Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -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, |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 5 | * Hansjoerg Lipp <hjlipp@web.de>, |
| 6 | * Tilman Schmidt <tilman@imap.cc>. |
| 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 | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | #include "gigaset.h" |
| 17 | |
| 18 | /* ========================================================== */ |
| 19 | /* bit masks for pending commands */ |
Tilman Schmidt | 917f508 | 2006-04-10 22:55:00 -0700 | [diff] [blame] | 20 | #define PC_DIAL 0x001 |
| 21 | #define PC_HUP 0x002 |
| 22 | #define PC_INIT 0x004 |
| 23 | #define PC_DLE0 0x008 |
| 24 | #define PC_DLE1 0x010 |
| 25 | #define PC_SHUTDOWN 0x020 |
| 26 | #define PC_ACCEPT 0x040 |
| 27 | #define PC_CID 0x080 |
| 28 | #define PC_NOCID 0x100 |
| 29 | #define PC_CIDMODE 0x200 |
| 30 | #define PC_UMMODE 0x400 |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 31 | |
| 32 | /* types of modem responses */ |
Tilman Schmidt | 917f508 | 2006-04-10 22:55:00 -0700 | [diff] [blame] | 33 | #define RT_NOTHING 0 |
| 34 | #define RT_ZSAU 1 |
| 35 | #define RT_RING 2 |
| 36 | #define RT_NUMBER 3 |
| 37 | #define RT_STRING 4 |
| 38 | #define RT_HEX 5 |
| 39 | #define RT_ZCAU 6 |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 40 | |
| 41 | /* Possible ASCII responses */ |
Tilman Schmidt | 917f508 | 2006-04-10 22:55:00 -0700 | [diff] [blame] | 42 | #define RSP_OK 0 |
Tilman Schmidt | c35a87f | 2009-10-25 09:30:47 +0000 | [diff] [blame] | 43 | #define RSP_BUSY 1 |
| 44 | #define RSP_CONNECT 2 |
Tilman Schmidt | 917f508 | 2006-04-10 22:55:00 -0700 | [diff] [blame] | 45 | #define RSP_ZGCI 3 |
| 46 | #define RSP_RING 4 |
| 47 | #define RSP_ZAOC 5 |
| 48 | #define RSP_ZCSTR 6 |
| 49 | #define RSP_ZCFGT 7 |
| 50 | #define RSP_ZCFG 8 |
| 51 | #define RSP_ZCCR 9 |
| 52 | #define RSP_EMPTY 10 |
| 53 | #define RSP_ZLOG 11 |
| 54 | #define RSP_ZCAU 12 |
| 55 | #define RSP_ZMWI 13 |
| 56 | #define RSP_ZABINFO 14 |
| 57 | #define RSP_ZSMLSTCHG 15 |
| 58 | #define RSP_VAR 100 |
| 59 | #define RSP_ZSAU (RSP_VAR + VAR_ZSAU) |
| 60 | #define RSP_ZDLE (RSP_VAR + VAR_ZDLE) |
| 61 | #define RSP_ZVLS (RSP_VAR + VAR_ZVLS) |
| 62 | #define RSP_ZCTP (RSP_VAR + VAR_ZCTP) |
| 63 | #define RSP_STR (RSP_VAR + VAR_NUM) |
| 64 | #define RSP_NMBR (RSP_STR + STR_NMBR) |
| 65 | #define RSP_ZCPN (RSP_STR + STR_ZCPN) |
| 66 | #define RSP_ZCON (RSP_STR + STR_ZCON) |
| 67 | #define RSP_ZBC (RSP_STR + STR_ZBC) |
| 68 | #define RSP_ZHLC (RSP_STR + STR_ZHLC) |
| 69 | #define RSP_ERROR -1 /* ERROR */ |
| 70 | #define RSP_WRONG_CID -2 /* unknown cid in cmd */ |
Tilman Schmidt | 917f508 | 2006-04-10 22:55:00 -0700 | [diff] [blame] | 71 | #define RSP_UNKNOWN -4 /* unknown response */ |
| 72 | #define RSP_FAIL -5 /* internal error */ |
| 73 | #define RSP_INVAL -6 /* invalid response */ |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 74 | |
Tilman Schmidt | 917f508 | 2006-04-10 22:55:00 -0700 | [diff] [blame] | 75 | #define RSP_NONE -19 |
| 76 | #define RSP_STRING -20 |
| 77 | #define RSP_NULL -21 |
Tilman Schmidt | c35a87f | 2009-10-25 09:30:47 +0000 | [diff] [blame] | 78 | #define RSP_RETRYFAIL -22 |
| 79 | #define RSP_RETRY -23 |
| 80 | #define RSP_SKIP -24 |
Tilman Schmidt | 917f508 | 2006-04-10 22:55:00 -0700 | [diff] [blame] | 81 | #define RSP_INIT -27 |
| 82 | #define RSP_ANY -26 |
| 83 | #define RSP_LAST -28 |
| 84 | #define RSP_NODEV -9 |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 85 | |
| 86 | /* actions for process_response */ |
| 87 | #define ACT_NOTHING 0 |
| 88 | #define ACT_SETDLE1 1 |
| 89 | #define ACT_SETDLE0 2 |
| 90 | #define ACT_FAILINIT 3 |
| 91 | #define ACT_HUPMODEM 4 |
| 92 | #define ACT_CONFIGMODE 5 |
| 93 | #define ACT_INIT 6 |
| 94 | #define ACT_DLE0 7 |
| 95 | #define ACT_DLE1 8 |
| 96 | #define ACT_FAILDLE0 9 |
| 97 | #define ACT_FAILDLE1 10 |
| 98 | #define ACT_RING 11 |
| 99 | #define ACT_CID 12 |
| 100 | #define ACT_FAILCID 13 |
| 101 | #define ACT_SDOWN 14 |
| 102 | #define ACT_FAILSDOWN 15 |
| 103 | #define ACT_DEBUG 16 |
| 104 | #define ACT_WARN 17 |
| 105 | #define ACT_DIALING 18 |
| 106 | #define ACT_ABORTDIAL 19 |
| 107 | #define ACT_DISCONNECT 20 |
| 108 | #define ACT_CONNECT 21 |
| 109 | #define ACT_REMOTEREJECT 22 |
Tilman Schmidt | 917f508 | 2006-04-10 22:55:00 -0700 | [diff] [blame] | 110 | #define ACT_CONNTIMEOUT 23 |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 111 | #define ACT_REMOTEHUP 24 |
| 112 | #define ACT_ABORTHUP 25 |
| 113 | #define ACT_ICALL 26 |
| 114 | #define ACT_ACCEPTED 27 |
| 115 | #define ACT_ABORTACCEPT 28 |
| 116 | #define ACT_TIMEOUT 29 |
| 117 | #define ACT_GETSTRING 30 |
| 118 | #define ACT_SETVER 31 |
| 119 | #define ACT_FAILVER 32 |
| 120 | #define ACT_GOTVER 33 |
| 121 | #define ACT_TEST 34 |
| 122 | #define ACT_ERROR 35 |
| 123 | #define ACT_ABORTCID 36 |
| 124 | #define ACT_ZCAU 37 |
Tilman Schmidt | 917f508 | 2006-04-10 22:55:00 -0700 | [diff] [blame] | 125 | #define ACT_NOTIFY_BC_DOWN 38 |
| 126 | #define ACT_NOTIFY_BC_UP 39 |
| 127 | #define ACT_DIAL 40 |
| 128 | #define ACT_ACCEPT 41 |
Tilman Schmidt | 917f508 | 2006-04-10 22:55:00 -0700 | [diff] [blame] | 129 | #define ACT_HUP 43 |
| 130 | #define ACT_IF_LOCK 44 |
| 131 | #define ACT_START 45 |
| 132 | #define ACT_STOP 46 |
| 133 | #define ACT_FAKEDLE0 47 |
| 134 | #define ACT_FAKEHUP 48 |
| 135 | #define ACT_FAKESDOWN 49 |
| 136 | #define ACT_SHUTDOWN 50 |
| 137 | #define ACT_PROC_CIDMODE 51 |
| 138 | #define ACT_UMODESET 52 |
| 139 | #define ACT_FAILUMODE 53 |
| 140 | #define ACT_CMODESET 54 |
| 141 | #define ACT_FAILCMODE 55 |
| 142 | #define ACT_IF_VER 56 |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 143 | #define ACT_CMD 100 |
| 144 | |
| 145 | /* at command sequences */ |
Tilman Schmidt | 917f508 | 2006-04-10 22:55:00 -0700 | [diff] [blame] | 146 | #define SEQ_NONE 0 |
| 147 | #define SEQ_INIT 100 |
| 148 | #define SEQ_DLE0 200 |
| 149 | #define SEQ_DLE1 250 |
| 150 | #define SEQ_CID 300 |
| 151 | #define SEQ_NOCID 350 |
| 152 | #define SEQ_HUP 400 |
| 153 | #define SEQ_DIAL 600 |
| 154 | #define SEQ_ACCEPT 720 |
| 155 | #define SEQ_SHUTDOWN 500 |
| 156 | #define SEQ_CIDMODE 10 |
| 157 | #define SEQ_UMMODE 11 |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 158 | |
| 159 | |
Tilman Schmidt | c35a87f | 2009-10-25 09:30:47 +0000 | [diff] [blame] | 160 | /* 100: init, 200: dle0, 250:dle1, 300: get cid (dial), 350: "hup" (no cid), |
| 161 | * 400: hup, 500: reset, 600: dial, 700: ring */ |
Tilman Schmidt | 528efc6 | 2009-05-13 12:44:17 +0000 | [diff] [blame] | 162 | struct reply_t gigaset_tab_nocid[] = |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 163 | { |
Tilman Schmidt | c35a87f | 2009-10-25 09:30:47 +0000 | [diff] [blame] | 164 | /* resp_code, min_ConState, max_ConState, parameter, new_ConState, timeout, |
| 165 | * action, command */ |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 166 | |
Tilman Schmidt | c35a87f | 2009-10-25 09:30:47 +0000 | [diff] [blame] | 167 | /* initialize device, set cid mode if possible */ |
| 168 | {RSP_INIT, -1, -1, SEQ_INIT, 100, 1, {ACT_TIMEOUT} }, |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 169 | |
Tilman Schmidt | c35a87f | 2009-10-25 09:30:47 +0000 | [diff] [blame] | 170 | {EV_TIMEOUT, 100, 100, -1, 101, 3, {0}, "Z\r"}, |
| 171 | {RSP_OK, 101, 103, -1, 120, 5, {ACT_GETSTRING}, |
| 172 | "+GMR\r"}, |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 173 | |
Tilman Schmidt | c35a87f | 2009-10-25 09:30:47 +0000 | [diff] [blame] | 174 | {EV_TIMEOUT, 101, 101, -1, 102, 5, {0}, "Z\r"}, |
| 175 | {RSP_ERROR, 101, 101, -1, 102, 5, {0}, "Z\r"}, |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 176 | |
Tilman Schmidt | c35a87f | 2009-10-25 09:30:47 +0000 | [diff] [blame] | 177 | {EV_TIMEOUT, 102, 102, -1, 108, 5, {ACT_SETDLE1}, |
| 178 | "^SDLE=0\r"}, |
| 179 | {RSP_OK, 108, 108, -1, 104, -1}, |
| 180 | {RSP_ZDLE, 104, 104, 0, 103, 5, {0}, "Z\r"}, |
| 181 | {EV_TIMEOUT, 104, 104, -1, 0, 0, {ACT_FAILINIT} }, |
| 182 | {RSP_ERROR, 108, 108, -1, 0, 0, {ACT_FAILINIT} }, |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 183 | |
Tilman Schmidt | c35a87f | 2009-10-25 09:30:47 +0000 | [diff] [blame] | 184 | {EV_TIMEOUT, 108, 108, -1, 105, 2, {ACT_SETDLE0, |
| 185 | ACT_HUPMODEM, |
| 186 | ACT_TIMEOUT} }, |
| 187 | {EV_TIMEOUT, 105, 105, -1, 103, 5, {0}, "Z\r"}, |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 188 | |
Tilman Schmidt | c35a87f | 2009-10-25 09:30:47 +0000 | [diff] [blame] | 189 | {RSP_ERROR, 102, 102, -1, 107, 5, {0}, "^GETPRE\r"}, |
| 190 | {RSP_OK, 107, 107, -1, 0, 0, {ACT_CONFIGMODE} }, |
| 191 | {RSP_ERROR, 107, 107, -1, 0, 0, {ACT_FAILINIT} }, |
| 192 | {EV_TIMEOUT, 107, 107, -1, 0, 0, {ACT_FAILINIT} }, |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 193 | |
Tilman Schmidt | c35a87f | 2009-10-25 09:30:47 +0000 | [diff] [blame] | 194 | {RSP_ERROR, 103, 103, -1, 0, 0, {ACT_FAILINIT} }, |
| 195 | {EV_TIMEOUT, 103, 103, -1, 0, 0, {ACT_FAILINIT} }, |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 196 | |
Tilman Schmidt | c35a87f | 2009-10-25 09:30:47 +0000 | [diff] [blame] | 197 | {RSP_STRING, 120, 120, -1, 121, -1, {ACT_SETVER} }, |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 198 | |
Tilman Schmidt | c35a87f | 2009-10-25 09:30:47 +0000 | [diff] [blame] | 199 | {EV_TIMEOUT, 120, 121, -1, 0, 0, {ACT_FAILVER, |
| 200 | ACT_INIT} }, |
| 201 | {RSP_ERROR, 120, 121, -1, 0, 0, {ACT_FAILVER, |
| 202 | ACT_INIT} }, |
| 203 | {RSP_OK, 121, 121, -1, 0, 0, {ACT_GOTVER, |
| 204 | ACT_INIT} }, |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 205 | |
Tilman Schmidt | c35a87f | 2009-10-25 09:30:47 +0000 | [diff] [blame] | 206 | /* leave dle mode */ |
| 207 | {RSP_INIT, 0, 0, SEQ_DLE0, 201, 5, {0}, "^SDLE=0\r"}, |
| 208 | {RSP_OK, 201, 201, -1, 202, -1}, |
| 209 | {RSP_ZDLE, 202, 202, 0, 0, 0, {ACT_DLE0} }, |
| 210 | {RSP_NODEV, 200, 249, -1, 0, 0, {ACT_FAKEDLE0} }, |
| 211 | {RSP_ERROR, 200, 249, -1, 0, 0, {ACT_FAILDLE0} }, |
| 212 | {EV_TIMEOUT, 200, 249, -1, 0, 0, {ACT_FAILDLE0} }, |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 213 | |
Tilman Schmidt | c35a87f | 2009-10-25 09:30:47 +0000 | [diff] [blame] | 214 | /* enter dle mode */ |
| 215 | {RSP_INIT, 0, 0, SEQ_DLE1, 251, 5, {0}, "^SDLE=1\r"}, |
| 216 | {RSP_OK, 251, 251, -1, 252, -1}, |
| 217 | {RSP_ZDLE, 252, 252, 1, 0, 0, {ACT_DLE1} }, |
| 218 | {RSP_ERROR, 250, 299, -1, 0, 0, {ACT_FAILDLE1} }, |
| 219 | {EV_TIMEOUT, 250, 299, -1, 0, 0, {ACT_FAILDLE1} }, |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 220 | |
Tilman Schmidt | c35a87f | 2009-10-25 09:30:47 +0000 | [diff] [blame] | 221 | /* incoming call */ |
| 222 | {RSP_RING, -1, -1, -1, -1, -1, {ACT_RING} }, |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 223 | |
Tilman Schmidt | c35a87f | 2009-10-25 09:30:47 +0000 | [diff] [blame] | 224 | /* get cid */ |
| 225 | {RSP_INIT, 0, 0, SEQ_CID, 301, 5, {0}, "^SGCI?\r"}, |
| 226 | {RSP_OK, 301, 301, -1, 302, -1}, |
| 227 | {RSP_ZGCI, 302, 302, -1, 0, 0, {ACT_CID} }, |
| 228 | {RSP_ERROR, 301, 349, -1, 0, 0, {ACT_FAILCID} }, |
| 229 | {EV_TIMEOUT, 301, 349, -1, 0, 0, {ACT_FAILCID} }, |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 230 | |
Tilman Schmidt | c35a87f | 2009-10-25 09:30:47 +0000 | [diff] [blame] | 231 | /* enter cid mode */ |
| 232 | {RSP_INIT, 0, 0, SEQ_CIDMODE, 150, 5, {0}, "^SGCI=1\r"}, |
| 233 | {RSP_OK, 150, 150, -1, 0, 0, {ACT_CMODESET} }, |
| 234 | {RSP_ERROR, 150, 150, -1, 0, 0, {ACT_FAILCMODE} }, |
| 235 | {EV_TIMEOUT, 150, 150, -1, 0, 0, {ACT_FAILCMODE} }, |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 236 | |
Tilman Schmidt | c35a87f | 2009-10-25 09:30:47 +0000 | [diff] [blame] | 237 | /* leave cid mode */ |
| 238 | {RSP_INIT, 0, 0, SEQ_UMMODE, 160, 5, {0}, "Z\r"}, |
| 239 | {RSP_OK, 160, 160, -1, 0, 0, {ACT_UMODESET} }, |
| 240 | {RSP_ERROR, 160, 160, -1, 0, 0, {ACT_FAILUMODE} }, |
| 241 | {EV_TIMEOUT, 160, 160, -1, 0, 0, {ACT_FAILUMODE} }, |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 242 | |
Tilman Schmidt | c35a87f | 2009-10-25 09:30:47 +0000 | [diff] [blame] | 243 | /* abort getting cid */ |
| 244 | {RSP_INIT, 0, 0, SEQ_NOCID, 0, 0, {ACT_ABORTCID} }, |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 245 | |
Tilman Schmidt | c35a87f | 2009-10-25 09:30:47 +0000 | [diff] [blame] | 246 | /* reset */ |
| 247 | {RSP_INIT, 0, 0, SEQ_SHUTDOWN, 504, 5, {0}, "Z\r"}, |
| 248 | {RSP_OK, 504, 504, -1, 0, 0, {ACT_SDOWN} }, |
| 249 | {RSP_ERROR, 501, 599, -1, 0, 0, {ACT_FAILSDOWN} }, |
| 250 | {EV_TIMEOUT, 501, 599, -1, 0, 0, {ACT_FAILSDOWN} }, |
| 251 | {RSP_NODEV, 501, 599, -1, 0, 0, {ACT_FAKESDOWN} }, |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 252 | |
Tilman Schmidt | c35a87f | 2009-10-25 09:30:47 +0000 | [diff] [blame] | 253 | {EV_PROC_CIDMODE, -1, -1, -1, -1, -1, {ACT_PROC_CIDMODE} }, |
| 254 | {EV_IF_LOCK, -1, -1, -1, -1, -1, {ACT_IF_LOCK} }, |
| 255 | {EV_IF_VER, -1, -1, -1, -1, -1, {ACT_IF_VER} }, |
| 256 | {EV_START, -1, -1, -1, -1, -1, {ACT_START} }, |
| 257 | {EV_STOP, -1, -1, -1, -1, -1, {ACT_STOP} }, |
| 258 | {EV_SHUTDOWN, -1, -1, -1, -1, -1, {ACT_SHUTDOWN} }, |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 259 | |
Tilman Schmidt | c35a87f | 2009-10-25 09:30:47 +0000 | [diff] [blame] | 260 | /* misc. */ |
| 261 | {RSP_ERROR, -1, -1, -1, -1, -1, {ACT_ERROR} }, |
| 262 | {RSP_ZCFGT, -1, -1, -1, -1, -1, {ACT_DEBUG} }, |
| 263 | {RSP_ZCFG, -1, -1, -1, -1, -1, {ACT_DEBUG} }, |
| 264 | {RSP_ZLOG, -1, -1, -1, -1, -1, {ACT_DEBUG} }, |
| 265 | {RSP_ZMWI, -1, -1, -1, -1, -1, {ACT_DEBUG} }, |
| 266 | {RSP_ZABINFO, -1, -1, -1, -1, -1, {ACT_DEBUG} }, |
| 267 | {RSP_ZSMLSTCHG, -1, -1, -1, -1, -1, {ACT_DEBUG} }, |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 268 | |
Tilman Schmidt | c35a87f | 2009-10-25 09:30:47 +0000 | [diff] [blame] | 269 | {RSP_ZCAU, -1, -1, -1, -1, -1, {ACT_ZCAU} }, |
| 270 | {RSP_NONE, -1, -1, -1, -1, -1, {ACT_DEBUG} }, |
| 271 | {RSP_ANY, -1, -1, -1, -1, -1, {ACT_WARN} }, |
| 272 | {RSP_LAST} |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 273 | }; |
| 274 | |
Tilman Schmidt | c35a87f | 2009-10-25 09:30:47 +0000 | [diff] [blame] | 275 | /* 600: start dialing, 650: dial in progress, 800: connection is up, 700: ring, |
| 276 | * 400: hup, 750: accepted icall */ |
Tilman Schmidt | 528efc6 | 2009-05-13 12:44:17 +0000 | [diff] [blame] | 277 | struct reply_t gigaset_tab_cid[] = |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 278 | { |
Tilman Schmidt | c35a87f | 2009-10-25 09:30:47 +0000 | [diff] [blame] | 279 | /* resp_code, min_ConState, max_ConState, parameter, new_ConState, timeout, |
| 280 | * action, command */ |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 281 | |
Tilman Schmidt | c35a87f | 2009-10-25 09:30:47 +0000 | [diff] [blame] | 282 | /* dial */ |
| 283 | {EV_DIAL, -1, -1, -1, -1, -1, {ACT_DIAL} }, |
| 284 | {RSP_INIT, 0, 0, SEQ_DIAL, 601, 5, {ACT_CMD+AT_BC} }, |
| 285 | {RSP_OK, 601, 601, -1, 602, 5, {ACT_CMD+AT_HLC} }, |
| 286 | {RSP_NULL, 602, 602, -1, 603, 5, {ACT_CMD+AT_PROTO} }, |
| 287 | {RSP_OK, 602, 602, -1, 603, 5, {ACT_CMD+AT_PROTO} }, |
| 288 | {RSP_OK, 603, 603, -1, 604, 5, {ACT_CMD+AT_TYPE} }, |
| 289 | {RSP_OK, 604, 604, -1, 605, 5, {ACT_CMD+AT_MSN} }, |
| 290 | {RSP_NULL, 605, 605, -1, 606, 5, {ACT_CMD+AT_CLIP} }, |
| 291 | {RSP_OK, 605, 605, -1, 606, 5, {ACT_CMD+AT_CLIP} }, |
| 292 | {RSP_NULL, 606, 606, -1, 607, 5, {ACT_CMD+AT_ISO} }, |
| 293 | {RSP_OK, 606, 606, -1, 607, 5, {ACT_CMD+AT_ISO} }, |
| 294 | {RSP_OK, 607, 607, -1, 608, 5, {0}, "+VLS=17\r"}, |
| 295 | {RSP_OK, 608, 608, -1, 609, -1}, |
| 296 | {RSP_ZSAU, 609, 609, ZSAU_PROCEEDING, 610, 5, {ACT_CMD+AT_DIAL} }, |
| 297 | {RSP_OK, 610, 610, -1, 650, 0, {ACT_DIALING} }, |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 298 | |
Tilman Schmidt | c35a87f | 2009-10-25 09:30:47 +0000 | [diff] [blame] | 299 | {RSP_ERROR, 601, 610, -1, 0, 0, {ACT_ABORTDIAL} }, |
| 300 | {EV_TIMEOUT, 601, 610, -1, 0, 0, {ACT_ABORTDIAL} }, |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 301 | |
Tilman Schmidt | c35a87f | 2009-10-25 09:30:47 +0000 | [diff] [blame] | 302 | /* optional dialing responses */ |
| 303 | {EV_BC_OPEN, 650, 650, -1, 651, -1}, |
| 304 | {RSP_ZVLS, 609, 651, 17, -1, -1, {ACT_DEBUG} }, |
| 305 | {RSP_ZCTP, 610, 651, -1, -1, -1, {ACT_DEBUG} }, |
| 306 | {RSP_ZCPN, 610, 651, -1, -1, -1, {ACT_DEBUG} }, |
| 307 | {RSP_ZSAU, 650, 651, ZSAU_CALL_DELIVERED, -1, -1, {ACT_DEBUG} }, |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 308 | |
Tilman Schmidt | c35a87f | 2009-10-25 09:30:47 +0000 | [diff] [blame] | 309 | /* connect */ |
| 310 | {RSP_ZSAU, 650, 650, ZSAU_ACTIVE, 800, -1, {ACT_CONNECT} }, |
| 311 | {RSP_ZSAU, 651, 651, ZSAU_ACTIVE, 800, -1, {ACT_CONNECT, |
| 312 | ACT_NOTIFY_BC_UP} }, |
| 313 | {RSP_ZSAU, 750, 750, ZSAU_ACTIVE, 800, -1, {ACT_CONNECT} }, |
| 314 | {RSP_ZSAU, 751, 751, ZSAU_ACTIVE, 800, -1, {ACT_CONNECT, |
| 315 | ACT_NOTIFY_BC_UP} }, |
| 316 | {EV_BC_OPEN, 800, 800, -1, 800, -1, {ACT_NOTIFY_BC_UP} }, |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 317 | |
Tilman Schmidt | c35a87f | 2009-10-25 09:30:47 +0000 | [diff] [blame] | 318 | /* remote hangup */ |
| 319 | {RSP_ZSAU, 650, 651, ZSAU_DISCONNECT_IND, 0, 0, {ACT_REMOTEREJECT} }, |
| 320 | {RSP_ZSAU, 750, 751, ZSAU_DISCONNECT_IND, 0, 0, {ACT_REMOTEHUP} }, |
| 321 | {RSP_ZSAU, 800, 800, ZSAU_DISCONNECT_IND, 0, 0, {ACT_REMOTEHUP} }, |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 322 | |
Tilman Schmidt | c35a87f | 2009-10-25 09:30:47 +0000 | [diff] [blame] | 323 | /* hangup */ |
| 324 | {EV_HUP, -1, -1, -1, -1, -1, {ACT_HUP} }, |
| 325 | {RSP_INIT, -1, -1, SEQ_HUP, 401, 5, {0}, "+VLS=0\r"}, |
| 326 | {RSP_OK, 401, 401, -1, 402, 5}, |
| 327 | {RSP_ZVLS, 402, 402, 0, 403, 5}, |
| 328 | {RSP_ZSAU, 403, 403, ZSAU_DISCONNECT_REQ, -1, -1, {ACT_DEBUG} }, |
| 329 | {RSP_ZSAU, 403, 403, ZSAU_NULL, 0, 0, {ACT_DISCONNECT} }, |
| 330 | {RSP_NODEV, 401, 403, -1, 0, 0, {ACT_FAKEHUP} }, |
| 331 | {RSP_ERROR, 401, 401, -1, 0, 0, {ACT_ABORTHUP} }, |
| 332 | {EV_TIMEOUT, 401, 403, -1, 0, 0, {ACT_ABORTHUP} }, |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 333 | |
Tilman Schmidt | c35a87f | 2009-10-25 09:30:47 +0000 | [diff] [blame] | 334 | {EV_BC_CLOSED, 0, 0, -1, 0, -1, {ACT_NOTIFY_BC_DOWN} }, |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 335 | |
Tilman Schmidt | c35a87f | 2009-10-25 09:30:47 +0000 | [diff] [blame] | 336 | /* ring */ |
| 337 | {RSP_ZBC, 700, 700, -1, -1, -1, {0} }, |
| 338 | {RSP_ZHLC, 700, 700, -1, -1, -1, {0} }, |
| 339 | {RSP_NMBR, 700, 700, -1, -1, -1, {0} }, |
| 340 | {RSP_ZCPN, 700, 700, -1, -1, -1, {0} }, |
| 341 | {RSP_ZCTP, 700, 700, -1, -1, -1, {0} }, |
| 342 | {EV_TIMEOUT, 700, 700, -1, 720, 720, {ACT_ICALL} }, |
| 343 | {EV_BC_CLOSED, 720, 720, -1, 0, -1, {ACT_NOTIFY_BC_DOWN} }, |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 344 | |
Tilman Schmidt | c35a87f | 2009-10-25 09:30:47 +0000 | [diff] [blame] | 345 | /*accept icall*/ |
| 346 | {EV_ACCEPT, -1, -1, -1, -1, -1, {ACT_ACCEPT} }, |
| 347 | {RSP_INIT, 720, 720, SEQ_ACCEPT, 721, 5, {ACT_CMD+AT_PROTO} }, |
| 348 | {RSP_OK, 721, 721, -1, 722, 5, {ACT_CMD+AT_ISO} }, |
| 349 | {RSP_OK, 722, 722, -1, 723, 5, {0}, "+VLS=17\r"}, |
| 350 | {RSP_OK, 723, 723, -1, 724, 5, {0} }, |
| 351 | {RSP_ZVLS, 724, 724, 17, 750, 50, {ACT_ACCEPTED} }, |
| 352 | {RSP_ERROR, 721, 729, -1, 0, 0, {ACT_ABORTACCEPT} }, |
| 353 | {EV_TIMEOUT, 721, 729, -1, 0, 0, {ACT_ABORTACCEPT} }, |
| 354 | {RSP_ZSAU, 700, 729, ZSAU_NULL, 0, 0, {ACT_ABORTACCEPT} }, |
| 355 | {RSP_ZSAU, 700, 729, ZSAU_ACTIVE, 0, 0, {ACT_ABORTACCEPT} }, |
| 356 | {RSP_ZSAU, 700, 729, ZSAU_DISCONNECT_IND, 0, 0, {ACT_ABORTACCEPT} }, |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 357 | |
Tilman Schmidt | c35a87f | 2009-10-25 09:30:47 +0000 | [diff] [blame] | 358 | {EV_BC_OPEN, 750, 750, -1, 751, -1}, |
| 359 | {EV_TIMEOUT, 750, 751, -1, 0, 0, {ACT_CONNTIMEOUT} }, |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 360 | |
Tilman Schmidt | c35a87f | 2009-10-25 09:30:47 +0000 | [diff] [blame] | 361 | /* B channel closed (general case) */ |
| 362 | {EV_BC_CLOSED, -1, -1, -1, -1, -1, {ACT_NOTIFY_BC_DOWN} }, |
Tilman Schmidt | 73a8881 | 2006-04-22 02:35:30 -0700 | [diff] [blame] | 363 | |
Tilman Schmidt | c35a87f | 2009-10-25 09:30:47 +0000 | [diff] [blame] | 364 | /* misc. */ |
| 365 | {RSP_ZCON, -1, -1, -1, -1, -1, {ACT_DEBUG} }, |
| 366 | {RSP_ZCCR, -1, -1, -1, -1, -1, {ACT_DEBUG} }, |
| 367 | {RSP_ZAOC, -1, -1, -1, -1, -1, {ACT_DEBUG} }, |
| 368 | {RSP_ZCSTR, -1, -1, -1, -1, -1, {ACT_DEBUG} }, |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 369 | |
Tilman Schmidt | c35a87f | 2009-10-25 09:30:47 +0000 | [diff] [blame] | 370 | {RSP_ZCAU, -1, -1, -1, -1, -1, {ACT_ZCAU} }, |
| 371 | {RSP_NONE, -1, -1, -1, -1, -1, {ACT_DEBUG} }, |
| 372 | {RSP_ANY, -1, -1, -1, -1, -1, {ACT_WARN} }, |
| 373 | {RSP_LAST} |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 374 | }; |
| 375 | |
| 376 | |
Tilman Schmidt | 50e4fe9 | 2009-10-25 09:30:57 +0000 | [diff] [blame] | 377 | static const struct resp_type_t { |
| 378 | unsigned char *response; |
| 379 | int resp_code; |
| 380 | int type; |
| 381 | } resp_type[] = |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 382 | { |
Tilman Schmidt | 917f508 | 2006-04-10 22:55:00 -0700 | [diff] [blame] | 383 | {"OK", RSP_OK, RT_NOTHING}, |
| 384 | {"ERROR", RSP_ERROR, RT_NOTHING}, |
| 385 | {"ZSAU", RSP_ZSAU, RT_ZSAU}, |
| 386 | {"ZCAU", RSP_ZCAU, RT_ZCAU}, |
| 387 | {"RING", RSP_RING, RT_RING}, |
| 388 | {"ZGCI", RSP_ZGCI, RT_NUMBER}, |
| 389 | {"ZVLS", RSP_ZVLS, RT_NUMBER}, |
| 390 | {"ZCTP", RSP_ZCTP, RT_NUMBER}, |
| 391 | {"ZDLE", RSP_ZDLE, RT_NUMBER}, |
| 392 | {"ZCFGT", RSP_ZCFGT, RT_NUMBER}, |
| 393 | {"ZCCR", RSP_ZCCR, RT_NUMBER}, |
| 394 | {"ZMWI", RSP_ZMWI, RT_NUMBER}, |
| 395 | {"ZHLC", RSP_ZHLC, RT_STRING}, |
| 396 | {"ZBC", RSP_ZBC, RT_STRING}, |
| 397 | {"NMBR", RSP_NMBR, RT_STRING}, |
| 398 | {"ZCPN", RSP_ZCPN, RT_STRING}, |
| 399 | {"ZCON", RSP_ZCON, RT_STRING}, |
| 400 | {"ZAOC", RSP_ZAOC, RT_STRING}, |
| 401 | {"ZCSTR", RSP_ZCSTR, RT_STRING}, |
| 402 | {"ZCFG", RSP_ZCFG, RT_HEX}, |
| 403 | {"ZLOG", RSP_ZLOG, RT_NOTHING}, |
| 404 | {"ZABINFO", RSP_ZABINFO, RT_NOTHING}, |
| 405 | {"ZSMLSTCHG", RSP_ZSMLSTCHG, RT_NOTHING}, |
Tilman Schmidt | c35a87f | 2009-10-25 09:30:47 +0000 | [diff] [blame] | 406 | {NULL, 0, 0} |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 407 | }; |
| 408 | |
Tilman Schmidt | 50e4fe9 | 2009-10-25 09:30:57 +0000 | [diff] [blame] | 409 | static const struct zsau_resp_t { |
| 410 | unsigned char *str; |
| 411 | int code; |
| 412 | } zsau_resp[] = |
| 413 | { |
| 414 | {"OUTGOING_CALL_PROCEEDING", ZSAU_OUTGOING_CALL_PROCEEDING}, |
| 415 | {"CALL_DELIVERED", ZSAU_CALL_DELIVERED}, |
| 416 | {"ACTIVE", ZSAU_ACTIVE}, |
| 417 | {"DISCONNECT_IND", ZSAU_DISCONNECT_IND}, |
| 418 | {"NULL", ZSAU_NULL}, |
| 419 | {"DISCONNECT_REQ", ZSAU_DISCONNECT_REQ}, |
| 420 | {NULL, ZSAU_UNKNOWN} |
| 421 | }; |
| 422 | |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 423 | /* |
| 424 | * Get integer from char-pointer |
| 425 | */ |
| 426 | static int isdn_getnum(char *p) |
| 427 | { |
| 428 | int v = -1; |
| 429 | |
Tilman Schmidt | 1528b18 | 2010-02-22 13:09:52 +0000 | [diff] [blame] | 430 | gig_dbg(DEBUG_EVENT, "string: %s", p); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 431 | |
| 432 | while (*p >= '0' && *p <= '9') |
| 433 | v = ((v < 0) ? 0 : (v * 10)) + (int) ((*p++) - '0'); |
| 434 | if (*p) |
| 435 | v = -1; /* invalid Character */ |
| 436 | return v; |
| 437 | } |
| 438 | |
| 439 | /* |
| 440 | * Get integer from char-pointer |
| 441 | */ |
| 442 | static int isdn_gethex(char *p) |
| 443 | { |
| 444 | int v = 0; |
| 445 | int c; |
| 446 | |
Tilman Schmidt | 1528b18 | 2010-02-22 13:09:52 +0000 | [diff] [blame] | 447 | gig_dbg(DEBUG_EVENT, "string: %s", p); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 448 | |
| 449 | if (!*p) |
| 450 | return -1; |
| 451 | |
| 452 | do { |
| 453 | if (v > (INT_MAX - 15) / 16) |
| 454 | return -1; |
| 455 | c = *p; |
| 456 | if (c >= '0' && c <= '9') |
| 457 | c -= '0'; |
| 458 | else if (c >= 'a' && c <= 'f') |
| 459 | c -= 'a' - 10; |
| 460 | else if (c >= 'A' && c <= 'F') |
| 461 | c -= 'A' - 10; |
| 462 | else |
| 463 | return -1; |
| 464 | v = v * 16 + c; |
| 465 | } while (*++p); |
| 466 | |
| 467 | return v; |
| 468 | } |
| 469 | |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 470 | /* retrieve CID from parsed response |
| 471 | * returns 0 if no CID, -1 if invalid CID, or CID value 1..65535 |
| 472 | */ |
| 473 | static int cid_of_response(char *s) |
| 474 | { |
| 475 | int cid; |
| 476 | |
| 477 | if (s[-1] != ';') |
| 478 | return 0; /* no CID separator */ |
| 479 | cid = isdn_getnum(s); |
| 480 | if (cid < 0) |
| 481 | return 0; /* CID not numeric */ |
| 482 | if (cid < 1 || cid > 65535) |
| 483 | return -1; /* CID out of range */ |
| 484 | return cid; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 485 | } |
| 486 | |
Tilman Schmidt | 1cec972 | 2009-10-06 12:19:01 +0000 | [diff] [blame] | 487 | /** |
| 488 | * gigaset_handle_modem_response() - process received modem response |
| 489 | * @cs: device descriptor structure. |
| 490 | * |
| 491 | * Called by asyncdata/isocdata if a block of data received from the |
| 492 | * device must be processed as a modem command response. The data is |
| 493 | * already in the cs structure. |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 494 | */ |
| 495 | void gigaset_handle_modem_response(struct cardstate *cs) |
| 496 | { |
| 497 | unsigned char *argv[MAX_REC_PARAMS + 1]; |
| 498 | int params; |
| 499 | int i, j; |
Tilman Schmidt | 35dc845 | 2007-03-29 01:20:34 -0700 | [diff] [blame] | 500 | const struct resp_type_t *rt; |
Tilman Schmidt | 50e4fe9 | 2009-10-25 09:30:57 +0000 | [diff] [blame] | 501 | const struct zsau_resp_t *zr; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 502 | int curarg; |
| 503 | unsigned long flags; |
| 504 | unsigned next, tail, head; |
| 505 | struct event_t *event; |
| 506 | int resp_code; |
| 507 | int param_type; |
| 508 | int abort; |
| 509 | size_t len; |
| 510 | int cid; |
| 511 | int rawstring; |
| 512 | |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 513 | len = cs->cbytes; |
| 514 | if (!len) { |
| 515 | /* ignore additional LFs/CRs (M10x config mode or cx100) */ |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 516 | gig_dbg(DEBUG_MCMD, "skipped EOL [%02X]", cs->respdata[len]); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 517 | return; |
| 518 | } |
| 519 | cs->respdata[len] = 0; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 520 | argv[0] = cs->respdata; |
| 521 | params = 1; |
| 522 | if (cs->at_state.getstring) { |
| 523 | /* getstring only allowed without cid at the moment */ |
| 524 | cs->at_state.getstring = 0; |
| 525 | rawstring = 1; |
| 526 | cid = 0; |
| 527 | } else { |
| 528 | /* parse line */ |
| 529 | for (i = 0; i < len; i++) |
| 530 | switch (cs->respdata[i]) { |
| 531 | case ';': |
| 532 | case ',': |
| 533 | case '=': |
| 534 | if (params > MAX_REC_PARAMS) { |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 535 | dev_warn(cs->dev, |
| 536 | "too many parameters in response\n"); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 537 | /* need last parameter (might be CID) */ |
| 538 | params--; |
| 539 | } |
| 540 | argv[params++] = cs->respdata + i + 1; |
| 541 | } |
| 542 | |
| 543 | rawstring = 0; |
| 544 | cid = params > 1 ? cid_of_response(argv[params-1]) : 0; |
| 545 | if (cid < 0) { |
| 546 | gigaset_add_event(cs, &cs->at_state, RSP_INVAL, |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 547 | NULL, 0, NULL); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 548 | return; |
| 549 | } |
| 550 | |
| 551 | for (j = 1; j < params; ++j) |
| 552 | argv[j][-1] = 0; |
| 553 | |
Tilman Schmidt | 1528b18 | 2010-02-22 13:09:52 +0000 | [diff] [blame] | 554 | gig_dbg(DEBUG_EVENT, "CMD received: %s", argv[0]); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 555 | if (cid) { |
| 556 | --params; |
Tilman Schmidt | 1528b18 | 2010-02-22 13:09:52 +0000 | [diff] [blame] | 557 | gig_dbg(DEBUG_EVENT, "CID: %s", argv[params]); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 558 | } |
Tilman Schmidt | 1528b18 | 2010-02-22 13:09:52 +0000 | [diff] [blame] | 559 | gig_dbg(DEBUG_EVENT, "available params: %d", params - 1); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 560 | for (j = 1; j < params; j++) |
Tilman Schmidt | 1528b18 | 2010-02-22 13:09:52 +0000 | [diff] [blame] | 561 | gig_dbg(DEBUG_EVENT, "param %d: %s", j, argv[j]); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 562 | } |
| 563 | |
| 564 | spin_lock_irqsave(&cs->ev_lock, flags); |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 565 | head = cs->ev_head; |
| 566 | tail = cs->ev_tail; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 567 | |
| 568 | abort = 1; |
| 569 | curarg = 0; |
| 570 | while (curarg < params) { |
| 571 | next = (tail + 1) % MAX_EVENTS; |
| 572 | if (unlikely(next == head)) { |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 573 | dev_err(cs->dev, "event queue full\n"); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 574 | break; |
| 575 | } |
| 576 | |
| 577 | event = cs->events + tail; |
| 578 | event->at_state = NULL; |
| 579 | event->cid = cid; |
| 580 | event->ptr = NULL; |
| 581 | event->arg = NULL; |
| 582 | tail = next; |
| 583 | |
| 584 | if (rawstring) { |
| 585 | resp_code = RSP_STRING; |
| 586 | param_type = RT_STRING; |
| 587 | } else { |
| 588 | for (rt = resp_type; rt->response; ++rt) |
| 589 | if (!strcmp(argv[curarg], rt->response)) |
| 590 | break; |
| 591 | |
| 592 | if (!rt->response) { |
| 593 | event->type = RSP_UNKNOWN; |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 594 | dev_warn(cs->dev, |
| 595 | "unknown modem response: %s\n", |
| 596 | argv[curarg]); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 597 | break; |
| 598 | } |
| 599 | |
| 600 | resp_code = rt->resp_code; |
| 601 | param_type = rt->type; |
| 602 | ++curarg; |
| 603 | } |
| 604 | |
| 605 | event->type = resp_code; |
| 606 | |
| 607 | switch (param_type) { |
| 608 | case RT_NOTHING: |
| 609 | break; |
| 610 | case RT_RING: |
| 611 | if (!cid) { |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 612 | dev_err(cs->dev, |
| 613 | "received RING without CID!\n"); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 614 | event->type = RSP_INVAL; |
| 615 | abort = 1; |
| 616 | } else { |
| 617 | event->cid = 0; |
| 618 | event->parameter = cid; |
| 619 | abort = 0; |
| 620 | } |
| 621 | break; |
| 622 | case RT_ZSAU: |
| 623 | if (curarg >= params) { |
| 624 | event->parameter = ZSAU_NONE; |
| 625 | break; |
| 626 | } |
Tilman Schmidt | 50e4fe9 | 2009-10-25 09:30:57 +0000 | [diff] [blame] | 627 | for (zr = zsau_resp; zr->str; ++zr) |
| 628 | if (!strcmp(argv[curarg], zr->str)) |
| 629 | break; |
| 630 | event->parameter = zr->code; |
| 631 | if (!zr->str) |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 632 | dev_warn(cs->dev, |
| 633 | "%s: unknown parameter %s after ZSAU\n", |
| 634 | __func__, argv[curarg]); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 635 | ++curarg; |
| 636 | break; |
| 637 | case RT_STRING: |
| 638 | if (curarg < params) { |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 639 | event->ptr = kstrdup(argv[curarg], GFP_ATOMIC); |
| 640 | if (!event->ptr) |
| 641 | dev_err(cs->dev, "out of memory\n"); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 642 | ++curarg; |
| 643 | } |
Tilman Schmidt | 1528b18 | 2010-02-22 13:09:52 +0000 | [diff] [blame] | 644 | gig_dbg(DEBUG_EVENT, "string==%s", |
Tilman Schmidt | 236b87c | 2008-12-26 01:22:03 -0800 | [diff] [blame] | 645 | event->ptr ? (char *) event->ptr : "NULL"); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 646 | break; |
| 647 | case RT_ZCAU: |
| 648 | event->parameter = -1; |
| 649 | if (curarg + 1 < params) { |
| 650 | i = isdn_gethex(argv[curarg]); |
| 651 | j = isdn_gethex(argv[curarg + 1]); |
| 652 | if (i >= 0 && i < 256 && j >= 0 && j < 256) |
| 653 | event->parameter = (unsigned) i << 8 |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 654 | | j; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 655 | curarg += 2; |
| 656 | } else |
| 657 | curarg = params - 1; |
| 658 | break; |
| 659 | case RT_NUMBER: |
| 660 | case RT_HEX: |
| 661 | if (curarg < params) { |
| 662 | if (param_type == RT_HEX) |
| 663 | event->parameter = |
| 664 | isdn_gethex(argv[curarg]); |
| 665 | else |
| 666 | event->parameter = |
| 667 | isdn_getnum(argv[curarg]); |
| 668 | ++curarg; |
| 669 | } else |
| 670 | event->parameter = -1; |
Tilman Schmidt | 1528b18 | 2010-02-22 13:09:52 +0000 | [diff] [blame] | 671 | gig_dbg(DEBUG_EVENT, "parameter==%d", event->parameter); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 672 | break; |
| 673 | } |
| 674 | |
| 675 | if (resp_code == RSP_ZDLE) |
| 676 | cs->dle = event->parameter; |
| 677 | |
| 678 | if (abort) |
| 679 | break; |
| 680 | } |
| 681 | |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 682 | cs->ev_tail = tail; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 683 | spin_unlock_irqrestore(&cs->ev_lock, flags); |
| 684 | |
| 685 | if (curarg != params) |
Tilman Schmidt | 1528b18 | 2010-02-22 13:09:52 +0000 | [diff] [blame] | 686 | gig_dbg(DEBUG_EVENT, |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 687 | "invalid number of processed parameters: %d/%d", |
| 688 | curarg, params); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 689 | } |
| 690 | EXPORT_SYMBOL_GPL(gigaset_handle_modem_response); |
| 691 | |
| 692 | /* disconnect |
| 693 | * process closing of connection associated with given AT state structure |
| 694 | */ |
| 695 | static void disconnect(struct at_state_t **at_state_p) |
| 696 | { |
| 697 | unsigned long flags; |
Tilman Schmidt | d48c778 | 2006-04-10 22:55:08 -0700 | [diff] [blame] | 698 | struct bc_state *bcs = (*at_state_p)->bcs; |
| 699 | struct cardstate *cs = (*at_state_p)->cs; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 700 | |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 701 | spin_lock_irqsave(&cs->lock, flags); |
| 702 | ++(*at_state_p)->seq_index; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 703 | |
| 704 | /* revert to selected idle mode */ |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 705 | if (!cs->cidmode) { |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 706 | cs->at_state.pending_commands |= PC_UMMODE; |
Tilman Schmidt | 1528b18 | 2010-02-22 13:09:52 +0000 | [diff] [blame] | 707 | gig_dbg(DEBUG_EVENT, "Scheduling PC_UMMODE"); |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 708 | cs->commands_pending = 1; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 709 | } |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 710 | spin_unlock_irqrestore(&cs->lock, flags); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 711 | |
| 712 | if (bcs) { |
| 713 | /* B channel assigned: invoke hardware specific handler */ |
| 714 | cs->ops->close_bchannel(bcs); |
Tilman Schmidt | 3305adf | 2009-10-06 12:18:26 +0000 | [diff] [blame] | 715 | /* notify LL */ |
| 716 | if (bcs->chstate & (CHS_D_UP | CHS_NOTIFY_LL)) { |
| 717 | bcs->chstate &= ~(CHS_D_UP | CHS_NOTIFY_LL); |
Tilman Schmidt | 088ec0c | 2009-10-06 12:19:07 +0000 | [diff] [blame] | 718 | gigaset_isdn_hupD(bcs); |
Tilman Schmidt | 3305adf | 2009-10-06 12:18:26 +0000 | [diff] [blame] | 719 | } |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 720 | } else { |
| 721 | /* no B channel assigned: just deallocate */ |
| 722 | spin_lock_irqsave(&cs->lock, flags); |
| 723 | list_del(&(*at_state_p)->list); |
| 724 | kfree(*at_state_p); |
| 725 | *at_state_p = NULL; |
| 726 | spin_unlock_irqrestore(&cs->lock, flags); |
| 727 | } |
| 728 | } |
| 729 | |
| 730 | /* get_free_channel |
| 731 | * get a free AT state structure: either one of those associated with the |
| 732 | * B channels of the Gigaset device, or if none of those is available, |
| 733 | * a newly allocated one with bcs=NULL |
| 734 | * The structure should be freed by calling disconnect() after use. |
| 735 | */ |
| 736 | static inline struct at_state_t *get_free_channel(struct cardstate *cs, |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 737 | int cid) |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 738 | /* cids: >0: siemens-cid |
| 739 | 0: without cid |
| 740 | -1: no cid assigned yet |
| 741 | */ |
| 742 | { |
| 743 | unsigned long flags; |
| 744 | int i; |
| 745 | struct at_state_t *ret; |
| 746 | |
| 747 | for (i = 0; i < cs->channels; ++i) |
| 748 | if (gigaset_get_channel(cs->bcs + i)) { |
| 749 | ret = &cs->bcs[i].at_state; |
| 750 | ret->cid = cid; |
| 751 | return ret; |
| 752 | } |
| 753 | |
| 754 | spin_lock_irqsave(&cs->lock, flags); |
| 755 | ret = kmalloc(sizeof(struct at_state_t), GFP_ATOMIC); |
| 756 | if (ret) { |
| 757 | gigaset_at_init(ret, NULL, cs, cid); |
| 758 | list_add(&ret->list, &cs->temp_at_states); |
| 759 | } |
| 760 | spin_unlock_irqrestore(&cs->lock, flags); |
| 761 | return ret; |
| 762 | } |
| 763 | |
| 764 | static void init_failed(struct cardstate *cs, int mode) |
| 765 | { |
| 766 | int i; |
| 767 | struct at_state_t *at_state; |
| 768 | |
| 769 | cs->at_state.pending_commands &= ~PC_INIT; |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 770 | cs->mode = mode; |
| 771 | cs->mstate = MS_UNINITIALIZED; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 772 | gigaset_free_channels(cs); |
| 773 | for (i = 0; i < cs->channels; ++i) { |
| 774 | at_state = &cs->bcs[i].at_state; |
| 775 | if (at_state->pending_commands & PC_CID) { |
| 776 | at_state->pending_commands &= ~PC_CID; |
| 777 | at_state->pending_commands |= PC_NOCID; |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 778 | cs->commands_pending = 1; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 779 | } |
| 780 | } |
| 781 | } |
| 782 | |
| 783 | static void schedule_init(struct cardstate *cs, int state) |
| 784 | { |
| 785 | if (cs->at_state.pending_commands & PC_INIT) { |
Tilman Schmidt | 1528b18 | 2010-02-22 13:09:52 +0000 | [diff] [blame] | 786 | gig_dbg(DEBUG_EVENT, "not scheduling PC_INIT again"); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 787 | return; |
| 788 | } |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 789 | cs->mstate = state; |
| 790 | cs->mode = M_UNKNOWN; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 791 | gigaset_block_channels(cs); |
| 792 | cs->at_state.pending_commands |= PC_INIT; |
Tilman Schmidt | 1528b18 | 2010-02-22 13:09:52 +0000 | [diff] [blame] | 793 | gig_dbg(DEBUG_EVENT, "Scheduling PC_INIT"); |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 794 | cs->commands_pending = 1; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 795 | } |
| 796 | |
Tilman Schmidt | 917f508 | 2006-04-10 22:55:00 -0700 | [diff] [blame] | 797 | /* Add "AT" to a command, add the cid, dle encode it, send the result to the |
| 798 | hardware. */ |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 799 | static void send_command(struct cardstate *cs, const char *cmd, int cid, |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 800 | int dle, gfp_t kmallocflags) |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 801 | { |
| 802 | size_t cmdlen, buflen; |
| 803 | char *cmdpos, *cmdbuf, *cmdtail; |
| 804 | |
| 805 | cmdlen = strlen(cmd); |
| 806 | buflen = 11 + cmdlen; |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 807 | if (unlikely(buflen <= cmdlen)) { |
| 808 | dev_err(cs->dev, "integer overflow in buflen\n"); |
| 809 | return; |
| 810 | } |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 811 | |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 812 | cmdbuf = kmalloc(buflen, kmallocflags); |
| 813 | if (unlikely(!cmdbuf)) { |
| 814 | dev_err(cs->dev, "out of memory\n"); |
| 815 | return; |
| 816 | } |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 817 | |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 818 | cmdpos = cmdbuf + 9; |
| 819 | cmdtail = cmdpos + cmdlen; |
| 820 | memcpy(cmdpos, cmd, cmdlen); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 821 | |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 822 | if (cid > 0 && cid <= 65535) { |
| 823 | do { |
| 824 | *--cmdpos = '0' + cid % 10; |
| 825 | cid /= 10; |
| 826 | ++cmdlen; |
| 827 | } while (cid); |
| 828 | } |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 829 | |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 830 | cmdlen += 2; |
| 831 | *--cmdpos = 'T'; |
| 832 | *--cmdpos = 'A'; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 833 | |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 834 | if (dle) { |
| 835 | cmdlen += 4; |
| 836 | *--cmdpos = '('; |
| 837 | *--cmdpos = 0x10; |
| 838 | *cmdtail++ = 0x10; |
| 839 | *cmdtail++ = ')'; |
| 840 | } |
| 841 | |
| 842 | cs->ops->write_cmd(cs, cmdpos, cmdlen, NULL); |
| 843 | kfree(cmdbuf); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 844 | } |
| 845 | |
| 846 | static struct at_state_t *at_state_from_cid(struct cardstate *cs, int cid) |
| 847 | { |
| 848 | struct at_state_t *at_state; |
| 849 | int i; |
| 850 | unsigned long flags; |
| 851 | |
| 852 | if (cid == 0) |
| 853 | return &cs->at_state; |
| 854 | |
| 855 | for (i = 0; i < cs->channels; ++i) |
| 856 | if (cid == cs->bcs[i].at_state.cid) |
| 857 | return &cs->bcs[i].at_state; |
| 858 | |
| 859 | spin_lock_irqsave(&cs->lock, flags); |
| 860 | |
| 861 | list_for_each_entry(at_state, &cs->temp_at_states, list) |
| 862 | if (cid == at_state->cid) { |
| 863 | spin_unlock_irqrestore(&cs->lock, flags); |
| 864 | return at_state; |
| 865 | } |
| 866 | |
| 867 | spin_unlock_irqrestore(&cs->lock, flags); |
| 868 | |
| 869 | return NULL; |
| 870 | } |
| 871 | |
| 872 | static void bchannel_down(struct bc_state *bcs) |
| 873 | { |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 874 | if (bcs->chstate & CHS_B_UP) { |
| 875 | bcs->chstate &= ~CHS_B_UP; |
Tilman Schmidt | 088ec0c | 2009-10-06 12:19:07 +0000 | [diff] [blame] | 876 | gigaset_isdn_hupB(bcs); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 877 | } |
| 878 | |
| 879 | if (bcs->chstate & (CHS_D_UP | CHS_NOTIFY_LL)) { |
| 880 | bcs->chstate &= ~(CHS_D_UP | CHS_NOTIFY_LL); |
Tilman Schmidt | 088ec0c | 2009-10-06 12:19:07 +0000 | [diff] [blame] | 881 | gigaset_isdn_hupD(bcs); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 882 | } |
| 883 | |
| 884 | gigaset_free_channel(bcs); |
| 885 | |
| 886 | gigaset_bcs_reinit(bcs); |
| 887 | } |
| 888 | |
| 889 | static void bchannel_up(struct bc_state *bcs) |
| 890 | { |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 891 | if (bcs->chstate & CHS_B_UP) { |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 892 | dev_notice(bcs->cs->dev, "%s: B channel already up\n", |
| 893 | __func__); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 894 | return; |
| 895 | } |
| 896 | |
| 897 | bcs->chstate |= CHS_B_UP; |
Tilman Schmidt | 088ec0c | 2009-10-06 12:19:07 +0000 | [diff] [blame] | 898 | gigaset_isdn_connB(bcs); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 899 | } |
| 900 | |
Tilman Schmidt | c35a87f | 2009-10-25 09:30:47 +0000 | [diff] [blame] | 901 | static void start_dial(struct at_state_t *at_state, void *data, |
| 902 | unsigned seq_index) |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 903 | { |
| 904 | struct bc_state *bcs = at_state->bcs; |
| 905 | struct cardstate *cs = at_state->cs; |
Tilman Schmidt | 088ec0c | 2009-10-06 12:19:07 +0000 | [diff] [blame] | 906 | char **commands = data; |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 907 | unsigned long flags; |
Tilman Schmidt | 088ec0c | 2009-10-06 12:19:07 +0000 | [diff] [blame] | 908 | int i; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 909 | |
| 910 | bcs->chstate |= CHS_NOTIFY_LL; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 911 | |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 912 | spin_lock_irqsave(&cs->lock, flags); |
| 913 | if (at_state->seq_index != seq_index) { |
| 914 | spin_unlock_irqrestore(&cs->lock, flags); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 915 | goto error; |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 916 | } |
| 917 | spin_unlock_irqrestore(&cs->lock, flags); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 918 | |
Tilman Schmidt | 088ec0c | 2009-10-06 12:19:07 +0000 | [diff] [blame] | 919 | for (i = 0; i < AT_NUM; ++i) { |
| 920 | kfree(bcs->commands[i]); |
| 921 | bcs->commands[i] = commands[i]; |
| 922 | } |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 923 | |
| 924 | at_state->pending_commands |= PC_CID; |
Tilman Schmidt | 1528b18 | 2010-02-22 13:09:52 +0000 | [diff] [blame] | 925 | gig_dbg(DEBUG_EVENT, "Scheduling PC_CID"); |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 926 | cs->commands_pending = 1; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 927 | return; |
| 928 | |
| 929 | error: |
Tilman Schmidt | 088ec0c | 2009-10-06 12:19:07 +0000 | [diff] [blame] | 930 | for (i = 0; i < AT_NUM; ++i) { |
| 931 | kfree(commands[i]); |
| 932 | commands[i] = NULL; |
| 933 | } |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 934 | at_state->pending_commands |= PC_NOCID; |
Tilman Schmidt | 1528b18 | 2010-02-22 13:09:52 +0000 | [diff] [blame] | 935 | gig_dbg(DEBUG_EVENT, "Scheduling PC_NOCID"); |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 936 | cs->commands_pending = 1; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 937 | return; |
| 938 | } |
| 939 | |
| 940 | static void start_accept(struct at_state_t *at_state) |
| 941 | { |
| 942 | struct cardstate *cs = at_state->cs; |
Tilman Schmidt | 088ec0c | 2009-10-06 12:19:07 +0000 | [diff] [blame] | 943 | struct bc_state *bcs = at_state->bcs; |
| 944 | int i; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 945 | |
Tilman Schmidt | 088ec0c | 2009-10-06 12:19:07 +0000 | [diff] [blame] | 946 | for (i = 0; i < AT_NUM; ++i) { |
| 947 | kfree(bcs->commands[i]); |
| 948 | bcs->commands[i] = NULL; |
| 949 | } |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 950 | |
Tilman Schmidt | 088ec0c | 2009-10-06 12:19:07 +0000 | [diff] [blame] | 951 | bcs->commands[AT_PROTO] = kmalloc(9, GFP_ATOMIC); |
| 952 | bcs->commands[AT_ISO] = kmalloc(9, GFP_ATOMIC); |
| 953 | if (!bcs->commands[AT_PROTO] || !bcs->commands[AT_ISO]) { |
| 954 | dev_err(at_state->cs->dev, "out of memory\n"); |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 955 | /* error reset */ |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 956 | at_state->pending_commands |= PC_HUP; |
Tilman Schmidt | 1528b18 | 2010-02-22 13:09:52 +0000 | [diff] [blame] | 957 | gig_dbg(DEBUG_EVENT, "Scheduling PC_HUP"); |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 958 | cs->commands_pending = 1; |
Tilman Schmidt | 088ec0c | 2009-10-06 12:19:07 +0000 | [diff] [blame] | 959 | return; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 960 | } |
Tilman Schmidt | 088ec0c | 2009-10-06 12:19:07 +0000 | [diff] [blame] | 961 | |
| 962 | snprintf(bcs->commands[AT_PROTO], 9, "^SBPR=%u\r", bcs->proto2); |
| 963 | snprintf(bcs->commands[AT_ISO], 9, "^SISO=%u\r", bcs->channel + 1); |
| 964 | |
| 965 | at_state->pending_commands |= PC_ACCEPT; |
Tilman Schmidt | 1528b18 | 2010-02-22 13:09:52 +0000 | [diff] [blame] | 966 | gig_dbg(DEBUG_EVENT, "Scheduling PC_ACCEPT"); |
Tilman Schmidt | 088ec0c | 2009-10-06 12:19:07 +0000 | [diff] [blame] | 967 | cs->commands_pending = 1; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 968 | } |
| 969 | |
| 970 | static void do_start(struct cardstate *cs) |
| 971 | { |
| 972 | gigaset_free_channels(cs); |
| 973 | |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 974 | if (cs->mstate != MS_LOCKED) |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 975 | schedule_init(cs, MS_INIT); |
| 976 | |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 977 | cs->isdn_up = 1; |
Tilman Schmidt | 088ec0c | 2009-10-06 12:19:07 +0000 | [diff] [blame] | 978 | gigaset_isdn_start(cs); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 979 | |
| 980 | cs->waiting = 0; |
| 981 | wake_up(&cs->waitqueue); |
| 982 | } |
| 983 | |
| 984 | static void finish_shutdown(struct cardstate *cs) |
| 985 | { |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 986 | if (cs->mstate != MS_LOCKED) { |
| 987 | cs->mstate = MS_UNINITIALIZED; |
| 988 | cs->mode = M_UNKNOWN; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 989 | } |
| 990 | |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 991 | /* Tell the LL that the device is not available .. */ |
| 992 | if (cs->isdn_up) { |
| 993 | cs->isdn_up = 0; |
Tilman Schmidt | 088ec0c | 2009-10-06 12:19:07 +0000 | [diff] [blame] | 994 | gigaset_isdn_stop(cs); |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 995 | } |
| 996 | |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 997 | /* The rest is done by cleanup_cs () in user mode. */ |
| 998 | |
| 999 | cs->cmd_result = -ENODEV; |
| 1000 | cs->waiting = 0; |
Tilman Schmidt | 2869b23 | 2007-02-12 00:52:34 -0800 | [diff] [blame] | 1001 | wake_up(&cs->waitqueue); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1002 | } |
| 1003 | |
| 1004 | static void do_shutdown(struct cardstate *cs) |
| 1005 | { |
| 1006 | gigaset_block_channels(cs); |
| 1007 | |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 1008 | if (cs->mstate == MS_READY) { |
| 1009 | cs->mstate = MS_SHUTDOWN; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1010 | cs->at_state.pending_commands |= PC_SHUTDOWN; |
Tilman Schmidt | 1528b18 | 2010-02-22 13:09:52 +0000 | [diff] [blame] | 1011 | gig_dbg(DEBUG_EVENT, "Scheduling PC_SHUTDOWN"); |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 1012 | cs->commands_pending = 1; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1013 | } else |
| 1014 | finish_shutdown(cs); |
| 1015 | } |
| 1016 | |
| 1017 | static void do_stop(struct cardstate *cs) |
| 1018 | { |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 1019 | unsigned long flags; |
| 1020 | |
| 1021 | spin_lock_irqsave(&cs->lock, flags); |
| 1022 | cs->connected = 0; |
| 1023 | spin_unlock_irqrestore(&cs->lock, flags); |
| 1024 | |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1025 | do_shutdown(cs); |
| 1026 | } |
| 1027 | |
| 1028 | /* Entering cid mode or getting a cid failed: |
| 1029 | * try to initialize the device and try again. |
| 1030 | * |
| 1031 | * channel >= 0: getting cid for the channel failed |
| 1032 | * channel < 0: entering cid mode failed |
| 1033 | * |
| 1034 | * returns 0 on failure |
| 1035 | */ |
| 1036 | static int reinit_and_retry(struct cardstate *cs, int channel) |
| 1037 | { |
| 1038 | int i; |
| 1039 | |
| 1040 | if (--cs->retry_count <= 0) |
| 1041 | return 0; |
| 1042 | |
| 1043 | for (i = 0; i < cs->channels; ++i) |
| 1044 | if (cs->bcs[i].at_state.cid > 0) |
| 1045 | return 0; |
| 1046 | |
| 1047 | if (channel < 0) |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1048 | dev_warn(cs->dev, |
| 1049 | "Could not enter cid mode. Reinit device and try again.\n"); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1050 | else { |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1051 | dev_warn(cs->dev, |
| 1052 | "Could not get a call id. Reinit device and try again.\n"); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1053 | cs->bcs[channel].at_state.pending_commands |= PC_CID; |
| 1054 | } |
| 1055 | schedule_init(cs, MS_INIT); |
| 1056 | return 1; |
| 1057 | } |
| 1058 | |
| 1059 | static int at_state_invalid(struct cardstate *cs, |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1060 | struct at_state_t *test_ptr) |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1061 | { |
| 1062 | unsigned long flags; |
| 1063 | unsigned channel; |
| 1064 | struct at_state_t *at_state; |
| 1065 | int retval = 0; |
| 1066 | |
| 1067 | spin_lock_irqsave(&cs->lock, flags); |
| 1068 | |
| 1069 | if (test_ptr == &cs->at_state) |
| 1070 | goto exit; |
| 1071 | |
| 1072 | list_for_each_entry(at_state, &cs->temp_at_states, list) |
| 1073 | if (at_state == test_ptr) |
| 1074 | goto exit; |
| 1075 | |
| 1076 | for (channel = 0; channel < cs->channels; ++channel) |
| 1077 | if (&cs->bcs[channel].at_state == test_ptr) |
| 1078 | goto exit; |
| 1079 | |
| 1080 | retval = 1; |
| 1081 | exit: |
| 1082 | spin_unlock_irqrestore(&cs->lock, flags); |
| 1083 | return retval; |
| 1084 | } |
| 1085 | |
| 1086 | static void handle_icall(struct cardstate *cs, struct bc_state *bcs, |
| 1087 | struct at_state_t **p_at_state) |
| 1088 | { |
| 1089 | int retval; |
| 1090 | struct at_state_t *at_state = *p_at_state; |
| 1091 | |
| 1092 | retval = gigaset_isdn_icall(at_state); |
| 1093 | switch (retval) { |
| 1094 | case ICALL_ACCEPT: |
| 1095 | break; |
| 1096 | default: |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1097 | dev_err(cs->dev, "internal error: disposition=%d\n", retval); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1098 | /* --v-- fall through --v-- */ |
| 1099 | case ICALL_IGNORE: |
| 1100 | case ICALL_REJECT: |
| 1101 | /* hang up actively |
| 1102 | * Device doc says that would reject the call. |
| 1103 | * In fact it doesn't. |
| 1104 | */ |
| 1105 | at_state->pending_commands |= PC_HUP; |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 1106 | cs->commands_pending = 1; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1107 | break; |
| 1108 | } |
| 1109 | } |
| 1110 | |
| 1111 | static int do_lock(struct cardstate *cs) |
| 1112 | { |
| 1113 | int mode; |
| 1114 | int i; |
| 1115 | |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 1116 | switch (cs->mstate) { |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1117 | case MS_UNINITIALIZED: |
| 1118 | case MS_READY: |
| 1119 | if (cs->cur_at_seq || !list_empty(&cs->temp_at_states) || |
| 1120 | cs->at_state.pending_commands) |
| 1121 | return -EBUSY; |
| 1122 | |
| 1123 | for (i = 0; i < cs->channels; ++i) |
| 1124 | if (cs->bcs[i].at_state.pending_commands) |
| 1125 | return -EBUSY; |
| 1126 | |
| 1127 | if (!gigaset_get_channels(cs)) |
| 1128 | return -EBUSY; |
| 1129 | |
| 1130 | break; |
| 1131 | case MS_LOCKED: |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1132 | break; |
| 1133 | default: |
| 1134 | return -EBUSY; |
| 1135 | } |
| 1136 | |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 1137 | mode = cs->mode; |
| 1138 | cs->mstate = MS_LOCKED; |
| 1139 | cs->mode = M_UNKNOWN; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1140 | |
| 1141 | return mode; |
| 1142 | } |
| 1143 | |
| 1144 | static int do_unlock(struct cardstate *cs) |
| 1145 | { |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 1146 | if (cs->mstate != MS_LOCKED) |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1147 | return -EINVAL; |
| 1148 | |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 1149 | cs->mstate = MS_UNINITIALIZED; |
| 1150 | cs->mode = M_UNKNOWN; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1151 | gigaset_free_channels(cs); |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 1152 | if (cs->connected) |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1153 | schedule_init(cs, MS_INIT); |
| 1154 | |
| 1155 | return 0; |
| 1156 | } |
| 1157 | |
| 1158 | static void do_action(int action, struct cardstate *cs, |
| 1159 | struct bc_state *bcs, |
| 1160 | struct at_state_t **p_at_state, char **pp_command, |
| 1161 | int *p_genresp, int *p_resp_code, |
| 1162 | struct event_t *ev) |
| 1163 | { |
| 1164 | struct at_state_t *at_state = *p_at_state; |
| 1165 | struct at_state_t *at_state2; |
| 1166 | unsigned long flags; |
| 1167 | |
| 1168 | int channel; |
| 1169 | |
| 1170 | unsigned char *s, *e; |
| 1171 | int i; |
| 1172 | unsigned long val; |
| 1173 | |
| 1174 | switch (action) { |
| 1175 | case ACT_NOTHING: |
| 1176 | break; |
| 1177 | case ACT_TIMEOUT: |
| 1178 | at_state->waiting = 1; |
| 1179 | break; |
| 1180 | case ACT_INIT: |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1181 | cs->at_state.pending_commands &= ~PC_INIT; |
| 1182 | cs->cur_at_seq = SEQ_NONE; |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 1183 | cs->mode = M_UNIMODEM; |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 1184 | spin_lock_irqsave(&cs->lock, flags); |
| 1185 | if (!cs->cidmode) { |
| 1186 | spin_unlock_irqrestore(&cs->lock, flags); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1187 | gigaset_free_channels(cs); |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 1188 | cs->mstate = MS_READY; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1189 | break; |
| 1190 | } |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 1191 | spin_unlock_irqrestore(&cs->lock, flags); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1192 | cs->at_state.pending_commands |= PC_CIDMODE; |
Tilman Schmidt | 1528b18 | 2010-02-22 13:09:52 +0000 | [diff] [blame] | 1193 | gig_dbg(DEBUG_EVENT, "Scheduling PC_CIDMODE"); |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 1194 | cs->commands_pending = 1; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1195 | break; |
| 1196 | case ACT_FAILINIT: |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1197 | dev_warn(cs->dev, "Could not initialize the device.\n"); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1198 | cs->dle = 0; |
| 1199 | init_failed(cs, M_UNKNOWN); |
| 1200 | cs->cur_at_seq = SEQ_NONE; |
| 1201 | break; |
| 1202 | case ACT_CONFIGMODE: |
| 1203 | init_failed(cs, M_CONFIG); |
| 1204 | cs->cur_at_seq = SEQ_NONE; |
| 1205 | break; |
| 1206 | case ACT_SETDLE1: |
| 1207 | cs->dle = 1; |
| 1208 | /* cs->inbuf[0].inputstate |= INS_command | INS_DLE_command; */ |
| 1209 | cs->inbuf[0].inputstate &= |
| 1210 | ~(INS_command | INS_DLE_command); |
| 1211 | break; |
| 1212 | case ACT_SETDLE0: |
| 1213 | cs->dle = 0; |
| 1214 | cs->inbuf[0].inputstate = |
| 1215 | (cs->inbuf[0].inputstate & ~INS_DLE_command) |
| 1216 | | INS_command; |
| 1217 | break; |
| 1218 | case ACT_CMODESET: |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 1219 | if (cs->mstate == MS_INIT || cs->mstate == MS_RECOVER) { |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1220 | gigaset_free_channels(cs); |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 1221 | cs->mstate = MS_READY; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1222 | } |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 1223 | cs->mode = M_CID; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1224 | cs->cur_at_seq = SEQ_NONE; |
| 1225 | break; |
| 1226 | case ACT_UMODESET: |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 1227 | cs->mode = M_UNIMODEM; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1228 | cs->cur_at_seq = SEQ_NONE; |
| 1229 | break; |
| 1230 | case ACT_FAILCMODE: |
| 1231 | cs->cur_at_seq = SEQ_NONE; |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 1232 | if (cs->mstate == MS_INIT || cs->mstate == MS_RECOVER) { |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1233 | init_failed(cs, M_UNKNOWN); |
| 1234 | break; |
| 1235 | } |
| 1236 | if (!reinit_and_retry(cs, -1)) |
| 1237 | schedule_init(cs, MS_RECOVER); |
| 1238 | break; |
| 1239 | case ACT_FAILUMODE: |
| 1240 | cs->cur_at_seq = SEQ_NONE; |
| 1241 | schedule_init(cs, MS_RECOVER); |
| 1242 | break; |
| 1243 | case ACT_HUPMODEM: |
| 1244 | /* send "+++" (hangup in unimodem mode) */ |
Tilman Schmidt | 698e3ed | 2006-06-26 00:25:34 -0700 | [diff] [blame] | 1245 | if (cs->connected) |
| 1246 | cs->ops->write_cmd(cs, "+++", 3, NULL); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1247 | break; |
| 1248 | case ACT_RING: |
| 1249 | /* get fresh AT state structure for new CID */ |
| 1250 | at_state2 = get_free_channel(cs, ev->parameter); |
| 1251 | if (!at_state2) { |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1252 | dev_warn(cs->dev, |
| 1253 | "RING ignored: could not allocate channel structure\n"); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1254 | break; |
| 1255 | } |
| 1256 | |
| 1257 | /* initialize AT state structure |
| 1258 | * note that bcs may be NULL if no B channel is free |
| 1259 | */ |
| 1260 | at_state2->ConState = 700; |
Tilman Schmidt | 3a0a3a6 | 2010-03-14 12:58:05 +0000 | [diff] [blame] | 1261 | for (i = 0; i < STR_NUM; ++i) { |
| 1262 | kfree(at_state2->str_var[i]); |
| 1263 | at_state2->str_var[i] = NULL; |
| 1264 | } |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1265 | at_state2->int_var[VAR_ZCTP] = -1; |
| 1266 | |
| 1267 | spin_lock_irqsave(&cs->lock, flags); |
| 1268 | at_state2->timer_expires = RING_TIMEOUT; |
| 1269 | at_state2->timer_active = 1; |
| 1270 | spin_unlock_irqrestore(&cs->lock, flags); |
| 1271 | break; |
| 1272 | case ACT_ICALL: |
| 1273 | handle_icall(cs, bcs, p_at_state); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1274 | break; |
| 1275 | case ACT_FAILSDOWN: |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1276 | dev_warn(cs->dev, "Could not shut down the device.\n"); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1277 | /* fall through */ |
| 1278 | case ACT_FAKESDOWN: |
| 1279 | case ACT_SDOWN: |
| 1280 | cs->cur_at_seq = SEQ_NONE; |
| 1281 | finish_shutdown(cs); |
| 1282 | break; |
| 1283 | case ACT_CONNECT: |
| 1284 | if (cs->onechannel) { |
| 1285 | at_state->pending_commands |= PC_DLE1; |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 1286 | cs->commands_pending = 1; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1287 | break; |
| 1288 | } |
| 1289 | bcs->chstate |= CHS_D_UP; |
Tilman Schmidt | 088ec0c | 2009-10-06 12:19:07 +0000 | [diff] [blame] | 1290 | gigaset_isdn_connD(bcs); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1291 | cs->ops->init_bchannel(bcs); |
| 1292 | break; |
| 1293 | case ACT_DLE1: |
| 1294 | cs->cur_at_seq = SEQ_NONE; |
| 1295 | bcs = cs->bcs + cs->curchannel; |
| 1296 | |
| 1297 | bcs->chstate |= CHS_D_UP; |
Tilman Schmidt | 088ec0c | 2009-10-06 12:19:07 +0000 | [diff] [blame] | 1298 | gigaset_isdn_connD(bcs); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1299 | cs->ops->init_bchannel(bcs); |
| 1300 | break; |
| 1301 | case ACT_FAKEHUP: |
| 1302 | at_state->int_var[VAR_ZSAU] = ZSAU_NULL; |
| 1303 | /* fall through */ |
| 1304 | case ACT_DISCONNECT: |
| 1305 | cs->cur_at_seq = SEQ_NONE; |
| 1306 | at_state->cid = -1; |
| 1307 | if (bcs && cs->onechannel && cs->dle) { |
| 1308 | /* Check for other open channels not needed: |
| 1309 | * DLE only used for M10x with one B channel. |
| 1310 | */ |
| 1311 | at_state->pending_commands |= PC_DLE0; |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 1312 | cs->commands_pending = 1; |
Tilman Schmidt | 698e3ed | 2006-06-26 00:25:34 -0700 | [diff] [blame] | 1313 | } else |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1314 | disconnect(p_at_state); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1315 | break; |
| 1316 | case ACT_FAKEDLE0: |
| 1317 | at_state->int_var[VAR_ZDLE] = 0; |
| 1318 | cs->dle = 0; |
| 1319 | /* fall through */ |
| 1320 | case ACT_DLE0: |
| 1321 | cs->cur_at_seq = SEQ_NONE; |
| 1322 | at_state2 = &cs->bcs[cs->curchannel].at_state; |
| 1323 | disconnect(&at_state2); |
| 1324 | break; |
| 1325 | case ACT_ABORTHUP: |
| 1326 | cs->cur_at_seq = SEQ_NONE; |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1327 | dev_warn(cs->dev, "Could not hang up.\n"); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1328 | at_state->cid = -1; |
| 1329 | if (bcs && cs->onechannel) |
| 1330 | at_state->pending_commands |= PC_DLE0; |
Tilman Schmidt | 698e3ed | 2006-06-26 00:25:34 -0700 | [diff] [blame] | 1331 | else |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1332 | disconnect(p_at_state); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1333 | schedule_init(cs, MS_RECOVER); |
| 1334 | break; |
| 1335 | case ACT_FAILDLE0: |
| 1336 | cs->cur_at_seq = SEQ_NONE; |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1337 | dev_warn(cs->dev, "Could not leave DLE mode.\n"); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1338 | at_state2 = &cs->bcs[cs->curchannel].at_state; |
| 1339 | disconnect(&at_state2); |
| 1340 | schedule_init(cs, MS_RECOVER); |
| 1341 | break; |
| 1342 | case ACT_FAILDLE1: |
| 1343 | cs->cur_at_seq = SEQ_NONE; |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1344 | dev_warn(cs->dev, |
| 1345 | "Could not enter DLE mode. Trying to hang up.\n"); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1346 | channel = cs->curchannel; |
| 1347 | cs->bcs[channel].at_state.pending_commands |= PC_HUP; |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 1348 | cs->commands_pending = 1; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1349 | break; |
| 1350 | |
| 1351 | case ACT_CID: /* got cid; start dialing */ |
| 1352 | cs->cur_at_seq = SEQ_NONE; |
| 1353 | channel = cs->curchannel; |
| 1354 | if (ev->parameter > 0 && ev->parameter <= 65535) { |
| 1355 | cs->bcs[channel].at_state.cid = ev->parameter; |
| 1356 | cs->bcs[channel].at_state.pending_commands |= |
| 1357 | PC_DIAL; |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 1358 | cs->commands_pending = 1; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1359 | break; |
| 1360 | } |
| 1361 | /* fall through */ |
| 1362 | case ACT_FAILCID: |
| 1363 | cs->cur_at_seq = SEQ_NONE; |
| 1364 | channel = cs->curchannel; |
| 1365 | if (!reinit_and_retry(cs, channel)) { |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1366 | dev_warn(cs->dev, |
| 1367 | "Could not get a call ID. Cannot dial.\n"); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1368 | at_state2 = &cs->bcs[channel].at_state; |
| 1369 | disconnect(&at_state2); |
| 1370 | } |
| 1371 | break; |
| 1372 | case ACT_ABORTCID: |
| 1373 | cs->cur_at_seq = SEQ_NONE; |
| 1374 | at_state2 = &cs->bcs[cs->curchannel].at_state; |
| 1375 | disconnect(&at_state2); |
| 1376 | break; |
| 1377 | |
| 1378 | case ACT_DIALING: |
| 1379 | case ACT_ACCEPTED: |
| 1380 | cs->cur_at_seq = SEQ_NONE; |
| 1381 | break; |
| 1382 | |
Tilman Schmidt | c35a87f | 2009-10-25 09:30:47 +0000 | [diff] [blame] | 1383 | case ACT_ABORTACCEPT: /* hangup/error/timeout during ICALL procssng */ |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1384 | disconnect(p_at_state); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1385 | break; |
| 1386 | |
| 1387 | case ACT_ABORTDIAL: /* error/timeout during dial preparation */ |
| 1388 | cs->cur_at_seq = SEQ_NONE; |
| 1389 | at_state->pending_commands |= PC_HUP; |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 1390 | cs->commands_pending = 1; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1391 | break; |
| 1392 | |
| 1393 | case ACT_REMOTEREJECT: /* DISCONNECT_IND after dialling */ |
| 1394 | case ACT_CONNTIMEOUT: /* timeout waiting for ZSAU=ACTIVE */ |
| 1395 | case ACT_REMOTEHUP: /* DISCONNECT_IND with established connection */ |
| 1396 | at_state->pending_commands |= PC_HUP; |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 1397 | cs->commands_pending = 1; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1398 | break; |
Tilman Schmidt | 917f508 | 2006-04-10 22:55:00 -0700 | [diff] [blame] | 1399 | case ACT_GETSTRING: /* warning: RING, ZDLE, ... |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1400 | are not handled properly anymore */ |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1401 | at_state->getstring = 1; |
| 1402 | break; |
| 1403 | case ACT_SETVER: |
| 1404 | if (!ev->ptr) { |
| 1405 | *p_genresp = 1; |
| 1406 | *p_resp_code = RSP_ERROR; |
| 1407 | break; |
| 1408 | } |
| 1409 | s = ev->ptr; |
| 1410 | |
| 1411 | if (!strcmp(s, "OK")) { |
| 1412 | *p_genresp = 1; |
| 1413 | *p_resp_code = RSP_ERROR; |
| 1414 | break; |
| 1415 | } |
| 1416 | |
| 1417 | for (i = 0; i < 4; ++i) { |
| 1418 | val = simple_strtoul(s, (char **) &e, 10); |
| 1419 | if (val > INT_MAX || e == s) |
| 1420 | break; |
| 1421 | if (i == 3) { |
| 1422 | if (*e) |
| 1423 | break; |
| 1424 | } else if (*e != '.') |
| 1425 | break; |
| 1426 | else |
| 1427 | s = e + 1; |
| 1428 | cs->fwver[i] = val; |
| 1429 | } |
| 1430 | if (i != 4) { |
| 1431 | *p_genresp = 1; |
| 1432 | *p_resp_code = RSP_ERROR; |
| 1433 | break; |
| 1434 | } |
| 1435 | /*at_state->getstring = 1;*/ |
| 1436 | cs->gotfwver = 0; |
| 1437 | break; |
| 1438 | case ACT_GOTVER: |
| 1439 | if (cs->gotfwver == 0) { |
| 1440 | cs->gotfwver = 1; |
Tilman Schmidt | 1528b18 | 2010-02-22 13:09:52 +0000 | [diff] [blame] | 1441 | gig_dbg(DEBUG_EVENT, |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1442 | "firmware version %02d.%03d.%02d.%02d", |
| 1443 | cs->fwver[0], cs->fwver[1], |
| 1444 | cs->fwver[2], cs->fwver[3]); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1445 | break; |
| 1446 | } |
| 1447 | /* fall through */ |
| 1448 | case ACT_FAILVER: |
| 1449 | cs->gotfwver = -1; |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1450 | dev_err(cs->dev, "could not read firmware version.\n"); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1451 | break; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1452 | case ACT_ERROR: |
Tilman Schmidt | 05eae94 | 2009-10-06 12:18:46 +0000 | [diff] [blame] | 1453 | gig_dbg(DEBUG_ANY, "%s: ERROR response in ConState %d", |
| 1454 | __func__, at_state->ConState); |
| 1455 | cs->cur_at_seq = SEQ_NONE; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1456 | break; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1457 | case ACT_DEBUG: |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1458 | gig_dbg(DEBUG_ANY, "%s: resp_code %d in ConState %d", |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1459 | __func__, ev->type, at_state->ConState); |
| 1460 | break; |
| 1461 | case ACT_WARN: |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1462 | dev_warn(cs->dev, "%s: resp_code %d in ConState %d!\n", |
| 1463 | __func__, ev->type, at_state->ConState); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1464 | break; |
| 1465 | case ACT_ZCAU: |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1466 | dev_warn(cs->dev, "cause code %04x in connection state %d.\n", |
| 1467 | ev->parameter, at_state->ConState); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1468 | break; |
| 1469 | |
| 1470 | /* events from the LL */ |
| 1471 | case ACT_DIAL: |
| 1472 | start_dial(at_state, ev->ptr, ev->parameter); |
| 1473 | break; |
| 1474 | case ACT_ACCEPT: |
| 1475 | start_accept(at_state); |
| 1476 | break; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1477 | case ACT_HUP: |
| 1478 | at_state->pending_commands |= PC_HUP; |
Tilman Schmidt | 1528b18 | 2010-02-22 13:09:52 +0000 | [diff] [blame] | 1479 | gig_dbg(DEBUG_EVENT, "Scheduling PC_HUP"); |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 1480 | cs->commands_pending = 1; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1481 | break; |
| 1482 | |
| 1483 | /* hotplug events */ |
| 1484 | case ACT_STOP: |
| 1485 | do_stop(cs); |
| 1486 | break; |
| 1487 | case ACT_START: |
| 1488 | do_start(cs); |
| 1489 | break; |
| 1490 | |
Tilman Schmidt | c35a87f | 2009-10-25 09:30:47 +0000 | [diff] [blame] | 1491 | /* events from the interface */ |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1492 | case ACT_IF_LOCK: |
| 1493 | cs->cmd_result = ev->parameter ? do_lock(cs) : do_unlock(cs); |
| 1494 | cs->waiting = 0; |
| 1495 | wake_up(&cs->waitqueue); |
| 1496 | break; |
| 1497 | case ACT_IF_VER: |
| 1498 | if (ev->parameter != 0) |
| 1499 | cs->cmd_result = -EINVAL; |
| 1500 | else if (cs->gotfwver != 1) { |
| 1501 | cs->cmd_result = -ENOENT; |
| 1502 | } else { |
| 1503 | memcpy(ev->arg, cs->fwver, sizeof cs->fwver); |
| 1504 | cs->cmd_result = 0; |
| 1505 | } |
| 1506 | cs->waiting = 0; |
| 1507 | wake_up(&cs->waitqueue); |
| 1508 | break; |
| 1509 | |
Tilman Schmidt | c35a87f | 2009-10-25 09:30:47 +0000 | [diff] [blame] | 1510 | /* events from the proc file system */ |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1511 | case ACT_PROC_CIDMODE: |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 1512 | spin_lock_irqsave(&cs->lock, flags); |
| 1513 | if (ev->parameter != cs->cidmode) { |
| 1514 | cs->cidmode = ev->parameter; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1515 | if (ev->parameter) { |
| 1516 | cs->at_state.pending_commands |= PC_CIDMODE; |
Tilman Schmidt | 1528b18 | 2010-02-22 13:09:52 +0000 | [diff] [blame] | 1517 | gig_dbg(DEBUG_EVENT, "Scheduling PC_CIDMODE"); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1518 | } else { |
| 1519 | cs->at_state.pending_commands |= PC_UMMODE; |
Tilman Schmidt | 1528b18 | 2010-02-22 13:09:52 +0000 | [diff] [blame] | 1520 | gig_dbg(DEBUG_EVENT, "Scheduling PC_UMMODE"); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1521 | } |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 1522 | cs->commands_pending = 1; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1523 | } |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 1524 | spin_unlock_irqrestore(&cs->lock, flags); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1525 | cs->waiting = 0; |
| 1526 | wake_up(&cs->waitqueue); |
| 1527 | break; |
| 1528 | |
| 1529 | /* events from the hardware drivers */ |
| 1530 | case ACT_NOTIFY_BC_DOWN: |
| 1531 | bchannel_down(bcs); |
| 1532 | break; |
| 1533 | case ACT_NOTIFY_BC_UP: |
| 1534 | bchannel_up(bcs); |
| 1535 | break; |
| 1536 | case ACT_SHUTDOWN: |
| 1537 | do_shutdown(cs); |
| 1538 | break; |
| 1539 | |
| 1540 | |
| 1541 | default: |
| 1542 | if (action >= ACT_CMD && action < ACT_CMD + AT_NUM) { |
| 1543 | *pp_command = at_state->bcs->commands[action - ACT_CMD]; |
| 1544 | if (!*pp_command) { |
| 1545 | *p_genresp = 1; |
| 1546 | *p_resp_code = RSP_NULL; |
| 1547 | } |
| 1548 | } else |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1549 | dev_err(cs->dev, "%s: action==%d!\n", __func__, action); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1550 | } |
| 1551 | } |
| 1552 | |
| 1553 | /* State machine to do the calling and hangup procedure */ |
| 1554 | static void process_event(struct cardstate *cs, struct event_t *ev) |
| 1555 | { |
| 1556 | struct bc_state *bcs; |
| 1557 | char *p_command = NULL; |
| 1558 | struct reply_t *rep; |
| 1559 | int rcode; |
| 1560 | int genresp = 0; |
| 1561 | int resp_code = RSP_ERROR; |
| 1562 | int sendcid; |
| 1563 | struct at_state_t *at_state; |
| 1564 | int index; |
| 1565 | int curact; |
| 1566 | unsigned long flags; |
| 1567 | |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1568 | if (ev->cid >= 0) { |
| 1569 | at_state = at_state_from_cid(cs, ev->cid); |
| 1570 | if (!at_state) { |
Tilman Schmidt | 1528b18 | 2010-02-22 13:09:52 +0000 | [diff] [blame] | 1571 | gig_dbg(DEBUG_EVENT, "event %d for invalid cid %d", |
| 1572 | ev->type, ev->cid); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1573 | gigaset_add_event(cs, &cs->at_state, RSP_WRONG_CID, |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1574 | NULL, 0, NULL); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1575 | return; |
| 1576 | } |
| 1577 | } else { |
| 1578 | at_state = ev->at_state; |
| 1579 | if (at_state_invalid(cs, at_state)) { |
Tilman Schmidt | 1528b18 | 2010-02-22 13:09:52 +0000 | [diff] [blame] | 1580 | gig_dbg(DEBUG_EVENT, "event for invalid at_state %p", |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1581 | at_state); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1582 | return; |
| 1583 | } |
| 1584 | } |
| 1585 | |
Tilman Schmidt | 1528b18 | 2010-02-22 13:09:52 +0000 | [diff] [blame] | 1586 | gig_dbg(DEBUG_EVENT, "connection state %d, event %d", |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1587 | at_state->ConState, ev->type); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1588 | |
| 1589 | bcs = at_state->bcs; |
| 1590 | sendcid = at_state->cid; |
| 1591 | |
| 1592 | /* Setting the pointer to the dial array */ |
| 1593 | rep = at_state->replystruct; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1594 | |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 1595 | spin_lock_irqsave(&cs->lock, flags); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1596 | if (ev->type == EV_TIMEOUT) { |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 1597 | if (ev->parameter != at_state->timer_index |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1598 | || !at_state->timer_active) { |
| 1599 | ev->type = RSP_NONE; /* old timeout */ |
Tilman Schmidt | 1528b18 | 2010-02-22 13:09:52 +0000 | [diff] [blame] | 1600 | gig_dbg(DEBUG_EVENT, "old timeout"); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1601 | } else if (!at_state->waiting) |
Tilman Schmidt | 1528b18 | 2010-02-22 13:09:52 +0000 | [diff] [blame] | 1602 | gig_dbg(DEBUG_EVENT, "timeout occurred"); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1603 | else |
Tilman Schmidt | 1528b18 | 2010-02-22 13:09:52 +0000 | [diff] [blame] | 1604 | gig_dbg(DEBUG_EVENT, "stopped waiting"); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1605 | } |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 1606 | spin_unlock_irqrestore(&cs->lock, flags); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1607 | |
Tilman Schmidt | 917f508 | 2006-04-10 22:55:00 -0700 | [diff] [blame] | 1608 | /* if the response belongs to a variable in at_state->int_var[VAR_XXXX] |
| 1609 | or at_state->str_var[STR_XXXX], set it */ |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1610 | if (ev->type >= RSP_VAR && ev->type < RSP_VAR + VAR_NUM) { |
| 1611 | index = ev->type - RSP_VAR; |
| 1612 | at_state->int_var[index] = ev->parameter; |
| 1613 | } else if (ev->type >= RSP_STR && ev->type < RSP_STR + STR_NUM) { |
| 1614 | index = ev->type - RSP_STR; |
| 1615 | kfree(at_state->str_var[index]); |
| 1616 | at_state->str_var[index] = ev->ptr; |
Tilman Schmidt | 917f508 | 2006-04-10 22:55:00 -0700 | [diff] [blame] | 1617 | ev->ptr = NULL; /* prevent process_events() from |
| 1618 | deallocating ptr */ |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1619 | } |
| 1620 | |
| 1621 | if (ev->type == EV_TIMEOUT || ev->type == RSP_STRING) |
| 1622 | at_state->getstring = 0; |
| 1623 | |
Tilman Schmidt | 917f508 | 2006-04-10 22:55:00 -0700 | [diff] [blame] | 1624 | /* Search row in dial array which matches modem response and current |
| 1625 | constate */ |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1626 | for (;; rep++) { |
| 1627 | rcode = rep->resp_code; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1628 | if (rcode == RSP_LAST) { |
| 1629 | /* found nothing...*/ |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1630 | dev_warn(cs->dev, "%s: rcode=RSP_LAST: " |
| 1631 | "resp_code %d in ConState %d!\n", |
| 1632 | __func__, ev->type, at_state->ConState); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1633 | return; |
| 1634 | } |
| 1635 | if ((rcode == RSP_ANY || rcode == ev->type) |
| 1636 | && ((int) at_state->ConState >= rep->min_ConState) |
| 1637 | && (rep->max_ConState < 0 |
| 1638 | || (int) at_state->ConState <= rep->max_ConState) |
| 1639 | && (rep->parameter < 0 || rep->parameter == ev->parameter)) |
| 1640 | break; |
| 1641 | } |
| 1642 | |
| 1643 | p_command = rep->command; |
| 1644 | |
| 1645 | at_state->waiting = 0; |
| 1646 | for (curact = 0; curact < MAXACT; ++curact) { |
| 1647 | /* The row tells us what we should do .. |
| 1648 | */ |
Tilman Schmidt | c35a87f | 2009-10-25 09:30:47 +0000 | [diff] [blame] | 1649 | do_action(rep->action[curact], cs, bcs, &at_state, &p_command, |
| 1650 | &genresp, &resp_code, ev); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1651 | if (!at_state) |
| 1652 | break; /* may be freed after disconnect */ |
| 1653 | } |
| 1654 | |
| 1655 | if (at_state) { |
| 1656 | /* Jump to the next con-state regarding the array */ |
| 1657 | if (rep->new_ConState >= 0) |
| 1658 | at_state->ConState = rep->new_ConState; |
| 1659 | |
| 1660 | if (genresp) { |
| 1661 | spin_lock_irqsave(&cs->lock, flags); |
Tilman Schmidt | c35a87f | 2009-10-25 09:30:47 +0000 | [diff] [blame] | 1662 | at_state->timer_expires = 0; |
| 1663 | at_state->timer_active = 0; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1664 | spin_unlock_irqrestore(&cs->lock, flags); |
Tilman Schmidt | c35a87f | 2009-10-25 09:30:47 +0000 | [diff] [blame] | 1665 | gigaset_add_event(cs, at_state, resp_code, |
| 1666 | NULL, 0, NULL); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1667 | } else { |
| 1668 | /* Send command to modem if not NULL... */ |
Tilman Schmidt | c35a87f | 2009-10-25 09:30:47 +0000 | [diff] [blame] | 1669 | if (p_command) { |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 1670 | if (cs->connected) |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1671 | send_command(cs, p_command, |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1672 | sendcid, cs->dle, |
| 1673 | GFP_ATOMIC); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1674 | else |
| 1675 | gigaset_add_event(cs, at_state, |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1676 | RSP_NODEV, |
| 1677 | NULL, 0, NULL); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1678 | } |
| 1679 | |
| 1680 | spin_lock_irqsave(&cs->lock, flags); |
| 1681 | if (!rep->timeout) { |
| 1682 | at_state->timer_expires = 0; |
| 1683 | at_state->timer_active = 0; |
| 1684 | } else if (rep->timeout > 0) { /* new timeout */ |
| 1685 | at_state->timer_expires = rep->timeout * 10; |
| 1686 | at_state->timer_active = 1; |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 1687 | ++at_state->timer_index; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1688 | } |
| 1689 | spin_unlock_irqrestore(&cs->lock, flags); |
| 1690 | } |
| 1691 | } |
| 1692 | } |
| 1693 | |
| 1694 | static void schedule_sequence(struct cardstate *cs, |
| 1695 | struct at_state_t *at_state, int sequence) |
| 1696 | { |
| 1697 | cs->cur_at_seq = sequence; |
| 1698 | gigaset_add_event(cs, at_state, RSP_INIT, NULL, sequence, NULL); |
| 1699 | } |
| 1700 | |
| 1701 | static void process_command_flags(struct cardstate *cs) |
| 1702 | { |
| 1703 | struct at_state_t *at_state = NULL; |
| 1704 | struct bc_state *bcs; |
| 1705 | int i; |
| 1706 | int sequence; |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 1707 | unsigned long flags; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1708 | |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 1709 | cs->commands_pending = 0; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1710 | |
| 1711 | if (cs->cur_at_seq) { |
Tilman Schmidt | 1528b18 | 2010-02-22 13:09:52 +0000 | [diff] [blame] | 1712 | gig_dbg(DEBUG_EVENT, "not searching scheduled commands: busy"); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1713 | return; |
| 1714 | } |
| 1715 | |
Tilman Schmidt | 1528b18 | 2010-02-22 13:09:52 +0000 | [diff] [blame] | 1716 | gig_dbg(DEBUG_EVENT, "searching scheduled commands"); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1717 | |
| 1718 | sequence = SEQ_NONE; |
| 1719 | |
| 1720 | /* clear pending_commands and hangup channels on shutdown */ |
| 1721 | if (cs->at_state.pending_commands & PC_SHUTDOWN) { |
| 1722 | cs->at_state.pending_commands &= ~PC_CIDMODE; |
| 1723 | for (i = 0; i < cs->channels; ++i) { |
| 1724 | bcs = cs->bcs + i; |
| 1725 | at_state = &bcs->at_state; |
| 1726 | at_state->pending_commands &= |
| 1727 | ~(PC_DLE1 | PC_ACCEPT | PC_DIAL); |
| 1728 | if (at_state->cid > 0) |
| 1729 | at_state->pending_commands |= PC_HUP; |
| 1730 | if (at_state->pending_commands & PC_CID) { |
| 1731 | at_state->pending_commands |= PC_NOCID; |
| 1732 | at_state->pending_commands &= ~PC_CID; |
| 1733 | } |
| 1734 | } |
| 1735 | } |
| 1736 | |
| 1737 | /* clear pending_commands and hangup channels on reset */ |
| 1738 | if (cs->at_state.pending_commands & PC_INIT) { |
| 1739 | cs->at_state.pending_commands &= ~PC_CIDMODE; |
| 1740 | for (i = 0; i < cs->channels; ++i) { |
| 1741 | bcs = cs->bcs + i; |
| 1742 | at_state = &bcs->at_state; |
| 1743 | at_state->pending_commands &= |
| 1744 | ~(PC_DLE1 | PC_ACCEPT | PC_DIAL); |
| 1745 | if (at_state->cid > 0) |
| 1746 | at_state->pending_commands |= PC_HUP; |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 1747 | if (cs->mstate == MS_RECOVER) { |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1748 | if (at_state->pending_commands & PC_CID) { |
| 1749 | at_state->pending_commands |= PC_NOCID; |
| 1750 | at_state->pending_commands &= ~PC_CID; |
| 1751 | } |
| 1752 | } |
| 1753 | } |
| 1754 | } |
| 1755 | |
Tilman Schmidt | c35a87f | 2009-10-25 09:30:47 +0000 | [diff] [blame] | 1756 | /* only switch back to unimodem mode if no commands are pending and |
| 1757 | * no channels are up */ |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 1758 | spin_lock_irqsave(&cs->lock, flags); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1759 | if (cs->at_state.pending_commands == PC_UMMODE |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 1760 | && !cs->cidmode |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1761 | && list_empty(&cs->temp_at_states) |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 1762 | && cs->mode == M_CID) { |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1763 | sequence = SEQ_UMMODE; |
| 1764 | at_state = &cs->at_state; |
| 1765 | for (i = 0; i < cs->channels; ++i) { |
| 1766 | bcs = cs->bcs + i; |
| 1767 | if (bcs->at_state.pending_commands || |
| 1768 | bcs->at_state.cid > 0) { |
| 1769 | sequence = SEQ_NONE; |
| 1770 | break; |
| 1771 | } |
| 1772 | } |
| 1773 | } |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 1774 | spin_unlock_irqrestore(&cs->lock, flags); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1775 | cs->at_state.pending_commands &= ~PC_UMMODE; |
| 1776 | if (sequence != SEQ_NONE) { |
| 1777 | schedule_sequence(cs, at_state, sequence); |
| 1778 | return; |
| 1779 | } |
| 1780 | |
| 1781 | for (i = 0; i < cs->channels; ++i) { |
| 1782 | bcs = cs->bcs + i; |
| 1783 | if (bcs->at_state.pending_commands & PC_HUP) { |
| 1784 | bcs->at_state.pending_commands &= ~PC_HUP; |
| 1785 | if (bcs->at_state.pending_commands & PC_CID) { |
| 1786 | /* not yet dialing: PC_NOCID is sufficient */ |
| 1787 | bcs->at_state.pending_commands |= PC_NOCID; |
| 1788 | bcs->at_state.pending_commands &= ~PC_CID; |
| 1789 | } else { |
| 1790 | schedule_sequence(cs, &bcs->at_state, SEQ_HUP); |
| 1791 | return; |
| 1792 | } |
| 1793 | } |
| 1794 | if (bcs->at_state.pending_commands & PC_NOCID) { |
| 1795 | bcs->at_state.pending_commands &= ~PC_NOCID; |
| 1796 | cs->curchannel = bcs->channel; |
| 1797 | schedule_sequence(cs, &cs->at_state, SEQ_NOCID); |
| 1798 | return; |
| 1799 | } else if (bcs->at_state.pending_commands & PC_DLE0) { |
| 1800 | bcs->at_state.pending_commands &= ~PC_DLE0; |
| 1801 | cs->curchannel = bcs->channel; |
| 1802 | schedule_sequence(cs, &cs->at_state, SEQ_DLE0); |
| 1803 | return; |
| 1804 | } |
| 1805 | } |
| 1806 | |
| 1807 | list_for_each_entry(at_state, &cs->temp_at_states, list) |
| 1808 | if (at_state->pending_commands & PC_HUP) { |
| 1809 | at_state->pending_commands &= ~PC_HUP; |
| 1810 | schedule_sequence(cs, at_state, SEQ_HUP); |
| 1811 | return; |
| 1812 | } |
| 1813 | |
| 1814 | if (cs->at_state.pending_commands & PC_INIT) { |
| 1815 | cs->at_state.pending_commands &= ~PC_INIT; |
Tilman Schmidt | c35a87f | 2009-10-25 09:30:47 +0000 | [diff] [blame] | 1816 | cs->dle = 0; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1817 | cs->inbuf->inputstate = INS_command; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1818 | schedule_sequence(cs, &cs->at_state, SEQ_INIT); |
| 1819 | return; |
| 1820 | } |
| 1821 | if (cs->at_state.pending_commands & PC_SHUTDOWN) { |
| 1822 | cs->at_state.pending_commands &= ~PC_SHUTDOWN; |
| 1823 | schedule_sequence(cs, &cs->at_state, SEQ_SHUTDOWN); |
| 1824 | return; |
| 1825 | } |
| 1826 | if (cs->at_state.pending_commands & PC_CIDMODE) { |
| 1827 | cs->at_state.pending_commands &= ~PC_CIDMODE; |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 1828 | if (cs->mode == M_UNIMODEM) { |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1829 | cs->retry_count = 1; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1830 | schedule_sequence(cs, &cs->at_state, SEQ_CIDMODE); |
| 1831 | return; |
| 1832 | } |
| 1833 | } |
| 1834 | |
| 1835 | for (i = 0; i < cs->channels; ++i) { |
| 1836 | bcs = cs->bcs + i; |
| 1837 | if (bcs->at_state.pending_commands & PC_DLE1) { |
| 1838 | bcs->at_state.pending_commands &= ~PC_DLE1; |
| 1839 | cs->curchannel = bcs->channel; |
| 1840 | schedule_sequence(cs, &cs->at_state, SEQ_DLE1); |
| 1841 | return; |
| 1842 | } |
| 1843 | if (bcs->at_state.pending_commands & PC_ACCEPT) { |
| 1844 | bcs->at_state.pending_commands &= ~PC_ACCEPT; |
| 1845 | schedule_sequence(cs, &bcs->at_state, SEQ_ACCEPT); |
| 1846 | return; |
| 1847 | } |
| 1848 | if (bcs->at_state.pending_commands & PC_DIAL) { |
| 1849 | bcs->at_state.pending_commands &= ~PC_DIAL; |
| 1850 | schedule_sequence(cs, &bcs->at_state, SEQ_DIAL); |
| 1851 | return; |
| 1852 | } |
| 1853 | if (bcs->at_state.pending_commands & PC_CID) { |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 1854 | switch (cs->mode) { |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1855 | case M_UNIMODEM: |
| 1856 | cs->at_state.pending_commands |= PC_CIDMODE; |
Tilman Schmidt | 1528b18 | 2010-02-22 13:09:52 +0000 | [diff] [blame] | 1857 | gig_dbg(DEBUG_EVENT, "Scheduling PC_CIDMODE"); |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 1858 | cs->commands_pending = 1; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1859 | return; |
| 1860 | #ifdef GIG_MAYINITONDIAL |
| 1861 | case M_UNKNOWN: |
| 1862 | schedule_init(cs, MS_INIT); |
| 1863 | return; |
| 1864 | #endif |
| 1865 | } |
| 1866 | bcs->at_state.pending_commands &= ~PC_CID; |
| 1867 | cs->curchannel = bcs->channel; |
| 1868 | #ifdef GIG_RETRYCID |
| 1869 | cs->retry_count = 2; |
| 1870 | #else |
| 1871 | cs->retry_count = 1; |
| 1872 | #endif |
| 1873 | schedule_sequence(cs, &cs->at_state, SEQ_CID); |
| 1874 | return; |
| 1875 | } |
| 1876 | } |
| 1877 | } |
| 1878 | |
| 1879 | static void process_events(struct cardstate *cs) |
| 1880 | { |
| 1881 | struct event_t *ev; |
| 1882 | unsigned head, tail; |
| 1883 | int i; |
| 1884 | int check_flags = 0; |
| 1885 | int was_busy; |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 1886 | unsigned long flags; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1887 | |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 1888 | spin_lock_irqsave(&cs->ev_lock, flags); |
| 1889 | head = cs->ev_head; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1890 | |
| 1891 | for (i = 0; i < 2 * MAX_EVENTS; ++i) { |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 1892 | tail = cs->ev_tail; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1893 | if (tail == head) { |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 1894 | if (!check_flags && !cs->commands_pending) |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1895 | break; |
| 1896 | check_flags = 0; |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 1897 | spin_unlock_irqrestore(&cs->ev_lock, flags); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1898 | process_command_flags(cs); |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 1899 | spin_lock_irqsave(&cs->ev_lock, flags); |
| 1900 | tail = cs->ev_tail; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1901 | if (tail == head) { |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 1902 | if (!cs->commands_pending) |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1903 | break; |
| 1904 | continue; |
| 1905 | } |
| 1906 | } |
| 1907 | |
| 1908 | ev = cs->events + head; |
| 1909 | was_busy = cs->cur_at_seq != SEQ_NONE; |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 1910 | spin_unlock_irqrestore(&cs->ev_lock, flags); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1911 | process_event(cs, ev); |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 1912 | spin_lock_irqsave(&cs->ev_lock, flags); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1913 | kfree(ev->ptr); |
| 1914 | ev->ptr = NULL; |
| 1915 | if (was_busy && cs->cur_at_seq == SEQ_NONE) |
| 1916 | check_flags = 1; |
| 1917 | |
| 1918 | head = (head + 1) % MAX_EVENTS; |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 1919 | cs->ev_head = head; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1920 | } |
| 1921 | |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 1922 | spin_unlock_irqrestore(&cs->ev_lock, flags); |
| 1923 | |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1924 | if (i == 2 * MAX_EVENTS) { |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1925 | dev_err(cs->dev, |
| 1926 | "infinite loop in process_events; aborting.\n"); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1927 | } |
| 1928 | } |
| 1929 | |
| 1930 | /* tasklet scheduled on any event received from the Gigaset device |
| 1931 | * parameter: |
| 1932 | * data ISDN controller state structure |
| 1933 | */ |
| 1934 | void gigaset_handle_event(unsigned long data) |
| 1935 | { |
| 1936 | struct cardstate *cs = (struct cardstate *) data; |
| 1937 | |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1938 | /* handle incoming data on control/common channel */ |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 1939 | if (cs->inbuf->head != cs->inbuf->tail) { |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1940 | gig_dbg(DEBUG_INTR, "processing new data"); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1941 | cs->ops->handle_input(cs->inbuf); |
| 1942 | } |
| 1943 | |
| 1944 | process_events(cs); |
| 1945 | } |