<p>Oron Peled would like Tzafrir Cohen to <strong>review</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/11612">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">openr2(4/6): added new cli command -- mfcr2 show links<br><br>* This command show the MFC/R2 links<br><br>Change-Id: I213822e1b7ef9c05bd89a2ba62df8e0856ce9f84<br>Signed-off-by: Oron Peled <oron.peled@xorcom.com><br>---<br>M channels/chan_dahdi.c<br>1 file changed, 101 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/12/11612/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 527bbc4..7bd250e 100644</span><br><span>--- a/channels/chan_dahdi.c</span><br><span>+++ b/channels/chan_dahdi.c</span><br><span>@@ -15000,10 +15000,111 @@</span><br><span> return CLI_SUCCESS;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+static void mfcr2_show_links_of(struct ast_cli_args *a, struct r2links *list_head, const char *title)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+#define FORMAT "%-5s %-10s %-15s %-10s %s\n"</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_LIST_LOCK(list_head);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (! AST_LIST_EMPTY(list_head)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ int x = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ char index[5];</span><br><span style="color: hsl(120, 100%, 40%);">+ char live_chans_str[5];</span><br><span style="color: hsl(120, 100%, 40%);">+ char channel_list[R2_LINK_CAPACITY * 4];</span><br><span style="color: hsl(120, 100%, 40%);">+ struct r2link_entry *cur;</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_cli(a->fd, "%s\n", title);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_cli(a->fd, FORMAT, "Index", "Thread", "Dahdi-Device", "Channels", "Channel-List");</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_LIST_TRAVERSE(list_head, cur, list) {</span><br><span style="color: hsl(120, 100%, 40%);">+ struct dahdi_mfcr2 *mfcr2 = &cur->mfcr2;</span><br><span style="color: hsl(120, 100%, 40%);">+ const char *thread_status = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ int i;</span><br><span style="color: hsl(120, 100%, 40%);">+ int len;</span><br><span style="color: hsl(120, 100%, 40%);">+ int inside_range;</span><br><span style="color: hsl(120, 100%, 40%);">+ int channo;</span><br><span style="color: hsl(120, 100%, 40%);">+ int prev_channo;</span><br><span style="color: hsl(120, 100%, 40%);">+ x++;</span><br><span style="color: hsl(120, 100%, 40%);">+ switch (mfcr2->r2master) {</span><br><span style="color: hsl(120, 100%, 40%);">+ case 0L: thread_status = "zero"; break;</span><br><span style="color: hsl(120, 100%, 40%);">+ case AST_PTHREADT_NULL: thread_status = "none"; break;</span><br><span style="color: hsl(120, 100%, 40%);">+ default: thread_status = "created"; break;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ snprintf(index, sizeof(index), "%d", mfcr2->index);</span><br><span style="color: hsl(120, 100%, 40%);">+ snprintf(live_chans_str, sizeof(live_chans_str), "%d", mfcr2->live_chans);</span><br><span style="color: hsl(120, 100%, 40%);">+ channo = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ prev_channo = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ inside_range = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ len = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Prepare nice string in channel_list[] */</span><br><span style="color: hsl(120, 100%, 40%);">+ for (i = 0; i < mfcr2->numchans; i++) {</span><br><span style="color: hsl(120, 100%, 40%);">+ struct dahdi_pvt *p = mfcr2->pvts[i];</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!p) {</span><br><span style="color: hsl(120, 100%, 40%);">+ continue;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ channo = p->channel;</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Don't show a range until we know the last channel number */</span><br><span style="color: hsl(120, 100%, 40%);">+ if (prev_channo && prev_channo == channo - 1) {</span><br><span style="color: hsl(120, 100%, 40%);">+ prev_channo = channo;</span><br><span style="color: hsl(120, 100%, 40%);">+ inside_range = 1;</span><br><span style="color: hsl(120, 100%, 40%);">+ continue;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ if (inside_range) {</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Close range */</span><br><span style="color: hsl(120, 100%, 40%);">+ len += snprintf(channel_list + len, sizeof(channel_list) - len - 1, "-%d,%d", prev_channo, channo);</span><br><span style="color: hsl(120, 100%, 40%);">+ inside_range = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ } else if (prev_channo) {</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Non-sequential channel numbers */</span><br><span style="color: hsl(120, 100%, 40%);">+ len += snprintf(channel_list + len, sizeof(channel_list) - len - 1, ",%d", channo);</span><br><span style="color: hsl(120, 100%, 40%);">+ } else {</span><br><span style="color: hsl(120, 100%, 40%);">+ /* First channel number */</span><br><span style="color: hsl(120, 100%, 40%);">+ len += snprintf(channel_list + len, sizeof(channel_list) - len - 1, "%d", channo);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ prev_channo = channo;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Handle leftover channels */</span><br><span style="color: hsl(120, 100%, 40%);">+ if (inside_range) {</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Close range */</span><br><span style="color: hsl(120, 100%, 40%);">+ len += snprintf(channel_list + len, sizeof(channel_list) - len - 1, "-%d", channo);</span><br><span style="color: hsl(120, 100%, 40%);">+ inside_range = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ } else if (prev_channo) {</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Non-sequential channel numbers */</span><br><span style="color: hsl(120, 100%, 40%);">+ len += snprintf(channel_list + len, sizeof(channel_list) - len - 1, ",%d", channo);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ // channel_list[len] = '\0';</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_cli(a->fd, FORMAT,</span><br><span style="color: hsl(120, 100%, 40%);">+ index,</span><br><span style="color: hsl(120, 100%, 40%);">+ thread_status,</span><br><span style="color: hsl(120, 100%, 40%);">+ (mfcr2->nodev) ? "MISSING" : "OK",</span><br><span style="color: hsl(120, 100%, 40%);">+ live_chans_str,</span><br><span style="color: hsl(120, 100%, 40%);">+ channel_list);</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%);">+ AST_LIST_UNLOCK(list_head);</span><br><span style="color: hsl(120, 100%, 40%);">+#undef FORMAT</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%);">+static char *handle_mfcr2_show_links(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ switch (cmd) {</span><br><span style="color: hsl(120, 100%, 40%);">+ case CLI_INIT:</span><br><span style="color: hsl(120, 100%, 40%);">+ e->command = "mfcr2 show links";</span><br><span style="color: hsl(120, 100%, 40%);">+ e->usage =</span><br><span style="color: hsl(120, 100%, 40%);">+ "Usage: mfcr2 show links\n"</span><br><span style="color: hsl(120, 100%, 40%);">+ " Shows the DAHDI MFC/R2 links.\n";</span><br><span style="color: hsl(120, 100%, 40%);">+ return NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ case CLI_GENERATE:</span><br><span style="color: hsl(120, 100%, 40%);">+ return NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ if (a->argc != 3) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return CLI_SHOWUSAGE;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ mfcr2_show_links_of(a, &r2links, "Live links\n");</span><br><span style="color: hsl(120, 100%, 40%);">+ mfcr2_show_links_of(a, &nodev_r2links, "Links to be removed (device missing)\n");</span><br><span style="color: hsl(120, 100%, 40%);">+ return CLI_SUCCESS;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> static struct ast_cli_entry dahdi_mfcr2_cli[] = {</span><br><span> AST_CLI_DEFINE(handle_mfcr2_version, "Show OpenR2 library version"),</span><br><span> AST_CLI_DEFINE(handle_mfcr2_show_variants, "Show supported MFC/R2 variants"),</span><br><span> AST_CLI_DEFINE(handle_mfcr2_show_channels, "Show MFC/R2 channels"),</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_CLI_DEFINE(handle_mfcr2_show_links, "Show MFC/R2 links"),</span><br><span> AST_CLI_DEFINE(handle_mfcr2_set_debug, "Set MFC/R2 channel logging level"),</span><br><span> AST_CLI_DEFINE(handle_mfcr2_call_files, "Enable/Disable MFC/R2 call files"),</span><br><span> AST_CLI_DEFINE(handle_mfcr2_set_idle, "Reset MFC/R2 channel forcing it to IDLE"),</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/11612">change 11612</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/+/11612"/><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: I213822e1b7ef9c05bd89a2ba62df8e0856ce9f84 </div>
<div style="display:none"> Gerrit-Change-Number: 11612 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Oron Peled <oron.peled@xorcom.com> </div>
<div style="display:none"> Gerrit-Reviewer: Tzafrir Cohen <tzafrir.cohen@xorcom.com> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>