|
177 | 177 | <para>This application will Accept the R2 call either with charge or no charge.</para>
|
178 | 178 | </description>
|
179 | 179 | </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> |
180 | 209 | <info name="CHANNEL" language="en_US" tech="DAHDI">
|
181 | 210 | <enumlist>
|
182 | 211 | <enum name="dahdi_channel">
|
@@ -2694,6 +2723,86 @@ static void my_hangup_polarityswitch(void *pvt)
|
2694 | 2723 | }
|
2695 | 2724 | }
|
2696 | 2725 |
|
| 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 | + |
2697 | 2806 | static int my_start(void *pvt)
|
2698 | 2807 | {
|
2699 | 2808 | struct dahdi_pvt *p = pvt;
|
@@ -17605,6 +17714,8 @@ static int __unload_module(void)
|
17605 | 17714 | ast_unregister_application(dahdi_accept_r2_call_app);
|
17606 | 17715 | #endif
|
17607 | 17716 |
|
| 17717 | + ast_custom_function_unregister(&polarity_function); |
| 17718 | + |
17608 | 17719 | ast_cli_unregister_multiple(dahdi_cli, ARRAY_LEN(dahdi_cli));
|
17609 | 17720 | ast_manager_unregister("DAHDIDialOffhook");
|
17610 | 17721 | ast_manager_unregister("DAHDIHangup");
|
@@ -19793,6 +19904,8 @@ static int load_module(void)
|
19793 | 19904 | ast_register_application_xml(dahdi_accept_r2_call_app, dahdi_accept_r2_call_exec);
|
19794 | 19905 | #endif
|
19795 | 19906 |
|
| 19907 | + ast_custom_function_register(&polarity_function); |
| 19908 | + |
19796 | 19909 | ast_cli_register_multiple(dahdi_cli, ARRAY_LEN(dahdi_cli));
|
19797 | 19910 | memset(round_robin, 0, sizeof(round_robin));
|
19798 | 19911 | ast_manager_register_xml("DAHDITransfer", 0, action_transfer);
|
|
0 commit comments