#include "asterisk.h"
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <net/if.h>
#include <errno.h>
#include <stdlib.h>
#include <fcntl.h>
#include <netdb.h>
#include <sys/signal.h>
#include <signal.h>
#include <netinet/in.h>
#include <netinet/in_systm.h>
#include <netinet/ip.h>
#include <arpa/inet.h>
#include <ctype.h>
#include "asterisk/lock.h"
#include "asterisk/channel.h"
#include "asterisk/config.h"
#include "asterisk/logger.h"
#include "asterisk/module.h"
#include "asterisk/pbx.h"
#include "asterisk/options.h"
#include "asterisk/sched.h"
#include "asterisk/io.h"
#include "asterisk/rtp.h"
#include "asterisk/acl.h"
#include "asterisk/callerid.h"
#include "asterisk/cli.h"
#include "asterisk/say.h"
#include "asterisk/cdr.h"
#include "asterisk/astdb.h"
#include "asterisk/features.h"
#include "asterisk/app.h"
#include "asterisk/musiconhold.h"
#include "asterisk/utils.h"
#include "asterisk/causes.h"
#include "asterisk/dsp.h"
#include "asterisk/devicestate.h"
#include "asterisk/stringfields.h"
#include "asterisk/abstract_jb.h"
Include dependency graph for chan_mgcp.c:
Go to the source code of this file.
Data Structures | |
struct | mgcp_endpoint |
struct | mgcp_gateway |
struct | mgcp_message |
mgcp_message: MGCP message for queuing up More... | |
struct | mgcp_request |
struct | mgcp_response |
struct | mgcp_subchannel |
Defines | |
#define | CANREINVITE 1 |
#define | DEFAULT_EXPIRY 120 |
#define | DEFAULT_MGCP_CA_PORT 2727 |
#define | DEFAULT_MGCP_GW_PORT 2427 |
#define | DEFAULT_RETRANS 1000 |
#define | INADDR_NONE (in_addr_t)(-1) |
#define | IPTOS_MINCOST 0x02 |
#define | MAX_EXPIRY 3600 |
#define | MAX_RETRANS 5 |
#define | MAX_SUBS 2 |
#define | MGCP_CX_CONF 3 |
#define | MGCP_CX_CONFERENCE 3 |
#define | MGCP_CX_INACTIVE 4 |
#define | MGCP_CX_MUTE 4 |
#define | MGCP_CX_RECVONLY 1 |
#define | MGCP_CX_SENDONLY 0 |
#define | MGCP_CX_SENDRECV 2 |
#define | MGCP_DTMF_HYBRID (1 << 2) |
#define | MGCP_DTMF_INBAND (1 << 1) |
#define | MGCP_DTMF_RFC2833 (1 << 0) |
#define | MGCP_MAX_HEADERS 64 |
#define | MGCP_MAX_LINES 64 |
#define | MGCP_MAX_PACKET 1500 |
#define | MGCP_OFFHOOK 2 |
#define | MGCP_ONHOOK 1 |
#define | MGCP_SUBCHANNEL_MAGIC "!978!" |
#define | MGCPDUMPER |
#define | RESPONSE_TIMEOUT 30 |
#define | SUB_ALT 1 |
#define | SUB_REAL 0 |
#define | TYPE_LINE 2 |
#define | TYPE_TRUNK 1 |
Enumerations | |
enum | { MGCP_CMD_EPCF, MGCP_CMD_CRCX, MGCP_CMD_MDCX, MGCP_CMD_DLCX, MGCP_CMD_RQNT, MGCP_CMD_NTFY, MGCP_CMD_AUEP, MGCP_CMD_AUCX, MGCP_CMD_RSIP } |
Functions | |
static char * | __get_header (struct mgcp_request *req, char *name, int *start) |
static int | __mgcp_xmit (struct mgcp_gateway *gw, char *data, int len) |
static int | add_header (struct mgcp_request *req, char *var, char *value) |
static int | add_line (struct mgcp_request *req, char *line) |
static int | add_sdp (struct mgcp_request *resp, struct mgcp_subchannel *sub, struct ast_rtp *rtp) |
AST_MODULE_INFO (ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT,"Media Gateway Control Protocol (MGCP)",.load=load_module,.unload=unload_module,.reload=reload,) | |
AST_MUTEX_DEFINE_STATIC (gatelock) | |
gatelock: mutex for gateway/endpoint lists | |
AST_MUTEX_DEFINE_STATIC (mgcp_reload_lock) | |
AST_MUTEX_DEFINE_STATIC (monlock) | |
AST_MUTEX_DEFINE_STATIC (netlock) | |
static int | attempt_transfer (struct mgcp_endpoint *p) |
static struct mgcp_gateway * | build_gateway (char *cat, struct ast_variable *v) |
build_gateway: parse mgcp.conf and create gateway/endpoint structures | |
static char * | control2str (int ind) |
static void | destroy_endpoint (struct mgcp_endpoint *e) |
static void | destroy_gateway (struct mgcp_gateway *g) |
static void * | do_monitor (void *data) |
static void | dump_cmd_queues (struct mgcp_endpoint *p, struct mgcp_subchannel *sub) |
dump_cmd_queues: (SC:) cleanup pending commands | |
static void | dump_queue (struct mgcp_gateway *gw, struct mgcp_endpoint *p) |
static int | find_and_retrans (struct mgcp_subchannel *sub, struct mgcp_request *req) |
static struct mgcp_request * | find_command (struct mgcp_endpoint *p, struct mgcp_subchannel *sub, struct mgcp_request **queue, ast_mutex_t *l, int ident) |
find_command: (SC:) remove command transaction from queue | |
static struct mgcp_subchannel * | find_subchannel_and_lock (char *name, int msgid, struct sockaddr_in *sin) |
static char * | get_csv (char *c, int *len, char **next) |
get_csv: (SC:) get comma separated value | |
static char * | get_header (struct mgcp_request *req, char *name) |
static char * | get_sdp (struct mgcp_request *req, char *name) |
static char * | get_sdp_by_line (char *line, char *name, int nameLen) |
static char * | get_sdp_iterate (int *iterator, struct mgcp_request *req, char *name) |
static void | handle_hd_hf (struct mgcp_subchannel *sub, char *ev) |
static int | handle_request (struct mgcp_subchannel *sub, struct mgcp_request *req, struct sockaddr_in *sin) |
static void | handle_response (struct mgcp_endpoint *p, struct mgcp_subchannel *sub, int result, unsigned int ident, struct mgcp_request *resp) |
static int | has_voicemail (struct mgcp_endpoint *p) |
static int | init_req (struct mgcp_endpoint *p, struct mgcp_request *req, char *verb) |
static int | init_resp (struct mgcp_request *req, char *resp, struct mgcp_request *orig, char *resprest) |
static int | load_module (void) |
load_module: PBX load module - initialization --- | |
static int | mgcp_answer (struct ast_channel *ast) |
static int | mgcp_audit_endpoint (int fd, int argc, char *argv[]) |
static int | mgcp_call (struct ast_channel *ast, char *dest, int timeout) |
static int | mgcp_devicestate (void *data) |
mgcp_devicestate: channel callback for device status monitoring | |
static int | mgcp_do_debug (int fd, int argc, char *argv[]) |
static int | mgcp_do_reload (void) |
mgcp_do_reload: Reload module | |
static int | mgcp_fixup (struct ast_channel *oldchan, struct ast_channel *newchan) |
static enum ast_rtp_get_result | mgcp_get_rtp_peer (struct ast_channel *chan, struct ast_rtp **rtp) |
static int | mgcp_hangup (struct ast_channel *ast) |
static int | mgcp_indicate (struct ast_channel *ast, int ind, const void *data, size_t datalen) |
static struct ast_channel * | mgcp_new (struct mgcp_subchannel *sub, int state) |
static int | mgcp_no_debug (int fd, int argc, char *argv[]) |
static int | mgcp_postrequest (struct mgcp_endpoint *p, struct mgcp_subchannel *sub, char *data, int len, unsigned int seqno) |
static void | mgcp_queue_control (struct mgcp_subchannel *sub, int control) |
static void | mgcp_queue_frame (struct mgcp_subchannel *sub, struct ast_frame *f) |
static void | mgcp_queue_hangup (struct mgcp_subchannel *sub) |
static struct ast_frame * | mgcp_read (struct ast_channel *ast) |
static int | mgcp_reload (int fd, int argc, char *argv[]) |
static struct ast_channel * | mgcp_request (const char *type, int format, void *data, int *cause) |
static struct ast_frame * | mgcp_rtp_read (struct mgcp_subchannel *sub) |
static int | mgcp_senddigit_begin (struct ast_channel *ast, char digit) |
static int | mgcp_senddigit_end (struct ast_channel *ast, char digit, unsigned int duration) |
static int | mgcp_set_rtp_peer (struct ast_channel *chan, struct ast_rtp *rtp, struct ast_rtp *vrtp, int codecs, int nat_active) |
static int | mgcp_show_endpoints (int fd, int argc, char *argv[]) |
static void * | mgcp_ss (void *data) |
static int | mgcp_write (struct ast_channel *ast, struct ast_frame *frame) |
static int | mgcpsock_read (int *id, int fd, short events, void *ignore) |
static void | parse (struct mgcp_request *req) |
static int | process_sdp (struct mgcp_subchannel *sub, struct mgcp_request *req) |
static void | prune_gateways (void) |
static int | reload (void) |
static int | reload_config (void) |
static int | reqprep (struct mgcp_request *req, struct mgcp_endpoint *p, char *verb) |
static int | resend_response (struct mgcp_subchannel *sub, struct mgcp_response *resp) |
static int | respprep (struct mgcp_request *resp, struct mgcp_endpoint *p, char *msg, struct mgcp_request *req, char *msgrest) |
static int | restart_monitor (void) |
static int | retrans_pkt (void *data) |
static void | sdpLineNum_iterator_init (int *iterator) |
static int | send_request (struct mgcp_endpoint *p, struct mgcp_subchannel *sub, struct mgcp_request *req, unsigned int seqno) |
static int | send_response (struct mgcp_subchannel *sub, struct mgcp_request *req) |
static void | start_rtp (struct mgcp_subchannel *sub) |
static int | transmit_audit_endpoint (struct mgcp_endpoint *p) |
static int | transmit_connect_with_sdp (struct mgcp_subchannel *sub, struct ast_rtp *rtp) |
static int | transmit_connection_del (struct mgcp_subchannel *sub) |
static int | transmit_connection_del_w_params (struct mgcp_endpoint *p, char *callid, char *cxident) |
static int | transmit_modify_request (struct mgcp_subchannel *sub) |
static int | transmit_modify_with_sdp (struct mgcp_subchannel *sub, struct ast_rtp *rtp, int codecs) |
static int | transmit_notify_request (struct mgcp_subchannel *sub, char *tone) |
static int | transmit_notify_request_with_callerid (struct mgcp_subchannel *sub, char *tone, char *callernum, char *callername) |
static int | transmit_response (struct mgcp_subchannel *sub, char *msg, struct mgcp_request *req, char *msgrest) |
static int | unalloc_sub (struct mgcp_subchannel *sub) |
static int | unload_module (void) |
Variables | |
static struct in_addr | __ourip |
static char | accountcode [AST_MAX_ACCOUNT_CODE] = "" |
static int | adsi = 0 |
static int | amaflags = 0 |
static char | audit_endpoint_usage [] |
static struct sockaddr_in | bindaddr |
static int | callreturn = 0 |
static int | callwaiting = 0 |
static int | cancallforward = 0 |
static int | canreinvite = CANREINVITE |
static int | capability = AST_FORMAT_ULAW |
static char | cid_name [AST_MAX_EXTENSION] = "" |
static char | cid_num [AST_MAX_EXTENSION] = "" |
static struct ast_cli_entry | cli_mgcp [] |
static const char | config [] = "mgcp.conf" |
static char | context [AST_MAX_EXTENSION] = "default" |
static ast_group_t | cur_callergroup = 0 |
static ast_group_t | cur_pickupgroup = 0 |
static char | debug_usage [] |
static struct ast_jb_conf | default_jbconf |
static int | dtmfmode = 0 |
static int | firstdigittimeout = 16000 |
static struct mgcp_gateway * | gateways |
static int | gendigittimeout = 8000 |
static struct ast_jb_conf | global_jbconf |
static int | immediate = 0 |
static struct io_context * | io |
static char | language [MAX_LANGUAGE] = "" |
static char | mailbox [AST_MAX_EXTENSION] |
static int | matchdigittimeout = 3000 |
static char * | mgcp_cxmodes [] |
static char | mgcp_reload_usage [] |
static int | mgcp_reloading = 0 |
static struct ast_rtp_protocol | mgcp_rtp |
static struct ast_channel_tech | mgcp_tech |
static int | mgcpdebug = 0 |
static int | mgcpsock = -1 |
static int * | mgcpsock_read_id = NULL |
static pthread_t | monitor_thread = AST_PTHREADT_NULL |
static char | musicclass [MAX_MUSICCLASS] = "" |
static int | nat = 0 |
static char | no_debug_usage [] |
static int | nonCodecCapability = AST_RTP_DTMF |
static unsigned int | oseq |
static char | ourhost [MAXHOSTNAMELEN] |
static int | ourport |
static struct sched_context * | sched |
static char | show_endpoints_usage [] |
static int | singlepath = 0 |
static int | slowsequence = 0 |
static const char | tdesc [] = "Media Gateway Control Protocol (MGCP)" |
static int | threewaycalling = 0 |
static int | tos = 0 |
static int | transfer = 0 |
Definition in file chan_mgcp.c.
#define CANREINVITE 1 |
#define DEFAULT_EXPIRY 120 |
#define DEFAULT_MGCP_CA_PORT 2727 |
#define DEFAULT_MGCP_GW_PORT 2427 |
#define DEFAULT_RETRANS 1000 |
How frequently to retransmit
Definition at line 119 of file chan_mgcp.c.
Referenced by __sip_reliable_xmit(), mgcp_postrequest(), and retrans_pkt().
#define INADDR_NONE (in_addr_t)(-1) |
#define IPTOS_MINCOST 0x02 |
Definition at line 81 of file chan_mgcp.c.
#define MAX_EXPIRY 3600 |
Definition at line 92 of file chan_mgcp.c.
#define MAX_RETRANS 5 |
Try only 5 times for retransmissions
Definition at line 120 of file chan_mgcp.c.
Referenced by retrans_pkt().
#define MAX_SUBS 2 |
#define MGCP_CX_CONF 3 |
#define MGCP_CX_CONFERENCE 3 |
Definition at line 127 of file chan_mgcp.c.
#define MGCP_CX_INACTIVE 4 |
Definition at line 129 of file chan_mgcp.c.
Referenced by build_gateway(), mgcp_hangup(), and unalloc_sub().
#define MGCP_CX_MUTE 4 |
#define MGCP_CX_RECVONLY 1 |
Definition at line 124 of file chan_mgcp.c.
Referenced by handle_request(), mgcp_call(), and mgcp_hangup().
#define MGCP_CX_SENDONLY 0 |
MGCP rtp stream modes {
Definition at line 123 of file chan_mgcp.c.
#define MGCP_CX_SENDRECV 2 |
Definition at line 125 of file chan_mgcp.c.
Referenced by handle_hd_hf(), handle_request(), mgcp_answer(), and mgcp_call().
#define MGCP_DTMF_HYBRID (1 << 2) |
Definition at line 114 of file chan_mgcp.c.
Referenced by build_gateway(), mgcp_hangup(), mgcp_new(), and mgcp_ss().
#define MGCP_DTMF_INBAND (1 << 1) |
Definition at line 113 of file chan_mgcp.c.
Referenced by build_gateway(), mgcp_hangup(), mgcp_new(), mgcp_rtp_read(), mgcp_ss(), transmit_modify_request(), transmit_notify_request(), and transmit_notify_request_with_callerid().
#define MGCP_DTMF_RFC2833 (1 << 0) |
#define MGCP_MAX_HEADERS 64 |
The private structures of the mgcp channels are linked for ! selecting outgoing channels
Definition at line 231 of file chan_mgcp.c.
Referenced by add_header(), init_req(), init_resp(), and parse().
#define MGCP_MAX_LINES 64 |
#define MGCP_MAX_PACKET 1500 |
Also from RFC 2543, should sub headers tho
Definition at line 118 of file chan_mgcp.c.
#define MGCP_OFFHOOK 2 |
Definition at line 306 of file chan_mgcp.c.
Referenced by handle_hd_hf(), handle_request(), handle_response(), mgcp_call(), mgcp_hangup(), transmit_modify_request(), transmit_notify_request(), and transmit_notify_request_with_callerid().
#define MGCP_ONHOOK 1 |
Definition at line 305 of file chan_mgcp.c.
Referenced by build_gateway(), do_monitor(), handle_request(), handle_response(), mgcp_call(), mgcp_hangup(), mgcp_request(), transmit_modify_request(), transmit_notify_request(), and transmit_notify_request_with_callerid().
#define MGCP_SUBCHANNEL_MAGIC "!978!" |
subchannel magic string. Needed to prove that any subchannel pointer passed by asterisk really points to a valid subchannel memory area. Ugly.. But serves the purpose for the time being.
Definition at line 283 of file chan_mgcp.c.
Referenced by build_gateway(), and mgcp_hangup().
#define MGCPDUMPER |
Definition at line 90 of file chan_mgcp.c.
#define RESPONSE_TIMEOUT 30 |
#define SUB_ALT 1 |
Definition at line 275 of file chan_mgcp.c.
#define SUB_REAL 0 |
Definition at line 274 of file chan_mgcp.c.
#define TYPE_LINE 2 |
Definition at line 309 of file chan_mgcp.c.
Referenced by build_device(), build_gateway(), do_monitor(), mgcp_call(), and skinny_hangup().
#define TYPE_TRUNK 1 |
anonymous enum |
MGCP_CMD_EPCF | |
MGCP_CMD_CRCX | |
MGCP_CMD_MDCX | |
MGCP_CMD_DLCX | |
MGCP_CMD_RQNT | |
MGCP_CMD_NTFY | |
MGCP_CMD_AUEP | |
MGCP_CMD_AUCX | |
MGCP_CMD_RSIP |
Definition at line 140 of file chan_mgcp.c.
00140 { 00141 MGCP_CMD_EPCF, 00142 MGCP_CMD_CRCX, 00143 MGCP_CMD_MDCX, 00144 MGCP_CMD_DLCX, 00145 MGCP_CMD_RQNT, 00146 MGCP_CMD_NTFY, 00147 MGCP_CMD_AUEP, 00148 MGCP_CMD_AUCX, 00149 MGCP_CMD_RSIP 00150 };
static char* __get_header | ( | struct mgcp_request * | req, | |
char * | name, | |||
int * | start | |||
) | [static] |
Definition at line 1537 of file chan_mgcp.c.
References mgcp_request::header, mgcp_request::headers, and len.
Referenced by build_route(), copy_all_header(), copy_via_headers(), func_header_read(), get_header(), and handle_response_register().
01538 { 01539 int x; 01540 int len = strlen(name); 01541 char *r; 01542 for (x=*start;x<req->headers;x++) { 01543 if (!strncasecmp(req->header[x], name, len) && 01544 (req->header[x][len] == ':')) { 01545 r = req->header[x] + len + 1; 01546 while(*r && (*r < 33)) 01547 r++; 01548 *start = x+1; 01549 return r; 01550 } 01551 } 01552 /* Don't return NULL, so get_header is always a valid pointer */ 01553 return ""; 01554 }
static int __mgcp_xmit | ( | struct mgcp_gateway * | gw, | |
char * | data, | |||
int | len | |||
) | [static] |
Definition at line 486 of file chan_mgcp.c.
References mgcp_gateway::addr, ast_log(), mgcp_gateway::defaddr, and LOG_WARNING.
Referenced by mgcp_postrequest(), resend_response(), retrans_pkt(), and send_response().
00487 { 00488 int res; 00489 if (gw->addr.sin_addr.s_addr) 00490 res=sendto(mgcpsock, data, len, 0, (struct sockaddr *)&gw->addr, sizeof(struct sockaddr_in)); 00491 else 00492 res=sendto(mgcpsock, data, len, 0, (struct sockaddr *)&gw->defaddr, sizeof(struct sockaddr_in)); 00493 if (res != len) { 00494 ast_log(LOG_WARNING, "mgcp_xmit returned %d: %s\n", res, strerror(errno)); 00495 } 00496 return res; 00497 }
static int add_header | ( | struct mgcp_request * | req, | |
char * | var, | |||
char * | value | |||
) | [static] |
Definition at line 1887 of file chan_mgcp.c.
References ast_log(), mgcp_request::data, mgcp_request::header, mgcp_request::headers, mgcp_request::len, mgcp_request::lines, LOG_WARNING, and MGCP_MAX_HEADERS.
Referenced by __transmit_response(), add_digit(), add_header_contentLength(), add_route(), add_sdp(), add_t38_sdp(), add_text(), add_vidupdate(), append_date(), copy_all_header(), copy_header(), copy_via_headers(), initreqprep(), reqprep(), respprep(), sip_notify(), transmit_audit_endpoint(), transmit_connection_del(), transmit_connection_del_w_params(), transmit_invite(), transmit_modify_request(), transmit_notify_request(), transmit_notify_request_with_callerid(), transmit_notify_with_mwi(), transmit_notify_with_sipfrag(), transmit_refer(), transmit_register(), transmit_reinvite_with_sdp(), transmit_reinvite_with_t38_sdp(), transmit_request_with_auth(), transmit_response_with_allow(), transmit_response_with_auth(), transmit_response_with_unsupported(), and transmit_state_notify().
01888 { 01889 if (req->len >= sizeof(req->data) - 4) { 01890 ast_log(LOG_WARNING, "Out of space, can't add anymore\n"); 01891 return -1; 01892 } 01893 if (req->lines) { 01894 ast_log(LOG_WARNING, "Can't add more headers when lines have been added\n"); 01895 return -1; 01896 } 01897 req->header[req->headers] = req->data + req->len; 01898 snprintf(req->header[req->headers], sizeof(req->data) - req->len, "%s: %s\r\n", var, value); 01899 req->len += strlen(req->header[req->headers]); 01900 if (req->headers < MGCP_MAX_HEADERS) 01901 req->headers++; 01902 else { 01903 ast_log(LOG_WARNING, "Out of header space\n"); 01904 return -1; 01905 } 01906 return 0; 01907 }
static int add_line | ( | struct mgcp_request * | req, | |
char * | line | |||
) | [static] |
Definition at line 1909 of file chan_mgcp.c.
References ast_log(), mgcp_request::data, mgcp_request::len, mgcp_request::line, mgcp_request::lines, LOG_WARNING, and MGCP_MAX_LINES.
Referenced by add_digit(), add_sdp(), add_t38_sdp(), add_text(), add_vidupdate(), transmit_notify_with_mwi(), transmit_notify_with_sipfrag(), and transmit_state_notify().
01910 { 01911 if (req->len >= sizeof(req->data) - 4) { 01912 ast_log(LOG_WARNING, "Out of space, can't add anymore\n"); 01913 return -1; 01914 } 01915 if (!req->lines) { 01916 /* Add extra empty return */ 01917 snprintf(req->data + req->len, sizeof(req->data) - req->len, "\r\n"); 01918 req->len += strlen(req->data + req->len); 01919 } 01920 req->line[req->lines] = req->data + req->len; 01921 snprintf(req->line[req->lines], sizeof(req->data) - req->len, "%s", line); 01922 req->len += strlen(req->line[req->lines]); 01923 if (req->lines < MGCP_MAX_LINES) 01924 req->lines++; 01925 else { 01926 ast_log(LOG_WARNING, "Out of line space\n"); 01927 return -1; 01928 } 01929 return 0; 01930 }
static int add_sdp | ( | struct mgcp_request * | resp, | |
struct mgcp_subchannel * | sub, | |||
struct ast_rtp * | rtp | |||
) | [static] |
Definition at line 2011 of file chan_mgcp.c.
References AST_FORMAT_MAX_AUDIO, ast_inet_ntoa(), ast_log(), ast_rtp_get_peer(), ast_rtp_get_us(), ast_rtp_lookup_code(), ast_rtp_lookup_mime_subtype(), ast_verbose(), mgcp_endpoint::capability, len, LOG_WARNING, mgcpdebug, mgcp_gateway::ourip, mgcp_endpoint::parent, mgcp_subchannel::parent, mgcp_subchannel::rtp, s, mgcp_endpoint::sub, t, and mgcp_subchannel::tmpdest.
Referenced by transmit_invite(), transmit_reinvite_with_sdp(), and transmit_response_with_sdp().
02012 { 02013 int len; 02014 int codec; 02015 char costr[80]; 02016 struct sockaddr_in sin; 02017 char v[256]; 02018 char s[256]; 02019 char o[256]; 02020 char c[256]; 02021 char t[256]; 02022 char m[256] = ""; 02023 char a[1024] = ""; 02024 int x; 02025 struct sockaddr_in dest; 02026 struct mgcp_endpoint *p = sub->parent; 02027 /* XXX We break with the "recommendation" and send our IP, in order that our 02028 peer doesn't have to ast_gethostbyname() us XXX */ 02029 len = 0; 02030 if (!sub->rtp) { 02031 ast_log(LOG_WARNING, "No way to add SDP without an RTP structure\n"); 02032 return -1; 02033 } 02034 ast_rtp_get_us(sub->rtp, &sin); 02035 if (rtp) { 02036 ast_rtp_get_peer(rtp, &dest); 02037 } else { 02038 if (sub->tmpdest.sin_addr.s_addr) { 02039 dest.sin_addr = sub->tmpdest.sin_addr; 02040 dest.sin_port = sub->tmpdest.sin_port; 02041 /* Reset temporary destination */ 02042 memset(&sub->tmpdest, 0, sizeof(sub->tmpdest)); 02043 } else { 02044 dest.sin_addr = p->parent->ourip; 02045 dest.sin_port = sin.sin_port; 02046 } 02047 } 02048 if (mgcpdebug) { 02049 ast_verbose("We're at %s port %d\n", ast_inet_ntoa(p->parent->ourip), ntohs(sin.sin_port)); 02050 } 02051 snprintf(v, sizeof(v), "v=0\r\n"); 02052 snprintf(o, sizeof(o), "o=root %d %d IN IP4 %s\r\n", getpid(), getpid(), ast_inet_ntoa(dest.sin_addr)); 02053 snprintf(s, sizeof(s), "s=session\r\n"); 02054 snprintf(c, sizeof(c), "c=IN IP4 %s\r\n", ast_inet_ntoa(dest.sin_addr)); 02055 snprintf(t, sizeof(t), "t=0 0\r\n"); 02056 snprintf(m, sizeof(m), "m=audio %d RTP/AVP", ntohs(dest.sin_port)); 02057 for (x = 1; x <= AST_FORMAT_MAX_AUDIO; x <<= 1) { 02058 if (p->capability & x) { 02059 if (mgcpdebug) { 02060 ast_verbose("Answering with capability %d\n", x); 02061 } 02062 codec = ast_rtp_lookup_code(sub->rtp, 1, x); 02063 if (codec > -1) { 02064 snprintf(costr, sizeof(costr), " %d", codec); 02065 strncat(m, costr, sizeof(m) - strlen(m) - 1); 02066 snprintf(costr, sizeof(costr), "a=rtpmap:%d %s/8000\r\n", codec, ast_rtp_lookup_mime_subtype(1, x, 0)); 02067 strncat(a, costr, sizeof(a) - strlen(a) - 1); 02068 } 02069 } 02070 } 02071 for (x = 1; x <= AST_RTP_MAX; x <<= 1) { 02072 if (p->nonCodecCapability & x) { 02073 if (mgcpdebug) { 02074 ast_verbose("Answering with non-codec capability %d\n", x); 02075 } 02076 codec = ast_rtp_lookup_code(sub->rtp, 0, x); 02077 if (codec > -1) { 02078 snprintf(costr, sizeof(costr), " %d", codec); 02079 strncat(m, costr, sizeof(m) - strlen(m) - 1); 02080 snprintf(costr, sizeof(costr), "a=rtpmap:%d %s/8000\r\n", codec, ast_rtp_lookup_mime_subtype(0, x, 0)); 02081 strncat(a, costr, sizeof(a) - strlen(a) - 1); 02082 if (x == AST_RTP_DTMF) { 02083 /* Indicate we support DTMF... Not sure about 16, 02084 but MSN supports it so dang it, we will too... */ 02085 snprintf(costr, sizeof costr, "a=fmtp:%d 0-16\r\n", codec); 02086 strncat(a, costr, sizeof(a) - strlen(a) - 1); 02087 } 02088 } 02089 } 02090 } 02091 strncat(m, "\r\n", sizeof(m) - strlen(m) - 1); 02092 len = strlen(v) + strlen(s) + strlen(o) + strlen(c) + strlen(t) + strlen(m) + strlen(a); 02093 snprintf(costr, sizeof(costr), "%d", len); 02094 add_line(resp, v); 02095 add_line(resp, o); 02096 add_line(resp, s); 02097 add_line(resp, c); 02098 add_line(resp, t); 02099 add_line(resp, m); 02100 add_line(resp, a); 02101 return 0; 02102 }
AST_MODULE_INFO | ( | ASTERISK_GPL_KEY | , | |
AST_MODFLAG_DEFAULT | , | |||
"Media Gateway Control Protocol (MGCP)" | , | |||
. | load = load_module , |
|||
. | unload = unload_module , |
|||
. | reload = reload | |||
) |
AST_MUTEX_DEFINE_STATIC | ( | gatelock | ) |
gatelock: mutex for gateway/endpoint lists
AST_MUTEX_DEFINE_STATIC | ( | mgcp_reload_lock | ) |
AST_MUTEX_DEFINE_STATIC | ( | monlock | ) |
AST_MUTEX_DEFINE_STATIC | ( | netlock | ) |
Protect the monitoring thread, so only one process can kill or start it, and not when it's doing something critical.
static int attempt_transfer | ( | struct mgcp_endpoint * | p | ) | [static] |
Definition at line 2859 of file chan_mgcp.c.
References ast_channel::_softhangup, ast_channel::_state, mgcp_subchannel::alreadygone, ast_bridged_channel(), ast_channel_masquerade(), AST_CONTROL_RINGING, AST_CONTROL_UNHOLD, ast_indicate(), ast_log(), ast_queue_control(), AST_SOFTHANGUP_DEV, AST_STATE_RINGING, ast_verbose(), mgcp_subchannel::id, LOG_DEBUG, LOG_WARNING, mgcp_queue_hangup(), mgcp_gateway::name, mgcp_endpoint::name, mgcp_subchannel::next, option_verbose, mgcp_subchannel::owner, mgcp_endpoint::parent, mgcp_endpoint::sub, unalloc_sub(), and VERBOSE_PREFIX_3.
Referenced by handle_onhook_message(), handle_request(), handle_soft_key_event_message(), local_attended_transfer(), and zt_handle_event().
02860 { 02861 /* ************************* 02862 * I hope this works. 02863 * Copied out of chan_zap 02864 * Cross your fingers 02865 * *************************/ 02866 02867 /* In order to transfer, we need at least one of the channels to 02868 actually be in a call bridge. We can't conference two applications 02869 together (but then, why would we want to?) */ 02870 if (ast_bridged_channel(p->sub->owner)) { 02871 /* The three-way person we're about to transfer to could still be in MOH, so 02872 stop if now if appropriate */ 02873 if (ast_bridged_channel(p->sub->next->owner)) 02874 ast_queue_control(p->sub->next->owner, AST_CONTROL_UNHOLD); 02875 if (p->sub->owner->_state == AST_STATE_RINGING) { 02876 ast_indicate(ast_bridged_channel(p->sub->next->owner), AST_CONTROL_RINGING); 02877 } 02878 if (ast_channel_masquerade(p->sub->next->owner, ast_bridged_channel(p->sub->owner))) { 02879 ast_log(LOG_WARNING, "Unable to masquerade %s as %s\n", 02880 ast_bridged_channel(p->sub->owner)->name, p->sub->next->owner->name); 02881 return -1; 02882 } 02883 /* Orphan the channel */ 02884 unalloc_sub(p->sub->next); 02885 } else if (ast_bridged_channel(p->sub->next->owner)) { 02886 if (p->sub->owner->_state == AST_STATE_RINGING) { 02887 ast_indicate(ast_bridged_channel(p->sub->next->owner), AST_CONTROL_RINGING); 02888 } 02889 ast_queue_control(p->sub->next->owner, AST_CONTROL_UNHOLD); 02890 if (ast_channel_masquerade(p->sub->owner, ast_bridged_channel(p->sub->next->owner))) { 02891 ast_log(LOG_WARNING, "Unable to masquerade %s as %s\n", 02892 ast_bridged_channel(p->sub->next->owner)->name, p->sub->owner->name); 02893 return -1; 02894 } 02895 /*swap_subs(p, SUB_THREEWAY, SUB_REAL);*/ 02896 if (option_verbose > 2) { 02897 ast_verbose(VERBOSE_PREFIX_3 "Swapping %d for %d on %s@%s\n", p->sub->id, p->sub->next->id, p->name, p->parent->name); 02898 } 02899 p->sub = p->sub->next; 02900 unalloc_sub(p->sub->next); 02901 /* Tell the caller not to hangup */ 02902 return 1; 02903 } else { 02904 ast_log(LOG_DEBUG, "Neither %s nor %s are in a bridge, nothing to transfer\n", 02905 p->sub->owner->name, p->sub->next->owner->name); 02906 p->sub->next->owner->_softhangup |= AST_SOFTHANGUP_DEV; 02907 if (p->sub->next->owner) { 02908 p->sub->next->alreadygone = 1; 02909 mgcp_queue_hangup(p->sub->next); 02910 } 02911 } 02912 return 0; 02913 }
static struct mgcp_gateway* build_gateway | ( | char * | cat, | |
struct ast_variable * | v | |||
) | [static] |
build_gateway: parse mgcp.conf and create gateway/endpoint structures
Definition at line 3555 of file chan_mgcp.c.
References __ourip, mgcp_endpoint::accountcode, accountcode, mgcp_gateway::addr, mgcp_endpoint::adsi, adsi, mgcp_endpoint::amaflags, amaflags, ast_append_ha(), ast_callerid_split(), ast_cdr_amaflags2int(), ast_get_group(), ast_get_ip(), ast_log(), ast_mutex_destroy(), ast_mutex_init(), ast_ouraddrfor(), ast_random(), ast_sched_del(), ast_strlen_zero(), ast_true(), ast_verbose(), mgcp_endpoint::callgroup, mgcp_endpoint::callreturn, callreturn, mgcp_endpoint::callwaiting, callwaiting, mgcp_endpoint::cancallforward, cancallforward, mgcp_endpoint::canreinvite, CANREINVITE, canreinvite, capability, mgcp_endpoint::capability, mgcp_endpoint::cid_name, cid_name, mgcp_endpoint::cid_num, cid_num, mgcp_endpoint::context, context, cur_callergroup, cur_pickupgroup, mgcp_subchannel::cx_queue_lock, mgcp_subchannel::cxmode, mgcp_gateway::defaddr, DEFAULT_MGCP_GW_PORT, mgcp_endpoint::delme, mgcp_gateway::delme, mgcp_endpoint::dtmfmode, dtmfmode, mgcp_gateway::dynamic, mgcp_gateway::endpoints, mgcp_gateway::expire, free, gateways, mgcp_gateway::ha, mgcp_endpoint::hascallwaiting, mgcp_endpoint::hookstate, mgcp_subchannel::id, mgcp_endpoint::immediate, immediate, INADDR_NONE, mgcp_endpoint::language, language, ast_variable::lineno, mgcp_subchannel::lock, LOG_WARNING, mgcp_subchannel::magic, mgcp_endpoint::mailbox, mailbox, malloc, MAX_SUBS, MGCP_CX_INACTIVE, MGCP_DTMF_HYBRID, MGCP_DTMF_INBAND, MGCP_DTMF_RFC2833, MGCP_ONHOOK, MGCP_SUBCHANNEL_MAGIC, mgcp_gateway::msgs_lock, mgcp_endpoint::msgstate, mgcp_endpoint::musicclass, musicclass, mgcp_endpoint::name, ast_variable::name, mgcp_gateway::name, mgcp_subchannel::nat, nat, ast_variable::next, mgcp_subchannel::next, mgcp_endpoint::next, mgcp_gateway::next, mgcp_endpoint::onhooktime, mgcp_gateway::ourip, mgcp_subchannel::parent, mgcp_endpoint::parent, mgcp_endpoint::pickupgroup, mgcp_endpoint::rqnt_ident, mgcp_subchannel::rtp, mgcp_endpoint::singlepath, singlepath, mgcp_endpoint::slowsequence, slowsequence, mgcp_endpoint::sub, mgcp_endpoint::threewaycalling, threewaycalling, mgcp_endpoint::transfer, transfer, mgcp_subchannel::txident, mgcp_endpoint::type, TYPE_LINE, TYPE_TRUNK, ast_variable::value, VERBOSE_PREFIX_3, and mgcp_gateway::wcardep.
Referenced by reload_config().
03556 { 03557 struct mgcp_gateway *gw; 03558 struct mgcp_endpoint *e; 03559 struct mgcp_subchannel *sub; 03560 /*char txident[80];*/ 03561 int i=0, y=0; 03562 int gw_reload = 0; 03563 int ep_reload = 0; 03564 canreinvite = CANREINVITE; 03565 03566 /* locate existing gateway */ 03567 gw = gateways; 03568 while (gw) { 03569 if (!strcasecmp(cat, gw->name)) { 03570 /* gateway already exists */ 03571 gw->delme = 0; 03572 gw_reload = 1; 03573 break; 03574 } 03575 gw = gw->next; 03576 } 03577 03578 if (!gw) 03579 gw = malloc(sizeof(struct mgcp_gateway)); 03580 03581 if (gw) { 03582 if (!gw_reload) { 03583 memset(gw, 0, sizeof(struct mgcp_gateway)); 03584 gw->expire = -1; 03585 gw->retransid = -1; /* SC */ 03586 ast_mutex_init(&gw->msgs_lock); 03587 ast_copy_string(gw->name, cat, sizeof(gw->name)); 03588 /* check if the name is numeric ip */ 03589 if ((strchr(gw->name, '.')) && inet_addr(gw->name) != INADDR_NONE) 03590 gw->isnamedottedip = 1; 03591 } 03592 while(v) { 03593 if (!strcasecmp(v->name, "host")) { 03594 if (!strcasecmp(v->value, "dynamic")) { 03595 /* They'll register with us */ 03596 gw->dynamic = 1; 03597 memset(&gw->addr.sin_addr, 0, 4); 03598 if (gw->addr.sin_port) { 03599 /* If we've already got a port, make it the default rather than absolute */ 03600 gw->defaddr.sin_port = gw->addr.sin_port; 03601 gw->addr.sin_port = 0; 03602 } 03603 } else { 03604 /* Non-dynamic. Make sure we become that way if we're not */ 03605 if (gw->expire > -1) 03606 ast_sched_del(sched, gw->expire); 03607 gw->expire = -1; 03608 gw->dynamic = 0; 03609 if (ast_get_ip(&gw->addr, v->value)) { 03610 if (!gw_reload) { 03611 ast_mutex_destroy(&gw->msgs_lock); 03612 free(gw); 03613 } 03614 return NULL; 03615 } 03616 } 03617 } else if (!strcasecmp(v->name, "defaultip")) { 03618 if (ast_get_ip(&gw->defaddr, v->value)) { 03619 if (!gw_reload) { 03620 ast_mutex_destroy(&gw->msgs_lock); 03621 free(gw); 03622 } 03623 return NULL; 03624 } 03625 } else if (!strcasecmp(v->name, "permit") || 03626 !strcasecmp(v->name, "deny")) { 03627 gw->ha = ast_append_ha(v->name, v->value, gw->ha); 03628 } else if (!strcasecmp(v->name, "port")) { 03629 gw->addr.sin_port = htons(atoi(v->value)); 03630 } else if (!strcasecmp(v->name, "context")) { 03631 ast_copy_string(context, v->value, sizeof(context)); 03632 } else if (!strcasecmp(v->name, "dtmfmode")) { 03633 if (!strcasecmp(v->value, "inband")) 03634 dtmfmode = MGCP_DTMF_INBAND; 03635 else if (!strcasecmp(v->value, "rfc2833")) 03636 dtmfmode = MGCP_DTMF_RFC2833; 03637 else if (!strcasecmp(v->value, "hybrid")) 03638 dtmfmode = MGCP_DTMF_HYBRID; 03639 else if (!strcasecmp(v->value, "none")) 03640 dtmfmode = 0; 03641 else 03642 ast_log(LOG_WARNING, "'%s' is not a valid DTMF mode at line %d\n", v->value, v->lineno); 03643 } else if (!strcasecmp(v->name, "nat")) { 03644 nat = ast_true(v->value); 03645 } else if (!strcasecmp(v->name, "callerid")) { 03646 if (!strcasecmp(v->value, "asreceived")) { 03647 cid_num[0] = '\0'; 03648 cid_name[0] = '\0'; 03649 } else { 03650 ast_callerid_split(v->value, cid_name, sizeof(cid_name), cid_num, sizeof(cid_num)); 03651 } 03652 } else if (!strcasecmp(v->name, "language")) { 03653 ast_copy_string(language, v->value, sizeof(language)); 03654 } else if (!strcasecmp(v->name, "accountcode")) { 03655 ast_copy_string(accountcode, v->value, sizeof(accountcode)); 03656 } else if (!strcasecmp(v->name, "amaflags")) { 03657 y = ast_cdr_amaflags2int(v->value); 03658 if (y < 0) { 03659 ast_log(LOG_WARNING, "Invalid AMA flags: %s at line %d\n", v->value, v->lineno); 03660 } else { 03661 amaflags = y; 03662 } 03663 } else if (!strcasecmp(v->name, "musiconhold")) { 03664 ast_copy_string(musicclass, v->value, sizeof(musicclass)); 03665 } else if (!strcasecmp(v->name, "callgroup")) { 03666 cur_callergroup = ast_get_group(v->value); 03667 } else if (!strcasecmp(v->name, "pickupgroup")) { 03668 cur_pickupgroup = ast_get_group(v->value); 03669 } else if (!strcasecmp(v->name, "immediate")) { 03670 immediate = ast_true(v->value); 03671 } else if (!strcasecmp(v->name, "cancallforward")) { 03672 cancallforward = ast_true(v->value); 03673 } else if (!strcasecmp(v->name, "singlepath")) { 03674 singlepath = ast_true(v->value); 03675 } else if (!strcasecmp(v->name, "canreinvite")) { 03676 canreinvite = ast_true(v->value); 03677 } else if (!strcasecmp(v->name, "mailbox")) { 03678 ast_copy_string(mailbox, v->value, sizeof(mailbox)); 03679 } else if (!strcasecmp(v->name, "adsi")) { 03680 adsi = ast_true(v->value); 03681 } else if (!strcasecmp(v->name, "callreturn")) { 03682 callreturn = ast_true(v->value); 03683 } else if (!strcasecmp(v->name, "callwaiting")) { 03684 callwaiting = ast_true(v->value); 03685 } else if (!strcasecmp(v->name, "slowsequence")) { 03686 slowsequence = ast_true(v->value); 03687 } else if (!strcasecmp(v->name, "transfer")) { 03688 transfer = ast_true(v->value); 03689 } else if (!strcasecmp(v->name, "threewaycalling")) { 03690 threewaycalling = ast_true(v->value); 03691 } else if (!strcasecmp(v->name, "wcardep")) { 03692 /* locate existing endpoint */ 03693 e = gw->endpoints; 03694 while (e) { 03695 if (!strcasecmp(v->value, e->name)) { 03696 /* endpoint already exists */ 03697 e->delme = 0; 03698 ep_reload = 1; 03699 break; 03700 } 03701 e = e->next; 03702 } 03703 03704 if (!e) { 03705 /* Allocate wildcard endpoint */ 03706 e = malloc(sizeof(struct mgcp_endpoint)); 03707 ep_reload = 0; 03708 } 03709 03710 if (e) { 03711 if (!ep_reload) { 03712 memset(e, 0, sizeof(struct mgcp_endpoint)); 03713 ast_mutex_init(&e->lock); 03714 ast_mutex_init(&e->rqnt_queue_lock); 03715 ast_mutex_init(&e->cmd_queue_lock); 03716 ast_copy_string(e->name, v->value, sizeof(e->name)); 03717 e->needaudit = 1; 03718 } 03719 ast_copy_string(gw->wcardep, v->value, sizeof(gw->wcardep)); 03720 /* XXX Should we really check for uniqueness?? XXX */ 03721 ast_copy_string(e->accountcode, accountcode, sizeof(e->accountcode)); 03722 ast_copy_string(e->context, context, sizeof(e->context)); 03723 ast_copy_string(e->cid_num, cid_num, sizeof(e->cid_num)); 03724 ast_copy_string(e->cid_name, cid_name, sizeof(e->cid_name)); 03725 ast_copy_string(e->language, language, sizeof(e->language)); 03726 ast_copy_string(e->musicclass, musicclass, sizeof(e->musicclass)); 03727 ast_copy_string(e->mailbox, mailbox, sizeof(e->mailbox)); 03728 snprintf(e->rqnt_ident, sizeof(e->rqnt_ident), "%08lx", ast_random()); 03729 e->msgstate = -1; 03730 e->amaflags = amaflags; 03731 e->capability = capability; 03732 e->parent = gw; 03733 e->dtmfmode = dtmfmode; 03734 if (!ep_reload && e->sub && e->sub->rtp) 03735 e->dtmfmode |= MGCP_DTMF_INBAND; 03736 e->adsi = adsi; 03737 e->type = TYPE_LINE; 03738 e->immediate = immediate; 03739 e->callgroup=cur_callergroup; 03740 e->pickupgroup=cur_pickupgroup; 03741 e->callreturn = callreturn; 03742 e->cancallforward = cancallforward; 03743 e->singlepath = singlepath; 03744 e->canreinvite = canreinvite; 03745 e->callwaiting = callwaiting; 03746 e->hascallwaiting = callwaiting; 03747 e->slowsequence = slowsequence; 03748 e->transfer = transfer; 03749 e->threewaycalling = threewaycalling; 03750 e->onhooktime = time(NULL); 03751 /* ASSUME we're onhook */ 03752 e->hookstate = MGCP_ONHOOK; 03753 if (!ep_reload) { 03754 /*snprintf(txident, sizeof(txident), "%08lx", ast_random());*/ 03755 for (i = 0; i < MAX_SUBS; i++) { 03756 sub = malloc(sizeof(struct mgcp_subchannel)); 03757 if (sub) { 03758 ast_verbose(VERBOSE_PREFIX_3 "Allocating subchannel '%d' on %s@%s\n", i, e->name, gw->name); 03759 memset(sub, 0, sizeof(struct mgcp_subchannel)); 03760 ast_mutex_init(&sub->lock); 03761 ast_mutex_init(&sub->cx_queue_lock); 03762 sub->parent = e; 03763 sub->id = i; 03764 snprintf(sub->txident, sizeof(sub->txident), "%08lx", ast_random()); 03765 /*stnrcpy(sub->txident, txident, sizeof(sub->txident) - 1);*/ 03766 sub->cxmode = MGCP_CX_INACTIVE; 03767 sub->nat = nat; 03768 sub->next = e->sub; 03769 e->sub = sub; 03770 } else { 03771 /* XXX Should find a way to clean up our memory */ 03772 ast_log(LOG_WARNING, "Out of memory allocating subchannel\n"); 03773 return NULL; 03774 } 03775 } 03776 /* Make out subs a circular linked list so we can always sping through the whole bunch */ 03777 sub = e->sub; 03778 /* find the end of the list */ 03779 while(sub->next){ 03780 sub = sub->next; 03781 } 03782 /* set the last sub->next to the first sub */ 03783 sub->next = e->sub; 03784 03785 e->next = gw->endpoints; 03786 gw->endpoints = e; 03787 } 03788 } 03789 } else if (!strcasecmp(v->name, "trunk") || 03790 !strcasecmp(v->name, "line")) { 03791 03792 /* locate existing endpoint */ 03793 e = gw->endpoints; 03794 while (e) { 03795 if (!strcasecmp(v->value, e->name)) { 03796 /* endpoint already exists */ 03797 e->delme = 0; 03798 ep_reload = 1; 03799 break; 03800 } 03801 e = e->next; 03802 } 03803 03804 if (!e) { 03805 e = malloc(sizeof(struct mgcp_endpoint)); 03806 ep_reload = 0; 03807 } 03808 03809 if (e) { 03810 if (!ep_reload) { 03811 memset(e, 0, sizeof(struct mgcp_endpoint)); 03812 ast_mutex_init(&e->lock); 03813 ast_mutex_init(&e->rqnt_queue_lock); 03814 ast_mutex_init(&e->cmd_queue_lock); 03815 ast_copy_string(e->name, v->value, sizeof(e->name)); 03816 e->needaudit = 1; 03817 } 03818 /* XXX Should we really check for uniqueness?? XXX */ 03819 ast_copy_string(e->accountcode, accountcode, sizeof(e->accountcode)); 03820 ast_copy_string(e->context, context, sizeof(e->context)); 03821 ast_copy_string(e->cid_num, cid_num, sizeof(e->cid_num)); 03822 ast_copy_string(e->cid_name, cid_name, sizeof(e->cid_name)); 03823 ast_copy_string(e->language, language, sizeof(e->language)); 03824 ast_copy_string(e->musicclass, musicclass, sizeof(e->musicclass)); 03825 ast_copy_string(e->mailbox, mailbox, sizeof(e->mailbox)); 03826 if (!ast_strlen_zero(mailbox)) { 03827 ast_verbose(VERBOSE_PREFIX_3 "Setting mailbox '%s' on %s@%s\n", mailbox, gw->name, e->name); 03828 } 03829 if (!ep_reload) { 03830 /* XXX potential issue due to reload */ 03831 e->msgstate = -1; 03832 e->parent = gw; 03833 } 03834 e->amaflags = amaflags; 03835 e->capability = capability; 03836 e->dtmfmode = dtmfmode; 03837 e->adsi = adsi; 03838 if (!strcasecmp(v->name, "trunk")) 03839 e->type = TYPE_TRUNK; 03840 else 03841 e->type = TYPE_LINE; 03842 03843 e->immediate = immediate; 03844 e->callgroup=cur_callergroup; 03845 e->pickupgroup=cur_pickupgroup; 03846 e->callreturn = callreturn; 03847 e->cancallforward = cancallforward; 03848 e->canreinvite = canreinvite; 03849 e->singlepath = singlepath; 03850 e->callwaiting = callwaiting; 03851 e->hascallwaiting = callwaiting; 03852 e->slowsequence = slowsequence; 03853 e->transfer = transfer; 03854 e->threewaycalling = threewaycalling; 03855 if (!ep_reload) { 03856 e->onhooktime = time(NULL); 03857 /* ASSUME we're onhook */ 03858 e->hookstate = MGCP_ONHOOK; 03859 snprintf(e->rqnt_ident, sizeof(e->rqnt_ident), "%08lx", ast_random()); 03860 } 03861 03862 for (i = 0, sub = NULL; i < MAX_SUBS; i++) { 03863 if (!ep_reload) { 03864 sub = malloc(sizeof(struct mgcp_subchannel)); 03865 } else { 03866 if (!sub) 03867 sub = e->sub; 03868 else 03869 sub = sub->next; 03870 } 03871 03872 if (sub) { 03873 if (!ep_reload) { 03874 ast_verbose(VERBOSE_PREFIX_3 "Allocating subchannel '%d' on %s@%s\n", i, e->name, gw->name); 03875 memset(sub, 0, sizeof(struct mgcp_subchannel)); 03876 ast_mutex_init(&sub->lock); 03877 ast_mutex_init(&sub->cx_queue_lock); 03878 ast_copy_string(sub->magic, MGCP_SUBCHANNEL_MAGIC, sizeof(sub->magic)); 03879 sub->parent = e; 03880 sub->id = i; 03881 snprintf(sub->txident, sizeof(sub->txident), "%08lx", ast_random()); 03882 sub->cxmode = MGCP_CX_INACTIVE; 03883 sub->next = e->sub; 03884 e->sub = sub; 03885 } 03886 sub->nat = nat; 03887 } else { 03888 /* XXX Should find a way to clean up our memory */ 03889 ast_log(LOG_WARNING, "Out of memory allocating subchannel\n"); 03890 return NULL; 03891 } 03892 } 03893 if (!ep_reload) { 03894 /* Make out subs a circular linked list so we can always sping through the whole bunch */ 03895 sub = e->sub; 03896 /* find the end of the list */ 03897 while (sub->next) { 03898 sub = sub->next; 03899 } 03900 /* set the last sub->next to the first sub */ 03901 sub->next = e->sub; 03902 03903 e->next = gw->endpoints; 03904 gw->endpoints = e; 03905 } 03906 } 03907 } else 03908 ast_log(LOG_WARNING, "Don't know keyword '%s' at line %d\n", v->name, v->lineno); 03909 v = v->next; 03910 } 03911 } 03912 if (!ntohl(gw->addr.sin_addr.s_addr) && !gw->dynamic) { 03913 ast_log(LOG_WARNING, "Gateway '%s' lacks IP address and isn't dynamic\n", gw->name); 03914 if (!gw_reload) { 03915 ast_mutex_destroy(&gw->msgs_lock); 03916 free(gw); 03917 } 03918 return NULL; 03919 } 03920 gw->defaddr.sin_family = AF_INET; 03921 gw->addr.sin_family = AF_INET; 03922 if (gw->defaddr.sin_addr.s_addr && !ntohs(gw->defaddr.sin_port)) 03923 gw->defaddr.sin_port = htons(DEFAULT_MGCP_GW_PORT); 03924 if (gw->addr.sin_addr.s_addr && !ntohs(gw->addr.sin_port)) 03925 gw->addr.sin_port = htons(DEFAULT_MGCP_GW_PORT); 03926 if (gw->addr.sin_addr.s_addr) 03927 if (ast_ouraddrfor(&gw->addr.sin_addr, &gw->ourip)) 03928 memcpy(&gw->ourip, &__ourip, sizeof(gw->ourip)); 03929 03930 return (gw_reload ? NULL : gw); 03931 }
static char* control2str | ( | int | ind | ) | [static] |
Definition at line 1351 of file chan_mgcp.c.
References AST_CONTROL_ANSWER, AST_CONTROL_BUSY, AST_CONTROL_CONGESTION, AST_CONTROL_FLASH, AST_CONTROL_HANGUP, AST_CONTROL_OFFHOOK, AST_CONTROL_OPTION, AST_CONTROL_RADIO_KEY, AST_CONTROL_RADIO_UNKEY, AST_CONTROL_RING, AST_CONTROL_RINGING, AST_CONTROL_TAKEOFFHOOK, and AST_CONTROL_WINK.
Referenced by mgcp_indicate(), and skinny_indicate().
01351 { 01352 switch (ind) { 01353 case AST_CONTROL_HANGUP: 01354 return "Other end has hungup"; 01355 case AST_CONTROL_RING: 01356 return "Local ring"; 01357 case AST_CONTROL_RINGING: 01358 return "Remote end is ringing"; 01359 case AST_CONTROL_ANSWER: 01360 return "Remote end has answered"; 01361 case AST_CONTROL_BUSY: 01362 return "Remote end is busy"; 01363 case AST_CONTROL_TAKEOFFHOOK: 01364 return "Make it go off hook"; 01365 case AST_CONTROL_OFFHOOK: 01366 return "Line is off hook"; 01367 case AST_CONTROL_CONGESTION: 01368 return "Congestion (circuits busy)"; 01369 case AST_CONTROL_FLASH: 01370 return "Flash hook"; 01371 case AST_CONTROL_WINK: 01372 return "Wink"; 01373 case AST_CONTROL_OPTION: 01374 return "Set a low-level option"; 01375 case AST_CONTROL_RADIO_KEY: 01376 return "Key Radio"; 01377 case AST_CONTROL_RADIO_UNKEY: 01378 return "Un-Key Radio"; 01379 } 01380 return "UNKNOWN"; 01381 }
static void destroy_endpoint | ( | struct mgcp_endpoint * | e | ) | [static] |
Definition at line 3966 of file chan_mgcp.c.
References ast_mutex_lock(), ast_rtp_destroy(), ast_strlen_zero(), mgcp_subchannel::cxident, mgcp_subchannel::lock, MAX_SUBS, mgcp_subchannel::next, mgcp_subchannel::rtp, s, mgcp_endpoint::sub, and transmit_connection_del().
Referenced by prune_gateways().
03967 { 03968 struct mgcp_subchannel *sub = e->sub->next, *s; 03969 int i; 03970 03971 for (i = 0; i < MAX_SUBS; i++) { 03972 ast_mutex_lock(&sub->lock); 03973 if (!ast_strlen_zero(sub->cxident)) { 03974 transmit_connection_del(sub); 03975 } 03976 if (sub->rtp) { 03977 ast_rtp_destroy(sub->rtp); 03978 sub->rtp = NULL; 03979 } 03980 memset(sub->magic, 0, sizeof(sub->magic)); 03981 mgcp_queue_hangup(sub); 03982 dump_cmd_queues(NULL, sub); 03983 ast_mutex_unlock(&sub->lock); 03984 sub = sub->next; 03985 } 03986 03987 if (e->dsp) { 03988 ast_dsp_free(e->dsp); 03989 } 03990 03991 dump_queue(e->parent, e); 03992 dump_cmd_queues(e, NULL); 03993 03994 sub = e->sub; 03995 for (i = 0; (i < MAX_SUBS) && sub; i++) { 03996 s = sub; 03997 sub = sub->next; 03998 ast_mutex_destroy(&s->lock); 03999 ast_mutex_destroy(&s->cx_queue_lock); 04000 free(s); 04001 } 04002 ast_mutex_destroy(&e->lock); 04003 ast_mutex_destroy(&e->rqnt_queue_lock); 04004 ast_mutex_destroy(&e->cmd_queue_lock); 04005 free(e); 04006 }
static void destroy_gateway | ( | struct mgcp_gateway * | g | ) | [static] |
Definition at line 4008 of file chan_mgcp.c.
References ast_free_ha(), dump_queue(), free, and mgcp_gateway::ha.
04009 { 04010 if (g->ha) 04011 ast_free_ha(g->ha); 04012 04013 dump_queue(g, NULL); 04014 04015 free (g); 04016 }
static void* do_monitor | ( | void * | data | ) | [static] |
Definition at line 3384 of file chan_mgcp.c.
References ast_io_add(), AST_IO_IN, ast_io_wait(), ast_mutex_lock(), ast_mutex_unlock(), ast_sched_runq(), ast_sched_wait(), ast_verbose(), mgcp_gateway::endpoints, gateways, has_voicemail(), io, mgcp_do_reload(), MGCP_ONHOOK, mgcp_reloading, mgcpsock, mgcpsock_read(), option_verbose, transmit_notify_request(), TYPE_LINE, and VERBOSE_PREFIX_1.
03385 { 03386 int res; 03387 int reloading; 03388 /*struct mgcp_gateway *g;*/ 03389 /*struct mgcp_endpoint *e;*/ 03390 /*time_t thispass = 0, lastpass = 0;*/ 03391 03392 /* Add an I/O event to our UDP socket */ 03393 if (mgcpsock > -1) 03394 mgcpsock_read_id = ast_io_add(io, mgcpsock, mgcpsock_read, AST_IO_IN, NULL); 03395 03396 /* This thread monitors all the frame relay interfaces which are not yet in use 03397 (and thus do not have a separate thread) indefinitely */ 03398 /* From here on out, we die whenever asked */ 03399 for(;;) { 03400 /* Check for a reload request */ 03401 ast_mutex_lock(&mgcp_reload_lock); 03402 reloading = mgcp_reloading; 03403 mgcp_reloading = 0; 03404 ast_mutex_unlock(&mgcp_reload_lock); 03405 if (reloading) { 03406 if (option_verbose > 0) 03407 ast_verbose(VERBOSE_PREFIX_1 "Reloading MGCP\n"); 03408 mgcp_do_reload(); 03409 /* Add an I/O event to our UDP socket */ 03410 if (mgcpsock > -1) 03411 mgcpsock_read_id = ast_io_add(io, mgcpsock, mgcpsock_read, AST_IO_IN, NULL); 03412 } 03413 03414 /* Check for interfaces needing to be killed */ 03415 /* Don't let anybody kill us right away. Nobody should lock the interface list 03416 and wait for the monitor list, but the other way around is okay. */ 03417 ast_mutex_lock(&monlock); 03418 /* Lock the network interface */ 03419 ast_mutex_lock(&netlock); 03420 03421 #if 0 03422 /* XXX THIS IS COMPLETELY HOSED */ 03423 /* The gateway goes into a state of panic */ 03424 /* If the vmwi indicator is sent while it is reseting interfaces */ 03425 lastpass = thispass; 03426 thispass = time(NULL); 03427 g = gateways; 03428 while(g) { 03429 if (thispass != lastpass) { 03430 e = g->endpoints; 03431 while(e) { 03432 if (e->type == TYPE_LINE) { 03433 res = has_voicemail(e); 03434 if ((e->msgstate != res) && (e->hookstate == MGCP_ONHOOK) && (!e->rtp)){ 03435 if (res) { 03436 transmit_notify_request(e, "L/vmwi(+)"); 03437 } else { 03438 transmit_notify_request(e, "L/vmwi(-)"); 03439 } 03440 e->msgstate = res; 03441 e->onhooktime = thispass; 03442 } 03443 } 03444 e = e->next; 03445 } 03446 } 03447 g = g->next; 03448 } 03449 #endif 03450 /* Okay, now that we know what to do, release the network lock */ 03451 ast_mutex_unlock(&netlock); 03452 /* And from now on, we're okay to be killed, so release the monitor lock as well */ 03453 ast_mutex_unlock(&monlock); 03454 pthread_testcancel(); 03455 /* Wait for sched or io */ 03456 res = ast_sched_wait(sched); 03457 /* copied from chan_sip.c */ 03458 if ((res < 0) || (res > 1000)) 03459 res = 1000; 03460 res = ast_io_wait(io, res); 03461 ast_mutex_lock(&monlock); 03462 if (res >= 0) 03463 ast_sched_runq(sched); 03464 ast_mutex_unlock(&monlock); 03465 } 03466 /* Never reached */ 03467 return NULL; 03468 }
static void dump_cmd_queues | ( | struct mgcp_endpoint * | p, | |
struct mgcp_subchannel * | sub | |||
) | [static] |
dump_cmd_queues: (SC:) cleanup pending commands
Definition at line 2347 of file chan_mgcp.c.
References ast_mutex_lock(), ast_mutex_unlock(), mgcp_endpoint::cmd_queue, mgcp_endpoint::cmd_queue_lock, mgcp_subchannel::cx_queue, mgcp_subchannel::cx_queue_lock, free, mgcp_subchannel::next, mgcp_request::next, mgcp_endpoint::rqnt_queue, mgcp_endpoint::rqnt_queue_lock, mgcp_endpoint::sub, and t.
Referenced by handle_request(), handle_response(), and unalloc_sub().
02348 { 02349 struct mgcp_request *t, *q; 02350 02351 if (p) { 02352 ast_mutex_lock(&p->rqnt_queue_lock); 02353 for (q = p->rqnt_queue; q; t = q->next, free(q), q=t); 02354 p->rqnt_queue = NULL; 02355 ast_mutex_unlock(&p->rqnt_queue_lock); 02356 02357 ast_mutex_lock(&p->cmd_queue_lock); 02358 for (q = p->cmd_queue; q; t = q->next, free(q), q=t); 02359 p->cmd_queue = NULL; 02360 ast_mutex_unlock(&p->cmd_queue_lock); 02361 02362 ast_mutex_lock(&p->sub->cx_queue_lock); 02363 for (q = p->sub->cx_queue; q; t = q->next, free(q), q=t); 02364 p->sub->cx_queue = NULL; 02365 ast_mutex_unlock(&p->sub->cx_queue_lock); 02366 02367 ast_mutex_lock(&p->sub->next->cx_queue_lock); 02368 for (q = p->sub->next->cx_queue; q; t = q->next, free(q), q=t); 02369 p->sub->next->cx_queue = NULL; 02370 ast_mutex_unlock(&p->sub->next->cx_queue_lock); 02371 } else if (sub) { 02372 ast_mutex_lock(&sub->cx_queue_lock); 02373 for (q = sub->cx_queue; q; t = q->next, free(q), q=t); 02374 sub->cx_queue = NULL; 02375 ast_mutex_unlock(&sub->cx_queue_lock); 02376 } 02377 }
static void dump_queue | ( | struct mgcp_gateway * | gw, | |
struct mgcp_endpoint * | p | |||
) | [static] |
Definition at line 526 of file chan_mgcp.c.
References ast_log(), ast_mutex_lock(), ast_mutex_unlock(), free, LOG_NOTICE, mgcp_gateway::msgs, mgcp_gateway::msgs_lock, mgcp_gateway::name, and mgcp_message::next.
Referenced by destroy_gateway(), and handle_request().
00527 { 00528 struct mgcp_message *cur, *q = NULL, *w, *prev; 00529 00530 ast_mutex_lock(&gw->msgs_lock); 00531 prev = NULL, cur = gw->msgs; 00532 while (cur) { 00533 if (!p || cur->owner_ep == p) { 00534 if (prev) 00535 prev->next = cur->next; 00536 else 00537 gw->msgs = cur->next; 00538 00539 ast_log(LOG_NOTICE, "Removing message from %s transaction %u\n", 00540 gw->name, cur->seqno); 00541 00542 w = cur; 00543 cur = cur->next; 00544 if (q) { 00545 w->next = q; 00546 } else { 00547 w->next = NULL; 00548 } 00549 q = w; 00550 } else { 00551 prev = cur, cur=cur->next; 00552 } 00553 } 00554 ast_mutex_unlock(&gw->msgs_lock); 00555 00556 while (q) { 00557 cur = q; 00558 q = q->next; 00559 free(cur); 00560 } 00561 }
static int find_and_retrans | ( | struct mgcp_subchannel * | sub, | |
struct mgcp_request * | req | |||
) | [static] |
Definition at line 3262 of file chan_mgcp.c.
References answer, free, mgcp_request::identifier, mgcp_response::next, mgcp_endpoint::parent, mgcp_subchannel::parent, resend_response(), RESPONSE_TIMEOUT, and mgcp_gateway::responses.
Referenced by mgcpsock_read().
03263 { 03264 int seqno=0; 03265 time_t now; 03266 struct mgcp_response *prev = NULL, *cur, *next, *answer=NULL; 03267 time(&now); 03268 if (sscanf(req->identifier, "%d", &seqno) != 1) 03269 seqno = 0; 03270 cur = sub->parent->parent->responses; 03271 while(cur) { 03272 next = cur->next; 03273 if (now - cur->whensent > RESPONSE_TIMEOUT) { 03274 /* Delete this entry */ 03275 if (prev) 03276 prev->next = next; 03277 else 03278 sub->parent->parent->responses = next; 03279 free(cur); 03280 } else { 03281 if (seqno == cur->seqno) 03282 answer = cur; 03283 prev = cur; 03284 } 03285 cur = next; 03286 } 03287 if (answer) { 03288 resend_response(sub, answer); 03289 return 1; 03290 } 03291 return 0; 03292 }
static struct mgcp_request* find_command | ( | struct mgcp_endpoint * | p, | |
struct mgcp_subchannel * | sub, | |||
struct mgcp_request ** | queue, | |||
ast_mutex_t * | l, | |||
int | ident | |||
) | [static] |
find_command: (SC:) remove command transaction from queue
Definition at line 2381 of file chan_mgcp.c.
References mgcp_gateway::addr, ast_inet_ntoa(), ast_mutex_lock(), ast_verbose(), mgcp_postrequest(), mgcp_request::next, and mgcp_endpoint::parent.
Referenced by agi_handle_command(), handle_response(), and handle_showagi().
02383 { 02384 struct mgcp_request *prev, *req; 02385 02386 ast_mutex_lock(l); 02387 for (prev = NULL, req = *queue; req; prev = req, req = req->next) { 02388 if (req->trid == ident) { 02389 /* remove from queue */ 02390 if (!prev) 02391 *queue = req->next; 02392 else 02393 prev->next = req->next; 02394 02395 /* send next pending command */ 02396 if (*queue) { 02397 if (mgcpdebug) { 02398 ast_verbose("Posting Queued Request:\n%s to %s:%d\n", (*queue)->data, 02399 ast_inet_ntoa(p->parent->addr.sin_addr), ntohs(p->parent->addr.sin_port)); 02400 } 02401 02402 mgcp_postrequest(p, sub, (*queue)->data, (*queue)->len, (*queue)->trid); 02403 } 02404 break; 02405 } 02406 } 02407 ast_mutex_unlock(l); 02408 return req; 02409 }
static struct mgcp_subchannel* find_subchannel_and_lock | ( | char * | name, | |
int | msgid, | |||
struct sockaddr_in * | sin | |||
) | [static] |
Definition at line 1584 of file chan_mgcp.c.
References __ourip, mgcp_gateway::addr, ast_inet_ntoa(), ast_log(), ast_mutex_lock(), ast_mutex_unlock(), ast_ouraddrfor(), ast_verbose(), mgcp_gateway::defaddr, mgcp_gateway::dynamic, mgcp_gateway::endpoints, gateways, mgcp_subchannel::id, mgcp_subchannel::lock, LOG_DEBUG, LOG_NOTICE, mgcp_endpoint::name, mgcp_gateway::name, mgcp_endpoint::next, mgcp_subchannel::next, mgcp_gateway::next, option_debug, option_verbose, mgcp_gateway::ourip, mgcp_endpoint::sub, and VERBOSE_PREFIX_3.
Referenced by mgcp_request(), and mgcpsock_read().
01585 { 01586 struct mgcp_endpoint *p = NULL; 01587 struct mgcp_subchannel *sub = NULL; 01588 struct mgcp_gateway *g; 01589 char tmp[256] = ""; 01590 char *at = NULL, *c; 01591 int found = 0; 01592 if (name) { 01593 ast_copy_string(tmp, name, sizeof(tmp)); 01594 at = strchr(tmp, '@'); 01595 if (!at) { 01596 ast_log(LOG_NOTICE, "Endpoint '%s' has no at sign!\n", name); 01597 return NULL; 01598 } 01599 *at++ = '\0'; 01600 } 01601 ast_mutex_lock(&gatelock); 01602 if (at && (at[0] == '[')) { 01603 at++; 01604 c = strrchr(at, ']'); 01605 if (c) 01606 *c = '\0'; 01607 } 01608 g = gateways; 01609 while(g) { 01610 if ((!name || !strcasecmp(g->name, at)) && 01611 (sin || g->addr.sin_addr.s_addr || g->defaddr.sin_addr.s_addr)) { 01612 /* Found the gateway. If it's dynamic, save it's address -- now for the endpoint */ 01613 if (sin && g->dynamic && name) { 01614 if ((g->addr.sin_addr.s_addr != sin->sin_addr.s_addr) || 01615 (g->addr.sin_port != sin->sin_port)) { 01616 memcpy(&g->addr, sin, sizeof(g->addr)); 01617 if (ast_ouraddrfor(&g->addr.sin_addr, &g->ourip)) 01618 memcpy(&g->ourip, &__ourip, sizeof(g->ourip)); 01619 if (option_verbose > 2) 01620 ast_verbose(VERBOSE_PREFIX_3 "Registered MGCP gateway '%s' at %s port %d\n", g->name, ast_inet_ntoa(g->addr.sin_addr), ntohs(g->addr.sin_port)); 01621 } 01622 } 01623 /* not dynamic, check if the name matches */ 01624 else if (name) { 01625 if (strcasecmp(g->name, at)) { 01626 g = g->next; 01627 continue; 01628 } 01629 } 01630 /* not dynamic, no name, check if the addr matches */ 01631 else if (!name && sin) { 01632 if ((g->addr.sin_addr.s_addr != sin->sin_addr.s_addr) || 01633 (g->addr.sin_port != sin->sin_port)) { 01634 g = g->next; 01635 continue; 01636 } 01637 } else { 01638 g = g->next; 01639 continue; 01640 } 01641 /* SC */ 01642 p = g->endpoints; 01643 while(p) { 01644 if (option_debug) 01645 ast_log(LOG_DEBUG, "Searching on %s@%s for subchannel\n", 01646 p->name, g->name); 01647 if (msgid) { 01648 #if 0 /* new transport mech */ 01649 sub = p->sub; 01650 do { 01651 if (option_debug) 01652 ast_log(LOG_DEBUG, "Searching on %s@%s-%d for subchannel with lastout: %d\n", 01653 p->name, g->name, sub->id, msgid); 01654 if (sub->lastout == msgid) { 01655 if (option_debug) 01656 ast_log(LOG_DEBUG, "Found subchannel sub%d to handle request %d sub->lastout: %d\n", 01657 sub->id, msgid, sub->lastout); 01658 found = 1; 01659 break; 01660 } 01661 sub = sub->next; 01662 } while (sub != p->sub); 01663 if (found) { 01664 break; 01665 } 01666 #endif 01667 /* SC */ 01668 sub = p->sub; 01669 found = 1; 01670 /* SC */ 01671 break; 01672 } else if (name && !strcasecmp(p->name, tmp)) { 01673 ast_log(LOG_DEBUG, "Coundn't determine subchannel, assuming current master %s@%s-%d\n", 01674 p->name, g->name, p->sub->id); 01675 sub = p->sub; 01676 found = 1; 01677 break; 01678 } 01679 p = p->next; 01680 } 01681 if (sub && found) { 01682 ast_mutex_lock(&sub->lock); 01683 break; 01684 } 01685 } 01686 g = g->next; 01687 } 01688 ast_mutex_unlock(&gatelock); 01689 if (!sub) { 01690 if (name) { 01691 if (g) 01692 ast_log(LOG_NOTICE, "Endpoint '%s' not found on gateway '%s'\n", tmp, at); 01693 else 01694 ast_log(LOG_NOTICE, "Gateway '%s' (and thus its endpoint '%s') does not exist\n", at, tmp); 01695 } 01696 } 01697 return sub; 01698 }
static char* get_csv | ( | char * | c, | |
int * | len, | |||
char ** | next | |||
) | [static] |
get_csv: (SC:) get comma separated value
Definition at line 1563 of file chan_mgcp.c.
References s.
Referenced by handle_response().
01564 { 01565 char *s; 01566 01567 *next = NULL, *len = 0; 01568 if (!c) return NULL; 01569 01570 while (*c && (*c < 33 || *c == ',')) 01571 c++; 01572 01573 s = c; 01574 while (*c && (*c >= 33 && *c != ',')) 01575 c++, (*len)++; 01576 *next = c; 01577 01578 if (*len == 0) 01579 s = NULL, *next = NULL; 01580 01581 return s; 01582 }
static char* get_header | ( | struct mgcp_request * | req, | |
char * | name | |||
) | [static] |
Definition at line 1556 of file chan_mgcp.c.
References __get_header().
Referenced by __transmit_response(), build_route(), check_auth(), check_user_full(), check_via(), copy_header(), extract_uri(), find_call(), find_sdp(), get_also_info(), get_destination(), get_rdnis(), get_refer_info(), gettag(), handle_request(), handle_request_bye(), handle_request_info(), handle_request_invite(), handle_request_notify(), handle_request_register(), handle_request_subscribe(), handle_response(), handle_response_invite(), handle_response_refer(), handle_response_register(), parse_moved_contact(), parse_ok_contact(), parse_register_contact(), receive_message(), register_verify(), reply_digest(), reqprep(), respprep(), send_request(), send_response(), sip_sipredirect(), sipsock_read(), transmit_refer(), transmit_response_with_auth(), transmit_response_with_sdp(), transmit_response_with_t38_sdp(), and transmit_state_notify().
01557 { 01558 int start = 0; 01559 return __get_header(req, name, &start); 01560 }
static char* get_sdp | ( | struct mgcp_request * | req, | |
char * | name | |||
) | [static] |
Definition at line 1508 of file chan_mgcp.c.
References get_sdp_by_line(), len, mgcp_request::line, and mgcp_request::lines.
Referenced by process_sdp().
01509 { 01510 int x; 01511 int len = strlen(name); 01512 char *r; 01513 01514 for (x=0; x<req->lines; x++) { 01515 r = get_sdp_by_line(req->line[x], name, len); 01516 if (r[0] != '\0') return r; 01517 } 01518 return ""; 01519 }
static char* get_sdp_by_line | ( | char * | line, | |
char * | name, | |||
int | nameLen | |||
) | [static] |
Definition at line 1498 of file chan_mgcp.c.
Referenced by get_sdp(), and get_sdp_iterate().
01499 { 01500 if (strncasecmp(line, name, nameLen) == 0 && line[nameLen] == '=') { 01501 char* r = line + nameLen + 1; 01502 while (*r && (*r < 33)) ++r; 01503 return r; 01504 } 01505 return ""; 01506 }
static char* get_sdp_iterate | ( | int * | iterator, | |
struct mgcp_request * | req, | |||
char * | name | |||
) | [static] |
Definition at line 1526 of file chan_mgcp.c.
References get_sdp_by_line(), len, and mgcp_request::line.
Referenced by get_sdp(), and process_sdp().
01527 { 01528 int len = strlen(name); 01529 char *r; 01530 while (*iterator < req->lines) { 01531 r = get_sdp_by_line(req->line[(*iterator)++], name, len); 01532 if (r[0] != '\0') return r; 01533 } 01534 return ""; 01535 }
static void handle_hd_hf | ( | struct mgcp_subchannel * | sub, | |
char * | ev | |||
) | [static] |
Definition at line 2915 of file chan_mgcp.c.
References ast_bridged_channel(), AST_CONTROL_ANSWER, AST_CONTROL_UNHOLD, ast_hangup(), ast_log(), ast_pthread_create, ast_queue_control(), AST_STATE_DOWN, AST_STATE_RING, mgcp_subchannel::cxmode, has_voicemail(), mgcp_endpoint::hookstate, mgcp_endpoint::immediate, LOG_WARNING, MGCP_CX_SENDRECV, mgcp_new(), MGCP_OFFHOOK, mgcp_queue_control(), mgcp_ss(), mgcp_gateway::name, mgcp_endpoint::name, mgcp_subchannel::outgoing, mgcp_subchannel::owner, mgcp_endpoint::parent, mgcp_subchannel::parent, mgcp_subchannel::rtp, start_rtp(), mgcp_endpoint::sub, t, transmit_modify_request(), and transmit_notify_request().
Referenced by handle_request().
02916 { 02917 struct mgcp_endpoint *p = sub->parent; 02918 struct ast_channel *c; 02919 pthread_t t; 02920 pthread_attr_t attr; 02921 pthread_attr_init(&attr); 02922 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); 02923 02924 /* Off hook / answer */ 02925 if (sub->outgoing) { 02926 /* Answered */ 02927 if (sub->owner) { 02928 if (ast_bridged_channel(sub->owner)) 02929 ast_queue_control(sub->owner, AST_CONTROL_UNHOLD); 02930 sub->cxmode = MGCP_CX_SENDRECV; 02931 if (!sub->rtp) { 02932 start_rtp(sub); 02933 } else { 02934 transmit_modify_request(sub); 02935 } 02936 /*transmit_notify_request(sub, "aw");*/ 02937 transmit_notify_request(sub, ""); 02938 mgcp_queue_control(sub, AST_CONTROL_ANSWER); 02939 } 02940 } else { 02941 /* Start switch */ 02942 /*sub->cxmode = MGCP_CX_SENDRECV;*/ 02943 if (!sub->owner) { 02944 if (!sub->rtp) { 02945 start_rtp(sub); 02946 } else { 02947 transmit_modify_request(sub); 02948 } 02949 if (p->immediate) { 02950 /* The channel is immediately up. Start right away */ 02951 #ifdef DLINK_BUGGY_FIRMWARE 02952 transmit_notify_request(sub, "rt"); 02953 #else 02954 transmit_notify_request(sub, "G/rt"); 02955 #endif 02956 c = mgcp_new(sub, AST_STATE_RING); 02957 if (!c) { 02958 ast_log(LOG_WARNING, "Unable to start PBX on channel %s@%s\n", p->name, p->parent->name); 02959 transmit_notify_request(sub, "G/cg"); 02960 ast_hangup(c); 02961 } 02962 } else { 02963 if (has_voicemail(p)) { 02964 transmit_notify_request(sub, "L/sl"); 02965 } else { 02966 transmit_notify_request(sub, "L/dl"); 02967 } 02968 c = mgcp_new(sub, AST_STATE_DOWN); 02969 if (c) { 02970 if (ast_pthread_create(&t, &attr, mgcp_ss, c)) { 02971 ast_log(LOG_WARNING, "Unable to create switch thread: %s\n", strerror(errno)); 02972 ast_hangup(c); 02973 } 02974 } else { 02975 ast_log(LOG_WARNING, "Unable to create channel for %s@%s\n", p->name, p->parent->name); 02976 } 02977 } 02978 } else { 02979 if (p->hookstate == MGCP_OFFHOOK) { 02980 ast_log(LOG_WARNING, "Off hook, but already have owner on %s@%s\n", p->name, p->parent->name); 02981 } else { 02982 ast_log(LOG_WARNING, "On hook, but already have owner on %s@%s\n", p->name, p->parent->name); 02983 ast_log(LOG_WARNING, "If we're onhook why are we here trying to handle a hd or hf?\n"); 02984 } 02985 if (ast_bridged_channel(sub->owner)) 02986 ast_queue_control(sub->owner, AST_CONTROL_UNHOLD); 02987 sub->cxmode = MGCP_CX_SENDRECV; 02988 if (!sub->rtp) { 02989 start_rtp(sub); 02990 } else { 02991 transmit_modify_request(sub); 02992 } 02993 /*transmit_notify_request(sub, "aw");*/ 02994 transmit_notify_request(sub, ""); 02995 /*ast_queue_control(sub->owner, AST_CONTROL_ANSWER);*/ 02996 } 02997 } 02998 pthread_attr_destroy(&attr); 02999 }
static int handle_request | ( | struct mgcp_subchannel * | sub, | |
struct mgcp_request * | req, | |||
struct sockaddr_in * | sin | |||
) | [static] |
Definition at line 3001 of file chan_mgcp.c.
References ast_channel::_state, mgcp_subchannel::alreadygone, ast_bridged_channel(), AST_CONTROL_HOLD, AST_CONTROL_UNHOLD, AST_FRAME_DTMF, ast_inet_ntoa(), ast_log(), ast_mutex_lock(), ast_mutex_unlock(), ast_queue_control(), AST_STATE_DOWN, ast_verbose(), attempt_transfer(), mgcp_endpoint::callwaiting, mgcp_endpoint::curtone, mgcp_subchannel::cxmode, dump_cmd_queues(), dump_queue(), mgcp_gateway::endpoints, f, get_header(), handle_hd_hf(), has_voicemail(), mgcp_endpoint::hascallwaiting, mgcp_endpoint::hidecallerid, mgcp_endpoint::hookstate, mgcp_subchannel::id, mgcp_subchannel::lock, LOG_DEBUG, LOG_NOTICE, LOG_WARNING, MGCP_CX_CONF, MGCP_CX_MUTE, MGCP_CX_RECVONLY, MGCP_CX_SENDRECV, MGCP_OFFHOOK, MGCP_ONHOOK, mgcp_queue_frame(), mgcp_queue_hangup(), mgcp_gateway::name, mgcp_endpoint::name, mgcp_subchannel::next, mgcp_endpoint::next, option_verbose, mgcp_subchannel::outgoing, mgcp_subchannel::owner, mgcp_endpoint::parent, mgcp_subchannel::parent, mgcp_subchannel::rtp, s, mgcp_endpoint::sub, mgcp_endpoint::threewaycalling, mgcp_endpoint::transfer, transmit_audit_endpoint(), transmit_connection_del(), transmit_modify_request(), transmit_notify_request(), transmit_response(), mgcp_request::verb, VERBOSE_PREFIX_3, and mgcp_gateway::wcardep.
Referenced by mgcpsock_read(), and sipsock_read().
03002 { 03003 char *ev, *s; 03004 struct ast_frame f = { 0, }; 03005 struct mgcp_endpoint *p = sub->parent; 03006 struct mgcp_gateway *g = NULL; 03007 int res; 03008 03009 if (mgcpdebug) { 03010 ast_verbose("Handling request '%s' on %s@%s\n", req->verb, p->name, p->parent->name); 03011 } 03012 /* Clear out potential response */ 03013 if (!strcasecmp(req->verb, "RSIP")) { 03014 /* Test if this RSIP request is just a keepalive */ 03015 if(!strcasecmp( get_header(req, "RM"), "X-keepalive")) { 03016 if (option_verbose > 2) 03017 ast_verbose(VERBOSE_PREFIX_3 "Received keepalive request from %s@%s\n", p->name, p->parent->name); 03018 transmit_response(sub, "200", req, "OK"); 03019 } else { 03020 dump_queue(p->parent, p); 03021 dump_cmd_queues(p, NULL); 03022 03023 if (option_verbose > 2 && (strcmp(p->name, p->parent->wcardep) != 0)) { 03024 ast_verbose(VERBOSE_PREFIX_3 "Resetting interface %s@%s\n", p->name, p->parent->name); 03025 } 03026 /* For RSIP on wildcard we reset all endpoints */ 03027 if (!strcmp(p->name, p->parent->wcardep)) { 03028 /* Reset all endpoints */ 03029 struct mgcp_endpoint *tmp_ep; 03030 03031 g = p->parent; 03032 tmp_ep = g->endpoints; 03033 while (tmp_ep) { 03034 /*if ((strcmp(tmp_ep->name, "*") != 0) && (strcmp(tmp_ep->name, "aaln/" "*") != 0)) {*/ 03035 if (strcmp(tmp_ep->name, g->wcardep) != 0) { 03036 struct mgcp_subchannel *tmp_sub, *first_sub; 03037 if (option_verbose > 2) { 03038 ast_verbose(VERBOSE_PREFIX_3 "Resetting interface %s@%s\n", tmp_ep->name, p->parent->name); 03039 } 03040 03041 first_sub = tmp_ep->sub; 03042 tmp_sub = tmp_ep->sub; 03043 while (tmp_sub) { 03044 mgcp_queue_hangup(tmp_sub); 03045 tmp_sub = tmp_sub->next; 03046 if (tmp_sub == first_sub) 03047 break; 03048 } 03049 } 03050 tmp_ep = tmp_ep->next; 03051 } 03052 } else if (sub->owner) { 03053 mgcp_queue_hangup(sub); 03054 } 03055 transmit_response(sub, "200", req, "OK"); 03056 /* We dont send NTFY or AUEP to wildcard ep */ 03057 if (strcmp(p->name, p->parent->wcardep) != 0) { 03058 transmit_notify_request(sub, ""); 03059 /* Audit endpoint. 03060 Idea is to prevent lost lines due to race conditions 03061 */ 03062 transmit_audit_endpoint(p); 03063 } 03064 } 03065 } else if (!strcasecmp(req->verb, "NTFY")) { 03066 /* Acknowledge and be sure we keep looking for the same things */ 03067 transmit_response(sub, "200", req, "OK"); 03068 /* Notified of an event */ 03069 ev = get_header(req, "O"); 03070 s = strchr(ev, '/'); 03071 if (s) ev = s + 1; 03072 ast_log(LOG_DEBUG, "Endpoint '%s@%s-%d' observed '%s'\n", p->name, p->parent->name, sub->id, ev); 03073 /* Keep looking for events unless this was a hangup */ 03074 if (strcasecmp(ev, "hu") && strcasecmp(ev, "hd") && strcasecmp(ev, "ping")) { 03075 transmit_notify_request(sub, p->curtone); 03076 } 03077 if (!strcasecmp(ev, "hd")) { 03078 p->hookstate = MGCP_OFFHOOK; 03079 sub->cxmode = MGCP_CX_SENDRECV; 03080 handle_hd_hf(sub, ev); 03081 } else if (!strcasecmp(ev, "hf")) { 03082 /* We can assume we are offhook if we received a hookflash */ 03083 /* First let's just do call wait and ignore threeway */ 03084 /* We're currently in charge */ 03085 if (p->hookstate != MGCP_OFFHOOK) { 03086 /* Cisco c7940 sends hf even if the phone is onhook */ 03087 /* Thanks to point on IRC for pointing this out */ 03088 return -1; 03089 } 03090 /* do not let * conference two down channels */ 03091 if (sub->owner && sub->owner->_state == AST_STATE_DOWN && !sub->next->owner) 03092 return -1; 03093 03094 if (p->callwaiting || p->transfer || p->threewaycalling) { 03095 if (option_verbose > 2) { 03096 ast_verbose(VERBOSE_PREFIX_3 "Swapping %d for %d on %s@%s\n", p->sub->id, p->sub->next->id, p->name, p->parent->name); 03097 } 03098 p->sub = p->sub->next; 03099 03100 /* transfer control to our next subchannel */ 03101 if (!sub->next->owner) { 03102 /* plave the first call on hold and start up a new call */ 03103 sub->cxmode = MGCP_CX_MUTE; 03104 if (option_verbose > 2) { 03105 ast_verbose(VERBOSE_PREFIX_3 "MGCP Muting %d on %s@%s\n", sub->id, p->name, p->parent->name); 03106 } 03107 transmit_modify_request(sub); 03108 if (sub->owner && ast_bridged_channel(sub->owner)) 03109 ast_queue_control(sub->owner, AST_CONTROL_HOLD); 03110 sub->next->cxmode = MGCP_CX_RECVONLY; 03111 handle_hd_hf(sub->next, ev); 03112 } else if (sub->owner && sub->next->owner) { 03113 /* We've got two active calls lets decide whether or not to conference or just flip flop */ 03114 if ((!sub->outgoing) && (!sub->next->outgoing)) { 03115 /* We made both calls lets conferenct */ 03116 if (option_verbose > 2) { 03117 ast_verbose(VERBOSE_PREFIX_3 "MGCP Conferencing %d and %d on %s@%s\n", 03118 sub->id, sub->next->id, p->name, p->parent->name); 03119 } 03120 sub->cxmode = MGCP_CX_CONF; 03121 sub->next->cxmode = MGCP_CX_CONF; 03122 if (ast_bridged_channel(sub->next->owner)) 03123 ast_queue_control(sub->next->owner, AST_CONTROL_UNHOLD); 03124 transmit_modify_request(sub); 03125 transmit_modify_request(sub->next); 03126 } else { 03127 /* Let's flipflop between calls */ 03128 /* XXX Need to check for state up ??? */ 03129 /* XXX Need a way to indicate the current call, or maybe the call that's waiting */ 03130 if (option_verbose > 2) { 03131 ast_verbose(VERBOSE_PREFIX_3 "We didn't make one of the calls FLIPFLOP %d and %d on %s@%s\n", 03132 sub->id, sub->next->id, p->name, p->parent->name); 03133 } 03134 sub->cxmode = MGCP_CX_MUTE; 03135 if (option_verbose > 2) { 03136 ast_verbose(VERBOSE_PREFIX_3 "MGCP Muting %d on %s@%s\n", sub->id, p->name, p->parent->name); 03137 } 03138 transmit_modify_request(sub); 03139 if (ast_bridged_channel(sub->owner)) 03140 ast_queue_control(sub->owner, AST_CONTROL_HOLD); 03141 03142 if (ast_bridged_channel(sub->next->owner)) 03143 ast_queue_control(sub->next->owner, AST_CONTROL_HOLD); 03144 03145 handle_hd_hf(sub->next, ev); 03146 } 03147 } else { 03148 /* We've most likely lost one of our calls find an active call and bring it up */ 03149 if (sub->owner) { 03150 p->sub = sub; 03151 } else if (sub->next->owner) { 03152 p->sub = sub->next; 03153 } else { 03154 /* We seem to have lost both our calls */ 03155 /* XXX - What do we do now? */ 03156 return -1; 03157 } 03158 if (ast_bridged_channel(p->sub->owner)) 03159 ast_queue_control(p->sub->owner, AST_CONTROL_UNHOLD); 03160 p->sub->cxmode = MGCP_CX_SENDRECV; 03161 transmit_modify_request(p->sub); 03162 } 03163 } else { 03164 ast_log(LOG_WARNING, "Callwaiting, call transfer or threeway calling not enabled on endpoint %s@%s\n", 03165 p->name, p->parent->name); 03166 } 03167 } else if (!strcasecmp(ev, "hu")) { 03168 p->hookstate = MGCP_ONHOOK; 03169 sub->cxmode = MGCP_CX_RECVONLY; 03170 ast_log(LOG_DEBUG, "MGCP %s@%s Went on hook\n", p->name, p->parent->name); 03171 /* Do we need to send MDCX before a DLCX ? 03172 if (sub->rtp) { 03173 transmit_modify_request(sub); 03174 } 03175 */ 03176 if (p->transfer && (sub->owner && sub->next->owner) && ((!sub->outgoing) || (!sub->next->outgoing))) { 03177 /* We're allowed to transfer, we have two avtive calls and */ 03178 /* we made at least one of the calls. Let's try and transfer */ 03179 ast_mutex_lock(&p->sub->next->lock); 03180 res = attempt_transfer(p); 03181 if (res < 0) { 03182 if (p->sub->next->owner) { 03183 sub->next->alreadygone = 1; 03184 mgcp_queue_hangup(sub->next); 03185 } 03186 } else if (res) { 03187 ast_log(LOG_WARNING, "Transfer attempt failed\n"); 03188 ast_mutex_unlock(&p->sub->next->lock); 03189 return -1; 03190 } 03191 ast_mutex_unlock(&p->sub->next->lock); 03192 } else { 03193 /* Hangup the current call */ 03194 /* If there is another active call, mgcp_hangup will ring the phone with the other call */ 03195 if (sub->owner) { 03196 sub->alreadygone = 1; 03197 mgcp_queue_hangup(sub); 03198 } else { 03199 /* verbose level check */ 03200 if (option_verbose > 2) { 03201 ast_verbose(VERBOSE_PREFIX_3 "MGCP handle_request(%s@%s-%d) ast_channel already destroyed, resending DLCX.\n", 03202 p->name, p->parent->name, sub->id); 03203 } 03204 /* Instruct the other side to remove the connection since it apparently * 03205 * still thinks the channel is active. * 03206 * For Cisco IAD2421 /BAK/ */ 03207 transmit_connection_del(sub); 03208 } 03209 } 03210 if ((p->hookstate == MGCP_ONHOOK) && (!sub->rtp) && (!sub->next->rtp)) { 03211 p->hidecallerid = 0; 03212 if (p->hascallwaiting && !p->callwaiting) { 03213 if (option_verbose > 2) 03214 ast_verbose(VERBOSE_PREFIX_3 "Enabling call waiting on MGCP/%s@%s-%d\n", p->name, p->parent->name, sub->id); 03215 p->callwaiting = -1; 03216 } 03217 if (has_voicemail(p)) { 03218 if (option_verbose > 2) { 03219 ast_verbose(VERBOSE_PREFIX_3 "MGCP handle_request(%s@%s) set vmwi(+)\n", p->name, p->parent->name); 03220 } 03221 transmit_notify_request(sub, "L/vmwi(+)"); 03222 } else { 03223 if (option_verbose > 2) { 03224 ast_verbose(VERBOSE_PREFIX_3 "MGCP handle_request(%s@%s) set vmwi(-)\n", p->name, p->parent->name); 03225 } 03226 transmit_notify_request(sub, "L/vmwi(-)"); 03227 } 03228 } 03229 } else if ((strlen(ev) == 1) && 03230 (((ev[0] >= '0') && (ev[0] <= '9')) || 03231 ((ev[0] >= 'A') && (ev[0] <= 'D')) || 03232 (ev[0] == '*') || (ev[0] == '#'))) { 03233 f.frametype = AST_FRAME_DTMF; 03234 f.subclass = ev[0]; 03235 f.src = "mgcp"; 03236 if (sub->owner) { 03237 /* XXX MUST queue this frame to all subs in threeway call if threeway call is active */ 03238 mgcp_queue_frame(sub, &f); 03239 ast_mutex_lock(&sub->next->lock); 03240 if (sub->next->owner) { 03241 mgcp_queue_frame(sub->next, &f); 03242 } 03243 ast_mutex_unlock(&sub->next->lock); 03244 } 03245 if (strstr(p->curtone, "wt") && (ev[0] == 'A')) { 03246 memset(p->curtone, 0, sizeof(p->curtone)); 03247 } 03248 } else if (!strcasecmp(ev, "T")) { 03249 /* Digit timeout -- unimportant */ 03250 } else if (!strcasecmp(ev, "ping")) { 03251 /* ping -- unimportant */ 03252 } else { 03253 ast_log(LOG_NOTICE, "Received unknown event '%s' from %s@%s\n", ev, p->name, p->parent->name); 03254 } 03255 } else { 03256 ast_log(LOG_WARNING, "Unknown verb '%s' received from %s\n", req->verb, ast_inet_ntoa(sin->sin_addr)); 03257 transmit_response(sub, "510", req, "Unknown verb"); 03258 } 03259 return 0; 03260 }
static void handle_response | ( | struct mgcp_endpoint * | p, | |
struct mgcp_subchannel * | sub, | |||
int | result, | |||
unsigned int | ident, | |||
struct mgcp_request * | resp | |||
) | [static] |
Definition at line 2412 of file chan_mgcp.c.
References ast_log(), ast_strlen_zero(), ast_verbose(), mgcp_request::cmd, mgcp_endpoint::cmd_queue, mgcp_endpoint::cmd_queue_lock, mgcp_subchannel::cx_queue, mgcp_subchannel::cx_queue_lock, mgcp_subchannel::cxident, dump_cmd_queues(), find_command(), free, get_csv(), get_header(), mgcp_endpoint::hookstate, mgcp_subchannel::id, len, mgcp_request::lines, LOG_NOTICE, LOG_WARNING, MGCP_CMD_AUEP, MGCP_CMD_CRCX, MGCP_OFFHOOK, MGCP_ONHOOK, mgcp_queue_hangup(), mgcp_endpoint::name, mgcp_gateway::name, mgcp_subchannel::next, option_verbose, mgcp_subchannel::owner, mgcp_endpoint::parent, process_sdp(), mgcp_endpoint::rqnt_queue, mgcp_endpoint::rqnt_queue_lock, mgcp_subchannel::rtp, mgcp_endpoint::slowsequence, start_rtp(), mgcp_endpoint::sub, mgcp_subchannel::tmpdest, transmit_connection_del(), transmit_connection_del_w_params(), transmit_modify_with_sdp(), transmit_notify_request(), and VERBOSE_PREFIX_3.
Referenced by handle_request(), mgcpsock_read(), and retrans_pkt().
02414 { 02415 char *c; 02416 struct mgcp_request *req; 02417 struct mgcp_gateway *gw = p->parent; 02418 02419 if (result < 200) { 02420 /* provisional response */ 02421 return; 02422 } 02423 02424 if (p->slowsequence) 02425 req = find_command(p, sub, &p->cmd_queue, &p->cmd_queue_lock, ident); 02426 else if (sub) 02427 req = find_command(p, sub, &sub->cx_queue, &sub->cx_queue_lock, ident); 02428 else if (!(req = find_command(p, sub, &p->rqnt_queue, &p->rqnt_queue_lock, ident))) 02429 req = find_command(p, sub, &p->cmd_queue, &p->cmd_queue_lock, ident); 02430 02431 if (!req) { 02432 if (option_verbose > 2) { 02433 ast_verbose(VERBOSE_PREFIX_3 "No command found on [%s] for transaction %d. Ignoring...\n", 02434 gw->name, ident); 02435 } 02436 return; 02437 } 02438 02439 if (p && (result >= 400) && (result <= 599)) { 02440 switch (result) { 02441 case 401: 02442 p->hookstate = MGCP_OFFHOOK; 02443 break; 02444 case 402: 02445 p->hookstate = MGCP_ONHOOK; 02446 break; 02447 case 406: 02448 ast_log(LOG_NOTICE, "Transaction %d timed out\n", ident); 02449 break; 02450 case 407: 02451 ast_log(LOG_NOTICE, "Transaction %d aborted\n", ident); 02452 break; 02453 } 02454 if (sub) { 02455 if (sub->owner) { 02456 ast_log(LOG_NOTICE, "Terminating on result %d from %s@%s-%d\n", 02457 result, p->name, p->parent->name, sub ? sub->id:-1); 02458 mgcp_queue_hangup(sub); 02459 } 02460 } else { 02461 if (p->sub->next->owner) { 02462 ast_log(LOG_NOTICE, "Terminating on result %d from %s@%s-%d\n", 02463 result, p->name, p->parent->name, sub ? sub->id:-1); 02464 mgcp_queue_hangup(p->sub); 02465 } 02466 02467 if (p->sub->owner) { 02468 ast_log(LOG_NOTICE, "Terminating on result %d from %s@%s-%d\n", 02469 result, p->name, p->parent->name, sub ? sub->id:-1); 02470 mgcp_queue_hangup(p->sub); 02471 } 02472 02473 dump_cmd_queues(p, NULL); 02474 } 02475 } 02476 02477 if (resp) { 02478 if (req->cmd == MGCP_CMD_CRCX) { 02479 if ((c = get_header(resp, "I"))) { 02480 if (!ast_strlen_zero(c) && sub) { 02481 /* if we are hanging up do not process this conn. */ 02482 if (sub->owner) { 02483 if (!ast_strlen_zero(sub->cxident)) { 02484 if (strcasecmp(c, sub->cxident)) { 02485 ast_log(LOG_WARNING, "Subchannel already has a cxident. sub->cxident: %s requested %s\n", sub->cxident, c); 02486 } 02487 } 02488 ast_copy_string(sub->cxident, c, sizeof(sub->cxident)); 02489 if (sub->tmpdest.sin_addr.s_addr) { 02490 transmit_modify_with_sdp(sub, NULL, 0); 02491 } 02492 } else { 02493 /* XXX delete this one 02494 callid and conn id may already be lost. 02495 so the following del conn may have a side effect of 02496 cleaning up the next subchannel */ 02497 transmit_connection_del(sub); 02498 } 02499 } 02500 } 02501 } 02502 02503 if (req->cmd == MGCP_CMD_AUEP) { 02504 /* check stale connection ids */ 02505 if ((c = get_header(resp, "I"))) { 02506 char *v, *n; 02507 int len; 02508 while ((v = get_csv(c, &len, &n))) { 02509 if (len) { 02510 if (strncasecmp(v, p->sub->cxident, len) && 02511 strncasecmp(v, p->sub->next->cxident, len)) { 02512 /* connection id not found. delete it */ 02513 char cxident[80] = ""; 02514 02515 if (len > (sizeof(cxident) - 1)) 02516 len = sizeof(cxident) - 1; 02517 ast_copy_string(cxident, v, len); 02518 if (option_verbose > 2) { 02519 ast_verbose(VERBOSE_PREFIX_3 "Non existing connection id %s on %s@%s \n", 02520 cxident, p->name, gw->name); 02521 } 02522 transmit_connection_del_w_params(p, NULL, cxident); 02523 } 02524 } 02525 c = n; 02526 } 02527 } 02528 02529 /* Try to determine the hookstate returned from an audit endpoint command */ 02530 if ((c = get_header(resp, "ES"))) { 02531 if (!ast_strlen_zero(c)) { 02532 if (strstr(c, "hu")) { 02533 if (p->hookstate != MGCP_ONHOOK) { 02534 /* XXX cleanup if we think we are offhook XXX */ 02535 if ((p->sub->owner || p->sub->next->owner ) && 02536 p->hookstate == MGCP_OFFHOOK) 02537 mgcp_queue_hangup(sub); 02538 p->hookstate = MGCP_ONHOOK; 02539 02540 /* update the requested events according to the new hookstate */ 02541 transmit_notify_request(p->sub, ""); 02542 02543 /* verbose level check */ 02544 if (option_verbose > 2) { 02545 ast_verbose(VERBOSE_PREFIX_3 "Setting hookstate of %s@%s to ONHOOK\n", p->name, gw->name); 02546 } 02547 } 02548 } else if (strstr(c, "hd")) { 02549 if (p->hookstate != MGCP_OFFHOOK) { 02550 p->hookstate = MGCP_OFFHOOK; 02551 02552 /* update the requested events according to the new hookstate */ 02553 transmit_notify_request(p->sub, ""); 02554 02555 /* verbose level check */ 02556 if (option_verbose > 2) { 02557 ast_verbose(VERBOSE_PREFIX_3 "Setting hookstate of %s@%s to OFFHOOK\n", p->name, gw->name); 02558 } 02559 } 02560 } 02561 } 02562 } 02563 } 02564 02565 if (resp && resp->lines) { 02566 /* do not process sdp if we are hanging up. this may be a late response */ 02567 if (sub && sub->owner) { 02568 if (!sub->rtp) 02569 start_rtp(sub); 02570 if (sub->rtp) 02571 process_sdp(sub, resp); 02572 } 02573 } 02574 } 02575 02576 free(req); 02577 }
static int has_voicemail | ( | struct mgcp_endpoint * | p | ) | [static] |
Definition at line 453 of file chan_mgcp.c.
References ast_app_has_voicemail(), and mgcp_endpoint::mailbox.
Referenced by do_monitor(), handle_hd_hf(), handle_init_event(), handle_request(), load_module(), mgcp_hangup(), mgcp_request(), vm_execmain(), and zt_handle_event().
00454 { 00455 return ast_app_has_voicemail(p->mailbox, NULL); 00456 }
static int init_req | ( | struct mgcp_endpoint * | p, | |
struct mgcp_request * | req, | |||
char * | verb | |||
) | [static] |
Definition at line 1949 of file chan_mgcp.c.
References ast_log(), mgcp_request::data, mgcp_request::header, mgcp_request::headers, mgcp_gateway::isnamedottedip, mgcp_request::len, LOG_WARNING, MGCP_MAX_HEADERS, mgcp_gateway::name, mgcp_endpoint::name, oseq, and mgcp_endpoint::parent.
Referenced by initreqprep(), reqprep(), and transmit_register().
01950 { 01951 /* Initialize a response */ 01952 if (req->headers || req->len) { 01953 ast_log(LOG_WARNING, "Request already initialized?!?\n"); 01954 return -1; 01955 } 01956 req->header[req->headers] = req->data + req->len; 01957 /* check if we need brackets around the gw name */ 01958 if (p->parent->isnamedottedip) 01959 snprintf(req->header[req->headers], sizeof(req->data) - req->len, "%s %d %s@[%s] MGCP 1.0\r\n", verb, oseq, p->name, p->parent->name); 01960 else 01961 snprintf(req->header[req->headers], sizeof(req->data) - req->len, "%s %d %s@%s MGCP 1.0\r\n", verb, oseq, p->name, p->parent->name); 01962 req->len += strlen(req->header[req->headers]); 01963 if (req->headers < MGCP_MAX_HEADERS) 01964 req->headers++; 01965 else 01966 ast_log(LOG_WARNING, "Out of header space\n"); 01967 return 0; 01968 }
static int init_resp | ( | struct mgcp_request * | req, | |
char * | resp, | |||
struct mgcp_request * | orig, | |||
char * | resprest | |||
) | [static] |
Definition at line 1932 of file chan_mgcp.c.
References ast_log(), mgcp_request::data, mgcp_request::header, mgcp_request::headers, mgcp_request::identifier, mgcp_request::len, LOG_WARNING, and MGCP_MAX_HEADERS.
Referenced by respprep().
01933 { 01934 /* Initialize a response */ 01935 if (req->headers || req->len) { 01936 ast_log(LOG_WARNING, "Request already initialized?!?\n"); 01937 return -1; 01938 } 01939 req->header[req->headers] = req->data + req->len; 01940 snprintf(req->header[req->headers], sizeof(req->data) - req->len, "%s %s %s\r\n", resp, orig->identifier, resprest); 01941 req->len += strlen(req->header[req->headers]); 01942 if (req->headers < MGCP_MAX_HEADERS) 01943 req->headers++; 01944 else 01945 ast_log(LOG_WARNING, "Out of header space\n"); 01946 return 0; 01947 }
static int load_module | ( | void | ) | [static] |
load_module: PBX load module - initialization ---
Definition at line 4243 of file chan_mgcp.c.
References ast_channel_register(), ast_cli_register_multiple(), ast_log(), AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_FAILURE, AST_MODULE_LOAD_SUCCESS, ast_rtp_proto_register(), cli_mgcp, io, io_context_create(), io_context_destroy(), LOG_ERROR, LOG_WARNING, mgcp_rtp, mgcp_tech, reload_config(), restart_monitor(), sched_context_create(), and sched_context_destroy().
04244 { 04245 if (!(sched = sched_context_create())) { 04246 ast_log(LOG_WARNING, "Unable to create schedule context\n"); 04247 return AST_MODULE_LOAD_FAILURE; 04248 } 04249 04250 if (!(io = io_context_create())) { 04251 ast_log(LOG_WARNING, "Unable to create I/O context\n"); 04252 sched_context_destroy(sched); 04253 return AST_MODULE_LOAD_FAILURE; 04254 } 04255 04256 if (reload_config()) 04257 return AST_MODULE_LOAD_DECLINE; 04258 04259 /* Make sure we can register our mgcp channel type */ 04260 if (ast_channel_register(&mgcp_tech)) { 04261 ast_log(LOG_ERROR, "Unable to register channel class 'MGCP'\n"); 04262 io_context_destroy(io); 04263 sched_context_destroy(sched); 04264 return AST_MODULE_LOAD_FAILURE; 04265 } 04266 04267 ast_rtp_proto_register(&mgcp_rtp); 04268 ast_cli_register_multiple(cli_mgcp, sizeof(cli_mgcp) / sizeof(struct ast_cli_entry)); 04269 04270 /* And start the monitor for the first time */ 04271 restart_monitor(); 04272 04273 return AST_MODULE_LOAD_SUCCESS; 04274 }
static int mgcp_answer | ( | struct ast_channel * | ast | ) | [static] |
Definition at line 1157 of file chan_mgcp.c.
References ast_channel::_state, ast_log(), ast_mutex_lock(), ast_mutex_unlock(), ast_setstate(), AST_STATE_UP, ast_verbose(), mgcp_subchannel::cxmode, mgcp_subchannel::id, mgcp_subchannel::lock, LOG_DEBUG, MGCP_CX_SENDRECV, mgcp_gateway::name, mgcp_endpoint::name, option_debug, option_verbose, mgcp_endpoint::parent, mgcp_subchannel::parent, mgcp_subchannel::rtp, start_rtp(), mgcp_endpoint::sub, ast_channel::tech_pvt, transmit_modify_request(), transmit_notify_request(), and VERBOSE_PREFIX_3.
01158 { 01159 int res = 0; 01160 struct mgcp_subchannel *sub = ast->tech_pvt; 01161 struct mgcp_endpoint *p = sub->parent; 01162 01163 ast_mutex_lock(&sub->lock); 01164 sub->cxmode = MGCP_CX_SENDRECV; 01165 if (!sub->rtp) { 01166 start_rtp(sub); 01167 } else { 01168 transmit_modify_request(sub); 01169 } 01170 /* verbose level check */ 01171 if (option_verbose > 2) { 01172 ast_verbose(VERBOSE_PREFIX_3 "MGCP mgcp_answer(%s) on %s@%s-%d\n", 01173 ast->name, p->name, p->parent->name, sub->id); 01174 } 01175 if (ast->_state != AST_STATE_UP) { 01176 ast_setstate(ast, AST_STATE_UP); 01177 if (option_debug) 01178 ast_log(LOG_DEBUG, "mgcp_answer(%s)\n", ast->name); 01179 transmit_notify_request(sub, ""); 01180 transmit_modify_request(sub); 01181 } 01182 ast_mutex_unlock(&sub->lock); 01183 return res; 01184 }
static int mgcp_audit_endpoint | ( | int | fd, | |
int | argc, | |||
char * | argv[] | |||
) | [static] |
Definition at line 1064 of file chan_mgcp.c.
References ast_cli(), ast_mutex_lock(), ast_mutex_unlock(), mgcp_gateway::endpoints, gateways, mgcpdebug, mgcp_endpoint::name, mgcp_gateway::name, mgcp_gateway::next, mgcp_endpoint::next, RESULT_SHOWUSAGE, RESULT_SUCCESS, and transmit_audit_endpoint().
01065 { 01066 struct mgcp_gateway *g; 01067 struct mgcp_endpoint *e; 01068 int found = 0; 01069 char *ename,*gname, *c; 01070 01071 if (!mgcpdebug) { 01072 return RESULT_SHOWUSAGE; 01073 } 01074 if (argc != 4) 01075 return RESULT_SHOWUSAGE; 01076 /* split the name into parts by null */ 01077 ename = argv[3]; 01078 gname = ename; 01079 while (*gname) { 01080 if (*gname == '@') { 01081 *gname = 0; 01082 gname++; 01083 break; 01084 } 01085 gname++; 01086 } 01087 if (gname[0] == '[') 01088 gname++; 01089 if ((c = strrchr(gname, ']'))) 01090 *c = '\0'; 01091 ast_mutex_lock(&gatelock); 01092 g = gateways; 01093 while(g) { 01094 if (!strcasecmp(g->name, gname)) { 01095 e = g->endpoints; 01096 while(e) { 01097 if (!strcasecmp(e->name, ename)) { 01098 found = 1; 01099 transmit_audit_endpoint(e); 01100 break; 01101 } 01102 e = e->next; 01103 } 01104 if (found) { 01105 break; 01106 } 01107 } 01108 g = g->next; 01109 } 01110 if (!found) { 01111 ast_cli(fd, " << Could not find endpoint >> "); 01112 } 01113 ast_mutex_unlock(&gatelock); 01114 return RESULT_SUCCESS; 01115 }
static int mgcp_call | ( | struct ast_channel * | ast, | |
char * | dest, | |||
int | timeout | |||
) | [static] |
Definition at line 819 of file chan_mgcp.c.
References ast_channel::_state, AST_CONTROL_RINGING, AST_LIST_TRAVERSE, ast_log(), ast_mutex_lock(), ast_mutex_unlock(), ast_queue_control(), ast_setstate(), AST_STATE_DOWN, AST_STATE_RESERVED, AST_STATE_RINGING, ast_strlen_zero(), ast_var_name(), ast_var_value(), ast_verbose(), mgcp_subchannel::callid, ast_channel::cid, ast_callerid::cid_name, ast_callerid::cid_num, mgcp_subchannel::cxident, mgcp_subchannel::cxmode, mgcp_endpoint::hookstate, mgcp_subchannel::lock, LOG_NOTICE, LOG_WARNING, MGCP_CX_RECVONLY, MGCP_CX_SENDRECV, MGCP_OFFHOOK, MGCP_ONHOOK, mgcpdebug, mgcp_subchannel::next, mgcp_subchannel::outgoing, mgcp_subchannel::owner, mgcp_subchannel::parent, mgcp_subchannel::rtp, start_rtp(), ast_channel::tech_pvt, transmit_modify_request(), transmit_notify_request_with_callerid(), mgcp_endpoint::type, TYPE_LINE, ast_channel::varshead, and VERBOSE_PREFIX_3.
00820 { 00821 int res; 00822 struct mgcp_endpoint *p; 00823 struct mgcp_subchannel *sub; 00824 char tone[50] = ""; 00825 const char *distinctive_ring = NULL; 00826 struct varshead *headp; 00827 struct ast_var_t *current; 00828 00829 if (mgcpdebug) { 00830 ast_verbose(VERBOSE_PREFIX_3 "MGCP mgcp_call(%s)\n", ast->name); 00831 } 00832 sub = ast->tech_pvt; 00833 p = sub->parent; 00834 headp = &ast->varshead; 00835 AST_LIST_TRAVERSE(headp,current,entries) { 00836 /* Check whether there is an ALERT_INFO variable */ 00837 if (strcasecmp(ast_var_name(current),"ALERT_INFO") == 0) { 00838 distinctive_ring = ast_var_value(current); 00839 } 00840 } 00841 00842 ast_mutex_lock(&sub->lock); 00843 switch (p->hookstate) { 00844 case MGCP_OFFHOOK: 00845 if (!ast_strlen_zero(distinctive_ring)) { 00846 snprintf(tone, sizeof(tone), "L/wt%s", distinctive_ring); 00847 if (mgcpdebug) { 00848 ast_verbose(VERBOSE_PREFIX_3 "MGCP distinctive callwait %s\n", tone); 00849 } 00850 } else { 00851 snprintf(tone, sizeof(tone), "L/wt"); 00852 if (mgcpdebug) { 00853 ast_verbose(VERBOSE_PREFIX_3 "MGCP normal callwait %s\n", tone); 00854 } 00855 } 00856 break; 00857 case MGCP_ONHOOK: 00858 default: 00859 if (!ast_strlen_zero(distinctive_ring)) { 00860 snprintf(tone, sizeof(tone), "L/r%s", distinctive_ring); 00861 if (mgcpdebug) { 00862 ast_verbose(VERBOSE_PREFIX_3 "MGCP distinctive ring %s\n", tone); 00863 } 00864 } else { 00865 snprintf(tone, sizeof(tone), "L/rg"); 00866 if (mgcpdebug) { 00867 ast_verbose(VERBOSE_PREFIX_3 "MGCP default ring\n"); 00868 } 00869 } 00870 break; 00871 } 00872 00873 if ((ast->_state != AST_STATE_DOWN) && (ast->_state != AST_STATE_RESERVED)) { 00874 ast_log(LOG_WARNING, "mgcp_call called on %s, neither down nor reserved\n", ast->name); 00875 ast_mutex_unlock(&sub->lock); 00876 return -1; 00877 } 00878 00879 res = 0; 00880 sub->outgoing = 1; 00881 sub->cxmode = MGCP_CX_RECVONLY; 00882 if (p->type == TYPE_LINE) { 00883 if (!sub->rtp) { 00884 start_rtp(sub); 00885 } else { 00886 transmit_modify_request(sub); 00887 } 00888 00889 if (sub->next->owner && !ast_strlen_zero(sub->next->cxident) && !ast_strlen_zero(sub->next->callid)) { 00890 /* try to prevent a callwait from disturbing the other connection */ 00891 sub->next->cxmode = MGCP_CX_RECVONLY; 00892 transmit_modify_request(sub->next); 00893 } 00894 00895 transmit_notify_request_with_callerid(sub, tone, ast->cid.cid_num, ast->cid.cid_name); 00896 ast_setstate(ast, AST_STATE_RINGING); 00897 00898 if (sub->next->owner && !ast_strlen_zero(sub->next->cxident) && !ast_strlen_zero(sub->next->callid)) { 00899 /* Put the connection back in sendrecv */ 00900 sub->next->cxmode = MGCP_CX_SENDRECV; 00901 transmit_modify_request(sub->next); 00902 } 00903 } else { 00904 ast_log(LOG_NOTICE, "Don't know how to dial on trunks yet\n"); 00905 res = -1; 00906 } 00907 ast_mutex_unlock(&sub->lock); 00908 ast_queue_control(ast, AST_CONTROL_RINGING); 00909 return res; 00910 }
static int mgcp_devicestate | ( | void * | data | ) | [static] |
mgcp_devicestate: channel callback for device status monitoring
data | tech/resource name of MGCP device to query |
Definition at line 1303 of file chan_mgcp.c.
References AST_DEVICE_INVALID, AST_DEVICE_UNKNOWN, ast_mutex_lock(), ast_mutex_unlock(), ast_strdupa, mgcp_gateway::endpoints, error(), gateways, mgcp_endpoint::name, mgcp_gateway::name, mgcp_endpoint::next, and mgcp_gateway::next.
01304 { 01305 struct mgcp_gateway *g; 01306 struct mgcp_endpoint *e = NULL; 01307 char *tmp, *endpt, *gw; 01308 int ret = AST_DEVICE_INVALID; 01309 01310 endpt = ast_strdupa(data); 01311 if ((tmp = strchr(endpt, '@'))) { 01312 *tmp++ = '\0'; 01313 gw = tmp; 01314 } else 01315 goto error; 01316 01317 ast_mutex_lock(&gatelock); 01318 g = gateways; 01319 while (g) { 01320 if (strcasecmp(g->name, gw) == 0) { 01321 e = g->endpoints; 01322 break; 01323 } 01324 g = g->next; 01325 } 01326 01327 if (!e) 01328 goto error; 01329 01330 while (e) { 01331 if (strcasecmp(e->name, endpt) == 0) 01332 break; 01333 e = e->next; 01334 } 01335 01336 if (!e) 01337 goto error; 01338 01339 /* 01340 * As long as the gateway/endpoint is valid, we'll 01341 * assume that the device is available and its state 01342 * can be tracked. 01343 */ 01344 ret = AST_DEVICE_UNKNOWN; 01345 01346 error: 01347 ast_mutex_unlock(&gatelock); 01348 return ret; 01349 }
static int mgcp_do_debug | ( | int | fd, | |
int | argc, | |||
char * | argv[] | |||
) | [static] |
Definition at line 1117 of file chan_mgcp.c.
References ast_cli(), mgcpdebug, RESULT_SHOWUSAGE, and RESULT_SUCCESS.
01118 { 01119 if (argc != 3) 01120 return RESULT_SHOWUSAGE; 01121 mgcpdebug = 1; 01122 ast_cli(fd, "MGCP Debugging Enabled\n"); 01123 return RESULT_SUCCESS; 01124 }
static int mgcp_do_reload | ( | void | ) | [static] |
mgcp_do_reload: Reload module
Definition at line 4277 of file chan_mgcp.c.
References reload_config().
Referenced by do_monitor().
04278 { 04279 reload_config(); 04280 return 0; 04281 }
static int mgcp_fixup | ( | struct ast_channel * | oldchan, | |
struct ast_channel * | newchan | |||
) | [static] |
Definition at line 1257 of file chan_mgcp.c.
References ast_log(), ast_mutex_lock(), ast_mutex_unlock(), mgcp_subchannel::lock, LOG_NOTICE, LOG_WARNING, mgcp_subchannel::owner, and ast_channel::tech_pvt.
01258 { 01259 struct mgcp_subchannel *sub = newchan->tech_pvt; 01260 01261 ast_mutex_lock(&sub->lock); 01262 ast_log(LOG_NOTICE, "mgcp_fixup(%s, %s)\n", oldchan->name, newchan->name); 01263 if (sub->owner != oldchan) { 01264 ast_mutex_unlock(&sub->lock); 01265 ast_log(LOG_WARNING, "old channel wasn't %p but was %p\n", oldchan, sub->owner); 01266 return -1; 01267 } 01268 sub->owner = newchan; 01269 ast_mutex_unlock(&sub->lock); 01270 return 0; 01271 }
static enum ast_rtp_get_result mgcp_get_rtp_peer | ( | struct ast_channel * | chan, | |
struct ast_rtp ** | rtp | |||
) | [static] |
Definition at line 3933 of file chan_mgcp.c.
References AST_RTP_GET_FAILED, AST_RTP_TRY_NATIVE, AST_RTP_TRY_PARTIAL, mgcp_endpoint::canreinvite, mgcp_subchannel::parent, mgcp_subchannel::rtp, and ast_channel::tech_pvt.
03934 { 03935 struct mgcp_subchannel *sub = NULL; 03936 03937 if (!(sub = chan->tech_pvt) || !(sub->rtp)) 03938 return AST_RTP_GET_FAILED; 03939 03940 *rtp = sub->rtp; 03941 03942 if (sub->parent->canreinvite) 03943 return AST_RTP_TRY_NATIVE; 03944 else 03945 return AST_RTP_TRY_PARTIAL; 03946 }
static int mgcp_hangup | ( | struct ast_channel * | ast | ) | [static] |
Definition at line 912 of file chan_mgcp.c.
References mgcp_subchannel::alreadygone, ast_bridged_channel(), ast_dsp_free(), ast_log(), ast_module_unref(), ast_mutex_lock(), ast_mutex_unlock(), ast_rtp_destroy(), ast_strlen_zero(), ast_verbose(), mgcp_subchannel::callid, mgcp_endpoint::callwaiting, ast_channel::cid, ast_callerid::cid_name, ast_callerid::cid_num, mgcp_subchannel::cxident, mgcp_subchannel::cxmode, mgcp_endpoint::dsp, mgcp_endpoint::dtmfmode, has_voicemail(), mgcp_endpoint::hascallwaiting, mgcp_endpoint::hidecallerid, mgcp_endpoint::hookstate, mgcp_subchannel::lock, LOG_DEBUG, mgcp_subchannel::magic, MGCP_CX_INACTIVE, MGCP_CX_RECVONLY, MGCP_DTMF_HYBRID, MGCP_DTMF_INBAND, MGCP_OFFHOOK, MGCP_ONHOOK, MGCP_SUBCHANNEL_MAGIC, mgcpdebug, mgcp_gateway::name, mgcp_endpoint::name, mgcp_subchannel::next, option_debug, option_verbose, mgcp_subchannel::outgoing, mgcp_subchannel::owner, mgcp_endpoint::parent, mgcp_subchannel::parent, mgcp_subchannel::rtp, mgcp_endpoint::sub, ast_channel::tech_pvt, mgcp_subchannel::tmpdest, transmit_connection_del(), transmit_modify_request(), transmit_notify_request(), transmit_notify_request_with_callerid(), VERBOSE_PREFIX_2, and VERBOSE_PREFIX_3.
00913 { 00914 struct mgcp_subchannel *sub = ast->tech_pvt; 00915 struct mgcp_endpoint *p = sub->parent; 00916 00917 if (option_debug) { 00918 ast_log(LOG_DEBUG, "mgcp_hangup(%s)\n", ast->name); 00919 } 00920 if (!ast->tech_pvt) { 00921 ast_log(LOG_DEBUG, "Asked to hangup channel not connected\n"); 00922 return 0; 00923 } 00924 if (strcmp(sub->magic, MGCP_SUBCHANNEL_MAGIC)) { 00925 ast_log(LOG_DEBUG, "Invalid magic. MGCP subchannel freed up already.\n"); 00926 return 0; 00927 } 00928 ast_mutex_lock(&sub->lock); 00929 if (mgcpdebug) { 00930 ast_verbose(VERBOSE_PREFIX_3 "MGCP mgcp_hangup(%s) on %s@%s\n", ast->name, p->name, p->parent->name); 00931 } 00932 00933 if ((p->dtmfmode & MGCP_DTMF_INBAND) && p->dsp) { 00934 /* check whether other channel is active. */ 00935 if (!sub->next->owner) { 00936 if (p->dtmfmode & MGCP_DTMF_HYBRID) 00937 p->dtmfmode &= ~MGCP_DTMF_INBAND; 00938 if (mgcpdebug) { 00939 ast_verbose(VERBOSE_PREFIX_2 "MGCP free dsp on %s@%s\n", p->name, p->parent->name); 00940 } 00941 ast_dsp_free(p->dsp); 00942 p->dsp = NULL; 00943 } 00944 } 00945 00946 sub->owner = NULL; 00947 if (!ast_strlen_zero(sub->cxident)) { 00948 transmit_connection_del(sub); 00949 } 00950 sub->cxident[0] = '\0'; 00951 if ((sub == p->sub) && sub->next->owner) { 00952 if (p->hookstate == MGCP_OFFHOOK) { 00953 if (sub->next->owner && ast_bridged_channel(sub->next->owner)) { 00954 transmit_notify_request_with_callerid(p->sub, "L/wt", ast_bridged_channel(sub->next->owner)->cid.cid_num, ast_bridged_channel(sub->next->owner)->cid.cid_name); 00955 } 00956 } else { 00957 /* set our other connection as the primary and swith over to it */ 00958 p->sub = sub->next; 00959 p->sub->cxmode = MGCP_CX_RECVONLY; 00960 transmit_modify_request(p->sub); 00961 if (sub->next->owner && ast_bridged_channel(sub->next->owner)) { 00962 transmit_notify_request_with_callerid(p->sub, "L/rg", ast_bridged_channel(sub->next->owner)->cid.cid_num, ast_bridged_channel(sub->next->owner)->cid.cid_name); 00963 } 00964 } 00965 00966 } else if ((sub == p->sub->next) && p->hookstate == MGCP_OFFHOOK) { 00967 transmit_notify_request(sub, "L/v"); 00968 } else if (p->hookstate == MGCP_OFFHOOK) { 00969 transmit_notify_request(sub, "L/ro"); 00970 } else { 00971 transmit_notify_request(sub, ""); 00972 } 00973 00974 ast->tech_pvt = NULL; 00975 sub->alreadygone = 0; 00976 sub->outgoing = 0; 00977 sub->cxmode = MGCP_CX_INACTIVE; 00978 sub->callid[0] = '\0'; 00979 /* Reset temporary destination */ 00980 memset(&sub->tmpdest, 0, sizeof(sub->tmpdest)); 00981 if (sub->rtp) { 00982 ast_rtp_destroy(sub->rtp); 00983 sub->rtp = NULL; 00984 } 00985 00986 ast_module_unref(ast_module_info->self); 00987 00988 if ((p->hookstate == MGCP_ONHOOK) && (!sub->next->rtp)) { 00989 p->hidecallerid = 0; 00990 if (p->hascallwaiting && !p->callwaiting) { 00991 if (option_verbose > 2) 00992 ast_verbose(VERBOSE_PREFIX_3 "Enabling call waiting on %s\n", ast->name); 00993 p->callwaiting = -1; 00994 } 00995 if (has_voicemail(p)) { 00996 if (mgcpdebug) { 00997 ast_verbose(VERBOSE_PREFIX_3 "MGCP mgcp_hangup(%s) on %s@%s set vmwi(+)\n", 00998 ast->name, p->name, p->parent->name); 00999 } 01000 transmit_notify_request(sub, "L/vmwi(+)"); 01001 } else { 01002 if (mgcpdebug) { 01003 ast_verbose(VERBOSE_PREFIX_3 "MGCP mgcp_hangup(%s) on %s@%s set vmwi(-)\n", 01004 ast->name, p->name, p->parent->name); 01005 } 01006 transmit_notify_request(sub, "L/vmwi(-)"); 01007 } 01008 } 01009 ast_mutex_unlock(&sub->lock); 01010 return 0; 01011 }
static int mgcp_indicate | ( | struct ast_channel * | ast, | |
int | ind, | |||
const void * | data, | |||
size_t | datalen | |||
) | [static] |
Definition at line 1383 of file chan_mgcp.c.
References AST_CONTROL_BUSY, AST_CONTROL_CONGESTION, AST_CONTROL_HOLD, AST_CONTROL_RINGING, AST_CONTROL_UNHOLD, ast_log(), ast_moh_start(), ast_moh_stop(), ast_mutex_lock(), ast_mutex_unlock(), ast_verbose(), control2str(), mgcp_subchannel::lock, LOG_WARNING, mgcpdebug, ast_channel::tech_pvt, transmit_notify_request(), and VERBOSE_PREFIX_3.
01384 { 01385 struct mgcp_subchannel *sub = ast->tech_pvt; 01386 int res = 0; 01387 01388 if (mgcpdebug) { 01389 ast_verbose(VERBOSE_PREFIX_3 "MGCP asked to indicate %d '%s' condition on channel %s\n", 01390 ind, control2str(ind), ast->name); 01391 } 01392 ast_mutex_lock(&sub->lock); 01393 switch(ind) { 01394 case AST_CONTROL_RINGING: 01395 #ifdef DLINK_BUGGY_FIRMWARE 01396 transmit_notify_request(sub, "rt"); 01397 #else 01398 transmit_notify_request(sub, "G/rt"); 01399 #endif 01400 break; 01401 case AST_CONTROL_BUSY: 01402 transmit_notify_request(sub, "L/bz"); 01403 break; 01404 case AST_CONTROL_CONGESTION: 01405 transmit_notify_request(sub, "G/cg"); 01406 break; 01407 case AST_CONTROL_HOLD: 01408 ast_moh_start(ast, data, NULL); 01409 break; 01410 case AST_CONTROL_UNHOLD: 01411 ast_moh_stop(ast); 01412 break; 01413 case -1: 01414 transmit_notify_request(sub, ""); 01415 break; 01416 default: 01417 ast_log(LOG_WARNING, "Don't know how to indicate condition %d\n", ind); 01418 res = -1; 01419 } 01420 ast_mutex_unlock(&sub->lock); 01421 return res; 01422 }
static struct ast_channel* mgcp_new | ( | struct mgcp_subchannel * | sub, | |
int | state | |||
) | [static] |
Definition at line 1424 of file chan_mgcp.c.
References accountcode, mgcp_endpoint::accountcode, mgcp_endpoint::adsi, ast_channel::adsicpe, ast_channel::amaflags, mgcp_endpoint::amaflags, AST_ADSI_UNAVAILABLE, ast_best_codec(), ast_channel_alloc(), ast_dsp_digitmode(), ast_dsp_new(), ast_dsp_set_features(), ast_hangup(), ast_jb_configure(), ast_log(), ast_module_ref(), ast_pbx_start(), ast_rtp_fd(), ast_state2str(), AST_STATE_DOWN, AST_STATE_RING, ast_strdup, ast_string_field_build, ast_string_field_set, ast_strlen_zero(), ast_verbose(), mgcp_endpoint::call_forward, mgcp_endpoint::callgroup, ast_channel::callgroup, capability, mgcp_endpoint::capability, ast_channel::cid, ast_callerid::cid_ani, ast_callerid::cid_name, mgcp_endpoint::cid_name, ast_callerid::cid_num, mgcp_endpoint::cid_num, ast_channel::context, mgcp_endpoint::context, mgcp_endpoint::dsp, DSP_DIGITMODE_NOQUELCH, DSP_FEATURE_DTMF_DETECT, mgcp_endpoint::dtmfmode, ast_channel::exten, mgcp_endpoint::exten, ast_channel::fds, fmt, global_jbconf, mgcp_subchannel::id, language, mgcp_endpoint::language, LOG_WARNING, MGCP_DTMF_HYBRID, MGCP_DTMF_INBAND, mgcp_tech, name, mgcp_gateway::name, mgcp_endpoint::name, ast_channel::nativeformats, option_verbose, mgcp_subchannel::owner, mgcp_endpoint::parent, mgcp_subchannel::parent, mgcp_endpoint::pickupgroup, ast_channel::pickupgroup, ast_channel::priority, ast_channel::rawreadformat, ast_channel::rawwriteformat, ast_channel::readformat, ast_channel::rings, mgcp_subchannel::rtp, mgcp_endpoint::sub, ast_channel::tech, ast_channel::tech_pvt, VERBOSE_PREFIX_3, and ast_channel::writeformat.
Referenced by handle_hd_hf(), and mgcp_request().
01425 { 01426 struct ast_channel *tmp; 01427 struct mgcp_endpoint *i = sub->parent; 01428 int fmt; 01429 01430 tmp = ast_channel_alloc(1, state, i->cid_num, i->cid_name, i->accountcode, i->exten, i->context, i->amaflags, "MGCP/%s@%s-%d", i->name, i->parent->name, sub->id); 01431 if (tmp) { 01432 tmp->tech = &mgcp_tech; 01433 tmp->nativeformats = i->capability; 01434 if (!tmp->nativeformats) 01435 tmp->nativeformats = capability; 01436 fmt = ast_best_codec(tmp->nativeformats); 01437 ast_string_field_build(tmp, name, "MGCP/%s@%s-%d", i->name, i->parent->name, sub->id); 01438 if (sub->rtp) 01439 tmp->fds[0] = ast_rtp_fd(sub->rtp); 01440 if (i->dtmfmode & (MGCP_DTMF_INBAND | MGCP_DTMF_HYBRID)) { 01441 i->dsp = ast_dsp_new(); 01442 ast_dsp_set_features(i->dsp,DSP_FEATURE_DTMF_DETECT); 01443 /* this is to prevent clipping of dtmf tones during dsp processing */ 01444 ast_dsp_digitmode(i->dsp, DSP_DIGITMODE_NOQUELCH); 01445 } else { 01446 i->dsp = NULL; 01447 } 01448 if (state == AST_STATE_RING) 01449 tmp->rings = 1; 01450 tmp->writeformat = fmt; 01451 tmp->rawwriteformat = fmt; 01452 tmp->readformat = fmt; 01453 tmp->rawreadformat = fmt; 01454 tmp->tech_pvt = sub; 01455 if (!ast_strlen_zero(i->language)) 01456 ast_string_field_set(tmp, language, i->language); 01457 if (!ast_strlen_zero(i->accountcode)) 01458 ast_string_field_set(tmp, accountcode, i->accountcode); 01459 if (i->amaflags) 01460 tmp->amaflags = i->amaflags; 01461 sub->owner = tmp; 01462 ast_module_ref(ast_module_info->self); 01463 tmp->callgroup = i->callgroup; 01464 tmp->pickupgroup = i->pickupgroup; 01465 ast_string_field_set(tmp, call_forward, i->call_forward); 01466 ast_copy_string(tmp->context, i->context, sizeof(tmp->context)); 01467 ast_copy_string(tmp->exten, i->exten, sizeof(tmp->exten)); 01468 01469 /* Don't use ast_set_callerid() here because it will 01470 * generate a needless NewCallerID event */ 01471 tmp->cid.cid_num = ast_strdup(i->cid_num); 01472 tmp->cid.cid_ani = ast_strdup(i->cid_num); 01473 tmp->cid.cid_name = ast_strdup(i->cid_name); 01474 01475 if (!i->adsi) 01476 tmp->adsicpe = AST_ADSI_UNAVAILABLE; 01477 tmp->priority = 1; 01478 if (sub->rtp) 01479 ast_jb_configure(tmp, &global_jbconf); 01480 if (state != AST_STATE_DOWN) { 01481 if (ast_pbx_start(tmp)) { 01482 ast_log(LOG_WARNING, "Unable to start PBX on %s\n", tmp->name); 01483 ast_hangup(tmp); 01484 tmp = NULL; 01485 } 01486 } 01487 /* verbose level check */ 01488 if (option_verbose > 2) { 01489 ast_verbose(VERBOSE_PREFIX_3 "MGCP mgcp_new(%s) created in state: %s\n", 01490 tmp->name, ast_state2str(state)); 01491 } 01492 } else { 01493 ast_log(LOG_WARNING, "Unable to allocate channel structure\n"); 01494 } 01495 return tmp; 01496 }
static int mgcp_no_debug | ( | int | fd, | |
int | argc, | |||
char * | argv[] | |||
) | [static] |
Definition at line 1126 of file chan_mgcp.c.
References ast_cli(), mgcpdebug, RESULT_SHOWUSAGE, and RESULT_SUCCESS.
01127 { 01128 if (argc != 4) 01129 return RESULT_SHOWUSAGE; 01130 mgcpdebug = 0; 01131 ast_cli(fd, "MGCP Debugging Disabled\n"); 01132 return RESULT_SUCCESS; 01133 }
static int mgcp_postrequest | ( | struct mgcp_endpoint * | p, | |
struct mgcp_subchannel * | sub, | |||
char * | data, | |||
int | len, | |||
unsigned int | seqno | |||
) | [static] |
Definition at line 668 of file chan_mgcp.c.
References __mgcp_xmit(), ast_log(), ast_mutex_lock(), ast_mutex_unlock(), ast_sched_add(), mgcp_message::buf, DEFAULT_RETRANS, mgcp_message::expire, mgcp_message::len, LOG_NOTICE, malloc, mgcp_gateway::msgs, mgcp_gateway::msgs_lock, mgcp_message::next, mgcp_message::owner_ep, mgcp_message::owner_sub, mgcp_endpoint::parent, mgcp_message::retrans, retrans_pkt(), mgcp_gateway::retransid, and mgcp_message::seqno.
Referenced by find_command(), and send_request().
00670 { 00671 struct mgcp_message *msg = malloc(sizeof(struct mgcp_message) + len); 00672 struct mgcp_message *cur; 00673 struct mgcp_gateway *gw = ((p && p->parent) ? p->parent : NULL); 00674 struct timeval tv; 00675 00676 if (!msg) { 00677 return -1; 00678 } 00679 if (!gw) { 00680 return -1; 00681 } 00682 /* SC 00683 time(&t); 00684 if (gw->messagepending && (gw->lastouttime + 20 < t)) { 00685 ast_log(LOG_NOTICE, "Timeout waiting for response to message:%d, lastouttime: %ld, now: %ld. Dumping pending queue\n", 00686 gw->msgs ? gw->msgs->seqno : -1, (long) gw->lastouttime, (long) t); 00687 dump_queue(sub->parent); 00688 } 00689 */ 00690 msg->owner_sub = sub; 00691 msg->owner_ep = p; 00692 msg->seqno = seqno; 00693 msg->next = NULL; 00694 msg->len = len; 00695 msg->retrans = 0; 00696 memcpy(msg->buf, data, msg->len); 00697 00698 ast_mutex_lock(&gw->msgs_lock); 00699 cur = gw->msgs; 00700 if (cur) { 00701 while(cur->next) 00702 cur = cur->next; 00703 cur->next = msg; 00704 } else { 00705 gw->msgs = msg; 00706 } 00707 00708 if (gettimeofday(&tv, NULL) < 0) { 00709 /* This shouldn't ever happen, but let's be sure */ 00710 ast_log(LOG_NOTICE, "gettimeofday() failed!\n"); 00711 } else { 00712 msg->expire = tv.tv_sec * 1000 + tv.tv_usec / 1000 + DEFAULT_RETRANS; 00713 00714 if (gw->retransid == -1) 00715 gw->retransid = ast_sched_add(sched, DEFAULT_RETRANS, retrans_pkt, (void *)gw); 00716 } 00717 ast_mutex_unlock(&gw->msgs_lock); 00718 /* SC 00719 if (!gw->messagepending) { 00720 gw->messagepending = 1; 00721 gw->lastout = seqno; 00722 gw->lastouttime = t; 00723 */ 00724 __mgcp_xmit(gw, msg->buf, msg->len); 00725 /* XXX Should schedule retransmission XXX */ 00726 /* SC 00727 } else 00728 ast_log(LOG_DEBUG, "Deferring transmission of transaction %d\n", seqno); 00729 */ 00730 return 0; 00731 }
static void mgcp_queue_control | ( | struct mgcp_subchannel * | sub, | |
int | control | |||
) | [static] |
Definition at line 599 of file chan_mgcp.c.
References AST_FRAME_CONTROL, f, and mgcp_queue_frame().
Referenced by handle_hd_hf().
00600 { 00601 struct ast_frame f = { AST_FRAME_CONTROL, }; 00602 f.subclass = control; 00603 return mgcp_queue_frame(sub, &f); 00604 }
static void mgcp_queue_frame | ( | struct mgcp_subchannel * | sub, | |
struct ast_frame * | f | |||
) | [static] |
Definition at line 563 of file chan_mgcp.c.
References ast_mutex_lock(), ast_mutex_trylock(), ast_mutex_unlock(), ast_queue_frame(), f, mgcp_subchannel::lock, ast_channel::lock, and mgcp_subchannel::owner.
Referenced by handle_request(), and mgcp_queue_control().
00564 { 00565 for(;;) { 00566 if (sub->owner) { 00567 if (!ast_mutex_trylock(&sub->owner->lock)) { 00568 ast_queue_frame(sub->owner, f); 00569 ast_mutex_unlock(&sub->owner->lock); 00570 break; 00571 } else { 00572 ast_mutex_unlock(&sub->lock); 00573 usleep(1); 00574 ast_mutex_lock(&sub->lock); 00575 } 00576 } else 00577 break; 00578 } 00579 }
static void mgcp_queue_hangup | ( | struct mgcp_subchannel * | sub | ) | [static] |
Definition at line 581 of file chan_mgcp.c.
References ast_mutex_lock(), ast_mutex_trylock(), ast_mutex_unlock(), ast_queue_hangup(), mgcp_subchannel::lock, ast_channel::lock, and mgcp_subchannel::owner.
Referenced by attempt_transfer(), handle_request(), and handle_response().
00582 { 00583 for(;;) { 00584 if (sub->owner) { 00585 if (!ast_mutex_trylock(&sub->owner->lock)) { 00586 ast_queue_hangup(sub->owner); 00587 ast_mutex_unlock(&sub->owner->lock); 00588 break; 00589 } else { 00590 ast_mutex_unlock(&sub->lock); 00591 usleep(1); 00592 ast_mutex_lock(&sub->lock); 00593 } 00594 } else 00595 break; 00596 } 00597 }
static struct ast_frame * mgcp_read | ( | struct ast_channel * | ast | ) | [static] |
Definition at line 1217 of file chan_mgcp.c.
References ast_mutex_lock(), ast_mutex_unlock(), f, mgcp_subchannel::lock, mgcp_rtp_read(), and ast_channel::tech_pvt.
01218 { 01219 struct ast_frame *f; 01220 struct mgcp_subchannel *sub = ast->tech_pvt; 01221 ast_mutex_lock(&sub->lock); 01222 f = mgcp_rtp_read(sub); 01223 ast_mutex_unlock(&sub->lock); 01224 return f; 01225 }
static int mgcp_reload | ( | int | fd, | |
int | argc, | |||
char * | argv[] | |||
) | [static] |
Definition at line 4283 of file chan_mgcp.c.
References ast_log(), ast_mutex_lock(), ast_mutex_unlock(), ast_verbose(), LOG_WARNING, mgcp_reloading, and restart_monitor().
Referenced by reload(), and unload_module().
04284 { 04285 static int deprecated = 0; 04286 if (!deprecated && argc > 0) { 04287 ast_log(LOG_WARNING, "'mgcp reload' is deprecated. Please use 'reload chan_mgcp.so' instead.\n"); 04288 deprecated = 1; 04289 } 04290 04291 ast_mutex_lock(&mgcp_reload_lock); 04292 if (mgcp_reloading) { 04293 ast_verbose("Previous mgcp reload not yet done\n"); 04294 } else 04295 mgcp_reloading = 1; 04296 ast_mutex_unlock(&mgcp_reload_lock); 04297 restart_monitor(); 04298 return 0; 04299 }
static struct ast_channel * mgcp_request | ( | const char * | type, | |
int | format, | |||
void * | data, | |||
int * | cause | |||
) | [static] |
Definition at line 3499 of file chan_mgcp.c.
References AST_CAUSE_BUSY, AST_CAUSE_UNREGISTERED, ast_log(), ast_mutex_unlock(), AST_STATE_DOWN, ast_strlen_zero(), ast_verbose(), mgcp_endpoint::call_forward, mgcp_endpoint::callwaiting, capability, mgcp_endpoint::dnd, find_subchannel_and_lock(), has_voicemail(), mgcp_endpoint::hookstate, mgcp_subchannel::lock, LOG_NOTICE, LOG_WARNING, mgcp_new(), MGCP_ONHOOK, mgcp_subchannel::next, option_verbose, mgcp_subchannel::owner, mgcp_subchannel::parent, restart_monitor(), transmit_notify_request(), and VERBOSE_PREFIX_3.
03500 { 03501 int oldformat; 03502 struct mgcp_subchannel *sub; 03503 struct ast_channel *tmpc = NULL; 03504 char tmp[256]; 03505 char *dest = data; 03506 03507 oldformat = format; 03508 format &= capability; 03509 if (!format) { 03510 ast_log(LOG_NOTICE, "Asked to get a channel of unsupported format '%d'\n", format); 03511 return NULL; 03512 } 03513 ast_copy_string(tmp, dest, sizeof(tmp)); 03514 if (ast_strlen_zero(tmp)) { 03515 ast_log(LOG_NOTICE, "MGCP Channels require an endpoint\n"); 03516 return NULL; 03517 } 03518 sub = find_subchannel_and_lock(tmp, 0, NULL); 03519 if (!sub) { 03520 ast_log(LOG_WARNING, "Unable to find MGCP endpoint '%s'\n", tmp); 03521 *cause = AST_CAUSE_UNREGISTERED; 03522 return NULL; 03523 } 03524 03525 if (option_verbose > 2) { 03526 ast_verbose(VERBOSE_PREFIX_3 "MGCP mgcp_request(%s)\n", tmp); 03527 ast_verbose(VERBOSE_PREFIX_3 "MGCP cw: %d, dnd: %d, so: %d, sno: %d\n", 03528 sub->parent->callwaiting, sub->parent->dnd, sub->owner ? 1 : 0, sub->next->owner ? 1: 0); 03529 } 03530 /* Must be busy */ 03531 if (((sub->parent->callwaiting) && ((sub->owner) && (sub->next->owner))) || 03532 ((!sub->parent->callwaiting) && (sub->owner)) || 03533 (sub->parent->dnd && (ast_strlen_zero(sub->parent->call_forward)))) { 03534 if (sub->parent->hookstate == MGCP_ONHOOK) { 03535 if (has_voicemail(sub->parent)) { 03536 transmit_notify_request(sub,"L/vmwi(+)"); 03537 } else { 03538 transmit_notify_request(sub,"L/vmwi(-)"); 03539 } 03540 } 03541 *cause = AST_CAUSE_BUSY; 03542 ast_mutex_unlock(&sub->lock); 03543 return NULL; 03544 } 03545 tmpc = mgcp_new(sub->owner ? sub->next : sub, AST_STATE_DOWN); 03546 ast_mutex_unlock(&sub->lock); 03547 if (!tmpc) 03548 ast_log(LOG_WARNING, "Unable to make channel for '%s'\n", tmp); 03549 restart_monitor(); 03550 return tmpc; 03551 }
static struct ast_frame* mgcp_rtp_read | ( | struct mgcp_subchannel * | sub | ) | [static] |
Definition at line 1186 of file chan_mgcp.c.
References ast_dsp_process(), AST_FRAME_DTMF, AST_FRAME_VOICE, ast_log(), ast_null_frame, ast_rtp_read(), ast_set_read_format(), ast_set_write_format(), mgcp_endpoint::dsp, mgcp_endpoint::dtmfmode, f, LOG_DEBUG, LOG_NOTICE, MGCP_DTMF_INBAND, MGCP_DTMF_RFC2833, ast_channel::nativeformats, mgcp_subchannel::owner, mgcp_subchannel::parent, ast_channel::readformat, mgcp_subchannel::rtp, and ast_channel::writeformat.
Referenced by mgcp_read().
01187 { 01188 /* Retrieve audio/etc from channel. Assumes sub->lock is already held. */ 01189 struct ast_frame *f; 01190 01191 f = ast_rtp_read(sub->rtp); 01192 /* Don't send RFC2833 if we're not supposed to */ 01193 if (f && (f->frametype == AST_FRAME_DTMF) && !(sub->parent->dtmfmode & MGCP_DTMF_RFC2833)) 01194 return &ast_null_frame; 01195 if (sub->owner) { 01196 /* We already hold the channel lock */ 01197 if (f->frametype == AST_FRAME_VOICE) { 01198 if (f->subclass != sub->owner->nativeformats) { 01199 ast_log(LOG_DEBUG, "Oooh, format changed to %d\n", f->subclass); 01200 sub->owner->nativeformats = f->subclass; 01201 ast_set_read_format(sub->owner, sub->owner->readformat); 01202 ast_set_write_format(sub->owner, sub->owner->writeformat); 01203 } 01204 /* Courtesy fearnor aka alex@pilosoft.com */ 01205 if ((sub->parent->dtmfmode & MGCP_DTMF_INBAND) && (sub->parent->dsp)) { 01206 #if 0 01207 ast_log(LOG_NOTICE, "MGCP ast_dsp_process\n"); 01208 #endif 01209 f = ast_dsp_process(sub->owner, sub->parent->dsp, f); 01210 } 01211 } 01212 } 01213 return f; 01214 }
static int mgcp_senddigit_begin | ( | struct ast_channel * | ast, | |
char | digit | |||
) | [static] |
static int mgcp_senddigit_end | ( | struct ast_channel * | ast, | |
char | digit, | |||
unsigned int | duration | |||
) | [static] |
Definition at line 1279 of file chan_mgcp.c.
References ast_mutex_lock(), ast_mutex_unlock(), mgcp_subchannel::lock, ast_channel::tech_pvt, and transmit_notify_request().
01280 { 01281 struct mgcp_subchannel *sub = ast->tech_pvt; 01282 char tmp[4]; 01283 01284 tmp[0] = 'D'; 01285 tmp[1] = '/'; 01286 tmp[2] = digit; 01287 tmp[3] = '\0'; 01288 ast_mutex_lock(&sub->lock); 01289 transmit_notify_request(sub, tmp); 01290 ast_mutex_unlock(&sub->lock); 01291 return -1; /* Return non-zero so that Asterisk will stop the inband indications */ 01292 }
static int mgcp_set_rtp_peer | ( | struct ast_channel * | chan, | |
struct ast_rtp * | rtp, | |||
struct ast_rtp * | vrtp, | |||
int | codecs, | |||
int | nat_active | |||
) | [static] |
Definition at line 3948 of file chan_mgcp.c.
References mgcp_subchannel::alreadygone, mgcp_subchannel::rtp, ast_channel::tech_pvt, and transmit_modify_with_sdp().
03949 { 03950 /* XXX Is there such thing as video support with MGCP? XXX */ 03951 struct mgcp_subchannel *sub; 03952 sub = chan->tech_pvt; 03953 if (sub && !sub->alreadygone) { 03954 transmit_modify_with_sdp(sub, rtp, codecs); 03955 return 0; 03956 } 03957 return -1; 03958 }
static int mgcp_show_endpoints | ( | int | fd, | |
int | argc, | |||
char * | argv[] | |||
) | [static] |
Definition at line 1013 of file chan_mgcp.c.
References mgcp_gateway::addr, ast_cli(), ast_inet_ntoa(), ast_mutex_lock(), ast_mutex_unlock(), mgcp_endpoint::context, mgcp_gateway::defaddr, mgcp_gateway::dynamic, mgcp_gateway::endpoints, gateways, mgcp_endpoint::name, mgcp_gateway::name, mgcp_gateway::next, mgcp_endpoint::next, mgcp_subchannel::owner, RESULT_SHOWUSAGE, RESULT_SUCCESS, mgcp_endpoint::sub, and mgcp_gateway::wcardep.
01014 { 01015 struct mgcp_gateway *g; 01016 struct mgcp_endpoint *e; 01017 int hasendpoints = 0; 01018 01019 if (argc != 3) 01020 return RESULT_SHOWUSAGE; 01021 ast_mutex_lock(&gatelock); 01022 g = gateways; 01023 while(g) { 01024 e = g->endpoints; 01025 ast_cli(fd, "Gateway '%s' at %s (%s)\n", g->name, g->addr.sin_addr.s_addr ? ast_inet_ntoa(g->addr.sin_addr) : ast_inet_ntoa(g->defaddr.sin_addr), g->dynamic ? "Dynamic" : "Static"); 01026 while(e) { 01027 /* Don't show wilcard endpoint */ 01028 if (strcmp(e->name, g->wcardep) !=0) 01029 ast_cli(fd, " -- '%s@%s in '%s' is %s\n", e->name, g->name, e->context, e->sub->owner ? "active" : "idle"); 01030 hasendpoints = 1; 01031 e = e->next; 01032 } 01033 if (!hasendpoints) { 01034 ast_cli(fd, " << No Endpoints Defined >> "); 01035 } 01036 g = g->next; 01037 } 01038 ast_mutex_unlock(&gatelock); 01039 return RESULT_SUCCESS; 01040 }
static void* mgcp_ss | ( | void * | data | ) | [static] |
Definition at line 2604 of file chan_mgcp.c.
References ast_bridged_channel(), ast_canmatch_extension(), ast_db_put(), ast_exists_extension(), ast_hangup(), ast_ignore_pattern(), ast_indicate(), ast_log(), ast_masq_park_call(), ast_matchmore_extension(), AST_MAX_EXTENSION, ast_parking_ext(), ast_pbx_run(), ast_pickup_call(), ast_pickup_ext(), ast_say_digit_str(), ast_set_callerid(), ast_setstate(), AST_STATE_RING, ast_strlen_zero(), ast_verbose(), ast_waitfordigit(), mgcp_endpoint::call_forward, mgcp_endpoint::callreturn, mgcp_endpoint::callwaiting, mgcp_endpoint::cancallforward, ast_channel::cid, ast_callerid::cid_ani, mgcp_endpoint::cid_name, ast_callerid::cid_num, mgcp_endpoint::cid_num, ast_channel::context, mgcp_endpoint::dnd, mgcp_endpoint::dtmfmode, ast_channel::exten, exten, firstdigittimeout, gendigittimeout, mgcp_endpoint::hascallwaiting, mgcp_endpoint::hidecallerid, mgcp_endpoint::lastcallerid, len, LOG_DEBUG, LOG_WARNING, matchdigittimeout, MGCP_DTMF_HYBRID, MGCP_DTMF_INBAND, mgcp_subchannel::next, option_debug, option_verbose, mgcp_subchannel::owner, mgcp_subchannel::parent, ast_channel::rings, start_rtp(), mgcp_endpoint::sub, ast_channel::tech_pvt, timeout, transmit_notify_request(), and VERBOSE_PREFIX_3.
Referenced by handle_hd_hf().
02605 { 02606 struct ast_channel *chan = data; 02607 struct mgcp_subchannel *sub = chan->tech_pvt; 02608 struct mgcp_endpoint *p = sub->parent; 02609 char exten[AST_MAX_EXTENSION] = ""; 02610 int len = 0; 02611 int timeout = firstdigittimeout; 02612 int res; 02613 int getforward = 0; 02614 02615 while(len < AST_MAX_EXTENSION-1) { 02616 res = ast_waitfordigit(chan, timeout); 02617 timeout = 0; 02618 if (res < 0) { 02619 ast_log(LOG_DEBUG, "waitfordigit returned < 0...\n"); 02620 /*res = tone_zone_play_tone(p->subs[index].zfd, -1);*/ 02621 ast_indicate(chan, -1); 02622 ast_hangup(chan); 02623 return NULL; 02624 } else if (res) { 02625 exten[len++]=res; 02626 exten[len] = '\0'; 02627 } 02628 if (!ast_ignore_pattern(chan->context, exten)) { 02629 /*res = tone_zone_play_tone(p->subs[index].zfd, -1);*/ 02630 ast_indicate(chan, -1); 02631 } else { 02632 /* XXX Redundant? We should already be playing dialtone */ 02633 /*tone_zone_play_tone(p->subs[index].zfd, ZT_TONE_DIALTONE);*/ 02634 transmit_notify_request(sub, "L/dl"); 02635 } 02636 if (ast_exists_extension(chan, chan->context, exten, 1, p->cid_num)) { 02637 if (!res || !ast_matchmore_extension(chan, chan->context, exten, 1, p->cid_num)) { 02638 if (getforward) { 02639 /* Record this as the forwarding extension */ 02640 ast_copy_string(p->call_forward, exten, sizeof(p->call_forward)); 02641 if (option_verbose > 2) { 02642 ast_verbose(VERBOSE_PREFIX_3 "Setting call forward to '%s' on channel %s\n", 02643 p->call_forward, chan->name); 02644 } 02645 /*res = tone_zone_play_tone(p->subs[index].zfd, ZT_TONE_DIALRECALL);*/ 02646 transmit_notify_request(sub, "L/sl"); 02647 if (res) 02648 break; 02649 usleep(500000); 02650 /*res = tone_zone_play_tone(p->subs[index].zfd, -1);*/ 02651 ast_indicate(chan, -1); 02652 sleep(1); 02653 memset(exten, 0, sizeof(exten)); 02654 /*res = tone_zone_play_tone(p->subs[index].zfd, ZT_TONE_DIALTONE);*/ 02655 transmit_notify_request(sub, "L/dl"); 02656 len = 0; 02657 getforward = 0; 02658 } else { 02659 /*res = tone_zone_play_tone(p->subs[index].zfd, -1);*/ 02660 ast_indicate(chan, -1); 02661 ast_copy_string(chan->exten, exten, sizeof(chan->exten)); 02662 ast_set_callerid(chan, 02663 p->hidecallerid ? "" : p->cid_num, 02664 p->hidecallerid ? "" : p->cid_name, 02665 chan->cid.cid_ani ? NULL : p->cid_num); 02666 ast_setstate(chan, AST_STATE_RING); 02667 /*zt_enable_ec(p);*/ 02668 if (p->dtmfmode & MGCP_DTMF_HYBRID) { 02669 p->dtmfmode |= MGCP_DTMF_INBAND; 02670 ast_indicate(chan, -1); 02671 } 02672 res = ast_pbx_run(chan); 02673 if (res) { 02674 ast_log(LOG_WARNING, "PBX exited non-zero\n"); 02675 /*res = tone_zone_play_tone(p->subs[index].zfd, ZT_TONE_CONGESTION);*/ 02676 /*transmit_notify_request(p, "nbz", 1);*/ 02677 transmit_notify_request(sub, "G/cg"); 02678 } 02679 return NULL; 02680 } 02681 } else { 02682 /* It's a match, but they just typed a digit, and there is an ambiguous match, 02683 so just set the timeout to matchdigittimeout and wait some more */ 02684 timeout = matchdigittimeout; 02685 } 02686 } else if (res == 0) { 02687 ast_log(LOG_DEBUG, "not enough digits (and no ambiguous match)...\n"); 02688 /*res = tone_zone_play_tone(p->subs[index].zfd, ZT_TONE_CONGESTION);*/ 02689 transmit_notify_request(sub, "G/cg"); 02690 /*zt_wait_event(p->subs[index].zfd);*/ 02691 ast_hangup(chan); 02692 return NULL; 02693 } else if (p->hascallwaiting && p->callwaiting && !strcmp(exten, "*70")) { 02694 if (option_verbose > 2) { 02695 ast_verbose(VERBOSE_PREFIX_3 "Disabling call waiting on %s\n", chan->name); 02696 } 02697 /* Disable call waiting if enabled */ 02698 p->callwaiting = 0; 02699 /*res = tone_zone_play_tone(p->subs[index].zfd, ZT_TONE_DIALRECALL);*/ 02700 transmit_notify_request(sub, "L/sl"); 02701 len = 0; 02702 memset(exten, 0, sizeof(exten)); 02703 timeout = firstdigittimeout; 02704 } else if (!strcmp(exten,ast_pickup_ext())) { 02705 /* Scan all channels and see if any there 02706 * ringing channqels with that have call groups 02707 * that equal this channels pickup group 02708 */ 02709 if (ast_pickup_call(chan)) { 02710 ast_log(LOG_WARNING, "No call pickup possible...\n"); 02711 /*res = tone_zone_play_tone(p->subs[index].zfd, ZT_TONE_CONGESTION);*/ 02712 transmit_notify_request(sub, "G/cg"); 02713 } 02714 ast_hangup(chan); 02715 return NULL; 02716 } else if (!p->hidecallerid && !strcmp(exten, "*67")) { 02717 if (option_verbose > 2) { 02718 ast_verbose(VERBOSE_PREFIX_3 "Disabling Caller*ID on %s\n", chan->name); 02719 } 02720 /* Disable Caller*ID if enabled */ 02721 p->hidecallerid = 1; 02722 ast_set_callerid(chan, "", "", NULL); 02723 /*res = tone_zone_play_tone(p->subs[index].zfd, ZT_TONE_DIALRECALL);*/ 02724 transmit_notify_request(sub, "L/sl"); 02725 len = 0; 02726 memset(exten, 0, sizeof(exten)); 02727 timeout = firstdigittimeout; 02728 } else if (p->callreturn && !strcmp(exten, "*69")) { 02729 res = 0; 02730 if (!ast_strlen_zero(p->lastcallerid)) { 02731 res = ast_say_digit_str(chan, p->lastcallerid, "", chan->language); 02732 } 02733 if (!res) 02734 /*res = tone_zone_play_tone(p->subs[index].zfd, ZT_TONE_DIALRECALL);*/ 02735 transmit_notify_request(sub, "L/sl"); 02736 break; 02737 } else if (!strcmp(exten, "*78")) { 02738 /* Do not disturb */ 02739 if (option_verbose > 2) { 02740 ast_verbose(VERBOSE_PREFIX_3 "Enabled DND on channel %s\n", chan->name); 02741 } 02742 /*res = tone_zone_play_tone(p->subs[index].zfd, ZT_TONE_DIALRECALL);*/ 02743 transmit_notify_request(sub, "L/sl"); 02744 p->dnd = 1; 02745 getforward = 0; 02746 memset(exten, 0, sizeof(exten)); 02747 len = 0; 02748 } else if (!strcmp(exten, "*79")) { 02749 /* Do not disturb */ 02750 if (option_verbose > 2) { 02751 ast_verbose(VERBOSE_PREFIX_3 "Disabled DND on channel %s\n", chan->name); 02752 } 02753 /*res = tone_zone_play_tone(p->subs[index].zfd, ZT_TONE_DIALRECALL);*/ 02754 transmit_notify_request(sub, "L/sl"); 02755 p->dnd = 0; 02756 getforward = 0; 02757 memset(exten, 0, sizeof(exten)); 02758 len = 0; 02759 } else if (p->cancallforward && !strcmp(exten, "*72")) { 02760 /*res = tone_zone_play_tone(p->subs[index].zfd, ZT_TONE_DIALRECALL);*/ 02761 transmit_notify_request(sub, "L/sl"); 02762 getforward = 1; 02763 memset(exten, 0, sizeof(exten)); 02764 len = 0; 02765 } else if (p->cancallforward && !strcmp(exten, "*73")) { 02766 if (option_verbose > 2) { 02767 ast_verbose(VERBOSE_PREFIX_3 "Cancelling call forwarding on channel %s\n", chan->name); 02768 } 02769 /*res = tone_zone_play_tone(p->subs[index].zfd, ZT_TONE_DIALRECALL);*/ 02770 transmit_notify_request(sub, "L/sl"); 02771 memset(p->call_forward, 0, sizeof(p->call_forward)); 02772 getforward = 0; 02773 memset(exten, 0, sizeof(exten)); 02774 len = 0; 02775 } else if (!strcmp(exten, ast_parking_ext()) && 02776 sub->next->owner && ast_bridged_channel(sub->next->owner)) { 02777 /* This is a three way call, the main call being a real channel, 02778 and we're parking the first call. */ 02779 ast_masq_park_call(ast_bridged_channel(sub->next->owner), chan, 0, NULL); 02780 if (option_verbose > 2) { 02781 ast_verbose(VERBOSE_PREFIX_3 "Parking call to '%s'\n", chan->name); 02782 } 02783 break; 02784 } else if (!ast_strlen_zero(p->lastcallerid) && !strcmp(exten, "*60")) { 02785 if (option_verbose > 2) { 02786 ast_verbose(VERBOSE_PREFIX_3 "Blacklisting number %s\n", p->lastcallerid); 02787 } 02788 res = ast_db_put("blacklist", p->lastcallerid, "1"); 02789 if (!res) { 02790 /*res = tone_zone_play_tone(p->subs[index].zfd, ZT_TONE_DIALRECALL);*/ 02791 transmit_notify_request(sub, "L/sl"); 02792 memset(exten, 0, sizeof(exten)); 02793 len = 0; 02794 } 02795 } else if (p->hidecallerid && !strcmp(exten, "*82")) { 02796 if (option_verbose > 2) { 02797 ast_verbose(VERBOSE_PREFIX_3 "Enabling Caller*ID on %s\n", chan->name); 02798 } 02799 /* Enable Caller*ID if enabled */ 02800 p->hidecallerid = 0; 02801 ast_set_callerid(chan, p->cid_num, p->cid_name, NULL); 02802 /*res = tone_zone_play_tone(p->subs[index].zfd, ZT_TONE_DIALRECALL);*/ 02803 transmit_notify_request(sub, "L/sl"); 02804 len = 0; 02805 memset(exten, 0, sizeof(exten)); 02806 timeout = firstdigittimeout; 02807 } else if (!ast_canmatch_extension(chan, chan->context, exten, 1, chan->cid.cid_num) && 02808 ((exten[0] != '*') || (strlen(exten) > 2))) { 02809 if (option_debug) 02810 ast_log(LOG_DEBUG, "Can't match %s from '%s' in context %s\n", exten, chan->cid.cid_num ? chan->cid.cid_num : "<Unknown Caller>", chan->context); 02811 break; 02812 } 02813 if (!timeout) 02814 timeout = gendigittimeout; 02815 if (len && !ast_ignore_pattern(chan->context, exten)) 02816 /*tone_zone_play_tone(p->subs[index].zfd, -1);*/ 02817 ast_indicate(chan, -1); 02818 } 02819 #if 0 02820 for (;;) { 02821 res = ast_waitfordigit(chan, to); 02822 if (!res) { 02823 ast_log(LOG_DEBUG, "Timeout...\n"); 02824 break; 02825 } 02826 if (res < 0) { 02827 ast_log(LOG_DEBUG, "Got hangup...\n"); 02828 ast_hangup(chan); 02829 break; 02830 } 02831 exten[pos++] = res; 02832 if (!ast_ignore_pattern(chan->context, exten)) 02833 ast_indicate(chan, -1); 02834 if (ast_matchmore_extension(chan, chan->context, exten, 1, chan->callerid)) { 02835 if (ast_exists_extension(chan, chan->context, exten, 1, chan->callerid)) 02836 to = 3000; 02837 else 02838 to = 8000; 02839 } else 02840 break; 02841 } 02842 if (ast_exists_extension(chan, chan->context, exten, 1, chan->callerid)) { 02843 ast_copy_string(chan->exten, exten, sizeof(chan->exten)1); 02844 if (!p->rtp) { 02845 start_rtp(p); 02846 } 02847 ast_setstate(chan, AST_STATE_RING); 02848 chan->rings = 1; 02849 if (ast_pbx_run(chan)) { 02850 ast_log(LOG_WARNING, "Unable to launch PBX on %s\n", chan->name); 02851 } else 02852 return NULL; 02853 } 02854 #endif 02855 ast_hangup(chan); 02856 return NULL; 02857 }
static int mgcp_write | ( | struct ast_channel * | ast, | |
struct ast_frame * | frame | |||
) | [static] |
Definition at line 1227 of file chan_mgcp.c.
References AST_FRAME_IMAGE, AST_FRAME_VOICE, ast_log(), ast_mutex_lock(), ast_mutex_unlock(), ast_rtp_write(), ast_frame::frametype, mgcp_subchannel::lock, LOG_WARNING, ast_channel::nativeformats, mgcp_subchannel::parent, ast_channel::readformat, mgcp_subchannel::rtp, mgcp_endpoint::singlepath, mgcp_endpoint::sub, ast_frame::subclass, ast_channel::tech_pvt, and ast_channel::writeformat.
01228 { 01229 struct mgcp_subchannel *sub = ast->tech_pvt; 01230 int res = 0; 01231 if (frame->frametype != AST_FRAME_VOICE) { 01232 if (frame->frametype == AST_FRAME_IMAGE) 01233 return 0; 01234 else { 01235 ast_log(LOG_WARNING, "Can't send %d type frames with MGCP write\n", frame->frametype); 01236 return 0; 01237 } 01238 } else { 01239 if (!(frame->subclass & ast->nativeformats)) { 01240 ast_log(LOG_WARNING, "Asked to transmit frame type %d, while native formats is %d (read/write = %d/%d)\n", 01241 frame->subclass, ast->nativeformats, ast->readformat, ast->writeformat); 01242 return -1; 01243 } 01244 } 01245 if (sub) { 01246 ast_mutex_lock(&sub->lock); 01247 if ((sub->parent->sub == sub) || !sub->parent->singlepath) { 01248 if (sub->rtp) { 01249 res = ast_rtp_write(sub->rtp, frame); 01250 } 01251 } 01252 ast_mutex_unlock(&sub->lock); 01253 } 01254 return res; 01255 }
static int mgcpsock_read | ( | int * | id, | |
int | fd, | |||
short | events, | |||
void * | ignore | |||
) | [static] |
Definition at line 3294 of file chan_mgcp.c.
References ast_inet_ntoa(), ast_log(), ast_mutex_lock(), ast_mutex_unlock(), ast_sched_del(), ast_strlen_zero(), ast_verbose(), find_and_retrans(), find_subchannel_and_lock(), free, handle_request(), handle_response(), len, mgcp_subchannel::lock, LOG_DEBUG, LOG_NOTICE, LOG_WARNING, mgcpsock, mgcp_gateway::msgs, mgcp_gateway::msgs_lock, mgcp_gateway::name, mgcp_message::next, mgcp_message::owner_ep, mgcp_message::owner_sub, mgcp_endpoint::parent, mgcp_subchannel::parent, parse(), result, mgcp_gateway::retransid, and mgcp_message::seqno.
Referenced by do_monitor().
03295 { 03296 struct mgcp_request req; 03297 struct sockaddr_in sin; 03298 struct mgcp_subchannel *sub; 03299 int res; 03300 socklen_t len; 03301 int result; 03302 int ident; 03303 len = sizeof(sin); 03304 memset(&req, 0, sizeof(req)); 03305 res = recvfrom(mgcpsock, req.data, sizeof(req.data) - 1, 0, (struct sockaddr *)&sin, &len); 03306 if (res < 0) { 03307 if (errno != ECONNREFUSED) 03308 ast_log(LOG_WARNING, "Recv error: %s\n", strerror(errno)); 03309 return 1; 03310 } 03311 req.data[res] = '\0'; 03312 req.len = res; 03313 if (mgcpdebug) { 03314 ast_verbose("MGCP read: \n%s\nfrom %s:%d\n", req.data, ast_inet_ntoa(sin.sin_addr), ntohs(sin.sin_port)); 03315 } 03316 parse(&req); 03317 if (req.headers < 1) { 03318 /* Must have at least one header */ 03319 return 1; 03320 } 03321 if (ast_strlen_zero(req.identifier)) { 03322 ast_log(LOG_NOTICE, "Message from %s missing identifier\n", ast_inet_ntoa(sin.sin_addr)); 03323 return 1; 03324 } 03325 03326 if (sscanf(req.verb, "%d", &result) && sscanf(req.identifier, "%d", &ident)) { 03327 /* Try to find who this message is for, if it's important */ 03328 sub = find_subchannel_and_lock(NULL, ident, &sin); 03329 if (sub) { 03330 struct mgcp_gateway *gw = sub->parent->parent; 03331 struct mgcp_message *cur, *prev; 03332 03333 ast_mutex_unlock(&sub->lock); 03334 ast_mutex_lock(&gw->msgs_lock); 03335 for (prev = NULL, cur = gw->msgs; cur; prev = cur, cur = cur->next) { 03336 if (cur->seqno == ident) { 03337 ast_log(LOG_DEBUG, "Got response back on transaction %d\n", ident); 03338 if (prev) 03339 prev->next = cur->next; 03340 else 03341 gw->msgs = cur->next; 03342 break; 03343 } 03344 } 03345 03346 /* stop retrans timer if the queue is empty */ 03347 if (!gw->msgs && (gw->retransid != -1)) { 03348 ast_sched_del(sched, gw->retransid); 03349 gw->retransid = -1; 03350 } 03351 03352 ast_mutex_unlock(&gw->msgs_lock); 03353 if (cur) { 03354 handle_response(cur->owner_ep, cur->owner_sub, result, ident, &req); 03355 free(cur); 03356 return 1; 03357 } 03358 03359 ast_log(LOG_NOTICE, "Got response back on [%s] for transaction %d we aren't sending?\n", 03360 gw->name, ident); 03361 } 03362 } else { 03363 if (ast_strlen_zero(req.endpoint) || 03364 ast_strlen_zero(req.version) || 03365 ast_strlen_zero(req.verb)) { 03366 ast_log(LOG_NOTICE, "Message must have a verb, an idenitifier, version, and endpoint\n"); 03367 return 1; 03368 } 03369 /* Process request, with iflock held */ 03370 sub = find_subchannel_and_lock(req.endpoint, 0, &sin); 03371 if (sub) { 03372 /* look first to find a matching response in the queue */ 03373 if (!find_and_retrans(sub, &req)) 03374 /* pass the request off to the currently mastering subchannel */ 03375 handle_request(sub, &req, &sin); 03376 ast_mutex_unlock(&sub->lock); 03377 } 03378 } 03379 return 1; 03380 }
static void parse | ( | struct mgcp_request * | req | ) | [static] |
Definition at line 1700 of file chan_mgcp.c.
References ast_log(), ast_strlen_zero(), ast_verbose(), mgcp_request::data, mgcp_request::endpoint, f, mgcp_request::header, mgcp_request::headers, mgcp_request::identifier, mgcp_request::line, mgcp_request::lines, LOG_WARNING, MGCP_MAX_HEADERS, MGCP_MAX_LINES, mgcpdebug, mgcp_request::verb, and mgcp_request::version.
Referenced by __login_exec(), acf_channel_read(), add_agent(), app_exec(), aqm_exec(), ast_hint_state_changed(), ast_parse_allow_disallow(), astman_get_variables(), cut_internal(), dictate_exec(), directory_exec(), find_conf(), function_agent(), get_in_brackets(), isAnsweringMachine(), mgcpsock_read(), mixmonitor_exec(), pbx_builtin_background(), pbx_builtin_waitexten(), pqm_exec(), privacy_exec(), ql_exec(), queue_exec(), reload_agents(), reload_queues(), rqm_exec(), sayunixtime_exec(), sendimage_exec(), sendtext_exec(), transfer_exec(), upqm_exec(), userevent_exec(), and vm_execmain().
01701 { 01702 /* Divide fields by NULL's */ 01703 char *c; 01704 int f = 0; 01705 c = req->data; 01706 01707 /* First header starts immediately */ 01708 req->header[f] = c; 01709 while(*c) { 01710 if (*c == '\n') { 01711 /* We've got a new header */ 01712 *c = 0; 01713 #if 0 01714 printf("Header: %s (%d)\n", req->header[f], strlen(req->header[f])); 01715 #endif 01716 if (ast_strlen_zero(req->header[f])) { 01717 /* Line by itself means we're now in content */ 01718 c++; 01719 break; 01720 } 01721 if (f >= MGCP_MAX_HEADERS - 1) { 01722 ast_log(LOG_WARNING, "Too many MGCP headers...\n"); 01723 } else 01724 f++; 01725 req->header[f] = c + 1; 01726 } else if (*c == '\r') { 01727 /* Ignore but eliminate \r's */ 01728 *c = 0; 01729 } 01730 c++; 01731 } 01732 /* Check for last header */ 01733 if (!ast_strlen_zero(req->header[f])) 01734 f++; 01735 req->headers = f; 01736 /* Now we process any mime content */ 01737 f = 0; 01738 req->line[f] = c; 01739 while(*c) { 01740 if (*c == '\n') { 01741 /* We've got a new line */ 01742 *c = 0; 01743 #if 0 01744 printf("Line: %s (%d)\n", req->line[f], strlen(req->line[f])); 01745 #endif 01746 if (f >= MGCP_MAX_LINES - 1) { 01747 ast_log(LOG_WARNING, "Too many SDP lines...\n"); 01748 } else 01749 f++; 01750 req->line[f] = c + 1; 01751 } else if (*c == '\r') { 01752 /* Ignore and eliminate \r's */ 01753 *c = 0; 01754 } 01755 c++; 01756 } 01757 /* Check for last line */ 01758 if (!ast_strlen_zero(req->line[f])) 01759 f++; 01760 req->lines = f; 01761 /* Parse up the initial header */ 01762 c = req->header[0]; 01763 while(*c && *c < 33) c++; 01764 /* First the verb */ 01765 req->verb = c; 01766 while(*c && (*c > 32)) c++; 01767 if (*c) { 01768 *c = '\0'; 01769 c++; 01770 while(*c && (*c < 33)) c++; 01771 req->identifier = c; 01772 while(*c && (*c > 32)) c++; 01773 if (*c) { 01774 *c = '\0'; 01775 c++; 01776 while(*c && (*c < 33)) c++; 01777 req->endpoint = c; 01778 while(*c && (*c > 32)) c++; 01779 if (*c) { 01780 *c = '\0'; 01781 c++; 01782 while(*c && (*c < 33)) c++; 01783 req->version = c; 01784 while(*c && (*c > 32)) c++; 01785 while(*c && (*c < 33)) c++; 01786 while(*c && (*c > 32)) c++; 01787 *c = '\0'; 01788 } 01789 } 01790 } 01791 01792 if (mgcpdebug) { 01793 ast_verbose("Verb: '%s', Identifier: '%s', Endpoint: '%s', Version: '%s'\n", 01794 req->verb, req->identifier, req->endpoint, req->version); 01795 ast_verbose("%d headers, %d lines\n", req->headers, req->lines); 01796 } 01797 if (*c) 01798 ast_log(LOG_WARNING, "Odd content, extra stuff left over ('%s')\n", c); 01799 }
static int process_sdp | ( | struct mgcp_subchannel * | sub, | |
struct mgcp_request * | req | |||
) | [static] |
Definition at line 1801 of file chan_mgcp.c.
References ahp, ast_gethostbyname(), ast_inet_ntoa(), ast_log(), ast_rtp_get_current_formats(), ast_rtp_pt_clear(), ast_rtp_set_m_type(), ast_rtp_set_peer(), ast_rtp_set_rtpmap_type(), ast_strdupa, ast_strlen_zero(), ast_verbose(), capability, mgcp_endpoint::capability, get_sdp(), get_sdp_iterate(), hp, len, LOG_WARNING, mgcpdebug, mgcp_endpoint::nonCodecCapability, nonCodecCapability, mgcp_subchannel::parent, portno, mgcp_subchannel::rtp, sdpLineNum_iterator_init(), and mgcp_endpoint::sub.
Referenced by handle_request(), handle_request_invite(), handle_response(), and handle_response_invite().
01802 { 01803 char *m; 01804 char *c; 01805 char *a; 01806 char host[258]; 01807 int len; 01808 int portno; 01809 int peercapability, peerNonCodecCapability; 01810 struct sockaddr_in sin; 01811 char *codecs; 01812 struct ast_hostent ahp; struct hostent *hp; 01813 int codec, codec_count=0; 01814 int iterator; 01815 struct mgcp_endpoint *p = sub->parent; 01816 01817 /* Get codec and RTP info from SDP */ 01818 m = get_sdp(req, "m"); 01819 c = get_sdp(req, "c"); 01820 if (ast_strlen_zero(m) || ast_strlen_zero(c)) { 01821 ast_log(LOG_WARNING, "Insufficient information for SDP (m = '%s', c = '%s')\n", m, c); 01822 return -1; 01823 } 01824 if (sscanf(c, "IN IP4 %256s", host) != 1) { 01825 ast_log(LOG_WARNING, "Invalid host in c= line, '%s'\n", c); 01826 return -1; 01827 } 01828 /* XXX This could block for a long time, and block the main thread! XXX */ 01829 hp = ast_gethostbyname(host, &ahp); 01830 if (!hp) { 01831 ast_log(LOG_WARNING, "Unable to lookup host in c= line, '%s'\n", c); 01832 return -1; 01833 } 01834 if (sscanf(m, "audio %d RTP/AVP %n", &portno, &len) != 1) { 01835 ast_log(LOG_WARNING, "Unable to determine port number for RTP in '%s'\n", m); 01836 return -1; 01837 } 01838 sin.sin_family = AF_INET; 01839 memcpy(&sin.sin_addr, hp->h_addr, sizeof(sin.sin_addr)); 01840 sin.sin_port = htons(portno); 01841 ast_rtp_set_peer(sub->rtp, &sin); 01842 #if 0 01843 printf("Peer RTP is at port %s:%d\n", ast_inet_ntoa(sin.sin_addr), ntohs(sin.sin_port)); 01844 #endif 01845 /* Scan through the RTP payload types specified in a "m=" line: */ 01846 ast_rtp_pt_clear(sub->rtp); 01847 codecs = ast_strdupa(m + len); 01848 while (!ast_strlen_zero(codecs)) { 01849 if (sscanf(codecs, "%d%n", &codec, &len) != 1) { 01850 if (codec_count) 01851 break; 01852 ast_log(LOG_WARNING, "Error in codec string '%s' at '%s'\n", m, codecs); 01853 return -1; 01854 } 01855 ast_rtp_set_m_type(sub->rtp, codec); 01856 codec_count++; 01857 codecs += len; 01858 } 01859 01860 /* Next, scan through each "a=rtpmap:" line, noting each */ 01861 /* specified RTP payload type (with corresponding MIME subtype): */ 01862 sdpLineNum_iterator_init(&iterator); 01863 while ((a = get_sdp_iterate(&iterator, req, "a"))[0] != '\0') { 01864 char* mimeSubtype = ast_strdupa(a); /* ensures we have enough space */ 01865 if (sscanf(a, "rtpmap: %u %[^/]/", &codec, mimeSubtype) != 2) 01866 continue; 01867 /* Note: should really look at the 'freq' and '#chans' params too */ 01868 ast_rtp_set_rtpmap_type(sub->rtp, codec, "audio", mimeSubtype, 0); 01869 } 01870 01871 /* Now gather all of the codecs that were asked for: */ 01872 ast_rtp_get_current_formats(sub->rtp, &peercapability, &peerNonCodecCapability); 01873 p->capability = capability & peercapability; 01874 if (mgcpdebug) { 01875 ast_verbose("Capabilities: us - %d, them - %d, combined - %d\n", 01876 capability, peercapability, p->capability); 01877 ast_verbose("Non-codec capabilities: us - %d, them - %d, combined - %d\n", 01878 nonCodecCapability, peerNonCodecCapability, p->nonCodecCapability); 01879 } 01880 if (!p->capability) { 01881 ast_log(LOG_WARNING, "No compatible codecs!\n"); 01882 return -1; 01883 } 01884 return 0; 01885 }
static void prune_gateways | ( | void | ) | [static] |
Definition at line 4018 of file chan_mgcp.c.
References ast_mutex_lock(), mgcp_gateway::delme, mgcp_endpoint::delme, destroy_endpoint(), mgcp_gateway::endpoints, gateways, mgcp_endpoint::next, and t.
Referenced by reload_config(), and unload_module().
04019 { 04020 struct mgcp_gateway *g, *z, *r; 04021 struct mgcp_endpoint *e, *p, *t; 04022 04023 ast_mutex_lock(&gatelock); 04024 04025 /* prune gateways */ 04026 for (z = NULL, g = gateways; g;) { 04027 /* prune endpoints */ 04028 for (p = NULL, e = g->endpoints; e; ) { 04029 if (e->delme || g->delme) { 04030 t = e; 04031 e = e->next; 04032 if (!p) 04033 g->endpoints = e; 04034 else 04035 p->next = e; 04036 destroy_endpoint(t); 04037 } else { 04038 p = e; 04039 e = e->next; 04040 } 04041 } 04042 04043 if (g->delme) { 04044 r = g; 04045 g = g->next; 04046 if (!z) 04047 gateways = g; 04048 else 04049 z->next = g; 04050 04051 destroy_gateway(r); 04052 } else { 04053 z = g; 04054 g = g->next; 04055 } 04056 } 04057 04058 ast_mutex_unlock(&gatelock); 04059 }
static int reload | ( | void | ) | [static] |
Definition at line 4301 of file chan_mgcp.c.
References mgcp_reload().
04302 { 04303 mgcp_reload(0, 0, NULL); 04304 return 0; 04305 }
static int reload_config | ( | void | ) | [static] |
Definition at line 4061 of file chan_mgcp.c.
References __ourip, ahp, ast_category_browse(), ast_config_destroy(), ast_config_load(), ast_getformatbyname(), ast_gethostbyname(), ast_inet_ntoa(), ast_io_remove(), ast_io_wait(), ast_jb_read_conf(), ast_log(), ast_mutex_lock(), ast_mutex_unlock(), ast_sched_runq(), ast_variable_browse(), ast_verbose(), bindaddr, build_gateway(), capability, config, default_jbconf, DEFAULT_MGCP_CA_PORT, mgcp_endpoint::delme, mgcp_gateway::delme, dtmfmode, mgcp_gateway::endpoints, format, gateways, global_jbconf, hp, io, IPTOS_MINCOST, ast_variable::lineno, LOG_NOTICE, LOG_WARNING, mgcpsock, mgcpsock_read_id, monitor_thread, mgcp_endpoint::name, mgcp_gateway::name, ast_variable::name, mgcp_endpoint::needaudit, mgcp_gateway::next, mgcp_endpoint::next, ast_variable::next, option_verbose, ourhost, ourport, prune_gateways(), tos, transmit_audit_endpoint(), ast_variable::value, VERBOSE_PREFIX_2, and VERBOSE_PREFIX_3.
04062 { 04063 struct ast_config *cfg; 04064 struct ast_variable *v; 04065 struct mgcp_gateway *g; 04066 struct mgcp_endpoint *e; 04067 char *cat; 04068 struct ast_hostent ahp; 04069 struct hostent *hp; 04070 int format; 04071 04072 if (gethostname(ourhost, sizeof(ourhost)-1)) { 04073 ast_log(LOG_WARNING, "Unable to get hostname, MGCP disabled\n"); 04074 return 0; 04075 } 04076 cfg = ast_config_load(config); 04077 04078 /* We *must* have a config file otherwise stop immediately */ 04079 if (!cfg) { 04080 ast_log(LOG_NOTICE, "Unable to load config %s, MGCP disabled\n", config); 04081 return 0; 04082 } 04083 memset(&bindaddr, 0, sizeof(bindaddr)); 04084 dtmfmode = 0; 04085 04086 /* Copy the default jb config over global_jbconf */ 04087 memcpy(&global_jbconf, &default_jbconf, sizeof(struct ast_jb_conf)); 04088 04089 v = ast_variable_browse(cfg, "general"); 04090 while (v) { 04091 /* handle jb conf */ 04092 if (!ast_jb_read_conf(&global_jbconf, v->name, v->value)) { 04093 v = v->next; 04094 continue; 04095 } 04096 04097 /* Create the interface list */ 04098 if (!strcasecmp(v->name, "bindaddr")) { 04099 if (!(hp = ast_gethostbyname(v->value, &ahp))) { 04100 ast_log(LOG_WARNING, "Invalid address: %s\n", v->value); 04101 } else { 04102 memcpy(&bindaddr.sin_addr, hp->h_addr, sizeof(bindaddr.sin_addr)); 04103 } 04104 } else if (!strcasecmp(v->name, "allow")) { 04105 format = ast_getformatbyname(v->value); 04106 if (format < 1) 04107 ast_log(LOG_WARNING, "Cannot allow unknown format '%s'\n", v->value); 04108 else 04109 capability |= format; 04110 } else if (!strcasecmp(v->name, "disallow")) { 04111 format = ast_getformatbyname(v->value); 04112 if (format < 1) 04113 ast_log(LOG_WARNING, "Cannot disallow unknown format '%s'\n", v->value); 04114 else 04115 capability &= ~format; 04116 } else if (!strcasecmp(v->name, "tos")) { 04117 if (sscanf(v->value, "%d", &format) == 1) 04118 tos = format & 0xff; 04119 else if (!strcasecmp(v->value, "lowdelay")) 04120 tos = IPTOS_LOWDELAY; 04121 else if (!strcasecmp(v->value, "throughput")) 04122 tos = IPTOS_THROUGHPUT; 04123 else if (!strcasecmp(v->value, "reliability")) 04124 tos = IPTOS_RELIABILITY; 04125 else if (!strcasecmp(v->value, "mincost")) 04126 tos = IPTOS_MINCOST; 04127 else if (!strcasecmp(v->value, "none")) 04128 tos = 0; 04129 else 04130 ast_log(LOG_WARNING, "Invalid tos value at line %d, should be 'lowdelay', 'throughput', 'reliability', 'mincost', or 'none'\n", v->lineno); 04131 } else if (!strcasecmp(v->name, "port")) { 04132 if (sscanf(v->value, "%d", &ourport) == 1) { 04133 bindaddr.sin_port = htons(ourport); 04134 } else { 04135 ast_log(LOG_WARNING, "Invalid port number '%s' at line %d of %s\n", v->value, v->lineno, config); 04136 } 04137 } 04138 v = v->next; 04139 } 04140 04141 /* mark existing entries for deletion */ 04142 ast_mutex_lock(&gatelock); 04143 g = gateways; 04144 while (g) { 04145 g->delme = 1; 04146 e = g->endpoints; 04147 while (e) { 04148 e->delme = 1; 04149 e = e->next; 04150 } 04151 g = g->next; 04152 } 04153 ast_mutex_unlock(&gatelock); 04154 04155 cat = ast_category_browse(cfg, NULL); 04156 while(cat) { 04157 if (strcasecmp(cat, "general")) { 04158 ast_mutex_lock(&gatelock); 04159 g = build_gateway(cat, ast_variable_browse(cfg, cat)); 04160 if (g) { 04161 if (option_verbose > 2) { 04162 ast_verbose(VERBOSE_PREFIX_3 "Added gateway '%s'\n", g->name); 04163 } 04164 g->next = gateways; 04165 gateways = g; 04166 } 04167 ast_mutex_unlock(&gatelock); 04168 04169 /* FS: process queue and IO */ 04170 if (monitor_thread == pthread_self()) { 04171 if (sched) ast_sched_runq(sched); 04172 if (io) ast_io_wait(io, 10); 04173 } 04174 } 04175 cat = ast_category_browse(cfg, cat); 04176 } 04177 04178 /* prune deleted entries etc. */ 04179 prune_gateways(); 04180 04181 if (ntohl(bindaddr.sin_addr.s_addr)) { 04182 memcpy(&__ourip, &bindaddr.sin_addr, sizeof(__ourip)); 04183 } else { 04184 hp = ast_gethostbyname(ourhost, &ahp); 04185 if (!hp) { 04186 ast_log(LOG_WARNING, "Unable to get our IP address, MGCP disabled\n"); 04187 ast_config_destroy(cfg); 04188 return 0; 04189 } 04190 memcpy(&__ourip, hp->h_addr, sizeof(__ourip)); 04191 } 04192 if (!ntohs(bindaddr.sin_port)) 04193 bindaddr.sin_port = ntohs(DEFAULT_MGCP_CA_PORT); 04194 bindaddr.sin_family = AF_INET; 04195 ast_mutex_lock(&netlock); 04196 if (mgcpsock > -1) 04197 close(mgcpsock); 04198 04199 if (mgcpsock_read_id != NULL) 04200 ast_io_remove(io, mgcpsock_read_id); 04201 mgcpsock_read_id = NULL; 04202 04203 mgcpsock = socket(AF_INET, SOCK_DGRAM, 0); 04204 if (mgcpsock < 0) { 04205 ast_log(LOG_WARNING, "Unable to create MGCP socket: %s\n", strerror(errno)); 04206 } else { 04207 if (bind(mgcpsock, (struct sockaddr *)&bindaddr, sizeof(bindaddr)) < 0) { 04208 ast_log(LOG_WARNING, "Failed to bind to %s:%d: %s\n", 04209 ast_inet_ntoa(bindaddr.sin_addr), ntohs(bindaddr.sin_port), 04210 strerror(errno)); 04211 close(mgcpsock); 04212 mgcpsock = -1; 04213 } else { 04214 if (option_verbose > 1) { 04215 ast_verbose(VERBOSE_PREFIX_2 "MGCP Listening on %s:%d\n", 04216 ast_inet_ntoa(bindaddr.sin_addr), ntohs(bindaddr.sin_port)); 04217 ast_verbose(VERBOSE_PREFIX_2 "Using TOS bits %d\n", tos); 04218 } 04219 if (setsockopt(mgcpsock, IPPROTO_IP, IP_TOS, &tos, sizeof(tos))) 04220 ast_log(LOG_WARNING, "Unable to set TOS to %d\n", tos); 04221 } 04222 } 04223 ast_mutex_unlock(&netlock); 04224 ast_config_destroy(cfg); 04225 04226 /* send audit only to the new endpoints */ 04227 g = gateways; 04228 while (g) { 04229 e = g->endpoints; 04230 while (e && e->needaudit) { 04231 e->needaudit = 0; 04232 transmit_audit_endpoint(e); 04233 ast_verbose(VERBOSE_PREFIX_3 "MGCP Auditing endpoint %s@%s for hookstate\n", e->name, g->name); 04234 e = e->next; 04235 } 04236 g = g->next; 04237 } 04238 04239 return 0; 04240 }
static int reqprep | ( | struct mgcp_request * | req, | |
struct mgcp_endpoint * | p, | |||
char * | verb | |||
) | [static] |
Definition at line 1978 of file chan_mgcp.c.
References init_req(), and oseq.
Referenced by transmit_audit_endpoint(), transmit_connection_del(), transmit_connection_del_w_params(), transmit_info_with_digit(), transmit_info_with_vidupdate(), transmit_invite(), transmit_message_with_text(), transmit_modify_request(), transmit_notify_request(), transmit_notify_request_with_callerid(), transmit_notify_with_sipfrag(), transmit_refer(), transmit_reinvite_with_sdp(), transmit_reinvite_with_t38_sdp(), transmit_request(), transmit_request_with_auth(), and transmit_state_notify().
01979 { 01980 memset(req, 0, sizeof(struct mgcp_request)); 01981 oseq++; 01982 if (oseq > 999999999) 01983 oseq = 1; 01984 init_req(p, req, verb); 01985 return 0; 01986 }
static int resend_response | ( | struct mgcp_subchannel * | sub, | |
struct mgcp_response * | resp | |||
) | [static] |
Definition at line 499 of file chan_mgcp.c.
References __mgcp_xmit(), mgcp_gateway::addr, ast_inet_ntoa(), ast_verbose(), mgcp_response::buf, mgcp_response::len, mgcp_endpoint::parent, mgcp_subchannel::parent, and mgcp_endpoint::sub.
Referenced by find_and_retrans().
00500 { 00501 struct mgcp_endpoint *p = sub->parent; 00502 int res; 00503 if (mgcpdebug) { 00504 ast_verbose("Retransmitting:\n%s\n to %s:%d\n", resp->buf, ast_inet_ntoa(p->parent->addr.sin_addr), ntohs(p->parent->addr.sin_port)); 00505 } 00506 res = __mgcp_xmit(p->parent, resp->buf, resp->len); 00507 if (res > 0) 00508 res = 0; 00509 return res; 00510 }
static int respprep | ( | struct mgcp_request * | resp, | |
struct mgcp_endpoint * | p, | |||
char * | msg, | |||
struct mgcp_request * | req, | |||
char * | msgrest | |||
) | [static] |
Definition at line 1971 of file chan_mgcp.c.
References init_resp().
Referenced by __transmit_response(), transmit_response(), transmit_response_with_allow(), transmit_response_with_auth(), transmit_response_with_date(), transmit_response_with_sdp(), transmit_response_with_t38_sdp(), and transmit_response_with_unsupported().
01972 { 01973 memset(resp, 0, sizeof(*resp)); 01974 init_resp(resp, msg, req, msgrest); 01975 return 0; 01976 }
static int restart_monitor | ( | void | ) | [static] |
Definition at line 3470 of file chan_mgcp.c.
References ast_log(), ast_mutex_lock(), ast_mutex_unlock(), ast_pthread_create_background, AST_PTHREADT_NULL, AST_PTHREADT_STOP, do_monitor(), LOG_ERROR, LOG_WARNING, and monitor_thread.
03471 { 03472 /* If we're supposed to be stopped -- stay stopped */ 03473 if (monitor_thread == AST_PTHREADT_STOP) 03474 return 0; 03475 if (ast_mutex_lock(&monlock)) { 03476 ast_log(LOG_WARNING, "Unable to lock monitor\n"); 03477 return -1; 03478 } 03479 if (monitor_thread == pthread_self()) { 03480 ast_mutex_unlock(&monlock); 03481 ast_log(LOG_WARNING, "Cannot kill myself\n"); 03482 return -1; 03483 } 03484 if (monitor_thread != AST_PTHREADT_NULL) { 03485 /* Wake up the thread */ 03486 pthread_kill(monitor_thread, SIGURG); 03487 } else { 03488 /* Start a new monitor */ 03489 if (ast_pthread_create_background(&monitor_thread, NULL, do_monitor, NULL) < 0) { 03490 ast_mutex_unlock(&monlock); 03491 ast_log(LOG_ERROR, "Unable to start monitor thread.\n"); 03492 return -1; 03493 } 03494 } 03495 ast_mutex_unlock(&monlock); 03496 return 0; 03497 }
static int retrans_pkt | ( | void * | data | ) | [static] |
Definition at line 606 of file chan_mgcp.c.
References __mgcp_xmit(), ast_log(), ast_mutex_lock(), ast_mutex_unlock(), ast_verbose(), free, handle_response(), LOG_WARNING, MAX_RETRANS, mgcpdebug, mgcp_gateway::msgs, mgcp_gateway::msgs_lock, mgcp_gateway::name, mgcp_message::next, mgcp_message::retrans, and mgcp_gateway::retransid.
Referenced by __sip_reliable_xmit(), and mgcp_postrequest().
00607 { 00608 struct mgcp_gateway *gw = (struct mgcp_gateway *)data; 00609 struct mgcp_message *cur, *exq = NULL, *w, *prev; 00610 int res = 0; 00611 00612 /* find out expired msgs */ 00613 ast_mutex_lock(&gw->msgs_lock); 00614 00615 prev = NULL, cur = gw->msgs; 00616 while (cur) { 00617 if (cur->retrans < MAX_RETRANS) { 00618 cur->retrans++; 00619 if (mgcpdebug) { 00620 ast_verbose("Retransmitting #%d transaction %u on [%s]\n", 00621 cur->retrans, cur->seqno, gw->name); 00622 } 00623 __mgcp_xmit(gw, cur->buf, cur->len); 00624 00625 prev = cur; 00626 cur = cur->next; 00627 } else { 00628 if (prev) 00629 prev->next = cur->next; 00630 else 00631 gw->msgs = cur->next; 00632 00633 ast_log(LOG_WARNING, "Maximum retries exceeded for transaction %u on [%s]\n", 00634 cur->seqno, gw->name); 00635 00636 w = cur; 00637 cur = cur->next; 00638 00639 if (exq) { 00640 w->next = exq; 00641 } else { 00642 w->next = NULL; 00643 } 00644 exq = w; 00645 } 00646 } 00647 00648 if (!gw->msgs) { 00649 gw->retransid = -1; 00650 res = 0; 00651 } else { 00652 res = 1; 00653 } 00654 ast_mutex_unlock(&gw->msgs_lock); 00655 00656 while (exq) { 00657 cur = exq; 00658 /* time-out transaction */ 00659 handle_response(cur->owner_ep, cur->owner_sub, 406, cur->seqno, NULL); 00660 exq = exq->next; 00661 free(cur); 00662 } 00663 00664 return res; 00665 }
static void sdpLineNum_iterator_init | ( | int * | iterator | ) | [static] |
static int send_request | ( | struct mgcp_endpoint * | p, | |
struct mgcp_subchannel * | sub, | |||
struct mgcp_request * | req, | |||
unsigned int | seqno | |||
) | [static] |
Definition at line 734 of file chan_mgcp.c.
References mgcp_gateway::addr, ast_inet_ntoa(), ast_log(), ast_mutex_lock(), ast_mutex_unlock(), ast_verbose(), mgcp_request::cmd, mgcp_endpoint::cmd_queue, mgcp_endpoint::cmd_queue_lock, mgcp_subchannel::cx_queue, mgcp_subchannel::cx_queue_lock, mgcp_request::data, free, mgcp_request::len, LOG_DEBUG, LOG_WARNING, malloc, MGCP_CMD_CRCX, MGCP_CMD_DLCX, MGCP_CMD_MDCX, MGCP_CMD_RQNT, mgcp_postrequest(), mgcpdebug, mgcp_request::next, mgcp_endpoint::parent, mgcp_endpoint::rqnt_queue, mgcp_endpoint::rqnt_queue_lock, mgcp_endpoint::slowsequence, and t.
Referenced by transmit_audit_endpoint(), transmit_connection_del(), transmit_connection_del_w_params(), transmit_info_with_digit(), transmit_info_with_vidupdate(), transmit_invite(), transmit_message_with_text(), transmit_modify_request(), transmit_notify_request(), transmit_notify_request_with_callerid(), transmit_notify_with_mwi(), transmit_notify_with_sipfrag(), transmit_refer(), transmit_register(), transmit_reinvite_with_sdp(), transmit_reinvite_with_t38_sdp(), transmit_request(), transmit_request_with_auth(), transmit_sip_request(), and transmit_state_notify().
00736 { 00737 int res = 0; 00738 struct mgcp_request **queue, *q, *r, *t; 00739 ast_mutex_t *l; 00740 00741 ast_log(LOG_DEBUG, "Slow sequence is %d\n", p->slowsequence); 00742 if (p->slowsequence) { 00743 queue = &p->cmd_queue; 00744 l = &p->cmd_queue_lock; 00745 ast_mutex_lock(l); 00746 } else { 00747 switch (req->cmd) { 00748 case MGCP_CMD_DLCX: 00749 queue = &sub->cx_queue; 00750 l = &sub->cx_queue_lock; 00751 ast_mutex_lock(l); 00752 q = sub->cx_queue; 00753 /* delete pending cx cmds */ 00754 while (q) { 00755 r = q->next; 00756 free(q); 00757 q = r; 00758 } 00759 *queue = NULL; 00760 break; 00761 00762 case MGCP_CMD_CRCX: 00763 case MGCP_CMD_MDCX: 00764 queue = &sub->cx_queue; 00765 l = &sub->cx_queue_lock; 00766 ast_mutex_lock(l); 00767 break; 00768 00769 case MGCP_CMD_RQNT: 00770 queue = &p->rqnt_queue; 00771 l = &p->rqnt_queue_lock; 00772 ast_mutex_lock(l); 00773 break; 00774 00775 default: 00776 queue = &p->cmd_queue; 00777 l = &p->cmd_queue_lock; 00778 ast_mutex_lock(l); 00779 break; 00780 } 00781 } 00782 00783 r = (struct mgcp_request *) malloc (sizeof(struct mgcp_request)); 00784 if (!r) { 00785 ast_log(LOG_WARNING, "Cannot post MGCP request: insufficient memory\n"); 00786 ast_mutex_unlock(l); 00787 return -1; 00788 } 00789 memcpy(r, req, sizeof(struct mgcp_request)); 00790 00791 if (!(*queue)) { 00792 if (mgcpdebug) { 00793 ast_verbose("Posting Request:\n%s to %s:%d\n", req->data, 00794 ast_inet_ntoa(p->parent->addr.sin_addr), ntohs(p->parent->addr.sin_port)); 00795 } 00796 00797 res = mgcp_postrequest(p, sub, req->data, req->len, seqno); 00798 } else { 00799 if (mgcpdebug) { 00800 ast_verbose("Queueing Request:\n%s to %s:%d\n", req->data, 00801 ast_inet_ntoa(p->parent->addr.sin_addr), ntohs(p->parent->addr.sin_port)); 00802 } 00803 } 00804 00805 /* XXX find tail. We could also keep tail in the data struct for faster access */ 00806 for (t = *queue; t && t->next; t = t->next); 00807 00808 r->next = NULL; 00809 if (t) 00810 t->next = r; 00811 else 00812 *queue = r; 00813 00814 ast_mutex_unlock(l); 00815 00816 return res; 00817 }
static int send_response | ( | struct mgcp_subchannel * | sub, | |
struct mgcp_request * | req | |||
) | [static] |
Definition at line 512 of file chan_mgcp.c.
References __mgcp_xmit(), mgcp_gateway::addr, ast_inet_ntoa(), ast_verbose(), mgcp_request::data, mgcp_request::len, mgcp_endpoint::parent, mgcp_subchannel::parent, and mgcp_endpoint::sub.
Referenced by __transmit_response(), transmit_response(), transmit_response_with_allow(), transmit_response_with_auth(), transmit_response_with_date(), transmit_response_with_sdp(), transmit_response_with_t38_sdp(), and transmit_response_with_unsupported().
00513 { 00514 struct mgcp_endpoint *p = sub->parent; 00515 int res; 00516 if (mgcpdebug) { 00517 ast_verbose("Transmitting:\n%s\n to %s:%d\n", req->data, ast_inet_ntoa(p->parent->addr.sin_addr), ntohs(p->parent->addr.sin_port)); 00518 } 00519 res = __mgcp_xmit(p->parent, req->data, req->len); 00520 if (res > 0) 00521 res = 0; 00522 return res; 00523 }
static void start_rtp | ( | struct mgcp_subchannel * | sub | ) | [static] |
Definition at line 2579 of file chan_mgcp.c.
References ast_mutex_lock(), ast_mutex_unlock(), ast_random(), ast_rtp_destroy(), ast_rtp_fd(), ast_rtp_new_with_bindaddr(), ast_rtp_set_callback(), ast_rtp_set_data(), ast_rtp_setnat(), bindaddr, mgcp_subchannel::callid, ast_channel::fds, io, mgcp_subchannel::lock, mgcp_subchannel::nat, mgcp_subchannel::owner, mgcp_subchannel::rtp, transmit_connect_with_sdp(), and mgcp_subchannel::txident.
Referenced by handle_hd_hf(), handle_offhook_message(), handle_response(), handle_soft_key_event_message(), handle_stimulus_message(), mgcp_answer(), mgcp_call(), mgcp_ss(), and skinny_answer().
02580 { 02581 ast_mutex_lock(&sub->lock); 02582 /* check again to be on the safe side */ 02583 if (sub->rtp) { 02584 ast_rtp_destroy(sub->rtp); 02585 sub->rtp = NULL; 02586 } 02587 /* Allocate the RTP now */ 02588 sub->rtp = ast_rtp_new_with_bindaddr(sched, io, 1, 0, bindaddr.sin_addr); 02589 if (sub->rtp && sub->owner) 02590 sub->owner->fds[0] = ast_rtp_fd(sub->rtp); 02591 if (sub->rtp) 02592 ast_rtp_setnat(sub->rtp, sub->nat); 02593 #if 0 02594 ast_rtp_set_callback(p->rtp, rtpready); 02595 ast_rtp_set_data(p->rtp, p); 02596 #endif 02597 /* Make a call*ID */ 02598 snprintf(sub->callid, sizeof(sub->callid), "%08lx%s", ast_random(), sub->txident); 02599 /* Transmit the connection create */ 02600 transmit_connect_with_sdp(sub, NULL); 02601 ast_mutex_unlock(&sub->lock); 02602 }
static int transmit_audit_endpoint | ( | struct mgcp_endpoint * | p | ) | [static] |
Definition at line 2288 of file chan_mgcp.c.
References add_header(), mgcp_request::cmd, MGCP_CMD_AUEP, oseq, reqprep(), send_request(), and mgcp_request::trid.
Referenced by handle_request(), mgcp_audit_endpoint(), and reload_config().
02289 { 02290 struct mgcp_request resp; 02291 reqprep(&resp, p, "AUEP"); 02292 /* removed unknown param VS */ 02293 /*add_header(&resp, "F", "A,R,D,S,X,N,I,T,O,ES,E,MD,M");*/ 02294 add_header(&resp, "F", "A"); 02295 /* fill in new fields */ 02296 resp.cmd = MGCP_CMD_AUEP; 02297 resp.trid = oseq; 02298 return send_request(p, NULL, &resp, oseq); /* SC */ 02299 }
static int transmit_connect_with_sdp | ( | struct mgcp_subchannel * | sub, | |
struct ast_rtp * | rtp | |||
) | [static] |
Definition at line 2144 of file chan_mgcp.c.
References AST_FORMAT_MAX_AUDIO, ast_rtp_lookup_mime_subtype(), mgcp_endpoint::capability, mgcp_subchannel::parent, and mgcp_endpoint::sub.
Referenced by start_rtp().
02145 { 02146 struct mgcp_request resp; 02147 char local[256]; 02148 char tmp[80]; 02149 int x; 02150 struct mgcp_endpoint *p = sub->parent; 02151 02152 snprintf(local, sizeof(local), "p:20"); 02153 for (x=1;x<= AST_FORMAT_MAX_AUDIO; x <<= 1) { 02154 if (p->capability & x) { 02155 snprintf(tmp, sizeof(tmp), ", a:%s", ast_rtp_lookup_mime_subtype(1, x, 0)); 02156 strncat(local, tmp, sizeof(local) - strlen(local) - 1); 02157 } 02158 } 02159 if (mgcpdebug) { 02160 ast_verbose(VERBOSE_PREFIX_3 "Creating connection for %s@%s-%d in cxmode: %s callid: %s\n", 02161 p->name, p->parent->name, sub->id, mgcp_cxmodes[sub->cxmode], sub->callid); 02162 } 02163 reqprep(&resp, p, "CRCX"); 02164 add_header(&resp, "C", sub->callid); 02165 add_header(&resp, "L", local); 02166 add_header(&resp, "M", mgcp_cxmodes[sub->cxmode]); 02167 /* X header should not be sent. kept for compatibility */ 02168 add_header(&resp, "X", sub->txident); 02169 /*add_header(&resp, "S", "");*/ 02170 add_sdp(&resp, sub, rtp); 02171 /* fill in new fields */ 02172 resp.cmd = MGCP_CMD_CRCX; 02173 resp.trid = oseq; 02174 return send_request(p, sub, &resp, oseq); /* SC */ 02175 }
static int transmit_connection_del | ( | struct mgcp_subchannel * | sub | ) | [static] |
Definition at line 2301 of file chan_mgcp.c.
References add_header(), ast_verbose(), mgcp_subchannel::callid, mgcp_request::cmd, mgcp_subchannel::cxident, mgcp_subchannel::cxmode, mgcp_subchannel::id, MGCP_CMD_DLCX, mgcp_cxmodes, mgcp_gateway::name, mgcp_endpoint::name, oseq, mgcp_endpoint::parent, mgcp_subchannel::parent, reqprep(), send_request(), mgcp_endpoint::sub, mgcp_request::trid, mgcp_subchannel::txident, and VERBOSE_PREFIX_3.
Referenced by destroy_endpoint(), handle_request(), handle_response(), mgcp_hangup(), and unalloc_sub().
02302 { 02303 struct mgcp_endpoint *p = sub->parent; 02304 struct mgcp_request resp; 02305 02306 if (mgcpdebug) { 02307 ast_verbose(VERBOSE_PREFIX_3 "Delete connection %s %s@%s-%d with new mode: %s on callid: %s\n", 02308 sub->cxident, p->name, p->parent->name, sub->id, mgcp_cxmodes[sub->cxmode], sub->callid); 02309 } 02310 reqprep(&resp, p, "DLCX"); 02311 /* check if call id is avail */ 02312 if (sub->callid[0]) 02313 add_header(&resp, "C", sub->callid); 02314 /* X header should not be sent. kept for compatibility */ 02315 add_header(&resp, "X", sub->txident); 02316 /* check if cxident is avail */ 02317 if (sub->cxident[0]) 02318 add_header(&resp, "I", sub->cxident); 02319 /* fill in new fields */ 02320 resp.cmd = MGCP_CMD_DLCX; 02321 resp.trid = oseq; 02322 return send_request(p, sub, &resp, oseq); /* SC */ 02323 }
static int transmit_connection_del_w_params | ( | struct mgcp_endpoint * | p, | |
char * | callid, | |||
char * | cxident | |||
) | [static] |
Definition at line 2325 of file chan_mgcp.c.
References add_header(), ast_verbose(), MGCP_CMD_DLCX, mgcp_gateway::name, mgcp_endpoint::name, oseq, mgcp_endpoint::parent, reqprep(), send_request(), mgcp_endpoint::sub, and VERBOSE_PREFIX_3.
Referenced by handle_response().
02326 { 02327 struct mgcp_request resp; 02328 02329 if (mgcpdebug) { 02330 ast_verbose(VERBOSE_PREFIX_3 "Delete connection %s %s@%s on callid: %s\n", 02331 cxident ? cxident : "", p->name, p->parent->name, callid ? callid : ""); 02332 } 02333 reqprep(&resp, p, "DLCX"); 02334 /* check if call id is avail */ 02335 if (callid && *callid) 02336 add_header(&resp, "C", callid); 02337 /* check if cxident is avail */ 02338 if (cxident && *cxident) 02339 add_header(&resp, "I", cxident); 02340 /* fill in new fields */ 02341 resp.cmd = MGCP_CMD_DLCX; 02342 resp.trid = oseq; 02343 return send_request(p, p->sub, &resp, oseq); 02344 }
static int transmit_modify_request | ( | struct mgcp_subchannel * | sub | ) | [static] |
Definition at line 2253 of file chan_mgcp.c.
References add_header(), ast_strlen_zero(), ast_verbose(), mgcp_subchannel::callid, mgcp_request::cmd, mgcp_subchannel::cxident, mgcp_subchannel::cxmode, mgcp_endpoint::dtmfmode, mgcp_endpoint::hookstate, mgcp_subchannel::id, MGCP_CMD_MDCX, mgcp_cxmodes, MGCP_DTMF_INBAND, MGCP_OFFHOOK, MGCP_ONHOOK, mgcp_gateway::name, mgcp_endpoint::name, oseq, mgcp_endpoint::parent, mgcp_subchannel::parent, reqprep(), mgcp_subchannel::rtp, send_request(), mgcp_endpoint::sub, mgcp_request::trid, mgcp_subchannel::txident, and VERBOSE_PREFIX_3.
Referenced by handle_hd_hf(), handle_request(), mgcp_answer(), mgcp_call(), and mgcp_hangup().
02254 { 02255 struct mgcp_request resp; 02256 struct mgcp_endpoint *p = sub->parent; 02257 02258 if (ast_strlen_zero(sub->cxident)) { 02259 /* We don't have a CXident yet, store the destination and 02260 wait a bit */ 02261 return 0; 02262 } 02263 if (mgcpdebug) { 02264 ast_verbose(VERBOSE_PREFIX_3 "Modified %s@%s-%d with new mode: %s on callid: %s\n", 02265 p->name, p->parent->name, sub->id, mgcp_cxmodes[sub->cxmode], sub->callid); 02266 } 02267 reqprep(&resp, p, "MDCX"); 02268 add_header(&resp, "C", sub->callid); 02269 add_header(&resp, "M", mgcp_cxmodes[sub->cxmode]); 02270 /* X header should not be sent. kept for compatibility */ 02271 add_header(&resp, "X", sub->txident); 02272 add_header(&resp, "I", sub->cxident); 02273 switch (sub->parent->hookstate) { 02274 case MGCP_ONHOOK: 02275 add_header(&resp, "R", "L/hd(N)"); 02276 break; 02277 case MGCP_OFFHOOK: 02278 add_header(&resp, "R", (sub->rtp && (p->dtmfmode & MGCP_DTMF_INBAND)) ? "L/hu(N), L/hf(N)" : "L/hu(N),L/hf(N),D/[0-9#*](N)"); 02279 break; 02280 } 02281 /* fill in new fields */ 02282 resp.cmd = MGCP_CMD_MDCX; 02283 resp.trid = oseq; 02284 return send_request(p, sub, &resp, oseq); /* SC */ 02285 }
static int transmit_modify_with_sdp | ( | struct mgcp_subchannel * | sub, | |
struct ast_rtp * | rtp, | |||
int | codecs | |||
) | [static] |
Definition at line 2104 of file chan_mgcp.c.
References AST_FORMAT_MAX_AUDIO, ast_rtp_get_peer(), ast_rtp_lookup_mime_subtype(), ast_strlen_zero(), mgcp_endpoint::capability, capability, mgcp_subchannel::cxident, mgcp_subchannel::parent, mgcp_endpoint::sub, and mgcp_subchannel::tmpdest.
Referenced by handle_response(), and mgcp_set_rtp_peer().
02105 { 02106 struct mgcp_request resp; 02107 char local[256]; 02108 char tmp[80]; 02109 int x; 02110 int capability; 02111 struct mgcp_endpoint *p = sub->parent; 02112 02113 capability = p->capability; 02114 if (codecs) 02115 capability = codecs; 02116 if (ast_strlen_zero(sub->cxident) && rtp) { 02117 /* We don't have a CXident yet, store the destination and 02118 wait a bit */ 02119 ast_rtp_get_peer(rtp, &sub->tmpdest); 02120 return 0; 02121 } 02122 snprintf(local, sizeof(local), "p:20"); 02123 for (x=1;x<= AST_FORMAT_MAX_AUDIO; x <<= 1) { 02124 if (p->capability & x) { 02125 snprintf(tmp, sizeof(tmp), ", a:%s", ast_rtp_lookup_mime_subtype(1, x, 0)); 02126 strncat(local, tmp, sizeof(local) - strlen(local) - 1); 02127 } 02128 } 02129 reqprep(&resp, p, "MDCX"); 02130 add_header(&resp, "C", sub->callid); 02131 add_header(&resp, "L", local); 02132 add_header(&resp, "M", mgcp_cxmodes[sub->cxmode]); 02133 /* X header should not be sent. kept for compatibility */ 02134 add_header(&resp, "X", sub->txident); 02135 add_header(&resp, "I", sub->cxident); 02136 /*add_header(&resp, "S", "");*/ 02137 add_sdp(&resp, sub, rtp); 02138 /* fill in new fields */ 02139 resp.cmd = MGCP_CMD_MDCX; 02140 resp.trid = oseq; 02141 return send_request(p, sub, &resp, oseq); /* SC */ 02142 }
static int transmit_notify_request | ( | struct mgcp_subchannel * | sub, | |
char * | tone | |||
) | [static] |
Definition at line 2177 of file chan_mgcp.c.
References add_header(), ast_strlen_zero(), ast_verbose(), mgcp_request::cmd, mgcp_endpoint::curtone, mgcp_subchannel::cxmode, mgcp_endpoint::dtmfmode, mgcp_endpoint::hookstate, mgcp_subchannel::id, MGCP_CMD_RQNT, mgcp_cxmodes, MGCP_DTMF_INBAND, MGCP_OFFHOOK, MGCP_ONHOOK, mgcp_gateway::name, mgcp_endpoint::name, oseq, mgcp_endpoint::parent, mgcp_subchannel::parent, reqprep(), mgcp_endpoint::rqnt_ident, mgcp_subchannel::rtp, send_request(), mgcp_endpoint::sub, mgcp_request::trid, and VERBOSE_PREFIX_3.
Referenced by do_monitor(), handle_hd_hf(), handle_request(), handle_response(), mgcp_answer(), mgcp_hangup(), mgcp_indicate(), mgcp_request(), mgcp_senddigit_end(), and mgcp_ss().
02178 { 02179 struct mgcp_request resp; 02180 struct mgcp_endpoint *p = sub->parent; 02181 02182 if (mgcpdebug) { 02183 ast_verbose(VERBOSE_PREFIX_3 "MGCP Asked to indicate tone: %s on %s@%s-%d in cxmode: %s\n", 02184 tone, p->name, p->parent->name, sub->id, mgcp_cxmodes[sub->cxmode]); 02185 } 02186 ast_copy_string(p->curtone, tone, sizeof(p->curtone)); 02187 reqprep(&resp, p, "RQNT"); 02188 add_header(&resp, "X", p->rqnt_ident); /* SC */ 02189 switch (p->hookstate) { 02190 case MGCP_ONHOOK: 02191 add_header(&resp, "R", "L/hd(N)"); 02192 break; 02193 case MGCP_OFFHOOK: 02194 add_header(&resp, "R", (sub->rtp && (p->dtmfmode & MGCP_DTMF_INBAND)) ? "L/hu(N),L/hf(N)" : "L/hu(N),L/hf(N),D/[0-9#*](N)"); 02195 break; 02196 } 02197 if (!ast_strlen_zero(tone)) { 02198 add_header(&resp, "S", tone); 02199 } 02200 /* fill in new fields */ 02201 resp.cmd = MGCP_CMD_RQNT; 02202 resp.trid = oseq; 02203 return send_request(p, NULL, &resp, oseq); /* SC */ 02204 }
static int transmit_notify_request_with_callerid | ( | struct mgcp_subchannel * | sub, | |
char * | tone, | |||
char * | callernum, | |||
char * | callername | |||
) | [static] |
Definition at line 2206 of file chan_mgcp.c.
References add_header(), ast_strlen_zero(), ast_verbose(), mgcp_request::cmd, mgcp_endpoint::curtone, mgcp_subchannel::cxmode, mgcp_endpoint::dtmfmode, mgcp_endpoint::hookstate, mgcp_subchannel::id, mgcp_endpoint::lastcallerid, MGCP_CMD_RQNT, mgcp_cxmodes, MGCP_DTMF_INBAND, MGCP_OFFHOOK, MGCP_ONHOOK, mgcp_gateway::name, mgcp_endpoint::name, oseq, mgcp_endpoint::parent, mgcp_subchannel::parent, reqprep(), mgcp_endpoint::rqnt_ident, mgcp_subchannel::rtp, send_request(), mgcp_endpoint::sub, t, mgcp_request::trid, and VERBOSE_PREFIX_3.
Referenced by mgcp_call(), and mgcp_hangup().
02207 { 02208 struct mgcp_request resp; 02209 char tone2[256]; 02210 char *l, *n; 02211 time_t t; 02212 struct tm tm; 02213 struct mgcp_endpoint *p = sub->parent; 02214 02215 time(&t); 02216 localtime_r(&t,&tm); 02217 n = callername; 02218 l = callernum; 02219 if (!n) 02220 n = ""; 02221 if (!l) 02222 l = ""; 02223 02224 /* Keep track of last callerid for blacklist and callreturn */ 02225 ast_copy_string(p->lastcallerid, l, sizeof(p->lastcallerid)); 02226 02227 snprintf(tone2, sizeof(tone2), "%s,L/ci(%02d/%02d/%02d/%02d,%s,%s)", tone, 02228 tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, l, n); 02229 ast_copy_string(p->curtone, tone, sizeof(p->curtone)); 02230 reqprep(&resp, p, "RQNT"); 02231 add_header(&resp, "X", p->rqnt_ident); /* SC */ 02232 switch (p->hookstate) { 02233 case MGCP_ONHOOK: 02234 add_header(&resp, "R", "L/hd(N)"); 02235 break; 02236 case MGCP_OFFHOOK: 02237 add_header(&resp, "R", (sub->rtp && (p->dtmfmode & MGCP_DTMF_INBAND)) ? "L/hu(N),L/hf(N)" : "L/hu(N),L/hf(N),D/[0-9#*](N)"); 02238 break; 02239 } 02240 if (!ast_strlen_zero(tone2)) { 02241 add_header(&resp, "S", tone2); 02242 } 02243 if (mgcpdebug) { 02244 ast_verbose(VERBOSE_PREFIX_3 "MGCP Asked to indicate tone: %s on %s@%s-%d in cxmode: %s\n", 02245 tone2, p->name, p->parent->name, sub->id, mgcp_cxmodes[sub->cxmode]); 02246 } 02247 /* fill in new fields */ 02248 resp.cmd = MGCP_CMD_RQNT; 02249 resp.trid = oseq; 02250 return send_request(p, NULL, &resp, oseq); /* SC */ 02251 }
static int transmit_response | ( | struct mgcp_subchannel * | sub, | |
char * | msg, | |||
struct mgcp_request * | req, | |||
char * | msgrest | |||
) | [static] |
Definition at line 1988 of file chan_mgcp.c.
References mgcp_request::data, mgcp_request::identifier, mgcp_request::len, malloc, mgcp_endpoint::parent, mgcp_subchannel::parent, mgcp_gateway::responses, respprep(), send_response(), and mgcp_endpoint::sub.
Referenced by handle_invite_replaces(), handle_keep_alive_message(), handle_line_state_req_message(), handle_open_receive_channel_ack_message(), handle_register_message(), handle_request(), handle_request_bye(), handle_request_cancel(), handle_request_info(), handle_request_invite(), handle_request_message(), handle_request_notify(), handle_request_refer(), handle_request_subscribe(), handle_server_request_message(), handle_soft_key_set_req_message(), handle_soft_key_template_req_message(), handle_speed_dial_stat_req_message(), handle_time_date_req_message(), handle_version_req_message(), local_attended_transfer(), receive_message(), register_verify(), sip_indicate(), sip_park_thread(), sipsock_read(), skinny_hold(), skinny_reset_device(), skinny_unhold(), transmit_callinfo(), transmit_callstate(), transmit_connect(), transmit_dialednumber(), transmit_displaymessage(), transmit_displaynotify(), transmit_displaypromptstatus(), transmit_lamp_indication(), transmit_ringer_mode(), transmit_selectsoftkeys(), transmit_speaker_mode(), and transmit_tone().
01989 { 01990 struct mgcp_request resp; 01991 struct mgcp_endpoint *p = sub->parent; 01992 struct mgcp_response *mgr; 01993 01994 respprep(&resp, p, msg, req, msgrest); 01995 mgr = malloc(sizeof(struct mgcp_response) + resp.len + 1); 01996 if (mgr) { 01997 /* Store MGCP response in case we have to retransmit */ 01998 memset(mgr, 0, sizeof(struct mgcp_response)); 01999 sscanf(req->identifier, "%d", &mgr->seqno); 02000 time(&mgr->whensent); 02001 mgr->len = resp.len; 02002 memcpy(mgr->buf, resp.data, resp.len); 02003 mgr->buf[resp.len] = '\0'; 02004 mgr->next = p->parent->responses; 02005 p->parent->responses = mgr; 02006 } 02007 return send_response(sub, &resp); 02008 }
static int unalloc_sub | ( | struct mgcp_subchannel * | sub | ) | [static] |
Definition at line 458 of file chan_mgcp.c.
References mgcp_subchannel::alreadygone, ast_log(), ast_rtp_destroy(), ast_strlen_zero(), mgcp_subchannel::callid, mgcp_subchannel::cxident, mgcp_subchannel::cxmode, dump_cmd_queues(), mgcp_subchannel::id, LOG_DEBUG, LOG_WARNING, MGCP_CX_INACTIVE, mgcp_gateway::name, mgcp_endpoint::name, mgcp_subchannel::outgoing, mgcp_subchannel::owner, mgcp_endpoint::parent, mgcp_subchannel::parent, mgcp_subchannel::rtp, mgcp_endpoint::sub, mgcp_subchannel::tmpdest, and transmit_connection_del().
Referenced by attempt_transfer(), ss_thread(), zt_handle_event(), and zt_hangup().
00459 { 00460 struct mgcp_endpoint *p = sub->parent; 00461 if (p->sub == sub) { 00462 ast_log(LOG_WARNING, "Trying to unalloc the real channel %s@%s?!?\n", p->name, p->parent->name); 00463 return -1; 00464 } 00465 ast_log(LOG_DEBUG, "Released sub %d of channel %s@%s\n", sub->id, p->name, p->parent->name); 00466 00467 sub->owner = NULL; 00468 if (!ast_strlen_zero(sub->cxident)) { 00469 transmit_connection_del(sub); 00470 } 00471 sub->cxident[0] = '\0'; 00472 sub->callid[0] = '\0'; 00473 sub->cxmode = MGCP_CX_INACTIVE; 00474 sub->outgoing = 0; 00475 sub->alreadygone = 0; 00476 memset(&sub->tmpdest, 0, sizeof(sub->tmpdest)); 00477 if (sub->rtp) { 00478 ast_rtp_destroy(sub->rtp); 00479 sub->rtp = NULL; 00480 } 00481 dump_cmd_queues(NULL, sub); /* SC */ 00482 return 0; 00483 }
static int unload_module | ( | void | ) | [static] |
Definition at line 4307 of file chan_mgcp.c.
References ast_channel_register(), ast_channel_unregister(), ast_cli_unregister_multiple(), ast_log(), ast_mutex_lock(), ast_mutex_trylock(), ast_mutex_unlock(), AST_PTHREADT_NULL, AST_PTHREADT_STOP, ast_rtp_proto_unregister(), cli_mgcp, mgcp_endpoint::delme, mgcp_gateway::delme, mgcp_gateway::endpoints, gateways, LOG_WARNING, mgcp_reload(), mgcp_reloading, mgcp_rtp, mgcp_tech, mgcpsock, monitor_thread, mgcp_endpoint::next, mgcp_gateway::next, prune_gateways(), and sched_context_destroy().
04308 { 04309 struct mgcp_endpoint *e; 04310 struct mgcp_gateway *g; 04311 04312 /* Check to see if we're reloading */ 04313 if (ast_mutex_trylock(&mgcp_reload_lock)) { 04314 ast_log(LOG_WARNING, "MGCP is currently reloading. Unable to remove module.\n"); 04315 return -1; 04316 } else { 04317 mgcp_reloading = 1; 04318 ast_mutex_unlock(&mgcp_reload_lock); 04319 } 04320 04321 /* First, take us out of the channel loop */ 04322 ast_channel_unregister(&mgcp_tech); 04323 04324 /* Shut down the monitoring thread */ 04325 if (!ast_mutex_lock(&monlock)) { 04326 if (monitor_thread && (monitor_thread != AST_PTHREADT_STOP)) { 04327 pthread_cancel(monitor_thread); 04328 pthread_kill(monitor_thread, SIGURG); 04329 pthread_join(monitor_thread, NULL); 04330 } 04331 monitor_thread = AST_PTHREADT_STOP; 04332 ast_mutex_unlock(&monlock); 04333 } else { 04334 ast_log(LOG_WARNING, "Unable to lock the monitor\n"); 04335 /* We always want to leave this in a consistent state */ 04336 ast_channel_register(&mgcp_tech); 04337 mgcp_reloading = 0; 04338 mgcp_reload(0, 0, NULL); 04339 return -1; 04340 } 04341 04342 if (!ast_mutex_lock(&gatelock)) { 04343 for (g = gateways; g; g = g->next) { 04344 g->delme = 1; 04345 for (e = g->endpoints; e; e = e->next) 04346 e->delme = 1; 04347 } 04348 04349 prune_gateways(); 04350 ast_mutex_unlock(&gatelock); 04351 } else { 04352 ast_log(LOG_WARNING, "Unable to lock the gateways list.\n"); 04353 /* We always want to leave this in a consistent state */ 04354 ast_channel_register(&mgcp_tech); 04355 /* Allow the monitor to restart */ 04356 monitor_thread = AST_PTHREADT_NULL; 04357 mgcp_reloading = 0; 04358 mgcp_reload(0, 0, NULL); 04359 return -1; 04360 } 04361 04362 close(mgcpsock); 04363 ast_rtp_proto_unregister(&mgcp_rtp); 04364 ast_cli_unregister_multiple(cli_mgcp, sizeof(cli_mgcp) / sizeof(struct ast_cli_entry)); 04365 sched_context_destroy(sched); 04366 04367 return 0; 04368 }
struct in_addr __ourip [static] |
Definition at line 221 of file chan_mgcp.c.
char accountcode[AST_MAX_ACCOUNT_CODE] = "" [static] |
Definition at line 186 of file chan_mgcp.c.
int adsi = 0 [static] |
Definition at line 192 of file chan_mgcp.c.
int amaflags = 0 [static] |
Definition at line 190 of file chan_mgcp.c.
char audit_endpoint_usage[] [static] |
Initial value:
"Usage: mgcp audit endpoint <endpointid>\n" " Lists the capabilities of an endpoint in the MGCP (Media Gateway Control Protocol) subsystem.\n" " mgcp debug MUST be on to see the results of this command.\n"
Definition at line 1046 of file chan_mgcp.c.
struct sockaddr_in bindaddr [static] |
Definition at line 405 of file chan_mgcp.c.
int callreturn = 0 [static] |
int callwaiting = 0 [static] |
int cancallforward = 0 [static] |
int canreinvite = CANREINVITE [static] |
int capability = AST_FORMAT_ULAW [static] |
Definition at line 217 of file chan_mgcp.c.
Referenced by add_sdp(), build_gateway(), build_setup(), mgcp_new(), mgcp_request(), parse_setup(), process_sdp(), reload_config(), set_local_capabilities(), and transmit_modify_with_sdp().
char cid_name[AST_MAX_EXTENSION] = "" [static] |
Definition at line 157 of file chan_mgcp.c.
Referenced by __oh323_new(), build_device(), build_gateway(), build_peer(), build_user(), check_access(), check_user_full(), dial_trunk(), misdn_new(), sip_call(), sla_ring_station(), and zt_handle_event().
char cid_num[AST_MAX_EXTENSION] = "" [static] |
Definition at line 156 of file chan_mgcp.c.
Referenced by __oh323_new(), build_device(), build_gateway(), build_peer(), build_user(), check_access(), check_user_full(), dial_trunk(), misdn_new(), sla_ring_station(), and zt_handle_event().
struct ast_cli_entry cli_mgcp[] [static] |
const char config[] = "mgcp.conf" [static] |
Definition at line 110 of file chan_mgcp.c.
char context[AST_MAX_EXTENSION] = "default" [static] |
Definition at line 152 of file chan_mgcp.c.
ast_group_t cur_callergroup = 0 [static] |
ast_group_t cur_pickupgroup = 0 [static] |
char debug_usage[] [static] |
Initial value:
"Usage: mgcp set debug\n" " Enables dumping of MGCP packets for debugging purposes\n"
Definition at line 1051 of file chan_mgcp.c.
struct ast_jb_conf default_jbconf [static] |
Global jitterbuffer configuration - by default, jb is disabled
Definition at line 100 of file chan_mgcp.c.
int dtmfmode = 0 [static] |
Definition at line 159 of file chan_mgcp.c.
Referenced by build_gateway(), reload_config(), and set_local_capabilities().
int firstdigittimeout = 16000 [static] |
Wait up to 16 seconds for first digit (FXO logic)
Definition at line 197 of file chan_mgcp.c.
Referenced by disa_exec(), mgcp_ss(), and skinny_ss().
struct mgcp_gateway * gateways [static] |
int gendigittimeout = 8000 [static] |
How long to wait for following digits (FXO logic)
Definition at line 200 of file chan_mgcp.c.
Referenced by mgcp_ss(), and skinny_ss().
struct ast_jb_conf global_jbconf [static] |
Definition at line 107 of file chan_mgcp.c.
int immediate = 0 [static] |
struct io_context* io [static] |
Definition at line 227 of file chan_mgcp.c.
char language[MAX_LANGUAGE] = "" [static] |
Definition at line 154 of file chan_mgcp.c.
char mailbox[AST_MAX_EXTENSION] [static] |
Definition at line 188 of file chan_mgcp.c.
Referenced by action_mailboxcount(), action_mailboxstatus(), build_device(), build_gateway(), build_peer(), disa_exec(), and realtime_directory().
int matchdigittimeout = 3000 [static] |
How long to wait for an extra digit, if there is an ambiguous match
Definition at line 203 of file chan_mgcp.c.
Referenced by mgcp_ss(), and skinny_ss().
char* mgcp_cxmodes[] [static] |
}
Definition at line 132 of file chan_mgcp.c.
Referenced by transmit_connection_del(), transmit_modify_request(), transmit_notify_request(), and transmit_notify_request_with_callerid().
char mgcp_reload_usage[] [static] |
Initial value:
"Usage: mgcp reload\n" " Reloads MGCP configuration from mgcp.conf\n" " Deprecated: please use 'reload chan_mgcp.so' instead.\n"
Definition at line 1059 of file chan_mgcp.c.
int mgcp_reloading = 0 [static] |
Definition at line 398 of file chan_mgcp.c.
Referenced by do_monitor(), mgcp_reload(), and unload_module().
struct ast_rtp_protocol mgcp_rtp [static] |
Initial value:
{ .type = "MGCP", .get_rtp_info = mgcp_get_rtp_peer, .set_rtp_peer = mgcp_set_rtp_peer, }
Definition at line 3960 of file chan_mgcp.c.
Referenced by load_module(), and unload_module().
struct ast_channel_tech mgcp_tech [static] |
Definition at line 434 of file chan_mgcp.c.
Referenced by load_module(), mgcp_new(), and unload_module().
int mgcpdebug = 0 [static] |
Definition at line 224 of file chan_mgcp.c.
Referenced by add_sdp(), mgcp_audit_endpoint(), mgcp_call(), mgcp_do_debug(), mgcp_hangup(), mgcp_indicate(), mgcp_no_debug(), parse(), process_sdp(), retrans_pkt(), and send_request().
int mgcpsock = -1 [static] |
Definition at line 403 of file chan_mgcp.c.
Referenced by do_monitor(), mgcpsock_read(), reload_config(), and unload_module().
int* mgcpsock_read_id = NULL [static] |
pthread_t monitor_thread = AST_PTHREADT_NULL [static] |
This is the thread for the monitor which checks for input on the channels which are not currently in use.
Definition at line 213 of file chan_mgcp.c.
char musicclass[MAX_MUSICCLASS] = "" [static] |
Definition at line 155 of file chan_mgcp.c.
Referenced by begin_dial(), build_gateway(), func_channel_write(), gtalk_new(), moh2_exec(), moh_write(), and read_config().
int nat = 0 [static] |
char no_debug_usage[] [static] |
Initial value:
"Usage: mgcp set debug off\n" " Disables dumping of MGCP packets for debugging purposes\n"
Definition at line 1055 of file chan_mgcp.c.
int nonCodecCapability = AST_RTP_DTMF [static] |
unsigned int oseq [static] |
Definition at line 194 of file chan_mgcp.c.
Referenced by init_req(), reqprep(), transmit_audit_endpoint(), transmit_connection_del(), transmit_connection_del_w_params(), transmit_modify_request(), transmit_notify_request(), and transmit_notify_request_with_callerid().
char ourhost[MAXHOSTNAMELEN] [static] |
Definition at line 220 of file chan_mgcp.c.
Referenced by ast_find_ourip(), handle_server_request_message(), and reload_config().
int ourport [static] |
Definition at line 222 of file chan_mgcp.c.
Referenced by build_contact(), build_via(), handle_server_request_message(), initreqprep(), and reload_config().
struct sched_context* sched [static] |
Definition at line 226 of file chan_mgcp.c.
char show_endpoints_usage[] [static] |
Initial value:
"Usage: mgcp show endpoints\n" " Lists all endpoints known to the MGCP (Media Gateway Control Protocol) subsystem.\n"
Definition at line 1042 of file chan_mgcp.c.
int singlepath = 0 [static] |
int slowsequence = 0 [static] |
const char tdesc[] = "Media Gateway Control Protocol (MGCP)" [static] |
Definition at line 109 of file chan_mgcp.c.
int threewaycalling = 0 [static] |
int tos = 0 [static] |
Definition at line 165 of file chan_mgcp.c.
int transfer = 0 [static] |
This is for flashhook transfers
Definition at line 178 of file chan_mgcp.c.
Referenced by build_device(), build_gateway(), leave_voicemail(), and send_packet().