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