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 */ |
Tilman Schmidt | f86936f | 2012-04-25 13:02:20 +0000 | [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 | |
Tilman Schmidt | f86936f | 2012-04-25 13:02:20 +0000 | [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 | |
Tilman Schmidt | f86936f | 2012-04-25 13:02:20 +0000 | [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 | |
Tilman Schmidt | f86936f | 2012-04-25 13:02:20 +0000 | [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 | |
Tilman Schmidt | f86936f | 2012-04-25 13:02:20 +0000 | [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 | |
Tilman Schmidt | f86936f | 2012-04-25 13:02:20 +0000 | [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 | |
Tilman Schmidt | f86936f | 2012-04-25 13:02:20 +0000 | [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 | |
Tilman Schmidt | f86936f | 2012-04-25 13:02:20 +0000 | [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 | |
Tilman Schmidt | f86936f | 2012-04-25 13:02:20 +0000 | [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} }, |
| 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 */ |
Tilman Schmidt | f86936f | 2012-04-25 13:02:20 +0000 | [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 */ |
Tilman Schmidt | f86936f | 2012-04-25 13:02:20 +0000 | [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 */ |
Tilman Schmidt | f86936f | 2012-04-25 13:02:20 +0000 | [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 */ |
Tilman Schmidt | f86936f | 2012-04-25 13:02:20 +0000 | [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 */ |
Tilman Schmidt | f86936f | 2012-04-25 13:02:20 +0000 | [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 */ |
Tilman Schmidt | f86936f | 2012-04-25 13:02:20 +0000 | [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 */ |
Tilman Schmidt | f86936f | 2012-04-25 13:02:20 +0000 | [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 */ |
Tilman Schmidt | f86936f | 2012-04-25 13:02:20 +0000 | [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 | |
Tilman Schmidt | f86936f | 2012-04-25 13:02:20 +0000 | [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. */ |
Tilman Schmidt | f86936f | 2012-04-25 13:02:20 +0000 | [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} }, |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 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 */ |
Tilman Schmidt | f86936f | 2012-04-25 13:02:20 +0000 | [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 | |
Tilman Schmidt | f86936f | 2012-04-25 13:02:20 +0000 | [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 */ |
Tilman Schmidt | f86936f | 2012-04-25 13:02:20 +0000 | [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 */ |
Tilman Schmidt | f86936f | 2012-04-25 13:02:20 +0000 | [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 */ |
Tilman Schmidt | f86936f | 2012-04-25 13:02:20 +0000 | [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 */ |
Tilman Schmidt | f86936f | 2012-04-25 13:02:20 +0000 | [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 | |
Tilman Schmidt | f86936f | 2012-04-25 13:02:20 +0000 | [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 */ |
Tilman Schmidt | f86936f | 2012-04-25 13:02:20 +0000 | [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*/ |
Tilman Schmidt | f86936f | 2012-04-25 13:02:20 +0000 | [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 | |
Tilman Schmidt | f86936f | 2012-04-25 13:02:20 +0000 | [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) */ |
Tilman Schmidt | f86936f | 2012-04-25 13:02:20 +0000 | [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. */ |
Tilman Schmidt | f86936f | 2012-04-25 13:02:20 +0000 | [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} }, |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 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 { |
Tilman Schmidt | 63b203b | 2013-01-21 11:57:21 +0000 | [diff] [blame] | 354 | char *response; |
| 355 | int resp_code; |
| 356 | int type; |
| 357 | } |
| 358 | resp_type[] = |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 359 | { |
Tilman Schmidt | 917f508 | 2006-04-10 22:55:00 -0700 | [diff] [blame] | 360 | {"OK", RSP_OK, RT_NOTHING}, |
| 361 | {"ERROR", RSP_ERROR, RT_NOTHING}, |
| 362 | {"ZSAU", RSP_ZSAU, RT_ZSAU}, |
| 363 | {"ZCAU", RSP_ZCAU, RT_ZCAU}, |
| 364 | {"RING", RSP_RING, RT_RING}, |
| 365 | {"ZGCI", RSP_ZGCI, RT_NUMBER}, |
| 366 | {"ZVLS", RSP_ZVLS, RT_NUMBER}, |
| 367 | {"ZCTP", RSP_ZCTP, RT_NUMBER}, |
| 368 | {"ZDLE", RSP_ZDLE, RT_NUMBER}, |
Tilman Schmidt | 917f508 | 2006-04-10 22:55:00 -0700 | [diff] [blame] | 369 | {"ZHLC", RSP_ZHLC, RT_STRING}, |
| 370 | {"ZBC", RSP_ZBC, RT_STRING}, |
| 371 | {"NMBR", RSP_NMBR, RT_STRING}, |
| 372 | {"ZCPN", RSP_ZCPN, RT_STRING}, |
| 373 | {"ZCON", RSP_ZCON, RT_STRING}, |
Tilman Schmidt | c35a87f | 2009-10-25 09:30:47 +0000 | [diff] [blame] | 374 | {NULL, 0, 0} |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 375 | }; |
| 376 | |
Tilman Schmidt | 50e4fe9 | 2009-10-25 09:30:57 +0000 | [diff] [blame] | 377 | static const struct zsau_resp_t { |
Tilman Schmidt | 63b203b | 2013-01-21 11:57:21 +0000 | [diff] [blame] | 378 | char *str; |
| 379 | int code; |
| 380 | } |
| 381 | zsau_resp[] = |
Tilman Schmidt | 50e4fe9 | 2009-10-25 09:30:57 +0000 | [diff] [blame] | 382 | { |
Tilman Schmidt | 63b203b | 2013-01-21 11:57:21 +0000 | [diff] [blame] | 383 | {"OUTGOING_CALL_PROCEEDING", ZSAU_PROCEEDING}, |
Tilman Schmidt | 50e4fe9 | 2009-10-25 09:30:57 +0000 | [diff] [blame] | 384 | {"CALL_DELIVERED", ZSAU_CALL_DELIVERED}, |
| 385 | {"ACTIVE", ZSAU_ACTIVE}, |
| 386 | {"DISCONNECT_IND", ZSAU_DISCONNECT_IND}, |
| 387 | {"NULL", ZSAU_NULL}, |
| 388 | {"DISCONNECT_REQ", ZSAU_DISCONNECT_REQ}, |
| 389 | {NULL, ZSAU_UNKNOWN} |
| 390 | }; |
| 391 | |
Tilman Schmidt | 4656e0a | 2015-03-21 20:15:32 +0100 | [diff] [blame] | 392 | /* check for and remove fixed string prefix |
| 393 | * If s starts with prefix terminated by a non-alphanumeric character, |
| 394 | * return pointer to the first character after that, otherwise return NULL. |
| 395 | */ |
| 396 | static char *skip_prefix(char *s, const char *prefix) |
| 397 | { |
| 398 | while (*prefix) |
| 399 | if (*s++ != *prefix++) |
| 400 | return NULL; |
| 401 | if (isalnum(*s)) |
| 402 | return NULL; |
| 403 | return s; |
| 404 | } |
| 405 | |
Tilman Schmidt | 6bf5011 | 2015-03-21 20:15:32 +0100 | [diff] [blame] | 406 | /* queue event with CID */ |
| 407 | static void add_cid_event(struct cardstate *cs, int cid, int type, |
| 408 | void *ptr, int parameter) |
| 409 | { |
| 410 | unsigned long flags; |
| 411 | unsigned next, tail; |
| 412 | struct event_t *event; |
| 413 | |
| 414 | gig_dbg(DEBUG_EVENT, "queueing event %d for cid %d", type, cid); |
| 415 | |
| 416 | spin_lock_irqsave(&cs->ev_lock, flags); |
| 417 | |
| 418 | tail = cs->ev_tail; |
| 419 | next = (tail + 1) % MAX_EVENTS; |
| 420 | if (unlikely(next == cs->ev_head)) { |
| 421 | dev_err(cs->dev, "event queue full\n"); |
| 422 | kfree(ptr); |
| 423 | } else { |
| 424 | event = cs->events + tail; |
| 425 | event->type = type; |
| 426 | event->cid = cid; |
| 427 | event->ptr = ptr; |
| 428 | event->arg = NULL; |
| 429 | event->parameter = parameter; |
| 430 | event->at_state = NULL; |
| 431 | cs->ev_tail = next; |
| 432 | } |
| 433 | |
| 434 | spin_unlock_irqrestore(&cs->ev_lock, flags); |
| 435 | } |
| 436 | |
Tilman Schmidt | 1cec972 | 2009-10-06 12:19:01 +0000 | [diff] [blame] | 437 | /** |
| 438 | * gigaset_handle_modem_response() - process received modem response |
| 439 | * @cs: device descriptor structure. |
| 440 | * |
| 441 | * Called by asyncdata/isocdata if a block of data received from the |
| 442 | * device must be processed as a modem command response. The data is |
| 443 | * already in the cs structure. |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 444 | */ |
| 445 | void gigaset_handle_modem_response(struct cardstate *cs) |
| 446 | { |
Tilman Schmidt | 4656e0a | 2015-03-21 20:15:32 +0100 | [diff] [blame] | 447 | char *eoc, *psep, *ptr; |
Tilman Schmidt | 35dc845 | 2007-03-29 01:20:34 -0700 | [diff] [blame] | 448 | const struct resp_type_t *rt; |
Tilman Schmidt | 50e4fe9 | 2009-10-25 09:30:57 +0000 | [diff] [blame] | 449 | const struct zsau_resp_t *zr; |
Tilman Schmidt | 6bf5011 | 2015-03-21 20:15:32 +0100 | [diff] [blame] | 450 | int cid, parameter; |
Tilman Schmidt | 4656e0a | 2015-03-21 20:15:32 +0100 | [diff] [blame] | 451 | u8 type, value; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 452 | |
Tilman Schmidt | 4df1e52 | 2015-03-21 20:15:32 +0100 | [diff] [blame] | 453 | if (!cs->cbytes) { |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 454 | /* ignore additional LFs/CRs (M10x config mode or cx100) */ |
Tilman Schmidt | 63b203b | 2013-01-21 11:57:21 +0000 | [diff] [blame] | 455 | gig_dbg(DEBUG_MCMD, "skipped EOL [%02X]", cs->respdata[0]); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 456 | return; |
| 457 | } |
Tilman Schmidt | 4df1e52 | 2015-03-21 20:15:32 +0100 | [diff] [blame] | 458 | cs->respdata[cs->cbytes] = 0; |
| 459 | |
| 460 | if (cs->at_state.getstring) { |
| 461 | /* state machine wants next line verbatim */ |
| 462 | cs->at_state.getstring = 0; |
| 463 | ptr = kstrdup(cs->respdata, GFP_ATOMIC); |
| 464 | gig_dbg(DEBUG_EVENT, "string==%s", ptr ? ptr : "NULL"); |
| 465 | add_cid_event(cs, 0, RSP_STRING, ptr, 0); |
| 466 | return; |
| 467 | } |
| 468 | |
Tilman Schmidt | 4656e0a | 2015-03-21 20:15:32 +0100 | [diff] [blame] | 469 | /* look up response type */ |
| 470 | for (rt = resp_type; rt->response; ++rt) { |
| 471 | eoc = skip_prefix(cs->respdata, rt->response); |
| 472 | if (eoc) |
| 473 | break; |
| 474 | } |
| 475 | if (!rt->response) { |
| 476 | add_cid_event(cs, 0, RSP_NONE, NULL, 0); |
| 477 | gig_dbg(DEBUG_EVENT, "unknown modem response: '%s'\n", |
| 478 | cs->respdata); |
| 479 | return; |
| 480 | } |
| 481 | |
Tilman Schmidt | d93187e | 2015-03-21 20:15:32 +0100 | [diff] [blame] | 482 | /* check for CID */ |
| 483 | psep = strrchr(cs->respdata, ';'); |
| 484 | if (psep && |
| 485 | !kstrtoint(psep + 1, 10, &cid) && |
| 486 | cid >= 1 && cid <= 65535) { |
| 487 | /* valid CID: chop it off */ |
| 488 | *psep = 0; |
| 489 | } else { |
| 490 | /* no valid CID: leave unchanged */ |
| 491 | cid = 0; |
| 492 | } |
| 493 | |
Tilman Schmidt | 4656e0a | 2015-03-21 20:15:32 +0100 | [diff] [blame] | 494 | gig_dbg(DEBUG_EVENT, "CMD received: %s", cs->respdata); |
Tilman Schmidt | d93187e | 2015-03-21 20:15:32 +0100 | [diff] [blame] | 495 | if (cid) |
| 496 | gig_dbg(DEBUG_EVENT, "CID: %d", cid); |
Tilman Schmidt | 4df1e52 | 2015-03-21 20:15:32 +0100 | [diff] [blame] | 497 | |
Tilman Schmidt | 4656e0a | 2015-03-21 20:15:32 +0100 | [diff] [blame] | 498 | switch (rt->type) { |
| 499 | case RT_NOTHING: |
| 500 | /* check parameter separator */ |
| 501 | if (*eoc) |
| 502 | goto bad_param; /* extra parameter */ |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 503 | |
Tilman Schmidt | 4656e0a | 2015-03-21 20:15:32 +0100 | [diff] [blame] | 504 | add_cid_event(cs, cid, rt->resp_code, NULL, 0); |
| 505 | break; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 506 | |
Tilman Schmidt | 4656e0a | 2015-03-21 20:15:32 +0100 | [diff] [blame] | 507 | case RT_RING: |
| 508 | /* check parameter separator */ |
| 509 | if (!*eoc) |
| 510 | eoc = NULL; /* no parameter */ |
| 511 | else if (*eoc++ != ',') |
| 512 | goto bad_param; |
Tilman Schmidt | 4df1e52 | 2015-03-21 20:15:32 +0100 | [diff] [blame] | 513 | |
Tilman Schmidt | 4656e0a | 2015-03-21 20:15:32 +0100 | [diff] [blame] | 514 | add_cid_event(cs, 0, rt->resp_code, NULL, cid); |
| 515 | |
| 516 | /* process parameters as individual responses */ |
| 517 | while (eoc) { |
| 518 | /* look up parameter type */ |
| 519 | psep = NULL; |
| 520 | for (rt = resp_type; rt->response; ++rt) { |
| 521 | psep = skip_prefix(eoc, rt->response); |
| 522 | if (psep) |
Tilman Schmidt | 50e4fe9 | 2009-10-25 09:30:57 +0000 | [diff] [blame] | 523 | break; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 524 | } |
Andy Shevchenko | c974138 | 2010-07-15 02:37:20 +0000 | [diff] [blame] | 525 | |
Tilman Schmidt | 4656e0a | 2015-03-21 20:15:32 +0100 | [diff] [blame] | 526 | /* all legal parameters are of type RT_STRING */ |
| 527 | if (!psep || rt->type != RT_STRING) { |
| 528 | dev_warn(cs->dev, |
| 529 | "illegal RING parameter: '%s'\n", |
| 530 | eoc); |
| 531 | return; |
| 532 | } |
| 533 | |
| 534 | /* skip parameter value separator */ |
| 535 | if (*psep++ != '=') |
| 536 | goto bad_param; |
| 537 | |
| 538 | /* look up end of parameter */ |
| 539 | eoc = strchr(psep, ','); |
| 540 | if (eoc) |
| 541 | *eoc++ = 0; |
| 542 | |
| 543 | /* retrieve parameter value */ |
| 544 | ptr = kstrdup(psep, GFP_ATOMIC); |
| 545 | |
| 546 | /* queue event */ |
| 547 | add_cid_event(cs, cid, rt->resp_code, ptr, 0); |
| 548 | } |
| 549 | break; |
| 550 | |
| 551 | case RT_ZSAU: |
| 552 | /* check parameter separator */ |
| 553 | if (!*eoc) { |
| 554 | /* no parameter */ |
| 555 | add_cid_event(cs, cid, rt->resp_code, NULL, ZSAU_NONE); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 556 | break; |
| 557 | } |
Tilman Schmidt | 4656e0a | 2015-03-21 20:15:32 +0100 | [diff] [blame] | 558 | if (*eoc++ != '=') |
| 559 | goto bad_param; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 560 | |
Tilman Schmidt | 4656e0a | 2015-03-21 20:15:32 +0100 | [diff] [blame] | 561 | /* look up parameter value */ |
| 562 | for (zr = zsau_resp; zr->str; ++zr) |
| 563 | if (!strcmp(eoc, zr->str)) |
| 564 | break; |
| 565 | if (!zr->str) |
| 566 | goto bad_param; |
| 567 | |
| 568 | add_cid_event(cs, cid, rt->resp_code, NULL, zr->code); |
| 569 | break; |
| 570 | |
| 571 | case RT_STRING: |
| 572 | /* check parameter separator */ |
| 573 | if (*eoc++ != '=') |
| 574 | goto bad_param; |
| 575 | |
| 576 | /* retrieve parameter value */ |
| 577 | ptr = kstrdup(eoc, GFP_ATOMIC); |
| 578 | |
| 579 | /* queue event */ |
| 580 | add_cid_event(cs, cid, rt->resp_code, ptr, 0); |
| 581 | break; |
| 582 | |
| 583 | case RT_ZCAU: |
| 584 | /* check parameter separators */ |
| 585 | if (*eoc++ != '=') |
| 586 | goto bad_param; |
| 587 | psep = strchr(eoc, ','); |
| 588 | if (!psep) |
| 589 | goto bad_param; |
| 590 | *psep++ = 0; |
| 591 | |
| 592 | /* decode parameter values */ |
| 593 | if (kstrtou8(eoc, 16, &type) || kstrtou8(psep, 16, &value)) { |
| 594 | *--psep = ','; |
| 595 | goto bad_param; |
| 596 | } |
| 597 | parameter = (type << 8) | value; |
| 598 | |
| 599 | add_cid_event(cs, cid, rt->resp_code, NULL, parameter); |
| 600 | break; |
| 601 | |
| 602 | case RT_NUMBER: |
| 603 | /* check parameter separator */ |
| 604 | if (*eoc++ != '=') |
| 605 | goto bad_param; |
| 606 | |
| 607 | /* decode parameter value */ |
| 608 | if (kstrtoint(eoc, 10, ¶meter)) |
| 609 | goto bad_param; |
| 610 | |
| 611 | /* special case ZDLE: set flag before queueing event */ |
| 612 | if (rt->resp_code == RSP_ZDLE) |
| 613 | cs->dle = parameter; |
| 614 | |
| 615 | add_cid_event(cs, cid, rt->resp_code, NULL, parameter); |
| 616 | break; |
| 617 | |
| 618 | bad_param: |
| 619 | /* parameter unexpected, incomplete or malformed */ |
| 620 | dev_warn(cs->dev, "bad parameter in response '%s'\n", |
| 621 | cs->respdata); |
| 622 | add_cid_event(cs, cid, rt->resp_code, NULL, -1); |
| 623 | break; |
| 624 | |
| 625 | default: |
| 626 | dev_err(cs->dev, "%s: internal error on '%s'\n", |
| 627 | __func__, cs->respdata); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 628 | } |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 629 | } |
| 630 | EXPORT_SYMBOL_GPL(gigaset_handle_modem_response); |
| 631 | |
Tilman Schmidt | b8324f9 | 2014-10-11 13:46:30 +0200 | [diff] [blame] | 632 | /* disconnect_nobc |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 633 | * process closing of connection associated with given AT state structure |
Tilman Schmidt | b8324f9 | 2014-10-11 13:46:30 +0200 | [diff] [blame] | 634 | * without B channel |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 635 | */ |
Tilman Schmidt | b8324f9 | 2014-10-11 13:46:30 +0200 | [diff] [blame] | 636 | static void disconnect_nobc(struct at_state_t **at_state_p, |
| 637 | struct cardstate *cs) |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 638 | { |
| 639 | unsigned long flags; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 640 | |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 641 | spin_lock_irqsave(&cs->lock, flags); |
| 642 | ++(*at_state_p)->seq_index; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 643 | |
| 644 | /* revert to selected idle mode */ |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 645 | if (!cs->cidmode) { |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 646 | cs->at_state.pending_commands |= PC_UMMODE; |
Tilman Schmidt | 1528b18 | 2010-02-22 13:09:52 +0000 | [diff] [blame] | 647 | gig_dbg(DEBUG_EVENT, "Scheduling PC_UMMODE"); |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 648 | cs->commands_pending = 1; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 649 | } |
| 650 | |
Tilman Schmidt | b8324f9 | 2014-10-11 13:46:30 +0200 | [diff] [blame] | 651 | /* check for and deallocate temporary AT state */ |
| 652 | if (!list_empty(&(*at_state_p)->list)) { |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 653 | list_del(&(*at_state_p)->list); |
| 654 | kfree(*at_state_p); |
| 655 | *at_state_p = NULL; |
Tilman Schmidt | b8324f9 | 2014-10-11 13:46:30 +0200 | [diff] [blame] | 656 | } |
| 657 | |
| 658 | spin_unlock_irqrestore(&cs->lock, flags); |
| 659 | } |
| 660 | |
| 661 | /* disconnect_bc |
| 662 | * process closing of connection associated with given AT state structure |
| 663 | * and B channel |
| 664 | */ |
| 665 | static void disconnect_bc(struct at_state_t *at_state, |
| 666 | struct cardstate *cs, struct bc_state *bcs) |
| 667 | { |
| 668 | unsigned long flags; |
| 669 | |
| 670 | spin_lock_irqsave(&cs->lock, flags); |
| 671 | ++at_state->seq_index; |
| 672 | |
| 673 | /* revert to selected idle mode */ |
| 674 | if (!cs->cidmode) { |
| 675 | cs->at_state.pending_commands |= PC_UMMODE; |
| 676 | gig_dbg(DEBUG_EVENT, "Scheduling PC_UMMODE"); |
| 677 | cs->commands_pending = 1; |
| 678 | } |
| 679 | spin_unlock_irqrestore(&cs->lock, flags); |
| 680 | |
| 681 | /* invoke hardware specific handler */ |
| 682 | cs->ops->close_bchannel(bcs); |
| 683 | |
| 684 | /* notify LL */ |
| 685 | if (bcs->chstate & (CHS_D_UP | CHS_NOTIFY_LL)) { |
| 686 | bcs->chstate &= ~(CHS_D_UP | CHS_NOTIFY_LL); |
| 687 | gigaset_isdn_hupD(bcs); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 688 | } |
| 689 | } |
| 690 | |
| 691 | /* get_free_channel |
| 692 | * get a free AT state structure: either one of those associated with the |
| 693 | * B channels of the Gigaset device, or if none of those is available, |
| 694 | * a newly allocated one with bcs=NULL |
Tilman Schmidt | b8324f9 | 2014-10-11 13:46:30 +0200 | [diff] [blame] | 695 | * The structure should be freed by calling disconnect_nobc() after use. |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 696 | */ |
| 697 | static inline struct at_state_t *get_free_channel(struct cardstate *cs, |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 698 | int cid) |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 699 | /* cids: >0: siemens-cid |
Tilman Schmidt | f86936f | 2012-04-25 13:02:20 +0000 | [diff] [blame] | 700 | * 0: without cid |
| 701 | * -1: no cid assigned yet |
| 702 | */ |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 703 | { |
| 704 | unsigned long flags; |
| 705 | int i; |
| 706 | struct at_state_t *ret; |
| 707 | |
| 708 | for (i = 0; i < cs->channels; ++i) |
Tilman Schmidt | 81fa7b8 | 2012-04-25 13:02:20 +0000 | [diff] [blame] | 709 | if (gigaset_get_channel(cs->bcs + i) >= 0) { |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 710 | ret = &cs->bcs[i].at_state; |
| 711 | ret->cid = cid; |
| 712 | return ret; |
| 713 | } |
| 714 | |
| 715 | spin_lock_irqsave(&cs->lock, flags); |
| 716 | ret = kmalloc(sizeof(struct at_state_t), GFP_ATOMIC); |
| 717 | if (ret) { |
| 718 | gigaset_at_init(ret, NULL, cs, cid); |
| 719 | list_add(&ret->list, &cs->temp_at_states); |
| 720 | } |
| 721 | spin_unlock_irqrestore(&cs->lock, flags); |
| 722 | return ret; |
| 723 | } |
| 724 | |
| 725 | static void init_failed(struct cardstate *cs, int mode) |
| 726 | { |
| 727 | int i; |
| 728 | struct at_state_t *at_state; |
| 729 | |
| 730 | cs->at_state.pending_commands &= ~PC_INIT; |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 731 | cs->mode = mode; |
| 732 | cs->mstate = MS_UNINITIALIZED; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 733 | gigaset_free_channels(cs); |
| 734 | for (i = 0; i < cs->channels; ++i) { |
| 735 | at_state = &cs->bcs[i].at_state; |
| 736 | if (at_state->pending_commands & PC_CID) { |
| 737 | at_state->pending_commands &= ~PC_CID; |
| 738 | at_state->pending_commands |= PC_NOCID; |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 739 | cs->commands_pending = 1; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 740 | } |
| 741 | } |
| 742 | } |
| 743 | |
| 744 | static void schedule_init(struct cardstate *cs, int state) |
| 745 | { |
| 746 | if (cs->at_state.pending_commands & PC_INIT) { |
Tilman Schmidt | 1528b18 | 2010-02-22 13:09:52 +0000 | [diff] [blame] | 747 | gig_dbg(DEBUG_EVENT, "not scheduling PC_INIT again"); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 748 | return; |
| 749 | } |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 750 | cs->mstate = state; |
| 751 | cs->mode = M_UNKNOWN; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 752 | gigaset_block_channels(cs); |
| 753 | cs->at_state.pending_commands |= PC_INIT; |
Tilman Schmidt | 1528b18 | 2010-02-22 13:09:52 +0000 | [diff] [blame] | 754 | gig_dbg(DEBUG_EVENT, "Scheduling PC_INIT"); |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 755 | cs->commands_pending = 1; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 756 | } |
| 757 | |
Tilman Schmidt | 63b203b | 2013-01-21 11:57:21 +0000 | [diff] [blame] | 758 | /* send an AT command |
| 759 | * adding the "AT" prefix, cid and DLE encapsulation as appropriate |
| 760 | */ |
| 761 | static void send_command(struct cardstate *cs, const char *cmd, |
| 762 | struct at_state_t *at_state) |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 763 | { |
Tilman Schmidt | 63b203b | 2013-01-21 11:57:21 +0000 | [diff] [blame] | 764 | int cid = at_state->cid; |
Tilman Schmidt | e3628dd | 2010-07-05 14:18:43 +0000 | [diff] [blame] | 765 | struct cmdbuf_t *cb; |
| 766 | size_t buflen; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 767 | |
Tilman Schmidt | e3628dd | 2010-07-05 14:18:43 +0000 | [diff] [blame] | 768 | buflen = strlen(cmd) + 12; /* DLE ( A T 1 2 3 4 5 <cmd> DLE ) \0 */ |
Tilman Schmidt | 63b203b | 2013-01-21 11:57:21 +0000 | [diff] [blame] | 769 | cb = kmalloc(sizeof(struct cmdbuf_t) + buflen, GFP_ATOMIC); |
Tilman Schmidt | e3628dd | 2010-07-05 14:18:43 +0000 | [diff] [blame] | 770 | if (!cb) { |
| 771 | dev_err(cs->dev, "%s: out of memory\n", __func__); |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 772 | return; |
| 773 | } |
Tilman Schmidt | e3628dd | 2010-07-05 14:18:43 +0000 | [diff] [blame] | 774 | if (cid > 0 && cid <= 65535) |
| 775 | cb->len = snprintf(cb->buf, buflen, |
Tilman Schmidt | 63b203b | 2013-01-21 11:57:21 +0000 | [diff] [blame] | 776 | cs->dle ? "\020(AT%d%s\020)" : "AT%d%s", |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 777 | cid, cmd); |
Tilman Schmidt | e3628dd | 2010-07-05 14:18:43 +0000 | [diff] [blame] | 778 | else |
| 779 | cb->len = snprintf(cb->buf, buflen, |
Tilman Schmidt | 63b203b | 2013-01-21 11:57:21 +0000 | [diff] [blame] | 780 | cs->dle ? "\020(AT%s\020)" : "AT%s", |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 781 | cmd); |
Tilman Schmidt | e3628dd | 2010-07-05 14:18:43 +0000 | [diff] [blame] | 782 | cb->offset = 0; |
| 783 | cb->next = NULL; |
| 784 | cb->wake_tasklet = NULL; |
| 785 | cs->ops->write_cmd(cs, cb); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 786 | } |
| 787 | |
| 788 | static struct at_state_t *at_state_from_cid(struct cardstate *cs, int cid) |
| 789 | { |
| 790 | struct at_state_t *at_state; |
| 791 | int i; |
| 792 | unsigned long flags; |
| 793 | |
| 794 | if (cid == 0) |
| 795 | return &cs->at_state; |
| 796 | |
| 797 | for (i = 0; i < cs->channels; ++i) |
| 798 | if (cid == cs->bcs[i].at_state.cid) |
| 799 | return &cs->bcs[i].at_state; |
| 800 | |
| 801 | spin_lock_irqsave(&cs->lock, flags); |
| 802 | |
| 803 | list_for_each_entry(at_state, &cs->temp_at_states, list) |
| 804 | if (cid == at_state->cid) { |
| 805 | spin_unlock_irqrestore(&cs->lock, flags); |
| 806 | return at_state; |
| 807 | } |
| 808 | |
| 809 | spin_unlock_irqrestore(&cs->lock, flags); |
| 810 | |
| 811 | return NULL; |
| 812 | } |
| 813 | |
| 814 | static void bchannel_down(struct bc_state *bcs) |
| 815 | { |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 816 | if (bcs->chstate & CHS_B_UP) { |
| 817 | bcs->chstate &= ~CHS_B_UP; |
Tilman Schmidt | 088ec0c | 2009-10-06 12:19:07 +0000 | [diff] [blame] | 818 | gigaset_isdn_hupB(bcs); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 819 | } |
| 820 | |
| 821 | if (bcs->chstate & (CHS_D_UP | CHS_NOTIFY_LL)) { |
| 822 | bcs->chstate &= ~(CHS_D_UP | CHS_NOTIFY_LL); |
Tilman Schmidt | 088ec0c | 2009-10-06 12:19:07 +0000 | [diff] [blame] | 823 | gigaset_isdn_hupD(bcs); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 824 | } |
| 825 | |
| 826 | gigaset_free_channel(bcs); |
| 827 | |
| 828 | gigaset_bcs_reinit(bcs); |
| 829 | } |
| 830 | |
| 831 | static void bchannel_up(struct bc_state *bcs) |
| 832 | { |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 833 | if (bcs->chstate & CHS_B_UP) { |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 834 | dev_notice(bcs->cs->dev, "%s: B channel already up\n", |
| 835 | __func__); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 836 | return; |
| 837 | } |
| 838 | |
| 839 | bcs->chstate |= CHS_B_UP; |
Tilman Schmidt | 088ec0c | 2009-10-06 12:19:07 +0000 | [diff] [blame] | 840 | gigaset_isdn_connB(bcs); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 841 | } |
| 842 | |
Tilman Schmidt | c35a87f | 2009-10-25 09:30:47 +0000 | [diff] [blame] | 843 | static void start_dial(struct at_state_t *at_state, void *data, |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 844 | unsigned seq_index) |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 845 | { |
| 846 | struct bc_state *bcs = at_state->bcs; |
| 847 | struct cardstate *cs = at_state->cs; |
Tilman Schmidt | 088ec0c | 2009-10-06 12:19:07 +0000 | [diff] [blame] | 848 | char **commands = data; |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 849 | unsigned long flags; |
Tilman Schmidt | 088ec0c | 2009-10-06 12:19:07 +0000 | [diff] [blame] | 850 | int i; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 851 | |
| 852 | bcs->chstate |= CHS_NOTIFY_LL; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 853 | |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 854 | spin_lock_irqsave(&cs->lock, flags); |
| 855 | if (at_state->seq_index != seq_index) { |
| 856 | spin_unlock_irqrestore(&cs->lock, flags); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 857 | goto error; |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 858 | } |
| 859 | spin_unlock_irqrestore(&cs->lock, flags); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 860 | |
Tilman Schmidt | 088ec0c | 2009-10-06 12:19:07 +0000 | [diff] [blame] | 861 | for (i = 0; i < AT_NUM; ++i) { |
| 862 | kfree(bcs->commands[i]); |
| 863 | bcs->commands[i] = commands[i]; |
| 864 | } |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 865 | |
| 866 | at_state->pending_commands |= PC_CID; |
Tilman Schmidt | 1528b18 | 2010-02-22 13:09:52 +0000 | [diff] [blame] | 867 | gig_dbg(DEBUG_EVENT, "Scheduling PC_CID"); |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 868 | cs->commands_pending = 1; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 869 | return; |
| 870 | |
| 871 | error: |
Tilman Schmidt | 088ec0c | 2009-10-06 12:19:07 +0000 | [diff] [blame] | 872 | for (i = 0; i < AT_NUM; ++i) { |
| 873 | kfree(commands[i]); |
| 874 | commands[i] = NULL; |
| 875 | } |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 876 | at_state->pending_commands |= PC_NOCID; |
Tilman Schmidt | 1528b18 | 2010-02-22 13:09:52 +0000 | [diff] [blame] | 877 | gig_dbg(DEBUG_EVENT, "Scheduling PC_NOCID"); |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 878 | cs->commands_pending = 1; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 879 | return; |
| 880 | } |
| 881 | |
| 882 | static void start_accept(struct at_state_t *at_state) |
| 883 | { |
| 884 | struct cardstate *cs = at_state->cs; |
Tilman Schmidt | 088ec0c | 2009-10-06 12:19:07 +0000 | [diff] [blame] | 885 | struct bc_state *bcs = at_state->bcs; |
| 886 | int i; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 887 | |
Tilman Schmidt | 088ec0c | 2009-10-06 12:19:07 +0000 | [diff] [blame] | 888 | for (i = 0; i < AT_NUM; ++i) { |
| 889 | kfree(bcs->commands[i]); |
| 890 | bcs->commands[i] = NULL; |
| 891 | } |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 892 | |
Tilman Schmidt | 088ec0c | 2009-10-06 12:19:07 +0000 | [diff] [blame] | 893 | bcs->commands[AT_PROTO] = kmalloc(9, GFP_ATOMIC); |
| 894 | bcs->commands[AT_ISO] = kmalloc(9, GFP_ATOMIC); |
| 895 | if (!bcs->commands[AT_PROTO] || !bcs->commands[AT_ISO]) { |
| 896 | dev_err(at_state->cs->dev, "out of memory\n"); |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 897 | /* error reset */ |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 898 | at_state->pending_commands |= PC_HUP; |
Tilman Schmidt | 1528b18 | 2010-02-22 13:09:52 +0000 | [diff] [blame] | 899 | gig_dbg(DEBUG_EVENT, "Scheduling PC_HUP"); |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 900 | cs->commands_pending = 1; |
Tilman Schmidt | 088ec0c | 2009-10-06 12:19:07 +0000 | [diff] [blame] | 901 | return; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 902 | } |
Tilman Schmidt | 088ec0c | 2009-10-06 12:19:07 +0000 | [diff] [blame] | 903 | |
| 904 | snprintf(bcs->commands[AT_PROTO], 9, "^SBPR=%u\r", bcs->proto2); |
| 905 | snprintf(bcs->commands[AT_ISO], 9, "^SISO=%u\r", bcs->channel + 1); |
| 906 | |
| 907 | at_state->pending_commands |= PC_ACCEPT; |
Tilman Schmidt | 1528b18 | 2010-02-22 13:09:52 +0000 | [diff] [blame] | 908 | gig_dbg(DEBUG_EVENT, "Scheduling PC_ACCEPT"); |
Tilman Schmidt | 088ec0c | 2009-10-06 12:19:07 +0000 | [diff] [blame] | 909 | cs->commands_pending = 1; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 910 | } |
| 911 | |
| 912 | static void do_start(struct cardstate *cs) |
| 913 | { |
| 914 | gigaset_free_channels(cs); |
| 915 | |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 916 | if (cs->mstate != MS_LOCKED) |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 917 | schedule_init(cs, MS_INIT); |
| 918 | |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 919 | cs->isdn_up = 1; |
Tilman Schmidt | 088ec0c | 2009-10-06 12:19:07 +0000 | [diff] [blame] | 920 | gigaset_isdn_start(cs); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 921 | |
| 922 | cs->waiting = 0; |
| 923 | wake_up(&cs->waitqueue); |
| 924 | } |
| 925 | |
| 926 | static void finish_shutdown(struct cardstate *cs) |
| 927 | { |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 928 | if (cs->mstate != MS_LOCKED) { |
| 929 | cs->mstate = MS_UNINITIALIZED; |
| 930 | cs->mode = M_UNKNOWN; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 931 | } |
| 932 | |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 933 | /* Tell the LL that the device is not available .. */ |
| 934 | if (cs->isdn_up) { |
| 935 | cs->isdn_up = 0; |
Tilman Schmidt | 088ec0c | 2009-10-06 12:19:07 +0000 | [diff] [blame] | 936 | gigaset_isdn_stop(cs); |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 937 | } |
| 938 | |
Tilman Schmidt | 63b203b | 2013-01-21 11:57:21 +0000 | [diff] [blame] | 939 | /* The rest is done by cleanup_cs() in process context. */ |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 940 | |
| 941 | cs->cmd_result = -ENODEV; |
| 942 | cs->waiting = 0; |
Tilman Schmidt | 2869b23 | 2007-02-12 00:52:34 -0800 | [diff] [blame] | 943 | wake_up(&cs->waitqueue); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 944 | } |
| 945 | |
| 946 | static void do_shutdown(struct cardstate *cs) |
| 947 | { |
| 948 | gigaset_block_channels(cs); |
| 949 | |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 950 | if (cs->mstate == MS_READY) { |
| 951 | cs->mstate = MS_SHUTDOWN; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 952 | cs->at_state.pending_commands |= PC_SHUTDOWN; |
Tilman Schmidt | 1528b18 | 2010-02-22 13:09:52 +0000 | [diff] [blame] | 953 | gig_dbg(DEBUG_EVENT, "Scheduling PC_SHUTDOWN"); |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 954 | cs->commands_pending = 1; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 955 | } else |
| 956 | finish_shutdown(cs); |
| 957 | } |
| 958 | |
| 959 | static void do_stop(struct cardstate *cs) |
| 960 | { |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 961 | unsigned long flags; |
| 962 | |
| 963 | spin_lock_irqsave(&cs->lock, flags); |
| 964 | cs->connected = 0; |
| 965 | spin_unlock_irqrestore(&cs->lock, flags); |
| 966 | |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 967 | do_shutdown(cs); |
| 968 | } |
| 969 | |
| 970 | /* Entering cid mode or getting a cid failed: |
| 971 | * try to initialize the device and try again. |
| 972 | * |
| 973 | * channel >= 0: getting cid for the channel failed |
| 974 | * channel < 0: entering cid mode failed |
| 975 | * |
Tilman Schmidt | 81fa7b8 | 2012-04-25 13:02:20 +0000 | [diff] [blame] | 976 | * returns 0 on success, <0 on failure |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 977 | */ |
| 978 | static int reinit_and_retry(struct cardstate *cs, int channel) |
| 979 | { |
| 980 | int i; |
| 981 | |
| 982 | if (--cs->retry_count <= 0) |
Tilman Schmidt | 81fa7b8 | 2012-04-25 13:02:20 +0000 | [diff] [blame] | 983 | return -EFAULT; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 984 | |
| 985 | for (i = 0; i < cs->channels; ++i) |
| 986 | if (cs->bcs[i].at_state.cid > 0) |
Tilman Schmidt | 81fa7b8 | 2012-04-25 13:02:20 +0000 | [diff] [blame] | 987 | return -EBUSY; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 988 | |
| 989 | if (channel < 0) |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 990 | dev_warn(cs->dev, |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 991 | "Could not enter cid mode. Reinit device and try again.\n"); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 992 | else { |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 993 | dev_warn(cs->dev, |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 994 | "Could not get a call id. Reinit device and try again.\n"); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 995 | cs->bcs[channel].at_state.pending_commands |= PC_CID; |
| 996 | } |
| 997 | schedule_init(cs, MS_INIT); |
Tilman Schmidt | 81fa7b8 | 2012-04-25 13:02:20 +0000 | [diff] [blame] | 998 | return 0; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 999 | } |
| 1000 | |
| 1001 | static int at_state_invalid(struct cardstate *cs, |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1002 | struct at_state_t *test_ptr) |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1003 | { |
| 1004 | unsigned long flags; |
| 1005 | unsigned channel; |
| 1006 | struct at_state_t *at_state; |
| 1007 | int retval = 0; |
| 1008 | |
| 1009 | spin_lock_irqsave(&cs->lock, flags); |
| 1010 | |
| 1011 | if (test_ptr == &cs->at_state) |
| 1012 | goto exit; |
| 1013 | |
| 1014 | list_for_each_entry(at_state, &cs->temp_at_states, list) |
| 1015 | if (at_state == test_ptr) |
| 1016 | goto exit; |
| 1017 | |
| 1018 | for (channel = 0; channel < cs->channels; ++channel) |
| 1019 | if (&cs->bcs[channel].at_state == test_ptr) |
| 1020 | goto exit; |
| 1021 | |
| 1022 | retval = 1; |
| 1023 | exit: |
| 1024 | spin_unlock_irqrestore(&cs->lock, flags); |
| 1025 | return retval; |
| 1026 | } |
| 1027 | |
| 1028 | static void handle_icall(struct cardstate *cs, struct bc_state *bcs, |
Tilman Schmidt | 63b203b | 2013-01-21 11:57:21 +0000 | [diff] [blame] | 1029 | struct at_state_t *at_state) |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1030 | { |
| 1031 | int retval; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1032 | |
| 1033 | retval = gigaset_isdn_icall(at_state); |
| 1034 | switch (retval) { |
| 1035 | case ICALL_ACCEPT: |
| 1036 | break; |
| 1037 | default: |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1038 | dev_err(cs->dev, "internal error: disposition=%d\n", retval); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1039 | /* --v-- fall through --v-- */ |
| 1040 | case ICALL_IGNORE: |
| 1041 | case ICALL_REJECT: |
| 1042 | /* hang up actively |
| 1043 | * Device doc says that would reject the call. |
| 1044 | * In fact it doesn't. |
| 1045 | */ |
| 1046 | at_state->pending_commands |= PC_HUP; |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 1047 | cs->commands_pending = 1; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1048 | break; |
| 1049 | } |
| 1050 | } |
| 1051 | |
| 1052 | static int do_lock(struct cardstate *cs) |
| 1053 | { |
| 1054 | int mode; |
| 1055 | int i; |
| 1056 | |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 1057 | switch (cs->mstate) { |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1058 | case MS_UNINITIALIZED: |
| 1059 | case MS_READY: |
| 1060 | if (cs->cur_at_seq || !list_empty(&cs->temp_at_states) || |
| 1061 | cs->at_state.pending_commands) |
| 1062 | return -EBUSY; |
| 1063 | |
| 1064 | for (i = 0; i < cs->channels; ++i) |
| 1065 | if (cs->bcs[i].at_state.pending_commands) |
| 1066 | return -EBUSY; |
| 1067 | |
Tilman Schmidt | 81fa7b8 | 2012-04-25 13:02:20 +0000 | [diff] [blame] | 1068 | if (gigaset_get_channels(cs) < 0) |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1069 | return -EBUSY; |
| 1070 | |
| 1071 | break; |
| 1072 | case MS_LOCKED: |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1073 | break; |
| 1074 | default: |
| 1075 | return -EBUSY; |
| 1076 | } |
| 1077 | |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 1078 | mode = cs->mode; |
| 1079 | cs->mstate = MS_LOCKED; |
| 1080 | cs->mode = M_UNKNOWN; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1081 | |
| 1082 | return mode; |
| 1083 | } |
| 1084 | |
| 1085 | static int do_unlock(struct cardstate *cs) |
| 1086 | { |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 1087 | if (cs->mstate != MS_LOCKED) |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1088 | return -EINVAL; |
| 1089 | |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 1090 | cs->mstate = MS_UNINITIALIZED; |
| 1091 | cs->mode = M_UNKNOWN; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1092 | gigaset_free_channels(cs); |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 1093 | if (cs->connected) |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1094 | schedule_init(cs, MS_INIT); |
| 1095 | |
| 1096 | return 0; |
| 1097 | } |
| 1098 | |
| 1099 | static void do_action(int action, struct cardstate *cs, |
| 1100 | struct bc_state *bcs, |
| 1101 | struct at_state_t **p_at_state, char **pp_command, |
| 1102 | int *p_genresp, int *p_resp_code, |
| 1103 | struct event_t *ev) |
| 1104 | { |
| 1105 | struct at_state_t *at_state = *p_at_state; |
Tilman Schmidt | b8324f9 | 2014-10-11 13:46:30 +0200 | [diff] [blame] | 1106 | struct bc_state *bcs2; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1107 | unsigned long flags; |
| 1108 | |
| 1109 | int channel; |
| 1110 | |
| 1111 | unsigned char *s, *e; |
| 1112 | int i; |
| 1113 | unsigned long val; |
| 1114 | |
| 1115 | switch (action) { |
| 1116 | case ACT_NOTHING: |
| 1117 | break; |
| 1118 | case ACT_TIMEOUT: |
| 1119 | at_state->waiting = 1; |
| 1120 | break; |
| 1121 | case ACT_INIT: |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1122 | cs->at_state.pending_commands &= ~PC_INIT; |
| 1123 | cs->cur_at_seq = SEQ_NONE; |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 1124 | cs->mode = M_UNIMODEM; |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 1125 | spin_lock_irqsave(&cs->lock, flags); |
| 1126 | if (!cs->cidmode) { |
| 1127 | spin_unlock_irqrestore(&cs->lock, flags); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1128 | gigaset_free_channels(cs); |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 1129 | cs->mstate = MS_READY; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1130 | break; |
| 1131 | } |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 1132 | spin_unlock_irqrestore(&cs->lock, flags); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1133 | cs->at_state.pending_commands |= PC_CIDMODE; |
Tilman Schmidt | 1528b18 | 2010-02-22 13:09:52 +0000 | [diff] [blame] | 1134 | gig_dbg(DEBUG_EVENT, "Scheduling PC_CIDMODE"); |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 1135 | cs->commands_pending = 1; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1136 | break; |
| 1137 | case ACT_FAILINIT: |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1138 | dev_warn(cs->dev, "Could not initialize the device.\n"); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1139 | cs->dle = 0; |
| 1140 | init_failed(cs, M_UNKNOWN); |
| 1141 | cs->cur_at_seq = SEQ_NONE; |
| 1142 | break; |
| 1143 | case ACT_CONFIGMODE: |
| 1144 | init_failed(cs, M_CONFIG); |
| 1145 | cs->cur_at_seq = SEQ_NONE; |
| 1146 | break; |
| 1147 | case ACT_SETDLE1: |
| 1148 | cs->dle = 1; |
| 1149 | /* cs->inbuf[0].inputstate |= INS_command | INS_DLE_command; */ |
| 1150 | cs->inbuf[0].inputstate &= |
| 1151 | ~(INS_command | INS_DLE_command); |
| 1152 | break; |
| 1153 | case ACT_SETDLE0: |
| 1154 | cs->dle = 0; |
| 1155 | cs->inbuf[0].inputstate = |
| 1156 | (cs->inbuf[0].inputstate & ~INS_DLE_command) |
| 1157 | | INS_command; |
| 1158 | break; |
| 1159 | case ACT_CMODESET: |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 1160 | if (cs->mstate == MS_INIT || cs->mstate == MS_RECOVER) { |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1161 | gigaset_free_channels(cs); |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 1162 | cs->mstate = MS_READY; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1163 | } |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 1164 | cs->mode = M_CID; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1165 | cs->cur_at_seq = SEQ_NONE; |
| 1166 | break; |
| 1167 | case ACT_UMODESET: |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 1168 | cs->mode = M_UNIMODEM; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1169 | cs->cur_at_seq = SEQ_NONE; |
| 1170 | break; |
| 1171 | case ACT_FAILCMODE: |
| 1172 | cs->cur_at_seq = SEQ_NONE; |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 1173 | if (cs->mstate == MS_INIT || cs->mstate == MS_RECOVER) { |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1174 | init_failed(cs, M_UNKNOWN); |
| 1175 | break; |
| 1176 | } |
Tilman Schmidt | 81fa7b8 | 2012-04-25 13:02:20 +0000 | [diff] [blame] | 1177 | if (reinit_and_retry(cs, -1) < 0) |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1178 | schedule_init(cs, MS_RECOVER); |
| 1179 | break; |
| 1180 | case ACT_FAILUMODE: |
| 1181 | cs->cur_at_seq = SEQ_NONE; |
| 1182 | schedule_init(cs, MS_RECOVER); |
| 1183 | break; |
| 1184 | case ACT_HUPMODEM: |
| 1185 | /* send "+++" (hangup in unimodem mode) */ |
Tilman Schmidt | e3628dd | 2010-07-05 14:18:43 +0000 | [diff] [blame] | 1186 | if (cs->connected) { |
| 1187 | struct cmdbuf_t *cb; |
| 1188 | |
| 1189 | cb = kmalloc(sizeof(struct cmdbuf_t) + 3, GFP_ATOMIC); |
| 1190 | if (!cb) { |
| 1191 | dev_err(cs->dev, "%s: out of memory\n", |
| 1192 | __func__); |
| 1193 | return; |
| 1194 | } |
| 1195 | memcpy(cb->buf, "+++", 3); |
| 1196 | cb->len = 3; |
| 1197 | cb->offset = 0; |
| 1198 | cb->next = NULL; |
| 1199 | cb->wake_tasklet = NULL; |
| 1200 | cs->ops->write_cmd(cs, cb); |
| 1201 | } |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1202 | break; |
| 1203 | case ACT_RING: |
| 1204 | /* get fresh AT state structure for new CID */ |
Tilman Schmidt | b8324f9 | 2014-10-11 13:46:30 +0200 | [diff] [blame] | 1205 | at_state = get_free_channel(cs, ev->parameter); |
| 1206 | if (!at_state) { |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1207 | dev_warn(cs->dev, |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 1208 | "RING ignored: could not allocate channel structure\n"); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1209 | break; |
| 1210 | } |
| 1211 | |
| 1212 | /* initialize AT state structure |
| 1213 | * note that bcs may be NULL if no B channel is free |
| 1214 | */ |
Tilman Schmidt | b8324f9 | 2014-10-11 13:46:30 +0200 | [diff] [blame] | 1215 | at_state->ConState = 700; |
Tilman Schmidt | 3a0a3a6 | 2010-03-14 12:58:05 +0000 | [diff] [blame] | 1216 | for (i = 0; i < STR_NUM; ++i) { |
Tilman Schmidt | b8324f9 | 2014-10-11 13:46:30 +0200 | [diff] [blame] | 1217 | kfree(at_state->str_var[i]); |
| 1218 | at_state->str_var[i] = NULL; |
Tilman Schmidt | 3a0a3a6 | 2010-03-14 12:58:05 +0000 | [diff] [blame] | 1219 | } |
Tilman Schmidt | b8324f9 | 2014-10-11 13:46:30 +0200 | [diff] [blame] | 1220 | at_state->int_var[VAR_ZCTP] = -1; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1221 | |
| 1222 | spin_lock_irqsave(&cs->lock, flags); |
Tilman Schmidt | b8324f9 | 2014-10-11 13:46:30 +0200 | [diff] [blame] | 1223 | at_state->timer_expires = RING_TIMEOUT; |
| 1224 | at_state->timer_active = 1; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1225 | spin_unlock_irqrestore(&cs->lock, flags); |
| 1226 | break; |
| 1227 | case ACT_ICALL: |
Tilman Schmidt | 63b203b | 2013-01-21 11:57:21 +0000 | [diff] [blame] | 1228 | handle_icall(cs, bcs, at_state); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1229 | break; |
| 1230 | case ACT_FAILSDOWN: |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1231 | dev_warn(cs->dev, "Could not shut down the device.\n"); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1232 | /* fall through */ |
| 1233 | case ACT_FAKESDOWN: |
| 1234 | case ACT_SDOWN: |
| 1235 | cs->cur_at_seq = SEQ_NONE; |
| 1236 | finish_shutdown(cs); |
| 1237 | break; |
| 1238 | case ACT_CONNECT: |
| 1239 | if (cs->onechannel) { |
| 1240 | at_state->pending_commands |= PC_DLE1; |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 1241 | cs->commands_pending = 1; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1242 | break; |
| 1243 | } |
| 1244 | bcs->chstate |= CHS_D_UP; |
Tilman Schmidt | 088ec0c | 2009-10-06 12:19:07 +0000 | [diff] [blame] | 1245 | gigaset_isdn_connD(bcs); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1246 | cs->ops->init_bchannel(bcs); |
| 1247 | break; |
| 1248 | case ACT_DLE1: |
| 1249 | cs->cur_at_seq = SEQ_NONE; |
| 1250 | bcs = cs->bcs + cs->curchannel; |
| 1251 | |
| 1252 | bcs->chstate |= CHS_D_UP; |
Tilman Schmidt | 088ec0c | 2009-10-06 12:19:07 +0000 | [diff] [blame] | 1253 | gigaset_isdn_connD(bcs); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1254 | cs->ops->init_bchannel(bcs); |
| 1255 | break; |
| 1256 | case ACT_FAKEHUP: |
| 1257 | at_state->int_var[VAR_ZSAU] = ZSAU_NULL; |
| 1258 | /* fall through */ |
| 1259 | case ACT_DISCONNECT: |
| 1260 | cs->cur_at_seq = SEQ_NONE; |
| 1261 | at_state->cid = -1; |
Tilman Schmidt | b8324f9 | 2014-10-11 13:46:30 +0200 | [diff] [blame] | 1262 | if (!bcs) { |
| 1263 | disconnect_nobc(p_at_state, cs); |
| 1264 | } else if (cs->onechannel && cs->dle) { |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1265 | /* Check for other open channels not needed: |
| 1266 | * DLE only used for M10x with one B channel. |
| 1267 | */ |
| 1268 | at_state->pending_commands |= PC_DLE0; |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 1269 | cs->commands_pending = 1; |
Tilman Schmidt | b8324f9 | 2014-10-11 13:46:30 +0200 | [diff] [blame] | 1270 | } else { |
| 1271 | disconnect_bc(at_state, cs, bcs); |
| 1272 | } |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1273 | break; |
| 1274 | case ACT_FAKEDLE0: |
| 1275 | at_state->int_var[VAR_ZDLE] = 0; |
| 1276 | cs->dle = 0; |
| 1277 | /* fall through */ |
| 1278 | case ACT_DLE0: |
| 1279 | cs->cur_at_seq = SEQ_NONE; |
Tilman Schmidt | b8324f9 | 2014-10-11 13:46:30 +0200 | [diff] [blame] | 1280 | bcs2 = cs->bcs + cs->curchannel; |
| 1281 | disconnect_bc(&bcs2->at_state, cs, bcs2); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1282 | break; |
| 1283 | case ACT_ABORTHUP: |
| 1284 | cs->cur_at_seq = SEQ_NONE; |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1285 | dev_warn(cs->dev, "Could not hang up.\n"); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1286 | at_state->cid = -1; |
Tilman Schmidt | b8324f9 | 2014-10-11 13:46:30 +0200 | [diff] [blame] | 1287 | if (!bcs) |
| 1288 | disconnect_nobc(p_at_state, cs); |
| 1289 | else if (cs->onechannel) |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1290 | at_state->pending_commands |= PC_DLE0; |
Tilman Schmidt | 698e3ed | 2006-06-26 00:25:34 -0700 | [diff] [blame] | 1291 | else |
Tilman Schmidt | b8324f9 | 2014-10-11 13:46:30 +0200 | [diff] [blame] | 1292 | disconnect_bc(at_state, cs, bcs); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1293 | schedule_init(cs, MS_RECOVER); |
| 1294 | break; |
| 1295 | case ACT_FAILDLE0: |
| 1296 | cs->cur_at_seq = SEQ_NONE; |
Tilman Schmidt | 5dcd7d8 | 2014-10-03 17:03:32 +0200 | [diff] [blame] | 1297 | dev_warn(cs->dev, "Error leaving DLE mode.\n"); |
| 1298 | cs->dle = 0; |
Tilman Schmidt | b8324f9 | 2014-10-11 13:46:30 +0200 | [diff] [blame] | 1299 | bcs2 = cs->bcs + cs->curchannel; |
| 1300 | disconnect_bc(&bcs2->at_state, cs, bcs2); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1301 | schedule_init(cs, MS_RECOVER); |
| 1302 | break; |
| 1303 | case ACT_FAILDLE1: |
| 1304 | cs->cur_at_seq = SEQ_NONE; |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1305 | dev_warn(cs->dev, |
| 1306 | "Could not enter DLE mode. Trying to hang up.\n"); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1307 | channel = cs->curchannel; |
| 1308 | cs->bcs[channel].at_state.pending_commands |= PC_HUP; |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 1309 | cs->commands_pending = 1; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1310 | break; |
| 1311 | |
| 1312 | case ACT_CID: /* got cid; start dialing */ |
| 1313 | cs->cur_at_seq = SEQ_NONE; |
| 1314 | channel = cs->curchannel; |
| 1315 | if (ev->parameter > 0 && ev->parameter <= 65535) { |
| 1316 | cs->bcs[channel].at_state.cid = ev->parameter; |
| 1317 | cs->bcs[channel].at_state.pending_commands |= |
| 1318 | PC_DIAL; |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 1319 | cs->commands_pending = 1; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1320 | break; |
| 1321 | } |
Tilman Schmidt | 63b203b | 2013-01-21 11:57:21 +0000 | [diff] [blame] | 1322 | /* bad cid: fall through */ |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1323 | case ACT_FAILCID: |
| 1324 | cs->cur_at_seq = SEQ_NONE; |
| 1325 | channel = cs->curchannel; |
Tilman Schmidt | 81fa7b8 | 2012-04-25 13:02:20 +0000 | [diff] [blame] | 1326 | if (reinit_and_retry(cs, channel) < 0) { |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1327 | dev_warn(cs->dev, |
| 1328 | "Could not get a call ID. Cannot dial.\n"); |
Tilman Schmidt | b8324f9 | 2014-10-11 13:46:30 +0200 | [diff] [blame] | 1329 | bcs2 = cs->bcs + channel; |
| 1330 | disconnect_bc(&bcs2->at_state, cs, bcs2); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1331 | } |
| 1332 | break; |
| 1333 | case ACT_ABORTCID: |
| 1334 | cs->cur_at_seq = SEQ_NONE; |
Tilman Schmidt | b8324f9 | 2014-10-11 13:46:30 +0200 | [diff] [blame] | 1335 | bcs2 = cs->bcs + cs->curchannel; |
| 1336 | disconnect_bc(&bcs2->at_state, cs, bcs2); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1337 | break; |
| 1338 | |
| 1339 | case ACT_DIALING: |
| 1340 | case ACT_ACCEPTED: |
| 1341 | cs->cur_at_seq = SEQ_NONE; |
| 1342 | break; |
| 1343 | |
Tilman Schmidt | c35a87f | 2009-10-25 09:30:47 +0000 | [diff] [blame] | 1344 | case ACT_ABORTACCEPT: /* hangup/error/timeout during ICALL procssng */ |
Tilman Schmidt | b8324f9 | 2014-10-11 13:46:30 +0200 | [diff] [blame] | 1345 | if (bcs) |
| 1346 | disconnect_bc(at_state, cs, bcs); |
| 1347 | else |
| 1348 | disconnect_nobc(p_at_state, cs); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1349 | break; |
| 1350 | |
| 1351 | case ACT_ABORTDIAL: /* error/timeout during dial preparation */ |
| 1352 | cs->cur_at_seq = SEQ_NONE; |
| 1353 | at_state->pending_commands |= PC_HUP; |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 1354 | cs->commands_pending = 1; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1355 | break; |
| 1356 | |
| 1357 | case ACT_REMOTEREJECT: /* DISCONNECT_IND after dialling */ |
| 1358 | case ACT_CONNTIMEOUT: /* timeout waiting for ZSAU=ACTIVE */ |
| 1359 | case ACT_REMOTEHUP: /* DISCONNECT_IND with established connection */ |
| 1360 | at_state->pending_commands |= PC_HUP; |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 1361 | cs->commands_pending = 1; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1362 | break; |
Tilman Schmidt | 917f508 | 2006-04-10 22:55:00 -0700 | [diff] [blame] | 1363 | case ACT_GETSTRING: /* warning: RING, ZDLE, ... |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1364 | are not handled properly anymore */ |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1365 | at_state->getstring = 1; |
| 1366 | break; |
| 1367 | case ACT_SETVER: |
| 1368 | if (!ev->ptr) { |
| 1369 | *p_genresp = 1; |
| 1370 | *p_resp_code = RSP_ERROR; |
| 1371 | break; |
| 1372 | } |
| 1373 | s = ev->ptr; |
| 1374 | |
| 1375 | if (!strcmp(s, "OK")) { |
Tilman Schmidt | e055d03 | 2012-04-25 13:02:20 +0000 | [diff] [blame] | 1376 | /* OK without version string: assume old response */ |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1377 | *p_genresp = 1; |
Tilman Schmidt | e055d03 | 2012-04-25 13:02:20 +0000 | [diff] [blame] | 1378 | *p_resp_code = RSP_NONE; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1379 | break; |
| 1380 | } |
| 1381 | |
| 1382 | for (i = 0; i < 4; ++i) { |
| 1383 | val = simple_strtoul(s, (char **) &e, 10); |
| 1384 | if (val > INT_MAX || e == s) |
| 1385 | break; |
| 1386 | if (i == 3) { |
| 1387 | if (*e) |
| 1388 | break; |
| 1389 | } else if (*e != '.') |
| 1390 | break; |
| 1391 | else |
| 1392 | s = e + 1; |
| 1393 | cs->fwver[i] = val; |
| 1394 | } |
| 1395 | if (i != 4) { |
| 1396 | *p_genresp = 1; |
| 1397 | *p_resp_code = RSP_ERROR; |
| 1398 | break; |
| 1399 | } |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1400 | cs->gotfwver = 0; |
| 1401 | break; |
| 1402 | case ACT_GOTVER: |
| 1403 | if (cs->gotfwver == 0) { |
| 1404 | cs->gotfwver = 1; |
Tilman Schmidt | 1528b18 | 2010-02-22 13:09:52 +0000 | [diff] [blame] | 1405 | gig_dbg(DEBUG_EVENT, |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1406 | "firmware version %02d.%03d.%02d.%02d", |
| 1407 | cs->fwver[0], cs->fwver[1], |
| 1408 | cs->fwver[2], cs->fwver[3]); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1409 | break; |
| 1410 | } |
| 1411 | /* fall through */ |
| 1412 | case ACT_FAILVER: |
| 1413 | cs->gotfwver = -1; |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1414 | dev_err(cs->dev, "could not read firmware version.\n"); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1415 | break; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1416 | case ACT_ERROR: |
Tilman Schmidt | 05eae94f | 2009-10-06 12:18:46 +0000 | [diff] [blame] | 1417 | gig_dbg(DEBUG_ANY, "%s: ERROR response in ConState %d", |
| 1418 | __func__, at_state->ConState); |
| 1419 | cs->cur_at_seq = SEQ_NONE; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1420 | break; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1421 | case ACT_DEBUG: |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1422 | gig_dbg(DEBUG_ANY, "%s: resp_code %d in ConState %d", |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1423 | __func__, ev->type, at_state->ConState); |
| 1424 | break; |
| 1425 | case ACT_WARN: |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1426 | dev_warn(cs->dev, "%s: resp_code %d in ConState %d!\n", |
| 1427 | __func__, ev->type, at_state->ConState); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1428 | break; |
| 1429 | case ACT_ZCAU: |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1430 | dev_warn(cs->dev, "cause code %04x in connection state %d.\n", |
| 1431 | ev->parameter, at_state->ConState); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1432 | break; |
| 1433 | |
Tilman Schmidt | f86936f | 2012-04-25 13:02:20 +0000 | [diff] [blame] | 1434 | /* events from the LL */ |
| 1435 | |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1436 | case ACT_DIAL: |
Tilman Schmidt | 846ac30 | 2014-10-11 13:46:29 +0200 | [diff] [blame] | 1437 | if (!ev->ptr) { |
| 1438 | *p_genresp = 1; |
| 1439 | *p_resp_code = RSP_ERROR; |
| 1440 | break; |
| 1441 | } |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1442 | start_dial(at_state, ev->ptr, ev->parameter); |
| 1443 | break; |
| 1444 | case ACT_ACCEPT: |
| 1445 | start_accept(at_state); |
| 1446 | break; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1447 | case ACT_HUP: |
| 1448 | at_state->pending_commands |= PC_HUP; |
Tilman Schmidt | 1528b18 | 2010-02-22 13:09:52 +0000 | [diff] [blame] | 1449 | gig_dbg(DEBUG_EVENT, "Scheduling PC_HUP"); |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 1450 | cs->commands_pending = 1; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1451 | break; |
| 1452 | |
Tilman Schmidt | f86936f | 2012-04-25 13:02:20 +0000 | [diff] [blame] | 1453 | /* hotplug events */ |
| 1454 | |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1455 | case ACT_STOP: |
| 1456 | do_stop(cs); |
| 1457 | break; |
| 1458 | case ACT_START: |
| 1459 | do_start(cs); |
| 1460 | break; |
| 1461 | |
Tilman Schmidt | f86936f | 2012-04-25 13:02:20 +0000 | [diff] [blame] | 1462 | /* events from the interface */ |
| 1463 | |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1464 | case ACT_IF_LOCK: |
| 1465 | cs->cmd_result = ev->parameter ? do_lock(cs) : do_unlock(cs); |
| 1466 | cs->waiting = 0; |
| 1467 | wake_up(&cs->waitqueue); |
| 1468 | break; |
| 1469 | case ACT_IF_VER: |
| 1470 | if (ev->parameter != 0) |
| 1471 | cs->cmd_result = -EINVAL; |
| 1472 | else if (cs->gotfwver != 1) { |
| 1473 | cs->cmd_result = -ENOENT; |
| 1474 | } else { |
| 1475 | memcpy(ev->arg, cs->fwver, sizeof cs->fwver); |
| 1476 | cs->cmd_result = 0; |
| 1477 | } |
| 1478 | cs->waiting = 0; |
| 1479 | wake_up(&cs->waitqueue); |
| 1480 | break; |
| 1481 | |
Tilman Schmidt | f86936f | 2012-04-25 13:02:20 +0000 | [diff] [blame] | 1482 | /* events from the proc file system */ |
| 1483 | |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1484 | case ACT_PROC_CIDMODE: |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 1485 | spin_lock_irqsave(&cs->lock, flags); |
| 1486 | if (ev->parameter != cs->cidmode) { |
| 1487 | cs->cidmode = ev->parameter; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1488 | if (ev->parameter) { |
| 1489 | cs->at_state.pending_commands |= PC_CIDMODE; |
Tilman Schmidt | 1528b18 | 2010-02-22 13:09:52 +0000 | [diff] [blame] | 1490 | gig_dbg(DEBUG_EVENT, "Scheduling PC_CIDMODE"); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1491 | } else { |
| 1492 | cs->at_state.pending_commands |= PC_UMMODE; |
Tilman Schmidt | 1528b18 | 2010-02-22 13:09:52 +0000 | [diff] [blame] | 1493 | gig_dbg(DEBUG_EVENT, "Scheduling PC_UMMODE"); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1494 | } |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 1495 | cs->commands_pending = 1; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1496 | } |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 1497 | spin_unlock_irqrestore(&cs->lock, flags); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1498 | cs->waiting = 0; |
| 1499 | wake_up(&cs->waitqueue); |
| 1500 | break; |
| 1501 | |
Tilman Schmidt | f86936f | 2012-04-25 13:02:20 +0000 | [diff] [blame] | 1502 | /* events from the hardware drivers */ |
| 1503 | |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1504 | case ACT_NOTIFY_BC_DOWN: |
| 1505 | bchannel_down(bcs); |
| 1506 | break; |
| 1507 | case ACT_NOTIFY_BC_UP: |
| 1508 | bchannel_up(bcs); |
| 1509 | break; |
| 1510 | case ACT_SHUTDOWN: |
| 1511 | do_shutdown(cs); |
| 1512 | break; |
| 1513 | |
| 1514 | |
| 1515 | default: |
| 1516 | if (action >= ACT_CMD && action < ACT_CMD + AT_NUM) { |
| 1517 | *pp_command = at_state->bcs->commands[action - ACT_CMD]; |
| 1518 | if (!*pp_command) { |
| 1519 | *p_genresp = 1; |
| 1520 | *p_resp_code = RSP_NULL; |
| 1521 | } |
| 1522 | } else |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1523 | dev_err(cs->dev, "%s: action==%d!\n", __func__, action); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1524 | } |
| 1525 | } |
| 1526 | |
| 1527 | /* State machine to do the calling and hangup procedure */ |
| 1528 | static void process_event(struct cardstate *cs, struct event_t *ev) |
| 1529 | { |
| 1530 | struct bc_state *bcs; |
| 1531 | char *p_command = NULL; |
| 1532 | struct reply_t *rep; |
| 1533 | int rcode; |
| 1534 | int genresp = 0; |
| 1535 | int resp_code = RSP_ERROR; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1536 | struct at_state_t *at_state; |
| 1537 | int index; |
| 1538 | int curact; |
| 1539 | unsigned long flags; |
| 1540 | |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1541 | if (ev->cid >= 0) { |
| 1542 | at_state = at_state_from_cid(cs, ev->cid); |
| 1543 | if (!at_state) { |
Tilman Schmidt | 1528b18 | 2010-02-22 13:09:52 +0000 | [diff] [blame] | 1544 | gig_dbg(DEBUG_EVENT, "event %d for invalid cid %d", |
| 1545 | ev->type, ev->cid); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1546 | gigaset_add_event(cs, &cs->at_state, RSP_WRONG_CID, |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1547 | NULL, 0, NULL); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1548 | return; |
| 1549 | } |
| 1550 | } else { |
| 1551 | at_state = ev->at_state; |
| 1552 | if (at_state_invalid(cs, at_state)) { |
Tilman Schmidt | 1528b18 | 2010-02-22 13:09:52 +0000 | [diff] [blame] | 1553 | gig_dbg(DEBUG_EVENT, "event for invalid at_state %p", |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1554 | at_state); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1555 | return; |
| 1556 | } |
| 1557 | } |
| 1558 | |
Tilman Schmidt | 1528b18 | 2010-02-22 13:09:52 +0000 | [diff] [blame] | 1559 | gig_dbg(DEBUG_EVENT, "connection state %d, event %d", |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1560 | at_state->ConState, ev->type); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1561 | |
| 1562 | bcs = at_state->bcs; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1563 | |
| 1564 | /* Setting the pointer to the dial array */ |
| 1565 | rep = at_state->replystruct; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1566 | |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 1567 | spin_lock_irqsave(&cs->lock, flags); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1568 | if (ev->type == EV_TIMEOUT) { |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 1569 | if (ev->parameter != at_state->timer_index |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1570 | || !at_state->timer_active) { |
| 1571 | ev->type = RSP_NONE; /* old timeout */ |
Tilman Schmidt | 1528b18 | 2010-02-22 13:09:52 +0000 | [diff] [blame] | 1572 | gig_dbg(DEBUG_EVENT, "old timeout"); |
Tilman Schmidt | 63b203b | 2013-01-21 11:57:21 +0000 | [diff] [blame] | 1573 | } else { |
| 1574 | if (at_state->waiting) |
| 1575 | gig_dbg(DEBUG_EVENT, "stopped waiting"); |
| 1576 | else |
| 1577 | gig_dbg(DEBUG_EVENT, "timeout occurred"); |
| 1578 | } |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1579 | } |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 1580 | spin_unlock_irqrestore(&cs->lock, flags); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1581 | |
Tilman Schmidt | 917f508 | 2006-04-10 22:55:00 -0700 | [diff] [blame] | 1582 | /* if the response belongs to a variable in at_state->int_var[VAR_XXXX] |
| 1583 | or at_state->str_var[STR_XXXX], set it */ |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1584 | if (ev->type >= RSP_VAR && ev->type < RSP_VAR + VAR_NUM) { |
| 1585 | index = ev->type - RSP_VAR; |
| 1586 | at_state->int_var[index] = ev->parameter; |
| 1587 | } else if (ev->type >= RSP_STR && ev->type < RSP_STR + STR_NUM) { |
| 1588 | index = ev->type - RSP_STR; |
| 1589 | kfree(at_state->str_var[index]); |
| 1590 | at_state->str_var[index] = ev->ptr; |
Tilman Schmidt | 917f508 | 2006-04-10 22:55:00 -0700 | [diff] [blame] | 1591 | ev->ptr = NULL; /* prevent process_events() from |
| 1592 | deallocating ptr */ |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1593 | } |
| 1594 | |
| 1595 | if (ev->type == EV_TIMEOUT || ev->type == RSP_STRING) |
| 1596 | at_state->getstring = 0; |
| 1597 | |
Tilman Schmidt | 917f508 | 2006-04-10 22:55:00 -0700 | [diff] [blame] | 1598 | /* Search row in dial array which matches modem response and current |
| 1599 | constate */ |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1600 | for (;; rep++) { |
| 1601 | rcode = rep->resp_code; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1602 | if (rcode == RSP_LAST) { |
| 1603 | /* found nothing...*/ |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1604 | dev_warn(cs->dev, "%s: rcode=RSP_LAST: " |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 1605 | "resp_code %d in ConState %d!\n", |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1606 | __func__, ev->type, at_state->ConState); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1607 | return; |
| 1608 | } |
| 1609 | if ((rcode == RSP_ANY || rcode == ev->type) |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 1610 | && ((int) at_state->ConState >= rep->min_ConState) |
| 1611 | && (rep->max_ConState < 0 |
| 1612 | || (int) at_state->ConState <= rep->max_ConState) |
| 1613 | && (rep->parameter < 0 || rep->parameter == ev->parameter)) |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1614 | break; |
| 1615 | } |
| 1616 | |
| 1617 | p_command = rep->command; |
| 1618 | |
| 1619 | at_state->waiting = 0; |
| 1620 | for (curact = 0; curact < MAXACT; ++curact) { |
| 1621 | /* The row tells us what we should do .. |
| 1622 | */ |
Tilman Schmidt | c35a87f | 2009-10-25 09:30:47 +0000 | [diff] [blame] | 1623 | do_action(rep->action[curact], cs, bcs, &at_state, &p_command, |
| 1624 | &genresp, &resp_code, ev); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1625 | if (!at_state) |
Tilman Schmidt | 63b203b | 2013-01-21 11:57:21 +0000 | [diff] [blame] | 1626 | /* at_state destroyed by disconnect */ |
| 1627 | return; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1628 | } |
| 1629 | |
Tilman Schmidt | 63b203b | 2013-01-21 11:57:21 +0000 | [diff] [blame] | 1630 | /* Jump to the next con-state regarding the array */ |
| 1631 | if (rep->new_ConState >= 0) |
| 1632 | at_state->ConState = rep->new_ConState; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1633 | |
Tilman Schmidt | 63b203b | 2013-01-21 11:57:21 +0000 | [diff] [blame] | 1634 | if (genresp) { |
| 1635 | spin_lock_irqsave(&cs->lock, flags); |
| 1636 | at_state->timer_expires = 0; |
| 1637 | at_state->timer_active = 0; |
| 1638 | spin_unlock_irqrestore(&cs->lock, flags); |
| 1639 | gigaset_add_event(cs, at_state, resp_code, NULL, 0, NULL); |
| 1640 | } else { |
| 1641 | /* Send command to modem if not NULL... */ |
| 1642 | if (p_command) { |
| 1643 | if (cs->connected) |
| 1644 | send_command(cs, p_command, at_state); |
| 1645 | else |
| 1646 | gigaset_add_event(cs, at_state, RSP_NODEV, |
| 1647 | NULL, 0, NULL); |
| 1648 | } |
| 1649 | |
| 1650 | spin_lock_irqsave(&cs->lock, flags); |
| 1651 | if (!rep->timeout) { |
Tilman Schmidt | c35a87f | 2009-10-25 09:30:47 +0000 | [diff] [blame] | 1652 | at_state->timer_expires = 0; |
| 1653 | at_state->timer_active = 0; |
Tilman Schmidt | 63b203b | 2013-01-21 11:57:21 +0000 | [diff] [blame] | 1654 | } else if (rep->timeout > 0) { /* new timeout */ |
| 1655 | at_state->timer_expires = rep->timeout * 10; |
| 1656 | at_state->timer_active = 1; |
| 1657 | ++at_state->timer_index; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1658 | } |
Tilman Schmidt | 63b203b | 2013-01-21 11:57:21 +0000 | [diff] [blame] | 1659 | spin_unlock_irqrestore(&cs->lock, flags); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1660 | } |
| 1661 | } |
| 1662 | |
| 1663 | static void schedule_sequence(struct cardstate *cs, |
| 1664 | struct at_state_t *at_state, int sequence) |
| 1665 | { |
| 1666 | cs->cur_at_seq = sequence; |
| 1667 | gigaset_add_event(cs, at_state, RSP_INIT, NULL, sequence, NULL); |
| 1668 | } |
| 1669 | |
| 1670 | static void process_command_flags(struct cardstate *cs) |
| 1671 | { |
| 1672 | struct at_state_t *at_state = NULL; |
| 1673 | struct bc_state *bcs; |
| 1674 | int i; |
| 1675 | int sequence; |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 1676 | unsigned long flags; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1677 | |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 1678 | cs->commands_pending = 0; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1679 | |
| 1680 | if (cs->cur_at_seq) { |
Tilman Schmidt | 1528b18 | 2010-02-22 13:09:52 +0000 | [diff] [blame] | 1681 | gig_dbg(DEBUG_EVENT, "not searching scheduled commands: busy"); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1682 | return; |
| 1683 | } |
| 1684 | |
Tilman Schmidt | 1528b18 | 2010-02-22 13:09:52 +0000 | [diff] [blame] | 1685 | gig_dbg(DEBUG_EVENT, "searching scheduled commands"); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1686 | |
| 1687 | sequence = SEQ_NONE; |
| 1688 | |
| 1689 | /* clear pending_commands and hangup channels on shutdown */ |
| 1690 | if (cs->at_state.pending_commands & PC_SHUTDOWN) { |
| 1691 | cs->at_state.pending_commands &= ~PC_CIDMODE; |
| 1692 | for (i = 0; i < cs->channels; ++i) { |
| 1693 | bcs = cs->bcs + i; |
| 1694 | at_state = &bcs->at_state; |
| 1695 | at_state->pending_commands &= |
| 1696 | ~(PC_DLE1 | PC_ACCEPT | PC_DIAL); |
| 1697 | if (at_state->cid > 0) |
| 1698 | at_state->pending_commands |= PC_HUP; |
| 1699 | if (at_state->pending_commands & PC_CID) { |
| 1700 | at_state->pending_commands |= PC_NOCID; |
| 1701 | at_state->pending_commands &= ~PC_CID; |
| 1702 | } |
| 1703 | } |
| 1704 | } |
| 1705 | |
| 1706 | /* clear pending_commands and hangup channels on reset */ |
| 1707 | if (cs->at_state.pending_commands & PC_INIT) { |
| 1708 | cs->at_state.pending_commands &= ~PC_CIDMODE; |
| 1709 | for (i = 0; i < cs->channels; ++i) { |
| 1710 | bcs = cs->bcs + i; |
| 1711 | at_state = &bcs->at_state; |
| 1712 | at_state->pending_commands &= |
| 1713 | ~(PC_DLE1 | PC_ACCEPT | PC_DIAL); |
| 1714 | if (at_state->cid > 0) |
| 1715 | at_state->pending_commands |= PC_HUP; |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 1716 | if (cs->mstate == MS_RECOVER) { |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1717 | if (at_state->pending_commands & PC_CID) { |
| 1718 | at_state->pending_commands |= PC_NOCID; |
| 1719 | at_state->pending_commands &= ~PC_CID; |
| 1720 | } |
| 1721 | } |
| 1722 | } |
| 1723 | } |
| 1724 | |
Tilman Schmidt | c35a87f | 2009-10-25 09:30:47 +0000 | [diff] [blame] | 1725 | /* only switch back to unimodem mode if no commands are pending and |
| 1726 | * no channels are up */ |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 1727 | spin_lock_irqsave(&cs->lock, flags); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1728 | if (cs->at_state.pending_commands == PC_UMMODE |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 1729 | && !cs->cidmode |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1730 | && list_empty(&cs->temp_at_states) |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 1731 | && cs->mode == M_CID) { |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1732 | sequence = SEQ_UMMODE; |
| 1733 | at_state = &cs->at_state; |
| 1734 | for (i = 0; i < cs->channels; ++i) { |
| 1735 | bcs = cs->bcs + i; |
| 1736 | if (bcs->at_state.pending_commands || |
| 1737 | bcs->at_state.cid > 0) { |
| 1738 | sequence = SEQ_NONE; |
| 1739 | break; |
| 1740 | } |
| 1741 | } |
| 1742 | } |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 1743 | spin_unlock_irqrestore(&cs->lock, flags); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1744 | cs->at_state.pending_commands &= ~PC_UMMODE; |
| 1745 | if (sequence != SEQ_NONE) { |
| 1746 | schedule_sequence(cs, at_state, sequence); |
| 1747 | return; |
| 1748 | } |
| 1749 | |
| 1750 | for (i = 0; i < cs->channels; ++i) { |
| 1751 | bcs = cs->bcs + i; |
| 1752 | if (bcs->at_state.pending_commands & PC_HUP) { |
Tilman Schmidt | d2ca848 | 2013-01-21 11:57:20 +0000 | [diff] [blame] | 1753 | if (cs->dle) { |
| 1754 | cs->curchannel = bcs->channel; |
| 1755 | schedule_sequence(cs, &cs->at_state, SEQ_DLE0); |
| 1756 | return; |
| 1757 | } |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1758 | bcs->at_state.pending_commands &= ~PC_HUP; |
| 1759 | if (bcs->at_state.pending_commands & PC_CID) { |
| 1760 | /* not yet dialing: PC_NOCID is sufficient */ |
| 1761 | bcs->at_state.pending_commands |= PC_NOCID; |
| 1762 | bcs->at_state.pending_commands &= ~PC_CID; |
| 1763 | } else { |
| 1764 | schedule_sequence(cs, &bcs->at_state, SEQ_HUP); |
| 1765 | return; |
| 1766 | } |
| 1767 | } |
| 1768 | if (bcs->at_state.pending_commands & PC_NOCID) { |
| 1769 | bcs->at_state.pending_commands &= ~PC_NOCID; |
| 1770 | cs->curchannel = bcs->channel; |
| 1771 | schedule_sequence(cs, &cs->at_state, SEQ_NOCID); |
| 1772 | return; |
| 1773 | } else if (bcs->at_state.pending_commands & PC_DLE0) { |
| 1774 | bcs->at_state.pending_commands &= ~PC_DLE0; |
| 1775 | cs->curchannel = bcs->channel; |
| 1776 | schedule_sequence(cs, &cs->at_state, SEQ_DLE0); |
| 1777 | return; |
| 1778 | } |
| 1779 | } |
| 1780 | |
| 1781 | list_for_each_entry(at_state, &cs->temp_at_states, list) |
| 1782 | if (at_state->pending_commands & PC_HUP) { |
| 1783 | at_state->pending_commands &= ~PC_HUP; |
| 1784 | schedule_sequence(cs, at_state, SEQ_HUP); |
| 1785 | return; |
| 1786 | } |
| 1787 | |
| 1788 | if (cs->at_state.pending_commands & PC_INIT) { |
| 1789 | cs->at_state.pending_commands &= ~PC_INIT; |
Tilman Schmidt | c35a87f | 2009-10-25 09:30:47 +0000 | [diff] [blame] | 1790 | cs->dle = 0; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1791 | cs->inbuf->inputstate = INS_command; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1792 | schedule_sequence(cs, &cs->at_state, SEQ_INIT); |
| 1793 | return; |
| 1794 | } |
| 1795 | if (cs->at_state.pending_commands & PC_SHUTDOWN) { |
| 1796 | cs->at_state.pending_commands &= ~PC_SHUTDOWN; |
| 1797 | schedule_sequence(cs, &cs->at_state, SEQ_SHUTDOWN); |
| 1798 | return; |
| 1799 | } |
| 1800 | if (cs->at_state.pending_commands & PC_CIDMODE) { |
| 1801 | cs->at_state.pending_commands &= ~PC_CIDMODE; |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 1802 | if (cs->mode == M_UNIMODEM) { |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1803 | cs->retry_count = 1; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1804 | schedule_sequence(cs, &cs->at_state, SEQ_CIDMODE); |
| 1805 | return; |
| 1806 | } |
| 1807 | } |
| 1808 | |
| 1809 | for (i = 0; i < cs->channels; ++i) { |
| 1810 | bcs = cs->bcs + i; |
| 1811 | if (bcs->at_state.pending_commands & PC_DLE1) { |
| 1812 | bcs->at_state.pending_commands &= ~PC_DLE1; |
| 1813 | cs->curchannel = bcs->channel; |
| 1814 | schedule_sequence(cs, &cs->at_state, SEQ_DLE1); |
| 1815 | return; |
| 1816 | } |
| 1817 | if (bcs->at_state.pending_commands & PC_ACCEPT) { |
| 1818 | bcs->at_state.pending_commands &= ~PC_ACCEPT; |
| 1819 | schedule_sequence(cs, &bcs->at_state, SEQ_ACCEPT); |
| 1820 | return; |
| 1821 | } |
| 1822 | if (bcs->at_state.pending_commands & PC_DIAL) { |
| 1823 | bcs->at_state.pending_commands &= ~PC_DIAL; |
| 1824 | schedule_sequence(cs, &bcs->at_state, SEQ_DIAL); |
| 1825 | return; |
| 1826 | } |
| 1827 | if (bcs->at_state.pending_commands & PC_CID) { |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 1828 | switch (cs->mode) { |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1829 | case M_UNIMODEM: |
| 1830 | cs->at_state.pending_commands |= PC_CIDMODE; |
Tilman Schmidt | 1528b18 | 2010-02-22 13:09:52 +0000 | [diff] [blame] | 1831 | gig_dbg(DEBUG_EVENT, "Scheduling PC_CIDMODE"); |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 1832 | cs->commands_pending = 1; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1833 | return; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1834 | case M_UNKNOWN: |
| 1835 | schedule_init(cs, MS_INIT); |
| 1836 | return; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1837 | } |
| 1838 | bcs->at_state.pending_commands &= ~PC_CID; |
| 1839 | cs->curchannel = bcs->channel; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1840 | cs->retry_count = 2; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1841 | schedule_sequence(cs, &cs->at_state, SEQ_CID); |
| 1842 | return; |
| 1843 | } |
| 1844 | } |
| 1845 | } |
| 1846 | |
| 1847 | static void process_events(struct cardstate *cs) |
| 1848 | { |
| 1849 | struct event_t *ev; |
| 1850 | unsigned head, tail; |
| 1851 | int i; |
| 1852 | int check_flags = 0; |
| 1853 | int was_busy; |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 1854 | unsigned long flags; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1855 | |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 1856 | spin_lock_irqsave(&cs->ev_lock, flags); |
| 1857 | head = cs->ev_head; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1858 | |
| 1859 | for (i = 0; i < 2 * MAX_EVENTS; ++i) { |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 1860 | tail = cs->ev_tail; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1861 | if (tail == head) { |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 1862 | if (!check_flags && !cs->commands_pending) |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1863 | break; |
| 1864 | check_flags = 0; |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 1865 | spin_unlock_irqrestore(&cs->ev_lock, flags); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1866 | process_command_flags(cs); |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 1867 | spin_lock_irqsave(&cs->ev_lock, flags); |
| 1868 | tail = cs->ev_tail; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1869 | if (tail == head) { |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 1870 | if (!cs->commands_pending) |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1871 | break; |
| 1872 | continue; |
| 1873 | } |
| 1874 | } |
| 1875 | |
| 1876 | ev = cs->events + head; |
| 1877 | was_busy = cs->cur_at_seq != SEQ_NONE; |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 1878 | spin_unlock_irqrestore(&cs->ev_lock, flags); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1879 | process_event(cs, ev); |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 1880 | spin_lock_irqsave(&cs->ev_lock, flags); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1881 | kfree(ev->ptr); |
| 1882 | ev->ptr = NULL; |
| 1883 | if (was_busy && cs->cur_at_seq == SEQ_NONE) |
| 1884 | check_flags = 1; |
| 1885 | |
| 1886 | head = (head + 1) % MAX_EVENTS; |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 1887 | cs->ev_head = head; |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1888 | } |
| 1889 | |
Tilman Schmidt | 69049cc | 2006-04-10 22:55:16 -0700 | [diff] [blame] | 1890 | spin_unlock_irqrestore(&cs->ev_lock, flags); |
| 1891 | |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1892 | if (i == 2 * MAX_EVENTS) { |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1893 | dev_err(cs->dev, |
| 1894 | "infinite loop in process_events; aborting.\n"); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1895 | } |
| 1896 | } |
| 1897 | |
| 1898 | /* tasklet scheduled on any event received from the Gigaset device |
| 1899 | * parameter: |
| 1900 | * data ISDN controller state structure |
| 1901 | */ |
| 1902 | void gigaset_handle_event(unsigned long data) |
| 1903 | { |
| 1904 | struct cardstate *cs = (struct cardstate *) data; |
| 1905 | |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1906 | /* handle incoming data on control/common channel */ |
Tilman Schmidt | 9d4bee2 | 2008-02-06 01:38:28 -0800 | [diff] [blame] | 1907 | if (cs->inbuf->head != cs->inbuf->tail) { |
Tilman Schmidt | 784d585 | 2006-04-10 22:55:04 -0700 | [diff] [blame] | 1908 | gig_dbg(DEBUG_INTR, "processing new data"); |
Hansjoerg Lipp | 14fa73a | 2006-03-26 01:38:30 -0800 | [diff] [blame] | 1909 | cs->ops->handle_input(cs->inbuf); |
| 1910 | } |
| 1911 | |
| 1912 | process_events(cs); |
| 1913 | } |