2 * Asterisk -- An open source telephony toolkit.
4 * UDPTL support for T.38
6 * Copyright (C) 2005, Steve Underwood, partly based on RTP code which is
7 * Copyright (C) 1999-2009, Digium, Inc.
9 * Steve Underwood <steveu@coppice.org>
10 * Kevin P. Fleming <kpfleming@digium.com>
12 * See http://www.asterisk.org for more information about
13 * the Asterisk project. Please do not directly contact
14 * any of the maintainers of this project for assistance;
15 * the project provides a web site, mailing lists and IRC
16 * channels for your use.
18 * This program is free software, distributed under the terms of
19 * the GNU General Public License Version 2. See the LICENSE file
20 * at the top of the source tree.
22 * A license has been granted to Digium (via disclaimer) for the use of
29 * \brief UDPTL support for T.38 faxing
32 * \author Mark Spencer <markster@digium.com>
33 * \author Steve Underwood <steveu@coppice.org>
34 * \author Kevin P. Fleming <kpfleming@digium.com>
36 * \page T38fax_udptl T.38 support :: UDPTL
38 * Asterisk supports T.38 fax passthrough, origination and termination. It does
39 * not support gateway operation. The only channel driver that supports T.38 at
40 * this time is chan_sip.
42 * UDPTL is handled very much like RTP. It can be reinvited to go directly between
43 * the endpoints, without involving Asterisk in the media stream.
51 /*! \li \ref udptl.c uses the configuration file \ref udptl.conf
52 * \addtogroup configuration_file Configuration Files
56 * \page udptl.conf udptl.conf
57 * \verbinclude udptl.conf.sample
61 <support_level>core</support_level>
66 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
72 #include "asterisk/udptl.h"
73 #include "asterisk/frame.h"
74 #include "asterisk/channel.h"
75 #include "asterisk/acl.h"
76 #include "asterisk/config_options.h"
77 #include "asterisk/lock.h"
78 #include "asterisk/utils.h"
79 #include "asterisk/netsock2.h"
80 #include "asterisk/cli.h"
81 #include "asterisk/unaligned.h"
84 <configInfo name="udptl" language="en_US">
85 <configFile name="udptl.conf">
86 <configObject name="global">
87 <synopsis>Global options for configuring UDPTL</synopsis>
88 <configOption name="udptlstart">
89 <synopsis>The start of the UDPTL port range</synopsis>
91 <configOption name="udptlend">
92 <synopsis>The end of the UDPTL port range</synopsis>
94 <configOption name="udptlchecksums">
95 <synopsis>Whether to enable or disable UDP checksums on UDPTL traffic</synopsis>
97 <configOption name="udptlfecentries">
98 <synopsis>The number of error correction entries in a UDPTL packet</synopsis>
100 <configOption name="udptlfecspan">
101 <synopsis>The span over which parity is calculated for FEC in a UDPTL packet</synopsis>
103 <configOption name="use_even_ports">
104 <synopsis>Whether to only use even-numbered UDPTL ports</synopsis>
106 <configOption name="t38faxudpec">
107 <synopsis>Removed</synopsis>
109 <configOption name="t38faxmaxdatagram">
110 <synopsis>Removed</synopsis>
117 #define UDPTL_MTU 1200
123 #define TRUE (!FALSE)
126 #define LOG_TAG(u) S_OR(u->tag, "no tag")
128 #define DEFAULT_UDPTLSTART 4000
129 #define DEFAULT_UDPTLEND 4999
131 static int udptldebug; /*!< Are we debugging? */
132 static struct ast_sockaddr udptldebugaddr; /*!< Debug packets to/from this host */
134 #define LOCAL_FAX_MAX_DATAGRAM 1400
135 #define DEFAULT_FAX_MAX_DATAGRAM 400
136 #define FAX_MAX_DATAGRAM_LIMIT 1400
137 #define MAX_FEC_ENTRIES 5
138 #define MAX_FEC_SPAN 5
140 #define UDPTL_BUF_MASK 15
144 uint8_t buf[LOCAL_FAX_MAX_DATAGRAM];
145 } udptl_fec_tx_buffer_t;
149 uint8_t buf[LOCAL_FAX_MAX_DATAGRAM];
150 unsigned int fec_len[MAX_FEC_ENTRIES];
151 uint8_t fec[MAX_FEC_ENTRIES][LOCAL_FAX_MAX_DATAGRAM];
152 unsigned int fec_span;
153 unsigned int fec_entries;
154 } udptl_fec_rx_buffer_t;
156 /*! \brief Structure for an UDPTL session */
160 struct ast_frame f[16];
161 unsigned char rawdata[8192 + AST_FRIENDLY_OFFSET];
162 unsigned int lasteventseqn;
165 struct ast_sockaddr us;
166 struct ast_sockaddr them;
168 struct ast_sched_context *sched;
169 struct io_context *io;
172 ast_udptl_callback callback;
174 /*! This option indicates the error correction scheme used in transmitted UDPTL
175 * packets and expected in received UDPTL packets.
177 enum ast_t38_ec_modes error_correction_scheme;
179 /*! This option indicates the number of error correction entries transmitted in
180 * UDPTL packets and expected in received UDPTL packets.
182 unsigned int error_correction_entries;
184 /*! This option indicates the span of the error correction entries in transmitted
185 * UDPTL packets (FEC only).
187 unsigned int error_correction_span;
189 /*! The maximum size UDPTL packet that can be accepted by
192 int far_max_datagram;
194 /*! The maximum size UDPTL packet that we are prepared to
195 * accept, or -1 if it hasn't been calculated since the last
196 * changes were applied to the UDPTL structure.
198 int local_max_datagram;
200 /*! The maximum IFP that can be submitted for sending
201 * to the remote device. Calculated from far_max_datagram,
202 * error_correction_scheme and error_correction_entries,
203 * or -1 if it hasn't been calculated since the last
204 * changes were applied to the UDPTL structure.
208 /*! The maximum IFP that the local endpoint is prepared
209 * to accept. Along with error_correction_scheme and
210 * error_correction_entries, used to calculate local_max_datagram.
214 unsigned int tx_seq_no;
215 unsigned int rx_seq_no;
217 udptl_fec_tx_buffer_t tx[UDPTL_BUF_MASK + 1];
218 udptl_fec_rx_buffer_t rx[UDPTL_BUF_MASK + 1];
221 static AST_RWLIST_HEAD_STATIC(protos, ast_udptl_protocol);
223 struct udptl_global_options {
224 unsigned int start; /*< The UDPTL start port */
225 unsigned int end; /*< The UDPTL end port */
226 unsigned int fecentries;
227 unsigned int fecspan;
228 unsigned int nochecksums;
229 unsigned int use_even_ports;
232 static AO2_GLOBAL_OBJ_STATIC(globals);
234 struct udptl_config {
235 struct udptl_global_options *general;
238 static void *udptl_snapshot_alloc(void);
239 static int udptl_pre_apply_config(void);
241 static struct aco_type general_option = {
244 .category_match = ACO_WHITELIST,
245 .item_offset = offsetof(struct udptl_config, general),
246 .category = "^general$",
249 static struct aco_type *general_options[] = ACO_TYPES(&general_option);
251 static struct aco_file udptl_conf = {
252 .filename = "udptl.conf",
253 .types = ACO_TYPES(&general_option),
256 CONFIG_INFO_CORE("udptl", cfg_info, globals, udptl_snapshot_alloc,
257 .files = ACO_FILES(&udptl_conf),
258 .pre_apply_config = udptl_pre_apply_config,
261 static inline int udptl_debug_test_addr(const struct ast_sockaddr *addr)
266 if (ast_sockaddr_isnull(&udptldebugaddr)) {
270 if (ast_sockaddr_port(&udptldebugaddr)) {
271 return !ast_sockaddr_cmp(&udptldebugaddr, addr);
273 return !ast_sockaddr_cmp_addr(&udptldebugaddr, addr);
277 static int decode_length(uint8_t *buf, unsigned int limit, unsigned int *len, unsigned int *pvalue)
281 if ((buf[*len] & 0x80) == 0) {
286 if ((buf[*len] & 0x40) == 0) {
287 if (*len == limit - 1)
289 *pvalue = (buf[*len] & 0x3F) << 8;
291 *pvalue |= buf[*len];
295 *pvalue = (buf[*len] & 0x3F) << 14;
297 /* We have a fragment. Currently we don't process fragments. */
298 ast_debug(1, "UDPTL packet with length greater than 16K received, decoding will fail\n");
301 /*- End of function --------------------------------------------------------*/
303 static int decode_open_type(uint8_t *buf, unsigned int limit, unsigned int *len, const uint8_t **p_object, unsigned int *p_num_octets)
305 unsigned int octet_cnt = 0;
307 if (decode_length(buf, limit, len, &octet_cnt) != 0)
311 /* Make sure the buffer contains at least the number of bits requested */
312 if ((*len + octet_cnt) > limit)
315 *p_num_octets = octet_cnt;
316 *p_object = &buf[*len];
322 /*- End of function --------------------------------------------------------*/
324 static unsigned int encode_length(uint8_t *buf, unsigned int *len, unsigned int value)
326 unsigned int multiplier;
334 if (value < 0x4000) {
336 /* Set the first bit of the first octet */
337 buf[*len] = ((0x8000 | value) >> 8) & 0xFF;
339 buf[*len] = value & 0xFF;
344 multiplier = (value < 0x10000) ? (value >> 14) : 4;
345 /* Set the first 2 bits of the octet */
346 buf[*len] = 0xC0 | multiplier;
348 return multiplier << 14;
350 /*- End of function --------------------------------------------------------*/
352 static int encode_open_type(const struct ast_udptl *udptl, uint8_t *buf, unsigned int buflen,
353 unsigned int *len, const uint8_t *data, unsigned int num_octets)
356 unsigned int octet_idx;
359 /* If open type is of zero length, add a single zero byte (10.1) */
360 if (num_octets == 0) {
365 /* Encode the open type */
366 for (octet_idx = 0; ; num_octets -= enclen, octet_idx += enclen) {
367 if ((enclen = encode_length(buf, len, num_octets)) < 0)
369 if (enclen + *len > buflen) {
370 ast_log(LOG_ERROR, "UDPTL (%s): Buffer overflow detected (%d + %d > %d)\n",
371 LOG_TAG(udptl), enclen, *len, buflen);
375 memcpy(&buf[*len], &data[octet_idx], enclen);
378 if (enclen >= num_octets)
384 /*- End of function --------------------------------------------------------*/
386 static int udptl_rx_packet(struct ast_udptl *s, uint8_t *buf, unsigned int len)
391 unsigned int ptr; /* an index that keeps track of how much of the UDPTL packet has been processed */
393 const uint8_t *ifp = NULL;
394 const uint8_t *data = NULL;
395 unsigned int ifp_len = 0;
397 const uint8_t *bufs[ARRAY_LEN(s->f) - 1];
398 unsigned int lengths[ARRAY_LEN(s->f) - 1];
405 memset(&s->f[0], 0, sizeof(s->f[0]));
407 /* Decode seq_number */
410 seq_no = (buf[0] << 8) | buf[1];
413 /* Break out the primary packet */
414 if ((stat1 = decode_open_type(buf, len, &ptr, &ifp, &ifp_len)) != 0)
416 /* Decode error_recovery */
419 if ((buf[ptr++] & 0x80) == 0) {
420 /* Secondary packet mode for error recovery */
421 if (seq_no > s->rx_seq_no) {
422 /* We received a later packet than we expected, so we need to check if we can fill in the gap from the
423 secondary packets. */
427 if ((stat2 = decode_length(buf, len, &ptr, &count)) < 0)
429 for (i = 0; i < count && total_count + i < ARRAY_LEN(bufs); i++) {
430 if ((stat1 = decode_open_type(buf, len, &ptr, &bufs[total_count + i], &lengths[total_count + i])) != 0) {
433 /* valid secondaries can contain zero-length packets that should be ignored */
434 if (!bufs[total_count + i] || !lengths[total_count + i]) {
435 /* drop the count of items to process and reuse the buffers that were just set */
442 while (stat2 > 0 && total_count < ARRAY_LEN(bufs));
443 /* Step through in reverse order, so we go oldest to newest */
444 for (i = total_count; i > 0; i--) {
445 if (seq_no - i >= s->rx_seq_no) {
446 /* This one wasn't seen before */
447 /* Decode the secondary IFP packet */
448 ast_debug(3, "Recovering lost packet via secondary %d, len %d\n", seq_no - i, lengths[i - 1]);
449 s->f[ifp_no].frametype = AST_FRAME_MODEM;
450 s->f[ifp_no].subclass.integer = AST_MODEM_T38;
452 s->f[ifp_no].mallocd = 0;
453 s->f[ifp_no].seqno = seq_no - i;
454 s->f[ifp_no].datalen = lengths[i - 1];
455 s->f[ifp_no].data.ptr = (uint8_t *) bufs[i - 1];
456 s->f[ifp_no].offset = 0;
457 s->f[ifp_no].src = "UDPTL";
459 AST_LIST_NEXT(&s->f[ifp_no - 1], frame_list) = &s->f[ifp_no];
460 AST_LIST_NEXT(&s->f[ifp_no], frame_list) = NULL;
471 /* FEC mode for error recovery */
472 /* Our buffers cannot tolerate overlength IFP packets in FEC mode */
473 if (ifp_len > LOCAL_FAX_MAX_DATAGRAM)
475 /* Update any missed slots in the buffer */
476 for ( ; seq_no > s->rx_seq_no; s->rx_seq_no++) {
477 x = s->rx_seq_no & UDPTL_BUF_MASK;
478 s->rx[x].buf_len = -1;
479 s->rx[x].fec_len[0] = 0;
480 s->rx[x].fec_span = 0;
481 s->rx[x].fec_entries = 0;
484 x = seq_no & UDPTL_BUF_MASK;
486 memset(repaired, 0, sizeof(repaired));
488 /* Save the new IFP packet */
489 memcpy(s->rx[x].buf, ifp, ifp_len);
490 s->rx[x].buf_len = ifp_len;
493 /* Decode the FEC packets */
494 /* The span is defined as an unconstrained integer, but will never be more
495 than a small value. */
501 s->rx[x].fec_span = span;
503 /* The number of entries is defined as a length, but will only ever be a small
504 value. Treat it as such. */
507 entries = buf[ptr++];
508 if (entries > MAX_FEC_ENTRIES) {
511 s->rx[x].fec_entries = entries;
513 /* Decode the elements */
514 for (i = 0; i < entries; i++) {
515 if ((stat1 = decode_open_type(buf, len, &ptr, &data, &s->rx[x].fec_len[i])) != 0)
517 if (s->rx[x].fec_len[i] > LOCAL_FAX_MAX_DATAGRAM)
520 /* Save the new FEC data */
521 memcpy(s->rx[x].fec[i], data, s->rx[x].fec_len[i]);
523 fprintf(stderr, "FEC: ");
524 for (j = 0; j < s->rx[x].fec_len[i]; j++)
525 fprintf(stderr, "%02X ", data[j]);
526 fprintf(stderr, "\n");
530 /* See if we can reconstruct anything which is missing */
531 /* TODO: this does not comprehensively hunt back and repair everything that is possible */
532 for (l = x; l != ((x - (16 - span*entries)) & UDPTL_BUF_MASK); l = (l - 1) & UDPTL_BUF_MASK) {
534 if (s->rx[l].fec_len[0] <= 0)
536 for (m = 0; m < s->rx[l].fec_entries; m++) {
539 int limit = (l + m) & UDPTL_BUF_MASK;
540 for (which = -1, k = (limit - s->rx[l].fec_span * s->rx[l].fec_entries) & UDPTL_BUF_MASK; k != limit; k = (k + s->rx[l].fec_entries) & UDPTL_BUF_MASK) {
541 if (s->rx[k].buf_len <= 0)
542 which = (which == -1) ? k : -2;
546 for (j = 0; j < s->rx[l].fec_len[m]; j++) {
547 s->rx[which].buf[j] = s->rx[l].fec[m][j];
548 for (k = (limit - s->rx[l].fec_span * s->rx[l].fec_entries) & UDPTL_BUF_MASK; k != limit; k = (k + s->rx[l].fec_entries) & UDPTL_BUF_MASK)
549 s->rx[which].buf[j] ^= (s->rx[k].buf_len > j) ? s->rx[k].buf[j] : 0;
551 s->rx[which].buf_len = s->rx[l].fec_len[m];
552 repaired[which] = TRUE;
556 /* Now play any new packets forwards in time */
557 for (l = (x + 1) & UDPTL_BUF_MASK, j = seq_no - UDPTL_BUF_MASK; l != x; l = (l + 1) & UDPTL_BUF_MASK, j++) {
559 //fprintf(stderr, "Fixed packet %d, len %d\n", j, l);
560 s->f[ifp_no].frametype = AST_FRAME_MODEM;
561 s->f[ifp_no].subclass.integer = AST_MODEM_T38;
563 s->f[ifp_no].mallocd = 0;
564 s->f[ifp_no].seqno = j;
565 s->f[ifp_no].datalen = s->rx[l].buf_len;
566 s->f[ifp_no].data.ptr = s->rx[l].buf;
567 s->f[ifp_no].offset = 0;
568 s->f[ifp_no].src = "UDPTL";
570 AST_LIST_NEXT(&s->f[ifp_no - 1], frame_list) = &s->f[ifp_no];
571 AST_LIST_NEXT(&s->f[ifp_no], frame_list) = NULL;
577 /* If packets are received out of sequence, we may have already processed this packet from the error
578 recovery information in a packet already received. */
579 if (seq_no >= s->rx_seq_no) {
580 /* Decode the primary IFP packet */
581 s->f[ifp_no].frametype = AST_FRAME_MODEM;
582 s->f[ifp_no].subclass.integer = AST_MODEM_T38;
584 s->f[ifp_no].mallocd = 0;
585 s->f[ifp_no].seqno = seq_no;
586 s->f[ifp_no].datalen = ifp_len;
587 s->f[ifp_no].data.ptr = (uint8_t *) ifp;
588 s->f[ifp_no].offset = 0;
589 s->f[ifp_no].src = "UDPTL";
591 AST_LIST_NEXT(&s->f[ifp_no - 1], frame_list) = &s->f[ifp_no];
592 AST_LIST_NEXT(&s->f[ifp_no], frame_list) = NULL;
597 s->rx_seq_no = seq_no + 1;
600 /*- End of function --------------------------------------------------------*/
602 static int udptl_build_packet(struct ast_udptl *s, uint8_t *buf, unsigned int buflen, uint8_t *ifp, unsigned int ifp_len)
604 uint8_t fec[LOCAL_FAX_MAX_DATAGRAM * 2] = { 0, };
616 seq = s->tx_seq_no & 0xFFFF;
618 /* Map the sequence number to an entry in the circular buffer */
619 entry = seq & UDPTL_BUF_MASK;
621 /* We save the message in a circular buffer, for generating FEC or
622 redundancy sets later on. */
623 s->tx[entry].buf_len = ifp_len;
624 memcpy(s->tx[entry].buf, ifp, ifp_len);
626 /* Build the UDPTLPacket */
629 /* Encode the sequence number */
630 buf[len++] = (seq >> 8) & 0xFF;
631 buf[len++] = seq & 0xFF;
633 /* Encode the primary IFP packet */
634 if (encode_open_type(s, buf, buflen, &len, ifp, ifp_len) < 0)
637 /* Encode the appropriate type of error recovery information */
638 switch (s->error_correction_scheme)
640 case UDPTL_ERROR_CORRECTION_NONE:
641 /* Encode the error recovery type */
643 /* The number of entries will always be zero, so it is pointless allowing
644 for the fragmented case here. */
645 if (encode_length(buf, &len, 0) < 0)
648 case UDPTL_ERROR_CORRECTION_REDUNDANCY:
649 /* Encode the error recovery type */
651 if (s->tx_seq_no > s->error_correction_entries)
652 entries = s->error_correction_entries;
654 entries = s->tx_seq_no;
655 /* The number of entries will always be small, so it is pointless allowing
656 for the fragmented case here. */
657 if (encode_length(buf, &len, entries) < 0)
659 /* Encode the elements */
660 for (i = 0; i < entries; i++) {
661 j = (entry - i - 1) & UDPTL_BUF_MASK;
662 if (encode_open_type(s, buf, buflen, &len, s->tx[j].buf, s->tx[j].buf_len) < 0) {
663 ast_debug(1, "UDPTL (%s): Encoding failed at i=%d, j=%d\n",
669 case UDPTL_ERROR_CORRECTION_FEC:
670 span = s->error_correction_span;
671 entries = s->error_correction_entries;
672 if (seq < s->error_correction_span*s->error_correction_entries) {
673 /* In the initial stages, wind up the FEC smoothly */
674 entries = seq/s->error_correction_span;
675 if (seq < s->error_correction_span)
678 /* Encode the error recovery type */
680 /* Span is defined as an inconstrained integer, which it dumb. It will only
681 ever be a small value. Treat it as such. */
684 /* The number of entries is defined as a length, but will only ever be a small
685 value. Treat it as such. */
686 buf[len++] = entries;
687 for (m = 0; m < entries; m++) {
688 /* Make an XOR'ed entry the maximum length */
689 limit = (entry + m) & UDPTL_BUF_MASK;
691 for (i = (limit - span*entries) & UDPTL_BUF_MASK; i != limit; i = (i + entries) & UDPTL_BUF_MASK) {
692 if (high_tide < s->tx[i].buf_len) {
693 for (j = 0; j < high_tide; j++)
694 fec[j] ^= s->tx[i].buf[j];
695 for ( ; j < s->tx[i].buf_len; j++)
696 fec[j] = s->tx[i].buf[j];
697 high_tide = s->tx[i].buf_len;
699 for (j = 0; j < s->tx[i].buf_len; j++)
700 fec[j] ^= s->tx[i].buf[j];
703 if (encode_open_type(s, buf, buflen, &len, fec, high_tide) < 0)
713 int ast_udptl_fd(const struct ast_udptl *udptl)
718 void ast_udptl_set_data(struct ast_udptl *udptl, void *data)
723 void ast_udptl_set_callback(struct ast_udptl *udptl, ast_udptl_callback callback)
725 udptl->callback = callback;
728 void ast_udptl_setnat(struct ast_udptl *udptl, int nat)
733 static int udptlread(int *id, int fd, short events, void *cbdata)
735 struct ast_udptl *udptl = cbdata;
738 if ((f = ast_udptl_read(udptl))) {
740 udptl->callback(udptl, f, udptl->data);
745 struct ast_frame *ast_udptl_read(struct ast_udptl *udptl)
748 struct ast_sockaddr addr;
751 buf = udptl->rawdata + AST_FRIENDLY_OFFSET;
753 /* Cache where the header will go */
754 res = ast_recvfrom(udptl->fd,
756 sizeof(udptl->rawdata) - AST_FRIENDLY_OFFSET,
761 ast_log(LOG_WARNING, "UDPTL (%s): read error: %s\n",
762 LOG_TAG(udptl), strerror(errno));
763 ast_assert(errno != EBADF);
764 return &ast_null_frame;
767 /* Ignore if the other side hasn't been given an address yet. */
768 if (ast_sockaddr_isnull(&udptl->them)) {
769 return &ast_null_frame;
773 /* Send to whoever sent to us */
774 if (ast_sockaddr_cmp(&udptl->them, &addr)) {
775 ast_sockaddr_copy(&udptl->them, &addr);
776 ast_debug(1, "UDPTL (%s): NAT, Using address %s\n",
777 LOG_TAG(udptl), ast_sockaddr_stringify(&udptl->them));
781 if (udptl_debug_test_addr(&addr)) {
784 /* Decode sequence number just for verbose message. */
789 seq_no = (buf[0] << 8) | buf[1];
792 ast_verb(1, "UDPTL (%s): packet from %s (seq %d, len %d)\n",
793 LOG_TAG(udptl), ast_sockaddr_stringify(&addr), seq_no, res);
795 if (udptl_rx_packet(udptl, buf, res) < 1) {
796 return &ast_null_frame;
802 static void calculate_local_max_datagram(struct ast_udptl *udptl)
804 unsigned int new_max = 0;
806 if (udptl->local_max_ifp == -1) {
807 ast_log(LOG_WARNING, "UDPTL (%s): Cannot calculate local_max_datagram before local_max_ifp has been set.\n",
809 udptl->local_max_datagram = -1;
813 /* calculate the amount of space required to receive an IFP
814 * of the maximum size supported by the application/endpoint
815 * that we are delivering them to (local endpoint), and add
816 * the amount of space required to support the selected
817 * error correction mode
819 switch (udptl->error_correction_scheme) {
820 case UDPTL_ERROR_CORRECTION_NONE:
821 /* need room for sequence number, length indicator, redundancy
822 * indicator and following length indicator
824 new_max = 5 + udptl->local_max_ifp;
826 case UDPTL_ERROR_CORRECTION_REDUNDANCY:
827 /* need room for sequence number, length indicators, plus
828 * room for up to 3 redundancy packets
830 new_max = 5 + udptl->local_max_ifp + 2 + (3 * udptl->local_max_ifp);
832 case UDPTL_ERROR_CORRECTION_FEC:
833 /* need room for sequence number, length indicators and a
834 * a single IFP of the maximum size expected
836 new_max = 5 + udptl->local_max_ifp + 4 + udptl->local_max_ifp;
839 /* add 5% extra space for insurance, but no larger than LOCAL_FAX_MAX_DATAGRAM */
840 udptl->local_max_datagram = MIN(new_max * 1.05, LOCAL_FAX_MAX_DATAGRAM);
843 static void calculate_far_max_ifp(struct ast_udptl *udptl)
845 unsigned new_max = 0;
847 if (udptl->far_max_datagram == -1) {
848 ast_log(LOG_WARNING, "UDPTL (%s): Cannot calculate far_max_ifp before far_max_datagram has been set.\n",
850 udptl->far_max_ifp = -1;
854 /* the goal here is to supply the local endpoint (application
855 * or bridged channel) a maximum IFP value that will allow it
856 * to effectively and efficiently transfer image data at its
857 * selected bit rate, taking into account the selected error
858 * correction mode, but without overrunning the far endpoint's
859 * datagram buffer. this is complicated by the fact that some
860 * far endpoints send us bogus (small) max datagram values,
861 * which would result in either buffer overrun or no error
862 * correction. we try to accomodate those, but if the supplied
863 * value is too small to do so, we'll emit warning messages and
864 * the user will have to use configuration options to override
865 * the max datagram value supplied by the far endpoint.
867 switch (udptl->error_correction_scheme) {
868 case UDPTL_ERROR_CORRECTION_NONE:
869 /* need room for sequence number, length indicator, redundancy
870 * indicator and following length indicator
872 new_max = udptl->far_max_datagram - 5;
874 case UDPTL_ERROR_CORRECTION_REDUNDANCY:
875 /* for this case, we'd like to send as many error correction entries
876 * as possible (up to the number we're configured for), but we'll settle
877 * for sending fewer if the configured number would cause the
878 * calculated max IFP to be too small for effective operation
880 * need room for sequence number, length indicators and the
881 * configured number of redundant packets
883 * note: we purposely don't allow error_correction_entries to drop to
884 * zero in this loop; we'd rather send smaller IFPs (and thus reduce
885 * the image data transfer rate) than sacrifice redundancy completely
888 new_max = (udptl->far_max_datagram - 8) / (udptl->error_correction_entries + 1);
890 if ((new_max < 80) && (udptl->error_correction_entries > 1)) {
891 /* the max ifp is not large enough, subtract an
892 * error correction entry and calculate again
894 --udptl->error_correction_entries;
900 case UDPTL_ERROR_CORRECTION_FEC:
901 /* need room for sequence number, length indicators and a
902 * a single IFP of the maximum size expected
904 new_max = (udptl->far_max_datagram - 10) / 2;
907 /* subtract 5% of space for insurance */
908 udptl->far_max_ifp = new_max * 0.95;
911 enum ast_t38_ec_modes ast_udptl_get_error_correction_scheme(const struct ast_udptl *udptl)
913 return udptl->error_correction_scheme;
916 void ast_udptl_set_error_correction_scheme(struct ast_udptl *udptl, enum ast_t38_ec_modes ec)
918 udptl->error_correction_scheme = ec;
920 case UDPTL_ERROR_CORRECTION_FEC:
921 udptl->error_correction_scheme = UDPTL_ERROR_CORRECTION_FEC;
922 if (udptl->error_correction_entries == 0) {
923 udptl->error_correction_entries = 3;
925 if (udptl->error_correction_span == 0) {
926 udptl->error_correction_span = 3;
929 case UDPTL_ERROR_CORRECTION_REDUNDANCY:
930 udptl->error_correction_scheme = UDPTL_ERROR_CORRECTION_REDUNDANCY;
931 if (udptl->error_correction_entries == 0) {
932 udptl->error_correction_entries = 3;
939 /* reset calculated values so they'll be computed again */
940 udptl->local_max_datagram = -1;
941 udptl->far_max_ifp = -1;
944 void ast_udptl_set_local_max_ifp(struct ast_udptl *udptl, unsigned int max_ifp)
946 /* make sure max_ifp is a positive value since a cast will take place when
947 * when setting local_max_ifp */
948 if ((signed int) max_ifp > 0) {
949 udptl->local_max_ifp = max_ifp;
950 /* reset calculated values so they'll be computed again */
951 udptl->local_max_datagram = -1;
955 unsigned int ast_udptl_get_local_max_datagram(struct ast_udptl *udptl)
957 if (udptl->local_max_datagram == -1) {
958 calculate_local_max_datagram(udptl);
961 /* this function expects a unsigned value in return. */
962 if (udptl->local_max_datagram < 0) {
965 return udptl->local_max_datagram;
968 void ast_udptl_set_far_max_datagram(struct ast_udptl *udptl, unsigned int max_datagram)
970 if (!max_datagram || (max_datagram > FAX_MAX_DATAGRAM_LIMIT)) {
971 udptl->far_max_datagram = DEFAULT_FAX_MAX_DATAGRAM;
973 udptl->far_max_datagram = max_datagram;
975 /* reset calculated values so they'll be computed again */
976 udptl->far_max_ifp = -1;
979 unsigned int ast_udptl_get_far_max_datagram(const struct ast_udptl *udptl)
981 if (udptl->far_max_datagram < 0) {
984 return udptl->far_max_datagram;
987 unsigned int ast_udptl_get_far_max_ifp(struct ast_udptl *udptl)
989 if (udptl->far_max_ifp == -1) {
990 calculate_far_max_ifp(udptl);
993 if (udptl->far_max_ifp < 0) {
996 return udptl->far_max_ifp;
999 struct ast_udptl *ast_udptl_new_with_bindaddr(struct ast_sched_context *sched, struct io_context *io, int callbackmode, struct ast_sockaddr *addr)
1001 struct ast_udptl *udptl;
1006 RAII_VAR(struct udptl_config *, cfg, ao2_global_obj_ref(globals), ao2_cleanup);
1008 if (!cfg || !cfg->general) {
1009 ast_log(LOG_ERROR, "Could not access global udptl options!\n");
1013 if (!(udptl = ast_calloc(1, sizeof(*udptl)))) {
1017 udptl->error_correction_span = cfg->general->fecspan;
1018 udptl->error_correction_entries = cfg->general->fecentries;
1020 udptl->far_max_datagram = -1;
1021 udptl->far_max_ifp = -1;
1022 udptl->local_max_ifp = -1;
1023 udptl->local_max_datagram = -1;
1025 for (i = 0; i <= UDPTL_BUF_MASK; i++) {
1026 udptl->rx[i].buf_len = -1;
1027 udptl->tx[i].buf_len = -1;
1030 if ((udptl->fd = socket(ast_sockaddr_is_ipv6(addr) ?
1031 AF_INET6 : AF_INET, SOCK_DGRAM, 0)) < 0) {
1033 ast_log(LOG_WARNING, "Unable to allocate socket: %s\n", strerror(errno));
1036 flags = fcntl(udptl->fd, F_GETFL);
1037 fcntl(udptl->fd, F_SETFL, flags | O_NONBLOCK);
1040 if (cfg->general->nochecksums)
1041 setsockopt(udptl->fd, SOL_SOCKET, SO_NO_CHECK, &cfg->general->nochecksums, sizeof(cfg->general->nochecksums));
1044 /* Find us a place */
1045 x = (cfg->general->start == cfg->general->end) ? cfg->general->start : (ast_random() % (cfg->general->end - cfg->general->start)) + cfg->general->start;
1046 if (cfg->general->use_even_ports && (x & 1)) {
1051 ast_sockaddr_copy(&udptl->us, addr);
1052 ast_sockaddr_set_port(&udptl->us, x);
1053 if (ast_bind(udptl->fd, &udptl->us) == 0) {
1056 if (errno != EADDRINUSE) {
1057 ast_log(LOG_WARNING, "Unexpected bind error: %s\n", strerror(errno));
1062 if (cfg->general->use_even_ports) {
1067 if (x > cfg->general->end)
1068 x = cfg->general->start;
1069 if (x == startplace) {
1070 ast_log(LOG_WARNING, "No UDPTL ports remaining\n");
1076 if (io && sched && callbackmode) {
1077 /* Operate this one in a callback mode */
1078 udptl->sched = sched;
1080 udptl->ioid = ast_io_add(udptl->io, udptl->fd, udptlread, AST_IO_IN, udptl);
1086 void ast_udptl_set_tag(struct ast_udptl *udptl, const char *format, ...)
1090 ast_free(udptl->tag);
1092 va_start(ap, format);
1093 if (ast_vasprintf(&udptl->tag, format, ap) == -1) {
1099 int ast_udptl_setqos(struct ast_udptl *udptl, unsigned int tos, unsigned int cos)
1101 return ast_set_qos(udptl->fd, tos, cos, "UDPTL");
1104 void ast_udptl_set_peer(struct ast_udptl *udptl, const struct ast_sockaddr *them)
1106 ast_sockaddr_copy(&udptl->them, them);
1109 void ast_udptl_get_peer(const struct ast_udptl *udptl, struct ast_sockaddr *them)
1111 ast_sockaddr_copy(them, &udptl->them);
1114 void ast_udptl_get_us(const struct ast_udptl *udptl, struct ast_sockaddr *us)
1116 ast_sockaddr_copy(us, &udptl->us);
1119 void ast_udptl_stop(struct ast_udptl *udptl)
1121 ast_sockaddr_setnull(&udptl->them);
1124 void ast_udptl_destroy(struct ast_udptl *udptl)
1127 ast_io_remove(udptl->io, udptl->ioid);
1131 ast_free(udptl->tag);
1135 int ast_udptl_write(struct ast_udptl *s, struct ast_frame *f)
1138 unsigned int len = f->datalen;
1139 /* if no max datagram size is provided, use default value */
1140 const int bufsize = (s->far_max_datagram > 0) ? s->far_max_datagram : DEFAULT_FAX_MAX_DATAGRAM;
1141 uint8_t buf[bufsize];
1143 memset(buf, 0, sizeof(buf));
1145 /* If we have no peer, return immediately */
1146 if (ast_sockaddr_isnull(&s->them)) {
1150 /* If there is no data length, return immediately */
1151 if (f->datalen == 0)
1154 if ((f->frametype != AST_FRAME_MODEM) ||
1155 (f->subclass.integer != AST_MODEM_T38)) {
1156 ast_log(LOG_WARNING, "UDPTL (%s): UDPTL can only send T.38 data.\n",
1161 if (len > s->far_max_ifp) {
1162 ast_log(LOG_WARNING,
1163 "UDPTL (%s): UDPTL asked to send %d bytes of IFP when far end only prepared to accept %d bytes; data loss will occur."
1164 "You may need to override the T38FaxMaxDatagram value for this endpoint in the channel driver configuration.\n",
1165 LOG_TAG(s), len, s->far_max_ifp);
1166 len = s->far_max_ifp;
1169 /* Save seq_no for debug output because udptl_build_packet increments it */
1170 seq = s->tx_seq_no & 0xFFFF;
1172 /* Cook up the UDPTL packet, with the relevant EC info. */
1173 len = udptl_build_packet(s, buf, sizeof(buf), f->data.ptr, len);
1175 if ((signed int) len > 0 && !ast_sockaddr_isnull(&s->them)) {
1176 if (ast_sendto(s->fd, buf, len, 0, &s->them) < 0) {
1177 ast_log(LOG_NOTICE, "UDPTL (%s): Transmission error to %s: %s\n",
1178 LOG_TAG(s), ast_sockaddr_stringify(&s->them), strerror(errno));
1180 if (udptl_debug_test_addr(&s->them)) {
1181 ast_verb(1, "UDPTL (%s): packet to %s (seq %d, len %d)\n",
1182 LOG_TAG(s), ast_sockaddr_stringify(&s->them), seq, len);
1189 void ast_udptl_proto_unregister(struct ast_udptl_protocol *proto)
1191 AST_RWLIST_WRLOCK(&protos);
1192 AST_RWLIST_REMOVE(&protos, proto, list);
1193 AST_RWLIST_UNLOCK(&protos);
1196 int ast_udptl_proto_register(struct ast_udptl_protocol *proto)
1198 struct ast_udptl_protocol *cur;
1200 AST_RWLIST_WRLOCK(&protos);
1201 AST_RWLIST_TRAVERSE(&protos, cur, list) {
1202 if (cur->type == proto->type) {
1203 ast_log(LOG_WARNING, "Tried to register same protocol '%s' twice\n", cur->type);
1204 AST_RWLIST_UNLOCK(&protos);
1208 AST_RWLIST_INSERT_TAIL(&protos, proto, list);
1209 AST_RWLIST_UNLOCK(&protos);
1213 static struct ast_udptl_protocol *get_proto(struct ast_channel *chan)
1215 struct ast_udptl_protocol *cur = NULL;
1217 AST_RWLIST_RDLOCK(&protos);
1218 AST_RWLIST_TRAVERSE(&protos, cur, list) {
1219 if (cur->type == ast_channel_tech(chan)->type)
1222 AST_RWLIST_UNLOCK(&protos);
1227 int ast_udptl_bridge(struct ast_channel *c0, struct ast_channel *c1, int flags, struct ast_frame **fo, struct ast_channel **rc)
1229 struct ast_frame *f;
1230 struct ast_channel *who;
1231 struct ast_channel *cs[3];
1232 struct ast_udptl *p0;
1233 struct ast_udptl *p1;
1234 struct ast_udptl_protocol *pr0;
1235 struct ast_udptl_protocol *pr1;
1236 struct ast_sockaddr ac0;
1237 struct ast_sockaddr ac1;
1238 struct ast_sockaddr t0;
1239 struct ast_sockaddr t1;
1244 ast_channel_lock_both(c0, c1);
1245 pr0 = get_proto(c0);
1246 pr1 = get_proto(c1);
1248 ast_log(LOG_WARNING, "Can't find native functions for channel '%s'\n", ast_channel_name(c0));
1249 ast_channel_unlock(c0);
1250 ast_channel_unlock(c1);
1254 ast_log(LOG_WARNING, "Can't find native functions for channel '%s'\n", ast_channel_name(c1));
1255 ast_channel_unlock(c0);
1256 ast_channel_unlock(c1);
1259 pvt0 = ast_channel_tech_pvt(c0);
1260 pvt1 = ast_channel_tech_pvt(c1);
1261 p0 = pr0->get_udptl_info(c0);
1262 p1 = pr1->get_udptl_info(c1);
1264 /* Somebody doesn't want to play... */
1265 ast_channel_unlock(c0);
1266 ast_channel_unlock(c1);
1269 if (pr0->set_udptl_peer(c0, p1)) {
1270 ast_log(LOG_WARNING, "Channel '%s' failed to talk to '%s'\n", ast_channel_name(c0), ast_channel_name(c1));
1271 memset(&ac1, 0, sizeof(ac1));
1273 /* Store UDPTL peer */
1274 ast_udptl_get_peer(p1, &ac1);
1276 if (pr1->set_udptl_peer(c1, p0)) {
1277 ast_log(LOG_WARNING, "Channel '%s' failed to talk back to '%s'\n", ast_channel_name(c1), ast_channel_name(c0));
1278 memset(&ac0, 0, sizeof(ac0));
1280 /* Store UDPTL peer */
1281 ast_udptl_get_peer(p0, &ac0);
1283 ast_channel_unlock(c0);
1284 ast_channel_unlock(c1);
1289 if ((ast_channel_tech_pvt(c0) != pvt0) ||
1290 (ast_channel_tech_pvt(c1) != pvt1) ||
1291 (ast_channel_masq(c0) || ast_channel_masqr(c0) || ast_channel_masq(c1) || ast_channel_masqr(c1))) {
1292 ast_debug(1, "Oooh, something is weird, backing out\n");
1293 /* Tell it to try again later */
1297 ast_udptl_get_peer(p1, &t1);
1298 ast_udptl_get_peer(p0, &t0);
1299 if (ast_sockaddr_cmp(&t1, &ac1)) {
1300 ast_debug(1, "Oooh, '%s' changed end address to %s\n",
1301 ast_channel_name(c1), ast_sockaddr_stringify(&t1));
1302 ast_debug(1, "Oooh, '%s' was %s\n",
1303 ast_channel_name(c1), ast_sockaddr_stringify(&ac1));
1304 ast_sockaddr_copy(&ac1, &t1);
1306 if (ast_sockaddr_cmp(&t0, &ac0)) {
1307 ast_debug(1, "Oooh, '%s' changed end address to %s\n",
1308 ast_channel_name(c0), ast_sockaddr_stringify(&t0));
1309 ast_debug(1, "Oooh, '%s' was %s\n",
1310 ast_channel_name(c0), ast_sockaddr_stringify(&ac0));
1311 ast_sockaddr_copy(&ac0, &t0);
1313 who = ast_waitfor_n(cs, 2, &to);
1315 ast_debug(1, "Ooh, empty read...\n");
1316 /* check for hangup / whentohangup */
1317 if (ast_check_hangup(c0) || ast_check_hangup(c1))
1325 ast_debug(1, "Oooh, got a %s\n", f ? "digit" : "hangup");
1326 /* That's all we needed */
1329 if (f->frametype == AST_FRAME_MODEM) {
1330 /* Forward T.38 frames if they happen upon us */
1333 } else if (who == c1) {
1339 /* Swap priority. Not that it's a big deal at this point */
1347 static char *handle_cli_udptl_set_debug(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
1351 e->command = "udptl set debug {on|off|ip}";
1353 "Usage: udptl set debug {on|off|ip host[:port]}\n"
1354 " Enable or disable dumping of UDPTL packets.\n"
1355 " If ip is specified, limit the dumped packets to those to and from\n"
1356 " the specified 'host' with optional port.\n";
1362 if (a->argc < 4 || a->argc > 5)
1363 return CLI_SHOWUSAGE;
1366 if (!strncasecmp(a->argv[3], "on", 2)) {
1368 memset(&udptldebugaddr, 0, sizeof(udptldebugaddr));
1369 ast_cli(a->fd, "UDPTL Debugging Enabled\n");
1370 } else if (!strncasecmp(a->argv[3], "off", 3)) {
1372 ast_cli(a->fd, "UDPTL Debugging Disabled\n");
1374 return CLI_SHOWUSAGE;
1377 struct ast_sockaddr *addrs;
1378 if (strncasecmp(a->argv[3], "ip", 2))
1379 return CLI_SHOWUSAGE;
1380 if (!ast_sockaddr_resolve(&addrs, a->argv[4], 0, 0)) {
1381 return CLI_SHOWUSAGE;
1383 ast_sockaddr_copy(&udptldebugaddr, &addrs[0]);
1384 ast_cli(a->fd, "UDPTL Debugging Enabled for IP: %s\n", ast_sockaddr_stringify(&udptldebugaddr));
1392 static char *handle_cli_show_config(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
1394 RAII_VAR(struct udptl_config *, cfg, NULL, ao2_cleanup);
1398 e->command = "udptl show config";
1400 "Usage: udptl show config\n"
1401 " Display UDPTL configuration options\n";
1407 if (!(cfg = ao2_global_obj_ref(globals))) {
1411 ast_cli(a->fd, "UDPTL Global options\n");
1412 ast_cli(a->fd, "--------------------\n");
1413 ast_cli(a->fd, "udptlstart: %u\n", cfg->general->start);
1414 ast_cli(a->fd, "udptlend: %u\n", cfg->general->end);
1415 ast_cli(a->fd, "udptlfecentries: %u\n", cfg->general->fecentries);
1416 ast_cli(a->fd, "udptlfecspan: %u\n", cfg->general->fecspan);
1417 ast_cli(a->fd, "use_even_ports: %s\n", AST_CLI_YESNO(cfg->general->use_even_ports));
1418 ast_cli(a->fd, "udptlchecksums: %s\n", AST_CLI_YESNO(!cfg->general->nochecksums));
1423 static struct ast_cli_entry cli_udptl[] = {
1424 AST_CLI_DEFINE(handle_cli_udptl_set_debug, "Enable/Disable UDPTL debugging"),
1425 AST_CLI_DEFINE(handle_cli_show_config, "Show UDPTL config options"),
1428 static void udptl_config_destructor(void *obj)
1430 struct udptl_config *cfg = obj;
1431 ao2_cleanup(cfg->general);
1434 static void *udptl_snapshot_alloc(void)
1436 struct udptl_config *cfg;
1438 if (!(cfg = ao2_alloc(sizeof(*cfg), udptl_config_destructor))) {
1441 if (!(cfg->general = ao2_alloc(sizeof(*cfg->general), NULL))) {
1449 static int removed_options_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
1451 if (!strcasecmp(var->name, "t38faxudpec")) {
1452 ast_log(LOG_WARNING, "t38faxudpec in udptl.conf is no longer supported; use the t38pt_udptl configuration option in sip.conf instead.\n");
1453 } else if (!strcasecmp(var->name, "t38faxmaxdatagram")) {
1454 ast_log(LOG_WARNING, "t38faxmaxdatagram in udptl.conf is no longer supported; value is now supplied by T.38 applications.\n");
1459 static void __ast_udptl_reload(int reload)
1461 if (aco_process_config(&cfg_info, reload) == ACO_PROCESS_ERROR) {
1463 RAII_VAR(struct udptl_config *, udptl_cfg, udptl_snapshot_alloc(), ao2_cleanup);
1465 if (aco_set_defaults(&general_option, "general", udptl_cfg->general)) {
1466 ast_log(LOG_ERROR, "Failed to load udptl.conf and failed to initialize defaults.\n");
1470 ast_log(LOG_NOTICE, "Could not load udptl config; using defaults\n");
1471 ao2_global_obj_replace_unref(globals, udptl_cfg);
1476 static int udptl_pre_apply_config(void) {
1477 struct udptl_config *cfg = aco_pending_config(&cfg_info);
1479 if (!cfg->general) {
1484 if (cfg->general->nochecksums) {
1485 ast_log(LOG_WARNING, "Disabling UDPTL checksums is not supported on this operating system!\n");
1486 cfg->general->nochecksums = 0;
1490 /* Fix up any global config values that we can handle before replacing the config */
1491 if (cfg->general->use_even_ports && (cfg->general->start & 1)) {
1492 ++cfg->general->start;
1493 ast_log(LOG_NOTICE, "Odd numbered udptlstart specified but use_even_ports enabled. udptlstart is now %d\n", cfg->general->start);
1495 if (cfg->general->start > cfg->general->end) {
1496 ast_log(LOG_WARNING, "Unreasonable values for UDPTL start/end ports; defaulting to %s-%s.\n", __stringify(DEFAULT_UDPTLSTART), __stringify(DEFAULT_UDPTLEND));
1497 cfg->general->start = DEFAULT_UDPTLSTART;
1498 cfg->general->end = DEFAULT_UDPTLEND;
1500 if (cfg->general->use_even_ports && (cfg->general->end & 1)) {
1501 --cfg->general->end;
1502 ast_log(LOG_NOTICE, "Odd numbered udptlend specified but use_even_ports enabled. udptlend is now %d\n", cfg->general->end);
1508 int ast_udptl_reload(void)
1510 __ast_udptl_reload(1);
1516 * \brief Clean up resources on Asterisk shutdown
1518 static void udptl_shutdown(void)
1520 ast_cli_unregister_multiple(cli_udptl, ARRAY_LEN(cli_udptl));
1521 ao2_t_global_obj_release(globals, "Unref udptl global container in shutdown");
1522 aco_info_destroy(&cfg_info);
1525 void ast_udptl_init(void)
1527 if (aco_info_init(&cfg_info)) {
1531 aco_option_register(&cfg_info, "udptlstart", ACO_EXACT, general_options, __stringify(DEFAULT_UDPTLSTART),
1532 OPT_UINT_T, PARSE_IN_RANGE | PARSE_DEFAULT,
1533 FLDSET(struct udptl_global_options, start), DEFAULT_UDPTLSTART, 1024, 65535);
1535 aco_option_register(&cfg_info, "udptlend", ACO_EXACT, general_options, __stringify(DEFAULT_UDPTLEND),
1536 OPT_UINT_T, PARSE_IN_RANGE | PARSE_DEFAULT,
1537 FLDSET(struct udptl_global_options, end), DEFAULT_UDPTLEND, 1024, 65535);
1539 aco_option_register(&cfg_info, "udptlfecentries", ACO_EXACT, general_options, NULL,
1540 OPT_UINT_T, PARSE_IN_RANGE | PARSE_RANGE_DEFAULTS,
1541 FLDSET(struct udptl_global_options, fecentries), 1, MAX_FEC_ENTRIES);
1543 aco_option_register(&cfg_info, "udptlfecspan", ACO_EXACT, general_options, NULL,
1544 OPT_UINT_T, PARSE_IN_RANGE | PARSE_RANGE_DEFAULTS,
1545 FLDSET(struct udptl_global_options, fecspan), 1, MAX_FEC_SPAN);
1547 aco_option_register(&cfg_info, "udptlchecksums", ACO_EXACT, general_options, "yes",
1548 OPT_BOOL_T, 0, FLDSET(struct udptl_global_options, nochecksums));
1550 aco_option_register(&cfg_info, "use_even_ports", ACO_EXACT, general_options, "no",
1551 OPT_BOOL_T, 1, FLDSET(struct udptl_global_options, use_even_ports));
1553 aco_option_register_custom(&cfg_info, "t38faxudpec", ACO_EXACT, general_options, NULL, removed_options_handler, 0);
1554 aco_option_register_custom(&cfg_info, "t38faxmaxdatagram", ACO_EXACT, general_options, NULL, removed_options_handler, 0);
1556 __ast_udptl_reload(0);
1558 ast_cli_register_multiple(cli_udptl, ARRAY_LEN(cli_udptl));
1560 ast_register_atexit(udptl_shutdown);