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" |
| 17 | |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 18 | /* == Handling of I4L IO =====================================================*/ |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 19 | |
| 20 | /* writebuf_from_LL |
| 21 | * called by LL to transmit data on an open channel |
| 22 | * inserts the buffer data into the send queue and starts the transmission |
| 23 | * Note that this operation must not sleep! |
| 24 | * When the buffer is processed completely, gigaset_skb_sent() should be called. |
| 25 | * parameters: |
| 26 | * driverID driver ID as assigned by LL |
| 27 | * channel channel number |
Tilman Schmidt | 917f508 | 2006-04-10 22:55:00 -0700 | [diff] [blame] | 28 | * ack if != 0 LL wants to be notified on completion via |
| 29 | * statcallb(ISDN_STAT_BSENT) |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 30 | * skb skb containing data to send |
| 31 | * return value: |
| 32 | * number of accepted bytes |
| 33 | * 0 if temporarily unable to accept data (out of buffer space) |
| 34 | * <0 on error (eg. -EINVAL) |
| 35 | */ |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 36 | static int writebuf_from_LL(int driverID, int channel, int ack, |
| 37 | struct sk_buff *skb) |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 38 | { |
| 39 | struct cardstate *cs; |
| 40 | struct bc_state *bcs; |
| 41 | unsigned len; |
| 42 | unsigned skblen; |
| 43 | |
| 44 | if (!(cs = gigaset_get_cs_by_id(driverID))) { |
| 45 | err("%s: invalid driver ID (%d)", __func__, driverID); |
| 46 | return -ENODEV; |
| 47 | } |
| 48 | if (channel < 0 || channel >= cs->channels) { |
| 49 | err("%s: invalid channel ID (%d)", __func__, channel); |
| 50 | return -ENODEV; |
| 51 | } |
| 52 | bcs = &cs->bcs[channel]; |
| 53 | len = skb->len; |
| 54 | |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 55 | gig_dbg(DEBUG_LLDATA, |
| 56 | "Receiving data from LL (id: %d, ch: %d, ack: %d, sz: %d)", |
| 57 | driverID, channel, ack, len); |
| 58 | |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 59 | if (!len) { |
| 60 | if (ack) |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 61 | notice("%s: not ACKing empty packet", __func__); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 62 | return 0; |
| 63 | } |
| 64 | if (len > MAX_BUF_SIZE) { |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 65 | err("%s: packet too large (%d bytes)", __func__, len); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 66 | return -EINVAL; |
| 67 | } |
| 68 | |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 69 | skblen = ack ? len : 0; |
| 70 | skb->head[0] = skblen & 0xff; |
| 71 | skb->head[1] = skblen >> 8; |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 72 | gig_dbg(DEBUG_MCMD, "skb: len=%u, skblen=%u: %02x %02x", |
| 73 | len, skblen, (unsigned) skb->head[0], (unsigned) skb->head[1]); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 74 | |
| 75 | /* pass to device-specific module */ |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 76 | return cs->ops->send_skb(bcs, skb); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | void gigaset_skb_sent(struct bc_state *bcs, struct sk_buff *skb) |
| 80 | { |
| 81 | unsigned len; |
| 82 | isdn_ctrl response; |
| 83 | |
| 84 | ++bcs->trans_up; |
| 85 | |
| 86 | if (skb->len) |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 87 | dev_warn(bcs->cs->dev, "%s: skb->len==%d\n", |
| 88 | __func__, skb->len); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 89 | |
| 90 | len = (unsigned char) skb->head[0] | |
| 91 | (unsigned) (unsigned char) skb->head[1] << 8; |
| 92 | if (len) { |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 93 | gig_dbg(DEBUG_MCMD, "ACKing to LL (id: %d, ch: %d, sz: %u)", |
| 94 | bcs->cs->myid, bcs->channel, len); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 95 | |
| 96 | response.driver = bcs->cs->myid; |
| 97 | response.command = ISDN_STAT_BSENT; |
| 98 | response.arg = bcs->channel; |
| 99 | response.parm.length = len; |
| 100 | bcs->cs->iif.statcallb(&response); |
| 101 | } |
| 102 | } |
| 103 | EXPORT_SYMBOL_GPL(gigaset_skb_sent); |
| 104 | |
| 105 | /* This function will be called by LL to send commands |
| 106 | * NOTE: LL ignores the returned value, for commands other than ISDN_CMD_IOCTL, |
| 107 | * so don't put too much effort into it. |
| 108 | */ |
| 109 | static int command_from_LL(isdn_ctrl *cntrl) |
| 110 | { |
| 111 | struct cardstate *cs = gigaset_get_cs_by_id(cntrl->driver); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 112 | struct bc_state *bcs; |
| 113 | int retval = 0; |
| 114 | struct setup_parm *sp; |
| 115 | |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 116 | gigaset_debugdrivers(); |
| 117 | |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 118 | if (!cs) { |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 119 | warn("LL tried to access unknown device with nr. %d", |
| 120 | cntrl->driver); |
| 121 | return -ENODEV; |
| 122 | } |
| 123 | |
| 124 | switch (cntrl->command) { |
| 125 | case ISDN_CMD_IOCTL: |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 126 | gig_dbg(DEBUG_ANY, "ISDN_CMD_IOCTL (driver: %d, arg: %ld)", |
| 127 | cntrl->driver, cntrl->arg); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 128 | |
| 129 | warn("ISDN_CMD_IOCTL is not supported."); |
| 130 | return -EINVAL; |
| 131 | |
| 132 | case ISDN_CMD_DIAL: |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 133 | gig_dbg(DEBUG_ANY, |
| 134 | "ISDN_CMD_DIAL (driver: %d, ch: %ld, " |
| 135 | "phone: %s, ownmsn: %s, si1: %d, si2: %d)", |
| 136 | cntrl->driver, cntrl->arg, |
| 137 | cntrl->parm.setup.phone, cntrl->parm.setup.eazmsn, |
| 138 | cntrl->parm.setup.si1, cntrl->parm.setup.si2); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 139 | |
| 140 | if (cntrl->arg >= cs->channels) { |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 141 | err("ISDN_CMD_DIAL: invalid channel (%d)", |
| 142 | (int) cntrl->arg); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 143 | return -EINVAL; |
| 144 | } |
| 145 | |
| 146 | bcs = cs->bcs + cntrl->arg; |
| 147 | |
| 148 | if (!gigaset_get_channel(bcs)) { |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 149 | err("ISDN_CMD_DIAL: channel not free"); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 150 | return -EBUSY; |
| 151 | } |
| 152 | |
| 153 | sp = kmalloc(sizeof *sp, GFP_ATOMIC); |
| 154 | if (!sp) { |
| 155 | gigaset_free_channel(bcs); |
| 156 | err("ISDN_CMD_DIAL: out of memory"); |
| 157 | return -ENOMEM; |
| 158 | } |
| 159 | *sp = cntrl->parm.setup; |
| 160 | |
Tilman Schmidt | 4d1ff58 | 2007-10-16 01:27:50 -0700 | [diff] [blame^] | 161 | if (!gigaset_add_event(cs, &bcs->at_state, EV_DIAL, sp, |
| 162 | bcs->at_state.seq_index, NULL)) { |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 163 | //FIXME what should we do? |
| 164 | kfree(sp); |
| 165 | gigaset_free_channel(bcs); |
| 166 | return -ENOMEM; |
| 167 | } |
| 168 | |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 169 | gig_dbg(DEBUG_CMD, "scheduling DIAL"); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 170 | gigaset_schedule_event(cs); |
| 171 | break; |
| 172 | case ISDN_CMD_ACCEPTD: //FIXME |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 173 | gig_dbg(DEBUG_ANY, "ISDN_CMD_ACCEPTD"); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 174 | |
| 175 | if (cntrl->arg >= cs->channels) { |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 176 | err("ISDN_CMD_ACCEPTD: invalid channel (%d)", |
| 177 | (int) cntrl->arg); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 178 | return -EINVAL; |
| 179 | } |
| 180 | |
| 181 | if (!gigaset_add_event(cs, &cs->bcs[cntrl->arg].at_state, |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 182 | EV_ACCEPT, NULL, 0, NULL)) { |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 183 | //FIXME what should we do? |
| 184 | return -ENOMEM; |
| 185 | } |
| 186 | |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 187 | gig_dbg(DEBUG_CMD, "scheduling ACCEPT"); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 188 | gigaset_schedule_event(cs); |
| 189 | |
| 190 | break; |
| 191 | case ISDN_CMD_ACCEPTB: |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 192 | gig_dbg(DEBUG_ANY, "ISDN_CMD_ACCEPTB"); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 193 | break; |
| 194 | case ISDN_CMD_HANGUP: |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 195 | gig_dbg(DEBUG_ANY, "ISDN_CMD_HANGUP (ch: %d)", |
| 196 | (int) cntrl->arg); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 197 | |
| 198 | if (cntrl->arg >= cs->channels) { |
| 199 | err("ISDN_CMD_HANGUP: invalid channel (%u)", |
| 200 | (unsigned) cntrl->arg); |
| 201 | return -EINVAL; |
| 202 | } |
| 203 | |
| 204 | if (!gigaset_add_event(cs, &cs->bcs[cntrl->arg].at_state, |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 205 | EV_HUP, NULL, 0, NULL)) { |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 206 | //FIXME what should we do? |
| 207 | return -ENOMEM; |
| 208 | } |
| 209 | |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 210 | gig_dbg(DEBUG_CMD, "scheduling HUP"); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 211 | gigaset_schedule_event(cs); |
| 212 | |
| 213 | break; |
Tilman Schmidt | 917f508 | 2006-04-10 22:55:00 -0700 | [diff] [blame] | 214 | case ISDN_CMD_CLREAZ: /* Do not signal incoming signals */ //FIXME |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 215 | gig_dbg(DEBUG_ANY, "ISDN_CMD_CLREAZ"); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 216 | break; |
Tilman Schmidt | 917f508 | 2006-04-10 22:55:00 -0700 | [diff] [blame] | 217 | case ISDN_CMD_SETEAZ: /* Signal incoming calls for given MSN */ //FIXME |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 218 | gig_dbg(DEBUG_ANY, |
| 219 | "ISDN_CMD_SETEAZ (id: %d, ch: %ld, number: %s)", |
| 220 | cntrl->driver, cntrl->arg, cntrl->parm.num); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 221 | break; |
Tilman Schmidt | 917f508 | 2006-04-10 22:55:00 -0700 | [diff] [blame] | 222 | case ISDN_CMD_SETL2: /* Set L2 to given protocol */ |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 223 | gig_dbg(DEBUG_ANY, "ISDN_CMD_SETL2 (ch: %ld, proto: %lx)", |
| 224 | cntrl->arg & 0xff, (cntrl->arg >> 8)); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 225 | |
| 226 | if ((cntrl->arg & 0xff) >= cs->channels) { |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 227 | err("ISDN_CMD_SETL2: invalid channel (%u)", |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 228 | (unsigned) cntrl->arg & 0xff); |
| 229 | return -EINVAL; |
| 230 | } |
| 231 | |
| 232 | if (!gigaset_add_event(cs, &cs->bcs[cntrl->arg & 0xff].at_state, |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 233 | EV_PROTO_L2, NULL, cntrl->arg >> 8, |
| 234 | NULL)) { |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 235 | //FIXME what should we do? |
| 236 | return -ENOMEM; |
| 237 | } |
| 238 | |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 239 | gig_dbg(DEBUG_CMD, "scheduling PROTO_L2"); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 240 | gigaset_schedule_event(cs); |
| 241 | break; |
Tilman Schmidt | 917f508 | 2006-04-10 22:55:00 -0700 | [diff] [blame] | 242 | case ISDN_CMD_SETL3: /* Set L3 to given protocol */ |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 243 | gig_dbg(DEBUG_ANY, "ISDN_CMD_SETL3 (ch: %ld, proto: %lx)", |
| 244 | cntrl->arg & 0xff, (cntrl->arg >> 8)); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 245 | |
| 246 | if ((cntrl->arg & 0xff) >= cs->channels) { |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 247 | err("ISDN_CMD_SETL3: invalid channel (%u)", |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 248 | (unsigned) cntrl->arg & 0xff); |
| 249 | return -EINVAL; |
| 250 | } |
| 251 | |
| 252 | if (cntrl->arg >> 8 != ISDN_PROTO_L3_TRANS) { |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 253 | err("ISDN_CMD_SETL3: invalid protocol %lu", |
| 254 | cntrl->arg >> 8); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 255 | return -EINVAL; |
| 256 | } |
| 257 | |
| 258 | break; |
| 259 | case ISDN_CMD_PROCEED: |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 260 | gig_dbg(DEBUG_ANY, "ISDN_CMD_PROCEED"); //FIXME |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 261 | break; |
| 262 | case ISDN_CMD_ALERT: |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 263 | gig_dbg(DEBUG_ANY, "ISDN_CMD_ALERT"); //FIXME |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 264 | if (cntrl->arg >= cs->channels) { |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 265 | err("ISDN_CMD_ALERT: invalid channel (%d)", |
| 266 | (int) cntrl->arg); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 267 | return -EINVAL; |
| 268 | } |
| 269 | //bcs = cs->bcs + cntrl->arg; |
| 270 | //bcs->proto2 = -1; |
| 271 | // FIXME |
| 272 | break; |
| 273 | case ISDN_CMD_REDIR: |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 274 | gig_dbg(DEBUG_ANY, "ISDN_CMD_REDIR"); //FIXME |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 275 | break; |
| 276 | case ISDN_CMD_PROT_IO: |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 277 | gig_dbg(DEBUG_ANY, "ISDN_CMD_PROT_IO"); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 278 | break; |
| 279 | case ISDN_CMD_FAXCMD: |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 280 | gig_dbg(DEBUG_ANY, "ISDN_CMD_FAXCMD"); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 281 | break; |
| 282 | case ISDN_CMD_GETL2: |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 283 | gig_dbg(DEBUG_ANY, "ISDN_CMD_GETL2"); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 284 | break; |
| 285 | case ISDN_CMD_GETL3: |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 286 | gig_dbg(DEBUG_ANY, "ISDN_CMD_GETL3"); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 287 | break; |
| 288 | case ISDN_CMD_GETEAZ: |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 289 | gig_dbg(DEBUG_ANY, "ISDN_CMD_GETEAZ"); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 290 | break; |
| 291 | case ISDN_CMD_SETSIL: |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 292 | gig_dbg(DEBUG_ANY, "ISDN_CMD_SETSIL"); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 293 | break; |
| 294 | case ISDN_CMD_GETSIL: |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 295 | gig_dbg(DEBUG_ANY, "ISDN_CMD_GETSIL"); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 296 | break; |
| 297 | default: |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 298 | err("unknown command %d from LL", cntrl->command); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 299 | return -EINVAL; |
| 300 | } |
| 301 | |
| 302 | return retval; |
| 303 | } |
| 304 | |
| 305 | void gigaset_i4l_cmd(struct cardstate *cs, int cmd) |
| 306 | { |
| 307 | isdn_ctrl command; |
| 308 | |
| 309 | command.driver = cs->myid; |
| 310 | command.command = cmd; |
| 311 | command.arg = 0; |
| 312 | cs->iif.statcallb(&command); |
| 313 | } |
| 314 | |
| 315 | void gigaset_i4l_channel_cmd(struct bc_state *bcs, int cmd) |
| 316 | { |
| 317 | isdn_ctrl command; |
| 318 | |
| 319 | command.driver = bcs->cs->myid; |
| 320 | command.command = cmd; |
| 321 | command.arg = bcs->channel; |
| 322 | bcs->cs->iif.statcallb(&command); |
| 323 | } |
| 324 | |
| 325 | int gigaset_isdn_setup_dial(struct at_state_t *at_state, void *data) |
| 326 | { |
| 327 | struct bc_state *bcs = at_state->bcs; |
| 328 | unsigned proto; |
| 329 | const char *bc; |
| 330 | size_t length[AT_NUM]; |
| 331 | size_t l; |
| 332 | int i; |
| 333 | struct setup_parm *sp = data; |
| 334 | |
| 335 | switch (bcs->proto2) { |
| 336 | case ISDN_PROTO_L2_HDLC: |
| 337 | proto = 1; /* 0: Bitsynchron, 1: HDLC, 2: voice */ |
| 338 | break; |
| 339 | case ISDN_PROTO_L2_TRANS: |
| 340 | proto = 2; /* 0: Bitsynchron, 1: HDLC, 2: voice */ |
| 341 | break; |
| 342 | default: |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 343 | dev_err(bcs->cs->dev, "%s: invalid L2 protocol: %u\n", |
| 344 | __func__, bcs->proto2); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 345 | return -EINVAL; |
| 346 | } |
| 347 | |
| 348 | switch (sp->si1) { |
| 349 | case 1: /* audio */ |
| 350 | bc = "9090A3"; /* 3.1 kHz audio, A-law */ |
| 351 | break; |
| 352 | case 7: /* data */ |
| 353 | default: /* hope the app knows what it is doing */ |
| 354 | bc = "8890"; /* unrestricted digital information */ |
| 355 | } |
| 356 | //FIXME add missing si1 values from 1TR6, inspect si2, set HLC/LLC |
| 357 | |
| 358 | length[AT_DIAL ] = 1 + strlen(sp->phone) + 1 + 1; |
| 359 | l = strlen(sp->eazmsn); |
| 360 | length[AT_MSN ] = l ? 6 + l + 1 + 1 : 0; |
| 361 | length[AT_BC ] = 5 + strlen(bc) + 1 + 1; |
| 362 | length[AT_PROTO] = 6 + 1 + 1 + 1; /* proto: 1 character */ |
| 363 | length[AT_ISO ] = 6 + 1 + 1 + 1; /* channel: 1 character */ |
| 364 | length[AT_TYPE ] = 6 + 1 + 1 + 1; /* call type: 1 character */ |
| 365 | length[AT_HLC ] = 0; |
| 366 | |
| 367 | for (i = 0; i < AT_NUM; ++i) { |
| 368 | kfree(bcs->commands[i]); |
| 369 | bcs->commands[i] = NULL; |
| 370 | if (length[i] && |
| 371 | !(bcs->commands[i] = kmalloc(length[i], GFP_ATOMIC))) { |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 372 | dev_err(bcs->cs->dev, "out of memory\n"); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 373 | return -ENOMEM; |
| 374 | } |
| 375 | } |
| 376 | |
| 377 | /* type = 1: extern, 0: intern, 2: recall, 3: door, 4: centrex */ |
| 378 | if (sp->phone[0] == '*' && sp->phone[1] == '*') { |
| 379 | /* internal call: translate ** prefix to CTP value */ |
| 380 | snprintf(bcs->commands[AT_DIAL], length[AT_DIAL], |
| 381 | "D%s\r", sp->phone+2); |
| 382 | strncpy(bcs->commands[AT_TYPE], "^SCTP=0\r", length[AT_TYPE]); |
| 383 | } else { |
| 384 | snprintf(bcs->commands[AT_DIAL], length[AT_DIAL], |
| 385 | "D%s\r", sp->phone); |
| 386 | strncpy(bcs->commands[AT_TYPE], "^SCTP=1\r", length[AT_TYPE]); |
| 387 | } |
| 388 | |
| 389 | if (bcs->commands[AT_MSN]) |
Tilman Schmidt | 917f508 | 2006-04-10 22:55:00 -0700 | [diff] [blame] | 390 | snprintf(bcs->commands[AT_MSN], length[AT_MSN], |
| 391 | "^SMSN=%s\r", sp->eazmsn); |
| 392 | snprintf(bcs->commands[AT_BC ], length[AT_BC ], |
| 393 | "^SBC=%s\r", bc); |
| 394 | snprintf(bcs->commands[AT_PROTO], length[AT_PROTO], |
| 395 | "^SBPR=%u\r", proto); |
| 396 | snprintf(bcs->commands[AT_ISO ], length[AT_ISO ], |
| 397 | "^SISO=%u\r", (unsigned)bcs->channel + 1); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 398 | |
| 399 | return 0; |
| 400 | } |
| 401 | |
| 402 | int gigaset_isdn_setup_accept(struct at_state_t *at_state) |
| 403 | { |
| 404 | unsigned proto; |
| 405 | size_t length[AT_NUM]; |
| 406 | int i; |
| 407 | struct bc_state *bcs = at_state->bcs; |
| 408 | |
| 409 | switch (bcs->proto2) { |
| 410 | case ISDN_PROTO_L2_HDLC: |
| 411 | proto = 1; /* 0: Bitsynchron, 1: HDLC, 2: voice */ |
| 412 | break; |
| 413 | case ISDN_PROTO_L2_TRANS: |
| 414 | proto = 2; /* 0: Bitsynchron, 1: HDLC, 2: voice */ |
| 415 | break; |
| 416 | default: |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 417 | dev_err(at_state->cs->dev, "%s: invalid protocol: %u\n", |
| 418 | __func__, bcs->proto2); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 419 | return -EINVAL; |
| 420 | } |
| 421 | |
| 422 | length[AT_DIAL ] = 0; |
| 423 | length[AT_MSN ] = 0; |
| 424 | length[AT_BC ] = 0; |
| 425 | length[AT_PROTO] = 6 + 1 + 1 + 1; /* proto: 1 character */ |
| 426 | length[AT_ISO ] = 6 + 1 + 1 + 1; /* channel: 1 character */ |
| 427 | length[AT_TYPE ] = 0; |
| 428 | length[AT_HLC ] = 0; |
| 429 | |
| 430 | for (i = 0; i < AT_NUM; ++i) { |
| 431 | kfree(bcs->commands[i]); |
| 432 | bcs->commands[i] = NULL; |
| 433 | if (length[i] && |
| 434 | !(bcs->commands[i] = kmalloc(length[i], GFP_ATOMIC))) { |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 435 | dev_err(at_state->cs->dev, "out of memory\n"); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 436 | return -ENOMEM; |
| 437 | } |
| 438 | } |
| 439 | |
Tilman Schmidt | 917f508 | 2006-04-10 22:55:00 -0700 | [diff] [blame] | 440 | snprintf(bcs->commands[AT_PROTO], length[AT_PROTO], |
| 441 | "^SBPR=%u\r", proto); |
| 442 | snprintf(bcs->commands[AT_ISO ], length[AT_ISO ], |
| 443 | "^SISO=%u\r", (unsigned) bcs->channel + 1); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 444 | |
| 445 | return 0; |
| 446 | } |
| 447 | |
| 448 | int gigaset_isdn_icall(struct at_state_t *at_state) |
| 449 | { |
| 450 | struct cardstate *cs = at_state->cs; |
| 451 | struct bc_state *bcs = at_state->bcs; |
| 452 | isdn_ctrl response; |
| 453 | int retval; |
| 454 | |
| 455 | /* fill ICALL structure */ |
| 456 | response.parm.setup.si1 = 0; /* default: unknown */ |
| 457 | response.parm.setup.si2 = 0; |
| 458 | response.parm.setup.screen = 0; //FIXME how to set these? |
| 459 | response.parm.setup.plan = 0; |
| 460 | if (!at_state->str_var[STR_ZBC]) { |
| 461 | /* no BC (internal call): assume speech, A-law */ |
| 462 | response.parm.setup.si1 = 1; |
| 463 | } else if (!strcmp(at_state->str_var[STR_ZBC], "8890")) { |
| 464 | /* unrestricted digital information */ |
| 465 | response.parm.setup.si1 = 7; |
| 466 | } else if (!strcmp(at_state->str_var[STR_ZBC], "8090A3")) { |
| 467 | /* speech, A-law */ |
| 468 | response.parm.setup.si1 = 1; |
| 469 | } else if (!strcmp(at_state->str_var[STR_ZBC], "9090A3")) { |
| 470 | /* 3,1 kHz audio, A-law */ |
| 471 | response.parm.setup.si1 = 1; |
| 472 | response.parm.setup.si2 = 2; |
| 473 | } else { |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 474 | dev_warn(cs->dev, "RING ignored - unsupported BC %s\n", |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 475 | at_state->str_var[STR_ZBC]); |
| 476 | return ICALL_IGNORE; |
| 477 | } |
| 478 | if (at_state->str_var[STR_NMBR]) { |
| 479 | strncpy(response.parm.setup.phone, at_state->str_var[STR_NMBR], |
| 480 | sizeof response.parm.setup.phone - 1); |
| 481 | response.parm.setup.phone[sizeof response.parm.setup.phone - 1] = 0; |
| 482 | } else |
| 483 | response.parm.setup.phone[0] = 0; |
| 484 | if (at_state->str_var[STR_ZCPN]) { |
| 485 | strncpy(response.parm.setup.eazmsn, at_state->str_var[STR_ZCPN], |
| 486 | sizeof response.parm.setup.eazmsn - 1); |
| 487 | response.parm.setup.eazmsn[sizeof response.parm.setup.eazmsn - 1] = 0; |
| 488 | } else |
| 489 | response.parm.setup.eazmsn[0] = 0; |
| 490 | |
| 491 | if (!bcs) { |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 492 | dev_notice(cs->dev, "no channel for incoming call\n"); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 493 | response.command = ISDN_STAT_ICALLW; |
| 494 | response.arg = 0; //FIXME |
| 495 | } else { |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 496 | gig_dbg(DEBUG_CMD, "Sending ICALL"); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 497 | response.command = ISDN_STAT_ICALL; |
| 498 | response.arg = bcs->channel; //FIXME |
| 499 | } |
| 500 | response.driver = cs->myid; |
| 501 | retval = cs->iif.statcallb(&response); |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 502 | gig_dbg(DEBUG_CMD, "Response: %d", retval); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 503 | switch (retval) { |
| 504 | case 0: /* no takers */ |
| 505 | return ICALL_IGNORE; |
| 506 | case 1: /* alerting */ |
| 507 | bcs->chstate |= CHS_NOTIFY_LL; |
| 508 | return ICALL_ACCEPT; |
| 509 | case 2: /* reject */ |
| 510 | return ICALL_REJECT; |
| 511 | case 3: /* incomplete */ |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 512 | dev_warn(cs->dev, |
| 513 | "LL requested unsupported feature: Incomplete Number\n"); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 514 | return ICALL_IGNORE; |
| 515 | case 4: /* proceeding */ |
| 516 | /* Gigaset will send ALERTING anyway. |
| 517 | * There doesn't seem to be a way to avoid this. |
| 518 | */ |
| 519 | return ICALL_ACCEPT; |
| 520 | case 5: /* deflect */ |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 521 | dev_warn(cs->dev, |
| 522 | "LL requested unsupported feature: Call Deflection\n"); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 523 | return ICALL_IGNORE; |
| 524 | default: |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 525 | dev_err(cs->dev, "LL error %d on ICALL\n", retval); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 526 | return ICALL_IGNORE; |
| 527 | } |
| 528 | } |
| 529 | |
| 530 | /* Set Callback function pointer */ |
| 531 | int gigaset_register_to_LL(struct cardstate *cs, const char *isdnid) |
| 532 | { |
| 533 | isdn_if *iif = &cs->iif; |
| 534 | |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 535 | gig_dbg(DEBUG_ANY, "Register driver capabilities to LL"); |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 536 | |
| 537 | //iif->id[sizeof(iif->id) - 1]=0; |
| 538 | //strncpy(iif->id, isdnid, sizeof(iif->id) - 1); |
| 539 | if (snprintf(iif->id, sizeof iif->id, "%s_%u", isdnid, cs->minor_index) |
| 540 | >= sizeof iif->id) |
| 541 | return -ENOMEM; //FIXME EINVAL/...?? |
| 542 | |
| 543 | iif->owner = THIS_MODULE; |
Tilman Schmidt | 917f508 | 2006-04-10 22:55:00 -0700 | [diff] [blame] | 544 | iif->channels = cs->channels; |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 545 | iif->maxbufsize = MAX_BUF_SIZE; |
Tilman Schmidt | 917f508 | 2006-04-10 22:55:00 -0700 | [diff] [blame] | 546 | iif->features = ISDN_FEATURE_L2_TRANS | |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 547 | ISDN_FEATURE_L2_HDLC | |
| 548 | #ifdef GIG_X75 |
| 549 | ISDN_FEATURE_L2_X75I | |
| 550 | #endif |
| 551 | ISDN_FEATURE_L3_TRANS | |
| 552 | ISDN_FEATURE_P_EURO; |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 553 | iif->hl_hdrlen = HW_HDR_LEN; /* Area for storing ack */ |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 554 | iif->command = command_from_LL; |
| 555 | iif->writebuf_skb = writebuf_from_LL; |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 556 | iif->writecmd = NULL; /* Don't support isdnctrl */ |
| 557 | iif->readstat = NULL; /* Don't support isdnctrl */ |
| 558 | iif->rcvcallb_skb = NULL; /* Will be set by LL */ |
| 559 | iif->statcallb = NULL; /* Will be set by LL */ |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 560 | |
| 561 | if (!register_isdn(iif)) |
| 562 | return 0; |
| 563 | |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 564 | cs->myid = iif->channels; /* Set my device id */ |
Hansjoerg Lipp | 3c66a22 | 2006-03-26 01:38:31 -0800 | [diff] [blame] | 565 | return 1; |
| 566 | } |