Freeswitch-svn
Threads by month
- ----- 2026 -----
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- 12151 discussions
10 Apr '07
Author: anthm
Date: Mon Apr 9 22:25:29 2007
New Revision: 4907
Modified:
freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c
freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h
freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c
Log:
fix rpid on gateways
Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c (original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c Mon Apr 9 22:25:29 2007
@@ -882,7 +882,7 @@
}
profile = gateway_ptr->profile;
- tech_pvt->from_str = switch_core_session_strdup(nsession, gateway_ptr->register_from);
+ tech_pvt->gateway_from_str = switch_core_session_strdup(nsession, gateway_ptr->register_from);
if (!strchr(dest, '@')) {
tech_pvt->dest = switch_core_session_sprintf(nsession, "sip:%s@%s", dest, gateway_ptr->register_proxy + 4);
} else {
Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h (original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h Mon Apr 9 22:25:29 2007
@@ -278,6 +278,7 @@
char *far_end_contact;
char *contact_url;
char *from_str;
+ char *gateway_from_str;
char *rm_encoding;
char *rm_fmtp;
char *fmtp_out;
Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c (original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c Mon Apr 9 22:25:29 2007
@@ -417,7 +417,8 @@
tech_pvt->nh = nua_handle(tech_pvt->profile->nua, NULL,
NUTAG_URL(url),
SIPTAG_TO_STR(tech_pvt->dest_to),
- SIPTAG_FROM_STR(tech_pvt->from_str),
+ TAG_IF(tech_pvt->gateway_from_str, SIPTAG_FROM_STR(tech_pvt->gateway_from_str)),
+ TAG_IF(!tech_pvt->gateway_from_str, SIPTAG_FROM_STR(tech_pvt->from_str)),
TAG_IF(tech_pvt->invite_contact, SIPTAG_CONTACT_STR(tech_pvt->invite_contact)),
TAG_IF(!tech_pvt->invite_contact, SIPTAG_CONTACT_STR(tech_pvt->profile->url)),
TAG_END());
1
0
Author: anthm
Date: Mon Apr 9 21:30:47 2007
New Revision: 4906
Added:
freeswitch/trunk/scripts/socket/socket2me/
freeswitch/trunk/scripts/socket/socket2me/Makefile
freeswitch/trunk/scripts/socket/socket2me/README
freeswitch/trunk/scripts/socket/socket2me/socket2me.c
Log:
socket2me
Added: freeswitch/trunk/scripts/socket/socket2me/Makefile
==============================================================================
--- (empty file)
+++ freeswitch/trunk/scripts/socket/socket2me/Makefile Mon Apr 9 21:30:47 2007
@@ -0,0 +1,4 @@
+socket2me: socket2me.c
+ $(CC) -Wall socket2me.c -o socket2me -l spandsp
+clean:
+ rm socket2me
Added: freeswitch/trunk/scripts/socket/socket2me/README
==============================================================================
--- (empty file)
+++ freeswitch/trunk/scripts/socket/socket2me/README Mon Apr 9 21:30:47 2007
@@ -0,0 +1,20 @@
+EXAMPLE OF EVENT SOCKET EXTERNAL APP: REQUIRES mod_event_socket
+
+Set this or something similar in your dialplan
+
+<extension name="fax">
+ <condition field="destination_number" expression="^866">
+ <action application="set" data="fax_file_name=/tmp/cool.tiff"/>
+ <!--"send" or "recv"-->
+ <action application="set" data="fax_mode=send"/>
+ <action application="socket" data="127.0.0.1:8084 async"/>
+ </condition>
+</extension>
+
+
+and in a separate process run
+#./socket2me 127.0.0.1 127.0.0.1 8084
+
+
+
+
Added: freeswitch/trunk/scripts/socket/socket2me/socket2me.c
==============================================================================
--- (empty file)
+++ freeswitch/trunk/scripts/socket/socket2me/socket2me.c Mon Apr 9 21:30:47 2007
@@ -0,0 +1,440 @@
+/*
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * * Neither the name of [original copyright holder] nor the names of
+ * its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written
+ * permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *
+ * Copyright (C) 2007, Anthony Minessale II <anthmct(a)yahoo.com>
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <arpa/inet.h>
+#include <sys/wait.h>
+#include <string.h>
+#include <unistd.h>
+#include <spandsp.h>
+
+#define SOCKET2ME_DEBUG 0
+#define MAXPENDING 10000
+#define RCVBUFSIZE 4198
+#define PORT_MIN 9000
+#define PORT_MAX 10000
+
+static int use_port = PORT_MIN;
+
+static void phase_b_handler(t30_state_t *s, void *user_data, int result)
+{
+ int session;
+ session = (intptr_t) user_data;
+
+ printf("Phase B handler on session %d - (0x%X) %s\n", session, result, t30_frametype(result));
+}
+
+static void phase_d_handler(t30_state_t *s, void *user_data, int result)
+{
+ int session;
+ char ident[21];
+ t30_stats_t t;
+
+ session = (intptr_t) user_data;
+
+ printf("Phase D handler on session %d - (0x%X) %s\n", session, result, t30_frametype(result));
+ t30_get_transfer_statistics(s, &t);
+ printf( "Phase D: bit rate %d\n", t.bit_rate);
+ printf( "Phase D: ECM %s\n", (t.error_correcting_mode) ? "on" : "off");
+ printf( "Phase D: pages transferred %d\n", t.pages_transferred);
+ printf( "Phase D: image size %d x %d\n", t.width, t.length);
+ printf( "Phase D: image resolution %d x %d\n", t.x_resolution, t.y_resolution);
+ printf( "Phase D: bad rows %d\n", t.bad_rows);
+ printf( "Phase D: longest bad row run %d\n", t.longest_bad_row_run);
+ printf( "Phase D: compression type %d\n", t.encoding);
+ printf( "Phase D: image size %d\n", t.image_size);
+ t30_get_local_ident(s, ident);
+ printf( "Phase D: local ident '%s'\n", ident);
+ t30_get_far_ident(s, ident);
+ printf( "Phase D: remote ident '%s'\n", ident);
+}
+
+static void phase_e_handler(t30_state_t *s, void *user_data, int result)
+{
+ int session;
+ t30_stats_t t;
+ const char *u;
+ char ident[21];
+
+ session = (intptr_t) user_data;
+ printf("Phase E handler on session %d - (%d) %s\n", session, result, t30_completion_code_to_str(result));
+ t30_get_transfer_statistics(s, &t);
+ printf( "Phase E: bit rate %d\n", t.bit_rate);
+ printf( "Phase E: ECM %s\n", (t.error_correcting_mode) ? "on" : "off");
+ printf( "Phase E: pages transferred %d\n", t.pages_transferred);
+ printf( "Phase E: image size %d x %d\n", t.width, t.length);
+ printf( "Phase E: image resolution %d x %d\n", t.x_resolution, t.y_resolution);
+ printf( "Phase E: bad rows %d\n", t.bad_rows);
+ printf( "Phase E: longest bad row run %d\n", t.longest_bad_row_run);
+ printf( "Phase E: coding method %s\n", t4_encoding_to_str(t.encoding));
+ printf( "Phase E: image size %d bytes\n", t.image_size);
+ t30_get_local_ident(s, ident);
+ printf( "Phase E: local ident '%s'\n", ident);
+ t30_get_far_ident(s, ident);
+ printf( "Phase E: remote ident '%s'\n", ident);
+ if ((u = t30_get_far_country(s)))
+ printf( "Phase E: Remote was made in '%s'\n", u);
+ if ((u = t30_get_far_vendor(s)))
+ printf( "Phase E: Remote was made by '%s'\n", u);
+ if ((u = t30_get_far_model(s)))
+ printf( "Phase E: Remote is model '%s'\n", u);
+}
+
+static int document_handler(t30_state_t *s, void *user_data, int event)
+{
+ int session;
+
+ session = (intptr_t) user_data;
+ printf("Document handler on session %d - event %d\n", session, event);
+ return FALSE;
+}
+
+void die(char *error_str)
+{
+ perror(error_str);
+ exit(1);
+}
+
+
+static int cheezy_get_var(char *data, char *name, char *buf, size_t buflen)
+{
+ char *p;
+
+ if ((p = strstr(data, name))) {
+ char *v, *e;
+
+ if ((v = strchr(p, ':'))) {
+ v++;
+ while(v && *v == ' ') {
+ v++;
+ }
+ if (v) {
+ if (!(e = strchr(v, '\r'))) {
+ e = strchr(v, '\n');
+ }
+ }
+
+ if (v && e) {
+ int cplen;
+ int len = e - v;
+
+ if (len > buflen - 1) {
+ cplen = buflen -1;
+ } else {
+ cplen = len;
+ }
+
+ strncpy(buf, v, cplen);
+ *(buf+cplen) = '\0';
+ return 1;
+ }
+
+ }
+ }
+ return 0;
+}
+
+void client_run(int client_socket, char *local_ip, int local_port, char *remote_ip, int remote_port)
+{
+ char sendbuf[RCVBUFSIZE], recvbuf[RCVBUFSIZE], infobuf[RCVBUFSIZE];
+ struct sockaddr_in addr = {0}, sendaddr = {0};
+ int read_bytes;
+ int usock;
+ int reuse_addr = 1;
+ fax_state_t fax;
+ char tmp[512], fn[512], *file_name = "/tmp/test.tiff";
+ int send_fax = FALSE;
+
+ snprintf(sendbuf, sizeof(sendbuf), "connect\n\n");
+ send(client_socket, sendbuf, strlen(sendbuf), 0);
+
+ if ((read_bytes = recv(client_socket, infobuf, sizeof(infobuf), 0)) < 0) {
+ die("recv() failed");
+ }
+
+#if SOCKET2ME_DEBUG
+ printf("READ [%s]\n", infobuf);
+#endif
+ snprintf(sendbuf, sizeof(sendbuf), "sendmsg\n"
+ "call-command: unicast\n"
+ "local_ip: %s\n"
+ "local_port: %d\n"
+ "remote_ip: %s\n"
+ "remote_port: %d\n"
+ "transport: udp\n\n",
+ local_ip, local_port,
+ remote_ip, remote_port
+ );
+
+ if (cheezy_get_var(infobuf, "variable_fax_file_name", fn, sizeof(fn))) {
+ file_name = fn;
+ }
+
+ if (cheezy_get_var(infobuf, "variable_fax_mode", tmp, sizeof(tmp))) {
+ if (!strcasecmp(tmp, "send")) {
+ send_fax = TRUE;
+ }
+ }
+#if SOCKET2ME_DEBUG
+ printf("SEND: [%s]\n", sendbuf);
+#endif
+ send(client_socket, sendbuf, strlen(sendbuf), 0);
+
+ memset(recvbuf, 0, sizeof(recvbuf));
+ if ((read_bytes = recv(client_socket, recvbuf, sizeof(recvbuf), 0)) < 0) {
+ die("recv() failed");
+ }
+#if SOCKET2ME_DEBUG
+ printf("READ [%s]\n", recvbuf);
+#endif
+
+ if ((usock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
+ die("socket() failed");
+ }
+
+ setsockopt(usock, SOL_SOCKET, SO_REUSEADDR, &reuse_addr, sizeof(reuse_addr));
+
+ addr.sin_family = AF_INET;
+ addr.sin_addr.s_addr = htonl(INADDR_ANY);
+ sendaddr.sin_addr.s_addr = inet_addr(remote_ip);
+ addr.sin_port = htons(remote_port);
+
+ sendaddr.sin_family = AF_INET;
+ sendaddr.sin_addr.s_addr = inet_addr(local_ip);
+ sendaddr.sin_port = htons(local_port);
+
+ if (bind(usock, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
+ die("bind() failed");
+ }
+
+ printf("%s Fax filename: [%s] from %s:%d -> %s:%d\n", send_fax ? "Sending" : "Receiving", file_name, local_ip, local_port, remote_ip, remote_port);
+
+ fax_init(&fax, send_fax);
+ t30_set_local_ident(&fax.t30_state, "Socket 2 ME");
+ t30_set_header_info(&fax.t30_state, "Socket 2 ME");
+ if (send_fax) {
+ t30_set_tx_file(&fax.t30_state, file_name, -1, -1);
+ } else {
+ t30_set_rx_file(&fax.t30_state, file_name, -1);
+ }
+ t30_set_phase_b_handler(&fax.t30_state, phase_b_handler, NULL);
+ t30_set_phase_d_handler(&fax.t30_state, phase_d_handler, NULL);
+ t30_set_phase_e_handler(&fax.t30_state, phase_e_handler, NULL);
+ t30_set_document_handler(&fax.t30_state, document_handler, NULL);
+
+ t30_set_ecm_capability(&fax.t30_state, TRUE);
+ t30_set_supported_compressions(&fax.t30_state, T30_SUPPORT_T4_1D_COMPRESSION | T30_SUPPORT_T4_2D_COMPRESSION | T30_SUPPORT_T6_COMPRESSION);
+
+ t30_set_supported_image_sizes(&fax.t30_state, T30_SUPPORT_US_LETTER_LENGTH | T30_SUPPORT_US_LEGAL_LENGTH | T30_SUPPORT_UNLIMITED_LENGTH
+ | T30_SUPPORT_215MM_WIDTH | T30_SUPPORT_255MM_WIDTH | T30_SUPPORT_303MM_WIDTH);
+ t30_set_supported_resolutions(&fax.t30_state, T30_SUPPORT_STANDARD_RESOLUTION | T30_SUPPORT_FINE_RESOLUTION | T30_SUPPORT_SUPERFINE_RESOLUTION
+ | T30_SUPPORT_R8_RESOLUTION | T30_SUPPORT_R16_RESOLUTION);
+
+ for (;;) {
+ struct sockaddr_in local_addr = {0};
+ int cliAddrLen = sizeof(local_addr);
+ short audioBuffer[1024], outbuf[1024];
+ int tx, bigger;
+ fd_set ready;
+
+ FD_ZERO(&ready);
+
+ FD_SET(usock, &ready);
+ FD_SET(client_socket, &ready);
+
+ bigger = usock > client_socket ? usock : client_socket;
+ select(++bigger, &ready, NULL, NULL, NULL);
+
+ if (FD_ISSET(client_socket, &ready)) {
+ memset(recvbuf, 0, sizeof(recvbuf));
+ if ((read_bytes = recv(client_socket, recvbuf, sizeof(recvbuf), 0)) < 0) {
+ die("recv() failed");
+ }
+
+ if (read_bytes == 0) {
+ break;
+ }
+#if SOCKET2ME_DEBUG
+ printf("READ [%s]\n", recvbuf);
+#endif
+ }
+
+ if (!FD_ISSET(usock, &ready)) {
+ continue;
+ }
+
+ if ((read_bytes = recvfrom(usock, audioBuffer, sizeof(audioBuffer), 0, (struct sockaddr *) &local_addr, &cliAddrLen)) < 0) {
+ die("recvfrom() failed");
+ }
+
+ fax_rx(&fax, (int16_t *)audioBuffer, read_bytes / 2);
+#if SOCKET2ME_DEBUG
+ printf("Handling client %s:%d %d bytes\n", inet_ntoa(local_addr.sin_addr), ntohs(local_addr.sin_port), read_bytes);
+#endif
+ if ((tx = fax_tx(&fax, (int16_t *) &outbuf, read_bytes / 2)) < 0) {
+ printf("Fax Error\n");
+ break;
+ } else if (!tx) {
+ continue;
+ }
+
+ cliAddrLen = sizeof(sendaddr);
+ if (sendto(usock, outbuf, tx * 2, 0, (struct sockaddr *) &sendaddr, sizeof(sendaddr)) != tx * 2) {
+ die("sendto() sent a different number of bytes than expected");
+ }
+ }
+
+ close(client_socket);
+ close(usock);
+
+ t30_terminate(&fax.t30_state);
+ fax_release(&fax);
+
+ printf("Done\n");
+ snprintf(sendbuf, sizeof(sendbuf), "hangup\n\n");
+ send(client_socket, sendbuf, strlen(sendbuf), 0);
+
+}
+
+int client_accept(int servSock)
+{
+ int client_sock;
+ struct sockaddr_in echoClntAddr;
+ unsigned int clntLen;
+
+ clntLen = sizeof(echoClntAddr);
+
+ if ((client_sock = accept(servSock, (struct sockaddr *) &echoClntAddr, &clntLen)) < 0) {
+ die("accept() failed");
+ }
+
+ printf("Client Connect: [%s]\n", inet_ntoa(echoClntAddr.sin_addr));
+
+ return client_sock;
+}
+
+int main(int argc, char *argv[])
+{
+ int servSock, client_sock;
+ int port = 8084;
+ struct sockaddr_in addr;
+ pid_t pid;
+ unsigned int process_count = 0;
+ int reuse_addr = 1;
+ char *local_ip = NULL;
+ char *remote_ip = NULL;
+ char *signal_port_name = NULL;
+
+ if (argc > 0) {
+ local_ip = argv[1];
+ }
+ if (argc > 1) {
+ remote_ip = argv[2];
+ }
+ if (argc > 2) {
+ signal_port_name = argv[3];
+ }
+
+ if (!local_ip) {
+ local_ip = "127.0.0.1";
+ }
+
+ if (!remote_ip) {
+ remote_ip = "127.0.0.1";
+ }
+
+ if (signal_port_name) {
+ port = atoi(signal_port_name);
+ }
+
+ if ((servSock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) {
+ die("Socket Error!\n");
+ }
+ setsockopt(servSock, SOL_SOCKET, SO_REUSEADDR, &reuse_addr, sizeof(reuse_addr));
+
+ memset(&addr, 0, sizeof(addr));
+ addr.sin_family = AF_INET;
+ addr.sin_addr.s_addr = htonl(INADDR_ANY);
+ addr.sin_port = htons(port);
+
+ if (bind(servSock, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
+ die("Bind Error!\n");
+ return -1;
+ }
+
+ if (listen(servSock, MAXPENDING) < 0) {
+ die("Listen error\n");
+ return -1;
+ }
+ for (;;) {
+ int local_port = use_port++;
+ int remote_port = use_port++;
+
+ if (use_port++ >= PORT_MAX) {
+ use_port = PORT_MIN;
+ }
+
+ client_sock = client_accept(servSock);
+
+ if ((pid = fork()) < 0) {
+ die("fork() failed");
+ } else if (pid == 0) {
+
+ close(servSock);
+
+ client_run(client_sock, local_ip, local_port, remote_ip, remote_port);
+ exit(0);
+ }
+
+#if SOCKET2ME_DEBUG
+ printf("with child process: %d\n", (int) pid);
+#endif
+ close(client_sock);
+ process_count++;
+
+ while (process_count) {
+ pid = waitpid((pid_t) -1, NULL, WNOHANG);
+ if (pid < 0) {
+ die("waitpid() failed");
+ } else if (pid == 0) {
+ break;
+ } else {
+ process_count--;
+ }
+ }
+ }
+}
1
0
10 Apr '07
Author: anthm
Date: Mon Apr 9 21:16:14 2007
New Revision: 4905
Modified:
freeswitch/trunk/src/mod/endpoints/mod_wanpipe/mod_wanpipe.c
Log:
update
Modified: freeswitch/trunk/src/mod/endpoints/mod_wanpipe/mod_wanpipe.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_wanpipe/mod_wanpipe.c (original)
+++ freeswitch/trunk/src/mod/endpoints/mod_wanpipe/mod_wanpipe.c Mon Apr 9 21:16:14 2007
@@ -665,10 +665,10 @@
} else if (tech_pvt->spri) {
chanmap = tech_pvt->spri->private_info;
- if (!switch_test_flag(tech_pvt, TFLAG_BYE)) {
+ //if (!switch_test_flag(tech_pvt, TFLAG_BYE)) {
pri_hangup(tech_pvt->spri->pri, tech_pvt->call, switch_channel_get_cause(channel));
pri_destroycall(tech_pvt->spri->pri, tech_pvt->call);
- }
+ //}
switch_mutex_lock(globals.channel_mutex);
*chanmap->map[tech_pvt->callno] = '\0';
1
0
09 Apr '07
Author: anthm
Date: Mon Apr 9 18:26:03 2007
New Revision: 4904
Modified:
freeswitch/trunk/src/mod/endpoints/mod_wanpipe/mod_wanpipe.c
Log:
woops
Modified: freeswitch/trunk/src/mod/endpoints/mod_wanpipe/mod_wanpipe.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_wanpipe/mod_wanpipe.c (original)
+++ freeswitch/trunk/src/mod/endpoints/mod_wanpipe/mod_wanpipe.c Mon Apr 9 18:26:03 2007
@@ -278,7 +278,7 @@
FD_ZERO(&oob);
for(i = 0; i < globals.fxs_index; i++) {
- inFD_ZERO(&oob)t fd;
+ int fd;
assert(FXS_ANALOG_CHANNELS[i]);
assert(FXS_ANALOG_CHANNELS[i]->sock);
1
0
[commit] r4903 - in freeswitch/trunk/src/mod/endpoints/mod_wanpipe: . libsangoma
by Freeswitch SVN 09 Apr '07
by Freeswitch SVN 09 Apr '07
09 Apr '07
Author: anthm
Date: Mon Apr 9 18:16:52 2007
New Revision: 4903
Modified:
freeswitch/trunk/src/mod/endpoints/mod_wanpipe/libsangoma/libsangoma.c
freeswitch/trunk/src/mod/endpoints/mod_wanpipe/libsangoma/libsangoma.h
freeswitch/trunk/src/mod/endpoints/mod_wanpipe/mod_wanpipe.c
Log:
update
Modified: freeswitch/trunk/src/mod/endpoints/mod_wanpipe/libsangoma/libsangoma.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_wanpipe/libsangoma/libsangoma.c (original)
+++ freeswitch/trunk/src/mod/endpoints/mod_wanpipe/libsangoma/libsangoma.c Mon Apr 9 18:16:52 2007
@@ -464,7 +464,7 @@
* Execute TDM command
*
*/
-static int sangoma_tdm_cmd_exec(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api)
+int sangoma_tdm_cmd_exec(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api)
{
int err;
Modified: freeswitch/trunk/src/mod/endpoints/mod_wanpipe/libsangoma/libsangoma.h
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_wanpipe/libsangoma/libsangoma.h (original)
+++ freeswitch/trunk/src/mod/endpoints/mod_wanpipe/libsangoma/libsangoma.h Mon Apr 9 18:16:52 2007
@@ -159,6 +159,7 @@
int sangoma_tdm_disable_rxhook_events(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api);
int sangoma_tdm_get_fe_alarms(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api);
+int sangoma_tdm_cmd_exec(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api);
#ifndef LIBSANGOMA_GET_HWCODING
#define LIBSANGOMA_GET_HWCODING 1
Modified: freeswitch/trunk/src/mod/endpoints/mod_wanpipe/mod_wanpipe.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_wanpipe/mod_wanpipe.c (original)
+++ freeswitch/trunk/src/mod/endpoints/mod_wanpipe/mod_wanpipe.c Mon Apr 9 18:16:52 2007
@@ -278,7 +278,7 @@
FD_ZERO(&oob);
for(i = 0; i < globals.fxs_index; i++) {
- int fd;
+ inFD_ZERO(&oob)t fd;
assert(FXS_ANALOG_CHANNELS[i]);
assert(FXS_ANALOG_CHANNELS[i]->sock);
1
0
[commit] r4902 - in freeswitch/trunk/src/mod/endpoints/mod_wanpipe: . libsangoma
by Freeswitch SVN 09 Apr '07
by Freeswitch SVN 09 Apr '07
09 Apr '07
Author: anthm
Date: Mon Apr 9 15:27:59 2007
New Revision: 4902
Added:
freeswitch/trunk/src/mod/endpoints/mod_wanpipe/lib_api.c
freeswitch/trunk/src/mod/endpoints/mod_wanpipe/testapp.c
Modified:
freeswitch/trunk/src/mod/endpoints/mod_wanpipe/Makefile
freeswitch/trunk/src/mod/endpoints/mod_wanpipe/libsangoma/libsangoma.c
freeswitch/trunk/src/mod/endpoints/mod_wanpipe/libsangoma/libsangoma.h
freeswitch/trunk/src/mod/endpoints/mod_wanpipe/mod_wanpipe.c
Log:
update
Modified: freeswitch/trunk/src/mod/endpoints/mod_wanpipe/Makefile
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_wanpipe/Makefile (original)
+++ freeswitch/trunk/src/mod/endpoints/mod_wanpipe/Makefile Mon Apr 9 15:27:59 2007
@@ -3,20 +3,23 @@
LIBPRI=libpri-1.2.4
LIBPRI_FILE=$(LIBPRI).tar.gz
LIBPRI_DIR=$(BASE)/libs/$(LIBPRI)
-WANPIPE=wanpipe-3.1.0.p13
+WANPIPE=wanpipe-3.1.0.p15
WANPIPE_HOST=ftp://ftp.sangoma.com/linux/custom/3.1
WANPIPE_FILE=$(WANPIPE).tgz
WANPIPE_DIR=$(BASE)/libs/$(WANPIPE)
WANPIPE_INCLUDE=$(WANPIPE_DIR)/patches/kdrivers/include
WANPIPE_KO=$(WANPIPE_DIR)/patches/kdrivers/src/net/wanpipe.ko
WANPIPE_INSTALLED_KO=$(shell echo "/lib/modules/`uname -r`/kernel/drivers/net/wan/wanpipe.ko")
-LIBSANGOMA_DIR=$(WANPIPE_DIR)/api/libsangoma
+LIBSANGOMA_DIR=./libsangoma
LOCAL_CFLAGS =-w -I$(WANPIPE_INCLUDE) -I$(LIBSANGOMA_DIR) -I/usr/local/include -I$(LIBPRI_DIR) -I/usr/src/linux/include -I. -I/usr/include
LOCAL_CFLAGS +=-D__LINUX__ -D_REENTRANT -D_GNU_SOURCE -DAFT_A104 -DWANPIPE_TDM_API -I$(switch_srcdir)/libs/libteletone/src -D_GNUC_ -DWANPIPE_TDM_API
LOCAL_OBJS = ss7boost_client.o $(LIBPRI_DIR)/copy_string.o $(LIBPRI_DIR)/pri.o $(LIBPRI_DIR)/q921.o $(LIBPRI_DIR)/prisched.o $(LIBPRI_DIR)/q931.o $(LIBPRI_DIR)/pri_facility.o $(LIBSANGOMA_DIR)/libsangoma.o $(LIBSANGOMA_DIR)/sangoma_pri.o
include $(BASE)/build/modmake.rules
+testapp: testapp.c $(LIBSANGOMA_DIR)/libsangoma.o
+ $(CC) -I$(WANPIPE_DIR)/api/lib $(CFLAGS) $(LOCAL_CFLAGS) lib_api.c testapp.c $(LIBSANGOMA_DIR)/libsangoma.o -o testapp
+
$(LIBPRI_DIR):
$(GETLIB) $(LIBPRI_HOST) $(LIBPRI_FILE)
Added: freeswitch/trunk/src/mod/endpoints/mod_wanpipe/lib_api.c
==============================================================================
--- (empty file)
+++ freeswitch/trunk/src/mod/endpoints/mod_wanpipe/lib_api.c Mon Apr 9 15:27:59 2007
@@ -0,0 +1,537 @@
+/*****************************************************************************
+* lib_api.c Common API library
+*
+* Author(s): Nenad Corbic <ncorbic(a)sangoma.com>
+*
+* Copyright: (c) 2003 Sangoma Technologies Inc.
+*
+* This program is free software; you can redistribute it and/or
+* modify it under the terms of the GNU General Public License
+* as published by the Free Software Foundation; either version
+* 2 of the License, or (at your option) any later version.
+* ============================================================================
+*/
+
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <ctype.h>
+#include <unistd.h>
+#include <sys/time.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <linux/if_wanpipe.h>
+#include <string.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#include <sys/types.h>
+#include <signal.h>
+#include <linux/if.h>
+
+#include <linux/wanpipe_defines.h>
+#include <linux/wanpipe_cfg.h>
+#include <linux/wanpipe.h>
+
+#include "lib_api.h"
+
+#define SINGLE_CHANNEL 0x2
+#define RANGE_CHANNEL 0x1
+
+
+char read_enable=0;
+char write_enable=0;
+char primary_enable=0;
+int tx_cnt=1;
+int rx_cnt=0;
+int tx_size=10;
+int tx_delay=0;
+int tx_data=-1;
+int tx_ss7_type=0;
+int rx_ss7_timer=0;
+
+unsigned char card_name[WAN_IFNAME_SZ];
+unsigned char if_name[WAN_IFNAME_SZ];
+
+unsigned char sw_if_name[WAN_IFNAME_SZ];
+unsigned char sw_card_name[WAN_IFNAME_SZ];
+
+unsigned char tx_file[WAN_IFNAME_SZ];
+unsigned char rx_file[WAN_IFNAME_SZ];
+
+unsigned char daddr[TX_ADDR_STR_SZ];
+unsigned char saddr[TX_ADDR_STR_SZ];
+unsigned char udata[TX_ADDR_STR_SZ];
+
+int files_used=0;
+int verbose=0;
+
+int tx_connections;
+
+int ds_prot=0;
+int ds_prot_opt=0;
+int ds_max_mult_cnt=0;
+unsigned int ds_active_ch=0;
+int ds_7bit_hdlc=0;
+int direction=-1;
+
+int tx_channels=1;
+int cause=0;
+int diagn=0;
+
+int card_cnt=0;
+int i_cnt=0;
+
+unsigned long parse_active_channel(char* val);
+
+int init_args(int argc, char *argv[])
+{
+ int i;
+ int c_cnt=0;
+
+ sprintf(daddr,"111");
+ sprintf(saddr,"222");
+ sprintf(udata,"C9");
+
+ for (i = 0; i < argc; i++){
+
+ if (!strcmp(argv[i],"-i")){
+
+ if (i+1 > argc-1){
+ printf("ERROR: Invalid Interface Name!\n");
+ return WAN_FALSE;
+ }
+
+ strncpy(if_name, argv[i+1],WAN_IFNAME_SZ);
+ i_cnt=1;
+
+ }else if (!strcmp(argv[i],"-si")){
+ if (i+1 > argc-1){
+ printf("ERROR: Invalid Switch Interface Name!\n");
+ return WAN_FALSE;
+ }
+
+ strncpy(sw_if_name, argv[i+1], WAN_IFNAME_SZ);
+
+ }else if (!strcmp(argv[i],"-c")){
+ if (i+1 > argc-1){
+ printf("ERROR: Invalid Card Name!\n");
+ return WAN_FALSE;
+ }
+
+ strncpy(card_name, argv[i+1], WAN_IFNAME_SZ);
+ card_cnt=1;
+
+ }else if (!strcmp(argv[i],"-sc")){
+ if (i+1 > argc-1){
+ printf("ERROR: Invalid Switch Card Name!\n");
+ return WAN_FALSE;
+ }
+
+ strncpy(sw_card_name, argv[i+1], WAN_IFNAME_SZ);
+
+ }else if (!strcmp(argv[i],"-r")){
+ read_enable=1;
+ c_cnt=1;
+
+ }else if (!strcmp(argv[i],"-w")){
+ write_enable=1;
+ c_cnt=1;
+
+ }else if (!strcmp(argv[i],"-pri")){
+ primary_enable=1;
+
+ }else if (!strcmp(argv[i],"-txcnt")){
+ if (i+1 > argc-1){
+ printf("ERROR: Invalid tx cnt!\n");
+ return WAN_FALSE;
+ }
+
+ if(isdigit(argv[i+1][0])){
+ tx_cnt = atoi(argv[i+1]);
+ }else{
+ printf("ERROR: Invalid tx cnt!\n");
+ return WAN_FALSE;
+ }
+
+ }else if (!strcmp(argv[i],"-rxcnt")){
+ if (i+1 > argc-1){
+ printf("ERROR: Invalid rx cnt!\n");
+ return WAN_FALSE;
+ }
+
+ if(isdigit(argv[i+1][0])){
+ rx_cnt = atoi(argv[i+1]);
+ }else{
+ printf("ERROR: Invalid rx cnt!\n");
+ return WAN_FALSE;
+ }
+
+ }else if (!strcmp(argv[i],"-txsize")){
+ if (i+1 > argc-1){
+ printf("ERROR: Invalid tx size!\n");
+ return WAN_FALSE;
+ }
+
+ if(isdigit(argv[i+1][0])){
+ tx_size = atoi(argv[i+1]);
+ }else{
+ printf("ERROR: Invalid tx size, must be a digit!\n");
+ return WAN_FALSE;
+ }
+ }else if (!strcmp(argv[i],"-txdelay")){
+ if (i+1 > argc-1){
+ printf("ERROR: Invalid tx delay!\n");
+ return WAN_FALSE;
+ }
+
+ if(isdigit(argv[i+1][0])){
+ tx_delay = atoi(argv[i+1]);
+ }else{
+ printf("ERROR: Invalid tx delay, must be a digit!\n");
+ return WAN_FALSE;
+ }
+ }else if (!strcmp(argv[i],"-txdata")){
+ if (i+1 > argc-1){
+ printf("ERROR: Invalid tx data!\n");
+ return WAN_FALSE;
+ }
+
+ if(isdigit(argv[i+1][0])){
+ tx_data = atoi(argv[i+1]);
+ }else{
+ printf("ERROR: Invalid tx data, must be a digit!\n");
+ return WAN_FALSE;
+ }
+ }else if (!strcmp(argv[i],"-tx_ss7_type")){
+ if (i+1 > argc-1){
+ printf("ERROR: Invalid tx ss7 type!\n");
+ return WAN_FALSE;
+ }
+
+ if(isdigit(argv[i+1][0])){
+ tx_ss7_type = atoi(argv[i+1]);
+ }else{
+ printf("ERROR: Invalid tx ss7 type, must be a digit!\n");
+ return WAN_FALSE;
+ }
+
+ }else if (!strcmp(argv[i],"-rx_ss7_timer")){
+ if (i+1 > argc-1){
+ printf("ERROR: Invalid rx ss7 timer!\n");
+ return WAN_FALSE;
+ }
+
+ if(isdigit(argv[i+1][0])){
+ rx_ss7_timer = atoi(argv[i+1]);
+ }else{
+ printf("ERROR: Invalid tx ss7 type, must be a digit!\n");
+ return WAN_FALSE;
+ }
+
+
+ }else if (!strcmp(argv[i],"-txfile")){
+
+ if (i+1 > argc-1){
+ printf("ERROR: Invalid Tx File Name!\n");
+ return WAN_FALSE;
+ }
+
+ strncpy(tx_file, argv[i+1],WAN_IFNAME_SZ);
+ files_used |= TX_FILE_USED;
+
+ }else if (!strcmp(argv[i],"-rxfile")){
+
+ if (i+1 > argc-1){
+ printf("ERROR: Invalid Rx File Name!\n");
+ return WAN_FALSE;
+ }
+
+ strncpy(rx_file, argv[i+1],WAN_IFNAME_SZ);
+ files_used |= RX_FILE_USED;
+
+ }else if (!strcmp(argv[i],"-daddr")){
+
+ if (i+1 > argc-1){
+ printf("ERROR: Invalid daddr str!\n");
+ return WAN_FALSE;
+ }
+
+ strncpy(daddr, argv[i+1],TX_ADDR_STR_SZ);
+
+ }else if (!strcmp(argv[i],"-saddr")){
+
+ if (i+1 > argc-1){
+ printf("ERROR: Invalid saddr str!\n");
+ return WAN_FALSE;
+ }
+
+ strncpy(saddr, argv[i+1],TX_ADDR_STR_SZ);
+
+ }else if (!strcmp(argv[i],"-udata")){
+
+ if (i+1 > argc-1){
+ printf("ERROR: Invalid udata str!\n");
+ return WAN_FALSE;
+ }
+
+ strncpy(udata, argv[i+1],TX_ADDR_STR_SZ);
+
+ }else if (!strcmp(argv[i],"-verbose")){
+ verbose=1;
+
+ }else if (!strcmp(argv[i],"-prot")){
+ if (i+1 > argc-1){
+ printf("ERROR: Invalid prot!\n");
+ return WAN_FALSE;
+ }
+
+ if(isdigit(argv[i+1][0])){
+ ds_prot = atoi(argv[i+1]);
+ }else{
+ printf("ERROR: Invalid prot, must be a digit!\n");
+ return WAN_FALSE;
+ }
+
+
+ }else if (!strcmp(argv[i],"-prot_opt")){
+ if (i+1 > argc-1){
+ printf("ERROR: Invalid prot_opt!\n");
+ return WAN_FALSE;
+ }
+
+ if(isdigit(argv[i+1][0])){
+ ds_prot_opt = atoi(argv[i+1]);
+ }else{
+ printf("ERROR: Invalid prot_opt, must be a digit!\n");
+ return WAN_FALSE;
+ }
+ }else if (!strcmp(argv[i],"-max_mult_cnt")){
+ if (i+1 > argc-1){
+ printf("ERROR: Invalid max_mult_cnt!\n");
+ return WAN_FALSE;
+ }
+
+ if(isdigit(argv[i+1][0])){
+ ds_max_mult_cnt = atoi(argv[i+1]);
+ }else{
+ printf("ERROR: Invalid max_mult_cnt, must be a digit!\n");
+ return WAN_FALSE;
+ }
+ }else if (!strcmp(argv[i],"-active_ch")){
+ if (i+1 > argc-1){
+ printf("ERROR: Invalid active ch!\n");
+ return WAN_FALSE;
+ }
+
+ ds_active_ch = parse_active_channel(argv[i+1]);
+ }else if (!strcmp(argv[i],"-txchan")){
+ if (i+1 > argc-1){
+ printf("ERROR: Invalid channels!\n");
+ return WAN_FALSE;
+ }
+
+ if(isdigit(argv[i+1][0])){
+ tx_channels = atoi(argv[i+1]);
+ }else{
+ printf("ERROR: Invalid channels, must be a digit!\n");
+ return WAN_FALSE;
+ }
+ }else if (!strcmp(argv[i],"-diagn")){
+ if (i+1 > argc-1){
+ printf("ERROR: Invalid diagn!\n");
+ return WAN_FALSE;
+ }
+
+ if(isdigit(argv[i+1][0])){
+ diagn = atoi(argv[i+1]);
+ }else{
+ printf("ERROR: Invalid diagn, must be a digit!\n");
+ return WAN_FALSE;
+ }
+
+ }else if (!strcmp(argv[i],"-cause")){
+ if (i+1 > argc-1){
+ printf("ERROR: Invalid cause!\n");
+ return WAN_FALSE;
+ }
+
+ if(isdigit(argv[i+1][0])){
+ cause = atoi(argv[i+1]);
+ }else{
+ printf("ERROR: Invalid cause, must be a digit!\n");
+ return WAN_FALSE;
+ }
+
+ }else if (!strcmp(argv[i],"-7bit_hdlc")){
+ if (i+1 > argc-1){
+ printf("ERROR: Invalid 7bit hdlc value!\n");
+ return WAN_FALSE;
+ }
+
+ if(isdigit(argv[i+1][0])){
+ ds_7bit_hdlc = atoi(argv[i+1]);
+ }else{
+ printf("ERROR: Invalid 7bit hdlc, must be a digit!\n");
+ return WAN_FALSE;
+ }
+
+ }else if (!strcmp(argv[i],"-dir")){
+ if (i+1 > argc-1){
+ printf("ERROR: Invalid direction value!\n");
+ return WAN_FALSE;
+ }
+
+ if(isdigit(argv[i+1][0])){
+ direction = atoi(argv[i+1]);
+ }else{
+ printf("ERROR: Invalid direction, must be a digit!\n");
+ return WAN_FALSE;
+ }
+ }
+ }
+
+ if (!i_cnt){
+ printf("ERROR: No Interface Name!\n");
+ return WAN_FALSE;
+ }
+ if (!card_cnt){
+ printf("ERROR: No Card name!\n");
+ return WAN_FALSE;
+ }
+ if (!c_cnt){
+ printf("ERROR: No Read or Write Command!\n");
+ return WAN_FALSE;
+ }
+
+ return WAN_TRUE;
+}
+
+static unsigned char api_usage[]="\n"
+"\n"
+"<options>:\n"
+" -i <ifname> #interface name\n"
+" -c <card name> #card name\n"
+" -r #read enable\n"
+" -w #write eable\n"
+"\n"
+"<extra options>\n"
+" -txcnt <digit> #number of tx packets (Dflt: 1)\n"
+" -txsize <digit> #tx packet size (Dflt: 10)\n"
+" -txdelay <digit> #delay in sec after each tx packet (Dflt: 0)\n"
+" -txdata <digit> #data to tx <1-255>\n"
+"\n"
+" -txfile <file> #Use file to tx instead\n"
+" -rxfile <file> #Save all rx data to a file\n"
+" \n"
+"\n"
+" -tx_ss7_type <digit> # 1=FISU 2=LSSU (repeating)\n"
+" -rx_ss7_timer <digit> #Force receive timeout value \n"
+"\n"
+" -rxcnt <digit> #number of rx packets before exit\n"
+" #this number overwrites the txcnt\n"
+" #Thus, app will only exit after it\n"
+" #receives the rxcnt number of packets.\n"
+" \n"
+" -verbose #Enable verbose mode\n"
+"\n"
+"<datascope options>\n"
+"\n"
+" -prot <digit> #Protocol Bit map: \n"
+" #1=FISU, 2=LSSU, 4=MSU, 8=RAW HDLC\n"
+" \n"
+" -prot_opt <digit> #Protocol bit map\n"
+" #0=None, 1=Delta, 2=Max Multiple\n"
+"\n"
+" -active_ch <digit> #Active channel\n"
+" #ALL = all channels \n"
+" #1 24 = 1 to 24 \n"
+" #1.24 = 1 and 24 \n"
+" #1-4.7-15 = 1 to 4 and 7 to 15\n"
+" \n"
+" -max_mult_cnt <digit> #If Prot_opt == 2 \n"
+" #max_mult_cnt is the number of \n"
+" #consecutive duplicate frames \n"
+" #received before pass up the stack.\n"
+" \n"
+" -7bit_hdlc <digit> #Enable 7 Bit Hdlc Engine\n"
+" #1=Enable 0=Disable\n"
+" \n"
+" -dir <digit> #Direction 0: Rx 1: Tx none: All\n"
+"\n"
+"<x25 protocol options>\n"
+"\n"
+" -txchan <digit> #Number of channels (dflt=1)\n"
+" -cause <digit> #disconnect cause (dflt=0)\n"
+" -diagn <digit> #disconnect diagnostic (dflt=0)\n"
+"\n";
+
+void usage(unsigned char *api_name)
+{
+printf ("\n\nAPI %s USAGE:\n\n%s <options> <extra options>\n\n%s\n",
+ api_name,api_name,api_usage);
+}
+
+
+/*============================================================================
+ * TE1
+ */
+unsigned long get_active_channels(int channel_flag, int start_channel, int stop_channel)
+{
+ int i = 0;
+ unsigned long tmp = 0, mask = 0;
+
+ if ((channel_flag & (SINGLE_CHANNEL | RANGE_CHANNEL)) == 0)
+ return tmp;
+ if (channel_flag & RANGE_CHANNEL) { /* Range of channels */
+ for(i = start_channel; i <= stop_channel; i++) {
+ mask = 1 << (i - 1);
+ tmp |=mask;
+ }
+ } else { /* Single channel */
+ mask = 1 << (stop_channel - 1);
+ tmp |= mask;
+ }
+ return tmp;
+}
+
+
+unsigned long parse_active_channel(char* val)
+{
+ int channel_flag = 0;
+ char* ptr = val;
+ int channel = 0, start_channel = 0;
+ unsigned long tmp = 0;
+
+ if (strcmp(val,"ALL") == 0)
+ return ENABLE_ALL_CHANNELS;
+
+ while(*ptr != '\0') {
+ if (isdigit(*ptr)) {
+ channel = strtoul(ptr, &ptr, 10);
+ channel_flag |= SINGLE_CHANNEL;
+ } else {
+ if (*ptr == '-') {
+ channel_flag |= RANGE_CHANNEL;
+ start_channel = channel;
+ } else {
+ tmp |= get_active_channels(channel_flag, start_channel, channel);
+ channel_flag = 0;
+ }
+ ptr++;
+ }
+ }
+ if (channel_flag){
+ tmp |= get_active_channels(channel_flag, start_channel, channel);
+ }
+ return tmp;
+}
+
+void u_delay(int usec)
+{
+ struct timeval tv;
+ tv.tv_usec = usec;
+ tv.tv_sec=0;
+
+ select(0,NULL,NULL, NULL, &tv);
+}
Modified: freeswitch/trunk/src/mod/endpoints/mod_wanpipe/libsangoma/libsangoma.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_wanpipe/libsangoma/libsangoma.c (original)
+++ freeswitch/trunk/src/mod/endpoints/mod_wanpipe/libsangoma/libsangoma.c Mon Apr 9 15:27:59 2007
@@ -23,96 +23,99 @@
#define DFT_CARD "wanpipe1"
#if defined(WIN32)
-//extern int verbose;
+//extern int verbose;
#define DEV_NAME_LEN 100
char device_name[DEV_NAME_LEN];
/* IOCTL management structures and variables*/
-wan_udp_hdr_t wan_udp;
+wan_udp_hdr_t wan_udp;
#include "win_api_common.h"
static wan_cmd_api_t api_cmd;
-static api_tx_hdr_t *tx_hdr = (api_tx_hdr_t *) api_cmd.data;
+static api_tx_hdr_t *tx_hdr = (api_tx_hdr_t *)api_cmd.data;
/* keeps the LAST (and single) event received */
static wp_tdm_api_rx_hdr_t last_tdm_api_event_buffer;
-#endif /* WIN32 */
+#endif /* WIN32 */
-void sangoma_socket_close(sng_fd_t * sp)
+void sangoma_socket_close(sng_fd_t *sp)
{
#if defined(WIN32)
- if (*sp != INVALID_HANDLE_VALUE) {
+ if( *sp != INVALID_HANDLE_VALUE){
CloseHandle(*sp);
*sp = INVALID_HANDLE_VALUE;
}
#else
- if (*sp > -1) {
- close(*sp);
- *sp = -1;
- }
+ if (*sp > -1) {
+ close(*sp);
+ *sp = -1;
+ }
#endif
}
int sangoma_socket_waitfor(sng_fd_t fd, int timeout, int flags)
{
#if defined(WIN32)
- API_POLL_STRUCT api_poll;
+ API_POLL_STRUCT api_poll;
memset(&api_poll, 0x00, sizeof(API_POLL_STRUCT));
-
+
api_poll.user_flags_bitmap = flags;
- if (DoApiPollCommand(fd, &api_poll)) {
+ if(DoApiPollCommand(fd, &api_poll)){
//failed
return 0;
}
- switch (api_poll.operation_status) {
- case SANG_STATUS_RX_DATA_AVAILABLE:
- break;
-
- default:
- prn(1, "Error: sangoma_socket_waitfor(): Unknown Operation Status: %d\n", api_poll.operation_status);
- return 0;
- } //switch()
+ switch(api_poll.operation_status)
+ {
+ case SANG_STATUS_RX_DATA_AVAILABLE:
+ break;
- if (api_poll.poll_events_bitmap == 0) {
- prn(1, "Error: invalid Poll Events bitmap: 0x%X\n", api_poll.poll_events_bitmap);
+ default:
+ prn(1, "Error: sangoma_socket_waitfor(): Unknown Operation Status: %d\n",
+ api_poll.operation_status);
+ return 0;
+ }//switch()
+
+ if(api_poll.poll_events_bitmap == 0){
+ prn(1, "Error: invalid Poll Events bitmap: 0x%X\n",
+ api_poll.poll_events_bitmap);
}
return api_poll.poll_events_bitmap;
#else
- struct pollfd pfds[1];
- int res;
+ struct pollfd pfds[1];
+ int res;
- memset(&pfds[0], 0, sizeof(pfds[0]));
- pfds[0].fd = fd;
- pfds[0].events = flags;
- res = poll(pfds, 1, timeout);
- if (res > 0) {
- if ((pfds[0].revents & POLLERR)) {
- res = -1;
- } else if ((pfds[0].revents)) {
- res = 1;
- }
+ memset(&pfds[0], 0, sizeof(pfds[0]));
+ pfds[0].fd = fd;
+ pfds[0].events = flags;
+ res = poll(pfds, 1, timeout);
+ if (res > 0) {
+ if ((pfds[0].revents & POLLERR)) {
+ res = -1;
+ } else if((pfds[0].revents)) {
+ res = 1;
}
+ }
- return res;
+ return res;
#endif
}
int sangoma_span_chan_toif(int span, int chan, char *interface_name)
{
- sprintf(interface_name, "s%ic%i", span, chan);
+ sprintf(interface_name,"s%ic%i",span,chan);
return 0;
}
int sangoma_interface_toi(char *interface_name, int *span, int *chan)
{
- char *p = NULL, *sp = NULL, *ch = NULL;
+ char *p=NULL, *sp = NULL, *ch = NULL;
int ret = 0;
char data[FNAME_LEN];
@@ -128,7 +131,7 @@
}
}
- if (ch && sp) {
+ if(ch && sp) {
*span = atoi(sp);
*chan = atoi(ch);
ret = 1;
@@ -159,7 +162,7 @@
}
}
- if (ch && sp) {
+ if(ch && sp) {
*span = atoi(sp);
*chan = atoi(ch);
ret = 1;
@@ -172,123 +175,132 @@
return ret;
}
-sng_fd_t sangoma_open_tdmapi_span_chan(int span, int chan)
+sng_fd_t sangoma_open_tdmapi_span_chan(int span, int chan)
{
- char fname[FNAME_LEN];
+ char fname[FNAME_LEN];
#if defined(WIN32)
//NOTE: under Windows Interfaces are zero based but 'chan' is 1 based.
- // Subtract 1 from 'chan'.
- _snprintf(fname, FNAME_LEN, "\\\\.\\WANPIPE%d_IF%d", span, chan - 1);
+ // Subtract 1 from 'chan'.
+ _snprintf(fname , FNAME_LEN, "\\\\.\\WANPIPE%d_IF%d", span, chan - 1);
//prn(verbose, "Opening device: %s...\n", fname);
- return CreateFile(fname,
- GENERIC_READ | GENERIC_WRITE,
- FILE_SHARE_READ | FILE_SHARE_WRITE,
- (LPSECURITY_ATTRIBUTES) NULL, OPEN_EXISTING, FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH, (HANDLE) NULL);
+ return CreateFile( fname,
+ GENERIC_READ | GENERIC_WRITE,
+ FILE_SHARE_READ | FILE_SHARE_WRITE,
+ (LPSECURITY_ATTRIBUTES)NULL,
+ OPEN_EXISTING,
+ FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH,
+ (HANDLE)NULL
+ );
#else
- int fd = -1;
+ int fd=-1;
- sprintf(fname, "/dev/wptdm_s%dc%d", span, chan);
+ sprintf(fname,"/dev/wptdm_s%dc%d",span,chan);
fd = open(fname, O_RDWR);
- return fd;
+ return fd;
#endif
-}
+}
-sng_fd_t sangoma_create_socket_by_name(char *device, char *card)
+sng_fd_t sangoma_create_socket_by_name(char *device, char *card)
{
- int span, chan;
- sangoma_interface_toi(device, &span, &chan);
-
- return sangoma_open_tdmapi_span_chan(span, chan);
+ int span,chan;
+ sangoma_interface_toi(device,&span,&chan);
+
+ return sangoma_open_tdmapi_span_chan(span,chan);
}
-
-sng_fd_t sangoma_open_tdmapi_span(int span)
+
+sng_fd_t sangoma_open_tdmapi_span(int span)
{
- int i = 0;
+ int i=0;
#if defined(WIN32)
sng_fd_t fd = INVALID_HANDLE_VALUE;
- for (i = 1; i < 32; i++) {
- if ((fd = sangoma_open_tdmapi_span_chan(span, i)) == INVALID_HANDLE_VALUE) {
+ for(i = 1; i < 32; i++){
+ if((fd = sangoma_open_tdmapi_span_chan(span, i)) == INVALID_HANDLE_VALUE){
//prn(verbose, "Span: %d, chan: %d: is not running, consider 'busy'\n",
- // span, i);
+ // span, i);
continue;
}
+
//get the open handle counter
- wan_udp.wan_udphdr_command = GET_OPEN_HANDLES_COUNTER;
+ wan_udp.wan_udphdr_command = GET_OPEN_HANDLES_COUNTER;
wan_udp.wan_udphdr_data_len = 0;
DoManagementCommand(fd, &wan_udp);
- if (wan_udp.wan_udphdr_return_code) {
- prn(1, "Error: command GET_OPEN_HANDLES_COUNTER failed! Span: %d, chan: %d\n", span, i);
+ if(wan_udp.wan_udphdr_return_code){
+ prn(1, "Error: command GET_OPEN_HANDLES_COUNTER failed! Span: %d, chan: %d\n",
+ span, i);
//don't forget to close!! otherwize counter will stay incremented.
sangoma_socket_close(&fd);
continue;
}
+
//prn(verbose, "open handles counter: %d\n", *(int*)&wan_udp.wan_udphdr_data[0]);
- if (*(int *) &wan_udp.wan_udphdr_data[0] == 1) {
+ if(*(int*)&wan_udp.wan_udphdr_data[0] == 1){
//this is the only process using this chan/span, so it is 'free'
//prn(verbose, "Found 'free' Span: %d, chan: %d\n",span, i);
break;
}
//don't forget to close!! otherwize counter will stay incremented.
sangoma_socket_close(&fd);
- } //for()
+ }//for()
#else
- unsigned char fname[FNAME_LEN];
- int fd = 0;
- for (i = 1; i < 32; i++) {
- sprintf(fname, "/dev/wptdm_s%dc%d", span, i);
+ unsigned char fname[FNAME_LEN];
+ int fd=0;
+ for (i=1;i<32;i++){
+ sprintf(fname,"/dev/wptdm_s%dc%d",span,i);
fd = open(fname, O_RDWR);
- if (fd < 0) {
- continue;
+ if (fd < 0){
+ continue;
}
break;
}
-#endif
- return fd;
-}
+#endif
+ return fd;
+}
int sangoma_readmsg_tdm(sng_fd_t fd, void *hdrbuf, int hdrlen, void *databuf, int datalen, int flag)
{
- int rx_len = 0;
+ int rx_len=0;
#if defined(WIN32)
- static RX_DATA_STRUCT rx_data;
- api_header_t *pri;
- wp_tdm_api_rx_hdr_t *tdm_api_rx_hdr;
- wp_tdm_api_rx_hdr_t *user_buf = (wp_tdm_api_rx_hdr_t *) hdrbuf;
+ static RX_DATA_STRUCT rx_data;
+ api_header_t *pri;
+ wp_tdm_api_rx_hdr_t *tdm_api_rx_hdr;
+ wp_tdm_api_rx_hdr_t *user_buf = (wp_tdm_api_rx_hdr_t*)hdrbuf;
- if (hdrlen != sizeof(wp_tdm_api_rx_hdr_t)) {
+ if(hdrlen != sizeof(wp_tdm_api_rx_hdr_t)){
//error
prn(1, "Error: sangoma_readmsg_tdm(): invalid size of user's 'header buffer'.\
Should be 'sizeof(wp_tdm_api_rx_hdr_t)'.\n");
return -1;
}
- if (DoReadCommand(fd, &rx_data)) {
+ if(DoReadCommand(fd, &rx_data) ){
//error
prn(1, "Error: DoReadCommand() failed! Check messages log.\n");
return -1;
}
+
//use our special buffer at rxdata to hold received data
pri = &rx_data.api_header;
- tdm_api_rx_hdr = (wp_tdm_api_rx_hdr_t *) rx_data.data;
+ tdm_api_rx_hdr = (wp_tdm_api_rx_hdr_t*)rx_data.data;
user_buf->wp_tdm_api_event_type = pri->operation_status;
- switch (pri->operation_status) {
+ switch(pri->operation_status)
+ {
case SANG_STATUS_RX_DATA_AVAILABLE:
//prn(verbose, "SANG_STATUS_RX_DATA_AVAILABLE\n");
- if (pri->data_length > datalen) {
- rx_len = 0;
+ if(pri->data_length > datalen){
+ rx_len=0;
break;
}
memcpy(databuf, rx_data.data, pri->data_length);
@@ -303,11 +315,12 @@
rx_len = pri->data_length;
//make copy for use with sangoma_tdm_read_event() - indirect access.
- memcpy(&last_tdm_api_event_buffer, tdm_api_rx_hdr, sizeof(wp_tdm_api_rx_hdr_t));
+ memcpy( &last_tdm_api_event_buffer, tdm_api_rx_hdr, sizeof(wp_tdm_api_rx_hdr_t));
break;
default:
- switch (pri->operation_status) {
+ switch(pri->operation_status)
+ {
case SANG_STATUS_RX_DATA_TIMEOUT:
//no data in READ_CMD_TIMEOUT, try again.
prn(1, "Error: Timeout on read.\n");
@@ -331,43 +344,43 @@
default:
prn(1, "Rx:Unknown Operation Status: %d\n", pri->operation_status);
break;
- } //switch()
+ }//switch()
return 0;
- } //switch()
+ }//switch()
#else
struct msghdr msg;
struct iovec iov[2];
- memset(&msg, 0, sizeof(struct msghdr));
+ memset(&msg,0,sizeof(struct msghdr));
- iov[0].iov_len = hdrlen;
- iov[0].iov_base = hdrbuf;
+ iov[0].iov_len=hdrlen;
+ iov[0].iov_base=hdrbuf;
- iov[1].iov_len = datalen;
- iov[1].iov_base = databuf;
+ iov[1].iov_len=datalen;
+ iov[1].iov_base=databuf;
- msg.msg_iovlen = 2;
- msg.msg_iov = iov;
+ msg.msg_iovlen=2;
+ msg.msg_iov=iov;
- rx_len = read(fd, &msg, datalen + hdrlen);
+ rx_len = read(fd,&msg,datalen+hdrlen);
- if (rx_len <= sizeof(wp_tdm_api_rx_hdr_t)) {
+ if (rx_len <= sizeof(wp_tdm_api_rx_hdr_t)){
return -EINVAL;
}
- rx_len -= sizeof(wp_tdm_api_rx_hdr_t);
+ rx_len-=sizeof(wp_tdm_api_rx_hdr_t);
#endif
- return rx_len;
-}
+ return rx_len;
+}
int sangoma_writemsg_tdm(sng_fd_t fd, void *hdrbuf, int hdrlen, void *databuf, unsigned short datalen, int flag)
{
int bsent;
#if defined(WIN32)
- static TX_DATA_STRUCT local_tx_data;
- api_header_t *pri;
+ static TX_DATA_STRUCT local_tx_data;
+ api_header_t *pri;
pri = &local_tx_data.api_header;
@@ -375,35 +388,36 @@
memcpy(local_tx_data.data, databuf, pri->data_length);
//queue data for transmission
- if (DoWriteCommand(fd, &local_tx_data)) {
+ if( DoWriteCommand(fd, &local_tx_data)){
//error
prn(1, "Error: DoWriteCommand() failed!! Check messages log.\n");
return -1;
}
- bsent = 0;
+ bsent=0;
//check that frame was transmitted
- switch (local_tx_data.api_header.operation_status) {
+ switch(local_tx_data.api_header.operation_status)
+ {
case SANG_STATUS_SUCCESS:
bsent = datalen;
break;
-
+
case SANG_STATUS_TX_TIMEOUT:
//error
prn(1, "****** Error: SANG_STATUS_TX_TIMEOUT ******\n");
//Check messages log or look at statistics.
break;
-
+
case SANG_STATUS_TX_DATA_TOO_LONG:
//Attempt to transmit data longer than the pre-configured maximum.
//Maximum length is set in 'Interface Properties',
//in the 'Device Manager'.
prn(1, "****** SANG_STATUS_TX_DATA_TOO_LONG ******\n");
break;
-
+
case SANG_STATUS_TX_DATA_TOO_SHORT:
//Minimum is 1 byte for Primary port,
- // 2 bytes for Secondary port
+ // 2 bytes for Secondary port
prn(1, "****** SANG_STATUS_TX_DATA_TOO_SHORT ******\n");
break;
@@ -416,27 +430,28 @@
break;
default:
- prn(1, "Unknown return code (0x%X) on transmission!\n", local_tx_data.api_header.operation_status);
+ prn(1, "Unknown return code (0x%X) on transmission!\n",
+ local_tx_data.api_header.operation_status);
break;
- } //switch()
+ }//switch()
#else
struct msghdr msg;
struct iovec iov[2];
- memset(&msg, 0, sizeof(struct msghdr));
+ memset(&msg,0,sizeof(struct msghdr));
- iov[0].iov_len = hdrlen;
- iov[0].iov_base = hdrbuf;
+ iov[0].iov_len=hdrlen;
+ iov[0].iov_base=hdrbuf;
- iov[1].iov_len = datalen;
- iov[1].iov_base = databuf;
+ iov[1].iov_len=datalen;
+ iov[1].iov_base=databuf;
- msg.msg_iovlen = 2;
- msg.msg_iov = iov;
+ msg.msg_iovlen=2;
+ msg.msg_iov=iov;
- bsent = write(fd, &msg, datalen + hdrlen);
- if (bsent > 0) {
- bsent -= sizeof(wp_tdm_api_tx_hdr_t);
+ bsent = write(fd,&msg,datalen+hdrlen);
+ if (bsent > 0){
+ bsent-=sizeof(wp_tdm_api_tx_hdr_t);
}
#endif
return bsent;
@@ -449,17 +464,17 @@
* Execute TDM command
*
*/
-static int sangoma_tdm_cmd_exec(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api)
+static int sangoma_tdm_cmd_exec(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api)
{
int err;
#if defined(WIN32)
err = tdmv_api_ioctl(fd, &tdm_api->wp_tdm_cmd);
#else
- err = ioctl(fd, SIOC_WANPIPE_TDM_API, &tdm_api->wp_tdm_cmd);
- if (err < 0) {
+ err = ioctl(fd,SIOC_WANPIPE_TDM_API,&tdm_api->wp_tdm_cmd);
+ if (err < 0){
char tmp[50];
- sprintf(tmp, "TDM API: CMD: %i\n", tdm_api->wp_tdm_cmd.cmd);
+ sprintf(tmp,"TDM API: CMD: %i\n",tdm_api->wp_tdm_cmd.cmd);
perror(tmp);
return -1;
}
@@ -471,35 +486,40 @@
* Get Full TDM API configuration per channel
*
*/
-int sangoma_get_full_cfg(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api)
+int sangoma_get_full_cfg(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api)
{
int err;
tdm_api->wp_tdm_cmd.cmd = SIOC_WP_TDM_GET_FULL_CFG;
- err = sangoma_tdm_cmd_exec(fd, tdm_api);
- if (err) {
+ err=sangoma_tdm_cmd_exec(fd,tdm_api);
+ if (err){
return err;
}
printf("TDM API CFG:\n");
- printf("\thw_tdm_coding:\t%d\n", tdm_api->wp_tdm_cmd.hw_tdm_coding);
- printf("\tusr_mtu_mru:\t%d\n", tdm_api->wp_tdm_cmd.hw_mtu_mru);
- printf("\tusr_period:\t%d\n", tdm_api->wp_tdm_cmd.usr_period);
- printf("\ttdm_codec:\t%d\n", tdm_api->wp_tdm_cmd.tdm_codec);
- printf("\tpower_level:\t%d\n", tdm_api->wp_tdm_cmd.power_level);
- printf("\trx_disable:\t%d\n", tdm_api->wp_tdm_cmd.rx_disable);
- printf("\ttx_disable:\t%d\n", tdm_api->wp_tdm_cmd.tx_disable);
- printf("\tusr_mtu_mru:\t%d\n", tdm_api->wp_tdm_cmd.usr_mtu_mru);
- printf("\tidle flag:\t0x%02X\n", tdm_api->wp_tdm_cmd.idle_flag);
- printf("\tfe alarms:\t0x%02X\n", tdm_api->wp_tdm_cmd.fe_alarms);
-
- printf("\trx pkt\t%d\ttx pkt\t%d\n", tdm_api->wp_tdm_cmd.stats.rx_packets, tdm_api->wp_tdm_cmd.stats.tx_packets);
- printf("\trx err\t%d\ttx err\t%d\n", tdm_api->wp_tdm_cmd.stats.rx_errors, tdm_api->wp_tdm_cmd.stats.tx_errors);
+ printf("\thw_tdm_coding:\t%d\n",tdm_api->wp_tdm_cmd.hw_tdm_coding);
+ printf("\tusr_mtu_mru:\t%d\n",tdm_api->wp_tdm_cmd.hw_mtu_mru);
+ printf("\tusr_period:\t%d\n",tdm_api->wp_tdm_cmd.usr_period);
+ printf("\ttdm_codec:\t%d\n",tdm_api->wp_tdm_cmd.tdm_codec);
+ printf("\tpower_level:\t%d\n",tdm_api->wp_tdm_cmd.power_level);
+ printf("\trx_disable:\t%d\n",tdm_api->wp_tdm_cmd.rx_disable);
+ printf("\ttx_disable:\t%d\n",tdm_api->wp_tdm_cmd.tx_disable);
+ printf("\tusr_mtu_mru:\t%d\n",tdm_api->wp_tdm_cmd.usr_mtu_mru);
+ printf("\tidle flag:\t0x%02X\n",tdm_api->wp_tdm_cmd.idle_flag);
+ printf("\tfe alarms:\t0x%02X\n",tdm_api->wp_tdm_cmd.fe_alarms);
+
+ printf("\trx pkt\t%d\ttx pkt\t%d\n",tdm_api->wp_tdm_cmd.stats.rx_packets,
+ tdm_api->wp_tdm_cmd.stats.tx_packets);
+ printf("\trx err\t%d\ttx err\t%d\n",
+ tdm_api->wp_tdm_cmd.stats.rx_errors,
+ tdm_api->wp_tdm_cmd.stats.tx_errors);
#ifndef __WINDOWS__
- printf("\trx ovr\t%d\ttx idl\t%d\n", tdm_api->wp_tdm_cmd.stats.rx_fifo_errors, tdm_api->wp_tdm_cmd.stats.tx_carrier_errors);
-#endif
-
+ printf("\trx ovr\t%d\ttx idl\t%d\n",
+ tdm_api->wp_tdm_cmd.stats.rx_fifo_errors,
+ tdm_api->wp_tdm_cmd.stats.tx_carrier_errors);
+#endif
+
return 0;
}
@@ -515,14 +535,14 @@
* }
*
*/
-int sangoma_tdm_set_codec(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api, int codec)
+int sangoma_tdm_set_codec(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api, int codec)
{
int err;
tdm_api->wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_CODEC;
tdm_api->wp_tdm_cmd.tdm_codec = codec;
- err = sangoma_tdm_cmd_exec(fd, tdm_api);
+ err=sangoma_tdm_cmd_exec(fd,tdm_api);
return err;
}
@@ -539,18 +559,18 @@
* }
*
*/
-int sangoma_tdm_get_codec(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api)
+int sangoma_tdm_get_codec(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api)
{
int err;
tdm_api->wp_tdm_cmd.cmd = SIOC_WP_TDM_GET_CODEC;
- err = sangoma_tdm_cmd_exec(fd, tdm_api);
- if (err) {
+ err=sangoma_tdm_cmd_exec(fd,tdm_api);
+ if (err){
return err;
}
- return tdm_api->wp_tdm_cmd.tdm_codec;
+ return tdm_api->wp_tdm_cmd.tdm_codec;
}
@@ -561,14 +581,14 @@
* 10,20,30,40,50 ms
*
*/
-int sangoma_tdm_set_usr_period(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api, int period)
+int sangoma_tdm_set_usr_period(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api, int period)
{
int err;
tdm_api->wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_USR_PERIOD;
tdm_api->wp_tdm_cmd.usr_period = period;
- err = sangoma_tdm_cmd_exec(fd, tdm_api);
+ err=sangoma_tdm_cmd_exec(fd,tdm_api);
return err;
}
@@ -580,14 +600,14 @@
* 10,20,30,40,50 ms
*
*/
-int sangoma_tdm_get_usr_period(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api)
+int sangoma_tdm_get_usr_period(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api)
{
int err;
tdm_api->wp_tdm_cmd.cmd = SIOC_WP_TDM_GET_USR_PERIOD;
- err = sangoma_tdm_cmd_exec(fd, tdm_api);
- if (err) {
+ err=sangoma_tdm_cmd_exec(fd,tdm_api);
+ if (err){
return err;
}
@@ -600,15 +620,15 @@
* Coding Format will be ULAW/ALAW based on T1/E1
*/
-int sangoma_tdm_get_hw_coding(int fd, wanpipe_tdm_api_t * tdm_api)
+int sangoma_tdm_get_hw_coding(int fd, wanpipe_tdm_api_t *tdm_api)
{
- int err;
- tdm_api->wp_tdm_cmd.cmd = SIOC_WP_TDM_GET_HW_CODING;
- err = sangoma_tdm_cmd_exec(fd, tdm_api);
- if (err) {
- return err;
- }
- return tdm_api->wp_tdm_cmd.hw_tdm_coding;
+ int err;
+ tdm_api->wp_tdm_cmd.cmd = SIOC_WP_TDM_GET_HW_CODING;
+ err=sangoma_tdm_cmd_exec(fd,tdm_api);
+ if (err){
+ return err;
+ }
+ return tdm_api->wp_tdm_cmd.hw_tdm_coding;
}
@@ -618,14 +638,14 @@
* The USER MTU/MRU values will change each time a PERIOD
* or CODEC is adjusted.
*/
-int sangoma_tdm_get_usr_mtu_mru(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api)
+int sangoma_tdm_get_usr_mtu_mru(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api)
{
int err;
tdm_api->wp_tdm_cmd.cmd = SIOC_WP_TDM_GET_USR_MTU_MRU;
- err = sangoma_tdm_cmd_exec(fd, tdm_api);
- if (err) {
+ err=sangoma_tdm_cmd_exec(fd,tdm_api);
+ if (err){
return err;
}
@@ -638,14 +658,14 @@
* This option is not implemented yet
*
*/
-int sangoma_tdm_set_power_level(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api, int power)
+int sangoma_tdm_set_power_level(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api, int power)
{
int err;
tdm_api->wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_POWER_LEVEL;
tdm_api->wp_tdm_cmd.power_level = power;
- err = sangoma_tdm_cmd_exec(fd, tdm_api);
+ err=sangoma_tdm_cmd_exec(fd,tdm_api);
return err;
}
@@ -656,43 +676,42 @@
* This option is not implemented yet
*
*/
-int sangoma_tdm_get_power_level(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api)
+int sangoma_tdm_get_power_level(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api)
{
int err;
tdm_api->wp_tdm_cmd.cmd = SIOC_WP_TDM_GET_POWER_LEVEL;
- err = sangoma_tdm_cmd_exec(fd, tdm_api);
- if (err) {
+ err=sangoma_tdm_cmd_exec(fd,tdm_api);
+ if (err){
return err;
}
return tdm_api->wp_tdm_cmd.power_level;
}
-int sangoma_tdm_flush_bufs(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api)
+int sangoma_tdm_flush_bufs(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api)
{
#if 0
tdm_api->wp_tdm_cmd.cmd = SIOC_WP_TDM_FLUSH_BUFFERS;
- err = sangoma_tdm_cmd_exec(fd, tdm_api);
- if (err) {
+ err=sangoma_tdm_cmd_exec(fd,tdm_api);
+ if (err){
return err;
}
#endif
return 0;
}
-int sangoma_tdm_enable_rbs_events(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api, int poll_in_sec)
-{
-
+int sangoma_tdm_enable_rbs_events(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api, int poll_in_sec) {
+
int err;
-
+
tdm_api->wp_tdm_cmd.cmd = SIOC_WP_TDM_ENABLE_RBS_EVENTS;
- tdm_api->wp_tdm_cmd.rbs_poll = poll_in_sec;
-
- err = sangoma_tdm_cmd_exec(fd, tdm_api);
- if (err) {
+ tdm_api->wp_tdm_cmd.rbs_poll=poll_in_sec;
+
+ err=sangoma_tdm_cmd_exec(fd,tdm_api);
+ if (err){
return err;
}
@@ -700,180 +719,185 @@
}
-int sangoma_tdm_disable_rbs_events(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api)
-{
+int sangoma_tdm_disable_rbs_events(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api) {
int err;
tdm_api->wp_tdm_cmd.cmd = SIOC_WP_TDM_DISABLE_RBS_EVENTS;
-
- err = sangoma_tdm_cmd_exec(fd, tdm_api);
- if (err) {
+
+ err=sangoma_tdm_cmd_exec(fd,tdm_api);
+ if (err){
return err;
}
return 0;
}
-int sangoma_tdm_write_rbs(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api, unsigned char rbs)
+int sangoma_tdm_write_rbs(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api, unsigned char rbs)
{
-
+
int err;
tdm_api->wp_tdm_cmd.cmd = SIOC_WP_TDM_WRITE_RBS_BITS;
- tdm_api->wp_tdm_cmd.rbs_tx_bits = rbs;
-
- err = sangoma_tdm_cmd_exec(fd, tdm_api);
- if (err) {
+ tdm_api->wp_tdm_cmd.rbs_tx_bits=rbs;
+
+ err=sangoma_tdm_cmd_exec(fd,tdm_api);
+ if (err){
return err;
}
return 0;
-}
+}
-int sangoma_tdm_read_event(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api)
+int sangoma_tdm_read_event(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api)
{
wp_tdm_api_rx_hdr_t *rx_event;
-#if defined(WIN32)
+#if defined(WIN32)
rx_event = &last_tdm_api_event_buffer;
#else
int err;
tdm_api->wp_tdm_cmd.cmd = SIOC_WP_TDM_READ_EVENT;
-
- err = sangoma_tdm_cmd_exec(fd, tdm_api);
- if (err) {
+
+ err=sangoma_tdm_cmd_exec(fd,tdm_api);
+ if (err){
return err;
}
rx_event = &tdm_api->wp_tdm_cmd.event;
#endif
- switch (rx_event->wp_tdm_api_event_type) {
-
+ switch (rx_event->wp_tdm_api_event_type){
+
case WP_TDM_EVENT_RBS:
- printf("%d: GOT RBS EVENT %p\n", (int) fd, tdm_api->wp_tdm_event.wp_rbs_event);
+ printf("%d: GOT RBS EVENT %p\n",(int)fd,tdm_api->wp_tdm_event.wp_rbs_event);
if (tdm_api->wp_tdm_event.wp_rbs_event) {
- tdm_api->wp_tdm_event.wp_rbs_event(fd, rx_event->wp_tdm_api_event_rbs_rx_bits);
+ tdm_api->wp_tdm_event.wp_rbs_event(fd,rx_event->wp_tdm_api_event_rbs_rx_bits);
}
-
+
break;
-
+
case WP_TDM_EVENT_DTMF:
- printf("%d: GOT DTMF EVENT\n", (int) fd);
+ printf("%d: GOT DTMF EVENT\n",(int)fd);
if (tdm_api->wp_tdm_event.wp_dtmf_event) {
tdm_api->wp_tdm_event.wp_dtmf_event(fd,
- rx_event->wp_tdm_api_event_dtmf_digit,
- rx_event->wp_tdm_api_event_dtmf_type, rx_event->wp_tdm_api_event_dtmf_port);
+ rx_event->wp_tdm_api_event_dtmf_digit,
+ rx_event->wp_tdm_api_event_dtmf_type,
+ rx_event->wp_tdm_api_event_dtmf_port);
}
break;
-
+
case WP_TDM_EVENT_RXHOOK:
- printf("%d: GOT RXHOOK EVENT\n", (int) fd);
+ printf("%d: GOT RXHOOK EVENT\n",(int)fd);
if (tdm_api->wp_tdm_event.wp_rxhook_event) {
- tdm_api->wp_tdm_event.wp_rxhook_event(fd, rx_event->wp_tdm_api_event_rxhook_state);
+ tdm_api->wp_tdm_event.wp_rxhook_event(fd,
+ rx_event->wp_tdm_api_event_rxhook_state);
}
break;
case WP_TDM_EVENT_RING_DETECT:
- printf("%d: GOT RXRING EVENT\n", (int) fd);
+ printf("%d: GOT RXRING EVENT\n",(int)fd);
if (tdm_api->wp_tdm_event.wp_rxring_event) {
- tdm_api->wp_tdm_event.wp_rxring_event(fd, rx_event->wp_tdm_api_event_ring_state);
+ tdm_api->wp_tdm_event.wp_rxring_event(fd,
+ rx_event->wp_tdm_api_event_ring_state);
}
break;
case WP_TDM_EVENT_RING_TRIP:
- printf("%d: GOT RING TRIP EVENT\n", (int) fd);
+ printf("%d: GOT RING TRIP EVENT\n",(int)fd);
if (tdm_api->wp_tdm_event.wp_ringtrip_event) {
- tdm_api->wp_tdm_event.wp_ringtrip_event(fd, rx_event->wp_tdm_api_event_ring_state);
+ tdm_api->wp_tdm_event.wp_ringtrip_event(fd,
+ rx_event->wp_tdm_api_event_ring_state);
}
break;
case WP_TDM_EVENT_FE_ALARM:
- printf("%d: GOT FE ALARMS EVENT %i\n", (int) fd, rx_event->wp_tdm_api_event_fe_alarm);
+ printf("%d: GOT FE ALARMS EVENT %i\n",(int)fd,
+ rx_event->wp_tdm_api_event_fe_alarm);
if (tdm_api->wp_tdm_event.wp_fe_alarm_event) {
- tdm_api->wp_tdm_event.wp_fe_alarm_event(fd, rx_event->wp_tdm_api_event_fe_alarm);
- }
-
+ tdm_api->wp_tdm_event.wp_fe_alarm_event(fd,
+ rx_event->wp_tdm_api_event_fe_alarm);
+ }
+
default:
- printf("%d: Unknown TDM event!", (int) fd);
+ printf("%d: Unknown TDM event!", (int)fd);
break;
}
-
+
return 0;
-}
+}
-int sangoma_tdm_enable_dtmf_events(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api)
+int sangoma_tdm_enable_dtmf_events(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api)
{
int err;
-
+
tdm_api->wp_tdm_cmd.cmd = SIOC_WP_TDM_ENABLE_DTMF_EVENTS;
- err = sangoma_tdm_cmd_exec(fd, tdm_api);
- if (err) {
+ err=sangoma_tdm_cmd_exec(fd,tdm_api);
+ if (err){
return err;
}
return 0;
}
-int sangoma_tdm_disable_dtmf_events(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api)
+int sangoma_tdm_disable_dtmf_events(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api)
{
int err;
tdm_api->wp_tdm_cmd.cmd = SIOC_WP_TDM_DISABLE_DTMF_EVENTS;
- err = sangoma_tdm_cmd_exec(fd, tdm_api);
- if (err) {
+ err=sangoma_tdm_cmd_exec(fd,tdm_api);
+ if (err){
return err;
}
return 0;
}
-int sangoma_tdm_enable_rm_dtmf_events(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api)
+int sangoma_tdm_enable_rm_dtmf_events(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api)
{
int err;
-
+
tdm_api->wp_tdm_cmd.cmd = SIOC_WP_TDM_ENABLE_RM_DTMF_EVENTS;
- err = sangoma_tdm_cmd_exec(fd, tdm_api);
- if (err) {
+ err=sangoma_tdm_cmd_exec(fd,tdm_api);
+ if (err){
return err;
}
return 0;
}
-int sangoma_tdm_disable_rm_dtmf_events(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api)
+int sangoma_tdm_disable_rm_dtmf_events(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api)
{
int err;
tdm_api->wp_tdm_cmd.cmd = SIOC_WP_TDM_DISABLE_RM_DTMF_EVENTS;
- err = sangoma_tdm_cmd_exec(fd, tdm_api);
- if (err) {
+ err=sangoma_tdm_cmd_exec(fd,tdm_api);
+ if (err){
return err;
}
return 0;
}
-int sangoma_tdm_enable_rxhook_events(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api)
+int sangoma_tdm_enable_rxhook_events(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api)
{
int err;
tdm_api->wp_tdm_cmd.cmd = SIOC_WP_TDM_ENABLE_RXHOOK_EVENTS;
- err = sangoma_tdm_cmd_exec(fd, tdm_api);
- if (err) {
+ err=sangoma_tdm_cmd_exec(fd,tdm_api);
+ if (err){
return err;
}
return 0;
}
-int sangoma_tdm_disable_rxhook_events(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api)
+int sangoma_tdm_disable_rxhook_events(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api)
{
int err;
tdm_api->wp_tdm_cmd.cmd = SIOC_WP_TDM_DISABLE_RXHOOK_EVENTS;
- err = sangoma_tdm_cmd_exec(fd, tdm_api);
- if (err) {
+ err=sangoma_tdm_cmd_exec(fd,tdm_api);
+ if (err){
return err;
}
@@ -884,18 +908,18 @@
* GET Front End Alarms
*
*/
-int sangoma_tdm_get_fe_alarms(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api)
+int sangoma_tdm_get_fe_alarms(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api)
{
int err;
tdm_api->wp_tdm_cmd.cmd = SIOC_WP_TDM_GET_FE_ALARMS;
- err = sangoma_tdm_cmd_exec(fd, tdm_api);
- if (err) {
+ err=sangoma_tdm_cmd_exec(fd,tdm_api);
+ if (err){
return err;
}
return tdm_api->wp_tdm_cmd.fe_alarms;
-}
+}
#endif /* WANPIPE_TDM_API */
Modified: freeswitch/trunk/src/mod/endpoints/mod_wanpipe/libsangoma/libsangoma.h
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_wanpipe/libsangoma/libsangoma.h (original)
+++ freeswitch/trunk/src/mod/endpoints/mod_wanpipe/libsangoma/libsangoma.h Mon Apr 9 15:27:59 2007
@@ -34,7 +34,7 @@
#ifdef WANPIPE_TDM_API
#include <wanpipe_tdm_api.h> //for TDMV API
#endif
-#include <sang_status_defines.h> //return codes
+#include <sang_status_defines.h>//return codes
#include <sang_api.h> //for IOCTL codes
#include <sdla_te1_pmc.h> //RBS definitions
#include <sdla_te1.h> //TE1 macros
@@ -94,7 +94,7 @@
/* Open Span/Chan devices
* open_tdmapi_span_chan: open device based on span chan values
* sangoma_open_tdmapi_span: open first available device on span
- */
+ */
sng_fd_t sangoma_open_tdmapi_span_chan(int span, int chan);
sng_fd_t sangoma_open_tdmapi_span(int span);
@@ -104,65 +104,67 @@
/* Device Rx/Tx functions
* writemsg_tdm: tx header + data from separate buffers
* readmsg_tdm: rx header + data to separate buffers
- */
-int sangoma_writemsg_tdm(sng_fd_t fd, void *hdrbuf, int hdrlen, void *databuf, unsigned short datalen, int flag);
-int sangoma_readmsg_tdm(sng_fd_t fd, void *hdrbuf, int hdrlen, void *databuf, int datalen, int flag);
+ */
+int sangoma_writemsg_tdm(sng_fd_t fd, void *hdrbuf, int hdrlen,
+ void *databuf, unsigned short datalen, int flag);
+int sangoma_readmsg_tdm(sng_fd_t fd, void *hdrbuf, int hdrlen,
+ void *databuf, int datalen, int flag);
#define sangoma_readmsg_socket sangoma_readmsg_tdm
#define sangoma_sendmsg_socket sangoma_writemsg_tdm
#ifdef WANPIPE_TDM_API
-void sangoma_socket_close(sng_fd_t * sp);
+void sangoma_socket_close(sng_fd_t *sp);
int sangoma_socket_waitfor(sng_fd_t fd, int timeout, int flags);
/* Get Full TDM API configuration per chan */
-int sangoma_get_full_cfg(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api);
+int sangoma_get_full_cfg(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api);
/* Get/Set TDM Codec per chan */
-int sangoma_tdm_set_codec(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api, int codec);
-int sangoma_tdm_get_codec(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api);
+int sangoma_tdm_set_codec(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api, int codec);
+int sangoma_tdm_get_codec(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api);
/* Get/Set USR Tx/Rx Period in milliseconds */
-int sangoma_tdm_set_usr_period(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api, int period);
-int sangoma_tdm_get_usr_period(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api);
+int sangoma_tdm_set_usr_period(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api, int period);
+int sangoma_tdm_get_usr_period(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api);
/* Get user MTU/MRU values in bytes */
-int sangoma_tdm_get_usr_mtu_mru(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api);
+int sangoma_tdm_get_usr_mtu_mru(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api);
/* Not supported yet */
-int sangoma_tdm_set_power_level(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api, int power);
-int sangoma_tdm_get_power_level(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api);
+int sangoma_tdm_set_power_level(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api, int power);
+int sangoma_tdm_get_power_level(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api);
/* Flush buffers from current channel */
-int sangoma_tdm_flush_bufs(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api);
+int sangoma_tdm_flush_bufs(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api);
-int sangoma_tdm_enable_rbs_events(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api, int poll_in_sec);
-int sangoma_tdm_disable_rbs_events(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api);
+int sangoma_tdm_enable_rbs_events(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api, int poll_in_sec);
+int sangoma_tdm_disable_rbs_events(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api);
-int sangoma_tdm_write_rbs(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api, unsigned char rbs);
+int sangoma_tdm_write_rbs(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api, unsigned char rbs);
-int sangoma_tdm_read_event(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api);
+int sangoma_tdm_read_event(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api);
/* DTMF Detection on Octasic chip */
-int sangoma_tdm_enable_dtmf_events(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api);
-int sangoma_tdm_disable_dtmf_events(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api);
+int sangoma_tdm_enable_dtmf_events(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api);
+int sangoma_tdm_disable_dtmf_events(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api);
/* DTMF Detection on A200 (SLIC) chip */
-int sangoma_tdm_enable_rm_dtmf_events(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api);
-int sangoma_tdm_disable_rm_dtmf_events(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api);
+int sangoma_tdm_enable_rm_dtmf_events(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api);
+int sangoma_tdm_disable_rm_dtmf_events(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api);
/* On/Off hook events on A200 (Analog) card */
-int sangoma_tdm_enable_rxhook_events(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api);
-int sangoma_tdm_disable_rxhook_events(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api);
+int sangoma_tdm_enable_rxhook_events(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api);
+int sangoma_tdm_disable_rxhook_events(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api);
-int sangoma_tdm_get_fe_alarms(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api);
+int sangoma_tdm_get_fe_alarms(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api);
#ifndef LIBSANGOMA_GET_HWCODING
#define LIBSANGOMA_GET_HWCODING 1
#endif
-int sangoma_tdm_get_hw_coding(int fd, wanpipe_tdm_api_t * tdm_api);
+int sangoma_tdm_get_hw_coding(int fd, wanpipe_tdm_api_t *tdm_api);
-#endif /* WANPIPE_TDM_API */
+#endif /* WANPIPE_TDM_API */
#endif
Modified: freeswitch/trunk/src/mod/endpoints/mod_wanpipe/mod_wanpipe.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_wanpipe/mod_wanpipe.c (original)
+++ freeswitch/trunk/src/mod/endpoints/mod_wanpipe/mod_wanpipe.c Mon Apr 9 15:27:59 2007
@@ -80,8 +80,8 @@
char map[SANGOMA_MAX_CHAN_PER_SPAN][SWITCH_UUID_FORMATTED_LENGTH + 1];
};
-unsigned int txseq = 0;
-unsigned int rxseq = 0;
+unsigned int txseq=0;
+unsigned int rxseq=0;
#define SETUP_LEN CORE_MAX_CHAN_PER_SPAN*CORE_MAX_SPANS+1
@@ -99,7 +99,7 @@
typedef struct ss7boost_handle ss7boost_handle_t;
-static int isup_exec_command(ss7boost_handle_t * ss7boost_handle, int span, int chan, int id, int cmd, int cause);
+static int isup_exec_command(ss7boost_handle_t *ss7boost_handle, int span, int chan, int id, int cmd, int cause);
static struct {
int debug;
@@ -210,38 +210,38 @@
-static int local_sangoma_tdm_read_event(sng_fd_t fd, wp_tdm_api_rx_hdr_t * rx_event)
+static int local_sangoma_tdm_read_event(sng_fd_t fd, wp_tdm_api_rx_hdr_t *rx_event)
{
wanpipe_tdm_api_t tdm_api[1];
-
+
#if defined(WIN32)
- rx_event = &last_tdm_api_event_buffer;
+ rx_event = &last_tdm_api_event_buffer;
#else
- int err;
+ int err;
- tdm_api->wp_tdm_cmd.cmd = SIOC_WP_TDM_READ_EVENT;
+ tdm_api->wp_tdm_cmd.cmd = SIOC_WP_TDM_READ_EVENT;
- if ((err = sangoma_tdm_cmd_exec(fd, tdm_api))) {
- return err;
- }
+ if ((err = sangoma_tdm_cmd_exec(fd, tdm_api))) {
+ return err;
+ }
- rx_event = &tdm_api->wp_tdm_cmd.event;
+ rx_event = &tdm_api->wp_tdm_cmd.event;
#endif
return 0;
}
-static int analog_set_state(analog_channel_t * alc, analog_state_t state)
+static int analog_set_state(analog_channel_t *alc, analog_state_t state)
{
alc->state = state;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Changing State to %d\n", state);
}
-static void analog_check_state(analog_channel_t * alc)
+static void analog_check_state(analog_channel_t *alc)
{
wanpipe_tdm_api_t tdm_api;
- switch (alc->state) {
+ switch(alc->state) {
case ANALOG_STATE_DOWN:
sangoma_tdm_enable_rxhook_events(alc->sock->fd, &tdm_api);
analog_set_state(alc, ANALOG_STATE_ONHOOK);
@@ -251,11 +251,11 @@
}
}
-static void analog_parse_event(analog_channel_t * alc)
+static void analog_parse_event(analog_channel_t *alc)
{
wp_tdm_api_rx_hdr_t rx_event;
int err = local_sangoma_tdm_read_event(alc->sock->fd, &rx_event);
-
+
if (err < 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error reading event!\n");
return;
@@ -269,21 +269,21 @@
}
-static void *SWITCH_THREAD_FUNC fxs_thread_run(switch_thread_t * thread, void *obj)
+static void *SWITCH_THREAD_FUNC fxs_thread_run(switch_thread_t *thread, void *obj)
{
- for (;;) {
+ for(;;) {
int i = 0, sel_on = -1;
fd_set oob;
FD_ZERO(&oob);
-
- for (i = 0; i < globals.fxs_index; i++) {
+
+ for(i = 0; i < globals.fxs_index; i++) {
int fd;
assert(FXS_ANALOG_CHANNELS[i]);
assert(FXS_ANALOG_CHANNELS[i]->sock);
fd = FXS_ANALOG_CHANNELS[i]->sock->fd;
-
+
analog_check_state(FXS_ANALOG_CHANNELS[i]);
FD_SET(fd, &oob);
@@ -295,7 +295,7 @@
if (sel_on > -1) {
if (select(++sel_on, NULL, NULL, &oob, NULL)) {
- for (i = 0; i < globals.fxs_index; i++) {
+ for(i = 0; i < globals.fxs_index; i++) {
int fd = FXS_ANALOG_CHANNELS[i]->sock->fd;
if (FD_ISSET(fd, &oob)) {
analog_parse_event(FXS_ANALOG_CHANNELS[i]);
@@ -307,7 +307,7 @@
}
-static int wp_close(private_object_t * tech_pvt)
+static int wp_close(private_object_t *tech_pvt)
{
int ret = 0;
@@ -317,16 +317,16 @@
ret = 1;
}
switch_mutex_unlock(globals.hash_mutex);
-
+
return ret;
}
-static wpsock_t *wp_open(private_object_t * tech_pvt, int span, int chan)
+static wpsock_t *wp_open(private_object_t *tech_pvt, int span, int chan)
{
sng_fd_t fd;
wpsock_t *sock;
char name[25];
-
+
snprintf(name, sizeof(name), "s%dc%d", span, chan);
switch_mutex_lock(globals.hash_mutex);
@@ -364,7 +364,7 @@
wpsock_t *sock;
sng_fd_t fd;
char name[25];
-
+
snprintf(name, sizeof(name), "s%dc%d", span, chan);
switch_mutex_lock(globals.hash_mutex);
@@ -380,7 +380,7 @@
sangoma_socket_close(&fd);
return 0;
}
-
+
return -1;
}
@@ -444,7 +444,7 @@
if (!strcasecmp(dp, "local"))
return PRI_LOCAL_ISDN;
if (!strcasecmp(dp, "private"))
- return PRI_PRIVATE;
+ return PRI_PRIVATE;
if (!strcasecmp(dp, "unknown"))
return PRI_UNKNOWN;
@@ -460,25 +460,26 @@
static switch_status_t wanpipe_on_hangup(switch_core_session_t *session);
static switch_status_t wanpipe_on_loopback(switch_core_session_t *session);
static switch_status_t wanpipe_on_transmit(switch_core_session_t *session);
-static switch_call_cause_t wanpipe_outgoing_channel(switch_core_session_t *session,
- switch_caller_profile_t *outbound_profile,
+static switch_call_cause_t wanpipe_outgoing_channel(switch_core_session_t *session, switch_caller_profile_t *outbound_profile,
switch_core_session_t **new_session, switch_memory_pool_t **pool);
-static switch_status_t wanpipe_read_frame(switch_core_session_t *session, switch_frame_t **frame, int timeout, switch_io_flag_t flags, int stream_id);
-static switch_status_t wanpipe_write_frame(switch_core_session_t *session, switch_frame_t *frame, int timeout, switch_io_flag_t flags, int stream_id);
-static int on_info(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event * pevent);
-static int on_hangup(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event * pevent);
-static int on_ring(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event * pevent);
+static switch_status_t wanpipe_read_frame(switch_core_session_t *session, switch_frame_t **frame, int timeout,
+ switch_io_flag_t flags, int stream_id);
+static switch_status_t wanpipe_write_frame(switch_core_session_t *session, switch_frame_t *frame, int timeout,
+ switch_io_flag_t flags, int stream_id);
+static int on_info(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event *pevent);
+static int on_hangup(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event *pevent);
+static int on_ring(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event *pevent);
static int check_flags(struct sangoma_pri *spri);
-static int on_restart(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event * pevent);
-static int on_anything(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event * pevent);
-static void *SWITCH_THREAD_FUNC pri_thread_run(switch_thread_t * thread, void *obj);
+static int on_restart(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event *pevent);
+static int on_anything(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event *pevent);
+static void *SWITCH_THREAD_FUNC pri_thread_run(switch_thread_t *thread, void *obj);
static switch_status_t config_wanpipe(int reload);
-static switch_status_t wanpipe_codec_init(private_object_t * tech_pvt)
+static switch_status_t wanpipe_codec_init(private_object_t *tech_pvt)
{
int err = 0;
- wanpipe_tdm_api_t tdm_api = { {0} };
+ wanpipe_tdm_api_t tdm_api = {{0}};
unsigned int rate = 8000;
switch_channel_t *channel = NULL;
@@ -491,21 +492,21 @@
assert(channel != NULL);
err = sangoma_tdm_set_codec(tech_pvt->wpsock->fd, &tdm_api, WP_SLINEAR);
-
+
sangoma_tdm_set_usr_period(tech_pvt->wpsock->fd, &tdm_api, globals.samples_per_frame / 8);
tech_pvt->frame_size = sangoma_tdm_get_usr_mtu_mru(tech_pvt->wpsock->fd, &tdm_api);
if (switch_core_codec_init
- (&tech_pvt->read_codec, "L16", NULL, rate, globals.samples_per_frame / 8, 1,
- SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL, switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
+ (&tech_pvt->read_codec, "L16", NULL, rate, globals.samples_per_frame / 8, 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL,
+ switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%s Cannot set read codec\n", switch_channel_get_name(channel));
switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
return SWITCH_STATUS_FALSE;
}
if (switch_core_codec_init
- (&tech_pvt->write_codec, "L16", NULL, rate, globals.samples_per_frame / 8, 1,
- SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL, switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
+ (&tech_pvt->write_codec, "L16", NULL, rate, globals.samples_per_frame / 8, 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL,
+ switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%s Cannot set read codec\n", switch_channel_get_name(channel));
switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
return SWITCH_STATUS_FALSE;
@@ -515,25 +516,25 @@
switch_core_session_set_read_codec(tech_pvt->session, &tech_pvt->read_codec);
switch_core_session_set_write_codec(tech_pvt->session, &tech_pvt->write_codec);
-#ifdef DOTRACE
- tech_pvt->fd = open("/tmp/wp-in.raw", O_WRONLY | O_TRUNC | O_CREAT);
- tech_pvt->fd2 = open("/tmp/wp-out.raw", O_WRONLY | O_TRUNC | O_CREAT);
+#ifdef DOTRACE
+ tech_pvt->fd = open("/tmp/wp-in.raw", O_WRONLY | O_TRUNC | O_CREAT);
+ tech_pvt->fd2 = open("/tmp/wp-out.raw", O_WRONLY | O_TRUNC | O_CREAT);
#endif
/* Setup artificial DTMF stuff */
memset(&tech_pvt->tone_session, 0, sizeof(tech_pvt->tone_session));
teletone_init_session(&tech_pvt->tone_session, 1024, NULL, NULL);
-
+
if (globals.debug) {
tech_pvt->tone_session.debug = globals.debug;
tech_pvt->tone_session.debug_stream = stdout;
}
-
+
tech_pvt->tone_session.rate = rate;
tech_pvt->tone_session.duration = globals.dtmf_on * (tech_pvt->tone_session.rate / 1000);
tech_pvt->tone_session.wait = globals.dtmf_off * (tech_pvt->tone_session.rate / 1000);
-
- teletone_dtmf_detect_init(&tech_pvt->dtmf_detect, rate);
+
+ teletone_dtmf_detect_init (&tech_pvt->dtmf_detect, rate);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Audio init %s\n", switch_channel_get_name(channel));
switch_set_flag(tech_pvt, TFLAG_CODEC);
@@ -562,46 +563,46 @@
tech_pvt->read_frame.data = tech_pvt->databuf;
- if (tech_pvt->ss7boost_handle) {
+ if (tech_pvt->ss7boost_handle) {
if (switch_channel_test_flag(channel, CF_OUTBOUND)) {
ss7boost_client_event_t event;
event.calling_number_presentation = tech_pvt->boost_pres;
event.trunk_group = tech_pvt->boost_trunk_group;
-
+
switch_mutex_lock(tech_pvt->ss7boost_handle->mutex);
tech_pvt->setup_index = ++tech_pvt->ss7boost_handle->setup_index;
if (tech_pvt->ss7boost_handle->setup_index == SETUP_LEN - 1) {
tech_pvt->ss7boost_handle->setup_index = 0;
}
switch_mutex_unlock(tech_pvt->ss7boost_handle->mutex);
-
+
switch_copy_string(tech_pvt->ss7boost_handle->setup_array[tech_pvt->setup_index],
- switch_core_session_get_uuid(session), sizeof(tech_pvt->ss7boost_handle->setup_array[tech_pvt->setup_index]));
-
-
- ss7boost_client_call_init(&event, tech_pvt->caller_profile->caller_id_number, tech_pvt->caller_profile->destination_number,
- tech_pvt->setup_index);
-
+ switch_core_session_get_uuid(session),
+ sizeof(tech_pvt->ss7boost_handle->setup_array[tech_pvt->setup_index]));
+
+
+ ss7boost_client_call_init(&event, tech_pvt->caller_profile->caller_id_number, tech_pvt->caller_profile->destination_number, tech_pvt->setup_index);
+
if (ss7boost_client_connection_write(&tech_pvt->ss7boost_handle->mcon, &event) <= 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Critical System Error: Failed to tx on ISUP socket [%s]\n", strerror(errno));
}
-
+
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Call Called Event TG=%d\n", tech_pvt->boost_trunk_group);
goto done;
}
- }
+ }
if ((status = wanpipe_codec_init(tech_pvt)) != SWITCH_STATUS_SUCCESS) {
switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
return status;
}
-
+
if (switch_test_flag(tech_pvt, TFLAG_NOSIG)) {
switch_channel_mark_answered(channel);
}
- done:
+ done:
/* Move Channel's State Machine to RING */
switch_channel_set_state(channel, CS_RING);
@@ -621,7 +622,7 @@
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "WANPIPE RING\n");
-
+
return SWITCH_STATUS_SUCCESS;
}
@@ -632,7 +633,7 @@
switch_channel_t *channel = NULL;
struct channel_map *chanmap = NULL;
-
+
channel = switch_core_session_get_channel(session);
assert(channel != NULL);
@@ -655,7 +656,11 @@
switch_mutex_unlock(tech_pvt->ss7boost_handle->mutex);
if (!switch_test_flag(tech_pvt, TFLAG_BYE)) {
isup_exec_command(tech_pvt->ss7boost_handle,
- tech_pvt->boost_span_number, tech_pvt->boost_chan_number, -1, SIGBOOST_EVENT_CALL_STOPPED, SIGBOOST_RELEASE_CAUSE_NORMAL);
+ tech_pvt->boost_span_number,
+ tech_pvt->boost_chan_number,
+ -1,
+ SIGBOOST_EVENT_CALL_STOPPED,
+ SIGBOOST_RELEASE_CAUSE_NORMAL);
}
} else if (tech_pvt->spri) {
chanmap = tech_pvt->spri->private_info;
@@ -668,7 +673,7 @@
switch_mutex_lock(globals.channel_mutex);
*chanmap->map[tech_pvt->callno] = '\0';
switch_mutex_unlock(globals.channel_mutex);
-
+
}
switch_set_flag_locked(tech_pvt, TFLAG_BYE);
@@ -676,7 +681,7 @@
teletone_destroy_session(&tech_pvt->tone_session);
switch_buffer_destroy(&tech_pvt->dtmf_buffer);
-
+
return SWITCH_STATUS_SUCCESS;
}
@@ -720,7 +725,12 @@
pri_answer(tech_pvt->spri->pri, tech_pvt->call, 0, 1);
}
} else if (tech_pvt->ss7boost_handle) {
- isup_exec_command(tech_pvt->ss7boost_handle, tech_pvt->boost_span_number, tech_pvt->boost_chan_number, -1, SIGBOOST_EVENT_CALL_ANSWERED, 0);
+ isup_exec_command(tech_pvt->ss7boost_handle,
+ tech_pvt->boost_span_number,
+ tech_pvt->boost_chan_number,
+ -1,
+ SIGBOOST_EVENT_CALL_ANSWERED,
+ 0);
}
return SWITCH_STATUS_SUCCESS;
@@ -728,7 +738,8 @@
-static switch_status_t wanpipe_read_frame(switch_core_session_t *session, switch_frame_t **frame, int timeout, switch_io_flag_t flags, int stream_id)
+static switch_status_t wanpipe_read_frame(switch_core_session_t *session, switch_frame_t **frame, int timeout,
+ switch_io_flag_t flags, int stream_id)
{
private_object_t *tech_pvt;
switch_channel_t *channel = NULL;
@@ -761,7 +772,8 @@
}
if ((bread = sangoma_readmsg_socket(tech_pvt->wpsock->fd,
- &tech_pvt->hdrframe, sizeof(tech_pvt->hdrframe), bp, sizeof(tech_pvt->databuf) - bytes, 0)) < 0) {
+ &tech_pvt->hdrframe,
+ sizeof(tech_pvt->hdrframe), bp, sizeof(tech_pvt->databuf) - bytes, 0)) < 0) {
if (errno == EBUSY) {
continue;
} else {
@@ -780,10 +792,10 @@
tech_pvt->read_frame.datalen = bytes;
tech_pvt->read_frame.samples = bytes / 2;
- teletone_dtmf_detect(&tech_pvt->dtmf_detect, tech_pvt->read_frame.data, tech_pvt->read_frame.samples);
+ teletone_dtmf_detect (&tech_pvt->dtmf_detect, tech_pvt->read_frame.data, tech_pvt->read_frame.samples);
teletone_dtmf_get(&tech_pvt->dtmf_detect, digit_str, sizeof(digit_str));
-
- if (digit_str[0]) {
+
+ if(digit_str[0]) {
switch_channel_queue_dtmf(channel, digit_str);
if (globals.debug) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "DTMF DETECTED: [%s]\n", digit_str);
@@ -797,7 +809,8 @@
memset(tech_pvt->read_frame.data, 0, tech_pvt->read_frame.datalen);
tech_pvt->skip_read_frames--;
}
-#ifdef DOTRACE
+
+#ifdef DOTRACE
write(tech_pvt->fd2, tech_pvt->read_frame.data, (int) tech_pvt->read_frame.datalen);
#endif
//printf("read %d\n", tech_pvt->read_frame.datalen);
@@ -805,7 +818,8 @@
return SWITCH_STATUS_SUCCESS;
}
-static switch_status_t wanpipe_write_frame(switch_core_session_t *session, switch_frame_t *frame, int timeout, switch_io_flag_t flags, int stream_id)
+static switch_status_t wanpipe_write_frame(switch_core_session_t *session, switch_frame_t *frame, int timeout,
+ switch_io_flag_t flags, int stream_id)
{
private_object_t *tech_pvt;
uint32_t dtmf_blen;
@@ -822,24 +836,25 @@
if (tech_pvt->dtmf_buffer && (dtmf_blen = switch_buffer_inuse(tech_pvt->dtmf_buffer))) {
uint32_t len = dtmf_blen > frame->datalen ? frame->datalen : dtmf_blen;
- switch_buffer_read(tech_pvt->dtmf_buffer, tech_pvt->auxbuf, len);
+ switch_buffer_read(tech_pvt->dtmf_buffer, tech_pvt->auxbuf, len);
if (len < frame->datalen) {
uint8_t *data = frame->data;
memcpy(data + len, tech_pvt->auxbuf + len, frame->datalen - len);
}
- data = tech_pvt->auxbuf;
- }
-
+ data= tech_pvt->auxbuf;
+ }
+
if (tech_pvt->skip_write_frames) {
tech_pvt->skip_write_frames--;
return SWITCH_STATUS_SUCCESS;
}
+
#ifdef DOTRACE
write(tech_pvt->fd, data, frame->datalen);
#endif
result = sangoma_sendmsg_socket(tech_pvt->wpsock->fd, &tech_pvt->hdrframe, sizeof(tech_pvt->hdrframe), data, frame->datalen, 0);
-
+
if (result < 0 && errno != EBUSY) {
return SWITCH_STATUS_GENERR;
}
@@ -871,13 +886,13 @@
}
}
for (cur = digits; *cur; cur++) {
- if ((wrote = teletone_mux_tones(&tech_pvt->tone_session, &tech_pvt->tone_session.TONES[(int) *cur]))) {
+ if ((wrote = teletone_mux_tones(&tech_pvt->tone_session, &tech_pvt->tone_session.TONES[(int)*cur]))) {
switch_buffer_write(tech_pvt->dtmf_buffer, tech_pvt->tone_session.buffer, wrote * 2);
}
}
tech_pvt->skip_read_frames = 200;
-
+
return status;
}
@@ -888,7 +903,7 @@
channel = switch_core_session_get_channel(session);
assert(channel != NULL);
-
+
tech_pvt = (private_object_t *) switch_core_session_get_private(session);
assert(tech_pvt != NULL);
@@ -930,7 +945,7 @@
tech_pvt = switch_core_session_get_private(session);
assert(tech_pvt != NULL);
- switch (sig) {
+ switch(sig) {
case SWITCH_SIG_KILL:
switch_clear_flag_locked(tech_pvt, TFLAG_MEDIA);
break;
@@ -953,8 +968,8 @@
/*.kill_channel */ wanpipe_kill_channel,
/*.waitfor_read */ NULL,
/*.waitfor_read */ NULL,
- /*.send_dtmf */ wanpipe_send_dtmf,
- /*.receive_message */ wanpipe_receive_message
+ /*.send_dtmf*/ wanpipe_send_dtmf,
+ /*.receive_message*/ wanpipe_receive_message
};
static const switch_state_handler_table_t wanpipe_state_handlers = {
@@ -984,8 +999,7 @@
};
-static switch_call_cause_t wanpipe_outgoing_channel(switch_core_session_t *session,
- switch_caller_profile_t *outbound_profile,
+static switch_call_cause_t wanpipe_outgoing_channel(switch_core_session_t *session, switch_caller_profile_t *outbound_profile,
switch_core_session_t **new_session, switch_memory_pool_t **pool)
{
char *bchan = NULL;
@@ -994,7 +1008,7 @@
char *dest;
int ready = 0, is_pri = 0, is_boost = 0, is_raw = 0;
switch_call_cause_t cause = SWITCH_CAUSE_SUCCESS;
-
+
if (!outbound_profile) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Doh! no caller profile\n");
cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
@@ -1008,7 +1022,7 @@
cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
goto error;
}
-
+
*dest++ = '\0';
if (!strcasecmp(protocol, "raw")) {
@@ -1027,7 +1041,7 @@
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error No SS7BOOST Spans Configured.\n");
}
}
-
+
if (!ready) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot Continue!\n");
cause = SWITCH_CAUSE_NETWORK_OUT_OF_ORDER;
@@ -1061,7 +1075,7 @@
goto error;
}
-
+
caller_profile = switch_caller_profile_clone(*new_session, outbound_profile);
if (is_pri) {
@@ -1124,7 +1138,7 @@
}
switch_set_flag_locked(tech_pvt, TFLAG_NOSIG);
snprintf(name, sizeof(name), "wanpipe/%s/nosig", bchan);
- switch_channel_set_name(channel, name);
+ switch_channel_set_name(channel, name);
switch_channel_set_caller_profile(channel, caller_profile);
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid address\n");
@@ -1146,18 +1160,18 @@
if (SPANS[span] && (spri = &SPANS[span]->spri) && switch_test_flag(spri, SANGOMA_PRI_READY)) {
chanmap = spri->private_info;
-
+
if (autochan > 0) {
- for (callno = 1; callno < SANGOMA_MAX_CHAN_PER_SPAN; callno++) {
- if ((SPANS[span]->bchans & (1 << callno)) && !*chanmap->map[callno]) {
+ for(callno = 1; callno < SANGOMA_MAX_CHAN_PER_SPAN; callno++) {
+ if ((SPANS[span]->bchans & (1 << callno)) && ! *chanmap->map[callno]) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Choosing channel s%dc%d\n", span, callno);
goto done;
}
}
callno = 0;
} else if (autochan < 0) {
- for (callno = SANGOMA_MAX_CHAN_PER_SPAN; callno > 0; callno--) {
- if ((SPANS[span]->bchans & (1 << callno)) && !*chanmap->map[callno]) {
+ for(callno = SANGOMA_MAX_CHAN_PER_SPAN; callno > 0; callno--) {
+ if ((SPANS[span]->bchans & (1 << callno)) && ! *chanmap->map[callno]) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Choosing channel s%dc%d\n", span, callno);
goto done;
}
@@ -1172,7 +1186,7 @@
span--;
}
}
- done:
+ done:
switch_mutex_unlock(globals.channel_mutex);
if (!spri || callno == 0 || callno == (SANGOMA_MAX_CHAN_PER_SPAN)) {
@@ -1181,26 +1195,31 @@
cause = SWITCH_CAUSE_SWITCH_CONGESTION;
goto error;
}
-
+
tech_pvt->callno = callno;
-
+
if (spri && (tech_pvt->call = pri_new_call(spri->pri))) {
struct pri_sr *sr;
-
+
snprintf(name, sizeof(name), "wanpipe/pri/s%dc%d/%s", spri->span, callno, caller_profile->destination_number);
- switch_channel_set_name(channel, name);
+ switch_channel_set_name(channel, name);
switch_channel_set_caller_profile(channel, caller_profile);
sr = pri_sr_new();
pri_sr_set_channel(sr, callno, 0, 0);
pri_sr_set_bearer(sr, 0, SPANS[span]->l1);
pri_sr_set_called(sr, caller_profile->destination_number, SPANS[span]->dp, 1);
pri_sr_set_caller(sr,
- caller_profile->caller_id_number, caller_profile->caller_id_name, SPANS[span]->dp,
+ caller_profile->caller_id_number,
+ caller_profile->caller_id_name,
+ SPANS[span]->dp,
PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN);
- pri_sr_set_redirecting(sr, caller_profile->caller_id_number, SPANS[span]->dp, PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN,
+ pri_sr_set_redirecting(sr,
+ caller_profile->caller_id_number,
+ SPANS[span]->dp,
+ PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN,
PRI_REDIR_UNCONDITIONAL);
-
- if (pri_setup(spri->pri, tech_pvt->call, sr)) {
+
+ if (pri_setup(spri->pri, tech_pvt->call , sr)) {
switch_core_session_destroy(new_session);
pri_sr_free(sr);
cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
@@ -1215,7 +1234,9 @@
goto error;
}
pri_sr_free(sr);
- switch_copy_string(chanmap->map[callno], switch_core_session_get_uuid(*new_session), sizeof(chanmap->map[callno]));
+ switch_copy_string(chanmap->map[callno],
+ switch_core_session_get_uuid(*new_session),
+ sizeof(chanmap->map[callno]));
tech_pvt->spri = spri;
}
} else if (is_boost) {
@@ -1224,8 +1245,8 @@
if ((p = strchr(caller_profile->destination_number, '/'))) {
char *grp = caller_profile->destination_number;
*p = '\0';
- caller_profile->destination_number = p + 1;
- tech_pvt->boost_trunk_group = atoi(grp + 1) - 1;
+ caller_profile->destination_number = p+1;
+ tech_pvt->boost_trunk_group = atoi(grp+1) - 1;
if (tech_pvt->boost_trunk_group < 0) {
tech_pvt->boost_trunk_group = 0;
}
@@ -1248,7 +1269,7 @@
cause = SWITCH_CAUSE_SUCCESS;
}
- error:
+ error:
switch_safe_free(protocol);
return cause;
}
@@ -1310,7 +1331,7 @@
/*event Handlers */
-static int on_info(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event * pevent)
+static int on_info(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event *pevent)
{
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "number is: %s\n", pevent->ring.callednum);
if (strlen(pevent->ring.callednum) > 3) {
@@ -1320,7 +1341,7 @@
return 0;
}
-static int on_hangup(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event * pevent)
+static int on_hangup(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event *pevent)
{
struct channel_map *chanmap;
switch_core_session_t *session;
@@ -1343,7 +1364,7 @@
tech_pvt->cause = pevent->hangup.cause;
switch_set_flag_locked(tech_pvt, TFLAG_BYE);
switch_channel_hangup(channel, tech_pvt->cause);
-
+
switch_mutex_lock(globals.channel_mutex);
*chanmap->map[pevent->hangup.channel] = '\0';
switch_mutex_unlock(globals.channel_mutex);
@@ -1355,7 +1376,7 @@
return 0;
}
-static int on_answer(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event * pevent)
+static int on_answer(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event *pevent)
{
switch_core_session_t *session;
switch_channel_t *channel;
@@ -1373,12 +1394,12 @@
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "-- Answer on channel s%dc%d but it's not in use?\n", spri->span, pevent->answer.channel);
}
-
+
return 0;
}
-static int on_proceed(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event * pevent)
+static int on_proceed(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event *pevent)
{
switch_core_session_t *session;
switch_channel_t *channel;
@@ -1390,10 +1411,10 @@
switch_core_session_message_t *msg;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "-- Proceeding on channel s%dc%d\n", spri->span, pevent->proceeding.channel);
-
+
channel = switch_core_session_get_channel(session);
assert(channel != NULL);
-
+
if ((msg = malloc(sizeof(*msg)))) {
memset(msg, 0, sizeof(*msg));
msg->message_id = SWITCH_MESSAGE_INDICATE_PROGRESS;
@@ -1404,18 +1425,18 @@
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error!\n");
}
-
+
switch_core_session_rwunlock(session);
} else {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE,
- "-- Proceeding on channel s%dc%d but it's not in use?\n", spri->span, pevent->proceeding.channel);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "-- Proceeding on channel s%dc%d but it's not in use?\n",
+ spri->span, pevent->proceeding.channel);
}
return 0;
}
-static int on_ringing(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event * pevent)
+static int on_ringing(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event *pevent)
{
switch_core_session_t *session;
switch_channel_t *channel;
@@ -1434,35 +1455,34 @@
switch_core_session_rwunlock(session);
} else {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
- "-- Ringing on channel s%dc%d %s but it's not in use?\n", spri->span, pevent->ringing.channel,
- chanmap->map[pevent->ringing.channel]);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "-- Ringing on channel s%dc%d %s but it's not in use?\n", spri->span, pevent->ringing.channel, chanmap->map[pevent->ringing.channel]);
}
return 0;
}
-static int on_ring(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event * pevent)
+static int on_ring(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event *pevent)
{
char name[128];
switch_core_session_t *session;
switch_channel_t *channel;
struct channel_map *chanmap;
int ret = 0;
-
+
switch_mutex_lock(globals.channel_mutex);
chanmap = spri->private_info;
if (switch_core_session_locate(chanmap->map[pevent->ring.channel])) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "--Duplicate Ring on channel s%dc%d (ignored)\n", spri->span, pevent->ring.channel);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "--Duplicate Ring on channel s%dc%d (ignored)\n",
+ spri->span, pevent->ring.channel);
switch_core_session_rwunlock(session);
ret = 0;
goto done;
}
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "-- Ring on channel s%dc%d (from %s to %s)\n", spri->span,
- pevent->ring.channel, pevent->ring.callingnum, pevent->ring.callednum);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "-- Ring on channel s%dc%d (from %s to %s)\n", spri->span, pevent->ring.channel,
+ pevent->ring.callingnum, pevent->ring.callednum);
pri_proceeding(spri->pri, pevent->ring.call, pevent->ring.channel, 0);
@@ -1494,14 +1514,21 @@
}
if ((tech_pvt->caller_profile = switch_caller_profile_new(switch_core_session_get_pool(session),
- NULL, globals.dialplan, "FreeSWITCH", pevent->ring.callingnum,
+ NULL,
+ globals.dialplan,
+ "FreeSWITCH",
+ pevent->ring.callingnum,
#ifdef WIN32
NULL,
#else
pevent->ring.callingani,
#endif
switch_strlen_zero(ani2str) ? NULL : ani2str,
- NULL, NULL, (char *) modname, NULL, pevent->ring.callednum))) {
+ NULL,
+ NULL,
+ (char *)modname,
+ NULL,
+ pevent->ring.callednum))) {
switch_channel_set_caller_profile(channel, tech_pvt->caller_profile);
}
@@ -1512,7 +1539,7 @@
if (!tech_pvt->call) {
tech_pvt->call = pevent->ring.call;
}
-
+
tech_pvt->callno = pevent->ring.channel;
tech_pvt->span = spri->span;
@@ -1521,16 +1548,16 @@
}
switch_copy_string(chanmap->map[pevent->ring.channel], switch_core_session_get_uuid(session), sizeof(chanmap->map[pevent->ring.channel]));
-
+
switch_channel_set_state(channel, CS_INIT);
switch_core_session_thread_launch(session);
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot Create new Inbound Channel!\n");
}
- done:
+ done:
switch_mutex_unlock(globals.channel_mutex);
-
+
return ret;
}
@@ -1540,7 +1567,7 @@
return 0;
}
-static int on_restart(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event * pevent)
+static int on_restart(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event *pevent)
{
switch_core_session_t *session;
struct channel_map *chanmap;
@@ -1554,7 +1581,7 @@
chanmap = spri->private_info;
-
+
if ((session = switch_core_session_locate(chanmap->map[pevent->restart.channel]))) {
switch_channel_t *channel;
channel = switch_core_session_get_channel(session);
@@ -1562,13 +1589,13 @@
switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
switch_core_session_rwunlock(session);
}
-
+
wp_restart(spri->span, pevent->restart.channel);
return 0;
}
-static int on_dchan_up(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event * pevent)
+static int on_dchan_up(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event *pevent)
{
if (!switch_test_flag(spri, SANGOMA_PRI_READY)) {
@@ -1579,26 +1606,27 @@
return 0;
}
-static int on_dchan_down(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event * pevent)
+static int on_dchan_down(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event *pevent)
{
if (switch_test_flag(spri, SANGOMA_PRI_READY)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Span %d D-Chan DOWN!\n", spri->span);
switch_clear_flag(spri, SANGOMA_PRI_READY);
}
-
+
return 0;
}
-static int on_anything(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event * pevent)
+static int on_anything(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event *pevent)
{
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Caught Event span %d %u (%s)\n", spri->span, event_type, sangoma_pri_event_str(event_type));
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Caught Event span %d %u (%s)\n", spri->span, event_type,
+ sangoma_pri_event_str(event_type));
return 0;
}
-static void *SWITCH_THREAD_FUNC pri_thread_run(switch_thread_t * thread, void *obj)
+static void *SWITCH_THREAD_FUNC pri_thread_run(switch_thread_t *thread, void *obj)
{
struct sangoma_pri *spri = obj;
struct channel_map chanmap;
@@ -1637,7 +1665,7 @@
{
switch_thread_t *thread;
switch_threadattr_t *thd_attr = NULL;
-
+
switch_threadattr_create(&thd_attr, module_pool);
switch_threadattr_detach_set(thd_attr, 1);
switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
@@ -1646,7 +1674,7 @@
}
-static int isup_exec_command(ss7boost_handle_t * ss7boost_handle, int span, int chan, int id, int cmd, int cause)
+static int isup_exec_command(ss7boost_handle_t *ss7boost_handle, int span, int chan, int id, int cmd, int cause)
{
ss7boost_client_event_t oevent;
int r = 0;
@@ -1654,12 +1682,12 @@
switch_mutex_lock(ss7boost_handle->mutex);
ss7boost_client_event_init(&oevent, cmd, chan, span);
oevent.release_cause = cause;
-
+
if (id >= 0) {
oevent.call_setup_id = id;
}
-
- if (ss7boost_client_connection_write(&ss7boost_handle->mcon, &oevent) <= 0) {
+
+ if (ss7boost_client_connection_write(&ss7boost_handle->mcon, &oevent) <= 0){
r = -1;
}
@@ -1671,26 +1699,26 @@
#ifdef USE_WAITFOR_SOCKET
static int waitfor_socket(int fd, int timeout, int flags)
{
- struct pollfd pfds[1];
- int res;
-
- memset(&pfds[0], 0, sizeof(pfds[0]));
- pfds[0].fd = fd;
- pfds[0].events = flags;
- res = poll(pfds, 1, timeout);
-
- if (res > 0) {
- if (pfds[0].revents & POLLIN) {
- res = 1;
- } else if ((pfds[0].revents & POLLERR)) {
- res = -1;
- } else {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "System Error: Poll Event Error no event!\n");
- res = -1;
- }
+ struct pollfd pfds[1];
+ int res;
+
+ memset(&pfds[0], 0, sizeof(pfds[0]));
+ pfds[0].fd = fd;
+ pfds[0].events = flags;
+ res = poll(pfds, 1, timeout);
+
+ if (res > 0) {
+ if(pfds[0].revents & POLLIN) {
+ res = 1;
+ } else if ((pfds[0].revents & POLLERR)) {
+ res = -1;
+ } else {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,"System Error: Poll Event Error no event!\n");
+ res = -1;
}
+ }
- return res;
+ return res;
}
#endif
@@ -1708,7 +1736,7 @@
}
-static void handle_call_stop(ss7boost_handle_t * ss7boost_handle, ss7boost_client_event_t * event)
+static void handle_call_stop(ss7boost_handle_t *ss7boost_handle, ss7boost_client_event_t *event)
{
char *uuid = ss7boost_handle->span_chanmap[event->span].map[event->chan];
@@ -1718,7 +1746,7 @@
if ((session = switch_core_session_locate(uuid))) {
private_object_t *tech_pvt;
switch_channel_t *channel;
-
+
channel = switch_core_session_get_channel(session);
assert(channel != NULL);
@@ -1730,25 +1758,35 @@
}
*uuid = '\0';
- }
+ }
- isup_exec_command(ss7boost_handle, event->span, event->chan, -1, SIGBOOST_EVENT_CALL_STOPPED_ACK, 0);
+ isup_exec_command(ss7boost_handle,
+ event->span,
+ event->chan,
+ -1,
+ SIGBOOST_EVENT_CALL_STOPPED_ACK,
+ 0);
}
-static void handle_call_start(ss7boost_handle_t * ss7boost_handle, ss7boost_client_event_t * event)
+static void handle_call_start(ss7boost_handle_t *ss7boost_handle, ss7boost_client_event_t *event)
{
switch_core_session_t *session = NULL;
switch_channel_t *channel = NULL;
char name[128];
if (*ss7boost_handle->span_chanmap[event->span].map[event->chan]) {
- isup_exec_command(ss7boost_handle, event->span, event->chan, -1, SIGBOOST_EVENT_CALL_START_NACK, SIGBOOST_RELEASE_CAUSE_BUSY);
+ isup_exec_command(ss7boost_handle,
+ event->span,
+ event->chan,
+ -1,
+ SIGBOOST_EVENT_CALL_START_NACK,
+ SIGBOOST_RELEASE_CAUSE_BUSY);
return;
}
-
+
if ((session = switch_core_session_request(&wanpipe_endpoint_interface, NULL))) {
private_object_t *tech_pvt;
@@ -1758,7 +1796,7 @@
switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
channel = switch_core_session_get_channel(session);
switch_core_session_set_private(session, tech_pvt);
- sprintf(name, "wanpipe/ss7boost/s%dc%d", event->span + 1, event->chan + 1);
+ sprintf(name, "wanpipe/ss7boost/s%dc%d", event->span+1, event->chan+1);
switch_channel_set_name(channel, name);
tech_pvt->session = session;
} else {
@@ -1768,13 +1806,21 @@
if ((tech_pvt->caller_profile = switch_caller_profile_new(switch_core_session_get_pool(session),
- NULL, globals.dialplan, "FreeSWITCH(boost)", (char *) event->calling_number_digits,
+ NULL,
+ globals.dialplan,
+ "FreeSWITCH(boost)",
+ (char *)event->calling_number_digits,
#ifdef WIN32
NULL,
#else
- (char *) event->calling_number_digits,
+ (char *)event->calling_number_digits,
#endif
- NULL, NULL, NULL, (char *) modname, NULL, (char *) event->called_number_digits))) {
+ NULL,
+ NULL,
+ NULL,
+ (char *)modname,
+ NULL,
+ (char *)event->called_number_digits))) {
switch_channel_set_caller_profile(channel, tech_pvt->caller_profile);
}
@@ -1786,73 +1832,88 @@
tech_pvt->boost_span_number = event->span;
tech_pvt->boost_chan_number = event->chan;
tech_pvt->boost_pres = event->calling_number_presentation;
-
- if (!wp_open(tech_pvt, event->span + 1, event->chan + 1)) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't open channel %d:%d\n", event->span + 1, event->chan + 1);
+
+ if (!wp_open(tech_pvt, event->span+1, event->chan+1)) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't open channel %d:%d\n", event->span+1, event->chan+1);
goto fail;
}
- switch_copy_string(ss7boost_handle->span_chanmap[event->span].map[event->chan],
- switch_core_session_get_uuid(session), sizeof(ss7boost_handle->span_chanmap[event->span].map[event->chan]));
-
+ switch_copy_string(ss7boost_handle->span_chanmap[event->span].map[event->chan], switch_core_session_get_uuid(session),
+ sizeof(ss7boost_handle->span_chanmap[event->span].map[event->chan]));
+
switch_channel_set_state(channel, CS_INIT);
- isup_exec_command(ss7boost_handle, event->span, event->chan, -1, SIGBOOST_EVENT_CALL_START_ACK, 0);
+ isup_exec_command(ss7boost_handle,
+ event->span,
+ event->chan,
+ -1,
+ SIGBOOST_EVENT_CALL_START_ACK,
+ 0);
switch_core_session_thread_launch(session);
return;
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot Create new Inbound Channel!\n");
}
-
- fail:
+
+ fail:
if (session) {
switch_core_session_destroy(&session);
}
- isup_exec_command(ss7boost_handle, event->span, event->chan, -1, SIGBOOST_EVENT_CALL_STOPPED, SIGBOOST_RELEASE_CAUSE_BUSY);
+ isup_exec_command(ss7boost_handle,
+ event->span,
+ event->chan,
+ -1,
+ SIGBOOST_EVENT_CALL_STOPPED,
+ SIGBOOST_RELEASE_CAUSE_BUSY);
}
-static void handle_heartbeat(ss7boost_handle_t * ss7boost_handle, ss7boost_client_event_t * event)
+static void handle_heartbeat(ss7boost_handle_t *ss7boost_handle, ss7boost_client_event_t *event)
{
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Heartbeat!\n");
- isup_exec_command(ss7boost_handle, event->span, event->chan, -1, SIGBOOST_EVENT_HEARTBEAT, 0);
+ isup_exec_command(ss7boost_handle,
+ event->span,
+ event->chan,
+ -1,
+ SIGBOOST_EVENT_HEARTBEAT,
+ 0);
}
-static void handle_call_start_ack(ss7boost_handle_t * ss7boost_handle, ss7boost_client_event_t * event)
+static void handle_call_start_ack(ss7boost_handle_t *ss7boost_handle, ss7boost_client_event_t *event)
{
char *uuid = ss7boost_handle->setup_array[event->call_setup_id];
-
+
if (*uuid) {
switch_core_session_t *session;
if ((session = switch_core_session_locate(uuid))) {
private_object_t *tech_pvt;
switch_channel_t *channel;
-
+
channel = switch_core_session_get_channel(session);
assert(channel != NULL);
-
+
tech_pvt = switch_core_session_get_private(session);
assert(tech_pvt != NULL);
-
+
tech_pvt->ss7boost_handle = ss7boost_handle;
tech_pvt->boost_span_number = event->span;
tech_pvt->boost_chan_number = event->chan;
-
- switch_copy_string(ss7boost_handle->span_chanmap[event->span].map[event->chan],
- switch_core_session_get_uuid(session), sizeof(ss7boost_handle->span_chanmap[event->span].map[event->chan]));
+
+ switch_copy_string(ss7boost_handle->span_chanmap[event->span].map[event->chan], switch_core_session_get_uuid(session),
+ sizeof(ss7boost_handle->span_chanmap[event->span].map[event->chan]));
if (!tech_pvt->wpsock) {
- if (!wp_open(tech_pvt, tech_pvt->boost_span_number + 1, tech_pvt->boost_chan_number + 1)) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't open fd for s%dc%d! [%s]\n",
- tech_pvt->boost_span_number + 1, tech_pvt->boost_chan_number + 1, strerror(errno));
+ if (!wp_open(tech_pvt, tech_pvt->boost_span_number+1, tech_pvt->boost_chan_number+1)) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't open fd for s%dc%d! [%s]\n",
+ tech_pvt->boost_span_number+1, tech_pvt->boost_chan_number+1, strerror(errno));
switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
return;
}
@@ -1863,29 +1924,29 @@
}
switch_channel_mark_pre_answered(channel);
-
+
switch_core_session_rwunlock(session);
}
*uuid = '\0';
}
}
-static void handle_call_start_nack_ack(ss7boost_handle_t * ss7boost_handle, ss7boost_client_event_t * event)
+static void handle_call_start_nack_ack(ss7boost_handle_t *ss7boost_handle, ss7boost_client_event_t *event)
{
// WTF IS THIS! ?
}
-static void handle_call_answer(ss7boost_handle_t * ss7boost_handle, ss7boost_client_event_t * event)
+static void handle_call_answer(ss7boost_handle_t *ss7boost_handle, ss7boost_client_event_t *event)
{
char *uuid = ss7boost_handle->span_chanmap[event->span].map[event->chan];
if (*uuid) {
switch_core_session_t *session;
-
+
if ((session = switch_core_session_locate(uuid))) {
private_object_t *tech_pvt;
switch_channel_t *channel;
-
+
channel = switch_core_session_get_channel(session);
assert(channel != NULL);
@@ -1893,9 +1954,9 @@
assert(tech_pvt != NULL);
if (!tech_pvt->wpsock) {
- if (!wp_open(tech_pvt, tech_pvt->boost_span_number + 1, tech_pvt->boost_chan_number + 1)) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't open fd for s%dc%d! [%s]\n",
- tech_pvt->boost_span_number + 1, tech_pvt->boost_chan_number + 1, strerror(errno));
+ if (!wp_open(tech_pvt, tech_pvt->boost_span_number+1, tech_pvt->boost_chan_number+1)) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't open fd for s%dc%d! [%s]\n",
+ tech_pvt->boost_span_number+1, tech_pvt->boost_chan_number+1, strerror(errno));
switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
return;
}
@@ -1904,7 +1965,7 @@
return;
}
}
-
+
switch_channel_mark_answered(channel);
switch_core_session_rwunlock(session);
} else {
@@ -1917,36 +1978,41 @@
}
}
-static void handle_call_stop_ack(ss7boost_handle_t * ss7boost_handle, ss7boost_client_event_t * event)
+static void handle_call_stop_ack(ss7boost_handle_t *ss7boost_handle, ss7boost_client_event_t *event)
{
// TODO anything here?
}
-static void handle_call_start_nack(ss7boost_handle_t * ss7boost_handle, ss7boost_client_event_t * event)
+static void handle_call_start_nack(ss7boost_handle_t *ss7boost_handle, ss7boost_client_event_t *event)
{
char *uuid = ss7boost_handle->setup_array[event->call_setup_id];
-
+
if (*uuid) {
switch_core_session_t *session;
if ((session = switch_core_session_locate(uuid))) {
private_object_t *tech_pvt;
switch_channel_t *channel;
-
+
channel = switch_core_session_get_channel(session);
assert(channel != NULL);
-
+
tech_pvt = switch_core_session_get_private(session);
assert(tech_pvt != NULL);
-
+
tech_pvt->ss7boost_handle = ss7boost_handle;
tech_pvt->boost_span_number = event->span;
tech_pvt->boost_chan_number = event->chan;
-
+
switch_channel_hangup(channel, event->release_cause);
-
- isup_exec_command(ss7boost_handle, event->span, event->chan, event->call_setup_id, SIGBOOST_EVENT_CALL_START_NACK_ACK, 0);
+
+ isup_exec_command(ss7boost_handle,
+ event->span,
+ event->chan,
+ event->call_setup_id,
+ SIGBOOST_EVENT_CALL_START_NACK_ACK,
+ 0);
switch_core_session_rwunlock(session);
} else {
@@ -1956,14 +2022,14 @@
}
}
-static int parse_ss7_event(ss7boost_handle_t * ss7boost_handle, ss7boost_client_event_t * event)
+static int parse_ss7_event(ss7boost_handle_t *ss7boost_handle, ss7boost_client_event_t *event)
{
int ret = 0;
switch_mutex_lock(ss7boost_handle->mutex);
-
- validate_number((unsigned char *) event->called_number_digits);
- validate_number((unsigned char *) event->calling_number_digits);
+
+ validate_number((unsigned char*)event->called_number_digits);
+ validate_number((unsigned char*)event->calling_number_digits);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
"\nRX EVENT\n"
@@ -1982,16 +2048,21 @@
"\n",
ss7boost_client_event_id_name(event->event_id),
event->event_id,
- event->span + 1,
- event->chan + 1,
+ event->span+1,
+ event->chan+1,
(event->called_number_digits_count ? (char *) event->called_number_digits : "N/A"),
(event->calling_number_digits_count ? (char *) event->calling_number_digits : "N/A"),
- switch_channel_cause2str(event->release_cause), event->span + 1, event->chan + 1, event->event_id, event->call_setup_id,
- event->seqno);
-
-
- switch (event->event_id) {
+ switch_channel_cause2str(event->release_cause),
+ event->span+1,
+ event->chan+1,
+ event->event_id,
+ event->call_setup_id,
+ event->seqno
+ );
+
+ switch(event->event_id) {
+
case SIGBOOST_EVENT_CALL_START:
handle_call_start(ss7boost_handle, event);
break;
@@ -2017,7 +2088,7 @@
handle_call_stop_ack(ss7boost_handle, event);
break;
default:
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Warning no handler implemented for [%s]\n",
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Warning no handler implemented for [%s]\n",
ss7boost_client_event_id_name(event->event_id));
break;
}
@@ -2025,40 +2096,48 @@
return ret;
}
-static void *SWITCH_THREAD_FUNC boost_thread_run(switch_thread_t * thread, void *obj)
+static void *SWITCH_THREAD_FUNC boost_thread_run(switch_thread_t *thread, void *obj)
{
ss7boost_handle_t *ss7boost_handle = (ss7boost_handle_t *) obj;
ss7boost_client_event_t *event;
if (ss7boost_client_connection_open(&ss7boost_handle->mcon,
- ss7boost_handle->local_ip,
- ss7boost_handle->local_port,
- ss7boost_handle->remote_ip, ss7boost_handle->remote_port, module_pool) != SWITCH_STATUS_SUCCESS) {
+ ss7boost_handle->local_ip,
+ ss7boost_handle->local_port,
+ ss7boost_handle->remote_ip,
+ ss7boost_handle->remote_port,
+ module_pool) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "FATAL ERROR CREATING CLIENT CONNECTION\n");
return NULL;
}
-
- isup_exec_command(ss7boost_handle, 0, 0, -1, SIGBOOST_EVENT_SYSTEM_RESTART, 0);
-
-
+
+ isup_exec_command(ss7boost_handle,
+ 0,
+ 0,
+ -1,
+ SIGBOOST_EVENT_SYSTEM_RESTART,
+ 0);
+
+
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Monitor Thread Started\n");
-
+
switch_mutex_lock(globals.hash_mutex);
globals.configured_boost_spans++;
switch_mutex_unlock(globals.hash_mutex);
globals.ss7boost_handle = ss7boost_handle;
-
- for (;;) {
+
+ for(;;) {
if (ss7boost_client_connection_read(&ss7boost_handle->mcon, &event) == SWITCH_STATUS_SUCCESS) {
- struct timeval current;
- struct timeval difftime;
- gettimeofday(¤t, NULL);
- timersub(¤t, &event->tv, &difftime);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Socket Event [%s] T=%d:%d\n",
- ss7boost_client_event_id_name(event->event_id), (int) difftime.tv_sec, (int) difftime.tv_usec);
-
- parse_ss7_event(ss7boost_handle, event);
+ struct timeval current;
+ struct timeval difftime;
+ gettimeofday(¤t,NULL);
+ timersub (¤t, &event->tv, &difftime);
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Socket Event [%s] T=%d:%d\n",
+ ss7boost_client_event_id_name(event->event_id),
+ (int)difftime.tv_sec, (int)difftime.tv_usec);
+
+ parse_ss7_event(ss7boost_handle, event);
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error: Reading from Boost Socket! %s\n", strerror(errno));
break;
@@ -2067,17 +2146,17 @@
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Close udp socket\n");
ss7boost_client_connection_close(&ss7boost_handle->mcon);
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Monitor Thread Ended\n");
-
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Monitor Thread Ended\n");
+
return NULL;
}
-static void launch_ss7boost_handle(ss7boost_handle_t * ss7boost_handle)
+static void launch_ss7boost_handle(ss7boost_handle_t *ss7boost_handle)
{
switch_thread_t *thread;
switch_threadattr_t *thd_attr = NULL;
-
+
switch_threadattr_create(&thd_attr, module_pool);
switch_threadattr_detach_set(thd_attr, 1);
switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
@@ -2134,7 +2213,7 @@
for (param = switch_xml_child(span, "param"); param; param = param->next) {
char *var = (char *) switch_xml_attr_soft(param, "name");
char *val = (char *) switch_xml_attr_soft(param, "value");
-
+
if (!strcasecmp(var, "local-ip")) {
local_ip = val;
} else if (!strcasecmp(var, "local-port")) {
@@ -2165,7 +2244,7 @@
}
analog_channels = switch_xml_child(cfg, "analog_channels");
- for (channel = switch_xml_child(analog_channels, "channel"); channel; channel = channel->next) {
+ for(channel = switch_xml_child(analog_channels, "channel"); channel; channel = channel->next) {
char *c_type = (char *) switch_xml_attr(channel, "type");
char *c_dev = (char *) switch_xml_attr(channel, "device");
char *user = NULL;
@@ -2175,7 +2254,7 @@
analog_type_t a_type = ANALOG_TYPE_UNKNOWN;
wpsock_t *sock;
int chan, span;
-
+
if (!c_type) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing required attribute 'type'\n");
continue;
@@ -2199,16 +2278,16 @@
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid device name '%s'\n", c_dev);
continue;
}
-
+
if (!(sock = wp_open(NULL, span, chan))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot open device '%s' (%s)\n", c_dev, strerror(errno));
continue;
}
for (param = switch_xml_child(channel, "param"); param; param = param->next) {
- char *var = (char *) switch_xml_attr_soft(param, "name");
- char *val = (char *) switch_xml_attr_soft(param, "value");
-
+ char *var = (char *) switch_xml_attr_soft(param, "name");
+ char *val = (char *) switch_xml_attr_soft(param, "value");
+
if (!strcasecmp(var, "user")) {
user = var;
} else if (!strcasecmp(var, "domain")) {
@@ -2234,7 +2313,7 @@
if (cid_num) {
alc->cid_name = strdup(cid_num);
}
-
+
alc->a_type = a_type;
alc->sock = sock;
alc->chan = chan;
@@ -2251,7 +2330,7 @@
if (globals.fxs_index) {
switch_thread_t *thread;
switch_threadattr_t *thd_attr = NULL;
-
+
switch_threadattr_create(&thd_attr, module_pool);
switch_threadattr_detach_set(thd_attr, 1);
switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
@@ -2266,10 +2345,10 @@
int32_t i = 0;
current_span = 0;
-
+
if (id) {
char *p;
-
+
min_span = atoi(id);
if ((p = strchr(id, '-'))) {
p++;
@@ -2285,16 +2364,16 @@
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Missing SPAN ID!\n");
continue;
}
-
+
for (i = min_span; i <= max_span; i++) {
current_span = i;
-
+
if (current_span <= 0 || current_span > MAX_SPANS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Invalid SPAN %d!\n", current_span);
current_span = 0;
continue;
}
-
+
if (!SPANS[current_span]) {
if (!(SPANS[current_span] = switch_core_alloc(module_pool, sizeof(*SPANS[current_span])))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "MEMORY ERROR\n");
@@ -2302,12 +2381,12 @@
}
SPANS[current_span]->span = current_span;
}
-
+
for (param = switch_xml_child(span, "param"); param; param = param->next) {
char *var = (char *) switch_xml_attr_soft(param, "name");
char *val = (char *) switch_xml_attr_soft(param, "value");
-
+
if (!strcmp(var, "dchan")) {
SPANS[current_span]->dchan = atoi(val);
} else if (!strcmp(var, "bchan")) {
@@ -2320,7 +2399,7 @@
fromi = atoi(from);
toi = atoi(to);
if (fromi > 0 && toi > 0 && fromi < toi && fromi < MAX_SPANS && toi < MAX_SPANS) {
- for (x = fromi; x <= toi; x++) {
+ for(x = fromi; x <= toi; x++) {
SPANS[current_span]->bchans |= (1 << x);
}
} else {
@@ -2354,14 +2433,18 @@
globals.configured_spans = 0;
- for (current_span = 1; current_span < MAX_SPANS; current_span++) {
+ for(current_span = 1; current_span < MAX_SPANS; current_span++) {
if (SPANS[current_span]) {
if (!SPANS[current_span]->l1) {
SPANS[current_span]->l1 = PRI_LAYER_1_ULAW;
}
if (sangoma_init_pri(&SPANS[current_span]->spri,
- current_span, SPANS[current_span]->dchan, SPANS[current_span]->pswitch, SPANS[current_span]->node, globals.debug)) {
+ current_span,
+ SPANS[current_span]->dchan,
+ SPANS[current_span]->pswitch,
+ SPANS[current_span]->node,
+ globals.debug)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Cannot launch span %d\n", current_span);
continue;
}
@@ -2378,3 +2461,6 @@
return SWITCH_STATUS_SUCCESS;
}
+
+
+
Added: freeswitch/trunk/src/mod/endpoints/mod_wanpipe/testapp.c
==============================================================================
--- (empty file)
+++ freeswitch/trunk/src/mod/endpoints/mod_wanpipe/testapp.c Mon Apr 9 15:27:59 2007
@@ -0,0 +1,448 @@
+/*****************************************************************************
+* aft_api.c AFT T1/E1: HDLC API Sample Code
+*
+* Author(s): Nenad Corbic <ncorbic(a)sangoma.com>
+*
+* Copyright: (c) 2003-2004 Sangoma Technologies Inc.
+*
+* This program is free software; you can redistribute it and/or
+* modify it under the terms of the GNU General Public License
+* as published by the Free Software Foundation; either version
+* 2 of the License, or (at your option) any later version.
+* ============================================================================
+*/
+
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <ctype.h>
+#include <unistd.h>
+#include <sys/time.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <linux/if_wanpipe.h>
+#include <string.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#include <sys/types.h>
+#include <signal.h>
+#include <linux/if.h>
+#include <linux/wanpipe_defines.h>
+#include <linux/wanpipe_cfg.h>
+#include <linux/wanpipe.h>
+#include <libsangoma.h>
+#include "lib_api.h"
+
+#define MAX_TX_DATA 5000 /* Size of tx data */
+#define MAX_FRAMES 5000 /* Number of frames to transmit */
+
+#define MAX_RX_DATA 5000
+
+unsigned short Rx_lgth;
+
+unsigned char Rx_data[MAX_RX_DATA];
+unsigned char Tx_data[MAX_TX_DATA + sizeof(wp_tdm_api_rx_hdr_t)];
+
+/* Prototypes */
+int MakeConnection(void);
+void handle_span_chan( void);
+void sig_end(int sigid);
+
+int dev_fd;
+FILE *tx_fd=NULL,*rx_fd=NULL;
+wanpipe_tdm_api_t tdm_api;
+
+
+/***************************************************
+* HANDLE SOCKET
+*
+* o Read a socket
+* o Cast data received to api_rx_element_t data type
+* o The received packet contains 16 bytes header
+*
+* ------------------------------------------
+* | 16 bytes | X bytes ...
+* ------------------------------------------
+* Header Data
+*
+* o Data structures:
+* ------------------
+* typedef struct {
+* union {
+* struct {
+* unsigned char _event_type;
+* unsigned char _rbs_rx_bits;
+* unsigned int _time_stamp;
+* }wp_event;
+* struct {
+* unsigned char _rbs_rx_bits;
+* unsigned int _time_stamp;
+* }wp_rx;
+* unsigned char reserved[16];
+* }wp_rx_hdr_u;
+* #define wp_api_event_type wp_rx_hdr_u.wp_event._event_type
+* #define wp_api_event_rbs_rx_bits wp_rx_hdr_u.wp_event._rbs_rx_bits
+* #define wp_api_event_time_stamp wp_rx_hdr_u.wp_event._time_stamp
+* } wp_tdm_api_rx_hdr_t;
+*
+* typedef struct {
+* wp_tdm_api_rx_hdr_t hdr;
+* unsigned char data[1];
+* } wp_tdm_api_rx_element_t;
+*
+* typedef struct {
+* union {
+* struct {
+* unsigned char _rbs_rx_bits;
+* unsigned int _time_stamp;
+* }wp_tx;
+* unsigned char reserved[16];
+* }wp_tx_hdr_u;
+* #define wp_api_time_stamp wp_tx_hdr_u.wp_tx._time_stamp
+* } wp_tdm_api_tx_hdr_t;
+*
+* typedef struct {
+* wp_tdm_api_tx_hdr_t hdr;
+* unsigned char data[1];
+* } wp_tdm_api_tx_element_t;
+*
+* #define WPTDM_A_BIT 0x08
+* #define WPTDM_B_BIT 0x04
+* #define WPTDM_C_BIT 0x02
+* #define WPTDM_D_BIT 0x01
+*
+*/
+
+void handle_span_chan(void)
+{
+ unsigned int Rx_count,Tx_count,Tx_length;
+ wp_tdm_api_rx_element_t* api_rx_el;
+ wp_tdm_api_tx_element_t * api_tx_el;
+ fd_set ready,write,oob;
+ int err,i;
+
+#if 0
+ int rlen;
+ int stream_sync=0;
+#endif
+
+ Rx_count = 0;
+ Tx_count = 0;
+
+ if (tdm_api.wp_tdm_cmd.hdlc) {
+ Tx_length = tx_size;
+ } else {
+ Tx_length = tdm_api.wp_tdm_cmd.usr_mtu_mru;
+ }
+
+ printf("\n\nSocket Handler: Rx=%d Tx=%i TxCnt=%i TxLen=%i TxDelay=%i\n",
+ read_enable,write_enable,tx_cnt,tx_size,tx_delay);
+
+ /* Initialize the Tx Data buffer */
+ memset(&Tx_data[0],0,MAX_TX_DATA + sizeof(wp_tdm_api_rx_hdr_t));
+
+ /* Cast the Tx data packet with the tx element
+ * structure. We must insert a 16 byte
+ * driver header, which driver will remove
+ * before passing packet out the physical port */
+ api_tx_el = (wp_tdm_api_tx_element_t*)&Tx_data[0];
+
+
+ /* Create a Tx packet based on user info, or
+ * by deafult incrementing number starting from 0 */
+ for (i=0;i<Tx_length;i++){
+ if (tx_data == -1){
+ api_tx_el->data[i] = (unsigned char)i;
+ }else{
+#if 0
+ api_tx_el->data[i] = (unsigned char)tx_data+(i%4);
+#else
+ api_tx_el->data[i] = (unsigned char)tx_data;
+#endif
+ }
+ }
+
+ sangoma_tdm_enable_rxhook_events(dev_fd, &tdm_api);
+
+ /* Main Rx Tx OOB routine */
+ for(;;) {
+
+ /* Initialize all select() descriptors */
+ FD_ZERO(&ready);
+ FD_ZERO(&write);
+ FD_ZERO(&oob);
+ FD_SET(dev_fd,&oob);
+ FD_SET(dev_fd,&ready);
+
+ if (write_enable){
+ FD_SET(dev_fd,&write);
+ }
+
+ /* Select will block, until:
+ * 1: OOB event, link level change
+ * 2: Rx data available
+ * 3: Interface able to Tx */
+
+ if(select(dev_fd + 1,&ready, &write, &oob, NULL)){
+
+ fflush(stdout);
+ if (FD_ISSET(dev_fd,&oob)){
+
+ /* An OOB event is pending, usually indicating
+ * a link level change */
+
+ err=sangoma_tdm_read_event(dev_fd,&tdm_api);
+
+ if(err < 0 ) {
+ printf("Failed to receive OOB %i , %i\n", Rx_count, err);
+ err = ioctl(dev_fd,SIOC_WANPIPE_SOCK_STATE,0);
+ printf("Sock state is %s\n",
+ (err == 0) ? "CONNECTED" :
+ (err == 1) ? "DISCONNECTED" :
+ "CONNECTING");
+ break;
+ }
+
+ printf("GOT OOB EXCEPTION CMD Exiting\n");
+ }
+
+
+ if (FD_ISSET(dev_fd,&ready)){
+
+ /* An Rx packet is pending
+ * 1: Read the rx packet into the Rx_data
+ * buffer. Confirm len > 0
+ *
+ * 2: Cast Rx_data to the api_rx_element.
+ * Thus, removing a 16 byte header
+ * attached by the driver.
+ *
+ * 3. Check error_flag:
+ * CRC,Abort..etc
+ */
+
+ memset(Rx_data, 0, sizeof(Rx_data));
+
+ err = sangoma_readmsg_tdm(dev_fd,
+ Rx_data,
+ sizeof(wp_tdm_api_rx_hdr_t),
+ &Rx_data[sizeof(wp_tdm_api_rx_hdr_t)],
+ MAX_RX_DATA, 0);
+
+
+ if (!read_enable){
+ goto bitstrm_skip_read;
+ }
+
+ /* err indicates bytes received */
+ if(err <= 0) {
+ printf("\nError receiving data\n");
+ break;
+ }
+
+ api_rx_el = (wp_tdm_api_rx_element_t*)&Rx_data[0];
+
+ /* Check the packet length */
+ Rx_lgth = err;
+ if(Rx_lgth<=0) {
+ printf("\nShort frame received (%d)\n",
+ Rx_lgth);
+ return;
+ }
+
+#if 0
+ if (api_rx_el->data[0] == tx_data && api_rx_el->data[1] == (tx_data+1)){
+ if (!stream_sync){
+ printf("GOT SYNC %x\n",api_rx_el->data[0]);
+ }
+ stream_sync=1;
+ }else{
+ if (stream_sync){
+ printf("OUT OF SYNC: %x\n",api_rx_el->data[0]);
+ }
+ }
+#endif
+
+ ++Rx_count;
+
+ if (verbose){
+#if 0
+ printf("Received %i Length = %i\n",
+ Rx_count,Rx_lgth);
+
+ printf("Data: ");
+ for(i=0;i<Rx_lgth; i ++) {
+ printf("0x%02X ", api_rx_el->data[i]);
+ }
+ printf("\n");
+#endif
+ }else{
+ //putchar('R');
+ }
+
+
+#if 0
+ switch(api_rx_el->hdr.wp_api_event_type){
+ case WP_TDM_EVENT_DTMF:
+ printf("DTMV Event: %c (%s:%s)!\n",
+ api_rx_el->hdr.wp_api_event_dtmf_digit,
+ (api_rx_el->hdr.wp_api_event_dtmf_type&WP_TDM_EVENT_DTMF_ROUT)?"ROUT":"SOUT",
+ (api_rx_el->hdr.wp_api_event_dtmf_type&WP_TDM_EVENT_DTMF_PRESET)?"PRESET":"STOP");
+ break;
+ case WP_TDM_EVENT_RXHOOK:
+ printf("RXHOOK Event: %s!\n",
+ (api_rx_el->hdr.wp_api_event_rxhook_state&WP_TDM_EVENT_RXHOOK_OFF)?"OFF-HOOK":"ON-HOOK");
+ break;
+ case WP_TDM_EVENT_RING:
+ printf("RING Event: %s!\n",
+ (api_rx_el->hdr.wp_api_event_ring_state&WP_TDM_EVENT_RING_PRESENT)?"PRESENT":"STOP");
+ break;
+ }
+#endif
+
+ if (rx_cnt > 0 && Rx_count >= rx_cnt){
+ break;
+ }
+bitstrm_skip_read:
+;
+ }
+
+ if (FD_ISSET(dev_fd,&write)){
+
+
+ err = sangoma_writemsg_tdm(dev_fd,
+ Tx_data,16,
+ &Tx_data[16], Tx_length,
+ 0);
+ if (err <= 0){
+ if (errno == EBUSY){
+ if (verbose){
+ printf("Sock busy try again!\n");
+ }
+ /* Socket busy try sending again !*/
+ }else{
+ printf("Faild to send %i \n",errno);
+ perror("Send: ");
+ break;
+ }
+ }else{
+
+ ++Tx_count;
+
+ if (verbose){
+ //printf("Packet sent: Sent %i : %i\n",
+ // err,Tx_count);
+ }else{
+ //putchar('T');
+ }
+ }
+ }
+
+ if (tx_delay){
+ usleep(tx_delay);
+ }
+
+ if (tx_cnt && tx_size && Tx_count >= tx_cnt && !(files_used & TX_FILE_USED)){
+
+ write_enable=0;
+ if (rx_cnt > 0){
+ /* Dont break let rx finish */
+ }else{
+ break;
+ }
+ }
+ }
+ }
+
+ sangoma_tdm_disable_rxhook_events(dev_fd, &tdm_api);
+ if (tx_fd){
+ fclose(tx_fd);
+ }
+ if (rx_fd){
+ fclose(rx_fd);
+ }
+ close (dev_fd);
+ return;
+
+}
+
+int rxhook_event (int fd, unsigned char state)
+{
+ printf("%d: RXHOOK Event: %s!\n",
+ fd, (state & WAN_EVENT_RXHOOK_OFF)?"OFF-HOOK":"ON-HOOK");
+ return 0;
+}
+
+/***************************************************************
+ * Main:
+ *
+ * o Make a socket connection to the driver.
+ * o Call handle_span_chan() to read the socket
+ *
+ **************************************************************/
+
+
+int main(int argc, char* argv[])
+{
+ int proceed;
+
+ proceed=init_args(argc,argv);
+ if (proceed != WAN_TRUE){
+ usage(argv[0]);
+ return -1;
+ }
+
+ signal(SIGINT,&sig_end);
+ memset(&tdm_api,0,sizeof(tdm_api));
+ tdm_api.wp_tdm_event.wp_rxhook_event = &rxhook_event;
+
+ printf("TDM RXHOOK PTR = %p\n",tdm_api.wp_tdm_event.wp_rxhook_event);
+
+ dev_fd =-1;
+
+ dev_fd = sangoma_open_tdmapi_span_chan(atoi(card_name),atoi(if_name));
+ if( dev_fd < 0){
+ printf("Failed to open span chan (%s:%s:%d:%d)\n",
+ card_name, if_name,
+ atoi(card_name),atoi(if_name));
+ exit (1);
+ }
+ printf("HANDLING SPAN %i CHAN %i FD=%i\n",
+ atoi(card_name),atoi(if_name),dev_fd);
+
+ sangoma_tdm_set_codec(dev_fd,&tdm_api,WP_NONE);
+ sangoma_get_full_cfg(dev_fd, &tdm_api);
+
+ handle_span_chan();
+ close(dev_fd);
+ return 0;
+
+ return 0;
+};
+
+
+void sig_end(int sigid)
+{
+
+ printf("Got Signal %i\n",sigid);
+
+ sangoma_tdm_disable_rxhook_events(dev_fd, &tdm_api);
+
+ if (tx_fd){
+ fclose(tx_fd);
+ }
+ if (rx_fd){
+ fclose(rx_fd);
+ }
+
+ if (dev_fd){
+ close (dev_fd);
+ }
+
+
+ exit(1);
+}
+
+
+
1
0
Author: anthm
Date: Mon Apr 9 14:42:40 2007
New Revision: 4901
Modified:
freeswitch/trunk/src/include/switch_ivr.h
freeswitch/trunk/src/include/switch_utils.h
Log:
dox
Modified: freeswitch/trunk/src/include/switch_ivr.h
==============================================================================
--- freeswitch/trunk/src/include/switch_ivr.h (original)
+++ freeswitch/trunk/src/include/switch_ivr.h Mon Apr 9 14:42:40 2007
@@ -110,9 +110,7 @@
/*!
\brief Wait for DTMF digits calling a pluggable callback function when digits are collected.
\param session the session to read.
- \param dtmf_callback code to execute if any dtmf is dialed during the recording
- \param buf an object to maintain across calls
- \param buflen the size of buf
+ \param args arguements to pass for callbacks etc
\param timeout a timeout in milliseconds
\return SWITCH_STATUS_SUCCESS to keep the collection moving.
*/
@@ -210,11 +208,8 @@
\param session the session to play the file too
\param fh file handle to use (NULL for builtin one)
\param file the path to the file
- \param dtmf_callback code to execute if any dtmf is dialed during the playback
- \param buf an object to maintain across calls
- \param buflen the size of buf
+ \param args arguements to pass for callbacks etc
\return SWITCH_STATUS_SUCCESS if all is well
- \note passing a NULL dtmf_callback nad a not NULL buf indicates to copy any dtmf to buf and stop playback.
*/
SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *session, switch_file_handle_t *fh, char *file, switch_input_args_t *args);
@@ -224,12 +219,9 @@
\param session the session to record from
\param fh file handle to use
\param file the path to the file
- \param dtmf_callback code to execute if any dtmf is dialed during the recording
- \param buf an object to maintain across calls
- \param buflen the size of buf
+ \param args arguements to pass for callbacks etc
\param limit max limit to record for (0 for infinite)
\return SWITCH_STATUS_SUCCESS if all is well
- \note passing a NULL dtmf_callback nad a not NULL buf indicates to copy any dtmf to buf and stop recording.
*/
SWITCH_DECLARE(switch_status_t) switch_ivr_record_file(switch_core_session_t *session,
switch_file_handle_t *fh, char *file, switch_input_args_t *args, uint32_t limit);
@@ -271,10 +263,8 @@
\param tts_name the desired tts module
\param voice_name the desired voice
\param rate the sample rate
- \param dtmf_callback code to execute if any dtmf is dialed during the audio
\param text the text to speak
- \param buf an option data pointer to pass to the callback or a string to put encountered digits in
- \param buflen the len of buf
+ \param args arguements to pass for callbacks etc
\return SWITCH_STATUS_SUCCESS if all is well
*/
SWITCH_DECLARE(switch_status_t) switch_ivr_speak_text(switch_core_session_t *session,
@@ -305,7 +295,7 @@
\brief Bridge Audio from one session to another
\param session one session
\param peer_session the other session
- \param dtmf_callback code to execute if any dtmf is dialed during the bridge
+ \param dtmf_callback a callback for messages and dtmf
\param session_data data to pass to the DTMF callback for session
\param peer_session_data data to pass to the DTMF callback for peer_session
\return SWITCH_STATUS_SUCCESS if all is well
@@ -491,6 +481,7 @@
/*!
\brief Feed digits collected into the stream for event match testing
\param parser a pointer to the parser object created by switch_ivr_digit_stream_parser_new
+ \param stream a stream to write data to
\param digit a digit to collect and test against the map of digit strings
\return NULL if no match found or consumer data that was associated with a given digit string when matched
*/
@@ -556,14 +547,15 @@
*\param name A pointer to the name of this menu.
*\param greeting_sound Optional pointer to a main sound (press 1 for this 2 for that).
*\param short_greeting_sound Optional pointer to a shorter main sound for subsequent loops.
- *\param exit_sound Optional pointer to a sound to play upon exiting the menu
+ *\param exit_sound Optional pointer to a sound to play upon exiting the menu.
*\param invalid_sound Optional pointer to a sound to play after invalid input.
- *\param tts_engine Text To Speech engine name
- *\param tts_voice Text To Speech engine voice name
+ *\param tts_engine Text To Speech engine name.
+ *\param tts_voice Text To Speech engine voice name.
+ *\param phrase_lang the language to use for the phrase macros.
*\param timeout A number of milliseconds to pause before looping.
*\param max_failures Maximum number of failures to withstand before hangingup This resets everytime you enter the menu.
- *\param pool memory pool (NULL to create one)
- *\return SWITCH_STATUS_SUCCESS if the menu was created
+ *\param pool memory pool (NULL to create one).
+ *\return SWITCH_STATUS_SUCCESS if the menu was created.
*/
SWITCH_DECLARE(switch_status_t) switch_ivr_menu_init(switch_ivr_menu_t ** new_menu,
switch_ivr_menu_t * main,
Modified: freeswitch/trunk/src/include/switch_utils.h
==============================================================================
--- freeswitch/trunk/src/include/switch_utils.h (original)
+++ freeswitch/trunk/src/include/switch_utils.h Mon Apr 9 14:42:40 2007
@@ -90,7 +90,7 @@
\brief find the char representation of an ip adress
\param buf the buffer to write the ip adress found into
\param len the length of the buf
- \param the struct in_addr * to get the adress from
+ \param in the struct in_addr * to get the adress from
\return the ip adress string
*/
SWITCH_DECLARE(char *) get_addr(char *buf, switch_size_t len, struct in_addr *in);
1
0
[commit] r4900 - in freeswitch/trunk: scripts/socket/FreeSWITCH src src/include
by Freeswitch SVN 09 Apr '07
by Freeswitch SVN 09 Apr '07
09 Apr '07
Author: anthm
Date: Mon Apr 9 14:38:47 2007
New Revision: 4900
Modified:
freeswitch/trunk/scripts/socket/FreeSWITCH/Client.pm
freeswitch/trunk/src/include/switch_ivr.h
freeswitch/trunk/src/include/switch_types.h
freeswitch/trunk/src/switch_core_session.c
freeswitch/trunk/src/switch_ivr.c
Log:
unicast framework
Modified: freeswitch/trunk/scripts/socket/FreeSWITCH/Client.pm
==============================================================================
--- freeswitch/trunk/scripts/socket/FreeSWITCH/Client.pm (original)
+++ freeswitch/trunk/scripts/socket/FreeSWITCH/Client.pm Mon Apr 9 14:38:47 2007
@@ -208,6 +208,22 @@
return $self->sendmsg($hash);
}
+sub unicast($$$$$$) {
+ my $self = shift;
+
+ my $hash = {
+ 'command' => "sendmsg",
+ 'call-command' => "unicast",
+ 'local_ip' => $_[0],
+ 'local_port' => $_[1],
+ 'remote_ip' => $_[2],
+ 'remote_port' => $_[3],
+ 'transport' => $_[4]
+ };
+
+ return $self->sendmsg($hash);
+}
+
sub call_data($) {
my $self = shift;
Modified: freeswitch/trunk/src/include/switch_ivr.h
==============================================================================
--- freeswitch/trunk/src/include/switch_ivr.h (original)
+++ freeswitch/trunk/src/include/switch_ivr.h Mon Apr 9 14:38:47 2007
@@ -42,6 +42,28 @@
#include <switch.h>
SWITCH_BEGIN_EXTERN_C
+
+struct switch_unicast_conninfo {
+ switch_core_session_t *session;
+ switch_codec_t read_codec;
+ switch_frame_t write_frame;
+ switch_byte_t write_frame_data[SWITCH_RECOMMENDED_BUFFER_SIZE];
+ switch_socket_t *socket;
+ char *local_ip;
+ uint32_t local_port;
+ char *remote_ip;
+ uint32_t remote_port;
+ switch_sockaddr_t *local_addr;
+ switch_sockaddr_t *remote_addr;
+ switch_mutex_t *flag_mutex;
+ int32_t flags;
+ int type;
+ int transport;
+ int stream_id;
+};
+typedef struct switch_unicast_conninfo switch_unicast_conninfo_t;
+
+
/**
* @defgroup switch_ivr IVR Library
* @ingroup core1
@@ -49,6 +71,15 @@
* building blocks for a higher level IVR interface.
* @{
*/
+
+SWITCH_DECLARE(switch_status_t) switch_ivr_deactivate_unicast(switch_core_session_t *session);
+SWITCH_DECLARE(switch_status_t) switch_ivr_activate_unicast(switch_core_session_t *session,
+ char *local_ip,
+ uint32_t local_port,
+ char *remote_ip,
+ uint32_t remote_port,
+ char *transport);
+
/*!
\brief Generate an XML CDR report.
\param session the session to get the data from.
Modified: freeswitch/trunk/src/include/switch_types.h
==============================================================================
--- freeswitch/trunk/src/include/switch_types.h (original)
+++ freeswitch/trunk/src/include/switch_types.h Mon Apr 9 14:38:47 2007
@@ -117,6 +117,13 @@
#define SWITCH_BITS_PER_BYTE 8
typedef uint8_t switch_byte_t;
+
+typedef enum {
+ SUF_NONE = 0,
+ SUF_THREAD_RUNNING = (1 << 0),
+ SUF_READY = (1 << 1)
+} switch_unicast_flag_t;
+
typedef enum {
SWITCH_FALSE = 0,
SWITCH_TRUE = 1
@@ -531,6 +538,7 @@
CF_RING_READY = (1 << 18) - Channel is ready to send ringback
CF_BREAK = (1 << 19) - Channel should stop what it's doing
CF_BROADCAST = (1 << 20) - Channel is broadcasting
+CF_UNICAST = (1 << 21) - Channel has a unicast connection
</pre>
*/
@@ -555,7 +563,8 @@
CF_GEN_RINGBACK = (1 << 17),
CF_RING_READY = (1 << 18),
CF_BREAK = (1 << 19),
- CF_BROADCAST = (1 << 20)
+ CF_BROADCAST = (1 << 20),
+ CF_UNICAST = (1 << 21)
} switch_channel_flag_t;
Modified: freeswitch/trunk/src/switch_core_session.c
==============================================================================
--- freeswitch/trunk/src/switch_core_session.c (original)
+++ freeswitch/trunk/src/switch_core_session.c Mon Apr 9 14:38:47 2007
@@ -599,6 +599,8 @@
switch_channel_dequeue_dtmf(channel, buf, sizeof(buf));
}
+ switch_ivr_deactivate_unicast(session);
+
switch_channel_clear_flag(channel, CF_BREAK);
}
@@ -647,6 +649,8 @@
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Close Channel %s\n", switch_channel_get_name((*session)->channel));
+ switch_ivr_deactivate_unicast(*session);
+
switch_scheduler_del_task_group((*session)->uuid_str);
switch_mutex_lock(runtime.session_table_mutex);
Modified: freeswitch/trunk/src/switch_ivr.c
==============================================================================
--- freeswitch/trunk/src/switch_ivr.c (original)
+++ freeswitch/trunk/src/switch_ivr.c Mon Apr 9 14:38:47 2007
@@ -80,6 +80,176 @@
}
+static void *SWITCH_THREAD_FUNC unicast_thread_run(switch_thread_t *thread, void *obj)
+{
+ switch_unicast_conninfo_t *conninfo = (switch_unicast_conninfo_t *) obj;
+ switch_size_t len;
+ switch_channel_t *channel;
+
+ if (!conninfo) {
+ return NULL;
+ }
+
+ channel = switch_core_session_get_channel(conninfo->session);
+
+ while(switch_test_flag(conninfo, SUF_READY) && switch_test_flag(conninfo, SUF_THREAD_RUNNING)) {
+ len = conninfo->write_frame.buflen;
+ if (switch_socket_recv(conninfo->socket, conninfo->write_frame.data, &len) != SWITCH_STATUS_SUCCESS || len == 0) {
+ break;
+ }
+ conninfo->write_frame.datalen = len;
+ conninfo->write_frame.samples = conninfo->write_frame.datalen / 2;
+ switch_core_session_write_frame(conninfo->session, &conninfo->write_frame, -1, conninfo->stream_id);
+ }
+
+ switch_clear_flag_locked(conninfo, SUF_READY);
+ switch_clear_flag_locked(conninfo, SUF_THREAD_RUNNING);
+
+ return NULL;
+}
+
+static void unicast_thread_launch(switch_unicast_conninfo_t *conninfo)
+{
+ switch_thread_t *thread;
+ switch_threadattr_t *thd_attr = NULL;
+
+ switch_threadattr_create(&thd_attr, switch_core_session_get_pool(conninfo->session));
+ switch_threadattr_detach_set(thd_attr, 1);
+ switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
+ switch_set_flag_locked(conninfo, SUF_THREAD_RUNNING);
+ switch_thread_create(&thread, thd_attr, unicast_thread_run, conninfo, switch_core_session_get_pool(conninfo->session));
+}
+
+SWITCH_DECLARE(switch_status_t) switch_ivr_deactivate_unicast(switch_core_session_t *session)
+{
+ switch_channel_t *channel;
+ switch_unicast_conninfo_t *conninfo;
+ int sanity = 0;
+
+ channel = switch_core_session_get_channel(session);
+ assert(channel != NULL);
+
+ if (switch_channel_test_flag(channel, CF_UNICAST)) {
+ if ((conninfo = switch_channel_get_private(channel, "unicast"))) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Shutting down unicast connection\n");
+ switch_clear_flag_locked(conninfo, SUF_READY);
+ switch_socket_shutdown(conninfo->socket, SWITCH_SHUTDOWN_READWRITE);
+ while(switch_test_flag(conninfo, SUF_THREAD_RUNNING)) {
+ switch_yield(10000);
+ if (++sanity >= 10000) {
+ break;
+ }
+ }
+ switch_core_codec_destroy(&conninfo->read_codec);
+ switch_socket_close(conninfo->socket);
+ }
+ switch_channel_clear_flag(channel, CF_UNICAST);
+ return SWITCH_STATUS_SUCCESS;
+ }
+
+ return SWITCH_STATUS_FALSE;
+
+}
+
+SWITCH_DECLARE(switch_status_t) switch_ivr_activate_unicast(switch_core_session_t *session,
+ char *local_ip,
+ uint32_t local_port,
+ char *remote_ip,
+ uint32_t remote_port,
+ char *transport)
+{
+ switch_channel_t *channel;
+ switch_unicast_conninfo_t *conninfo;
+ switch_codec_t *read_codec;
+
+ channel = switch_core_session_get_channel(session);
+ assert(channel != NULL);
+
+ conninfo = switch_core_session_alloc(session, sizeof(*conninfo));
+ assert(conninfo != NULL);
+
+ conninfo->local_ip = switch_core_session_strdup(session, local_ip);
+ conninfo->local_port = local_port;
+
+ conninfo->remote_ip = switch_core_session_strdup(session, remote_ip);
+ conninfo->remote_port = remote_port;
+ conninfo->session = session;
+
+ if (!strcasecmp(transport, "udp")) {
+ conninfo->type = AF_INET;
+ conninfo->transport = SOCK_DGRAM;
+ } else if (!strcasecmp(transport, "tcp")) {
+ conninfo->type = AF_INET;
+ conninfo->transport = SOCK_STREAM;
+ } else {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid transport %s\n", transport);
+ goto fail;
+ }
+
+ switch_mutex_init(&conninfo->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
+
+ read_codec = switch_core_session_get_read_codec(session);
+
+ if (switch_core_codec_init(&conninfo->read_codec,
+ "L16",
+ NULL,
+ read_codec->implementation->samples_per_second,
+ read_codec->implementation->microseconds_per_frame / 1000,
+ 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
+ NULL, switch_core_session_get_pool(session)) == SWITCH_STATUS_SUCCESS) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
+ "Raw Codec Activation Success L16@%uhz 1 channel %dms\n",
+ read_codec->implementation->samples_per_second, read_codec->implementation->microseconds_per_frame / 1000);
+ } else {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Raw Codec Activation Failed L16@%uhz 1 channel %dms\n",
+ read_codec->implementation->samples_per_second, read_codec->implementation->microseconds_per_frame / 1000);
+ goto fail;
+ }
+
+ conninfo->write_frame.data = conninfo->write_frame_data;
+ conninfo->write_frame.buflen = sizeof(conninfo->write_frame_data);
+ conninfo->write_frame.codec = &conninfo->read_codec;
+
+
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "connect %s:%d->%s:%d\n",
+ conninfo->local_ip, conninfo->local_port, conninfo->remote_ip, conninfo->remote_port);
+
+ if (switch_sockaddr_info_get(&conninfo->local_addr,
+ conninfo->local_ip, SWITCH_UNSPEC, conninfo->local_port, 0,
+ switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
+ goto fail;
+ }
+
+ if (switch_sockaddr_info_get(&conninfo->remote_addr,
+ conninfo->remote_ip, SWITCH_UNSPEC, conninfo->remote_port, 0,
+ switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
+ goto fail;
+ }
+
+ if (switch_socket_create(&conninfo->socket, AF_INET, SOCK_DGRAM, 0, switch_core_session_get_pool(session)) == SWITCH_STATUS_SUCCESS) {
+ if (switch_socket_bind(conninfo->socket, conninfo->local_addr) != SWITCH_STATUS_SUCCESS) {
+ goto fail;
+ }
+ } else {
+ goto fail;
+ }
+
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Created unicast connection %s:%d->%s:%d\n",
+ conninfo->local_ip, conninfo->local_port, conninfo->remote_ip, conninfo->remote_port);
+ switch_channel_set_private(channel, "unicast", conninfo);
+ switch_channel_set_flag(channel, CF_UNICAST);
+ switch_set_flag_locked(conninfo, SUF_READY);
+ return SWITCH_STATUS_SUCCESS;
+
+ fail:
+
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Failure creating unicast connection %s:%d->%s:%d\n",
+ conninfo->local_ip, conninfo->local_port, conninfo->remote_ip, conninfo->remote_port);
+ return SWITCH_STATUS_FALSE;
+
+
+}
+
SWITCH_DECLARE(switch_status_t) switch_ivr_parse_event(switch_core_session_t *session, switch_event_t *event)
{
switch_channel_t *channel = switch_core_session_get_channel(session);
@@ -89,6 +259,7 @@
unsigned long CMD_EXECUTE = switch_hashfunc_default("execute", &hlen);
unsigned long CMD_HANGUP = switch_hashfunc_default("hangup", &hlen);
unsigned long CMD_NOMEDIA = switch_hashfunc_default("nomedia", &hlen);
+ unsigned long CMD_UNICAST = switch_hashfunc_default("unicast", &hlen);
assert(channel != NULL);
assert(event != NULL);
@@ -109,7 +280,7 @@
char *app_name = switch_event_get_header(event, "execute-app-name");
char *app_arg = switch_event_get_header(event, "execute-app-arg");
char *loop_h = switch_event_get_header(event, "loops");
- int loops = 0;
+ int loops = 1;
if (loop_h) {
loops = atoi(loop_h);
@@ -130,6 +301,31 @@
}
}
}
+ } else if (cmd_hash == CMD_UNICAST) {
+ char *local_ip = switch_event_get_header(event, "local_ip");
+ char *local_port = switch_event_get_header(event, "local_port");
+ char *remote_ip = switch_event_get_header(event, "remote_ip");
+ char *remote_port = switch_event_get_header(event, "remote_port");
+ char *transport = switch_event_get_header(event, "transport");
+
+ if (switch_strlen_zero(local_ip)) {
+ local_ip = "127.0.0.1";
+ }
+ if (switch_strlen_zero(remote_ip)) {
+ remote_ip = "127.0.0.1";
+ }
+ if (switch_strlen_zero(local_port)) {
+ local_port = "8025";
+ }
+ if (switch_strlen_zero(remote_port)) {
+ remote_port = "8026";
+ }
+ if (switch_strlen_zero(transport)) {
+ transport = "udp";
+ }
+
+ switch_ivr_activate_unicast(session, local_ip, atoi(local_port), remote_ip, atoi(remote_port), transport);
+
} else if (cmd_hash == CMD_HANGUP) {
char *cause_name = switch_event_get_header(event, "hangup-cause");
switch_call_cause_t cause = SWITCH_CAUSE_NORMAL_CLEARING;
@@ -154,10 +350,11 @@
{
switch_status_t status = SWITCH_STATUS_SUCCESS;
switch_channel_t *channel;
- switch_frame_t *frame;
+ switch_frame_t *read_frame;
int stream_id = 0;
switch_event_t *event;
-
+ switch_unicast_conninfo_t *conninfo = NULL;
+ switch_codec_t *read_codec = switch_core_session_get_read_codec(session);
channel = switch_core_session_get_channel(session);
assert(channel != NULL);
@@ -171,10 +368,73 @@
switch_channel_set_flag(channel, CF_CONTROLLED);
while (switch_channel_ready(channel) && switch_channel_test_flag(channel, CF_CONTROLLED)) {
- if ((status = switch_core_session_read_frame(session, &frame, -1, stream_id)) == SWITCH_STATUS_SUCCESS) {
+ if ((status = switch_core_session_read_frame(session, &read_frame, -1, stream_id)) == SWITCH_STATUS_SUCCESS) {
if (!SWITCH_READ_ACCEPTABLE(status)) {
break;
}
+
+ if (switch_channel_test_flag(channel, CF_UNICAST)) {
+ if (!conninfo) {
+ if (!(conninfo = switch_channel_get_private(channel, "unicast"))) {
+ switch_channel_clear_flag(channel, CF_UNICAST);
+ }
+
+ if (conninfo) {
+ unicast_thread_launch(conninfo);
+ }
+ }
+
+ if (conninfo) {
+ switch_size_t len;
+ uint32_t flags = 0;
+ switch_byte_t decoded[SWITCH_RECOMMENDED_BUFFER_SIZE];
+ uint32_t rate = read_codec->implementation->samples_per_second;
+ uint32_t dlen = sizeof(decoded);
+ switch_status_t status;
+ switch_byte_t *sendbuf = NULL;
+ uint32_t sendlen = 0;
+
+ if (switch_test_flag(read_frame, SFF_CNG)) {
+ sendlen = read_codec->implementation->bytes_per_frame;
+ memset(decoded, 255, sendlen);
+ sendbuf = decoded;
+ status = SWITCH_STATUS_SUCCESS;
+ } else {
+
+ status = switch_core_codec_decode(
+ read_codec,
+ &conninfo->read_codec,
+ read_frame->data,
+ read_frame->datalen,
+ read_codec->implementation->samples_per_second,
+ decoded, &dlen, &rate, &flags);
+ switch (status) {
+ case SWITCH_STATUS_NOOP:
+ case SWITCH_STATUS_BREAK:
+ sendbuf = read_frame->data;
+ sendlen = read_frame->datalen;
+ status = SWITCH_STATUS_SUCCESS;
+ break;
+ case SWITCH_STATUS_SUCCESS:
+ sendbuf = decoded;
+ sendlen = dlen;
+ status = SWITCH_STATUS_SUCCESS;
+ break;
+ default:
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Codec Error\n");
+ switch_ivr_deactivate_unicast(session);
+ break;
+ }
+ }
+
+ if (status == SWITCH_STATUS_SUCCESS) {
+ len = sendlen;
+ if (switch_socket_sendto(conninfo->socket, conninfo->remote_addr, 0, (void *)sendbuf, &len) != SWITCH_STATUS_SUCCESS) {
+ switch_ivr_deactivate_unicast(session);
+ }
+ }
+ }
+ }
if (switch_core_session_dequeue_private_event(session, &event) == SWITCH_STATUS_SUCCESS) {
switch_ivr_parse_event(session, event);
@@ -212,6 +472,10 @@
switch_event_fire(&event);
}
+ if (switch_channel_test_flag(channel, CF_UNICAST)) {
+ switch_ivr_deactivate_unicast(session);
+ }
+
return status;
}
1
0
[commit] r4899 - in freeswitch/branches/mikej/sofiasip-upgrade: . conf libs/apr/include/arch/unix libs/libdingaling/src src src/include src/mod src/mod/applications/mod_commands src/mod/endpoints/mod_dingaling src/mod/endpoints/mod_sofia
by Freeswitch SVN 09 Apr '07
by Freeswitch SVN 09 Apr '07
09 Apr '07
Author: mikej
Date: Mon Apr 9 12:32:10 2007
New Revision: 4899
Modified:
freeswitch/branches/mikej/sofiasip-upgrade/Makefile.am
freeswitch/branches/mikej/sofiasip-upgrade/bootstrap.sh
freeswitch/branches/mikej/sofiasip-upgrade/conf/dingaling.conf.xml
freeswitch/branches/mikej/sofiasip-upgrade/conf/freeswitch_combined.xml
freeswitch/branches/mikej/sofiasip-upgrade/conf/sofia.conf.xml
freeswitch/branches/mikej/sofiasip-upgrade/conf/switch.conf.xml
freeswitch/branches/mikej/sofiasip-upgrade/configure.in
freeswitch/branches/mikej/sofiasip-upgrade/libs/apr/include/arch/unix/apr_private.h.in
freeswitch/branches/mikej/sofiasip-upgrade/libs/libdingaling/src/libdingaling.c
freeswitch/branches/mikej/sofiasip-upgrade/libs/libdingaling/src/libdingaling.h
freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch.h
freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_rtp.h
freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_xml.h
freeswitch/branches/mikej/sofiasip-upgrade/src/mod/Makefile.am
freeswitch/branches/mikej/sofiasip-upgrade/src/mod/applications/mod_commands/mod_commands.c
freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_dingaling/Makefile
freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_dingaling/mod_dingaling.c
freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_sofia/mod_sofia.h
freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_sofia/sofia.c
freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_sofia/sofia_reg.c
freeswitch/branches/mikej/sofiasip-upgrade/src/switch_core.c
freeswitch/branches/mikej/sofiasip-upgrade/src/switch_rtp.c
freeswitch/branches/mikej/sofiasip-upgrade/src/switch_xml.c
Log:
merged changes from trunk revisions 4873-4898.
Modified: freeswitch/branches/mikej/sofiasip-upgrade/Makefile.am
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/Makefile.am (original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/Makefile.am Mon Apr 9 12:32:10 2007
@@ -14,6 +14,9 @@
AM_CFLAGS += -DCRASH_PROT
endif
+.DEFAULT:
+ @cd src/mod && $(MAKE) $(AM_MAKEFLAGS) $@
+
libfreeswitch_la_SOURCES = \
src/switch_apr.c \
src/switch_buffer.c \
@@ -90,8 +93,6 @@
libs/libteletone/src/libteletone_generate.h\
libs/libteletone/src/libteletone.h
-
-
CORE_CFLAGS = `$(switch_srcdir)/libs/apr/apr-1-config --cflags --cppflags --includes`
CORE_CFLAGS += `$(switch_srcdir)/libs/apr-util/apu-1-config --includes`
CORE_CFLAGS += -I$(switch_srcdir)/libs/sqlite
@@ -118,7 +119,7 @@
MOD_LINK = $(BASE)/libfreeswitch.la
CLEANFILES = src/include/switch_version.h
-BUILT_SOURCES = src/include/switch_version.h ./$(DEPDIR)/modules.targets
+BUILT_SOURCES = src/include/switch_version.h
bin_PROGRAMS = freeswitch
freeswitch_SOURCES = src/switch.c
@@ -244,15 +245,10 @@
megaclean: eclean modclean
rm -f `find ./libs -name \*.la`
-@am__include@ @am__quote@./$(DEPDIR)/modules.targets@am__quote@
-
modules.conf:
if test -f $@; then touch $@; else cp build/modules.conf.in $@ ;fi
-./$(DEPDIR)/modules.targets: modules.conf
- mods=`cat modules.conf | sed -e 's|^.*/||'`; echo MODULE_TARGETS=\"$$mods\" > ./$(DEPDIR)/modules.targets
-
-$(MODULE_TARGETS):
+$(OUR_MODULES):
@set fnord $$MAKEFLAGS; amf=$$2; \
(cd src/mod && $(MAKE) $(AM_MAKEFLAGS) $@) \
|| case "$$amf" in *=*) exit 1;; *k*) fail=yes;; *) exit 1;; esac; \
Modified: freeswitch/branches/mikej/sofiasip-upgrade/bootstrap.sh
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/bootstrap.sh (original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/bootstrap.sh Mon Apr 9 12:32:10 2007
@@ -15,7 +15,7 @@
touch ChangeLog
# autoconf 2.59 or newer
-ac_version=`${AUTOCONF:-autoconf} --version 2>/dev/null|sed -e 's/^[^0-9]*//;s/[a-z]* *$//;q'`
+ac_version=`${AUTOCONF:-autoconf} --version 2>/dev/null|sed -e 's/^[^0-9]*//;s/[a-z]* *$//;s/[- ].*//g;q'`
if test -z "$ac_version"; then
echo "bootstrap: autoconf not found."
echo " You need autoconf version 2.59 or newer installed"
@@ -33,7 +33,7 @@
fi
# automake 1.7 or newer
-am_version=`${AUTOMAKE:-automake} --version 2>/dev/null|sed -e 's/^[^0-9]*//;s/[a-z]* *$//;q'`
+am_version=`${AUTOMAKE:-automake} --version 2>/dev/null|sed -e 's/^[^0-9]*//;s/[a-z]* *$//;s/[- ].*//g;q'`
if test -z "$am_version"; then
echo "bootstrap: automake not found."
echo " You need automake version 1.7 or newer installed"
@@ -70,7 +70,7 @@
if test -z "$1"; then a=0 ; else a=$1;fi
if test -z "$2"; then b=0 ; else b=$2;fi
-if test -z "$3"; then c=0 ; else c=$3;fi
+if test -z "$3"; then c=0 ; else c=$3;fi
if test "$a" -lt "2"; then
if test "$b" -lt "5" -o "$b" = "5" -a "$c" -lt "14" ; then
Modified: freeswitch/branches/mikej/sofiasip-upgrade/conf/dingaling.conf.xml
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/conf/dingaling.conf.xml (original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/conf/dingaling.conf.xml Mon Apr 9 12:32:10 2007
@@ -15,7 +15,6 @@
<param name="message" value="Jingle all the way"/>
<param name="rtp-ip" value="auto"/>
<param name="auto-login" value="true"/>
- <param name="auto-reply" value="Press *Call* to call FreeSWITCH and be sure to come to ClueCon! http://www.cluecon.com"/>
<!-- SASL "plain" or "md5" -->
<param name="sasl" value="plain"/>
<!-- if the server where the jabber is hosted is not the same as the one in the jid -->
Modified: freeswitch/branches/mikej/sofiasip-upgrade/conf/freeswitch_combined.xml
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/conf/freeswitch_combined.xml (original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/conf/freeswitch_combined.xml Mon Apr 9 12:32:10 2007
@@ -7,6 +7,9 @@
<settings>
<!--Most channels to allow at once -->
<param name="max-sessions" value="1000"/>
+ <!--RTP port range -->
+ <!--<param name="rtp-start-port" value="16384"/>-->
+ <!--<param name="rtp-end-port" value="32768"/>-->
</settings>
<!--Any variables defined here will be available in every channel, in the dialplan etc -->
<variables>
Modified: freeswitch/branches/mikej/sofiasip-upgrade/conf/sofia.conf.xml
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/conf/sofia.conf.xml (original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/conf/sofia.conf.xml Mon Apr 9 12:32:10 2007
@@ -16,6 +16,8 @@
<!--<param name="proxy" value="asterlink.com"/>-->
<!--/// expire in seconds: *optional* 3600, if blank ///-->
<!--<param name="expire-seconds" value="60"/>-->
+ <!--/// do not register ///-->
+ <!--<param name="register" value="false"/>-->
<!--</gateway>-->
</gateways>
<settings>
Modified: freeswitch/branches/mikej/sofiasip-upgrade/conf/switch.conf.xml
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/conf/switch.conf.xml (original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/conf/switch.conf.xml Mon Apr 9 12:32:10 2007
@@ -2,6 +2,9 @@
<settings>
<!--Most channels to allow at once -->
<param name="max-sessions" value="1000"/>
+ <!--RTP port range -->
+ <!--<param name="rtp-start-port" value="16384"/>-->
+ <!--<param name="rtp-end-port" value="32768"/>-->
</settings>
<!--Any variables defined here will be available in every channel, in the dialplan etc -->
<variables>
Modified: freeswitch/branches/mikej/sofiasip-upgrade/configure.in
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/configure.in (original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/configure.in Mon Apr 9 12:32:10 2007
@@ -340,9 +340,20 @@
#LIBS+=> core.log || error="yes";if test -n "$(VERBOSE)" -o "$$error" = "yes";then cat core.log;fi;if test "$$error" = "yes";then exit 1;fi
LIBTOOL='`if test -z "$(VERBOSE)" ; then echo $(SHELL) $(switch_builddir)/quiet_libtool ;else echo $(switch_builddir)/libtool; fi;`'
TOUCH_TARGET='if test -f "$@";then touch "$@";fi;'
-AM_MAKEFLAGS='`test -n "$(VERBOSE)" || echo -s`'
+CONF_MODULES='\`grep -v "\#" $(switch_builddir)/modules.conf | sed -e "s|^.*/||" \`'
+OUR_MODS='`if test -z "$(MODULES)" ; then tmp_mods="$(CONF_MODULES)"; else tmp_mods="$(MODULES)" ; fi ; mods=\`for i in $$tmp_mods ; do echo $$i-all ; done \`; echo $$mods `'
+OUR_CLEAN_MODS='`if test -z "$(MODULES)" ; then tmp_mods="$(CONF_MODULES)"; else tmp_mods="$(MODULES)" ; fi ; mods=\`for i in $$tmp_mods ; do echo $$i-clean ; done \`; echo $$mods `'
+OUR_INSTALL_MODS='`if test -z "$(MODULES)" ; then tmp_mods="$(CONF_MODULES)"; else tmp_mods="$(MODULES)" ; fi ; mods=\`for i in $$tmp_mods ; do echo $$i-install ; done\`; echo $$mods `'
+OUR_UNINSTALL_MODS='`if test -z "$(MODULES)" ; then tmp_mods="$(CONF_MODULES)"; else tmp_mods="$(MODULES)" ; fi ; mods=\`for i in $$tmp_mods ; do echo $$i-uninstall ; done\`; echo $$mods `'
+AM_MAKEFLAGS='"OUR_MODULES=$(OUR_MODS)" "OUR_CLEAN_MODULES=$(OUR_CLEAN_MODS)" "OUR_INSTALL_MODULES=$(OUR_INSTALL_MODS)" "OUR_UNINSTALL_MODULES=$(OUR_UNINSTALL_MODS)" `test -n "$(VERBOSE)" || echo -s`'
+#AM_MAKEFLAGS='`test -n "$(VERBOSE)" || echo -s`'
AC_SUBST(LIBTOOL)
AC_SUBST(TOUCH_TARGET)
+AC_SUBST(CONF_MODULES)
+AC_SUBST(OUR_MODS)
+AC_SUBST(OUR_CLEAN_MODS)
+AC_SUBST(OUR_INSTALL_MODS)
+AC_SUBST(OUR_UNINSTALL_MODS)
AC_SUBST(AM_MAKEFLAGS)
# Run configure in all the subdirs
Modified: freeswitch/branches/mikej/sofiasip-upgrade/libs/apr/include/arch/unix/apr_private.h.in
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/libs/apr/include/arch/unix/apr_private.h.in (original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/libs/apr/include/arch/unix/apr_private.h.in Mon Apr 9 12:32:10 2007
@@ -632,16 +632,16 @@
/* */
#undef SIGWAIT_TAKES_ONE_ARG
-/* The size of a `char', as computed by sizeof. */
+/* The size of `char', as computed by sizeof. */
#undef SIZEOF_CHAR
-/* The size of a `int', as computed by sizeof. */
+/* The size of `int', as computed by sizeof. */
#undef SIZEOF_INT
-/* The size of a `long', as computed by sizeof. */
+/* The size of `long', as computed by sizeof. */
#undef SIZEOF_LONG
-/* The size of a `long long', as computed by sizeof. */
+/* The size of `long long', as computed by sizeof. */
#undef SIZEOF_LONG_LONG
/* The size of off_t */
@@ -650,7 +650,7 @@
/* The size of pid_t */
#undef SIZEOF_PID_T
-/* The size of a `short', as computed by sizeof. */
+/* The size of `short', as computed by sizeof. */
#undef SIZEOF_SHORT
/* The size of size_t */
@@ -659,7 +659,7 @@
/* The size of ssize_t */
#undef SIZEOF_SSIZE_T
-/* The size of a `void*', as computed by sizeof. */
+/* The size of `void*', as computed by sizeof. */
#undef SIZEOF_VOIDP
/* Define to 1 if you have the ANSI C header files. */
@@ -752,13 +752,13 @@
#undef inline
#endif
-/* Define to `long' if <sys/types.h> does not define. */
+/* Define to `long int' if <sys/types.h> does not define. */
#undef off_t
/* Define to `int' if <sys/types.h> does not define. */
#undef pid_t
-/* Define to `unsigned' if <sys/types.h> does not define. */
+/* Define to `unsigned int' if <sys/types.h> does not define. */
#undef size_t
/* Define to `int' if <sys/types.h> does not define. */
Modified: freeswitch/branches/mikej/sofiasip-upgrade/libs/libdingaling/src/libdingaling.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/libs/libdingaling/src/libdingaling.c (original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/libs/libdingaling/src/libdingaling.c Mon Apr 9 12:32:10 2007
@@ -526,97 +526,6 @@
const char *marker = "TRUE";
-static int on_disco_info(void *user_data, ikspak *pak)
-{
- ldl_handle_t *handle = user_data;
-
- if (pak->subtype == IKS_TYPE_RESULT) {
- if (iks_find_with_attrib(pak->query, "feature", "var", "http://www.google.com/xmpp/protocol/voice/v1")) {
- char *from = iks_find_attrib(pak->x, "from");
- char id[1024];
- char *resource;
- struct ldl_buffer *buffer;
- size_t x;
-
-
- apr_cpystrn(id, from, sizeof(id));
- if ((resource = strchr(id, '/'))) {
- *resource++ = '\0';
- }
-
- if (!apr_hash_get(handle->sub_hash, from, APR_HASH_KEY_STRING)) {
- iks *msg;
- apr_hash_set(handle->sub_hash, apr_pstrdup(handle->pool, from), APR_HASH_KEY_STRING, &marker);
- msg = iks_make_s10n (IKS_TYPE_SUBSCRIBED, id, "Ding A Ling....");
- apr_queue_push(handle->queue, msg);
- }
-
-
-
- if (resource) {
- for (x = 0; x < strlen(resource); x++) {
- resource[x] = (char)tolower((int)resource[x]);
- }
- }
-
- if (resource && strstr(resource, "talk") && (buffer = apr_hash_get(handle->probe_hash, id, APR_HASH_KEY_STRING))) {
- apr_cpystrn(buffer->buf, from, buffer->len);
- fflush(stderr);
- buffer->hit = 1;
- }
- }
- return IKS_FILTER_EAT;
- }
-
- if (pak->subtype == IKS_TYPE_GET) {
- iks *iq, *query, *tag;
- uint8_t send = 0;
-
- if ((iq = iks_new("iq"))) {
- do {
- iks_insert_attrib(iq, "from", handle->login);
- iks_insert_attrib(iq, "to", pak->from->full);
- iks_insert_attrib(iq, "id", pak->id);
- iks_insert_attrib(iq, "type", "result");
-
- if (!(query = iks_insert (iq, "query"))) {
- break;
- }
- iks_insert_attrib(query, "xmlns", "http://jabber.org/protocol/disco#info");
-
- if (!(tag = iks_insert (query, "identity"))) {
- break;
- }
- iks_insert_attrib(tag, "category", "client");
- iks_insert_attrib(tag, "type", "voice");
- iks_insert_attrib(tag, "name", "LibDingaLing");
-
-
- if (!(tag = iks_insert (query, "feature"))) {
- break;
- }
- iks_insert_attrib(tag, "var", "http://jabber.org/protocol/disco#info");
-
- if (!(tag = iks_insert (query, "feature"))) {
- break;
- }
- iks_insert_attrib(tag, "var", "http://www.google.com/xmpp/protocol/voice/v1");
-
- iks_send(handle->parser, iq);
- send = 1;
- } while (0);
-
- iks_delete(iq);
- }
-
- if (!send) {
- globals.logger(DL_LOG_DEBUG, "Memory Error!\n");
- }
- }
-
- return IKS_FILTER_EAT;
-}
-
static int on_vcard(void *user_data, ikspak *pak)
{
@@ -635,7 +544,7 @@
static int on_disco_default(void *user_data, ikspak *pak)
{
char *node = NULL;
- char *ns;
+ char *ns = NULL;
ldl_handle_t *handle = user_data;
iks *iq, *query, *tag;
uint8_t send = 0;
@@ -650,6 +559,8 @@
globals.logger(DL_LOG_DEBUG, "FixME!!! node=[%s]\n", node?node:"");
} else if (pak->subtype == IKS_TYPE_GET) {
if ((iq = iks_new("iq"))) {
+ int all = 0;
+
iks_insert_attrib(iq, "from", handle->login);
iks_insert_attrib(iq, "to", pak->from->full);
iks_insert_attrib(iq, "id", pak->id);
@@ -667,13 +578,17 @@
if (!(tag = iks_insert (query, "identity"))) {
goto fail;
}
+
+ if (!strcasecmp(ns, FEATURE_DISCO) && !node) {
+ all++;
+ }
iks_insert_attrib(tag, "category", "gateway");
iks_insert_attrib(tag, "type", "voice");
iks_insert_attrib(tag, "name", "LibDingaLing");
for (x = 0; FEATURES[x].name; x++) {
- if (!ns || !strcasecmp(ns, FEATURES[x].name)) {
+ if (all || !ns || !strcasecmp(ns, FEATURES[x].name)) {
if (!(tag = iks_insert (query, "feature"))) {
goto fail;
}
@@ -698,26 +613,6 @@
return IKS_FILTER_EAT;
}
-
-
-static int on_disco_items(void *user_data, ikspak *pak)
-{
- globals.logger(DL_LOG_DEBUG, "FixME!!!\n");
- return IKS_FILTER_EAT;
-}
-
-static int on_disco_reg_in(void *user_data, ikspak *pak)
-{
- globals.logger(DL_LOG_DEBUG, "FixME!!!\n");
- return IKS_FILTER_EAT;
-}
-
-static int on_disco_reg_out(void *user_data, ikspak *pak)
-{
- globals.logger(DL_LOG_DEBUG, "FixME!!!\n");
- return IKS_FILTER_EAT;
-}
-
static int on_presence(void *user_data, ikspak *pak)
{
ldl_handle_t *handle = user_data;
@@ -731,6 +626,8 @@
struct ldl_buffer *buffer;
ldl_signal_t dl_signal = LDL_SIGNAL_PRESENCE_IN;
+
+
if (type && *type) {
if (!strcasecmp(type, "unavailable")) {
dl_signal = LDL_SIGNAL_PRESENCE_OUT;
@@ -754,6 +651,7 @@
*resource++ = '\0';
}
+
if (!apr_hash_get(handle->sub_hash, from, APR_HASH_KEY_STRING)) {
iks *msg;
apr_hash_set(handle->sub_hash, apr_pstrdup(handle->pool, from), APR_HASH_KEY_STRING, &marker);
@@ -761,12 +659,11 @@
apr_queue_push(handle->queue, msg);
}
-
if (resource && strstr(resource, "talk") && (buffer = apr_hash_get(handle->probe_hash, id, APR_HASH_KEY_STRING))) {
apr_cpystrn(buffer->buf, from, buffer->len);
fflush(stderr);
buffer->hit = 1;
- }
+ }
if (handle->session_callback) {
handle->session_callback(handle, NULL, dl_signal, to, id, status ? status : "n/a", show ? show : "n/a");
@@ -1500,9 +1397,9 @@
handle,
(iksStreamHook *) (ldl_test_flag(handle, LDL_FLAG_COMPONENT) ? on_stream_component : on_stream));
- if (globals.debug) {
- iks_set_log_hook(handle->parser, (iksLogHook *) on_log);
- }
+
+ iks_set_log_hook(handle->parser, (iksLogHook *) on_log);
+
strncpy(tmp, jabber_id, sizeof(tmp)-1);
sl = strchr(tmp, '/');
@@ -1598,7 +1495,10 @@
handle->state = CS_NEW;
}
ldl_clear_flag_locked(handle, LDL_FLAG_RUNNING);
-
+ if (!ldl_test_flag(handle, LDL_FLAG_TLS)) {
+ ldl_flush_queue(handle, 1);
+ }
+
while(ldl_test_flag(handle, LDL_FLAG_QUEUE_RUNNING)) {
microsleep(100);
}
@@ -1872,6 +1772,15 @@
}
+int ldl_global_debug(int on)
+{
+ if (on > -1) {
+ globals.debug = on ? 1 : 0;
+ }
+
+ return globals.debug ? 1 : 0;
+}
+
void ldl_global_set_logger(ldl_logger_t logger)
{
globals.logger = logger;
@@ -1953,42 +1862,34 @@
iks *pres, *msg;
char *lid = NULL, *low_id = NULL;
struct ldl_buffer buffer;
- apr_time_t started;
+ time_t started;
unsigned int elapsed;
char *notice = "Call Me!";
- int again = 0;
-
+ int next = 0;
+
buffer.buf = buf;
buffer.len = len;
buffer.hit = 0;
- pres = iks_new("presence");
- iks_insert_attrib(pres, "type", "probe");
- iks_insert_attrib(pres, "from", from);
- iks_insert_attrib(pres, "to", id);
-
-
apr_hash_set(handle->probe_hash, id, APR_HASH_KEY_STRING, &buffer);
- msg = iks_make_s10n (IKS_TYPE_SUBSCRIBE, id, notice);
- iks_insert_attrib(msg, "from", from);
- apr_queue_push(handle->queue, msg);
- msg = iks_make_s10n (IKS_TYPE_SUBSCRIBED, id, notice);
- iks_insert_attrib(msg, "from", from);
- apr_queue_push(handle->queue, msg);
- apr_queue_push(handle->queue, pres);
-
- //schedule_packet(handle, next_id(), pres, LDL_RETRY);
- started = apr_time_now();
+ started = time(NULL);
for(;;) {
- elapsed = (unsigned int)((apr_time_now() - started) / 1000);
- if (elapsed > 5000 && ! again) {
+ elapsed = time(NULL) - started;
+ if (elapsed == next) {
msg = iks_make_s10n (IKS_TYPE_SUBSCRIBE, id, notice);
iks_insert_attrib(msg, "from", from);
apr_queue_push(handle->queue, msg);
- again++;
+
+ pres = iks_new("presence");
+ iks_insert_attrib(pres, "xmlns", "jabber:client");
+ iks_insert_attrib(pres, "type", "probe");
+ iks_insert_attrib(pres, "to", id);
+ iks_insert_attrib(pres, "from", from);
+ apr_queue_push(handle->queue, pres);
+ next += 5;
}
- if (elapsed > 10000) {
+ if (elapsed >= 17) {
break;
}
if (buffer.hit) {
@@ -2179,10 +2080,10 @@
ldl_status ldl_global_destroy(void)
{
- if (ldl_test_flag(&globals, LDL_FLAG_INIT)) {
+ if (!ldl_test_flag(&globals, LDL_FLAG_INIT)) {
return LDL_STATUS_FALSE;
}
-
+
apr_pool_destroy(globals.memory_pool);
ldl_clear_flag(&globals, LDL_FLAG_INIT);
apr_terminate();
Modified: freeswitch/branches/mikej/sofiasip-upgrade/libs/libdingaling/src/libdingaling.h
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/libs/libdingaling/src/libdingaling.h (original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/libs/libdingaling/src/libdingaling.h Mon Apr 9 12:32:10 2007
@@ -376,6 +376,13 @@
void ldl_session_accept_candidate(ldl_session_t *session, ldl_candidate_t *candidate);
/*!
+ \brief turn logging on/off
+ \param on (TRUE or FALSE)
+ \return current state
+*/
+int ldl_global_debug(int on);
+
+/*!
\brief Set a custom logger
\param logger the logger function
*/
Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch.h
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch.h (original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch.h Mon Apr 9 12:32:10 2007
@@ -59,7 +59,10 @@
#include <setjmp.h>
#include <ctype.h>
#include <fcntl.h>
+#ifndef _MSC_VER
#include <strings.h>
+#endif
+#include <string.h>
#include <sys/stat.h>
#include <limits.h>
#include <sys/types.h>
Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_rtp.h
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_rtp.h (original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_rtp.h Mon Apr 9 12:32:10 2007
@@ -27,6 +27,7 @@
*
*
* switch_channel.h -- Media Channel Interface
+ * Marcel Barbulescu <marcelbarbulescu(a)gmail.com>
*
*/
/**
@@ -53,6 +54,20 @@
*/
SWITCH_DECLARE(void) switch_rtp_init(switch_memory_pool_t *pool);
+/*!
+ \brief Set/Get RTP start port
+ \param port new value (if > 0)
+ \return the current RTP start port
+*/
+SWITCH_DECLARE(switch_port_t) switch_rtp_set_start_port(switch_port_t port);
+
+/*!
+ \brief Set/Get RTP end port
+ \param port new value (if > 0)
+ \return the current RTP end port
+*/
+SWITCH_DECLARE(switch_port_t) switch_rtp_set_end_port(switch_port_t port);
+
/*!
\brief Request a new port to be used for media
\return the new port to use
Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_xml.h
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_xml.h (original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/include/switch_xml.h Mon Apr 9 12:32:10 2007
@@ -222,7 +222,7 @@
///\param name the name of the tag
///\param off the offset
///\return an xml node or NULL
- switch_xml_t switch_xml_add_child(switch_xml_t xml, const char *name, switch_size_t off);
+ SWITCH_DECLARE(switch_xml_t) switch_xml_add_child(switch_xml_t xml, const char *name, switch_size_t off);
///\brief wrapper for switch_xml_add_child() that strdup()s name
///\param xml the xml node
@@ -235,7 +235,7 @@
///\param xml the xml node
///\param txt the text
///\return an xml node or NULL
- switch_xml_t switch_xml_set_txt(switch_xml_t xml, const char *txt);
+ SWITCH_DECLARE(switch_xml_t) switch_xml_set_txt(switch_xml_t xml, const char *txt);
///\brief wrapper for switch_xml_set_txt() that strdup()s txt
///\ sets the character content for the given tag and returns the tag
Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/Makefile.am
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/Makefile.am (original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/Makefile.am Mon Apr 9 12:32:10 2007
@@ -1,90 +1,28 @@
-CONF_MODULES=if test ! -f $(switch_builddir)/modules.conf ; then cp $(switch_builddir)/build/modules.conf.in $(switch_builddir)/modules.conf ; fi ; conf_modules=`grep -v "\#" $(switch_builddir)/modules.conf` ;
-FOUND_MODULES=found_modules=`find . -type d -name mod_\* | sed -e 's|^\./||'` ;
-OUR_MODULES=if test -z "$(MODULES)" ; then our_modules=$$conf_modules ; else our_modules="$(MODULES)" ; fi ;
-OUR_CLEAN_MODULES=if test -z "$(MODULES)" ; then tmp_clean_modules=`echo $$conf_modules $$found_modules`; \
- our_clean_modules=`for i in $$tmp_clean_modules ; do echo $$i ; done | sort | uniq` ; \
- else our_clean_modules="$(MODULES)" ; fi ;
-MOD_NAME=`echo $$i | sed -e 's|^.*/||'`
-MOD_DIR=`if test -d $(switch_srcdir)/src/mod/$$i ; then echo $(switch_srcdir)/src/mod/$$i ; else echo $$i ; fi;`
+all: $(OUR_MODULES)
+clean: $(OUR_CLEAN_MODULES)
+install: $(OUR_INSTALL_MODULES)
+uninstall: $(OUR_UNINSTALL_MODULES)
-all:
- @$(CONF_MODULES) \
- $(OUR_MODULES) \
- echo ;\
- echo making modules ; \
- for i in $$our_modules ; do \
- echo ;\
- echo making $$i ; \
- moddir=$(MOD_DIR); \
- if test -f $$moddir/Makefile ; then \
- cd $$moddir && MODNAME=$(MOD_NAME) BASE=$(switch_builddir) $(MAKE) $(AM_MAKEFLAGS) || exit 1; else \
- cd $$moddir && MODNAME=$(MOD_NAME) BASE=$(switch_builddir) $(MAKE) $(AM_MAKEFLAGS) -f $(switch_builddir)/build/modmake.rules || exit 1; \
- fi; \
- done
- @echo
- @echo done making modules
-
-clean:
- @$(CONF_MODULES) \
- $(FOUND_MODULES) \
- $(OUR_CLEAN_MODULES) \
- echo ;\
- echo making clean modules ; \
- for i in $$our_clean_modules ; do \
- echo ;\
- echo making clean $$i ; \
- moddir=$(MOD_DIR); \
- if test -f $$moddir/Makefile ; then \
- cd $$moddir && MODNAME=$(MOD_NAME) BASE=$(switch_builddir) $(MAKE) $(AM_MAKEFLAGS) clean || exit 1; else \
- cd $$moddir && MODNAME=$(MOD_NAME) BASE=$(switch_builddir) $(MAKE) $(AM_MAKEFLAGS) -f $(switch_builddir)/build/modmake.rules clean || exit 1; \
- fi; \
- done
- @echo
- @echo done making clean modules
-
-install:
- @$(CONF_MODULES) \
- $(OUR_MODULES) \
- echo ;\
- echo Installing Modules ; \
- for i in $$our_modules ; do \
- echo ;\
- echo making install $$i ; \
- moddir=$(MOD_DIR); \
- if test -f $$moddir/Makefile ; then \
- cd $$moddir && MODNAME=$(MOD_NAME) BASE=$(switch_builddir) $(MAKE) $(AM_MAKEFLAGS) install || exit 1; else \
- cd $$moddir && MODNAME=$(MOD_NAME) BASE=$(switch_builddir) $(MAKE) $(AM_MAKEFLAGS) -f $(switch_builddir)/build/modmake.rules install || exit 1; \
- fi; \
- done
- @echo
- @echo done Installing Modules
-
-uninstall:
- @$(CONF_MODULES) \
- $(OUR_MODULES) \
- echo ;\
- echo Uninstalling Modules ; \
- for i in $$our_modules ; do \
- echo ;\
- echo making uninstall $$i ; \
- moddir=$(MOD_DIR); \
- if test -f $$moddir/Makefile ; then \
- cd $$moddir && MODNAME=$(MOD_NAME) BASE=$(switch_builddir) $(MAKE) $(AM_MAKEFLAGS) uninstall || exit 1; else \
- cd $$moddir && MODNAME=$(MOD_NAME) BASE=$(switch_builddir) $(MAKE) $(AM_MAKEFLAGS) -f $(switch_builddir)/build/modmake.rules uninstall || exit 1; \
- fi; \
- done
- @echo
- @echo done Uninstalling Modules
-
-
-@am__include@ @am__quote@$(switch_builddir)/$(DEPDIR)/modules.targets@am__quote@
-
-$(MODULE_TARGETS):
+$(OUR_MODULES) $(OUR_CLEAN_MODULES) $(OUR_INSTALL_MODULES) $(OUR_UNINSTALL_MODULES):
@set fnord $$MAKEFLAGS; amf=$$2; \
- moddir=`grep $@ $(switch_builddir)/modules.conf | sed -e 's|#||'` ; \
+ target=`echo $@ | sed -e 's|^.*-||'`; \
+ modname=`echo $@ | sed -e 's|-.*||'`; \
+ confmoddir=`cat $(switch_builddir)/modules.conf | grep $$modname | sed -e 's|#||' `; \
+ if test -z "$$confmoddir" ; then moddir=$@ ; else \
+ if test -d "$(switch_srcdir)/src/mod/$$confmoddir" ; then \
+ moddir="$(switch_srcdir)/src/mod/$$confmoddir" ; else \
+ moddir="$$confmoddir" ; \
+ fi ; \
+ fi ; \
+ if test -z "$$target" ; then target="all" ; fi ; \
+ echo ;\
+ echo making $$target $$modname ;\
(if test -f $$moddir/Makefile ; then \
- cd $$moddir && MODNAME=$(MOD_NAME) BASE=$(switch_builddir) $(MAKE) $(AM_MAKEFLAGS); else\
- cd $$moddir && MODNAME=$(MOD_NAME) BASE=$(switch_builddir) $(MAKE) $(AM_MAKEFLAGS) -f $(switch_builddir)/build/modmake.rules;\
+ cd $$moddir && MODNAME=$$modname BASE=$(switch_builddir) $(MAKE) $(AM_MAKEFLAGS) $$target; else\
+ cd $$moddir && MODNAME=$$modname BASE=$(switch_builddir) $(MAKE) $(AM_MAKEFLAGS) -f $(switch_builddir)/build/modmake.rules $$target ;\
fi;)\
|| case "$$amf" in *=*) exit 1;; *k*) fail=yes;; *) exit 1;; esac; \
test -z "$$fail"
+
+.DEFAULT:
+ @if test -z "`echo $@ | grep all`"; then $(MAKE) $(AM_MAKEFLAGS) $@-all ; else echo Unknown target `echo $@ | sed -e 's|-all||'`; exit 1; fi
Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/applications/mod_commands/mod_commands.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/applications/mod_commands/mod_commands.c (original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/applications/mod_commands/mod_commands.c Mon Apr 9 12:32:10 2007
@@ -27,6 +27,7 @@
* Michael Jerris <mike(a)jerris.com>
* Johny Kadarisman <jkr888(a)gmail.com>
* Paul Tinsley <jackhammer(a)gmail.com>
+ * Marcel Barbulescu <marcelbarbulescu(a)gmail.com>
*
*
* mod_commands.c -- Misc. Command Module
@@ -724,6 +725,55 @@
return SWITCH_STATUS_SUCCESS;
}
+static switch_status_t xml_wrap_api_function(char *cmd, switch_core_session_t *isession, switch_stream_handle_t *stream)
+{
+ char *dcommand, *edata = NULL, *send = NULL, *command, *arg = NULL;
+ switch_stream_handle_t mystream = { 0 };
+ int encoded = 0, elen = 0;
+
+ if ((dcommand = strdup(cmd))) {
+ if (!strncasecmp(dcommand, "encoded ", 8)) {
+ encoded++;
+ command = dcommand + 8;
+ } else {
+ command = dcommand;
+ }
+
+ if ((arg = strchr(command, ' '))) {
+ *arg++ = '\0';
+ }
+ SWITCH_STANDARD_STREAM(mystream);
+ switch_api_execute(command, arg, NULL, &mystream);
+
+ if (mystream.data) {
+ if (encoded) {
+ elen = (int) strlen(mystream.data) * 3;
+ edata = malloc(elen);
+ assert(edata != NULL);
+ memset(edata, 0, elen);
+ switch_url_encode(mystream.data, edata, elen);
+ send = edata;
+ } else {
+ send = mystream.data;
+ }
+ }
+
+ stream->write_function(stream,
+ "<result>\n"
+ " <row id=\"1\">\n"
+ " <data>%s</data>\n"
+ " </row>\n"
+ "</result>\n",
+ send ? send : "ERROR"
+ );
+ switch_safe_free(mystream.data);
+ switch_safe_free(edata);
+ free(dcommand);
+ }
+
+ return SWITCH_STATUS_SUCCESS;
+}
+
static switch_status_t sched_api_function(char *cmd, switch_core_session_t *isession, switch_stream_handle_t *stream)
{
char *tm = NULL, *dcmd, *group;
@@ -768,8 +818,43 @@
char *http;
uint32_t count;
int print_title;
+ switch_xml_t xml;
+ int rows;
};
+static int show_as_xml_callback(void *pArg, int argc, char **argv, char **columnNames)
+{
+ struct holder *holder = (struct holder *) pArg;
+ switch_xml_t row, field;
+ int x, f_off = 0;
+ char id[50];
+
+ if (holder->count == 0) {
+ if (!(holder->xml = switch_xml_new("result"))) {
+ return -1;
+ }
+ }
+
+ if (!(row = switch_xml_add_child_d(holder->xml, "row", holder->rows++))) {
+ return -1;
+ }
+
+ snprintf(id, sizeof(id), "%d", holder->rows);
+ switch_xml_set_attr_d(row, "id", id);
+
+ for(x = 0; x < argc; x++) {
+ if ((field = switch_xml_add_child_d(row, columnNames[x], f_off++))) {
+ switch_xml_set_txt_d(field, argv[x]);
+ } else {
+ return -1;
+ }
+ }
+
+ holder->count++;
+
+ return 0;
+}
+
static int show_callback(void *pArg, int argc, char **argv, char **columnNames)
{
struct holder *holder = (struct holder *) pArg;
@@ -808,19 +893,33 @@
return 0;
}
-static switch_status_t show_function(char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream)
+static switch_status_t show_function(char *data, switch_core_session_t *session, switch_stream_handle_t *stream)
{
char sql[1024];
char *errmsg;
switch_core_db_t *db = switch_core_db_handle();
struct holder holder = { 0 };
int help = 0;
+ char *mydata = NULL, *argv[5] = {0};
+ int argc;
+ char *cmd = NULL, *as = NULL;
if (session) {
return SWITCH_STATUS_FALSE;
}
- if (stream->event) {
+ if (data) {
+ if ((mydata = strdup(data))) {
+ argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
+ }
+
+ cmd = argv[0];
+ if (argv[2] && !strcasecmp(argv[1], "as")) {
+ as = argv[2];
+ }
+ }
+
+ if (!as && stream->event) {
holder.http = switch_event_get_header(stream->event, "http-host");
}
@@ -864,23 +963,44 @@
holder.stream->write_function(holder.stream, "<table cellpadding=1 cellspacing=4 border=1>\n");
}
- switch_core_db_exec(db, sql, show_callback, &holder, &errmsg);
-
- if (holder.http) {
- holder.stream->write_function(holder.stream, "</table>");
+ if (!as) {
+ as = "csv";
}
- if (errmsg) {
- stream->write_function(stream, "SQL ERR [%s]\n", errmsg);
- switch_core_db_free(errmsg);
- errmsg = NULL;
- } else if (help) {
- if (holder.count == 0)
- stream->write_function(stream, "No such command.\n");
+ if (!strcasecmp(as, "csv")) {
+ switch_core_db_exec(db, sql, show_callback, &holder, &errmsg);
+ if (holder.http) {
+ holder.stream->write_function(holder.stream, "</table>");
+ }
+
+ if (errmsg) {
+ stream->write_function(stream, "SQL ERR [%s]\n", errmsg);
+ switch_core_db_free(errmsg);
+ errmsg = NULL;
+ } else if (help) {
+ if (holder.count == 0)
+ stream->write_function(stream, "No such command.\n");
+ } else {
+ stream->write_function(stream, "\n%u total.\n", holder.count);
+ }
+ } else if (!strcasecmp(as, "xml")) {
+ switch_core_db_exec(db, sql, show_as_xml_callback, &holder, &errmsg);
+ if (holder.xml) {
+ char *xmlstr = switch_xml_toxml(holder.xml);
+ if (xmlstr) {
+ holder.stream->write_function(holder.stream, "%s", xmlstr);
+ free(xmlstr);
+ } else {
+ holder.stream->write_function(holder.stream, "ERROR\n");
+ }
+ } else {
+ holder.stream->write_function(holder.stream, "ERROR\n");
+ }
} else {
- stream->write_function(stream, "\n%u total.\n", holder.count);
+ holder.stream->write_function(holder.stream, "Cannot find format %s\n", as);
}
+ switch_safe_free(mydata);
switch_core_db_close(db);
return SWITCH_STATUS_SUCCESS;
}
@@ -914,12 +1034,21 @@
return SWITCH_STATUS_SUCCESS;
}
+
+static switch_api_interface_t xml_wrap_api_interface = {
+ /*.interface_name */ "xml_wrap",
+ /*.desc */ "Wrap another api command in xml",
+ /*.function */ xml_wrap_api_function,
+ /*.syntax */ "<command> <args>",
+ /*.next */ NULL
+};
+
static switch_api_interface_t sched_del_api_interface = {
/*.interface_name */ "sched_del",
/*.desc */ "Delete a Scheduled task",
/*.function */ sched_del_function,
/*.syntax */ "<task_id>|<group_id>",
- /*.next */ NULL
+ /*.next */ &xml_wrap_api_interface
};
static switch_api_interface_t sched_api_api_interface = {
Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_dingaling/Makefile
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_dingaling/Makefile (original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_dingaling/Makefile Mon Apr 9 12:32:10 2007
@@ -3,7 +3,7 @@
LOCAL_CFLAGS = `$(BASE)/libs/apr/apr-1-config --cflags --cppflags --includes`
LOCAL_CFLAGS += `$(BASE)/libs/apr-util/apu-1-config --includes`
LOCAL_CFLAGS += `if test -f $(BASE)/.libs/libfreeswitch_la-switch_odbc.o ; then echo -DSWITCH_HAVE_ODBC; fi ;`
-LOCAL_CFLAGS += -w
+#LOCAL_CFLAGS += -w
IKS_DIR=$(BASE)/libs/iksemel
IKS_LA=$(IKS_DIR)/src/libiksemel.la
Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_dingaling/mod_dingaling.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_dingaling/mod_dingaling.c (original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_dingaling/mod_dingaling.c Mon Apr 9 12:32:10 2007
@@ -108,7 +108,9 @@
char *login;
char *password;
char *message;
+#ifdef AUTO_REPLY
char *auto_reply;
+#endif
char *dialplan;
char *ip;
char *extip;
@@ -192,6 +194,7 @@
static switch_status_t dl_login(char *arg, switch_core_session_t *session, switch_stream_handle_t *stream);
static switch_status_t dl_logout(char *profile_name, switch_core_session_t *session, switch_stream_handle_t *stream);
static switch_status_t dl_pres(char *profile_name, switch_core_session_t *session, switch_stream_handle_t *stream);
+static switch_status_t dl_debug(char *profile_name, switch_core_session_t *session, switch_stream_handle_t *stream);
static switch_status_t channel_on_init(switch_core_session_t *session);
static switch_status_t channel_on_hangup(switch_core_session_t *session);
static switch_status_t channel_on_ring(switch_core_session_t *session);
@@ -722,13 +725,15 @@
if (ll) {
if ((xmltxt = strchr(ll, ':'))) {
*xmltxt++ = '\0';
- xml = switch_xml_parse_str(xmltxt, strlen(xmltxt));
- form = switch_xml_toxml(xml);
- switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, level,
- "%s:\n-------------------------------------------------------------------------------\n"
- "%s\n", ll, form);
- switch_xml_free(xml);
- free(data);
+ if (strlen(xmltxt) > 2) {
+ xml = switch_xml_parse_str(xmltxt, strlen(xmltxt));
+ form = switch_xml_toxml(xml);
+ switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, level,
+ "%s:\n-------------------------------------------------------------------------------\n"
+ "%s\n", ll, form);
+ switch_xml_free(xml);
+ free(data);
+ }
}
}
} else {
@@ -849,9 +854,8 @@
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "SETUP RTP %s:%d -> %s:%d\n", tech_pvt->profile->ip,
tech_pvt->local_port, tech_pvt->remote_ip, tech_pvt->remote_port);
-
+
flags = SWITCH_RTP_FLAG_GOOGLEHACK | SWITCH_RTP_FLAG_AUTOADJ | SWITCH_RTP_FLAG_RAW_WRITE | SWITCH_RTP_FLAG_AUTO_CNG;
- //flags = SWITCH_RTP_FLAG_AUTOADJ;
if (switch_test_flag(tech_pvt->profile, TFLAG_TIMER)) {
flags |= SWITCH_RTP_FLAG_USE_TIMER;
@@ -874,7 +878,11 @@
uint8_t inb = switch_test_flag(tech_pvt, TFLAG_OUTBOUND) ? 0 : 1;
switch_rtp_activate_ice(tech_pvt->rtp_session, tech_pvt->remote_user, tech_pvt->local_user);
if ((vad_in && inb) || (vad_out && !inb)) {
- switch_rtp_enable_vad(tech_pvt->rtp_session, tech_pvt->session, &tech_pvt->read_codec, SWITCH_VAD_FLAG_TALKING);
+ if (switch_rtp_enable_vad(tech_pvt->rtp_session, tech_pvt->session, &tech_pvt->read_codec, SWITCH_VAD_FLAG_TALKING) != SWITCH_STATUS_SUCCESS) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "VAD ERROR %s\n", err);
+ switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
+ return 0;
+ }
switch_set_flag_locked(tech_pvt, TFLAG_VAD);
}
switch_rtp_set_cng_pt(tech_pvt->rtp_session, 13);
@@ -1065,7 +1073,8 @@
while (!(switch_test_flag(tech_pvt, TFLAG_CODEC_READY) &&
switch_test_flag(tech_pvt, TFLAG_RTP_READY) &&
- switch_test_flag(tech_pvt, TFLAG_ANSWER) && switch_test_flag(tech_pvt, TFLAG_TRANSPORT_ACCEPT)
+ switch_test_flag(tech_pvt, TFLAG_ANSWER) && switch_test_flag(tech_pvt, TFLAG_TRANSPORT_ACCEPT) &&
+ tech_pvt->remote_ip && tech_pvt->remote_port
&& switch_test_flag(tech_pvt, TFLAG_TRANSPORT))) {
now = switch_time_now();
elapsed = (unsigned int) ((now - started) / 1000);
@@ -1329,89 +1338,101 @@
static switch_status_t channel_read_frame(switch_core_session_t *session, switch_frame_t **frame, int timeout, switch_io_flag_t flags, int stream_id)
{
struct private_object *tech_pvt = NULL;
- uint32_t bytes = 0;
- switch_size_t samples = 0, frames = 0, ms = 0;
switch_channel_t *channel = NULL;
- switch_payload_t payload = 0;
- switch_status_t status;
+ int payload = 0;
channel = switch_core_session_get_channel(session);
assert(channel != NULL);
- tech_pvt = switch_core_session_get_private(session);
+ tech_pvt = (struct private_object *) switch_core_session_get_private(session);
assert(tech_pvt != NULL);
-
- if (!tech_pvt->rtp_session) {
- return SWITCH_STATUS_FALSE;
- }
-
- if (switch_test_flag(tech_pvt, TFLAG_BYE)) {
- //terminate_session(&session, __LINE__, SWITCH_CAUSE_NORMAL_CLEARING);
- return SWITCH_STATUS_FALSE;
+ while (!(tech_pvt->read_codec.implementation && switch_rtp_ready(tech_pvt->rtp_session))) {
+ if (switch_channel_ready(channel)) {
+ switch_yield(10000);
+ } else {
+ return SWITCH_STATUS_GENERR;
+ }
}
tech_pvt->read_frame.datalen = 0;
switch_set_flag_locked(tech_pvt, TFLAG_READING);
- bytes = tech_pvt->read_codec.implementation->encoded_bytes_per_frame;
- samples = tech_pvt->read_codec.implementation->samples_per_frame;
- ms = tech_pvt->read_codec.implementation->microseconds_per_frame;
- tech_pvt->read_frame.datalen = 0;
+#if 0
+ if (tech_pvt->last_read) {
+ elapsed = (unsigned int) ((switch_time_now() - tech_pvt->last_read) / 1000);
+ if (elapsed > 60000) {
+ return SWITCH_STATUS_TIMEOUT;
+ }
+ }
+#endif
- while (!switch_test_flag(tech_pvt, TFLAG_BYE) && switch_test_flag(tech_pvt, TFLAG_IO)
- && tech_pvt->read_frame.datalen == 0) {
- tech_pvt->read_frame.flags = 0;
- status = switch_rtp_zerocopy_read_frame(tech_pvt->rtp_session, &tech_pvt->read_frame);
+ if (switch_test_flag(tech_pvt, TFLAG_IO)) {
+ switch_status_t status;
- if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) {
- return SWITCH_STATUS_FALSE;
- }
- payload = tech_pvt->read_frame.payload;
+ assert(tech_pvt->rtp_session != NULL);
+ tech_pvt->read_frame.datalen = 0;
- if (switch_rtp_has_dtmf(tech_pvt->rtp_session)) {
- char dtmf[128];
- switch_rtp_dequeue_dtmf(tech_pvt->rtp_session, dtmf, sizeof(dtmf));
- switch_channel_queue_dtmf(channel, dtmf);
- switch_set_flag_locked(tech_pvt, TFLAG_DTMF);
- }
- if (switch_test_flag(tech_pvt, TFLAG_DTMF)) {
- switch_clear_flag_locked(tech_pvt, TFLAG_DTMF);
- return SWITCH_STATUS_BREAK;
- }
+ while (switch_test_flag(tech_pvt, TFLAG_IO) && tech_pvt->read_frame.datalen == 0) {
+ tech_pvt->read_frame.flags = SFF_NONE;
- if (switch_test_flag(&tech_pvt->read_frame, SFF_CNG)) {
- tech_pvt->read_frame.datalen = tech_pvt->last_read ? tech_pvt->last_read : tech_pvt->read_codec.implementation->encoded_bytes_per_frame;
- }
+ status = switch_rtp_zerocopy_read_frame(tech_pvt->rtp_session, &tech_pvt->read_frame);
+ if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) {
+ return SWITCH_STATUS_FALSE;
+ }
- if (tech_pvt->read_frame.datalen > 0) {
- if (!switch_test_flag((&tech_pvt->read_frame), SFF_CNG)) {
- if (tech_pvt->read_codec.implementation->encoded_bytes_per_frame && bytes) {
- bytes = tech_pvt->read_codec.implementation->encoded_bytes_per_frame;
- frames = (tech_pvt->read_frame.datalen / bytes);
- } else {
- frames = 1;
+
+
+ payload = tech_pvt->read_frame.payload;
+
+#if 0
+ elapsed = (unsigned int) ((switch_time_now() - started) / 1000);
+
+ if (timeout > -1) {
+ if (elapsed >= (unsigned int) timeout) {
+ return SWITCH_STATUS_BREAK;
}
- samples = frames * tech_pvt->read_codec.implementation->samples_per_frame;
- ms = frames * tech_pvt->read_codec.implementation->microseconds_per_frame;
- tech_pvt->timestamp_recv += (int32_t) samples;
- tech_pvt->read_frame.samples = (int) samples;
- tech_pvt->last_read = tech_pvt->read_frame.datalen;
}
- break;
- }
- switch_yield(1000);
- }
+ elapsed = (unsigned int) ((switch_time_now() - last_act) / 1000);
+ if (elapsed >= hard_timeout) {
+ return SWITCH_STATUS_BREAK;
+ }
+#endif
+ if (switch_rtp_has_dtmf(tech_pvt->rtp_session)) {
+ char dtmf[128];
+ switch_rtp_dequeue_dtmf(tech_pvt->rtp_session, dtmf, sizeof(dtmf));
+ switch_channel_queue_dtmf(channel, dtmf);
+ }
+
+
+ if (tech_pvt->read_frame.datalen > 0) {
+ size_t bytes = 0;
+ int frames = 1;
+ if (!switch_test_flag((&tech_pvt->read_frame), SFF_CNG)) {
+ if ((bytes = tech_pvt->read_codec.implementation->encoded_bytes_per_frame)) {
+ frames = (tech_pvt->read_frame.datalen / bytes);
+ }
+ tech_pvt->read_frame.samples = (int) (frames * tech_pvt->read_codec.implementation->samples_per_frame);
+ }
+ break;
+ }
+ }
+ }
switch_clear_flag_locked(tech_pvt, TFLAG_READING);
+ if (tech_pvt->read_frame.datalen == 0) {
+ *frame = NULL;
+ return SWITCH_STATUS_GENERR;
+ }
*frame = &tech_pvt->read_frame;
+
return SWITCH_STATUS_SUCCESS;
}
@@ -1422,45 +1443,46 @@
switch_status_t status = SWITCH_STATUS_SUCCESS;
int bytes = 0, samples = 0, frames = 0;
-
channel = switch_core_session_get_channel(session);
assert(channel != NULL);
- tech_pvt = switch_core_session_get_private(session);
+ tech_pvt = (struct private_object *) switch_core_session_get_private(session);
assert(tech_pvt != NULL);
- if (!tech_pvt->rtp_session) {
- return SWITCH_STATUS_FALSE;
+ while (!(tech_pvt->read_codec.implementation && switch_rtp_ready(tech_pvt->rtp_session))) {
+ if (switch_channel_ready(channel)) {
+ switch_yield(10000);
+ } else {
+ return SWITCH_STATUS_GENERR;
+ }
}
- if (!switch_test_flag(tech_pvt, TFLAG_RTP_READY)) {
+ if (!switch_test_flag(tech_pvt, TFLAG_IO)) {
return SWITCH_STATUS_SUCCESS;
}
-
- if (switch_test_flag(tech_pvt, TFLAG_BYE)) {
- return SWITCH_STATUS_FALSE;
- }
-
switch_set_flag_locked(tech_pvt, TFLAG_WRITING);
- if (tech_pvt->read_codec.implementation->encoded_bytes_per_frame) {
- bytes = tech_pvt->read_codec.implementation->encoded_bytes_per_frame;
- frames = ((int) frame->datalen / bytes);
- } else {
- frames = 1;
- }
+ if (!switch_test_flag(frame, SFF_CNG)) {
+ if (tech_pvt->read_codec.implementation->encoded_bytes_per_frame) {
+ bytes = tech_pvt->read_codec.implementation->encoded_bytes_per_frame;
+ frames = ((int) frame->datalen / bytes);
+ } else
+ frames = 1;
- samples = frames * tech_pvt->read_codec.implementation->samples_per_frame;
- tech_pvt->timestamp_send += samples;
- if (switch_rtp_write_frame(tech_pvt->rtp_session, frame, 0) < 0) {
- terminate_session(&session, __LINE__, SWITCH_CAUSE_NORMAL_CLEARING);
- return SWITCH_STATUS_FALSE;
+ samples = frames * tech_pvt->read_codec.implementation->samples_per_frame;
}
+#if 0
+ printf("%s %s->%s send %d bytes %d samples in %d frames ts=%d\n",
+ switch_channel_get_name(channel),
+ tech_pvt->local_sdp_audio_ip, tech_pvt->remote_sdp_audio_ip, frame->datalen, samples, frames, tech_pvt->timestamp_send);
+#endif
+ tech_pvt->timestamp_send += samples;
+ //switch_rtp_write_frame(tech_pvt->rtp_session, frame, tech_pvt->timestamp_send);
+ switch_rtp_write_frame(tech_pvt->rtp_session, frame, 0);
switch_clear_flag_locked(tech_pvt, TFLAG_WRITING);
-
return status;
}
@@ -1569,12 +1591,20 @@
};
+static switch_api_interface_t debug_api_interface = {
+ /*.interface_name */ "dl_debug",
+ /*.desc */ "DingaLing Presence",
+ /*.function */ dl_debug,
+ /*.syntax */ "dl_debug [true|false]",
+ /*.next */ NULL
+};
+
static switch_api_interface_t pres_api_interface = {
/*.interface_name */ "dl_pres",
/*.desc */ "DingaLing Presence",
/*.function */ dl_pres,
/*.syntax */ "dl_pres <profile_name>",
- /*.next */ NULL
+ /*.next */ &debug_api_interface
};
static switch_api_interface_t logout_api_interface = {
@@ -1898,6 +1928,7 @@
break;
}
}
+
if (globals.init) {
ldl_global_destroy();
}
@@ -1933,8 +1964,10 @@
switch_set_flag(profile, TFLAG_TIMER);
} else if (!strcasecmp(var, "dialplan")) {
profile->dialplan = switch_core_strdup(module_pool, val);
+#ifdef AUTO_REPLY // gotta fix looping on this
} else if (!strcasecmp(var, "auto-reply")) {
profile->auto_reply = switch_core_strdup(module_pool, val);
+#endif
} else if (!strcasecmp(var, "name")) {
profile->name = switch_core_strdup(module_pool, val);
} else if (!strcasecmp(var, "message")) {
@@ -1981,6 +2014,27 @@
}
}
+static switch_status_t dl_debug(char *tf, switch_core_session_t *session, switch_stream_handle_t *stream)
+{
+ int on, cur;
+
+ if (session) {
+ return SWITCH_STATUS_FALSE;
+ }
+
+ if (tf) {
+ on = switch_true(tf);
+ cur = ldl_global_debug(on);
+ } else {
+ cur = ldl_global_debug(-1);
+ }
+
+
+ stream->write_function(stream, "DEBUG IS NOW %s\n", cur ? "ON" : "OFF");
+
+ return SWITCH_STATUS_SUCCESS;
+}
+
static switch_status_t dl_pres(char *profile_name, switch_core_session_t *session, switch_stream_handle_t *stream)
{
mdl_profile_t *profile;
@@ -2349,6 +2403,8 @@
switch_mutex_unlock(profile->mutex);
if (is_special(to)) {
ldl_handle_send_presence(profile->handle, to, from, NULL, NULL, "Click To Call", profile->avatar);
+ } else {
+ ldl_handle_send_presence(profile->handle, to, from, NULL, NULL, "Authenticated.\nCome to ClueCon!\nhttp://www.cluecon.com", profile->avatar);
}
#if 0
if (is_special(to)) {
@@ -2444,12 +2500,13 @@
char *proto = MDL_CHAT_PROTO;
char *pproto = NULL, *ffrom = NULL;
char *hint;
-
+#ifdef AUTO_REPLY
if (profile->auto_reply) {
ldl_handle_send_msg(handle,
(profile->user_flags & LDL_FLAG_COMPONENT) ? to : ldl_handle_get_login(profile->handle), from, "",
profile->auto_reply);
}
+#endif
if (strchr(to, '+')) {
pproto = strdup(to);
@@ -2526,7 +2583,7 @@
}
} else {
- if (dl_signal != LDL_SIGNAL_INITIATE) {
+ if (dl_signal != LDL_SIGNAL_INITIATE && !msg) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Session is already dead\n");
status = LDL_STATUS_FALSE;
goto done;
@@ -2534,6 +2591,7 @@
if ((session = switch_core_session_request(&channel_endpoint_interface, NULL)) != 0) {
switch_core_session_add_stream(session, NULL);
+
if ((tech_pvt = (struct private_object *) switch_core_session_alloc(session, sizeof(struct private_object))) != 0) {
memset(tech_pvt, 0, sizeof(*tech_pvt));
switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_sofia/mod_sofia.h
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_sofia/mod_sofia.h (original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_sofia/mod_sofia.h Mon Apr 9 12:32:10 2007
@@ -27,6 +27,7 @@
* Ken Rice, Asteria Solutions Group, Inc <ken(a)asteriasgi.com>
* Paul D. Tinsley <pdt at jackhammer.org>
* Bret McDanel <trixter AT 0xdecafbad.com>
+ * Marcel Barbulescu <marcelbarbulescu(a)gmail.com>
*
*
* mod_sofia.h -- SOFIA SIP Endpoint
@@ -159,7 +160,8 @@
REG_STATE_REGISTER,
REG_STATE_REGED,
REG_STATE_FAILED,
- REG_STATE_EXPIRED
+ REG_STATE_EXPIRED,
+ REG_STATE_NOREG
} reg_state_t;
struct outbound_reg {
Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_sofia/sofia.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_sofia/sofia.c (original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_sofia/sofia.c Mon Apr 9 12:32:10 2007
@@ -27,6 +27,7 @@
* Ken Rice, Asteria Solutions Group, Inc <ken(a)asteriasgi.com>
* Paul D. Tinsley <pdt at jackhammer.org>
* Bret McDanel <trixter AT 0xdecafbad.com>
+ * Marcel Barbulescu <marcelbarbulescu(a)gmail.com>
*
*
* sofia.c -- SOFIA SIP Endpoint (sofia code)
@@ -668,7 +669,7 @@
}
if ((gateway = switch_core_alloc(profile->pool, sizeof(*gateway)))) {
- char *scheme = "Digest",
+ char *register_str = "true", *scheme = "Digest",
*realm = NULL,
*username = NULL, *password = NULL, *extension = NULL, *proxy = NULL, *context = "default", *expire_seconds = "3600";
@@ -682,7 +683,9 @@
char *var = (char *) switch_xml_attr_soft(param, "name");
char *val = (char *) switch_xml_attr_soft(param, "value");
- if (!strcmp(var, "scheme")) {
+ if (!strcmp(var, "register")) {
+ register_str = val;
+ } else if (!strcmp(var, "scheme")) {
scheme = val;
} else if (!strcmp(var, "realm")) {
realm = val;
@@ -725,6 +728,9 @@
proxy = realm;
}
+ if (!switch_true(register_str)) {
+ gateway->state = REG_STATE_NOREG;
+ }
gateway->register_scheme = switch_core_strdup(gateway->pool, scheme);
gateway->register_context = switch_core_strdup(gateway->pool, context);
gateway->register_realm = switch_core_strdup(gateway->pool, realm);
Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_sofia/sofia_reg.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_sofia/sofia_reg.c (original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/mod/endpoints/mod_sofia/sofia_reg.c Mon Apr 9 12:32:10 2007
@@ -27,6 +27,7 @@
* Ken Rice, Asteria Solutions Group, Inc <ken(a)asteriasgi.com>
* Paul D. Tinsley <pdt at jackhammer.org>
* Bret McDanel <trixter AT 0xdecafbad.com>
+ * Marcel Barbulescu <marcelbarbulescu(a)gmail.com>
*
*
* sofia_ref.c -- SOFIA SIP Endpoint (registration code)
@@ -56,6 +57,8 @@
reg_state_t ostate = gateway_ptr->state;
switch (ostate) {
+ case REG_STATE_NOREG:
+ break;
case REG_STATE_REGISTER:
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "registered %s\n", gateway_ptr->name);
gateway_ptr->expires = now + gateway_ptr->freq;
@@ -244,6 +247,7 @@
switch_event_t *event;
const char *rpid = "unknown";
const char *display = "\"user\"";
+ char network_addr[80];
/* all callers must confirm that sip, sip->sip_request and sip->sip_contact are not NULL */
assert(sip != NULL && sip->sip_contact != NULL && sip->sip_request != NULL);
@@ -322,7 +326,8 @@
}
if (!authorization || stale) {
- snprintf(params, sizeof(params), "from_user=%s&from_host=%s&contact=%s", from_user, from_host, contact_str);
+ get_addr(network_addr, sizeof(network_addr), &((struct sockaddr_in *) msg_addrinfo(nua_current_request(nua))->ai_addr)->sin_addr);
+ snprintf(params, sizeof(params), "network_addr=%s&from_user=%s&from_host=%s&contact=%s", network_addr, from_user, from_host, contact_str);
if (switch_xml_locate("directory", "domain", "name", from_host, &xml, &domain, params) != SWITCH_STATUS_SUCCESS) {
@@ -777,3 +782,4 @@
+
Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/switch_core.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/switch_core.c (original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/switch_core.c Mon Apr 9 12:32:10 2007
@@ -26,6 +26,7 @@
* Anthony Minessale II <anthmct(a)yahoo.com>
* Michael Jerris <mike(a)jerris.com>
* Paul D. Tinsley <pdt at jackhammer.org>
+ * Marcel Barbulescu <marcelbarbulescu(a)gmail.com>
*
*
* switch_core.c -- Main Core Library
@@ -445,6 +446,12 @@
if (!strcasecmp(var, "max-sessions")) {
switch_core_session_limit(atoi(val));
}
+ else if (!strcasecmp(var, "rtp-start-port")) {
+ switch_rtp_set_start_port((switch_port_t)atoi(val));
+ }
+ else if (!strcasecmp(var, "rtp-end-port")) {
+ switch_rtp_set_end_port((switch_port_t)atoi(val));
+ }
}
}
Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/switch_rtp.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/switch_rtp.c (original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/switch_rtp.c Mon Apr 9 12:32:10 2007
@@ -24,6 +24,7 @@
* Contributor(s):
*
* Anthony Minessale II <anthmct(a)yahoo.com>
+ * Marcel Barbulescu <marcelbarbulescu(a)gmail.com>
*
*
* switch_rtp.c -- RTP
@@ -50,6 +51,8 @@
#define MASTER_KEY_LEN 30
#define RTP_MAGIC_NUMBER 42
+static switch_port_t START_PORT = RTP_START_PORT;
+static switch_port_t END_PORT = RTP_END_PORT;
static switch_port_t NEXT_PORT = RTP_START_PORT;
static switch_mutex_t *port_lock = NULL;
@@ -263,6 +266,43 @@
global_init = 1;
}
+SWITCH_DECLARE(switch_port_t) switch_rtp_set_start_port(switch_port_t port)
+{
+ if (port) {
+ if (port_lock) {
+ switch_mutex_lock(port_lock);
+ }
+ if (NEXT_PORT == START_PORT) {
+ NEXT_PORT = port;
+ }
+ START_PORT = port;
+ if (NEXT_PORT < START_PORT) {
+ NEXT_PORT = START_PORT;
+ }
+ if (port_lock) {
+ switch_mutex_unlock(port_lock);
+ }
+ }
+ return START_PORT;
+}
+
+SWITCH_DECLARE(switch_port_t) switch_rtp_set_end_port(switch_port_t port)
+{
+ if (port) {
+ if (port_lock) {
+ switch_mutex_lock(port_lock);
+ }
+ END_PORT = port;
+ if (NEXT_PORT > END_PORT) {
+ NEXT_PORT = START_PORT;
+ }
+ if (port_lock) {
+ switch_mutex_unlock(port_lock);
+ }
+ }
+ return END_PORT;
+}
+
SWITCH_DECLARE(switch_port_t) switch_rtp_request_port(void)
{
switch_port_t port;
@@ -270,8 +310,8 @@
switch_mutex_lock(port_lock);
port = NEXT_PORT;
NEXT_PORT += 2;
- if (NEXT_PORT > RTP_END_PORT) {
- NEXT_PORT = RTP_START_PORT;
+ if (NEXT_PORT > END_PORT) {
+ NEXT_PORT = START_PORT;
}
switch_mutex_unlock(port_lock);
return port;
@@ -772,7 +812,6 @@
return -1;
}
-
if (!bytes && switch_test_flag(rtp_session, SWITCH_RTP_FLAG_BREAK)) {
switch_clear_flag_locked(rtp_session, SWITCH_RTP_FLAG_BREAK);
@@ -787,22 +826,6 @@
if (bytes < 0) {
return (int) bytes;
- } else if (bytes > 0 && switch_test_flag(rtp_session, SWITCH_RTP_FLAG_SECURE)) {
- int sbytes = (int) bytes;
- err_status_t stat;
-
- stat = srtp_unprotect(rtp_session->recv_ctx, &rtp_session->recv_msg.header, &sbytes);
- if (stat) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
- "error: srtp unprotection failed with code %d%s\n", stat,
- stat == err_status_replay_fail ? " (replay check failed)" : stat == err_status_auth_fail ? " (auth check failed)" : "");
- return -1;
- }
- bytes = sbytes;
- }
-
- if (bytes && rtp_session->cng_pt && rtp_session->recv_msg.header.pt == rtp_session->cng_pt) {
- continue;
}
if (rtp_session->timer.interval) {
@@ -818,26 +841,63 @@
}
}
-
-
if (check) {
do_2833(rtp_session);
if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_USE_TIMER)) {
+ uint8_t *data = (uint8_t *) rtp_session->recv_msg.body;
/* We're late! We're Late! */
if (!switch_test_flag(rtp_session, SWITCH_RTP_FLAG_NOBLOCK) && status == SWITCH_STATUS_BREAK) {
switch_yield(1000);
continue;
}
- memset(&rtp_session->recv_msg, 0, SWITCH_RTP_CNG_PAYLOAD);
- rtp_session->recv_msg.header.pt = SWITCH_RTP_CNG_PAYLOAD;
+
+ memset(data, 0, 2);
+ data[0] = 65;
+
+ rtp_session->recv_msg.header.pt = (uint32_t) rtp_session->cng_pt ? rtp_session->cng_pt : SWITCH_RTP_CNG_PAYLOAD;
*flags |= SFF_CNG;
- /* Return a CNG frame */
- *payload_type = SWITCH_RTP_CNG_PAYLOAD;
- return SWITCH_RTP_CNG_PAYLOAD + rtp_header_len;
+ *payload_type = (switch_payload_t)rtp_session->recv_msg.header.pt;
+ return 2 + rtp_header_len;
}
}
+ if (bytes && rtp_session->recv_msg.header.version != 2) {
+ uint8_t *data = (uint8_t *) rtp_session->recv_msg.body;
+ if (rtp_session->recv_msg.header.version == 0 && rtp_session->ice_user) {
+ handle_ice(rtp_session, (void *) &rtp_session->recv_msg, bytes);
+ }
+
+ if (rtp_session->invalid_handler) {
+ rtp_session->invalid_handler(rtp_session, rtp_session->sock, (void *) &rtp_session->recv_msg, bytes, rtp_session->from_addr);
+ }
+
+ memset(data, 0, 2);
+ data[0] = 65;
+
+ rtp_session->recv_msg.header.pt = (uint32_t) rtp_session->cng_pt ? rtp_session->cng_pt : SWITCH_RTP_CNG_PAYLOAD;
+ *flags |= SFF_CNG;
+ *payload_type = (switch_payload_t)rtp_session->recv_msg.header.pt;
+ return 2 + rtp_header_len;
+ }
+
+
+
+
+ if (bytes && switch_test_flag(rtp_session, SWITCH_RTP_FLAG_SECURE)) {
+ int sbytes = (int) bytes;
+ err_status_t stat;
+
+ stat = srtp_unprotect(rtp_session->recv_ctx, &rtp_session->recv_msg.header, &sbytes);
+ if (stat) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
+ "error: srtp unprotection failed with code %d%s\n", stat,
+ stat == err_status_replay_fail ? " (replay check failed)" : stat == err_status_auth_fail ? " (auth check failed)" : "");
+ return -1;
+ }
+ bytes = sbytes;
+ }
+
if (status == SWITCH_STATUS_BREAK || bytes == 0) {
if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_DATAWAIT)) {
switch_yield((rtp_session->ms_per_packet / 1000) * 750);
@@ -846,49 +906,45 @@
return 0;
}
-
- if (rtp_session->recv_msg.header.version) {
- if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_AUTOADJ)
- && switch_sockaddr_get_port(rtp_session->from_addr)) {
- char *tx_host;
- char *old_host;
- char bufa[30], bufb[30];
- tx_host = switch_get_addr(bufa, sizeof(bufa), rtp_session->from_addr);
- old_host = switch_get_addr(bufb, sizeof(bufb), rtp_session->remote_addr);
-
- if ((switch_sockaddr_get_port(rtp_session->from_addr) != rtp_session->remote_port)
- || strcmp(tx_host, old_host)) {
- const char *err;
- uint32_t old = rtp_session->remote_port;
-
- if (!switch_strlen_zero(tx_host) && switch_sockaddr_get_port(rtp_session->from_addr) > 0) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING,
- "Auto Changing port from %s:%u to %s:%u\n", old_host, old, tx_host,
- switch_sockaddr_get_port(rtp_session->from_addr));
- switch_rtp_set_remote_address(rtp_session, tx_host, switch_sockaddr_get_port(rtp_session->from_addr), &err);
- }
+
+
+ if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_AUTOADJ) && switch_sockaddr_get_port(rtp_session->from_addr)) {
+
+ char *tx_host;
+ char *old_host;
+ char bufa[30], bufb[30];
+ tx_host = switch_get_addr(bufa, sizeof(bufa), rtp_session->from_addr);
+ old_host = switch_get_addr(bufb, sizeof(bufb), rtp_session->remote_addr);
+
+ if ((switch_sockaddr_get_port(rtp_session->from_addr) != rtp_session->remote_port)
+ || strcmp(tx_host, old_host)) {
+ const char *err;
+ uint32_t old = rtp_session->remote_port;
+
+ if (!switch_strlen_zero(tx_host) && switch_sockaddr_get_port(rtp_session->from_addr) > 0) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING,
+ "Auto Changing port from %s:%u to %s:%u\n", old_host, old, tx_host,
+ switch_sockaddr_get_port(rtp_session->from_addr));
+ switch_rtp_set_remote_address(rtp_session, tx_host, switch_sockaddr_get_port(rtp_session->from_addr), &err);
}
- switch_clear_flag_locked(rtp_session, SWITCH_RTP_FLAG_AUTOADJ);
}
+ switch_clear_flag_locked(rtp_session, SWITCH_RTP_FLAG_AUTOADJ);
}
- if (rtp_session->recv_msg.header.version == 2) {
- if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_GOOGLEHACK) && rtp_session->recv_msg.header.pt == 102) {
- rtp_session->recv_msg.header.pt = 97;
- }
- rtp_session->rseq = ntohs((uint16_t) rtp_session->recv_msg.header.seq);
- rtp_session->rpayload = (switch_payload_t) rtp_session->recv_msg.header.pt;
- } else {
- if (rtp_session->recv_msg.header.version == 0 && rtp_session->ice_user) {
- handle_ice(rtp_session, (void *) &rtp_session->recv_msg, bytes);
- }
+ if (bytes && rtp_session->cng_pt && rtp_session->recv_msg.header.pt == rtp_session->cng_pt) {
+ continue;
+ }
- if (rtp_session->invalid_handler) {
- rtp_session->invalid_handler(rtp_session, rtp_session->sock, (void *) &rtp_session->recv_msg, bytes, rtp_session->from_addr);
- }
- return 0;
+
+
+ if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_GOOGLEHACK) && rtp_session->recv_msg.header.pt == 102) {
+ rtp_session->recv_msg.header.pt = 97;
}
+ rtp_session->rseq = ntohs((uint16_t) rtp_session->recv_msg.header.seq);
+ rtp_session->rpayload = (switch_payload_t) rtp_session->recv_msg.header.pt;
+
+
/* RFC2833 ... TBD try harder to honor the duration etc. */
if (!switch_test_flag(rtp_session, SWITCH_RTP_FLAG_PASS_RFC2833)
&& rtp_session->recv_msg.header.pt == rtp_session->te) {
@@ -923,9 +979,8 @@
rtp_session->dtmf_data.dc = 0;
}
}
-
+
continue;
-
}
break;
@@ -1182,12 +1237,11 @@
}
if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_VAD) &&
- rtp_session->recv_msg.header.pt == rtp_session->vad_data.read_codec->implementation->ianacode &&
- ((datalen == rtp_session->vad_data.read_codec->implementation->encoded_bytes_per_frame) ||
- (datalen > SWITCH_RTP_CNG_PAYLOAD && rtp_session->vad_data.read_codec->implementation->encoded_bytes_per_frame == 0))) {
- int16_t decoded[SWITCH_RECOMMENDED_BUFFER_SIZE / sizeof(int16_t)];
- uint32_t rate;
- uint32_t flags;
+ rtp_session->recv_msg.header.pt == rtp_session->vad_data.read_codec->implementation->ianacode) {
+
+ int16_t decoded[SWITCH_RECOMMENDED_BUFFER_SIZE / sizeof(int16_t)] = {0};
+ uint32_t rate = 0;
+ uint32_t flags = 0;
uint32_t len = sizeof(decoded);
time_t now = time(NULL);
send = 0;
@@ -1205,6 +1259,7 @@
datalen,
rtp_session->vad_data.read_codec->implementation->samples_per_second,
decoded, &len, &rate, &flags) == SWITCH_STATUS_SUCCESS) {
+
uint32_t energy = 0;
uint32_t x, y = 0, z = len / sizeof(int16_t);
@@ -1215,7 +1270,7 @@
energy += abs(decoded[y]);
y += rtp_session->vad_data.read_codec->implementation->number_of_channels;
}
-
+
if (++rtp_session->vad_data.start_count < rtp_session->vad_data.start) {
send = 1;
} else {
@@ -1274,35 +1329,23 @@
if (switch_test_flag(&rtp_session->vad_data, SWITCH_VAD_FLAG_TALKING)) {
send = 1;
- } else {
- if (switch_test_flag(&rtp_session->vad_data, SWITCH_VAD_FLAG_CNG)
- && ++rtp_session->vad_data.cng_count >= rtp_session->vad_data.cng_freq) {
- rtp_session->send_msg.header.pt = SWITCH_RTP_CNG_PAYLOAD;
- memset(rtp_session->send_msg.body, 255, SWITCH_RTP_CNG_PAYLOAD);
- /* rtp_session->send_msg.header.ts = htonl(rtp_session->vad_data.ts);
- * rtp_session->vad_data.ts++;
- */
- bytes = SWITCH_RTP_CNG_PAYLOAD;
- send = 1;
- rtp_session->vad_data.cng_count = 0;
- }
- }
-
+ }
}
} else {
return SWITCH_STATUS_GENERR;
}
}
- rtp_session->last_write_ts = ntohl(send_msg->header.ts);
- rtp_session->last_write_ssrc = ntohl(send_msg->header.ssrc);
- rtp_session->last_write_seq = rtp_session->seq;
- if (rtp_session->last_write_seq <= rtp_session->dtmf_data.out_digit_seq) {
+ if (rtp_session->last_write_seq >0 && rtp_session->last_write_seq <= rtp_session->dtmf_data.out_digit_seq) {
send = 0;
}
if (send) {
+
+ rtp_session->last_write_ts = ntohl(send_msg->header.ts);
+ rtp_session->last_write_ssrc = ntohl(send_msg->header.ssrc);
+ rtp_session->last_write_seq = rtp_session->seq;
if (rtp_session->timer.interval) {
switch_core_timer_check(&rtp_session->timer);
rtp_session->last_write_samplecount = rtp_session->timer.samplecount;
@@ -1360,7 +1403,8 @@
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't load codec?\n");
return SWITCH_STATUS_FALSE;
}
-
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Activate VAD codec %s %dms\n", codec->implementation->iananame,
+ codec->implementation->microseconds_per_frame / 1000);
rtp_session->vad_data.diff_level = 400;
rtp_session->vad_data.hangunder = 15;
rtp_session->vad_data.hangover = 40;
Modified: freeswitch/branches/mikej/sofiasip-upgrade/src/switch_xml.c
==============================================================================
--- freeswitch/branches/mikej/sofiasip-upgrade/src/switch_xml.c (original)
+++ freeswitch/branches/mikej/sofiasip-upgrade/src/switch_xml.c Mon Apr 9 12:32:10 2007
@@ -1570,7 +1570,7 @@
// Adds a child tag. off is the offset of the child tag relative to the start
// of the parent tag's character content. Returns the child tag
-switch_xml_t switch_xml_add_child(switch_xml_t xml, const char *name, switch_size_t off)
+SWITCH_DECLARE(switch_xml_t) switch_xml_add_child(switch_xml_t xml, const char *name, switch_size_t off)
{
switch_xml_t child;
@@ -1587,7 +1587,7 @@
}
// sets the character content for the given tag and returns the tag
-switch_xml_t switch_xml_set_txt(switch_xml_t xml, const char *txt)
+SWITCH_DECLARE(switch_xml_t) switch_xml_set_txt(switch_xml_t xml, const char *txt)
{
if (!xml)
return NULL;
1
0
Author: mikej
Date: Mon Apr 9 11:58:20 2007
New Revision: 4898
Modified:
freeswitch/trunk/Makefile.am
Log:
stray bits from the last commit
Modified: freeswitch/trunk/Makefile.am
==============================================================================
--- freeswitch/trunk/Makefile.am (original)
+++ freeswitch/trunk/Makefile.am Mon Apr 9 11:58:20 2007
@@ -119,7 +119,7 @@
MOD_LINK = $(BASE)/libfreeswitch.la
CLEANFILES = src/include/switch_version.h
-BUILT_SOURCES = src/include/switch_version.h ./$(DEPDIR)/modules.targets
+BUILT_SOURCES = src/include/switch_version.h
bin_PROGRAMS = freeswitch
freeswitch_SOURCES = src/switch.c
1
0