2002-12-08 17:30:24 +00:00
|
|
|
/** @file app_rpt.c
|
|
|
|
*
|
|
|
|
* Asterisk -- A telephony toolkit for Linux.
|
|
|
|
*
|
2004-05-31 16:04:10 +00:00
|
|
|
* Radio Repeater / Remote Base program
|
2004-06-26 19:28:55 +00:00
|
|
|
* version 0.10 6/26/04
|
2002-12-08 17:30:24 +00:00
|
|
|
*
|
2004-06-21 04:24:50 +00:00
|
|
|
* Copyright (C) 2002-2004, Jim Dixon, WB6NIL
|
2002-12-08 17:30:24 +00:00
|
|
|
*
|
2004-06-21 04:24:50 +00:00
|
|
|
* Jim Dixon, WB6NIL <jim@lambdatel.com>
|
2002-12-08 17:30:24 +00:00
|
|
|
*
|
|
|
|
* This program is free software, distributed under the terms of
|
|
|
|
* the GNU General Public License
|
|
|
|
*
|
2004-05-31 16:04:10 +00:00
|
|
|
* Repeater / Remote Functions:
|
|
|
|
* "Simple" Mode: * - autopatch access, # - autopatch hangup
|
|
|
|
* Normal mode:
|
2004-06-21 04:24:50 +00:00
|
|
|
* *0 - autopatch off
|
|
|
|
* *1XXX - remote link off
|
|
|
|
* *2XXX - remote link monitor
|
|
|
|
* *3XXX - remote link tranceive
|
|
|
|
* *4XXX - remote link command mode
|
|
|
|
* *6 - autopatch access/send (*)
|
|
|
|
* *7 - system status
|
2004-05-31 16:04:10 +00:00
|
|
|
* *8 - force ID
|
2004-06-25 19:33:22 +00:00
|
|
|
* *90 - system disable (and reset)
|
|
|
|
* *91 - system enable
|
|
|
|
* *99 - system reset
|
2004-05-31 16:04:10 +00:00
|
|
|
*
|
|
|
|
* To send an asterisk (*) while dialing or talking on phone,
|
|
|
|
* use the autopatch acess code.
|
2004-06-26 18:06:17 +00:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* Remote cmds:
|
|
|
|
*
|
|
|
|
* *0 - Recall Memory MM (*000-*099) (Gets memory from rpt.conf)
|
|
|
|
* *1 - Set VFO MMMMM*KKK*O (Mhz digits, Khz digits, Offset)
|
|
|
|
* *2 - Set Rx PL Tone HHH*D*
|
|
|
|
* *3 - Set Tx PL Tone HHH*D*
|
|
|
|
* *40 - RX PL off (Default)
|
|
|
|
* *41 - RX PL On
|
|
|
|
* *42 - TX PL Off (Default)
|
|
|
|
* *43 - TX PL On
|
|
|
|
* *44 - Low Power
|
|
|
|
* *45 - Med Power
|
|
|
|
* *46 - Hi Power
|
|
|
|
*
|
|
|
|
*/
|
2002-12-08 17:30:24 +00:00
|
|
|
|
2004-05-31 16:04:10 +00:00
|
|
|
/* number of digits for function after *. Must be at least 1 */
|
2004-06-21 04:24:50 +00:00
|
|
|
#define FUNCTION_LEN 4
|
|
|
|
/* string containing all of the 1 digit functions */
|
2004-06-25 19:33:22 +00:00
|
|
|
#define SHORTFUNCS "05678"
|
|
|
|
/* string containing all of the 2 digit functions */
|
|
|
|
#define MEDFUNCS "9"
|
2004-05-31 16:04:10 +00:00
|
|
|
|
|
|
|
/* maximum digits in DTMF buffer, and seconds after * for DTMF command timeout */
|
|
|
|
|
|
|
|
#define MAXDTMF 10
|
|
|
|
#define DTMF_TIMEOUT 3
|
|
|
|
|
2004-06-26 18:06:17 +00:00
|
|
|
#define MAXREMSTR 15
|
|
|
|
|
2004-06-21 04:24:50 +00:00
|
|
|
#define NODES "nodes"
|
2004-06-26 18:06:17 +00:00
|
|
|
#define MEMORY "memory"
|
|
|
|
|
|
|
|
#define DEFAULT_IOBASE 0x378
|
2004-06-21 04:24:50 +00:00
|
|
|
|
|
|
|
#define MAXCONNECTTIME 5000
|
|
|
|
|
|
|
|
#define MAXNODESTR 300
|
|
|
|
|
2004-05-31 16:04:10 +00:00
|
|
|
enum {REM_OFF,REM_MONITOR,REM_TX};
|
|
|
|
|
2004-06-21 04:24:50 +00:00
|
|
|
enum{ID,PROC,TERM,COMPLETE,UNKEY,REMDISC,REMALREADY,REMNOTFOUND,REMGO,
|
2004-06-25 19:33:22 +00:00
|
|
|
CONNECTED,CONNFAIL,STATUS,TIMEOUT};
|
2004-06-21 04:24:50 +00:00
|
|
|
|
2004-06-26 18:06:17 +00:00
|
|
|
enum {REM_SIMPLEX,REM_MINUS,REM_PLUS};
|
|
|
|
|
|
|
|
enum {REM_LOWPWR,REM_MEDPWR,REM_HIPWR};
|
|
|
|
|
2002-12-08 17:30:24 +00:00
|
|
|
#include <asterisk/lock.h>
|
|
|
|
#include <asterisk/file.h>
|
|
|
|
#include <asterisk/logger.h>
|
|
|
|
#include <asterisk/channel.h>
|
2004-06-21 04:24:50 +00:00
|
|
|
#include <asterisk/callerid.h>
|
2002-12-08 17:30:24 +00:00
|
|
|
#include <asterisk/pbx.h>
|
|
|
|
#include <asterisk/module.h>
|
|
|
|
#include <asterisk/translate.h>
|
|
|
|
#include <asterisk/options.h>
|
|
|
|
#include <asterisk/config.h>
|
2004-06-21 04:24:50 +00:00
|
|
|
#include <asterisk/utils.h>
|
|
|
|
#include <asterisk/say.h>
|
2002-12-08 17:30:24 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
2004-06-21 04:24:50 +00:00
|
|
|
#include <search.h>
|
2002-12-08 17:30:24 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <dirent.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/file.h>
|
|
|
|
#include <sys/ioctl.h>
|
2004-06-26 18:06:17 +00:00
|
|
|
#include <sys/io.h>
|
2002-12-08 17:30:24 +00:00
|
|
|
#include <math.h>
|
|
|
|
#include <tonezone.h>
|
|
|
|
#include <linux/zaptel.h>
|
|
|
|
|
2004-06-26 19:28:55 +00:00
|
|
|
static char *tdesc = "Radio Repeater / Remote Base version 0.10 06/26/2004";
|
2004-06-21 04:24:50 +00:00
|
|
|
static char *app = "Rpt";
|
|
|
|
|
|
|
|
static char *synopsis = "Radio Repeater/Remote Base Control System";
|
|
|
|
|
|
|
|
static char *descrip =
|
|
|
|
" Rpt(sysname): Radio Remote Link or Remote Base Link Endpoint Process.\n";
|
|
|
|
|
2002-12-08 17:30:24 +00:00
|
|
|
static int debug = 0;
|
2004-06-21 04:24:50 +00:00
|
|
|
static int nrpts = 0;
|
|
|
|
|
|
|
|
struct ast_config *cfg;
|
|
|
|
|
2002-12-08 17:30:24 +00:00
|
|
|
STANDARD_LOCAL_USER;
|
|
|
|
LOCAL_USER_DECL;
|
|
|
|
|
|
|
|
#define MSWAIT 200
|
|
|
|
#define HANGTIME 5000
|
|
|
|
#define TOTIME 180000
|
|
|
|
#define IDTIME 300000
|
|
|
|
#define MAXRPTS 20
|
|
|
|
|
|
|
|
static pthread_t rpt_master_thread;
|
|
|
|
|
2004-06-21 04:24:50 +00:00
|
|
|
struct rpt;
|
|
|
|
|
|
|
|
struct rpt_link
|
|
|
|
{
|
|
|
|
struct rpt_link *next;
|
|
|
|
struct rpt_link *prev;
|
|
|
|
char mode; /* 1 if in tx mode */
|
|
|
|
char isremote;
|
|
|
|
char name[MAXNODESTR]; /* identifier (routing) string */
|
|
|
|
char lasttx;
|
|
|
|
char lastrx;
|
|
|
|
char connected;
|
|
|
|
char outbound;
|
|
|
|
long elaptime;
|
|
|
|
struct ast_channel *chan;
|
|
|
|
struct ast_channel *pchan;
|
|
|
|
} ;
|
|
|
|
|
|
|
|
struct rpt_tele
|
|
|
|
{
|
|
|
|
struct rpt_tele *next;
|
|
|
|
struct rpt_tele *prev;
|
|
|
|
struct rpt *rpt;
|
|
|
|
int mode;
|
|
|
|
struct rpt_link mylink;
|
|
|
|
pthread_t threadid;
|
|
|
|
} ;
|
|
|
|
|
2002-12-08 17:30:24 +00:00
|
|
|
static struct rpt
|
|
|
|
{
|
|
|
|
char *name;
|
2004-06-21 04:24:50 +00:00
|
|
|
ast_mutex_t lock;
|
2002-12-08 17:30:24 +00:00
|
|
|
char *rxchanname;
|
|
|
|
char *txchanname;
|
|
|
|
char *ourcontext;
|
|
|
|
char *ourcallerid;
|
|
|
|
char *acctcode;
|
2004-06-21 04:24:50 +00:00
|
|
|
char *ident;
|
2004-05-31 16:04:10 +00:00
|
|
|
char *tonezone;
|
2004-06-21 04:24:50 +00:00
|
|
|
struct rpt_link links;
|
2002-12-08 17:30:24 +00:00
|
|
|
int hangtime;
|
|
|
|
int totime;
|
|
|
|
int idtime;
|
2004-06-21 04:24:50 +00:00
|
|
|
char exttx;
|
|
|
|
char localtx;
|
2004-05-31 16:04:10 +00:00
|
|
|
char remoterx;
|
|
|
|
char remotetx;
|
2004-06-21 04:24:50 +00:00
|
|
|
char remoteon;
|
2004-05-31 16:04:10 +00:00
|
|
|
char simple;
|
2004-06-21 04:24:50 +00:00
|
|
|
char remote;
|
2004-06-25 19:33:22 +00:00
|
|
|
char tounkeyed;
|
|
|
|
char tonotify;
|
|
|
|
char enable;
|
2004-06-21 04:24:50 +00:00
|
|
|
char dtmfbuf[MAXDTMF];
|
|
|
|
char rem_dtmfbuf[MAXDTMF];
|
|
|
|
char cmdnode[50];
|
|
|
|
struct ast_channel *rxchannel,*txchannel;
|
|
|
|
struct ast_channel *pchannel,*txpchannel;
|
|
|
|
struct rpt_tele tele;
|
|
|
|
pthread_t rpt_call_thread,rpt_thread;
|
2004-06-26 18:06:17 +00:00
|
|
|
time_t rem_dtmf_time,dtmf_time_rem;
|
2004-06-21 04:24:50 +00:00
|
|
|
int tailtimer,totimer,idtimer,txconf,conf,callmode,cidx;
|
|
|
|
int dtmfidx,rem_dtmfidx;
|
|
|
|
char mydtmf;
|
2004-06-26 18:06:17 +00:00
|
|
|
int iobase;
|
2002-12-08 17:30:24 +00:00
|
|
|
char exten[AST_MAX_EXTENSION];
|
2004-06-26 18:06:17 +00:00
|
|
|
char freq[MAXREMSTR],rxpl[MAXREMSTR],txpl[MAXREMSTR];
|
|
|
|
char offset;
|
|
|
|
char powerlevel;
|
|
|
|
char txplon;
|
|
|
|
char rxplon;
|
2002-12-08 17:30:24 +00:00
|
|
|
} rpt_vars[MAXRPTS];
|
|
|
|
|
2004-06-21 04:24:50 +00:00
|
|
|
static void *rpt_tele_thread(void *this)
|
2002-12-08 17:30:24 +00:00
|
|
|
{
|
|
|
|
ZT_CONFINFO ci; /* conference info */
|
2004-06-21 04:24:50 +00:00
|
|
|
int res = 0,hastx,imdone = 0;
|
|
|
|
struct rpt_tele *mytele = (struct rpt_tele *)this;
|
|
|
|
struct rpt *myrpt;
|
|
|
|
struct rpt_link *l,*m,linkbase;
|
|
|
|
struct ast_channel *mychannel;
|
2002-12-08 17:30:24 +00:00
|
|
|
|
2004-06-21 04:24:50 +00:00
|
|
|
/* get a pointer to myrpt */
|
|
|
|
myrpt = mytele->rpt;
|
2002-12-08 17:30:24 +00:00
|
|
|
/* allocate a pseudo-channel thru asterisk */
|
|
|
|
mychannel = ast_request("zap",AST_FORMAT_SLINEAR,"pseudo");
|
|
|
|
if (!mychannel)
|
|
|
|
{
|
|
|
|
fprintf(stderr,"rpt:Sorry unable to obtain pseudo channel\n");
|
2004-06-21 04:24:50 +00:00
|
|
|
ast_mutex_lock(&myrpt->lock);
|
|
|
|
remque((struct qelem *)mytele);
|
|
|
|
ast_mutex_unlock(&myrpt->lock);
|
|
|
|
free(mytele);
|
2002-12-08 17:30:24 +00:00
|
|
|
pthread_exit(NULL);
|
|
|
|
}
|
|
|
|
/* make a conference for the tx */
|
|
|
|
ci.chan = 0;
|
2004-06-21 04:24:50 +00:00
|
|
|
ci.confno = myrpt->conf; /* use the tx conference */
|
2002-12-08 17:30:24 +00:00
|
|
|
ci.confmode = ZT_CONF_CONFANN;
|
|
|
|
/* first put the channel on the conference in announce mode */
|
|
|
|
if (ioctl(mychannel->fds[0],ZT_SETCONF,&ci) == -1)
|
|
|
|
{
|
|
|
|
ast_log(LOG_WARNING, "Unable to set conference mode to Announce\n");
|
2004-06-21 04:24:50 +00:00
|
|
|
ast_mutex_lock(&myrpt->lock);
|
|
|
|
remque((struct qelem *)mytele);
|
|
|
|
ast_mutex_unlock(&myrpt->lock);
|
|
|
|
free(mytele);
|
|
|
|
ast_hangup(mychannel);
|
2002-12-08 17:30:24 +00:00
|
|
|
pthread_exit(NULL);
|
|
|
|
}
|
|
|
|
ast_stopstream(mychannel);
|
2004-06-21 04:24:50 +00:00
|
|
|
switch(mytele->mode)
|
2004-05-31 16:04:10 +00:00
|
|
|
{
|
2004-06-21 04:24:50 +00:00
|
|
|
case ID:
|
|
|
|
res = ast_streamfile(mychannel, myrpt->ident, mychannel->language);
|
|
|
|
break;
|
|
|
|
case PROC:
|
|
|
|
/* wait a little bit longer */
|
|
|
|
usleep(1500000);
|
|
|
|
res = ast_streamfile(mychannel, "rpt/callproceeding", mychannel->language);
|
|
|
|
break;
|
|
|
|
case TERM:
|
|
|
|
/* wait a little bit longer */
|
|
|
|
usleep(1500000);
|
|
|
|
res = ast_streamfile(mychannel, "rpt/callterminated", mychannel->language);
|
|
|
|
break;
|
|
|
|
case COMPLETE:
|
|
|
|
/* wait a little bit */
|
|
|
|
usleep(1000000);
|
|
|
|
res = ast_streamfile(mychannel, "rpt/functioncomplete", mychannel->language);
|
|
|
|
break;
|
|
|
|
case UNKEY:
|
|
|
|
/* wait a little bit */
|
|
|
|
usleep(1000000);
|
|
|
|
hastx = 0;
|
|
|
|
l = myrpt->links.next;
|
|
|
|
if (l != &myrpt->links)
|
|
|
|
{
|
|
|
|
ast_mutex_lock(&myrpt->lock);
|
|
|
|
while(l != &myrpt->links)
|
|
|
|
{
|
|
|
|
if (l->mode) hastx++;
|
|
|
|
l = l->next;
|
|
|
|
}
|
|
|
|
ast_mutex_unlock(&myrpt->lock);
|
|
|
|
res = ast_streamfile(mychannel,
|
|
|
|
((!hastx) ? "rpt/remote_monitor" : "rpt/remote_tx"),
|
|
|
|
mychannel->language);
|
|
|
|
if (!res)
|
|
|
|
res = ast_waitstream(mychannel, "");
|
|
|
|
else
|
|
|
|
ast_log(LOG_WARNING, "ast_streamfile failed on %s\n", mychannel->name);
|
|
|
|
ast_stopstream(mychannel);
|
|
|
|
}
|
|
|
|
/* if in remote cmd mode, indicate it */
|
|
|
|
if (myrpt->cmdnode[0])
|
|
|
|
{
|
|
|
|
ast_safe_sleep(mychannel,200);
|
|
|
|
res = ast_streamfile(mychannel, "rpt/remote_cmd", mychannel->language);
|
|
|
|
if (!res)
|
|
|
|
res = ast_waitstream(mychannel, "");
|
|
|
|
else
|
|
|
|
ast_log(LOG_WARNING, "ast_streamfile failed on %s\n", mychannel->name);
|
|
|
|
ast_stopstream(mychannel);
|
|
|
|
}
|
|
|
|
imdone = 1;
|
|
|
|
break;
|
|
|
|
case REMDISC:
|
|
|
|
/* wait a little bit */
|
|
|
|
usleep(1000000);
|
|
|
|
res = ast_streamfile(mychannel, "rpt/node", mychannel->language);
|
|
|
|
if (!res)
|
|
|
|
res = ast_waitstream(mychannel, "");
|
|
|
|
else
|
|
|
|
ast_log(LOG_WARNING, "ast_streamfile failed on %s\n", mychannel->name);
|
|
|
|
ast_stopstream(mychannel);
|
|
|
|
ast_say_character_str(mychannel,mytele->mylink.name,NULL,mychannel->language);
|
|
|
|
res = ast_streamfile(mychannel, ((mytele->mylink.connected) ?
|
|
|
|
"rpt/remote_disc" : "rpt/remote_busy"), mychannel->language);
|
|
|
|
break;
|
|
|
|
case REMALREADY:
|
|
|
|
/* wait a little bit */
|
|
|
|
usleep(1000000);
|
|
|
|
res = ast_streamfile(mychannel, "rpt/remote_already", mychannel->language);
|
|
|
|
break;
|
|
|
|
case REMNOTFOUND:
|
|
|
|
/* wait a little bit */
|
|
|
|
usleep(1000000);
|
|
|
|
res = ast_streamfile(mychannel, "rpt/remote_notfound", mychannel->language);
|
|
|
|
break;
|
|
|
|
case REMGO:
|
|
|
|
/* wait a little bit */
|
|
|
|
usleep(1000000);
|
|
|
|
res = ast_streamfile(mychannel, "rpt/remote_go", mychannel->language);
|
|
|
|
break;
|
|
|
|
case CONNECTED:
|
|
|
|
/* wait a little bit */
|
|
|
|
usleep(1000000);
|
|
|
|
res = ast_streamfile(mychannel, "rpt/node", mychannel->language);
|
|
|
|
if (!res)
|
|
|
|
res = ast_waitstream(mychannel, "");
|
|
|
|
else
|
|
|
|
ast_log(LOG_WARNING, "ast_streamfile failed on %s\n", mychannel->name);
|
|
|
|
ast_stopstream(mychannel);
|
|
|
|
ast_say_character_str(mychannel,mytele->mylink.name,NULL,mychannel->language);
|
|
|
|
res = ast_streamfile(mychannel, "rpt/connected", mychannel->language);
|
|
|
|
break;
|
|
|
|
case CONNFAIL:
|
|
|
|
res = ast_streamfile(mychannel, "rpt/node", mychannel->language);
|
|
|
|
if (!res)
|
|
|
|
res = ast_waitstream(mychannel, "");
|
|
|
|
else
|
|
|
|
ast_log(LOG_WARNING, "ast_streamfile failed on %s\n", mychannel->name);
|
|
|
|
ast_stopstream(mychannel);
|
|
|
|
ast_say_character_str(mychannel,mytele->mylink.name,NULL,mychannel->language);
|
|
|
|
res = ast_streamfile(mychannel, "rpt/connection_failed", mychannel->language);
|
|
|
|
break;
|
|
|
|
case STATUS:
|
|
|
|
/* wait a little bit */
|
|
|
|
usleep(1000000);
|
|
|
|
hastx = 0;
|
|
|
|
linkbase.next = &linkbase;
|
|
|
|
linkbase.prev = &linkbase;
|
|
|
|
ast_mutex_lock(&myrpt->lock);
|
|
|
|
/* make our own list of links */
|
|
|
|
l = myrpt->links.next;
|
|
|
|
while(l != &myrpt->links)
|
|
|
|
{
|
|
|
|
m = malloc(sizeof(struct rpt_link));
|
|
|
|
if (!m)
|
|
|
|
{
|
|
|
|
ast_log(LOG_WARNING, "Cannot alloc memory on %s\n", mychannel->name);
|
|
|
|
pthread_exit(NULL);
|
|
|
|
}
|
|
|
|
memcpy(m,l,sizeof(struct rpt_link));
|
|
|
|
m->next = m->prev = NULL;
|
|
|
|
insque((struct qelem *)m,(struct qelem *)linkbase.next);
|
|
|
|
l = l->next;
|
|
|
|
}
|
|
|
|
ast_mutex_unlock(&myrpt->lock);
|
|
|
|
res = ast_streamfile(mychannel, "rpt/node", mychannel->language);
|
|
|
|
if (!res)
|
|
|
|
res = ast_waitstream(mychannel, "");
|
|
|
|
else
|
|
|
|
ast_log(LOG_WARNING, "ast_streamfile failed on %s\n", mychannel->name);
|
|
|
|
ast_stopstream(mychannel);
|
|
|
|
ast_say_character_str(mychannel,myrpt->name,NULL,mychannel->language);
|
|
|
|
if (!res)
|
|
|
|
res = ast_waitstream(mychannel, "");
|
|
|
|
else
|
|
|
|
ast_log(LOG_WARNING, "ast_streamfile failed on %s\n", mychannel->name);
|
|
|
|
ast_stopstream(mychannel);
|
|
|
|
if (myrpt->callmode)
|
|
|
|
{
|
|
|
|
hastx = 1;
|
|
|
|
res = ast_streamfile(mychannel, "rpt/autopatch_on", mychannel->language);
|
|
|
|
if (!res)
|
|
|
|
res = ast_waitstream(mychannel, "");
|
|
|
|
else
|
|
|
|
ast_log(LOG_WARNING, "ast_streamfile failed on %s\n", mychannel->name);
|
|
|
|
ast_stopstream(mychannel);
|
|
|
|
}
|
|
|
|
l = linkbase.next;
|
|
|
|
while(l != &linkbase)
|
|
|
|
{
|
|
|
|
hastx = 1;
|
|
|
|
res = ast_streamfile(mychannel, "rpt/node", mychannel->language);
|
|
|
|
if (!res)
|
|
|
|
res = ast_waitstream(mychannel, "");
|
|
|
|
else
|
|
|
|
ast_log(LOG_WARNING, "ast_streamfile failed on %s\n", mychannel->name);
|
|
|
|
ast_stopstream(mychannel);
|
|
|
|
ast_say_character_str(mychannel,l->name,NULL,mychannel->language);
|
|
|
|
if (!res)
|
|
|
|
res = ast_waitstream(mychannel, "");
|
|
|
|
else
|
|
|
|
ast_log(LOG_WARNING, "ast_streamfile failed on %s\n", mychannel->name);
|
|
|
|
ast_stopstream(mychannel);
|
|
|
|
res = ast_streamfile(mychannel, ((l->mode) ?
|
|
|
|
"rpt/tranceive" : "rpt/monitor"), mychannel->language);
|
|
|
|
if (!res)
|
|
|
|
res = ast_waitstream(mychannel, "");
|
|
|
|
else
|
|
|
|
ast_log(LOG_WARNING, "ast_streamfile failed on %s\n", mychannel->name);
|
|
|
|
ast_stopstream(mychannel);
|
|
|
|
l = l->next;
|
|
|
|
}
|
|
|
|
if (!hastx)
|
|
|
|
{
|
|
|
|
res = ast_streamfile(mychannel, "rpt/repeat_only", mychannel->language);
|
|
|
|
if (!res)
|
|
|
|
res = ast_waitstream(mychannel, "");
|
|
|
|
else
|
|
|
|
ast_log(LOG_WARNING, "ast_streamfile failed on %s\n", mychannel->name);
|
|
|
|
ast_stopstream(mychannel);
|
|
|
|
}
|
|
|
|
/* destroy our local link queue */
|
|
|
|
l = linkbase.next;
|
|
|
|
while(l != &linkbase)
|
|
|
|
{
|
|
|
|
m = l;
|
|
|
|
l = l->next;
|
|
|
|
remque((struct qelem *)m);
|
|
|
|
free(m);
|
|
|
|
}
|
|
|
|
imdone = 1;
|
|
|
|
break;
|
2004-06-25 19:33:22 +00:00
|
|
|
case TIMEOUT:
|
|
|
|
res = ast_streamfile(mychannel, "rpt/node", mychannel->language);
|
|
|
|
if (!res)
|
|
|
|
res = ast_waitstream(mychannel, "");
|
|
|
|
else
|
|
|
|
ast_log(LOG_WARNING, "ast_streamfile failed on %s\n", mychannel->name);
|
|
|
|
ast_stopstream(mychannel);
|
|
|
|
ast_say_character_str(mychannel,myrpt->name,NULL,mychannel->language);
|
|
|
|
res = ast_streamfile(mychannel, "rpt/timeout", mychannel->language);
|
|
|
|
break;
|
2004-05-31 16:04:10 +00:00
|
|
|
}
|
2004-06-21 04:24:50 +00:00
|
|
|
if (!imdone)
|
2004-05-31 16:04:10 +00:00
|
|
|
{
|
2004-06-21 04:24:50 +00:00
|
|
|
if (!res)
|
|
|
|
res = ast_waitstream(mychannel, "");
|
|
|
|
else {
|
|
|
|
ast_log(LOG_WARNING, "ast_streamfile failed on %s\n", mychannel->name);
|
|
|
|
res = 0;
|
|
|
|
}
|
2004-05-31 16:04:10 +00:00
|
|
|
}
|
|
|
|
ast_stopstream(mychannel);
|
2004-06-21 04:24:50 +00:00
|
|
|
ast_mutex_lock(&myrpt->lock);
|
|
|
|
remque((struct qelem *)mytele);
|
|
|
|
ast_mutex_unlock(&myrpt->lock);
|
|
|
|
free(mytele);
|
2004-05-31 16:04:10 +00:00
|
|
|
ast_hangup(mychannel);
|
|
|
|
pthread_exit(NULL);
|
|
|
|
}
|
|
|
|
|
2004-06-21 04:24:50 +00:00
|
|
|
static void rpt_telemetry(struct rpt *myrpt,int mode,struct rpt_link *mylink)
|
2004-05-31 16:04:10 +00:00
|
|
|
{
|
2004-06-21 04:24:50 +00:00
|
|
|
struct rpt_tele *tele;
|
|
|
|
pthread_attr_t attr;
|
2004-05-31 16:04:10 +00:00
|
|
|
|
2004-06-21 04:24:50 +00:00
|
|
|
tele = malloc(sizeof(struct rpt_tele));
|
|
|
|
if (!tele)
|
2004-05-31 16:04:10 +00:00
|
|
|
{
|
2004-06-21 04:24:50 +00:00
|
|
|
ast_log(LOG_WARNING, "Unable to allocate memory\n");
|
2004-05-31 16:04:10 +00:00
|
|
|
pthread_exit(NULL);
|
2004-06-21 04:24:50 +00:00
|
|
|
return;
|
2004-05-31 16:04:10 +00:00
|
|
|
}
|
2004-06-21 04:24:50 +00:00
|
|
|
/* zero it out */
|
|
|
|
memset((char *)tele,0,sizeof(struct rpt_tele));
|
|
|
|
tele->rpt = myrpt;
|
|
|
|
tele->mode = mode;
|
|
|
|
ast_mutex_lock(&myrpt->lock);
|
|
|
|
memset(&tele->mylink,0,sizeof(struct rpt_link));
|
|
|
|
if (mylink)
|
2004-05-31 16:04:10 +00:00
|
|
|
{
|
2004-06-21 04:24:50 +00:00
|
|
|
memcpy(&tele->mylink,mylink,sizeof(struct rpt_link));
|
|
|
|
}
|
|
|
|
insque((struct qelem *)tele,(struct qelem *)myrpt->tele.next);
|
|
|
|
ast_mutex_unlock(&myrpt->lock);
|
|
|
|
pthread_attr_init(&attr);
|
|
|
|
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
|
|
|
|
pthread_create(&tele->threadid,&attr,rpt_tele_thread,(void *) tele);
|
|
|
|
return;
|
2004-05-31 16:04:10 +00:00
|
|
|
}
|
|
|
|
|
2004-06-26 18:06:17 +00:00
|
|
|
static int sayfile(struct ast_channel *mychannel,char *fname)
|
|
|
|
{
|
|
|
|
int res;
|
|
|
|
|
|
|
|
res = ast_streamfile(mychannel, fname, mychannel->language);
|
|
|
|
if (!res)
|
|
|
|
res = ast_waitstream(mychannel, "");
|
|
|
|
else
|
|
|
|
ast_log(LOG_WARNING, "ast_streamfile failed on %s\n", mychannel->name);
|
|
|
|
ast_stopstream(mychannel);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int saycharstr(struct ast_channel *mychannel,char *str)
|
|
|
|
{
|
|
|
|
int res;
|
|
|
|
|
|
|
|
res = ast_say_character_str(mychannel,str,NULL,mychannel->language);
|
|
|
|
if (!res)
|
|
|
|
res = ast_waitstream(mychannel, "");
|
|
|
|
else
|
|
|
|
ast_log(LOG_WARNING, "ast_streamfile failed on %s\n", mychannel->name);
|
|
|
|
ast_stopstream(mychannel);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2002-12-08 17:30:24 +00:00
|
|
|
static void *rpt_call(void *this)
|
|
|
|
{
|
|
|
|
ZT_CONFINFO ci; /* conference info */
|
|
|
|
struct rpt *myrpt = (struct rpt *)this;
|
|
|
|
int res;
|
|
|
|
struct ast_frame *f,wf;
|
|
|
|
int stopped,congstarted;
|
|
|
|
struct ast_channel *mychannel,*genchannel;
|
|
|
|
|
|
|
|
myrpt->mydtmf = 0;
|
|
|
|
/* allocate a pseudo-channel thru asterisk */
|
|
|
|
mychannel = ast_request("zap",AST_FORMAT_SLINEAR,"pseudo");
|
|
|
|
if (!mychannel)
|
|
|
|
{
|
|
|
|
fprintf(stderr,"rpt:Sorry unable to obtain pseudo channel\n");
|
|
|
|
pthread_exit(NULL);
|
|
|
|
}
|
|
|
|
ci.chan = 0;
|
2004-06-21 04:24:50 +00:00
|
|
|
ci.confno = myrpt->conf; /* use the pseudo conference */
|
2002-12-08 17:30:24 +00:00
|
|
|
ci.confmode = ZT_CONF_REALANDPSEUDO | ZT_CONF_TALKER | ZT_CONF_LISTENER
|
|
|
|
| ZT_CONF_PSEUDO_TALKER | ZT_CONF_PSEUDO_LISTENER;
|
|
|
|
/* first put the channel on the conference */
|
|
|
|
if (ioctl(mychannel->fds[0],ZT_SETCONF,&ci) == -1)
|
|
|
|
{
|
|
|
|
ast_log(LOG_WARNING, "Unable to set conference mode to Announce\n");
|
|
|
|
ast_hangup(mychannel);
|
|
|
|
myrpt->callmode = 0;
|
|
|
|
pthread_exit(NULL);
|
|
|
|
}
|
|
|
|
/* allocate a pseudo-channel thru asterisk */
|
|
|
|
genchannel = ast_request("zap",AST_FORMAT_SLINEAR,"pseudo");
|
|
|
|
if (!genchannel)
|
|
|
|
{
|
|
|
|
fprintf(stderr,"rpt:Sorry unable to obtain pseudo channel\n");
|
|
|
|
ast_hangup(mychannel);
|
|
|
|
pthread_exit(NULL);
|
|
|
|
}
|
|
|
|
ci.chan = 0;
|
2004-06-21 04:24:50 +00:00
|
|
|
ci.confno = myrpt->conf;
|
2002-12-08 17:30:24 +00:00
|
|
|
ci.confmode = ZT_CONF_REALANDPSEUDO | ZT_CONF_TALKER | ZT_CONF_LISTENER
|
|
|
|
| ZT_CONF_PSEUDO_TALKER | ZT_CONF_PSEUDO_LISTENER;
|
|
|
|
/* first put the channel on the conference */
|
|
|
|
if (ioctl(genchannel->fds[0],ZT_SETCONF,&ci) == -1)
|
|
|
|
{
|
|
|
|
ast_log(LOG_WARNING, "Unable to set conference mode to Announce\n");
|
|
|
|
ast_hangup(mychannel);
|
|
|
|
ast_hangup(genchannel);
|
|
|
|
myrpt->callmode = 0;
|
|
|
|
pthread_exit(NULL);
|
|
|
|
}
|
2004-05-31 16:04:10 +00:00
|
|
|
if (myrpt->tonezone && (tone_zone_set_zone(mychannel->fds[0],myrpt->tonezone) == -1))
|
|
|
|
{
|
|
|
|
ast_log(LOG_WARNING, "Unable to set tone zone %s\n",myrpt->tonezone);
|
|
|
|
ast_hangup(mychannel);
|
|
|
|
ast_hangup(genchannel);
|
|
|
|
myrpt->callmode = 0;
|
|
|
|
pthread_exit(NULL);
|
|
|
|
}
|
|
|
|
if (myrpt->tonezone && (tone_zone_set_zone(genchannel->fds[0],myrpt->tonezone) == -1))
|
|
|
|
{
|
|
|
|
ast_log(LOG_WARNING, "Unable to set tone zone %s\n",myrpt->tonezone);
|
|
|
|
ast_hangup(mychannel);
|
|
|
|
ast_hangup(genchannel);
|
|
|
|
myrpt->callmode = 0;
|
|
|
|
pthread_exit(NULL);
|
|
|
|
}
|
2002-12-08 17:30:24 +00:00
|
|
|
/* start dialtone */
|
|
|
|
if (tone_zone_play_tone(mychannel->fds[0],ZT_TONE_DIALTONE) < 0)
|
|
|
|
{
|
|
|
|
ast_log(LOG_WARNING, "Cannot start dialtone\n");
|
|
|
|
ast_hangup(mychannel);
|
|
|
|
ast_hangup(genchannel);
|
|
|
|
myrpt->callmode = 0;
|
|
|
|
pthread_exit(NULL);
|
|
|
|
}
|
|
|
|
stopped = 0;
|
|
|
|
congstarted = 0;
|
|
|
|
while ((myrpt->callmode == 1) || (myrpt->callmode == 4))
|
|
|
|
{
|
|
|
|
|
|
|
|
if ((myrpt->callmode == 1) && (myrpt->cidx > 0) && (!stopped))
|
|
|
|
{
|
|
|
|
stopped = 1;
|
|
|
|
/* stop dial tone */
|
|
|
|
tone_zone_play_tone(mychannel->fds[0],-1);
|
|
|
|
}
|
|
|
|
if ((myrpt->callmode == 4) && (!congstarted))
|
|
|
|
{
|
|
|
|
congstarted = 1;
|
|
|
|
/* start congestion tone */
|
|
|
|
tone_zone_play_tone(mychannel->fds[0],ZT_TONE_CONGESTION);
|
|
|
|
}
|
|
|
|
res = ast_waitfor(mychannel, MSWAIT);
|
|
|
|
if (res < 0)
|
|
|
|
{
|
|
|
|
ast_hangup(mychannel);
|
|
|
|
ast_hangup(genchannel);
|
2004-06-21 04:24:50 +00:00
|
|
|
ast_mutex_lock(&myrpt->lock);
|
2002-12-08 17:30:24 +00:00
|
|
|
myrpt->callmode = 0;
|
2004-06-21 04:24:50 +00:00
|
|
|
ast_mutex_unlock(&myrpt->lock);
|
2002-12-08 17:30:24 +00:00
|
|
|
pthread_exit(NULL);
|
|
|
|
}
|
|
|
|
if (res == 0) continue;
|
|
|
|
f = ast_read(mychannel);
|
|
|
|
if (f == NULL)
|
|
|
|
{
|
|
|
|
ast_hangup(mychannel);
|
|
|
|
ast_hangup(genchannel);
|
2004-06-21 04:24:50 +00:00
|
|
|
ast_mutex_lock(&myrpt->lock);
|
2002-12-08 17:30:24 +00:00
|
|
|
myrpt->callmode = 0;
|
2004-06-21 04:24:50 +00:00
|
|
|
ast_mutex_unlock(&myrpt->lock);
|
2002-12-08 17:30:24 +00:00
|
|
|
pthread_exit(NULL);
|
|
|
|
}
|
|
|
|
if ((f->frametype == AST_FRAME_CONTROL) &&
|
|
|
|
(f->subclass == AST_CONTROL_HANGUP))
|
|
|
|
{
|
|
|
|
ast_frfree(f);
|
|
|
|
ast_hangup(mychannel);
|
|
|
|
ast_hangup(genchannel);
|
2004-06-21 04:24:50 +00:00
|
|
|
ast_mutex_lock(&myrpt->lock);
|
2002-12-08 17:30:24 +00:00
|
|
|
myrpt->callmode = 0;
|
2004-06-21 04:24:50 +00:00
|
|
|
ast_mutex_unlock(&myrpt->lock);
|
2002-12-08 17:30:24 +00:00
|
|
|
pthread_exit(NULL);
|
|
|
|
}
|
|
|
|
ast_frfree(f);
|
|
|
|
}
|
|
|
|
/* stop any tone generation */
|
|
|
|
tone_zone_play_tone(mychannel->fds[0],-1);
|
|
|
|
/* end if done */
|
|
|
|
if (!myrpt->callmode)
|
|
|
|
{
|
|
|
|
ast_hangup(mychannel);
|
|
|
|
ast_hangup(genchannel);
|
2004-06-21 04:24:50 +00:00
|
|
|
ast_mutex_lock(&myrpt->lock);
|
2002-12-08 17:30:24 +00:00
|
|
|
myrpt->callmode = 0;
|
2004-06-21 04:24:50 +00:00
|
|
|
ast_mutex_unlock(&myrpt->lock);
|
2002-12-08 17:30:24 +00:00
|
|
|
pthread_exit(NULL);
|
|
|
|
}
|
|
|
|
if (myrpt->ourcallerid && *myrpt->ourcallerid)
|
|
|
|
{
|
|
|
|
if (mychannel->callerid) free(mychannel->callerid);
|
|
|
|
mychannel->callerid = strdup(myrpt->ourcallerid);
|
|
|
|
}
|
|
|
|
strcpy(mychannel->exten,myrpt->exten);
|
|
|
|
strcpy(mychannel->context,myrpt->ourcontext);
|
|
|
|
if (myrpt->acctcode)
|
|
|
|
strcpy(mychannel->accountcode,myrpt->acctcode);
|
|
|
|
mychannel->priority = 1;
|
|
|
|
ast_channel_undefer_dtmf(mychannel);
|
|
|
|
if (ast_pbx_start(mychannel) < 0)
|
|
|
|
{
|
|
|
|
ast_log(LOG_WARNING, "Unable to start PBX!!\n");
|
|
|
|
ast_hangup(mychannel);
|
|
|
|
ast_hangup(genchannel);
|
2004-06-21 04:24:50 +00:00
|
|
|
ast_mutex_lock(&myrpt->lock);
|
2002-12-08 17:30:24 +00:00
|
|
|
myrpt->callmode = 0;
|
2004-06-21 04:24:50 +00:00
|
|
|
ast_mutex_unlock(&myrpt->lock);
|
2002-12-08 17:30:24 +00:00
|
|
|
pthread_exit(NULL);
|
|
|
|
}
|
2004-06-21 04:24:50 +00:00
|
|
|
ast_mutex_lock(&myrpt->lock);
|
2002-12-08 17:30:24 +00:00
|
|
|
myrpt->callmode = 3;
|
|
|
|
while(myrpt->callmode)
|
|
|
|
{
|
|
|
|
if ((!mychannel->pvt) && (myrpt->callmode != 4))
|
|
|
|
{
|
|
|
|
myrpt->callmode = 4;
|
2004-06-21 04:24:50 +00:00
|
|
|
ast_mutex_unlock(&myrpt->lock);
|
2002-12-08 17:30:24 +00:00
|
|
|
/* start congestion tone */
|
|
|
|
tone_zone_play_tone(genchannel->fds[0],ZT_TONE_CONGESTION);
|
2004-06-21 04:24:50 +00:00
|
|
|
ast_mutex_lock(&myrpt->lock);
|
2002-12-08 17:30:24 +00:00
|
|
|
}
|
|
|
|
if (myrpt->mydtmf)
|
|
|
|
{
|
|
|
|
wf.frametype = AST_FRAME_DTMF;
|
|
|
|
wf.subclass = myrpt->mydtmf;
|
|
|
|
wf.offset = 0;
|
|
|
|
wf.mallocd = 0;
|
|
|
|
wf.data = NULL;
|
|
|
|
wf.datalen = 0;
|
|
|
|
wf.samples = 0;
|
2004-06-21 04:24:50 +00:00
|
|
|
ast_mutex_unlock(&myrpt->lock);
|
2002-12-08 17:30:24 +00:00
|
|
|
ast_write(genchannel,&wf);
|
2004-06-21 04:24:50 +00:00
|
|
|
ast_mutex_lock(&myrpt->lock);
|
2002-12-08 17:30:24 +00:00
|
|
|
myrpt->mydtmf = 0;
|
|
|
|
}
|
2004-06-21 04:24:50 +00:00
|
|
|
ast_mutex_unlock(&myrpt->lock);
|
2002-12-08 17:30:24 +00:00
|
|
|
usleep(25000);
|
2004-06-21 04:24:50 +00:00
|
|
|
ast_mutex_lock(&myrpt->lock);
|
2002-12-08 17:30:24 +00:00
|
|
|
}
|
2004-06-21 04:24:50 +00:00
|
|
|
ast_mutex_unlock(&myrpt->lock);
|
2002-12-08 17:30:24 +00:00
|
|
|
tone_zone_play_tone(genchannel->fds[0],-1);
|
|
|
|
if (mychannel->pvt) ast_softhangup(mychannel,AST_SOFTHANGUP_DEV);
|
|
|
|
ast_hangup(genchannel);
|
2004-06-21 04:24:50 +00:00
|
|
|
ast_mutex_lock(&myrpt->lock);
|
2002-12-08 17:30:24 +00:00
|
|
|
myrpt->callmode = 0;
|
2004-06-21 04:24:50 +00:00
|
|
|
ast_mutex_unlock(&myrpt->lock);
|
2002-12-08 17:30:24 +00:00
|
|
|
pthread_exit(NULL);
|
|
|
|
}
|
|
|
|
|
2004-06-21 04:24:50 +00:00
|
|
|
static void send_link_dtmf(struct rpt *myrpt,char c)
|
|
|
|
{
|
|
|
|
char str[300];
|
|
|
|
struct ast_frame wf;
|
|
|
|
struct rpt_link *l;
|
|
|
|
|
|
|
|
sprintf(str,"D %s %s %d %c",myrpt->cmdnode,myrpt->name,++(myrpt->dtmfidx),c);
|
|
|
|
wf.frametype = AST_FRAME_TEXT;
|
|
|
|
wf.subclass = 0;
|
|
|
|
wf.offset = 0;
|
|
|
|
wf.mallocd = 1;
|
|
|
|
wf.datalen = strlen(str) + 1;
|
|
|
|
wf.samples = 0;
|
|
|
|
l = myrpt->links.next;
|
|
|
|
/* first, see if our dude is there */
|
|
|
|
while(l != &myrpt->links)
|
|
|
|
{
|
2004-06-25 19:33:22 +00:00
|
|
|
/* if we found it, write it and were done */
|
|
|
|
if (!strcmp(l->name,myrpt->cmdnode))
|
2004-06-21 04:24:50 +00:00
|
|
|
{
|
2004-06-25 19:33:22 +00:00
|
|
|
wf.data = strdup(str);
|
|
|
|
ast_write(l->chan,&wf);
|
|
|
|
return;
|
2004-06-21 04:24:50 +00:00
|
|
|
}
|
|
|
|
l = l->next;
|
|
|
|
}
|
|
|
|
l = myrpt->links.next;
|
|
|
|
/* if not, give it to everyone */
|
|
|
|
while(l != &myrpt->links)
|
|
|
|
{
|
2004-06-25 19:33:22 +00:00
|
|
|
wf.data = strdup(str);
|
|
|
|
ast_write(l->chan,&wf);
|
2004-06-21 04:24:50 +00:00
|
|
|
l = l->next;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void process_dtmf(char *cmd,struct rpt *myrpt, int allow_linkcmd)
|
2004-05-31 16:04:10 +00:00
|
|
|
{
|
|
|
|
pthread_attr_t attr;
|
2004-06-21 04:24:50 +00:00
|
|
|
char *tele,tmp[300],deststr[300],*val,*s,*s1;
|
|
|
|
struct rpt_link *l;
|
2004-05-31 16:04:10 +00:00
|
|
|
ZT_CONFINFO ci; /* conference info */
|
|
|
|
|
2004-06-21 04:24:50 +00:00
|
|
|
switch(atoi(cmd) / 1000)
|
2004-05-31 16:04:10 +00:00
|
|
|
{
|
2004-06-21 04:24:50 +00:00
|
|
|
case 6: /* autopatch on / send asterisk (*) */
|
2004-06-25 19:33:22 +00:00
|
|
|
if (!myrpt->enable) return;
|
2004-06-21 04:24:50 +00:00
|
|
|
ast_mutex_lock(&myrpt->lock);
|
2004-05-31 16:04:10 +00:00
|
|
|
/* if on call, force * into current audio stream */
|
|
|
|
if ((myrpt->callmode == 2) || (myrpt->callmode == 3))
|
|
|
|
{
|
|
|
|
myrpt->mydtmf = '*';
|
2004-06-21 04:24:50 +00:00
|
|
|
ast_mutex_unlock(&myrpt->lock);
|
2004-05-31 16:04:10 +00:00
|
|
|
break;
|
|
|
|
}
|
2004-06-21 04:24:50 +00:00
|
|
|
if (myrpt->callmode)
|
|
|
|
{
|
|
|
|
ast_mutex_unlock(&myrpt->lock);
|
|
|
|
return;
|
|
|
|
}
|
2004-05-31 16:04:10 +00:00
|
|
|
myrpt->callmode = 1;
|
|
|
|
myrpt->cidx = 0;
|
|
|
|
myrpt->exten[myrpt->cidx] = 0;
|
2004-06-21 04:24:50 +00:00
|
|
|
ast_mutex_unlock(&myrpt->lock);
|
2004-05-31 16:04:10 +00:00
|
|
|
pthread_attr_init(&attr);
|
|
|
|
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
|
2004-06-21 04:24:50 +00:00
|
|
|
pthread_create(&myrpt->rpt_call_thread,&attr,rpt_call,(void *) myrpt);
|
|
|
|
return;
|
|
|
|
case 0: /* autopatch off */
|
2004-06-25 19:33:22 +00:00
|
|
|
if (!myrpt->enable) return;
|
2004-06-21 04:24:50 +00:00
|
|
|
ast_mutex_lock(&myrpt->lock);
|
|
|
|
if (!myrpt->callmode)
|
|
|
|
{
|
|
|
|
ast_mutex_unlock(&myrpt->lock);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
myrpt->callmode = 0;
|
|
|
|
ast_mutex_unlock(&myrpt->lock);
|
|
|
|
rpt_telemetry(myrpt,TERM,NULL);
|
2004-05-31 16:04:10 +00:00
|
|
|
return;
|
2004-06-25 19:33:22 +00:00
|
|
|
case 9: /* system control group */
|
|
|
|
/* if invalid, just ignore */
|
|
|
|
if ((cmd[1] >= '2') && (cmd[1] <= '8')) return;
|
2004-06-21 04:24:50 +00:00
|
|
|
ast_mutex_lock(&myrpt->lock);
|
2004-06-25 19:33:22 +00:00
|
|
|
if (cmd[1] == '1') /* system enable */
|
|
|
|
{
|
|
|
|
myrpt->enable = 1;
|
|
|
|
}
|
|
|
|
if (cmd[1] == '0') /* system disable */
|
|
|
|
{
|
|
|
|
myrpt->enable = 0;
|
|
|
|
}
|
|
|
|
/* reset system */
|
2004-05-31 16:04:10 +00:00
|
|
|
myrpt->callmode = 0;
|
2004-06-21 04:24:50 +00:00
|
|
|
ast_mutex_unlock(&myrpt->lock);
|
|
|
|
l = myrpt->links.next;
|
|
|
|
/* disconnect all of the remote stuff */
|
|
|
|
while(l != &myrpt->links)
|
|
|
|
{
|
|
|
|
ast_softhangup(l->chan,AST_SOFTHANGUP_DEV);
|
|
|
|
l = l->next;
|
|
|
|
}
|
|
|
|
break;
|
2004-05-31 16:04:10 +00:00
|
|
|
case 1: /* remote base off */
|
2004-06-25 19:33:22 +00:00
|
|
|
if (!myrpt->enable) return;
|
2004-06-21 04:24:50 +00:00
|
|
|
val = ast_variable_retrieve(cfg,NODES,cmd + 1);
|
|
|
|
if (!val)
|
2004-05-31 16:04:10 +00:00
|
|
|
{
|
2004-06-21 04:24:50 +00:00
|
|
|
rpt_telemetry(myrpt,REMNOTFOUND,NULL);
|
|
|
|
return;
|
2004-05-31 16:04:10 +00:00
|
|
|
}
|
2004-06-21 04:24:50 +00:00
|
|
|
strncpy(tmp,val,sizeof(tmp) - 1);
|
|
|
|
s = tmp;
|
|
|
|
s1 = strsep(&s,",");
|
|
|
|
ast_mutex_lock(&myrpt->lock);
|
|
|
|
l = myrpt->links.next;
|
|
|
|
/* try to find this one in queue */
|
|
|
|
while(l != &myrpt->links)
|
2004-05-31 16:04:10 +00:00
|
|
|
{
|
2004-06-21 04:24:50 +00:00
|
|
|
/* if found matching string */
|
|
|
|
if (!strcmp(l->name,cmd + 1)) break;
|
|
|
|
l = l->next;
|
2004-05-31 16:04:10 +00:00
|
|
|
}
|
2004-06-21 04:24:50 +00:00
|
|
|
if (l != &myrpt->links) /* if found */
|
|
|
|
{
|
|
|
|
ast_mutex_unlock(&myrpt->lock);
|
|
|
|
ast_softhangup(l->chan,AST_SOFTHANGUP_DEV);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ast_mutex_unlock(&myrpt->lock);
|
|
|
|
return;
|
2004-05-31 16:04:10 +00:00
|
|
|
case 2: /* remote base monitor */
|
2004-06-25 19:33:22 +00:00
|
|
|
if (!myrpt->enable) return;
|
2004-06-21 04:24:50 +00:00
|
|
|
val = ast_variable_retrieve(cfg,NODES,cmd + 1);
|
|
|
|
if (!val)
|
|
|
|
{
|
|
|
|
rpt_telemetry(myrpt,REMNOTFOUND,NULL);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
strncpy(tmp,val,sizeof(tmp) - 1);
|
|
|
|
s = tmp;
|
|
|
|
s1 = strsep(&s,",");
|
|
|
|
ast_mutex_lock(&myrpt->lock);
|
|
|
|
l = myrpt->links.next;
|
|
|
|
/* try to find this one in queue */
|
|
|
|
while(l != &myrpt->links)
|
|
|
|
{
|
|
|
|
/* if found matching string */
|
|
|
|
if (!strcmp(l->name,cmd + 1)) break;
|
|
|
|
l = l->next;
|
|
|
|
}
|
|
|
|
/* if found */
|
|
|
|
if (l != &myrpt->links)
|
|
|
|
{
|
|
|
|
/* if already in this mode, just ignore */
|
|
|
|
if (!l->mode) {
|
|
|
|
ast_mutex_unlock(&myrpt->lock);
|
|
|
|
rpt_telemetry(myrpt,REMALREADY,NULL);
|
|
|
|
return;
|
2004-05-31 16:04:10 +00:00
|
|
|
}
|
2004-06-21 04:24:50 +00:00
|
|
|
ast_softhangup(l->chan,AST_SOFTHANGUP_DEV);
|
|
|
|
usleep(500000);
|
|
|
|
}
|
|
|
|
ast_mutex_unlock(&myrpt->lock);
|
|
|
|
/* establish call in monitor mode */
|
|
|
|
l = malloc(sizeof(struct rpt_link));
|
|
|
|
if (!l)
|
|
|
|
{
|
|
|
|
ast_log(LOG_WARNING, "Unable to malloc\n");
|
|
|
|
pthread_exit(NULL);
|
|
|
|
}
|
|
|
|
/* zero the silly thing */
|
|
|
|
memset((char *)l,0,sizeof(struct rpt_link));
|
|
|
|
sprintf(deststr,"IAX2/%s",s1);
|
|
|
|
tele = strchr(deststr,'/');
|
|
|
|
if (!tele)
|
|
|
|
{
|
|
|
|
fprintf(stderr,"rpt:Dial number (%s) must be in format tech/number\n",deststr);
|
|
|
|
pthread_exit(NULL);
|
|
|
|
}
|
|
|
|
*tele++ = 0;
|
|
|
|
l->isremote = (s && ast_true(s));
|
|
|
|
strncpy(l->name,cmd + 1,MAXNODESTR - 1);
|
|
|
|
l->chan = ast_request(deststr,AST_FORMAT_SLINEAR,tele);
|
|
|
|
if (l->chan)
|
|
|
|
{
|
|
|
|
ast_set_read_format(l->chan,AST_FORMAT_SLINEAR);
|
|
|
|
ast_set_write_format(l->chan,AST_FORMAT_SLINEAR);
|
|
|
|
l->chan->whentohangup = 0;
|
|
|
|
l->chan->appl = "Apprpt";
|
|
|
|
l->chan->data = "(Remote Rx)";
|
|
|
|
if (option_verbose > 2)
|
|
|
|
ast_verbose(VERBOSE_PREFIX_3 "rpt (remote) initiating call to %s/%s on %s\n",
|
|
|
|
deststr,tele,l->chan->name);
|
|
|
|
l->chan->callerid = strdup(myrpt->name);
|
|
|
|
ast_call(l->chan,tele,0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
free(l);
|
|
|
|
if (option_verbose > 2)
|
|
|
|
ast_verbose(VERBOSE_PREFIX_3 "Unable to place call to %s/%s on %s\n",
|
|
|
|
deststr,tele,l->chan->name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* allocate a pseudo-channel thru asterisk */
|
|
|
|
l->pchan = ast_request("zap",AST_FORMAT_SLINEAR,"pseudo");
|
|
|
|
if (!l->pchan)
|
|
|
|
{
|
|
|
|
fprintf(stderr,"rpt:Sorry unable to obtain pseudo channel\n");
|
|
|
|
pthread_exit(NULL);
|
|
|
|
}
|
|
|
|
ast_set_read_format(l->pchan,AST_FORMAT_SLINEAR);
|
|
|
|
ast_set_write_format(l->pchan,AST_FORMAT_SLINEAR);
|
|
|
|
/* make a conference for the pseudo-one */
|
|
|
|
ci.chan = 0;
|
|
|
|
ci.confno = myrpt->conf;
|
|
|
|
ci.confmode = ZT_CONF_CONF | ZT_CONF_LISTENER | ZT_CONF_TALKER;
|
|
|
|
/* first put the channel on the conference in proper mode */
|
|
|
|
if (ioctl(l->pchan->fds[0],ZT_SETCONF,&ci) == -1)
|
|
|
|
{
|
|
|
|
ast_log(LOG_WARNING, "Unable to set conference mode to Announce\n");
|
|
|
|
pthread_exit(NULL);
|
2004-05-31 16:04:10 +00:00
|
|
|
}
|
2004-06-21 04:24:50 +00:00
|
|
|
ast_mutex_lock(&myrpt->lock);
|
|
|
|
/* insert at end of queue */
|
|
|
|
insque((struct qelem *)l,(struct qelem *)myrpt->links.next);
|
|
|
|
ast_mutex_unlock(&myrpt->lock);
|
2004-05-31 16:04:10 +00:00
|
|
|
break;
|
|
|
|
case 3: /* remote base tranceieve */
|
2004-06-25 19:33:22 +00:00
|
|
|
if (!myrpt->enable) return;
|
2004-06-21 04:24:50 +00:00
|
|
|
val = ast_variable_retrieve(cfg,NODES,cmd + 1);
|
|
|
|
if (!val)
|
|
|
|
{
|
|
|
|
rpt_telemetry(myrpt,REMNOTFOUND,NULL);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
strncpy(tmp,val,sizeof(tmp) - 1);
|
|
|
|
s = tmp;
|
|
|
|
s1 = strsep(&s,",");
|
|
|
|
ast_mutex_lock(&myrpt->lock);
|
|
|
|
l = myrpt->links.next;
|
|
|
|
/* try to find this one in queue */
|
|
|
|
while(l != &myrpt->links)
|
|
|
|
{
|
|
|
|
/* if found matching string */
|
|
|
|
if (!strcmp(l->name,cmd + 1)) break;
|
2004-06-25 19:33:22 +00:00
|
|
|
l = l->next;
|
2004-06-21 04:24:50 +00:00
|
|
|
}
|
|
|
|
/* if found */
|
|
|
|
if (l != &myrpt->links)
|
|
|
|
{
|
|
|
|
/* if already in this mode, just ignore */
|
|
|
|
if (l->mode)
|
2004-05-31 16:04:10 +00:00
|
|
|
{
|
2004-06-21 04:24:50 +00:00
|
|
|
ast_mutex_unlock(&myrpt->lock);
|
|
|
|
rpt_telemetry(myrpt,REMALREADY,NULL);
|
|
|
|
return;
|
2004-05-31 16:04:10 +00:00
|
|
|
}
|
2004-06-21 04:24:50 +00:00
|
|
|
ast_softhangup(l->chan,AST_SOFTHANGUP_DEV);
|
|
|
|
usleep(500000);
|
2004-05-31 16:04:10 +00:00
|
|
|
}
|
2004-06-21 04:24:50 +00:00
|
|
|
ast_mutex_unlock(&myrpt->lock);
|
|
|
|
/* establish call in tranceive mode */
|
|
|
|
l = malloc(sizeof(struct rpt_link));
|
|
|
|
if (!l)
|
|
|
|
{
|
|
|
|
ast_log(LOG_WARNING, "Unable to malloc\n");
|
|
|
|
pthread_exit(NULL);
|
|
|
|
}
|
|
|
|
/* zero the silly thing */
|
|
|
|
memset((char *)l,0,sizeof(struct rpt_link));
|
|
|
|
l->mode = 1;
|
|
|
|
strncpy(l->name,cmd + 1,MAXNODESTR - 1);
|
|
|
|
l->isremote = (s && ast_true(s));
|
|
|
|
sprintf(deststr,"IAX2/%s",s1);
|
|
|
|
tele = strchr(deststr,'/');
|
|
|
|
if (!tele)
|
|
|
|
{
|
|
|
|
fprintf(stderr,"rpt:Dial number must be in format tech/number\n");
|
|
|
|
pthread_exit(NULL);
|
|
|
|
}
|
|
|
|
*tele++ = 0;
|
|
|
|
l->chan = ast_request(deststr,AST_FORMAT_SLINEAR,tele);
|
|
|
|
if (l->chan)
|
|
|
|
{
|
|
|
|
ast_set_read_format(l->chan,AST_FORMAT_SLINEAR);
|
|
|
|
ast_set_write_format(l->chan,AST_FORMAT_SLINEAR);
|
|
|
|
l->chan->whentohangup = 0;
|
|
|
|
l->chan->appl = "Apprpt";
|
|
|
|
l->chan->data = "(Remote Rx)";
|
|
|
|
if (option_verbose > 2)
|
|
|
|
ast_verbose(VERBOSE_PREFIX_3 "rpt (remote) initiating call to %s/%s on %s\n",
|
|
|
|
deststr,tele,l->chan->name);
|
|
|
|
l->chan->callerid = strdup(myrpt->name);
|
|
|
|
ast_call(l->chan,tele,999);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
free(l);
|
|
|
|
if (option_verbose > 2)
|
|
|
|
ast_verbose(VERBOSE_PREFIX_3 "Unable to place call to %s/%s on %s\n",
|
|
|
|
deststr,tele,l->chan->name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* allocate a pseudo-channel thru asterisk */
|
|
|
|
l->pchan = ast_request("zap",AST_FORMAT_SLINEAR,"pseudo");
|
|
|
|
if (!l->pchan)
|
|
|
|
{
|
|
|
|
fprintf(stderr,"rpt:Sorry unable to obtain pseudo channel\n");
|
|
|
|
pthread_exit(NULL);
|
|
|
|
}
|
|
|
|
ast_set_read_format(l->pchan,AST_FORMAT_SLINEAR);
|
|
|
|
ast_set_write_format(l->pchan,AST_FORMAT_SLINEAR);
|
|
|
|
/* make a conference for the tx */
|
|
|
|
ci.chan = 0;
|
|
|
|
ci.confno = myrpt->conf;
|
|
|
|
ci.confmode = ZT_CONF_CONF | ZT_CONF_LISTENER | ZT_CONF_TALKER;
|
|
|
|
/* first put the channel on the conference in proper mode */
|
|
|
|
if (ioctl(l->pchan->fds[0],ZT_SETCONF,&ci) == -1)
|
|
|
|
{
|
|
|
|
ast_log(LOG_WARNING, "Unable to set conference mode to Announce\n");
|
|
|
|
pthread_exit(NULL);
|
|
|
|
}
|
|
|
|
ast_mutex_lock(&myrpt->lock);
|
|
|
|
/* insert at end of queue */
|
|
|
|
insque((struct qelem *)l,(struct qelem *)myrpt->links.next);
|
|
|
|
ast_mutex_unlock(&myrpt->lock);
|
|
|
|
break;
|
|
|
|
case 4: /* remote cmd mode */
|
2004-06-25 19:33:22 +00:00
|
|
|
if (!myrpt->enable) return;
|
2004-06-21 04:24:50 +00:00
|
|
|
/* if doesnt allow link cmd, return */
|
|
|
|
if ((!allow_linkcmd) || (myrpt->links.next == &myrpt->links)) return;
|
|
|
|
/* if already in cmd mode, or selected self, forget it */
|
|
|
|
if ((myrpt->cmdnode[0]) || (!strcmp(myrpt->name,cmd + 1)))
|
|
|
|
{
|
|
|
|
rpt_telemetry(myrpt,REMALREADY,NULL);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* node must at least exist in list */
|
|
|
|
val = ast_variable_retrieve(cfg,NODES,cmd + 1);
|
|
|
|
if (!val)
|
|
|
|
{
|
|
|
|
rpt_telemetry(myrpt,REMNOTFOUND,NULL);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ast_mutex_lock(&myrpt->lock);
|
|
|
|
myrpt->dtmfidx = -1;
|
|
|
|
myrpt->dtmfbuf[0] = 0;
|
|
|
|
myrpt->rem_dtmfidx = -1;
|
|
|
|
myrpt->rem_dtmfbuf[0] = 0;
|
|
|
|
strcpy(myrpt->cmdnode,cmd + 1);
|
|
|
|
ast_mutex_unlock(&myrpt->lock);
|
|
|
|
rpt_telemetry(myrpt,REMGO,NULL);
|
|
|
|
return;
|
|
|
|
case 7: /* system status */
|
2004-06-25 19:33:22 +00:00
|
|
|
if (!myrpt->enable) return;
|
2004-06-21 04:24:50 +00:00
|
|
|
rpt_telemetry(myrpt,STATUS,NULL);
|
|
|
|
return;
|
|
|
|
case 8: /* force ID */
|
2004-06-25 19:33:22 +00:00
|
|
|
if (!myrpt->enable) return;
|
2004-06-21 04:24:50 +00:00
|
|
|
myrpt->idtimer = 0;
|
|
|
|
return;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
2004-06-25 19:33:22 +00:00
|
|
|
if (!myrpt->enable) return;
|
2004-06-21 04:24:50 +00:00
|
|
|
rpt_telemetry(myrpt,COMPLETE,NULL);
|
|
|
|
}
|
|
|
|
|
2004-06-25 19:33:22 +00:00
|
|
|
static void handle_link_data(struct rpt *myrpt, struct rpt_link *mylink,
|
|
|
|
char *str)
|
2004-06-21 04:24:50 +00:00
|
|
|
{
|
|
|
|
char tmp[300],cmd[300],dest[300],src[300],c;
|
|
|
|
int seq;
|
|
|
|
struct rpt_link *l;
|
|
|
|
struct ast_frame wf;
|
|
|
|
|
|
|
|
wf.frametype = AST_FRAME_TEXT;
|
|
|
|
wf.subclass = 0;
|
|
|
|
wf.offset = 0;
|
|
|
|
wf.mallocd = 1;
|
|
|
|
wf.datalen = strlen(str) + 1;
|
|
|
|
wf.samples = 0;
|
|
|
|
/* put string in our buffer */
|
|
|
|
strncpy(tmp,str,sizeof(tmp) - 1);
|
|
|
|
if (sscanf(tmp,"%s %s %s %d %c",cmd,dest,src,&seq,&c) != 5)
|
|
|
|
{
|
|
|
|
ast_log(LOG_WARNING, "Unable to parse link string %s\n",str);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (strcmp(cmd,"D"))
|
|
|
|
{
|
|
|
|
ast_log(LOG_WARNING, "Unable to parse link string %s\n",str);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* if not for me, redistribute to all links */
|
|
|
|
if (strcmp(dest,myrpt->name))
|
|
|
|
{
|
|
|
|
l = myrpt->links.next;
|
2004-06-25 19:33:22 +00:00
|
|
|
/* see if this is one in list */
|
2004-06-21 04:24:50 +00:00
|
|
|
while(l != &myrpt->links)
|
|
|
|
{
|
2004-06-25 19:33:22 +00:00
|
|
|
/* dont send back from where it came */
|
|
|
|
if ((l == mylink) || (!strcmp(l->name,mylink->name)))
|
2004-06-21 04:24:50 +00:00
|
|
|
{
|
2004-06-25 19:33:22 +00:00
|
|
|
l = l->next;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* if it is, send it and we're done */
|
|
|
|
if (!strcmp(l->name,dest))
|
|
|
|
{
|
|
|
|
/* send, but not to src */
|
|
|
|
if (strcmp(l->name,src)) {
|
|
|
|
wf.data = strdup(str);
|
|
|
|
ast_write(l->chan,&wf);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
l = l->next;
|
|
|
|
}
|
|
|
|
l = myrpt->links.next;
|
|
|
|
/* otherwise, send it to all of em */
|
|
|
|
while(l != &myrpt->links)
|
|
|
|
{
|
|
|
|
/* dont send back from where it came */
|
|
|
|
if ((l == mylink) || (!strcmp(l->name,mylink->name)))
|
|
|
|
{
|
|
|
|
l = l->next;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* send, but not to src */
|
|
|
|
if (strcmp(l->name,src)) {
|
2004-06-21 04:24:50 +00:00
|
|
|
wf.data = strdup(str);
|
|
|
|
ast_write(l->chan,&wf);
|
|
|
|
}
|
|
|
|
l = l->next;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ast_mutex_lock(&myrpt->lock);
|
2004-06-26 19:28:55 +00:00
|
|
|
if (myrpt->callmode == 1)
|
|
|
|
{
|
|
|
|
myrpt->exten[myrpt->cidx++] = c;
|
|
|
|
myrpt->exten[myrpt->cidx] = 0;
|
|
|
|
/* if this exists */
|
|
|
|
if (ast_exists_extension(myrpt->pchannel,myrpt->ourcontext,myrpt->exten,1,NULL))
|
|
|
|
{
|
|
|
|
myrpt->callmode = 2;
|
|
|
|
rpt_telemetry(myrpt,PROC,NULL);
|
|
|
|
}
|
|
|
|
/* if can continue, do so */
|
|
|
|
if (!ast_canmatch_extension(myrpt->pchannel,myrpt->ourcontext,myrpt->exten,1,NULL))
|
|
|
|
{
|
|
|
|
/* call has failed, inform user */
|
|
|
|
myrpt->callmode = 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((myrpt->callmode == 2) || (myrpt->callmode == 3))
|
|
|
|
{
|
|
|
|
myrpt->mydtmf = c;
|
|
|
|
}
|
2004-06-21 04:24:50 +00:00
|
|
|
if (c == '*')
|
|
|
|
{
|
|
|
|
myrpt->rem_dtmfidx = 0;
|
|
|
|
myrpt->rem_dtmfbuf[myrpt->rem_dtmfidx] = 0;
|
|
|
|
time(&myrpt->rem_dtmf_time);
|
|
|
|
ast_mutex_unlock(&myrpt->lock);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if ((c != '#') && (myrpt->rem_dtmfidx >= 0))
|
|
|
|
{
|
|
|
|
time(&myrpt->rem_dtmf_time);
|
|
|
|
if (myrpt->rem_dtmfidx < MAXDTMF)
|
|
|
|
{
|
|
|
|
myrpt->rem_dtmfbuf[myrpt->rem_dtmfidx++] = c;
|
|
|
|
myrpt->rem_dtmfbuf[myrpt->rem_dtmfidx] = 0;
|
|
|
|
/* if to terminate function now */
|
|
|
|
if ((myrpt->rem_dtmfidx == 1) && strchr(SHORTFUNCS,c))
|
|
|
|
{
|
|
|
|
while(myrpt->rem_dtmfidx < FUNCTION_LEN)
|
|
|
|
myrpt->rem_dtmfbuf[myrpt->rem_dtmfidx++] = '0';
|
|
|
|
myrpt->rem_dtmfbuf[myrpt->rem_dtmfidx] = 0;
|
|
|
|
}
|
2004-06-25 19:33:22 +00:00
|
|
|
/* if to terminate function now */
|
|
|
|
if ((myrpt->rem_dtmfidx == 2) && strchr(MEDFUNCS,myrpt->rem_dtmfbuf[0]))
|
|
|
|
{
|
|
|
|
while(myrpt->rem_dtmfidx < FUNCTION_LEN)
|
|
|
|
myrpt->rem_dtmfbuf[myrpt->rem_dtmfidx++] = '0';
|
|
|
|
myrpt->rem_dtmfbuf[myrpt->rem_dtmfidx] = 0;
|
|
|
|
}
|
2004-06-21 04:24:50 +00:00
|
|
|
}
|
|
|
|
if (myrpt->rem_dtmfidx == FUNCTION_LEN)
|
|
|
|
{
|
|
|
|
strcpy(cmd,myrpt->rem_dtmfbuf);
|
|
|
|
myrpt->rem_dtmfbuf[0] = 0;
|
|
|
|
myrpt->rem_dtmfidx = -1;
|
|
|
|
ast_mutex_unlock(&myrpt->lock);
|
|
|
|
process_dtmf(cmd,myrpt,0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ast_mutex_unlock(&myrpt->lock);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-06-26 18:06:17 +00:00
|
|
|
/* Doug Hall RBI-1 serial data definitions:
|
|
|
|
*
|
|
|
|
* Byte 0: Expansion external outputs
|
|
|
|
* Byte 1:
|
|
|
|
* Bits 0-3 are BAND as follows:
|
|
|
|
* Bits 4-5 are POWER bits as follows:
|
|
|
|
* 00 - Low Power
|
|
|
|
* 01 - Hi Power
|
|
|
|
* 02 - Med Power
|
|
|
|
* Bits 6-7 are always set
|
|
|
|
* Byte 2:
|
|
|
|
* Bits 0-3 MHZ in BCD format
|
|
|
|
* Bits 4-5 are offset as follows:
|
|
|
|
* 00 - minus
|
|
|
|
* 01 - plus
|
|
|
|
* 02 - simplex
|
|
|
|
* 03 - minus minus (whatever that is)
|
|
|
|
* Bit 6 is the 0/5 KHZ bit
|
|
|
|
* Bit 7 is always set
|
|
|
|
* Byte 3:
|
|
|
|
* Bits 0-3 are 10 KHZ in BCD format
|
|
|
|
* Bits 4-7 are 100 KHZ in BCD format
|
|
|
|
* Byte 4: PL Tone code and encode/decode enable bits
|
|
|
|
* Bits 0-5 are PL tone code (comspec binary codes)
|
|
|
|
* Bit 6 is encode enable/disable
|
|
|
|
* Bit 7 is decode enable/disable
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* take the frequency from the 10 mhz digits (and up) and convert it
|
|
|
|
to a band number */
|
|
|
|
|
|
|
|
static int rbi_mhztoband(char *str)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
i = atoi(str) / 10; /* get the 10's of mhz */
|
|
|
|
switch(i)
|
|
|
|
{
|
|
|
|
case 2:
|
|
|
|
return 10;
|
|
|
|
case 5:
|
|
|
|
return 11;
|
|
|
|
case 14:
|
|
|
|
return 2;
|
|
|
|
case 22:
|
|
|
|
return 3;
|
|
|
|
case 44:
|
|
|
|
return 4;
|
|
|
|
case 124:
|
|
|
|
return 0;
|
|
|
|
case 125:
|
|
|
|
return 1;
|
|
|
|
case 126:
|
|
|
|
return 8;
|
|
|
|
case 127:
|
|
|
|
return 5;
|
|
|
|
case 128:
|
|
|
|
return 6;
|
|
|
|
case 129:
|
|
|
|
return 7;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* take a PL frequency and turn it into a code */
|
|
|
|
static int rbi_pltocode(char *str)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
char *s;
|
|
|
|
|
|
|
|
s = strchr(str,'.');
|
|
|
|
i = 0;
|
|
|
|
if (s) i = atoi(s + 1);
|
|
|
|
i += atoi(str) * 10;
|
|
|
|
switch(i)
|
|
|
|
{
|
|
|
|
case 670:
|
|
|
|
return 0;
|
|
|
|
case 719:
|
|
|
|
return 1;
|
|
|
|
case 744:
|
|
|
|
return 2;
|
|
|
|
case 770:
|
|
|
|
return 3;
|
|
|
|
case 797:
|
|
|
|
return 4;
|
|
|
|
case 825:
|
|
|
|
return 5;
|
|
|
|
case 854:
|
|
|
|
return 6;
|
|
|
|
case 885:
|
|
|
|
return 7;
|
|
|
|
case 915:
|
|
|
|
return 8;
|
|
|
|
case 948:
|
|
|
|
return 9;
|
|
|
|
case 974:
|
|
|
|
return 10;
|
|
|
|
case 1000:
|
|
|
|
return 11;
|
|
|
|
case 1035:
|
|
|
|
return 12;
|
|
|
|
case 1072:
|
|
|
|
return 13;
|
|
|
|
case 1109:
|
|
|
|
return 14;
|
|
|
|
case 1148:
|
|
|
|
return 15;
|
|
|
|
case 1188:
|
|
|
|
return 16;
|
|
|
|
case 1230:
|
|
|
|
return 17;
|
|
|
|
case 1273:
|
|
|
|
return 18;
|
|
|
|
case 1318:
|
|
|
|
return 19;
|
|
|
|
case 1365:
|
|
|
|
return 20;
|
|
|
|
case 1413:
|
|
|
|
return 21;
|
|
|
|
case 1462:
|
|
|
|
return 22;
|
|
|
|
case 1514:
|
|
|
|
return 23;
|
|
|
|
case 1567:
|
|
|
|
return 24;
|
|
|
|
case 1622:
|
|
|
|
return 25;
|
|
|
|
case 1679:
|
|
|
|
return 26;
|
|
|
|
case 1738:
|
|
|
|
return 27;
|
|
|
|
case 1799:
|
|
|
|
return 28;
|
|
|
|
case 1862:
|
|
|
|
return 29;
|
|
|
|
case 1928:
|
|
|
|
return 30;
|
|
|
|
case 2035:
|
|
|
|
return 31;
|
|
|
|
case 2107:
|
|
|
|
return 32;
|
|
|
|
case 2181:
|
|
|
|
return 33;
|
|
|
|
case 2257:
|
|
|
|
return 34;
|
|
|
|
case 2336:
|
|
|
|
return 35;
|
|
|
|
case 2418:
|
|
|
|
return 36;
|
|
|
|
case 2503:
|
|
|
|
return 37;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Shift out a formatted serial bit stream
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void rbi_out(struct rpt *myrpt,unsigned char *data)
|
|
|
|
{
|
|
|
|
int i,j;
|
|
|
|
unsigned char od,d;
|
|
|
|
static volatile long long delayvar;
|
|
|
|
|
|
|
|
for(i = 0 ; i < 5 ; i++){
|
|
|
|
od = *data++;
|
|
|
|
for(j = 0 ; j < 8 ; j++){
|
|
|
|
d = od & 1;
|
|
|
|
outb(d,myrpt->iobase);
|
|
|
|
/* >= 15 us */
|
|
|
|
for(delayvar = 1; delayvar < 15000; delayvar++);
|
|
|
|
od >>= 1;
|
|
|
|
outb(d | 2,myrpt->iobase);
|
|
|
|
/* >= 30 us */
|
|
|
|
for(delayvar = 1; delayvar < 30000; delayvar++);
|
|
|
|
outb(d,myrpt->iobase);
|
|
|
|
/* >= 10 us */
|
|
|
|
for(delayvar = 1; delayvar < 10000; delayvar++);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* >= 50 us */
|
|
|
|
for(delayvar = 1; delayvar < 50000; delayvar++);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int setrbi(struct rpt *myrpt)
|
|
|
|
{
|
|
|
|
char tmp[MAXREMSTR],rbicmd[5],*s;
|
|
|
|
int band,txoffset = 0,txpower = 0,rxpl;
|
|
|
|
|
|
|
|
|
|
|
|
strcpy(tmp,myrpt->freq);
|
|
|
|
s = strchr(tmp,'.');
|
|
|
|
/* if no decimal, is invalid */
|
|
|
|
if (s == NULL) return -1;
|
|
|
|
*s++ = 0;
|
|
|
|
if (strlen(tmp) < 2) return -1;
|
|
|
|
if (strlen(s) < 3) return -1;
|
|
|
|
if ((s[2] != '0') && (s[2] != '5')) return -1;
|
|
|
|
band = rbi_mhztoband(tmp);
|
|
|
|
if (band == -1) return -1;
|
|
|
|
rxpl = rbi_pltocode(myrpt->rxpl);
|
|
|
|
if (rxpl == -1) return -1;
|
|
|
|
switch(myrpt->offset)
|
|
|
|
{
|
|
|
|
case REM_MINUS:
|
|
|
|
txoffset = 0;
|
|
|
|
break;
|
|
|
|
case REM_PLUS:
|
|
|
|
txoffset = 0x10;
|
|
|
|
break;
|
|
|
|
case REM_SIMPLEX:
|
|
|
|
txoffset = 0x20;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
switch(myrpt->powerlevel)
|
|
|
|
{
|
|
|
|
case REM_LOWPWR:
|
|
|
|
txpower = 0;
|
|
|
|
break;
|
|
|
|
case REM_MEDPWR:
|
|
|
|
txpower = 0x20;
|
|
|
|
break;
|
|
|
|
case REM_HIPWR:
|
|
|
|
txpower = 0x10;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
rbicmd[0] = 0;
|
|
|
|
rbicmd[1] = band | txpower | 0xc0;
|
|
|
|
rbicmd[2] = (*(s - 2) - '0') | txoffset | 0x80;
|
|
|
|
if (s[2] == '5') rbicmd[2] |= 0x40;
|
|
|
|
rbicmd[3] = ((*s - '0') << 4) + (s[1] - '0');
|
|
|
|
rbicmd[4] = rxpl;
|
|
|
|
if (myrpt->txplon) rbicmd[4] |= 0x40;
|
|
|
|
if (myrpt->rxplon) rbicmd[4] |= 0x80;
|
|
|
|
rbi_out(myrpt,rbicmd);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int remote_function(struct rpt *myrpt,char *cmd, struct ast_channel *mychannel)
|
|
|
|
{
|
|
|
|
char *s,*s1,tmp[300],oc,savestr[MAXREMSTR],*val;
|
|
|
|
|
|
|
|
switch(cmd[0])
|
|
|
|
{
|
|
|
|
case '0': /* retrieve memory */
|
|
|
|
val = ast_variable_retrieve(cfg,MEMORY,cmd + 1);
|
|
|
|
if (!val)
|
|
|
|
{
|
|
|
|
if (ast_safe_sleep(mychannel,1000) == -1) return -1;
|
|
|
|
return(sayfile(mychannel,"rpt/memory_notfound"));
|
|
|
|
}
|
|
|
|
strncpy(tmp,val,sizeof(tmp) - 1);
|
|
|
|
s = strchr(tmp,',');
|
|
|
|
if (!s) return 0;
|
|
|
|
*s++ = 0;
|
|
|
|
s1 = strchr(s,',');
|
|
|
|
if (!s1) return 0;
|
|
|
|
*s1++ = 0;
|
|
|
|
strcpy(myrpt->freq,tmp);
|
|
|
|
strcpy(myrpt->rxpl,s);
|
|
|
|
myrpt->offset = REM_SIMPLEX;
|
|
|
|
myrpt->powerlevel = REM_MEDPWR;
|
|
|
|
myrpt->rxplon = 0;
|
|
|
|
myrpt->txplon = 0;
|
|
|
|
while(*s1)
|
|
|
|
{
|
|
|
|
switch(*s1++)
|
|
|
|
{
|
|
|
|
case 'L':
|
|
|
|
case 'l':
|
|
|
|
myrpt->powerlevel = REM_LOWPWR;
|
|
|
|
break;
|
|
|
|
case 'H':
|
|
|
|
case 'h':
|
|
|
|
myrpt->powerlevel = REM_HIPWR;
|
|
|
|
break;
|
|
|
|
case 'M':
|
|
|
|
case 'm':
|
|
|
|
myrpt->powerlevel = REM_MEDPWR;
|
|
|
|
break;
|
|
|
|
case '-':
|
|
|
|
myrpt->offset = REM_MINUS;
|
|
|
|
break;
|
|
|
|
case '+':
|
|
|
|
myrpt->offset = REM_PLUS;
|
|
|
|
break;
|
|
|
|
case 'S':
|
|
|
|
case 's':
|
|
|
|
myrpt->offset = REM_SIMPLEX;
|
|
|
|
break;
|
|
|
|
case 'T':
|
|
|
|
case 't':
|
|
|
|
myrpt->txplon = 1;
|
|
|
|
break;
|
|
|
|
case 'R':
|
|
|
|
case 'r':
|
|
|
|
myrpt->rxplon = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (setrbi(myrpt) == -1) return 0;
|
|
|
|
break;
|
|
|
|
case '1': /* set freq + offset */
|
|
|
|
strncpy(tmp,cmd,sizeof(tmp) - 1);
|
|
|
|
s1 = NULL;
|
|
|
|
oc = 0;
|
|
|
|
/* see if we have at least 1 */
|
|
|
|
s = strchr(tmp,'*');
|
|
|
|
if (s)
|
|
|
|
{
|
|
|
|
*s++ = 0;
|
|
|
|
s1 = strchr(s,'*');
|
|
|
|
if (s1)
|
|
|
|
{
|
|
|
|
*s1++ = 0;
|
|
|
|
oc = *s1;
|
|
|
|
}
|
|
|
|
if (strlen(s) > 3) return 0;
|
|
|
|
if (strlen(s) < 3) memset(s + strlen(s),'0',3 - strlen(s));
|
|
|
|
s[3] = 0;
|
|
|
|
} else strcat(tmp,".000");
|
|
|
|
if (oc)
|
|
|
|
{
|
|
|
|
switch(oc)
|
|
|
|
{
|
|
|
|
case '1':
|
|
|
|
myrpt->offset = REM_MINUS;
|
|
|
|
break;
|
|
|
|
case '2':
|
|
|
|
myrpt->offset = REM_SIMPLEX;
|
|
|
|
break;
|
|
|
|
case '3':
|
|
|
|
myrpt->offset = REM_PLUS;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
} else myrpt->offset = REM_SIMPLEX;
|
|
|
|
if(s) *--s = '.';
|
|
|
|
strcpy(savestr,myrpt->freq);
|
|
|
|
strcpy(myrpt->freq,tmp + 1);
|
|
|
|
if (setrbi(myrpt) == -1)
|
|
|
|
{
|
|
|
|
strcpy(myrpt->freq,savestr);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '2': /* set rx PL tone */
|
|
|
|
strncpy(tmp,cmd,sizeof(tmp) - 1);
|
|
|
|
/* see if we have at least 1 */
|
|
|
|
s = strchr(tmp,'*');
|
|
|
|
if (s)
|
|
|
|
{
|
|
|
|
*s++ = '.';
|
|
|
|
if (strlen(s + 1) > 1) return 0;
|
|
|
|
} else strcat(tmp,".0");
|
|
|
|
strcpy(savestr,myrpt->rxpl);
|
|
|
|
strcpy(myrpt->rxpl,tmp + 1);
|
|
|
|
if (setrbi(myrpt) == -1)
|
|
|
|
{
|
|
|
|
strcpy(myrpt->rxpl,savestr);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '4': /* other stuff */
|
|
|
|
if (strlen(cmd) > 2) return 0;
|
|
|
|
switch(cmd[1])
|
|
|
|
{
|
|
|
|
case '0': /* RX PL Off */
|
|
|
|
myrpt->rxplon = 0;
|
|
|
|
break;
|
|
|
|
case '1': /* RX PL On */
|
|
|
|
myrpt->rxplon = 1;
|
|
|
|
break;
|
|
|
|
case '2': /* TX PL Off */
|
|
|
|
myrpt->txplon = 0;
|
|
|
|
break;
|
|
|
|
case '3': /* TX PL On */
|
|
|
|
myrpt->txplon = 1;
|
|
|
|
break;
|
|
|
|
case '4': /* Low Power */
|
|
|
|
myrpt->powerlevel = REM_LOWPWR;
|
|
|
|
break;
|
|
|
|
case '5': /* Medium Power */
|
|
|
|
myrpt->powerlevel = REM_MEDPWR;
|
|
|
|
break;
|
|
|
|
case '6': /* Hi Power */
|
|
|
|
myrpt->powerlevel = REM_HIPWR;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (setrbi(myrpt) == -1) return 0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int handle_dtmf_digit(struct rpt *myrpt,char c, struct ast_channel *mychannel)
|
|
|
|
{
|
|
|
|
char str[MAXDTMF],*s,*s1;
|
|
|
|
time_t now;
|
2004-06-26 19:08:57 +00:00
|
|
|
int res = 0;
|
2004-06-26 18:06:17 +00:00
|
|
|
|
|
|
|
time(&now);
|
|
|
|
/* if timed-out */
|
|
|
|
if ((myrpt->dtmf_time_rem + DTMF_TIMEOUT) < now)
|
|
|
|
{
|
|
|
|
strcpy(str,myrpt->dtmfbuf);
|
|
|
|
myrpt->dtmfidx = -1;
|
|
|
|
myrpt->dtmfbuf[0] = 0;
|
|
|
|
myrpt->dtmf_time_rem = 0;
|
|
|
|
}
|
|
|
|
/* if decode not active */
|
|
|
|
if (myrpt->dtmfidx == -1)
|
|
|
|
{
|
|
|
|
/* if not lead-in digit, dont worry */
|
|
|
|
if (c != '*') return 0;
|
|
|
|
myrpt->dtmfidx = 0;
|
|
|
|
myrpt->dtmfbuf[0] = 0;
|
|
|
|
myrpt->dtmf_time_rem = now;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* if too many in buffer, start over */
|
|
|
|
if (myrpt->dtmfidx >= MAXDTMF)
|
|
|
|
{
|
|
|
|
myrpt->dtmfidx = 0;
|
|
|
|
myrpt->dtmfbuf[0] = 0;
|
|
|
|
myrpt->dtmf_time_rem = now;
|
|
|
|
}
|
|
|
|
if (c == '*')
|
|
|
|
{
|
|
|
|
/* if star at beginning, or 2 together, erase buffer */
|
|
|
|
if ((myrpt->dtmfidx < 1) ||
|
|
|
|
(myrpt->dtmfbuf[myrpt->dtmfidx - 1] == '*'))
|
|
|
|
{
|
|
|
|
myrpt->dtmfidx = 0;
|
|
|
|
myrpt->dtmfbuf[0] = 0;
|
|
|
|
myrpt->dtmf_time_rem = now;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
myrpt->dtmfbuf[myrpt->dtmfidx++] = c;
|
|
|
|
myrpt->dtmfbuf[myrpt->dtmfidx] = 0;
|
|
|
|
myrpt->dtmf_time_rem = now;
|
|
|
|
switch(myrpt->dtmfbuf[0])
|
|
|
|
{
|
|
|
|
case '4': /* wait for 1 more digit */
|
|
|
|
/* if we are at end, process it */
|
|
|
|
if (myrpt->dtmfidx >= 2) break;
|
|
|
|
return 0;
|
|
|
|
case '0': /* wait for 2 more digits */
|
|
|
|
/* if we are at end, process it */
|
|
|
|
if (myrpt->dtmfidx >= 3) break;
|
|
|
|
return 0;
|
|
|
|
case '2':
|
|
|
|
case '3': /* go until 1 digit after * */
|
|
|
|
s = strchr(myrpt->dtmfbuf,'*');
|
|
|
|
/* if we dont have a star, dont worry yet */
|
|
|
|
if (s == NULL) return 0;
|
|
|
|
/* if nothing after star yet */
|
|
|
|
if (!s[1]) return 0;
|
|
|
|
/* okay, we got it */
|
|
|
|
break;
|
|
|
|
case '1': /* go until 1 digit after second * */
|
|
|
|
s = strchr(myrpt->dtmfbuf,'*');
|
|
|
|
/* if we dont have a star, dont worry yet */
|
|
|
|
if (s == NULL) return 0;
|
|
|
|
/* if nothing after star yet */
|
|
|
|
if (!s[1]) return 0;
|
|
|
|
s1 = strchr(s + 1,'*');
|
|
|
|
/* if we dont have a 2nd star, dont worry yet */
|
|
|
|
if (s1 == NULL) return 0;
|
|
|
|
/* if nothing after 2nd * yet */
|
|
|
|
if (!s1[1]) return 0;
|
|
|
|
/* okay, we got it */
|
|
|
|
break;
|
|
|
|
case '5': /* status, just deux it here */
|
2004-06-26 19:08:57 +00:00
|
|
|
myrpt->remotetx = 0;
|
|
|
|
ast_indicate(myrpt->txchannel,AST_CONTROL_RADIO_UNKEY);
|
|
|
|
if (!myrpt->remoterx)
|
|
|
|
{
|
|
|
|
ast_indicate(mychannel,AST_CONTROL_RADIO_KEY);
|
|
|
|
}
|
|
|
|
if ((sayfile(mychannel,"rpt/node") == -1) ||
|
|
|
|
(saycharstr(mychannel,myrpt->name) == -1) ||
|
|
|
|
(sayfile(mychannel,"rpt/frequency") == -1) ||
|
|
|
|
(saycharstr(mychannel,myrpt->freq) == -1))
|
|
|
|
{
|
|
|
|
if (!myrpt->remoterx)
|
|
|
|
{
|
|
|
|
ast_indicate(mychannel,AST_CONTROL_RADIO_UNKEY);
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
2004-06-26 18:06:17 +00:00
|
|
|
switch(myrpt->offset)
|
|
|
|
{
|
|
|
|
case REM_MINUS:
|
2004-06-26 19:08:57 +00:00
|
|
|
res = sayfile(mychannel,"rpt/minus");
|
2004-06-26 18:06:17 +00:00
|
|
|
break;
|
|
|
|
case REM_SIMPLEX:
|
2004-06-26 19:08:57 +00:00
|
|
|
res = sayfile(mychannel,"rpt/simplex");
|
2004-06-26 18:06:17 +00:00
|
|
|
break;
|
|
|
|
case REM_PLUS:
|
2004-06-26 19:08:57 +00:00
|
|
|
res = sayfile(mychannel,"rpt/plus");
|
2004-06-26 18:06:17 +00:00
|
|
|
break;
|
|
|
|
}
|
2004-06-26 19:08:57 +00:00
|
|
|
if (res == -1)
|
|
|
|
{
|
|
|
|
if (!myrpt->remoterx)
|
|
|
|
{
|
|
|
|
ast_indicate(mychannel,AST_CONTROL_RADIO_UNKEY);
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
2004-06-26 18:06:17 +00:00
|
|
|
switch(myrpt->powerlevel)
|
|
|
|
{
|
|
|
|
case REM_LOWPWR:
|
2004-06-26 19:08:57 +00:00
|
|
|
res = sayfile(mychannel,"rpt/lopwr") ;
|
2004-06-26 18:06:17 +00:00
|
|
|
break;
|
|
|
|
case REM_MEDPWR:
|
2004-06-26 19:08:57 +00:00
|
|
|
res = sayfile(mychannel,"rpt/medpwr");
|
2004-06-26 18:06:17 +00:00
|
|
|
break;
|
|
|
|
case REM_HIPWR:
|
2004-06-26 19:08:57 +00:00
|
|
|
res = sayfile(mychannel,"rpt/hipwr");
|
2004-06-26 18:06:17 +00:00
|
|
|
break;
|
|
|
|
}
|
2004-06-26 19:08:57 +00:00
|
|
|
if (res || (sayfile(mychannel,"rpt/rxpl") == -1) ||
|
|
|
|
(sayfile(mychannel,"rpt/frequency") == -1) ||
|
|
|
|
(saycharstr(mychannel,myrpt->rxpl) == -1) ||
|
|
|
|
(sayfile(mychannel,"rpt/txpl") == -1) ||
|
|
|
|
(sayfile(mychannel,((myrpt->txplon) ? "rpt/on" : "rpt/off")) == -1) ||
|
|
|
|
(sayfile(mychannel,"rpt/rxpl") == -1) ||
|
|
|
|
(sayfile(mychannel,((myrpt->rxplon) ? "rpt/on" : "rpt/off")) == -1))
|
|
|
|
{
|
|
|
|
if (!myrpt->remoterx)
|
|
|
|
{
|
|
|
|
ast_indicate(mychannel,AST_CONTROL_RADIO_UNKEY);
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (!myrpt->remoterx)
|
|
|
|
{
|
|
|
|
ast_indicate(mychannel,AST_CONTROL_RADIO_UNKEY);
|
|
|
|
}
|
2004-06-26 18:06:17 +00:00
|
|
|
myrpt->dtmfidx = -1;
|
|
|
|
myrpt->dtmfbuf[0] = 0;
|
|
|
|
myrpt->dtmf_time_rem = 0;
|
|
|
|
return 1;
|
|
|
|
default:
|
|
|
|
myrpt->dtmfidx = -1;
|
|
|
|
myrpt->dtmfbuf[0] = 0;
|
|
|
|
myrpt->dtmf_time_rem = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
strcpy(str,myrpt->dtmfbuf);
|
2004-06-26 19:08:57 +00:00
|
|
|
myrpt->remotetx = 0;
|
|
|
|
ast_indicate(myrpt->txchannel,AST_CONTROL_RADIO_UNKEY);
|
|
|
|
if (!myrpt->remoterx)
|
|
|
|
{
|
|
|
|
ast_indicate(mychannel,AST_CONTROL_RADIO_KEY);
|
|
|
|
}
|
2004-06-26 18:06:17 +00:00
|
|
|
myrpt->dtmfidx = -1;
|
|
|
|
myrpt->dtmfbuf[0] = 0;
|
|
|
|
myrpt->dtmf_time_rem = 0;
|
2004-06-26 19:08:57 +00:00
|
|
|
res = remote_function(myrpt,str,mychannel);
|
|
|
|
if (!myrpt->remoterx)
|
|
|
|
{
|
|
|
|
ast_indicate(mychannel,AST_CONTROL_RADIO_UNKEY);
|
|
|
|
}
|
|
|
|
return res;
|
2004-06-26 18:06:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int handle_remote_data(struct rpt *myrpt, char *str, struct ast_channel *mychannel)
|
2004-06-25 19:33:22 +00:00
|
|
|
{
|
|
|
|
char tmp[300],cmd[300],dest[300],src[300],c;
|
2004-06-26 18:06:17 +00:00
|
|
|
int seq,res;
|
2004-06-25 19:33:22 +00:00
|
|
|
|
|
|
|
/* put string in our buffer */
|
|
|
|
strncpy(tmp,str,sizeof(tmp) - 1);
|
|
|
|
if (sscanf(tmp,"%s %s %s %d %c",cmd,dest,src,&seq,&c) != 5)
|
|
|
|
{
|
|
|
|
ast_log(LOG_WARNING, "Unable to parse link string %s\n",str);
|
2004-06-26 18:06:17 +00:00
|
|
|
return 0;
|
2004-06-25 19:33:22 +00:00
|
|
|
}
|
|
|
|
if (strcmp(cmd,"D"))
|
|
|
|
{
|
|
|
|
ast_log(LOG_WARNING, "Unable to parse link string %s\n",str);
|
2004-06-26 18:06:17 +00:00
|
|
|
return 0;
|
2004-06-25 19:33:22 +00:00
|
|
|
}
|
|
|
|
/* if not for me, ignore */
|
2004-06-26 18:06:17 +00:00
|
|
|
if (strcmp(dest,myrpt->name)) return 0;
|
|
|
|
res = handle_dtmf_digit(myrpt,c,mychannel);
|
|
|
|
if (res != 1) return res;
|
2004-06-26 19:08:57 +00:00
|
|
|
myrpt->remotetx = 0;
|
|
|
|
ast_indicate(myrpt->txchannel,AST_CONTROL_RADIO_UNKEY);
|
|
|
|
if (!myrpt->remoterx)
|
|
|
|
{
|
|
|
|
ast_indicate(mychannel,AST_CONTROL_RADIO_KEY);
|
|
|
|
}
|
2004-06-26 18:06:17 +00:00
|
|
|
if (ast_safe_sleep(mychannel,1000) == -1) return -1;
|
2004-06-26 19:08:57 +00:00
|
|
|
res = sayfile(mychannel,"rpt/functioncomplete");
|
|
|
|
if (!myrpt->remoterx)
|
|
|
|
{
|
|
|
|
ast_indicate(mychannel,AST_CONTROL_RADIO_UNKEY);
|
|
|
|
}
|
|
|
|
return res;
|
2004-06-25 19:33:22 +00:00
|
|
|
}
|
|
|
|
|
2004-06-21 04:24:50 +00:00
|
|
|
/* single thread with one file (request) to dial */
|
|
|
|
static void *rpt(void *this)
|
|
|
|
{
|
|
|
|
struct rpt *myrpt = (struct rpt *)this;
|
|
|
|
char *tele;
|
|
|
|
int ms = MSWAIT,lasttx,keyed,val,remrx;
|
|
|
|
struct ast_channel *who;
|
2002-12-08 17:30:24 +00:00
|
|
|
ZT_CONFINFO ci; /* conference info */
|
2004-05-31 16:04:10 +00:00
|
|
|
time_t dtmf_time,t;
|
2004-06-21 04:24:50 +00:00
|
|
|
struct rpt_link *l,*m;
|
2002-12-08 17:30:24 +00:00
|
|
|
pthread_attr_t attr;
|
|
|
|
|
2004-06-21 04:24:50 +00:00
|
|
|
ast_mutex_lock(&myrpt->lock);
|
2002-12-08 17:30:24 +00:00
|
|
|
tele = strchr(myrpt->rxchanname,'/');
|
|
|
|
if (!tele)
|
|
|
|
{
|
|
|
|
fprintf(stderr,"rpt:Dial number must be in format tech/number\n");
|
2004-06-21 04:24:50 +00:00
|
|
|
ast_mutex_unlock(&myrpt->lock);
|
2002-12-08 17:30:24 +00:00
|
|
|
pthread_exit(NULL);
|
|
|
|
}
|
|
|
|
*tele++ = 0;
|
|
|
|
myrpt->rxchannel = ast_request(myrpt->rxchanname,AST_FORMAT_SLINEAR,tele);
|
|
|
|
if (myrpt->rxchannel)
|
|
|
|
{
|
2004-04-07 20:12:42 +00:00
|
|
|
ast_set_read_format(myrpt->rxchannel,AST_FORMAT_SLINEAR);
|
|
|
|
ast_set_write_format(myrpt->rxchannel,AST_FORMAT_SLINEAR);
|
2002-12-08 17:30:24 +00:00
|
|
|
myrpt->rxchannel->whentohangup = 0;
|
|
|
|
myrpt->rxchannel->appl = "Apprpt";
|
|
|
|
myrpt->rxchannel->data = "(Repeater Rx)";
|
|
|
|
if (option_verbose > 2)
|
|
|
|
ast_verbose(VERBOSE_PREFIX_3 "rpt (Rx) initiating call to %s/%s on %s\n",
|
|
|
|
myrpt->rxchanname,tele,myrpt->rxchannel->name);
|
|
|
|
ast_call(myrpt->rxchannel,tele,999);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-05-31 16:04:10 +00:00
|
|
|
fprintf(stderr,"rpt:Sorry unable to obtain Rx channel\n");
|
2004-06-21 04:24:50 +00:00
|
|
|
ast_mutex_unlock(&myrpt->lock);
|
2002-12-08 17:30:24 +00:00
|
|
|
pthread_exit(NULL);
|
|
|
|
}
|
|
|
|
if (myrpt->txchanname)
|
|
|
|
{
|
|
|
|
tele = strchr(myrpt->txchanname,'/');
|
|
|
|
if (!tele)
|
|
|
|
{
|
|
|
|
fprintf(stderr,"rpt:Dial number must be in format tech/number\n");
|
2004-06-21 04:24:50 +00:00
|
|
|
ast_mutex_unlock(&myrpt->lock);
|
2002-12-08 17:30:24 +00:00
|
|
|
pthread_exit(NULL);
|
|
|
|
}
|
|
|
|
*tele++ = 0;
|
|
|
|
myrpt->txchannel = ast_request(myrpt->txchanname,AST_FORMAT_SLINEAR,tele);
|
|
|
|
if (myrpt->txchannel)
|
|
|
|
{
|
2004-04-07 20:12:42 +00:00
|
|
|
ast_set_read_format(myrpt->txchannel,AST_FORMAT_SLINEAR);
|
|
|
|
ast_set_write_format(myrpt->txchannel,AST_FORMAT_SLINEAR);
|
2002-12-08 17:30:24 +00:00
|
|
|
myrpt->txchannel->whentohangup = 0;
|
|
|
|
myrpt->txchannel->appl = "Apprpt";
|
|
|
|
myrpt->txchannel->data = "(Repeater Rx)";
|
|
|
|
if (option_verbose > 2)
|
|
|
|
ast_verbose(VERBOSE_PREFIX_3 "rpt (Tx) initiating call to %s/%s on %s\n",
|
|
|
|
myrpt->txchanname,tele,myrpt->txchannel->name);
|
|
|
|
ast_call(myrpt->txchannel,tele,999);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-05-31 16:04:10 +00:00
|
|
|
fprintf(stderr,"rpt:Sorry unable to obtain Tx channel\n");
|
2004-06-21 04:24:50 +00:00
|
|
|
ast_mutex_unlock(&myrpt->lock);
|
2002-12-08 17:30:24 +00:00
|
|
|
pthread_exit(NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
myrpt->txchannel = myrpt->rxchannel;
|
|
|
|
}
|
|
|
|
/* allocate a pseudo-channel thru asterisk */
|
|
|
|
myrpt->pchannel = ast_request("zap",AST_FORMAT_SLINEAR,"pseudo");
|
|
|
|
if (!myrpt->pchannel)
|
|
|
|
{
|
|
|
|
fprintf(stderr,"rpt:Sorry unable to obtain pseudo channel\n");
|
2004-06-21 04:24:50 +00:00
|
|
|
ast_mutex_unlock(&myrpt->lock);
|
2002-12-08 17:30:24 +00:00
|
|
|
pthread_exit(NULL);
|
|
|
|
}
|
|
|
|
/* make a conference for the tx */
|
|
|
|
ci.chan = 0;
|
|
|
|
ci.confno = -1; /* make a new conf */
|
|
|
|
ci.confmode = ZT_CONF_CONF | ZT_CONF_LISTENER;
|
2004-06-21 04:24:50 +00:00
|
|
|
/* first put the channel on the conference in proper mode */
|
2002-12-08 17:30:24 +00:00
|
|
|
if (ioctl(myrpt->txchannel->fds[0],ZT_SETCONF,&ci) == -1)
|
|
|
|
{
|
|
|
|
ast_log(LOG_WARNING, "Unable to set conference mode to Announce\n");
|
2004-06-21 04:24:50 +00:00
|
|
|
ast_mutex_unlock(&myrpt->lock);
|
2002-12-08 17:30:24 +00:00
|
|
|
pthread_exit(NULL);
|
|
|
|
}
|
|
|
|
/* save tx conference number */
|
|
|
|
myrpt->txconf = ci.confno;
|
|
|
|
/* make a conference for the pseudo */
|
|
|
|
ci.chan = 0;
|
|
|
|
ci.confno = -1; /* make a new conf */
|
|
|
|
ci.confmode = ZT_CONF_CONFANNMON;
|
|
|
|
/* first put the channel on the conference in announce mode */
|
|
|
|
if (ioctl(myrpt->pchannel->fds[0],ZT_SETCONF,&ci) == -1)
|
|
|
|
{
|
|
|
|
ast_log(LOG_WARNING, "Unable to set conference mode to Announce\n");
|
2004-06-21 04:24:50 +00:00
|
|
|
ast_mutex_unlock(&myrpt->lock);
|
2002-12-08 17:30:24 +00:00
|
|
|
pthread_exit(NULL);
|
|
|
|
}
|
|
|
|
/* save pseudo channel conference number */
|
2004-06-21 04:24:50 +00:00
|
|
|
myrpt->conf = ci.confno;
|
|
|
|
/* allocate a pseudo-channel thru asterisk */
|
|
|
|
myrpt->txpchannel = ast_request("zap",AST_FORMAT_SLINEAR,"pseudo");
|
|
|
|
if (!myrpt->txpchannel)
|
|
|
|
{
|
|
|
|
fprintf(stderr,"rpt:Sorry unable to obtain pseudo channel\n");
|
|
|
|
ast_mutex_unlock(&myrpt->lock);
|
|
|
|
pthread_exit(NULL);
|
|
|
|
}
|
|
|
|
/* make a conference for the tx */
|
|
|
|
ci.chan = 0;
|
|
|
|
ci.confno = myrpt->txconf;
|
|
|
|
ci.confmode = ZT_CONF_CONF | ZT_CONF_TALKER ;
|
|
|
|
/* first put the channel on the conference in proper mode */
|
|
|
|
if (ioctl(myrpt->txpchannel->fds[0],ZT_SETCONF,&ci) == -1)
|
|
|
|
{
|
|
|
|
ast_log(LOG_WARNING, "Unable to set conference mode to Announce\n");
|
|
|
|
ast_mutex_unlock(&myrpt->lock);
|
|
|
|
pthread_exit(NULL);
|
|
|
|
}
|
2002-12-08 17:30:24 +00:00
|
|
|
/* Now, the idea here is to copy from the physical rx channel buffer
|
|
|
|
into the pseudo tx buffer, and from the pseudo rx buffer into the
|
|
|
|
tx channel buffer */
|
2004-06-21 04:24:50 +00:00
|
|
|
myrpt->links.next = &myrpt->links;
|
|
|
|
myrpt->links.prev = &myrpt->links;
|
2002-12-08 17:30:24 +00:00
|
|
|
myrpt->tailtimer = 0;
|
|
|
|
myrpt->totimer = 0;
|
|
|
|
myrpt->idtimer = 0;
|
2004-06-21 04:24:50 +00:00
|
|
|
myrpt->callmode = 0;
|
2004-06-25 19:33:22 +00:00
|
|
|
myrpt->tounkeyed = 0;
|
|
|
|
myrpt->tonotify = 0;
|
2002-12-08 17:30:24 +00:00
|
|
|
lasttx = 0;
|
|
|
|
keyed = 0;
|
2004-06-21 04:24:50 +00:00
|
|
|
myrpt->dtmfidx = -1;
|
|
|
|
myrpt->dtmfbuf[0] = 0;
|
|
|
|
myrpt->rem_dtmfidx = -1;
|
|
|
|
myrpt->rem_dtmfbuf[0] = 0;
|
2004-05-31 16:04:10 +00:00
|
|
|
dtmf_time = 0;
|
2004-06-21 04:24:50 +00:00
|
|
|
myrpt->rem_dtmf_time = 0;
|
2004-06-25 19:33:22 +00:00
|
|
|
myrpt->enable = 1;
|
|
|
|
ast_mutex_unlock(&myrpt->lock);
|
2002-12-08 17:30:24 +00:00
|
|
|
val = 0;
|
|
|
|
ast_channel_setoption(myrpt->rxchannel,AST_OPTION_TONE_VERIFY,&val,sizeof(char),0);
|
|
|
|
val = 1;
|
|
|
|
ast_channel_setoption(myrpt->rxchannel,AST_OPTION_RELAXDTMF,&val,sizeof(char),0);
|
|
|
|
while (ms >= 0)
|
|
|
|
{
|
|
|
|
struct ast_frame *f;
|
2004-06-21 04:24:50 +00:00
|
|
|
struct ast_channel *cs[300];
|
|
|
|
int totx,elap,n,toexit;
|
2002-12-08 17:30:24 +00:00
|
|
|
|
2004-05-31 16:04:10 +00:00
|
|
|
if (ast_check_hangup(myrpt->rxchannel)) break;
|
|
|
|
if (ast_check_hangup(myrpt->txchannel)) break;
|
2004-06-21 04:24:50 +00:00
|
|
|
if (ast_check_hangup(myrpt->pchannel)) break;
|
|
|
|
if (ast_check_hangup(myrpt->txpchannel)) break;
|
|
|
|
ast_mutex_lock(&myrpt->lock);
|
|
|
|
myrpt->localtx = keyed;
|
|
|
|
l = myrpt->links.next;
|
|
|
|
remrx = 0;
|
|
|
|
while(l != &myrpt->links)
|
2004-05-31 16:04:10 +00:00
|
|
|
{
|
2004-06-21 04:24:50 +00:00
|
|
|
if (l->lastrx) remrx = 1;
|
|
|
|
l = l->next;
|
2004-05-31 16:04:10 +00:00
|
|
|
}
|
2004-06-21 04:24:50 +00:00
|
|
|
totx = (keyed || myrpt->callmode ||
|
|
|
|
(myrpt->tele.next != &myrpt->tele));
|
|
|
|
myrpt->exttx = totx;
|
2004-06-25 19:33:22 +00:00
|
|
|
totx = totx || remrx;
|
|
|
|
if (!totx)
|
|
|
|
{
|
|
|
|
myrpt->totimer = myrpt->totime;
|
|
|
|
myrpt->tounkeyed = 0;
|
|
|
|
myrpt->tonotify = 0;
|
|
|
|
}
|
2002-12-08 17:30:24 +00:00
|
|
|
else myrpt->tailtimer = myrpt->hangtime;
|
2004-06-25 19:33:22 +00:00
|
|
|
totx = totx && myrpt->totimer;
|
|
|
|
/* if timed-out and not said already, say it */
|
|
|
|
if ((!myrpt->totimer) && (!myrpt->tonotify))
|
|
|
|
{
|
|
|
|
myrpt->tonotify = 1;
|
|
|
|
rpt_telemetry(myrpt,TIMEOUT,NULL);
|
|
|
|
}
|
2002-12-08 17:30:24 +00:00
|
|
|
/* if wants to transmit and in phone call, but timed out,
|
|
|
|
reset time-out timer if keyed */
|
2004-06-25 19:33:22 +00:00
|
|
|
if ((!totx) && (!myrpt->totimer) && (!myrpt->tounkeyed) && (!keyed))
|
|
|
|
{
|
|
|
|
myrpt->tounkeyed = 1;
|
|
|
|
}
|
|
|
|
if ((!totx) && (!myrpt->totimer) && myrpt->tounkeyed && keyed)
|
2002-12-08 17:30:24 +00:00
|
|
|
{
|
|
|
|
myrpt->totimer = myrpt->totime;
|
2004-06-25 19:33:22 +00:00
|
|
|
myrpt->tounkeyed = 0;
|
|
|
|
myrpt->tonotify = 0;
|
2004-06-21 04:24:50 +00:00
|
|
|
ast_mutex_unlock(&myrpt->lock);
|
2002-12-08 17:30:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2004-05-31 16:04:10 +00:00
|
|
|
/* if timed-out and in circuit busy after call */
|
|
|
|
if ((!totx) && (!myrpt->totimer) && (myrpt->callmode == 4))
|
|
|
|
{
|
|
|
|
myrpt->callmode = 0;
|
|
|
|
}
|
2004-06-25 19:33:22 +00:00
|
|
|
/* get rid of tail if timed out */
|
|
|
|
if (!myrpt->totimer) myrpt->tailtimer = 0;
|
|
|
|
/* if not timed-out, add in tail */
|
|
|
|
if (myrpt->totimer) totx = totx || myrpt->tailtimer;
|
|
|
|
/* if time to ID */
|
2002-12-08 17:30:24 +00:00
|
|
|
if (totx && (!myrpt->idtimer))
|
|
|
|
{
|
|
|
|
myrpt->idtimer = myrpt->idtime;
|
2004-06-21 04:24:50 +00:00
|
|
|
ast_mutex_unlock(&myrpt->lock);
|
|
|
|
rpt_telemetry(myrpt,ID,NULL);
|
|
|
|
ast_mutex_lock(&myrpt->lock);
|
2002-12-08 17:30:24 +00:00
|
|
|
}
|
2004-06-25 19:33:22 +00:00
|
|
|
/* let telemetry transmit anyway (regardless of timeout) */
|
|
|
|
totx = totx || (myrpt->tele.next != &myrpt->tele);
|
2002-12-08 17:30:24 +00:00
|
|
|
if (totx && (!lasttx))
|
|
|
|
{
|
|
|
|
lasttx = 1;
|
2004-06-21 04:24:50 +00:00
|
|
|
ast_mutex_unlock(&myrpt->lock);
|
2002-12-08 17:30:24 +00:00
|
|
|
ast_indicate(myrpt->txchannel,AST_CONTROL_RADIO_KEY);
|
2004-06-21 04:24:50 +00:00
|
|
|
ast_mutex_lock(&myrpt->lock);
|
2002-12-08 17:30:24 +00:00
|
|
|
}
|
2004-06-25 19:33:22 +00:00
|
|
|
totx = totx && myrpt->enable;
|
2002-12-08 17:30:24 +00:00
|
|
|
if ((!totx) && lasttx)
|
|
|
|
{
|
|
|
|
lasttx = 0;
|
2004-06-21 04:24:50 +00:00
|
|
|
ast_mutex_unlock(&myrpt->lock);
|
2002-12-08 17:30:24 +00:00
|
|
|
ast_indicate(myrpt->txchannel,AST_CONTROL_RADIO_UNKEY);
|
2004-06-21 04:24:50 +00:00
|
|
|
ast_mutex_lock(&myrpt->lock);
|
2004-05-31 16:04:10 +00:00
|
|
|
}
|
|
|
|
time(&t);
|
|
|
|
/* if DTMF timeout */
|
2004-06-21 04:24:50 +00:00
|
|
|
if ((!myrpt->cmdnode[0]) && (myrpt->dtmfidx >= 0) && ((dtmf_time + DTMF_TIMEOUT) < t))
|
2004-05-31 16:04:10 +00:00
|
|
|
{
|
2004-06-21 04:24:50 +00:00
|
|
|
myrpt->dtmfidx = -1;
|
|
|
|
myrpt->dtmfbuf[0] = 0;
|
|
|
|
}
|
|
|
|
/* if remote DTMF timeout */
|
|
|
|
if ((myrpt->rem_dtmfidx >= 0) && ((myrpt->rem_dtmf_time + DTMF_TIMEOUT) < t))
|
|
|
|
{
|
|
|
|
myrpt->rem_dtmfidx = -1;
|
|
|
|
myrpt->rem_dtmfbuf[0] = 0;
|
2004-05-31 16:04:10 +00:00
|
|
|
}
|
|
|
|
n = 0;
|
|
|
|
cs[n++] = myrpt->rxchannel;
|
|
|
|
cs[n++] = myrpt->pchannel;
|
2004-06-21 04:24:50 +00:00
|
|
|
cs[n++] = myrpt->txpchannel;
|
2004-05-31 16:04:10 +00:00
|
|
|
if (myrpt->txchannel != myrpt->rxchannel) cs[n++] = myrpt->txchannel;
|
2004-06-21 04:24:50 +00:00
|
|
|
l = myrpt->links.next;
|
|
|
|
while(l != &myrpt->links)
|
2004-05-31 16:04:10 +00:00
|
|
|
{
|
2004-06-21 04:24:50 +00:00
|
|
|
cs[n++] = l->chan;
|
|
|
|
cs[n++] = l->pchan;
|
|
|
|
l = l->next;
|
2004-05-31 16:04:10 +00:00
|
|
|
}
|
2004-06-21 04:24:50 +00:00
|
|
|
ast_mutex_unlock(&myrpt->lock);
|
2002-12-08 17:30:24 +00:00
|
|
|
ms = MSWAIT;
|
2004-05-31 16:04:10 +00:00
|
|
|
who = ast_waitfor_n(cs,n,&ms);
|
2002-12-08 17:30:24 +00:00
|
|
|
if (who == NULL) ms = 0;
|
|
|
|
elap = MSWAIT - ms;
|
2004-06-21 04:24:50 +00:00
|
|
|
ast_mutex_lock(&myrpt->lock);
|
|
|
|
l = myrpt->links.next;
|
|
|
|
while(l != &myrpt->links)
|
|
|
|
{
|
|
|
|
/* ignore non-timing channels */
|
|
|
|
if (l->elaptime < 0)
|
|
|
|
{
|
|
|
|
l = l->next;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
l->elaptime += elap;
|
|
|
|
/* if connection has taken too long */
|
|
|
|
if ((l->elaptime > MAXCONNECTTIME) &&
|
|
|
|
(l->chan->_state != AST_STATE_UP))
|
|
|
|
{
|
|
|
|
ast_mutex_unlock(&myrpt->lock);
|
|
|
|
ast_softhangup(l->chan,AST_SOFTHANGUP_DEV);
|
|
|
|
rpt_telemetry(myrpt,CONNFAIL,l);
|
|
|
|
ast_mutex_lock(&myrpt->lock);
|
|
|
|
}
|
|
|
|
l = l->next;
|
|
|
|
}
|
2002-12-08 17:30:24 +00:00
|
|
|
if (myrpt->tailtimer) myrpt->tailtimer -= elap;
|
|
|
|
if (myrpt->tailtimer < 0) myrpt->tailtimer = 0;
|
|
|
|
if (myrpt->totimer) myrpt->totimer -= elap;
|
|
|
|
if (myrpt->totimer < 0) myrpt->totimer = 0;
|
|
|
|
if (myrpt->idtimer) myrpt->idtimer -= elap;
|
|
|
|
if (myrpt->idtimer < 0) myrpt->idtimer = 0;
|
2004-06-21 04:24:50 +00:00
|
|
|
ast_mutex_unlock(&myrpt->lock);
|
2002-12-08 17:30:24 +00:00
|
|
|
if (!ms) continue;
|
|
|
|
if (who == myrpt->rxchannel) /* if it was a read from rx */
|
|
|
|
{
|
|
|
|
f = ast_read(myrpt->rxchannel);
|
|
|
|
if (!f)
|
|
|
|
{
|
|
|
|
if (debug) printf("@@@@ rpt:Hung Up\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (f->frametype == AST_FRAME_VOICE)
|
|
|
|
{
|
|
|
|
ast_write(myrpt->pchannel,f);
|
|
|
|
}
|
|
|
|
else if (f->frametype == AST_FRAME_DTMF)
|
|
|
|
{
|
|
|
|
char c;
|
|
|
|
|
|
|
|
c = (char) f->subclass; /* get DTMF char */
|
2004-06-21 04:24:50 +00:00
|
|
|
if (c == '#')
|
|
|
|
{
|
|
|
|
/* if in simple mode, kill autopatch */
|
|
|
|
if (myrpt->simple && myrpt->callmode)
|
|
|
|
{
|
|
|
|
myrpt->callmode = 0;
|
|
|
|
rpt_telemetry(myrpt,TERM,NULL);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
ast_mutex_lock(&myrpt->lock);
|
|
|
|
if (myrpt->cmdnode[0])
|
|
|
|
{
|
|
|
|
myrpt->cmdnode[0] = 0;
|
|
|
|
myrpt->dtmfidx = -1;
|
|
|
|
myrpt->dtmfbuf[0] = 0;
|
|
|
|
ast_mutex_unlock(&myrpt->lock);
|
|
|
|
rpt_telemetry(myrpt,COMPLETE,NULL);
|
|
|
|
} else ast_mutex_unlock(&myrpt->lock);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (myrpt->cmdnode[0])
|
|
|
|
{
|
|
|
|
send_link_dtmf(myrpt,c);
|
|
|
|
continue;
|
|
|
|
}
|
2004-05-31 16:04:10 +00:00
|
|
|
if (!myrpt->simple)
|
2002-12-08 17:30:24 +00:00
|
|
|
{
|
2004-05-31 16:04:10 +00:00
|
|
|
if (c == '*')
|
|
|
|
{
|
2004-06-21 04:24:50 +00:00
|
|
|
myrpt->dtmfidx = 0;
|
|
|
|
myrpt->dtmfbuf[myrpt->dtmfidx] = 0;
|
2004-05-31 16:04:10 +00:00
|
|
|
time(&dtmf_time);
|
|
|
|
continue;
|
|
|
|
}
|
2004-06-21 04:24:50 +00:00
|
|
|
else if ((c != '#') && (myrpt->dtmfidx >= 0))
|
2004-05-31 16:04:10 +00:00
|
|
|
{
|
|
|
|
time(&dtmf_time);
|
2004-06-21 04:24:50 +00:00
|
|
|
if (myrpt->dtmfidx < MAXDTMF)
|
2004-05-31 16:04:10 +00:00
|
|
|
{
|
2004-06-21 04:24:50 +00:00
|
|
|
myrpt->dtmfbuf[myrpt->dtmfidx++] = c;
|
|
|
|
myrpt->dtmfbuf[myrpt->dtmfidx] = 0;
|
|
|
|
/* if to terminate function now */
|
|
|
|
if ((myrpt->dtmfidx == 1) && strchr(SHORTFUNCS,c))
|
|
|
|
{
|
|
|
|
while(myrpt->dtmfidx < FUNCTION_LEN)
|
|
|
|
myrpt->dtmfbuf[myrpt->dtmfidx++] = '0';
|
|
|
|
myrpt->dtmfbuf[myrpt->dtmfidx] = 0;
|
|
|
|
}
|
2004-06-25 19:33:22 +00:00
|
|
|
/* if to terminate function now */
|
|
|
|
if ((myrpt->dtmfidx == 2) && strchr(MEDFUNCS,myrpt->dtmfbuf[0]))
|
|
|
|
{
|
|
|
|
while(myrpt->dtmfidx < FUNCTION_LEN)
|
|
|
|
myrpt->dtmfbuf[myrpt->dtmfidx++] = '0';
|
|
|
|
myrpt->dtmfbuf[myrpt->dtmfidx] = 0;
|
|
|
|
}
|
2004-05-31 16:04:10 +00:00
|
|
|
}
|
2004-06-21 04:24:50 +00:00
|
|
|
if (myrpt->dtmfidx == FUNCTION_LEN)
|
2004-05-31 16:04:10 +00:00
|
|
|
{
|
2004-06-21 04:24:50 +00:00
|
|
|
process_dtmf(myrpt->dtmfbuf,myrpt,1);
|
|
|
|
myrpt->dtmfbuf[0] = 0;
|
|
|
|
myrpt->dtmfidx = -1;
|
2004-05-31 16:04:10 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ((!myrpt->callmode) && (c == '*'))
|
|
|
|
{
|
|
|
|
myrpt->callmode = 1;
|
|
|
|
myrpt->cidx = 0;
|
|
|
|
myrpt->exten[myrpt->cidx] = 0;
|
|
|
|
pthread_attr_init(&attr);
|
|
|
|
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
|
|
|
|
pthread_create(&myrpt->rpt_call_thread,&attr,rpt_call,(void *)myrpt);
|
|
|
|
continue;
|
|
|
|
}
|
2002-12-08 17:30:24 +00:00
|
|
|
}
|
|
|
|
if (myrpt->callmode == 1)
|
|
|
|
{
|
|
|
|
myrpt->exten[myrpt->cidx++] = c;
|
|
|
|
myrpt->exten[myrpt->cidx] = 0;
|
|
|
|
/* if this exists */
|
|
|
|
if (ast_exists_extension(myrpt->pchannel,myrpt->ourcontext,myrpt->exten,1,NULL))
|
|
|
|
{
|
|
|
|
myrpt->callmode = 2;
|
2004-06-21 04:24:50 +00:00
|
|
|
rpt_telemetry(myrpt,PROC,NULL);
|
2002-12-08 17:30:24 +00:00
|
|
|
}
|
|
|
|
/* if can continue, do so */
|
|
|
|
if (ast_canmatch_extension(myrpt->pchannel,myrpt->ourcontext,myrpt->exten,1,NULL)) continue;
|
|
|
|
/* call has failed, inform user */
|
|
|
|
myrpt->callmode = 4;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if ((myrpt->callmode == 2) || (myrpt->callmode == 3))
|
|
|
|
{
|
|
|
|
myrpt->mydtmf = f->subclass;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (f->frametype == AST_FRAME_CONTROL)
|
|
|
|
{
|
|
|
|
if (f->subclass == AST_CONTROL_HANGUP)
|
|
|
|
{
|
|
|
|
if (debug) printf("@@@@ rpt:Hung Up\n");
|
|
|
|
ast_frfree(f);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* if RX key */
|
|
|
|
if (f->subclass == AST_CONTROL_RADIO_KEY)
|
|
|
|
{
|
|
|
|
if (debug) printf("@@@@ rx key\n");
|
|
|
|
keyed = 1;
|
|
|
|
}
|
|
|
|
/* if RX un-key */
|
|
|
|
if (f->subclass == AST_CONTROL_RADIO_UNKEY)
|
|
|
|
{
|
|
|
|
if (debug) printf("@@@@ rx un-key\n");
|
|
|
|
keyed = 0;
|
2004-06-21 04:24:50 +00:00
|
|
|
/* if we have remotes, twiddle */
|
|
|
|
if (myrpt->cmdnode[0] || (myrpt->links.next != &myrpt->links))
|
2004-05-31 16:04:10 +00:00
|
|
|
{
|
2004-06-21 04:24:50 +00:00
|
|
|
rpt_telemetry(myrpt,UNKEY,NULL);
|
2004-05-31 16:04:10 +00:00
|
|
|
}
|
2002-12-08 17:30:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
ast_frfree(f);
|
2004-05-31 16:04:10 +00:00
|
|
|
continue;
|
2002-12-08 17:30:24 +00:00
|
|
|
}
|
|
|
|
if (who == myrpt->pchannel) /* if it was a read from pseudo */
|
|
|
|
{
|
|
|
|
f = ast_read(myrpt->pchannel);
|
|
|
|
if (!f)
|
|
|
|
{
|
|
|
|
if (debug) printf("@@@@ rpt:Hung Up\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (f->frametype == AST_FRAME_VOICE)
|
|
|
|
{
|
2004-06-21 04:24:50 +00:00
|
|
|
ast_write(myrpt->txpchannel,f);
|
2002-12-08 17:30:24 +00:00
|
|
|
}
|
|
|
|
if (f->frametype == AST_FRAME_CONTROL)
|
|
|
|
{
|
|
|
|
if (f->subclass == AST_CONTROL_HANGUP)
|
|
|
|
{
|
|
|
|
if (debug) printf("@@@@ rpt:Hung Up\n");
|
|
|
|
ast_frfree(f);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ast_frfree(f);
|
2004-05-31 16:04:10 +00:00
|
|
|
continue;
|
2002-12-08 17:30:24 +00:00
|
|
|
}
|
|
|
|
if (who == myrpt->txchannel) /* if it was a read from tx */
|
|
|
|
{
|
|
|
|
f = ast_read(myrpt->txchannel);
|
|
|
|
if (!f)
|
|
|
|
{
|
|
|
|
if (debug) printf("@@@@ rpt:Hung Up\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (f->frametype == AST_FRAME_CONTROL)
|
|
|
|
{
|
|
|
|
if (f->subclass == AST_CONTROL_HANGUP)
|
|
|
|
{
|
|
|
|
if (debug) printf("@@@@ rpt:Hung Up\n");
|
|
|
|
ast_frfree(f);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ast_frfree(f);
|
2004-05-31 16:04:10 +00:00
|
|
|
continue;
|
|
|
|
}
|
2004-06-21 04:24:50 +00:00
|
|
|
toexit = 0;
|
|
|
|
l = myrpt->links.next;
|
|
|
|
while(l != &myrpt->links)
|
2004-05-31 16:04:10 +00:00
|
|
|
{
|
2004-06-21 04:24:50 +00:00
|
|
|
if (who == l->chan) /* if it was a read from rx */
|
2004-05-31 16:04:10 +00:00
|
|
|
{
|
2004-06-21 04:24:50 +00:00
|
|
|
ast_mutex_lock(&myrpt->lock);
|
|
|
|
remrx = 0;
|
|
|
|
/* see if any other links are receiving */
|
|
|
|
m = myrpt->links.next;
|
|
|
|
while(m != &myrpt->links)
|
|
|
|
{
|
|
|
|
/* if not us, count it */
|
|
|
|
if ((m != l) && (m->lastrx)) remrx = 1;
|
|
|
|
m = m->next;
|
|
|
|
}
|
|
|
|
ast_mutex_unlock(&myrpt->lock);
|
|
|
|
totx = (((l->isremote) ? myrpt->localtx :
|
|
|
|
myrpt->exttx) || remrx) && l->mode;
|
|
|
|
if (l->lasttx != totx)
|
|
|
|
{
|
|
|
|
if (totx)
|
|
|
|
{
|
|
|
|
ast_indicate(l->chan,AST_CONTROL_RADIO_KEY);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ast_indicate(l->chan,AST_CONTROL_RADIO_UNKEY);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
l->lasttx = totx;
|
|
|
|
f = ast_read(l->chan);
|
|
|
|
if (!f)
|
|
|
|
{
|
|
|
|
ast_mutex_lock(&myrpt->lock);
|
|
|
|
/* remove from queue */
|
|
|
|
remque((struct qelem *) l);
|
2004-06-26 19:08:57 +00:00
|
|
|
if (!strcmp(myrpt->cmdnode,l->name))
|
|
|
|
myrpt->cmdnode[0] = 0;
|
2004-06-21 04:24:50 +00:00
|
|
|
ast_mutex_unlock(&myrpt->lock);
|
|
|
|
rpt_telemetry(myrpt,REMDISC,l);
|
|
|
|
/* hang-up on call to device */
|
|
|
|
ast_hangup(l->chan);
|
|
|
|
ast_hangup(l->pchan);
|
|
|
|
free(l);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (f->frametype == AST_FRAME_VOICE)
|
|
|
|
{
|
|
|
|
ast_write(l->pchan,f);
|
|
|
|
}
|
|
|
|
if (f->frametype == AST_FRAME_TEXT)
|
|
|
|
{
|
2004-06-25 19:33:22 +00:00
|
|
|
handle_link_data(myrpt,l,f->data);
|
2004-06-21 04:24:50 +00:00
|
|
|
}
|
|
|
|
if (f->frametype == AST_FRAME_CONTROL)
|
|
|
|
{
|
|
|
|
if (f->subclass == AST_CONTROL_ANSWER)
|
|
|
|
{
|
|
|
|
l->connected = 1;
|
|
|
|
l->elaptime = -1;
|
|
|
|
rpt_telemetry(myrpt,CONNECTED,l);
|
|
|
|
}
|
|
|
|
/* if RX key */
|
|
|
|
if (f->subclass == AST_CONTROL_RADIO_KEY)
|
|
|
|
{
|
|
|
|
if (debug) printf("@@@@ rx key\n");
|
|
|
|
l->lastrx = 1;
|
|
|
|
}
|
|
|
|
/* if RX un-key */
|
|
|
|
if (f->subclass == AST_CONTROL_RADIO_UNKEY)
|
|
|
|
{
|
|
|
|
if (debug) printf("@@@@ rx un-key\n");
|
|
|
|
l->lastrx = 0;
|
|
|
|
}
|
|
|
|
if (f->subclass == AST_CONTROL_HANGUP)
|
|
|
|
{
|
|
|
|
ast_frfree(f);
|
|
|
|
ast_mutex_lock(&myrpt->lock);
|
|
|
|
/* remove from queue */
|
|
|
|
remque((struct qelem *) l);
|
2004-06-26 19:08:57 +00:00
|
|
|
if (!strcmp(myrpt->cmdnode,l->name))
|
|
|
|
myrpt->cmdnode[0] = 0;
|
2004-06-21 04:24:50 +00:00
|
|
|
ast_mutex_unlock(&myrpt->lock);
|
|
|
|
rpt_telemetry(myrpt,REMDISC,l);
|
|
|
|
/* hang-up on call to device */
|
|
|
|
ast_hangup(l->chan);
|
|
|
|
ast_hangup(l->pchan);
|
|
|
|
free(l);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ast_frfree(f);
|
2004-05-31 16:04:10 +00:00
|
|
|
break;
|
|
|
|
}
|
2004-06-21 04:24:50 +00:00
|
|
|
if (who == l->pchan)
|
2004-05-31 16:04:10 +00:00
|
|
|
{
|
2004-06-21 04:24:50 +00:00
|
|
|
f = ast_read(l->pchan);
|
|
|
|
if (!f)
|
2004-05-31 16:04:10 +00:00
|
|
|
{
|
|
|
|
if (debug) printf("@@@@ rpt:Hung Up\n");
|
2004-06-21 04:24:50 +00:00
|
|
|
toexit = 1;
|
2004-05-31 16:04:10 +00:00
|
|
|
break;
|
|
|
|
}
|
2004-06-21 04:24:50 +00:00
|
|
|
if (f->frametype == AST_FRAME_VOICE)
|
2004-05-31 16:04:10 +00:00
|
|
|
{
|
2004-06-21 04:24:50 +00:00
|
|
|
ast_write(l->chan,f);
|
2004-05-31 16:04:10 +00:00
|
|
|
}
|
2004-06-21 04:24:50 +00:00
|
|
|
if (f->frametype == AST_FRAME_CONTROL)
|
2004-05-31 16:04:10 +00:00
|
|
|
{
|
2004-06-21 04:24:50 +00:00
|
|
|
if (f->subclass == AST_CONTROL_HANGUP)
|
2004-05-31 16:04:10 +00:00
|
|
|
{
|
2004-06-21 04:24:50 +00:00
|
|
|
if (debug) printf("@@@@ rpt:Hung Up\n");
|
|
|
|
ast_frfree(f);
|
|
|
|
toexit = 1;
|
|
|
|
break;
|
2004-05-31 16:04:10 +00:00
|
|
|
}
|
|
|
|
}
|
2004-06-21 04:24:50 +00:00
|
|
|
ast_frfree(f);
|
|
|
|
break;
|
2004-05-31 16:04:10 +00:00
|
|
|
}
|
2004-06-21 04:24:50 +00:00
|
|
|
l = l->next;
|
2004-05-31 16:04:10 +00:00
|
|
|
}
|
2004-06-21 04:24:50 +00:00
|
|
|
if (toexit) break;
|
|
|
|
if (who == myrpt->txpchannel) /* if it was a read from remote tx */
|
2004-05-31 16:04:10 +00:00
|
|
|
{
|
2004-06-21 04:24:50 +00:00
|
|
|
f = ast_read(myrpt->txpchannel);
|
2004-05-31 16:04:10 +00:00
|
|
|
if (!f)
|
|
|
|
{
|
|
|
|
if (debug) printf("@@@@ rpt:Hung Up\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (f->frametype == AST_FRAME_CONTROL)
|
|
|
|
{
|
|
|
|
if (f->subclass == AST_CONTROL_HANGUP)
|
|
|
|
{
|
|
|
|
if (debug) printf("@@@@ rpt:Hung Up\n");
|
|
|
|
ast_frfree(f);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ast_frfree(f);
|
|
|
|
continue;
|
2002-12-08 17:30:24 +00:00
|
|
|
}
|
|
|
|
}
|
2004-06-21 04:24:50 +00:00
|
|
|
ast_mutex_lock(&myrpt->lock);
|
2002-12-08 17:30:24 +00:00
|
|
|
ast_hangup(myrpt->pchannel);
|
2004-06-21 04:24:50 +00:00
|
|
|
ast_hangup(myrpt->txpchannel);
|
2002-12-08 17:30:24 +00:00
|
|
|
ast_hangup(myrpt->rxchannel);
|
2004-05-31 16:04:10 +00:00
|
|
|
if (myrpt->txchannel != myrpt->rxchannel) ast_hangup(myrpt->txchannel);
|
2004-06-21 04:24:50 +00:00
|
|
|
l = myrpt->links.next;
|
|
|
|
while(l != &myrpt->links)
|
2004-05-31 16:04:10 +00:00
|
|
|
{
|
2004-06-21 04:24:50 +00:00
|
|
|
struct rpt_link *ll = l;
|
|
|
|
/* remove from queue */
|
|
|
|
remque((struct qelem *) l);
|
|
|
|
/* hang-up on call to device */
|
|
|
|
ast_hangup(l->chan);
|
|
|
|
ast_hangup(l->pchan);
|
|
|
|
l = l->next;
|
|
|
|
free(ll);
|
2004-05-31 16:04:10 +00:00
|
|
|
}
|
2004-06-21 04:24:50 +00:00
|
|
|
ast_mutex_unlock(&myrpt->lock);
|
2002-12-08 17:30:24 +00:00
|
|
|
if (debug) printf("@@@@ rpt:Hung up channel\n");
|
2004-06-21 04:24:50 +00:00
|
|
|
pthread_exit(NULL);
|
2002-12-08 17:30:24 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *rpt_master(void *ignore)
|
|
|
|
{
|
|
|
|
char *this,*val;
|
|
|
|
int i,n;
|
|
|
|
|
|
|
|
/* start with blank config */
|
|
|
|
memset(&rpt_vars,0,sizeof(rpt_vars));
|
|
|
|
|
|
|
|
cfg = ast_load("rpt.conf");
|
|
|
|
if (!cfg) {
|
|
|
|
ast_log(LOG_NOTICE, "Unable to open radio repeater configuration rpt.conf. Radio Repeater disabled.\n");
|
|
|
|
pthread_exit(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* go thru all the specified repeaters */
|
|
|
|
this = NULL;
|
|
|
|
n = 0;
|
|
|
|
while((this = ast_category_browse(cfg,this)) != NULL)
|
|
|
|
{
|
2004-06-21 04:24:50 +00:00
|
|
|
if (!strcmp(this,NODES)) continue;
|
2004-06-26 18:06:17 +00:00
|
|
|
if (!strcmp(this,MEMORY)) continue;
|
2002-12-08 17:30:24 +00:00
|
|
|
ast_log(LOG_DEBUG,"Loading config for repeater %s\n",this);
|
2004-06-21 04:24:50 +00:00
|
|
|
ast_mutex_init(&rpt_vars[n].lock);
|
|
|
|
rpt_vars[n].tele.next = &rpt_vars[n].tele;
|
|
|
|
rpt_vars[n].tele.prev = &rpt_vars[n].tele;
|
2002-12-08 17:30:24 +00:00
|
|
|
rpt_vars[n].name = this;
|
|
|
|
rpt_vars[n].rxchanname = ast_variable_retrieve(cfg,this,"rxchannel");
|
|
|
|
rpt_vars[n].txchanname = ast_variable_retrieve(cfg,this,"txchannel");
|
|
|
|
rpt_vars[n].ourcontext = ast_variable_retrieve(cfg,this,"context");
|
|
|
|
if (!rpt_vars[n].ourcontext) rpt_vars[n].ourcontext = this;
|
|
|
|
rpt_vars[n].ourcallerid = ast_variable_retrieve(cfg,this,"callerid");
|
|
|
|
rpt_vars[n].acctcode = ast_variable_retrieve(cfg,this,"accountcode");
|
2004-06-21 04:24:50 +00:00
|
|
|
rpt_vars[n].ident = ast_variable_retrieve(cfg,this,"idrecording");
|
2002-12-08 17:30:24 +00:00
|
|
|
val = ast_variable_retrieve(cfg,this,"hangtime");
|
|
|
|
if (val) rpt_vars[n].hangtime = atoi(val);
|
|
|
|
else rpt_vars[n].hangtime = HANGTIME;
|
|
|
|
val = ast_variable_retrieve(cfg,this,"totime");
|
|
|
|
if (val) rpt_vars[n].totime = atoi(val);
|
|
|
|
else rpt_vars[n].totime = TOTIME;
|
|
|
|
val = ast_variable_retrieve(cfg,this,"idtime");
|
|
|
|
if (val) rpt_vars[n].idtime = atoi(val);
|
|
|
|
else rpt_vars[n].idtime = IDTIME;
|
2004-05-31 16:04:10 +00:00
|
|
|
val = ast_variable_retrieve(cfg,this,"simple");
|
|
|
|
if (val) rpt_vars[n].simple = ast_true(val);
|
|
|
|
else rpt_vars[n].simple = 0;
|
2004-06-21 04:24:50 +00:00
|
|
|
val = ast_variable_retrieve(cfg,this,"remote");
|
|
|
|
if (val) rpt_vars[n].remote = ast_true(val);
|
|
|
|
else rpt_vars[n].remote = 0;
|
2004-05-31 16:04:10 +00:00
|
|
|
rpt_vars[n].tonezone = ast_variable_retrieve(cfg,this,"tonezone");
|
2004-06-26 18:06:17 +00:00
|
|
|
val = ast_variable_retrieve(cfg,this,"iobase");
|
|
|
|
if (val) rpt_vars[n].iobase = atoi(val);
|
|
|
|
else rpt_vars[n].iobase = DEFAULT_IOBASE;
|
2002-12-08 17:30:24 +00:00
|
|
|
n++;
|
|
|
|
}
|
2004-06-21 04:24:50 +00:00
|
|
|
nrpts = n;
|
2002-12-08 17:30:24 +00:00
|
|
|
ast_log(LOG_DEBUG, "Total of %d repeaters configured.\n",n);
|
|
|
|
/* start em all */
|
|
|
|
for(i = 0; i < n; i++)
|
|
|
|
{
|
|
|
|
if (!rpt_vars[i].rxchanname)
|
|
|
|
{
|
2004-06-21 04:24:50 +00:00
|
|
|
ast_log(LOG_WARNING,"Did not specify rxchanname for node %s\n",rpt_vars[i].name);
|
2002-12-08 17:30:24 +00:00
|
|
|
pthread_exit(NULL);
|
|
|
|
}
|
2004-06-21 04:24:50 +00:00
|
|
|
/* if is a remote, dont start one for it */
|
2004-06-26 18:06:17 +00:00
|
|
|
if (rpt_vars[i].remote)
|
|
|
|
{
|
|
|
|
strcpy(rpt_vars[i].freq,"146.460");
|
|
|
|
strcpy(rpt_vars[i].rxpl,"100.0");
|
|
|
|
rpt_vars[i].offset = REM_SIMPLEX;
|
|
|
|
rpt_vars[i].powerlevel = REM_MEDPWR;
|
|
|
|
continue;
|
|
|
|
}
|
2004-06-21 04:24:50 +00:00
|
|
|
if (!rpt_vars[i].ident)
|
2002-12-08 17:30:24 +00:00
|
|
|
{
|
2004-06-21 04:24:50 +00:00
|
|
|
ast_log(LOG_WARNING,"Did not specify ident for node %s\n",rpt_vars[i].name);
|
2002-12-08 17:30:24 +00:00
|
|
|
pthread_exit(NULL);
|
|
|
|
}
|
2004-06-21 04:24:50 +00:00
|
|
|
pthread_create(&rpt_vars[i].rpt_thread,NULL,rpt,(void *) &rpt_vars[i]);
|
2002-12-08 17:30:24 +00:00
|
|
|
}
|
|
|
|
/* wait for first one to die (should be never) */
|
2004-06-21 04:24:50 +00:00
|
|
|
pthread_join(rpt_vars[0].rpt_thread,NULL);
|
2002-12-08 17:30:24 +00:00
|
|
|
pthread_exit(NULL);
|
|
|
|
}
|
|
|
|
|
2004-06-21 04:24:50 +00:00
|
|
|
static int rpt_exec(struct ast_channel *chan, void *data)
|
|
|
|
{
|
|
|
|
int res=-1,i,keyed = 0,rem_totx;
|
|
|
|
struct localuser *u;
|
|
|
|
char tmp[256];
|
|
|
|
char *options,*stringp,*tele;
|
|
|
|
struct rpt *myrpt;
|
|
|
|
struct ast_frame *f;
|
|
|
|
struct ast_channel *who;
|
|
|
|
struct ast_channel *cs[20];
|
|
|
|
struct rpt_link *l;
|
|
|
|
ZT_CONFINFO ci; /* conference info */
|
|
|
|
int ms,elap;
|
|
|
|
|
|
|
|
if (!data || ast_strlen_zero((char *)data)) {
|
|
|
|
ast_log(LOG_WARNING, "Rpt requires an argument (system node)\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
strncpy(tmp, (char *)data, sizeof(tmp)-1);
|
|
|
|
stringp=tmp;
|
|
|
|
strsep(&stringp, "|");
|
|
|
|
options = strsep(&stringp, "|");
|
|
|
|
myrpt = NULL;
|
|
|
|
/* see if we can find our specified one */
|
|
|
|
for(i = 0; i < nrpts; i++)
|
|
|
|
{
|
|
|
|
/* if name matches, assign it and exit loop */
|
|
|
|
if (!strcmp(tmp,rpt_vars[i].name))
|
|
|
|
{
|
|
|
|
myrpt = &rpt_vars[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (myrpt == NULL)
|
|
|
|
{
|
|
|
|
ast_log(LOG_WARNING, "Cannot find specified system node %s\n",tmp);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
/* if is not a remote */
|
|
|
|
if (!myrpt->remote)
|
|
|
|
{
|
|
|
|
char *b,*b1;
|
|
|
|
|
|
|
|
/* look at callerid to see what node this comes from */
|
|
|
|
if (!chan->callerid) /* if doesnt have callerid */
|
|
|
|
{
|
|
|
|
ast_log(LOG_WARNING, "Trying to use busy link on %s\n",tmp);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
ast_callerid_parse(chan->callerid,&b,&b1);
|
|
|
|
ast_shrink_phone_number(b1);
|
|
|
|
if (!strcmp(myrpt->name,b1))
|
|
|
|
{
|
|
|
|
ast_log(LOG_WARNING, "Trying to link to self!!\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
ast_mutex_lock(&myrpt->lock);
|
|
|
|
l = myrpt->links.next;
|
|
|
|
/* try to find this one in queue */
|
|
|
|
while(l != &myrpt->links)
|
|
|
|
{
|
|
|
|
/* if found matching string */
|
|
|
|
if (!strcmp(l->name,b1)) break;
|
2004-06-25 19:33:22 +00:00
|
|
|
l = l->next;
|
2004-06-21 04:24:50 +00:00
|
|
|
}
|
|
|
|
/* if found */
|
|
|
|
if (l != &myrpt->links)
|
|
|
|
{
|
|
|
|
/* remove from queue */
|
|
|
|
remque((struct qelem *) l);
|
|
|
|
ast_mutex_unlock(&myrpt->lock);
|
|
|
|
/* hang-up on call to device */
|
|
|
|
ast_hangup(l->chan);
|
|
|
|
ast_hangup(l->pchan);
|
|
|
|
free(l);
|
|
|
|
usleep(500000);
|
|
|
|
} else
|
|
|
|
ast_mutex_unlock(&myrpt->lock);
|
|
|
|
/* establish call in tranceive mode */
|
|
|
|
l = malloc(sizeof(struct rpt_link));
|
|
|
|
if (!l)
|
|
|
|
{
|
|
|
|
ast_log(LOG_WARNING, "Unable to malloc\n");
|
|
|
|
pthread_exit(NULL);
|
|
|
|
}
|
|
|
|
/* zero the silly thing */
|
|
|
|
memset((char *)l,0,sizeof(struct rpt_link));
|
|
|
|
l->mode = 1;
|
|
|
|
strncpy(l->name,b1,MAXNODESTR - 1);
|
|
|
|
l->isremote = 0;
|
|
|
|
l->chan = chan;
|
|
|
|
l->connected = 1;
|
|
|
|
ast_set_read_format(l->chan,AST_FORMAT_SLINEAR);
|
|
|
|
ast_set_write_format(l->chan,AST_FORMAT_SLINEAR);
|
|
|
|
/* allocate a pseudo-channel thru asterisk */
|
|
|
|
l->pchan = ast_request("zap",AST_FORMAT_SLINEAR,"pseudo");
|
|
|
|
if (!l->pchan)
|
|
|
|
{
|
|
|
|
fprintf(stderr,"rpt:Sorry unable to obtain pseudo channel\n");
|
|
|
|
pthread_exit(NULL);
|
|
|
|
}
|
|
|
|
ast_set_read_format(l->pchan,AST_FORMAT_SLINEAR);
|
|
|
|
ast_set_write_format(l->pchan,AST_FORMAT_SLINEAR);
|
|
|
|
/* make a conference for the tx */
|
|
|
|
ci.chan = 0;
|
|
|
|
ci.confno = myrpt->conf;
|
|
|
|
ci.confmode = ZT_CONF_CONF | ZT_CONF_LISTENER | ZT_CONF_TALKER;
|
|
|
|
/* first put the channel on the conference in proper mode */
|
|
|
|
if (ioctl(l->pchan->fds[0],ZT_SETCONF,&ci) == -1)
|
|
|
|
{
|
|
|
|
ast_log(LOG_WARNING, "Unable to set conference mode to Announce\n");
|
|
|
|
pthread_exit(NULL);
|
|
|
|
}
|
|
|
|
ast_mutex_lock(&myrpt->lock);
|
|
|
|
/* insert at end of queue */
|
|
|
|
insque((struct qelem *)l,(struct qelem *)myrpt->links.next);
|
|
|
|
ast_mutex_unlock(&myrpt->lock);
|
|
|
|
if (chan->_state != AST_STATE_UP) {
|
|
|
|
ast_answer(chan);
|
|
|
|
}
|
|
|
|
return AST_PBX_KEEPALIVE;
|
|
|
|
}
|
|
|
|
/* if remote, error if anyone else already linked */
|
|
|
|
if (myrpt->remoteon)
|
|
|
|
{
|
|
|
|
ast_mutex_unlock(&myrpt->lock);
|
|
|
|
ast_log(LOG_WARNING, "Trying to use busy link on %s\n",tmp);
|
|
|
|
return -1;
|
|
|
|
}
|
2004-06-26 18:06:17 +00:00
|
|
|
if (ioperm(myrpt->iobase,1,1) == -1)
|
|
|
|
{
|
|
|
|
ast_mutex_unlock(&myrpt->lock);
|
|
|
|
ast_log(LOG_WARNING, "Cant get io permission on IO port %x hex\n",myrpt->iobase);
|
|
|
|
return -1;
|
|
|
|
}
|
2004-06-21 04:24:50 +00:00
|
|
|
LOCAL_USER_ADD(u);
|
|
|
|
tele = strchr(myrpt->rxchanname,'/');
|
|
|
|
if (!tele)
|
|
|
|
{
|
|
|
|
fprintf(stderr,"rpt:Dial number must be in format tech/number\n");
|
|
|
|
ast_mutex_unlock(&myrpt->lock);
|
|
|
|
pthread_exit(NULL);
|
|
|
|
}
|
|
|
|
*tele++ = 0;
|
|
|
|
ast_mutex_lock(&myrpt->lock);
|
|
|
|
myrpt->rxchannel = ast_request(myrpt->rxchanname,AST_FORMAT_SLINEAR,tele);
|
|
|
|
if (myrpt->rxchannel)
|
|
|
|
{
|
|
|
|
ast_set_read_format(myrpt->rxchannel,AST_FORMAT_SLINEAR);
|
|
|
|
ast_set_write_format(myrpt->rxchannel,AST_FORMAT_SLINEAR);
|
|
|
|
myrpt->rxchannel->whentohangup = 0;
|
|
|
|
myrpt->rxchannel->appl = "Apprpt";
|
|
|
|
myrpt->rxchannel->data = "(Repeater Rx)";
|
|
|
|
if (option_verbose > 2)
|
|
|
|
ast_verbose(VERBOSE_PREFIX_3 "rpt (Rx) initiating call to %s/%s on %s\n",
|
|
|
|
myrpt->rxchanname,tele,myrpt->rxchannel->name);
|
|
|
|
ast_mutex_unlock(&myrpt->lock);
|
|
|
|
ast_call(myrpt->rxchannel,tele,999);
|
|
|
|
ast_mutex_lock(&myrpt->lock);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fprintf(stderr,"rpt:Sorry unable to obtain Rx channel\n");
|
|
|
|
ast_mutex_unlock(&myrpt->lock);
|
|
|
|
pthread_exit(NULL);
|
|
|
|
}
|
|
|
|
*--tele = '/';
|
|
|
|
if (myrpt->txchanname)
|
|
|
|
{
|
|
|
|
tele = strchr(myrpt->txchanname,'/');
|
|
|
|
if (!tele)
|
|
|
|
{
|
|
|
|
fprintf(stderr,"rpt:Dial number must be in format tech/number\n");
|
|
|
|
ast_mutex_unlock(&myrpt->lock);
|
|
|
|
pthread_exit(NULL);
|
|
|
|
}
|
|
|
|
*tele++ = 0;
|
|
|
|
myrpt->txchannel = ast_request(myrpt->txchanname,AST_FORMAT_SLINEAR,tele);
|
|
|
|
if (myrpt->txchannel)
|
|
|
|
{
|
|
|
|
ast_set_read_format(myrpt->txchannel,AST_FORMAT_SLINEAR);
|
|
|
|
ast_set_write_format(myrpt->txchannel,AST_FORMAT_SLINEAR);
|
|
|
|
myrpt->txchannel->whentohangup = 0;
|
|
|
|
myrpt->txchannel->appl = "Apprpt";
|
|
|
|
myrpt->txchannel->data = "(Repeater Rx)";
|
|
|
|
if (option_verbose > 2)
|
|
|
|
ast_verbose(VERBOSE_PREFIX_3 "rpt (Tx) initiating call to %s/%s on %s\n",
|
|
|
|
myrpt->txchanname,tele,myrpt->txchannel->name);
|
|
|
|
ast_mutex_unlock(&myrpt->lock);
|
|
|
|
ast_call(myrpt->txchannel,tele,999);
|
|
|
|
ast_mutex_lock(&myrpt->lock);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fprintf(stderr,"rpt:Sorry unable to obtain Tx channel\n");
|
|
|
|
ast_mutex_unlock(&myrpt->lock);
|
|
|
|
pthread_exit(NULL);
|
|
|
|
}
|
|
|
|
*--tele = '/';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
myrpt->txchannel = myrpt->rxchannel;
|
|
|
|
}
|
|
|
|
myrpt->remoterx = 0;
|
|
|
|
myrpt->remotetx = 0;
|
|
|
|
myrpt->remoteon = 1;
|
2004-06-26 18:06:17 +00:00
|
|
|
myrpt->dtmfidx = -1;
|
|
|
|
myrpt->dtmfbuf[0] = 0;
|
|
|
|
myrpt->dtmf_time_rem = 0;
|
2004-06-21 04:24:50 +00:00
|
|
|
ast_mutex_unlock(&myrpt->lock);
|
2004-06-26 18:06:17 +00:00
|
|
|
setrbi(myrpt);
|
2004-06-23 14:37:46 +00:00
|
|
|
ast_set_write_format(chan, AST_FORMAT_SLINEAR);
|
|
|
|
ast_set_read_format(chan, AST_FORMAT_SLINEAR);
|
2004-06-21 04:24:50 +00:00
|
|
|
/* if we are on 2w loop and are a remote, turn EC on */
|
|
|
|
if (myrpt->remote && (myrpt->rxchannel == myrpt->txchannel))
|
|
|
|
{
|
|
|
|
i = 128;
|
|
|
|
ioctl(myrpt->rxchannel->fds[0],ZT_ECHOCANCEL,&i);
|
|
|
|
}
|
|
|
|
if (chan->_state != AST_STATE_UP) {
|
|
|
|
ast_answer(chan);
|
|
|
|
}
|
|
|
|
cs[0] = chan;
|
|
|
|
cs[1] = myrpt->rxchannel;
|
|
|
|
for(;;)
|
|
|
|
{
|
|
|
|
if (ast_check_hangup(chan)) break;
|
|
|
|
if (ast_check_hangup(myrpt->rxchannel)) break;
|
|
|
|
ms = MSWAIT;
|
|
|
|
who = ast_waitfor_n(cs,2,&ms);
|
|
|
|
if (who == NULL) ms = 0;
|
|
|
|
elap = MSWAIT - ms;
|
|
|
|
if (!ms) continue;
|
|
|
|
rem_totx = keyed;
|
|
|
|
if (rem_totx && (!myrpt->remotetx))
|
|
|
|
{
|
|
|
|
myrpt->remotetx = 1;
|
|
|
|
ast_indicate(myrpt->txchannel,AST_CONTROL_RADIO_KEY);
|
|
|
|
}
|
|
|
|
if ((!rem_totx) && myrpt->remotetx)
|
|
|
|
{
|
|
|
|
myrpt->remotetx = 0;
|
|
|
|
ast_indicate(myrpt->txchannel,AST_CONTROL_RADIO_UNKEY);
|
|
|
|
}
|
|
|
|
if (who == chan) /* if it was a read from incomming */
|
|
|
|
{
|
|
|
|
f = ast_read(chan);
|
|
|
|
if (!f)
|
|
|
|
{
|
|
|
|
if (debug) printf("@@@@ link:Hung Up\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (f->frametype == AST_FRAME_VOICE)
|
|
|
|
{
|
|
|
|
/* if not transmitting, zero-out audio */
|
|
|
|
if (!myrpt->remotetx)
|
|
|
|
memset(f->data,0,f->datalen);
|
|
|
|
ast_write(myrpt->txchannel,f);
|
|
|
|
}
|
|
|
|
else if (f->frametype == AST_FRAME_TEXT)
|
|
|
|
{
|
2004-06-26 18:06:17 +00:00
|
|
|
if (handle_remote_data(myrpt,f->data,chan) == -1)
|
|
|
|
{
|
|
|
|
if (debug) printf("@@@@ rpt:Hung Up\n");
|
|
|
|
ast_frfree(f);
|
|
|
|
break;
|
|
|
|
}
|
2004-06-21 04:24:50 +00:00
|
|
|
}
|
|
|
|
else if (f->frametype == AST_FRAME_CONTROL)
|
|
|
|
{
|
|
|
|
if (f->subclass == AST_CONTROL_HANGUP)
|
|
|
|
{
|
|
|
|
if (debug) printf("@@@@ rpt:Hung Up\n");
|
|
|
|
ast_frfree(f);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* if RX key */
|
|
|
|
if (f->subclass == AST_CONTROL_RADIO_KEY)
|
|
|
|
{
|
|
|
|
if (debug) printf("@@@@ rx key\n");
|
|
|
|
keyed = 1;
|
|
|
|
}
|
|
|
|
/* if RX un-key */
|
|
|
|
if (f->subclass == AST_CONTROL_RADIO_UNKEY)
|
|
|
|
{
|
|
|
|
if (debug) printf("@@@@ rx un-key\n");
|
|
|
|
keyed = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ast_frfree(f);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (who == myrpt->rxchannel) /* if it was a read from radio */
|
|
|
|
{
|
|
|
|
f = ast_read(myrpt->rxchannel);
|
|
|
|
if (!f)
|
|
|
|
{
|
|
|
|
if (debug) printf("@@@@ link:Hung Up\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (f->frametype == AST_FRAME_VOICE)
|
|
|
|
{
|
|
|
|
if ((myrpt->remote) && (myrpt->remotetx))
|
|
|
|
memset(f->data,0,f->datalen);
|
|
|
|
ast_write(chan,f);
|
|
|
|
}
|
|
|
|
else if (f->frametype == AST_FRAME_CONTROL)
|
|
|
|
{
|
|
|
|
if (f->subclass == AST_CONTROL_HANGUP)
|
|
|
|
{
|
|
|
|
if (debug) printf("@@@@ rpt:Hung Up\n");
|
|
|
|
ast_frfree(f);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* if RX key */
|
|
|
|
if (f->subclass == AST_CONTROL_RADIO_KEY)
|
|
|
|
{
|
|
|
|
if (debug) printf("@@@@ remote rx key\n");
|
|
|
|
if (!myrpt->remotetx)
|
|
|
|
{
|
|
|
|
ast_indicate(chan,AST_CONTROL_RADIO_KEY);
|
|
|
|
myrpt->remoterx = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* if RX un-key */
|
|
|
|
if (f->subclass == AST_CONTROL_RADIO_UNKEY)
|
|
|
|
{
|
|
|
|
if (debug) printf("@@@@ remote rx un-key\n");
|
|
|
|
if (!myrpt->remotetx)
|
|
|
|
{
|
|
|
|
ast_indicate(chan,AST_CONTROL_RADIO_UNKEY);
|
|
|
|
myrpt->remoterx = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ast_frfree(f);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
ast_mutex_lock(&myrpt->lock);
|
|
|
|
if (myrpt->rxchannel != myrpt->txchannel) ast_hangup(myrpt->txchannel);
|
|
|
|
ast_hangup(myrpt->rxchannel);
|
|
|
|
myrpt->remoteon = 0;
|
|
|
|
ast_mutex_unlock(&myrpt->lock);
|
|
|
|
LOCAL_USER_REMOVE(u);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2002-12-08 17:30:24 +00:00
|
|
|
int unload_module(void)
|
|
|
|
{
|
2004-06-22 17:42:14 +00:00
|
|
|
int i;
|
2004-06-25 19:33:22 +00:00
|
|
|
|
2002-12-08 17:30:24 +00:00
|
|
|
STANDARD_HANGUP_LOCALUSERS;
|
2004-06-22 17:42:14 +00:00
|
|
|
for(i = 0; i < nrpts; i++) {
|
2004-06-25 19:33:22 +00:00
|
|
|
if (!strcmp(rpt_vars[i].name,NODES)) continue;
|
2004-06-22 17:42:14 +00:00
|
|
|
ast_mutex_destroy(&rpt_vars[i].lock);
|
2004-06-25 19:33:22 +00:00
|
|
|
}
|
2004-06-21 04:24:50 +00:00
|
|
|
return ast_unregister_application(app);
|
2002-12-08 17:30:24 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int load_module(void)
|
|
|
|
{
|
|
|
|
pthread_create(&rpt_master_thread,NULL,rpt_master,NULL);
|
2004-06-21 04:24:50 +00:00
|
|
|
return ast_register_application(app, rpt_exec, synopsis, descrip);
|
2002-12-08 17:30:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
char *description(void)
|
|
|
|
{
|
|
|
|
return tdesc;
|
|
|
|
}
|
|
|
|
|
|
|
|
int usecount(void)
|
|
|
|
{
|
|
|
|
int res;
|
|
|
|
STANDARD_USECOUNT(res);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *key()
|
|
|
|
{
|
|
|
|
return ASTERISK_GPL_KEY;
|
|
|
|
}
|