X-Git-Url: http://git.eversberg.eu/gitweb.cgi?p=lcr.git;a=blobdiff_plain;f=interface.c;h=292c9aaf22f0108b26348911146d501a6cf939c7;hp=60e058f99617b231a2f0b96629381506ea15c46a;hb=034d3a91404addedc1c7a3494862c79532b0b878;hpb=5463e1b62a39ce417b610584e3d34a8bc30ac15e diff --git a/interface.c b/interface.c index 60e058f..292c9aa 100644 --- a/interface.c +++ b/interface.c @@ -15,6 +15,7 @@ struct interface *interface_first = NULL; /* first interface is current list */ struct interface *interface_newlist = NULL; /* first interface in new list */ +#ifdef WITH_MISDN /* set default out_channel */ void default_out_channel(struct interface_port *ifport) { @@ -22,7 +23,7 @@ void default_out_channel(struct interface_port *ifport) selchannel = (struct select_channel *)MALLOC(sizeof(struct select_channel)); memuse++; - + if (ifport->mISDNport->ntmode) selchannel->channel = CHANNEL_FREE; else @@ -53,6 +54,7 @@ void default_in_channel(struct interface_port *ifport) ifport->in_channel = selchannel; } +#endif /* parse string for a positive number */ @@ -278,6 +280,10 @@ static int inter_port(struct interface *interface, char *filename, int line, cha } static int inter_portnum(struct interface *interface, char *filename, int line, char *parameter, char *value) { +#ifndef WITH_MISDN + SPRINT(interface_error, "Error in %s (line %d): mISDN support is not compiled in.\n", filename, line); + return(-1); +#else struct interface_port *ifport, **ifportp; struct interface *searchif; int val; @@ -312,11 +318,15 @@ static int inter_portnum(struct interface *interface, char *filename, int line, ifportp = &((*ifportp)->next); *ifportp = ifport; return(0); +#endif } static int inter_portname(struct interface *interface, char *filename, int line, char *parameter, char *value) { +#ifndef WITH_MISDN + SPRINT(interface_error, "Error in %s (line %d): mISDN support is not compiled in.\n", filename, line); + return(-1); +#else struct interface_port *ifport, **ifportp; - struct interface *searchif; /* goto end of chain */ ifport = interface->ifport; @@ -325,22 +335,6 @@ static int inter_portname(struct interface *interface, char *filename, int line, ifport = ifport->next; } - /* check for port already assigned, but not for shared loop interface */ - searchif = interface_newlist; - if (!!strcmp(value, options.loopback_lcr)) - { - while(searchif) { - ifport = searchif->ifport; - while(ifport) { - if (!strcasecmp(ifport->portname, value)) { - SPRINT(interface_error, "Error in %s (line %d): port '%s' already used above.\n", filename, line, value); - return(-1); - } - ifport = ifport->next; - } - searchif = searchif->next; - } - } /* alloc port substructure */ ifport = (struct interface_port *)MALLOC(sizeof(struct interface_port)); memuse++; @@ -354,6 +348,7 @@ static int inter_portname(struct interface *interface, char *filename, int line, ifportp = &((*ifportp)->next); *ifportp = ifport; return(0); +#endif } static int inter_l1hold(struct interface *interface, char *filename, int line, char *parameter, char *value) { @@ -756,6 +751,22 @@ static int inter_nodtmf(struct interface *interface, char *filename, int line, c ifport->nodtmf = 1; return(0); } +static int inter_dtmf_threshold(struct interface *interface, char *filename, int line, char *parameter, char *value) +{ + struct interface_port *ifport; + + /* port in chain ? */ + if (!interface->ifport) { + SPRINT(interface_error, "Error in %s (line %d): parameter '%s' expects previous 'port' definition.\n", filename, line, parameter); + return(-1); + } + /* goto end of chain */ + ifport = interface->ifport; + while(ifport->next) + ifport = ifport->next; + ifport->dtmf_threshold = atoi(value); + return(0); +} static int inter_filter(struct interface *interface, char *filename, int line, char *parameter, char *value) { char *p, *q; @@ -911,6 +922,17 @@ static int inter_gsm_bs(struct interface *interface, char *filename, int line, c return(0); #endif } +static int inter_gsm_bs_hr(struct interface *interface, char *filename, int line, char *parameter, char *value) +{ +#ifndef WITH_GSM_BS + SPRINT(interface_error, "Error in %s (line %d): GSM BS side not compiled in.\n", filename, line); + return(-1); +#else + interface->gsm_bs_hr = 1; + + return(0); +#endif +} static int inter_gsm_ms(struct interface *interface, char *filename, int line, char *parameter, char *value) { #ifndef WITH_GSM_MS @@ -931,7 +953,7 @@ static int inter_gsm_ms(struct interface *interface, char *filename, int line, c /* check if name is used multiple times */ searchif = interface_newlist; while(searchif) { - if (!strcmp(searchif->gsm_ms_name, interface->gsm_ms_name)) { + if (searchif != interface && !strcmp(searchif->gsm_ms_name, interface->gsm_ms_name)) { SPRINT(interface_error, "Error in %s (line %d): mobile '%s' already uses the given MS name '%s', choose a different one.\n", filename, line, interface->gsm_ms_name, searchif->gsm_ms_name); return(-1); } @@ -961,18 +983,67 @@ static int inter_sip(struct interface *interface, char *filename, int line, char SPRINT(interface_error, "Error in %s (line %d): Missing SIP remote IP.\n", filename, line); return(-1); } - SCPY(interface->sip_local_ip, value); - SCPY(interface->sip_remote_ip, p); + SCPY(interface->sip_local_peer, value); + SCPY(interface->sip_remote_peer, p); return(0); #endif } static int inter_rtp_bridge(struct interface *interface, char *filename, int line, char *parameter, char *value) { + int supported = 0; + +#ifdef WITH_GSM_BS + if (interface->gsm_bs) + supported = 1; +#endif +#ifdef WITH_SIP + if (interface->sip) + supported = 1; +#endif + if (!supported) { + SPRINT(interface_error, "Error in %s (line %d): Interface does not support RTP\n", filename, line); + return(-1); + } + + if (interface->app != EAPP_TYPE_BRIDGE) { + SPRINT(interface_error, "Error in %s (line %d): '%s' requires previous 'bridge' parameter.\n", filename, line, parameter); + return(-1); + } + interface->rtp_bridge = 1; return(0); } +#if 0 +static int inter_rtp_payload(struct interface *interface, char *filename, int line, char *parameter, char *value) +{ +#ifndef WITH_GSM_BS + SPRINT(interface_error, "Error in %s (line %d): GSM BS side not compiled in.\n", filename, line); + return(-1); +#else + if (!interface->gsm_bs) { + SPRINT(interface_error, "Error in %s (line %d): This parameter only works for GSM BS side interface\n", filename, line); + return(-1); + } + if (!interface->rtp_bridge) { + SPRINT(interface_error, "Error in %s (line %d): This parameter only works here, if RTP bridging is enabled\n", filename, line); + return(-1); + } + if (!value[0]) { + SPRINT(interface_error, "Error in %s (line %d): parameter '%s' expects one payload type\n", filename, line, parameter); + return(-1); + } + if (interface->gsm_bs_payloads == sizeof(interface->gsm_bs_payload_types)) { + SPRINT(interface_error, "Error in %s (line %d): Too many payload types defined\n", filename, line); + return(-1); + } + interface->gsm_bs_payload_types[interface->gsm_bs_payloads++] = atoi(value); + + return(0); +#endif +} +#endif static int inter_nonotify(struct interface *interface, char *filename, int line, char *parameter, char *value) { struct interface_port *ifport; @@ -1026,11 +1097,17 @@ static int inter_ss5(struct interface *interface, char *filename, int line, char if (!strcasecmp(element, "delay")) ifport->ss5 |= SS5_FEATURE_DELAY; else - if (!strcasecmp(element, "starrelease")) - ifport->ss5 |= SS5_FEATURE_STAR_RELEASE; + if (!strcasecmp(element, "release")) + ifport->ss5 |= SS5_FEATURE_RELEASE; + else + if (!strcasecmp(element, "mute-rx")) + ifport->ss5 |= SS5_FEATURE_MUTE_RX; else - if (!strcasecmp(element, "suppress")) - ifport->ss5 |= SS5_FEATURE_SUPPRESS; + if (!strcasecmp(element, "mute-tx")) + ifport->ss5 |= SS5_FEATURE_MUTE_TX; + else + if (!strcasecmp(element, "quality")) + ifport->ss5 |= SS5_FEATURE_QUALITY; else { SPRINT(interface_error, "Error in %s (line %d): parameter '%s' does not allow value element '%s'.\n", filename, line, parameter, element); return(-1); @@ -1041,7 +1118,6 @@ static int inter_ss5(struct interface *interface, char *filename, int line, char #endif static int inter_remote(struct interface *interface, char *filename, int line, char *parameter, char *value) { - struct interface_port *ifport; struct interface *searchif; if (!value[0]) { @@ -1050,38 +1126,97 @@ static int inter_remote(struct interface *interface, char *filename, int line, c } searchif = interface_newlist; while(searchif) { - ifport = searchif->ifport; - while(ifport) { - if (ifport->remote && !strcmp(ifport->remote_app, value)) { - SPRINT(interface_error, "Error in %s (line %d): port '%s' already uses remote application '%s'.\n", filename, line, ifport->portname, value); - return(-1); - } - ifport = ifport->next; + if (interface->remote && !strcmp(interface->remote_app, value)) { + SPRINT(interface_error, "Error in %s (line %d): interface '%s' already uses remote application '%s'.\n", filename, line, interface->name, value); + return(-1); } searchif = searchif->next; } - /* set portname */ - if (inter_portname(interface, filename, line, (char *)"portname", options.loopback_lcr)) + /* goto end of chain again to set application name */ + interface->remote = 1; + SCPY(interface->remote_app, value); + + return(0); +} +static int inter_context(struct interface *interface, char *filename, int line, char *parameter, char *value) +{ + if (!value[0]) { + SPRINT(interface_error, "Error in %s (line %d): parameter '%s' expects application context as value.\n", filename, line, parameter); return(-1); + } + SCPY(interface->remote_context, value); - /* goto end of chain again to set application name */ + return(0); +} +static int inter_pots_flash(struct interface *interface, char *filename, int line, char *parameter, char *value) +{ + struct interface_port *ifport; + + /* port in chain ? */ + if (!interface->ifport) { + SPRINT(interface_error, "Error in %s (line %d): parameter '%s' expects previous 'port' definition.\n", filename, line, parameter); + return(-1); + } + /* goto end of chain */ ifport = interface->ifport; while(ifport->next) ifport = ifport->next; - ifport->remote = 1; - SCPY(ifport->remote_app, value); + ifport->pots_flash = 1; + return(0); +} +static int inter_pots_ring(struct interface *interface, char *filename, int line, char *parameter, char *value) +{ + struct interface_port *ifport; + /* port in chain ? */ + if (!interface->ifport) { + SPRINT(interface_error, "Error in %s (line %d): parameter '%s' expects previous 'port' definition.\n", filename, line, parameter); + return(-1); + } + /* goto end of chain */ + ifport = interface->ifport; + while(ifport->next) + ifport = ifport->next; + + ifport->pots_ring = 1; return(0); } +static int inter_pots_transfer(struct interface *interface, char *filename, int line, char *parameter, char *value) +{ + struct interface_port *ifport; + + /* port in chain ? */ + if (!interface->ifport) { + SPRINT(interface_error, "Error in %s (line %d): parameter '%s' expects previous 'port' definition.\n", filename, line, parameter); + return(-1); + } + /* goto end of chain */ + ifport = interface->ifport; + while(ifport->next) + ifport = ifport->next; + ifport->pots_transfer = 1; + return(0); +} static int inter_shutdown(struct interface *interface, char *filename, int line, char *parameter, char *value) { interface->shutdown = 1; return(0); } +static int inter_bridge(struct interface *interface, char *filename, int line, char *parameter, char *value) +{ + if (!value || !value[0]) { + SPRINT(interface_error, "Error in %s (line %d): Missing destination interface name.\n", filename, line); + return(-1); + } + interface->app = EAPP_TYPE_BRIDGE; + SCPY(interface->bridge_if, value); + + return(0); +} /* @@ -1198,6 +1333,10 @@ struct interface_param interface_param[] = { "Disables DTMF detection for this interface.\n" "This parameter must follow a 'port' parameter."}, + {"dtmf-threshold", &inter_dtmf_threshold, "", + "Set threshold value for minimum DTMF tone level.\n" + "This parameter must follow a 'port' parameter."}, + {"filter", &inter_filter, " ", "Adds/appends a filter. Filters are ordered in transmit direction.\n" "gain - Changes volume (-8 .. 8)\n" @@ -1215,6 +1354,8 @@ struct interface_param interface_param[] = { ""}, {"gsm-bs", &inter_gsm_bs, "", "Sets up GSM base station interface for using OpenBSC."}, + {"hr", &inter_gsm_bs_hr, "", + "Enable and prefer half rate for mobile terminating calls."}, {"gsm-ms", &inter_gsm_ms, "", "Sets up GSM mobile station interface for using Osmocom-BB.\n" "The name of the MS folows the interface name.\n" @@ -1224,12 +1365,24 @@ struct interface_param interface_param[] = { "Sets up SIP interface that represents one SIP endpoint.\n" "Give SIP configuration file."}, {"rtp-bridge", &inter_rtp_bridge, "", - "Sets up SIP interface that represents one SIP endpoint.\n" - "Give SIP configuration file."}, + "Enables RTP bridging directly from this interface.\n" + "This only works if both bridged interfaces use RTP, e.g. between gsm-bs and sip.\n" + "This parameter must follow a 'bridge' parameter.\n"}, +#if 0 + not needed, since ms defines what is supports and remote (sip) tells what is selected + {"rtp-payload", &inter_rtp_payload, "", + "Define RTP payload to use. Only valid in conjuntion with gsm-bs!\n" + "If multiple payloads are defined, the first has highest priority.\n" + "If none are defined, GSM fullrate V1 (type 3) is assumed.\n"}, +#endif {"nonotify", &inter_nonotify, "", "Prevents sending notify messages to this interface. A call placed on hold will\n" "Not affect the remote end (phone or telcom switch).\n" "This parameter must follow a 'port' parameter."}, + {"bridge", &inter_bridge, "", + "Define bridge application for this interface. All calls received on this\n" + "interface will be directly bridged to the given destination interface.\n" + "There will be no PBX application, nor routing."}, #ifdef WITH_SS5 {"ccitt5", &inter_ss5, "[ [feature ...]]", @@ -1243,13 +1396,31 @@ struct interface_param interface_param[] = { " bell - Allow releasing and pulse-dialing via 2600 Hz like old Bell systems.\n" " pulsedialing - Use pulse dialing on outgoing exchange. (takes long!)\n" " delay - Use on incomming exchange, to make you feel a delay when blueboxing.\n" - " starrelease - Pulse dialing a star (11 pulses per digit) clears current call.\n" - " suppress - Suppress received tones, as they will be recognized."}, + " release - Pulse dialing a star (11 pulses per digit) clears current call.\n" + " mutes-rx - Mute received 2600 and 2400 Hz tones when detected. (more realistic)\n" + " mutes-tx - Mute received 2600 and 2400 Hz tones while transmitting reply tone. (more hackable)"}, #endif {"remote", &inter_remote, "", "Sets up an interface that communicates with the remote application.\n" "Use \"asterisk\" to use chan_lcr as remote application."}, + {"context", &inter_context, "", + "Give context for calls to application."}, + + {"pots-flash", &inter_pots_flash, "", + "Allow flash button to hold an active call and setup a new call.\n" + "Ihis parameter only appies to POTS type of interfaces\n" + "This parameter must follow a 'port' parameter.\n"}, + {"pots-ring-after-hangup", &inter_pots_ring, "", + "Allow ringing of last hold call after hangup. Other calls on hold will not be\n" + "released.\n" + "Ihis parameter only appies to POTS type of interfaces\n" + "This parameter must follow a 'port' parameter.\n"}, + {"pots-transfer-after-hangup", &inter_pots_transfer, "", + "If two calls on hold, both are connected after hangup.\n" + "If one call is on hold and another one alerting, call on hold is tranfered.\n" + "Ihis parameter only appies to POTS type of interfaces\n" + "This parameter must follow a 'port' parameter.\n"}, {"shutdown", &inter_shutdown, "", "Interface will not be loaded when processing interface.conf"}, @@ -1464,10 +1635,11 @@ void free_interfaces(struct interface *interface) } } +#ifdef WITH_MISDN /* * defaults of ports if not specified by config */ -static void set_defaults(struct interface_port *ifport) +static void set_mISDN_defaults(struct interface_port *ifport) { /* default channel selection list */ if (!ifport->out_channel) @@ -1493,6 +1665,7 @@ static void set_defaults(struct interface_port *ifport) else ifport->mISDNport->locally = 0; } +#endif /* @@ -1502,18 +1675,19 @@ static void set_defaults(struct interface_port *ifport) */ void relink_interfaces(void) { +#ifdef WITH_MISDN struct mISDNport *mISDNport; - struct interface *interface, *temp; struct interface_port *ifport; - int found; +#endif + struct interface *interface, *temp, *found; interface = interface_first; while(interface) { - found = 0; + found = NULL; temp = interface_newlist; while(temp) { if (!strcmp(temp->name, interface->name)) - found = 1; + found = temp; temp = temp->next; } if (!found) { @@ -1529,17 +1703,26 @@ void relink_interfaces(void) if (interface->sip) sip_exit_inst(interface); #endif + } else { +#ifdef WITH_SIP + if (interface->sip) { + /* move sip instance, if we keep interface */ + found->sip_inst = interface->sip_inst; + interface->sip_inst = NULL; + } +#endif + ; } interface = interface->next; } interface = interface_newlist; while(interface) { - found = 0; + found = NULL; temp = interface_first; while(temp) { if (!strcmp(temp->name, interface->name)) - found = 1; + found = temp; temp = temp->next; } if (!found) { @@ -1559,6 +1742,7 @@ void relink_interfaces(void) interface = interface->next; } +#ifdef WITH_MISDN /* unlink all mISDNports */ mISDNport = mISDNport_first; while(mISDNport) { @@ -1579,7 +1763,7 @@ void relink_interfaces(void) PDEBUG(DEBUG_ISDN, "Port %d:%s relinking!\n", ifport->portnum, ifport->portname); ifport->mISDNport = mISDNport; mISDNport->ifport = ifport; - set_defaults(ifport); + set_mISDN_defaults(ifport); } mISDNport = mISDNport->next; } @@ -1608,7 +1792,7 @@ void relink_interfaces(void) while(ifport) { if (!ifport->mISDNport) { if (!interface->shutdown) { - load_port(ifport); + load_mISDN_port(ifport); } else { ifport->block = 2; } @@ -1617,14 +1801,15 @@ void relink_interfaces(void) } interface = interface->next; } - +#endif } +#ifdef WITH_MISDN /* * load port */ -void load_port(struct interface_port *ifport) +void load_mISDN_port(struct interface_port *ifport) { struct mISDNport *mISDNport; @@ -1638,13 +1823,14 @@ void load_port(struct interface_port *ifport) ifport->portnum = mISDNport->portnum; SCPY(ifport->portname, mISDNport->name); /* set defaults */ - set_defaults(ifport); + set_mISDN_defaults(ifport); /* load static port instances */ mISDNport_static(mISDNport); } else { ifport->block = 2; /* not available */ } } +#endif /* * give summary of interface syntax @@ -1686,11 +1872,7 @@ void do_screen(int out, char *id, int idsize, int *type, int *present, const cha char suffix[64]; struct interface *interface = interface_first; - while (interface) { - if (!strcmp(interface->name, interface_name)) - break; - interface = interface->next; - } + interface = getinterfacebyname(interface_name); if (!interface) return; @@ -1817,3 +1999,16 @@ void do_screen(int out, char *id, int idsize, int *type, int *present, const cha } } +struct interface *getinterfacebyname(const char *name) +{ + struct interface *interface = interface_first; + + while (interface) { + if (!strcmp(interface->name, name)) + return interface; + interface = interface->next; + } + + return NULL; +} +