├── nipc ├── web │ ├── config.php │ ├── images │ │ ├── basic.jpg │ │ ├── advanced.jpg │ │ ├── question.jpg │ │ ├── sim_programmer.png │ │ └── yatebts_nipc_logo.png │ ├── .htaccess │ ├── index.php │ ├── download.php │ ├── structure.php │ ├── README │ └── main.php ├── echo.au ├── welcome.au ├── redir │ ├── .htaccess │ └── index.php ├── auth │ ├── milenage │ │ ├── rijndael.h │ │ └── milenage.h │ ├── Makefile.in │ ├── nipc_auth.sh │ └── test_crypto.sh ├── custom_sms.js ├── subscribers.conf.sample ├── Makefile.in └── welcome.js ├── mbts ├── TRXManager │ ├── clockdump.sh │ └── Makefile.in ├── CLI │ ├── README.CLI │ ├── Makefile.in │ └── CLI.h ├── A53 │ ├── a53.h │ ├── Makefile.in │ ├── utils.h │ ├── gea.h │ ├── ifc.cpp │ ├── kasumi.h │ ├── gea.c │ ├── gprs_cipher.h │ ├── a5_speed.c │ ├── a5.h │ ├── gea_test.c │ ├── bits.h │ └── a53test.cpp ├── Peering │ ├── Makefile.in │ ├── NeighborTable.h │ └── NeighborTable.cpp ├── CommonLibs │ ├── A51.h │ ├── example.config │ ├── README.common │ ├── Makefile.in │ ├── sqlite3util.h │ ├── TimevalTest.cpp │ ├── F16Test.cpp │ ├── ReportingTest.cpp │ ├── VectorTest.cpp │ ├── LinkedLists.cpp │ ├── LogTest.cpp │ ├── Timeval.cpp │ ├── SocketsTest.cpp │ ├── InterthreadTest.cpp │ ├── BitVectorTest.cpp │ ├── Timeval.h │ ├── Reporting.h │ ├── MemoryLeak.h │ └── Threads.cpp ├── Control │ ├── Makefile.in │ ├── README.Control │ └── ControlCommon.cpp ├── sqlite3 │ └── Makefile.in ├── SGSNGGSN │ ├── Makefile.in │ ├── SgsnConn.h │ └── miniggsn.h ├── Globals │ ├── Makefile.in │ ├── Defines.h │ ├── Globals.h │ └── Globals.cpp ├── ctags.sh ├── apps │ └── Makefile.in ├── Connection │ ├── Makefile.in │ ├── CmdConnection.h │ ├── MediaConnection.h │ ├── LogConnection.h │ ├── GenConnection.h │ ├── LogConnection.cpp │ ├── GprsConnMap.h │ ├── CmdConnection.cpp │ ├── SigConnection.h │ ├── ConnectionMap.h │ ├── MediaConnection.cpp │ ├── GprsConnMap.cpp │ └── GenConnection.cpp ├── GPRS │ ├── Makefile.in │ ├── makefile.tests │ ├── RLC.cpp │ ├── CS4.txt │ ├── GPRSTDMA.h │ ├── GPRSExport.h │ └── MsgBase.cpp ├── GSM │ ├── AppInfTest.cpp │ ├── GSM610Tables.h │ ├── Makefile.in │ ├── GSMTAPDump.h │ ├── PowerManager.h │ ├── GSMSAPMux.cpp │ ├── PhysicalStatus.h │ ├── GSMSMSCBL3Messages.cpp │ ├── GSMSAPMux.h │ └── PowerManager.cpp ├── README ├── Makefile.tail.in ├── Makefile.head.in ├── LEGAL └── AUTHORS ├── scripts ├── nipc_validations.js ├── Makefile.in └── lib_str_util.js ├── transceiver └── Makefile.in ├── autogen.sh ├── roaming └── Makefile.in ├── README ├── config.h.in └── INSTALL /nipc/web/config.php: -------------------------------------------------------------------------------- 1 | 4 | -------------------------------------------------------------------------------- /nipc/echo.au: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yatevoip/yatebts/HEAD/nipc/echo.au -------------------------------------------------------------------------------- /nipc/welcome.au: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yatevoip/yatebts/HEAD/nipc/welcome.au -------------------------------------------------------------------------------- /mbts/TRXManager/clockdump.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | sudo tcpdump -i lo0 -A udp port 5700 3 | 4 | -------------------------------------------------------------------------------- /mbts/CLI/README.CLI: -------------------------------------------------------------------------------- 1 | This is the directory for the OpenBTS command line interface. 2 | 3 | -------------------------------------------------------------------------------- /nipc/redir/.htaccess: -------------------------------------------------------------------------------- 1 | RewriteEngine On 2 | RewriteBase /nipc 3 | RewriteRule .* index.php [L] 4 | -------------------------------------------------------------------------------- /nipc/web/images/basic.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yatevoip/yatebts/HEAD/nipc/web/images/basic.jpg -------------------------------------------------------------------------------- /nipc/web/images/advanced.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yatevoip/yatebts/HEAD/nipc/web/images/advanced.jpg -------------------------------------------------------------------------------- /nipc/web/images/question.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yatevoip/yatebts/HEAD/nipc/web/images/question.jpg -------------------------------------------------------------------------------- /nipc/web/images/sim_programmer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yatevoip/yatebts/HEAD/nipc/web/images/sim_programmer.png -------------------------------------------------------------------------------- /nipc/web/images/yatebts_nipc_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yatevoip/yatebts/HEAD/nipc/web/images/yatebts_nipc_logo.png -------------------------------------------------------------------------------- /mbts/A53/a53.h: -------------------------------------------------------------------------------- 1 | typedef unsigned char u8; 2 | typedef unsigned short u16; 3 | typedef unsigned int u32; 4 | 5 | void A53_GSM( u8 *key, int klen, int count, u8 *block1, u8 *block2 ); 6 | -------------------------------------------------------------------------------- /mbts/CLI/Makefile.in: -------------------------------------------------------------------------------- 1 | # Makefile 2 | # This file holds the make rules for the CLI lib 3 | 4 | INCLUDES := $(ALL_INCLUDES) 5 | INCFILES := ../../config.h CLI.h 6 | 7 | LIBS := libCLI.a 8 | OBJS := CLI.o 9 | -------------------------------------------------------------------------------- /mbts/Peering/Makefile.in: -------------------------------------------------------------------------------- 1 | # Makefile 2 | # This file holds the make rules for the peering lib 3 | 4 | INCLUDES := $(ALL_INCLUDES) 5 | INCFILES := ../../config.h NeighborTable.h 6 | 7 | LIBS := libPeering.a 8 | OBJS := NeighborTable.o 9 | -------------------------------------------------------------------------------- /mbts/TRXManager/Makefile.in: -------------------------------------------------------------------------------- 1 | # Makefile 2 | # This file holds the make rules for the TRX Manager lib 3 | 4 | INCLUDES := $(ALL_INCLUDES) 5 | INCFILES := ../../config.h TRXManager.h 6 | 7 | LIBS := libTRXManager.a 8 | OBJS := TRXManager.o 9 | -------------------------------------------------------------------------------- /mbts/CommonLibs/A51.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include 4 | #include 5 | 6 | typedef unsigned char byte; 7 | typedef unsigned long word; 8 | typedef word bit; 9 | 10 | void A51_GSM( byte *key, int klen, int count, byte *block1, byte *block2 ); 11 | 12 | -------------------------------------------------------------------------------- /mbts/Control/Makefile.in: -------------------------------------------------------------------------------- 1 | # Makefile 2 | # This file holds the make rules for the control lib 3 | 4 | INCLUDES := $(ALL_INCLUDES) 5 | INCFILES := ../../config.h ControlCommon.h RadioResource.h 6 | 7 | LIBS := libControl.a 8 | OBJS := ControlCommon.o DCCHDispatch.o RadioResource.o SMSCB.o 9 | -------------------------------------------------------------------------------- /mbts/A53/Makefile.in: -------------------------------------------------------------------------------- 1 | # Makefile 2 | # This file holds the make rules for the A53 lib 3 | 4 | INCLUDES := $(TOP_INCLUDES) 5 | INCFILES := ../../config.h a5.h bits.h gea.h gprs_cipher.h kasumi.h linuxlist.h utils.h 6 | 7 | LIBS := libA53.a 8 | OBJS := a5.o bits.o gea.o kasumi.o utils.o ifc.o 9 | -------------------------------------------------------------------------------- /nipc/web/.htaccess: -------------------------------------------------------------------------------- 1 | # NOTE: set in httpd.conf for the directory 2 | # where is the interface: AllowOverride All 3 | 4 | # Deny from all and allow the interface to be 5 | # accessed from 127.0.0.1 uncomment the following: 6 | 7 | #order deny,allow 8 | #allow from 127.0.0.1 9 | #deny from all 10 | -------------------------------------------------------------------------------- /mbts/sqlite3/Makefile.in: -------------------------------------------------------------------------------- 1 | # Makefile 2 | # This file holds the make rules for the sqlite3 lib 3 | 4 | INCLUDES := $(TOP_INCLUDES) 5 | INCFILES := ../../config.h sqlite3ext.h sqlite3.h 6 | 7 | PROGS:= 8 | LIBS := libsqlite3.a 9 | OBJS := sqlite3.o 10 | LOCALFLAGS := -DSQLITE_OMIT_LOAD_EXTENSION 11 | -------------------------------------------------------------------------------- /nipc/redir/index.php: -------------------------------------------------------------------------------- 1 | 6 | 7 | Redirecting... 8 | 9 | 10 | Redirecting... 11 | 12 | -------------------------------------------------------------------------------- /mbts/SGSNGGSN/Makefile.in: -------------------------------------------------------------------------------- 1 | # Makefile 2 | # This file holds the make rules for the SGSN/GGSN lib 3 | 4 | INCLUDES := $(ALL_INCLUDES) 5 | INCFILES := ../../config.h Ggsn.h GPRSL3Messages.h LLC.h miniggsn.h \ 6 | SgsnBase.h SgsnExport.h SgsnConn.h Sgsn.h 7 | 8 | LIBS := libSGSNGGSN.a 9 | OBJS := Ggsn.o GPRSL3Messages.o iputils.o LLC.o miniggsn.o SgsnCli.o Sgsn.o 10 | -------------------------------------------------------------------------------- /mbts/Globals/Makefile.in: -------------------------------------------------------------------------------- 1 | # Makefile 2 | # This file holds the make rules for the globals lib 3 | 4 | INCLUDES := $(ALL_INCLUDES) 5 | INCFILES := ../../config.h Defines.h Globals.h 6 | CFLAGS := $(CFLAGS) -DPACKAGE_REVISION='"@PACKAGE_REVISION@"' 7 | CCFLAGS:= $(CCFLAGS) -DPACKAGE_REVISION='"@PACKAGE_REVISION@"' 8 | 9 | LIBS := libGlobals.a 10 | OBJS := Globals.o 11 | -------------------------------------------------------------------------------- /mbts/CommonLibs/example.config: -------------------------------------------------------------------------------- 1 | # example file 2 | key1 value1 3 | 4 | key2 123456 5 | $static key2 6 | key3 ssdf klsdf lkdf sf 7 | $optional key3 8 | 9 | key4 10 | 11 | key5 10 11 13 15 12 | 13 | # This file is also used to test the logging system. 14 | 15 | Log.Alarms.Max 20 16 | Log.Alarms.TargetIP 127.0.0.1 17 | Log.Alarms.TargetPort 10101 18 | Log.Level NOTICE 19 | -------------------------------------------------------------------------------- /mbts/ctags.sh: -------------------------------------------------------------------------------- 1 | #DIRS="AsteriskConfig tools" 2 | DIRS="CLI CommonLibs Control GPRS GSM Globals Peering 3 | SGSNGGSN SIP SMS SR TRXManager TransceiverRAD1 apps" 4 | # sqlite3 doc pat 5 | 6 | files="" 7 | for dir in $DIRS;do 8 | files="$files $dir/*.h $dir/*.cpp" 9 | done 10 | 11 | eval echo $files 12 | # Ignore PACKED keyword 13 | eval ctags -I PACKED --extra=+fq $files 14 | 15 | -------------------------------------------------------------------------------- /mbts/apps/Makefile.in: -------------------------------------------------------------------------------- 1 | # Makefile 2 | # This file holds the make rules for the local BSS helper 3 | 4 | INCLUDES := $(ALL_INCLUDES) 5 | INCFILES := 6 | 7 | PROGS:= mbts 8 | OBJS := GetConfigurationKeys.o 9 | LOCALLIBS = $(ALL_LIBS) $(A53_LIBS) 10 | 11 | all: 12 | 13 | mbts: OpenBTS.cpp $(MKDEPS) $(INCFILES) $(OBJS) $(LIBS) $(ALL_DEPS) $(A53_DEPS) 14 | $(COMPILE) -o $@ $(LOCALFLAGS) $< $(OBJS) $(LIBS) $(LIBTHR) $(LDFLAGS) $(LOCALLIBS) 15 | -------------------------------------------------------------------------------- /mbts/Connection/Makefile.in: -------------------------------------------------------------------------------- 1 | # Makefile 2 | # This file holds the make rules for the connection lib 3 | 4 | INCLUDES := $(ALL_INCLUDES) 5 | INCFILES := ../../config.h @top_srcdir@/ybts.h CmdConnection.h ConnectionMap.h GprsConnMap.h \ 6 | GenConnection.h LogConnection.h MediaConnection.h SigConnection.h 7 | 8 | LIBS := libConnection.a 9 | OBJS := CmdConnection.o ConnectionMap.o GprsConnMap.o \ 10 | GenConnection.o LogConnection.o MediaConnection.o SigConnection.o 11 | -------------------------------------------------------------------------------- /mbts/GPRS/Makefile.in: -------------------------------------------------------------------------------- 1 | # Makefile 2 | # This file holds the make rules for the GPRS lib 3 | 4 | INCLUDES := $(ALL_INCLUDES) 5 | INCFILES := ../../config.h BSSG.h BSSGMessages.h ByteVector.h FEC.h GPRSExport.h \ 6 | GPRSInternal.h GPRSRLC.h GPRSTDMA.h MAC.h MsgBase.h MSInfo.h RLCEngine.h RLCHdr.h \ 7 | RLCMessages.h RList.h ScalarTypes.h TBF.h 8 | 9 | LIBS := libGPRS.a 10 | OBJS := BSSG.o BSSGMessages.o ByteVector.o FEC.o GPRSCLI.o MAC.o MsgBase.o MSInfo.o \ 11 | RLC.o RLCEngine.o RLCMessages.o TBF.o 12 | -------------------------------------------------------------------------------- /mbts/A53/utils.h: -------------------------------------------------------------------------------- 1 | #ifndef OSMOCORE_UTIL_H 2 | #define OSMOCORE_UTIL_H 3 | 4 | #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) 5 | 6 | #include 7 | 8 | struct value_string { 9 | unsigned int value; 10 | const char *str; 11 | }; 12 | 13 | const char *get_value_string(const struct value_string *vs, uint32_t val); 14 | int get_string_value(const struct value_string *vs, const char *str); 15 | 16 | char *osmo_ubit_dump(const uint8_t *bits, unsigned int len); 17 | char *osmo_hexdump_nospc(const unsigned char *buf, int len); 18 | 19 | int osmo_hexparse(const char *str, uint8_t *b, int max_len); 20 | 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /mbts/A53/gea.h: -------------------------------------------------------------------------------- 1 | /* 2 | * GEA3 header 3 | * 4 | * See gea.c for details 5 | */ 6 | 7 | #ifndef __GEA_H__ 8 | #define __GEA_H__ 9 | 10 | #include 11 | 12 | #include "gprs_cipher.h" 13 | 14 | /* 15 | * Performs the GEA3 algorithm (used in GPRS) 16 | * out : uint8_t [] 17 | * len : uint16_t 18 | * kc : uint64_t 19 | * iv : uint32_t 20 | * direct: 0 or 1 21 | */ 22 | 23 | int osmo_gea3(uint8_t *out, uint16_t len, uint64_t kc, uint32_t iv, enum gprs_cipher_direction direct); 24 | 25 | int osmo_gea4(uint8_t *out, uint16_t len, uint8_t * kc, uint32_t iv, enum gprs_cipher_direction direct); 26 | 27 | #endif /* __GEA_H__ */ 28 | 29 | -------------------------------------------------------------------------------- /mbts/GSM/AppInfTest.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | 6 | // Load configuration from a file. 7 | ConfigurationTable gConfig("OpenBTS.config"); 8 | 9 | int main() 10 | { 11 | GSM::L3ApplicationInformation ai(); 12 | static const char init_request_msbased_gps[4] = {'@', '\x01', 'x', '\xa8'}; // pre encoded PER for the following XER: 13 | static std::vector request_msbased_gps(init_request_msbased_gps, 14 | init_request_msbased_gps + sizeof(init_request_msbased_gps)); 15 | GSM::L3ApplicationInformation ai2(request_msbased_gps); 16 | 17 | GSM::L3Frame f(ai2); 18 | std::cout << f; 19 | 20 | return 0; 21 | } 22 | 23 | -------------------------------------------------------------------------------- /mbts/A53/ifc.cpp: -------------------------------------------------------------------------------- 1 | #include "a53.h" 2 | extern "C" { 3 | #include "a5.h" 4 | }; 5 | #include 6 | 7 | void A53_GSM( u8 *key, int klen, int count, u8 *block1, u8 *block2 ) 8 | { 9 | ubit_t dl[120]; 10 | ubit_t ul[120]; 11 | static bool first = true; 12 | if (first) { 13 | printf("public A5/3\n"); 14 | first = false; 15 | } 16 | osmo_a5_3(key, (uint32_t)count, dl, ul); 17 | for (int i = 0; i < 15; i++) { 18 | unsigned char acc1 = 0; 19 | unsigned char acc2 = 0; 20 | for (int j = 0; j < 8; j++) { 21 | acc1 |= (dl[i*8+j] & 1) << (7-j); 22 | acc2 |= (ul[i*8+j] & 1) << (7-j); 23 | } 24 | block1[i] = acc1; 25 | block2[i] = acc2; 26 | } 27 | block1[14] &= 0xC0; 28 | block2[14] &= 0xC0; 29 | } 30 | -------------------------------------------------------------------------------- /mbts/CommonLibs/README.common: -------------------------------------------------------------------------------- 1 | This directory contains common-use classes, most of which are not specific to GSM. 2 | 3 | Vector A vector class (NOT std::vector<>) that supports 4 | aliased subvectors. Not resizable. 5 | BitVector Bit-indexable vectors based on Vector. 6 | Interthread A set of C++ wrappers for pthread facilities. 7 | Sockets A set of C++ wrappers for Unix sockets. 8 | Timeval A C++ wraper for struct timeval. 9 | LinkLists Classes for simple linked lists of pointers. 10 | Logger A logging interface based on syslogd. 11 | Configuration A key-value configuration table. 12 | Regexp A C++ wrapper on stdlib regular expressions. 13 | 14 | Do "make tests" to build a series of unit tests for these classes. 15 | 16 | -------------------------------------------------------------------------------- /nipc/web/index.php: -------------------------------------------------------------------------------- 1 | 22 | -------------------------------------------------------------------------------- /mbts/Control/README.Control: -------------------------------------------------------------------------------- 1 | This directory contains control-layer functions for the access point. 2 | 3 | Most GSM L3 and VoIP messages terminate here. 4 | 5 | Everything in this directory should be in the Control namespace. 6 | 7 | Components: 8 | 9 | RadioResource -- Functions for RR procedures (paging, access grant) 10 | MobilityManagement -- Functions for MM procedures (CM service, location updating) 11 | CallControl -- Functions for CC (mobile originated, mobile terminated) 12 | SMS -- Funcitons for text messaging. 13 | 14 | 15 | 16 | SIP and RTP UDP/IP Port Assignments 17 | 18 | Component Protocol Port(s) 19 | Asterisk SIP 5060 20 | Zoiper SIP 5061 21 | AP/BTS SIP 5062 22 | Zoiper RTP 16384-16385 23 | Asterisk RTP 16386-16483 24 | AP/BTS RTP 16484-16583 25 | 26 | -------------------------------------------------------------------------------- /mbts/CommonLibs/Makefile.in: -------------------------------------------------------------------------------- 1 | # Makefile 2 | # This file holds the make rules for the common libs 3 | 4 | INCLUDES := $(TOP_INCLUDES) -I@srcdir@/../sqlite3 5 | INCFILES := ../../config.h A51.h BitVector.h Configuration.h F16.h Interthread.h \ 6 | LinkedLists.h Logger.h MemoryLeak.h Reporting.h ScalarTypes.h Sockets.h \ 7 | Threads.h Timeval.h Utils.h Vector.h sqlite3util.h 8 | 9 | ifeq ($(BUILD_TESTS),yes) 10 | PROGS:= A51Test BitVectorTest ConfigurationTest F16Test InterthreadTest LogTest \ 11 | SocketsTest TimevalTest URLEncodeTest VectorTest 12 | LOCALLIBS = $(SQL_LIBS) 13 | $(PROGS): $(SQL_DEPS) 14 | EXTRACLEAN = testSource testDestination 15 | endif 16 | LIBS := libCommonLibs.a 17 | OBJS := A51.o Configuration.o BitVector.o LinkedLists.o Logger.o Reporting.o Sockets.o \ 18 | Threads.o Timeval.o Utils.o sqlite3util.o 19 | -------------------------------------------------------------------------------- /mbts/GSM/GSM610Tables.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 Free Software Foundation, Inc. 3 | * 4 | * This software is distributed under multiple licenses; see the COPYING file in the main directory for licensing information for this specific distribuion. 5 | * 6 | * This use of this software may be subject to additional restrictions. 7 | * See the LEGAL file in the main directory for details. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | 13 | */ 14 | 15 | 16 | 17 | #ifndef GSM610TABLES_H 18 | #define GSM610TABLES_H 19 | 20 | 21 | 22 | namespace GSM { 23 | 24 | /** Table #2 from GSM 05.03 */ 25 | extern unsigned int g610BitOrder[260]; 26 | 27 | } 28 | 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /nipc/web/download.php: -------------------------------------------------------------------------------- 1 | 27 | -------------------------------------------------------------------------------- /mbts/GSM/Makefile.in: -------------------------------------------------------------------------------- 1 | # Makefile 2 | # This file holds the make rules for the GSM lib 3 | 4 | INCLUDES := $(ALL_INCLUDES) 5 | INCFILES := ../../config.h GSM610Tables.h GSMCommon.h GSMConfig.h GSML1FEC.h GSML2LAPDm.h \ 6 | GSML3CommonElements.h GSML3GPRSElements.h GSML3Message.h GSML3RRElements.h \ 7 | GSML3RRMessages.h GSMLogicalChannel.h GSMSAPMux.h GSMSMSCBL3Messages.h GSMTAPDump.h \ 8 | gsmtap.h GSMTDMA.h GSMTransfer.h PhysicalStatus.h PowerManager.h 9 | 10 | 11 | ifeq ($(BUILD_TESTS),yes) 12 | PROGS:= AppInfTest 13 | LOCALLIBS = $(SQL_LIBS) 14 | $(PROGS): $(SQL_DEPS) 15 | endif 16 | LIBS := libGSM.a 17 | OBJS := GSM610Tables.o GSMCommon.o GSMConfig.o GSML1FEC.o GSML2LAPDm.o \ 18 | GSML3CommonElements.o GSML3GPRSElements.o GSML3Message.o GSML3RRElements.o \ 19 | GSML3RRMessages.o GSMLogicalChannel.o GSMSAPMux.o GSMSMSCBL3Messages.o GSMTAPDump.o \ 20 | GSMTDMA.o GSMTransfer.o PhysicalStatus.o PowerManager.o 21 | -------------------------------------------------------------------------------- /scripts/nipc_validations.js: -------------------------------------------------------------------------------- 1 | function checkValidKi(error,field_name,field_value,section_name) 2 | { 3 | if (field_value == "*") 4 | return true; 5 | 6 | if (!checkValidHex(error,field_name,field_value,section_name)) 7 | return false; 8 | 9 | return true; 10 | } 11 | 12 | function checkValidHex(error,field_name,field_value,section_name) 13 | { 14 | var str = /^[0-9a-fA-F]{32}$/; 15 | if (!str.test(field_value)) { 16 | error.reason = "Invalid value '" + field_value + "' for '" + field_name + "' in section '" + section_name + "'. Field must be 128 bits in hex format."; 17 | error.error = 401; 18 | return false; 19 | } 20 | return true; 21 | } 22 | 23 | function checkValidIccid(error,field_name,field_value,section_name) 24 | { 25 | if (field_value.length > 20) { 26 | error.reason = "ICCID: '"+ field_value +"' can't have more than 20 characters."; 27 | error.error = 401; 28 | return false; 29 | } 30 | return true; 31 | } 32 | -------------------------------------------------------------------------------- /nipc/auth/milenage/rijndael.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------- 2 | * Example algorithms f1, f1*, f2, f3, f4, f5, f5* 3 | *------------------------------------------------------------------- 4 | * 5 | * A sample implementation of the example 3GPP authentication and 6 | * key agreement functions f1, f1*, f2, f3, f4, f5 and f5*. This is 7 | * a byte-oriented implementation of the functions, and of the block 8 | * cipher kernel function Rijndael. 9 | * 10 | * This has been coded for clarity, not necessarily for efficiency. 11 | * 12 | * The functions f2, f3, f4 and f5 share the same inputs and have 13 | * been coded together as a single function. f1, f1* and f5* are 14 | * all coded separately. 15 | * 16 | * This code is extracted from ETSI TS 135 206 17 | *-----------------------------------------------------------------*/ 18 | 19 | #ifndef RIJNDAEL_H 20 | #define RIJNDAEL_H 21 | 22 | 23 | void RijndaelKeySchedule( u8 key[16] ); 24 | void RijndaelEncrypt( u8 input[16], u8 output[16] ); 25 | 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /mbts/A53/kasumi.h: -------------------------------------------------------------------------------- 1 | /* 2 | * KASUMI header 3 | * 4 | * See kasumi.c for details 5 | */ 6 | 7 | #ifndef __KASUMI_H__ 8 | #define __KASUMI_H__ 9 | 10 | #include 11 | 12 | /* 13 | * Single iteration of KASUMI cipher 14 | */ 15 | uint64_t _kasumi(uint64_t P, uint16_t *KLi1, uint16_t *KLi2, uint16_t *KOi1, uint16_t *KOi2, uint16_t *KOi3, uint16_t *KIi1, uint16_t *KIi2, uint16_t *KIi3); 16 | 17 | /* 18 | * Implementation of the KGCORE algorithm (used by A5/3, A5/4, GEA3, GEA4 and ECSD) 19 | * 20 | * CA : uint8_t 21 | * cb : uint8_t 22 | * cc : uint32_t 23 | * cd : uint8_t 24 | * ck : uint8_t [8] 25 | * co : uint8_t [output, cl-dependent] 26 | * cl : uint16_t 27 | */ 28 | void _kasumi_kgcore(uint8_t CA, uint8_t cb, uint32_t cc, uint8_t cd, const uint8_t *ck, uint8_t *co, uint16_t cl); 29 | 30 | /*! \brief Expand key into set of subkeys 31 | * \param[in] key (128 bits) as array of bytes 32 | * \param[out] arrays of round-specific subkeys - see TS 135 202 for details 33 | */ 34 | void _kasumi_key_expand(const uint8_t *key, uint16_t *KLi1, uint16_t *KLi2, uint16_t *KOi1, uint16_t *KOi2, uint16_t *KOi3, uint16_t *KIi1, uint16_t *KIi2, uint16_t *KIi3); 35 | 36 | #endif /* __KASUMI_H__ */ 37 | -------------------------------------------------------------------------------- /mbts/GSM/GSMTAPDump.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008, 2009 Free Software Foundation, Inc. 3 | * This software is distributed under multiple licenses; see the COPYING file in the main directory for licensing information for this specific distribuion. 4 | * 5 | This program is distributed in the hope that it will be useful, 6 | but WITHOUT ANY WARRANTY; without even the implied warranty of 7 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 8 | 9 | * 10 | * This use of this software may be subject to additional restrictions. 11 | * See the LEGAL file in the main directory for details. 12 | 13 | */ 14 | 15 | 16 | 17 | #ifndef GSMTAPDUMP_H 18 | #define GSMTAPDUMP_H 19 | 20 | #include "gsmtap.h" 21 | #include "GSMCommon.h" 22 | #include "GSMTransfer.h" 23 | 24 | 25 | void gWriteGSMTAP(unsigned ARFCN, unsigned TS, unsigned FN, 26 | GSM::TypeAndOffset to, bool is_sacch, bool ul_dln, 27 | const BitVector& frame, 28 | unsigned wType = GSMTAP_TYPE_UM); 29 | 30 | 31 | void gWriteGSMTAP(unsigned ARFCN, unsigned TS, unsigned FN, 32 | GSM::TypeAndOffset to, bool is_sacch, bool ul_dln, 33 | const char* data, unsigned int len, 34 | unsigned wType = GSMTAP_TYPE_UM, unsigned int defSCN = 255); 35 | 36 | #endif 37 | 38 | // vim: ts=4 sw=4 39 | -------------------------------------------------------------------------------- /mbts/README: -------------------------------------------------------------------------------- 1 | Welcome to the MBTS section of Yate-BTS, a derivation of OpenBTS. 2 | (Note: OpenBTS is a trademark of Range Networks, Inc., not affiliated with 3 | the developers or supporters of MBTS.) 4 | 5 | 6 | For additional information and support, refer to http://yatebts.com. 7 | 8 | 9 | These are the directories: 10 | 11 | CommonLib Common-use libraries, mostly C++ wrappers for basic facilities. 12 | Control Control-layer functions for the protocols of GSM 04.08 and SIP. 13 | GSM The GSM stack. 14 | RRLP Radio Resource Location Protocol 15 | TRXManager The interface between the GSM stack and the radio. 16 | Transceiver The software transceiver and specific installation tests. 17 | apps OpenBTS application binaries. 18 | 19 | 20 | 21 | By default, OpenBTS assumes the following UDP port assignments: 22 | 23 | 5060 -- Yate SIP interface 24 | XXXX -- Yate-BTS/MBTS socket interface 25 | 5700-range -- OpenBTS-transceiver interface 26 | 27 | These can be controlled in the CONFIG table in /etc/OpenBTS.db. 28 | 29 | Standrd paths: 30 | /OpenBTS -- Binary installation and authorization keys. 31 | /etc/OpenBTS -- Configuration databases. 32 | /var/run/OpenBTS -- Real-time reporting databases. 33 | 34 | The script apps/setUpFiles.sh will create these directories and install the 35 | correct files in them. 36 | 37 | 38 | -------------------------------------------------------------------------------- /nipc/web/structure.php: -------------------------------------------------------------------------------- 1 | needed to know where to return for Cancel button or Return button 32 | // besides method listed here, all methods starting with add_,edit_,delete_ are not saved 33 | $exceptions_to_save = array(); 34 | 35 | ?> 36 | -------------------------------------------------------------------------------- /transceiver/Makefile.in: -------------------------------------------------------------------------------- 1 | # Makefile 2 | # This file holds the make rules for the transceiver 3 | 4 | 5 | DEBUG := 6 | 7 | CXX := @CXX@ -Wall 8 | AR := ar 9 | DEFS := 10 | INCLUDES := -I@top_srcdir@ -I.. -I@srcdir@ 11 | CCFLAGS:= @YATE_INC@ 12 | CFLAGS := $(subst -fno-check-new,,$(CCFLAGS)) 13 | LDFLAGS:= @LDFLAGS@ 14 | YATELIBS:= @YATE_LIB@ 15 | INCFILES := transceiver.h 16 | 17 | LOCALLIBS := 18 | LIBS := libtransceiver.a 19 | OBJS := transceiver.o sigproc.o gsmutil.o 20 | PROGS := 21 | 22 | COMPILE = $(CXX) $(DEFS) $(DEBUG) $(INCLUDES) $(CFLAGS) 23 | LINK = $(CXX) $(LDFLAGS) 24 | 25 | prefix = @prefix@ 26 | exec_prefix = @exec_prefix@ 27 | 28 | # include optional local make rules 29 | -include YateLocal.mak 30 | 31 | .PHONY: all debug ddebug xdebug 32 | all: $(LIBS) $(PROGS) 33 | 34 | debug: 35 | $(MAKE) all DEBUG=-g3 MODSTRIP= 36 | 37 | ddebug: 38 | $(MAKE) all DEBUG='-g3 -DDEBUG' MODSTRIP= 39 | 40 | xdebug: 41 | $(MAKE) all DEBUG='-g3 -DXDEBUG' MODSTRIP= 42 | 43 | .PHONY: strip 44 | strip: all 45 | strip --strip-debug --discard-locals $(PROGS) 46 | 47 | .PHONY: clean 48 | clean: 49 | @-$(RM) $(PROGS) $(LIBS) $(OBJS) $(EXTRACLEAN) core 2>/dev/null 50 | 51 | %.o: @srcdir@/%.cpp $(INCFILES) 52 | $(COMPILE) -c $< 53 | 54 | Makefile: @srcdir@/Makefile.in ../config.status 55 | cd .. && ./config.status 56 | 57 | libtransceiver.a: $(OBJS) 58 | $(AR) rcs $@ $^ 59 | -------------------------------------------------------------------------------- /mbts/CommonLibs/sqlite3util.h: -------------------------------------------------------------------------------- 1 | #ifndef SQLITE3UTIL_H 2 | #define SQLITE3UTIL_H 3 | 4 | #include 5 | 6 | // (pat) Dont put statics in .h files - they generate a zillion g++ error messages. 7 | extern const char *enableWAL; 8 | //static const char* enableWAL = { 9 | // "PRAGMA journal_mode=WAL" 10 | //}; 11 | 12 | int sqlite3_prepare_statement(sqlite3* DB, sqlite3_stmt **stmt, const char* query, unsigned retries = 5); 13 | 14 | int sqlite3_run_query(sqlite3* DB, sqlite3_stmt *stmt, unsigned retries = 5); 15 | 16 | bool sqlite3_single_lookup(sqlite3* DB, const char *tableName, 17 | const char* keyName, const char* keyData, 18 | const char* valueName, unsigned &valueData, unsigned retries = 5); 19 | 20 | bool sqlite3_single_lookup(sqlite3* DB, const char* tableName, 21 | const char* keyName, const char* keyData, 22 | const char* valueName, char* &valueData, unsigned retries = 5); 23 | 24 | // This function returns an allocated string that must be free'd by the caller. 25 | bool sqlite3_single_lookup(sqlite3* DB, const char* tableName, 26 | const char* keyName, unsigned keyData, 27 | const char* valueName, char* &valueData, unsigned retries = 5); 28 | 29 | bool sqlite3_exists(sqlite3* DB, const char* tableName, 30 | const char* keyName, const char* keyData, unsigned retries = 5); 31 | 32 | /** Run a query, ignoring the result; return true on success. */ 33 | bool sqlite3_command(sqlite3* DB, const char* query, unsigned retries = 5); 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /mbts/Connection/CmdConnection.h: -------------------------------------------------------------------------------- 1 | /** 2 | * CmdConnection.h 3 | * This file is part of the Yate-BTS Project http://www.yatebts.com 4 | * 5 | * Declaration for Command socket connection 6 | * 7 | * Yet Another Telephony Engine - Base Transceiver Station 8 | * Copyright (C) 2013-2023 Null Team Impex SRL 9 | * Copyright (C) 2014 Legba, Inc 10 | * 11 | * This software is distributed under multiple licenses; 12 | * see the COPYING file in the main directory for licensing 13 | * information for this specific distribution. 14 | * 15 | * This use of this software may be subject to additional restrictions. 16 | * See the LEGAL file in the main directory for details. 17 | * 18 | * This program is distributed in the hope that it will be useful, 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 21 | */ 22 | 23 | #ifndef CMDCONNECTION_H 24 | #define CMDCONNECTION_H 25 | 26 | #include "GenConnection.h" 27 | 28 | namespace Connection { 29 | 30 | class CmdConnection : public GenConnection 31 | { 32 | public: 33 | inline CmdConnection(int fileDesc = -1) 34 | : GenConnection(fileDesc,1024) 35 | { } 36 | bool write(const char* text, size_t len = 0); 37 | char* read(); 38 | private: 39 | virtual void process(const unsigned char* data, size_t len); 40 | }; 41 | 42 | }; // namespace Connection 43 | 44 | #endif /* CMDCONNECTION_H */ 45 | 46 | /* vi: set ts=8 sw=4 sts=4 noet: */ 47 | -------------------------------------------------------------------------------- /autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # autogen.sh 4 | # This file is part of the Yate-BTS Project http://www.yatebts.com 5 | # 6 | # Yet Another Telephony Engine - Base Transceiver Station 7 | # Copyright (C) 2013-2023 Null Team Impex SRL 8 | # 9 | # This software is distributed under multiple licenses; 10 | # see the COPYING file in the main directory for licensing 11 | # information for this specific distribution. 12 | # 13 | # This use of this software may be subject to additional restrictions. 14 | # See the LEGAL file in the main directory for details. 15 | # 16 | # This program is distributed in the hope that it will be useful, 17 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 19 | 20 | 21 | # Run this to generate a new configure script 22 | 23 | if [ -z `which which 2>/dev/null` ]; then 24 | echo "Please install the required 'which' utility." >&2 25 | exit 1 26 | fi 27 | 28 | ac=`which autoconf 2>/dev/null` 29 | test -z "$ac" && ac=/usr/local/gnu-autotools/bin/autoconf 30 | if [ -x "$ac" ]; then 31 | "$ac" || exit $? 32 | case "x$1" in 33 | x--silent) 34 | ;; 35 | x--configure) 36 | shift 37 | ./configure "$@" || exit $? 38 | echo "Finished! Now run make." 39 | ;; 40 | *) 41 | echo "Finished! Now run configure. If in doubt run ./configure --help" 42 | ;; 43 | esac 44 | else 45 | echo "Please install Gnu autoconf to build from CVS." >&2 46 | exit 1 47 | fi 48 | -------------------------------------------------------------------------------- /nipc/custom_sms.js: -------------------------------------------------------------------------------- 1 | /** 2 | * custom_sms.js 3 | * This file is part of the Yate-BTS Project http://www.yatebts.com 4 | * 5 | * Copyright (C) 2015-2023 Null Team 6 | * 7 | * This software is distributed under multiple licenses; 8 | * see the COPYING file in the main directory for licensing 9 | * information for this specific distribution. 10 | * 11 | * This use of this software may be subject to additional restrictions. 12 | * See the LEGAL file in the main directory for details. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 17 | */ 18 | 19 | /* 20 | * Custom SMS 21 | * To use it put in javascript.conf: 22 | * 23 | * [scripts] 24 | * custom_sms=custom_sms.js 25 | */ 26 | 27 | function onControl(msg) 28 | { 29 | if (!msg.called && (!msg.text || !msg.rpdu)) { 30 | msg.retValue("Missing IMSI or Message. The SMS will not be sent."); 31 | msg["operation-status"] = false; 32 | return true; 33 | } 34 | 35 | var m = new Message("msg.execute"); 36 | m.caller = "12345"; 37 | m.called = msg.called; 38 | m["sms.caller"] = "12345"; 39 | if (msg.text) 40 | m.text = msg.text; 41 | else if (msg.rpdu) 42 | m.rpdu = msg.rpdu; 43 | 44 | m.callto = "ybts/IMSI"+msg.called; 45 | msg["operation-status"] = m.dispatch(); 46 | return true; 47 | } 48 | 49 | Engine.debugName("custom_sms"); 50 | Message.install(onControl,"chan.control",80,"component","custom_sms"); 51 | -------------------------------------------------------------------------------- /mbts/CommonLibs/TimevalTest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 Free Software Foundation, Inc. 3 | * 4 | * 5 | * This software is distributed under the terms of the GNU Affero Public License. 6 | * See the COPYING file in the main directory for details. 7 | * 8 | * This use of this software may be subject to additional restrictions. 9 | * See the LEGAL file in the main directory for details. 10 | 11 | This program is free software: you can redistribute it and/or modify 12 | it under the terms of the GNU Affero General Public License as published by 13 | the Free Software Foundation, either version 3 of the License, or 14 | (at your option) any later version. 15 | 16 | This program is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | GNU Affero General Public License for more details. 20 | 21 | You should have received a copy of the GNU Affero General Public License 22 | along with this program. If not, see . 23 | 24 | */ 25 | 26 | 27 | 28 | 29 | #include "Timeval.h" 30 | #include 31 | 32 | using namespace std; 33 | 34 | int main(int argc, char *argv[]) 35 | { 36 | 37 | Timeval then(10000); 38 | cout << then.elapsed() << endl; 39 | 40 | while (!then.passed()) { 41 | cout << "now: " << Timeval() << " then: " << then << " remaining: " << then.remaining() << endl; 42 | usleep(500000); 43 | } 44 | cout << "now: " << Timeval() << " then: " << then << " remaining: " << then.remaining() << endl; 45 | } 46 | -------------------------------------------------------------------------------- /mbts/Connection/MediaConnection.h: -------------------------------------------------------------------------------- 1 | /** 2 | * MediaConnection.h 3 | * This file is part of the Yate-BTS Project http://www.yatebts.com 4 | * 5 | * Declaration for Media socket connection 6 | * 7 | * Yet Another Telephony Engine - Base Transceiver Station 8 | * Copyright (C) 2013-2023 Null Team Impex SRL 9 | * Copyright (C) 2014 Legba, Inc 10 | * 11 | * This software is distributed under multiple licenses; 12 | * see the COPYING file in the main directory for licensing 13 | * information for this specific distribution. 14 | * 15 | * This use of this software may be subject to additional restrictions. 16 | * See the LEGAL file in the main directory for details. 17 | * 18 | * This program is distributed in the hope that it will be useful, 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 21 | */ 22 | 23 | #ifndef MEDIACONNECTION_H 24 | #define MEDIACONNECTION_H 25 | 26 | #include "GenConnection.h" 27 | 28 | namespace Connection { 29 | 30 | class MediaConnection : public GenConnection 31 | { 32 | public: 33 | inline MediaConnection(int fileDesc = -1) 34 | : GenConnection(fileDesc,1508) 35 | { } 36 | bool send(unsigned int id, const void* data, size_t len, const void* data2 = 0, size_t len2 = 0); 37 | private: 38 | virtual void process(const unsigned char* data, size_t len); 39 | void process(unsigned int id, const unsigned char* data, size_t len); 40 | }; 41 | 42 | }; // namespace Connection 43 | 44 | #endif /* MEDIACONNECTION_H */ 45 | 46 | /* vi: set ts=8 sw=4 sts=4 noet: */ 47 | -------------------------------------------------------------------------------- /scripts/Makefile.in: -------------------------------------------------------------------------------- 1 | # Makefile 2 | # This file holds the make rules the Yate BTS module and associated executables 3 | 4 | # override DESTDIR at install time to prefix the install directory 5 | DESTDIR := 6 | 7 | SCRIPTS := lib_str_util.js 8 | SOUNDS := 9 | CONFIG := 10 | 11 | prefix = @prefix@ 12 | exec_prefix = @exec_prefix@ 13 | datarootdir = @datarootdir@ 14 | 15 | datadir:= @datadir@ 16 | confdir:= @YATE_CFG@ 17 | moddir := @YATE_MOD@ 18 | scrdir := @YATE_SCR@ 19 | shrdir := @YATE_SHR@ 20 | 21 | # include optional local make rules 22 | -include YateLocal.mak 23 | 24 | .PHONY: all 25 | all: 26 | 27 | install: all 28 | @mkdir -p "$(DESTDIR)$(confdir)/" && \ 29 | lst="`ls -1 @srcdir@/*.conf @srcdir@/*.sample @srcdir@/*.default @srcdir@/*.sql 2>/dev/null | sed 's/\.sample//g; s/\.default//g; s/[^ ]*\*\.[^ ]*//g' | sort | uniq`" ; \ 30 | for s in $$lst $(CONFIG); do \ 31 | d="$(DESTDIR)$(confdir)/`echo $$s | sed 's,.*/,,'`" ; \ 32 | if [ -f "$$d" ]; then \ 33 | echo "Not overwriting existing $$d" ; \ 34 | else \ 35 | if [ ! -f "$$s" ]; then \ 36 | test -f "$$s.default" && s="$$s.default" ; \ 37 | test -f "$$s.sample" && s="$$s.sample" ; \ 38 | fi ; \ 39 | install -m 0644 "$$s" "$$d" ; \ 40 | fi ; \ 41 | done 42 | @mkdir -p "$(DESTDIR)$(scrdir)/" && \ 43 | for i in $(SCRIPTS) ; do \ 44 | install -m 0644 @srcdir@/$$i "$(DESTDIR)$(scrdir)/" ; \ 45 | done 46 | 47 | uninstall: 48 | @-for i in $(SCRIPTS) ; do \ 49 | rm -f "$(DESTDIR)$(scrdir)/$$i" ; \ 50 | done 51 | @-rmdir "$(DESTDIR)$(scrdir)" 52 | @-rmdir "$(DESTDIR)$(shrdir)" 53 | -------------------------------------------------------------------------------- /roaming/Makefile.in: -------------------------------------------------------------------------------- 1 | # Makefile 2 | # This file holds the make rules the Yate BTS module and associated executables 3 | 4 | # override DESTDIR at install time to prefix the install directory 5 | DESTDIR := 6 | 7 | SCRIPTS := roaming.js handover.js 8 | SOUNDS := 9 | CONFIG := 10 | 11 | prefix = @prefix@ 12 | exec_prefix = @exec_prefix@ 13 | datarootdir = @datarootdir@ 14 | 15 | datadir:= @datadir@ 16 | confdir:= @YATE_CFG@ 17 | moddir := @YATE_MOD@ 18 | scrdir := @YATE_SCR@ 19 | shrdir := @YATE_SHR@ 20 | 21 | # include optional local make rules 22 | -include YateLocal.mak 23 | 24 | .PHONY: all 25 | all: 26 | 27 | install: all 28 | @mkdir -p "$(DESTDIR)$(confdir)/" && \ 29 | lst="`ls -1 @srcdir@/*.conf @srcdir@/*.sample @srcdir@/*.default @srcdir@/*.sql 2>/dev/null | sed 's/\.sample//g; s/\.default//g; s/[^ ]*\*\.[^ ]*//g' | sort | uniq`" ; \ 30 | for s in $$lst $(CONFIG); do \ 31 | d="$(DESTDIR)$(confdir)/`echo $$s | sed 's,.*/,,'`" ; \ 32 | if [ -f "$$d" ]; then \ 33 | echo "Not overwriting existing $$d" ; \ 34 | else \ 35 | if [ ! -f "$$s" ]; then \ 36 | test -f "$$s.default" && s="$$s.default" ; \ 37 | test -f "$$s.sample" && s="$$s.sample" ; \ 38 | fi ; \ 39 | install -m 0644 "$$s" "$$d" ; \ 40 | fi ; \ 41 | done 42 | @mkdir -p "$(DESTDIR)$(scrdir)/" && \ 43 | for i in $(SCRIPTS) ; do \ 44 | install -m 0644 @srcdir@/$$i "$(DESTDIR)$(scrdir)/" ; \ 45 | done 46 | 47 | uninstall: 48 | @-for i in $(SCRIPTS) ; do \ 49 | rm -f "$(DESTDIR)$(scrdir)/$$i" ; \ 50 | done 51 | @-rmdir "$(DESTDIR)$(scrdir)" 52 | @-rmdir "$(DESTDIR)$(shrdir)" 53 | -------------------------------------------------------------------------------- /mbts/A53/gea.c: -------------------------------------------------------------------------------- 1 | /* 2 | * gea.c 3 | * 4 | * Full reimplementation of GEA3 5 | * 6 | * Copyright (C) 2013 Max 7 | * 8 | * All Rights Reserved 9 | * 10 | * This program is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 2 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License along 21 | * with this program; if not, write to the Free Software Foundation, Inc., 22 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 23 | */ 24 | #include 25 | 26 | #include "bits.h" 27 | #include "gprs_cipher.h" 28 | #include "kasumi.h" 29 | 30 | 31 | int osmo_gea4(uint8_t *out, uint16_t len, uint8_t * kc, uint32_t iv, enum gprs_cipher_direction direction) { 32 | _kasumi_kgcore(0xFF, 0, iv, direction, kc, out, len * 8); 33 | 34 | return 0; 35 | } 36 | 37 | int osmo_gea3(uint8_t *out, uint16_t len, uint64_t kc, uint32_t iv, enum gprs_cipher_direction direction) { 38 | uint8_t ck[16]; 39 | osmo_64pack2pbit(kc, ck); 40 | osmo_64pack2pbit(kc, ck + 8); 41 | 42 | // _kasumi_kgcore(0xFF, 0, iv, direction, ck, out, len * 8); 43 | 44 | return osmo_gea4(out, len, ck, iv, direction); 45 | } 46 | -------------------------------------------------------------------------------- /mbts/Peering/NeighborTable.h: -------------------------------------------------------------------------------- 1 | /**@ The global table of neighboring BTS units. */ 2 | /* 3 | * Copright 2011 Range Networks, Inc. 4 | * All rights reserved. 5 | */ 6 | 7 | 8 | #ifndef NEIGHBORTABLE_H 9 | #define NEIGHBORTABLE_H 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | 16 | namespace Peering { 17 | 18 | class NeighborTable { 19 | 20 | struct Neighbor { 21 | Neighbor(int c0, int bsic, const char* id) : C0(c0), BSIC(bsic), CELL_ID(id) { } 22 | unsigned C0; 23 | unsigned BSIC; 24 | std::string CELL_ID; 25 | }; 26 | 27 | private: 28 | std::vector mNeighbors; 29 | std::vector mARFCNList; ///< current ARFCN list 30 | int mBCCSet; ///< set of current BCCs 31 | mutable Mutex mLock; 32 | 33 | public: 34 | NeighborTable() : mBCCSet(0) {} 35 | 36 | /** Populate the list from a descriptor string */ 37 | bool setNeighbors(const char* list); 38 | 39 | /** Returns the cell ID for a measurement. */ 40 | std::string getCellID(unsigned BCCH_FREQ_NCELL, unsigned BSIC); 41 | 42 | /** Return the ARFCN given its position in the BCCH channel list (GSM 04.08 10.5.2.20). */ 43 | int getARFCN(unsigned BCCH_FREQ_NCELL); 44 | 45 | /** 46 | Get the neighbor cell ARFCNs as a vector. 47 | mARFCNList is updated by every call to add(). 48 | This returns a copy to be thread-safe. 49 | */ 50 | std::vector ARFCNList() const { ScopedLock lock(mLock); return mARFCNList; } 51 | 52 | /** Get the neighbor cell BCC set as a bitmask. */ 53 | int BCCSet() const { return mBCCSet; } 54 | }; 55 | 56 | } //namespace 57 | 58 | extern Peering::NeighborTable gNeighborTable; 59 | 60 | #endif 61 | 62 | -------------------------------------------------------------------------------- /nipc/auth/Makefile.in: -------------------------------------------------------------------------------- 1 | # Makefile 2 | # This file holds the make rules the Yate BTS module and associated executables 3 | 4 | # override DESTDIR at install time to prefix the install directory 5 | DESTDIR := 6 | 7 | # override DEBUG at compile time to enable full debug or remove it all 8 | DEBUG := 9 | 10 | CC := @CC@ -Wall 11 | CFLAGS := @CFLAGS@ 12 | INCLUDES := -I@top_srcdir@ 13 | 14 | prefix = @prefix@ 15 | exec_prefix = @exec_prefix@ 16 | datarootdir = @datarootdir@ 17 | 18 | datadir:= @datadir@ 19 | scrdir := @YATE_SCR@ 20 | shrdir := @YATE_SHR@ 21 | 22 | SCRIPTS := nipc_auth.sh 23 | PROGS := do_nipc_comp128 do_nipc_milenage 24 | CCOMPILE = $(CC) $(DEFS) $(DEBUG) $(INCLUDES) $(CFLAGS) 25 | 26 | MILENAGE:= @srcdir@/milenage/main.c \ 27 | @srcdir@/milenage/milenage.c @srcdir@/milenage/rijndael.c 28 | MIL_INC := @srcdir@/milenage/milenage.h @srcdir@/milenage/rijndael.h 29 | 30 | # include optional local make rules 31 | -include YateLocal.mak 32 | 33 | .PHONY: all clean 34 | all: $(PROGS) 35 | 36 | install: all 37 | @mkdir -p "$(DESTDIR)$(scrdir)/" && \ 38 | for i in $(SCRIPTS) ; do \ 39 | @INSTALL_D@ @srcdir@/$$i "$(DESTDIR)$(scrdir)/" ; \ 40 | done ; \ 41 | for i in $(PROGS) ; do \ 42 | @INSTALL_D@ "$$i" "$(DESTDIR)$(scrdir)/" ; \ 43 | done 44 | 45 | uninstall: 46 | @-for i in $(SCRIPTS) $(PROGS) ; do \ 47 | rm -f "$(DESTDIR)$(scrdir)/$$i" ; \ 48 | done 49 | @-rmdir "$(DESTDIR)$(scrdir)" 50 | @-rmdir "$(DESTDIR)$(shrdir)" 51 | 52 | clean: 53 | @-$(RM) $(PROGS) 2>/dev/null 54 | 55 | do_nipc_comp128: @srcdir@/do_comp128.c 56 | $(CCOMPILE) -o $@ $< 57 | 58 | do_nipc_milenage: $(MILENAGE) $(MIL_INC) 59 | $(CCOMPILE) -o $@ $(MILENAGE) 60 | -------------------------------------------------------------------------------- /nipc/subscribers.conf.sample: -------------------------------------------------------------------------------- 1 | ; !!! NOTE !!! 2 | ; This file is used when YateBTS is in NiPC (Network in a PC) mode 3 | ; File generated by the YateBTS LMI interface 4 | 5 | [general] 6 | ; Your Country code (where YateBTS is installed) 7 | ; Ex: 1 for US, 44 for UK 8 | ;country_code= 9 | 10 | ; Subscribers are accepted by either matching the IMSI against this configured 11 | ; regular expression or by setting subscribers individually 12 | ; Note! If a regular expression is used, 2G/3G authentication cannot be used. 13 | ; Ex: regexp=^001 14 | ;regexp= 15 | 16 | ; Resource for the emergency calls gateway 17 | ; If not set any emergency calls will be delivered to the outbound gateway 18 | ; It is also possible to specify a short or international number (possibly MSISDN) 19 | ; Ex: gw_sos=sip/sip:sos@emergency.gw 20 | ; Ex: gw_sos=111 21 | ; Ex: gw_sos=+10744341111 22 | ;gw_sos= 23 | 24 | 25 | ; you have to put subscriber IMSI as a category and the subscriber parameters 26 | ; as keys 27 | 28 | ;[001990010001014] 29 | ; Official phone number. Should include configured country code 30 | ; Ex: msisdn=10744341111 31 | 32 | ; Whether this subscriber is allowed to use the service 33 | ; Allowed values: on, off 34 | ; Ex: active=off 35 | 36 | ; Card secret. Set or generated when SIMs are written 37 | ; Ex:ki=00112233445566778899aabbccddeeff 38 | 39 | ; Operator secret. 40 | ; Allowed values: empty for 2G IMSIs, 00000000000000000000000000000000 for 3G IMSIs. 41 | ; Ex: op=00000000000000000000000000000000 42 | 43 | ; SIM type 44 | ; Allowed values: 2G, 3G 45 | ; Ex: imsi_type=3G 46 | 47 | ; Short number subscribers can use to dial each other. Can be empty or not set 48 | ; Ex:short_number=111 49 | -------------------------------------------------------------------------------- /mbts/CommonLibs/F16Test.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 Free Software Foundation, Inc. 3 | * 4 | * 5 | * This software is distributed under the terms of the GNU Affero Public License. 6 | * See the COPYING file in the main directory for details. 7 | * 8 | * This use of this software may be subject to additional restrictions. 9 | * See the LEGAL file in the main directory for details. 10 | 11 | This program is free software: you can redistribute it and/or modify 12 | it under the terms of the GNU Affero General Public License as published by 13 | the Free Software Foundation, either version 3 of the License, or 14 | (at your option) any later version. 15 | 16 | This program is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | GNU Affero General Public License for more details. 20 | 21 | You should have received a copy of the GNU Affero General Public License 22 | along with this program. If not, see . 23 | 24 | */ 25 | 26 | #include "F16.h" 27 | 28 | 29 | #include 30 | 31 | using namespace std; 32 | 33 | int main(int argc, char **argv) 34 | { 35 | 36 | F16 a = 2.5; 37 | F16 b = 1.5; 38 | F16 c = 2.5 * 1.5; 39 | F16 d = c + a; 40 | F16 e = 10; 41 | cout << a << ' ' << b << ' ' << c << ' ' << d << ' ' << e << endl; 42 | 43 | a *= 3; 44 | b *= 0.3; 45 | c *= e; 46 | cout << a << ' ' << b << ' ' << c << ' ' << d << endl; 47 | 48 | a /= 3; 49 | b /= 0.3; 50 | c = d * 0.05; 51 | cout << a << ' ' << b << ' ' << c << ' ' << d << endl; 52 | 53 | F16 f = a/d; 54 | cout << f << ' ' << f+0.5 << endl; 55 | } 56 | -------------------------------------------------------------------------------- /nipc/auth/milenage/milenage.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------- 2 | * Example algorithms f1, f1*, f2, f3, f4, f5, f5* 3 | *------------------------------------------------------------------- 4 | * 5 | * A sample implementation of the example 3GPP authentication and 6 | * key agreement functions f1, f1*, f2, f3, f4, f5 and f5*. This is 7 | * a byte-oriented implementation of the functions, and of the block 8 | * cipher kernel function Rijndael. 9 | * 10 | * This has been coded for clarity, not necessarily for efficiency. 11 | * 12 | * The functions f2, f3, f4 and f5 share the same inputs and have 13 | * been coded together as a single function. f1, f1* and f5* are 14 | * all coded separately. 15 | * 16 | * This code is extracted from ETSI TS 135 206 17 | *-----------------------------------------------------------------*/ 18 | 19 | #ifndef MILENAGE_H 20 | #define MILENAGE_H 21 | 22 | typedef unsigned char u8; 23 | 24 | 25 | void f1Opc ( u8 k[16], u8 rand[16], u8 sqn[6], u8 amf[2], 26 | u8 mac_a[8], u8 op[16], u8 opc ); 27 | void f2345Opc ( u8 k[16], u8 rand[16], 28 | u8 res[8], u8 ck[16], u8 ik[16], u8 ak[6], u8 op[16], u8 opc ); 29 | void f1starOpc( u8 k[16], u8 rand[16], u8 sqn[6], u8 amf[2], 30 | u8 mac_s[8], u8 op[16], u8 opc ); 31 | void f5starOpc( u8 k[16], u8 rand[16], 32 | u8 ak[6], u8 op[16], u8 opc ); 33 | void ComputeOPc( u8 op_c[16], u8 op[16] ); 34 | 35 | #define f1(k,rand,sqn,amf,mac_a,op) f1Opc(k,rand,sqn,amf,mac_a,op,0) 36 | #define f2345(k,rand,res,ck,ik,ak,op) f2345Opc(k,rand,res,ck,ik,ak,op,0) 37 | #define f1star(k,rand,sqn,amf,mac_s,op) f1starOpc(k,rand,sqn,amf,mac_s,op,0) 38 | #define f5star(k,rand,ak,op) f5starOpc(k,rand,ak,op,0) 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /mbts/A53/gprs_cipher.h: -------------------------------------------------------------------------------- 1 | #ifndef _GPRS_CIPHER_H 2 | #define _GPRS_CIPHER_H 3 | 4 | #include "linuxlist.h" 5 | 6 | #define GSM0464_CIPH_MAX_BLOCK 1523 7 | 8 | enum gprs_ciph_algo { 9 | GPRS_ALGO_GEA0, 10 | GPRS_ALGO_GEA1, 11 | GPRS_ALGO_GEA2, 12 | GPRS_ALGO_GEA3, 13 | GPRS_ALGO_GEA4, 14 | _GPRS_ALGO_NUM 15 | }; 16 | 17 | enum gprs_cipher_direction { 18 | GPRS_CIPH_MS2SGSN, 19 | GPRS_CIPH_SGSN2MS, 20 | }; 21 | 22 | /* An implementation of a GPRS cipher */ 23 | struct gprs_cipher_impl { 24 | struct llist_head list; 25 | enum gprs_ciph_algo algo; 26 | const char *name; 27 | unsigned int priority; 28 | 29 | /* As specified in 04.64 Annex A. Uses Kc, IV and direction 30 | * to generate the 1523 bytes cipher stream that need to be 31 | * XORed wit the plaintext for encrypt / ciphertext for decrypt */ 32 | int (*run)(uint8_t *out, uint16_t len, uint64_t kc, uint32_t iv, 33 | enum gprs_cipher_direction direction); 34 | }; 35 | 36 | /* register a cipher with the core (from a plugin) */ 37 | int gprs_cipher_register(struct gprs_cipher_impl *ciph); 38 | 39 | /* load all available GPRS cipher plugins */ 40 | int gprs_cipher_load(const char *path); 41 | 42 | /* function to be called by core code */ 43 | int gprs_cipher_run(uint8_t *out, uint16_t len, enum gprs_ciph_algo algo, 44 | uint64_t kc, uint32_t iv, enum gprs_cipher_direction dir); 45 | 46 | /* Do we have an implementation for this cipher? */ 47 | int gprs_cipher_supported(enum gprs_ciph_algo algo); 48 | 49 | /* GSM TS 04.64 / Section A.2.1 : Generation of 'input' */ 50 | uint32_t gprs_cipher_gen_input_ui(uint32_t iov_ui, uint8_t sapi, uint32_t lfn, uint32_t oc); 51 | 52 | /* GSM TS 04.64 / Section A.2.1 : Generation of 'input' */ 53 | uint32_t gprs_cipher_gen_input_i(uint32_t iov_i, uint32_t lfn, uint32_t oc); 54 | 55 | #endif /* _GPRS_CIPHER_H */ 56 | -------------------------------------------------------------------------------- /mbts/Globals/Defines.h: -------------------------------------------------------------------------------- 1 | // Pat added this file. 2 | // We need an include file that is included before any other include files. 3 | // Might I suggest that Range Networks specific global #defines be prefixed with RN_ 4 | 5 | #ifndef DEFINES_H 6 | #define DEFINES_H 7 | 8 | // GPRS_1 turns on the SharedEncoder. It is the thing that keeps the modem from registering. 9 | #define GPRS_ENCODER 1 // Use SharedL1Encoder and SharedL1Decoder 10 | #define GPRS_TESTSI4 1 11 | #define GPRS_TEST 1 // Compile in other GPRS stuff. 12 | #define GPRS_PAT 1 // Compile in GPRS code. Turn this off to get previous non-GRPS code, 13 | // although I am not maintaining it so you may have to fix compile 14 | // problems to use it. 15 | 16 | // __GNUG__ is true for g++ and __GNUC__ for gcc. 17 | #if __GNUC__&0==__GNUG__ 18 | 19 | #define RN_UNUSED __attribute__((unused)) 20 | 21 | #define RN_UNUSED_PARAM(var) RN_UNUSED var 22 | 23 | // Pack structs onto byte boundaries. 24 | // Note that if structs are nested, this must appear on all of them. 25 | #define RN_PACKED __attribute__((packed)) 26 | 27 | #else 28 | 29 | // Suppress warning message about a variable or function being unused. 30 | // In C++ you can leave out the variable name to suppress the 'unused variable' warning. 31 | #define RN_UNUSED_PARAM(var) /*nothing*/ 32 | #define RN_UNUSED /*not defined*/ 33 | #define RN_PACKED /*not defined*/ 34 | #endif 35 | 36 | // Bound value between min and max values. 37 | #define RN_BOUND(value,min,max) ( (value)<(min) ? (min) : (value)>(max) ? (max) : (value) ) 38 | 39 | #define RN_PRETTY_TEXT(name) (" " #name "=(") << name << ")" 40 | #define RN_PRETTY_TEXT1(name) (" " #name "=") << name 41 | #define RN_WRITE_TEXT(name) os << RN_PRETTY_TEXT(name) 42 | #define RN_WRITE_OPT_TEXT(name,flag) if (flag) { os << RN_WRITE_TEXT(name); } 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /mbts/Connection/LogConnection.h: -------------------------------------------------------------------------------- 1 | /** 2 | * LogConnection.h 3 | * This file is part of the Yate-BTS Project http://www.yatebts.com 4 | * 5 | * Declaration for Logging socket connection 6 | * 7 | * Yet Another Telephony Engine - Base Transceiver Station 8 | * Copyright (C) 2013-2023 Null Team Impex SRL 9 | * Copyright (C) 2014 Legba, Inc 10 | * 11 | * This software is distributed under multiple licenses; 12 | * see the COPYING file in the main directory for licensing 13 | * information for this specific distribution. 14 | * 15 | * This use of this software may be subject to additional restrictions. 16 | * See the LEGAL file in the main directory for details. 17 | * 18 | * This program is distributed in the hope that it will be useful, 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 21 | */ 22 | 23 | #ifndef LOGCONNECTION_H 24 | #define LOGCONNECTION_H 25 | 26 | #include "GenConnection.h" 27 | 28 | namespace Connection { 29 | 30 | class LogConnection : public GenConnection 31 | { 32 | public: 33 | inline LogConnection(int fileDesc = -1) 34 | : GenConnection(fileDesc) 35 | { if (!gSelf) gSelf = this; } 36 | inline bool write(const char* text) 37 | { return writeLog(0xff,text); } 38 | inline bool write(unsigned char level, const char* text) 39 | { return writeLog(0x07 & level,text); } 40 | inline static LogConnection* self() 41 | { return gSelf; } 42 | static bool hook(int level, const char* text, int offset); 43 | private: 44 | virtual void process(const unsigned char* data, size_t len); 45 | bool writeLog(unsigned char level, const char* text); 46 | static LogConnection* gSelf; 47 | }; 48 | 49 | }; // namespace Connection 50 | 51 | #endif /* LOGCONNECTION_H */ 52 | 53 | /* vi: set ts=8 sw=4 sts=4 noet: */ 54 | -------------------------------------------------------------------------------- /nipc/web/README: -------------------------------------------------------------------------------- 1 | What is Network in a PC Web GUI 2 | -------------------------------- 3 | 4 | A Graphical Web Interface used to create configurations files for YateBTS. 5 | 6 | It has tree parts: 7 | 8 | 1. Subscribers contains: List Subscribers, Online Subscribers, Rejected IMSIs 9 | List Subscribers - each IMSI can be inserted individually or 10 | insert a regular expression to be used to match the subscribers IMSIs. 11 | 12 | Online Subscribers - lists all the subscribers online. 13 | 14 | Rejected IMSIs - lists all the rejected subscribers. 15 | 16 | 2. BTS Configuration - has all the sections from ybts.conf file that can be configured. 17 | 18 | 3. Outgoing - configure outbound connection On IAX or SIP protocol with their specific parameters. 19 | 20 | Requirements 21 | ------------ 22 | 23 | PHP, Apache, YateBTS are required to run the software. 24 | 25 | Installing 26 | ---------- 27 | 28 | Depending on your operating system the main web directory will be /var/www (debian based systems) 29 | or /var/www/html otherwise. If you don't have this path, then you need to install Apache server. 30 | 31 | Assuming you install YateBTS package or installed by hand(make install), the UI source code is 32 | located in /usr/local/share/yate/nipc_web. 33 | 34 | > cd /var/www/html (or cd /var/www on debian based OS) 35 | > ln -s /usr/local/share/yate/nipc_web yatebts_nipc 36 | 37 | 38 | Configuration 39 | ------------- 40 | 41 | Before using the interface, the permissions for the directories that are 42 | set in the $yate_conf_dir variable MUST be set. 43 | 44 | The command that has to be runned as root (if the default settings are set) is: 45 | chmod -R a+rw /usr/local/etc/yate/ 46 | 47 | Failing to configure the right permissions will make the interface display some errors 48 | the first time when it's used. 49 | -------------------------------------------------------------------------------- /mbts/Connection/GenConnection.h: -------------------------------------------------------------------------------- 1 | /** 2 | * GenConnection.h 3 | * This file is part of the Yate-BTS Project http://www.yatebts.com 4 | * 5 | * Declaration for a generic socket connection 6 | * 7 | * Yet Another Telephony Engine - Base Transceiver Station 8 | * Copyright (C) 2013-2023 Null Team Impex SRL 9 | * Copyright (C) 2014 Legba, Inc 10 | * 11 | * This software is distributed under multiple licenses; 12 | * see the COPYING file in the main directory for licensing 13 | * information for this specific distribution. 14 | * 15 | * This use of this software may be subject to additional restrictions. 16 | * See the LEGAL file in the main directory for details. 17 | * 18 | * This program is distributed in the hope that it will be useful, 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 21 | */ 22 | 23 | #ifndef GENCONNECTION_H 24 | #define GENCONNECTION_H 25 | 26 | #include 27 | 28 | #include 29 | 30 | namespace Connection { 31 | 32 | class GenConnection 33 | { 34 | public: 35 | inline bool valid() const 36 | { return mSockFd >= 0; } 37 | bool start(const char* name = 0); 38 | void clear(); 39 | protected: 40 | inline GenConnection(int fileDesc = -1, int bufSize = 0) 41 | : mSockFd(-1), mBufSize(bufSize) 42 | { initialize(fileDesc); } 43 | virtual ~GenConnection(); 44 | bool initialize(int fileDesc); 45 | virtual bool send(const void* buffer, size_t len); 46 | virtual void process(const unsigned char* data, size_t len) = 0; 47 | virtual void started(); 48 | virtual void idle(); 49 | virtual void run(); 50 | int mSockFd; 51 | int mBufSize; 52 | Thread mRecvThread; 53 | }; 54 | 55 | }; // namespace Connection 56 | 57 | #endif /* GENCONNECTION_H */ 58 | 59 | /* vi: set ts=8 sw=4 sts=4 noet: */ 60 | -------------------------------------------------------------------------------- /mbts/Connection/LogConnection.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * LogConnection.cpp 3 | * This file is part of the Yate-BTS Project http://www.yatebts.com 4 | * 5 | * Logging socket connection 6 | * 7 | * Yet Another Telephony Engine - Base Transceiver Station 8 | * Copyright (C) 2013-2023 Null Team Impex SRL 9 | * Copyright (C) 2014 Legba, Inc 10 | * 11 | * This software is distributed under multiple licenses; 12 | * see the COPYING file in the main directory for licensing 13 | * information for this specific distribution. 14 | * 15 | * This use of this software may be subject to additional restrictions. 16 | * See the LEGAL file in the main directory for details. 17 | * 18 | * This program is distributed in the hope that it will be useful, 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 21 | */ 22 | 23 | #include "LogConnection.h" 24 | 25 | #include 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | using namespace Connection; 33 | 34 | LogConnection* LogConnection::gSelf = 0; 35 | 36 | bool LogConnection::writeLog(unsigned char level, const char* text) 37 | { 38 | if (!text) 39 | return false; 40 | size_t len = ::strlen(text); 41 | if (!len) 42 | return false; 43 | char* buf = (char*)::malloc(len + 1); 44 | if (!buf) 45 | return false; 46 | buf[0] = level; 47 | ::memcpy(buf + 1,text,len); 48 | bool ok = send(buf,len + 1); 49 | ::free(buf); 50 | return ok; 51 | } 52 | 53 | void LogConnection::process(const unsigned char* data, size_t len) 54 | { 55 | assert(false); 56 | } 57 | 58 | bool LogConnection::hook(int level, const char* text, int offset) 59 | { 60 | return self() && self()->write(level,text + offset); 61 | } 62 | 63 | /* vi: set ts=8 sw=4 sts=4 noet: */ 64 | -------------------------------------------------------------------------------- /mbts/Connection/GprsConnMap.h: -------------------------------------------------------------------------------- 1 | /** 2 | * GprsConnMap.h 3 | * This file is part of the Yate-BTS Project http://www.yatebts.com 4 | * 5 | * Declaration for Connection to GPRS info mapper 6 | * 7 | * Yet Another Telephony Engine - Base Transceiver Station 8 | * Copyright (C) 2014-2023 Null Team Impex SRL 9 | * Copyright (C) 2014 Legba, Inc 10 | * 11 | * This software is distributed under multiple licenses; 12 | * see the COPYING file in the main directory for licensing 13 | * information for this specific distribution. 14 | * 15 | * This use of this software may be subject to additional restrictions. 16 | * See the LEGAL file in the main directory for details. 17 | * 18 | * This program is distributed in the hope that it will be useful, 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 21 | */ 22 | 23 | #ifndef GPRSCONNMAP_H 24 | #define GPRSCONNMAP_H 25 | 26 | #include 27 | 28 | #ifndef BTS_GPRS_MAP_BASE 29 | #define BTS_GPRS_MAP_BASE 8192 30 | #endif 31 | #ifndef BTS_GPRS_MAP_SIZE 32 | #define BTS_GPRS_MAP_SIZE 1024 33 | #endif 34 | 35 | namespace SGSN { 36 | class SgsnInfo; 37 | }; 38 | 39 | namespace Connection { 40 | 41 | class GprsConnMap : public Mutex 42 | { 43 | public: 44 | struct Conn { 45 | SGSN::SgsnInfo* mInfo; 46 | }; 47 | GprsConnMap(); 48 | int map(SGSN::SgsnInfo* info); 49 | void remap(SGSN::SgsnInfo* info, unsigned int id); 50 | SGSN::SgsnInfo* unmap(unsigned int id); 51 | bool unmap(const SGSN::SgsnInfo* info); 52 | int find(const SGSN::SgsnInfo* info); 53 | SGSN::SgsnInfo* find(unsigned int id); 54 | private: 55 | unsigned int mIndex; 56 | Conn mMap[BTS_GPRS_MAP_SIZE]; 57 | }; 58 | 59 | }; // namespace Connection 60 | 61 | #endif /* GPRSCONNMAP_H */ 62 | 63 | /* vi: set ts=8 sw=4 sts=4 noet: */ 64 | -------------------------------------------------------------------------------- /mbts/CommonLibs/ReportingTest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 Range Networks, Inc. 3 | * 4 | * This software is distributed under the terms of the GNU Affero Public License. 5 | * See the COPYING file in the main directory for details. 6 | * 7 | * This use of this software may be subject to additional restrictions. 8 | * See the LEGAL file in the main directory for details. 9 | 10 | This program is free software: you can redistribute it and/or modify 11 | it under the terms of the GNU Affero General Public License as published by 12 | the Free Software Foundation, either version 3 of the License, or 13 | (at your option) any later version. 14 | 15 | This program is distributed in the hope that it will be useful, 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | GNU Affero General Public License for more details. 19 | 20 | You should have received a copy of the GNU Affero General Public License 21 | along with this program. If not, see . 22 | 23 | */ 24 | 25 | 26 | #include "stdlib.h" 27 | #include 28 | #include 29 | 30 | #include "Reporting.h" 31 | 32 | 33 | int main(int argc, char *argv[]) 34 | { 35 | 36 | srandom(time(NULL)); 37 | 38 | ReportingTable rpt("./test.db",LOG_LOCAL7); 39 | 40 | rpt.create("count1"); 41 | rpt.create("count2"); 42 | rpt.create("max1"); 43 | rpt.create("max2"); 44 | 45 | rpt.incr("count1"); 46 | rpt.incr("count2"); 47 | rpt.incr("count1"); 48 | 49 | rpt.clear("max1"); 50 | rpt.max("max1",random()); 51 | rpt.max("max2",random()); 52 | 53 | rpt.create("indexed",5,10); 54 | for (int i=0; i<20; i++) { 55 | rpt.incr("indexed",random()%6 + 5); 56 | } 57 | 58 | rpt.create("indexedMax",5,10); 59 | for (int i=5; i<=10; i++) { 60 | rpt.max("indexedMax", i, random()); 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /mbts/SGSNGGSN/SgsnConn.h: -------------------------------------------------------------------------------- 1 | /** 2 | * SgsnConn.h 3 | * This file is part of the Yate-BTS Project http://www.yatebts.com 4 | * 5 | * Declaration for SGSN connection processing functions 6 | * 7 | * Yet Another Telephony Engine - Base Transceiver Station 8 | * Copyright (C) 2014-2023 Null Team Impex SRL 9 | * Copyright (C) 2014 Legba, Inc 10 | * 11 | * This software is distributed under multiple licenses; 12 | * see the COPYING file in the main directory for licensing 13 | * information for this specific distribution. 14 | * 15 | * This use of this software may be subject to additional restrictions. 16 | * See the LEGAL file in the main directory for details. 17 | * 18 | * This program is distributed in the hope that it will be useful, 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 21 | */ 22 | 23 | #ifndef SGSNCONN_H 24 | #define SGSNCONN_H 25 | 26 | #include "Sgsn.h" 27 | 28 | namespace SGSN { 29 | 30 | enum GprsConnState { 31 | GprsConnNone = -1, 32 | GprsConnLocal = -2, 33 | }; 34 | 35 | class SgsnConn { 36 | public: 37 | static void attachLBO(SgsnInfo* si); 38 | static void identityReq(SgsnInfo* si); 39 | static void authRequest(SgsnInfo* si, const char* text); 40 | static void attachAccept(SgsnInfo* si, const char* text); 41 | static void attachRej(SgsnInfo* si, unsigned char cause); 42 | static void detach(SgsnInfo* si, unsigned char cause, const char* text); 43 | static void pdpActivate(SgsnInfo* si, bool reply, const char* text); 44 | static void pdpModify(SgsnInfo* si, bool reply, const char* text); 45 | static void pdpDeactivate(SgsnInfo* si, const char* text); 46 | static void userData(SgsnInfo* si, const unsigned char* data, size_t len); 47 | }; 48 | 49 | }; // namespace SGSN 50 | 51 | #endif /* SGSNCONN_H */ 52 | 53 | /* vi: set ts=8 sw=4 sts=4 noet: */ 54 | -------------------------------------------------------------------------------- /mbts/Makefile.tail.in: -------------------------------------------------------------------------------- 1 | 2 | # Makefile.tail start 3 | 4 | COMPILE = $(CXX) $(DEFS) $(DEBUG) $(INCLUDES) $(CCFLAGS) 5 | CCOMPILE = $(CC) -std=gnu99 $(CFLAGS) $(DEFS) $(DEBUG) $(INCLUDES) 6 | LINK = $(CXX) $(LDFLAGS) 7 | 8 | # include optional local make rules 9 | -include YateLocal.mak 10 | 11 | .PHONY: all debug ddebug xdebug tests 12 | all: $(PROGS) $(LIBS) 13 | 14 | debug: 15 | $(MAKE) all DEBUG=-g3 MODSTRIP= 16 | 17 | ddebug: 18 | $(MAKE) all DEBUG='-g3 -DDEBUG' MODSTRIP= 19 | 20 | xdebug: 21 | $(MAKE) all DEBUG='-g3 -DXDEBUG' MODSTRIP= 22 | 23 | tests: 24 | $(MAKE) all BUILD_TESTS=yes 25 | 26 | .PHONY: strip clean install uninstall 27 | strip: all 28 | strip --strip-debug --discard-locals $(PROGS) 29 | 30 | clean: 31 | @-$(RM) $(PROGS) $(LIBS) $(OBJS) $(EXTRACLEAN) core 2>/dev/null 32 | 33 | install: $(PROGS) 34 | @mkdir -p "$(DESTDIR)$(moddir)/server/bts" && \ 35 | for i in $(PROGS) ; do \ 36 | install -D "$$i" "$(DESTDIR)$(moddir)/server/bts/$$i" ; \ 37 | done 38 | for i in $(FILES) ; do \ 39 | install -m 0644 "$$i" "$(DESTDIR)$(moddir)/server/bts/$$i" ; \ 40 | done 41 | 42 | uninstall: 43 | @-for i in $(FILES) ; do \ 44 | rm -f "$(DESTDIR)$(moddir)/server/bts/$$i" ; \ 45 | done 46 | @-for i in $(PROGS) ; do \ 47 | rm -f "$(DESTDIR)$(moddir)/server/bts/$$i" ; \ 48 | done 49 | @-test -d "$(DESTDIR)$(moddir)/server/bts" && rmdir "$(DESTDIR)$(moddir)/server/bts" 50 | 51 | %.o: @srcdir@/%.cpp $(INCFILES) 52 | $(COMPILE) -c $(LOCALFLAGS) $< 53 | 54 | %.o: @srcdir@/%.c $(INCFILES) 55 | $(CCOMPILE) $(LOCALFLAGS) -c $< 56 | 57 | Makefile: @srcdir@/Makefile.in ../../config.status 58 | cd ../.. && ./config.status 59 | 60 | $(LIBS): $(OBJS) 61 | $(AR) rcs $@ $^ 62 | 63 | %: %.cpp $(MKDEPS) $(INCFILES) $(LIBS) $(LIBDEPS) 64 | $(COMPILE) -o $@ $(LOCALFLAGS) $< $(LIBS) $(LIBTHR) $(LDFLAGS) $(LOCALLIBS) 65 | 66 | ../%.a: 67 | $(MAKE) -C `dirname $@` 68 | 69 | # Makefile.tail end 70 | 71 | -------------------------------------------------------------------------------- /mbts/GSM/PowerManager.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 Free Software Foundation, Inc. 3 | * 4 | * This software is distributed under multiple licenses; see the COPYING file in the main directory for licensing information for this specific distribuion. 5 | * 6 | * This use of this software may be subject to additional restrictions. 7 | * See the LEGAL file in the main directory for details. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | 13 | */ 14 | 15 | #ifndef __POWER_CONTROL__ 16 | #define __POWER_CONTROL__ 17 | 18 | #include 19 | 20 | #include 21 | #include 22 | 23 | // forward declaration 24 | //class Timeval; 25 | 26 | // Make it all inline for now - no change to automake 27 | 28 | class ARFCNManager; 29 | 30 | 31 | namespace GSM { 32 | 33 | 34 | class PowerManager { 35 | 36 | private: 37 | 38 | Thread mThread; 39 | ARFCNManager* mRadio; 40 | unsigned mAveragedT3122; ///< averaged over the last NumSamples taken SamplePeriod apart kept in mSamples 41 | volatile unsigned mAtten; ///< current attenuation - either set by ourselves or by setPower 42 | Timeval mLast; ///< when controller operated last time 43 | unsigned mSamples[100]; 44 | unsigned mNextSampleIndex; 45 | 46 | 47 | 48 | void increasePower(); 49 | void reducePower(); 50 | 51 | // internal method, does the control step 52 | void internalControlStep(); 53 | 54 | void sampleT3122(); 55 | 56 | void serviceLoop(); 57 | 58 | public: 59 | 60 | PowerManager(); 61 | 62 | void start(); 63 | 64 | int power() { return -mAtten; } 65 | 66 | friend void* PowerManagerServiceLoopAdapter(PowerManager *pm); 67 | 68 | }; 69 | 70 | 71 | void *PowerManagerServiceLoopAdapter(PowerManager *pm); 72 | 73 | 74 | 75 | } // namespace GSM 76 | 77 | 78 | #endif // __POWER_CONTROL__ 79 | 80 | // vim: ts=4 sw=4 81 | -------------------------------------------------------------------------------- /mbts/Connection/CmdConnection.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * CmdConnection.cpp 3 | * This file is part of the Yate-BTS Project http://www.yatebts.com 4 | * 5 | * Command socket connection 6 | * 7 | * Yet Another Telephony Engine - Base Transceiver Station 8 | * Copyright (C) 2013-2023 Null Team Impex SRL 9 | * Copyright (C) 2014 Legba, Inc 10 | * 11 | * This software is distributed under multiple licenses; 12 | * see the COPYING file in the main directory for licensing 13 | * information for this specific distribution. 14 | * 15 | * This use of this software may be subject to additional restrictions. 16 | * See the LEGAL file in the main directory for details. 17 | * 18 | * This program is distributed in the hope that it will be useful, 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 21 | */ 22 | 23 | #include "CmdConnection.h" 24 | 25 | #include 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | using namespace Connection; 32 | 33 | bool CmdConnection::write(const char* text, size_t len) 34 | { 35 | if (text && !len) 36 | len = ::strlen(text); 37 | return text && len && send(text,len); 38 | } 39 | 40 | char* CmdConnection::read() 41 | { 42 | char buf[mBufSize]; 43 | for (;;) { 44 | int fd = mSockFd; 45 | if (fd < 0) 46 | return 0; 47 | ssize_t len = ::read(fd,buf,mBufSize); 48 | if (!len) { 49 | LOG(DEBUG) << "received EOF on socket"; 50 | return 0; 51 | } 52 | if (len > 0) { 53 | if (len >= mBufSize) 54 | len = mBufSize - 1; 55 | buf[len] = 0; 56 | return ::strdup(buf); 57 | } 58 | else if (errno != EAGAIN && errno != EINTR) { 59 | LOG(ERR) << "recv() error " << errno << ": " << strerror(errno); 60 | return 0; 61 | } 62 | } 63 | } 64 | 65 | void CmdConnection::process(const unsigned char* data, size_t len) 66 | { 67 | assert(false); 68 | } 69 | 70 | /* vi: set ts=8 sw=4 sts=4 noet: */ 71 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | What is YateBTS 2 | --------------- 3 | 4 | YateBTS is an open source GSM Base Station software. 5 | 6 | You can use this software to create a 2G GSM network, either standalone or connected to 7 | the public telephony network. 8 | 9 | The use of a non-DSP aproach for GSM protocol together with a SIP implementation 10 | that supports an IMS core and SS7 core network makes it a disruptive technology. 11 | 12 | 13 | Please see the INSTALL file for information of how to download, build and install YateBTS. 14 | 15 | 16 | Configuration 17 | ------------- 18 | 19 | YateBTS is a module for the Yate telephony engine. 20 | 21 | You will need to configure Yate to load it and also YateBTS itself. 22 | 23 | 24 | YateBTS 25 | ------- 26 | 27 | The module is configured by the ybts.conf file. Depending on the install method you may 28 | have just an ybts.conf.sample which you will need to copy as ybts.conf 29 | 30 | As a minimum you will need to configure the radio band and frequency (ARFCN) on which 31 | YateBTS will operate. Please read the minimal instructions at top of ybts.conf.sample 32 | 33 | Depending on the transceiver you will need to edit the path setting in ybts.conf: 34 | 35 | [transceiver] 36 | Path=./transceiver 37 | 38 | replace ./transceiver with ./transceiver-rad1 or ./transceiver-uhd or ./transceiver-usrp1 39 | 40 | Alternatively you may create a symbolic link to the desired transceiver: 41 | 42 | cd /usr/lib64/yate/bts (or wherever it is installed) 43 | ln -s transceiver-rad1 transceiver 44 | 45 | 46 | Network In a PC 47 | ---------------- 48 | 49 | The Network In a PC (NiPC) is a configuration that allows using YateBTS standalone 50 | with just local subscribers. 51 | 52 | To use it you need to configure in Yate: 53 | 54 | In file javascript.conf: 55 | 56 | [general] 57 | routing=welcome.js 58 | 59 | [scripts] 60 | nipc=nipc.js 61 | 62 | In file extmodule.conf: 63 | 64 | [scripts] 65 | gsm_auth.sh 66 | 67 | For more info see: 68 | http://wiki.yatebts.com/index.php/Javascript_NiPC 69 | -------------------------------------------------------------------------------- /mbts/CommonLibs/VectorTest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 Free Software Foundation, Inc. 3 | * 4 | * 5 | * This software is distributed under the terms of the GNU Affero Public License. 6 | * See the COPYING file in the main directory for details. 7 | * 8 | * This use of this software may be subject to additional restrictions. 9 | * See the LEGAL file in the main directory for details. 10 | 11 | This program is free software: you can redistribute it and/or modify 12 | it under the terms of the GNU Affero General Public License as published by 13 | the Free Software Foundation, either version 3 of the License, or 14 | (at your option) any later version. 15 | 16 | This program is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | GNU Affero General Public License for more details. 20 | 21 | You should have received a copy of the GNU Affero General Public License 22 | along with this program. If not, see . 23 | 24 | */ 25 | 26 | 27 | 28 | #include "Vector.h" 29 | #include 30 | 31 | // We must have a gConfig now to include Vector. 32 | #include "Configuration.h" 33 | ConfigurationTable gConfig; 34 | 35 | using namespace std; 36 | 37 | typedef Vector TestVector; 38 | 39 | int main(int argc, char *argv[]) 40 | { 41 | TestVector test1(5); 42 | for (int i=0; i<5; i++) test1[i]=i; 43 | TestVector test2(5); 44 | for (int i=0; i<5; i++) test2[i]=10+i; 45 | 46 | cout << test1 << endl; 47 | cout << test2 << endl; 48 | 49 | { 50 | TestVector testC(test1,test2); 51 | cout << testC << endl; 52 | cout << testC.head(3) << endl; 53 | cout << testC.tail(3) << endl; 54 | testC.fill(8); 55 | cout << testC << endl; 56 | test1.copyToSegment(testC,3); 57 | cout << testC << endl; 58 | 59 | TestVector testD(testC.segment(4,3)); 60 | cout << testD << endl; 61 | testD.fill(9); 62 | cout << testC << endl; 63 | cout << testD << endl; 64 | } 65 | 66 | return 0; 67 | } 68 | -------------------------------------------------------------------------------- /mbts/A53/a5_speed.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "bits.h" 9 | #include "utils.h" 10 | #include "a5.h" 11 | 12 | static const uint8_t key[] = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef }; 13 | static const uint32_t fn = 123456; 14 | static const uint8_t dl[] = { 15 | /* A5/0 */ 16 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 17 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 18 | 19 | /* A5/1 */ 20 | 0xcb, 0xa2, 0x55, 0x76, 0x17, 0x5d, 0x3b, 0x1c, 21 | 0x7b, 0x2f, 0x29, 0xa8, 0xc1, 0xb6, 0x00, 22 | 23 | /* A5/2 */ 24 | 0x45, 0x9c, 0x88, 0xc3, 0x82, 0xb7, 0xff, 0xb3, 25 | 0x98, 0xd2, 0xf9, 0x6e, 0x0f, 0x14, 0x80, 26 | }; 27 | static const uint8_t ul[] = { 28 | /* A5/0 */ 29 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 30 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 31 | 32 | /* A5/1 */ 33 | 0xd9, 0x03, 0x5e, 0x0f, 0x2a, 0xec, 0x13, 0x9a, 34 | 0x05, 0xd4, 0xa8, 0x7b, 0xb1, 0x64, 0x80, 35 | 36 | /* A5/2 */ 37 | 0xf0, 0x3a, 0xac, 0xde, 0xe3, 0x5b, 0x5e, 0x65, 38 | 0x80, 0xba, 0xab, 0xc0, 0x59, 0x26, 0x40, 39 | }; 40 | 41 | void test_a5(int n, char * kc, uint32_t count, char * block1, char * block2) { 42 | ubit_t out[114]; 43 | int k = (n == 4) ? 16 : 8; 44 | int ntrials; 45 | float t; 46 | int i; 47 | uint8_t key[k]; 48 | osmo_hexparse(kc, key, k); 49 | ntrials = 10000; 50 | 51 | t = clock(); 52 | for (i = 0; i < ntrials; i++) { 53 | osmo_a5(n, key, count, out, NULL); 54 | } 55 | t = (clock() - t) / (CLOCKS_PER_SEC * (float)ntrials); 56 | printf("osmo_a5 DL takes %g seconds per iteration\n", t); 57 | 58 | t = clock(); 59 | for (i = 0; i < ntrials; i++) { 60 | osmo_a5(n, key, count, NULL, out); 61 | } 62 | t = (clock() - t) / (CLOCKS_PER_SEC * (float)ntrials); 63 | printf("osmo_a5 UL takes %g seconds per iteration\n", t); 64 | 65 | } 66 | 67 | int main(int argc, char **argv) 68 | { 69 | test_a5(3, "2BD6459F82C5BC00", 0x24F20F, "889EEAAF9ED1BA1ABBD8436232E440", "5CA3406AA244CF69CF047AADA2DF40"); 70 | 71 | return 0; 72 | } 73 | -------------------------------------------------------------------------------- /scripts/lib_str_util.js: -------------------------------------------------------------------------------- 1 | /** 2 | * lib_str_util.js 3 | * This file is part of the Yate-BTS Project http://www.yatebts.com 4 | * 5 | * String utility functions library for Javascript 6 | * 7 | * Copyright (C) 2014-2023 Null Team 8 | * 9 | * This software is distributed under multiple licenses; 10 | * see the COPYING file in the main directory for licensing 11 | * information for this specific distribution. 12 | * 13 | * This use of this software may be subject to additional restrictions. 14 | * See the LEGAL file in the main directory for details. 15 | * 16 | * This program is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 19 | */ 20 | 21 | // Parse a string as boolean value 22 | function parseBool(str,defVal) 23 | { 24 | switch (str) { 25 | case false: 26 | case "false": 27 | case "no": 28 | case "off": 29 | case "disable": 30 | case "f": 31 | return false; 32 | case true: 33 | case "true": 34 | case "yes": 35 | case "on": 36 | case "enable": 37 | case "t": 38 | return true; 39 | } 40 | if (defVal === undefined) 41 | return false; 42 | return defVal; 43 | } 44 | 45 | // Helper that returns a left or right aligned fixed length string 46 | function strFix(str,len,pad) 47 | { 48 | if (str === null) 49 | str = ""; 50 | if (pad == "") 51 | pad = " "; 52 | if (len < 0) { 53 | // right aligned 54 | len = -len; 55 | if (str.length >= len) 56 | return str.substr(str.length - len); 57 | while (str.length < len) 58 | str = pad + str; 59 | } 60 | else { 61 | // left aligned 62 | if (str.length >= len) 63 | return str.substr(0,len); 64 | while (str.length < len) 65 | str += pad; 66 | } 67 | return str; 68 | } 69 | 70 | // Perform one command line completion 71 | function oneCompletion(msg,str,part) 72 | { 73 | if (part != "" && str.indexOf(part) != 0) 74 | return; 75 | var ret = msg.retValue(); 76 | if (ret != "") 77 | ret += "\t"; 78 | msg.retValue(ret + str); 79 | } 80 | 81 | /* vi: set ts=8 sw=4 sts=4 noet: */ 82 | -------------------------------------------------------------------------------- /nipc/Makefile.in: -------------------------------------------------------------------------------- 1 | # Makefile 2 | # This file holds the make rules the Yate BTS module and associated executables 3 | 4 | # override DESTDIR at install time to prefix the install directory 5 | DESTDIR := 6 | 7 | SCRIPTS := nipc.js welcome.js custom_sms.js 8 | SOUNDS := welcome.au echo.au 9 | 10 | prefix = @prefix@ 11 | exec_prefix = @exec_prefix@ 12 | datarootdir = @datarootdir@ 13 | 14 | datadir:= @datadir@ 15 | confdir:= @YATE_CFG@ 16 | moddir := @YATE_MOD@ 17 | scrdir := @YATE_SCR@ 18 | shrdir := @YATE_SHR@ 19 | snddir := "$(shrdir)/sounds" 20 | webdir := "$(shrdir)/nipc_web" 21 | 22 | # include optional local make rules 23 | -include YateLocal.mak 24 | 25 | .PHONY: all 26 | all: 27 | 28 | install: all 29 | @mkdir -p "$(DESTDIR)$(confdir)/" && \ 30 | lst="`ls -1 @srcdir@/*.conf @srcdir@/*.sample @srcdir@/*.default @srcdir@/*.sql 2>/dev/null | sed 's/\.sample//g; s/\.default//g; s/[^ ]*\*\.[^ ]*//g' | sort | uniq`" ; \ 31 | for s in $$lst $(CONFIG); do \ 32 | d="$(DESTDIR)$(confdir)/`echo $$s | sed 's,.*/,,'`" ; \ 33 | if [ -f "$$d" ]; then \ 34 | echo "Not overwriting existing $$d" ; \ 35 | else \ 36 | if [ ! -f "$$s" ]; then \ 37 | test -f "$$s.default" && s="$$s.default" ; \ 38 | test -f "$$s.sample" && s="$$s.sample" ; \ 39 | fi ; \ 40 | install -m 0644 "$$s" "$$d" ; \ 41 | fi ; \ 42 | done 43 | @mkdir -p "$(DESTDIR)$(scrdir)/" && \ 44 | for i in $(SCRIPTS) ; do \ 45 | install -m 0644 @srcdir@/$$i "$(DESTDIR)$(scrdir)/" ; \ 46 | done 47 | @mkdir -p "$(DESTDIR)$(snddir)/" && \ 48 | for i in $(SOUNDS) ; do \ 49 | install -m 0644 @srcdir@/$$i "$(DESTDIR)$(snddir)/" ; \ 50 | done 51 | @mkdir -p "$(DESTDIR)$(webdir)/" && \ 52 | for i in `find "@srcdir@/web" -type f | fgrep -v .svn` ; do \ 53 | @INSTALL_D@ -m 0644 "$$i" "$(DESTDIR)$(webdir)/$${i##*/web/}" ; \ 54 | done ; \ 55 | chmod +x "$(DESTDIR)$(webdir)/ansql/force_update.php" 56 | 57 | uninstall: 58 | @-for i in $(SCRIPTS) ; do \ 59 | rm -f "$(DESTDIR)$(scrdir)/$$i" ; \ 60 | done 61 | @-rmdir "$(DESTDIR)$(scrdir)" 62 | @-for i in $(SOUNDS) ; do \ 63 | rm -f "$(DESTDIR)$(snddir)/$$i" ; \ 64 | done 65 | @-rmdir "$(DESTDIR)$(snddir)" 66 | @-rmdir "$(DESTDIR)$(shrdir)" 67 | -------------------------------------------------------------------------------- /mbts/A53/a5.h: -------------------------------------------------------------------------------- 1 | /* 2 | * a5.h 3 | * 4 | * Copyright (C) 2011 Sylvain Munaut 5 | * 6 | * All Rights Reserved 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License along 19 | * with this program; if not, write to the Free Software Foundation, Inc., 20 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 21 | */ 22 | 23 | #ifndef __OSMO_A5_H__ 24 | #define __OSMO_A5_H__ 25 | 26 | #include 27 | #include 28 | 29 | #include "bits.h" 30 | 31 | /*! \defgroup a5 GSM A5 ciphering algorithm 32 | * @{ 33 | */ 34 | 35 | /*! \file gsm/a5.h 36 | * \brief Osmocom GSM A5 ciphering algorithm header 37 | */ 38 | 39 | /*! \brief Converts a frame number into the 22 bit number used in A5/x 40 | * \param[in] fn The true framenumber 41 | * \return 22 bit word 42 | */ 43 | static inline uint32_t 44 | osmo_a5_fn_count(uint32_t fn) 45 | { 46 | int t1 = fn / (26 * 51); 47 | int t2 = fn % 26; 48 | int t3 = fn % 51; 49 | return (t1 << 11) | (t3 << 5) | t2; 50 | } 51 | 52 | /* Notes: 53 | * - key must be 8 bytes long (or NULL for A5/0) 54 | * - the dl and ul pointer must be either NULL or 114 bits long 55 | * - fn is the _real_ GSM frame number. 56 | * (converted internally to fn_count) 57 | */ 58 | void osmo_a5(int n, const uint8_t *key, uint32_t fn, ubit_t *dl, ubit_t *ul); 59 | void osmo_a5_1(const uint8_t *key, uint32_t fn, ubit_t *dl, ubit_t *ul); 60 | void osmo_a5_2(const uint8_t *key, uint32_t fn, ubit_t *dl, ubit_t *ul); 61 | void osmo_a5_3(const uint8_t *key, uint32_t fn, ubit_t *dl, ubit_t *ul); 62 | void osmo_a5_4(const uint8_t *ck, uint32_t fn, ubit_t *dl, ubit_t *ul); 63 | 64 | /*! @} */ 65 | 66 | #endif /* __OSMO_A5_H__ */ 67 | -------------------------------------------------------------------------------- /mbts/GPRS/makefile.tests: -------------------------------------------------------------------------------- 1 | HDR=BSSG.h BSSGMessages.h ByteVector.h FEC.h GPRSExport.h GPRSInternal.h \ 2 | GPRSTDMA.h MAC.h MsgBase.h RLCEngine.h RLCHdr.h RLCMessages.h RList.h \ 3 | ScalarTypes.h TBF.h Transfer.h Utils.h 4 | #HDR= Utils.h BSSG.h BSSGMessages.h FEC.h GPRSExport.h GPRSInternal.h \ 5 | # GPRSTDMA.h MAC.h RLCEngine.h RLCHdr.h RLCMessages.h TBF.h Transfer.h Utils.h BaseTypes.h 6 | SRC= GPRSConfig.cpp TBF.cpp RLCMessages.cpp BSSG.cpp BSSGMessages.cpp ByteVector.cpp FEC.cpp MAC.cpp MsgBase.cpp \ 7 | RLCEngine.cpp Transfer.cpp Utils.cpp 8 | 9 | INCLUDE= -I. -I.. -I../CommonLibs -I../Control -I../GPRS -I../GSM -I../SIP -I../SMS -I../TRXManager -I../Globals -I../CLI -I../HLR -I../SR -I../sqlite3 10 | 11 | ODIR=.libs 12 | 13 | OBJ= $(SRC:%.cpp=$(ODIR)/%.o) 14 | 15 | 16 | all: lib 17 | 18 | test1: test1.cpp Makefile libGPRS.a 19 | g++ $(INCLUDE) -o test1 test1.cpp libGPRS.a ../CommonLibs/.libs/libcommon.a 20 | 21 | test2: test1.cpp Makefile libGPRS.a 22 | g++ $(INCLUDE) -o test1 test1.cpp libGPRS.a ../CommonLibs/.libs/libcommon.a ../GSM/.libs/libGSM.a 23 | 24 | lib: $(OBJ) 25 | ar cru $(ODIR)/libGPRS.a $(OBJ) 26 | touch libGPRS.la 27 | 28 | #.cpp.o: 29 | $(ODIR)/%.o: %.cpp 30 | -mkdir o 2>/dev/null 31 | g++ -DHAVE_CONFIG_H -I. -I. -I.. -I../CommonLibs -I../Control -I../GPRS -I../GSM -I../SIP -I../SMS -I../TRXManager -I../Globals -I../CLI -I../HLR -I../SR -I../sqlite3 -Wall -g -c -o $(ODIR)/$*.o $*.cpp 32 | 33 | 34 | 35 | 36 | # g++ -DHAVE_CONFIG_H -I. -I. -I.. -I../CommonLibs -I../Control -I../GPRS -I../GSM -I../SIP -I../SMS -I../TRXManager -I../Globals -I../CLI -I../HLR -I../SR -I../sqlite3 -Wall -O3 -g -O2 -MT RadioResource.lo -MD -MP -MF ".deps/RadioResource.Tpo" -c -o RadioResource.lo RadioResource.cpp; \ 37 | then mv -f ".deps/RadioResource.Tpo" ".deps/RadioResource.Plo"; else rm -f ".deps/RadioResource.Tpo"; exit 1; fi 38 | 39 | $(OBJ):$(HDR) 40 | 41 | svnadd: 42 | svn add $(HDR) $(SRC) 43 | 44 | clean: 45 | /bin/rm $(ODIR)/* 46 | 47 | commit: 48 | svn commit $(HDR) $(SRC) 49 | 50 | ping: ping.o 51 | gcc -o ping ping.c 52 | 53 | pinghttp: pinghttp.c iputils.c makefile.tests 54 | gcc -DSTANDALONE=1 -o pinghttp $(CFLAGS) pinghttp.c iputils.c 55 | 56 | 57 | tags: .ALWAYS 58 | cd ..; sh PAT.ctags 59 | 60 | .ALWAYS: 61 | -------------------------------------------------------------------------------- /mbts/CLI/CLI.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 Free Software Foundation, Inc. 3 | * 4 | * This software is distributed under multiple licenses; see the COPYING file in the main directory for licensing information for this specific distribuion. 5 | * 6 | * This use of this software may be subject to additional restrictions. 7 | * See the LEGAL file in the main directory for details. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | */ 15 | 16 | 17 | #ifndef OPENBTSCLI_H 18 | #define OPENBTSCLI_H 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | 25 | namespace CommandLine { 26 | 27 | 28 | /** A table for matching strings to actions. */ 29 | typedef std::map ParseTable; 30 | 31 | /** The help table. */ 32 | typedef std::map HelpTable; 33 | 34 | class Parser { 35 | 36 | private: 37 | 38 | ParseTable mParseTable; 39 | HelpTable mHelpTable; 40 | static const int mMaxArgs = 10; 41 | 42 | public: 43 | 44 | void addCommands(); 45 | 46 | /** 47 | Process a command line. 48 | @return 0 on sucess, -1 on exit request, error codes otherwise 49 | */ 50 | int process(const char* line, std::ostream& os) const; 51 | 52 | /** Add a command to the parsing table. */ 53 | void addCommand(const char* name, int (*func)(int,char**,std::ostream&), const char* helpString) 54 | { mParseTable[name] = func; mHelpTable[name]=helpString; } 55 | 56 | ParseTable::const_iterator begin() const { return mParseTable.begin(); } 57 | ParseTable::const_iterator end() const { return mParseTable.end(); } 58 | 59 | /** Return a help string. */ 60 | const char *help(const std::string& cmd) const; 61 | 62 | private: 63 | 64 | /** 65 | Parse and execute a command string. 66 | @line a writeable copy of the original line 67 | @cline the original line 68 | @os output stream 69 | @return status code 70 | */ 71 | int execute(char* line, std::ostream& os) const; 72 | 73 | }; 74 | 75 | 76 | 77 | } // CLI 78 | 79 | 80 | 81 | #endif 82 | // vim: ts=4 sw=4 83 | -------------------------------------------------------------------------------- /mbts/Makefile.head.in: -------------------------------------------------------------------------------- 1 | # Makefile.head start 2 | 3 | # This file is part of the Yate-BTS Project http://www.yatebts.com 4 | # 5 | # Yet Another Telephony Engine - Base Transceiver Station 6 | # Copyright (C) 2013-2023 Null Team Impex SRL 7 | # Copyright (C) 2014 Legba, Inc 8 | # 9 | # This software is distributed under multiple licenses; 10 | # see the COPYING file in the main directory for licensing 11 | # information for this specific distribution. 12 | # 13 | # This use of this software may be subject to additional restrictions. 14 | # See the LEGAL file in the main directory for details. 15 | # 16 | # This program is distributed in the hope that it will be useful, 17 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 19 | 20 | TOP_INCLUDES := -I@top_srcdir@ -I../.. -I@srcdir@ 21 | GSM_INCLUDES := $(TOP_INCLUDES) -I@srcdir@/../CommonLibs -I@srcdir@/../A53 \ 22 | -I@srcdir@/../Connection -I@srcdir@/../GSM -I@srcdir@/../Globals -I@srcdir@/../sqlite3 23 | ALL_INCLUDES := $(GSM_INCLUDES) -I@srcdir@/../Control -I@srcdir@/../CLI -I@srcdir@/../GPRS \ 24 | -I@srcdir@/../Peering -I@srcdir@/../SGSNGGSN -I@srcdir@/../TRXManager 25 | 26 | SQL_LIBS := -L../sqlite3 -lsqlite3 27 | GSM_LIBS := -L../GSM -lGSM -L../Connection -lConnection -L../Peering -lPeering \ 28 | -L../CommonLibs -lCommonLibs -L../Globals -lGlobals $(SQL_LIBS) 29 | ALL_LIBS := -L../CLI -lCLI -L../Control -lControl -L../GPRS -lGPRS \ 30 | -L../SGSNGGSN -lSGSNGGSN -L../TRXManager -lTRXManager $(GSM_LIBS) 31 | A53_LIBS := -L../A53 -lA53 32 | 33 | SQL_DEPS := ../sqlite3/libsqlite3.a 34 | GSM_DEPS := $(SQL_DEPS) ../CommonLibs/libCommonLibs.a ../Connection/libConnection.a \ 35 | ../GSM/libGSM.a ../Globals/libGlobals.a 36 | ALL_DEPS := $(GSM_DEPS) ../CLI/libCLI.a ../Control/libControl.a ../GPRS/libGPRS.a \ 37 | ../Peering/libPeering.a ../SGSNGGSN/libSGSNGGSN.a ../SGSNGGSN/libSGSNGGSN.a \ 38 | ../TRXManager/libTRXManager.a 39 | A53_DEPS := ../A53/libA53.a 40 | 41 | prefix = @prefix@ 42 | exec_prefix = @exec_prefix@ 43 | moddir := @YATE_MOD@ 44 | 45 | DEBUG := 46 | CXX := @CXX@ -Wall 47 | AR := ar 48 | DEFS := 49 | OBJS := 50 | LIBS := 51 | PROGS:= 52 | FILES:= 53 | LIBTHR := @THREAD_LIB@ 54 | CCFLAGS:= @YATE_INC@ 55 | CFLAGS :=$(subst -Wno-overloaded-virtual,,$(CCFLAGS)) 56 | LDFLAGS:= @LDFLAGS@ 57 | 58 | # Makefile.head end 59 | 60 | -------------------------------------------------------------------------------- /nipc/welcome.js: -------------------------------------------------------------------------------- 1 | /** 2 | * welcome.js 3 | * This file is part of the Yate-BTS Project http://www.yatebts.com 4 | * 5 | * Copyright (C) 2014-2023 Null Team 6 | * 7 | * This software is distributed under multiple licenses; 8 | * see the COPYING file in the main directory for licensing 9 | * information for this specific distribution. 10 | * 11 | * This use of this software may be subject to additional restrictions. 12 | * See the LEGAL file in the main directory for details. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 17 | */ 18 | 19 | /* 20 | * Network-In-a-PC demo 21 | * To use it put in javascript.conf: 22 | * 23 | * [general] 24 | * routing=welcome.js 25 | */ 26 | 27 | function getPathPrompt(pprompt) 28 | { 29 | if (prompts_dir!="" && File.exists(prompts_dir+pprompt)) 30 | return prompts_dir+pprompt; 31 | 32 | var dirs = ["/usr/share/yate/sounds/", "/usr/local/share/yate/sounds/", "/var/spool/yatebts/"]; 33 | for (var dir of dirs) 34 | if (File.exists(dir+pprompt)) { 35 | prompts_dir = dir; 36 | return prompts_dir+pprompt; 37 | } 38 | 39 | //this should not happen 40 | Engine.debug(Debug.Warn,"Don't have path for prompt "+pprompt); 41 | return false; 42 | } 43 | 44 | function onChanDtmf(msg) 45 | { 46 | if(msg.text == 1) { 47 | state = "echoTest"; 48 | Channel.callTo("wave/play/"+getPathPrompt("echo.au")); 49 | } 50 | 51 | else if (msg.text == 2) 52 | Channel.callJust("conf/333",{"lonely":true}); 53 | } 54 | 55 | function welcomeIVR(msg) 56 | { 57 | Engine.debug(Engine.DebugInfo,"Got call to welcome IVR."); 58 | 59 | Message.install(onChanDtmf, "chan.dtmf", 90, "id", msg.id); 60 | Channel.callTo("wave/play/"+getPathPrompt("welcome.au")); 61 | 62 | if (state == "") 63 | // No digit was pressed 64 | // Wait aprox 10 seconds to see if digit is pressed 65 | Channel.callTo("wave/record/-",{"maxlen":180000}); 66 | 67 | Engine.debug(Engine.DebugInfo,"Returned to main function in state '"+state+"'"); 68 | if (state == "echoTest") 69 | Channel.callJust("external/playrec/echo.sh"); 70 | } 71 | 72 | state = ""; 73 | prompts_dir = ""; 74 | 75 | Engine.debugName("welcome"); 76 | // 32843 -> david 77 | if (message.called=="32843") 78 | welcomeIVR(message); 79 | -------------------------------------------------------------------------------- /mbts/CommonLibs/LinkedLists.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 Free Software Foundation, Inc. 3 | * 4 | * 5 | * This software is distributed under the terms of the GNU Affero Public License. 6 | * See the COPYING file in the main directory for details. 7 | * 8 | * This use of this software may be subject to additional restrictions. 9 | * See the LEGAL file in the main directory for details. 10 | 11 | This program is free software: you can redistribute it and/or modify 12 | it under the terms of the GNU Affero General Public License as published by 13 | the Free Software Foundation, either version 3 of the License, or 14 | (at your option) any later version. 15 | 16 | This program is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | GNU Affero General Public License for more details. 20 | 21 | You should have received a copy of the GNU Affero General Public License 22 | along with this program. If not, see . 23 | 24 | */ 25 | 26 | 27 | 28 | 29 | #include "LinkedLists.h" 30 | 31 | 32 | void PointerFIFO::push_front(void* val) // by pat 33 | { 34 | // Pat added this routine for completeness, but never used or tested. 35 | // The first person to use this routine should remove this assert. 36 | ListNode *node = allocate(); 37 | node->data(val); 38 | node->next(mHead); 39 | mHead = node; 40 | if (!mTail) mTail=node; 41 | mSize++; 42 | } 43 | 44 | void PointerFIFO::put(void* val) 45 | { 46 | ListNode *node = allocate(); 47 | node->data(val); 48 | node->next(NULL); 49 | if (mTail!=NULL) mTail->next(node); 50 | mTail=node; 51 | if (mHead==NULL) mHead=node; 52 | mSize++; 53 | } 54 | 55 | /** Take an item from the FIFO. */ 56 | void* PointerFIFO::get() 57 | { 58 | // empty list? 59 | if (mHead==NULL) return NULL; 60 | // normal case 61 | ListNode* next = mHead->next(); 62 | void* retVal = mHead->data(); 63 | release(mHead); 64 | mHead = next; 65 | if (next==NULL) mTail=NULL; 66 | mSize--; 67 | return retVal; 68 | } 69 | 70 | 71 | ListNode *PointerFIFO::allocate() 72 | { 73 | if (mFreeList==NULL) return new ListNode; 74 | ListNode* retVal = mFreeList; 75 | mFreeList = mFreeList->next(); 76 | return retVal; 77 | } 78 | 79 | void PointerFIFO::release(ListNode* wNode) 80 | { 81 | wNode->next(mFreeList); 82 | mFreeList = wNode; 83 | } 84 | -------------------------------------------------------------------------------- /mbts/GSM/GSMSAPMux.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008, 2009 Free Software Foundation, Inc. 3 | * 4 | * This software is distributed under multiple licenses; see the COPYING file in the main directory for licensing information for this specific distribuion. 5 | * 6 | * This use of this software may be subject to additional restrictions. 7 | * See the LEGAL file in the main directory for details. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | 13 | */ 14 | 15 | 16 | 17 | #include "GSMSAPMux.h" 18 | #include "GSMTransfer.h" 19 | #include "GSML1FEC.h" 20 | #include "GSML2LAPDm.h" 21 | 22 | #include 23 | 24 | 25 | using namespace GSM; 26 | 27 | 28 | void SAPMux::writeHighSide(const L2Frame& frame) 29 | { 30 | // The SAP may or may not be present, depending on the channel type. 31 | OBJLOG(DEBUG) << frame; 32 | ScopedLock lock(mLock); 33 | mDownstream->writeHighSide(frame); 34 | } 35 | 36 | 37 | 38 | void SAPMux::writeLowSide(const L2Frame& frame) 39 | { 40 | OBJLOG(DEBUG) << frame.SAPI() << " " << frame; 41 | unsigned SAPI = frame.SAPI(); 42 | bool data = frame.primitive()==DATA; 43 | if (data && (!mUpstream[SAPI])) { 44 | LOG(WARNING) << "received DATA for unsupported SAP " << SAPI; 45 | return; 46 | } 47 | if (data) { 48 | mUpstream[SAPI]->writeLowSide(frame); 49 | } else { 50 | // If this is a non-data primitive, copy it out to every SAP. 51 | for (int i=0; i<4; i++) { 52 | if (mUpstream[i]) mUpstream[i]->writeLowSide(frame); 53 | } 54 | } 55 | } 56 | 57 | 58 | 59 | void LoopbackSAPMux::writeHighSide(const L2Frame& frame) 60 | { 61 | OBJLOG(DEBUG) << "Loopback " << frame; 62 | // Substitute primitive 63 | L2Frame newFrame(frame); 64 | unsigned SAPI = frame.SAPI(); 65 | switch (frame.primitive()) { 66 | case ERROR: SAPI=0; break; 67 | case RELEASE: return; 68 | default: break; 69 | } 70 | // Because this is a test fixture, as assert here. 71 | // If this were not a text fixture, we would print a warning 72 | // and ignore the frame. 73 | assert(mUpstream[SAPI]); 74 | ScopedLock lock(mLock); 75 | mUpstream[SAPI]->writeLowSide(newFrame); 76 | } 77 | 78 | 79 | 80 | void LoopbackSAPMux::writeLowSide(const L2Frame& frame) 81 | { 82 | assert(mDownstream); 83 | L2Frame newFrame(frame); 84 | mDownstream->writeHighSide(newFrame); 85 | } 86 | 87 | 88 | 89 | 90 | 91 | // vim: ts=4 sw=4 92 | -------------------------------------------------------------------------------- /nipc/web/main.php: -------------------------------------------------------------------------------- 1 | 56 | 57 | 58 | 59 | <?php print $proj_title; ?> 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /config.h.in: -------------------------------------------------------------------------------- 1 | /* config.h.in template for config.h */ 2 | 3 | /* Define if building universal (internal helper macro) */ 4 | #undef AC_APPLE_UNIVERSAL_BUILD 5 | 6 | /* Define to 1 if you have the header file. */ 7 | #undef HAVE_BYTESWAP_H 8 | 9 | /* Define to 1 if you have the header file. */ 10 | #undef HAVE_INTTYPES_H 11 | 12 | /* Define to 1 if you have the header file. */ 13 | #undef HAVE_MEMORY_H 14 | 15 | /* Define to 1 if you have the header file. */ 16 | #undef HAVE_STDINT_H 17 | 18 | /* Define to 1 if you have the header file. */ 19 | #undef HAVE_STDLIB_H 20 | 21 | /* Define to 1 if you have the header file. */ 22 | #undef HAVE_UNISTD_H 23 | 24 | /* Define to 1 if you have the header file. */ 25 | #undef HAVE_STRINGS_H 26 | 27 | /* Define to 1 if you have the header file. */ 28 | #undef HAVE_STRING_H 29 | 30 | /* Define to 1 if you have the header file. */ 31 | #undef HAVE_SYS_STAT_H 32 | 33 | /* Define to 1 if you have the header file. */ 34 | #undef HAVE_SYS_TYPES_H 35 | 36 | /* Define to 1 if you have the header file. */ 37 | #undef HAVE_SYS_PRCTL_H 38 | 39 | /* Define to the full name of this package. */ 40 | #undef PACKAGE_NAME 41 | 42 | /* Define to the full name and version of this package. */ 43 | #undef PACKAGE_STRING 44 | 45 | /* Define to the one symbol short name of this package. */ 46 | #undef PACKAGE_TARNAME 47 | 48 | /* Define to the version of this package. */ 49 | #undef PACKAGE_VERSION 50 | 51 | /* Define to 1 if you have the ANSI C header files. */ 52 | #undef STDC_HEADERS 53 | 54 | /* Define to 1 if you can safely include both and . */ 55 | #undef TIME_WITH_SYS_TIME 56 | 57 | /* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most 58 | significant byte first (like Motorola and SPARC, unlike Intel). */ 59 | #if defined AC_APPLE_UNIVERSAL_BUILD 60 | # if defined __BIG_ENDIAN__ 61 | # define WORDS_BIGENDIAN 1 62 | # endif 63 | #else 64 | # ifndef WORDS_BIGENDIAN 65 | # undef WORDS_BIGENDIAN 66 | # endif 67 | #endif 68 | 69 | /* Define to empty if `const' does not conform to ANSI C. */ 70 | #undef const 71 | 72 | /* Define to `__inline__' or `__inline' if that's what the C compiler 73 | calls it, or to nothing if 'inline' is not supported under any name. */ 74 | #ifndef __cplusplus 75 | #undef inline 76 | #endif 77 | 78 | /* Define to `unsigned int' if does not define. */ 79 | #undef size_t 80 | -------------------------------------------------------------------------------- /mbts/GSM/PhysicalStatus.h: -------------------------------------------------------------------------------- 1 | /**@file Declarations for PhysicalStatus and related classes. */ 2 | /* 3 | * Copyright 2010 Kestrel Signal Processing, Inc. 4 | * Copyright 2011 Range Networks, Inc. 5 | * 6 | * This software is distributed under multiple licenses; 7 | * see the COPYING file in the main directory for licensing 8 | * information for this specific distribuion. 9 | * 10 | * This use of this software may be subject to additional restrictions. 11 | * See the LEGAL file in the main directory for details. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 16 | 17 | */ 18 | 19 | 20 | 21 | #ifndef PHYSICALSTATUS_H 22 | #define PHYSICALSTATUS_H 23 | 24 | #include 25 | 26 | #include 27 | #include 28 | 29 | 30 | struct sqlite3; 31 | 32 | 33 | namespace GSM { 34 | 35 | class L3MeasurementResults; 36 | class LogicalChannel; 37 | 38 | /** 39 | A table for tracking the state of channels. 40 | */ 41 | class PhysicalStatus { 42 | 43 | private: 44 | 45 | Mutex mLock; ///< to reduce the load on the filesystem locking 46 | sqlite3 *mDB; ///< database connection 47 | 48 | public: 49 | 50 | /** 51 | Initialize a physical status reporting table. 52 | @param path Path fto sqlite3 database file. 53 | @return 0 if the database was successfully opened and initialized; 1 otherwise 54 | */ 55 | int open(const char*wPath); 56 | 57 | ~PhysicalStatus(); 58 | 59 | /** 60 | Add reporting information associated with a channel to the table. 61 | @param chan The channel to report. 62 | @param measResults The measurement report. 63 | @return The result of the SQLite query: true for the query being executed successfully, false otherwise. 64 | */ 65 | bool setPhysical(const LogicalChannel* chan, const L3MeasurementResults& measResults); 66 | 67 | /** 68 | Dump the physical status table to the output stream. 69 | @param os The output stream to dump the channel information to. 70 | */ 71 | // void dump(std::ostream& os) const; 72 | 73 | private: 74 | 75 | /** 76 | Create entry in table. This is for the initial creation. 77 | @param chan The channel to create an entry for. 78 | @return The result of the SQLite query: true for the query being executed successfully, false otherwise. 79 | */ 80 | bool createEntry(const LogicalChannel* chan); 81 | 82 | 83 | }; 84 | 85 | 86 | } 87 | 88 | #endif 89 | 90 | // vim: ts=4 sw=4 91 | -------------------------------------------------------------------------------- /mbts/CommonLibs/LogTest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 Free Software Foundation, Inc. 3 | * Copyright 2010 Kestrel Signal Processing, Inc. 4 | * 5 | * 6 | * This software is distributed under the terms of the GNU Affero Public License. 7 | * See the COPYING file in the main directory for details. 8 | * 9 | * This use of this software may be subject to additional restrictions. 10 | * See the LEGAL file in the main directory for details. 11 | 12 | This program is free software: you can redistribute it and/or modify 13 | it under the terms of the GNU Affero General Public License as published by 14 | the Free Software Foundation, either version 3 of the License, or 15 | (at your option) any later version. 16 | 17 | This program is distributed in the hope that it will be useful, 18 | but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | GNU Affero General Public License for more details. 21 | 22 | You should have received a copy of the GNU Affero General Public License 23 | along with this program. If not, see . 24 | 25 | */ 26 | 27 | #include 28 | #include 29 | 30 | #include "Logger.h" 31 | #include "Configuration.h" 32 | 33 | ConfigurationTable gConfig; 34 | //ConfigurationTable gConfig("example.config"); 35 | 36 | void printAlarms() 37 | { 38 | std::ostream_iterator output( std::cout, "\n" ); 39 | std::list alarms = gGetLoggerAlarms(); 40 | std::cout << "# alarms = " << alarms.size() << std::endl; 41 | std::copy( alarms.begin(), alarms.end(), output ); 42 | } 43 | 44 | int main(int argc, char *argv[]) 45 | { 46 | gLogInit("LogTest","NOTICE",LOG_LOCAL7); 47 | 48 | LOG(EMERG) << " testing the logger."; 49 | LOG(ALERT) << " testing the logger."; 50 | LOG(CRIT) << " testing the logger."; 51 | LOG(ERR) << " testing the logger."; 52 | LOG(WARNING) << " testing the logger."; 53 | LOG(NOTICE) << " testing the logger."; 54 | LOG(INFO) << " testing the logger."; 55 | LOG(DEBUG) << " testing the logger."; 56 | std::cout << "\n\n\n"; 57 | std::cout << "testing Alarms\n"; 58 | std::cout << "you should see three lines:" << std::endl; 59 | printAlarms(); 60 | std::cout << "----------- generating 20 alarms ----------" << std::endl; 61 | for (int i = 0 ; i < 20 ; ++i) { 62 | LOG(ALERT) << i; 63 | } 64 | std::cout << "you should see ten lines with the numbers 10..19:" << std::endl; 65 | printAlarms(); 66 | } 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /mbts/Connection/SigConnection.h: -------------------------------------------------------------------------------- 1 | /** 2 | * SigConnection.h 3 | * This file is part of the Yate-BTS Project http://www.yatebts.com 4 | * 5 | * Declaration for Signaling socket connection 6 | * 7 | * Yet Another Telephony Engine - Base Transceiver Station 8 | * Copyright (C) 2013-2023 Null Team Impex SRL 9 | * Copyright (C) 2014 Legba, Inc 10 | * 11 | * This software is distributed under multiple licenses; 12 | * see the COPYING file in the main directory for licensing 13 | * information for this specific distribution. 14 | * 15 | * This use of this software may be subject to additional restrictions. 16 | * See the LEGAL file in the main directory for details. 17 | * 18 | * This program is distributed in the hope that it will be useful, 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 21 | */ 22 | 23 | #ifndef SIGCONNECTION_H 24 | #define SIGCONNECTION_H 25 | 26 | #include "GenConnection.h" 27 | 28 | #include 29 | #include 30 | 31 | namespace Connection { 32 | 33 | #include "ybts.h" 34 | 35 | class SigConnection : public GenConnection 36 | { 37 | public: 38 | inline SigConnection(int fileDesc = -1) 39 | : GenConnection(fileDesc,2600), mHbRecv(0,0), mHbSend(0,0) 40 | { } 41 | bool send(BtsPrimitive prim, unsigned char info = 0, const void* data = 0, size_t len = 0); 42 | bool send(BtsPrimitive prim, unsigned char info, unsigned int id); 43 | bool send(BtsPrimitive prim, unsigned char info, unsigned int id, const void* data, size_t len); 44 | inline bool send(BtsPrimitive prim, unsigned char info, unsigned int id, const std::string str) 45 | { return send(prim, info, id, str.data(), str.size()); } 46 | bool send(unsigned char sapi, unsigned int id, const GSM::L3Frame* frame); 47 | protected: 48 | virtual bool send(const void* buffer, size_t len); 49 | virtual void process(const unsigned char* data, size_t len); 50 | virtual void started(); 51 | virtual void idle(); 52 | private: 53 | void process(BtsPrimitive prim, unsigned char info); 54 | void process(BtsPrimitive prim, unsigned char info, const unsigned char* data, size_t len); 55 | void process(BtsPrimitive prim, unsigned char info, unsigned int id); 56 | void process(BtsPrimitive prim, unsigned char info, unsigned int id, const unsigned char* data, size_t len); 57 | Timeval mHbRecv; 58 | Timeval mHbSend; 59 | }; 60 | 61 | }; // namespace Connection 62 | 63 | #endif /* SIGCONNECTION_H */ 64 | 65 | /* vi: set ts=8 sw=4 sts=4 noet: */ 66 | -------------------------------------------------------------------------------- /mbts/Connection/ConnectionMap.h: -------------------------------------------------------------------------------- 1 | /** 2 | * ConnectionMap.h 3 | * This file is part of the Yate-BTS Project http://www.yatebts.com 4 | * 5 | * Declaration for Connection to Logical Channel mapper 6 | * 7 | * Yet Another Telephony Engine - Base Transceiver Station 8 | * Copyright (C) 2013-2023 Null Team Impex SRL 9 | * Copyright (C) 2014 Legba, Inc 10 | * 11 | * This software is distributed under multiple licenses; 12 | * see the COPYING file in the main directory for licensing 13 | * information for this specific distribution. 14 | * 15 | * This use of this software may be subject to additional restrictions. 16 | * See the LEGAL file in the main directory for details. 17 | * 18 | * This program is distributed in the hope that it will be useful, 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 21 | */ 22 | 23 | #ifndef CONNECTIONMAP_H 24 | #define CONNECTIONMAP_H 25 | 26 | #include 27 | 28 | #ifndef BTS_CONN_MAP_SIZE 29 | #define BTS_CONN_MAP_SIZE 1024 30 | #endif 31 | 32 | namespace GSM { 33 | class LogicalChannel; 34 | class TCHFACCHLogicalChannel; 35 | class SACCHLogicalChannel; 36 | }; 37 | 38 | namespace Connection { 39 | 40 | class ConnectionMap : public Mutex 41 | { 42 | public: 43 | struct Conn { 44 | GSM::LogicalChannel* mChan; 45 | GSM::TCHFACCHLogicalChannel* mMedia; 46 | GSM::SACCHLogicalChannel* mSACCH; 47 | int mHoRef; 48 | int mTA; 49 | }; 50 | ConnectionMap(); 51 | int map(GSM::LogicalChannel* chan, GSM::SACCHLogicalChannel* sacch, int ref = -1); 52 | void mapMedia(unsigned int id, GSM::TCHFACCHLogicalChannel* media); 53 | GSM::LogicalChannel* unmap(unsigned int id); 54 | bool unmap(const GSM::LogicalChannel* chan); 55 | int remap(GSM::LogicalChannel* chan, GSM::TCHFACCHLogicalChannel* media, GSM::SACCHLogicalChannel* sacch); 56 | int find(const GSM::LogicalChannel* chan); 57 | int find(const GSM::SACCHLogicalChannel* chan); 58 | GSM::LogicalChannel* find(unsigned int id); 59 | GSM::TCHFACCHLogicalChannel* findMedia(unsigned int id); 60 | GSM::TCHFACCHLogicalChannel* findMedia(const GSM::LogicalChannel* chan); 61 | int findRef(int ref); 62 | inline void putTA(unsigned int id, int TA) { mMap[id].mTA = TA; } 63 | inline int takeTA(unsigned int id) { mMap[id].mHoRef = -1; return mMap[id].mTA; } 64 | private: 65 | unsigned int mIndex; 66 | Conn mMap[BTS_CONN_MAP_SIZE]; 67 | }; 68 | 69 | }; // namespace Connection 70 | 71 | #endif /* CONNECTIONMAP_H */ 72 | 73 | /* vi: set ts=8 sw=4 sts=4 noet: */ 74 | -------------------------------------------------------------------------------- /mbts/Globals/Globals.h: -------------------------------------------------------------------------------- 1 | //#define RN_DEVELOPER_MODE 1 2 | /**@file Global system parameters. */ 3 | /* 4 | * Copyright 2008, 2009 Free Software Foundation, Inc. 5 | * Copyright 2011 Range Networks, Inc. 6 | * Copyright (C) 2013-2023 Null Team Impex SRL 7 | * Copyright (C) 2014 Legba, Inc 8 | * 9 | * This software is distributed under multiple licenses; 10 | * see the COPYING file in the main directory for licensing 11 | * information for this specific distribuion. 12 | * 13 | * This use of this software may be subject to additional restrictions. 14 | * See the LEGAL file in the main directory for details. 15 | 16 | This program is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 19 | 20 | */ 21 | 22 | /* 23 | This file keeps global system parameters. 24 | */ 25 | 26 | #ifndef GLOBALS_H 27 | #define GLOBALS_H 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | //#include 34 | //#include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | 44 | 45 | /** Date-and-time string, defined in OpenBTS.cpp. */ 46 | extern const char* gDateTime; 47 | 48 | /** 49 | Just about everything goes into the configuration table. 50 | This should be defined in the main body of the top-level application. 51 | */ 52 | extern ConfigurationTable gConfig; 53 | 54 | /** The OpenBTS welcome message. */ 55 | extern const char* gOpenBTSWelcome; 56 | 57 | /** The OpenBTS version string. */ 58 | extern const char *gVersionString; 59 | 60 | /** The central parser. */ 61 | extern CommandLine::Parser gParser; 62 | 63 | /** The global TMSI table. */ 64 | //extern Control::TMSITable gTMSITable; 65 | 66 | /** The physical status reporting table */ 67 | extern GSM::PhysicalStatus gPhysStatus; 68 | 69 | /** The subscriber registry and authenticator */ 70 | //extern SubscriberRegistry gSubscriberRegistry; 71 | 72 | /** The global transceiver interface. */ 73 | extern TransceiverManager gTRX; 74 | 75 | /** Connections to YBTS */ 76 | extern Connection::LogConnection gLogConn; 77 | extern Connection::CmdConnection gCmdConn; 78 | extern Connection::SigConnection gSigConn; 79 | extern Connection::MediaConnection gMediaConn; 80 | extern Connection::ConnectionMap gConnMap; 81 | extern Connection::GprsConnMap gGprsMap; 82 | 83 | extern ReportingTable gReports; 84 | #endif 85 | -------------------------------------------------------------------------------- /mbts/CommonLibs/Timeval.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 Free Software Foundation, Inc. 3 | * 4 | * 5 | * This software is distributed under the terms of the GNU Affero Public License. 6 | * See the COPYING file in the main directory for details. 7 | * 8 | * This use of this software may be subject to additional restrictions. 9 | * See the LEGAL file in the main directory for details. 10 | 11 | This program is free software: you can redistribute it and/or modify 12 | it under the terms of the GNU Affero General Public License as published by 13 | the Free Software Foundation, either version 3 of the License, or 14 | (at your option) any later version. 15 | 16 | This program is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | GNU Affero General Public License for more details. 20 | 21 | You should have received a copy of the GNU Affero General Public License 22 | along with this program. If not, see . 23 | 24 | */ 25 | 26 | 27 | 28 | #include "Timeval.h" 29 | 30 | using namespace std; 31 | 32 | void Timeval::future(unsigned offset) 33 | { 34 | now(); 35 | unsigned sec = offset/1000; 36 | unsigned msec = offset%1000; 37 | mTimeval.tv_usec += msec*1000; 38 | mTimeval.tv_sec += sec; 39 | if (mTimeval.tv_usec>1000000) { 40 | mTimeval.tv_usec -= 1000000; 41 | mTimeval.tv_sec += 1; 42 | } 43 | } 44 | 45 | 46 | struct timespec Timeval::timespec() const 47 | { 48 | struct timespec retVal; 49 | retVal.tv_sec = mTimeval.tv_sec; 50 | retVal.tv_nsec = 1000 * (long)mTimeval.tv_usec; 51 | return retVal; 52 | } 53 | 54 | 55 | bool Timeval::passed() const 56 | { 57 | Timeval nowTime; 58 | if (nowTime.mTimeval.tv_sec < mTimeval.tv_sec) return false; 59 | if (nowTime.mTimeval.tv_sec > mTimeval.tv_sec) return true; 60 | if (nowTime.mTimeval.tv_usec > mTimeval.tv_usec) return true; 61 | return false; 62 | } 63 | 64 | double Timeval::seconds() const 65 | { 66 | return ((double)mTimeval.tv_sec) + 1e-6*((double)mTimeval.tv_usec); 67 | } 68 | 69 | 70 | 71 | long Timeval::delta(const Timeval& other) const 72 | { 73 | // 2^31 milliseconds is just over 4 years. 74 | int32_t deltaS = other.sec() - sec(); 75 | int32_t deltaUs = other.usec() - usec(); 76 | return 1000*deltaS + deltaUs/1000; 77 | } 78 | 79 | 80 | 81 | 82 | ostream& operator<<(ostream& os, const Timeval& tv) 83 | { 84 | os.setf( ios::fixed, ios::floatfield ); 85 | os << tv.seconds(); 86 | return os; 87 | } 88 | 89 | 90 | ostream& operator<<(ostream& os, const struct timespec& ts) 91 | { 92 | os << ts.tv_sec << "," << ts.tv_nsec; 93 | return os; 94 | } 95 | 96 | 97 | 98 | // vim: ts=4 sw=4 99 | -------------------------------------------------------------------------------- /mbts/CommonLibs/SocketsTest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 Free Software Foundation, Inc. 3 | * 4 | * 5 | * This software is distributed under the terms of the GNU Affero Public License. 6 | * See the COPYING file in the main directory for details. 7 | * 8 | * This use of this software may be subject to additional restrictions. 9 | * See the LEGAL file in the main directory for details. 10 | 11 | This program is free software: you can redistribute it and/or modify 12 | it under the terms of the GNU Affero General Public License as published by 13 | the Free Software Foundation, either version 3 of the License, or 14 | (at your option) any later version. 15 | 16 | This program is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | GNU Affero General Public License for more details. 20 | 21 | You should have received a copy of the GNU Affero General Public License 22 | along with this program. If not, see . 23 | 24 | */ 25 | 26 | 27 | 28 | 29 | #include "Sockets.h" 30 | #include "Threads.h" 31 | #include 32 | #include 33 | 34 | 35 | static const int gNumToSend = 10; 36 | 37 | 38 | void *testReaderIP(void *) 39 | { 40 | UDPSocket readSocket(5934, "localhost", 5061); 41 | readSocket.nonblocking(); 42 | int rc = 0; 43 | while (rc0) { 47 | COUT("read: " << buf); 48 | rc++; 49 | } else { 50 | sleep(2); 51 | } 52 | } 53 | return NULL; 54 | } 55 | 56 | 57 | 58 | void *testReaderUnix(void *) 59 | { 60 | UDDSocket readSocket("testDestination"); 61 | readSocket.nonblocking(); 62 | int rc = 0; 63 | while (rc0) { 67 | COUT("read: " << buf); 68 | rc++; 69 | } else { 70 | sleep(2); 71 | } 72 | } 73 | return NULL; 74 | } 75 | 76 | 77 | int main(int argc, char * argv[] ) 78 | { 79 | 80 | Thread readerThreadIP; 81 | readerThreadIP.start(testReaderIP,NULL); 82 | Thread readerThreadUnix; 83 | readerThreadUnix.start(testReaderUnix,NULL); 84 | 85 | UDPSocket socket1(5061, "127.0.0.1",5934); 86 | UDDSocket socket1U("testSource","testDestination"); 87 | 88 | COUT("socket1: " << socket1.port()); 89 | 90 | // give the readers time to open 91 | sleep(1); 92 | 93 | for (int i=0; i=halfModulus) delta -= RLCBSN_t::BSNPeriodicity; 27 | else if (delta<-halfModulus) delta += RLCBSN_t::BSNPeriodicity; 28 | return delta; 29 | } 30 | 31 | 32 | // Based on GSM::FNDelta 33 | // We assume the values are within a half periodicity of each other. 34 | int RLCBSN_t::BSNdelta(RLCBSN_t v2) 35 | { 36 | RLCBSN_t v1 = *this; 37 | //int delta = v1.mValue - v2.mValue; 38 | //if (delta>=halfModulus) delta -= BSNPeriodicity; 39 | //else if (delta<-halfModulus) delta += BSNPeriodicity; 40 | //return RLCBSN_t(delta); 41 | return RLCBSN_t(deltaBSN(v1.mValue,v2.mValue)); 42 | } 43 | 44 | // Return 1 if v1 > v2; return -1 if v1 < v2, using modulo BSNPeriodicity. 45 | int RLCBSN_t::BSNcompare(RLCBSN_t v2) 46 | { 47 | int delta = BSNdelta(v2); 48 | if (delta>0) return 1; 49 | if (delta<0) return -1; 50 | return 0; 51 | } 52 | 53 | // (pat) Return the block radio number for a frame number. 54 | RLCBSN_t FrameNumber2BSN(int fn) 55 | { 56 | // The RLC blocks use a 52-multiframe, but each 13-multiframe is identical: 57 | // the first 12 frames are 3 RLC blocks, and the last frame is for timing or idle. 58 | int mfn = (fn / 13); // how many 13-multiframes 59 | int rem = (fn - (mfn*13)); // how many blocks within the last multiframe. 60 | RLCBSN_t result = mfn * 3 + ((rem==12) ? 2 : (rem/4)); 61 | result.normalize(); 62 | return result; 63 | } 64 | 65 | 66 | // Return the Block Sequence Number for a frame number. 67 | // There are 12 radio blocks per 52 frames, 68 | int BSN2FrameNumber(RLCBSN_t absn) // absolute block sequence number. 69 | { 70 | // One extra frame is inserted after every 3 radio blocks, 71 | // so 3 radio blocks take 13 frames. 72 | int bsn = absn; // Convert to int so we do math on int, not RLCBSN_t 73 | int result = ((int)bsn / 3) * 13 + ((int)bsn % 3) * 4; 74 | assert(result >= 0 && (unsigned) result <= GSM::gHyperframe); 75 | return result; 76 | } 77 | 78 | std::ostream& operator<<(std::ostream& os, const RLCDir::type &dir) 79 | { 80 | os << RLCDir::name(dir); 81 | return os; 82 | } 83 | }; 84 | -------------------------------------------------------------------------------- /mbts/Connection/MediaConnection.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * MediaConnection.cpp 3 | * This file is part of the Yate-BTS Project http://www.yatebts.com 4 | * 5 | * Media socket connection 6 | * 7 | * Yet Another Telephony Engine - Base Transceiver Station 8 | * Copyright (C) 2013-2023 Null Team Impex SRL 9 | * Copyright (C) 2014 Legba, Inc 10 | * 11 | * This software is distributed under multiple licenses; 12 | * see the COPYING file in the main directory for licensing 13 | * information for this specific distribution. 14 | * 15 | * This use of this software may be subject to additional restrictions. 16 | * See the LEGAL file in the main directory for details. 17 | * 18 | * This program is distributed in the hope that it will be useful, 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 21 | */ 22 | 23 | #include "MediaConnection.h" 24 | #include "ConnectionMap.h" 25 | #include "GprsConnMap.h" 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | using namespace Connection; 33 | using namespace GSM; 34 | using namespace SGSN; 35 | 36 | bool MediaConnection::send(unsigned int id, const void* data, size_t len, const void* data2, size_t len2) 37 | { 38 | if (!valid()) 39 | return false; 40 | if (!data2) 41 | len2 = 0; 42 | unsigned char buf[len + len2 + 2]; 43 | buf[0] = (unsigned char)(id >> 8); 44 | buf[1] = (unsigned char)id; 45 | ::memcpy(buf + 2,data,len); 46 | if (len2) 47 | ::memcpy(buf + len + 2,data2,len2); 48 | return GenConnection::send(buf,len + len2 + 2); 49 | } 50 | 51 | void MediaConnection::process(const unsigned char* data, size_t len) 52 | { 53 | if (len < 3) { 54 | LOG(ERR) << "received short message of length " << len; 55 | return; 56 | } 57 | unsigned int id = (((unsigned int)data[0]) << 8) | data[1]; 58 | process(id,data + 2,len - 2); 59 | } 60 | 61 | void MediaConnection::process(unsigned int id, const unsigned char* data, size_t len) 62 | { 63 | #ifdef XDEBUG 64 | Timeval timer; 65 | #endif 66 | TCHFACCHLogicalChannel* tch = gConnMap.findMedia(id); 67 | if (tch) { 68 | // TODO: check frame size and blocking operation 69 | tch->sendTCH(data); 70 | #ifdef XDEBUG 71 | long ms = timer.elapsed(); 72 | if (ms > 50) 73 | LOG(ERR) << "connection " << id << " sent " << len << " bytes voice frame in " << ms << " ms"; 74 | #endif 75 | return; 76 | } 77 | SgsnInfo* si = gGprsMap.find(id); 78 | if (si) { 79 | SgsnConn::userData(si,data,len); 80 | #ifdef XDEBUG 81 | long ms = timer.elapsed(); 82 | if (ms > 250) 83 | LOG(ERR) << "connection " << id << " sent " << len << " bytes of data in " << ms << " ms"; 84 | #endif 85 | return; 86 | } 87 | LOG(ERR) << "received media frame for unmapped id " << id; 88 | } 89 | 90 | /* vi: set ts=8 sw=4 sts=4 noet: */ 91 | -------------------------------------------------------------------------------- /mbts/CommonLibs/InterthreadTest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 Free Software Foundation, Inc. 3 | * 4 | * 5 | * This software is distributed under the terms of the GNU Affero Public License. 6 | * See the COPYING file in the main directory for details. 7 | * 8 | * This use of this software may be subject to additional restrictions. 9 | * See the LEGAL file in the main directory for details. 10 | 11 | This program is free software: you can redistribute it and/or modify 12 | it under the terms of the GNU Affero General Public License as published by 13 | the Free Software Foundation, either version 3 of the License, or 14 | (at your option) any later version. 15 | 16 | This program is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | GNU Affero General Public License for more details. 20 | 21 | You should have received a copy of the GNU Affero General Public License 22 | along with this program. If not, see . 23 | 24 | */ 25 | 26 | 27 | 28 | #include "Threads.h" 29 | #include "Interthread.h" 30 | #include 31 | 32 | using namespace std; 33 | 34 | 35 | InterthreadQueue gQ; 36 | InterthreadMap gMap; 37 | 38 | void* qWriter(void*) 39 | { 40 | int *p; 41 | for (int i=0; i<20; i++) { 42 | p = new int; 43 | *p = i; 44 | COUT("queue write " << *p); 45 | gQ.write(p); 46 | if (random()%2) sleep(1); 47 | } 48 | p = new int; 49 | *p = -1; 50 | gQ.write(p); 51 | return NULL; 52 | } 53 | 54 | void* qReader(void*) 55 | { 56 | bool done = false; 57 | while (!done) { 58 | int *p = gQ.read(); 59 | COUT("queue read " << *p); 60 | if (*p<0) done=true; 61 | delete p; 62 | } 63 | return NULL; 64 | } 65 | 66 | 67 | void* mapWriter(void*) 68 | { 69 | int *p; 70 | for (int i=0; i<20; i++) { 71 | p = new int; 72 | *p = i; 73 | COUT("map write " << *p); 74 | gMap.write(i,p); 75 | if (random()%2) sleep(1); 76 | } 77 | return NULL; 78 | } 79 | 80 | void* mapReader(void*) 81 | { 82 | for (int i=0; i<20; i++) { 83 | int *p = gMap.read(i); 84 | COUT("map read " << *p); 85 | // InterthreadMap will delete the pointers 86 | // delete p; 87 | } 88 | return NULL; 89 | } 90 | 91 | 92 | 93 | 94 | 95 | 96 | int main(int argc, char *argv[]) 97 | { 98 | Thread qReaderThread; 99 | qReaderThread.start(qReader,NULL); 100 | Thread mapReaderThread; 101 | mapReaderThread.start(mapReader,NULL); 102 | 103 | Thread qWriterThread; 104 | qWriterThread.start(qWriter,NULL); 105 | Thread mapWriterThread; 106 | mapWriterThread.start(mapWriter,NULL); 107 | 108 | qReaderThread.join(); 109 | qWriterThread.join(); 110 | mapReaderThread.join(); 111 | mapWriterThread.join(); 112 | } 113 | 114 | 115 | // vim: ts=4 sw=4 116 | -------------------------------------------------------------------------------- /mbts/Peering/NeighborTable.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copright 2011 Range Networks, Inc. 3 | * All rights reserved. 4 | * Copyright (C) 2013-2023 Null Team Impex SRL 5 | * Copyright (C) 2014 Legba, Inc 6 | */ 7 | 8 | #include "NeighborTable.h" 9 | #include 10 | 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | using namespace Peering; 17 | using namespace std; 18 | 19 | 20 | bool NeighborTable::setNeighbors(const char* list) 21 | { 22 | // Syntax is: BAND ARFCN1:BSIC1:CELLID1 ARFCN2:BSIC2:CELLID2 ... 23 | int band,len; 24 | if (sscanf(list,"%d %n",&band,&len) != 1) 25 | return false; 26 | std::vector cells; 27 | std::vector arfcns; 28 | int bccs = 0; 29 | int lastC0 = -1; 30 | for (list += len; *list; list += len) { 31 | int c0,bsic; 32 | char id[16]; 33 | if (sscanf(list,"%d:%d:%15s %n",&c0,&bsic,id,&len) != 3 || c0 < 0 || bsic < 0 || bsic > 63) 34 | return false; 35 | cells.push_back(Neighbor(c0,bsic,id)); 36 | // Received list is already sorted by ARFCN 37 | if (c0 != lastC0) { 38 | arfcns.push_back(c0); 39 | lastC0 = c0; 40 | } 41 | bccs |= (1 << (bsic & 0x07)); 42 | } 43 | // Radio band is ignored now, we should receive only neighbors for our own band 44 | LOG(NOTICE) << "Neighbor cells: " << cells.size() << ", ARFCNs: " << arfcns.size() << ", BCCs: 0x" << hex << bccs; 45 | mLock.lock(); 46 | mNeighbors = cells; 47 | mARFCNList = arfcns; 48 | mBCCSet = bccs; 49 | mLock.unlock(); 50 | gBTS.regenerateBeacon(); 51 | return true; 52 | } 53 | 54 | std::string NeighborTable::getCellID(unsigned BCCH_FREQ_NCELL, unsigned BSIC) 55 | { 56 | // There is a potential race condition here where mARFCNList could have changed 57 | // between the sending of SI5 and the receipt of the corresponding measurement report. 58 | // That will not be a serious problem as long as BSICs are unique, 59 | // which they should be. The method will just return NULL. 60 | 61 | LOG(DEBUG) << "BCCH_FREQ_NCELL=" << BCCH_FREQ_NCELL << " BSIC=" << BSIC; 62 | ScopedLock lock(mLock); 63 | 64 | int c0 = getARFCN(BCCH_FREQ_NCELL); 65 | if (c0 < 0) return ""; 66 | for (std::vector::iterator it = mNeighbors.begin() ; it != mNeighbors.end(); ++it) 67 | if ((unsigned)c0 == it->C0 && BSIC == it->BSIC) return it->CELL_ID; 68 | return ""; 69 | } 70 | 71 | /* Return the ARFCN given its position in the BCCH channel list. 72 | * The way I read GSM 04.08 10.5.2.20, they take the ARFCNs, sort them 73 | * in ascending order, move the first to the last if it's 0, 74 | * then BCCH-FREQ-NCELL is a position in that list. 75 | */ 76 | int NeighborTable::getARFCN(unsigned BCCH_FREQ_NCELL) 77 | { 78 | LOG(DEBUG) << "BCCH_FREQ_NCELL=" << BCCH_FREQ_NCELL; 79 | ScopedLock lock(mLock); 80 | if (BCCH_FREQ_NCELL >= mARFCNList.size()) { 81 | LOG(ALERT) << "BCCH-FREQ-NCELL not in BCCH channel list"; 82 | return -1; 83 | } 84 | return mARFCNList[BCCH_FREQ_NCELL]; 85 | } 86 | 87 | -------------------------------------------------------------------------------- /mbts/A53/gea_test.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "bits.h" 8 | #include "utils.h" 9 | #include "gprs_cipher.h" 10 | #include "gea.h" 11 | 12 | void print_check(char * res, uint8_t * out, uint16_t len) { 13 | uint8_t buf[len]; 14 | osmo_hexparse(res, buf, len); 15 | if (0 != memcmp(buf, out, len)) { 16 | printf("FAIL:\n"); 17 | printf("OUT: %s\n", osmo_hexdump_nospc(out, len)); 18 | printf("EXP: %s\n", osmo_hexdump_nospc(buf, len)); 19 | } 20 | else printf("OK\n"); 21 | } 22 | 23 | void test_gea3(uint64_t kc, uint32_t iv, int dir, uint16_t len, char * res) { 24 | printf("%d: %d -> 0x%X ", len, dir, iv); 25 | uint8_t out[len]; 26 | osmo_gea3(out, len, kc, iv, dir); 27 | print_check(res, out, len); 28 | } 29 | 30 | void test_gea4(char * kc, uint32_t iv, int dir, uint16_t len, char * res) { 31 | printf("%d: %d -> 0x%X ", len, dir, iv); 32 | uint8_t out[len], ck[256]; 33 | osmo_hexparse(kc, ck, len); 34 | osmo_gea4(out, len, ck, iv, dir); 35 | print_check(res, out, len); 36 | } 37 | 38 | int main(int argc, char **argv) 39 | { 40 | // printf("GEA3 support: %d\n", gprs_cipher_supported(GPRS_ALGO_GEA3)); 41 | // printf("GEA4 support: %d\n", gprs_cipher_supported(GPRS_ALGO_GEA4)); 42 | // test vectors according to 3GPP TS 55.217 and TS 55.218 43 | test_gea3(0x2BD6459F82C5BC00LL, 0x8E9421A3, 0, 59, "5F359709DE950D0105B17B6C90194280F880B48DCCDC2AFEED415DBEF4354EEBB21D073CCBBFB2D706BD7AFFD371FC96E3970D143DCB2624054826"); 44 | test_gea3(0x952C49104881FF48LL, 0x5064DB71, 0, 59, "FDC03D738C8E14FF0320E59AAF75760799E9DA78DD8F888471C4AEAAC1849633A26CD84F459D265B83D7D9B9A0B1E54F4D75E331640DF19E0DB0E0"); 45 | test_gea3(0xEFA8B2229E720C2ALL, 0x4BDBD5E5, 1, 59, "4718A2ADFC90590949DDADAB406EC3B925F1AF1214673909DAAB96BB4C18B1374BB1E99445A81CC856E47C6E49E9DBB9873D0831B2175CA1E109BA"); 46 | test_gea3(0x3451F23A43BD2C87LL, 0x893FE14F, 0, 59, "B46B1E284E3F8B63B86D9DF0915CFCEDDF2F061895BF9F82BF2593AE4847E94A4626C393CF8941CE15EA7812690D8415B88C5730FE1F5D410E16A2"); 47 | test_gea3(0xCAA2639BE82435CFLL, 0x8FE17885, 1, 59, "9FEFAF155A26CF35603E727CDAA87BA067FD84FF98A50B7FF0EC8E95A0FB70E79CB93DEE2B7E9AB59D050E1262401571F349C68229DDF0DECC4E85"); 48 | test_gea3(0x1ACA8B448B767B39LL, 0x4F7BC3B5, 0, 59, "514F6C3A3B5A55CA190092F7BB6E80EF3EDB738FCDCE2FF90BB387DDE75BBC32A04A67B898A3DFB8198FFFC37D437CF69E7F9C13B51A868720E750"); 49 | test_gea4("D3C5D592327FB11C4035C6680AF8C6D1", 0x0A3A59B4, 0, 51, "6E217CE41EBEFB5EC8094C15974290065E42BABC9AE35654A53085CE68DFA4426A2FF0AD4AF3341006A3F84B7613ACB4FBDC34"); 50 | test_gea4("3D43C388C9581E337FF1F97EB5C1F85E", 0x48571AB9, 0, 59, "FC7314EF00A63ED0116F236C5D25C54EEC56A5B71F9F18B4D7941F84E422ACBDE5EEA9A204679002D14F312F3DEE2A1AC917C3FBDC3696143C0F5D"); 51 | test_gea4("A4496A64DF4F399F3B4506814A3E07A1", 0xEB04ADE2, 1, 59, "2AEB5970FB06B718027D048488AAF24FB3B74EA4A6B1242FF85B108FF816A303C72757D9AAD862B835D1D287DBC141D0A28D79D87BB137CD1198CD"); 52 | 53 | return 0; 54 | } 55 | -------------------------------------------------------------------------------- /mbts/CommonLibs/BitVectorTest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 Free Software Foundation, Inc. 3 | * 4 | * 5 | * This software is distributed under the terms of the GNU Affero Public License. 6 | * See the COPYING file in the main directory for details. 7 | * 8 | * This use of this software may be subject to additional restrictions. 9 | * See the LEGAL file in the main directory for details. 10 | 11 | This program is free software: you can redistribute it and/or modify 12 | it under the terms of the GNU Affero General Public License as published by 13 | the Free Software Foundation, either version 3 of the License, or 14 | (at your option) any later version. 15 | 16 | This program is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | GNU Affero General Public License for more details. 20 | 21 | You should have received a copy of the GNU Affero General Public License 22 | along with this program. If not, see . 23 | 24 | */ 25 | 26 | 27 | 28 | 29 | #include "BitVector.h" 30 | #include 31 | #include 32 | 33 | using namespace std; 34 | 35 | 36 | int main(int argc, char *argv[]) 37 | { 38 | BitVector v1("0000111100111100101011110000"); 39 | cout << v1 << endl; 40 | v1.LSB8MSB(); 41 | cout << v1 << endl; 42 | ViterbiR2O4 vCoder; 43 | BitVector v2(v1.size()*2); 44 | v1.encode(vCoder,v2); 45 | cout << v2 << endl; 46 | SoftVector sv2(v2); 47 | cout << sv2 << endl; 48 | for (unsigned i=0; i 21 | 22 | using namespace GSM; 23 | using namespace std; 24 | 25 | 26 | void L3SMSCBSerialNumber::writeV(L3Frame& l3, size_t& wp) const 27 | { 28 | l3.writeField(wp,mGS,2); 29 | l3.writeField(wp,mMessageCode,10); 30 | l3.writeField(wp,mUpdateNumber,4); 31 | } 32 | 33 | void L3SMSCBSerialNumber::text(ostream& os) const 34 | { 35 | os << "GS=" << mGS; 36 | os << " MessageCode=" << mMessageCode; 37 | os << " UpdateNumber=" << mUpdateNumber; 38 | } 39 | 40 | 41 | void L3SMSCBMessageIdentifier::writeV(L3Frame& l3, size_t& wp) const 42 | { 43 | l3.writeField(wp,mValue,16); 44 | } 45 | 46 | void L3SMSCBMessageIdentifier::text(ostream& os) const 47 | { 48 | os << hex << "0x" << mValue << dec; 49 | } 50 | 51 | 52 | void L3SMSCBDataCodingScheme::writeV(L3Frame& l3, size_t& wp) const 53 | { 54 | l3.writeField(wp,mValue,8); 55 | } 56 | 57 | void L3SMSCBDataCodingScheme::text(ostream& os) const 58 | { 59 | os << hex << "0x" << mValue << dec; 60 | } 61 | 62 | 63 | void L3SMSCBPageParameter::writeV(L3Frame& l3, size_t& wp) const 64 | { 65 | l3.writeField(wp,mNumber,4); 66 | l3.writeField(wp,mTotal,4); 67 | } 68 | 69 | void L3SMSCBPageParameter::text(ostream& os) const 70 | { 71 | os << mNumber << "/" << mTotal; 72 | } 73 | 74 | void L3SMSCBContent::writeV(L3Frame& l3, size_t& wp) const 75 | { 76 | for (unsigned i=0; i<82; i++) l3.writeField(wp,mData[i],8); 77 | } 78 | 79 | void L3SMSCBContent::text(ostream& os) const 80 | { 81 | os << hex; 82 | for (unsigned i=0; i<82; i++) os << setw(2) << (int)mData[i]; 83 | os << dec; 84 | } 85 | 86 | 87 | 88 | ostream& GSM::operator<<(ostream& os, const L3SMSCBMessage& msg) 89 | { 90 | msg.text(os); 91 | return os; 92 | } 93 | 94 | 95 | void L3SMSCBMessage::write(L3Frame& frame) const 96 | { 97 | size_t wp=0; 98 | mSerialNumber.writeV(frame,wp); 99 | mMessageIdentifier.writeV(frame,wp); 100 | mDataCodingScheme.writeV(frame,wp); 101 | mPageParameter.writeV(frame,wp); 102 | mContent.writeV(frame,wp); 103 | } 104 | 105 | void L3SMSCBMessage::text(ostream& os) const 106 | { 107 | os << "serialNumber=(" << mSerialNumber << ")"; 108 | os << " messageID=" << mMessageIdentifier; 109 | os << " DCS=" << mDataCodingScheme; 110 | os << " page=" << mPageParameter; 111 | os << " content=(" << mContent << ")"; 112 | } 113 | 114 | 115 | // vim: ts=4 sw=4 116 | -------------------------------------------------------------------------------- /INSTALL: -------------------------------------------------------------------------------- 1 | The following tools are required: 2 | - A subversion (svn) client; As root go to /usr/src or whereever you'd like to store source code 3 | - GnuMake: GNU Make is a tool which controls the generation of executables and other non-source files of a program from the program's source files 4 | - Autoconf: Autoconf is an extensible package of M4 macros that produce shell scripts to automatically configure software source code packages. 5 | - GCC: GNU Compiler Collection 6 | - libusb-1.0-0-dev: (2:0.1.12-23.3 and others) Library for programming USB applications without the knowledge of Linux kernel internals 7 | 8 | Both YateBTS and Yate can be built from a source tarball. In this case subversion and autoconf are not needed. 9 | 10 | 11 | Yate instalation 12 | ---------------- 13 | 14 | Below is a short install guide for Yate. For more detailed information please check http://docs.yate.ro/wiki/Compiling_and_installing_Yate_from_SVN 15 | 16 | The prerequisites of installing Yate are the same as above. You need at least Yate version 5.1.0 17 | 18 | To install Yate: 19 | 20 | Download Yate sources from the SVN 21 | Once you have the svn client installed, getting the sources is simple: you just type the following command in your terminal: 22 | cd /usr/src/ 23 | svn checkout http://voip.null.ro/svn/yate/trunk yate 24 | 25 | Install Yate from SVN 26 | 27 | Go to directory where Yate was downloded and run autogen.sh. This will generate the configure script that checks dependencies. 28 | Then run make install-noapi that will compile and install Yate. 29 | Instead of make install-noapi you can use make install but make sure to install doxygen or kdoc package. 30 | cd yate/ 31 | ./autogen.sh 32 | ./configure 33 | make install-noapi 34 | 35 | If you get any errors when running ./configure you'll probably have to install additional packages. 36 | 37 | If you try to run yate and get: 38 | 39 | yate: error while loading shared libraries: libyate.so.5.1.0: cannot open shared object file: No such file or directory 40 | 41 | Then run: 42 | export LD_LIBRARY_PATH=/usr/local/lib/:$LD_LIBRARY_PATH 43 | 44 | For additional information about Yate installation and configuration, please see Yate documentation Wiki: 45 | http://docs.yate.ro/wiki/Beginners_in_Yate 46 | 47 | 48 | Install YateBTS 49 | --------------- 50 | 51 | Download YateBTS 52 | 53 | You can download the sources in any directory. I choose /usr/src 54 | cd /usr/src 55 | svn checkout http://voip.null.ro/svn/yatebts/trunk yatebts 56 | 57 | Check dependencies 58 | Run autogen.sh to generate configure script that will check dependencies. 59 | cd yatebts/ 60 | ./autogen.sh 61 | ./configure 62 | 63 | If you encounter the following error then you need to install libusb1-dev or libusb1-devel and then run ./configure again. 64 | checking for libusb-1.0/libusb.h... no 65 | configure: error: This header file is required. 66 | 67 | Install YateBTS 68 | 69 | To compile and install YateBTS run: 70 | make install 71 | 72 | After this, the YateBTS modules/scripts/configurations will be moved in the appropriate directories where other Yate modules/scripts/configurations are located. 73 | -------------------------------------------------------------------------------- /nipc/auth/nipc_auth.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | # Global Yate script that performs 2G/3G authentication 4 | # 5 | # Must be placed in same directory as do_nipc_comp128 and do_nipc_milenage 6 | # 7 | # Install in extmodule.conf 8 | # 9 | # [scripts] 10 | # /path/to/nipc_auth.sh 11 | 12 | cd `dirname $0` 13 | 14 | # install in Yate and run main loop 15 | echo "%%>setlocal:trackparam:nipc_auth" 16 | echo "%%>install:95:gsm.auth" 17 | echo "%%>setlocal:restart:true" 18 | while read -r REPLY; do 19 | case "$REPLY" in 20 | %%\>message:*) 21 | # gsm.auth handling 22 | id="${REPLY#*:*}"; id="${id%%:*}" 23 | params=":${REPLY#*:*:*:*:*:}:" 24 | # extract parameters, assume we don't need unescaping 25 | rand="${params#*:rand=}"; rand="${rand%%:*}" 26 | ki="${params#*:ki=}"; ki="${ki%%:*}" 27 | op="${params#*:op=}"; op="${op%%:*}" 28 | proto="${params#*:protocol=}"; proto="${proto%%:*}" 29 | resp="" 30 | case "X$proto" in 31 | Xcomp128) 32 | case "X$op" in 33 | X1|X2|X3) 34 | proto="${proto}_${op}" 35 | ;; 36 | esac 37 | res=`./do_nipc_$proto 0x$ki 0x$rand` 38 | if [ ${#res} = 25 ]; then 39 | resp="sres=${res:0:8}:kc=${res:9}" 40 | fi 41 | ;; 42 | Xcomp128-1|Xcomp128-2|Xcomp128-3) 43 | proto="${proto:0:7}_${proto:8}" 44 | res=`./do_nipc_$proto 0x$ki 0x$rand` 45 | if [ ${#res} = 25 ]; then 46 | resp="sres=${res:0:8}:kc=${res:9}" 47 | fi 48 | ;; 49 | Xmilenage) 50 | sqn="${params#*:sqn=}"; sqn="${sqn%%:*}" 51 | auts="${params#*:auts=}"; auts="${auts%%:*}" 52 | amf="${params#*:amf=}"; amf="${amf%%:*}" 53 | if [ -n "$amf" ]; then 54 | amf=" 0x$amf" 55 | fi 56 | opc="${params#*:opc=}"; opc="${opc%%:*}" 57 | case "X$opc" in 58 | Xtrue|Xyes|Xon|Xenable|Xt|X1) 59 | opc=" --opc" 60 | ;; 61 | *) 62 | opc="" 63 | ;; 64 | esac 65 | if [ -n "$sqn" ]; then 66 | if [ -n "$auts" ]; then 67 | res=`./do_nipc_milenage$opc --auts 0x$ki 0x$op 0x$sqn 0x$rand$amf` 68 | if [ ${#res} = 28 ]; then 69 | resp="auts=${res}" 70 | fi 71 | else 72 | res=`./do_nipc_milenage$opc 0x$ki 0x$op 0x$sqn 0x$rand$amf` 73 | if [ ${#res} = 115 ]; then 74 | resp="xres=${res:0:16}:ck=${res:17:32}:ik=${res:50:32}:autn=${res:83}" 75 | fi 76 | fi 77 | else 78 | if [ -n "$auts" ]; then 79 | res=`./do_nipc_milenage$opc 0x$ki 0x$op 0x$auts 0x$rand$amf` 80 | if [ ${#res} = 12 ]; then 81 | resp="sqn=${res}" 82 | fi 83 | else 84 | autn="${params#*:autn=}"; autn="${autn%%:*}" 85 | res=`./do_nipc_milenage$opc 0x$ki 0x$op 0x$autn 0x$rand$amf` 86 | if [ ${#res} = 95 ]; then 87 | resp="xres=${res:0:16}:ck=${res:17:32}:ik=${res:50:32}:sqn=${res:83}" 88 | fi 89 | fi 90 | fi 91 | ;; 92 | esac 93 | if [ -n "$resp" ]; then 94 | echo "%%. 22 | 23 | */ 24 | 25 | 26 | #ifndef TIMEVAL_H 27 | #define TIMEVAL_H 28 | 29 | #include 30 | #include "sys/time.h" 31 | #include 32 | #include 33 | 34 | 35 | 36 | /** A wrapper on usleep to sleep for milliseconds. */ 37 | inline void msleep(long v) { usleep(v*1000); } 38 | 39 | 40 | /** A C++ wrapper for struct timeval. */ 41 | class Timeval { 42 | 43 | private: 44 | 45 | struct timeval mTimeval; 46 | 47 | public: 48 | 49 | /** Set the value to gettimeofday. */ 50 | void now() { gettimeofday(&mTimeval,NULL); } 51 | 52 | /** Set the value to gettimeofday plus an offset. */ 53 | void future(unsigned ms); 54 | 55 | //@{ 56 | Timeval(unsigned sec, unsigned usec) 57 | { 58 | mTimeval.tv_sec = sec; 59 | mTimeval.tv_usec = usec; 60 | } 61 | 62 | Timeval(const struct timeval& wTimeval) 63 | :mTimeval(wTimeval) 64 | {} 65 | 66 | /** 67 | Create a Timeval offset into the future. 68 | @param offset milliseconds 69 | */ 70 | Timeval(unsigned offset=0) { future(offset); } 71 | //@} 72 | 73 | /** Convert to a struct timespec. */ 74 | struct timespec timespec() const; 75 | 76 | /** Return total seconds. */ 77 | double seconds() const; 78 | 79 | uint32_t sec() const { return mTimeval.tv_sec; } 80 | uint32_t usec() const { return mTimeval.tv_usec; } 81 | 82 | /** Return difference from other (other-self), in ms. */ 83 | long delta(const Timeval& other) const; 84 | 85 | /** Elapsed time in ms. */ 86 | long elapsed() const { return delta(Timeval()); } 87 | 88 | /** Remaining time in ms. */ 89 | long remaining() const { return -elapsed(); } 90 | 91 | /** Return true if the time has passed, as per gettimeofday. */ 92 | bool passed() const; 93 | 94 | /** Add a given number of minutes to the time. */ 95 | void addMinutes(unsigned minutes) { mTimeval.tv_sec += minutes*60; } 96 | 97 | }; 98 | 99 | std::ostream& operator<<(std::ostream& os, const Timeval&); 100 | 101 | std::ostream& operator<<(std::ostream& os, const struct timespec&); 102 | 103 | 104 | #endif 105 | // vim: ts=4 sw=4 106 | -------------------------------------------------------------------------------- /mbts/Connection/GprsConnMap.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * GprsConnMap.cpp 3 | * This file is part of the Yate-BTS Project http://www.yatebts.com 4 | * 5 | * Connection to GPRS info mapper 6 | * 7 | * Yet Another Telephony Engine - Base Transceiver Station 8 | * Copyright (C) 2014-2023 Null Team Impex SRL 9 | * Copyright (C) 2014 Legba, Inc 10 | * 11 | * This software is distributed under multiple licenses; 12 | * see the COPYING file in the main directory for licensing 13 | * information for this specific distribution. 14 | * 15 | * This use of this software may be subject to additional restrictions. 16 | * See the LEGAL file in the main directory for details. 17 | * 18 | * This program is distributed in the hope that it will be useful, 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 21 | */ 22 | 23 | #include "GprsConnMap.h" 24 | 25 | #include 26 | 27 | #include 28 | 29 | using namespace Connection; 30 | 31 | 32 | GprsConnMap::GprsConnMap() 33 | : mIndex(0) 34 | { 35 | memset(mMap,0,sizeof(mMap)); 36 | } 37 | 38 | int GprsConnMap::map(SGSN::SgsnInfo* info) 39 | { 40 | if (!info) 41 | return -1; 42 | int id = find(info); 43 | if (id >= 0) 44 | return id; 45 | lock(); 46 | unsigned int i = mIndex; 47 | for (;;) { 48 | i = (i + 1) % BTS_GPRS_MAP_SIZE; 49 | if (i == mIndex) 50 | break; 51 | if (!mMap[i].mInfo) { 52 | mMap[i].mInfo = info; 53 | mIndex = i; 54 | id = BTS_GPRS_MAP_BASE + i; 55 | break; 56 | } 57 | } 58 | unlock(); 59 | if (id < 0) 60 | LOG(CRIT) << "connection map is full!"; 61 | return id; 62 | } 63 | 64 | void GprsConnMap::remap(SGSN::SgsnInfo* info, unsigned int id) 65 | { 66 | if (id < BTS_GPRS_MAP_BASE) 67 | return; 68 | id -= BTS_GPRS_MAP_BASE; 69 | if (id < BTS_GPRS_MAP_SIZE) 70 | mMap[id].mInfo = info; 71 | } 72 | 73 | SGSN::SgsnInfo* GprsConnMap::unmap(unsigned int id) 74 | { 75 | if (id < BTS_GPRS_MAP_BASE) 76 | return 0; 77 | id -= BTS_GPRS_MAP_BASE; 78 | if ((id < BTS_GPRS_MAP_SIZE) && mMap[id].mInfo) { 79 | SGSN::SgsnInfo* info = mMap[id].mInfo; 80 | mMap[id].mInfo = 0; 81 | return info; 82 | } 83 | return 0; 84 | } 85 | 86 | bool GprsConnMap::unmap(const SGSN::SgsnInfo* info) 87 | { 88 | if (!info) 89 | return false; 90 | for (unsigned int i = 0; i < BTS_GPRS_MAP_SIZE; i++) { 91 | Conn& c = mMap[i]; 92 | if (c.mInfo == info) { 93 | lock(); 94 | if (c.mInfo == info) { 95 | c.mInfo = 0; 96 | } 97 | unlock(); 98 | return true; 99 | } 100 | } 101 | return false; 102 | } 103 | 104 | int GprsConnMap::find(const SGSN::SgsnInfo* info) 105 | { 106 | for (unsigned int i = 0; i < BTS_GPRS_MAP_SIZE; i++) { 107 | if (mMap[i].mInfo == info) 108 | return BTS_GPRS_MAP_BASE + i; 109 | } 110 | return -1; 111 | } 112 | 113 | SGSN::SgsnInfo* GprsConnMap::find(unsigned int id) 114 | { 115 | if (id < BTS_GPRS_MAP_BASE) 116 | return 0; 117 | id -= BTS_GPRS_MAP_BASE; 118 | return (id < BTS_GPRS_MAP_SIZE) ? mMap[id].mInfo : 0; 119 | } 120 | 121 | /* vi: set ts=8 sw=4 sts=4 noet: */ 122 | -------------------------------------------------------------------------------- /mbts/GPRS/GPRSTDMA.h: -------------------------------------------------------------------------------- 1 | /**@file GPRS TDMA parameters. */ 2 | /* 3 | * Copyright 2011 Range Networks, Inc. 4 | * All Rights Reserved. 5 | * 6 | * This software is distributed under multiple licenses; 7 | * see the COPYING file in the main directory for licensing 8 | * information for this specific distribuion. 9 | * 10 | * This use of this software may be subject to additional restrictions. 11 | * See the LEGAL file in the main directory for details. 12 | 13 | This program is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 16 | 17 | */ 18 | 19 | 20 | #ifndef GPRSTDMA_H 21 | #define GPRSTDMA_H 22 | 23 | 24 | #include "GSMCommon.h" 25 | #include "GSMTDMA.h" 26 | 27 | namespace GPRS { 28 | // (pat) We wont use this to program the radio right now, and probably never. 29 | // However, it is needed to init a LogicalChannel. The info needs to duplicate 30 | // that for an RR TCH, which is what we are really using. 31 | // Currently we will hook to the existing RR logical channels to get RLC blocks. 32 | // In the future, we probably would not use this either, we would probably modify 33 | // TRXManager to send the entire channel stream directly to us, and then direct 34 | // the packets internally; not use the ARFCNManager::mDemuxTable, 35 | // which is what this TDMA_MAPPING is primarily for. 36 | 37 | /** A macro to save some typing when we set up TDMA maps. */ 38 | // This is copied from ../GSM/GSMTDMA.cpp 39 | #define MAKE_TDMA_MAPPING(NAME,TYPEANDOFFSET,DOWNLINK,UPLINK,ALLOWEDSLOTS,C0ONLY,REPEAT) \ 40 | const GSM::TDMAMapping g##NAME##Mapping(TYPEANDOFFSET,DOWNLINK,UPLINK,ALLOWEDSLOTS,C0ONLY, \ 41 | REPEAT,sizeof(NAME##Frames)/sizeof(unsigned),NAME##Frames) 42 | 43 | 44 | /** PDCH TDMA from GSM 03.64 6.1.2, GSM 05.02 Clause 7 Table 6 of 9. */ 45 | // (pat) This was the orignal; does not look correct to me: 46 | // const unsigned PDCHFrames[] = {0,1,2,3, 4,5,6,7, 8,9,10,11, 13,14,15,16, 16,17,18,19, 47 | // 20,21,22,23, 25,26,27,28, 29,30,31,32, 33,34,35,36, 38,39,40,41, 42,43,44,45, 46,47,48,49}; 48 | 49 | // (pat) This is first line (PDTCH/F PACCH/F) of GSM05.02 clause 7 table 6 of 9 50 | // Note that we skip over frames 12, 25, 38 and 51, which are used for other purposes. 51 | // TODO: I dont know if we are going to handle the frame mapping this way, 52 | // or let the GPRS code handle all the frames, including the PTCCH (timing advance) slots. 53 | const unsigned PDTCHFFrames[] = {0,1,2,3, 4,5,6,7, 8,9,10,11, 13,14,15,16, 17,18,19,20, 54 | 21,22,23,24, 26,27,28,29, 30,31,32,33, 34,35,36,37, 39,40,41,42, 43,44,45,46, 47,48,49,50 }; 55 | const unsigned PTCCHFrames[] = { 12, 38 }; 56 | const unsigned PDIdleFrames[] = { 25, 51 }; 57 | 58 | // PDCH is the name of the packet data channel, comprised of PDTCH, PTCCH, and 2 idle frames. 59 | MAKE_TDMA_MAPPING(PDTCHF,GSM::TDMA_PDTCHF,true,true,0xff,false,52); // Makes gPDTCHFMapping 60 | MAKE_TDMA_MAPPING(PTCCH,GSM::TDMA_PTCCH,true,false,0xff,false,52); 61 | MAKE_TDMA_MAPPING(PDIdle,GSM::TDMA_PDIDLE,true,false,0xff,false,52); 62 | 63 | const GSM::MappingPair gPDTCHPair(gPDTCHFMapping,gPDTCHFMapping); 64 | const GSM::MappingPair gPTCCHPair(gPTCCHMapping); 65 | 66 | 67 | }; // namespace GPRS 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /mbts/Globals/Globals.cpp: -------------------------------------------------------------------------------- 1 | /**@file Global system parameters. */ 2 | /* 3 | * Copyright 2008, 2009, 2010 Free Software Foundation, Inc. 4 | * Copyright 2010 Kestrel Signal Processing, Inc. 5 | * Copyright 2011, 2012 Range Networks, Inc. 6 | * Copyright (C) 2013-2023 Null Team Impex SRL 7 | * Copyright (C) 2014 Legba, Inc 8 | * 9 | * This software is distributed under multiple licenses; 10 | * see the COPYING file in the main directory for licensing 11 | * information for this specific distribuion. 12 | * 13 | * This use of this software may be subject to additional restrictions. 14 | * See the LEGAL file in the main directory for details. 15 | 16 | This program is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 19 | 20 | */ 21 | 22 | #include 23 | #include 24 | #include 25 | //#include 26 | //#include 27 | #include 28 | 29 | #define PROD_CAT "P" 30 | 31 | #define FEATURES "+GPRS " 32 | 33 | const char *gVersionString = "release " PACKAGE_VERSION " built " __DATE__ " rev" PACKAGE_REVISION " "; 34 | 35 | const char* gOpenBTSWelcome = 36 | //23456789123456789223456789323456789423456789523456789623456789723456789 37 | "Yate-BTS MBTS Component\n" 38 | "Copyright 2008, 2009, 2010 Free Software Foundation, Inc.\n" 39 | "Copyright 2010 Kestrel Signal Processing, Inc.\n" 40 | "Copyright 2011, 2012, 2013 Range Networks, Inc.\n" 41 | "Copyright 2013, 2014-2023 Null Team Impex SRL\n" 42 | "Copyright 2014 Legba, Inc.\n" 43 | "\"OpenBTS\" is a registered trademark of Range Networks, Inc.\n" 44 | "\nContributors:\n" 45 | " SC Null Team Impex SRL:\n" 46 | " Paul Chitescu\n" 47 | " Legba, Inc.\n" 48 | " David Burgess\n" 49 | " Range Networks, Inc.:\n" 50 | " David Burgess, Harvind Samra, Donald Kirker, Doug Brown,\n" 51 | " Pat Thompson, Kurtis Heimerl\n" 52 | " Kestrel Signal Processing, Inc.:\n" 53 | " David Burgess, Harvind Samra, Raffi Sevlian, Roshan Baliga\n" 54 | " GNU Radio:\n" 55 | " Johnathan Corgan\n" 56 | " Others:\n" 57 | " Anne Kwong, Jacob Appelbaum, Joshua Lackey, Alon Levy\n" 58 | " Alexander Chemeris, Alberto Escudero-Pascual\n" 59 | "Incorporated L/GPL libraries and components:\n" 60 | " libusb, LGPL 2.1, various copyright holders, www.libusb.org\n" 61 | "Incorporated BSD/MIT-style libraries and components:\n" 62 | " A5/1 Pedagogical Implementation, Simplified BSD License,\n" 63 | " Copyright 1998-1999 Marc Briceno, Ian Goldberg, and David Wagner\n" 64 | "Incorporated public domain libraries and components:\n" 65 | " sqlite3, released to public domain 15 Sept 2001, www.sqlite.org\n" 66 | "\n" 67 | "\nThis program comes with ABSOLUTELY NO WARRANTY.\n" 68 | "\nUse of this software may be subject to other legal restrictions,\n" 69 | "including patent licensing and radio spectrum licensing.\n" 70 | "All users of this software are expected to comply with applicable\n" 71 | "regulations and laws. See the LEGAL file in the source code for\n" 72 | "more information.\n" 73 | "\n" 74 | "Release " PACKAGE_VERSION " formal build date " __DATE__ " rev" PACKAGE_REVISION "\n" 75 | ; 76 | 77 | 78 | CommandLine::Parser gParser; 79 | 80 | -------------------------------------------------------------------------------- /mbts/GSM/GSMSAPMux.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 Free Software Foundation, Inc. 3 | * 4 | * This software is distributed under multiple licenses; see the COPYING file in the main directory for licensing information for this specific distribuion. 5 | * 6 | * This use of this software may be subject to additional restrictions. 7 | * See the LEGAL file in the main directory for details. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | 13 | */ 14 | 15 | 16 | 17 | #ifndef SAPMUX_H 18 | #define SAPMUX_H 19 | 20 | #include "GSMTransfer.h" 21 | #include "GSML1FEC.h" 22 | 23 | #include 24 | 25 | namespace GSM { 26 | 27 | class L2DL; 28 | 29 | 30 | /** 31 | A SAPMux is a multipexer the connects a single L1 to multiple L2s. 32 | A "service access point" in GSM/ISDN is analogous to port number in IP. 33 | GSM allows up to 4 SAPs, although only two are presently used. 34 | See GSM 04.05 5.2 for an introduction. 35 | (pat) SAPs exist at every level in the OSI model. This should probably be called L2SAPMux. 36 | */ 37 | class SAPMux { 38 | 39 | protected: 40 | 41 | mutable Mutex mLock; 42 | L2DL * mUpstream[4]; ///< one L2 for each SAP, GSM 04.05 5.3 43 | L1FEC * mDownstream; ///< a single L1 44 | 45 | public: 46 | 47 | SAPMux(){ 48 | mUpstream[0] = NULL; 49 | mUpstream[1] = NULL; 50 | mUpstream[2] = NULL; 51 | mUpstream[3] = NULL; 52 | mDownstream = NULL; 53 | } 54 | 55 | virtual ~SAPMux() {} 56 | 57 | virtual void writeHighSide(const L2Frame& frame); 58 | virtual void writeLowSide(const L2Frame& frame); 59 | 60 | void upstream( L2DL * wUpstream, unsigned wSAPI=0 ) 61 | { assert(mUpstream[wSAPI]==NULL); mUpstream[wSAPI]=wUpstream; } 62 | void downstream( L1FEC * wDownstream ) 63 | { assert(mDownstream==NULL); mDownstream=wDownstream; } 64 | 65 | }; 66 | 67 | 68 | 69 | 70 | /** 71 | The LoopbackSAPMux is a test fixture. 72 | Writes to the high side are eachoed back to the high side. 73 | Writes to the low side are echoed back to the low side. 74 | */ 75 | class LoopbackSAPMux : public SAPMux { 76 | 77 | public: 78 | 79 | LoopbackSAPMux():SAPMux() {} 80 | 81 | void writeHighSide(const L2Frame& frame); 82 | void writeLowSide(const L2Frame& frame); 83 | 84 | }; 85 | 86 | 87 | /** 88 | The L1TestPointSAPMux is a test fixture. 89 | Writes to the high side pass through to the low side. 90 | Writes to the low side are dumped to cout. 91 | */ 92 | class L1TestPointSAPMux : public SAPMux { 93 | 94 | public: 95 | 96 | L1TestPointSAPMux():SAPMux() {} 97 | ~L1TestPointSAPMux() {} 98 | 99 | // These are defined in the .h so that we 100 | // don't have to link in all of L2 to 101 | // use them. 102 | 103 | void writeHighSide(const L2Frame& frame) 104 | { 105 | assert(mDownstream); 106 | mLock.lock(); 107 | mDownstream->writeHighSide(frame); 108 | mLock.unlock(); 109 | } 110 | 111 | void writeLowSide(const L2Frame& frame) 112 | { 113 | LOG(DEBUG) << "SAPMux::writeLowSide frame=" << frame; 114 | } 115 | 116 | }; 117 | 118 | 119 | 120 | 121 | } // namespace GSM 122 | 123 | 124 | #endif 125 | // vim: ts=4 sw=4 126 | -------------------------------------------------------------------------------- /mbts/LEGAL: -------------------------------------------------------------------------------- 1 | OpenBTS 2 | 3 | Most parts copyright 2008-2011 Free Software Foundation. 4 | Some parts copyright 2010 Kestrel Signal Processing, Inc. 5 | Some parts copyright 2011-2013 Range Networks, Inc. 6 | Some parts copyright 2014-2023 SC Null Team Impex SRL. 7 | Some parts copyeight 2014 Legba, Inc. 8 | 9 | 10 | Patent Laws 11 | 12 | The use of this software to provide GSM services may result in the use of 13 | patented technologies. The user of this software is required to take whatever 14 | actions are necessary to avoid patent infringement. 15 | 16 | 17 | Trademark 18 | 19 | "OpenBTS" is a registered trademark of Range Networks, Inc. (Range), a 20 | California corporation. Range reserves the right to control the use of this 21 | trademark. Do not use this trademark in commerce without permission and do not 22 | rebrand OpenBTS under a different trademark. 23 | 24 | That said, Yate-BTS is not OpenBTS, but a derivative work, allowed under AGPLv3 25 | and substantially different in design. 26 | 27 | 28 | Telecom and Radio Spectrum Laws 29 | 30 | The primary function of Yate-BTS is the provision of telecommunications service 31 | over a radio link. This activity is heavily regulated nearly everywhere in 32 | the world. Users of this software are expected to comply with local and national 33 | regulations in the jurisdictions where this sortware is used with radio equipment. 34 | 35 | 36 | Legal Summary 37 | 38 | The user of this software is expected to comply with all applicable laws and 39 | regulations, including patent laws, copyright laws, and telecommunications 40 | regulations. 41 | 42 | The legal restrictions listed here are not necessarily exhaustive. 43 | 44 | 45 | Note to ALL GOVERNMENT USERS, EVERYWHERE IN THE WORLD 46 | 47 | THE USE OF THIS SOFTWARE IN ACTIVE INTELLIGENCE GATHERING NECESSARILY 48 | VIOLATES THE TERMS OF THE AGPLv3 LICENSE, SINCE SUCH A LICENSE REQUIRES 49 | NOTIFICATION OF AGPLv3 RIGHTS TO THE TARGETS OF SAID INTELLIGENCE GATHERING. 50 | 51 | We seriously doubt that you are approaching your targets and giving 52 | them the URL to the public release web site, so it is reasonable to 53 | assume that you are in violation. :) 54 | 55 | 56 | Note to US Government Users 57 | 58 | The Yate-BTS software applications and associated documentation are "Commercial 59 | Item(s)," as that term is defined at 48 C.F.R. Section 2.101, consisting of 60 | "Commercial Computer Software" and "Commercial Computer Software Documentation," 61 | as such terms are used in 48 C.F.R. 12.212 or 48 C.F.R. 227.7202, as 62 | applicable. Consistent with 48 C.F.R. 12.212 or 48 C.F.R. Sections 227.7202-1 63 | through 227.7202-4, as applicable, the Commercial Computer Software and 64 | Commercial Computer Software Documentation are being licensed to U.S. Government 65 | end users (a) only as Commercial Items and (b) with only those rights as are 66 | granted to all other end users pursuant to the terms and conditions of AGPLv3. 67 | 68 | 69 | Note to US Government Contractors 70 | 71 | AGPLv3 is not compatible with "government purpose rights" (GPR). If you receive 72 | this software under AGPLv3 and deliver it under GPR, you will be in violation 73 | of the license and subject to enforcement actions by the original authors 74 | and copyright holders, including Legba, Inc., SC Null Team Impex SRL and 75 | the Free Software Foundation, Inc. 76 | 77 | -------------------------------------------------------------------------------- /nipc/auth/test_crypto.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | all0="000000000000" 4 | 5 | test=`./do_nipc_milenage 0xA82573E41613C37D8F8F1EBC829FBF5C 0x467D46FB75EEC4DB1548EBE3D2004EFF 0x753fd2894f2f2455c152b23a7c40 0x6374409263c9b4f62bd7cf2665b1c054` 6 | if [ "x$test" = "x$all0" ]; then 7 | echo "MILENAGE test 1 OK" 8 | else 9 | echo "MILENAGE test 1 failed: got '$test', expecting '$all0'" >&2 10 | fi 11 | 12 | test=`./do_nipc_milenage 0xA82573E41613C37D8F8F1EBC829FBF5C 0x467D46FB75EEC4DB1548EBE3D2004EFF 0xBAC45D181DB00FCB3A76339051E7 0x337F180A6F0FA6921E21040E7A09D9A2` 13 | if [ "x$test" = "x$all0" ]; then 14 | echo "MILENAGE test 2 OK" 15 | else 16 | echo "MILENAGE test 2 failed: got '$test', expecting '$all0'" >&2 17 | fi 18 | 19 | exp="F7A6A2CA54261C0A 9E0AFBCF1144DA7692746FF52C9A35EC 67CC2BD2BD96FF16C6A19E5C10753D1B 343A26789DC70000EF4765A1B6DD016D" 20 | test=`./do_nipc_milenage 0x5B238655E11E37717D7DD8E7B2A6378C 0x467D46FB75EEC4DB1548EBE3D2004EFF 0x00000000011C 0x88F2AC8A88F0F7CEC9D72CB29DB58DB0` 21 | if [ "x$test" = "x$exp" ]; then 22 | echo "MILENAGE test 3 OK" 23 | else 24 | echo "MILENAGE test 3 failed: got '$test', expecting '$exp'" >&2 25 | fi 26 | 27 | exp="F7A6A2CA54261C0A 9E0AFBCF1144DA7692746FF52C9A35EC 67CC2BD2BD96FF16C6A19E5C10753D1B 00000000011C" 28 | test=`./do_nipc_milenage 0x5B238655E11E37717D7DD8E7B2A6378C 0x467D46FB75EEC4DB1548EBE3D2004EFF 0x343A26789DC70000EF4765A1B6DD016D 0x88F2AC8A88F0F7CEC9D72CB29DB58DB0` 29 | if [ "x$test" = "x$exp" ]; then 30 | echo "MILENAGE test 4 OK" 31 | else 32 | echo "MILENAGE test 4 failed: got '$test', expecting '$exp'" >&2 33 | fi 34 | 35 | exp="BAC45D181DB00FCB3A76339051E7" 36 | test=`./do_nipc_milenage --auts 0xA82573E41613C37D8F8F1EBC829FBF5C 0x467D46FB75EEC4DB1548EBE3D2004EFF 0x000000000000 0x337F180A6F0FA6921E21040E7A09D9A2` 37 | if [ "x$test" = "x$exp" ]; then 38 | echo "MILENAGE test 5 OK" 39 | else 40 | echo "MILENAGE test 5 failed: got '$test', expecting '$exp'" >&2 41 | fi 42 | 43 | exp="F7A6A2CA54261C0A 9E0AFBCF1144DA7692746FF52C9A35EC 67CC2BD2BD96FF16C6A19E5C10753D1B 343A26789DC790014D8EE02734ACC628" 44 | test=`./do_nipc_milenage --opc 0x5B238655E11E37717D7DD8E7B2A6378C 0xBEC199A5AFB432DF7E7A3E457A992668 0x00000000011C 0x88F2AC8A88F0F7CEC9D72CB29DB58DB0 0x9001` 45 | if [ "x$test" = "x$exp" ]; then 46 | echo "MILENAGE test 6 OK" 47 | else 48 | echo "MILENAGE test 6 failed: got '$test', expecting '$exp'" >&2 49 | fi 50 | 51 | exp="BAC45D181DB00FCB3A76339051E7" 52 | test=`./do_nipc_milenage --opc --auts 0xA82573E41613C37D8F8F1EBC829FBF5C 0xC69B87AF18CEFEB6FB0083BA51E8D200 0x000000000000 0x337F180A6F0FA6921E21040E7A09D9A2` 53 | if [ "x$test" = "x$exp" ]; then 54 | echo "MILENAGE test 7 OK" 55 | else 56 | echo "MILENAGE test 7 failed: got '$test', expecting '$exp'" >&2 57 | fi 58 | 59 | 60 | exp="F38D6AE6 251D97EBBECE7000" 61 | test=`./do_nipc_comp128 0xFE328519ACE736DCE836AD893BCE8721 0xEFEDB342A03A4D38E7AB8CEE4E133D1A` 62 | if [ "x$test" = "x$exp" ]; then 63 | echo "COMP128 test 1 OK" 64 | else 65 | echo "COMP128 test 1 failed: got '$test', expecting '$exp'" >&2 66 | fi 67 | 68 | exp="0DF072B6 5DE5E352FD076000" 69 | test=`./do_nipc_comp128 0xFE328519ACE736DCE836AD893BCE8721 0x8CBF6C5893F0F9489BF9C8064B2DA276` 70 | if [ "x$test" = "x$exp" ]; then 71 | echo "COMP128 test 2 OK" 72 | else 73 | echo "COMP128 test 2 failed: got '$test', expecting '$exp'" >&2 74 | fi 75 | -------------------------------------------------------------------------------- /mbts/CommonLibs/Reporting.h: -------------------------------------------------------------------------------- 1 | /**@file Module for performance-reporting mechanisms. */ 2 | /* 3 | * Copyright 2012, 2013 Range Networks, Inc. 4 | * 5 | * This software is distributed under the terms of the GNU Affero Public License. 6 | * See the COPYING file in the main directory for details. 7 | * 8 | * This use of this software may be subject to additional restrictions. 9 | * See the LEGAL file in the main directory for details. 10 | 11 | This program is free software: you can redistribute it and/or modify 12 | it under the terms of the GNU Affero General Public License as published by 13 | the Free Software Foundation, either version 3 of the License, or 14 | (at your option) any later version. 15 | 16 | This program is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | GNU Affero General Public License for more details. 20 | 21 | You should have received a copy of the GNU Affero General Public License 22 | along with this program. If not, see . 23 | 24 | */ 25 | 26 | #ifndef REPORTING_H 27 | #define REPORTING_H 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | typedef std::map ReportBatch; 37 | 38 | /** 39 | Collect performance statistics into a database. 40 | Parameters are counters or max/min trackers, all integer. 41 | */ 42 | class ReportingTable { 43 | 44 | private: 45 | 46 | sqlite3* mDB; ///< database connection 47 | int mFacility; ///< rsyslogd facility 48 | ReportBatch mBatch; ///< batch of report updates, not yet stored in the db 49 | mutable Mutex mLock; ///< control for multithreaded read/write access to the batch 50 | Thread mBatchCommitter; ///< thread responsible for committing batches of report updates to the db 51 | 52 | 53 | 54 | public: 55 | 56 | /** 57 | Open the database connection; 58 | create the table if it does not exist yet. 59 | */ 60 | ReportingTable(const char* filename); 61 | 62 | /** Create a new parameter. */ 63 | bool create(const char* paramName); 64 | 65 | /** Create an indexed parameter set. */ 66 | bool create(const char* baseBame, unsigned minIndex, unsigned maxIndex); 67 | 68 | /** Increment a counter. */ 69 | bool incr(const char* paramName); 70 | 71 | /** Increment an indexed counter. */ 72 | bool incr(const char* baseName, unsigned index); 73 | 74 | /** Take a max of a parameter. */ 75 | bool max(const char* paramName, unsigned newVal); 76 | 77 | /** Take a max of an indexed parameter. */ 78 | bool max(const char* paramName, unsigned index, unsigned newVal); 79 | 80 | /** Clear the whole table. */ 81 | bool clear(); 82 | 83 | /** Clear a value. */ 84 | bool clear(const char* paramName); 85 | 86 | /** Clear an indexed value. */ 87 | bool clear(const char* paramName, unsigned index); 88 | 89 | /** Dump the database to a stream. */ 90 | void dump(std::ostream&) const; 91 | 92 | /** Commit outstanding report updates to the database */ 93 | bool commit(); 94 | }; 95 | 96 | /** Periodically triggers ReportingTable::commit(). */ 97 | void* reportingBatchCommitter(void*); 98 | 99 | #endif 100 | 101 | 102 | // vim: ts=4 sw=4 103 | -------------------------------------------------------------------------------- /mbts/A53/a53test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | void printer(int which, const char *label, u8 *vector, int lth) 9 | { 10 | cout << " block" << which << " " << label << " = "; 11 | int i; 12 | for (i = 0; i < lth; i++) { 13 | cout << hex << std::setw(2) << setfill('0') << (int)vector[i] << dec; 14 | } 15 | } 16 | 17 | void check(int which, u8 *exp, u8 *got) 18 | { 19 | printer(which, "exp", exp, 15); 20 | printer(which, "got", got, 15); 21 | int err = 0; 22 | int i; 23 | for (i = 0; i < 15; i++) { 24 | if (exp[i] == got[i]) continue; 25 | err = 1; 26 | break; 27 | } 28 | if (err) { 29 | cout << " ERROR" << endl; 30 | } else { 31 | cout << " ok" << endl; 32 | } 33 | } 34 | 35 | int unhex(const char c) 36 | { 37 | if (c >= '0' && c <= '9') return c - '0'; 38 | if (c >= 'A' && c <= 'F') return c - 'A' + 10; 39 | cout << "oops" << endl; 40 | exit(1); 41 | } 42 | 43 | int seti(const char *src) 44 | { 45 | int r = 0; 46 | for ( ; *src != 0; src++) { 47 | r = (r << 4) + unhex(*src); 48 | } 49 | return r; 50 | } 51 | 52 | void setu8(u8 *dst, const char *src) 53 | { 54 | for ( ; *src != 0; src += 2) { 55 | *dst++ = (unhex(src[0]) << 4) | (unhex(src[1])); 56 | } 57 | } 58 | 59 | int main() 60 | { 61 | int i, keylth; 62 | unsigned int count; 63 | u8 key[16], exp1[15], exp2[15], got1[15], got2[15]; 64 | const char *data[52] = { 65 | "2BD6459F82C5BC00", "24F20F", "889EEAAF9ED1BA1ABBD8436232E440", "5CA3406AA244CF69CF047AADA2DF40", 66 | "952C49104881FF48", "061527", "AB7DB38A573A325DAA76E4CB800A40", "4C4B594FEA9D00FE8978B7B7BC1080", 67 | "EFA8B2229E720C2A", "33FD3F", "0E4015755A336469C3DD8680E30340", "6F10669E2B4E18B042431A28E47F80", 68 | "3451F23A43BD2C87", "0E418C", "75F7C4C51560905DFBA05E46FB54C0", "192C95353CDF979E054186DF15BF00", 69 | "CAA2639BE82435CF", "2FF229", "301437E4D4D6565D4904C631606EC0", "F0A3B8795E264D3E1A82F684353DC0", 70 | "7AE67E87400B9FA6", "2F24E5", "F794290FEF643D2EA348A7796A2100", "CB6FA6C6B8A705AF9FEFE975818500", 71 | "58AF69935540698B", "05446B", "749CA4E6B691E5A598C461D5FE4740", "31C9E444CD04677ADAA8A082ADBC40", 72 | "017F81E5F236FE62", "156B26", "2A6976761E60CC4E8F9F52160276C0", "A544D8475F2C78C35614128F1179C0", 73 | "1ACA8B448B767B39", "0BC3B5", "A4F70DC5A2C9707F5FA1C60EB10640", "7780B597B328C1400B5C74823E8500", 74 | // "5ACB1D644C0D512041A5", "1D5157", "8EFAEC49C355CCD995C2BF649FD480", "F3A2910CAEDF587E976171AAF33B80", 75 | // "9315819243A043BEBE6E", "2E196F", "AA08DB46DD3DED78A612085C529D00", "0250463DA0E3886F9BC2E3BB0D73C0", 76 | // "3D43C388C9581E337FF1F97EB5C1F85E", "35D2CF", "A2FE3034B6B22CC4E33C7090BEC340", "170D7497432FF897B91BE8AECBA880", 77 | // "A4496A64DF4F399F3B4506814A3E07A1", "212777", "89CDEE360DF9110281BCF57755A040", "33822C0C779598C9CBFC49183AF7C0", 78 | }; 79 | for (i = 32; i>=0; i-=4) { 80 | cout << "test set " << (1+i/4) << endl; 81 | setu8(key, data[i]); 82 | keylth = strlen(data[i])*4; 83 | count = seti(data[i+1]); 84 | A53_GSM(key, keylth, count, got1, got2); 85 | setu8(exp1, data[i+2]); 86 | setu8(exp2, data[i+3]); 87 | check(1, exp1, got1); 88 | check(2, exp2, got2); 89 | } 90 | cout << "time test" << endl; 91 | int n = 10000; 92 | float t = clock(); 93 | for (i = 0; i < n; i++) { 94 | A53_GSM(key, keylth, count, got1, got2); 95 | } 96 | t = (clock() - t) / (CLOCKS_PER_SEC * (float)n); 97 | cout << "GSM takes " << t << " seconds per iteration" << endl; 98 | exit(0); 99 | } 100 | -------------------------------------------------------------------------------- /mbts/CommonLibs/MemoryLeak.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011 Range Networks, Inc. 3 | * All Rights Reserved. 4 | * 5 | * This software is distributed under multiple licenses; 6 | * see the COPYING file in the main directory for licensing 7 | * information for this specific distribuion. 8 | * 9 | * This use of this software may be subject to additional restrictions. 10 | * See the LEGAL file in the main directory for details. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 15 | */ 16 | #ifndef _MEMORYLEAK_ 17 | #define _MEMORYLEAK_ 1 18 | #include 19 | #include "ScalarTypes.h" 20 | #include "Logger.h" 21 | 22 | namespace Utils { 23 | 24 | struct MemStats { 25 | // Enumerates the classes that are checked. 26 | // Redundancies are ok, for example, we check BitVector and also 27 | // several descendants of BitVector. 28 | enum MemoryNames { 29 | mZeroIsUnused, 30 | mVector, 31 | mVectorData, 32 | mBitVector, 33 | mByteVector, 34 | mByteVectorData, 35 | mRLCRawBlock, 36 | mRLCUplinkDataBlock, 37 | mRLCMessage, 38 | mRLCMsgPacketDownlinkDummyControlBlock, // Redundant with RLCMessage 39 | mTBF, 40 | mLlcEngine, 41 | mSgsnDownlinkMsg, 42 | mRachInfo, 43 | mPdpPdu, 44 | mFECDispatchInfo, 45 | mL3Frame, 46 | msignalVector, 47 | mSoftVector, 48 | mScramblingCode, 49 | mURlcDownSdu, 50 | mURlcPdu, 51 | // Must be last: 52 | mMax, 53 | }; 54 | int mMemTotal[mMax]; // In elements, not bytes. 55 | int mMemNow[mMax]; 56 | const char *mMemName[mMax]; 57 | MemStats(); 58 | void memChkNew(MemoryNames memIndex, const char *id); 59 | void memChkDel(MemoryNames memIndex, const char *id); 60 | void text(std::ostream &os); 61 | // We would prefer to use an unordered_map, but that requires special compile switches. 62 | // What a super great language. 63 | typedef std::map MemMapType; 64 | MemMapType mMemMap; 65 | }; 66 | extern struct MemStats gMemStats; 67 | extern int gMemLeakDebug; 68 | 69 | // This is a memory leak detector. 70 | // Use by putting RN_MEMCHKNEW and RN_MEMCHKDEL in class constructors/destructors, 71 | // or use the DEFINE_MEMORY_LEAK_DETECTOR class and add the defined class 72 | // as an ancestor to the class to be memory leak checked. 73 | 74 | struct MemLabel { 75 | std::string mccKey; 76 | virtual ~MemLabel() { 77 | Int_z &tmp = Utils::gMemStats.mMemMap[mccKey]; tmp = tmp - 1; 78 | } 79 | }; 80 | 81 | #if RN_DISABLE_MEMORY_LEAK_TEST 82 | #define RN_MEMCHKNEW(type) 83 | #define RN_MEMCHKDEL(type) 84 | #define RN_MEMLOG(type,ptr) 85 | #define DEFINE_MEMORY_LEAK_DETECTOR_CLASS(subClass,checkerClass) \ 86 | struct checkerClass {}; 87 | #else 88 | 89 | #define RN_MEMCHKNEW(type) { Utils::gMemStats.memChkNew(Utils::MemStats::m##type,#type); } 90 | #define RN_MEMCHKDEL(type) { Utils::gMemStats.memChkDel(Utils::MemStats::m##type,#type); } 91 | 92 | #define RN_MEMLOG(type,ptr) { \ 93 | static std::string key = format("%s_%s:%d",#type,__FILE__,__LINE__); \ 94 | (ptr)->/* MemCheck##type:: */ mccKey = key; \ 95 | Utils::gMemStats.mMemMap[key]++; \ 96 | } 97 | 98 | // TODO: The above assumes that checkclass is MemCheck ## subClass 99 | #define DEFINE_MEMORY_LEAK_DETECTOR_CLASS(subClass,checkerClass) \ 100 | struct checkerClass : public virtual Utils::MemLabel { \ 101 | checkerClass() { RN_MEMCHKNEW(subClass); } \ 102 | virtual ~checkerClass() { \ 103 | RN_MEMCHKDEL(subClass); \ 104 | } \ 105 | }; 106 | 107 | #endif 108 | 109 | } // namespace Utils 110 | 111 | #endif 112 | -------------------------------------------------------------------------------- /mbts/Connection/GenConnection.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * GenConnection.cpp 3 | * This file is part of the Yate-BTS Project http://www.yatebts.com 4 | * 5 | * Generic socket connection 6 | * 7 | * Yet Another Telephony Engine - Base Transceiver Station 8 | * Copyright (C) 2013-2023 Null Team Impex SRL 9 | * Copyright (C) 2014 Legba, Inc 10 | * 11 | * This software is distributed under multiple licenses; 12 | * see the COPYING file in the main directory for licensing 13 | * information for this specific distribution. 14 | * 15 | * This use of this software may be subject to additional restrictions. 16 | * See the LEGAL file in the main directory for details. 17 | * 18 | * This program is distributed in the hope that it will be useful, 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 21 | */ 22 | 23 | #include "GenConnection.h" 24 | 25 | #include 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | using namespace Connection; 35 | 36 | #define BUF_LEN 1024 37 | #define SLEEP_US 20000 38 | 39 | GenConnection::~GenConnection() 40 | { 41 | clear(); 42 | } 43 | 44 | void GenConnection::clear() 45 | { 46 | int fd = mSockFd; 47 | mSockFd = -1; 48 | if (fd >= 0) 49 | ::close(fd); 50 | } 51 | 52 | bool GenConnection::initialize(int fileDesc) 53 | { 54 | if (fileDesc < 0) 55 | return valid(); 56 | linger l; 57 | l.l_onoff = 1; 58 | l.l_linger = 0; 59 | if (::setsockopt(fileDesc,SOL_SOCKET,SO_LINGER,&l,sizeof(l))) 60 | return false; 61 | mSockFd = fileDesc; 62 | if (mBufSize < BUF_LEN) 63 | mBufSize = BUF_LEN; 64 | return true; 65 | } 66 | 67 | bool GenConnection::start(const char* name) 68 | { 69 | struct Local { 70 | static void* runFunc(void* ptr) { 71 | static_cast(ptr)->run(); 72 | return 0; 73 | } 74 | }; 75 | 76 | if (!valid()) 77 | return false; 78 | mRecvThread.start(Local::runFunc,this,name); 79 | return true; 80 | } 81 | 82 | bool GenConnection::send(const void* buffer, size_t len) 83 | { 84 | int fd = mSockFd; 85 | return (fd >= 0) && (::send(fd,buffer,len,0) == (int)len); 86 | } 87 | 88 | void GenConnection::run() 89 | { 90 | unsigned char buf[mBufSize]; 91 | struct timeval tOut; 92 | fd_set fSet; 93 | FD_ZERO(&fSet); 94 | LOG(INFO) << "starting thread loop"; 95 | started(); 96 | while (valid()) { 97 | pthread_testcancel(); 98 | int fd = mSockFd; 99 | if (fd < 0) 100 | break; 101 | tOut.tv_sec = 0; 102 | tOut.tv_usec = SLEEP_US; 103 | FD_SET(fd,&fSet); 104 | if (::select(fd + 1,&fSet,0,0,&tOut) < 0) { 105 | if (errno != EAGAIN && errno != EINTR) { 106 | LOG(ERR) << "select() error " << errno << ": " << strerror(errno); 107 | break; 108 | } 109 | ::usleep(SLEEP_US); 110 | idle(); 111 | continue; 112 | } 113 | if (!FD_ISSET(fd,&fSet)) { 114 | idle(); 115 | continue; 116 | } 117 | ssize_t len = ::recv(fd,buf,mBufSize,MSG_DONTWAIT); 118 | if (!len) { 119 | LOG(DEBUG) << "received EOF on socket"; 120 | break; 121 | } 122 | if (len > 0) { 123 | if (len < mBufSize) 124 | buf[len] = 0; 125 | process(buf,len); 126 | } 127 | else if (errno != EAGAIN && errno != EINTR) { 128 | LOG(ERR) << "recv() error " << errno << ": " << strerror(errno); 129 | break; 130 | } 131 | } 132 | } 133 | 134 | void GenConnection::started() 135 | { 136 | } 137 | 138 | void GenConnection::idle() 139 | { 140 | } 141 | 142 | /* vi: set ts=8 sw=4 sts=4 noet: */ 143 | -------------------------------------------------------------------------------- /mbts/GPRS/GPRSExport.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011 Range Networks, Inc. 3 | * All Rights Reserved. 4 | * 5 | * This software is distributed under multiple licenses; 6 | * see the COPYING file in the main directory for licensing 7 | * information for this specific distribuion. 8 | * 9 | * This use of this software may be subject to additional restrictions. 10 | * See the LEGAL file in the main directory for details. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 15 | */ 16 | 17 | // (pat) This is the GPRS exported include for use by clients in other directories. 18 | 19 | #ifndef GPRSEXPORT_H 20 | #define GPRSEXPORT_H 21 | #include 22 | // The user of this file must include these first, to avoid circular .h files: 23 | //#include "GSMConfig.h" // For Time 24 | //#include "GSMCommon.h" // For ChannelType 25 | 26 | // You must not include anything from the GSM directory to avoid circular calls 27 | // that read files out of order, but we need transparent pointers to these classes, 28 | // so they must be defined first. 29 | namespace GSM { 30 | class RxBurst; 31 | class L3RRMessage; 32 | class CCCHLogicalChannel; 33 | class L3RequestReference; 34 | class Time; 35 | }; 36 | 37 | namespace GPRS { 38 | 39 | struct GPRSConfig { 40 | static unsigned GetRAColour(); 41 | static bool IsEnabled(); 42 | static bool sgsnIsInternal(); 43 | }; 44 | 45 | enum ChannelCodingType { // Compression/Coding schemes CS-1 to CS-4 coded as 0-3 46 | ChannelCodingCS1, 47 | ChannelCodingCS2, 48 | ChannelCodingCS3, 49 | ChannelCodingCS4, 50 | ChannelCodingMax = ChannelCodingCS4, 51 | }; 52 | 53 | // See notes at GPRSCellOptions_t::GPRSCellOptions_t() 54 | struct GPRSCellOptions_t { 55 | unsigned mRelSupported; 56 | unsigned mNMO; 57 | unsigned mT3168Code; // range 0..7 58 | unsigned mT3192Code; // range 0..7 59 | unsigned mDRX_TIMER_MAX; 60 | unsigned mACCESS_BURST_TYPE; 61 | unsigned mCONTROL_ACK_TYPE; 62 | unsigned mBS_CV_MAX; 63 | bool mNW_EXT_UTBF; // Extended uplink TBF 44.060 9.3.1b and 9.3.1.3 64 | bool mAdvertiseEDGE; // if true, advertise EDGE support 65 | GPRSCellOptions_t(); 66 | }; 67 | 68 | extern const int GPRSUSFEncoding[8]; 69 | 70 | extern GPRSCellOptions_t &GPRSGetCellOptions(); 71 | 72 | // The following are not in a class because we dont want to include the entire GPRS class hierarchy. 73 | 74 | // The function by which bursts are delivered to GPRS. 75 | class PDCHL1FEC; 76 | extern void GPRSWriteLowSideRx(const GSM::RxBurst&, PDCHL1FEC*); 77 | 78 | 79 | // The function by which RACH messages are delivered to GPRS. 80 | extern void GPRSProcessRACH(unsigned RA, const GSM::Time &when, float RSSI, float timingError); 81 | 82 | extern int GetPowerAlpha(); 83 | extern int GetPowerGamma(); 84 | extern int GetPowerGammaAdjust(int rssi, int gamma); 85 | extern int GetGprsTargetRSSI(); 86 | extern int GetTargetRSSIInterval(); 87 | extern unsigned GPRSDebug; 88 | extern void GPRSSetDebug(int value); 89 | extern void GPRSNotifyGsmActivity(const char *imsi); 90 | 91 | // Hook into CLI/CLI.cpp:Parser class for GPRS sub-command. 92 | int gprsCLI(int,char**,std::ostream&); 93 | int configGprsChannelsMin(); 94 | 95 | void gprsStart(); // External entry point to start gprs service. 96 | 97 | }; // namespace GPRS 98 | 99 | // GPRSLOG is no longer used outside the GPRS directory. 100 | /**** 101 | * #ifndef GPRSLOG 102 | * #include "Logger.h" 103 | * #define GPRSLOG(level) if (GPRS::GPRSDebug & (level)) \ 104 | * Log(LOG_DEBUG).get() <<"GPRS,"<<(level)<<":" 105 | * #endif 106 | ***/ 107 | 108 | #endif 109 | -------------------------------------------------------------------------------- /mbts/GSM/PowerManager.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2009 Free Software Foundation, Inc. 3 | * 4 | * This software is distributed under multiple licenses; see the COPYING file in the main directory for licensing information for this specific distribuion. 5 | * 6 | * This use of this software may be subject to additional restrictions. 7 | * See the LEGAL file in the main directory for details. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | 13 | */ 14 | 15 | #include "PowerManager.h" 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | extern TransceiverManager gTRX; 23 | 24 | using namespace GSM; 25 | 26 | 27 | 28 | void PowerManager::increasePower() 29 | { 30 | int maxAtten = gConfig.getNum("GSM.Radio.PowerManager.MaxAttenDB"); 31 | int minAtten = gConfig.getNum("GSM.Radio.PowerManager.MinAttenDB"); 32 | if (mAtten==minAtten) { 33 | LOG(DEBUG) << "power already at maximum"; 34 | return; 35 | } 36 | mAtten--; // raise power by reducing attenuation 37 | if (mAttenmaxAtten) mAtten=maxAtten; 39 | LOG(INFO) << "power increased to -" << mAtten << " dB"; 40 | mRadio->setPower(mAtten); 41 | } 42 | 43 | void PowerManager::reducePower() 44 | { 45 | int maxAtten = gConfig.getNum("GSM.Radio.PowerManager.MaxAttenDB"); 46 | int minAtten = gConfig.getNum("GSM.Radio.PowerManager.MinAttenDB"); 47 | if (mAtten==maxAtten) { 48 | LOG(DEBUG) << "power already at minimum"; 49 | return; 50 | } 51 | mAtten++; // reduce power be increasing attenuation 52 | if (mAttenmaxAtten) mAtten=maxAtten; 54 | LOG(INFO) << "power decreased to -" << mAtten << " dB"; 55 | mRadio->setPower(mAtten); 56 | } 57 | 58 | 59 | // internal method, does the control step 60 | void PowerManager::internalControlStep() 61 | { 62 | unsigned target = gConfig.getNum("GSM.Radio.PowerManager.TargetT3122"); 63 | LOG(DEBUG) << "Avg T3122 " << mAveragedT3122 << ", target " << target; 64 | // Adapt the power. 65 | if (mAveragedT3122 > target) reducePower(); 66 | else increasePower(); 67 | } 68 | 69 | 70 | void PowerManager::sampleT3122() 71 | { 72 | // Tweak it down a little just in case there's no activity. 73 | mSamples[mNextSampleIndex] = gBTS.shrinkT3122(); 74 | unsigned numSamples = gConfig.getNum("GSM.Radio.PowerManager.NumSamples"); 75 | mNextSampleIndex = (mNextSampleIndex + 1) % numSamples; 76 | long sum = 0; 77 | for (unsigned i=0; iserviceLoop(); 111 | return NULL; 112 | } 113 | 114 | 115 | void PowerManager::start() 116 | { 117 | mRadio = gTRX.ARFCN(0); 118 | mRadio->setPower(mAtten); 119 | mThread.start((void*(*)(void*))PowerManagerServiceLoopAdapter,this,"bts:power"); 120 | } 121 | 122 | 123 | // vim: ts=4 sw=4 124 | -------------------------------------------------------------------------------- /mbts/GPRS/MsgBase.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011 Range Networks, Inc. 3 | * All Rights Reserved. 4 | * 5 | * This software is distributed under multiple licenses; 6 | * see the COPYING file in the main directory for licensing 7 | * information for this specific distribuion. 8 | * 9 | * This use of this software may be subject to additional restrictions. 10 | * See the LEGAL file in the main directory for details. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 15 | */ 16 | 17 | #include 18 | 19 | #include "MsgBase.h" 20 | 21 | void MsgCommonWrite::_define_vtable() {} 22 | void MsgCommonLength::_define_vtable() {} 23 | void MsgCommonText::_define_vtable() {} 24 | 25 | // Copied from same functions in L3Frame: 26 | static const unsigned fillPattern[8] = {0,0,1,0,1,0,1,1}; 27 | 28 | void MsgCommonWrite::writeField(const ItemWithValueAndWidth&item,const char*) 29 | { 30 | mResult.writeField(wp,item.getValue(),item.getWidth()); 31 | } 32 | 33 | void MsgCommonWrite::writeField(uint64_t value, unsigned len, const char *, Type2Str) 34 | { 35 | mResult.writeField(wp,value,len); 36 | } 37 | 38 | void MsgCommonWrite::writeOptFieldLH(uint64_t value, unsigned len, int present, const char *) 39 | { 40 | if (present) { writeH(); writeField(value,len); } else { writeL(); } 41 | } 42 | 43 | // pat added: write an Optional Field controlled by an initial 0/1 field. 44 | void MsgCommonWrite::writeOptField01(uint64_t value, unsigned len, int present, const char*) 45 | { 46 | if (present) { write1(); writeField(value,len); } else { write0(); } 47 | } 48 | 49 | void MsgCommonWrite::writeH() 50 | { 51 | unsigned fillBit = fillPattern[wp%8]; // wp is in MsgCommon 52 | writeField(!fillBit,1); 53 | } 54 | 55 | 56 | void MsgCommonWrite::writeL() 57 | { 58 | unsigned fillBit = fillPattern[wp%8]; // wp is in MsgCommon 59 | writeField(fillBit,1); 60 | } 61 | 62 | void MsgCommonWrite::writeBitMap(bool*bitmap,unsigned bitmaplen, const char*name) 63 | { 64 | for (unsigned i=0; i str; cp--) { 84 | if (*cp != lastch) { 85 | if (cp < end-6) { strcpy(cp+2,"..."); } 86 | break; 87 | } 88 | } 89 | } 90 | #endif 91 | 92 | #define TOHEX(v) ((v) + ((v) < 10 ? '0' : ('a'-10))) 93 | void MsgCommonText::writeBitMap(bool*bitmap,unsigned bitmaplen, const char*name) 94 | { 95 | char txtbits[bitmaplen+6], *tp = txtbits; 96 | unsigned i, accum = 0; 97 | for (i=0; i. 23 | 24 | */ 25 | 26 | 27 | 28 | #include 29 | #include 30 | #include 31 | #ifdef HAVE_SYS_PRCTL_H 32 | #include 33 | #endif 34 | 35 | #include "Threads.h" 36 | #include "Timeval.h" 37 | 38 | 39 | using namespace std; 40 | 41 | 42 | 43 | 44 | Mutex gStreamLock; ///< Global lock to control access to cout and cerr. 45 | 46 | void lockCout() 47 | { 48 | gStreamLock.lock(); 49 | Timeval entryTime; 50 | cout << entryTime << " " << pthread_self() << ": "; 51 | } 52 | 53 | 54 | void unlockCout() 55 | { 56 | cout << dec << endl << flush; 57 | gStreamLock.unlock(); 58 | } 59 | 60 | 61 | void lockCerr() 62 | { 63 | gStreamLock.lock(); 64 | Timeval entryTime; 65 | cerr << entryTime << " " << pthread_self() << ": "; 66 | } 67 | 68 | void unlockCerr() 69 | { 70 | cerr << dec << endl << flush; 71 | gStreamLock.unlock(); 72 | } 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | Mutex::Mutex() 81 | { 82 | bool res; 83 | res = pthread_mutexattr_init(&mAttribs); 84 | assert(!res); 85 | res = pthread_mutexattr_settype(&mAttribs,PTHREAD_MUTEX_RECURSIVE); 86 | assert(!res); 87 | res = pthread_mutex_init(&mMutex,&mAttribs); 88 | assert(!res); 89 | } 90 | 91 | 92 | Mutex::~Mutex() 93 | { 94 | pthread_mutex_destroy(&mMutex); 95 | bool res = pthread_mutexattr_destroy(&mAttribs); 96 | assert(!res); 97 | } 98 | 99 | 100 | 101 | 102 | /** Block for the signal up to the cancellation timeout. */ 103 | void Signal::wait(Mutex& wMutex, unsigned timeout) const 104 | { 105 | Timeval then(timeout); 106 | struct timespec waitTime = then.timespec(); 107 | pthread_cond_timedwait(&mSignal,&wMutex.mMutex,&waitTime); 108 | } 109 | 110 | void Thread::start(void *(*task)(void*), void *arg, const char* name, ...) 111 | { 112 | #ifdef PR_SET_NAME 113 | class NamedTask 114 | { 115 | void *(*mTask)(void*); 116 | void *mArg; 117 | char mName[16]; 118 | public: 119 | inline NamedTask(void *(*task)(void*), void *arg, const char* name, va_list ap) 120 | : mTask(task), mArg(arg) 121 | { 122 | vsnprintf(mName, 15, name, ap); 123 | mName[15] = '\0'; 124 | } 125 | 126 | static void* run(void* arg) 127 | { 128 | NamedTask* t = static_cast(arg); 129 | void *(*task)(void*) = t->mTask; 130 | arg = t->mArg; 131 | prctl(PR_SET_NAME, (unsigned long)t->mName, 0, 0, 0); 132 | delete t; 133 | return task(arg); 134 | } 135 | }; 136 | #endif 137 | 138 | assert(mThread==((pthread_t)0)); 139 | bool res; 140 | // (pat) Moved initialization to constructor to avoid crash in destructor. 141 | //res = pthread_attr_init(&mAttrib); 142 | //assert(!res); 143 | res = pthread_attr_setstacksize(&mAttrib, mStackSize); 144 | assert(!res); 145 | #ifdef PR_SET_NAME 146 | if (name && *name) { 147 | va_list ap; 148 | va_start(ap, name); 149 | NamedTask* t = new NamedTask(task, arg, name, ap); 150 | va_end(ap); 151 | res = pthread_create(&mThread, &mAttrib, NamedTask::run, t); 152 | } 153 | else 154 | #endif 155 | res = pthread_create(&mThread, &mAttrib, task, arg); 156 | assert(!res); 157 | } 158 | 159 | 160 | 161 | // vim: ts=4 sw=4 162 | -------------------------------------------------------------------------------- /mbts/AUTHORS: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2008, 2009 Free Software Foundation, Inc. 3 | # Copyright 2014 Legba, Inc. 4 | # 5 | # 6 | # This is free software; you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation; either version 3, or (at your option) 9 | # any later version. 10 | # 11 | # This is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License along 17 | # with this program; if not, write to the Free Software Foundation, Inc., 18 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 | # 20 | 21 | David A. Burgess, david.burgess@leg.ba: 22 | CLI/CLI.cpp 23 | CLI/CLI.h 24 | CommonLibs/Assert.h 25 | CommonLibs/BitVector.cpp 26 | CommonLibs/BitVectorTest.cpp 27 | CommonLibs/Configuration.cpp 28 | CommonLibs/Configuration.h 29 | CommonLibs/ConfigurationTest.cpp 30 | CommonLibs/Interthread.h 31 | CommonLibs/InterthreadTest.cpp 32 | CommonLibs/LinkedLists.cpp 33 | CommonLibs/LinkedLists.h 34 | CommonLibs/Regexp.h 35 | CommonLibs/RegexpTest.cpp 36 | CommonLibs/Sockets.cpp 37 | CommonLibs/Sockets.h 38 | CommonLibs/SocketsTest.cpp 39 | CommonLibs/Threads.cpp 40 | CommonLibs/Threads.h 41 | CommonLibs/Timeval.cpp 42 | CommonLibs/Timeval.h 43 | CommonLibs/TimevalTest.cpp 44 | CommonLibs/Vector.h 45 | CommonLibs/VectorTest.cpp 46 | Control/ControlCommon.cpp 47 | Control/ControlCommon.h 48 | Control/RadioResource.cpp 49 | Control/DCCHDispatch.cpp 50 | GSM/GSM610Tables.cpp 51 | GSM/GSM610Tables.h 52 | GSM/GSMCommon.cpp 53 | GSM/GSMCommon.h 54 | GSM/GSMConfig.h 55 | GSM/GSML1FEC.cpp 56 | GSM/GSML1FEC.h 57 | GSM/GSML2LAPDm.cpp 58 | GSM/GSML2LAPDm.h 59 | GSM/GSML3CommonElements.cpp 60 | GSM/GSML3CommonElements.h 61 | GSM/GSML3Message.cpp 62 | GSM/GSML3Message.h 63 | GSM/GSML3RRElements.cpp 64 | GSM/GSML3RRElements.h 65 | GSM/GSML3RRMessages.cpp 66 | GSM/GSML3RRMessages.h 67 | GSM/GSMLogicalChannel.h 68 | GSM/GSMTDMA.cpp 69 | GSM/GSMTDMA.h 70 | GSM/GSMTransfer.cpp 71 | GSM/GSMTransfer.h 72 | LICENSEBLOCK 73 | TRXManager/TRXManager.cpp 74 | Transceiver/Complex.h 75 | apps/OpenBTS.cpp 76 | 77 | Harvind S. Samra, harvind@rangenetworks.com: 78 | Control/RadioResource.cpp 79 | GSM/GSMConfig.h 80 | GSM/GSMTransfer.h 81 | LICENSEBLOCK 82 | Transceiver/ComplexTest.cpp 83 | Transceiver/Transceiver.cpp 84 | Transceiver/Transceiver.h 85 | Transceiver/USRPDevice.cpp 86 | Transceiver/USRPDevice.h 87 | Transceiver/USRPping.cpp 88 | Transceiver/radioInterface.cpp 89 | Transceiver/radioInterface.h 90 | Transceiver/rcvLPF_651.h 91 | Transceiver/runTransceiver.cpp 92 | Transceiver/sendLPF_961.h 93 | Transceiver/sigProcLib.cpp 94 | Transceiver/sigProcLib.h 95 | Transceiver/sigProcLibTest.cpp 96 | Transceiver/sweepGenerator.cpp 97 | Transceiver/testRadio.cpp 98 | 99 | Raffi Sevlian, raffisev@gmail.com: 100 | Control/ControlCommon.cpp 101 | Control/ControlCommon.h 102 | Control/DCCHDispatch.cpp 103 | Control/RadioResource.cpp 104 | GSM/GSMCommon.h 105 | GSM/GSMConfig.h 106 | GSM/GSML1FEC.h 107 | GSM/GSML3CommonElements.cpp 108 | GSM/GSML3CommonElements.h 109 | GSM/GSML3Message.cpp 110 | GSM/GSML3Message.h 111 | GSM/GSML3RRElements.cpp 112 | GSM/GSML3RRElements.h 113 | GSM/GSML3RRMessages.cpp 114 | GSM/GSML3RRMessages.h 115 | GSM/GSMLogicalChannel.h 116 | GSM/GSMSAPMux.cpp 117 | GSM/GSMSAPMux.h 118 | GSM/GSMTransfer.h 119 | LICENSEBLOCK 120 | TRXManager/TRXManager.h 121 | 122 | Alon Levy, alonlevy1@gmail.com 123 | RRLPMessages.cpp 124 | RRLPMessages.h 125 | RRLPTest.cpp 126 | 127 | Pat Thompson, pat.thompson@rangenetworks.com 128 | GPRS/* 129 | 130 | Paul Chitescu, paul@null.ro 131 | Connection/* 132 | Control/DCCHDispatch.cpp 133 | 134 | -------------------------------------------------------------------------------- /mbts/SGSNGGSN/miniggsn.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011 Range Networks, Inc. 3 | * All Rights Reserved. 4 | * 5 | * This software is distributed under multiple licenses; 6 | * see the COPYING file in the main directory for licensing 7 | * information for this specific distribuion. 8 | * 9 | * This use of this software may be subject to additional restrictions. 10 | * See the LEGAL file in the main directory for details. 11 | 12 | This program is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 15 | */ 16 | 17 | #ifndef _MINIGGSN_H_ 18 | #define _MINIGGSN_H_ 19 | #include 20 | #include "Logger.h" 21 | 22 | namespace SGSN { 23 | 24 | class PdpContext; 25 | 26 | // MiniGGSN IP connections. 27 | // This holds the IP address and is slightly different than a PDPContext: 28 | // o The IP address is permanently allocated. 29 | // o The PDPContext is strictly a handle for the MS; it is deleted when PDPContext is deactivated 30 | // or when the MS is deleted. 31 | // o There can be multiple PDPContext with the same IP address. 32 | // o When a PDPContext is deallocated, there may still be messages for it in the message queue, 33 | // so those messages point to the permanet mg_con_s instead of the PdpContext. 34 | // o The IP address must remain reserved for a period of time after a PdpContext is deleted/deactivated. 35 | // Note: This was written in C originally. 36 | typedef struct mg_con_s { 37 | PdpContext *mg_pdp; // Points back to the PDP context using this connection. 38 | uint32_t mg_ptmsi; // The ptmsi that is using this IP connection. 39 | int mg_nsapi; // The nsapi in this ptmsi that is using this IP connection. 40 | uint32_t mg_ip; // The IP address used for this connection, in network order. 41 | // Keep track of the last few tcp packets received: 42 | #define MG_PACKET_HISTORY 60 43 | struct mg_packets { 44 | uint16_t source, dest; // TCP source and dest ports. 45 | uint16_t totlen; // IP length, which includes headers. 46 | uint32_t seq; // TCP sequence number 47 | uint32_t saddr, daddr; // source and destination IP addr 48 | uint16_t ipid, ipfragoff; // Added 3-2012 49 | } mg_packets[MG_PACKET_HISTORY]; 50 | int mg_oldest_packet; 51 | double mg_time_last_close; 52 | } mg_con_t; 53 | #define MG_CON_DEFINED 54 | 55 | unsigned char *miniggsn_rcv_npdu(int *error, int *plen, uint32_t *dstaddr); 56 | int miniggsn_snd_npdu(PdpContext *pctx,unsigned char *npdu, unsigned len); 57 | int miniggsn_snd_npdu_by_mgc(mg_con_t *mgp,unsigned char *npdu, unsigned len); 58 | void miniggsn_handle_read(); 59 | bool miniggsn_init(); 60 | mg_con_t *mg_con_find_free(uint32_t ptmsi, int nsapi); 61 | void mg_con_close(mg_con_t *mgp); 62 | void mg_con_open(mg_con_t *mgp,PdpContext *pdp); 63 | 64 | //extern int pinghttp(char *whoto,char *whofrom,mg_con_t *mgp); 65 | 66 | extern int tun_fd; 67 | 68 | // From iputils.h: 69 | bool ip_addr_crack(const char *address,uint32_t *paddr, uint32_t *pmask); 70 | char *ip_ntoa(int32_t ip, char *buf); 71 | char *ip_sockaddr2a(void * /*struct sockaddr * */ sap,char *buf); 72 | int ip_add_addr(char *ifname, int32_t ipaddr, int maskbits); 73 | const char *ip_proto_name(int ipproto); 74 | unsigned int ip_checksum(void *ptr, unsigned len, void *dummyhdr); 75 | void ip_hdr_dump(unsigned char *packet, const char *msg); 76 | int runcmd(const char *path, ...); 77 | int ip_tun_open(const char *tname, const char *addrstr); 78 | void ip_init(); 79 | int ip_finddns(uint32_t*); 80 | uint32_t *ip_findmyaddr(); 81 | extern double pat_timef(), pat_elapsedf(); 82 | 83 | 84 | // Logging. These date from when this was part of the SGSN, written in C. 85 | extern FILE *mg_log_fp; 86 | extern time_t gGgsnInitTime; 87 | // formerly: fprintf(mg_log_fp,"%.1f:",pat_timef() - gGgsnInitTime); 88 | #define MGLOGF(...) if (mg_log_fp) { \ 89 | fprintf(mg_log_fp,"%s:",timestr().c_str()); \ 90 | fprintf(mg_log_fp, __VA_ARGS__); \ 91 | fputc('\n',mg_log_fp); \ 92 | fflush(mg_log_fp); \ 93 | } 94 | #define MGLOG(stuff) {std::ostringstream ss; ss<0){LOG(lev)< 26 | #include 27 | #include 28 | #include 29 | 30 | #include 31 | 32 | #include 33 | #include 34 | #undef WARNING 35 | 36 | 37 | using namespace std; 38 | using namespace GSM; 39 | using namespace Control; 40 | 41 | 42 | 43 | 44 | 45 | // FIXME -- getMessage should return an L3Frame, not an L3Message. 46 | // This will mean moving all of the parsing into the control layer. 47 | // FIXME -- This needs an adjustable timeout. 48 | 49 | L3Message* getMessageCore(LogicalChannel *LCH, unsigned SAPI) 50 | { 51 | unsigned timeout_ms = LCH->N200() * T200ms; 52 | L3Frame *rcv = LCH->recv(timeout_ms,SAPI); 53 | if (rcv==NULL) { 54 | LOG(NOTICE) << "L3 read timeout"; 55 | throw ChannelReadTimeout(); 56 | } 57 | LOG(DEBUG) << "received " << *rcv; 58 | Primitive primitive = rcv->primitive(); 59 | if (primitive!=DATA) { 60 | LOG(ERR) << "unexpected primitive " << primitive; 61 | delete rcv; 62 | throw UnexpectedPrimitive(); 63 | } 64 | L3Message *msg = parseL3(*rcv); 65 | if (msg==NULL) { 66 | LOG(WARNING) << "unparsed message:" << *rcv; 67 | delete rcv; 68 | return NULL; 69 | //throw UnsupportedMessage(); 70 | } 71 | delete rcv; 72 | LOG(DEBUG) << *msg; 73 | return msg; 74 | } 75 | 76 | 77 | // FIXME -- getMessage should return an L3Frame, not an L3Message. 78 | // This will mean moving all of the parsing into the control layer. 79 | // FIXME -- This needs an adjustable timeout. 80 | 81 | L3Message* Control::getMessage(LogicalChannel *LCH, unsigned SAPI) 82 | { 83 | L3Message *msg = getMessageCore(LCH,SAPI); 84 | // Handsets should not be sending us GPRS suspension requests when GPRS support is not enabled. 85 | // But if they do, we should ignore them. 86 | // They should not send more than one in any case, but we need to be 87 | // ready for whatever crazy behavior they throw at us. 88 | 89 | // The suspend procedure includes MS<->BSS and BSS<->SGSN messages. 90 | // GSM44.018 3.4.25 GPRS Suspension Procedure and 9.1.13b: GPRS Suspension Request message. 91 | // Also 23.060 16.2.1.1 Suspend/Resume procedure general. 92 | // GSM08.18: Suspend Procedure talks about communication between the BSS and SGSN, 93 | // and is not applicable to us when using the internal SGSN. 94 | // Note: When call is finished the RR is supposed to include a GPRS resumption IE, but if it does not, 95 | // 23.060 16.2.1.1.1 says the MS will do a GPRS RoutingAreaUpdate to get the 96 | // GPRS service back, so we are not worrying about it. 97 | // (pat 3-2012) Send the message to the internal SGSN. 98 | // It returns true if GPRS and the internal SGSN are enabled. 99 | // If we are using an external SGSN, we could send the GPRS suspend request to the SGSN via the BSSG, 100 | // but that has no hope of doing anything useful. See ticket #613. 101 | // First, We are supposed to automatically detect when we should do the Resume procedure. 102 | // Second: An RA-UPDATE, which gets send to the SGSN, does something to the CC state 103 | // that I dont understand yet. 104 | // We dont do any of the above. 105 | unsigned count = gConfig.getNum("GSM.Control.GPRSMaxIgnore"); 106 | const GSM::L3GPRSSuspensionRequest *srmsg; 107 | while (count && (srmsg = dynamic_cast(msg))) { 108 | if (! SGSN::Sgsn::handleGprsSuspensionRequest(srmsg->mTLLI,srmsg->mRaId)) { 109 | LOG(NOTICE) << "ignoring GPRS suspension request"; 110 | } 111 | msg = getMessageCore(LCH,SAPI); 112 | count--; 113 | } 114 | return msg; 115 | } 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | // vim: ts=4 sw=4 125 | --------------------------------------------------------------------------------