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