UDPTL support for T.38. More...
#include "asterisk/network.h"
#include "asterisk/frame.h"
#include "asterisk/io.h"
#include "asterisk/sched.h"
#include "asterisk/channel.h"
#include "asterisk/netsock2.h"
Go to the source code of this file.
Data Structures | |
struct | ast_udptl_protocol |
Typedefs | |
typedef int(* | ast_udptl_callback )(struct ast_udptl *udptl, struct ast_frame *f, void *data) |
Enumerations | |
enum | ast_t38_ec_modes { UDPTL_ERROR_CORRECTION_NONE, UDPTL_ERROR_CORRECTION_FEC, UDPTL_ERROR_CORRECTION_REDUNDANCY } |
Functions | |
int | ast_udptl_bridge (struct ast_channel *c0, struct ast_channel *c1, int flags, struct ast_frame **fo, struct ast_channel **rc) |
void | ast_udptl_destroy (struct ast_udptl *udptl) |
int | ast_udptl_fd (const struct ast_udptl *udptl) |
enum ast_t38_ec_modes | ast_udptl_get_error_correction_scheme (const struct ast_udptl *udptl) |
unsigned int | ast_udptl_get_far_max_datagram (const struct ast_udptl *udptl) |
unsigned int | ast_udptl_get_far_max_ifp (struct ast_udptl *udptl) |
retrieves far max ifp | |
unsigned int | ast_udptl_get_local_max_datagram (struct ast_udptl *udptl) |
retrieves local_max_datagram. | |
void | ast_udptl_get_peer (const struct ast_udptl *udptl, struct ast_sockaddr *them) |
void | ast_udptl_get_us (const struct ast_udptl *udptl, struct ast_sockaddr *us) |
void | ast_udptl_init (void) |
struct ast_udptl * | ast_udptl_new_with_bindaddr (struct sched_context *sched, struct io_context *io, int callbackmode, struct ast_sockaddr *in) |
int | ast_udptl_proto_register (struct ast_udptl_protocol *proto) |
void | ast_udptl_proto_unregister (struct ast_udptl_protocol *proto) |
struct ast_frame * | ast_udptl_read (struct ast_udptl *udptl) |
int | ast_udptl_reload (void) |
void | ast_udptl_reset (struct ast_udptl *udptl) |
void | ast_udptl_set_callback (struct ast_udptl *udptl, ast_udptl_callback callback) |
void | ast_udptl_set_data (struct ast_udptl *udptl, void *data) |
void | ast_udptl_set_error_correction_scheme (struct ast_udptl *udptl, enum ast_t38_ec_modes ec) |
void | ast_udptl_set_far_max_datagram (struct ast_udptl *udptl, unsigned int max_datagram) |
sets far max datagram size. If max_datagram is = 0, the far max datagram size is set to a default value. | |
void | ast_udptl_set_local_max_ifp (struct ast_udptl *udptl, unsigned int max_ifp) |
void | ast_udptl_set_m_type (struct ast_udptl *udptl, unsigned int pt) |
void | ast_udptl_set_peer (struct ast_udptl *udptl, const struct ast_sockaddr *them) |
void | ast_udptl_set_tag (struct ast_udptl *udptl, const char *format,...) |
Associates a character string 'tag' with a UDPTL session. | |
void | ast_udptl_set_udptlmap_type (struct ast_udptl *udptl, unsigned int pt, char *mimeType, char *mimeSubtype) |
void | ast_udptl_setnat (struct ast_udptl *udptl, int nat) |
int | ast_udptl_setqos (struct ast_udptl *udptl, unsigned int tos, unsigned int cos) |
void | ast_udptl_stop (struct ast_udptl *udptl) |
int | ast_udptl_write (struct ast_udptl *udptl, struct ast_frame *f) |
UDPTL support for T.38.
Definition in file udptl.h.
typedef int(* ast_udptl_callback)(struct ast_udptl *udptl, struct ast_frame *f, void *data) |
enum ast_t38_ec_modes |
UDPTL_ERROR_CORRECTION_NONE | |
UDPTL_ERROR_CORRECTION_FEC | |
UDPTL_ERROR_CORRECTION_REDUNDANCY |
Definition at line 37 of file udptl.h.
00037 { 00038 UDPTL_ERROR_CORRECTION_NONE, 00039 UDPTL_ERROR_CORRECTION_FEC, 00040 UDPTL_ERROR_CORRECTION_REDUNDANCY 00041 };
int ast_udptl_bridge | ( | struct ast_channel * | c0, | |
struct ast_channel * | c1, | |||
int | flags, | |||
struct ast_frame ** | fo, | |||
struct ast_channel ** | rc | |||
) |
Definition at line 1146 of file udptl.c.
References ast_channel_lock, ast_channel_trylock, ast_channel_unlock, ast_check_hangup(), ast_debug, AST_FRAME_MODEM, ast_frfree, ast_log(), ast_read(), ast_sockaddr_cmp(), ast_sockaddr_copy(), ast_sockaddr_stringify(), ast_udptl_get_peer(), ast_waitfor_n(), ast_write(), f, ast_frame::frametype, get_proto(), ast_udptl_protocol::get_udptl_info, LOG_WARNING, ast_channel::masq, ast_channel::masqr, ast_udptl_protocol::set_udptl_peer, and ast_channel::tech_pvt.
01147 { 01148 struct ast_frame *f; 01149 struct ast_channel *who; 01150 struct ast_channel *cs[3]; 01151 struct ast_udptl *p0; 01152 struct ast_udptl *p1; 01153 struct ast_udptl_protocol *pr0; 01154 struct ast_udptl_protocol *pr1; 01155 struct ast_sockaddr ac0; 01156 struct ast_sockaddr ac1; 01157 struct ast_sockaddr t0; 01158 struct ast_sockaddr t1; 01159 void *pvt0; 01160 void *pvt1; 01161 int to; 01162 01163 ast_channel_lock(c0); 01164 while (ast_channel_trylock(c1)) { 01165 ast_channel_unlock(c0); 01166 usleep(1); 01167 ast_channel_lock(c0); 01168 } 01169 pr0 = get_proto(c0); 01170 pr1 = get_proto(c1); 01171 if (!pr0) { 01172 ast_log(LOG_WARNING, "Can't find native functions for channel '%s'\n", c0->name); 01173 ast_channel_unlock(c0); 01174 ast_channel_unlock(c1); 01175 return -1; 01176 } 01177 if (!pr1) { 01178 ast_log(LOG_WARNING, "Can't find native functions for channel '%s'\n", c1->name); 01179 ast_channel_unlock(c0); 01180 ast_channel_unlock(c1); 01181 return -1; 01182 } 01183 pvt0 = c0->tech_pvt; 01184 pvt1 = c1->tech_pvt; 01185 p0 = pr0->get_udptl_info(c0); 01186 p1 = pr1->get_udptl_info(c1); 01187 if (!p0 || !p1) { 01188 /* Somebody doesn't want to play... */ 01189 ast_channel_unlock(c0); 01190 ast_channel_unlock(c1); 01191 return -2; 01192 } 01193 if (pr0->set_udptl_peer(c0, p1)) { 01194 ast_log(LOG_WARNING, "Channel '%s' failed to talk to '%s'\n", c0->name, c1->name); 01195 memset(&ac1, 0, sizeof(ac1)); 01196 } else { 01197 /* Store UDPTL peer */ 01198 ast_udptl_get_peer(p1, &ac1); 01199 } 01200 if (pr1->set_udptl_peer(c1, p0)) { 01201 ast_log(LOG_WARNING, "Channel '%s' failed to talk back to '%s'\n", c1->name, c0->name); 01202 memset(&ac0, 0, sizeof(ac0)); 01203 } else { 01204 /* Store UDPTL peer */ 01205 ast_udptl_get_peer(p0, &ac0); 01206 } 01207 ast_channel_unlock(c0); 01208 ast_channel_unlock(c1); 01209 cs[0] = c0; 01210 cs[1] = c1; 01211 cs[2] = NULL; 01212 for (;;) { 01213 if ((c0->tech_pvt != pvt0) || 01214 (c1->tech_pvt != pvt1) || 01215 (c0->masq || c0->masqr || c1->masq || c1->masqr)) { 01216 ast_debug(1, "Oooh, something is weird, backing out\n"); 01217 /* Tell it to try again later */ 01218 return -3; 01219 } 01220 to = -1; 01221 ast_udptl_get_peer(p1, &t1); 01222 ast_udptl_get_peer(p0, &t0); 01223 if (ast_sockaddr_cmp(&t1, &ac1)) { 01224 ast_debug(1, "Oooh, '%s' changed end address to %s\n", 01225 c1->name, ast_sockaddr_stringify(&t1)); 01226 ast_debug(1, "Oooh, '%s' was %s\n", 01227 c1->name, ast_sockaddr_stringify(&ac1)); 01228 ast_sockaddr_copy(&ac1, &t1); 01229 } 01230 if (ast_sockaddr_cmp(&t0, &ac0)) { 01231 ast_debug(1, "Oooh, '%s' changed end address to %s\n", 01232 c0->name, ast_sockaddr_stringify(&t0)); 01233 ast_debug(1, "Oooh, '%s' was %s\n", 01234 c0->name, ast_sockaddr_stringify(&ac0)); 01235 ast_sockaddr_copy(&ac0, &t0); 01236 } 01237 who = ast_waitfor_n(cs, 2, &to); 01238 if (!who) { 01239 ast_debug(1, "Ooh, empty read...\n"); 01240 /* check for hangup / whentohangup */ 01241 if (ast_check_hangup(c0) || ast_check_hangup(c1)) 01242 break; 01243 continue; 01244 } 01245 f = ast_read(who); 01246 if (!f) { 01247 *fo = f; 01248 *rc = who; 01249 ast_debug(1, "Oooh, got a %s\n", f ? "digit" : "hangup"); 01250 /* That's all we needed */ 01251 return 0; 01252 } else { 01253 if (f->frametype == AST_FRAME_MODEM) { 01254 /* Forward T.38 frames if they happen upon us */ 01255 if (who == c0) { 01256 ast_write(c1, f); 01257 } else if (who == c1) { 01258 ast_write(c0, f); 01259 } 01260 } 01261 ast_frfree(f); 01262 } 01263 /* Swap priority. Not that it's a big deal at this point */ 01264 cs[2] = cs[0]; 01265 cs[0] = cs[1]; 01266 cs[1] = cs[2]; 01267 } 01268 return -1; 01269 }
void ast_udptl_destroy | ( | struct ast_udptl * | udptl | ) |
Definition at line 1044 of file udptl.c.
References ast_free, ast_io_remove(), ast_udptl::fd, ast_udptl::io, ast_udptl::ioid, and ast_udptl::tag.
Referenced by __sip_destroy().
int ast_udptl_fd | ( | const struct ast_udptl * | udptl | ) |
Definition at line 643 of file udptl.c.
References ast_udptl::fd.
Referenced by __oh323_new(), initialize_udptl(), and sip_new().
00644 { 00645 return udptl->fd; 00646 }
enum ast_t38_ec_modes ast_udptl_get_error_correction_scheme | ( | const struct ast_udptl * | udptl | ) |
Definition at line 841 of file udptl.c.
References ast_udptl::error_correction_scheme.
Referenced by add_sdp().
00842 { 00843 return udptl->error_correction_scheme; 00844 }
unsigned int ast_udptl_get_far_max_datagram | ( | const struct ast_udptl * | udptl | ) |
Definition at line 909 of file udptl.c.
References ast_udptl::far_max_datagram.
Referenced by process_sdp().
00910 { 00911 if (udptl->far_max_datagram < 0) { 00912 return 0; 00913 } 00914 return udptl->far_max_datagram; 00915 }
unsigned int ast_udptl_get_far_max_ifp | ( | struct ast_udptl * | udptl | ) |
retrieves far max ifp
positive | value representing max ifp size | |
0 | if no value is present |
Definition at line 917 of file udptl.c.
References calculate_far_max_ifp(), and ast_udptl::far_max_ifp.
Referenced by change_t38_state(), and interpret_t38_parameters().
00918 { 00919 if (udptl->far_max_ifp == -1) { 00920 calculate_far_max_ifp(udptl); 00921 } 00922 00923 if (udptl->far_max_ifp < 0) { 00924 return 0; 00925 } 00926 return udptl->far_max_ifp; 00927 }
unsigned int ast_udptl_get_local_max_datagram | ( | struct ast_udptl * | udptl | ) |
retrieves local_max_datagram.
positive | value representing max datagram size. | |
0 | if no value is present |
Definition at line 885 of file udptl.c.
References calculate_local_max_datagram(), and ast_udptl::local_max_datagram.
Referenced by add_sdp().
00886 { 00887 if (udptl->local_max_datagram == -1) { 00888 calculate_local_max_datagram(udptl); 00889 } 00890 00891 /* this function expects a unsigned value in return. */ 00892 if (udptl->local_max_datagram < 0) { 00893 return 0; 00894 } 00895 return udptl->local_max_datagram; 00896 }
void ast_udptl_get_peer | ( | const struct ast_udptl * | udptl, | |
struct ast_sockaddr * | them | |||
) |
Definition at line 1029 of file udptl.c.
References ast_sockaddr_copy(), and ast_udptl::them.
Referenced by ast_udptl_bridge(), and sip_set_udptl_peer().
01030 { 01031 ast_sockaddr_copy(them, &udptl->them); 01032 }
void ast_udptl_get_us | ( | const struct ast_udptl * | udptl, | |
struct ast_sockaddr * | us | |||
) |
Definition at line 1034 of file udptl.c.
References ast_sockaddr_copy(), and ast_udptl::us.
Referenced by add_sdp().
01035 { 01036 ast_sockaddr_copy(us, &udptl->us); 01037 }
void ast_udptl_init | ( | void | ) |
Definition at line 1436 of file udptl.c.
References __ast_udptl_reload(), ARRAY_LEN, ast_cli_register_multiple(), ast_register_atexit(), and udptl_shutdown().
Referenced by main().
01437 { 01438 __ast_udptl_reload(0); 01439 01440 ast_cli_register_multiple(cli_udptl, ARRAY_LEN(cli_udptl)); 01441 01442 ast_register_atexit(udptl_shutdown); 01443 }
struct ast_udptl* ast_udptl_new_with_bindaddr | ( | struct sched_context * | sched, | |
struct io_context * | io, | |||
int | callbackmode, | |||
struct ast_sockaddr * | in | |||
) | [read] |
Definition at line 929 of file udptl.c.
References ast_bind(), ast_calloc, ast_free, ast_io_add(), AST_IO_IN, ast_log(), ast_random(), ast_sockaddr_copy(), ast_sockaddr_is_ipv6(), ast_sockaddr_set_port, udptl_fec_tx_buffer_t::buf_len, udptl_fec_rx_buffer_t::buf_len, errno, ast_udptl::error_correction_entries, ast_udptl::error_correction_span, ast_udptl::far_max_datagram, ast_udptl::far_max_ifp, ast_udptl::fd, ast_udptl::flags, ast_udptl::io, ast_udptl::ioid, ast_udptl::local_max_datagram, ast_udptl::local_max_ifp, LOG_WARNING, ast_udptl::rx, ast_udptl::sched, ast_udptl::tx, UDPTL_BUF_MASK, udptlread(), and ast_udptl::us.
Referenced by initialize_udptl().
00930 { 00931 struct ast_udptl *udptl; 00932 int x; 00933 int startplace; 00934 int i; 00935 long int flags; 00936 00937 if (!(udptl = ast_calloc(1, sizeof(*udptl)))) 00938 return NULL; 00939 00940 udptl->error_correction_span = udptlfecspan; 00941 udptl->error_correction_entries = udptlfecentries; 00942 00943 udptl->far_max_datagram = -1; 00944 udptl->far_max_ifp = -1; 00945 udptl->local_max_ifp = -1; 00946 udptl->local_max_datagram = -1; 00947 00948 for (i = 0; i <= UDPTL_BUF_MASK; i++) { 00949 udptl->rx[i].buf_len = -1; 00950 udptl->tx[i].buf_len = -1; 00951 } 00952 00953 if ((udptl->fd = socket(ast_sockaddr_is_ipv6(addr) ? 00954 AF_INET6 : AF_INET, SOCK_DGRAM, 0)) < 0) { 00955 ast_free(udptl); 00956 ast_log(LOG_WARNING, "Unable to allocate socket: %s\n", strerror(errno)); 00957 return NULL; 00958 } 00959 flags = fcntl(udptl->fd, F_GETFL); 00960 fcntl(udptl->fd, F_SETFL, flags | O_NONBLOCK); 00961 #ifdef SO_NO_CHECK 00962 if (nochecksums) 00963 setsockopt(udptl->fd, SOL_SOCKET, SO_NO_CHECK, &nochecksums, sizeof(nochecksums)); 00964 #endif 00965 /* Find us a place */ 00966 x = (udptlstart == udptlend) ? udptlstart : (ast_random() % (udptlend - udptlstart)) + udptlstart; 00967 if (use_even_ports && (x & 1)) { 00968 ++x; 00969 } 00970 startplace = x; 00971 for (;;) { 00972 ast_sockaddr_copy(&udptl->us, addr); 00973 ast_sockaddr_set_port(&udptl->us, x); 00974 if (ast_bind(udptl->fd, &udptl->us) == 0) { 00975 break; 00976 } 00977 if (errno != EADDRINUSE && errno != EACCES) { 00978 ast_log(LOG_WARNING, "Unexpected bind error: %s\n", strerror(errno)); 00979 close(udptl->fd); 00980 ast_free(udptl); 00981 return NULL; 00982 } 00983 if (use_even_ports) { 00984 x += 2; 00985 } else { 00986 ++x; 00987 } 00988 if (x > udptlend) 00989 x = udptlstart; 00990 if (x == startplace) { 00991 ast_log(LOG_WARNING, "No UDPTL ports remaining\n"); 00992 close(udptl->fd); 00993 ast_free(udptl); 00994 return NULL; 00995 } 00996 } 00997 if (io && sched && callbackmode) { 00998 /* Operate this one in a callback mode */ 00999 udptl->sched = sched; 01000 udptl->io = io; 01001 udptl->ioid = ast_io_add(udptl->io, udptl->fd, udptlread, AST_IO_IN, udptl); 01002 } 01003 return udptl; 01004 }
int ast_udptl_proto_register | ( | struct ast_udptl_protocol * | proto | ) |
Definition at line 1115 of file udptl.c.
References ast_log(), AST_RWLIST_INSERT_TAIL, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_udptl_protocol::list, LOG_WARNING, and ast_udptl_protocol::type.
Referenced by load_module().
01116 { 01117 struct ast_udptl_protocol *cur; 01118 01119 AST_RWLIST_WRLOCK(&protos); 01120 AST_RWLIST_TRAVERSE(&protos, cur, list) { 01121 if (cur->type == proto->type) { 01122 ast_log(LOG_WARNING, "Tried to register same protocol '%s' twice\n", cur->type); 01123 AST_RWLIST_UNLOCK(&protos); 01124 return -1; 01125 } 01126 } 01127 AST_RWLIST_INSERT_TAIL(&protos, proto, list); 01128 AST_RWLIST_UNLOCK(&protos); 01129 return 0; 01130 }
void ast_udptl_proto_unregister | ( | struct ast_udptl_protocol * | proto | ) |
Definition at line 1108 of file udptl.c.
References AST_RWLIST_REMOVE, AST_RWLIST_UNLOCK, and AST_RWLIST_WRLOCK.
Referenced by unload_module().
01109 { 01110 AST_RWLIST_WRLOCK(&protos); 01111 AST_RWLIST_REMOVE(&protos, proto, list); 01112 AST_RWLIST_UNLOCK(&protos); 01113 }
Definition at line 675 of file udptl.c.
References ast_assert, ast_debug, AST_FRIENDLY_OFFSET, ast_log(), ast_null_frame, ast_recvfrom(), ast_sockaddr_cmp(), ast_sockaddr_copy(), ast_sockaddr_isnull(), ast_sockaddr_stringify(), ast_verb, errno, ast_udptl::f, ast_udptl::fd, LOG_TAG, LOG_WARNING, ast_udptl::nat, ast_udptl::rawdata, ast_udptl::them, udptl_debug_test_addr(), and udptl_rx_packet().
Referenced by sip_rtp_read(), skinny_rtp_read(), and udptlread().
00676 { 00677 int res; 00678 struct ast_sockaddr addr; 00679 uint8_t *buf; 00680 00681 buf = udptl->rawdata + AST_FRIENDLY_OFFSET; 00682 00683 /* Cache where the header will go */ 00684 res = ast_recvfrom(udptl->fd, 00685 buf, 00686 sizeof(udptl->rawdata) - AST_FRIENDLY_OFFSET, 00687 0, 00688 &addr); 00689 if (res < 0) { 00690 if (errno != EAGAIN) 00691 ast_log(LOG_WARNING, "UDPTL (%s): read error: %s\n", 00692 LOG_TAG(udptl), strerror(errno)); 00693 ast_assert(errno != EBADF); 00694 return &ast_null_frame; 00695 } 00696 00697 /* Ignore if the other side hasn't been given an address yet. */ 00698 if (ast_sockaddr_isnull(&udptl->them)) { 00699 return &ast_null_frame; 00700 } 00701 00702 if (udptl->nat) { 00703 /* Send to whoever sent to us */ 00704 if (ast_sockaddr_cmp(&udptl->them, &addr)) { 00705 ast_sockaddr_copy(&udptl->them, &addr); 00706 ast_debug(1, "UDPTL (%s): NAT, Using address %s\n", 00707 LOG_TAG(udptl), ast_sockaddr_stringify(&udptl->them)); 00708 } 00709 } 00710 00711 if (udptl_debug_test_addr(&addr)) { 00712 int seq_no; 00713 00714 /* Decode sequence number just for verbose message. */ 00715 if (res < 2) { 00716 /* Short packet. */ 00717 seq_no = -1; 00718 } else { 00719 seq_no = (buf[0] << 8) | buf[1]; 00720 } 00721 00722 ast_verb(1, "UDPTL (%s): packet from %s (seq %d, len %d)\n", 00723 LOG_TAG(udptl), ast_sockaddr_stringify(&addr), seq_no, res); 00724 } 00725 if (udptl_rx_packet(udptl, buf, res) < 1) { 00726 return &ast_null_frame; 00727 } 00728 00729 return &udptl->f[0]; 00730 }
int ast_udptl_reload | ( | void | ) |
Definition at line 1421 of file udptl.c.
References __ast_udptl_reload().
01422 { 01423 __ast_udptl_reload(1); 01424 return 0; 01425 }
void ast_udptl_reset | ( | struct ast_udptl * | udptl | ) |
void ast_udptl_set_callback | ( | struct ast_udptl * | udptl, | |
ast_udptl_callback | callback | |||
) |
Definition at line 653 of file udptl.c.
References ast_udptl::callback.
00654 { 00655 udptl->callback = callback; 00656 }
void ast_udptl_set_data | ( | struct ast_udptl * | udptl, | |
void * | data | |||
) |
Definition at line 648 of file udptl.c.
References ast_udptl::data.
00649 { 00650 udptl->data = data; 00651 }
void ast_udptl_set_error_correction_scheme | ( | struct ast_udptl * | udptl, | |
enum ast_t38_ec_modes | ec | |||
) |
Definition at line 846 of file udptl.c.
References ast_udptl::error_correction_entries, ast_udptl::error_correction_scheme, ast_udptl::error_correction_span, ast_udptl::far_max_ifp, ast_udptl::local_max_datagram, UDPTL_ERROR_CORRECTION_FEC, and UDPTL_ERROR_CORRECTION_REDUNDANCY.
Referenced by process_sdp(), process_sdp_a_image(), and set_t38_capabilities().
00847 { 00848 udptl->error_correction_scheme = ec; 00849 switch (ec) { 00850 case UDPTL_ERROR_CORRECTION_FEC: 00851 udptl->error_correction_scheme = UDPTL_ERROR_CORRECTION_FEC; 00852 if (udptl->error_correction_entries == 0) { 00853 udptl->error_correction_entries = 3; 00854 } 00855 if (udptl->error_correction_span == 0) { 00856 udptl->error_correction_span = 3; 00857 } 00858 break; 00859 case UDPTL_ERROR_CORRECTION_REDUNDANCY: 00860 udptl->error_correction_scheme = UDPTL_ERROR_CORRECTION_REDUNDANCY; 00861 if (udptl->error_correction_entries == 0) { 00862 udptl->error_correction_entries = 3; 00863 } 00864 break; 00865 default: 00866 /* nothing to do */ 00867 break; 00868 }; 00869 /* reset calculated values so they'll be computed again */ 00870 udptl->local_max_datagram = -1; 00871 udptl->far_max_ifp = -1; 00872 }
void ast_udptl_set_far_max_datagram | ( | struct ast_udptl * | udptl, | |
unsigned int | max_datagram | |||
) |
sets far max datagram size. If max_datagram is = 0, the far max datagram size is set to a default value.
Definition at line 898 of file udptl.c.
References DEFAULT_FAX_MAX_DATAGRAM, ast_udptl::far_max_datagram, ast_udptl::far_max_ifp, and FAX_MAX_DATAGRAM_LIMIT.
Referenced by process_sdp(), and process_sdp_a_image().
00899 { 00900 if (!max_datagram || (max_datagram > FAX_MAX_DATAGRAM_LIMIT)) { 00901 udptl->far_max_datagram = DEFAULT_FAX_MAX_DATAGRAM; 00902 } else { 00903 udptl->far_max_datagram = max_datagram; 00904 } 00905 /* reset calculated values so they'll be computed again */ 00906 udptl->far_max_ifp = -1; 00907 }
void ast_udptl_set_local_max_ifp | ( | struct ast_udptl * | udptl, | |
unsigned int | max_ifp | |||
) |
Definition at line 874 of file udptl.c.
References ast_udptl::local_max_datagram, and ast_udptl::local_max_ifp.
Referenced by interpret_t38_parameters().
00875 { 00876 /* make sure max_ifp is a positive value since a cast will take place when 00877 * when setting local_max_ifp */ 00878 if ((signed int) max_ifp > 0) { 00879 udptl->local_max_ifp = max_ifp; 00880 /* reset calculated values so they'll be computed again */ 00881 udptl->local_max_datagram = -1; 00882 } 00883 }
void ast_udptl_set_m_type | ( | struct ast_udptl * | udptl, | |
unsigned int | pt | |||
) |
void ast_udptl_set_peer | ( | struct ast_udptl * | udptl, | |
const struct ast_sockaddr * | them | |||
) |
Definition at line 1024 of file udptl.c.
References ast_sockaddr_copy(), and ast_udptl::them.
Referenced by process_sdp().
01025 { 01026 ast_sockaddr_copy(&udptl->them, them); 01027 }
void ast_udptl_set_tag | ( | struct ast_udptl * | udptl, | |
const char * | format, | |||
... | ||||
) |
Associates a character string 'tag' with a UDPTL session.
udptl | The UDPTL session. | |
format | printf-style format string used to construct the tag |
This function formats a tag for the specified UDPTL session, so that any log messages generated by the UDPTL stack related to that session will include the tag and the reader of the messages will be able to identify which endpoint caused them to be generated.
none |
Definition at line 1006 of file udptl.c.
References ast_free, ast_vasprintf, and ast_udptl::tag.
Referenced by change_t38_state().
void ast_udptl_set_udptlmap_type | ( | struct ast_udptl * | udptl, | |
unsigned int | pt, | |||
char * | mimeType, | |||
char * | mimeSubtype | |||
) |
void ast_udptl_setnat | ( | struct ast_udptl * | udptl, | |
int | nat | |||
) |
Definition at line 658 of file udptl.c.
References ast_udptl::nat.
Referenced by do_setnat(), and initialize_udptl().
int ast_udptl_setqos | ( | struct ast_udptl * | udptl, | |
unsigned int | tos, | |||
unsigned int | cos | |||
) |
Definition at line 1019 of file udptl.c.
References ast_netsock_set_qos(), and ast_udptl::fd.
Referenced by initialize_udptl().
01020 { 01021 return ast_netsock_set_qos(udptl->fd, tos, cos, "UDPTL"); 01022 }
void ast_udptl_stop | ( | struct ast_udptl * | udptl | ) |
Definition at line 1039 of file udptl.c.
References ast_sockaddr_setnull(), and ast_udptl::them.
Referenced by process_sdp(), and stop_media_flows().
01040 { 01041 ast_sockaddr_setnull(&udptl->them); 01042 }
Definition at line 1055 of file udptl.c.
References AST_FRAME_MODEM, ast_log(), AST_MODEM_T38, ast_sendto(), ast_sockaddr_isnull(), ast_sockaddr_stringify(), ast_verb, ast_frame_subclass::codec, ast_frame::data, ast_frame::datalen, DEFAULT_FAX_MAX_DATAGRAM, errno, ast_udptl::far_max_datagram, ast_udptl::far_max_ifp, ast_udptl::fd, ast_frame::frametype, len(), LOG_NOTICE, LOG_TAG, LOG_WARNING, ast_frame::ptr, seq, ast_frame::subclass, ast_udptl::them, ast_udptl::tx_seq_no, udptl_build_packet(), and udptl_debug_test_addr().
Referenced by sip_write().
01056 { 01057 unsigned int seq; 01058 unsigned int len = f->datalen; 01059 int res; 01060 /* if no max datagram size is provided, use default value */ 01061 const int bufsize = (s->far_max_datagram > 0) ? s->far_max_datagram : DEFAULT_FAX_MAX_DATAGRAM; 01062 uint8_t buf[bufsize]; 01063 01064 memset(buf, 0, sizeof(buf)); 01065 01066 /* If we have no peer, return immediately */ 01067 if (ast_sockaddr_isnull(&s->them)) { 01068 return 0; 01069 } 01070 01071 /* If there is no data length, return immediately */ 01072 if (f->datalen == 0) 01073 return 0; 01074 01075 if ((f->frametype != AST_FRAME_MODEM) || 01076 (f->subclass.codec != AST_MODEM_T38)) { 01077 ast_log(LOG_WARNING, "UDPTL (%s): UDPTL can only send T.38 data.\n", 01078 LOG_TAG(s)); 01079 return -1; 01080 } 01081 01082 if (len > s->far_max_ifp) { 01083 ast_log(LOG_WARNING, 01084 "UDPTL (%s): UDPTL asked to send %u bytes of IFP when far end only prepared to accept %d bytes; data loss will occur." 01085 "You may need to override the T38FaxMaxDatagram value for this endpoint in the channel driver configuration.\n", 01086 LOG_TAG(s), len, s->far_max_ifp); 01087 len = s->far_max_ifp; 01088 } 01089 01090 /* Save seq_no for debug output because udptl_build_packet increments it */ 01091 seq = s->tx_seq_no & 0xFFFF; 01092 01093 /* Cook up the UDPTL packet, with the relevant EC info. */ 01094 len = udptl_build_packet(s, buf, sizeof(buf), f->data.ptr, len); 01095 01096 if ((signed int) len > 0 && !ast_sockaddr_isnull(&s->them)) { 01097 if ((res = ast_sendto(s->fd, buf, len, 0, &s->them)) < 0) 01098 ast_log(LOG_NOTICE, "UDPTL (%s): Transmission error to %s: %s\n", 01099 LOG_TAG(s), ast_sockaddr_stringify(&s->them), strerror(errno)); 01100 if (udptl_debug_test_addr(&s->them)) 01101 ast_verb(1, "UDPTL (%s): packet to %s (seq %u, len %u)\n", 01102 LOG_TAG(s), ast_sockaddr_stringify(&s->them), seq, len); 01103 } 01104 01105 return 0; 01106 }