Package: asterisk / 1:1.6.2.9-2+squeeze12

dahdi-fxsks-hookstate Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
Subject: Allow FXO channels to send out calls even before someone calls in through them
Author: frawd (issues.asterisk.org user)
Bug: http://issues.asterisk.org/view.php?id=14577
Last-Update: 2010-03-31

This rxisoffhook does not work. Before 1.6.0 it was wrapped in a #ifdef
DAHDI_CHECK_HOOKSTATE (or rather: ZAP_CHECK_HOOKSTATE). In 1.6 it is 
accidentally enabled by default.

On DAHDI (the kernel) this field is not properly initialized at startup. 
And thus it will only work after an incoming ring.

This patch makes the test only apply to FXS devices (FXO* signalling)
by default, and leaves the test of other signalling types as a build-time
option (which we don't enable).

(Patch asterisk_chan_dahdi_hookstate_fix.diff)

--- a/channels/chan_dahdi.c
+++ b/channels/chan_dahdi.c
@@ -10698,10 +10698,10 @@ static inline int available(struct dahdi
 				return 1;
 		}
 #endif
-		if (!(p->radio || (p->oprmode < 0)))
+
+		/* Trust hook state */
+		if (p->sig && !(p->radio || (p->oprmode < 0)))
 		{
-			if (!p->sig || (p->sig == SIG_FXSLS))
-				return 1;
 			/* Check hook state */
 			if (p->subs[SUB_REAL].dfd > -1) {
 				memset(&par, 0, sizeof(par));
@@ -10711,28 +10711,30 @@ static inline int available(struct dahdi
 				res = 0;
 				par.rxisoffhook = 0;
 			}
+
 			if (res) {
 				ast_log(LOG_WARNING, "Unable to check hook state on channel %d: %s\n", p->channel, strerror(errno));
-			} else if ((p->sig == SIG_FXSKS) || (p->sig == SIG_FXSGS)) {
-				/* When "onhook" that means no battery on the line, and thus
-				  it is out of service..., if it's on a TDM card... If it's a channel
-				  bank, there is no telling... */
+			}
+			else if ((p->sig != SIG_FXSKS) && (p->sig != SIG_FXSGS) && (p->sig != SIG_FXSLS)) {
+				if (par.rxisoffhook) {
+					ast_debug(1, "Channel %d off hook, can't use\n", p->channel);
+					/* Not available when the other end is off hook */
+					return 0;
+				}
+			}
+#ifdef DAHDI_CHECK_HOOKSTATE
+			} else { /* FXO channel case (SIG_FXS--) */
+				/* Channel bank (using CAS), "onhook" does not necessarily means out of service, so return 1 */
 				if (par.rxbits > -1)
 					return 1;
+				/* TDM FXO card, "onhook" means out of service (no battery on the line) */
 				if (par.rxisoffhook)
 					return 1;
 				else
 					return 0;
-			} else if (par.rxisoffhook) {
-				ast_debug(1, "Channel %d off hook, can't use\n", p->channel);
-				/* Not available when the other end is off hook */
-#ifdef DAHDI_CHECK_HOOKSTATE
-				return 0;
-#else
-				return 1;
 #endif
-			}
 		}
+
 		return 1;
 	}