From 2f0307a08dbcbbeeea74c4e534778fc298dca2c9 Mon Sep 17 00:00:00 2001 From: gardners Date: Wed, 10 Aug 2011 15:38:59 +0200 Subject: [PATCH] Added mesh potato build script. Updated gateway operation to support mesh potato again. --- dna.c | 9 ++++++--- gateway.c | 27 +++++++++++++++++++++++++++ mpbuild | 6 ++++++ mphlr.h | 2 +- server.c | 2 +- 5 files changed, 41 insertions(+), 5 deletions(-) create mode 100755 mpbuild diff --git a/dna.c b/dna.c index 450f9c39..68169ae2 100644 --- a/dna.c +++ b/dna.c @@ -20,7 +20,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "mphlr.h" #include -char *gatewayuri=NULL; +char *gatewayspec=NULL; char *outputtemplate=NULL; char *instrumentation_file=NULL; @@ -215,7 +215,7 @@ int usage(char *complaint) { fprintf(stderr,"dna: %s\n",complaint); fprintf(stderr,"usage:\n"); - fprintf(stderr," dna [-v ...] -S [-f HLR backing file] [-I import.txt] [-N interface,...] [-G SIP gateway]\n"); + fprintf(stderr," dna [-v ...] -S [-f HLR backing file] [-I import.txt] [-N interface,...] [-G gateway specification]\n"); fprintf(stderr,"or\n"); fprintf(stderr," dna [-v ...] -f -E \n"); fprintf(stderr,"or\n"); @@ -259,6 +259,8 @@ int usage(char *complaint) fprintf(stderr," @value means read value from file called value.\n"); fprintf(stderr," -C - Request the creation of a new subscriber with the specified DID.\n"); fprintf(stderr," -t - Specify the request timeout period.\n"); + fprintf(stderr," -G - Offer gateway services. Argument specifies locations of necessary files.\n"); + fprintf(stderr," Use -G [potato|android|custom:...] to set defaults for your device type.\n"); fprintf(stderr," -N - Specify one or more interfaces for the DNA overlay mesh to operate.\n"); fprintf(stderr," Interface specifications take the form IP[:speed[:type[:port]]], and\n"); fprintf(stderr," multiple interfaces can be specified by comma separating them.\n"); @@ -298,7 +300,8 @@ int main(int argc,char **argv) overlayMode=1; break; case 'G': /* Offer gateway services */ - gatewayuri=strdup(optarg); + gatewayspec=strdup(optarg); + if(prepareGateway(gatewayspec)) return usage("Invalid gateway specification"); break; case 'E': /* Export HLR into plain text file that can be imported later */ if (!hlr_file) usage("You must specify an HLR file to export from, i.e., dna -f hlr.dat -E hlr.txt"); diff --git a/gateway.c b/gateway.c index 465dde4f..172e197c 100644 --- a/gateway.c +++ b/gateway.c @@ -20,6 +20,33 @@ typedef struct dna_gateway_extension { #define MAX_CURRENT_EXTENSIONS 1024 dna_gateway_extension extensions[MAX_CURRENT_EXTENSIONS]; +int prepareGateway(char *spec) +{ + if ((!strcasecmp(spec,"potato"))||(!strcasecmp(spec,"meshpotato"))||(!strcasecmp(spec,"mp"))||(!strcasecmp(spec,"mp1"))) { + /* Setup for mesh potato */ + asterisk_extensions_conf="/etc/asterisk/gatewayextensions.conf"; + asterisk_binary="/usr/sbin/asterisk"; + temp_file="/var/dnatemp.out"; + cmd_file="/var/dnatemp.cmd"; + shell="/bin/sh"; + return 0; + } else if ((!strcasecmp(spec,"android"))||(!strcasecmp(spec,"batphone"))) { + /* Setup for android -- this is default, so don't change anything */ + return 0; + } else if (!strncasecmp(spec,"custom:",7)) { + char a[1024],b[1024],c[1024],d[1024],e[1024]; + if (sscanf(spec,"custom:%[^:]:%[^:]:%[^:]:%[^:]:%[^:]",a,b,c,d,e)!=5) return WHY("Invalid custom gateway specification"); + asterisk_extensions_conf=strdup(a); + asterisk_binary=strdup(b); + temp_file=strdup(c); + cmd_file=strdup(d); + shell=strdup(e); + return 0; + } + else + return WHY("Invalid gateway specification"); +} + int safeSystem(char *cmd_file) { { diff --git a/mpbuild b/mpbuild new file mode 100755 index 00000000..e6d8f34e --- /dev/null +++ b/mpbuild @@ -0,0 +1,6 @@ +#!/bin/sh + +toolchain=$HOME/OpenWrt-SDK-atheros-for-Linux-i686/staging_dir/toolchain-mips_gcc4.1.2 + +$toolchain/bin/mips-linux-gcc -DHAVE_SYS_MMAN_H -DHAVE_STDINT_H -DHAVE_SYS_STAT_H -DHAVE_POLL_H -DHAVE_ARPA_INET_H -DHAVE_BZERO -o dna.meshpotato `ls -1 *.c | egrep -v "asterisk_app.c|serval.c"` +$toolchain/bin/mips-linux-strip dna.meshpotato diff --git a/mphlr.h b/mphlr.h index 74d8f02d..6e57485f 100644 --- a/mphlr.h +++ b/mphlr.h @@ -125,7 +125,7 @@ double simulatedBER; extern int serverMode; -extern char *gatewayuri; +extern char *gatewayspec; extern struct sockaddr recvaddr; extern struct in_addr client_addr; diff --git a/server.c b/server.c index 50bc342a..dca43a1d 100644 --- a/server.c +++ b/server.c @@ -420,7 +420,7 @@ int processRequest(unsigned char *packet,int len, data[dlen++]=sendDone&0xff; respondSimple(hlr_sid,ACTION_DATA,data,dlen,transaction_id,CRYPT_CIPHERED|CRYPT_SIGNED); } - if (gatewayuri&&(var_id==VAR_LOCATIONS)&&did&&strlen(did)) + if (gatewayspec&&(var_id==VAR_LOCATIONS)&&did&&strlen(did)) { /* We are a gateway, so offer connection via the gateway as well */ unsigned char data[MAX_DATA_BYTES+16];