Skip to content

Commit 8a21417

Browse files
InterLinked1gtjoseph
authored andcommitted
chan_dahdi: Add POLARITY function.
Adds a POLARITY function which can be used to retrieve the current polarity of an FXS channel as well as set the polarity of an FXS channel to idle or reverse at any point during a call. ASTERISK-30000 #close Change-Id: If6f50998f723e4484bf68e2473f5cedfeaf9b8f1
1 parent 7cc026b commit 8a21417

File tree

2 files changed

+118
-0
lines changed

2 files changed

+118
-0
lines changed

Diff for: channels/chan_dahdi.c

+113
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,35 @@
177177
<para>This application will Accept the R2 call either with charge or no charge.</para>
178178
</description>
179179
</application>
180+
<function name="POLARITY" language="en_US">
181+
<synopsis>
182+
Set or get the polarity of a DAHDI channel.
183+
</synopsis>
184+
<syntax />
185+
<description>
186+
<para>The POLARITY function can be used to set the polarity of a DAHDI channel.</para>
187+
<para>Applies only to FXS channels (using FXO signalling) with supporting hardware.</para>
188+
<para>The polarity can be set to the following numeric or named values:</para>
189+
<enumlist>
190+
<enum name="0" />
191+
<enum name="idle" />
192+
<enum name="1" />
193+
<enum name="reverse" />
194+
</enumlist>
195+
<para>However, when read, the function will always return 0 or 1.</para>
196+
<example title="Set idle polarity">
197+
same => n,Set(POLARITY()=0)
198+
</example>
199+
<example title="Set reverse polarity">
200+
same => n,NoOp(Current Polarity: ${POLARITY()})
201+
same => n,Set(POLARITY()=reverse)
202+
same => n,NoOp(New Polarity: ${POLARITY()})
203+
</example>
204+
<example title="Reverse the polarity from whatever it is currently">
205+
same => n,Set(POLARITY()=${IF($[ "${POLARITY()}" = "1" ]?0:1)})
206+
</example>
207+
</description>
208+
</function>
180209
<info name="CHANNEL" language="en_US" tech="DAHDI">
181210
<enumlist>
182211
<enum name="dahdi_channel">
@@ -2694,6 +2723,86 @@ static void my_hangup_polarityswitch(void *pvt)
26942723
}
26952724
}
26962725

2726+
/*! \brief Return DAHDI pivot if channel is FXO signalled */
2727+
static struct dahdi_pvt *fxo_pvt(struct ast_channel *chan)
2728+
{
2729+
int res;
2730+
struct dahdi_params dahdip;
2731+
struct dahdi_pvt *pvt = NULL;
2732+
2733+
if (strcasecmp(ast_channel_tech(chan)->type, "DAHDI")) {
2734+
ast_log(LOG_WARNING, "%s is not a DAHDI channel\n", ast_channel_name(chan));
2735+
return NULL;
2736+
}
2737+
2738+
memset(&dahdip, 0, sizeof(dahdip));
2739+
res = ioctl(ast_channel_fd(chan, 0), DAHDI_GET_PARAMS, &dahdip);
2740+
2741+
if (res) {
2742+
ast_log(LOG_WARNING, "Unable to get parameters of %s: %s\n", ast_channel_name(chan), strerror(errno));
2743+
return NULL;
2744+
}
2745+
if (!(dahdip.sigtype & __DAHDI_SIG_FXO)) {
2746+
ast_log(LOG_WARNING, "%s is not FXO signalled\n", ast_channel_name(chan));
2747+
return NULL;
2748+
}
2749+
2750+
pvt = ast_channel_tech_pvt(chan);
2751+
if (!dahdi_analog_lib_handles(pvt->sig, 0, 0)) {
2752+
ast_log(LOG_WARNING, "Channel signalling is not analog");
2753+
return NULL;
2754+
}
2755+
2756+
return pvt;
2757+
}
2758+
2759+
static int polarity_read(struct ast_channel *chan, const char *cmd, char *data, char *buffer, size_t buflen)
2760+
{
2761+
struct dahdi_pvt *pvt;
2762+
2763+
pvt = fxo_pvt(chan);
2764+
if (!pvt) {
2765+
return -1;
2766+
}
2767+
2768+
snprintf(buffer, buflen, "%d", pvt->polarity);
2769+
2770+
return 0;
2771+
}
2772+
2773+
static int polarity_write(struct ast_channel *chan, const char *cmd, char *data, const char *value)
2774+
{
2775+
struct dahdi_pvt *pvt;
2776+
int polarity;
2777+
2778+
pvt = fxo_pvt(chan);
2779+
if (!pvt) {
2780+
return -1;
2781+
}
2782+
2783+
if (!strcasecmp(value, "idle")) {
2784+
polarity = POLARITY_IDLE;
2785+
} else if (!strcasecmp(value, "reverse")) {
2786+
polarity = POLARITY_REV;
2787+
} else {
2788+
polarity = atoi(value);
2789+
}
2790+
2791+
if (polarity != POLARITY_IDLE && polarity != POLARITY_REV) {
2792+
ast_log(LOG_WARNING, "Invalid polarity: '%s'\n", value);
2793+
return -1;
2794+
}
2795+
2796+
my_set_polarity(pvt, polarity);
2797+
return 0;
2798+
}
2799+
2800+
static struct ast_custom_function polarity_function = {
2801+
.name = "POLARITY",
2802+
.write = polarity_write,
2803+
.read = polarity_read,
2804+
};
2805+
26972806
static int my_start(void *pvt)
26982807
{
26992808
struct dahdi_pvt *p = pvt;
@@ -17605,6 +17714,8 @@ static int __unload_module(void)
1760517714
ast_unregister_application(dahdi_accept_r2_call_app);
1760617715
#endif
1760717716

17717+
ast_custom_function_unregister(&polarity_function);
17718+
1760817719
ast_cli_unregister_multiple(dahdi_cli, ARRAY_LEN(dahdi_cli));
1760917720
ast_manager_unregister("DAHDIDialOffhook");
1761017721
ast_manager_unregister("DAHDIHangup");
@@ -19793,6 +19904,8 @@ static int load_module(void)
1979319904
ast_register_application_xml(dahdi_accept_r2_call_app, dahdi_accept_r2_call_exec);
1979419905
#endif
1979519906

19907+
ast_custom_function_register(&polarity_function);
19908+
1979619909
ast_cli_register_multiple(dahdi_cli, ARRAY_LEN(dahdi_cli));
1979719910
memset(round_robin, 0, sizeof(round_robin));
1979819911
ast_manager_register_xml("DAHDITransfer", 0, action_transfer);

Diff for: doc/CHANGES-staging/chan_dahdi_polarity.txt

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Subject: chan_dahdi
2+
3+
A POLARITY function is now available that allows
4+
getting or setting the polarity on a channel
5+
from the dialplan.

0 commit comments

Comments
 (0)