<p>N A has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/19714">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">chan_dahdi: Allow autoreoriginating after hangup.<br><br>Currently, if an FXS channel is still off hook when<br>all calls on the line have hung up, the user is provided<br>reorder tone until going back on hook again.<br><br>In addition to not reflecting what most commercial switches<br>actually do, it's very common for switches to automatically<br>reoriginate for the user so that dial tone is provided without<br>the user having to depress and release the hookswitch manually.<br>This can increase convenience for users.<br><br>This behavior is now supported for kewlstart FXS channels.<br>It's supported only for kewlstart (FXOKS) mainly because the<br>behavior doesn't make any sense for ground start channels,<br>and loop start signalling doesn't provide the necessary DAHDI<br>event that makes this easy to implement. Likely almost everyone<br>is using FXOKS over FXOLS anyways since FXOLS is pretty useless<br>these days.<br><br>ASTERISK-30357 #close<br><br>Change-Id: Ic6f182c821c4c8d0a14a8f0906264688d6cc7820<br>---<br>M channels/chan_dahdi.c<br>M channels/chan_dahdi.h<br>M configs/samples/chan_dahdi.conf.sample<br>A doc/CHANGES-staging/chan_dahdi_autoreorig.txt<br>4 files changed, 106 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/14/19714/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/channels/chan_dahdi.c b/channels/chan_dahdi.c</span><br><span>index 5607eb0..26adba1 100644</span><br><span>--- a/channels/chan_dahdi.c</span><br><span>+++ b/channels/chan_dahdi.c</span><br><span>@@ -6532,6 +6532,36 @@</span><br><span>      ast_free(p->cidspill);</span><br><span>    p->cidspill = NULL;</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+    if (p->reoriginate && p->sig == SIG_FXOKS && dahdi_analog_lib_handles(p->sig, p->radio, 0)) {</span><br><span style="color: hsl(120, 100%, 40%);">+             /* Automatic reorigination: if all calls towards a user have hung up,</span><br><span style="color: hsl(120, 100%, 40%);">+          * give dial tone again, so user doesn't need to cycle the hook state manually. */</span><br><span style="color: hsl(120, 100%, 40%);">+                if (my_is_off_hook(p) && !p->owner) {</span><br><span style="color: hsl(120, 100%, 40%);">+                      /* 2 important criteria: channel must be off-hook, with no calls remaining (no owner) */</span><br><span style="color: hsl(120, 100%, 40%);">+                      ast_debug(1, "Queuing reorigination for channel %d\n", p->channel);</span><br><span style="color: hsl(120, 100%, 40%);">+                      my_play_tone(p, SUB_REAL, -1); /* Stop any congestion tone that may be present. */</span><br><span style="color: hsl(120, 100%, 40%);">+                    /* Must wait for the loop disconnect to end.</span><br><span style="color: hsl(120, 100%, 40%);">+                   * Sadly, these definitions are in dahdi/kernel.h, not dahdi/user.h</span><br><span style="color: hsl(120, 100%, 40%);">+                    * Calling usleep on an active DAHDI channel is a no-no, but this is okay.</span><br><span style="color: hsl(120, 100%, 40%);">+                     */</span><br><span style="color: hsl(120, 100%, 40%);">+                   usleep(800000); /* DAHDI_KEWLTIME + DAHDI_AFTERKEWLTIME */</span><br><span style="color: hsl(120, 100%, 40%);">+                    /* If the line is still off-hook and ownerless, actually queue the reorigination.</span><br><span style="color: hsl(120, 100%, 40%);">+                      * do_monitor will actually go ahead and do it. */</span><br><span style="color: hsl(120, 100%, 40%);">+                    if (!p->owner && my_is_off_hook(p)) {</span><br><span style="color: hsl(120, 100%, 40%);">+                              p->doreoriginate = 1; /* Tell do_monitor to reoriginate this channel */</span><br><span style="color: hsl(120, 100%, 40%);">+                            /* Note, my_off_hook will fail if called before the loop disconnect has finished</span><br><span style="color: hsl(120, 100%, 40%);">+                               * (important for FXOKS signaled channels). This is because DAHDI will reject</span><br><span style="color: hsl(120, 100%, 40%);">+                          * DAHDI_OFFHOOK while the channel is in TXSTATE_KEWL or TXSTATE_AFTERKEWL,</span><br><span style="color: hsl(120, 100%, 40%);">+                            * so we have to wait for that to finish (see comment above).</span><br><span style="color: hsl(120, 100%, 40%);">+                          * do_monitor itself cannot block, so make the blocking usleep call</span><br><span style="color: hsl(120, 100%, 40%);">+                            * here in the channel thread instead.</span><br><span style="color: hsl(120, 100%, 40%);">+                                 */</span><br><span style="color: hsl(120, 100%, 40%);">+                           my_off_hook(p); /* Now, go ahead and take the channel back off hook (sig_analog put it on hook) */</span><br><span style="color: hsl(120, 100%, 40%);">+                    } else {</span><br><span style="color: hsl(120, 100%, 40%);">+                              ast_debug(1, "Channel %d is no longer eligible for reorigination (went back on hook or became in use)\n", p->channel);</span><br><span style="color: hsl(120, 100%, 40%);">+                   }</span><br><span style="color: hsl(120, 100%, 40%);">+             }</span><br><span style="color: hsl(120, 100%, 40%);">+     }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>  ast_mutex_unlock(&p->lock);</span><br><span>   ast_verb(3, "Hungup '%s'\n", ast_channel_name(ast));</span><br><span> </span><br><span>@@ -11902,6 +11932,26 @@</span><br><span>                                                else</span><br><span>                                                         doomed = handle_init_event(i, res);</span><br><span>                                  }</span><br><span style="color: hsl(120, 100%, 40%);">+                                     if (i->doreoriginate && res == DAHDI_EVENT_HOOKCOMPLETE) {</span><br><span style="color: hsl(120, 100%, 40%);">+                                         /* Actually automatically reoriginate this FXS line, if directed to.</span><br><span style="color: hsl(120, 100%, 40%);">+                                           * We should get a DAHDI_EVENT_HOOKCOMPLETE from the loop disconnect</span><br><span style="color: hsl(120, 100%, 40%);">+                                           * doing its thing (one reason why this is for FXOKS only: FXOLS</span><br><span style="color: hsl(120, 100%, 40%);">+                                               * hangups don't give us any DAHDI events to piggyback off of)*/</span><br><span style="color: hsl(120, 100%, 40%);">+                                          i->doreoriginate = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+                                              /* Double check the channel is still off-hook. There's only about a millisecond</span><br><span style="color: hsl(120, 100%, 40%);">+                                            * between when doreoriginate is set high and we see that here, but just to be safe. */</span><br><span style="color: hsl(120, 100%, 40%);">+                                               if (!my_is_off_hook(i)) {</span><br><span style="color: hsl(120, 100%, 40%);">+                                                     ast_debug(1, "Woah! Went back on hook before reoriginate could happen on channel %d\n", i->channel);</span><br><span style="color: hsl(120, 100%, 40%);">+                                             } else {</span><br><span style="color: hsl(120, 100%, 40%);">+                                                      ast_verb(3, "Automatic reorigination on channel %d\n", i->channel);</span><br><span style="color: hsl(120, 100%, 40%);">+                                                      res = DAHDI_EVENT_RINGOFFHOOK; /* Pretend that the physical channel just went off hook */</span><br><span style="color: hsl(120, 100%, 40%);">+                                                     if (dahdi_analog_lib_handles(i->sig, i->radio, i->oprmode)) {</span><br><span style="color: hsl(120, 100%, 40%);">+                                                                doomed = (struct dahdi_pvt *) analog_handle_init_event(i->sig_pvt, dahdievent_to_analogevent(res));</span><br><span style="color: hsl(120, 100%, 40%);">+                                                        } else {</span><br><span style="color: hsl(120, 100%, 40%);">+                                                              doomed = handle_init_event(i, res);</span><br><span style="color: hsl(120, 100%, 40%);">+                                                   }</span><br><span style="color: hsl(120, 100%, 40%);">+                                             }</span><br><span style="color: hsl(120, 100%, 40%);">+                                     }</span><br><span>                                    ast_mutex_lock(&iflock);</span><br><span>                                 }</span><br><span>                    }</span><br><span>@@ -12994,6 +13044,7 @@</span><br><span>          tmp->ani_wink_time = conf->chan.ani_wink_time;</span><br><span>                 tmp->ani_timeout = conf->chan.ani_timeout;</span><br><span>             tmp->hanguponpolarityswitch = conf->chan.hanguponpolarityswitch;</span><br><span style="color: hsl(120, 100%, 40%);">+                tmp->reoriginate = conf->chan.reoriginate;</span><br><span>             tmp->sendcalleridafter = conf->chan.sendcalleridafter;</span><br><span>                 ast_cc_copy_config_params(tmp->cc_params, conf->chan.cc_params);</span><br><span> </span><br><span>@@ -18412,6 +18463,8 @@</span><br><span>                         confp->chan.ani_timeout = atoi(v->value);</span><br><span>              } else if (!strcasecmp(v->name, "hanguponpolarityswitch")) {</span><br><span>                    confp->chan.hanguponpolarityswitch = ast_true(v->value);</span><br><span style="color: hsl(120, 100%, 40%);">+                } else if (!strcasecmp(v->name, "autoreoriginate")) {</span><br><span style="color: hsl(120, 100%, 40%);">+                    confp->chan.reoriginate = ast_true(v->value);</span><br><span>          } else if (!strcasecmp(v->name, "sendcalleridafter")) {</span><br><span>                         confp->chan.sendcalleridafter = atoi(v->value);</span><br><span>                } else if (!strcasecmp(v->name, "mwimonitornotify")) {</span><br><span>diff --git a/channels/chan_dahdi.h b/channels/chan_dahdi.h</span><br><span>index de813f2..ad7a366 100644</span><br><span>--- a/channels/chan_dahdi.h</span><br><span>+++ b/channels/chan_dahdi.h</span><br><span>@@ -275,6 +275,14 @@</span><br><span>   * \note Set from the "hanguponpolarityswitch" value read in from chan_dahdi.conf</span><br><span>   */</span><br><span>  unsigned int hanguponpolarityswitch:1;</span><br><span style="color: hsl(120, 100%, 40%);">+        /*!</span><br><span style="color: hsl(120, 100%, 40%);">+    * \brief TRUE if FXS (FXO-signalled) channel should reoriginate for user to make a new call.</span><br><span style="color: hsl(120, 100%, 40%);">+  */</span><br><span style="color: hsl(120, 100%, 40%);">+   unsigned int reoriginate:1;</span><br><span style="color: hsl(120, 100%, 40%);">+   /*!</span><br><span style="color: hsl(120, 100%, 40%);">+    * \brief Internal flag for if we should actually process a reorigination.</span><br><span style="color: hsl(120, 100%, 40%);">+     */</span><br><span style="color: hsl(120, 100%, 40%);">+   unsigned int doreoriginate:1;</span><br><span>        /*! \brief TRUE if DTMF detection needs to be done by hardware. */</span><br><span>   unsigned int hardwaredtmf:1;</span><br><span>         /*!</span><br><span>diff --git a/configs/samples/chan_dahdi.conf.sample b/configs/samples/chan_dahdi.conf.sample</span><br><span>index 6b29549..073699b 100644</span><br><span>--- a/configs/samples/chan_dahdi.conf.sample</span><br><span>+++ b/configs/samples/chan_dahdi.conf.sample</span><br><span>@@ -1073,6 +1073,15 @@</span><br><span> ;                        polarity switch and hangup polarity switch.</span><br><span> ;                        (default: 600ms)</span><br><span> ;</span><br><span style="color: hsl(120, 100%, 40%);">+; For kewlstart FXS (FXO signalled) ports only:</span><br><span style="color: hsl(120, 100%, 40%);">+; When all calls towards a DAHDI channel have cleared, automatically</span><br><span style="color: hsl(120, 100%, 40%);">+; reoriginate and provide dial tone to the user again, so s/he can</span><br><span style="color: hsl(120, 100%, 40%);">+; make another call without having to cycle the hookswitch manually.</span><br><span style="color: hsl(120, 100%, 40%);">+; This only works for kewlstart (fxo_ks) lines!</span><br><span style="color: hsl(120, 100%, 40%);">+; Dial tone will be provided only after the loop disconnect has finished.</span><br><span style="color: hsl(120, 100%, 40%);">+;</span><br><span style="color: hsl(120, 100%, 40%);">+;autoreoriginate=yes</span><br><span style="color: hsl(120, 100%, 40%);">+;</span><br><span> ; On trunk interfaces (FXS) it can be useful to attempt to follow the progress</span><br><span> ; of a call through RINGING, BUSY, and ANSWERING.   If turned on, call</span><br><span> ; progress attempts to determine answer, busy, and ringing on phone lines.</span><br><span>diff --git a/doc/CHANGES-staging/chan_dahdi_autoreorig.txt b/doc/CHANGES-staging/chan_dahdi_autoreorig.txt</span><br><span>new file mode 100644</span><br><span>index 0000000..921c612</span><br><span>--- /dev/null</span><br><span>+++ b/doc/CHANGES-staging/chan_dahdi_autoreorig.txt</span><br><span>@@ -0,0 +1,7 @@</span><br><span style="color: hsl(120, 100%, 40%);">+Subject: chan_dahdi</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+The autoreoriginate setting now allows for kewlstart FXS</span><br><span style="color: hsl(120, 100%, 40%);">+channels to automatically reoriginate and provide dial tone</span><br><span style="color: hsl(120, 100%, 40%);">+to the user again after all calls on the line have cleared.</span><br><span style="color: hsl(120, 100%, 40%);">+This saves users from having to manually hang up and pick up</span><br><span style="color: hsl(120, 100%, 40%);">+the receiver again before making another call.</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/19714">change 19714</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/asterisk/+/19714"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: Ic6f182c821c4c8d0a14a8f0906264688d6cc7820 </div>
<div style="display:none"> Gerrit-Change-Number: 19714 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: N A <asterisk@phreaknet.org> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>