[asterisk-commits] jdixon: branch jdixon/chan_usbradio-1.4 r141990 - /team/jdixon/chan_usbradio-...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Tue Sep 9 01:16:34 CDT 2008
Author: jdixon
Date: Tue Sep 9 01:16:33 2008
New Revision: 141990
URL: http://svn.digium.com/view/asterisk?view=rev&rev=141990
Log:
Fixed startup with outgoing to reflectors
Modified:
team/jdixon/chan_usbradio-1.4/channels/chan_irlp.c
Modified: team/jdixon/chan_usbradio-1.4/channels/chan_irlp.c
URL: http://svn.digium.com/view/asterisk/team/jdixon/chan_usbradio-1.4/channels/chan_irlp.c?view=diff&rev=141990&r1=141989&r2=141990
==============================================================================
--- team/jdixon/chan_usbradio-1.4/channels/chan_irlp.c (original)
+++ team/jdixon/chan_usbradio-1.4/channels/chan_irlp.c Tue Sep 9 01:16:33 2008
@@ -31,7 +31,7 @@
/*** MODULEINFO
***/
-/* Version 0.8, 9/7/2008
+/* Version 0.9, 9/8/2008
irlp channel driver for Asterisk/app_rpt.
I wish to thank the following people for the immeasurable amount of
@@ -42,6 +42,7 @@
Skip, WB6YMH
Randy, KC6HUR
Steve, N4IRS
+Dixon Jim, K6JWN (not to be confused with Jim Dixon)
Eric, KA6UAI for putting up with a few miserable days of
testing using his on-the-air repeater
*/
@@ -79,8 +80,7 @@
#define MAX_RXKEY_TIME 4
-/* 50 * 10 * 20ms iax2 = 10,000ms = 10 seconds heartbeat */
-#define KEEPALIVE_TIME 50 * 10
+#define KEEPALIVE_TIME 10
#define QUEUE_OVERLOAD_THRESHOLD_AST 25
#define ADPCM_BLOCKING_FACTOR 6
@@ -142,9 +142,53 @@
char app[16];
char txkey;
int rxkey;
- int keepalive;
struct ast_frame fr;
struct ast_module_user *u;
+};
+
+struct rtcp_sdes_request_item {
+ unsigned char r_item;
+ char *r_text;
+};
+
+struct rtcp_sdes_request {
+ int nitems;
+ unsigned char ssrc[4];
+ struct rtcp_sdes_request_item item[10];
+};
+
+struct rtcp_common_t {
+#ifdef RTP_BIG_ENDIAN
+ uint8_t version:2;
+ uint8_t p:1;
+ uint8_t count:5;
+#else
+ uint8_t count:5;
+ uint8_t p:1;
+ uint8_t version:2;
+#endif
+ uint8_t pt:8;
+ uint16_t length;
+};
+
+struct rtcp_sdes_item_t {
+ uint8_t type;
+ uint8_t length;
+ char data[1];
+};
+
+struct rtcp_t {
+ struct rtcp_common_t common;
+ union {
+ struct {
+ uint32_t src[1];
+ } bye;
+
+ struct rtcp_sdes_t {
+ uint32_t src;
+ struct rtcp_sdes_item_t item[1];
+ } sdes;
+ } r;
};
/*
@@ -197,6 +241,7 @@
static unsigned int xcount = 0;
static char havedtmf = 0;
static char irlp_dtmf_string[64];
+time_t keepalive = 0;
#ifdef OLD_ASTERISK
#define ast_free free
@@ -213,8 +258,8 @@
static int irlp_digit_end(struct ast_channel *c, char digit, unsigned int duratiion);
static int irlp_text(struct ast_channel *c, const char *text);
static struct irlp_pvt *irlp_alloc(void *data);
+static int is_valid_rtcp(unsigned char *p, int len);
static int is_rtcp_bye(unsigned char *p, int len);
-static int is_valid_rtcp(unsigned char *p, int len);
static struct ast_channel *irlp_new(struct irlp_pvt *i, int state);
static const struct ast_channel_tech irlp_tech = {
@@ -240,6 +285,7 @@
if (alt_ctrl_sock != -1) close(alt_ctrl_sock);
alt_ctrl_sock = -1;
proto = IRLP_NOPROTO;
+ keepalive = 0;
in_node = 0;
nodenum = 0;
txindex = 0;
@@ -337,6 +383,95 @@
} while (p < end && (((p[0] >> 6) & 3) == 2));
return (p == end)?1:0;
+}
+
+static int rtcp_make_sdes(unsigned char *pkt, int pktLen)
+{
+ unsigned char zp[1500];
+ unsigned char *p = zp;
+ struct rtcp_t *rp;
+ unsigned char *ap;
+ char line[150];
+ int l, hl, pl;
+
+ hl = 0;
+ *p++ = 0x40;
+ *p++ = 201;
+ *p++ = 0;
+ *p++ = 1;
+ *((long *) p) = htonl(0x0310f987);
+ p += 4;
+ hl = 8;
+
+ rp = (struct rtcp_t *) p;
+ *((short *) p) = htons((2 << 14) | 202 | (1 << 8));
+ rp->r.sdes.src = htonl(0x0310f987);
+ ap = (unsigned char *) rp->r.sdes.item;
+
+ strcpy(line,"repeater at irlp.net");
+ *ap++ = 1;
+ *ap++ = l = strlen(line);
+ memcpy(ap,line,l);
+ ap += l;
+
+ strcpy(line,"SpeakFreely/IRLP");
+ *ap++ = 6;
+ *ap++ = l = strlen(line);
+ memcpy(ap,line,l);
+ ap += l;
+
+
+ *ap++ = 0;
+ *ap++ = 0;
+ *ap++ = 0xbf;
+ l = ap - p;
+
+ rp->common.length = htons(((l + 3) / 4) - 1);
+ l = hl + ((ntohs(rp->common.length) + 1) * 4);
+
+ pl = (l & 4) ? l : l + 4;
+
+ if (pl > l) {
+ int pad = pl - l;
+ memset(zp + l, '\0', pad);
+ zp[pl - 1] = pad;
+ p[0] |= 0x20;
+ rp->common.length = htons(ntohs(rp->common.length) + ((pad) / 4));
+ l = pl;
+ }
+
+ if (l > pktLen)
+ return 0;
+ memcpy(pkt,zp,l);
+ return l;
+}
+
+static void send_keepalive(void)
+{
+char buf[200],*cp;
+int len;
+struct sockaddr_in sin;
+
+ if (!*remote_irlp_node_ip)
+ {
+ cp = irlp_read_file(IRLP_ROOT,"calledip");
+ if (!cp) return;
+ if (cp[strlen(cp) - 1] == '\n')
+ cp[strlen(cp) - 1] = 0;
+ strncpy(buf,cp,sizeof(buf) - 1);
+ free(cp);
+ }
+ else
+ {
+ strncpy(buf,remote_irlp_node_ip,sizeof(buf) - 1);
+ }
+ sin.sin_family = AF_INET;
+ sin.sin_addr.s_addr = inet_addr(buf);
+ sin.sin_port = htons(tx_audio_port + 1);
+ len = rtcp_make_sdes((unsigned char *)buf,sizeof(buf) - 1);
+ sendto((alt_ctrl_sock != -1) ? alt_ctrl_sock : ctrl_sock,buf,len,
+ 0,(struct sockaddr *)&sin,sizeof(struct sockaddr));
+ return;
}
static int do_new_call(void)
@@ -438,7 +573,7 @@
fd_set fds[3];
struct timeval tmout;
- int i,myaud,myctl,x,was_outbound;
+ int i,myaud,myctl,x,was_outbound,seen_curcall;
char buf[LARGEST_PACKET_SIZE + 1];
struct sockaddr_in sin;
@@ -449,8 +584,10 @@
size_t len;
struct stat statbuf;
static int play_outbound = 0;
+ time_t now;
ast_log(LOG_NOTICE, "IRLP reader thread started.\n");
+ seen_curcall = 0;
while(run_forever)
{
if ((proto == IRLP_NOPROTO) && curcall) process_codec_file(curcall);
@@ -476,6 +613,16 @@
}
myaud = (alt_audio_sock != -1) ? alt_audio_sock : audio_sock;
myctl = (alt_ctrl_sock != -1) ? alt_ctrl_sock : ctrl_sock;
+
+ time(&now);
+ cp = irlp_read_file(IRLP_ROOT,"codec");
+ i = ((cp && *cp));
+ if (cp) free(cp);
+ if (i && keepalive && ((keepalive + KEEPALIVE_TIME) < now))
+ {
+ keepalive = now;
+ send_keepalive();
+ }
FD_ZERO(fds);
FD_SET(myaud,fds);
FD_SET(myctl,fds);
@@ -526,6 +673,7 @@
cp[strlen(cp) - 1] = 0;
in_node = atoi(cp + 3);
ast_log(LOG_NOTICE,"irlp node connected from %s node %s\n",ip,cp + 3);
+ keepalive = 0;
if (!curcall) do_new_call();
if ((!ready) && curcall)
{
@@ -542,10 +690,11 @@
fr.delivery.tv_sec = 0;
fr.delivery.tv_usec = 0;
ast_queue_frame(curcall,&fr);
+
}
ready = 1;
if (curcall && (proto == IRLP_NOPROTO)) process_codec_file(curcall);
- } else ast_log(LOG_NOTICE,"irlp node connected from %s\n", ip);
+ } else ast_log(LOG_NOTICE,"irlp node attempted connect from %s with no node info\n", ip);
if (cp) free(cp);
}
}
@@ -745,6 +894,7 @@
fcntl(alt_ctrl_sock,F_SETFL,O_NONBLOCK);
}
}
+ time(&keepalive);
return p;
}
@@ -1073,7 +1223,6 @@
}
cp = frame->data;
if (p->txkey || txindex) {
- p->keepalive = KEEPALIVE_TIME;
if ((proto == IRLP_ISADPCM) && (!txindex))
memcpy(tx_buf + (frame_size *
blocking_factor),cp + frame_size,3);
@@ -1141,17 +1290,6 @@
}
txindex = 0;
}
- if (p->txkey) return 0;
- if (p->keepalive--) return 0;
- p->keepalive = KEEPALIVE_TIME;
-
- /*
- If you made changes to this driver to
- make it run on an IRLP reflector channel,
- you must create and transmit keepalive packets.
- No need to send keepalive heartbeats if
- you are running this driver on an IRLP stnXXXX node.
- */
return 0;
}
@@ -1383,3 +1521,4 @@
AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "irlp channel driver");
+
More information about the asterisk-commits
mailing list