From 828a13733b812a6138427aba7d75b3994f48dacc Mon Sep 17 00:00:00 2001 From: Mathieu Rene Date: Wed, 25 Jul 2012 15:45:20 -0400 Subject: [PATCH 01/29] oops --- .../mod_media_gateway/media_gateway_xml.c | 105 +++++++++--------- 1 file changed, 52 insertions(+), 53 deletions(-) diff --git a/src/mod/endpoints/mod_media_gateway/media_gateway_xml.c b/src/mod/endpoints/mod_media_gateway/media_gateway_xml.c index b52d4da0f1..68d546985d 100644 --- a/src/mod/endpoints/mod_media_gateway/media_gateway_xml.c +++ b/src/mod/endpoints/mod_media_gateway/media_gateway_xml.c @@ -65,6 +65,58 @@ switch_status_t config_profile(megaco_profile_t *profile, switch_bool_t reload) profile->idx = ++mg_sap_id; + + + if ((mg_phys_terms = switch_xml_child(mg_interface, "physical_terminations"))) { + for (mg_term = switch_xml_child(mg_phys_terms, "map"); mg_term; mg_term = mg_term->next) { + switch_memory_pool_t *pool; + mg_termination_t *term; + // + const char *prefix = switch_xml_attr(mg_term, "termination-id-prefix"); + //const char *sztermination_id_base = switch_xml_attr(mg_term, "termination-id-base"); + //const char *tech = switch_xml_attr(mg_term, "tech"); + const char *channel_prefix = switch_xml_attr(mg_term, "channel-prefix"); + const char *channel_map = switch_xml_attr(mg_term, "channel-map"); + const char *szspan_id = switch_xml_attr(mg_term, "span-id"); + const int span_id = !zstr(szspan_id) ? atoi(szspan_id) : 0; + + + if (!zstr(channel_map)) { + /* Split channel-map */ + char *channel_map_dup = strdup(channel_map); + char *chanmap[24]; + int chanmap_count, i; + chanmap_count = switch_split(channel_map_dup, ' ', chanmap); + for (i = 0; i < chanmap_count; i++) { + char *p = strchr(chanmap[i], '-'); + if (p) { + int startchan, endchan, j; + *p++ = '\0'; + startchan = atoi(chanmap[i]); + endchan = atoi(p); + + for (j = startchan; j < endchan; j++) { + switch_core_new_memory_pool(&pool); + term = switch_core_alloc(profile->pool, sizeof *term); + term->pool = pool; + term->type = MG_TERM_TDM; + term->profile = profile; + term->name = switch_core_sprintf(pool, "%s%d", prefix, j); + term->u.tdm.span = span_id; + term->u.tdm.channel = j; + + switch_core_hash_insert_wrlock(profile->terminations, term->name, term, profile->terminations_rwlock); + + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Mapped termination [%s] to freetdm span: %d chan: %d\n", term->name, term->u.tdm.span, term->u.tdm.channel); + } + } + } + + free(channel_map_dup); + } + } + } + /* we should break from here , profile name should be unique */ break; @@ -113,59 +165,6 @@ switch_status_t config_profile(megaco_profile_t *profile, switch_bool_t reload) } } - - if ((mg_phys_terms = switch_xml_child(cfg, "physical_terminations"))) { - - for (mg_term = switch_xml_child(mg_phys_terms, "map"); mg_term; mg_term = mg_term->next) { - switch_memory_pool_t *pool; - mg_termination_t *term; - // - const char *prefix = switch_xml_attr(mg_term, "termination-id-prefix"); - //const char *sztermination_id_base = switch_xml_attr(mg_term, "termination-id-base"); - //const char *tech = switch_xml_attr(mg_term, "tech"); - const char *channel_prefix = switch_xml_attr(mg_term, "channel-prefix"); - const char *channel_map = switch_xml_attr(mg_term, "channel-map"); - const char *szspan_id = switch_xml_attr(mg_term, "span-id"); - const int span_id = !zstr(szspan_id) ? atoi(szspan_id) : 0; - - - if (!zstr(channel_map)) { - /* Split channel-map */ - char *channel_map_dup = strdup(channel_map); - char *chanmap[24]; - int chanmap_count, i; - chanmap_count = switch_split(channel_map_dup, ' ', chanmap); - for (i = 0; i < chanmap_count; i++) { - char *p = strchr(chanmap[i], '-'); - if (p) { - int startchan, endchan, j; - *p++ = '\0'; - startchan = atoi(chanmap[i]); - endchan = atoi(p); - - for (j = startchan; j < endchan; j++) { - switch_core_new_memory_pool(&pool); - term = switch_core_alloc(profile->pool, sizeof *term); - term->pool = pool; - term->type = MG_TERM_TDM; - term->profile = profile; - term->name = switch_core_sprintf(pool, "%s%d", prefix, j); - term->u.tdm.span = span_id; - term->u.tdm.channel = j; - - switch_core_hash_insert_wrlock(profile->terminations, term->name, term, profile->terminations_rwlock); - - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Mapped termination [%s] to freetdm span: %d chan: %d\n", term->name, term->u.tdm.span, term->u.tdm.channel); - } - } - } - - free(channel_map_dup); - } - - } - } - /* configure the MEGACO stack */ status = sng_mgco_cfg(profile); From 6cf298a74631ef0baa37fd4601df3d0fad922d14 Mon Sep 17 00:00:00 2001 From: Mathieu Rene Date: Wed, 25 Jul 2012 17:18:18 -0400 Subject: [PATCH 02/29] use span name instead of id. implement termination choose for tdm. --- libs/freetdm/mod_freetdm/tdm.c | 14 ++++++++++++-- .../endpoints/mod_media_gateway/media_gateway.c | 17 +++++++++++++++-- .../mod_media_gateway/media_gateway_xml.c | 8 ++++---- .../mod_media_gateway/mod_media_gateway.h | 13 ++++++++++++- 4 files changed, 43 insertions(+), 9 deletions(-) diff --git a/libs/freetdm/mod_freetdm/tdm.c b/libs/freetdm/mod_freetdm/tdm.c index a3369f1f7b..53ee192cf0 100644 --- a/libs/freetdm/mod_freetdm/tdm.c +++ b/libs/freetdm/mod_freetdm/tdm.c @@ -38,6 +38,7 @@ void ctdm_init(switch_loadable_module_interface_t *module_interface); #define kSPAN_ID "span" #define kCHAN_ID "chan" +#define kSPAN_NAME "span_name" static struct { switch_memory_pool_t *pool; @@ -97,7 +98,8 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi switch_originate_flag_t flags, switch_call_cause_t *cancel_cause) { const char *szspanid = switch_event_get_header(var_event, kSPAN_ID), - *szchanid = switch_event_get_header(var_event, kCHAN_ID); + *szchanid = switch_event_get_header(var_event, kCHAN_ID), + *span_name = switch_event_get_header(var_event, kSPAN_NAME); int chan_id; int span_id; @@ -111,14 +113,22 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi ctdm_private_t *tech_pvt = NULL; - if (zstr(szchanid) || zstr(szspanid)) { + if (zstr(szchanid) || (zstr(szspanid) && zstr(span_name))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Both ["kSPAN_ID"] and ["kCHAN_ID"] have to be set.\n"); goto fail; } chan_id = atoi(szchanid); span_id = atoi(szspanid); + + if (!span_id) { + if (ftdm_span_find_by_name(span_name, &span) == FTDM_SUCCESS) { + span_id = ftdm_span_get_id(span); + } else { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot find span [%s]\n"); + } + } if (!(*new_session = switch_core_session_request(ctdm.endpoint_interface, SWITCH_CALL_DIRECTION_OUTBOUND, 0, pool))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't request session.\n"); diff --git a/src/mod/endpoints/mod_media_gateway/media_gateway.c b/src/mod/endpoints/mod_media_gateway/media_gateway.c index 8580844172..8fbd08abf5 100644 --- a/src/mod/endpoints/mod_media_gateway/media_gateway.c +++ b/src/mod/endpoints/mod_media_gateway/media_gateway.c @@ -120,7 +120,7 @@ switch_status_t megaco_activate_termination(mg_termination_t *term) } else if (term->type == MG_TERM_TDM) { switch_snprintf(dialstring, sizeof dialstring, "tdm/%s", term->name); - switch_event_add_header(var_event, SWITCH_STACK_BOTTOM, kSPAN_ID, "%d", term->u.tdm.span); + switch_event_add_header_string(var_event, SWITCH_STACK_BOTTOM, kSPAN_NAME, term->u.tdm.span_name); switch_event_add_header(var_event, SWITCH_STACK_BOTTOM, kCHAN_ID, "%d", term->u.tdm.channel); } @@ -135,6 +135,8 @@ switch_status_t megaco_activate_termination(mg_termination_t *term) switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Termination [%s] successfully instanciated as [%s] [%s]\n", term->name, dialstring, switch_core_session_get_uuid(session)); + switch_set_flag(term, MGT_ACTIVE); + done: if (session) { switch_core_session_rwunlock(session); @@ -151,6 +153,7 @@ mg_termination_t *megaco_choose_termination(megaco_profile_t *profile, const cha mg_termination_t *term = NULL; char name[100]; int term_id; + size_t prefixlen = strlen(prefix); /* Check the termination type by prefix */ if (strncasecmp(prefix, profile->rtp_termination_id_prefix, strlen(profile->rtp_termination_id_prefix)) == 0) { @@ -158,8 +161,14 @@ mg_termination_t *megaco_choose_termination(megaco_profile_t *profile, const cha term_id = mg_rtp_request_id(profile); switch_snprintf(name, sizeof name, "%s/%d", profile->rtp_termination_id_prefix, term_id); } else { + for (term = profile->physical_terminations; term; term = term->next) { + if (!strncasecmp(prefix, term->name, prefixlen) && !switch_test_flag(term, MGT_ALLOCATED)) { + switch_set_flag(term, MGT_ALLOCATED); + return term; + } + } - return term; + return NULL; } switch_core_new_memory_pool(&pool); @@ -168,6 +177,7 @@ mg_termination_t *megaco_choose_termination(megaco_profile_t *profile, const cha term->type = termtype; term->active_events = NULL; term->profile = profile; + switch_set_flag(term, MGT_ALLOCATED); if (termtype == MG_TERM_RTP) { /* Fill in local address and reserve an rtp port */ @@ -212,6 +222,9 @@ void megaco_termination_destroy(mg_termination_t *term) term->active_events = NULL; } + switch_clear_flag(term, MGT_ALLOCATED); + switch_clear_flag(term, MGT_ACTIVE); + if (term->type == MG_TERM_RTP) { switch_core_hash_delete_wrlock(term->profile->terminations, term->name, term->profile->terminations_rwlock); switch_core_destroy_memory_pool(&term->pool); diff --git a/src/mod/endpoints/mod_media_gateway/media_gateway_xml.c b/src/mod/endpoints/mod_media_gateway/media_gateway_xml.c index 68d546985d..f30c1d955d 100644 --- a/src/mod/endpoints/mod_media_gateway/media_gateway_xml.c +++ b/src/mod/endpoints/mod_media_gateway/media_gateway_xml.c @@ -77,8 +77,6 @@ switch_status_t config_profile(megaco_profile_t *profile, switch_bool_t reload) //const char *tech = switch_xml_attr(mg_term, "tech"); const char *channel_prefix = switch_xml_attr(mg_term, "channel-prefix"); const char *channel_map = switch_xml_attr(mg_term, "channel-map"); - const char *szspan_id = switch_xml_attr(mg_term, "span-id"); - const int span_id = !zstr(szspan_id) ? atoi(szspan_id) : 0; if (!zstr(channel_map)) { @@ -102,12 +100,14 @@ switch_status_t config_profile(megaco_profile_t *profile, switch_bool_t reload) term->type = MG_TERM_TDM; term->profile = profile; term->name = switch_core_sprintf(pool, "%s%d", prefix, j); - term->u.tdm.span = span_id; term->u.tdm.channel = j; + term->u.tdm.span_name = switch_core_strdup(pool, channel_prefix); switch_core_hash_insert_wrlock(profile->terminations, term->name, term, profile->terminations_rwlock); + term->next = profile->physical_terminations; + profile->physical_terminations = term; - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Mapped termination [%s] to freetdm span: %d chan: %d\n", term->name, term->u.tdm.span, term->u.tdm.channel); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Mapped termination [%s] to freetdm span: %s chan: %d\n", term->name, term->u.tdm.span_name, term->u.tdm.channel); } } } diff --git a/src/mod/endpoints/mod_media_gateway/mod_media_gateway.h b/src/mod/endpoints/mod_media_gateway/mod_media_gateway.h index d74fb31d1e..c1960877bd 100644 --- a/src/mod/endpoints/mod_media_gateway/mod_media_gateway.h +++ b/src/mod/endpoints/mod_media_gateway/mod_media_gateway.h @@ -83,10 +83,17 @@ typedef struct mg_context_s mg_context_t; /* TDM parameters understood by the controllable channel */ #define kSPAN_ID "span" #define kCHAN_ID "chan" +#define kSPAN_NAME "span_name" typedef struct mg_termination_s mg_termination_t; +enum { + MGT_ALLOCATED = (1 << 0), + MGT_ACTIVE = (1 << 1), + +} mg_termination_flags; + struct mg_termination_s { switch_memory_pool_t *pool; mg_termination_type_t type; @@ -96,6 +103,7 @@ struct mg_termination_s { megaco_profile_t *profile; /*!< Parent MG profile */ MgMgcoReqEvtDesc *active_events; /* !< active megaco events */ mg_termination_t *next; /*!< List for physical terminations */ + uint32_t flags; union { struct { @@ -116,8 +124,8 @@ struct mg_termination_s { } rtp; struct { - int span; int channel; + const char *span_name; } tdm; } u; }; @@ -165,6 +173,9 @@ struct megaco_profile_s { uint8_t rtpid_bitmap[MG_MAX_CONTEXTS/8]; uint32_t rtpid_next; + + mg_termination_t *physical_terminations; + switch_hash_t *terminations; switch_thread_rwlock_t *terminations_rwlock; }; From f223b9a0bb76ec5580ff84b6dc62e40fad189aa8 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 25 Jul 2012 17:28:56 -0400 Subject: [PATCH 03/29] adding add rsp sdp code --- .../media_gateway_cmd_handler.c | 294 +++++++++--------- 1 file changed, 152 insertions(+), 142 deletions(-) diff --git a/src/mod/endpoints/mod_media_gateway/media_gateway_cmd_handler.c b/src/mod/endpoints/mod_media_gateway/media_gateway_cmd_handler.c index 6a6ef5c4d9..5f756ac249 100644 --- a/src/mod/endpoints/mod_media_gateway/media_gateway_cmd_handler.c +++ b/src/mod/endpoints/mod_media_gateway/media_gateway_cmd_handler.c @@ -142,8 +142,13 @@ switch_status_t mg_is_ito_pkg_req(megaco_profile_t* mg_profile, MgMgcoCommand *c (reqEvtPar->u.other.val.u.eq.type.pres == PRSNT_NODEF) && (reqEvtPar->u.other.val.u.eq.type.val == MGT_VALTYPE_UINT32)) { +#ifdef BIT_64 switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO," Received Inactivity timer value [%d]\n", reqEvtPar->u.other.val.u.eq.u.decInt.val); +#else + switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO," Received Inactivity timer value [%ld]\n", + reqEvtPar->u.other.val.u.eq.u.decInt.val); +#endif mg_profile->inact_tmr = reqEvtPar->u.other.val.u.eq.u.decInt.val/MG_INACTIVITY_TMR_RESOLUTION; @@ -544,7 +549,7 @@ switch_status_t handle_mg_add_cmd(megaco_profile_t* mg_profile, MgMgcoCommand *i if ((NOTPRSNT != termId->type.pres) && (MGT_TERMID_CHOOSE == termId->type.val)){ - term = megaco_choose_termination(mg_profile, "RTP"); /* TODO - RTP string has be configured one */ + term = megaco_choose_termination(mg_profile, mg_profile->rtp_termination_id_prefix); if(NULL == term){ mg_util_set_err_string(&errTxt, " Resource Failure "); @@ -660,189 +665,194 @@ switch_status_t handle_mg_add_cmd(megaco_profile_t* mg_profile, MgMgcoCommand *i desc->type.val = MGT_MEDIADESC; mgUtlCpyMgMgcoMediaDesc(&desc->u.media, inc_med_desc, &rsp.u.mgCmdRsp[0]->memCp); - { - /* build local descriptors */ - /*MgMgcoStreamDesc *stream;*/ - MgMgcoLocalDesc *local; - CmSdpInfoSet *psdp; - char* ipAddress = "192.168.1.1"; - MgMgcoMediaDesc* media = &desc->u.media; + /* only for RTP */ + if(is_rtp){ + /* build local descriptors */ + /*MgMgcoStreamDesc *stream;*/ + MgMgcoLocalDesc *local; + CmSdpInfoSet *psdp; + char* ipAddress[4];// = "192.168.1.1"; + MgMgcoMediaDesc* media = &desc->u.media; - /* Most probably we need to add local descriptor */ + switch_split((char*)term->u.rtp.local_addr,'.',ipAddress); - /* allocating mem for local descriptor */ - if (mgUtlGrowList((void ***)&media->parms, sizeof(MgMgcoMediaPar), - &media->num, &rsp.u.mgCmdRsp[0]->memCp) != ROK) - { - switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR,"Grow List failed\n"); - return SWITCH_STATUS_FALSE; - } + printf("ipAddress[0]=%s, ipAddress[1]=%s, ipAddress[2]=%s,ipAddress[3]=%s\n",ipAddress[0],ipAddress[1],ipAddress[2],ipAddress[3]); + + /* Most probably we need to add local descriptor */ + + /* allocating mem for local descriptor */ + if (mgUtlGrowList((void ***)&media->parms, sizeof(MgMgcoMediaPar), + &media->num, &rsp.u.mgCmdRsp[0]->memCp) != ROK) + { + switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR,"Grow List failed\n"); + return SWITCH_STATUS_FALSE; + } #if 0 - /* Kapil - NOT REQUIRED..keeping now just for ref..will delete asap */ - media->parms[media->num.val-1]->type.pres = PRSNT_NODEF; - /*media->parms[media->num.val-1]->type.val = MGT_MEDIAPAR_STRPAR;*/ + /* Kapil - NOT REQUIRED..keeping now just for ref..will delete asap */ + media->parms[media->num.val-1]->type.pres = PRSNT_NODEF; + /*media->parms[media->num.val-1]->type.val = MGT_MEDIAPAR_STRPAR;*/ - printf("media->num.val[%d]\n",media->num.val); + printf("media->num.val[%d]\n",media->num.val); - stream = &media->parms[media->num.val-1]->u.stream; - stream->pres.pres = PRSNT_NODEF; - stream->pres.val = 0x01; + stream = &media->parms[media->num.val-1]->u.stream; + stream->pres.pres = PRSNT_NODEF; + stream->pres.val = 0x01; #if 0 - if(inc_med_desc->num.pres && inc_med_desc->num.val){ - /* TODO - check stream descriptor type for all medias */ - inc_strm_desc = &inc_med_desc->parms[0]->u.stream; - memcpy(&stream->streamId, &inc_strm_desc->streamId, sizeof(MgMgcoStreamId)); - } + if(inc_med_desc->num.pres && inc_med_desc->num.val){ + /* TODO - check stream descriptor type for all medias */ + inc_strm_desc = &inc_med_desc->parms[0]->u.stream; + memcpy(&stream->streamId, &inc_strm_desc->streamId, sizeof(MgMgcoStreamId)); + } #endif - MG_INIT_TOKEN_VALUE(&(stream->streamId), 1); + MG_INIT_TOKEN_VALUE(&(stream->streamId), 1); - stream->sl.pres.pres = PRSNT_NODEF; - stream->sl.pres.val = 0x01; + stream->sl.pres.pres = PRSNT_NODEF; + stream->sl.pres.val = 0x01; - local = &stream->sl.local; + local = &stream->sl.local; #endif - media->parms[media->num.val-1]->type.pres = PRSNT_NODEF; - media->parms[media->num.val-1]->type.val = MGT_MEDIAPAR_LOCAL; + media->parms[media->num.val-1]->type.pres = PRSNT_NODEF; + media->parms[media->num.val-1]->type.val = MGT_MEDIAPAR_LOCAL; - local = &media->parms[media->num.val-1]->u.local; + local = &media->parms[media->num.val-1]->u.local; - local->pres.pres = PRSNT_NODEF; + local->pres.pres = PRSNT_NODEF; - psdp = &(local->sdp); + psdp = &(local->sdp); - if (mgUtlGrowList((void ***)&psdp->info, sizeof(CmSdpInfo), - &psdp->numComp, &rsp.u.mgCmdRsp[0]->memCp) != ROK) - { - switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR,"Grow List failed\n"); - return SWITCH_STATUS_FALSE; - } + if (mgUtlGrowList((void ***)&psdp->info, sizeof(CmSdpInfo), + &psdp->numComp, &rsp.u.mgCmdRsp[0]->memCp) != ROK) + { + switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR,"Grow List failed\n"); + return SWITCH_STATUS_FALSE; + } - psdp->info[psdp->numComp.val-1]->pres.pres = PRSNT_NODEF; + psdp->info[psdp->numComp.val-1]->pres.pres = PRSNT_NODEF; - /* fill version */ - /*memcpy(&psdp->info[0]->ver, &prsdp->info[0]->ver, sizeof(TknU16)); */ - MG_INIT_TOKEN_VALUE(&(psdp->info[psdp->numComp.val-1]->ver),1); + /* fill version */ + /*memcpy(&psdp->info[0]->ver, &prsdp->info[0]->ver, sizeof(TknU16)); */ + MG_INIT_TOKEN_VALUE(&(psdp->info[psdp->numComp.val-1]->ver),1); - /* fill orig */ - MG_INIT_TOKEN_VALUE(&(psdp->info[psdp->numComp.val-1]->orig.pres), 1); - MG_INIT_TOKEN_VALUE(&(psdp->info[psdp->numComp.val-1]->orig.type), CM_SDP_SPEC); - MG_INIT_TOKEN_VALUE(&(psdp->info[psdp->numComp.val-1]->orig.orig.pres), 1); + /* fill orig */ + MG_INIT_TOKEN_VALUE(&(psdp->info[psdp->numComp.val-1]->orig.pres), 1); + MG_INIT_TOKEN_VALUE(&(psdp->info[psdp->numComp.val-1]->orig.type), CM_SDP_SPEC); + MG_INIT_TOKEN_VALUE(&(psdp->info[psdp->numComp.val-1]->orig.orig.pres), 1); - MG_SET_TKNSTROSXL(psdp->info[psdp->numComp.val-1]->orig.orig.usrName, 1, "-", - &rsp.u.mgCmdRsp[0]->memCp); - MG_SET_TKNSTROSXL(psdp->info[psdp->numComp.val-1]->orig.orig.sessId, 1, "0", - &rsp.u.mgCmdRsp[0]->memCp); - MG_SET_TKNSTROSXL(psdp->info[psdp->numComp.val-1]->orig.orig.sessVer, 1, "0", - &rsp.u.mgCmdRsp[0]->memCp); - MG_SET_VAL_PRES( (psdp->info[psdp->numComp.val-1]->orig.orig.sdpAddr.netType.type), - CM_SDP_NET_TYPE_IN); - MG_SET_VAL_PRES( (psdp->info[psdp->numComp.val-1]->orig.orig.sdpAddr.addrType), - CM_SDP_ADDR_TYPE_IPV4); - MG_SET_VAL_PRES( (psdp->info[psdp->numComp.val-1]->orig.orig.sdpAddr.u.ip4.addrType), - CM_SDP_IPV4_IP_UNI); - MG_SET_VAL_PRES( (psdp->info[psdp->numComp.val-1]->orig.orig.sdpAddr.u.ip4.addrType), - CM_SDP_IPV4_IP_UNI); - MG_SET_VAL_PRES( (psdp->info[psdp->numComp.val-1]->orig.orig.sdpAddr.u.ip4.u.ip.b[0]), - ipAddress[0]); - MG_SET_VAL_PRES( (psdp->info[psdp->numComp.val-1]->orig.orig.sdpAddr.u.ip4.u.ip.b[1]), - ipAddress[1]); - MG_SET_VAL_PRES( (psdp->info[psdp->numComp.val-1]->orig.orig.sdpAddr.u.ip4.u.ip.b[2]), - ipAddress[2]); - MG_SET_VAL_PRES( (psdp->info[psdp->numComp.val-1]->orig.orig.sdpAddr.u.ip4.u.ip.b[3]), - ipAddress[3]); + MG_SET_TKNSTROSXL(psdp->info[psdp->numComp.val-1]->orig.orig.usrName, 1, "-", + &rsp.u.mgCmdRsp[0]->memCp); + MG_SET_TKNSTROSXL(psdp->info[psdp->numComp.val-1]->orig.orig.sessId, 1, "0", + &rsp.u.mgCmdRsp[0]->memCp); + MG_SET_TKNSTROSXL(psdp->info[psdp->numComp.val-1]->orig.orig.sessVer, 1, "0", + &rsp.u.mgCmdRsp[0]->memCp); + MG_SET_VAL_PRES( (psdp->info[psdp->numComp.val-1]->orig.orig.sdpAddr.netType.type), + CM_SDP_NET_TYPE_IN); + MG_SET_VAL_PRES( (psdp->info[psdp->numComp.val-1]->orig.orig.sdpAddr.addrType), + CM_SDP_ADDR_TYPE_IPV4); + MG_SET_VAL_PRES( (psdp->info[psdp->numComp.val-1]->orig.orig.sdpAddr.u.ip4.addrType), + CM_SDP_IPV4_IP_UNI); + MG_SET_VAL_PRES( (psdp->info[psdp->numComp.val-1]->orig.orig.sdpAddr.u.ip4.addrType), + CM_SDP_IPV4_IP_UNI); + MG_SET_VAL_PRES( (psdp->info[psdp->numComp.val-1]->orig.orig.sdpAddr.u.ip4.u.ip.b[0]), + atoi(ipAddress[0])); + MG_SET_VAL_PRES( (psdp->info[psdp->numComp.val-1]->orig.orig.sdpAddr.u.ip4.u.ip.b[1]), + atoi(ipAddress[1])); + MG_SET_VAL_PRES( (psdp->info[psdp->numComp.val-1]->orig.orig.sdpAddr.u.ip4.u.ip.b[2]), + atoi(ipAddress[2])); + MG_SET_VAL_PRES( (psdp->info[psdp->numComp.val-1]->orig.orig.sdpAddr.u.ip4.u.ip.b[3]), + atoi(ipAddress[3])); - /* fill session name */ - /* TODO - need to fill proper session name or skip it..*/ - MG_SET_TKNSTROSXL(psdp->info[psdp->numComp.val-1]->sessName, 8, "SANGOMA",&rsp.u.mgCmdRsp[0]->memCp); + /* fill session name */ + /* TODO - need to fill proper session name or skip it..*/ + MG_SET_TKNSTROSXL(psdp->info[psdp->numComp.val-1]->sessName, 8, "SANGOMA",&rsp.u.mgCmdRsp[0]->memCp); - /* Fill the SDP Connection Info */ - /* "c=" line - ipaddress */ - MG_INIT_TOKEN_VALUE(&(psdp->info[psdp->numComp.val-1]->conn.netType.type),CM_SDP_NET_TYPE_IN); - MG_INIT_TOKEN_VALUE(&(psdp->info[psdp->numComp.val-1]->conn.addrType), CM_SDP_ADDR_TYPE_IPV4); - MG_INIT_TOKEN_VALUE(&(psdp->info[psdp->numComp.val-1]->conn.u.ip4.addrType), CM_SDP_IPV4_IP_UNI); + /* Fill the SDP Connection Info */ + /* "c=" line - ipaddress */ + MG_INIT_TOKEN_VALUE(&(psdp->info[psdp->numComp.val-1]->conn.netType.type),CM_SDP_NET_TYPE_IN); + MG_INIT_TOKEN_VALUE(&(psdp->info[psdp->numComp.val-1]->conn.addrType), CM_SDP_ADDR_TYPE_IPV4); + MG_INIT_TOKEN_VALUE(&(psdp->info[psdp->numComp.val-1]->conn.u.ip4.addrType), CM_SDP_IPV4_IP_UNI); - MG_SET_VAL_PRES( (psdp->info[psdp->numComp.val-1]->conn.u.ip4.u.uniIp.b[0]), ipAddress[0]); - MG_SET_VAL_PRES( (psdp->info[psdp->numComp.val-1]->conn.u.ip4.u.uniIp.b[1]), ipAddress[1]); - MG_SET_VAL_PRES( (psdp->info[psdp->numComp.val-1]->conn.u.ip4.u.uniIp.b[2]), ipAddress[2]); - MG_SET_VAL_PRES( (psdp->info[psdp->numComp.val-1]->conn.u.ip4.u.uniIp.b[3]), ipAddress[3]); + MG_SET_VAL_PRES( (psdp->info[psdp->numComp.val-1]->conn.u.ip4.u.uniIp.b[0]), atoi(ipAddress[0])); + MG_SET_VAL_PRES( (psdp->info[psdp->numComp.val-1]->conn.u.ip4.u.uniIp.b[1]), atoi(ipAddress[1])); + MG_SET_VAL_PRES( (psdp->info[psdp->numComp.val-1]->conn.u.ip4.u.uniIp.b[2]), atoi(ipAddress[2])); + MG_SET_VAL_PRES( (psdp->info[psdp->numComp.val-1]->conn.u.ip4.u.uniIp.b[3]), atoi(ipAddress[3])); - /* t= line */ - MG_INIT_TOKEN_VALUE(&(psdp->info[psdp->numComp.val-1]->sdpTime.pres),1); + + /* t= line */ + MG_INIT_TOKEN_VALUE(&(psdp->info[psdp->numComp.val-1]->sdpTime.pres),1); #if 0 - MG_INIT_TOKEN_VALUE(&(psdp->info[psdp->numComp.val-1]->sdpTime.sdpOpTimeSet.numComp),0); - MG_INIT_TOKEN_VALUE(&(psdp->info[psdp->numComp.val-1]->sdpTime.zoneAdjSet.numComp),0); + MG_INIT_TOKEN_VALUE(&(psdp->info[psdp->numComp.val-1]->sdpTime.sdpOpTimeSet.numComp),0); + MG_INIT_TOKEN_VALUE(&(psdp->info[psdp->numComp.val-1]->sdpTime.zoneAdjSet.numComp),0); #endif - /* fill media descriptors */ - { - CmSdpMediaDescSet* med = &psdp->info[psdp->numComp.val-1]->mediaDescSet; - CmSdpMediaDesc* media; + /* fill media descriptors */ + { + CmSdpMediaDescSet* med = &psdp->info[psdp->numComp.val-1]->mediaDescSet; + CmSdpMediaDesc* media; - if (mgUtlGrowList((void ***)&med->mediaDesc, sizeof(CmSdpMediaDesc), - &med->numComp, &rsp.u.mgCmdRsp[0]->memCp) != ROK) - { - switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR,"Grow List failed\n"); - return SWITCH_STATUS_FALSE; - } + if (mgUtlGrowList((void ***)&med->mediaDesc, sizeof(CmSdpMediaDesc), + &med->numComp, &rsp.u.mgCmdRsp[0]->memCp) != ROK) + { + switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR,"Grow List failed\n"); + return SWITCH_STATUS_FALSE; + } - media = med->mediaDesc[med->numComp.val-1]; + media = med->mediaDesc[med->numComp.val-1]; - MG_INIT_TOKEN_VALUE(&(media->pres),1); + MG_INIT_TOKEN_VALUE(&(media->pres),1); - /* Fill CmSdpMediaField */ - MG_INIT_TOKEN_VALUE(&(media->field.pres),1); - MG_INIT_TOKEN_VALUE(&(media->field.mediaType),CM_SDP_MEDIA_AUDIO); + /* Fill CmSdpMediaField */ + MG_INIT_TOKEN_VALUE(&(media->field.pres),1); + MG_INIT_TOKEN_VALUE(&(media->field.mediaType),CM_SDP_MEDIA_AUDIO); - MG_INIT_TOKEN_VALUE(&(media->field.id.type),CM_SDP_VCID_PORT); - MG_INIT_TOKEN_VALUE(&(media->field.id.u.port.type),CM_SDP_PORT_INT); - MG_INIT_TOKEN_VALUE(&(media->field.id.u.port.u.portInt.pres),1); - MG_INIT_TOKEN_VALUE(&(media->field.id.u.port.u.portInt.port.type), CM_SDP_SPEC); - MG_INIT_TOKEN_VALUE(&(media->field.id.u.port.u.portInt.port.val), 2904); + MG_INIT_TOKEN_VALUE(&(media->field.id.type),CM_SDP_VCID_PORT); + MG_INIT_TOKEN_VALUE(&(media->field.id.u.port.type),CM_SDP_PORT_INT); + MG_INIT_TOKEN_VALUE(&(media->field.id.u.port.u.portInt.pres),1); + MG_INIT_TOKEN_VALUE(&(media->field.id.u.port.u.portInt.port.type), CM_SDP_SPEC); + //MG_INIT_TOKEN_VALUE(&(media->field.id.u.port.u.portInt.port.val), term->u.rtp.local_port); + MG_INIT_TOKEN_VALUE(&(media->field.id.u.port.u.portInt.port.val), 2904); - if (mgUtlGrowList((void ***)&media->field.par.pflst, sizeof(CmSdpMedProtoFmts), - &media->field.par.numProtFmts, &rsp.u.mgCmdRsp[0]->memCp) != ROK) - { - switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR,"Grow List failed\n"); - return SWITCH_STATUS_FALSE; - } + if (mgUtlGrowList((void ***)&media->field.par.pflst, sizeof(CmSdpMedProtoFmts), + &media->field.par.numProtFmts, &rsp.u.mgCmdRsp[0]->memCp) != ROK) + { + switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR,"Grow List failed\n"); + return SWITCH_STATUS_FALSE; + } - /* CmSdpMedProtoFmts */ - MG_INIT_TOKEN_VALUE(&(media->field.par.pflst[media->field.par.numProtFmts.val-1]->prot.type), CM_SDP_MEDIA_PROTO_RTP) - MG_INIT_TOKEN_VALUE(&(media->field.par.pflst[media->field.par.numProtFmts.val-1]->prot.u.subtype.type), CM_SDP_PROTO_RTP_AVP); - MG_INIT_TOKEN_VALUE(&(media->field.par.pflst[media->field.par.numProtFmts.val-1]->protType), CM_SDP_MEDIA_PROTO_RTP); + /* CmSdpMedProtoFmts */ + MG_INIT_TOKEN_VALUE(&(media->field.par.pflst[media->field.par.numProtFmts.val-1]->prot.type), CM_SDP_MEDIA_PROTO_RTP) + MG_INIT_TOKEN_VALUE(&(media->field.par.pflst[media->field.par.numProtFmts.val-1]->prot.u.subtype.type), CM_SDP_PROTO_RTP_AVP); + MG_INIT_TOKEN_VALUE(&(media->field.par.pflst[media->field.par.numProtFmts.val-1]->protType), CM_SDP_MEDIA_PROTO_RTP); - if (mgUtlGrowList((void ***)&media->field.par.pflst[media->field.par.numProtFmts.val-1]->u.rtp.fmts, sizeof(CmSdpU8OrNil), - &media->field.par.pflst[media->field.par.numProtFmts.val-1]->u.rtp.num, &rsp.u.mgCmdRsp[0]->memCp) != ROK) - { - switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR,"Grow List failed\n"); - return SWITCH_STATUS_FALSE; - } + if (mgUtlGrowList((void ***)&media->field.par.pflst[media->field.par.numProtFmts.val-1]->u.rtp.fmts, sizeof(CmSdpU8OrNil), + &media->field.par.pflst[media->field.par.numProtFmts.val-1]->u.rtp.num, &rsp.u.mgCmdRsp[0]->memCp) != ROK) + { + switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR,"Grow List failed\n"); + return SWITCH_STATUS_FALSE; + } - MG_INIT_TOKEN_VALUE(&(media->field.par.pflst[media->field.par.numProtFmts.val-1]->u.rtp.fmts[0]->type), CM_SDP_SPEC); + MG_INIT_TOKEN_VALUE(&(media->field.par.pflst[media->field.par.numProtFmts.val-1]->u.rtp.fmts[0]->type), CM_SDP_SPEC); - MG_INIT_TOKEN_VALUE(&(media->field.par.pflst[media->field.par.numProtFmts.val-1]->u.rtp.fmts[0]->val), 4); + MG_INIT_TOKEN_VALUE(&(media->field.par.pflst[media->field.par.numProtFmts.val-1]->u.rtp.fmts[0]->val), 4); - /* Fill attribute if reqd */ - { - if (mgUtlGrowList((void ***)&media->attrSet.attr, sizeof(CmSdpAttr), - &media->attrSet.numComp, &rsp.u.mgCmdRsp[0]->memCp) != ROK) - { - switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR,"Grow List failed\n"); - return SWITCH_STATUS_FALSE; - } + /* Fill attribute if reqd */ + { + if (mgUtlGrowList((void ***)&media->attrSet.attr, sizeof(CmSdpAttr), + &media->attrSet.numComp, &rsp.u.mgCmdRsp[0]->memCp) != ROK) + { + switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR,"Grow List failed\n"); + return SWITCH_STATUS_FALSE; + } - MG_INIT_TOKEN_VALUE(&(media->attrSet.attr[0]->type),CM_SDP_ATTR_PTIME); - MG_INIT_TOKEN_VALUE(&(media->attrSet.attr[0]->u.ptime),30); - } - - } - - } + MG_INIT_TOKEN_VALUE(&(media->attrSet.attr[0]->type),CM_SDP_ATTR_PTIME); + MG_INIT_TOKEN_VALUE(&(media->attrSet.attr[0]->u.ptime), term->u.rtp.ptime); + } + } + } /* We will always send one command at a time..*/ From 898a183a0e59311211ee6ba86bca100ac5465d5c Mon Sep 17 00:00:00 2001 From: Mathieu Rene Date: Wed, 25 Jul 2012 18:57:32 -0400 Subject: [PATCH 04/29] missing crtp init in mod_freetdm.c -- start implementing media modify --- libs/freetdm/mod_freetdm/mod_freetdm.c | 3 ++ .../mod_media_gateway/media_gateway.c | 47 +++++++++++-------- src/mod/endpoints/mod_sofia/rtp.c | 38 +++++++++++++++ 3 files changed, 69 insertions(+), 19 deletions(-) diff --git a/libs/freetdm/mod_freetdm/mod_freetdm.c b/libs/freetdm/mod_freetdm/mod_freetdm.c index 16bdacdad7..34fb3f469a 100755 --- a/libs/freetdm/mod_freetdm/mod_freetdm.c +++ b/libs/freetdm/mod_freetdm/mod_freetdm.c @@ -178,6 +178,7 @@ static const char* channel_get_variable(switch_core_session_t *session, switch_e ftdm_status_t ftdm_channel_from_event(ftdm_sigmsg_t *sigmsg, switch_core_session_t **sp); void dump_chan(ftdm_span_t *span, uint32_t chan_id, switch_stream_handle_t *stream); void dump_chan_xml(ftdm_span_t *span, uint32_t chan_id, switch_stream_handle_t *stream); +void ctdm_init(switch_loadable_module_interface_t *module_interface); static switch_core_session_t *ftdm_channel_get_session(ftdm_channel_t *channel, int32_t id) { @@ -5359,6 +5360,8 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_freetdm_load) SWITCH_ADD_APP(app_interface, "disable_dtmf", "Disable DTMF Detection", "Disable DTMF Detection", disable_dtmf_function, "", SAF_NONE); SWITCH_ADD_APP(app_interface, "enable_dtmf", "Enable DTMF Detection", "Enable DTMF Detection", enable_dtmf_function, "", SAF_NONE); + ctdm_init(*module_interface); + /* indicate that the module should continue to be loaded */ return SWITCH_STATUS_SUCCESS; } diff --git a/src/mod/endpoints/mod_media_gateway/media_gateway.c b/src/mod/endpoints/mod_media_gateway/media_gateway.c index 8fbd08abf5..fe2804d212 100644 --- a/src/mod/endpoints/mod_media_gateway/media_gateway.c +++ b/src/mod/endpoints/mod_media_gateway/media_gateway.c @@ -88,19 +88,6 @@ switch_status_t megaco_activate_termination(mg_termination_t *term) switch_status_t status = SWITCH_STATUS_SUCCESS; char dialstring[100]; switch_call_cause_t cause; - - if (!zstr(term->uuid)) { - /* A UUID is present, check if the channel still exists */ - switch_core_session_t *session; - if ((session = switch_core_session_locate(term->uuid))) { - switch_core_session_rwunlock(session); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Channel [%s] already exists for termination [%s]\n", term->uuid, term->name); - return SWITCH_STATUS_SUCCESS; - } - - /* The referenced channel doesn't exist anymore, clear it */ - term->uuid = NULL; - } switch_event_create(&var_event, SWITCH_EVENT_CLONE); @@ -126,14 +113,35 @@ switch_status_t megaco_activate_termination(mg_termination_t *term) /* Set common variables on the channel */ switch_event_add_header_string(var_event, SWITCH_STACK_BOTTOM, SWITCH_PARK_AFTER_BRIDGE_VARIABLE, "true"); + + if (!zstr(term->uuid)) { + /* A UUID is present, check if the channel still exists */ + switch_core_session_t *session; + if ((session = switch_core_session_locate(term->uuid))) { + switch_event_add_header_string(var_event, SWITCH_STACK_BOTTOM, "command", "media_modify"); + + switch_core_session_receive_event(session, &var_event); - if (switch_ivr_originate(NULL, &session, &cause, dialstring, 0, NULL, NULL, NULL, NULL, var_event, 0, NULL) != SWITCH_CAUSE_SUCCESS) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to instanciate termination [%s]: %s\n", term->name, switch_channel_cause2str(cause)); - status = SWITCH_STATUS_FALSE; - goto done; + switch_core_session_rwunlock(session); + + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Sent refresh to channel [%s], for termination [%s]\n", term->uuid, term->name); + + return SWITCH_STATUS_SUCCESS; + } + + /* The referenced channel doesn't exist anymore, clear it */ + term->uuid = NULL; } - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Termination [%s] successfully instanciated as [%s] [%s]\n", term->name, dialstring, switch_core_session_get_uuid(session)); + if (!zstr(term->uuid)) { + if (switch_ivr_originate(NULL, &session, &cause, dialstring, 0, NULL, NULL, NULL, NULL, var_event, 0, NULL) != SWITCH_CAUSE_SUCCESS) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to instanciate termination [%s]: %s\n", term->name, switch_channel_cause2str(cause)); + status = SWITCH_STATUS_FALSE; + goto done; + } + + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Termination [%s] successfully instanciated as [%s] [%s]\n", term->name, dialstring, switch_core_session_get_uuid(session)); + } switch_set_flag(term, MGT_ACTIVE); @@ -162,7 +170,7 @@ mg_termination_t *megaco_choose_termination(megaco_profile_t *profile, const cha switch_snprintf(name, sizeof name, "%s/%d", profile->rtp_termination_id_prefix, term_id); } else { for (term = profile->physical_terminations; term; term = term->next) { - if (!strncasecmp(prefix, term->name, prefixlen) && !switch_test_flag(term, MGT_ALLOCATED)) { + if (!switch_test_flag(term, MGT_ALLOCATED) && !strncasecmp(prefix, term->name, prefixlen)) { switch_set_flag(term, MGT_ALLOCATED); return term; } @@ -185,6 +193,7 @@ mg_termination_t *megaco_choose_termination(megaco_profile_t *profile, const cha term->u.rtp.local_port = switch_rtp_request_port(term->u.rtp.local_addr); term->u.rtp.codec = megaco_codec_str(profile->default_codec); term->u.rtp.term_id = term_id; + term->u.rtp.ptime = 20; term->name = switch_core_strdup(term->pool, name); } diff --git a/src/mod/endpoints/mod_sofia/rtp.c b/src/mod/endpoints/mod_sofia/rtp.c index a464beb1be..631c8e7711 100644 --- a/src/mod/endpoints/mod_sofia/rtp.c +++ b/src/mod/endpoints/mod_sofia/rtp.c @@ -93,6 +93,7 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch static switch_status_t channel_write_frame(switch_core_session_t *session, switch_frame_t *frame, switch_io_flag_t flags, int stream_id); static switch_status_t channel_receive_message(switch_core_session_t *session, switch_core_session_message_t *msg); static switch_status_t channel_send_dtmf(switch_core_session_t *session, const switch_dtmf_t *dtmf); +static switch_status_t channel_receive_event(switch_core_session_t *session, switch_event_t *event); switch_state_handler_table_t crtp_state_handlers = { .on_init = channel_on_init, @@ -104,6 +105,7 @@ switch_io_routines_t crtp_io_routines = { .read_frame = channel_read_frame, .write_frame = channel_write_frame, .receive_message = channel_receive_message, + .receive_event = channel_receive_event, .send_dtmf = channel_send_dtmf }; @@ -395,6 +397,42 @@ static switch_status_t channel_send_dtmf(switch_core_session_t *session, const s return SWITCH_STATUS_SUCCESS; } +static switch_bool_t compare_var(switch_event_t *event, switch_channel_t *channel, const char *varname) +{ + const char *chan_val = switch_channel_get_variable_dup(channel, varname, SWITCH_FALSE, -1); + const char *event_val = switch_event_get_header(event, varname); + + return strcasecmp(chan_val, event_val); +} + +static switch_status_t channel_receive_event(switch_core_session_t *session, switch_event_t *event) +{ + const char *command = switch_event_get_header(event, "command"); + switch_channel_t *channel = switch_core_session_get_channel(session); + + if (!zstr(command) && !strcasecmp(command, "media_modify")) { + /* Compare parameters */ + if (compare_var(event, channel, kREMOTEADDR) || + compare_var(event, channel, kREMOTEPORT) || + compare_var(event, channel, kLOCALADDR) || + compare_var(event, channel, kLOCALPORT)) { + /* We need to reset the rtp session */ + + } + + if (compare_var(event, channel, kCODEC) || + compare_var(event, channel, kPTIME) || + compare_var(event, channel, kPT) || + compare_var(event, channel, kRATE)) { + /* Reset codec */ + + } + + } else { + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Received unknown command [%s] in event.\n", !command ? "null" : command); + } +} + static switch_status_t channel_receive_message(switch_core_session_t *session, switch_core_session_message_t *msg) { crtp_private_t *tech_pvt = NULL; From 4f6f7eb4564128d7849c777348a10f623f9d4fa8 Mon Sep 17 00:00:00 2001 From: Mathieu Rene Date: Wed, 25 Jul 2012 19:34:15 -0400 Subject: [PATCH 05/29] refactor error --- src/mod/endpoints/mod_media_gateway/media_gateway.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mod/endpoints/mod_media_gateway/media_gateway.c b/src/mod/endpoints/mod_media_gateway/media_gateway.c index fe2804d212..70d31e6f55 100644 --- a/src/mod/endpoints/mod_media_gateway/media_gateway.c +++ b/src/mod/endpoints/mod_media_gateway/media_gateway.c @@ -133,7 +133,7 @@ switch_status_t megaco_activate_termination(mg_termination_t *term) term->uuid = NULL; } - if (!zstr(term->uuid)) { + if (zstr(term->uuid)) { if (switch_ivr_originate(NULL, &session, &cause, dialstring, 0, NULL, NULL, NULL, NULL, var_event, 0, NULL) != SWITCH_CAUSE_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to instanciate termination [%s]: %s\n", term->name, switch_channel_cause2str(cause)); status = SWITCH_STATUS_FALSE; From 87569c0ba9dd35fbce307369aeaeed0b5c116c91 Mon Sep 17 00:00:00 2001 From: Mathieu Rene Date: Wed, 25 Jul 2012 19:37:16 -0400 Subject: [PATCH 06/29] properly git rid of span_id --- libs/freetdm/mod_freetdm/tdm.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/libs/freetdm/mod_freetdm/tdm.c b/libs/freetdm/mod_freetdm/tdm.c index 53ee192cf0..405e4a9aad 100644 --- a/libs/freetdm/mod_freetdm/tdm.c +++ b/libs/freetdm/mod_freetdm/tdm.c @@ -97,8 +97,7 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi switch_memory_pool_t **pool, switch_originate_flag_t flags, switch_call_cause_t *cancel_cause) { - const char *szspanid = switch_event_get_header(var_event, kSPAN_ID), - *szchanid = switch_event_get_header(var_event, kCHAN_ID), + const char *szchanid = switch_event_get_header(var_event, kCHAN_ID), *span_name = switch_event_get_header(var_event, kSPAN_NAME); int chan_id; int span_id; @@ -113,22 +112,20 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi ctdm_private_t *tech_pvt = NULL; - if (zstr(szchanid) || (zstr(szspanid) && zstr(span_name))) { + if (zstr(szchanid) || zstr(span_name)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Both ["kSPAN_ID"] and ["kCHAN_ID"] have to be set.\n"); goto fail; } chan_id = atoi(szchanid); - span_id = atoi(szspanid); - - if (!span_id) { - if (ftdm_span_find_by_name(span_name, &span) == FTDM_SUCCESS) { - span_id = ftdm_span_get_id(span); - } else { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot find span [%s]\n"); - } + + if (ftdm_span_find_by_name(span_name, &span) == FTDM_SUCCESS) { + span_id = ftdm_span_get_id(span); + } else { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot find span [%s]\n"); } + if (!(*new_session = switch_core_session_request(ctdm.endpoint_interface, SWITCH_CALL_DIRECTION_OUTBOUND, 0, pool))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't request session.\n"); From 4950c32dd542069e73ffac4d1eff1934af189b5a Mon Sep 17 00:00:00 2001 From: Mathieu Rene Date: Wed, 25 Jul 2012 19:37:47 -0400 Subject: [PATCH 07/29] properly git rid of span_id --- libs/freetdm/mod_freetdm/tdm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/mod_freetdm/tdm.c b/libs/freetdm/mod_freetdm/tdm.c index 405e4a9aad..5c259e0cd1 100644 --- a/libs/freetdm/mod_freetdm/tdm.c +++ b/libs/freetdm/mod_freetdm/tdm.c @@ -123,7 +123,7 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi if (ftdm_span_find_by_name(span_name, &span) == FTDM_SUCCESS) { span_id = ftdm_span_get_id(span); } else { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot find span [%s]\n"); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot find span [%s]\n", span_name); } From 63b2654b54488c74b10de76a6a474ef79aa18bc5 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 25 Jul 2012 19:47:41 -0400 Subject: [PATCH 08/29] commit -- fix stash pop err --- libs/freetdm/mod_freetdm/tdm.c | 1 - .../media_gateway_cmd_handler.c | 29 +++++++++++++++---- src/mod/endpoints/mod_sofia/rtp.c | 2 ++ 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/libs/freetdm/mod_freetdm/tdm.c b/libs/freetdm/mod_freetdm/tdm.c index 5c259e0cd1..de52934570 100644 --- a/libs/freetdm/mod_freetdm/tdm.c +++ b/libs/freetdm/mod_freetdm/tdm.c @@ -119,7 +119,6 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi chan_id = atoi(szchanid); - if (ftdm_span_find_by_name(span_name, &span) == FTDM_SUCCESS) { span_id = ftdm_span_get_id(span); } else { diff --git a/src/mod/endpoints/mod_media_gateway/media_gateway_cmd_handler.c b/src/mod/endpoints/mod_media_gateway/media_gateway_cmd_handler.c index 5f756ac249..e040340e2c 100644 --- a/src/mod/endpoints/mod_media_gateway/media_gateway_cmd_handler.c +++ b/src/mod/endpoints/mod_media_gateway/media_gateway_cmd_handler.c @@ -540,8 +540,14 @@ switch_status_t handle_mg_add_cmd(megaco_profile_t* mg_profile, MgMgcoCommand *i MG_SET_VAL_PRES(new_ctxtId->val, mg_ctxt->context_id); } else { - /* context already present */ - memcpy(new_ctxtId, &inc_cmd->contextId,sizeof(MgMgcoContextId)); + /* context already present */ + memcpy(new_ctxtId, &inc_cmd->contextId,sizeof(MgMgcoContextId)); + mg_ctxt = megaco_get_context(mg_profile, inc_cmd->contextId.val.val); + if(NULL == mg_ctxt){ + mg_util_set_err_string(&errTxt, " Resource Failure "); + err_code = MGT_MGCO_RSP_CODE_RSRC_ERROR; + goto error; + } } /********************************************************************/ @@ -565,6 +571,17 @@ switch_status_t handle_mg_add_cmd(megaco_profile_t* mg_profile, MgMgcoCommand *i /* allocate rtp term and associated the same to context */ /********************************************************************/ }else{ /* Physical termination */ + printf("termId->name.lcl.val[%s]\n",termId->name.lcl.val); + term = megaco_find_termination(mg_profile, (char*)termId->name.lcl.val); + + if(NULL == term){ + mg_util_set_err_string(&errTxt, " Resource Failure "); + err_code = MGT_MGCO_RSP_CODE_RSRC_ERROR; + goto error; + } + + switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO," Allocated Termination[%p] with term name[%s]\n", (void*)term, term->name); + /* get physical termination */ } @@ -672,9 +689,10 @@ switch_status_t handle_mg_add_cmd(megaco_profile_t* mg_profile, MgMgcoCommand *i MgMgcoLocalDesc *local; CmSdpInfoSet *psdp; char* ipAddress[4];// = "192.168.1.1"; + char* dup = strdup((char*)term->u.rtp.local_addr); MgMgcoMediaDesc* media = &desc->u.media; - switch_split((char*)term->u.rtp.local_addr,'.',ipAddress); + switch_split(dup,'.',ipAddress); printf("ipAddress[0]=%s, ipAddress[1]=%s, ipAddress[2]=%s,ipAddress[3]=%s\n",ipAddress[0],ipAddress[1],ipAddress[2],ipAddress[3]); @@ -812,8 +830,7 @@ switch_status_t handle_mg_add_cmd(megaco_profile_t* mg_profile, MgMgcoCommand *i MG_INIT_TOKEN_VALUE(&(media->field.id.u.port.type),CM_SDP_PORT_INT); MG_INIT_TOKEN_VALUE(&(media->field.id.u.port.u.portInt.pres),1); MG_INIT_TOKEN_VALUE(&(media->field.id.u.port.u.portInt.port.type), CM_SDP_SPEC); - //MG_INIT_TOKEN_VALUE(&(media->field.id.u.port.u.portInt.port.val), term->u.rtp.local_port); - MG_INIT_TOKEN_VALUE(&(media->field.id.u.port.u.portInt.port.val), 2904); + MG_INIT_TOKEN_VALUE(&(media->field.id.u.port.u.portInt.port.val), term->u.rtp.local_port); if (mgUtlGrowList((void ***)&media->field.par.pflst, sizeof(CmSdpMedProtoFmts), &media->field.par.numProtFmts, &rsp.u.mgCmdRsp[0]->memCp) != ROK) @@ -852,6 +869,8 @@ switch_status_t handle_mg_add_cmd(megaco_profile_t* mg_profile, MgMgcoCommand *i MG_INIT_TOKEN_VALUE(&(media->attrSet.attr[0]->u.ptime), term->u.rtp.ptime); } } + + free(dup); } diff --git a/src/mod/endpoints/mod_sofia/rtp.c b/src/mod/endpoints/mod_sofia/rtp.c index 631c8e7711..3ab784d74d 100644 --- a/src/mod/endpoints/mod_sofia/rtp.c +++ b/src/mod/endpoints/mod_sofia/rtp.c @@ -431,6 +431,8 @@ static switch_status_t channel_receive_event(switch_core_session_t *session, swi } else { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Received unknown command [%s] in event.\n", !command ? "null" : command); } + + return SWITCH_STATUS_SUCCESS; } static switch_status_t channel_receive_message(switch_core_session_t *session, switch_core_session_message_t *msg) From 5284f5d134e11372eff658bd9d5a9530c33b6be3 Mon Sep 17 00:00:00 2001 From: Mathieu Rene Date: Wed, 25 Jul 2012 19:56:25 -0400 Subject: [PATCH 09/29] missing goto fail --- libs/freetdm/mod_freetdm/tdm.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libs/freetdm/mod_freetdm/tdm.c b/libs/freetdm/mod_freetdm/tdm.c index 5c259e0cd1..5b9f1486ec 100644 --- a/libs/freetdm/mod_freetdm/tdm.c +++ b/libs/freetdm/mod_freetdm/tdm.c @@ -124,6 +124,7 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi span_id = ftdm_span_get_id(span); } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot find span [%s]\n", span_name); + goto fail; } From 706c662f4b94cfc225a8de0c92e200fa8d9361cd Mon Sep 17 00:00:00 2001 From: Mathieu Rene Date: Wed, 25 Jul 2012 20:04:35 -0400 Subject: [PATCH 10/29] fix crash on chan open failure --- libs/freetdm/mod_freetdm/tdm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/mod_freetdm/tdm.c b/libs/freetdm/mod_freetdm/tdm.c index 5b9f1486ec..9ef95a7bfc 100644 --- a/libs/freetdm/mod_freetdm/tdm.c +++ b/libs/freetdm/mod_freetdm/tdm.c @@ -270,9 +270,9 @@ static switch_status_t channel_on_destroy(switch_core_session_t *session) if (tech_pvt->write_codec.implementation) { switch_core_codec_destroy(&tech_pvt->write_codec); } + + ftdm_channel_close(&tech_pvt->ftdm_channel); } - - ftdm_channel_close(&tech_pvt->ftdm_channel); return SWITCH_STATUS_SUCCESS; } From 3c382781340922e4d440afc3cf59280c4a2a761e Mon Sep 17 00:00:00 2001 From: David Yat Sin Date: Wed, 25 Jul 2012 20:41:01 -0400 Subject: [PATCH 11/29] Added new channel type clear-channel for channels that do not have a signalling module --- libs/freetdm/src/ftdm_io.c | 30 ++++++++++++++----- .../src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c | 3 +- libs/freetdm/src/include/freetdm.h | 3 +- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/libs/freetdm/src/ftdm_io.c b/libs/freetdm/src/ftdm_io.c index ec623ad6e6..2a5f1cb6ee 100644 --- a/libs/freetdm/src/ftdm_io.c +++ b/libs/freetdm/src/ftdm_io.c @@ -1470,13 +1470,23 @@ FT_DECLARE(ftdm_status_t) ftdm_group_channel_use_count(ftdm_group_t *group, uint static __inline__ int chan_is_avail(ftdm_channel_t *check) { - if (!ftdm_test_flag(check, FTDM_CHANNEL_READY) || - !ftdm_test_flag(check, FTDM_CHANNEL_SIG_UP) || - ftdm_test_flag(check, FTDM_CHANNEL_INUSE) || - ftdm_test_flag(check, FTDM_CHANNEL_SUSPENDED) || - ftdm_test_flag(check, FTDM_CHANNEL_IN_ALARM) || - check->state != FTDM_CHANNEL_STATE_DOWN) { - return 0; + if (check->type == FTDM_CHAN_TYPE_CLEAR) { + if (!ftdm_test_flag(check, FTDM_CHANNEL_READY) || + ftdm_test_flag(check, FTDM_CHANNEL_INUSE) || + ftdm_test_flag(check, FTDM_CHANNEL_SUSPENDED) || + ftdm_test_flag(check, FTDM_CHANNEL_IN_ALARM) || + check->state != FTDM_CHANNEL_STATE_DOWN) { + return 0; + } + } else { + if (!ftdm_test_flag(check, FTDM_CHANNEL_READY) || + !ftdm_test_flag(check, FTDM_CHANNEL_SIG_UP) || + ftdm_test_flag(check, FTDM_CHANNEL_INUSE) || + ftdm_test_flag(check, FTDM_CHANNEL_SUSPENDED) || + ftdm_test_flag(check, FTDM_CHANNEL_IN_ALARM) || + check->state != FTDM_CHANNEL_STATE_DOWN) { + return 0; + } } return 1; } @@ -5129,6 +5139,12 @@ static ftdm_status_t load_config(void) } else { ftdm_log(FTDM_LOG_WARNING, "Cannot add EM channels to a non-EM trunk!\n"); } + } else if (!strcasecmp(var, "clear-channel")) { + unsigned chans_configured = 0; + chan_config.type = FTDM_CHAN_TYPE_CLEAR; + if (ftdm_configure_span_channels(span, val, &chan_config, &chans_configured) == FTDM_SUCCESS) { + configured += chans_configured; + } } else if (!strcasecmp(var, "b-channel")) { unsigned chans_configured = 0; chan_config.type = FTDM_CHAN_TYPE_B; diff --git a/libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c b/libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c index 87ba7ed728..85ccba53bb 100755 --- a/libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c +++ b/libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c @@ -306,7 +306,8 @@ static unsigned wp_open_range(ftdm_span_t *span, unsigned spanno, unsigned start if (type == FTDM_CHAN_TYPE_FXS || type == FTDM_CHAN_TYPE_FXO || type == FTDM_CHAN_TYPE_CAS - || type == FTDM_CHAN_TYPE_B) { + || type == FTDM_CHAN_TYPE_B + || type == FTDM_CHAN_TYPE_CLEAR) { int err; hwec_str = "unavailable"; diff --git a/libs/freetdm/src/include/freetdm.h b/libs/freetdm/src/include/freetdm.h index f7de8519b7..a45fdfe661 100755 --- a/libs/freetdm/src/include/freetdm.h +++ b/libs/freetdm/src/include/freetdm.h @@ -181,9 +181,10 @@ typedef enum { FTDM_CHAN_TYPE_FXO, /*!< FXO analog channel */ FTDM_CHAN_TYPE_EM, /*!< E & M channel */ FTDM_CHAN_TYPE_CAS, /*!< CAS channel */ + FTDM_CHAN_TYPE_CLEAR, /* Clear channnel - no signalling module */ FTDM_CHAN_TYPE_COUNT /*!< Count of channel types */ } ftdm_chan_type_t; -#define CHAN_TYPE_STRINGS "B", "DQ921", "DQ931", "FXS", "FXO", "EM", "CAS", "INVALID" +#define CHAN_TYPE_STRINGS "B", "DQ921", "DQ931", "FXS", "FXO", "EM", "CAS", "CLEAR", "INVALID" /*! \brief transform from channel type to string and from string to channel type * ftdm_str2ftdm_chan_type transforms a channel string (ie: "FXO" to FTDM_CHAN_TYPE_FXO) * ftdm_chan_type2str transforms a channel type to string (ie: FTDM_CHAN_TYPE_B to "B") From ae84538819c9769fe2cd59472cbb6d4942514b13 Mon Sep 17 00:00:00 2001 From: Mathieu Rene Date: Wed, 25 Jul 2012 20:49:33 -0400 Subject: [PATCH 12/29] mark tdm channel as answered immediately --- libs/freetdm/mod_freetdm/tdm.c | 2 ++ src/switch_rtp.c | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/libs/freetdm/mod_freetdm/tdm.c b/libs/freetdm/mod_freetdm/tdm.c index 9ef95a7bfc..a01ac153b2 100644 --- a/libs/freetdm/mod_freetdm/tdm.c +++ b/libs/freetdm/mod_freetdm/tdm.c @@ -228,6 +228,8 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi goto fail; } + switch_channel_mark_answered(channel); + return SWITCH_CAUSE_SUCCESS; fail: diff --git a/src/switch_rtp.c b/src/switch_rtp.c index 3bad17ce17..3cc5255e8b 100644 --- a/src/switch_rtp.c +++ b/src/switch_rtp.c @@ -34,6 +34,8 @@ //#define RTP_DEBUG_WRITE_DELTA //#define DEBUG_MISSED_SEQ +typedef unsigned long u_long; + #include #include #include @@ -1451,7 +1453,7 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_add_crypto_key(switch_rtp_t *rtp_sess uint32_t index, switch_rtp_crypto_key_type_t type, unsigned char *key, switch_size_t keylen) { #ifndef ENABLE_SRTP - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_CRIT, "SRTP NOT SUPPORTED IN THIS BUILD!\n"); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "SRTP NOT SUPPORTED IN THIS BUILD!\n"); return SWITCH_STATUS_FALSE; #else switch_rtp_crypto_key_t *crypto_key; From c6fecc1ee814939dfefdbe80a84fff6d964cddc8 Mon Sep 17 00:00:00 2001 From: Mathieu Rene Date: Wed, 25 Jul 2012 20:50:18 -0400 Subject: [PATCH 13/29] go in consume media right away --- libs/freetdm/mod_freetdm/tdm.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libs/freetdm/mod_freetdm/tdm.c b/libs/freetdm/mod_freetdm/tdm.c index a01ac153b2..6076c193fe 100644 --- a/libs/freetdm/mod_freetdm/tdm.c +++ b/libs/freetdm/mod_freetdm/tdm.c @@ -256,6 +256,9 @@ fail: static switch_status_t channel_on_init(switch_core_session_t *session) { + switch_channel_t *channel = switch_core_session_get_channel(session); + + switch_channel_set_state(channel, CS_CONSUME_MEDIA); return SWITCH_STATUS_SUCCESS; } From 3bf9fef864ceb8854734003b51880b38bee1ed47 Mon Sep 17 00:00:00 2001 From: Mathieu Rene Date: Wed, 25 Jul 2012 20:54:47 -0400 Subject: [PATCH 14/29] originate returns a status, not a cause --- src/mod/endpoints/mod_media_gateway/media_gateway.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mod/endpoints/mod_media_gateway/media_gateway.c b/src/mod/endpoints/mod_media_gateway/media_gateway.c index 70d31e6f55..3ed79ab36a 100644 --- a/src/mod/endpoints/mod_media_gateway/media_gateway.c +++ b/src/mod/endpoints/mod_media_gateway/media_gateway.c @@ -134,7 +134,7 @@ switch_status_t megaco_activate_termination(mg_termination_t *term) } if (zstr(term->uuid)) { - if (switch_ivr_originate(NULL, &session, &cause, dialstring, 0, NULL, NULL, NULL, NULL, var_event, 0, NULL) != SWITCH_CAUSE_SUCCESS) { + if (switch_ivr_originate(NULL, &session, &cause, dialstring, 0, NULL, NULL, NULL, NULL, var_event, 0, NULL) != SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to instanciate termination [%s]: %s\n", term->name, switch_channel_cause2str(cause)); status = SWITCH_STATUS_FALSE; goto done; From b1398aaccbd6cf7aa4bde189c6006ebc099b076e Mon Sep 17 00:00:00 2001 From: Mathieu Rene Date: Wed, 25 Jul 2012 20:59:09 -0400 Subject: [PATCH 15/29] Im feeling bold --- src/switch_rtp.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/switch_rtp.c b/src/switch_rtp.c index 3cc5255e8b..16e473e30f 100644 --- a/src/switch_rtp.c +++ b/src/switch_rtp.c @@ -1834,6 +1834,7 @@ SWITCH_DECLARE(switch_rtp_t *) switch_rtp_new(const char *rx_host, goto end; } +#if 0 if (zstr(tx_host)) { *err = "Missing remote host"; goto end; @@ -1843,6 +1844,7 @@ SWITCH_DECLARE(switch_rtp_t *) switch_rtp_new(const char *rx_host, *err = "Missing remote port"; goto end; } +#endif if (switch_rtp_create(&rtp_session, payload, samples_per_interval, ms_per_packet, flags, timer_name, err, pool) != SWITCH_STATUS_SUCCESS) { goto end; @@ -1856,7 +1858,7 @@ SWITCH_DECLARE(switch_rtp_t *) switch_rtp_new(const char *rx_host, goto end; } - if (switch_rtp_set_remote_address(rtp_session, tx_host, tx_port, 0, SWITCH_TRUE, err) != SWITCH_STATUS_SUCCESS) { + if (!zstr(tx_host) && switch_rtp_set_remote_address(rtp_session, tx_host, tx_port, 0, SWITCH_TRUE, err) != SWITCH_STATUS_SUCCESS) { switch_mutex_unlock(rtp_session->flag_mutex); rtp_session = NULL; goto end; From 051692d268e9b180ec6e50b16af18d0f398af5a3 Mon Sep 17 00:00:00 2001 From: Mathieu Rene Date: Wed, 25 Jul 2012 21:04:15 -0400 Subject: [PATCH 16/29] save the uuid --- src/mod/endpoints/mod_media_gateway/media_gateway.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/mod/endpoints/mod_media_gateway/media_gateway.c b/src/mod/endpoints/mod_media_gateway/media_gateway.c index 3ed79ab36a..9805548b6f 100644 --- a/src/mod/endpoints/mod_media_gateway/media_gateway.c +++ b/src/mod/endpoints/mod_media_gateway/media_gateway.c @@ -140,6 +140,7 @@ switch_status_t megaco_activate_termination(mg_termination_t *term) goto done; } + term->uuid = switch_core_strdup(term->pool, switch_core_session_get_uuid(session)); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Termination [%s] successfully instanciated as [%s] [%s]\n", term->name, dialstring, switch_core_session_get_uuid(session)); } From 0494df1ac4054e34ee6210442ba98bc50eec853d Mon Sep 17 00:00:00 2001 From: Mathieu Rene Date: Wed, 25 Jul 2012 21:06:47 -0400 Subject: [PATCH 17/29] give the tdm channels their caller profile so switch_ivr_uuid_bridge doesn't piss its pants off --- libs/freetdm/mod_freetdm/tdm.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libs/freetdm/mod_freetdm/tdm.c b/libs/freetdm/mod_freetdm/tdm.c index 6076c193fe..6398515b72 100644 --- a/libs/freetdm/mod_freetdm/tdm.c +++ b/libs/freetdm/mod_freetdm/tdm.c @@ -101,7 +101,7 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi *span_name = switch_event_get_header(var_event, kSPAN_NAME); int chan_id; int span_id; - + switch_caller_profile_t *caller_profile; ftdm_span_t *span; ftdm_channel_t *chan; switch_channel_t *channel; @@ -149,6 +149,10 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi tech_pvt->session = *new_session; switch_core_session_set_private(*new_session, tech_pvt); + + caller_profile = switch_caller_profile_clone(*new_session, outbound_profile); + switch_channel_set_caller_profile(channel, caller_profile); + snprintf(name, sizeof(name), "tdm/%d:%d", span_id, chan_id); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Connect outbound channel %s\n", name); switch_channel_set_name(channel, name); From 4d3038c9e4e882116ca53e2fe25910caf91b7078 Mon Sep 17 00:00:00 2001 From: Mathieu Rene Date: Wed, 25 Jul 2012 21:16:14 -0400 Subject: [PATCH 18/29] add logging before uuid_bridge, set frame->codec from tech_pvt->read_codec --- libs/freetdm/mod_freetdm/tdm.c | 1 + src/mod/endpoints/mod_media_gateway/media_gateway.c | 4 ++++ src/mod/endpoints/mod_sofia/rtp.c | 1 + 3 files changed, 6 insertions(+) diff --git a/libs/freetdm/mod_freetdm/tdm.c b/libs/freetdm/mod_freetdm/tdm.c index 6398515b72..89e0d3c464 100644 --- a/libs/freetdm/mod_freetdm/tdm.c +++ b/libs/freetdm/mod_freetdm/tdm.c @@ -337,6 +337,7 @@ top: *frame = &tech_pvt->read_frame; tech_pvt->read_frame.datalen = (uint32_t)len; tech_pvt->read_frame.samples = tech_pvt->read_frame.datalen; + tech_pvt->read_frame = &tech_pvt->read_codec; if (ftdm_channel_get_codec(tech_pvt->ftdm_channel) == FTDM_CODEC_SLIN) { tech_pvt->read_frame.samples /= 2; diff --git a/src/mod/endpoints/mod_media_gateway/media_gateway.c b/src/mod/endpoints/mod_media_gateway/media_gateway.c index 9805548b6f..3d10abf05c 100644 --- a/src/mod/endpoints/mod_media_gateway/media_gateway.c +++ b/src/mod/endpoints/mod_media_gateway/media_gateway.c @@ -286,6 +286,10 @@ switch_status_t megaco_context_add_termination(mg_context_t *ctx, mg_termination megaco_activate_termination(ctx->terminations[1]); } + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Bridging: %s (%s) <> %s (%s)\n", + ctx->terminations[0]->name, ctx->terminations[0]->uuid, + ctx->terminations[1]->name, ctx->terminations[1]->uuid); + switch_ivr_uuid_bridge(ctx->terminations[0]->uuid, ctx->terminations[1]->uuid); } diff --git a/src/mod/endpoints/mod_sofia/rtp.c b/src/mod/endpoints/mod_sofia/rtp.c index 631c8e7711..43e2725224 100644 --- a/src/mod/endpoints/mod_sofia/rtp.c +++ b/src/mod/endpoints/mod_sofia/rtp.c @@ -325,6 +325,7 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch } tech_pvt->read_frame.flags = SFF_NONE; + tech_pvt->read_frame.codec = &tech_pvt->read_codec; status = switch_rtp_zerocopy_read_frame(tech_pvt->rtp_session, &tech_pvt->read_frame, flags); if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) { From f85347cf7221f6c0a5eee1a783a28f2ba71ef1d9 Mon Sep 17 00:00:00 2001 From: Mathieu Rene Date: Wed, 25 Jul 2012 21:16:46 -0400 Subject: [PATCH 19/29] add logging before uuid_bridge, set frame->codec from tech_pvt->read_codec --- libs/freetdm/mod_freetdm/tdm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/freetdm/mod_freetdm/tdm.c b/libs/freetdm/mod_freetdm/tdm.c index 89e0d3c464..f22ded6cb1 100644 --- a/libs/freetdm/mod_freetdm/tdm.c +++ b/libs/freetdm/mod_freetdm/tdm.c @@ -337,7 +337,7 @@ top: *frame = &tech_pvt->read_frame; tech_pvt->read_frame.datalen = (uint32_t)len; tech_pvt->read_frame.samples = tech_pvt->read_frame.datalen; - tech_pvt->read_frame = &tech_pvt->read_codec; + tech_pvt->read_frame.codec = &tech_pvt->read_codec; if (ftdm_channel_get_codec(tech_pvt->ftdm_channel) == FTDM_CODEC_SLIN) { tech_pvt->read_frame.samples /= 2; From 039c18638c16c71b7165615b34437a8e871af961 Mon Sep 17 00:00:00 2001 From: Mathieu Rene Date: Wed, 25 Jul 2012 21:26:53 -0400 Subject: [PATCH 20/29] allocate recv buffer for tdm --- libs/freetdm/mod_freetdm/tdm.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libs/freetdm/mod_freetdm/tdm.c b/libs/freetdm/mod_freetdm/tdm.c index f22ded6cb1..2e81c59c71 100644 --- a/libs/freetdm/mod_freetdm/tdm.c +++ b/libs/freetdm/mod_freetdm/tdm.c @@ -52,6 +52,8 @@ typedef struct { switch_core_session_t *session; switch_codec_t read_codec, write_codec; switch_frame_t read_frame; + + unsigned char databuf[SWITCH_RECOMMENDED_BUFFER_SIZE]; } ctdm_private_t; static switch_status_t channel_on_init(switch_core_session_t *session); @@ -147,6 +149,8 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi tech_pvt->span_id = span_id; tech_pvt->ftdm_channel = chan; tech_pvt->session = *new_session; + tech_pvt->read_frame.buflen = sizeof(tech_pvt->databuf); + tech_pvt->read_frame.data = tech_pvt->databuf; switch_core_session_set_private(*new_session, tech_pvt); From c649c5b02355934e5394b3eba0d15be6a4906427 Mon Sep 17 00:00:00 2001 From: Mathieu Rene Date: Wed, 25 Jul 2012 21:49:47 -0400 Subject: [PATCH 21/29] allow remote addr modification on rtp --- src/mod/endpoints/mod_sofia/rtp.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/mod/endpoints/mod_sofia/rtp.c b/src/mod/endpoints/mod_sofia/rtp.c index 43e2725224..215f545990 100644 --- a/src/mod/endpoints/mod_sofia/rtp.c +++ b/src/mod/endpoints/mod_sofia/rtp.c @@ -410,15 +410,25 @@ static switch_status_t channel_receive_event(switch_core_session_t *session, swi { const char *command = switch_event_get_header(event, "command"); switch_channel_t *channel = switch_core_session_get_channel(session); + crtp_private_t *tech_pvt = switch_core_session_get_private(session); if (!zstr(command) && !strcasecmp(command, "media_modify")) { /* Compare parameters */ if (compare_var(event, channel, kREMOTEADDR) || - compare_var(event, channel, kREMOTEPORT) || - compare_var(event, channel, kLOCALADDR) || - compare_var(event, channel, kLOCALPORT)) { - /* We need to reset the rtp session */ + compare_var(event, channel, kREMOTEPORT)) { + char *remote_addr = switch_event_get_header(event, kREMOTEADDR); + char *szremote_port = switch_event_get_header(event, kREMOTEADDR); + switch_port_t remote_port = !zstr(szremote_port) ? atoi(szremote_port) : 0; + switch_channel_set_variable(channel, kREMOTEADDR, remote_addr); + switch_channel_set_variable(channel, kREMOTEPORT, szremote_port); + const char *err; + + if (switch_rtp_set_remote_address(tech_pvt->rtp_session, remote_addr, remote_port, 0, SWITCH_TRUE, &err) != SWITCH_STATUS_SUCCESS) { + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Error setting RTP remote address: %s\n", err); + } else { + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Set RTP remote: %s:%d\n", remote_addr, (int)remote_port); + } } if (compare_var(event, channel, kCODEC) || @@ -426,7 +436,7 @@ static switch_status_t channel_receive_event(switch_core_session_t *session, swi compare_var(event, channel, kPT) || compare_var(event, channel, kRATE)) { /* Reset codec */ - + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_CRIT, "Switching codec not yet implemented\n"); } } else { From 84796f84f1b2625bf85bb3d208da698ac9b87dae Mon Sep 17 00:00:00 2001 From: Mathieu Rene Date: Wed, 25 Jul 2012 21:58:03 -0400 Subject: [PATCH 22/29] allow remote addr modification on rtp --- src/mod/endpoints/mod_sofia/rtp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mod/endpoints/mod_sofia/rtp.c b/src/mod/endpoints/mod_sofia/rtp.c index 215f545990..b24bb1653a 100644 --- a/src/mod/endpoints/mod_sofia/rtp.c +++ b/src/mod/endpoints/mod_sofia/rtp.c @@ -419,10 +419,11 @@ static switch_status_t channel_receive_event(switch_core_session_t *session, swi char *remote_addr = switch_event_get_header(event, kREMOTEADDR); char *szremote_port = switch_event_get_header(event, kREMOTEADDR); switch_port_t remote_port = !zstr(szremote_port) ? atoi(szremote_port) : 0; + const char *err; + switch_channel_set_variable(channel, kREMOTEADDR, remote_addr); switch_channel_set_variable(channel, kREMOTEPORT, szremote_port); - const char *err; if (switch_rtp_set_remote_address(tech_pvt->rtp_session, remote_addr, remote_port, 0, SWITCH_TRUE, &err) != SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Error setting RTP remote address: %s\n", err); @@ -438,7 +439,6 @@ static switch_status_t channel_receive_event(switch_core_session_t *session, swi /* Reset codec */ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_CRIT, "Switching codec not yet implemented\n"); } - } else { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Received unknown command [%s] in event.\n", !command ? "null" : command); } From 43e39619ae76be00bedf2f15276b04cc0fbb6ec5 Mon Sep 17 00:00:00 2001 From: Mathieu Rene Date: Wed, 25 Jul 2012 22:24:12 -0400 Subject: [PATCH 23/29] prevent writes if we dont have a remote addr --- src/mod/endpoints/mod_sofia/rtp.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/mod/endpoints/mod_sofia/rtp.c b/src/mod/endpoints/mod_sofia/rtp.c index b24bb1653a..a12b3c6e55 100644 --- a/src/mod/endpoints/mod_sofia/rtp.c +++ b/src/mod/endpoints/mod_sofia/rtp.c @@ -188,11 +188,12 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi tech_pvt->dtmf_type = DTMF_2833; /* XXX */ if (zstr(local_addr) || local_port == 0) { - tech_pvt->mode = RTP_SENDONLY; + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "The local address and port must be set\n"); + goto fail; } else if (zstr(remote_addr) || remote_port == 0) { - tech_pvt->mode = RTP_SENDRECV; + tech_pvt->mode = RTP_RECVONLY; } else { - + tech_pvt->mode = RTP_SENDRECV; } switch_core_session_set_private(*new_session, tech_pvt); @@ -314,7 +315,7 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch tech_pvt = switch_core_session_get_private(session); assert(tech_pvt != NULL); - if (!tech_pvt->rtp_session) { + if (!tech_pvt->rtp_session || tech_pvt->mode == RTP_RECVONLY) { goto cng; } @@ -429,6 +430,7 @@ static switch_status_t channel_receive_event(switch_core_session_t *session, swi switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Error setting RTP remote address: %s\n", err); } else { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Set RTP remote: %s:%d\n", remote_addr, (int)remote_port); + tech_pvt->mode = RTP_SENDRECV; } } @@ -439,6 +441,15 @@ static switch_status_t channel_receive_event(switch_core_session_t *session, swi /* Reset codec */ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_CRIT, "Switching codec not yet implemented\n"); } + + if (compare_var(event, channel, kRFC2833PT)) { + const char *szpt = switch_channel_get_variable(channel, kRFC2833PT); + int pt = !zstr(szpt) ? atoi(szpt) : 0; + + switch_channel_set_variable(channel, kRFC2833PT, szpt); + switch_rtp_set_telephony_event(tech_pvt->rtp_session, pt); + } + } else { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Received unknown command [%s] in event.\n", !command ? "null" : command); } From a4bb00023c6f785a96589e8611bd02493d92ad03 Mon Sep 17 00:00:00 2001 From: David Yat Sin Date: Wed, 25 Jul 2012 23:16:32 -0400 Subject: [PATCH 24/29] Reverted back clear-channel, used existing FTDM_SIGTYPE instead --- libs/freetdm/src/ftdm_io.c | 8 +------- libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c | 3 +-- libs/freetdm/src/include/freetdm.h | 3 +-- 3 files changed, 3 insertions(+), 11 deletions(-) diff --git a/libs/freetdm/src/ftdm_io.c b/libs/freetdm/src/ftdm_io.c index 2a5f1cb6ee..b8b9cff527 100644 --- a/libs/freetdm/src/ftdm_io.c +++ b/libs/freetdm/src/ftdm_io.c @@ -1470,7 +1470,7 @@ FT_DECLARE(ftdm_status_t) ftdm_group_channel_use_count(ftdm_group_t *group, uint static __inline__ int chan_is_avail(ftdm_channel_t *check) { - if (check->type == FTDM_CHAN_TYPE_CLEAR) { + if (check->span->signal_type == FTDM_SIGTYPE_NONE) { if (!ftdm_test_flag(check, FTDM_CHANNEL_READY) || ftdm_test_flag(check, FTDM_CHANNEL_INUSE) || ftdm_test_flag(check, FTDM_CHANNEL_SUSPENDED) || @@ -5139,12 +5139,6 @@ static ftdm_status_t load_config(void) } else { ftdm_log(FTDM_LOG_WARNING, "Cannot add EM channels to a non-EM trunk!\n"); } - } else if (!strcasecmp(var, "clear-channel")) { - unsigned chans_configured = 0; - chan_config.type = FTDM_CHAN_TYPE_CLEAR; - if (ftdm_configure_span_channels(span, val, &chan_config, &chans_configured) == FTDM_SUCCESS) { - configured += chans_configured; - } } else if (!strcasecmp(var, "b-channel")) { unsigned chans_configured = 0; chan_config.type = FTDM_CHAN_TYPE_B; diff --git a/libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c b/libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c index 85ccba53bb..87ba7ed728 100755 --- a/libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c +++ b/libs/freetdm/src/ftmod/ftmod_wanpipe/ftmod_wanpipe.c @@ -306,8 +306,7 @@ static unsigned wp_open_range(ftdm_span_t *span, unsigned spanno, unsigned start if (type == FTDM_CHAN_TYPE_FXS || type == FTDM_CHAN_TYPE_FXO || type == FTDM_CHAN_TYPE_CAS - || type == FTDM_CHAN_TYPE_B - || type == FTDM_CHAN_TYPE_CLEAR) { + || type == FTDM_CHAN_TYPE_B) { int err; hwec_str = "unavailable"; diff --git a/libs/freetdm/src/include/freetdm.h b/libs/freetdm/src/include/freetdm.h index a45fdfe661..f7de8519b7 100755 --- a/libs/freetdm/src/include/freetdm.h +++ b/libs/freetdm/src/include/freetdm.h @@ -181,10 +181,9 @@ typedef enum { FTDM_CHAN_TYPE_FXO, /*!< FXO analog channel */ FTDM_CHAN_TYPE_EM, /*!< E & M channel */ FTDM_CHAN_TYPE_CAS, /*!< CAS channel */ - FTDM_CHAN_TYPE_CLEAR, /* Clear channnel - no signalling module */ FTDM_CHAN_TYPE_COUNT /*!< Count of channel types */ } ftdm_chan_type_t; -#define CHAN_TYPE_STRINGS "B", "DQ921", "DQ931", "FXS", "FXO", "EM", "CAS", "CLEAR", "INVALID" +#define CHAN_TYPE_STRINGS "B", "DQ921", "DQ931", "FXS", "FXO", "EM", "CAS", "INVALID" /*! \brief transform from channel type to string and from string to channel type * ftdm_str2ftdm_chan_type transforms a channel string (ie: "FXO" to FTDM_CHAN_TYPE_FXO) * ftdm_chan_type2str transforms a channel type to string (ie: FTDM_CHAN_TYPE_B to "B") From ee8047ebbf3314749712155a6775283c449fccda Mon Sep 17 00:00:00 2001 From: root Date: Thu, 26 Jul 2012 12:30:33 -0400 Subject: [PATCH 25/29] changes on test box --- .../media_gateway_cmd_handler.c | 24 +- .../mod_media_gateway/media_gateway_stack.h | 9 +- .../mod_media_gateway/media_gateway_utils.c | 489 +++++++++--------- .../mod_media_gateway/mod_media_gateway.c | 4 +- .../mod_media_gateway/mod_media_gateway.h | 1 + src/mod/endpoints/mod_sofia/rtp.c | 19 +- src/switch_channel.c | 4 +- src/switch_rtp.c | 2 +- 8 files changed, 296 insertions(+), 256 deletions(-) diff --git a/src/mod/endpoints/mod_media_gateway/media_gateway_cmd_handler.c b/src/mod/endpoints/mod_media_gateway/media_gateway_cmd_handler.c index e040340e2c..27fe1a4a4b 100644 --- a/src/mod/endpoints/mod_media_gateway/media_gateway_cmd_handler.c +++ b/src/mod/endpoints/mod_media_gateway/media_gateway_cmd_handler.c @@ -301,6 +301,8 @@ switch_status_t mg_prc_descriptors(megaco_profile_t* mg_profile, MgMgcoCommand * } } + mgco_handle_sdp(&local->sdp, term, MG_SDP_LOCAL); + break; } @@ -311,6 +313,7 @@ switch_status_t mg_prc_descriptors(megaco_profile_t* mg_profile, MgMgcoCommand * remote = &mediaPar->u.remote; sdp = remote->sdp.info[0]; /* for Matt - same like local descriptor */ + mgco_handle_sdp(&remote->sdp, term, MG_SDP_REMOTE); break; } @@ -403,12 +406,12 @@ switch_status_t mg_prc_descriptors(megaco_profile_t* mg_profile, MgMgcoCommand * if (mgStream->sl.remote.pres.pres) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Got remote stream media description:\n"); - mgco_print_sdp(&mgStream->sl.remote.sdp); + mgco_handle_sdp(&mgStream->sl.remote.sdp, term, MG_SDP_LOCAL); } if (mgStream->sl.local.pres.pres) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Got local stream media description:\n"); - mgco_print_sdp(&mgStream->sl.local.sdp); + mgco_handle_sdp(&mgStream->sl.local.sdp, term, MG_SDP_REMOTE); } break; @@ -567,11 +570,8 @@ switch_status_t handle_mg_add_cmd(megaco_profile_t* mg_profile, MgMgcoCommand *i is_rtp = 0x01; - /* TODO - Matt */ - /* allocate rtp term and associated the same to context */ - /********************************************************************/ + /********************************************************************/ }else{ /* Physical termination */ - printf("termId->name.lcl.val[%s]\n",termId->name.lcl.val); term = megaco_find_termination(mg_profile, (char*)termId->name.lcl.val); if(NULL == term){ @@ -581,9 +581,6 @@ switch_status_t handle_mg_add_cmd(megaco_profile_t* mg_profile, MgMgcoCommand *i } switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO," Allocated Termination[%p] with term name[%s]\n", (void*)term, term->name); - - - /* get physical termination */ } /********************************************************************/ /* associate physical termination to context */ @@ -694,8 +691,6 @@ switch_status_t handle_mg_add_cmd(megaco_profile_t* mg_profile, MgMgcoCommand *i switch_split(dup,'.',ipAddress); - printf("ipAddress[0]=%s, ipAddress[1]=%s, ipAddress[2]=%s,ipAddress[3]=%s\n",ipAddress[0],ipAddress[1],ipAddress[2],ipAddress[3]); - /* Most probably we need to add local descriptor */ /* allocating mem for local descriptor */ @@ -918,8 +913,8 @@ switch_status_t handle_mg_modify_cmd(megaco_profile_t* mg_profile, MgMgcoCommand MgMgcoInd *mgErr; MgMgcoTermId *termId; MgMgcoTermIdLst* termLst; - mg_termination_t* term = NULL; - switch_status_t ret; + mg_termination_t* term = NULL; + switch_status_t ret; int err_code; /*MgMgcoAmmReq *cmd = &inc_cmd->u.mgCmdInd[0]->cmd.u.mod;*/ U32 txn_id = inc_cmd->transId.val; @@ -1033,6 +1028,9 @@ switch_status_t handle_mg_modify_cmd(megaco_profile_t* mg_profile, MgMgcoCommand ret = mg_prc_descriptors(mg_profile, inc_cmd, term); + /* SDP updated to termination */ + + megaco_activate_termination(term); } /********************************************************************/ diff --git a/src/mod/endpoints/mod_media_gateway/media_gateway_stack.h b/src/mod/endpoints/mod_media_gateway/media_gateway_stack.h index 8c429ef620..9401ce49ce 100644 --- a/src/mod/endpoints/mod_media_gateway/media_gateway_stack.h +++ b/src/mod/endpoints/mod_media_gateway/media_gateway_stack.h @@ -15,6 +15,13 @@ #define MG_INACTIVITY_TMR_RESOLUTION 100 /* mit in ito package is experessed in 10ms steps */ +typedef enum{ + MG_SDP_NONE, + MG_SDP_LOCAL, + MG_SDP_REMOTE, +}mgco_sdp_types_e; + + typedef enum{ SNG_MG_TPT_NONE, SNG_MG_TPT_UDP, @@ -151,7 +158,7 @@ int sng_mgco_mg_get_status(int elemId, MgMngmt* cfm, megaco_profile_t* mg_cfg, m switch_status_t mg_is_ito_pkg_req(megaco_profile_t* mg_profile, MgMgcoCommand *cmd); switch_status_t mg_send_end_of_axn(SuId suId, MgMgcoTransId* transId, MgMgcoContextId* ctxtId, TknU32* peerId); -void mgco_print_sdp(CmSdpInfoSet *sdp); +void mgco_handle_sdp(CmSdpInfoSet *sdp,mg_termination_t* term, mgco_sdp_types_e sdp_type); void mg_util_set_ctxt_string ( MgStr *errTxt, MgMgcoContextId *ctxtId); switch_status_t handle_mg_add_cmd(megaco_profile_t* mg_profile, MgMgcoCommand *inc_cmd, MgMgcoContextId* new_ctxtId); switch_status_t handle_mg_subtract_cmd(megaco_profile_t* mg_profile, MgMgcoCommand *inc_cmd); diff --git a/src/mod/endpoints/mod_media_gateway/media_gateway_utils.c b/src/mod/endpoints/mod_media_gateway/media_gateway_utils.c index 4e4d34b736..56a1ffdc3a 100644 --- a/src/mod/endpoints/mod_media_gateway/media_gateway_utils.c +++ b/src/mod/endpoints/mod_media_gateway/media_gateway_utils.c @@ -740,8 +740,11 @@ void mgco_print_sdp_attr_set(CmSdpAttrSet *s) } -void mgco_print_sdp_c_line(CmSdpConn *s) +void mgco_handle_sdp_c_line(CmSdpConn *s, mg_termination_t* term, mgco_sdp_types_e sdp_type) { + char ipadd[12]; + memset(ipadd, 0, 12); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "********** SDP connection line ****** \n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t Net Type = %d \n", @@ -760,7 +763,21 @@ void mgco_print_sdp_c_line(CmSdpConn *s) s->u.ip4.u.uniIp.b[1].val, s->u.ip4.u.uniIp.b[2].val, s->u.ip4.u.uniIp.b[3].val); - } + + if(MG_SDP_REMOTE == sdp_type) { + sprintf(ipadd,"%d.%d.%d.%d", + s->u.ip4.u.uniIp.b[0].val, + s->u.ip4.u.uniIp.b[1].val, + s->u.ip4.u.uniIp.b[2].val, + s->u.ip4.u.uniIp.b[3].val); + printf("Remote ip = %s \n", ipadd); + /* update remote ip */ + if(MG_TERM_RTP == term->type){ + term->u.rtp.remote_addr = strdup(ipadd); + printf("Update remote ip to [%s]\n", term->u.rtp.remote_addr); + } + } + } } switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "**************** \n"); } @@ -834,255 +851,263 @@ void mgco_print_sdp_media_param(CmSdpMedPar *s) switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "**************** \n"); } -void mgco_print_sdp(CmSdpInfoSet *sdp) +void mgco_handle_sdp(CmSdpInfoSet *sdp, mg_termination_t* term, mgco_sdp_types_e sdp_type) { - int i; + int i; + + if (sdp->numComp.pres == NOTPRSNT) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, " No %s SDP present \n", (MG_SDP_LOCAL== sdp_type)?"MG_SDP_LOCAL":"MG_SDP_REMOTE"); + return; + } + + for (i = 0; i < sdp->numComp.val; i++) { + CmSdpInfo *s = sdp->info[i]; + int mediaId; + + /************************************************************************************************************************/ + /* info presence check */ + if(NOTPRSNT == s->pres.pres) continue; + + /************************************************************************************************************************/ + /* Version */ + if(NOTPRSNT != s->ver.pres) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, " SDP Version = %d \n", s->ver.val); + } + + /************************************************************************************************************************/ + /* Orig */ + if(NOTPRSNT != s->orig.pres.pres) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "********** SDP orig line ****** \n \t Type = %d \n", s->orig.type.val); + + if(NOTPRSNT != s->orig.orig.pres.pres) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t User Name = %s \n", + (NOTPRSNT != s->orig.orig.usrName.pres)?(char*)s->orig.orig.usrName.val:"Not Present"); + + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t Session Id = %s \n", + (NOTPRSNT != s->orig.orig.sessId.pres)?(char*)s->orig.orig.sessId.val:"Not Present"); + + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t Session Version = %s \n", + (NOTPRSNT != s->orig.orig.sessVer.pres)?(char*)s->orig.orig.sessVer.val:"Not Present"); + + /* sdpAddr */ + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t Net Type = %d \n", + (NOTPRSNT != s->orig.orig.sdpAddr.netType.type.pres)?s->orig.orig.sdpAddr.netType.type.val:-1); + + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t Address Type = %d \n", + (NOTPRSNT != s->orig.orig.sdpAddr.addrType.pres)?s->orig.orig.sdpAddr.addrType.val:-1); + + /* print IPV4 address */ + if (s->orig.orig.sdpAddr.addrType.pres && s->orig.orig.sdpAddr.addrType.val == CM_SDP_ADDR_TYPE_IPV4 && + s->orig.orig.sdpAddr.netType.type.val == CM_SDP_NET_TYPE_IN && + s->orig.orig.sdpAddr.u.ip4.addrType.val == CM_SDP_IPV4_IP_UNI) { + + if (s->orig.orig.sdpAddr.u.ip4.addrType.pres) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Address: %d.%d.%d.%d\n", + s->orig.orig.sdpAddr.u.ip4.u.ip.b[0].val, + s->orig.orig.sdpAddr.u.ip4.u.ip.b[1].val, + s->orig.orig.sdpAddr.u.ip4.u.ip.b[2].val, + s->orig.orig.sdpAddr.u.ip4.u.ip.b[3].val); + } + + }else{ + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t O-line not present \n"); + } + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "********** ****** \n"); + } + } else{ + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t O-line not present \n"); + } + /************************************************************************************************************************/ + /* Session Name (s = line) */ + + if(NOTPRSNT != s->sessName.pres) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t Session Name = %s \n", s->sessName.val); + } else{ + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t s-line not present \n"); + } + + /************************************************************************************************************************/ + /* Session Info(i= line) */ + + if(NOTPRSNT != s->info.pres) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t Session Info = %s \n", s->info.val); + } else{ + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t i-line not present \n"); + } + + /************************************************************************************************************************/ + /* Session Uri */ + + if(NOTPRSNT != s->uri.pres) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t Session Uri = %s \n", s->uri.val); + } else{ + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t uri not present \n"); + } + + /************************************************************************************************************************/ + /* E-Mail */ + /* TODO */ - if (sdp->numComp.pres == NOTPRSNT) { - return; - } - - for (i = 0; i < sdp->numComp.val; i++) { - CmSdpInfo *s = sdp->info[i]; - int mediaId; - - /************************************************************************************************************************/ - /* info presence check */ - if(NOTPRSNT == s->pres.pres) continue; - - /************************************************************************************************************************/ - /* Version */ - if(NOTPRSNT != s->ver.pres) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, " SDP Version = %d \n", s->ver.val); - } - - /************************************************************************************************************************/ - /* Orig */ - if(NOTPRSNT != s->orig.pres.pres) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "********** SDP orig line ****** \n \t Type = %d \n", s->orig.type.val); - - if(NOTPRSNT != s->orig.orig.pres.pres) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t User Name = %s \n", - (NOTPRSNT != s->orig.orig.usrName.pres)?(char*)s->orig.orig.usrName.val:"Not Present"); - - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t Session Id = %s \n", - (NOTPRSNT != s->orig.orig.sessId.pres)?(char*)s->orig.orig.sessId.val:"Not Present"); - - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t Session Version = %s \n", - (NOTPRSNT != s->orig.orig.sessVer.pres)?(char*)s->orig.orig.sessVer.val:"Not Present"); - - /* sdpAddr */ - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t Net Type = %d \n", - (NOTPRSNT != s->orig.orig.sdpAddr.netType.type.pres)?s->orig.orig.sdpAddr.netType.type.val:-1); - - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t Address Type = %d \n", - (NOTPRSNT != s->orig.orig.sdpAddr.addrType.pres)?s->orig.orig.sdpAddr.addrType.val:-1); - - /* print IPV4 address */ - if (s->orig.orig.sdpAddr.addrType.pres && s->orig.orig.sdpAddr.addrType.val == CM_SDP_ADDR_TYPE_IPV4 && - s->orig.orig.sdpAddr.netType.type.val == CM_SDP_NET_TYPE_IN && - s->orig.orig.sdpAddr.u.ip4.addrType.val == CM_SDP_IPV4_IP_UNI) { - - if (s->orig.orig.sdpAddr.u.ip4.addrType.pres) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Address: %d.%d.%d.%d\n", - s->orig.orig.sdpAddr.u.ip4.u.ip.b[0].val, - s->orig.orig.sdpAddr.u.ip4.u.ip.b[1].val, - s->orig.orig.sdpAddr.u.ip4.u.ip.b[2].val, - s->orig.orig.sdpAddr.u.ip4.u.ip.b[3].val); - } - - }else{ - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t O-line not present \n"); - } - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "********** ****** \n"); - } - } else{ - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t O-line not present \n"); - } - /************************************************************************************************************************/ - /* Session Name (s = line) */ - - if(NOTPRSNT != s->sessName.pres) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t Session Name = %s \n", s->sessName.val); - } else{ - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t s-line not present \n"); - } - - /************************************************************************************************************************/ - /* Session Info(i= line) */ - - if(NOTPRSNT != s->info.pres) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t Session Info = %s \n", s->info.val); - } else{ - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t i-line not present \n"); - } - - /************************************************************************************************************************/ - /* Session Uri */ - - if(NOTPRSNT != s->uri.pres) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t Session Uri = %s \n", s->uri.val); - } else{ - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t uri not present \n"); - } - - /************************************************************************************************************************/ - /* E-Mail */ - /* TODO */ + /************************************************************************************************************************/ + /* Phone */ + /* TODO */ - /************************************************************************************************************************/ - /* Phone */ - /* TODO */ + /************************************************************************************************************************/ + /* connection line */ + + mgco_handle_sdp_c_line(&s->conn, term, sdp_type); + /************************************************************************************************************************/ + /* Bandwidth */ + /* TODO */ + + /************************************************************************************************************************/ + /* SDP Time (t= line)*/ + + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "*** t-line **************** \n"); + if(NOTPRSNT != s->sdpTime.pres.pres) { + if(NOTPRSNT != s->sdpTime.sdpOpTimeSet.numComp.pres) { + int i = 0x00; + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "SDP op time present with total component[%d]\n", s->sdpTime.sdpOpTimeSet.numComp.val); + for (i = 0;isdpTime.sdpOpTimeSet.numComp.val;i++){ + CmSdpOpTime* t = s->sdpTime.sdpOpTimeSet.sdpOpTime[i]; + if(NOTPRSNT == t->pres.pres) continue; + + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t Start Time = %s \n", + (NOTPRSNT != t->startTime.pres)?(char*)t->startTime.val:"Not Present"); + + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t Stop Time = %s \n", + (NOTPRSNT != t->stopTime.pres)?(char*)t->stopTime.val:"Not Present"); + + /*repeat time repFieldSet */ + + if(NOTPRSNT != t->repFieldSet.numComp.pres) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "SDP repeat time present with total component[%d]\n", + t->repFieldSet.numComp.val); + + /*TODO - print repeat fields */ + }else{ + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "SDP repeat time not present \n"); + } + } /* sdpOpTimeSet.numComp for loop -- end */ + }else{/*sdpOpTimeSet.numComp.pres if -- end */ + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "SDP op time not present \n"); + } + + /*TODO - zoneAdjSet */ + }else{ + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "t-line not present \n"); + } + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "**************** \n"); - /************************************************************************************************************************/ - /* connection line */ + /************************************************************************************************************************/ + /* key type (k= line)*/ - mgco_print_sdp_c_line(&s->conn); - /************************************************************************************************************************/ - /* Bandwidth */ - /* TODO */ + if(NOTPRSNT != s->keyType.pres.pres) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t Key Type = %d \n", + (NOTPRSNT != s->keyType.keyType.pres)?s->keyType.keyType.val:-1); - /************************************************************************************************************************/ - /* SDP Time (t= line)*/ + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t Key Data = %s \n", + (NOTPRSNT != s->keyType.key_data.pres)?(char*)s->keyType.key_data.val:"Not Present"); + }else{ + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "k-line not present \n"); + } - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "*** t-line **************** \n"); - if(NOTPRSNT != s->sdpTime.pres.pres) { - if(NOTPRSNT != s->sdpTime.sdpOpTimeSet.numComp.pres) { - int i = 0x00; - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "SDP op time present with total component[%d]\n", s->sdpTime.sdpOpTimeSet.numComp.val); - for (i = 0;isdpTime.sdpOpTimeSet.numComp.val;i++){ - CmSdpOpTime* t = s->sdpTime.sdpOpTimeSet.sdpOpTime[i]; - if(NOTPRSNT == t->pres.pres) continue; + /************************************************************************************************************************/ + /* Attribute Set */ - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t Start Time = %s \n", - (NOTPRSNT != t->startTime.pres)?(char*)t->startTime.val:"Not Present"); + mgco_print_sdp_attr_set(&s->attrSet); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t Stop Time = %s \n", - (NOTPRSNT != t->stopTime.pres)?(char*)t->stopTime.val:"Not Present"); + /************************************************************************************************************************/ + /* Media Descriptor Set */ - /*repeat time repFieldSet */ + if (s->mediaDescSet.numComp.pres) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "****** Media Descriptor Set present with numComp[%d]\n", s->mediaDescSet.numComp.val); + for (mediaId = 0; mediaId < s->mediaDescSet.numComp.val; mediaId++) { + CmSdpMediaDesc *desc = s->mediaDescSet.mediaDesc[mediaId]; - if(NOTPRSNT != t->repFieldSet.numComp.pres) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "SDP repeat time present with total component[%d]\n", - t->repFieldSet.numComp.val); + if(NOTPRSNT == desc->pres.pres) continue; - /*TODO - print repeat fields */ - }else{ - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "SDP repeat time not present \n"); - } - } /* sdpOpTimeSet.numComp for loop -- end */ - }else{/*sdpOpTimeSet.numComp.pres if -- end */ - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "SDP op time not present \n"); - } + /* Media Field */ + { + CmSdpMediaField* f = &desc->field; + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t Media Type = %d \n",(NOTPRSNT == f->mediaType.pres)?f->mediaType.val:-1); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t Media = %s \n",(NOTPRSNT == f->media.pres)?(char*)f->media.val:"Not Present"); + /* Channel ID */ + if(NOTPRSNT != f->id.type.pres){ + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t VcId Type = %d \n", f->id.type.val); + switch(f->id.type.val){ + case CM_SDP_VCID_PORT: + { + CmSdpPort *p = &f->id.u.port; + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "CM_SDP_VCID_PORT:\n"); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t SDP port type = %d \n", (NOTPRSNT == p->type.pres)?p->type.val:-1); + switch(p->type.val) + { + case CM_SDP_PORT_INT: + { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, + "\t CM_SDP_PORT_INT: SDP port = %d type = %d \n", + p->u.portInt.port.val.val, p->u.portInt.port.type.val); + if(MG_SDP_REMOTE == sdp_type) { + /* update remote information */ + if(MG_TERM_RTP == term->type){ + term->u.rtp.remote_port = p->u.portInt.port.val.val; + printf("Update remote port to [%d]\n", term->u.rtp.remote_port); + } + } + break; + } + case CM_SDP_PORT_VPCID: + { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t CM_SDP_PORT_VPCID: \n"); + break; + } + default: + break; + } + break; + } + default: + break; + } + } + mgco_print_sdp_media_param(&f->par); + } - /*TODO - zoneAdjSet */ - }else{ - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "t-line not present \n"); - } - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "**************** \n"); + /*info */ + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t Info = %s \n",(NOTPRSNT == desc->info.pres)?(char*)desc->info.val:"Not Present"); + + /*connection set */ + { + int cnt=0x00; + if(NOTPRSNT != desc->connSet.numComp.pres){ + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t Number of Connection component[%d]\n",desc->connSet.numComp.val); + for(cnt=0;cntconnSet.numComp.val;cnt++){ + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "************************\n"); + mgco_handle_sdp_c_line(desc->connSet.connSet[cnt], term, sdp_type); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "************************\n"); + } + } + } + + /* attribute set */ + mgco_print_sdp_attr_set(&desc->attrSet); - /************************************************************************************************************************/ - /* key type (k= line)*/ + if (desc->field.mediaType.val == CM_SDP_MEDIA_AUDIO && + desc->field.id.type.val == CM_SDP_VCID_PORT && + desc->field.id.u.port.type.val == CM_SDP_PORT_INT && + desc->field.id.u.port.u.portInt.port.type.val == CM_SDP_SPEC) { + int port = desc->field.id.u.port.u.portInt.port.val.val; - if(NOTPRSNT != s->keyType.pres.pres) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t Key Type = %d \n", - (NOTPRSNT != s->keyType.keyType.pres)?s->keyType.keyType.val:-1); - - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t Key Data = %s \n", - (NOTPRSNT != s->keyType.key_data.pres)?(char*)s->keyType.key_data.val:"Not Present"); - }else{ - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "k-line not present \n"); - } - - /************************************************************************************************************************/ - /* Attribute Set */ - - mgco_print_sdp_attr_set(&s->attrSet); - - /************************************************************************************************************************/ - /* Media Descriptor Set */ - - if (s->mediaDescSet.numComp.pres) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "****** Media Descriptor Set present with numComp[%d]\n", s->mediaDescSet.numComp.val); - for (mediaId = 0; mediaId < s->mediaDescSet.numComp.val; mediaId++) { - CmSdpMediaDesc *desc = s->mediaDescSet.mediaDesc[mediaId]; - - if(NOTPRSNT == desc->pres.pres) continue; - - /* Media Field */ - { - CmSdpMediaField* f = &desc->field; - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t Media Type = %d \n",(NOTPRSNT == f->mediaType.pres)?f->mediaType.val:-1); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t Media = %s \n",(NOTPRSNT == f->media.pres)?(char*)f->media.val:"Not Present"); - /* Channel ID */ - if(NOTPRSNT != f->id.type.pres){ - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t VcId Type = %d \n", f->id.type.val); - switch(f->id.type.val){ - case CM_SDP_VCID_PORT: - { - CmSdpPort *p = &f->id.u.port; - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "CM_SDP_VCID_PORT:\n"); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t SDP port type = %d \n", (NOTPRSNT == p->type.pres)?p->type.val:-1); - switch(p->type.val) - { - case CM_SDP_PORT_INT: - { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t CM_SDP_PORT_INT: SDP port = %d type = %d \n", p->u.portInt.port.val.val, p->u.portInt.port.type.val); - break; - } - case CM_SDP_PORT_VPCID: - { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t CM_SDP_PORT_VPCID: \n"); - break; - } - default: - break; - } - break; - } - default: - break; - } - } - mgco_print_sdp_media_param(&f->par); - } - - /*info */ - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t Info = %s \n",(NOTPRSNT == desc->info.pres)?(char*)desc->info.val:"Not Present"); - - /*connection set */ - { - int cnt=0x00; - if(NOTPRSNT != desc->connSet.numComp.pres){ - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "\t Number of Connection component[%d]\n",desc->connSet.numComp.val); - for(cnt=0;cntconnSet.numComp.val;cnt++){ - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "************************\n"); - mgco_print_sdp_c_line(desc->connSet.connSet[cnt]); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "************************\n"); - } - } - } - - /* attribute set */ - mgco_print_sdp_attr_set(&desc->attrSet); - - - if (desc->field.mediaType.val == CM_SDP_MEDIA_AUDIO && - desc->field.id.type.val == CM_SDP_VCID_PORT && - desc->field.id.u.port.type.val == CM_SDP_PORT_INT && - desc->field.id.u.port.u.portInt.port.type.val == CM_SDP_SPEC) { - int port = desc->field.id.u.port.u.portInt.port.val.val; - - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Port: %d\n", port); - - } - } - } - } + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Port: %d\n", port); + } + } + } + } } /*****************************************************************************************************************************/ diff --git a/src/mod/endpoints/mod_media_gateway/mod_media_gateway.c b/src/mod/endpoints/mod_media_gateway/mod_media_gateway.c index 1533ca7d15..de315d7ae9 100644 --- a/src/mod/endpoints/mod_media_gateway/mod_media_gateway.c +++ b/src/mod/endpoints/mod_media_gateway/mod_media_gateway.c @@ -639,7 +639,7 @@ void handle_mgco_cmd_ind(Pst *pst, SuId suId, MgMgcoCommand* cmd) MgMgcoNtfyReply* ntfy = &cmd->u.mgCmdCfm[0]->u.ntfy; MgMgcoTermId* term = NULL; char term_name[32]; - memset(&term_name[0], 32, 0x00); + memset(&term_name[0], 0x00,32); strcpy(&term_name[0], "Invalid"); @@ -685,7 +685,7 @@ void handle_mgco_cmd_ind(Pst *pst, SuId suId, MgMgcoCommand* cmd) MgMgcoSvcChgReply* svc = &cmd->u.mgCmdCfm[0]->u.svc; MgMgcoTermId* term = NULL; char term_name[32]; - memset(&term_name[0], 32, 0x00); + memset(&term_name[0], 0x00, 32); strcpy(&term_name[0], "Invalid"); diff --git a/src/mod/endpoints/mod_media_gateway/mod_media_gateway.h b/src/mod/endpoints/mod_media_gateway/mod_media_gateway.h index c1960877bd..bf2fda7a05 100644 --- a/src/mod/endpoints/mod_media_gateway/mod_media_gateway.h +++ b/src/mod/endpoints/mod_media_gateway/mod_media_gateway.h @@ -231,6 +231,7 @@ mg_context_t *megaco_choose_context(megaco_profile_t *profile); void megaco_release_context(mg_context_t *ctx); switch_status_t megaco_context_sub_termination(mg_context_t *ctx, mg_termination_t *term); switch_status_t megaco_context_sub_all_termination(mg_context_t *ctx); +switch_status_t megaco_activate_termination(mg_termination_t *term); mg_termination_t *megaco_choose_termination(megaco_profile_t *profile, const char *prefix); mg_termination_t *megaco_find_termination(megaco_profile_t *profile, const char *name); diff --git a/src/mod/endpoints/mod_sofia/rtp.c b/src/mod/endpoints/mod_sofia/rtp.c index d56ca14a1f..04feb55a8a 100644 --- a/src/mod/endpoints/mod_sofia/rtp.c +++ b/src/mod/endpoints/mod_sofia/rtp.c @@ -315,7 +315,8 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch tech_pvt = switch_core_session_get_private(session); assert(tech_pvt != NULL); - if (!tech_pvt->rtp_session || tech_pvt->mode == RTP_RECVONLY) { + if (!tech_pvt->rtp_session || tech_pvt->mode == RTP_SENDONLY) { + switch_yield(20000); /* replace by local timer XXX */ goto cng; } @@ -338,6 +339,7 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch cng: *frame = &tech_pvt->read_frame; + tech_pvt->read_frame.codec = &tech_pvt->read_codec; tech_pvt->read_frame.flags |= SFF_CNG; tech_pvt->read_frame.datalen = 0; @@ -370,8 +372,11 @@ static switch_status_t channel_write_frame(switch_core_session_t *session, switc tech_pvt->timestamp_send += samples; #endif - - switch_rtp_write_frame(tech_pvt->rtp_session, frame); + if (tech_pvt->mode == RTP_RECVONLY) { + return SWITCH_STATUS_SUCCESS; + } + + switch_rtp_write_frame(tech_pvt->rtp_session, frame); return SWITCH_STATUS_SUCCESS; } @@ -403,7 +408,11 @@ static switch_bool_t compare_var(switch_event_t *event, switch_channel_t *channe { const char *chan_val = switch_channel_get_variable_dup(channel, varname, SWITCH_FALSE, -1); const char *event_val = switch_event_get_header(event, varname); - + + if (zstr(chan_val) || zstr(event_val)) { + return 1; + } + return strcasecmp(chan_val, event_val); } @@ -418,7 +427,7 @@ static switch_status_t channel_receive_event(switch_core_session_t *session, swi if (compare_var(event, channel, kREMOTEADDR) || compare_var(event, channel, kREMOTEPORT)) { char *remote_addr = switch_event_get_header(event, kREMOTEADDR); - char *szremote_port = switch_event_get_header(event, kREMOTEADDR); + char *szremote_port = switch_event_get_header(event, kREMOTEPORT); switch_port_t remote_port = !zstr(szremote_port) ? atoi(szremote_port) : 0; const char *err; diff --git a/src/switch_channel.c b/src/switch_channel.c index 138123f3eb..a563a67b1a 100644 --- a/src/switch_channel.c +++ b/src/switch_channel.c @@ -4154,8 +4154,8 @@ SWITCH_DECLARE(const char *) switch_channel_get_partner_uuid(switch_channel_t *c { const char *uuid = NULL; - if (!(uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE))) { - uuid = switch_channel_get_variable(channel, SWITCH_ORIGINATE_SIGNAL_BOND_VARIABLE); + if (!(uuid = switch_channel_get_variable_dup(channel, SWITCH_SIGNAL_BOND_VARIABLE, SWITCH_FALSE, -1))) { + uuid = switch_channel_get_variable_dup(channel, SWITCH_ORIGINATE_SIGNAL_BOND_VARIABLE, SWITCH_FALSE, -1); } return uuid; diff --git a/src/switch_rtp.c b/src/switch_rtp.c index 16e473e30f..f3234a21b2 100644 --- a/src/switch_rtp.c +++ b/src/switch_rtp.c @@ -2165,7 +2165,7 @@ SWITCH_DECLARE(uint8_t) switch_rtp_ready(switch_rtp_t *rtp_session) } switch_mutex_lock(rtp_session->flag_mutex); - ret = (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_IO) && rtp_session->sock_input && rtp_session->sock_output && rtp_session->remote_addr + ret = (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_IO) && rtp_session->sock_input /* && rtp_session->sock_output && rtp_session->remote_addr */ && rtp_session->ready == 2) ? 1 : 0; switch_mutex_unlock(rtp_session->flag_mutex); From 0e5ebbd984e2ca72e0badf3a357662e781c7fac0 Mon Sep 17 00:00:00 2001 From: Mathieu Rene Date: Thu, 26 Jul 2012 12:43:32 -0400 Subject: [PATCH 26/29] remove typedef added for code completion --- src/switch_rtp.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/switch_rtp.c b/src/switch_rtp.c index f3234a21b2..341b005473 100644 --- a/src/switch_rtp.c +++ b/src/switch_rtp.c @@ -34,8 +34,6 @@ //#define RTP_DEBUG_WRITE_DELTA //#define DEBUG_MISSED_SEQ -typedef unsigned long u_long; - #include #include #include From a6b85b7de570399b8490ab5a6d3a14e0d6405f26 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 26 Jul 2012 13:50:43 -0400 Subject: [PATCH 27/29] fixing two add for same termination back-2-back scenario, 2nd add should reject as term already in context --- .../endpoints/mod_media_gateway/media_gateway.c | 3 +++ .../media_gateway_cmd_handler.c | 13 +++++++++++++ .../mod_media_gateway/media_gateway_stack.h | 5 +++++ .../mod_media_gateway/media_gateway_utils.c | 10 ++++++++-- .../mod_media_gateway/media_gateway_xml.c | 2 ++ .../mod_media_gateway/mod_media_gateway.h | 17 ++++++++++------- 6 files changed, 41 insertions(+), 9 deletions(-) diff --git a/src/mod/endpoints/mod_media_gateway/media_gateway.c b/src/mod/endpoints/mod_media_gateway/media_gateway.c index 3d10abf05c..e47055236a 100644 --- a/src/mod/endpoints/mod_media_gateway/media_gateway.c +++ b/src/mod/endpoints/mod_media_gateway/media_gateway.c @@ -185,6 +185,7 @@ mg_termination_t *megaco_choose_termination(megaco_profile_t *profile, const cha term->pool = pool; term->type = termtype; term->active_events = NULL; + term->mg_ctxt = NULL; term->profile = profile; switch_set_flag(term, MGT_ALLOCATED); @@ -231,6 +232,8 @@ void megaco_termination_destroy(mg_termination_t *term) free(term->active_events); term->active_events = NULL; } + + term->mg_ctxt = NULL; switch_clear_flag(term, MGT_ALLOCATED); switch_clear_flag(term, MGT_ACTIVE); diff --git a/src/mod/endpoints/mod_media_gateway/media_gateway_cmd_handler.c b/src/mod/endpoints/mod_media_gateway/media_gateway_cmd_handler.c index 27fe1a4a4b..57c8843aee 100644 --- a/src/mod/endpoints/mod_media_gateway/media_gateway_cmd_handler.c +++ b/src/mod/endpoints/mod_media_gateway/media_gateway_cmd_handler.c @@ -566,6 +566,10 @@ switch_status_t handle_mg_add_cmd(megaco_profile_t* mg_profile, MgMgcoCommand *i goto error; } + if(!term->mg_ctxt){ + term->mg_ctxt = mg_ctxt; + } + switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO," Allocated Termination[%p] with term name[%s]\n", (void*)term, term->name); is_rtp = 0x01; @@ -580,6 +584,15 @@ switch_status_t handle_mg_add_cmd(megaco_profile_t* mg_profile, MgMgcoCommand *i goto error; } + if(!term->mg_ctxt){ + term->mg_ctxt = mg_ctxt; + } else { + switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO," Termination[%s] already in context..rejecting ADD \n", term->name); + mg_util_set_err_string(&errTxt, " Term already is in call "); + err_code = MGT_MGCP_RSP_CODE_PROT_ERROR; + goto error; + } + switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_INFO," Allocated Termination[%p] with term name[%s]\n", (void*)term, term->name); } /********************************************************************/ diff --git a/src/mod/endpoints/mod_media_gateway/media_gateway_stack.h b/src/mod/endpoints/mod_media_gateway/media_gateway_stack.h index 9401ce49ce..e5c16df9c0 100644 --- a/src/mod/endpoints/mod_media_gateway/media_gateway_stack.h +++ b/src/mod/endpoints/mod_media_gateway/media_gateway_stack.h @@ -15,6 +15,11 @@ #define MG_INACTIVITY_TMR_RESOLUTION 100 /* mit in ito package is experessed in 10ms steps */ +/* rtp/avp profiles */ +#define MG_RTP_AVP_PROFILE_A_LAW 8 +#define MG_RTP_AVP_PROFILE_U_LAW 0 + + typedef enum{ MG_SDP_NONE, MG_SDP_LOCAL, diff --git a/src/mod/endpoints/mod_media_gateway/media_gateway_utils.c b/src/mod/endpoints/mod_media_gateway/media_gateway_utils.c index 56a1ffdc3a..908b604118 100644 --- a/src/mod/endpoints/mod_media_gateway/media_gateway_utils.c +++ b/src/mod/endpoints/mod_media_gateway/media_gateway_utils.c @@ -789,7 +789,7 @@ void mgco_print_CmSdpU8OrNil(CmSdpU8OrNil* p) switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE,"CmSdpU8OrNil: Value = %d \n", (NOTPRSNT != p->val.pres)?p->val.val:-1); } -void mgco_print_sdp_media_param(CmSdpMedPar *s) +void mgco_print_sdp_media_param(CmSdpMedPar *s, mg_termination_t* term, mgco_sdp_types_e sdp_type) { int i=0x00; switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "***** Media Parameter *********** \n"); @@ -832,6 +832,12 @@ void mgco_print_sdp_media_param(CmSdpMedPar *s) for(i=0;inum.val;i++){ mgco_print_CmSdpU8OrNil(r->fmts[i]); + + if(MG_RTP_AVP_PROFILE_A_LAW == r->fmts[i]->val.val){ + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, " MG_RTP_AVP_PROFILE_A_LAW: \n"); + }else if(MG_RTP_AVP_PROFILE_U_LAW == r->fmts[i]->val.val){ + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, " MG_RTP_AVP_PROFILE_U_LAW: \n"); + } } } break; @@ -1074,7 +1080,7 @@ void mgco_handle_sdp(CmSdpInfoSet *sdp, mg_termination_t* term, mgco_sdp_types_e break; } } - mgco_print_sdp_media_param(&f->par); + mgco_print_sdp_media_param(&f->par, term, sdp_type); } /*info */ diff --git a/src/mod/endpoints/mod_media_gateway/media_gateway_xml.c b/src/mod/endpoints/mod_media_gateway/media_gateway_xml.c index f30c1d955d..e3c3b8c3de 100644 --- a/src/mod/endpoints/mod_media_gateway/media_gateway_xml.c +++ b/src/mod/endpoints/mod_media_gateway/media_gateway_xml.c @@ -99,6 +99,8 @@ switch_status_t config_profile(megaco_profile_t *profile, switch_bool_t reload) term->pool = pool; term->type = MG_TERM_TDM; term->profile = profile; + term->mg_ctxt = NULL; + term->active_events = NULL; term->name = switch_core_sprintf(pool, "%s%d", prefix, j); term->u.tdm.channel = j; term->u.tdm.span_name = switch_core_strdup(pool, channel_prefix); diff --git a/src/mod/endpoints/mod_media_gateway/mod_media_gateway.h b/src/mod/endpoints/mod_media_gateway/mod_media_gateway.h index bf2fda7a05..e0022d8ecd 100644 --- a/src/mod/endpoints/mod_media_gateway/mod_media_gateway.h +++ b/src/mod/endpoints/mod_media_gateway/mod_media_gateway.h @@ -94,6 +94,14 @@ enum { } mg_termination_flags; +struct mg_context_s { + uint32_t context_id; + mg_termination_t *terminations[MG_CONTEXT_MAX_TERMS]; + megaco_profile_t *profile; + mg_context_t *next; + switch_memory_pool_t *pool; +}; + struct mg_termination_s { switch_memory_pool_t *pool; mg_termination_type_t type; @@ -104,6 +112,7 @@ struct mg_termination_s { MgMgcoReqEvtDesc *active_events; /* !< active megaco events */ mg_termination_t *next; /*!< List for physical terminations */ uint32_t flags; + mg_context_t* mg_ctxt; union { struct { @@ -131,13 +140,7 @@ struct mg_termination_s { }; -struct mg_context_s { - uint32_t context_id; - mg_termination_t *terminations[MG_CONTEXT_MAX_TERMS]; - megaco_profile_t *profile; - mg_context_t *next; - switch_memory_pool_t *pool; -}; + #define MG_CONTEXT_MODULO 16 #define MG_MAX_CONTEXTS 32768 From b1b2bee36268834ad0d7348ed098c6ad446b75fd Mon Sep 17 00:00:00 2001 From: root Date: Thu, 26 Jul 2012 15:02:25 -0400 Subject: [PATCH 28/29] fixing local sdp issue --- .../media_gateway_cmd_handler.c | 83 +++++++++++-------- .../mod_media_gateway/media_gateway_utils.c | 13 ++- .../mod_media_gateway/mod_media_gateway.h | 2 +- 3 files changed, 54 insertions(+), 44 deletions(-) diff --git a/src/mod/endpoints/mod_media_gateway/media_gateway_cmd_handler.c b/src/mod/endpoints/mod_media_gateway/media_gateway_cmd_handler.c index 57c8843aee..185f3fb5a9 100644 --- a/src/mod/endpoints/mod_media_gateway/media_gateway_cmd_handler.c +++ b/src/mod/endpoints/mod_media_gateway/media_gateway_cmd_handler.c @@ -498,6 +498,10 @@ switch_status_t handle_mg_add_cmd(megaco_profile_t* mg_profile, MgMgcoCommand *i /*MgMgcoStreamDesc* inc_strm_desc;*/ MgMgcoAudRetParm *desc; mg_context_t* mg_ctxt; + int mediaId; + MgMgcoLocalDesc *local = NULL; + CmSdpInfoSet *psdp = NULL; + /* TODO - Kapil dummy line , will need to add with proper code */ inc_med_desc = &cmd->dl.descs[0]->u.media; @@ -686,18 +690,25 @@ switch_status_t handle_mg_add_cmd(megaco_profile_t* mg_profile, MgMgcoCommand *i } /* copy media descriptor */ - desc = rsp.u.mgCmdRsp[0]->u.add.audit.parms[rsp.u.mgCmdRsp[0]->u.add.audit.num.val-1]; desc->type.pres = PRSNT_NODEF; desc->type.val = MGT_MEDIADESC; mgUtlCpyMgMgcoMediaDesc(&desc->u.media, inc_med_desc, &rsp.u.mgCmdRsp[0]->memCp); + /* see if we have received local descriptor */ + if((NOTPRSNT != desc->u.media.num.pres) && + (0 != desc->u.media.num.val)) + { + for(mediaId=0; mediaIdu.media.num.val; mediaId++) { + if(MGT_MEDIAPAR_LOCAL == desc->u.media.parms[mediaId]->type.val) { + local = &desc->u.media.parms[mediaId]->u.local; + } + } + } /* only for RTP */ if(is_rtp){ /* build local descriptors */ /*MgMgcoStreamDesc *stream;*/ - MgMgcoLocalDesc *local; - CmSdpInfoSet *psdp; char* ipAddress[4];// = "192.168.1.1"; char* dup = strdup((char*)term->u.rtp.local_addr); MgMgcoMediaDesc* media = &desc->u.media; @@ -705,45 +716,47 @@ switch_status_t handle_mg_add_cmd(megaco_profile_t* mg_profile, MgMgcoCommand *i switch_split(dup,'.',ipAddress); /* Most probably we need to add local descriptor */ + if(!local){ - /* allocating mem for local descriptor */ - if (mgUtlGrowList((void ***)&media->parms, sizeof(MgMgcoMediaPar), - &media->num, &rsp.u.mgCmdRsp[0]->memCp) != ROK) - { - switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR,"Grow List failed\n"); - return SWITCH_STATUS_FALSE; - } + /* allocating mem for local descriptor */ + if (mgUtlGrowList((void ***)&media->parms, sizeof(MgMgcoMediaPar), + &media->num, &rsp.u.mgCmdRsp[0]->memCp) != ROK) + { + switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, SWITCH_LOG_ERROR,"Grow List failed\n"); + return SWITCH_STATUS_FALSE; + } #if 0 - /* Kapil - NOT REQUIRED..keeping now just for ref..will delete asap */ - media->parms[media->num.val-1]->type.pres = PRSNT_NODEF; - /*media->parms[media->num.val-1]->type.val = MGT_MEDIAPAR_STRPAR;*/ + /* Kapil - NOT REQUIRED..keeping now just for ref..will delete asap */ + media->parms[media->num.val-1]->type.pres = PRSNT_NODEF; + /*media->parms[media->num.val-1]->type.val = MGT_MEDIAPAR_STRPAR;*/ - printf("media->num.val[%d]\n",media->num.val); + printf("media->num.val[%d]\n",media->num.val); - stream = &media->parms[media->num.val-1]->u.stream; - stream->pres.pres = PRSNT_NODEF; - stream->pres.val = 0x01; + stream = &media->parms[media->num.val-1]->u.stream; + stream->pres.pres = PRSNT_NODEF; + stream->pres.val = 0x01; #if 0 - if(inc_med_desc->num.pres && inc_med_desc->num.val){ - /* TODO - check stream descriptor type for all medias */ - inc_strm_desc = &inc_med_desc->parms[0]->u.stream; - memcpy(&stream->streamId, &inc_strm_desc->streamId, sizeof(MgMgcoStreamId)); + if(inc_med_desc->num.pres && inc_med_desc->num.val){ + /* TODO - check stream descriptor type for all medias */ + inc_strm_desc = &inc_med_desc->parms[0]->u.stream; + memcpy(&stream->streamId, &inc_strm_desc->streamId, sizeof(MgMgcoStreamId)); + } +#endif + + MG_INIT_TOKEN_VALUE(&(stream->streamId), 1); + + + stream->sl.pres.pres = PRSNT_NODEF; + stream->sl.pres.val = 0x01; + + local = &stream->sl.local; +#endif + media->parms[media->num.val-1]->type.pres = PRSNT_NODEF; + media->parms[media->num.val-1]->type.val = MGT_MEDIAPAR_LOCAL; + + local = &media->parms[media->num.val-1]->u.local; } -#endif - - MG_INIT_TOKEN_VALUE(&(stream->streamId), 1); - - - stream->sl.pres.pres = PRSNT_NODEF; - stream->sl.pres.val = 0x01; - - local = &stream->sl.local; -#endif - media->parms[media->num.val-1]->type.pres = PRSNT_NODEF; - media->parms[media->num.val-1]->type.val = MGT_MEDIAPAR_LOCAL; - - local = &media->parms[media->num.val-1]->u.local; local->pres.pres = PRSNT_NODEF; diff --git a/src/mod/endpoints/mod_media_gateway/media_gateway_utils.c b/src/mod/endpoints/mod_media_gateway/media_gateway_utils.c index 908b604118..e5d08c1d84 100644 --- a/src/mod/endpoints/mod_media_gateway/media_gateway_utils.c +++ b/src/mod/endpoints/mod_media_gateway/media_gateway_utils.c @@ -112,8 +112,6 @@ S16 mg_fill_mgco_termid ( MgMgcoTermId *termId, char* term_str, int term_len, C /*MG_GETMEM(termId->name.lcl.val, termId->name.lcl.len , memCp, ret);*/ ret = mg_stack_alloc_mem((Ptr*)&termId->name.lcl.val,term_len); - printf("termId->name.lcl.val[%p]\n",termId->name.lcl.val); - if( ret != ROK) RETVALUE(ret); @@ -121,7 +119,7 @@ S16 mg_fill_mgco_termid ( MgMgcoTermId *termId, char* term_str, int term_len, C strncpy((char*)(termId->name.lcl.val), term_str, termId->name.lcl.len); termId->name.lcl.val[termId->name.lcl.len] = '\0'; - printf("mg_fill_mgco_termid: name.lcl.val[%s], len[%d], term_str[%s], term_len[%d]\n",termId->name.lcl.val, termId->name.lcl.len, term_str,term_len); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE,"mg_fill_mgco_termid: name.lcl.val[%s], len[%d], term_str[%s], term_len[%d]\n",termId->name.lcl.val, termId->name.lcl.len, term_str,term_len); } @@ -742,8 +740,8 @@ void mgco_print_sdp_attr_set(CmSdpAttrSet *s) void mgco_handle_sdp_c_line(CmSdpConn *s, mg_termination_t* term, mgco_sdp_types_e sdp_type) { - char ipadd[12]; - memset(ipadd, 0, 12); + char ipadd[32]; + memset(ipadd, 0, sizeof(ipadd)); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "********** SDP connection line ****** \n"); @@ -770,11 +768,10 @@ void mgco_handle_sdp_c_line(CmSdpConn *s, mg_termination_t* term, mgco_sdp_types s->u.ip4.u.uniIp.b[1].val, s->u.ip4.u.uniIp.b[2].val, s->u.ip4.u.uniIp.b[3].val); - printf("Remote ip = %s \n", ipadd); /* update remote ip */ if(MG_TERM_RTP == term->type){ - term->u.rtp.remote_addr = strdup(ipadd); - printf("Update remote ip to [%s]\n", term->u.rtp.remote_addr); + term->u.rtp.remote_addr = switch_core_strdup(term->pool,ipadd); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE,"Update remote ip to [%s]\n", term->u.rtp.remote_addr); } } } diff --git a/src/mod/endpoints/mod_media_gateway/mod_media_gateway.h b/src/mod/endpoints/mod_media_gateway/mod_media_gateway.h index e0022d8ecd..af53052fbb 100644 --- a/src/mod/endpoints/mod_media_gateway/mod_media_gateway.h +++ b/src/mod/endpoints/mod_media_gateway/mod_media_gateway.h @@ -111,8 +111,8 @@ struct mg_termination_s { megaco_profile_t *profile; /*!< Parent MG profile */ MgMgcoReqEvtDesc *active_events; /* !< active megaco events */ mg_termination_t *next; /*!< List for physical terminations */ - uint32_t flags; mg_context_t* mg_ctxt; + uint32_t flags; union { struct { From 258900818a5fd7f3eb9fed91bf8ebd2659d5471a Mon Sep 17 00:00:00 2001 From: David Yat Sin Date: Thu, 26 Jul 2012 16:43:18 -0400 Subject: [PATCH 29/29] freetdm: Added thread to service events when there is no signalling module on a span --- libs/freetdm/src/ftdm_io.c | 48 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/libs/freetdm/src/ftdm_io.c b/libs/freetdm/src/ftdm_io.c index b8b9cff527..758827c9ed 100644 --- a/libs/freetdm/src/ftdm_io.c +++ b/libs/freetdm/src/ftdm_io.c @@ -5618,16 +5618,61 @@ FT_DECLARE(ftdm_status_t) ftdm_configure_span_signaling(ftdm_span_t *span, const return status; } +static void *ftdm_span_service_events(ftdm_thread_t *me, void *obj) +{ + int i; + unsigned waitms; + ftdm_event_t *event; + ftdm_status_t status = FTDM_SUCCESS; + ftdm_span_t *span = (ftdm_span_t*) obj; + short *poll_events = ftdm_malloc(sizeof(short) * span->chan_count); + + memset(poll_events, 0, sizeof(short) * span->chan_count); + + for(i = 1; i <= span->chan_count; i++) { + poll_events[i] |= FTDM_EVENTS; + } + + while (ftdm_running() && !(ftdm_test_flag(span, FTDM_SPAN_STOP_THREAD))) { + waitms = 1000; + status = ftdm_span_poll_event(span, waitms, poll_events); + switch (status) { + case FTDM_FAIL: + ftdm_log(FTDM_LOG_CRIT, "%s:Failed to poll span for events\n", span->name); + break; + case FTDM_TIMEOUT: + break; + case FTDM_SUCCESS: + /* Check if there are any channels that have events available */ + while (ftdm_span_next_event(span, &event) == FTDM_SUCCESS); + break; + default: + ftdm_log(FTDM_LOG_CRIT, "%s:Unhandled IO event\n", span->name); + } + } + return NULL; +} + FT_DECLARE(ftdm_status_t) ftdm_span_start(ftdm_span_t *span) { ftdm_status_t status = FTDM_FAIL; - ftdm_mutex_lock(span->mutex); if (ftdm_test_flag(span, FTDM_SPAN_STARTED)) { status = FTDM_EINVAL; goto done; } + if (span->signal_type == FTDM_SIGTYPE_NONE) { + /* If there is no signalling component, start a thread to poll events */ + status = ftdm_thread_create_detached(ftdm_span_service_events, span); + if (status != FTDM_SUCCESS) { + ftdm_log(FTDM_LOG_CRIT,"Failed to start span event monitor thread!\n"); + goto done; + } + + status = ftdm_report_initial_channels_alarms(span); + goto done; + } if (!span->start) { status = FTDM_ENOSYS; @@ -5643,7 +5688,6 @@ FT_DECLARE(ftdm_status_t) ftdm_span_start(ftdm_span_t *span) if (status == FTDM_SUCCESS) { ftdm_set_flag_locked(span, FTDM_SPAN_STARTED); } - done: ftdm_mutex_unlock(span->mutex); return status;