X-Git-Url: http://git.eversberg.eu/gitweb.cgi?p=lcr.git;a=blobdiff_plain;f=interface.c;h=02e15317329da1040be4254bf1f030c827103c03;hp=8a367d63388952d707f430d7ea424a5e1551d9f1;hb=refs%2Fheads%2Fbackup2;hpb=68eab068230bf7595dc866732444fedb3c6bf394 diff --git a/interface.c b/interface.c index 8a367d6..02e1531 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 @@ -31,8 +32,7 @@ void default_out_channel(struct interface_port *ifport) ifport->out_channel = selchannel; /* additional channel selection for multipoint NT ports */ - if (!ifport->mISDNport->ptp && ifport->mISDNport->ntmode) - { + if (!ifport->mISDNport->ptp && ifport->mISDNport->ntmode) { selchannelp = &(selchannel->next); selchannel = (struct select_channel *)MALLOC(sizeof(struct select_channel)); memuse++; @@ -54,6 +54,7 @@ void default_in_channel(struct interface_port *ifport) ifport->in_channel = selchannel; } +#endif /* parse string for a positive number */ @@ -77,10 +78,8 @@ static int get_number(char *value) * and return pointer to next element in buffer */ static char *get_seperated(char *buffer) { - while(*buffer) - { - if (*buffer==',' || *buffer<=32) /* seperate */ - { + while(*buffer) { + if (*buffer==',' || *buffer<=32) { /* seperate */ *buffer++ = '\0'; while((*buffer>'\0' && *buffer<=32) || *buffer==',') buffer++; @@ -99,8 +98,7 @@ static int inter_block(struct interface *interface, char *filename, int line, ch struct interface_port *ifport; /* port in chain ? */ - if (!interface->ifport) - { + if (!interface->ifport) { SPRINT(interface_error, "Error in %s (line %d): parameter '%s' expects previous 'port' definition.\n", filename, line, parameter); return(-1); } @@ -109,8 +107,7 @@ static int inter_block(struct interface *interface, char *filename, int line, ch while(ifport->next) ifport = ifport->next; /* add value */ - if (value[0]) - { + if (value[0]) { SPRINT(interface_error, "Error in %s (line %d): parameter '%s' expects no value.\n", filename, line, parameter); return(-1); } @@ -119,26 +116,40 @@ static int inter_block(struct interface *interface, char *filename, int line, ch } static int inter_extension(struct interface *interface, char *filename, int line, char *parameter, char *value) { - if (value[0]) - { + if (interface->external) { + SPRINT(interface_error, "Error in %s (line %d): parameter '%s' not allowed, because interface is external interface.\n", filename, line, parameter); + return(-1); + } + if (value[0]) { SPRINT(interface_error, "Error in %s (line %d): parameter '%s' expects no value.\n", filename, line, parameter); return(-1); } interface->extension = 1; return(0); } +static int inter_extern(struct interface *interface, char *filename, int line, char *parameter, char *value) +{ + if (interface->extension) { + SPRINT(interface_error, "Error in %s (line %d): parameter '%s' not allowed, because interface is an extension.\n", filename, line, parameter); + return(-1); + } + if (value[0]) { + SPRINT(interface_error, "Error in %s (line %d): parameter '%s' expects no value.\n", filename, line, parameter); + return(-1); + } + interface->external = 1; + return(0); +} static int inter_ptp(struct interface *interface, char *filename, int line, char *parameter, char *value) { struct interface_port *ifport; /* port in chain ? */ - if (!interface->ifport) - { + if (!interface->ifport) { SPRINT(interface_error, "Error in %s (line %d): parameter '%s' expects previous 'port' definition.\n", filename, line, parameter); return(-1); } - if (interface->ifport->ptmp) - { + if (interface->ifport->ptmp) { SPRINT(interface_error, "Error in %s (line %d): parameter '%s' previously ptmp was given.\n", filename, line, parameter); return(-1); } @@ -147,8 +158,7 @@ static int inter_ptp(struct interface *interface, char *filename, int line, char while(ifport->next) ifport = ifport->next; /* add value */ - if (value[0]) - { + if (value[0]) { SPRINT(interface_error, "Error in %s (line %d): parameter '%s' expects no value.\n", filename, line, parameter); return(-1); } @@ -161,13 +171,11 @@ static int inter_ptmp(struct interface *interface, char *filename, int line, cha struct interface_port *ifport; /* port in chain ? */ - if (!interface->ifport) - { + if (!interface->ifport) { SPRINT(interface_error, "Error in %s (line %d): parameter '%s' expects previous 'port' definition.\n", filename, line, parameter); return(-1); } - if (interface->ifport->ptp) - { + if (interface->ifport->ptp) { SPRINT(interface_error, "Error in %s (line %d): parameter '%s' previously ptp was given.\n", filename, line, parameter); return(-1); } @@ -176,8 +184,7 @@ static int inter_ptmp(struct interface *interface, char *filename, int line, cha while(ifport->next) ifport = ifport->next; /* add value */ - if (value[0]) - { + if (value[0]) { SPRINT(interface_error, "Error in %s (line %d): parameter '%s' expects no value.\n", filename, line, parameter); return(-1); } @@ -190,8 +197,7 @@ static int inter_nt(struct interface *interface, char *filename, int line, char struct interface_port *ifport; /* port in chain ? */ - if (!interface->ifport) - { + if (!interface->ifport) { SPRINT(interface_error, "Error in %s (line %d): parameter '%s' expects previous 'port' definition.\n", filename, line, parameter); return(-1); } @@ -200,8 +206,7 @@ static int inter_nt(struct interface *interface, char *filename, int line, char while(ifport->next) ifport = ifport->next; /* add value */ - if (value[0]) - { + if (value[0]) { SPRINT(interface_error, "Error in %s (line %d): parameter '%s' expects no value.\n", filename, line, parameter); return(-1); } @@ -213,8 +218,7 @@ static int inter_tespecial(struct interface *interface, char *filename, int line struct interface_port *ifport; /* port in chain ? */ - if (!interface->ifport) - { + if (!interface->ifport) { SPRINT(interface_error, "Error in %s (line %d): parameter '%s' expects previous 'port' definition.\n", filename, line, parameter); return(-1); } @@ -223,8 +227,7 @@ static int inter_tespecial(struct interface *interface, char *filename, int line while(ifport->next) ifport = ifport->next; /* add value */ - if (value[0]) - { + if (value[0]) { SPRINT(interface_error, "Error in %s (line %d): parameter '%s' expects no value.\n", filename, line, parameter); return(-1); } @@ -233,15 +236,12 @@ static int inter_tespecial(struct interface *interface, char *filename, int line } static int inter_tones(struct interface *interface, char *filename, int line, char *parameter, char *value) { - if (!strcasecmp(value, "yes")) - { + if (!strcasecmp(value, "yes")) { interface->is_tones = IS_YES; } else - if (!strcasecmp(value, "no")) - { + if (!strcasecmp(value, "no")) { interface->is_tones = IS_NO; - } else - { + } else { SPRINT(interface_error, "Error in %s (line %d): parameter '%s' expects value 'yes' or 'no'.\n", filename, line, parameter); return(-1); } @@ -249,15 +249,12 @@ static int inter_tones(struct interface *interface, char *filename, int line, ch } static int inter_earlyb(struct interface *interface, char *filename, int line, char *parameter, char *value) { - if (!strcasecmp(value, "yes")) - { + if (!strcasecmp(value, "yes")) { interface->is_earlyb = IS_YES; } else - if (!strcasecmp(value, "no")) - { + if (!strcasecmp(value, "no")) { interface->is_earlyb = IS_NO; - } else - { + } else { SPRINT(interface_error, "Error in %s (line %d): parameter '%s' expects value 'yes' or 'no'.\n", filename, line, parameter); return(-1); } @@ -265,15 +262,12 @@ static int inter_earlyb(struct interface *interface, char *filename, int line, c } static int inter_hunt(struct interface *interface, char *filename, int line, char *parameter, char *value) { - if (!strcasecmp(value, "linear")) - { + if (!strcasecmp(value, "linear")) { interface->hunt = HUNT_LINEAR; } else - if (!strcasecmp(value, "roundrobin")) - { + if (!strcasecmp(value, "roundrobin")) { interface->hunt = HUNT_ROUNDROBIN; - } else - { + } else { SPRINT(interface_error, "Error in %s (line %d): parameter '%s' expects value 'linear' or 'roundrobin'.\n", filename, line, parameter); return(-1); } @@ -286,25 +280,25 @@ 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; val = get_number(value); - if (val == -1) - { + if (val == -1) { SPRINT(interface_error, "Error in %s (line %d): parameter '%s' expects one numeric value.\n", filename, line, parameter); return(-1); } /* check for port already assigned */ searchif = interface_newlist; - while(searchif) - { + while(searchif) { ifport = searchif->ifport; - while(ifport) - { - if (ifport->portnum == val) - { + while(ifport) { + if (ifport->portnum == val) { SPRINT(interface_error, "Error in %s (line %d): port '%d' already used above.\n", filename, line, val); return(-1); } @@ -324,28 +318,23 @@ 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; - /* check for port already assigned */ - searchif = interface_newlist; - 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); - } + /* goto end of chain */ + ifport = interface->ifport; + if (ifport) { + while(ifport->next) ifport = ifport->next; - } - searchif = searchif->next; } + /* alloc port substructure */ ifport = (struct interface_port *)MALLOC(sizeof(struct interface_port)); memuse++; @@ -359,14 +348,38 @@ 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) +{ + 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; + if (!strcmp(value, "yes")) { + ifport->l1hold = 1; + } else + if (!strcmp(value, "no")) { + ifport->l1hold = 0; + } else { + SPRINT(interface_error, "Error in %s (line %d): parameter '%s' expecting parameter 'yes' or 'no'.\n", filename, line, parameter); + return(-1); + } + return(0); } static int inter_l2hold(struct interface *interface, char *filename, int line, char *parameter, char *value) { struct interface_port *ifport; /* port in chain ? */ - if (!interface->ifport) - { + if (!interface->ifport) { SPRINT(interface_error, "Error in %s (line %d): parameter '%s' expects previous 'port' definition.\n", filename, line, parameter); return(-1); } @@ -374,15 +387,12 @@ static int inter_l2hold(struct interface *interface, char *filename, int line, c ifport = interface->ifport; while(ifport->next) ifport = ifport->next; - if (!strcmp(value, "yes")) - { + if (!strcmp(value, "yes")) { ifport->l2hold = 1; } else - if (!strcmp(value, "no")) - { + if (!strcmp(value, "no")) { ifport->l2hold = -1; - } else - { + } else { SPRINT(interface_error, "Error in %s (line %d): parameter '%s' expecting parameter 'yes' or 'no'.\n", filename, line, parameter); return(-1); } @@ -396,8 +406,7 @@ static int inter_channel_out(struct interface *interface, char *filename, int li char *p, *el; /* port in chain ? */ - if (!interface->ifport) - { + if (!interface->ifport) { SPRINT(interface_error, "Error in %s (line %d): parameter '%s' expects previous 'port' definition.\n", filename, line, parameter); return(-1); } @@ -406,44 +415,35 @@ static int inter_channel_out(struct interface *interface, char *filename, int li while(ifport->next) ifport = ifport->next; p = value; - while(*p) - { + while(*p) { el = p; p = get_seperated(p); - if (!strcasecmp(el, "force")) - { + if (!strcasecmp(el, "force")) { ifport->channel_force = 1; - if (ifport->out_channel) - { + if (ifport->out_channel) { SPRINT(interface_error, "Error in %s (line %d): value 'force' may only appear as first element in list.\n", filename, line); return(-1); } } else - if (!strcasecmp(el, "any")) - { + if (!strcasecmp(el, "any")) { val = CHANNEL_ANY; goto selchannel; } else - if (!strcasecmp(el, "free")) - { + if (!strcasecmp(el, "free")) { val = CHANNEL_FREE; goto selchannel; } else - if (!strcasecmp(el, "no")) - { + if (!strcasecmp(el, "no")) { val = CHANNEL_NO; goto selchannel; - } else - { + } else { val = get_number(el); - if (val == -1) - { + if (val == -1) { SPRINT(interface_error, "Error in %s (line %d): parameter '%s' expects a comma seperated list of 'force', 'any', 'free', 'no' and any channel number.\n", filename, line, parameter); return(-1); } - if (val<1 || val==16 || val>126) - { + if (val<1 || val==16 || val>126) { SPRINT(interface_error, "Error in %s (line %d): channel '%d' out of range.\n", filename, line, val); return(-1); } @@ -470,8 +470,7 @@ static int inter_channel_in(struct interface *interface, char *filename, int lin char *p, *el; /* port in chain ? */ - if (!interface->ifport) - { + if (!interface->ifport) { SPRINT(interface_error, "Error in %s (line %d): parameter '%s' expects previous 'port' definition.\n", filename, line, parameter); return(-1); } @@ -480,30 +479,24 @@ static int inter_channel_in(struct interface *interface, char *filename, int lin while(ifport->next) ifport = ifport->next; p = value; - while(*p) - { + while(*p) { el = p; p = get_seperated(p); - if (ifport->in_channel) if (ifport->in_channel->channel == CHANNEL_FREE) - { + if (ifport->in_channel) if (ifport->in_channel->channel == CHANNEL_FREE) { SPRINT(interface_error, "Error in %s (line %d): parameter '%s' has values behind 'free' keyword. They has no effect.\n", filename, line, parameter); return(-1); } - if (!strcasecmp(el, "free")) - { + if (!strcasecmp(el, "free")) { val = CHANNEL_FREE; goto selchannel; - } else - { + } else { val = get_number(el); - if (val == -1) - { + if (val == -1) { SPRINT(interface_error, "Error in %s (line %d): parameter '%s' expects a comma seperated list of channel numbers and 'free'.\n", filename, line, parameter); return(-1); } - if (val<1 || val==16 || val>126) - { + if (val<1 || val==16 || val>126) { SPRINT(interface_error, "Error in %s (line %d): channel '%d' out of range.\n", filename, line, val); return(-1); } @@ -530,8 +523,7 @@ static int inter_timeouts(struct interface *interface, char *filename, int line, char *p, *el; /* port in chain ? */ - if (!interface->ifport) - { + if (!interface->ifport) { SPRINT(interface_error, "Error in %s (line %d): parameter '%s' expects previous 'port' definition.\n", filename, line, parameter); return(-1); } @@ -540,8 +532,7 @@ static int inter_timeouts(struct interface *interface, char *filename, int line, while(ifport->next) ifport = ifport->next; p = value; - if (!*p) - { + if (!*p) { nofive: SPRINT(interface_error, "Error in %s (line %d): parameter '%s' expects five timeout values.\n", filename, line, parameter); return(-1); @@ -576,21 +567,18 @@ static int inter_msn(struct interface *interface, char *filename, int line, char struct interface_msn *ifmsn, **ifmsnp; char *p, *el; - if (!value[0]) - { + if (!value[0]) { SPRINT(interface_error, "Error in %s (line %d): parameter '%s' expects one MSN number or a list.\n", filename, line, parameter); return(-1); } - if (interface->ifscreen_in) - { + if (interface->ifscreen_in) { SPRINT(interface_error, "Error in %s (line %d): parameter '%s' not allowed with 'screen_in' parameter.\n", filename, line, parameter); return(-1); } /* process list */ p = value; - while(*p) - { + while(*p) { el = p; p = get_seperated(p); /* add MSN to list */ @@ -611,8 +599,7 @@ static int inter_screen(struct interface_screen **ifscreenp, struct interface *i struct interface_screen *ifscreen; char *p, *el; - if (!value[0]) - { + if (!value[0]) { SPRINT(interface_error, "Error in %s (line %d): parameter '%s' expects old caller ID and new caller ID.\n", filename, line, parameter); return(-1); } @@ -630,60 +617,49 @@ static int inter_screen(struct interface_screen **ifscreenp, struct interface *i // printf("interface=%s\n", interface->name); /* get match */ p = value; - while(*p) - { + while(*p) { el = p; p = get_seperated(p); - if (!strcasecmp(el, "unknown")) - { - if (ifscreen->match_type != -1) - { + if (!strcasecmp(el, "unknown")) { + if (ifscreen->match_type != -1) { typeerror: SPRINT(interface_error, "Error in %s (line %d): number type already set earlier.\n", filename, line, parameter); return(-1); } ifscreen->match_type = INFO_NTYPE_UNKNOWN; } else - if (!strcasecmp(el, "subscriber")) - { + if (!strcasecmp(el, "subscriber")) { if (ifscreen->match_type != -1) goto typeerror; ifscreen->match_type = INFO_NTYPE_SUBSCRIBER; } else - if (!strcasecmp(el, "national")) - { + if (!strcasecmp(el, "national")) { if (ifscreen->match_type != -1) goto typeerror; ifscreen->match_type = INFO_NTYPE_NATIONAL; } else - if (!strcasecmp(el, "international")) - { + if (!strcasecmp(el, "international")) { if (ifscreen->match_type != -1) goto typeerror; ifscreen->match_type = INFO_NTYPE_INTERNATIONAL; } else - if (!strcasecmp(el, "allowed")) - { - if (ifscreen->match_present != -1) - { + if (!strcasecmp(el, "allowed")) { + if (ifscreen->match_present != -1) { presenterror: SPRINT(interface_error, "Error in %s (line %d): presentation type already set earlier.\n", filename, line); return(-1); } ifscreen->match_present = INFO_PRESENT_ALLOWED; } else - if (!strcasecmp(el, "restrict") || !strcasecmp(el, "restricted")) - { + if (!strcasecmp(el, "restrict") || !strcasecmp(el, "restricted")) { if (ifscreen->match_present != -1) goto presenterror; ifscreen->match_present = INFO_PRESENT_RESTRICTED; } else { SCPY(ifscreen->match, el); /* check for % at the end */ - if (strchr(el, '%')) - { - if (strchr(el, '%') != el+strlen(el)-1) - { + if (strchr(el, '%')) { + if (strchr(el, '%') != el+strlen(el)-1) { SPRINT(interface_error, "Error in %s (line %d): %% joker found, but must at the end.\n", filename, line, parameter); return(-1); } @@ -691,58 +667,48 @@ static int inter_screen(struct interface_screen **ifscreenp, struct interface *i break; } } - if (ifscreen->match[0] == '\0') - { + if (ifscreen->match[0] == '\0') { SPRINT(interface_error, "Error in %s (line %d): parameter '%s' expects old caller ID.\n", filename, line, parameter); return(-1); } /* get result */ - while(*p) - { + while(*p) { el = p; p = get_seperated(p); - if (!strcasecmp(el, "unknown")) - { + if (!strcasecmp(el, "unknown")) { if (ifscreen->result_type != -1) goto typeerror; ifscreen->result_type = INFO_NTYPE_UNKNOWN; } else - if (!strcasecmp(el, "subscriber")) - { + if (!strcasecmp(el, "subscriber")) { if (ifscreen->result_type != -1) goto typeerror; ifscreen->result_type = INFO_NTYPE_SUBSCRIBER; } else - if (!strcasecmp(el, "national")) - { + if (!strcasecmp(el, "national")) { if (ifscreen->result_type != -1) goto typeerror; ifscreen->result_type = INFO_NTYPE_NATIONAL; } else - if (!strcasecmp(el, "international")) - { + if (!strcasecmp(el, "international")) { if (ifscreen->result_type != -1) goto typeerror; ifscreen->result_type = INFO_NTYPE_INTERNATIONAL; } else - if (!strcasecmp(el, "present") || !strcasecmp(el, "presented") || !strcasecmp(el, "allowed") || !strcasecmp(el, "allow")) - { + if (!strcasecmp(el, "present") || !strcasecmp(el, "presented") || !strcasecmp(el, "allowed") || !strcasecmp(el, "allow")) { if (ifscreen->result_present != -1) goto presenterror; ifscreen->result_present = INFO_PRESENT_ALLOWED; } else - if (!strcasecmp(el, "restrict") || !strcasecmp(el, "restricted") || !strcasecmp(el, "deny") || !strcasecmp(el, "denied")) - { + if (!strcasecmp(el, "restrict") || !strcasecmp(el, "restricted") || !strcasecmp(el, "deny") || !strcasecmp(el, "denied")) { if (ifscreen->result_present != -1) goto presenterror; ifscreen->result_present = INFO_PRESENT_RESTRICTED; } else { SCPY(ifscreen->result, el); /* check for % at the end */ - if (strchr(el, '%')) - { - if (strchr(el, '%') != el+strlen(el)-1) - { + if (strchr(el, '%')) { + if (strchr(el, '%') != el+strlen(el)-1) { SPRINT(interface_error, "Error in %s (line %d): %% joker found, but must at the end.\n", filename, line, parameter); return(-1); } @@ -750,8 +716,7 @@ static int inter_screen(struct interface_screen **ifscreenp, struct interface *i break; } } - if (ifscreen->result[0] == '\0') - { + if (ifscreen->result[0] == '\0') { SPRINT(interface_error, "Error in %s (line %d): parameter '%s' expects new caller ID.\n", filename, line, parameter); return(-1); } @@ -759,8 +724,7 @@ static int inter_screen(struct interface_screen **ifscreenp, struct interface *i } static int inter_screen_in(struct interface *interface, char *filename, int line, char *parameter, char *value) { - if (interface->ifmsn) - { + if (interface->ifmsn) { SPRINT(interface_error, "Error in %s (line %d): parameter '%s' not allowed with 'msn' parameter.\n", filename, line, parameter); return(-1); } @@ -776,8 +740,7 @@ static int inter_nodtmf(struct interface *interface, char *filename, int line, c struct interface_port *ifport; /* port in chain ? */ - if (!interface->ifport) - { + if (!interface->ifport) { SPRINT(interface_error, "Error in %s (line %d): parameter '%s' expects previous 'port' definition.\n", filename, line, parameter); return(-1); } @@ -788,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; @@ -796,62 +775,51 @@ static int inter_filter(struct interface *interface, char *filename, int line, c p = value; while(*p > 32) p++; - if (*p) - { + if (*p) { *p++ = 0; while(*p > 0 && *p <= 32) p++; } - if (!strcasecmp(value, "gain")) - { + if (!strcasecmp(value, "gain")) { q = p; while(*q > 32) q++; - if (*q) - { + if (*q) { *q++ = 0; while(*q > 0 && *q <= 32) q++; } - if (*p == 0 || *q == 0) - { + if (*p == 0 || *q == 0) { SPRINT(interface_error, "Error in %s (line %d): parameter '%s %s' expects two gain values.\n", filename, line, parameter, value); return(-1); } - if (atoi(p)<-8 || atoi(p)>8 || atoi(q)<-8 || atoi(q)>8) - { + if (atoi(p)<-8 || atoi(p)>8 || atoi(q)<-8 || atoi(q)>8) { SPRINT(interface_error, "Error in %s (line %d): parameter '%s %s' gain values not in range. (-8...8)\n", filename, line, parameter, value); return(-1); } interface->tx_gain = atoi(p); interface->rx_gain = atoi(q); } else - if (!strcasecmp(value, "pipeline")) - { - if (*p == 0) - { + if (!strcasecmp(value, "pipeline")) { + if (*p == 0) { SPRINT(interface_error, "Error in %s (line %d): parameter '%s %s' expects pipeline string.\n", filename, line, parameter, value); return(-1); } SCPY(interface->pipeline, p); } else - if (!strcasecmp(value, "blowfish")) - { + if (!strcasecmp(value, "blowfish")) { unsigned char key[56]; int l; - if (!!strncmp(p, "0x", 2)) - { + if (!!strncmp(p, "0x", 2)) { SPRINT(interface_error, "Error in %s (line %d): parameter '%s %s' expects blowfish key starting with '0x'.\n", filename, line, parameter, value); return(-1); } p += 2; l = 0; - while(*p) - { - if (l == 56) - { + while(*p) { + if (l == 56) { SPRINT(interface_error, "Error in %s (line %d): parameter '%s %s' key too long.\n", filename, line, parameter, value); return(-1); } @@ -861,15 +829,13 @@ static int inter_filter(struct interface *interface, char *filename, int line, c key[l] = (*p-'a'+10)<<4; else if (*p >= 'A' && *p <= 'F') key[l] = (*p-'A'+10)<<4; - else - { + else { digout: SPRINT(interface_error, "Error in %s (line %d): parameter '%s %s' key has digits out of range. (0...9, a...f)\n", filename, line, parameter, value); return(-1); } p++; - if (*p == 0) - { + if (*p == 0) { SPRINT(interface_error, "Error in %s (line %d): parameter '%s %s' key must end on an 8 bit boundary (two character boundary).\n", filename, line, parameter, value); return(-1); } @@ -884,15 +850,13 @@ static int inter_filter(struct interface *interface, char *filename, int line, c p++; l++; } - if (l < 4) - { + if (l < 4) { SPRINT(interface_error, "Error in %s (line %d): parameter '%s %s' key must be at least 4 bytes (8 characters).\n", filename, line, parameter, value); return(-1); } memcpy(interface->bf_key, key, l); interface->bf_len = l; - } else - { + } else { SPRINT(interface_error, "Error in %s (line %d): parameter '%s' has unknown filter '%s'.\n", filename, line, parameter, value); return(-1); } @@ -903,8 +867,7 @@ static int inter_dialmax(struct interface *interface, char *filename, int line, struct interface_port *ifport; /* port in chain ? */ - if (!interface->ifport) - { + if (!interface->ifport) { SPRINT(interface_error, "Error in %s (line %d): parameter '%s' expects previous 'port' definition.\n", filename, line, parameter); return(-1); } @@ -915,6 +878,532 @@ static int inter_dialmax(struct interface *interface, char *filename, int line, ifport->dialmax = atoi(value); return(0); } +static int inter_tones_dir(struct interface *interface, char *filename, int line, char *parameter, char *value) +{ + if (!value || !value[0]) { + SPRINT(interface_error, "Error in %s (line %d): Missing tones directory.\n", filename, line); + return(-1); + } + SCPY(interface->tones_dir, value); + + return(0); +} +static int inter_gsm(struct interface *interface, char *filename, int line, char *parameter, char *value) +{ + SPRINT(interface_error, "Error in %s (line %d): parameter '%s' is outdated.\nPlease use 'gsm-bs' for base station or 'gsm-ms' for mobile station interface!\n", filename, line, parameter); + return(-1); +} +static int inter_gsm_bs(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 + struct interface *searchif; + + interface->gsm_bs = 1; + + if (!value) + interface->gsm_bs_name[0] = '\0'; + else + SCPY(interface->gsm_bs_name, value); + + /* check if name is used multiple times */ + searchif = interface_newlist; + while(searchif) { + if (searchif != interface && searchif->gsm_bs && !strcmp(searchif->gsm_bs_name, interface->gsm_bs_name)) { + SPRINT(interface_error, "Error in %s (line %d): network '%s' already uses the given MS name '%s', choose a different one.\n", filename, line, interface->gsm_bs_name, searchif->gsm_bs_name); + return(-1); + } + searchif = searchif->next; + } + + 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 + SPRINT(interface_error, "Error in %s (line %d): GSM MS side not compiled in.\n", filename, line); + return(-1); +#else + struct interface *searchif; + + interface->gsm_ms = 1; + + /* copy values */ + if (!value || !value[0]) { + SPRINT(interface_error, "Error in %s (line %d): Missing MS name and socket name.\n", filename, line); + return(-1); + } + SCPY(interface->gsm_ms_name, value); + + /* check if name is used multiple times */ + searchif = interface_newlist; + while(searchif) { + if (searchif != interface && searchif->gsm_bs && !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); + } + searchif = searchif->next; + } + + return(0); +#endif +} +static int inter_sip(struct interface *interface, char *filename, int line, char *parameter, char *value) +{ +#ifndef WITH_SIP + SPRINT(interface_error, "Error in %s (line %d): SIP not compiled in.\n", filename, line); + return(-1); +#else + char *p; + + interface->sip = 1; + + /* copy values */ + if (!value || !value[0]) { + SPRINT(interface_error, "Error in %s (line %d): Missing SIP local peer.\n", filename, line); + return(-1); + } + p = get_seperated(value); + SCPY(interface->sip_local_peer, value); + SCPY(interface->sip_remote_peer, p); + + return(0); +#endif +} +static int inter_authenticate(struct interface *interface, char *filename, int line, char *parameter, char *value) +{ +#ifndef WITH_SIP + SPRINT(interface_error, "Error in %s (line %d): SIP not compiled in.\n", filename, line); + return(-1); +#else + char *p, *q; + + if (!interface->sip) { + SPRINT(interface_error, "Error in %s (line %d): This is not a SIP interface.\n", filename, line); + return(-1); + } + + /* copy values */ + if (!value || !value[0]) { + SPRINT(interface_error, "Error in %s (line %d): Missing SIP user.\n", filename, line); + return(-1); + } + p = get_seperated(value); + if (!p[0]) { + SPRINT(interface_error, "Error in %s (line %d): Missing SIP password.\n", filename, line); + return(-1); + } + q = get_seperated(p); + SCPY(interface->sip_auth_user, value); + SCPY(interface->sip_auth_password, p); + if (q[0]) + SCPY(interface->sip_auth_realm, q); + + return(0); +#endif +} +static int options_interval(struct interface *interface, char *filename, int line, char *parameter, char *value) +{ +#ifndef WITH_SIP + SPRINT(interface_error, "Error in %s (line %d): SIP not compiled in.\n", filename, line); + return(-1); +#else + if (!interface->sip) { + SPRINT(interface_error, "Error in %s (line %d): This is not a SIP interface.\n", filename, line); + return(-1); + } + + if (!value || !value[0]) { + SPRINT(interface_error, "Error in %s (line %d): Missing options interval.\n", filename, line); + return(-1); + } + interface->sip_options_interval = atoi(value); + + return(0); +#endif +} +static int options_asserted_id(struct interface *interface, char *filename, int line, char *parameter, char *value) +{ +#ifndef WITH_SIP + SPRINT(interface_error, "Error in %s (line %d): SIP not compiled in.\n", filename, line); + return(-1); +#else + if (!interface->sip) { + SPRINT(interface_error, "Error in %s (line %d): This is not a SIP interface.\n", filename, line); + return(-1); + } + + if (!value || !value[0]) { + SPRINT(interface_error, "Error in %s (line %d): Missing asserted caller ID.\n", filename, line); + return(-1); + } + SCPY(interface->sip_asserted_id, value); + + return(0); +#endif +} +static int options_public(struct interface *interface, char *filename, int line, char *parameter, char *value) +{ +#ifndef WITH_SIP + SPRINT(interface_error, "Error in %s (line %d): SIP not compiled in.\n", filename, line); + return(-1); +#else + if (!interface->sip) { + SPRINT(interface_error, "Error in %s (line %d): This is not a SIP interface.\n", filename, line); + return(-1); + } + if (interface->sip_stun_server[0]) { + SPRINT(interface_error, "Error in %s (line %d): Don't specify STUN, if you want to define public IP.\n", filename, line); + return(-1); + } + + if (!value || !value[0]) { + SPRINT(interface_error, "Error in %s (line %d): Missing public IP.\n", filename, line); + return(-1); + } + SCPY(interface->sip_public_ip, value); + + return(0); +#endif +} +static int options_stun(struct interface *interface, char *filename, int line, char *parameter, char *value) +{ +#ifndef WITH_SIP + SPRINT(interface_error, "Error in %s (line %d): SIP not compiled in.\n", filename, line); + return(-1); +#else + char *p; + + if (!interface->sip) { + SPRINT(interface_error, "Error in %s (line %d): This is not a SIP interface.\n", filename, line); + return(-1); + } + if (interface->sip_public_ip[0]) { + SPRINT(interface_error, "Error in %s (line %d): Don't specify public IP, if you want to define STUN.\n", filename, line); + return(-1); + } + + if (!value || !value[0]) { + SPRINT(interface_error, "Error in %s (line %d): Missing STUN server.\n", filename, line); + return(-1); + } + p = get_seperated(value); + if (!p[0]) { + SPRINT(interface_error, "Error in %s (line %d): Missing STUN timer.\n", filename, line); + return(-1); + } + SCPY(interface->sip_stun_server, value); + interface->sip_stun_interval = atoi(p); + + return(0); +#endif +} +static int inter_rtp_ports(struct interface *interface, char *filename, int line, char *parameter, char *value) +{ +#ifndef WITH_SIP + SPRINT(interface_error, "Error in %s (line %d): SIP not compiled in.\n", filename, line); + return(-1); +#else + char *p; + + if (!interface->sip) { + SPRINT(interface_error, "Error in %s (line %d): This is not a SIP interface.\n", filename, line); + return(-1); + } + + /* copy values */ + if (!value || !value[0]) { + SPRINT(interface_error, "Error in %s (line %d): Missing 'from' port.\n", filename, line); + return(-1); + } + p = get_seperated(value); + if (!p[0]) { + SPRINT(interface_error, "Error in %s (line %d): Missing 'to' port.\n", filename, line); + return(-1); + } + interface->rtp_port_from = atoi(value); + interface->rtp_port_to = atoi(p); + + return(0); +#endif +} +static int inter_register(struct interface *interface, char *filename, int line, char *parameter, char *value) +{ +#ifndef WITH_SIP + SPRINT(interface_error, "Error in %s (line %d): SIP not compiled in.\n", filename, line); + return(-1); +#else + char *p, *q; + + if (!interface->sip) { + SPRINT(interface_error, "Error in %s (line %d): This is not a SIP interface.\n", filename, line); + return(-1); + } + + /* copy values */ + if (!value || !value[0]) { + SPRINT(interface_error, "Error in %s (line %d): Missing SIP user.\n", filename, line); + return(-1); + } + p = get_seperated(value); + if (!p[0]) { + SPRINT(interface_error, "Error in %s (line %d): Missing SIP host\n", filename, line); + return(-1); + } + q = get_seperated(p); + if (!q[0]) + interface->sip_register_interval = 0; + else + interface->sip_register_interval = atoi(q); + interface->sip_register = 1; + SCPY(interface->sip_register_user, value); + SCPY(interface->sip_register_host, 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; + + /* 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->nonotify = 1; + return(0); +} +#ifdef WITH_SS5 +static int inter_ss5(struct interface *interface, char *filename, int line, char *parameter, char *value) +{ + struct interface_port *ifport; + char *element; + + /* 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->ss5 |= SS5_ENABLE; + while((element = strsep(&value, " "))) { + if (element[0] == '\0') + continue; + if (!strcasecmp(element, "connect")) + ifport->ss5 |= SS5_FEATURE_CONNECT; + else + if (!strcasecmp(element, "nodisconnect")) + ifport->ss5 |= SS5_FEATURE_NODISCONNECT; + else + if (!strcasecmp(element, "releaseguardtimer")) + ifport->ss5 |= SS5_FEATURE_RELEASEGUARDTIMER; + else + if (!strcasecmp(element, "bell")) + ifport->ss5 |= SS5_FEATURE_BELL; + else + if (!strcasecmp(element, "pulsedialing")) + ifport->ss5 |= SS5_FEATURE_PULSEDIALING; + else + if (!strcasecmp(element, "delay")) + ifport->ss5 |= SS5_FEATURE_DELAY; + else + 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, "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); + } + } + return(0); +} +#endif +static int inter_remote(struct interface *interface, char *filename, int line, char *parameter, char *value) +{ + struct interface *searchif; + + if (!value[0]) { + SPRINT(interface_error, "Error in %s (line %d): parameter '%s' expects application name as value.\n", filename, line, parameter); + return(-1); + } + searchif = interface_newlist; + while(searchif) { + 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; + } + + /* 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); + + 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->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); +} /* @@ -923,6 +1412,12 @@ static int inter_dialmax(struct interface *interface, char *filename, int line, struct interface_param interface_param[] = { { "extension", &inter_extension, "", "If keyword is given, calls to interface are handled as internal extensions."}, + + { "extern", &inter_extern, "", + "If keyword is given, this interface will be used for external calls.\n" + "Calls require an external interface, if the routing action 'extern' is used\nwithout specific interface given.\n" + "Calls forwarded by extension's 'settings' also require an external interface."}, + {"tones", &inter_tones, "yes | no", "Interface generates tones during call setup and release, or not.\nBy default only NT-mode ports generate tones."}, @@ -968,6 +1463,11 @@ struct interface_param interface_param[] = { "Note that this is not compliant with ISDN protocol.\n" "This parameter must follow a 'port' parameter."}, + {"layer1hold", &inter_l1hold, "yes | no", + "The given port will not release layer 1 after layer 2 is down.\n" + "It is required to keep layer 1 of telephones up, to solve activation problems.\n" + "This parameter must follow a 'port' parameter."}, + {"layer2hold", &inter_l2hold, "yes | no", "The given port will continuously try to establish layer 2 link and hold it.\n" "It is required for PTP links in most cases, therefore it is default.\n" @@ -977,7 +1477,8 @@ struct interface_param interface_param[] = { "Channel selection list for all outgoing calls to the interface.\n" "A free channels is searched in order of appearance.\n" "This parameter must follow a 'port' parameter.\n" - " force - Forces the selected port with no acceptable alternative (see DSS1).\n" + " force - Forces the selected port with no acceptable alternative (see Q.931).\n" + " -> this will be automatically set for multipoint (ptmp) NT-mode ports\n" " [,...] - List of channels to search.\n" " free - Select any free channel\n" " any - On outgoing calls, signal 'any channel acceptable'. (see DSS1)\n" @@ -994,7 +1495,7 @@ struct interface_param interface_param[] = { {"timeouts", &inter_timeouts, " ", "Timeout values for call states. They are both for incoming and outgoing states.\n" "The default is 120 seconds for all states. Use 0 to disable.\n" - "This parameter must follow a 'port' parameter.\n"}, + "This parameter must follow a 'port' parameter."}, {"msn", &inter_msn, ",[[,...]]", "Incoming caller ID is checked against given MSN numbers.\n" @@ -1019,6 +1520,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" @@ -1028,6 +1533,108 @@ struct interface_param interface_param[] = { {"dialmax", &inter_dialmax, "", "Limits the number of digits in setup/information message."}, + {"tones-dir", &inter_tones_dir, "", + "Overrides the given tone_dir in options.conf.\n" + "To used kernel tones in mISDN_dsp.ko, say 'american', 'german', or 'oldgerman'."}, + {"tones_dir", &inter_tones_dir, "", + "Same as tones-dir"}, + + {"gsm", &inter_gsm, "", + ""}, + {"gsm-bs", &inter_gsm_bs, "[]", + "Sets up GSM base station interface for using OpenBSC.\n" + "The socket is /tmp/bsc_mncc by default. If socket name is given, the socket will be\n" + "extended to /tmp/bsc_mncc_."}, + {"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 socket will be /tmp/ms_mncc_."}, + + {"sip", &inter_sip, "[:port] [[port]]", + "Sets up SIP interface that represents one SIP endpoint.\n" + "If the remote IP/host is omitted, a client must register first to us."}, + {"register", &inter_register, " [options-interval]", + "Registers to given SIP registrar.\n" + "Optionally give SIP timer to send OPTIONS messages to keepalive REGISTER sessions."}, + {"authenticate", &inter_authenticate, " [realm]", + "Defines SIP user and password for authentication.\n" + "If no remote IP was give, we are SIP gateway, so realm must be given also."}, + {"options-interval", &options_interval, " | 0", + "Defines SIP timer to send OPTIONS messages to keepalive INVITE sessions."}, + {"asserted-id", &options_asserted_id, "", + "Defines SIP's asserted-id in INVITE message."}, + {"public", &options_public, " ", + "Defines public IP, if this endpoint is behind NAT firewall."}, + {"stun", &options_stun, " ", + "Defines STUN server to resolv real local IP.\n" + "The interval is used to check if IP has changed. (use 300)"}, + {"rtp-ports", &inter_rtp_ports, " ", + "Defines the range of ports to be used for RTP. This overrides the default."}, + + {"rtp-bridge", &inter_rtp_bridge, "", + "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."}, +#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."}, +#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 ...]]", + "Interface uses CCITT No. 5 inband signalling rather than D-channel.\n" + "This feature causes CPU load to rise and has no practical intend.\n" + "If you don't know what it is, you don't need it.\n" + "Features apply to protocol behaviour and blueboxing specials, they are:\n" + " connect - Connect incomming call to throughconnect audio, if required.\n" + " nodisconnect - Don't disconnect if incomming exchange disconnects.\n" + " releaseguardtimer - Tries to prevent Blueboxing by a longer release-guard.\n" + " 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" + " 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."}, + {"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."}, + {"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."}, + + {"shutdown", &inter_shutdown, "", + "Interface will not be loaded when processing interface.conf"}, + {NULL, NULL, NULL, NULL} }; @@ -1055,22 +1662,17 @@ struct interface *read_interfaces(void) interface_error[0] = '\0'; SPRINT(filename, "%s/interface.conf", CONFIG_DATA); - if (!(fp = fopen(filename,"r"))) - { + if (!(fp = fopen(filename,"r"))) { SPRINT(interface_error, "Cannot open '%s'\n", filename); goto error; } line=0; - while((fgets(buffer,sizeof(buffer),fp))) - { - buffer[sizeof(buffer)-1]=0; - if (buffer[0]) buffer[strlen(buffer)-1]=0; + while((GETLINE(buffer, fp))) { p=buffer; line++; - while(*p <= 32) /* skip spaces */ - { + while(*p <= 32) { /* skip spaces */ if (*p == 0) break; p++; @@ -1081,10 +1683,8 @@ struct interface *read_interfaces(void) parameter[0]=0; value[0]=0; i=0; /* read parameter */ - while(*p > 32) - { - if (i+1 >= sizeof(parameter)) - { + while(*p > 32) { + if (i+1 >= sizeof(parameter)) { SPRINT(interface_error, "Error in %s (line %d): parameter name too long.\n",filename,line); goto error; } @@ -1092,20 +1692,16 @@ struct interface *read_interfaces(void) parameter[i++] = *p++; } - while(*p <= 32) /* skip spaces */ - { + while(*p <= 32) { /* skip spaces */ if (*p == 0) break; p++; } - if (*p!=0 && *p!='#') /* missing name */ - { + if (*p!=0 && *p!='#') { /* missing name */ i=0; /* read until end */ - while(*p!=0 && *p!='#') - { - if (i+1 >= sizeof(value)) - { + while(*p!=0 && *p!='#') { + if (i+1 >= sizeof(value)) { SPRINT(interface_error, "Error in %s (line %d): value too long.\n", filename, line); goto error; } @@ -1114,8 +1710,7 @@ struct interface *read_interfaces(void) } /* remove trailing spaces from value */ - while(i) - { + while(i) { if (value[i-1]==0 || value[i-1]>32) break; value[i-1] = '\0'; @@ -1124,18 +1719,15 @@ struct interface *read_interfaces(void) } /* check for interface name as first statement */ - if (expecting && parameter[0]!='[') - { + if (expecting && parameter[0]!='[') { SPRINT(interface_error, "Error in %s (line %d): expecting interface name inside [ and ], but got: '%s'.\n", filename, line, parameter); goto error; } expecting = 0; /* check for new interface */ - if (parameter[0] == '[') - { - if (parameter[strlen(parameter)-1] != ']') - { + if (parameter[0] == '[') { + if (parameter[strlen(parameter)-1] != ']') { SPRINT(interface_error, "Error in %s (line %d): expecting interface name inside [ and ], but got: '%s'.\n", filename, line, parameter); goto error; } @@ -1143,10 +1735,8 @@ struct interface *read_interfaces(void) /* check if interface name already exists */ interface = interface_newlist; - while(interface) - { - if (!strcasecmp(interface->name, parameter+1)) - { + while(interface) { + if (!strcasecmp(interface->name, parameter+1)) { SPRINT(interface_error, "Error in %s (line %d): interface name '%s' already defined above.\n", filename, line, parameter+1); goto error; } @@ -1168,10 +1758,8 @@ struct interface *read_interfaces(void) } ifparam = interface_param; - while(ifparam->name) - { - if (!strcasecmp(parameter, ifparam->name)) - { + while(ifparam->name) { + if (!strcasecmp(parameter, ifparam->name)) { if (ifparam->func(interface, filename, line, parameter, value)) goto error; break; @@ -1207,22 +1795,18 @@ void free_interfaces(struct interface *interface) struct interface_msn *ifmsn; struct interface_screen *ifscreen; - while(interface) - { + while(interface) { ifport = interface->ifport; - while(ifport) - { + while(ifport) { selchannel = ifport->in_channel; - while(selchannel) - { + while(selchannel) { temp = selchannel; selchannel = selchannel->next; FREE(temp, sizeof(struct select_channel)); memuse--; } selchannel = ifport->out_channel; - while(selchannel) - { + while(selchannel) { temp = selchannel; selchannel = selchannel->next; FREE(temp, sizeof(struct select_channel)); @@ -1234,24 +1818,21 @@ void free_interfaces(struct interface *interface) memuse--; } ifmsn = interface->ifmsn; - while(ifmsn) - { + while(ifmsn) { temp = ifmsn; ifmsn = ifmsn->next; FREE(temp, sizeof(struct interface_msn)); memuse--; } ifscreen = interface->ifscreen_in; - while(ifscreen) - { + while(ifscreen) { temp = ifscreen; ifscreen = ifscreen->next; FREE(temp, sizeof(struct interface_screen)); memuse--; } ifscreen = interface->ifscreen_out; - while(ifscreen) - { + while(ifscreen) { temp = ifscreen; ifscreen = ifscreen->next; FREE(temp, sizeof(struct interface_screen)); @@ -1264,32 +1845,37 @@ 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) default_out_channel(ifport); if (!ifport->in_channel) default_in_channel(ifport); + /* must force the channel on PTMP/NT ports */ + if (!ifport->mISDNport->ptp && ifport->mISDNport->ntmode) + ifport->channel_force = 1; /* default is_tones */ if (ifport->interface->is_tones) ifport->mISDNport->tones = (ifport->interface->is_tones==IS_YES); else - ifport->mISDNport->tones = (ifport->mISDNport->ntmode)?1:0; + ifport->mISDNport->tones = (ifport->mISDNport->ntmode || ifport->mISDNport->ss5)?1:0; /* default is_earlyb */ if (ifport->interface->is_earlyb) ifport->mISDNport->earlyb = (ifport->interface->is_earlyb==IS_YES); else - ifport->mISDNport->earlyb = (ifport->mISDNport->ntmode)?0:1; + ifport->mISDNport->earlyb = (ifport->mISDNport->ntmode && !ifport->mISDNport->ss5)?0:1; /* set locally flag */ if (ifport->interface->extension) ifport->mISDNport->locally = 1; else ifport->mISDNport->locally = 0; } +#endif /* @@ -1299,36 +1885,95 @@ static void set_defaults(struct interface_port *ifport) */ void relink_interfaces(void) { +#ifdef WITH_MISDN struct mISDNport *mISDNport; - struct interface *interface; struct interface_port *ifport; +#endif + struct interface *interface, *temp, *found; + + interface = interface_first; + while(interface) { + found = NULL; + temp = interface_newlist; + while(temp) { + if (!strcmp(temp->name, interface->name)) + found = temp; + temp = temp->next; + } + if (!found) { +#ifdef WITH_GSM_MS + if (interface->gsm_ms) + gsm_ms_delete(interface->gsm_ms_name); +#endif +#ifdef WITH_GSM_BS + if (interface->gsm_bs) + gsm_bs_delete(interface->gsm_bs_name); +#endif +#ifdef WITH_SIP + 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 = NULL; + temp = interface_first; + while(temp) { + if (!strcmp(temp->name, interface->name)) + found = temp; + temp = temp->next; + } + if (!found) { +#ifdef WITH_GSM_MS + if (interface->gsm_ms) + gsm_ms_new(interface); +#endif +#ifdef WITH_GSM_BS + if (interface->gsm_bs) + gsm_bs_new(interface); +#endif +#ifdef WITH_SIP + if (interface->sip) + sip_init_inst(interface); +#endif + } + interface = interface->next; + } + +#ifdef WITH_MISDN /* unlink all mISDNports */ mISDNport = mISDNport_first; - while(mISDNport) - { + while(mISDNport) { mISDNport->ifport = NULL; mISDNport = mISDNport->next; } /* relink existing mISDNports */ interface = interface_newlist; - while(interface) - { + while(interface) { ifport = interface->ifport; - while(ifport) - { + while(ifport) { mISDNport = mISDNport_first; - while(mISDNport) - { + while(mISDNport) { if (!strcmp(mISDNport->name, ifport->portname)) ifport->portnum = mISDNport->portnum; /* same name, so we use same number */ - if (mISDNport->portnum == ifport->portnum) - { - PDEBUG(DEBUG_ISDN, "Port %d:%s relinking!\n", mISDNport->portnum); + if (mISDNport->portnum == ifport->portnum) { + 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; } @@ -1340,12 +1985,10 @@ void relink_interfaces(void) /* close unused mISDNports */ closeagain: mISDNport = mISDNport_first; - while(mISDNport) - { - if (mISDNport->ifport == NULL) - { + while(mISDNport) { + if (mISDNport->ifport == NULL) { PDEBUG(DEBUG_ISDN, "Port %d is not used anymore and will be closed\n", mISDNport->portnum); - /* remove all port objects and destroy port */ + /* destroy port */ mISDNport_close(mISDNport); goto closeagain; } @@ -1354,34 +1997,35 @@ void relink_interfaces(void) /* open and link new mISDNports */ interface = interface_newlist; - while(interface) - { + while(interface) { ifport = interface->ifport; - while(ifport) - { - if (!ifport->mISDNport) - { - load_port(ifport); + while(ifport) { + if (!ifport->mISDNport) { + if (!interface->shutdown) { + load_mISDN_port(ifport); + } else { + ifport->block = 2; + } } ifport = ifport->next; } 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; /* open new port */ - mISDNport = mISDNport_open(ifport->portnum, ifport->portname, ifport->ptp, ifport->nt, ifport->tespecial, ifport->l2hold, ifport->interface); - if (mISDNport) - { + mISDNport = mISDNport_open(ifport); + if (mISDNport) { /* link port */ ifport->mISDNport = mISDNport; mISDNport->ifport = ifport; @@ -1389,12 +2033,14 @@ void load_port(struct interface_port *ifport) ifport->portnum = mISDNport->portnum; SCPY(ifport->portname, mISDNport->name); /* set defaults */ - set_defaults(ifport); - } else - { + set_mISDN_defaults(ifport); + /* load static port instances */ + mISDNport_static(mISDNport); + } else { ifport->block = 2; /* not available */ } } +#endif /* * give summary of interface syntax @@ -1408,18 +2054,15 @@ void doc_interface(void) printf("[]\n"); ifparam = interface_param; - while(ifparam->name) - { + while(ifparam->name) { if (ifparam->name[0]) printf("%s %s\n", ifparam->name, ifparam->usage); ifparam++; } ifparam = interface_param; - while(ifparam->name) - { - if (ifparam->name[0]) - { + while(ifparam->name) { + if (ifparam->name[0]) { printf("\nParameter: %s %s\n", ifparam->name, ifparam->usage); printf("%s\n", ifparam->help); } @@ -1431,37 +2074,37 @@ void doc_interface(void) /* screen caller id * out==0: incoming caller id, out==1: outgoing caller id */ -void do_screen(int out, char *id, int idsize, int *type, int *present, struct interface *interface) +void do_screen(int out, char *id, int idsize, int *type, int *present, const char *interface_name) { char *msn1; struct interface_msn *ifmsn; struct interface_screen *ifscreen; char suffix[64]; + struct interface *interface = interface_first; + + interface = getinterfacebyname(interface_name); + if (!interface) + return; /* screen incoming caller id */ - if (!out) - { + if (!out) { /* check for MSN numbers, use first MSN if no match */ msn1 = NULL; ifmsn = interface->ifmsn; - while(ifmsn) - { + while(ifmsn) { if (!msn1) msn1 = ifmsn->msn; - if (!strcmp(ifmsn->msn, id)) - { + if (!strcmp(ifmsn->msn, id)) { break; } ifmsn = ifmsn->next; } - if (ifmsn) - { + if (ifmsn) { start_trace(-1, interface, numberrize_callerinfo(id, *type, options.national, options.international), NULL, DIRECTION_IN, 0, 0, "SCREEN (found in MSN list)"); add_trace("msn", NULL, "%s", id); end_trace(); } - if (!ifmsn && msn1) // not in list, first msn given - { + if (!ifmsn && msn1) { // not in list, first msn given start_trace(-1, interface, numberrize_callerinfo(id, *type, options.national, options.international), NULL, DIRECTION_IN, 0, 0, "SCREEN (not found in MSN list)"); add_trace("msn", "given", "%s", id); add_trace("msn", "used", "%s", msn1); @@ -1476,28 +2119,22 @@ void do_screen(int out, char *id, int idsize, int *type, int *present, struct in ifscreen = interface->ifscreen_out; else ifscreen = interface->ifscreen_in; - while (ifscreen) - { + while (ifscreen) { if (ifscreen->match_type==-1 || ifscreen->match_type==*type) - if (ifscreen->match_present==-1 || ifscreen->match_present==*present) - { - if (strchr(ifscreen->match,'%')) - { + if (ifscreen->match_present==-1 || ifscreen->match_present==*present) { + if (strchr(ifscreen->match,'%')) { if (!strncmp(ifscreen->match, id, strchr(ifscreen->match,'%')-ifscreen->match)) break; - } else - { + } else { if (!strcmp(ifscreen->match, id)) break; } } ifscreen = ifscreen->next; } - if (ifscreen) // match - { + if (ifscreen) { // match start_trace(-1, interface, numberrize_callerinfo(id, *type, options.national, options.international), NULL, out?DIRECTION_OUT:DIRECTION_IN, 0, 0, "SCREEN (found in screen list)"); - switch(*type) - { + switch(*type) { case INFO_NTYPE_UNKNOWN: add_trace("given", "type", "unknown"); break; @@ -1511,8 +2148,7 @@ void do_screen(int out, char *id, int idsize, int *type, int *present, struct in add_trace("given", "type", "international"); break; } - switch(*present) - { + switch(*present) { case INFO_PRESENT_ALLOWED: add_trace("given", "present", "allowed"); break; @@ -1524,11 +2160,9 @@ void do_screen(int out, char *id, int idsize, int *type, int *present, struct in break; } add_trace("given", "id", "%s", id[0]?id:""); - if (ifscreen->result_type != -1) - { + if (ifscreen->result_type != -1) { *type = ifscreen->result_type; - switch(*type) - { + switch(*type) { case INFO_NTYPE_UNKNOWN: add_trace("used", "type", "unknown"); break; @@ -1543,11 +2177,9 @@ void do_screen(int out, char *id, int idsize, int *type, int *present, struct in break; } } - if (ifscreen->result_present != -1) - { + if (ifscreen->result_present != -1) { *present = ifscreen->result_present; - switch(*present) - { + switch(*present) { case INFO_PRESENT_ALLOWED: add_trace("used", "present", "allowed"); break; @@ -1559,19 +2191,16 @@ void do_screen(int out, char *id, int idsize, int *type, int *present, struct in break; } } - if (strchr(ifscreen->match,'%')) - { + if (strchr(ifscreen->match,'%')) { SCPY(suffix, strchr(ifscreen->match,'%') - ifscreen->match + id); UNCPY(id, ifscreen->result, idsize); id[idsize-1] = '\0'; - if (strchr(id,'%')) - { + if (strchr(id,'%')) { *strchr(id,'%') = '\0'; UNCAT(id, suffix, idsize); id[idsize-1] = '\0'; } - } else - { + } else { UNCPY(id, ifscreen->result, idsize); id[idsize-1] = '\0'; } @@ -1580,3 +2209,16 @@ void do_screen(int out, char *id, int idsize, int *type, int *present, struct in } } +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; +} +