diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 6902de93f..000000000 --- a/.gitignore +++ /dev/null @@ -1,70 +0,0 @@ -# compiler output -*.o -*.lo -*.a -*.la -*.conf -.deps -.dirstamp -.libs - -# generated files -lib/freeDiameter/build-aux/* -lib/freeDiameter/config.status -lib/freeDiameter/m4/*.m4 -lib/freeDiameter/!m4/ax_*.m4 -lib/freeDiameter/libfdcore/fdd.tab.[chy] -lib/freeDiameter/libfdcore/lex.fdd.[cl] -lib/freeDiameter/include/freeDiameter/version.h -lib/freeDiameter/include/freeDiameter/freeDiameter-config.h.in* -lib/freeDiameter/include/freeDiameter/freeDiameter-config.h -lib/freeDiameter/include/freeDiameter/freeDiameter-host.h -support/systemd/nextepc-*.service -support/logrotate/nextepc - -# autotools -stamp-h1 -config.h -lib/nextepc-config.h -lib/nextepc-config.h.in* -config.log -config.status -configure -aclocal.m4 -libtool -autom4te.cache -build/* -!build/git-version-gen -!build/osc-upload.sh -!build/dput-upload.sh -Makefile -Makefile.in -m4/*.m4 -!m4/ax_*.m4 - -.tarball-version -.version - -# autotest -tests/package.m4 -tests/atconfig -tests/testsuite -tests/testsuite.dir/ -tests/testsuite.log - -# executables -tests/testunit -tests/testsimple -tests/testcomplex -tests/testvolte -tests/testcsfb -nextepc-mmed -nextepc-pcrfd -nextepc-pgwd -nextepc-sgwd -nextepc-epcd -nextepc-hssd - -# webui -webui/.next/ -webui/node_modules/ diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index b8c29f21b..000000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "lib/ogslib"] - path = lib/ogslib - url = https://github.com/open5gs/ogslib diff --git a/Makefile.am b/Makefile.am deleted file mode 100644 index 55dde63a8..000000000 --- a/Makefile.am +++ /dev/null @@ -1,68 +0,0 @@ -# Copyright (C) 2019 by Sukchan Lee - -# This file is part of Open5GS. - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -ACLOCAL_AMFLAGS = -I m4 -EXTRA_DIST = build/git-version-gen .version README.md LICENSE - -SUBDIRS = lib src support tests - -bin_PROGRAMS = nextepc-mmed nextepc-hssd nextepc-sgwd nextepc-pgwd nextepc-pcrfd nextepc-epcd - -dist_nextepc_mmed_SOURCES = main.c -nextepc_mmed_LDADD = $(top_srcdir)/src/libmme.la - -dist_nextepc_hssd_SOURCES = main.c -nextepc_hssd_LDADD = $(top_srcdir)/src/libhss.la - -dist_nextepc_sgwd_SOURCES = main.c -nextepc_sgwd_LDADD = $(top_srcdir)/src/libsgw.la - -dist_nextepc_pgwd_SOURCES = main.c -nextepc_pgwd_LDADD = $(top_srcdir)/src/libpgw.la - -dist_nextepc_pcrfd_SOURCES = main.c -nextepc_pcrfd_LDADD = $(top_srcdir)/src/libpcrf.la - -dist_nextepc_epcd_SOURCES = main.c -nextepc_epcd_LDADD = $(top_srcdir)/src/libepc.la - -AM_CPPFLAGS = \ - @OGSCORE_CFLAGS@ \ - -I$(top_srcdir)/lib \ - -I$(top_srcdir)/src \ - $(NULL) - -DEFS = \ - @DEFS@ \ - -DSYSCONF_DIR=\"$(sysconfdir)/\" \ - -DLOCALSTATE_DIR=\"$(localstatedir)/\" \ - $(NULL) - -install-data-hook: - $(MKDIR_P) $(DESTDIR)/$(localstatedir)/log/nextepc - $(MKDIR_P) $(DESTDIR)/$(localstatedir)/run/nextepc-mmed - $(MKDIR_P) $(DESTDIR)/$(localstatedir)/run/nextepc-sgwd - $(MKDIR_P) $(DESTDIR)/$(localstatedir)/run/nextepc-pgwd - $(MKDIR_P) $(DESTDIR)/$(localstatedir)/run/nextepc-pcrfd - $(MKDIR_P) $(DESTDIR)/$(localstatedir)/run/nextepc-hssd - $(MKDIR_P) $(DESTDIR)/$(localstatedir)/run/nextepc-epcd - -BUILT_SOURCES = $(top_srcdir)/.version -$(top_srcdir)/.version: - echo $(VERSION) > $@-t && mv $@-t $@ -dist-hook: - echo $(VERSION) > $(distdir)/.tarball-version diff --git a/README.md b/README.md index f96267f10..c3256c5d1 100644 --- a/README.md +++ b/README.md @@ -1,26 +1,26 @@ ## Documentation -If you don't understand something about NextEPC, the [https://open5gs.org/nextepc/docs/](https://open5gs.org/nextepc/docs/) is a great place to look for answers. +If you don't understand something about Open5GS, the [https://open5gs.org/open5gs/docs/](https://open5gs.org/open5gs/docs/) is a great place to look for answers. ## Support -Problem with NextEPC can be filed as [issues](https://github.com/open5gs/nextepc/issues) in this repository. +Problem with Open5GS can be filed as [issues](https://github.com/open5gs/open5gs/issues) in this repository. -Discussions related to this project are happening on the [nextepc@lists.osmocom.org](mailto:nextepc@lists.osmocom.org) mailing list, please see for subscription options and the list archive. +Discussions related to this project are happening on the [open5gs@lists.osmocom.org](mailto:open5gs@lists.osmocom.org) mailing list, please see for subscription options and the list archive. -Voice and text chat available in NextEPC's [Discord](https://discordapp.com/) workspace. Use [this link](https://discord.gg/GreNkuc) to get started. +Voice and text chat available in Open5GS's [Discord](https://discordapp.com/) workspace. Use [this link](https://discord.gg/GreNkuc) to get started. ## Contributing -NextEPC is a pure/classic FOSS project, open to contributions from anyone. +Open5GS is a pure/classic FOSS project, open to contributions from anyone. -[Pull requests](https://github.com/open5gs/nextepc/pulls) are always welcome, and I appreciates any help the community can give to help make NextEPC better. +[Pull requests](https://github.com/open5gs/open5gs/pulls) are always welcome, and I appreciates any help the community can give to help make Open5GS better. Do you want to be a committer? Please [send me an email](mailto:acetcom@gmail.com). You will be added as a committer to this project. However, if someone consistently causes difficulties with these source repositories due to poor behavior or other serious problems then commit access may be revoked. ## License -NextEPC source files are made available under the terms of the GNU Affero General Public License (GNU AGPLv3). +Open5GS source files are made available under the terms of the GNU Affero General Public License (GNU AGPLv3). -When you contribute code for NextEPC, the same license applies. +When you contribute code for Open5GS, the same license applies. diff --git a/configs/csfb.yaml.in b/configs/csfb.yaml.in new file mode 100644 index 000000000..a79c61f60 --- /dev/null +++ b/configs/csfb.yaml.in @@ -0,0 +1,157 @@ +db_uri: mongodb://localhost/open5gs + +logger: + +parameter: + no_ipv6: true + +mme: + freeDiameter: + identity: mme.localdomain + realm: localdomain + listen_on: 127.0.0.2 + load_extension: + - module: @freediameter_extensions_builddir@/dbg_msg_dumps.fdx + conf: 0x8888 + - module: @freediameter_extensions_builddir@/dict_rfc5777.fdx + - module: @freediameter_extensions_builddir@/dict_mip6i.fdx + - module: @freediameter_extensions_builddir@/dict_nasreq.fdx + - module: @freediameter_extensions_builddir@/dict_nas_mipv6.fdx + - module: @freediameter_extensions_builddir@/dict_dcca.fdx + - module: @freediameter_extensions_builddir@/dict_dcca_3gpp.fdx + - module: @freediameter_extensions_builddir@/dict_s6a.fdx + connect: + - identity: hss.localdomain + addr: 127.0.0.4 + + s1ap: + addr: 127.0.0.1 + gtpc: + addr: 127.0.0.1 + sgsap: + - addr: 127.0.0.2 + map: + tai: + plmn_id: + mcc: 901 + mnc: 70 + tac: 7 + lai: + plmn_id: + mcc: 901 + mnc: 70 + lac: 2342 + map: + tai: + plmn_id: + mcc: 724 + mnc: 21 + tac: 12345 + lai: + plmn_id: + mcc: 724 + mnc: 21 + lac: 51544 + gummei: + - plmn_id: + mcc: 901 + mnc: 70 + mme_gid: 2 + mme_code: 1 + - plmn_id: + mcc: 724 + mnc: 21 + mme_gid: 2 + mme_code: 1 + tai: + plmn_id: + mcc: 901 + mnc: 70 + tac: 7 + tai: + plmn_id: + mcc: 724 + mnc: 21 + tac: 12345 + security: + integrity_order : [ EIA1, EIA2, EIA0 ] + ciphering_order : [ EEA0, EEA1, EEA2 ] + + network_name: + full: Open5GS + +hss: + freeDiameter: + identity: hss.localdomain + realm: localdomain + listen_on: 127.0.0.4 + load_extension: + - module: @freediameter_extensions_builddir@/dbg_msg_dumps.fdx + conf: 0x8888 + - module: @freediameter_extensions_builddir@/dict_rfc5777.fdx + - module: @freediameter_extensions_builddir@/dict_mip6i.fdx + - module: @freediameter_extensions_builddir@/dict_nasreq.fdx + - module: @freediameter_extensions_builddir@/dict_nas_mipv6.fdx + - module: @freediameter_extensions_builddir@/dict_dcca.fdx + - module: @freediameter_extensions_builddir@/dict_dcca_3gpp.fdx + - module: @freediameter_extensions_builddir@/dict_s6a.fdx + connect: + - identity: mme.localdomain + addr: 127.0.0.2 + +sgw: + gtpc: + addr: 127.0.0.2 + gtpu: + addr: 127.0.0.2 + +pgw: + freeDiameter: + identity: pgw.localdomain + realm: localdomain + listen_on: 127.0.0.3 + load_extension: + - module: @freediameter_extensions_builddir@/dbg_msg_dumps.fdx + conf: 0x8888 + - module: @freediameter_extensions_builddir@/dict_rfc5777.fdx + - module: @freediameter_extensions_builddir@/dict_mip6i.fdx + - module: @freediameter_extensions_builddir@/dict_nasreq.fdx + - module: @freediameter_extensions_builddir@/dict_nas_mipv6.fdx + - module: @freediameter_extensions_builddir@/dict_dcca.fdx + - module: @freediameter_extensions_builddir@/dict_dcca_3gpp.fdx + connect: + - identity: pcrf.localdomain + addr: 127.0.0.5 + + gtpc: + - addr: + - 127.0.0.3 + - ::1 + gtpu: + - addr: 127.0.0.3 + - addr: ::1 + ue_pool: + - addr: 45.45.0.1/16 + - addr: cafe::1/64 + dns: + - 8.8.8.8 + - 8.8.4.4 + - 2001:4860:4860::8888 + - 2001:4860:4860::8844 +pcrf: + freeDiameter: + identity: pcrf.localdomain + realm: localdomain + listen_on: 127.0.0.5 + load_extension: + - module: @freediameter_extensions_builddir@/dbg_msg_dumps.fdx + conf: 0x8888 + - module: @freediameter_extensions_builddir@/dict_rfc5777.fdx + - module: @freediameter_extensions_builddir@/dict_mip6i.fdx + - module: @freediameter_extensions_builddir@/dict_nasreq.fdx + - module: @freediameter_extensions_builddir@/dict_nas_mipv6.fdx + - module: @freediameter_extensions_builddir@/dict_dcca.fdx + - module: @freediameter_extensions_builddir@/dict_dcca_3gpp.fdx + connect: + - identity: pgw.localdomain + addr: 127.0.0.3 diff --git a/configs/freeDiameter/cacert.pem b/configs/freeDiameter/cacert.pem new file mode 100644 index 000000000..5536d8663 --- /dev/null +++ b/configs/freeDiameter/cacert.pem @@ -0,0 +1,17 @@ +-----BEGIN CERTIFICATE----- +MIICrDCCAhWgAwIBAgIUPoUbKXRTWQbrJYUIvyHdacCzw9cwDQYJKoZIhvcNAQEL +BQAwaDEXMBUGA1UEAwwOY2EubG9jYWxkb21haW4xCzAJBgNVBAYTAktPMQ4wDAYD +VQQIDAVTZW91bDEOMAwGA1UEBwwFTm93b24xEDAOBgNVBAoMB09wZW41R1MxDjAM +BgNVBAsMBVRlc3RzMB4XDTE5MTAyMDA2NDM1OFoXDTI5MTAxNzA2NDM1OFowaDEX +MBUGA1UEAwwOY2EubG9jYWxkb21haW4xCzAJBgNVBAYTAktPMQ4wDAYDVQQIDAVT +ZW91bDEOMAwGA1UEBwwFTm93b24xEDAOBgNVBAoMB09wZW41R1MxDjAMBgNVBAsM +BVRlc3RzMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC2sDnWMj9oXpIw+vcm +9k/WidMyhSbImINLe9YgibFfozoxZt51Hvi/aAxlqyq7akGtvpL8yVZD6j7o74z7 +6dlnUFDGC4M0WGEkcxqf5NIWe0QplCsXkEOMYHrXLQisAuUk81DNcsXlZr74bmDI +B0dUM0xJ2JrA5mx1LzTFHSesIwIDAQABo1MwUTAdBgNVHQ4EFgQUxTjcug/DKW49 +mQeW0IcS/bhIzDcwHwYDVR0jBBgwFoAUxTjcug/DKW49mQeW0IcS/bhIzDcwDwYD +VR0TAQH/BAUwAwEB/zANBgkqhkiG9w0BAQsFAAOBgQB533IwIPOEE1w2RLBF9EKX +UxaDnUYW05t9eZFLsUtOLFiR84xhCawGEWNtaLvoJE42E17qEjnX4+KGOc6/sa6q +bLskf7BK7496dQrVY5DO9vdSpN1ep3j+1QKae23wYpjqt2UEU3QtIZpsDjUreYri +YLVacMQydGgizNQrY3iCvQ== +-----END CERTIFICATE----- diff --git a/configs/freeDiameter/hss.cert.pem b/configs/freeDiameter/hss.cert.pem new file mode 100644 index 000000000..629f150a6 --- /dev/null +++ b/configs/freeDiameter/hss.cert.pem @@ -0,0 +1,60 @@ +Certificate: + Data: + Version: 3 (0x2) + Serial Number: 2 (0x2) + Signature Algorithm: sha256WithRSAEncryption + Issuer: CN=ca.localdomain, C=KO, ST=Seoul, L=Nowon, O=Open5GS, OU=Tests + Validity + Not Before: Oct 20 06:43:58 2019 GMT + Not After : Oct 17 06:43:58 2029 GMT + Subject: C=KO, ST=Seoul, O=Open5GS, OU=Tests, CN=hss.localdomain + Subject Public Key Info: + Public Key Algorithm: rsaEncryption + RSA Public-Key: (1024 bit) + Modulus: + 00:d3:e7:ba:6d:14:65:af:df:90:e5:4a:53:56:a1: + f6:89:2e:cb:ee:ce:d6:73:9f:48:b6:96:78:67:a7: + 87:18:b8:ab:c3:0b:31:b3:02:92:48:ed:49:ac:40: + c1:13:3b:13:58:50:cc:2e:59:44:e9:7e:31:02:14: + f0:18:82:95:10:e4:37:b2:5d:14:19:1d:4b:8f:e9: + 1f:45:75:cf:0a:e0:8f:7b:e1:70:7b:ab:e4:af:2b: + 7c:4d:7f:00:d8:eb:cf:f3:96:ab:fc:04:4f:21:ad: + d8:c4:94:05:02:ff:f3:12:48:88:9e:ce:cf:37:29: + e0:28:39:37:62:05:ed:6d:5d + Exponent: 65537 (0x10001) + X509v3 extensions: + X509v3 Basic Constraints: + CA:FALSE + Netscape Comment: + OpenSSL Generated Certificate + X509v3 Subject Key Identifier: + AB:0F:C4:B8:B7:6B:56:12:F5:D4:A3:29:B7:D9:5E:3C:DD:8B:79:DD + X509v3 Authority Key Identifier: + keyid:C5:38:DC:BA:0F:C3:29:6E:3D:99:07:96:D0:87:12:FD:B8:48:CC:37 + + Signature Algorithm: sha256WithRSAEncryption + 43:95:ee:57:3f:4d:ad:bf:42:6c:48:ae:f8:2f:db:f6:cf:2e: + 53:a2:3d:48:0a:48:a4:2c:2a:7c:fa:ec:b1:bd:06:a1:21:a5: + 38:d8:00:05:81:25:91:51:e2:e6:a8:67:a8:c2:f6:5d:2a:f0: + 40:fe:20:d3:82:2d:d9:8c:4c:61:b7:43:87:7f:fe:e4:a1:b6: + fd:54:35:13:4f:63:a5:6b:4a:01:aa:25:e9:80:27:eb:2e:a2: + 18:e0:36:37:a5:57:09:67:ed:8f:1e:13:fd:b8:b2:d7:4e:cf: + 93:d4:bf:75:02:38:4e:d4:4a:9c:35:fb:a8:0b:3a:ba:03:1a: + e6:9e +-----BEGIN CERTIFICATE----- +MIICsjCCAhugAwIBAgIBAjANBgkqhkiG9w0BAQsFADBoMRcwFQYDVQQDDA5jYS5s +b2NhbGRvbWFpbjELMAkGA1UEBhMCS08xDjAMBgNVBAgMBVNlb3VsMQ4wDAYDVQQH +DAVOb3dvbjEQMA4GA1UECgwHT3BlbjVHUzEOMAwGA1UECwwFVGVzdHMwHhcNMTkx +MDIwMDY0MzU4WhcNMjkxMDE3MDY0MzU4WjBZMQswCQYDVQQGEwJLTzEOMAwGA1UE +CAwFU2VvdWwxEDAOBgNVBAoMB09wZW41R1MxDjAMBgNVBAsMBVRlc3RzMRgwFgYD +VQQDDA9oc3MubG9jYWxkb21haW4wgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGB +ANPnum0UZa/fkOVKU1ah9okuy+7O1nOfSLaWeGenhxi4q8MLMbMCkkjtSaxAwRM7 +E1hQzC5ZROl+MQIU8BiClRDkN7JdFBkdS4/pH0V1zwrgj3vhcHur5K8rfE1/ANjr +z/OWq/wETyGt2MSUBQL/8xJIiJ7Ozzcp4Cg5N2IF7W1dAgMBAAGjezB5MAkGA1Ud +EwQCMAAwLAYJYIZIAYb4QgENBB8WHU9wZW5TU0wgR2VuZXJhdGVkIENlcnRpZmlj +YXRlMB0GA1UdDgQWBBSrD8S4t2tWEvXUoym32V483Yt53TAfBgNVHSMEGDAWgBTF +ONy6D8Mpbj2ZB5bQhxL9uEjMNzANBgkqhkiG9w0BAQsFAAOBgQBDle5XP02tv0Js +SK74L9v2zy5Toj1ICkikLCp8+uyxvQahIaU42AAFgSWRUeLmqGeowvZdKvBA/iDT +gi3ZjExht0OHf/7kobb9VDUTT2Ola0oBqiXpgCfrLqIY4DY3pVcJZ+2PHhP9uLLX +Ts+T1L91AjhO1EqcNfuoCzq6Axrmng== +-----END CERTIFICATE----- diff --git a/support/freeDiameter/hss.conf.in b/configs/freeDiameter/hss.conf.in similarity index 94% rename from support/freeDiameter/hss.conf.in rename to configs/freeDiameter/hss.conf.in index 3658567ba..6c42f4272 100644 --- a/support/freeDiameter/hss.conf.in +++ b/configs/freeDiameter/hss.conf.in @@ -106,7 +106,7 @@ ListenOn = "127.0.0.4"; # Default : NO DEFAULT #TLS_Cred = "" , ""; #TLS_Cred = "/etc/ssl/certs/freeDiameter.pem", "/etc/ssl/private/freeDiameter.key"; -TLS_Cred = "@SYSCONF_DIR@/nextepc/freeDiameter/hss.cert.pem", "@SYSCONF_DIR@/nextepc/freeDiameter/hss.key.pem"; +TLS_Cred = "@sysconfdir@/freeDiameter/hss.cert.pem", "@sysconfdir@/freeDiameter/hss.key.pem"; # Certificate authority / trust anchors # The file containing the list of trusted Certificate Authorities (PEM list) @@ -114,7 +114,7 @@ TLS_Cred = "@SYSCONF_DIR@/nextepc/freeDiameter/hss.cert.pem", "@SYSCONF_DIR@/nex # The directive can appear several times to specify several files. # Default : GNUTLS default behavior #TLS_CA = ""; -TLS_CA = "@SYSCONF_DIR@/nextepc/freeDiameter/cacert.pem"; +TLS_CA = "@sysconfdir@/freeDiameter/cacert.pem"; # Certificate Revocation List file # The information about revoked certificates. @@ -222,14 +222,14 @@ TLS_CA = "@SYSCONF_DIR@/nextepc/freeDiameter/cacert.pem"; # 4 - full - display the complete information on a single long line # 8 - tree - display the complete information in an easier to read format spanning several lines. -LoadExtension = "dbg_msg_dumps.so" : "0x8888"; -LoadExtension = "dict_rfc5777.so"; -LoadExtension = "dict_mip6i.so"; -LoadExtension = "dict_nasreq.so"; -LoadExtension = "dict_nas_mipv6.so"; -LoadExtension = "dict_dcca.so"; -LoadExtension = "dict_dcca_3gpp.so"; -LoadExtension = "dict_s6a.so"; +LoadExtension = "@libdir@/freeDiameter/dbg_msg_dumps.fdx" : "0x8888"; +LoadExtension = "@libdir@/freeDiameter/dict_rfc5777.fdx"; +LoadExtension = "@libdir@/freeDiameter/dict_mip6i.fdx"; +LoadExtension = "@libdir@/freeDiameter/dict_nasreq.fdx"; +LoadExtension = "@libdir@/freeDiameter/dict_nas_mipv6.fdx"; +LoadExtension = "@libdir@/freeDiameter/dict_dcca.fdx"; +LoadExtension = "@libdir@/freeDiameter/dict_dcca_3gpp.fdx"; +LoadExtension = "@libdir@/freeDiameter/dict_s6a.fdx"; ############################################################## diff --git a/configs/freeDiameter/hss.key.pem b/configs/freeDiameter/hss.key.pem new file mode 100644 index 000000000..fcf33a1c3 --- /dev/null +++ b/configs/freeDiameter/hss.key.pem @@ -0,0 +1,15 @@ +-----BEGIN RSA PRIVATE KEY----- +MIICXQIBAAKBgQDT57ptFGWv35DlSlNWofaJLsvuztZzn0i2lnhnp4cYuKvDCzGz +ApJI7UmsQMETOxNYUMwuWUTpfjECFPAYgpUQ5DeyXRQZHUuP6R9Fdc8K4I974XB7 +q+SvK3xNfwDY68/zlqv8BE8hrdjElAUC//MSSIiezs83KeAoOTdiBe1tXQIDAQAB +AoGBAM7ShI2Ec/9lSInSsmaC7BpW12p87KirFZBIarpYs634SIS0v0xFvTt6hgae +qRO4/BedvLucG3t91B2BDBoQEaZELCjJ9kCUtzphW+u8/SUvPUCfb5xiLLeDQCVR +oU45JuqlF+ro9XM0x7f1REuTza1Xr20O5n5TzaCzQkdTlMdtAkEA+Yk9aS589D2c +TAj7H5nQMFai/z0JKM7kuBmXaqbsPtnYjdNvVYsCRPcjbhyfIjN88o/QGuUuInpb +PyzUZh3x2wJBANlk8d5ZVco+UE1NX0KzpEXHMY+z8kE4f8IMy0KN1V+An0ZbdxJE +X0aUMz9/K0+V6n0rlpY4QdOnTnbIEg2hTycCQDXBUM9lylk7JH5kuORX2Ddxkm91 +kJGP8EmQicPZ7a6kczgqQiOlbHm625EO7WEKwnHmdSg2Ergur5VubNsKvF0CQQCc +sbv8rpu9qOisr2ZIZ7+yY/9/Ow8Un6rGrf4cPKtdqRIk3myXCB08fDnsPLd1J/Pa +wP5LzMT10BQoXdFVbb3lAkBpNXUkts8O1YxSG5zTruvygjU2n4Lova31icJ8HFaG +pfKHJpqDGPooupFxeCsPVPBZIRtxW70CZcr77eW/XKXv +-----END RSA PRIVATE KEY----- diff --git a/configs/freeDiameter/meson.build b/configs/freeDiameter/meson.build new file mode 100644 index 000000000..923e96180 --- /dev/null +++ b/configs/freeDiameter/meson.build @@ -0,0 +1,57 @@ +# Copyright (C) 2019 by Sukchan Lee + +# This file is part of Open5GS. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +freediameter_sysconfdir = join_paths(sysconfdir, 'freeDiameter') +meson.add_install_script(python3_exe, '-c', + mkdir_p.format(freediameter_sysconfdir)) + +freediameter_conf = ''' + mme.conf + hss.conf + pgw.conf + pcrf.conf +'''.split() + +foreach file : freediameter_conf + gen = configure_file( + input : file + '.in', + output : file, + configuration : conf_data) + meson.add_install_script(python3_exe, '-c', + install_conf.format(gen, freediameter_sysconfdir)) +endforeach + +freediameter_pem = ''' + cacert.pem + mme.cert.pem + mme.key.pem + hss.cert.pem + hss.key.pem + pgw.cert.pem + pgw.key.pem + pcrf.cert.pem + pcrf.key.pem +'''.split() + +foreach file : freediameter_pem + gen = configure_file( + input : file, + output : file, + configuration : conf_data) + meson.add_install_script(python3_exe, '-c', + install_conf.format(gen, freediameter_sysconfdir)) +endforeach diff --git a/configs/freeDiameter/mme.cert.pem b/configs/freeDiameter/mme.cert.pem new file mode 100644 index 000000000..2e84db4ce --- /dev/null +++ b/configs/freeDiameter/mme.cert.pem @@ -0,0 +1,60 @@ +Certificate: + Data: + Version: 3 (0x2) + Serial Number: 1 (0x1) + Signature Algorithm: sha256WithRSAEncryption + Issuer: CN=ca.localdomain, C=KO, ST=Seoul, L=Nowon, O=Open5GS, OU=Tests + Validity + Not Before: Oct 20 06:43:58 2019 GMT + Not After : Oct 17 06:43:58 2029 GMT + Subject: C=KO, ST=Seoul, O=Open5GS, OU=Tests, CN=mme.localdomain + Subject Public Key Info: + Public Key Algorithm: rsaEncryption + RSA Public-Key: (1024 bit) + Modulus: + 00:b5:3a:31:ed:bf:fe:cd:e7:50:cc:94:ba:3d:fd: + 2f:e6:cb:83:25:3d:82:93:26:57:b4:2f:6b:29:d9: + fd:80:c8:c5:82:9c:09:17:14:38:91:57:ac:72:b0: + 86:d4:6f:bd:6b:fa:b9:60:51:9b:ab:6b:68:37:15: + c7:de:8b:bd:e8:da:5a:49:75:03:33:09:8e:49:e4: + d9:5b:3c:2f:ca:47:9b:95:d5:6f:16:e4:8d:39:b4: + 39:dd:51:1a:55:27:68:b9:a0:24:ad:1c:18:48:bb: + 49:54:ae:03:a3:0b:b8:e5:da:b4:c2:7f:09:a4:12: + 8e:97:08:58:24:6a:4b:f4:87 + Exponent: 65537 (0x10001) + X509v3 extensions: + X509v3 Basic Constraints: + CA:FALSE + Netscape Comment: + OpenSSL Generated Certificate + X509v3 Subject Key Identifier: + 20:74:06:F0:AF:F6:2D:90:D1:CB:8C:5C:AB:73:D7:45:99:31:DD:AA + X509v3 Authority Key Identifier: + keyid:C5:38:DC:BA:0F:C3:29:6E:3D:99:07:96:D0:87:12:FD:B8:48:CC:37 + + Signature Algorithm: sha256WithRSAEncryption + 0a:f5:fd:1f:19:52:9a:99:ec:34:67:e8:57:dc:61:73:c0:05: + b0:53:e3:8f:66:86:c9:99:af:28:5a:2a:06:a8:53:b1:80:ea: + 5c:c9:ad:93:ec:b8:b4:b0:e4:04:8b:85:1b:08:93:f2:71:b1: + 21:ab:80:40:e4:27:c6:c5:7a:56:f2:d2:33:6c:f0:1d:f4:99: + 85:55:60:9c:eb:d3:b8:e3:4b:e5:be:1e:d2:39:d5:55:6f:4c: + 20:07:c8:24:1c:21:70:e4:54:17:0b:a5:66:17:be:8b:5c:73: + ca:5e:42:6e:27:15:18:69:dc:c6:49:97:d7:66:e0:a8:ad:9c: + f1:b7 +-----BEGIN CERTIFICATE----- +MIICsjCCAhugAwIBAgIBATANBgkqhkiG9w0BAQsFADBoMRcwFQYDVQQDDA5jYS5s +b2NhbGRvbWFpbjELMAkGA1UEBhMCS08xDjAMBgNVBAgMBVNlb3VsMQ4wDAYDVQQH +DAVOb3dvbjEQMA4GA1UECgwHT3BlbjVHUzEOMAwGA1UECwwFVGVzdHMwHhcNMTkx +MDIwMDY0MzU4WhcNMjkxMDE3MDY0MzU4WjBZMQswCQYDVQQGEwJLTzEOMAwGA1UE +CAwFU2VvdWwxEDAOBgNVBAoMB09wZW41R1MxDjAMBgNVBAsMBVRlc3RzMRgwFgYD +VQQDDA9tbWUubG9jYWxkb21haW4wgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGB +ALU6Me2//s3nUMyUuj39L+bLgyU9gpMmV7QvaynZ/YDIxYKcCRcUOJFXrHKwhtRv +vWv6uWBRm6traDcVx96LvejaWkl1AzMJjknk2Vs8L8pHm5XVbxbkjTm0Od1RGlUn +aLmgJK0cGEi7SVSuA6MLuOXatMJ/CaQSjpcIWCRqS/SHAgMBAAGjezB5MAkGA1Ud +EwQCMAAwLAYJYIZIAYb4QgENBB8WHU9wZW5TU0wgR2VuZXJhdGVkIENlcnRpZmlj +YXRlMB0GA1UdDgQWBBQgdAbwr/YtkNHLjFyrc9dFmTHdqjAfBgNVHSMEGDAWgBTF +ONy6D8Mpbj2ZB5bQhxL9uEjMNzANBgkqhkiG9w0BAQsFAAOBgQAK9f0fGVKamew0 +Z+hX3GFzwAWwU+OPZobJma8oWioGqFOxgOpcya2T7Li0sOQEi4UbCJPycbEhq4BA +5CfGxXpW8tIzbPAd9JmFVWCc69O440vlvh7SOdVVb0wgB8gkHCFw5FQXC6VmF76L +XHPKXkJuJxUYadzGSZfXZuCorZzxtw== +-----END CERTIFICATE----- diff --git a/support/freeDiameter/mme.conf.in b/configs/freeDiameter/mme.conf.in similarity index 94% rename from support/freeDiameter/mme.conf.in rename to configs/freeDiameter/mme.conf.in index 8cb87072b..57393d9d8 100644 --- a/support/freeDiameter/mme.conf.in +++ b/configs/freeDiameter/mme.conf.in @@ -106,7 +106,7 @@ ListenOn = "127.0.0.2"; # Default : NO DEFAULT #TLS_Cred = "" , ""; #TLS_Cred = "/etc/ssl/certs/freeDiameter.pem", "/etc/ssl/private/freeDiameter.key"; -TLS_Cred = "@SYSCONF_DIR@/nextepc/freeDiameter/mme.cert.pem", "@SYSCONF_DIR@/nextepc/freeDiameter/mme.key.pem"; +TLS_Cred = "@sysconfdir@/freeDiameter/mme.cert.pem", "@sysconfdir@/freeDiameter/mme.key.pem"; # Certificate authority / trust anchors # The file containing the list of trusted Certificate Authorities (PEM list) @@ -114,7 +114,7 @@ TLS_Cred = "@SYSCONF_DIR@/nextepc/freeDiameter/mme.cert.pem", "@SYSCONF_DIR@/nex # The directive can appear several times to specify several files. # Default : GNUTLS default behavior #TLS_CA = ""; -TLS_CA = "@SYSCONF_DIR@/nextepc/freeDiameter/cacert.pem"; +TLS_CA = "@sysconfdir@/freeDiameter/cacert.pem"; # Certificate Revocation List file # The information about revoked certificates. @@ -222,14 +222,14 @@ TLS_CA = "@SYSCONF_DIR@/nextepc/freeDiameter/cacert.pem"; # 4 - full - display the complete information on a single long line # 8 - tree - display the complete information in an easier to read format spanning several lines. -LoadExtension = "dbg_msg_dumps.so" : "0x8888"; -LoadExtension = "dict_rfc5777.so"; -LoadExtension = "dict_mip6i.so"; -LoadExtension = "dict_nasreq.so"; -LoadExtension = "dict_nas_mipv6.so"; -LoadExtension = "dict_dcca.so"; -LoadExtension = "dict_dcca_3gpp.so"; -LoadExtension = "dict_s6a.so"; +LoadExtension = "@libdir@/freeDiameter/dbg_msg_dumps.fdx" : "0x8888"; +LoadExtension = "@libdir@/freeDiameter/dict_rfc5777.fdx"; +LoadExtension = "@libdir@/freeDiameter/dict_mip6i.fdx"; +LoadExtension = "@libdir@/freeDiameter/dict_nasreq.fdx"; +LoadExtension = "@libdir@/freeDiameter/dict_nas_mipv6.fdx"; +LoadExtension = "@libdir@/freeDiameter/dict_dcca.fdx"; +LoadExtension = "@libdir@/freeDiameter/dict_dcca_3gpp.fdx"; +LoadExtension = "@libdir@/freeDiameter/dict_s6a.fdx"; ############################################################## diff --git a/configs/freeDiameter/mme.key.pem b/configs/freeDiameter/mme.key.pem new file mode 100644 index 000000000..21b81a428 --- /dev/null +++ b/configs/freeDiameter/mme.key.pem @@ -0,0 +1,15 @@ +-----BEGIN RSA PRIVATE KEY----- +MIICXQIBAAKBgQC1OjHtv/7N51DMlLo9/S/my4MlPYKTJle0L2sp2f2AyMWCnAkX +FDiRV6xysIbUb71r+rlgUZura2g3Fcfei73o2lpJdQMzCY5J5NlbPC/KR5uV1W8W +5I05tDndURpVJ2i5oCStHBhIu0lUrgOjC7jl2rTCfwmkEo6XCFgkakv0hwIDAQAB +AoGBALL3ID1H/8m4Z9tP+EelEzvYt8772kmUcMHYnfw7cJNQMXQUwQlQh7hIG107 +JDr/idDrTUtn69GxhL35PWJxH3z7b9nPQCcPZQ3PZWW8lDXNqNCjV5j+2zDAXqkc +IyxLQuPnTyn9kcB/OIjNGrr86/6JKS1ipbT9AIllV+br5OMhAkEA7KMLbiAI03JH +wBhtnHdtj7NETXDnZd0Plj3ATpa7SOtxmBtqVVOH/1ghAqJ0YScrqa9+eEqcn6mv +sHoJ10wVVwJBAMQOdR6b6H3Swy5dZNYzSKDsWRf4cNK5Kz8HJ8UOLbHTjzcDHNsD +n09McdcnWgNAxV6J0YJzu4LWQjT4b1e77FECQAd+8rG+Wgk4qYUwQOif79yJdTRu +yyWy5vd/ZUQYCj65FpQW6jthtgEkrYcD1mPtdbieUodE9cko+uPAOeeUBWkCQQCt +lL9NImxtOjVkz3t/ylf7YkZfWq9JYnhPjV5AsZTzZIPgCPl7T3G1G9GO1GB1kNsu +IIdGIIFcDacAjxTFcLSBAkA1Bl7gARE2XZR9iVVJ/On2hWFZhtG9RId+k0pVUxKs +KXYnYSiD/WIeVZ6IBswqL2AnEV+kBBuZ7D9aEiDYbXQ/ +-----END RSA PRIVATE KEY----- diff --git a/configs/freeDiameter/pcrf.cert.pem b/configs/freeDiameter/pcrf.cert.pem new file mode 100644 index 000000000..acbd4adfc --- /dev/null +++ b/configs/freeDiameter/pcrf.cert.pem @@ -0,0 +1,60 @@ +Certificate: + Data: + Version: 3 (0x2) + Serial Number: 4 (0x4) + Signature Algorithm: sha256WithRSAEncryption + Issuer: CN=ca.localdomain, C=KO, ST=Seoul, L=Nowon, O=Open5GS, OU=Tests + Validity + Not Before: Oct 20 06:43:58 2019 GMT + Not After : Oct 17 06:43:58 2029 GMT + Subject: C=KO, ST=Seoul, O=Open5GS, OU=Tests, CN=pcrf.localdomain + Subject Public Key Info: + Public Key Algorithm: rsaEncryption + RSA Public-Key: (1024 bit) + Modulus: + 00:c4:63:95:b8:b2:99:ca:4d:dd:ac:b8:e2:78:29: + 43:03:8a:de:6b:05:99:97:b7:90:39:f8:f6:b8:20: + 77:44:4b:1b:95:6c:ad:e1:5f:2c:48:a2:8a:d2:95: + 72:0e:f9:e1:cf:70:4e:45:6e:71:7e:2a:41:29:93: + 7a:12:01:73:0b:10:20:7a:38:66:9f:75:76:21:d6: + 7d:0c:ea:35:47:16:d6:c3:9f:41:ec:e9:98:36:16: + 84:9f:43:38:2b:b2:c8:d9:f3:6c:07:82:e4:ce:c8: + a3:f3:c3:60:13:f3:46:44:fa:f0:ee:a9:48:40:8f: + 80:3e:60:73:ff:6d:59:03:2f + Exponent: 65537 (0x10001) + X509v3 extensions: + X509v3 Basic Constraints: + CA:FALSE + Netscape Comment: + OpenSSL Generated Certificate + X509v3 Subject Key Identifier: + 53:A8:0E:78:45:FB:38:A6:CF:30:E5:FF:BB:CA:E6:CF:A3:4A:DC:53 + X509v3 Authority Key Identifier: + keyid:C5:38:DC:BA:0F:C3:29:6E:3D:99:07:96:D0:87:12:FD:B8:48:CC:37 + + Signature Algorithm: sha256WithRSAEncryption + 47:6b:2b:f9:03:8d:c1:fd:84:21:fe:3c:5b:8c:9d:c1:48:bc: + ae:90:67:c5:ad:1a:80:e9:97:9c:c2:d4:31:1b:7d:4e:1a:72: + 09:fb:92:32:b3:82:79:59:cd:92:21:27:c7:34:c3:76:27:a8: + 11:33:cd:4a:ec:10:cb:44:89:da:47:1a:a4:6a:06:10:fb:f1: + 6a:de:d5:1a:15:de:4a:54:6f:29:b8:de:ec:20:f2:d1:c3:0c: + 9a:8e:97:46:8c:21:c3:63:7f:41:52:41:7e:73:47:43:0a:d1: + 86:0b:f0:fb:9a:1f:6d:b5:93:88:95:88:84:6d:28:8e:29:2e: + 66:9d +-----BEGIN CERTIFICATE----- +MIICszCCAhygAwIBAgIBBDANBgkqhkiG9w0BAQsFADBoMRcwFQYDVQQDDA5jYS5s +b2NhbGRvbWFpbjELMAkGA1UEBhMCS08xDjAMBgNVBAgMBVNlb3VsMQ4wDAYDVQQH +DAVOb3dvbjEQMA4GA1UECgwHT3BlbjVHUzEOMAwGA1UECwwFVGVzdHMwHhcNMTkx +MDIwMDY0MzU4WhcNMjkxMDE3MDY0MzU4WjBaMQswCQYDVQQGEwJLTzEOMAwGA1UE +CAwFU2VvdWwxEDAOBgNVBAoMB09wZW41R1MxDjAMBgNVBAsMBVRlc3RzMRkwFwYD +VQQDDBBwY3JmLmxvY2FsZG9tYWluMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKB +gQDEY5W4spnKTd2suOJ4KUMDit5rBZmXt5A5+Pa4IHdESxuVbK3hXyxIoorSlXIO ++eHPcE5FbnF+KkEpk3oSAXMLECB6OGafdXYh1n0M6jVHFtbDn0Hs6Zg2FoSfQzgr +ssjZ82wHguTOyKPzw2AT80ZE+vDuqUhAj4A+YHP/bVkDLwIDAQABo3sweTAJBgNV +HRMEAjAAMCwGCWCGSAGG+EIBDQQfFh1PcGVuU1NMIEdlbmVyYXRlZCBDZXJ0aWZp +Y2F0ZTAdBgNVHQ4EFgQUU6gOeEX7OKbPMOX/u8rmz6NK3FMwHwYDVR0jBBgwFoAU +xTjcug/DKW49mQeW0IcS/bhIzDcwDQYJKoZIhvcNAQELBQADgYEAR2sr+QONwf2E +If48W4ydwUi8rpBnxa0agOmXnMLUMRt9ThpyCfuSMrOCeVnNkiEnxzTDdieoETPN +SuwQy0SJ2kcapGoGEPvxat7VGhXeSlRvKbje7CDy0cMMmo6XRowhw2N/QVJBfnNH +QwrRhgvw+5ofbbWTiJWIhG0ojikuZp0= +-----END CERTIFICATE----- diff --git a/support/freeDiameter/pcrf.conf.in b/configs/freeDiameter/pcrf.conf.in similarity index 95% rename from support/freeDiameter/pcrf.conf.in rename to configs/freeDiameter/pcrf.conf.in index 9f4c90f1d..75524f8cb 100644 --- a/support/freeDiameter/pcrf.conf.in +++ b/configs/freeDiameter/pcrf.conf.in @@ -106,7 +106,7 @@ ListenOn = "127.0.0.5"; # Default : NO DEFAULT #TLS_Cred = "" , ""; #TLS_Cred = "/etc/ssl/certs/freeDiameter.pem", "/etc/ssl/private/freeDiameter.key"; -TLS_Cred = "@SYSCONF_DIR@/nextepc/freeDiameter/pcrf.cert.pem", "@SYSCONF_DIR@/nextepc/freeDiameter/pcrf.key.pem"; +TLS_Cred = "@sysconfdir@/freeDiameter/pcrf.cert.pem", "@sysconfdir@/freeDiameter/pcrf.key.pem"; # Certificate authority / trust anchors # The file containing the list of trusted Certificate Authorities (PEM list) @@ -114,7 +114,7 @@ TLS_Cred = "@SYSCONF_DIR@/nextepc/freeDiameter/pcrf.cert.pem", "@SYSCONF_DIR@/ne # The directive can appear several times to specify several files. # Default : GNUTLS default behavior #TLS_CA = ""; -TLS_CA = "@SYSCONF_DIR@/nextepc/freeDiameter/cacert.pem"; +TLS_CA = "@sysconfdir@/freeDiameter/cacert.pem"; # Certificate Revocation List file # The information about revoked certificates. @@ -222,13 +222,13 @@ TLS_CA = "@SYSCONF_DIR@/nextepc/freeDiameter/cacert.pem"; # 4 - full - display the complete information on a single long line # 8 - tree - display the complete information in an easier to read format spanning several lines. -LoadExtension = "dbg_msg_dumps.so" : "0x8888"; -LoadExtension = "dict_rfc5777.so"; -LoadExtension = "dict_mip6i.so"; -LoadExtension = "dict_nasreq.so"; -LoadExtension = "dict_nas_mipv6.so"; -LoadExtension = "dict_dcca.so"; -LoadExtension = "dict_dcca_3gpp.so"; +LoadExtension = "@libdir@/freeDiameter/dbg_msg_dumps.fdx" : "0x8888"; +LoadExtension = "@libdir@/freeDiameter/dict_rfc5777.fdx"; +LoadExtension = "@libdir@/freeDiameter/dict_mip6i.fdx"; +LoadExtension = "@libdir@/freeDiameter/dict_nasreq.fdx"; +LoadExtension = "@libdir@/freeDiameter/dict_nas_mipv6.fdx"; +LoadExtension = "@libdir@/freeDiameter/dict_dcca.fdx"; +LoadExtension = "@libdir@/freeDiameter/dict_dcca_3gpp.fdx"; ############################################################## diff --git a/configs/freeDiameter/pcrf.key.pem b/configs/freeDiameter/pcrf.key.pem new file mode 100644 index 000000000..aefcc45a1 --- /dev/null +++ b/configs/freeDiameter/pcrf.key.pem @@ -0,0 +1,15 @@ +-----BEGIN RSA PRIVATE KEY----- +MIICXQIBAAKBgQDEY5W4spnKTd2suOJ4KUMDit5rBZmXt5A5+Pa4IHdESxuVbK3h +XyxIoorSlXIO+eHPcE5FbnF+KkEpk3oSAXMLECB6OGafdXYh1n0M6jVHFtbDn0Hs +6Zg2FoSfQzgrssjZ82wHguTOyKPzw2AT80ZE+vDuqUhAj4A+YHP/bVkDLwIDAQAB +AoGBAJG6b+RhK3uSMjcz7mFKBP9A8fCqdCG/xdcu5i0VcksMDMjhn1mIXPz9GFRR +LxTr2eMrK/mbjb4YLshiNgfcaXdzpZGauK15PNEHemygI4et9b0iE3ZfGM3dGEGi +UmWzXgO347S8CNmm6JX/gtAaCafeapmyms6E4teYFp1UMRIBAkEA7zrq9HZT1CZu +fWN9DraOUVrgMdV8Q/qdKzAqMsTf95r43aRxxe8ZkXpQuf1X0kBDH8cIeOAVu96/ +hmfxCcVZAQJBANIn3YU7xCnUbdK29tYuxAzEw7j4pdfjHEPgkvjV1xsGVwM+DQkF +/yrSgAujxR70uGfBcUF/M9XRniBWg+FRrC8CQBXJ5vZnBJGRAoU3F3/Mjr/IKB1B +1XSXkdMKKv2+wqtZmQsO3DHr6gc+/bVC5snGgpaVWScxOamHyyfhtalvKQECQG+w +PCyo3NIWUd+g2YJvDEZ09EgD7a/UxZrVaYbRryZvsiLJAYiAJWKOyPpmqUaQbMjH +p/dVMSk75Dvvfttq2oUCQQDuEO0xY0gHxzFYH1K82Yw5aDdRsryEQYpb5e+jduH1 +EHACfc2H4Oc3/a39q7On+HnZgxK7gFMpGW+D0MdDDoL6 +-----END RSA PRIVATE KEY----- diff --git a/configs/freeDiameter/pgw.cert.pem b/configs/freeDiameter/pgw.cert.pem new file mode 100644 index 000000000..87c486ed0 --- /dev/null +++ b/configs/freeDiameter/pgw.cert.pem @@ -0,0 +1,60 @@ +Certificate: + Data: + Version: 3 (0x2) + Serial Number: 3 (0x3) + Signature Algorithm: sha256WithRSAEncryption + Issuer: CN=ca.localdomain, C=KO, ST=Seoul, L=Nowon, O=Open5GS, OU=Tests + Validity + Not Before: Oct 20 06:43:58 2019 GMT + Not After : Oct 17 06:43:58 2029 GMT + Subject: C=KO, ST=Seoul, O=Open5GS, OU=Tests, CN=pgw.localdomain + Subject Public Key Info: + Public Key Algorithm: rsaEncryption + RSA Public-Key: (1024 bit) + Modulus: + 00:bf:bc:94:38:f4:03:a5:23:8c:21:ba:4e:5e:51: + f7:76:f5:e1:1e:43:fc:04:a0:f9:b9:9f:47:dd:d3: + b5:aa:83:e8:cb:d0:3c:56:0e:4d:fd:de:b6:93:fa: + eb:a3:94:4a:79:68:1d:84:61:cf:b7:d0:ac:d0:41: + ef:66:e0:8a:40:ec:b4:d2:5b:ce:cc:2c:cd:7d:7e: + 87:73:b0:4b:4d:79:54:3b:a4:48:bb:19:4f:9f:7e: + 30:e7:af:17:32:a3:95:af:c4:a5:19:8f:53:3c:16: + cd:54:9d:38:98:2b:0f:b7:cd:33:91:f0:ef:b8:d2: + 9f:0e:fe:8e:77:9d:e8:ba:f3 + Exponent: 65537 (0x10001) + X509v3 extensions: + X509v3 Basic Constraints: + CA:FALSE + Netscape Comment: + OpenSSL Generated Certificate + X509v3 Subject Key Identifier: + EB:F6:EA:D3:F2:F2:C6:C6:83:EF:13:CD:AF:49:A8:ED:03:DF:7F:ED + X509v3 Authority Key Identifier: + keyid:C5:38:DC:BA:0F:C3:29:6E:3D:99:07:96:D0:87:12:FD:B8:48:CC:37 + + Signature Algorithm: sha256WithRSAEncryption + 3b:00:ef:c4:9f:69:c3:22:06:76:6f:70:88:50:1c:f3:a2:9a: + 68:00:34:fa:3a:68:b2:94:fe:7c:31:7d:4e:95:bd:47:4d:69: + 1f:76:32:64:83:1b:5b:11:71:bb:0a:7a:af:72:54:7a:dc:30: + 51:e5:93:27:8c:8a:51:e6:e5:15:53:70:14:85:3b:77:1a:87: + ce:d0:6f:31:07:5d:14:30:d7:de:a0:b5:a7:a1:96:18:1a:fd: + ea:9f:c2:ea:bb:72:52:84:b6:57:6d:70:93:35:64:d3:8b:82: + 1b:7b:ea:85:8a:fb:c6:b3:e0:66:ad:db:11:dd:5e:6e:22:dd: + b4:23 +-----BEGIN CERTIFICATE----- +MIICsjCCAhugAwIBAgIBAzANBgkqhkiG9w0BAQsFADBoMRcwFQYDVQQDDA5jYS5s +b2NhbGRvbWFpbjELMAkGA1UEBhMCS08xDjAMBgNVBAgMBVNlb3VsMQ4wDAYDVQQH +DAVOb3dvbjEQMA4GA1UECgwHT3BlbjVHUzEOMAwGA1UECwwFVGVzdHMwHhcNMTkx +MDIwMDY0MzU4WhcNMjkxMDE3MDY0MzU4WjBZMQswCQYDVQQGEwJLTzEOMAwGA1UE +CAwFU2VvdWwxEDAOBgNVBAoMB09wZW41R1MxDjAMBgNVBAsMBVRlc3RzMRgwFgYD +VQQDDA9wZ3cubG9jYWxkb21haW4wgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGB +AL+8lDj0A6UjjCG6Tl5R93b14R5D/ASg+bmfR93TtaqD6MvQPFYOTf3etpP666OU +SnloHYRhz7fQrNBB72bgikDstNJbzswszX1+h3OwS015VDukSLsZT59+MOevFzKj +la/EpRmPUzwWzVSdOJgrD7fNM5Hw77jSnw7+jned6LrzAgMBAAGjezB5MAkGA1Ud +EwQCMAAwLAYJYIZIAYb4QgENBB8WHU9wZW5TU0wgR2VuZXJhdGVkIENlcnRpZmlj +YXRlMB0GA1UdDgQWBBTr9urT8vLGxoPvE82vSajtA99/7TAfBgNVHSMEGDAWgBTF +ONy6D8Mpbj2ZB5bQhxL9uEjMNzANBgkqhkiG9w0BAQsFAAOBgQA7AO/En2nDIgZ2 +b3CIUBzzoppoADT6OmiylP58MX1Olb1HTWkfdjJkgxtbEXG7CnqvclR63DBR5ZMn +jIpR5uUVU3AUhTt3GofO0G8xB10UMNfeoLWnoZYYGv3qn8Lqu3JShLZXbXCTNWTT +i4Ibe+qFivvGs+BmrdsR3V5uIt20Iw== +-----END CERTIFICATE----- diff --git a/support/freeDiameter/pgw.conf.in b/configs/freeDiameter/pgw.conf.in similarity index 95% rename from support/freeDiameter/pgw.conf.in rename to configs/freeDiameter/pgw.conf.in index 1283584c0..e5ee14ba9 100644 --- a/support/freeDiameter/pgw.conf.in +++ b/configs/freeDiameter/pgw.conf.in @@ -106,7 +106,7 @@ ListenOn = "127.0.0.3"; # Default : NO DEFAULT #TLS_Cred = "" , ""; #TLS_Cred = "/etc/ssl/certs/freeDiameter.pem", "/etc/ssl/private/freeDiameter.key"; -TLS_Cred = "@SYSCONF_DIR@/nextepc/freeDiameter/pgw.cert.pem", "@SYSCONF_DIR@/nextepc/freeDiameter/pgw.key.pem"; +TLS_Cred = "@sysconfdir@/freeDiameter/pgw.cert.pem", "@sysconfdir@/freeDiameter/pgw.key.pem"; # Certificate authority / trust anchors # The file containing the list of trusted Certificate Authorities (PEM list) @@ -114,7 +114,7 @@ TLS_Cred = "@SYSCONF_DIR@/nextepc/freeDiameter/pgw.cert.pem", "@SYSCONF_DIR@/nex # The directive can appear several times to specify several files. # Default : GNUTLS default behavior #TLS_CA = ""; -TLS_CA = "@SYSCONF_DIR@/nextepc/freeDiameter/cacert.pem"; +TLS_CA = "@sysconfdir@/freeDiameter/cacert.pem"; # Certificate Revocation List file # The information about revoked certificates. @@ -222,13 +222,13 @@ TLS_CA = "@SYSCONF_DIR@/nextepc/freeDiameter/cacert.pem"; # 4 - full - display the complete information on a single long line # 8 - tree - display the complete information in an easier to read format spanning several lines. -LoadExtension = "dbg_msg_dumps.so" : "0x8888"; -LoadExtension = "dict_rfc5777.so"; -LoadExtension = "dict_mip6i.so"; -LoadExtension = "dict_nasreq.so"; -LoadExtension = "dict_nas_mipv6.so"; -LoadExtension = "dict_dcca.so"; -LoadExtension = "dict_dcca_3gpp.so"; +LoadExtension = "@libdir@/freeDiameter/dbg_msg_dumps.fdx" : "0x8888"; +LoadExtension = "@libdir@/freeDiameter/dict_rfc5777.fdx"; +LoadExtension = "@libdir@/freeDiameter/dict_mip6i.fdx"; +LoadExtension = "@libdir@/freeDiameter/dict_nasreq.fdx"; +LoadExtension = "@libdir@/freeDiameter/dict_nas_mipv6.fdx"; +LoadExtension = "@libdir@/freeDiameter/dict_dcca.fdx"; +LoadExtension = "@libdir@/freeDiameter/dict_dcca_3gpp.fdx"; ############################################################## diff --git a/configs/freeDiameter/pgw.key.pem b/configs/freeDiameter/pgw.key.pem new file mode 100644 index 000000000..62bfe370e --- /dev/null +++ b/configs/freeDiameter/pgw.key.pem @@ -0,0 +1,15 @@ +-----BEGIN RSA PRIVATE KEY----- +MIICXAIBAAKBgQC/vJQ49AOlI4whuk5eUfd29eEeQ/wEoPm5n0fd07Wqg+jL0DxW +Dk393raT+uujlEp5aB2EYc+30KzQQe9m4IpA7LTSW87MLM19fodzsEtNeVQ7pEi7 +GU+ffjDnrxcyo5WvxKUZj1M8Fs1UnTiYKw+3zTOR8O+40p8O/o53nei68wIDAQAB +AoGAarZPHH+aw79MD718PnyKKVhhqZGW4xCgzFG9EtXwpu1xlHXaDt85QxFANo4R +teIjrPxoaTRzAlAOzn3T+0L/TnhU67WUOvSQEhGzS1liNNw024NekOy3rrqAvB3D +esmOtR5+LtadCb2CuJdL0XALUp+F/g25CoryXsKMIg4Eg9ECQQD9fbT7n3GurBlF +s1E+Ah1+fpD2qOvyFrK4Yzs/CYn5s1yEO0AMwLavO71Y+SIGzFnuIASbyEX4Adl/ +hxSvDp5ZAkEAwaJmOzgLsLvSf5RkYzaX+/IO/DBYowDknalMobDplaOlK5LLFNiM +naEH6A6UV981OnIr6ScU8knC0HyDmmTyKwJAfu3jIdvE4OHsBaq0k4gbnKtjix8q +hh43f3ywve/Y1t+pA81nVPtqfnQ7a8HT9/N7VHFT3W17G6RRdDn/cWiwgQJAOuD+ +5RLtuxfhshmVTPXU0S+Rju3EhgxHeAl628/Ht1DDcLR6PCR83ZGRreaBBRdCQDtn +TsYrgGEdc/forJH1cQJBAMzBcACt51/OuHtPF+kxeRqgLINji82EQOGmZBvtWySI +cRFndLh6N8OOkDnP2MwGY7j0jWveKE8mVA12ymMWZuU= +-----END RSA PRIVATE KEY----- diff --git a/support/config/nextepc.conf.in b/configs/installed.yaml.in similarity index 82% rename from support/config/nextepc.conf.in rename to configs/installed.yaml.in index 1f35fc9e6..f32f85420 100644 --- a/support/config/nextepc.conf.in +++ b/configs/installed.yaml.in @@ -1,7 +1,7 @@ -db_uri: mongodb://localhost/nextepc +db_uri: mongodb://localhost/open5gs logger: - file: @LOCALSTATE_DIR@/log/nextepc/nextepc.log + file: @localstatedir@/log/open5gs/open5gs.log # # o Set OGS_LOG_INFO to all domain level # - If `level` is omitted, the default level is OGS_LOG_INFO) @@ -105,7 +105,7 @@ max: pool: mme: - freeDiameter: mme.conf + freeDiameter: @sysconfdir@/freeDiameter/mme.conf # # > @@ -203,7 +203,7 @@ mme: # lac: 43692 # - addr # - 127.0.0.3 -# - fe80::2%@LO_DEV@ +# - fe80::2%@loopback_devname@ # map: # tai: # plmn_id: @@ -303,15 +303,15 @@ mme: # # # network_name: -# full: NextEPC +# full: Open5GS # short: Next # network_name: - full: NextEPC + full: Open5GS hss: - freeDiameter: hss.conf + freeDiameter: @sysconfdir@/freeDiameter/hss.conf sgw: # @@ -319,39 +319,39 @@ sgw: # # o Specify SGW addresses the GTP-C must connect to # -# o One SGW is defined. If prefer_ipv4 is not true, [fe80::2%@LO_DEV@] is selected. +# o One SGW is defined. If prefer_ipv4 is not true, [fe80::2%@loopback_devname@] is selected. # gtpc: # addr: # - 127.0.0.2 -# - fe80::2%@LO_DEV@ +# - fe80::2%@loopback_devname@ # # o Two SGW are defined. MME selects SGW with round-robin manner per UE # gtpc: # - addr: 127.0.0.2 -# - addr: fe80::2%@LO_DEV@ +# - addr: fe80::2%@loopback_devname@ # # o Three SGW are defined. MME selects SGW with round-robin manner per UE # gtpc: # - addr # - 127.0.0.2 -# - fe80::2%@LO_DEV@ +# - fe80::2%@loopback_devname@ # - addr # - 127.0.0.12 -# - fe80::12%@LO_DEV@ -# - name: sgw3.nextepc.org +# - fe80::12%@loopback_devname@ +# - name: sgw3.open5gs.org # # ------------------------ SGW -------------------------- # -# o GTP-C Server(127.0.0.2:2123, [fe80::2%@LO_DEV@]:2123) +# o GTP-C Server(127.0.0.2:2123, [fe80::2%@loopback_devname@]:2123) # gtpc: # addr: # - 127.0.0.2 -# - fe80::2%@LO_DEV@ +# - fe80::2%@loopback_devname@ # -# o On SGW, Same Configuration(127.0.0.2:2123, [fe80::2%@LO_DEV@]:2123) as below. +# o On SGW, Same Configuration(127.0.0.2:2123, [fe80::2%@loopback_devname@]:2123) as below. # gtpc: # - addr: 127.0.0.2 -# - addr: fe80::2%@LO_DEV@ +# - addr: fe80::2%@loopback_devname@ # gtpc: addr: 127.0.0.2 @@ -387,7 +387,7 @@ sgw: gtpu: pgw: - freeDiameter: pgw.conf + freeDiameter: @sysconfdir@/freeDiameter/pgw.conf # # ------------------------ MME -------------------------- @@ -398,17 +398,17 @@ pgw: # you can use a specific PGW node for each UE. # # o Two PGW are defined. 127.0.0.3:2123 is used. -# [fe80::3%@LO_DEV@]:2123 is ignored. +# [fe80::3%@loopback_devname@]:2123 is ignored. # gtpc: # - addr: 127.0.0.3 -# - addr: fe80::3%@LO_DEV@ +# - addr: fe80::3%@loopback_devname@ # # o One PGW is defined. if prefer_ipv4 is not true, -# [fe80::3%@LO_DEV@] is selected. +# [fe80::3%@loopback_devname@] is selected. # gtpc: # - addr: # - 127.0.0.3 -# - fe80::3%@LO_DEV@ +# - fe80::3%@loopback_devname@ # # o Two PGW are defined with a different APN. # - Note that if PGW IP for UE is configured in HSS, @@ -426,16 +426,16 @@ pgw: # apn: volte # ------------------------ PGW -------------------------- # -# o GTP-C Server(127.0.0.3:2123, [fe80::3%@LO_DEV@]:2123) +# o GTP-C Server(127.0.0.3:2123, [fe80::3%@loopback_devname@]:2123) # gtpc: # addr: # - 127.0.0.3 -# - fe80::3%@LO_DEV@ +# - fe80::3%@loopback_devname@ # -# o On PGW, Same configuration(127.0.0.3:2123, [fe80::3%@LO_DEV@]:2123). +# o On PGW, Same configuration(127.0.0.3:2123, [fe80::3%@loopback_devname@]:2123). # gtpc: # - addr: 127.0.0.3 -# - addr: fe80::3%@LO_DEV@ +# - addr: fe80::3%@loopback_devname@ # gtpc: addr: @@ -462,14 +462,14 @@ pgw: # # # o IPv4 Pool -# $ sudo ip addr add 45.45.0.1/16 dev pgwtun +# $ sudo ip addr add 45.45.0.1/16 dev ogstun # # ue_pool: # addr: 45.45.0.1/16 # # o IPv4/IPv6 Pool -# $ sudo ip addr add 45.45.0.1/16 dev pgwtun -# $ sudo ip addr add cafe:1::1/64 dev pgwtun +# $ sudo ip addr add 45.45.0.1/16 dev ogstun +# $ sudo ip addr add cafe:1::1/64 dev ogstun # # ue_pool: # - addr: 45.45.0.1/16 @@ -478,10 +478,10 @@ pgw: # # o Specific APN(e.g 'volte') uses 45.46.0.1/16, cafe:2::1/64 # All other APNs use 45.45.0.1/16, cafe:1::1/64 -# $ sudo ip addr add 45.45.0.1/16 dev pgwtun -# $ sudo ip addr add 45.46.0.1/16 dev pgwtun -# $ sudo ip addr add cafe:1::1/64 dev pgwtun -# $ sudo ip addr add cafe:2::1/64 dev pgwtun +# $ sudo ip addr add 45.45.0.1/16 dev ogstun +# $ sudo ip addr add 45.46.0.1/16 dev ogstun +# $ sudo ip addr add cafe:1::1/64 dev ogstun +# $ sudo ip addr add cafe:2::1/64 dev ogstun # # ue_pool: # - addr: 45.45.0.1/16 @@ -491,22 +491,22 @@ pgw: # - addr: cafe:2::1/64 # apn: volte # -# o Multiple Devices (default: pgwtun) -# $ sudo ip addr add 45.45.0.1/16 dev pgwtun -# $ sudo ip addr add cafe:1::1/64 dev pgwtun2 -# $ sudo ip addr add 45.46.0.1/16 dev pgwtun3 -# $ sudo ip addr add cafe:2::1/64 dev pgwtun3 +# o Multiple Devices (default: ogstun) +# $ sudo ip addr add 45.45.0.1/16 dev ogstun +# $ sudo ip addr add cafe:1::1/64 dev ogstun2 +# $ sudo ip addr add 45.46.0.1/16 dev ogstun3 +# $ sudo ip addr add cafe:2::1/64 dev ogstun3 # # ue_pool: # - addr: 45.45.0.1/16 # - addr: cafe:1::1/64 -# dev: pgwtun2 +# dev: ogstun2 # - addr: 45.46.0.1/16 # apn: volte -# dev: pgwtun3 +# dev: ogstun3 # - addr: cafe:2::1/64 # apn: volte -# dev: pgwtun3 +# dev: ogstun3 # ue_pool: - addr: 45.45.0.1/16 @@ -534,4 +534,4 @@ pgw: # pcrf: - freeDiameter: pcrf.conf + freeDiameter: @sysconfdir@/freeDiameter/pcrf.conf diff --git a/configs/logrotate/meson.build b/configs/logrotate/meson.build new file mode 100644 index 000000000..6c27ca954 --- /dev/null +++ b/configs/logrotate/meson.build @@ -0,0 +1,19 @@ +# Copyright (C) 2019 by Sukchan Lee + +# This file is part of Open5GS. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +file = 'open5gs' +configure_file(input : file + '.in', output : file, configuration : conf_data) diff --git a/configs/logrotate/open5gs.in b/configs/logrotate/open5gs.in new file mode 100644 index 000000000..aa6cc0b19 --- /dev/null +++ b/configs/logrotate/open5gs.in @@ -0,0 +1,14 @@ +@localstatedir@/log/open5gs/*.log { + daily + sharedscripts + missingok + compress + rotate 14 + create 640 open5gs open5gs + + postrotate + for i in pcrfd pgwd sgwd hssd mmed; do + systemctl reload open5gs-$i + done + endscript +} diff --git a/configs/meson.build b/configs/meson.build new file mode 100644 index 000000000..056fef392 --- /dev/null +++ b/configs/meson.build @@ -0,0 +1,56 @@ +# Copyright (C) 2019 by Sukchan Lee + +# This file is part of Open5GS. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +conf_data = configuration_data() + +conf_data.set('bindir', bindir) +conf_data.set('sysconfdir', sysconfdir) +conf_data.set('libdir', libdir) +conf_data.set('localstatedir', localstatedir) + +freediameter_extensions_builddir = join_paths( + meson.build_root(), 'subprojects', 'freediameter', 'extensions') +conf_data.set('freediameter_extensions_builddir', + freediameter_extensions_builddir) + +if host_system == 'linux' + conf_data.set('loopback_devname', 'lo') +else + conf_data.set('loopback_devname', 'lo0') +endif + +example_conf = ''' + simple.yaml + installed.yaml + mnc3.yaml + csfb.yaml + volte.yaml + srslte.yaml +'''.split() + +foreach file : example_conf + gen = configure_file( + input : file + '.in', + output : file, + configuration : conf_data) +endforeach + +subdir('open5gs') +subdir('freeDiameter') +subdir('systemd') +subdir('logrotate') +subdir('newsyslog') diff --git a/configs/mnc3.yaml.in b/configs/mnc3.yaml.in new file mode 100644 index 000000000..c8cc83e8b --- /dev/null +++ b/configs/mnc3.yaml.in @@ -0,0 +1,127 @@ +db_uri: mongodb://localhost/open5gs + +logger: + +parameter: + no_ipv6: true + +mme: + freeDiameter: + identity: mme.localdomain + realm: localdomain + listen_on: 127.0.0.2 + load_extension: + - module: @freediameter_extensions_builddir@/dbg_msg_dumps.fdx + conf: 0x8888 + - module: @freediameter_extensions_builddir@/dict_rfc5777.fdx + - module: @freediameter_extensions_builddir@/dict_mip6i.fdx + - module: @freediameter_extensions_builddir@/dict_nasreq.fdx + - module: @freediameter_extensions_builddir@/dict_nas_mipv6.fdx + - module: @freediameter_extensions_builddir@/dict_dcca.fdx + - module: @freediameter_extensions_builddir@/dict_dcca_3gpp.fdx + - module: @freediameter_extensions_builddir@/dict_s6a.fdx + connect: + - identity: hss.localdomain + addr: 127.0.0.4 + + s1ap: + addr: 127.0.0.1 + gtpc: + addr: 127.0.0.1 + gummei: + plmn_id: + mcc: 310 + mnc: 014 + mme_gid: 32798 + mme_code: 100 + tai: + plmn_id: + mcc: 310 + mnc: 014 + tac: [50, 51, 52, 53] + security: + integrity_order : [ EIA1, EIA2, EIA0 ] + ciphering_order : [ EEA0, EEA1, EEA2 ] + + network_name: + full: Open5GS + +hss: + freeDiameter: + identity: hss.localdomain + realm: localdomain + listen_on: 127.0.0.4 + load_extension: + - module: @freediameter_extensions_builddir@/dbg_msg_dumps.fdx + conf: 0x8888 + - module: @freediameter_extensions_builddir@/dict_rfc5777.fdx + - module: @freediameter_extensions_builddir@/dict_mip6i.fdx + - module: @freediameter_extensions_builddir@/dict_nasreq.fdx + - module: @freediameter_extensions_builddir@/dict_nas_mipv6.fdx + - module: @freediameter_extensions_builddir@/dict_dcca.fdx + - module: @freediameter_extensions_builddir@/dict_dcca_3gpp.fdx + - module: @freediameter_extensions_builddir@/dict_s6a.fdx + connect: + - identity: mme.localdomain + addr: 127.0.0.2 + +sgw: + gtpc: + addr: 127.0.0.2 + gtpu: + addr: 127.0.0.2 + +pgw: + freeDiameter: + identity: pgw.localdomain + realm: localdomain + listen_on: 127.0.0.3 + load_extension: + - module: @freediameter_extensions_builddir@/dbg_msg_dumps.fdx + conf: 0x8888 + - module: @freediameter_extensions_builddir@/dict_rfc5777.fdx + - module: @freediameter_extensions_builddir@/dict_mip6i.fdx + - module: @freediameter_extensions_builddir@/dict_nasreq.fdx + - module: @freediameter_extensions_builddir@/dict_nas_mipv6.fdx + - module: @freediameter_extensions_builddir@/dict_dcca.fdx + - module: @freediameter_extensions_builddir@/dict_dcca_3gpp.fdx + connect: + connect: + - identity: pcrf.localdomain + addr: 127.0.0.5 + + gtpc: + - addr: + - 127.0.0.3 + - ::1 + - addr: + - 127.0.0.4 + apn: starent.com + gtpu: + - addr: 127.0.0.3 + - addr: ::1 + ue_pool: + - addr: 45.45.0.1/16 + - addr: cafe::1/64 + dns: + - 8.8.8.8 + - 8.8.4.4 + - 2001:4860:4860::8888 + - 2001:4860:4860::8844 +pcrf: + freeDiameter: + identity: pcrf.localdomain + realm: localdomain + listen_on: 127.0.0.5 + load_extension: + - module: @freediameter_extensions_builddir@/dbg_msg_dumps.fdx + conf: 0x8888 + - module: @freediameter_extensions_builddir@/dict_rfc5777.fdx + - module: @freediameter_extensions_builddir@/dict_mip6i.fdx + - module: @freediameter_extensions_builddir@/dict_nasreq.fdx + - module: @freediameter_extensions_builddir@/dict_nas_mipv6.fdx + - module: @freediameter_extensions_builddir@/dict_dcca.fdx + - module: @freediameter_extensions_builddir@/dict_dcca_3gpp.fdx + connect: + - identity: pgw.localdomain + addr: 127.0.0.3 diff --git a/configs/newsyslog/meson.build b/configs/newsyslog/meson.build new file mode 100644 index 000000000..12e30fe3d --- /dev/null +++ b/configs/newsyslog/meson.build @@ -0,0 +1,19 @@ +# Copyright (C) 2019 by Sukchan Lee + +# This file is part of Open5GS. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +file = 'open5gs.conf' +configure_file(input : file + '.in', output : file, configuration : conf_data) diff --git a/configs/newsyslog/open5gs.conf.in b/configs/newsyslog/open5gs.conf.in new file mode 100644 index 000000000..757f00adf --- /dev/null +++ b/configs/newsyslog/open5gs.conf.in @@ -0,0 +1,8 @@ +# truncate rails logs every day at midnight, keep 14 previous logs, compress previous logs +# +# logfilename [owner:group] mode count size when flags [/pid_file] [sig_num] +@localstatedir@/log/open5gs/pcrf.log 644 14 * $D0 GZ @LOCALSTATE_DIR@/run/open5gs-pcrfd/pid` +@localstatedir@/log/open5gs/pgw.log 644 14 * $D0 GZ @LOCALSTATE_DIR@/run/open5gs-pgwd/pid` +@localstatedir@/log/open5gs/sgw.log 644 14 * $D0 GZ @LOCALSTATE_DIR@/run/open5gs-sgwd/pid` +@localstatedir@/log/open5gs/hss.log 644 14 * $D0 GZ @LOCALSTATE_DIR@/run/open5gs-hssd/pid` +@localstatedir@/log/open5gs/mme.log 644 14 * $D0 GZ @LOCALSTATE_DIR@/run/open5gs-mmed/pid` diff --git a/configs/open5gs/hss.yaml.in b/configs/open5gs/hss.yaml.in new file mode 100644 index 000000000..61e08efd1 --- /dev/null +++ b/configs/open5gs/hss.yaml.in @@ -0,0 +1,9 @@ +db_uri: mongodb://localhost/open5gs + +logger: + file: @localstatedir@/log/open5gs/hss.log + +parameter: + +hss: + freeDiameter: @sysconfdir@/freeDiameter/hss.conf diff --git a/configs/open5gs/meson.build b/configs/open5gs/meson.build new file mode 100644 index 000000000..377a21ab3 --- /dev/null +++ b/configs/open5gs/meson.build @@ -0,0 +1,37 @@ +# Copyright (C) 2019 by Sukchan Lee + +# This file is part of Open5GS. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +open5gs_sysconfdir = join_paths(sysconfdir, 'open5gs') +meson.add_install_script(python3_exe, '-c', + mkdir_p.format(open5gs_sysconfdir)) + +open5gs_conf = ''' + mme.yaml + hss.yaml + sgw.yaml + pgw.yaml + pcrf.yaml +'''.split() + +foreach file : open5gs_conf + gen = configure_file( + input : file + '.in', + output : file, + configuration : conf_data) + meson.add_install_script(python3_exe, '-c', + install_conf.format(gen, open5gs_sysconfdir)) +endforeach diff --git a/support/config/mme.conf.in b/configs/open5gs/mme.yaml.in similarity index 76% rename from support/config/mme.conf.in rename to configs/open5gs/mme.yaml.in index b2b094ce5..e74fa70f7 100644 --- a/support/config/mme.conf.in +++ b/configs/open5gs/mme.yaml.in @@ -1,12 +1,10 @@ -### For reference, see `nextepc.conf` - logger: - file: @LOCALSTATE_DIR@/log/nextepc/mme.log + file: @localstatedir@/log/open5gs/mme.log parameter: mme: - freeDiameter: mme.conf + freeDiameter: @sysconfdir@/freeDiameter/mme.conf s1ap: gtpc: gummei: @@ -24,7 +22,7 @@ mme: integrity_order : [ EIA1, EIA2, EIA0 ] ciphering_order : [ EEA0, EEA1, EEA2 ] network_name: - full: NextEPC + full: Open5GS sgw: gtpc: diff --git a/configs/open5gs/pcrf.yaml.in b/configs/open5gs/pcrf.yaml.in new file mode 100644 index 000000000..349b3b47f --- /dev/null +++ b/configs/open5gs/pcrf.yaml.in @@ -0,0 +1,9 @@ +db_uri: mongodb://localhost/open5gs + +logger: + file: @localstatedir@/log/open5gs/pcrf.log + +parameter: + +pcrf: + freeDiameter: @sysconfdir@/freeDiameter/pcrf.conf diff --git a/support/config/pgw.conf.in b/configs/open5gs/pgw.yaml.in similarity index 61% rename from support/config/pgw.conf.in rename to configs/open5gs/pgw.yaml.in index 980eb22b8..a5bbb30ee 100644 --- a/support/config/pgw.conf.in +++ b/configs/open5gs/pgw.yaml.in @@ -1,16 +1,13 @@ -### For reference, see `nextepc.conf` - logger: - file: @LOCALSTATE_DIR@/log/nextepc/pgw.log + file: @localstatedir@/log/open5gs/pgw.log parameter: pgw: - freeDiameter: pgw.conf + freeDiameter: @sysconfdir@/freeDiameter/pgw.conf gtpc: - addr: - - 127.0.0.3 - - ::1 + - addr: 127.0.0.3 + - addr: ::1 gtpu: - addr: 127.0.0.3 - addr: ::1 diff --git a/support/config/sgw.conf.in b/configs/open5gs/sgw.yaml.in similarity index 50% rename from support/config/sgw.conf.in rename to configs/open5gs/sgw.yaml.in index cd67ed278..b76ac9cbc 100644 --- a/support/config/sgw.conf.in +++ b/configs/open5gs/sgw.yaml.in @@ -1,7 +1,5 @@ -### For reference, see `nextepc.conf` - logger: - file: @LOCALSTATE_DIR@/log/nextepc/sgw.log + file: @localstatedir@/log/open5gs/sgw.log parameter: no_ipv6: true diff --git a/configs/simple.yaml.in b/configs/simple.yaml.in new file mode 100644 index 000000000..4b63bf437 --- /dev/null +++ b/configs/simple.yaml.in @@ -0,0 +1,123 @@ +db_uri: mongodb://localhost/open5gs + +logger: + +parameter: + no_ipv6: true + +mme: + freeDiameter: + identity: mme.localdomain + realm: localdomain + listen_on: 127.0.0.2 + load_extension: + - module: @freediameter_extensions_builddir@/dbg_msg_dumps.fdx + conf: 0x8888 + - module: @freediameter_extensions_builddir@/dict_rfc5777.fdx + - module: @freediameter_extensions_builddir@/dict_mip6i.fdx + - module: @freediameter_extensions_builddir@/dict_nasreq.fdx + - module: @freediameter_extensions_builddir@/dict_nas_mipv6.fdx + - module: @freediameter_extensions_builddir@/dict_dcca.fdx + - module: @freediameter_extensions_builddir@/dict_dcca_3gpp.fdx + - module: @freediameter_extensions_builddir@/dict_s6a.fdx + connect: + - identity: hss.localdomain + addr: 127.0.0.4 + + s1ap: + addr: 127.0.0.1 + gtpc: + addr: 127.0.0.1 + gummei: + plmn_id: + mcc: 001 + mnc: 01 + mme_gid: 2 + mme_code: 1 + tai: + plmn_id: + mcc: 001 + mnc: 01 + tac: 12345 + security: + integrity_order : [ EIA1, EIA2, EIA0 ] + ciphering_order : [ EEA0, EEA1, EEA2 ] + + network_name: + full: Open5GS + +hss: + freeDiameter: + identity: hss.localdomain + realm: localdomain + listen_on: 127.0.0.4 + load_extension: + - module: @freediameter_extensions_builddir@/dbg_msg_dumps.fdx + conf: 0x8888 + - module: @freediameter_extensions_builddir@/dict_rfc5777.fdx + - module: @freediameter_extensions_builddir@/dict_mip6i.fdx + - module: @freediameter_extensions_builddir@/dict_nasreq.fdx + - module: @freediameter_extensions_builddir@/dict_nas_mipv6.fdx + - module: @freediameter_extensions_builddir@/dict_dcca.fdx + - module: @freediameter_extensions_builddir@/dict_dcca_3gpp.fdx + - module: @freediameter_extensions_builddir@/dict_s6a.fdx + connect: + - identity: mme.localdomain + addr: 127.0.0.2 + +sgw: + gtpc: + addr: 127.0.0.2 + gtpu: + addr: 127.0.0.2 + +pgw: + freeDiameter: + identity: pgw.localdomain + realm: localdomain + listen_on: 127.0.0.3 + load_extension: + - module: @freediameter_extensions_builddir@/dbg_msg_dumps.fdx + conf: 0x8888 + - module: @freediameter_extensions_builddir@/dict_rfc5777.fdx + - module: @freediameter_extensions_builddir@/dict_mip6i.fdx + - module: @freediameter_extensions_builddir@/dict_nasreq.fdx + - module: @freediameter_extensions_builddir@/dict_nas_mipv6.fdx + - module: @freediameter_extensions_builddir@/dict_dcca.fdx + - module: @freediameter_extensions_builddir@/dict_dcca_3gpp.fdx + connect: + - identity: pcrf.localdomain + addr: 127.0.0.5 + + gtpc: + addr: + - 127.0.0.3 + - ::1 + gtpu: + - addr: 127.0.0.3 + - addr: ::1 + ue_pool: + - addr: 45.45.0.1/16 + - addr: cafe::1/64 + dns: + - 8.8.8.8 + - 8.8.4.4 + - 2001:4860:4860::8888 + - 2001:4860:4860::8844 +pcrf: + freeDiameter: + identity: pcrf.localdomain + realm: localdomain + listen_on: 127.0.0.5 + load_extension: + - module: @freediameter_extensions_builddir@/dbg_msg_dumps.fdx + conf: 0x8888 + - module: @freediameter_extensions_builddir@/dict_rfc5777.fdx + - module: @freediameter_extensions_builddir@/dict_mip6i.fdx + - module: @freediameter_extensions_builddir@/dict_nasreq.fdx + - module: @freediameter_extensions_builddir@/dict_nas_mipv6.fdx + - module: @freediameter_extensions_builddir@/dict_dcca.fdx + - module: @freediameter_extensions_builddir@/dict_dcca_3gpp.fdx + connect: + - identity: pgw.localdomain + addr: 127.0.0.3 diff --git a/configs/srslte.yaml.in b/configs/srslte.yaml.in new file mode 100644 index 000000000..e9b692374 --- /dev/null +++ b/configs/srslte.yaml.in @@ -0,0 +1,123 @@ +db_uri: mongodb://localhost/open5gs + +logger: + +parameter: + no_ipv6: true + +mme: + freeDiameter: + identity: mme.localdomain + realm: localdomain + listen_on: 127.0.0.2 + load_extension: + - module: @freediameter_extensions_builddir@/dbg_msg_dumps.fdx + conf: 0x8888 + - module: @freediameter_extensions_builddir@/dict_rfc5777.fdx + - module: @freediameter_extensions_builddir@/dict_mip6i.fdx + - module: @freediameter_extensions_builddir@/dict_nasreq.fdx + - module: @freediameter_extensions_builddir@/dict_nas_mipv6.fdx + - module: @freediameter_extensions_builddir@/dict_dcca.fdx + - module: @freediameter_extensions_builddir@/dict_dcca_3gpp.fdx + - module: @freediameter_extensions_builddir@/dict_s6a.fdx + connect: + - identity: hss.localdomain + addr: 127.0.0.4 + + s1ap: + addr: 127.0.1.100 + gtpc: + addr: 127.0.1.100 + gummei: + plmn_id: + mcc: 901 + mnc: 70 + mme_gid: 2 + mme_code: 1 + tai: + plmn_id: + mcc: 901 + mnc: 70 + tac: 7 + security: + integrity_order : [ EIA1, EIA2, EIA0 ] + ciphering_order : [ EEA0, EEA1, EEA2 ] + + network_name: + full: Open5GS + +hss: + freeDiameter: + identity: hss.localdomain + realm: localdomain + listen_on: 127.0.0.4 + load_extension: + - module: @freediameter_extensions_builddir@/dbg_msg_dumps.fdx + conf: 0x8888 + - module: @freediameter_extensions_builddir@/dict_rfc5777.fdx + - module: @freediameter_extensions_builddir@/dict_mip6i.fdx + - module: @freediameter_extensions_builddir@/dict_nasreq.fdx + - module: @freediameter_extensions_builddir@/dict_nas_mipv6.fdx + - module: @freediameter_extensions_builddir@/dict_dcca.fdx + - module: @freediameter_extensions_builddir@/dict_dcca_3gpp.fdx + - module: @freediameter_extensions_builddir@/dict_s6a.fdx + connect: + - identity: mme.localdomain + addr: 127.0.0.2 + +sgw: + gtpc: + addr: 127.0.0.2 + gtpu: + addr: 127.0.0.2 + +pgw: + freeDiameter: + identity: pgw.localdomain + realm: localdomain + listen_on: 127.0.0.3 + load_extension: + - module: @freediameter_extensions_builddir@/dbg_msg_dumps.fdx + conf: 0x8888 + - module: @freediameter_extensions_builddir@/dict_rfc5777.fdx + - module: @freediameter_extensions_builddir@/dict_mip6i.fdx + - module: @freediameter_extensions_builddir@/dict_nasreq.fdx + - module: @freediameter_extensions_builddir@/dict_nas_mipv6.fdx + - module: @freediameter_extensions_builddir@/dict_dcca.fdx + - module: @freediameter_extensions_builddir@/dict_dcca_3gpp.fdx + connect: + - identity: pcrf.localdomain + addr: 127.0.0.5 + + gtpc: + addr: + - 127.0.0.3 + - ::1 + gtpu: + - addr: 127.0.0.3 + - addr: ::1 + ue_pool: + - addr: 45.45.0.1/16 + - addr: cafe::1/64 + dns: + - 8.8.8.8 + - 8.8.4.4 + - 2001:4860:4860::8888 + - 2001:4860:4860::8844 +pcrf: + freeDiameter: + identity: pcrf.localdomain + realm: localdomain + listen_on: 127.0.0.5 + load_extension: + - module: @freediameter_extensions_builddir@/dbg_msg_dumps.fdx + conf: 0x8888 + - module: @freediameter_extensions_builddir@/dict_rfc5777.fdx + - module: @freediameter_extensions_builddir@/dict_mip6i.fdx + - module: @freediameter_extensions_builddir@/dict_nasreq.fdx + - module: @freediameter_extensions_builddir@/dict_nas_mipv6.fdx + - module: @freediameter_extensions_builddir@/dict_dcca.fdx + - module: @freediameter_extensions_builddir@/dict_dcca_3gpp.fdx + connect: + - identity: pgw.localdomain + addr: 127.0.0.3 diff --git a/support/network/99-nextepc.netdev b/configs/systemd/99-open5gs.netdev similarity index 60% rename from support/network/99-nextepc.netdev rename to configs/systemd/99-open5gs.netdev index 0ccbc171b..0bf4405c8 100644 --- a/support/network/99-nextepc.netdev +++ b/configs/systemd/99-open5gs.netdev @@ -1,3 +1,3 @@ [NetDev] -Name=pgwtun +Name=ogstun Kind=tun diff --git a/support/network/99-nextepc.network b/configs/systemd/99-open5gs.network similarity index 83% rename from support/network/99-nextepc.network rename to configs/systemd/99-open5gs.network index 90cf2f55f..992ba590f 100644 --- a/support/network/99-nextepc.network +++ b/configs/systemd/99-open5gs.network @@ -1,5 +1,5 @@ [Match] -Name=pgwtun +Name=ogstun [Network] Address=45.45.0.1/16 diff --git a/configs/systemd/meson.build b/configs/systemd/meson.build new file mode 100644 index 000000000..2cba508f1 --- /dev/null +++ b/configs/systemd/meson.build @@ -0,0 +1,43 @@ +# Copyright (C) 2019 by Sukchan Lee + +# This file is part of Open5GS. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +systemd_conf_in = ''' + open5gs-hssd.service + open5gs-pgwd.service + open5gs-mmed.service + open5gs-sgwd.service + open5gs-pcrfd.service +'''.split() + +foreach file : systemd_conf_in + configure_file( + input : file + '.in', + output : file, + configuration : conf_data) +endforeach + +systemd_conf = ''' + 99-open5gs.netdev + 99-open5gs.network +'''.split() + +foreach file : systemd_conf + configure_file( + input : file, + output : file, + configuration : conf_data) +endforeach diff --git a/support/systemd/nextepc-hssd.service.in b/configs/systemd/open5gs-hssd.service.in similarity index 60% rename from support/systemd/nextepc-hssd.service.in rename to configs/systemd/open5gs-hssd.service.in index ff07639fe..1241b6df8 100644 --- a/support/systemd/nextepc-hssd.service.in +++ b/configs/systemd/open5gs-hssd.service.in @@ -1,16 +1,16 @@ [Unit] -Description=NextEPC HSS Daemon +Description=Open5GS HSS Daemon BindTo=mongodb.service After=networking.service mongodb.service [Service] Type=simple -User=nextepc -Group=nextepc +User=open5gs +Group=open5gs Restart=always -ExecStart=@BIN_DIR@/nextepc-hssd -f @SYSCONF_DIR@/nextepc/hss.conf +ExecStart=@bindir@/open5gs-hssd -c @sysconfdir@/open5gs/hss.yaml RestartSec=2 RestartPreventExitStatus=1 diff --git a/support/systemd/nextepc-mmed.service.in b/configs/systemd/open5gs-mmed.service.in similarity index 54% rename from support/systemd/nextepc-mmed.service.in rename to configs/systemd/open5gs-mmed.service.in index c46a61faf..aeafd326b 100644 --- a/support/systemd/nextepc-mmed.service.in +++ b/configs/systemd/open5gs-mmed.service.in @@ -1,15 +1,15 @@ [Unit] -Description=NextEPC MME Daemon +Description=Open5GS MME Daemon After=networking.service [Service] Type=simple -User=nextepc -Group=nextepc +User=open5gs +Group=open5gs Restart=always -ExecStart=@BIN_DIR@/nextepc-mmed -f @SYSCONF_DIR@/nextepc/mme.conf +ExecStart=@bindir@/open5gs-mmed -c @sysconfdir@/open5gs/mme.yaml RestartSec=2 RestartPreventExitStatus=1 diff --git a/support/systemd/nextepc-pcrfd.service.in b/configs/systemd/open5gs-pcrfd.service.in similarity index 59% rename from support/systemd/nextepc-pcrfd.service.in rename to configs/systemd/open5gs-pcrfd.service.in index c1c372559..b57b84ca1 100644 --- a/support/systemd/nextepc-pcrfd.service.in +++ b/configs/systemd/open5gs-pcrfd.service.in @@ -1,16 +1,16 @@ [Unit] -Description=NextEPC PCRF Daemon +Description=Open5GS PCRF Daemon BindTo=mongodb.service After=networking.service mongodb.service [Service] Type=simple -User=nextepc -Group=nextepc +User=open5gs +Group=open5gs Restart=always -ExecStart=@BIN_DIR@/nextepc-pcrfd -f @SYSCONF_DIR@/nextepc/pcrf.conf +ExecStart=@bindir@/open5gs-pcrfd -c @sysconfdir@/open5gs/pcrf.yaml RestartSec=2 RestartPreventExitStatus=1 diff --git a/support/systemd/nextepc-sgwd.service.in b/configs/systemd/open5gs-pgwd.service.in similarity index 54% rename from support/systemd/nextepc-sgwd.service.in rename to configs/systemd/open5gs-pgwd.service.in index b688391af..854154bba 100644 --- a/support/systemd/nextepc-sgwd.service.in +++ b/configs/systemd/open5gs-pgwd.service.in @@ -1,15 +1,15 @@ [Unit] -Description=NextEPC S-GW Daemon +Description=Open5GS P-GW Daemon After=networking.service [Service] Type=simple -User=nextepc -Group=nextepc +User=open5gs +Group=open5gs Restart=always -ExecStart=@BIN_DIR@/nextepc-sgwd -f @SYSCONF_DIR@/nextepc/sgw.conf +ExecStart=@bindir@/open5gs-pgwd -c @sysconfdir@/open5gs/pgw.yaml RestartSec=2 RestartPreventExitStatus=1 diff --git a/support/systemd/nextepc-pgwd.service.in b/configs/systemd/open5gs-sgwd.service.in similarity index 54% rename from support/systemd/nextepc-pgwd.service.in rename to configs/systemd/open5gs-sgwd.service.in index 13fc3c4c1..beb9614b0 100644 --- a/support/systemd/nextepc-pgwd.service.in +++ b/configs/systemd/open5gs-sgwd.service.in @@ -1,15 +1,15 @@ [Unit] -Description=NextEPC P-GW Daemon +Description=Open5GS S-GW Daemon After=networking.service [Service] Type=simple -User=nextepc -Group=nextepc +User=open5gs +Group=open5gs Restart=always -ExecStart=@BIN_DIR@/nextepc-pgwd -f @SYSCONF_DIR@/nextepc/pgw.conf +ExecStart=@bindir@/open5gs-sgwd -c @sysconfdir@/open5gs/sgw.yaml RestartSec=2 RestartPreventExitStatus=1 diff --git a/configs/volte.yaml.in b/configs/volte.yaml.in new file mode 100644 index 000000000..5c17ec679 --- /dev/null +++ b/configs/volte.yaml.in @@ -0,0 +1,142 @@ +db_uri: mongodb://localhost/open5gs + +logger: + +parameter: + +mme: + freeDiameter: + identity: mme.open-ims.test + realm: open-ims.test +# port: 3868 +# sec_port: 5868 + listen_on: 127.0.0.2 + load_extension: + - module: @freediameter_extensions_builddir@/dbg_msg_dumps.fdx + conf: 0x8888 + - module: @freediameter_extensions_builddir@/dict_rfc5777.fdx + - module: @freediameter_extensions_builddir@/dict_mip6i.fdx + - module: @freediameter_extensions_builddir@/dict_nasreq.fdx + - module: @freediameter_extensions_builddir@/dict_nas_mipv6.fdx + - module: @freediameter_extensions_builddir@/dict_dcca.fdx + - module: @freediameter_extensions_builddir@/dict_dcca_3gpp.fdx + - module: @freediameter_extensions_builddir@/dict_s6a.fdx + connect: + - identity: hss.open-ims.test + addr: 127.0.0.4 +# port: 3868 + + s1ap: + addr: 127.0.0.1 + gtpc: + addr: 127.0.0.1 + gummei: + plmn_id: + mcc: 001 + mnc: 01 + mme_gid: 2 + mme_code: 1 + tai: + plmn_id: + mcc: 001 + mnc: 01 + tac: 12345 + security: + integrity_order : [ EIA1, EIA2, EIA0 ] + ciphering_order : [ EEA0, EEA1, EEA2 ] + +hss: + freeDiameter: + identity: hss.open-ims.test + realm: open-ims.test +# port: 3868 +# sec_port: 5868 + listen_on: 127.0.0.4 + load_extension: + - module: @freediameter_extensions_builddir@/dbg_msg_dumps.fdx + conf: 0x8888 + - module: @freediameter_extensions_builddir@/dict_rfc5777.fdx + - module: @freediameter_extensions_builddir@/dict_mip6i.fdx + - module: @freediameter_extensions_builddir@/dict_nasreq.fdx + - module: @freediameter_extensions_builddir@/dict_nas_mipv6.fdx + - module: @freediameter_extensions_builddir@/dict_dcca.fdx + - module: @freediameter_extensions_builddir@/dict_dcca_3gpp.fdx + - module: @freediameter_extensions_builddir@/dict_s6a.fdx + connect: + - identity: mme.open-ims.test + addr: 127.0.0.2 +# port: 3868 + +sgw: + gtpc: + addr: 127.0.0.2 + gtpu: + addr: 127.0.0.2 + +pgw: + freeDiameter: + identity: pgw.open-ims.test + realm: open-ims.test +# port: 3868 +# sec_port: 5868 + listen_on: 127.0.0.3 + load_extension: + - module: @freediameter_extensions_builddir@/dbg_msg_dumps.fdx + conf: 0x8888 + - module: @freediameter_extensions_builddir@/dict_rfc5777.fdx + - module: @freediameter_extensions_builddir@/dict_mip6i.fdx + - module: @freediameter_extensions_builddir@/dict_nasreq.fdx + - module: @freediameter_extensions_builddir@/dict_nas_mipv6.fdx + - module: @freediameter_extensions_builddir@/dict_dcca.fdx + - module: @freediameter_extensions_builddir@/dict_dcca_3gpp.fdx + connect: + - identity: pcrf.open-ims.test + addr: 127.0.0.5 +# port: 3868 + + gtpc: + addr: + - 127.0.0.3 + - ::1 + gtpu: + - addr: 127.0.0.3 + - addr: ::1 + ue_pool: + - addr: 45.45.0.1/16 + - addr: cafe::1/64 + dns: + - 8.8.8.8 + - 8.8.4.4 + - 2001:4860:4860::8888 + - 2001:4860:4860::8844 +# +# +# +# o Proxy Call Session Control Function +# +# p-cscf: +# - 127.0.0.1 +# - ::1 +# + +pcrf: + freeDiameter: + identity: pcrf.open-ims.test + realm: open-ims.test +# port: 3868 +# sec_port: 5868 + listen_on: 127.0.0.5 + load_extension: + - module: @freediameter_extensions_builddir@/dbg_msg_dumps.fdx + conf: 0x8888 + - module: @freediameter_extensions_builddir@/dict_rfc5777.fdx + - module: @freediameter_extensions_builddir@/dict_mip6i.fdx + - module: @freediameter_extensions_builddir@/dict_nasreq.fdx + - module: @freediameter_extensions_builddir@/dict_nas_mipv6.fdx + - module: @freediameter_extensions_builddir@/dict_dcca.fdx + - module: @freediameter_extensions_builddir@/dict_dcca_3gpp.fdx + connect: + - identity: pgw.open-ims.test + addr: 127.0.0.3 + - identity: pcscf.open-ims.test + addr: 127.0.0.1 diff --git a/configure.ac b/configure.ac deleted file mode 100644 index 670477fae..000000000 --- a/configure.ac +++ /dev/null @@ -1,235 +0,0 @@ -# -*- Autoconf -*- -# Process this file with autoconf to produce a configure script. - -# Copyright (C) 2019 by Sukchan Lee - -# This file is part of Open5GS. - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -AC_INIT([NextEPC], - m4_esyscmd([build/git-version-gen .tarball-version]), - [acetcom@gmail.com]) - -AC_CONFIG_AUX_DIR([build]) -AC_CONFIG_MACRO_DIR([m4]) -AC_CONFIG_TESTDIR(tests) -AC_CANONICAL_HOST - -AM_INIT_AUTOMAKE([1.10 -Wall -Werror foreign subdir-objects]) -m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) -AC_CONFIG_HEADERS([lib/nextepc-config.h]) -AC_CONFIG_SRCDIR([main.c]) - -LO_DEV="lo0" -case $host in - *linux*) - OSCPPFLAGS="-DLINUX=1" - IPFW_CPPFLAGS="-DNEED_SYSCTLBYNAME -DNEED_SIN_LEN" - LO_DEV="lo" - ;; - *-apple-darwin*) - OSCPPFLAGS="-DDARWIN -DSIGPROCMASK_SETS_THREAD_MASK" - ;; - *) - ;; -esac -AC_SUBST(OSCPPFLAGS) -AC_SUBST(IPFW_CPPFLAGS) -AC_SUBST(LO_DEV) - -AH_TOP([ -#ifndef __NEXTEPC_CONFIG_H__ -#define __NEXTEPC_CONFIG_H__ -/* need this, because some autoconf tests rely on this (e.g. stpcpy) - * and it should be used for new programs */ -#define _DEFAULT_SOURCE 1 -#define _BSD_SOURCE 1 -]) - -AH_BOTTOM([ -#endif /* __NEXTEPC_CONFIG_H__ */ -]) - -AH_VERBATIM([_REENTRANT], -[/* To allow the use of core in multithreaded programs we have to use - special features from the library. */ -#ifndef _REENTRANT -# define _REENTRANT 1 -#endif -]) - -dnl Checks CC and freinds -AC_PROG_MAKE_SET -AC_PROG_MKDIR_P -AC_PROG_CC -AM_PROG_CC_C_O -AC_PROG_INSTALL -AM_PROG_AR -LT_INIT - -AC_PATH_PROG(PKG_CONFIG, pkg-config, no) -if test "x$PKG_CONFIG" = "xno"; then - AC_MSG_ERROR([You need to install pkg-config]) -fi -PKG_PROG_PKG_CONFIG([0.20]) - -dnl Checks for compile flag -AX_CHECK_COMPILE_FLAG([-Wno-unused-result], [CFLAGS="$CFLAGS -Wno-unused-result"]) - -################################## -#### Checks for Directories. ##### -################################## - -AX_RECURSIVE_EVAL(["${bindir}"], [BIN_DIR]) -AX_RECURSIVE_EVAL(["${libdir}"], [LIB_DIR]) -AX_RECURSIVE_EVAL(["${sysconfdir}"], [SYSCONF_DIR]) -AX_RECURSIVE_EVAL(["${localstatedir}"], [LOCALSTATE_DIR]) -AC_SUBST(BIN_DIR) -AC_SUBST(LIB_DIR) -AC_SUBST(SYSCONF_DIR) -AC_SUBST(LOCALSTATE_DIR) - -####################################### -#### Checks for library functions. #### -####################################### - -AC_SEARCH_LIBS(gethostbyname, nsl) -AC_SEARCH_LIBS(gethostname, nsl) -AC_SEARCH_LIBS(socket, socket) -AC_SEARCH_LIBS(pthread_barrier_wait, pthread) -AC_SEARCH_LIBS(gnutls_global_set_log_level, gnutls) - -AC_CHECK_FILE([lib/ogslib/configure.ac], [have_srclib=yes], [have_srclib=no]) -if test x$have_srclib == xyes; then - AC_CONFIG_SUBDIRS([lib/ogslib]) - AC_SUBST(OGSCORE_CFLAGS, '-I$(top_srcdir)/lib/ogslib/src') - AC_SUBST(OGSCORE_LIBS, '$(top_srcdir)/lib/ogslib/src/core/libogscore-1.0.la') - AC_SUBST(OGSCRYPT_CFLAGS, '-I$(top_srcdir)/lib/ogslib/src') - AC_SUBST(OGSCRYPT_LIBS, '$(top_srcdir)/lib/ogslib/src/crypt/libogscrypt-1.0.la') -else - PKG_CHECK_MODULES(OGSCORE, ogscore-1.0 >= 1.3.0) - PKG_CHECK_MODULES(OGSCRYPT, ogscrypt-1.0 >= 1.3.0) -fi -AM_CONDITIONAL([WITH_SRCLIB], [test x$have_srclib = xyes]) - -AC_SEARCH_LIBS([sctp_sendmsg], [sctp], [have_sctp=yes], [have_sctp=no]) -if test x$have_sctp == xno; then - AC_SEARCH_LIBS([usrsctp_init], [usrsctp], [have_usrsctp=yes], [have_usrsctp=no]) - if test x$have_usrsctp == xno; then - AC_MSG_ERROR([You must install the SCTP libraries and development headers to enable SCTP support.]) - else - AC_DEFINE(HAVE_USRSCTP, 1, - [Define if your system supports the usrsctp system calls]) - fi -fi -AM_CONDITIONAL([WITH_USRSCTP], [test x$have_usrsctp = xyes]) - -AC_CHECK_HEADERS( \ - netinet/sctp.h \ -) - -AC_CHECK_HEADERS(netinet/ip.h netinet/ip6.h net/route.h,,,[[ -#include -#if HAVE_SYS_SOCKET_H -#include -#endif -#include -#if HAVE_NETINET_IN_SYSTM_H -#include -#endif -]]) - -AC_CHECK_HEADERS(netinet/ip_icmp.h netinet/icmp6.h,,,[[ -#include -#if HAVE_SYS_SOCKET_H -#include -#endif -#include -#if HAVE_NETINET_IN_SYSTM_H -#include -#endif -#include -]]) - -PKG_CHECK_MODULES([YAML], yaml-0.1 >= 0.1.4) -PKG_CHECK_MODULES([MONGOC], libmongoc-1.0 >= 1.3.1) - -##################### -#### Conclusion. #### -##################### - -AC_CONFIG_SUBDIRS([lib/freeDiameter]) - -AC_CONFIG_FILES([lib/asn1c/Makefile]) -AC_CONFIG_FILES([lib/s1ap/Makefile]) -AC_CONFIG_FILES([lib/nas/Makefile]) -AC_CONFIG_FILES([lib/diameter/Makefile]) -AC_CONFIG_FILES([lib/gtp/Makefile]) -AC_CONFIG_FILES([lib/dbi/Makefile]) -AC_CONFIG_FILES([lib/sctp/Makefile]) -AC_CONFIG_FILES([lib/app/Makefile]) -AC_CONFIG_FILES([lib/Makefile]) -AC_CONFIG_FILES([src/mme/Makefile]) -AC_CONFIG_FILES([src/hss/Makefile]) -AC_CONFIG_FILES([src/sgw/Makefile]) -AC_CONFIG_FILES([src/pgw/ipfw/Makefile]) -AC_CONFIG_FILES([src/pgw/Makefile]) -AC_CONFIG_FILES([src/pcrf/Makefile]) -AC_CONFIG_FILES([src/Makefile]) -AC_CONFIG_FILES([support/config/nextepc.conf]) -AC_CONFIG_FILES([support/config/mme.conf]) -AC_CONFIG_FILES([support/config/sgw.conf]) -AC_CONFIG_FILES([support/config/pgw.conf]) -AC_CONFIG_FILES([support/config/hss.conf]) -AC_CONFIG_FILES([support/config/pcrf.conf]) -AC_CONFIG_FILES([support/config/Makefile]) -AC_CONFIG_FILES([support/freeDiameter/mme.conf]) -AC_CONFIG_FILES([support/freeDiameter/pgw.conf]) -AC_CONFIG_FILES([support/freeDiameter/hss.conf]) -AC_CONFIG_FILES([support/freeDiameter/pcrf.conf]) -AC_CONFIG_FILES([support/freeDiameter/Makefile]) -AC_CONFIG_FILES([support/systemd/nextepc-mmed.service]) -AC_CONFIG_FILES([support/systemd/nextepc-sgwd.service]) -AC_CONFIG_FILES([support/systemd/nextepc-pgwd.service]) -AC_CONFIG_FILES([support/systemd/nextepc-hssd.service]) -AC_CONFIG_FILES([support/systemd/nextepc-pcrfd.service]) -AC_CONFIG_FILES([support/systemd/Makefile]) -AC_CONFIG_FILES([support/logrotate/nextepc]) -AC_CONFIG_FILES([support/logrotate/Makefile]) -AC_CONFIG_FILES([support/newsyslog/nextepc.conf]) -AC_CONFIG_FILES([support/newsyslog/Makefile]) -AC_CONFIG_FILES([support/Makefile]) -AC_CONFIG_FILES([tests/sample-simple.conf]) -AC_CONFIG_FILES([tests/sample-complex.conf]) -AC_CONFIG_FILES([tests/sample-volte.conf]) -AC_CONFIG_FILES([tests/sample-csfb.conf]) -AC_CONFIG_FILES([tests/Makefile]) -AC_CONFIG_FILES([Makefile]) -AC_OUTPUT - -AC_MSG_NOTICE([NextEPC configuration: - - version: ${PACKAGE_VERSION} - compiler: ${CC} - compiler flags: ${CFLAGS} ${OGSLIB_CFLAGS} ${MONGOC_CFLAGS} - linker flags: ${LDFLAGS} ${LIBS} ${OGSCORE_LIBS} ${OGSCRYPT_LIBS} ${MONGOC_LIBS} - path prefix: ${prefix} - binary file: ${BIN_DIR}/nextepc-epcd - library directory: ${LIB_DIR}/nextepc - configuration prefix: ${SYSCONF_DIR}/nextepc - configuration file: ${SYSCONF_DIR}/nextepc/nextepc.conf - pid file: ${LOCALSTATE_DIR}/run/nextepc.pid - logging file: ${LOCALSTATE_DIR}/log/nextepc.log -]) diff --git a/debian/changelog b/debian/changelog index 5a449ff77..b238c02c7 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,541 +1,563 @@ -nextepc (0.6.0) unstable; urgency=medium +open5gs (1.0.0) unstable; urgency=medium - * Re-factorting all the library + * Change build-tool to MESON + * Many BUGS Fixed - -- Sukchan Lee Fri, 13 Sep 2019 12:14:08 +0000 + -- Sukchan Lee Sun, 27 Oct 2019 06:34:23 +0000 -nextepc (0.5.2~disco) disco; urgency=medium +open5gs (1.0.0~eoan6) eoan; urgency=medium + + * Change build-tool to MESON + * Many BUGS Fixed + + -- Sukchan Lee Sun, 27 Oct 2019 06:33:10 +0000 + +open5gs (1.0.0~disco6) disco; urgency=medium + + * Change build-tool to MESON + * Many BUGS Fixed + + -- Sukchan Lee Sun, 27 Oct 2019 06:32:11 +0000 + +open5gs (1.0.0~bionic6) bionic; urgency=medium + + * Change build-tool to MESON + * Many BUGS Fixed + + -- Sukchan Lee Sun, 27 Oct 2019 14:39:52 +0900 + +open5gs (0.5.2~disco) disco; urgency=medium * Bug Fixed -- Sukchan Lee Sun, 11 Aug 2019 13:21:24 +0000 -nextepc (0.5.2~xenial) xenial; urgency=medium +open5gs (0.5.2~xenial) xenial; urgency=medium * Bug Fixed -- Sukchan Lee Sun, 11 Aug 2019 12:55:48 +0000 -nextepc (0.5.2~bionic) bionic; urgency=medium +open5gs (0.5.2~bionic) bionic; urgency=medium * Bug Fixed -- Sukchan Lee Sun, 11 Aug 2019 11:51:07 +0000 -nextepc (0.5.2) unstable; urgency=medium +open5gs (0.5.2) unstable; urgency=medium * Bug Fixed -- Sukchan Lee Sun, 11 Aug 2019 11:17:35 +0000 -nextepc (0.5.1~xenial) xenial; urgency=medium +open5gs (0.5.1~xenial) xenial; urgency=medium * SMSoSG Supported * Many BUGS Fixed -- Sukchan Lee Tue, 30 Jul 2019 22:42:27 +0900 -nextepc (0.5.1~bionic) bionic; urgency=medium +open5gs (0.5.1~bionic) bionic; urgency=medium * SMSoSG Supported * Many BUGS Fixed -- Sukchan Lee Tue, 30 Jul 2019 22:41:14 +0900 -nextepc (0.5.1) unstable; urgency=medium +open5gs (0.5.1) unstable; urgency=medium * SMSoSG Supported * Many BUGS Fixed -- Sukchan Lee Tue, 30 Jul 2019 21:34:15 +0900 -nextepc (0.5.0-1~bionic) bionic; urgency=medium +open5gs (0.5.0-1~bionic) bionic; urgency=medium * CSFB Supported * OGSLib package name changed -- Sukchan Lee Thu, 11 Jul 2019 15:34:08 +0000 -nextepc (0.5.0-1~xenial) xenial; urgency=medium +open5gs (0.5.0-1~xenial) xenial; urgency=medium * CSFB Supported * OGSLib package name changed -- Sukchan Lee Thu, 11 Jul 2019 15:09:05 +0000 -nextepc (0.5.0) unstable; urgency=medium +open5gs (0.5.0) unstable; urgency=medium * CSFB Supported * OGSLib package name changed -- Sukchan Lee Thu, 11 Jul 2019 22:26:35 +0900 -nextepc (0.4.4~bionic) bionic; urgency=medium +open5gs (0.4.4~bionic) bionic; urgency=medium * Bug Fixed -- Sukchan Lee Sun, 30 Jun 2019 13:23:15 +0000 -nextepc (0.4.4~xenial) xenial; urgency=medium +open5gs (0.4.4~xenial) xenial; urgency=medium * Bug Fixed -- Sukchan Lee Sun, 30 Jun 2019 13:21:59 +0000 -nextepc (0.4.4) unstable; urgency=medium +open5gs (0.4.4) unstable; urgency=medium * Bug Fixed -- Sukchan Lee Sun, 30 Jun 2019 12:05:12 +0000 -nextepc (0.4.3~xenial) xenial; urgency=medium +open5gs (0.4.3~xenial) xenial; urgency=medium * Bug Fixed -- Sukchan Lee Sat, 22 Jun 2019 06:57:10 +0000 -nextepc (0.4.3~bionic) bionic; urgency=medium +open5gs (0.4.3~bionic) bionic; urgency=medium * Bug Fixed -- Sukchan Lee Sat, 22 Jun 2019 06:55:56 +0000 -nextepc (0.4.3) unstable; urgency=medium +open5gs (0.4.3) unstable; urgency=medium * Bug Fixed -- Sukchan Lee Sat, 22 Jun 2019 03:30:10 +0000 -nextepc (0.4.2~xenial) xenial; urgency=medium +open5gs (0.4.2~xenial) xenial; urgency=medium * Bug Fixed -- Sukchan Lee Tue, 28 May 2019 20:11:51 +0900 -nextepc (0.4.2~bionic) bionic; urgency=medium +open5gs (0.4.2~bionic) bionic; urgency=medium * Bug Fixed -- Sukchan Lee Tue, 28 May 2019 20:09:02 +0900 -nextepc (0.4.2) unstable; urgency=medium +open5gs (0.4.2) unstable; urgency=medium * Bug Fixed -- Sukchan Lee Tue, 28 May 2019 20:04:53 +0900 -nextepc (0.4.1~bionic) bionic; urgency=medium +open5gs (0.4.1~bionic) bionic; urgency=medium * Bug Fixed -- Sukchan Lee Sat, 18 May 2019 09:59:17 +0000 -nextepc (0.4.1~xenial) xenial; urgency=medium +open5gs (0.4.1~xenial) xenial; urgency=medium * Bug Fixed -- Sukchan Lee Sat, 18 May 2019 09:57:44 +0000 -nextepc (0.4.1) unstable; urgency=medium +open5gs (0.4.1) unstable; urgency=medium * Bug Fixed -- Sukchan Lee Sat, 18 May 2019 08:18:59 +0000 -nextepc (0.4.0) unstable; urgency=medium +open5gs (0.4.0) unstable; urgency=medium * Integration with OGSLIB -- Sukchan Lee Mon, 29 Apr 2019 14:09:03 +0000 -nextepc (0.3.11~bionic) bionic; urgency=medium +open5gs (0.3.11~bionic) bionic; urgency=medium * Bug Fixed -- Sukchan Lee Sat, 27 Apr 2019 13:59:08 +0000 -nextepc (0.3.11~xenial) xenial; urgency=medium +open5gs (0.3.11~xenial) xenial; urgency=medium * Bug Fixed -- Sukchan Lee Sat, 27 Apr 2019 13:57:42 +0000 -nextepc (0.3.10~xenial) xenial; urgency=medium +open5gs (0.3.10~xenial) xenial; urgency=medium * Bug Fixed -- Sukchan Lee Fri, 17 Aug 2018 04:28:38 +0000 -nextepc (0.3.10~bionic) bionic; urgency=medium +open5gs (0.3.10~bionic) bionic; urgency=medium * Bug Fixed -- Sukchan Lee Fri, 17 Aug 2018 04:21:39 +0000 -nextepc (0.3.9~artful) artful; urgency=medium +open5gs (0.3.9~artful) artful; urgency=medium * Bug Fixed -- Sukchan Lee Sun, 03 Jun 2018 01:40:44 +0000 -nextepc (0.3.9~xenial) xenial; urgency=medium +open5gs (0.3.9~xenial) xenial; urgency=medium * Bug Fixed -- Sukchan Lee Sun, 03 Jun 2018 01:39:33 +0000 -nextepc (0.3.9~bionic) bionic; urgency=medium +open5gs (0.3.9~bionic) bionic; urgency=medium * Bug Fixed -- Sukchan Lee Sun, 03 Jun 2018 01:38:15 +0000 -nextepc (0.3.8-1~bionic) bionic; urgency=medium +open5gs (0.3.8-1~bionic) bionic; urgency=medium * Bug Fixed -- Sukchan Lee Sat, 05 May 2018 22:37:45 +0900 -nextepc (0.3.8~bionic) bionic; urgency=medium +open5gs (0.3.8~bionic) bionic; urgency=medium * Bug Fixed -- Sukchan Lee Sat, 05 May 2018 21:48:55 +0900 -nextepc (0.3.8~xenial) xenial; urgency=medium +open5gs (0.3.8~xenial) xenial; urgency=medium * Bug Fixed -- Sukchan Lee Sun, 29 Apr 2018 21:47:25 +0900 -nextepc (0.3.8~artful) artful; urgency=medium +open5gs (0.3.8~artful) artful; urgency=medium * Bug Fixed -- Sukchan Lee Sun, 29 Apr 2018 21:45:36 +0900 -nextepc (0.3.7~artful) artful; urgency=medium +open5gs (0.3.7~artful) artful; urgency=medium * Buf Fixed -- Sukchan Lee Sat, 14 Apr 2018 15:02:05 +0900 -nextepc (0.3.7~xenial) xenial; urgency=medium +open5gs (0.3.7~xenial) xenial; urgency=medium * Bug Fixed -- Sukchan Lee Sat, 14 Apr 2018 14:59:37 +0900 -nextepc (0.3.6~xenial) xenial; urgency=medium +open5gs (0.3.6~xenial) xenial; urgency=medium * Bug Fixed -- Sukchan Lee Wed, 21 Mar 2018 08:02:52 +0000 -nextepc (0.3.6~artful) artful; urgency=medium +open5gs (0.3.6~artful) artful; urgency=medium * Bug Fixed -- Sukchan Lee Wed, 21 Mar 2018 08:00:12 +0000 -nextepc (0.3.5~xenial) xenial; urgency=medium +open5gs (0.3.5~xenial) xenial; urgency=medium * Bug Fixed -- Sukchan Lee Tue, 06 Mar 2018 12:41:53 +0000 -nextepc (0.3.5~artful) artful; urgency=medium +open5gs (0.3.5~artful) artful; urgency=medium * Bug Fixed -- Sukchan Lee Tue, 06 Mar 2018 12:40:07 +0000 -nextepc (0.3.4-1~xenial) xenial; urgency=medium +open5gs (0.3.4-1~xenial) xenial; urgency=medium * Bug Fixed -- Sukchan Lee Thu, 22 Feb 2018 02:16:08 +0000 -nextepc (0.3.4-1~artful) artful; urgency=medium +open5gs (0.3.4-1~artful) artful; urgency=medium * Bug Fixed -- Sukchan Lee Thu, 22 Feb 2018 02:14:43 +0000 -nextepc (0.3.4~xenial) xenial; urgency=medium +open5gs (0.3.4~xenial) xenial; urgency=medium * Bug Fixed -- Sukchan Lee Thu, 22 Feb 2018 02:09:23 +0000 -nextepc (0.3.4~artful) artful; urgency=medium +open5gs (0.3.4~artful) artful; urgency=medium * Bug Fixed -- Sukchan Lee Thu, 22 Feb 2018 01:33:04 +0000 -nextepc (0.3.3-3~artful) artful; urgency=medium +open5gs (0.3.3-3~artful) artful; urgency=medium * Support Docker -- Sukchan Lee Tue, 13 Feb 2018 04:47:43 +0000 -nextepc (0.3.3-3~xenial) xenial; urgency=medium +open5gs (0.3.3-3~xenial) xenial; urgency=medium * Support Docker -- Sukchan Lee Tue, 13 Feb 2018 04:44:47 +0000 -nextepc (0.3.3-2~xenial) xenial; urgency=medium +open5gs (0.3.3-2~xenial) xenial; urgency=medium * Minor bug fixes -- Sukchan Lee Sun, 11 Feb 2018 16:08:14 +0000 -nextepc (0.3.3-2~artful) artful; urgency=medium +open5gs (0.3.3-2~artful) artful; urgency=medium * Minor bug fixes -- Sukchan Lee Sun, 11 Feb 2018 16:05:44 +0000 -nextepc (0.3.3-1~xenial) xenial; urgency=medium +open5gs (0.3.3-1~xenial) xenial; urgency=medium * Minor bug fixes -- Sukchan Lee Sun, 11 Feb 2018 15:39:37 +0000 -nextepc (0.3.3-1~artful) artful; urgency=medium +open5gs (0.3.3-1~artful) artful; urgency=medium * Minor bug fixes -- Sukchan Lee Sun, 11 Feb 2018 15:33:57 +0000 -nextepc (0.3.3~artful) artful; urgency=medium +open5gs (0.3.3~artful) artful; urgency=medium * Minor bug fixes -- Sukchan Lee Sun, 11 Feb 2018 15:05:08 +0000 -nextepc (0.3.3~xenial) xenial; urgency=medium +open5gs (0.3.3~xenial) xenial; urgency=medium * Minor bug fixes -- Sukchan Lee Sun, 11 Feb 2018 15:00:24 +0000 -nextepc (0.3.2~zesty) zesty; urgency=medium +open5gs (0.3.2~zesty) zesty; urgency=medium * VoLTE Support -- Sukchan Lee Wed, 24 Jan 2018 08:06:32 +0000 -nextepc (0.3.2~xenial) xenial; urgency=medium +open5gs (0.3.2~xenial) xenial; urgency=medium * VoLTE Support -- Sukchan Lee Wed, 24 Jan 2018 08:03:41 +0000 -nextepc (0.3.2~artful) artful; urgency=medium +open5gs (0.3.2~artful) artful; urgency=medium * VoLTE Support -- Sukchan Lee Wed, 24 Jan 2018 08:00:24 +0000 -nextepc (0.3.1-1~zesty) zesty; urgency=medium +open5gs (0.3.1-1~zesty) zesty; urgency=medium * IPv6 Support (Linux Only) * Change Configuration File (JSON -> YAML) -- Sukchan Lee Sun, 31 Dec 2017 22:10:52 +0000 -nextepc (0.3.1-1~xenial) xenial; urgency=medium +open5gs (0.3.1-1~xenial) xenial; urgency=medium * IPv6 Support (Linux Only) * Change Configuration File (JSON -> YAML) -- Sukchan Lee Sun, 31 Dec 2017 22:09:26 +0000 -nextepc (0.3.1-1~artful) artful; urgency=medium +open5gs (0.3.1-1~artful) artful; urgency=medium * IPv6 Support (Linux Only) * Change Configuration File (JSON -> YAML) -- Sukchan Lee Sun, 31 Dec 2017 22:04:50 +0000 -nextepc (0.3-3~zesty) zesty; urgency=medium +open5gs (0.3-3~zesty) zesty; urgency=medium * IPv6 Support (Linux Only) * Change Configuration File (JSON -> YAML) -- Sukchan Lee Mon, 18 Dec 2017 10:18:26 +0000 -nextepc (0.3-3~xenial) xenial; urgency=medium +open5gs (0.3-3~xenial) xenial; urgency=medium * IPv6 Support (Linux Only) * Change Configuration File (JSON -> YAML) -- Sukchan Lee Mon, 18 Dec 2017 10:16:51 +0000 -nextepc (0.3-3~artful) artful; urgency=medium +open5gs (0.3-3~artful) artful; urgency=medium * IPv6 Support (Linux Only) * Change Configuration File (JSON -> YAML) -- Sukchan Lee Mon, 18 Dec 2017 10:15:18 +0000 -nextepc (0.3-2~artful) artful; urgency=medium +open5gs (0.3-2~artful) artful; urgency=medium * Fix the bug reboot scenario -- Sukchan Lee Mon, 18 Dec 2017 07:06:52 +0000 -nextepc (0.3-1~artful) artful; urgency=medium +open5gs (0.3-1~artful) artful; urgency=medium * IPv6 Support (Linux Only) * Change Configuration File (JSON -> YAML) -- Sukchan Lee Mon, 18 Dec 2017 05:07:31 +0000 -nextepc (0.2-6~artful2) artful; urgency=medium +open5gs (0.2-6~artful2) artful; urgency=medium * postrm script is improved to purge package completely. -- Sukchan Lee Fri, 03 Nov 2017 02:30:53 +0000 -nextepc (0.2-6~zesty2) zesty; urgency=medium +open5gs (0.2-6~zesty2) zesty; urgency=medium * postrm script is improved to purge package completely. -- Sukchan Lee Fri, 03 Nov 2017 02:30:08 +0000 -nextepc (0.2-6~xenial2) xenial; urgency=medium +open5gs (0.2-6~xenial2) xenial; urgency=medium * postrm script is improved to purge package completely. -- Sukchan Lee Fri, 03 Nov 2017 02:28:41 +0000 -nextepc (0.2-6~zesty) zesty; urgency=medium +open5gs (0.2-6~zesty) zesty; urgency=medium * postrm script is improved to purge package completely. -- Sukchan Lee Fri, 03 Nov 2017 02:25:37 +0000 -nextepc (0.2-6~xenial) xenial; urgency=medium +open5gs (0.2-6~xenial) xenial; urgency=medium * postrm script is improved to purge package completely. -- Sukchan Lee Fri, 03 Nov 2017 02:23:54 +0000 -nextepc (0.2-6~artful) artful; urgency=medium +open5gs (0.2-6~artful) artful; urgency=medium * postrm script is improved to purge package completely. -- Sukchan Lee Fri, 03 Nov 2017 02:00:14 +0000 -nextepc (0.2-5~artful) artful; urgency=medium +open5gs (0.2-5~artful) artful; urgency=medium * Relase 0.2 -- Sukchan Lee Thu, 02 Nov 2017 07:13:23 +0000 -nextepc (0.2-5~zesty) zesty; urgency=medium +open5gs (0.2-5~zesty) zesty; urgency=medium * Relase 0.2 -- Sukchan Lee Thu, 02 Nov 2017 07:12:17 +0000 -nextepc (0.2-5~xenial) xenial; urgency=medium +open5gs (0.2-5~xenial) xenial; urgency=medium * Release 0.2 -- Sukchan Lee Thu, 02 Nov 2017 07:11:16 +0000 -nextepc (0.2-4~xenial2) xenial; urgency=medium +open5gs (0.2-4~xenial2) xenial; urgency=medium - * Fix the bug nextepc-pgwd post install script + * Fix the bug open5gs-pgwd post install script -- Sukchan Lee Tue, 31 Oct 2017 14:07:54 +0000 -nextepc (0.2-4~artful) artful; urgency=medium +open5gs (0.2-4~artful) artful; urgency=medium - * Fix the bug nextepc-pgwd post install script + * Fix the bug open5gs-pgwd post install script -- Sukchan Lee Tue, 31 Oct 2017 14:06:31 +0000 -nextepc (0.2-4~zesty) zesty; urgency=medium +open5gs (0.2-4~zesty) zesty; urgency=medium - * Fix the bug nextepc-pgwd post install script + * Fix the bug open5gs-pgwd post install script -- Sukchan Lee Tue, 31 Oct 2017 14:04:23 +0000 -nextepc (0.2-4~xenial) xenial; urgency=medium +open5gs (0.2-4~xenial) xenial; urgency=medium - * Fix the bug nextepc-pgwd post install script + * Fix the bug open5gs-pgwd post install script -- Sukchan Lee Tue, 31 Oct 2017 14:01:58 +0000 -nextepc (0.2-3~artful) artful; urgency=medium +open5gs (0.2-3~artful) artful; urgency=medium * MongoDB re-connect using systemd -- Sukchan Lee Tue, 31 Oct 2017 12:10:18 +0000 -nextepc (0.2-3~zesty) zesty; urgency=medium +open5gs (0.2-3~zesty) zesty; urgency=medium * MongoDB re-connect using systemd -- Sukchan Lee Tue, 31 Oct 2017 12:07:36 +0000 -nextepc (0.2-3~xenial) xenial; urgency=medium +open5gs (0.2-3~xenial) xenial; urgency=medium * MongoDB re-connect using systemd -- Sukchan Lee Tue, 31 Oct 2017 12:00:16 +0000 -nextepc (0.2-2~artful) artful; urgency=medium +open5gs (0.2-2~artful) artful; urgency=medium * Fix PGW installation -- Sukchan Lee Tue, 31 Oct 2017 05:02:03 +0000 -nextepc (0.2-2~xenial) xenial; urgency=medium +open5gs (0.2-2~xenial) xenial; urgency=medium * Fix PGW installation -- Sukchan Lee Tue, 31 Oct 2017 03:16:02 +0000 -nextepc (0.2-1~artful2) artful; urgency=medium +open5gs (0.2-1~artful2) artful; urgency=medium * Fix the compile error [-Werror=pointer] -- Sukchan Lee Mon, 30 Oct 2017 13:14:42 +0000 -nextepc (0.2-1~artful1) artful; urgency=medium +open5gs (0.2-1~artful1) artful; urgency=medium * Remove mongodb build-dependancy for Ubuntu 17.10(i386) -- Sukchan Lee Mon, 30 Oct 2017 12:46:58 +0000 -nextepc (0.2-1~artful) artful; urgency=medium +open5gs (0.2-1~artful) artful; urgency=medium * Ubuntu 17.10(amd64) * Currently, `mongodb` is not available in Ubuntu 17.10(i386) -- Sukchan Lee Mon, 30 Oct 2017 06:50:47 +0000 -nextepc (0.2-1~zesty) zesty; urgency=medium +open5gs (0.2-1~zesty) zesty; urgency=medium * Ubuntu 17.04 -- Sukchan Lee Mon, 30 Oct 2017 06:47:55 +0000 -nextepc (0.2-1~xenial) xenial; urgency=medium +open5gs (0.2-1~xenial) xenial; urgency=medium * Add matapackage * dh_overide_auto_test is re-enabled -- Sukchan Lee Mon, 30 Oct 2017 03:48:39 +0000 -nextepc (0.1.1) UNRELEASED; urgency=medium +open5gs (0.1.1) UNRELEASED; urgency=medium * Initial release. diff --git a/debian/compat b/debian/compat index ec635144f..b4de39476 100644 --- a/debian/compat +++ b/debian/compat @@ -1 +1 @@ -9 +11 diff --git a/debian/control b/debian/control index 1e4b0e2c7..8c89aafbe 100644 --- a/debian/control +++ b/debian/control @@ -1,18 +1,13 @@ -Source: nextepc -Maintainer: Harald Welte +Source: open5gs Section: net Priority: optional -Build-Depends: debhelper (>= 9), - autotools-dev, - dh-autoreconf, - dh-systemd, +Maintainer: Harald Welte +Uploaders: Sukchan Lee +Build-Depends: debhelper (>= 11), pkg-config, - autoconf, - automake, - libtool, + meson (>= 0.43.0), flex, bison, - libogslib-dev (>= 1.3.0), libgnutls28-dev, libgcrypt-dev, libssl-dev, @@ -21,31 +16,32 @@ Build-Depends: debhelper (>= 9), libbson-dev, libsctp-dev, libyaml-dev, -Standards-Version: 3.9.8 -Vcs-Browser: https://github.com/open5gs/nextepc -Vcs-Git: git://github.com/open5gs/nextepc -Homepage: https://open5gs.org/nextepc +Standards-Version: 4.3.0 +Rules-Requires-Root: no +Homepage: https://open5gs.org +Vcs-Browser: https://github.com/open5gs/open5gs +Vcs-Git: git://github.com/open5gs/open5gs -Package: nextepc-core +Package: open5gs-common Architecture: any Multi-Arch: same Depends: ${shlibs:Depends}, ${misc:Depends} Description: Open Source based 3GPP EPC (Shared Files) - NextEPC is a C-language Open Source implementation of the 3GPP Evolved + Open5GS is a C-language Open Source implementation of the 3GPP Evolved Packet Core, i.e. the core network of an LTE network. . This package contains some core libraries/plugins required by the other - binary packages such as nextepc-{mme,sgw,pgw,pcrf,hss}. + binary packages such as open5gs-{mme,sgw,pgw,pcrf,hss}. -Package: nextepc-mme +Package: open5gs-mme Architecture: any Multi-Arch: same Depends: ${shlibs:Depends}, ${misc:Depends}, - nextepc-core (= ${binary:Version}) + open5gs-common (= ${binary:Version}) Description: Open Source based 3GPP EPC MME (Mobility Management Entity) - NextEPC is a C-language Open Source implementation of the 3GPP Evolved + Open5GS is a C-language Open Source implementation of the 3GPP Evolved Packet Core, i.e. the core network of an LTE network. . This package provides the MME (Mobility Management Engine), which @@ -53,29 +49,29 @@ Description: Open Source based 3GPP EPC MME (Mobility Management Entity) network, and interfaces via S11 to the SGW as well as via S6a to the HSS. -Package: nextepc-sgw +Package: open5gs-sgw Architecture: any Multi-Arch: same Depends: ${shlibs:Depends}, ${misc:Depends}, - nextepc-core (= ${binary:Version}) + open5gs-common (= ${binary:Version}) Description: Open Source based 3GPP EPC SGW (Serving Gateway) - NextEPC is a C-language Open Source implementation of the 3GPP Evolved + Open5GS is a C-language Open Source implementation of the 3GPP Evolved Packet Core, i.e. the core network of an LTE network. . This package provides the SGW (Serving Gateway) which is situated between the MME and PGW. It implements the S11 interface to the MME, and the S5 interface to the PGW. -Package: nextepc-pgw +Package: open5gs-pgw Architecture: any Multi-Arch: same Depends: ${shlibs:Depends}, ${misc:Depends}, udev, - nextepc-core (= ${binary:Version}) + open5gs-common (= ${binary:Version}) Description: Open Source based 3GPP EPC PGW (Packet Data Network Gateway) - NextEPC is a C-language Open Source implementation of the 3GPP Evolved + Open5GS is a C-language Open Source implementation of the 3GPP Evolved Packet Core, i.e. the core network of an LTE network. . This package provides the PGW or PDN-GW (Packet Data Network Gateway) @@ -84,15 +80,15 @@ Description: Open Source based 3GPP EPC PGW (Packet Data Network Gateway) interface towards the S-GW, the SGi interface towards the Internet, and the S7 interface towards the PCRF. -Package: nextepc-pcrf +Package: open5gs-pcrf Architecture: any Multi-Arch: same Depends: ${shlibs:Depends}, ${misc:Depends}, mongodb, - nextepc-core (= ${binary:Version}) + open5gs-common (= ${binary:Version}) Description: Open Source based 3GPP EPC PCRF (Policy and Charging Rules Function) - NextEPC is a C-language Open Source implementation of the 3GPP Evolved + Open5GS is a C-language Open Source implementation of the 3GPP Evolved Packet Core, i.e. the core network of an LTE network. . This package contains the PCRF (Policy and Charging Rules Function), @@ -100,15 +96,15 @@ Description: Open Source based 3GPP EPC PCRF (Policy and Charging Rules Function how to account/charge related traffic. It implements the Gx interface towards the PGW using the DIAMETER protocol. -Package: nextepc-hss +Package: open5gs-hss Architecture: any Multi-Arch: same Depends: ${shlibs:Depends}, ${misc:Depends}, mongodb, - nextepc-core (= ${binary:Version}) + open5gs-common (= ${binary:Version}) Description: Open Source based 3GPP EPC HSS (Home Subscriber Server) - NextEPC is a C-language Open Source implementation of the 3GPP Evolved + Open5GS is a C-language Open Source implementation of the 3GPP Evolved Packet Core, i.e. the core network of an LTE network. . This package provides the HSS (Home Subscriber Server) element of the @@ -117,31 +113,31 @@ Description: Open Source based 3GPP EPC HSS (Home Subscriber Server) information, etc. It implements the S6a interface towards the MME using the DIAMETER protocol. -Package: nextepc +Package: open5gs Architecture: any Multi-Arch: same Depends: ${misc:Depends}, mongodb, - nextepc-core (= ${binary:Version}), - nextepc-mme (= ${binary:Version}), - nextepc-sgw (= ${binary:Version}), - nextepc-pgw (= ${binary:Version}), - nextepc-hss (= ${binary:Version}), - nextepc-pcrf (= ${binary:Version}) + open5gs-common (= ${binary:Version}), + open5gs-mme (= ${binary:Version}), + open5gs-sgw (= ${binary:Version}), + open5gs-pgw (= ${binary:Version}), + open5gs-hss (= ${binary:Version}), + open5gs-pcrf (= ${binary:Version}) Description: Open Source based 3GPP EPC (metapackage) - NextEPC is a C-language Open Source implementation of the 3GPP Evolved + Open5GS is a C-language Open Source implementation of the 3GPP Evolved Packet Core, i.e. the core network of an LTE network. . - This is a metapackage that depends on all the nextepc parts. + This is a metapackage that depends on all the open5gs parts. (MME, SGW, PGW, HSS, PCRF) -Package: nextepc-dbg +Package: open5gs-dbg Architecture: any Multi-Arch: same Depends: ${misc:Depends}, - nextepc (= ${binary:Version}) -Description: Debug symbols for NextEPC - NextEPC is a C-language Open Source implementation of the 3GPP Evolved + open5gs (= ${binary:Version}) +Description: Debug symbols for Open5GS + Open5GS is a C-language Open Source implementation of the 3GPP Evolved Packet Core, i.e. the core network of an LTE network. . - This package contains debug symbols for NextEPC. + This package contains debug symbols for Open5GS. diff --git a/debian/copyright b/debian/copyright index d7ca04b06..268c72adc 100644 --- a/debian/copyright +++ b/debian/copyright @@ -1,9 +1,9 @@ Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ -Upstream-Name: nextepc -Source: https://github.com/acetcom/nextepc +Upstream-Name: open5gs +Source: https://github.com/open5gs/open5gs Files: * -Copyright: 2017 NextEPC Group +Copyright: 2017 Open5GS Group License: AGPL-3 Files: lib/freeDiameter-1.2.1/* diff --git a/debian/nextepc-core.install b/debian/nextepc-core.install deleted file mode 100644 index 0731c0228..000000000 --- a/debian/nextepc-core.install +++ /dev/null @@ -1,5 +0,0 @@ -usr/lib/*/nextepc/* -var/log/nextepc -etc/nextepc/nextepc.conf -etc/nextepc/freeDiameter/cacert.pem -support/logrotate/nextepc /etc/logrotate.d diff --git a/debian/nextepc-hss.install b/debian/nextepc-hss.install deleted file mode 100644 index 59fcd8ab2..000000000 --- a/debian/nextepc-hss.install +++ /dev/null @@ -1,6 +0,0 @@ -usr/bin/nextepc-hssd -etc/nextepc/freeDiameter/hss.conf -etc/nextepc/freeDiameter/hss.cert.pem -etc/nextepc/freeDiameter/hss.key.pem -etc/nextepc/hss.conf -support/systemd/nextepc-hssd.service lib/systemd/system diff --git a/debian/nextepc-mme.install b/debian/nextepc-mme.install deleted file mode 100644 index 619d1a771..000000000 --- a/debian/nextepc-mme.install +++ /dev/null @@ -1,6 +0,0 @@ -usr/bin/nextepc-mmed -etc/nextepc/freeDiameter/mme.conf -etc/nextepc/freeDiameter/mme.cert.pem -etc/nextepc/freeDiameter/mme.key.pem -etc/nextepc/mme.conf -support/systemd/nextepc-mmed.service lib/systemd/system diff --git a/debian/nextepc-pcrf.install b/debian/nextepc-pcrf.install deleted file mode 100644 index d4479c82c..000000000 --- a/debian/nextepc-pcrf.install +++ /dev/null @@ -1,6 +0,0 @@ -usr/bin/nextepc-pcrfd -etc/nextepc/freeDiameter/pcrf.conf -etc/nextepc/freeDiameter/pcrf.cert.pem -etc/nextepc/freeDiameter/pcrf.key.pem -etc/nextepc/pcrf.conf -support/systemd/nextepc-pcrfd.service lib/systemd/system diff --git a/debian/nextepc-pgw.install b/debian/nextepc-pgw.install deleted file mode 100644 index 33c9ecb2c..000000000 --- a/debian/nextepc-pgw.install +++ /dev/null @@ -1,7 +0,0 @@ -usr/bin/nextepc-pgwd -etc/nextepc/freeDiameter/pgw.conf -etc/nextepc/freeDiameter/pgw.cert.pem -etc/nextepc/freeDiameter/pgw.key.pem -etc/nextepc/pgw.conf -support/network/99-nextepc.* etc/systemd/network -support/systemd/nextepc-pgwd.service lib/systemd/system diff --git a/debian/nextepc-sgw.install b/debian/nextepc-sgw.install deleted file mode 100644 index bbbc090f6..000000000 --- a/debian/nextepc-sgw.install +++ /dev/null @@ -1,3 +0,0 @@ -usr/bin/nextepc-sgwd -etc/nextepc/sgw.conf -support/systemd/nextepc-sgwd.service lib/systemd/system diff --git a/debian/open5gs-common.dirs b/debian/open5gs-common.dirs new file mode 100644 index 000000000..d5b197ccf --- /dev/null +++ b/debian/open5gs-common.dirs @@ -0,0 +1 @@ +var/log/open5gs diff --git a/debian/open5gs-common.install b/debian/open5gs-common.install new file mode 100644 index 000000000..31606586c --- /dev/null +++ b/debian/open5gs-common.install @@ -0,0 +1,5 @@ +usr/lib/*/libogs*.so* +usr/lib/*/libfd*.so* +usr/lib/*/freeDiameter/*.fdx +configs/freeDiameter/cacert.pem /etc/freeDiameter +configs/logrotate/open5gs /etc/logrotate.d diff --git a/debian/nextepc-core.postinst b/debian/open5gs-common.postinst similarity index 78% rename from debian/nextepc-core.postinst rename to debian/open5gs-common.postinst index be717c591..32e7c42d2 100644 --- a/debian/nextepc-core.postinst +++ b/debian/open5gs-common.postinst @@ -1,5 +1,5 @@ #!/bin/sh -# postinst script for nextepc +# postinst script for open5gs-common # # see: dh_installdeb(1) @@ -20,15 +20,15 @@ set -e case "$1" in configure) - # create a nextepc group and user - if ! getent passwd nextepc >/dev/null; then + # create a open5gs group and user + if ! getent passwd open5gs >/dev/null; then adduser --system --disabled-password --disabled-login \ - --home /var/run/nextepc --no-create-home \ - --quiet --group nextepc + --home /var/run/open5gs --no-create-home \ + --quiet --group open5gs fi - for dir in /var/log/nextepc; do + for dir in /var/log/open5gs; do if ! dpkg-statoverride --list "$dir" >/dev/null 2>&1; then - dpkg-statoverride --update --add nextepc nextepc 0755 "$dir" + dpkg-statoverride --update --add open5gs open5gs 0755 "$dir" fi done ;; diff --git a/debian/nextepc-core.postrm b/debian/open5gs-common.postrm similarity index 88% rename from debian/nextepc-core.postrm rename to debian/open5gs-common.postrm index c55098403..9e0a3e0b8 100644 --- a/debian/nextepc-core.postrm +++ b/debian/open5gs-common.postrm @@ -1,5 +1,5 @@ #!/bin/sh -# postrm script for nextepc-core +# postrm script for open5gs-common # # see: dh_installdeb(1) @@ -21,8 +21,8 @@ set -e case "$1" in purge) - rm -f /var/log/nextepc/*.log || true - rmdir /var/log/nextepc || true + rm -f /var/log/open5gs/*.log || true + rmdir /var/log/open5gs || true ;; remove|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear) diff --git a/debian/open5gs-hss.install b/debian/open5gs-hss.install new file mode 100644 index 000000000..100258889 --- /dev/null +++ b/debian/open5gs-hss.install @@ -0,0 +1,4 @@ +usr/bin/open5gs-hssd +configs/freeDiameter/hss.* etc/freeDiameter +configs/open5gs/hss.yaml etc/open5gs +configs/systemd/open5gs-hssd.service lib/systemd/system diff --git a/debian/open5gs-mme.install b/debian/open5gs-mme.install new file mode 100644 index 000000000..81839cf5f --- /dev/null +++ b/debian/open5gs-mme.install @@ -0,0 +1,4 @@ +usr/bin/open5gs-mmed +configs/freeDiameter/mme.* etc/freeDiameter +configs/open5gs/mme.yaml etc/open5gs +configs/systemd/open5gs-mmed.service lib/systemd/system diff --git a/debian/open5gs-pcrf.install b/debian/open5gs-pcrf.install new file mode 100644 index 000000000..b8aeac869 --- /dev/null +++ b/debian/open5gs-pcrf.install @@ -0,0 +1,4 @@ +usr/bin/open5gs-pcrfd +configs/freeDiameter/pcrf.* etc/freeDiameter +configs/open5gs/pcrf.yaml etc/open5gs +configs/systemd/open5gs-pcrfd.service lib/systemd/system diff --git a/debian/open5gs-pgw.install b/debian/open5gs-pgw.install new file mode 100644 index 000000000..817448545 --- /dev/null +++ b/debian/open5gs-pgw.install @@ -0,0 +1,5 @@ +usr/bin/open5gs-pgwd +configs/freeDiameter/pgw.* etc/freeDiameter +configs/open5gs/pgw.yaml etc/open5gs +configs/systemd/99-open5gs.net* etc/systemd/network +configs/systemd/open5gs-pgwd.service lib/systemd/system diff --git a/debian/nextepc-pgw.postinst b/debian/open5gs-pgw.postinst similarity index 78% rename from debian/nextepc-pgw.postinst rename to debian/open5gs-pgw.postinst index 12630c7c3..df626256e 100644 --- a/debian/nextepc-pgw.postinst +++ b/debian/open5gs-pgw.postinst @@ -1,5 +1,5 @@ #!/bin/sh -# postinst script for nextepc +# postinst script for open5gs-pgw # # see: dh_installdeb(1) @@ -21,16 +21,16 @@ set -e case "$1" in configure) if test "x`sysctl -n net.ipv6.conf.all.disable_ipv6`" = x1; then - echo "net.ipv6.conf.all.disable_ipv6=0" > /etc/sysctl.d/30-nextepc.conf - sysctl -p /etc/sysctl.d/30-nextepc.conf + echo "net.ipv6.conf.all.disable_ipv6=0" > /etc/sysctl.d/30-open5gs.conf + sysctl -p /etc/sysctl.d/30-open5gs.conf fi if test "x`systemctl is-enabled systemd-networkd`" = xdisabled; then systemctl enable systemd-networkd fi deb-systemd-invoke restart systemd-networkd - if test -f /etc/sysctl.d/30-nextepc.conf && grep "pgwtun" /proc/net/dev > /dev/null; then - echo "net.ipv6.conf.pgwtun.disable_ipv6=0" > /etc/sysctl.d/30-nextepc.conf - sysctl -p /etc/sysctl.d/30-nextepc.conf + if test -f /etc/sysctl.d/30-open5gs.conf && grep "ogstun" /proc/net/dev > /dev/null; then + echo "net.ipv6.conf.ogstun.disable_ipv6=0" > /etc/sysctl.d/30-open5gs.conf + sysctl -p /etc/sysctl.d/30-open5gs.conf fi ;; diff --git a/debian/nextepc-pgw.postrm b/debian/open5gs-pgw.postrm similarity index 84% rename from debian/nextepc-pgw.postrm rename to debian/open5gs-pgw.postrm index 94c3e805b..03d8616b6 100644 --- a/debian/nextepc-pgw.postrm +++ b/debian/open5gs-pgw.postrm @@ -1,5 +1,5 @@ #!/bin/sh -# postrm script for nextepc-core +# postrm script for open5gs-pgw # # see: dh_installdeb(1) @@ -21,10 +21,10 @@ set -e case "$1" in purge) - if grep "pgwtun" /proc/net/dev > /dev/null; then - ip tuntap del name pgwtun mode tun + if grep "ogstun" /proc/net/dev > /dev/null; then + ip tuntap del name ogstun mode tun fi - rm -f /etc/sysctl.d/30-nextepc.conf + rm -f /etc/sysctl.d/30-open5gs.conf ;; remove|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear) diff --git a/debian/open5gs-sgw.install b/debian/open5gs-sgw.install new file mode 100644 index 000000000..1c1c5e27e --- /dev/null +++ b/debian/open5gs-sgw.install @@ -0,0 +1,3 @@ +usr/bin/open5gs-sgwd +configs/open5gs/sgw.yaml etc/open5gs +configs/systemd/open5gs-sgwd.service lib/systemd/system diff --git a/debian/rules b/debian/rules index 03f250b10..5d68f3bc2 100755 --- a/debian/rules +++ b/debian/rules @@ -1,28 +1,17 @@ #!/usr/bin/make -f -# Uncomment this to turn on verbose mode. export DH_VERBOSE=1 - -DEBIAN := $(shell dpkg-parsechangelog | grep ^Version: | cut -d' ' -f2) -DEBVERS := $(shell echo '$(DEBIAN)' | cut -d- -f1) -VERSION := $(shell echo '$(DEBVERS)' | sed -e 's/[+-].*//' -e 's/~//g') - -# This has to be exported to make some magic below work. -#export DH_OPTIONS export DEB_BUILD_MAINT_OPTIONS = hardening=+all -%: - dh $@ --with autoreconf --with systemd +export LC_ALL = C.UTF-8 -override_dh_strip: - dh_strip --dbg-package=nextepc-dbg +include /usr/share/dpkg/default.mk + +%: + dh $@ --buildsystem=meson + +override_dh_install: + dh_install --sourcedir=obj-$(DEB_HOST_GNU_TYPE) override_dh_auto_test: - sctp_exclude_list=; \ - if ! cat /proc/net/protocols | grep SCTP > /dev/null; then \ - sctp_exclude_list="-x sctp-test"; \ - fi; \ - tests/testunit $$sctp_exclude_list || exit; \ - -#override_dh_makeshlibs: -# dh_makeshlibs -V + cd obj-$(DEB_HOST_GNU_TYPE) && meson test --suite unit diff --git a/docker/README.md b/docker/README.md index 6e5f31995..87195af22 100644 --- a/docker/README.md +++ b/docker/README.md @@ -15,8 +15,8 @@ Docker running example -f docker-compose.yml -f docker-compose.test.yml run test * Test(ubuntu:artful) - $ TAG=artful docker-compose build - $ TAG=artful docker-compose \ + $ TAG=eoan docker-compose build + $ TAG=eoan docker-compose \ -f docker-compose.yml -f docker-compose.test.yml run test * Development(fedora:latest) @@ -24,8 +24,8 @@ Docker running example $ DIST=fedora docker-compose run dev * Runtime(debian:jessie) - $ DIST=debian TAG=jessie docker-compose build - $ DIST=debian TAG=jessie docker-compose + $ DIST=debian TAG=stretch docker-compose build + $ DIST=debian TAG=stretch docker-compose -f docker-compose.yml -f docker-compose.run.yml run run * All Test with All Environment @@ -66,11 +66,19 @@ export DEBEMAIL='acetcom@gmail.com' $ gpg --export > public.asc $ gpg --import public.asc +* Upload OpenBuildService + $ dch -i + $ debuild -S -uc -us -d + $ osc co home:acetcom:open5gs latest + $ cd home\:acetcom\:open5gs/latest/ + $ cp ~/git/open5gs_1.0.0.* . + $ osc ci -m "Update it" + * Upload LaunchPad $ dch -i - $ debuild -S - $ dput ppa:acetcom/nextepc *.source.changes + $ debuild -S -d + $ dput ppa:open5gs/latest *.source.changes -* Build pckage - $ dpkg-buildpackage +* Build package + $ dpkg-buildpackage -d diff --git a/docker/build/Dockerfile b/docker/build/Dockerfile index 38dde8e16..1f93945ff 100644 --- a/docker/build/Dockerfile +++ b/docker/build/Dockerfile @@ -1,7 +1,7 @@ ARG dist=ubuntu ARG tag=latest ARG username=acetcom -FROM ${username}/${dist}-${tag}-nextepc-base +FROM ${username}/${dist}-${tag}-open5gs-base MAINTAINER Sukchan Lee @@ -10,15 +10,10 @@ COPY setup.sh /root ARG USER=open5gs ARG REPO=nextepc -ARG BRANCH=master -RUN git clone --recursive https://github.com/$USER/$REPO -ADD https://api.github.com/repos/$USER/$REPO/git/refs/heads/$BRANCH /root/nextepc-ver.json +ARG BRANCH=meson +RUN git clone https://github.com/$USER/$REPO +ADD https://api.github.com/repos/$USER/$REPO/git/refs/heads/$BRANCH /root/open5gs-ver.json -RUN cd nextepc && \ - git fetch && git checkout -f -B master origin/master && \ - autoreconf -f -i && \ - ./configure \ - --prefix=/usr \ - --sysconfdir=/etc \ - --localstatedir=/var && \ - make -j `nproc` install +RUN cd $REPO && \ + git fetch && git checkout -f -B $BRANCH origin/$BRANCH && \ + meson build && ninja -C build install diff --git a/docker/build/setup.sh b/docker/build/setup.sh index ca6732e03..75cdc1f10 100755 --- a/docker/build/setup.sh +++ b/docker/build/setup.sh @@ -1,10 +1,10 @@ #!/bin/sh -if ! grep "pgwtun" /proc/net/dev > /dev/null; then - ip tuntap add name pgwtun mode tun +if ! grep "ogstun" /proc/net/dev > /dev/null; then + ip tuntap add name ogstun mode tun fi -ip addr del 45.45.0.1/16 dev pgwtun 2> /dev/null -ip addr add 45.45.0.1/16 dev pgwtun -ip addr del cafe::1/64 dev pgwtun 2> /dev/null -ip addr add cafe::1/64 dev pgwtun -ip link set pgwtun up +ip addr del 45.45.0.1/16 dev ogstun 2> /dev/null +ip addr add 45.45.0.1/16 dev ogstun +ip addr del cafe::1/64 dev ogstun 2> /dev/null +ip addr add cafe::1/64 dev ogstun +ip link set ogstun up diff --git a/docker/centos/7/base/Dockerfile b/docker/centos/7/base/Dockerfile index a05b0cebf..1e979d8e9 100644 --- a/docker/centos/7/base/Dockerfile +++ b/docker/centos/7/base/Dockerfile @@ -4,9 +4,13 @@ FROM ${dist}:${tag} MAINTAINER Sukchan Lee +RUN yum -y install epel-release +RUN yum -y install https://centos7.iuscommunity.org/ius-release.rpm +RUN yum -y update + RUN yum -y install \ - autoconf \ - libtool \ + python3 \ + ninja-build \ gcc \ flex \ bison \ @@ -18,13 +22,7 @@ RUN yum -y install \ openssl-devel \ cyrus-sasl-devel \ libyaml-devel \ - iproute + iproute \ + mongo-c-driver-devel -RUN yum -y install epel-release && \ - yum -y install mongo-c-driver-devel - -RUN yum install -y https://centos7.iuscommunity.org/ius-release.rpm && \ - yum install -y python36u python36u-libs python36u-devel python36u-pip \ - yum install -y ninja-build - -RUN pip3.6 install meson +RUN pip3 install --upgrade pip && pip install meson diff --git a/docker/centos/7/dev b/docker/centos/7/dev new file mode 120000 index 000000000..4d9f1c963 --- /dev/null +++ b/docker/centos/7/dev @@ -0,0 +1 @@ +../8/dev \ No newline at end of file diff --git a/docker/centos/7/dev/setup.sh b/docker/centos/7/dev/setup.sh deleted file mode 100755 index ca6732e03..000000000 --- a/docker/centos/7/dev/setup.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/sh - -if ! grep "pgwtun" /proc/net/dev > /dev/null; then - ip tuntap add name pgwtun mode tun -fi -ip addr del 45.45.0.1/16 dev pgwtun 2> /dev/null -ip addr add 45.45.0.1/16 dev pgwtun -ip addr del cafe::1/64 dev pgwtun 2> /dev/null -ip addr add cafe::1/64 dev pgwtun -ip link set pgwtun up diff --git a/docker/centos/8/base/Dockerfile b/docker/centos/8/base/Dockerfile new file mode 100644 index 000000000..ae89b2649 --- /dev/null +++ b/docker/centos/8/base/Dockerfile @@ -0,0 +1,29 @@ +ARG dist=centos +ARG tag=latest +FROM ${dist}:${tag} + +MAINTAINER Sukchan Lee + +RUN dnf -y install epel-release && \ + dnf -y install 'dnf-command(config-manager)' && \ + dnf config-manager --set-enabled PowerTools && \ + dnf -y update + +RUN dnf -y install \ + python3 \ + ninja-build \ + gcc \ + flex \ + bison \ + git \ + lksctp-tools-devel \ + libidn-devel \ + gnutls-devel \ + libgcrypt-devel \ + openssl-devel \ + cyrus-sasl-devel \ + libyaml-devel \ + iproute \ + mongo-c-driver-devel + +RUN pip3 install --upgrade pip && pip install meson diff --git a/docker/centos/7/dev/Dockerfile b/docker/centos/8/dev/Dockerfile similarity index 90% rename from docker/centos/7/dev/Dockerfile rename to docker/centos/8/dev/Dockerfile index 3c00693cc..44b590668 100644 --- a/docker/centos/7/dev/Dockerfile +++ b/docker/centos/8/dev/Dockerfile @@ -1,7 +1,7 @@ ARG dist=centos ARG tag=latest ARG username=acetcom -FROM ${username}/${dist}-${tag}-nextepc-base +FROM ${username}/${dist}-${tag}-open5gs-base MAINTAINER Sukchan Lee diff --git a/docker/centos/8/dev/setup.sh b/docker/centos/8/dev/setup.sh new file mode 100755 index 000000000..75cdc1f10 --- /dev/null +++ b/docker/centos/8/dev/setup.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +if ! grep "ogstun" /proc/net/dev > /dev/null; then + ip tuntap add name ogstun mode tun +fi +ip addr del 45.45.0.1/16 dev ogstun 2> /dev/null +ip addr add 45.45.0.1/16 dev ogstun +ip addr del cafe::1/64 dev ogstun 2> /dev/null +ip addr add cafe::1/64 dev ogstun +ip link set ogstun up diff --git a/docker/centos/latest b/docker/centos/latest index c7930257d..301160a93 120000 --- a/docker/centos/latest +++ b/docker/centos/latest @@ -1 +1 @@ -7 \ No newline at end of file +8 \ No newline at end of file diff --git a/docker/check.sh b/docker/check.sh index 376ce7c9d..9b96e0960 100755 --- a/docker/check.sh +++ b/docker/check.sh @@ -3,16 +3,25 @@ docker-compose build docker-compose -f docker-compose.yml -f docker-compose.test.yml run --rm test -TAG=artful docker-compose build -TAG=artful docker-compose -f docker-compose.yml -f docker-compose.test.yml run --rm test +TAG=eoan docker-compose build +TAG=eoan docker-compose -f docker-compose.yml -f docker-compose.test.yml run --rm test DIST=fedora docker-compose build DIST=fedora docker-compose -f docker-compose.yml -f docker-compose.test.yml run --rm test +DIST=fedora TAG=29 docker-compose build +DIST=fedora TAG=29 docker-compose -f docker-compose.yml -f docker-compose.test.yml run --rm test + DIST=centos docker-compose build DIST=centos docker-compose -f docker-compose.yml -f docker-compose.test.yml run --rm test -DIST=debian TAG=jessie docker-compose build -DIST=debian TAG=jessie docker-compose -f docker-compose.yml -f docker-compose.test.yml run --rm test +DIST=centos TAG=7 docker-compose build +DIST=centos TAG=7 docker-compose -f docker-compose.yml -f docker-compose.test.yml run --rm test + +DIST=debian docker-compose build +DIST=debian docker-compose -f docker-compose.yml -f docker-compose.test.yml run --rm test + +DIST=debian TAG=stretch docker-compose build +DIST=debian TAG=stretch docker-compose -f docker-compose.yml -f docker-compose.test.yml run --rm test docker rm $(docker ps -qa --no-trunc --filter "status=exited") diff --git a/docker/debian/stretch/base/Dockerfile b/docker/debian/buster/base/Dockerfile similarity index 62% rename from docker/debian/stretch/base/Dockerfile rename to docker/debian/buster/base/Dockerfile index f460f8f6b..1b7d46910 100644 --- a/docker/debian/stretch/base/Dockerfile +++ b/docker/debian/buster/base/Dockerfile @@ -1,29 +1,16 @@ -ARG dist=debian -ARG tag=stable +ARG dist=ubuntu +ARG tag=latest FROM ${dist}:${tag} MAINTAINER Sukchan Lee -ARG tag=stable -#RUN apt-get update && \ -# apt-get install -y netselect-apt && \ -# apt-get clean && \ -# if [ "x$tag" = "xlatest" ]; then \ -# netselect-apt -o /etc/apt/sources.list; \ -# else \ -# netselect-apt ${tag} -o /etc/apt/sources.list; \ -# fi - RUN apt-get update && \ apt-get upgrade -y && \ apt-get install -y --no-install-recommends \ - autoconf \ - automake \ - libtool \ python3-pip \ python3-setuptools \ ninja-build \ - gcc \ + build-essential \ flex \ bison \ git \ @@ -35,10 +22,10 @@ RUN apt-get update && \ libmongoc-dev \ libbson-dev \ libyaml-dev \ - build-essential \ iproute2 \ ca-certificates \ netbase \ pkg-config && \ apt-get clean +RUN python3 -m pip install --upgrade pip RUN python3 -m pip install meson diff --git a/docker/debian/jessie/dev b/docker/debian/buster/dev similarity index 100% rename from docker/debian/jessie/dev rename to docker/debian/buster/dev diff --git a/docker/debian/buster/latest b/docker/debian/buster/latest new file mode 120000 index 000000000..b9bc2fdcb --- /dev/null +++ b/docker/debian/buster/latest @@ -0,0 +1 @@ +latest \ No newline at end of file diff --git a/docker/debian/buster/stable b/docker/debian/buster/stable new file mode 120000 index 000000000..870bbe4e5 --- /dev/null +++ b/docker/debian/buster/stable @@ -0,0 +1 @@ +stable \ No newline at end of file diff --git a/docker/debian/jessie/base/Dockerfile b/docker/debian/jessie/base/Dockerfile deleted file mode 100644 index df4e5778a..000000000 --- a/docker/debian/jessie/base/Dockerfile +++ /dev/null @@ -1,37 +0,0 @@ -ARG dist=debian -ARG tag=jessie -FROM ${dist}:${tag} - -MAINTAINER Sukchan Lee - -RUN apt-get update && \ - apt-get upgrade -y && \ - apt-get install -y --no-install-recommends \ - autoconf \ - automake \ - libtool \ - gcc \ - flex \ - bison \ - git \ - libsctp-dev \ - libgnutls28-dev \ - libgcrypt-dev \ - libssl-dev \ - libidn11-dev \ - libyaml-dev \ - build-essential \ - iproute2 \ - ca-certificates \ - netbase \ - curl \ - pkg-config && \ - apt-get clean - -WORKDIR /root -RUN curl -SLO "https://github.com/mongodb/mongo-c-driver/releases/download/1.9.2/mongo-c-driver-1.9.2.tar.gz"; \ - tar xzf mongo-c-driver-1.9.2.tar.gz; \ - cd mongo-c-driver-1.9.2; \ - ./configure --disable-automatic-init-and-cleanup; \ - make -j `nproc` install; \ - ldconfig; diff --git a/docker/debian/latest b/docker/debian/latest index 720221193..766a99ab6 120000 --- a/docker/debian/latest +++ b/docker/debian/latest @@ -1 +1 @@ -stretch \ No newline at end of file +buster \ No newline at end of file diff --git a/docker/debian/stable b/docker/debian/stable index 720221193..766a99ab6 120000 --- a/docker/debian/stable +++ b/docker/debian/stable @@ -1 +1 @@ -stretch \ No newline at end of file +buster \ No newline at end of file diff --git a/docker/debian/stretch b/docker/debian/stretch new file mode 120000 index 000000000..766a99ab6 --- /dev/null +++ b/docker/debian/stretch @@ -0,0 +1 @@ +buster \ No newline at end of file diff --git a/docker/debian/stretch/dev b/docker/debian/stretch/dev deleted file mode 120000 index 08e6badb1..000000000 --- a/docker/debian/stretch/dev +++ /dev/null @@ -1 +0,0 @@ -../../ubuntu/bionic/dev \ No newline at end of file diff --git a/docker/docker-compose.run.yml b/docker/docker-compose.run.yml index b8edeec28..54eb2a158 100644 --- a/docker/docker-compose.run.yml +++ b/docker/docker-compose.run.yml @@ -3,7 +3,7 @@ version: '3' services: run: network_mode: "host" - image: ${USER}/${DIST-ubuntu}-${TAG-latest}-nextepc-build + image: ${USER}/${DIST-ubuntu}-${TAG-latest}-open5gs-build depends_on: - mongodb - build @@ -14,9 +14,9 @@ services: sysctls: - net.ipv6.conf.all.disable_ipv6=0 volumes: - - config:/etc/nextepc - hostname: nextepc-run - command: /bin/bash -c "/root/setup.sh; /usr/bin/nextepc-epcd" + - config:/etc/open5gs + hostname: open5gs-run + command: /bin/bash -c "/root/setup.sh; /usr/bin/open5gs-pcrfd -D; /usr/bin/open5gs-pgwd -D; /usr/bin/open5gs-sgwd -D; /usr/bin/open5gs-hssd -D; /usr/bin/open5gs-mmed" volumes: config: {} diff --git a/docker/docker-compose.test.yml b/docker/docker-compose.test.yml index d5afffaf8..da15d51c1 100644 --- a/docker/docker-compose.test.yml +++ b/docker/docker-compose.test.yml @@ -2,17 +2,17 @@ version: '3' services: test: - image: ${USER}/${DIST-ubuntu}-${TAG-latest}-nextepc-build + image: ${USER}/${DIST-ubuntu}-${TAG-latest}-open5gs-build depends_on: - mongodb - build environment: - DB_URI: mongodb://mongodb/nextepc + DB_URI: mongodb://mongodb/open5gs cap_add: - NET_ADMIN devices: - "/dev/net/tun:/dev/net/tun" sysctls: - net.ipv6.conf.all.disable_ipv6=0 - hostname: nextepc-test - command: /bin/bash -c "/root/setup.sh; /usr/bin/testepc" + hostname: open5gs-test + command: /bin/bash -c "/root/setup.sh; cd nextepc && ninja -C build test" diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 36ca82251..33a3764d4 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -3,7 +3,7 @@ version: '3' services: mongodb: image: mongo - container_name: nextepc-mongodb + container_name: open5gs-mongodb ports: - "27017:27017" volumes: @@ -11,8 +11,8 @@ services: webui: build: webui - image: ${USER}/nextepc-webui - container_name: nextepc-webui + image: ${USER}/open5gs-webui + container_name: open5gs-webui depends_on: - mongodb ports: @@ -20,7 +20,7 @@ services: depends_on: - mongodb environment: - DB_URI: mongodb://mongodb/nextepc + DB_URI: mongodb://mongodb/open5gs base: build: @@ -28,7 +28,7 @@ services: args: dist: ${DIST-ubuntu} tag: ${TAG-latest} - image: ${USER}/${DIST-ubuntu}-${TAG-latest}-nextepc-base + image: ${USER}/${DIST-ubuntu}-${TAG-latest}-open5gs-base command: /bin/bash -c "echo 'base' services" build: @@ -38,7 +38,7 @@ services: dist: ${DIST-ubuntu} tag: ${TAG-latest} username: ${USER} - image: ${USER}/${DIST-ubuntu}-${TAG-latest}-nextepc-build + image: ${USER}/${DIST-ubuntu}-${TAG-latest}-open5gs-build depends_on: - base command: /bin/bash -c "echo 'build' services" @@ -50,12 +50,12 @@ services: dist: ${DIST-ubuntu} tag: ${TAG-latest} username: ${USER} - image: ${USER}/${DIST-ubuntu}-${TAG-latest}-nextepc-dev + image: ${USER}/${DIST-ubuntu}-${TAG-latest}-open5gs-dev depends_on: - mongodb - base environment: - - DB_URI=mongodb://mongodb/nextepc + - DB_URI=mongodb://mongodb/open5gs - DISPLAY=$DISPLAY # - DISPLAY=docker.for.mac.localhost:0 cap_add: @@ -70,7 +70,7 @@ services: - /tmp/.X11-unix:/tmp/.X11-unix # - /etc/localtime:/etc/localtime:ro # - /usr/share/zoneinfo/Europe/Helsinki:/etc/localtime:ro - hostname: nextepc-dev + hostname: open5gs-dev user: ${USER} entrypoint: /bin/bash -c "/bin/bash -c \"$${@}\"" command: | diff --git a/docker/fedora/29 b/docker/fedora/29 new file mode 120000 index 000000000..8580e7b68 --- /dev/null +++ b/docker/fedora/29 @@ -0,0 +1 @@ +30 \ No newline at end of file diff --git a/docker/fedora/29/dev/setup.sh b/docker/fedora/29/dev/setup.sh deleted file mode 100755 index ca6732e03..000000000 --- a/docker/fedora/29/dev/setup.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/sh - -if ! grep "pgwtun" /proc/net/dev > /dev/null; then - ip tuntap add name pgwtun mode tun -fi -ip addr del 45.45.0.1/16 dev pgwtun 2> /dev/null -ip addr add 45.45.0.1/16 dev pgwtun -ip addr del cafe::1/64 dev pgwtun 2> /dev/null -ip addr add cafe::1/64 dev pgwtun -ip link set pgwtun up diff --git a/docker/fedora/29/base/Dockerfile b/docker/fedora/30/base/Dockerfile similarity index 67% rename from docker/fedora/29/base/Dockerfile rename to docker/fedora/30/base/Dockerfile index 6c8a928bf..39cac3518 100644 --- a/docker/fedora/29/base/Dockerfile +++ b/docker/fedora/30/base/Dockerfile @@ -5,12 +5,9 @@ FROM ${dist}:${tag} MAINTAINER Sukchan Lee RUN dnf -y install \ - autoconf \ - libtool \ - gcc \ - make \ - python3-pip \ + python3 \ ninja-build \ + gcc \ flex \ bison \ git \ @@ -18,10 +15,10 @@ RUN dnf -y install \ libidn-devel \ gnutls-devel \ libgcrypt-devel \ - mongo-c-driver-devel \ openssl-devel \ cyrus-sasl-devel \ - snappy-devel \ libyaml-devel \ - iproute -RUN python3 -m pip install meson + iproute \ + mongo-c-driver-devel + +RUN pip3 install --upgrade pip && pip install meson diff --git a/docker/fedora/29/dev/Dockerfile b/docker/fedora/30/dev/Dockerfile similarity index 90% rename from docker/fedora/29/dev/Dockerfile rename to docker/fedora/30/dev/Dockerfile index 4d24030aa..a54b2b881 100644 --- a/docker/fedora/29/dev/Dockerfile +++ b/docker/fedora/30/dev/Dockerfile @@ -1,7 +1,7 @@ ARG dist=fedora ARG tag=latest ARG username=acetcom -FROM ${username}/${dist}-${tag}-nextepc-base +FROM ${username}/${dist}-${tag}-open5gs-base MAINTAINER Sukchan Lee diff --git a/docker/fedora/30/dev/setup.sh b/docker/fedora/30/dev/setup.sh new file mode 100755 index 000000000..75cdc1f10 --- /dev/null +++ b/docker/fedora/30/dev/setup.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +if ! grep "ogstun" /proc/net/dev > /dev/null; then + ip tuntap add name ogstun mode tun +fi +ip addr del 45.45.0.1/16 dev ogstun 2> /dev/null +ip addr add 45.45.0.1/16 dev ogstun +ip addr del cafe::1/64 dev ogstun 2> /dev/null +ip addr add cafe::1/64 dev ogstun +ip link set ogstun up diff --git a/docker/fedora/latest b/docker/fedora/latest index d99e90eb9..8580e7b68 120000 --- a/docker/fedora/latest +++ b/docker/fedora/latest @@ -1 +1 @@ -29 \ No newline at end of file +30 \ No newline at end of file diff --git a/docker/package/Dockerfile b/docker/package/Dockerfile index 6042eb9ce..4ddbedb82 100644 --- a/docker/package/Dockerfile +++ b/docker/package/Dockerfile @@ -3,8 +3,8 @@ FROM ubuntu:${tag} RUN apt-get update && \ apt-get -y install software-properties-common && \ - add-apt-repository ppa:acetcom/nextepc && \ + add-apt-repository ppa:acetcom/open5gs && \ apt-get update && \ - apt-get install -y nextepc + apt-get install -y open5gs WORKDIR /root diff --git a/docker/ubuntu/bionic/base/Dockerfile b/docker/ubuntu/bionic/base/Dockerfile index cb28c5e65..000255356 100644 --- a/docker/ubuntu/bionic/base/Dockerfile +++ b/docker/ubuntu/bionic/base/Dockerfile @@ -7,13 +7,10 @@ MAINTAINER Sukchan Lee RUN apt-get update && \ apt-get upgrade -y && \ apt-get install -y --no-install-recommends \ - autoconf \ - automake \ - libtool \ python3-pip \ python3-setuptools \ ninja-build \ - gcc \ + build-essential \ flex \ bison \ git \ @@ -25,7 +22,6 @@ RUN apt-get update && \ libmongoc-dev \ libbson-dev \ libyaml-dev \ - build-essential \ iproute2 \ ca-certificates \ netbase \ diff --git a/docker/ubuntu/bionic/dev/Dockerfile b/docker/ubuntu/bionic/dev/Dockerfile index 7fdc11a27..8beba0d3d 100644 --- a/docker/ubuntu/bionic/dev/Dockerfile +++ b/docker/ubuntu/bionic/dev/Dockerfile @@ -1,7 +1,7 @@ ARG dist=ubuntu ARG tag=latest ARG username=acetcom -FROM ${username}/${dist}-${tag}-nextepc-base +FROM ${username}/${dist}-${tag}-open5gs-base MAINTAINER Sukchan Lee @@ -14,8 +14,6 @@ RUN apt-get update && \ devscripts \ osc \ dput \ - dh-autoreconf \ - dh-systemd \ manpages-dev \ fakeroot \ cscope \ diff --git a/docker/ubuntu/bionic/dev/setup.sh b/docker/ubuntu/bionic/dev/setup.sh index ca6732e03..75cdc1f10 100755 --- a/docker/ubuntu/bionic/dev/setup.sh +++ b/docker/ubuntu/bionic/dev/setup.sh @@ -1,10 +1,10 @@ #!/bin/sh -if ! grep "pgwtun" /proc/net/dev > /dev/null; then - ip tuntap add name pgwtun mode tun +if ! grep "ogstun" /proc/net/dev > /dev/null; then + ip tuntap add name ogstun mode tun fi -ip addr del 45.45.0.1/16 dev pgwtun 2> /dev/null -ip addr add 45.45.0.1/16 dev pgwtun -ip addr del cafe::1/64 dev pgwtun 2> /dev/null -ip addr add cafe::1/64 dev pgwtun -ip link set pgwtun up +ip addr del 45.45.0.1/16 dev ogstun 2> /dev/null +ip addr add 45.45.0.1/16 dev ogstun +ip addr del cafe::1/64 dev ogstun 2> /dev/null +ip addr add cafe::1/64 dev ogstun +ip link set ogstun up diff --git a/docker/ubuntu/artful b/docker/ubuntu/eoan similarity index 100% rename from docker/ubuntu/artful rename to docker/ubuntu/eoan diff --git a/docker/ubuntu/trusty/base/Dockerfile b/docker/ubuntu/trusty/base/Dockerfile deleted file mode 100644 index b4e91626f..000000000 --- a/docker/ubuntu/trusty/base/Dockerfile +++ /dev/null @@ -1,37 +0,0 @@ -ARG dist=ubuntu -ARG tag=latest -FROM ${dist}:${tag} - -MAINTAINER Sukchan Lee - -RUN apt-get update && \ - apt-get upgrade -y && \ - apt-get install -y --no-install-recommends \ - autoconf \ - automake \ - libtool \ - gcc \ - flex \ - bison \ - git \ - libsctp-dev \ - libgnutls28-dev \ - libgcrypt-dev \ - libssl-dev \ - libidn11-dev \ - libyaml-dev \ - build-essential \ - iproute2 \ - ca-certificates \ - netbase \ - curl \ - pkg-config && \ - apt-get clean - -WORKDIR /root -RUN curl -SLO "https://github.com/mongodb/mongo-c-driver/releases/download/1.9.2/mongo-c-driver-1.9.2.tar.gz"; \ - tar xzf mongo-c-driver-1.9.2.tar.gz; \ - cd mongo-c-driver-1.9.2; \ - ./configure --disable-automatic-init-and-cleanup; \ - make -j `nproc` install; \ - ldconfig; diff --git a/docker/ubuntu/trusty/dev b/docker/ubuntu/trusty/dev deleted file mode 120000 index 981b884da..000000000 --- a/docker/ubuntu/trusty/dev +++ /dev/null @@ -1 +0,0 @@ -../xenial/dev \ No newline at end of file diff --git a/docker/webui/Dockerfile b/docker/webui/Dockerfile index 8414c0bbb..f4eeb1ce4 100644 --- a/docker/webui/Dockerfile +++ b/docker/webui/Dockerfile @@ -2,17 +2,17 @@ FROM node:carbon MAINTAINER Sukchan Lee -ARG PACKAGE=nextepc -ARG VERSION=0.3.3 +ARG PACKAGE=open5gs +ARG VERSION=1.0.0 RUN set -e; \ cd /usr/src; \ rm -rf ./$PACKAGE; \ - curl -SLO "https://github.com/acetcom/$PACKAGE/archive/v$VERSION.tar.gz"; \ + curl -SLO "https://github.com/open5gs/$PACKAGE/archive/v$VERSION.tar.gz"; \ tar -xvf v$VERSION.tar.gz; \ mv ./$PACKAGE-$VERSION/ ./$PACKAGE; -WORKDIR /usr/src/nextepc/webui +WORKDIR /usr/src/open5gs/webui RUN npm install && \ npm run build diff --git a/docs/_config.yml b/docs/_config.yml index aec141828..dedfc366f 100644 --- a/docs/_config.yml +++ b/docs/_config.yml @@ -13,12 +13,12 @@ # you will see them accessed via {{ site.title }}, {{ site.email }}, and so on. # You can create any custom variable you would like, and they will be accessible # in the templates via {{ site.myvariable }}. -title: NextEPC +title: Open5GS email: acetcom@gmail.com description: >- # this means to ignore newlines until "baseurl:" An open source implementation of the Evolved Packet Core of LTE networks - supporting 3GPP Release 13. -baseurl: "/nextepc" # the subpath of your site, e.g. /blog + supporting 3GPP Release 14. +baseurl: "/blog" # the subpath of your site, e.g. /blog url: "https://open5gs.org" # the base hostname & protocol for your site, e.g. http://example.com author: "Sukchan Lee" github_username: open5gs diff --git a/docs/_docs/guide/01-quickstart.md b/docs/_docs/guide/01-quickstart.md index bd4cb2dcf..9f086fe01 100644 --- a/docs/_docs/guide/01-quickstart.md +++ b/docs/_docs/guide/01-quickstart.md @@ -2,55 +2,53 @@ title: Quickstart --- -**Note:** NextEPC supports installation of packages in *Debian/Ubuntu and openSUSE* environments. *CentOS, Fedora, FreeBSD, and Mac OSX* require you to [build with source code]({{ site.url }}{{ site.baseurl }}/docs/guide/02-building-nextepc-from-sources) +**Note:** Open5GS supports installation of packages in *Debian/Ubuntu and openSUSE* environments. *CentOS, Fedora, FreeBSD, and Mac OSX* require you to [build with source code]({{ site.url }}{{ site.baseurl }}/docs/guide/02-building-open5gs-from-sources) {: .notice--warning} -### Install NextEPC with a Package Manager +### Install Open5GS with a Package Manager --- -The NextEPC package is available on the recent versions of *Ubuntu*. +The Open5GS package is available on the recent versions of *Ubuntu*. ```bash $ sudo apt update $ sudo apt install software-properties-common $ sudo add-apt-repository ppa:open5gs/latest $ sudo apt update -$ sudo apt install nextepc +$ sudo apt install open5gs ``` -The NextEPC package is also available on [OBS](https://build.opensuse.org/package/show/home:acetcom:open5gs:snapshot/nextepc). First, install the authentication key as shown below. +The Open5GS package is also available on [OBS](https://build.opensuse.org/package/show/home:acetcom:open5gs:snapshot/open5gs). First, install the authentication key as shown below. ```bash $ sudo apt update $ sudo apt install wget gnupg -$ wget https://download.opensuse.org/repositories/home:/acetcom:/open5gs:/latest/Debian_9.0/Release.key +$ wget https://download.opensuse.org/repositories/home:/acetcom:/open5gs:/latest/Debian_10.0/Release.key $ sudo apt-key add Release.key ``` -In Debian 9.0(stretch), you can install it as follows: +In Debian 10.0(buster), you can install it as follows: ```bash $ sudo sh -c "echo 'deb http://download.opensuse.org/repositories/home:/acetcom:/open5gs:/latest/Debian_9.0/ ./' > /etc/apt/sources.list.d/open5gs.list" $ sudo apt update -$ sudo apt install nextepc +$ sudo apt install open5gs ``` Other Linux distributions can be installed by changing the path. ``` -http://download.opensuse.org/repositories/home:/acetcom:/open5gs:/latest/Debian_9.0/ http://download.opensuse.org/repositories/home:/acetcom:/open5gs:/latest/Debian_10.0/ -http://download.opensuse.org/repositories/home:/acetcom:/open5gs:/latest/Raspbian_9.0/ +http://download.opensuse.org/repositories/home:/acetcom:/open5gs:/latest/Debian_Testing/ +http://download.opensuse.org/repositories/home:/acetcom:/open5gs:/latest/Debian_Unstable/ http://download.opensuse.org/repositories/home:/acetcom:/open5gs:/latest/Raspbian_10.0/ -http://download.opensuse.org/repositories/home:/acetcom:/open5gs:/latest/xUbuntu_16.04/ -http://download.opensuse.org/repositories/home:/acetcom:/open5gs:/latest/xUbuntu_17.10/ http://download.opensuse.org/repositories/home:/acetcom:/open5gs:/latest/xUbuntu_18.04/ -http://download.opensuse.org/repositories/home:/acetcom:/open5gs:/latest/xUbuntu_18.10/ http://download.opensuse.org/repositories/home:/acetcom:/open5gs:/latest/xUbuntu_19.04/ +http://download.opensuse.org/repositories/home:/acetcom:/open5gs:/latest/xUbuntu_19.10/ ``` -[Martin Hauke](https://build.opensuse.org/user/show/mnhauke) packaged NextEPC for *openSUSE* on [OBS](https://build.opensuse.org/package/show/home:mnhauke:nextepc/nextepc). +[Martin Hauke](https://build.opensuse.org/user/show/mnhauke) packaged Open5GS for *openSUSE* on [OBS](https://build.opensuse.org/package/show/home:mnhauke:nextepc/nextepc). ```bash $ sudo zypper addrepo -f obs://home:mnhauke:nextepc home:mnhauke:nextepc @@ -58,18 +56,18 @@ $ sudo zypper install nextepc $ sudo zypper install mongodb-server mongodb-shell ``` -### Configure NextEPC +### Configure Open5GS --- -Modify [/etc/nextepc/mme.conf](https://github.com/{{ site.github_username }}/nextepc/blob/master/support/config/mme.conf.in) to set the S1AP/GTP-C IP address, PLMN ID, and TAC +Modify [/etc/open5gs/mme.yaml](https://github.com/{{ site.github_username }}/open5gs/blob/master/configs/open5gs/mme.yaml.in) to set the S1AP/GTP-C IP address, PLMN ID, and TAC ```diff -diff -u /etc/nextepc/mme.conf.old /etc/nextepc/mme.conf ---- mme.conf.old 2018-04-15 18:28:31.000000000 +0900 -+++ mme.conf 2018-04-15 19:53:10.000000000 +0900 +diff -u /etc/open5gs/mme.yaml.old /etc/open5gs/mme.yaml +--- mme.yaml.old 2018-04-15 18:28:31.000000000 +0900 ++++ mme.yaml 2018-04-15 19:53:10.000000000 +0900 @@ -8,18 +8,20 @@ parameter: mme: - freeDiameter: mme.conf + freeDiameter: /etc/freeDiameter/mme.conf s1ap: + addr: 192.168.0.100 gtpc: @@ -95,11 +93,11 @@ diff -u /etc/nextepc/mme.conf.old /etc/nextepc/mme.conf ciphering_order : [ EEA0, EEA1, EEA2 ] ``` -Modify [/etc/nextepc/sgw.conf](https://github.com/{{ site.github_username }}/nextepc/blob/master/support/config/sgw.conf.in) to set the GTP-U IP address. +Modify [/etc/open5gs/sgw.yaml](https://github.com/{{ site.github_username }}/open5gs/blob/master/configs/open5gs/sgw.yaml.in) to set the GTP-U IP address. ```diff -diff -u /etc/nextepc/sgw.conf.old /etc/nextepc/sgw.conf ---- sgw.conf.old 2018-04-15 18:30:25.000000000 +0900 -+++ sgw.conf 2018-04-15 18:30:30.000000000 +0900 +diff -u /etc/open5gs/sgw.yaml.old /etc/open5gs/sgw.yaml +--- sgw.yaml.old 2018-04-15 18:30:25.000000000 +0900 ++++ sgw.yaml 2018-04-15 18:30:30.000000000 +0900 @@ -14,3 +14,4 @@ gtpc: addr: 127.0.0.2 @@ -107,17 +105,17 @@ diff -u /etc/nextepc/sgw.conf.old /etc/nextepc/sgw.conf + addr: 192.168.0.100 ``` -After changing conf files, please restart NextEPC daemons. +After changing conf files, please restart Open5GS daemons. ```bash -$ sudo systemctl restart nextepc-mmed -$ sudo systemctl restart nextepc-sgwd +$ sudo systemctl restart open5gs-mmed +$ sudo systemctl restart open5gs-sgwd ``` -### Install WebUI of NextEPC +### Install WebUI of Open5GS --- -[Node.js](https://nodejs.org/) is required to install WebUI of NextEPC +[Node.js](https://nodejs.org/) is required to install WebUI of Open5GS 1. *Debian and Ubuntu* based Linux distributions can install [Node.js](https://nodejs.org/) as follows: @@ -134,7 +132,7 @@ $ sudo systemctl restart nextepc-sgwd $ sudo zypper install nodejs8 ``` -You can now install WebUI of NextEPC. +You can now install WebUI of Open5GS. ```bash $ curl -sL {{ site.url }}{{ site.baseurl }}/assets/webui/install | sudo -E bash - @@ -158,14 +156,14 @@ To add subscriber information, you can do WebUI operations in the following orde 3. Fill the IMSI, security context(K, OPc, AMF), and APN of the subscriber. 4. Click `SAVE` Button -**Tip:** This addition immediately affects NextEPC without restaring any daemon. +**Tip:** This addition immediately affects Open5GS without restaring any daemon. {: .notice--info} ### Adding a route for UE to have Internet connectivity --- -If your phone can connect to internet, you must run the following command in NextEPC-PGW installed host. +If your phone can connect to internet, you must run the following command in Open5GS-PGW installed host. ```bash ### Check IP Tables @@ -197,7 +195,7 @@ target prot opt source destination $ sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward" ### Add NAT Rule -$ sudo iptables -t nat -A POSTROUTING -s 45.45.0.0/16 ! -o pgwtun -j MASQUERADE +$ sudo iptables -t nat -A POSTROUTING -s 45.45.0.0/16 ! -o ogstun -j MASQUERADE ``` **Note:** For the first time, it is a good condition if you do not have any rules in the IP/NAT tables. If a program such as docker has already set up a rule, you will need to add a rule differently. @@ -207,63 +205,63 @@ $ sudo iptables -t nat -A POSTROUTING -s 45.45.0.0/16 ! -o pgwtun -j MASQUERADE --- - Connect your eNodeB to the IP of your server via the standard S1AP port of SCTP 36412 (for MME) - You can see actual traffic through wireshark -- [[srsenb.pcapng]]({{ site.url }}{{ site.baseurl }}/assets/pcapng/srsenb.pcapng). -- You can view the log at `/var/log/nextepc/*.log`. +- You can view the log at `/var/log/open5gs/*.log`. ### Troubleshooting --- -Problem with NextEPC can be filed as [GitHub Issues](https://github.com/open5gs/nextepc/issues). Please include the following to get help: +Problem with Open5GS can be filed as [GitHub Issues](https://github.com/open5gs/open5gs/issues). Please include the following to get help: - Attach `*.pcapng` file created by wireskark. -- Attach configuration files at `/etc/nextepc/*.conf`. -- Attach log files at `/var/log/nextepc/*.log`. +- Attach configuration files at `/etc/open5gs/*.conf`. +- Attach log files at `/var/log/open5gs/*.log`. You can modify the configuration file to record more logs. ```diff -diff -u /etc/nextepc/mme.conf.old /etc/nextepc/mme.conf ---- mme.conf.old 2018-04-15 18:28:31.000000000 +0900 -+++ mme.conf 2018-04-15 19:53:10.000000000 +0900 +diff -u /etc/open5gs/mme.yaml.old /etc/open5gs/mme.yaml +--- mme.yaml.old 2018-04-15 18:28:31.000000000 +0900 ++++ mme.yaml 2018-04-15 19:53:10.000000000 +0900 @@ -2,6 +2,7 @@ logger: - file: @LOCALSTATE_DIR@/log/nextepc/mme.log + file: /var/log/open5gs/mme.log + level: debug parameter: ``` -After changing conf files, please restart NextEPC daemons. +After changing conf files, please restart Open5GS daemons. ```bash -$ sudo systemctl restart nextepc-mmed -$ sudo systemctl restart nextepc-sgwd +$ sudo systemctl restart open5gs-mmed +$ sudo systemctl restart open5gs-sgwd ``` -### Uninstall NextEPC and WebUI +### Uninstall Open5GS and WebUI -How to remove NextEPC package: +How to remove Open5GS package: 1. On *Ubuntu*: ```bash - $ sudo apt purge nextepc + $ sudo apt purge open5gs $ sudo apt autoremove ``` 2. On *openSUSE*: ```bash - $ sudo zypper rm nextepc + $ sudo zypper rm open5gs ``` -You may need to remove manually `/var/log/nextepc` unless it is empty. +You may need to remove manually `/var/log/open5gs` unless it is empty. ```bash -$ sudo rm -Rf /var/log/nextepc +$ sudo rm -Rf /var/log/open5gs ``` -The WebUI of NextEPC can be removed as follows: +The WebUI of Open5GS can be removed as follows: ```bash curl -sL {{ site.url }}{{ site.baseurl }}/assets/webui/uninstall | sudo -E bash - diff --git a/docs/_docs/guide/02-building-nextepc-from-sources.md b/docs/_docs/guide/02-building-nextepc-from-sources.md deleted file mode 100644 index 8df18d67a..000000000 --- a/docs/_docs/guide/02-building-nextepc-from-sources.md +++ /dev/null @@ -1,417 +0,0 @@ ---- -title: Building nextepc from Sources -head_inline: "" ---- - -This post explains how to compile and install the source code on **Debian/Ubuntu** based Linux Distribution. -{: .blue} - -### Getting MongoDB ---- - -Install MongoDB with package manager. - -```bash -$ sudo apt update -$ sudo apt install mongodb -$ sudo systemctl start mongodb (if '/usr/bin/mongod' is not running) -``` - -### Setting up TUN device (No persistent after rebooting) ---- - -Create the TUN device with the interface name `pgwtun`. - -```bash -$ sudo ip tuntap add name pgwtun mode tun -$ sudo ip addr add 45.45.0.1/16 dev pgwtun -$ sudo ip addr add cafe::1/64 dev pgwtun -$ sudo ip link set pgwtun up -``` - -The script provided in [$GIT_REPO/support/network/restart.sh](https://github.com/{{ site.github_username }}/nextepc/blob/master/support/network/restart.sh) makes it easy to configure the TUN device as follows: -`$ sudo ./support/network/restart.sh` -{: .notice--info} - -### Building NextEPC ---- - -Install the depedencies for building the source code. - -```bash -$ sudo apt install autoconf libtool gcc pkg-config git flex bison libsctp-dev libgnutls28-dev libgcrypt-dev libssl-dev libidn11-dev libmongoc-dev libbson-dev libyaml-dev -``` - -Git clone with `--recursive` option. - -```bash -➜ open5gs git clone --recursive https://github.com/{{ site.github_username }}/nextepc -``` - -To compile with autotools: - -```bash -➜ open5gs cd nextepc -➜ nextepc git:(master) ✗ autoreconf -iv -➜ nextepc git:(master) ✗ ./configure --prefix=`pwd`/install -➜ nextepc git:(master) ✗ make -j `nproc` -``` - -Check whether the compilation is correct. -```bash -➜ nextepc git:(master) ✗ make check -``` - -**Tip:** You can also check the result of `make check` with a tool that captures packets. If you are running `wireshark`, select the `loopback` interface and set FILTER to `s1ap || gtpv2 || diameter || gtp`. You can see the virtually created packets. [[testcomplex.pcapng]]({{ site.url }}{{ site.baseurl }}/assets/pcapng/testcomplex.pcapng) -{: .notice--info} - -You need to perform the **installation process**. -```bash -➜ nextepc git:(master) ✗ make install -``` - -### Configure NextEPC ---- - -**Note:** In the developer environment, all settings can be managed in one place, such as [$INSTALL_PREFIX/install/etc/nextepc/nextepc.conf](https://github.com/{{ site.github_username }}/nextepc/blob/master/support/config/nextepc.conf.in). -{: .notice--danger} - -Modify [$INSTALL_PREFIX/install/etc/nextepc/nextepc.conf](https://github.com/{{ site.github_username }}/nextepc/blob/master/support/config/nextepc.conf.in) to set the S1AP/GTP-C/GTP-U IP address, PLMN ID, and TAC - -```diff -diff -u ./install/etc/nextepc/nextepc.conf.old ./install/etc/nextepc/nextepc.conf ---- nextepc.conf.old 2018-04-15 18:28:31.000000000 +0900 -+++ nextepc.conf 2018-04-15 19:53:10.000000000 +0900 -@@ -74,6 +74,7 @@ mme: - # dev: eth0 - # - s1ap: -+ addr: 192.168.0.100 - - # - # > -@@ -87,6 +88,7 @@ mme: - # - addr: ::1 - # - gtpc: -+ addr: 192.168.0.100 - - # - # -@@ -110,8 +112,8 @@ mme: - # - gummei: - plmn_id: -- mcc: 001 -- mnc: 01 -+ mcc: 901 -+ mnc: 70 - mme_gid: 2 - mme_code: 1 - -@@ -149,9 +151,9 @@ mme: - # - tai: - plmn_id: -- mcc: 001 -- mnc: 01 -- tac: 12345 -+ mcc: 901 -+ mnc: 70 -+ tac: 7 - - security: - integrity_order : [ EIA1, EIA2, EIA0 ] -@@ -242,6 +244,7 @@ sgw: - # gtpu: - # - gtpu: -+ addr: 192.168.0.100 - - pgw: - freeDiameter: pgw.conf -``` - -### Running NextEPC ---- - -For developers, it provides `nextepc-epcd` daemon that includes both *MME*, *SGW*, *PGW*, *HSS*, and *PCRF*. - -```bash -➜ nextepc git:(master) ✗ ./nextepc-epcd -NextEPC daemon v0.5.2.12-0aae - -Configuration: '/Users/acetcom/Documents/git/nextepc/install/etc/nextepc/nextepc.conf' -File Logging: '/Users/acetcom/Documents/git/nextepc/install/var/log/nextepc/nextepc.log' -MongoDB URI: 'mongodb://localhost/nextepc' -08/25 20:40:18.194: [core] INFO: MME try to initialize (epc.c:100) -NextEPC daemon v0.5.2.12-0aae - -Configuration: '/Users/acetcom/Documents/git/nextepc/install/etc/nextepc/nextepc.conf' -File Logging: '/Users/acetcom/Documents/git/nextepc/install/var/log/nextepc/nextepc.log' -MongoDB URI: 'mongodb://localhost/nextepc' -08/25 20:40:18.439: [gtp] INFO: gtp_server() [192.168.0.3]:2123 (gtp-path.c:36) -08/25 20:40:18.439: [gtp] INFO: gtp_connect() [127.0.0.2]:2123 (gtp-path.c:61) -08/25 20:40:18.439: [mme] INFO: s1ap_server() [192.168.0.3]:36412 (s1ap-usrpath.c:47) -08/25 20:40:18.439: [core] INFO: MME initialize...done (epc.c:104) -NextEPC daemon v0.5.2.12-0aae - -Configuration: '/Users/acetcom/Documents/git/nextepc/install/etc/nextepc/nextepc.conf' -File Logging: '/Users/acetcom/Documents/git/nextepc/install/var/log/nextepc/nextepc.log' -MongoDB URI: 'mongodb://localhost/nextepc' -08/25 20:40:18.517: [pcrf] INFO: PCRF initialize...done (pcrf.c:24) -NextEPC daemon v0.5.2.12-0aae - -Configuration: '/Users/acetcom/Documents/git/nextepc/install/etc/nextepc/nextepc.conf' -File Logging: '/Users/acetcom/Documents/git/nextepc/install/var/log/nextepc/nextepc.log' -MongoDB URI: 'mongodb://localhost/nextepc' -08/25 20:40:18.606: [gtp] INFO: gtp_server() [127.0.0.2]:2123 (gtp-path.c:36) -08/25 20:40:18.606: [gtp] INFO: gtp_server() [192.168.0.3]:2152 (gtp-path.c:36) -08/25 20:40:18.613: [sgw] INFO: SGW initialize...done (sgw.c:24) -NextEPC daemon v0.5.2.12-0aae - -Configuration: '/Users/acetcom/Documents/git/nextepc/install/etc/nextepc/nextepc.conf' -File Logging: '/Users/acetcom/Documents/git/nextepc/install/var/log/nextepc/nextepc.log' -MongoDB URI: 'mongodb://localhost/nextepc' -08/25 20:40:18.706: [pgw] INFO: PGW initialize...done (pgw.c:24) -08/25 20:40:18.706: [gtp] INFO: gtp_server() [127.0.0.3]:2123 (gtp-path.c:36) -08/25 20:40:18.707: [fd] INFO: CONNECTED TO 'pgw.localdomain' (TCP,soc#15): (fd-logger.c:113) -08/25 20:40:18.707: [gtp] INFO: gtp_server() [127.0.0.3]:2152 (gtp-path.c:36) -08/25 20:40:18.707: [fd] INFO: CONNECTED TO 'pcrf.localdomain' (TCP,soc#19): (fd-logger.c:113) -08/25 20:40:18.742: [fd] INFO: CONNECTED TO 'hss.localdomain' (TCP,soc#24): (fd-logger.c:113) -08/25 20:40:18.743: [fd] INFO: CONNECTED TO 'mme.localdomain' (TCP,soc#21): (fd-logger.c:113) -08/25 20:40:18.744: [hss] INFO: HSS initialize...done (hss.c:24) -... -``` - -Several command line options are provided. - -```bash -➜ nextepc git:(master) ✗ ./nextepc-epcd -h -Usage: /Users/acetcom/Documents/git/nextepc/.libs/nextepc-epcd [options] -Options: - -c filename : set configuration file - -l filename : set logging file - -e level : set global log-level (default:info) - -m domain : set log-domain (e.g. mme:sgw:gtp) - -d : print lots of debugging information - -t : print tracing information for developer - -D : start as a daemon - -v : show version number and exit - -h : show this message and exit -``` - - -### Building WebUI of NextEPC ---- - -[Node.js](https://nodejs.org/) is required to build WebUI of NextEPC - -```bash -$ sudo apt install curl -$ curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash - -$ sudo apt install nodejs -``` - -Install the dependencies to run WebUI - -```bash -➜ nextepc git:(master) ✗ cd webui -➜ webui git:(master) ✗ npm install -``` - -The WebUI runs as an [npm](https://www.npmjs.com/) script. - -```bash -➜ webui git:(master) ✗ npm run dev -``` - -### Register Subscriber Information ---- - -Connect to `http://localhost:3000` and login with **admin** account. - -> Username : admin -> Password : 1423 - -**Note:** -You can change the password in _Account_ Menu. -{: .notice--info} - -To add subscriber information, you can do WebUI operations in the following order: - - 1. Go to `Subscriber` Menu. - 2. Click `+` Button to add a new subscriber. - 3. Fill the IMSI, security context(K, OPc, AMF), and APN of the subscriber. - 4. Click `SAVE` Button - -**Tip:** This addition immediately affects NextEPC without restaring any daemon. -{: .notice--warning} - -### Adding a route for UE to have internet connectivity ---- - -If your phone can connect to internet, you must run the following command in NextEPC-PGW installed host. - -```bash -### Check IP Tables -$ sudo iptables -L -Chain INPUT (policy ACCEPT) -target prot opt source destination - -Chain FORWARD (policy ACCEPT) -target prot opt source destination - -Chain OUTPUT (policy ACCEPT) -target prot opt source destination - -### Check NAT Tables -$ sudo iptables -L -t nat -Chain PREROUTING (policy ACCEPT) -target prot opt source destination - -Chain INPUT (policy ACCEPT) -target prot opt source destination - -Chain OUTPUT (policy ACCEPT) -target prot opt source destination - -Chain POSTROUTING (policy ACCEPT) -target prot opt source destination - -### Enable IPv4 Forwarding -$ sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward" - -### Add NAT Rule -$ sudo iptables -t nat -A POSTROUTING -s 45.45.0.0/16 ! -o pgwtun -j MASQUERADE -``` - -**Note:** It is a good condition if you do not have any rules in the IP/NAT tables. If a program such as docker has already set up a rule, you will need to add a rule differently. - -### Turn on your eNodeB and Phone ---- - -- You can see actual traffic through wireshark -- [[srsenb.pcapng]]({{ site.url }}{{ site.baseurl }}/assets/pcapng/srsenb.pcapng). -- You can view the log at `$INSTALL_PREFIX/var/log/nextepc/*.log`. - -### Troubleshooting ---- - -Debugging tools can help you troubleshoot problems. - -- [GDB](https://www.gnu.org/software/gdb/) can be used as below: - - ```bash - ➜ nextepc git:(master) ✗ sudo apt install gdb - ➜ nextepc git:(master) ✗ ./libtool --mode=execute gdb ./nextepc-epcd - ``` - -- On *Mac OS X*, you can use the [LLDB](https://lldb.llvm.org/). - - ```bash - ➜ nextepc git:(master) ✗ ./libtool --mode=execute sudo lldb ./nextepc-epcd - ``` - -You can use the command line option[`-d`] to record more logs. - -```bash -➜ nextepc git:(master) ✗ ./nextepc-epcd -d -NextEPC daemon v0.5.2.12-0aae - -Configuration: '/Users/acetcom/Documents/git/nextepc/install/etc/nextepc/nextepc.conf' -File Logging: '/Users/acetcom/Documents/git/nextepc/install/var/log/nextepc/nextepc.log' -LOG-LEVEL: 'debug' -MongoDB URI: 'mongodb://localhost/nextepc' -08/25 20:41:53.302: [thread] DEBUG: [0x1022da008] thread started (ogs-thread.c:101) -08/25 20:41:53.302: [thread] DEBUG: [0x1022da008] worker signal (ogs-thread.c:66) -08/25 20:41:53.353: [thread] DEBUG: [0x1022da108] thread started (ogs-thread.c:101) -08/25 20:41:53.353: [thread] DEBUG: [0x1022da108] worker signal (ogs-thread.c:66) -08/25 20:41:53.408: [thread] DEBUG: [0x1022da208] thread started (ogs-thread.c:101) -08/25 20:41:53.408: [thread] DEBUG: [0x1022da208] worker signal (ogs-thread.c:66) -08/25 20:41:53.460: [thread] DEBUG: [0x1022da308] worker signal (ogs-thread.c:66) -08/25 20:41:53.461: [thread] DEBUG: [0x1022da308] thread started (ogs-thread.c:101) -08/25 20:41:53.516: [core] INFO: MME try to initialize (epc.c:100) -08/25 20:41:53.723: [thread] DEBUG: [0x1022db108] worker signal (ogs-thread.c:66) -08/25 20:41:53.723: [thread] DEBUG: [0x1022db108] thread started (ogs-thread.c:101) -08/25 20:41:53.723: [core] INFO: MME initialize...done (epc.c:104) -08/25 20:41:53.723: [mme] DEBUG: mme_state_initial(): INIT - (mme-sm.c:43) -08/25 20:41:53.724: [mme] DEBUG: mme_state_operational(): ENTRY - (mme-sm.c:88) -08/25 20:41:53.724: [sock] DEBUG: socket create(2:2:17) (ogs-socket.c:82) -08/25 20:41:53.724: [sock] DEBUG: udp_socket() family:2 (ogs-udp.c:31) -08/25 20:41:53.724: [sock] DEBUG: socket bind 192.168.0.3:2123 (ogs-socket.c:107) -08/25 20:41:53.724: [sock] DEBUG: udp_server() [192.168.0.3]:2123 (ogs-udp.c:55) -08/25 20:41:53.724: [gtp] INFO: gtp_server() [192.168.0.3]:2123 (gtp-path.c:36) -08/25 20:41:53.724: [gtp] INFO: gtp_connect() [127.0.0.2]:2123 (gtp-path.c:61) -08/25 20:41:53.726: [core] DEBUG: Old INITMSG (numout:10 maxin:2048 maxattempt:8 maxinit_to:60000) (ogs-usrsctp.c:130) -08/25 20:41:53.726: [core] DEBUG: New INITMSG (numout:30 maxin:65535 maxattempt:4 maxinit_to:8000) (ogs-usrsctp.c:150) -08/25 20:41:53.726: [core] DEBUG: sctp_bind() [192.168.0.3]:36412 (ogs-usrsctp.c:259) -08/25 20:41:53.726: [mme] INFO: s1ap_server() [192.168.0.3]:36412 (s1ap-usrpath.c:47) -NextEPC daemon v0.5.2.12-0aae - -Configuration: '/Users/acetcom/Documents/git/nextepc/install/etc/nextepc/nextepc.conf' -File Logging: '/Users/acetcom/Documents/git/nextepc/install/var/log/nextepc/nextepc.log' -LOG-LEVEL: 'debug' -MongoDB URI: 'mongodb://localhost/nextepc' -NextEPC daemon v0.5.2.12-0aae - -Configuration: '/Users/acetcom/Documents/git/nextepc/install/etc/nextepc/nextepc.conf' -File Logging: '/Users/acetcom/Documents/git/nextepc/install/var/log/nextepc/nextepc.log' -LOG-LEVEL: 'debug' -MongoDB URI: 'mongodb://localhost/nextepc' -08/25 20:41:53.833: [thread] DEBUG: [0x105506608] worker signal (ogs-thread.c:66) -08/25 20:41:53.834: [thread] DEBUG: [0x105506608] thread started (ogs-thread.c:101) -08/25 20:41:53.834: [sgw] DEBUG: sgw_state_initial(): INIT - (sgw-sm.c:31) -08/25 20:41:53.834: [sgw] INFO: SGW initialize...done (sgw.c:24) -08/25 20:41:53.834: [sgw] DEBUG: sgw_state_operational(): ENTRY - (sgw-sm.c:55) -08/25 20:41:53.837: [sock] DEBUG: socket create(2:2:17) (ogs-socket.c:82) -08/25 20:41:53.837: [sock] DEBUG: udp_socket() family:2 (ogs-udp.c:31) -08/25 20:41:53.837: [sock] DEBUG: socket bind 127.0.0.2:2123 (ogs-socket.c:107) -08/25 20:41:53.837: [sock] DEBUG: udp_server() [127.0.0.2]:2123 (ogs-udp.c:55) -08/25 20:41:53.837: [gtp] INFO: gtp_server() [127.0.0.2]:2123 (gtp-path.c:36) -08/25 20:41:53.837: [sock] DEBUG: socket create(2:2:17) (ogs-socket.c:82) -08/25 20:41:53.837: [sock] DEBUG: udp_socket() family:2 (ogs-udp.c:31) -08/25 20:41:53.837: [sock] DEBUG: socket bind 192.168.0.3:2152 (ogs-socket.c:107) -08/25 20:41:53.837: [sock] DEBUG: udp_server() [192.168.0.3]:2152 (ogs-udp.c:55) -08/25 20:41:53.837: [gtp] INFO: gtp_server() [192.168.0.3]:2152 (gtp-path.c:36) -NextEPC daemon v0.5.2.12-0aae - -Configuration: '/Users/acetcom/Documents/git/nextepc/install/etc/nextepc/nextepc.conf' -File Logging: '/Users/acetcom/Documents/git/nextepc/install/var/log/nextepc/nextepc.log' -LOG-LEVEL: 'debug' -MongoDB URI: 'mongodb://localhost/nextepc' -NextEPC daemon v0.5.2.12-0aae - -Configuration: '/Users/acetcom/Documents/git/nextepc/install/etc/nextepc/nextepc.conf' -File Logging: '/Users/acetcom/Documents/git/nextepc/install/var/log/nextepc/nextepc.log' -LOG-LEVEL: 'debug' -MongoDB URI: 'mongodb://localhost/nextepc' -08/25 20:41:53.964: [pcrf] INFO: PCRF initialize...done (pcrf.c:24) -08/25 20:41:54.043: [thread] DEBUG: [0x100d7cb08] thread started (ogs-thread.c:101) -08/25 20:41:54.043: [thread] DEBUG: [0x100d7cb08] worker signal (ogs-thread.c:66) -08/25 20:41:54.044: [fd] INFO: CONNECTED TO 'pgw.localdomain' (TCP,soc#15): (fd-logger.c:113) -08/25 20:41:54.044: [pgw] DEBUG: pgw_state_initial(): INIT (pgw-sm.c:34) -08/25 20:41:54.044: [pgw] DEBUG: pgw_state_operational(): ENTRY (pgw-sm.c:63) -08/25 20:41:54.044: [sock] DEBUG: socket create(2:2:17) (ogs-socket.c:82) -08/25 20:41:54.044: [sock] DEBUG: udp_socket() family:2 (ogs-udp.c:31) -08/25 20:41:54.044: [sock] DEBUG: socket bind 127.0.0.3:2123 (ogs-socket.c:107) -08/25 20:41:54.044: [sock] DEBUG: udp_server() [127.0.0.3]:2123 (ogs-udp.c:55) -08/25 20:41:54.044: [gtp] INFO: gtp_server() [127.0.0.3]:2123 (gtp-path.c:36) -08/25 20:41:54.044: [sock] DEBUG: socket create(2:2:17) (ogs-socket.c:82) -08/25 20:41:54.044: [sock] DEBUG: udp_socket() family:2 (ogs-udp.c:31) -08/25 20:41:54.045: [sock] DEBUG: socket bind 127.0.0.3:2152 (ogs-socket.c:107) -08/25 20:41:54.045: [sock] DEBUG: udp_server() [127.0.0.3]:2152 (ogs-udp.c:55) -08/25 20:41:54.045: [fd] INFO: CONNECTED TO 'pcrf.localdomain' (TCP,soc#19): (fd-logger.c:113) -08/25 20:41:54.045: [gtp] INFO: gtp_server() [127.0.0.3]:2152 (gtp-path.c:36) -08/25 20:41:54.046: [pgw] INFO: PGW initialize...done (pgw.c:24) -08/25 20:41:54.273: [hss] INFO: HSS initialize...done (hss.c:24) -08/25 20:41:54.274: [fd] INFO: CONNECTED TO 'hss.localdomain' (TCP,soc#24): (fd-logger.c:113) -08/25 20:41:54.275: [fd] INFO: CONNECTED TO 'mme.localdomain' (TCP,soc#21): (fd-logger.c:113) -08/25 20:41:54.686: [pgw] DEBUG: [PGW] PROTO:17 SRC:2d2d0001 2d2d0001 d683d683 010fd314 (pgw-ipfw.c:284) -08/25 20:41:54.686: [pgw] DEBUG: [PGW] HLEN:20 DST:2d2d0001 d683d683 010fd314 0053756b (pgw-ipfw.c:287) -08/25 20:41:55.688: [pgw] DEBUG: [PGW] PROTO:17 SRC:2d2d0001 2d2d0001 d683d683 010f98b5 (pgw-ipfw.c:284) -08/25 20:41:55.689: [pgw] DEBUG: [PGW] HLEN:20 DST:2d2d0001 d683d683 010f98b5 0053756b (pgw-ipfw.c:287) -``` diff --git a/docs/_docs/guide/02-building-open5gs-from-sources.md b/docs/_docs/guide/02-building-open5gs-from-sources.md new file mode 100644 index 000000000..ffbcc38cb --- /dev/null +++ b/docs/_docs/guide/02-building-open5gs-from-sources.md @@ -0,0 +1,335 @@ +--- +title: Building Open5GS from Sources +head_inline: "" +--- + +This post explains how to compile and install the source code on **Debian/Ubuntu** based Linux Distribution. +{: .blue} + +### Getting MongoDB +--- + +Install MongoDB with package manager. + +```bash +$ sudo apt update +$ sudo apt install mongodb +$ sudo systemctl start mongodb (if '/usr/bin/mongod' is not running) +``` + +### Setting up TUN device (No persistent after rebooting) +--- + +Create the TUN device with the interface name `ogstun`. + +```bash +$ sudo ip tuntap add name ogstun mode tun +$ sudo ip addr add 45.45.0.1/16 dev ogstun +$ sudo ip addr add cafe::1/64 dev ogstun +$ sudo ip link set ogstun up +``` + +**Tip:** The script provided in [$GIT_REPO/misc/netconf.sh](https://github.com/{{ site.github_username }}/open5gs/blob/master/misc/netconf.sh) makes it easy to configure the TUN device as follows: +`$ sudo ./misc/netconf.sh` +{: .notice--info} + +### Building Open5GS +--- + +Install the depedencies for building the source code. + +```bash +$ sudo apt install python3-pip python3-setuptools ninja-build build-essential flex bison git libsctp-dev libgnutls28-dev libgcrypt-dev libssl-dev libidn11-dev libmongoc-dev libbson-dev libyaml-dev +``` + +Install Meson using Python. + +```bash +$ pip3 install --user meson +``` + +Git clone. + +```bash +$ git clone https://github.com/{{ site.github_username }}/open5gs +``` + +To compile with meson: + +```bash +$ cd open5gs +$ meson build --prefix=`pwd`/install +$ ninja -C build +``` + +Check whether the compilation is correct. +```bash +$ ninja -C build test +``` + +**Tip:** You can also check the result of `ninja -C build test` with a tool that captures packets. If you are running `wireshark`, select the `loopback` interface and set FILTER to `s1ap || gtpv2 || diameter || gtp`. You can see the virtually created packets. [[testcomplex.pcapng]]({{ site.url }}{{ site.baseurl }}/assets/pcapng/testcomplex.pcapng) +{: .notice--info} + +You need to perform the **installation process**. +```bash +$ cd build +$ ninja install +``` + +### Configure Open5GS +--- + +Modify [/etc/open5gs/mme.yaml](https://github.com/{{ site.github_username }}/open5gs/blob/master/configs/open5gs/mme.yaml.in) to set the S1AP/GTP-C IP address, PLMN ID, and TAC + +```diff +diff -u /etc/open5gs/mme.yaml.old /etc/open5gs/mme.yaml +--- mme.yaml.old 2018-04-15 18:28:31.000000000 +0900 ++++ mme.yaml 2018-04-15 19:53:10.000000000 +0900 +@@ -8,18 +8,20 @@ parameter: + mme: + freeDiameter: /etc/freeDiameter/mme.conf + s1ap: ++ addr: 192.168.0.100 + gtpc: ++ addr: 192.168.0.100 + gummei: + plmn_id: +- mcc: 001 +- mnc: 01 ++ mcc: 901 ++ mnc: 70 + mme_gid: 2 + mme_code: 1 + tai: + plmn_id: +- mcc: 001 +- mnc: 01 +- tac: 12345 ++ mcc: 901 ++ mnc: 70 ++ tac: 7 + security: + integrity_order : [ EIA1, EIA2, EIA0 ] + ciphering_order : [ EEA0, EEA1, EEA2 ] +``` + +Modify [/etc/open5gs/sgw.yaml](https://github.com/{{ site.github_username }}/open5gs/blob/master/configs/open5gs/sgw.yaml.in) to set the GTP-U IP address. +```diff +diff -u /etc/open5gs/sgw.yaml.old /etc/open5gs/sgw.yaml +--- sgw.yaml.old 2018-04-15 18:30:25.000000000 +0900 ++++ sgw.yaml 2018-04-15 18:30:30.000000000 +0900 +@@ -14,3 +14,4 @@ + gtpc: + addr: 127.0.0.2 + gtpu: ++ addr: 192.168.0.100 +``` + +After changing conf files, please restart Open5GS daemons. + + +### Running Open5GS +--- + +```bash +$ cd install +$ ./open5gs-pcrfd +Open5GS daemon v1.0.0 + +10/27 15:47:55.821: [app] INFO: Configuration: '/Users/acetcom/Documents/git/nextepc/install/etc/open5gs/pcrf.yaml' (../src/main.c:54) +10/27 15:47:55.822: [app] INFO: File Logging: '/Users/acetcom/Documents/git/nextepc/install/var/log/open5gs/pcrf.log' (../src/main.c:57) +10/27 15:47:55.868: [dbi] INFO: MongoDB URI: 'mongodb://localhost/open5gs' (../lib/dbi/ogs-mongoc.c:99) +10/27 15:47:55.965: [app] INFO: PCRF initialize...done (../src/pcrf/app-init.c:31) + +$ ./open5gs-pgwd +Open5GS daemon v1.0.0 + +10/27 15:48:11.198: [app] INFO: Configuration: '/Users/acetcom/Documents/git/nextepc/install/etc/open5gs/pgw.yaml' (../src/main.c:54) +10/27 15:48:11.199: [app] INFO: File Logging: '/Users/acetcom/Documents/git/nextepc/install/var/log/open5gs/pgw.log' (../src/main.c:57) +10/27 15:48:11.292: [app] INFO: PGW initialize...done (../src/pgw/app-init.c:31) +10/27 15:48:11.293: [gtp] INFO: gtp_server() [127.0.0.3]:2123 (../lib/gtp/path.c:32) +10/27 15:48:11.293: [gtp] INFO: gtp_server() [::1]:2123 (../lib/gtp/path.c:32) +10/27 15:48:11.293: [gtp] INFO: gtp_server() [127.0.0.3]:2152 (../lib/gtp/path.c:32) +10/27 15:48:11.293: [gtp] INFO: gtp_server() [::1]:2152 (../lib/gtp/path.c:32) + +$ ./open5gs-sgwd +Open5GS daemon v1.0.0 + +10/27 15:48:21.526: [app] INFO: Configuration: '/Users/acetcom/Documents/git/nextepc/install/etc/open5gs/sgw.yaml' (../src/main.c:54) +10/27 15:48:21.527: [app] INFO: File Logging: '/Users/acetcom/Documents/git/nextepc/install/var/log/open5gs/sgw.log' (../src/main.c:57) +10/27 15:48:21.533: [app] INFO: SGW initialize...done (../src/sgw/app-init.c:31) +10/27 15:48:21.537: [gtp] INFO: gtp_server() [127.0.0.2]:2123 (../lib/gtp/path.c:32) +10/27 15:48:21.537: [gtp] INFO: gtp_server() [192.168.0.3]:2152 (../lib/gtp/path.c:32) + +$ ./open5gs-hssd +Open5GS daemon v1.0.0 + +10/27 15:48:32.802: [app] INFO: Configuration: '/Users/acetcom/Documents/git/nextepc/install/etc/open5gs/hss.yaml' (../src/main.c:54) +10/27 15:48:32.803: [app] INFO: File Logging: '/Users/acetcom/Documents/git/nextepc/install/var/log/open5gs/hss.log' (../src/main.c:57) +10/27 15:48:32.815: [dbi] INFO: MongoDB URI: 'mongodb://localhost/open5gs' (../lib/dbi/ogs-mongoc.c:99) +10/27 15:48:32.861: [app] INFO: HSS initialize...done (../src/hss/app-init.c:31) + +$ ./open5gs-mmed +Open5GS daemon v1.0.0 + +10/27 15:46:23.539: [app] INFO: Configuration: '/Users/acetcom/Documents/git/nextepc/install/etc/open5gs/mme.yaml' (../src/main.c:54) +10/27 15:46:23.540: [app] INFO: File Logging: '/Users/acetcom/Documents/git/nextepc/install/var/log/open5gs/mme.log' (../src/main.c:57) +10/27 15:46:23.682: [app] INFO: MME initialize...done (../src/mme/app-init.c:33) +10/27 15:46:23.682: [gtp] INFO: gtp_server() [192.168.0.3]:2123 (../lib/gtp/path.c:32) +10/27 15:46:23.683: [gtp] INFO: gtp_connect() [127.0.0.2]:2123 (../lib/gtp/path.c:57) +10/27 15:46:23.683: [mme] INFO: s1ap_server() [192.168.0.3]:36412 (../src/mme/s1ap-usrpath.c:46) +``` + +Several command line options are provided. + +```bash +$ ./open5gs-mmed -h +Usage: ./open5gs-mmed [options] +Options: + -c filename : set configuration file + -l filename : set logging file + -e level : set global log-level (default:info) + -m domain : set log-domain (e.g. mme:sgw:gtp) + -d : print lots of debugging information + -t : print tracing information for developer + -D : start as a daemon + -v : show version number and exit + -h : show this message and exit +``` + + +### Building WebUI of Open5GS +--- + +[Node.js](https://nodejs.org/) is required to build WebUI of Open5GS + +```bash +$ sudo apt install curl +$ curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash - +$ sudo apt install nodejs +``` + +Install the dependencies to run WebUI + +```bash +$ cd webui +$ npm install +``` + +The WebUI runs as an [npm](https://www.npmjs.com/) script. + +```bash +$ npm run dev +``` + +### Register Subscriber Information +--- + +Connect to `http://localhost:3000` and login with **admin** account. + +> Username : admin +> Password : 1423 + +**Note:** +You can change the password in _Account_ Menu. +{: .notice--info} + +To add subscriber information, you can do WebUI operations in the following order: + + 1. Go to `Subscriber` Menu. + 2. Click `+` Button to add a new subscriber. + 3. Fill the IMSI, security context(K, OPc, AMF), and APN of the subscriber. + 4. Click `SAVE` Button + +**Tip:** This addition immediately affects Open5GS without restaring any daemon. +{: .notice--warning} + +### Adding a route for UE to have internet connectivity +--- + +If your phone can connect to internet, you must run the following command in Open5GS-PGW installed host. + +```bash +### Check IP Tables +$ sudo iptables -L +Chain INPUT (policy ACCEPT) +target prot opt source destination + +Chain FORWARD (policy ACCEPT) +target prot opt source destination + +Chain OUTPUT (policy ACCEPT) +target prot opt source destination + +### Check NAT Tables +$ sudo iptables -L -t nat +Chain PREROUTING (policy ACCEPT) +target prot opt source destination + +Chain INPUT (policy ACCEPT) +target prot opt source destination + +Chain OUTPUT (policy ACCEPT) +target prot opt source destination + +Chain POSTROUTING (policy ACCEPT) +target prot opt source destination + +### Enable IPv4 Forwarding +$ sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward" + +### Add NAT Rule +$ sudo iptables -t nat -A POSTROUTING -s 45.45.0.0/16 ! -o ogstun -j MASQUERADE +``` + +**Note:** It is a good condition if you do not have any rules in the IP/NAT tables. If a program such as docker has already set up a rule, you will need to add a rule differently. + +### Turn on your eNodeB and Phone +--- + +- You can see actual traffic through wireshark -- [[srsenb.pcapng]]({{ site.url }}{{ site.baseurl }}/assets/pcapng/srsenb.pcapng). +- You can view the log at `$INSTALL_PREFIX/var/log/open5gs/*.log`. + +### Troubleshooting +--- + +Debugging tools can help you troubleshoot problems. + +- [GDB](https://www.gnu.org/software/gdb/) can be used as below: + + ```bash + $ gdb ./open5gs-mmed + ``` + +- On *Mac OS X*, you can use the [LLDB](https://lldb.llvm.org/). + + ```bash + $ lldb ./open5gs-mmed + ``` + +You can use the command line option[`-d`] to record more logs. + +```bash +Open5GS daemon v1.0.0 + +10/27 15:50:45.170: [app] INFO: Configuration: '/Users/acetcom/Documents/git/nextepc/install/etc/open5gs/mme.yaml' (../src/main.c:54) +10/27 15:50:45.171: [app] INFO: File Logging: '/Users/acetcom/Documents/git/nextepc/install/var/log/open5gs/mme.log' (../src/main.c:57) +10/27 15:50:45.171: [app] INFO: LOG-LEVEL: 'debug' (../src/main.c:60) +10/27 15:50:45.267: [thread] DEBUG: [0x10b52ed08] thread started (../lib/core/ogs-thread.c:101) +10/27 15:50:45.267: [thread] DEBUG: [0x10b52ed08] worker signal (../lib/core/ogs-thread.c:66) +10/27 15:50:45.268: [app] INFO: MME initialize...done (../src/mme/app-init.c:33) +10/27 15:50:45.268: [mme] DEBUG: mme_state_initial(): INIT + (../src/mme/mme-sm.c:38) +10/27 15:50:45.268: [mme] DEBUG: mme_state_operational(): ENTRY + (../src/mme/mme-sm.c:83) +10/27 15:50:45.269: [sock] DEBUG: socket create(2:2:17) (../lib/core/ogs-socket.c:92) +10/27 15:50:45.269: [sock] DEBUG: udp_socket() family:2 (../lib/core/ogs-udp.c:31) +10/27 15:50:45.269: [sock] DEBUG: socket bind 192.168.0.3:2123 (../lib/core/ogs-socket.c:117) +10/27 15:50:45.269: [sock] DEBUG: udp_server() [192.168.0.3]:2123 (../lib/core/ogs-udp.c:55) +10/27 15:50:45.269: [gtp] INFO: gtp_server() [192.168.0.3]:2123 (../lib/gtp/path.c:32) +10/27 15:50:45.269: [gtp] INFO: gtp_connect() [127.0.0.2]:2123 (../lib/gtp/path.c:57) +10/27 15:50:45.270: [sctp] DEBUG: Old INITMSG (numout:10 maxin:2048 maxattempt:8 maxinit_to:60000) (../lib/sctp/ogs-usrsctp.c:132) +10/27 15:50:45.271: [sctp] DEBUG: New INITMSG (numout:30 maxin:65535 maxattempt:4 maxinit_to:8000) (../lib/sctp/ogs-usrsctp.c:152) +10/27 15:50:45.271: [sctp] DEBUG: sctp_bind() [192.168.0.3]:36412 (../lib/sctp/ogs-usrsctp.c:261) +10/27 15:50:45.271: [mme] INFO: s1ap_server() [192.168.0.3]:36412 (../src/mme/s1ap-usrpath.c:46) +``` diff --git a/docs/_docs/guide/03-splitting-network-elements.md b/docs/_docs/guide/03-splitting-network-elements.md index 5b927c35a..b62bcacce 100644 --- a/docs/_docs/guide/03-splitting-network-elements.md +++ b/docs/_docs/guide/03-splitting-network-elements.md @@ -1,15 +1,15 @@ --- -title: NextEPC Splitting Network Elements +title: Open5GS Splitting Network Elements head_inline: "" --- -In a production network network elements would typically not all be on the same machine, as is the default example that ships with NextEPC. +In a production network network elements would typically not all be on the same machine, as is the default example that ships with Open5GS. -NextEPC is designed to be standards compliant, so in theory you can connect any core network element (MME, PGW, SGW, PCRF, HSS) from NextEPC or any other vendor to form a functioning network, so long as they are 3GPP compliant. +Open5GS is designed to be standards compliant, so in theory you can connect any core network element (MME, PGW, SGW, PCRF, HSS) from Open5GS or any other vendor to form a functioning network, so long as they are 3GPP compliant. To demonstrate this we will cover isolating each network element onto it's on machine and connect each network element to the other. For some interfaces specifying multiple interfaces is supported to allow connection to multiple -In these examples we'll be connecting NextEPC elements together, but it could just as easily be EPC elements from a different vendor in the place of any NextEPC network element. +In these examples we'll be connecting Open5GS elements together, but it could just as easily be EPC elements from a different vendor in the place of any Open5GS network element. | Service | IP | Identity | | ------------- |:-------------:|:-------------:| @@ -27,11 +27,11 @@ In it's simplest from the P-GW has 3 interfaces: * Sgi - Connection to external network (Generally the Internet via standard TCP/IP) ### S5 Interface Configuration -Edit ```/etc/nextepc/pgw.conf```and change the address to IP of the server running the P-GW for the listener on GTP-C and GTP-U interfaces. +Edit ```/etc/open5gs/pgw.yaml``` and change the address to IP of the server running the P-GW for the listener on GTP-C and GTP-U interfaces. ``` pgw: - freeDiameter: pgw.conf + freeDiameter: /etc/freeDiameter/pgw.conf gtpc: addr: - 10.0.1.121 @@ -44,7 +44,7 @@ pgw: ### Gx Interface Configuration -Edit ```/etc/nextepc/freeDiameter/pgwd.conf``` +Edit ```/etc/freeDiameter/pgw.conf``` Update ```ListenOn``` address to IP of the server running the P-GW: @@ -56,9 +56,9 @@ Update ConnectPeer to connect to the PCRF on it's IP. ### Restart Services -Restart NextEPC PGW Daemon: +Restart Open5GS PGW Daemon: -``` $ sudo systemctl restart nextepc-pgwd ``` +``` $ sudo systemctl restart open5gs-pgwd ``` # External S-GW @@ -67,19 +67,19 @@ In it's simplest form the S-GW has 2 interfaces: * S5 - Connection to the home network P-GW (GTP-C) ### S5 Interface Configuration -Edit ```/etc/nextepc/sgw.conf```and change the address to IP of the server running the S-GW for the listener on GTP-C interface. +Edit ```/etc/open5gs/sgw.yaml``` and change the address to IP of the server running the S-GW for the listener on GTP-C interface. ``` sgw: - freeDiameter: pgw.conf + freeDiameter: /etc/freeDiameter/pgw.conf gtpc: addr: - 10.0.1.122 ``` - Restart NextEPC SGW Daemon: + Restart Open5GS SGW Daemon: -``` $ sudo systemctl restart nextepc-sgwd ``` +``` $ sudo systemctl restart open5gs-sgwd ``` # External PCRF @@ -87,7 +87,7 @@ In it's simplest from the PCRF has 1 network interface: * Gx - Connection to P-GW (Diameter) ### Gx Interface Configuration -Edit ```/etc/nextepc/freeDiameter/hss.conf``` +Edit ```/etc/freeDiameter/hss.conf``` Update ```ListenOn``` address to IP of the server running the HSS on it's IP: @@ -97,19 +97,19 @@ Update ConnectPeer to connect to the MME. ```ConnectPeer = "pgw.localdomain" { ConnectTo = "10.0.1.121"; No_TLS; };``` -### MongoDB Interface Configuration (NextEPC HSS only) -Edit ```/etc/nextepc/freeDiameter/hss.conf``` and change the ```db_uri:``` to point at the HSS: ```db_uri: mongodb://10.0.1.118/nextepc``` +### MongoDB Interface Configuration (Open5GS HSS only) +Edit ```/etc/freeDiameter/hss.conf``` and change the ```db_uri:``` to point at the HSS: ```db_uri: mongodb://10.0.1.118/open5gs``` -Restart NextEPC PCRF Daemon: +Restart Open5GS PCRF Daemon: -``` $ sudo systemctl restart nextepc-pcrfd ``` +``` $ sudo systemctl restart open5gs-pcrfd ``` # External HSS In it's simplest form the HSS has 1 network interface: * S6a - Connection to MME (Diameter) ### S6a Interface Configuration -Edit ```/etc/nextepc/freeDiameter/hss.conf``` +Edit ```/etc/freeDiameter/hss.conf``` Update ```ListenOn``` address to IP of the server running the HSS on it's IP: @@ -119,12 +119,12 @@ Update ConnectPeer to connect to the MME. ```ConnectPeer = "mme.localdomain" { ConnectTo = "10.0.1.124"; No_TLS; };``` -Restart NextEPC HSS Daemon: +Restart Open5GS HSS Daemon: -``` $ sudo systemctl restart nextepc-hssd ``` +``` $ sudo systemctl restart open5gs-hssd ``` -### MongoDB Interface Configuration (NextEPC specific) -If you are using NextEPC's HSS you may need to enable MongoDB access from the PCRF. This is done by editing ''/etc/mongodb.conf'' and changing the bind IP to: +### MongoDB Interface Configuration (Open5GS specific) +If you are using Open5GS's HSS you may need to enable MongoDB access from the PCRF. This is done by editing ''/etc/mongodb.conf'' and changing the bind IP to: ``` bind_ip = 0.0.0.0 ``` Restart MongoDB for changes to take effect. @@ -138,7 +138,7 @@ In it's simplest form the MME has 3 interfaces: * S11 - Connection to S-GW (GTP-C) ### S11 Interface Configuration -Edit ```/etc/nextepc/mme.conf```, filling the IP address of the S-GW and P-GW servers. +Edit ```/etc/open5gs/mme.yaml``` and filling the IP address of the S-GW and P-GW servers. ``` sgw: gtpc: @@ -151,7 +151,7 @@ pgw: ``` ### S6a Interface Configuration -Edit ```/etc/nextepc/freeDiameter/mme.conf``` +Edit ```/etc/freeDiameter/mme.conf``` Update ```ListenOn``` address to IP of the server running the MME: @@ -163,7 +163,7 @@ Update ConnectPeer to connect to the PCRF on it's IP. ### Restart Services -Restart NextEPC MME Daemon: +Restart Open5GS MME Daemon: -``` $ sudo systemctl restart nextepc-mmed ``` +``` $ sudo systemctl restart open5gs-mmed ``` diff --git a/docs/_docs/guide/04-setting-up-kamailio-IMS.md b/docs/_docs/guide/04-setting-up-kamailio-IMS.md index 1445df468..fa87d0d6b 100644 --- a/docs/_docs/guide/04-setting-up-kamailio-IMS.md +++ b/docs/_docs/guide/04-setting-up-kamailio-IMS.md @@ -3,7 +3,7 @@ title: Setting up Kamailio IMS head_inline: "" --- -Setting up Kamailio IMS in OpenStack VM and connecting P-CSCF of Kamailio IMS with PCRF of NextEPC (Running on another OpenStak VM) - Install from deb packages +Setting up Kamailio IMS in OpenStack VM and connecting P-CSCF of Kamailio IMS with PCRF of Open5GS (Running on another OpenStak VM) - Install from deb packages {: .blue} @@ -1195,9 +1195,9 @@ password: hss The steps are exactly the same as in Step 11, but now the usernames and passwords are alice and bob, which are the default users present in FoHSS. -#### 18. Ensure NextEPC PCRF of the Core Network is configured to use IMS +#### 18. Ensure Open5GS PCRF of the Core Network is configured to use IMS -In nextepc.conf, add the floating IP of the VM running P-CSCF as shown below +In open5gs.yaml, add the floating IP of the VM running P-CSCF as shown below ``` parameter: @@ -1208,19 +1208,19 @@ pcscf: - 172.24.15.21 ``` -And, make sure to run NextEPC with Realm as created above "mnc096.mcc262.3gppnetwork.org" so that when a connection request from P-SCSF to PCRF with a FQDN pcrf.mnc096.mcc262.3gppnetwork.org it should be resolved as localhost of the NextEPC machine +And, make sure to run Open5GS with Realm as created above "mnc096.mcc262.3gppnetwork.org" so that when a connection request from P-SCSF to PCRF with a FQDN pcrf.mnc096.mcc262.3gppnetwork.org it should be resolved as localhost of the Open5GS machine {: .notice--warning} -- To change Realm in All-in-One NextEPC configuration +- To change Realm in All-in-One Open5GS configuration ``` -$ cd ~/nextepc/install/etc/nextepc/freediameter +$ cd ~/open5gs/install/etc/freediameter ``` - And, change all the configuration files in freediameter folder (hss.conf, mme.conf, pcrf.conf, pgw.conf) to have desired Domain Name -- Copy `make_certs.sh` from `~/nextepc/support/freeDiameter/` to `~/nextepc/install/etc/nextepc/freediameter`. +- Copy `make_certs.sh` from `~/open5gs/misc` to `~/open5gs/install/etc/freediameter`. - Modify Domain Names in make_certs.sh and Generate the certificates using make_certs.sh -- Insert additional "ConnectPeer" entry in `~/nextepc/install/etc/nextepc/freediameter/pcrf.conf` to connect to P-CSCF as show below +- Insert additional "ConnectPeer" entry in `~/open5gs/install/etc/freediameter/pcrf.conf` to connect to P-CSCF as show below ``` ConnectPeer = "pcscf.mnc096.mcc262.3gppnetwork.org" { ConnectTo = "172.24.15.21"; Port=3871; No_TLS; NO_SCTP; }; diff --git a/docs/_docs/platform/01-debian-ubuntu.md b/docs/_docs/platform/01-debian-ubuntu.md index 7bb612865..5626effd2 100644 --- a/docs/_docs/platform/01-debian-ubuntu.md +++ b/docs/_docs/platform/01-debian-ubuntu.md @@ -2,26 +2,16 @@ title: Build on Ubuntu/Debian --- -### TUN device permissions ---- - -To run nextepc with least privilege, the TUN device privilege should be a `crw-rw-rw-`(666). Otherwise, you need to run nextepc daemon as root. If the permission is not `crw-rw-rw-`(666), you may need to install [udev](https://mirrors.edge.kernel.org/pub/linux/utils/kernel/hotplug/udev/udev.html) package. +### Using Meson +Install the depedencies for using Meson. ```bash -$ ls -al /dev/net/tun -crw-rw---- 1 root 28 10, 200 Feb 11 05:13 /dev/net/tun - -$ sudo apt install udev -$ sudo systemctl start systemd-udevd (if '/lib/systemd/systemd-udevd' is not running) - -$ ls -al /dev/net/tun -crw-rw-rw- 1 root 28 10, 200 Feb 11 05:13 /dev/net/tun +$ sudo apt install python3 python3-pip python3-setuptools python3-wheel ninja-build ``` -Nevertheless, if the permission do not change, you can run nextepc with root privileges or change the permission using [chmod](https://www.gnu.org/software/coreutils/manual/html_node/chmod-invocation.html) as follows: - +Install Meson using Python ```bash -$ sudo chmod 666 /dev/net/tun +$ pip3 install --user meson ``` ### Making TUN Permanent @@ -29,21 +19,21 @@ $ sudo chmod 666 /dev/net/tun Write a configuration file for the TUN deivce. ```bash -$ sudo sh -c "cat << EOF > /etc/systemd/network/99-nextepc.netdev +$ sudo sh -c "cat << EOF > /etc/systemd/network/99-open5gs.netdev [NetDev] -Name=pgwtun +Name=ogstun Kind=tun EOF" ``` -Create a TUN device. The interface name will be `pgwtun`. +Create a TUN device. The interface name will be `ogstun`. ```bash $ sudo systemctl enable systemd-networkd $ sudo systemctl restart systemd-networkd $ sudo apt install net-tools -$ ifconfig pgwtun -pgwtun: flags=4241 mtu 1500 +$ ifconfig ogstun +ogstun: flags=4241 mtu 1500 inet6 fe80::e86e:86d8:ea24:f8ee prefixlen 64 scopeid 0x20 unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 txqueuelen 500 (UNSPEC) RX packets 0 bytes 0 (0.0 B) @@ -55,13 +45,13 @@ pgwtun: flags=4241 mtu 1500 Then, to support IPv6-enabled UEs, you must configure your TUN device to support IPv6. ```bash -$ sysctl -n net.ipv6.conf.pgwtun.disable_ipv6 +$ sysctl -n net.ipv6.conf.ogstun.disable_ipv6 1 -$ sudo sh -c "echo 'net.ipv6.conf.pgwtun.disable_ipv6=0' > /etc/sysctl.d/30-nextepc.conf" -$ sudo sysctl -p /etc/sysctl.d/30-nextepc.conf +$ sudo sh -c "echo 'net.ipv6.conf.ogstun.disable_ipv6=0' > /etc/sysctl.d/30-open5gs.conf" +$ sudo sysctl -p /etc/sysctl.d/30-open5gs.conf -$ sysctl -n net.ipv6.conf.pgwtun.disable_ipv6 +$ sysctl -n net.ipv6.conf.ogstun.disable_ipv6 0 ``` @@ -72,9 +62,9 @@ $ sysctl -n net.ipv6.conf.pgwtun.disable_ipv6 You are now ready to set the IP address on TUN device. ```bash -$ sudo sh -c "cat << EOF > /etc/systemd/network/99-nextepc.network +$ sudo sh -c "cat << EOF > /etc/systemd/network/99-open5gs.network [Match] -Name=pgwtun +Name=ogstun [Network] Address=45.45.0.1/16 Address=cafe::1/64 @@ -91,8 +81,8 @@ Make sure it is set up properly. ```bash -$ ifconfig pgwtun -pgwtun: flags=4305 mtu 1500 +$ ifconfig ogstun +ogstun: flags=4305 mtu 1500 inet 45.45.0.1 netmask 255.255.0.0 destination 45.45.0.1 inet6 cafe::1 prefixlen 64 scopeid 0x0 inet6 fe80::e86e:86d8:ea24:f8ee prefixlen 64 scopeid 0x20 @@ -103,6 +93,6 @@ pgwtun: flags=4305 mtu 1500 TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 ``` -**Note:** On *Linux*, you should run `nextepc-pgwd` first to correctly verify the IP address of TUN device. Otherwise, the TUN device's IP address is not displayed by the [ifconfig](http://net-tools.sourceforge.net/man/ifconfig.8.html) command. +**Note:** On *Linux*, you should run `open5gs-pgwd` first to correctly verify the IP address of TUN device. Otherwise, the TUN device's IP address is not displayed by the [ifconfig](http://net-tools.sourceforge.net/man/ifconfig.8.html) command. {: .notice--warning} diff --git a/docs/_docs/platform/02-centos.md b/docs/_docs/platform/02-centos.md index 24b2220f8..d252e7302 100644 --- a/docs/_docs/platform/02-centos.md +++ b/docs/_docs/platform/02-centos.md @@ -3,7 +3,7 @@ title: CentOS head_inline: "" --- -This guide is based on **CentOS 7** Distribution. +This guide is based on **CentOS 8** Distribution. {: .blue} ### Getting MongoDB @@ -30,22 +30,22 @@ sudo systemctl start mongod (if '/usr/bin/mongod' is not running) ### Setting up TUN device (No persistent after rebooting) --- -Create the TUN device. Interface name will be `pgwtun`. +Create the TUN device. Interface name will be `ogstun`. ```bash $ sudo yum -y install iproute -$ sudo ip tuntap add name pgwtun mode tun +$ sudo ip tuntap add name ogstun mode tun $ ip link show ``` Then, to support IPv6-enabled UEs, you must configure your TUN device to support IPv6. ```bash -$ sysctl -n net.ipv6.conf.pgwtun.disable_ipv6 +$ sysctl -n net.ipv6.conf.ogstun.disable_ipv6 1 -$ sudo -w net.ipv6.conf.pgwtun.disable_ipv6=0 +$ sudo -w net.ipv6.conf.ogstun.disable_ipv6=0 -$ sysctl -n net.ipv6.conf.pgwtun.disable_ipv6 +$ sysctl -n net.ipv6.conf.ogstun.disable_ipv6 0 ``` @@ -55,66 +55,79 @@ $ sysctl -n net.ipv6.conf.pgwtun.disable_ipv6 You are now ready to set the IP address on TUN device. ```bash -$ sudo ip addr add 45.45.0.1/16 dev pgwtun -$ sudo ip addr add cafe::1/64 dev pgwtun +$ sudo ip addr add 45.45.0.1/16 dev ogstun +$ sudo ip addr add cafe::1/64 dev ogstun ``` Make sure it is set up properly. ```bash -$ sudo ip link set pgwtun up +$ sudo ip link set ogstun up $ ip link show ``` -**Tip:** The script provided in [$GIT_REPO/support/network/restart.sh](https://github.com/{{ site.github_username }}/nextepc/blob/master/support/network/restart.sh) makes it easy to configure the TUN device as follows: -`$ sudo ./support/network/restart.sh` +**Tip:** The script provided in [$GIT_REPO/misc/netconf.sh](https://github.com/{{ site.github_username }}/open5gs/blob/master/misc/netconf.sh) makes it easy to configure the TUN device as follows: +`$ sudo ./misc/netconf.sh` {: .notice--info} -### Building NextEPC +### Building Open5GS --- +Configure EPEL package. + +```bash +$ sudo dnf install epel-release +``` + +Enable PowerTools. +```bash +$ sudo dnf install 'dnf-command(config-manager)' +$ sudo dnf config-manager --set-enabled PowerTools +$ sudo update +``` + Install the depedencies for building the source code. ```bash -$ sudo yum -y install git flex bison autoconf libtool lksctp-tools-devel libidn-devel gnutls-devel libgcrypt-devel openssl-devel cyrus-sasl-devel libyaml-devel +$ sudo dnf install python3 ninja-build gcc flex bison git lksctp-tools-devel libidn-devel gnutls-devel libgcrypt-devel openssl-devel cyrus-sasl-devel libyaml-devel iproute mongo-c-driver-devel ``` -Configure EPEL package and install mongo-c-driver. +Install Meson using Python. ```bash -$ sudo yum -y install epel-release -$ sudo yum -y install mongo-c-driver-devel +$ sudo pip3 install --upgrade pip +$ sudo pip install meson ``` -Git clone with `--recursive` option. +Git clone. ```bash -➜ open5gs git clone --recursive https://github.com/{{ site.github_username }}/nextepc +$ git clone https://github.com/{{ site.github_username }}/open5gs ``` -To compile with autotools: +To compile with meson: ```bash -➜ open5gs cd nextepc -➜ nextepc git:(master) ✗ autoreconf -iv -➜ nextepc git:(master) ✗ ./configure --prefix=`pwd`/install -➜ nextepc git:(master) ✗ make -j `nproc` +$ cd open5gs +$ meson build --prefix=`pwd`/install +$ ninja -C build ``` Check whether the compilation is correct. ```bash -➜ nextepc git:(master) ✗ make check +$ ninja -C build test ``` -**Tip:** You can also check the result of `make check` with a tool that captures packets. If you are running `wireshark`, select the `loopback` interface and set FILTER to `s1ap || gtpv2 || diameter || gtp`. You can see the virtually created packets. [[testcomplex.pcapng]]({{ site.url }}{{ site.baseurl }}/assets/pcapng/testcomplex.pcapng) +**Tip:** You can also check the result of `ninja -C build test` with a tool that captures packets. If you are running `wireshark`, select the `loopback` interface and set FILTER to `s1ap || gtpv2 || diameter || gtp`. You can see the virtually created packets. [[testcomplex.pcapng]]({{ site.url }}{{ site.baseurl }}/assets/pcapng/testcomplex.pcapng) {: .notice--info} You need to perform the **installation process**. ```bash -➜ nextepc git:(master) ✗ make install +$ cd build +$ ninja install ``` -### Building WebUI of NextEPC +### Building WebUI of Open5GS --- -[Node.js](https://nodejs.org/) is required to build WebUI of NextEPC +[Node.js](https://nodejs.org/) is required to build WebUI of Open5GS ```bash $ curl --silent --location https://rpm.nodesource.com/setup_8.x | sudo bash - @@ -124,12 +137,12 @@ $ sudo yum -y install nodejs Install the dependencies to run WebUI ```bash -➜ nextepc git:(master) ✗ cd webui -➜ webui git:(master) ✗ npm install +$ cd webui +$ npm install ``` The WebUI runs as an [npm](https://www.npmjs.com/) script. ```bash -➜ webui git:(master) ✗ npm run dev +$ npm run dev ``` diff --git a/docs/_docs/platform/03-fedora.md b/docs/_docs/platform/03-fedora.md index 9894f5674..618701c58 100644 --- a/docs/_docs/platform/03-fedora.md +++ b/docs/_docs/platform/03-fedora.md @@ -3,7 +3,7 @@ title: Fedora head_inline: "" --- -This guide is based on **Fedora 27** Distribution. +This guide is based on **Fedora 30** Distribution. {: .blue} ### Getting MongoDB @@ -23,22 +23,22 @@ $ mongod --dbpath ./data/db ### Setting up TUN device (No persistent after rebooting) --- -Create the TUN device. Interface name will be `pgwtun`. +Create the TUN device. Interface name will be `ogstun`. ```bash $ sudo dnf -y install iproute -$ sudo ip tuntap add name pgwtun mode tun +$ sudo ip tuntap add name ogstun mode tun $ ip link show ``` Then, to support IPv6-enabled UEs, you must configure your TUN device to support IPv6. ```bash -$ sysctl -n net.ipv6.conf.pgwtun.disable_ipv6 +$ sysctl -n net.ipv6.conf.ogstun.disable_ipv6 1 -$ sudo -w net.ipv6.conf.pgwtun.disable_ipv6=0 +$ sudo -w net.ipv6.conf.ogstun.disable_ipv6=0 -$ sysctl -n net.ipv6.conf.pgwtun.disable_ipv6 +$ sysctl -n net.ipv6.conf.ogstun.disable_ipv6 0 ``` @@ -48,60 +48,66 @@ $ sysctl -n net.ipv6.conf.pgwtun.disable_ipv6 You are now ready to set the IP address on TUN device. ```bash -$ sudo ip addr add 45.45.0.1/16 dev pgwtun -$ sudo ip addr add cafe::1/64 dev pgwtun +$ sudo ip addr add 45.45.0.1/16 dev ogstun +$ sudo ip addr add cafe::1/64 dev ogstun ``` Make sure it is set up properly. ```bash -$ sudo ip link set pgwtun up +$ sudo ip link set ogstun up $ ip link show ``` -**Tip:** The script provided in [$GIT_REPO/support/network/restart.sh](https://github.com/{{ site.github_username }}/nextepc/blob/master/support/network/restart.sh) makes it easy to configure the TUN device as follows: -`$ sudo ./support/network/restart.sh` +**Tip:** The script provided in [$GIT_REPO/misc/netconf.sh](https://github.com/{{ site.github_username }}/open5gs/blob/master/misc/netconf.sh) makes it easy to configure the TUN device as follows: +`$ sudo ./misc/netconf.sh` {: .notice--info} -### Building NextEPC +### Building Open5GS --- Install the depedencies for building the source code. ```bash -$ sudo dnf -y install git gcc flex bison autoconf libtool mongo-c-driver-devel lksctp-tools-devel libidn-devel gnutls-devel libgcrypt-devel openssl-devel cyrus-sasl-devel snappy-devel libyaml-devel +$ sudo dnf install python3 ninja-build gcc flex bison git lksctp-tools-devel libidn-devel gnutls-devel libgcrypt-devel openssl-devel cyrus-sasl-devel libyaml-devel iproute mongo-c-driver-devel ``` -Git clone with `--recursive` option. - +Install Meson using Python. ```bash -➜ open5gs git clone --recursive https://github.com/{{ site.github_username }}/nextepc +$ sudo pip3 install --upgrade pip +$ sudo pip install meson ``` -To compile with autotools: +Git clone. ```bash -➜ open5gs cd nextepc -➜ nextepc git:(master) ✗ autoreconf -iv -➜ nextepc git:(master) ✗ ./configure --prefix=`pwd`/install -➜ nextepc git:(master) ✗ make -j `nproc` +$ git clone https://github.com/{{ site.github_username }}/open5gs +``` + +To compile with meson: + +```bash +$ cd open5gs +$ meson build --prefix=`pwd`/install +$ ninja -C build ``` Check whether the compilation is correct. ```bash -➜ nextepc git:(master) ✗ make check +$ ninja -C build test ``` -**Tip:** You can also check the result of `make check` with a tool that captures packets. If you are running `wireshark`, select the `loopback` interface and set FILTER to `s1ap || gtpv2 || diameter || gtp`. You can see the virtually created packets. [[testcomplex.pcapng]]({{ site.url }}{{ site.baseurl }}/assets/pcapng/testcomplex.pcapng) +**Tip:** You can also check the result of `ninja -C build test` with a tool that captures packets. If you are running `wireshark`, select the `loopback` interface and set FILTER to `s1ap || gtpv2 || diameter || gtp`. You can see the virtually created packets. [[testcomplex.pcapng]]({{ site.url }}{{ site.baseurl }}/assets/pcapng/testcomplex.pcapng) {: .notice--info} You need to perform **the installation process**. ```bash -➜ nextepc git:(master) ✗ make install +$ cd build +$ ninja install ``` -### Building WebUI of NextEPC +### Building WebUI of Open5GS --- -[Node.js](https://nodejs.org/) is required to build WebUI of NextEPC +[Node.js](https://nodejs.org/) is required to build WebUI of Open5GS ```bash $ sudo dnf -y install nodejs @@ -110,12 +116,12 @@ $ sudo dnf -y install nodejs Install the dependencies to run WebUI ```bash -➜ nextepc git:(master) ✗ cd webui -➜ webui git:(master) ✗ npm install +$ cd webui +$ npm install ``` The WebUI runs as an [npm](https://www.npmjs.com/) script. ```bash -➜ webui git:(master) ✗ npm run dev +$ npm run dev ``` diff --git a/docs/_docs/platform/04-freebsd.md b/docs/_docs/platform/04-freebsd.md index ff1f5e5ae..b81ce239a 100644 --- a/docs/_docs/platform/04-freebsd.md +++ b/docs/_docs/platform/04-freebsd.md @@ -36,31 +36,36 @@ Enable IP forwarding $ sudo sysctl -w net.inet.ip.forwarding=1 ``` -**Tip:** The script provided in [$GIT_REPO/support/network/restart.sh](https://github.com/{{ site.github_username }}/nextepc/blob/master/support/network/restart.sh) makes it easy to configure the TUN device as follows: +**Tip:** The script provided in [$GIT_REPO/support/network/restart.sh](https://github.com/{{ site.github_username }}/open5gs/blob/master/support/network/restart.sh) makes it easy to configure the TUN device as follows: `$ sudo ./support/network/restart.sh` {: .notice--info} -### Building NextEPC +### Building Open5GS --- Install the depedencies for building the source code. ```bash -$ sudo pkg install git gcc bison gsed pkgconf autoconf automake libtool mongo-c-driver gnutls libgcrypt libidn libyaml +$ sudo pkg install py36-pip ninja gcc bison gsed pkgconf git mongo-c-driver gnutls libgcrypt libidn libyaml ``` -Git clone with `--recursive` option. +Install Meson using Python. +```bash +$ sudo pip install --upgrade pip +$ sudo pip install meson +``` + +Git clone. ```bash -➜ open5gs git clone --recursive https://github.com/{{ site.github_username }}/nextepc +$ git clone https://github.com/{{ site.github_username }}/open5gs ``` To compile with autotools: ```bash -➜ open5gs cd nextepc -➜ nextepc git:(master) ✗ autoreconf -iv -➜ nextepc git:(master) ✗ ./configure --prefix=`pwd`/install -➜ nextepc git:(master) ✗ make -j `nproc` +$ cd open5gs +$ meson build --prefix=`pwd`/install +$ ninja -C build ``` Check whether the compilation is correct. @@ -68,21 +73,22 @@ Check whether the compilation is correct. **Note:** This should require *sudo* due to access `/dev/tun0`. {: .notice--danger} ```bash -➜ nextepc git:(master) ✗ sudo make check +$ sudo ninja -C build test ``` -**Tip:** You can also check the result of `make check` with a tool that captures packets. If you are running `wireshark`, select the `loopback` interface and set FILTER to `s1ap || gtpv2 || diameter || gtp`. You can see the virtually created packets. [[testcomplex.pcapng]]({{ site.url }}{{ site.baseurl }}/assets/pcapng/testcomplex.pcapng) +**Tip:** You can also check the result of `ninja -C build test` with a tool that captures packets. If you are running `wireshark`, select the `loopback` interface and set FILTER to `s1ap || gtpv2 || diameter || gtp`. You can see the virtually created packets. [[testcomplex.pcapng]]({{ site.url }}{{ site.baseurl }}/assets/pcapng/testcomplex.pcapng) {: .notice--info} You need to perform **the installation process**. ```bash -➜ nextepc git:(master) ✗ make install +$ cd build +$ ninja install ``` -### Building WebUI of NextEPC +### Building WebUI of Open5GS --- -[Node.js](https://nodejs.org/) is required to build WebUI of NextEPC +[Node.js](https://nodejs.org/) is required to build WebUI of Open5GS ```bash $ sudo pkg install node @@ -91,13 +97,13 @@ $ sudo pkg install node Install the dependencies to run WebUI ```bash -➜ nextepc git:(master) ✗ cd webui -➜ webui git:(master) ✗ npm install +$ cd webui +$ npm install ``` The WebUI runs as an [npm](https://www.npmjs.com/) script. ```bash -➜ webui git:(master) ✗ npm run dev +$ npm run dev ``` diff --git a/docs/_docs/platform/05-macosx.md b/docs/_docs/platform/05-macosx.md index 0a6acd180..09a9b55e6 100644 --- a/docs/_docs/platform/05-macosx.md +++ b/docs/_docs/platform/05-macosx.md @@ -3,7 +3,7 @@ title: Mac OS X head_inline: "" --- -This guide is based on **macOS High Sierra 10.13.3**. +This guide is based on **macOS Catalina 10.15**. {: .blue} ### Installing Homebrew @@ -45,57 +45,62 @@ $ sudo ifconfig lo0 alias 127.0.0.5 netmask 255.255.255.255 Enable IP forwarding & Masquerading ```bash $ sudo sysctl -w net.inet.ip.forwarding=1 -$ sudo sh -c "echo 'nat on {en0} from 45.45.0.0/16 to any -> {en0}' > /etc/pf.anchors/org.nextepc" -$ sudo pfctl -e -f /etc/pf.anchors/org.nextepc +$ sudo sh -c "echo 'nat on {en0} from 45.45.0.0/16 to any -> {en0}' > /etc/pf.anchors/org.open5gs" +$ sudo pfctl -e -f /etc/pf.anchors/org.open5gs ``` -**Tip:** The script provided in [$GIT_REPO/support/network/restart.sh](https://github.com/{{ site.github_username }}/nextepc/blob/master/support/network/restart.sh) makes it easy to configure the TUN device as follows: -`$ sudo ./support/network/restart.sh` +**Tip:** The script provided in [$GIT_REPO/misc/netconf.sh](https://github.com/{{ site.github_username }}/open5gs/blob/master/misc/netconf.sh) makes it easy to configure the TUN device as follows: +`$ sudo ./misc/netconf.sh` {: .notice--info} -### Building NextEPC +### Building Open5GS --- Install the depedencies for building the source code. ```bash -$ brew install autoconf automake libtool gnu-sed mongo-c-driver libusrsctp gnutls libgcrypt libidn libyaml pkg-config +$ brew install gnu-sed mongo-c-driver libusrsctp gnutls libgcrypt libidn libyaml pkg-config ``` -Git clone with `--recursive` option. - +Install Meson using Homebrew. ```bash -➜ open5gs git clone --recursive https://github.com/{{ site.github_username }}/nextepc +$ brew install meson ``` -To compile with autotools: +Git clone. ```bash -➜ open5gs cd nextepc -➜ nextepc git:(master) ✗ autoreconf -iv -➜ nextepc git:(master) ✗ ./configure --prefix=`pwd`/install -➜ nextepc git:(master) ✗ make -j `nproc` +$ git clone https://github.com/{{ site.github_username }}/open5gs +``` + +To compile with meson: + +```bash +$ cd open5gs +$ meson build --prefix=`pwd`/install +$ ninja -C build ``` Check whether the compilation is correct. -**Note:** This should require *sudo* due to access `/dev/tun0`. +**Note:** This should require `sudo` due to access `/dev/tun0`. {: .notice--danger} ```bash -➜ nextepc git:(master) ✗ sudo make check +$ sudo ninja -C build test ``` -**Tip:** You can also check the result of `make check` with a tool that captures packets. If you are running `wireshark`, select the `loopback` interface and set FILTER to `s1ap || gtpv2 || diameter || gtp`. You can see the virtually created packets. [[testcomplex.pcapng]]({{ site.url }}{{ site.baseurl }}/assets/pcapng/testcomplex.pcapng) +**Tip:** You can also check the result of `ninja -C build test` with a tool that captures packets. If you are running `wireshark`, select the `loopback` interface and set FILTER to `s1ap || gtpv2 || diameter || gtp`. You can see the virtually created packets. [[testcomplex.pcapng]]({{ site.url }}{{ site.baseurl }}/assets/pcapng/testcomplex.pcapng) {: .notice--info} You need to perform **the installation process**. ```bash -➜ nextepc git:(master) ✗ make install +$ cd build +$ ninja install ``` -### Building WebUI of NextEPC +### Building WebUI of Open5GS --- -[Node.js](https://nodejs.org/) is required to build WebUI of NextEPC +[Node.js](https://nodejs.org/) is required to build WebUI of Open5GS ```bash $ brew install node @@ -104,13 +109,13 @@ $ brew install node Install the dependencies to run WebUI ```bash -➜ nextepc git:(master) ✗ cd webui -➜ webui git:(master) ✗ npm install +$ cd webui +$ npm install ``` The WebUI runs as an [npm](https://www.npmjs.com/) script. ```bash -➜ webui git:(master) ✗ npm run dev +$ npm run dev ``` diff --git a/docs/_docs/platform/06-ubuntu-trusty.md b/docs/_docs/platform/06-ubuntu-trusty.md deleted file mode 100644 index 0462e264d..000000000 --- a/docs/_docs/platform/06-ubuntu-trusty.md +++ /dev/null @@ -1,157 +0,0 @@ ---- -title: Ubuntu (Trusty) -head_inline: "" ---- - -This guide is based on **Ubuntu 14.04(Trusty)** Distribution. -{: .blue} - -## Getting MongoDB - -Install MongoDB with package manager. -```bash -$ sudo apt update -$ sudo apt install mongodb -$ sudo systemctl start mongodb (if '/usr/bin/mongod' is not running) -``` - -### TUN device permissions ---- - -To run nextepc with least privilege, the TUN device privilege should be a `crw-rw-rw-`(666). Otherwise, you need to run nextepc daemon as root. If the permission is not `crw-rw-rw-`(666), you may need to install [udev](https://mirrors.edge.kernel.org/pub/linux/utils/kernel/hotplug/udev/udev.html) package. - -```bash -$ ls -al /dev/net/tun -crw-rw---- 1 root 28 10, 200 Feb 11 05:13 /dev/net/tun - -$ sudo apt install udev -$ sudo systemctl start systemd-udevd (if '/lib/systemd/systemd-udevd' is not running) - -$ ls -al /dev/net/tun -crw-rw-rw- 1 root 28 10, 200 Feb 11 05:13 /dev/net/tun -``` - -Nevertheless, if the permission do not change, you can run nextepc with root privileges or change the permission using [chmod](https://www.gnu.org/software/coreutils/manual/html_node/chmod-invocation.html) as follows: - -```bash -$ sudo chmod 666 /dev/net/tun -``` - -### Making TUN Permanent ---- - -Write the configuration file for the TUN deivce. -```bash -$ sudo sh -c "cat << EOF > /etc/network/interfaces.d/nextepc -auto pgwtun -iface pgwtun inet static - address 45.45.0.1 - netmask 255.255.0.0 - pre-up ip tuntap add name pgwtun mode tun - post-down ip tuntap del name pgwtun mode tun -iface pgwtun inet6 static - address cafe::1 - netmask 64 -EOF" -``` - -For loading TUN configuration, -```bash -$ sudo sh -c 'if ! grep "source-directory" /etc/network/interfaces | grep "/etc/network/interfaces.d" > /dev/null; then - echo "source-directory /etc/network/interfaces.d" >> /etc/network/interfaces -fi' -``` - -Create the TUN device. Interface name will be `pgwtun`. -```bash -$ ifup pgwtun -``` - -Then, to support IPv6-enabled UEs, you must configure your TUN device to support IPv6. - -```bash -$ sysctl -n net.ipv6.conf.pgwtun.disable_ipv6 -1 - -$ sudo sh -c "echo 'net.ipv6.conf.pgwtun.disable_ipv6=0' > /etc/sysctl.d/30-nextepc.conf" -$ sudo sysctl -p /etc/sysctl.d/30-nextepc.conf - -$ sysctl -n net.ipv6.conf.pgwtun.disable_ipv6 -0 -``` - -**Note:** If your TUN device already supports IPv6, you can skip this steps above. -{: .notice--warning} - - -### Building NextEPC ---- - -Install the depedencies for building the source code. - -```bash -sudo apt install git gcc flex bison make autoconf libtool pkg-config libsctp-dev libssl-dev libgnutls-dev libidn11-dev libyaml-dev -``` - -Then, compile and install Mongo C Driver like the followings. -```bash -sudo apt-get -y install g++ libsasl2-dev -tar xzf mongo-c-driver-1.8.0.tar.gz -cd mongo-c-driver-1.8.0 -./configure --disable-automatic-init-and-cleanup -make -sudo make install -sudo ldconfig -``` - -Git clone with `--recursive` option. - -```bash -➜ open5gs git clone --recursive https://github.com/{{ site.github_username }}/nextepc -``` - -To compile with autotools: - -```bash -➜ open5gs cd nextepc -➜ nextepc git:(master) ✗ autoreconf -iv -➜ nextepc git:(master) ✗ ./configure --prefix=`pwd`/install -➜ nextepc git:(master) ✗ make -j `nproc` -``` - -Check whether the compilation is correct. -```bash -➜ nextepc git:(master) ✗ make check -``` - -You need to perform **the installation process**. -```bash -➜ nextepc git:(master) ✗ make install -``` - -Check whether the installation is correct. -```bash -➜ nextepc git:(master) ✗ ./test/testcomplex -s1setup_test : SUCCESS -attach_test : SUCCESS -volte_test : SUCCESS -handover_test : SUCCESS -All tests passed. -``` - -**Tip:** You can also check the result of `./test/testcomplex` with a tool that captures packets. If you are running `wireshark`, select the `loopback` interface and set FILTER to `s1ap || gtpv2 || diameter || gtp`. You can see the virtually created packets. [[testcomplex.pcapng]]({{ site.url }}{{ site.baseurl }}/assets/pcapng/testcomplex.pcapng) -{: .notice--info} - -For developers, it provides `nextepc-epcd` daemon that includes both *MME*, *SGW*, *PGW*, *HSS*, and *PCRF*. - -```bash -➜ nextepc git:(master) ✗ ./nextepc-epcd -04/06 23:13:03.367: [core] INFO: NextEPC daemon start (main.c:169) - -PID[6404]: '/home/acetcom/Documents/git/open5gs/nextepc/install/var/run/nextepc-epcd/pid' -File Logging: '/home/acetcom/Documents/git/open5gs/nextepc/install/var/log/nextepc/nextepc.log' -MongoDB URI: 'mongodb://localhost/nextepc' -Configuration: '/home/acetcom/Documents/git/open5gs/nextepc/install/etc/nextepc/nextepc.conf' -04/06 23:13:03.369: [core] INFO: PCRF try to initialize (epc.c:37) -... -``` diff --git a/docs/_docs/tutorial/01-your-first-lte.md b/docs/_docs/tutorial/01-your-first-lte.md index a13531233..5db4d71cb 100644 --- a/docs/_docs/tutorial/01-your-first-lte.md +++ b/docs/_docs/tutorial/01-your-first-lte.md @@ -88,12 +88,12 @@ SMSP: ffffffffffffffffffffffffffffffffffffffffffffffffe1ffffffffffffffffffffffff ###### Program your SIM card like the followings: ``` -./pySim-prog.py -p 0 -n NextEPC -a 62416296 -s 8988211000000213010 -i 310789012345301 -x 310 -y 789 -k 82E9053A1882085FF2C020359938DAE9 -o BFD5771AAF4F6728E9BC6EF2C2533BDB +./pySim-prog.py -p 0 -n Open5GS -a 62416296 -s 8988211000000213010 -i 310789012345301 -x 310 -y 789 -k 82E9053A1882085FF2C020359938DAE9 -o BFD5771AAF4F6728E9BC6EF2C2533BDB Using PC/SC reader (dev=0) interface Insert card now (or CTRL-C to cancel) Autodetected card type: sysmoUSIM-SJS1 Generated card parameters : - > Name : NextEPC + > Name : Open5GS > SMSP : e1ffffffffffffffffffffffff0581005155f5ffffffffffff000000 > ICCID : 8988211000000213010 > MCC/MNC : 310/789 @@ -151,9 +151,9 @@ Download and build srsLTE: ➜ build git:(master) ✗ make test ``` -#### 3. NextEPC +#### 3. Open5GS -The NextEPC package is available on the recent versions of *Ubuntu*. +The Open5GS package is available on the recent versions of *Ubuntu*. ```bash # Getting the authentication key @@ -161,24 +161,24 @@ $ sudo apt install wget $ wget https://download.opensuse.org/repositories/home:/acetcom:/open5gs:/latest/xUbuntu_18.04/Release.key $ sudo apt-key add Release.key -# Installing NextEPC +# Installing Open5GS $ sudo sh -c "echo 'deb https://download.opensuse.org/repositories/home:/acetcom:/open5gs:/latest/xUbuntu_18.04/ ./' > /etc/apt/sources.list.d/open5gs.list" $ sudo apt update -$ sudo apt install nextepc +$ sudo apt install open5gs ``` -The following shows how to install the Web UI of NextEPC. +The following shows how to install the Web UI of Open5GS. ```bash $ curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash - $ sudo apt install nodejs -$ curl -sL http://nextepc.org/static/webui/install | sudo -E bash - +$ curl -sL http://open5gs.org/static/webui/install | sudo -E bash - ``` ### Configuration & Running --- -#### 1. NextEPC +#### 1. Open5GS When you purchase the sysmoUSIM, you will receive the following information via e-mail. @@ -219,12 +219,12 @@ Then proceed as follows: 3. Fill the IMSI, security context(K, OPc, AMF), and APN of the subscriber. 4. Click `SAVE` Button -Modify [/etc/nextepc/mme.conf](https://github.com/{{ site.github_username }}/nextepc/blob/master/support/config/mme.conf.in) to set the S1AP/GTP-C IP address, PLMN ID, and TAC +Modify [/etc/open5gs/mme.yaml](https://github.com/{{ site.github_username }}/open5gs/blob/master/configs/open5gs/mme.yaml.in) to set the S1AP/GTP-C IP address, PLMN ID, and TAC ```diff -diff -u mme.conf.old mme.conf ---- mme.conf.old 2018-04-15 18:28:31.000000000 +0900 -+++ mme.conf 2018-04-15 19:53:10.000000000 +0900 +diff -u mme.yaml.old mme.yaml +--- mme.yaml.old 2018-04-15 18:28:31.000000000 +0900 ++++ mme.yaml 2018-04-15 19:53:10.000000000 +0900 @@ -14,18 +14,20 @@ mme: freeDiameter: mme.conf @@ -263,12 +263,12 @@ TAC : 7 - srsENB default value ``` -The GTP-U IP address will be set to 127.0.0.2. To do this, modify [/etc/nextepc/sgw.conf](https://github.com/{{ site.github_username }}/nextepc/blob/master/support/config/sgw.conf.in) to set the GTP-U IP address. +The GTP-U IP address will be set to 127.0.0.2. To do this, modify [/etc/open5gs/sgw.yaml](https://github.com/{{ site.github_username }}/open5gs/blob/master/configs/open5gs/sgw.yaml.in) to set the GTP-U IP address. ```diff -diff -u /etc/nextepc/sgw.conf.old /etc/nextepc/sgw.conf ---- sgw.conf.old 2018-04-15 18:30:25.000000000 +0900 -+++ sgw.conf 2018-04-15 18:30:30.000000000 +0900 +diff -u /etc/open5gs/sgw.yaml.old /etc/open5gs/sgw.yaml +--- sgw.yaml.old 2018-04-15 18:30:25.000000000 +0900 ++++ sgw.yaml 2018-04-15 18:30:30.000000000 +0900 @@ -14,3 +14,4 @@ gtpc: addr: 127.0.0.2 @@ -276,14 +276,14 @@ diff -u /etc/nextepc/sgw.conf.old /etc/nextepc/sgw.conf + addr: 127.0.0.2 ``` -After changing conf files, please restart NextEPC daemons. +After changing conf files, please restart Open5GS daemons. ```bash -$ sudo systemctl restart nextepc-mmed -$ sudo systemctl restart nextepc-sgwd +$ sudo systemctl restart open5gs-mmed +$ sudo systemctl restart open5gs-sgwd ``` -If your phone can connect to internet, you must run the following command in NextEPC-PGW installed host. +If your phone can connect to internet, you must run the following command in Open5GS-PGW installed host. ```bash ### Check IP Tables @@ -315,7 +315,7 @@ target prot opt source destination $ sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward" ### Add NAT Rule -$ sudo iptables -t nat -A POSTROUTING -s 45.45.0.0/16 ! -o pgwtun -j MASQUERADE +$ sudo iptables -t nat -A POSTROUTING -s 45.45.0.0/16 ! -o ogstun -j MASQUERADE ``` **Note:** For the first time, it is a good condition if you do not have any rules in the IP/NAT tables. If a program such as docker has already set up a rule, you will need to add a rule differently. @@ -440,4 +440,4 @@ Type to view trace --- - You can see actual traffic through wireshark -- [[srsenb.pcapng]]({{ site.url }}{{ site.baseurl }}/assets/pcapng/srsenb.pcapng). -- You can view the log at `/var/log/nextepc/*.log`. +- You can view the log at `/var/log/open5gs/*.log`. diff --git a/docs/_includes/footer.html b/docs/_includes/footer.html index e253e21f2..3e387b857 100644 --- a/docs/_includes/footer.html +++ b/docs/_includes/footer.html @@ -14,7 +14,7 @@ {% if site.email %}
  • {{ site.email }}
  • -
  • (Please do not mail me directly for technical support. Instead, use GitHub Issues.)
  • +
  • (Please do not mail me directly for technical support. Instead, use GitHub Issues.)
  • {% endif %} diff --git a/docs/_pages/about.md b/docs/_pages/about.md index 994f8a61b..a7dd1dabf 100644 --- a/docs/_pages/about.md +++ b/docs/_pages/about.md @@ -4,7 +4,7 @@ title: About permalink: /about/ --- -NextEPC is a C-language Open Source implementation of the 3GPP Evolved Packet Core, i.e. the core network of an LTE network. +Open5GS is a C-language Open Source implementation of the 3GPP Evolved Packet Core, i.e. the core network of an LTE network. #### Supported Features --- diff --git a/docs/_pages/docs.md b/docs/_pages/docs.md index 55228d72f..acfe0a9c7 100644 --- a/docs/_pages/docs.md +++ b/docs/_pages/docs.md @@ -7,7 +7,7 @@ head_inline: "" - User's Guide - [Quickstart](guide/01-quickstart) - - [Building nextepc from Sources](guide/02-building-nextepc-from-sources) + - [Building Open5GS from Sources](guide/02-building-open5gs-from-sources) - [Splitting Network Elements](guide/03-splitting-network-elements) - [Setting up Kamailio IMS](guide/04-setting-up-kamailio-IMS) @@ -20,4 +20,3 @@ head_inline: "" - [Fedora](platform/03-fedora) - [FreeBSD](platform/04-freebsd) - [MacOSX](platform/05-macosx) - - [Ubuntu(Trusty)](platform/06-ubuntu-trusty) diff --git a/docs/_pages/faq.md b/docs/_pages/faq.md index c0b818bcf..7b9c273b2 100644 --- a/docs/_pages/faq.md +++ b/docs/_pages/faq.md @@ -6,6 +6,11 @@ permalink: /faq/ #### Is it possible to setup IP/NAT table along with Docker? +Enable IP Forward. +``` +$ sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward" +``` + The following is the default docker IP/NAT table. ``` @@ -57,7 +62,7 @@ $ diff -u oldtables newtables -A PREROUTING -m addrtype --dst-type LOCAL -j DOCKER -A OUTPUT ! -d 127.0.0.0/8 -m addrtype --dst-type LOCAL -j DOCKER -A POSTROUTING -s 172.17.0.0/16 ! -o docker0 -j MASQUERADE -+-A POSTROUTING -s 45.45.0.0/16 ! -o pgwtun -j MASQUERADE ++-A POSTROUTING -s 45.45.0.0/16 ! -o ogstun -j MASQUERADE -A DOCKER -i docker0 -j RETURN COMMIT # Completed on Sat Jun 1 23:43:50 2019 @@ -65,10 +70,10 @@ $ diff -u oldtables newtables -A FORWARD -o docker0 -j DOCKER -A FORWARD -i docker0 ! -o docker0 -j ACCEPT -A FORWARD -i docker0 -o docker0 -j ACCEPT -+-A FORWARD -o pgwtun -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT -+-A FORWARD -o pgwtun -j DOCKER -+-A FORWARD -i pgwtun ! -o pgwtun -j ACCEPT -+-A FORWARD -i pgwtun -o pgwtun -j ACCEPT ++-A FORWARD -o ogstun -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT ++-A FORWARD -o ogstun -j DOCKER ++-A FORWARD -i ogstun ! -o ogstun -j ACCEPT ++-A FORWARD -i ogstun -o ogstun -j ACCEPT -A DOCKER-ISOLATION-STAGE-1 -i docker0 ! -o docker0 -j DOCKER-ISOLATION-STAGE-2 -A DOCKER-ISOLATION-STAGE-1 -j RETURN -A DOCKER-ISOLATION-STAGE-2 -o docker0 -j DROP @@ -110,7 +115,7 @@ target prot opt source destination $ sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward" ### Add NAT Rule -$ sudo iptables -t nat -A POSTROUTING -s 45.45.0.0/16 ! -o pgwtun -j MASQUERADE +$ sudo iptables -t nat -A POSTROUTING -s 45.45.0.0/16 ! -o ogstun -j MASQUERADE ``` #### How to use a different APN for each PGW @@ -120,7 +125,7 @@ By default, MME selects the PGW as the first PGW node. To use a different APN fo See the following example. ``` -### For reference, see `nextepc.conf` +### For reference, see `pgw.yaml` #------------------------ MME -------------------------- # # o Two PGW are defined. 127.0.0.3:2123 is used. @@ -156,19 +161,19 @@ See the following example. The IP address of the UE can also use a different UE pool depending on the APN. ``` -### For reference, see `nextepc.conf` +### For reference, see `pgw.yaml` # # # # o IPv4 Pool -# $ sudo ip addr add 45.45.0.1/16 dev pgwtun +# $ sudo ip addr add 45.45.0.1/16 dev ogstun # # ue_pool: # addr: 45.45.0.1/16 # # o IPv4/IPv6 Pool -# $ sudo ip addr add 45.45.0.1/16 dev pgwtun -# $ sudo ip addr add cafe:1::1/64 dev pgwtun +# $ sudo ip addr add 45.45.0.1/16 dev ogstun +# $ sudo ip addr add cafe:1::1/64 dev ogstun # # ue_pool: # - addr: 45.45.0.1/16 @@ -177,10 +182,10 @@ The IP address of the UE can also use a different UE pool depending on the APN. # # o Specific APN(e.g 'volte') uses 45.46.0.1/16, cafe:2::1/64 # All other APNs use 45.45.0.1/16, cafe:1::1/64 -# $ sudo ip addr add 45.45.0.1/16 dev pgwtun -# $ sudo ip addr add 45.46.0.1/16 dev pgwtun -# $ sudo ip addr add cafe:1::1/64 dev pgwtun -# $ sudo ip addr add cafe:2::1/64 dev pgwtun +# $ sudo ip addr add 45.45.0.1/16 dev ogstun +# $ sudo ip addr add 45.46.0.1/16 dev ogstun +# $ sudo ip addr add cafe:1::1/64 dev ogstun +# $ sudo ip addr add cafe:2::1/64 dev ogstun # # ue_pool: # - addr: 45.45.0.1/16 @@ -190,22 +195,22 @@ The IP address of the UE can also use a different UE pool depending on the APN. # - addr: cafe:2::1/64 # apn: volte # -# o Multiple Devices (default: pgwtun) -# $ sudo ip addr add 45.45.0.1/16 dev pgwtun -# $ sudo ip addr add cafe:1::1/64 dev pgwtun2 -# $ sudo ip addr add 45.46.0.1/16 dev pgwtun3 -# $ sudo ip addr add cafe:2::1/64 dev pgwtun3 +# o Multiple Devices (default: ogstun) +# $ sudo ip addr add 45.45.0.1/16 dev ogstun +# $ sudo ip addr add cafe:1::1/64 dev ogstun2 +# $ sudo ip addr add 45.46.0.1/16 dev ogstun3 +# $ sudo ip addr add cafe:2::1/64 dev ogstun3 # # ue_pool: # - addr: 45.45.0.1/16 # - addr: cafe:1::1/64 -# dev: pgwtun2 +# dev: ogstun2 # - addr: 45.46.0.1/16 # apn: volte -# dev: pgwtun3 +# dev: ogstun3 # - addr: cafe:2::1/64 # apn: volte -# dev: pgwtun3 +# dev: ogstun3 # ``` @@ -214,11 +219,13 @@ The IP address of the UE can also use a different UE pool depending on the APN. If you do not start MongoDB, you will get the following error: ```bash -âžœ nextepc git:(master) ✗ ./test/testsimple -04/09 15:42:34.817: [core] ERROR: Failed to conect to server [mongodb://localhost/nextepc] (context.c:326) -04/09 15:42:34.817: [core] ERROR: app_initialize() failed (basic/abts-main.c:91) -s1ap_message_test : -04/09 15:42:34.830: [s1ap] ERROR: Failed to decode S1AP-PDU[-1] (s1ap_encoder.c:41) -04/09 15:42:34.830: [core] FATAL: ogs_log_vprintf: Assertion `domain' failed. (ogs-log.c:347) +$ ./install/bin/open5gs-hssd +Open5GS daemon v1.0.0 + +10/27 16:45:00.371: [app] INFO: Configuration: '/Users/acetcom/Documents/git/nextepc/install/etc/open5gs/hss.yaml' (../src/main.c:54) +10/27 16:45:00.372: [app] INFO: File Logging: '/Users/acetcom/Documents/git/nextepc/install/var/log/open5gs/hss.log' (../src/main.c:57) +10/27 16:45:00.377: [dbi] ERROR: Failed to connect to server [mongodb://localhost/open5gs] (../lib/dbi/ogs-mongoc.c:91) +10/27 16:45:00.377: [app] ERROR: Failed to intialize HSS (../src/hss/app-init.c:28) ``` You can start MongoDB using systemctl. @@ -226,20 +233,13 @@ You can start MongoDB using systemctl. $ sudo systemctl start mongodb ``` -#### Failing to run `./nextepc-epcd` +#### Failing to run `./open5gs-mmed` -You might be getting the following error after running `./nextepc-epcd`. +You might be getting the following error after running `./open5gs-mmed`. ```bash -âžœ nextepc git:(master) ./nextepc-epcd -04/09 15:41:02.600: [core] INFO: NextEPC daemon start (main.c:169) -04/09 15:41:02.601: [core] ERROR: CHECK PERMISSION of Installation Directory... (application.c:144) -04/09 15:41:02.601: [core] ERROR: Cannot create PID file:`/home/acetcom/Documents/git/open5gs/nextepc/install/var/run/nextepc-epcd/pid` (application.c:145) -04/09 15:41:02.601: [core] WARNING: log_pid: should not be reached. (application.c:146) -/home/acetcom/Documents/git/open5gs/nextepc/lib/ogslib/src/core/.libs/libogscore-1.0.so.0(ogs_abort+0x2b)[0x7f9d5d26d71b] -/home/acetcom/Documents/git/open5gs/nextepc/.libs/nextepc-epcd(+0x9606)[0x563a4ba23606] -/home/acetcom/Documents/git/open5gs/nextepc/.libs/nextepc-epcd(+0x8640)[0x563a4ba22640] -/home/acetcom/Documents/git/open5gs/nextepc/.libs/nextepc-epcd(+0x81f3)[0x563a4ba221f3] -[1] 9635 abort (core dumped) ./nextepc-epcd +$ ./build/src/mme/open5gs-mmed +10/27 16:45:41.912: [app] FATAL: cannot open file `/Users/acetcom/Documents/git/nextepc/install/etc/open5gs/mme.yaml` (../lib/app/ogs-config.c:67) +10/27 16:45:41.912: [app] FATAL: Open5GS initialization failed. Aborted (../src/main.c:211) ``` You should perform **the installation process**. @@ -248,17 +248,17 @@ You should perform **the installation process**. $ make install ``` -#### I have some error when running `./test/testcomplex` +#### I have some error when running `./build/test/simple/simple` -Did you see the following error after executing `testcomplex`? +Did you see the following error after executing `./build/test/simple/simple`? ```bash -âžœ nextepc git:(master) ✗ ./test/testcomplex +$ ./build/test/simple/simple s1setup_test : SUCCESS attach_test : -Line 134: Condition is false, but expected true \04/09 15:49:09.285: [esm] FATAL: esm_handle_pdn_connectivity_request: Assertion `SECURITY_CONTEXT_IS_VALID(mme_ue)' failed. (esm_handler.c:29) -/home/acetcom/Documents/git/open5gs/nextepc/lib/ogslib/src/core/.libs/libogscore-1.0.so.0(ogs_abort+0x2b)[0x7f608518271b] -/home/acetcom/Documents/git/open5gs/nextepc/test/.libs/testcomplex(+0x92121)[0x55dc9e274121] -/home/acetcom/Documents/git/open5gs/nextepc/test/.libs/testcomplex(+0x4f5b9)[0x55dc9e2315b9] +/home/acetcom/Documents/git/open5gs/open5gs/lib/ogslib/src/core/.libs/libogscore-1.0.so.0(ogs_abort+0x2b)[0x7f608518271b] +/home/acetcom/Documents/git/open5gs/open5gs/test/.libs/testcomplex(+0x92121)[0x55dc9e274121] +/home/acetcom/Documents/git/open5gs/open5gs/test/.libs/testcomplex(+0x4f5b9)[0x55dc9e2315b9] ``` @@ -272,15 +272,15 @@ $ mongo Kill all processes. ```bash -$ ps -ef | grep testcomplex -$ ps -ef | grep nextepc -$ sudo pkill -9 testcomplex -$ sudo pkill -9 nextepc-epcd ... +$ ps -ef | grep simple +$ ps -ef | grep open5gs +$ sudo pkill -9 simple +$ sudo pkill -9 open5gs-mmed ... ``` -Execute `testcomplex` +Execute `./build/test/simple/simple` ```bash -$ ./test/testcomplex +$ ./build/test/simple/simple ``` #### My eNB does not support IPv6. @@ -294,7 +294,7 @@ parameter: no_ipv6: true ``` -**Note:** This parameter `no_ipv6` is only applied to EPC Elements such as MME, SGW, and so on. The parameter `no_ipv6` does not affect to UE. So, IPv6-enabled UE can connect to NextEPC LTE network. +**Note:** This parameter `no_ipv6` is only applied to EPC Elements such as MME, SGW, and so on. The parameter `no_ipv6` does not affect to UE. So, IPv6-enabled UE can connect to Open5GS LTE network. {: .notice--warning} #### Unable to add new user by WebUI @@ -306,9 +306,9 @@ Please, delete corresponding cookies, cache, session data etc. You should configure the domain name on your computer. Otherwise, freeDiameter raise an error. -#### How many of UEs can NextEPC support? +#### How many of UEs can Open5GS support? -See the [lib/base/types.h](https://github.com/{{ site.github_username }}/nextepc/blob/master/lib/base/types.h). +See the [lib/core/ogs-3gpp-types.h](https://github.com/{{ site.github_username }}/open5gs/blob/master/lib/core/ogs-3gpp-types.h). ``` #define MAX_NUM_OF_ENB 128 @@ -395,7 +395,7 @@ Currently, the number of UE is limited to `128*128`. #### The parsing errors are caused by tab spaces in the configuration files. -YAML forbids tabs. You should use space instead of tab in NextEPC configuration file. +YAML forbids tabs. You should use space instead of tab in Open5GS configuration file. ```markdown YAML FAQ: Why does YAML forbid tabs? @@ -405,85 +405,66 @@ Tabs have been outlawed since they are treated differently by different editors #### Cross compilation setup -By default, NextEPC is designed to support the Embedding System. To do so, we introduced pool-based memory management. Unfortunately, we have not tested NextEPC in an embedded environment. I tried to compile on the ARM architecture using Docker and run it with QEMU for your reference. +By default, Open5GS is designed to support the Embedding System. To do so, we introduced pool-based memory management. Unfortunately, we have not tested Open5GS in an embedded environment. I tried to compile on the ARM architecture using Docker and run it with QEMU for your reference. - We'll use Debian Docker Environment. ```bash -$ git clone -r https://github.com/acetcom/nextepc -$ cd nextepc/docker +$ git clone https://github.com/acetcom/open5gs +$ cd open5gs/docker $ DIST=debian docker-compose run dev ``` - In Docker Container ```bash -acetcom@nextepc-dev:~$ sudo dpkg --add-architecture armel -acetcom@nextepc-dev:~$ sudo apt-get install libsctp-dev:armel libyaml-dev:armel libgnutls28-dev:armel libgcrypt-dev:armel libssl-dev:armel libmongoc-dev:armel libbson-dev:armel -acetcom@nextepc-dev:~$ sudo apt-get install crossbuild-essential-armel -acetcom@nextepc-dev:~$ sudo apt-get install qemu +$ sudo dpkg --add-architecture armel +$ sudo apt update +$ sudo apt install libsctp-dev:armel libyaml-dev:armel libgnutls28-dev:armel libgcrypt-dev:armel libidn11-dev:armel libssl-dev:armel libmongoc-dev:armel libbson-dev:armel +$ sudo apt install crossbuild-essential-armel +$ sudo apt install qemu +$ git clone https://github.com/acetcom/open5gs +$ cd open5gs/ -acetcom@nextepc-dev:~$ mkdir git -acetcom@nextepc-dev:~$ cd git/ -acetcom@nextepc-dev:~/git$ git clone https://github.com/acetcom/nextepc -acetcom@nextepc-dev:~/git$ cd nextepc/ -acetcom@nextepc-dev:~/git/nextepc$ autoreconf -if;./configure --prefix=`pwd`/install --host=arm-linux-gnueabi;make -j 2 -acetcom@nextepc-dev:~/git/nextepc$ make install -acetcom@nextepc-dev:~/git/nextepc$ qemu-arm .libs/nextepc-mmed -NextEPC daemon v0.3.10 - Oct 4 2018 13:24:24 +$ cat << EOF > cross_file.txt +[host_machine] +system = 'linux' +cpu_family = 'x86_64' +cpu = 'x86_64' +endian = 'little' -[10/04 13:38:06.329] WARN: pid file /home/acetcom/git/nextepc/install/var/run/nextepc-mmed/pid overwritten -- Unclean shutdown of previous NextEPC run? (application.c:113) - PID[55780] : '/home/acetcom/git/nextepc/install/var/run/nextepc-mmed/pid' - File Logging : '/home/acetcom/git/nextepc/install/var/log/nextepc/nextepc.log' -qemu: Unsupported syscall: 345 -qemu: Unsupported syscall: 345 -qemu: Unsupported syscall: 345 -qemu: Unsupported syscall: 345 -qemu: Unsupported syscall: 345 -qemu: Unsupported syscall: 345 -qemu: Unsupported syscall: 345 -qemu: Unsupported syscall: 345 - MongoDB URI : 'mongodb://mongodb/nextepc' - Configuration : '/home/acetcom/git/nextepc/install/etc/nextepc/nextepc.conf' -[10/04 13:38:06.400] MME try to initialize -Unknown host QEMU_IFLA type: 40 -Unknown host QEMU_IFLA type: 41 -Unknown host QEMU_IFLA type: 40 -Unknown host QEMU_IFLA type: 41 +[binaries] +c = '/usr/bin/arm-linux-gnueabi-gcc' +ar = '/usr/bin/arm-linux-gnueabi-ar' +strip = '/usr/bin/arm-linux-gnueabi-strip' +pkgconfig = '/usr/bin/arm-linux-gnueabi-pkg-config' +exe_wrapper = 'qemu' + +[properties] +needs_exe_wrapper = true +EOF + +$ meson build --prefix=`pwd`/install --cross-file cross_file.txt +$ ninja -C build +$ ./install/bin/open5gs-sgwd +./install/bin/open5gs-sgwd +Open5GS daemon v1.0.0 + +10/27 08:37:33.158: [app] INFO: Configuration: '/home/acetcom/git/nextepc/install/etc/open5gs/sgw.yaml' (../src/main.c:54) +10/27 08:37:33.166: [app] INFO: File Logging: '/home/acetcom/git/nextepc/install/var/log/open5gs/sgw.log' (../src/main.c:57) Unknown QEMU_IFLA_INFO_KIND ipip -Unknown host QEMU_IFLA type: 40 -Unknown host QEMU_IFLA type: 41 Unknown QEMU_IFLA_INFO_KIND ip6tnl -Unknown host QEMU_IFLA type: 40 -Unknown host QEMU_IFLA type: 41 -Unknown host QEMU_IFLA type: 40 -Unknown host QEMU_IFLA type: 41 -Unknown host QEMU_IFLA type: 40 -Unknown host QEMU_IFLA type: 41 -Unknown host QEMU_IFLA type: 40 -Unknown host QEMU_IFLA type: 41 -Unknown QEMU_IFLA_INFO_KIND ipip -Unknown host QEMU_IFLA type: 40 -Unknown host QEMU_IFLA type: 41 -Unknown QEMU_IFLA_INFO_KIND ip6tnl -Unknown host QEMU_IFLA type: 40 -Unknown host QEMU_IFLA type: 41 -Unknown host QEMU_IFLA type: 40 -Unknown host QEMU_IFLA type: 41 -[10/04 13:38:08.693] gtp_server() [172.20.0.2]:2123 -[10/04 13:38:08.696] gtp_client() [127.0.0.2]:2123 -Unsupported setsockopt level=132 optname=11 -[10/04 13:38:08.697] ERRR: Unable to subscribe to SCTP events: (92:Protocol not available) (unix/sctp.c:291) -[10/04 13:38:08.699] ASSERT: !(rv == CORE_OK). (unix/sctp.c:33) -[10/04 13:38:08.700] ERRR: sctp_server() [172.20.0.2]:36412 failed(92:Protocol not available) (unix/sctp.c:98) -[10/04 13:38:08.701] ASSERT: !(rv == CORE_OK). (s1ap_sctp.c:35) -[10/04 13:38:08.702] ASSERT: !(rv == CORE_OK). (s1ap_path.c:53) -[10/04 13:38:08.703] ASSERT: !(rv == CORE_OK). (s1ap_path.c:28) -[10/04 13:38:08.704] ERRR: Can't establish S1AP path (mme_sm.c:63) -[10/04 13:38:08.708] MME initialize...done +10/27 08:37:33.225: [app] INFO: SGW initialize...done (../src/sgw/app-init.c:31) +10/27 08:37:33.263: [gtp] INFO: gtp_server() [127.0.0.2]:2123 (../lib/gtp/path.c:32) +10/27 08:37:33.265: [gtp] INFO: gtp_server() [172.20.0.4]:2152 (../lib/gtp/path.c:32) +./install/bin/open5gs-hssd +Open5GS daemon v1.0.0 -[10/04 13:38:08.710] INFO: NextEPC daemon start (main.c:157) +10/27 08:37:45.754: [app] INFO: Configuration: '/home/acetcom/git/nextepc/install/etc/open5gs/hss.yaml' (../src/main.c:54) +10/27 08:37:45.762: [app] INFO: File Logging: '/home/acetcom/git/nextepc/install/var/log/open5gs/hss.log' (../src/main.c:57) +10/27 08:37:45.868: [dbi] INFO: MongoDB URI: 'mongodb://mongodb/open5gs' (../lib/dbi/ogs-mongoc.c:99) +^Cgetsockopt level=132 optname=0 not yet supported ``` The SCTP module is not included in the QEMU kernel. I believe that if the Linux kernel installed on your target platform contains an SCTP module, it will work normally. diff --git a/docs/_pages/github.md b/docs/_pages/github.md index 938785d70..fe013a506 100644 --- a/docs/_pages/github.md +++ b/docs/_pages/github.md @@ -1,5 +1,5 @@ --- title: GitHub redirect_to: - - https://github.com/open5gs/nextepc + - https://github.com/open5gs/open5gs --- diff --git a/docs/_posts/2017-10-09-release-v0.1.0.md b/docs/_posts/2017-10-09-release-v0.1.0.md index 1cb7725ae..ae4f734c3 100644 --- a/docs/_posts/2017-10-09-release-v0.1.0.md +++ b/docs/_posts/2017-10-09-release-v0.1.0.md @@ -8,4 +8,4 @@ tags: - Release --- -- Assets -- [v0.1.0.tar.gz](https://github.com/open5gs/nextepc/archive/v0.1.0.tar.gz) +- Assets -- [v0.1.0.tar.gz](https://github.com/open5gs/open5gs/archive/v0.1.0.tar.gz) diff --git a/docs/_posts/2017-10-11-release-v0.1.1.md b/docs/_posts/2017-10-11-release-v0.1.1.md index 25bf897b2..7ea0e1164 100644 --- a/docs/_posts/2017-10-11-release-v0.1.1.md +++ b/docs/_posts/2017-10-11-release-v0.1.1.md @@ -8,5 +8,5 @@ tags: - Release --- -- Fix the bug related to Mongo C Driver. [[More Info](https://github.com/open5gs/nextepc/commit/4245502ae287df9c457621b3f4cccb519c4d4878)] -- Assets -- [v0.1.1.tar.gz](https://github.com/open5gs/nextepc/archive/v0.1.1.tar.gz) +- Fix the bug related to Mongo C Driver. [[More Info](https://github.com/open5gs/open5gs/commit/4245502ae287df9c457621b3f4cccb519c4d4878)] +- Assets -- [v0.1.1.tar.gz](https://github.com/open5gs/open5gs/archive/v0.1.1.tar.gz) diff --git a/docs/_posts/2017-11-02-release-v0.2.0.md b/docs/_posts/2017-11-02-release-v0.2.0.md index bc787e217..43b33c9ed 100644 --- a/docs/_posts/2017-11-02-release-v0.2.0.md +++ b/docs/_posts/2017-11-02-release-v0.2.0.md @@ -11,4 +11,4 @@ tags: - Publish Debian/Ubuntu Package - Support FreeBSD and Mac OS X" -- Assets -- [v0.2.0.tar.gz](https://github.com/open5gs/nextepc/archive/v0.2.0.tar.gz) +- Assets -- [v0.2.0.tar.gz](https://github.com/open5gs/open5gs/archive/v0.2.0.tar.gz) diff --git a/docs/_posts/2017-12-18-release-v0.3.0.md b/docs/_posts/2017-12-18-release-v0.3.0.md index cdbf7fbe9..a6a3c159b 100644 --- a/docs/_posts/2017-12-18-release-v0.3.0.md +++ b/docs/_posts/2017-12-18-release-v0.3.0.md @@ -11,4 +11,4 @@ tags: - IPv6 Support (Linux Only) - Change Configuration File (JSON -> YAML) -- Assets -- [v0.3.0.tar.gz](https://github.com/open5gs/nextepc/archive/v0.3.0.tar.gz) +- Assets -- [v0.3.0.tar.gz](https://github.com/open5gs/open5gs/archive/v0.3.0.tar.gz) diff --git a/docs/_posts/2017-12-31-release-v0.3.1.md b/docs/_posts/2017-12-31-release-v0.3.1.md index c34a2c198..cbe46ac39 100644 --- a/docs/_posts/2017-12-31-release-v0.3.1.md +++ b/docs/_posts/2017-12-31-release-v0.3.1.md @@ -8,5 +8,5 @@ tags: - Release --- -- Add Authentication Synch Failure ([#11](https://github.com/open5gs/nextepc/issues/11)) -- [eric80s](https://github.com/eric80s) -- Assets -- [v0.3.1.tar.gz](https://github.com/open5gs/nextepc/archive/v0.3.1.tar.gz) +- Add Authentication Synch Failure ([#11](https://github.com/open5gs/open5gs/issues/11)) -- [eric80s](https://github.com/eric80s) +- Assets -- [v0.3.1.tar.gz](https://github.com/open5gs/open5gs/archive/v0.3.1.tar.gz) diff --git a/docs/_posts/2018-02-13-release-v0.3.3.md b/docs/_posts/2018-02-13-release-v0.3.3.md index 299e101f0..5f29c625a 100644 --- a/docs/_posts/2018-02-13-release-v0.3.3.md +++ b/docs/_posts/2018-02-13-release-v0.3.3.md @@ -10,11 +10,11 @@ head_inline: "" --- #### New -- Docker support ([#16](https://github.com/open5gs/nextepc/issues/16)) -- [amilenovic](https://github.com/amilenovic) +- Docker support ([#16](https://github.com/open5gs/open5gs/issues/16)) -- [amilenovic](https://github.com/amilenovic) #### Bug fixes -- Fix the BUG for MAC failure of authentication failure -- [#17](https://github.com/open5gs/nextepc/issues/17) from [razaborg](https://github.com/razaborg) -- Fix the BUG for EPS attach type of Attach accept -- [#12](https://github.com/open5gs/nextepc/issues/12) from [pcminitech](https://github.com/pcminitech) +- Fix the BUG for MAC failure of authentication failure -- [#17](https://github.com/open5gs/open5gs/issues/17) from [razaborg](https://github.com/razaborg) +- Fix the BUG for EPS attach type of Attach accept -- [#12](https://github.com/open5gs/open5gs/issues/12) from [pcminitech](https://github.com/pcminitech) -Download -- [v0.3.3.tar.gz](https://github.com/open5gs/nextepc/archive/v0.3.3.tar.gz) +Download -- [v0.3.3.tar.gz](https://github.com/open5gs/open5gs/archive/v0.3.3.tar.gz) {: .notice--info} diff --git a/docs/_posts/2018-03-06-release-v0.3.5.md b/docs/_posts/2018-03-06-release-v0.3.5.md index 597940a78..5079a84e9 100644 --- a/docs/_posts/2018-03-06-release-v0.3.5.md +++ b/docs/_posts/2018-03-06-release-v0.3.5.md @@ -10,11 +10,11 @@ head_inline: "" --- #### New -- Support Network Name ([#22](https://github.com/open5gs/nextepc/pull/22)) -- [medeiros405](https://github.com/medeiros405) +- Support Network Name ([#22](https://github.com/open5gs/open5gs/pull/22)) -- [medeiros405](https://github.com/medeiros405) #### Bug fixes -- Fix the BUG for security capabilities mismatch ([#27](https://github.com/open5gs/nextepc/issues/27)) -- [wayne43290](https://github.com/wayne43290) -- Fix the BUG that SGW process is dead during paging process ([#18](https://github.com/open5gs/nextepc/issues/18)) -- [jackson040407](https://github.com/jackson040407) +- Fix the BUG for security capabilities mismatch ([#27](https://github.com/open5gs/open5gs/issues/27)) -- [wayne43290](https://github.com/wayne43290) +- Fix the BUG that SGW process is dead during paging process ([#18](https://github.com/open5gs/open5gs/issues/18)) -- [jackson040407](https://github.com/jackson040407) -Download -- [v0.3.5.tar.gz](https://github.com/open5gs/nextepc/archive/v0.3.5.tar.gz) +Download -- [v0.3.5.tar.gz](https://github.com/open5gs/open5gs/archive/v0.3.5.tar.gz) {: .notice--info} diff --git a/docs/_posts/2018-03-21-release-v0.3.6.md b/docs/_posts/2018-03-21-release-v0.3.6.md index 840b87f04..d94dacea3 100644 --- a/docs/_posts/2018-03-21-release-v0.3.6.md +++ b/docs/_posts/2018-03-21-release-v0.3.6.md @@ -8,8 +8,8 @@ tags: - Release --- -- Support eNB/MME Configuration Transfer, Error Indication ([#29](https://github.com/open5gs/nextepc/issues/29)) -- [wayne43290](https://github.com/wayne43290) -- Increase SCTP recv buffer : 2048->8192 ([#35](https://github.com/open5gs/nextepc/issues/35)) -- [EugeneBogush](https://github.com/EugeneBogush) +- Support eNB/MME Configuration Transfer, Error Indication ([#29](https://github.com/open5gs/open5gs/issues/29)) -- [wayne43290](https://github.com/wayne43290) +- Increase SCTP recv buffer : 2048->8192 ([#35](https://github.com/open5gs/open5gs/issues/35)) -- [EugeneBogush](https://github.com/EugeneBogush) -Download -- [v0.3.6.tar.gz](https://github.com/open5gs/nextepc/archive/v0.3.6.tar.gz) +Download -- [v0.3.6.tar.gz](https://github.com/open5gs/open5gs/archive/v0.3.6.tar.gz) {: .notice--info} diff --git a/docs/_posts/2018-04-14-release-v0.3.7.md b/docs/_posts/2018-04-14-release-v0.3.7.md index ef9c6c3a8..0c97f9d29 100644 --- a/docs/_posts/2018-04-14-release-v0.3.7.md +++ b/docs/_posts/2018-04-14-release-v0.3.7.md @@ -8,5 +8,5 @@ tags: - Release --- -Download -- [v0.3.7.tar.gz](https://github.com/open5gs/nextepc/archive/v0.3.7.tar.gz) +Download -- [v0.3.7.tar.gz](https://github.com/open5gs/open5gs/archive/v0.3.7.tar.gz) {: .notice--info} diff --git a/docs/_posts/2018-06-03-release-v0.3.9.md b/docs/_posts/2018-06-03-release-v0.3.9.md index d3463e5e8..a41b2c422 100644 --- a/docs/_posts/2018-06-03-release-v0.3.9.md +++ b/docs/_posts/2018-06-03-release-v0.3.9.md @@ -13,11 +13,11 @@ head_inline: "" - Support NAS encryption(EEA1/EEA2/EEA3) #### Bug fixes -- Confirm with 36.412 requirement of SCTP stream id ([#54](https://github.com/open5gs/nextepc/issues/54)) -- [brchiu](https://github.com/brchiu) -- Fix to set correct timezone in UE ([#61](https://github.com/open5gs/nextepc/pull/61)) -- [medeiros405](https://github.com/medeiros405) -- Fix to change MME's integrity order ([#64](https://github.com/open5gs/nextepc/issues/64)) -- [kewinrausch](https://github.com/kewinrausch) -- Fix the bug for tracking area update ([#29](https://github.com/open5gs/nextepc/issues/29)) -- [wayne43290](https://github.com/wayne43290) -- Fix the bug for indirect tunnel ([#29](https://github.com/open5gs/nextepc/issues/29)) -- [wayne43290](https://github.com/wayne43290) +- Confirm with 36.412 requirement of SCTP stream id ([#54](https://github.com/open5gs/open5gs/issues/54)) -- [brchiu](https://github.com/brchiu) +- Fix to set correct timezone in UE ([#61](https://github.com/open5gs/open5gs/pull/61)) -- [medeiros405](https://github.com/medeiros405) +- Fix to change MME's integrity order ([#64](https://github.com/open5gs/open5gs/issues/64)) -- [kewinrausch](https://github.com/kewinrausch) +- Fix the bug for tracking area update ([#29](https://github.com/open5gs/open5gs/issues/29)) -- [wayne43290](https://github.com/wayne43290) +- Fix the bug for indirect tunnel ([#29](https://github.com/open5gs/open5gs/issues/29)) -- [wayne43290](https://github.com/wayne43290) -Download -- [v0.3.9.tar.gz](https://github.com/open5gs/nextepc/archive/v0.3.9.tar.gz) +Download -- [v0.3.9.tar.gz](https://github.com/open5gs/open5gs/archive/v0.3.9.tar.gz) {: .notice--info} diff --git a/docs/_posts/2018-08-17-release-v0.3.10.md b/docs/_posts/2018-08-17-release-v0.3.10.md index 95a264dda..654c78f9f 100644 --- a/docs/_posts/2018-08-17-release-v0.3.10.md +++ b/docs/_posts/2018-08-17-release-v0.3.10.md @@ -10,12 +10,12 @@ head_inline: "" --- #### Bug fixes - - Renew freeDiameter Certificate ([#93](https://github.com/open5gs/nextepc/issues/93), [#94](https://github.com/open5gs/nextepc/issues/94)) -- [Ravi-t](https://github.com/Ravi-t), [hchenji](https://github.com/hchenji) - - Fix TLV uint32 bug ([#73](https://github.com/open5gs/nextepc/pull/73)) -- [giuliol](https://github.com/giuliol) - - Add TRACE for IP address of connected UEs ([#71](https://github.com/open5gs/nextepc/issues/71)) -- [pgupta408](https://github.com/Ravi-t) - - Show reason string for YAML parser error ([#40](https://github.com/open5gs/nextepc/issues/40)) -- [Raw1mage](https://github.com/Raw1mage) + - Renew freeDiameter Certificate ([#93](https://github.com/open5gs/open5gs/issues/93), [#94](https://github.com/open5gs/open5gs/issues/94)) -- [Ravi-t](https://github.com/Ravi-t), [hchenji](https://github.com/hchenji) + - Fix TLV uint32 bug ([#73](https://github.com/open5gs/open5gs/pull/73)) -- [giuliol](https://github.com/giuliol) + - Add TRACE for IP address of connected UEs ([#71](https://github.com/open5gs/open5gs/issues/71)) -- [pgupta408](https://github.com/Ravi-t) + - Show reason string for YAML parser error ([#40](https://github.com/open5gs/open5gs/issues/40)) -- [Raw1mage](https://github.com/Raw1mage) - Fix compile error for GCC 8.1 - Fix compile error for Mongo-C-Driver 1.11 -Download -- [v0.3.10.tar.gz](https://github.com/open5gs/nextepc/archive/v0.3.10.tar.gz) +Download -- [v0.3.10.tar.gz](https://github.com/open5gs/open5gs/archive/v0.3.10.tar.gz) {: .notice--info} diff --git a/docs/_posts/2019-04-28-release-v0.3.11.md b/docs/_posts/2019-04-28-release-v0.3.11.md index f7daf6c14..25fbe63c3 100644 --- a/docs/_posts/2019-04-28-release-v0.3.11.md +++ b/docs/_posts/2019-04-28-release-v0.3.11.md @@ -10,19 +10,19 @@ head_inline: "" --- #### Enhancements -- Support 4-bytes RES in NAS Auth ([#147](https://github.com/open5gs/nextepc/issues/147)) -- [Ranjjiitsingh](https://github.com/Ranjjiitsingh) -- Add SGW selection mode ([#100](https://github.com/open5gs/nextepc/pull/100)) -- [TerryAlu](https://github.com/TerryAlu) +- Support 4-bytes RES in NAS Auth ([#147](https://github.com/open5gs/open5gs/issues/147)) -- [Ranjjiitsingh](https://github.com/Ranjjiitsingh) +- Add SGW selection mode ([#100](https://github.com/open5gs/open5gs/pull/100)) -- [TerryAlu](https://github.com/TerryAlu) #### Bug fixes -- Increase packet memory buffer ([#161](https://github.com/open5gs/nextepc/issues/161)) -- [mathieuxilan](https://github.com/mathieuxilan) -- Fix setting END-ID to 0 ([#156](https://github.com/open5gs/nextepc/issues/156)) -- [hypercloud2017](https://github.com/hypercloud2017) -- Fix incorrect timezone in NAS & GTP ([#140](https://github.com/open5gs/nextepc/issues/140)) -- [EugeneBogush](https://github.com/EugeneBogush) +- Increase packet memory buffer ([#161](https://github.com/open5gs/open5gs/issues/161)) -- [mathieuxilan](https://github.com/mathieuxilan) +- Fix setting END-ID to 0 ([#156](https://github.com/open5gs/open5gs/issues/156)) -- [hypercloud2017](https://github.com/hypercloud2017) +- Fix incorrect timezone in NAS & GTP ([#140](https://github.com/open5gs/open5gs/issues/140)) -- [EugeneBogush](https://github.com/EugeneBogush) #### Miscellaneous -- nas_message.py: Fix copy+paste error([#159](https://github.com/open5gs/nextepc/issues/159)) -- [laf0rge](https://github.com/laf0rge) -- Fix missing 'break' statement ([#129](https://github.com/open5gs/nextepc/pull/129)) -- [EugeneBogush](https://github.com/EugeneBogush) -- Add missing C namespace ([#109](https://github.com/open5gs/nextepc/pull/109)) -- [brchiu](https://github.com/brchiu) +- nas_message.py: Fix copy+paste error([#159](https://github.com/open5gs/open5gs/issues/159)) -- [laf0rge](https://github.com/laf0rge) +- Fix missing 'break' statement ([#129](https://github.com/open5gs/open5gs/pull/129)) -- [EugeneBogush](https://github.com/EugeneBogush) +- Add missing C namespace ([#109](https://github.com/open5gs/open5gs/pull/109)) -- [brchiu](https://github.com/brchiu) - Refine EXIT routine for daemon process -Download -- [v0.3.11.tar.gz](https://github.com/open5gs/nextepc/archive/v0.3.11.tar.gz) +Download -- [v0.3.11.tar.gz](https://github.com/open5gs/open5gs/archive/v0.3.11.tar.gz) {: .notice--info} diff --git a/docs/_posts/2019-04-29-release-v0.4.0.md b/docs/_posts/2019-04-29-release-v0.4.0.md index 04b719504..eab68c35f 100644 --- a/docs/_posts/2019-04-29-release-v0.4.0.md +++ b/docs/_posts/2019-04-29-release-v0.4.0.md @@ -11,10 +11,10 @@ head_inline: "" #### Enhancements - Integration with OGSLib -- High CPU usage on idle ([#87](https://github.com/open5gs/nextepc/issues/87)) -- [hchenji](https://github.com/hchenji) +- High CPU usage on idle ([#87](https://github.com/open5gs/open5gs/issues/87)) -- [hchenji](https://github.com/hchenji) #### Bug fixes -- The problem related to MNC of LENGTH 3 ([#163](https://github.com/open5gs/nextepc/issues/163)) -- [Avi-Dekra](https://github.com/Avi-Dekra) +- The problem related to MNC of LENGTH 3 ([#163](https://github.com/open5gs/open5gs/issues/163)) -- [Avi-Dekra](https://github.com/Avi-Dekra) -Download -- [v0.4.0.tar.gz](https://github.com/open5gs/nextepc/archive/v0.4.0.tar.gz) +Download -- [v0.4.0.tar.gz](https://github.com/open5gs/open5gs/archive/v0.4.0.tar.gz) {: .notice--info} diff --git a/docs/_posts/2019-05-18-release-v0.4.1.md b/docs/_posts/2019-05-18-release-v0.4.1.md index 0c443e232..bf7cd3726 100644 --- a/docs/_posts/2019-05-18-release-v0.4.1.md +++ b/docs/_posts/2019-05-18-release-v0.4.1.md @@ -10,15 +10,15 @@ head_inline: "" --- #### Minor changes -- Rearrange the initialization order [[2d74383](https://github.com/open5gs/nextepc/commit/2d7438313d7426ca3ad4591f090b7f8564257fb7)] -- Remove ____DATE____ and ____TIME____ from all source code to make the same binary. [[c8ed909](https://github.com/open5gs/nextepc/commit/c8ed909f4680225490ac23d2d56e7d8f8112d6f6)] -- Improve sanity checks when queues cannot be pushed [[bc180c3](https://github.com/open5gs/nextepc/commit/bc180c3ffc431a06a49e0de1af71098fd91d561b)] -- Update document to correct typo ([#176](https://github.com/open5gs/nextepc/issues/176)) -- [iman432](https://github.com/iman432) -- Add UE address to LOG ([#178](https://github.com/open5gs/nextepc/pull/178)) -- [medeiros405](https://github.com/medeiros405) +- Rearrange the initialization order [[2d74383](https://github.com/open5gs/open5gs/commit/2d7438313d7426ca3ad4591f090b7f8564257fb7)] +- Remove ____DATE____ and ____TIME____ from all source code to make the same binary. [[c8ed909](https://github.com/open5gs/open5gs/commit/c8ed909f4680225490ac23d2d56e7d8f8112d6f6)] +- Improve sanity checks when queues cannot be pushed [[bc180c3](https://github.com/open5gs/open5gs/commit/bc180c3ffc431a06a49e0de1af71098fd91d561b)] +- Update document to correct typo ([#176](https://github.com/open5gs/open5gs/issues/176)) -- [iman432](https://github.com/iman432) +- Add UE address to LOG ([#178](https://github.com/open5gs/open5gs/pull/178)) -- [medeiros405](https://github.com/medeiros405) #### Bug fixes -- Fix CentOS compilation errors and segmentation fault in test programs ([#175](https://github.com/open5gs/nextepc/issues/175)) -- [fefer](https://github.com/fefer) -- Modify the test program on MacOSX [ab81e38](https://github.com/open5gs/nextepc/commit/ab81e384879fdf51c667344fc8be912254dbec75) +- Fix CentOS compilation errors and segmentation fault in test programs ([#175](https://github.com/open5gs/open5gs/issues/175)) -- [fefer](https://github.com/fefer) +- Modify the test program on MacOSX [ab81e38](https://github.com/open5gs/open5gs/commit/ab81e384879fdf51c667344fc8be912254dbec75) -Download -- [v0.4.1.tar.gz](https://github.com/open5gs/nextepc/archive/v0.4.1.tar.gz) +Download -- [v0.4.1.tar.gz](https://github.com/open5gs/open5gs/archive/v0.4.1.tar.gz) {: .notice--info} diff --git a/docs/_posts/2019-05-28-release-v0.4.2.md b/docs/_posts/2019-05-28-release-v0.4.2.md index dd5ed3203..91d80bf55 100644 --- a/docs/_posts/2019-05-28-release-v0.4.2.md +++ b/docs/_posts/2019-05-28-release-v0.4.2.md @@ -10,11 +10,11 @@ head_inline: "" --- #### Enhancement -- Support a different APN for each PGW ([#183](https://github.com/open5gs/nextepc/issues/183)) -- Attach Reject for an invalid APN name ([#187](https://github.com/open5gs/nextepc/issues/187)) -- [ravens](https://github.com/ravens) +- Support a different APN for each PGW ([#183](https://github.com/open5gs/open5gs/issues/183)) +- Attach Reject for an invalid APN name ([#187](https://github.com/open5gs/open5gs/issues/187)) -- [ravens](https://github.com/ravens) #### Bug fixes -- Fix the PIDFile path of the systemd service ([#182](https://github.com/open5gs/nextepc/issues/182)) -- [smoein](https://github.com/smoein) +- Fix the PIDFile path of the systemd service ([#182](https://github.com/open5gs/open5gs/issues/182)) -- [smoein](https://github.com/smoein) -Download -- [v0.4.2.tar.gz](https://github.com/open5gs/nextepc/archive/v0.4.2.tar.gz) +Download -- [v0.4.2.tar.gz](https://github.com/open5gs/open5gs/archive/v0.4.2.tar.gz) {: .notice--info} diff --git a/docs/_posts/2019-06-22-release-v0.4.3.md b/docs/_posts/2019-06-22-release-v0.4.3.md index c83bc2baa..15239be9f 100644 --- a/docs/_posts/2019-06-22-release-v0.4.3.md +++ b/docs/_posts/2019-06-22-release-v0.4.3.md @@ -10,12 +10,12 @@ head_inline: "" --- #### Enhancement -- Adjust the size of memory pool for SGW buffering ([#190](https://github.com/open5gs/nextepc/issues/190)) -- [lezixiao](https://github.com/lezixiao) +- Adjust the size of memory pool for SGW buffering ([#190](https://github.com/open5gs/open5gs/issues/190)) -- [lezixiao](https://github.com/lezixiao) #### Bug fixes -- Enable SCTP_NODELAY and Fix the assertion ([#198](https://github.com/open5gs/nextepc/issues/198)) -- [lezixiao](https://github.com/lezixiao) -- Fix the assertion of handling a freeDiameter session ([#195](https://github.com/open5gs/nextepc/issues/195)) -- [lezixiao](https://github.com/lezixiao) -- Fix PGW coredump when GTP-U packet cannot find BEARER by TEID ([#194](https://github.com/open5gs/nextepc/issues/194)) -- [lezixiao](https://github.com/lezixiao) +- Enable SCTP_NODELAY and Fix the assertion ([#198](https://github.com/open5gs/open5gs/issues/198)) -- [lezixiao](https://github.com/lezixiao) +- Fix the assertion of handling a freeDiameter session ([#195](https://github.com/open5gs/open5gs/issues/195)) -- [lezixiao](https://github.com/lezixiao) +- Fix PGW coredump when GTP-U packet cannot find BEARER by TEID ([#194](https://github.com/open5gs/open5gs/issues/194)) -- [lezixiao](https://github.com/lezixiao) -Download -- [v0.4.3.tar.gz](https://github.com/open5gs/nextepc/archive/v0.4.3.tar.gz) +Download -- [v0.4.3.tar.gz](https://github.com/open5gs/open5gs/archive/v0.4.3.tar.gz) {: .notice--info} diff --git a/docs/_posts/2019-06-30-release-v0.4.4.md b/docs/_posts/2019-06-30-release-v0.4.4.md index 7afd3939a..825b4cdb1 100644 --- a/docs/_posts/2019-06-30-release-v0.4.4.md +++ b/docs/_posts/2019-06-30-release-v0.4.4.md @@ -10,13 +10,13 @@ head_inline: "" --- #### Bug fixes -- Move enb_ostream_id from mme_ue to enb_ue context ([#206](https://github.com/open5gs/nextepc/issues/206)) -- [lezixiao](https://github.com/lezixiao) -- Fix the MME crash EMM status following Initial Context Setup Response ([#205](https://github.com/open5gs/nextepc/issues/205)) -- [lezixiao](https://github.com/lezixiao) -- Fix the SGW crash for "Context Not Found" ([#204](https://github.com/open5gs/nextepc/issues/204)) -- [lezixiao](https://github.com/lezixiao) -- Fix the Multiple Attachment for same IMSI ([#203](https://github.com/open5gs/nextepc/issues/203)) -- [lezixiao](https://github.com/lezixiao) -- Add Handler of the Service Request and TAU Request in Security-mode state ([#202](https://github.com/open5gs/nextepc/issues/202)) -- [lezixiao](https://github.com/lezixiao) -- Fix Service reject handler ([#201](https://github.com/open5gs/nextepc/issues/201)) -- [lezixiao](https://github.com/lezixiao) -- Clear resources when SCTP-send failed ([#200](https://github.com/open5gs/nextepc/issues/200)) -- [lezixiao](https://github.com/lezixiao) +- Move enb_ostream_id from mme_ue to enb_ue context ([#206](https://github.com/open5gs/open5gs/issues/206)) -- [lezixiao](https://github.com/lezixiao) +- Fix the MME crash EMM status following Initial Context Setup Response ([#205](https://github.com/open5gs/open5gs/issues/205)) -- [lezixiao](https://github.com/lezixiao) +- Fix the SGW crash for "Context Not Found" ([#204](https://github.com/open5gs/open5gs/issues/204)) -- [lezixiao](https://github.com/lezixiao) +- Fix the Multiple Attachment for same IMSI ([#203](https://github.com/open5gs/open5gs/issues/203)) -- [lezixiao](https://github.com/lezixiao) +- Add Handler of the Service Request and TAU Request in Security-mode state ([#202](https://github.com/open5gs/open5gs/issues/202)) -- [lezixiao](https://github.com/lezixiao) +- Fix Service reject handler ([#201](https://github.com/open5gs/open5gs/issues/201)) -- [lezixiao](https://github.com/lezixiao) +- Clear resources when SCTP-send failed ([#200](https://github.com/open5gs/open5gs/issues/200)) -- [lezixiao](https://github.com/lezixiao) -Download -- [v0.4.4.tar.gz](https://github.com/open5gs/nextepc/archive/v0.4.4.tar.gz) +Download -- [v0.4.4.tar.gz](https://github.com/open5gs/open5gs/archive/v0.4.4.tar.gz) {: .notice--info} diff --git a/docs/_posts/2019-07-11-release-v0.5.0.md b/docs/_posts/2019-07-11-release-v0.5.0.md index 9d4284002..6ab7f3eaf 100644 --- a/docs/_posts/2019-07-11-release-v0.5.0.md +++ b/docs/_posts/2019-07-11-release-v0.5.0.md @@ -16,12 +16,12 @@ head_inline: "" - package naming doesn't follow usual package naming conventions ([OGSLIB-#1](https://github.com/open5gs/ogslib/issues/1)) -- [laf0rge](https://github.com/laf0rge) #### Standard Compliant -- Missing mandatory IE in GTPv2 ([#215](https://github.com/open5gs/nextepc/issues/215)) -- [tasai511](https://github.com/tasai511) +- Missing mandatory IE in GTPv2 ([#215](https://github.com/open5gs/open5gs/issues/215)) -- [tasai511](https://github.com/tasai511) #### Bug fixes -- Fix Security Command Reject ([#214](https://github.com/open5gs/nextepc/issues/214)) -- [lezixiao](https://github.com/lezixiao) -- docker-compose build fails, missing ogslib-dev ([#211](https://github.com/open5gs/nextepc/issues/211)) -- [mrlnc](https://github.com/mrlnc) -- freeDiameter: Fix compilation of SCTP_SEND_FAILED_EVENT ([#211](https://github.com/open5gs/nextepc/pull/211)) -- [laf0rge](https://github.com/laf0rge) +- Fix Security Command Reject ([#214](https://github.com/open5gs/open5gs/issues/214)) -- [lezixiao](https://github.com/lezixiao) +- docker-compose build fails, missing ogslib-dev ([#211](https://github.com/open5gs/open5gs/issues/211)) -- [mrlnc](https://github.com/mrlnc) +- freeDiameter: Fix compilation of SCTP_SEND_FAILED_EVENT ([#211](https://github.com/open5gs/open5gs/pull/211)) -- [laf0rge](https://github.com/laf0rge) -Download -- [v0.5.0.tar.gz](https://github.com/open5gs/nextepc/archive/v0.5.0.tar.gz) +Download -- [v0.5.0.tar.gz](https://github.com/open5gs/open5gs/archive/v0.5.0.tar.gz) {: .notice--info} diff --git a/docs/_posts/2019-07-30-release-v0.5.1.md b/docs/_posts/2019-07-30-release-v0.5.1.md index 7c20af6ff..7e22e383e 100644 --- a/docs/_posts/2019-07-30-release-v0.5.1.md +++ b/docs/_posts/2019-07-30-release-v0.5.1.md @@ -13,7 +13,7 @@ head_inline: "" - SMS over SG Support #### Solving the CS Fallback Issue -- CS Fallback Configuration Changes ([#224](https://github.com/open5gs/nextepc/issues/224), [#225](https://github.com/open5gs/nextepc/issues/225), [#231](https://github.com/open5gs/nextepc/issues/231)) -- [medeiros405](https://github.com/medeiros405) +- CS Fallback Configuration Changes ([#224](https://github.com/open5gs/open5gs/issues/224), [#225](https://github.com/open5gs/open5gs/issues/225), [#231](https://github.com/open5gs/open5gs/issues/231)) -- [medeiros405](https://github.com/medeiros405) 1. Single MSC/VLR(127.0.0.2) ``` @@ -99,24 +99,24 @@ head_inline: "" lac: 43693 ``` -- UEContextModifcationRequest does not have both CSFallbackIndicator and SecurityCapabilities ([#223](https://github.com/open5gs/nextepc/pull/223)) -- [medeiros405](https://github.com/medeiros405) -- NextEPC crash in MT-Fallback with fixing the BUG of ogs_realloc() ([ogslib:#4](https://github.com/open5gs/ogslib/issues/4)) +- UEContextModifcationRequest does not have both CSFallbackIndicator and SecurityCapabilities ([#223](https://github.com/open5gs/open5gs/pull/223)) -- [medeiros405](https://github.com/medeiros405) +- Open5GS crash in MT-Fallback with fixing the BUG of ogs_realloc() ([ogslib:#4](https://github.com/open5gs/ogslib/issues/4)) - Add Paging Reject #### Enhancements -- Fix Diameter spec-compliant related issue ([#240](https://github.com/open5gs/nextepc/pull/240)) -- [laf0rge](https://github.com/laf0rge) -- Prefer to use SCTP in Diameter ([#235](https://github.com/open5gs/nextepc/pull/235)) -- [laf0rge](https://github.com/laf0rge) -- Set Diameter SCTP PPID to 46 ([#234](https://github.com/open5gs/nextepc/issues/234)) -- [laf0rge](https://github.com/laf0rge) -- MME protects SecurityModeComplete that is not integrity ([#226](https://github.com/open5gs/nextepc/issues/226)) -- [laf0rge](https://github.com/laf0rge) -- Add Guard timer in EMM state machine ([#220](https://github.com/open5gs/nextepc/pull/220)) -- [laf0rge](https://github.com/laf0rge) -- mme-kdf: Ensure input arguments(kasme, ..) are read-only and 'const' ([#230](https://github.com/open5gs/nextepc/pull/230)) -- [laf0rge](https://github.com/laf0rge) +- Fix Diameter spec-compliant related issue ([#240](https://github.com/open5gs/open5gs/pull/240)) -- [laf0rge](https://github.com/laf0rge) +- Prefer to use SCTP in Diameter ([#235](https://github.com/open5gs/open5gs/pull/235)) -- [laf0rge](https://github.com/laf0rge) +- Set Diameter SCTP PPID to 46 ([#234](https://github.com/open5gs/open5gs/issues/234)) -- [laf0rge](https://github.com/laf0rge) +- MME protects SecurityModeComplete that is not integrity ([#226](https://github.com/open5gs/open5gs/issues/226)) -- [laf0rge](https://github.com/laf0rge) +- Add Guard timer in EMM state machine ([#220](https://github.com/open5gs/open5gs/pull/220)) -- [laf0rge](https://github.com/laf0rge) +- mme-kdf: Ensure input arguments(kasme, ..) are read-only and 'const' ([#230](https://github.com/open5gs/open5gs/pull/230)) -- [laf0rge](https://github.com/laf0rge) #### Bug fixes -- Fix the problem of releasing Dedicated Bearer ([#180](https://github.com/open5gs/nextepc/issues/180)) -- [lezixiao](https://github.com/lezixiao) -- Fix the MME crash if UE indicates only EIA0 ([#222](https://github.com/open5gs/nextepc/pull/222)) -- [laf0rge](https://github.com/laf0rge) -- Sending ErrorIndication if S1AP decoding is failed ([#218](https://github.com/open5gs/nextepc/pull/218), [#219](https://github.com/open5gs/nextepc/pull/219)) -- [laf0rge](https://github.com/laf0rge) +- Fix the problem of releasing Dedicated Bearer ([#180](https://github.com/open5gs/open5gs/issues/180)) -- [lezixiao](https://github.com/lezixiao) +- Fix the MME crash if UE indicates only EIA0 ([#222](https://github.com/open5gs/open5gs/pull/222)) -- [laf0rge](https://github.com/laf0rge) +- Sending ErrorIndication if S1AP decoding is failed ([#218](https://github.com/open5gs/open5gs/pull/218), [#219](https://github.com/open5gs/open5gs/pull/219)) -- [laf0rge](https://github.com/laf0rge) -Download -- [v0.5.1.tar.gz](https://github.com/open5gs/nextepc/archive/v0.5.1.tar.gz) +Download -- [v0.5.1.tar.gz](https://github.com/open5gs/open5gs/archive/v0.5.1.tar.gz) {: .notice--info} diff --git a/docs/_posts/2019-08-11-release-v0.5.2.md b/docs/_posts/2019-08-11-release-v0.5.2.md index 970fda864..808b5522c 100644 --- a/docs/_posts/2019-08-11-release-v0.5.2.md +++ b/docs/_posts/2019-08-11-release-v0.5.2.md @@ -13,7 +13,7 @@ head_inline: "" - Support Ubuntu 19.04(Disco Dingo) #### Enhancements -- Add Configuration Memory Pool Size ([#245](https://github.com/open5gs/nextepc/issues/245)) -- [lezixiao](https://github.com/lezixiao) +- Add Configuration Memory Pool Size ([#245](https://github.com/open5gs/open5gs/issues/245)) -- [lezixiao](https://github.com/lezixiao) ``` pool: @@ -44,9 +44,9 @@ head_inline: "" ``` #### Bug fixes -- Fix freeDiameter build fail for bison+flex ([#243](https://github.com/open5gs/nextepc/issues/243)) -- [laf0rge](https://github.com/laf0rge) -- Increase Protocol Configuration Options(PCO) to 16 ([#241](https://github.com/open5gs/nextepc/issues/241)) -- [medeiros405](https://github.com/medeiros405) +- Fix freeDiameter build fail for bison+flex ([#243](https://github.com/open5gs/open5gs/issues/243)) -- [laf0rge](https://github.com/laf0rge) +- Increase Protocol Configuration Options(PCO) to 16 ([#241](https://github.com/open5gs/open5gs/issues/241)) -- [medeiros405](https://github.com/medeiros405) -Download -- [v0.5.2.tar.gz](https://github.com/open5gs/nextepc/archive/v0.5.2.tar.gz) +Download -- [v0.5.2.tar.gz](https://github.com/open5gs/open5gs/archive/v0.5.2.tar.gz) {: .notice--info} diff --git a/docs/_posts/2019-10-27-release-v1.0.0.md b/docs/_posts/2019-10-27-release-v1.0.0.md new file mode 100644 index 000000000..7c638e837 --- /dev/null +++ b/docs/_posts/2019-10-27-release-v1.0.0.md @@ -0,0 +1,51 @@ +--- +title: "v1.0.0 - Rename Project to Open5GS" +date: 2019-10-27 16:55:00 +0900 +categories: + - Release +tags: + - News + - Release +head_inline: "" +--- + +#### New Project +- Rename Project to Open5GS v1.0.0 + +#### New Package +- Support Ubuntu 19.10(Eoan Ermine) + +#### New Build +- Change BuildTool to Meson(autotools removed) + + +Install Meson using Python. +``` +$ sudo apt install python3-pip python3-setuptools ninja-build +$ pip3 install --user meson +``` + +To compile with meson: +```bash +$ cd open5gs +$ meson build --prefix=`pwd`/install +$ ninja -C build +``` + +Check whether the compilation is correct. +```bash +$ ninja -C build test +``` + +You need to perform the **installation process**. +```bash +$ cd build +$ ninja install +``` + +#### Bug fixes +- Add memset() after ogs_pool_alloc() in mme/sgw/pgw-context.c ([#267](https://github.com/open5gs/open5gs/issues/267), [#268](https://github.com/open5gs/open5gs/issues/268)) -- [laf0rge](https://github.com/laf0rge) +- Do not overwrites configuration files for `ninja install` ([#252](https://github.com/open5gs/open5gs/issues/252)) -- [laf0rge](https://github.com/laf0rge) + +Download -- [v1.0.0.tar.gz](https://github.com/open5gs/open5gs/archive/v1.0.0.tar.gz) +{: .notice--info} diff --git a/docs/assets/webui/install b/docs/assets/webui/install index 47dd390c5..16fd2c65f 100644 --- a/docs/assets/webui/install +++ b/docs/assets/webui/install @@ -4,13 +4,13 @@ # # Run as root or insert `sudo -E` before `bash`: # -# curl -sL http://nextepc.org/static/setup_3.x | bash - +# curl -sL http://open5gs.org/static/setup_3.x | bash - # or -# wget -qO- http://nextepc.org/static/setup_3.x | bash - +# wget -qO- http://open5gs.org/static/setup_3.x | bash - # -PACKAGE="nextepc" -VERSION="0.5.1" +PACKAGE="open5gs" +VERSION="1.0.0" print_status() { echo @@ -68,8 +68,8 @@ exec_cmd() { } uninstall() { -exec_cmd_nobail "deb-systemd-invoke stop nextepc-webui" -exec_cmd_nobail "systemctl disable nextepc-webui" +exec_cmd_nobail "deb-systemd-invoke stop open5gs-webui" +exec_cmd_nobail "systemctl disable open5gs-webui" exec_cmd_nobail "rm -f /lib/systemd/system/${PACKAGE}-webui.service" exec_cmd_nobail "systemctl daemon-reload" @@ -105,7 +105,7 @@ fi uninstall -print_status "Download the NextEPC Source Code (v${VERSION})..." +print_status "Download the Open5GS Source Code (v${VERSION})..." if [ -x /usr/bin/curl ]; then exec_cmd "curl -sLf 'https://github.com/acetcom/${PACKAGE}/archive/v${VERSION}.tar.gz' | tar zxf -" RC=$? @@ -114,23 +114,23 @@ else RC=$? fi -print_status "Build the NextEPC WebUI..." +print_status "Build the Open5GS WebUI..." exec_cmd "cd ./${PACKAGE}-${VERSION}/webui && npm install && npm run build" -print_status "Install the NextEPC WebUI..." +print_status "Install the Open5GS WebUI..." exec_cmd "mv ./${PACKAGE}-${VERSION}/webui /usr/lib/node_modules/${PACKAGE}" -exec_cmd_nobail "chown -R nextepc:nextepc /usr/lib/node_modules/${PACKAGE}" +exec_cmd_nobail "chown -R open5gs:open5gs /usr/lib/node_modules/${PACKAGE}" -exec_cmd "cat << EOF > /lib/systemd/system/nextepc-webui.service +exec_cmd "cat << EOF > /lib/systemd/system/open5gs-webui.service [Unit] -Description=NextEPC WebUI +Description=Open5GS WebUI BindTo=mongodb.service After=networking.service mongodb.service [Service] Type=simple -WorkingDirectory=/usr/lib/node_modules/nextepc +WorkingDirectory=/usr/lib/node_modules/open5gs Environment=NODE_ENV=production ExecStart=/usr/bin/node server/index.js Restart=always @@ -141,8 +141,8 @@ WantedBy=multi-user.target EOF" exec_cmd_nobail "systemctl daemon-reload" -exec_cmd "systemctl enable nextepc-webui" -exec_cmd "deb-systemd-invoke start nextepc-webui" +exec_cmd "systemctl enable open5gs-webui" +exec_cmd "deb-systemd-invoke start open5gs-webui" exec_cmd "rm -rf ./${PACKAGE}-${VERSION}" } diff --git a/docs/assets/webui/uninstall b/docs/assets/webui/uninstall index 127c902ae..4897c362c 100644 --- a/docs/assets/webui/uninstall +++ b/docs/assets/webui/uninstall @@ -4,9 +4,9 @@ # # Run as root or insert `sudo -E` before `bash`: # -# curl -sL http://nextepc.org/static/uninstall_webui.sh | bash - +# curl -sL http://open5gs.org/static/uninstall_webui.sh | bash - # or -# wget -qO- http://nextepc.org/static/uninstall_webui.shx | bash - +# wget -qO- http://open5gs.org/static/uninstall_webui.shx | bash - # exec_cmd_nobail() { @@ -15,10 +15,10 @@ exec_cmd_nobail() { } uninstall() { -exec_cmd_nobail "deb-systemd-invoke stop nextepc-webui" -exec_cmd_nobail "systemctl disable nextepc-webui" -exec_cmd_nobail "rm -f /lib/systemd/system/nextepc-webui.service" -exec_cmd_nobail "rm -rf /usr/lib/node_modules/nextepc" +exec_cmd_nobail "deb-systemd-invoke stop open5gs-webui" +exec_cmd_nobail "systemctl disable open5gs-webui" +exec_cmd_nobail "rm -f /lib/systemd/system/open5gs-webui.service" +exec_cmd_nobail "rm -rf /usr/lib/node_modules/open5gs" exec_cmd_nobail "systemctl daemon-reload" } diff --git a/lib/Makefile.am b/lib/Makefile.am deleted file mode 100644 index e9a774018..000000000 --- a/lib/Makefile.am +++ /dev/null @@ -1,9 +0,0 @@ -## Process this file with automake to produce Makefile.in - -SUBDIRS = freeDiameter - -if WITH_SRCLIB -SUBDIRS += ogslib -endif - -SUBDIRS += asn1c s1ap nas diameter gtp dbi sctp app diff --git a/lib/app/Makefile.am b/lib/app/Makefile.am deleted file mode 100644 index 78317ab1e..000000000 --- a/lib/app/Makefile.am +++ /dev/null @@ -1,28 +0,0 @@ -## Process this file with automake to produce Makefile.in. - -pkglib_LTLIBRARIES = libogsapp.la - -libogsapp_la_SOURCES = \ - ogs-yaml.h ogs-yaml.c \ - ogs-config.h ogs-config.c \ - ogs-init.h ogs-init.c \ - $(NULL) - -libogsapp_la_LIBADD = \ - @OGSCORE_LIBS@ \ - @YAML_LIBS@ \ - $(NULL) - -libogsapp_la_DEPENDENCIES = \ - $(NULL) - -AM_CPPFLAGS = \ - @OGSCORE_CFLAGS@ \ - @YAML_CFLAGS@ \ - -I$(top_srcdir)/lib \ - $(NULL) - -AM_CFLAGS = \ - -DOGS_APP_COMPILATION \ - -Wall -Werror \ - $(NULL) diff --git a/lib/app/meson.build b/lib/app/meson.build new file mode 100644 index 000000000..7ddf60b06 --- /dev/null +++ b/lib/app/meson.build @@ -0,0 +1,46 @@ +# Copyright (C) 2019 by Sukchan Lee + +# This file is part of Open5GS. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +libapp_sources = files(''' + ogs-app.h + + ogs-yaml.h + ogs-config.h + ogs-init.h + + ogs-yaml.c + ogs-config.c + ogs-init.c +'''.split()) + +yaml_dep = dependency('yaml-0.1') + +libapp_inc = include_directories('.') + +libapp = library('ogsapp', + sources : libapp_sources, + version : libogslib_version, + c_args : '-DOGS_APP_COMPILATION', + include_directories : [libapp_inc, libinc], + dependencies : [libcore_dep, yaml_dep], + install : true) + +libapp_dep = declare_dependency( + link_with : libapp, + include_directories : [libapp_inc, libinc], + dependencies : [libcore_dep, yaml_dep], +) diff --git a/lib/ogs-app.h b/lib/app/ogs-app.h similarity index 76% rename from lib/ogs-app.h rename to lib/app/ogs-app.h index a0cf7ee53..06b082140 100644 --- a/lib/ogs-app.h +++ b/lib/app/ogs-app.h @@ -20,15 +20,12 @@ #ifndef OGS_APP_H #define OGS_APP_H -#include "ogs-common.h" +#include "ogs-core.h" #define OGS_APP_INSIDE extern int __ogs_app_domain; -#undef OGS_LOG_DOMAIN -#define OGS_LOG_DOMAIN __ogs_app_domain - #include "app/ogs-yaml.h" #include "app/ogs-config.h" #include "app/ogs-init.h" @@ -42,28 +39,22 @@ extern int __ogs_app_domain; extern "C" { #endif -#define OGS_MAX_FILEPATH_LEN 256 - -/* For testing */ -void epc_child_terminate(void); -ogs_thread_t *epc_child_create(char *name, char **argv); - -int app_initialize(char **argv); +int app_initialize(const char *const argv[]); void app_terminate(void); -int mme_initialize(); +int mme_initialize(void); void mme_terminate(void); -int hss_initialize(); +int hss_initialize(void); void hss_terminate(void); -int sgw_initialize(); +int sgw_initialize(void); void sgw_terminate(void); -int pgw_initialize(); +int pgw_initialize(void); void pgw_terminate(void); -int pcrf_initialize(); +int pcrf_initialize(void); void pcrf_terminate(void); #ifdef __cplusplus diff --git a/lib/app/ogs-config.c b/lib/app/ogs-config.c index 309697e2f..db0ad9609 100644 --- a/lib/app/ogs-config.c +++ b/lib/app/ogs-config.c @@ -65,7 +65,7 @@ int ogs_config_read() file = fopen(config->file, "rb"); if (!file) { ogs_fatal("cannot open file `%s`", config->file); - ogs_assert_if_reached(); + return OGS_ERROR; } ogs_assert(yaml_parser_initialize(&parser)); @@ -132,7 +132,7 @@ int ogs_config_read() return OGS_OK; } -static void recalculate_pool_size() +static void recalculate_pool_size(void) { #define MAX_NUM_OF_BEARER 4 /* Num of Bearer per APN(Session) */ #define MAX_NUM_OF_TUNNEL 3 /* Num of Tunnel per Bearer */ @@ -145,7 +145,7 @@ static void recalculate_pool_size() self.pool.pf = self.pool.bearer * MAX_NUM_OF_PF; } -static int config_prepare() +static int config_prepare(void) { #define USRSCTP_LOCAL_UDP_PORT 9899 self.usrsctp.udp_port = USRSCTP_LOCAL_UDP_PORT; @@ -173,7 +173,7 @@ static int config_prepare() return OGS_OK; } -static int ogs_app_ctx_validation() +static int ogs_app_ctx_validation(void) { if (self.parameter.no_ipv4 == 1 && self.parameter.no_ipv6 == 1) { diff --git a/lib/app/ogs-init.c b/lib/app/ogs-init.c index f8ca3ecaa..169bed9b1 100644 --- a/lib/app/ogs-init.c +++ b/lib/app/ogs-init.c @@ -21,7 +21,7 @@ int __ogs_app_domain; -int ogs_app_initialize(char *default_config, char **argv) +int ogs_app_initialize(const char *default_config, const char *const argv[]) { int rv, opt; ogs_getopt_t options; @@ -45,7 +45,7 @@ int ogs_app_initialize(char *default_config, char **argv) */ memset(&optarg, 0, sizeof(optarg)); - ogs_getopt_init(&options, argv); + ogs_getopt_init(&options, (char**)argv); while ((opt = ogs_getopt(&options, "c:l:e:m:")) != -1) { switch (opt) { case 'c': diff --git a/lib/app/ogs-init.h b/lib/app/ogs-init.h index 8d509b13b..3c6222938 100644 --- a/lib/app/ogs-init.h +++ b/lib/app/ogs-init.h @@ -28,7 +28,7 @@ extern "C" { #endif /* __cplusplus */ -int ogs_app_initialize(char *default_config, char **argv); +int ogs_app_initialize(const char *default_config, const char *const argv[]); void ogs_app_terminate(void); void ogs_app_setup_log(void); diff --git a/lib/asn1c/Makefile.am b/lib/asn1c/Makefile.am deleted file mode 100644 index f9aad99c6..000000000 --- a/lib/asn1c/Makefile.am +++ /dev/null @@ -1,1154 +0,0 @@ -ASN_MODULE_SRCS= \ - s1ap/S1AP_S1AP-PDU.c \ - s1ap/S1AP_InitiatingMessage.c \ - s1ap/S1AP_SuccessfulOutcome.c \ - s1ap/S1AP_UnsuccessfulOutcome.c \ - s1ap/S1AP_E-RAB-IE-ContainerList.c \ - s1ap/S1AP_HandoverRequired.c \ - s1ap/S1AP_HandoverCommand.c \ - s1ap/S1AP_E-RABSubjecttoDataForwardingList.c \ - s1ap/S1AP_E-RABDataForwardingItem.c \ - s1ap/S1AP_HandoverPreparationFailure.c \ - s1ap/S1AP_HandoverRequest.c \ - s1ap/S1AP_E-RABToBeSetupListHOReq.c \ - s1ap/S1AP_E-RABToBeSetupItemHOReq.c \ - s1ap/S1AP_HandoverRequestAcknowledge.c \ - s1ap/S1AP_E-RABAdmittedList.c \ - s1ap/S1AP_E-RABAdmittedItem.c \ - s1ap/S1AP_E-RABFailedtoSetupListHOReqAck.c \ - s1ap/S1AP_E-RABFailedToSetupItemHOReqAck.c \ - s1ap/S1AP_HandoverFailure.c \ - s1ap/S1AP_HandoverNotify.c \ - s1ap/S1AP_PathSwitchRequest.c \ - s1ap/S1AP_E-RABToBeSwitchedDLList.c \ - s1ap/S1AP_E-RABToBeSwitchedDLItem.c \ - s1ap/S1AP_PathSwitchRequestAcknowledge.c \ - s1ap/S1AP_E-RABToBeSwitchedULList.c \ - s1ap/S1AP_E-RABToBeSwitchedULItem.c \ - s1ap/S1AP_PathSwitchRequestFailure.c \ - s1ap/S1AP_HandoverCancel.c \ - s1ap/S1AP_HandoverCancelAcknowledge.c \ - s1ap/S1AP_E-RABSetupRequest.c \ - s1ap/S1AP_E-RABToBeSetupListBearerSUReq.c \ - s1ap/S1AP_E-RABToBeSetupItemBearerSUReq.c \ - s1ap/S1AP_E-RABSetupResponse.c \ - s1ap/S1AP_E-RABSetupListBearerSURes.c \ - s1ap/S1AP_E-RABSetupItemBearerSURes.c \ - s1ap/S1AP_E-RABModifyRequest.c \ - s1ap/S1AP_E-RABToBeModifiedListBearerModReq.c \ - s1ap/S1AP_E-RABToBeModifiedItemBearerModReq.c \ - s1ap/S1AP_E-RABModifyResponse.c \ - s1ap/S1AP_E-RABModifyListBearerModRes.c \ - s1ap/S1AP_E-RABModifyItemBearerModRes.c \ - s1ap/S1AP_E-RABReleaseCommand.c \ - s1ap/S1AP_E-RABReleaseResponse.c \ - s1ap/S1AP_E-RABReleaseListBearerRelComp.c \ - s1ap/S1AP_E-RABReleaseItemBearerRelComp.c \ - s1ap/S1AP_E-RABReleaseIndication.c \ - s1ap/S1AP_InitialContextSetupRequest.c \ - s1ap/S1AP_E-RABToBeSetupListCtxtSUReq.c \ - s1ap/S1AP_E-RABToBeSetupItemCtxtSUReq.c \ - s1ap/S1AP_InitialContextSetupResponse.c \ - s1ap/S1AP_E-RABSetupListCtxtSURes.c \ - s1ap/S1AP_E-RABSetupItemCtxtSURes.c \ - s1ap/S1AP_InitialContextSetupFailure.c \ - s1ap/S1AP_Paging.c \ - s1ap/S1AP_TAIList.c \ - s1ap/S1AP_TAIItem.c \ - s1ap/S1AP_UEContextReleaseRequest.c \ - s1ap/S1AP_UEContextReleaseCommand.c \ - s1ap/S1AP_UEContextReleaseComplete.c \ - s1ap/S1AP_UEContextModificationRequest.c \ - s1ap/S1AP_UEContextModificationResponse.c \ - s1ap/S1AP_UEContextModificationFailure.c \ - s1ap/S1AP_UERadioCapabilityMatchRequest.c \ - s1ap/S1AP_UERadioCapabilityMatchResponse.c \ - s1ap/S1AP_DownlinkNASTransport.c \ - s1ap/S1AP_InitialUEMessage.c \ - s1ap/S1AP_UplinkNASTransport.c \ - s1ap/S1AP_NASNonDeliveryIndication.c \ - s1ap/S1AP_RerouteNASRequest.c \ - s1ap/S1AP_NASDeliveryIndication.c \ - s1ap/S1AP_Reset.c \ - s1ap/S1AP_ResetType.c \ - s1ap/S1AP_ResetAll.c \ - s1ap/S1AP_UE-associatedLogicalS1-ConnectionListRes.c \ - s1ap/S1AP_ResetAcknowledge.c \ - s1ap/S1AP_UE-associatedLogicalS1-ConnectionListResAck.c \ - s1ap/S1AP_ErrorIndication.c \ - s1ap/S1AP_S1SetupRequest.c \ - s1ap/S1AP_S1SetupResponse.c \ - s1ap/S1AP_S1SetupFailure.c \ - s1ap/S1AP_ENBConfigurationUpdate.c \ - s1ap/S1AP_ENBConfigurationUpdateAcknowledge.c \ - s1ap/S1AP_ENBConfigurationUpdateFailure.c \ - s1ap/S1AP_MMEConfigurationUpdate.c \ - s1ap/S1AP_MMEConfigurationUpdateAcknowledge.c \ - s1ap/S1AP_MMEConfigurationUpdateFailure.c \ - s1ap/S1AP_DownlinkS1cdma2000tunnelling.c \ - s1ap/S1AP_UplinkS1cdma2000tunnelling.c \ - s1ap/S1AP_UECapabilityInfoIndication.c \ - s1ap/S1AP_ENBStatusTransfer.c \ - s1ap/S1AP_MMEStatusTransfer.c \ - s1ap/S1AP_TraceStart.c \ - s1ap/S1AP_TraceFailureIndication.c \ - s1ap/S1AP_DeactivateTrace.c \ - s1ap/S1AP_CellTrafficTrace.c \ - s1ap/S1AP_LocationReportingControl.c \ - s1ap/S1AP_LocationReportingFailureIndication.c \ - s1ap/S1AP_LocationReport.c \ - s1ap/S1AP_OverloadStart.c \ - s1ap/S1AP_OverloadStop.c \ - s1ap/S1AP_WriteReplaceWarningRequest.c \ - s1ap/S1AP_WriteReplaceWarningResponse.c \ - s1ap/S1AP_ENBDirectInformationTransfer.c \ - s1ap/S1AP_Inter-SystemInformationTransferType.c \ - s1ap/S1AP_MMEDirectInformationTransfer.c \ - s1ap/S1AP_ENBConfigurationTransfer.c \ - s1ap/S1AP_MMEConfigurationTransfer.c \ - s1ap/S1AP_PrivateMessage.c \ - s1ap/S1AP_KillRequest.c \ - s1ap/S1AP_KillResponse.c \ - s1ap/S1AP_PWSRestartIndication.c \ - s1ap/S1AP_PWSFailureIndication.c \ - s1ap/S1AP_DownlinkUEAssociatedLPPaTransport.c \ - s1ap/S1AP_UplinkUEAssociatedLPPaTransport.c \ - s1ap/S1AP_DownlinkNonUEAssociatedLPPaTransport.c \ - s1ap/S1AP_UplinkNonUEAssociatedLPPaTransport.c \ - s1ap/S1AP_E-RABModificationIndication.c \ - s1ap/S1AP_E-RABToBeModifiedListBearerModInd.c \ - s1ap/S1AP_E-RABToBeModifiedItemBearerModInd.c \ - s1ap/S1AP_E-RABNotToBeModifiedListBearerModInd.c \ - s1ap/S1AP_E-RABNotToBeModifiedItemBearerModInd.c \ - s1ap/S1AP_CSGMembershipInfo.c \ - s1ap/S1AP_E-RABModificationConfirm.c \ - s1ap/S1AP_E-RABModifyListBearerModConf.c \ - s1ap/S1AP_E-RABModifyItemBearerModConf.c \ - s1ap/S1AP_UEContextModificationIndication.c \ - s1ap/S1AP_UEContextModificationConfirm.c \ - s1ap/S1AP_UEContextSuspendRequest.c \ - s1ap/S1AP_UEContextSuspendResponse.c \ - s1ap/S1AP_UEContextResumeRequest.c \ - s1ap/S1AP_E-RABFailedToResumeListResumeReq.c \ - s1ap/S1AP_E-RABFailedToResumeItemResumeReq.c \ - s1ap/S1AP_UEContextResumeResponse.c \ - s1ap/S1AP_E-RABFailedToResumeListResumeRes.c \ - s1ap/S1AP_E-RABFailedToResumeItemResumeRes.c \ - s1ap/S1AP_UEContextResumeFailure.c \ - s1ap/S1AP_ConnectionEstablishmentIndication.c \ - s1ap/S1AP_RetrieveUEInformation.c \ - s1ap/S1AP_UEInformationTransfer.c \ - s1ap/S1AP_ENBCPRelocationIndication.c \ - s1ap/S1AP_MMECPRelocationIndication.c \ - s1ap/S1AP_Additional-GUTI.c \ - s1ap/S1AP_AreaScopeOfMDT.c \ - s1ap/S1AP_AllocationAndRetentionPriority.c \ - s1ap/S1AP_AssistanceDataForCECapableUEs.c \ - s1ap/S1AP_AssistanceDataForPaging.c \ - s1ap/S1AP_AssistanceDataForRecommendedCells.c \ - s1ap/S1AP_Bearers-SubjectToStatusTransferList.c \ - s1ap/S1AP_Bearers-SubjectToStatusTransfer-Item.c \ - s1ap/S1AP_BearerType.c \ - s1ap/S1AP_BitRate.c \ - s1ap/S1AP_BPLMNs.c \ - s1ap/S1AP_BroadcastCancelledAreaList.c \ - s1ap/S1AP_BroadcastCompletedAreaList.c \ - s1ap/S1AP_CancelledCellinEAI.c \ - s1ap/S1AP_CancelledCellinEAI-Item.c \ - s1ap/S1AP_CancelledCellinTAI.c \ - s1ap/S1AP_CancelledCellinTAI-Item.c \ - s1ap/S1AP_Cause.c \ - s1ap/S1AP_CauseMisc.c \ - s1ap/S1AP_CauseProtocol.c \ - s1ap/S1AP_CauseRadioNetwork.c \ - s1ap/S1AP_CauseTransport.c \ - s1ap/S1AP_CauseNas.c \ - s1ap/S1AP_CellAccessMode.c \ - s1ap/S1AP_CellIdentifierAndCELevelForCECapableUEs.c \ - s1ap/S1AP_CELevel.c \ - s1ap/S1AP_CE-mode-B-SupportIndicator.c \ - s1ap/S1AP_CellIdentity.c \ - s1ap/S1AP_CellID-Broadcast.c \ - s1ap/S1AP_CellID-Broadcast-Item.c \ - s1ap/S1AP_CellID-Cancelled.c \ - s1ap/S1AP_CellID-Cancelled-Item.c \ - s1ap/S1AP_CellBasedMDT.c \ - s1ap/S1AP_CellIdListforMDT.c \ - s1ap/S1AP_Cdma2000PDU.c \ - s1ap/S1AP_Cdma2000RATType.c \ - s1ap/S1AP_Cdma2000SectorID.c \ - s1ap/S1AP_Cdma2000HOStatus.c \ - s1ap/S1AP_Cdma2000HORequiredIndication.c \ - s1ap/S1AP_Cdma2000OneXSRVCCInfo.c \ - s1ap/S1AP_Cdma2000OneXMEID.c \ - s1ap/S1AP_Cdma2000OneXMSI.c \ - s1ap/S1AP_Cdma2000OneXPilot.c \ - s1ap/S1AP_Cdma2000OneXRAND.c \ - s1ap/S1AP_Cell-Size.c \ - s1ap/S1AP_CellType.c \ - s1ap/S1AP_CGI.c \ - s1ap/S1AP_CI.c \ - s1ap/S1AP_CNDomain.c \ - s1ap/S1AP_ConcurrentWarningMessageIndicator.c \ - s1ap/S1AP_Correlation-ID.c \ - s1ap/S1AP_CSFallbackIndicator.c \ - s1ap/S1AP_AdditionalCSFallbackIndicator.c \ - s1ap/S1AP_CSG-Id.c \ - s1ap/S1AP_CSG-IdList.c \ - s1ap/S1AP_CSG-IdList-Item.c \ - s1ap/S1AP_CSGMembershipStatus.c \ - s1ap/S1AP_COUNTvalue.c \ - s1ap/S1AP_COUNTValueExtended.c \ - s1ap/S1AP_COUNTvaluePDCP-SNlength18.c \ - s1ap/S1AP_Coverage-Level.c \ - s1ap/S1AP_CriticalityDiagnostics.c \ - s1ap/S1AP_CriticalityDiagnostics-IE-List.c \ - s1ap/S1AP_CriticalityDiagnostics-IE-Item.c \ - s1ap/S1AP_DataCodingScheme.c \ - s1ap/S1AP_DCN-ID.c \ - s1ap/S1AP_ServedDCNs.c \ - s1ap/S1AP_ServedDCNsItem.c \ - s1ap/S1AP_DL-CP-SecurityInformation.c \ - s1ap/S1AP_DL-Forwarding.c \ - s1ap/S1AP_DL-NAS-MAC.c \ - s1ap/S1AP_Direct-Forwarding-Path-Availability.c \ - s1ap/S1AP_Data-Forwarding-Not-Possible.c \ - s1ap/S1AP_DLNASPDUDeliveryAckRequest.c \ - s1ap/S1AP_EARFCN.c \ - s1ap/S1AP_ECGIList.c \ - s1ap/S1AP_PWSfailedECGIList.c \ - s1ap/S1AP_EmergencyAreaIDList.c \ - s1ap/S1AP_EmergencyAreaID.c \ - s1ap/S1AP_EmergencyAreaID-Broadcast.c \ - s1ap/S1AP_EmergencyAreaID-Broadcast-Item.c \ - s1ap/S1AP_EmergencyAreaID-Cancelled.c \ - s1ap/S1AP_EmergencyAreaID-Cancelled-Item.c \ - s1ap/S1AP_CompletedCellinEAI.c \ - s1ap/S1AP_CompletedCellinEAI-Item.c \ - s1ap/S1AP_ECGI-List.c \ - s1ap/S1AP_EmergencyAreaIDListForRestart.c \ - s1ap/S1AP_ENB-ID.c \ - s1ap/S1AP_GERAN-Cell-ID.c \ - s1ap/S1AP_Global-ENB-ID.c \ - s1ap/S1AP_GUMMEIList.c \ - s1ap/S1AP_ENB-StatusTransfer-TransparentContainer.c \ - s1ap/S1AP_ENB-UE-S1AP-ID.c \ - s1ap/S1AP_ENBname.c \ - s1ap/S1AP_ENBX2TLAs.c \ - s1ap/S1AP_EncryptionAlgorithms.c \ - s1ap/S1AP_EnhancedCoverageRestricted.c \ - s1ap/S1AP_EPLMNs.c \ - s1ap/S1AP_EventType.c \ - s1ap/S1AP_E-RAB-ID.c \ - s1ap/S1AP_E-RABInformationList.c \ - s1ap/S1AP_E-RABInformationListItem.c \ - s1ap/S1AP_E-RABList.c \ - s1ap/S1AP_E-RABItem.c \ - s1ap/S1AP_E-RABLevelQoSParameters.c \ - s1ap/S1AP_EUTRAN-CGI.c \ - s1ap/S1AP_EUTRANRoundTripDelayEstimationInfo.c \ - s1ap/S1AP_ExpectedUEBehaviour.c \ - s1ap/S1AP_ExpectedUEActivityBehaviour.c \ - s1ap/S1AP_ExpectedActivityPeriod.c \ - s1ap/S1AP_ExpectedIdlePeriod.c \ - s1ap/S1AP_SourceOfUEActivityBehaviourInformation.c \ - s1ap/S1AP_ExpectedHOInterval.c \ - s1ap/S1AP_ExtendedRNC-ID.c \ - s1ap/S1AP_ExtendedRepetitionPeriod.c \ - s1ap/S1AP_Extended-UEIdentityIndexValue.c \ - s1ap/S1AP_ForbiddenInterRATs.c \ - s1ap/S1AP_ForbiddenTAs.c \ - s1ap/S1AP_ForbiddenTAs-Item.c \ - s1ap/S1AP_ForbiddenTACs.c \ - s1ap/S1AP_ForbiddenLAs.c \ - s1ap/S1AP_ForbiddenLAs-Item.c \ - s1ap/S1AP_ForbiddenLACs.c \ - s1ap/S1AP_GBR-QosInformation.c \ - s1ap/S1AP_GTP-TEID.c \ - s1ap/S1AP_GUMMEI.c \ - s1ap/S1AP_GUMMEIType.c \ - s1ap/S1AP_GWContextReleaseIndication.c \ - s1ap/S1AP_HandoverRestrictionList.c \ - s1ap/S1AP_HandoverType.c \ - s1ap/S1AP_HFN.c \ - s1ap/S1AP_HFNModified.c \ - s1ap/S1AP_HFNforPDCP-SNlength18.c \ - s1ap/S1AP_Masked-IMEISV.c \ - s1ap/S1AP_ImmediateMDT.c \ - s1ap/S1AP_IMSI.c \ - s1ap/S1AP_InformationOnRecommendedCellsAndENBsForPaging.c \ - s1ap/S1AP_IntegrityProtectionAlgorithms.c \ - s1ap/S1AP_IntendedNumberOfPagingAttempts.c \ - s1ap/S1AP_InterfacesToTrace.c \ - s1ap/S1AP_KillAllWarningMessages.c \ - s1ap/S1AP_LAC.c \ - s1ap/S1AP_LAI.c \ - s1ap/S1AP_LastVisitedCell-Item.c \ - s1ap/S1AP_LastVisitedEUTRANCellInformation.c \ - s1ap/S1AP_LastVisitedUTRANCellInformation.c \ - s1ap/S1AP_LastVisitedGERANCellInformation.c \ - s1ap/S1AP_L3-Information.c \ - s1ap/S1AP_LPPa-PDU.c \ - s1ap/S1AP_LHN-ID.c \ - s1ap/S1AP_Links-to-log.c \ - s1ap/S1AP_ListeningSubframePattern.c \ - s1ap/S1AP_LoggedMDT.c \ - s1ap/S1AP_LoggingInterval.c \ - s1ap/S1AP_LoggingDuration.c \ - s1ap/S1AP_LoggedMBSFNMDT.c \ - s1ap/S1AP_M3Configuration.c \ - s1ap/S1AP_M3period.c \ - s1ap/S1AP_M4Configuration.c \ - s1ap/S1AP_M4period.c \ - s1ap/S1AP_M5Configuration.c \ - s1ap/S1AP_M5period.c \ - s1ap/S1AP_M6Configuration.c \ - s1ap/S1AP_M6report-Interval.c \ - s1ap/S1AP_M6delay-threshold.c \ - s1ap/S1AP_M7Configuration.c \ - s1ap/S1AP_M7period.c \ - s1ap/S1AP_MDT-Activation.c \ - s1ap/S1AP_MDT-Location-Info.c \ - s1ap/S1AP_MDT-Configuration.c \ - s1ap/S1AP_ManagementBasedMDTAllowed.c \ - s1ap/S1AP_MBSFN-ResultToLog.c \ - s1ap/S1AP_MBSFN-ResultToLogInfo.c \ - s1ap/S1AP_MDTPLMNList.c \ - s1ap/S1AP_PrivacyIndicator.c \ - s1ap/S1AP_MDTMode.c \ - s1ap/S1AP_MDTMode-Extension.c \ - s1ap/S1AP_MeasurementsToActivate.c \ - s1ap/S1AP_MeasurementThresholdA2.c \ - s1ap/S1AP_MessageIdentifier.c \ - s1ap/S1AP_MobilityInformation.c \ - s1ap/S1AP_MMEname.c \ - s1ap/S1AP_MMEPagingTarget.c \ - s1ap/S1AP_MMERelaySupportIndicator.c \ - s1ap/S1AP_MME-Group-ID.c \ - s1ap/S1AP_MME-Code.c \ - s1ap/S1AP_MME-UE-S1AP-ID.c \ - s1ap/S1AP_M-TMSI.c \ - s1ap/S1AP_MSClassmark2.c \ - s1ap/S1AP_MSClassmark3.c \ - s1ap/S1AP_MutingAvailabilityIndication.c \ - s1ap/S1AP_MutingPatternInformation.c \ - s1ap/S1AP_NAS-PDU.c \ - s1ap/S1AP_NASSecurityParametersfromE-UTRAN.c \ - s1ap/S1AP_NASSecurityParameterstoE-UTRAN.c \ - s1ap/S1AP_NB-IoT-DefaultPagingDRX.c \ - s1ap/S1AP_NB-IoT-Paging-eDRXInformation.c \ - s1ap/S1AP_NB-IoT-Paging-eDRX-Cycle.c \ - s1ap/S1AP_NB-IoT-PagingTimeWindow.c \ - s1ap/S1AP_NB-IoT-UEIdentityIndexValue.c \ - s1ap/S1AP_NextPagingAreaScope.c \ - s1ap/S1AP_NumberofBroadcastRequest.c \ - s1ap/S1AP_NumberOfBroadcasts.c \ - s1ap/S1AP_OldBSS-ToNewBSS-Information.c \ - s1ap/S1AP_OverloadAction.c \ - s1ap/S1AP_OverloadResponse.c \ - s1ap/S1AP_PagingAttemptInformation.c \ - s1ap/S1AP_PagingAttemptCount.c \ - s1ap/S1AP_Paging-eDRXInformation.c \ - s1ap/S1AP_Paging-eDRX-Cycle.c \ - s1ap/S1AP_PagingTimeWindow.c \ - s1ap/S1AP_PagingDRX.c \ - s1ap/S1AP_PagingPriority.c \ - s1ap/S1AP_PDCP-SN.c \ - s1ap/S1AP_PDCP-SNExtended.c \ - s1ap/S1AP_PDCP-SNlength18.c \ - s1ap/S1AP_M1PeriodicReporting.c \ - s1ap/S1AP_PLMNidentity.c \ - s1ap/S1AP_Port-Number.c \ - s1ap/S1AP_Pre-emptionCapability.c \ - s1ap/S1AP_Pre-emptionVulnerability.c \ - s1ap/S1AP_PriorityLevel.c \ - s1ap/S1AP_ProSeAuthorized.c \ - s1ap/S1AP_ProSeDirectDiscovery.c \ - s1ap/S1AP_ProSeUEtoNetworkRelaying.c \ - s1ap/S1AP_ProSeDirectCommunication.c \ - s1ap/S1AP_PS-ServiceNotAvailable.c \ - s1ap/S1AP_QCI.c \ - s1ap/S1AP_ReceiveStatusofULPDCPSDUs.c \ - s1ap/S1AP_ReceiveStatusOfULPDCPSDUsExtended.c \ - s1ap/S1AP_ReceiveStatusOfULPDCPSDUsPDCP-SNlength18.c \ - s1ap/S1AP_RecommendedCellsForPaging.c \ - s1ap/S1AP_RecommendedCellList.c \ - s1ap/S1AP_RecommendedCellItem.c \ - s1ap/S1AP_RecommendedENBsForPaging.c \ - s1ap/S1AP_RecommendedENBList.c \ - s1ap/S1AP_RecommendedENBItem.c \ - s1ap/S1AP_RelativeMMECapacity.c \ - s1ap/S1AP_RelayNode-Indicator.c \ - s1ap/S1AP_RAC.c \ - s1ap/S1AP_RAT-Type.c \ - s1ap/S1AP_ReportAmountMDT.c \ - s1ap/S1AP_ReportIntervalMDT.c \ - s1ap/S1AP_M1ReportingTrigger.c \ - s1ap/S1AP_RequestType.c \ - s1ap/S1AP_RIMTransfer.c \ - s1ap/S1AP_RIMInformation.c \ - s1ap/S1AP_RIMRoutingAddress.c \ - s1ap/S1AP_ReportArea.c \ - s1ap/S1AP_RepetitionPeriod.c \ - s1ap/S1AP_RLFReportInformation.c \ - s1ap/S1AP_RNC-ID.c \ - s1ap/S1AP_RRC-Container.c \ - s1ap/S1AP_RRC-Establishment-Cause.c \ - s1ap/S1AP_ECGIListForRestart.c \ - s1ap/S1AP_Routing-ID.c \ - s1ap/S1AP_SecurityKey.c \ - s1ap/S1AP_SecurityContext.c \ - s1ap/S1AP_SerialNumber.c \ - s1ap/S1AP_SONInformation.c \ - s1ap/S1AP_SONInformation-Extension.c \ - s1ap/S1AP_SONInformationRequest.c \ - s1ap/S1AP_SONInformationReply.c \ - s1ap/S1AP_SONInformationReport.c \ - s1ap/S1AP_SONConfigurationTransfer.c \ - s1ap/S1AP_SynchronisationInformation.c \ - s1ap/S1AP_Source-ToTarget-TransparentContainer.c \ - s1ap/S1AP_SourceBSS-ToTargetBSS-TransparentContainer.c \ - s1ap/S1AP_SourceeNB-ID.c \ - s1ap/S1AP_SRVCCOperationNotPossible.c \ - s1ap/S1AP_SRVCCOperationPossible.c \ - s1ap/S1AP_SRVCCHOIndication.c \ - s1ap/S1AP_SourceeNB-ToTargeteNB-TransparentContainer.c \ - s1ap/S1AP_SourceRNC-ToTargetRNC-TransparentContainer.c \ - s1ap/S1AP_ServedGUMMEIs.c \ - s1ap/S1AP_ServedGUMMEIsItem.c \ - s1ap/S1AP_ServedGroupIDs.c \ - s1ap/S1AP_ServedMMECs.c \ - s1ap/S1AP_ServedPLMNs.c \ - s1ap/S1AP_SubscriberProfileIDforRFP.c \ - s1ap/S1AP_SupportedTAs.c \ - s1ap/S1AP_SupportedTAs-Item.c \ - s1ap/S1AP_StratumLevel.c \ - s1ap/S1AP_SynchronisationStatus.c \ - s1ap/S1AP_TimeSynchronisationInfo.c \ - s1ap/S1AP_S-TMSI.c \ - s1ap/S1AP_TAC.c \ - s1ap/S1AP_TAIBasedMDT.c \ - s1ap/S1AP_TAIListforMDT.c \ - s1ap/S1AP_TAIListforWarning.c \ - s1ap/S1AP_TAI.c \ - s1ap/S1AP_TAI-Broadcast.c \ - s1ap/S1AP_TAI-Broadcast-Item.c \ - s1ap/S1AP_TAI-Cancelled.c \ - s1ap/S1AP_TAI-Cancelled-Item.c \ - s1ap/S1AP_TABasedMDT.c \ - s1ap/S1AP_TAListforMDT.c \ - s1ap/S1AP_CompletedCellinTAI.c \ - s1ap/S1AP_CompletedCellinTAI-Item.c \ - s1ap/S1AP_TBCD-STRING.c \ - s1ap/S1AP_TargetID.c \ - s1ap/S1AP_TargeteNB-ID.c \ - s1ap/S1AP_TargetRNC-ID.c \ - s1ap/S1AP_TargeteNB-ToSourceeNB-TransparentContainer.c \ - s1ap/S1AP_Target-ToSource-TransparentContainer.c \ - s1ap/S1AP_TargetRNC-ToSourceRNC-TransparentContainer.c \ - s1ap/S1AP_TargetBSS-ToSourceBSS-TransparentContainer.c \ - s1ap/S1AP_M1ThresholdEventA2.c \ - s1ap/S1AP_Threshold-RSRP.c \ - s1ap/S1AP_Threshold-RSRQ.c \ - s1ap/S1AP_TimeToWait.c \ - s1ap/S1AP_Time-UE-StayedInCell.c \ - s1ap/S1AP_Time-UE-StayedInCell-EnhancedGranularity.c \ - s1ap/S1AP_TransportInformation.c \ - s1ap/S1AP_TransportLayerAddress.c \ - s1ap/S1AP_TraceActivation.c \ - s1ap/S1AP_TraceDepth.c \ - s1ap/S1AP_E-UTRAN-Trace-ID.c \ - s1ap/S1AP_TrafficLoadReductionIndication.c \ - s1ap/S1AP_TunnelInformation.c \ - s1ap/S1AP_TypeOfError.c \ - s1ap/S1AP_TAIListForRestart.c \ - s1ap/S1AP_UEAggregateMaximumBitrate.c \ - s1ap/S1AP_UE-RetentionInformation.c \ - s1ap/S1AP_UE-S1AP-IDs.c \ - s1ap/S1AP_UE-S1AP-ID-pair.c \ - s1ap/S1AP_UE-associatedLogicalS1-ConnectionItem.c \ - s1ap/S1AP_UEIdentityIndexValue.c \ - s1ap/S1AP_UE-HistoryInformation.c \ - s1ap/S1AP_UE-HistoryInformationFromTheUE.c \ - s1ap/S1AP_UEPagingID.c \ - s1ap/S1AP_UERadioCapability.c \ - s1ap/S1AP_UERadioCapabilityForPaging.c \ - s1ap/S1AP_UE-RLF-Report-Container.c \ - s1ap/S1AP_UE-RLF-Report-Container-for-extended-bands.c \ - s1ap/S1AP_UESecurityCapabilities.c \ - s1ap/S1AP_UESidelinkAggregateMaximumBitrate.c \ - s1ap/S1AP_UE-Usage-Type.c \ - s1ap/S1AP_UL-CP-SecurityInformation.c \ - s1ap/S1AP_UL-NAS-MAC.c \ - s1ap/S1AP_UL-NAS-Count.c \ - s1ap/S1AP_UserLocationInformation.c \ - s1ap/S1AP_UEUserPlaneCIoTSupportIndicator.c \ - s1ap/S1AP_VoiceSupportMatchIndicator.c \ - s1ap/S1AP_V2XServicesAuthorized.c \ - s1ap/S1AP_VehicleUE.c \ - s1ap/S1AP_PedestrianUE.c \ - s1ap/S1AP_WarningAreaList.c \ - s1ap/S1AP_WarningType.c \ - s1ap/S1AP_WarningSecurityInfo.c \ - s1ap/S1AP_WarningMessageContents.c \ - s1ap/S1AP_X2TNLConfigurationInfo.c \ - s1ap/S1AP_ENBX2ExtTLAs.c \ - s1ap/S1AP_ENBX2ExtTLA.c \ - s1ap/S1AP_ENBX2GTPTLAs.c \ - s1ap/S1AP_ENBIndirectX2TransportLayerAddresses.c \ - s1ap/S1AP_Criticality.c \ - s1ap/S1AP_Presence.c \ - s1ap/S1AP_PrivateIE-ID.c \ - s1ap/S1AP_ProcedureCode.c \ - s1ap/S1AP_ProtocolExtensionID.c \ - s1ap/S1AP_ProtocolIE-ID.c \ - s1ap/S1AP_TriggeringMessage.c \ - s1ap/S1AP_ProtocolIE-Container.c \ - s1ap/S1AP_ProtocolIE-SingleContainer.c \ - s1ap/S1AP_ProtocolIE-Field.c \ - s1ap/S1AP_ProtocolIE-ContainerList.c \ - s1ap/S1AP_ProtocolExtensionContainer.c \ - s1ap/S1AP_ProtocolExtensionField.c \ - s1ap/S1AP_PrivateIE-Container.c \ - s1ap/S1AP_PrivateIE-Field.c - -ASN_MODULE_HDRS= \ - s1ap/S1AP_S1AP-PDU.h \ - s1ap/S1AP_InitiatingMessage.h \ - s1ap/S1AP_SuccessfulOutcome.h \ - s1ap/S1AP_UnsuccessfulOutcome.h \ - s1ap/S1AP_E-RAB-IE-ContainerList.h \ - s1ap/S1AP_E-RAB-IE-ContainerPairList.h \ - s1ap/S1AP_ProtocolError-IE-ContainerList.h \ - s1ap/S1AP_HandoverRequired.h \ - s1ap/S1AP_HandoverCommand.h \ - s1ap/S1AP_E-RABSubjecttoDataForwardingList.h \ - s1ap/S1AP_E-RABDataForwardingItem.h \ - s1ap/S1AP_HandoverPreparationFailure.h \ - s1ap/S1AP_HandoverRequest.h \ - s1ap/S1AP_E-RABToBeSetupListHOReq.h \ - s1ap/S1AP_E-RABToBeSetupItemHOReq.h \ - s1ap/S1AP_HandoverRequestAcknowledge.h \ - s1ap/S1AP_E-RABAdmittedList.h \ - s1ap/S1AP_E-RABAdmittedItem.h \ - s1ap/S1AP_E-RABFailedtoSetupListHOReqAck.h \ - s1ap/S1AP_E-RABFailedToSetupItemHOReqAck.h \ - s1ap/S1AP_HandoverFailure.h \ - s1ap/S1AP_HandoverNotify.h \ - s1ap/S1AP_PathSwitchRequest.h \ - s1ap/S1AP_E-RABToBeSwitchedDLList.h \ - s1ap/S1AP_E-RABToBeSwitchedDLItem.h \ - s1ap/S1AP_PathSwitchRequestAcknowledge.h \ - s1ap/S1AP_E-RABToBeSwitchedULList.h \ - s1ap/S1AP_E-RABToBeSwitchedULItem.h \ - s1ap/S1AP_PathSwitchRequestFailure.h \ - s1ap/S1AP_HandoverCancel.h \ - s1ap/S1AP_HandoverCancelAcknowledge.h \ - s1ap/S1AP_E-RABSetupRequest.h \ - s1ap/S1AP_E-RABToBeSetupListBearerSUReq.h \ - s1ap/S1AP_E-RABToBeSetupItemBearerSUReq.h \ - s1ap/S1AP_E-RABSetupResponse.h \ - s1ap/S1AP_E-RABSetupListBearerSURes.h \ - s1ap/S1AP_E-RABSetupItemBearerSURes.h \ - s1ap/S1AP_E-RABModifyRequest.h \ - s1ap/S1AP_E-RABToBeModifiedListBearerModReq.h \ - s1ap/S1AP_E-RABToBeModifiedItemBearerModReq.h \ - s1ap/S1AP_E-RABModifyResponse.h \ - s1ap/S1AP_E-RABModifyListBearerModRes.h \ - s1ap/S1AP_E-RABModifyItemBearerModRes.h \ - s1ap/S1AP_E-RABReleaseCommand.h \ - s1ap/S1AP_E-RABReleaseResponse.h \ - s1ap/S1AP_E-RABReleaseListBearerRelComp.h \ - s1ap/S1AP_E-RABReleaseItemBearerRelComp.h \ - s1ap/S1AP_E-RABReleaseIndication.h \ - s1ap/S1AP_InitialContextSetupRequest.h \ - s1ap/S1AP_E-RABToBeSetupListCtxtSUReq.h \ - s1ap/S1AP_E-RABToBeSetupItemCtxtSUReq.h \ - s1ap/S1AP_InitialContextSetupResponse.h \ - s1ap/S1AP_E-RABSetupListCtxtSURes.h \ - s1ap/S1AP_E-RABSetupItemCtxtSURes.h \ - s1ap/S1AP_InitialContextSetupFailure.h \ - s1ap/S1AP_Paging.h \ - s1ap/S1AP_TAIList.h \ - s1ap/S1AP_TAIItem.h \ - s1ap/S1AP_UEContextReleaseRequest.h \ - s1ap/S1AP_UEContextReleaseCommand.h \ - s1ap/S1AP_UEContextReleaseComplete.h \ - s1ap/S1AP_UEContextModificationRequest.h \ - s1ap/S1AP_UEContextModificationResponse.h \ - s1ap/S1AP_UEContextModificationFailure.h \ - s1ap/S1AP_UERadioCapabilityMatchRequest.h \ - s1ap/S1AP_UERadioCapabilityMatchResponse.h \ - s1ap/S1AP_DownlinkNASTransport.h \ - s1ap/S1AP_InitialUEMessage.h \ - s1ap/S1AP_UplinkNASTransport.h \ - s1ap/S1AP_NASNonDeliveryIndication.h \ - s1ap/S1AP_RerouteNASRequest.h \ - s1ap/S1AP_NASDeliveryIndication.h \ - s1ap/S1AP_Reset.h \ - s1ap/S1AP_ResetType.h \ - s1ap/S1AP_ResetAll.h \ - s1ap/S1AP_UE-associatedLogicalS1-ConnectionListRes.h \ - s1ap/S1AP_ResetAcknowledge.h \ - s1ap/S1AP_UE-associatedLogicalS1-ConnectionListResAck.h \ - s1ap/S1AP_ErrorIndication.h \ - s1ap/S1AP_S1SetupRequest.h \ - s1ap/S1AP_S1SetupResponse.h \ - s1ap/S1AP_S1SetupFailure.h \ - s1ap/S1AP_ENBConfigurationUpdate.h \ - s1ap/S1AP_ENBConfigurationUpdateAcknowledge.h \ - s1ap/S1AP_ENBConfigurationUpdateFailure.h \ - s1ap/S1AP_MMEConfigurationUpdate.h \ - s1ap/S1AP_MMEConfigurationUpdateAcknowledge.h \ - s1ap/S1AP_MMEConfigurationUpdateFailure.h \ - s1ap/S1AP_DownlinkS1cdma2000tunnelling.h \ - s1ap/S1AP_UplinkS1cdma2000tunnelling.h \ - s1ap/S1AP_UECapabilityInfoIndication.h \ - s1ap/S1AP_ENBStatusTransfer.h \ - s1ap/S1AP_MMEStatusTransfer.h \ - s1ap/S1AP_TraceStart.h \ - s1ap/S1AP_TraceFailureIndication.h \ - s1ap/S1AP_DeactivateTrace.h \ - s1ap/S1AP_CellTrafficTrace.h \ - s1ap/S1AP_LocationReportingControl.h \ - s1ap/S1AP_LocationReportingFailureIndication.h \ - s1ap/S1AP_LocationReport.h \ - s1ap/S1AP_OverloadStart.h \ - s1ap/S1AP_OverloadStop.h \ - s1ap/S1AP_WriteReplaceWarningRequest.h \ - s1ap/S1AP_WriteReplaceWarningResponse.h \ - s1ap/S1AP_ENBDirectInformationTransfer.h \ - s1ap/S1AP_Inter-SystemInformationTransferType.h \ - s1ap/S1AP_MMEDirectInformationTransfer.h \ - s1ap/S1AP_ENBConfigurationTransfer.h \ - s1ap/S1AP_MMEConfigurationTransfer.h \ - s1ap/S1AP_PrivateMessage.h \ - s1ap/S1AP_KillRequest.h \ - s1ap/S1AP_KillResponse.h \ - s1ap/S1AP_PWSRestartIndication.h \ - s1ap/S1AP_PWSFailureIndication.h \ - s1ap/S1AP_DownlinkUEAssociatedLPPaTransport.h \ - s1ap/S1AP_UplinkUEAssociatedLPPaTransport.h \ - s1ap/S1AP_DownlinkNonUEAssociatedLPPaTransport.h \ - s1ap/S1AP_UplinkNonUEAssociatedLPPaTransport.h \ - s1ap/S1AP_E-RABModificationIndication.h \ - s1ap/S1AP_E-RABToBeModifiedListBearerModInd.h \ - s1ap/S1AP_E-RABToBeModifiedItemBearerModInd.h \ - s1ap/S1AP_E-RABNotToBeModifiedListBearerModInd.h \ - s1ap/S1AP_E-RABNotToBeModifiedItemBearerModInd.h \ - s1ap/S1AP_CSGMembershipInfo.h \ - s1ap/S1AP_E-RABModificationConfirm.h \ - s1ap/S1AP_E-RABModifyListBearerModConf.h \ - s1ap/S1AP_E-RABModifyItemBearerModConf.h \ - s1ap/S1AP_UEContextModificationIndication.h \ - s1ap/S1AP_UEContextModificationConfirm.h \ - s1ap/S1AP_UEContextSuspendRequest.h \ - s1ap/S1AP_UEContextSuspendResponse.h \ - s1ap/S1AP_UEContextResumeRequest.h \ - s1ap/S1AP_E-RABFailedToResumeListResumeReq.h \ - s1ap/S1AP_E-RABFailedToResumeItemResumeReq.h \ - s1ap/S1AP_UEContextResumeResponse.h \ - s1ap/S1AP_E-RABFailedToResumeListResumeRes.h \ - s1ap/S1AP_E-RABFailedToResumeItemResumeRes.h \ - s1ap/S1AP_UEContextResumeFailure.h \ - s1ap/S1AP_ConnectionEstablishmentIndication.h \ - s1ap/S1AP_RetrieveUEInformation.h \ - s1ap/S1AP_UEInformationTransfer.h \ - s1ap/S1AP_ENBCPRelocationIndication.h \ - s1ap/S1AP_MMECPRelocationIndication.h \ - s1ap/S1AP_Additional-GUTI.h \ - s1ap/S1AP_AreaScopeOfMDT.h \ - s1ap/S1AP_AllocationAndRetentionPriority.h \ - s1ap/S1AP_AssistanceDataForCECapableUEs.h \ - s1ap/S1AP_AssistanceDataForPaging.h \ - s1ap/S1AP_AssistanceDataForRecommendedCells.h \ - s1ap/S1AP_Bearers-SubjectToStatusTransferList.h \ - s1ap/S1AP_Bearers-SubjectToStatusTransfer-Item.h \ - s1ap/S1AP_BearerType.h \ - s1ap/S1AP_BitRate.h \ - s1ap/S1AP_BPLMNs.h \ - s1ap/S1AP_BroadcastCancelledAreaList.h \ - s1ap/S1AP_BroadcastCompletedAreaList.h \ - s1ap/S1AP_CancelledCellinEAI.h \ - s1ap/S1AP_CancelledCellinEAI-Item.h \ - s1ap/S1AP_CancelledCellinTAI.h \ - s1ap/S1AP_CancelledCellinTAI-Item.h \ - s1ap/S1AP_Cause.h \ - s1ap/S1AP_CauseMisc.h \ - s1ap/S1AP_CauseProtocol.h \ - s1ap/S1AP_CauseRadioNetwork.h \ - s1ap/S1AP_CauseTransport.h \ - s1ap/S1AP_CauseNas.h \ - s1ap/S1AP_CellAccessMode.h \ - s1ap/S1AP_CellIdentifierAndCELevelForCECapableUEs.h \ - s1ap/S1AP_CELevel.h \ - s1ap/S1AP_CE-mode-B-SupportIndicator.h \ - s1ap/S1AP_CellIdentity.h \ - s1ap/S1AP_CellID-Broadcast.h \ - s1ap/S1AP_CellID-Broadcast-Item.h \ - s1ap/S1AP_CellID-Cancelled.h \ - s1ap/S1AP_CellID-Cancelled-Item.h \ - s1ap/S1AP_CellBasedMDT.h \ - s1ap/S1AP_CellIdListforMDT.h \ - s1ap/S1AP_Cdma2000PDU.h \ - s1ap/S1AP_Cdma2000RATType.h \ - s1ap/S1AP_Cdma2000SectorID.h \ - s1ap/S1AP_Cdma2000HOStatus.h \ - s1ap/S1AP_Cdma2000HORequiredIndication.h \ - s1ap/S1AP_Cdma2000OneXSRVCCInfo.h \ - s1ap/S1AP_Cdma2000OneXMEID.h \ - s1ap/S1AP_Cdma2000OneXMSI.h \ - s1ap/S1AP_Cdma2000OneXPilot.h \ - s1ap/S1AP_Cdma2000OneXRAND.h \ - s1ap/S1AP_Cell-Size.h \ - s1ap/S1AP_CellType.h \ - s1ap/S1AP_CGI.h \ - s1ap/S1AP_CI.h \ - s1ap/S1AP_CNDomain.h \ - s1ap/S1AP_ConcurrentWarningMessageIndicator.h \ - s1ap/S1AP_Correlation-ID.h \ - s1ap/S1AP_CSFallbackIndicator.h \ - s1ap/S1AP_AdditionalCSFallbackIndicator.h \ - s1ap/S1AP_CSG-Id.h \ - s1ap/S1AP_CSG-IdList.h \ - s1ap/S1AP_CSG-IdList-Item.h \ - s1ap/S1AP_CSGMembershipStatus.h \ - s1ap/S1AP_COUNTvalue.h \ - s1ap/S1AP_COUNTValueExtended.h \ - s1ap/S1AP_COUNTvaluePDCP-SNlength18.h \ - s1ap/S1AP_Coverage-Level.h \ - s1ap/S1AP_CriticalityDiagnostics.h \ - s1ap/S1AP_CriticalityDiagnostics-IE-List.h \ - s1ap/S1AP_CriticalityDiagnostics-IE-Item.h \ - s1ap/S1AP_DataCodingScheme.h \ - s1ap/S1AP_DCN-ID.h \ - s1ap/S1AP_ServedDCNs.h \ - s1ap/S1AP_ServedDCNsItem.h \ - s1ap/S1AP_DL-CP-SecurityInformation.h \ - s1ap/S1AP_DL-Forwarding.h \ - s1ap/S1AP_DL-NAS-MAC.h \ - s1ap/S1AP_Direct-Forwarding-Path-Availability.h \ - s1ap/S1AP_Data-Forwarding-Not-Possible.h \ - s1ap/S1AP_DLNASPDUDeliveryAckRequest.h \ - s1ap/S1AP_EARFCN.h \ - s1ap/S1AP_ECGIList.h \ - s1ap/S1AP_PWSfailedECGIList.h \ - s1ap/S1AP_EmergencyAreaIDList.h \ - s1ap/S1AP_EmergencyAreaID.h \ - s1ap/S1AP_EmergencyAreaID-Broadcast.h \ - s1ap/S1AP_EmergencyAreaID-Broadcast-Item.h \ - s1ap/S1AP_EmergencyAreaID-Cancelled.h \ - s1ap/S1AP_EmergencyAreaID-Cancelled-Item.h \ - s1ap/S1AP_CompletedCellinEAI.h \ - s1ap/S1AP_CompletedCellinEAI-Item.h \ - s1ap/S1AP_ECGI-List.h \ - s1ap/S1AP_EmergencyAreaIDListForRestart.h \ - s1ap/S1AP_ENB-ID.h \ - s1ap/S1AP_GERAN-Cell-ID.h \ - s1ap/S1AP_Global-ENB-ID.h \ - s1ap/S1AP_GUMMEIList.h \ - s1ap/S1AP_ENB-StatusTransfer-TransparentContainer.h \ - s1ap/S1AP_ENB-UE-S1AP-ID.h \ - s1ap/S1AP_ENBname.h \ - s1ap/S1AP_ENBX2TLAs.h \ - s1ap/S1AP_EncryptionAlgorithms.h \ - s1ap/S1AP_EnhancedCoverageRestricted.h \ - s1ap/S1AP_EPLMNs.h \ - s1ap/S1AP_EventType.h \ - s1ap/S1AP_E-RAB-ID.h \ - s1ap/S1AP_E-RABInformationList.h \ - s1ap/S1AP_E-RABInformationListItem.h \ - s1ap/S1AP_E-RABList.h \ - s1ap/S1AP_E-RABItem.h \ - s1ap/S1AP_E-RABLevelQoSParameters.h \ - s1ap/S1AP_EUTRAN-CGI.h \ - s1ap/S1AP_EUTRANRoundTripDelayEstimationInfo.h \ - s1ap/S1AP_ExpectedUEBehaviour.h \ - s1ap/S1AP_ExpectedUEActivityBehaviour.h \ - s1ap/S1AP_ExpectedActivityPeriod.h \ - s1ap/S1AP_ExpectedIdlePeriod.h \ - s1ap/S1AP_SourceOfUEActivityBehaviourInformation.h \ - s1ap/S1AP_ExpectedHOInterval.h \ - s1ap/S1AP_ExtendedRNC-ID.h \ - s1ap/S1AP_ExtendedRepetitionPeriod.h \ - s1ap/S1AP_Extended-UEIdentityIndexValue.h \ - s1ap/S1AP_ForbiddenInterRATs.h \ - s1ap/S1AP_ForbiddenTAs.h \ - s1ap/S1AP_ForbiddenTAs-Item.h \ - s1ap/S1AP_ForbiddenTACs.h \ - s1ap/S1AP_ForbiddenLAs.h \ - s1ap/S1AP_ForbiddenLAs-Item.h \ - s1ap/S1AP_ForbiddenLACs.h \ - s1ap/S1AP_GBR-QosInformation.h \ - s1ap/S1AP_GTP-TEID.h \ - s1ap/S1AP_GUMMEI.h \ - s1ap/S1AP_GUMMEIType.h \ - s1ap/S1AP_GWContextReleaseIndication.h \ - s1ap/S1AP_HandoverRestrictionList.h \ - s1ap/S1AP_HandoverType.h \ - s1ap/S1AP_HFN.h \ - s1ap/S1AP_HFNModified.h \ - s1ap/S1AP_HFNforPDCP-SNlength18.h \ - s1ap/S1AP_Masked-IMEISV.h \ - s1ap/S1AP_ImmediateMDT.h \ - s1ap/S1AP_IMSI.h \ - s1ap/S1AP_InformationOnRecommendedCellsAndENBsForPaging.h \ - s1ap/S1AP_IntegrityProtectionAlgorithms.h \ - s1ap/S1AP_IntendedNumberOfPagingAttempts.h \ - s1ap/S1AP_InterfacesToTrace.h \ - s1ap/S1AP_KillAllWarningMessages.h \ - s1ap/S1AP_LAC.h \ - s1ap/S1AP_LAI.h \ - s1ap/S1AP_LastVisitedCell-Item.h \ - s1ap/S1AP_LastVisitedEUTRANCellInformation.h \ - s1ap/S1AP_LastVisitedUTRANCellInformation.h \ - s1ap/S1AP_LastVisitedGERANCellInformation.h \ - s1ap/S1AP_L3-Information.h \ - s1ap/S1AP_LPPa-PDU.h \ - s1ap/S1AP_LHN-ID.h \ - s1ap/S1AP_Links-to-log.h \ - s1ap/S1AP_ListeningSubframePattern.h \ - s1ap/S1AP_LoggedMDT.h \ - s1ap/S1AP_LoggingInterval.h \ - s1ap/S1AP_LoggingDuration.h \ - s1ap/S1AP_LoggedMBSFNMDT.h \ - s1ap/S1AP_M3Configuration.h \ - s1ap/S1AP_M3period.h \ - s1ap/S1AP_M4Configuration.h \ - s1ap/S1AP_M4period.h \ - s1ap/S1AP_M5Configuration.h \ - s1ap/S1AP_M5period.h \ - s1ap/S1AP_M6Configuration.h \ - s1ap/S1AP_M6report-Interval.h \ - s1ap/S1AP_M6delay-threshold.h \ - s1ap/S1AP_M7Configuration.h \ - s1ap/S1AP_M7period.h \ - s1ap/S1AP_MDT-Activation.h \ - s1ap/S1AP_MDT-Location-Info.h \ - s1ap/S1AP_MDT-Configuration.h \ - s1ap/S1AP_ManagementBasedMDTAllowed.h \ - s1ap/S1AP_MBSFN-ResultToLog.h \ - s1ap/S1AP_MBSFN-ResultToLogInfo.h \ - s1ap/S1AP_MDTPLMNList.h \ - s1ap/S1AP_PrivacyIndicator.h \ - s1ap/S1AP_MDTMode.h \ - s1ap/S1AP_MDTMode-Extension.h \ - s1ap/S1AP_MeasurementsToActivate.h \ - s1ap/S1AP_MeasurementThresholdA2.h \ - s1ap/S1AP_MessageIdentifier.h \ - s1ap/S1AP_MobilityInformation.h \ - s1ap/S1AP_MMEname.h \ - s1ap/S1AP_MMEPagingTarget.h \ - s1ap/S1AP_MMERelaySupportIndicator.h \ - s1ap/S1AP_MME-Group-ID.h \ - s1ap/S1AP_MME-Code.h \ - s1ap/S1AP_MME-UE-S1AP-ID.h \ - s1ap/S1AP_M-TMSI.h \ - s1ap/S1AP_MSClassmark2.h \ - s1ap/S1AP_MSClassmark3.h \ - s1ap/S1AP_MutingAvailabilityIndication.h \ - s1ap/S1AP_MutingPatternInformation.h \ - s1ap/S1AP_NAS-PDU.h \ - s1ap/S1AP_NASSecurityParametersfromE-UTRAN.h \ - s1ap/S1AP_NASSecurityParameterstoE-UTRAN.h \ - s1ap/S1AP_NB-IoT-DefaultPagingDRX.h \ - s1ap/S1AP_NB-IoT-Paging-eDRXInformation.h \ - s1ap/S1AP_NB-IoT-Paging-eDRX-Cycle.h \ - s1ap/S1AP_NB-IoT-PagingTimeWindow.h \ - s1ap/S1AP_NB-IoT-UEIdentityIndexValue.h \ - s1ap/S1AP_NextPagingAreaScope.h \ - s1ap/S1AP_NumberofBroadcastRequest.h \ - s1ap/S1AP_NumberOfBroadcasts.h \ - s1ap/S1AP_OldBSS-ToNewBSS-Information.h \ - s1ap/S1AP_OverloadAction.h \ - s1ap/S1AP_OverloadResponse.h \ - s1ap/S1AP_PagingAttemptInformation.h \ - s1ap/S1AP_PagingAttemptCount.h \ - s1ap/S1AP_Paging-eDRXInformation.h \ - s1ap/S1AP_Paging-eDRX-Cycle.h \ - s1ap/S1AP_PagingTimeWindow.h \ - s1ap/S1AP_PagingDRX.h \ - s1ap/S1AP_PagingPriority.h \ - s1ap/S1AP_PDCP-SN.h \ - s1ap/S1AP_PDCP-SNExtended.h \ - s1ap/S1AP_PDCP-SNlength18.h \ - s1ap/S1AP_M1PeriodicReporting.h \ - s1ap/S1AP_PLMNidentity.h \ - s1ap/S1AP_Port-Number.h \ - s1ap/S1AP_Pre-emptionCapability.h \ - s1ap/S1AP_Pre-emptionVulnerability.h \ - s1ap/S1AP_PriorityLevel.h \ - s1ap/S1AP_ProSeAuthorized.h \ - s1ap/S1AP_ProSeDirectDiscovery.h \ - s1ap/S1AP_ProSeUEtoNetworkRelaying.h \ - s1ap/S1AP_ProSeDirectCommunication.h \ - s1ap/S1AP_PS-ServiceNotAvailable.h \ - s1ap/S1AP_QCI.h \ - s1ap/S1AP_ReceiveStatusofULPDCPSDUs.h \ - s1ap/S1AP_ReceiveStatusOfULPDCPSDUsExtended.h \ - s1ap/S1AP_ReceiveStatusOfULPDCPSDUsPDCP-SNlength18.h \ - s1ap/S1AP_RecommendedCellsForPaging.h \ - s1ap/S1AP_RecommendedCellList.h \ - s1ap/S1AP_RecommendedCellItem.h \ - s1ap/S1AP_RecommendedENBsForPaging.h \ - s1ap/S1AP_RecommendedENBList.h \ - s1ap/S1AP_RecommendedENBItem.h \ - s1ap/S1AP_RelativeMMECapacity.h \ - s1ap/S1AP_RelayNode-Indicator.h \ - s1ap/S1AP_RAC.h \ - s1ap/S1AP_RAT-Type.h \ - s1ap/S1AP_ReportAmountMDT.h \ - s1ap/S1AP_ReportIntervalMDT.h \ - s1ap/S1AP_M1ReportingTrigger.h \ - s1ap/S1AP_RequestType.h \ - s1ap/S1AP_RIMTransfer.h \ - s1ap/S1AP_RIMInformation.h \ - s1ap/S1AP_RIMRoutingAddress.h \ - s1ap/S1AP_ReportArea.h \ - s1ap/S1AP_RepetitionPeriod.h \ - s1ap/S1AP_RLFReportInformation.h \ - s1ap/S1AP_RNC-ID.h \ - s1ap/S1AP_RRC-Container.h \ - s1ap/S1AP_RRC-Establishment-Cause.h \ - s1ap/S1AP_ECGIListForRestart.h \ - s1ap/S1AP_Routing-ID.h \ - s1ap/S1AP_SecurityKey.h \ - s1ap/S1AP_SecurityContext.h \ - s1ap/S1AP_SerialNumber.h \ - s1ap/S1AP_SONInformation.h \ - s1ap/S1AP_SONInformation-Extension.h \ - s1ap/S1AP_SONInformationRequest.h \ - s1ap/S1AP_SONInformationReply.h \ - s1ap/S1AP_SONInformationReport.h \ - s1ap/S1AP_SONConfigurationTransfer.h \ - s1ap/S1AP_SynchronisationInformation.h \ - s1ap/S1AP_Source-ToTarget-TransparentContainer.h \ - s1ap/S1AP_SourceBSS-ToTargetBSS-TransparentContainer.h \ - s1ap/S1AP_SourceeNB-ID.h \ - s1ap/S1AP_SRVCCOperationNotPossible.h \ - s1ap/S1AP_SRVCCOperationPossible.h \ - s1ap/S1AP_SRVCCHOIndication.h \ - s1ap/S1AP_SourceeNB-ToTargeteNB-TransparentContainer.h \ - s1ap/S1AP_SourceRNC-ToTargetRNC-TransparentContainer.h \ - s1ap/S1AP_ServedGUMMEIs.h \ - s1ap/S1AP_ServedGUMMEIsItem.h \ - s1ap/S1AP_ServedGroupIDs.h \ - s1ap/S1AP_ServedMMECs.h \ - s1ap/S1AP_ServedPLMNs.h \ - s1ap/S1AP_SubscriberProfileIDforRFP.h \ - s1ap/S1AP_SupportedTAs.h \ - s1ap/S1AP_SupportedTAs-Item.h \ - s1ap/S1AP_StratumLevel.h \ - s1ap/S1AP_SynchronisationStatus.h \ - s1ap/S1AP_TimeSynchronisationInfo.h \ - s1ap/S1AP_S-TMSI.h \ - s1ap/S1AP_TAC.h \ - s1ap/S1AP_TAIBasedMDT.h \ - s1ap/S1AP_TAIListforMDT.h \ - s1ap/S1AP_TAIListforWarning.h \ - s1ap/S1AP_TAI.h \ - s1ap/S1AP_TAI-Broadcast.h \ - s1ap/S1AP_TAI-Broadcast-Item.h \ - s1ap/S1AP_TAI-Cancelled.h \ - s1ap/S1AP_TAI-Cancelled-Item.h \ - s1ap/S1AP_TABasedMDT.h \ - s1ap/S1AP_TAListforMDT.h \ - s1ap/S1AP_CompletedCellinTAI.h \ - s1ap/S1AP_CompletedCellinTAI-Item.h \ - s1ap/S1AP_TBCD-STRING.h \ - s1ap/S1AP_TargetID.h \ - s1ap/S1AP_TargeteNB-ID.h \ - s1ap/S1AP_TargetRNC-ID.h \ - s1ap/S1AP_TargeteNB-ToSourceeNB-TransparentContainer.h \ - s1ap/S1AP_Target-ToSource-TransparentContainer.h \ - s1ap/S1AP_TargetRNC-ToSourceRNC-TransparentContainer.h \ - s1ap/S1AP_TargetBSS-ToSourceBSS-TransparentContainer.h \ - s1ap/S1AP_M1ThresholdEventA2.h \ - s1ap/S1AP_Threshold-RSRP.h \ - s1ap/S1AP_Threshold-RSRQ.h \ - s1ap/S1AP_TimeToWait.h \ - s1ap/S1AP_Time-UE-StayedInCell.h \ - s1ap/S1AP_Time-UE-StayedInCell-EnhancedGranularity.h \ - s1ap/S1AP_TransportInformation.h \ - s1ap/S1AP_TransportLayerAddress.h \ - s1ap/S1AP_TraceActivation.h \ - s1ap/S1AP_TraceDepth.h \ - s1ap/S1AP_E-UTRAN-Trace-ID.h \ - s1ap/S1AP_TrafficLoadReductionIndication.h \ - s1ap/S1AP_TunnelInformation.h \ - s1ap/S1AP_TypeOfError.h \ - s1ap/S1AP_TAIListForRestart.h \ - s1ap/S1AP_UEAggregateMaximumBitrate.h \ - s1ap/S1AP_UE-RetentionInformation.h \ - s1ap/S1AP_UE-S1AP-IDs.h \ - s1ap/S1AP_UE-S1AP-ID-pair.h \ - s1ap/S1AP_UE-associatedLogicalS1-ConnectionItem.h \ - s1ap/S1AP_UEIdentityIndexValue.h \ - s1ap/S1AP_UE-HistoryInformation.h \ - s1ap/S1AP_UE-HistoryInformationFromTheUE.h \ - s1ap/S1AP_UEPagingID.h \ - s1ap/S1AP_UERadioCapability.h \ - s1ap/S1AP_UERadioCapabilityForPaging.h \ - s1ap/S1AP_UE-RLF-Report-Container.h \ - s1ap/S1AP_UE-RLF-Report-Container-for-extended-bands.h \ - s1ap/S1AP_UESecurityCapabilities.h \ - s1ap/S1AP_UESidelinkAggregateMaximumBitrate.h \ - s1ap/S1AP_UE-Usage-Type.h \ - s1ap/S1AP_UL-CP-SecurityInformation.h \ - s1ap/S1AP_UL-NAS-MAC.h \ - s1ap/S1AP_UL-NAS-Count.h \ - s1ap/S1AP_UserLocationInformation.h \ - s1ap/S1AP_UEUserPlaneCIoTSupportIndicator.h \ - s1ap/S1AP_VoiceSupportMatchIndicator.h \ - s1ap/S1AP_V2XServicesAuthorized.h \ - s1ap/S1AP_VehicleUE.h \ - s1ap/S1AP_PedestrianUE.h \ - s1ap/S1AP_WarningAreaList.h \ - s1ap/S1AP_WarningType.h \ - s1ap/S1AP_WarningSecurityInfo.h \ - s1ap/S1AP_WarningMessageContents.h \ - s1ap/S1AP_X2TNLConfigurationInfo.h \ - s1ap/S1AP_ENBX2ExtTLAs.h \ - s1ap/S1AP_ENBX2ExtTLA.h \ - s1ap/S1AP_ENBX2GTPTLAs.h \ - s1ap/S1AP_ENBIndirectX2TransportLayerAddresses.h \ - s1ap/S1AP_Criticality.h \ - s1ap/S1AP_Presence.h \ - s1ap/S1AP_PrivateIE-ID.h \ - s1ap/S1AP_ProcedureCode.h \ - s1ap/S1AP_ProtocolExtensionID.h \ - s1ap/S1AP_ProtocolIE-ID.h \ - s1ap/S1AP_TriggeringMessage.h \ - s1ap/S1AP_ProtocolIE-Container.h \ - s1ap/S1AP_ProtocolIE-SingleContainer.h \ - s1ap/S1AP_ProtocolIE-Field.h \ - s1ap/S1AP_ProtocolIE-ContainerPair.h \ - s1ap/S1AP_ProtocolIE-FieldPair.h \ - s1ap/S1AP_ProtocolIE-ContainerList.h \ - s1ap/S1AP_ProtocolIE-ContainerPairList.h \ - s1ap/S1AP_ProtocolExtensionContainer.h \ - s1ap/S1AP_ProtocolExtensionField.h \ - s1ap/S1AP_PrivateIE-Container.h \ - s1ap/S1AP_PrivateIE-Field.h - -ASN_MODULE_HDRS+=s1ap/S1AP_asn_constant.h - -ASN_MODULE_HDRS+=common/ANY.h -ASN_MODULE_SRCS+=common/ANY.c -ASN_MODULE_HDRS+=common/OCTET_STRING.h -ASN_MODULE_HDRS+=common/OPEN_TYPE.h -ASN_MODULE_SRCS+=common/OPEN_TYPE.c -ASN_MODULE_HDRS+=common/constr_CHOICE.h -ASN_MODULE_HDRS+=common/BOOLEAN.h -ASN_MODULE_SRCS+=common/BOOLEAN.c -ASN_MODULE_HDRS+=common/INTEGER.h -ASN_MODULE_SRCS+=common/INTEGER.c -ASN_MODULE_HDRS+=common/NULL.h -ASN_MODULE_SRCS+=common/NULL.c -ASN_MODULE_HDRS+=common/NativeEnumerated.h -ASN_MODULE_SRCS+=common/NativeEnumerated.c -ASN_MODULE_HDRS+=common/NativeInteger.h -ASN_MODULE_SRCS+=common/NativeInteger.c -ASN_MODULE_HDRS+=common/OBJECT_IDENTIFIER.h -ASN_MODULE_SRCS+=common/OBJECT_IDENTIFIER.c -ASN_MODULE_HDRS+=common/PrintableString.h -ASN_MODULE_SRCS+=common/PrintableString.c -ASN_MODULE_HDRS+=common/asn_SEQUENCE_OF.h -ASN_MODULE_SRCS+=common/asn_SEQUENCE_OF.c -ASN_MODULE_HDRS+=common/asn_SET_OF.h -ASN_MODULE_SRCS+=common/asn_SET_OF.c -ASN_MODULE_SRCS+=common/constr_CHOICE.c -ASN_MODULE_HDRS+=common/constr_SEQUENCE.h -ASN_MODULE_SRCS+=common/constr_SEQUENCE.c -ASN_MODULE_HDRS+=common/constr_SEQUENCE_OF.h -ASN_MODULE_SRCS+=common/constr_SEQUENCE_OF.c -ASN_MODULE_HDRS+=common/constr_SET_OF.h -ASN_MODULE_SRCS+=common/constr_SET_OF.c -ASN_MODULE_HDRS+=common/asn_application.h -ASN_MODULE_SRCS+=common/asn_application.c -ASN_MODULE_HDRS+=common/asn_ioc.h -ASN_MODULE_HDRS+=common/asn_system.h -ASN_MODULE_HDRS+=common/asn_codecs.h -ASN_MODULE_HDRS+=common/asn_internal.h -ASN_MODULE_SRCS+=common/asn_internal.c -ASN_MODULE_HDRS+=common/asn_random_fill.h -ASN_MODULE_SRCS+=common/asn_random_fill.c -ASN_MODULE_HDRS+=common/asn_bit_data.h -ASN_MODULE_SRCS+=common/asn_bit_data.c -ASN_MODULE_SRCS+=common/OCTET_STRING.c -ASN_MODULE_HDRS+=common/BIT_STRING.h -ASN_MODULE_SRCS+=common/BIT_STRING.c -ASN_MODULE_SRCS+=common/asn_codecs_prim.c -ASN_MODULE_HDRS+=common/asn_codecs_prim.h -ASN_MODULE_HDRS+=common/ber_tlv_length.h -ASN_MODULE_SRCS+=common/ber_tlv_length.c -ASN_MODULE_HDRS+=common/ber_tlv_tag.h -ASN_MODULE_SRCS+=common/ber_tlv_tag.c -ASN_MODULE_HDRS+=common/ber_decoder.h -ASN_MODULE_SRCS+=common/ber_decoder.c -ASN_MODULE_HDRS+=common/der_encoder.h -ASN_MODULE_SRCS+=common/der_encoder.c -ASN_MODULE_HDRS+=common/constr_TYPE.h -ASN_MODULE_SRCS+=common/constr_TYPE.c -ASN_MODULE_HDRS+=common/constraints.h -ASN_MODULE_SRCS+=common/constraints.c -ASN_MODULE_HDRS+=common/xer_support.h -ASN_MODULE_SRCS+=common/xer_support.c -ASN_MODULE_HDRS+=common/xer_decoder.h -ASN_MODULE_SRCS+=common/xer_decoder.c -ASN_MODULE_HDRS+=common/xer_encoder.h -ASN_MODULE_SRCS+=common/xer_encoder.c -ASN_MODULE_HDRS+=common/per_support.h -ASN_MODULE_SRCS+=common/per_support.c -ASN_MODULE_HDRS+=common/per_decoder.h -ASN_MODULE_SRCS+=common/per_decoder.c -ASN_MODULE_HDRS+=common/per_encoder.h -ASN_MODULE_SRCS+=common/per_encoder.c -ASN_MODULE_HDRS+=common/per_opentype.h -ASN_MODULE_SRCS+=common/per_opentype.c -ASN_MODULE_HDRS+=common/oer_decoder.h -ASN_MODULE_HDRS+=common/oer_encoder.h -ASN_MODULE_HDRS+=common/oer_support.h -ASN_MODULE_SRCS+=common/oer_decoder.c -ASN_MODULE_SRCS+=common/oer_encoder.c -ASN_MODULE_SRCS+=common/oer_support.c -ASN_MODULE_SRCS+=common/OPEN_TYPE_oer.c -ASN_MODULE_SRCS+=common/INTEGER_oer.c -ASN_MODULE_SRCS+=common/BIT_STRING_oer.c -ASN_MODULE_SRCS+=common/OCTET_STRING_oer.c -ASN_MODULE_SRCS+=common/NativeInteger_oer.c -ASN_MODULE_SRCS+=common/NativeEnumerated_oer.c -ASN_MODULE_SRCS+=common/constr_CHOICE_oer.c -ASN_MODULE_SRCS+=common/constr_SEQUENCE_oer.c -ASN_MODULE_SRCS+=common/constr_SET_OF_oer.c - -ASN_MODULE_CFLAGS= - -pkglib_LTLIBRARIES=libasn1c.la -libasn1c_la_SOURCES= \ - $(ASN_MODULE_SRCS) $(ASN_MODULE_HDRS) \ - $(NULL) - -libasn1c_la_LIBADD = \ - @OGSCORE_LIBS@ \ - $(NULL) - -AM_CPPFLAGS = \ - @OGSCORE_CFLAGS@ \ - -I$(top_srcdir)/lib/asn1c/common \ - -I$(top_srcdir)/lib/asn1c/s1ap \ - $(NULL) - -AM_CFLAGS = \ - ${ASN_MODULE_CFLAGS} \ - -Wno-parentheses-equality -Wno-overflow -Wno-format \ - $(NULL) - -regen: regenerate-from-asn1-source - -regenerate-from-asn1-source: - ASN1C_PREFIX=S1AP_ ../../../../asn1c.velichkov/asn1c/asn1c -pdu=all -fcompound-names -findirect-choice -fno-include-deps ../support/r14.4.0/36413-e40.asn - rm -f S1AP_E-RAB-IE-ContainerPairList.c S1AP_ProtocolError-IE-ContainerList.c S1AP_ProtocolIE-ContainerPair.c S1AP_ProtocolIE-FieldPair.c S1AP_ProtocolIE-ContainerPairList.c - rm -f converter-example.mk converter-example.c pdu_collection.c - rm -f Makefile.am.asn1convert Makefile.am.libasncodec - diff --git a/lib/asn1c/common/asn_internal.h b/lib/asn1c/common/asn_internal.h index 77e005f79..3358c36c5 100644 --- a/lib/asn1c/common/asn_internal.h +++ b/lib/asn1c/common/asn_internal.h @@ -29,10 +29,7 @@ int get_asn1c_environment_version(void); /* Run-time version */ #define REALLOC(oldptr, size) realloc(oldptr, size) #define FREEMEM(ptr) free(ptr) #else -extern void *ogs_malloc(size_t size); -extern void ogs_free(void *ptr); -extern void *ogs_calloc(size_t nmemb, size_t size); -extern void *ogs_realloc(void *ptr, size_t size); +#include "ogs-core.h" #define CALLOC(nmemb, size) ogs_calloc(nmemb, size) #define MALLOC(size) ogs_malloc(size) #define REALLOC(oldptr, size) ogs_realloc(oldptr, size) diff --git a/lib/asn1c/common/asn_system.h b/lib/asn1c/common/asn_system.h index 001bd54dc..fa8cf1165 100644 --- a/lib/asn1c/common/asn_system.h +++ b/lib/asn1c/common/asn_system.h @@ -9,11 +9,7 @@ #define ASN_SYSTEM_H #ifdef HAVE_CONFIG_H -#if 0 /* modified by acetcom */ #include "config.h" -#else -#include "ogs-common.h" -#endif #endif #ifndef _DEFAULT_SOURCE diff --git a/lib/asn1c/common/meson.build b/lib/asn1c/common/meson.build new file mode 100644 index 000000000..7348aa40a --- /dev/null +++ b/lib/asn1c/common/meson.build @@ -0,0 +1,137 @@ +# Copyright (C) 2019 by Sukchan Lee + +# This file is part of Open5GS. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +libasn1c_common_sources = files(''' + ANY.h + OCTET_STRING.h + OPEN_TYPE.h + constr_CHOICE.h + BOOLEAN.h + INTEGER.h + NULL.h + NativeEnumerated.h + NativeInteger.h + OBJECT_IDENTIFIER.h + PrintableString.h + asn_SEQUENCE_OF.h + asn_SET_OF.h + constr_SEQUENCE.h + constr_SEQUENCE_OF.h + constr_SET_OF.h + asn_application.h + asn_ioc.h + asn_system.h + asn_codecs.h + asn_internal.h + asn_random_fill.h + asn_bit_data.h + BIT_STRING.h + asn_codecs_prim.h + ber_tlv_length.h + ber_tlv_tag.h + ber_decoder.h + der_encoder.h + constr_TYPE.h + constraints.h + xer_support.h + xer_decoder.h + xer_encoder.h + per_support.h + per_decoder.h + per_encoder.h + per_opentype.h + oer_decoder.h + oer_encoder.h + oer_support.h + + ANY.c + OPEN_TYPE.c + BOOLEAN.c + INTEGER.c + NULL.c + NativeEnumerated.c + NativeInteger.c + OBJECT_IDENTIFIER.c + PrintableString.c + asn_SEQUENCE_OF.c + asn_SET_OF.c + constr_CHOICE.c + constr_SEQUENCE.c + constr_SEQUENCE_OF.c + constr_SET_OF.c + asn_application.c + asn_internal.c + asn_random_fill.c + asn_bit_data.c + OCTET_STRING.c + BIT_STRING.c + asn_codecs_prim.c + ber_tlv_length.c + ber_tlv_tag.c + ber_decoder.c + der_encoder.c + constr_TYPE.c + constraints.c + xer_support.c + xer_decoder.c + xer_encoder.c + per_support.c + per_decoder.c + per_encoder.c + per_opentype.c + oer_decoder.c + oer_encoder.c + oer_support.c + OPEN_TYPE_oer.c + INTEGER_oer.c + BIT_STRING_oer.c + OCTET_STRING_oer.c + NativeInteger_oer.c + NativeEnumerated_oer.c + constr_CHOICE_oer.c + constr_SEQUENCE_oer.c + constr_SET_OF_oer.c +'''.split()) + +libasn1c_common_cc_flags = cc.get_supported_arguments([ + '-Wno-parentheses-equality', + '-Wno-overflow', + '-Wno-format', + + '-Wno-implicit-fallthrough', + '-Wno-missing-prototypes', + '-Wno-missing-declarations', + '-Wno-missing-field-initializers', + '-Wno-format-nonliteral', + '-Wno-format-security', + '-std=gnu99', +]) + +libasn1c_common_inc = include_directories('.') + +libasn1c_common = library('ogsasn1c-common', + sources : libasn1c_common_sources, + version : libogslib_version, + c_args : libasn1c_common_cc_flags, + include_directories : libasn1c_common_inc, + dependencies : libcore_dep, + install : true) + +libasn1c_common_dep = declare_dependency( + link_with : libasn1c_common, + include_directories : libasn1c_common_inc, + dependencies : libcore_dep) diff --git a/lib/asn1c/meson.build b/lib/asn1c/meson.build new file mode 100644 index 000000000..eadd26d12 --- /dev/null +++ b/lib/asn1c/meson.build @@ -0,0 +1,19 @@ +# Copyright (C) 2019 by Sukchan Lee + +# This file is part of Open5GS. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +subdir('common') +subdir('s1ap') diff --git a/lib/asn1c/s1ap/meson.build b/lib/asn1c/s1ap/meson.build new file mode 100644 index 000000000..c0e932ecc --- /dev/null +++ b/lib/asn1c/s1ap/meson.build @@ -0,0 +1,1065 @@ +# Copyright (C) 2019 by Sukchan Lee + +# This file is part of Open5GS. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +libasn1c_s1ap_sources = files(''' + S1AP_S1AP-PDU.h + S1AP_InitiatingMessage.h + S1AP_SuccessfulOutcome.h + S1AP_UnsuccessfulOutcome.h + S1AP_E-RAB-IE-ContainerList.h + S1AP_E-RAB-IE-ContainerPairList.h + S1AP_ProtocolError-IE-ContainerList.h + S1AP_HandoverRequired.h + S1AP_HandoverCommand.h + S1AP_E-RABSubjecttoDataForwardingList.h + S1AP_E-RABDataForwardingItem.h + S1AP_HandoverPreparationFailure.h + S1AP_HandoverRequest.h + S1AP_E-RABToBeSetupListHOReq.h + S1AP_E-RABToBeSetupItemHOReq.h + S1AP_HandoverRequestAcknowledge.h + S1AP_E-RABAdmittedList.h + S1AP_E-RABAdmittedItem.h + S1AP_E-RABFailedtoSetupListHOReqAck.h + S1AP_E-RABFailedToSetupItemHOReqAck.h + S1AP_HandoverFailure.h + S1AP_HandoverNotify.h + S1AP_PathSwitchRequest.h + S1AP_E-RABToBeSwitchedDLList.h + S1AP_E-RABToBeSwitchedDLItem.h + S1AP_PathSwitchRequestAcknowledge.h + S1AP_E-RABToBeSwitchedULList.h + S1AP_E-RABToBeSwitchedULItem.h + S1AP_PathSwitchRequestFailure.h + S1AP_HandoverCancel.h + S1AP_HandoverCancelAcknowledge.h + S1AP_E-RABSetupRequest.h + S1AP_E-RABToBeSetupListBearerSUReq.h + S1AP_E-RABToBeSetupItemBearerSUReq.h + S1AP_E-RABSetupResponse.h + S1AP_E-RABSetupListBearerSURes.h + S1AP_E-RABSetupItemBearerSURes.h + S1AP_E-RABModifyRequest.h + S1AP_E-RABToBeModifiedListBearerModReq.h + S1AP_E-RABToBeModifiedItemBearerModReq.h + S1AP_E-RABModifyResponse.h + S1AP_E-RABModifyListBearerModRes.h + S1AP_E-RABModifyItemBearerModRes.h + S1AP_E-RABReleaseCommand.h + S1AP_E-RABReleaseResponse.h + S1AP_E-RABReleaseListBearerRelComp.h + S1AP_E-RABReleaseItemBearerRelComp.h + S1AP_E-RABReleaseIndication.h + S1AP_InitialContextSetupRequest.h + S1AP_E-RABToBeSetupListCtxtSUReq.h + S1AP_E-RABToBeSetupItemCtxtSUReq.h + S1AP_InitialContextSetupResponse.h + S1AP_E-RABSetupListCtxtSURes.h + S1AP_E-RABSetupItemCtxtSURes.h + S1AP_InitialContextSetupFailure.h + S1AP_Paging.h + S1AP_TAIList.h + S1AP_TAIItem.h + S1AP_UEContextReleaseRequest.h + S1AP_UEContextReleaseCommand.h + S1AP_UEContextReleaseComplete.h + S1AP_UEContextModificationRequest.h + S1AP_UEContextModificationResponse.h + S1AP_UEContextModificationFailure.h + S1AP_UERadioCapabilityMatchRequest.h + S1AP_UERadioCapabilityMatchResponse.h + S1AP_DownlinkNASTransport.h + S1AP_InitialUEMessage.h + S1AP_UplinkNASTransport.h + S1AP_NASNonDeliveryIndication.h + S1AP_RerouteNASRequest.h + S1AP_NASDeliveryIndication.h + S1AP_Reset.h + S1AP_ResetType.h + S1AP_ResetAll.h + S1AP_UE-associatedLogicalS1-ConnectionListRes.h + S1AP_ResetAcknowledge.h + S1AP_UE-associatedLogicalS1-ConnectionListResAck.h + S1AP_ErrorIndication.h + S1AP_S1SetupRequest.h + S1AP_S1SetupResponse.h + S1AP_S1SetupFailure.h + S1AP_ENBConfigurationUpdate.h + S1AP_ENBConfigurationUpdateAcknowledge.h + S1AP_ENBConfigurationUpdateFailure.h + S1AP_MMEConfigurationUpdate.h + S1AP_MMEConfigurationUpdateAcknowledge.h + S1AP_MMEConfigurationUpdateFailure.h + S1AP_DownlinkS1cdma2000tunnelling.h + S1AP_UplinkS1cdma2000tunnelling.h + S1AP_UECapabilityInfoIndication.h + S1AP_ENBStatusTransfer.h + S1AP_MMEStatusTransfer.h + S1AP_TraceStart.h + S1AP_TraceFailureIndication.h + S1AP_DeactivateTrace.h + S1AP_CellTrafficTrace.h + S1AP_LocationReportingControl.h + S1AP_LocationReportingFailureIndication.h + S1AP_LocationReport.h + S1AP_OverloadStart.h + S1AP_OverloadStop.h + S1AP_WriteReplaceWarningRequest.h + S1AP_WriteReplaceWarningResponse.h + S1AP_ENBDirectInformationTransfer.h + S1AP_Inter-SystemInformationTransferType.h + S1AP_MMEDirectInformationTransfer.h + S1AP_ENBConfigurationTransfer.h + S1AP_MMEConfigurationTransfer.h + S1AP_PrivateMessage.h + S1AP_KillRequest.h + S1AP_KillResponse.h + S1AP_PWSRestartIndication.h + S1AP_PWSFailureIndication.h + S1AP_DownlinkUEAssociatedLPPaTransport.h + S1AP_UplinkUEAssociatedLPPaTransport.h + S1AP_DownlinkNonUEAssociatedLPPaTransport.h + S1AP_UplinkNonUEAssociatedLPPaTransport.h + S1AP_E-RABModificationIndication.h + S1AP_E-RABToBeModifiedListBearerModInd.h + S1AP_E-RABToBeModifiedItemBearerModInd.h + S1AP_E-RABNotToBeModifiedListBearerModInd.h + S1AP_E-RABNotToBeModifiedItemBearerModInd.h + S1AP_CSGMembershipInfo.h + S1AP_E-RABModificationConfirm.h + S1AP_E-RABModifyListBearerModConf.h + S1AP_E-RABModifyItemBearerModConf.h + S1AP_UEContextModificationIndication.h + S1AP_UEContextModificationConfirm.h + S1AP_UEContextSuspendRequest.h + S1AP_UEContextSuspendResponse.h + S1AP_UEContextResumeRequest.h + S1AP_E-RABFailedToResumeListResumeReq.h + S1AP_E-RABFailedToResumeItemResumeReq.h + S1AP_UEContextResumeResponse.h + S1AP_E-RABFailedToResumeListResumeRes.h + S1AP_E-RABFailedToResumeItemResumeRes.h + S1AP_UEContextResumeFailure.h + S1AP_ConnectionEstablishmentIndication.h + S1AP_RetrieveUEInformation.h + S1AP_UEInformationTransfer.h + S1AP_ENBCPRelocationIndication.h + S1AP_MMECPRelocationIndication.h + S1AP_Additional-GUTI.h + S1AP_AreaScopeOfMDT.h + S1AP_AllocationAndRetentionPriority.h + S1AP_AssistanceDataForCECapableUEs.h + S1AP_AssistanceDataForPaging.h + S1AP_AssistanceDataForRecommendedCells.h + S1AP_Bearers-SubjectToStatusTransferList.h + S1AP_Bearers-SubjectToStatusTransfer-Item.h + S1AP_BearerType.h + S1AP_BitRate.h + S1AP_BPLMNs.h + S1AP_BroadcastCancelledAreaList.h + S1AP_BroadcastCompletedAreaList.h + S1AP_CancelledCellinEAI.h + S1AP_CancelledCellinEAI-Item.h + S1AP_CancelledCellinTAI.h + S1AP_CancelledCellinTAI-Item.h + S1AP_Cause.h + S1AP_CauseMisc.h + S1AP_CauseProtocol.h + S1AP_CauseRadioNetwork.h + S1AP_CauseTransport.h + S1AP_CauseNas.h + S1AP_CellAccessMode.h + S1AP_CellIdentifierAndCELevelForCECapableUEs.h + S1AP_CELevel.h + S1AP_CE-mode-B-SupportIndicator.h + S1AP_CellIdentity.h + S1AP_CellID-Broadcast.h + S1AP_CellID-Broadcast-Item.h + S1AP_CellID-Cancelled.h + S1AP_CellID-Cancelled-Item.h + S1AP_CellBasedMDT.h + S1AP_CellIdListforMDT.h + S1AP_Cdma2000PDU.h + S1AP_Cdma2000RATType.h + S1AP_Cdma2000SectorID.h + S1AP_Cdma2000HOStatus.h + S1AP_Cdma2000HORequiredIndication.h + S1AP_Cdma2000OneXSRVCCInfo.h + S1AP_Cdma2000OneXMEID.h + S1AP_Cdma2000OneXMSI.h + S1AP_Cdma2000OneXPilot.h + S1AP_Cdma2000OneXRAND.h + S1AP_Cell-Size.h + S1AP_CellType.h + S1AP_CGI.h + S1AP_CI.h + S1AP_CNDomain.h + S1AP_ConcurrentWarningMessageIndicator.h + S1AP_Correlation-ID.h + S1AP_CSFallbackIndicator.h + S1AP_AdditionalCSFallbackIndicator.h + S1AP_CSG-Id.h + S1AP_CSG-IdList.h + S1AP_CSG-IdList-Item.h + S1AP_CSGMembershipStatus.h + S1AP_COUNTvalue.h + S1AP_COUNTValueExtended.h + S1AP_COUNTvaluePDCP-SNlength18.h + S1AP_Coverage-Level.h + S1AP_CriticalityDiagnostics.h + S1AP_CriticalityDiagnostics-IE-List.h + S1AP_CriticalityDiagnostics-IE-Item.h + S1AP_DataCodingScheme.h + S1AP_DCN-ID.h + S1AP_ServedDCNs.h + S1AP_ServedDCNsItem.h + S1AP_DL-CP-SecurityInformation.h + S1AP_DL-Forwarding.h + S1AP_DL-NAS-MAC.h + S1AP_Direct-Forwarding-Path-Availability.h + S1AP_Data-Forwarding-Not-Possible.h + S1AP_DLNASPDUDeliveryAckRequest.h + S1AP_EARFCN.h + S1AP_ECGIList.h + S1AP_PWSfailedECGIList.h + S1AP_EmergencyAreaIDList.h + S1AP_EmergencyAreaID.h + S1AP_EmergencyAreaID-Broadcast.h + S1AP_EmergencyAreaID-Broadcast-Item.h + S1AP_EmergencyAreaID-Cancelled.h + S1AP_EmergencyAreaID-Cancelled-Item.h + S1AP_CompletedCellinEAI.h + S1AP_CompletedCellinEAI-Item.h + S1AP_ECGI-List.h + S1AP_EmergencyAreaIDListForRestart.h + S1AP_ENB-ID.h + S1AP_GERAN-Cell-ID.h + S1AP_Global-ENB-ID.h + S1AP_GUMMEIList.h + S1AP_ENB-StatusTransfer-TransparentContainer.h + S1AP_ENB-UE-S1AP-ID.h + S1AP_ENBname.h + S1AP_ENBX2TLAs.h + S1AP_EncryptionAlgorithms.h + S1AP_EnhancedCoverageRestricted.h + S1AP_EPLMNs.h + S1AP_EventType.h + S1AP_E-RAB-ID.h + S1AP_E-RABInformationList.h + S1AP_E-RABInformationListItem.h + S1AP_E-RABList.h + S1AP_E-RABItem.h + S1AP_E-RABLevelQoSParameters.h + S1AP_EUTRAN-CGI.h + S1AP_EUTRANRoundTripDelayEstimationInfo.h + S1AP_ExpectedUEBehaviour.h + S1AP_ExpectedUEActivityBehaviour.h + S1AP_ExpectedActivityPeriod.h + S1AP_ExpectedIdlePeriod.h + S1AP_SourceOfUEActivityBehaviourInformation.h + S1AP_ExpectedHOInterval.h + S1AP_ExtendedRNC-ID.h + S1AP_ExtendedRepetitionPeriod.h + S1AP_Extended-UEIdentityIndexValue.h + S1AP_ForbiddenInterRATs.h + S1AP_ForbiddenTAs.h + S1AP_ForbiddenTAs-Item.h + S1AP_ForbiddenTACs.h + S1AP_ForbiddenLAs.h + S1AP_ForbiddenLAs-Item.h + S1AP_ForbiddenLACs.h + S1AP_GBR-QosInformation.h + S1AP_GTP-TEID.h + S1AP_GUMMEI.h + S1AP_GUMMEIType.h + S1AP_GWContextReleaseIndication.h + S1AP_HandoverRestrictionList.h + S1AP_HandoverType.h + S1AP_HFN.h + S1AP_HFNModified.h + S1AP_HFNforPDCP-SNlength18.h + S1AP_Masked-IMEISV.h + S1AP_ImmediateMDT.h + S1AP_IMSI.h + S1AP_InformationOnRecommendedCellsAndENBsForPaging.h + S1AP_IntegrityProtectionAlgorithms.h + S1AP_IntendedNumberOfPagingAttempts.h + S1AP_InterfacesToTrace.h + S1AP_KillAllWarningMessages.h + S1AP_LAC.h + S1AP_LAI.h + S1AP_LastVisitedCell-Item.h + S1AP_LastVisitedEUTRANCellInformation.h + S1AP_LastVisitedUTRANCellInformation.h + S1AP_LastVisitedGERANCellInformation.h + S1AP_L3-Information.h + S1AP_LPPa-PDU.h + S1AP_LHN-ID.h + S1AP_Links-to-log.h + S1AP_ListeningSubframePattern.h + S1AP_LoggedMDT.h + S1AP_LoggingInterval.h + S1AP_LoggingDuration.h + S1AP_LoggedMBSFNMDT.h + S1AP_M3Configuration.h + S1AP_M3period.h + S1AP_M4Configuration.h + S1AP_M4period.h + S1AP_M5Configuration.h + S1AP_M5period.h + S1AP_M6Configuration.h + S1AP_M6report-Interval.h + S1AP_M6delay-threshold.h + S1AP_M7Configuration.h + S1AP_M7period.h + S1AP_MDT-Activation.h + S1AP_MDT-Location-Info.h + S1AP_MDT-Configuration.h + S1AP_ManagementBasedMDTAllowed.h + S1AP_MBSFN-ResultToLog.h + S1AP_MBSFN-ResultToLogInfo.h + S1AP_MDTPLMNList.h + S1AP_PrivacyIndicator.h + S1AP_MDTMode.h + S1AP_MDTMode-Extension.h + S1AP_MeasurementsToActivate.h + S1AP_MeasurementThresholdA2.h + S1AP_MessageIdentifier.h + S1AP_MobilityInformation.h + S1AP_MMEname.h + S1AP_MMEPagingTarget.h + S1AP_MMERelaySupportIndicator.h + S1AP_MME-Group-ID.h + S1AP_MME-Code.h + S1AP_MME-UE-S1AP-ID.h + S1AP_M-TMSI.h + S1AP_MSClassmark2.h + S1AP_MSClassmark3.h + S1AP_MutingAvailabilityIndication.h + S1AP_MutingPatternInformation.h + S1AP_NAS-PDU.h + S1AP_NASSecurityParametersfromE-UTRAN.h + S1AP_NASSecurityParameterstoE-UTRAN.h + S1AP_NB-IoT-DefaultPagingDRX.h + S1AP_NB-IoT-Paging-eDRXInformation.h + S1AP_NB-IoT-Paging-eDRX-Cycle.h + S1AP_NB-IoT-PagingTimeWindow.h + S1AP_NB-IoT-UEIdentityIndexValue.h + S1AP_NextPagingAreaScope.h + S1AP_NumberofBroadcastRequest.h + S1AP_NumberOfBroadcasts.h + S1AP_OldBSS-ToNewBSS-Information.h + S1AP_OverloadAction.h + S1AP_OverloadResponse.h + S1AP_PagingAttemptInformation.h + S1AP_PagingAttemptCount.h + S1AP_Paging-eDRXInformation.h + S1AP_Paging-eDRX-Cycle.h + S1AP_PagingTimeWindow.h + S1AP_PagingDRX.h + S1AP_PagingPriority.h + S1AP_PDCP-SN.h + S1AP_PDCP-SNExtended.h + S1AP_PDCP-SNlength18.h + S1AP_M1PeriodicReporting.h + S1AP_PLMNidentity.h + S1AP_Port-Number.h + S1AP_Pre-emptionCapability.h + S1AP_Pre-emptionVulnerability.h + S1AP_PriorityLevel.h + S1AP_ProSeAuthorized.h + S1AP_ProSeDirectDiscovery.h + S1AP_ProSeUEtoNetworkRelaying.h + S1AP_ProSeDirectCommunication.h + S1AP_PS-ServiceNotAvailable.h + S1AP_QCI.h + S1AP_ReceiveStatusofULPDCPSDUs.h + S1AP_ReceiveStatusOfULPDCPSDUsExtended.h + S1AP_ReceiveStatusOfULPDCPSDUsPDCP-SNlength18.h + S1AP_RecommendedCellsForPaging.h + S1AP_RecommendedCellList.h + S1AP_RecommendedCellItem.h + S1AP_RecommendedENBsForPaging.h + S1AP_RecommendedENBList.h + S1AP_RecommendedENBItem.h + S1AP_RelativeMMECapacity.h + S1AP_RelayNode-Indicator.h + S1AP_RAC.h + S1AP_RAT-Type.h + S1AP_ReportAmountMDT.h + S1AP_ReportIntervalMDT.h + S1AP_M1ReportingTrigger.h + S1AP_RequestType.h + S1AP_RIMTransfer.h + S1AP_RIMInformation.h + S1AP_RIMRoutingAddress.h + S1AP_ReportArea.h + S1AP_RepetitionPeriod.h + S1AP_RLFReportInformation.h + S1AP_RNC-ID.h + S1AP_RRC-Container.h + S1AP_RRC-Establishment-Cause.h + S1AP_ECGIListForRestart.h + S1AP_Routing-ID.h + S1AP_SecurityKey.h + S1AP_SecurityContext.h + S1AP_SerialNumber.h + S1AP_SONInformation.h + S1AP_SONInformation-Extension.h + S1AP_SONInformationRequest.h + S1AP_SONInformationReply.h + S1AP_SONInformationReport.h + S1AP_SONConfigurationTransfer.h + S1AP_SynchronisationInformation.h + S1AP_Source-ToTarget-TransparentContainer.h + S1AP_SourceBSS-ToTargetBSS-TransparentContainer.h + S1AP_SourceeNB-ID.h + S1AP_SRVCCOperationNotPossible.h + S1AP_SRVCCOperationPossible.h + S1AP_SRVCCHOIndication.h + S1AP_SourceeNB-ToTargeteNB-TransparentContainer.h + S1AP_SourceRNC-ToTargetRNC-TransparentContainer.h + S1AP_ServedGUMMEIs.h + S1AP_ServedGUMMEIsItem.h + S1AP_ServedGroupIDs.h + S1AP_ServedMMECs.h + S1AP_ServedPLMNs.h + S1AP_SubscriberProfileIDforRFP.h + S1AP_SupportedTAs.h + S1AP_SupportedTAs-Item.h + S1AP_StratumLevel.h + S1AP_SynchronisationStatus.h + S1AP_TimeSynchronisationInfo.h + S1AP_S-TMSI.h + S1AP_TAC.h + S1AP_TAIBasedMDT.h + S1AP_TAIListforMDT.h + S1AP_TAIListforWarning.h + S1AP_TAI.h + S1AP_TAI-Broadcast.h + S1AP_TAI-Broadcast-Item.h + S1AP_TAI-Cancelled.h + S1AP_TAI-Cancelled-Item.h + S1AP_TABasedMDT.h + S1AP_TAListforMDT.h + S1AP_CompletedCellinTAI.h + S1AP_CompletedCellinTAI-Item.h + S1AP_TBCD-STRING.h + S1AP_TargetID.h + S1AP_TargeteNB-ID.h + S1AP_TargetRNC-ID.h + S1AP_TargeteNB-ToSourceeNB-TransparentContainer.h + S1AP_Target-ToSource-TransparentContainer.h + S1AP_TargetRNC-ToSourceRNC-TransparentContainer.h + S1AP_TargetBSS-ToSourceBSS-TransparentContainer.h + S1AP_M1ThresholdEventA2.h + S1AP_Threshold-RSRP.h + S1AP_Threshold-RSRQ.h + S1AP_TimeToWait.h + S1AP_Time-UE-StayedInCell.h + S1AP_Time-UE-StayedInCell-EnhancedGranularity.h + S1AP_TransportInformation.h + S1AP_TransportLayerAddress.h + S1AP_TraceActivation.h + S1AP_TraceDepth.h + S1AP_E-UTRAN-Trace-ID.h + S1AP_TrafficLoadReductionIndication.h + S1AP_TunnelInformation.h + S1AP_TypeOfError.h + S1AP_TAIListForRestart.h + S1AP_UEAggregateMaximumBitrate.h + S1AP_UE-RetentionInformation.h + S1AP_UE-S1AP-IDs.h + S1AP_UE-S1AP-ID-pair.h + S1AP_UE-associatedLogicalS1-ConnectionItem.h + S1AP_UEIdentityIndexValue.h + S1AP_UE-HistoryInformation.h + S1AP_UE-HistoryInformationFromTheUE.h + S1AP_UEPagingID.h + S1AP_UERadioCapability.h + S1AP_UERadioCapabilityForPaging.h + S1AP_UE-RLF-Report-Container.h + S1AP_UE-RLF-Report-Container-for-extended-bands.h + S1AP_UESecurityCapabilities.h + S1AP_UESidelinkAggregateMaximumBitrate.h + S1AP_UE-Usage-Type.h + S1AP_UL-CP-SecurityInformation.h + S1AP_UL-NAS-MAC.h + S1AP_UL-NAS-Count.h + S1AP_UserLocationInformation.h + S1AP_UEUserPlaneCIoTSupportIndicator.h + S1AP_VoiceSupportMatchIndicator.h + S1AP_V2XServicesAuthorized.h + S1AP_VehicleUE.h + S1AP_PedestrianUE.h + S1AP_WarningAreaList.h + S1AP_WarningType.h + S1AP_WarningSecurityInfo.h + S1AP_WarningMessageContents.h + S1AP_X2TNLConfigurationInfo.h + S1AP_ENBX2ExtTLAs.h + S1AP_ENBX2ExtTLA.h + S1AP_ENBX2GTPTLAs.h + S1AP_ENBIndirectX2TransportLayerAddresses.h + S1AP_Criticality.h + S1AP_Presence.h + S1AP_PrivateIE-ID.h + S1AP_ProcedureCode.h + S1AP_ProtocolExtensionID.h + S1AP_ProtocolIE-ID.h + S1AP_TriggeringMessage.h + S1AP_ProtocolIE-Container.h + S1AP_ProtocolIE-SingleContainer.h + S1AP_ProtocolIE-Field.h + S1AP_ProtocolIE-ContainerPair.h + S1AP_ProtocolIE-FieldPair.h + S1AP_ProtocolIE-ContainerList.h + S1AP_ProtocolIE-ContainerPairList.h + S1AP_ProtocolExtensionContainer.h + S1AP_ProtocolExtensionField.h + S1AP_PrivateIE-Container.h + S1AP_PrivateIE-Field.h + S1AP_asn_constant.h + + S1AP_S1AP-PDU.c + S1AP_InitiatingMessage.c + S1AP_SuccessfulOutcome.c + S1AP_UnsuccessfulOutcome.c + S1AP_E-RAB-IE-ContainerList.c + S1AP_HandoverRequired.c + S1AP_HandoverCommand.c + S1AP_E-RABSubjecttoDataForwardingList.c + S1AP_E-RABDataForwardingItem.c + S1AP_HandoverPreparationFailure.c + S1AP_HandoverRequest.c + S1AP_E-RABToBeSetupListHOReq.c + S1AP_E-RABToBeSetupItemHOReq.c + S1AP_HandoverRequestAcknowledge.c + S1AP_E-RABAdmittedList.c + S1AP_E-RABAdmittedItem.c + S1AP_E-RABFailedtoSetupListHOReqAck.c + S1AP_E-RABFailedToSetupItemHOReqAck.c + S1AP_HandoverFailure.c + S1AP_HandoverNotify.c + S1AP_PathSwitchRequest.c + S1AP_E-RABToBeSwitchedDLList.c + S1AP_E-RABToBeSwitchedDLItem.c + S1AP_PathSwitchRequestAcknowledge.c + S1AP_E-RABToBeSwitchedULList.c + S1AP_E-RABToBeSwitchedULItem.c + S1AP_PathSwitchRequestFailure.c + S1AP_HandoverCancel.c + S1AP_HandoverCancelAcknowledge.c + S1AP_E-RABSetupRequest.c + S1AP_E-RABToBeSetupListBearerSUReq.c + S1AP_E-RABToBeSetupItemBearerSUReq.c + S1AP_E-RABSetupResponse.c + S1AP_E-RABSetupListBearerSURes.c + S1AP_E-RABSetupItemBearerSURes.c + S1AP_E-RABModifyRequest.c + S1AP_E-RABToBeModifiedListBearerModReq.c + S1AP_E-RABToBeModifiedItemBearerModReq.c + S1AP_E-RABModifyResponse.c + S1AP_E-RABModifyListBearerModRes.c + S1AP_E-RABModifyItemBearerModRes.c + S1AP_E-RABReleaseCommand.c + S1AP_E-RABReleaseResponse.c + S1AP_E-RABReleaseListBearerRelComp.c + S1AP_E-RABReleaseItemBearerRelComp.c + S1AP_E-RABReleaseIndication.c + S1AP_InitialContextSetupRequest.c + S1AP_E-RABToBeSetupListCtxtSUReq.c + S1AP_E-RABToBeSetupItemCtxtSUReq.c + S1AP_InitialContextSetupResponse.c + S1AP_E-RABSetupListCtxtSURes.c + S1AP_E-RABSetupItemCtxtSURes.c + S1AP_InitialContextSetupFailure.c + S1AP_Paging.c + S1AP_TAIList.c + S1AP_TAIItem.c + S1AP_UEContextReleaseRequest.c + S1AP_UEContextReleaseCommand.c + S1AP_UEContextReleaseComplete.c + S1AP_UEContextModificationRequest.c + S1AP_UEContextModificationResponse.c + S1AP_UEContextModificationFailure.c + S1AP_UERadioCapabilityMatchRequest.c + S1AP_UERadioCapabilityMatchResponse.c + S1AP_DownlinkNASTransport.c + S1AP_InitialUEMessage.c + S1AP_UplinkNASTransport.c + S1AP_NASNonDeliveryIndication.c + S1AP_RerouteNASRequest.c + S1AP_NASDeliveryIndication.c + S1AP_Reset.c + S1AP_ResetType.c + S1AP_ResetAll.c + S1AP_UE-associatedLogicalS1-ConnectionListRes.c + S1AP_ResetAcknowledge.c + S1AP_UE-associatedLogicalS1-ConnectionListResAck.c + S1AP_ErrorIndication.c + S1AP_S1SetupRequest.c + S1AP_S1SetupResponse.c + S1AP_S1SetupFailure.c + S1AP_ENBConfigurationUpdate.c + S1AP_ENBConfigurationUpdateAcknowledge.c + S1AP_ENBConfigurationUpdateFailure.c + S1AP_MMEConfigurationUpdate.c + S1AP_MMEConfigurationUpdateAcknowledge.c + S1AP_MMEConfigurationUpdateFailure.c + S1AP_DownlinkS1cdma2000tunnelling.c + S1AP_UplinkS1cdma2000tunnelling.c + S1AP_UECapabilityInfoIndication.c + S1AP_ENBStatusTransfer.c + S1AP_MMEStatusTransfer.c + S1AP_TraceStart.c + S1AP_TraceFailureIndication.c + S1AP_DeactivateTrace.c + S1AP_CellTrafficTrace.c + S1AP_LocationReportingControl.c + S1AP_LocationReportingFailureIndication.c + S1AP_LocationReport.c + S1AP_OverloadStart.c + S1AP_OverloadStop.c + S1AP_WriteReplaceWarningRequest.c + S1AP_WriteReplaceWarningResponse.c + S1AP_ENBDirectInformationTransfer.c + S1AP_Inter-SystemInformationTransferType.c + S1AP_MMEDirectInformationTransfer.c + S1AP_ENBConfigurationTransfer.c + S1AP_MMEConfigurationTransfer.c + S1AP_PrivateMessage.c + S1AP_KillRequest.c + S1AP_KillResponse.c + S1AP_PWSRestartIndication.c + S1AP_PWSFailureIndication.c + S1AP_DownlinkUEAssociatedLPPaTransport.c + S1AP_UplinkUEAssociatedLPPaTransport.c + S1AP_DownlinkNonUEAssociatedLPPaTransport.c + S1AP_UplinkNonUEAssociatedLPPaTransport.c + S1AP_E-RABModificationIndication.c + S1AP_E-RABToBeModifiedListBearerModInd.c + S1AP_E-RABToBeModifiedItemBearerModInd.c + S1AP_E-RABNotToBeModifiedListBearerModInd.c + S1AP_E-RABNotToBeModifiedItemBearerModInd.c + S1AP_CSGMembershipInfo.c + S1AP_E-RABModificationConfirm.c + S1AP_E-RABModifyListBearerModConf.c + S1AP_E-RABModifyItemBearerModConf.c + S1AP_UEContextModificationIndication.c + S1AP_UEContextModificationConfirm.c + S1AP_UEContextSuspendRequest.c + S1AP_UEContextSuspendResponse.c + S1AP_UEContextResumeRequest.c + S1AP_E-RABFailedToResumeListResumeReq.c + S1AP_E-RABFailedToResumeItemResumeReq.c + S1AP_UEContextResumeResponse.c + S1AP_E-RABFailedToResumeListResumeRes.c + S1AP_E-RABFailedToResumeItemResumeRes.c + S1AP_UEContextResumeFailure.c + S1AP_ConnectionEstablishmentIndication.c + S1AP_RetrieveUEInformation.c + S1AP_UEInformationTransfer.c + S1AP_ENBCPRelocationIndication.c + S1AP_MMECPRelocationIndication.c + S1AP_Additional-GUTI.c + S1AP_AreaScopeOfMDT.c + S1AP_AllocationAndRetentionPriority.c + S1AP_AssistanceDataForCECapableUEs.c + S1AP_AssistanceDataForPaging.c + S1AP_AssistanceDataForRecommendedCells.c + S1AP_Bearers-SubjectToStatusTransferList.c + S1AP_Bearers-SubjectToStatusTransfer-Item.c + S1AP_BearerType.c + S1AP_BitRate.c + S1AP_BPLMNs.c + S1AP_BroadcastCancelledAreaList.c + S1AP_BroadcastCompletedAreaList.c + S1AP_CancelledCellinEAI.c + S1AP_CancelledCellinEAI-Item.c + S1AP_CancelledCellinTAI.c + S1AP_CancelledCellinTAI-Item.c + S1AP_Cause.c + S1AP_CauseMisc.c + S1AP_CauseProtocol.c + S1AP_CauseRadioNetwork.c + S1AP_CauseTransport.c + S1AP_CauseNas.c + S1AP_CellAccessMode.c + S1AP_CellIdentifierAndCELevelForCECapableUEs.c + S1AP_CELevel.c + S1AP_CE-mode-B-SupportIndicator.c + S1AP_CellIdentity.c + S1AP_CellID-Broadcast.c + S1AP_CellID-Broadcast-Item.c + S1AP_CellID-Cancelled.c + S1AP_CellID-Cancelled-Item.c + S1AP_CellBasedMDT.c + S1AP_CellIdListforMDT.c + S1AP_Cdma2000PDU.c + S1AP_Cdma2000RATType.c + S1AP_Cdma2000SectorID.c + S1AP_Cdma2000HOStatus.c + S1AP_Cdma2000HORequiredIndication.c + S1AP_Cdma2000OneXSRVCCInfo.c + S1AP_Cdma2000OneXMEID.c + S1AP_Cdma2000OneXMSI.c + S1AP_Cdma2000OneXPilot.c + S1AP_Cdma2000OneXRAND.c + S1AP_Cell-Size.c + S1AP_CellType.c + S1AP_CGI.c + S1AP_CI.c + S1AP_CNDomain.c + S1AP_ConcurrentWarningMessageIndicator.c + S1AP_Correlation-ID.c + S1AP_CSFallbackIndicator.c + S1AP_AdditionalCSFallbackIndicator.c + S1AP_CSG-Id.c + S1AP_CSG-IdList.c + S1AP_CSG-IdList-Item.c + S1AP_CSGMembershipStatus.c + S1AP_COUNTvalue.c + S1AP_COUNTValueExtended.c + S1AP_COUNTvaluePDCP-SNlength18.c + S1AP_Coverage-Level.c + S1AP_CriticalityDiagnostics.c + S1AP_CriticalityDiagnostics-IE-List.c + S1AP_CriticalityDiagnostics-IE-Item.c + S1AP_DataCodingScheme.c + S1AP_DCN-ID.c + S1AP_ServedDCNs.c + S1AP_ServedDCNsItem.c + S1AP_DL-CP-SecurityInformation.c + S1AP_DL-Forwarding.c + S1AP_DL-NAS-MAC.c + S1AP_Direct-Forwarding-Path-Availability.c + S1AP_Data-Forwarding-Not-Possible.c + S1AP_DLNASPDUDeliveryAckRequest.c + S1AP_EARFCN.c + S1AP_ECGIList.c + S1AP_PWSfailedECGIList.c + S1AP_EmergencyAreaIDList.c + S1AP_EmergencyAreaID.c + S1AP_EmergencyAreaID-Broadcast.c + S1AP_EmergencyAreaID-Broadcast-Item.c + S1AP_EmergencyAreaID-Cancelled.c + S1AP_EmergencyAreaID-Cancelled-Item.c + S1AP_CompletedCellinEAI.c + S1AP_CompletedCellinEAI-Item.c + S1AP_ECGI-List.c + S1AP_EmergencyAreaIDListForRestart.c + S1AP_ENB-ID.c + S1AP_GERAN-Cell-ID.c + S1AP_Global-ENB-ID.c + S1AP_GUMMEIList.c + S1AP_ENB-StatusTransfer-TransparentContainer.c + S1AP_ENB-UE-S1AP-ID.c + S1AP_ENBname.c + S1AP_ENBX2TLAs.c + S1AP_EncryptionAlgorithms.c + S1AP_EnhancedCoverageRestricted.c + S1AP_EPLMNs.c + S1AP_EventType.c + S1AP_E-RAB-ID.c + S1AP_E-RABInformationList.c + S1AP_E-RABInformationListItem.c + S1AP_E-RABList.c + S1AP_E-RABItem.c + S1AP_E-RABLevelQoSParameters.c + S1AP_EUTRAN-CGI.c + S1AP_EUTRANRoundTripDelayEstimationInfo.c + S1AP_ExpectedUEBehaviour.c + S1AP_ExpectedUEActivityBehaviour.c + S1AP_ExpectedActivityPeriod.c + S1AP_ExpectedIdlePeriod.c + S1AP_SourceOfUEActivityBehaviourInformation.c + S1AP_ExpectedHOInterval.c + S1AP_ExtendedRNC-ID.c + S1AP_ExtendedRepetitionPeriod.c + S1AP_Extended-UEIdentityIndexValue.c + S1AP_ForbiddenInterRATs.c + S1AP_ForbiddenTAs.c + S1AP_ForbiddenTAs-Item.c + S1AP_ForbiddenTACs.c + S1AP_ForbiddenLAs.c + S1AP_ForbiddenLAs-Item.c + S1AP_ForbiddenLACs.c + S1AP_GBR-QosInformation.c + S1AP_GTP-TEID.c + S1AP_GUMMEI.c + S1AP_GUMMEIType.c + S1AP_GWContextReleaseIndication.c + S1AP_HandoverRestrictionList.c + S1AP_HandoverType.c + S1AP_HFN.c + S1AP_HFNModified.c + S1AP_HFNforPDCP-SNlength18.c + S1AP_Masked-IMEISV.c + S1AP_ImmediateMDT.c + S1AP_IMSI.c + S1AP_InformationOnRecommendedCellsAndENBsForPaging.c + S1AP_IntegrityProtectionAlgorithms.c + S1AP_IntendedNumberOfPagingAttempts.c + S1AP_InterfacesToTrace.c + S1AP_KillAllWarningMessages.c + S1AP_LAC.c + S1AP_LAI.c + S1AP_LastVisitedCell-Item.c + S1AP_LastVisitedEUTRANCellInformation.c + S1AP_LastVisitedUTRANCellInformation.c + S1AP_LastVisitedGERANCellInformation.c + S1AP_L3-Information.c + S1AP_LPPa-PDU.c + S1AP_LHN-ID.c + S1AP_Links-to-log.c + S1AP_ListeningSubframePattern.c + S1AP_LoggedMDT.c + S1AP_LoggingInterval.c + S1AP_LoggingDuration.c + S1AP_LoggedMBSFNMDT.c + S1AP_M3Configuration.c + S1AP_M3period.c + S1AP_M4Configuration.c + S1AP_M4period.c + S1AP_M5Configuration.c + S1AP_M5period.c + S1AP_M6Configuration.c + S1AP_M6report-Interval.c + S1AP_M6delay-threshold.c + S1AP_M7Configuration.c + S1AP_M7period.c + S1AP_MDT-Activation.c + S1AP_MDT-Location-Info.c + S1AP_MDT-Configuration.c + S1AP_ManagementBasedMDTAllowed.c + S1AP_MBSFN-ResultToLog.c + S1AP_MBSFN-ResultToLogInfo.c + S1AP_MDTPLMNList.c + S1AP_PrivacyIndicator.c + S1AP_MDTMode.c + S1AP_MDTMode-Extension.c + S1AP_MeasurementsToActivate.c + S1AP_MeasurementThresholdA2.c + S1AP_MessageIdentifier.c + S1AP_MobilityInformation.c + S1AP_MMEname.c + S1AP_MMEPagingTarget.c + S1AP_MMERelaySupportIndicator.c + S1AP_MME-Group-ID.c + S1AP_MME-Code.c + S1AP_MME-UE-S1AP-ID.c + S1AP_M-TMSI.c + S1AP_MSClassmark2.c + S1AP_MSClassmark3.c + S1AP_MutingAvailabilityIndication.c + S1AP_MutingPatternInformation.c + S1AP_NAS-PDU.c + S1AP_NASSecurityParametersfromE-UTRAN.c + S1AP_NASSecurityParameterstoE-UTRAN.c + S1AP_NB-IoT-DefaultPagingDRX.c + S1AP_NB-IoT-Paging-eDRXInformation.c + S1AP_NB-IoT-Paging-eDRX-Cycle.c + S1AP_NB-IoT-PagingTimeWindow.c + S1AP_NB-IoT-UEIdentityIndexValue.c + S1AP_NextPagingAreaScope.c + S1AP_NumberofBroadcastRequest.c + S1AP_NumberOfBroadcasts.c + S1AP_OldBSS-ToNewBSS-Information.c + S1AP_OverloadAction.c + S1AP_OverloadResponse.c + S1AP_PagingAttemptInformation.c + S1AP_PagingAttemptCount.c + S1AP_Paging-eDRXInformation.c + S1AP_Paging-eDRX-Cycle.c + S1AP_PagingTimeWindow.c + S1AP_PagingDRX.c + S1AP_PagingPriority.c + S1AP_PDCP-SN.c + S1AP_PDCP-SNExtended.c + S1AP_PDCP-SNlength18.c + S1AP_M1PeriodicReporting.c + S1AP_PLMNidentity.c + S1AP_Port-Number.c + S1AP_Pre-emptionCapability.c + S1AP_Pre-emptionVulnerability.c + S1AP_PriorityLevel.c + S1AP_ProSeAuthorized.c + S1AP_ProSeDirectDiscovery.c + S1AP_ProSeUEtoNetworkRelaying.c + S1AP_ProSeDirectCommunication.c + S1AP_PS-ServiceNotAvailable.c + S1AP_QCI.c + S1AP_ReceiveStatusofULPDCPSDUs.c + S1AP_ReceiveStatusOfULPDCPSDUsExtended.c + S1AP_ReceiveStatusOfULPDCPSDUsPDCP-SNlength18.c + S1AP_RecommendedCellsForPaging.c + S1AP_RecommendedCellList.c + S1AP_RecommendedCellItem.c + S1AP_RecommendedENBsForPaging.c + S1AP_RecommendedENBList.c + S1AP_RecommendedENBItem.c + S1AP_RelativeMMECapacity.c + S1AP_RelayNode-Indicator.c + S1AP_RAC.c + S1AP_RAT-Type.c + S1AP_ReportAmountMDT.c + S1AP_ReportIntervalMDT.c + S1AP_M1ReportingTrigger.c + S1AP_RequestType.c + S1AP_RIMTransfer.c + S1AP_RIMInformation.c + S1AP_RIMRoutingAddress.c + S1AP_ReportArea.c + S1AP_RepetitionPeriod.c + S1AP_RLFReportInformation.c + S1AP_RNC-ID.c + S1AP_RRC-Container.c + S1AP_RRC-Establishment-Cause.c + S1AP_ECGIListForRestart.c + S1AP_Routing-ID.c + S1AP_SecurityKey.c + S1AP_SecurityContext.c + S1AP_SerialNumber.c + S1AP_SONInformation.c + S1AP_SONInformation-Extension.c + S1AP_SONInformationRequest.c + S1AP_SONInformationReply.c + S1AP_SONInformationReport.c + S1AP_SONConfigurationTransfer.c + S1AP_SynchronisationInformation.c + S1AP_Source-ToTarget-TransparentContainer.c + S1AP_SourceBSS-ToTargetBSS-TransparentContainer.c + S1AP_SourceeNB-ID.c + S1AP_SRVCCOperationNotPossible.c + S1AP_SRVCCOperationPossible.c + S1AP_SRVCCHOIndication.c + S1AP_SourceeNB-ToTargeteNB-TransparentContainer.c + S1AP_SourceRNC-ToTargetRNC-TransparentContainer.c + S1AP_ServedGUMMEIs.c + S1AP_ServedGUMMEIsItem.c + S1AP_ServedGroupIDs.c + S1AP_ServedMMECs.c + S1AP_ServedPLMNs.c + S1AP_SubscriberProfileIDforRFP.c + S1AP_SupportedTAs.c + S1AP_SupportedTAs-Item.c + S1AP_StratumLevel.c + S1AP_SynchronisationStatus.c + S1AP_TimeSynchronisationInfo.c + S1AP_S-TMSI.c + S1AP_TAC.c + S1AP_TAIBasedMDT.c + S1AP_TAIListforMDT.c + S1AP_TAIListforWarning.c + S1AP_TAI.c + S1AP_TAI-Broadcast.c + S1AP_TAI-Broadcast-Item.c + S1AP_TAI-Cancelled.c + S1AP_TAI-Cancelled-Item.c + S1AP_TABasedMDT.c + S1AP_TAListforMDT.c + S1AP_CompletedCellinTAI.c + S1AP_CompletedCellinTAI-Item.c + S1AP_TBCD-STRING.c + S1AP_TargetID.c + S1AP_TargeteNB-ID.c + S1AP_TargetRNC-ID.c + S1AP_TargeteNB-ToSourceeNB-TransparentContainer.c + S1AP_Target-ToSource-TransparentContainer.c + S1AP_TargetRNC-ToSourceRNC-TransparentContainer.c + S1AP_TargetBSS-ToSourceBSS-TransparentContainer.c + S1AP_M1ThresholdEventA2.c + S1AP_Threshold-RSRP.c + S1AP_Threshold-RSRQ.c + S1AP_TimeToWait.c + S1AP_Time-UE-StayedInCell.c + S1AP_Time-UE-StayedInCell-EnhancedGranularity.c + S1AP_TransportInformation.c + S1AP_TransportLayerAddress.c + S1AP_TraceActivation.c + S1AP_TraceDepth.c + S1AP_E-UTRAN-Trace-ID.c + S1AP_TrafficLoadReductionIndication.c + S1AP_TunnelInformation.c + S1AP_TypeOfError.c + S1AP_TAIListForRestart.c + S1AP_UEAggregateMaximumBitrate.c + S1AP_UE-RetentionInformation.c + S1AP_UE-S1AP-IDs.c + S1AP_UE-S1AP-ID-pair.c + S1AP_UE-associatedLogicalS1-ConnectionItem.c + S1AP_UEIdentityIndexValue.c + S1AP_UE-HistoryInformation.c + S1AP_UE-HistoryInformationFromTheUE.c + S1AP_UEPagingID.c + S1AP_UERadioCapability.c + S1AP_UERadioCapabilityForPaging.c + S1AP_UE-RLF-Report-Container.c + S1AP_UE-RLF-Report-Container-for-extended-bands.c + S1AP_UESecurityCapabilities.c + S1AP_UESidelinkAggregateMaximumBitrate.c + S1AP_UE-Usage-Type.c + S1AP_UL-CP-SecurityInformation.c + S1AP_UL-NAS-MAC.c + S1AP_UL-NAS-Count.c + S1AP_UserLocationInformation.c + S1AP_UEUserPlaneCIoTSupportIndicator.c + S1AP_VoiceSupportMatchIndicator.c + S1AP_V2XServicesAuthorized.c + S1AP_VehicleUE.c + S1AP_PedestrianUE.c + S1AP_WarningAreaList.c + S1AP_WarningType.c + S1AP_WarningSecurityInfo.c + S1AP_WarningMessageContents.c + S1AP_X2TNLConfigurationInfo.c + S1AP_ENBX2ExtTLAs.c + S1AP_ENBX2ExtTLA.c + S1AP_ENBX2GTPTLAs.c + S1AP_ENBIndirectX2TransportLayerAddresses.c + S1AP_Criticality.c + S1AP_Presence.c + S1AP_PrivateIE-ID.c + S1AP_ProcedureCode.c + S1AP_ProtocolExtensionID.c + S1AP_ProtocolIE-ID.c + S1AP_TriggeringMessage.c + S1AP_ProtocolIE-Container.c + S1AP_ProtocolIE-SingleContainer.c + S1AP_ProtocolIE-Field.c + S1AP_ProtocolIE-ContainerList.c + S1AP_ProtocolExtensionContainer.c + S1AP_ProtocolExtensionField.c + S1AP_PrivateIE-Container.c + S1AP_PrivateIE-Field.c +'''.split()) + +libasn1c_s1ap_inc = include_directories('.') + +libasn1c_s1ap = library('ogsasn1c-s1ap', + sources : libasn1c_s1ap_sources, + version : libogslib_version, + c_args : libasn1c_common_cc_flags, + include_directories : libasn1c_s1ap_inc, + dependencies : libasn1c_common_dep, + install : true) + +libasn1c_s1ap_dep = declare_dependency( + link_with : libasn1c_s1ap, + include_directories : libasn1c_s1ap_inc, + dependencies : libasn1c_common_dep) diff --git a/lib/core/abts.c b/lib/core/abts.c new file mode 100644 index 000000000..a81e6b870 --- /dev/null +++ b/lib/core/abts.c @@ -0,0 +1,622 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * abts.c + * + * This code is taken from the APR library. + * Modified by Sukchan Lee to fit Open5GS coding style. + */ +#include "abts.h" +#if 0 /* modified by acetcom */ +#include "abts_tests.h" +#include "testutil.h" +#else +#include "ogs-core.h" +#endif + +#define ABTS_STAT_SIZE 6 +static char status[ABTS_STAT_SIZE] = {'|', '/', '-', '|', '\\', '-'}; +static int curr_char; +#if 0 /* modified by acetcom */ +static int verbose = 0; +#else +static int verbose = 1; +#endif +static int exclude = 0; +static int quiet = 0; +static int list_tests = 0; + +const char **testlist = NULL; + +static int find_test_name(const char *testname) { + int i; + for (i = 0; testlist[i] != NULL; i++) { + if (!strcmp(testlist[i], testname)) { + return 1; + } + } + return 0; +} + +/* Determine if the test should be run at all */ +static int should_test_run(const char *testname) { + int found = 0; + if (list_tests == 1) { + return 0; + } + if (testlist == NULL) { + return 1; + } + found = find_test_name(testname); + if ((found && !exclude) || (!found && exclude)) { + return 1; + } + return 0; +} + +static void reset_status(void) +{ + curr_char = 0; +} + +static void update_status(void) +{ + if (!quiet) { + curr_char = (curr_char + 1) % ABTS_STAT_SIZE; + fprintf(stdout, "\b%c", status[curr_char]); + fflush(stdout); + } +} + +static void end_suite(abts_suite *suite) +{ + if (suite != NULL) { + sub_suite *last = suite->tail; + if (!quiet) { + fprintf(stdout, "\b"); + fflush(stdout); + } + if (last->failed == 0) { + fprintf(stdout, "SUCCESS\n"); + fflush(stdout); + } + else { + fprintf(stdout, "FAILED %d of %d\n", last->failed, last->num_test); + fflush(stdout); + } + } +} + +abts_suite *abts_add_suite(abts_suite *suite, const char *suite_name_full) +{ + sub_suite *subsuite; + char *p; + const char *suite_name; + curr_char = 0; + + /* Only end the suite if we actually ran it */ + if (suite && suite->tail &&!suite->tail->not_run) { + end_suite(suite); + } + + subsuite = malloc(sizeof(*subsuite)); + subsuite->num_test = 0; + subsuite->failed = 0; + subsuite->next = NULL; + /* suite_name_full may be an absolute path depending on __FILE__ + * expansion */ + suite_name = strrchr(suite_name_full, '/'); + if (!suite_name) { + suite_name = strrchr(suite_name_full, '\\'); + } + if (suite_name) { + suite_name++; + } else { + suite_name = suite_name_full; + } + p = strrchr(suite_name, '.'); + if (p) { + subsuite->name = memcpy(calloc(p - suite_name + 1, 1), + suite_name, p - suite_name); + } + else { +#if 0 /* modified by acetcom */ + subsuite->name = suite_name; +#else + subsuite->name = memcpy(calloc(strlen(suite_name) + 1, 1), + suite_name, strlen(suite_name)); +#endif + } + + if (list_tests) { + fprintf(stdout, "%s\n", subsuite->name); + } + + subsuite->not_run = 0; + + if (suite == NULL) { + suite = malloc(sizeof(*suite)); + suite->head = subsuite; + suite->tail = subsuite; + } + else { + suite->tail->next = subsuite; + suite->tail = subsuite; + } + + if (!should_test_run(subsuite->name)) { + subsuite->not_run = 1; + return suite; + } + + reset_status(); + fprintf(stdout, "%-20s: ", subsuite->name); + update_status(); + fflush(stdout); + + return suite; +} + +void abts_run_test(abts_suite *ts, test_func f, void *value) +{ + abts_case tc; + sub_suite *ss; + + if (!should_test_run(ts->tail->name)) { + return; + } + ss = ts->tail; + + tc.failed = 0; + tc.suite = ss; + + ss->num_test++; + update_status(); + + f(&tc, value); + + if (tc.failed) { + ss->failed++; + } +} + +static int report(abts_suite *suite) +{ + int count = 0; + sub_suite *dptr; + + if (suite && suite->tail &&!suite->tail->not_run) { + end_suite(suite); + } + + for (dptr = suite->head; dptr; dptr = dptr->next) { + count += dptr->failed; + } + + if (list_tests) { + return 0; + } + + if (count == 0) { + printf("All tests passed.\n"); + return 0; + } + + dptr = suite->head; + fprintf(stdout, "%-15s\t\tTotal\tFail\tFailed %%\n", "Failed Tests"); + fprintf(stdout, "===================================================\n"); + while (dptr != NULL) { + if (dptr->failed != 0) { + float percent = ((float)dptr->failed / (float)dptr->num_test); + fprintf(stdout, "%-15s\t\t%5d\t%4d\t%6.2f%%\n", dptr->name, + dptr->num_test, dptr->failed, percent * 100); + } + dptr = dptr->next; + } + return 1; +} + +void abts_log_message(const char *fmt, ...) +{ + va_list args; + update_status(); + + if (verbose) { + va_start(args, fmt); +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wformat-nonliteral" + vfprintf(stderr, fmt, args); +#pragma GCC diagnostic pop + va_end(args); + fprintf(stderr, "\n"); + fflush(stderr); + } +} + +void abts_int_equal(abts_case *tc, const int expected, const int actual, int lineno) +{ + update_status(); + if (tc->failed) return; + + if (expected == actual) return; + + tc->failed = TRUE; + if (verbose) { + fprintf(stderr, "Line %d: expected <%d>, but saw <%d>\n", lineno, expected, actual); + fflush(stderr); + } +} + +void abts_int_nequal(abts_case *tc, const int expected, const int actual, int lineno) +{ + update_status(); + if (tc->failed) return; + + if (expected != actual) return; + + tc->failed = TRUE; + if (verbose) { + fprintf(stderr, "Line %d: expected something other than <%d>, but saw <%d>\n", + lineno, expected, actual); + fflush(stderr); + } +} + +void abts_size_equal(abts_case *tc, size_t expected, size_t actual, int lineno) +{ + update_status(); + if (tc->failed) return; + + if (expected == actual) return; + + tc->failed = TRUE; + if (verbose) { + /* Note that the comparison is type-exact, reporting must be a best-fit */ + fprintf(stderr, "Line %d: expected %lu, but saw %lu\n", lineno, + (unsigned long)expected, (unsigned long)actual); + fflush(stderr); + } +} + +void abts_str_equal(abts_case *tc, const char *expected, const char *actual, int lineno) +{ + update_status(); + if (tc->failed) return; + + if (!expected && !actual) return; + if (expected && actual) + if (!strcmp(expected, actual)) return; + + tc->failed = TRUE; + if (verbose) { + fprintf(stderr, "Line %d: expected <%s>, but saw <%s>\n", lineno, expected, actual); + fflush(stderr); + } +} + +void abts_str_nequal(abts_case *tc, const char *expected, const char *actual, + size_t n, int lineno) +{ + update_status(); + if (tc->failed) return; + + if (!strncmp(expected, actual, n)) return; + + tc->failed = TRUE; + if (verbose) { + fprintf(stderr, "Line %d: expected something other than <%s>, but saw <%s>\n", + lineno, expected, actual); + fflush(stderr); + } +} + +void abts_ptr_notnull(abts_case *tc, const void *ptr, int lineno) +{ + update_status(); + if (tc->failed) return; + + if (ptr != NULL) return; + + tc->failed = TRUE; + if (verbose) { + fprintf(stderr, "Line %d: expected non-NULL, but saw NULL\n", lineno); + fflush(stderr); + } +} + +void abts_ptr_equal(abts_case *tc, const void *expected, const void *actual, int lineno) +{ + update_status(); + if (tc->failed) return; + + if (expected == actual) return; + + tc->failed = TRUE; + if (verbose) { + fprintf(stderr, "Line %d: expected <%p>, but saw <%p>\n", lineno, expected, actual); + fflush(stderr); + } +} + +void abts_fail(abts_case *tc, const char *message, int lineno) +{ + update_status(); + if (tc->failed) return; + + tc->failed = TRUE; + if (verbose) { + fprintf(stderr, "Line %d: %s\n", lineno, message); + fflush(stderr); + } +} + +void abts_assert(abts_case *tc, const char *message, int condition, int lineno) +{ + update_status(); + if (tc->failed) return; + + if (condition) return; + + tc->failed = TRUE; + if (verbose) { + fprintf(stderr, "Line %d: %s\n", lineno, message); + fflush(stderr); + } +} + +void abts_true(abts_case *tc, int condition, int lineno) +{ + update_status(); + if (tc->failed) return; + + if (condition) return; + + tc->failed = TRUE; + if (verbose) { + fprintf(stderr, "Line %d: Condition is false, but expected true\n", lineno); + fflush(stderr); + } +} + +void abts_not_impl(abts_case *tc, const char *message, int lineno) +{ + update_status(); + + tc->suite->not_impl++; + if (verbose) { + fprintf(stderr, "Line %d: %s\n", lineno, message); + fflush(stderr); + } +} + +#if 0 /* modified by acetcom */ +int main(int argc, const char *const argv[]) { +#else +void abts_init(int argc, const char *const argv[]) { +#endif + int i; +#if 0 /* modified by acetcom */ + int rv; + int list_provided = 0; + abts_suite *suite = NULL; + + initialize(); +#else + int list_provided = 0; +#endif + + quiet = !isatty(STDOUT_FILENO); + + for (i = 1; i < argc; i++) { + if (!strcmp(argv[i], "-v")) { + verbose = 1; + continue; + } + if (!strcmp(argv[i], "-x")) { + exclude = 1; + continue; + } + if (!strcmp(argv[i], "-l")) { + list_tests = 1; + continue; + } + if (!strcmp(argv[i], "-q")) { + quiet = 1; + continue; + } +#if 1 /* modified by acetcom */ + if (!strcmp(argv[i], "-f")) { + i++; + continue; + } + if (!strcmp(argv[i], "-d")) { + i++; + continue; + } + if (!strcmp(argv[i], "-t")) { + i++; + continue; + } +#endif + if (argv[i][0] == '-') { +#if 0 /* modified by acetcom */ + fprintf(stderr, "Invalid option: `%s'\n", argv[i]); + exit(1); +#else + continue; +#endif + } + list_provided = 1; + } + + if (list_provided) { + /* Waste a little space here, because it is easier than counting the + * number of tests listed. Besides it is at most three char *. + */ + testlist = calloc(argc + 1, sizeof(char *)); + for (i = 1; i < argc; i++) { + testlist[i - 1] = argv[i]; + } + } + +#if 0 /* modified by acetcom */ + for (i = 0; i < (sizeof(alltests) / sizeof(struct testlist *)); i++) { + suite = alltests[i].func(suite); + } + + rv = report(suite); + return rv; +#endif +} + +#if 1 /* modified by acetcom */ +static void show_help(const char *name) +{ + printf("Usage: %s [options] [test1] [test2] ...\n" + "Options:\n" + " -c filename : set configuration file\n" + " -e level : set global log-level (default:info)\n" + " -m domain : set log-domain (e.g. mme:sgw:gtp)\n" + " -d : print lots of debugging information\n" + " -t : print tracing information for developer\n" + " -v : show version number and exit\n" + " -h : show this message and exit\n" + " -v : turn on verbose in test\n" + " -q : turn off status in test\n" + " -x : exclute test-unit (e.g. -x sctp-test)\n" + " -l : list test-unit\n" + "\n", name); +} + +int abts_main(int argc, const char *const argv[], const char **argv_out) +{ + char *arg; + int i, opt; + ogs_getopt_t options; + struct { + char *config_file; + char *log_level; + char *domain_mask; + + bool enable_debug; + bool enable_trace; + } optarg; + + memset(&optarg, 0, sizeof(optarg)); + + ogs_getopt_init(&options, (char**)argv); + while ((opt = ogs_getopt(&options, "hvxlqc:e:m:dt")) != -1) { + switch (opt) { + case 'h': + show_help(argv[0]); + break; + case 'v': + verbose = 1; + break; + case 'x': + exclude = 1; + break; + case 'l': + list_tests = 1; + break; + case 'q': + quiet = 1; + break; + case 'c': + optarg.config_file = options.optarg; + break; + case 'e': + optarg.log_level = options.optarg; + break; + case 'm': + optarg.domain_mask = options.optarg; + break; + case 'd': + optarg.enable_debug = true; + break; + case 't': + optarg.enable_trace = true; + break; + case '?': + fprintf(stderr, "%s: %s\n", argv[0], options.errmsg); + show_help(argv[0]); + return OGS_ERROR; + default: + fprintf(stderr, "%s: should not be reached\n", OGS_FUNC); + exit(1); + } + } + + i = 0; + while((arg = ogs_getopt_arg(&options))) { + if (!testlist) + testlist = calloc(argc + 1, sizeof(char *)); + testlist[i++] = arg; + } + + if (optarg.enable_debug) optarg.log_level = (char*)"debug"; + if (optarg.enable_trace) optarg.log_level = (char*)"trace"; + + i = 0; + argv_out[i++] = argv[0]; + + argv_out[i++] = "-e"; + if (!optarg.log_level) + argv_out[i++] = "error"; /* Default LOG Level : ERROR */ + else + argv_out[i++] = optarg.log_level; + + if (optarg.config_file) { + argv_out[i++] = "-c"; + argv_out[i++] = optarg.config_file; + } + if (optarg.domain_mask) { + argv_out[i++] = "-m"; + argv_out[i++] = optarg.domain_mask; + } + + argv_out[i] = NULL; + + return OGS_OK; +} + +static void abts_free(abts_suite *suite) +{ + sub_suite *ptr = NULL, *next_ptr = NULL; + + ptr = suite->head; + while (ptr != NULL) { + next_ptr = ptr->next; + + free((void*)ptr->name); + free(ptr); + ptr = next_ptr; + } + + free(suite); +} + +int abts_report(abts_suite *suite) +{ + int rv = report(suite); + + abts_free(suite); + free(testlist); + + return rv; +} +#endif diff --git a/lib/core/abts.h b/lib/core/abts.h new file mode 100644 index 000000000..a791b7cf9 --- /dev/null +++ b/lib/core/abts.h @@ -0,0 +1,119 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * abts.h + * + * This code is taken from the APR library. + * Modified by Sukchan Lee to fit Open5GS coding style. + */ +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include +#include +#ifdef WIN32 +#include +#else +#include +#endif + +#ifndef ABTS_H +#define ABTS_H + +#ifndef FALSE +#define FALSE 0 +#endif +#ifndef TRUE +#define TRUE 1 +#endif + +struct sub_suite { + const char *name; + int num_test; + int failed; + int not_run; + int not_impl; + struct sub_suite *next; +}; +typedef struct sub_suite sub_suite; + +struct abts_suite { + sub_suite *head; + sub_suite *tail; +}; +typedef struct abts_suite abts_suite; + +struct abts_case { + int failed; + sub_suite *suite; +}; +typedef struct abts_case abts_case; + +typedef void (*test_func)(abts_case *tc, void *data); + +#define ADD_SUITE(suite) abts_add_suite(suite, __FILE__); + +abts_suite *abts_add_suite(abts_suite *suite, const char *suite_name); +void abts_run_test(abts_suite *ts, test_func f, void *value); +void abts_log_message(const char *fmt, ...); + +void abts_int_equal(abts_case *tc, const int expected, const int actual, int lineno); +void abts_int_nequal(abts_case *tc, const int expected, const int actual, int lineno); +void abts_str_equal(abts_case *tc, const char *expected, const char *actual, int lineno); +void abts_str_nequal(abts_case *tc, const char *expected, const char *actual, + size_t n, int lineno); +void abts_ptr_notnull(abts_case *tc, const void *ptr, int lineno); +void abts_ptr_equal(abts_case *tc, const void *expected, const void *actual, int lineno); +void abts_true(abts_case *tc, int condition, int lineno); +void abts_fail(abts_case *tc, const char *message, int lineno); +void abts_not_impl(abts_case *tc, const char *message, int lineno); +void abts_assert(abts_case *tc, const char *message, int condition, int lineno); +void abts_size_equal(abts_case *tc, size_t expected, size_t actual, int lineno); + +/* Convenience macros. Ryan hates these! */ +#define ABTS_INT_EQUAL(a, b, c) abts_int_equal(a, b, c, __LINE__) +#define ABTS_INT_NEQUAL(a, b, c) abts_int_nequal(a, b, c, __LINE__) +#define ABTS_STR_EQUAL(a, b, c) abts_str_equal(a, b, c, __LINE__) +#define ABTS_STR_NEQUAL(a, b, c, d) abts_str_nequal(a, b, c, d, __LINE__) +#define ABTS_PTR_NOTNULL(a, b) abts_ptr_notnull(a, b, __LINE__) +#define ABTS_PTR_EQUAL(a, b, c) abts_ptr_equal(a, b, c, __LINE__) +#define ABTS_TRUE(a, b) abts_true(a, b, __LINE__); +#define ABTS_FAIL(a, b) abts_fail(a, b, __LINE__); +#define ABTS_NOT_IMPL(a, b) abts_not_impl(a, b, __LINE__); +#define ABTS_ASSERT(a, b, c) abts_assert(a, b, c, __LINE__); + +#define ABTS_SIZE_EQUAL(a, b, c) abts_size_equal(a, b, c, __LINE__) + + +abts_suite *run_tests(abts_suite *suite); +abts_suite *run_tests1(abts_suite *suite); +#if 1 /* modified by acetcom */ +void abts_init(int argc, const char *const argv[]); +int abts_main(int argc, const char *const argv[], const char **argv_out); +int abts_report(abts_suite *suite); +#endif + + +#endif + +#ifdef __cplusplus +} +#endif + diff --git a/lib/core/arc4random.c b/lib/core/arc4random.c new file mode 100644 index 000000000..a2338e692 --- /dev/null +++ b/lib/core/arc4random.c @@ -0,0 +1,556 @@ +/* Portable arc4random.c based on arc4random.c from OpenBSD. + * Portable version by Chris Davis, adapted for Libevent by Nick Mathewson + * Copyright (c) 2010 Chris Davis, Niels Provos, and Nick Mathewson + * Copyright (c) 2010-2012 Niels Provos and Nick Mathewson + * + * Note that in Libevent, this file isn't compiled directly. Instead, + * it's included from evutil_rand.c + */ + +/* + * Copyright (c) 1996, David Mazieres + * Copyright (c) 2008, Damien Miller + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/* + * Arc4 random number generator for OpenBSD. + * + * This code is derived from section 17.1 of Applied Cryptography, + * second edition, which describes a stream cipher allegedly + * compatible with RSA Labs "RC4" cipher (the actual description of + * which is a trade secret). The same algorithm is used as a stream + * cipher called "arcfour" in Tatu Ylonen's ssh package. + * + * Here the stream cipher has been modified always to include the time + * when initializing the state. That makes it impossible to + * regenerate the same random sequence twice, so this can't be used + * for encryption, but will generate good random numbers. + * + * RC4 is a registered trademark of RSA Laboratories. + */ + +#ifndef ARC4RANDOM_EXPORT +#define ARC4RANDOM_EXPORT +#endif + +#ifndef ARC4RANDOM_UINT32 +#define ARC4RANDOM_UINT32 uint32_t +#endif + +#ifndef ARC4RANDOM_NO_INCLUDES +#include "evconfig-private.h" +#ifdef _WIN32 +#include +#include +#else +#include +#include +#include +#include +#ifdef EVENT__HAVE_SYS_SYSCTL_H +#include +#endif +#endif +#include +#include +#include +#endif + +/* Add platform entropy 32 bytes (256 bits) at a time. */ +#define ADD_ENTROPY 32 + +/* Re-seed from the platform RNG after generating this many bytes. */ +#define BYTES_BEFORE_RESEED 1600000 + +struct arc4_stream { + unsigned char i; + unsigned char j; + unsigned char s[256]; +}; + +#ifdef _WIN32 +#define getpid _getpid +#define pid_t int +#endif + +static int rs_initialized; +static struct arc4_stream rs; +static pid_t arc4_stir_pid; +static int arc4_count; +static int arc4_seeded_ok; + +static inline unsigned char arc4_getbyte(void); + +static inline void +arc4_init(void) +{ + int n; + + for (n = 0; n < 256; n++) + rs.s[n] = n; + rs.i = 0; + rs.j = 0; +} + +static inline void +arc4_addrandom(const unsigned char *dat, int datlen) +{ + int n; + unsigned char si; + + rs.i--; + for (n = 0; n < 256; n++) { + rs.i = (rs.i + 1); + si = rs.s[rs.i]; + rs.j = (rs.j + si + dat[n % datlen]); + rs.s[rs.i] = rs.s[rs.j]; + rs.s[rs.j] = si; + } + rs.j = rs.i; +} + +#ifndef _WIN32 +static ssize_t +read_all(int fd, unsigned char *buf, size_t count) +{ + size_t numread = 0; + ssize_t result; + + while (numread < count) { + result = read(fd, buf+numread, count-numread); + if (result<0) + return -1; + else if (result == 0) + break; + numread += result; + } + + return (ssize_t)numread; +} +#endif + +#ifdef _WIN32 +#define TRY_SEED_WIN32 +static int +arc4_seed_win32(void) +{ + /* This is adapted from Tor's crypto_seed_rng() */ + static int provider_set = 0; + static HCRYPTPROV provider; + unsigned char buf[ADD_ENTROPY]; + + if (!provider_set) { + if (!CryptAcquireContext(&provider, NULL, NULL, PROV_RSA_FULL, + CRYPT_VERIFYCONTEXT)) { + if (GetLastError() != (DWORD)NTE_BAD_KEYSET) + return -1; + } + provider_set = 1; + } + if (!CryptGenRandom(provider, sizeof(buf), buf)) + return -1; + arc4_addrandom(buf, sizeof(buf)); + evutil_memclear_(buf, sizeof(buf)); + arc4_seeded_ok = 1; + return 0; +} +#endif + +#if defined(EVENT__HAVE_SYS_SYSCTL_H) && defined(EVENT__HAVE_SYSCTL) +#if EVENT__HAVE_DECL_CTL_KERN && EVENT__HAVE_DECL_KERN_RANDOM && EVENT__HAVE_DECL_RANDOM_UUID +#define TRY_SEED_SYSCTL_LINUX +static int +arc4_seed_sysctl_linux(void) +{ + /* Based on code by William Ahern, this function tries to use the + * RANDOM_UUID sysctl to get entropy from the kernel. This can work + * even if /dev/urandom is inaccessible for some reason (e.g., we're + * running in a chroot). */ + int mib[] = { CTL_KERN, KERN_RANDOM, RANDOM_UUID }; + unsigned char buf[ADD_ENTROPY]; + size_t len, n; + unsigned i; + int any_set; + + memset(buf, 0, sizeof(buf)); + + for (len = 0; len < sizeof(buf); len += n) { + n = sizeof(buf) - len; + + if (0 != sysctl(mib, 3, &buf[len], &n, NULL, 0)) + return -1; + } + /* make sure that the buffer actually got set. */ + for (i=0,any_set=0; i sizeof(buf)) + n = len - sizeof(buf); + if (sysctl(mib, 2, &buf[len], &n, NULL, 0) == -1) + return -1; + } + } + /* make sure that the buffer actually got set. */ + for (i=any_set=0; i 0xffffffffUL) + min = 0x100000000UL % upper_bound; +#else + /* Calculate (2**32 % upper_bound) avoiding 64-bit math */ + if (upper_bound > 0x80000000) + min = 1 + ~upper_bound; /* 2**32 - upper_bound */ + else { + /* (2**32 - (x * 2)) % x == 2**32 % x when x <= 2**31 */ + min = ((0xffffffff - (upper_bound * 2)) + 1) % upper_bound; + } +#endif + + /* + * This could theoretically loop forever but each retry has + * p > 0.5 (worst case, usually far better) of selecting a + * number inside the range we need, so it should rarely need + * to re-roll. + */ + for (;;) { + r = arc4random(); + if (r >= min) + break; + } + + return r % upper_bound; +} +#endif diff --git a/lib/core/meson.build b/lib/core/meson.build new file mode 100644 index 000000000..29c0b5c34 --- /dev/null +++ b/lib/core/meson.build @@ -0,0 +1,307 @@ +# Copyright (C) 2019 by Sukchan Lee + +# This file is part of Open5GS. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +libcore_conf = configuration_data() + +libcore_headers = (''' + arpa/inet.h + ctype.h + errno.h + execinfo.h + fcntl.h + ifaddrs.h + netdb.h + pthread.h + signal.h + stdarg.h + stddef.h + stdio.h + stdint.h + stdbool.h + stdlib.h + string.h + strings.h + time.h + sys/time.h + unistd.h + net/if.h + netinet/in.h + netinet/in_systm.h + netinet/udp.h + netinet/tcp.h + sys/ioctl.h + sys/param.h + sys/random.h + sys/socket.h + sys/stat.h + limits.h + sys/syslimits.h + sys/types.h + sys/wait.h + sys/uio.h +'''.split()) + +foreach h : libcore_headers + if cc.has_header(h) + define = 'HAVE_' + h.underscorify().to_upper() + libcore_conf.set(define, 1) + endif +endforeach + +libcore_functions = (''' + arc4random + arc4random_buf + getrandom + localtime_r + getifaddrs + getenv + putenv + setenv + unsetenv + strerror_r + sigaction + sigwait + sigsuspend + eventfd + kqueue + epoll_ctl +'''.split()) + +foreach f : libcore_functions + if cc.has_function(f) + define = 'HAVE_' + f.underscorify().to_upper() + libcore_conf.set(define, 1) + set_variable('have_func_' + f, true) + else + set_variable('have_func_' + f, false) + endif +endforeach + +# Determination of thread implementation +threads = [] +if host_system == 'windows' and not get_option('force_posix_threads') +else + threads = dependency('threads') + if cc.has_header_symbol('pthread.h', 'pthread_barrier_wait') + libcore_conf.set('HAVE_PTHREAD_BAR', 1) + endif +endif + +# Check for sys_syslist +if cc.has_header_symbol('signal.h', 'sys_siglist') + libcore_conf.set('HAVE_DECL_SYS_SIGLIST', 1, + description: 'Define to 1 if you have the declaration of \`sys_siglist\', and to 0 if you don\'t.') +endif + +# Check whether strerror_r returns char * +if have_func_strerror_r + if cc.compiles('''#define _GNU_SOURCE + #include + int func (void) { + char error_string[256]; + char *ptr = strerror_r (-2, error_string, 256); + char c = *strerror_r (-2, error_string, 256); + return c != 0 && ptr != (void*) 0L; + }''', name : 'strerror_r() returns char *') + libcore_conf.set('STRERROR_R_CHAR_P', 1, + description: 'Defined if strerror_r returns char *') + endif +endif + +# Check for backtrace() +libexecinfo = cc.find_library('execinfo', required : false) +if libcore_conf.has('HAVE_EXECINFO_H') + if cc.has_function('backtrace', prefix : '#include ') + libcore_conf.set('HAVE_BACKTRACE', 1) + elif libexecinfo.found() and cc.has_function('backtrace', + prefix : '#include ', + dependencies : libexecinfo) + libcore_conf.set('HAVE_BACKTRACE', 1) + endif +endif + +# Check for clock_gettime() +clock_gettime_test_code = ''' + #include + struct timespec t; + int main (int argc, char ** argv) { + return clock_gettime(CLOCK_REALTIME, &t); + }''' +librt = [] +if cc.links(clock_gettime_test_code, name : 'clock_gettime()') + libcore_conf.set('HAVE_CLOCK_GETTIME', 1) +elif cc.links(clock_gettime_test_code, args : '-lrt', name : 'clock_gettime() in librt') + libcore_conf.set('HAVE_CLOCK_GETTIME', 1) + librt = cc.find_library('rt') +elif cc.links(clock_gettime_test_code, args : '-lposix4', name : 'clock_gettime() in libposix4') + libcore_conf.set('HAVE_CLOCK_GETTIME', 1) + librt = cc.find_library('posix4') +else + error('Could not find clock_gettime()') +endif + +# Check for /dev/urandom +if run_command('[', '-c', '/dev/urandom', ']').returncode() == 0 + libcore_conf.set_quoted('OGS_DEV_RANDOM', '/dev/urandom', + description: 'a suitable file to read random data from') +endif + +# Check for eventfd(2) +if cc.links('''#include + #include + int main (int argc, char ** argv) { + eventfd (0, EFD_CLOEXEC); + return 0; + }''', name : 'eventfd(2) system call') + libcore_conf.set('HAVE_EVENTFD', 1) +endif + +# Check for epoll +if have_func_epoll_ctl + libcore_conf.set('HAVE_EPOLL', 1, description: 'Defined if your system supports the epoll system calls') +endif + +# Check for socket +libsocket = cc.find_library('socket', required : false) +if host_system != 'windows' + # socket() + socket_test = '''#include + #include + int main (int argc, char ** argv) { + return socket(1, 2, 3); + }''' + if cc.links(socket_test, name : 'socket()') + elif libsocket.found() and cc.links(socket_test, + dependencies : libsocket, + name : 'socket() in -lsocket') + else + error('Could not find socket()') + endif +endif + +configure_file(output : 'core-config-private.h', configuration : libcore_conf) + +ogs_libcore_conf = configuration_data() + +ogs_libcore_conf.set('_GNU_SOURCE', true) +ogs_libcore_conf.set('OGS_BIG_ENDIAN', 4321) +ogs_libcore_conf.set('OGS_LITTLE_ENDIAN', 1234) + +if host_machine.endian() == 'big' + ogs_libcore_conf.set('OGS_BYTE_ORDER', 'OGS_BIG_ENDIAN') +else + ogs_libcore_conf.set('OGS_BYTE_ORDER', 'OGS_LITTLE_ENDIAN') +endif + +if host_system == 'windows' +ogs_libcore_conf.set('OGS_DIR_SEPARATOR', '\'\\\\\'') +ogs_libcore_conf.set_quoted('OGS_DIR_SEPARATOR_S', '\\\\') +else +ogs_libcore_conf.set('OGS_DIR_SEPARATOR', '\'/\'') +ogs_libcore_conf.set_quoted('OGS_DIR_SEPARATOR_S', '/') +endif + +configure_file(output : 'core-config.h', configuration : ogs_libcore_conf) + +libcore_sources = files(''' + ogs-core.h + + ogs-compat.h + ogs-macros.h + ogs-pool.h + ogs-list.h + ogs-abort.h + ogs-errno.h + ogs-strings.h + ogs-time.h + ogs-conv.h + ogs-log.h + ogs-pkbuf.h + ogs-memory.h + ogs-rbtree.h + ogs-timer.h + ogs-rand.h + ogs-thread.h + ogs-signal.h + ogs-process.h + ogs-sockaddr.h + ogs-socket.h + ogs-sockpair.h + ogs-socknode.h + ogs-udp.h + ogs-tcp.h + ogs-queue.h + ogs-poll.h + ogs-notify.h + ogs-tlv.h + ogs-env.h + ogs-fsm.h + ogs-hash.h + ogs-misc.h + ogs-getopt.h + ogs-3gpp-types.h + abts.h + + ogs-abort.c + ogs-errno.c + ogs-strings.c + ogs-time.c + ogs-conv.c + ogs-log.c + ogs-pkbuf.c + ogs-memory.c + ogs-rbtree.c + ogs-timer.c + ogs-rand.c + ogs-thread.c + ogs-signal.c + ogs-process.c + ogs-sockaddr.c + ogs-socket.c + ogs-sockpair.c + ogs-socknode.c + ogs-udp.c + ogs-tcp.c + ogs-queue.c + ogs-select.c + ogs-poll.c + ogs-notify.c + ogs-tlv.c + ogs-env.c + ogs-fsm.c + ogs-hash.c + ogs-misc.c + ogs-getopt.c + ogs-3gpp-types.c + ogs-core.c + abts.c +'''.split()) + +libcore_inc = include_directories('.') + +libcore = library('ogscore', + sources : libcore_sources, + version : libogslib_version, + c_args : '-DOGS_CORE_COMPILATION', + include_directories : [libcore_inc, libinc], + dependencies : [threads, librt, libexecinfo, libsocket], + install : true) + +libcore_dep = declare_dependency( + link_with : libcore, + include_directories : [libcore_inc, libinc], + dependencies : [threads, librt, libexecinfo, libsocket]) diff --git a/lib/core/ogs-3gpp-types.c b/lib/core/ogs-3gpp-types.c new file mode 100644 index 000000000..f25b5e9d1 --- /dev/null +++ b/lib/core/ogs-3gpp-types.c @@ -0,0 +1,179 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "ogs-core.h" + +#define PLMN_ID_DIGIT1(x) (((x) / 100) % 10) +#define PLMN_ID_DIGIT2(x) (((x) / 10) % 10) +#define PLMN_ID_DIGIT3(x) ((x) % 10) + +uint32_t ogs_plmn_id_hexdump(void *plmn_id) +{ + uint32_t hex; + ogs_assert(plmn_id); + memcpy(&hex, plmn_id, sizeof(ogs_plmn_id_t)); + hex = ntohl(hex) >> 8; + return hex; +} + +uint16_t ogs_plmn_id_mcc(ogs_plmn_id_t *plmn_id) +{ + return plmn_id->mcc1 * 100 + plmn_id->mcc2 * 10 + plmn_id->mcc3; +} +uint16_t ogs_plmn_id_mnc(ogs_plmn_id_t *plmn_id) +{ + return plmn_id->mnc1 == 0xf ? plmn_id->mnc2 * 10 + plmn_id->mnc3 : + plmn_id->mnc1 * 100 + plmn_id->mnc2 * 10 + plmn_id->mnc3; +} +uint16_t ogs_plmn_id_mnc_len(ogs_plmn_id_t *plmn_id) +{ + return plmn_id->mnc1 == 0xf ? 2 : 3; +} + +void *ogs_plmn_id_build(ogs_plmn_id_t *plmn_id, + uint16_t mcc, uint16_t mnc, uint16_t mnc_len) +{ + plmn_id->mcc1 = PLMN_ID_DIGIT1(mcc); + plmn_id->mcc2 = PLMN_ID_DIGIT2(mcc); + plmn_id->mcc3 = PLMN_ID_DIGIT3(mcc); + + if (mnc_len == 2) + plmn_id->mnc1 = 0xf; + else + plmn_id->mnc1 = PLMN_ID_DIGIT1(mnc); + + plmn_id->mnc2 = PLMN_ID_DIGIT2(mnc); + plmn_id->mnc3 = PLMN_ID_DIGIT3(mnc); + + return plmn_id; +} + +int ogs_fqdn_build(char *dst, char *src, int length) +{ + int i = 0, j = 0; + + for (i = 0, j = 0; i < length; i++, j++) { + if (src[i] == '.') { + dst[i-j] = j; + j = -1; + } else { + dst[i+1] = src[i]; + } + } + dst[i-j] = j; + + return length+1; +} + +int ogs_fqdn_parse(char *dst, char *src, int length) +{ + int i = 0, j = 0; + uint8_t len = 0; + + do { + len = src[i++]; + memcpy(&dst[j], &src[i], len); + + i += len; + j += len; + + if (i < length) + dst[j++] = '.'; + else + dst[j] = 0; + } while (i < length); + + return j; +} + +/* 8.13 Protocol Configuration Options (PCO) + * 10.5.6.3 Protocol configuration options in 3GPP TS 24.008 */ +int ogs_pco_parse(ogs_pco_t *pco, unsigned char *data, int data_len) +{ + ogs_pco_t *source = (ogs_pco_t *)data; + int size = 0; + int i = 0; + + ogs_assert(pco); + ogs_assert(data); + ogs_assert(data_len); + + memset(pco, 0, sizeof(ogs_pco_t)); + + pco->ext = source->ext; + pco->configuration_protocol = source->configuration_protocol; + size++; + + while(size < data_len && i < OGS_MAX_NUM_OF_PROTOCOL_OR_CONTAINER_ID) { + ogs_pco_id_t *id = &pco->ids[i]; + ogs_assert(size + sizeof(id->id) <= data_len); + memcpy(&id->id, data + size, sizeof(id->id)); + id->id = ntohs(id->id); + size += sizeof(id->id); + + ogs_assert(size + sizeof(id->len) <= data_len); + memcpy(&id->len, data + size, sizeof(id->len)); + size += sizeof(id->len); + + id->data = data + size; + size += id->len; + + i++; + } + pco->num_of_id = i; + ogs_assert(size == data_len); + + return size; +} +int ogs_pco_build(unsigned char *data, int data_len, ogs_pco_t *pco) +{ + ogs_pco_t target; + int size = 0; + int i = 0; + + ogs_assert(pco); + ogs_assert(data); + ogs_assert(data_len); + + memcpy(&target, pco, sizeof(ogs_pco_t)); + + ogs_assert(size + 1 <= data_len); + memcpy(data + size, &target, 1); + size += 1; + + ogs_assert(target.num_of_id <= OGS_MAX_NUM_OF_PROTOCOL_OR_CONTAINER_ID); + for (i = 0; i < target.num_of_id; i++) { + ogs_pco_id_t *id = &target.ids[i]; + + ogs_assert(size + sizeof(id->id) <= data_len); + id->id = htons(id->id); + memcpy(data + size, &id->id, sizeof(id->id)); + size += sizeof(id->id); + + ogs_assert(size + sizeof(id->len) <= data_len); + memcpy(data + size, &id->len, sizeof(id->len)); + size += sizeof(id->len); + + ogs_assert(size + id->len <= data_len); + memcpy(data + size, id->data, id->len); + size += id->len; + } + + return size; +} diff --git a/lib/core/ogs-3gpp-types.h b/lib/core/ogs-3gpp-types.h new file mode 100644 index 000000000..4b8008e23 --- /dev/null +++ b/lib/core/ogs-3gpp-types.h @@ -0,0 +1,326 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#if !defined(OGS_CORE_INSIDE) && !defined(OGS_CORE_COMPILATION) +#error "This header cannot be included directly." +#endif + +#ifndef OGS_3GPP_TYPES_H +#define OGS_3GPP_TYPES_H + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#define OGS_MAX_FILEPATH_LEN 256 + +#define OGS_MAX_NUM_OF_SESS 4 /* Num of APN(Session) per UE */ + +#define OGS_MAX_SDU_LEN 8192 +#define OGS_PLMN_ID_LEN 3 + +#define OGS_BCD_TO_BUFFER_LEN(x) (((x)+1)/2) +#define OGS_MAX_IMSI_BCD_LEN 15 +#define OGS_MAX_IMSI_LEN \ + OGS_BCD_TO_BUFFER_LEN(OGS_MAX_IMSI_BCD_LEN) + +#define OGS_MAX_NUM_OF_HOSTNAME 16 +#define OGS_MAX_APN_LEN 100 +#define OGS_MAX_PCO_LEN 251 +#define OGS_MAX_FQDN_LEN 256 + +#define OGS_NEXT_ID(__id, __min, __max) \ + ((__id) = ((__id) == (__max) ? (__min) : ((__id) + 1))) +#define OGS_COMPARE_ID(__id1, __id2, __max) \ + ((__id2) > (__id1) ? ((__id2) - (__id1) < ((__max)-1) ? -1 : 1) : \ + (__id1) > (__id2) ? ((__id1) - (__id2) < ((__max)-1) ? 1 : -1) : 0) + +#define OGS_TIME_TO_BCD(x) \ + (((((x) % 10) << 4) & 0xf0) | (((x) / 10) & 0x0f)) + +/********************************** + * PLMN_ID Structure */ +typedef struct ogs_plmn_id_s { +ED2(uint8_t mcc2:4;, + uint8_t mcc1:4;) +ED2(uint8_t mnc1:4;, + uint8_t mcc3:4;) +ED2(uint8_t mnc3:4;, + uint8_t mnc2:4;) +} __attribute__ ((packed)) ogs_plmn_id_t; + +uint32_t ogs_plmn_id_hexdump(void *plmn_id); + +uint16_t ogs_plmn_id_mcc(ogs_plmn_id_t *plmn_id); +uint16_t ogs_plmn_id_mnc(ogs_plmn_id_t *plmn_id); +uint16_t ogs_plmn_id_mnc_len(ogs_plmn_id_t *plmn_id); + +void *ogs_plmn_id_build(ogs_plmn_id_t *plmn_id, + uint16_t mcc, uint16_t mnc, uint16_t mnc_len); + +#define OGS_MAX_NUM_OF_TAI 16 + +typedef struct ogs_tai_s { + ogs_plmn_id_t plmn_id; + uint16_t tac; +} __attribute__ ((packed)) ogs_tai_t; + +typedef struct ogs_e_cgi_s { + ogs_plmn_id_t plmn_id; + uint32_t cell_id; /* 28 bit */ +} __attribute__ ((packed)) ogs_e_cgi_t; + +/************************************************** + * Common Structure + * S1AP : 9.2.2.1 Transport Layer Address, See 36.414 + * GTP : 8.22 Fully Qualified TEID (F-TEID) */ +#define OGS_IPV4_LEN 4 +#define OGS_IPV6_LEN 16 +#define OGS_IPV4V6_LEN 20 +typedef struct ogs_ip_s { + union { + uint32_t addr; + uint8_t addr6[OGS_IPV6_LEN]; + struct { + uint32_t addr; + uint8_t addr6[OGS_IPV6_LEN]; + } both; + }; + uint32_t len; +ED3(uint8_t ipv4:1;, + uint8_t ipv6:1;, + uint8_t reserved:6;) +} ogs_ip_t; + +/************************************************** + * 8.14 PDN Address Allocation (PAA) */ +#define OGS_PAA_IPV4_LEN 5 +#define OGS_PAA_IPV6_LEN 18 +#define OGS_PAA_IPV4V6_LEN 22 +typedef struct ogs_paa_s { +/* 8.34 PDN Type */ +#define OGS_GTP_PDN_TYPE_IPV4 1 +#define OGS_GTP_PDN_TYPE_IPV6 2 +#define OGS_GTP_PDN_TYPE_IPV4V6 3 +#define OGS_GTP_PDN_TYPE_NON_IP 4 +ED2(uint8_t spare:5;, + uint8_t pdn_type:3;) + union { + /* GTP_PDN_TYPE_IPV4 */ + uint32_t addr; + + /* GTP_PDN_TYPE_IPV6 */ + struct { + /* the IPv6 Prefix Length */ + uint8_t len; + /* IPv6 Prefix and Interface Identifier */ + uint8_t addr6[OGS_IPV6_LEN]; + }; + + /* GTP_PDN_TYPE_BOTH */ + struct { + struct { + /* the IPv6 Prefix Length */ + uint8_t len; + /* IPv6 Prefix and Interface Identifier */ + uint8_t addr6[OGS_IPV6_LEN]; + }; + uint32_t addr; + } __attribute__ ((packed)) both; + }; +} __attribute__ ((packed)) ogs_paa_t; + +#define MAX_BIT_RATE 10000000000UL + +typedef struct ogs_bitrate_s { + uint64_t downlink; /* bits per seconds */ + uint64_t uplink; /* bits per seconds */ +} ogs_bitrate_t; + +/********************************** + * QoS Structure */ +typedef struct ogs_qos_s { +#define OGS_PDN_QCI_1 1 +#define OGS_PDN_QCI_2 2 +#define OGS_PDN_QCI_3 3 +#define OGS_PDN_QCI_4 4 +#define OGS_PDN_QCI_5 5 +#define OGS_PDN_QCI_6 6 +#define OGS_PDN_QCI_7 7 +#define OGS_PDN_QCI_8 8 +#define OGS_PDN_QCI_9 9 +#define OGS_PDN_QCI_65 65 +#define OGS_PDN_QCI_66 66 +#define OGS_PDN_QCI_69 69 +#define OGS_PDN_QCI_70 70 + uint8_t qci; + + struct { + /* Values 1 to 8 should only be assigned for services that are + * authorized to receive prioritized treatment within an operator domain. + * Values 9 to 15 may be assigned to resources that are authorized + * by the home network and thus applicable when a UE is roaming. */ + uint8_t priority_level; + +#define OGS_PDN_PRE_EMPTION_CAPABILITY_ENABLED 0 +#define OGS_PDN_PRE_EMPTION_CAPABILITY_DISABLED 1 + uint8_t pre_emption_capability; +#define OGS_PDN_PRE_EMPTION_VULNERABILITY_ENABLED 0 +#define OGS_PDN_PRE_EMPTION_VULNERABILITY_DISABLED 1 + uint8_t pre_emption_vulnerability; + } arp; + + ogs_bitrate_t mbr; /* Maxmimum Bit Rate (MBR) */ + ogs_bitrate_t gbr; /* Guaranteed Bit Rate (GBR) */ +} ogs_qos_t; + +/********************************** + * Flow Structure */ +#define OGS_FLOW_DOWNLINK_ONLY 1 +#define OGS_FLOW_UPLINK_ONLY 2 +typedef struct ogs_flow_s { + uint8_t direction; + char *description; +} ogs_flow_t; + +#define OGS_FLOW_FREE(__fLOW) \ + do { \ + if ((__fLOW)->description) \ + { \ + ogs_free((__fLOW)->description); \ + } \ + else \ + ogs_assert_if_reached(); \ + } while(0) + +/********************************** + * PCC Rule Structure */ +typedef struct ogs_pcc_rule_s { +#define OGS_PCC_RULE_TYPE_INSTALL 1 +#define OGS_PCC_RULE_TYPE_REMOVE 2 + uint8_t type; + +#define OGS_MAX_PCC_RULE_NAME_LEN 256 + char *name; + +/* Num of Flow per PCC Rule */ +#define OGS_MAX_NUM_OF_FLOW 8 + ogs_flow_t flow[OGS_MAX_NUM_OF_FLOW]; + int num_of_flow; + +#define OGS_FLOW_STATUS_ENABLED_UPLINK 0 +#define OGS_FLOW_STATUS_ENABLED_DOWNLINK 1 +#define OGS_FLOW_STATUS_ENABLED 2 +#define OGS_FLOW_STATUS_DISABLED 3 +#define OGS_FLOW_STATUS_REMOVE 4 + int flow_status; + uint32_t precedence; + + ogs_qos_t qos; +} ogs_pcc_rule_t; + +#define OGS_PCC_RULE_FREE(__pCCrULE) \ + do { \ + int __pCCrULE_iNDEX; \ + ogs_assert((__pCCrULE)); \ + if ((__pCCrULE)->name) { \ + ogs_free((__pCCrULE)->name); \ + } else \ + ogs_assert_if_reached(); \ + for (__pCCrULE_iNDEX = 0; \ + __pCCrULE_iNDEX < (__pCCrULE)->num_of_flow; __pCCrULE_iNDEX++) { \ + OGS_FLOW_FREE(&((__pCCrULE)->flow[__pCCrULE_iNDEX])); \ + } \ + (__pCCrULE)->num_of_flow = 0; \ + } while(0) + +/********************************** + * PDN Structure */ +typedef struct ogs_pdn_s { + uint32_t context_identifier; + char apn[OGS_MAX_APN_LEN+1]; +#define OGS_HSS_PDN_TYPE_IPV4 0 +#define OGS_HSS_PDN_TYPE_IPV6 1 +#define OGS_HSS_PDN_TYPE_IPV4V6 2 +#define OGS_HSS_PDN_TYPE_IPV4_OR_IPV6 3 + int pdn_type; + + ogs_qos_t qos; + ogs_bitrate_t ambr; /* APN-AMBR */ + + ogs_paa_t paa; + ogs_ip_t pgw_ip; +} ogs_pdn_t; + +int ogs_fqdn_build(char *dst, char *src, int len); +int ogs_fqdn_parse(char *dst, char *src, int len); + +/************************************************** + * Protocol Configuration Options Structure + * 8.13 Protocol Configuration Options (PCO) + * 10.5.6.3 Protocol configuration options in 3GPP TS 24.008 + * RFC 3232 [103] + * RFC 1661 [102] */ +#define OGS_PCO_PPP_FOR_USE_WITH_IP_PDP_TYPE_OR_IP_PDN_TYPE 0 + +#define OGS_PCO_ID_INTERNET_PROTOCOL_CONTROL_PROTOCOL 0x8021 +#define OGS_PCO_ID_CHALLENGE_HANDSHAKE_AUTHENTICATION_PROTOCOL 0xc223 +#define OGS_PCO_ID_P_CSCF_IPV6_ADDRESS_REQUEST 0x0001 +#define OGS_PCO_ID_DNS_SERVER_IPV6_ADDRESS_REQUEST 0x0003 +#define OGS_PCO_ID_IP_ADDRESS_ALLOCATION_VIA_NAS_SIGNALLING 0x000a +#define OGS_PCO_ID_P_CSCF_IPV4_ADDRESS_REQUEST 0x000c +#define OGS_PCO_ID_DNS_SERVER_IPV4_ADDRESS_REQUEST 0x000d +#define OGS_PCO_ID_IPV4_LINK_MTU_REQUEST 0x0010 +typedef struct ogs_pco_ipcp_options_s { + uint8_t type; + uint8_t len; + uint32_t addr; +} __attribute__ ((packed)) ogs_pco_ipcp_options_t; + +#define OGS_PCO_MAX_NUM_OF_IPCO_OPTIONS 4 +typedef struct ogs_pco_ipcp_s { + uint8_t code; + uint8_t identifier; + uint16_t len; + ogs_pco_ipcp_options_t options[OGS_PCO_MAX_NUM_OF_IPCO_OPTIONS]; +} __attribute__ ((packed)) ogs_pco_ipcp_t; + +typedef struct ogs_pco_id_s { + uint16_t id; + uint8_t len; + void *data; +} ogs_pco_id_t; + +#define OGS_MAX_NUM_OF_PROTOCOL_OR_CONTAINER_ID 16 +typedef struct ogs_pco_s { +ED3(uint8_t ext:1;, + uint8_t spare:4;, + uint8_t configuration_protocol:3;) + uint8_t num_of_id; + ogs_pco_id_t ids[OGS_MAX_NUM_OF_PROTOCOL_OR_CONTAINER_ID]; +} ogs_pco_t; + +int ogs_pco_parse(ogs_pco_t *pco, unsigned char *data, int data_len); +int ogs_pco_build(unsigned char *data, int data_len, ogs_pco_t *pco); + +#ifdef __cplusplus +} +#endif + +#endif /* OGS_3GPP_TYPES_H */ diff --git a/lib/core/ogs-abort.c b/lib/core/ogs-abort.c new file mode 100644 index 000000000..d03040727 --- /dev/null +++ b/lib/core/ogs-abort.c @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "core-config-private.h" + +#if HAVE_EXECINFO_H +#include +#endif + +#include "ogs-core.h" + +OGS_GNUC_NORETURN void ogs_abort(void) +{ +#if HAVE_BACKTRACE + int nptrs; + void *buffer[100]; + + nptrs = backtrace(buffer, OGS_ARRAY_SIZE(buffer)); + backtrace_symbols_fd(buffer, nptrs, 2); + + abort(); +#elif defined(_WIN32) + DebugBreak(); + abort(); + ExitProcess(127); +#else + abort(); +#endif +} diff --git a/lib/ogs-common.h b/lib/core/ogs-abort.h similarity index 73% rename from lib/ogs-common.h rename to lib/core/ogs-abort.h index 5cae7465a..837c59ad0 100644 --- a/lib/ogs-common.h +++ b/lib/core/ogs-abort.h @@ -17,29 +17,21 @@ * along with this program. If not, see . */ -#ifndef OGS_COMMON_H -#define OGS_COMMON_H - -#include "ogs-core.h" - -#ifdef HAVE_CONFIG_H -#undef PACKAGE -#undef PACKAGE_BUGREPORT -#undef PACKAGE_NAME -#undef PACKAGE_STRING -#undef PACKAGE_TARNAME -#undef PACKAGE_URL -#undef PACKAGE_VERSION -#undef VERSION -#include "nextepc-config.h" +#if !defined(OGS_CORE_INSIDE) && !defined(OGS_CORE_COMPILATION) +#error "This header cannot be included directly." #endif +#ifndef OGS_ABORT_H +#define OGS_ABORT_H + #ifdef __cplusplus extern "C" { #endif +OGS_GNUC_NORETURN void ogs_abort(void); + #ifdef __cplusplus } #endif -#endif /* OGS_COMMON_H */ +#endif /* OGS_ABORT_H */ diff --git a/lib/core/ogs-compat.h b/lib/core/ogs-compat.h new file mode 100644 index 000000000..aa0c816f4 --- /dev/null +++ b/lib/core/ogs-compat.h @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#if !defined(OGS_CORE_INSIDE) && !defined(OGS_CORE_COMPILATION) +#error "This header cannot be included directly." +#endif + +#ifndef OGS_COMPAT_H +#define OGS_COMPAT_H + +#if defined(_WIN32) + +#include +#include /* IPv6 */ + +#ifndef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN +#include +#undef WIN32_LEAN_AND_MEAN +#else +#include +#endif + +/* For structs needed by GetAdaptersAddresses */ +#if defined(_WIN32_WINNT) && (_WIN32_WINNT < 0x0600) +#undef _WIN32_WINNT +#endif +#ifndef _WIN32_WINNT +#define _WIN32_WINNT 0x0600 +#endif + +#else /* !defined(_WIN32) */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#endif + +#endif diff --git a/lib/core/ogs-conv.c b/lib/core/ogs-conv.c new file mode 100644 index 000000000..183214534 --- /dev/null +++ b/lib/core/ogs-conv.c @@ -0,0 +1,146 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "core-config-private.h" + +#if HAVE_CTYPE_H +#include +#endif + +#include "ogs-core.h" + +void *ogs_ascii_to_hex(char *in, int in_len, void *out, int out_len) +{ + int i = 0, j = 0, k = 0, hex; + uint8_t *out_p = out; + + while(i < in_len && j < out_len) + { + if (!isspace(in[i])) + { + hex = isdigit(in[i]) ? in[i] - '0' : + islower(in[i]) ? in[i] - 'a' + 10 : in[i] - 'A' + 10; + if ((k & 0x1) == 0) + { + out_p[j] = (hex << 4); + } + else + { + out_p[j] |= hex; + j++; + } + k++; + } + i++; + } + + return out; +} + +void *ogs_hex_to_ascii(void *in, int in_len, void *out, int out_len) +{ + char *p; + int i = 0, l, off = 0; + + p = out; + p[0] = 0; + + l = (in_len - off) > out_len ? out_len : in_len - off; + for (i = 0; i < l; i++) + { + p += sprintf(p, "%02X", ((char*)in)[off+i] & 0xff); + if ((i & 0x3) == 3 && (i != (l-1))) p += sprintf(p, " "); + } + + return out; +} + +void *ogs_uint64_to_buffer(uint64_t num, int size, void *buffer) +{ + int i; + uint8_t *buffer_p = buffer; + for (i = 0; i < size; i++) + buffer_p[i] = (num >> ((size-1-i) * 8)) & 0xff; + + return buffer; +} + +uint64_t ogs_buffer_to_uint64(void *buffer, int size) +{ + uint64_t num = 0; + uint8_t *buffer_p = buffer; + int i; + + for (i = 0; i < size; i++) + { + num |= (((uint64_t)buffer_p[i]) << ((size-1-i) * 8)); + } + + return num; +} + +void *ogs_bcd_to_buffer(const char *in, void *out, int *out_len) +{ + int i = 0; + uint8_t *out_p = out; + int in_len = strlen(in); + + for (i = 0; i < in_len; i++) + { + if (i & 0x01) + out_p[i>>1] = out_p[i>>1] | (((in[i] - 0x30) << 4) & 0xF0); + else + out_p[i>>1] = (in[i] - 0x30) & 0x0F; + } + + *out_len = (in_len + 1) / 2; + if (in_len & 0x01) + { + out_p[(*out_len)-1] |= 0xF0; + } + + return out; +} + +void *ogs_buffer_to_bcd(uint8_t *in, int in_len, void *out) +{ + int i = 0; + uint8_t *out_p = out; + + for (i = 0; i < in_len-1; i++) + { + out_p[i*2] = 0x30 + (in[i] & 0x0F); + out_p[i*2+1] = 0x30 + ((in[i] & 0xF0) >> 4); + } + + if ((in[i] & 0xF0) == 0xF0) + { + out_p[i*2] = 0x30 + (in[i] & 0x0F); + out_p[i*2+1] = 0; + } + else + { + out_p[i*2] = 0x30 + (in[i] & 0x0F); + out_p[i*2+1] = 0x30 + ((in[i] & 0xF0) >> 4); + out_p[i*2+2] = 0; + } + + return out; +} + diff --git a/lib/core/ogs-conv.h b/lib/core/ogs-conv.h new file mode 100644 index 000000000..217468c4b --- /dev/null +++ b/lib/core/ogs-conv.h @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#if !defined(OGS_CORE_INSIDE) && !defined(OGS_CORE_COMPILATION) +#error "This header cannot be included directly." +#endif + +#ifndef OGS_CONV_H +#define OGS_CONV_H + +#ifdef __cplusplus +extern "C" { +#endif + +#define OGS_HEX(I, I_LEN, O) ogs_ascii_to_hex((char*)I, I_LEN, O, sizeof(O)) +void *ogs_ascii_to_hex(char *in, int in_len, void *out, int out_len); +void *ogs_hex_to_ascii(void *in, int in_len, void *out, int out_len); +void *ogs_uint64_to_buffer(uint64_t num, int size, void *buffer); +uint64_t ogs_buffer_to_uint64(void *buffer, int size); +void *ogs_bcd_to_buffer(const char *in, void *out, int *out_len); +void *ogs_buffer_to_bcd(uint8_t *in, int in_len, void *out); + +#ifdef __cplusplus +} +#endif + +#endif /* OGS_CONV_H */ diff --git a/lib/core/ogs-core.c b/lib/core/ogs-core.c new file mode 100644 index 000000000..53e93cfd6 --- /dev/null +++ b/lib/core/ogs-core.c @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "ogs-core.h" + +int __ogs_mem_domain; +int __ogs_sock_domain; +int __ogs_event_domain; +int __ogs_thread_domain; +int __ogs_tlv_domain; + +static ogs_core_context_t self = { + .log.pool = 8, + .log.domain_pool = 64, + .log.level = OGS_LOG_DEFAULT, + + .pkbuf.pool = 8, + .pkbuf.config_pool = 8, + + .socket.pool = 128, + .timer.pool = 512, + + .tlv.pool = 512, +}; + +void ogs_core_initialize(void) +{ + ogs_log_init(); + ogs_pkbuf_init(); + ogs_socket_init(); + ogs_tlv_init(); + + ogs_log_install_domain(&__ogs_mem_domain, "mem", ogs_core()->log.level); + ogs_log_install_domain(&__ogs_sock_domain, "sock", ogs_core()->log.level); + ogs_log_install_domain(&__ogs_event_domain, "event", ogs_core()->log.level); + ogs_log_install_domain(&__ogs_thread_domain, + "thread", ogs_core()->log.level); + ogs_log_install_domain(&__ogs_tlv_domain, "tlv", ogs_core()->log.level); +} + +void ogs_core_terminate(void) +{ + ogs_tlv_final(); + ogs_socket_final(); + ogs_pkbuf_final(); + ogs_log_final(); +} + +ogs_core_context_t *ogs_core(void) +{ + return &self; +} diff --git a/lib/core/ogs-core.h b/lib/core/ogs-core.h new file mode 100644 index 000000000..fa114a91a --- /dev/null +++ b/lib/core/ogs-core.h @@ -0,0 +1,109 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef OGS_CORE_H +#define OGS_CORE_H + +#include "core/core-config.h" + +#define OGS_CORE_INSIDE + +#include "core/ogs-compat.h" +#include "core/ogs-macros.h" +#include "core/ogs-list.h" +#include "core/ogs-pool.h" +#include "core/ogs-abort.h" +#include "core/ogs-strings.h" +#include "core/ogs-errno.h" +#include "core/ogs-time.h" +#include "core/ogs-conv.h" +#include "core/ogs-log.h" +#include "core/ogs-pkbuf.h" +#include "core/ogs-memory.h" +#include "core/ogs-rand.h" +#include "core/ogs-rbtree.h" +#include "core/ogs-timer.h" +#include "core/ogs-thread.h" +#include "core/ogs-process.h" +#include "core/ogs-signal.h" +#include "core/ogs-sockaddr.h" +#include "core/ogs-socket.h" +#include "core/ogs-sockpair.h" +#include "core/ogs-socknode.h" +#include "core/ogs-udp.h" +#include "core/ogs-tcp.h" +#include "core/ogs-queue.h" +#include "core/ogs-poll.h" +#include "core/ogs-notify.h" +#include "core/ogs-tlv.h" +#include "core/ogs-env.h" +#include "core/ogs-fsm.h" +#include "core/ogs-hash.h" +#include "core/ogs-misc.h" +#include "core/ogs-getopt.h" +#include "core/ogs-3gpp-types.h" + +#undef OGS_CORE_INSIDE + +#ifdef __cplusplus +extern "C" { +#endif + +extern int __ogs_mem_domain; +extern int __ogs_sock_domain; +extern int __ogs_event_domain; +extern int __ogs_thread_domain; +extern int __ogs_tlv_domain; + +typedef struct { + struct { + int pool; + int domain_pool; + ogs_log_level_e level; + } log; + + struct { + int pool; + int config_pool; + } pkbuf; + + struct { + int pool; + } socket; + + struct { + int pool; + } timer; + + struct { + int pool; + } tlv; + +} ogs_core_context_t; + +void ogs_core_initialize(void); +void ogs_core_terminate(void); + +ogs_core_context_t *ogs_core(void); + +#ifdef __cplusplus +} +#endif + +#endif /* OGS_CORE_H */ diff --git a/lib/core/ogs-env.c b/lib/core/ogs-env.c new file mode 100644 index 000000000..f8553f7d4 --- /dev/null +++ b/lib/core/ogs-env.c @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "core-config-private.h" + +#include "ogs-core.h" + +char *ogs_env_get(const char *envvar) +{ +#ifdef HAVE_GETENV + return getenv(envvar); +#else + return NULL; +#endif +} + + +int ogs_env_set(const char *envvar, const char *value) +{ +#if defined(HAVE_SETENV) + + if (0 > setenv(envvar, value, 1)) { + ogs_log_message(OGS_LOG_ERROR, ogs_errno, "setenv() failed"); + return OGS_ERROR; + } + return OGS_OK; + +#elif defined(HAVE_PUTENV) + + char buf[OGS_HUGE_LEN]; + + if (ogs_snprintf(buf, OGS_HUGE_LEN, "%s=%s", envvar, value) < 0) { + ogs_error("snprintf() failed"); + return OGS_ERROR; + } + if (0 > putenv(buf)) { + ogs_log_message(OGS_LOG_ERROR, ogs_errno, "putenv() failed"); + return OGS_ERROR; + } + return OGS_OK; + +#else + ogs_error("Not implemented"); + return OGS_ERROR; +#endif +} + + +int ogs_env_delete(const char *envvar) +{ +#ifdef HAVE_UNSETENV + + if (0 > unsetenv(envvar)) { + ogs_error("unsetenv() failed"); + return OGS_ERROR; + } + return OGS_OK; + +#else + /* hint: some platforms allow envvars to be unset via + * putenv("varname")... that isn't Single Unix spec, + * but if your platform doesn't have unsetenv() it is + * worth investigating and potentially adding a + * configure check to decide when to use that form of + * putenv() here + */ + ogs_error("Not implemented"); + return OGS_ERROR; +#endif +} diff --git a/lib/core/ogs-env.h b/lib/core/ogs-env.h new file mode 100644 index 000000000..c04d77932 --- /dev/null +++ b/lib/core/ogs-env.h @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#if !defined(OGS_CORE_INSIDE) && !defined(OGS_CORE_COMPILATION) +#error "This header cannot be included directly." +#endif + +#ifndef OGS_ENV_H +#define OGS_ENV_H + +#ifdef __cplusplus +extern "C" { +#endif + +char *ogs_env_get(const char *envvar); +int ogs_env_set(const char *envvar, const char *value); +int ogs_env_delete(const char *envvar); + +#ifdef __cplusplus +} +#endif + +#endif /* OGS_ENV_H */ diff --git a/lib/core/ogs-epoll.c b/lib/core/ogs-epoll.c new file mode 100644 index 000000000..2ce394d55 --- /dev/null +++ b/lib/core/ogs-epoll.c @@ -0,0 +1,194 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "core-config-private.h" + +#if HAVE_UNISTD_H +#include +#endif + +#include + +#include "ogs-core.h" +#include "ogs-poll-private.h" + +static void epoll_init(ogs_pollset_t *pollset); +static void epoll_cleanup(ogs_pollset_t *pollset); +static int epoll_add(ogs_poll_t *poll, short when); +static int epoll_remove(ogs_poll_t *poll); +static int epoll_process(ogs_pollset_t *pollset, ogs_time_t timeout); + +const ogs_pollset_actions_t ogs_epoll_actions = { + epoll_init, + epoll_cleanup, + + epoll_add, + epoll_remove, + epoll_process, + + ogs_notify_pollset, +}; + +struct epoll_context_s { + int epfd; + + struct epoll_event *event_list; +}; + +static void epoll_init(ogs_pollset_t *pollset) +{ + struct epoll_context_s *context = NULL; + ogs_assert(pollset); + + context = ogs_calloc(1, sizeof *context); + ogs_assert(context); + pollset->context = context; + + context->event_list = ogs_calloc( + ogs_core()->socket.pool, sizeof(struct epoll_event)); + ogs_assert(context->event_list); + + context->epfd = epoll_create(ogs_core()->socket.pool); + ogs_assert(context->epfd >= 0); + + ogs_notify_init(pollset); +} + +static void epoll_cleanup(ogs_pollset_t *pollset) +{ + struct epoll_context_s *context = NULL; + + ogs_assert(pollset); + context = pollset->context; + ogs_assert(context); + + ogs_notify_final(pollset); + close(context->epfd); + ogs_free(context->event_list); + + ogs_free(context); +} + +static int epoll_add(ogs_poll_t *poll, short when) +{ + ogs_pollset_t *pollset = NULL; + struct epoll_context_s *context = NULL; + int rv; + struct epoll_event ee; + + ogs_assert(poll); + pollset = poll->pollset; + ogs_assert(pollset); + context = pollset->context; + ogs_assert(context); + + ee.events = 0; + if (when == OGS_POLLIN) + ee.events |= (EPOLLIN|EPOLLRDHUP); + if (when == OGS_POLLOUT) + ee.events |= EPOLLOUT; + + ee.data.ptr = poll; + + rv = epoll_ctl(context->epfd, EPOLL_CTL_ADD, poll->fd, &ee); + if (rv < 0) { + ogs_log_message(OGS_LOG_ERROR, ogs_socket_errno, "epoll_ctl failed"); + return OGS_ERROR; + } + + return OGS_OK; +} + +static int epoll_remove(ogs_poll_t *poll) +{ + int rv; + ogs_pollset_t *pollset = NULL; + struct epoll_context_s *context = NULL; + struct epoll_event ee; + + ogs_assert(poll); + pollset = poll->pollset; + ogs_assert(pollset); + context = pollset->context; + ogs_assert(context); + + ee.events = 0; + ee.data.ptr = NULL; + + rv = epoll_ctl(context->epfd, EPOLL_CTL_DEL, poll->fd, &ee); + if (rv < 0) { + ogs_log_message(OGS_LOG_ERROR, ogs_socket_errno, + "epoll_remove failed"); + return OGS_ERROR; + } + + return OGS_OK; +} + +static int epoll_process(ogs_pollset_t *pollset, ogs_time_t timeout) +{ + struct epoll_context_s *context = NULL; + int num_of_poll; + int i; + + ogs_assert(pollset); + context = pollset->context; + ogs_assert(context); + + num_of_poll = epoll_wait(context->epfd, context->event_list, + ogs_core()->socket.pool, + timeout == OGS_INFINITE_TIME ? OGS_INFINITE_TIME : + ogs_time_to_msec(timeout)); + if (num_of_poll < 0) { + ogs_log_message(OGS_LOG_ERROR, ogs_socket_errno, "epoll failed"); + return OGS_ERROR; + } else if (num_of_poll == 0) { + return OGS_TIMEUP; + } + + for (i = 0; i < num_of_poll; i++) { + ogs_poll_t *poll = NULL; + uint32_t received; + short when = 0; + + received = context->event_list[i].events; + if (received & (EPOLLERR|EPOLLHUP)) { + when = OGS_POLLIN|OGS_POLLOUT; + } else { + if (received & (EPOLLIN|EPOLLRDHUP)) { + when |= OGS_POLLIN; + } + if (received & EPOLLOUT) { + when |= OGS_POLLOUT; + } + } + + if (!when) + continue; + + poll = context->event_list[i].data.ptr; + ogs_assert(poll); + + if (poll->handler) { + poll->handler(when, poll->fd, poll->data); + } + } + + return OGS_OK; +} diff --git a/lib/core/ogs-errno.c b/lib/core/ogs-errno.c new file mode 100644 index 000000000..b5992e3b6 --- /dev/null +++ b/lib/core/ogs-errno.c @@ -0,0 +1,78 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "core-config-private.h" + +#include "ogs-core.h" + +char *ogs_strerror(ogs_err_t err, char *buf, size_t size) +{ +#if defined(_WIN32) + /* + * The following code is stolen from APR Library + * http://svn.apache.org/repos/asf/apr/apr/trunk/misc/unix/errorcodes.c + */ + size_t len = 0, i; + LPTSTR msg = (LPTSTR)buf; + len = FormatMessage( + FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, + err, + MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), /* Default Language */ + msg, + (DWORD)(size/sizeof(TCHAR)), + NULL); + + if (len) { + /* FormatMessage put the message in the buffer, but it may + * have embedded a newline (\r\n), and possible more than one. + * Remove the newlines replacing them with a space. This is not + * as visually perfect as moving all the remaining message over, + * but more efficient. + */ + i = len; + while (i) { + i--; + if ((buf[i] == '\r') || (buf[i] == '\n')) + buf[i] = ' '; + } + } + else { + /* Windows didn't provide us with a message. Even stuff like */ + ogs_snprintf(buf, size, "Unrecognized Win32 error code %d", (int)err); + } + + return buf; +#elif defined(HAVE_STRERROR_R) + +#if defined(STRERROR_R_CHAR_P) + return strerror_r(err, buf, size); +#else + int ret = strerror_r(err, buf, size); + + if (ret == 0) + return buf; + else + return NULL; +#endif + +#else +#error TODO +#endif +} diff --git a/lib/core/ogs-errno.h b/lib/core/ogs-errno.h new file mode 100644 index 000000000..991c9b4e4 --- /dev/null +++ b/lib/core/ogs-errno.h @@ -0,0 +1,85 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#if !defined(OGS_CORE_INSIDE) && !defined(OGS_CORE_COMPILATION) +#error "This header cannot be included directly." +#endif + +#ifndef OGS_ERRNO_H +#define OGS_ERRNO_H + +#ifdef __cplusplus +extern "C" { +#endif + +#if defined(_WIN32) + +typedef DWORD ogs_err_t; + +#define OGS_ENOMEM ERROR_NOT_ENOUGH_MEMORY +#define OGS_EACCES ERROR_ACCESS_DENIED +#define OGS_EEXIST ERROR_ALREADY_EXISTS +#define OGS_EEXIST_FILE ERROR_FILE_EXISTS +#define OGS_ETIMEDOUT WSAETIMEDOUT +#define OGS_ECONNREFUSED WSAECONNREFUSED +#define OGS_EBADF WSAEBADF +#define OGS_EAGAIN WSAEWOULDBLOCK + +#define ogs_errno GetLastError() +#define ogs_set_errno(err) SetLastError(err) +#define ogs_socket_errno WSAGetLastError() +#define ogs_set_socket_errno(err) WSASetLastError(err) + +#else + +typedef int ogs_err_t; + +#define OGS_ENOMEM ENOMEM +#define OGS_EACCES EACCES +#define OGS_EEXIST EEXIST +#define OGS_EEXIST_FILE EEXIST +#define OGS_ETIMEDOUT ETIMEDOUT +#define OGS_ECONNREFUSED ECONNREFUSED +#define OGS_EBADF EBADF +#if (__hpux__) +#define OGS_EAGAIN EWOULDBLOCK +#else +#define OGS_EAGAIN EAGAIN +#endif + +#define ogs_errno errno +#define ogs_socket_errno errno +#define ogs_set_errno(err) errno = err +#define ogs_set_socket_errno(err) errno = err + +#endif + +#define OGS_OK 0 +#define OGS_ERROR -1 +#define OGS_RETRY -2 +#define OGS_TIMEUP -3 +#define OGS_DONE -4 + +char *ogs_strerror(ogs_err_t err, char *buf, size_t size); + +#ifdef __cplusplus +} +#endif + +#endif /* OGS_ERRNO_H */ diff --git a/lib/core/ogs-fsm.c b/lib/core/ogs-fsm.c new file mode 100644 index 000000000..d244f9846 --- /dev/null +++ b/lib/core/ogs-fsm.c @@ -0,0 +1,98 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "ogs-core.h" + +typedef struct fsm_event_s { + int id; +} fsm_event_t; + +static fsm_event_t entry_event = { + OGS_FSM_ENTRY_SIG, +}; +static fsm_event_t exit_event = { + OGS_FSM_EXIT_SIG, +}; + +const char *OGS_FSM_NAME_INIT_SIG = "INIT"; +const char *OGS_FSM_NAME_ENTRY_SIG = "ENTRY"; +const char *OGS_FSM_NAME_EXIT_SIG = "EXIT"; + +void ogs_fsm_init(void *sm, void *event) +{ + ogs_fsm_t *s = sm; + fsm_event_t *e = event; + + if (s->init != NULL) + { + (*s->init)(s, e); + if (s->init != s->state) { + if (e) { + e->id = OGS_FSM_ENTRY_SIG; + (*s->state)(s, e); + } else { + (*s->state)(s, &entry_event); + } + } + } +} + +void ogs_fsm_dispatch(void *sm, void *event) +{ + ogs_fsm_t *s = sm; + fsm_event_t *e = event; + ogs_fsm_handler_t tmp = s->state; + + (*tmp)(s, e); + if (s->state != tmp) { + if (e) { + e->id = OGS_FSM_EXIT_SIG; + (*tmp)(s, e); + } else { + (*tmp)(s, &exit_event); + } + if (e) { + e->id = OGS_FSM_ENTRY_SIG; + (*s->state)(s, e); + } else { + (*s->state)(s, &entry_event); + } + } +} + +void ogs_fsm_fini(void *sm, void *event) +{ + ogs_fsm_t *s = sm; + fsm_event_t *e = event; + + if (s->fini != s->state) { + if (e) { + e->id = OGS_FSM_EXIT_SIG; + (*s->state)(s, e); + } else { + (*s->state)(s, &exit_event); + } + } + + if (s->fini != NULL) { + (*s->fini)(s, e); + } + + s->state = s->init; +} diff --git a/lib/core/ogs-fsm.h b/lib/core/ogs-fsm.h new file mode 100644 index 000000000..1923cc691 --- /dev/null +++ b/lib/core/ogs-fsm.h @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#if !defined(OGS_CORE_INSIDE) && !defined(OGS_CORE_COMPILATION) +#error "This header cannot be included directly." +#endif + +#ifndef OGS_FSM_H +#define OGS_FSM_H + +#ifdef __cplusplus +extern "C" { +#endif + +extern const char *OGS_FSM_NAME_INIT_SIG; +extern const char *OGS_FSM_NAME_ENTRY_SIG; +extern const char *OGS_FSM_NAME_EXIT_SIG; + +typedef enum { + OGS_FSM_ENTRY_SIG, + OGS_FSM_EXIT_SIG, + OGS_FSM_USER_SIG +} ogs_fsm_signal_e; + +typedef void (*ogs_fsm_handler_t)(void *sm, void *event); + +typedef struct _ogs_fsm_t { + ogs_fsm_handler_t init; + ogs_fsm_handler_t fini; + ogs_fsm_handler_t state; +} ogs_fsm_t; + +#define ogs_fsm_create(__s, __i, __f) \ + (((__s)->init = (__s)->state = (ogs_fsm_handler_t)(__i)), \ + (__s)->fini = (ogs_fsm_handler_t)(__f)) + +#define ogs_fsm_delete(__s) \ + ((__s)->init = (__s)->state = (__s)->fini = NULL) + +void ogs_fsm_init(void *sm, void *event); +void ogs_fsm_dispatch(void *sm, void *event); +void ogs_fsm_fini(void *sm, void *event); + +#define OGS_FSM_TRAN(__s, __target) \ + ((ogs_fsm_t *)__s)->state = (ogs_fsm_handler_t)(__target) + +#define OGS_FSM_STATE(__s) \ + (((ogs_fsm_t *)__s)->state) + +#define OGS_FSM_CHECK(__s, __f) \ + (OGS_FSM_STATE(__s) == (ogs_fsm_handler_t)__f) + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* OGS_FSM_H */ diff --git a/lib/core/ogs-getopt.c b/lib/core/ogs-getopt.c new file mode 100644 index 000000000..8e0faaf17 --- /dev/null +++ b/lib/core/ogs-getopt.c @@ -0,0 +1,287 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "ogs-getopt.h" + +#define OGS_GETOPT_MSG_INVALID "invalid option" +#define OGS_GETOPT_MSG_MISSING "option requires an argument" +#define OGS_GETOPT_MSG_TOOMANY "option takes no arguments" + +static int ogs_getopt_error( + ogs_getopt_t *options, const char *msg, const char *data) +{ + unsigned p = 0; + const char *sep = " -- '"; + while (*msg) + options->errmsg[p++] = *msg++; + while (*sep) + options->errmsg[p++] = *sep++; + while (p < sizeof(options->errmsg) - 2 && *data) + options->errmsg[p++] = *data++; + options->errmsg[p++] = '\''; + options->errmsg[p++] = '\0'; + return '?'; +} + +void ogs_getopt_init(ogs_getopt_t *options, char **argv) +{ + options->argv = argv; + options->permute = 1; + options->optind = 1; + options->subopt = 0; + options->optarg = 0; + options->errmsg[0] = '\0'; +} + +static int ogs_getopt_is_dashdash(const char *arg) +{ + return arg != 0 && arg[0] == '-' && arg[1] == '-' && arg[2] == '\0'; +} + +static int ogs_getopt_is_shortopt(const char *arg) +{ + return arg != 0 && arg[0] == '-' && arg[1] != '-' && arg[1] != '\0'; +} + +static int +ogs_getopt_is_longopt(const char *arg) +{ + return arg != 0 && arg[0] == '-' && arg[1] == '-' && arg[2] != '\0'; +} + +static void ogs_getopt_permute(ogs_getopt_t *options, int index) +{ + char *nonoption = options->argv[index]; + int i; + for (i = index; i < options->optind - 1; i++) + options->argv[i] = options->argv[i + 1]; + options->argv[options->optind - 1] = nonoption; +} + +static int ogs_getopt_argtype(const char *optstring, char c) +{ + int count = OGS_GETOPT_NONE; + if (c == ':') + return -1; + for (; *optstring && c != *optstring; optstring++); + if (!*optstring) + return -1; + if (optstring[1] == ':') + count += optstring[2] == ':' ? 2 : 1; + return count; +} + +int ogs_getopt(ogs_getopt_t *options, const char *optstring) +{ + int type; + char *next; + char *option = options->argv[options->optind]; + options->errmsg[0] = '\0'; + options->optopt = 0; + options->optarg = 0; + if (option == 0) { + return -1; + } else if (ogs_getopt_is_dashdash(option)) { + options->optind++; /* consume "--" */ + return -1; + } else if (!ogs_getopt_is_shortopt(option)) { + if (options->permute) { + int index = options->optind++; + int r = ogs_getopt(options, optstring); + ogs_getopt_permute(options, index); + options->optind--; + return r; + } else { + return -1; + } + } + option += options->subopt + 1; + options->optopt = option[0]; + type = ogs_getopt_argtype(optstring, option[0]); + next = options->argv[options->optind + 1]; + switch (type) { + case -1: { + char str[2] = {0, 0}; + str[0] = option[0]; + options->optind++; + return ogs_getopt_error(options, OGS_GETOPT_MSG_INVALID, str); + } + case OGS_GETOPT_NONE: + if (option[1]) { + options->subopt++; + } else { + options->subopt = 0; + options->optind++; + } + return option[0]; + case OGS_GETOPT_REQUIRED: + options->subopt = 0; + options->optind++; + if (option[1]) { + options->optarg = option + 1; + } else if (next != 0) { + options->optarg = next; + options->optind++; + } else { + char str[2] = {0, 0}; + str[0] = option[0]; + options->optarg = 0; + return ogs_getopt_error(options, OGS_GETOPT_MSG_MISSING, str); + } + return option[0]; + case OGS_GETOPT_OPTIONAL: + options->subopt = 0; + options->optind++; + if (option[1]) + options->optarg = option + 1; + else + options->optarg = 0; + return option[0]; + } + return 0; +} + +char *ogs_getopt_arg(ogs_getopt_t *options) +{ + char *option = options->argv[options->optind]; + options->subopt = 0; + if (option != 0) + options->optind++; + return option; +} + +static int ogs_getopt_longopts_end(const ogs_getopt_long_t *longopts, int i) +{ + return !longopts[i].longname && !longopts[i].shortname; +} + +static void +ogs_getopt_from_long(const ogs_getopt_long_t *longopts, char *optstring) +{ + char *p = optstring; + int i; + for (i = 0; !ogs_getopt_longopts_end(longopts, i); i++) { + if (longopts[i].shortname) { + int a; + *p++ = longopts[i].shortname; + for (a = 0; a < (int)longopts[i].argtype; a++) + *p++ = ':'; + } + } + *p = '\0'; +} + +/* Unlike strcmp(), handles options containing "=". */ +static int ogs_getopt_longopts_match(const char *longname, const char *option) +{ + const char *a = option, *n = longname; + if (longname == 0) + return 0; + for (; *a && *n && *a != '='; a++, n++) + if (*a != *n) + return 0; + return *n == '\0' && (*a == '\0' || *a == '='); +} + +/* Return the part after "=", or NULL. */ +static char *ogs_getopt_longopts_arg(char *option) +{ + for (; *option && *option != '='; option++); + if (*option == '=') + return option + 1; + else + return 0; +} + +static int ogs_getopt_long_fallback(ogs_getopt_t *options, + const ogs_getopt_long_t *longopts, + int *longindex) +{ + int result; + char optstring[96 * 3 + 1]; /* 96 ASCII printable characters */ + ogs_getopt_from_long(longopts, optstring); + result = ogs_getopt(options, optstring); + if (longindex != 0) { + *longindex = -1; + if (result != -1) { + int i; + for (i = 0; !ogs_getopt_longopts_end(longopts, i); i++) + if (longopts[i].shortname == options->optopt) + *longindex = i; + } + } + return result; +} + +int ogs_getopt_long(ogs_getopt_t *options, + const ogs_getopt_long_t *longopts, + int *longindex) +{ + int i; + char *option = options->argv[options->optind]; + if (option == 0) { + return -1; + } else if (ogs_getopt_is_dashdash(option)) { + options->optind++; /* consume "--" */ + return -1; + } else if (ogs_getopt_is_shortopt(option)) { + return ogs_getopt_long_fallback(options, longopts, longindex); + } else if (!ogs_getopt_is_longopt(option)) { + if (options->permute) { + int index = options->optind++; + int r = ogs_getopt_long(options, longopts, longindex); + ogs_getopt_permute(options, index); + options->optind--; + return r; + } else { + return -1; + } + } + + /* Parse as long option. */ + options->errmsg[0] = '\0'; + options->optopt = 0; + options->optarg = 0; + option += 2; /* skip "--" */ + options->optind++; + for (i = 0; !ogs_getopt_longopts_end(longopts, i); i++) { + const char *name = longopts[i].longname; + if (ogs_getopt_longopts_match(name, option)) { + char *arg; + if (longindex) + *longindex = i; + options->optopt = longopts[i].shortname; + arg = ogs_getopt_longopts_arg(option); + if (longopts[i].argtype == OGS_GETOPT_NONE && arg != 0) { + return ogs_getopt_error(options, OGS_GETOPT_MSG_TOOMANY, name); + } if (arg != 0) { + options->optarg = arg; + } else if (longopts[i].argtype == OGS_GETOPT_REQUIRED) { + options->optarg = options->argv[options->optind]; + if (options->optarg == 0) + return ogs_getopt_error( + options, OGS_GETOPT_MSG_MISSING, name); + else + options->optind++; + } + return options->optopt; + } + } + return ogs_getopt_error(options, OGS_GETOPT_MSG_INVALID, option); +} diff --git a/lib/core/ogs-getopt.h b/lib/core/ogs-getopt.h new file mode 100644 index 000000000..40e2682d4 --- /dev/null +++ b/lib/core/ogs-getopt.h @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#if !defined(OGS_CORE_INSIDE) && !defined(OGS_CORE_COMPILATION) +#error "This header cannot be included directly." +#endif + +#ifndef OGS_GETOPT_H +#define OGS_GETOPT_H + +/* + * The following code is stolen from optparse + * https://github.com/skeeto/optparse + */ + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct ogs_getopt_s { + char **argv; + int permute; + int optind; + int optopt; + char *optarg; + char errmsg[64]; + int subopt; +} ogs_getopt_t; + +typedef enum { + OGS_GETOPT_NONE, + OGS_GETOPT_REQUIRED, + OGS_GETOPT_OPTIONAL +} ogs_getopt_argtype_e; + +typedef struct ogs_getopt_long_s { + const char *longname; + int shortname; + ogs_getopt_argtype_e argtype; +} ogs_getopt_long_t; + +void ogs_getopt_init(ogs_getopt_t *options, char **argv); +int ogs_getopt(ogs_getopt_t *options, const char *optstring); +int ogs_getopt_long(ogs_getopt_t *options, + const ogs_getopt_long_t *longopts, + int *longindex); +char *ogs_getopt_arg(ogs_getopt_t *options); + +#ifdef __cplusplus +} +#endif + +#endif /* OGS_GETOPT_H */ diff --git a/lib/core/ogs-hash.c b/lib/core/ogs-hash.c new file mode 100644 index 000000000..8664af8b3 --- /dev/null +++ b/lib/core/ogs-hash.c @@ -0,0 +1,370 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "ogs-core.h" + +typedef struct ogs_hash_entry_t ogs_hash_entry_t; +struct ogs_hash_entry_t { + ogs_hash_entry_t *next; + unsigned int hash; + const void *key; + int klen; + const void *val; +}; + +struct ogs_hash_index_t { + ogs_hash_t *ht; + ogs_hash_entry_t *this, *next; + unsigned int index; +}; + +struct ogs_hash_t { + ogs_hash_entry_t **array; + ogs_hash_index_t iterator; /* For ogs_hash_first(NULL, ...) */ + unsigned int count, max, seed; + ogs_hashfunc_t hash_func; + ogs_hash_entry_t *free; /* List of recycled entries */ +}; + +#define INITIAL_MAX 15 /* tunable == 2^n - 1 */ + +static ogs_hash_entry_t **alloc_array(ogs_hash_t *ht, unsigned int max) +{ + return ogs_calloc(1, sizeof(*ht->array) * (max + 1)); +} + +ogs_hash_t *ogs_hash_make() +{ + ogs_hash_t *ht; + ogs_time_t now = ogs_get_monotonic_time(); + + ht = ogs_malloc(sizeof(ogs_hash_t)); + + ht->free = NULL; + ht->count = 0; + ht->max = INITIAL_MAX; + ht->seed = (unsigned int)((now >> 32) ^ now ^ + (uintptr_t)ht ^ (uintptr_t)&now) - 1; + ht->array = alloc_array(ht, ht->max); + ht->hash_func = NULL; + + return ht; +} + +ogs_hash_t *ogs_hash_make_custom(ogs_hashfunc_t hash_func) +{ + ogs_hash_t *ht = ogs_hash_make(); + ht->hash_func = hash_func; + return ht; +} + +void ogs_hash_destroy(ogs_hash_t *ht) +{ + ogs_hash_entry_t *he = NULL, *next_he = NULL; + + ogs_assert(ht); + ogs_assert(ht->array); + + ogs_hash_clear(ht); + + he = ht->free; + while(he) { + next_he = he->next; + + ogs_free(he); + he = next_he; + } + + ogs_free(ht->array); + ogs_free(ht); +} + +ogs_hash_index_t *ogs_hash_next(ogs_hash_index_t *hi) +{ + hi->this = hi->next; + while (!hi->this) { + if (hi->index > hi->ht->max) + return NULL; + + hi->this = hi->ht->array[hi->index++]; + } + hi->next = hi->this->next; + return hi; +} + +ogs_hash_index_t *ogs_hash_first(ogs_hash_t *ht) +{ + ogs_hash_index_t *hi; + + hi = &ht->iterator; + + hi->ht = ht; + hi->index = 0; + hi->this = NULL; + hi->next = NULL; + return ogs_hash_next(hi); +} + +void ogs_hash_this(ogs_hash_index_t *hi, + const void **key, int *klen, void **val) +{ + if (key) *key = hi->this->key; + if (klen) *klen = hi->this->klen; + if (val) *val = (void *)hi->this->val; +} + +const void *ogs_hash_this_key(ogs_hash_index_t *hi) +{ + const void *key; + + ogs_hash_this(hi, &key, NULL, NULL); + return key; +} + +int ogs_hash_this_key_len(ogs_hash_index_t *hi) +{ + int klen; + + ogs_hash_this(hi, NULL, &klen, NULL); + return klen; +} + +void *ogs_hash_this_val(ogs_hash_index_t *hi) +{ + void *val; + + ogs_hash_this(hi, NULL, NULL, &val); + return val; +} + +static void expand_array(ogs_hash_t *ht) +{ + ogs_hash_index_t *hi; + ogs_hash_entry_t **new_array; + unsigned int new_max; + + new_max = ht->max * 2 + 1; + new_array = alloc_array(ht, new_max); + for (hi = ogs_hash_first(ht); hi; hi = ogs_hash_next(hi)) { + unsigned int i = hi->this->hash & new_max; + hi->this->next = new_array[i]; + new_array[i] = hi->this; + } + ogs_free(ht->array); + ht->array = new_array; + ht->max = new_max; +} + +static unsigned int hashfunc_default( + const char *char_key, int *klen, unsigned int hash) +{ + const unsigned char *key = (const unsigned char *)char_key; + const unsigned char *p; + int i; + + /* + * This is the popular `times 33' hash algorithm which is used by + * perl and also appears in Berkeley DB. This is one of the best + * known hash functions for strings because it is both computed + * very fast and distributes very well. + * + * The originator may be Dan Bernstein but the code in Berkeley DB + * cites Chris Torek as the source. The best citation I have found + * is "Chris Torek, Hash function for text in C, Usenet message + * <27038@mimsy.umd.edu> in comp.lang.c , October, 1990." in Rich + * Salz's USENIX 1992 paper about INN which can be found at + * . + * + * The magic of number 33, i.e. why it works better than many other + * constants, prime or not, has never been adequately explained by + * anyone. So I try an explanation: if one experimentally tests all + * multipliers between 1 and 256 (as I did while writing a low-level + * data structure library some time ago) one detects that even + * numbers are not useable at all. The remaining 128 odd numbers + * (except for the number 1) work more or less all equally well. + * They all distribute in an acceptable way and this way fill a hash + * table with an average percent of approx. 86%. + * + * If one compares the chi^2 values of the variants (see + * Bob Jenkins ``Hashing Frequently Asked Questions'' at + * http://burtleburtle.net/bob/hash/hashfaq.html for a description + * of chi^2), the number 33 not even has the best value. But the + * number 33 and a few other equally good numbers like 17, 31, 63, + * 127 and 129 have nevertheless a great advantage to the remaining + * numbers in the large set of possible multipliers: their multiply + * operation can be replaced by a faster operation based on just one + * shift plus either a single addition or subtraction operation. And + * because a hash function has to both distribute good _and_ has to + * be very fast to compute, those few numbers should be preferred. + * + * -- Ralf S. Engelschall + */ + + if (*klen == OGS_HASH_KEY_STRING) { + for (p = key; *p; p++) { + hash = hash * 33 + *p; + } + *klen = p - key; + } + else { + for (p = key, i = *klen; i; i--, p++) { + hash = hash * 33 + *p; + } + } + + return hash; +} + +unsigned int ogs_hashfunc_default(const char *char_key, int *klen) +{ + return hashfunc_default(char_key, klen, 0); +} + +static ogs_hash_entry_t **find_entry(ogs_hash_t *ht, + const void *key, int klen, const void *val) +{ + ogs_hash_entry_t **hep, *he; + unsigned int hash; + + if (ht->hash_func) + hash = ht->hash_func(key, &klen); + else + hash = hashfunc_default(key, &klen, ht->seed); + + /* scan linked list */ + for (hep = &ht->array[hash & ht->max], he = *hep; + he; hep = &he->next, he = *hep) { + if (he->hash == hash + && he->klen == klen + && memcmp(he->key, key, klen) == 0) + break; + } + if (he || !val) + return hep; + + /* add a new entry for non-NULL values */ + if ((he = ht->free) != NULL) + ht->free = he->next; + else + he = ogs_malloc(sizeof(*he)); + he->next = NULL; + he->hash = hash; + he->key = key; + he->klen = klen; + he->val = val; + *hep = he; + ht->count++; + return hep; +} + +void *ogs_hash_get(ogs_hash_t *ht, const void *key, int klen) +{ + ogs_hash_entry_t *he; + he = *find_entry(ht, key, klen, NULL); + if (he) + return (void *)he->val; + else + return NULL; +} + +void ogs_hash_set(ogs_hash_t *ht, const void *key, int klen, const void *val) +{ + ogs_hash_entry_t **hep; + hep = find_entry(ht, key, klen, val); + if (*hep) { + if (!val) { + /* delete entry */ + ogs_hash_entry_t *old = *hep; + *hep = (*hep)->next; + old->next = ht->free; + ht->free = old; + --ht->count; + } else { + /* replace entry */ + (*hep)->val = val; + /* check that the collision rate isn't too high */ + if (ht->count > ht->max) { + expand_array(ht); + } + } + } + /* else key not present and val==NULL */ +} + +void *ogs_hash_get_or_set(ogs_hash_t *ht, + const void *key, int klen, const void *val) +{ + ogs_hash_entry_t **hep; + hep = find_entry(ht, key, klen, val); + if (*hep) { + val = (*hep)->val; + /* check that the collision rate isn't too high */ + if (ht->count > ht->max) { + expand_array(ht); + } + return (void *)val; + } + /* else key not present and val==NULL */ + return NULL; +} + +unsigned int ogs_hash_count(ogs_hash_t *ht) +{ + return ht->count; +} + +void ogs_hash_clear(ogs_hash_t *ht) +{ + ogs_hash_index_t *hi; + for (hi = ogs_hash_first(ht); hi; hi = ogs_hash_next(hi)) + ogs_hash_set(ht, hi->this->key, hi->this->klen, NULL); +} + +/* This is basically the following... + * for every element in hash table { + * comp elemeny.key, element.value + * } + * + * Like with table_do, the comp callback is called for each and every + * element of the hash table. + */ +int ogs_hash_do(ogs_hash_do_callback_fn_t *comp, + void *rec, const ogs_hash_t *ht) +{ + ogs_hash_index_t hix; + ogs_hash_index_t *hi; + int rv, dorv = 1; + + hix.ht = (ogs_hash_t *)ht; + hix.index = 0; + hix.this = NULL; + hix.next = NULL; + + if ((hi = ogs_hash_next(&hix))) { + /* Scan the entire table */ + do { + rv = (*comp)(rec, hi->this->key, hi->this->klen, hi->this->val); + } while (rv && (hi = ogs_hash_next(hi))); + + if (rv == 0) { + dorv = 0; + } + } + return dorv; +} diff --git a/lib/core/ogs-hash.h b/lib/core/ogs-hash.h new file mode 100644 index 000000000..e2e2e32c5 --- /dev/null +++ b/lib/core/ogs-hash.h @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#if !defined(OGS_CORE_INSIDE) && !defined(OGS_CORE_COMPILATION) +#error "This header cannot be included directly." +#endif + +#ifndef OGS_HASH_H +#define OGS_HASH_H + +#ifdef __cplusplus +extern "C" { +#endif + +#define OGS_HASH_KEY_STRING (-1) + +typedef struct ogs_hash_t ogs_hash_t; +typedef struct ogs_hash_index_t ogs_hash_index_t; +typedef unsigned int (*ogs_hashfunc_t)(const char *key, int *klen); +unsigned int ogs_hashfunc_default(const char *key, int *klen); + +ogs_hash_t *ogs_hash_make(void); +ogs_hash_t *ogs_hash_make_custom(ogs_hashfunc_t ogs_hash_func); +void ogs_hash_destroy(ogs_hash_t *ht); + +void ogs_hash_set(ogs_hash_t *ht, const void *key, int klen, const void *val); +void *ogs_hash_get(ogs_hash_t *ht, const void *key, int klen); +void *ogs_hash_get_or_set(ogs_hash_t *ht, + const void *key, int klen, const void *val); + +ogs_hash_index_t *ogs_hash_first(ogs_hash_t *ht); +ogs_hash_index_t *ogs_hash_next(ogs_hash_index_t *hi); +void ogs_hash_this(ogs_hash_index_t *hi, + const void **key, int *klen, void **val); + +const void* ogs_hash_this_key(ogs_hash_index_t *hi); +int ogs_hash_this_key_len(ogs_hash_index_t *hi); +void* ogs_hash_this_val(ogs_hash_index_t *hi); +unsigned int ogs_hash_count(ogs_hash_t *ht); +void ogs_hash_clear(ogs_hash_t *ht); + +typedef int (ogs_hash_do_callback_fn_t)( + void *rec, const void *key, int klen, const void *value); + +int ogs_hash_do(ogs_hash_do_callback_fn_t *comp, + void *rec, const ogs_hash_t *ht); + + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* OGS_HASH_H */ diff --git a/lib/core/ogs-kqueue.c b/lib/core/ogs-kqueue.c new file mode 100644 index 000000000..c9e23b93d --- /dev/null +++ b/lib/core/ogs-kqueue.c @@ -0,0 +1,275 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "core-config-private.h" + +#if HAVE_UNISTD_H +#include +#endif + +#include +#include + +#include "ogs-core.h" +#include "ogs-poll-private.h" + +static void kqueue_init(ogs_pollset_t *pollset); +static void kqueue_cleanup(ogs_pollset_t *pollset); +static int kqueue_add(ogs_poll_t *poll, short when); +static int kqueue_remove(ogs_poll_t *poll); +static int kqueue_process(ogs_pollset_t *pollset, ogs_time_t timeout); + +static void kqueue_notify_init(ogs_pollset_t *pollset); +static int kqueue_notify_pollset(ogs_pollset_t *pollset); + +const ogs_pollset_actions_t ogs_kqueue_actions = { + kqueue_init, + kqueue_cleanup, + + kqueue_add, + kqueue_remove, + kqueue_process, + + kqueue_notify_pollset, +}; + +struct kqueue_context_s { + int kqueue; + + struct kevent *change_list; + struct kevent *event_list; + int nchanges, nevents; +}; + +static void kqueue_init(ogs_pollset_t *pollset) +{ + struct kqueue_context_s *context = NULL; + ogs_assert(pollset); + + context = ogs_calloc(1, sizeof *context); + ogs_assert(context); + pollset->context = context; + + context->change_list = ogs_calloc( + ogs_core()->socket.pool, sizeof(struct kevent)); + context->event_list = ogs_calloc( + ogs_core()->socket.pool, sizeof(struct kevent)); + ogs_assert(context->change_list); + context->nchanges = 0; + context->nevents = ogs_core()->socket.pool; + + context->kqueue = kqueue(); + ogs_assert(context->kqueue != -1); + + kqueue_notify_init(pollset); +} + +static void kqueue_cleanup(ogs_pollset_t *pollset) +{ + struct kqueue_context_s *context = NULL; + + ogs_assert(pollset); + context = pollset->context; + ogs_assert(context); + + ogs_free(context->change_list); + ogs_free(context->event_list); + + close(context->kqueue); + + ogs_free(context); +} + +static int kqueue_set(ogs_poll_t *poll, int filter, int flags) +{ + ogs_pollset_t *pollset = NULL; + struct kqueue_context_s *context = NULL; + struct kevent *kev; + + ogs_assert(poll); + pollset = poll->pollset; + ogs_assert(pollset); + context = pollset->context; + ogs_assert(context); + + ogs_assert(context->nchanges < ogs_core()->socket.pool); + + kev = &context->change_list[context->nchanges]; + memset(kev, 0, sizeof *kev); + kev->ident = poll->fd; + kev->filter = filter; + kev->flags = flags; + kev->udata = poll; + + poll->index = context->nchanges; + context->nchanges++; + + return OGS_OK; +} + +static int kqueue_add(ogs_poll_t *poll, short when) +{ + int filter = 0; + + if (when & OGS_POLLIN) { + filter = EVFILT_READ; + } + if (when & OGS_POLLOUT) { + filter = EVFILT_WRITE; + } + + return kqueue_set(poll, filter, EV_ADD|EV_ENABLE); +} + +static int kqueue_remove(ogs_poll_t *poll) +{ + ogs_pollset_t *pollset = NULL; + struct kqueue_context_s *context = NULL; + struct kevent *kev; + ogs_poll_t *last = NULL; + + ogs_assert(poll); + pollset = poll->pollset; + ogs_assert(pollset); + context = pollset->context; + ogs_assert(context); + + ogs_assert(poll->index < context->nchanges); + + context->nchanges--; + kev = &context->change_list[context->nchanges]; + + ogs_assert(kev); + context->change_list[poll->index] = *kev; + + last = kev->udata; + ogs_assert(last); + + last->index = poll->index; + + return OGS_OK; +} + +static int kqueue_process(ogs_pollset_t *pollset, ogs_time_t timeout) +{ + struct kqueue_context_s *context = NULL; + struct timespec ts, *tp; + int i, n; + + ogs_assert(pollset); + context = pollset->context; + ogs_assert(context); + + if (timeout == OGS_INFINITE_TIME) { + tp = NULL; + } else { + ts.tv_sec = ogs_time_sec(timeout); + ts.tv_nsec = ogs_time_usec(timeout) * 1000; + tp = &ts; + } + + n = kevent(context->kqueue, + context->change_list, context->nchanges, + context->event_list, context->nevents, tp); + if (n < 0) { + ogs_log_message(OGS_LOG_ERROR, ogs_socket_errno, "kqueue failed"); + return OGS_ERROR; + } else if (n == 0) { + return OGS_TIMEUP; + } + + for (i = 0; i < n; i++) { + ogs_poll_t *poll = NULL; + short when = 0; + + if (context->event_list[i].flags & EV_ERROR) { + ogs_warn("kevent() error = 0x%x", context->event_list[i].flags); + } else if (context->event_list[i].filter == EVFILT_READ) { + when |= OGS_POLLIN; + } else if (context->event_list[i].filter == EVFILT_WRITE) { + when |= OGS_POLLOUT; + } else if (context->event_list[i].filter == EVFILT_USER) { + /* Nothing */ + } else { + ogs_warn("kevent() unknown filter = 0x%x\n", + context->event_list[i].filter); + } + + if (!when) + continue; + + poll = (ogs_poll_t *)context->event_list[i].udata; + ogs_assert(poll); + + if (poll->handler) { + poll->handler(when, poll->fd, poll->data); + } + } + + return OGS_OK; +} + +#define NOTIFY_IDENT 42 /* Magic number */ + +static void kqueue_notify_init(ogs_pollset_t *pollset) +{ + int rc; + struct kqueue_context_s *context = NULL; + struct kevent kev; + struct timespec timeout = { 0, 0 }; + ogs_assert(pollset); + + ogs_assert(pollset); + context = pollset->context; + ogs_assert(context); + + memset(&kev, 0, sizeof kev); + kev.ident = NOTIFY_IDENT; + kev.filter = EVFILT_USER; + kev.flags = EV_ADD | EV_CLEAR; + + rc = kevent(context->kqueue, &kev, 1, NULL, 0, &timeout); + ogs_assert(rc != -1); +} + +static int kqueue_notify_pollset(ogs_pollset_t *pollset) +{ + int rc; + struct kqueue_context_s *context = NULL; + struct kevent kev; + struct timespec timeout = { 0, 0 }; + ogs_assert(pollset); + + ogs_assert(pollset); + context = pollset->context; + ogs_assert(context); + + memset(&kev, 0, sizeof kev); + kev.ident = NOTIFY_IDENT; + kev.filter = EVFILT_USER; + kev.fflags = NOTE_TRIGGER; + + rc = kevent(context->kqueue, &kev, 1, NULL, 0, &timeout); + if (rc == -1) { + ogs_warn("kevent() failed"); + return OGS_ERROR; + } + + return OGS_OK; +} diff --git a/lib/core/ogs-list.h b/lib/core/ogs-list.h new file mode 100644 index 000000000..087ad9b87 --- /dev/null +++ b/lib/core/ogs-list.h @@ -0,0 +1,115 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#if !defined(OGS_CORE_INSIDE) && !defined(OGS_CORE_COMPILATION) +#error "This header cannot be included directly." +#endif + +#ifndef OGS_LIST_H +#define OGS_LIST_H + +#ifdef __cplusplus +extern "C" { +#endif + +struct ogs_list_s { + struct ogs_list_s *prev, *next; +}; +typedef struct ogs_list_s ogs_list_t; +typedef struct ogs_list_s ogs_lnode_t;; + +#define OGS_LIST(name) \ + ogs_list_t name = { &(name), &(name) } + +#define ogs_list_init(list) do { \ + (list)->prev = (NULL); \ + (list)->next = (NULL); \ +} while (0) + +static ogs_inline void ogs_list_add(ogs_list_t *list, void *lnode) +{ + ogs_list_t *node = lnode; + ogs_list_t *head = list; + ogs_list_t *tail = list->prev; + + node->prev = tail; + node->next = NULL; + if (tail) + tail->next = node; + else + head->next = node; + head->prev = node; +} + +static ogs_inline void ogs_list_remove(ogs_list_t *list, void *lnode) +{ + ogs_list_t *node = lnode; + ogs_list_t *prev = node->prev; + ogs_list_t *next = node->next;; + + if (prev) + prev->next = next; + else + list->next = next; + + if (next) + next->prev = prev; + else + list->prev = prev; +} + +static ogs_inline void *ogs_list_first(const ogs_list_t *list) +{ + return list->next; +} + +static ogs_inline void *ogs_list_next(void *lnode) +{ + ogs_list_t *node = lnode; + return node->next; +} + +#define ogs_list_for_each(list, node) \ + for (node = ogs_list_first(list); (node); \ + node = ogs_list_next(node)) + +#define ogs_list_for_each_safe(list, n, node) \ + for (node = ogs_list_first(list); \ + (node) && (n = ogs_list_next(node), 1); \ + node = n) + +static ogs_inline bool ogs_list_empty(const ogs_list_t *list) +{ + return list->next == NULL; +} + +static ogs_inline int ogs_list_count(const ogs_list_t *list) +{ + ogs_list_t *node; + int i = 0; + ogs_list_for_each(list, node) + i++; + return i; +} + +#ifdef __cplusplus +} +#endif + +#endif /* OGS_LIST_H */ diff --git a/lib/core/ogs-log.c b/lib/core/ogs-log.c new file mode 100644 index 000000000..ff9d965e9 --- /dev/null +++ b/lib/core/ogs-log.c @@ -0,0 +1,625 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "core-config-private.h" + +#if HAVE_CTYPE_H +#include +#endif + +#if HAVE_STDARG_H +#include +#endif + +#include "ogs-core.h" + +#define TA_NOR "\033[0m" /* all off */ + +#define TA_FGC_BLACK "\033[30m" /* Black */ +#define TA_FGC_RED "\033[31m" /* Red */ +#define TA_FGC_BOLD_RED "\033[1;31m" /* Bold Red */ +#define TA_FGC_GREEN "\033[32m" /* Green */ +#define TA_FGC_BOLD_GREEN "\033[1;32m" /* Bold Green */ +#define TA_FGC_YELLOW "\033[33m" /* Yellow */ +#define TA_FGC_BOLD_YELLOW "\033[1;33m" /* Bold Yellow */ +#define TA_FGC_BOLD_BLUE "\033[1;34m" /* Bold Blue */ +#define TA_FGC_BOLD_MAGENTA "\033[1;35m" /* Bold Magenta */ +#define TA_FGC_BOLD_CYAN "\033[1;36m" /* Bold Cyan */ +#define TA_FGC_WHITE "\033[37m" /* White */ +#define TA_FGC_BOLD_WHITE "\033[1;37m" /* Bold White */ +#define TA_FGC_DEFAULT "\033[39m" /* default */ + +typedef enum { + OGS_LOG_STDERR_TYPE, + OGS_LOG_FILE_TYPE, +} ogs_log_type_e; + +typedef struct ogs_log_s { + ogs_lnode_t node; + + ogs_log_type_e type; + + union { + struct { + FILE *out; + const char *name; + } file; + }; + + struct { + ED7(uint8_t color:1;, + uint8_t timestamp:1;, + uint8_t domain:1;, + uint8_t level:1;, + uint8_t fileline:1;, + uint8_t function:1;, + uint8_t linefeed:1;) + } print; + + void (*writer)(ogs_log_t *log, ogs_log_level_e level, const char *string); + +} ogs_log_t; + +typedef struct ogs_log_domain_s { + ogs_lnode_t node; + + int id; + ogs_log_level_e level; + const char *name; +} ogs_log_domain_t; + +const char *level_strings[] = { + NULL, + "FATAL", "ERROR", "WARNING", "INFO", "DEBUG", "TRACE", +}; + +static OGS_POOL(log_pool, ogs_log_t); +static OGS_LIST(log_list); + +static OGS_POOL(domain_pool, ogs_log_domain_t); +static OGS_LIST(domain_list); + +static ogs_log_t *add_log(ogs_log_type_e type); +static int file_cycle(ogs_log_t *log); + +static char *log_timestamp(char *buf, char *last, + int use_color); +static char *log_domain(char *buf, char *last, + const char *name, int use_color); +static char *log_content(char *buf, char *last, + const char *format, va_list ap); +static char *log_level(char *buf, char *last, + ogs_log_level_e level, int use_color); +static char *log_linefeed(char *buf, char *last); + +static void file_writer( + ogs_log_t *log, ogs_log_level_e level, const char *string); + +void ogs_log_init(void) +{ + ogs_pool_init(&log_pool, ogs_core()->log.pool); + ogs_list_init(&log_list); + + ogs_pool_init(&domain_pool, ogs_core()->log.domain_pool); + ogs_list_init(&domain_list); + + ogs_log_add_domain("core", ogs_core()->log.level); + ogs_log_add_stderr(); +} + +void ogs_log_final(void) +{ + ogs_log_t *log, *saved_log; + ogs_log_domain_t *domain, *saved_domain; + + ogs_list_for_each_safe(&log_list, saved_log, log) + ogs_log_remove(log); + ogs_pool_final(&log_pool); + + ogs_list_for_each_safe(&domain_list, saved_domain, domain) + ogs_log_remove_domain(domain); + ogs_pool_final(&domain_pool); +} + +void ogs_log_cycle(void) +{ + ogs_log_t *log = NULL; + + ogs_list_for_each(&log_list, log) { + switch(log->type) { + case OGS_LOG_FILE_TYPE: + file_cycle(log); + default: + break; + } + } +} + +ogs_log_t *ogs_log_add_stderr(void) +{ + ogs_log_t *log = NULL; + + log = add_log(OGS_LOG_STDERR_TYPE); + ogs_assert(log); + + log->file.out = stderr; + log->writer = file_writer; + +#if !defined(_WIN32) + log->print.color = 1; +#endif + + return log; +} + +ogs_log_t *ogs_log_add_file(const char *name) +{ + FILE *out = NULL; + ogs_log_t *log = NULL; + + out = fopen(name, "a"); + if (!out) + return NULL; + + log = add_log(OGS_LOG_FILE_TYPE); + ogs_assert(log); + + log->file.name = name; + log->file.out = out; + + log->writer = file_writer; + + return log; +} + +void ogs_log_remove(ogs_log_t *log) +{ + ogs_assert(log); + + ogs_list_remove(&log_list, log); + + if (log->type == OGS_LOG_FILE_TYPE) { + ogs_assert(log->file.out); + fclose(log->file.out); + log->file.out = NULL; + } + + ogs_pool_free(&log_pool, log); +} + +ogs_log_domain_t *ogs_log_add_domain(const char *name, ogs_log_level_e level) +{ + ogs_log_domain_t *domain = NULL; + + ogs_assert(name); + + ogs_pool_alloc(&domain_pool, &domain); + ogs_assert(domain); + + domain->name = name; + domain->id = ogs_pool_index(&domain_pool, domain); + domain->level = level; + + ogs_list_add(&domain_list, domain); + + return domain; +} + +ogs_log_domain_t *ogs_log_find_domain(const char *name) +{ + ogs_log_domain_t *domain = NULL; + + ogs_assert(name); + + ogs_list_for_each(&domain_list, domain) + if (!ogs_strcasecmp(domain->name, name)) + return domain; + + return NULL; +} + +void ogs_log_remove_domain(ogs_log_domain_t *domain) +{ + ogs_assert(domain); + + ogs_list_remove(&domain_list, domain); + ogs_pool_free(&domain_pool, domain); +} + +void ogs_log_set_domain_level(int id, ogs_log_level_e level) +{ + ogs_log_domain_t *domain = NULL; + + ogs_assert(id > 0 && id <= ogs_core()->log.domain_pool); + + domain = ogs_pool_find(&domain_pool, id); + ogs_assert(domain); + + domain->level = level; +} + +ogs_log_level_e ogs_log_get_domain_level(int id) +{ + ogs_log_domain_t *domain = NULL; + + ogs_assert(id > 0 && id <= ogs_core()->log.domain_pool); + + domain = ogs_pool_find(&domain_pool, id); + ogs_assert(domain); + + return domain->level; +} + +const char *ogs_log_get_domain_name(int id) +{ + ogs_log_domain_t *domain = NULL; + + ogs_assert(id > 0 && id <= ogs_core()->log.domain_pool); + + domain = ogs_pool_find(&domain_pool, id); + ogs_assert(domain); + + return domain->name; +} + +int ogs_log_get_domain_id(const char *name) +{ + ogs_log_domain_t *domain = NULL; + + ogs_assert(name); + + domain = ogs_log_find_domain(name); + ogs_assert(domain); + + return domain->id; +} + +void ogs_log_install_domain(int *domain_id, + const char *name, ogs_log_level_e level) +{ + ogs_log_domain_t *domain = NULL; + + ogs_assert(domain_id); + ogs_assert(name); + + domain = ogs_log_find_domain(name); + if (domain) { + ogs_warn("`%s` log-domain duplicated", name); + if (level != domain->level) { + ogs_warn("[%s]->[%s] log-level changed", + level_strings[domain->level], level_strings[level]); + ogs_log_set_domain_level(domain->id, level); + } + } else { + domain = ogs_log_add_domain(name, level); + ogs_assert(domain); + } + + *domain_id = domain->id; +} + +void ogs_log_set_mask_level(const char *_mask, ogs_log_level_e level) +{ + ogs_log_domain_t *domain = NULL; + + if (_mask) { + const char *delim = " \t\n,:"; + char *mask = NULL; + char *saveptr; + char *name; + + mask = ogs_strdup(_mask); + ogs_assert(mask); + + for (name = ogs_strtok_r(mask, delim, &saveptr); + name != NULL; + name = ogs_strtok_r(NULL, delim, &saveptr)) { + + domain = ogs_log_find_domain(name); + if (domain) + domain->level = level; + } + + ogs_free(mask); + } else { + ogs_list_for_each(&domain_list, domain) + domain->level = level; + } +} + +static ogs_log_level_e ogs_log_level_from_string(const char *string) +{ + ogs_log_level_e level = OGS_ERROR; + + if (!strcasecmp(string, "none")) level = OGS_LOG_NONE; + else if (!strcasecmp(string, "fatal")) level = OGS_LOG_FATAL; + else if (!strcasecmp(string, "error")) level = OGS_LOG_ERROR; + else if (!strcasecmp(string, "warn")) level = OGS_LOG_WARN; + else if (!strcasecmp(string, "info")) level = OGS_LOG_INFO; + else if (!strcasecmp(string, "debug")) level = OGS_LOG_DEBUG; + else if (!strcasecmp(string, "trace")) level = OGS_LOG_TRACE; + + return level; +} + +int ogs_log_config_domain(const char *domain, const char *level) +{ + if (domain || level) { + int l = ogs_core()->log.level; + + if (level) { + l = ogs_log_level_from_string(level); + if (l == OGS_ERROR) { + ogs_error("Invalid LOG-LEVEL " + "[none:fatal|error|warn|info|debug|trace]: %s\n", + level); + return OGS_ERROR; + } + } + + ogs_log_set_mask_level(domain, l); + } + + return OGS_OK; +} + +void ogs_log_vprintf(ogs_log_level_e level, int id, + ogs_err_t err, const char *file, int line, const char *func, + int content_only, const char *format, va_list ap) +{ + ogs_log_t *log = NULL; + ogs_log_domain_t *domain = NULL; + + char logstr[OGS_HUGE_LEN]; + char *p, *last; + + int wrote_stderr = 0; + + ogs_list_for_each(&log_list, log) { + domain = ogs_pool_find(&domain_pool, id); + ogs_assert(domain); + if (domain->level < level) + return; + + p = logstr; + last = logstr + OGS_HUGE_LEN; + + if (!content_only) { + if (log->print.timestamp) + p = log_timestamp(p, last, log->print.color); + if (log->print.domain) + p = log_domain(p, last, domain->name, log->print.color); + if (log->print.level) + p = log_level(p, last, level, log->print.color); + } + + p = log_content(p, last, format, ap); + + if (err) { + char errbuf[OGS_HUGE_LEN]; + p = ogs_slprintf(p, last, " (%d:%s)", + (int)err, ogs_strerror(err, errbuf, OGS_HUGE_LEN)); + } + + if (!content_only) { + if (log->print.fileline) + p = ogs_slprintf(p, last, " (%s:%d)", file, line); + if (log->print.function) + p = ogs_slprintf(p, last, " %s()", func); + if (log->print.linefeed) + p = log_linefeed(p, last); + } + + log->writer(log, level, logstr); + + if (log->type == OGS_LOG_STDERR_TYPE) + wrote_stderr = 1; + } + + if (!wrote_stderr) + { + int use_color = 0; +#if !defined(_WIN32) + use_color = 1; +#endif + + p = logstr; + last = logstr + OGS_HUGE_LEN; + + if (!content_only) { + p = log_timestamp(p, last, use_color); + p = log_level(p, last, level, use_color); + } + p = log_content(p, last, format, ap); + if (!content_only) { + p = ogs_slprintf(p, last, " (%s:%d)", file, line); + p = ogs_slprintf(p, last, " %s()", func); + p = log_linefeed(p, last); + } + + fprintf(stderr, "%s", logstr); + fflush(stderr); + } +} + +void ogs_log_printf(ogs_log_level_e level, int id, + ogs_err_t err, const char *file, int line, const char *func, + int content_only, const char *format, ...) +{ + va_list args; + + va_start(args, format); + ogs_log_vprintf(level, id, + err, file, line, func, content_only, format, args); + va_end(args); +} + +void ogs_log_hexdump_func(ogs_log_level_e level, int id, + const unsigned char *data, size_t len) +{ + size_t n, m; + char dumpstr[OGS_HUGE_LEN]; + char *p, *last; + + last = dumpstr + OGS_HUGE_LEN; + p = dumpstr; + + for (n = 0; n < len; n += 16) { + p = ogs_slprintf(p, last, "%04x: ", (int)n); + + for (m = n; m < n + 16; m++) { + if (m > n && (m % 4) == 0) + p = ogs_slprintf(p, last, " "); + if (m < len) + p = ogs_slprintf(p, last, "%02x", data[m]); + else + p = ogs_slprintf(p, last, " "); + } + + p = ogs_slprintf(p, last, " "); + + for (m = n; m < len && m < n + 16; m++) + p = ogs_slprintf(p, last, "%c", isprint(data[m]) ? data[m] : '.'); + + p = ogs_slprintf(p, last, "\n"); + } + + ogs_log_print(level, "%s", dumpstr); +} + +static ogs_log_t *add_log(ogs_log_type_e type) +{ + ogs_log_t *log = NULL; + + ogs_pool_alloc(&log_pool, &log); + ogs_assert(log); + memset(log, 0, sizeof *log); + + log->type = type; + + log->print.timestamp = 1; + log->print.domain = 1; + log->print.level = 1; + log->print.fileline = 1; + log->print.linefeed = 1; + + ogs_list_add(&log_list, log); + + return log; +} + +static int file_cycle(ogs_log_t *log) +{ + ogs_assert(log); + ogs_assert(log->file.out); + ogs_assert(log->file.name); + + fclose(log->file.out); + log->file.out = fopen(log->file.name, "a"); + ogs_assert(log->file.out); + + return 0; +} + +static char *log_timestamp(char *buf, char *last, + int use_color) +{ + struct timeval tv; + struct tm tm; + char nowstr[32]; + + ogs_gettimeofday(&tv); + ogs_localtime(tv.tv_sec, &tm); + strftime(nowstr, sizeof nowstr, "%m/%d %H:%M:%S", &tm); + + buf = ogs_slprintf(buf, last, "%s%s.%03d%s: ", + use_color ? TA_FGC_GREEN : "", + nowstr, (int)(tv.tv_usec/1000), + use_color ? TA_NOR : ""); + + return buf; +} + +static char *log_domain(char *buf, char *last, + const char *name, int use_color) +{ + buf = ogs_slprintf(buf, last, "[%s%s%s] ", + use_color ? TA_FGC_YELLOW : "", + name, + use_color ? TA_NOR : ""); + + return buf; +} + +static char *log_level(char *buf, char *last, + ogs_log_level_e level, int use_color) +{ + const char *colors[] = { + TA_NOR, + TA_FGC_BOLD_RED, TA_FGC_BOLD_YELLOW, TA_FGC_BOLD_CYAN, + TA_FGC_BOLD_GREEN, TA_FGC_BOLD_WHITE, TA_FGC_WHITE, + }; + + buf = ogs_slprintf(buf, last, "%s%s%s: ", + use_color ? colors[level] : "", + level_strings[level], + use_color ? TA_NOR : ""); + + return buf; +} + +static char *log_content(char *buf, char *last, + const char *format, va_list ap) +{ + va_list bp; + + va_copy(bp, ap); +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wformat-nonliteral" + buf = ogs_vslprintf(buf, last, format, bp); +#pragma GCC diagnostic pop + va_end(bp); + + return buf; +} + +static char *log_linefeed(char *buf, char *last) +{ +#if defined(_WIN32) + if (buf > last - 3) + buf = last - 3; + + buf = ogs_slprintf(buf, last, "\r\n"); +#else + if (buf > last - 2) + buf = last - 2; + + buf = ogs_slprintf(buf, last, "\n"); +#endif + + return buf; +} + +static void file_writer( + ogs_log_t *log, ogs_log_level_e level, const char *string) +{ + fprintf(log->file.out, "%s", string); + fflush(log->file.out); +} + diff --git a/lib/core/ogs-log.h b/lib/core/ogs-log.h new file mode 100644 index 000000000..40133341b --- /dev/null +++ b/lib/core/ogs-log.h @@ -0,0 +1,141 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#if !defined(OGS_CORE_INSIDE) && !defined(OGS_CORE_COMPILATION) +#error "This header cannot be included directly." +#endif + +#ifndef OGS_LOG_H +#define OGS_LOG_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef OGS_LOG_DOMAIN +#define OGS_LOG_DOMAIN 1 +#endif + +#define ogs_fatal(...) ogs_log_message(OGS_LOG_FATAL, 0, __VA_ARGS__) +#define ogs_error(...) ogs_log_message(OGS_LOG_ERROR, 0, __VA_ARGS__) +#define ogs_warn(...) ogs_log_message(OGS_LOG_WARN, 0, __VA_ARGS__) +#define ogs_info(...) ogs_log_message(OGS_LOG_INFO, 0, __VA_ARGS__) +#define ogs_debug(...) ogs_log_message(OGS_LOG_DEBUG, 0, __VA_ARGS__) +#define ogs_trace(...) ogs_log_message(OGS_LOG_TRACE, 0, __VA_ARGS__) + +#define ogs_log_message(level, err, ...) \ + ogs_log_printf(level, OGS_LOG_DOMAIN, \ + err, __FILE__, __LINE__, OGS_FUNC, \ + 0, __VA_ARGS__) + +#define ogs_log_print(level, ...) \ + ogs_log_printf(level, OGS_LOG_DOMAIN, \ + 0, NULL, 0, NULL, \ + 1, __VA_ARGS__) + +#define ogs_log_hexdump(level, _d, _l) \ + ogs_log_hexdump_func(level, OGS_LOG_DOMAIN, _d, _l) + +typedef enum { + OGS_LOG_NONE, + OGS_LOG_FATAL, + OGS_LOG_ERROR, + OGS_LOG_WARN, + OGS_LOG_INFO, + OGS_LOG_DEBUG, + OGS_LOG_TRACE, + OGS_LOG_DEFAULT = OGS_LOG_INFO, + OGS_LOG_FULL = OGS_LOG_TRACE, +} ogs_log_level_e; + +typedef struct ogs_log_s ogs_log_t; +typedef struct ogs_log_domain_s ogs_log_domain_t; + +void ogs_log_init(void); +void ogs_log_final(void); +void ogs_log_cycle(void); + +ogs_log_t *ogs_log_add_stderr(void); +ogs_log_t *ogs_log_add_file(const char *name); +void ogs_log_remove(ogs_log_t *log); + +ogs_log_domain_t *ogs_log_add_domain(const char *name, ogs_log_level_e level); +ogs_log_domain_t *ogs_log_find_domain(const char *name); +void ogs_log_remove_domain(ogs_log_domain_t *domain); + +void ogs_log_set_domain_level(int id, ogs_log_level_e level); +ogs_log_level_e ogs_log_get_domain_level(int id); + +const char *ogs_log_get_domain_name(int id); +int ogs_log_get_domain_id(const char *name); + +void ogs_log_install_domain(int *domain_id, + const char *name, ogs_log_level_e level); +int ogs_log_config_domain(const char *domain, const char *level); + +void ogs_log_set_mask_level(const char *mask, ogs_log_level_e level); + +void ogs_log_vprintf(ogs_log_level_e level, int id, + ogs_err_t err, const char *file, int line, const char *func, + int content_only, const char *format, va_list ap); +void ogs_log_printf(ogs_log_level_e level, int domain_id, + ogs_err_t err, const char *file, int line, const char *func, + int content_only, const char *format, ...) + OGS_GNUC_PRINTF(8, 9); + +void ogs_log_hexdump_func(ogs_log_level_e level, int domain_id, + const unsigned char *data, size_t len); + +#define ogs_assert(expr) \ + do { \ + if (ogs_likely(expr)) ; \ + else { \ + ogs_fatal("%s: Assertion `%s' failed.", OGS_FUNC, #expr); \ + ogs_abort(); \ + } \ + } while(0) + +#define ogs_assert_if_reached() \ + do { \ + ogs_warn("%s: should not be reached.", OGS_FUNC); \ + ogs_abort(); \ + } while(0) + +#define ogs_expect(expr) \ + do { \ + if (ogs_likely(expr)) ; \ + else { \ + ogs_error("%s: Expectation `%s' failed.", OGS_FUNC, #expr); \ + } \ + } while (0) + +#define ogs_expect_or_return(expr) \ + do { \ + if (ogs_likely(expr)) ; \ + else { \ + ogs_error("%s: Expectation `%s' failed.", OGS_FUNC, #expr); \ + return; \ + } \ + } while (0) + +#ifdef __cplusplus +} +#endif + +#endif /* OGS_LOG_H */ diff --git a/lib/core/ogs-macros.h b/lib/core/ogs-macros.h new file mode 100644 index 000000000..0c6d22370 --- /dev/null +++ b/lib/core/ogs-macros.h @@ -0,0 +1,168 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#if !defined(OGS_CORE_INSIDE) && !defined(OGS_CORE_COMPILATION) +#error "This header cannot be included directly." +#endif + +#ifndef OGS_MACROS_H +#define OGS_MACROS_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __GNUC__ +#define OGS_GNUC_CHECK_VERSION(major, minor) \ + ((__GNUC__ > (major)) || \ + ((__GNUC__ == (major)) && (__GNUC_MINOR__ >= (minor)))) +#else +#define OGS_GNUC_CHECK_VERSION(major, minor) 0 +#endif + +#if defined(_MSC_VER) +#define ogs_inline __inline +#else +#define ogs_inline __inline__ +#endif + +#if defined(_WIN32) +#define OGS_FUNC __FUNCTION__ +#elif defined(__STDC_VERSION__) && __STDC_VERSION__ < 199901L +#define OGS_FUNC __FUNCTION__ +#else +#define OGS_FUNC __func__ +#endif + +#if defined(__GNUC__) +#define ogs_likely(x) __builtin_expect (!!(x), 1) +#define ogs_unlikely(x) __builtin_expect (!!(x), 0) +#else +#define ogs_likely(v) v +#define ogs_unlikely(v) v +#endif + +#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4) +#if !defined (__clang__) && OGS_GNUC_CHECK_VERSION (4, 4) +#define OGS_GNUC_PRINTF(f, v) __attribute__ ((format (gnu_printf, f, v))) +#else +#define OGS_GNUC_PRINTF(f, v) __attribute__ ((format (__printf__, f, v))) +#endif +#define OGS_GNUC_NORETURN __attribute__((__noreturn__)) +#else +#define OGS_GNUC_PRINTF(f, v) +#define OGS_GNUC_NORETURN +#endif + +#if defined(_WIN32) +#define htole16(x) (x) +#define htole32(x) (x) +#define htole64(x) (x) +#define le16toh(x) (x) +#define le32toh(x) (x) +#define le64toh(x) (x) + +#define htobe16(x) htons((x)) +#define htobe32(x) htonl((x)) +#define htobe64(x) htonll((x)) +#define be16toh(x) ntohs((x)) +#define be32toh(x) ntohl((x)) +#define be64toh(x) ntohll((x)) + +#elif defined(__APPLE__) +#include +#define htole16(x) OSSwapHostToLittleInt16((x)) +#define htole32(x) OSSwapHostToLittleInt32((x)) +#define htole64(x) OSSwapHostToLittleInt64((x)) +#define le16toh(x) OSSwapLittleToHostInt16((x)) +#define le32toh(x) OSSwapLittleToHostInt32((x)) +#define le64toh(x) OSSwapLittleToHostInt64((x)) + +#define htobe16(x) OSSwapHostToBigInt16((x)) +#define htobe32(x) OSSwapHostToBigInt32((x)) +#define htobe64(x) OSSwapHostToBigInt64((x)) +#define be16toh(x) OSSwapBigToHostInt16((x)) +#define be32toh(x) OSSwapBigToHostInt32((x)) +#define be64toh(x) OSSwapBigToHostInt64((x)) + +#elif defined(__FreeBSD__) +#define le16toh(x) letoh16(x) +#define le32toh(x) letoh32(x) +#define le64toh(x) letoh64(x) + +#define be16toh(x) betoh16(x) +#define be32toh(x) betoh32(x) +#define be64toh(x) betoh64(x) + +#endif + +#ifndef WORDS_BIGENDIAN +#if OGS_BYTE_ORDER == OGS_BIG_ENDIAN +#define WORDS_BIGENDIAN 1 +#endif +#endif + +#if OGS_BYTE_ORDER == OGS_BIG_ENDIAN +#define ED2(x1, x2) x1 x2 +#define ED3(x1, x2, x3) x1 x2 x3 +#define ED4(x1, x2, x3, x4) x1 x2 x3 x4 +#define ED5(x1, x2, x3, x4, x5) x1 x2 x3 x4 x5 +#define ED6(x1, x2, x3, x4, x5, x6) x1 x2 x3 x4 x5 x6 +#define ED7(x1, x2, x3, x4, x5, x6, x7) x1 x2 x3 x4 x5 x6 x7 +#define ED8(x1, x2, x3, x4, x5, x6, x7, x8) x1 x2 x3 x4 x5 x6 x7 x8 +#else +#define ED2(x1, x2) x2 x1 +#define ED3(x1, x2, x3) x3 x2 x1 +#define ED4(x1, x2, x3, x4) x4 x3 x2 x1 +#define ED5(x1, x2, x3, x4, x5) x5 x4 x3 x2 x1 +#define ED6(x1, x2, x3, x4, x5, x6) x6 x5 x4 x3 x2 x1 +#define ED7(x1, x2, x3, x4, x5, x6, x7) x7 x6 x5 x4 x3 x2 x1 +#define ED8(x1, x2, x3, x4, x5, x6, x7, x8) x8 x7 x6 x5 x4 x3 x2 x1 +#endif + +#define OGS_STATIC_ASSERT(expr) \ + typedef char dummy_for_ogs_static_assert##__LINE__[(expr) ? 1 : -1] + +#define OGS_ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) + +#define OGS_STRINGIFY(n) OGS_STRINGIFY_HELPER(n) +#define OGS_STRINGIFY_HELPER(n) #n + +#define OGS_PASTE(n1, n2) OGS_PASTE_HELPER(n1, n2) +#define OGS_PASTE_HELPER(n1, n2) n1##n2 + +#define INET_NTOP(src, dst) \ + inet_ntop(AF_INET, (void *)(uintptr_t)(src), (dst), INET_ADDRSTRLEN) +#define INET6_NTOP(src, dst) \ + inet_ntop(AF_INET6, (void *)(src), (dst), INET6_ADDRSTRLEN) + +#define ogs_max(x , y) (((x) > (y)) ? (x) : (y)) +#define ogs_min(x , y) (((x) < (y)) ? (x) : (y)) + +#if defined(_WIN32) +#define OGS_IS_DIR_SEPARATOR(c) ((c) == OGS_DIR_SEPARATOR || (c) == '/') +#else +#define OGS_IS_DIR_SEPARATOR(c) ((c) == OGS_DIR_SEPARATOR) +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* OGS_MACROS_H */ diff --git a/lib/core/ogs-memory.c b/lib/core/ogs-memory.c new file mode 100644 index 000000000..7fbbe527f --- /dev/null +++ b/lib/core/ogs-memory.c @@ -0,0 +1,102 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "ogs-core.h" + +#undef OGS_LOG_DOMAIN +#define OGS_LOG_DOMAIN __ogs_mem_domain + +void *ogs_malloc(size_t size) +{ + size_t headroom = 0; + ogs_pkbuf_t *pkbuf = NULL; + + ogs_assert(size); + + headroom = sizeof(ogs_pkbuf_t *); + pkbuf = ogs_pkbuf_alloc(NULL, headroom + size); + ogs_pkbuf_reserve(pkbuf, headroom); + memcpy(pkbuf->head, &pkbuf, headroom); + ogs_pkbuf_put(pkbuf, size); + + return pkbuf->data; +} + +void ogs_free(void *ptr) +{ + size_t headroom; + ogs_pkbuf_t *pkbuf = NULL; + + if (!ptr) + return; + + headroom = sizeof(ogs_pkbuf_t *); + memcpy(&pkbuf, (unsigned char*)ptr - headroom, headroom); + ogs_assert(pkbuf); + + ogs_pkbuf_free(pkbuf); +} + +void *ogs_calloc(size_t nmemb, size_t size) +{ + void *ptr = NULL; + + ptr = ogs_malloc(nmemb * size); + ogs_assert(ptr); + + memset(ptr, 0, nmemb * size); + return ptr; +} + +void *ogs_realloc(void *ptr, size_t size) +{ + size_t headroom = 0; + ogs_pkbuf_t *pkbuf = NULL; + ogs_cluster_t *cluster = NULL; + + if (!ptr) + return ogs_malloc(size); + + headroom = sizeof(ogs_pkbuf_t *); + + memcpy(&pkbuf, (unsigned char*)ptr - headroom, headroom); + ogs_assert(pkbuf); + cluster = pkbuf->cluster; + ogs_assert(cluster); + + if (!size) { + ogs_pkbuf_free(pkbuf); + return NULL; + } + + if (size > (cluster->size - headroom)) { + void *new = NULL; + + new = ogs_malloc(size); + ogs_assert(new); + memcpy(new, ptr, pkbuf->len); + + ogs_pkbuf_free(pkbuf); + return new; + } else { + pkbuf->tail = pkbuf->data + size; + pkbuf->len = size; + return ptr; + } +} diff --git a/lib/core/ogs-memory.h b/lib/core/ogs-memory.h new file mode 100644 index 000000000..0f72082c4 --- /dev/null +++ b/lib/core/ogs-memory.h @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#if !defined(OGS_CORE_INSIDE) && !defined(OGS_CORE_COMPILATION) +#error "This header cannot be included directly." +#endif + +#ifndef OGS_MEMORY_H +#define OGS_MEMORY_H + +#ifdef __cplusplus +extern "C" { +#endif + +void *ogs_malloc(size_t size); +void ogs_free(void *ptr); +void *ogs_calloc(size_t nmemb, size_t size); +void *ogs_realloc(void *ptr, size_t size); + +#ifdef __cplusplus +} +#endif + +#endif /* OGS_MEMORY_H */ diff --git a/lib/core/ogs-misc.c b/lib/core/ogs-misc.c new file mode 100644 index 000000000..8ef79ade3 --- /dev/null +++ b/lib/core/ogs-misc.c @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "ogs-core.h" + +#define PATH_SEPARATOR '/' + +/* Remove trailing separators that don't affect the meaning of PATH. */ +static void path_canonicalize(char *dir) +{ + /* At some point this could eliminate redundant components. For + * now, it just makes sure there is no trailing slash. */ + size_t len = strlen (dir); + size_t orig_len = len; + + ogs_assert(dir); + + while ((len > 0) && (dir[len - 1] == PATH_SEPARATOR)) + len--; + + if (len != orig_len) + dir[len] = 0; +} + +/* Remove one component off the end of PATH. */ +void ogs_path_remove_last_component(char *dir, const char *path) +{ + int i; + int len = 0; + + ogs_assert(dir); + ogs_assert(path); + + strcpy(dir, path); + path_canonicalize (dir); + for (i = (strlen(dir) - 1); i >= 0; i--) { + if (path[i] == PATH_SEPARATOR) + break; + } + + len = (i < 0) ? 0 : i; + dir[len] = 0; +} + +bool ogs_path_is_absolute(const char *filename) +{ + ogs_assert(filename); + + if (OGS_IS_DIR_SEPARATOR(filename[0])) + return true; + +#if defined(_WIN32) + if (isalpha(filename[0]) && + filename[1] == ':' && OGS_IS_DIR_SEPARATOR(filename[2])) + return true; +#endif + + return false; +} diff --git a/lib/core/ogs-misc.h b/lib/core/ogs-misc.h new file mode 100644 index 000000000..5d6f8c876 --- /dev/null +++ b/lib/core/ogs-misc.h @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#if !defined(OGS_CORE_INSIDE) && !defined(OGS_CORE_COMPILATION) +#error "This header cannot be included directly." +#endif + +#ifndef OGS_MISC_H +#define OGS_MISC_H + +#ifdef __cplusplus +extern "C" { +#endif + +void ogs_path_remove_last_component(char *dir, const char *path); +bool ogs_path_is_absolute(const char *filename); + +#ifdef __cplusplus +} +#endif + +#endif /* OGS_MISC_H */ diff --git a/lib/core/ogs-notify.c b/lib/core/ogs-notify.c new file mode 100644 index 000000000..bdf337409 --- /dev/null +++ b/lib/core/ogs-notify.c @@ -0,0 +1,112 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "core-config-private.h" + +#if HAVE_UNISTD_H +#include +#endif + +#if HAVE_EVENTFD +#include +#endif + +#include "ogs-core.h" +#include "ogs-poll-private.h" + +static void ogs_drain_pollset(short when, ogs_socket_t fd, void *data); + +void ogs_notify_init(ogs_pollset_t *pollset) +{ +#if !defined(HAVE_EVENTFD) + int rc; +#endif + ogs_assert(pollset); + +#if defined(HAVE_EVENTFD) + pollset->notify.fd[0] = eventfd(0, 0); + ogs_assert(pollset->notify.fd[0] != INVALID_SOCKET); +#else + rc = ogs_socketpair(AF_SOCKPAIR, SOCK_STREAM, 0, pollset->notify.fd); + ogs_assert(rc == OGS_OK); +#endif + + pollset->notify.poll = ogs_pollset_add(pollset, OGS_POLLIN, + pollset->notify.fd[0], ogs_drain_pollset, NULL); + ogs_assert(pollset->notify.poll); +} + +void ogs_notify_final(ogs_pollset_t *pollset) +{ + ogs_assert(pollset); + + ogs_pollset_remove(pollset->notify.poll); + + ogs_closesocket(pollset->notify.fd[0]); +#if !defined(HAVE_EVENTFD) + ogs_closesocket(pollset->notify.fd[1]); +#endif +} + +int ogs_notify_pollset(ogs_pollset_t *pollset) +{ + ssize_t r; +#if defined(HAVE_EVENTFD) + uint64_t msg = 1; +#else + char buf[1]; + buf[0] = 0; +#endif + + ogs_assert(pollset); + +#if defined(HAVE_EVENTFD) + r = write(pollset->notify.fd[0], (void*)&msg, sizeof(msg)); +#else + r = send(pollset->notify.fd[1], buf, 1, 0); +#endif + + if (r < 0) { + ogs_log_message(OGS_LOG_ERROR, ogs_socket_errno, "notify failed"); + return OGS_ERROR; + } + + return OGS_OK; +} + +static void ogs_drain_pollset(short when, ogs_socket_t fd, void *data) +{ + ssize_t r; +#if defined(HAVE_EVENTFD) + uint64_t msg; +#else + unsigned char buf[1024]; +#endif + + ogs_assert(when == OGS_POLLIN); + +#if defined(HAVE_EVENTFD) + r = read(fd, (char *)&msg, sizeof(msg)); +#else + r = recv(fd, (char *)buf, sizeof(buf), 0); +#endif + if (r < 0) { + ogs_log_message(OGS_LOG_ERROR, ogs_socket_errno, "drain failed"); + } +} diff --git a/lib/core/ogs-notify.h b/lib/core/ogs-notify.h new file mode 100644 index 000000000..2fe3427de --- /dev/null +++ b/lib/core/ogs-notify.h @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#if !defined(OGS_CORE_INSIDE) && !defined(OGS_CORE_COMPILATION) +#error "This header cannot be included directly." +#endif + +#ifndef OGS_NOTIFY_H +#define OGS_NOTIFY_H + +#ifdef __cplusplus +extern "C" { +#endif + +void ogs_notify_init(ogs_pollset_t *pollset); +void ogs_notify_final(ogs_pollset_t *pollset); +int ogs_notify_pollset(ogs_pollset_t *pollset); + +#ifdef __cplusplus +} +#endif + +#endif /* OGS_NOTIFY_H */ diff --git a/lib/core/ogs-pkbuf.c b/lib/core/ogs-pkbuf.c new file mode 100644 index 000000000..3cacf479d --- /dev/null +++ b/lib/core/ogs-pkbuf.c @@ -0,0 +1,329 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "ogs-core.h" + +#undef OGS_LOG_DOMAIN +#define OGS_LOG_DOMAIN __ogs_mem_domain + +#define OGS_CLUSTER_128_SIZE 128 +#define OGS_CLUSTER_256_SIZE 256 +#define OGS_CLUSTER_512_SIZE 512 +#define OGS_CLUSTER_1024_SIZE 1024 +#define OGS_CLUSTER_2048_SIZE 2048 +#define OGS_CLUSTER_8192_SIZE 8192 +#define OGS_CLUSTER_BIG_SIZE 1024*1024 + +typedef uint8_t ogs_cluster_128_t[OGS_CLUSTER_128_SIZE]; +typedef uint8_t ogs_cluster_256_t[OGS_CLUSTER_256_SIZE]; +typedef uint8_t ogs_cluster_512_t[OGS_CLUSTER_512_SIZE]; +typedef uint8_t ogs_cluster_1024_t[OGS_CLUSTER_1024_SIZE]; +typedef uint8_t ogs_cluster_2048_t[OGS_CLUSTER_2048_SIZE]; +typedef uint8_t ogs_cluster_8192_t[OGS_CLUSTER_8192_SIZE]; +typedef uint8_t ogs_cluster_big_t[OGS_CLUSTER_BIG_SIZE]; + +OGS_STATIC_ASSERT(sizeof(ogs_cluster_128_t) % sizeof(void *) == 0); +OGS_STATIC_ASSERT(sizeof(ogs_cluster_256_t) % sizeof(void *) == 0); +OGS_STATIC_ASSERT(sizeof(ogs_cluster_512_t) % sizeof(void *) == 0); +OGS_STATIC_ASSERT(sizeof(ogs_cluster_1024_t) % sizeof(void *) == 0); +OGS_STATIC_ASSERT(sizeof(ogs_cluster_2048_t) % sizeof(void *) == 0); +OGS_STATIC_ASSERT(sizeof(ogs_cluster_8192_t) % sizeof(void *) == 0); +OGS_STATIC_ASSERT(sizeof(ogs_cluster_big_t) % sizeof(void *) == 0); + +typedef struct ogs_pkbuf_pool_s { + OGS_POOL(pkbuf, ogs_pkbuf_t); + OGS_POOL(cluster, ogs_cluster_t); + + OGS_POOL(cluster_128, ogs_cluster_128_t); + OGS_POOL(cluster_256, ogs_cluster_256_t); + OGS_POOL(cluster_512, ogs_cluster_512_t); + OGS_POOL(cluster_1024, ogs_cluster_1024_t); + OGS_POOL(cluster_2048, ogs_cluster_2048_t); + OGS_POOL(cluster_8192, ogs_cluster_8192_t); + OGS_POOL(cluster_big, ogs_cluster_big_t); + + ogs_thread_mutex_t mutex; +} ogs_pkbuf_pool_t; + +static OGS_POOL(pkbuf_pool, ogs_pkbuf_pool_t); +static ogs_pkbuf_pool_t *default_pool = NULL; + +static ogs_cluster_t *cluster_alloc( + ogs_pkbuf_pool_t *pool, unsigned int size); +static void cluster_free(ogs_pkbuf_pool_t *pool, ogs_cluster_t *cluster); + +void *ogs_pkbuf_put_data( + ogs_pkbuf_t *pkbuf, const void *data, unsigned int len) +{ + void *tmp = ogs_pkbuf_put(pkbuf, len); + + memcpy(tmp, data, len); + return tmp; +} + +void ogs_pkbuf_init(void) +{ + ogs_pool_init(&pkbuf_pool, ogs_core()->pkbuf.pool); +} + +void ogs_pkbuf_final(void) +{ + ogs_pool_final(&pkbuf_pool); +} + +void ogs_pkbuf_default_init(ogs_pkbuf_config_t *config) +{ + ogs_assert(config); + memset(config, 0, sizeof *config); + + config->cluster_128_pool = 8192; + config->cluster_256_pool = 4096; + config->cluster_512_pool = 2048; + config->cluster_1024_pool = 1024; + config->cluster_2048_pool = 512; + config->cluster_8192_pool = 128; + config->cluster_big_pool = 8; +} + +void ogs_pkbuf_default_create(ogs_pkbuf_config_t *config) +{ + default_pool = ogs_pkbuf_pool_create(config); +} + +void ogs_pkbuf_default_destroy(void) +{ + ogs_pkbuf_pool_destroy(default_pool); +} + +ogs_pkbuf_pool_t *ogs_pkbuf_pool_create(ogs_pkbuf_config_t *config) +{ + ogs_pkbuf_pool_t *pool = NULL; + int tmp = 0; + + ogs_assert(config); + + ogs_pool_alloc(&pkbuf_pool, &pool); + ogs_assert(pool); + memset(pool, 0, sizeof *pool); + + ogs_thread_mutex_init(&pool->mutex); + + tmp = config->cluster_128_pool + config->cluster_256_pool + + config->cluster_512_pool + config->cluster_1024_pool + + config->cluster_2048_pool + config->cluster_8192_pool + + config->cluster_big_pool; + + ogs_pool_init(&pool->pkbuf, tmp); + ogs_pool_init(&pool->cluster, tmp); + + ogs_pool_init(&pool->cluster_128, config->cluster_128_pool); + ogs_pool_init(&pool->cluster_256, config->cluster_256_pool); + ogs_pool_init(&pool->cluster_512, config->cluster_512_pool); + ogs_pool_init(&pool->cluster_1024, config->cluster_1024_pool); + ogs_pool_init(&pool->cluster_2048, config->cluster_2048_pool); + ogs_pool_init(&pool->cluster_8192, config->cluster_8192_pool); + ogs_pool_init(&pool->cluster_big, config->cluster_big_pool); + + return pool; +} + +void ogs_pkbuf_pool_destroy(ogs_pkbuf_pool_t *pool) +{ + ogs_assert(pool); + + ogs_pool_final(&pool->pkbuf); + ogs_pool_final(&pool->cluster); + + ogs_pool_final(&pool->cluster_128); + ogs_pool_final(&pool->cluster_256); + ogs_pool_final(&pool->cluster_512); + ogs_pool_final(&pool->cluster_1024); + ogs_pool_final(&pool->cluster_2048); + ogs_pool_final(&pool->cluster_8192); + ogs_pool_final(&pool->cluster_big); + + ogs_thread_mutex_destroy(&pool->mutex); + + ogs_pool_free(&pkbuf_pool, pool); +} + +ogs_pkbuf_t *ogs_pkbuf_alloc(ogs_pkbuf_pool_t *pool, unsigned int size) +{ + ogs_pkbuf_t *pkbuf = NULL; + ogs_cluster_t *cluster = NULL; + + if (pool == NULL) + pool = default_pool; + ogs_assert(pool); + + ogs_thread_mutex_lock(&pool->mutex); + + cluster = cluster_alloc(pool, size); + ogs_assert(cluster); + + ogs_pool_alloc(&pool->pkbuf, &pkbuf); + ogs_assert(pkbuf); + memset(pkbuf, 0, sizeof(*pkbuf)); + + cluster->ref++; + + ogs_thread_mutex_unlock(&pool->mutex); + + pkbuf->cluster = cluster; + + pkbuf->len = 0; + + pkbuf->data = cluster->buffer; + pkbuf->head = cluster->buffer; + pkbuf->tail = cluster->buffer; + pkbuf->end = cluster->buffer + size; + + pkbuf->pool = pool; + + return pkbuf; +} + +void ogs_pkbuf_free(ogs_pkbuf_t *pkbuf) +{ + ogs_pkbuf_pool_t *pool = NULL; + ogs_cluster_t *cluster = NULL; + ogs_assert(pkbuf); + + pool = pkbuf->pool; + ogs_assert(pool); + + cluster = pkbuf->cluster; + ogs_assert(cluster); + + ogs_thread_mutex_lock(&pool->mutex); + + cluster->ref--; + if (cluster->ref == 0) + cluster_free(pool, pkbuf->cluster); + + ogs_pool_free(&pool->pkbuf, pkbuf); + + ogs_thread_mutex_unlock(&pool->mutex); +} + +ogs_pkbuf_t *ogs_pkbuf_copy(ogs_pkbuf_t *pkbuf) +{ + ogs_pkbuf_pool_t *pool = NULL; + ogs_pkbuf_t *newbuf = NULL; + + ogs_assert(pkbuf); + pool = pkbuf->pool; + ogs_assert(pool); + + ogs_thread_mutex_lock(&pool->mutex); + + ogs_pool_alloc(&pool->pkbuf, &newbuf); + ogs_assert(newbuf); + memcpy(newbuf, pkbuf, sizeof *pkbuf); + + newbuf->cluster->ref++; + + ogs_thread_mutex_unlock(&pool->mutex); + + return newbuf; +} + +static ogs_cluster_t *cluster_alloc( + ogs_pkbuf_pool_t *pool, unsigned int size) +{ + ogs_cluster_t *cluster = NULL; + void *buffer = NULL; + ogs_assert(pool); + + ogs_pool_alloc(&pool->cluster, &cluster); + ogs_assert(cluster); + memset(cluster, 0, sizeof(*cluster)); + + if (size <= OGS_CLUSTER_128_SIZE) { + ogs_pool_alloc(&pool->cluster_128, (ogs_cluster_128_t**)&buffer); + ogs_assert(buffer); + cluster->size = OGS_CLUSTER_128_SIZE; + } else if (size <= OGS_CLUSTER_256_SIZE) { + ogs_pool_alloc(&pool->cluster_256, (ogs_cluster_256_t**)&buffer); + ogs_assert(buffer); + cluster->size = OGS_CLUSTER_256_SIZE; + } else if (size <= OGS_CLUSTER_512_SIZE) { + ogs_pool_alloc(&pool->cluster_512, (ogs_cluster_512_t**)&buffer); + ogs_assert(buffer); + cluster->size = OGS_CLUSTER_512_SIZE; + } else if (size <= OGS_CLUSTER_1024_SIZE) { + ogs_pool_alloc(&pool->cluster_1024, (ogs_cluster_1024_t**)&buffer); + ogs_assert(buffer); + cluster->size = OGS_CLUSTER_1024_SIZE; + } else if (size <= OGS_CLUSTER_2048_SIZE) { + ogs_pool_alloc(&pool->cluster_2048, (ogs_cluster_2048_t**)&buffer); + ogs_assert(buffer); + cluster->size = OGS_CLUSTER_2048_SIZE; + } else if (size <= OGS_CLUSTER_8192_SIZE) { + ogs_pool_alloc(&pool->cluster_8192, (ogs_cluster_8192_t**)&buffer); + ogs_assert(buffer); + cluster->size = OGS_CLUSTER_8192_SIZE; + } else if (size <= OGS_CLUSTER_BIG_SIZE) { + ogs_pool_alloc(&pool->cluster_big, (ogs_cluster_big_t**)&buffer); + ogs_assert(buffer); + cluster->size = OGS_CLUSTER_BIG_SIZE; + } else { + ogs_fatal("invalid size = %d", size); + ogs_assert_if_reached(); + } + cluster->buffer = buffer; + + return cluster; +} + +static void cluster_free(ogs_pkbuf_pool_t *pool, ogs_cluster_t *cluster) +{ + ogs_assert(pool); + ogs_assert(cluster); + ogs_assert(cluster->buffer); + + switch (cluster->size) { + case OGS_CLUSTER_128_SIZE: + ogs_pool_free(&pool->cluster_128, (ogs_cluster_128_t*)cluster->buffer); + break; + case OGS_CLUSTER_256_SIZE: + ogs_pool_free(&pool->cluster_256, (ogs_cluster_256_t*)cluster->buffer); + break; + case OGS_CLUSTER_512_SIZE: + ogs_pool_free(&pool->cluster_512, (ogs_cluster_512_t*)cluster->buffer); + break; + case OGS_CLUSTER_1024_SIZE: + ogs_pool_free(&pool->cluster_1024, (ogs_cluster_1024_t*)cluster->buffer); + break; + case OGS_CLUSTER_2048_SIZE: + ogs_pool_free(&pool->cluster_2048, (ogs_cluster_2048_t*)cluster->buffer); + break; + case OGS_CLUSTER_8192_SIZE: + ogs_pool_free(&pool->cluster_8192, (ogs_cluster_8192_t*)cluster->buffer); + break; + case OGS_CLUSTER_BIG_SIZE: + ogs_pool_free(&pool->cluster_big, (ogs_cluster_big_t*)cluster->buffer); + break; + default: + ogs_assert_if_reached(); + } + + ogs_pool_free(&pool->cluster, cluster); +} + diff --git a/lib/core/ogs-pkbuf.h b/lib/core/ogs-pkbuf.h new file mode 100644 index 000000000..e6b443482 --- /dev/null +++ b/lib/core/ogs-pkbuf.h @@ -0,0 +1,149 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#if !defined(OGS_CORE_INSIDE) && !defined(OGS_CORE_COMPILATION) +#error "This header cannot be included directly." +#endif + +#ifndef OGS_PKBUF_H +#define OGS_PKBUF_H + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct ogs_cluster_s { + unsigned char *buffer; + unsigned int size; + + unsigned int ref; +} ogs_cluster_t; + +typedef struct ogs_pkbuf_pool_s ogs_pkbuf_pool_t; +typedef struct ogs_pkbuf_s { + ogs_cluster_t *cluster; + + unsigned int len; + + unsigned char *head; + unsigned char *tail; + unsigned char *data; + unsigned char *end; + + ogs_pkbuf_pool_t *pool; +} ogs_pkbuf_t; + +typedef struct ogs_pkbuf_config_s { + int cluster_128_pool; + int cluster_256_pool; + int cluster_512_pool; + int cluster_1024_pool; + int cluster_2048_pool; + int cluster_8192_pool; + int cluster_big_pool; +} ogs_pkbuf_config_t; + +void ogs_pkbuf_init(void); +void ogs_pkbuf_final(void); + +void ogs_pkbuf_default_init(ogs_pkbuf_config_t *config); +void ogs_pkbuf_default_create(ogs_pkbuf_config_t *config); +void ogs_pkbuf_default_destroy(void); + +ogs_pkbuf_pool_t *ogs_pkbuf_pool_create(ogs_pkbuf_config_t *config); +void ogs_pkbuf_pool_destroy(ogs_pkbuf_pool_t *pool); + +ogs_pkbuf_t *ogs_pkbuf_alloc(ogs_pkbuf_pool_t *pool, unsigned int size); +void ogs_pkbuf_free(ogs_pkbuf_t *pkbuf); + +void *ogs_pkbuf_put_data( + ogs_pkbuf_t *pkbuf, const void *data, unsigned int len); +ogs_pkbuf_t *ogs_pkbuf_copy(ogs_pkbuf_t *pkbuf); + +static ogs_inline int ogs_pkbuf_tailroom(const ogs_pkbuf_t *pkbuf) +{ + return pkbuf->end - pkbuf->tail; +} + +static ogs_inline int ogs_pkbuf_headroom(const ogs_pkbuf_t *pkbuf) +{ + return pkbuf->data - pkbuf->head; +} + +static ogs_inline void ogs_pkbuf_reserve(ogs_pkbuf_t *pkbuf, int len) +{ + pkbuf->data += len; + pkbuf->tail += len; +} + +static ogs_inline void *ogs_pkbuf_put(ogs_pkbuf_t *pkbuf, unsigned int len) +{ + void *tmp = pkbuf->tail; + + pkbuf->tail += len; + pkbuf->len += len; + + if (ogs_unlikely(pkbuf->tail > pkbuf->end)) + ogs_assert_if_reached(); + + return tmp; +} + +static ogs_inline void ogs_pkbuf_put_u8(ogs_pkbuf_t *pkbuf, uint8_t val) +{ + *(uint8_t *)ogs_pkbuf_put(pkbuf, 1) = val; +} + +static ogs_inline void *ogs_pkbuf_push(ogs_pkbuf_t *pkbuf, unsigned int len) +{ + pkbuf->data -= len; + pkbuf->len += len; + + if (ogs_unlikely(pkbuf->data < pkbuf->head)) + ogs_assert_if_reached(); + + return pkbuf->data; +} + +static ogs_inline void *ogs_pkbuf_pull_inline( + ogs_pkbuf_t *pkbuf, unsigned int len) +{ + pkbuf->len -= len; + return pkbuf->data += len; +} + +static ogs_inline void *ogs_pkbuf_pull(ogs_pkbuf_t *pkbuf, unsigned int len) +{ + return ogs_unlikely(len > pkbuf->len) ? + NULL : ogs_pkbuf_pull_inline(pkbuf, len); +} + +static ogs_inline void ogs_pkbuf_trim(ogs_pkbuf_t *pkbuf, unsigned int len) +{ + if (pkbuf->len > len) { + pkbuf->tail = pkbuf->data + len; + pkbuf->len = len; + } +} + +#ifdef __cplusplus +} +#endif + +#endif /* OGS_PKBUF_H */ diff --git a/lib/core/ogs-poll-private.h b/lib/core/ogs-poll-private.h new file mode 100644 index 000000000..248439584 --- /dev/null +++ b/lib/core/ogs-poll-private.h @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef OGS_POLL_PRIVATE_H +#define OGS_POLL_PRIVATE_H + +#if !defined(OGS_CORE_COMPILATION) +#error "This private header cannot be included directly." +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct ogs_poll_s { + ogs_lnode_t node; + int index; + + ogs_socket_t fd; + ogs_poll_handler_f handler; + void *data; + + ogs_pollset_t *pollset; +} ogs_poll_t; + +typedef struct ogs_pollset_s { + void *context; + OGS_POOL(pool, ogs_poll_t); + + struct { + ogs_socket_t fd[2]; + ogs_poll_t *poll; + } notify; +} ogs_pollset_t; + +#ifdef __cplusplus +} +#endif + +#endif /* OGS_POLL_PRIVATE_H */ diff --git a/lib/core/ogs-poll.c b/lib/core/ogs-poll.c new file mode 100644 index 000000000..8dfa8712e --- /dev/null +++ b/lib/core/ogs-poll.c @@ -0,0 +1,115 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "ogs-core.h" + +#include "ogs-poll-private.h" + +extern const ogs_pollset_actions_t ogs_kqueue_actions; +extern const ogs_pollset_actions_t ogs_epoll_actions; +extern const ogs_pollset_actions_t ogs_select_actions; + +ogs_pollset_actions_t ogs_pollset_actions; +bool ogs_pollset_actions_initialized = false; + +ogs_pollset_t *ogs_pollset_create(void) +{ + ogs_pollset_t *pollset = ogs_calloc(1, sizeof *pollset); + ogs_assert(pollset); + + ogs_pool_init(&pollset->pool, ogs_core()->socket.pool); + + if (ogs_pollset_actions_initialized == false) + { +#if defined(HAVE_KQUEUE) + ogs_pollset_actions = ogs_kqueue_actions;; +#elif defined(HAVE_EPOLL) + ogs_pollset_actions = ogs_epoll_actions;; +#else + ogs_pollset_actions = ogs_select_actions; +#endif + ogs_pollset_actions_initialized = true; + } + + ogs_pollset_actions.init(pollset); + + return pollset; +} + +void ogs_pollset_destroy(ogs_pollset_t *pollset) +{ + ogs_assert(pollset); + + ogs_pollset_actions.cleanup(pollset); + + ogs_pool_final(&pollset->pool); + ogs_free(pollset); +} + +ogs_poll_t *ogs_pollset_add(ogs_pollset_t *pollset, short when, + ogs_socket_t fd, ogs_poll_handler_f handler, void *data) +{ + ogs_poll_t *poll = NULL; + int rc; + + ogs_assert(pollset); + + ogs_assert(fd != INVALID_SOCKET); + ogs_assert(handler); + + ogs_pool_alloc(&pollset->pool, &poll); + ogs_assert(poll); + + rc = ogs_nonblocking(fd); + ogs_assert(rc == OGS_OK); + rc = ogs_closeonexec(fd); + ogs_assert(rc == OGS_OK); + + poll->fd = fd; + poll->handler = handler; + poll->data = data; + + poll->pollset = pollset; + + rc = ogs_pollset_actions.add(poll, when); + if (rc != OGS_OK) { + ogs_error("cannot add poll"); + ogs_pool_free(&pollset->pool, poll); + return NULL; + } + + return poll; +} + +void ogs_pollset_remove(ogs_poll_t *poll) +{ + int rc; + ogs_pollset_t *pollset = NULL; + + ogs_assert(poll); + pollset = poll->pollset; + ogs_assert(pollset); + + rc = ogs_pollset_actions.remove(poll); + if (rc != OGS_OK) { + ogs_error("cannot delete poll"); + } + + ogs_pool_free(&pollset->pool, poll); +} diff --git a/lib/core/ogs-poll.h b/lib/core/ogs-poll.h new file mode 100644 index 000000000..6646e2fdd --- /dev/null +++ b/lib/core/ogs-poll.h @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#if !defined(OGS_CORE_INSIDE) && !defined(OGS_CORE_COMPILATION) +#error "This header cannot be included directly." +#endif + +#ifndef OGS_POLL_H +#define OGS_POLL_H + +#ifdef __cplusplus +extern "C" { +#endif + +typedef void (*ogs_poll_handler_f)(short when, ogs_socket_t fd, void *data); + +ogs_pollset_t *ogs_pollset_create(void); +void ogs_pollset_destroy(ogs_pollset_t *pollset); + +#define OGS_POLLIN 0x01 +#define OGS_POLLOUT 0x02 + +ogs_poll_t *ogs_pollset_add(ogs_pollset_t *pollset, short when, + ogs_socket_t fd, ogs_poll_handler_f handler, void *data); +void ogs_pollset_remove(ogs_poll_t *poll); + +typedef struct ogs_pollset_actions_s { + void (*init)(ogs_pollset_t *pollset); + void (*cleanup)(ogs_pollset_t *pollset); + + int (*add)(ogs_poll_t *poll, short when); + int (*remove)(ogs_poll_t *poll); + + int (*poll)(ogs_pollset_t *pollset, ogs_time_t timeout); + int (*notify)(ogs_pollset_t *pollset); +} ogs_pollset_actions_t; + +extern ogs_pollset_actions_t ogs_pollset_actions; + +#define ogs_pollset_poll ogs_pollset_actions.poll +#define ogs_pollset_notify ogs_pollset_actions.notify + +#ifdef __cplusplus +} +#endif + +#endif /* OGS_POLL_H */ diff --git a/lib/core/ogs-pool.h b/lib/core/ogs-pool.h new file mode 100644 index 000000000..8c3cb3069 --- /dev/null +++ b/lib/core/ogs-pool.h @@ -0,0 +1,98 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#if !defined(OGS_CORE_INSIDE) && !defined(OGS_CORE_COMPILATION) +#error "This header cannot be included directly." +#endif + +#ifndef OGS_POOL_H +#define OGS_POOL_H + +#ifdef __cplusplus +extern "C" { +#endif + +typedef unsigned int ogs_index_t; + +#define OGS_POOL(pool, type) \ + struct { \ + const char *name; \ + int head, tail; \ + int size, avail; \ + type **free, *array, **index; \ + } pool + +#define ogs_pool_init(pool, _size) do { \ + int i; \ + (pool)->name = #pool; \ + (pool)->free = malloc(sizeof(*(pool)->free) * _size); \ + ogs_assert((pool)->free); \ + (pool)->array = malloc(sizeof(*(pool)->array) * _size); \ + ogs_assert((pool)->array); \ + (pool)->index = malloc(sizeof(*(pool)->index) * _size); \ + ogs_assert((pool)->index); \ + (pool)->size = (pool)->avail = _size; \ + (pool)->head = (pool)->tail = 0; \ + for (i = 0; i < _size; i++) { \ + (pool)->free[i] = &((pool)->array[i]); \ + (pool)->index[i] = NULL; \ + } \ +} while (0) + +#define ogs_pool_final(pool) do { \ + if (((pool)->size != (pool)->avail)) \ + ogs_error("%d in '%s[%d]' were not released.", \ + (pool)->size - (pool)->avail, (pool)->name, (pool)->size); \ + free((pool)->free); \ + free((pool)->array); \ + free((pool)->index); \ +} while (0) + +#define ogs_pool_index(pool, node) (((node) - (pool)->array)+1) +#define ogs_pool_find(pool, _index) \ + (_index > 0) ? (pool)->index[_index-1] : NULL + +#define ogs_pool_alloc(pool, node) do { \ + *(node) = NULL; \ + if ((pool)->avail > 0) { \ + (pool)->avail--; \ + *(node) = (void*)(pool)->free[(pool)->head]; \ + (pool)->free[(pool)->head] = NULL; \ + (pool)->head = ((pool)->head + 1) % ((pool)->size); \ + (pool)->index[ogs_pool_index(pool, *(node))-1] = *(node); \ + } \ +} while (0) + +#define ogs_pool_free(pool, node) do { \ + if ((pool)->avail < (pool)->size) { \ + (pool)->avail++; \ + (pool)->free[(pool)->tail] = (void*)(node); \ + (pool)->tail = ((pool)->tail + 1) % ((pool)->size); \ + (pool)->index[ogs_pool_index(pool, node)-1] = NULL; \ + } \ +} while (0) + +#define ogs_pool_size(pool) ((pool)->size) +#define ogs_pool_avail(pool) ((pool)->avail) + +#ifdef __cplusplus +} +#endif + +#endif /* OGS_POOL_H */ diff --git a/lib/core/ogs-process.c b/lib/core/ogs-process.c new file mode 100644 index 000000000..3327503aa --- /dev/null +++ b/lib/core/ogs-process.c @@ -0,0 +1,430 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "core-config-private.h" + +#if HAVE_SYS_WAIT_H +#include +#endif + +#if HAVE_FCNTL_H +#include +#endif + +#if HAVE_SIGNAL_H +#include +#endif + +#if HAVE_UNISTD_H +#include +#endif + +#include "ogs-core.h" + +int ogs_proc_create(const char *const commandLine[], int options, + ogs_proc_t *const out_process) +{ +#if defined(_WIN32) + struct process_process_information_s { + void *hProcess; + void *hThread; + unsigned long dwProcessId; + unsigned long dwThreadId; + }; + + ogs_proc_tecurity_attributes_s { + unsigned long nLength; + void *lpSecurityDescriptor; + int bInheritHandle; + }; + + ogs_proc_ttartup_info_s { + unsigned long cb; + char *lpReserved; + char *lpDesktop; + char *lpTitle; + unsigned long dwX; + unsigned long dwY; + unsigned long dwXSize; + unsigned long dwYSize; + unsigned long dwXCountChars; + unsigned long dwYCountChars; + unsigned long dwFillAttribute; + unsigned long dwFlags; + unsigned short wShowWindow; + unsigned short cbReserved2; + unsigned char *lpReserved2; + void *hStdInput; + void *hStdOutput; + void *hStdError; + }; + + int fd; + void *rd, *wr; + char *commandLineCombined; + size_t len; + int i, j; + const unsigned long startFUseStdHandles = 0x00000100; + const unsigned long handleFlagInherit = 0x00000001; + struct process_process_information_s processInfo; + ogs_proc_tecurity_attributes_s saAttr = {sizeof(saAttr), 0, 1}; + char *environment = 0; + ogs_proc_ttartup_info_s startInfo = { 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + ogs_assert(out_process); + + startInfo.cb = sizeof(startInfo); + startInfo.dwFlags = startFUseStdHandles; + + if (ogs_proc_option_inherit_environment != + (options & ogs_proc_option_inherit_environment)) { + environment = "\0\0"; + } + + if (!CreatePipe(&rd, &wr, (LPSECURITY_ATTRIBUTES)&saAttr, 0)) { + return OGS_ERROR; + } + + if (!SetHandleInformation(wr, handleFlagInherit, 0)) { + return OGS_ERROR; + } + + fd = _open_osfhandle((intptr_t)wr, 0); + + if (-1 != fd) { + out_process->stdin_file = _fdopen(fd, "wb"); + + if (0 == out_process->stdin_file) { + return OGS_ERROR; + } + } + + startInfo.hStdInput = rd; + + if (!CreatePipe(&rd, &wr, (LPSECURITY_ATTRIBUTES)&saAttr, 0)) { + return OGS_ERROR; + } + + if (!SetHandleInformation(rd, handleFlagInherit, 0)) { + return OGS_ERROR; + } + + fd = _open_osfhandle((intptr_t)rd, 0); + + if (-1 != fd) { + out_process->stdout_file = _fdopen(fd, "rb"); + + if (0 == out_process->stdout_file) { + return OGS_ERROR; + } + } + + startInfo.hStdOutput = wr; + + if (ogs_proc_option_combined_stdout_stderr == + (options & ogs_proc_option_combined_stdout_stderr)) { + out_process->stderr_file = out_process->stdout_file; + startInfo.hStdError = startInfo.hStdOutput; + } else { + if (!CreatePipe(&rd, &wr, (LPSECURITY_ATTRIBUTES)&saAttr, 0)) { + return OGS_ERROR; + } + + if (!SetHandleInformation(rd, handleFlagInherit, 0)) { + return OGS_ERROR; + } + + fd = _open_osfhandle((intptr_t)rd, 0); + + if (-1 != fd) { + out_process->stderr_file = _fdopen(fd, "rb"); + + if (0 == out_process->stderr_file) { + return OGS_ERROR; + } + } + + startInfo.hStdError = wr; + } + + // Combine commandLine together into a single string + len = 0; + for (i = 0; commandLine[i]; i++) { + // For the ' ' between items and trailing '\0' + len++; + + for (j = 0; '\0' != commandLine[i][j]; j++) { + len++; + } + } + + commandLineCombined = (char *)_alloca(len); + + if (!commandLineCombined) { + return OGS_ERROR; + } + + // Gonna re-use len to store the write index into commandLineCombined + len = 0; + + for (i = 0; commandLine[i]; i++) { + if (0 != i) { + commandLineCombined[len++] = ' '; + } + + for (j = 0; '\0' != commandLine[i][j]; j++) { + commandLineCombined[len++] = commandLine[i][j]; + } + } + + commandLineCombined[len] = '\0'; + + if (!CreateProcessA(NULL, + commandLineCombined, // command line + NULL, // process security attributes + NULL, // primary thread security attributes + 1, // handles are inherited + 0, // creation flags + environment, // use parent's environment + NULL, // use parent's current directory + (LPSTARTUPINFOA)&startInfo, // STARTUPINFO pointer + (LPPROCESS_INFORMATION)&processInfo)) { + return OGS_ERROR; + } + + out_process->hProcess = processInfo.hProcess; + out_process->dwProcessId = processInfo.dwProcessId; + + // We don't need the handle of the primary thread in the called process. + CloseHandle(processInfo.hThread); + + return OGS_OK; +#else + int stdinfd[2]; + int stdoutfd[2]; + int stderrfd[2]; + pid_t child; + + ogs_assert(out_process); + + if (0 != pipe(stdinfd)) { + return OGS_ERROR; + } + + if (0 != pipe(stdoutfd)) { + return OGS_ERROR; + } + + if (ogs_proc_option_combined_stdout_stderr != + (options & ogs_proc_option_combined_stdout_stderr)) { + if (0 != pipe(stderrfd)) { + return OGS_ERROR; + } + } + + child = fork(); + + if (-1 == child) { + return OGS_ERROR; + } + + if (0 == child) { + // Close the stdin write end + close(stdinfd[1]); + // Map the read end to stdin + dup2(stdinfd[0], STDIN_FILENO); + + // Close the stdout read end + close(stdoutfd[0]); + // Map the write end to stdout + dup2(stdoutfd[1], STDOUT_FILENO); + + if (ogs_proc_option_combined_stdout_stderr == + (options & ogs_proc_option_combined_stdout_stderr)) { + dup2(STDOUT_FILENO, STDERR_FILENO); + } else { + // Close the stderr read end + close(stderrfd[0]); + // Map the write end to stdout + dup2(stderrfd[1], STDERR_FILENO); + } + + if (ogs_proc_option_inherit_environment != + (options & ogs_proc_option_inherit_environment)) { + char *const environment[1] = {0}; + exit(execve(commandLine[0], (char *const *)commandLine, environment)); + } else { + exit(execvp(commandLine[0], (char *const *)commandLine)); + } + } else { + // Close the stdin read end + close(stdinfd[0]); + // Store the stdin write end + out_process->stdin_file = fdopen(stdinfd[1], "wb"); + + // Close the stdout write end + close(stdoutfd[1]); + // Store the stdout read end + out_process->stdout_file = fdopen(stdoutfd[0], "rb"); + + if (ogs_proc_option_combined_stdout_stderr == + (options & ogs_proc_option_combined_stdout_stderr)) { + out_process->stderr_file = out_process->stdout_file; + } else { + // Close the stderr write end + close(stderrfd[1]); + // Store the stderr read end + out_process->stderr_file = fdopen(stderrfd[0], "rb"); + } + + // Store the child's pid + out_process->child = child; + + return OGS_OK; + } +#endif +} + +FILE *ogs_proc_stdin(const ogs_proc_t *const process) +{ + ogs_assert(process); + return process->stdin_file; +} + +FILE *ogs_proc_stdout(const ogs_proc_t *const process) +{ + ogs_assert(process); + return process->stdout_file; +} + +FILE *ogs_proc_stderr(const ogs_proc_t *const process) +{ + ogs_assert(process); + if (process->stdout_file != process->stderr_file) { + return process->stderr_file; + } else { + return OGS_OK; + } +} + +int ogs_proc_join(ogs_proc_t *const process, int *const out_return_code) +{ +#if defined(_WIN32) + const unsigned long infinite = 0xFFFFFFFF; + + ogs_assert(process); + ogs_assert(out_return_code); + if (0 != process->stdin_file) { + fclose(process->stdin_file); + process->stdin_file = 0; + } + + WaitForSingleObject(process->hProcess, infinite); + + if (out_return_code) { + if (!GetExitCodeProcess(process->hProcess, + (unsigned long *)out_return_code)) { + return OGS_ERROR; + } + } + + return OGS_OK; +#else + int status; + + ogs_assert(process); + ogs_assert(out_return_code); + if (0 != process->stdin_file) { + fclose(process->stdin_file); + process->stdin_file = 0; + } + + if (process->child != waitpid(process->child, &status, 0)) { + return OGS_ERROR; + } + + if (out_return_code) { + if (WIFEXITED(status)) { + *out_return_code = WEXITSTATUS(status); + } else { + *out_return_code = 0; + } + } + + return OGS_OK; +#endif +} + +int ogs_proc_destroy(ogs_proc_t *const process) +{ + ogs_assert(process); + if (0 != process->stdin_file) { + fclose(process->stdin_file); + } + + fclose(process->stdout_file); + + if (process->stdout_file != process->stderr_file) { + fclose(process->stderr_file); + } + +#if defined(_WIN32) + CloseHandle(process->hProcess); +#endif + + return OGS_OK; +} + +int ogs_proc_terminate(ogs_proc_t *const process) +{ + ogs_assert(process); +#if defined(_WIN32) + // `GenerateConsoleCtrlEvent` can only be called on a process group. To call + // `GenerateConsoleCtrlEvent` on a single child process it has to be put in + // its own process group (which we did when starting the child process). + if (!GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT, process->dwProcessId)) { + return OGS_ERROR; + } +#else + if (kill(process->child, SIGTERM) == -1) { + return OGS_ERROR; + } +#endif + + return OGS_OK; +} + +int ogs_proc_kill(ogs_proc_t *const process) +{ + ogs_assert(process); +#if defined(_WIN32) + // We use 137 as the exit status because it is the same exit status as a + // process that is stopped with the `SIGKILL` signal on POSIX systems. + if (!TerminateProcess(process->hProcess, 137)) { + return OGS_ERROR; + } +#else + if (kill(process->child, SIGKILL) == -1) { + return OGS_ERROR; + } +#endif + + return OGS_OK; +} diff --git a/lib/core/ogs-process.h b/lib/core/ogs-process.h new file mode 100644 index 000000000..0d0ab6175 --- /dev/null +++ b/lib/core/ogs-process.h @@ -0,0 +1,96 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#if !defined(OGS_CORE_INSIDE) && !defined(OGS_CORE_COMPILATION) +#error "This header cannot be included directly." +#endif + +#ifndef OGS_PROCESS_H +#define OGS_PROCESS_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * The following code is stolen from process.h + * https://github.com/sheredom/process.h + */ + +#if defined(_WIN32) +typedef struct _PROCESS_INFORMATION *LPPROCESS_INFORMATION; +typedef struct _SECURITY_ATTRIBUTES *LPSECURITY_ATTRIBUTES; +typedef struct _STARTUPINFOA *LPSTARTUPINFOA; + +__declspec(dllimport) int __stdcall SetHandleInformation(void *, unsigned long, + unsigned long); +__declspec(dllimport) int __stdcall CreatePipe(void **, void **, + LPSECURITY_ATTRIBUTES, + unsigned long); +__declspec(dllimport) int __stdcall CreateProcessA( + const char *, char *, LPSECURITY_ATTRIBUTES, LPSECURITY_ATTRIBUTES, int, + unsigned long, void *, const char *, LPSTARTUPINFOA, LPPROCESS_INFORMATION); +__declspec(dllimport) int __stdcall CloseHandle(void *); +__declspec(dllimport) unsigned long __stdcall WaitForSingleObject( + void *, unsigned long); +__declspec(dllimport) int __stdcall GetExitCodeProcess( + void *, unsigned long *lpExitCode); +__declspec(dllimport) int __cdecl _open_osfhandle(intptr_t, int); +void *__cdecl _alloca(size_t); +#endif + +typedef struct ogs_proc_s { + FILE *stdin_file; + FILE *stdout_file; + FILE *stderr_file; + +#if defined(_WIN32) + void *hProcess; + unsigned long dwProcessId; +#else + pid_t child; +#endif +} ogs_proc_t; + +enum ogs_proc_option_e { + // stdout and stderr are the same FILE. + ogs_proc_option_combined_stdout_stderr = 0x1, + + // The child process should inherit the environment variables of the parent. + ogs_proc_option_inherit_environment = 0x2 +}; + +int ogs_proc_create(const char *const command_line[], int options, + ogs_proc_t *const out_process); + +FILE *ogs_proc_stdin(const ogs_proc_t *const process); +FILE *ogs_proc_stdout(const ogs_proc_t *const process); +FILE *ogs_proc_stderr(const ogs_proc_t *const process); + +int ogs_proc_join(ogs_proc_t *const process, int *const out_return_code); +int ogs_proc_destroy(ogs_proc_t *const process); + +int ogs_proc_terminate(ogs_proc_t *const process); +int ogs_proc_kill(ogs_proc_t *const process); + +#ifdef __cplusplus +} +#endif + +#endif /* OGS_PROCESS_H */ diff --git a/lib/core/ogs-queue.c b/lib/core/ogs-queue.c new file mode 100644 index 000000000..c0b6ea3b6 --- /dev/null +++ b/lib/core/ogs-queue.c @@ -0,0 +1,284 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "ogs-core.h" + +#undef OGS_LOG_DOMAIN +#define OGS_LOG_DOMAIN __ogs_event_domain + +typedef struct ogs_queue_s { + void **data; + unsigned int nelts; /**< # elements */ + unsigned int in; /**< next empty location */ + unsigned int out; /**< next filled location */ + unsigned int bounds;/**< max size of queue */ + unsigned int full_waiters; + unsigned int empty_waiters; + ogs_thread_mutex_t one_big_mutex; + ogs_thread_cond_t not_empty; + ogs_thread_cond_t not_full; + int terminated; +} ogs_queue_t; + +/** + * Detects when the ogs_queue_t is full. This utility function is expected + * to be called from within critical sections, and is not threadsafe. + */ +#define ogs_queue_full(queue) ((queue)->nelts == (queue)->bounds) + +/** + * Detects when the ogs_queue_t is empty. This utility function is expected + * to be called from within critical sections, and is not threadsafe. + */ +#define ogs_queue_empty(queue) ((queue)->nelts == 0) + +/** + * Callback routine that is called to destroy this + * ogs_queue_t when its pool is destroyed. + */ +ogs_queue_t *ogs_queue_create(unsigned int capacity) +{ + ogs_queue_t *queue = ogs_calloc(1, sizeof *queue); + ogs_assert(queue); + + ogs_thread_mutex_init(&queue->one_big_mutex); + ogs_thread_cond_init(&queue->not_empty); + ogs_thread_cond_init(&queue->not_full); + + queue->data = ogs_calloc(1, capacity * sizeof(void*)); + queue->bounds = capacity; + queue->nelts = 0; + queue->in = 0; + queue->out = 0; + queue->terminated = 0; + queue->full_waiters = 0; + queue->empty_waiters = 0; + + return queue; +} + +void ogs_queue_destroy(ogs_queue_t *queue) +{ + ogs_assert(queue); + + ogs_free(queue->data); + + ogs_thread_cond_destroy(&queue->not_empty); + ogs_thread_cond_destroy(&queue->not_full); + ogs_thread_mutex_destroy(&queue->one_big_mutex); + + ogs_free(queue); +} + +static int queue_push(ogs_queue_t *queue, void *data, ogs_time_t timeout) +{ + int rv; + + if (queue->terminated) { + return OGS_DONE; /* no more elements ever again */ + } + + ogs_thread_mutex_lock(&queue->one_big_mutex); + + if (ogs_queue_full(queue)) { + if (!timeout) { + ogs_thread_mutex_unlock(&queue->one_big_mutex); + return OGS_RETRY; + } + if (!queue->terminated) { + queue->full_waiters++; + if (timeout > 0) { + rv = ogs_thread_cond_timedwait(&queue->not_full, + &queue->one_big_mutex, + timeout); + } + else { + rv = ogs_thread_cond_wait(&queue->not_full, + &queue->one_big_mutex); + } + queue->full_waiters--; + if (rv != OGS_OK) { + ogs_thread_mutex_unlock(&queue->one_big_mutex); + return rv; + } + } + /* If we wake up and it's still empty, then we were interrupted */ + if (ogs_queue_full(queue)) { + ogs_warn("queue full (intr)"); + ogs_thread_mutex_unlock(&queue->one_big_mutex); + if (queue->terminated) { + return OGS_DONE; /* no more elements ever again */ + } + else { + return OGS_ERROR; + } + } + } + + queue->data[queue->in] = data; + queue->in++; + if (queue->in >= queue->bounds) + queue->in -= queue->bounds; + queue->nelts++; + + if (queue->empty_waiters) { + ogs_trace("signal !empty"); + ogs_thread_cond_signal(&queue->not_empty); + } + + ogs_thread_mutex_unlock(&queue->one_big_mutex); + return OGS_OK; +} + +int ogs_queue_push(ogs_queue_t *queue, void *data) +{ + return queue_push(queue, data, OGS_INFINITE_TIME); +} + +/** + * Push new data onto the queue. If the queue is full, return OGS_RETRY. If + * the push operation completes successfully, it signals other threads + * waiting in ogs_queue_pop() that they may continue consuming sockets. + */ +int ogs_queue_trypush(ogs_queue_t *queue, void *data) +{ + return queue_push(queue, data, 0); +} + +int ogs_queue_timedpush(ogs_queue_t *queue, void *data, ogs_time_t timeout) +{ + return queue_push(queue, data, timeout); +} + +/** + * not thread safe + */ +unsigned int ogs_queue_size(ogs_queue_t *queue) { + return queue->nelts; +} + +/** + * Retrieves the next item from the queue. If there are no + * items available, it will either return OGS_RETRY (timeout = 0), + * or block until one becomes available (infinitely with timeout < 0, + * otherwise until the given timeout expires). Once retrieved, the + * item is placed into the address specified by 'data'. + */ +static int queue_pop(ogs_queue_t *queue, void **data, ogs_time_t timeout) +{ + int rv; + + if (queue->terminated) { + return OGS_DONE; /* no more elements ever again */ + } + + ogs_thread_mutex_lock(&queue->one_big_mutex); + + /* Keep waiting until we wake up and find that the queue is not empty. */ + if (ogs_queue_empty(queue)) { + if (!timeout) { + ogs_thread_mutex_unlock(&queue->one_big_mutex); + return OGS_RETRY; + } + if (!queue->terminated) { + queue->empty_waiters++; + if (timeout > 0) { + rv = ogs_thread_cond_timedwait(&queue->not_empty, + &queue->one_big_mutex, + timeout); + } + else { + rv = ogs_thread_cond_wait(&queue->not_empty, + &queue->one_big_mutex); + } + queue->empty_waiters--; + if (rv != OGS_OK) { + ogs_thread_mutex_unlock(&queue->one_big_mutex); + return rv; + } + } + /* If we wake up and it's still empty, then we were interrupted */ + if (ogs_queue_empty(queue)) { + ogs_warn("queue empty (intr)"); + ogs_thread_mutex_unlock(&queue->one_big_mutex); + if (queue->terminated) { + return OGS_DONE; /* no more elements ever again */ + } else { + return OGS_ERROR; + } + } + } + + *data = queue->data[queue->out]; + queue->nelts--; + + queue->out++; + if (queue->out >= queue->bounds) + queue->out -= queue->bounds; + if (queue->full_waiters) { + ogs_trace("signal !full"); + ogs_thread_cond_signal(&queue->not_full); + } + + ogs_thread_mutex_unlock(&queue->one_big_mutex); + return OGS_OK; +} + +int ogs_queue_pop(ogs_queue_t *queue, void **data) +{ + return queue_pop(queue, data, OGS_INFINITE_TIME); +} + +int ogs_queue_trypop(ogs_queue_t *queue, void **data) +{ + return queue_pop(queue, data, 0); +} + +int ogs_queue_timedpop(ogs_queue_t *queue, void **data, ogs_time_t timeout) +{ + return queue_pop(queue, data, timeout); +} + +int ogs_queue_interrupt_all(ogs_queue_t *queue) +{ + ogs_debug("interrupt all"); + ogs_thread_mutex_lock(&queue->one_big_mutex); + + ogs_thread_cond_broadcast(&queue->not_empty); + ogs_thread_cond_broadcast(&queue->not_full); + + ogs_thread_mutex_unlock(&queue->one_big_mutex); + + return OGS_OK; +} + +int ogs_queue_term(ogs_queue_t *queue) +{ + ogs_thread_mutex_lock(&queue->one_big_mutex); + + /* we must hold one_big_mutex when setting this... otherwise, + * we could end up setting it and waking everybody up just after a + * would-be popper checks it but right before they block + */ + queue->terminated = 1; + ogs_thread_mutex_unlock(&queue->one_big_mutex); + + return ogs_queue_interrupt_all(queue); +} + diff --git a/lib/core/ogs-queue.h b/lib/core/ogs-queue.h new file mode 100644 index 000000000..ad66815a8 --- /dev/null +++ b/lib/core/ogs-queue.h @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#if !defined(OGS_CORE_INSIDE) && !defined(OGS_CORE_COMPILATION) +#error "This header cannot be included directly." +#endif + +#ifndef OGS_QUEUE_H +#define OGS_QUEUE_H + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct ogs_queue_s ogs_queue_t; + +ogs_queue_t *ogs_queue_create(unsigned int capacity); +void ogs_queue_destroy(ogs_queue_t *queue); + +int ogs_queue_push(ogs_queue_t *queue, void *data); +int ogs_queue_pop(ogs_queue_t *queue, void **data); + +int ogs_queue_trypush(ogs_queue_t *queue, void *data); +int ogs_queue_trypop(ogs_queue_t *queue, void **data); + +int ogs_queue_timedpush(ogs_queue_t *queue, void *data, ogs_time_t timeout); +int ogs_queue_timedpop(ogs_queue_t *queue, void **data, ogs_time_t timeout); + +unsigned int ogs_queue_size(ogs_queue_t *queue); + +int ogs_queue_interrupt_all(ogs_queue_t *queue); +int ogs_queue_term(ogs_queue_t *queue); + + +#ifdef __cplusplus +} +#endif + +#endif /* OGS_QUEUE_H */ diff --git a/lib/core/ogs-rand.c b/lib/core/ogs-rand.c new file mode 100644 index 000000000..3a07ef7f3 --- /dev/null +++ b/lib/core/ogs-rand.c @@ -0,0 +1,131 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "core-config-private.h" + +#if HAVE_SYS_PARAM_H +#include +#endif + +#if HAVE_SYS_RANDOM_H +#include +#endif + +#if HAVE_FCNTL_H +#include +#endif + +#if HAVE_UNISTD_H +#include +#endif + +#include "ogs-core.h" + +void ogs_random(void *buf, size_t buflen) +{ +#ifdef _WIN32 + void arc4random_buf(void *buf, size_t n); + arc4random_buf(buf, buflen); +#elif defined(HAVE_GETRANDOM) + int rc = getrandom(buf, buflen, GRND_NONBLOCK); + if (rc < 0) { + ogs_log_message(OGS_LOG_FATAL, ogs_errno, "getrandom() failed"); + ogs_assert_if_reached(); + } +#elif defined(HAVE_ARC4RANDOM_BUF) + arc4random_buf(buf, buflen); +#elif defined(OGS_DEV_RANDOM) + int fd = -1; + + /* On BSD/OS 4.1, /dev/random gives out 8 bytes at a time, then + * gives EOF, so reading 'buflen' bytes may require opening the + * device several times. */ + do { + int rc; + + if (fd == -1) + if ((fd = open(OGS_DEV_RANDOM, O_RDONLY)) == -1) { + ogs_log_message(OGS_LOG_FATAL, ogs_errno, "open() failed"); + ogs_assert_if_reached(); + } + + do { + rc = read(fd, buf, buflen); + } while (rc == -1 && errno == EINTR); + + if (rc < 0) { + ogs_log_message(OGS_LOG_ERROR, ogs_errno, "read() failed"); + close(fd); + return; + } + else if (rc == 0) { + close(fd); + fd = -1; /* force open() again */ + } + else { + buf = (unsigned char *)buf + rc; + buflen -= rc; + } + } while (buflen > 0); + + close(fd); +#else +#error cannot find a method which finds a pseudo-random number +#endif +} + +uint32_t ogs_random32(void) +{ +#ifdef _WIN32 + uint32_t arc4random(void); + return arc4random(); +#elif defined(HAVE_ARC4RANDOM_BUF) + return arc4random(); +#else + uint32_t rand32; + + ogs_random(&rand32, sizeof(rand32)); + return rand32; +#endif +} + +#ifdef _WIN32 +#define ARC4RANDOM_NO_INCLUDES +#define ARC4_LOCK_() do {} while(0) +#define ARC4_UNLOCK_() do {} while(0) + +#define ARC4RANDOM_UINT32 uint32_t +#define ARC4RANDOM_NOSTIR +#define ARC4RANDOM_NOADDRANDOM +#define ARC4RANDOM_NOUNIFORM + +/** + * Stolen from libevent library. + * https://github.com/libevent/libevent/blob/master/evutil.c + */ +void *(*volatile evutil_memset_volatile_)(void *, int, size_t) = memset; + +static void evutil_memclear_(void *mem, size_t len) +{ + evutil_memset_volatile_(mem, 0, len); +} + +#include "arc4random.c" +#endif + diff --git a/lib/core/ogs-rand.h b/lib/core/ogs-rand.h new file mode 100644 index 000000000..9cf9d8832 --- /dev/null +++ b/lib/core/ogs-rand.h @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#if !defined(OGS_CORE_INSIDE) && !defined(OGS_CORE_COMPILATION) +#error "This header cannot be included directly." +#endif + +#ifndef OGS_RAND_H +#define OGS_RAND_H + +#ifdef __cplusplus +extern "C" { +#endif + +void ogs_random(void *buf, size_t buflen); +uint32_t ogs_random32(void); + +#ifdef __cplusplus +} +#endif + +#endif /* OGS_RAND_H */ diff --git a/lib/core/ogs-rbtree.c b/lib/core/ogs-rbtree.c new file mode 100644 index 000000000..a89d2af53 --- /dev/null +++ b/lib/core/ogs-rbtree.c @@ -0,0 +1,434 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "ogs-core.h" + +static ogs_inline void rb_change_child(ogs_rbtree_t *tree, + ogs_rbnode_t *old, ogs_rbnode_t *new, ogs_rbnode_t *parent) +{ + if (parent) { + if (old == parent->left) + parent->left = new; + else + parent->right = new; + } else { + tree->root = new; + } +} + +static ogs_inline void rb_replace_node(ogs_rbtree_t *tree, + ogs_rbnode_t *old, ogs_rbnode_t *new, ogs_rbnode_t *parent) +{ + rb_change_child(tree, old, new, parent); + + if (new) + new->parent = parent; +} + +/* + * Example - Left rotate at A + * + * A B + * / \ / \ + * B C <-- D A + * / \ / \ / \ / \ + * D 3 4 5 1 2 3 C + * / \ / \ + * 1 2 1 2 + */ +static void rb_rotate_left(ogs_rbtree_t *tree, ogs_rbnode_t *node) +{ + ogs_rbnode_t *right = node->right; + node->right = right->left; + if (right->left) + right->left->parent = node; + + rb_replace_node(tree, node, right, node->parent); + + right->left = node; + node->parent = right; +} + +/* + * Example - right rotate at A + * + * A B + * / \ / \ + * B C --> D A + * / \ / \ / \ / \ + * D 3 4 5 1 2 3 C + * / \ / \ + * 1 2 1 2 + */ +static void rb_rotate_right(ogs_rbtree_t *tree, ogs_rbnode_t *node) +{ + ogs_rbnode_t *left = node->left; + node->left = left->right; + if (left->right) + left->right->parent = node; + + rb_replace_node(tree, node, left, node->parent); + + left->right = node; + node->parent = left; +} + +void ogs_rbtree_insert_color(ogs_rbtree_t *tree, void *rb_node) +{ + ogs_rbnode_t *node = rb_node; + ogs_rbnode_t *parent; + ogs_assert(tree); + ogs_assert(node); + + while ((parent = node->parent) && parent->color == OGS_RBTREE_RED) { + ogs_rbnode_t *gparent = parent->parent; + ogs_assert(gparent); + + /* parent == grandparent's left child */ + if (parent == gparent->left) { + ogs_rbnode_t *uncle = gparent->right; + + if (uncle && uncle->color == OGS_RBTREE_RED) { + /* + * node's uncle == red (color flips) + * + * G g + * / \ / \ + * p u --> P U + * / / + * n n + */ + uncle->color = OGS_RBTREE_BLACK; + parent->color = OGS_RBTREE_BLACK; + + gparent->color = OGS_RBTREE_RED; + + node = gparent; + } else { + /* node's uncle == black */ + if (node == parent->right) { + /* + * node == the parent's right child, + * (left rotate at parent) + * + * G G + * / \ / \ + * p U --> p U + * \ / + * n n + */ + node = node->parent; + rb_rotate_left(tree, node); + } + + /* + * Now we're the left child + * (right rotate at grand parent) + * + * g P + * / \ / \ + * P U --> n g + * / \ + * n U + */ + node->parent->color = OGS_RBTREE_BLACK; + gparent->color = OGS_RBTREE_RED; + rb_rotate_right(tree, gparent); + } + /* parent == grandparent's right child */ + } else { + ogs_rbnode_t *uncle = gparent->left; + + if (uncle && uncle->color == OGS_RBTREE_RED) { + /* + * node's uncle == red (color flips) + * + * G g + * / \ / \ + * u p --> U P + * \ \ + * n n + */ + uncle->color = OGS_RBTREE_BLACK; + parent->color = OGS_RBTREE_BLACK; + + gparent->color = OGS_RBTREE_RED; + + node = gparent; + } else { + /* node's uncle == black */ + if (node == parent->left) { + /* + * node == the parent's left child, + * (right rotate at parent) + * + * G G + * / \ / \ + * p U --> p U + * / \ + * n n + */ + node = node->parent; + rb_rotate_right(tree, node); + } + + /* + * Now we're the right child, + * (left rotate at grand parent) + * + * g P + * / \ / \ + * P U --> n g + * \ \ + * n U + */ + node->parent->color = OGS_RBTREE_BLACK; + gparent->color = OGS_RBTREE_RED; + rb_rotate_left(tree, gparent); + } + } + } + + ogs_assert(tree->root); + tree->root->color = OGS_RBTREE_BLACK; +} + +static void rb_delete_color( + ogs_rbtree_t *tree, ogs_rbnode_t *node, ogs_rbnode_t *parent) +{ + ogs_rbnode_t *sibling; + ogs_assert(tree); + +#define rb_is_black(r) ((!r) || (r)->color == OGS_RBTREE_BLACK) + while (node != tree->root && rb_is_black(node)) { + if (node == parent->left) { + sibling = parent->right; + if (sibling->color == OGS_RBTREE_RED) { + /* + * Case 1 - left rotate at parent + * + * P S + * / \ / \ + * N s --> p Sr + * / \ / \ + * Sl Sr N Sl + */ + sibling->color = OGS_RBTREE_BLACK; + parent->color = OGS_RBTREE_RED; + rb_rotate_left(tree, parent); + sibling = parent->right; + } + if (rb_is_black(sibling->left) && rb_is_black(sibling->right)) { + /* + * Case 2 - sibling color flip + * (p could be either color here) + * + * (p) (p) + * / \ / \ + * N S --> N s + * / \ / \ + * Sl Sr Sl Sr + */ + sibling->color = OGS_RBTREE_RED; + node = parent; + parent = node->parent; + } else { + if (rb_is_black(sibling->right)) { + /* + * Case 3 - right rotate at sibling + * (p could be either color here) + * + * (p) (p) + * / \ / \ + * N S --> N Sl + * / \ \ + * sl Sr s + * \ + * Sr + */ + sibling->left->color = OGS_RBTREE_BLACK; + sibling->color = OGS_RBTREE_RED; + rb_rotate_right(tree, sibling); + sibling = parent->right; + } + /* + * Case 4 - left rotate at parent + color flips + * (p and sl could be either color here. + * After rotation, p becomes black, s acquires + * p's color, and sl keeps its color) + * + * (p) (s) + * / \ / \ + * N S --> P Sr + * / \ / \ + * (sl) sr N (sl) + */ + sibling->color = parent->color; + parent->color = OGS_RBTREE_BLACK; + sibling->right->color = OGS_RBTREE_BLACK; + rb_rotate_left(tree, parent); + node = tree->root; + } + } else { + sibling = parent->left; + if (sibling->color == OGS_RBTREE_RED) { + sibling->color = OGS_RBTREE_BLACK; + parent->color = OGS_RBTREE_RED; + /* Case 1 - right rotate at parent */ + rb_rotate_right(tree, parent); + sibling = parent->left; + } + if (rb_is_black(sibling->left) && rb_is_black(sibling->right)) { + /* Case 2 - sibling color flip */ + sibling->color = OGS_RBTREE_RED; + node = parent; + parent = node->parent; + } else { + if (rb_is_black(sibling->left)) { + sibling->right->color = OGS_RBTREE_BLACK; + sibling->color = OGS_RBTREE_RED; + /* Case 3 - left rotate at sibling */ + rb_rotate_left(tree, sibling); + sibling = parent->left; + } + /* Case 4 - right rotate at parent + color flips */ + sibling->color = parent->color; + parent->color = OGS_RBTREE_BLACK; + sibling->left->color = OGS_RBTREE_BLACK; + rb_rotate_right(tree, parent); + node = tree->root; + } + } + } + if (node) + node->color = OGS_RBTREE_BLACK; +} + +void ogs_rbtree_delete(ogs_rbtree_t *tree, void *rb_node) +{ + ogs_rbnode_t *node = rb_node; + ogs_rbnode_t *child, *parent; + ogs_rbtree_color_e color; + ogs_assert(tree); + ogs_assert(node); + + if (!node->left) { + child = node->right; + parent = node->parent; + color = node->color; + + rb_replace_node(tree, node, child, parent); + } else if (!node->right) { + child = node->left; + parent = node->parent; + color = node->color; + + rb_replace_node(tree, node, child, parent); + } else { + ogs_rbnode_t *new = ogs_rbtree_min(node->right); + + child = new->right; + parent = new->parent; + color = new->color; + + new->left = node->left; + node->left->parent = new; + + if (parent == node) { + parent = new; + } else { + if (child) { + child->parent = parent; + } + parent->left = child; + + new->right = node->right; + node->right->parent = new; + } + + new->color = node->color; + + rb_replace_node(tree, node, new, node->parent); + } + + if (color == OGS_RBTREE_BLACK) + rb_delete_color(tree, child, parent); +} + +void *ogs_rbtree_first(const ogs_rbtree_t *tree) +{ + ogs_rbnode_t *node; + ogs_assert(tree); + + node = tree->root; + if (!node) + return NULL; + + return ogs_rbtree_min(node); +} + +void *ogs_rbtree_last(const ogs_rbtree_t *tree) +{ + ogs_rbnode_t *node; + ogs_assert(tree); + + node = tree->root; + if (!node) + return NULL; + + return ogs_rbtree_max(node); +} + +#define rb_empty_node(node) ((node)->parent == (node)) + +void *ogs_rbtree_next(const void *rb_node) +{ + const ogs_rbnode_t *node = rb_node; + ogs_rbnode_t *parent; + ogs_assert(node); + + if (rb_empty_node(node)) + return NULL; + + if (node->right) + return ogs_rbtree_min(node->right); + + while ((parent = node->parent) && node == parent->right) + node = parent; + + return parent; +} + +void *ogs_rbtree_prev(const void *rb_node) +{ + const ogs_rbnode_t *node = rb_node; + ogs_rbnode_t *parent; + ogs_assert(node); + + if (rb_empty_node(node)) + return NULL; + + if (node->left) + return ogs_rbtree_max(node->left); + + while ((parent = node->parent) && node == parent->left) + node = parent; + + return parent; +} diff --git a/lib/core/ogs-rbtree.h b/lib/core/ogs-rbtree.h new file mode 100644 index 000000000..1a42bfdc6 --- /dev/null +++ b/lib/core/ogs-rbtree.h @@ -0,0 +1,120 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#if !defined(OGS_CORE_INSIDE) && !defined(OGS_CORE_COMPILATION) +#error "This header cannot be included directly." +#endif + +#ifndef OGS_RBTREE_H +#define OGS_RBTREE_H + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { + OGS_RBTREE_BLACK = 0, + OGS_RBTREE_RED = 1, +} ogs_rbtree_color_e; + +typedef struct ogs_rbnode_s { + struct ogs_rbnode_s *parent; + struct ogs_rbnode_s *left; + struct ogs_rbnode_s *right; + + ogs_rbtree_color_e color; +} ogs_rbnode_t; + +typedef struct ogs_rbtree_s { + ogs_rbnode_t *root; +} ogs_rbtree_t; + +#define OGS_RBTREE(name) ogs_rbtree_t name = { NULL } + +#define ogs_rb_entry(n, type, link) \ + (type *)((u_char *)n - offsetof(type, link)) + +static ogs_inline void ogs_rbtree_link_node( + void *rb_node, ogs_rbnode_t *parent, ogs_rbnode_t **rb_link) +{ + ogs_rbnode_t *node = rb_node; + node->parent = parent; + node->left = node->right = NULL; + node->color = OGS_RBTREE_RED; + + *rb_link = node; +} + +void ogs_rbtree_insert_color(ogs_rbtree_t *tree, void *rb_node); +void ogs_rbtree_delete(ogs_rbtree_t *tree, void *rb_node); + +static ogs_inline void *ogs_rbtree_min(const ogs_rbnode_t *rb_node) +{ + const ogs_rbnode_t *node = rb_node; + ogs_assert(node); + + while (node->left) + node = node->left; + + return (void *)node; +} + +static ogs_inline void *ogs_rbtree_max(const void *rb_node) +{ + const ogs_rbnode_t *node = rb_node; + ogs_assert(node); + + while (node->right) + node = node->right; + + return (void *)node; +} + +void *ogs_rbtree_first(const ogs_rbtree_t *tree); +void *ogs_rbtree_next(const void *node); +void *ogs_rbtree_last(const ogs_rbtree_t *tree); +void *ogs_rbtree_prev(const void *node); + +#define ogs_rbtree_for_each(tree, node) \ + for (node = ogs_rbtree_first(tree); \ + (node); node = ogs_rbtree_next(node)) + +#define ogs_rbtree_reverse_for_each(tree, node) \ + for (node = ogs_rbtree_last(tree); \ + (node); node = ogs_rbtree_prev(node)) + +static ogs_inline bool ogs_rbtree_empty(const ogs_rbtree_t *tree) +{ + return tree->root == NULL; +} + +static ogs_inline int ogs_rbtree_count(const ogs_rbtree_t *tree) +{ + ogs_rbnode_t *node; + int i = 0; + ogs_rbtree_for_each(tree, node) + i++; + return i; +} + +#ifdef __cplusplus +} +#endif + +#endif /* OGS_RBTREE_H */ diff --git a/lib/core/ogs-select.c b/lib/core/ogs-select.c new file mode 100644 index 000000000..549393f43 --- /dev/null +++ b/lib/core/ogs-select.c @@ -0,0 +1,197 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "core-config-private.h" + +#if HAVE_UNISTD_H +#include +#endif + +#include "ogs-core.h" +#include "ogs-poll-private.h" + +static void select_init(ogs_pollset_t *pollset); +static void select_cleanup(ogs_pollset_t *pollset); +static int select_add(ogs_poll_t *poll, short when); +static int select_remove(ogs_poll_t *poll); +static int select_process(ogs_pollset_t *pollset, ogs_time_t timeout); + +const ogs_pollset_actions_t ogs_select_actions = { + select_init, + select_cleanup, + + select_add, + select_remove, + select_process, + + ogs_notify_pollset, +}; + +struct select_context_s { + int max_fd; + fd_set master_read_fd_set; + fd_set master_write_fd_set; + fd_set work_read_fd_set; + fd_set work_write_fd_set; + + ogs_list_t list; +}; + +static void select_init(ogs_pollset_t *pollset) +{ + struct select_context_s *context = NULL; + ogs_assert(pollset); + + context = ogs_calloc(1, sizeof *context); + ogs_assert(context); + pollset->context = context; + + ogs_list_init(&context->list); + + context->max_fd = -1; + FD_ZERO(&context->master_read_fd_set); + FD_ZERO(&context->master_write_fd_set); + + ogs_notify_init(pollset); +} + +static void select_cleanup(ogs_pollset_t *pollset) +{ + struct select_context_s *context = NULL; + + ogs_assert(pollset); + context = pollset->context; + ogs_assert(context); + + ogs_notify_final(pollset); + ogs_free(context); +} + +static int select_add(ogs_poll_t *poll, short when) +{ + ogs_pollset_t *pollset = NULL; + struct select_context_s *context = NULL; + + ogs_assert(poll); + pollset = poll->pollset; + ogs_assert(pollset); + context = pollset->context; + ogs_assert(context); + + if (when & OGS_POLLIN) { + FD_SET(poll->fd, &context->master_read_fd_set); + } + + if (when & OGS_POLLOUT) { + FD_SET(poll->fd, &context->master_write_fd_set); + } + + if (poll->fd > context->max_fd) + context->max_fd = poll->fd; + + ogs_list_add(&context->list, poll); + + return OGS_OK; +} + +static int select_remove(ogs_poll_t *poll) +{ + ogs_pollset_t *pollset = NULL; + struct select_context_s *context = NULL; + + ogs_assert(poll); + pollset = poll->pollset; + ogs_assert(pollset); + context = pollset->context; + ogs_assert(context); + + FD_CLR(poll->fd, &context->master_read_fd_set); + FD_CLR(poll->fd, &context->master_write_fd_set); + + if (context->max_fd == poll->fd) { + context->max_fd = -1; + } + + ogs_list_remove(&context->list, poll); + + return OGS_OK; +} + +static int select_process(ogs_pollset_t *pollset, ogs_time_t timeout) +{ + struct select_context_s *context = NULL; + ogs_poll_t *poll = NULL; + int rc; + struct timeval tv, *tp; + + ogs_assert(pollset); + context = pollset->context; + ogs_assert(context); + + if (context->max_fd == -1) { + ogs_list_for_each(&context->list, poll) { + if (context->max_fd < poll->fd) { + context->max_fd = poll->fd; + } + } + ogs_debug("change max_fd: %d", context->max_fd); + } + + context->work_read_fd_set = context->master_read_fd_set; + context->work_write_fd_set = context->master_write_fd_set; + + if (timeout == OGS_INFINITE_TIME) { + tp = NULL; + } else { + tv.tv_sec = ogs_time_sec(timeout); +#if defined(_WIN32) /* I don't know why windows need more time */ + tv.tv_usec = ogs_time_usec(timeout) + ogs_time_from_msec(1); +#else + tv.tv_usec = ogs_time_usec(timeout); +#endif + + tp = &tv; + } + + rc = select(context->max_fd + 1, + &context->work_read_fd_set, &context->work_write_fd_set, NULL, tp); + if (rc < 0) { + ogs_log_message(OGS_LOG_ERROR, ogs_socket_errno, "select() failed"); + return OGS_ERROR; + } else if (rc == 0) { + return OGS_TIMEUP; + } + + ogs_list_for_each(&context->list, poll) { + short when = 0; + if (FD_ISSET(poll->fd, &context->work_read_fd_set)) { + when |= OGS_POLLIN; + } + + if (FD_ISSET(poll->fd, &context->work_write_fd_set)) { + when |= OGS_POLLOUT; + } + + if (when && poll->handler) { + poll->handler(when, poll->fd, poll->data); + } + } + + return OGS_OK; +} diff --git a/lib/core/ogs-signal.c b/lib/core/ogs-signal.c new file mode 100644 index 000000000..6cda75552 --- /dev/null +++ b/lib/core/ogs-signal.c @@ -0,0 +1,454 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "core-config-private.h" + +#if HAVE_SIGNAL_H +#include +#endif + +#include "ogs-core.h" + +#if HAVE_SIGACTION + +#if defined(__NetBSD__) || defined(DARWIN) +static void avoid_zombies(int signo) +{ + int exit_status; + + while (waitpid(-1, &exit_status, WNOHANG) > 0) { + /* do nothing */ + } +} +#endif /* DARWIN */ + +/* + * Replace standard signal() with the more reliable sigaction equivalent + * from W. Richard Stevens' "Advanced Programming in the UNIX Environment" + * (the version that does not automatically restart system calls). + */ +ogs_sigfunc_t *ogs_signal(int signo, ogs_sigfunc_t *func) +{ + struct sigaction act, oact; + + act.sa_handler = func; + sigemptyset(&act.sa_mask); + act.sa_flags = 0; +#ifdef SA_INTERRUPT /* SunOS */ + act.sa_flags |= SA_INTERRUPT; +#endif +#if defined(__osf__) && defined(__alpha) + /* XXX jeff thinks this should be enabled whenever SA_NOCLDWAIT is defined */ + + /* this is required on Tru64 to cause child processes to + * disappear gracefully - XPG4 compatible + */ + if ((signo == SIGCHLD) && (func == SIG_IGN)) { + act.sa_flags |= SA_NOCLDWAIT; + } +#endif +#if defined(__NetBSD__) || defined(DARWIN) + /* ignoring SIGCHLD or leaving the default disposition doesn't avoid zombies, + * and there is no SA_NOCLDWAIT flag, so catch the signal and reap status in + * the handler to avoid zombies + */ + if ((signo == SIGCHLD) && (func == SIG_IGN)) { + act.sa_handler = avoid_zombies; + } +#endif + if (sigaction(signo, &act, &oact) < 0) + return SIG_ERR; + return oact.sa_handler; +} + +#endif /* HAVE_SIGACTION */ + +/* AC_DECL_SYS_SIGLIST defines either of these symbols depending + * on the version of autoconf used. */ +#if HAVE_DECL_SYS_SIGLIST + +void ogs_signal_init(void) +{ +} +const char *ogs_signal_description_get(int signum) +{ + return (signum >= 0) ? sys_siglist[signum] : "unknown signal (number)"; +} + +#else /* !(SYS_SIGLIST_DECLARED || HAVE_DECL_SYS_SIGLIST) */ + +/* we need to roll our own signal description stuff */ + +#if defined(NSIG) +#define OGS_NUMSIG NSIG +#elif defined(_NSIG) +#define OGS_NUMSIG _NSIG +#elif defined(__NSIG) +#define OGS_NUMSIG __NSIG +#else +#define OGS_NUMSIG 33 /* breaks on OS/390 with < 33; 32 is o.k. for most */ +#endif + +static const char *signal_description[OGS_NUMSIG]; + +#define store_desc(index, string) \ + do { \ + if (index >= OGS_NUMSIG) { \ + ogs_assert(index < OGS_NUMSIG); \ + } \ + else { \ + signal_description[index] = string; \ + } \ + } while (0) + +void ogs_signal_init(void) +{ + int sig; + + store_desc(0, "Signal 0"); + +#ifdef SIGHUP + store_desc(SIGHUP, "Hangup"); +#endif +#ifdef SIGINT + store_desc(SIGINT, "Interrupt"); +#endif +#ifdef SIGQUIT + store_desc(SIGQUIT, "Quit"); +#endif +#ifdef SIGILL + store_desc(SIGILL, "Illegal instruction"); +#endif +#ifdef SIGTRAP + store_desc(SIGTRAP, "Trace/BPT trap"); +#endif +#ifdef SIGIOT + store_desc(SIGIOT, "IOT instruction"); +#endif +#ifdef SIGABRT + store_desc(SIGABRT, "Abort"); +#endif +#ifdef SIGEMT + store_desc(SIGEMT, "Emulator trap"); +#endif +#ifdef SIGFPE + store_desc(SIGFPE, "Arithmetic exception"); +#endif +#ifdef SIGKILL + store_desc(SIGKILL, "Killed"); +#endif +#ifdef SIGBUS + store_desc(SIGBUS, "Bus error"); +#endif +#ifdef SIGSEGV + store_desc(SIGSEGV, "Segmentation fault"); +#endif +#ifdef SIGSYS + store_desc(SIGSYS, "Bad system call"); +#endif +#ifdef SIGPIPE + store_desc(SIGPIPE, "Broken pipe"); +#endif +#ifdef SIGALRM + store_desc(SIGALRM, "Alarm clock"); +#endif +#ifdef SIGTERM + store_desc(SIGTERM, "Terminated"); +#endif +#ifdef SIGUSR1 + store_desc(SIGUSR1, "User defined signal 1"); +#endif +#ifdef SIGUSR2 + store_desc(SIGUSR2, "User defined signal 2"); +#endif +#ifdef SIGCLD + store_desc(SIGCLD, "Child status change"); +#endif +#ifdef SIGCHLD + store_desc(SIGCHLD, "Child status change"); +#endif +#ifdef SIGPWR + store_desc(SIGPWR, "Power-fail restart"); +#endif +#ifdef SIGWINCH + store_desc(SIGWINCH, "Window changed"); +#endif +#ifdef SIGURG + store_desc(SIGURG, "urgent socket condition"); +#endif +#ifdef SIGPOLL + store_desc(SIGPOLL, "Pollable event occurred"); +#endif +#ifdef SIGIO + store_desc(SIGIO, "socket I/O possible"); +#endif +#ifdef SIGSTOP + store_desc(SIGSTOP, "Stopped (signal)"); +#endif +#ifdef SIGTSTP + store_desc(SIGTSTP, "Stopped"); +#endif +#ifdef SIGCONT + store_desc(SIGCONT, "Continued"); +#endif +#ifdef SIGTTIN + store_desc(SIGTTIN, "Stopped (tty input)"); +#endif +#ifdef SIGTTOU + store_desc(SIGTTOU, "Stopped (tty output)"); +#endif +#ifdef SIGVTALRM + store_desc(SIGVTALRM, "virtual timer expired"); +#endif +#ifdef SIGPROF + store_desc(SIGPROF, "profiling timer expired"); +#endif +#ifdef SIGXCPU + store_desc(SIGXCPU, "exceeded cpu limit"); +#endif +#ifdef SIGXFSZ + store_desc(SIGXFSZ, "exceeded file size limit"); +#endif + + for (sig = 0; sig < OGS_NUMSIG; ++sig) + if (signal_description[sig] == NULL) + signal_description[sig] = "unknown signal (number)"; +} + +const char *ogs_signal_description_get(int signum) +{ + return (signum >= 0 && signum < OGS_NUMSIG) + ? signal_description[signum] + : "unknown signal (number)"; +} + +#endif /* HAVE_DECL_SYS_SIGLIST */ + +#if (HAVE_SIGSUSPEND || HAVE_SIGWAIT) + +static void remove_sync_sigs(sigset_t *sig_mask) +{ +#ifdef SIGABRT + sigdelset(sig_mask, SIGABRT); +#endif +#ifdef SIGBUS + sigdelset(sig_mask, SIGBUS); +#endif +#ifdef SIGEMT + sigdelset(sig_mask, SIGEMT); +#endif +#ifdef SIGFPE + sigdelset(sig_mask, SIGFPE); +#endif +#ifdef SIGILL + sigdelset(sig_mask, SIGILL); +#endif +#ifdef SIGIOT + sigdelset(sig_mask, SIGIOT); +#endif +#ifdef SIGPIPE + sigdelset(sig_mask, SIGPIPE); +#endif +#ifdef SIGSEGV + sigdelset(sig_mask, SIGSEGV); +#endif +#ifdef SIGSYS + sigdelset(sig_mask, SIGSYS); +#endif +#ifdef SIGTRAP + sigdelset(sig_mask, SIGTRAP); +#endif + +/* the rest of the signals removed from the mask in this function + * absolutely must be removed; you cannot block synchronous signals + * (requirement of pthreads API) + */ +} + +int ogs_signal_thread(int(*signal_handler)(int signum)) +{ + sigset_t sig_mask; +#if HAVE_SIGWAIT + int (*sig_func)(int signum) = (int (*)(int))signal_handler; +#endif + + /* This thread will be the one responsible for handling signals */ + sigfillset(&sig_mask); + + /* On certain platforms, sigwait() returns EINVAL if any of various + * unblockable signals are included in the mask. This was first + * observed on AIX and Tru64. + */ +#ifdef SIGKILL + sigdelset(&sig_mask, SIGKILL); +#endif +#ifdef SIGSTOP + sigdelset(&sig_mask, SIGSTOP); +#endif +#ifdef SIGCONT + sigdelset(&sig_mask, SIGCONT); +#endif +#ifdef SIGWAITING + sigdelset(&sig_mask, SIGWAITING); +#endif + + /* no synchronous signals should be in the mask passed to sigwait() */ + remove_sync_sigs(&sig_mask); + + /* On AIX (4.3.3, at least), sigwait() won't wake up if the high- + * order bit of the second word of flags is turned on. sigdelset() + * returns an error when trying to turn this off, so we'll turn it + * off manually. + * + * Note that the private fields differ between 32-bit and 64-bit + * and even between _ALL_SOURCE and !_ALL_SOURCE. Except that on + * AIX 4.3 32-bit builds and 64-bit builds use the same definition. + * + * Applicable AIX fixes such that this is no longer needed: + * + * APAR IY23096 for AIX 51B, fix included in AIX 51C, and + * APAR IY24162 for 43X. + */ +#if defined(_AIX) +#if defined(__64BIT__) && defined(_AIXVERSION_510) +#ifdef _ALL_SOURCE + sig_mask.ss_set[3] &= 0x7FFFFFFF; +#else /* not _ALL_SOURCE */ + sig_mask.__ss_set[3] &= 0x7FFFFFFF; +#endif +#else /* not 64-bit build, or 64-bit build on 4.3 */ +#ifdef _ALL_SOURCE + sig_mask.hisigs &= 0x7FFFFFFF; +#else /* not _ALL_SOURCE */ + sig_mask.__hisigs &= 0x7FFFFFFF; +#endif +#endif +#endif /* _AIX */ + + while (1) { +#if HAVE_SIGWAIT + int signal_received; + + if (sigwait(&sig_mask, &signal_received) != 0) + { + /* handle sigwait() error here */ + } + + if (sig_func(signal_received) == 1) { + return OGS_OK; + } +#elif HAVE_SIGSUSPEND + sigsuspend(&sig_mask); +#else +#error No sigwait() and no sigsuspend() +#endif + } +} + +int ogs_setup_signal_thread(void) +{ + sigset_t sig_mask; + int rv; + + /* All threads should mask out signals to be handled by + * the thread doing sigwait(). + * + * No thread should ever block synchronous signals. + * See the Solaris man page for pthread_sigmask() for + * some information. Solaris chooses to knock out such + * processes when a blocked synchronous signal is + * delivered, skipping any registered signal handler. + * AIX doesn't call a signal handler either. At least + * one level of linux+glibc does call the handler even + * when the synchronous signal is blocked. + */ + sigfillset(&sig_mask); + remove_sync_sigs(&sig_mask); + +#if defined(SIGPROCMASK_SETS_THREAD_MASK) + if ((rv = sigprocmask(SIG_SETMASK, &sig_mask, NULL)) != 0) { + ogs_log_message(OGS_LOG_ERROR, ogs_errno, "sigprocmask() failed"); + return OGS_ERROR; + } +#else + if ((rv = pthread_sigmask(SIG_SETMASK, &sig_mask, NULL)) != 0) { + ogs_log_message(OGS_LOG_ERROR, ogs_errno, "pthread_sigmask() failed"); + return OGS_ERROR; + } +#endif + return rv; +} + +#endif + +int ogs_signal_block(int signum) +{ +#if HAVE_SIGACTION + sigset_t sig_mask; + int rv; + + sigemptyset(&sig_mask); + + sigaddset(&sig_mask, signum); + +#if defined(SIGPROCMASK_SETS_THREAD_MASK) + if ((rv = sigprocmask(SIG_BLOCK, &sig_mask, NULL)) != 0) { + ogs_log_message(OGS_LOG_ERROR, ogs_errno, "pthread_sigmask() failed"); + return OGS_ERROR; + } +#else + if ((rv = pthread_sigmask(SIG_BLOCK, &sig_mask, NULL)) != 0) { + ogs_log_message(OGS_LOG_ERROR, ogs_errno, "pthread_sigmask() failed"); + return OGS_ERROR; + } +#endif + return OGS_OK; +#else + ogs_assert_if_reached(); + return OGS_ERROR; +#endif +} + +int ogs_signal_unblock(int signum) +{ +#if HAVE_SIGACTION + sigset_t sig_mask; + int rv; + + sigemptyset(&sig_mask); + + sigaddset(&sig_mask, signum); + +#if defined(SIGPROCMASK_SETS_THREAD_MASK) || ! OGS_HAS_THREADS + if ((rv = sigprocmask(SIG_UNBLOCK, &sig_mask, NULL)) != 0) { + ogs_log_message(OGS_LOG_ERROR, ogs_errno, "pthread_sigmask() failed"); + return OGS_ERROR; + } +#else + if ((rv = pthread_sigmask(SIG_UNBLOCK, &sig_mask, NULL)) != 0) { + ogs_log_message(OGS_LOG_ERROR, ogs_errno, "pthread_sigmask() failed"); + return OGS_ERROR; + } +#endif + return OGS_OK; +#else + ogs_assert_if_reached(); + return OGS_ERROR; +#endif +} diff --git a/lib/core/ogs-signal.h b/lib/core/ogs-signal.h new file mode 100644 index 000000000..a10d1182f --- /dev/null +++ b/lib/core/ogs-signal.h @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#if !defined(OGS_CORE_INSIDE) && !defined(OGS_CORE_COMPILATION) +#error "This header cannot be included directly." +#endif + +#ifndef OGS_SIGNAL_H +#define OGS_SIGNAL_H + +#ifdef __cplusplus +extern "C" { +#endif + +#if HAVE_SIGACTION + +#if defined(__APPLE__) && !defined(__cplusplus) && !defined(_ANSI_SOURCE) +/* work around Darwin header file bugs + * http://www.opensource.apple.com/bugs/X/BSD%20Kernel/2657228.html + */ +#undef SIG_DFL +#undef SIG_IGN +#undef SIG_ERR +#define SIG_DFL (void (*)(int))0 +#define SIG_IGN (void (*)(int))1 +#define SIG_ERR (void (*)(int))-1 +#endif + +typedef void ogs_sigfunc_t(int); + +ogs_sigfunc_t *ogs_signal(int signo, ogs_sigfunc_t *func); + +#if defined(SIG_IGN) && !defined(SIG_ERR) +#define SIG_ERR ((ogs_sigfunc_t *) -1) +#endif + +#else /* !HAVE_SIGACTION */ +#define ogs_signal(a, b) signal(a, b) +#endif + + +void ogs_signal_init(void); +const char *ogs_signal_description_get(int signum); + +int ogs_setup_signal_thread(void); +int ogs_signal_thread(int(*signal_handler)(int signum)); + +int ogs_signal_block(int signum); +int ogs_signal_unblock(int signum); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* OGS_SIGNAL_H */ diff --git a/lib/core/ogs-sockaddr.c b/lib/core/ogs-sockaddr.c new file mode 100644 index 000000000..80d5200ba --- /dev/null +++ b/lib/core/ogs-sockaddr.c @@ -0,0 +1,563 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "core-config-private.h" + +#if HAVE_ARPA_INET_H +#include +#endif + +#if HAVE_CTYPE_H +#include +#endif + +#if HAVE_IFADDRS_H +#include +#endif + +#if HAVE_NETDB_H +#include +#endif + +#include "ogs-core.h" + +#undef OGS_LOG_DOMAIN +#define OGS_LOG_DOMAIN __ogs_sock_domain + +int ogs_getaddrinfo(ogs_sockaddr_t **sa_list, + int family, const char *hostname, uint16_t port, int flags) +{ + *sa_list = NULL; + return ogs_addaddrinfo(sa_list, family, hostname, port, flags); +} + +int ogs_freeaddrinfo(ogs_sockaddr_t *sa_list) +{ + ogs_sockaddr_t *next = NULL, *addr = NULL; + + addr = sa_list; + while (addr) { + next = addr->next; + ogs_free(addr); + addr = next; + } + + return OGS_OK; +} + +int ogs_addaddrinfo(ogs_sockaddr_t **sa_list, + int family, const char *hostname, uint16_t port, int flags) +{ + int rc; + char service[NI_MAXSERV]; + struct addrinfo hints, *ai, *ai_list; + ogs_sockaddr_t *prev; + char buf[OGS_ADDRSTRLEN]; + + ogs_assert(sa_list); + + memset(&hints, 0, sizeof(hints)); + hints.ai_family = family; + hints.ai_socktype = SOCK_STREAM; + hints.ai_flags = flags; + + ogs_snprintf(service, sizeof(service), "%u", port); + + rc = getaddrinfo(hostname, service, &hints, &ai_list); + if (rc != 0) { + ogs_log_message(OGS_LOG_ERROR, ogs_socket_errno, + "getaddrinfo(%d:%s:%d:0x%x) failed", + family, hostname, port, flags); + return OGS_ERROR; + } + + prev = NULL; + if (*sa_list) { + prev = *sa_list; + while(prev->next) prev = prev->next; + } + for (ai = ai_list; ai; ai = ai->ai_next) { + ogs_sockaddr_t *new; + if (ai->ai_family != AF_INET && ai->ai_family != AF_INET6) + continue; + + new = ogs_calloc(1, sizeof(ogs_sockaddr_t)); + memcpy(&new->sa, ai->ai_addr, ai->ai_addrlen); + new->ogs_sin_port = htobe16(port); + ogs_trace("addr:%s, port:%d", OGS_ADDR(new, buf), port); + + if (!prev) + *sa_list = new; + else + prev->next = new; + + prev = new; + } + + freeaddrinfo(ai_list); + + if (prev == NULL) { + ogs_log_message(OGS_LOG_ERROR, ogs_socket_errno, + "ogs_getaddrinfo(%d:%s:%d:%d) failed", + family, hostname, port, flags); + return OGS_ERROR; + } + + return OGS_OK; +} + +int ogs_filteraddrinfo(ogs_sockaddr_t **sa_list, int family) +{ + ogs_sockaddr_t *addr = NULL, *prev = NULL, *next = NULL; + + ogs_assert(sa_list); + + prev = NULL; + addr = *sa_list; + while (addr) { + next = addr->next; + + if (addr->ogs_sa_family != family) { + if (prev) + prev->next = addr->next; + else + *sa_list = addr->next; + ogs_free(addr); + + } else { + prev = addr; + } + + addr = next; + } + + return OGS_OK; +} + +int ogs_copyaddrinfo(ogs_sockaddr_t **dst, const ogs_sockaddr_t *src) +{ + ogs_sockaddr_t *d; + const ogs_sockaddr_t *s; + + for (*dst = d = NULL, s = src; s; s = s->next) + { + if (!d) + { + d = ogs_calloc(1, sizeof *s); + *dst = memcpy(d, s, sizeof *s); + } + else + { + d->next = ogs_calloc(1, sizeof(ogs_sockaddr_t)); + d = memcpy(d->next, s, sizeof *s); + } + } + return OGS_OK; +} + +int ogs_sortaddrinfo(ogs_sockaddr_t **sa_list, int family) +{ + ogs_sockaddr_t *head = NULL, *addr = NULL, *new = NULL, *old = NULL; + + ogs_assert(sa_list); + + old = *sa_list; + while (old) { + addr = old; + + old = old->next; + + if (head == NULL || addr->ogs_sa_family == family) { + addr->next = head; + head = addr; + } else { + new = head; + while(new->next != NULL && new->next->ogs_sa_family != family) { + new = new->next; + } + addr->next = new->next; + new->next = addr; + } + } + + *sa_list = head; + + return OGS_OK; +} + +ogs_sockaddr_t *ogs_link_local_addr_by_dev(const char *dev) +{ +#if defined(HAVE_GETIFADDRS) + struct ifaddrs *iflist, *cur; + int rc; + + ogs_assert(dev); + + rc = getifaddrs(&iflist); + if (rc != 0) { + ogs_log_message(OGS_LOG_ERROR, ogs_socket_errno, "getifaddrs failed"); + return NULL; + } + + for (cur = iflist; cur != NULL; cur = cur->ifa_next) { + ogs_sockaddr_t *addr = NULL; + + if (cur->ifa_addr == NULL) /* may happen with ppp interfaces */ + continue; + + if (strcmp(dev, cur->ifa_name) != 0) + continue; + + if (cur->ifa_addr->sa_family == AF_INET) + continue; + + addr = (ogs_sockaddr_t *)cur->ifa_addr; + if (!IN6_IS_ADDR_LINKLOCAL(&addr->sin6.sin6_addr)) + continue; + + addr = ogs_calloc(1, sizeof(ogs_sockaddr_t)); + ogs_assert(addr); + memcpy(&addr->sa, cur->ifa_addr, ogs_sockaddr_len(cur->ifa_addr)); + + freeifaddrs(iflist); + return addr; + } + + freeifaddrs(iflist); +#endif + return NULL; +} + +int ogs_filter_ip_version(ogs_sockaddr_t **addr, + int no_ipv4, int no_ipv6, int prefer_ipv4) +{ + int rv; + + if (no_ipv4 == 1) { + rv = ogs_filteraddrinfo(addr, AF_INET6); + ogs_assert(rv == OGS_OK); + } + if (no_ipv6 == 1) { + rv = ogs_filteraddrinfo(addr, AF_INET); + ogs_assert(rv == OGS_OK); + } + + if (prefer_ipv4 == 1) { + rv = ogs_sortaddrinfo(addr, AF_INET); + ogs_assert(rv == OGS_OK); + } else { + rv = ogs_sortaddrinfo(addr, AF_INET6); + ogs_assert(rv == OGS_OK); + } + + return OGS_OK; +} + + +const char *ogs_inet_ntop(void *sa, char *buf, int buflen) +{ + int family; + ogs_sockaddr_t *sockaddr = NULL; + + sockaddr = sa; + ogs_assert(sockaddr); + ogs_assert(buf); + ogs_assert(buflen >= OGS_ADDRSTRLEN); + + family = sockaddr->ogs_sa_family; + switch(family) { + case AF_INET: + return inet_ntop(family, &sockaddr->sin.sin_addr, buf, + INET_ADDRSTRLEN); + case AF_INET6: + return inet_ntop(family, &sockaddr->sin6.sin6_addr, buf, + INET6_ADDRSTRLEN); + default: + ogs_fatal("Unknown family(%d)", family); + ogs_abort(); + return NULL; + } +} + +int ogs_inet_pton(int family, const char *src, void *sa) +{ + ogs_sockaddr_t *dst = NULL; + + ogs_assert(src); + dst = sa; + ogs_assert(dst); + + dst->ogs_sa_family = family; + switch(family) { + case AF_INET: + return inet_pton(family, src, &dst->sin.sin_addr) == 1 ? + OGS_OK : OGS_ERROR; + case AF_INET6: + return inet_pton(family, src, &dst->sin6.sin6_addr) == 1 ? + OGS_OK : OGS_ERROR; + default: + ogs_fatal("Unknown family(%d)", family); + ogs_abort(); + return OGS_ERROR; + } +} + +socklen_t ogs_sockaddr_len(const void *sa) +{ + const ogs_sockaddr_t *sockaddr = sa; + + ogs_assert(sa); + + switch(sockaddr->ogs_sa_family) { + case AF_INET: + return sizeof(struct sockaddr_in); + case AF_INET6: + return sizeof(struct sockaddr_in6); + default: + ogs_fatal("Unknown family(%d)", sockaddr->ogs_sa_family); + ogs_abort(); + return OGS_ERROR; + } +} + +bool ogs_sockaddr_is_equal(void *p, void *q) +{ + ogs_sockaddr_t *a, *b; + + a = p; + ogs_assert(a); + b = q; + ogs_assert(b); + + if (a->ogs_sa_family != b->ogs_sa_family) + return false; + + if (a->ogs_sa_family == AF_INET && memcmp( + &a->sin.sin_addr, &b->sin.sin_addr, sizeof(struct in_addr)) == 0) + return true; + else if (a->ogs_sa_family == AF_INET6 && memcmp( + &a->sin6.sin6_addr, &b->sin6.sin6_addr, sizeof(struct in6_addr)) == 0) + return true; + else { + ogs_fatal("Unknown family(%d)", a->ogs_sa_family); + ogs_abort(); + } + + return false; +} + +static int parse_network(ogs_ipsubnet_t *ipsub, const char *network) +{ + /* legacy syntax for ip addrs: a.b.c. ==> a.b.c.0/24 for example */ + int shift; + char *s, *t; + int octet; + char buf[sizeof "255.255.255.255"]; + + if (strlen(network) < sizeof buf) + strcpy(buf, network); + else + return OGS_ERROR; + + /* parse components */ + s = buf; + ipsub->sub[0] = 0; + ipsub->mask[0] = 0; + shift = 24; + while (*s) { + t = s; + if (!isdigit(*t)) + return OGS_ERROR; + + while (isdigit(*t)) + ++t; + + if (*t == '.') + *t++ = 0; + else if (*t) + return OGS_ERROR; + + if (shift < 0) + return OGS_ERROR; + + octet = atoi(s); + if (octet < 0 || octet > 255) + return OGS_ERROR; + + ipsub->sub[0] |= octet << shift; + ipsub->mask[0] |= 0xFFUL << shift; + s = t; + shift -= 8; + } + ipsub->sub[0] = be32toh(ipsub->sub[0]); + ipsub->mask[0] = be32toh(ipsub->mask[0]); + ipsub->family = AF_INET; + + return OGS_OK; +} + +/* return values: + * CORE_EINVAL not an IP address; caller should see + * if it is something else + * CORE_BADIP IP address portion is is not valid + * CORE_BADMASK mask portion is not valid + */ +static int parse_ip( + ogs_ipsubnet_t *ipsub, const char *ipstr, int network_allowed) +{ + /* supported flavors of IP: + * + * . IPv6 numeric address string (e.g., "fe80::1") + * + * IMPORTANT: Don't store IPv4-mapped IPv6 address as an IPv6 address. + * + * . IPv4 numeric address string (e.g., "127.0.0.1") + * + * . IPv4 network string (e.g., "9.67") + * + * IMPORTANT: This network form is only allowed if network_allowed is on. + */ + int rc; + + rc = inet_pton(AF_INET6, ipstr, ipsub->sub); + if (rc == 1) { + if (IN6_IS_ADDR_V4MAPPED((struct in6_addr *)ipsub->sub)) { + /* ipsubnet_test() assumes that we don't create IPv4-mapped IPv6 + * addresses; this of course forces the user to specify + * IPv4 addresses in a.b.c.d style instead of ::ffff:a.b.c.d style. + */ + ogs_error("Cannot support IPv4-mapped IPv6: " + "Use IPv4 address in a.b.c.d style " + "instead of ::ffff:a.b.c.d style"); + return OGS_ERROR; + } + ipsub->family = AF_INET6; + } else { + rc = inet_pton(AF_INET, ipstr, ipsub->sub); + if (rc == 1) { + ipsub->family = AF_INET; + } + } + + if (rc != 1) { + if (network_allowed) + return parse_network(ipsub, ipstr); + else + return OGS_ERROR; + } + return OGS_OK; +} + +static int looks_like_ip(const char *ipstr) +{ + if (strlen(ipstr) == 0) + return 0; + + if (strchr(ipstr, ':')) { + /* definitely not a hostname; + * assume it is intended to be an IPv6 address */ + return 1; + } + + /* simple IPv4 address string check */ + while ((*ipstr == '.') || isdigit(*ipstr)) + ipstr++; + + return (*ipstr == '\0'); +} + +static void fix_subnet(ogs_ipsubnet_t *ipsub) +{ + /* in case caller specified more bits in network address than are + * valid according to the mask, turn off the extra bits + */ + int i; + + for (i = 0; i < sizeof ipsub->mask / sizeof(int32_t); i++) + ipsub->sub[i] &= ipsub->mask[i]; +} + +/* be sure not to store any IPv4 address as a v4-mapped IPv6 address */ +int ogs_ipsubnet(ogs_ipsubnet_t *ipsub, + const char *ipstr, const char *mask_or_numbits) +{ + int rv; + char *endptr; + long bits, maxbits = 32; + + ogs_assert(ipsub); + ogs_assert(ipstr); + + /* filter out stuff which doesn't look remotely like an IP address; + * this helps callers like mod_access which have a syntax allowing + * hostname or IP address; + * CORE_EINVAL tells the caller that it was probably not intended + * to be an IP address + */ + if (!looks_like_ip(ipstr)) { + ogs_error("looks_like_ip() is failed"); + return OGS_ERROR; + } + + /* assume ipstr is an individual IP address, not a subnet */ + memset(ipsub->mask, 0xFF, sizeof ipsub->mask); + + rv = parse_ip(ipsub, ipstr, mask_or_numbits == NULL); + if (rv != OGS_OK) { + ogs_error("parse_ip() is failed"); + return rv; + } + + if (mask_or_numbits) { + if (ipsub->family == AF_INET6) { + maxbits = 128; + } + bits = strtol(mask_or_numbits, &endptr, 10); + if (*endptr == '\0' && bits > 0 && bits <= maxbits) { + /* valid num-bits string; fill in mask appropriately */ + int cur_entry = 0; + int32_t cur_bit_value; + + memset(ipsub->mask, 0, sizeof ipsub->mask); + while (bits > 32) { + ipsub->mask[cur_entry] = 0xFFFFFFFF; /* all 32 bits */ + bits -= 32; + ++cur_entry; + } + cur_bit_value = 0x80000000; + while (bits) { + ipsub->mask[cur_entry] |= cur_bit_value; + --bits; + cur_bit_value /= 2; + } + ipsub->mask[cur_entry] = htobe32(ipsub->mask[cur_entry]); + } + else if (inet_pton(AF_INET, mask_or_numbits, ipsub->mask) == 1 && + ipsub->family == AF_INET) { + /* valid IPv4 netmask */ + } else { + ogs_error("Bad netmask"); + return OGS_ERROR; + } + } + + fix_subnet(ipsub); + + return OGS_OK; +} diff --git a/lib/core/ogs-sockaddr.h b/lib/core/ogs-sockaddr.h new file mode 100644 index 000000000..a6536729b --- /dev/null +++ b/lib/core/ogs-sockaddr.h @@ -0,0 +1,96 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#if !defined(OGS_CORE_INSIDE) && !defined(OGS_CORE_COMPILATION) +#error "This header cannot be included directly." +#endif + +#ifndef OGS_SOCKADDR_H +#define OGS_SOCKADDR_H + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct ogs_sockaddr_s ogs_sockaddr_t; +struct ogs_sockaddr_s { + /* Reserved Area + * - Should not add any atrribute in this area. + * + * e.g) + * struct sockaddr addr; + * ... + * sockaddr_len((ogs_sockaddr_t *)&addr); + */ +#define ogs_sa_family sa.sa_family +#define ogs_sin_port sin.sin_port + union { + struct sockaddr_storage ss; + struct sockaddr_in sin; + struct sockaddr_in6 sin6; + struct sockaddr sa; + }; + + /* User Area + * - Could add your attribute. + */ + ogs_sockaddr_t *next; +}; + +typedef struct ogs_ipsubnet_s { + int family; + + uint32_t sub[4]; /* big enough for IPv4 and IPv6 addresses */ + uint32_t mask[4]; +} ogs_ipsubnet_t; + +int ogs_getaddrinfo(ogs_sockaddr_t **sa_list, + int family, const char *hostname, uint16_t port, int flags); +int ogs_freeaddrinfo(ogs_sockaddr_t *sa_list); + +int ogs_addaddrinfo(ogs_sockaddr_t **sa_list, + int family, const char *hostname, uint16_t port, int flags); +int ogs_copyaddrinfo( + ogs_sockaddr_t **dst, const ogs_sockaddr_t *src); +int ogs_filteraddrinfo(ogs_sockaddr_t **sa_list, int family); +int ogs_sortaddrinfo(ogs_sockaddr_t **sa_list, int family); + +ogs_sockaddr_t *ogs_link_local_addr_by_dev(const char *dev); +int ogs_filter_ip_version(ogs_sockaddr_t **addr, + int no_ipv4, int no_ipv6, int prefer_ipv4); + +#define OGS_ADDRSTRLEN INET6_ADDRSTRLEN +#define OGS_ADDR(__aDDR, __bUF) \ + ogs_inet_ntop(__aDDR, __bUF, OGS_ADDRSTRLEN) +#define OGS_PORT(__aDDR) \ + be16toh((__aDDR)->ogs_sin_port) +const char *ogs_inet_ntop(void *addr, char *buf, int buflen); +int ogs_inet_pton(int family, const char *src, void *addr); + +socklen_t ogs_sockaddr_len(const void *addr); +bool ogs_sockaddr_is_equal(void *p, void *q); + +int ogs_ipsubnet(ogs_ipsubnet_t *ipsub, + const char *ipstr, const char *mask_or_numbits); + +#ifdef __cplusplus +} +#endif + +#endif /* OGS_SOCKADDR_H */ diff --git a/lib/core/ogs-socket.c b/lib/core/ogs-socket.c new file mode 100644 index 000000000..d22597bcd --- /dev/null +++ b/lib/core/ogs-socket.c @@ -0,0 +1,380 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "core-config-private.h" + +#if HAVE_FCNTL_H +#include +#endif + +#if HAVE_UNISTD_H +#include +#endif + +#include "ogs-core.h" + +#undef OGS_LOG_DOMAIN +#define OGS_LOG_DOMAIN __ogs_sock_domain + +void ogs_socket_init(void) +{ +#if _WIN32 + WORD wVersionRequested; + WSADATA wsaData; + int err; + + wVersionRequested = MAKEWORD(2, 2); + + err = WSAStartup(wVersionRequested, &wsaData); + ogs_assert(err == 0); +#endif +} + +void ogs_socket_final(void) +{ +} + +ogs_sock_t *ogs_sock_create(void) +{ + ogs_sock_t *sock = NULL; + + sock = ogs_calloc(1, sizeof(*sock)); + ogs_assert(sock); + + sock->fd = INVALID_SOCKET; + + return sock; +} + +void ogs_sock_destroy(ogs_sock_t *sock) +{ + ogs_assert(sock); + + if (sock->fd != INVALID_SOCKET) { + ogs_closesocket(sock->fd); + } + sock->fd = INVALID_SOCKET; + + ogs_free(sock); +} + +ogs_sock_t *ogs_sock_socket(int family, int type, int protocol) +{ + ogs_sock_t *sock = NULL; + + sock = ogs_sock_create(); + ogs_assert(sock); + + sock->family = family; + sock->fd = socket(sock->family, type, protocol); + if (sock->fd < 0) { + ogs_log_message(OGS_LOG_ERROR, ogs_socket_errno, + "socket create(%d:%d:%d) failed", sock->family, type, protocol); + return NULL; + } + + ogs_debug("socket create(%d:%d:%d)", sock->family, type, protocol); + + return sock; +} + +int ogs_sock_bind(ogs_sock_t *sock, ogs_sockaddr_t *addr) +{ + char buf[OGS_ADDRSTRLEN]; + socklen_t addrlen; + + ogs_assert(sock); + ogs_assert(addr); + + addrlen = ogs_sockaddr_len(addr); + ogs_assert(addrlen); + + if (bind(sock->fd, &addr->sa, addrlen) != 0) { + ogs_log_message(OGS_LOG_ERROR, ogs_socket_errno, + "socket bind(%d) [%s]:%d failed", + addr->ogs_sa_family, OGS_ADDR(addr, buf), OGS_PORT(addr)); + return OGS_ERROR; + } + + memcpy(&sock->local_addr, addr, sizeof(sock->local_addr)); + + ogs_debug("socket bind %s:%d", OGS_ADDR(addr, buf), OGS_PORT(addr)); + + return OGS_OK; +} + +int ogs_sock_connect(ogs_sock_t *sock, ogs_sockaddr_t *addr) +{ + char buf[OGS_ADDRSTRLEN]; + socklen_t addrlen; + + ogs_assert(sock); + ogs_assert(addr); + + addrlen = ogs_sockaddr_len(addr); + ogs_assert(addrlen); + + if (connect(sock->fd, &addr->sa, addrlen) != 0) { + ogs_log_message(OGS_LOG_ERROR, ogs_socket_errno, + "socket connect[%s]:%d failed", + OGS_ADDR(addr, buf), OGS_PORT(addr)); + return OGS_ERROR; + } + + memcpy(&sock->remote_addr, addr, sizeof(sock->remote_addr)); + + ogs_debug("socket connect %s:%d\n", OGS_ADDR(addr, buf), OGS_PORT(addr)); + + return OGS_OK; +} + +int ogs_sock_listen(ogs_sock_t *sock) +{ + int rc; + ogs_assert(sock); + + rc = listen(sock->fd, 5); + if (rc < 0) { + ogs_log_message(OGS_LOG_ERROR, ogs_socket_errno, "listen failed"); + return OGS_ERROR; + } + + return OGS_OK; +} + +ogs_sock_t *ogs_sock_accept(ogs_sock_t *sock) +{ + ogs_sock_t *new_sock = NULL; + + int new_fd = -1; + ogs_sockaddr_t addr; + socklen_t addrlen; + + ogs_assert(sock); + + memset(&addr, 0, sizeof(addr)); + addrlen = sizeof(addr.ss); + + new_fd = accept(sock->fd, &addr.sa, &addrlen); + if (new_fd < 0) { + ogs_log_message(OGS_LOG_ERROR, ogs_socket_errno, "accept failed"); + return NULL; + } + + new_sock = ogs_sock_create(); + ogs_assert(new_sock); + + new_sock->family = sock->family; + new_sock->fd = new_fd; + + memcpy(&new_sock->remote_addr, &addr, sizeof(new_sock->remote_addr)); + + return new_sock;; +} + +ssize_t ogs_write(ogs_socket_t fd, const void *buf, size_t len) +{ + ssize_t size; + + ogs_assert(fd != INVALID_SOCKET); + + size = write(fd, buf, len); + if (size < 0) { + ogs_log_message(OGS_LOG_ERROR, ogs_socket_errno, + "ogs_write(len:%d) failed", (int)size); + } + + return size; +} + +ssize_t ogs_read(ogs_socket_t fd, void *buf, size_t len) +{ + ssize_t size; + + ogs_assert(fd != INVALID_SOCKET); + + size = read(fd, buf, len); + if (size < 0) { + ogs_log_message(OGS_LOG_ERROR, ogs_socket_errno, + "ogs_read(len:%d) failed", (int)size); + } + + return size; +} + +ssize_t ogs_send(ogs_socket_t fd, const void *buf, size_t len, int flags) +{ + ssize_t size; + + ogs_assert(fd != INVALID_SOCKET); + + size = send(fd, buf, len, flags); + if (size < 0) { + ogs_log_message(OGS_LOG_ERROR, ogs_socket_errno, + "send(len:%d) failed", (int)len); + } + + return size; +} + +ssize_t ogs_sendto(ogs_socket_t fd, + const void *buf, size_t len, int flags, const ogs_sockaddr_t *to) +{ + ssize_t size; + socklen_t addrlen; + + ogs_assert(fd != INVALID_SOCKET); + ogs_assert(to); + + addrlen = ogs_sockaddr_len(to); + ogs_assert(addrlen); + + size = sendto(fd, buf, len, flags, &to->sa, addrlen); + if (size < 0) { + ogs_log_message(OGS_LOG_ERROR, ogs_socket_errno, + "sendto(len:%d) failed", (int)len); + } + + return size; +} + +ssize_t ogs_recv(ogs_socket_t fd, void *buf, size_t len, int flags) +{ + ssize_t size; + + ogs_assert(fd != INVALID_SOCKET); + + size = recv(fd, buf, len, flags); + if (size < 0) { + ogs_log_message(OGS_LOG_ERROR, ogs_socket_errno, + "recv(len:%d) failed", (int)len); + } + + return size; +} + +ssize_t ogs_recvfrom(ogs_socket_t fd, + void *buf, size_t len, int flags, ogs_sockaddr_t *from) +{ + ssize_t size; + socklen_t addrlen = sizeof(struct sockaddr_storage); + + ogs_assert(fd != INVALID_SOCKET); + ogs_assert(from); + + size = recvfrom(fd, buf, len, flags, &from->sa, &addrlen); + if (size < 0) { + ogs_log_message(OGS_LOG_ERROR, ogs_socket_errno, + "recvfrom(len:%d) failed", (int)len); + } + + return size; +} + +int ogs_closesocket(ogs_socket_t fd) +{ + int r; +#ifdef _WIN32 + r = closesocket(fd); +#else + r = close(fd); +#endif + if (r != 0) { + ogs_log_message(OGS_LOG_ERROR, ogs_socket_errno, "closesocket failed"); + return OGS_ERROR; + } + + return OGS_OK; +} + +int ogs_nonblocking(ogs_socket_t fd) +{ +#ifdef _WIN32 + int rc; + ogs_assert(fd != INVALID_SOCKET); + + u_long io_mode = 1; + rc = ioctlsocket(fd, FIONBIO, &io_mode); + if (rc != OGS_OK) { + ogs_log_message(OGS_LOG_ERROR, ogs_socket_errno, "ioctlsocket failed"); + return OGS_ERROR; + } +#else + int rc; + int flags; + ogs_assert(fd != INVALID_SOCKET); + + flags = fcntl(fd, F_GETFL, NULL); + if (flags < 0) { + ogs_log_message(OGS_LOG_ERROR, ogs_socket_errno, "F_GETFL failed"); + return OGS_ERROR; + } + if (!(flags & O_NONBLOCK)) { + rc = fcntl(fd, F_SETFL, (flags | O_NONBLOCK)); + if (rc != OGS_OK) { + ogs_log_message(OGS_LOG_ERROR, ogs_socket_errno, "F_SETFL failed"); + return OGS_ERROR; + } + } +#endif + + return OGS_OK; +} + +int ogs_closeonexec(ogs_socket_t fd) +{ +#ifndef _WIN32 + int rc; + int flags; + + ogs_assert(fd != INVALID_SOCKET); + flags = fcntl(fd, F_GETFL, NULL); + if (flags < 0) { + ogs_log_message(OGS_LOG_ERROR, ogs_socket_errno, "F_GETFL failed"); + return OGS_ERROR; + } + if (!(flags & FD_CLOEXEC)) { + rc = fcntl(fd, F_SETFL, (flags | FD_CLOEXEC)); + if (rc != OGS_OK) { + ogs_log_message(OGS_LOG_ERROR, ogs_socket_errno, "F_SETFL failed"); + return OGS_ERROR; + } + } +#endif + + return OGS_OK; +} + +int ogs_listen_reusable(ogs_socket_t fd) +{ +#if defined(SO_REUSEADDR) && !defined(_WIN32) + int rc; + int on = 1; + + ogs_assert(fd != INVALID_SOCKET); + rc = setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (void *)&on, sizeof(int)); + if (rc != OGS_OK) { + ogs_log_message(OGS_LOG_ERROR, ogs_socket_errno, + "setsockopt(SOL_SOCKET, SO_REUSEADDR) failed"); + return OGS_ERROR; + } +#endif + + return OGS_OK; +} diff --git a/lib/core/ogs-socket.h b/lib/core/ogs-socket.h new file mode 100644 index 000000000..8294b3c07 --- /dev/null +++ b/lib/core/ogs-socket.h @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#if !defined(OGS_CORE_INSIDE) && !defined(OGS_CORE_COMPILATION) +#error "This header cannot be included directly." +#endif + +#ifndef OGS_SOCKET_H +#define OGS_SOCKET_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef _WIN32 +typedef SOCKET ogs_socket_t; +#else +typedef int ogs_socket_t; +#endif + +#if !defined(_WIN32) && !defined(INVALID_SOCKET) +#define INVALID_SOCKET -1 +#endif + +typedef struct ogs_sock_s { + int family; + ogs_socket_t fd; + + ogs_sockaddr_t local_addr; + ogs_sockaddr_t remote_addr; +} ogs_sock_t; + +void ogs_socket_init(void); +void ogs_socket_final(void); + +ogs_sock_t *ogs_sock_create(void); +void ogs_sock_destroy(ogs_sock_t *sock); + +ogs_sock_t *ogs_sock_socket(int family, int type, int protocol); +int ogs_sock_bind(ogs_sock_t *sock, ogs_sockaddr_t *addr); +int ogs_sock_connect(ogs_sock_t *sock, ogs_sockaddr_t *addr); + +int ogs_sock_listen(ogs_sock_t *sock); +ogs_sock_t *ogs_sock_accept(ogs_sock_t *sock); + +ssize_t ogs_write(ogs_socket_t fd, const void *buf, size_t len); +ssize_t ogs_read(ogs_socket_t fd, void *buf, size_t len); + +ssize_t ogs_send(ogs_socket_t fd, const void *buf, size_t len, int flags); +ssize_t ogs_sendto(ogs_socket_t fd, + const void *buf, size_t len, int flags, const ogs_sockaddr_t *to); +ssize_t ogs_recv(ogs_socket_t fd, void *buf, size_t len, int flags); +ssize_t ogs_recvfrom(ogs_socket_t fd, + void *buf, size_t len, int flags, ogs_sockaddr_t *from); + +int ogs_closesocket(ogs_socket_t fd); + +int ogs_nonblocking(ogs_socket_t fd); +int ogs_closeonexec(ogs_socket_t fd); +int ogs_listen_reusable(ogs_socket_t fd); + +#ifdef __cplusplus +} +#endif + +#endif /* OGS_SOCKET_H */ diff --git a/lib/core/ogs-socknode.c b/lib/core/ogs-socknode.c new file mode 100644 index 000000000..d29789340 --- /dev/null +++ b/lib/core/ogs-socknode.c @@ -0,0 +1,324 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "core-config-private.h" + +#if HAVE_NET_IF_H +#include +#endif + +#if HAVE_IFADDRS_H +#include +#endif + +#include "ogs-core.h" + +#undef OGS_LOG_DOMAIN +#define OGS_LOG_DOMAIN __ogs_sock_domain + +ogs_socknode_t *ogs_socknode_new(ogs_sockaddr_t *addr) +{ + ogs_socknode_t *node = NULL; + + ogs_assert(addr); + + node = ogs_calloc(1, sizeof(ogs_socknode_t)); + ogs_assert(node); + + node->addr = addr; + + return node; +} + +void ogs_socknode_free(ogs_socknode_t *node) +{ + ogs_assert(node); + + ogs_freeaddrinfo(node->addr); + if (node->pollin.poll) + ogs_pollset_remove(node->pollin.poll); + if (node->pollout.poll) + ogs_pollset_remove(node->pollout.poll); + if (node->sock) { + if (node->cleanup) + node->cleanup(node->sock); + else + ogs_sock_destroy(node->sock); + } + ogs_free(node); +} + +ogs_socknode_t *ogs_socknode_add( + ogs_list_t *list, int family, ogs_sockaddr_t *addr) +{ + int rv; + ogs_socknode_t *node = NULL; + + ogs_assert(list); + ogs_assert(addr); + + if (family != AF_UNSPEC) { + rv = ogs_filteraddrinfo(&addr, family); + ogs_assert(rv == OGS_OK); + } + + if (addr) { + node = ogs_calloc(1, sizeof(ogs_socknode_t)); + ogs_assert(node); + + node->addr = addr; + + ogs_list_add(list, node); + } + + return node; +} + +void ogs_socknode_remove(ogs_list_t *list, ogs_socknode_t *node) +{ + ogs_assert(node); + + ogs_list_remove(list, node); + ogs_socknode_free(node); +} + +void ogs_socknode_remove_all(ogs_list_t *list) +{ + ogs_socknode_t *node = NULL, *saved_node = NULL; + + ogs_list_for_each_safe(list, saved_node, node) + ogs_socknode_remove(list, node); +} + +int ogs_socknode_probe( + ogs_list_t *list, ogs_list_t *list6, const char *dev, uint16_t port) +{ +#if defined(HAVE_GETIFADDRS) + ogs_socknode_t *node = NULL; + struct ifaddrs *iflist, *cur; + int rc; + + rc = getifaddrs(&iflist); + if (rc != 0) { + ogs_log_message(OGS_LOG_ERROR, ogs_socket_errno, "getifaddrs failed"); + return OGS_ERROR; + } + + for (cur = iflist; cur != NULL; cur = cur->ifa_next) { + ogs_sockaddr_t *addr = NULL; + + if (cur->ifa_flags & IFF_LOOPBACK) + continue; + + if (cur->ifa_flags & IFF_POINTOPOINT) + continue; + + if (cur->ifa_addr == NULL) /* may happen with ppp interfaces */ + continue; + + if (dev && strcmp(dev, cur->ifa_name) != 0) + continue; + + addr = (ogs_sockaddr_t *)cur->ifa_addr; + if (cur->ifa_addr->sa_family == AF_INET) { + if (!list) continue; + +#ifndef IN_IS_ADDR_LOOPBACK +#define IN_IS_ADDR_LOOPBACK(a) \ + ((((long int) (a)->s_addr) & be32toh(0xff000000)) == be32toh(0x7f000000)) +#endif /* IN_IS_ADDR_LOOPBACK */ + +/* An IP equivalent to IN6_IS_ADDR_UNSPECIFIED */ +#ifndef IN_IS_ADDR_UNSPECIFIED +#define IN_IS_ADDR_UNSPECIFIED(a) \ + (((long int) (a)->s_addr) == 0x00000000) +#endif /* IN_IS_ADDR_UNSPECIFIED */ + if (IN_IS_ADDR_UNSPECIFIED(&addr->sin.sin_addr) || + IN_IS_ADDR_LOOPBACK(&addr->sin.sin_addr)) + continue; + } else if (cur->ifa_addr->sa_family == AF_INET6) { + if (!list6) continue; + + if (IN6_IS_ADDR_UNSPECIFIED(&addr->sin6.sin6_addr) || + IN6_IS_ADDR_LOOPBACK(&addr->sin6.sin6_addr) || + IN6_IS_ADDR_MULTICAST(&addr->sin6.sin6_addr) || + IN6_IS_ADDR_LINKLOCAL(&addr->sin6.sin6_addr) || + IN6_IS_ADDR_SITELOCAL(&addr->sin6.sin6_addr)) + continue; + } else + continue; + + addr = ogs_calloc(1, sizeof(ogs_sockaddr_t)); + memcpy(&addr->sa, cur->ifa_addr, ogs_sockaddr_len(cur->ifa_addr)); + addr->ogs_sin_port = htobe16(port); + + node = ogs_calloc(1, sizeof(ogs_socknode_t)); + node->addr = addr; + + if (addr->ogs_sa_family == AF_INET) { + ogs_assert(list); + ogs_list_add(list, node); + } else if (addr->ogs_sa_family == AF_INET6) { + ogs_assert(list6); + ogs_list_add(list6, node); + } else + ogs_assert_if_reached(); + } + + freeifaddrs(iflist); + return OGS_OK; +#elif defined(_WIN32) + return OGS_OK; +#else + ogs_assert_if_reached(); + return OGS_ERROR; +#endif + +} + +int ogs_socknode_fill_scope_id_in_local(ogs_sockaddr_t *sa_list) +{ +#if defined(HAVE_GETIFADDRS) + struct ifaddrs *iflist = NULL, *cur; + int rc; + ogs_sockaddr_t *addr, *ifaddr; + + for (addr = sa_list; addr != NULL; addr = addr->next) { + if (addr->ogs_sa_family != AF_INET6) + continue; + + if (!IN6_IS_ADDR_LINKLOCAL(&addr->sin6.sin6_addr)) + continue; + + if (addr->sin6.sin6_scope_id != 0) + continue; + + if (iflist == NULL) { + rc = getifaddrs(&iflist); + if (rc != 0) { + ogs_log_message(OGS_LOG_ERROR, ogs_socket_errno, + "getifaddrs failed"); + return OGS_ERROR; + } + } + + for (cur = iflist; cur != NULL; cur = cur->ifa_next) { + ifaddr = (ogs_sockaddr_t *)cur->ifa_addr; + + if (cur->ifa_addr == NULL) /* may happen with ppp interfaces */ + continue; + + if (cur->ifa_addr->sa_family != AF_INET6) + continue; + + if (!IN6_IS_ADDR_LINKLOCAL(&ifaddr->sin6.sin6_addr)) + continue; + + if (memcmp(&addr->sin6.sin6_addr, + &ifaddr->sin6.sin6_addr, sizeof(struct in6_addr)) == 0) { + /* Fill Scope ID in localhost */ + addr->sin6.sin6_scope_id = ifaddr->sin6.sin6_scope_id; + } + } + } + + if (iflist) + freeifaddrs(iflist); + + return OGS_OK; +#elif defined(_WIN32) + return OGS_OK; +#else + ogs_assert_if_reached(); + return OGS_ERROR; +#endif +} + +void ogs_socknode_sctp_option(ogs_socknode_t *node, ogs_sockopt_t *option) +{ + ogs_assert(node); + ogs_assert(option); + + memcpy(&node->option.sctp, &option->sctp, sizeof(option->sctp)); +} + +void ogs_socknode_nodelay(ogs_socknode_t *node, int on) +{ + ogs_assert(node); + node->option.nodelay = on; +} + +void ogs_socknode_linger(ogs_socknode_t *node, int onoff, int linger) +{ + ogs_assert(node); + node->option.l_onoff = onoff; + node->option.l_linger = linger; +} + +void ogs_socknode_set_cleanup( + ogs_socknode_t *node, void (*cleanup)(ogs_sock_t *)) +{ + ogs_assert(node); + ogs_assert(cleanup); + + node->cleanup = cleanup; +} + +void ogs_socknode_set_poll(ogs_socknode_t *node, + ogs_pollset_t *set, short when, void *handler, void *data) +{ + ogs_assert(node); + ogs_assert(set); + ogs_assert(handler); + + if (when == OGS_POLLIN) { + node->pollin.set = set; + node->pollin.handler = handler; + node->pollin.data = data; + } else if (when == OGS_POLLOUT) { + node->pollout.set = set; + node->pollout.handler = handler; + node->pollout.data = data; + } +} + +void ogs_socknode_install_poll(ogs_socknode_t *node) +{ + ogs_assert(node); + + if (node->pollin.handler) { + ogs_assert(node->sock); + ogs_assert(node->pollin.set); + ogs_assert(node->pollin.handler); + + node->pollin.poll = ogs_pollset_add(node->pollin.set, + OGS_POLLIN, node->sock->fd, node->pollin.handler, node->pollin.data); + ogs_assert(node->pollin.poll); + } + if (node->pollout.handler) { + ogs_assert(node->sock); + ogs_assert(node->pollout.set); + ogs_assert(node->pollout.handler); + + node->pollout.poll = ogs_pollset_add(node->pollout.set, + OGS_POLLOUT, node->sock->fd, node->pollout.handler, node->pollout.data); + ogs_assert(node->pollout.poll); + } + +} diff --git a/lib/core/ogs-socknode.h b/lib/core/ogs-socknode.h new file mode 100644 index 000000000..0b84b9d73 --- /dev/null +++ b/lib/core/ogs-socknode.h @@ -0,0 +1,95 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#if !defined(OGS_CORE_INSIDE) && !defined(OGS_CORE_COMPILATION) +#error "This header cannot be included directly." +#endif + +#ifndef OGS_SOCKNODE_H +#define OGS_SOCKNODE_H + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct ogs_sockopt_s { + struct { + int heartbit_interval; + int rto_initial; + int rto_min; + int rto_max; + int max_num_of_ostreams; + int max_num_of_istreams; + int max_attempts; + int max_initial_timeout; + } sctp; + + int nodelay; + int l_onoff; + int l_linger;; +} ogs_sockopt_t; + +typedef struct ogs_pollset_s ogs_pollset_t; +typedef struct ogs_poll_s ogs_poll_t; + +typedef struct ogs_socknode_s { + ogs_lnode_t node; + + ogs_sockaddr_t *addr; + + ogs_sock_t *sock; + void (*cleanup)(ogs_sock_t *sock); + + struct { + ogs_pollset_t *set; + ogs_poll_t *poll; + void *handler; + void *data; + } pollin, pollout; + + ogs_sockopt_t option; +} ogs_socknode_t; + +ogs_socknode_t *ogs_socknode_new(ogs_sockaddr_t *addr); +void ogs_socknode_free(ogs_socknode_t *node); + +ogs_socknode_t *ogs_socknode_add( + ogs_list_t *list, int family, ogs_sockaddr_t *sa_list); +void ogs_socknode_remove(ogs_list_t *list, ogs_socknode_t *node); +void ogs_socknode_remove_all(ogs_list_t *list); + +int ogs_socknode_probe( + ogs_list_t *list, ogs_list_t *list6, const char *dev, uint16_t port); +int ogs_socknode_fill_scope_id_in_local(ogs_sockaddr_t *sa_list); + +void ogs_socknode_sctp_option(ogs_socknode_t *node, ogs_sockopt_t *option); +void ogs_socknode_nodelay(ogs_socknode_t *node, int on); +void ogs_socknode_linger(ogs_socknode_t *node, int onoff, int linger); + +void ogs_socknode_set_cleanup( + ogs_socknode_t *node, void (*cleanup)(ogs_sock_t *)); +void ogs_socknode_set_poll(ogs_socknode_t *node, + ogs_pollset_t *set, short when, void *handler, void *data); +void ogs_socknode_install_poll(ogs_socknode_t *node); + +#ifdef __cplusplus +} +#endif + +#endif /* OGS_SOCKNODE_H */ diff --git a/lib/core/ogs-sockpair.c b/lib/core/ogs-sockpair.c new file mode 100644 index 000000000..ca7ff05a7 --- /dev/null +++ b/lib/core/ogs-sockpair.c @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "ogs-core.h" + +#undef OGS_LOG_DOMAIN +#define OGS_LOG_DOMAIN __ogs_sock_domain + +int ogs_socketpair(int family, int type, int protocol, ogs_socket_t fd[2]) +{ +#ifndef WIN32 + return socketpair(family, type, protocol, fd); +#else + int rc; + ogs_socket_t server = INVALID_SOCKET; + ogs_socket_t acceptor = INVALID_SOCKET; + ogs_socket_t client = INVALID_SOCKET; + struct sockaddr_in server_addr; + struct sockaddr_in client_addr; + socklen_t size; + + ogs_assert(family == AF_INET); + ogs_assert(type == SOCK_STREAM); + ogs_assert(protocol == 0); + + server = socket(family, type, protocol); + ogs_assert(server != INVALID_SOCKET); + + memset(&server_addr, 0, sizeof(server_addr)); + server_addr.sin_family = AF_INET; + server_addr.sin_addr.s_addr = htobe32(INADDR_LOOPBACK); + server_addr.sin_port = 0; + + rc = bind(server, (struct sockaddr *)&server_addr, sizeof(server_addr)); + ogs_assert(rc == 0); + rc = listen(server, 1); + ogs_assert(rc == 0); + + client = socket(AF_INET, SOCK_STREAM, 0); + ogs_assert(client != INVALID_SOCKET); + + memset(&client_addr, 0, sizeof(client_addr)); + size = sizeof(client_addr); + rc = getsockname(server, (struct sockaddr *)&client_addr, &size); + ogs_assert(rc == 0); + ogs_assert(size == sizeof(client_addr)); + + rc = connect(client, (struct sockaddr *)&client_addr, sizeof(client_addr)); + ogs_assert(rc == 0); + + size = sizeof(server_addr); + acceptor = accept(server, (struct sockaddr *)&server_addr, &size); + ogs_assert(acceptor != INVALID_SOCKET); + ogs_assert(size == sizeof(server_addr)); + + rc = getsockname(client, (struct sockaddr *)&client_addr, &size); + ogs_assert(rc == 0); + ogs_assert(size == sizeof(client_addr)); + ogs_assert(server_addr.sin_family == client_addr.sin_family); + ogs_assert(server_addr.sin_addr.s_addr == client_addr.sin_addr.s_addr); + ogs_assert(server_addr.sin_port == client_addr.sin_port); + + ogs_closesocket(server); + fd[0] = client; + fd[1] = acceptor; + + return OGS_OK; +#endif +} + diff --git a/lib/core/ogs-sockpair.h b/lib/core/ogs-sockpair.h new file mode 100644 index 000000000..c94920a70 --- /dev/null +++ b/lib/core/ogs-sockpair.h @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#if !defined(OGS_CORE_INSIDE) && !defined(OGS_CORE_COMPILATION) +#error "This header cannot be included directly." +#endif + +#ifndef OGS_SOCKPAIR_H +#define OGS_SOCKPAIR_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef _WIN32 +#define AF_SOCKPAIR AF_INET +#else +#define AF_SOCKPAIR AF_UNIX +#endif + +int ogs_socketpair(int family, int type, int protocol, ogs_socket_t fd[2]); + +#ifdef __cplusplus +} +#endif + +#endif /* OGS_SOCKPAIR_H */ diff --git a/lib/core/ogs-strings.c b/lib/core/ogs-strings.c new file mode 100644 index 000000000..00f69d9b9 --- /dev/null +++ b/lib/core/ogs-strings.c @@ -0,0 +1,156 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "core-config-private.h" + +#if HAVE_FCNTL_H +#include +#endif + +#if HAVE_STDARG_H +#include +#endif + +#include "ogs-core.h" + +int ogs_vsnprintf(char *str, size_t size, const char *format, va_list ap) +{ + int r = -1; + + /* Microsoft has finally implemented snprintf in Visual Studio 2015. + * In previous versions, I will simulate it as below. */ +#if defined(_MSC_VER) && _MSC_VER < 1900 + ogs_assert(str); + + if (size != 0) + r = _vsnprintf_s(str, size, _TRUNCATE, format, ap); + + if (r == -1) + r = _vscprintf(format, ap); +#else + r = vsnprintf(str, size, format, ap); +#endif + str[size-1] = '\0'; + + return r; +} + +int ogs_snprintf(char *str, size_t size, const char *format, ...) +{ + int r; + va_list ap; + + va_start(ap, format); + r = ogs_vsnprintf(str, size, format, ap); + va_end(ap); + + return r; +} + +char *ogs_vslprintf(char *str, char *last, const char *format, va_list ap) +{ + int r = -1; + + ogs_assert(last); + + if (!str) + return NULL; + + if (str < last) + r = ogs_vsnprintf(str, last - str, format, ap); + + return (str + r); +} + +char *ogs_slprintf(char *str, char *last, const char *format, ...) +{ + char *r; + va_list ap; + + va_start(ap, format); + r = ogs_vslprintf(str, last, format, ap); + va_end(ap); + + return r; +} + +char *ogs_strdup(const char *s) +{ + char *res; + size_t len; + + if (s == NULL) + return NULL; + + len = strlen(s) + 1; + res = ogs_memdup(s, len); + return res; +} + +char *ogs_strndup(const char *s, size_t n) +{ + char *res; + const char *end; + + if (s == NULL) + return NULL; + + end = memchr(s, '\0', n); + if (end != NULL) + n = end - s; + res = ogs_malloc(n + 1); + memcpy(res, s, n); + res[n] = '\0'; + return res; +} + +void *ogs_memdup(const void *m, size_t n) +{ + void *res; + + if (m == NULL) + return NULL; + + res = ogs_malloc(n); + memcpy(res, m, n); + return res; +} + +char *ogs_cpystrn(char *dst, const char *src, size_t dst_size) +{ + char *d = dst, *end; + + if (dst_size == 0) { + return (dst); + } + + if (src) { + end = dst + dst_size - 1; + + for (; d < end; ++d, ++src) { + if (!(*d = *src)) { + return (d); + } + } + } + + *d = '\0'; /* always null terminate */ + + return (d); +} diff --git a/lib/core/ogs-strings.h b/lib/core/ogs-strings.h new file mode 100644 index 000000000..ddc17b19a --- /dev/null +++ b/lib/core/ogs-strings.h @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#if !defined(OGS_CORE_INSIDE) && !defined(OGS_CORE_COMPILATION) +#error "This header cannot be included directly." +#endif + +#ifndef OGS_STRINGS_H +#define OGS_STRINGS_H + +#ifdef __cplusplus +extern "C" { +#endif + +#define OGS_HUGE_LEN 8192 + +#if defined(_WIN32) +#define ogs_strtok_r strtok_s +#define ogs_strcasecmp _stricmp +#define ogs_strncasecmp _strnicmp +#else +#define ogs_strtok_r strtok_r +#define ogs_strcasecmp strcasecmp +#define ogs_strncasecmp strncasecmp +#endif + +int ogs_vsnprintf(char *str, size_t size, const char *format, va_list ap) + OGS_GNUC_PRINTF (3, 0); +int ogs_snprintf(char *str, size_t size, const char *format, ...) + OGS_GNUC_PRINTF(3, 4); +char *ogs_vslprintf(char *str, char *last, const char *format, va_list ap) + OGS_GNUC_PRINTF (3, 0); +char *ogs_slprintf(char *str, char *last, const char *format, ...) + OGS_GNUC_PRINTF(3, 4); + +char *ogs_strdup(const char *s); +char *ogs_strndup(const char *s, size_t n); +void *ogs_memdup(const void *m, size_t n); + +char *ogs_cpystrn(char *dst, const char *src, size_t dst_size); + +#ifdef __cplusplus +} +#endif + +#endif /* OGS_STRINGS_H */ diff --git a/lib/core/ogs-tcp.c b/lib/core/ogs-tcp.c new file mode 100644 index 000000000..5aa0acd4d --- /dev/null +++ b/lib/core/ogs-tcp.c @@ -0,0 +1,108 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "ogs-core.h" + +#undef OGS_LOG_DOMAIN +#define OGS_LOG_DOMAIN __ogs_sock_domain + +ogs_sock_t *ogs_tcp_server(ogs_socknode_t *node) +{ + int rv; + ogs_sock_t *new = NULL; + ogs_sockaddr_t *addr; + char buf[OGS_ADDRSTRLEN]; + + ogs_assert(node); + ogs_assert(node->addr); + + addr = node->addr; + while(addr) { + new = ogs_sock_socket(addr->ogs_sa_family, SOCK_STREAM, IPPROTO_TCP); + if (new) { + rv = ogs_listen_reusable(new->fd); + ogs_assert(rv == OGS_OK); + + if (ogs_sock_bind(new, addr) == OGS_OK) { + ogs_debug("tcp_server() [%s]:%d", + OGS_ADDR(addr, buf), OGS_PORT(addr)); + break; + } + + ogs_sock_destroy(new); + } + + addr = addr->next; + } + + if (addr == NULL) { + ogs_log_message(OGS_LOG_ERROR, ogs_socket_errno, + "tcp_server() [%s]:%d failed", + OGS_ADDR(node->addr, buf), OGS_PORT(node->addr)); + return NULL; + } + + rv = ogs_sock_listen(new); + ogs_assert(rv == OGS_OK); + + node->sock = new; + + ogs_socknode_install_poll(node); + + return new; +} + +ogs_sock_t *ogs_tcp_client(ogs_socknode_t *node) +{ + ogs_sock_t *new = NULL; + ogs_sockaddr_t *addr; + char buf[OGS_ADDRSTRLEN]; + + ogs_assert(node); + ogs_assert(node->addr); + + addr = node->addr; + while (addr) { + new = ogs_sock_socket(addr->ogs_sa_family, SOCK_STREAM, IPPROTO_TCP); + if (new) { + if (ogs_sock_connect(new, addr) == OGS_OK) { + ogs_debug("tcp_client() [%s]:%d", + OGS_ADDR(addr, buf), OGS_PORT(addr)); + break; + } + + ogs_sock_destroy(new); + } + + addr = addr->next; + } + + if (addr == NULL) { + ogs_log_message(OGS_LOG_ERROR, ogs_socket_errno, + "tcp_client() [%s]:%d failed", + OGS_ADDR(node->addr, buf), OGS_PORT(node->addr)); + return NULL; + } + + node->sock = new; + + ogs_socknode_install_poll(node); + + return new; +} diff --git a/lib/core/ogs-tcp.h b/lib/core/ogs-tcp.h new file mode 100644 index 000000000..bb646b93b --- /dev/null +++ b/lib/core/ogs-tcp.h @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#if !defined(OGS_CORE_INSIDE) && !defined(OGS_CORE_COMPILATION) +#error "This header cannot be included directly." +#endif + +#ifndef OGS_TCP_H +#define OGS_TCP_H + +#ifdef __cplusplus +extern "C" { +#endif + +ogs_sock_t *ogs_tcp_server(ogs_socknode_t *node); +ogs_sock_t *ogs_tcp_client(ogs_socknode_t *node); + +#ifdef __cplusplus +} +#endif + +#endif /* OGS_TCP_H */ diff --git a/lib/core/ogs-thread.c b/lib/core/ogs-thread.c new file mode 100644 index 000000000..c6294228c --- /dev/null +++ b/lib/core/ogs-thread.c @@ -0,0 +1,139 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "ogs-core.h" + +#undef OGS_LOG_DOMAIN +#define OGS_LOG_DOMAIN __ogs_thread_domain + +#if !defined(_WIN32) +#define ogs_thread_id_t pthread_t +#define ogs_thread_join(_n) pthread_join((_n), NULL) +#else +#define ogs_thread_id_t HANDLE +static ogs_inline DWORD ogs_thread_join(ogs_thread_id_t thread) +{ + DWORD ret = WaitForSingleObject(thread, INFINITE); + if (!CloseHandle (thread)) { + ogs_log_message( + OGS_LOG_ERROR, ogs_errno, "Couldn't close thread handle"); + } + + return ret; +} +#endif + +typedef struct ogs_thread_s { + ogs_thread_id_t id; + + ogs_thread_mutex_t mutex; + ogs_thread_cond_t cond; + + bool running; + + void (*func)(void *); + void *data; +} ogs_thread_t; + +static void *thread_worker(void *arg) +{ + ogs_thread_t *thread = arg; + ogs_assert(thread); + + ogs_thread_mutex_lock(&thread->mutex); + + thread->running = true; + ogs_thread_cond_signal(&thread->cond); + + ogs_thread_mutex_unlock(&thread->mutex); + + ogs_debug("[%p] worker signal", thread); + thread->func(thread->data); + + ogs_thread_mutex_lock(&thread->mutex); + thread->running = false; + ogs_thread_mutex_unlock(&thread->mutex); + ogs_debug("[%p] worker done", thread); + + return NULL; +} + +ogs_thread_t *ogs_thread_create(void (*func)(void *), void *data) +{ + ogs_thread_t *thread = ogs_calloc(1, sizeof *thread); + ogs_assert(thread); + + ogs_thread_mutex_init(&thread->mutex); + ogs_thread_cond_init(&thread->cond); + + ogs_thread_mutex_lock(&thread->mutex); + + thread->running = false; + + thread->func = func; + thread->data = data; + +#if !defined(_WIN32) + pthread_create(&thread->id, NULL, thread_worker, thread); +#else + thread->id = CreateThread(NULL, 0, + (LPTHREAD_START_ROUTINE)thread_worker, thread, 0, NULL); +#endif + + ogs_thread_cond_wait(&thread->cond, &thread->mutex); + ogs_thread_mutex_unlock(&thread->mutex); + ogs_debug("[%p] thread started", thread); + + return thread; +} + +void ogs_thread_destroy(ogs_thread_t *thread) +{ + const ogs_time_t deadline = ogs_get_monotonic_time() + 5 * 1000 * 1000; + ogs_assert(thread); + + ogs_debug("[%p] thread running(%d)", thread, thread->running); + while(ogs_get_monotonic_time() <= deadline) { + /* wait 5 seconds */ + ogs_thread_mutex_lock(&thread->mutex); + if (!thread->running) { + ogs_thread_mutex_unlock(&thread->mutex); + break; + } + ogs_thread_mutex_unlock(&thread->mutex); + ogs_usleep(1000); + } + + ogs_debug("[%p] thread destroy", thread); + ogs_thread_mutex_lock(&thread->mutex); + if (thread->running) { + ogs_fatal("thread still running after 3 seconds"); + ogs_assert_if_reached(); + } + ogs_thread_mutex_unlock(&thread->mutex); + + ogs_thread_join(thread->id); + ogs_debug("[%p] thread join", thread); + + ogs_thread_cond_destroy(&thread->cond); + ogs_thread_mutex_destroy(&thread->mutex); + + ogs_free(thread); + ogs_debug("[%p] thread done", thread); +} diff --git a/lib/core/ogs-thread.h b/lib/core/ogs-thread.h new file mode 100644 index 000000000..3114addc5 --- /dev/null +++ b/lib/core/ogs-thread.h @@ -0,0 +1,117 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#if !defined(OGS_CORE_INSIDE) && !defined(OGS_CORE_COMPILATION) +#error "This header cannot be included directly." +#endif + +#ifndef OGS_THREAD_H +#define OGS_THREAD_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * The following code is stolen from mongodb-c-driver + * https://github.com/mongodb/mongo-c-driver/blob/master/src/libmongoc/src/mongoc/mongoc-thread-private.h + */ +#if !defined(_WIN32) +#define ogs_thread_mutex_t pthread_mutex_t +#define ogs_thread_mutex_init(_n) (void)pthread_mutex_init((_n), NULL) +#define ogs_thread_mutex_lock (void)pthread_mutex_lock +#define ogs_thread_mutex_unlock (void)pthread_mutex_unlock +#define ogs_thread_mutex_destroy (void)pthread_mutex_destroy +#define ogs_thread_cond_t pthread_cond_t +#define ogs_thread_cond_init(_n) (void)pthread_cond_init((_n), NULL) +#define ogs_thread_cond_wait pthread_cond_wait +static ogs_inline int ogs_thread_cond_timedwait( + pthread_cond_t *cond, pthread_mutex_t *mutex, ogs_time_t timeout) +{ + int r; + struct timespec to; + struct timeval tv; + ogs_time_t usec; + + ogs_gettimeofday(&tv); + + usec = ogs_time_from_sec(tv.tv_sec) + tv.tv_usec + timeout; + + to.tv_sec = ogs_time_sec(usec); + to.tv_nsec = ogs_time_usec(usec) * 1000; + + r = pthread_cond_timedwait(cond, mutex, &to); + if (r == 0) + return OGS_OK; + else if (r == OGS_ETIMEDOUT) + return OGS_TIMEUP; + else + return OGS_ERROR; +} +#define ogs_thread_cond_signal (void)pthread_cond_signal +#define ogs_thread_cond_broadcast pthread_cond_broadcast +#define ogs_thread_cond_destroy (void)pthread_cond_destroy +#define ogs_thread_id_t pthread_t +#define ogs_thread_join(_n) pthread_join((_n), NULL) +#else +#define ogs_thread_mutex_t CRITICAL_SECTION +#define ogs_thread_mutex_init InitializeCriticalSection +#define ogs_thread_mutex_lock EnterCriticalSection +#define ogs_thread_mutex_unlock LeaveCriticalSection +#define ogs_thread_mutex_destroy DeleteCriticalSection +#define ogs_thread_cond_t CONDITION_VARIABLE +#define ogs_thread_cond_init InitializeConditionVariable +#define ogs_thread_cond_wait(_c, _m) \ + ogs_thread_cond_timedwait ((_c), (_m), INFINITE) +static ogs_inline int ogs_thread_cond_timedwait( + ogs_thread_cond_t *cond, ogs_thread_mutex_t *mutex, ogs_time_t timeout) +{ + int r; + + if (SleepConditionVariableCS(cond, mutex, + (DWORD)ogs_time_to_msec(timeout))) { + return OGS_OK; + } else { + r = GetLastError(); + + if (r == WAIT_TIMEOUT || r == ERROR_TIMEOUT) { + return OGS_TIMEUP; + } else { + return OGS_ERROR; + } + } +} +#define ogs_thread_cond_signal WakeConditionVariable +#define ogs_thread_cond_broadcast WakeAllConditionVariable +static ogs_inline int ogs_thread_cond_destroy(ogs_thread_cond_t *_ignored) +{ + return 0; +} +#endif + +typedef struct ogs_thread_s ogs_thread_t; + +ogs_thread_t *ogs_thread_create(void (*func)(void *), void *data); +void ogs_thread_destroy(ogs_thread_t *thread); + +#ifdef __cplusplus +} +#endif + +#endif /* OGS_THREAD_H */ diff --git a/lib/core/ogs-time.c b/lib/core/ogs-time.c new file mode 100644 index 000000000..84fc3c080 --- /dev/null +++ b/lib/core/ogs-time.c @@ -0,0 +1,211 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifdef __APPLE__ +#include +#include +#include +#include +#endif + +#include "core-config-private.h" + +#if HAVE_SYS_TIME_H +#include +#endif + +#include "ogs-core.h" + +/* + * The following code is stolen from mongodb-c-driver + * https://github.com/mongodb/mongo-c-driver/blob/master/src/libbson/src/bson/bson-clock.c + */ + +int ogs_gettimeofday(struct timeval *tv) +{ +#if defined(_WIN32) +#if defined(_MSC_VER) +#define DELTA_EPOCH_IN_MICROSEC 11644473600000000Ui64 +#else +#define DELTA_EPOCH_IN_MICROSEC 11644473600000000ULL +#endif + FILETIME ft; + uint64_t tmp = 0; + + /* + * The const value is shamelessy stolen from + * http://www.boost.org/doc/libs/1_55_0/boost/chrono/detail/inlined/win/chrono.hpp + * + * File times are the number of 100 nanosecond intervals elapsed since + * 12:00 am Jan 1, 1601 UTC. I haven't check the math particularly hard + * + * ... good luck + */ + + if (tv) { + GetSystemTimeAsFileTime (&ft); + + /* pull out of the filetime into a 64 bit uint */ + tmp |= ft.dwHighDateTime; + tmp <<= 32; + tmp |= ft.dwLowDateTime; + + /* convert from 100's of nanosecs to microsecs */ + tmp /= 10; + + /* adjust to unix epoch */ + tmp -= DELTA_EPOCH_IN_MICROSEC; + + tv->tv_sec = (long) (tmp / 1000000UL); + tv->tv_usec = (long) (tmp % 1000000UL); + } + + return 0; +#else + int rc = gettimeofday(tv, NULL); + ogs_assert(rc == 0); + return 0; +#endif +} + +int ogs_timezone(void) +{ +#if defined(_WIN32) + u_long n; + TIME_ZONE_INFORMATION tz; + + n = GetTimeZoneInformation(&tz); + + switch (n) { + case TIME_ZONE_ID_UNKNOWN: + /* Bias = UTC - local time in minutes + * tm_gmtoff is seconds east of UTC + */ + return tz.Bias * -60; + case TIME_ZONE_ID_STANDARD: + return (tz.Bias + tz.StandardBias) * -60; + case TIME_ZONE_ID_DAYLIGHT: + return (tz.Bias + tz.DaylightBias) * -60; + default: + ogs_assert_if_reached(); + return 0; + } +#else + struct timeval tv; + struct tm tm; + time_t t1, t2; + int ret; + + ret = ogs_gettimeofday(&tv); + ogs_assert(ret == 0); + + t1 = tv.tv_sec; + ogs_gmtime(t1, &tm); + tm.tm_isdst = 0; + t2 = mktime(&tm); + + return difftime(t1, t2); +#endif +} + +ogs_time_t ogs_get_monotonic_time(void) +{ +#if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC) + struct timespec ts; + clock_gettime(CLOCK_MONOTONIC, &ts); + return ((ts.tv_sec * 1000000UL) + (ts.tv_nsec / 1000UL)); +#elif defined(__APPLE__) + static mach_timebase_info_data_t info = {0}; + static double ratio = 0.0; + + if (!info.denom) { + /* the value from mach_absolute_time () * info.numer / info.denom + * is in nano seconds. So we have to divid by 1000.0 to get micro + * seconds*/ + mach_timebase_info(&info); + ratio = (double) info.numer / (double) info.denom / 1000.0; + } + + return mach_absolute_time() * ratio; +#elif defined(_WIN32) + /* Despite it's name, this is in milliseconds! */ + ogs_time_t ticks = GetTickCount64(); + return (ticks * 1000L); +#elif defined(__hpux__) + ogs_time_t nanosec = gethrtime(); + return (nanosec / 1000UL); +#else +#warning "Monotonic clock is not yet supported on your platform." + struct timeval tv; + + ogs_gettimeofday(&tv); + return (tv.tv_sec * 1000000UL) + tv.tv_usec; +#endif +} + +void ogs_localtime(time_t s, struct tm *tm) +{ + ogs_assert(tm); + +#if (HAVE_LOCALTIME_R) + (void)localtime_r(&s, tm); +#else + struct tm *t; + + t = localtime(&s); + *tm = *t; +#endif +} + +void ogs_gmtime(time_t s, struct tm *tm) +{ + ogs_assert(tm); + +#if (HAVE_LOCALTIME_R) + (void)gmtime_r(&s, tm); +#else + struct tm *t; + + t = gmtime(&s); + *tm = *t; +#endif +} + +void ogs_msleep(time_t msec) +{ +#if defined(_WIN32) + Sleep(msec); +#else + ogs_usleep(msec * 1000); +#endif +} + +void ogs_usleep(time_t usec) +{ +#if defined(_WIN32) + Sleep(usec ? (1 + (usec - 1) / 1000) : 0); +#else + struct timespec req, rem; + req.tv_sec = usec / OGS_USEC_PER_SEC; + req.tv_nsec = (usec % OGS_USEC_PER_SEC) * 1000; + while (nanosleep(&req, &rem) == -1 && errno == EINTR) + req = rem; +#endif +} + diff --git a/lib/core/ogs-time.h b/lib/core/ogs-time.h new file mode 100644 index 000000000..30aadba11 --- /dev/null +++ b/lib/core/ogs-time.h @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#if !defined(OGS_CORE_INSIDE) && !defined(OGS_CORE_COMPILATION) +#error "This header cannot be included directly." +#endif + +#ifndef OGS_TIME_H +#define OGS_TIME_H + +#ifdef __cplusplus +extern "C" { +#endif + +typedef int64_t ogs_time_t; + +#define OGS_INFINITE_TIME (-1) +#define OGS_NO_WAIT_TIME (0) + +/** number of microseconds per second */ +#define OGS_USEC_PER_SEC (1000000) + +/** @return ogs_time_t as a second */ +#define ogs_time_sec(time) ((time) / OGS_USEC_PER_SEC) + +/** @return ogs_time_t as a usec */ +#define ogs_time_usec(time) ((time) % OGS_USEC_PER_SEC) + +/** @return ogs_time_t as a msec */ +#define ogs_time_msec(time) (((time) / 1000) % 1000) + +/** @return ogs_time_t as a msec */ +#define ogs_time_to_msec(time) ((time) ? (1 + ((time) - 1) / 1000) : 0) + +/** @return milliseconds as an ogs_time_t */ +#define ogs_time_from_msec(msec) ((ogs_time_t)(msec) * 1000) + +/** @return seconds as an ogs_time_t */ +#define ogs_time_from_sec(sec) ((ogs_time_t)(sec) * OGS_USEC_PER_SEC) + +int ogs_gettimeofday(struct timeval *tv); + +/** @return number of microseconds since an arbitrary point */ +ogs_time_t ogs_get_monotonic_time(void); +/** @return the GMT offset in seconds */ +int ogs_timezone(void); + +void ogs_localtime(time_t s, struct tm *tm); +void ogs_gmtime(time_t s, struct tm *tm); + +void ogs_msleep(time_t msec); +void ogs_usleep(time_t usec); + +#ifdef __cplusplus +} +#endif + +#endif /* OGS_TIME_H */ diff --git a/lib/core/ogs-timer.c b/lib/core/ogs-timer.c new file mode 100644 index 000000000..5f8326c23 --- /dev/null +++ b/lib/core/ogs-timer.c @@ -0,0 +1,195 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "ogs-core.h" + +#undef OGS_LOG_DOMAIN +#define OGS_LOG_DOMAIN __ogs_event_domain + +typedef struct ogs_timer_mgr_s { + OGS_POOL(pool, ogs_timer_t); + ogs_rbtree_t tree; +} ogs_timer_mgr_t; + +typedef struct ogs_timer_s { + ogs_rbnode_t rbnode; + ogs_lnode_t lnode; + + void (*cb)(void*); + void *data; + + ogs_timer_mgr_t *manager; + bool running; + ogs_time_t timeout;; +} ogs_timer_t; + +static void add_timer_node( + ogs_rbtree_t *tree, ogs_timer_t *timer, ogs_time_t duration) +{ + ogs_rbnode_t **new = NULL; + ogs_rbnode_t *parent = NULL; + ogs_assert(tree); + ogs_assert(timer); + + timer->timeout = ogs_get_monotonic_time() + duration; + + new = &tree->root; + while (*new) { + ogs_timer_t *this = ogs_rb_entry(*new, ogs_timer_t, rbnode); + + parent = *new; + if (timer->timeout < this->timeout) + new = &(*new)->left; + else + new = &(*new)->right; + } + + ogs_rbtree_link_node(timer, parent, new); + ogs_rbtree_insert_color(tree, timer); +} + +ogs_timer_mgr_t *ogs_timer_mgr_create(void) +{ + ogs_timer_mgr_t *manager = ogs_calloc(1, sizeof *manager); + ogs_assert(manager); + + ogs_pool_init(&manager->pool, ogs_core()->timer.pool); + + return manager; +} + +void ogs_timer_mgr_destroy(ogs_timer_mgr_t *manager) +{ + ogs_assert(manager); + + ogs_pool_final(&manager->pool); + ogs_free(manager); +} + +ogs_timer_t *ogs_timer_add( + ogs_timer_mgr_t *manager, void (*cb)(void *data), void *data) +{ + ogs_timer_t *timer = NULL; + ogs_assert(manager); + ogs_assert(cb); + + ogs_pool_alloc(&manager->pool, &timer); + ogs_assert(timer); + + memset(timer, 0, sizeof *timer); + timer->cb = cb; + timer->data = data; + + timer->manager = manager; + + return timer; +} + +void ogs_timer_delete(ogs_timer_t *timer) +{ + ogs_timer_mgr_t *manager; + ogs_assert(timer); + manager = timer->manager; + ogs_assert(manager); + + ogs_timer_stop(timer); + + ogs_pool_free(&manager->pool, timer); +} + +void ogs_timer_start(ogs_timer_t *timer, ogs_time_t duration) +{ + ogs_timer_mgr_t *manager = NULL; + ogs_assert(timer); + ogs_assert(duration > 0); + + manager = timer->manager; + ogs_assert(manager); + + if (timer->running == true) + ogs_rbtree_delete(&manager->tree, timer); + + timer->running = true; + add_timer_node(&manager->tree, timer, duration); +} + +void ogs_timer_stop(ogs_timer_t *timer) +{ + ogs_timer_mgr_t *manager = NULL; + ogs_assert(timer); + manager = timer->manager; + ogs_assert(manager); + + if (timer->running == false) + return; + + timer->running = false; + ogs_rbtree_delete(&manager->tree, timer); +} + +ogs_time_t ogs_timer_mgr_next(ogs_timer_mgr_t *manager) +{ + ogs_time_t current; + ogs_rbnode_t *rbnode = NULL; + ogs_assert(manager); + + current = ogs_get_monotonic_time(); + rbnode = ogs_rbtree_first(&manager->tree); + if (rbnode) { + ogs_timer_t *this = ogs_rb_entry(rbnode, ogs_timer_t, rbnode); + if (this->timeout > current) { + return (this->timeout - current); + } else { + return OGS_NO_WAIT_TIME; + } + } + + return OGS_INFINITE_TIME; +} + +void ogs_timer_mgr_expire(ogs_timer_mgr_t *manager) +{ + OGS_LIST(list); + ogs_lnode_t *lnode; + + ogs_time_t current; + ogs_rbnode_t *rbnode; + ogs_timer_t *this; + ogs_assert(manager); + + current = ogs_get_monotonic_time(); + + ogs_list_init(&list); + ogs_rbtree_for_each(&manager->tree, rbnode) { + this = ogs_rb_entry(rbnode, ogs_timer_t, rbnode); + + if (this->timeout > current) + break; + + ogs_list_add(&list, &this->lnode); + } + + ogs_list_for_each(&list, lnode) { + this = ogs_rb_entry(lnode, ogs_timer_t, lnode); + ogs_timer_stop(this); + if (this->cb) + this->cb(this->data); + } +} + diff --git a/lib/core/ogs-timer.h b/lib/core/ogs-timer.h new file mode 100644 index 000000000..5c990e92f --- /dev/null +++ b/lib/core/ogs-timer.h @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#if !defined(OGS_CORE_INSIDE) && !defined(OGS_CORE_COMPILATION) +#error "This header cannot be included directly." +#endif + +#ifndef OGS_TIMER_H +#define OGS_TIMER_H + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct ogs_timer_mgr_s ogs_timer_mgr_t; +typedef struct ogs_timer_s ogs_timer_t;; + +ogs_timer_mgr_t *ogs_timer_mgr_create(void); +void ogs_timer_mgr_destroy(ogs_timer_mgr_t *manager); + +ogs_timer_t *ogs_timer_add( + ogs_timer_mgr_t *manager, void (*cb)(void *data), void *data); +void ogs_timer_delete(ogs_timer_t *timer); + +void ogs_timer_start(ogs_timer_t *timer, ogs_time_t duration); +void ogs_timer_stop(ogs_timer_t *timer); + +ogs_time_t ogs_timer_mgr_next(ogs_timer_mgr_t *manager); +void ogs_timer_mgr_expire(ogs_timer_mgr_t *manager); + +#ifdef __cplusplus +} +#endif + +#endif /* OGS_TIMER_H */ diff --git a/lib/core/ogs-tlv.c b/lib/core/ogs-tlv.c new file mode 100644 index 000000000..a43108f13 --- /dev/null +++ b/lib/core/ogs-tlv.c @@ -0,0 +1,462 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "ogs-core.h" + +#undef OGS_LOG_DOMAIN +#define OGS_LOG_DOMAIN __ogs_tlv_domain + +static OGS_POOL(pool, ogs_tlv_t); + +/* ogs_tlv_t common functions */ +ogs_tlv_t *ogs_tlv_get(void) +{ + ogs_tlv_t *tlv = NULL; + + /* get tlv node from node pool */ + ogs_pool_alloc(&pool, &tlv); + + /* check for error */ + ogs_assert(tlv); + + /* intialize tlv node */ + memset(tlv, 0, sizeof(ogs_tlv_t)); + return tlv; +} + +void ogs_tlv_free(ogs_tlv_t *tlv) +{ + /* free tlv node to the node pool */ + ogs_pool_free(&pool, tlv); +} + +void ogs_tlv_init(void) +{ + ogs_pool_init(&pool, ogs_core()->tlv.pool); +} + +void ogs_tlv_final(void) +{ + ogs_pool_final(&pool); +} + +uint32_t ogs_tlv_pool_avail(void) +{ + return ogs_pool_avail(&pool); +} + +void ogs_tlv_free_all(ogs_tlv_t *root) +{ + /* free all tlv node to the node pool */ + ogs_tlv_t *iter = root; + ogs_tlv_t *next = NULL; + while (iter) { + if(iter->embedded != NULL) { + ogs_tlv_free_all(iter->embedded); + } + next = iter->next; + ogs_tlv_free(iter); + iter = next; + } +} + +uint8_t ogs_tlv_value_8(ogs_tlv_t *tlv) +{ + return (*((uint8_t*)(tlv->value))); +} + +uint16_t ogs_tlv_value_16(ogs_tlv_t *tlv) +{ + uint16_t u_16; + uint8_t *v = tlv->value; + + u_16 = ((v[0] << 8) & 0xff00) | + ((v[1] ) & 0x00ff); + + return u_16; +} + +uint32_t ogs_tlv_value_32(ogs_tlv_t *tlv) +{ + uint32_t u_32; + uint8_t *v = tlv->value; + + u_32 = ((v[0] << 24) & 0xff000000) | + ((v[1] << 16) & 0x00ff0000) | + ((v[2] << 8) & 0x0000ff00) | + ((v[3] ) & 0x000000ff); + + return u_32; +} + +uint32_t ogs_tlv_calc_length(ogs_tlv_t *tlv, uint8_t mode) +{ + ogs_tlv_t *iter = tlv; + uint32_t length = 0; + + while(iter) { + /* this is length for type field */ + switch(mode) { + case OGS_TLV_MODE_T1_L1: + length += 2; + break; + case OGS_TLV_MODE_T1_L2: + length += 3; + break; + case OGS_TLV_MODE_T1_L2_I1: + case OGS_TLV_MODE_T2_L2: + length += 4; + break; + default: + ogs_assert_if_reached(); + break; + } + + /* this is length for type field */ + if(iter->embedded != NULL) { + iter->length = ogs_tlv_calc_length(iter->embedded, mode); + } + + /* this is length for value field */ + length += iter->length; + + iter = iter->next; + } + return length; +} + +uint32_t ogs_tlv_calc_count(ogs_tlv_t *tlv) +{ + ogs_tlv_t *iter = tlv; + uint32_t count = 0; + + while(iter) { + if(iter->embedded != NULL) { + count += ogs_tlv_calc_count(iter->embedded); + } else { + count++; + } + iter = iter->next; + } + return count; +} + +static uint8_t *tlv_put_type(uint32_t type, uint8_t *pos, uint8_t mode) +{ + switch(mode) { + case OGS_TLV_MODE_T1_L1: + case OGS_TLV_MODE_T1_L2: + case OGS_TLV_MODE_T1_L2_I1: + *(pos++) = type & 0xFF; + break; + case OGS_TLV_MODE_T2_L2: + *(pos++) = (type >> 8) & 0xFF; + *(pos++) = type & 0xFF; + break; + default: + ogs_assert_if_reached(); + break; + } + return pos; +} + +static uint8_t *tlv_put_length(uint32_t length, uint8_t *pos, uint8_t mode) +{ + switch(mode) { + case OGS_TLV_MODE_T1_L1: + *(pos++) = length & 0xFF; + break; + case OGS_TLV_MODE_T1_L2: + case OGS_TLV_MODE_T1_L2_I1: + case OGS_TLV_MODE_T2_L2: + *(pos++) = (length >> 8) & 0xFF; + *(pos++) = length & 0xFF; + break; + default: + ogs_assert_if_reached(); + break; + } + + return pos; +} + +static uint8_t *tlv_put_instance(uint8_t instance, uint8_t *pos, uint8_t mode) +{ + switch(mode) { + case OGS_TLV_MODE_T1_L2_I1: + *(pos++) = instance & 0xFF; + break; + default: + break; + } + + return pos; +} + +static uint8_t *tlv_get_element(ogs_tlv_t *tlv, uint8_t *blk, uint8_t mode) +{ + uint8_t *pos = blk; + + switch(mode) { + case OGS_TLV_MODE_T1_L1: + tlv->type = *(pos++); + tlv->length = *(pos++); + break; + case OGS_TLV_MODE_T1_L2: + tlv->type = *(pos++); + tlv->length = *(pos++) << 8; + tlv->length += *(pos++); + break; + case OGS_TLV_MODE_T1_L2_I1: + tlv->type = *(pos++); + tlv->length = *(pos++) << 8; + tlv->length += *(pos++); + tlv->instance = *(pos++); + break; + case OGS_TLV_MODE_T2_L2: + tlv->type = *(pos++) << 8; + tlv->type += *(pos++); + tlv->length = *(pos++) << 8; + tlv->length += *(pos++); + break; + default: + ogs_assert_if_reached(); + break; + } + + tlv->value = pos; + + return (pos + ogs_tlv_length(tlv)); +} + +static void tlv_alloc_buff_to_tlv( + ogs_tlv_t *head, uint8_t *buff, uint32_t buff_len) +{ + head->buff_allocated = true; + head->buff_len = buff_len; + head->buff_ptr = buff; + head->buff = buff; +} + +ogs_tlv_t *ogs_tlv_find_root(ogs_tlv_t *tlv) +{ + ogs_tlv_t *head = tlv->head; + ogs_tlv_t *parent; + + parent = head->parent; + while(parent) { + head = parent->head; + parent = head->parent; + } + + return head; +} + +ogs_tlv_t *ogs_tlv_add(ogs_tlv_t *head, + uint32_t type, uint32_t length, uint8_t instance, void *value) +{ + ogs_tlv_t *curr = head; + ogs_tlv_t *new = NULL; + + new = ogs_tlv_get(); + ogs_assert(new); + if(length != 0) + ogs_assert(value); + + new->type = type; + new->length = length; + new->instance = instance; + new->value = value; + + if (head != NULL && head->buff_allocated == true) { + ogs_assert((head->buff_ptr - head->buff + length) < head->buff_len); + + memcpy(head->buff_ptr, value, length); + new->value = head->buff_ptr; + head->buff_ptr += length; + } + + if(curr == NULL) { + new->head = new; + new->tail = new; + } else { + head = head->head; /* in case head is not head */ + new->head = head; + head->tail->next = new; + head->tail = new; + } + return new; +} + +ogs_tlv_t *ogs_tlv_copy(void *buff, uint32_t buff_len, + uint32_t type, uint32_t length, uint8_t instance, void *value) +{ + ogs_tlv_t *new = NULL; + + new = ogs_tlv_get(); + ogs_assert(new); + + new->type = type; + new->length = length; + new->instance = instance; + new->value = value; + new->head = new->tail = new; + + tlv_alloc_buff_to_tlv(new, buff, buff_len); + + memcpy(new->buff_ptr, value, length); + new->value = new->buff_ptr; + new->buff_ptr += length; + + return new; +} + +ogs_tlv_t *ogs_tlv_embed(ogs_tlv_t *parent, + uint32_t type, uint32_t length, uint8_t instance, void *value) +{ + ogs_tlv_t *new = NULL, *root = NULL; + + ogs_assert(parent); + + new = ogs_tlv_get(); + ogs_assert(new); + + new->type = type; + new->length = length; + new->instance = instance; + new->value = value; + + root = ogs_tlv_find_root(parent); + + if(root->buff_allocated == true) { + ogs_assert((root->buff_ptr - root->buff + length) < root->buff_len); + + memcpy(root->buff_ptr, value, length); + new->value = root->buff_ptr; + root->buff_ptr += length; + } + + if(parent->embedded == NULL) { + parent->embedded = new->head = new->tail = new; + new->parent = parent; + } else { + new->head = parent->embedded; + parent->embedded->tail->next = new; + parent->embedded->tail = new; + } + + return new; +} + +uint32_t ogs_tlv_render(ogs_tlv_t *root, + void *data, uint32_t length, uint8_t mode) +{ + ogs_tlv_t *curr = root; + uint8_t *pos = data; + uint8_t *blk = data; + uint32_t embedded_len = 0; + + while(curr) { + pos = tlv_put_type(curr->type, pos, mode); + + if(curr->embedded == NULL) { + pos = tlv_put_length(curr->length, pos, mode); + pos = tlv_put_instance(curr->instance, pos, mode); + + if ((pos - blk) + ogs_tlv_length(curr) > length) + ogs_assert_if_reached(); + + memcpy((char*)pos, (char*)curr->value, curr->length); + pos += curr->length; + } else { + embedded_len = ogs_tlv_calc_length(curr->embedded, mode); + pos = tlv_put_length(embedded_len, pos, mode); + pos = tlv_put_instance(curr->instance, pos, mode); + ogs_tlv_render(curr->embedded, + pos, length - (uint32_t)(pos-blk), mode); + pos += embedded_len; + } + curr = curr->next; + } + + return (pos - blk); +} + +/* ogs_tlv_t parsing functions */ +ogs_tlv_t *ogs_tlv_parse_block(uint32_t length, void *data, uint8_t mode) +{ + uint8_t *pos = data; + uint8_t *blk = data; + + ogs_tlv_t *root = NULL; + ogs_tlv_t *prev = NULL; + ogs_tlv_t *curr = NULL; + + root = curr = ogs_tlv_get(); + + ogs_assert(curr); + + pos = tlv_get_element(curr, pos, mode); + + ogs_assert(pos); + + while(pos - blk < length) { + prev = curr; + + curr = ogs_tlv_get(); + ogs_assert(curr); + prev->next = curr; + + pos = tlv_get_element(curr, pos, mode); + ogs_assert(pos); + } + + ogs_assert(length == (pos - blk)); + + return root; +} + +ogs_tlv_t *ogs_tlv_parse_embedded_block(ogs_tlv_t *tlv, uint8_t mode) +{ + tlv->embedded = ogs_tlv_parse_block(tlv->length, tlv->value, mode); + + return tlv->embedded; +} + +/* tlv operation-related function */ +ogs_tlv_t *ogs_tlv_find(ogs_tlv_t *root, uint32_t type) +{ + ogs_tlv_t *iter = root, *embed = NULL; + while(iter) { + if(iter->type == type) { + return iter; + } + + if(iter->embedded != NULL) { + embed = ogs_tlv_find(iter->embedded, type); + if(embed != NULL) { + return embed; + } + } + iter = iter->next; + } + + /* tlv for the designated type doesn't exist */ + return NULL; +} diff --git a/lib/core/ogs-tlv.h b/lib/core/ogs-tlv.h new file mode 100644 index 000000000..0cc651963 --- /dev/null +++ b/lib/core/ogs-tlv.h @@ -0,0 +1,100 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#if !defined(OGS_CORE_INSIDE) && !defined(OGS_CORE_COMPILATION) +#error "This header cannot be included directly." +#endif + +#ifndef OGS_TLV_H +#define OGS_TLV_H + +#define OGS_TLV_MODE_T1_L1 1 +#define OGS_TLV_MODE_T1_L2 2 +#define OGS_TLV_MODE_T1_L2_I1 3 +#define OGS_TLV_MODE_T2_L2 4 + +/* ogs_tlv_t struncture */ + +typedef struct ogs_tlv_s +{ + /* for tlv management */ + struct ogs_tlv_s *head; + struct ogs_tlv_s *tail; /* this is used only for head ogs_tlv_t */ + struct ogs_tlv_s *next; + + struct ogs_tlv_s *parent; + struct ogs_tlv_s *embedded; + + /* tlv basic element */ + uint32_t type; + uint32_t length; + uint8_t instance; + void *value; + + /* can be needed in encoding ogs_tlv_t*/ + bool buff_allocated; + uint32_t buff_len; + unsigned char *buff_ptr; + unsigned char *buff; +} ogs_tlv_t; + +#define ogs_tlv_type(pTlv) pTlv->type +#define ogs_tlv_length(pTlv) pTlv->length +#define ogs_tlv_instance(pTlv) pTlv->instance +#define ogs_tlv_value(pTlv) pTlv->value + +/* ogs_tlv_t pool related functions */ +ogs_tlv_t *ogs_tlv_get(void); +void ogs_tlv_free(ogs_tlv_t *tlv); +void ogs_tlv_free_all(ogs_tlv_t *root); + +void ogs_tlv_init(void); +void ogs_tlv_final(void); + +uint32_t ogs_tlv_pool_avail(void); + +/* ogs_tlv_t encoding functions */ +ogs_tlv_t *ogs_tlv_add(ogs_tlv_t *head, + uint32_t type, uint32_t length, uint8_t instance, void *value); +ogs_tlv_t *ogs_tlv_copy(void *buff, uint32_t buff_len, + uint32_t type, uint32_t length, uint8_t instance, void *value); +ogs_tlv_t *ogs_tlv_embed(ogs_tlv_t *parent, + uint32_t type, uint32_t length, uint8_t instance, void *value); + +uint32_t ogs_tlv_render( + ogs_tlv_t *root, void *data, uint32_t length, uint8_t mode); + +/* ogs_tlv_t parsing functions */ +ogs_tlv_t *ogs_tlv_parse_block(uint32_t length, void *data, uint8_t mode); +ogs_tlv_t *ogs_tlv_parse_embedded_block(ogs_tlv_t *tlv, uint8_t mode); + +/* tlv operation-related function */ +ogs_tlv_t *ogs_tlv_find(ogs_tlv_t *root, uint32_t type); +ogs_tlv_t *ogs_tlv_find_root(ogs_tlv_t *tlv); +uint32_t ogs_tlv_calc_length(ogs_tlv_t *tlv, uint8_t mode); +uint32_t ogs_tlv_calc_count(ogs_tlv_t *tlv); +uint8_t ogs_tlv_value_8(ogs_tlv_t *tlv); +uint16_t ogs_tlv_value_16(ogs_tlv_t *tlv); +uint32_t ogs_tlv_value_32(ogs_tlv_t *tlv); + +#ifdef __cplusplus +} +#endif + +#endif /* OGS_OGS_TLV_H */ diff --git a/lib/core/ogs-udp.c b/lib/core/ogs-udp.c new file mode 100644 index 000000000..398c06819 --- /dev/null +++ b/lib/core/ogs-udp.c @@ -0,0 +1,145 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "ogs-core.h" + +#undef OGS_LOG_DOMAIN +#define OGS_LOG_DOMAIN __ogs_sock_domain + +ogs_sock_t *ogs_udp_socket(int family, ogs_socknode_t *node) +{ + ogs_sock_t *sock = NULL; + sock = ogs_sock_socket(family, SOCK_DGRAM, IPPROTO_UDP); + ogs_assert(sock); + + ogs_debug("udp_socket() family:%d", family); + + return sock; +} + +ogs_sock_t *ogs_udp_server(ogs_socknode_t *node) +{ + int rv; + ogs_sock_t *new = NULL; + ogs_sockaddr_t *addr; + char buf[OGS_ADDRSTRLEN]; + + ogs_assert(node); + ogs_assert(node->addr); + + addr = node->addr; + while (addr) { + new = ogs_udp_socket(addr->ogs_sa_family, node); + if (new) { + rv = ogs_listen_reusable(new->fd); + ogs_assert(rv == OGS_OK); + + if (ogs_sock_bind(new, addr) == OGS_OK) { + ogs_debug("udp_server() [%s]:%d", + OGS_ADDR(addr, buf), OGS_PORT(addr)); + break; + } + + ogs_sock_destroy(new); + } + + addr = addr->next; + } + + if (addr == NULL) { + ogs_log_message(OGS_LOG_ERROR, ogs_socket_errno, + "udp_server() [%s]:%d failed", + OGS_ADDR(node->addr, buf), OGS_PORT(node->addr)); + return NULL; + } + + node->sock = new; + + ogs_socknode_install_poll(node); + + return new; +} + +ogs_sock_t *ogs_udp_client(ogs_socknode_t *node) +{ + ogs_sock_t *new = NULL; + ogs_sockaddr_t *addr; + char buf[OGS_ADDRSTRLEN]; + + ogs_assert(node); + ogs_assert(node->addr); + + addr = node->addr; + while (addr) { + new = ogs_udp_socket(addr->ogs_sa_family, node); + if (new) { + if (ogs_sock_connect(new, addr) == OGS_OK) { + ogs_debug("udp_client() [%s]:%d", + OGS_ADDR(addr, buf), OGS_PORT(addr)); + break; + } + + ogs_sock_destroy(new); + } + + addr = addr->next; + } + + if (addr == NULL) { + ogs_log_message(OGS_LOG_ERROR, ogs_socket_errno, + "udp_client() [%s]:%d failed", + OGS_ADDR(node->addr, buf), OGS_PORT(node->addr)); + return NULL;; + } + + node->sock = new; + + ogs_socknode_install_poll(node); + + return new; +} + +int ogs_udp_connect(ogs_sock_t *sock, ogs_sockaddr_t *sa_list) +{ + ogs_sockaddr_t *addr; + char buf[OGS_ADDRSTRLEN]; + + ogs_assert(sock); + ogs_assert(sa_list); + + addr = sa_list; + while (addr) { + if (ogs_sock_connect(sock, addr) == OGS_OK) { + ogs_debug("udp_connect() [%s]:%d", + OGS_ADDR(addr, buf), OGS_PORT(addr)); + break; + } + + addr = addr->next; + } + + if (addr == NULL) { + ogs_log_message(OGS_LOG_ERROR, ogs_socket_errno, + "udp_connect() [%s]:%d failed", + OGS_ADDR(sa_list, buf), OGS_PORT(sa_list)); + return OGS_ERROR; + } + + return OGS_OK; +} diff --git a/lib/core/ogs-udp.h b/lib/core/ogs-udp.h new file mode 100644 index 000000000..c850a8d4e --- /dev/null +++ b/lib/core/ogs-udp.h @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#if !defined(OGS_CORE_INSIDE) && !defined(OGS_CORE_COMPILATION) +#error "This header cannot be included directly." +#endif + +#ifndef OGS_UDP_H +#define OGS_UDP_H + +#ifdef __cplusplus +extern "C" { +#endif + +ogs_sock_t *ogs_udp_socket(int family, ogs_socknode_t *node); +ogs_sock_t *ogs_udp_server(ogs_socknode_t *node); +ogs_sock_t *ogs_udp_client(ogs_socknode_t *node); +int ogs_udp_connect(ogs_sock_t *sock, ogs_sockaddr_t *sa_list); + +#ifdef __cplusplus +} +#endif + +#endif /* OGS_UDP_H */ diff --git a/lib/crypt/kasumi.c b/lib/crypt/kasumi.c new file mode 100644 index 000000000..7ce7fed04 --- /dev/null +++ b/lib/crypt/kasumi.c @@ -0,0 +1,470 @@ +/*----------------------------------------------------------------------- + * kasumi.c + *----------------------------------------------------------------------- + * + * A sample implementation of KASUMI, the core algorithm for the + * 3GPP Confidentiality and Integrity algorithms. + * + * This has been coded for clarity, not necessarily for efficiency. + * + * This will compile and run correctly on both Intel (little endian) + * and Sparc (big endian) machines. (Compilers used supported 32-bit ints). + * + * Version 1.1 08 May 2000 + * + *-----------------------------------------------------------------------*/ + +#include "kasumi.h" + +/*--------- 16 bit rotate left ------------------------------------------*/ + +#define ROL16(a,b) (u16)((a<>(16-b))) + +/*-------- globals: The subkey arrays -----------------------------------*/ + +static u16 KLi1[8], KLi2[8]; +static u16 KOi1[8], KOi2[8], KOi3[8]; +static u16 KIi1[8], KIi2[8], KIi3[8]; + + +/*--------------------------------------------------------------------- + * FI() + * The FI function (fig 3). It includes the S7 and S9 tables. + * Transforms a 16-bit value. + *---------------------------------------------------------------------*/ +static u16 FI( u16 in, u16 subkey ) +{ + u16 nine, seven; + static u16 S7[] = { + 54, 50, 62, 56, 22, 34, 94, 96, 38, 6, 63, 93, 2, 18,123, 33, + 55,113, 39,114, 21, 67, 65, 12, 47, 73, 46, 27, 25,111,124, 81, + 53, 9,121, 79, 52, 60, 58, 48,101,127, 40,120,104, 70, 71, 43, + 20,122, 72, 61, 23,109, 13,100, 77, 1, 16, 7, 82, 10,105, 98, + 117,116, 76, 11, 89,106, 0,125,118, 99, 86, 69, 30, 57,126, 87, + 112, 51, 17, 5, 95, 14, 90, 84, 91, 8, 35,103, 32, 97, 28, 66, + 102, 31, 26, 45, 75, 4, 85, 92, 37, 74, 80, 49, 68, 29,115, 44, + 64,107,108, 24,110, 83, 36, 78, 42, 19, 15, 41, 88,119, 59, 3}; + static u16 S9[] = { + 167,239,161,379,391,334, 9,338, 38,226, 48,358,452,385, 90,397, + 183,253,147,331,415,340, 51,362,306,500,262, 82,216,159,356,177, + 175,241,489, 37,206, 17, 0,333, 44,254,378, 58,143,220, 81,400, + 95, 3,315,245, 54,235,218,405,472,264,172,494,371,290,399, 76, + 165,197,395,121,257,480,423,212,240, 28,462,176,406,507,288,223, + 501,407,249,265, 89,186,221,428,164, 74,440,196,458,421,350,163, + 232,158,134,354, 13,250,491,142,191, 69,193,425,152,227,366,135, + 344,300,276,242,437,320,113,278, 11,243, 87,317, 36, 93,496, 27, + 487,446,482, 41, 68,156,457,131,326,403,339, 20, 39,115,442,124, + 475,384,508, 53,112,170,479,151,126,169, 73,268,279,321,168,364, + 363,292, 46,499,393,327,324, 24,456,267,157,460,488,426,309,229, + 439,506,208,271,349,401,434,236, 16,209,359, 52, 56,120,199,277, + 465,416,252,287,246, 6, 83,305,420,345,153,502, 65, 61,244,282, + 173,222,418, 67,386,368,261,101,476,291,195,430, 49, 79,166,330, + 280,383,373,128,382,408,155,495,367,388,274,107,459,417, 62,454, + 132,225,203,316,234, 14,301, 91,503,286,424,211,347,307,140,374, + 35,103,125,427, 19,214,453,146,498,314,444,230,256,329,198,285, + 50,116, 78,410, 10,205,510,171,231, 45,139,467, 29, 86,505, 32, + 72, 26,342,150,313,490,431,238,411,325,149,473, 40,119,174,355, + 185,233,389, 71,448,273,372, 55,110,178,322, 12,469,392,369,190, + 1,109,375,137,181, 88, 75,308,260,484, 98,272,370,275,412,111, + 336,318, 4,504,492,259,304, 77,337,435, 21,357,303,332,483, 18, + 47, 85, 25,497,474,289,100,269,296,478,270,106, 31,104,433, 84, + 414,486,394, 96, 99,154,511,148,413,361,409,255,162,215,302,201, + 266,351,343,144,441,365,108,298,251, 34,182,509,138,210,335,133, + 311,352,328,141,396,346,123,319,450,281,429,228,443,481, 92,404, + 485,422,248,297, 23,213,130,466, 22,217,283, 70,294,360,419,127, + 312,377, 7,468,194, 2,117,295,463,258,224,447,247,187, 80,398, + 284,353,105,390,299,471,470,184, 57,200,348, 63,204,188, 33,451, + 97, 30,310,219, 94,160,129,493, 64,179,263,102,189,207,114,402, + 438,477,387,122,192, 42,381, 5,145,118,180,449,293,323,136,380, + 43, 66, 60,455,341,445,202,432, 8,237, 15,376,436,464, 59,461}; + + /* The sixteen bit input is split into two unequal halves, * + * nine bits and seven bits - as is the subkey */ + + nine = (u16)(in>>7); + seven = (u16)(in&0x7F); + + /* Now run the various operations */ + + nine = (u16)(S9[nine] ^ seven); + seven = (u16)(S7[seven] ^ (nine & 0x7F)); + + seven ^= (subkey>>9); + nine ^= (subkey&0x1FF); + + nine = (u16)(S9[nine] ^ seven); + seven = (u16)(S7[seven] ^ (nine & 0x7F)); + + in = (u16)((seven<<9) + nine); + + return( in ); +} + + +/*--------------------------------------------------------------------- + * FO() + * The FO() function. + * Transforms a 32-bit value. Uses to identify the + * appropriate subkeys to use. + *---------------------------------------------------------------------*/ +static u32 FO( u32 in, int index ) +{ + u16 left, right; + + /* Split the input into two 16-bit words */ + + left = (u16)(in>>16); + right = (u16) in; + + /* Now apply the same basic transformation three times */ + + left ^= KOi1[index]; + left = FI( left, KIi1[index] ); + left ^= right; + + right ^= KOi2[index]; + right = FI( right, KIi2[index] ); + right ^= left; + + left ^= KOi3[index]; + left = FI( left, KIi3[index] ); + left ^= right; + + in = (((u32)right)<<16)+left; + + return( in ); +} + +/*--------------------------------------------------------------------- + * FL() + * The FL() function. + * Transforms a 32-bit value. Uses to identify the + * appropriate subkeys to use. + *---------------------------------------------------------------------*/ +static u32 FL( u32 in, int index ) +{ + u16 l, r, a, b; + + /* split out the left and right halves */ + + l = (u16)(in>>16); + r = (u16)(in); + + /* do the FL() operations */ + + a = (u16) (l & KLi1[index]); + r ^= ROL16(a,1); + + b = (u16)(r | KLi2[index]); + l ^= ROL16(b,1); + + /* put the two halves back together */ + + in = (((u32)l)<<16) + r; + + return( in ); +} + + +/*--------------------------------------------------------------------- + * kasumi() + * the Main algorithm (fig 1). Apply the same pair of operations + * four times. Transforms the 64-bit input. + *---------------------------------------------------------------------*/ +void kasumi( u8 *data ) +{ + u32 left, right, temp; + REGISTER32 *d; + int n; + + /* Start by getting the data into two 32-bit words (endian corect) */ + + d = (REGISTER32*)data; + left = (((u32)d[0].b8[0])<<24)+(((u32)d[0].b8[1])<<16) + +(d[0].b8[2]<<8)+(d[0].b8[3]); + right = (((u32)d[1].b8[0])<<24)+(((u32)d[1].b8[1])<<16) + +(d[1].b8[2]<<8)+(d[1].b8[3]); + n = 0; + do { + temp = FL( left, n ); + temp = FO( temp, n++ ); + right ^= temp; + temp = FO( right, n ); + temp = FL( temp, n++ ); + left ^= temp; + } while( n<=7 ); + + /* return the correct endian result */ + d[0].b8[0] = (u8)(left>>24); d[1].b8[0] = (u8)(right>>24); + d[0].b8[1] = (u8)(left>>16); d[1].b8[1] = (u8)(right>>16); + d[0].b8[2] = (u8)(left>>8); d[1].b8[2] = (u8)(right>>8); + d[0].b8[3] = (u8)(left); d[1].b8[3] = (u8)(right); + + /* strange issue with gcc, where data is not updated + with left and right values... give a try like this: + data = d; + actually not working... */ +} + +/*--------------------------------------------------------------------- + * kasumi_key_schedule() + * Build the key schedule. Most "key" operations use 16-bit + * subkeys so we build u16-sized arrays that are "endian" correct. + *---------------------------------------------------------------------*/ +void kasumi_key_schedule( u8 *k ) +{ + static u16 C[] = { + 0x0123,0x4567,0x89AB,0xCDEF, 0xFEDC,0xBA98,0x7654,0x3210 }; + u16 key[8], Kprime[8]; + REGISTER16 *k16; + int n; + + /* Start by ensuring the subkeys are endian correct on a 16-bit basis */ + + k16 = (REGISTER16 *)k; + for( n=0; n<8; ++n ) + key[n] = (u16)((k16[n].b8[0]<<8) + (k16[n].b8[1])); + + /* Now build the K'[] keys */ + + for( n=0; n<8; ++n ) + Kprime[n] = (u16)(key[n] ^ C[n]); + + /* Finally construct the various sub keys */ + + for( n=0; n<8; ++n ) + { + KLi1[n] = ROL16(key[n],1); + KLi2[n] = Kprime[(n+2)&0x7]; + KOi1[n] = ROL16(key[(n+1)&0x7],5); + KOi2[n] = ROL16(key[(n+5)&0x7],8); + KOi3[n] = ROL16(key[(n+6)&0x7],13); + KIi1[n] = Kprime[(n+4)&0x7]; + KIi2[n] = Kprime[(n+3)&0x7]; + KIi3[n] = Kprime[(n+7)&0x7]; + } +} +/*--------------------------------------------------------------------- + * e n d o f k a s u m i . c + *---------------------------------------------------------------------*/ + +/*------------------------------------------------------------------- + * F8 - Confidentiality Algorithm + *------------------------------------------------------------------- + * + * A sample implementation of f8, the 3GPP Confidentiality algorithm. + * + * This has been coded for clarity, not necessarily for efficiency. + * + * This will compile and run correctly on both Intel (little endian) + * and Sparc (big endian) machines. (Compilers used supported 32-bit ints) + * + * Version 1.0 05 November 1999 + * + *-------------------------------------------------------------------*/ + +/*--------------------------------------------------------- + * f8() + * Given key, count, bearer, direction, data, + * and bit length encrypt the bit stream + *---------------------------------------------------------*/ +void kasumi_f8(u8 *key, u32 count, u32 bearer, u32 dir, u8 *data, int length) +{ + REGISTER64 A; /* the modifier */ + REGISTER64 temp; /* The working register */ + int i, n; + int lastbits = (8-(length%8)) % 8; + u8 ModKey[16]; /* Modified key */ + u16 blkcnt; /* The block counter */ + + /* Start by building our global modifier */ + temp.b32[0] = temp.b32[1] = 0; + A.b32[0] = A.b32[1] = 0; + + /* initialise register in an endian correct manner*/ + A.b8[0] = (u8) (count>>24); + A.b8[1] = (u8) (count>>16); + A.b8[2] = (u8) (count>>8); + A.b8[3] = (u8) (count); + A.b8[4] = (u8) (bearer<<3); + A.b8[4] |= (u8) (dir<<2); + + /* Construct the modified key and then "kasumi" A */ + for( n=0; n<16; ++n ) + ModKey[n] = (u8)(key[n] ^ 0x55); + kasumi_key_schedule( ModKey ); + + kasumi( A.b8 ); /* First encryption to create modifier */ + + /* Final initialisation steps */ + blkcnt = 0; + kasumi_key_schedule( key ); + + /* Now run the block cipher */ + while( length > 0 ) + { + /* First we calculate the next 64-bits of keystream */ + + /* XOR in A and BLKCNT to last value */ + temp.b32[0] ^= A.b32[0]; + temp.b32[1] ^= A.b32[1]; + temp.b8[7] ^= (u8) blkcnt; + temp.b8[6] ^= (u8) (blkcnt>>8); + + /* KASUMI it to produce the next block of keystream */ + kasumi( temp.b8 ); + + /* Set to the number of bytes of input data * + * we have to modify. (=8 if length <= 64) */ + if( length >= 64 ) + n = 8; + else + n = (length+7)/8; + + /* XOR the keystream with the input data stream */ + for( i=0; i holds our chaining value... * + * is the running XOR of all KASUMI o/ps */ + for( n=0; n<4; ++n ) + { + A.b8[n] = (u8)(count>>(24-(n*8))); + A.b8[n+4] = (u8)(fresh>>(24-(n*8))); + } + kasumi( A.b8 ); + B.b32[0] = A.b32[0]; + B.b32[1] = A.b32[1]; + + /* Now run the blocks until we reach the last block */ + while( length >= 64 ) + { + for( n=0; n<8; ++n ) + A.b8[n] ^= *data++; + kasumi( A.b8 ); + length -= 64; + B.b32[0] ^= A.b32[0]; /* running XOR across */ + B.b32[1] ^= A.b32[1]; /* the block outputs */ + } + + /* Process whole bytes in the last block */ + n = 0; + while( length >=8 ) + { + A.b8[n++] ^= *data++; + length -= 8; + } + + /* Now add the direction bit to the input bit stream * + * If length (which holds the # of data bits in the * + * last byte) is non-zero we add it in, otherwise * + * it has to start a new byte. */ + if( length ) + { + i = *data; + if( dir ) + i |= FinalBit[length]; + } + else + i = dir ? 0x80 : 0; + + A.b8[n++] ^= (u8)i; + + /* Now add in the final '1' bit. The problem here * + * is if the message length happens to be n*64-1. * + * If so we need to process this block and then * + * create a new input block of 0x8000000000000000. */ + if( (length==7) && (n==8) ) /* then we've filled the block */ + { + kasumi( A.b8 ); + B.b32[0] ^= A.b32[0]; /* running XOR across */ + B.b32[1] ^= A.b32[1]; /* the block outputs */ + + A.b8[0] ^= 0x80; /* toggle first bit */ + i = 0x80; + n = 1; + } + else + { + if( length == 7 ) /* we finished off the last byte */ + A.b8[n] ^= 0x80; /* so start a new one..... */ + else + A.b8[n-1] ^= FinalBit[length+1]; + } + + kasumi( A.b8 ); + B.b32[0] ^= A.b32[0]; /* running XOR across */ + B.b32[1] ^= A.b32[1]; /* the block outputs */ + + /* Final step is to KASUMI what we have using the * + * key XORd with 0xAAAA..... */ + for( n=0; n<16; ++n ) + ModKey[n] = (u8)*key++ ^ 0xAA; + kasumi_key_schedule( ModKey ); + kasumi( B.b8 ); + + /* We return the left-most 32-bits of the result */ + + for( n=0; n<4; ++n ) + mac_i[n] = B.b8[n]; + + return( mac_i ); +} + +/*----------------------------------------------------------- + * e n d o f f 9 . c + *-----------------------------------------------------------*/ diff --git a/lib/crypt/kasumi.h b/lib/crypt/kasumi.h new file mode 100644 index 000000000..ec7d91de5 --- /dev/null +++ b/lib/crypt/kasumi.h @@ -0,0 +1,68 @@ +/*--------------------------------------------------------- + * Kasumi.h + *---------------------------------------------------------*/ + +#if !defined(OGS_CRYPT_INSIDE) && !defined(OGS_CRYPT_COMPILATION) +#error "This header cannot be included directly." +#endif + +#ifndef KASUMI_H +#define KASUMI_H + +#include "ogs-core.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef uint8_t u8; +typedef uint16_t u16; +/* original reference is using long, which is 64 bits on 64 bits system + I changed to int to make it work on x86 32 / 64 bits system +typedef unsigned long u32; +*/ +typedef uint32_t u32; + + +/*------- unions: used to remove "endian" issues ------------------------*/ + +typedef union { + u32 b32; + u16 b16[2]; + u8 b8[4]; +} REGISTER32; /* is redefining DWORD */ + +typedef union { + u16 b16; + u8 b8[2]; +} REGISTER16; /* is redefining WORD */ + +/*----- a 64-bit structure to help with endian issues -----*/ + +typedef union { + u32 b32[2]; + u16 b16[4]; + u8 b8[8]; +} REGISTER64; + +/*------------- prototypes -------------------------------- + * take care: length (in f8 and f9) is always in bits + *---------------------------------------------------------*/ + +/* initialize the 128 bits key into the cipher */ +void kasumi_key_schedule( u8 *key ); + +/* cipher a block of 64 bits */ +void kasumi( u8 *data ); + +/* cipher a whole message in 3GPP -counter- mode */ +void kasumi_f8( u8 *key, u32 count, u32 bearer, u32 dir, u8 *data, int length ); + +/* compute a 3GPP MAC on a message */ +u8* kasumi_f9( u8 *key, u32 count, u32 fresh, u32 dir, u8 *data, int length ); + +#ifdef __cplusplus +} +#endif + +#endif /* KASUMI_H */ diff --git a/lib/crypt/meson.build b/lib/crypt/meson.build new file mode 100644 index 000000000..dc0c02c15 --- /dev/null +++ b/lib/crypt/meson.build @@ -0,0 +1,57 @@ +# Copyright (C) 2019 by Sukchan Lee + +# This file is part of Open5GS. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +libcrypt_sources = files(''' + ogs-crypt.h + + ogs-aes.h + ogs-aes-cmac.h + ogs-sha1.h + ogs-sha1-hmac.h + ogs-sha2.h + ogs-sha2-hmac.h + milenage.h + snow-3g.h + zuc.h + kasumi.h + + ogs-aes.c + ogs-aes-cmac.c + ogs-sha1.c + ogs-sha1-hmac.c + ogs-sha2.c + ogs-sha2-hmac.c + milenage.c + snow-3g.c + zuc.c + kasumi.c +'''.split()) + +libcrypt_inc = include_directories('.') + +libcrypt = library('ogscrypt', + sources : libcrypt_sources, + version : libogslib_version, + c_args : '-DOGS_CRYPT_COMPILATION', + include_directories : [libcrypt_inc, libinc], + dependencies : libcore_dep, + install : true) + +libcrypt_dep = declare_dependency( + link_with : libcrypt, + include_directories : [libcrypt_inc, libinc], + dependencies : libcore_dep) diff --git a/lib/crypt/milenage.c b/lib/crypt/milenage.c new file mode 100644 index 000000000..229dca66d --- /dev/null +++ b/lib/crypt/milenage.c @@ -0,0 +1,366 @@ +/* + * 3GPP AKA - Milenage algorithm (3GPP TS 35.205, .206, .207, .208) + * Copyright (c) 2006-2007 + * + * This software may be distributed under the terms of the BSD license. + * See README for more details. + * + * This file implements an example authentication algorithm defined for 3GPP + * AKA. This can be used to implement a simple HLR/AuC into hlr_auc_gw to allow + * EAP-AKA to be tested properly with real USIM cards. + * + * This implementations assumes that the r1..r5 and c1..c5 constants defined in + * TS 35.206 are used, i.e., r1=64, r2=0, r3=32, r4=64, r5=96, c1=00..00, + * c2=00..01, c3=00..02, c4=00..04, c5=00..08. The block cipher is assumed to + * be AES (Rijndael). + */ +#include "ogs-crypt.h" + +#include "milenage.h" + +#define os_memcpy memcpy +#define os_memcmp memcmp +#define os_memcmp_const memcmp + +int aes_128_encrypt_block(const uint8_t *key, + const uint8_t *in, uint8_t *out); + +int aes_128_encrypt_block(const uint8_t *key, + const uint8_t *in, uint8_t *out) +{ + const int key_bits = 128; + unsigned int rk[OGS_AES_RKLENGTH(128)]; + int nrounds; + + nrounds = ogs_aes_setup_enc(rk, key, key_bits); + ogs_aes_encrypt(rk, nrounds, in, out); + + return 0; +} + +/** + * milenage_f1 - Milenage f1 and f1* algorithms + * @opc: OPc = 128-bit value derived from OP and K + * @k: K = 128-bit subscriber key + * @_rand: RAND = 128-bit random challenge + * @sqn: SQN = 48-bit sequence number + * @amf: AMF = 16-bit authentication management field + * @mac_a: Buffer for MAC-A = 64-bit network authentication code, or %NULL + * @mac_s: Buffer for MAC-S = 64-bit resync authentication code, or %NULL + * Returns: 0 on success, -1 on failure + */ +int milenage_f1(const uint8_t *opc, const uint8_t *k, + const uint8_t *_rand, const uint8_t *sqn, + const uint8_t *amf, uint8_t *mac_a, uint8_t *mac_s) +{ + uint8_t tmp1[16], tmp2[16], tmp3[16]; + int i; + + /* tmp1 = TEMP = E_K(RAND XOR OP_C) */ + for (i = 0; i < 16; i++) + tmp1[i] = _rand[i] ^ opc[i]; + if (aes_128_encrypt_block(k, tmp1, tmp1)) + return -1; + + /* tmp2 = IN1 = SQN || AMF || SQN || AMF */ + os_memcpy(tmp2, sqn, 6); + os_memcpy(tmp2 + 6, amf, 2); + os_memcpy(tmp2 + 8, tmp2, 8); + + /* OUT1 = E_K(TEMP XOR rot(IN1 XOR OP_C, r1) XOR c1) XOR OP_C */ + + /* rotate (tmp2 XOR OP_C) by r1 (= 0x40 = 8 bytes) */ + for (i = 0; i < 16; i++) + tmp3[(i + 8) % 16] = tmp2[i] ^ opc[i]; + /* XOR with TEMP = E_K(RAND XOR OP_C) */ + for (i = 0; i < 16; i++) + tmp3[i] ^= tmp1[i]; + /* XOR with c1 (= ..00, i.e., NOP) */ + + /* f1 || f1* = E_K(tmp3) XOR OP_c */ + if (aes_128_encrypt_block(k, tmp3, tmp1)) + return -1; + for (i = 0; i < 16; i++) + tmp1[i] ^= opc[i]; + if (mac_a) + os_memcpy(mac_a, tmp1, 8); /* f1 */ + if (mac_s) + os_memcpy(mac_s, tmp1 + 8, 8); /* f1* */ + return 0; +} + + +/** + * milenage_f2345 - Milenage f2, f3, f4, f5, f5* algorithms + * @opc: OPc = 128-bit value derived from OP and K + * @k: K = 128-bit subscriber key + * @_rand: RAND = 128-bit random challenge + * @res: Buffer for RES = 64-bit signed response (f2), or %NULL + * @ck: Buffer for CK = 128-bit confidentiality key (f3), or %NULL + * @ik: Buffer for IK = 128-bit integrity key (f4), or %NULL + * @ak: Buffer for AK = 48-bit anonymity key (f5), or %NULL + * @akstar: Buffer for AK = 48-bit anonymity key (f5*), or %NULL + * Returns: 0 on success, -1 on failure + */ +int milenage_f2345(const uint8_t *opc, const uint8_t *k, + const uint8_t *_rand, uint8_t *res, uint8_t *ck, + uint8_t *ik, uint8_t *ak, uint8_t *akstar) +{ + uint8_t tmp1[16], tmp2[16], tmp3[16]; + int i; + + /* tmp2 = TEMP = E_K(RAND XOR OP_C) */ + for (i = 0; i < 16; i++) + tmp1[i] = _rand[i] ^ opc[i]; + if (aes_128_encrypt_block(k, tmp1, tmp2)) + return -1; + + /* OUT2 = E_K(rot(TEMP XOR OP_C, r2) XOR c2) XOR OP_C */ + /* OUT3 = E_K(rot(TEMP XOR OP_C, r3) XOR c3) XOR OP_C */ + /* OUT4 = E_K(rot(TEMP XOR OP_C, r4) XOR c4) XOR OP_C */ + /* OUT5 = E_K(rot(TEMP XOR OP_C, r5) XOR c5) XOR OP_C */ + + /* f2 and f5 */ + /* rotate by r2 (= 0, i.e., NOP) */ + for (i = 0; i < 16; i++) + tmp1[i] = tmp2[i] ^ opc[i]; + tmp1[15] ^= 1; /* XOR c2 (= ..01) */ + /* f5 || f2 = E_K(tmp1) XOR OP_c */ + if (aes_128_encrypt_block(k, tmp1, tmp3)) + return -1; + for (i = 0; i < 16; i++) + tmp3[i] ^= opc[i]; + if (res) + os_memcpy(res, tmp3 + 8, 8); /* f2 */ + if (ak) + os_memcpy(ak, tmp3, 6); /* f5 */ + + /* f3 */ + if (ck) { + /* rotate by r3 = 0x20 = 4 bytes */ + for (i = 0; i < 16; i++) + tmp1[(i + 12) % 16] = tmp2[i] ^ opc[i]; + tmp1[15] ^= 2; /* XOR c3 (= ..02) */ + if (aes_128_encrypt_block(k, tmp1, ck)) + return -1; + for (i = 0; i < 16; i++) + ck[i] ^= opc[i]; + } + + /* f4 */ + if (ik) { + /* rotate by r4 = 0x40 = 8 bytes */ + for (i = 0; i < 16; i++) + tmp1[(i + 8) % 16] = tmp2[i] ^ opc[i]; + tmp1[15] ^= 4; /* XOR c4 (= ..04) */ + if (aes_128_encrypt_block(k, tmp1, ik)) + return -1; + for (i = 0; i < 16; i++) + ik[i] ^= opc[i]; + } + + /* f5* */ + if (akstar) { + /* rotate by r5 = 0x60 = 12 bytes */ + for (i = 0; i < 16; i++) + tmp1[(i + 4) % 16] = tmp2[i] ^ opc[i]; + tmp1[15] ^= 8; /* XOR c5 (= ..08) */ + if (aes_128_encrypt_block(k, tmp1, tmp1)) + return -1; + for (i = 0; i < 6; i++) + akstar[i] = tmp1[i] ^ opc[i]; + } + + return 0; +} + + +/** + * milenage_generate - Generate AKA AUTN,IK,CK,RES + * @opc: OPc = 128-bit operator variant algorithm configuration field (encr.) + * @amf: AMF = 16-bit authentication management field + * @k: K = 128-bit subscriber key + * @sqn: SQN = 48-bit sequence number + * @_rand: RAND = 128-bit random challenge + * @autn: Buffer for AUTN = 128-bit authentication token + * @ik: Buffer for IK = 128-bit integrity key (f4), or %NULL + * @ck: Buffer for CK = 128-bit confidentiality key (f3), or %NULL + * @res: Buffer for RES = 64-bit signed response (f2), or %NULL + * @res_len: Max length for res; set to used length or 0 on failure + */ +void milenage_generate(const uint8_t *opc, const uint8_t *amf, + const uint8_t *k, const uint8_t *sqn, const uint8_t *_rand, + uint8_t *autn, uint8_t *ik, uint8_t *ck, uint8_t *ak, + uint8_t *res, size_t *res_len) +{ + int i; + uint8_t mac_a[8]; + + if (*res_len < 8) { + *res_len = 0; + return; + } + if (milenage_f1(opc, k, _rand, sqn, amf, mac_a, NULL) || + milenage_f2345(opc, k, _rand, res, ck, ik, ak, NULL)) { + *res_len = 0; + return; + } + *res_len = 8; + + /* AUTN = (SQN ^ AK) || AMF || MAC */ + for (i = 0; i < 6; i++) + autn[i] = sqn[i] ^ ak[i]; + os_memcpy(autn + 6, amf, 2); + os_memcpy(autn + 8, mac_a, 8); +} + +/** + * milenage_auts - Milenage AUTS validation + * @opc: OPc = 128-bit operator variant algorithm configuration field (encr.) + * @k: K = 128-bit subscriber key + * @_rand: RAND = 128-bit random challenge + * @auts: AUTS = 112-bit authentication token from client + * @sqn: Buffer for SQN = 48-bit sequence number + * Returns: 0 = success (sqn filled), -1 on failure + */ +int milenage_auts(const uint8_t *opc, const uint8_t *k, + const uint8_t *_rand, const uint8_t *auts, uint8_t *sqn) +{ + uint8_t amf[2] = { 0x00, 0x00 }; /* TS 33.102 v7.0.0, 6.3.3 */ + uint8_t ak[6], mac_s[8]; + int i; + + if (milenage_f2345(opc, k, _rand, NULL, NULL, NULL, NULL, ak)) + return -1; + for (i = 0; i < 6; i++) + sqn[i] = auts[i] ^ ak[i]; + if (milenage_f1(opc, k, _rand, sqn, amf, NULL, mac_s) || + os_memcmp_const(mac_s, auts + 6, 8) != 0) + return -1; + return 0; +} + + +/** + * gsm_milenage - Generate GSM-Milenage (3GPP TS 55.205) authentication triplet + * @opc: OPc = 128-bit operator variant algorithm configuration field (encr.) + * @k: K = 128-bit subscriber key + * @_rand: RAND = 128-bit random challenge + * @sres: Buffer for SRES = 32-bit SRES + * @kc: Buffer for Kc = 64-bit Kc + * Returns: 0 on success, -1 on failure + */ +int gsm_milenage(const uint8_t *opc, const uint8_t *k, + const uint8_t *_rand, uint8_t *sres, uint8_t *kc) +{ + uint8_t res[8], ck[16], ik[16]; + int i; + + if (milenage_f2345(opc, k, _rand, res, ck, ik, NULL, NULL)) + return -1; + + for (i = 0; i < 8; i++) + kc[i] = ck[i] ^ ck[i + 8] ^ ik[i] ^ ik[i + 8]; + +#ifdef GSM_MILENAGE_ALT_SRES + os_memcpy(sres, res, 4); +#else /* GSM_MILENAGE_ALT_SRES */ + for (i = 0; i < 4; i++) + sres[i] = res[i] ^ res[i + 4]; +#endif /* GSM_MILENAGE_ALT_SRES */ + return 0; +} + + +/** + * milenage_generate - Generate AKA AUTN,IK,CK,RES + * @opc: OPc = 128-bit operator variant algorithm configuration field (encr.) + * @k: K = 128-bit subscriber key + * @sqn: SQN = 48-bit sequence number + * @_rand: RAND = 128-bit random challenge + * @autn: AUTN = 128-bit authentication token + * @ik: Buffer for IK = 128-bit integrity key (f4), or %NULL + * @ck: Buffer for CK = 128-bit confidentiality key (f3), or %NULL + * @res: Buffer for RES = 64-bit signed response (f2), or %NULL + * @res_len: Variable that will be set to RES length + * @auts: 112-bit buffer for AUTS + * Returns: 0 on success, -1 on failure, or -2 on synchronization failure + */ +int milenage_check(const uint8_t *opc, const uint8_t *k, + const uint8_t *sqn, const uint8_t *_rand, const uint8_t *autn, + uint8_t *ik, uint8_t *ck, uint8_t *res, size_t *res_len, + uint8_t *auts) +{ + int i; + uint8_t mac_a[8], ak[6], rx_sqn[6]; + const uint8_t *amf; + + ogs_log_print(OGS_LOG_INFO, "Milenage: AUTN\n"); + ogs_log_hexdump(OGS_LOG_INFO, autn, 16); + ogs_log_print(OGS_LOG_INFO, "Milenage: RAND\n"); + ogs_log_hexdump(OGS_LOG_INFO, _rand, 16); + + if (milenage_f2345(opc, k, _rand, res, ck, ik, ak, NULL)) + return -1; + + *res_len = 8; + ogs_log_print(OGS_LOG_INFO, "Milenage: RES\n"); + ogs_log_hexdump(OGS_LOG_INFO, res, *res_len); + ogs_log_print(OGS_LOG_INFO, "Milenage: CK\n"); + ogs_log_hexdump(OGS_LOG_INFO, ck, 16); + ogs_log_print(OGS_LOG_INFO, "Milenage: IK\n"); + ogs_log_hexdump(OGS_LOG_INFO, ik, 16); + ogs_log_print(OGS_LOG_INFO, "Milenage: AK\n"); + ogs_log_hexdump(OGS_LOG_INFO, ak, 6); + + /* AUTN = (SQN ^ AK) || AMF || MAC */ + for (i = 0; i < 6; i++) + rx_sqn[i] = autn[i] ^ ak[i]; + ogs_log_print(OGS_LOG_INFO, "Milenage: SQN\n"); + ogs_log_hexdump(OGS_LOG_INFO, rx_sqn, 6); + + if (os_memcmp(rx_sqn, sqn, 6) <= 0) { + uint8_t auts_amf[2] = { 0x00, 0x00 }; /* TS 33.102 v7.0.0, 6.3.3 */ + if (milenage_f2345(opc, k, _rand, NULL, NULL, NULL, NULL, ak)) + return -1; + ogs_log_print(OGS_LOG_INFO, "Milenage: AK*\n"); + ogs_log_hexdump(OGS_LOG_INFO, ak, 6); + for (i = 0; i < 6; i++) + auts[i] = sqn[i] ^ ak[i]; + if (milenage_f1(opc, k, _rand, sqn, auts_amf, NULL, auts + 6)) + return -1; + ogs_log_print(OGS_LOG_INFO, "Milenage: AUTS*\n"); + ogs_log_hexdump(OGS_LOG_INFO, auts, 14); + return -2; + } + + amf = autn + 6; + ogs_log_print(OGS_LOG_INFO, "Milenage: AMF\n"); + ogs_log_hexdump(OGS_LOG_INFO, amf, 2); + if (milenage_f1(opc, k, _rand, rx_sqn, amf, mac_a, NULL)) + return -1; + + ogs_log_print(OGS_LOG_INFO, "Milenage: MAC_A\n"); + ogs_log_hexdump(OGS_LOG_INFO, mac_a, 8); + + if (os_memcmp_const(mac_a, autn + 8, 8) != 0) { + ogs_log_print(OGS_LOG_INFO, "Milenage: MAC mismatch\n"); + ogs_log_print(OGS_LOG_INFO, "Milenage: Received MAC_A\n"); + ogs_log_hexdump(OGS_LOG_INFO, autn + 8, 8); + return -1; + } + + return 0; +} + +void milenage_opc(const uint8_t *k, const uint8_t *op, uint8_t *opc) +{ + int i; + + aes_128_encrypt_block(k, op, opc); + + for (i = 0; i < 16; i++) + { + opc[i] ^= op[i]; + } +} diff --git a/lib/crypt/milenage.h b/lib/crypt/milenage.h new file mode 100644 index 000000000..61e7264dc --- /dev/null +++ b/lib/crypt/milenage.h @@ -0,0 +1,45 @@ +/* + * UMTS AKA - Milenage algorithm (3GPP TS 35.205, .206, .207, .208) + * Copyright (c) 2006-2007 + * + * This software may be distributed under the terms of the BSD license. + * See README for more details. + */ + +#if !defined(OGS_CRYPT_INSIDE) && !defined(OGS_CRYPT_COMPILATION) +#error "This header cannot be included directly." +#endif + +#ifndef MILENAGE_H +#define MILENAGE_H + +#ifdef __cplusplus +extern "C" { +#endif + +void milenage_generate(const uint8_t *opc, const uint8_t *amf, + const uint8_t *k, const uint8_t *sqn, const uint8_t *_rand, + uint8_t *autn, uint8_t *ik, uint8_t *ck, uint8_t *ak, + uint8_t *res, size_t *res_len); +int milenage_auts(const uint8_t *opc, const uint8_t *k, + const uint8_t *_rand, const uint8_t *auts, uint8_t *sqn); +int gsm_milenage(const uint8_t *opc, const uint8_t *k, + const uint8_t *_rand, uint8_t *sres, uint8_t *kc); +int milenage_check(const uint8_t *opc, const uint8_t *k, + const uint8_t *sqn, const uint8_t *_rand, const uint8_t *autn, + uint8_t *ik, uint8_t *ck, uint8_t *res, size_t *res_len, + uint8_t *auts); +int milenage_f1(const uint8_t *opc, const uint8_t *k, + const uint8_t *_rand, const uint8_t *sqn, const uint8_t *amf, + uint8_t *mac_a, uint8_t *mac_s); +int milenage_f2345(const uint8_t *opc, const uint8_t *k, + const uint8_t *_rand, uint8_t *res, uint8_t *ck, uint8_t *ik, + uint8_t *ak, uint8_t *akstar); + +void milenage_opc(const uint8_t *k, const uint8_t *op, uint8_t *opc); + +#ifdef __cplusplus +} +#endif + +#endif /* MILENAGE_H */ diff --git a/lib/crypt/ogs-aes-cmac.c b/lib/crypt/ogs-aes-cmac.c new file mode 100644 index 000000000..91740f646 --- /dev/null +++ b/lib/crypt/ogs-aes-cmac.c @@ -0,0 +1,288 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#include "ogs-crypt.h" + +#if (OGS_AES_BLOCK_SIZE != 16) +#error "Wrong AES block size" +#endif + +/* From RFC 4493 + + +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + + Algorithm Generate_Subkey + + +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + + + + + Input : K (128-bit key) + + + Output : K1 (128-bit first subkey) + + + K2 (128-bit second subkey) + + +-------------------------------------------------------------------+ + + + + + Constants: const_Zero is 0x00000000000000000000000000000000 + + + const_Rb is 0x00000000000000000000000000000087 + + + Variables: L for output of AES-128 applied to 0^128 + + + + + + Step 1. L := AES-128(K, const_Zero); + + + Step 2. if MSB(L) is equal to 0 + + + then K1 := L << 1; + + + else K1 := (L << 1) XOR const_Rb; + + + Step 3. if MSB(K1) is equal to 0 + + + then K2 := K1 << 1; + + + else K2 := (K1 << 1) XOR const_Rb; + + + Step 4. return K1, K2; + + + + + +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ + +static int _generate_subkey(uint8_t *k1, uint8_t *k2, + const uint8_t *key) +{ + uint8_t zero[16] = { + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 + }; + uint8_t rb[16] = { + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x87 + }; + uint8_t L[16]; + + uint32_t rk[OGS_AES_RKLENGTH(OGS_AES_MAX_KEY_BITS)]; + int i, nrounds; + + /* Step 1. L := AES-128(K, const_Zero) */ + nrounds = ogs_aes_setup_enc(rk, key, 128); + ogs_aes_encrypt(rk, nrounds, zero, L); + + /* Step 2. if MSB(L) is equal to 0 */ + if ((L[0] & 0x80) == 0) + { + /* then k1 := L << 1; */ + for (i = 0; i < 15; i++) + k1[i] = ((L[i] << 1) & 0xfe) | ((L[i + 1] & 0x80) ? 1 : 0); + k1[15] = ((L[15] << 1) & 0xfe); + } + else + { + /* else k1 := (L << 1) XOR const_Rb; */ + for (i = 0; i < 15; i++) + k1[i] = (((L[i] << 1) & 0xfe) | ((L[i + 1] & 0x80) ? 1 : 0)) + ^ rb[i]; + k1[15] = ((L[15] << 1) & 0xfe) ^ rb[15]; + } + + /* Step 3. if MSB(k1) is equal to 0 */ + if ((k1[0] & 0x80) == 0) + { + /* then k2 := k2 << 1; */ + for (i = 0; i < 15; i++) + k2[i] = ((k1[i] << 1) & 0xfe) | ((k1[i + 1] & 0x80) ? 1 : 0); + k2[15] = ((k1[15] << 1) & 0xfe); + } + else + { + /* else k2 := (k2 << 1) XOR const_Rb; */ + for (i = 0; i < 15; i++) + k2[i] = (((k1[i] << 1) & 0xfe) | ((k1[i + 1] & 0x80) ? 1 : 0)) + ^ rb[i]; + k2[15] = ((k1[15] << 1) & 0xfe) ^ rb[15]; + } + + return OGS_OK; +} + +/* From RFC 4493 + + +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + + Algorithm AES-CMAC + + +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + + + + + Input : K ( 128-bit key ) + + + : M ( message to be authenticated ) + + + : len ( length of the message in octets ) + + + Output : T ( message authentication code ) + + + + + +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + + Constants: const_Zero is 0x00000000000000000000000000000000 + + + const_Bsize is 16 + + + + + + Variables: K1, K2 for 128-bit subkeys + + + M_i is the i-th block (i=1..ceil(len/const_Bsize)) + + + M_last is the last block xor-ed with K1 or K2 + + + n for number of blocks to be processed + + + r for number of octets of last block + + + flag for denoting if last block is complete or not + + + + + + Step 1. (K1,K2) := Generate_Subkey(K); + + + Step 2. n := ceil(len/const_Bsize); + + + Step 3. if n = 0 + + + then + + + n := 1; + + + flag := false; + + + else + + + if len mod const_Bsize is 0 + + + then flag := true; + + + else flag := false; + + + + + + Step 4. if flag is true + + + then M_last := M_n XOR K1; + + + else M_last := padding(M_n) XOR K2; + + + Step 5. X := const_Zero; + + + Step 6. for i := 1 to n-1 do + + + begin + + + Y := X XOR M_i; + + + X := AES-128(K,Y); + + + end + + + Y := M_last XOR X; + + + T := AES-128(K,Y); + + + Step 7. return T; + + +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ + +int ogs_aes_cmac_calculate(uint8_t *cmac, const uint8_t *key, + const uint8_t *msg, const uint32_t len) +{ + uint8_t x[16] = { + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 + }; + uint8_t y[16], m_last[16]; + uint8_t k1[16], k2[16]; + int i, j, n, bs, flag; + uint32_t rk[OGS_AES_RKLENGTH(OGS_AES_MAX_KEY_BITS)]; + int nrounds; + + ogs_assert(cmac); + ogs_assert(key); + ogs_assert(msg); + + /* Step 1. (K1,K2) := Generate_Subkey(K); */ + _generate_subkey(k1, k2, key); + + /* Step 2. n := ceil(len/const_Bsize); */ + n = (len + 15) / OGS_AES_BLOCK_SIZE; + + /* Step 3. if n = 0 + then + n := 1; + flag := false; + else + if len mod const_Bsize is 0 + then flag := true; + else flag := false; + */ + if (n == 0) + { + n = 1; + flag = 0; + } + else + { + if (len % OGS_AES_BLOCK_SIZE == 0) + flag = 1; + else + flag = 0; + } + + /* Step 4. if flag is true + then M_last := M_n XOR K1; + else M_last := padding(M_n) XOR K2; + */ + bs = (n - 1) * OGS_AES_BLOCK_SIZE; + + if (flag) + { + for (i = 0; i < 16; i++) + m_last[i] = msg[bs + i] ^ k1[i]; + } + else + { + for (i = 0; i < len % OGS_AES_BLOCK_SIZE; i++) + m_last[i] = msg[bs + i] ^ k2[i]; + + m_last[i] = 0x80 ^ k2[i]; + + for (i = i + 1; i < OGS_AES_BLOCK_SIZE; i++) + m_last[i] = 0x00 ^ k2[i]; + } + + + /* Step 5. X := const_Zero; */ + /* Step 6. for i := 1 to n-1 do + begin + Y := X XOR M_i; + X := AES-128(K,Y); + end + Y := M_last XOR X; + T := AES-128(K,Y); + */ + + nrounds = ogs_aes_setup_enc(rk, key, 128); + + for (i = 0; i <= n - 2; i++) + { + bs = i * OGS_AES_BLOCK_SIZE; + for (j = 0; j < 16; j++) + y[j] = x[j] ^ msg[bs + j]; + ogs_aes_encrypt(rk, nrounds, y, x); + } + + bs = (n - 1) * OGS_AES_BLOCK_SIZE; + for (j = 0; j < 16; j++) + y[j] = m_last[j] ^ x[j]; + ogs_aes_encrypt(rk, nrounds, y, cmac); + + return OGS_OK; +} + +/* From RFC 4493 + + +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + + Algorithm Verify_MAC + + +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + + + + + Input : K ( 128-bit Key ) + + + : M ( message to be verified ) + + + : len ( length of the message in octets ) + + + : T' ( the received MAC to be verified ) + + + Output : INVALID or VALID + + + + + +-------------------------------------------------------------------+ + + + + + Step 1. T* := AES-CMAC(K,M,len); + + + Step 2. if T* is equal to T' + + + then + + + return VALID; + + + else + + + return INVALID; + + +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ + +int ogs_aes_cmac_verify(uint8_t *cmac, const uint8_t *key, + const uint8_t *msg, const uint32_t len) +{ + int rv; + uint8_t cmac_calc[16]; + + rv = ogs_aes_cmac_calculate(cmac_calc, key, msg, len); + if (rv != OGS_OK) + return rv; + + if (memcmp(cmac_calc, cmac, 16) != 0) + return OGS_ERR_INVALID_CMAC; + + return OGS_OK; +} + diff --git a/lib/crypt/ogs-aes-cmac.h b/lib/crypt/ogs-aes-cmac.h new file mode 100644 index 000000000..f16f65e89 --- /dev/null +++ b/lib/crypt/ogs-aes-cmac.h @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#if !defined(OGS_CRYPT_INSIDE) && !defined(OGS_CRYPT_COMPILATION) +#error "This header cannot be included directly." +#endif + +#ifndef OGS_AES_CMAC_H +#define OGS_AES_CMAC_H + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Caculate CMAC value + * + * @param cmac + * @param key + * @param msg + * @param len + * + * @return OGS_OK + * OGS_ERROR + */ +int ogs_aes_cmac_calculate(uint8_t *cmac, const uint8_t *key, + const uint8_t *msg, const uint32_t len); + +/** + * Verify CMAC value + * + * @param cmac + * @param key + * @param msg + * @param len + * + * @return OGS_OK + * OGS_ERROR + * OGS_ERR_INVALID_CMAC + */ +#define OGS_ERR_INVALID_CMAC -2 +int ogs_aes_cmac_verify(uint8_t *cmac, const uint8_t *key, + const uint8_t *msg, const uint32_t len); + +#ifdef __cplusplus +} +#endif + +#endif /* OGS_AES_CMAC_H */ diff --git a/lib/crypt/ogs-aes.c b/lib/crypt/ogs-aes.c new file mode 100644 index 000000000..96da5060b --- /dev/null +++ b/lib/crypt/ogs-aes.c @@ -0,0 +1,1467 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "ogs-crypt.h" + +#define FULL_UNROLL + +static const uint32_t Te0[256] = +{ + 0xc66363a5U, 0xf87c7c84U, 0xee777799U, 0xf67b7b8dU, + 0xfff2f20dU, 0xd66b6bbdU, 0xde6f6fb1U, 0x91c5c554U, + 0x60303050U, 0x02010103U, 0xce6767a9U, 0x562b2b7dU, + 0xe7fefe19U, 0xb5d7d762U, 0x4dababe6U, 0xec76769aU, + 0x8fcaca45U, 0x1f82829dU, 0x89c9c940U, 0xfa7d7d87U, + 0xeffafa15U, 0xb25959ebU, 0x8e4747c9U, 0xfbf0f00bU, + 0x41adadecU, 0xb3d4d467U, 0x5fa2a2fdU, 0x45afafeaU, + 0x239c9cbfU, 0x53a4a4f7U, 0xe4727296U, 0x9bc0c05bU, + 0x75b7b7c2U, 0xe1fdfd1cU, 0x3d9393aeU, 0x4c26266aU, + 0x6c36365aU, 0x7e3f3f41U, 0xf5f7f702U, 0x83cccc4fU, + 0x6834345cU, 0x51a5a5f4U, 0xd1e5e534U, 0xf9f1f108U, + 0xe2717193U, 0xabd8d873U, 0x62313153U, 0x2a15153fU, + 0x0804040cU, 0x95c7c752U, 0x46232365U, 0x9dc3c35eU, + 0x30181828U, 0x379696a1U, 0x0a05050fU, 0x2f9a9ab5U, + 0x0e070709U, 0x24121236U, 0x1b80809bU, 0xdfe2e23dU, + 0xcdebeb26U, 0x4e272769U, 0x7fb2b2cdU, 0xea75759fU, + 0x1209091bU, 0x1d83839eU, 0x582c2c74U, 0x341a1a2eU, + 0x361b1b2dU, 0xdc6e6eb2U, 0xb45a5aeeU, 0x5ba0a0fbU, + 0xa45252f6U, 0x763b3b4dU, 0xb7d6d661U, 0x7db3b3ceU, + 0x5229297bU, 0xdde3e33eU, 0x5e2f2f71U, 0x13848497U, + 0xa65353f5U, 0xb9d1d168U, 0x00000000U, 0xc1eded2cU, + 0x40202060U, 0xe3fcfc1fU, 0x79b1b1c8U, 0xb65b5bedU, + 0xd46a6abeU, 0x8dcbcb46U, 0x67bebed9U, 0x7239394bU, + 0x944a4adeU, 0x984c4cd4U, 0xb05858e8U, 0x85cfcf4aU, + 0xbbd0d06bU, 0xc5efef2aU, 0x4faaaae5U, 0xedfbfb16U, + 0x864343c5U, 0x9a4d4dd7U, 0x66333355U, 0x11858594U, + 0x8a4545cfU, 0xe9f9f910U, 0x04020206U, 0xfe7f7f81U, + 0xa05050f0U, 0x783c3c44U, 0x259f9fbaU, 0x4ba8a8e3U, + 0xa25151f3U, 0x5da3a3feU, 0x804040c0U, 0x058f8f8aU, + 0x3f9292adU, 0x219d9dbcU, 0x70383848U, 0xf1f5f504U, + 0x63bcbcdfU, 0x77b6b6c1U, 0xafdada75U, 0x42212163U, + 0x20101030U, 0xe5ffff1aU, 0xfdf3f30eU, 0xbfd2d26dU, + 0x81cdcd4cU, 0x180c0c14U, 0x26131335U, 0xc3ecec2fU, + 0xbe5f5fe1U, 0x359797a2U, 0x884444ccU, 0x2e171739U, + 0x93c4c457U, 0x55a7a7f2U, 0xfc7e7e82U, 0x7a3d3d47U, + 0xc86464acU, 0xba5d5de7U, 0x3219192bU, 0xe6737395U, + 0xc06060a0U, 0x19818198U, 0x9e4f4fd1U, 0xa3dcdc7fU, + 0x44222266U, 0x542a2a7eU, 0x3b9090abU, 0x0b888883U, + 0x8c4646caU, 0xc7eeee29U, 0x6bb8b8d3U, 0x2814143cU, + 0xa7dede79U, 0xbc5e5ee2U, 0x160b0b1dU, 0xaddbdb76U, + 0xdbe0e03bU, 0x64323256U, 0x743a3a4eU, 0x140a0a1eU, + 0x924949dbU, 0x0c06060aU, 0x4824246cU, 0xb85c5ce4U, + 0x9fc2c25dU, 0xbdd3d36eU, 0x43acacefU, 0xc46262a6U, + 0x399191a8U, 0x319595a4U, 0xd3e4e437U, 0xf279798bU, + 0xd5e7e732U, 0x8bc8c843U, 0x6e373759U, 0xda6d6db7U, + 0x018d8d8cU, 0xb1d5d564U, 0x9c4e4ed2U, 0x49a9a9e0U, + 0xd86c6cb4U, 0xac5656faU, 0xf3f4f407U, 0xcfeaea25U, + 0xca6565afU, 0xf47a7a8eU, 0x47aeaee9U, 0x10080818U, + 0x6fbabad5U, 0xf0787888U, 0x4a25256fU, 0x5c2e2e72U, + 0x381c1c24U, 0x57a6a6f1U, 0x73b4b4c7U, 0x97c6c651U, + 0xcbe8e823U, 0xa1dddd7cU, 0xe874749cU, 0x3e1f1f21U, + 0x964b4bddU, 0x61bdbddcU, 0x0d8b8b86U, 0x0f8a8a85U, + 0xe0707090U, 0x7c3e3e42U, 0x71b5b5c4U, 0xcc6666aaU, + 0x904848d8U, 0x06030305U, 0xf7f6f601U, 0x1c0e0e12U, + 0xc26161a3U, 0x6a35355fU, 0xae5757f9U, 0x69b9b9d0U, + 0x17868691U, 0x99c1c158U, 0x3a1d1d27U, 0x279e9eb9U, + 0xd9e1e138U, 0xebf8f813U, 0x2b9898b3U, 0x22111133U, + 0xd26969bbU, 0xa9d9d970U, 0x078e8e89U, 0x339494a7U, + 0x2d9b9bb6U, 0x3c1e1e22U, 0x15878792U, 0xc9e9e920U, + 0x87cece49U, 0xaa5555ffU, 0x50282878U, 0xa5dfdf7aU, + 0x038c8c8fU, 0x59a1a1f8U, 0x09898980U, 0x1a0d0d17U, + 0x65bfbfdaU, 0xd7e6e631U, 0x844242c6U, 0xd06868b8U, + 0x824141c3U, 0x299999b0U, 0x5a2d2d77U, 0x1e0f0f11U, + 0x7bb0b0cbU, 0xa85454fcU, 0x6dbbbbd6U, 0x2c16163aU, +}; + +static const uint32_t Te1[256] = +{ + 0xa5c66363U, 0x84f87c7cU, 0x99ee7777U, 0x8df67b7bU, + 0x0dfff2f2U, 0xbdd66b6bU, 0xb1de6f6fU, 0x5491c5c5U, + 0x50603030U, 0x03020101U, 0xa9ce6767U, 0x7d562b2bU, + 0x19e7fefeU, 0x62b5d7d7U, 0xe64dababU, 0x9aec7676U, + 0x458fcacaU, 0x9d1f8282U, 0x4089c9c9U, 0x87fa7d7dU, + 0x15effafaU, 0xebb25959U, 0xc98e4747U, 0x0bfbf0f0U, + 0xec41adadU, 0x67b3d4d4U, 0xfd5fa2a2U, 0xea45afafU, + 0xbf239c9cU, 0xf753a4a4U, 0x96e47272U, 0x5b9bc0c0U, + 0xc275b7b7U, 0x1ce1fdfdU, 0xae3d9393U, 0x6a4c2626U, + 0x5a6c3636U, 0x417e3f3fU, 0x02f5f7f7U, 0x4f83ccccU, + 0x5c683434U, 0xf451a5a5U, 0x34d1e5e5U, 0x08f9f1f1U, + 0x93e27171U, 0x73abd8d8U, 0x53623131U, 0x3f2a1515U, + 0x0c080404U, 0x5295c7c7U, 0x65462323U, 0x5e9dc3c3U, + 0x28301818U, 0xa1379696U, 0x0f0a0505U, 0xb52f9a9aU, + 0x090e0707U, 0x36241212U, 0x9b1b8080U, 0x3ddfe2e2U, + 0x26cdebebU, 0x694e2727U, 0xcd7fb2b2U, 0x9fea7575U, + 0x1b120909U, 0x9e1d8383U, 0x74582c2cU, 0x2e341a1aU, + 0x2d361b1bU, 0xb2dc6e6eU, 0xeeb45a5aU, 0xfb5ba0a0U, + 0xf6a45252U, 0x4d763b3bU, 0x61b7d6d6U, 0xce7db3b3U, + 0x7b522929U, 0x3edde3e3U, 0x715e2f2fU, 0x97138484U, + 0xf5a65353U, 0x68b9d1d1U, 0x00000000U, 0x2cc1ededU, + 0x60402020U, 0x1fe3fcfcU, 0xc879b1b1U, 0xedb65b5bU, + 0xbed46a6aU, 0x468dcbcbU, 0xd967bebeU, 0x4b723939U, + 0xde944a4aU, 0xd4984c4cU, 0xe8b05858U, 0x4a85cfcfU, + 0x6bbbd0d0U, 0x2ac5efefU, 0xe54faaaaU, 0x16edfbfbU, + 0xc5864343U, 0xd79a4d4dU, 0x55663333U, 0x94118585U, + 0xcf8a4545U, 0x10e9f9f9U, 0x06040202U, 0x81fe7f7fU, + 0xf0a05050U, 0x44783c3cU, 0xba259f9fU, 0xe34ba8a8U, + 0xf3a25151U, 0xfe5da3a3U, 0xc0804040U, 0x8a058f8fU, + 0xad3f9292U, 0xbc219d9dU, 0x48703838U, 0x04f1f5f5U, + 0xdf63bcbcU, 0xc177b6b6U, 0x75afdadaU, 0x63422121U, + 0x30201010U, 0x1ae5ffffU, 0x0efdf3f3U, 0x6dbfd2d2U, + 0x4c81cdcdU, 0x14180c0cU, 0x35261313U, 0x2fc3ececU, + 0xe1be5f5fU, 0xa2359797U, 0xcc884444U, 0x392e1717U, + 0x5793c4c4U, 0xf255a7a7U, 0x82fc7e7eU, 0x477a3d3dU, + 0xacc86464U, 0xe7ba5d5dU, 0x2b321919U, 0x95e67373U, + 0xa0c06060U, 0x98198181U, 0xd19e4f4fU, 0x7fa3dcdcU, + 0x66442222U, 0x7e542a2aU, 0xab3b9090U, 0x830b8888U, + 0xca8c4646U, 0x29c7eeeeU, 0xd36bb8b8U, 0x3c281414U, + 0x79a7dedeU, 0xe2bc5e5eU, 0x1d160b0bU, 0x76addbdbU, + 0x3bdbe0e0U, 0x56643232U, 0x4e743a3aU, 0x1e140a0aU, + 0xdb924949U, 0x0a0c0606U, 0x6c482424U, 0xe4b85c5cU, + 0x5d9fc2c2U, 0x6ebdd3d3U, 0xef43acacU, 0xa6c46262U, + 0xa8399191U, 0xa4319595U, 0x37d3e4e4U, 0x8bf27979U, + 0x32d5e7e7U, 0x438bc8c8U, 0x596e3737U, 0xb7da6d6dU, + 0x8c018d8dU, 0x64b1d5d5U, 0xd29c4e4eU, 0xe049a9a9U, + 0xb4d86c6cU, 0xfaac5656U, 0x07f3f4f4U, 0x25cfeaeaU, + 0xafca6565U, 0x8ef47a7aU, 0xe947aeaeU, 0x18100808U, + 0xd56fbabaU, 0x88f07878U, 0x6f4a2525U, 0x725c2e2eU, + 0x24381c1cU, 0xf157a6a6U, 0xc773b4b4U, 0x5197c6c6U, + 0x23cbe8e8U, 0x7ca1ddddU, 0x9ce87474U, 0x213e1f1fU, + 0xdd964b4bU, 0xdc61bdbdU, 0x860d8b8bU, 0x850f8a8aU, + 0x90e07070U, 0x427c3e3eU, 0xc471b5b5U, 0xaacc6666U, + 0xd8904848U, 0x05060303U, 0x01f7f6f6U, 0x121c0e0eU, + 0xa3c26161U, 0x5f6a3535U, 0xf9ae5757U, 0xd069b9b9U, + 0x91178686U, 0x5899c1c1U, 0x273a1d1dU, 0xb9279e9eU, + 0x38d9e1e1U, 0x13ebf8f8U, 0xb32b9898U, 0x33221111U, + 0xbbd26969U, 0x70a9d9d9U, 0x89078e8eU, 0xa7339494U, + 0xb62d9b9bU, 0x223c1e1eU, 0x92158787U, 0x20c9e9e9U, + 0x4987ceceU, 0xffaa5555U, 0x78502828U, 0x7aa5dfdfU, + 0x8f038c8cU, 0xf859a1a1U, 0x80098989U, 0x171a0d0dU, + 0xda65bfbfU, 0x31d7e6e6U, 0xc6844242U, 0xb8d06868U, + 0xc3824141U, 0xb0299999U, 0x775a2d2dU, 0x111e0f0fU, + 0xcb7bb0b0U, 0xfca85454U, 0xd66dbbbbU, 0x3a2c1616U, +}; + +static const uint32_t Te2[256] = +{ + 0x63a5c663U, 0x7c84f87cU, 0x7799ee77U, 0x7b8df67bU, + 0xf20dfff2U, 0x6bbdd66bU, 0x6fb1de6fU, 0xc55491c5U, + 0x30506030U, 0x01030201U, 0x67a9ce67U, 0x2b7d562bU, + 0xfe19e7feU, 0xd762b5d7U, 0xabe64dabU, 0x769aec76U, + 0xca458fcaU, 0x829d1f82U, 0xc94089c9U, 0x7d87fa7dU, + 0xfa15effaU, 0x59ebb259U, 0x47c98e47U, 0xf00bfbf0U, + 0xadec41adU, 0xd467b3d4U, 0xa2fd5fa2U, 0xafea45afU, + 0x9cbf239cU, 0xa4f753a4U, 0x7296e472U, 0xc05b9bc0U, + 0xb7c275b7U, 0xfd1ce1fdU, 0x93ae3d93U, 0x266a4c26U, + 0x365a6c36U, 0x3f417e3fU, 0xf702f5f7U, 0xcc4f83ccU, + 0x345c6834U, 0xa5f451a5U, 0xe534d1e5U, 0xf108f9f1U, + 0x7193e271U, 0xd873abd8U, 0x31536231U, 0x153f2a15U, + 0x040c0804U, 0xc75295c7U, 0x23654623U, 0xc35e9dc3U, + 0x18283018U, 0x96a13796U, 0x050f0a05U, 0x9ab52f9aU, + 0x07090e07U, 0x12362412U, 0x809b1b80U, 0xe23ddfe2U, + 0xeb26cdebU, 0x27694e27U, 0xb2cd7fb2U, 0x759fea75U, + 0x091b1209U, 0x839e1d83U, 0x2c74582cU, 0x1a2e341aU, + 0x1b2d361bU, 0x6eb2dc6eU, 0x5aeeb45aU, 0xa0fb5ba0U, + 0x52f6a452U, 0x3b4d763bU, 0xd661b7d6U, 0xb3ce7db3U, + 0x297b5229U, 0xe33edde3U, 0x2f715e2fU, 0x84971384U, + 0x53f5a653U, 0xd168b9d1U, 0x00000000U, 0xed2cc1edU, + 0x20604020U, 0xfc1fe3fcU, 0xb1c879b1U, 0x5bedb65bU, + 0x6abed46aU, 0xcb468dcbU, 0xbed967beU, 0x394b7239U, + 0x4ade944aU, 0x4cd4984cU, 0x58e8b058U, 0xcf4a85cfU, + 0xd06bbbd0U, 0xef2ac5efU, 0xaae54faaU, 0xfb16edfbU, + 0x43c58643U, 0x4dd79a4dU, 0x33556633U, 0x85941185U, + 0x45cf8a45U, 0xf910e9f9U, 0x02060402U, 0x7f81fe7fU, + 0x50f0a050U, 0x3c44783cU, 0x9fba259fU, 0xa8e34ba8U, + 0x51f3a251U, 0xa3fe5da3U, 0x40c08040U, 0x8f8a058fU, + 0x92ad3f92U, 0x9dbc219dU, 0x38487038U, 0xf504f1f5U, + 0xbcdf63bcU, 0xb6c177b6U, 0xda75afdaU, 0x21634221U, + 0x10302010U, 0xff1ae5ffU, 0xf30efdf3U, 0xd26dbfd2U, + 0xcd4c81cdU, 0x0c14180cU, 0x13352613U, 0xec2fc3ecU, + 0x5fe1be5fU, 0x97a23597U, 0x44cc8844U, 0x17392e17U, + 0xc45793c4U, 0xa7f255a7U, 0x7e82fc7eU, 0x3d477a3dU, + 0x64acc864U, 0x5de7ba5dU, 0x192b3219U, 0x7395e673U, + 0x60a0c060U, 0x81981981U, 0x4fd19e4fU, 0xdc7fa3dcU, + 0x22664422U, 0x2a7e542aU, 0x90ab3b90U, 0x88830b88U, + 0x46ca8c46U, 0xee29c7eeU, 0xb8d36bb8U, 0x143c2814U, + 0xde79a7deU, 0x5ee2bc5eU, 0x0b1d160bU, 0xdb76addbU, + 0xe03bdbe0U, 0x32566432U, 0x3a4e743aU, 0x0a1e140aU, + 0x49db9249U, 0x060a0c06U, 0x246c4824U, 0x5ce4b85cU, + 0xc25d9fc2U, 0xd36ebdd3U, 0xacef43acU, 0x62a6c462U, + 0x91a83991U, 0x95a43195U, 0xe437d3e4U, 0x798bf279U, + 0xe732d5e7U, 0xc8438bc8U, 0x37596e37U, 0x6db7da6dU, + 0x8d8c018dU, 0xd564b1d5U, 0x4ed29c4eU, 0xa9e049a9U, + 0x6cb4d86cU, 0x56faac56U, 0xf407f3f4U, 0xea25cfeaU, + 0x65afca65U, 0x7a8ef47aU, 0xaee947aeU, 0x08181008U, + 0xbad56fbaU, 0x7888f078U, 0x256f4a25U, 0x2e725c2eU, + 0x1c24381cU, 0xa6f157a6U, 0xb4c773b4U, 0xc65197c6U, + 0xe823cbe8U, 0xdd7ca1ddU, 0x749ce874U, 0x1f213e1fU, + 0x4bdd964bU, 0xbddc61bdU, 0x8b860d8bU, 0x8a850f8aU, + 0x7090e070U, 0x3e427c3eU, 0xb5c471b5U, 0x66aacc66U, + 0x48d89048U, 0x03050603U, 0xf601f7f6U, 0x0e121c0eU, + 0x61a3c261U, 0x355f6a35U, 0x57f9ae57U, 0xb9d069b9U, + 0x86911786U, 0xc15899c1U, 0x1d273a1dU, 0x9eb9279eU, + 0xe138d9e1U, 0xf813ebf8U, 0x98b32b98U, 0x11332211U, + 0x69bbd269U, 0xd970a9d9U, 0x8e89078eU, 0x94a73394U, + 0x9bb62d9bU, 0x1e223c1eU, 0x87921587U, 0xe920c9e9U, + 0xce4987ceU, 0x55ffaa55U, 0x28785028U, 0xdf7aa5dfU, + 0x8c8f038cU, 0xa1f859a1U, 0x89800989U, 0x0d171a0dU, + 0xbfda65bfU, 0xe631d7e6U, 0x42c68442U, 0x68b8d068U, + 0x41c38241U, 0x99b02999U, 0x2d775a2dU, 0x0f111e0fU, + 0xb0cb7bb0U, 0x54fca854U, 0xbbd66dbbU, 0x163a2c16U, +}; + +static const uint32_t Te3[256] = +{ + 0x6363a5c6U, 0x7c7c84f8U, 0x777799eeU, 0x7b7b8df6U, + 0xf2f20dffU, 0x6b6bbdd6U, 0x6f6fb1deU, 0xc5c55491U, + 0x30305060U, 0x01010302U, 0x6767a9ceU, 0x2b2b7d56U, + 0xfefe19e7U, 0xd7d762b5U, 0xababe64dU, 0x76769aecU, + 0xcaca458fU, 0x82829d1fU, 0xc9c94089U, 0x7d7d87faU, + 0xfafa15efU, 0x5959ebb2U, 0x4747c98eU, 0xf0f00bfbU, + 0xadadec41U, 0xd4d467b3U, 0xa2a2fd5fU, 0xafafea45U, + 0x9c9cbf23U, 0xa4a4f753U, 0x727296e4U, 0xc0c05b9bU, + 0xb7b7c275U, 0xfdfd1ce1U, 0x9393ae3dU, 0x26266a4cU, + 0x36365a6cU, 0x3f3f417eU, 0xf7f702f5U, 0xcccc4f83U, + 0x34345c68U, 0xa5a5f451U, 0xe5e534d1U, 0xf1f108f9U, + 0x717193e2U, 0xd8d873abU, 0x31315362U, 0x15153f2aU, + 0x04040c08U, 0xc7c75295U, 0x23236546U, 0xc3c35e9dU, + 0x18182830U, 0x9696a137U, 0x05050f0aU, 0x9a9ab52fU, + 0x0707090eU, 0x12123624U, 0x80809b1bU, 0xe2e23ddfU, + 0xebeb26cdU, 0x2727694eU, 0xb2b2cd7fU, 0x75759feaU, + 0x09091b12U, 0x83839e1dU, 0x2c2c7458U, 0x1a1a2e34U, + 0x1b1b2d36U, 0x6e6eb2dcU, 0x5a5aeeb4U, 0xa0a0fb5bU, + 0x5252f6a4U, 0x3b3b4d76U, 0xd6d661b7U, 0xb3b3ce7dU, + 0x29297b52U, 0xe3e33eddU, 0x2f2f715eU, 0x84849713U, + 0x5353f5a6U, 0xd1d168b9U, 0x00000000U, 0xeded2cc1U, + 0x20206040U, 0xfcfc1fe3U, 0xb1b1c879U, 0x5b5bedb6U, + 0x6a6abed4U, 0xcbcb468dU, 0xbebed967U, 0x39394b72U, + 0x4a4ade94U, 0x4c4cd498U, 0x5858e8b0U, 0xcfcf4a85U, + 0xd0d06bbbU, 0xefef2ac5U, 0xaaaae54fU, 0xfbfb16edU, + 0x4343c586U, 0x4d4dd79aU, 0x33335566U, 0x85859411U, + 0x4545cf8aU, 0xf9f910e9U, 0x02020604U, 0x7f7f81feU, + 0x5050f0a0U, 0x3c3c4478U, 0x9f9fba25U, 0xa8a8e34bU, + 0x5151f3a2U, 0xa3a3fe5dU, 0x4040c080U, 0x8f8f8a05U, + 0x9292ad3fU, 0x9d9dbc21U, 0x38384870U, 0xf5f504f1U, + 0xbcbcdf63U, 0xb6b6c177U, 0xdada75afU, 0x21216342U, + 0x10103020U, 0xffff1ae5U, 0xf3f30efdU, 0xd2d26dbfU, + 0xcdcd4c81U, 0x0c0c1418U, 0x13133526U, 0xecec2fc3U, + 0x5f5fe1beU, 0x9797a235U, 0x4444cc88U, 0x1717392eU, + 0xc4c45793U, 0xa7a7f255U, 0x7e7e82fcU, 0x3d3d477aU, + 0x6464acc8U, 0x5d5de7baU, 0x19192b32U, 0x737395e6U, + 0x6060a0c0U, 0x81819819U, 0x4f4fd19eU, 0xdcdc7fa3U, + 0x22226644U, 0x2a2a7e54U, 0x9090ab3bU, 0x8888830bU, + 0x4646ca8cU, 0xeeee29c7U, 0xb8b8d36bU, 0x14143c28U, + 0xdede79a7U, 0x5e5ee2bcU, 0x0b0b1d16U, 0xdbdb76adU, + 0xe0e03bdbU, 0x32325664U, 0x3a3a4e74U, 0x0a0a1e14U, + 0x4949db92U, 0x06060a0cU, 0x24246c48U, 0x5c5ce4b8U, + 0xc2c25d9fU, 0xd3d36ebdU, 0xacacef43U, 0x6262a6c4U, + 0x9191a839U, 0x9595a431U, 0xe4e437d3U, 0x79798bf2U, + 0xe7e732d5U, 0xc8c8438bU, 0x3737596eU, 0x6d6db7daU, + 0x8d8d8c01U, 0xd5d564b1U, 0x4e4ed29cU, 0xa9a9e049U, + 0x6c6cb4d8U, 0x5656faacU, 0xf4f407f3U, 0xeaea25cfU, + 0x6565afcaU, 0x7a7a8ef4U, 0xaeaee947U, 0x08081810U, + 0xbabad56fU, 0x787888f0U, 0x25256f4aU, 0x2e2e725cU, + 0x1c1c2438U, 0xa6a6f157U, 0xb4b4c773U, 0xc6c65197U, + 0xe8e823cbU, 0xdddd7ca1U, 0x74749ce8U, 0x1f1f213eU, + 0x4b4bdd96U, 0xbdbddc61U, 0x8b8b860dU, 0x8a8a850fU, + 0x707090e0U, 0x3e3e427cU, 0xb5b5c471U, 0x6666aaccU, + 0x4848d890U, 0x03030506U, 0xf6f601f7U, 0x0e0e121cU, + 0x6161a3c2U, 0x35355f6aU, 0x5757f9aeU, 0xb9b9d069U, + 0x86869117U, 0xc1c15899U, 0x1d1d273aU, 0x9e9eb927U, + 0xe1e138d9U, 0xf8f813ebU, 0x9898b32bU, 0x11113322U, + 0x6969bbd2U, 0xd9d970a9U, 0x8e8e8907U, 0x9494a733U, + 0x9b9bb62dU, 0x1e1e223cU, 0x87879215U, 0xe9e920c9U, + 0xcece4987U, 0x5555ffaaU, 0x28287850U, 0xdfdf7aa5U, + 0x8c8c8f03U, 0xa1a1f859U, 0x89898009U, 0x0d0d171aU, + 0xbfbfda65U, 0xe6e631d7U, 0x4242c684U, 0x6868b8d0U, + 0x4141c382U, 0x9999b029U, 0x2d2d775aU, 0x0f0f111eU, + 0xb0b0cb7bU, 0x5454fca8U, 0xbbbbd66dU, 0x16163a2cU, +}; + +static const uint32_t Te4[256] = +{ + 0x63636363U, 0x7c7c7c7cU, 0x77777777U, 0x7b7b7b7bU, + 0xf2f2f2f2U, 0x6b6b6b6bU, 0x6f6f6f6fU, 0xc5c5c5c5U, + 0x30303030U, 0x01010101U, 0x67676767U, 0x2b2b2b2bU, + 0xfefefefeU, 0xd7d7d7d7U, 0xababababU, 0x76767676U, + 0xcacacacaU, 0x82828282U, 0xc9c9c9c9U, 0x7d7d7d7dU, + 0xfafafafaU, 0x59595959U, 0x47474747U, 0xf0f0f0f0U, + 0xadadadadU, 0xd4d4d4d4U, 0xa2a2a2a2U, 0xafafafafU, + 0x9c9c9c9cU, 0xa4a4a4a4U, 0x72727272U, 0xc0c0c0c0U, + 0xb7b7b7b7U, 0xfdfdfdfdU, 0x93939393U, 0x26262626U, + 0x36363636U, 0x3f3f3f3fU, 0xf7f7f7f7U, 0xccccccccU, + 0x34343434U, 0xa5a5a5a5U, 0xe5e5e5e5U, 0xf1f1f1f1U, + 0x71717171U, 0xd8d8d8d8U, 0x31313131U, 0x15151515U, + 0x04040404U, 0xc7c7c7c7U, 0x23232323U, 0xc3c3c3c3U, + 0x18181818U, 0x96969696U, 0x05050505U, 0x9a9a9a9aU, + 0x07070707U, 0x12121212U, 0x80808080U, 0xe2e2e2e2U, + 0xebebebebU, 0x27272727U, 0xb2b2b2b2U, 0x75757575U, + 0x09090909U, 0x83838383U, 0x2c2c2c2cU, 0x1a1a1a1aU, + 0x1b1b1b1bU, 0x6e6e6e6eU, 0x5a5a5a5aU, 0xa0a0a0a0U, + 0x52525252U, 0x3b3b3b3bU, 0xd6d6d6d6U, 0xb3b3b3b3U, + 0x29292929U, 0xe3e3e3e3U, 0x2f2f2f2fU, 0x84848484U, + 0x53535353U, 0xd1d1d1d1U, 0x00000000U, 0xededededU, + 0x20202020U, 0xfcfcfcfcU, 0xb1b1b1b1U, 0x5b5b5b5bU, + 0x6a6a6a6aU, 0xcbcbcbcbU, 0xbebebebeU, 0x39393939U, + 0x4a4a4a4aU, 0x4c4c4c4cU, 0x58585858U, 0xcfcfcfcfU, + 0xd0d0d0d0U, 0xefefefefU, 0xaaaaaaaaU, 0xfbfbfbfbU, + 0x43434343U, 0x4d4d4d4dU, 0x33333333U, 0x85858585U, + 0x45454545U, 0xf9f9f9f9U, 0x02020202U, 0x7f7f7f7fU, + 0x50505050U, 0x3c3c3c3cU, 0x9f9f9f9fU, 0xa8a8a8a8U, + 0x51515151U, 0xa3a3a3a3U, 0x40404040U, 0x8f8f8f8fU, + 0x92929292U, 0x9d9d9d9dU, 0x38383838U, 0xf5f5f5f5U, + 0xbcbcbcbcU, 0xb6b6b6b6U, 0xdadadadaU, 0x21212121U, + 0x10101010U, 0xffffffffU, 0xf3f3f3f3U, 0xd2d2d2d2U, + 0xcdcdcdcdU, 0x0c0c0c0cU, 0x13131313U, 0xececececU, + 0x5f5f5f5fU, 0x97979797U, 0x44444444U, 0x17171717U, + 0xc4c4c4c4U, 0xa7a7a7a7U, 0x7e7e7e7eU, 0x3d3d3d3dU, + 0x64646464U, 0x5d5d5d5dU, 0x19191919U, 0x73737373U, + 0x60606060U, 0x81818181U, 0x4f4f4f4fU, 0xdcdcdcdcU, + 0x22222222U, 0x2a2a2a2aU, 0x90909090U, 0x88888888U, + 0x46464646U, 0xeeeeeeeeU, 0xb8b8b8b8U, 0x14141414U, + 0xdedededeU, 0x5e5e5e5eU, 0x0b0b0b0bU, 0xdbdbdbdbU, + 0xe0e0e0e0U, 0x32323232U, 0x3a3a3a3aU, 0x0a0a0a0aU, + 0x49494949U, 0x06060606U, 0x24242424U, 0x5c5c5c5cU, + 0xc2c2c2c2U, 0xd3d3d3d3U, 0xacacacacU, 0x62626262U, + 0x91919191U, 0x95959595U, 0xe4e4e4e4U, 0x79797979U, + 0xe7e7e7e7U, 0xc8c8c8c8U, 0x37373737U, 0x6d6d6d6dU, + 0x8d8d8d8dU, 0xd5d5d5d5U, 0x4e4e4e4eU, 0xa9a9a9a9U, + 0x6c6c6c6cU, 0x56565656U, 0xf4f4f4f4U, 0xeaeaeaeaU, + 0x65656565U, 0x7a7a7a7aU, 0xaeaeaeaeU, 0x08080808U, + 0xbabababaU, 0x78787878U, 0x25252525U, 0x2e2e2e2eU, + 0x1c1c1c1cU, 0xa6a6a6a6U, 0xb4b4b4b4U, 0xc6c6c6c6U, + 0xe8e8e8e8U, 0xddddddddU, 0x74747474U, 0x1f1f1f1fU, + 0x4b4b4b4bU, 0xbdbdbdbdU, 0x8b8b8b8bU, 0x8a8a8a8aU, + 0x70707070U, 0x3e3e3e3eU, 0xb5b5b5b5U, 0x66666666U, + 0x48484848U, 0x03030303U, 0xf6f6f6f6U, 0x0e0e0e0eU, + 0x61616161U, 0x35353535U, 0x57575757U, 0xb9b9b9b9U, + 0x86868686U, 0xc1c1c1c1U, 0x1d1d1d1dU, 0x9e9e9e9eU, + 0xe1e1e1e1U, 0xf8f8f8f8U, 0x98989898U, 0x11111111U, + 0x69696969U, 0xd9d9d9d9U, 0x8e8e8e8eU, 0x94949494U, + 0x9b9b9b9bU, 0x1e1e1e1eU, 0x87878787U, 0xe9e9e9e9U, + 0xcecececeU, 0x55555555U, 0x28282828U, 0xdfdfdfdfU, + 0x8c8c8c8cU, 0xa1a1a1a1U, 0x89898989U, 0x0d0d0d0dU, + 0xbfbfbfbfU, 0xe6e6e6e6U, 0x42424242U, 0x68686868U, + 0x41414141U, 0x99999999U, 0x2d2d2d2dU, 0x0f0f0f0fU, + 0xb0b0b0b0U, 0x54545454U, 0xbbbbbbbbU, 0x16161616U, +}; + +static const uint32_t Td0[256] = +{ + 0x51f4a750U, 0x7e416553U, 0x1a17a4c3U, 0x3a275e96U, + 0x3bab6bcbU, 0x1f9d45f1U, 0xacfa58abU, 0x4be30393U, + 0x2030fa55U, 0xad766df6U, 0x88cc7691U, 0xf5024c25U, + 0x4fe5d7fcU, 0xc52acbd7U, 0x26354480U, 0xb562a38fU, + 0xdeb15a49U, 0x25ba1b67U, 0x45ea0e98U, 0x5dfec0e1U, + 0xc32f7502U, 0x814cf012U, 0x8d4697a3U, 0x6bd3f9c6U, + 0x038f5fe7U, 0x15929c95U, 0xbf6d7aebU, 0x955259daU, + 0xd4be832dU, 0x587421d3U, 0x49e06929U, 0x8ec9c844U, + 0x75c2896aU, 0xf48e7978U, 0x99583e6bU, 0x27b971ddU, + 0xbee14fb6U, 0xf088ad17U, 0xc920ac66U, 0x7dce3ab4U, + 0x63df4a18U, 0xe51a3182U, 0x97513360U, 0x62537f45U, + 0xb16477e0U, 0xbb6bae84U, 0xfe81a01cU, 0xf9082b94U, + 0x70486858U, 0x8f45fd19U, 0x94de6c87U, 0x527bf8b7U, + 0xab73d323U, 0x724b02e2U, 0xe31f8f57U, 0x6655ab2aU, + 0xb2eb2807U, 0x2fb5c203U, 0x86c57b9aU, 0xd33708a5U, + 0x302887f2U, 0x23bfa5b2U, 0x02036abaU, 0xed16825cU, + 0x8acf1c2bU, 0xa779b492U, 0xf307f2f0U, 0x4e69e2a1U, + 0x65daf4cdU, 0x0605bed5U, 0xd134621fU, 0xc4a6fe8aU, + 0x342e539dU, 0xa2f355a0U, 0x058ae132U, 0xa4f6eb75U, + 0x0b83ec39U, 0x4060efaaU, 0x5e719f06U, 0xbd6e1051U, + 0x3e218af9U, 0x96dd063dU, 0xdd3e05aeU, 0x4de6bd46U, + 0x91548db5U, 0x71c45d05U, 0x0406d46fU, 0x605015ffU, + 0x1998fb24U, 0xd6bde997U, 0x894043ccU, 0x67d99e77U, + 0xb0e842bdU, 0x07898b88U, 0xe7195b38U, 0x79c8eedbU, + 0xa17c0a47U, 0x7c420fe9U, 0xf8841ec9U, 0x00000000U, + 0x09808683U, 0x322bed48U, 0x1e1170acU, 0x6c5a724eU, + 0xfd0efffbU, 0x0f853856U, 0x3daed51eU, 0x362d3927U, + 0x0a0fd964U, 0x685ca621U, 0x9b5b54d1U, 0x24362e3aU, + 0x0c0a67b1U, 0x9357e70fU, 0xb4ee96d2U, 0x1b9b919eU, + 0x80c0c54fU, 0x61dc20a2U, 0x5a774b69U, 0x1c121a16U, + 0xe293ba0aU, 0xc0a02ae5U, 0x3c22e043U, 0x121b171dU, + 0x0e090d0bU, 0xf28bc7adU, 0x2db6a8b9U, 0x141ea9c8U, + 0x57f11985U, 0xaf75074cU, 0xee99ddbbU, 0xa37f60fdU, + 0xf701269fU, 0x5c72f5bcU, 0x44663bc5U, 0x5bfb7e34U, + 0x8b432976U, 0xcb23c6dcU, 0xb6edfc68U, 0xb8e4f163U, + 0xd731dccaU, 0x42638510U, 0x13972240U, 0x84c61120U, + 0x854a247dU, 0xd2bb3df8U, 0xaef93211U, 0xc729a16dU, + 0x1d9e2f4bU, 0xdcb230f3U, 0x0d8652ecU, 0x77c1e3d0U, + 0x2bb3166cU, 0xa970b999U, 0x119448faU, 0x47e96422U, + 0xa8fc8cc4U, 0xa0f03f1aU, 0x567d2cd8U, 0x223390efU, + 0x87494ec7U, 0xd938d1c1U, 0x8ccaa2feU, 0x98d40b36U, + 0xa6f581cfU, 0xa57ade28U, 0xdab78e26U, 0x3fadbfa4U, + 0x2c3a9de4U, 0x5078920dU, 0x6a5fcc9bU, 0x547e4662U, + 0xf68d13c2U, 0x90d8b8e8U, 0x2e39f75eU, 0x82c3aff5U, + 0x9f5d80beU, 0x69d0937cU, 0x6fd52da9U, 0xcf2512b3U, + 0xc8ac993bU, 0x10187da7U, 0xe89c636eU, 0xdb3bbb7bU, + 0xcd267809U, 0x6e5918f4U, 0xec9ab701U, 0x834f9aa8U, + 0xe6956e65U, 0xaaffe67eU, 0x21bccf08U, 0xef15e8e6U, + 0xbae79bd9U, 0x4a6f36ceU, 0xea9f09d4U, 0x29b07cd6U, + 0x31a4b2afU, 0x2a3f2331U, 0xc6a59430U, 0x35a266c0U, + 0x744ebc37U, 0xfc82caa6U, 0xe090d0b0U, 0x33a7d815U, + 0xf104984aU, 0x41ecdaf7U, 0x7fcd500eU, 0x1791f62fU, + 0x764dd68dU, 0x43efb04dU, 0xccaa4d54U, 0xe49604dfU, + 0x9ed1b5e3U, 0x4c6a881bU, 0xc12c1fb8U, 0x4665517fU, + 0x9d5eea04U, 0x018c355dU, 0xfa877473U, 0xfb0b412eU, + 0xb3671d5aU, 0x92dbd252U, 0xe9105633U, 0x6dd64713U, + 0x9ad7618cU, 0x37a10c7aU, 0x59f8148eU, 0xeb133c89U, + 0xcea927eeU, 0xb761c935U, 0xe11ce5edU, 0x7a47b13cU, + 0x9cd2df59U, 0x55f2733fU, 0x1814ce79U, 0x73c737bfU, + 0x53f7cdeaU, 0x5ffdaa5bU, 0xdf3d6f14U, 0x7844db86U, + 0xcaaff381U, 0xb968c43eU, 0x3824342cU, 0xc2a3405fU, + 0x161dc372U, 0xbce2250cU, 0x283c498bU, 0xff0d9541U, + 0x39a80171U, 0x080cb3deU, 0xd8b4e49cU, 0x6456c190U, + 0x7bcb8461U, 0xd532b670U, 0x486c5c74U, 0xd0b85742U, +}; + +static const uint32_t Td1[256] = +{ + 0x5051f4a7U, 0x537e4165U, 0xc31a17a4U, 0x963a275eU, + 0xcb3bab6bU, 0xf11f9d45U, 0xabacfa58U, 0x934be303U, + 0x552030faU, 0xf6ad766dU, 0x9188cc76U, 0x25f5024cU, + 0xfc4fe5d7U, 0xd7c52acbU, 0x80263544U, 0x8fb562a3U, + 0x49deb15aU, 0x6725ba1bU, 0x9845ea0eU, 0xe15dfec0U, + 0x02c32f75U, 0x12814cf0U, 0xa38d4697U, 0xc66bd3f9U, + 0xe7038f5fU, 0x9515929cU, 0xebbf6d7aU, 0xda955259U, + 0x2dd4be83U, 0xd3587421U, 0x2949e069U, 0x448ec9c8U, + 0x6a75c289U, 0x78f48e79U, 0x6b99583eU, 0xdd27b971U, + 0xb6bee14fU, 0x17f088adU, 0x66c920acU, 0xb47dce3aU, + 0x1863df4aU, 0x82e51a31U, 0x60975133U, 0x4562537fU, + 0xe0b16477U, 0x84bb6baeU, 0x1cfe81a0U, 0x94f9082bU, + 0x58704868U, 0x198f45fdU, 0x8794de6cU, 0xb7527bf8U, + 0x23ab73d3U, 0xe2724b02U, 0x57e31f8fU, 0x2a6655abU, + 0x07b2eb28U, 0x032fb5c2U, 0x9a86c57bU, 0xa5d33708U, + 0xf2302887U, 0xb223bfa5U, 0xba02036aU, 0x5ced1682U, + 0x2b8acf1cU, 0x92a779b4U, 0xf0f307f2U, 0xa14e69e2U, + 0xcd65daf4U, 0xd50605beU, 0x1fd13462U, 0x8ac4a6feU, + 0x9d342e53U, 0xa0a2f355U, 0x32058ae1U, 0x75a4f6ebU, + 0x390b83ecU, 0xaa4060efU, 0x065e719fU, 0x51bd6e10U, + 0xf93e218aU, 0x3d96dd06U, 0xaedd3e05U, 0x464de6bdU, + 0xb591548dU, 0x0571c45dU, 0x6f0406d4U, 0xff605015U, + 0x241998fbU, 0x97d6bde9U, 0xcc894043U, 0x7767d99eU, + 0xbdb0e842U, 0x8807898bU, 0x38e7195bU, 0xdb79c8eeU, + 0x47a17c0aU, 0xe97c420fU, 0xc9f8841eU, 0x00000000U, + 0x83098086U, 0x48322bedU, 0xac1e1170U, 0x4e6c5a72U, + 0xfbfd0effU, 0x560f8538U, 0x1e3daed5U, 0x27362d39U, + 0x640a0fd9U, 0x21685ca6U, 0xd19b5b54U, 0x3a24362eU, + 0xb10c0a67U, 0x0f9357e7U, 0xd2b4ee96U, 0x9e1b9b91U, + 0x4f80c0c5U, 0xa261dc20U, 0x695a774bU, 0x161c121aU, + 0x0ae293baU, 0xe5c0a02aU, 0x433c22e0U, 0x1d121b17U, + 0x0b0e090dU, 0xadf28bc7U, 0xb92db6a8U, 0xc8141ea9U, + 0x8557f119U, 0x4caf7507U, 0xbbee99ddU, 0xfda37f60U, + 0x9ff70126U, 0xbc5c72f5U, 0xc544663bU, 0x345bfb7eU, + 0x768b4329U, 0xdccb23c6U, 0x68b6edfcU, 0x63b8e4f1U, + 0xcad731dcU, 0x10426385U, 0x40139722U, 0x2084c611U, + 0x7d854a24U, 0xf8d2bb3dU, 0x11aef932U, 0x6dc729a1U, + 0x4b1d9e2fU, 0xf3dcb230U, 0xec0d8652U, 0xd077c1e3U, + 0x6c2bb316U, 0x99a970b9U, 0xfa119448U, 0x2247e964U, + 0xc4a8fc8cU, 0x1aa0f03fU, 0xd8567d2cU, 0xef223390U, + 0xc787494eU, 0xc1d938d1U, 0xfe8ccaa2U, 0x3698d40bU, + 0xcfa6f581U, 0x28a57adeU, 0x26dab78eU, 0xa43fadbfU, + 0xe42c3a9dU, 0x0d507892U, 0x9b6a5fccU, 0x62547e46U, + 0xc2f68d13U, 0xe890d8b8U, 0x5e2e39f7U, 0xf582c3afU, + 0xbe9f5d80U, 0x7c69d093U, 0xa96fd52dU, 0xb3cf2512U, + 0x3bc8ac99U, 0xa710187dU, 0x6ee89c63U, 0x7bdb3bbbU, + 0x09cd2678U, 0xf46e5918U, 0x01ec9ab7U, 0xa8834f9aU, + 0x65e6956eU, 0x7eaaffe6U, 0x0821bccfU, 0xe6ef15e8U, + 0xd9bae79bU, 0xce4a6f36U, 0xd4ea9f09U, 0xd629b07cU, + 0xaf31a4b2U, 0x312a3f23U, 0x30c6a594U, 0xc035a266U, + 0x37744ebcU, 0xa6fc82caU, 0xb0e090d0U, 0x1533a7d8U, + 0x4af10498U, 0xf741ecdaU, 0x0e7fcd50U, 0x2f1791f6U, + 0x8d764dd6U, 0x4d43efb0U, 0x54ccaa4dU, 0xdfe49604U, + 0xe39ed1b5U, 0x1b4c6a88U, 0xb8c12c1fU, 0x7f466551U, + 0x049d5eeaU, 0x5d018c35U, 0x73fa8774U, 0x2efb0b41U, + 0x5ab3671dU, 0x5292dbd2U, 0x33e91056U, 0x136dd647U, + 0x8c9ad761U, 0x7a37a10cU, 0x8e59f814U, 0x89eb133cU, + 0xeecea927U, 0x35b761c9U, 0xede11ce5U, 0x3c7a47b1U, + 0x599cd2dfU, 0x3f55f273U, 0x791814ceU, 0xbf73c737U, + 0xea53f7cdU, 0x5b5ffdaaU, 0x14df3d6fU, 0x867844dbU, + 0x81caaff3U, 0x3eb968c4U, 0x2c382434U, 0x5fc2a340U, + 0x72161dc3U, 0x0cbce225U, 0x8b283c49U, 0x41ff0d95U, + 0x7139a801U, 0xde080cb3U, 0x9cd8b4e4U, 0x906456c1U, + 0x617bcb84U, 0x70d532b6U, 0x74486c5cU, 0x42d0b857U, +}; + +static const uint32_t Td2[256] = +{ + 0xa75051f4U, 0x65537e41U, 0xa4c31a17U, 0x5e963a27U, + 0x6bcb3babU, 0x45f11f9dU, 0x58abacfaU, 0x03934be3U, + 0xfa552030U, 0x6df6ad76U, 0x769188ccU, 0x4c25f502U, + 0xd7fc4fe5U, 0xcbd7c52aU, 0x44802635U, 0xa38fb562U, + 0x5a49deb1U, 0x1b6725baU, 0x0e9845eaU, 0xc0e15dfeU, + 0x7502c32fU, 0xf012814cU, 0x97a38d46U, 0xf9c66bd3U, + 0x5fe7038fU, 0x9c951592U, 0x7aebbf6dU, 0x59da9552U, + 0x832dd4beU, 0x21d35874U, 0x692949e0U, 0xc8448ec9U, + 0x896a75c2U, 0x7978f48eU, 0x3e6b9958U, 0x71dd27b9U, + 0x4fb6bee1U, 0xad17f088U, 0xac66c920U, 0x3ab47dceU, + 0x4a1863dfU, 0x3182e51aU, 0x33609751U, 0x7f456253U, + 0x77e0b164U, 0xae84bb6bU, 0xa01cfe81U, 0x2b94f908U, + 0x68587048U, 0xfd198f45U, 0x6c8794deU, 0xf8b7527bU, + 0xd323ab73U, 0x02e2724bU, 0x8f57e31fU, 0xab2a6655U, + 0x2807b2ebU, 0xc2032fb5U, 0x7b9a86c5U, 0x08a5d337U, + 0x87f23028U, 0xa5b223bfU, 0x6aba0203U, 0x825ced16U, + 0x1c2b8acfU, 0xb492a779U, 0xf2f0f307U, 0xe2a14e69U, + 0xf4cd65daU, 0xbed50605U, 0x621fd134U, 0xfe8ac4a6U, + 0x539d342eU, 0x55a0a2f3U, 0xe132058aU, 0xeb75a4f6U, + 0xec390b83U, 0xefaa4060U, 0x9f065e71U, 0x1051bd6eU, + 0x8af93e21U, 0x063d96ddU, 0x05aedd3eU, 0xbd464de6U, + 0x8db59154U, 0x5d0571c4U, 0xd46f0406U, 0x15ff6050U, + 0xfb241998U, 0xe997d6bdU, 0x43cc8940U, 0x9e7767d9U, + 0x42bdb0e8U, 0x8b880789U, 0x5b38e719U, 0xeedb79c8U, + 0x0a47a17cU, 0x0fe97c42U, 0x1ec9f884U, 0x00000000U, + 0x86830980U, 0xed48322bU, 0x70ac1e11U, 0x724e6c5aU, + 0xfffbfd0eU, 0x38560f85U, 0xd51e3daeU, 0x3927362dU, + 0xd9640a0fU, 0xa621685cU, 0x54d19b5bU, 0x2e3a2436U, + 0x67b10c0aU, 0xe70f9357U, 0x96d2b4eeU, 0x919e1b9bU, + 0xc54f80c0U, 0x20a261dcU, 0x4b695a77U, 0x1a161c12U, + 0xba0ae293U, 0x2ae5c0a0U, 0xe0433c22U, 0x171d121bU, + 0x0d0b0e09U, 0xc7adf28bU, 0xa8b92db6U, 0xa9c8141eU, + 0x198557f1U, 0x074caf75U, 0xddbbee99U, 0x60fda37fU, + 0x269ff701U, 0xf5bc5c72U, 0x3bc54466U, 0x7e345bfbU, + 0x29768b43U, 0xc6dccb23U, 0xfc68b6edU, 0xf163b8e4U, + 0xdccad731U, 0x85104263U, 0x22401397U, 0x112084c6U, + 0x247d854aU, 0x3df8d2bbU, 0x3211aef9U, 0xa16dc729U, + 0x2f4b1d9eU, 0x30f3dcb2U, 0x52ec0d86U, 0xe3d077c1U, + 0x166c2bb3U, 0xb999a970U, 0x48fa1194U, 0x642247e9U, + 0x8cc4a8fcU, 0x3f1aa0f0U, 0x2cd8567dU, 0x90ef2233U, + 0x4ec78749U, 0xd1c1d938U, 0xa2fe8ccaU, 0x0b3698d4U, + 0x81cfa6f5U, 0xde28a57aU, 0x8e26dab7U, 0xbfa43fadU, + 0x9de42c3aU, 0x920d5078U, 0xcc9b6a5fU, 0x4662547eU, + 0x13c2f68dU, 0xb8e890d8U, 0xf75e2e39U, 0xaff582c3U, + 0x80be9f5dU, 0x937c69d0U, 0x2da96fd5U, 0x12b3cf25U, + 0x993bc8acU, 0x7da71018U, 0x636ee89cU, 0xbb7bdb3bU, + 0x7809cd26U, 0x18f46e59U, 0xb701ec9aU, 0x9aa8834fU, + 0x6e65e695U, 0xe67eaaffU, 0xcf0821bcU, 0xe8e6ef15U, + 0x9bd9bae7U, 0x36ce4a6fU, 0x09d4ea9fU, 0x7cd629b0U, + 0xb2af31a4U, 0x23312a3fU, 0x9430c6a5U, 0x66c035a2U, + 0xbc37744eU, 0xcaa6fc82U, 0xd0b0e090U, 0xd81533a7U, + 0x984af104U, 0xdaf741ecU, 0x500e7fcdU, 0xf62f1791U, + 0xd68d764dU, 0xb04d43efU, 0x4d54ccaaU, 0x04dfe496U, + 0xb5e39ed1U, 0x881b4c6aU, 0x1fb8c12cU, 0x517f4665U, + 0xea049d5eU, 0x355d018cU, 0x7473fa87U, 0x412efb0bU, + 0x1d5ab367U, 0xd25292dbU, 0x5633e910U, 0x47136dd6U, + 0x618c9ad7U, 0x0c7a37a1U, 0x148e59f8U, 0x3c89eb13U, + 0x27eecea9U, 0xc935b761U, 0xe5ede11cU, 0xb13c7a47U, + 0xdf599cd2U, 0x733f55f2U, 0xce791814U, 0x37bf73c7U, + 0xcdea53f7U, 0xaa5b5ffdU, 0x6f14df3dU, 0xdb867844U, + 0xf381caafU, 0xc43eb968U, 0x342c3824U, 0x405fc2a3U, + 0xc372161dU, 0x250cbce2U, 0x498b283cU, 0x9541ff0dU, + 0x017139a8U, 0xb3de080cU, 0xe49cd8b4U, 0xc1906456U, + 0x84617bcbU, 0xb670d532U, 0x5c74486cU, 0x5742d0b8U, +}; + +static const uint32_t Td3[256] = +{ + 0xf4a75051U, 0x4165537eU, 0x17a4c31aU, 0x275e963aU, + 0xab6bcb3bU, 0x9d45f11fU, 0xfa58abacU, 0xe303934bU, + 0x30fa5520U, 0x766df6adU, 0xcc769188U, 0x024c25f5U, + 0xe5d7fc4fU, 0x2acbd7c5U, 0x35448026U, 0x62a38fb5U, + 0xb15a49deU, 0xba1b6725U, 0xea0e9845U, 0xfec0e15dU, + 0x2f7502c3U, 0x4cf01281U, 0x4697a38dU, 0xd3f9c66bU, + 0x8f5fe703U, 0x929c9515U, 0x6d7aebbfU, 0x5259da95U, + 0xbe832dd4U, 0x7421d358U, 0xe0692949U, 0xc9c8448eU, + 0xc2896a75U, 0x8e7978f4U, 0x583e6b99U, 0xb971dd27U, + 0xe14fb6beU, 0x88ad17f0U, 0x20ac66c9U, 0xce3ab47dU, + 0xdf4a1863U, 0x1a3182e5U, 0x51336097U, 0x537f4562U, + 0x6477e0b1U, 0x6bae84bbU, 0x81a01cfeU, 0x082b94f9U, + 0x48685870U, 0x45fd198fU, 0xde6c8794U, 0x7bf8b752U, + 0x73d323abU, 0x4b02e272U, 0x1f8f57e3U, 0x55ab2a66U, + 0xeb2807b2U, 0xb5c2032fU, 0xc57b9a86U, 0x3708a5d3U, + 0x2887f230U, 0xbfa5b223U, 0x036aba02U, 0x16825cedU, + 0xcf1c2b8aU, 0x79b492a7U, 0x07f2f0f3U, 0x69e2a14eU, + 0xdaf4cd65U, 0x05bed506U, 0x34621fd1U, 0xa6fe8ac4U, + 0x2e539d34U, 0xf355a0a2U, 0x8ae13205U, 0xf6eb75a4U, + 0x83ec390bU, 0x60efaa40U, 0x719f065eU, 0x6e1051bdU, + 0x218af93eU, 0xdd063d96U, 0x3e05aeddU, 0xe6bd464dU, + 0x548db591U, 0xc45d0571U, 0x06d46f04U, 0x5015ff60U, + 0x98fb2419U, 0xbde997d6U, 0x4043cc89U, 0xd99e7767U, + 0xe842bdb0U, 0x898b8807U, 0x195b38e7U, 0xc8eedb79U, + 0x7c0a47a1U, 0x420fe97cU, 0x841ec9f8U, 0x00000000U, + 0x80868309U, 0x2bed4832U, 0x1170ac1eU, 0x5a724e6cU, + 0x0efffbfdU, 0x8538560fU, 0xaed51e3dU, 0x2d392736U, + 0x0fd9640aU, 0x5ca62168U, 0x5b54d19bU, 0x362e3a24U, + 0x0a67b10cU, 0x57e70f93U, 0xee96d2b4U, 0x9b919e1bU, + 0xc0c54f80U, 0xdc20a261U, 0x774b695aU, 0x121a161cU, + 0x93ba0ae2U, 0xa02ae5c0U, 0x22e0433cU, 0x1b171d12U, + 0x090d0b0eU, 0x8bc7adf2U, 0xb6a8b92dU, 0x1ea9c814U, + 0xf1198557U, 0x75074cafU, 0x99ddbbeeU, 0x7f60fda3U, + 0x01269ff7U, 0x72f5bc5cU, 0x663bc544U, 0xfb7e345bU, + 0x4329768bU, 0x23c6dccbU, 0xedfc68b6U, 0xe4f163b8U, + 0x31dccad7U, 0x63851042U, 0x97224013U, 0xc6112084U, + 0x4a247d85U, 0xbb3df8d2U, 0xf93211aeU, 0x29a16dc7U, + 0x9e2f4b1dU, 0xb230f3dcU, 0x8652ec0dU, 0xc1e3d077U, + 0xb3166c2bU, 0x70b999a9U, 0x9448fa11U, 0xe9642247U, + 0xfc8cc4a8U, 0xf03f1aa0U, 0x7d2cd856U, 0x3390ef22U, + 0x494ec787U, 0x38d1c1d9U, 0xcaa2fe8cU, 0xd40b3698U, + 0xf581cfa6U, 0x7ade28a5U, 0xb78e26daU, 0xadbfa43fU, + 0x3a9de42cU, 0x78920d50U, 0x5fcc9b6aU, 0x7e466254U, + 0x8d13c2f6U, 0xd8b8e890U, 0x39f75e2eU, 0xc3aff582U, + 0x5d80be9fU, 0xd0937c69U, 0xd52da96fU, 0x2512b3cfU, + 0xac993bc8U, 0x187da710U, 0x9c636ee8U, 0x3bbb7bdbU, + 0x267809cdU, 0x5918f46eU, 0x9ab701ecU, 0x4f9aa883U, + 0x956e65e6U, 0xffe67eaaU, 0xbccf0821U, 0x15e8e6efU, + 0xe79bd9baU, 0x6f36ce4aU, 0x9f09d4eaU, 0xb07cd629U, + 0xa4b2af31U, 0x3f23312aU, 0xa59430c6U, 0xa266c035U, + 0x4ebc3774U, 0x82caa6fcU, 0x90d0b0e0U, 0xa7d81533U, + 0x04984af1U, 0xecdaf741U, 0xcd500e7fU, 0x91f62f17U, + 0x4dd68d76U, 0xefb04d43U, 0xaa4d54ccU, 0x9604dfe4U, + 0xd1b5e39eU, 0x6a881b4cU, 0x2c1fb8c1U, 0x65517f46U, + 0x5eea049dU, 0x8c355d01U, 0x877473faU, 0x0b412efbU, + 0x671d5ab3U, 0xdbd25292U, 0x105633e9U, 0xd647136dU, + 0xd7618c9aU, 0xa10c7a37U, 0xf8148e59U, 0x133c89ebU, + 0xa927eeceU, 0x61c935b7U, 0x1ce5ede1U, 0x47b13c7aU, + 0xd2df599cU, 0xf2733f55U, 0x14ce7918U, 0xc737bf73U, + 0xf7cdea53U, 0xfdaa5b5fU, 0x3d6f14dfU, 0x44db8678U, + 0xaff381caU, 0x68c43eb9U, 0x24342c38U, 0xa3405fc2U, + 0x1dc37216U, 0xe2250cbcU, 0x3c498b28U, 0x0d9541ffU, + 0xa8017139U, 0x0cb3de08U, 0xb4e49cd8U, 0x56c19064U, + 0xcb84617bU, 0x32b670d5U, 0x6c5c7448U, 0xb85742d0U, +}; + +static const uint32_t Td4[256] = +{ + 0x52525252U, 0x09090909U, 0x6a6a6a6aU, 0xd5d5d5d5U, + 0x30303030U, 0x36363636U, 0xa5a5a5a5U, 0x38383838U, + 0xbfbfbfbfU, 0x40404040U, 0xa3a3a3a3U, 0x9e9e9e9eU, + 0x81818181U, 0xf3f3f3f3U, 0xd7d7d7d7U, 0xfbfbfbfbU, + 0x7c7c7c7cU, 0xe3e3e3e3U, 0x39393939U, 0x82828282U, + 0x9b9b9b9bU, 0x2f2f2f2fU, 0xffffffffU, 0x87878787U, + 0x34343434U, 0x8e8e8e8eU, 0x43434343U, 0x44444444U, + 0xc4c4c4c4U, 0xdedededeU, 0xe9e9e9e9U, 0xcbcbcbcbU, + 0x54545454U, 0x7b7b7b7bU, 0x94949494U, 0x32323232U, + 0xa6a6a6a6U, 0xc2c2c2c2U, 0x23232323U, 0x3d3d3d3dU, + 0xeeeeeeeeU, 0x4c4c4c4cU, 0x95959595U, 0x0b0b0b0bU, + 0x42424242U, 0xfafafafaU, 0xc3c3c3c3U, 0x4e4e4e4eU, + 0x08080808U, 0x2e2e2e2eU, 0xa1a1a1a1U, 0x66666666U, + 0x28282828U, 0xd9d9d9d9U, 0x24242424U, 0xb2b2b2b2U, + 0x76767676U, 0x5b5b5b5bU, 0xa2a2a2a2U, 0x49494949U, + 0x6d6d6d6dU, 0x8b8b8b8bU, 0xd1d1d1d1U, 0x25252525U, + 0x72727272U, 0xf8f8f8f8U, 0xf6f6f6f6U, 0x64646464U, + 0x86868686U, 0x68686868U, 0x98989898U, 0x16161616U, + 0xd4d4d4d4U, 0xa4a4a4a4U, 0x5c5c5c5cU, 0xccccccccU, + 0x5d5d5d5dU, 0x65656565U, 0xb6b6b6b6U, 0x92929292U, + 0x6c6c6c6cU, 0x70707070U, 0x48484848U, 0x50505050U, + 0xfdfdfdfdU, 0xededededU, 0xb9b9b9b9U, 0xdadadadaU, + 0x5e5e5e5eU, 0x15151515U, 0x46464646U, 0x57575757U, + 0xa7a7a7a7U, 0x8d8d8d8dU, 0x9d9d9d9dU, 0x84848484U, + 0x90909090U, 0xd8d8d8d8U, 0xababababU, 0x00000000U, + 0x8c8c8c8cU, 0xbcbcbcbcU, 0xd3d3d3d3U, 0x0a0a0a0aU, + 0xf7f7f7f7U, 0xe4e4e4e4U, 0x58585858U, 0x05050505U, + 0xb8b8b8b8U, 0xb3b3b3b3U, 0x45454545U, 0x06060606U, + 0xd0d0d0d0U, 0x2c2c2c2cU, 0x1e1e1e1eU, 0x8f8f8f8fU, + 0xcacacacaU, 0x3f3f3f3fU, 0x0f0f0f0fU, 0x02020202U, + 0xc1c1c1c1U, 0xafafafafU, 0xbdbdbdbdU, 0x03030303U, + 0x01010101U, 0x13131313U, 0x8a8a8a8aU, 0x6b6b6b6bU, + 0x3a3a3a3aU, 0x91919191U, 0x11111111U, 0x41414141U, + 0x4f4f4f4fU, 0x67676767U, 0xdcdcdcdcU, 0xeaeaeaeaU, + 0x97979797U, 0xf2f2f2f2U, 0xcfcfcfcfU, 0xcecececeU, + 0xf0f0f0f0U, 0xb4b4b4b4U, 0xe6e6e6e6U, 0x73737373U, + 0x96969696U, 0xacacacacU, 0x74747474U, 0x22222222U, + 0xe7e7e7e7U, 0xadadadadU, 0x35353535U, 0x85858585U, + 0xe2e2e2e2U, 0xf9f9f9f9U, 0x37373737U, 0xe8e8e8e8U, + 0x1c1c1c1cU, 0x75757575U, 0xdfdfdfdfU, 0x6e6e6e6eU, + 0x47474747U, 0xf1f1f1f1U, 0x1a1a1a1aU, 0x71717171U, + 0x1d1d1d1dU, 0x29292929U, 0xc5c5c5c5U, 0x89898989U, + 0x6f6f6f6fU, 0xb7b7b7b7U, 0x62626262U, 0x0e0e0e0eU, + 0xaaaaaaaaU, 0x18181818U, 0xbebebebeU, 0x1b1b1b1bU, + 0xfcfcfcfcU, 0x56565656U, 0x3e3e3e3eU, 0x4b4b4b4bU, + 0xc6c6c6c6U, 0xd2d2d2d2U, 0x79797979U, 0x20202020U, + 0x9a9a9a9aU, 0xdbdbdbdbU, 0xc0c0c0c0U, 0xfefefefeU, + 0x78787878U, 0xcdcdcdcdU, 0x5a5a5a5aU, 0xf4f4f4f4U, + 0x1f1f1f1fU, 0xddddddddU, 0xa8a8a8a8U, 0x33333333U, + 0x88888888U, 0x07070707U, 0xc7c7c7c7U, 0x31313131U, + 0xb1b1b1b1U, 0x12121212U, 0x10101010U, 0x59595959U, + 0x27272727U, 0x80808080U, 0xececececU, 0x5f5f5f5fU, + 0x60606060U, 0x51515151U, 0x7f7f7f7fU, 0xa9a9a9a9U, + 0x19191919U, 0xb5b5b5b5U, 0x4a4a4a4aU, 0x0d0d0d0dU, + 0x2d2d2d2dU, 0xe5e5e5e5U, 0x7a7a7a7aU, 0x9f9f9f9fU, + 0x93939393U, 0xc9c9c9c9U, 0x9c9c9c9cU, 0xefefefefU, + 0xa0a0a0a0U, 0xe0e0e0e0U, 0x3b3b3b3bU, 0x4d4d4d4dU, + 0xaeaeaeaeU, 0x2a2a2a2aU, 0xf5f5f5f5U, 0xb0b0b0b0U, + 0xc8c8c8c8U, 0xebebebebU, 0xbbbbbbbbU, 0x3c3c3c3cU, + 0x83838383U, 0x53535353U, 0x99999999U, 0x61616161U, + 0x17171717U, 0x2b2b2b2bU, 0x04040404U, 0x7e7e7e7eU, + 0xbabababaU, 0x77777777U, 0xd6d6d6d6U, 0x26262626U, + 0xe1e1e1e1U, 0x69696969U, 0x14141414U, 0x63636363U, + 0x55555555U, 0x21212121U, 0x0c0c0c0cU, 0x7d7d7d7dU, +}; + +static const uint32_t rcon[] = +{ + 0x01000000, 0x02000000, 0x04000000, 0x08000000, + 0x10000000, 0x20000000, 0x40000000, 0x80000000, + 0x1B000000, 0x36000000, + /* for 128-bit blocks, Rijndael never uses more than 10 rcon values */ +}; + +#define GETU32(plaintext) (((uint32_t)(plaintext)[0] << 24) ^ \ + ((uint32_t)(plaintext)[1] << 16) ^ \ + ((uint32_t)(plaintext)[2] << 8) ^ \ + ((uint32_t)(plaintext)[3])) + +#define PUTU32(ciphertext, st) { (ciphertext)[0] = (uint8_t)((st) >> 24); \ + (ciphertext)[1] = (uint8_t)((st) >> 16); \ + (ciphertext)[2] = (uint8_t)((st) >> 8); \ + (ciphertext)[3] = (uint8_t)(st); } + +/** + * Expand the cipher key into the encryption key schedule. + * + * @return the number of rounds for the given cipher key size. + */ +int ogs_aes_setup_enc(uint32_t *rk, const uint8_t *key, int keybits) +{ + int i = 0; + uint32_t temp; + + rk[0] = GETU32(key ); + rk[1] = GETU32(key + 4); + rk[2] = GETU32(key + 8); + rk[3] = GETU32(key + 12); + if (keybits == 128) + { + for (;;) + { + temp = rk[3]; + rk[4] = rk[0] ^ + (Te4[(temp >> 16) & 0xff] & 0xff000000) ^ + (Te4[(temp >> 8) & 0xff] & 0x00ff0000) ^ + (Te4[(temp ) & 0xff] & 0x0000ff00) ^ + (Te4[(temp >> 24) ] & 0x000000ff) ^ + rcon[i]; + rk[5] = rk[1] ^ rk[4]; + rk[6] = rk[2] ^ rk[5]; + rk[7] = rk[3] ^ rk[6]; + if (++i == 10) + return 10; + rk += 4; + } + } + rk[4] = GETU32(key + 16); + rk[5] = GETU32(key + 20); + if (keybits == 192) + { + for (;;) + { + temp = rk[ 5]; + rk[ 6] = rk[ 0] ^ + (Te4[(temp >> 16) & 0xff] & 0xff000000) ^ + (Te4[(temp >> 8) & 0xff] & 0x00ff0000) ^ + (Te4[(temp ) & 0xff] & 0x0000ff00) ^ + (Te4[(temp >> 24) ] & 0x000000ff) ^ + rcon[i]; + rk[ 7] = rk[ 1] ^ rk[ 6]; + rk[ 8] = rk[ 2] ^ rk[ 7]; + rk[ 9] = rk[ 3] ^ rk[ 8]; + if (++i == 8) + return 12; + rk[10] = rk[ 4] ^ rk[ 9]; + rk[11] = rk[ 5] ^ rk[10]; + rk += 6; + } + } + rk[6] = GETU32(key + 24); + rk[7] = GETU32(key + 28); + if (keybits == 256) + { + for (;;) + { + temp = rk[ 7]; + rk[ 8] = rk[ 0] ^ + (Te4[(temp >> 16) & 0xff] & 0xff000000) ^ + (Te4[(temp >> 8) & 0xff] & 0x00ff0000) ^ + (Te4[(temp ) & 0xff] & 0x0000ff00) ^ + (Te4[(temp >> 24) ] & 0x000000ff) ^ + rcon[i]; + rk[ 9] = rk[ 1] ^ rk[ 8]; + rk[10] = rk[ 2] ^ rk[ 9]; + rk[11] = rk[ 3] ^ rk[10]; + if (++i == 7) + return 14; + temp = rk[11]; + rk[12] = rk[ 4] ^ + (Te4[(temp >> 24) ] & 0xff000000) ^ + (Te4[(temp >> 16) & 0xff] & 0x00ff0000) ^ + (Te4[(temp >> 8) & 0xff] & 0x0000ff00) ^ + (Te4[(temp ) & 0xff] & 0x000000ff); + rk[13] = rk[ 5] ^ rk[12]; + rk[14] = rk[ 6] ^ rk[13]; + rk[15] = rk[ 7] ^ rk[14]; + rk += 8; + } + } + return 0; +} + +/** + * Expand the cipher key into the decryption key schedule. + * + * @return the number of rounds for the given cipher key size. + */ +int ogs_aes_setup_dec(uint32_t *rk, const uint8_t *key, int keybits) +{ + int nrounds, i, j; + uint32_t temp; + + /* expand the cipher key: */ + nrounds = ogs_aes_setup_enc(rk, key, keybits); + /* invert the order of the round keys: */ + for (i = 0, j = 4*nrounds; i < j; i += 4, j -= 4) + { + temp = rk[i ]; rk[i ] = rk[j ]; rk[j ] = temp; + temp = rk[i + 1]; rk[i + 1] = rk[j + 1]; rk[j + 1] = temp; + temp = rk[i + 2]; rk[i + 2] = rk[j + 2]; rk[j + 2] = temp; + temp = rk[i + 3]; rk[i + 3] = rk[j + 3]; rk[j + 3] = temp; + } + /* apply the inverse MixColumn transform to all round keys but the first and the last: */ + for (i = 1; i < nrounds; i++) + { + rk += 4; + rk[0] = + Td0[Te4[(rk[0] >> 24) ] & 0xff] ^ + Td1[Te4[(rk[0] >> 16) & 0xff] & 0xff] ^ + Td2[Te4[(rk[0] >> 8) & 0xff] & 0xff] ^ + Td3[Te4[(rk[0] ) & 0xff] & 0xff]; + rk[1] = + Td0[Te4[(rk[1] >> 24) ] & 0xff] ^ + Td1[Te4[(rk[1] >> 16) & 0xff] & 0xff] ^ + Td2[Te4[(rk[1] >> 8) & 0xff] & 0xff] ^ + Td3[Te4[(rk[1] ) & 0xff] & 0xff]; + rk[2] = + Td0[Te4[(rk[2] >> 24) ] & 0xff] ^ + Td1[Te4[(rk[2] >> 16) & 0xff] & 0xff] ^ + Td2[Te4[(rk[2] >> 8) & 0xff] & 0xff] ^ + Td3[Te4[(rk[2] ) & 0xff] & 0xff]; + rk[3] = + Td0[Te4[(rk[3] >> 24) ] & 0xff] ^ + Td1[Te4[(rk[3] >> 16) & 0xff] & 0xff] ^ + Td2[Te4[(rk[3] >> 8) & 0xff] & 0xff] ^ + Td3[Te4[(rk[3] ) & 0xff] & 0xff]; + } + return nrounds; +} + +void ogs_aes_encrypt(const uint32_t *rk, int nrounds, const uint8_t plaintext[16], + uint8_t ciphertext[16]) +{ + uint32_t s0, s1, s2, s3, t0, t1, t2, t3; + #ifndef FULL_UNROLL + int r; + #endif /* ?FULL_UNROLL */ + /* + * map byte array block to cipher state + * and add initial round key: + */ + s0 = GETU32(plaintext ) ^ rk[0]; + s1 = GETU32(plaintext + 4) ^ rk[1]; + s2 = GETU32(plaintext + 8) ^ rk[2]; + s3 = GETU32(plaintext + 12) ^ rk[3]; + #ifdef FULL_UNROLL + /* round 1: */ + t0 = Te0[s0 >> 24] ^ Te1[(s1 >> 16) & 0xff] ^ Te2[(s2 >> 8) & 0xff] ^ Te3[s3 & 0xff] ^ rk[ 4]; + t1 = Te0[s1 >> 24] ^ Te1[(s2 >> 16) & 0xff] ^ Te2[(s3 >> 8) & 0xff] ^ Te3[s0 & 0xff] ^ rk[ 5]; + t2 = Te0[s2 >> 24] ^ Te1[(s3 >> 16) & 0xff] ^ Te2[(s0 >> 8) & 0xff] ^ Te3[s1 & 0xff] ^ rk[ 6]; + t3 = Te0[s3 >> 24] ^ Te1[(s0 >> 16) & 0xff] ^ Te2[(s1 >> 8) & 0xff] ^ Te3[s2 & 0xff] ^ rk[ 7]; + /* round 2: */ + s0 = Te0[t0 >> 24] ^ Te1[(t1 >> 16) & 0xff] ^ Te2[(t2 >> 8) & 0xff] ^ Te3[t3 & 0xff] ^ rk[ 8]; + s1 = Te0[t1 >> 24] ^ Te1[(t2 >> 16) & 0xff] ^ Te2[(t3 >> 8) & 0xff] ^ Te3[t0 & 0xff] ^ rk[ 9]; + s2 = Te0[t2 >> 24] ^ Te1[(t3 >> 16) & 0xff] ^ Te2[(t0 >> 8) & 0xff] ^ Te3[t1 & 0xff] ^ rk[10]; + s3 = Te0[t3 >> 24] ^ Te1[(t0 >> 16) & 0xff] ^ Te2[(t1 >> 8) & 0xff] ^ Te3[t2 & 0xff] ^ rk[11]; + /* round 3: */ + t0 = Te0[s0 >> 24] ^ Te1[(s1 >> 16) & 0xff] ^ Te2[(s2 >> 8) & 0xff] ^ Te3[s3 & 0xff] ^ rk[12]; + t1 = Te0[s1 >> 24] ^ Te1[(s2 >> 16) & 0xff] ^ Te2[(s3 >> 8) & 0xff] ^ Te3[s0 & 0xff] ^ rk[13]; + t2 = Te0[s2 >> 24] ^ Te1[(s3 >> 16) & 0xff] ^ Te2[(s0 >> 8) & 0xff] ^ Te3[s1 & 0xff] ^ rk[14]; + t3 = Te0[s3 >> 24] ^ Te1[(s0 >> 16) & 0xff] ^ Te2[(s1 >> 8) & 0xff] ^ Te3[s2 & 0xff] ^ rk[15]; + /* round 4: */ + s0 = Te0[t0 >> 24] ^ Te1[(t1 >> 16) & 0xff] ^ Te2[(t2 >> 8) & 0xff] ^ Te3[t3 & 0xff] ^ rk[16]; + s1 = Te0[t1 >> 24] ^ Te1[(t2 >> 16) & 0xff] ^ Te2[(t3 >> 8) & 0xff] ^ Te3[t0 & 0xff] ^ rk[17]; + s2 = Te0[t2 >> 24] ^ Te1[(t3 >> 16) & 0xff] ^ Te2[(t0 >> 8) & 0xff] ^ Te3[t1 & 0xff] ^ rk[18]; + s3 = Te0[t3 >> 24] ^ Te1[(t0 >> 16) & 0xff] ^ Te2[(t1 >> 8) & 0xff] ^ Te3[t2 & 0xff] ^ rk[19]; + /* round 5: */ + t0 = Te0[s0 >> 24] ^ Te1[(s1 >> 16) & 0xff] ^ Te2[(s2 >> 8) & 0xff] ^ Te3[s3 & 0xff] ^ rk[20]; + t1 = Te0[s1 >> 24] ^ Te1[(s2 >> 16) & 0xff] ^ Te2[(s3 >> 8) & 0xff] ^ Te3[s0 & 0xff] ^ rk[21]; + t2 = Te0[s2 >> 24] ^ Te1[(s3 >> 16) & 0xff] ^ Te2[(s0 >> 8) & 0xff] ^ Te3[s1 & 0xff] ^ rk[22]; + t3 = Te0[s3 >> 24] ^ Te1[(s0 >> 16) & 0xff] ^ Te2[(s1 >> 8) & 0xff] ^ Te3[s2 & 0xff] ^ rk[23]; + /* round 6: */ + s0 = Te0[t0 >> 24] ^ Te1[(t1 >> 16) & 0xff] ^ Te2[(t2 >> 8) & 0xff] ^ Te3[t3 & 0xff] ^ rk[24]; + s1 = Te0[t1 >> 24] ^ Te1[(t2 >> 16) & 0xff] ^ Te2[(t3 >> 8) & 0xff] ^ Te3[t0 & 0xff] ^ rk[25]; + s2 = Te0[t2 >> 24] ^ Te1[(t3 >> 16) & 0xff] ^ Te2[(t0 >> 8) & 0xff] ^ Te3[t1 & 0xff] ^ rk[26]; + s3 = Te0[t3 >> 24] ^ Te1[(t0 >> 16) & 0xff] ^ Te2[(t1 >> 8) & 0xff] ^ Te3[t2 & 0xff] ^ rk[27]; + /* round 7: */ + t0 = Te0[s0 >> 24] ^ Te1[(s1 >> 16) & 0xff] ^ Te2[(s2 >> 8) & 0xff] ^ Te3[s3 & 0xff] ^ rk[28]; + t1 = Te0[s1 >> 24] ^ Te1[(s2 >> 16) & 0xff] ^ Te2[(s3 >> 8) & 0xff] ^ Te3[s0 & 0xff] ^ rk[29]; + t2 = Te0[s2 >> 24] ^ Te1[(s3 >> 16) & 0xff] ^ Te2[(s0 >> 8) & 0xff] ^ Te3[s1 & 0xff] ^ rk[30]; + t3 = Te0[s3 >> 24] ^ Te1[(s0 >> 16) & 0xff] ^ Te2[(s1 >> 8) & 0xff] ^ Te3[s2 & 0xff] ^ rk[31]; + /* round 8: */ + s0 = Te0[t0 >> 24] ^ Te1[(t1 >> 16) & 0xff] ^ Te2[(t2 >> 8) & 0xff] ^ Te3[t3 & 0xff] ^ rk[32]; + s1 = Te0[t1 >> 24] ^ Te1[(t2 >> 16) & 0xff] ^ Te2[(t3 >> 8) & 0xff] ^ Te3[t0 & 0xff] ^ rk[33]; + s2 = Te0[t2 >> 24] ^ Te1[(t3 >> 16) & 0xff] ^ Te2[(t0 >> 8) & 0xff] ^ Te3[t1 & 0xff] ^ rk[34]; + s3 = Te0[t3 >> 24] ^ Te1[(t0 >> 16) & 0xff] ^ Te2[(t1 >> 8) & 0xff] ^ Te3[t2 & 0xff] ^ rk[35]; + /* round 9: */ + t0 = Te0[s0 >> 24] ^ Te1[(s1 >> 16) & 0xff] ^ Te2[(s2 >> 8) & 0xff] ^ Te3[s3 & 0xff] ^ rk[36]; + t1 = Te0[s1 >> 24] ^ Te1[(s2 >> 16) & 0xff] ^ Te2[(s3 >> 8) & 0xff] ^ Te3[s0 & 0xff] ^ rk[37]; + t2 = Te0[s2 >> 24] ^ Te1[(s3 >> 16) & 0xff] ^ Te2[(s0 >> 8) & 0xff] ^ Te3[s1 & 0xff] ^ rk[38]; + t3 = Te0[s3 >> 24] ^ Te1[(s0 >> 16) & 0xff] ^ Te2[(s1 >> 8) & 0xff] ^ Te3[s2 & 0xff] ^ rk[39]; + if (nrounds > 10) + { + /* round 10: */ + s0 = Te0[t0 >> 24] ^ Te1[(t1 >> 16) & 0xff] ^ Te2[(t2 >> 8) & 0xff] ^ Te3[t3 & 0xff] ^ rk[40]; + s1 = Te0[t1 >> 24] ^ Te1[(t2 >> 16) & 0xff] ^ Te2[(t3 >> 8) & 0xff] ^ Te3[t0 & 0xff] ^ rk[41]; + s2 = Te0[t2 >> 24] ^ Te1[(t3 >> 16) & 0xff] ^ Te2[(t0 >> 8) & 0xff] ^ Te3[t1 & 0xff] ^ rk[42]; + s3 = Te0[t3 >> 24] ^ Te1[(t0 >> 16) & 0xff] ^ Te2[(t1 >> 8) & 0xff] ^ Te3[t2 & 0xff] ^ rk[43]; + /* round 11: */ + t0 = Te0[s0 >> 24] ^ Te1[(s1 >> 16) & 0xff] ^ Te2[(s2 >> 8) & 0xff] ^ Te3[s3 & 0xff] ^ rk[44]; + t1 = Te0[s1 >> 24] ^ Te1[(s2 >> 16) & 0xff] ^ Te2[(s3 >> 8) & 0xff] ^ Te3[s0 & 0xff] ^ rk[45]; + t2 = Te0[s2 >> 24] ^ Te1[(s3 >> 16) & 0xff] ^ Te2[(s0 >> 8) & 0xff] ^ Te3[s1 & 0xff] ^ rk[46]; + t3 = Te0[s3 >> 24] ^ Te1[(s0 >> 16) & 0xff] ^ Te2[(s1 >> 8) & 0xff] ^ Te3[s2 & 0xff] ^ rk[47]; + if (nrounds > 12) + { + /* round 12: */ + s0 = Te0[t0 >> 24] ^ Te1[(t1 >> 16) & 0xff] ^ Te2[(t2 >> 8) & 0xff] ^ Te3[t3 & 0xff] ^ rk[48]; + s1 = Te0[t1 >> 24] ^ Te1[(t2 >> 16) & 0xff] ^ Te2[(t3 >> 8) & 0xff] ^ Te3[t0 & 0xff] ^ rk[49]; + s2 = Te0[t2 >> 24] ^ Te1[(t3 >> 16) & 0xff] ^ Te2[(t0 >> 8) & 0xff] ^ Te3[t1 & 0xff] ^ rk[50]; + s3 = Te0[t3 >> 24] ^ Te1[(t0 >> 16) & 0xff] ^ Te2[(t1 >> 8) & 0xff] ^ Te3[t2 & 0xff] ^ rk[51]; + /* round 13: */ + t0 = Te0[s0 >> 24] ^ Te1[(s1 >> 16) & 0xff] ^ Te2[(s2 >> 8) & 0xff] ^ Te3[s3 & 0xff] ^ rk[52]; + t1 = Te0[s1 >> 24] ^ Te1[(s2 >> 16) & 0xff] ^ Te2[(s3 >> 8) & 0xff] ^ Te3[s0 & 0xff] ^ rk[53]; + t2 = Te0[s2 >> 24] ^ Te1[(s3 >> 16) & 0xff] ^ Te2[(s0 >> 8) & 0xff] ^ Te3[s1 & 0xff] ^ rk[54]; + t3 = Te0[s3 >> 24] ^ Te1[(s0 >> 16) & 0xff] ^ Te2[(s1 >> 8) & 0xff] ^ Te3[s2 & 0xff] ^ rk[55]; + } + } + rk += nrounds << 2; + #else /* !FULL_UNROLL */ + /* + * nrounds - 1 full rounds: + */ + r = nrounds >> 1; + for (;;) + { + t0 = + Te0[(s0 >> 24) ] ^ + Te1[(s1 >> 16) & 0xff] ^ + Te2[(s2 >> 8) & 0xff] ^ + Te3[(s3 ) & 0xff] ^ + rk[4]; + t1 = + Te0[(s1 >> 24) ] ^ + Te1[(s2 >> 16) & 0xff] ^ + Te2[(s3 >> 8) & 0xff] ^ + Te3[(s0 ) & 0xff] ^ + rk[5]; + t2 = + Te0[(s2 >> 24) ] ^ + Te1[(s3 >> 16) & 0xff] ^ + Te2[(s0 >> 8) & 0xff] ^ + Te3[(s1 ) & 0xff] ^ + rk[6]; + t3 = + Te0[(s3 >> 24) ] ^ + Te1[(s0 >> 16) & 0xff] ^ + Te2[(s1 >> 8) & 0xff] ^ + Te3[(s2 ) & 0xff] ^ + rk[7]; + rk += 8; + if (--r == 0) + break; + s0 = + Te0[(t0 >> 24) ] ^ + Te1[(t1 >> 16) & 0xff] ^ + Te2[(t2 >> 8) & 0xff] ^ + Te3[(t3 ) & 0xff] ^ + rk[0]; + s1 = + Te0[(t1 >> 24) ] ^ + Te1[(t2 >> 16) & 0xff] ^ + Te2[(t3 >> 8) & 0xff] ^ + Te3[(t0 ) & 0xff] ^ + rk[1]; + s2 = + Te0[(t2 >> 24) ] ^ + Te1[(t3 >> 16) & 0xff] ^ + Te2[(t0 >> 8) & 0xff] ^ + Te3[(t1 ) & 0xff] ^ + rk[2]; + s3 = + Te0[(t3 >> 24) ] ^ + Te1[(t0 >> 16) & 0xff] ^ + Te2[(t1 >> 8) & 0xff] ^ + Te3[(t2 ) & 0xff] ^ + rk[3]; + } + #endif /* ?FULL_UNROLL */ + /* + * apply last round and + * map cipher state to byte array block: + */ + s0 = + (Te4[(t0 >> 24) ] & 0xff000000) ^ + (Te4[(t1 >> 16) & 0xff] & 0x00ff0000) ^ + (Te4[(t2 >> 8) & 0xff] & 0x0000ff00) ^ + (Te4[(t3 ) & 0xff] & 0x000000ff) ^ + rk[0]; + PUTU32(ciphertext , s0); + s1 = + (Te4[(t1 >> 24) ] & 0xff000000) ^ + (Te4[(t2 >> 16) & 0xff] & 0x00ff0000) ^ + (Te4[(t3 >> 8) & 0xff] & 0x0000ff00) ^ + (Te4[(t0 ) & 0xff] & 0x000000ff) ^ + rk[1]; + PUTU32(ciphertext + 4, s1); + s2 = + (Te4[(t2 >> 24) ] & 0xff000000) ^ + (Te4[(t3 >> 16) & 0xff] & 0x00ff0000) ^ + (Te4[(t0 >> 8) & 0xff] & 0x0000ff00) ^ + (Te4[(t1 ) & 0xff] & 0x000000ff) ^ + rk[2]; + PUTU32(ciphertext + 8, s2); + s3 = + (Te4[(t3 >> 24) ] & 0xff000000) ^ + (Te4[(t0 >> 16) & 0xff] & 0x00ff0000) ^ + (Te4[(t1 >> 8) & 0xff] & 0x0000ff00) ^ + (Te4[(t2 ) & 0xff] & 0x000000ff) ^ + rk[3]; + PUTU32(ciphertext + 12, s3); +} + +void ogs_aes_decrypt(const uint32_t *rk, int nrounds, const uint8_t ciphertext[16], + uint8_t plaintext[16]) +{ + uint32_t s0, s1, s2, s3, t0, t1, t2, t3; + #ifndef FULL_UNROLL + int r; + #endif /* ?FULL_UNROLL */ + + /* + * map byte array block to cipher state + * and add initial round key: + */ + s0 = GETU32(ciphertext ) ^ rk[0]; + s1 = GETU32(ciphertext + 4) ^ rk[1]; + s2 = GETU32(ciphertext + 8) ^ rk[2]; + s3 = GETU32(ciphertext + 12) ^ rk[3]; + #ifdef FULL_UNROLL + /* round 1: */ + t0 = Td0[s0 >> 24] ^ Td1[(s3 >> 16) & 0xff] ^ Td2[(s2 >> 8) & 0xff] ^ Td3[s1 & 0xff] ^ rk[ 4]; + t1 = Td0[s1 >> 24] ^ Td1[(s0 >> 16) & 0xff] ^ Td2[(s3 >> 8) & 0xff] ^ Td3[s2 & 0xff] ^ rk[ 5]; + t2 = Td0[s2 >> 24] ^ Td1[(s1 >> 16) & 0xff] ^ Td2[(s0 >> 8) & 0xff] ^ Td3[s3 & 0xff] ^ rk[ 6]; + t3 = Td0[s3 >> 24] ^ Td1[(s2 >> 16) & 0xff] ^ Td2[(s1 >> 8) & 0xff] ^ Td3[s0 & 0xff] ^ rk[ 7]; + /* round 2: */ + s0 = Td0[t0 >> 24] ^ Td1[(t3 >> 16) & 0xff] ^ Td2[(t2 >> 8) & 0xff] ^ Td3[t1 & 0xff] ^ rk[ 8]; + s1 = Td0[t1 >> 24] ^ Td1[(t0 >> 16) & 0xff] ^ Td2[(t3 >> 8) & 0xff] ^ Td3[t2 & 0xff] ^ rk[ 9]; + s2 = Td0[t2 >> 24] ^ Td1[(t1 >> 16) & 0xff] ^ Td2[(t0 >> 8) & 0xff] ^ Td3[t3 & 0xff] ^ rk[10]; + s3 = Td0[t3 >> 24] ^ Td1[(t2 >> 16) & 0xff] ^ Td2[(t1 >> 8) & 0xff] ^ Td3[t0 & 0xff] ^ rk[11]; + /* round 3: */ + t0 = Td0[s0 >> 24] ^ Td1[(s3 >> 16) & 0xff] ^ Td2[(s2 >> 8) & 0xff] ^ Td3[s1 & 0xff] ^ rk[12]; + t1 = Td0[s1 >> 24] ^ Td1[(s0 >> 16) & 0xff] ^ Td2[(s3 >> 8) & 0xff] ^ Td3[s2 & 0xff] ^ rk[13]; + t2 = Td0[s2 >> 24] ^ Td1[(s1 >> 16) & 0xff] ^ Td2[(s0 >> 8) & 0xff] ^ Td3[s3 & 0xff] ^ rk[14]; + t3 = Td0[s3 >> 24] ^ Td1[(s2 >> 16) & 0xff] ^ Td2[(s1 >> 8) & 0xff] ^ Td3[s0 & 0xff] ^ rk[15]; + /* round 4: */ + s0 = Td0[t0 >> 24] ^ Td1[(t3 >> 16) & 0xff] ^ Td2[(t2 >> 8) & 0xff] ^ Td3[t1 & 0xff] ^ rk[16]; + s1 = Td0[t1 >> 24] ^ Td1[(t0 >> 16) & 0xff] ^ Td2[(t3 >> 8) & 0xff] ^ Td3[t2 & 0xff] ^ rk[17]; + s2 = Td0[t2 >> 24] ^ Td1[(t1 >> 16) & 0xff] ^ Td2[(t0 >> 8) & 0xff] ^ Td3[t3 & 0xff] ^ rk[18]; + s3 = Td0[t3 >> 24] ^ Td1[(t2 >> 16) & 0xff] ^ Td2[(t1 >> 8) & 0xff] ^ Td3[t0 & 0xff] ^ rk[19]; + /* round 5: */ + t0 = Td0[s0 >> 24] ^ Td1[(s3 >> 16) & 0xff] ^ Td2[(s2 >> 8) & 0xff] ^ Td3[s1 & 0xff] ^ rk[20]; + t1 = Td0[s1 >> 24] ^ Td1[(s0 >> 16) & 0xff] ^ Td2[(s3 >> 8) & 0xff] ^ Td3[s2 & 0xff] ^ rk[21]; + t2 = Td0[s2 >> 24] ^ Td1[(s1 >> 16) & 0xff] ^ Td2[(s0 >> 8) & 0xff] ^ Td3[s3 & 0xff] ^ rk[22]; + t3 = Td0[s3 >> 24] ^ Td1[(s2 >> 16) & 0xff] ^ Td2[(s1 >> 8) & 0xff] ^ Td3[s0 & 0xff] ^ rk[23]; + /* round 6: */ + s0 = Td0[t0 >> 24] ^ Td1[(t3 >> 16) & 0xff] ^ Td2[(t2 >> 8) & 0xff] ^ Td3[t1 & 0xff] ^ rk[24]; + s1 = Td0[t1 >> 24] ^ Td1[(t0 >> 16) & 0xff] ^ Td2[(t3 >> 8) & 0xff] ^ Td3[t2 & 0xff] ^ rk[25]; + s2 = Td0[t2 >> 24] ^ Td1[(t1 >> 16) & 0xff] ^ Td2[(t0 >> 8) & 0xff] ^ Td3[t3 & 0xff] ^ rk[26]; + s3 = Td0[t3 >> 24] ^ Td1[(t2 >> 16) & 0xff] ^ Td2[(t1 >> 8) & 0xff] ^ Td3[t0 & 0xff] ^ rk[27]; + /* round 7: */ + t0 = Td0[s0 >> 24] ^ Td1[(s3 >> 16) & 0xff] ^ Td2[(s2 >> 8) & 0xff] ^ Td3[s1 & 0xff] ^ rk[28]; + t1 = Td0[s1 >> 24] ^ Td1[(s0 >> 16) & 0xff] ^ Td2[(s3 >> 8) & 0xff] ^ Td3[s2 & 0xff] ^ rk[29]; + t2 = Td0[s2 >> 24] ^ Td1[(s1 >> 16) & 0xff] ^ Td2[(s0 >> 8) & 0xff] ^ Td3[s3 & 0xff] ^ rk[30]; + t3 = Td0[s3 >> 24] ^ Td1[(s2 >> 16) & 0xff] ^ Td2[(s1 >> 8) & 0xff] ^ Td3[s0 & 0xff] ^ rk[31]; + /* round 8: */ + s0 = Td0[t0 >> 24] ^ Td1[(t3 >> 16) & 0xff] ^ Td2[(t2 >> 8) & 0xff] ^ Td3[t1 & 0xff] ^ rk[32]; + s1 = Td0[t1 >> 24] ^ Td1[(t0 >> 16) & 0xff] ^ Td2[(t3 >> 8) & 0xff] ^ Td3[t2 & 0xff] ^ rk[33]; + s2 = Td0[t2 >> 24] ^ Td1[(t1 >> 16) & 0xff] ^ Td2[(t0 >> 8) & 0xff] ^ Td3[t3 & 0xff] ^ rk[34]; + s3 = Td0[t3 >> 24] ^ Td1[(t2 >> 16) & 0xff] ^ Td2[(t1 >> 8) & 0xff] ^ Td3[t0 & 0xff] ^ rk[35]; + /* round 9: */ + t0 = Td0[s0 >> 24] ^ Td1[(s3 >> 16) & 0xff] ^ Td2[(s2 >> 8) & 0xff] ^ Td3[s1 & 0xff] ^ rk[36]; + t1 = Td0[s1 >> 24] ^ Td1[(s0 >> 16) & 0xff] ^ Td2[(s3 >> 8) & 0xff] ^ Td3[s2 & 0xff] ^ rk[37]; + t2 = Td0[s2 >> 24] ^ Td1[(s1 >> 16) & 0xff] ^ Td2[(s0 >> 8) & 0xff] ^ Td3[s3 & 0xff] ^ rk[38]; + t3 = Td0[s3 >> 24] ^ Td1[(s2 >> 16) & 0xff] ^ Td2[(s1 >> 8) & 0xff] ^ Td3[s0 & 0xff] ^ rk[39]; + if (nrounds > 10) + { + /* round 10: */ + s0 = Td0[t0 >> 24] ^ Td1[(t3 >> 16) & 0xff] ^ Td2[(t2 >> 8) & 0xff] ^ Td3[t1 & 0xff] ^ rk[40]; + s1 = Td0[t1 >> 24] ^ Td1[(t0 >> 16) & 0xff] ^ Td2[(t3 >> 8) & 0xff] ^ Td3[t2 & 0xff] ^ rk[41]; + s2 = Td0[t2 >> 24] ^ Td1[(t1 >> 16) & 0xff] ^ Td2[(t0 >> 8) & 0xff] ^ Td3[t3 & 0xff] ^ rk[42]; + s3 = Td0[t3 >> 24] ^ Td1[(t2 >> 16) & 0xff] ^ Td2[(t1 >> 8) & 0xff] ^ Td3[t0 & 0xff] ^ rk[43]; + /* round 11: */ + t0 = Td0[s0 >> 24] ^ Td1[(s3 >> 16) & 0xff] ^ Td2[(s2 >> 8) & 0xff] ^ Td3[s1 & 0xff] ^ rk[44]; + t1 = Td0[s1 >> 24] ^ Td1[(s0 >> 16) & 0xff] ^ Td2[(s3 >> 8) & 0xff] ^ Td3[s2 & 0xff] ^ rk[45]; + t2 = Td0[s2 >> 24] ^ Td1[(s1 >> 16) & 0xff] ^ Td2[(s0 >> 8) & 0xff] ^ Td3[s3 & 0xff] ^ rk[46]; + t3 = Td0[s3 >> 24] ^ Td1[(s2 >> 16) & 0xff] ^ Td2[(s1 >> 8) & 0xff] ^ Td3[s0 & 0xff] ^ rk[47]; + if (nrounds > 12) + { + /* round 12: */ + s0 = Td0[t0 >> 24] ^ Td1[(t3 >> 16) & 0xff] ^ Td2[(t2 >> 8) & 0xff] ^ Td3[t1 & 0xff] ^ rk[48]; + s1 = Td0[t1 >> 24] ^ Td1[(t0 >> 16) & 0xff] ^ Td2[(t3 >> 8) & 0xff] ^ Td3[t2 & 0xff] ^ rk[49]; + s2 = Td0[t2 >> 24] ^ Td1[(t1 >> 16) & 0xff] ^ Td2[(t0 >> 8) & 0xff] ^ Td3[t3 & 0xff] ^ rk[50]; + s3 = Td0[t3 >> 24] ^ Td1[(t2 >> 16) & 0xff] ^ Td2[(t1 >> 8) & 0xff] ^ Td3[t0 & 0xff] ^ rk[51]; + /* round 13: */ + t0 = Td0[s0 >> 24] ^ Td1[(s3 >> 16) & 0xff] ^ Td2[(s2 >> 8) & 0xff] ^ Td3[s1 & 0xff] ^ rk[52]; + t1 = Td0[s1 >> 24] ^ Td1[(s0 >> 16) & 0xff] ^ Td2[(s3 >> 8) & 0xff] ^ Td3[s2 & 0xff] ^ rk[53]; + t2 = Td0[s2 >> 24] ^ Td1[(s1 >> 16) & 0xff] ^ Td2[(s0 >> 8) & 0xff] ^ Td3[s3 & 0xff] ^ rk[54]; + t3 = Td0[s3 >> 24] ^ Td1[(s2 >> 16) & 0xff] ^ Td2[(s1 >> 8) & 0xff] ^ Td3[s0 & 0xff] ^ rk[55]; + } + } + rk += nrounds << 2; + #else /* !FULL_UNROLL */ + /* + * nrounds - 1 full rounds: + */ + r = nrounds >> 1; + for (;;) + { + t0 = + Td0[(s0 >> 24) ] ^ + Td1[(s3 >> 16) & 0xff] ^ + Td2[(s2 >> 8) & 0xff] ^ + Td3[(s1 ) & 0xff] ^ + rk[4]; + t1 = + Td0[(s1 >> 24) ] ^ + Td1[(s0 >> 16) & 0xff] ^ + Td2[(s3 >> 8) & 0xff] ^ + Td3[(s2 ) & 0xff] ^ + rk[5]; + t2 = + Td0[(s2 >> 24) ] ^ + Td1[(s1 >> 16) & 0xff] ^ + Td2[(s0 >> 8) & 0xff] ^ + Td3[(s3 ) & 0xff] ^ + rk[6]; + t3 = + Td0[(s3 >> 24) ] ^ + Td1[(s2 >> 16) & 0xff] ^ + Td2[(s1 >> 8) & 0xff] ^ + Td3[(s0 ) & 0xff] ^ + rk[7]; + rk += 8; + if (--r == 0) + break; + s0 = + Td0[(t0 >> 24) ] ^ + Td1[(t3 >> 16) & 0xff] ^ + Td2[(t2 >> 8) & 0xff] ^ + Td3[(t1 ) & 0xff] ^ + rk[0]; + s1 = + Td0[(t1 >> 24) ] ^ + Td1[(t0 >> 16) & 0xff] ^ + Td2[(t3 >> 8) & 0xff] ^ + Td3[(t2 ) & 0xff] ^ + rk[1]; + s2 = + Td0[(t2 >> 24) ] ^ + Td1[(t1 >> 16) & 0xff] ^ + Td2[(t0 >> 8) & 0xff] ^ + Td3[(t3 ) & 0xff] ^ + rk[2]; + s3 = + Td0[(t3 >> 24) ] ^ + Td1[(t2 >> 16) & 0xff] ^ + Td2[(t1 >> 8) & 0xff] ^ + Td3[(t0 ) & 0xff] ^ + rk[3]; + } + #endif /* ?FULL_UNROLL */ + /* + * apply last round and + * map cipher state to byte array block: + */ + s0 = + (Td4[(t0 >> 24) ] & 0xff000000) ^ + (Td4[(t3 >> 16) & 0xff] & 0x00ff0000) ^ + (Td4[(t2 >> 8) & 0xff] & 0x0000ff00) ^ + (Td4[(t1 ) & 0xff] & 0x000000ff) ^ + rk[0]; + PUTU32(plaintext , s0); + s1 = + (Td4[(t1 >> 24) ] & 0xff000000) ^ + (Td4[(t0 >> 16) & 0xff] & 0x00ff0000) ^ + (Td4[(t3 >> 8) & 0xff] & 0x0000ff00) ^ + (Td4[(t2 ) & 0xff] & 0x000000ff) ^ + rk[1]; + PUTU32(plaintext + 4, s1); + s2 = + (Td4[(t2 >> 24) ] & 0xff000000) ^ + (Td4[(t1 >> 16) & 0xff] & 0x00ff0000) ^ + (Td4[(t0 >> 8) & 0xff] & 0x0000ff00) ^ + (Td4[(t3 ) & 0xff] & 0x000000ff) ^ + rk[2]; + PUTU32(plaintext + 8, s2); + s3 = + (Td4[(t3 >> 24) ] & 0xff000000) ^ + (Td4[(t2 >> 16) & 0xff] & 0x00ff0000) ^ + (Td4[(t1 >> 8) & 0xff] & 0x0000ff00) ^ + (Td4[(t0 ) & 0xff] & 0x000000ff) ^ + rk[3]; + PUTU32(plaintext + 12, s3); +} + +int ogs_aes_cbc_encrypt(const uint8_t *key, const uint32_t keybits, + uint8_t *ivec, const uint8_t *in, const uint32_t inlen, + uint8_t *out, uint32_t *outlen) +{ + uint32_t n; + uint32_t len = inlen; + const uint8_t *iv = ivec; + + uint32_t rk[OGS_AES_RKLENGTH(OGS_AES_MAX_KEY_BITS)]; + int nrounds; + + ogs_assert(key); + ogs_assert(keybits >= 128); + ogs_assert(ivec); + ogs_assert(in); + ogs_assert(inlen); + ogs_assert(out); + ogs_assert(outlen); + + if (*outlen < ((inlen - 1) / OGS_AES_BLOCK_SIZE + 1) * OGS_AES_BLOCK_SIZE) + { + return OGS_ERROR; + } + + *outlen = ((inlen - 1) / OGS_AES_BLOCK_SIZE + 1) * OGS_AES_BLOCK_SIZE; + + nrounds = ogs_aes_setup_enc(rk, key, keybits); + + while (len >= OGS_AES_BLOCK_SIZE) + { + for(n=0; n < OGS_AES_BLOCK_SIZE; ++n) + out[n] = in[n] ^ iv[n]; + ogs_aes_encrypt(rk, nrounds, out, out); + iv = out; + len -= OGS_AES_BLOCK_SIZE; + in += OGS_AES_BLOCK_SIZE; + out += OGS_AES_BLOCK_SIZE; + } + + if (len) + { + for(n=0; n < len; ++n) + out[n] = in[n] ^ iv[n]; + for(n=len; n < OGS_AES_BLOCK_SIZE; ++n) + out[n] = iv[n]; + ogs_aes_encrypt(rk, nrounds, out, out); + iv = out; + } + + memcpy(ivec, iv, OGS_AES_BLOCK_SIZE); + + return OGS_OK; +} + +int ogs_aes_cbc_decrypt(const uint8_t *key, const uint32_t keybits, + uint8_t *ivec, const uint8_t *in, const uint32_t inlen, + uint8_t *out, uint32_t *outlen) +{ + uint32_t n; + uint32_t len = inlen; + uint8_t tmp[OGS_AES_BLOCK_SIZE]; + const uint8_t *iv = ivec; + + uint32_t rk[OGS_AES_RKLENGTH(OGS_AES_MAX_KEY_BITS)]; + int nrounds; + + ogs_assert(key); + ogs_assert(keybits >= 128); + ogs_assert(ivec); + ogs_assert(in); + ogs_assert(inlen); + ogs_assert(out); + ogs_assert(outlen); + + if (inlen % OGS_AES_BLOCK_SIZE != 0) + { + return OGS_ERROR; + } + + *outlen = inlen; + + nrounds = ogs_aes_setup_dec(rk, key, keybits); + + if (in != out) + { + while (len >= OGS_AES_BLOCK_SIZE) + { + ogs_aes_decrypt(rk, nrounds, in, out); + for(n=0; n < OGS_AES_BLOCK_SIZE; ++n) + out[n] ^= iv[n]; + iv = in; + len -= OGS_AES_BLOCK_SIZE; + in += OGS_AES_BLOCK_SIZE; + out += OGS_AES_BLOCK_SIZE; + } + + if (len) + { + ogs_aes_decrypt(rk, nrounds, in, tmp); + for(n=0; n < len; ++n) + out[n] = tmp[n] ^ iv[n]; + iv = in; + } + + memcpy(ivec, iv, OGS_AES_BLOCK_SIZE); + } + else + { + while (len >= OGS_AES_BLOCK_SIZE) + { + memcpy(tmp, in, OGS_AES_BLOCK_SIZE); + + ogs_aes_decrypt(rk, nrounds, in, out); + for(n=0; n < OGS_AES_BLOCK_SIZE; ++n) + out[n] ^= ivec[n]; + memcpy(ivec, tmp, OGS_AES_BLOCK_SIZE); + len -= OGS_AES_BLOCK_SIZE; + in += OGS_AES_BLOCK_SIZE; + out += OGS_AES_BLOCK_SIZE; + } + + if (len) + { + memcpy(tmp, in, OGS_AES_BLOCK_SIZE); + ogs_aes_decrypt(rk, nrounds, tmp, out); + for(n=0; n < len; ++n) + out[n] ^= ivec[n]; + for(n=len; n < OGS_AES_BLOCK_SIZE; ++n) + out[n] = tmp[n]; + + memcpy(ivec, tmp, OGS_AES_BLOCK_SIZE); + } + } + + return OGS_OK; +} + +static void ctr128_inc(uint8_t *counter) +{ + uint32_t n = 16, c = 1; + + do { + --n; + c += counter[n]; + counter[n] = (uint8_t)c; + c >>= 8; + } while (n); +} + +static void ctr128_inc_aligned(uint8_t *counter) +{ + size_t *data, c, d, n; + const union { + long one; + char little; + } is_endian = { + 1 + }; + + if (is_endian.little || ((size_t)counter % sizeof(size_t)) != 0) { + ctr128_inc(counter); + return; + } + + data = (size_t *)counter; + c = 1; + n = 16 / sizeof(size_t); + do { + --n; + d = data[n] += c; + /* did addition carry? */ + c = ((d - c) & ~d) >> (sizeof(size_t) * 8 - 1); + } while (n); +} + +int ogs_aes_ctr128_encrypt(const uint8_t *key, + uint8_t *ivec, const uint8_t *in, const uint32_t inlen, + uint8_t *out) +{ + uint8_t ecount_buf[16]; + uint32_t len = inlen; + + uint32_t rk[OGS_AES_RKLENGTH(OGS_AES_MAX_KEY_BITS)]; + int nrounds; + + uint32_t n = 0; + size_t l = 0; + + ogs_assert(key); + ogs_assert(ivec); + ogs_assert(in); + ogs_assert(len); + ogs_assert(out); + + memset(ecount_buf, 0, 16); + nrounds = ogs_aes_setup_enc(rk, key, 128); + + while (n && len) + { + *(out++) = *(in++) ^ ecount_buf[n]; + --len; + n = (n + 1) % 16; + } + + while (len >= 16) + { + ogs_aes_encrypt(rk, nrounds, ivec, ecount_buf); + ctr128_inc_aligned(ivec); + for (n = 0; n < 16; n += sizeof(size_t)) + *(size_t *)(out + n) = + *(size_t *)(in + n) ^ *(size_t *)(ecount_buf + n); + len -= 16; + out += 16; + in += 16; + n = 0; + } + if (len) + { + ogs_aes_encrypt(rk, nrounds, ivec, ecount_buf); + ctr128_inc_aligned(ivec); + while (len--) + { + out[n] = in[n] ^ ecount_buf[n]; + ++n; + } + } + return OGS_OK; + + /* low-performance for understanding the aes-ctr128 */ + while (l < len) + { + if (n == 0) + { + ogs_aes_encrypt(rk, nrounds, ivec, ecount_buf); + ctr128_inc(ivec); + } + out[l] = in[l] ^ ecount_buf[n]; + ++l; + n = (n + 1) % 16; + } + + return OGS_OK; +} + diff --git a/lib/crypt/ogs-aes.h b/lib/crypt/ogs-aes.h new file mode 100644 index 000000000..88a8dcfa6 --- /dev/null +++ b/lib/crypt/ogs-aes.h @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#if !defined(OGS_CRYPT_INSIDE) && !defined(OGS_CRYPT_COMPILATION) +#error "This header cannot be included directly." +#endif + +#ifndef OGS_AES_H +#define OGS_AES_H + +#ifdef __cplusplus +extern "C" { +#endif + +#define OGS_AES_BLOCK_SIZE 16 +#define OGS_AES_MAX_KEY_BITS 256 + +#define OGS_AES_KEYLENGTH(keybits) ((keybits)/8) +#define OGS_AES_RKLENGTH(keybits) ((keybits)/8+28) +#define OGS_AES_NROUNDS(keybits) ((keybits)/32+6) + +int ogs_aes_setup_enc(uint32_t *rk, const uint8_t *key, int keybits); +int ogs_aes_setup_dec(uint32_t *rk, const uint8_t *key, int keybits); + +void ogs_aes_encrypt(const uint32_t *rk, int nrounds, + const uint8_t plaintext[16], uint8_t ciphertext[16]); +void ogs_aes_decrypt(const uint32_t *rk, int nrounds, + const uint8_t ciphertext[16], uint8_t plaintext[16]); + +int ogs_aes_cbc_encrypt(const uint8_t *key, + const uint32_t keybits, uint8_t *ivec, + const uint8_t *in, const uint32_t inlen, + uint8_t *out, uint32_t *outlen); +int ogs_aes_cbc_decrypt(const uint8_t *key, + const uint32_t keybits, uint8_t *ivec, + const uint8_t *in, const uint32_t inlen, + uint8_t *out, uint32_t *outlen); + +int ogs_aes_ctr128_encrypt(const uint8_t *key, + uint8_t *ivec, const uint8_t *in, const uint32_t inlen, + uint8_t *out); + +#ifdef __cplusplus +} +#endif + +#endif /* OGS_AES_H */ diff --git a/lib/crypt/ogs-crypt.h b/lib/crypt/ogs-crypt.h new file mode 100644 index 000000000..8ca7b0dd1 --- /dev/null +++ b/lib/crypt/ogs-crypt.h @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef OGS_CRYPT_H +#define OGS_CRYPT_H + +#include "ogs-core.h" + +#define OGS_CRYPT_INSIDE + +#include "crypt/ogs-sha1.h" +#include "crypt/ogs-sha1-hmac.h" +#include "crypt/ogs-sha2.h" +#include "crypt/ogs-sha2-hmac.h" +#include "crypt/ogs-aes.h" +#include "crypt/ogs-aes-cmac.h" + +#include "crypt/milenage.h" +#include "crypt/snow-3g.h" +#include "crypt/zuc.h" +#include "crypt/kasumi.h" + +#undef OGS_CRYPT_INSIDE + +#ifdef __cplusplus +extern "C" { +#endif + +#define OGS_RAND_LEN 16 +#define OGS_AUTN_LEN 16 +#define OGS_AUTS_LEN 14 +#define OGS_MAX_RES_LEN 16 + +#ifdef __cplusplus +} +#endif + +#endif /* OGS_CRYPT_H */ diff --git a/lib/crypt/ogs-sha1-hmac.c b/lib/crypt/ogs-sha1-hmac.c new file mode 100644 index 000000000..8be091650 --- /dev/null +++ b/lib/crypt/ogs-sha1-hmac.c @@ -0,0 +1,134 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +/*- + * HMAC-SHA-224/256/384/512 implementation + * Last update: 06/15/2005 + * Issue date: 06/15/2005 + * + * Copyright (C) 2005 Olivier Gay + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the project nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include "ogs-crypt.h" + +void ogs_hmac_sha1_init(ogs_hmac_sha1_ctx *ctx, const uint8_t *key, + uint32_t key_size) +{ + uint32_t fill; + uint32_t num; + + uint8_t key_temp[OGS_SHA1_DIGEST_SIZE]; + int i; + + if (key_size == OGS_SHA1_BLOCK_SIZE) { + memcpy(key_temp, key, sizeof(key_temp)); + num = OGS_SHA1_BLOCK_SIZE; + } else { + if (key_size > OGS_SHA1_BLOCK_SIZE){ + num = OGS_SHA1_DIGEST_SIZE; + ogs_sha1(key, key_size, key_temp); + } else { /* key_size > SHA1_BLOCK_SIZE */ + memcpy(key_temp, key, sizeof(key_temp)); + num = key_size; + } + fill = OGS_SHA1_BLOCK_SIZE - num; + + memset(ctx->block_ipad + num, 0x36, fill); + memset(ctx->block_opad + num, 0x5c, fill); + } + + for (i = 0; i < num; i++) { + ctx->block_ipad[i] = key_temp[i] ^ 0x36; + ctx->block_opad[i] = key_temp[i] ^ 0x5c; + } + + ogs_sha1_init(&ctx->ctx_inside); + ogs_sha1_update(&ctx->ctx_inside, ctx->block_ipad, OGS_SHA1_BLOCK_SIZE); + + ogs_sha1_init(&ctx->ctx_outside); + ogs_sha1_update(&ctx->ctx_outside, ctx->block_opad, + OGS_SHA1_BLOCK_SIZE); + + /* for hmac_reinit */ + memcpy(&ctx->ctx_inside_reinit, &ctx->ctx_inside, + sizeof(ogs_sha1_ctx)); + memcpy(&ctx->ctx_outside_reinit, &ctx->ctx_outside, + sizeof(ogs_sha1_ctx)); +} + +void ogs_hmac_sha1_reinit(ogs_hmac_sha1_ctx *ctx) +{ + memcpy(&ctx->ctx_inside, &ctx->ctx_inside_reinit, + sizeof(ogs_sha1_ctx)); + memcpy(&ctx->ctx_outside, &ctx->ctx_outside_reinit, + sizeof(ogs_sha1_ctx)); +} + +void ogs_hmac_sha1_update(ogs_hmac_sha1_ctx *ctx, const uint8_t *message, + uint32_t message_len) +{ + ogs_sha1_update(&ctx->ctx_inside, message, message_len); +} + +void ogs_hmac_sha1_final(ogs_hmac_sha1_ctx *ctx, uint8_t *mac, + uint32_t mac_size) +{ + uint8_t digest_inside[OGS_SHA1_DIGEST_SIZE]; + uint8_t mac_temp[OGS_SHA1_DIGEST_SIZE]; + + ogs_sha1_final(&ctx->ctx_inside, digest_inside); + ogs_sha1_update(&ctx->ctx_outside, digest_inside, OGS_SHA1_DIGEST_SIZE); + ogs_sha1_final(&ctx->ctx_outside, mac_temp); + memcpy(mac, mac_temp, mac_size); +} + +void ogs_hmac_sha1(const uint8_t *key, uint32_t key_size, + const uint8_t *message, uint32_t message_len, + uint8_t *mac, uint32_t mac_size) +{ + ogs_hmac_sha1_ctx ctx; + + ogs_hmac_sha1_init(&ctx, key, key_size); + ogs_hmac_sha1_update(&ctx, message, message_len); + ogs_hmac_sha1_final(&ctx, mac, mac_size); +} diff --git a/lib/crypt/ogs-sha1-hmac.h b/lib/crypt/ogs-sha1-hmac.h new file mode 100644 index 000000000..c26689b42 --- /dev/null +++ b/lib/crypt/ogs-sha1-hmac.h @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#if !defined(OGS_CRYPT_INSIDE) && !defined(OGS_CRYPT_COMPILATION) +#error "This header cannot be included directly." +#endif + +#ifndef OGS_SHA1_HMAC_H +#define OGS_SHA1_HMAC_H + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct { + ogs_sha1_ctx ctx_inside; + ogs_sha1_ctx ctx_outside; + + /* for hmac_reinit */ + ogs_sha1_ctx ctx_inside_reinit; + ogs_sha1_ctx ctx_outside_reinit; + + uint8_t block_ipad[OGS_SHA1_BLOCK_SIZE]; + uint8_t block_opad[OGS_SHA1_BLOCK_SIZE]; +} ogs_hmac_sha1_ctx; + +void ogs_hmac_sha1_init(ogs_hmac_sha1_ctx *ctx, const uint8_t *key, + uint32_t key_size); +void ogs_hmac_sha1_reinit(ogs_hmac_sha1_ctx *ctx); +void ogs_hmac_sha1_update(ogs_hmac_sha1_ctx *ctx, const uint8_t *message, + uint32_t message_len); +void ogs_hmac_sha1_final(ogs_hmac_sha1_ctx *ctx, uint8_t *mac, + uint32_t mac_size); +void ogs_hmac_sha1(const uint8_t *key, uint32_t key_size, + const uint8_t *message, uint32_t message_len, + uint8_t *mac, uint32_t mac_size); + +#ifdef __cplusplus +} +#endif + +#endif /* OGS_SHA1_HMAC_H */ diff --git a/lib/crypt/ogs-sha1.c b/lib/crypt/ogs-sha1.c new file mode 100644 index 000000000..14475e906 --- /dev/null +++ b/lib/crypt/ogs-sha1.c @@ -0,0 +1,422 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +/* + * sha1.c + * + * Copyright (C) 1998, 2009 + * Paul E. Jones + * All Rights Reserved + * + ***************************************************************************** + * $Id: sha1.c 12 2009-06-22 19:34:25Z paulej $ + ***************************************************************************** + * + * Description: + * This file implements the Secure Hashing Standard as defined + * in FIPS PUB 180-1 published April 17, 1995. + * + * The Secure Hashing Standard, which uses the Secure Hashing + * Algorithm (SHA), produces a 160-bit message digest for a + * given data stream. In theory, it is highly improbable that + * two messages will produce the same message digest. Therefore, + * this algorithm can serve as a means of providing a "fingerprint" + * for a message. + * + * Portability Issues: + * SHA-1 is defined in terms of 32-bit "words". This code was + * written with the expectation that the processor has at least + * a 32-bit machine word size. If the machine word size is larger, + * the code should still function properly. One caveat to that + * is that the input functions taking characters and character + * arrays assume that only 8 bits of information are stored in each + * character. + * + * Caveats: + * SHA-1 is designed to work with messages less than 2^64 bits + * long. Although SHA-1 allows a message digest to be generated for + * messages of any number of bits less than 2^64, this + * implementation only works with messages with a length that is a + * multiple of the size of an 8-bit character. + * + */ + +#include "ogs-crypt.h" + +/* + * Define the circular shift macro + */ +#define SHA1CircularShift(bits,word) \ + ((((word) << (bits)) & 0xFFFFFFFF) | \ + ((word) >> (32-(bits)))) + +/* Function prototypes */ +static void SHA1ProcessMessageBlock(ogs_sha1_ctx *); +static void SHA1PadMessage(ogs_sha1_ctx *); + +/* + * sha1_init + * + * Description: + * This function will initialize the ogs_sha1_ctx in preparation + * for computing a new message digest. + * + * Parameters: + * context: [in/out] + * The context to reset. + * + * Returns: + * Nothing. + * + * Comments: + * + */ +void ogs_sha1_init(ogs_sha1_ctx *ctx) +{ + ctx->Length_Low = 0; + ctx->Length_High = 0; + ctx->Message_Block_Index = 0; + + ctx->Message_Digest[0] = 0x67452301; + ctx->Message_Digest[1] = 0xEFCDAB89; + ctx->Message_Digest[2] = 0x98BADCFE; + ctx->Message_Digest[3] = 0x10325476; + ctx->Message_Digest[4] = 0xC3D2E1F0; + + ctx->Computed = 0; + ctx->Corrupted = 0; +} + +/* + * sha1_final + * + * Description: + * This function will return the 160-bit message digest into the + * Message_Digest array within the ogs_sha1_ctx provided + * + * Parameters: + * context: [in/out] + * The context to use to calculate the SHA-1 hash. + * + * Returns: + * 1 if successful, 0 if it failed. + * + * Comments: + * + */ +#if 0 /* modifed by anoveth */ +void ogs_sha1_final(ogs_sha1_ctx *ctx) +#else +void ogs_sha1_final(ogs_sha1_ctx *ctx, uint8_t *digest) +#endif +{ +#if 0 /* blocked by anoveth */ + if (ctx->Corrupted) + { + return 0; + } +#endif + + if (!ctx->Computed) + { + SHA1PadMessage(ctx); + ctx->Computed = 1; + } + +#if 0 /* modified by anoveth */ + return 1; +#else + { +#if OGS_BYTE_ORDER == OGS_BIG_ENDIAN + memcpy(digest, ctx->Message_Digest, OGS_SHA1_DIGEST_SIZE); +#else +#define ROTR(a) ((((unsigned)(a))>>8)|((a)<<24)) +#define ROTL(a) (((a)<<8)|(((unsigned)(a))>>24)) +#define SWAP32(a) (ROTL((a)&0xff00ff00)|ROTR((a)&0x00ff00ff)) + uint32_t n[5]; + n[0] = SWAP32(ctx->Message_Digest[0]); + n[1] = SWAP32(ctx->Message_Digest[1]); + n[2] = SWAP32(ctx->Message_Digest[2]); + n[3] = SWAP32(ctx->Message_Digest[3]); + n[4] = SWAP32(ctx->Message_Digest[4]); + + memcpy(digest, n, OGS_SHA1_DIGEST_SIZE); + } +#endif +#endif +} + +/* + * sha1_update + * + * Description: + * This function accepts an array of octets as the next portion of + * the message. + * + * Parameters: + * context: [in/out] + * The SHA-1 context to update + * message_array: [in] + * An array of characters representing the next portion of the + * message. + * length: [in] + * The length of the message in message_array + * + * Returns: + * Nothing. + * + * Comments: + * + */ +void ogs_sha1_update(ogs_sha1_ctx *ctx, const uint8_t *message_array, + uint32_t length) +{ + if (!length) + { + return; + } + + if (ctx->Computed || ctx->Corrupted) + { + ctx->Corrupted = 1; + return; + } + + while(length-- && !ctx->Corrupted) + { + ctx->Message_Block[ctx->Message_Block_Index++] = + (*message_array & 0xFF); + + ctx->Length_Low += 8; + /* Force it to 32 bits */ + ctx->Length_Low &= 0xFFFFFFFF; + if (ctx->Length_Low == 0) + { + ctx->Length_High++; + /* Force it to 32 bits */ + ctx->Length_High &= 0xFFFFFFFF; + if (ctx->Length_High == 0) + { + /* Message is too long */ + ctx->Corrupted = 1; + } + } + + if (ctx->Message_Block_Index == 64) + { + SHA1ProcessMessageBlock(ctx); + } + + message_array++; + } +} + +/* + * SHA1ProcessMessageBlock + * + * Description: + * This function will process the next 512 bits of the message + * stored in the Message_Block array. + * + * Parameters: + * None. + * + * Returns: + * Nothing. + * + * Comments: + * Many of the variable names in the SHAContext, especially the + * single character names, were used because those were the names + * used in the publication. + * + * + */ +static void SHA1ProcessMessageBlock(ogs_sha1_ctx *ctx) +{ + const unsigned K[] = /* Constants defined in SHA-1 */ + { + 0x5A827999, + 0x6ED9EBA1, + 0x8F1BBCDC, + 0xCA62C1D6 + }; + int t; /* Loop counter */ + unsigned temp; /* Temporary word value */ + unsigned W[80]; /* Word sequence */ + unsigned A, B, C, D, E; /* Word buffers */ + + /* + * Initialize the first 16 words in the array W + */ + for(t = 0; t < 16; t++) + { + W[t] = ((unsigned) ctx->Message_Block[t * 4]) << 24; + W[t] |= ((unsigned) ctx->Message_Block[t * 4 + 1]) << 16; + W[t] |= ((unsigned) ctx->Message_Block[t * 4 + 2]) << 8; + W[t] |= ((unsigned) ctx->Message_Block[t * 4 + 3]); + } + + for(t = 16; t < 80; t++) + { + W[t] = SHA1CircularShift(1,W[t-3] ^ W[t-8] ^ W[t-14] ^ W[t-16]); + } + + A = ctx->Message_Digest[0]; + B = ctx->Message_Digest[1]; + C = ctx->Message_Digest[2]; + D = ctx->Message_Digest[3]; + E = ctx->Message_Digest[4]; + + for(t = 0; t < 20; t++) + { + temp = SHA1CircularShift(5,A) + + ((B & C) | ((~B) & D)) + E + W[t] + K[0]; + temp &= 0xFFFFFFFF; + E = D; + D = C; + C = SHA1CircularShift(30,B); + B = A; + A = temp; + } + + for(t = 20; t < 40; t++) + { + temp = SHA1CircularShift(5,A) + (B ^ C ^ D) + E + W[t] + K[1]; + temp &= 0xFFFFFFFF; + E = D; + D = C; + C = SHA1CircularShift(30,B); + B = A; + A = temp; + } + + for(t = 40; t < 60; t++) + { + temp = SHA1CircularShift(5,A) + + ((B & C) | (B & D) | (C & D)) + E + W[t] + K[2]; + temp &= 0xFFFFFFFF; + E = D; + D = C; + C = SHA1CircularShift(30,B); + B = A; + A = temp; + } + + for(t = 60; t < 80; t++) + { + temp = SHA1CircularShift(5,A) + (B ^ C ^ D) + E + W[t] + K[3]; + temp &= 0xFFFFFFFF; + E = D; + D = C; + C = SHA1CircularShift(30,B); + B = A; + A = temp; + } + + ctx->Message_Digest[0] = + (ctx->Message_Digest[0] + A) & 0xFFFFFFFF; + ctx->Message_Digest[1] = + (ctx->Message_Digest[1] + B) & 0xFFFFFFFF; + ctx->Message_Digest[2] = + (ctx->Message_Digest[2] + C) & 0xFFFFFFFF; + ctx->Message_Digest[3] = + (ctx->Message_Digest[3] + D) & 0xFFFFFFFF; + ctx->Message_Digest[4] = + (ctx->Message_Digest[4] + E) & 0xFFFFFFFF; + + ctx->Message_Block_Index = 0; +} + +/* + * SHA1PadMessage + * + * Description: + * According to the standard, the message must be padded to an even + * 512 bits. The first padding bit must be a '1'. The last 64 + * bits represent the length of the original message. All bits in + * between should be 0. This function will pad the message + * according to those rules by filling the Message_Block array + * accordingly. It will also call SHA1ProcessMessageBlock() + * appropriately. When it returns, it can be assumed that the + * message digest has been computed. + * + * Parameters: + * context: [in/out] + * The context to pad + * + * Returns: + * Nothing. + * + * Comments: + * + */ +static void SHA1PadMessage(ogs_sha1_ctx *ctx) +{ + /* + * Check to see if the current message block is too small to hold + * the initial padding bits and length. If so, we will pad the + * block, process it, and then continue padding into a second + * block. + */ + if (ctx->Message_Block_Index > 55) + { + ctx->Message_Block[ctx->Message_Block_Index++] = 0x80; + while(ctx->Message_Block_Index < 64) + { + ctx->Message_Block[ctx->Message_Block_Index++] = 0; + } + + SHA1ProcessMessageBlock(ctx); + + while(ctx->Message_Block_Index < 56) + { + ctx->Message_Block[ctx->Message_Block_Index++] = 0; + } + } + else + { + ctx->Message_Block[ctx->Message_Block_Index++] = 0x80; + while(ctx->Message_Block_Index < 56) + { + ctx->Message_Block[ctx->Message_Block_Index++] = 0; + } + } + + /* + * Store the message length as the last 8 octets + */ + ctx->Message_Block[56] = (ctx->Length_High >> 24) & 0xFF; + ctx->Message_Block[57] = (ctx->Length_High >> 16) & 0xFF; + ctx->Message_Block[58] = (ctx->Length_High >> 8) & 0xFF; + ctx->Message_Block[59] = (ctx->Length_High) & 0xFF; + ctx->Message_Block[60] = (ctx->Length_Low >> 24) & 0xFF; + ctx->Message_Block[61] = (ctx->Length_Low >> 16) & 0xFF; + ctx->Message_Block[62] = (ctx->Length_Low >> 8) & 0xFF; + ctx->Message_Block[63] = (ctx->Length_Low) & 0xFF; + + SHA1ProcessMessageBlock(ctx); +} + +void ogs_sha1(const uint8_t *message, uint32_t len, uint8_t *digest) +{ + ogs_sha1_ctx ctx; + + ogs_sha1_init(&ctx); + ogs_sha1_update(&ctx, message, len); + ogs_sha1_final(&ctx, digest); +} diff --git a/lib/crypt/ogs-sha1.h b/lib/crypt/ogs-sha1.h new file mode 100644 index 000000000..fc64d0fc1 --- /dev/null +++ b/lib/crypt/ogs-sha1.h @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#if !defined(OGS_CRYPT_INSIDE) && !defined(OGS_CRYPT_COMPILATION) +#error "This header cannot be included directly." +#endif + +#ifndef OGS_SHA1_H +#define OGS_SHA1_H + +#ifdef __cplusplus +extern "C" { +#endif + +#define OGS_SHA1_DIGEST_SIZE (160 / 8) +#define OGS_SHA1_BLOCK_SIZE (512 / 8) + +typedef struct ogs_sha1_ctx +{ + unsigned Message_Digest[5]; /* Message Digest (output) */ + + unsigned Length_Low; /* Message length in bits */ + unsigned Length_High; /* Message length in bits */ + + unsigned char Message_Block[64]; /* 512-bit message blocks */ + int Message_Block_Index; /* Index into message block array */ + + int Computed; /* Is the digest computed? */ + int Corrupted; /* Is the message digest corruped? */ +} ogs_sha1_ctx; + +void ogs_sha1_init(ogs_sha1_ctx *ctx); +void ogs_sha1_update(ogs_sha1_ctx *ctx, const uint8_t *message, uint32_t len); +void ogs_sha1_final(ogs_sha1_ctx *ctx, uint8_t *digest); +void ogs_sha1(const uint8_t *message, uint32_t len, uint8_t *digest); + +#ifdef __cplusplus +} +#endif + +#endif /* OGS_SHA1_H */ diff --git a/lib/crypt/ogs-sha2-hmac.c b/lib/crypt/ogs-sha2-hmac.c new file mode 100644 index 000000000..71262e903 --- /dev/null +++ b/lib/crypt/ogs-sha2-hmac.c @@ -0,0 +1,388 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +/*- + * HMAC-SHA-224/256/384/512 implementation + * Last update: 06/15/2005 + * Issue date: 06/15/2005 + * + * Copyright (C) 2005 Olivier Gay + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the project nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include "ogs-crypt.h" + +/* HMAC-SHA-224 functions */ + +void ogs_hmac_sha224_init(ogs_hmac_sha224_ctx *ctx, const uint8_t *key, + uint32_t key_size) +{ + uint32_t fill; + uint32_t num; + + uint8_t key_temp[OGS_SHA224_DIGEST_SIZE]; + int i; + + if (key_size == OGS_SHA224_BLOCK_SIZE) { + memcpy(key_temp, key, sizeof(key_temp)); + num = OGS_SHA224_BLOCK_SIZE; + } else { + if (key_size > OGS_SHA224_BLOCK_SIZE){ + num = OGS_SHA224_DIGEST_SIZE; + ogs_sha224(key, key_size, key_temp); + } else { /* key_size > OGS_SHA224_BLOCK_SIZE */ + memcpy(key_temp, key, sizeof(key_temp)); + num = key_size; + } + fill = OGS_SHA224_BLOCK_SIZE - num; + + memset(ctx->block_ipad + num, 0x36, fill); + memset(ctx->block_opad + num, 0x5c, fill); + } + + for (i = 0; i < num; i++) { + ctx->block_ipad[i] = key_temp[i] ^ 0x36; + ctx->block_opad[i] = key_temp[i] ^ 0x5c; + } + + ogs_sha224_init(&ctx->ctx_inside); + ogs_sha224_update(&ctx->ctx_inside, ctx->block_ipad, OGS_SHA224_BLOCK_SIZE); + + ogs_sha224_init(&ctx->ctx_outside); + ogs_sha224_update(&ctx->ctx_outside, ctx->block_opad, + OGS_SHA224_BLOCK_SIZE); + + /* for hmac_reinit */ + memcpy(&ctx->ctx_inside_reinit, &ctx->ctx_inside, + sizeof(ogs_sha224_ctx)); + memcpy(&ctx->ctx_outside_reinit, &ctx->ctx_outside, + sizeof(ogs_sha224_ctx)); +} + +void ogs_hmac_sha224_reinit(ogs_hmac_sha224_ctx *ctx) +{ + memcpy(&ctx->ctx_inside, &ctx->ctx_inside_reinit, + sizeof(ogs_sha224_ctx)); + memcpy(&ctx->ctx_outside, &ctx->ctx_outside_reinit, + sizeof(ogs_sha224_ctx)); +} + +void ogs_hmac_sha224_update(ogs_hmac_sha224_ctx *ctx, const uint8_t *message, + uint32_t message_len) +{ + ogs_sha224_update(&ctx->ctx_inside, message, message_len); +} + +void ogs_hmac_sha224_final(ogs_hmac_sha224_ctx *ctx, uint8_t *mac, + uint32_t mac_size) +{ + uint8_t digest_inside[OGS_SHA224_DIGEST_SIZE]; + uint8_t mac_temp[OGS_SHA224_DIGEST_SIZE]; + + ogs_sha224_final(&ctx->ctx_inside, digest_inside); + ogs_sha224_update(&ctx->ctx_outside, digest_inside, OGS_SHA224_DIGEST_SIZE); + ogs_sha224_final(&ctx->ctx_outside, mac_temp); + memcpy(mac, mac_temp, mac_size); +} + +void ogs_hmac_sha224(const uint8_t *key, uint32_t key_size, + const uint8_t *message, uint32_t message_len, + uint8_t *mac, uint32_t mac_size) +{ + ogs_hmac_sha224_ctx ctx; + + ogs_hmac_sha224_init(&ctx, key, key_size); + ogs_hmac_sha224_update(&ctx, message, message_len); + ogs_hmac_sha224_final(&ctx, mac, mac_size); +} + +/* HMAC-SHA-256 functions */ + +void ogs_hmac_sha256_init(ogs_hmac_sha256_ctx *ctx, const uint8_t *key, + uint32_t key_size) +{ + uint32_t fill; + uint32_t num; + + uint8_t key_temp[OGS_SHA256_DIGEST_SIZE]; + int i; + + if (key_size == OGS_SHA256_BLOCK_SIZE) { + memcpy(key_temp, key, sizeof(key_temp)); + num = OGS_SHA256_BLOCK_SIZE; + } else { + if (key_size > OGS_SHA256_BLOCK_SIZE){ + num = OGS_SHA256_DIGEST_SIZE; + ogs_sha256(key, key_size, key_temp); + } else { /* key_size > OGS_SHA256_BLOCK_SIZE */ + memcpy(key_temp, key, sizeof(key_temp)); + num = key_size; + } + fill = OGS_SHA256_BLOCK_SIZE - num; + + memset(ctx->block_ipad + num, 0x36, fill); + memset(ctx->block_opad + num, 0x5c, fill); + } + + for (i = 0; i < num; i++) { + ctx->block_ipad[i] = key_temp[i] ^ 0x36; + ctx->block_opad[i] = key_temp[i] ^ 0x5c; + } + + ogs_sha256_init(&ctx->ctx_inside); + ogs_sha256_update(&ctx->ctx_inside, ctx->block_ipad, OGS_SHA256_BLOCK_SIZE); + + ogs_sha256_init(&ctx->ctx_outside); + ogs_sha256_update(&ctx->ctx_outside, ctx->block_opad, + OGS_SHA256_BLOCK_SIZE); + + /* for hmac_reinit */ + memcpy(&ctx->ctx_inside_reinit, &ctx->ctx_inside, + sizeof(ogs_sha256_ctx)); + memcpy(&ctx->ctx_outside_reinit, &ctx->ctx_outside, + sizeof(ogs_sha256_ctx)); +} + +void ogs_hmac_sha256_reinit(ogs_hmac_sha256_ctx *ctx) +{ + memcpy(&ctx->ctx_inside, &ctx->ctx_inside_reinit, + sizeof(ogs_sha256_ctx)); + memcpy(&ctx->ctx_outside, &ctx->ctx_outside_reinit, + sizeof(ogs_sha256_ctx)); +} + +void ogs_hmac_sha256_update(ogs_hmac_sha256_ctx *ctx, const uint8_t *message, + uint32_t message_len) +{ + ogs_sha256_update(&ctx->ctx_inside, message, message_len); +} + +void ogs_hmac_sha256_final(ogs_hmac_sha256_ctx *ctx, uint8_t *mac, + uint32_t mac_size) +{ + uint8_t digest_inside[OGS_SHA256_DIGEST_SIZE]; + uint8_t mac_temp[OGS_SHA256_DIGEST_SIZE]; + + ogs_sha256_final(&ctx->ctx_inside, digest_inside); + ogs_sha256_update(&ctx->ctx_outside, digest_inside, OGS_SHA256_DIGEST_SIZE); + ogs_sha256_final(&ctx->ctx_outside, mac_temp); + memcpy(mac, mac_temp, mac_size); +} + +void ogs_hmac_sha256(const uint8_t *key, uint32_t key_size, + const uint8_t *message, uint32_t message_len, + uint8_t *mac, uint32_t mac_size) +{ + ogs_hmac_sha256_ctx ctx; + + ogs_hmac_sha256_init(&ctx, key, key_size); + ogs_hmac_sha256_update(&ctx, message, message_len); + ogs_hmac_sha256_final(&ctx, mac, mac_size); +} + +/* HMAC-SHA-384 functions */ + +void ogs_hmac_sha384_init(ogs_hmac_sha384_ctx *ctx, const uint8_t *key, + uint32_t key_size) +{ + uint32_t fill; + uint32_t num; + + uint8_t key_temp[OGS_SHA384_DIGEST_SIZE]; + int i; + + if (key_size == OGS_SHA384_BLOCK_SIZE) { + memcpy(key_temp, key, sizeof(key_temp)); + num = OGS_SHA384_BLOCK_SIZE; + } else { + if (key_size > OGS_SHA384_BLOCK_SIZE){ + num = OGS_SHA384_DIGEST_SIZE; + ogs_sha384(key, key_size, key_temp); + } else { /* key_size > OGS_SHA384_BLOCK_SIZE */ + memcpy(key_temp, key, sizeof(key_temp)); + num = key_size; + } + fill = OGS_SHA384_BLOCK_SIZE - num; + + memset(ctx->block_ipad + num, 0x36, fill); + memset(ctx->block_opad + num, 0x5c, fill); + } + + for (i = 0; i < num; i++) { + ctx->block_ipad[i] = key_temp[i] ^ 0x36; + ctx->block_opad[i] = key_temp[i] ^ 0x5c; + } + + ogs_sha384_init(&ctx->ctx_inside); + ogs_sha384_update(&ctx->ctx_inside, ctx->block_ipad, OGS_SHA384_BLOCK_SIZE); + + ogs_sha384_init(&ctx->ctx_outside); + ogs_sha384_update(&ctx->ctx_outside, ctx->block_opad, + OGS_SHA384_BLOCK_SIZE); + + /* for hmac_reinit */ + memcpy(&ctx->ctx_inside_reinit, &ctx->ctx_inside, + sizeof(ogs_sha384_ctx)); + memcpy(&ctx->ctx_outside_reinit, &ctx->ctx_outside, + sizeof(ogs_sha384_ctx)); +} + +void ogs_hmac_sha384_reinit(ogs_hmac_sha384_ctx *ctx) +{ + memcpy(&ctx->ctx_inside, &ctx->ctx_inside_reinit, + sizeof(ogs_sha384_ctx)); + memcpy(&ctx->ctx_outside, &ctx->ctx_outside_reinit, + sizeof(ogs_sha384_ctx)); +} + +void ogs_hmac_sha384_update(ogs_hmac_sha384_ctx *ctx, const uint8_t *message, + uint32_t message_len) +{ + ogs_sha384_update(&ctx->ctx_inside, message, message_len); +} + +void ogs_hmac_sha384_final(ogs_hmac_sha384_ctx *ctx, uint8_t *mac, + uint32_t mac_size) +{ + uint8_t digest_inside[OGS_SHA384_DIGEST_SIZE]; + uint8_t mac_temp[OGS_SHA384_DIGEST_SIZE]; + + ogs_sha384_final(&ctx->ctx_inside, digest_inside); + ogs_sha384_update(&ctx->ctx_outside, digest_inside, OGS_SHA384_DIGEST_SIZE); + ogs_sha384_final(&ctx->ctx_outside, mac_temp); + memcpy(mac, mac_temp, mac_size); +} + +void ogs_hmac_sha384(const uint8_t *key, uint32_t key_size, + const uint8_t *message, uint32_t message_len, + uint8_t *mac, uint32_t mac_size) +{ + ogs_hmac_sha384_ctx ctx; + + ogs_hmac_sha384_init(&ctx, key, key_size); + ogs_hmac_sha384_update(&ctx, message, message_len); + ogs_hmac_sha384_final(&ctx, mac, mac_size); +} + +/* HMAC-SHA-512 functions */ + +void ogs_hmac_sha512_init(ogs_hmac_sha512_ctx *ctx, const uint8_t *key, + uint32_t key_size) +{ + uint32_t fill; + uint32_t num; + + uint8_t key_temp[OGS_SHA512_DIGEST_SIZE]; + int i; + + if (key_size == OGS_SHA512_BLOCK_SIZE) { + memcpy(key_temp, key, sizeof(key_temp)); + num = OGS_SHA512_BLOCK_SIZE; + } else { + if (key_size > OGS_SHA512_BLOCK_SIZE){ + num = OGS_SHA512_DIGEST_SIZE; + ogs_sha512(key, key_size, key_temp); + } else { /* key_size > OGS_SHA512_BLOCK_SIZE */ + memcpy(key_temp, key, sizeof(key_temp)); + num = key_size; + } + fill = OGS_SHA512_BLOCK_SIZE - num; + + memset(ctx->block_ipad + num, 0x36, fill); + memset(ctx->block_opad + num, 0x5c, fill); + } + + for (i = 0; i < num; i++) { + ctx->block_ipad[i] = key_temp[i] ^ 0x36; + ctx->block_opad[i] = key_temp[i] ^ 0x5c; + } + + ogs_sha512_init(&ctx->ctx_inside); + ogs_sha512_update(&ctx->ctx_inside, ctx->block_ipad, OGS_SHA512_BLOCK_SIZE); + + ogs_sha512_init(&ctx->ctx_outside); + ogs_sha512_update(&ctx->ctx_outside, ctx->block_opad, + OGS_SHA512_BLOCK_SIZE); + + /* for hmac_reinit */ + memcpy(&ctx->ctx_inside_reinit, &ctx->ctx_inside, + sizeof(ogs_sha512_ctx)); + memcpy(&ctx->ctx_outside_reinit, &ctx->ctx_outside, + sizeof(ogs_sha512_ctx)); +} + +void ogs_hmac_sha512_reinit(ogs_hmac_sha512_ctx *ctx) +{ + memcpy(&ctx->ctx_inside, &ctx->ctx_inside_reinit, + sizeof(ogs_sha512_ctx)); + memcpy(&ctx->ctx_outside, &ctx->ctx_outside_reinit, + sizeof(ogs_sha512_ctx)); +} + +void ogs_hmac_sha512_update(ogs_hmac_sha512_ctx *ctx, const uint8_t *message, + uint32_t message_len) +{ + ogs_sha512_update(&ctx->ctx_inside, message, message_len); +} + +void ogs_hmac_sha512_final(ogs_hmac_sha512_ctx *ctx, uint8_t *mac, + uint32_t mac_size) +{ + uint8_t digest_inside[OGS_SHA512_DIGEST_SIZE]; + uint8_t mac_temp[OGS_SHA512_DIGEST_SIZE]; + + ogs_sha512_final(&ctx->ctx_inside, digest_inside); + ogs_sha512_update(&ctx->ctx_outside, digest_inside, OGS_SHA512_DIGEST_SIZE); + ogs_sha512_final(&ctx->ctx_outside, mac_temp); + memcpy(mac, mac_temp, mac_size); +} + +void ogs_hmac_sha512(const uint8_t *key, uint32_t key_size, + const uint8_t *message, uint32_t message_len, + uint8_t *mac, uint32_t mac_size) +{ + ogs_hmac_sha512_ctx ctx; + + ogs_hmac_sha512_init(&ctx, key, key_size); + ogs_hmac_sha512_update(&ctx, message, message_len); + ogs_hmac_sha512_final(&ctx, mac, mac_size); +} diff --git a/lib/crypt/ogs-sha2-hmac.h b/lib/crypt/ogs-sha2-hmac.h new file mode 100644 index 000000000..dcd567027 --- /dev/null +++ b/lib/crypt/ogs-sha2-hmac.h @@ -0,0 +1,127 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#if !defined(OGS_CRYPT_INSIDE) && !defined(OGS_CRYPT_COMPILATION) +#error "This header cannot be included directly." +#endif + +#ifndef OGS_SHA2_HMAC_H +#define OGS_SHA2_HMAC_H + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct { + ogs_sha224_ctx ctx_inside; + ogs_sha224_ctx ctx_outside; + + /* for hmac_reinit */ + ogs_sha224_ctx ctx_inside_reinit; + ogs_sha224_ctx ctx_outside_reinit; + + uint8_t block_ipad[OGS_SHA224_BLOCK_SIZE]; + uint8_t block_opad[OGS_SHA224_BLOCK_SIZE]; +} ogs_hmac_sha224_ctx; + +typedef struct { + ogs_sha256_ctx ctx_inside; + ogs_sha256_ctx ctx_outside; + + /* for hmac_reinit */ + ogs_sha256_ctx ctx_inside_reinit; + ogs_sha256_ctx ctx_outside_reinit; + + uint8_t block_ipad[OGS_SHA256_BLOCK_SIZE]; + uint8_t block_opad[OGS_SHA256_BLOCK_SIZE]; +} ogs_hmac_sha256_ctx; + +typedef struct { + ogs_sha384_ctx ctx_inside; + ogs_sha384_ctx ctx_outside; + + /* for hmac_reinit */ + ogs_sha384_ctx ctx_inside_reinit; + ogs_sha384_ctx ctx_outside_reinit; + + uint8_t block_ipad[OGS_SHA384_BLOCK_SIZE]; + uint8_t block_opad[OGS_SHA384_BLOCK_SIZE]; +} ogs_hmac_sha384_ctx; + +typedef struct { + ogs_sha512_ctx ctx_inside; + ogs_sha512_ctx ctx_outside; + + /* for hmac_reinit */ + ogs_sha512_ctx ctx_inside_reinit; + ogs_sha512_ctx ctx_outside_reinit; + + uint8_t block_ipad[OGS_SHA512_BLOCK_SIZE]; + uint8_t block_opad[OGS_SHA512_BLOCK_SIZE]; +} ogs_hmac_sha512_ctx; + +void ogs_hmac_sha224_init(ogs_hmac_sha224_ctx *ctx, const uint8_t *key, + uint32_t key_size); +void ogs_hmac_sha224_reinit(ogs_hmac_sha224_ctx *ctx); +void ogs_hmac_sha224_update(ogs_hmac_sha224_ctx *ctx, const uint8_t *message, + uint32_t message_len); +void ogs_hmac_sha224_final(ogs_hmac_sha224_ctx *ctx, uint8_t *mac, + uint32_t mac_size); +void ogs_hmac_sha224(const uint8_t *key, uint32_t key_size, + const uint8_t *message, uint32_t message_len, + uint8_t *mac, uint32_t mac_size); + +void ogs_hmac_sha256_init(ogs_hmac_sha256_ctx *ctx, const uint8_t *key, + uint32_t key_size); +void ogs_hmac_sha256_reinit(ogs_hmac_sha256_ctx *ctx); +void ogs_hmac_sha256_update(ogs_hmac_sha256_ctx *ctx, const uint8_t *message, + uint32_t message_len); +void ogs_hmac_sha256_final(ogs_hmac_sha256_ctx *ctx, uint8_t *mac, + uint32_t mac_size); +void ogs_hmac_sha256(const uint8_t *key, uint32_t key_size, + const uint8_t *message, uint32_t message_len, + uint8_t *mac, uint32_t mac_size); + +void ogs_hmac_sha384_init(ogs_hmac_sha384_ctx *ctx, const uint8_t *key, + uint32_t key_size); +void ogs_hmac_sha384_reinit(ogs_hmac_sha384_ctx *ctx); +void ogs_hmac_sha384_update(ogs_hmac_sha384_ctx *ctx, const uint8_t *message, + uint32_t message_len); +void ogs_hmac_sha384_final(ogs_hmac_sha384_ctx *ctx, uint8_t *mac, + uint32_t mac_size); +void ogs_hmac_sha384(const uint8_t *key, uint32_t key_size, + const uint8_t *message, uint32_t message_len, + uint8_t *mac, uint32_t mac_size); + +void ogs_hmac_sha512_init(ogs_hmac_sha512_ctx *ctx, const uint8_t *key, + uint32_t key_size); +void ogs_hmac_sha512_reinit(ogs_hmac_sha512_ctx *ctx); +void ogs_hmac_sha512_update(ogs_hmac_sha512_ctx *ctx, const uint8_t *message, + uint32_t message_len); +void ogs_hmac_sha512_final(ogs_hmac_sha512_ctx *ctx, uint8_t *mac, + uint32_t mac_size); +void ogs_hmac_sha512(const uint8_t *key, uint32_t key_size, + const uint8_t *message, uint32_t message_len, + uint8_t *mac, uint32_t mac_size); + +#ifdef __cplusplus +} +#endif + +#endif /* OGS_SHA2_HMAC_H */ diff --git a/lib/crypt/ogs-sha2.c b/lib/crypt/ogs-sha2.c new file mode 100644 index 000000000..b6ceecb8d --- /dev/null +++ b/lib/crypt/ogs-sha2.c @@ -0,0 +1,834 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +/* + * FIPS 180-2 SHA-224/256/384/512 implementation + * Last update: 02/02/2007 + * Issue date: 04/30/2005 + * + * Copyright (C) 2005, 2007 Olivier Gay + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the project nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include "ogs-crypt.h" + +#define SHFR(x, n) (x >> n) +#define ROTR(x, n) ((x >> n) | (x << ((sizeof(x) << 3) - n))) +#define ROTL(x, n) ((x << n) | (x >> ((sizeof(x) << 3) - n))) +#define CH(x, y, z) ((x & y) ^ (~x & z)) +#define MAJ(x, y, z) ((x & y) ^ (x & z) ^ (y & z)) + +#define SHA256_F1(x) (ROTR(x, 2) ^ ROTR(x, 13) ^ ROTR(x, 22)) +#define SHA256_F2(x) (ROTR(x, 6) ^ ROTR(x, 11) ^ ROTR(x, 25)) +#define SHA256_F3(x) (ROTR(x, 7) ^ ROTR(x, 18) ^ SHFR(x, 3)) +#define SHA256_F4(x) (ROTR(x, 17) ^ ROTR(x, 19) ^ SHFR(x, 10)) + +#define SHA512_F1(x) (ROTR(x, 28) ^ ROTR(x, 34) ^ ROTR(x, 39)) +#define SHA512_F2(x) (ROTR(x, 14) ^ ROTR(x, 18) ^ ROTR(x, 41)) +#define SHA512_F3(x) (ROTR(x, 1) ^ ROTR(x, 8) ^ SHFR(x, 7)) +#define SHA512_F4(x) (ROTR(x, 19) ^ ROTR(x, 61) ^ SHFR(x, 6)) + +#define UNPACK32(x, str) \ +{ \ + *((str) + 3) = (uint8_t) ((x) ); \ + *((str) + 2) = (uint8_t) ((x) >> 8); \ + *((str) + 1) = (uint8_t) ((x) >> 16); \ + *((str) + 0) = (uint8_t) ((x) >> 24); \ +} + +#define PACK32(str, x) \ +{ \ + *(x) = ((uint32_t) *((str) + 3) ) \ + | ((uint32_t) *((str) + 2) << 8) \ + | ((uint32_t) *((str) + 1) << 16) \ + | ((uint32_t) *((str) + 0) << 24); \ +} + +#define UNPACK64(x, str) \ +{ \ + *((str) + 7) = (uint8_t) ((x) ); \ + *((str) + 6) = (uint8_t) ((x) >> 8); \ + *((str) + 5) = (uint8_t) ((x) >> 16); \ + *((str) + 4) = (uint8_t) ((x) >> 24); \ + *((str) + 3) = (uint8_t) ((x) >> 32); \ + *((str) + 2) = (uint8_t) ((x) >> 40); \ + *((str) + 1) = (uint8_t) ((x) >> 48); \ + *((str) + 0) = (uint8_t) ((x) >> 56); \ +} + +#define PACK64(str, x) \ +{ \ + *(x) = ((uint64_t) *((str) + 7) ) \ + | ((uint64_t) *((str) + 6) << 8) \ + | ((uint64_t) *((str) + 5) << 16) \ + | ((uint64_t) *((str) + 4) << 24) \ + | ((uint64_t) *((str) + 3) << 32) \ + | ((uint64_t) *((str) + 2) << 40) \ + | ((uint64_t) *((str) + 1) << 48) \ + | ((uint64_t) *((str) + 0) << 56); \ +} + +/* Macros used for loops unrolling */ + +#define SHA256_SCR(i) \ +{ \ + w[i] = SHA256_F4(w[i - 2]) + w[i - 7] \ + + SHA256_F3(w[i - 15]) + w[i - 16]; \ +} + +#define SHA512_SCR(i) \ +{ \ + w[i] = SHA512_F4(w[i - 2]) + w[i - 7] \ + + SHA512_F3(w[i - 15]) + w[i - 16]; \ +} + +#define SHA256_EXP(a, b, c, d, e, f, g, h, j) \ +{ \ + t1 = wv[h] + SHA256_F2(wv[e]) + CH(wv[e], wv[f], wv[g]) \ + + sha256_k[j] + w[j]; \ + t2 = SHA256_F1(wv[a]) + MAJ(wv[a], wv[b], wv[c]); \ + wv[d] += t1; \ + wv[h] = t1 + t2; \ +} + +#define SHA512_EXP(a, b, c, d, e, f, g ,h, j) \ +{ \ + t1 = wv[h] + SHA512_F2(wv[e]) + CH(wv[e], wv[f], wv[g]) \ + + sha512_k[j] + w[j]; \ + t2 = SHA512_F1(wv[a]) + MAJ(wv[a], wv[b], wv[c]); \ + wv[d] += t1; \ + wv[h] = t1 + t2; \ +} + +static uint32_t sha224_h0[8] = + {0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939, + 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4}; + +static uint32_t sha256_h0[8] = + {0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, + 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19}; + +static uint64_t sha384_h0[8] = + {0xcbbb9d5dc1059ed8ULL, 0x629a292a367cd507ULL, + 0x9159015a3070dd17ULL, 0x152fecd8f70e5939ULL, + 0x67332667ffc00b31ULL, 0x8eb44a8768581511ULL, + 0xdb0c2e0d64f98fa7ULL, 0x47b5481dbefa4fa4ULL}; + +static uint64_t sha512_h0[8] = + {0x6a09e667f3bcc908ULL, 0xbb67ae8584caa73bULL, + 0x3c6ef372fe94f82bULL, 0xa54ff53a5f1d36f1ULL, + 0x510e527fade682d1ULL, 0x9b05688c2b3e6c1fULL, + 0x1f83d9abfb41bd6bULL, 0x5be0cd19137e2179ULL}; + +static uint32_t sha256_k[64] = + {0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, + 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, + 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, + 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, + 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, + 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, + 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, + 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, + 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, + 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, + 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, + 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, + 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, + 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, + 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, + 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2}; + +static uint64_t sha512_k[80] = + {0x428a2f98d728ae22ULL, 0x7137449123ef65cdULL, + 0xb5c0fbcfec4d3b2fULL, 0xe9b5dba58189dbbcULL, + 0x3956c25bf348b538ULL, 0x59f111f1b605d019ULL, + 0x923f82a4af194f9bULL, 0xab1c5ed5da6d8118ULL, + 0xd807aa98a3030242ULL, 0x12835b0145706fbeULL, + 0x243185be4ee4b28cULL, 0x550c7dc3d5ffb4e2ULL, + 0x72be5d74f27b896fULL, 0x80deb1fe3b1696b1ULL, + 0x9bdc06a725c71235ULL, 0xc19bf174cf692694ULL, + 0xe49b69c19ef14ad2ULL, 0xefbe4786384f25e3ULL, + 0x0fc19dc68b8cd5b5ULL, 0x240ca1cc77ac9c65ULL, + 0x2de92c6f592b0275ULL, 0x4a7484aa6ea6e483ULL, + 0x5cb0a9dcbd41fbd4ULL, 0x76f988da831153b5ULL, + 0x983e5152ee66dfabULL, 0xa831c66d2db43210ULL, + 0xb00327c898fb213fULL, 0xbf597fc7beef0ee4ULL, + 0xc6e00bf33da88fc2ULL, 0xd5a79147930aa725ULL, + 0x06ca6351e003826fULL, 0x142929670a0e6e70ULL, + 0x27b70a8546d22ffcULL, 0x2e1b21385c26c926ULL, + 0x4d2c6dfc5ac42aedULL, 0x53380d139d95b3dfULL, + 0x650a73548baf63deULL, 0x766a0abb3c77b2a8ULL, + 0x81c2c92e47edaee6ULL, 0x92722c851482353bULL, + 0xa2bfe8a14cf10364ULL, 0xa81a664bbc423001ULL, + 0xc24b8b70d0f89791ULL, 0xc76c51a30654be30ULL, + 0xd192e819d6ef5218ULL, 0xd69906245565a910ULL, + 0xf40e35855771202aULL, 0x106aa07032bbd1b8ULL, + 0x19a4c116b8d2d0c8ULL, 0x1e376c085141ab53ULL, + 0x2748774cdf8eeb99ULL, 0x34b0bcb5e19b48a8ULL, + 0x391c0cb3c5c95a63ULL, 0x4ed8aa4ae3418acbULL, + 0x5b9cca4f7763e373ULL, 0x682e6ff3d6b2b8a3ULL, + 0x748f82ee5defb2fcULL, 0x78a5636f43172f60ULL, + 0x84c87814a1f0ab72ULL, 0x8cc702081a6439ecULL, + 0x90befffa23631e28ULL, 0xa4506cebde82bde9ULL, + 0xbef9a3f7b2c67915ULL, 0xc67178f2e372532bULL, + 0xca273eceea26619cULL, 0xd186b8c721c0c207ULL, + 0xeada7dd6cde0eb1eULL, 0xf57d4f7fee6ed178ULL, + 0x06f067aa72176fbaULL, 0x0a637dc5a2c898a6ULL, + 0x113f9804bef90daeULL, 0x1b710b35131c471bULL, + 0x28db77f523047d84ULL, 0x32caab7b40c72493ULL, + 0x3c9ebe0a15c9bebcULL, 0x431d67c49c100d4cULL, + 0x4cc5d4becb3e42b6ULL, 0x597f299cfc657e2aULL, + 0x5fcb6fab3ad6faecULL, 0x6c44198c4a475817ULL}; + +/* SHA-256 functions */ + +static void sha256_transf(ogs_sha256_ctx *ctx, const uint8_t *message, + uint32_t block_nb) +{ + uint32_t w[64]; + uint32_t wv[8]; + uint32_t t1, t2; + const uint8_t *sub_block; + int i; + +#ifndef UNROLL_LOOPS + int j; +#endif + + for (i = 0; i < (int) block_nb; i++) { + sub_block = message + (i << 6); + +#ifndef UNROLL_LOOPS + for (j = 0; j < 16; j++) { + PACK32(&sub_block[j << 2], &w[j]); + } + + for (j = 16; j < 64; j++) { + SHA256_SCR(j); + } + + for (j = 0; j < 8; j++) { + wv[j] = ctx->h[j]; + } + + for (j = 0; j < 64; j++) { + t1 = wv[7] + SHA256_F2(wv[4]) + CH(wv[4], wv[5], wv[6]) + + sha256_k[j] + w[j]; + t2 = SHA256_F1(wv[0]) + MAJ(wv[0], wv[1], wv[2]); + wv[7] = wv[6]; + wv[6] = wv[5]; + wv[5] = wv[4]; + wv[4] = wv[3] + t1; + wv[3] = wv[2]; + wv[2] = wv[1]; + wv[1] = wv[0]; + wv[0] = t1 + t2; + } + + for (j = 0; j < 8; j++) { + ctx->h[j] += wv[j]; + } +#else + PACK32(&sub_block[ 0], &w[ 0]); PACK32(&sub_block[ 4], &w[ 1]); + PACK32(&sub_block[ 8], &w[ 2]); PACK32(&sub_block[12], &w[ 3]); + PACK32(&sub_block[16], &w[ 4]); PACK32(&sub_block[20], &w[ 5]); + PACK32(&sub_block[24], &w[ 6]); PACK32(&sub_block[28], &w[ 7]); + PACK32(&sub_block[32], &w[ 8]); PACK32(&sub_block[36], &w[ 9]); + PACK32(&sub_block[40], &w[10]); PACK32(&sub_block[44], &w[11]); + PACK32(&sub_block[48], &w[12]); PACK32(&sub_block[52], &w[13]); + PACK32(&sub_block[56], &w[14]); PACK32(&sub_block[60], &w[15]); + + SHA256_SCR(16); SHA256_SCR(17); SHA256_SCR(18); SHA256_SCR(19); + SHA256_SCR(20); SHA256_SCR(21); SHA256_SCR(22); SHA256_SCR(23); + SHA256_SCR(24); SHA256_SCR(25); SHA256_SCR(26); SHA256_SCR(27); + SHA256_SCR(28); SHA256_SCR(29); SHA256_SCR(30); SHA256_SCR(31); + SHA256_SCR(32); SHA256_SCR(33); SHA256_SCR(34); SHA256_SCR(35); + SHA256_SCR(36); SHA256_SCR(37); SHA256_SCR(38); SHA256_SCR(39); + SHA256_SCR(40); SHA256_SCR(41); SHA256_SCR(42); SHA256_SCR(43); + SHA256_SCR(44); SHA256_SCR(45); SHA256_SCR(46); SHA256_SCR(47); + SHA256_SCR(48); SHA256_SCR(49); SHA256_SCR(50); SHA256_SCR(51); + SHA256_SCR(52); SHA256_SCR(53); SHA256_SCR(54); SHA256_SCR(55); + SHA256_SCR(56); SHA256_SCR(57); SHA256_SCR(58); SHA256_SCR(59); + SHA256_SCR(60); SHA256_SCR(61); SHA256_SCR(62); SHA256_SCR(63); + + wv[0] = ctx->h[0]; wv[1] = ctx->h[1]; + wv[2] = ctx->h[2]; wv[3] = ctx->h[3]; + wv[4] = ctx->h[4]; wv[5] = ctx->h[5]; + wv[6] = ctx->h[6]; wv[7] = ctx->h[7]; + + SHA256_EXP(0,1,2,3,4,5,6,7, 0); SHA256_EXP(7,0,1,2,3,4,5,6, 1); + SHA256_EXP(6,7,0,1,2,3,4,5, 2); SHA256_EXP(5,6,7,0,1,2,3,4, 3); + SHA256_EXP(4,5,6,7,0,1,2,3, 4); SHA256_EXP(3,4,5,6,7,0,1,2, 5); + SHA256_EXP(2,3,4,5,6,7,0,1, 6); SHA256_EXP(1,2,3,4,5,6,7,0, 7); + SHA256_EXP(0,1,2,3,4,5,6,7, 8); SHA256_EXP(7,0,1,2,3,4,5,6, 9); + SHA256_EXP(6,7,0,1,2,3,4,5,10); SHA256_EXP(5,6,7,0,1,2,3,4,11); + SHA256_EXP(4,5,6,7,0,1,2,3,12); SHA256_EXP(3,4,5,6,7,0,1,2,13); + SHA256_EXP(2,3,4,5,6,7,0,1,14); SHA256_EXP(1,2,3,4,5,6,7,0,15); + SHA256_EXP(0,1,2,3,4,5,6,7,16); SHA256_EXP(7,0,1,2,3,4,5,6,17); + SHA256_EXP(6,7,0,1,2,3,4,5,18); SHA256_EXP(5,6,7,0,1,2,3,4,19); + SHA256_EXP(4,5,6,7,0,1,2,3,20); SHA256_EXP(3,4,5,6,7,0,1,2,21); + SHA256_EXP(2,3,4,5,6,7,0,1,22); SHA256_EXP(1,2,3,4,5,6,7,0,23); + SHA256_EXP(0,1,2,3,4,5,6,7,24); SHA256_EXP(7,0,1,2,3,4,5,6,25); + SHA256_EXP(6,7,0,1,2,3,4,5,26); SHA256_EXP(5,6,7,0,1,2,3,4,27); + SHA256_EXP(4,5,6,7,0,1,2,3,28); SHA256_EXP(3,4,5,6,7,0,1,2,29); + SHA256_EXP(2,3,4,5,6,7,0,1,30); SHA256_EXP(1,2,3,4,5,6,7,0,31); + SHA256_EXP(0,1,2,3,4,5,6,7,32); SHA256_EXP(7,0,1,2,3,4,5,6,33); + SHA256_EXP(6,7,0,1,2,3,4,5,34); SHA256_EXP(5,6,7,0,1,2,3,4,35); + SHA256_EXP(4,5,6,7,0,1,2,3,36); SHA256_EXP(3,4,5,6,7,0,1,2,37); + SHA256_EXP(2,3,4,5,6,7,0,1,38); SHA256_EXP(1,2,3,4,5,6,7,0,39); + SHA256_EXP(0,1,2,3,4,5,6,7,40); SHA256_EXP(7,0,1,2,3,4,5,6,41); + SHA256_EXP(6,7,0,1,2,3,4,5,42); SHA256_EXP(5,6,7,0,1,2,3,4,43); + SHA256_EXP(4,5,6,7,0,1,2,3,44); SHA256_EXP(3,4,5,6,7,0,1,2,45); + SHA256_EXP(2,3,4,5,6,7,0,1,46); SHA256_EXP(1,2,3,4,5,6,7,0,47); + SHA256_EXP(0,1,2,3,4,5,6,7,48); SHA256_EXP(7,0,1,2,3,4,5,6,49); + SHA256_EXP(6,7,0,1,2,3,4,5,50); SHA256_EXP(5,6,7,0,1,2,3,4,51); + SHA256_EXP(4,5,6,7,0,1,2,3,52); SHA256_EXP(3,4,5,6,7,0,1,2,53); + SHA256_EXP(2,3,4,5,6,7,0,1,54); SHA256_EXP(1,2,3,4,5,6,7,0,55); + SHA256_EXP(0,1,2,3,4,5,6,7,56); SHA256_EXP(7,0,1,2,3,4,5,6,57); + SHA256_EXP(6,7,0,1,2,3,4,5,58); SHA256_EXP(5,6,7,0,1,2,3,4,59); + SHA256_EXP(4,5,6,7,0,1,2,3,60); SHA256_EXP(3,4,5,6,7,0,1,2,61); + SHA256_EXP(2,3,4,5,6,7,0,1,62); SHA256_EXP(1,2,3,4,5,6,7,0,63); + + ctx->h[0] += wv[0]; ctx->h[1] += wv[1]; + ctx->h[2] += wv[2]; ctx->h[3] += wv[3]; + ctx->h[4] += wv[4]; ctx->h[5] += wv[5]; + ctx->h[6] += wv[6]; ctx->h[7] += wv[7]; +#endif /* !UNROLL_LOOPS */ + } +} + +void ogs_sha256(const uint8_t *message, uint32_t len, uint8_t *digest) +{ + ogs_sha256_ctx ctx; + + ogs_sha256_init(&ctx); + ogs_sha256_update(&ctx, message, len); + ogs_sha256_final(&ctx, digest); +} + +void ogs_sha256_init(ogs_sha256_ctx *ctx) +{ +#ifndef UNROLL_LOOPS + int i; + for (i = 0; i < 8; i++) { + ctx->h[i] = sha256_h0[i]; + } +#else + ctx->h[0] = sha256_h0[0]; ctx->h[1] = sha256_h0[1]; + ctx->h[2] = sha256_h0[2]; ctx->h[3] = sha256_h0[3]; + ctx->h[4] = sha256_h0[4]; ctx->h[5] = sha256_h0[5]; + ctx->h[6] = sha256_h0[6]; ctx->h[7] = sha256_h0[7]; +#endif /* !UNROLL_LOOPS */ + + ctx->len = 0; + ctx->tot_len = 0; +} + +void ogs_sha256_update(ogs_sha256_ctx *ctx, const uint8_t *message, + uint32_t len) +{ + uint32_t block_nb; + uint32_t new_len, rem_len, tmp_len; + const uint8_t *shifted_message; + + tmp_len = OGS_SHA256_BLOCK_SIZE - ctx->len; + rem_len = len < tmp_len ? len : tmp_len; + + memcpy(&ctx->block[ctx->len], message, rem_len); + + if (ctx->len + len < OGS_SHA256_BLOCK_SIZE) { + ctx->len += len; + return; + } + + new_len = len - rem_len; + block_nb = new_len / OGS_SHA256_BLOCK_SIZE; + + shifted_message = message + rem_len; + + sha256_transf(ctx, ctx->block, 1); + sha256_transf(ctx, shifted_message, block_nb); + + rem_len = new_len % OGS_SHA256_BLOCK_SIZE; + + memcpy(ctx->block, &shifted_message[block_nb << 6], + rem_len); + + ctx->len = rem_len; + ctx->tot_len += (block_nb + 1) << 6; +} + +void ogs_sha256_final(ogs_sha256_ctx *ctx, uint8_t *digest) +{ + uint32_t block_nb; + uint32_t pm_len; + uint32_t len_b; + +#ifndef UNROLL_LOOPS + int i; +#endif + + block_nb = (1 + ((OGS_SHA256_BLOCK_SIZE - 9) + < (ctx->len % OGS_SHA256_BLOCK_SIZE))); + + len_b = (ctx->tot_len + ctx->len) << 3; + pm_len = block_nb << 6; + + memset(ctx->block + ctx->len, 0, pm_len - ctx->len); + ctx->block[ctx->len] = 0x80; + UNPACK32(len_b, ctx->block + pm_len - 4); + + sha256_transf(ctx, ctx->block, block_nb); + +#ifndef UNROLL_LOOPS + for (i = 0 ; i < 8; i++) { + UNPACK32(ctx->h[i], &digest[i << 2]); + } +#else + UNPACK32(ctx->h[0], &digest[ 0]); + UNPACK32(ctx->h[1], &digest[ 4]); + UNPACK32(ctx->h[2], &digest[ 8]); + UNPACK32(ctx->h[3], &digest[12]); + UNPACK32(ctx->h[4], &digest[16]); + UNPACK32(ctx->h[5], &digest[20]); + UNPACK32(ctx->h[6], &digest[24]); + UNPACK32(ctx->h[7], &digest[28]); +#endif /* !UNROLL_LOOPS */ +} + +/* SHA-512 functions */ + +static void sha512_transf(ogs_sha512_ctx *ctx, const uint8_t *message, + uint32_t block_nb) +{ + uint64_t w[80]; + uint64_t wv[8]; + uint64_t t1, t2; + const uint8_t *sub_block; + int i, j; + + for (i = 0; i < (int) block_nb; i++) { + sub_block = message + (i << 7); + +#ifndef UNROLL_LOOPS + for (j = 0; j < 16; j++) { + PACK64(&sub_block[j << 3], &w[j]); + } + + for (j = 16; j < 80; j++) { + SHA512_SCR(j); + } + + for (j = 0; j < 8; j++) { + wv[j] = ctx->h[j]; + } + + for (j = 0; j < 80; j++) { + t1 = wv[7] + SHA512_F2(wv[4]) + CH(wv[4], wv[5], wv[6]) + + sha512_k[j] + w[j]; + t2 = SHA512_F1(wv[0]) + MAJ(wv[0], wv[1], wv[2]); + wv[7] = wv[6]; + wv[6] = wv[5]; + wv[5] = wv[4]; + wv[4] = wv[3] + t1; + wv[3] = wv[2]; + wv[2] = wv[1]; + wv[1] = wv[0]; + wv[0] = t1 + t2; + } + + for (j = 0; j < 8; j++) { + ctx->h[j] += wv[j]; + } +#else + PACK64(&sub_block[ 0], &w[ 0]); PACK64(&sub_block[ 8], &w[ 1]); + PACK64(&sub_block[ 16], &w[ 2]); PACK64(&sub_block[ 24], &w[ 3]); + PACK64(&sub_block[ 32], &w[ 4]); PACK64(&sub_block[ 40], &w[ 5]); + PACK64(&sub_block[ 48], &w[ 6]); PACK64(&sub_block[ 56], &w[ 7]); + PACK64(&sub_block[ 64], &w[ 8]); PACK64(&sub_block[ 72], &w[ 9]); + PACK64(&sub_block[ 80], &w[10]); PACK64(&sub_block[ 88], &w[11]); + PACK64(&sub_block[ 96], &w[12]); PACK64(&sub_block[104], &w[13]); + PACK64(&sub_block[112], &w[14]); PACK64(&sub_block[120], &w[15]); + + SHA512_SCR(16); SHA512_SCR(17); SHA512_SCR(18); SHA512_SCR(19); + SHA512_SCR(20); SHA512_SCR(21); SHA512_SCR(22); SHA512_SCR(23); + SHA512_SCR(24); SHA512_SCR(25); SHA512_SCR(26); SHA512_SCR(27); + SHA512_SCR(28); SHA512_SCR(29); SHA512_SCR(30); SHA512_SCR(31); + SHA512_SCR(32); SHA512_SCR(33); SHA512_SCR(34); SHA512_SCR(35); + SHA512_SCR(36); SHA512_SCR(37); SHA512_SCR(38); SHA512_SCR(39); + SHA512_SCR(40); SHA512_SCR(41); SHA512_SCR(42); SHA512_SCR(43); + SHA512_SCR(44); SHA512_SCR(45); SHA512_SCR(46); SHA512_SCR(47); + SHA512_SCR(48); SHA512_SCR(49); SHA512_SCR(50); SHA512_SCR(51); + SHA512_SCR(52); SHA512_SCR(53); SHA512_SCR(54); SHA512_SCR(55); + SHA512_SCR(56); SHA512_SCR(57); SHA512_SCR(58); SHA512_SCR(59); + SHA512_SCR(60); SHA512_SCR(61); SHA512_SCR(62); SHA512_SCR(63); + SHA512_SCR(64); SHA512_SCR(65); SHA512_SCR(66); SHA512_SCR(67); + SHA512_SCR(68); SHA512_SCR(69); SHA512_SCR(70); SHA512_SCR(71); + SHA512_SCR(72); SHA512_SCR(73); SHA512_SCR(74); SHA512_SCR(75); + SHA512_SCR(76); SHA512_SCR(77); SHA512_SCR(78); SHA512_SCR(79); + + wv[0] = ctx->h[0]; wv[1] = ctx->h[1]; + wv[2] = ctx->h[2]; wv[3] = ctx->h[3]; + wv[4] = ctx->h[4]; wv[5] = ctx->h[5]; + wv[6] = ctx->h[6]; wv[7] = ctx->h[7]; + + j = 0; + + do { + SHA512_EXP(0,1,2,3,4,5,6,7,j); j++; + SHA512_EXP(7,0,1,2,3,4,5,6,j); j++; + SHA512_EXP(6,7,0,1,2,3,4,5,j); j++; + SHA512_EXP(5,6,7,0,1,2,3,4,j); j++; + SHA512_EXP(4,5,6,7,0,1,2,3,j); j++; + SHA512_EXP(3,4,5,6,7,0,1,2,j); j++; + SHA512_EXP(2,3,4,5,6,7,0,1,j); j++; + SHA512_EXP(1,2,3,4,5,6,7,0,j); j++; + } while (j < 80); + + ctx->h[0] += wv[0]; ctx->h[1] += wv[1]; + ctx->h[2] += wv[2]; ctx->h[3] += wv[3]; + ctx->h[4] += wv[4]; ctx->h[5] += wv[5]; + ctx->h[6] += wv[6]; ctx->h[7] += wv[7]; +#endif /* !UNROLL_LOOPS */ + } +} + +void ogs_sha512(const uint8_t *message, uint32_t len, + uint8_t *digest) +{ + ogs_sha512_ctx ctx; + + ogs_sha512_init(&ctx); + ogs_sha512_update(&ctx, message, len); + ogs_sha512_final(&ctx, digest); +} + +void ogs_sha512_init(ogs_sha512_ctx *ctx) +{ +#ifndef UNROLL_LOOPS + int i; + for (i = 0; i < 8; i++) { + ctx->h[i] = sha512_h0[i]; + } +#else + ctx->h[0] = sha512_h0[0]; ctx->h[1] = sha512_h0[1]; + ctx->h[2] = sha512_h0[2]; ctx->h[3] = sha512_h0[3]; + ctx->h[4] = sha512_h0[4]; ctx->h[5] = sha512_h0[5]; + ctx->h[6] = sha512_h0[6]; ctx->h[7] = sha512_h0[7]; +#endif /* !UNROLL_LOOPS */ + + ctx->len = 0; + ctx->tot_len = 0; +} + +void ogs_sha512_update(ogs_sha512_ctx *ctx, const uint8_t *message, + uint32_t len) +{ + uint32_t block_nb; + uint32_t new_len, rem_len, tmp_len; + const uint8_t *shifted_message; + + tmp_len = OGS_SHA512_BLOCK_SIZE - ctx->len; + rem_len = len < tmp_len ? len : tmp_len; + + memcpy(&ctx->block[ctx->len], message, rem_len); + + if (ctx->len + len < OGS_SHA512_BLOCK_SIZE) { + ctx->len += len; + return; + } + + new_len = len - rem_len; + block_nb = new_len / OGS_SHA512_BLOCK_SIZE; + + shifted_message = message + rem_len; + + sha512_transf(ctx, ctx->block, 1); + sha512_transf(ctx, shifted_message, block_nb); + + rem_len = new_len % OGS_SHA512_BLOCK_SIZE; + + memcpy(ctx->block, &shifted_message[block_nb << 7], + rem_len); + + ctx->len = rem_len; + ctx->tot_len += (block_nb + 1) << 7; +} + +void ogs_sha512_final(ogs_sha512_ctx *ctx, uint8_t *digest) +{ + uint32_t block_nb; + uint32_t pm_len; + uint32_t len_b; + +#ifndef UNROLL_LOOPS + int i; +#endif + + block_nb = 1 + ((OGS_SHA512_BLOCK_SIZE - 17) + < (ctx->len % OGS_SHA512_BLOCK_SIZE)); + + len_b = (ctx->tot_len + ctx->len) << 3; + pm_len = block_nb << 7; + + memset(ctx->block + ctx->len, 0, pm_len - ctx->len); + ctx->block[ctx->len] = 0x80; + UNPACK32(len_b, ctx->block + pm_len - 4); + + sha512_transf(ctx, ctx->block, block_nb); + +#ifndef UNROLL_LOOPS + for (i = 0 ; i < 8; i++) { + UNPACK64(ctx->h[i], &digest[i << 3]); + } +#else + UNPACK64(ctx->h[0], &digest[ 0]); + UNPACK64(ctx->h[1], &digest[ 8]); + UNPACK64(ctx->h[2], &digest[16]); + UNPACK64(ctx->h[3], &digest[24]); + UNPACK64(ctx->h[4], &digest[32]); + UNPACK64(ctx->h[5], &digest[40]); + UNPACK64(ctx->h[6], &digest[48]); + UNPACK64(ctx->h[7], &digest[56]); +#endif /* !UNROLL_LOOPS */ +} + +/* SHA-384 functions */ + +void ogs_sha384(const uint8_t *message, uint32_t len, + uint8_t *digest) +{ + ogs_sha384_ctx ctx; + + ogs_sha384_init(&ctx); + ogs_sha384_update(&ctx, message, len); + ogs_sha384_final(&ctx, digest); +} + +void ogs_sha384_init(ogs_sha384_ctx *ctx) +{ +#ifndef UNROLL_LOOPS + int i; + for (i = 0; i < 8; i++) { + ctx->h[i] = sha384_h0[i]; + } +#else + ctx->h[0] = sha384_h0[0]; ctx->h[1] = sha384_h0[1]; + ctx->h[2] = sha384_h0[2]; ctx->h[3] = sha384_h0[3]; + ctx->h[4] = sha384_h0[4]; ctx->h[5] = sha384_h0[5]; + ctx->h[6] = sha384_h0[6]; ctx->h[7] = sha384_h0[7]; +#endif /* !UNROLL_LOOPS */ + + ctx->len = 0; + ctx->tot_len = 0; +} + +void ogs_sha384_update(ogs_sha384_ctx *ctx, const uint8_t *message, + uint32_t len) +{ + uint32_t block_nb; + uint32_t new_len, rem_len, tmp_len; + const uint8_t *shifted_message; + + tmp_len = OGS_SHA384_BLOCK_SIZE - ctx->len; + rem_len = len < tmp_len ? len : tmp_len; + + memcpy(&ctx->block[ctx->len], message, rem_len); + + if (ctx->len + len < OGS_SHA384_BLOCK_SIZE) { + ctx->len += len; + return; + } + + new_len = len - rem_len; + block_nb = new_len / OGS_SHA384_BLOCK_SIZE; + + shifted_message = message + rem_len; + + sha512_transf(ctx, ctx->block, 1); + sha512_transf(ctx, shifted_message, block_nb); + + rem_len = new_len % OGS_SHA384_BLOCK_SIZE; + + memcpy(ctx->block, &shifted_message[block_nb << 7], + rem_len); + + ctx->len = rem_len; + ctx->tot_len += (block_nb + 1) << 7; +} + +void ogs_sha384_final(ogs_sha384_ctx *ctx, uint8_t *digest) +{ + uint32_t block_nb; + uint32_t pm_len; + uint32_t len_b; + +#ifndef UNROLL_LOOPS + int i; +#endif + + block_nb = (1 + ((OGS_SHA384_BLOCK_SIZE - 17) + < (ctx->len % OGS_SHA384_BLOCK_SIZE))); + + len_b = (ctx->tot_len + ctx->len) << 3; + pm_len = block_nb << 7; + + memset(ctx->block + ctx->len, 0, pm_len - ctx->len); + ctx->block[ctx->len] = 0x80; + UNPACK32(len_b, ctx->block + pm_len - 4); + + sha512_transf(ctx, ctx->block, block_nb); + +#ifndef UNROLL_LOOPS + for (i = 0 ; i < 6; i++) { + UNPACK64(ctx->h[i], &digest[i << 3]); + } +#else + UNPACK64(ctx->h[0], &digest[ 0]); + UNPACK64(ctx->h[1], &digest[ 8]); + UNPACK64(ctx->h[2], &digest[16]); + UNPACK64(ctx->h[3], &digest[24]); + UNPACK64(ctx->h[4], &digest[32]); + UNPACK64(ctx->h[5], &digest[40]); +#endif /* !UNROLL_LOOPS */ +} + +/* SHA-224 functions */ + +void ogs_sha224(const uint8_t *message, uint32_t len, + uint8_t *digest) +{ + ogs_sha224_ctx ctx; + + ogs_sha224_init(&ctx); + ogs_sha224_update(&ctx, message, len); + ogs_sha224_final(&ctx, digest); +} + +void ogs_sha224_init(ogs_sha224_ctx *ctx) +{ +#ifndef UNROLL_LOOPS + int i; + for (i = 0; i < 8; i++) { + ctx->h[i] = sha224_h0[i]; + } +#else + ctx->h[0] = sha224_h0[0]; ctx->h[1] = sha224_h0[1]; + ctx->h[2] = sha224_h0[2]; ctx->h[3] = sha224_h0[3]; + ctx->h[4] = sha224_h0[4]; ctx->h[5] = sha224_h0[5]; + ctx->h[6] = sha224_h0[6]; ctx->h[7] = sha224_h0[7]; +#endif /* !UNROLL_LOOPS */ + + ctx->len = 0; + ctx->tot_len = 0; +} + +void ogs_sha224_update(ogs_sha224_ctx *ctx, const uint8_t *message, + uint32_t len) +{ + uint32_t block_nb; + uint32_t new_len, rem_len, tmp_len; + const uint8_t *shifted_message; + + tmp_len = OGS_SHA224_BLOCK_SIZE - ctx->len; + rem_len = len < tmp_len ? len : tmp_len; + + memcpy(&ctx->block[ctx->len], message, rem_len); + + if (ctx->len + len < OGS_SHA224_BLOCK_SIZE) { + ctx->len += len; + return; + } + + new_len = len - rem_len; + block_nb = new_len / OGS_SHA224_BLOCK_SIZE; + + shifted_message = message + rem_len; + + sha256_transf(ctx, ctx->block, 1); + sha256_transf(ctx, shifted_message, block_nb); + + rem_len = new_len % OGS_SHA224_BLOCK_SIZE; + + memcpy(ctx->block, &shifted_message[block_nb << 6], + rem_len); + + ctx->len = rem_len; + ctx->tot_len += (block_nb + 1) << 6; +} + +void ogs_sha224_final(ogs_sha224_ctx *ctx, uint8_t *digest) +{ + uint32_t block_nb; + uint32_t pm_len; + uint32_t len_b; + +#ifndef UNROLL_LOOPS + int i; +#endif + + block_nb = (1 + ((OGS_SHA224_BLOCK_SIZE - 9) + < (ctx->len % OGS_SHA224_BLOCK_SIZE))); + + len_b = (ctx->tot_len + ctx->len) << 3; + pm_len = block_nb << 6; + + memset(ctx->block + ctx->len, 0, pm_len - ctx->len); + ctx->block[ctx->len] = 0x80; + UNPACK32(len_b, ctx->block + pm_len - 4); + + sha256_transf(ctx, ctx->block, block_nb); + +#ifndef UNROLL_LOOPS + for (i = 0 ; i < 7; i++) { + UNPACK32(ctx->h[i], &digest[i << 2]); + } +#else + UNPACK32(ctx->h[0], &digest[ 0]); + UNPACK32(ctx->h[1], &digest[ 4]); + UNPACK32(ctx->h[2], &digest[ 8]); + UNPACK32(ctx->h[3], &digest[12]); + UNPACK32(ctx->h[4], &digest[16]); + UNPACK32(ctx->h[5], &digest[20]); + UNPACK32(ctx->h[6], &digest[24]); +#endif /* !UNROLL_LOOPS */ +} diff --git a/lib/crypt/ogs-sha2.h b/lib/crypt/ogs-sha2.h new file mode 100644 index 000000000..c531d0c5a --- /dev/null +++ b/lib/crypt/ogs-sha2.h @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#if !defined(OGS_CRYPT_INSIDE) && !defined(OGS_CRYPT_COMPILATION) +#error "This header cannot be included directly." +#endif + +#ifndef OGS_SHA2_H +#define OGS_SHA2_H + +#ifdef __cplusplus +extern "C" { +#endif + +#define OGS_SHA224_DIGEST_SIZE ( 224 / 8) +#define OGS_SHA256_DIGEST_SIZE ( 256 / 8) +#define OGS_SHA384_DIGEST_SIZE ( 384 / 8) +#define OGS_SHA512_DIGEST_SIZE ( 512 / 8) + +#define OGS_SHA256_BLOCK_SIZE ( 512 / 8) +#define OGS_SHA512_BLOCK_SIZE (1024 / 8) +#define OGS_SHA384_BLOCK_SIZE OGS_SHA512_BLOCK_SIZE +#define OGS_SHA224_BLOCK_SIZE OGS_SHA256_BLOCK_SIZE + +typedef struct { + uint32_t tot_len; + uint32_t len; + uint8_t block[2 * OGS_SHA256_BLOCK_SIZE]; + uint32_t h[8]; +} ogs_sha256_ctx; + +typedef struct { + uint32_t tot_len; + uint32_t len; + uint8_t block[2 * OGS_SHA512_BLOCK_SIZE]; + uint64_t h[8]; +} ogs_sha512_ctx; + +typedef ogs_sha512_ctx ogs_sha384_ctx; +typedef ogs_sha256_ctx ogs_sha224_ctx; + +void ogs_sha224_init(ogs_sha224_ctx *ctx); +void ogs_sha224_update(ogs_sha224_ctx *ctx, const uint8_t *message, + uint32_t len); +void ogs_sha224_final(ogs_sha224_ctx *ctx, uint8_t *digest); +void ogs_sha224(const uint8_t *message, uint32_t len, uint8_t *digest); + +void ogs_sha256_init(ogs_sha256_ctx * ctx); +void ogs_sha256_update(ogs_sha256_ctx *ctx, const uint8_t *message, + uint32_t len); +void ogs_sha256_final(ogs_sha256_ctx *ctx, uint8_t *digest); +void ogs_sha256(const uint8_t *message, uint32_t len, uint8_t *digest); + +void ogs_sha384_init(ogs_sha384_ctx *ctx); +void ogs_sha384_update(ogs_sha384_ctx *ctx, const uint8_t *message, + uint32_t len); +void ogs_sha384_final(ogs_sha384_ctx *ctx, uint8_t *digest); +void ogs_sha384(const uint8_t *message, uint32_t len, uint8_t *digest); + +void ogs_sha512_init(ogs_sha512_ctx *ctx); +void ogs_sha512_update(ogs_sha512_ctx *ctx, const uint8_t *message, + uint32_t len); +void ogs_sha512_final(ogs_sha512_ctx *ctx, uint8_t *digest); +void ogs_sha512(const uint8_t *message, uint32_t len, uint8_t *digest); + +#ifdef __cplusplus +} +#endif + +#endif /* OGS_SHA2_H */ diff --git a/lib/crypt/snow-3g.c b/lib/crypt/snow-3g.c new file mode 100644 index 000000000..9fca1ce79 --- /dev/null +++ b/lib/crypt/snow-3g.c @@ -0,0 +1,606 @@ +/*------------------------------------------------------------------------ +* SNOW_3G.c +*------------------------------------------------------------------------*/ + +#include "snow-3g.h" + +u8 MULx(u8 V, u8 c); +u8 MULxPOW(u8 V, u8 i, u8 c); +u32 MULalpha(u8 c); +u32 DIValpha(u8 c); +u32 S1(u32 w); +u32 S2(u32 w); +void ClockLFSRInitializationMode(u32 F); +void ClockLFSRKeyStreamMode(void); +u32 ClockFSM(void); +u64 MUL64x(u64 V, u64 c); +u64 MUL64xPOW(u64 V, u8 i, u64 c); +u64 MUL64(u64 V, u64 P, u64 c); +u8 mask8bit(int n); + +/* LFSR */ + +static u32 LFSR_S0 = 0x00; +static u32 LFSR_S1 = 0x00; +static u32 LFSR_S2 = 0x00; +static u32 LFSR_S3 = 0x00; +static u32 LFSR_S4 = 0x00; +static u32 LFSR_S5 = 0x00; +static u32 LFSR_S6 = 0x00; +static u32 LFSR_S7 = 0x00; +static u32 LFSR_S8 = 0x00; +static u32 LFSR_S9 = 0x00; +static u32 LFSR_S10 = 0x00; +static u32 LFSR_S11 = 0x00; +static u32 LFSR_S12 = 0x00; +static u32 LFSR_S13 = 0x00; +static u32 LFSR_S14 = 0x00; +static u32 LFSR_S15 = 0x00; + +/* FSM */ + +static u32 FSM_R1 = 0x00; +static u32 FSM_R2 = 0x00; +static u32 FSM_R3 = 0x00; + +/* Rijndael S-box SR */ + +static u8 SR[256] = { +0x63,0x7C,0x77,0x7B,0xF2,0x6B,0x6F,0xC5,0x30,0x01,0x67,0x2B,0xFE,0xD7,0xAB,0x76, +0xCA,0x82,0xC9,0x7D,0xFA,0x59,0x47,0xF0,0xAD,0xD4,0xA2,0xAF,0x9C,0xA4,0x72,0xC0, +0xB7,0xFD,0x93,0x26,0x36,0x3F,0xF7,0xCC,0x34,0xA5,0xE5,0xF1,0x71,0xD8,0x31,0x15, +0x04,0xC7,0x23,0xC3,0x18,0x96,0x05,0x9A,0x07,0x12,0x80,0xE2,0xEB,0x27,0xB2,0x75, +0x09,0x83,0x2C,0x1A,0x1B,0x6E,0x5A,0xA0,0x52,0x3B,0xD6,0xB3,0x29,0xE3,0x2F,0x84, +0x53,0xD1,0x00,0xED,0x20,0xFC,0xB1,0x5B,0x6A,0xCB,0xBE,0x39,0x4A,0x4C,0x58,0xCF, +0xD0,0xEF,0xAA,0xFB,0x43,0x4D,0x33,0x85,0x45,0xF9,0x02,0x7F,0x50,0x3C,0x9F,0xA8, +0x51,0xA3,0x40,0x8F,0x92,0x9D,0x38,0xF5,0xBC,0xB6,0xDA,0x21,0x10,0xFF,0xF3,0xD2, +0xCD,0x0C,0x13,0xEC,0x5F,0x97,0x44,0x17,0xC4,0xA7,0x7E,0x3D,0x64,0x5D,0x19,0x73, +0x60,0x81,0x4F,0xDC,0x22,0x2A,0x90,0x88,0x46,0xEE,0xB8,0x14,0xDE,0x5E,0x0B,0xDB, +0xE0,0x32,0x3A,0x0A,0x49,0x06,0x24,0x5C,0xC2,0xD3,0xAC,0x62,0x91,0x95,0xE4,0x79, +0xE7,0xC8,0x37,0x6D,0x8D,0xD5,0x4E,0xA9,0x6C,0x56,0xF4,0xEA,0x65,0x7A,0xAE,0x08, +0xBA,0x78,0x25,0x2E,0x1C,0xA6,0xB4,0xC6,0xE8,0xDD,0x74,0x1F,0x4B,0xBD,0x8B,0x8A, +0x70,0x3E,0xB5,0x66,0x48,0x03,0xF6,0x0E,0x61,0x35,0x57,0xB9,0x86,0xC1,0x1D,0x9E, +0xE1,0xF8,0x98,0x11,0x69,0xD9,0x8E,0x94,0x9B,0x1E,0x87,0xE9,0xCE,0x55,0x28,0xDF, +0x8C,0xA1,0x89,0x0D,0xBF,0xE6,0x42,0x68,0x41,0x99,0x2D,0x0F,0xB0,0x54,0xBB,0x16 +}; + +/* S-box SQ */ + +static u8 SQ[256] = { +0x25,0x24,0x73,0x67,0xD7,0xAE,0x5C,0x30,0xA4,0xEE,0x6E,0xCB,0x7D,0xB5,0x82,0xDB, +0xE4,0x8E,0x48,0x49,0x4F,0x5D,0x6A,0x78,0x70,0x88,0xE8,0x5F,0x5E,0x84,0x65,0xE2, +0xD8,0xE9,0xCC,0xED,0x40,0x2F,0x11,0x28,0x57,0xD2,0xAC,0xE3,0x4A,0x15,0x1B,0xB9, +0xB2,0x80,0x85,0xA6,0x2E,0x02,0x47,0x29,0x07,0x4B,0x0E,0xC1,0x51,0xAA,0x89,0xD4, +0xCA,0x01,0x46,0xB3,0xEF,0xDD,0x44,0x7B,0xC2,0x7F,0xBE,0xC3,0x9F,0x20,0x4C,0x64, +0x83,0xA2,0x68,0x42,0x13,0xB4,0x41,0xCD,0xBA,0xC6,0xBB,0x6D,0x4D,0x71,0x21,0xF4, +0x8D,0xB0,0xE5,0x93,0xFE,0x8F,0xE6,0xCF,0x43,0x45,0x31,0x22,0x37,0x36,0x96,0xFA, +0xBC,0x0F,0x08,0x52,0x1D,0x55,0x1A,0xC5,0x4E,0x23,0x69,0x7A,0x92,0xFF,0x5B,0x5A, +0xEB,0x9A,0x1C,0xA9,0xD1,0x7E,0x0D,0xFC,0x50,0x8A,0xB6,0x62,0xF5,0x0A,0xF8,0xDC, +0x03,0x3C,0x0C,0x39,0xF1,0xB8,0xF3,0x3D,0xF2,0xD5,0x97,0x66,0x81,0x32,0xA0,0x00, +0x06,0xCE,0xF6,0xEA,0xB7,0x17,0xF7,0x8C,0x79,0xD6,0xA7,0xBF,0x8B,0x3F,0x1F,0x53, +0x63,0x75,0x35,0x2C,0x60,0xFD,0x27,0xD3,0x94,0xA5,0x7C,0xA1,0x05,0x58,0x2D,0xBD, +0xD9,0xC7,0xAF,0x6B,0x54,0x0B,0xE0,0x38,0x04,0xC8,0x9D,0xE7,0x14,0xB1,0x87,0x9C, +0xDF,0x6F,0xF9,0xDA,0x2A,0xC4,0x59,0x16,0x74,0x91,0xAB,0x26,0x61,0x76,0x34,0x2B, +0xAD,0x99,0xFB,0x72,0xEC,0x33,0x12,0xDE,0x98,0x3B,0xC0,0x9B,0x3E,0x18,0x10,0x3A, +0x56,0xE1,0x77,0xC9,0x1E,0x9E,0x95,0xA3,0x90,0x19,0xA8,0x6C,0x09,0xD0,0xF0,0x86 +}; + +/* MULx. +* Input V: an 8-bit input. +* Input c: an 8-bit input. +* Output : an 8-bit output. +* See section 3.1.1 for details. +*/ + +u8 MULx(u8 V, u8 c) +{ + if ( V & 0x80 ) + return ( (V << 1) ^ c); + else + return ( V << 1); +} + +/* MULxPOW. +* Input V: an 8-bit input. +* Input i: a positive integer. +* Input c: an 8-bit input. +* Output : an 8-bit output. +* See section 3.1.2 for details. +*/ + +u8 MULxPOW(u8 V, u8 i, u8 c) +{ + if ( i == 0) + return V; + else + return MULx( MULxPOW( V, i-1, c ), c); +} + +/* The function MUL alpha. +* Input c: 8-bit input. +* Output : 32-bit output. +* See section 3.4.2 for details. +*/ + +u32 MULalpha(u8 c) +{ + return ( ( ((u32)MULxPOW(c, 23, 0xa9)) << 24 ) | + ( ((u32)MULxPOW(c, 245, 0xa9)) << 16 ) | + ( ((u32)MULxPOW(c, 48, 0xa9)) << 8 ) | + ( ((u32)MULxPOW(c, 239, 0xa9)) ) ) ; +} + +/* The function DIV alpha. +* Input c: 8-bit input. +* Output : 32-bit output. +* See section 3.4.3 for details. +*/ + +u32 DIValpha(u8 c) +{ + return ( ( ((u32)MULxPOW(c, 16, 0xa9)) << 24 ) | + ( ((u32)MULxPOW(c, 39, 0xa9)) << 16 ) | + ( ((u32)MULxPOW(c, 6, 0xa9)) << 8 ) | + ( ((u32)MULxPOW(c, 64, 0xa9)) ) ) ; +} + +/* The 32x32-bit S-Box S1 +* Input: a 32-bit input. +* Output: a 32-bit output of S1 box. +* See section 3.3.1. +*/ + +u32 S1(u32 w) +{ + u8 r0=0, r1=0, r2=0, r3=0; + u8 srw0 = SR[ (u8)((w >> 24) & 0xff) ]; + u8 srw1 = SR[ (u8)((w >> 16) & 0xff) ]; + u8 srw2 = SR[ (u8)((w >> 8) & 0xff) ]; + u8 srw3 = SR[ (u8)((w) & 0xff) ]; + r0 = ( ( MULx( srw0 , 0x1b) ) ^ + ( srw1 ) ^ + ( srw2 ) ^ + ( (MULx( srw3, 0x1b)) ^ srw3 ) + ); + r1 = ( ( ( MULx( srw0 , 0x1b) ) ^ srw0 ) ^ + ( MULx(srw1, 0x1b) ) ^ + ( srw2 ) ^ + ( srw3 ) + ); + r2 = ( ( srw0 ) ^ + ( ( MULx( srw1 , 0x1b) ) ^ srw1 ) ^ + ( MULx(srw2, 0x1b) ) ^ + ( srw3 ) + ); + r3 = ( ( srw0 ) ^ + ( srw1 ) ^ + ( ( MULx( srw2 , 0x1b) ) ^ srw2 ) ^ + ( MULx( srw3, 0x1b) ) + ); + + return ( ( ((u32)r0) << 24 ) | ( ((u32)r1) << 16 ) | ( ((u32)r2) << 8 ) | + ( ((u32)r3) ) ); +} + +/* The 32x32-bit S-Box S2 +* Input: a 32-bit input. +* Output: a 32-bit output of S2 box. +* See section 3.3.2. +*/ + +u32 S2(u32 w) +{ + u8 r0=0, r1=0, r2=0, r3=0; + u8 sqw0 = SQ[ (u8)((w >> 24) & 0xff) ]; + u8 sqw1 = SQ[ (u8)((w >> 16) & 0xff) ]; + u8 sqw2 = SQ[ (u8)((w >> 8) & 0xff) ]; + u8 sqw3 = SQ[ (u8)((w) & 0xff) ]; + r0 = ( ( MULx( sqw0 , 0x69) ) ^ + ( sqw1 ) ^ + ( sqw2 ) ^ + ( (MULx( sqw3, 0x69)) ^ sqw3 ) + ); + r1 = ( ( ( MULx( sqw0 , 0x69) ) ^ sqw0 ) ^ + ( MULx(sqw1, 0x69) ) ^ + ( sqw2 ) ^ + ( sqw3 ) + ); + r2 = ( ( sqw0 ) ^ + ( ( MULx( sqw1 , 0x69) ) ^ sqw1 ) ^ + ( MULx(sqw2, 0x69) ) ^ + ( sqw3 ) + ); + r3 = ( ( sqw0 ) ^ + ( sqw1 ) ^ + ( ( MULx( sqw2 , 0x69) ) ^ sqw2 ) ^ + ( MULx( sqw3, 0x69) ) + ); + return ( ( ((u32)r0) << 24 ) | ( ((u32)r1) << 16 ) | ( ((u32)r2) << 8 ) | + ( ((u32)r3) ) ); +} + +/* Clocking LFSR in initialization mode. +* LFSR Registers S0 to S15 are updated as the LFSR receives a single clock. +* Input F: a 32-bit word comes from output of FSM. +* See section 3.4.4. +*/ + +void ClockLFSRInitializationMode(u32 F) +{ + u32 v = ( ( (LFSR_S0 << 8) & 0xffffff00 ) ^ + ( MULalpha( (u8)((LFSR_S0>>24) & 0xff) ) ) ^ + ( LFSR_S2 ) ^ + ( (LFSR_S11 >> 8) & 0x00ffffff ) ^ + ( DIValpha( (u8)( ( LFSR_S11) & 0xff ) ) ) ^ + ( F ) + ); + LFSR_S0 = LFSR_S1; + LFSR_S1 = LFSR_S2; + LFSR_S2 = LFSR_S3; + LFSR_S3 = LFSR_S4; + LFSR_S4 = LFSR_S5; + LFSR_S5 = LFSR_S6; + LFSR_S6 = LFSR_S7; + LFSR_S7 = LFSR_S8; + LFSR_S8 = LFSR_S9; + LFSR_S9 = LFSR_S10; + LFSR_S10 = LFSR_S11; + LFSR_S11 = LFSR_S12; + LFSR_S12 = LFSR_S13; + LFSR_S13 = LFSR_S14; + LFSR_S14 = LFSR_S15; + LFSR_S15 = v; +} + +/* Clocking LFSR in keystream mode. +* LFSR Registers S0 to S15 are updated as the LFSR receives a single clock. +* See section 3.4.5. +*/ + +void ClockLFSRKeyStreamMode(void) +{ + u32 v = ( ( (LFSR_S0 << 8) & 0xffffff00 ) ^ + ( MULalpha( (u8)((LFSR_S0>>24) & 0xff) ) ) ^ + ( LFSR_S2 ) ^ + ( (LFSR_S11 >> 8) & 0x00ffffff ) ^ + ( DIValpha( (u8)( ( LFSR_S11) & 0xff ) ) ) + ); + LFSR_S0 = LFSR_S1; + LFSR_S1 = LFSR_S2; + LFSR_S2 = LFSR_S3; + LFSR_S3 = LFSR_S4; + LFSR_S4 = LFSR_S5; + LFSR_S5 = LFSR_S6; + LFSR_S6 = LFSR_S7; + LFSR_S7 = LFSR_S8; + LFSR_S8 = LFSR_S9; + LFSR_S9 = LFSR_S10; + LFSR_S10 = LFSR_S11; + LFSR_S11 = LFSR_S12; + LFSR_S12 = LFSR_S13; + LFSR_S13 = LFSR_S14; + LFSR_S14 = LFSR_S15; + LFSR_S15 = v; +} + +/* Clocking FSM. +* Produces a 32-bit word F. +* Updates FSM registers R1, R2, R3. +* See Section 3.4.6. +*/ + +u32 ClockFSM(void) +{ + u32 F = ( ( LFSR_S15 + FSM_R1 ) & 0xffffffff ) ^ FSM_R2 ; + u32 r = ( FSM_R2 + ( FSM_R3 ^ LFSR_S5 ) ) & 0xffffffff ; + FSM_R3 = S2(FSM_R2); + FSM_R2 = S1(FSM_R1); + FSM_R1 = r; + return F; +} + +/* Initialization. +* Input k[4]: Four 32-bit words making up 128-bit key. +* Input IV[4]: Four 32-bit words making 128-bit initialization variable. +* Output: All the LFSRs and FSM are initialized for key generation. +* See Section 4.1. +*/ + +void snow_3g_initialize(u32 k[4], u32 IV[4]) +{ + u8 i=0; + u32 F = 0x0; + LFSR_S15 = k[3] ^ IV[0]; + LFSR_S14 = k[2]; + LFSR_S13 = k[1]; + LFSR_S12 = k[0] ^ IV[1]; + LFSR_S11 = k[3] ^ 0xffffffff; + LFSR_S10 = k[2] ^ 0xffffffff ^ IV[2]; + LFSR_S9 = k[1] ^ 0xffffffff ^ IV[3]; + LFSR_S8 = k[0] ^ 0xffffffff; + LFSR_S7 = k[3]; + LFSR_S6 = k[2]; + LFSR_S5 = k[1]; + LFSR_S4 = k[0]; + LFSR_S3 = k[3] ^ 0xffffffff; + LFSR_S2 = k[2] ^ 0xffffffff; + LFSR_S1 = k[1] ^ 0xffffffff; + LFSR_S0 = k[0] ^ 0xffffffff; + FSM_R1 = 0x0; + FSM_R2 = 0x0; + FSM_R3 = 0x0; + for(i=0;i<32;i++) + { + F = ClockFSM(); + ClockLFSRInitializationMode(F); + } +} + +/* Generation of Keystream. +* input n: number of 32-bit words of keystream. +* input z: space for the generated keystream, assumes +* memory is allocated already. +* output: generated keystream which is filled in z +* See section 4.2. +*/ + +void snow_3g_generate_key_stream(u32 n, u32 *ks) +{ + u32 t = 0; + u32 F = 0x0; + ClockFSM(); /* Clock FSM once. Discard the output. */ + ClockLFSRKeyStreamMode(); /* Clock LFSR in keystream mode once. */ + for ( t=0; t +#include +#include +*/ + +/* f8. +* Input key: 128 bit Confidentiality Key. +* Input count:32-bit Count, Frame dependent input. +* Input bearer: 5-bit Bearer identity (in the LSB side). +* Input dir:1 bit, direction of transmission. +* Input data: length number of bits, input bit stream. +* Input length: 32 bit Length, i.e., the number of bits to be encrypted or +* decrypted. +* Output data: Output bit stream. Assumes data is suitably memory +* allocated. +* Encrypts/decrypts blocks of data between 1 and 2^32 bits in length as +* defined in Section 3. +*/ + +void snow_3g_f8(u8 *key, u32 count, u32 bearer, u32 dir, u8 *data, u32 length) +{ + u32 K[4],IV[4]; + int n = ( length + 31 ) / 32; + int i=0; + int lastbits = (8-(length%8)) % 8; + u32 *KS; + + /*Initialisation*/ + /* Load the confidentiality key for SNOW 3G initialization as in section + 3.4. */ + for (i=0; i<4; i++) + K[3-i] = (key[4*i] << 24) ^ (key[4*i+1] << 16) + ^ (key[4*i+2] << 8) ^ (key[4*i+3]); + + /* Prepare the initialization vector (IV) for SNOW 3G initialization as in + section 3.4. */ + IV[3] = count; + IV[2] = (bearer << 27) | ((dir & 0x1) << 26); + IV[1] = IV[3]; + IV[0] = IV[2]; + + /* Run SNOW 3G algorithm to generate sequence of key stream bits KS*/ + snow_3g_initialize(K,IV); + KS = (u32 *)ogs_malloc(4*n); + snow_3g_generate_key_stream(n,(u32*)KS); + + /* Exclusive-OR the input data with keystream to generate the output bit + stream */ + for (i=0; i> 24) & 0xff; + data[4*i+1] ^= (u8) (KS[i] >> 16) & 0xff; + data[4*i+2] ^= (u8) (KS[i] >> 8) & 0xff; + data[4*i+3] ^= (u8) (KS[i] ) & 0xff; + } + + ogs_free(KS); + + /* zero last bits of data in case its length is not byte-aligned + this is an addition to the C reference code, which did not handle it */ + if (lastbits) + data[length/8] &= 256 - (1<>i ) & 0x1 ) + result ^= MUL64xPOW(V,i,c); + } + return result; +} + +/* mask8bit. + * Input n: an integer in 1-7. + * Output : an 8 bit mask. + * Prepares an 8 bit mask with required number of 1 bits on the MSB side. + */ +u8 mask8bit(int n) +{ + return 0xFF ^ ((1<<(8-n)) - 1); +} + +/* f9. + * Input key: 128 bit Integrity Key. + * Input count:32-bit Count, Frame dependent input. + * Input fresh: 32-bit Random number. + * Input dir:1 bit, direction of transmission (in the LSB). + * Input data: length number of bits, input bit stream. + * Input length: 64 bit Length, i.e., the number of bits to be MAC'd. + * Output : 32 bit block used as MAC + * Generates 32-bit MAC using UIA2 algorithm as defined in Section 4. + */ +void snow_3g_f9(u8* key, u32 count, u32 fresh, u32 dir, u8 *data, u64 length, + u8 *out) +{ + u32 K[4],IV[4], z[5]; + u32 i=0, D; + u64 EVAL; + u64 V; + u64 P; + u64 Q; + u64 c; + + u64 M_D_2; + int rem_bits = 0; + + /* Load the Integrity Key for SNOW3G initialization as in section 4.4. */ + for (i=0; i<4; i++) + { + K[3-i] = (key[4*i] << 24) ^ (key[4*i+1] << 16) ^ + (key[4*i+2] << 8) ^ (key[4*i+3]); + } + + /* Prepare the Initialization Vector (IV) for SNOW3G initialization as + in section 4.4. */ + IV[3] = count; + IV[2] = fresh; + IV[1] = count ^ ( dir << 31 ) ; + IV[0] = fresh ^ (dir << 15); + + z[0] = z[1] = z[2] = z[3] = z[4] = 0; + + /* Run SNOW 3G to produce 5 keystream words z_1, z_2, z_3, z_4 and z_5. */ + snow_3g_initialize(K, IV); + snow_3g_generate_key_stream(5, z); + + P = (u64)z[0] << 32 | (u64)z[1]; + Q = (u64)z[2] << 32 | (u64)z[3]; + + /* Calculation */ + if ((length % 64) == 0) + D = (length>>6) + 1; + else + D = (length>>6) + 2; + EVAL = 0; + c = 0x1b; + + /* for 0 <= i <= D-3 */ + for (i=0; i 7) + { + M_D_2 |= (u64)data[8*(D-2)+i] << (8*(7-i)); + rem_bits -= 8; + i++; + } + if (rem_bits > 0) + M_D_2 |= (u64)(data[8*(D-2)+i] & mask8bit(rem_bits)) << (8*(7-i)); + + V = EVAL ^ M_D_2; + EVAL = MUL64(V,P,c); + + /* for D-1 */ + EVAL ^= length; + + /* Multiply by Q */ + EVAL = MUL64(EVAL,Q,c); + + /* XOR with z_5: this is a modification to the reference C code, + which forgot to XOR z[5] */ + for (i=0; i<4; i++) + /* + MAC_I[i] = (mac32 >> (8*(3-i))) & 0xff; + */ + out[i] = ((EVAL >> (56-(i*8))) ^ (z[4] >> (24-(i*8)))) & 0xff; +} + +/* End of f9.c */ +/*------------------------------------------------------------------------*/ diff --git a/lib/crypt/snow-3g.h b/lib/crypt/snow-3g.h new file mode 100644 index 000000000..ef953ee7e --- /dev/null +++ b/lib/crypt/snow-3g.h @@ -0,0 +1,72 @@ +#if !defined(OGS_CRYPT_INSIDE) && !defined(OGS_CRYPT_COMPILATION) +#error "This header cannot be included directly." +#endif + +#ifndef SNOW_3G_H +#define SNOW_3G_H + +#include "ogs-core.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef uint8_t u8; +typedef uint32_t u32; +typedef uint64_t u64; + +/* Initialization. +* Input k[4]: Four 32-bit words making up 128-bit key. +* Input IV[4]: Four 32-bit words making 128-bit initialization variable. +* Output: All the LFSRs and FSM are initialized for key generation. +* See Section 4.1. +*/ + +void snow_3g_initialize(u32 k[4], u32 IV[4]); + +/* Generation of Keystream. +* input n: number of 32-bit words of keystream. +* input z: space for the generated keystream, assumes +* memory is allocated already. +* output: generated keystream which is filled in z +* See section 4.2. +*/ + +void snow_3g_generate_key_stream(u32 n, u32 *z); + +/* f8. +* Input key: 128 bit Confidentiality Key. +* Input count:32-bit Count, Frame dependent input. +* Input bearer: 5-bit Bearer identity (in the LSB side). +* Input dir:1 bit, direction of transmission. +* Input data: length number of bits, input bit stream. +* Input length: 32 bit Length, i.e., the number of bits to be encrypted or +* decrypted. +* Output data: Output bit stream. Assumes data is suitably memory +* allocated. +* Encrypts/decrypts blocks of data between 1 and 2^32 bits in length as +* defined in Section 3. +*/ + +void snow_3g_f8( u8 *key, u32 count, u32 bearer, u32 dir, + u8 *data, u32 length ); + +/* f9. +* Input key: 128 bit Integrity Key. +* Input count:32-bit Count, Frame dependent input. +* Input fresh: 32-bit Random number. +* Input dir:1 bit, direction of transmission (in the LSB). +* Input data: length number of bits, input bit stream. +* Input length: 64 bit Length, i.e., the number of bits to be MAC'd. +* Output : 32 bit block used as MAC +* Generates 32-bit MAC using UIA2 algorithm as defined in Section 4. +*/ + +void snow_3g_f9( u8* key, u32 count, u32 fresh, u32 dir, + u8 *data, u64 length, u8 *out); + +#ifdef __cplusplus +} +#endif + +#endif /* SNOW_3G_H */ diff --git a/lib/crypt/zuc.c b/lib/crypt/zuc.c new file mode 100644 index 000000000..38c4609b1 --- /dev/null +++ b/lib/crypt/zuc.c @@ -0,0 +1,404 @@ +/*--------------------------------------------- + * ZUC / EEA3 / EIA3 : LTE security algorithm + *--------------------------------------------*/ +#include "zuc.h" + +u32 AddM(u32 a, u32 b); +void LFSRWithInitialisationMode(u32 u); +void LFSRWithWorkMode(void); +void BitReorganization(void); +u32 L1(u32 X); +u32 L2(u32 X); +u32 F(void); +void ZUC(u8* k, u8* iv, u32* ks, u32 len); +u32 GET_WORD(u32 * DATA, u32 i); +u8 GET_BIT(u8 * DATA, u32 i); + +/*-------------------------------------------- + * ZUC keystream generator algorithm + *------------------------------------------*/ + +/* the state registers of LFSR */ +static u32 LFSR_S0; +static u32 LFSR_S1; +static u32 LFSR_S2; +static u32 LFSR_S3; +static u32 LFSR_S4; +static u32 LFSR_S5; +static u32 LFSR_S6; +static u32 LFSR_S7; +static u32 LFSR_S8; +static u32 LFSR_S9; +static u32 LFSR_S10; +static u32 LFSR_S11; +static u32 LFSR_S12; +static u32 LFSR_S13; +static u32 LFSR_S14; +static u32 LFSR_S15; + +/* the registers of F */ +static u32 F_R1; +static u32 F_R2; + +/* the outputs of BitReorganization */ +static u32 BRC_X0; +static u32 BRC_X1; +static u32 BRC_X2; +static u32 BRC_X3; + +/* the s-boxes */ +static u8 S0[256] = { +0x3e,0x72,0x5b,0x47,0xca,0xe0,0x00,0x33,0x04,0xd1,0x54,0x98,0x09,0xb9,0x6d,0xcb, +0x7b,0x1b,0xf9,0x32,0xaf,0x9d,0x6a,0xa5,0xb8,0x2d,0xfc,0x1d,0x08,0x53,0x03,0x90, +0x4d,0x4e,0x84,0x99,0xe4,0xce,0xd9,0x91,0xdd,0xb6,0x85,0x48,0x8b,0x29,0x6e,0xac, +0xcd,0xc1,0xf8,0x1e,0x73,0x43,0x69,0xc6,0xb5,0xbd,0xfd,0x39,0x63,0x20,0xd4,0x38, +0x76,0x7d,0xb2,0xa7,0xcf,0xed,0x57,0xc5,0xf3,0x2c,0xbb,0x14,0x21,0x06,0x55,0x9b, +0xe3,0xef,0x5e,0x31,0x4f,0x7f,0x5a,0xa4,0x0d,0x82,0x51,0x49,0x5f,0xba,0x58,0x1c, +0x4a,0x16,0xd5,0x17,0xa8,0x92,0x24,0x1f,0x8c,0xff,0xd8,0xae,0x2e,0x01,0xd3,0xad, +0x3b,0x4b,0xda,0x46,0xeb,0xc9,0xde,0x9a,0x8f,0x87,0xd7,0x3a,0x80,0x6f,0x2f,0xc8, +0xb1,0xb4,0x37,0xf7,0x0a,0x22,0x13,0x28,0x7c,0xcc,0x3c,0x89,0xc7,0xc3,0x96,0x56, +0x07,0xbf,0x7e,0xf0,0x0b,0x2b,0x97,0x52,0x35,0x41,0x79,0x61,0xa6,0x4c,0x10,0xfe, +0xbc,0x26,0x95,0x88,0x8a,0xb0,0xa3,0xfb,0xc0,0x18,0x94,0xf2,0xe1,0xe5,0xe9,0x5d, +0xd0,0xdc,0x11,0x66,0x64,0x5c,0xec,0x59,0x42,0x75,0x12,0xf5,0x74,0x9c,0xaa,0x23, +0x0e,0x86,0xab,0xbe,0x2a,0x02,0xe7,0x67,0xe6,0x44,0xa2,0x6c,0xc2,0x93,0x9f,0xf1, +0xf6,0xfa,0x36,0xd2,0x50,0x68,0x9e,0x62,0x71,0x15,0x3d,0xd6,0x40,0xc4,0xe2,0x0f, +0x8e,0x83,0x77,0x6b,0x25,0x05,0x3f,0x0c,0x30,0xea,0x70,0xb7,0xa1,0xe8,0xa9,0x65, +0x8d,0x27,0x1a,0xdb,0x81,0xb3,0xa0,0xf4,0x45,0x7a,0x19,0xdf,0xee,0x78,0x34,0x60 +}; + +static u8 S1[256] = { +0x55,0xc2,0x63,0x71,0x3b,0xc8,0x47,0x86,0x9f,0x3c,0xda,0x5b,0x29,0xaa,0xfd,0x77, +0x8c,0xc5,0x94,0x0c,0xa6,0x1a,0x13,0x00,0xe3,0xa8,0x16,0x72,0x40,0xf9,0xf8,0x42, +0x44,0x26,0x68,0x96,0x81,0xd9,0x45,0x3e,0x10,0x76,0xc6,0xa7,0x8b,0x39,0x43,0xe1, +0x3a,0xb5,0x56,0x2a,0xc0,0x6d,0xb3,0x05,0x22,0x66,0xbf,0xdc,0x0b,0xfa,0x62,0x48, +0xdd,0x20,0x11,0x06,0x36,0xc9,0xc1,0xcf,0xf6,0x27,0x52,0xbb,0x69,0xf5,0xd4,0x87, +0x7f,0x84,0x4c,0xd2,0x9c,0x57,0xa4,0xbc,0x4f,0x9a,0xdf,0xfe,0xd6,0x8d,0x7a,0xeb, +0x2b,0x53,0xd8,0x5c,0xa1,0x14,0x17,0xfb,0x23,0xd5,0x7d,0x30,0x67,0x73,0x08,0x09, +0xee,0xb7,0x70,0x3f,0x61,0xb2,0x19,0x8e,0x4e,0xe5,0x4b,0x93,0x8f,0x5d,0xdb,0xa9, +0xad,0xf1,0xae,0x2e,0xcb,0x0d,0xfc,0xf4,0x2d,0x46,0x6e,0x1d,0x97,0xe8,0xd1,0xe9, +0x4d,0x37,0xa5,0x75,0x5e,0x83,0x9e,0xab,0x82,0x9d,0xb9,0x1c,0xe0,0xcd,0x49,0x89, +0x01,0xb6,0xbd,0x58,0x24,0xa2,0x5f,0x38,0x78,0x99,0x15,0x90,0x50,0xb8,0x95,0xe4, +0xd0,0x91,0xc7,0xce,0xed,0x0f,0xb4,0x6f,0xa0,0xcc,0xf0,0x02,0x4a,0x79,0xc3,0xde, +0xa3,0xef,0xea,0x51,0xe6,0x6b,0x18,0xec,0x1b,0x2c,0x80,0xf7,0x74,0xe7,0xff,0x21, +0x5a,0x6a,0x54,0x1e,0x41,0x31,0x92,0x35,0xc4,0x33,0x07,0x0a,0xba,0x7e,0x0e,0x34, +0x88,0xb1,0x98,0x7c,0xf3,0x3d,0x60,0x6c,0x7b,0xca,0xd3,0x1f,0x32,0x65,0x04,0x28, +0x64,0xbe,0x85,0x9b,0x2f,0x59,0x8a,0xd7,0xb0,0x25,0xac,0xaf,0x12,0x03,0xe2,0xf2 +}; + +/* the constants D */ +static u32 EK_d[16] = { +0x44D7, 0x26BC, 0x626B, 0x135E, 0x5789, 0x35E2, 0x7135, 0x09AF, +0x4D78, 0x2F13, 0x6BC4, 0x1AF1, 0x5E26, 0x3C4D, 0x789A, 0x47AC +}; + +/* ——————————————————————- */ +/* c = a + b mod (2^31 – 1) */ +u32 AddM(u32 a, u32 b) +{ + u32 c = a + b; + return (c & 0x7FFFFFFF) + (c >> 31); +} + +/* LFSR with initialization mode */ +#define MulByPow2(x, k) ((((x) << k) | ((x) >> (31 - k))) & 0x7FFFFFFF) +void LFSRWithInitialisationMode(u32 u) +{ + u32 f, v; + f = LFSR_S0; + + v = MulByPow2(LFSR_S0, 8); + f = AddM(f, v); + v = MulByPow2(LFSR_S4, 20); + f = AddM(f, v); + v = MulByPow2(LFSR_S10, 21); + f = AddM(f, v); + v = MulByPow2(LFSR_S13, 17); + f = AddM(f, v); + v = MulByPow2(LFSR_S15, 15); + f = AddM(f, v); + + f = AddM(f, u); + + /* update the state */ + LFSR_S0 = LFSR_S1; + LFSR_S1 = LFSR_S2; + LFSR_S2 = LFSR_S3; + LFSR_S3 = LFSR_S4; + LFSR_S4 = LFSR_S5; + LFSR_S5 = LFSR_S6; + LFSR_S6 = LFSR_S7; + LFSR_S7 = LFSR_S8; + LFSR_S8 = LFSR_S9; + LFSR_S9 = LFSR_S10; + LFSR_S10 = LFSR_S11; + LFSR_S11 = LFSR_S12; + LFSR_S12 = LFSR_S13; + LFSR_S13 = LFSR_S14; + LFSR_S14 = LFSR_S15; + LFSR_S15 = f; +} + +/* LFSR with work mode */ +void LFSRWithWorkMode(void) +{ + u32 f, v; + f = LFSR_S0; + + v = MulByPow2(LFSR_S0, 8); + f = AddM(f, v); + v = MulByPow2(LFSR_S4, 20); + f = AddM(f, v); + v = MulByPow2(LFSR_S10, 21); + f = AddM(f, v); + v = MulByPow2(LFSR_S13, 17); + f = AddM(f, v); + v = MulByPow2(LFSR_S15, 15); + f = AddM(f, v); + + /* update the state */ + LFSR_S0 = LFSR_S1; + LFSR_S1 = LFSR_S2; + LFSR_S2 = LFSR_S3; + LFSR_S3 = LFSR_S4; + LFSR_S4 = LFSR_S5; + LFSR_S5 = LFSR_S6; + LFSR_S6 = LFSR_S7; + LFSR_S7 = LFSR_S8; + LFSR_S8 = LFSR_S9; + LFSR_S9 = LFSR_S10; + LFSR_S10 = LFSR_S11; + LFSR_S11 = LFSR_S12; + LFSR_S12 = LFSR_S13; + LFSR_S13 = LFSR_S14; + LFSR_S14 = LFSR_S15; + LFSR_S15 = f; +} + +/* BitReorganization */ +void BitReorganization(void) +{ + BRC_X0 = ((LFSR_S15 & 0x7FFF8000) << 1) | (LFSR_S14 & 0xFFFF); + BRC_X1 = ((LFSR_S11 & 0xFFFF) << 16) | (LFSR_S9 >> 15); + BRC_X2 = ((LFSR_S7 & 0xFFFF) << 16) | (LFSR_S5 >> 15); + BRC_X3 = ((LFSR_S2 & 0xFFFF) << 16) | (LFSR_S0 >> 15); +} + +#define ROT(a, k) (((a) << k) | ((a) >> (32 - k))) + +/* L1 */ +u32 L1(u32 X) +{ + return (X ^ ROT(X, 2) ^ ROT(X, 10) ^ ROT(X, 18) ^ ROT(X, 24)); +} + +/* L2 */ +u32 L2(u32 X) +{ + return (X ^ ROT(X, 8) ^ ROT(X, 14) ^ ROT(X, 22) ^ ROT(X, 30)); +} + +#define MAKEU32(a, b, c, d) (((u32)(a) << 24) | ((u32)(b) << 16) | ((u32)(c) << 8) | ((u32)(d))) +/* F */ +u32 F(void) +{ + u32 W, W1, W2, u, v; + + W = (BRC_X0 ^ F_R1) + F_R2; + W1 = F_R1 + BRC_X1; + W2 = F_R2 ^ BRC_X2; + + u = L1((W1 << 16) | (W2 >> 16)); + v = L2((W2 << 16) | (W1 >> 16)); + + F_R1 = MAKEU32(S0[u >> 24], S1[(u >> 16) & 0xFF], + S0[(u >> 8) & 0xFF], S1[u & 0xFF]); + F_R2 = MAKEU32(S0[v >> 24], S1[(v >> 16) & 0xFF], + S0[(v >> 8) & 0xFF], S1[v & 0xFF]); + + return W; +} + +#define MAKEU31(a, b, c) (((u32)(a) << 23) | ((u32)(b) << 8) | (u32)(c)) +/* initialize */ +void zuc_initialize(u8* k, u8* iv) +{ + u32 w, nCount; + + /* expand key */ + LFSR_S0 = MAKEU31(k[0], EK_d[0], iv[0]); + LFSR_S1 = MAKEU31(k[1], EK_d[1], iv[1]); + LFSR_S2 = MAKEU31(k[2], EK_d[2], iv[2]); + LFSR_S3 = MAKEU31(k[3], EK_d[3], iv[3]); + LFSR_S4 = MAKEU31(k[4], EK_d[4], iv[4]); + LFSR_S5 = MAKEU31(k[5], EK_d[5], iv[5]); + LFSR_S6 = MAKEU31(k[6], EK_d[6], iv[6]); + LFSR_S7 = MAKEU31(k[7], EK_d[7], iv[7]); + LFSR_S8 = MAKEU31(k[8], EK_d[8], iv[8]); + LFSR_S9 = MAKEU31(k[9], EK_d[9], iv[9]); + LFSR_S10 = MAKEU31(k[10], EK_d[10], iv[10]); + LFSR_S11 = MAKEU31(k[11], EK_d[11], iv[11]); + LFSR_S12 = MAKEU31(k[12], EK_d[12], iv[12]); + LFSR_S13 = MAKEU31(k[13], EK_d[13], iv[13]); + LFSR_S14 = MAKEU31(k[14], EK_d[14], iv[14]); + LFSR_S15 = MAKEU31(k[15], EK_d[15], iv[15]); + + /* set F_R1 and F_R2 to zero */ + F_R1 = 0; + F_R2 = 0; + nCount = 32; + while (nCount > 0) + { + BitReorganization(); + w = F(); + LFSRWithInitialisationMode(w >> 1); + nCount --; + } +} + +void zuc_generate_key_stream(u32* pKeystream, u32 KeystreamLen) +{ + int i; + BitReorganization(); + F(); /* discard the output of F */ + LFSRWithWorkMode(); + + for (i = 0; i < KeystreamLen; i ++) + { + BitReorganization(); + pKeystream[i] = F() ^ BRC_X3; + LFSRWithWorkMode(); + } +} + +/* The ZUC algorithm, see ref. [3]*/ +void ZUC(u8* k, u8* iv, u32* ks, u32 len) +{ + /* The initialization of ZUC, see page 17 of ref. [3]*/ + zuc_initialize(k, iv); + /* The procedure of generating keystream of ZUC, see page 18 of ref. [3]*/ + zuc_generate_key_stream(ks, len); +} +/* end of ZUC.c */ + +/*----------------------------------------------------- + * EEA3 + *---------------------------------------------------*/ + +/* + * EEA3: LTE Encryption Algorithm 3 + * EEA3.c +*/ +void zuc_eea3(u8* CK, u32 COUNT, u32 BEARER, u32 DIRECTION, + u32 LENGTH, u8* M, u8* C) +{ + u32 *z, L, L8, i; + u8 IV[16]; + u32 lastbits = (8-(LENGTH%8))%8; + + L = (LENGTH+31)/32; + z = (u32 *) ogs_malloc(L*sizeof(u32)); + + L8 = (LENGTH+7)/8; + + IV[0] = (COUNT>>24) & 0xFF; + IV[1] = (COUNT>>16) & 0xFF; + IV[2] = (COUNT>>8) & 0xFF; + IV[3] = COUNT & 0xFF; + + IV[4] = ((BEARER << 3) | ((DIRECTION&1)<<2)) & 0xFC; + IV[5] = 0; + IV[6] = 0; + IV[7] = 0; + + IV[8] = IV[0]; + IV[9] = IV[1]; + IV[10] = IV[2]; + IV[11] = IV[3]; + + IV[12] = IV[4]; + IV[13] = IV[5]; + IV[14] = IV[6]; + IV[15] = IV[7]; + + ZUC(CK, IV, z, L); + + for (i=0; i> (3-i%4)*8) & 0xff); + } + + /* zero last bits of data in case its length is not word-aligned (32 bits) + this is an addition to the C reference code, which did not handle it */ + if (lastbits) + i--; + C[i] &= 0x100 - (1<>(32-ti)); + return WORD; +} + +u8 GET_BIT(u8 * DATA, u32 i) +{ + return (DATA[i/8] & (1<<(7-(i%8)))) ? 1 : 0; +} + +void zuc_eia3(u8* IK, u32 COUNT, u32 BEARER, u32 DIRECTION, + u32 LENGTH, u8* M, u32* MAC) +{ + u32 *z, N, L, T, i; + u8 IV[16]; + + IV[0] = (COUNT>>24) & 0xFF; + IV[1] = (COUNT>>16) & 0xFF; + IV[2] = (COUNT>>8) & 0xFF; + IV[3] = COUNT & 0xFF; + + IV[4] = (BEARER << 3) & 0xF8; + IV[5] = IV[6] = IV[7] = 0; + + IV[8] = ((COUNT>>24) & 0xFF) ^ ((DIRECTION&1)<<7); + IV[9] = (COUNT>>16) & 0xFF; + IV[10] = (COUNT>>8) & 0xFF; + IV[11] = COUNT & 0xFF; + + IV[12] = IV[4]; + IV[13] = IV[5]; + IV[14] = IV[6] ^ ((DIRECTION&1)<<7); + IV[15] = IV[7]; + + N = LENGTH + 64; + L = (N + 31) / 32; + z = (u32 *) ogs_malloc(L*sizeof(u32)); + ZUC(IK, IV, z, L); + + T = 0; + for (i=0; i + +# This file is part of Open5GS. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +libdbi_sources = files(''' + ogs-dbi.h + + ogs-mongoc.h + + ogs-mongoc.c +'''.split()) + +libmongoc_dep = dependency('libmongoc-1.0') + +libdbi_inc = include_directories('.') + +libdbi = library('ogsdbi', + sources : libdbi_sources, + version : libogslib_version, + c_args : '-DOGS_DBI_COMPILATION', + include_directories : [libdbi_inc, libinc], + dependencies : [libcore_dep, libmongoc_dep], + install : true) + +libdbi_dep = declare_dependency( + link_with : libdbi, + include_directories : [libdbi_inc, libinc], + dependencies : [libcore_dep, libmongoc_dep]) diff --git a/lib/ogs-dbi.h b/lib/dbi/ogs-dbi.h similarity index 97% rename from lib/ogs-dbi.h rename to lib/dbi/ogs-dbi.h index 580618dbf..f389d00f4 100644 --- a/lib/ogs-dbi.h +++ b/lib/dbi/ogs-dbi.h @@ -20,7 +20,7 @@ #ifndef OGS_DB_H #define OGS_DB_H -#include "ogs-common.h" +#include "ogs-core.h" #define OGS_DBI_INSIDE diff --git a/lib/diameter/Makefile.am b/lib/diameter/Makefile.am deleted file mode 100644 index b172f93ac..000000000 --- a/lib/diameter/Makefile.am +++ /dev/null @@ -1,50 +0,0 @@ -# Copyright (C) 2019 by Sukchan Lee - -# This file is part of Open5GS. - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -pkglib_LTLIBRARIES = libogsdiameter.la - -libogsdiameter_la_SOURCES = \ - message.h logger.h base.h \ - libapp_sip.c message.c logger.c \ - config.c init.c \ - \ - s6a/dict.h s6a/message.h s6a/dict.c \ - gx/dict.h gx/message.h gx/dict.c gx/message.c \ - rx/dict.h rx/message.h rx/dict.c rx/message.c \ - $(NULL) - -libogsdiameter_la_DEPENDENCIES = \ - $(top_srcdir)/lib/freeDiameter/libfdcore/libfdcore.la \ - $(top_srcdir)/lib/freeDiameter/libfdproto/libfdproto.la \ - $(NULL) - -libogsdiameter_la_LIBADD = \ - @OGSCORE_LIBS@ \ - $(top_srcdir)/lib/freeDiameter/libfdcore/libfdcore.la \ - $(top_srcdir)/lib/freeDiameter/libfdproto/libfdproto.la \ - $(NULL) - -AM_CPPFLAGS = \ - @OGSCORE_CFLAGS@ \ - -I$(top_srcdir)/lib \ - -I$(top_srcdir)/lib/freeDiameter/include \ - $(NULL) - -AM_CFLAGS = \ - -DOGS_DIAMETER_COMPILATION \ - -Wall -Werror \ - $(NULL) diff --git a/lib/diameter/base.h b/lib/diameter/common/base.h similarity index 100% rename from lib/diameter/base.h rename to lib/diameter/common/base.h diff --git a/lib/diameter/config.c b/lib/diameter/common/config.c similarity index 96% rename from lib/diameter/config.c rename to lib/diameter/common/config.c index 401ca2ccb..086a58dee 100644 --- a/lib/diameter/config.c +++ b/lib/diameter/common/config.c @@ -17,7 +17,12 @@ * along with this program. If not, see . */ -#include "ogs-diameter.h" +#include "ogs-diameter-common.h" + +int fd_ext_add(char *filename, char *conffile); +int fd_rtdisp_init(void); +int fd_ext_load(void); +int fd_msg_init(void); static int diam_config_apply(ogs_diam_config_t *fd_config) { @@ -163,7 +168,6 @@ static int diam_config_apply(ogs_diam_config_t *fd_config) fclose(fd); } - extern int fd_ext_add( char * filename, char * conffile ); CHECK_FCT_DO( fd_ext_add( fname, cfname ), return OGS_ERROR ); } @@ -178,21 +182,18 @@ int ogs_diam_config_init(ogs_diam_config_t *fd_config) CHECK_FCT( diam_config_apply(fd_config) ); /* The following module use data from the configuration */ - int fd_rtdisp_init(void); CHECK_FCT( fd_rtdisp_init() ); /* Now, load all dynamic extensions */ - int fd_ext_load(); CHECK_FCT( fd_ext_load() ); /* Display configuration */ b = fd_conf_dump(&buf, &len, NULL); LOG_SPLIT(FD_LOG_NOTICE, NULL, - b ?: "", NULL); + b ?: (char*)"", NULL); free(buf); /* Since some extensions might have modified the definitions from the dict_base_protocol, we only load the objects now */ - int fd_msg_init(void); CHECK_FCT( fd_msg_init() ); return OGS_OK; diff --git a/lib/diameter/init.c b/lib/diameter/common/init.c similarity index 93% rename from lib/diameter/init.c rename to lib/diameter/common/init.c index bf4a2900d..900da3a7d 100644 --- a/lib/diameter/init.c +++ b/lib/diameter/common/init.c @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -#include "ogs-diameter.h" +#include "ogs-diameter-common.h" int __ogs_diam_domain; @@ -93,7 +93,10 @@ static void diam_log_func(int printlevel, char buffer[OGS_HUGE_LEN]; int ret = 0; +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wformat-nonliteral" ret = vsnprintf(buffer, OGS_HUGE_LEN, format, ap); +#pragma GCC diagnostic pop if (ret < 0 || ret > OGS_HUGE_LEN) { ogs_error("vsnprintf() failed"); return; @@ -114,12 +117,12 @@ static void diam_log_func(int printlevel, if (!strcmp(buffer, " - The certificate is expired.")) { ogs_error("You can renew CERT as follows:"); ogs_error("./support/freeDiameter/make_certs.sh " - "./install/etc/nextepc/freeDiameter"); + "./install/etc/open5gs/freeDiameter"); } break; case FD_LOG_FATAL: { - char *except = "Initiating freeDiameter shutdown sequence"; + const char *except = "Initiating freeDiameter shutdown sequence"; if (strncmp(buffer, except, strlen(except)) == 0) ogs_info("[%d]: %s:%u %s", printlevel, fname, line, buffer); else diff --git a/lib/diameter/libapp_sip.c b/lib/diameter/common/libapp_sip.c similarity index 99% rename from lib/diameter/libapp_sip.c rename to lib/diameter/common/libapp_sip.c index 968aaaf71..98afdc871 100644 --- a/lib/diameter/libapp_sip.c +++ b/lib/diameter/common/libapp_sip.c @@ -34,7 +34,7 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * *********************************************************************************************************/ -#include "ogs-diameter.h" +#include "ogs-diameter-common.h" /* Search a given AVP model in an AVP (extracted from libfreediameter/message.c ) */ int fd_avp_search_avp ( struct avp * groupedavp, struct dict_object * what, struct avp ** avp ) diff --git a/lib/diameter/logger.c b/lib/diameter/common/logger.c similarity index 97% rename from lib/diameter/logger.c rename to lib/diameter/common/logger.c index f14ad2ed1..45a8e598b 100644 --- a/lib/diameter/logger.c +++ b/lib/diameter/common/logger.c @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -#include "ogs-diameter.h" +#include "ogs-diameter-common.h" static struct ogs_diam_logger_t self; @@ -85,7 +85,7 @@ static void ogs_diam_logger_cb(enum fd_hook_type type, struct msg * msg, struct peer_hdr * peer, void * other, struct fd_hook_permsgdata *pmd, void * regdata) { - char * peer_name = peer ? peer->info.pi_diamid : ""; + const char * peer_name = peer ? peer->info.pi_diamid : ""; CHECK_POSIX_DO( pthread_mutex_lock(&mtx), ); diff --git a/lib/diameter/logger.h b/lib/diameter/common/logger.h similarity index 92% rename from lib/diameter/logger.h rename to lib/diameter/common/logger.h index 8e3e66ebc..e6d3d28e5 100644 --- a/lib/diameter/logger.h +++ b/lib/diameter/common/logger.h @@ -49,18 +49,18 @@ struct ogs_diam_logger_t { }; int ogs_diam_logger_init(int mode); -void ogs_diam_logger_final(); +void ogs_diam_logger_final(void); -struct ogs_diam_logger_t* ogs_diam_logger_self(); +struct ogs_diam_logger_t* ogs_diam_logger_self(void); -int ogs_diam_logger_stats_start(); +int ogs_diam_logger_stats_start(void); typedef void (*ogs_diam_logger_user_handler)( enum fd_hook_type type, struct msg *msg, struct peer_hdr *peer, void *other, struct fd_hook_permsgdata *pmd, void *regdata); void ogs_diam_logger_register(ogs_diam_logger_user_handler instance); -void ogs_diam_logger_unregister(); +void ogs_diam_logger_unregister(void); #ifdef __cplusplus } diff --git a/lib/diameter/common/meson.build b/lib/diameter/common/meson.build new file mode 100644 index 000000000..5f5dd4586 --- /dev/null +++ b/lib/diameter/common/meson.build @@ -0,0 +1,48 @@ +# Copyright (C) 2019 by Sukchan Lee + +# This file is part of Open5GS. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +libdiameter_common_sources = files(''' + ogs-diameter-common.h + + message.h + logger.h + base.h + + libapp_sip.c + message.c + logger.c + config.c + init.c +'''.split()) + +libdiameter_common_inc = include_directories('.') + +freediameter_proj = subproject('freediameter') +libfdcore_dep = freediameter_proj.get_variable('libfdcore_dep') + +libdiameter_common = library('ogsdiameter-common', + sources : libdiameter_common_sources, + version : libogslib_version, + c_args : '-DOGS_DIAM_COMPILATION', + include_directories : [libdiameter_common_inc, libinc], + dependencies : [libcore_dep, libfdcore_dep], + install : true) + +libdiameter_common_dep = declare_dependency( + link_with : libdiameter_common, + include_directories : [libdiameter_common_inc, libinc], + dependencies : [libcore_dep, libfdcore_dep]) diff --git a/lib/diameter/message.c b/lib/diameter/common/message.c similarity index 99% rename from lib/diameter/message.c rename to lib/diameter/common/message.c index a87f0eb0c..eaa22971a 100644 --- a/lib/diameter/message.c +++ b/lib/diameter/common/message.c @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -#include "ogs-diameter.h" +#include "ogs-diameter-common.h" #define CHECK_dict_search( _type, _criteria, _what, _result ) \ CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, (_type), (_criteria), (_what), (_result), ENOENT) ); diff --git a/lib/diameter/message.h b/lib/diameter/common/message.h similarity index 100% rename from lib/diameter/message.h rename to lib/diameter/common/message.h diff --git a/lib/ogs-diameter.h b/lib/diameter/common/ogs-diameter-common.h similarity index 74% rename from lib/ogs-diameter.h rename to lib/diameter/common/ogs-diameter-common.h index 5d6604f2a..913cc3623 100644 --- a/lib/ogs-diameter.h +++ b/lib/diameter/common/ogs-diameter-common.h @@ -17,21 +17,31 @@ * along with this program. If not, see . */ -#ifndef OGS_DIAMETER_H -#define OGS_DIAMETER_H +#ifndef OGS_DIAMETER_COMMON_H +#define OGS_DIAMETER_COMMON_H #include "freeDiameter/freeDiameter-host.h" + +#if defined(__GNUC__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wstrict-prototypes" +#endif + #include "freeDiameter/libfdcore.h" -#include "ogs-common.h" +#if defined(__GNUC__) +#pragma GCC diagnostic pop +#endif + +#include "ogs-core.h" #define OGS_MAX_NUM_OF_PCC_RULE 8 /* Num of PCC Rule */ #define OGS_DIAMETER_INSIDE -#include "diameter/message.h" -#include "diameter/logger.h" -#include "diameter/base.h" +#include "diameter/common/message.h" +#include "diameter/common/logger.h" +#include "diameter/common/base.h" #undef OGS_DIAMETER_INSIDE @@ -48,4 +58,4 @@ extern int __ogs_diam_domain; } #endif -#endif /* OGS_DIAMETER_H */ +#endif /* OGS_DIAMETER_COMMON_H */ diff --git a/lib/diameter/gx/dict.c b/lib/diameter/gx/dict.c index ec532fd0f..00a250c08 100644 --- a/lib/diameter/gx/dict.c +++ b/lib/diameter/gx/dict.c @@ -18,7 +18,7 @@ * along with this program. If not, see . */ -#include "diameter/ogs-gx.h" +#include "ogs-diameter-gx.h" #define CHECK_dict_search( _type, _criteria, _what, _result ) \ CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, (_type), (_criteria), (_what), (_result), ENOENT) ); diff --git a/lib/diameter/gx/meson.build b/lib/diameter/gx/meson.build new file mode 100644 index 000000000..f473c47a6 --- /dev/null +++ b/lib/diameter/gx/meson.build @@ -0,0 +1,41 @@ +# Copyright (C) 2019 by Sukchan Lee + +# This file is part of Open5GS. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +libdiameter_gx_sources = files(''' + ogs-diameter-gx.h + + dict.h + message.h + + dict.c + message.c +'''.split()) + +libdiameter_gx_inc = include_directories('.') + +libdiameter_gx = library('ogsdiameter-gx', + sources : libdiameter_gx_sources, + version : libogslib_version, + c_args : '-DOGS_DIAM_COMPILATION', + include_directories : libdiameter_gx_inc, + dependencies : libdiameter_common_dep, + install : true) + +libdiameter_gx_dep = declare_dependency( + link_with : libdiameter_gx, + include_directories : libdiameter_gx_inc, + dependencies : libdiameter_common_dep) diff --git a/lib/diameter/gx/message.c b/lib/diameter/gx/message.c index c4bd7f9c1..c19b1ef05 100644 --- a/lib/diameter/gx/message.c +++ b/lib/diameter/gx/message.c @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -#include "diameter/ogs-gx.h" +#include "ogs-diameter-gx.h" void ogs_diam_gx_message_free(ogs_diam_gx_message_t *gx_message) { diff --git a/lib/diameter/ogs-gx.h b/lib/diameter/gx/ogs-diameter-gx.h similarity index 91% rename from lib/diameter/ogs-gx.h rename to lib/diameter/gx/ogs-diameter-gx.h index 72509bb19..5569f2b0a 100644 --- a/lib/diameter/ogs-gx.h +++ b/lib/diameter/gx/ogs-diameter-gx.h @@ -20,12 +20,12 @@ #ifndef OGS_DIAMETER_GX_H #define OGS_DIAMETER_GX_H -#include "ogs-diameter.h" +#include "ogs-diameter-common.h" #define OGS_DIAMETER_INSIDE -#include "gx/dict.h" -#include "gx/message.h" +#include "diameter/gx/dict.h" +#include "diameter/gx/message.h" #undef OGS_DIAMETER_INSIDE diff --git a/lib/diameter/meson.build b/lib/diameter/meson.build new file mode 100644 index 000000000..befcc7099 --- /dev/null +++ b/lib/diameter/meson.build @@ -0,0 +1,21 @@ +# Copyright (C) 2019 by Sukchan Lee + +# This file is part of Open5GS. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +subdir('common') +subdir('gx') +subdir('rx') +subdir('s6a') diff --git a/lib/diameter/rx/dict.c b/lib/diameter/rx/dict.c index 6d9541932..943167892 100644 --- a/lib/diameter/rx/dict.c +++ b/lib/diameter/rx/dict.c @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -#include "diameter/ogs-rx.h" +#include "ogs-diameter-rx.h" #define CHECK_dict_search( _type, _criteria, _what, _result ) \ CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, (_type), (_criteria), (_what), (_result), ENOENT) ); diff --git a/lib/diameter/rx/meson.build b/lib/diameter/rx/meson.build new file mode 100644 index 000000000..f6ea2db61 --- /dev/null +++ b/lib/diameter/rx/meson.build @@ -0,0 +1,41 @@ +# Copyright (C) 2019 by Sukchan Lee + +# This file is part of Open5GS. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +libdiameter_rx_sources = files(''' + ogs-diameter-rx.h + + dict.h + message.h + + dict.c + message.c +'''.split()) + +libdiameter_rx_inc = include_directories('.') + +libdiameter_rx = library('ogsdiameter-rx', + sources : libdiameter_rx_sources, + version : libogslib_version, + c_args : '-DOGS_DIAM_COMPILATION', + include_directories : libdiameter_rx_inc, + dependencies : libdiameter_common_dep, + install : true) + +libdiameter_rx_dep = declare_dependency( + link_with : libdiameter_rx, + include_directories : libdiameter_rx_inc, + dependencies : libdiameter_common_dep) diff --git a/lib/diameter/rx/message.c b/lib/diameter/rx/message.c index d0e15ec21..ce1e04544 100644 --- a/lib/diameter/rx/message.c +++ b/lib/diameter/rx/message.c @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -#include "diameter/ogs-rx.h" +#include "ogs-diameter-rx.h" void ogs_diam_rx_message_free(ogs_diam_rx_message_t *rx_message) { diff --git a/lib/diameter/ogs-rx.h b/lib/diameter/rx/ogs-diameter-rx.h similarity index 91% rename from lib/diameter/ogs-rx.h rename to lib/diameter/rx/ogs-diameter-rx.h index 83e969ee6..58d24fd1f 100644 --- a/lib/diameter/ogs-rx.h +++ b/lib/diameter/rx/ogs-diameter-rx.h @@ -20,12 +20,12 @@ #ifndef OGS_DIAMETER_RX_H #define OGS_DIAMETER_RX_H -#include "ogs-diameter.h" +#include "ogs-diameter-common.h" #define OGS_DIAMETER_INSIDE -#include "rx/dict.h" -#include "rx/message.h" +#include "diameter/rx/dict.h" +#include "diameter/rx/message.h" #undef OGS_DIAMETER_INSIDE diff --git a/lib/diameter/s6a/dict.c b/lib/diameter/s6a/dict.c index ede58f244..2968d9418 100644 --- a/lib/diameter/s6a/dict.c +++ b/lib/diameter/s6a/dict.c @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -#include "diameter/ogs-s6a.h" +#include "ogs-diameter-s6a.h" #define CHECK_dict_search( _type, _criteria, _what, _result ) \ CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, (_type), (_criteria), (_what), (_result), ENOENT) ); diff --git a/lib/diameter/s6a/meson.build b/lib/diameter/s6a/meson.build new file mode 100644 index 000000000..0d3bfc607 --- /dev/null +++ b/lib/diameter/s6a/meson.build @@ -0,0 +1,40 @@ +# Copyright (C) 2019 by Sukchan Lee + +# This file is part of Open5GS. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +libdiameter_s6a_sources = files(''' + ogs-diameter-s6a.h + + dict.h + message.h + + dict.c +'''.split()) + +libdiameter_s6a_inc = include_directories('.') + +libdiameter_s6a = library('ogsdiameter-s6a', + sources : libdiameter_s6a_sources, + version : libogslib_version, + c_args : '-DOGS_DIAM_COMPILATION', + include_directories : [libdiameter_s6a_inc, libcrypt_inc], + dependencies : libdiameter_common_dep, + install : true) + +libdiameter_s6a_dep = declare_dependency( + link_with : libdiameter_s6a, + include_directories : [libdiameter_s6a_inc, libcrypt_inc], + dependencies : libdiameter_common_dep) diff --git a/lib/diameter/ogs-s6a.h b/lib/diameter/s6a/ogs-diameter-s6a.h similarity index 90% rename from lib/diameter/ogs-s6a.h rename to lib/diameter/s6a/ogs-diameter-s6a.h index 8e727a9fd..927f93939 100644 --- a/lib/diameter/ogs-s6a.h +++ b/lib/diameter/s6a/ogs-diameter-s6a.h @@ -20,12 +20,12 @@ #ifndef OGS_DIMAETER_S6A_H #define OGS_DIMAETER_S6A_H -#include "ogs-diameter.h" +#include "ogs-diameter-common.h" #define OGS_DIAMETER_INSIDE -#include "s6a/dict.h" -#include "s6a/message.h" +#include "diameter/s6a/dict.h" +#include "diameter/s6a/message.h" #undef OGS_DIAMETER_INSIDE diff --git a/lib/freeDiameter/Makefile.am b/lib/freeDiameter/Makefile.am deleted file mode 100644 index d3ba1d6fc..000000000 --- a/lib/freeDiameter/Makefile.am +++ /dev/null @@ -1,10 +0,0 @@ -## Process this file with automake to produce Makefile.in - -ACLOCAL_AMFLAGS = -I m4 -EXTRA_DIST= \ - include/freeDiameter/libfdcore.h \ - include/freeDiameter/libfdproto.h \ - include/freeDiameter/extension.h \ - $(NULL) - -SUBDIRS = libfdproto libfdcore extensions diff --git a/lib/freeDiameter/configure.ac b/lib/freeDiameter/configure.ac deleted file mode 100644 index 10fc037ec..000000000 --- a/lib/freeDiameter/configure.ac +++ /dev/null @@ -1,232 +0,0 @@ -dnl Process this file with autoconf to produce a configure script. -dnl -dnl This file is free software; as a special exception the author gives -dnl unlimited permission to copy and/or distribute it, with or without -dnl modifications, as long as this notice is preserved. -dnl -dnl This program is distributed in the hope that it will be useful, but -dnl WITHOUT ANY WARRANTY, to the extent permitted by law; without even the -dnl implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - -AC_INIT([nextepc], [1.2.1], [acetcom@gmail.com]) - -dnl Must come before AM_INIT_AUTOMAKE. -AC_CONFIG_AUX_DIR([build-aux]) -AM_INIT_AUTOMAKE([1.10 -Wall -Werror foreign]) - -# Where to generate output; srcdir location. -AC_CONFIG_HEADERS([include/freeDiameter/freeDiameter-config.h]) -AC_CANONICAL_HOST -case $host in - *-freebsd*) - AC_DEFINE_UNQUOTED([SCTP_USE_MAPPED_ADDRESSES], - [1], [Disable SCTP]) - ;; - *) - ;; -esac - -AH_TOP([ -#ifndef FD_IS_CONFIG -#define FD_IS_CONFIG - -#define _GNU_SOURCE 1 - -#ifdef __cplusplus -extern "C" { -#endif - -]) - -AH_BOTTOM([ -#define FD_PROJECT_COPYRIGHT "Copyright (c) 2008-2015, WIDE Project (www.wide.ad.jp) and NICT (www.nict.go.jp)" - -#ifndef FD_DEFAULT_CONF_FILENAME -#define FD_DEFAULT_CONF_FILENAME "freeDiameter.conf" -#endif /* FD_DEFAULT_CONF_FILENAME */ - -/* Maximum number of hooks handlers that can be registered. Make this compilation option if needed */ -#define FD_HOOK_HANDLE_LIMIT 5 - -#ifdef __cplusplus -} -#endif - -#endif /* FD_IS_CONFIG */ -]) - -dnl kernel style compile messages -m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) - -dnl Checks CC and freinds -AC_PROG_MAKE_SET -AC_PROG_CC -AC_PROG_INSTALL -AC_PROG_YACC -AC_PROG_LEX -AM_PROG_AR -LT_INIT([dlopen pic-only disable-static]) - -dnl Checks for compile flag -dnl AX_CHECK_COMPILE_FLAG([-Wno-format-truncation],[CFLAGS="$CFLAGS -Wno-format-truncation"]) - -if test "x$LEX" != "xflex"; then - AC_MSG_ERROR([flex program is needed to build freeDiameter, please install flex.]) -fi - -if test "x$YACC" = "xyacc"; then -# AC_PROG_YACC only checks for yacc replacements, not for yacc itself - AC_CHECK_PROG([YACC_FOUND], [yacc], [yes], [no]) - if test "x$YACC_FOUND" = "xno"; then - AC_MSG_ERROR([A yacc program is needed to build freeDiameter, please install bison.]) - fi -fi - -dnl Check Endian -AC_C_BIGENDIAN - -############################# -#### From FreeDiameter CMAKE -############################# -touch include/freeDiameter/version.h -rm -f libfdcore/fdd.tab.y -ln -s fdd.y libfdcore/fdd.tab.y -rm -f libfdcore/lex.fdd.l -ln -s fdd.l libfdcore/lex.fdd.l - -AC_DEFINE_UNQUOTED([FD_PROJECT_BINARY], - ["freeDiameterd"], [Project Binary]) -AC_DEFINE_UNQUOTED([FD_PROJECT_NAME], - ["freeDiameter"], [Project Name]) -AC_DEFINE_UNQUOTED([FD_PROJECT_VERSION_MAJOR], - [`echo $PACKAGE_VERSION | $SED 's/^\([[^\.]]\+\)\.\([[^\.]]\+\)\.\([[^\.]]\+\).*/\1/'`], - [Major version of this package]) -AC_DEFINE_UNQUOTED([FD_PROJECT_VERSION_MINOR], - [`echo $PACKAGE_VERSION | $SED 's/^\([[^\.]]\+\)\.\([[^\.]]\+\)\.\([[^\.]]\+\).*/\2/'`], - [Minor version of this package]) -AC_DEFINE_UNQUOTED([FD_PROJECT_VERSION_REV], - [`echo $PACKAGE_VERSION | $SED 's/^\([[^\.]]\+\)\.\([[^\.]]\+\)\.\([[^\.]]\+\).*/\3/'`], - [Patch version of this package]) -AC_DEFINE_UNQUOTED([FD_PROJECT_VERSION_API], - [6], - [API version of this package]) - -# adl_RECURSIVE_EVAL(VALUE, RESULT) -# ================================= -# Interpolate the VALUE in loop until it doesn't change, -# and set the result to $RESULT. -# WARNING: It's easy to get an infinite loop with some unsane input. -# For example ${datadir} becomes ${datarootdir}, and then ${prefix}/share, and -# finally ${prefix} is replaced by the prefix. -AC_DEFUN([adl_RECURSIVE_EVAL], -[_lcl_receval="$1" -$2=`(test "x$prefix" = xNONE && prefix="$ac_default_prefix" - test "x$exec_prefix" = xNONE && exec_prefix="${prefix}" - _lcl_receval_old='' - while test "[$]_lcl_receval_old" != "[$]_lcl_receval"; do - _lcl_receval_old="[$]_lcl_receval" - eval _lcl_receval="\"[$]_lcl_receval\"" - done - echo "[$]_lcl_receval")`]) -adl_RECURSIVE_EVAL(["${libdir}"], [LIB_DIR]) -adl_RECURSIVE_EVAL(["${sysconfdir}"], [SYSCONF_DIR]) - -AC_SUBST(extlibdir) -extlibdir=${libdir}/nextepc/freeDiameter -AC_DEFINE_UNQUOTED([DEFAULT_CONF_PATH], - ["${SYSCONF_DIR}/nextepc/freeDiameter"], [Default Configuration Path]) -AC_DEFINE_UNQUOTED([DEFAULT_EXTENSIONS_PATH], - ["${LIB_DIR}/nextepc/freeDiameter"], [Default Extensions Path]) -AC_SUBST(PREFIX) - -AC_CHECK_FUNCS([strndup]) - -AC_CHECK_DECL([ntohll],[AC_DEFINE([HAVE_NTOHLL], [1], - [Define to 1 if you have ntohll.])]) -AC_CHECK_DECL([AI_ADDRCONFIG], - [AC_DEFINE([HAVE_AI_ADDRCONFIG], [1], [Define AI_ADDRCONFIG])], [], [[#include ]]) - -AC_SEARCH_LIBS([clock_gettime], [rt], - [AC_DEFINE([HAVE_CLOCK_GETTIME], [1], [Define clock_gettime])]) -AC_SEARCH_LIBS([dlopen], [dl dld]) -AC_SEARCH_LIBS([pthread_barrier_wait], [pthread], - [AC_DEFINE([HAVE_PTHREAD_BAR], [1], - [Define to 1 if you have pthread_barrier_wait in libpthread])], - []) -AC_SEARCH_LIBS([sctp_sendmsg], [sctp], [have_sctp_lib=yes]) -if test x$have_sctp_lib != xyes; then - AC_DEFINE([DISABLE_SCTP], [1], [Disable SCTP]) -fi -AM_CONDITIONAL([SCTP], [test x$have_sctp_lib = xyes]) - -AC_SEARCH_LIBS([gnutls_global_init], [gnutls],, [have_gnutls_lib=no]) -if test x$have_gnutls_lib == xno; then - AC_MSG_ERROR([You must install the GnuTLS libraries and development headers to enable GnuTLS support.]) -fi -AC_SEARCH_LIBS([gnutls_hash], [gnutls], - [AC_DEFINE(GNUTLS_VERSION_210, 1, - [Define to 1 if you have gnutls 2.10 installed])], []) -AC_SEARCH_LIBS([gnutls_transport_set_vec_push_function], [gnutls], - [AC_DEFINE(GNUTLS_VERSION_212, 1, - [Define to 1 if you have gnutls 2.10 installed])], []) -AC_SEARCH_LIBS([gnutls_x509_trust_list_verify_crt], [gnutls], - [AC_DEFINE(GNUTLS_VERSION_300, 1, - [Define to 1 if you have gnutls 3.0 installed])], []) -AC_SEARCH_LIBS([gnutls_handshake_set_timeout], [gnutls], - [AC_DEFINE(GNUTLS_VERSION_310, 1, - [Define to 1 if you have gnutls 3.1 installed])], []) - -AC_SEARCH_LIBS([gcry_control], [gcrypt],, [have_gcrypt_lib=no]) -if test x$have_gcrypt_lib == xno; then - AC_MSG_ERROR([You must install the Libgcrypt libraries and development headers to enable Libgcrypt support.]) -fi -AC_SEARCH_LIBS([idna_strerror], [idn],, [have_idn_lib=no]) -if test x$have_idn_lib == xno; then - AC_MSG_ERROR([You must install the GNU Libidn libraries and development headers to enable GNU Libidn support.]) -fi - -AC_CACHE_CHECK([whether sctp_connectx function accepts 4 arguments], - [ap_cv_sctp_connectx], -[AC_TRY_COMPILE( - [#include -#include ], - [sctp_connectx(0, NULL, 0, NULL);], - [ap_cv_sctp_connectx=yes], [ap_cv_sctp_connectx=no]) -]) - -if test "$ap_cv_sctp_connectx" = "yes"; then - AC_DEFINE([SCTP_CONNECTX_4_ARGS], [1], - [Define 1 if sctp_connectx function accepts 4 arguments]) -fi - -##################### -#### Conclusion. #### -##################### - -AC_CONFIG_FILES([include/freeDiameter/freeDiameter-host.h:include/freeDiameter/freeDiameter-host.hin]) -AC_CONFIG_FILES([libfdproto/Makefile]) -AC_CONFIG_FILES([libfdcore/Makefile]) -AC_CONFIG_FILES([extensions/dbg_msg_dumps/Makefile]) -AC_CONFIG_FILES([extensions/dict_rfc5777/Makefile]) -AC_CONFIG_FILES([extensions/dict_mip6i/Makefile]) -AC_CONFIG_FILES([extensions/dict_nasreq/Makefile]) -AC_CONFIG_FILES([extensions/dict_nas_mipv6/Makefile]) -AC_CONFIG_FILES([extensions/dict_dcca/Makefile]) -AC_CONFIG_FILES([extensions/dict_dcca_3gpp/Makefile]) -AC_CONFIG_FILES([extensions/dict_s6a/Makefile]) -AC_CONFIG_FILES([extensions/Makefile]) -AC_CONFIG_FILES([Makefile]) -AC_OUTPUT - -echo " -FreeDiameter configuration --------------------- -version : ${PACKAGE_VERSION} -host : ${host} -source code location : ${srcdir} -compiler : ${CC} -compiler flags : ${CFLAGS} -linker flags : ${LDFLAGS} ${LIBS} -config directory : ${SYSCONF_DIR}/nextepc/freeDiameter -extensions directory : ${LIB_DIR}/nextepc -" diff --git a/lib/freeDiameter/extensions/Makefile.am b/lib/freeDiameter/extensions/Makefile.am deleted file mode 100644 index 7fe4cc19d..000000000 --- a/lib/freeDiameter/extensions/Makefile.am +++ /dev/null @@ -1,7 +0,0 @@ -## Process this file with automake to produce Makefile.in - -SUBDIRS = \ - dbg_msg_dumps dict_rfc5777 dict_mip6i \ - dict_nasreq dict_nas_mipv6 \ - dict_dcca dict_dcca_3gpp dict_s6a \ - $(NULL) diff --git a/lib/freeDiameter/extensions/dbg_msg_dumps/Makefile.am b/lib/freeDiameter/extensions/dbg_msg_dumps/Makefile.am deleted file mode 100644 index d880b7ecf..000000000 --- a/lib/freeDiameter/extensions/dbg_msg_dumps/Makefile.am +++ /dev/null @@ -1,27 +0,0 @@ -## Process this file with automake to produce Makefile.in - -extlib_LTLIBRARIES = dbg_msg_dumps.la - -dbg_msg_dumps_la_SOURCES = dbg_msg_dumps.c - -dbg_msg_dumps_la_DEPENDENCIES = \ - $(top_srcdir)/libfdcore/libfdcore.la \ - $(top_srcdir)/libfdproto/libfdproto.la \ - $(NULL) - -dbg_msg_dumps_la_LIBADD = \ - $(top_srcdir)/libfdcore/libfdcore.la \ - $(top_srcdir)/libfdproto/libfdproto.la \ - $(NULL) - -AM_LDFLAGS = \ - -module -avoid-version -shared \ - $(NULL) - -AM_CPPFLAGS = \ - -I$(top_srcdir)/include \ - $(NULL) - -AM_CFLAGS = \ - -Wall -Werror \ - $(NULL) diff --git a/lib/freeDiameter/extensions/dict_dcca/Makefile.am b/lib/freeDiameter/extensions/dict_dcca/Makefile.am deleted file mode 100644 index 57da4881a..000000000 --- a/lib/freeDiameter/extensions/dict_dcca/Makefile.am +++ /dev/null @@ -1,27 +0,0 @@ -## Process this file with automake to produce Makefile.in - -extlib_LTLIBRARIES = dict_dcca.la - -dict_dcca_la_SOURCES = dict_dcca.c - -dict_dcca_la_DEPENDENCIES = \ - $(top_srcdir)/libfdcore/libfdcore.la \ - $(top_srcdir)/libfdproto/libfdproto.la \ - $(NULL) - -dict_dcca_la_LIBADD = \ - $(top_srcdir)/libfdcore/libfdcore.la \ - $(top_srcdir)/libfdproto/libfdproto.la \ - $(NULL) - -AM_LDFLAGS = \ - -module -avoid-version -shared \ - $(NULL) - -AM_CPPFLAGS = \ - -I$(top_srcdir)/include \ - $(NULL) - -AM_CFLAGS = \ - -Wall -Werror \ - $(NULL) diff --git a/lib/freeDiameter/extensions/dict_dcca_3gpp/Makefile.am b/lib/freeDiameter/extensions/dict_dcca_3gpp/Makefile.am deleted file mode 100644 index facc16798..000000000 --- a/lib/freeDiameter/extensions/dict_dcca_3gpp/Makefile.am +++ /dev/null @@ -1,28 +0,0 @@ -## Process this file with automake to produce Makefile.in - -extlib_LTLIBRARIES = dict_dcca_3gpp.la - -dict_dcca_3gpp_la_SOURCES = \ - dict_dcca_3gpp.c - -dict_dcca_3gpp_la_DEPENDENCIES = \ - $(top_srcdir)/libfdcore/libfdcore.la \ - $(top_srcdir)/libfdproto/libfdproto.la \ - $(NULL) - -dict_dcca_3gpp_la_LIBADD = \ - $(top_srcdir)/libfdcore/libfdcore.la \ - $(top_srcdir)/libfdproto/libfdproto.la \ - $(NULL) - -AM_LDFLAGS = \ - -module -avoid-version -shared \ - $(NULL) - -AM_CPPFLAGS = \ - -I$(top_srcdir)/include \ - $(NULL) - -AM_CFLAGS = \ - -Wall -Werror \ - $(NULL) diff --git a/lib/freeDiameter/extensions/dict_mip6i/Makefile.am b/lib/freeDiameter/extensions/dict_mip6i/Makefile.am deleted file mode 100644 index 5a8a6f4f0..000000000 --- a/lib/freeDiameter/extensions/dict_mip6i/Makefile.am +++ /dev/null @@ -1,27 +0,0 @@ -## Process this file with automake to produce Makefile.in - -extlib_LTLIBRARIES = dict_mip6i.la - -dict_mip6i_la_SOURCES = dict_mip6i.c - -dict_mip6i_la_DEPENDENCIES = \ - $(top_srcdir)/libfdcore/libfdcore.la \ - $(top_srcdir)/libfdproto/libfdproto.la \ - $(NULL) - -dict_mip6i_la_LIBADD = \ - $(top_srcdir)/libfdcore/libfdcore.la \ - $(top_srcdir)/libfdproto/libfdproto.la \ - $(NULL) - -AM_LDFLAGS = \ - -module -avoid-version -shared \ - $(NULL) - -AM_CPPFLAGS = \ - -I$(top_srcdir)/include \ - $(NULL) - -AM_CFLAGS = \ - -Wall -Werror \ - $(NULL) diff --git a/lib/freeDiameter/extensions/dict_nas_mipv6/Makefile.am b/lib/freeDiameter/extensions/dict_nas_mipv6/Makefile.am deleted file mode 100644 index f274def02..000000000 --- a/lib/freeDiameter/extensions/dict_nas_mipv6/Makefile.am +++ /dev/null @@ -1,27 +0,0 @@ -## Process this file with automake to produce Makefile.in - -extlib_LTLIBRARIES = dict_nas_mipv6.la - -dict_nas_mipv6_la_SOURCES = dict_nas_mipv6.c - -dict_nas_mipv6_la_DEPENDENCIES = \ - $(top_srcdir)/libfdcore/libfdcore.la \ - $(top_srcdir)/libfdproto/libfdproto.la \ - $(NULL) - -dict_nas_mipv6_la_LIBADD = \ - $(top_srcdir)/libfdcore/libfdcore.la \ - $(top_srcdir)/libfdproto/libfdproto.la \ - $(NULL) - -AM_LDFLAGS = \ - -module -avoid-version -shared \ - $(NULL) - -AM_CPPFLAGS = \ - -I$(top_srcdir)/include \ - $(NULL) - -AM_CFLAGS = \ - -Wall -Werror \ - $(NULL) diff --git a/lib/freeDiameter/extensions/dict_nasreq/Makefile.am b/lib/freeDiameter/extensions/dict_nasreq/Makefile.am deleted file mode 100644 index 18cde9205..000000000 --- a/lib/freeDiameter/extensions/dict_nasreq/Makefile.am +++ /dev/null @@ -1,27 +0,0 @@ -## Process this file with automake to produce Makefile.in - -extlib_LTLIBRARIES = dict_nasreq.la - -dict_nasreq_la_SOURCES = dict_nasreq.c - -dict_nasreq_la_DEPENDENCIES = \ - $(top_srcdir)/libfdcore/libfdcore.la \ - $(top_srcdir)/libfdproto/libfdproto.la \ - $(NULL) - -dict_nasreq_la_LIBADD = \ - $(top_srcdir)/libfdcore/libfdcore.la \ - $(top_srcdir)/libfdproto/libfdproto.la \ - $(NULL) - -AM_LDFLAGS = \ - -module -avoid-version -shared \ - $(NULL) - -AM_CPPFLAGS = \ - -I$(top_srcdir)/include \ - $(NULL) - -AM_CFLAGS = \ - -Wall -Werror \ - $(NULL) diff --git a/lib/freeDiameter/extensions/dict_rfc5777/Makefile.am b/lib/freeDiameter/extensions/dict_rfc5777/Makefile.am deleted file mode 100644 index d3aff5c70..000000000 --- a/lib/freeDiameter/extensions/dict_rfc5777/Makefile.am +++ /dev/null @@ -1,28 +0,0 @@ -## Process this file with automake to produce Makefile.in - -extlib_LTLIBRARIES = dict_rfc5777.la - -dict_rfc5777_la_SOURCES = \ - dict_rfc5777.c - -dict_rfc5777_la_DEPENDENCIES = \ - $(top_srcdir)/libfdcore/libfdcore.la \ - $(top_srcdir)/libfdproto/libfdproto.la \ - $(NULL) - -dict_rfc5777_la_LIBADD = \ - $(top_srcdir)/libfdcore/libfdcore.la \ - $(top_srcdir)/libfdproto/libfdproto.la \ - $(NULL) - -AM_LDFLAGS = \ - -module -avoid-version -shared \ - $(NULL) - -AM_CPPFLAGS = \ - -I$(top_srcdir)/include \ - $(NULL) - -AM_CFLAGS = \ - -Wall -Werror \ - $(NULL) diff --git a/lib/freeDiameter/extensions/dict_s6a/Makefile.am b/lib/freeDiameter/extensions/dict_s6a/Makefile.am deleted file mode 100644 index 2c9e63a50..000000000 --- a/lib/freeDiameter/extensions/dict_s6a/Makefile.am +++ /dev/null @@ -1,28 +0,0 @@ -## Process this file with automake to produce Makefile.in - -extlib_LTLIBRARIES = dict_s6a.la - -dict_s6a_la_SOURCES = \ - dict_s6a.c - -dict_s6a_la_DEPENDENCIES = \ - $(top_srcdir)/libfdcore/libfdcore.la \ - $(top_srcdir)/libfdproto/libfdproto.la \ - $(NULL) - -dict_s6a_la_LIBADD = \ - $(top_srcdir)/libfdcore/libfdcore.la \ - $(top_srcdir)/libfdproto/libfdproto.la \ - $(NULL) - -AM_LDFLAGS = \ - -module -avoid-version -shared \ - $(NULL) - -AM_CPPFLAGS = \ - -I$(top_srcdir)/include \ - $(NULL) - -AM_CFLAGS = \ - -Wall -Werror \ - $(NULL) diff --git a/lib/freeDiameter/libfdcore/Makefile.am b/lib/freeDiameter/libfdcore/Makefile.am deleted file mode 100644 index 755da81fe..000000000 --- a/lib/freeDiameter/libfdcore/Makefile.am +++ /dev/null @@ -1,35 +0,0 @@ -## Process this file with automake to produce Makefile.in - -EXTRA_DIST = fdd.y fdd.l - -pkglib_LTLIBRARIES = libfdcore.la - -libfdcore_la_SOURCES = \ - fdcore-internal.h \ - apps.c cnxctx.h config.c core.c cnxctx.c endpoints.c events.c \ - extensions.c fifo_stats.c hooks.c dict_base_proto.c messages.c \ - queues.c peers.c p_ce.c p_cnx.c p_dw.c p_dp.c p_expiry.c \ - p_out.c p_psm.c p_sr.c routing_dispatch.c server.c tcp.c \ - fdd.tab.y lex.fdd.l version.c \ - $(NULL) - -libfdcore_la_DEPENDENCIES = \ - $(top_srcdir)/libfdproto/libfdproto.la \ - $(NULL) - -libfdcore_la_LIBADD = \ - $(top_srcdir)/libfdproto/libfdproto.la \ - $(NULL) - -if SCTP -libfdcore_la_SOURCES += sctp.c sctp3436.c -endif - -AM_YFLAGS = -p fdd -d -AM_LFLAGS = -p -Cem -Pfdd - -BUILT_SOURCES = fdd.tab.h - -AM_CPPFLAGS = \ - -I$(top_srcdir)/include \ - $(NULL) diff --git a/lib/freeDiameter/libfdproto/Makefile.am b/lib/freeDiameter/libfdproto/Makefile.am deleted file mode 100644 index e50a11421..000000000 --- a/lib/freeDiameter/libfdproto/Makefile.am +++ /dev/null @@ -1,14 +0,0 @@ -## Process this file with automake to produce Makefile.in - -pkglib_LTLIBRARIES = libfdproto.la - -libfdproto_la_SOURCES = \ - fdproto-internal.h \ - dictionary.c dictionary_functions.c dispatch.c fifo.c init.c \ - lists.c log.c messages.c ostr.c portability.c rt_data.c \ - sessions.c utils.c version.c \ - $(NULL) - -AM_CPPFLAGS = \ - -I$(top_srcdir)/include \ - $(NULL) diff --git a/lib/gtp/meson.build b/lib/gtp/meson.build new file mode 100644 index 000000000..e0c807d6e --- /dev/null +++ b/lib/gtp/meson.build @@ -0,0 +1,51 @@ +# Copyright (C) 2019 by Sukchan Lee + +# This file is part of Open5GS. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +libgtp_sources = files(''' + ogs-gtp.h + + tlv.h + message.h + types.h + conv.h + node.h + path.h + xact.h + + tlv.c + message.c + types.c + conv.c + node.c + path.c + xact.c +'''.split()) + +libgtp_inc = include_directories('.') + +libgtp = library('ogsgtp', + sources : libgtp_sources, + version : libogslib_version, + c_args : '-DOGS_GTP_COMPILATION', + include_directories : [libgtp_inc, libinc], + dependencies : libcore_dep, + install : true) + +libgtp_dep = declare_dependency( + link_with : libgtp, + include_directories : [libgtp_inc, libinc], + dependencies : libcore_dep) diff --git a/lib/gtp/message.c b/lib/gtp/message.c index 672c835aa..8aa324e1e 100644 --- a/lib/gtp/message.c +++ b/lib/gtp/message.c @@ -20,7 +20,7 @@ /******************************************************************************* * This file had been created by gtp-tlv.py script v0.1.0 * Please do not modify this file but regenerate it via script. - * Created on: 2019-09-10 21:31:45.122396 by acetcom + * Created on: 2019-09-26 22:10:18.839117 by acetcom * from 29274-d80.docx ******************************************************************************/ @@ -2771,7 +2771,7 @@ int ogs_gtp_parse_msg(ogs_gtp_message_t *gtp_message, ogs_pkbuf_t *pkbuf) ogs_assert(pkbuf); ogs_assert(pkbuf->len); - h = pkbuf->data; + h = (ogs_gtp_header_t *)pkbuf->data; ogs_assert(h); memset(gtp_message, 0, sizeof(ogs_gtp_message_t)); diff --git a/lib/gtp/message.h b/lib/gtp/message.h index ad3445d2c..0d8881cdf 100644 --- a/lib/gtp/message.h +++ b/lib/gtp/message.h @@ -20,7 +20,7 @@ /******************************************************************************* * This file had been created by gtp-tlv.py script v0.1.0 * Please do not modify this file but regenerate it via script. - * Created on: 2019-09-10 21:31:45.116236 by acetcom + * Created on: 2019-09-26 22:10:18.823195 by acetcom * from 29274-d80.docx ******************************************************************************/ @@ -31,7 +31,7 @@ #ifndef OGS_GTP_MESSAGE_H #define OGS_GTP_MESSAGE_H -#include "tlv.h" +#include "gtp/tlv.h" #ifdef __cplusplus extern "C" { diff --git a/lib/ogs-gtp.h b/lib/gtp/ogs-gtp.h similarity index 98% rename from lib/ogs-gtp.h rename to lib/gtp/ogs-gtp.h index c7c5b94a6..8ac029d7b 100644 --- a/lib/ogs-gtp.h +++ b/lib/gtp/ogs-gtp.h @@ -20,7 +20,7 @@ #ifndef OGS_GTP_H #define OGS_GTP_H -#include "ogs-common.h" +#include "ogs-core.h" #define OGS_GTPV1_U_UDP_PORT 2152 #define OGS_GTPV2_C_UDP_PORT 2123 diff --git a/lib/gtp/support/README.md b/lib/gtp/support/README.md index d161a3c71..33713bff7 100644 --- a/lib/gtp/support/README.md +++ b/lib/gtp/support/README.md @@ -1,10 +1,10 @@ * Install python-pip -user@host ~/Documents/git/nextepc/lib/gtp/support$ \ +user@host ~/Documents/git/open5gs/lib/gtp/support$ \ sudo apt-get install python-pip * Install python-docx -user@host ~/Documents/git/nextepc/lib/gtp/support$ \ +user@host ~/Documents/git/open5gs/lib/gtp/support$ \ sudo pip install python-docx * Change the format of standard specification @@ -12,5 +12,5 @@ user@host ~/Documents/git/nextepc/lib/gtp/support$ \ using Microsoft Office 2007+ * Generate TLV support files -user@host ~/Documents/git/nextepc/lib/s1ap/support$ \ +user@host ~/Documents/git/open5gs/lib/s1ap/support$ \ python gtp-tlv.py -f 29274-d80.docx -o .. diff --git a/lib/gtp/support/gtp-tlv.py b/lib/gtp/support/gtp-tlv.py index e3688587e..219884812 100644 --- a/lib/gtp/support/gtp-tlv.py +++ b/lib/gtp/support/gtp-tlv.py @@ -379,7 +379,7 @@ f.write("""#if !defined(OGS_GTP_INSIDE) && !defined(OGS_GTP_COMPILATION) #ifndef OGS_GTP_MESSAGE_H #define OGS_GTP_MESSAGE_H -#include "ogs-gtp-tlv.h" +#include "gtp/tlv.h" #ifdef __cplusplus extern "C" { @@ -609,7 +609,7 @@ f.write("""int ogs_gtp_parse_msg(ogs_gtp_message_t *gtp_message, ogs_pkbuf_t *pk ogs_assert(pkbuf); ogs_assert(pkbuf->len); - h = pkbuf->data; + h = (ogs_gtp_header_t *)pkbuf->data; ogs_assert(h); memset(gtp_message, 0, sizeof(ogs_gtp_message_t)); diff --git a/lib/gtp/tlv.h b/lib/gtp/tlv.h index 1ae8a7e05..f017d499b 100644 --- a/lib/gtp/tlv.h +++ b/lib/gtp/tlv.h @@ -54,7 +54,7 @@ typedef enum { typedef struct ogs_tlv_desc_s { ogs_tlv_type_e ctype; - char *name; + const char *name; uint16_t type; uint16_t length; uint8_t instance; diff --git a/lib/gtp/types.c b/lib/gtp/types.c index e8dd5b3e8..92dcbc820 100644 --- a/lib/gtp/types.c +++ b/lib/gtp/types.c @@ -45,13 +45,17 @@ int16_t ogs_gtp_parse_bearer_qos( bearer_qos->qci = source->qci; size++; - bearer_qos->ul_mbr = ogs_buffer_to_uint64(octet->data + size, 5); + bearer_qos->ul_mbr = ogs_buffer_to_uint64( + (unsigned char *)octet->data + size, 5); size += 5; - bearer_qos->dl_mbr = ogs_buffer_to_uint64(octet->data + size, 5); + bearer_qos->dl_mbr = ogs_buffer_to_uint64( + (unsigned char *)octet->data + size, 5); size += 5; - bearer_qos->ul_gbr = ogs_buffer_to_uint64(octet->data + size, 5); + bearer_qos->ul_gbr = ogs_buffer_to_uint64( + (unsigned char *)octet->data + size, 5); size += 5; - bearer_qos->dl_gbr = ogs_buffer_to_uint64(octet->data + size, 5); + bearer_qos->dl_gbr = ogs_buffer_to_uint64( + (unsigned char *)octet->data + size, 5); size += 5; ogs_assert(size == octet->len); @@ -72,16 +76,16 @@ int16_t ogs_gtp_build_bearer_qos(ogs_tlv_octet_t *octet, octet->data = data; memcpy(&target, bearer_qos, sizeof(ogs_gtp_bearer_qos_t)); - memcpy(octet->data + size, &target, 2); + memcpy((unsigned char *)octet->data + size, &target, 2); size += 2; - ogs_uint64_to_buffer(target.ul_mbr, 5, octet->data + size); + ogs_uint64_to_buffer(target.ul_mbr, 5, (unsigned char *)octet->data + size); size += 5; - ogs_uint64_to_buffer(target.dl_mbr, 5, octet->data + size); + ogs_uint64_to_buffer(target.dl_mbr, 5, (unsigned char *)octet->data + size); size += 5; - ogs_uint64_to_buffer(target.ul_gbr, 5, octet->data + size); + ogs_uint64_to_buffer(target.ul_gbr, 5, (unsigned char *)octet->data + size); size += 5; - ogs_uint64_to_buffer(target.dl_gbr, 5, octet->data + size); + ogs_uint64_to_buffer(target.dl_gbr, 5, (unsigned char *)octet->data + size); size += 5; octet->len = size; @@ -107,32 +111,31 @@ int16_t ogs_gtp_build_tft( memcpy(&target, tft, sizeof(ogs_gtp_tft_t)); ogs_assert(size + sizeof(target.flags) <= data_len); - memcpy(octet->data + size, &target.flags, sizeof(target.flags)); + memcpy((unsigned char *)octet->data + size, &target.flags, sizeof(target.flags)); size += sizeof(target.flags); - for (i = 0; i < target.num_of_packet_filter; i++) - { + for (i = 0; i < target.num_of_packet_filter; i++) { ogs_assert(size + sizeof(target.pf[i].flags) <= data_len); - memcpy(octet->data + size, &target.pf[i].flags, + memcpy((unsigned char *)octet->data + size, &target.pf[i].flags, sizeof(target.pf[i].flags)); size += sizeof(target.pf[i].flags); ogs_assert(size + sizeof(target.pf[i].precedence) <= data_len); - memcpy(octet->data + size, &target.pf[i].precedence, + memcpy((unsigned char *)octet->data + size, &target.pf[i].precedence, sizeof(target.pf[i].precedence)); size += sizeof(target.pf[i].precedence); ogs_assert(size + sizeof(target.pf[i].length) <= data_len); - memcpy(octet->data + size, &target.pf[i].length, + memcpy((unsigned char *)octet->data + size, &target.pf[i].length, sizeof(target.pf[i].length)); size += sizeof(target.pf[i].length); - for (j = 0; j < target.pf[i].num_of_component; j++) - { + for (j = 0; j < target.pf[i].num_of_component; j++) { ogs_assert(size + sizeof(target.pf[i].component[j].type) <= data_len); - memcpy(octet->data + size, &target.pf[i].component[j].type, - sizeof(target.pf[i].component[j].type)); + memcpy((unsigned char *)octet->data + size, + &target.pf[i].component[j].type, + sizeof(target.pf[i].component[j].type)); size += sizeof(target.pf[i].component[j].type); switch(target.pf[i].component[j].type) { @@ -140,8 +143,9 @@ int16_t ogs_gtp_build_tft( { ogs_assert(size + sizeof(target.pf[i].component[j].proto) <= data_len); - memcpy(octet->data + size, &target.pf[i].component[j].proto, - sizeof(target.pf[i].component[j].proto)); + memcpy((unsigned char *)octet->data + size, + &target.pf[i].component[j].proto, + sizeof(target.pf[i].component[j].proto)); size += sizeof(target.pf[i].component[j].proto); break; } @@ -150,7 +154,7 @@ int16_t ogs_gtp_build_tft( ogs_assert(size + sizeof(target.pf[i].component[j].ipv4.addr) <= data_len); - memcpy(octet->data + size, + memcpy((unsigned char *)octet->data + size, &target.pf[i].component[j].ipv4.addr, sizeof(target.pf[i].component[j].ipv4.addr)); size += sizeof(target.pf[i].component[j].ipv4.addr); @@ -158,9 +162,9 @@ int16_t ogs_gtp_build_tft( ogs_assert(size + sizeof(target.pf[i].component[j].ipv4.mask) <= data_len); - memcpy(octet->data + size, - &target.pf[i].component[j].ipv4.mask, - sizeof(target.pf[i].component[j].ipv4.mask)); + memcpy((unsigned char *)octet->data + size, + &target.pf[i].component[j].ipv4.mask, + sizeof(target.pf[i].component[j].ipv4.mask)); size += sizeof(target.pf[i].component[j].ipv4.mask); break; case GTP_PACKET_FILTER_IPV6_LOCAL_ADDRESS_PREFIX_LENGTH_TYPE: @@ -168,15 +172,15 @@ int16_t ogs_gtp_build_tft( ogs_assert(size + sizeof(target.pf[i].component[j].ipv6.addr) <= data_len); - memcpy(octet->data + size, - &target.pf[i].component[j].ipv6.addr, - sizeof(target.pf[i].component[j].ipv6.addr)); + memcpy((unsigned char *)octet->data + size, + &target.pf[i].component[j].ipv6.addr, + sizeof(target.pf[i].component[j].ipv6.addr)); size += sizeof(target.pf[i].component[j].ipv6.addr); ogs_assert(size + sizeof(target.pf[i].component[j].ipv6.prefixlen) <= data_len); - memcpy(octet->data + size, + memcpy((unsigned char *)octet->data + size, &target.pf[i].component[j].ipv6.prefixlen, sizeof(target.pf[i].component[j].ipv6.prefixlen)); size += sizeof(target.pf[i].component[j].ipv6.prefixlen); @@ -185,17 +189,17 @@ int16_t ogs_gtp_build_tft( ogs_assert(size + sizeof(target.pf[i].component[j].ipv6_mask.addr) <= data_len); - memcpy(octet->data + size, - &target.pf[i].component[j].ipv6_mask.addr, - sizeof(target.pf[i].component[j].ipv6_mask.addr)); + memcpy((unsigned char *)octet->data + size, + &target.pf[i].component[j].ipv6_mask.addr, + sizeof(target.pf[i].component[j].ipv6_mask.addr)); size += sizeof(target.pf[i].component[j].ipv6_mask.addr); ogs_assert(size + sizeof(target.pf[i].component[j].ipv6_mask.mask) <= data_len); - memcpy(octet->data + size, - &target.pf[i].component[j].ipv6_mask.mask, - sizeof(target.pf[i].component[j].ipv6_mask.mask)); + memcpy((unsigned char *)octet->data + size, + &target.pf[i].component[j].ipv6_mask.mask, + sizeof(target.pf[i].component[j].ipv6_mask.mask)); size += sizeof(target.pf[i].component[j].ipv6_mask.mask); break; case GTP_PACKET_FILTER_SINGLE_LOCAL_PORT_TYPE: @@ -205,7 +209,7 @@ int16_t ogs_gtp_build_tft( <= data_len); target.pf[i].component[j].port.low = htons(target.pf[i].component[j].port.low); - memcpy(octet->data + size, + memcpy((unsigned char *)octet->data + size, &target.pf[i].component[j].port.low, sizeof(target.pf[i].component[j].port.low)); size += sizeof(target.pf[i].component[j].port.low); @@ -218,9 +222,9 @@ int16_t ogs_gtp_build_tft( <= data_len); target.pf[i].component[j].port.low = htons(target.pf[i].component[j].port.low); - memcpy(octet->data + size, - &target.pf[i].component[j].port.low, - sizeof(target.pf[i].component[j].port.low)); + memcpy((unsigned char *)octet->data + size, + &target.pf[i].component[j].port.low, + sizeof(target.pf[i].component[j].port.low)); size += sizeof(target.pf[i].component[j].port.low); ogs_assert(size + @@ -228,7 +232,7 @@ int16_t ogs_gtp_build_tft( <= data_len); target.pf[i].component[j].port.high = htons(target.pf[i].component[j].port.high); - memcpy(octet->data + size, + memcpy((unsigned char *)octet->data + size, &target.pf[i].component[j].port.high, sizeof(target.pf[i].component[j].port.high)); size += sizeof(target.pf[i].component[j].port.high); @@ -264,40 +268,46 @@ int16_t ogs_gtp_parse_uli(ogs_gtp_uli_t *uli, ogs_tlv_octet_t *octet) if (uli->flags.cgi) { ogs_assert(size + sizeof(uli->cgi) <= octet->len); - memcpy(&uli->cgi, octet->data + size, sizeof(uli->cgi)); + memcpy(&uli->cgi, + (unsigned char *)octet->data + size, sizeof(uli->cgi)); uli->cgi.lac = ntohs(uli->cgi.lac); uli->cgi.ci = ntohs(uli->cgi.ci); size += sizeof(uli->cgi); } if (uli->flags.sai) { ogs_assert(size + sizeof(uli->sai) <= octet->len); - memcpy(&uli->sai, octet->data + size, sizeof(uli->sai)); + memcpy(&uli->sai, + (unsigned char *)octet->data + size, sizeof(uli->sai)); uli->sai.lac = ntohs(uli->sai.lac); uli->sai.sac = ntohs(uli->sai.sac); size += sizeof(uli->sai); } if (uli->flags.rai) { ogs_assert(size + sizeof(uli->rai) <= octet->len); - memcpy(&uli->rai, octet->data + size, sizeof(uli->rai)); + memcpy(&uli->rai, + (unsigned char *)octet->data + size, sizeof(uli->rai)); uli->rai.lac = ntohs(uli->rai.lac); uli->rai.rac = ntohs(uli->rai.rac); size += sizeof(uli->rai); } if (uli->flags.tai) { ogs_assert(size + sizeof(uli->tai) <= octet->len); - memcpy(&uli->tai, octet->data + size, sizeof(uli->tai)); + memcpy(&uli->tai, + (unsigned char *)octet->data + size, sizeof(uli->tai)); uli->tai.tac = ntohs(uli->tai.tac); size += sizeof(uli->tai); } if (uli->flags.e_cgi) { ogs_assert(size + sizeof(uli->e_cgi) <= octet->len); - memcpy(&uli->e_cgi, octet->data + size, sizeof(uli->e_cgi)); + memcpy(&uli->e_cgi, + (unsigned char *)octet->data + size, sizeof(uli->e_cgi)); uli->e_cgi.cell_id = ntohl(uli->e_cgi.cell_id); size += sizeof(uli->e_cgi); } if (uli->flags.lai) { ogs_assert(size + sizeof(uli->lai) <= octet->len); - memcpy(&uli->lai, octet->data + size, sizeof(uli->lai)); + memcpy(&uli->lai, + (unsigned char *)octet->data + size, sizeof(uli->lai)); uli->lai.lac = ntohs(uli->lai.lac); size += sizeof(uli->lai); } @@ -321,46 +331,53 @@ int16_t ogs_gtp_build_uli( memcpy(&target, uli, sizeof(ogs_gtp_uli_t)); ogs_assert(size + sizeof(target.flags) <= data_len); - memcpy(octet->data + size, &target.flags, sizeof(target.flags)); + memcpy((unsigned char *)octet->data + size, + &target.flags, sizeof(target.flags)); size += sizeof(target.flags); if (target.flags.cgi) { ogs_assert(size + sizeof(target.cgi) <= data_len); target.cgi.lac = htons(target.cgi.lac); target.cgi.ci = htons(target.cgi.ci); - memcpy(octet->data + size, &target.cgi, sizeof(target.cgi)); + memcpy((unsigned char *)octet->data + size, + &target.cgi, sizeof(target.cgi)); size += sizeof(target.cgi); } if (target.flags.sai) { ogs_assert(size + sizeof(target.sai) <= data_len); target.sai.lac = htons(target.sai.lac); target.sai.sac = htons(target.sai.sac); - memcpy(octet->data + size, &target.sai, sizeof(target.sai)); + memcpy((unsigned char *)octet->data + size, + &target.sai, sizeof(target.sai)); size += sizeof(target.sai); } if (target.flags.rai) { ogs_assert(size + sizeof(target.rai) <= data_len); target.rai.lac = htons(target.rai.lac); target.rai.rac = htons(target.rai.rac); - memcpy(octet->data + size, &target.rai, sizeof(target.rai)); + memcpy((unsigned char *)octet->data + size, + &target.rai, sizeof(target.rai)); size += sizeof(target.rai); } if (target.flags.tai) { ogs_assert(size + sizeof(target.tai) <= data_len); target.tai.tac = htons(target.tai.tac); - memcpy(octet->data + size, &target.tai, sizeof(target.tai)); + memcpy((unsigned char *)octet->data + size, + &target.tai, sizeof(target.tai)); size += sizeof(target.tai); } if (target.flags.e_cgi) { ogs_assert(size + sizeof(target.e_cgi) <= data_len); target.e_cgi.cell_id = htonl(target.e_cgi.cell_id); - memcpy(octet->data + size, &target.e_cgi, sizeof(target.e_cgi)); + memcpy((unsigned char *)octet->data + size, + &target.e_cgi, sizeof(target.e_cgi)); size += sizeof(target.e_cgi); } if (target.flags.lai) { ogs_assert(size + sizeof(target.lai) <= data_len); target.lai.lac = htons(target.lai.lac); - memcpy(octet->data + size, &target.lai, sizeof(target.lai)); + memcpy((unsigned char *)octet->data + size, + &target.lai, sizeof(target.lai)); size += sizeof(target.lai); } diff --git a/lib/gtp/xact.c b/lib/gtp/xact.c index 5501bfbce..863655772 100644 --- a/lib/gtp/xact.c +++ b/lib/gtp/xact.c @@ -187,6 +187,7 @@ int ogs_gtp_xact_update_tx(ogs_gtp_xact_t *xact, case GTP_XACT_INTERMEDIATE_STAGE: ogs_assert_if_reached(); + break; case GTP_XACT_FINAL_STAGE: ogs_assert(xact->step == 2); @@ -194,11 +195,13 @@ int ogs_gtp_xact_update_tx(ogs_gtp_xact_t *xact, default: ogs_assert_if_reached(); + break; } } else if (xact->org == OGS_GTP_REMOTE_ORIGINATOR) { switch (stage) { case GTP_XACT_INITIAL_STAGE: ogs_assert_if_reached(); + break; case GTP_XACT_INTERMEDIATE_STAGE: case GTP_XACT_FINAL_STAGE: @@ -207,13 +210,13 @@ int ogs_gtp_xact_update_tx(ogs_gtp_xact_t *xact, default: ogs_assert_if_reached(); + break; } } else ogs_assert_if_reached(); - ogs_pkbuf_push(pkbuf, OGS_GTPV2C_HEADER_LEN); - h = pkbuf->data; + h = (ogs_gtp_header_t *)pkbuf->data; ogs_assert(h); memset(h, 0, sizeof(ogs_gtp_header_t)); @@ -252,6 +255,7 @@ int ogs_gtp_xact_update_rx(ogs_gtp_xact_t *xact, uint8_t type) switch (stage) { case GTP_XACT_INITIAL_STAGE: ogs_assert_if_reached(); + break; case GTP_XACT_INTERMEDIATE_STAGE: if (xact->seq[1].type == type) { @@ -305,6 +309,7 @@ int ogs_gtp_xact_update_rx(ogs_gtp_xact_t *xact, uint8_t type) default: ogs_assert_if_reached(); + break; } } else if (xact->org == OGS_GTP_REMOTE_ORIGINATOR) { switch (stage) { @@ -355,6 +360,7 @@ int ogs_gtp_xact_update_rx(ogs_gtp_xact_t *xact, uint8_t type) case GTP_XACT_INTERMEDIATE_STAGE: ogs_assert_if_reached(); + break; case GTP_XACT_FINAL_STAGE: ogs_assert(xact->step == 2); @@ -364,6 +370,7 @@ int ogs_gtp_xact_update_rx(ogs_gtp_xact_t *xact, uint8_t type) default: ogs_assert_if_reached(); + break; } } else ogs_assert_if_reached(); @@ -415,6 +422,7 @@ int ogs_gtp_xact_commit(ogs_gtp_xact_t *xact) case GTP_XACT_INTERMEDIATE_STAGE: ogs_assert_if_reached(); + break; case GTP_XACT_FINAL_STAGE: ogs_assert(xact->step == 2 || xact->step == 3); @@ -427,11 +435,13 @@ int ogs_gtp_xact_commit(ogs_gtp_xact_t *xact) default: ogs_assert_if_reached(); + break; } } else if (xact->org == OGS_GTP_REMOTE_ORIGINATOR) { switch (stage) { case GTP_XACT_INITIAL_STAGE: ogs_assert_if_reached(); + break; case GTP_XACT_INTERMEDIATE_STAGE: ogs_assert(xact->step == 2); @@ -452,6 +462,7 @@ int ogs_gtp_xact_commit(ogs_gtp_xact_t *xact) default: ogs_assert_if_reached(); + break; } } else ogs_assert_if_reached(); @@ -653,6 +664,7 @@ ogs_gtp_xact_t *ogs_gtp_xact_find_by_xid( break; default: ogs_assert_if_reached(); + break; } ogs_assert(list); diff --git a/lib/meson.build b/lib/meson.build new file mode 100644 index 000000000..a973c49a7 --- /dev/null +++ b/lib/meson.build @@ -0,0 +1,29 @@ +# Copyright (C) 2019 by Sukchan Lee + +# This file is part of Open5GS. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +libinc = include_directories('.') + +subdir('core') +subdir('crypt') +subdir('sctp') +subdir('dbi') +subdir('app') +subdir('diameter') +subdir('asn1c') +subdir('s1ap') +subdir('nas') +subdir('gtp') diff --git a/lib/nas/decoder.c b/lib/nas/decoder.c index c599c0df0..bb23714b2 100644 --- a/lib/nas/decoder.c +++ b/lib/nas/decoder.c @@ -20,12 +20,61 @@ /******************************************************************************* * This file had been created by nas-message.py script v0.1.0 * Please do not modify this file but regenerate it via script. - * Created on: 2019-09-10 21:33:33.940672 by acetcom + * Created on: 2019-09-30 22:46:44.508167 by acetcom * from 24301-d80.docx ******************************************************************************/ #include "ogs-nas.h" +int ogs_nas_decode_attach_request(ogs_nas_message_t *message, ogs_pkbuf_t *pkbuf); +int ogs_nas_decode_attach_accept(ogs_nas_message_t *message, ogs_pkbuf_t *pkbuf); +int ogs_nas_decode_attach_complete(ogs_nas_message_t *message, ogs_pkbuf_t *pkbuf); +int ogs_nas_decode_attach_reject(ogs_nas_message_t *message, ogs_pkbuf_t *pkbuf); +int ogs_nas_decode_detach_request_from_ue(ogs_nas_message_t *message, ogs_pkbuf_t *pkbuf); +int ogs_nas_decode_detach_request_to_ue(ogs_nas_message_t *message, ogs_pkbuf_t *pkbuf); +int ogs_nas_decode_tracking_area_update_request(ogs_nas_message_t *message, ogs_pkbuf_t *pkbuf); +int ogs_nas_decode_tracking_area_update_accept(ogs_nas_message_t *message, ogs_pkbuf_t *pkbuf); +int ogs_nas_decode_tracking_area_update_reject(ogs_nas_message_t *message, ogs_pkbuf_t *pkbuf); +int ogs_nas_decode_extended_service_request(ogs_nas_message_t *message, ogs_pkbuf_t *pkbuf); +int ogs_nas_decode_service_request(ogs_nas_message_t *message, ogs_pkbuf_t *pkbuf); +int ogs_nas_decode_service_reject(ogs_nas_message_t *message, ogs_pkbuf_t *pkbuf); +int ogs_nas_decode_guti_reallocation_command(ogs_nas_message_t *message, ogs_pkbuf_t *pkbuf); +int ogs_nas_decode_authentication_request(ogs_nas_message_t *message, ogs_pkbuf_t *pkbuf); +int ogs_nas_decode_authentication_response(ogs_nas_message_t *message, ogs_pkbuf_t *pkbuf); +int ogs_nas_decode_identity_request(ogs_nas_message_t *message, ogs_pkbuf_t *pkbuf); +int ogs_nas_decode_identity_response(ogs_nas_message_t *message, ogs_pkbuf_t *pkbuf); +int ogs_nas_decode_authentication_failure(ogs_nas_message_t *message, ogs_pkbuf_t *pkbuf); +int ogs_nas_decode_security_mode_command(ogs_nas_message_t *message, ogs_pkbuf_t *pkbuf); +int ogs_nas_decode_security_mode_complete(ogs_nas_message_t *message, ogs_pkbuf_t *pkbuf); +int ogs_nas_decode_security_mode_reject(ogs_nas_message_t *message, ogs_pkbuf_t *pkbuf); +int ogs_nas_decode_emm_status(ogs_nas_message_t *message, ogs_pkbuf_t *pkbuf); +int ogs_nas_decode_emm_information(ogs_nas_message_t *message, ogs_pkbuf_t *pkbuf); +int ogs_nas_decode_downlink_nas_transport(ogs_nas_message_t *message, ogs_pkbuf_t *pkbuf); +int ogs_nas_decode_uplink_nas_transport(ogs_nas_message_t *message, ogs_pkbuf_t *pkbuf); +int ogs_nas_decode_cs_service_notification(ogs_nas_message_t *message, ogs_pkbuf_t *pkbuf); +int ogs_nas_decode_uplink_generic_nas_transport(ogs_nas_message_t *message, ogs_pkbuf_t *pkbuf); +int ogs_nas_decode_downlink_generic_nas_transport(ogs_nas_message_t *message, ogs_pkbuf_t *pkbuf); +int ogs_nas_decode_activate_default_eps_bearer_context_request(ogs_nas_message_t *message, ogs_pkbuf_t *pkbuf); +int ogs_nas_decode_activate_default_eps_bearer_context_accept(ogs_nas_message_t *message, ogs_pkbuf_t *pkbuf); +int ogs_nas_decode_activate_default_eps_bearer_context_reject(ogs_nas_message_t *message, ogs_pkbuf_t *pkbuf); +int ogs_nas_decode_activate_dedicated_eps_bearer_context_request(ogs_nas_message_t *message, ogs_pkbuf_t *pkbuf); +int ogs_nas_decode_activate_dedicated_eps_bearer_context_accept(ogs_nas_message_t *message, ogs_pkbuf_t *pkbuf); +int ogs_nas_decode_activate_dedicated_eps_bearer_context_reject(ogs_nas_message_t *message, ogs_pkbuf_t *pkbuf); +int ogs_nas_decode_modify_eps_bearer_context_request(ogs_nas_message_t *message, ogs_pkbuf_t *pkbuf); +int ogs_nas_decode_modify_eps_bearer_context_accept(ogs_nas_message_t *message, ogs_pkbuf_t *pkbuf); +int ogs_nas_decode_modify_eps_bearer_context_reject(ogs_nas_message_t *message, ogs_pkbuf_t *pkbuf); +int ogs_nas_decode_deactivate_eps_bearer_context_request(ogs_nas_message_t *message, ogs_pkbuf_t *pkbuf); +int ogs_nas_decode_deactivate_eps_bearer_context_accept(ogs_nas_message_t *message, ogs_pkbuf_t *pkbuf); +int ogs_nas_decode_pdn_connectivity_request(ogs_nas_message_t *message, ogs_pkbuf_t *pkbuf); +int ogs_nas_decode_pdn_connectivity_reject(ogs_nas_message_t *message, ogs_pkbuf_t *pkbuf); +int ogs_nas_decode_pdn_disconnect_request(ogs_nas_message_t *message, ogs_pkbuf_t *pkbuf); +int ogs_nas_decode_pdn_disconnect_reject(ogs_nas_message_t *message, ogs_pkbuf_t *pkbuf); +int ogs_nas_decode_bearer_resource_allocation_request(ogs_nas_message_t *message, ogs_pkbuf_t *pkbuf); +int ogs_nas_decode_bearer_resource_allocation_reject(ogs_nas_message_t *message, ogs_pkbuf_t *pkbuf); +int ogs_nas_decode_bearer_resource_modification_request(ogs_nas_message_t *message, ogs_pkbuf_t *pkbuf); +int ogs_nas_decode_bearer_resource_modification_reject(ogs_nas_message_t *message, ogs_pkbuf_t *pkbuf); +int ogs_nas_decode_esm_information_response(ogs_nas_message_t *message, ogs_pkbuf_t *pkbuf); +int ogs_nas_decode_esm_status(ogs_nas_message_t *message, ogs_pkbuf_t *pkbuf); int ogs_nas_decode_attach_request(ogs_nas_message_t *message, ogs_pkbuf_t *pkbuf) { ogs_nas_attach_request_t *attach_request = &message->emm.attach_request; @@ -2658,7 +2707,7 @@ int ogs_nas_decode_esm_status(ogs_nas_message_t *message, ogs_pkbuf_t *pkbuf) int ogs_nas_emm_decode(ogs_nas_message_t *message, ogs_pkbuf_t *pkbuf) { - uint16_t size = 0; + int size = 0; uint16_t decoded = 0; ogs_assert(pkbuf); @@ -2678,7 +2727,7 @@ int ogs_nas_emm_decode(ogs_nas_message_t *message, ogs_pkbuf_t *pkbuf) ogs_assert(ogs_pkbuf_push(pkbuf, 1)); decoded -= 1; size = ogs_nas_decode_service_request(message, pkbuf); - ogs_assert(size >= OGS_OK); + ogs_assert(size >= 0); decoded += size; goto out; @@ -2688,140 +2737,140 @@ int ogs_nas_emm_decode(ogs_nas_message_t *message, ogs_pkbuf_t *pkbuf) { case OGS_NAS_ATTACH_REQUEST: size = ogs_nas_decode_attach_request(message, pkbuf); - ogs_assert(size >= OGS_OK); + ogs_assert(size >= 0); decoded += size; break; case OGS_NAS_ATTACH_ACCEPT: size = ogs_nas_decode_attach_accept(message, pkbuf); - ogs_assert(size >= OGS_OK); + ogs_assert(size >= 0); decoded += size; break; case OGS_NAS_ATTACH_COMPLETE: size = ogs_nas_decode_attach_complete(message, pkbuf); - ogs_assert(size >= OGS_OK); + ogs_assert(size >= 0); decoded += size; break; case OGS_NAS_ATTACH_REJECT: size = ogs_nas_decode_attach_reject(message, pkbuf); - ogs_assert(size >= OGS_OK); + ogs_assert(size >= 0); decoded += size; break; case OGS_NAS_DETACH_REQUEST: size = ogs_nas_decode_detach_request_from_ue(message, pkbuf); - ogs_assert(size >= OGS_OK); + ogs_assert(size >= 0); decoded += size; break; case OGS_NAS_DETACH_ACCEPT: break; case OGS_NAS_TRACKING_AREA_UPDATE_REQUEST: size = ogs_nas_decode_tracking_area_update_request(message, pkbuf); - ogs_assert(size >= OGS_OK); + ogs_assert(size >= 0); decoded += size; break; case OGS_NAS_TRACKING_AREA_UPDATE_ACCEPT: size = ogs_nas_decode_tracking_area_update_accept(message, pkbuf); - ogs_assert(size >= OGS_OK); + ogs_assert(size >= 0); decoded += size; break; case OGS_NAS_TRACKING_AREA_UPDATE_COMPLETE: break; case OGS_NAS_TRACKING_AREA_UPDATE_REJECT: size = ogs_nas_decode_tracking_area_update_reject(message, pkbuf); - ogs_assert(size >= OGS_OK); + ogs_assert(size >= 0); decoded += size; break; case OGS_NAS_EXTENDED_SERVICE_REQUEST: size = ogs_nas_decode_extended_service_request(message, pkbuf); - ogs_assert(size >= OGS_OK); + ogs_assert(size >= 0); decoded += size; break; case OGS_NAS_SERVICE_REJECT: size = ogs_nas_decode_service_reject(message, pkbuf); - ogs_assert(size >= OGS_OK); + ogs_assert(size >= 0); decoded += size; break; case OGS_NAS_GUTI_REALLOCATION_COMMAND: size = ogs_nas_decode_guti_reallocation_command(message, pkbuf); - ogs_assert(size >= OGS_OK); + ogs_assert(size >= 0); decoded += size; break; case OGS_NAS_GUTI_REALLOCATION_COMPLETE: break; case OGS_NAS_AUTHENTICATION_REQUEST: size = ogs_nas_decode_authentication_request(message, pkbuf); - ogs_assert(size >= OGS_OK); + ogs_assert(size >= 0); decoded += size; break; case OGS_NAS_AUTHENTICATION_RESPONSE: size = ogs_nas_decode_authentication_response(message, pkbuf); - ogs_assert(size >= OGS_OK); + ogs_assert(size >= 0); decoded += size; break; case OGS_NAS_AUTHENTICATION_REJECT: break; case OGS_NAS_IDENTITY_REQUEST: size = ogs_nas_decode_identity_request(message, pkbuf); - ogs_assert(size >= OGS_OK); + ogs_assert(size >= 0); decoded += size; break; case OGS_NAS_IDENTITY_RESPONSE: size = ogs_nas_decode_identity_response(message, pkbuf); - ogs_assert(size >= OGS_OK); + ogs_assert(size >= 0); decoded += size; break; case OGS_NAS_AUTHENTICATION_FAILURE: size = ogs_nas_decode_authentication_failure(message, pkbuf); - ogs_assert(size >= OGS_OK); + ogs_assert(size >= 0); decoded += size; break; case OGS_NAS_SECURITY_MODE_COMMAND: size = ogs_nas_decode_security_mode_command(message, pkbuf); - ogs_assert(size >= OGS_OK); + ogs_assert(size >= 0); decoded += size; break; case OGS_NAS_SECURITY_MODE_COMPLETE: size = ogs_nas_decode_security_mode_complete(message, pkbuf); - ogs_assert(size >= OGS_OK); + ogs_assert(size >= 0); decoded += size; break; case OGS_NAS_SECURITY_MODE_REJECT: size = ogs_nas_decode_security_mode_reject(message, pkbuf); - ogs_assert(size >= OGS_OK); + ogs_assert(size >= 0); decoded += size; break; case OGS_NAS_EMM_STATUS: size = ogs_nas_decode_emm_status(message, pkbuf); - ogs_assert(size >= OGS_OK); + ogs_assert(size >= 0); decoded += size; break; case OGS_NAS_EMM_INFORMATION: size = ogs_nas_decode_emm_information(message, pkbuf); - ogs_assert(size >= OGS_OK); + ogs_assert(size >= 0); decoded += size; break; case OGS_NAS_DOWNLINK_NAS_TRANSPORT: size = ogs_nas_decode_downlink_nas_transport(message, pkbuf); - ogs_assert(size >= OGS_OK); + ogs_assert(size >= 0); decoded += size; break; case OGS_NAS_UPLINK_NAS_TRANSPORT: size = ogs_nas_decode_uplink_nas_transport(message, pkbuf); - ogs_assert(size >= OGS_OK); + ogs_assert(size >= 0); decoded += size; break; case OGS_NAS_CS_SERVICE_NOTIFICATION: size = ogs_nas_decode_cs_service_notification(message, pkbuf); - ogs_assert(size >= OGS_OK); + ogs_assert(size >= 0); decoded += size; break; case OGS_NAS_UPLINK_GENERIC_NAS_TRANSPORT: size = ogs_nas_decode_uplink_generic_nas_transport(message, pkbuf); - ogs_assert(size >= OGS_OK); + ogs_assert(size >= 0); decoded += size; break; case OGS_NAS_DOWNLINK_GENERIC_NAS_TRANSPORT: size = ogs_nas_decode_downlink_generic_nas_transport(message, pkbuf); - ogs_assert(size >= OGS_OK); + ogs_assert(size >= 0); decoded += size; break; default: @@ -2837,7 +2886,7 @@ out: } int ogs_nas_esm_decode(ogs_nas_message_t *message, ogs_pkbuf_t *pkbuf) { - uint16_t size = 0; + int size = 0; uint16_t decoded = 0; ogs_assert(pkbuf); @@ -2855,109 +2904,109 @@ int ogs_nas_esm_decode(ogs_nas_message_t *message, ogs_pkbuf_t *pkbuf) { case OGS_NAS_ACTIVATE_DEFAULT_EPS_BEARER_CONTEXT_REQUEST: size = ogs_nas_decode_activate_default_eps_bearer_context_request(message, pkbuf); - ogs_assert(size >= OGS_OK); + ogs_assert(size >= 0); decoded += size; break; case OGS_NAS_ACTIVATE_DEFAULT_EPS_BEARER_CONTEXT_ACCEPT: size = ogs_nas_decode_activate_default_eps_bearer_context_accept(message, pkbuf); - ogs_assert(size >= OGS_OK); + ogs_assert(size >= 0); decoded += size; break; case OGS_NAS_ACTIVATE_DEFAULT_EPS_BEARER_CONTEXT_REJECT: size = ogs_nas_decode_activate_default_eps_bearer_context_reject(message, pkbuf); - ogs_assert(size >= OGS_OK); + ogs_assert(size >= 0); decoded += size; break; case OGS_NAS_ACTIVATE_DEDICATED_EPS_BEARER_CONTEXT_REQUEST: size = ogs_nas_decode_activate_dedicated_eps_bearer_context_request(message, pkbuf); - ogs_assert(size >= OGS_OK); + ogs_assert(size >= 0); decoded += size; break; case OGS_NAS_ACTIVATE_DEDICATED_EPS_BEARER_CONTEXT_ACCEPT: size = ogs_nas_decode_activate_dedicated_eps_bearer_context_accept(message, pkbuf); - ogs_assert(size >= OGS_OK); + ogs_assert(size >= 0); decoded += size; break; case OGS_NAS_ACTIVATE_DEDICATED_EPS_BEARER_CONTEXT_REJECT: size = ogs_nas_decode_activate_dedicated_eps_bearer_context_reject(message, pkbuf); - ogs_assert(size >= OGS_OK); + ogs_assert(size >= 0); decoded += size; break; case OGS_NAS_MODIFY_EPS_BEARER_CONTEXT_REQUEST: size = ogs_nas_decode_modify_eps_bearer_context_request(message, pkbuf); - ogs_assert(size >= OGS_OK); + ogs_assert(size >= 0); decoded += size; break; case OGS_NAS_MODIFY_EPS_BEARER_CONTEXT_ACCEPT: size = ogs_nas_decode_modify_eps_bearer_context_accept(message, pkbuf); - ogs_assert(size >= OGS_OK); + ogs_assert(size >= 0); decoded += size; break; case OGS_NAS_MODIFY_EPS_BEARER_CONTEXT_REJECT: size = ogs_nas_decode_modify_eps_bearer_context_reject(message, pkbuf); - ogs_assert(size >= OGS_OK); + ogs_assert(size >= 0); decoded += size; break; case OGS_NAS_DEACTIVATE_EPS_BEARER_CONTEXT_REQUEST: size = ogs_nas_decode_deactivate_eps_bearer_context_request(message, pkbuf); - ogs_assert(size >= OGS_OK); + ogs_assert(size >= 0); decoded += size; break; case OGS_NAS_DEACTIVATE_EPS_BEARER_CONTEXT_ACCEPT: size = ogs_nas_decode_deactivate_eps_bearer_context_accept(message, pkbuf); - ogs_assert(size >= OGS_OK); + ogs_assert(size >= 0); decoded += size; break; case OGS_NAS_PDN_CONNECTIVITY_REQUEST: size = ogs_nas_decode_pdn_connectivity_request(message, pkbuf); - ogs_assert(size >= OGS_OK); + ogs_assert(size >= 0); decoded += size; break; case OGS_NAS_PDN_CONNECTIVITY_REJECT: size = ogs_nas_decode_pdn_connectivity_reject(message, pkbuf); - ogs_assert(size >= OGS_OK); + ogs_assert(size >= 0); decoded += size; break; case OGS_NAS_PDN_DISCONNECT_REQUEST: size = ogs_nas_decode_pdn_disconnect_request(message, pkbuf); - ogs_assert(size >= OGS_OK); + ogs_assert(size >= 0); decoded += size; break; case OGS_NAS_PDN_DISCONNECT_REJECT: size = ogs_nas_decode_pdn_disconnect_reject(message, pkbuf); - ogs_assert(size >= OGS_OK); + ogs_assert(size >= 0); decoded += size; break; case OGS_NAS_BEARER_RESOURCE_ALLOCATION_REQUEST: size = ogs_nas_decode_bearer_resource_allocation_request(message, pkbuf); - ogs_assert(size >= OGS_OK); + ogs_assert(size >= 0); decoded += size; break; case OGS_NAS_BEARER_RESOURCE_ALLOCATION_REJECT: size = ogs_nas_decode_bearer_resource_allocation_reject(message, pkbuf); - ogs_assert(size >= OGS_OK); + ogs_assert(size >= 0); decoded += size; break; case OGS_NAS_BEARER_RESOURCE_MODIFICATION_REQUEST: size = ogs_nas_decode_bearer_resource_modification_request(message, pkbuf); - ogs_assert(size >= OGS_OK); + ogs_assert(size >= 0); decoded += size; break; case OGS_NAS_BEARER_RESOURCE_MODIFICATION_REJECT: size = ogs_nas_decode_bearer_resource_modification_reject(message, pkbuf); - ogs_assert(size >= OGS_OK); + ogs_assert(size >= 0); decoded += size; break; case OGS_NAS_ESM_INFORMATION_REQUEST: break; case OGS_NAS_ESM_INFORMATION_RESPONSE: size = ogs_nas_decode_esm_information_response(message, pkbuf); - ogs_assert(size >= OGS_OK); + ogs_assert(size >= 0); decoded += size; break; case OGS_NAS_ESM_STATUS: size = ogs_nas_decode_esm_status(message, pkbuf); - ogs_assert(size >= OGS_OK); + ogs_assert(size >= 0); decoded += size; break; default: diff --git a/lib/nas/encoder.c b/lib/nas/encoder.c index 5e00f86ac..d6fcb27de 100644 --- a/lib/nas/encoder.c +++ b/lib/nas/encoder.c @@ -20,12 +20,61 @@ /******************************************************************************* * This file had been created by nas-message.py script v0.1.0 * Please do not modify this file but regenerate it via script. - * Created on: 2019-09-10 21:33:33.950259 by acetcom + * Created on: 2019-09-30 22:46:44.517916 by acetcom * from 24301-d80.docx ******************************************************************************/ #include "ogs-nas.h" +int ogs_nas_encode_attach_request(ogs_pkbuf_t *pkbuf, ogs_nas_message_t *message); +int ogs_nas_encode_attach_accept(ogs_pkbuf_t *pkbuf, ogs_nas_message_t *message); +int ogs_nas_encode_attach_complete(ogs_pkbuf_t *pkbuf, ogs_nas_message_t *message); +int ogs_nas_encode_attach_reject(ogs_pkbuf_t *pkbuf, ogs_nas_message_t *message); +int ogs_nas_encode_detach_request_from_ue(ogs_pkbuf_t *pkbuf, ogs_nas_message_t *message); +int ogs_nas_encode_detach_request_to_ue(ogs_pkbuf_t *pkbuf, ogs_nas_message_t *message); +int ogs_nas_encode_tracking_area_update_request(ogs_pkbuf_t *pkbuf, ogs_nas_message_t *message); +int ogs_nas_encode_tracking_area_update_accept(ogs_pkbuf_t *pkbuf, ogs_nas_message_t *message); +int ogs_nas_encode_tracking_area_update_reject(ogs_pkbuf_t *pkbuf, ogs_nas_message_t *message); +int ogs_nas_encode_extended_service_request(ogs_pkbuf_t *pkbuf, ogs_nas_message_t *message); +int ogs_nas_encode_service_request(ogs_pkbuf_t *pkbuf, ogs_nas_message_t *message); +int ogs_nas_encode_service_reject(ogs_pkbuf_t *pkbuf, ogs_nas_message_t *message); +int ogs_nas_encode_guti_reallocation_command(ogs_pkbuf_t *pkbuf, ogs_nas_message_t *message); +int ogs_nas_encode_authentication_request(ogs_pkbuf_t *pkbuf, ogs_nas_message_t *message); +int ogs_nas_encode_authentication_response(ogs_pkbuf_t *pkbuf, ogs_nas_message_t *message); +int ogs_nas_encode_identity_request(ogs_pkbuf_t *pkbuf, ogs_nas_message_t *message); +int ogs_nas_encode_identity_response(ogs_pkbuf_t *pkbuf, ogs_nas_message_t *message); +int ogs_nas_encode_authentication_failure(ogs_pkbuf_t *pkbuf, ogs_nas_message_t *message); +int ogs_nas_encode_security_mode_command(ogs_pkbuf_t *pkbuf, ogs_nas_message_t *message); +int ogs_nas_encode_security_mode_complete(ogs_pkbuf_t *pkbuf, ogs_nas_message_t *message); +int ogs_nas_encode_security_mode_reject(ogs_pkbuf_t *pkbuf, ogs_nas_message_t *message); +int ogs_nas_encode_emm_status(ogs_pkbuf_t *pkbuf, ogs_nas_message_t *message); +int ogs_nas_encode_emm_information(ogs_pkbuf_t *pkbuf, ogs_nas_message_t *message); +int ogs_nas_encode_downlink_nas_transport(ogs_pkbuf_t *pkbuf, ogs_nas_message_t *message); +int ogs_nas_encode_uplink_nas_transport(ogs_pkbuf_t *pkbuf, ogs_nas_message_t *message); +int ogs_nas_encode_cs_service_notification(ogs_pkbuf_t *pkbuf, ogs_nas_message_t *message); +int ogs_nas_encode_uplink_generic_nas_transport(ogs_pkbuf_t *pkbuf, ogs_nas_message_t *message); +int ogs_nas_encode_downlink_generic_nas_transport(ogs_pkbuf_t *pkbuf, ogs_nas_message_t *message); +int ogs_nas_encode_activate_default_eps_bearer_context_request(ogs_pkbuf_t *pkbuf, ogs_nas_message_t *message); +int ogs_nas_encode_activate_default_eps_bearer_context_accept(ogs_pkbuf_t *pkbuf, ogs_nas_message_t *message); +int ogs_nas_encode_activate_default_eps_bearer_context_reject(ogs_pkbuf_t *pkbuf, ogs_nas_message_t *message); +int ogs_nas_encode_activate_dedicated_eps_bearer_context_request(ogs_pkbuf_t *pkbuf, ogs_nas_message_t *message); +int ogs_nas_encode_activate_dedicated_eps_bearer_context_accept(ogs_pkbuf_t *pkbuf, ogs_nas_message_t *message); +int ogs_nas_encode_activate_dedicated_eps_bearer_context_reject(ogs_pkbuf_t *pkbuf, ogs_nas_message_t *message); +int ogs_nas_encode_modify_eps_bearer_context_request(ogs_pkbuf_t *pkbuf, ogs_nas_message_t *message); +int ogs_nas_encode_modify_eps_bearer_context_accept(ogs_pkbuf_t *pkbuf, ogs_nas_message_t *message); +int ogs_nas_encode_modify_eps_bearer_context_reject(ogs_pkbuf_t *pkbuf, ogs_nas_message_t *message); +int ogs_nas_encode_deactivate_eps_bearer_context_request(ogs_pkbuf_t *pkbuf, ogs_nas_message_t *message); +int ogs_nas_encode_deactivate_eps_bearer_context_accept(ogs_pkbuf_t *pkbuf, ogs_nas_message_t *message); +int ogs_nas_encode_pdn_connectivity_request(ogs_pkbuf_t *pkbuf, ogs_nas_message_t *message); +int ogs_nas_encode_pdn_connectivity_reject(ogs_pkbuf_t *pkbuf, ogs_nas_message_t *message); +int ogs_nas_encode_pdn_disconnect_request(ogs_pkbuf_t *pkbuf, ogs_nas_message_t *message); +int ogs_nas_encode_pdn_disconnect_reject(ogs_pkbuf_t *pkbuf, ogs_nas_message_t *message); +int ogs_nas_encode_bearer_resource_allocation_request(ogs_pkbuf_t *pkbuf, ogs_nas_message_t *message); +int ogs_nas_encode_bearer_resource_allocation_reject(ogs_pkbuf_t *pkbuf, ogs_nas_message_t *message); +int ogs_nas_encode_bearer_resource_modification_request(ogs_pkbuf_t *pkbuf, ogs_nas_message_t *message); +int ogs_nas_encode_bearer_resource_modification_reject(ogs_pkbuf_t *pkbuf, ogs_nas_message_t *message); +int ogs_nas_encode_esm_information_response(ogs_pkbuf_t *pkbuf, ogs_nas_message_t *message); +int ogs_nas_encode_esm_status(ogs_pkbuf_t *pkbuf, ogs_nas_message_t *message); int ogs_nas_encode_attach_request(ogs_pkbuf_t *pkbuf, ogs_nas_message_t *message) { ogs_nas_attach_request_t *attach_request = &message->emm.attach_request; diff --git a/lib/nas/ies.c b/lib/nas/ies.c index 1c57cdf67..804b9bd72 100644 --- a/lib/nas/ies.c +++ b/lib/nas/ies.c @@ -20,7 +20,7 @@ /******************************************************************************* * This file had been created by nas-message.py script v0.1.0 * Please do not modify this file but regenerate it via script. - * Created on: 2019-09-10 21:33:33.927161 by acetcom + * Created on: 2019-09-30 22:46:44.494712 by acetcom * from 24301-d80.docx ******************************************************************************/ @@ -40,7 +40,7 @@ int ogs_nas_encode_optional_type(ogs_pkbuf_t *pkbuf, uint8_t type) int ogs_nas_decode_additional_information(ogs_nas_additional_information_t *additional_information, ogs_pkbuf_t *pkbuf) { uint16_t size = 0; - ogs_nas_additional_information_t *source = pkbuf->data; + ogs_nas_additional_information_t *source = (ogs_nas_additional_information_t *)pkbuf->data; additional_information->length = source->length; size = additional_information->length + sizeof(additional_information->length); @@ -99,7 +99,7 @@ int ogs_nas_encode_device_properties(ogs_pkbuf_t *pkbuf, ogs_nas_device_properti int ogs_nas_decode_eps_bearer_context_status(ogs_nas_eps_bearer_context_status_t *eps_bearer_context_status, ogs_pkbuf_t *pkbuf) { uint16_t size = 0; - ogs_nas_eps_bearer_context_status_t *source = pkbuf->data; + ogs_nas_eps_bearer_context_status_t *source = (ogs_nas_eps_bearer_context_status_t *)pkbuf->data; eps_bearer_context_status->length = source->length; size = eps_bearer_context_status->length + sizeof(eps_bearer_context_status->length); @@ -133,7 +133,7 @@ int ogs_nas_encode_eps_bearer_context_status(ogs_pkbuf_t *pkbuf, ogs_nas_eps_bea int ogs_nas_decode_supported_codec_list(ogs_nas_supported_codec_list_t *supported_codec_list, ogs_pkbuf_t *pkbuf) { uint16_t size = 0; - ogs_nas_supported_codec_list_t *source = pkbuf->data; + ogs_nas_supported_codec_list_t *source = (ogs_nas_supported_codec_list_t *)pkbuf->data; supported_codec_list->length = source->length; size = supported_codec_list->length + sizeof(supported_codec_list->length); @@ -201,7 +201,7 @@ int ogs_nas_encode_location_area_identification(ogs_pkbuf_t *pkbuf, ogs_nas_loca int ogs_nas_decode_mobile_identity(ogs_nas_mobile_identity_t *mobile_identity, ogs_pkbuf_t *pkbuf) { uint16_t size = 0; - ogs_nas_mobile_identity_t *source = pkbuf->data; + ogs_nas_mobile_identity_t *source = (ogs_nas_mobile_identity_t *)pkbuf->data; mobile_identity->length = source->length; size = mobile_identity->length + sizeof(mobile_identity->length); @@ -246,7 +246,7 @@ int ogs_nas_encode_mobile_identity(ogs_pkbuf_t *pkbuf, ogs_nas_mobile_identity_t int ogs_nas_decode_mobile_station_classmark_2(ogs_nas_mobile_station_classmark_2_t *mobile_station_classmark_2, ogs_pkbuf_t *pkbuf) { uint16_t size = 0; - ogs_nas_mobile_station_classmark_2_t *source = pkbuf->data; + ogs_nas_mobile_station_classmark_2_t *source = (ogs_nas_mobile_station_classmark_2_t *)pkbuf->data; mobile_station_classmark_2->length = source->length; size = mobile_station_classmark_2->length + sizeof(mobile_station_classmark_2->length); @@ -280,7 +280,7 @@ int ogs_nas_encode_mobile_station_classmark_2(ogs_pkbuf_t *pkbuf, ogs_nas_mobile int ogs_nas_decode_mobile_station_classmark_3(ogs_nas_mobile_station_classmark_3_t *mobile_station_classmark_3, ogs_pkbuf_t *pkbuf) { uint16_t size = 0; - ogs_nas_mobile_station_classmark_3_t *source = pkbuf->data; + ogs_nas_mobile_station_classmark_3_t *source = (ogs_nas_mobile_station_classmark_3_t *)pkbuf->data; mobile_station_classmark_3->length = source->length; size = mobile_station_classmark_3->length + sizeof(mobile_station_classmark_3->length); @@ -314,7 +314,7 @@ int ogs_nas_encode_mobile_station_classmark_3(ogs_pkbuf_t *pkbuf, ogs_nas_mobile int ogs_nas_decode_plmn_list(ogs_nas_plmn_list_t *plmn_list, ogs_pkbuf_t *pkbuf) { uint16_t size = 0; - ogs_nas_plmn_list_t *source = pkbuf->data; + ogs_nas_plmn_list_t *source = (ogs_nas_plmn_list_t *)pkbuf->data; plmn_list->length = source->length; size = plmn_list->length + sizeof(plmn_list->length); @@ -398,7 +398,7 @@ int ogs_nas_encode_additional_update_type(ogs_pkbuf_t *pkbuf, ogs_nas_additional int ogs_nas_decode_authentication_failure_parameter(ogs_nas_authentication_failure_parameter_t *authentication_failure_parameter, ogs_pkbuf_t *pkbuf) { uint16_t size = 0; - ogs_nas_authentication_failure_parameter_t *source = pkbuf->data; + ogs_nas_authentication_failure_parameter_t *source = (ogs_nas_authentication_failure_parameter_t *)pkbuf->data; authentication_failure_parameter->length = source->length; size = authentication_failure_parameter->length + sizeof(authentication_failure_parameter->length); @@ -492,7 +492,7 @@ int ogs_nas_encode_eps_attach_type(ogs_pkbuf_t *pkbuf, ogs_nas_eps_attach_type_t int ogs_nas_decode_eps_mobile_identity(ogs_nas_eps_mobile_identity_t *eps_mobile_identity, ogs_pkbuf_t *pkbuf) { uint16_t size = 0; - ogs_nas_eps_mobile_identity_t *source = pkbuf->data; + ogs_nas_eps_mobile_identity_t *source = (ogs_nas_eps_mobile_identity_t *)pkbuf->data; eps_mobile_identity->length = source->length; size = eps_mobile_identity->length + sizeof(eps_mobile_identity->length); @@ -539,7 +539,7 @@ int ogs_nas_encode_eps_mobile_identity(ogs_pkbuf_t *pkbuf, ogs_nas_eps_mobile_id int ogs_nas_decode_eps_network_feature_support(ogs_nas_eps_network_feature_support_t *eps_network_feature_support, ogs_pkbuf_t *pkbuf) { uint16_t size = 0; - ogs_nas_eps_network_feature_support_t *source = pkbuf->data; + ogs_nas_eps_network_feature_support_t *source = (ogs_nas_eps_network_feature_support_t *)pkbuf->data; eps_network_feature_support->length = source->length; size = eps_network_feature_support->length + sizeof(eps_network_feature_support->length); @@ -633,7 +633,7 @@ int ogs_nas_encode_eps_update_type(ogs_pkbuf_t *pkbuf, ogs_nas_eps_update_type_t int ogs_nas_decode_esm_message_container(ogs_nas_esm_message_container_t *esm_message_container, ogs_pkbuf_t *pkbuf) { uint16_t size = 0; - ogs_nas_esm_message_container_t *source = pkbuf->data; + ogs_nas_esm_message_container_t *source = (ogs_nas_esm_message_container_t *)pkbuf->data; esm_message_container->length = ntohs(source->length); size = esm_message_container->length + sizeof(esm_message_container->length); @@ -705,7 +705,7 @@ int ogs_nas_encode_gprs_timer(ogs_pkbuf_t *pkbuf, ogs_nas_gprs_timer_t *gprs_tim int ogs_nas_decode_gprs_timer_2(ogs_nas_gprs_timer_2_t *gprs_timer_2, ogs_pkbuf_t *pkbuf) { uint16_t size = 0; - ogs_nas_gprs_timer_2_t *source = pkbuf->data; + ogs_nas_gprs_timer_2_t *source = (ogs_nas_gprs_timer_2_t *)pkbuf->data; gprs_timer_2->length = source->length; size = gprs_timer_2->length + sizeof(gprs_timer_2->length); @@ -739,7 +739,7 @@ int ogs_nas_encode_gprs_timer_2(ogs_pkbuf_t *pkbuf, ogs_nas_gprs_timer_2_t *gprs int ogs_nas_decode_gprs_timer_3(ogs_nas_gprs_timer_3_t *gprs_timer_3, ogs_pkbuf_t *pkbuf) { uint16_t size = 0; - ogs_nas_gprs_timer_3_t *source = pkbuf->data; + ogs_nas_gprs_timer_3_t *source = (ogs_nas_gprs_timer_3_t *)pkbuf->data; gprs_timer_3->length = source->length; size = gprs_timer_3->length + sizeof(gprs_timer_3->length); @@ -858,7 +858,7 @@ int ogs_nas_encode_ksi_and_sequence_number(ogs_pkbuf_t *pkbuf, ogs_nas_ksi_and_s int ogs_nas_decode_authentication_parameter_autn(ogs_nas_authentication_parameter_autn_t *authentication_parameter_autn, ogs_pkbuf_t *pkbuf) { uint16_t size = 0; - ogs_nas_authentication_parameter_autn_t *source = pkbuf->data; + ogs_nas_authentication_parameter_autn_t *source = (ogs_nas_authentication_parameter_autn_t *)pkbuf->data; authentication_parameter_autn->length = source->length; size = authentication_parameter_autn->length + sizeof(authentication_parameter_autn->length); @@ -892,7 +892,7 @@ int ogs_nas_encode_authentication_parameter_autn(ogs_pkbuf_t *pkbuf, ogs_nas_aut int ogs_nas_decode_ms_network_capability(ogs_nas_ms_network_capability_t *ms_network_capability, ogs_pkbuf_t *pkbuf) { uint16_t size = 0; - ogs_nas_ms_network_capability_t *source = pkbuf->data; + ogs_nas_ms_network_capability_t *source = (ogs_nas_ms_network_capability_t *)pkbuf->data; ms_network_capability->length = source->length; size = ms_network_capability->length + sizeof(ms_network_capability->length); @@ -976,7 +976,7 @@ int ogs_nas_encode_key_set_identifier(ogs_pkbuf_t *pkbuf, ogs_nas_key_set_identi int ogs_nas_decode_message_container(ogs_nas_message_container_t *message_container, ogs_pkbuf_t *pkbuf) { uint16_t size = 0; - ogs_nas_message_container_t *source = pkbuf->data; + ogs_nas_message_container_t *source = (ogs_nas_message_container_t *)pkbuf->data; message_container->length = source->length; size = message_container->length + sizeof(message_container->length); @@ -1040,7 +1040,7 @@ int ogs_nas_encode_security_algorithms(ogs_pkbuf_t *pkbuf, ogs_nas_security_algo int ogs_nas_decode_network_name(ogs_nas_network_name_t *network_name, ogs_pkbuf_t *pkbuf) { uint16_t size = 0; - ogs_nas_network_name_t *source = pkbuf->data; + ogs_nas_network_name_t *source = (ogs_nas_network_name_t *)pkbuf->data; network_name->length = source->length; size = network_name->length + sizeof(network_name->length); @@ -1074,7 +1074,7 @@ int ogs_nas_encode_network_name(ogs_pkbuf_t *pkbuf, ogs_nas_network_name_t *netw int ogs_nas_decode_network_resource_identifier_container(ogs_nas_network_resource_identifier_container_t *network_resource_identifier_container, ogs_pkbuf_t *pkbuf) { uint16_t size = 0; - ogs_nas_network_resource_identifier_container_t *source = pkbuf->data; + ogs_nas_network_resource_identifier_container_t *source = (ogs_nas_network_resource_identifier_container_t *)pkbuf->data; network_resource_identifier_container->length = source->length; size = network_resource_identifier_container->length + sizeof(network_resource_identifier_container->length); @@ -1444,7 +1444,7 @@ int ogs_nas_encode_tracking_area_identity(ogs_pkbuf_t *pkbuf, ogs_nas_tracking_a int ogs_nas_decode_tracking_area_identity_list(ogs_nas_tracking_area_identity_list_t *tracking_area_identity_list, ogs_pkbuf_t *pkbuf) { uint16_t size = 0; - ogs_nas_tracking_area_identity_list_t *source = pkbuf->data; + ogs_nas_tracking_area_identity_list_t *source = (ogs_nas_tracking_area_identity_list_t *)pkbuf->data; tracking_area_identity_list->length = source->length; size = tracking_area_identity_list->length + sizeof(tracking_area_identity_list->length); @@ -1478,7 +1478,7 @@ int ogs_nas_encode_tracking_area_identity_list(ogs_pkbuf_t *pkbuf, ogs_nas_track int ogs_nas_decode_ue_network_capability(ogs_nas_ue_network_capability_t *ue_network_capability, ogs_pkbuf_t *pkbuf) { uint16_t size = 0; - ogs_nas_ue_network_capability_t *source = pkbuf->data; + ogs_nas_ue_network_capability_t *source = (ogs_nas_ue_network_capability_t *)pkbuf->data; ue_network_capability->length = source->length; size = ue_network_capability->length + sizeof(ue_network_capability->length); @@ -1537,7 +1537,7 @@ int ogs_nas_encode_ue_radio_capability_information_update_needed(ogs_pkbuf_t *pk int ogs_nas_decode_ue_security_capability(ogs_nas_ue_security_capability_t *ue_security_capability, ogs_pkbuf_t *pkbuf) { uint16_t size = 0; - ogs_nas_ue_security_capability_t *source = pkbuf->data; + ogs_nas_ue_security_capability_t *source = (ogs_nas_ue_security_capability_t *)pkbuf->data; ue_security_capability->length = source->length; size = ue_security_capability->length + sizeof(ue_security_capability->length); @@ -1571,7 +1571,7 @@ int ogs_nas_encode_ue_security_capability(ogs_pkbuf_t *pkbuf, ogs_nas_ue_securit int ogs_nas_decode_emergency_number_list(ogs_nas_emergency_number_list_t *emergency_number_list, ogs_pkbuf_t *pkbuf) { uint16_t size = 0; - ogs_nas_emergency_number_list_t *source = pkbuf->data; + ogs_nas_emergency_number_list_t *source = (ogs_nas_emergency_number_list_t *)pkbuf->data; emergency_number_list->length = source->length; size = emergency_number_list->length + sizeof(emergency_number_list->length); @@ -1605,7 +1605,7 @@ int ogs_nas_encode_emergency_number_list(ogs_pkbuf_t *pkbuf, ogs_nas_emergency_n int ogs_nas_decode_cli(ogs_nas_cli_t *cli, ogs_pkbuf_t *pkbuf) { uint16_t size = 0; - ogs_nas_cli_t *source = pkbuf->data; + ogs_nas_cli_t *source = (ogs_nas_cli_t *)pkbuf->data; cli->length = source->length; size = cli->length + sizeof(cli->length); @@ -1669,7 +1669,7 @@ int ogs_nas_encode_ss_code(ogs_pkbuf_t *pkbuf, ogs_nas_ss_code_t *ss_code) int ogs_nas_decode_authentication_response_parameter(ogs_nas_authentication_response_parameter_t *authentication_response_parameter, ogs_pkbuf_t *pkbuf) { uint16_t size = 0; - ogs_nas_authentication_response_parameter_t *source = pkbuf->data; + ogs_nas_authentication_response_parameter_t *source = (ogs_nas_authentication_response_parameter_t *)pkbuf->data; authentication_response_parameter->length = source->length; size = authentication_response_parameter->length + sizeof(authentication_response_parameter->length); @@ -1733,7 +1733,7 @@ int ogs_nas_encode_lcs_indicator(ogs_pkbuf_t *pkbuf, ogs_nas_lcs_indicator_t *lc int ogs_nas_decode_lcs_client_identity(ogs_nas_lcs_client_identity_t *lcs_client_identity, ogs_pkbuf_t *pkbuf) { uint16_t size = 0; - ogs_nas_lcs_client_identity_t *source = pkbuf->data; + ogs_nas_lcs_client_identity_t *source = (ogs_nas_lcs_client_identity_t *)pkbuf->data; lcs_client_identity->length = source->length; size = lcs_client_identity->length + sizeof(lcs_client_identity->length); @@ -1797,7 +1797,7 @@ int ogs_nas_encode_generic_message_container_type(ogs_pkbuf_t *pkbuf, ogs_nas_ge int ogs_nas_decode_generic_message_container(ogs_nas_generic_message_container_t *generic_message_container, ogs_pkbuf_t *pkbuf) { uint16_t size = 0; - ogs_nas_generic_message_container_t *source = pkbuf->data; + ogs_nas_generic_message_container_t *source = (ogs_nas_generic_message_container_t *)pkbuf->data; generic_message_container->length = ntohs(source->length); size = generic_message_container->length + sizeof(generic_message_container->length); @@ -1839,7 +1839,7 @@ int ogs_nas_encode_generic_message_container(ogs_pkbuf_t *pkbuf, ogs_nas_generic int ogs_nas_decode_voice_domain_preference_and_ue_usage_setting(ogs_nas_voice_domain_preference_and_ue_usage_setting_t *voice_domain_preference_and_ue_usage_setting, ogs_pkbuf_t *pkbuf) { uint16_t size = 0; - ogs_nas_voice_domain_preference_and_ue_usage_setting_t *source = pkbuf->data; + ogs_nas_voice_domain_preference_and_ue_usage_setting_t *source = (ogs_nas_voice_domain_preference_and_ue_usage_setting_t *)pkbuf->data; voice_domain_preference_and_ue_usage_setting->length = source->length; size = voice_domain_preference_and_ue_usage_setting->length + sizeof(voice_domain_preference_and_ue_usage_setting->length); @@ -1898,7 +1898,7 @@ int ogs_nas_encode_guti_type(ogs_pkbuf_t *pkbuf, ogs_nas_guti_type_t *guti_type) int ogs_nas_decode_extended_drx_parameters(ogs_nas_extended_drx_parameters_t *extended_drx_parameters, ogs_pkbuf_t *pkbuf) { uint16_t size = 0; - ogs_nas_extended_drx_parameters_t *source = pkbuf->data; + ogs_nas_extended_drx_parameters_t *source = (ogs_nas_extended_drx_parameters_t *)pkbuf->data; extended_drx_parameters->length = source->length; size = extended_drx_parameters->length + sizeof(extended_drx_parameters->length); @@ -1982,7 +1982,7 @@ int ogs_nas_encode_csfb_response(ogs_pkbuf_t *pkbuf, ogs_nas_csfb_response_t *cs int ogs_nas_decode_daylight_saving_time(ogs_nas_daylight_saving_time_t *daylight_saving_time, ogs_pkbuf_t *pkbuf) { uint16_t size = 0; - ogs_nas_daylight_saving_time_t *source = pkbuf->data; + ogs_nas_daylight_saving_time_t *source = (ogs_nas_daylight_saving_time_t *)pkbuf->data; daylight_saving_time->length = source->length; size = daylight_saving_time->length + sizeof(daylight_saving_time->length); @@ -2106,7 +2106,7 @@ int ogs_nas_encode_emm_cause(ogs_pkbuf_t *pkbuf, ogs_nas_emm_cause_t *emm_cause) int ogs_nas_decode_access_point_name(ogs_nas_access_point_name_t *access_point_name, ogs_pkbuf_t *pkbuf) { uint16_t size = 0; - ogs_nas_access_point_name_t *source = pkbuf->data; + ogs_nas_access_point_name_t *source = (ogs_nas_access_point_name_t *)pkbuf->data; access_point_name->length = source->length; size = access_point_name->length + sizeof(access_point_name->length); @@ -2149,7 +2149,7 @@ int ogs_nas_encode_access_point_name(ogs_pkbuf_t *pkbuf, ogs_nas_access_point_na int ogs_nas_decode_protocol_configuration_options(ogs_nas_protocol_configuration_options_t *protocol_configuration_options, ogs_pkbuf_t *pkbuf) { uint16_t size = 0; - ogs_nas_protocol_configuration_options_t *source = pkbuf->data; + ogs_nas_protocol_configuration_options_t *source = (ogs_nas_protocol_configuration_options_t *)pkbuf->data; protocol_configuration_options->length = source->length; size = protocol_configuration_options->length + sizeof(protocol_configuration_options->length); @@ -2183,7 +2183,7 @@ int ogs_nas_encode_protocol_configuration_options(ogs_pkbuf_t *pkbuf, ogs_nas_pr int ogs_nas_decode_quality_of_service(ogs_nas_quality_of_service_t *quality_of_service, ogs_pkbuf_t *pkbuf) { uint16_t size = 0; - ogs_nas_quality_of_service_t *source = pkbuf->data; + ogs_nas_quality_of_service_t *source = (ogs_nas_quality_of_service_t *)pkbuf->data; quality_of_service->length = source->length; size = quality_of_service->length + sizeof(quality_of_service->length); @@ -2242,7 +2242,7 @@ int ogs_nas_encode_radio_priority(ogs_pkbuf_t *pkbuf, ogs_nas_radio_priority_t * int ogs_nas_decode_re_attempt_indicator(ogs_nas_re_attempt_indicator_t *re_attempt_indicator, ogs_pkbuf_t *pkbuf) { uint16_t size = 0; - ogs_nas_re_attempt_indicator_t *source = pkbuf->data; + ogs_nas_re_attempt_indicator_t *source = (ogs_nas_re_attempt_indicator_t *)pkbuf->data; re_attempt_indicator->length = source->length; size = re_attempt_indicator->length + sizeof(re_attempt_indicator->length); @@ -2306,7 +2306,7 @@ int ogs_nas_encode_request_type(ogs_pkbuf_t *pkbuf, ogs_nas_request_type_t *requ int ogs_nas_decode_traffic_flow_aggregate_description(ogs_nas_traffic_flow_aggregate_description_t *traffic_flow_aggregate_description, ogs_pkbuf_t *pkbuf) { uint16_t size = 0; - ogs_nas_traffic_flow_aggregate_description_t *source = pkbuf->data; + ogs_nas_traffic_flow_aggregate_description_t *source = (ogs_nas_traffic_flow_aggregate_description_t *)pkbuf->data; traffic_flow_aggregate_description->length = source->length; size = traffic_flow_aggregate_description->length + sizeof(traffic_flow_aggregate_description->length); @@ -2340,7 +2340,7 @@ int ogs_nas_encode_traffic_flow_aggregate_description(ogs_pkbuf_t *pkbuf, ogs_na int ogs_nas_decode_traffic_flow_template(ogs_nas_traffic_flow_template_t *traffic_flow_template, ogs_pkbuf_t *pkbuf) { uint16_t size = 0; - ogs_nas_traffic_flow_template_t *source = pkbuf->data; + ogs_nas_traffic_flow_template_t *source = (ogs_nas_traffic_flow_template_t *)pkbuf->data; traffic_flow_template->length = source->length; size = traffic_flow_template->length + sizeof(traffic_flow_template->length); @@ -2374,7 +2374,7 @@ int ogs_nas_encode_traffic_flow_template(ogs_pkbuf_t *pkbuf, ogs_nas_traffic_flo int ogs_nas_decode_transaction_identifier(ogs_nas_transaction_identifier_t *transaction_identifier, ogs_pkbuf_t *pkbuf) { uint16_t size = 0; - ogs_nas_transaction_identifier_t *source = pkbuf->data; + ogs_nas_transaction_identifier_t *source = (ogs_nas_transaction_identifier_t *)pkbuf->data; transaction_identifier->length = source->length; size = transaction_identifier->length + sizeof(transaction_identifier->length); @@ -2433,7 +2433,7 @@ int ogs_nas_encode_wlan_offload_acceptability(ogs_pkbuf_t *pkbuf, ogs_nas_wlan_o int ogs_nas_decode_nbifom_container(ogs_nas_nbifom_container_t *nbifom_container, ogs_pkbuf_t *pkbuf) { uint16_t size = 0; - ogs_nas_nbifom_container_t *source = pkbuf->data; + ogs_nas_nbifom_container_t *source = (ogs_nas_nbifom_container_t *)pkbuf->data; nbifom_container->length = source->length; size = nbifom_container->length + sizeof(nbifom_container->length); @@ -2467,7 +2467,7 @@ int ogs_nas_encode_nbifom_container(ogs_pkbuf_t *pkbuf, ogs_nas_nbifom_container int ogs_nas_decode_apn_aggregate_maximum_bit_rate(ogs_nas_apn_aggregate_maximum_bit_rate_t *apn_aggregate_maximum_bit_rate, ogs_pkbuf_t *pkbuf) { uint16_t size = 0; - ogs_nas_apn_aggregate_maximum_bit_rate_t *source = pkbuf->data; + ogs_nas_apn_aggregate_maximum_bit_rate_t *source = (ogs_nas_apn_aggregate_maximum_bit_rate_t *)pkbuf->data; apn_aggregate_maximum_bit_rate->length = source->length; size = apn_aggregate_maximum_bit_rate->length + sizeof(apn_aggregate_maximum_bit_rate->length); @@ -2501,7 +2501,7 @@ int ogs_nas_encode_apn_aggregate_maximum_bit_rate(ogs_pkbuf_t *pkbuf, ogs_nas_ap int ogs_nas_decode_header_compression_configuration(ogs_nas_header_compression_configuration_t *header_compression_configuration, ogs_pkbuf_t *pkbuf) { uint16_t size = 0; - ogs_nas_header_compression_configuration_t *source = pkbuf->data; + ogs_nas_header_compression_configuration_t *source = (ogs_nas_header_compression_configuration_t *)pkbuf->data; header_compression_configuration->length = source->length; size = header_compression_configuration->length + sizeof(header_compression_configuration->length); @@ -2564,7 +2564,7 @@ int ogs_nas_encode_control_plane_only_indication(ogs_pkbuf_t *pkbuf, ogs_nas_con int ogs_nas_decode_extended_protocol_configuration_options(ogs_nas_extended_protocol_configuration_options_t *extended_protocol_configuration_options, ogs_pkbuf_t *pkbuf) { uint16_t size = 0; - ogs_nas_extended_protocol_configuration_options_t *source = pkbuf->data; + ogs_nas_extended_protocol_configuration_options_t *source = (ogs_nas_extended_protocol_configuration_options_t *)pkbuf->data; extended_protocol_configuration_options->length = ntohs(source->length); size = extended_protocol_configuration_options->length + sizeof(extended_protocol_configuration_options->length); @@ -2606,7 +2606,7 @@ int ogs_nas_encode_extended_protocol_configuration_options(ogs_pkbuf_t *pkbuf, o int ogs_nas_decode_header_compression_configuration_status(ogs_nas_header_compression_configuration_status_t *header_compression_configuration_status, ogs_pkbuf_t *pkbuf) { uint16_t size = 0; - ogs_nas_header_compression_configuration_status_t *source = pkbuf->data; + ogs_nas_header_compression_configuration_status_t *source = (ogs_nas_header_compression_configuration_status_t *)pkbuf->data; header_compression_configuration_status->length = source->length; size = header_compression_configuration_status->length + sizeof(header_compression_configuration_status->length); @@ -2640,7 +2640,7 @@ int ogs_nas_encode_header_compression_configuration_status(ogs_pkbuf_t *pkbuf, o int ogs_nas_decode_serving_plmn_rate_control(ogs_nas_serving_plmn_rate_control_t *serving_plmn_rate_control, ogs_pkbuf_t *pkbuf) { uint16_t size = 0; - ogs_nas_serving_plmn_rate_control_t *source = pkbuf->data; + ogs_nas_serving_plmn_rate_control_t *source = (ogs_nas_serving_plmn_rate_control_t *)pkbuf->data; serving_plmn_rate_control->length = source->length; size = serving_plmn_rate_control->length + sizeof(serving_plmn_rate_control->length); @@ -2699,7 +2699,7 @@ int ogs_nas_encode_connectivity_type(ogs_pkbuf_t *pkbuf, ogs_nas_connectivity_ty int ogs_nas_decode_eps_quality_of_service(ogs_nas_eps_quality_of_service_t *eps_quality_of_service, ogs_pkbuf_t *pkbuf) { uint16_t size = 0; - ogs_nas_eps_quality_of_service_t *source = pkbuf->data; + ogs_nas_eps_quality_of_service_t *source = (ogs_nas_eps_quality_of_service_t *)pkbuf->data; eps_quality_of_service->length = source->length; size = eps_quality_of_service->length + sizeof(eps_quality_of_service->length); @@ -2848,7 +2848,7 @@ int ogs_nas_encode_llc_service_access_point_identifier(ogs_pkbuf_t *pkbuf, ogs_n int ogs_nas_decode_packet_flow_identifier(ogs_nas_packet_flow_identifier_t *packet_flow_identifier, ogs_pkbuf_t *pkbuf) { uint16_t size = 0; - ogs_nas_packet_flow_identifier_t *source = pkbuf->data; + ogs_nas_packet_flow_identifier_t *source = (ogs_nas_packet_flow_identifier_t *)pkbuf->data; packet_flow_identifier->length = source->length; size = packet_flow_identifier->length + sizeof(packet_flow_identifier->length); @@ -2882,7 +2882,7 @@ int ogs_nas_encode_packet_flow_identifier(ogs_pkbuf_t *pkbuf, ogs_nas_packet_flo int ogs_nas_decode_pdn_address(ogs_nas_pdn_address_t *pdn_address, ogs_pkbuf_t *pkbuf) { uint16_t size = 0; - ogs_nas_pdn_address_t *source = pkbuf->data; + ogs_nas_pdn_address_t *source = (ogs_nas_pdn_address_t *)pkbuf->data; pdn_address->length = source->length; size = pdn_address->length + sizeof(pdn_address->length); diff --git a/lib/nas/ies.h b/lib/nas/ies.h index c85ee767d..60eca1c16 100644 --- a/lib/nas/ies.h +++ b/lib/nas/ies.h @@ -20,7 +20,7 @@ /******************************************************************************* * This file had been created by nas-message.py script v0.1.0 * Please do not modify this file but regenerate it via script. - * Created on: 2019-09-10 21:33:33.925174 by acetcom + * Created on: 2019-09-30 22:46:44.492673 by acetcom * from 24301-d80.docx ******************************************************************************/ diff --git a/lib/nas/meson.build b/lib/nas/meson.build new file mode 100644 index 000000000..c5762059d --- /dev/null +++ b/lib/nas/meson.build @@ -0,0 +1,46 @@ +# Copyright (C) 2019 by Sukchan Lee + +# This file is part of Open5GS. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +libnas_sources = files(''' + ogs-nas.h + + ies.h + types.h + conv.h + message.h + + ies.c + types.c + conv.c + decoder.c + encoder.c +'''.split()) + +libnas_inc = include_directories('.') + +libnas = library('ogsnas', + sources : libnas_sources, + version : libogslib_version, + c_args : '-DOGS_NAS_COMPILATION', + include_directories : [libnas_inc, libcrypt_inc, libinc], + dependencies : libcore_dep, + install : true) + +libnas_dep = declare_dependency( + link_with : libnas, + include_directories : [libnas_inc, libcrypt_inc, libinc], + dependencies : libcore_dep) diff --git a/lib/nas/message.h b/lib/nas/message.h index e289a8a7c..705843ec2 100644 --- a/lib/nas/message.h +++ b/lib/nas/message.h @@ -20,7 +20,7 @@ /******************************************************************************* * This file had been created by nas-message.py script v0.1.0 * Please do not modify this file but regenerate it via script. - * Created on: 2019-09-10 21:33:33.932906 by acetcom + * Created on: 2019-09-30 22:46:44.500512 by acetcom * from 24301-d80.docx ******************************************************************************/ @@ -1408,6 +1408,8 @@ typedef struct ogs_nas_message_s { }; } ogs_nas_message_t; +int ogs_nas_emm_encode(ogs_pkbuf_t **pkbuf, ogs_nas_message_t *message); +int ogs_nas_esm_encode(ogs_pkbuf_t **pkbuf, ogs_nas_message_t *message); int ogs_nas_emm_decode(ogs_nas_message_t *message, ogs_pkbuf_t *pkbuf); int ogs_nas_esm_decode(ogs_nas_message_t *message, ogs_pkbuf_t *pkbuf); int ogs_nas_plain_encode( diff --git a/lib/ogs-nas.h b/lib/nas/ogs-nas.h similarity index 97% rename from lib/ogs-nas.h rename to lib/nas/ogs-nas.h index ac91af0a0..6e80897d2 100644 --- a/lib/ogs-nas.h +++ b/lib/nas/ogs-nas.h @@ -20,7 +20,7 @@ #ifndef OGS_NAS_H #define OGS_NAS_H -#include "ogs-common.h" +#include "ogs-core.h" #include "ogs-crypt.h" #define OGS_NAS_INSIDE diff --git a/lib/nas/support/README.md b/lib/nas/support/README.md index f98450008..5b1c49825 100644 --- a/lib/nas/support/README.md +++ b/lib/nas/support/README.md @@ -1,10 +1,10 @@ * Install python-pip -user@host ~/Documents/git/nextepc/lib/gtp/support$ \ +user@host ~/Documents/git/open5gs/lib/gtp/support$ \ sudo apt-get install python-pip * Install python-docx -user@host ~/Documents/git/nextepc/lib/gtp/support$ \ +user@host ~/Documents/git/open5gs/lib/gtp/support$ \ sudo pip install python-docx * Change the format of standard specification @@ -12,5 +12,5 @@ user@host ~/Documents/git/nextepc/lib/gtp/support$ \ using Microsoft Office 2007+ * Generate Message support files -user@host ~/Documents/git/nextepc/lib/s1ap/support$ \ +user@host ~/Documents/git/open5gs/lib/s1ap/support$ \ python nas-message.py -f 24301-d80.docx -o .. diff --git a/lib/nas/support/nas-message.py b/lib/nas/support/nas-message.py index d57edc507..777e067ab 100644 --- a/lib/nas/support/nas-message.py +++ b/lib/nas/support/nas-message.py @@ -434,7 +434,7 @@ for (k, v) in sorted_type_list: f.write("int ogs_nas_decode_%s(ogs_nas_%s_t *%s, ogs_pkbuf_t *pkbuf)\n" % (v_lower(k), v_lower(k), v_lower(k))) f.write("{\n") f.write(" uint16_t size = 0;\n") - f.write(" ogs_nas_%s_t *source = pkbuf->data;\n\n" % v_lower(k)) + f.write(" ogs_nas_%s_t *source = (ogs_nas_%s_t *)pkbuf->data;\n\n" % (v_lower(k), v_lower(k))) f.write(" %s->length = ntohs(source->length);\n" % v_lower(k)) f.write(" size = %s->length + sizeof(%s->length);\n\n" % (v_lower(k), v_lower(k))) f.write(" ogs_assert(ogs_pkbuf_pull(pkbuf, size));\n") @@ -464,7 +464,7 @@ for (k, v) in sorted_type_list: f.write("int ogs_nas_decode_%s(ogs_nas_%s_t *%s, ogs_pkbuf_t *pkbuf)\n" % (v_lower(k), v_lower(k), v_lower(k))) f.write("{\n") f.write(" uint16_t size = 0;\n") - f.write(" ogs_nas_%s_t *source = pkbuf->data;\n\n" % v_lower(k)) + f.write(" ogs_nas_%s_t *source = (ogs_nas_%s_t *)pkbuf->data;\n\n" % (v_lower(k), v_lower(k))) f.write(" %s->length = source->length;\n" % v_lower(k)) f.write(" size = %s->length + sizeof(%s->length);\n\n" % (v_lower(k), v_lower(k))) f.write(" ogs_assert(ogs_pkbuf_pull(pkbuf, size));\n") @@ -622,6 +622,8 @@ typedef struct ogs_nas_message_s { }; } ogs_nas_message_t; +int ogs_nas_emm_encode(ogs_pkbuf_t **pkbuf, ogs_nas_message_t *message); +int ogs_nas_esm_encode(ogs_pkbuf_t **pkbuf, ogs_nas_message_t *message); int ogs_nas_emm_decode(ogs_nas_message_t *message, ogs_pkbuf_t *pkbuf); int ogs_nas_esm_decode(ogs_nas_message_t *message, ogs_pkbuf_t *pkbuf); int ogs_nas_plain_encode( @@ -644,6 +646,13 @@ f.write("""#include "ogs-nas.h" """) +for (k, v) in sorted_msg_list: + if "ies" not in msg_list[k]: + continue + if len(msg_list[k]["ies"]) == 0: + continue + f.write("int ogs_nas_decode_%s(ogs_nas_message_t *message, ogs_pkbuf_t *pkbuf);\n" % v_lower(k)) + for (k, v) in sorted_msg_list: if "ies" not in msg_list[k]: continue @@ -703,7 +712,7 @@ for (k, v) in sorted_msg_list: f.write("""int ogs_nas_emm_decode(ogs_nas_message_t *message, ogs_pkbuf_t *pkbuf) { - uint16_t size = 0; + int size = 0; uint16_t decoded = 0; ogs_assert(pkbuf); @@ -723,7 +732,7 @@ f.write("""int ogs_nas_emm_decode(ogs_nas_message_t *message, ogs_pkbuf_t *pkbuf ogs_assert(ogs_pkbuf_push(pkbuf, 1)); decoded -= 1; size = ogs_nas_decode_service_request(message, pkbuf); - ogs_assert(size >= OGS_OK); + ogs_assert(size >= 0); decoded += size; goto out; @@ -739,7 +748,7 @@ for (k, v) in sorted_msg_list: f.write(" case OGS_NAS_%s:\n" % v_upper(k)) if len(msg_list[k]["ies"]) != 0: f.write(" size = ogs_nas_decode_%s(message, pkbuf);\n" % v_lower(k)) - f.write(" ogs_assert(size >= OGS_OK);\n") + f.write(" ogs_assert(size >= 0);\n") f.write(" decoded += size;\n") f.write(" break;\n") @@ -758,7 +767,7 @@ out: f.write("""int ogs_nas_esm_decode(ogs_nas_message_t *message, ogs_pkbuf_t *pkbuf) { - uint16_t size = 0; + int size = 0; uint16_t decoded = 0; ogs_assert(pkbuf); @@ -782,7 +791,7 @@ for (k, v) in sorted_msg_list: f.write(" case OGS_NAS_%s:\n" % v_upper(k)) if len(msg_list[k]["ies"]) != 0: f.write(" size = ogs_nas_decode_%s(message, pkbuf);\n" % v_lower(k)) - f.write(" ogs_assert(size >= OGS_OK);\n") + f.write(" ogs_assert(size >= 0);\n") f.write(" decoded += size;\n") f.write(" break;\n") @@ -807,6 +816,13 @@ f.write("""#include "ogs-nas.h" """) +for (k, v) in sorted_msg_list: + if "ies" not in msg_list[k]: + continue; + if len(msg_list[k]["ies"]) == 0: + continue + f.write("int ogs_nas_encode_%s(ogs_pkbuf_t *pkbuf, ogs_nas_message_t *message);\n" % v_lower(k)) + for (k, v) in sorted_msg_list: if "ies" not in msg_list[k]: continue; diff --git a/lib/nas/types.h b/lib/nas/types.h index 22d20610d..26a7e207f 100644 --- a/lib/nas/types.h +++ b/lib/nas/types.h @@ -24,7 +24,7 @@ #ifndef OGS_NAS_TYPES_H #define OGS_NAS_TYPES_H -#include "ogs-common.h" +#include "ogs-core.h" #ifdef __cplusplus extern "C" { @@ -33,8 +33,7 @@ extern "C" { #define OGS_NAS_CLEAR_DATA(__dATA) \ do { \ ogs_assert((__dATA)); \ - if ((__dATA)->buffer) \ - { \ + if ((__dATA)->buffer) { \ ogs_free((__dATA)->buffer); \ (__dATA)->buffer = NULL; \ (__dATA)->length = 0; \ diff --git a/lib/ogslib b/lib/ogslib deleted file mode 160000 index c79b09b9b..000000000 --- a/lib/ogslib +++ /dev/null @@ -1 +0,0 @@ -Subproject commit c79b09b9bbd932aa0db285de503cffc280003db5 diff --git a/lib/s1ap/conv.h b/lib/s1ap/conv.h index bfa10a787..b92f32edd 100644 --- a/lib/s1ap/conv.h +++ b/lib/s1ap/conv.h @@ -24,8 +24,6 @@ #ifndef OGS_S1AP_CONV_H #define OGS_S1AP_CONV_H -#include "ogs-s1ap.h" - #ifdef __cplusplus extern "C" { #endif diff --git a/lib/s1ap/meson.build b/lib/s1ap/meson.build new file mode 100644 index 000000000..b54361939 --- /dev/null +++ b/lib/s1ap/meson.build @@ -0,0 +1,41 @@ +# Copyright (C) 2019 by Sukchan Lee + +# This file is part of Open5GS. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +libs1ap_sources = files(''' + ogs-s1ap.h + + conv.h + message.h + + conv.c + message.c +'''.split()) + +libs1ap_inc = include_directories('.') + +libs1ap = library('ogss1ap', + sources : libs1ap_sources, + version : libogslib_version, + c_args : '-DOGS_S1AP_COMPILATION', + include_directories : [libs1ap_inc, libinc], + dependencies : libasn1c_s1ap_dep, + install : true) + +libs1ap_dep = declare_dependency( + link_with : libs1ap, + include_directories : [libs1ap_inc, libinc], + dependencies : libasn1c_s1ap_dep) diff --git a/lib/ogs-s1ap.h b/lib/s1ap/ogs-s1ap.h similarity index 99% rename from lib/ogs-s1ap.h rename to lib/s1ap/ogs-s1ap.h index 40f2277e1..66ac883e9 100644 --- a/lib/ogs-s1ap.h +++ b/lib/s1ap/ogs-s1ap.h @@ -20,7 +20,7 @@ #ifndef OGS_S1AP_H #define OGS_S1AP_H -#include "ogs-common.h" +#include "ogs-core.h" #include "S1AP_Additional-GUTI.h" #include "S1AP_AdditionalCSFallbackIndicator.h" diff --git a/lib/sctp/meson.build b/lib/sctp/meson.build new file mode 100644 index 000000000..ba53bfa62 --- /dev/null +++ b/lib/sctp/meson.build @@ -0,0 +1,72 @@ +# Copyright (C) 2019 by Sukchan Lee + +# This file is part of Open5GS. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +libsctp_conf = configuration_data() + +libsctp_headers = (''' + netinet/sctp.h +'''.split()) + +foreach h : libsctp_headers + if cc.has_header(h) + define = 'HAVE_' + h.underscorify().to_upper() + libsctp_conf.set(define, 1) + endif +endforeach + +libsctp_sources = files(''' + ogs-sctp.h + + ogs-sctp.c +'''.split()) + +libsctp_dep = cc.find_library('sctp', required : false) +if libsctp_dep.found() + libsctp_sources += files('ogs-lksctp.c') +else + libsctp_dep = cc.find_library('usrsctp', required : false) + if not libsctp_dep.found() +# sctp_debug = get_option('debug_level') >= 7 + libsctp_dep = dependency('usrsctp', + version: ['>=1.0.0', '<2'], + fallback: ['usrsctp', 'usrsctp_dep'], + default_options: [ + 'sctp_build_programs=false', +# 'sctp_debug=@0@'.format(sctp_debug), + ]) + endif + + libsctp_sources += files('ogs-usrsctp.c') + libsctp_conf.set('HAVE_USRSCTP', 1) +endif + +configure_file(output : 'sctp-config.h', configuration : libsctp_conf) + +libsctp_inc = include_directories('.') + +libsctp = library('ogssctp', + sources : libsctp_sources, + version : libogslib_version, + c_args : '-DOGS_SCTP_COMPILATION', + include_directories : [libsctp_inc, libinc], + dependencies : [libcore_dep, libsctp_dep], + install : true) + +libsctp_dep = declare_dependency( + link_with : libsctp, + include_directories : [libsctp_inc, libinc], + dependencies : [libcore_dep, libsctp_dep]) diff --git a/lib/ogs-sctp.h b/lib/sctp/ogs-sctp.h similarity index 98% rename from lib/ogs-sctp.h rename to lib/sctp/ogs-sctp.h index 9d4713b21..023bd9e4d 100644 --- a/lib/ogs-sctp.h +++ b/lib/sctp/ogs-sctp.h @@ -20,7 +20,9 @@ #ifndef OGS_SCTP_H #define OGS_SCTP_H -#include "ogs-common.h" +#include "ogs-core.h" + +#include "sctp/sctp-config.h" #if HAVE_NETINET_SCTP_H #include @@ -60,6 +62,8 @@ extern int __ogs_sctp_domain; #endif #include ogs_sockaddr_t *ogs_usrsctp_remote_addr(union sctp_sockstore *store); +void ogs_sctp_destroy(ogs_sock_t *sock); +ogs_sock_t *ogs_sctp_accept(ogs_sock_t *sock); #else #define ogs_sctp_destroy ogs_sock_destroy #define ogs_sctp_accept ogs_sock_accept @@ -78,7 +82,6 @@ void ogs_sctp_init(uint16_t port); void ogs_sctp_final(void); ogs_sock_t *ogs_sctp_socket(int family, int type, ogs_socknode_t *node); -void ogs_sctp_destroy(ogs_sock_t *sock); void ogs_sctp_set_option(ogs_sockopt_t *option, ogs_socknode_t *node); @@ -88,7 +91,6 @@ ogs_sock_t *ogs_sctp_client(int type, ogs_socknode_t *node); int ogs_sctp_bind(ogs_sock_t *sock, ogs_sockaddr_t *sa_list); int ogs_sctp_connect(ogs_sock_t *sock, ogs_sockaddr_t *sa_list); int ogs_sctp_listen(ogs_sock_t *sock); -ogs_sock_t *ogs_sctp_accept(ogs_sock_t *sock); int ogs_sctp_sendmsg(ogs_sock_t *sock, const void *msg, size_t len, ogs_sockaddr_t *to, uint32_t ppid, uint16_t stream_no); diff --git a/lib/sctp/ogs-usrsctp.c b/lib/sctp/ogs-usrsctp.c index c9418044d..ea6c119bd 100644 --- a/lib/sctp/ogs-usrsctp.c +++ b/lib/sctp/ogs-usrsctp.c @@ -420,7 +420,10 @@ static void ogs_debug_printf(const char *format, ...) va_list ap; va_start(ap, format); +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wformat-nonliteral" vprintf(format, ap); +#pragma GCC diagnostic pop va_end(ap); } diff --git a/m4/ax_check_compile_flag.m4 b/m4/ax_check_compile_flag.m4 deleted file mode 100644 index bd753b34d..000000000 --- a/m4/ax_check_compile_flag.m4 +++ /dev/null @@ -1,53 +0,0 @@ -# =========================================================================== -# https://www.gnu.org/software/autoconf-archive/ax_check_compile_flag.html -# =========================================================================== -# -# SYNOPSIS -# -# AX_CHECK_COMPILE_FLAG(FLAG, [ACTION-SUCCESS], [ACTION-FAILURE], [EXTRA-FLAGS], [INPUT]) -# -# DESCRIPTION -# -# Check whether the given FLAG works with the current language's compiler -# or gives an error. (Warnings, however, are ignored) -# -# ACTION-SUCCESS/ACTION-FAILURE are shell commands to execute on -# success/failure. -# -# If EXTRA-FLAGS is defined, it is added to the current language's default -# flags (e.g. CFLAGS) when the check is done. The check is thus made with -# the flags: "CFLAGS EXTRA-FLAGS FLAG". This can for example be used to -# force the compiler to issue an error when a bad flag is given. -# -# INPUT gives an alternative input source to AC_COMPILE_IFELSE. -# -# NOTE: Implementation based on AX_CFLAGS_GCC_OPTION. Please keep this -# macro in sync with AX_CHECK_{PREPROC,LINK}_FLAG. -# -# LICENSE -# -# Copyright (c) 2008 Guido U. Draheim -# Copyright (c) 2011 Maarten Bosmans -# -# Copying and distribution of this file, with or without modification, are -# permitted in any medium without royalty provided the copyright notice -# and this notice are preserved. This file is offered as-is, without any -# warranty. - -#serial 6 - -AC_DEFUN([AX_CHECK_COMPILE_FLAG], -[AC_PREREQ(2.64)dnl for _AC_LANG_PREFIX and AS_VAR_IF -AS_VAR_PUSHDEF([CACHEVAR],[ax_cv_check_[]_AC_LANG_ABBREV[]flags_$4_$1])dnl -AC_CACHE_CHECK([whether _AC_LANG compiler accepts $1], CACHEVAR, [ - ax_check_save_flags=$[]_AC_LANG_PREFIX[]FLAGS - _AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS $4 $1" - AC_COMPILE_IFELSE([m4_default([$5],[AC_LANG_PROGRAM()])], - [AS_VAR_SET(CACHEVAR,[yes])], - [AS_VAR_SET(CACHEVAR,[no])]) - _AC_LANG_PREFIX[]FLAGS=$ax_check_save_flags]) -AS_VAR_IF(CACHEVAR,yes, - [m4_default([$2], :)], - [m4_default([$3], :)]) -AS_VAR_POPDEF([CACHEVAR])dnl -])dnl AX_CHECK_COMPILE_FLAGS diff --git a/m4/ax_recursive_eval.m4 b/m4/ax_recursive_eval.m4 deleted file mode 100644 index 0625aca22..000000000 --- a/m4/ax_recursive_eval.m4 +++ /dev/null @@ -1,56 +0,0 @@ -# =========================================================================== -# https://www.gnu.org/software/autoconf-archive/ax_recursive_eval.html -# =========================================================================== -# -# SYNOPSIS -# -# AX_RECURSIVE_EVAL(VALUE, RESULT) -# -# DESCRIPTION -# -# Interpolate the VALUE in loop until it doesn't change, and set the -# result to $RESULT. WARNING: It's easy to get an infinite loop with some -# unsane input. -# -# LICENSE -# -# Copyright (c) 2008 Alexandre Duret-Lutz -# -# This program is free software; you can redistribute it and/or modify it -# under the terms of the GNU General Public License as published by the -# Free Software Foundation; either version 2 of the License, or (at your -# option) any later version. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General -# Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with this program. If not, see . -# -# As a special exception, the respective Autoconf Macro's copyright owner -# gives unlimited permission to copy, distribute and modify the configure -# scripts that are the output of Autoconf when processing the Macro. You -# need not follow the terms of the GNU General Public License when using -# or distributing such scripts, even though portions of the text of the -# Macro appear in them. The GNU General Public License (GPL) does govern -# all other use of the material that constitutes the Autoconf Macro. -# -# This special exception to the GPL applies to versions of the Autoconf -# Macro released by the Autoconf Archive. When you make and distribute a -# modified version of the Autoconf Macro, you may extend this special -# exception to the GPL to apply to your modified version as well. - -#serial 1 - -AC_DEFUN([AX_RECURSIVE_EVAL], -[_lcl_receval="$1" -$2=`(test "x$prefix" = xNONE && prefix="$ac_default_prefix" - test "x$exec_prefix" = xNONE && exec_prefix="${prefix}" - _lcl_receval_old='' - while test "[$]_lcl_receval_old" != "[$]_lcl_receval"; do - _lcl_receval_old="[$]_lcl_receval" - eval _lcl_receval="\"[$]_lcl_receval\"" - done - echo "[$]_lcl_receval")`]) diff --git a/meson.build b/meson.build new file mode 100644 index 000000000..de6f2f2b4 --- /dev/null +++ b/meson.build @@ -0,0 +1,135 @@ +# Copyright (C) 2019 by Sukchan Lee + +# This file is part of Open5GS. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +project('open5gs', 'c', + version : '1.0.0', + license : 'AGPL-3.0-or-later', + meson_version : '>= 0.43.0', + default_options : [ + 'warning_level=1', + 'c_std=gnu89', + 'prefix=/usr', + ], +) + +libogslib_version = '1.0.0' + +prefix = get_option('prefix') +bindir = join_paths(prefix, get_option('bindir')) +libdir = join_paths(prefix, get_option('libdir')) +sysconfdir = join_paths(prefix, get_option('sysconfdir')) +localstatedir = join_paths(prefix, get_option('localstatedir')) + +cc = meson.get_compiler('c') +host_system = host_machine.system() + +#python = import('python') +#python3 = python.find_installation('python3') +python3 = find_program('python3', 'python') +python3_exe = join_paths(python3.path()) +mkdir_p = 'import os; os.makedirs("@0@", exist_ok=True) if not os.environ.get("DESTDIR") else False;' +install_conf = 'import os; import shutil; shutil.copy("@0@", "@1@") if not os.environ.get("DESTDIR") and not os.path.isfile(os.path.join("@1@", os.path.split("@0@")[1])) else False;' + +meson.add_install_script(python3_exe, '-c', + mkdir_p.format(join_paths(localstatedir, 'log', 'open5gs'))) + +# Compiler flags +if cc.get_id() == 'gcc' or cc.get_id() == 'clang' + possible_cc_flags = [ + '-Wextra', + '-Wlogical-op', + '-Werror=missing-include-dirs', + '-Werror=pointer-arith', + '-Werror=init-self', + '-Wfloat-equal', + '-Wsuggest-attribute=noreturn', + '-Werror=missing-prototypes', + '-Werror=missing-declarations', + '-Werror=implicit-function-declaration', + '-Werror=return-type', + '-Werror=incompatible-pointer-types', + '-Werror=format=2', + '-Wstrict-prototypes', + '-Wredundant-decls', + '-Wimplicit-fallthrough=5', + '-Wendif-labels', + '-Wstrict-aliasing=3', + '-Wwrite-strings', + '-Werror=overflow', + '-Werror=shift-count-overflow', + '-Werror=shift-overflow=2', + '-Wdate-time', + '-Wnested-externs', + '-Wunused', + '-Wduplicated-branches', + '-Wmisleading-indentation', + + '-Wno-sign-compare', + '-Wno-unused-parameter', + + '-ffast-math', + '-fdiagnostics-show-option', + ## TODO : '-fvisibility=hidden', + '-fstack-protector', + '-fstack-protector-strong', + '--param=ssp-buffer-size=4', + ] + + if cc.get_id() == 'clang' + possible_cc_flags += [ + '-Wno-typedef-redefinition', + '-Wno-gnu-variable-sized-type-not-at-end', + ] + endif + + if get_option('buildtype') != 'debug' + possible_cc_flags += [ + '-ffunction-sections', + '-fdata-sections', + ] + endif +else + possible_cc_flags = [] +endif + +add_project_arguments( + cc.get_supported_arguments(possible_cc_flags), + language : 'c') + +freediameter_proj = subproject('freediameter') + +subdir('configs') +subdir('lib') +subdir('src') +# Don’t build the tests unless we can run them (either natively or in an exe wrapper) +build_tests = not meson.is_cross_build() or (meson.is_cross_build() and meson.has_exe_wrapper()) +if build_tests + subdir('tests') +endif + +message('\n'.join([ + '', + ' prefix: ' + get_option('prefix'), + ' libdir: ' + get_option('libdir'), + ' bindir: ' + get_option('bindir'), + ' sysconfdir: ' + get_option('sysconfdir'), + ' localstatedir: ' + get_option('localstatedir'), + ' source code location: ' + meson.source_root(), + ' compiler: ' + cc.get_id(), + ' debugging support: ' + get_option('buildtype'), + '', +])) diff --git a/misc/README.md b/misc/README.md new file mode 100644 index 000000000..4b301df1e --- /dev/null +++ b/misc/README.md @@ -0,0 +1,6 @@ + +* Network Configuration +$ sudo ./misc/network/restart.sh + +* Generate Key & Cert for Diameter +$ ./misc/ssl/make_certs.sh ./freeDiameter diff --git a/build/dput-upload.sh b/misc/dput-upload.sh similarity index 100% rename from build/dput-upload.sh rename to misc/dput-upload.sh diff --git a/build/git-version-gen b/misc/git-version-gen similarity index 100% rename from build/git-version-gen rename to misc/git-version-gen diff --git a/support/network/ipv6_restart.sh b/misc/ipv6_netconf.sh similarity index 77% rename from support/network/ipv6_restart.sh rename to misc/ipv6_netconf.sh index 5917f5541..fa4c940a7 100755 --- a/support/network/ipv6_restart.sh +++ b/misc/ipv6_netconf.sh @@ -3,14 +3,14 @@ SYSTEM=`uname`; if [ "$SYSTEM" = "Linux" ]; then - if ! grep "pgwtun" /proc/net/dev > /dev/null; then - ip tuntap add name pgwtun mode tun + if ! grep "ogstun" /proc/net/dev > /dev/null; then + ip tuntap add name ogstun mode tun fi - ip addr del 45.45.0.1/16 dev pgwtun 2> /dev/null - ip addr add 45.45.0.1/16 dev pgwtun - ip addr del cafe::1/64 dev pgwtun 2> /dev/null - ip addr add cafe::1/64 dev pgwtun - ip link set pgwtun up + ip addr del 45.45.0.1/16 dev ogstun 2> /dev/null + ip addr add 45.45.0.1/16 dev ogstun + ip addr del cafe::1/64 dev ogstun 2> /dev/null + ip addr add cafe::1/64 dev ogstun + ip link set ogstun up ip addr del fe80::2 dev lo 2> /dev/null ip addr del fe80::3 dev lo 2> /dev/null ip addr del fe80::4 dev lo 2> /dev/null diff --git a/support/freeDiameter/make_certs.sh b/misc/make_certs.sh similarity index 82% rename from support/freeDiameter/make_certs.sh rename to misc/make_certs.sh index 81b5e1c04..b11a90812 100755 --- a/support/freeDiameter/make_certs.sh +++ b/misc/make_certs.sh @@ -13,26 +13,26 @@ echo 01 > demoCA/serial touch demoCA/index.txt # CA self certificate -openssl req -new -batch -x509 -days 3650 -nodes -newkey rsa:1024 -out $1/cacert.pem -keyout cakey.pem -subj /CN=ca.localdomain/C=KO/ST=Seoul/L=Nowon/O=NextEPC/OU=Tests +openssl req -new -batch -x509 -days 3650 -nodes -newkey rsa:1024 -out $1/cacert.pem -keyout cakey.pem -subj /CN=ca.localdomain/C=KO/ST=Seoul/L=Nowon/O=Open5GS/OU=Tests #mme openssl genrsa -out $1/mme.key.pem 1024 -openssl req -new -batch -out mme.csr.pem -key $1/mme.key.pem -subj /CN=mme.localdomain/C=KO/ST=Seoul/L=Nowon/O=NextEPC/OU=Tests +openssl req -new -batch -out mme.csr.pem -key $1/mme.key.pem -subj /CN=mme.localdomain/C=KO/ST=Seoul/L=Nowon/O=Open5GS/OU=Tests openssl ca -cert $1/cacert.pem -days 3650 -keyfile cakey.pem -in mme.csr.pem -out $1/mme.cert.pem -outdir . -batch #hss openssl genrsa -out $1/hss.key.pem 1024 -openssl req -new -batch -out hss.csr.pem -key $1/hss.key.pem -subj /CN=hss.localdomain/C=KO/ST=Seoul/L=Nowon/O=NextEPC/OU=Tests +openssl req -new -batch -out hss.csr.pem -key $1/hss.key.pem -subj /CN=hss.localdomain/C=KO/ST=Seoul/L=Nowon/O=Open5GS/OU=Tests openssl ca -cert $1/cacert.pem -days 3650 -keyfile cakey.pem -in hss.csr.pem -out $1/hss.cert.pem -outdir . -batch #pgw openssl genrsa -out $1/pgw.key.pem 1024 -openssl req -new -batch -out pgw.csr.pem -key $1/pgw.key.pem -subj /CN=pgw.localdomain/C=KO/ST=Seoul/L=Nowon/O=NextEPC/OU=Tests +openssl req -new -batch -out pgw.csr.pem -key $1/pgw.key.pem -subj /CN=pgw.localdomain/C=KO/ST=Seoul/L=Nowon/O=Open5GS/OU=Tests openssl ca -cert $1/cacert.pem -days 3650 -keyfile cakey.pem -in pgw.csr.pem -out $1/pgw.cert.pem -outdir . -batch #pcrf openssl genrsa -out $1/pcrf.key.pem 1024 -openssl req -new -batch -out pcrf.csr.pem -key $1/pcrf.key.pem -subj /CN=pcrf.localdomain/C=KO/ST=Seoul/L=Nowon/O=NextEPC/OU=Tests +openssl req -new -batch -out pcrf.csr.pem -key $1/pcrf.key.pem -subj /CN=pcrf.localdomain/C=KO/ST=Seoul/L=Nowon/O=Open5GS/OU=Tests openssl ca -cert $1/cacert.pem -days 3650 -keyfile cakey.pem -in pcrf.csr.pem -out $1/pcrf.cert.pem -outdir . -batch rm -rf demoCA diff --git a/support/mongodb/python/NextEPC.py b/misc/mongodb/python/Open5GS.py similarity index 87% rename from support/mongodb/python/NextEPC.py rename to misc/mongodb/python/Open5GS.py index e065491e1..dfdbb7c8d 100644 --- a/support/mongodb/python/NextEPC.py +++ b/misc/mongodb/python/Open5GS.py @@ -3,7 +3,7 @@ import pymongo import random import bson -class NextEPC: +class Open5GS: def __init__(self, server, port): self.server = server self.port = port @@ -11,7 +11,7 @@ class NextEPC: def GetSubscribers(self): myclient = pymongo.MongoClient("mongodb://" + str(self.server) + ":" + str(self.port) + "/") - mydb = myclient["nextepc"] + mydb = myclient["open5gs"] mycol = mydb["subscribers"] subs_list = [] for x in mycol.find(): @@ -23,7 +23,7 @@ class NextEPC: def GetSubscriber(self, imsi): myclient = pymongo.MongoClient("mongodb://" + str(self.server) + ":" + str(self.port) + "/") - mydb = myclient["nextepc"] + mydb = myclient["open5gs"] mycol = mydb["subscribers"] myquery = { "imsi": str(imsi)} mydoc = mycol.find(myquery) @@ -35,7 +35,7 @@ class NextEPC: def AddSubscriber(self, sub_data): myclient = pymongo.MongoClient("mongodb://" + str(self.server) + ":" + str(self.port) + "/") - mydb = myclient["nextepc"] + mydb = myclient["open5gs"] mycol = mydb["subscribers"] x = mycol.insert_one(sub_data) @@ -45,7 +45,7 @@ class NextEPC: def DeleteSubscriber(self, imsi): myclient = pymongo.MongoClient("mongodb://" + str(self.server) + ":" + str(self.port) + "/") - mydb = myclient["nextepc"] + mydb = myclient["open5gs"] mycol = mydb["subscribers"] myquery = { "imsi": str(imsi)} x = mycol.delete_many(myquery) diff --git a/support/mongodb/python/README.md b/misc/mongodb/python/README.md similarity index 77% rename from support/mongodb/python/README.md rename to misc/mongodb/python/README.md index f6a37509d..031cc1965 100644 --- a/support/mongodb/python/README.md +++ b/misc/mongodb/python/README.md @@ -1,6 +1,6 @@ -## NextEPC Python Library +## Open5GS Python Library -Basic Python library to interface with MongoDB subscriber DB in NextEPC HSS / PCRF. Requires Python 3+, mongo, pymongo and bson. (All available through PIP) +Basic Python library to interface with MongoDB subscriber DB in Open5GS HSS / PCRF. Requires Python 3+, mongo, pymongo and bson. (All available through PIP) If you are planning to run this on a different machine other than localhost (the machine hosting the MongoDB service) you will need to enable remote access to MongoDB by binding it's IP to 0.0.0.0: @@ -14,8 +14,8 @@ Restart MongoDB for changes to take effect. Basic Example: ``` -import NextEPC -NextEPC_1 = NextEPC("10.0.1.118", 27017) +import Open5GS +Open5GS_1 = Open5GS("10.0.1.118", 27017) pdn = [{'apn': 'internet', 'pcc_rule': [], 'ambr': {'downlink': 1234, 'uplink': 1234}, 'qos': {'qci': 9, 'arp': {'priority_level': 8, 'pre_emption_vulnerability': 1, 'pre_emption_capability': 1}}, 'type': 2}] sub_data = {'imsi': '891012222222300', \ @@ -27,13 +27,13 @@ sub_data = {'imsi': '891012222222300', \ 'access_restriction_data': 32, \ 'security': {'k': '465B5CE8 B199B49F AA5F0A2E E238A6BC', 'amf': '8000', 'op': None, 'opc': 'E8ED289D EBA952E4 283B54E8 8E6183CA'}, '__v': 0} -print(NextEPC_1.AddSubscriber(sub_data)) #Add Subscriber using dict of sub_data +print(Open5GS_1.AddSubscriber(sub_data)) #Add Subscriber using dict of sub_data -print(NextEPC_1.GetSubscriber('891012222222300')) #Get added Subscriber's details +print(Open5GS_1.GetSubscriber('891012222222300')) #Get added Subscriber's details -print(NextEPC_1.DeleteSubscriber('891012222222300')) #Delete Subscriber +print(Open5GS_1.DeleteSubscriber('891012222222300')) #Delete Subscriber -Subscriber_List = NextEPC_1.GetSubscribers() +Subscriber_List = Open5GS_1.GetSubscribers() for subscribers in Subscriber_List: print(subscribers['imsi']) diff --git a/misc/netconf.sh b/misc/netconf.sh new file mode 100755 index 000000000..8c690521a --- /dev/null +++ b/misc/netconf.sh @@ -0,0 +1,30 @@ +#!/bin/sh + +SYSTEM=`uname`; + +if [ "$SYSTEM" = "Linux" ]; then + if ! grep "ogstun" /proc/net/dev > /dev/null; then + ip tuntap add name ogstun mode tun + fi + if test "x`sysctl -n net.ipv6.conf.ogstun.disable_ipv6`" = x1; then + echo "net.ipv6.conf.ogstun.disable_ipv6=0" > /etc/sysctl.d/30-open5gs.conf + sysctl -p /etc/sysctl.d/30-open5gs.conf + fi + ip addr del 45.45.0.1/16 dev ogstun 2> /dev/null + ip addr add 45.45.0.1/16 dev ogstun + ip addr del cafe::1/64 dev ogstun 2> /dev/null + ip addr add cafe::1/64 dev ogstun + ip link set ogstun up +else + sysctl -w net.inet.ip.forwarding=1 + ifconfig lo0 alias 127.0.0.2 netmask 255.255.255.255 + ifconfig lo0 alias 127.0.0.3 netmask 255.255.255.255 + ifconfig lo0 alias 127.0.0.4 netmask 255.255.255.255 + ifconfig lo0 alias 127.0.0.5 netmask 255.255.255.255 + if [ "$SYSTEM" = "Darwin" ]; then + if ! test -f /etc/pf.anchors/org.open5gs; then + sudo sh -c "echo 'nat on {en0} from 45.45.0.0/16 to any -> {en0}' > /etc/pf.anchors/org.open5gs" + fi + pfctl -e -f /etc/pf.anchors/org.open5gs + fi +fi diff --git a/build/osc-upload.sh b/misc/osc-upload.sh similarity index 100% rename from build/osc-upload.sh rename to misc/osc-upload.sh diff --git a/support/radvd/README.md b/misc/radvd/README.md similarity index 100% rename from support/radvd/README.md rename to misc/radvd/README.md diff --git a/support/radvd/radvd.conf.example b/misc/radvd/radvd.conf.example similarity index 97% rename from support/radvd/radvd.conf.example rename to misc/radvd/radvd.conf.example index cb795ce50..ae0d8517a 100644 --- a/support/radvd/radvd.conf.example +++ b/misc/radvd/radvd.conf.example @@ -8,7 +8,7 @@ # NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE # -interface pgwtun +interface ogstun { AdvSendAdvert on; @@ -39,7 +39,7 @@ interface pgwtun AdvHomeAgentFlag off; # -# NextEPC pgwtun prefix +# Open5GS ogstun prefix # prefix cafe::/64 { diff --git a/support/valgrind/README.md b/misc/valgrind/README.md similarity index 75% rename from support/valgrind/README.md rename to misc/valgrind/README.md index f05bc3b02..35e63e657 100644 --- a/support/valgrind/README.md +++ b/misc/valgrind/README.md @@ -1,20 +1,20 @@ * Memory Leak Check -user@host ~/Documents/git/nextepc$ \ +user@host ~/Documents/git/open5gs$ \ sudo valgrind --leak-check=full --show-leak-kinds=all \ --suppressions=support/valgrind/mongoc.suppressions \ --suppressions=support/valgrind/freeDiameter.suppressions \ ./test/testepc * Generate Suppression File -user@host ~/Documents/git/nextepc$ \ +user@host ~/Documents/git/open5gs$ \ sudo valgrind --leak-check=full --show-reachable=yes --error-limit=no \ --gen-suppressions=all --log-file=support/valgrind/test.log \ --suppressions=support/valgrind/mongoc.suppressions \ ./test/testepc -user@host ~/Documents/git/nextepc/support/valgrind$ \ +user@host ~/Documents/git/open5gs/support/valgrind$ \ sudo chown user:user test.log -user@host ~/Documents/git/nextepc/support/valgrind$ \ +user@host ~/Documents/git/open5gs/support/valgrind$ \ cat ./test.log | ./parse_suppressions.sh > test.supp diff --git a/support/valgrind/freeDiameter.suppressions b/misc/valgrind/freeDiameter.suppressions similarity index 100% rename from support/valgrind/freeDiameter.suppressions rename to misc/valgrind/freeDiameter.suppressions diff --git a/support/valgrind/mongoc.suppressions b/misc/valgrind/mongoc.suppressions similarity index 100% rename from support/valgrind/mongoc.suppressions rename to misc/valgrind/mongoc.suppressions diff --git a/support/valgrind/parse_suppressions.sh b/misc/valgrind/parse_suppressions.sh similarity index 100% rename from support/valgrind/parse_suppressions.sh rename to misc/valgrind/parse_suppressions.sh diff --git a/src/Makefile.am b/src/Makefile.am deleted file mode 100644 index 9d081dc6a..000000000 --- a/src/Makefile.am +++ /dev/null @@ -1,74 +0,0 @@ -## Process this file with automake to produce Makefile.in. - -SUBDIRS = mme hss sgw pgw pcrf - -noinst_LTLIBRARIES = libmme.la libhss.la libsgw.la libpgw.la libpcrf.la libepc.la - -libmme_la_SOURCES = mme.c -libmme_la_DEPENDENCIES = \ - $(top_srcdir)/src/mme/libmme.la \ - $(NULL) -libmme_la_LIBADD = \ - $(top_srcdir)/src/mme/libmme.la \ - @OGSCRYPT_LIBS@ \ - $(NULL) - -libhss_la_SOURCES = hss.c -libhss_la_DEPENDENCIES = \ - $(top_srcdir)/src/hss/libhss.la \ - $(NULL) -libhss_la_LIBADD = \ - $(top_srcdir)/src/hss/libhss.la \ - @OGSCRYPT_LIBS@ \ - $(NULL) - -libsgw_la_SOURCES = sgw.c -libsgw_la_DEPENDENCIES = \ - $(top_srcdir)/src/sgw/libsgw.la \ - $(NULL) -libsgw_la_LIBADD = \ - $(top_srcdir)/src/sgw/libsgw.la \ - $(NULL) - -libpgw_la_SOURCES = pgw.c -libpgw_la_DEPENDENCIES = \ - $(top_srcdir)/src/pgw/libpgw.la \ - $(NULL) -libpgw_la_LIBADD = \ - $(top_srcdir)/src/pgw/libpgw.la \ - $(NULL) - -libpcrf_la_SOURCES = pcrf.c -libpcrf_la_DEPENDENCIES = \ - $(top_srcdir)/src/pcrf/libpcrf.la \ - $(NULL) -libpcrf_la_LIBADD = \ - $(top_srcdir)/src/pcrf/libpcrf.la \ - $(NULL) - -libepc_la_SOURCES = epc.c -libepc_la_DEPENDENCIES = \ - $(top_srcdir)/src/mme/libmme.la \ - $(top_srcdir)/src/hss/libhss.la \ - $(top_srcdir)/src/sgw/libsgw.la \ - $(top_srcdir)/src/pgw/libpgw.la \ - $(top_srcdir)/src/pcrf/libpcrf.la \ - $(NULL) -libepc_la_LIBADD = \ - $(top_srcdir)/src/mme/libmme.la \ - $(top_srcdir)/src/hss/libhss.la \ - $(top_srcdir)/src/sgw/libsgw.la \ - $(top_srcdir)/src/pgw/libpgw.la \ - $(top_srcdir)/src/pcrf/libpcrf.la \ - @OGSCRYPT_LIBS@ \ - $(NULL) - -AM_CPPFLAGS = \ - @OGSCORE_CFLAGS@ \ - -I$(top_srcdir)/src \ - -I$(top_srcdir)/lib \ - $(NULL) - -AM_CFLAGS = \ - -Wall -Werror \ - $(NULL) diff --git a/src/hss.c b/src/hss.c deleted file mode 100644 index abc0b4b58..000000000 --- a/src/hss.c +++ /dev/null @@ -1,21 +0,0 @@ -#include "ogs-app.h" - -int app_initialize(char **argv) -{ - int rv; - - rv = hss_initialize(); - if (rv != OGS_OK) { - ogs_error("Failed to intialize HSS"); - return rv; - } - ogs_info("HSS initialize...done"); - - return OGS_OK; -} - -void app_terminate(void) -{ - hss_terminate(); - ogs_info("HSS terminate...done"); -} diff --git a/src/hss/Makefile.am b/src/hss/Makefile.am deleted file mode 100644 index 58c7737dc..000000000 --- a/src/hss/Makefile.am +++ /dev/null @@ -1,32 +0,0 @@ -## Process this file with automake to produce Makefile.in. - -noinst_LTLIBRARIES = libhss.la - -libhss_la_SOURCES = \ - hss-auc.h hss-context.h hss-fd-path.h \ - hss-auc.c hss-init.c hss-context.c hss-fd-path.c \ - $(NULL) - -libhss_la_DEPENDENCIES = \ - $(top_srcdir)/lib/diameter/libogsdiameter.la \ - $(top_srcdir)/lib/dbi/libogsdbi.la \ - $(top_srcdir)/lib/app/libogsapp.la \ - $(NULL) - -libhss_la_LIBADD = \ - $(top_srcdir)/lib/diameter/libogsdiameter.la \ - $(top_srcdir)/lib/dbi/libogsdbi.la \ - $(top_srcdir)/lib/app/libogsapp.la \ - $(NULL) - -AM_CPPFLAGS = \ - @OGSCORE_CFLAGS@ \ - -I$(top_srcdir)/lib \ - -I$(top_srcdir)/src \ - -I$(top_srcdir)/lib/freeDiameter/include \ - @MONGOC_CFLAGS@ \ - $(NULL) - -AM_CFLAGS = \ - -Wall -Werror \ - $(NULL) diff --git a/src/hss/app-init.c b/src/hss/app-init.c new file mode 100644 index 000000000..dced7ea54 --- /dev/null +++ b/src/hss/app-init.c @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "ogs-app.h" + +int app_initialize(const char *const argv[]) +{ + int rv; + + rv = hss_initialize(); + if (rv != OGS_OK) { + ogs_error("Failed to intialize HSS"); + return rv; + } + ogs_info("HSS initialize...done"); + + return OGS_OK; +} + +void app_terminate(void) +{ + hss_terminate(); + ogs_info("HSS terminate...done"); +} diff --git a/src/hss/hss-auc.c b/src/hss/hss-auc.c index 38118eb21..70ed2f973 100644 --- a/src/hss/hss-auc.c +++ b/src/hss/hss-auc.c @@ -18,7 +18,7 @@ */ #include "ogs-crypt.h" -#include "ogs-common.h" +#include "ogs-core.h" #include "hss-auc.h" diff --git a/src/hss/hss-context.c b/src/hss/hss-context.c index a256ded8a..a0dea0a6d 100644 --- a/src/hss/hss-context.c +++ b/src/hss/hss-context.c @@ -27,7 +27,7 @@ int __hss_log_domain; static int context_initialized = 0; -hss_context_t* hss_self() +hss_context_t* hss_self(void) { return &self; } @@ -61,7 +61,7 @@ void hss_context_final(void) context_initialized = 0; } -static int hss_context_prepare() +static int hss_context_prepare(void) { self.diam_config->cnf_port = DIAMETER_PORT; self.diam_config->cnf_port_tls = DIAMETER_SECURE_PORT; @@ -69,7 +69,7 @@ static int hss_context_prepare() return OGS_OK; } -static int hss_context_validation() +static int hss_context_validation(void) { if (self.diam_conf_path == NULL && (self.diam_config->cnf_diamid == NULL || @@ -82,7 +82,7 @@ static int hss_context_validation() return OGS_OK; } -int hss_context_parse_config() +int hss_context_parse_config(void) { int rv; yaml_document_t *document = NULL; diff --git a/src/hss/hss-context.h b/src/hss/hss-context.h index c6815bbd1..f1b6fdebc 100644 --- a/src/hss/hss-context.h +++ b/src/hss/hss-context.h @@ -20,7 +20,7 @@ #ifndef HSS_CONTEXT_H #define HSS_CONTEXT_H -#include "diameter/ogs-s6a.h" +#include "ogs-diameter-s6a.h" #include "ogs-app.h" #ifdef __cplusplus diff --git a/src/hss/hss-fd-path.c b/src/hss/hss-fd-path.c index f2189eb14..87e73ec42 100644 --- a/src/hss/hss-fd-path.c +++ b/src/hss/hss-fd-path.c @@ -21,6 +21,7 @@ #include "hss-context.h" #include "hss-auc.h" +#include "hss-fd-path.h" /* handler for fallback cb */ static struct disp_hdl *hdl_s6a_fb = NULL; @@ -209,7 +210,7 @@ static int hss_ogs_diam_s6a_air_cb( struct msg **msg, struct avp *avp, ogs_assert(ret == 0); /* Set the Origin-Host, Origin-Realm, andResult-Code AVPs */ - ret = fd_msg_rescode_set(ans, "DIAMETER_SUCCESS", NULL, NULL, 1); + ret = fd_msg_rescode_set(ans, (char*)"DIAMETER_SUCCESS", NULL, NULL, 1); ogs_assert(ret == 0); /* Set the Auth-Session-State AVP */ @@ -312,7 +313,7 @@ static int hss_ogs_diam_s6a_ulr_cb( struct msg **msg, struct avp *avp, #endif /* Set the Origin-Host, Origin-Realm, andResult-Code AVPs */ - ret = fd_msg_rescode_set(ans, "DIAMETER_SUCCESS", NULL, NULL, 1); + ret = fd_msg_rescode_set(ans, (char*)"DIAMETER_SUCCESS", NULL, NULL, 1); ogs_assert(ret == 0); /* Set the Auth-Session-State AVP */ diff --git a/src/hss/meson.build b/src/hss/meson.build new file mode 100644 index 000000000..9051adc24 --- /dev/null +++ b/src/hss/meson.build @@ -0,0 +1,48 @@ +# Copyright (C) 2019 by Sukchan Lee + +# This file is part of Open5GS. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +libhss_sources = files(''' + hss-auc.h + hss-context.h + hss-fd-path.h + hss-auc.c + hss-init.c + hss-context.c + hss-fd-path.c +'''.split()) + +libhss = static_library('hss', + sources : libhss_sources, + dependencies : [libapp_dep, libcrypt_dep, libdbi_dep, libdiameter_s6a_dep], + install : false) + +libhss_dep = declare_dependency( + link_with : libhss, + dependencies : [libapp_dep, libcrypt_dep, libdbi_dep, libdiameter_s6a_dep]) + +hss_sources = files(''' + app-init.c + ../main.c +'''.split()) + +executable('open5gs-hssd', + sources : hss_sources, + c_args : '-DDEFAULT_CONFIG_FILENAME="@0@/hss.yaml"'.format(open5gs_sysconfdir), + include_directories : srcinc, + dependencies : libhss_dep, + install_rpath : libdir, + install : true) diff --git a/main.c b/src/main.c similarity index 75% rename from main.c rename to src/main.c index 387e92f76..840219c49 100644 --- a/main.c +++ b/src/main.c @@ -1,5 +1,20 @@ -/** - * @file main.c +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ #include @@ -7,12 +22,11 @@ #include #include "ogs-app.h" +#include "version.h" -#define DEFAULT_CONFIG_FILENAME SYSCONF_DIR "nextepc/nextepc.conf" +static const char *version = "Open5GS daemon v" OPEN5GS_VERSION; -static char *version = "NextEPC daemon v" PACKAGE_VERSION; - -static void show_version() +static void show_version(void) { printf("%s\n\n", version); } @@ -33,7 +47,7 @@ static void show_help(const char *name) "\n", name); } -static void show_running_config() +static void show_running_config(void) { ogs_log_print(OGS_LOG_INFO, "%s\n\n", version); @@ -73,14 +87,14 @@ static int check_signal(int signum) return 0; } -static void terminate() +static void terminate(void) { app_terminate(); ogs_app_terminate(); } -int main(int argc, char *argv[]) +int main(int argc, const char *const argv[]) { /************************************************************************** * Starting up process. @@ -98,11 +112,11 @@ int main(int argc, char *argv[]) bool enable_debug; bool enable_trace; } optarg; - char *argv_out[argc]; + const char *argv_out[argc]; memset(&optarg, 0, sizeof(optarg)); - ogs_getopt_init(&options, argv); + ogs_getopt_init(&options, (char**)argv); while ((opt = ogs_getopt(&options, "vhDc:l:e:m:dt")) != -1) { switch (opt) { case 'v': @@ -161,8 +175,8 @@ int main(int argc, char *argv[]) } } - if (optarg.enable_debug) optarg.log_level = "debug"; - if (optarg.enable_trace) optarg.log_level = "trace"; + if (optarg.enable_debug) optarg.log_level = (char*)"debug"; + if (optarg.enable_trace) optarg.log_level = (char*)"trace"; i = 0; argv_out[i++] = argv[0]; @@ -190,7 +204,13 @@ int main(int argc, char *argv[]) ogs_setup_signal_thread(); rv = ogs_app_initialize(DEFAULT_CONFIG_FILENAME, argv_out); - ogs_assert(rv == OGS_OK); + if (rv != OGS_OK) { + if (rv == OGS_RETRY) + return EXIT_SUCCESS; + + ogs_fatal("Open5GS initialization failed. Aborted"); + return OGS_ERROR; + } show_running_config(); @@ -199,14 +219,14 @@ int main(int argc, char *argv[]) if (rv == OGS_RETRY) return EXIT_SUCCESS; - ogs_fatal("NextEPC initialization failed. Aborted"); + ogs_fatal("Open5GS initialization failed. Aborted"); return OGS_ERROR; } atexit(terminate); ogs_signal_thread(check_signal); - ogs_info("NextEPC daemon terminating..."); + ogs_info("Open5GS daemon terminating..."); return OGS_OK; } diff --git a/src/meson.build b/src/meson.build new file mode 100644 index 000000000..7f6eff3e2 --- /dev/null +++ b/src/meson.build @@ -0,0 +1,28 @@ +# Copyright (C) 2019 by Sukchan Lee + +# This file is part of Open5GS. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +srcinc = include_directories('.') + +version_conf = configuration_data() +version_conf.set_quoted('OPEN5GS_VERSION', meson.project_version()) +configure_file(output : 'version.h', configuration : version_conf) + +subdir('mme') +subdir('hss') +subdir('sgw') +subdir('pgw') +subdir('pcrf') diff --git a/src/mme.c b/src/mme.c deleted file mode 100644 index 83e3fc2f0..000000000 --- a/src/mme.c +++ /dev/null @@ -1,25 +0,0 @@ -#include "ogs-sctp.h" -#include "ogs-app.h" - -int app_initialize(char **argv) -{ - int rv; - - ogs_sctp_init(ogs_config()->usrsctp.udp_port); - rv = mme_initialize(); - if (rv != OGS_OK) { - ogs_error("Failed to intialize MME"); - return rv; - } - ogs_info("MME initialize...done"); - - return OGS_OK; -} - -void app_terminate(void) -{ - mme_terminate(); - ogs_sctp_final(); - ogs_info("MME terminate...done"); -} - diff --git a/src/mme/Makefile.am b/src/mme/Makefile.am deleted file mode 100644 index 5dccba1e2..000000000 --- a/src/mme/Makefile.am +++ /dev/null @@ -1,63 +0,0 @@ -## Process this file with automake to produce Makefile.in. - -noinst_LTLIBRARIES = libmme.la - -libmme_la_SOURCES = \ - mme-kdf.h mme-event.h mme-timer.h mme-context.h \ - s1ap-build.h s1ap-handler.h s1ap-path.h \ - sgsap-build.h sgsap-handler.h sgsap-conv.h sgsap-path.h \ - mme-fd-path.h mme-s6a-handler.h \ - nas-security.h nas-path.h \ - emm-handler.h emm-build.h \ - esm-handler.h esm-build.h \ - mme-gtp-path.h mme-s11-build.h mme-s11-handler.h \ - mme-sm.h mme-path.h \ - mme-kdf.c mme-init.c mme-event.c mme-timer.c mme-context.c \ - s1ap-sm.c s1ap-build.c s1ap-handler.c s1ap-path.c \ - sgsap-sm.c sgsap-build.c sgsap-handler.c sgsap-conv.c sgsap-path.c \ - mme-fd-path.c mme-s6a-handler.c \ - nas-security.c nas-path.c \ - emm-sm.c emm-handler.c emm-build.c \ - esm-sm.c esm-handler.c esm-build.c \ - mme-gtp-path.c mme-s11-build.c mme-s11-handler.c \ - mme-sm.c mme-path.c \ - sbc-message.h sbc-handler.h sbc-handler.c \ - $(NULL) - -if WITH_USRSCTP -libmme_la_SOURCES += s1ap-usrpath.c sgsap-usrpath.c -else -libmme_la_SOURCES += s1ap-lkpath.c sgsap-lkpath.c -endif - -libmme_la_DEPENDENCIES = \ - $(top_srcdir)/lib/s1ap/libogss1ap.la \ - $(top_srcdir)/lib/nas/libogsnas.la \ - $(top_srcdir)/lib/diameter/libogsdiameter.la \ - $(top_srcdir)/lib/gtp/libogsgtp.la \ - $(top_srcdir)/lib/sctp/libogssctp.la \ - $(top_srcdir)/lib/app/libogsapp.la \ - $(NULL) - -libmme_la_LIBADD = \ - $(top_srcdir)/lib/s1ap/libogss1ap.la \ - $(top_srcdir)/lib/nas/libogsnas.la \ - $(top_srcdir)/lib/diameter/libogsdiameter.la \ - $(top_srcdir)/lib/gtp/libogsgtp.la \ - $(top_srcdir)/lib/sctp/libogssctp.la \ - $(top_srcdir)/lib/app/libogsapp.la \ - $(NULL) - -AM_CPPFLAGS = \ - @OGSCORE_CFLAGS@ \ - -I$(top_srcdir)/lib \ - -I$(top_srcdir)/src \ - -I$(top_srcdir)/lib/asn1c/common \ - -I$(top_srcdir)/lib/asn1c/s1ap \ - -I$(top_srcdir)/lib/freeDiameter/include \ - @MONGOC_CFLAGS@ \ - $(NULL) - -AM_CFLAGS = \ - -Wall -Werror \ - $(NULL) diff --git a/src/mme/app-init.c b/src/mme/app-init.c new file mode 100644 index 000000000..d53337383 --- /dev/null +++ b/src/mme/app-init.c @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "ogs-sctp.h" +#include "ogs-app.h" + +int app_initialize(const char *const argv[]) +{ + int rv; + + ogs_sctp_init(ogs_config()->usrsctp.udp_port); + rv = mme_initialize(); + if (rv != OGS_OK) { + ogs_error("Failed to intialize MME"); + return rv; + } + ogs_info("MME initialize...done"); + + return OGS_OK; +} + +void app_terminate(void) +{ + mme_terminate(); + ogs_sctp_final(); + ogs_info("MME terminate...done"); +} + diff --git a/src/mme/esm-handler.c b/src/mme/esm-handler.c index 40e7a53cb..407dbb44c 100644 --- a/src/mme/esm-handler.c +++ b/src/mme/esm-handler.c @@ -23,6 +23,7 @@ #include "mme-gtp-path.h" #include "esm-build.h" +#include "esm-handler.h" #undef OGS_LOG_DOMAIN #define OGS_LOG_DOMAIN __esm_log_domain diff --git a/src/mme/meson.build b/src/mme/meson.build new file mode 100644 index 000000000..2b756b255 --- /dev/null +++ b/src/mme/meson.build @@ -0,0 +1,118 @@ +# Copyright (C) 2019 by Sukchan Lee + +# This file is part of Open5GS. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +libmme_sources = files(''' + mme-kdf.h + mme-event.h + mme-timer.h + mme-context.h + s1ap-build.h + s1ap-handler.h + s1ap-path.h + sgsap-build.h + sgsap-handler.h + sgsap-conv.h + sgsap-path.h + mme-fd-path.h + mme-s6a-handler.h + nas-security.h + nas-path.h + emm-handler.h + emm-build.h + esm-handler.h + esm-build.h + mme-gtp-path.h + mme-s11-build.h + mme-s11-handler.h + sbc-message.h + sbc-handler.h + mme-sm.h + mme-path.h + + mme-kdf.c + mme-init.c + mme-event.c + mme-timer.c + mme-context.c + s1ap-sm.c + s1ap-build.c + s1ap-handler.c + s1ap-path.c + sgsap-sm.c + sgsap-build.c + sgsap-handler.c + sgsap-conv.c + sgsap-path.c + mme-fd-path.c + mme-s6a-handler.c + nas-security.c + nas-path.c + emm-sm.c + emm-handler.c + emm-build.c + esm-sm.c + esm-handler.c + esm-build.c + mme-gtp-path.c + mme-s11-build.c + mme-s11-handler.c + mme-sm.c + mme-path.c + sbc-handler.c +'''.split()) + +if libsctp_conf.has('HAVE_USRSCTP') + libmme_sources += files('s1ap-usrpath.c') + libmme_sources += files('sgsap-usrpath.c') +else + libmme_sources += files('s1ap-lkpath.c') + libmme_sources += files('sgsap-lkpath.c') +endif + +libmme = static_library('mme', + sources : libmme_sources, + dependencies : [libapp_dep, + libcrypt_dep, + libsctp_dep, + libs1ap_dep, + libnas_dep, + libdiameter_s6a_dep, + libgtp_dep], + install : false) + +libmme_dep = declare_dependency( + link_with : libmme, + dependencies : [libapp_dep, + libcrypt_dep, + libsctp_dep, + libs1ap_dep, + libnas_dep, + libdiameter_s6a_dep, + libgtp_dep]) + +mme_sources = files(''' + app-init.c + ../main.c +'''.split()) + +executable('open5gs-mmed', + sources : mme_sources, + c_args : '-DDEFAULT_CONFIG_FILENAME="@0@/mme.yaml"'.format(open5gs_sysconfdir), + include_directories : srcinc, + dependencies : libmme_dep, + install_rpath : libdir, + install : true) diff --git a/src/mme/mme-context.c b/src/mme/mme-context.c index abeaa2e70..c0b146907 100644 --- a/src/mme/mme-context.c +++ b/src/mme/mme-context.c @@ -17,9 +17,6 @@ * along with this program. If not, see . */ -#include - -#include #include "ogs-sctp.h" #include "mme-context.h" @@ -151,12 +148,12 @@ void mme_context_final() context_initialized = 0; } -mme_context_t *mme_self() +mme_context_t *mme_self(void) { return &self; } -static int mme_context_prepare() +static int mme_context_prepare(void) { self.relative_capacity = 0xff; @@ -169,7 +166,7 @@ static int mme_context_prepare() return OGS_OK; } -static int mme_context_validation() +static int mme_context_validation(void) { if (self.diam_conf_path == NULL && (self.diam_config->cnf_diamid == NULL || @@ -1649,6 +1646,7 @@ mme_pgw_t *mme_pgw_add(ogs_sockaddr_t *addr) ogs_pool_alloc(&mme_pgw_pool, &pgw); ogs_assert(pgw); + memset(pgw, 0, sizeof *pgw); pgw->node = ogs_gtp_node_new(addr); ogs_assert(pgw->node); @@ -1826,7 +1824,7 @@ mme_csmap_t *mme_csmap_find_by_tai(ogs_tai_t *tai) return NULL; } -mme_csmap_t *mme_csmap_find_by_ogs_nas_lai(ogs_nas_lai_t *lai) +mme_csmap_t *mme_csmap_find_by_nas_lai(ogs_nas_lai_t *lai) { mme_csmap_t *csmap = NULL; ogs_assert(lai); @@ -1849,6 +1847,7 @@ mme_enb_t *mme_enb_add(ogs_sock_t *sock, ogs_sockaddr_t *addr) ogs_pool_alloc(&mme_enb_pool, &enb); ogs_assert(enb); + memset(enb, 0, sizeof *enb); enb->sock = sock; enb->addr = addr; @@ -1873,6 +1872,7 @@ mme_enb_t *mme_enb_add(ogs_sock_t *sock, ogs_sockaddr_t *addr) ogs_hash_set(self.enb_addr_hash, enb->addr, sizeof(ogs_sockaddr_t), enb); e.enb = enb; + e.id = 0; ogs_fsm_create(&enb->sm, s1ap_state_initial, s1ap_state_final); ogs_fsm_init(&enb->sm, &e); @@ -1970,6 +1970,7 @@ enb_ue_t *enb_ue_add(mme_enb_t *enb) ogs_pool_alloc(&enb_ue_pool, &enb_ue); ogs_assert(enb_ue); + memset(enb_ue, 0, sizeof *enb_ue); enb_ue->enb_ue_s1ap_id = INVALID_UE_S1AP_ID; enb_ue->mme_ue_s1ap_id = OGS_NEXT_ID(self.mme_ue_s1ap_id, 1, 0xffffffff); @@ -2131,6 +2132,7 @@ mme_ue_t *mme_ue_add(enb_ue_t *enb_ue) ogs_pool_alloc(&mme_ue_pool, &mme_ue); ogs_assert(mme_ue); + memset(mme_ue, 0, sizeof *mme_ue); ogs_list_init(&mme_ue->sess_list); @@ -2175,17 +2177,23 @@ mme_ue_t *mme_ue_add(enb_ue_t *enb_ue) /* Add All Timers */ mme_ue->t3413.timer = ogs_timer_add( self.timer_mgr, mme_timer_t3413_expire, mme_ue); + mme_ue->t3413.pkbuf = NULL; mme_ue->t3422.timer = ogs_timer_add( self.timer_mgr, mme_timer_t3422_expire, mme_ue); + mme_ue->t3422.pkbuf = NULL; mme_ue->t3450.timer = ogs_timer_add( self.timer_mgr, mme_timer_t3450_expire, mme_ue); + mme_ue->t3450.pkbuf = NULL; mme_ue->t3460.timer = ogs_timer_add( self.timer_mgr, mme_timer_t3460_expire, mme_ue); + mme_ue->t3460.pkbuf = NULL; mme_ue->t3470.timer = ogs_timer_add( self.timer_mgr, mme_timer_t3470_expire, mme_ue); + mme_ue->t3470.pkbuf = NULL; /* Create FSM */ e.mme_ue = mme_ue; + e.id = 0; ogs_fsm_create(&mme_ue->sm, emm_state_initial, emm_state_final); ogs_fsm_init(&mme_ue->sm, &e); @@ -2544,6 +2552,7 @@ mme_sess_t *mme_sess_add(mme_ue_t *mme_ue, uint8_t pti) ogs_pool_alloc(&mme_sess_pool, &sess); ogs_assert(sess); + memset(sess, 0, sizeof *sess); ogs_list_init(&sess->bearer_list); @@ -2665,6 +2674,7 @@ mme_bearer_t *mme_bearer_add(mme_sess_t *sess) ogs_pool_alloc(&mme_bearer_pool, &bearer); ogs_assert(bearer); + memset(bearer, 0, sizeof *bearer); bearer->ebi = OGS_NEXT_ID(mme_ue->ebi, MIN_EPS_BEARER_ID, MAX_EPS_BEARER_ID); @@ -2676,8 +2686,10 @@ mme_bearer_t *mme_bearer_add(mme_sess_t *sess) bearer->t3489.timer = ogs_timer_add( self.timer_mgr, mme_timer_t3489_expire, bearer); + bearer->t3489.pkbuf = NULL; e.bearer = bearer; + e.id = 0; ogs_fsm_create(&bearer->sm, esm_state_initial, esm_state_final); ogs_fsm_init(&bearer->sm, &e); diff --git a/src/mme/mme-context.h b/src/mme/mme-context.h index 3743aa308..899d05e0c 100644 --- a/src/mme/mme-context.h +++ b/src/mme/mme-context.h @@ -23,7 +23,7 @@ #include "ogs-crypt.h" #include "ogs-s1ap.h" -#include "diameter/ogs-s6a.h" +#include "ogs-diameter-s6a.h" #include "ogs-gtp.h" #include "ogs-nas.h" #include "ogs-app.h" @@ -276,8 +276,7 @@ struct enb_ue_s { #define CLEAR_ENB_UE_TIMER(__eNB_UE_TIMER) \ do { \ ogs_timer_stop((__eNB_UE_TIMER).timer); \ - if ((__eNB_UE_TIMER).pkbuf) \ - { \ + if ((__eNB_UE_TIMER).pkbuf) { \ ogs_pkbuf_free((__eNB_UE_TIMER).pkbuf); \ (__eNB_UE_TIMER).pkbuf = NULL; \ } \ @@ -428,8 +427,7 @@ struct mme_ue_s { #define CLEAR_MME_UE_TIMER(__mME_UE_TIMER) \ do { \ ogs_timer_stop((__mME_UE_TIMER).timer); \ - if ((__mME_UE_TIMER).pkbuf) \ - { \ + if ((__mME_UE_TIMER).pkbuf) { \ ogs_pkbuf_free((__mME_UE_TIMER).pkbuf); \ (__mME_UE_TIMER).pkbuf = NULL; \ } \ @@ -645,17 +643,17 @@ int mme_context_parse_config(void); mme_sgw_t *mme_sgw_add(ogs_sockaddr_t *addr); void mme_sgw_remove(mme_sgw_t *sgw); -void mme_sgw_remove_all(); +void mme_sgw_remove_all(void); mme_pgw_t *mme_pgw_add(ogs_sockaddr_t *addr); void mme_pgw_remove(mme_pgw_t *pgw); -void mme_pgw_remove_all(); +void mme_pgw_remove_all(void); ogs_sockaddr_t *mme_pgw_addr_find_by_apn( ogs_list_t *list, int family, char *apn); mme_vlr_t *mme_vlr_add(ogs_sockaddr_t *addr); void mme_vlr_remove(mme_vlr_t *vlr); -void mme_vlr_remove_all(); +void mme_vlr_remove_all(void); ogs_socknode_t *mme_vlr_new_node(mme_vlr_t *vlr); void mme_vlr_free_node(mme_vlr_t *vlr); @@ -677,7 +675,7 @@ int mme_enb_set_enb_id(mme_enb_t *enb, uint32_t enb_id); int mme_enb_sock_type(ogs_sock_t *sock); enb_ue_t *enb_ue_add(mme_enb_t *enb); -unsigned int enb_ue_count(); +unsigned int enb_ue_count(void); void enb_ue_remove(enb_ue_t *enb_ue); void enb_ue_remove_in_enb(mme_enb_t *enb); void enb_ue_switch_to_enb(enb_ue_t *enb_ue, mme_enb_t *new_enb); @@ -689,7 +687,7 @@ enb_ue_t *enb_ue_next_in_enb(enb_ue_t *enb_ue); mme_ue_t *mme_ue_add(enb_ue_t *enb_ue); void mme_ue_remove(mme_ue_t *mme_ue); -void mme_ue_remove_all(); +void mme_ue_remove_all(void); mme_ue_t *mme_ue_find_by_imsi(uint8_t *imsi, int imsi_len); mme_ue_t *mme_ue_find_by_imsi_bcd(char *imsi_bcd); @@ -787,8 +785,8 @@ ogs_pdn_t *mme_default_pdn(mme_ue_t *mme_ue); int mme_find_served_tai(ogs_tai_t *tai); -int mme_m_tmsi_pool_generate(); -mme_m_tmsi_t *mme_m_tmsi_alloc(); +int mme_m_tmsi_pool_generate(void); +mme_m_tmsi_t *mme_m_tmsi_alloc(void); int mme_m_tmsi_free(mme_m_tmsi_t *tmsi); uint8_t mme_selected_int_algorithm(mme_ue_t *mme_ue); diff --git a/src/mme/mme-event.c b/src/mme/mme-event.c index d44b7fd7c..7d59ec9e7 100644 --- a/src/mme/mme-event.c +++ b/src/mme/mme-event.c @@ -17,6 +17,8 @@ * along with this program. If not, see . */ +#include "ogs-sctp.h" + #include "mme-event.h" #include "mme-context.h" diff --git a/src/mme/mme-fd-path.c b/src/mme/mme-fd-path.c index c67e6fdd1..125e1c34c 100644 --- a/src/mme/mme-fd-path.c +++ b/src/mme/mme-fd-path.c @@ -227,7 +227,7 @@ static void mme_s6a_aia_cb(void *data, struct msg **msg) ogs_assert(s6abuf_len < 8192); s6abuf = ogs_pkbuf_alloc(NULL, s6abuf_len); ogs_pkbuf_put(s6abuf, s6abuf_len); - s6a_message = s6abuf->data; + s6a_message = (ogs_diam_s6a_message_t *)s6abuf->data; ogs_assert(s6a_message); /* Set Authentication-Information Command */ @@ -598,7 +598,7 @@ static void mme_s6a_ula_cb(void *data, struct msg **msg) ogs_assert(s6abuf_len < 8192); s6abuf = ogs_pkbuf_alloc(NULL, s6abuf_len); ogs_pkbuf_put(s6abuf, s6abuf_len); - s6a_message = s6abuf->data; + s6a_message = (ogs_diam_s6a_message_t *)s6abuf->data; ogs_assert(s6a_message); /* Set Authentication-Information Command */ diff --git a/src/mme/mme-gtp-path.c b/src/mme/mme-gtp-path.c index e19de46b7..78b6bd7af 100644 --- a/src/mme/mme-gtp-path.c +++ b/src/mme/mme-gtp-path.c @@ -57,7 +57,7 @@ static void _gtpv2_c_recv_cb(short when, ogs_socket_t fd, void *data) } } -int mme_gtp_open() +int mme_gtp_open(void) { int rv; ogs_socknode_t *node = NULL; @@ -101,7 +101,7 @@ int mme_gtp_open() return OGS_OK; } -void mme_gtp_close() +void mme_gtp_close(void) { ogs_socknode_remove_all(&mme_self()->gtpc_list); ogs_socknode_remove_all(&mme_self()->gtpc_list6); diff --git a/src/mme/mme-gtp-path.h b/src/mme/mme-gtp-path.h index 981bde468..e1603c8ef 100644 --- a/src/mme/mme-gtp-path.h +++ b/src/mme/mme-gtp-path.h @@ -26,8 +26,8 @@ extern "C" { #endif -int mme_gtp_open(); -void mme_gtp_close(); +int mme_gtp_open(void); +void mme_gtp_close(void); int mme_gtp_send_create_session_request(mme_sess_t *sess); int mme_gtp_send_modify_bearer_request( diff --git a/src/mme/mme-kdf.c b/src/mme/mme-kdf.c index b52c54cf0..5a126ec29 100644 --- a/src/mme/mme-kdf.c +++ b/src/mme/mme-kdf.c @@ -19,6 +19,8 @@ #include "ogs-crypt.h" +#include "mme-kdf.h" + void mme_kdf_nas(uint8_t algorithm_type_distinguishers, uint8_t algorithm_identity, const uint8_t *kasme, uint8_t *knas) { diff --git a/src/mme/mme-sm.c b/src/mme/mme-sm.c index 76c36a02f..0ff6c40ee 100644 --- a/src/mme/mme-sm.c +++ b/src/mme/mme-sm.c @@ -346,7 +346,7 @@ void mme_state_operational(ogs_fsm_t *s, mme_event_t *e) ogs_assert(mme_ue); s6abuf = e->pkbuf; ogs_assert(s6abuf); - s6a_message = s6abuf->data; + s6a_message = (ogs_diam_s6a_message_t *)s6abuf->data; ogs_assert(s6a_message); if (s6a_message->result_code != ER_DIAMETER_SUCCESS) { diff --git a/src/mme/nas-security.c b/src/mme/nas-security.c index 87d1467c1..742f73946 100644 --- a/src/mme/nas-security.c +++ b/src/mme/nas-security.c @@ -121,7 +121,7 @@ int nas_security_decode(mme_ue_t *mme_ue, if (security_header_type.service_request) { #define SHORT_MAC_SIZE 2 ogs_nas_ksi_and_sequence_number_t *ksi_and_sequence_number = - pkbuf->data + 1; + (ogs_nas_ksi_and_sequence_number_t *)(pkbuf->data + 1); uint8_t original_mac[SHORT_MAC_SIZE]; uint8_t estimated_sequence_number; uint8_t sequence_number_high_3bit; @@ -187,7 +187,7 @@ int nas_security_decode(mme_ue_t *mme_ue, /* NAS Security Header */ ogs_assert(ogs_pkbuf_push(pkbuf, 6)); - h = pkbuf->data; + h = (ogs_nas_security_header_t *)pkbuf->data; /* NAS Security Header.Sequence_Number */ ogs_assert(ogs_pkbuf_pull(pkbuf, 5)); @@ -239,7 +239,7 @@ void nas_mac_calculate(uint8_t algorithm_identity, uint32_t mac32; ogs_assert(knas_int); - ogs_assert(bearer >= 0 && bearer <= 0x1f); + ogs_assert(bearer <= 0x1f); ogs_assert(direction == 0 || direction == 1); ogs_assert(pkbuf); ogs_assert(pkbuf->data); @@ -289,7 +289,7 @@ void nas_encrypt(uint8_t algorithm_identity, uint8_t ivec[16]; ogs_assert(knas_enc); - ogs_assert(bearer >= 0 && bearer <= 0x1f); + ogs_assert(bearer <= 0x1f); ogs_assert(direction == 0 || direction == 1); ogs_assert(pkbuf); ogs_assert(pkbuf->data); diff --git a/src/mme/s1ap-handler.c b/src/mme/s1ap-handler.c index 3d94541ce..84947e14e 100644 --- a/src/mme/s1ap-handler.c +++ b/src/mme/s1ap-handler.c @@ -1973,6 +1973,7 @@ void s1ap_handle_s1_reset( break; case S1AP_Cause_PR_nas: ogs_warn("NAS-Cause[%d]", (int)Cause->choice.nas); + break; default: ogs_warn("Invalid cause group[%d]", Cause->present); break; diff --git a/src/mme/s1ap-path.c b/src/mme/s1ap-path.c index ecfda7dcc..39b126e9a 100644 --- a/src/mme/s1ap-path.c +++ b/src/mme/s1ap-path.c @@ -173,7 +173,7 @@ int s1ap_send_to_nas(enb_ue_t *enb_ue, ogs_pkbuf_reserve(nasbuf, OGS_NAS_HEADROOM); ogs_pkbuf_put_data(nasbuf, nasPdu->buf, nasPdu->size); - sh = nasbuf->data; + sh = (ogs_nas_security_header_t *)nasbuf->data; ogs_assert(sh); memset(&security_header_type, 0, sizeof(nas_security_header_type_t)); @@ -214,7 +214,7 @@ int s1ap_send_to_nas(enb_ue_t *enb_ue, enb_ue->mme_ue, security_header_type, nasbuf) == OGS_OK); } - h = nasbuf->data; + h = (ogs_nas_emm_header_t *)nasbuf->data; ogs_assert(h); if (h->protocol_discriminator == OGS_NAS_PROTOCOL_DISCRIMINATOR_EMM) { int rv; diff --git a/src/mme/s1ap-path.h b/src/mme/s1ap-path.h index 23505259a..cb2d2afe7 100644 --- a/src/mme/s1ap-path.h +++ b/src/mme/s1ap-path.h @@ -31,8 +31,8 @@ extern "C" { #define s1ap_event_push mme_sctp_event_push -int s1ap_open(); -void s1ap_close(); +int s1ap_open(void); +void s1ap_close(void); ogs_sock_t *s1ap_server(ogs_socknode_t *node); void s1ap_recv_handler(short when, ogs_socket_t fd, void *data); diff --git a/src/mme/s1ap-usrpath.c b/src/mme/s1ap-usrpath.c index 0d88f8986..b6249e6f8 100644 --- a/src/mme/s1ap-usrpath.c +++ b/src/mme/s1ap-usrpath.c @@ -50,7 +50,7 @@ ogs_sock_t *s1ap_server(ogs_socknode_t *node) void s1ap_recv_handler(short when, ogs_socket_t fd, void *data) { - /* At this point, nextepc does not use SOCK_STREAM in libusrsctp */ + /* At this point, open5gs does not use SOCK_STREAM in libusrsctp */ ogs_assert_if_reached(); } diff --git a/src/mme/sbc-message.h b/src/mme/sbc-message.h index 5c24f6d22..8e2c18a90 100644 --- a/src/mme/sbc-message.h +++ b/src/mme/sbc-message.h @@ -20,7 +20,7 @@ #ifndef SBC_MESSAGE_H #define SBC_MESSAGE_H -#include "ogs-common.h" +#include "ogs-core.h" #ifdef __cplusplus extern "C" { diff --git a/src/mme/sgsap-conv.h b/src/mme/sgsap-conv.h index 4ca2f4d28..1d1c22281 100644 --- a/src/mme/sgsap-conv.h +++ b/src/mme/sgsap-conv.h @@ -20,7 +20,7 @@ #ifndef SGSAP_CONV_H #define SGSAP_CONV_H -#include "ogs-common.h" +#include "ogs-core.h" #ifdef __cplusplus extern "C" { diff --git a/src/mme/sgsap-handler.c b/src/mme/sgsap-handler.c index f487699a3..4fdbac0a3 100644 --- a/src/mme/sgsap-handler.c +++ b/src/mme/sgsap-handler.c @@ -20,6 +20,7 @@ #include "sgsap-types.h" #include "sgsap-build.h" #include "sgsap-path.h" +#include "sgsap-handler.h" #include "mme-sm.h" #include "mme-context.h" diff --git a/src/mme/sgsap-path.c b/src/mme/sgsap-path.c index daa300bde..7158bac39 100644 --- a/src/mme/sgsap-path.c +++ b/src/mme/sgsap-path.c @@ -32,7 +32,9 @@ int sgsap_open() ogs_list_for_each(&mme_self()->vlr_list, vlr) { mme_event_t e; + e.vlr = vlr; + e.id = 0; ogs_fsm_create(&vlr->sm, sgsap_state_initial, sgsap_state_final); ogs_fsm_init(&vlr->sm, &e); diff --git a/src/pcrf.c b/src/pcrf.c deleted file mode 100644 index 3d676d67f..000000000 --- a/src/pcrf.c +++ /dev/null @@ -1,21 +0,0 @@ -#include "ogs-app.h" - -int app_initialize(char **argv) -{ - int rv; - - rv = pcrf_initialize(); - if (rv != OGS_OK) { - ogs_error("Failed to intialize PCRF"); - return rv; - } - ogs_info("PCRF initialize...done"); - - return OGS_OK; -} - -void app_terminate(void) -{ - pcrf_terminate(); - ogs_info("PCRF terminate...done"); -} diff --git a/src/pcrf/Makefile.am b/src/pcrf/Makefile.am deleted file mode 100644 index 0fbd9e7f0..000000000 --- a/src/pcrf/Makefile.am +++ /dev/null @@ -1,31 +0,0 @@ -## Process this file with automake to produce Makefile.in. - -noinst_LTLIBRARIES = libpcrf.la - -libpcrf_la_SOURCES = \ - pcrf-context.h pcrf-fd-path.h \ - pcrf-init.c pcrf-context.c pcrf-fd-path.c pcrf-gx-path.c pcrf-rx-path.c \ - $(NULL) - -libpcrf_la_DEPENDENCIES = \ - $(top_srcdir)/lib/diameter/libogsdiameter.la \ - $(top_srcdir)/lib/dbi/libogsdbi.la \ - $(top_srcdir)/lib/app/libogsapp.la \ - $(NULL) - -libpcrf_la_LIBADD = \ - $(top_srcdir)/lib/diameter/libogsdiameter.la \ - $(top_srcdir)/lib/dbi/libogsdbi.la \ - $(top_srcdir)/lib/app/libogsapp.la \ - $(NULL) - -AM_CPPFLAGS = \ - @OGSCORE_CFLAGS@ \ - -I$(top_srcdir)/lib \ - -I$(top_srcdir)/src \ - -I$(top_srcdir)/lib/freeDiameter/include \ - @MONGOC_CFLAGS@ \ - $(NULL) - -AM_CFLAGS = \ - -Wall -Werror diff --git a/src/pcrf/app-init.c b/src/pcrf/app-init.c new file mode 100644 index 000000000..f7ca67ca6 --- /dev/null +++ b/src/pcrf/app-init.c @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "ogs-app.h" + +int app_initialize(const char *const argv[]) +{ + int rv; + + rv = pcrf_initialize(); + if (rv != OGS_OK) { + ogs_error("Failed to intialize PCRF"); + return rv; + } + ogs_info("PCRF initialize...done"); + + return OGS_OK; +} + +void app_terminate(void) +{ + pcrf_terminate(); + ogs_info("PCRF terminate...done"); +} diff --git a/src/pcrf/meson.build b/src/pcrf/meson.build new file mode 100644 index 000000000..e265e8730 --- /dev/null +++ b/src/pcrf/meson.build @@ -0,0 +1,55 @@ +# Copyright (C) 2019 by Sukchan Lee + +# This file is part of Open5GS. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +libpcrf_sources = files(''' + pcrf-context.h + pcrf-fd-path.h + + pcrf-init.c + pcrf-context.c + pcrf-fd-path.c + pcrf-gx-path.c + pcrf-rx-path.c +'''.split()) + +libpcrf = static_library('pcrf', + sources : libpcrf_sources, + dependencies : [libapp_dep, + libdbi_dep, + libdiameter_rx_dep, + libdiameter_gx_dep], + install : false) + +libpcrf_dep = declare_dependency( + link_with : libpcrf, + dependencies : [libapp_dep, + libdbi_dep, + libdiameter_rx_dep, + libdiameter_gx_dep]) + +pcrf_sources = files(''' + app-init.c + ../main.c +'''.split()) + +executable('open5gs-pcrfd', + sources : pcrf_sources, + c_args : '-DDEFAULT_CONFIG_FILENAME="@0@/pcrf.yaml"'.format(open5gs_sysconfdir), + include_directories : srcinc, + dependencies : libpcrf_dep, + install_rpath : libdir, + install : true) diff --git a/src/pcrf/pcrf-context.c b/src/pcrf/pcrf-context.c index e850807af..2bd74c971 100644 --- a/src/pcrf/pcrf-context.c +++ b/src/pcrf/pcrf-context.c @@ -27,7 +27,7 @@ int __pcrf_log_domain; static int context_initialized = 0; -pcrf_context_t* pcrf_self() +pcrf_context_t *pcrf_self(void) { return &self; } @@ -67,7 +67,7 @@ void pcrf_context_final(void) context_initialized = 0; } -static int pcrf_context_prepare() +static int pcrf_context_prepare(void) { self.diam_config->cnf_port = DIAMETER_PORT; self.diam_config->cnf_port_tls = DIAMETER_SECURE_PORT; @@ -75,7 +75,7 @@ static int pcrf_context_prepare() return OGS_OK; } -static int pcrf_context_validation() +static int pcrf_context_validation(void) { if (self.diam_conf_path == NULL && (self.diam_config->cnf_diamid == NULL || @@ -89,7 +89,7 @@ static int pcrf_context_validation() return OGS_OK; } -int pcrf_context_parse_config() +int pcrf_context_parse_config(void) { int rv; yaml_document_t *document = NULL; diff --git a/src/pcrf/pcrf-context.h b/src/pcrf/pcrf-context.h index 2a393d5d6..fbfe8a9dd 100644 --- a/src/pcrf/pcrf-context.h +++ b/src/pcrf/pcrf-context.h @@ -20,8 +20,8 @@ #ifndef PCRF_CONTEXT_H #define PCRF_CONTEXT_H -#include "diameter/ogs-gx.h" -#include "diameter/ogs-rx.h" +#include "ogs-diameter-gx.h" +#include "ogs-diameter-rx.h" #include "ogs-app.h" #ifdef __cplusplus diff --git a/src/pcrf/pcrf-gx-path.c b/src/pcrf/pcrf-gx-path.c index 5bd0a19e0..3bf8c9c95 100644 --- a/src/pcrf/pcrf-gx-path.c +++ b/src/pcrf/pcrf-gx-path.c @@ -543,7 +543,7 @@ static int pcrf_gx_ccr_cb( struct msg **msg, struct avp *avp, } /* Set the Origin-Host, Origin-Realm, andResult-Code AVPs */ - ret = fd_msg_rescode_set(ans, "DIAMETER_SUCCESS", NULL, NULL, 1); + ret = fd_msg_rescode_set(ans, (char *)"DIAMETER_SUCCESS", NULL, NULL, 1); ogs_assert(ret == 0); if (cc_request_type != OGS_DIAM_GX_CC_REQUEST_TYPE_TERMINATION_REQUEST) { @@ -574,15 +574,15 @@ out: /* Set the Result-Code */ if (result_code == OGS_DIAM_AVP_UNSUPPORTED) { ret = fd_msg_rescode_set(ans, - "DIAMETER_AVP_UNSUPPORTED", NULL, NULL, 1); + (char *)"DIAMETER_AVP_UNSUPPORTED", NULL, NULL, 1); ogs_assert(ret == 0); } else if (result_code == OGS_DIAM_UNKNOWN_SESSION_ID) { ret = fd_msg_rescode_set(ans, - "DIAMETER_UNKNOWN_SESSION_ID", NULL, NULL, 1); + (char *)"DIAMETER_UNKNOWN_SESSION_ID", NULL, NULL, 1); ogs_assert(ret == 0); } else if (result_code == OGS_DIAM_MISSING_AVP) { ret = fd_msg_rescode_set(ans, - "DIAMETER_MISSING_AVP", NULL, NULL, 1); + (char *)"DIAMETER_MISSING_AVP", NULL, NULL, 1); ogs_assert(ret == 0); } else { ret = ogs_diam_message_experimental_rescode_set(ans, result_code); diff --git a/src/pcrf/pcrf-rx-path.c b/src/pcrf/pcrf-rx-path.c index 4f7d0be85..daae00732 100644 --- a/src/pcrf/pcrf-rx-path.c +++ b/src/pcrf/pcrf-rx-path.c @@ -341,7 +341,7 @@ static int pcrf_rx_aar_cb( struct msg **msg, struct avp *avp, ogs_assert(ret == 0); /* Set the Origin-Host, Origin-Realm, andResult-Code AVPs */ - ret = fd_msg_rescode_set(ans, "DIAMETER_SUCCESS", NULL, NULL, 1); + ret = fd_msg_rescode_set(ans, (char *)"DIAMETER_SUCCESS", NULL, NULL, 1); ogs_assert(ret == 0); /* Store this value in the session */ @@ -367,15 +367,15 @@ static int pcrf_rx_aar_cb( struct msg **msg, struct avp *avp, out: if (result_code == OGS_DIAM_AVP_UNSUPPORTED) { ret = fd_msg_rescode_set(ans, - "DIAMETER_AVP_UNSUPPORTED", NULL, NULL, 1); + (char *)"DIAMETER_AVP_UNSUPPORTED", NULL, NULL, 1); ogs_assert(ret == 0); } else if (result_code == OGS_DIAM_UNKNOWN_SESSION_ID) { ret = fd_msg_rescode_set(ans, - "DIAMETER_UNKNOWN_SESSION_ID", NULL, NULL, 1); + (char *)"DIAMETER_UNKNOWN_SESSION_ID", NULL, NULL, 1); ogs_assert(ret == 0); } else if (result_code == OGS_DIAM_MISSING_AVP) { ret = fd_msg_rescode_set(ans, - "DIAMETER_MISSING_AVP", NULL, NULL, 1); + (char *)"DIAMETER_MISSING_AVP", NULL, NULL, 1); ogs_assert(ret == 0); } else { ret = ogs_diam_message_experimental_rescode_set(ans, result_code); @@ -663,7 +663,7 @@ static int pcrf_rx_str_cb( struct msg **msg, struct avp *avp, } /* Set the Origin-Host, Origin-Realm, andResult-Code AVPs */ - ret = fd_msg_rescode_set(ans, "DIAMETER_SUCCESS", NULL, NULL, 1); + ret = fd_msg_rescode_set(ans, (char *)"DIAMETER_SUCCESS", NULL, NULL, 1); ogs_assert(ret == 0); /* Send the answer */ @@ -685,19 +685,19 @@ static int pcrf_rx_str_cb( struct msg **msg, struct avp *avp, out: if (result_code == OGS_DIAM_AVP_UNSUPPORTED) { ret = fd_msg_rescode_set(ans, - "DIAMETER_AVP_UNSUPPORTED", NULL, NULL, 1); + (char *)"DIAMETER_AVP_UNSUPPORTED", NULL, NULL, 1); ogs_assert(ret == 0); } else if (result_code == OGS_DIAM_UNKNOWN_SESSION_ID) { ret = fd_msg_rescode_set(ans, - "DIAMETER_UNKNOWN_SESSION_ID", NULL, NULL, 1); + (char *)"DIAMETER_UNKNOWN_SESSION_ID", NULL, NULL, 1); ogs_assert(ret == 0); } else if (result_code == OGS_DIAM_MISSING_AVP) { ret = fd_msg_rescode_set(ans, - "DIAMETER_MISSING_AVP", NULL, NULL, 1); + (char *)"DIAMETER_MISSING_AVP", NULL, NULL, 1); ogs_assert(ret == 0); } else { ret = fd_msg_rescode_set(ans, - "DIAMETER_MISSING_AVP", NULL, NULL, 1); + (char *)"DIAMETER_MISSING_AVP", NULL, NULL, 1); ogs_assert(ret == 0); } diff --git a/src/pgw.c b/src/pgw.c deleted file mode 100644 index 478822f47..000000000 --- a/src/pgw.c +++ /dev/null @@ -1,21 +0,0 @@ -#include "ogs-app.h" - -int app_initialize(char **argv) -{ - int rv; - - rv = pgw_initialize(); - if (rv != OGS_OK) { - ogs_error("Failed to intialize PGW"); - return rv; - } - ogs_info("PGW initialize...done"); - - return OGS_OK; -} - -void app_terminate(void) -{ - pgw_terminate(); - ogs_info("PGW terminate...done"); -} diff --git a/src/pgw/Makefile.am b/src/pgw/Makefile.am deleted file mode 100644 index 10340eef1..000000000 --- a/src/pgw/Makefile.am +++ /dev/null @@ -1,43 +0,0 @@ -## Process this file with automake to produce Makefile.in. - -SUBDIRS = ipfw - -noinst_LTLIBRARIES = libpgw.la - -libpgw_la_SOURCES = \ - ogs-tun.h ogs-tun.c \ - pgw-ipfw.h \ - pgw-event.h pgw-context.h pgw-sm.h \ - pgw-gtp-path.h pgw-s5c-build.h pgw-s5c-handler.h \ - pgw-fd-path.h pgw-gx-handler.h \ - pgw-ipfw.c \ - pgw-init.c pgw-event.c pgw-context.c pgw-sm.c \ - pgw-gtp-path.c pgw-s5c-build.c pgw-s5c-handler.c \ - pgw-fd-path.c pgw-gx-handler.c \ - $(NULL) - -libpgw_la_DEPENDENCIES = \ - $(top_srcdir)/lib/diameter/libogsdiameter.la \ - $(top_srcdir)/lib/gtp/libogsgtp.la \ - $(top_srcdir)/lib/app/libogsapp.la \ - $(top_srcdir)/src/pgw/ipfw/libipfw.la \ - $(NULL) - -libpgw_la_LIBADD = \ - $(top_srcdir)/lib/diameter/libogsdiameter.la \ - $(top_srcdir)/lib/gtp/libogsgtp.la \ - $(top_srcdir)/lib/app/libogsapp.la \ - $(top_srcdir)/src/pgw/ipfw/libipfw.la \ - $(NULL) - -AM_CPPFLAGS = \ - @OGSCORE_CFLAGS@ \ - -I$(top_srcdir)/lib \ - -I$(top_srcdir)/src \ - -I$(top_srcdir)/lib/freeDiameter/include \ - @MONGOC_CFLAGS@ \ - $(NULL) - -AM_CFLAGS = \ - -Wall -Werror \ - $(NULL) diff --git a/src/pgw/app-init.c b/src/pgw/app-init.c new file mode 100644 index 000000000..a274e0386 --- /dev/null +++ b/src/pgw/app-init.c @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "ogs-app.h" + +int app_initialize(const char *const argv[]) +{ + int rv; + + rv = pgw_initialize(); + if (rv != OGS_OK) { + ogs_error("Failed to intialize PGW"); + return rv; + } + ogs_info("PGW initialize...done"); + + return OGS_OK; +} + +void app_terminate(void) +{ + pgw_terminate(); + ogs_info("PGW terminate...done"); +} diff --git a/src/pgw/ipfw/Makefile.am b/src/pgw/ipfw/Makefile.am deleted file mode 100644 index 3ee55a5fb..000000000 --- a/src/pgw/ipfw/Makefile.am +++ /dev/null @@ -1,37 +0,0 @@ -## Process this file with automake to produce Makefile.in. - -noinst_LTLIBRARIES = libipfw.la - -EXTRA_DIST = \ - objs/include_e/timeconv.h \ - objs/include_e/net/if_var.h \ - objs/include_e/netinet/ip_fw.h \ - objs/include_e/netinet/ip_dummynet.h \ - objs/include_e/sys/sockio.h \ - objs/include_e/libutil.h \ - objs/include_e/timeconv.h \ - objs/include_e/net/if_var.h \ - objs/include_e/netinet/ip_fw.h \ - objs/include_e/netinet/ip_dummynet.h \ - objs/include_e/sys/sockio.h \ - objs/include_e/libutil.h \ - $(NULL) - -libipfw_la_SOURCES = \ - ipfw2.h ipfw2.c dummynet.c ipv6.c tables.c \ - expand_number.c humanize_number.c \ - glue.h glue.c missing.h \ - $(NULL) - -AM_CPPFLAGS = \ - -I$(top_srcdir)/src/pgw/ipfw/objs/include_e \ - -include glue.h \ - -D_DEFAULT_SOURCE -D_BSD_SOURCE \ - -DUSERSPACE -D__BSD_VISIBLE -DNEED_STRTONUM -DNEED_ROUNDUP2 \ - @IPFW_CPPFLAGS@ \ - $(NULL) - -AM_CFLAGS = \ - -Wall -Werror -Wno-shift-negative-value \ - -Wno-unused-but-set-variable -Wno-unknown-warning-option \ - $(NULL) diff --git a/src/pgw/ipfw/meson.build b/src/pgw/ipfw/meson.build new file mode 100644 index 000000000..fe029a445 --- /dev/null +++ b/src/pgw/ipfw/meson.build @@ -0,0 +1,77 @@ +# Copyright (C) 2019 by Sukchan Lee + +# This file is part of Open5GS. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +libipfw_sources = files(''' + objs/include_e/timeconv.h + objs/include_e/net/if_var.h + objs/include_e/netinet/ip_fw.h + objs/include_e/netinet/ip_dummynet.h + objs/include_e/sys/sockio.h + objs/include_e/libutil.h + objs/include_e/timeconv.h + objs/include_e/net/if_var.h + objs/include_e/netinet/ip_fw.h + objs/include_e/netinet/ip_dummynet.h + objs/include_e/sys/sockio.h + objs/include_e/libutil.h + + ipfw2.h + glue.h + missing.h + + ipfw2.c + dummynet.c + ipv6.c + tables.c + expand_number.c + humanize_number.c + glue.c +'''.split()) + +ipfwinc = include_directories('objs/include_e') + +ipfw_cc_flags = ['-D_DEFAULT_SOURCE', '-D_BSD_SOURCE', '-DUSERSPACE', + '-D__BSD_VISIBLE', '-DNEED_STRTONUM', '-DNEED_ROUNDUP2' ] + +if host_system == 'linux' + ipfw_cc_flags += ['-DNEED_SYSCTLBYNAME', '-DNEED_SIN_LEN'] +endif + +if cc.get_id() == 'gcc' or cc.get_id() == 'clang' + ipfw_cc_flags += cc.get_supported_arguments([ + '-Wno-shift-negative-value', + '-Wno-unused-but-set-variable', + '-Wno-unknown-warning-option', + + '-Wno-missing-prototypes', + '-Wno-missing-declarations', + '-Wno-discarded-qualifiers', + '-Wno-redundant-decls', + '-Wno-shift-overflow', + '-Wno-float-equal', + '-Wno-implicit-fallthrough', + '-Wno-incompatible-pointer-types-discards-qualifiers', + '-Wno-format-nonliteral', + '-Wno-cpp', + ]) +endif + +libipfw = static_library('ipfw', + sources : [libipfw_sources], + c_args : ['-include', 'glue.h', ipfw_cc_flags], + include_directories : [ipfwinc], + install : false) diff --git a/src/pgw/meson.build b/src/pgw/meson.build new file mode 100644 index 000000000..258d818ee --- /dev/null +++ b/src/pgw/meson.build @@ -0,0 +1,90 @@ +# Copyright (C) 2019 by Sukchan Lee + +# This file is part of Open5GS. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +subdir('ipfw') + +pgw_conf = configuration_data() + +pgw_headers = (''' + net/if.h + netinet/ip.h + netinet/ip6.h + netinet/ip_icmp.h + netinet/icmp6.h +'''.split()) + +foreach h : pgw_headers + if cc.has_header(h) + define = 'HAVE_' + h.underscorify().to_upper() + pgw_conf.set(define, 1) + endif +endforeach + +if have_func_kqueue + pgw_conf.set('HAVE_KQUEUE', 1) +endif + +configure_file(output : 'pgw-config.h', configuration : pgw_conf) + +libpgw_sources = files(''' + ogs-tun.h + ogs-tun.c + + pgw-ipfw.h + pgw-event.h + pgw-context.h + pgw-sm.h + pgw-gtp-path.h + pgw-s5c-build.h + pgw-s5c-handler.h + pgw-fd-path.h + pgw-gx-handler.h + + pgw-ipfw.c + pgw-init.c + pgw-event.c + pgw-context.c + pgw-sm.c + pgw-gtp-path.c + pgw-s5c-build.c + pgw-s5c-handler.c + pgw-fd-path.c + pgw-gx-handler.c +'''.split()) + +libpgw = static_library('pgw', + sources : libpgw_sources, + link_with : libipfw, + dependencies : [libapp_dep, libdiameter_gx_dep, libgtp_dep], + install : false) + +libpgw_dep = declare_dependency( + link_with : libpgw, + dependencies : [libapp_dep, libdiameter_gx_dep, libgtp_dep]) + +pgw_sources = files(''' + app-init.c + ../main.c +'''.split()) + +executable('open5gs-pgwd', + sources : pgw_sources, + c_args : '-DDEFAULT_CONFIG_FILENAME="@0@/pgw.yaml"'.format(open5gs_sysconfdir), + include_directories : srcinc, + dependencies : libpgw_dep, + install_rpath : libdir, + install : true) diff --git a/src/pgw/ogs-tun.c b/src/pgw/ogs-tun.c index 78041db95..ceecfc571 100644 --- a/src/pgw/ogs-tun.c +++ b/src/pgw/ogs-tun.c @@ -17,7 +17,6 @@ * along with this program. If not, see . */ -#include "ogs-common.h" #include "ogs-tun.h" #undef OGS_LOG_DOMAIN @@ -43,7 +42,7 @@ ogs_socket_t ogs_tun_open(char *ifname, int len, int is_tap) { ogs_socket_t fd = INVALID_SOCKET; #if defined(__linux__) - char *dev = "/dev/net/tun"; + const char *dev = "/dev/net/tun"; int rc; struct ifreq ifr; int flags = IFF_NO_PI; diff --git a/src/pgw/pgw-context.c b/src/pgw/pgw-context.c index e26d6ac39..9f89dcae7 100644 --- a/src/pgw/pgw-context.c +++ b/src/pgw/pgw-context.c @@ -17,9 +17,6 @@ * along with this program. If not, see . */ -#include -#include - #include "pgw-context.h" static pgw_context_t self; @@ -37,7 +34,7 @@ static OGS_POOL(pgw_pf_pool, pgw_pf_t); static int context_initiaized = 0; -void pgw_context_init() +void pgw_context_init(void) { ogs_assert(context_initiaized == 0); @@ -76,7 +73,7 @@ void pgw_context_init() context_initiaized = 1; } -void pgw_context_final() +void pgw_context_final(void) { ogs_assert(context_initiaized == 1); @@ -99,24 +96,24 @@ void pgw_context_final() context_initiaized = 0; } -pgw_context_t *pgw_self() +pgw_context_t *pgw_self(void) { return &self; } -static int pgw_context_prepare() +static int pgw_context_prepare(void) { self.gtpc_port = OGS_GTPV2_C_UDP_PORT; self.gtpu_port = OGS_GTPV1_U_UDP_PORT; self.diam_config->cnf_port = DIAMETER_PORT; self.diam_config->cnf_port_tls = DIAMETER_SECURE_PORT; - self.tun_ifname = "pgwtun"; + self.tun_ifname = "ogstun"; return OGS_OK; } -static int pgw_context_validation() +static int pgw_context_validation(void) { if (self.diam_conf_path == NULL && (self.diam_config->cnf_diamid == NULL || @@ -146,7 +143,7 @@ static int pgw_context_validation() return OGS_OK; } -int pgw_context_parse_config() +int pgw_context_parse_config(void) { int rv; yaml_document_t *document = NULL; @@ -711,6 +708,8 @@ pgw_sess_t *pgw_sess_add( ogs_pool_alloc(&pgw_sess_pool, &sess); ogs_assert(sess); + memset(sess, 0, sizeof *sess); + sess->index = ogs_pool_index(&pgw_sess_pool, sess); ogs_assert(sess->index > 0 && sess->index <= ogs_config()->pool.sess); @@ -792,7 +791,7 @@ int pgw_sess_remove(pgw_sess_t *sess) return OGS_OK; } -void pgw_sess_remove_all() +void pgw_sess_remove_all(void) { pgw_sess_t *sess = NULL, *next = NULL;; @@ -892,6 +891,8 @@ pgw_bearer_t *pgw_bearer_add(pgw_sess_t *sess) ogs_pool_alloc(&pgw_bearer_pool, &bearer); ogs_assert(bearer); + memset(bearer, 0, sizeof *bearer); + bearer->index = ogs_pool_index(&pgw_bearer_pool, bearer); ogs_assert(bearer->index > 0 && bearer->index <= ogs_config()->pool.bearer); @@ -1044,6 +1045,7 @@ pgw_pf_t *pgw_pf_add(pgw_bearer_t *bearer, uint32_t precedence) ogs_pool_alloc(&pgw_pf_pool, &pf); ogs_assert(pf); + memset(pf, 0, sizeof *pf); pf->identifier = OGS_NEXT_ID(bearer->pf_identifier, 1, 15); pf->bearer = bearer; @@ -1098,7 +1100,7 @@ pgw_pf_t *pgw_pf_next(pgw_pf_t *pf) return ogs_list_next(pf); } -int pgw_ue_pool_generate() +int pgw_ue_pool_generate(void) { int j; pgw_subnet_t *subnet = NULL; @@ -1271,7 +1273,7 @@ int pgw_dev_remove(pgw_dev_t *dev) return OGS_OK; } -void pgw_dev_remove_all() +void pgw_dev_remove_all(void) { pgw_dev_t *dev = NULL, *next_dev = NULL; @@ -1296,7 +1298,7 @@ pgw_dev_t *pgw_dev_find_by_ifname(const char *ifname) return OGS_OK; } -pgw_dev_t *pgw_dev_first() +pgw_dev_t *pgw_dev_first(void) { return ogs_list_first(&self.dev_list); } @@ -1361,7 +1363,7 @@ int pgw_subnet_remove(pgw_subnet_t *subnet) return OGS_OK; } -void pgw_subnet_remove_all() +void pgw_subnet_remove_all(void) { pgw_subnet_t *subnet = NULL, *next_subnet = NULL; @@ -1369,7 +1371,7 @@ void pgw_subnet_remove_all() pgw_subnet_remove(subnet); } -pgw_subnet_t *pgw_subnet_first() +pgw_subnet_t *pgw_subnet_first(void) { return ogs_list_first(&self.subnet_list); } diff --git a/src/pgw/pgw-context.h b/src/pgw/pgw-context.h index 07a0ff9a3..2cd61352a 100644 --- a/src/pgw/pgw-context.h +++ b/src/pgw/pgw-context.h @@ -20,10 +20,14 @@ #ifndef PGW_CONTEXT_H #define PGW_CONTEXT_H +#include "pgw-config.h" + +#if HAVE_NET_IF_H #include +#endif #include "ogs-gtp.h" -#include "diameter/ogs-gx.h" +#include "ogs-diameter-gx.h" #include "ogs-app.h" #ifdef __cplusplus @@ -44,7 +48,7 @@ typedef struct pgw_context_s { uint32_t gtpc_port; /* Default: PGW GTP-C local port */ uint32_t gtpu_port; /* Default: PGW GTP-U local port */ - const char *tun_ifname; /* Default:: pgwtun */ + const char *tun_ifname; /* Default: ogstun */ ogs_list_t gtpc_list; /* PGW GTPC IPv4 Server List */ ogs_list_t gtpc_list6; /* PGW GTPC IPv6 Server List */ @@ -222,7 +226,7 @@ pgw_sess_t *pgw_sess_add( uint8_t *imsi, int imsi_len, char *apn, uint8_t pdn_type, uint8_t ebi); int pgw_sess_remove(pgw_sess_t *sess); -void pgw_sess_remove_all(); +void pgw_sess_remove_all(void); pgw_sess_t *pgw_sess_find(uint32_t index); pgw_sess_t *pgw_sess_find_by_teid(uint32_t teid); @@ -249,15 +253,15 @@ pgw_pf_t *pgw_pf_find_by_id(pgw_bearer_t *pgw_bearer, uint8_t id); pgw_pf_t *pgw_pf_first(pgw_bearer_t *bearer); pgw_pf_t *pgw_pf_next(pgw_pf_t *pf); -int pgw_ue_pool_generate(); +int pgw_ue_pool_generate(void); pgw_ue_ip_t *pgw_ue_ip_alloc(int family, const char *apn); int pgw_ue_ip_free(pgw_ue_ip_t *ip); pgw_dev_t *pgw_dev_add(const char *ifname); int pgw_dev_remove(pgw_dev_t *dev); -void pgw_dev_remove_all(); +void pgw_dev_remove_all(void); pgw_dev_t *pgw_dev_find_by_ifname(const char *ifname); -pgw_dev_t *pgw_dev_first(); +pgw_dev_t *pgw_dev_first(void); pgw_dev_t *pgw_dev_next(pgw_dev_t *dev); pgw_subnet_t *pgw_subnet_add( @@ -265,8 +269,8 @@ pgw_subnet_t *pgw_subnet_add( const char *apn, const char *ifname); pgw_subnet_t *pgw_subnet_next(pgw_subnet_t *subnet); int pgw_subnet_remove(pgw_subnet_t *subnet); -void pgw_subnet_remove_all(); -pgw_subnet_t *pgw_subnet_first(); +void pgw_subnet_remove_all(void); +pgw_subnet_t *pgw_subnet_first(void); pgw_subnet_t *gw_subnet_next(pgw_subnet_t *subnet); #ifdef __cplusplus diff --git a/src/pgw/pgw-fd-path.c b/src/pgw/pgw-fd-path.c index 299a1e577..e86b6930c 100644 --- a/src/pgw/pgw-fd-path.c +++ b/src/pgw/pgw-fd-path.c @@ -79,7 +79,7 @@ void pgw_gx_send_ccr(pgw_sess_t *sess, ogs_gtp_xact_t *xact, ogs_assert(sess); ogs_assert(sess->ipv4 || sess->ipv6); ogs_assert(gtpbuf); - message = gtpbuf->data; + message = (ogs_gtp_message_t *)gtpbuf->data; ogs_assert(message); ogs_debug("[Credit-Control-Request]"); @@ -519,7 +519,7 @@ static void pgw_gx_cca_cb(void *data, struct msg **msg) ogs_assert(gxbuf_len < 8192); gxbuf = ogs_pkbuf_alloc(NULL, gxbuf_len); ogs_pkbuf_put(gxbuf, gxbuf_len); - gx_message = gxbuf->data; + gx_message = (ogs_diam_gx_message_t *)gxbuf->data; ogs_assert(gx_message); /* Set Credit Control Command */ @@ -833,7 +833,7 @@ static int pgw_gx_rar_cb( struct msg **msg, struct avp *avp, ogs_assert(gxbuf_len < 8192); gxbuf = ogs_pkbuf_alloc(NULL, gxbuf_len); ogs_pkbuf_put(gxbuf, gxbuf_len); - gx_message = gxbuf->data; + gx_message = (ogs_diam_gx_message_t *)gxbuf->data; ogs_assert(gx_message); /* Set Credit Control Command */ @@ -969,7 +969,7 @@ static int pgw_gx_rar_cb( struct msg **msg, struct avp *avp, ogs_assert(ret == 0); /* Set the Origin-Host, Origin-Realm, andResult-Code AVPs */ - ret = fd_msg_rescode_set(ans, "DIAMETER_SUCCESS", NULL, NULL, 1); + ret = fd_msg_rescode_set(ans, (char *)"DIAMETER_SUCCESS", NULL, NULL, 1); ogs_assert(ret == 0); /* Store this value in the session */ @@ -993,7 +993,7 @@ static int pgw_gx_rar_cb( struct msg **msg, struct avp *avp, out: if (result_code == OGS_DIAM_UNKNOWN_SESSION_ID) { ret = fd_msg_rescode_set(ans, - "DIAMETER_UNKNOWN_SESSION_ID", NULL, NULL, 1); + (char *)"DIAMETER_UNKNOWN_SESSION_ID", NULL, NULL, 1); ogs_assert(ret == 0); } else { ret = ogs_diam_message_experimental_rescode_set(ans, result_code); diff --git a/src/pgw/pgw-gtp-path.c b/src/pgw/pgw-gtp-path.c index a704cba29..2a6ded10f 100644 --- a/src/pgw/pgw-gtp-path.c +++ b/src/pgw/pgw-gtp-path.c @@ -150,7 +150,7 @@ static void _gtpv1_u_recv_cb(short when, ogs_socket_t fd, void *data) ogs_assert(pkbuf); ogs_assert(pkbuf->len); - gtp_h = pkbuf->data; + gtp_h = (ogs_gtp_header_t *)pkbuf->data; if (gtp_h->flags & OGS_GTPU_FLAGS_S) len += 4; teid = ntohl(gtp_h->teid); @@ -159,7 +159,7 @@ static void _gtpv1_u_recv_cb(short when, ogs_socket_t fd, void *data) /* Remove GTP header and send packets to TUN interface */ ogs_assert(ogs_pkbuf_pull(pkbuf, len)); - ip_h = pkbuf->data; + ip_h = (struct ip *)pkbuf->data; ogs_assert(ip_h); bearer = pgw_bearer_find_by_pgw_s5u_teid(teid); @@ -200,7 +200,7 @@ cleanup: ogs_pkbuf_free(pkbuf); } -int pgw_gtp_open() +int pgw_gtp_open(void) { pgw_dev_t *dev = NULL; pgw_subnet_t *subnet = NULL; @@ -254,12 +254,12 @@ int pgw_gtp_open() /* NOTE : tun device can be created via following command. * - * $ sudo ip tuntap add name pgwtun mode tun + * $ sudo ip tuntap add name ogstun mode tun * * Also, before running pgw, assign the one IP from IP pool of UE - * to pgwtun. The IP should not be assigned to UE + * to ogstun. The IP should not be assigned to UE * - * $ sudo ifconfig pgwtun 45.45.0.1/16 up + * $ sudo ifconfig ogstun 45.45.0.1/16 up * */ @@ -278,10 +278,10 @@ int pgw_gtp_open() /* * On Linux, it is possible to create a persistent tun/tap - * interface which will continue to exist even if nextepc quit, + * interface which will continue to exist even if open5gs quit, * although this is normally not required. * It can be useful to set up a tun/tap interface owned - * by a non-root user, so nextepc can be started without + * by a non-root user, so open5gs can be started without * needing any root privileges at all. */ @@ -304,7 +304,7 @@ int pgw_gtp_open() return OGS_OK; } -void pgw_gtp_close() +void pgw_gtp_close(void) { pgw_dev_t *dev = NULL; diff --git a/src/pgw/pgw-gtp-path.h b/src/pgw/pgw-gtp-path.h index ab40c21e5..481752e33 100644 --- a/src/pgw/pgw-gtp-path.h +++ b/src/pgw/pgw-gtp-path.h @@ -27,8 +27,8 @@ extern "C" { #endif -int pgw_gtp_open(); -void pgw_gtp_close(); +int pgw_gtp_open(void); +void pgw_gtp_close(void); #ifdef __cplusplus } diff --git a/src/pgw/pgw-gx-handler.c b/src/pgw/pgw-gx-handler.c index 13464c61d..e5783e78e 100644 --- a/src/pgw/pgw-gx-handler.c +++ b/src/pgw/pgw-gx-handler.c @@ -20,6 +20,7 @@ #include "pgw-context.h" #include "pgw-gtp-path.h" #include "pgw-s5c-build.h" +#include "pgw-gx-handler.h" #include "pgw-ipfw.h" static int bearer_binding(pgw_sess_t *sess, ogs_diam_gx_message_t *gx_message); diff --git a/src/pgw/pgw-ipfw.c b/src/pgw/pgw-ipfw.c index 3a54f3f34..b13e175b7 100644 --- a/src/pgw/pgw-ipfw.c +++ b/src/pgw/pgw-ipfw.c @@ -26,7 +26,7 @@ #include #include -#include "pgw-context.h" +#include "pgw-ipfw.h" #include "ipfw/ipfw2.h" #include "ipfw/objs/include_e/netinet/ip_fw.h" diff --git a/src/pgw/pgw-s5c-build.c b/src/pgw/pgw-s5c-build.c index 3bc6bb05f..c50359856 100644 --- a/src/pgw/pgw-s5c-build.c +++ b/src/pgw/pgw-s5c-build.c @@ -18,6 +18,7 @@ */ #include "pgw-context.h" +#include "pgw-s5c-build.h" #include "ipfw/ipfw2.h" diff --git a/src/pgw/pgw-sm.c b/src/pgw/pgw-sm.c index edc53e84f..888036ad7 100644 --- a/src/pgw/pgw-sm.c +++ b/src/pgw/pgw-sm.c @@ -77,7 +77,7 @@ void pgw_state_operational(ogs_fsm_t *s, pgw_event_t *e) copybuf_len = sizeof(ogs_gtp_message_t); copybuf = ogs_pkbuf_alloc(NULL, copybuf_len); ogs_pkbuf_put(copybuf, copybuf_len); - message = copybuf->data; + message = (ogs_gtp_message_t *)copybuf->data; ogs_assert(message); rv = ogs_gtp_parse_msg(message, recvbuf); @@ -141,7 +141,7 @@ void pgw_state_operational(ogs_fsm_t *s, pgw_event_t *e) gxbuf = e->gxbuf; ogs_assert(gxbuf); - gx_message = gxbuf->data; + gx_message = (ogs_diam_gx_message_t *)gxbuf->data; ogs_assert(gx_message); sess_index = e->sess_index; @@ -157,7 +157,7 @@ void pgw_state_operational(ogs_fsm_t *s, pgw_event_t *e) gtpbuf = e->gtpbuf; ogs_assert(gtpbuf); - message = gtpbuf->data; + message = (ogs_gtp_message_t *)gtpbuf->data; if (gx_message->result_code == ER_DIAMETER_SUCCESS) { switch(gx_message->cc_request_type) { diff --git a/src/sgw.c b/src/sgw.c deleted file mode 100644 index 0eb5a8f72..000000000 --- a/src/sgw.c +++ /dev/null @@ -1,21 +0,0 @@ -#include "ogs-app.h" - -int app_initialize(char **argv) -{ - int rv; - - rv = sgw_initialize(); - if (rv != OGS_OK) { - ogs_error("Failed to intialize SGW"); - return rv; - } - ogs_info("SGW initialize...done"); - - return OGS_OK; -} - -void app_terminate(void) -{ - sgw_terminate(); - ogs_info("SGW terminate...done"); -} diff --git a/src/sgw/Makefile.am b/src/sgw/Makefile.am deleted file mode 100644 index 141906002..000000000 --- a/src/sgw/Makefile.am +++ /dev/null @@ -1,32 +0,0 @@ -## Process this file with automake to produce Makefile.in. - -noinst_LTLIBRARIES = libsgw.la - -SUBDIR = gtp - -libsgw_la_SOURCES = \ - sgw-event.h sgw-context.h \ - sgw-gtp-path.h sgw-sm.h sgw-s11-handler.h sgw-s5c-handler.h \ - sgw-init.c sgw-event.c sgw-context.c \ - sgw-gtp-path.c sgw-sm.c sgw-s11-handler.c sgw-s5c-handler.c \ - $(NULL) - -libsgw_la_DEPENDENCIES = \ - $(top_srcdir)/lib/gtp/libogsgtp.la \ - $(top_srcdir)/lib/app/libogsapp.la \ - $(NULL) - -libsgw_la_LIBADD = \ - $(top_srcdir)/lib/gtp/libogsgtp.la \ - $(top_srcdir)/lib/app/libogsapp.la \ - $(NULL) - -AM_CPPFLAGS = \ - @OGSCORE_CFLAGS@ \ - -I$(top_srcdir)/lib \ - -I$(top_srcdir)/src \ - @MONGOC_CFLAGS@ \ - $(NULL) - -AM_CFLAGS = \ - -Wall -Werror diff --git a/src/sgw/app-init.c b/src/sgw/app-init.c new file mode 100644 index 000000000..3ba16d16f --- /dev/null +++ b/src/sgw/app-init.c @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "ogs-app.h" + +int app_initialize(const char *const argv[]) +{ + int rv; + + rv = sgw_initialize(); + if (rv != OGS_OK) { + ogs_error("Failed to intialize SGW"); + return rv; + } + ogs_info("SGW initialize...done"); + + return OGS_OK; +} + +void app_terminate(void) +{ + sgw_terminate(); + ogs_info("SGW terminate...done"); +} diff --git a/src/sgw/meson.build b/src/sgw/meson.build new file mode 100644 index 000000000..21121f672 --- /dev/null +++ b/src/sgw/meson.build @@ -0,0 +1,55 @@ +# Copyright (C) 2019 by Sukchan Lee + +# This file is part of Open5GS. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +libsgw_sources = files(''' + sgw-event.h + sgw-context.h + sgw-gtp-path.h + sgw-sm.h + sgw-s11-handler.h + sgw-s5c-handler.h + + sgw-init.c + sgw-event.c + sgw-context.c + sgw-gtp-path.c + sgw-sm.c + sgw-s11-handler.c + sgw-s5c-handler.c +'''.split()) + +libsgw = static_library('sgw', + sources : libsgw_sources, + dependencies : [libapp_dep, libgtp_dep], + install : false) + +libsgw_dep = declare_dependency( + link_with : libsgw, + dependencies : [libapp_dep, libgtp_dep]) + +sgw_sources = files(''' + app-init.c + ../main.c +'''.split()) + +executable('open5gs-sgwd', + sources : sgw_sources, + c_args : '-DDEFAULT_CONFIG_FILENAME="@0@/sgw.yaml"'.format(open5gs_sysconfdir), + include_directories : srcinc, + dependencies : libsgw_dep, + install_rpath : libdir, + install : true) diff --git a/src/sgw/sgw-context.c b/src/sgw/sgw-context.c index 3202a28c8..27d26c3b7 100644 --- a/src/sgw/sgw-context.c +++ b/src/sgw/sgw-context.c @@ -17,7 +17,6 @@ * along with this program. If not, see . */ -#include #include #include "sgw-context.h" @@ -33,7 +32,7 @@ static OGS_POOL(sgw_tunnel_pool, sgw_tunnel_t); static int context_initialized = 0; -void sgw_context_init() +void sgw_context_init(void) { ogs_assert(context_initialized == 0); @@ -63,7 +62,7 @@ void sgw_context_init() context_initialized = 1; } -void sgw_context_final() +void sgw_context_final(void) { ogs_assert(context_initialized == 1); @@ -83,12 +82,12 @@ void sgw_context_final() context_initialized = 0; } -sgw_context_t *sgw_self() +sgw_context_t *sgw_self(void) { return &self; } -static int sgw_context_prepare() +static int sgw_context_prepare(void) { self.gtpc_port = OGS_GTPV2_C_UDP_PORT; self.gtpu_port = OGS_GTPV1_U_UDP_PORT; @@ -96,7 +95,7 @@ static int sgw_context_prepare() return OGS_OK; } -static int sgw_context_validation() +static int sgw_context_validation(void) { if (ogs_list_empty(&self.gtpc_list) && ogs_list_empty(&self.gtpc_list6)) { @@ -113,7 +112,7 @@ static int sgw_context_validation() return OGS_OK; } -int sgw_context_parse_config() +int sgw_context_parse_config(void) { int rv; yaml_document_t *document = NULL; @@ -451,6 +450,7 @@ sgw_ue_t *sgw_ue_add(uint8_t *imsi, int imsi_len) ogs_pool_alloc(&sgw_ue_pool, &sgw_ue); ogs_assert(sgw_ue); + memset(sgw_ue, 0, sizeof *sgw_ue); sgw_ue->sgw_s11_teid = ogs_pool_index(&sgw_ue_pool, sgw_ue); ogs_assert(sgw_ue->sgw_s11_teid > 0 && @@ -481,7 +481,7 @@ int sgw_ue_remove(sgw_ue_t *sgw_ue) return OGS_OK; } -void sgw_ue_remove_all() +void sgw_ue_remove_all(void) { sgw_ue_t *sgw_ue = NULL, *next = NULL;; @@ -504,6 +504,7 @@ sgw_sess_t *sgw_sess_add(sgw_ue_t *sgw_ue, char *apn, uint8_t ebi) ogs_pool_alloc(&sgw_sess_pool, &sess); ogs_assert(sess); + memset(sess, 0, sizeof *sess); sess->sgw_s5c_teid = SGW_S5C_INDEX_TO_TEID(ogs_pool_index(&sgw_sess_pool, sess)); @@ -600,6 +601,7 @@ sgw_bearer_t* sgw_bearer_add(sgw_sess_t *sess) ogs_pool_alloc(&sgw_bearer_pool, &bearer); ogs_assert(bearer); + memset(bearer, 0, sizeof *bearer); bearer->sgw_ue = sgw_ue; bearer->sess = sess; @@ -708,6 +710,7 @@ sgw_tunnel_t *sgw_tunnel_add(sgw_bearer_t *bearer, uint8_t interface_type) ogs_pool_alloc(&sgw_tunnel_pool, &tunnel); ogs_assert(tunnel); + memset(tunnel, 0, sizeof *tunnel); tunnel->interface_type = interface_type; tunnel->local_teid = ogs_pool_index(&sgw_tunnel_pool, tunnel); diff --git a/src/sgw/sgw-context.h b/src/sgw/sgw-context.h index 1ff635a88..70a501af8 100644 --- a/src/sgw/sgw-context.h +++ b/src/sgw/sgw-context.h @@ -157,7 +157,7 @@ sgw_ue_t *sgw_ue_find_by_teid(uint32_t teid); sgw_ue_t *sgw_ue_add(uint8_t *imsi, int imsi_len); int sgw_ue_remove(sgw_ue_t *sgw_ue); -void sgw_ue_remove_all(); +void sgw_ue_remove_all(void); sgw_sess_t *sgw_sess_add(sgw_ue_t *sgw_ue, char *apn, uint8_t ebi); int sgw_sess_remove(sgw_sess_t *sess); diff --git a/src/sgw/sgw-gtp-path.c b/src/sgw/sgw-gtp-path.c index 3ec5eb176..d865da647 100644 --- a/src/sgw/sgw-gtp-path.c +++ b/src/sgw/sgw-gtp-path.c @@ -252,7 +252,7 @@ static void _gtpv1_u_recv_cb(short when, ogs_socket_t fd, void *data) return; } -int sgw_gtp_open() +int sgw_gtp_open(void) { ogs_socknode_t *node = NULL; ogs_sock_t *sock = NULL; @@ -311,7 +311,7 @@ int sgw_gtp_open() return OGS_OK; } -void sgw_gtp_close() +void sgw_gtp_close(void) { ogs_socknode_remove_all(&sgw_self()->gtpc_list); ogs_socknode_remove_all(&sgw_self()->gtpc_list6); diff --git a/src/sgw/sgw-gtp-path.h b/src/sgw/sgw-gtp-path.h index fbaa70561..43afdb679 100644 --- a/src/sgw/sgw-gtp-path.h +++ b/src/sgw/sgw-gtp-path.h @@ -24,8 +24,8 @@ extern "C" { #endif -int sgw_gtp_open(); -void sgw_gtp_close(); +int sgw_gtp_open(void); +void sgw_gtp_close(void); int sgw_gtp_send_end_marker(sgw_tunnel_t *s1u_tunnel); diff --git a/lib/freeDiameter/.hg_archival.txt b/subprojects/freediameter/.hg_archival.txt similarity index 100% rename from lib/freeDiameter/.hg_archival.txt rename to subprojects/freediameter/.hg_archival.txt diff --git a/lib/freeDiameter/.hgignore b/subprojects/freediameter/.hgignore similarity index 100% rename from lib/freeDiameter/.hgignore rename to subprojects/freediameter/.hgignore diff --git a/lib/freeDiameter/.hgtags b/subprojects/freediameter/.hgtags similarity index 100% rename from lib/freeDiameter/.hgtags rename to subprojects/freediameter/.hgtags diff --git a/lib/freeDiameter/CMakeLists.txt b/subprojects/freediameter/CMakeLists.txt similarity index 100% rename from lib/freeDiameter/CMakeLists.txt rename to subprojects/freediameter/CMakeLists.txt diff --git a/lib/freeDiameter/CTestConfig.cmake b/subprojects/freediameter/CTestConfig.cmake similarity index 100% rename from lib/freeDiameter/CTestConfig.cmake rename to subprojects/freediameter/CTestConfig.cmake diff --git a/lib/freeDiameter/INSTALL b/subprojects/freediameter/INSTALL similarity index 100% rename from lib/freeDiameter/INSTALL rename to subprojects/freediameter/INSTALL diff --git a/lib/freeDiameter/INSTALL.Fedora b/subprojects/freediameter/INSTALL.Fedora similarity index 100% rename from lib/freeDiameter/INSTALL.Fedora rename to subprojects/freediameter/INSTALL.Fedora diff --git a/lib/freeDiameter/INSTALL.FreeBSD b/subprojects/freediameter/INSTALL.FreeBSD similarity index 100% rename from lib/freeDiameter/INSTALL.FreeBSD rename to subprojects/freediameter/INSTALL.FreeBSD diff --git a/lib/freeDiameter/INSTALL.OSX b/subprojects/freediameter/INSTALL.OSX similarity index 100% rename from lib/freeDiameter/INSTALL.OSX rename to subprojects/freediameter/INSTALL.OSX diff --git a/lib/freeDiameter/INSTALL.OpenSUSE b/subprojects/freediameter/INSTALL.OpenSUSE similarity index 100% rename from lib/freeDiameter/INSTALL.OpenSUSE rename to subprojects/freediameter/INSTALL.OpenSUSE diff --git a/lib/freeDiameter/INSTALL.OpenWRT b/subprojects/freediameter/INSTALL.OpenWRT similarity index 100% rename from lib/freeDiameter/INSTALL.OpenWRT rename to subprojects/freediameter/INSTALL.OpenWRT diff --git a/lib/freeDiameter/INSTALL.Ubuntu b/subprojects/freediameter/INSTALL.Ubuntu similarity index 100% rename from lib/freeDiameter/INSTALL.Ubuntu rename to subprojects/freediameter/INSTALL.Ubuntu diff --git a/lib/freeDiameter/INSTALL.pkgsrc b/subprojects/freediameter/INSTALL.pkgsrc similarity index 100% rename from lib/freeDiameter/INSTALL.pkgsrc rename to subprojects/freediameter/INSTALL.pkgsrc diff --git a/lib/freeDiameter/LICENSE b/subprojects/freediameter/LICENSE similarity index 100% rename from lib/freeDiameter/LICENSE rename to subprojects/freediameter/LICENSE diff --git a/lib/freeDiameter/NEWS b/subprojects/freediameter/NEWS similarity index 100% rename from lib/freeDiameter/NEWS rename to subprojects/freediameter/NEWS diff --git a/lib/freeDiameter/README b/subprojects/freediameter/README similarity index 100% rename from lib/freeDiameter/README rename to subprojects/freediameter/README diff --git a/lib/freeDiameter/cmake/Modules/CMakeUserUseBison.cmake b/subprojects/freediameter/cmake/Modules/CMakeUserUseBison.cmake similarity index 100% rename from lib/freeDiameter/cmake/Modules/CMakeUserUseBison.cmake rename to subprojects/freediameter/cmake/Modules/CMakeUserUseBison.cmake diff --git a/lib/freeDiameter/cmake/Modules/CMakeUserUseFlex.cmake b/subprojects/freediameter/cmake/Modules/CMakeUserUseFlex.cmake similarity index 100% rename from lib/freeDiameter/cmake/Modules/CMakeUserUseFlex.cmake rename to subprojects/freediameter/cmake/Modules/CMakeUserUseFlex.cmake diff --git a/lib/freeDiameter/cmake/Modules/FindGcrypt.cmake b/subprojects/freediameter/cmake/Modules/FindGcrypt.cmake similarity index 100% rename from lib/freeDiameter/cmake/Modules/FindGcrypt.cmake rename to subprojects/freediameter/cmake/Modules/FindGcrypt.cmake diff --git a/lib/freeDiameter/cmake/Modules/FindGnuTLS.cmake b/subprojects/freediameter/cmake/Modules/FindGnuTLS.cmake similarity index 100% rename from lib/freeDiameter/cmake/Modules/FindGnuTLS.cmake rename to subprojects/freediameter/cmake/Modules/FindGnuTLS.cmake diff --git a/lib/freeDiameter/cmake/Modules/FindIDNA.cmake b/subprojects/freediameter/cmake/Modules/FindIDNA.cmake similarity index 100% rename from lib/freeDiameter/cmake/Modules/FindIDNA.cmake rename to subprojects/freediameter/cmake/Modules/FindIDNA.cmake diff --git a/lib/freeDiameter/cmake/Modules/FindLibXml2.cmake b/subprojects/freediameter/cmake/Modules/FindLibXml2.cmake similarity index 100% rename from lib/freeDiameter/cmake/Modules/FindLibXml2.cmake rename to subprojects/freediameter/cmake/Modules/FindLibXml2.cmake diff --git a/lib/freeDiameter/cmake/Modules/FindMySQL.cmake b/subprojects/freediameter/cmake/Modules/FindMySQL.cmake similarity index 100% rename from lib/freeDiameter/cmake/Modules/FindMySQL.cmake rename to subprojects/freediameter/cmake/Modules/FindMySQL.cmake diff --git a/lib/freeDiameter/cmake/Modules/FindPostgreSQL.cmake b/subprojects/freediameter/cmake/Modules/FindPostgreSQL.cmake similarity index 100% rename from lib/freeDiameter/cmake/Modules/FindPostgreSQL.cmake rename to subprojects/freediameter/cmake/Modules/FindPostgreSQL.cmake diff --git a/lib/freeDiameter/cmake/Modules/FindSCTP.cmake b/subprojects/freediameter/cmake/Modules/FindSCTP.cmake similarity index 100% rename from lib/freeDiameter/cmake/Modules/FindSCTP.cmake rename to subprojects/freediameter/cmake/Modules/FindSCTP.cmake diff --git a/lib/freeDiameter/cmake/Modules/GetVersionWithHg.cmake b/subprojects/freediameter/cmake/Modules/GetVersionWithHg.cmake similarity index 100% rename from lib/freeDiameter/cmake/Modules/GetVersionWithHg.cmake rename to subprojects/freediameter/cmake/Modules/GetVersionWithHg.cmake diff --git a/lib/freeDiameter/contrib/CxDx/README b/subprojects/freediameter/contrib/CxDx/README similarity index 100% rename from lib/freeDiameter/contrib/CxDx/README rename to subprojects/freediameter/contrib/CxDx/README diff --git a/lib/freeDiameter/contrib/CxDx/dict_cxdx.c b/subprojects/freediameter/contrib/CxDx/dict_cxdx.c similarity index 100% rename from lib/freeDiameter/contrib/CxDx/dict_cxdx.c rename to subprojects/freediameter/contrib/CxDx/dict_cxdx.c diff --git a/lib/freeDiameter/contrib/CxDx/dict_cxdx.xml b/subprojects/freediameter/contrib/CxDx/dict_cxdx.xml similarity index 100% rename from lib/freeDiameter/contrib/CxDx/dict_cxdx.xml rename to subprojects/freediameter/contrib/CxDx/dict_cxdx.xml diff --git a/lib/freeDiameter/contrib/OpenWRT/HOWTO b/subprojects/freediameter/contrib/OpenWRT/HOWTO similarity index 100% rename from lib/freeDiameter/contrib/OpenWRT/HOWTO rename to subprojects/freediameter/contrib/OpenWRT/HOWTO diff --git a/lib/freeDiameter/contrib/OpenWRT/others/D-Link_DIR-330_netconfig.patch b/subprojects/freediameter/contrib/OpenWRT/others/D-Link_DIR-330_netconfig.patch similarity index 100% rename from lib/freeDiameter/contrib/OpenWRT/others/D-Link_DIR-330_netconfig.patch rename to subprojects/freediameter/contrib/OpenWRT/others/D-Link_DIR-330_netconfig.patch diff --git a/lib/freeDiameter/contrib/OpenWRT/packages/freeDiameter/patches/01-freeDiameter-OpenWRT.patch b/subprojects/freediameter/contrib/OpenWRT/packages/freeDiameter/patches/01-freeDiameter-OpenWRT.patch similarity index 100% rename from lib/freeDiameter/contrib/OpenWRT/packages/freeDiameter/patches/01-freeDiameter-OpenWRT.patch rename to subprojects/freediameter/contrib/OpenWRT/packages/freeDiameter/patches/01-freeDiameter-OpenWRT.patch diff --git a/lib/freeDiameter/contrib/OpenWRT/test_required/testcase.c b/subprojects/freediameter/contrib/OpenWRT/test_required/testcase.c similarity index 100% rename from lib/freeDiameter/contrib/OpenWRT/test_required/testcase.c rename to subprojects/freediameter/contrib/OpenWRT/test_required/testcase.c diff --git a/lib/freeDiameter/contrib/PKI/ca_script/openssl.cnf b/subprojects/freediameter/contrib/PKI/ca_script/openssl.cnf similarity index 100% rename from lib/freeDiameter/contrib/PKI/ca_script/openssl.cnf rename to subprojects/freediameter/contrib/PKI/ca_script/openssl.cnf diff --git a/lib/freeDiameter/contrib/PKI/ca_script2/openssl.cnf b/subprojects/freediameter/contrib/PKI/ca_script2/openssl.cnf similarity index 100% rename from lib/freeDiameter/contrib/PKI/ca_script2/openssl.cnf rename to subprojects/freediameter/contrib/PKI/ca_script2/openssl.cnf diff --git a/lib/freeDiameter/contrib/PKI/phpki-0.82.patch b/subprojects/freediameter/contrib/PKI/phpki-0.82.patch similarity index 100% rename from lib/freeDiameter/contrib/PKI/phpki-0.82.patch rename to subprojects/freediameter/contrib/PKI/phpki-0.82.patch diff --git a/lib/freeDiameter/contrib/README b/subprojects/freediameter/contrib/README similarity index 100% rename from lib/freeDiameter/contrib/README rename to subprojects/freediameter/contrib/README diff --git a/lib/freeDiameter/contrib/RPM/build_rpm.txt b/subprojects/freediameter/contrib/RPM/build_rpm.txt similarity index 100% rename from lib/freeDiameter/contrib/RPM/build_rpm.txt rename to subprojects/freediameter/contrib/RPM/build_rpm.txt diff --git a/lib/freeDiameter/contrib/RPM/freeDiameter.spec b/subprojects/freediameter/contrib/RPM/freeDiameter.spec similarity index 100% rename from lib/freeDiameter/contrib/RPM/freeDiameter.spec rename to subprojects/freediameter/contrib/RPM/freeDiameter.spec diff --git a/lib/freeDiameter/contrib/app_acct_tools/README b/subprojects/freediameter/contrib/app_acct_tools/README similarity index 100% rename from lib/freeDiameter/contrib/app_acct_tools/README rename to subprojects/freediameter/contrib/app_acct_tools/README diff --git a/lib/freeDiameter/contrib/app_acct_tools/database.sql b/subprojects/freediameter/contrib/app_acct_tools/database.sql similarity index 100% rename from lib/freeDiameter/contrib/app_acct_tools/database.sql rename to subprojects/freediameter/contrib/app_acct_tools/database.sql diff --git a/lib/freeDiameter/contrib/app_acct_tools/display_results.php b/subprojects/freediameter/contrib/app_acct_tools/display_results.php similarity index 100% rename from lib/freeDiameter/contrib/app_acct_tools/display_results.php rename to subprojects/freediameter/contrib/app_acct_tools/display_results.php diff --git a/lib/freeDiameter/contrib/app_acct_tools/display_self.php b/subprojects/freediameter/contrib/app_acct_tools/display_self.php similarity index 100% rename from lib/freeDiameter/contrib/app_acct_tools/display_self.php rename to subprojects/freediameter/contrib/app_acct_tools/display_self.php diff --git a/lib/freeDiameter/contrib/app_acct_tools/display_stats.php b/subprojects/freediameter/contrib/app_acct_tools/display_stats.php similarity index 100% rename from lib/freeDiameter/contrib/app_acct_tools/display_stats.php rename to subprojects/freediameter/contrib/app_acct_tools/display_stats.php diff --git a/lib/freeDiameter/contrib/app_acct_tools/process_records.php b/subprojects/freediameter/contrib/app_acct_tools/process_records.php similarity index 100% rename from lib/freeDiameter/contrib/app_acct_tools/process_records.php rename to subprojects/freediameter/contrib/app_acct_tools/process_records.php diff --git a/lib/freeDiameter/contrib/app_acct_tools/purge_to_file.php b/subprojects/freediameter/contrib/app_acct_tools/purge_to_file.php similarity index 100% rename from lib/freeDiameter/contrib/app_acct_tools/purge_to_file.php rename to subprojects/freediameter/contrib/app_acct_tools/purge_to_file.php diff --git a/lib/freeDiameter/contrib/debian/changelog b/subprojects/freediameter/contrib/debian/changelog similarity index 100% rename from lib/freeDiameter/contrib/debian/changelog rename to subprojects/freediameter/contrib/debian/changelog diff --git a/lib/freeDiameter/contrib/debian/compat b/subprojects/freediameter/contrib/debian/compat similarity index 100% rename from lib/freeDiameter/contrib/debian/compat rename to subprojects/freediameter/contrib/debian/compat diff --git a/lib/freeDiameter/contrib/debian/control b/subprojects/freediameter/contrib/debian/control similarity index 100% rename from lib/freeDiameter/contrib/debian/control rename to subprojects/freediameter/contrib/debian/control diff --git a/lib/freeDiameter/contrib/debian/copyright b/subprojects/freediameter/contrib/debian/copyright similarity index 100% rename from lib/freeDiameter/contrib/debian/copyright rename to subprojects/freediameter/contrib/debian/copyright diff --git a/lib/freeDiameter/contrib/debian/dirs b/subprojects/freediameter/contrib/debian/dirs similarity index 100% rename from lib/freeDiameter/contrib/debian/dirs rename to subprojects/freediameter/contrib/debian/dirs diff --git a/lib/freeDiameter/contrib/debian/docs b/subprojects/freediameter/contrib/debian/docs similarity index 100% rename from lib/freeDiameter/contrib/debian/docs rename to subprojects/freediameter/contrib/debian/docs diff --git a/lib/freeDiameter/contrib/debian/freediameter-accounting-server.examples b/subprojects/freediameter/contrib/debian/freediameter-accounting-server.examples similarity index 100% rename from lib/freeDiameter/contrib/debian/freediameter-accounting-server.examples rename to subprojects/freediameter/contrib/debian/freediameter-accounting-server.examples diff --git a/lib/freeDiameter/contrib/debian/freediameter-accounting-server.install b/subprojects/freediameter/contrib/debian/freediameter-accounting-server.install similarity index 100% rename from lib/freeDiameter/contrib/debian/freediameter-accounting-server.install rename to subprojects/freediameter/contrib/debian/freediameter-accounting-server.install diff --git a/lib/freeDiameter/contrib/debian/freediameter-common.examples b/subprojects/freediameter/contrib/debian/freediameter-common.examples similarity index 100% rename from lib/freeDiameter/contrib/debian/freediameter-common.examples rename to subprojects/freediameter/contrib/debian/freediameter-common.examples diff --git a/lib/freeDiameter/contrib/debian/freediameter-common.install b/subprojects/freediameter/contrib/debian/freediameter-common.install similarity index 100% rename from lib/freeDiameter/contrib/debian/freediameter-common.install rename to subprojects/freediameter/contrib/debian/freediameter-common.install diff --git a/lib/freeDiameter/contrib/debian/freediameter-daemon.default b/subprojects/freediameter/contrib/debian/freediameter-daemon.default similarity index 100% rename from lib/freeDiameter/contrib/debian/freediameter-daemon.default rename to subprojects/freediameter/contrib/debian/freediameter-daemon.default diff --git a/lib/freeDiameter/contrib/debian/freediameter-daemon.init b/subprojects/freediameter/contrib/debian/freediameter-daemon.init similarity index 100% rename from lib/freeDiameter/contrib/debian/freediameter-daemon.init rename to subprojects/freediameter/contrib/debian/freediameter-daemon.init diff --git a/lib/freeDiameter/contrib/debian/freediameter-daemon.install b/subprojects/freediameter/contrib/debian/freediameter-daemon.install similarity index 100% rename from lib/freeDiameter/contrib/debian/freediameter-daemon.install rename to subprojects/freediameter/contrib/debian/freediameter-daemon.install diff --git a/lib/freeDiameter/contrib/debian/freediameter-debug-tools.examples b/subprojects/freediameter/contrib/debian/freediameter-debug-tools.examples similarity index 100% rename from lib/freeDiameter/contrib/debian/freediameter-debug-tools.examples rename to subprojects/freediameter/contrib/debian/freediameter-debug-tools.examples diff --git a/lib/freeDiameter/contrib/debian/freediameter-debug-tools.install b/subprojects/freediameter/contrib/debian/freediameter-debug-tools.install similarity index 100% rename from lib/freeDiameter/contrib/debian/freediameter-debug-tools.install rename to subprojects/freediameter/contrib/debian/freediameter-debug-tools.install diff --git a/lib/freeDiameter/contrib/debian/freediameter-dev.install b/subprojects/freediameter/contrib/debian/freediameter-dev.install similarity index 100% rename from lib/freeDiameter/contrib/debian/freediameter-dev.install rename to subprojects/freediameter/contrib/debian/freediameter-dev.install diff --git a/lib/freeDiameter/contrib/debian/freediameter-dictionary-legacy.examples b/subprojects/freediameter/contrib/debian/freediameter-dictionary-legacy.examples similarity index 100% rename from lib/freeDiameter/contrib/debian/freediameter-dictionary-legacy.examples rename to subprojects/freediameter/contrib/debian/freediameter-dictionary-legacy.examples diff --git a/lib/freeDiameter/contrib/debian/freediameter-dictionary-legacy.install b/subprojects/freediameter/contrib/debian/freediameter-dictionary-legacy.install similarity index 100% rename from lib/freeDiameter/contrib/debian/freediameter-dictionary-legacy.install rename to subprojects/freediameter/contrib/debian/freediameter-dictionary-legacy.install diff --git a/lib/freeDiameter/contrib/debian/freediameter-dictionary-mip6.install b/subprojects/freediameter/contrib/debian/freediameter-dictionary-mip6.install similarity index 100% rename from lib/freeDiameter/contrib/debian/freediameter-dictionary-mip6.install rename to subprojects/freediameter/contrib/debian/freediameter-dictionary-mip6.install diff --git a/lib/freeDiameter/contrib/debian/freediameter-dictionary-rfc4005.install b/subprojects/freediameter/contrib/debian/freediameter-dictionary-rfc4005.install similarity index 100% rename from lib/freeDiameter/contrib/debian/freediameter-dictionary-rfc4005.install rename to subprojects/freediameter/contrib/debian/freediameter-dictionary-rfc4005.install diff --git a/lib/freeDiameter/contrib/debian/freediameter-dictionary-rfc4006.install b/subprojects/freediameter/contrib/debian/freediameter-dictionary-rfc4006.install similarity index 100% rename from lib/freeDiameter/contrib/debian/freediameter-dictionary-rfc4006.install rename to subprojects/freediameter/contrib/debian/freediameter-dictionary-rfc4006.install diff --git a/lib/freeDiameter/contrib/debian/freediameter-dictionary-rfc4072.install b/subprojects/freediameter/contrib/debian/freediameter-dictionary-rfc4072.install similarity index 100% rename from lib/freeDiameter/contrib/debian/freediameter-dictionary-rfc4072.install rename to subprojects/freediameter/contrib/debian/freediameter-dictionary-rfc4072.install diff --git a/lib/freeDiameter/contrib/debian/freediameter-dictionary-rfc4740.install b/subprojects/freediameter/contrib/debian/freediameter-dictionary-rfc4740.install similarity index 100% rename from lib/freeDiameter/contrib/debian/freediameter-dictionary-rfc4740.install rename to subprojects/freediameter/contrib/debian/freediameter-dictionary-rfc4740.install diff --git a/lib/freeDiameter/contrib/debian/freediameter-eap-server.examples b/subprojects/freediameter/contrib/debian/freediameter-eap-server.examples similarity index 100% rename from lib/freeDiameter/contrib/debian/freediameter-eap-server.examples rename to subprojects/freediameter/contrib/debian/freediameter-eap-server.examples diff --git a/lib/freeDiameter/contrib/debian/freediameter-eap-server.install b/subprojects/freediameter/contrib/debian/freediameter-eap-server.install similarity index 100% rename from lib/freeDiameter/contrib/debian/freediameter-eap-server.install rename to subprojects/freediameter/contrib/debian/freediameter-eap-server.install diff --git a/lib/freeDiameter/contrib/debian/freediameter-radius-gateway.examples b/subprojects/freediameter/contrib/debian/freediameter-radius-gateway.examples similarity index 100% rename from lib/freeDiameter/contrib/debian/freediameter-radius-gateway.examples rename to subprojects/freediameter/contrib/debian/freediameter-radius-gateway.examples diff --git a/lib/freeDiameter/contrib/debian/freediameter-radius-gateway.install b/subprojects/freediameter/contrib/debian/freediameter-radius-gateway.install similarity index 100% rename from lib/freeDiameter/contrib/debian/freediameter-radius-gateway.install rename to subprojects/freediameter/contrib/debian/freediameter-radius-gateway.install diff --git a/lib/freeDiameter/contrib/debian/freediameter-sip-server.examples b/subprojects/freediameter/contrib/debian/freediameter-sip-server.examples similarity index 100% rename from lib/freeDiameter/contrib/debian/freediameter-sip-server.examples rename to subprojects/freediameter/contrib/debian/freediameter-sip-server.examples diff --git a/lib/freeDiameter/contrib/debian/freediameter-sip-server.install b/subprojects/freediameter/contrib/debian/freediameter-sip-server.install similarity index 100% rename from lib/freeDiameter/contrib/debian/freediameter-sip-server.install rename to subprojects/freediameter/contrib/debian/freediameter-sip-server.install diff --git a/lib/freeDiameter/contrib/debian/rules b/subprojects/freediameter/contrib/debian/rules similarity index 100% rename from lib/freeDiameter/contrib/debian/rules rename to subprojects/freediameter/contrib/debian/rules diff --git a/lib/freeDiameter/contrib/debian/update_changelog.txt b/subprojects/freediameter/contrib/debian/update_changelog.txt similarity index 100% rename from lib/freeDiameter/contrib/debian/update_changelog.txt rename to subprojects/freediameter/contrib/debian/update_changelog.txt diff --git a/lib/freeDiameter/contrib/dict_dcca/README b/subprojects/freediameter/contrib/dict_dcca/README similarity index 100% rename from lib/freeDiameter/contrib/dict_dcca/README rename to subprojects/freediameter/contrib/dict_dcca/README diff --git a/lib/freeDiameter/contrib/dict_dcca/dict_dcca_3gpp.c b/subprojects/freediameter/contrib/dict_dcca/dict_dcca_3gpp.c similarity index 100% rename from lib/freeDiameter/contrib/dict_dcca/dict_dcca_3gpp.c rename to subprojects/freediameter/contrib/dict_dcca/dict_dcca_3gpp.c diff --git a/lib/freeDiameter/contrib/dict_dcca/dict_dcca_nokia.c b/subprojects/freediameter/contrib/dict_dcca/dict_dcca_nokia.c similarity index 100% rename from lib/freeDiameter/contrib/dict_dcca/dict_dcca_nokia.c rename to subprojects/freediameter/contrib/dict_dcca/dict_dcca_nokia.c diff --git a/lib/freeDiameter/contrib/dict_gx/README b/subprojects/freediameter/contrib/dict_gx/README similarity index 100% rename from lib/freeDiameter/contrib/dict_gx/README rename to subprojects/freediameter/contrib/dict_gx/README diff --git a/lib/freeDiameter/contrib/dict_gx/dict_gx.xml b/subprojects/freediameter/contrib/dict_gx/dict_gx.xml similarity index 100% rename from lib/freeDiameter/contrib/dict_gx/dict_gx.xml rename to subprojects/freediameter/contrib/dict_gx/dict_gx.xml diff --git a/lib/freeDiameter/contrib/dict_legacy/README b/subprojects/freediameter/contrib/dict_legacy/README similarity index 100% rename from lib/freeDiameter/contrib/dict_legacy/README rename to subprojects/freediameter/contrib/dict_legacy/README diff --git a/lib/freeDiameter/contrib/dict_legacy/dictionary.dtd b/subprojects/freediameter/contrib/dict_legacy/dictionary.dtd similarity index 100% rename from lib/freeDiameter/contrib/dict_legacy/dictionary.dtd rename to subprojects/freediameter/contrib/dict_legacy/dictionary.dtd diff --git a/lib/freeDiameter/contrib/nightly_tests/README b/subprojects/freediameter/contrib/nightly_tests/README similarity index 100% rename from lib/freeDiameter/contrib/nightly_tests/README rename to subprojects/freediameter/contrib/nightly_tests/README diff --git a/lib/freeDiameter/contrib/nightly_tests/cronjob.sh b/subprojects/freediameter/contrib/nightly_tests/cronjob.sh similarity index 100% rename from lib/freeDiameter/contrib/nightly_tests/cronjob.sh rename to subprojects/freediameter/contrib/nightly_tests/cronjob.sh diff --git a/lib/freeDiameter/contrib/nightly_tests/prereqs.fedora b/subprojects/freediameter/contrib/nightly_tests/prereqs.fedora similarity index 100% rename from lib/freeDiameter/contrib/nightly_tests/prereqs.fedora rename to subprojects/freediameter/contrib/nightly_tests/prereqs.fedora diff --git a/lib/freeDiameter/contrib/nightly_tests/prereqs.freebsd b/subprojects/freediameter/contrib/nightly_tests/prereqs.freebsd similarity index 100% rename from lib/freeDiameter/contrib/nightly_tests/prereqs.freebsd rename to subprojects/freediameter/contrib/nightly_tests/prereqs.freebsd diff --git a/lib/freeDiameter/contrib/nightly_tests/prereqs.opensuse b/subprojects/freediameter/contrib/nightly_tests/prereqs.opensuse similarity index 100% rename from lib/freeDiameter/contrib/nightly_tests/prereqs.opensuse rename to subprojects/freediameter/contrib/nightly_tests/prereqs.opensuse diff --git a/lib/freeDiameter/contrib/nightly_tests/prereqs.ubuntu b/subprojects/freediameter/contrib/nightly_tests/prereqs.ubuntu similarity index 100% rename from lib/freeDiameter/contrib/nightly_tests/prereqs.ubuntu rename to subprojects/freediameter/contrib/nightly_tests/prereqs.ubuntu diff --git a/lib/freeDiameter/contrib/nightly_tests/runtests.sh b/subprojects/freediameter/contrib/nightly_tests/runtests.sh similarity index 100% rename from lib/freeDiameter/contrib/nightly_tests/runtests.sh rename to subprojects/freediameter/contrib/nightly_tests/runtests.sh diff --git a/lib/freeDiameter/contrib/nightly_tests/tests.list b/subprojects/freediameter/contrib/nightly_tests/tests.list similarity index 100% rename from lib/freeDiameter/contrib/nightly_tests/tests.list rename to subprojects/freediameter/contrib/nightly_tests/tests.list diff --git a/lib/freeDiameter/contrib/test_Gx/CMakeLists.txt b/subprojects/freediameter/contrib/test_Gx/CMakeLists.txt similarity index 100% rename from lib/freeDiameter/contrib/test_Gx/CMakeLists.txt rename to subprojects/freediameter/contrib/test_Gx/CMakeLists.txt diff --git a/lib/freeDiameter/contrib/test_Gx/main_gx.c b/subprojects/freediameter/contrib/test_Gx/main_gx.c similarity index 100% rename from lib/freeDiameter/contrib/test_Gx/main_gx.c rename to subprojects/freediameter/contrib/test_Gx/main_gx.c diff --git a/lib/freeDiameter/contrib/test_Gx/readme.txt b/subprojects/freediameter/contrib/test_Gx/readme.txt similarity index 100% rename from lib/freeDiameter/contrib/test_Gx/readme.txt rename to subprojects/freediameter/contrib/test_Gx/readme.txt diff --git a/lib/freeDiameter/contrib/tools/README b/subprojects/freediameter/contrib/tools/README similarity index 100% rename from lib/freeDiameter/contrib/tools/README rename to subprojects/freediameter/contrib/tools/README diff --git a/lib/freeDiameter/contrib/tools/diameter-rfcs.org b/subprojects/freediameter/contrib/tools/diameter-rfcs.org similarity index 100% rename from lib/freeDiameter/contrib/tools/diameter-rfcs.org rename to subprojects/freediameter/contrib/tools/diameter-rfcs.org diff --git a/lib/freeDiameter/contrib/tools/org_to_fd.pl b/subprojects/freediameter/contrib/tools/org_to_fd.pl similarity index 100% rename from lib/freeDiameter/contrib/tools/org_to_fd.pl rename to subprojects/freediameter/contrib/tools/org_to_fd.pl diff --git a/lib/freeDiameter/contrib/update_copyright.sh b/subprojects/freediameter/contrib/update_copyright.sh similarity index 100% rename from lib/freeDiameter/contrib/update_copyright.sh rename to subprojects/freediameter/contrib/update_copyright.sh diff --git a/lib/freeDiameter/contrib/wireshark/HOWTO b/subprojects/freediameter/contrib/wireshark/HOWTO similarity index 100% rename from lib/freeDiameter/contrib/wireshark/HOWTO rename to subprojects/freediameter/contrib/wireshark/HOWTO diff --git a/lib/freeDiameter/contrib/wireshark/sample/192.168.103.10.priv.pem b/subprojects/freediameter/contrib/wireshark/sample/192.168.103.10.priv.pem similarity index 100% rename from lib/freeDiameter/contrib/wireshark/sample/192.168.103.10.priv.pem rename to subprojects/freediameter/contrib/wireshark/sample/192.168.103.10.priv.pem diff --git a/lib/freeDiameter/contrib/wireshark/sample/192.168.103.20.priv.pem b/subprojects/freediameter/contrib/wireshark/sample/192.168.103.20.priv.pem similarity index 100% rename from lib/freeDiameter/contrib/wireshark/sample/192.168.103.20.priv.pem rename to subprojects/freediameter/contrib/wireshark/sample/192.168.103.20.priv.pem diff --git a/lib/freeDiameter/contrib/wireshark/sample/README b/subprojects/freediameter/contrib/wireshark/sample/README similarity index 100% rename from lib/freeDiameter/contrib/wireshark/sample/README rename to subprojects/freediameter/contrib/wireshark/sample/README diff --git a/lib/freeDiameter/contrib/wireshark/sample/capture.cap b/subprojects/freediameter/contrib/wireshark/sample/capture.cap similarity index 100% rename from lib/freeDiameter/contrib/wireshark/sample/capture.cap rename to subprojects/freediameter/contrib/wireshark/sample/capture.cap diff --git a/lib/freeDiameter/contrib/wireshark/wireshark-1.2.7-diameter-tls.patch b/subprojects/freediameter/contrib/wireshark/wireshark-1.2.7-diameter-tls.patch similarity index 100% rename from lib/freeDiameter/contrib/wireshark/wireshark-1.2.7-diameter-tls.patch rename to subprojects/freediameter/contrib/wireshark/wireshark-1.2.7-diameter-tls.patch diff --git a/lib/freeDiameter/doc/acl_wl.conf.sample b/subprojects/freediameter/doc/acl_wl.conf.sample similarity index 100% rename from lib/freeDiameter/doc/acl_wl.conf.sample rename to subprojects/freediameter/doc/acl_wl.conf.sample diff --git a/lib/freeDiameter/doc/app_acct.conf.sample b/subprojects/freediameter/doc/app_acct.conf.sample similarity index 100% rename from lib/freeDiameter/doc/app_acct.conf.sample rename to subprojects/freediameter/doc/app_acct.conf.sample diff --git a/lib/freeDiameter/doc/app_diameap.conf.sample b/subprojects/freediameter/doc/app_diameap.conf.sample similarity index 100% rename from lib/freeDiameter/doc/app_diameap.conf.sample rename to subprojects/freediameter/doc/app_diameap.conf.sample diff --git a/lib/freeDiameter/doc/app_radgw.conf.sample b/subprojects/freediameter/doc/app_radgw.conf.sample similarity index 100% rename from lib/freeDiameter/doc/app_radgw.conf.sample rename to subprojects/freediameter/doc/app_radgw.conf.sample diff --git a/lib/freeDiameter/doc/app_redirect.conf.sample b/subprojects/freediameter/doc/app_redirect.conf.sample similarity index 100% rename from lib/freeDiameter/doc/app_redirect.conf.sample rename to subprojects/freediameter/doc/app_redirect.conf.sample diff --git a/lib/freeDiameter/doc/app_sip.conf.sample b/subprojects/freediameter/doc/app_sip.conf.sample similarity index 100% rename from lib/freeDiameter/doc/app_sip.conf.sample rename to subprojects/freediameter/doc/app_sip.conf.sample diff --git a/lib/freeDiameter/doc/app_sip.sql b/subprojects/freediameter/doc/app_sip.sql similarity index 100% rename from lib/freeDiameter/doc/app_sip.sql rename to subprojects/freediameter/doc/app_sip.sql diff --git a/lib/freeDiameter/doc/app_sip_SL.sql b/subprojects/freediameter/doc/app_sip_SL.sql similarity index 100% rename from lib/freeDiameter/doc/app_sip_SL.sql rename to subprojects/freediameter/doc/app_sip_SL.sql diff --git a/lib/freeDiameter/doc/dbg_interactive.py.sample b/subprojects/freediameter/doc/dbg_interactive.py.sample similarity index 100% rename from lib/freeDiameter/doc/dbg_interactive.py.sample rename to subprojects/freediameter/doc/dbg_interactive.py.sample diff --git a/lib/freeDiameter/doc/dict_legacy_xml.conf.sample b/subprojects/freediameter/doc/dict_legacy_xml.conf.sample similarity index 100% rename from lib/freeDiameter/doc/dict_legacy_xml.conf.sample rename to subprojects/freediameter/doc/dict_legacy_xml.conf.sample diff --git a/lib/freeDiameter/doc/eap_tls_plugin.diameap.conf.sample b/subprojects/freediameter/doc/eap_tls_plugin.diameap.conf.sample similarity index 100% rename from lib/freeDiameter/doc/eap_tls_plugin.diameap.conf.sample rename to subprojects/freediameter/doc/eap_tls_plugin.diameap.conf.sample diff --git a/lib/freeDiameter/doc/echodrop.rgwx.conf.sample b/subprojects/freediameter/doc/echodrop.rgwx.conf.sample similarity index 100% rename from lib/freeDiameter/doc/echodrop.rgwx.conf.sample rename to subprojects/freediameter/doc/echodrop.rgwx.conf.sample diff --git a/lib/freeDiameter/doc/freediameter.conf.sample b/subprojects/freediameter/doc/freediameter.conf.sample similarity index 100% rename from lib/freeDiameter/doc/freediameter.conf.sample rename to subprojects/freediameter/doc/freediameter.conf.sample diff --git a/lib/freeDiameter/doc/rt_busypeers.conf.sample b/subprojects/freediameter/doc/rt_busypeers.conf.sample similarity index 100% rename from lib/freeDiameter/doc/rt_busypeers.conf.sample rename to subprojects/freediameter/doc/rt_busypeers.conf.sample diff --git a/lib/freeDiameter/doc/rt_default.conf.sample b/subprojects/freediameter/doc/rt_default.conf.sample similarity index 100% rename from lib/freeDiameter/doc/rt_default.conf.sample rename to subprojects/freediameter/doc/rt_default.conf.sample diff --git a/lib/freeDiameter/doc/rt_ereg.conf.sample b/subprojects/freediameter/doc/rt_ereg.conf.sample similarity index 100% rename from lib/freeDiameter/doc/rt_ereg.conf.sample rename to subprojects/freediameter/doc/rt_ereg.conf.sample diff --git a/lib/freeDiameter/doc/single_host/make_certs.sh b/subprojects/freediameter/doc/single_host/make_certs.sh similarity index 100% rename from lib/freeDiameter/doc/single_host/make_certs.sh rename to subprojects/freediameter/doc/single_host/make_certs.sh diff --git a/lib/freeDiameter/doc/test_app.conf.sample b/subprojects/freediameter/doc/test_app.conf.sample similarity index 100% rename from lib/freeDiameter/doc/test_app.conf.sample rename to subprojects/freediameter/doc/test_app.conf.sample diff --git a/lib/freeDiameter/doc/test_netemul.conf.sample b/subprojects/freediameter/doc/test_netemul.conf.sample similarity index 100% rename from lib/freeDiameter/doc/test_netemul.conf.sample rename to subprojects/freediameter/doc/test_netemul.conf.sample diff --git a/lib/freeDiameter/doc/test_sip.conf.sample b/subprojects/freediameter/doc/test_sip.conf.sample similarity index 100% rename from lib/freeDiameter/doc/test_sip.conf.sample rename to subprojects/freediameter/doc/test_sip.conf.sample diff --git a/lib/freeDiameter/extensions/CMakeLists.txt b/subprojects/freediameter/extensions/CMakeLists.txt similarity index 100% rename from lib/freeDiameter/extensions/CMakeLists.txt rename to subprojects/freediameter/extensions/CMakeLists.txt diff --git a/lib/freeDiameter/extensions/_sample/CMakeLists.txt b/subprojects/freediameter/extensions/_sample/CMakeLists.txt similarity index 100% rename from lib/freeDiameter/extensions/_sample/CMakeLists.txt rename to subprojects/freediameter/extensions/_sample/CMakeLists.txt diff --git a/lib/freeDiameter/extensions/_sample/fini.c b/subprojects/freediameter/extensions/_sample/fini.c similarity index 100% rename from lib/freeDiameter/extensions/_sample/fini.c rename to subprojects/freediameter/extensions/_sample/fini.c diff --git a/lib/freeDiameter/extensions/_sample/hello.cpp b/subprojects/freediameter/extensions/_sample/hello.cpp similarity index 100% rename from lib/freeDiameter/extensions/_sample/hello.cpp rename to subprojects/freediameter/extensions/_sample/hello.cpp diff --git a/lib/freeDiameter/extensions/_sample/sample.c b/subprojects/freediameter/extensions/_sample/sample.c similarity index 100% rename from lib/freeDiameter/extensions/_sample/sample.c rename to subprojects/freediameter/extensions/_sample/sample.c diff --git a/lib/freeDiameter/extensions/acl_wl/CMakeLists.txt b/subprojects/freediameter/extensions/acl_wl/CMakeLists.txt similarity index 100% rename from lib/freeDiameter/extensions/acl_wl/CMakeLists.txt rename to subprojects/freediameter/extensions/acl_wl/CMakeLists.txt diff --git a/lib/freeDiameter/extensions/acl_wl/acl_wl.c b/subprojects/freediameter/extensions/acl_wl/acl_wl.c similarity index 100% rename from lib/freeDiameter/extensions/acl_wl/acl_wl.c rename to subprojects/freediameter/extensions/acl_wl/acl_wl.c diff --git a/lib/freeDiameter/extensions/acl_wl/acl_wl.h b/subprojects/freediameter/extensions/acl_wl/acl_wl.h similarity index 100% rename from lib/freeDiameter/extensions/acl_wl/acl_wl.h rename to subprojects/freediameter/extensions/acl_wl/acl_wl.h diff --git a/lib/freeDiameter/extensions/acl_wl/aw_conf.l b/subprojects/freediameter/extensions/acl_wl/aw_conf.l similarity index 100% rename from lib/freeDiameter/extensions/acl_wl/aw_conf.l rename to subprojects/freediameter/extensions/acl_wl/aw_conf.l diff --git a/lib/freeDiameter/extensions/acl_wl/aw_conf.y b/subprojects/freediameter/extensions/acl_wl/aw_conf.y similarity index 100% rename from lib/freeDiameter/extensions/acl_wl/aw_conf.y rename to subprojects/freediameter/extensions/acl_wl/aw_conf.y diff --git a/lib/freeDiameter/extensions/acl_wl/aw_tree.c b/subprojects/freediameter/extensions/acl_wl/aw_tree.c similarity index 100% rename from lib/freeDiameter/extensions/acl_wl/aw_tree.c rename to subprojects/freediameter/extensions/acl_wl/aw_tree.c diff --git a/lib/freeDiameter/extensions/app_acct/CMakeLists.txt b/subprojects/freediameter/extensions/app_acct/CMakeLists.txt similarity index 100% rename from lib/freeDiameter/extensions/app_acct/CMakeLists.txt rename to subprojects/freediameter/extensions/app_acct/CMakeLists.txt diff --git a/lib/freeDiameter/extensions/app_acct/acct_conf.l b/subprojects/freediameter/extensions/app_acct/acct_conf.l similarity index 100% rename from lib/freeDiameter/extensions/app_acct/acct_conf.l rename to subprojects/freediameter/extensions/app_acct/acct_conf.l diff --git a/lib/freeDiameter/extensions/app_acct/acct_conf.y b/subprojects/freediameter/extensions/app_acct/acct_conf.y similarity index 100% rename from lib/freeDiameter/extensions/app_acct/acct_conf.y rename to subprojects/freediameter/extensions/app_acct/acct_conf.y diff --git a/lib/freeDiameter/extensions/app_acct/acct_db.c b/subprojects/freediameter/extensions/app_acct/acct_db.c similarity index 100% rename from lib/freeDiameter/extensions/app_acct/acct_db.c rename to subprojects/freediameter/extensions/app_acct/acct_db.c diff --git a/lib/freeDiameter/extensions/app_acct/acct_records.c b/subprojects/freediameter/extensions/app_acct/acct_records.c similarity index 100% rename from lib/freeDiameter/extensions/app_acct/acct_records.c rename to subprojects/freediameter/extensions/app_acct/acct_records.c diff --git a/lib/freeDiameter/extensions/app_acct/app_acct.c b/subprojects/freediameter/extensions/app_acct/app_acct.c similarity index 100% rename from lib/freeDiameter/extensions/app_acct/app_acct.c rename to subprojects/freediameter/extensions/app_acct/app_acct.c diff --git a/lib/freeDiameter/extensions/app_acct/app_acct.h b/subprojects/freediameter/extensions/app_acct/app_acct.h similarity index 100% rename from lib/freeDiameter/extensions/app_acct/app_acct.h rename to subprojects/freediameter/extensions/app_acct/app_acct.h diff --git a/lib/freeDiameter/extensions/app_diameap/CMakeLists.txt b/subprojects/freediameter/extensions/app_diameap/CMakeLists.txt similarity index 100% rename from lib/freeDiameter/extensions/app_diameap/CMakeLists.txt rename to subprojects/freediameter/extensions/app_diameap/CMakeLists.txt diff --git a/lib/freeDiameter/extensions/app_diameap/LICENSE b/subprojects/freediameter/extensions/app_diameap/LICENSE similarity index 100% rename from lib/freeDiameter/extensions/app_diameap/LICENSE rename to subprojects/freediameter/extensions/app_diameap/LICENSE diff --git a/lib/freeDiameter/extensions/app_diameap/README b/subprojects/freediameter/extensions/app_diameap/README similarity index 100% rename from lib/freeDiameter/extensions/app_diameap/README rename to subprojects/freediameter/extensions/app_diameap/README diff --git a/lib/freeDiameter/extensions/app_diameap/diameap.c b/subprojects/freediameter/extensions/app_diameap/diameap.c similarity index 100% rename from lib/freeDiameter/extensions/app_diameap/diameap.c rename to subprojects/freediameter/extensions/app_diameap/diameap.c diff --git a/lib/freeDiameter/extensions/app_diameap/diameap.h b/subprojects/freediameter/extensions/app_diameap/diameap.h similarity index 100% rename from lib/freeDiameter/extensions/app_diameap/diameap.h rename to subprojects/freediameter/extensions/app_diameap/diameap.h diff --git a/lib/freeDiameter/extensions/app_diameap/diameap.l b/subprojects/freediameter/extensions/app_diameap/diameap.l similarity index 100% rename from lib/freeDiameter/extensions/app_diameap/diameap.l rename to subprojects/freediameter/extensions/app_diameap/diameap.l diff --git a/lib/freeDiameter/extensions/app_diameap/diameap.sql b/subprojects/freediameter/extensions/app_diameap/diameap.sql similarity index 100% rename from lib/freeDiameter/extensions/app_diameap/diameap.sql rename to subprojects/freediameter/extensions/app_diameap/diameap.sql diff --git a/lib/freeDiameter/extensions/app_diameap/diameap.y b/subprojects/freediameter/extensions/app_diameap/diameap.y similarity index 100% rename from lib/freeDiameter/extensions/app_diameap/diameap.y rename to subprojects/freediameter/extensions/app_diameap/diameap.y diff --git a/lib/freeDiameter/extensions/app_diameap/diameap_common.h b/subprojects/freediameter/extensions/app_diameap/diameap_common.h similarity index 100% rename from lib/freeDiameter/extensions/app_diameap/diameap_common.h rename to subprojects/freediameter/extensions/app_diameap/diameap_common.h diff --git a/lib/freeDiameter/extensions/app_diameap/diameap_defs.h b/subprojects/freediameter/extensions/app_diameap/diameap_defs.h similarity index 100% rename from lib/freeDiameter/extensions/app_diameap/diameap_defs.h rename to subprojects/freediameter/extensions/app_diameap/diameap_defs.h diff --git a/lib/freeDiameter/extensions/app_diameap/diameap_eap.c b/subprojects/freediameter/extensions/app_diameap/diameap_eap.c similarity index 100% rename from lib/freeDiameter/extensions/app_diameap/diameap_eap.c rename to subprojects/freediameter/extensions/app_diameap/diameap_eap.c diff --git a/lib/freeDiameter/extensions/app_diameap/diameap_eap.h b/subprojects/freediameter/extensions/app_diameap/diameap_eap.h similarity index 100% rename from lib/freeDiameter/extensions/app_diameap/diameap_eap.h rename to subprojects/freediameter/extensions/app_diameap/diameap_eap.h diff --git a/lib/freeDiameter/extensions/app_diameap/diameap_eappacket.c b/subprojects/freediameter/extensions/app_diameap/diameap_eappacket.c similarity index 100% rename from lib/freeDiameter/extensions/app_diameap/diameap_eappacket.c rename to subprojects/freediameter/extensions/app_diameap/diameap_eappacket.c diff --git a/lib/freeDiameter/extensions/app_diameap/diameap_eappacket.h b/subprojects/freediameter/extensions/app_diameap/diameap_eappacket.h similarity index 100% rename from lib/freeDiameter/extensions/app_diameap/diameap_eappacket.h rename to subprojects/freediameter/extensions/app_diameap/diameap_eappacket.h diff --git a/lib/freeDiameter/extensions/app_diameap/diameap_init.c b/subprojects/freediameter/extensions/app_diameap/diameap_init.c similarity index 100% rename from lib/freeDiameter/extensions/app_diameap/diameap_init.c rename to subprojects/freediameter/extensions/app_diameap/diameap_init.c diff --git a/lib/freeDiameter/extensions/app_diameap/diameap_mysql.c b/subprojects/freediameter/extensions/app_diameap/diameap_mysql.c similarity index 100% rename from lib/freeDiameter/extensions/app_diameap/diameap_mysql.c rename to subprojects/freediameter/extensions/app_diameap/diameap_mysql.c diff --git a/lib/freeDiameter/extensions/app_diameap/diameap_mysql.h b/subprojects/freediameter/extensions/app_diameap/diameap_mysql.h similarity index 100% rename from lib/freeDiameter/extensions/app_diameap/diameap_mysql.h rename to subprojects/freediameter/extensions/app_diameap/diameap_mysql.h diff --git a/lib/freeDiameter/extensions/app_diameap/diameap_plugins.c b/subprojects/freediameter/extensions/app_diameap/diameap_plugins.c similarity index 100% rename from lib/freeDiameter/extensions/app_diameap/diameap_plugins.c rename to subprojects/freediameter/extensions/app_diameap/diameap_plugins.c diff --git a/lib/freeDiameter/extensions/app_diameap/diameap_plugins.h b/subprojects/freediameter/extensions/app_diameap/diameap_plugins.h similarity index 100% rename from lib/freeDiameter/extensions/app_diameap/diameap_plugins.h rename to subprojects/freediameter/extensions/app_diameap/diameap_plugins.h diff --git a/lib/freeDiameter/extensions/app_diameap/diameap_server.c b/subprojects/freediameter/extensions/app_diameap/diameap_server.c similarity index 100% rename from lib/freeDiameter/extensions/app_diameap/diameap_server.c rename to subprojects/freediameter/extensions/app_diameap/diameap_server.c diff --git a/lib/freeDiameter/extensions/app_diameap/diameap_server.h b/subprojects/freediameter/extensions/app_diameap/diameap_server.h similarity index 100% rename from lib/freeDiameter/extensions/app_diameap/diameap_server.h rename to subprojects/freediameter/extensions/app_diameap/diameap_server.h diff --git a/lib/freeDiameter/extensions/app_diameap/diameap_tls.c b/subprojects/freediameter/extensions/app_diameap/diameap_tls.c similarity index 100% rename from lib/freeDiameter/extensions/app_diameap/diameap_tls.c rename to subprojects/freediameter/extensions/app_diameap/diameap_tls.c diff --git a/lib/freeDiameter/extensions/app_diameap/diameap_tls.h b/subprojects/freediameter/extensions/app_diameap/diameap_tls.h similarity index 100% rename from lib/freeDiameter/extensions/app_diameap/diameap_tls.h rename to subprojects/freediameter/extensions/app_diameap/diameap_tls.h diff --git a/lib/freeDiameter/extensions/app_diameap/diameap_user.c b/subprojects/freediameter/extensions/app_diameap/diameap_user.c similarity index 100% rename from lib/freeDiameter/extensions/app_diameap/diameap_user.c rename to subprojects/freediameter/extensions/app_diameap/diameap_user.c diff --git a/lib/freeDiameter/extensions/app_diameap/diameap_user.h b/subprojects/freediameter/extensions/app_diameap/diameap_user.h similarity index 100% rename from lib/freeDiameter/extensions/app_diameap/diameap_user.h rename to subprojects/freediameter/extensions/app_diameap/diameap_user.h diff --git a/lib/freeDiameter/extensions/app_diameap/libcrypt.c b/subprojects/freediameter/extensions/app_diameap/libcrypt.c similarity index 100% rename from lib/freeDiameter/extensions/app_diameap/libcrypt.c rename to subprojects/freediameter/extensions/app_diameap/libcrypt.c diff --git a/lib/freeDiameter/extensions/app_diameap/libcrypt.h b/subprojects/freediameter/extensions/app_diameap/libcrypt.h similarity index 100% rename from lib/freeDiameter/extensions/app_diameap/libcrypt.h rename to subprojects/freediameter/extensions/app_diameap/libcrypt.h diff --git a/lib/freeDiameter/extensions/app_diameap/libdiameap.h b/subprojects/freediameter/extensions/app_diameap/libdiameap.h similarity index 100% rename from lib/freeDiameter/extensions/app_diameap/libdiameap.h rename to subprojects/freediameter/extensions/app_diameap/libdiameap.h diff --git a/lib/freeDiameter/extensions/app_diameap/plugins.h b/subprojects/freediameter/extensions/app_diameap/plugins.h similarity index 100% rename from lib/freeDiameter/extensions/app_diameap/plugins.h rename to subprojects/freediameter/extensions/app_diameap/plugins.h diff --git a/lib/freeDiameter/extensions/app_diameap/plugins/CMakeLists.txt b/subprojects/freediameter/extensions/app_diameap/plugins/CMakeLists.txt similarity index 100% rename from lib/freeDiameter/extensions/app_diameap/plugins/CMakeLists.txt rename to subprojects/freediameter/extensions/app_diameap/plugins/CMakeLists.txt diff --git a/lib/freeDiameter/extensions/app_diameap/plugins/eap_identity/CMakeLists.txt b/subprojects/freediameter/extensions/app_diameap/plugins/eap_identity/CMakeLists.txt similarity index 100% rename from lib/freeDiameter/extensions/app_diameap/plugins/eap_identity/CMakeLists.txt rename to subprojects/freediameter/extensions/app_diameap/plugins/eap_identity/CMakeLists.txt diff --git a/lib/freeDiameter/extensions/app_diameap/plugins/eap_identity/eap_identity.c b/subprojects/freediameter/extensions/app_diameap/plugins/eap_identity/eap_identity.c similarity index 100% rename from lib/freeDiameter/extensions/app_diameap/plugins/eap_identity/eap_identity.c rename to subprojects/freediameter/extensions/app_diameap/plugins/eap_identity/eap_identity.c diff --git a/lib/freeDiameter/extensions/app_diameap/plugins/eap_md5/CMakeLists.txt b/subprojects/freediameter/extensions/app_diameap/plugins/eap_md5/CMakeLists.txt similarity index 100% rename from lib/freeDiameter/extensions/app_diameap/plugins/eap_md5/CMakeLists.txt rename to subprojects/freediameter/extensions/app_diameap/plugins/eap_md5/CMakeLists.txt diff --git a/lib/freeDiameter/extensions/app_diameap/plugins/eap_md5/eap_md5.c b/subprojects/freediameter/extensions/app_diameap/plugins/eap_md5/eap_md5.c similarity index 100% rename from lib/freeDiameter/extensions/app_diameap/plugins/eap_md5/eap_md5.c rename to subprojects/freediameter/extensions/app_diameap/plugins/eap_md5/eap_md5.c diff --git a/lib/freeDiameter/extensions/app_diameap/plugins/eap_tls/CMakeLists.txt b/subprojects/freediameter/extensions/app_diameap/plugins/eap_tls/CMakeLists.txt similarity index 100% rename from lib/freeDiameter/extensions/app_diameap/plugins/eap_tls/CMakeLists.txt rename to subprojects/freediameter/extensions/app_diameap/plugins/eap_tls/CMakeLists.txt diff --git a/lib/freeDiameter/extensions/app_diameap/plugins/eap_tls/eap_tls.c b/subprojects/freediameter/extensions/app_diameap/plugins/eap_tls/eap_tls.c similarity index 100% rename from lib/freeDiameter/extensions/app_diameap/plugins/eap_tls/eap_tls.c rename to subprojects/freediameter/extensions/app_diameap/plugins/eap_tls/eap_tls.c diff --git a/lib/freeDiameter/extensions/app_diameap/plugins/eap_tls/eap_tls.h b/subprojects/freediameter/extensions/app_diameap/plugins/eap_tls/eap_tls.h similarity index 100% rename from lib/freeDiameter/extensions/app_diameap/plugins/eap_tls/eap_tls.h rename to subprojects/freediameter/extensions/app_diameap/plugins/eap_tls/eap_tls.h diff --git a/lib/freeDiameter/extensions/app_diameap/plugins/eap_tls/eaptls.l b/subprojects/freediameter/extensions/app_diameap/plugins/eap_tls/eaptls.l similarity index 100% rename from lib/freeDiameter/extensions/app_diameap/plugins/eap_tls/eaptls.l rename to subprojects/freediameter/extensions/app_diameap/plugins/eap_tls/eaptls.l diff --git a/lib/freeDiameter/extensions/app_diameap/plugins/eap_tls/eaptls.y b/subprojects/freediameter/extensions/app_diameap/plugins/eap_tls/eaptls.y similarity index 100% rename from lib/freeDiameter/extensions/app_diameap/plugins/eap_tls/eaptls.y rename to subprojects/freediameter/extensions/app_diameap/plugins/eap_tls/eaptls.y diff --git a/lib/freeDiameter/extensions/app_radgw/CMakeLists.txt b/subprojects/freediameter/extensions/app_radgw/CMakeLists.txt similarity index 100% rename from lib/freeDiameter/extensions/app_radgw/CMakeLists.txt rename to subprojects/freediameter/extensions/app_radgw/CMakeLists.txt diff --git a/lib/freeDiameter/extensions/app_radgw/hostap_compat.h b/subprojects/freediameter/extensions/app_radgw/hostap_compat.h similarity index 100% rename from lib/freeDiameter/extensions/app_radgw/hostap_compat.h rename to subprojects/freediameter/extensions/app_radgw/hostap_compat.h diff --git a/lib/freeDiameter/extensions/app_radgw/md5.c b/subprojects/freediameter/extensions/app_radgw/md5.c similarity index 100% rename from lib/freeDiameter/extensions/app_radgw/md5.c rename to subprojects/freediameter/extensions/app_radgw/md5.c diff --git a/lib/freeDiameter/extensions/app_radgw/md5.h b/subprojects/freediameter/extensions/app_radgw/md5.h similarity index 100% rename from lib/freeDiameter/extensions/app_radgw/md5.h rename to subprojects/freediameter/extensions/app_radgw/md5.h diff --git a/lib/freeDiameter/extensions/app_radgw/radius.c b/subprojects/freediameter/extensions/app_radgw/radius.c similarity index 100% rename from lib/freeDiameter/extensions/app_radgw/radius.c rename to subprojects/freediameter/extensions/app_radgw/radius.c diff --git a/lib/freeDiameter/extensions/app_radgw/radius.h b/subprojects/freediameter/extensions/app_radgw/radius.h similarity index 100% rename from lib/freeDiameter/extensions/app_radgw/radius.h rename to subprojects/freediameter/extensions/app_radgw/radius.h diff --git a/lib/freeDiameter/extensions/app_radgw/rgw.h b/subprojects/freediameter/extensions/app_radgw/rgw.h similarity index 100% rename from lib/freeDiameter/extensions/app_radgw/rgw.h rename to subprojects/freediameter/extensions/app_radgw/rgw.h diff --git a/lib/freeDiameter/extensions/app_radgw/rgw_clients.c b/subprojects/freediameter/extensions/app_radgw/rgw_clients.c similarity index 100% rename from lib/freeDiameter/extensions/app_radgw/rgw_clients.c rename to subprojects/freediameter/extensions/app_radgw/rgw_clients.c diff --git a/lib/freeDiameter/extensions/app_radgw/rgw_common.h b/subprojects/freediameter/extensions/app_radgw/rgw_common.h similarity index 100% rename from lib/freeDiameter/extensions/app_radgw/rgw_common.h rename to subprojects/freediameter/extensions/app_radgw/rgw_common.h diff --git a/lib/freeDiameter/extensions/app_radgw/rgw_conf.l b/subprojects/freediameter/extensions/app_radgw/rgw_conf.l similarity index 100% rename from lib/freeDiameter/extensions/app_radgw/rgw_conf.l rename to subprojects/freediameter/extensions/app_radgw/rgw_conf.l diff --git a/lib/freeDiameter/extensions/app_radgw/rgw_conf.y b/subprojects/freediameter/extensions/app_radgw/rgw_conf.y similarity index 100% rename from lib/freeDiameter/extensions/app_radgw/rgw_conf.y rename to subprojects/freediameter/extensions/app_radgw/rgw_conf.y diff --git a/lib/freeDiameter/extensions/app_radgw/rgw_main.c b/subprojects/freediameter/extensions/app_radgw/rgw_main.c similarity index 100% rename from lib/freeDiameter/extensions/app_radgw/rgw_main.c rename to subprojects/freediameter/extensions/app_radgw/rgw_main.c diff --git a/lib/freeDiameter/extensions/app_radgw/rgw_msg_attrtype.c b/subprojects/freediameter/extensions/app_radgw/rgw_msg_attrtype.c similarity index 100% rename from lib/freeDiameter/extensions/app_radgw/rgw_msg_attrtype.c rename to subprojects/freediameter/extensions/app_radgw/rgw_msg_attrtype.c diff --git a/lib/freeDiameter/extensions/app_radgw/rgw_msg_codes.c b/subprojects/freediameter/extensions/app_radgw/rgw_msg_codes.c similarity index 100% rename from lib/freeDiameter/extensions/app_radgw/rgw_msg_codes.c rename to subprojects/freediameter/extensions/app_radgw/rgw_msg_codes.c diff --git a/lib/freeDiameter/extensions/app_radgw/rgw_plugins.c b/subprojects/freediameter/extensions/app_radgw/rgw_plugins.c similarity index 100% rename from lib/freeDiameter/extensions/app_radgw/rgw_plugins.c rename to subprojects/freediameter/extensions/app_radgw/rgw_plugins.c diff --git a/lib/freeDiameter/extensions/app_radgw/rgw_servers.c b/subprojects/freediameter/extensions/app_radgw/rgw_servers.c similarity index 100% rename from lib/freeDiameter/extensions/app_radgw/rgw_servers.c rename to subprojects/freediameter/extensions/app_radgw/rgw_servers.c diff --git a/lib/freeDiameter/extensions/app_radgw/rgw_worker.c b/subprojects/freediameter/extensions/app_radgw/rgw_worker.c similarity index 100% rename from lib/freeDiameter/extensions/app_radgw/rgw_worker.c rename to subprojects/freediameter/extensions/app_radgw/rgw_worker.c diff --git a/lib/freeDiameter/extensions/app_radgw/rgwx_acct.c b/subprojects/freediameter/extensions/app_radgw/rgwx_acct.c similarity index 100% rename from lib/freeDiameter/extensions/app_radgw/rgwx_acct.c rename to subprojects/freediameter/extensions/app_radgw/rgwx_acct.c diff --git a/lib/freeDiameter/extensions/app_radgw/rgwx_auth.c b/subprojects/freediameter/extensions/app_radgw/rgwx_auth.c similarity index 100% rename from lib/freeDiameter/extensions/app_radgw/rgwx_auth.c rename to subprojects/freediameter/extensions/app_radgw/rgwx_auth.c diff --git a/lib/freeDiameter/extensions/app_radgw/rgwx_debug.c b/subprojects/freediameter/extensions/app_radgw/rgwx_debug.c similarity index 100% rename from lib/freeDiameter/extensions/app_radgw/rgwx_debug.c rename to subprojects/freediameter/extensions/app_radgw/rgwx_debug.c diff --git a/lib/freeDiameter/extensions/app_radgw/rgwx_echodrop.c b/subprojects/freediameter/extensions/app_radgw/rgwx_echodrop.c similarity index 100% rename from lib/freeDiameter/extensions/app_radgw/rgwx_echodrop.c rename to subprojects/freediameter/extensions/app_radgw/rgwx_echodrop.c diff --git a/lib/freeDiameter/extensions/app_radgw/rgwx_echodrop.h b/subprojects/freediameter/extensions/app_radgw/rgwx_echodrop.h similarity index 100% rename from lib/freeDiameter/extensions/app_radgw/rgwx_echodrop.h rename to subprojects/freediameter/extensions/app_radgw/rgwx_echodrop.h diff --git a/lib/freeDiameter/extensions/app_radgw/rgwx_echodrop.l b/subprojects/freediameter/extensions/app_radgw/rgwx_echodrop.l similarity index 100% rename from lib/freeDiameter/extensions/app_radgw/rgwx_echodrop.l rename to subprojects/freediameter/extensions/app_radgw/rgwx_echodrop.l diff --git a/lib/freeDiameter/extensions/app_radgw/rgwx_echodrop.y b/subprojects/freediameter/extensions/app_radgw/rgwx_echodrop.y similarity index 100% rename from lib/freeDiameter/extensions/app_radgw/rgwx_echodrop.y rename to subprojects/freediameter/extensions/app_radgw/rgwx_echodrop.y diff --git a/lib/freeDiameter/extensions/app_radgw/rgwx_sample.c b/subprojects/freediameter/extensions/app_radgw/rgwx_sample.c similarity index 100% rename from lib/freeDiameter/extensions/app_radgw/rgwx_sample.c rename to subprojects/freediameter/extensions/app_radgw/rgwx_sample.c diff --git a/lib/freeDiameter/extensions/app_radgw/rgwx_sip.c b/subprojects/freediameter/extensions/app_radgw/rgwx_sip.c similarity index 100% rename from lib/freeDiameter/extensions/app_radgw/rgwx_sip.c rename to subprojects/freediameter/extensions/app_radgw/rgwx_sip.c diff --git a/lib/freeDiameter/extensions/app_redirect/CMakeLists.txt b/subprojects/freediameter/extensions/app_redirect/CMakeLists.txt similarity index 100% rename from lib/freeDiameter/extensions/app_redirect/CMakeLists.txt rename to subprojects/freediameter/extensions/app_redirect/CMakeLists.txt diff --git a/lib/freeDiameter/extensions/app_redirect/app_redir.c b/subprojects/freediameter/extensions/app_redirect/app_redir.c similarity index 100% rename from lib/freeDiameter/extensions/app_redirect/app_redir.c rename to subprojects/freediameter/extensions/app_redirect/app_redir.c diff --git a/lib/freeDiameter/extensions/app_redirect/app_redir.h b/subprojects/freediameter/extensions/app_redirect/app_redir.h similarity index 100% rename from lib/freeDiameter/extensions/app_redirect/app_redir.h rename to subprojects/freediameter/extensions/app_redirect/app_redir.h diff --git a/lib/freeDiameter/extensions/app_redirect/ard-host.h.in b/subprojects/freediameter/extensions/app_redirect/ard-host.h.in similarity index 100% rename from lib/freeDiameter/extensions/app_redirect/ard-host.h.in rename to subprojects/freediameter/extensions/app_redirect/ard-host.h.in diff --git a/lib/freeDiameter/extensions/app_redirect/ard_conf.l b/subprojects/freediameter/extensions/app_redirect/ard_conf.l similarity index 100% rename from lib/freeDiameter/extensions/app_redirect/ard_conf.l rename to subprojects/freediameter/extensions/app_redirect/ard_conf.l diff --git a/lib/freeDiameter/extensions/app_redirect/ard_conf.y b/subprojects/freediameter/extensions/app_redirect/ard_conf.y similarity index 100% rename from lib/freeDiameter/extensions/app_redirect/ard_conf.y rename to subprojects/freediameter/extensions/app_redirect/ard_conf.y diff --git a/lib/freeDiameter/extensions/app_redirect/ard_rules.c b/subprojects/freediameter/extensions/app_redirect/ard_rules.c similarity index 100% rename from lib/freeDiameter/extensions/app_redirect/ard_rules.c rename to subprojects/freediameter/extensions/app_redirect/ard_rules.c diff --git a/lib/freeDiameter/extensions/app_sip/CMakeLists.txt b/subprojects/freediameter/extensions/app_sip/CMakeLists.txt similarity index 100% rename from lib/freeDiameter/extensions/app_sip/CMakeLists.txt rename to subprojects/freediameter/extensions/app_sip/CMakeLists.txt diff --git a/lib/freeDiameter/extensions/app_sip/README b/subprojects/freediameter/extensions/app_sip/README similarity index 100% rename from lib/freeDiameter/extensions/app_sip/README rename to subprojects/freediameter/extensions/app_sip/README diff --git a/lib/freeDiameter/extensions/app_sip/TODO b/subprojects/freediameter/extensions/app_sip/TODO similarity index 100% rename from lib/freeDiameter/extensions/app_sip/TODO rename to subprojects/freediameter/extensions/app_sip/TODO diff --git a/lib/freeDiameter/extensions/app_sip/app_sip.c b/subprojects/freediameter/extensions/app_sip/app_sip.c similarity index 100% rename from lib/freeDiameter/extensions/app_sip/app_sip.c rename to subprojects/freediameter/extensions/app_sip/app_sip.c diff --git a/lib/freeDiameter/extensions/app_sip/app_sip.h b/subprojects/freediameter/extensions/app_sip/app_sip.h similarity index 100% rename from lib/freeDiameter/extensions/app_sip/app_sip.h rename to subprojects/freediameter/extensions/app_sip/app_sip.h diff --git a/lib/freeDiameter/extensions/app_sip/app_sip.l b/subprojects/freediameter/extensions/app_sip/app_sip.l similarity index 100% rename from lib/freeDiameter/extensions/app_sip/app_sip.l rename to subprojects/freediameter/extensions/app_sip/app_sip.l diff --git a/lib/freeDiameter/extensions/app_sip/app_sip.y b/subprojects/freediameter/extensions/app_sip/app_sip.y similarity index 100% rename from lib/freeDiameter/extensions/app_sip/app_sip.y rename to subprojects/freediameter/extensions/app_sip/app_sip.y diff --git a/lib/freeDiameter/extensions/app_sip/libapp_sip.c b/subprojects/freediameter/extensions/app_sip/libapp_sip.c similarity index 100% rename from lib/freeDiameter/extensions/app_sip/libapp_sip.c rename to subprojects/freediameter/extensions/app_sip/libapp_sip.c diff --git a/lib/freeDiameter/extensions/app_sip/locationinfo.c b/subprojects/freediameter/extensions/app_sip/locationinfo.c similarity index 100% rename from lib/freeDiameter/extensions/app_sip/locationinfo.c rename to subprojects/freediameter/extensions/app_sip/locationinfo.c diff --git a/lib/freeDiameter/extensions/app_sip/locationinfosl.c b/subprojects/freediameter/extensions/app_sip/locationinfosl.c similarity index 100% rename from lib/freeDiameter/extensions/app_sip/locationinfosl.c rename to subprojects/freediameter/extensions/app_sip/locationinfosl.c diff --git a/lib/freeDiameter/extensions/app_sip/md5.c b/subprojects/freediameter/extensions/app_sip/md5.c similarity index 100% rename from lib/freeDiameter/extensions/app_sip/md5.c rename to subprojects/freediameter/extensions/app_sip/md5.c diff --git a/lib/freeDiameter/extensions/app_sip/md5.h b/subprojects/freediameter/extensions/app_sip/md5.h similarity index 100% rename from lib/freeDiameter/extensions/app_sip/md5.h rename to subprojects/freediameter/extensions/app_sip/md5.h diff --git a/lib/freeDiameter/extensions/app_sip/multimediaauth.c b/subprojects/freediameter/extensions/app_sip/multimediaauth.c similarity index 100% rename from lib/freeDiameter/extensions/app_sip/multimediaauth.c rename to subprojects/freediameter/extensions/app_sip/multimediaauth.c diff --git a/lib/freeDiameter/extensions/app_sip/pushprofile.c b/subprojects/freediameter/extensions/app_sip/pushprofile.c similarity index 100% rename from lib/freeDiameter/extensions/app_sip/pushprofile.c rename to subprojects/freediameter/extensions/app_sip/pushprofile.c diff --git a/lib/freeDiameter/extensions/app_sip/registrationtermination.c b/subprojects/freediameter/extensions/app_sip/registrationtermination.c similarity index 100% rename from lib/freeDiameter/extensions/app_sip/registrationtermination.c rename to subprojects/freediameter/extensions/app_sip/registrationtermination.c diff --git a/lib/freeDiameter/extensions/app_sip/serverassignment.c b/subprojects/freediameter/extensions/app_sip/serverassignment.c similarity index 100% rename from lib/freeDiameter/extensions/app_sip/serverassignment.c rename to subprojects/freediameter/extensions/app_sip/serverassignment.c diff --git a/lib/freeDiameter/extensions/app_sip/tools/CMakeLists.txt b/subprojects/freediameter/extensions/app_sip/tools/CMakeLists.txt similarity index 100% rename from lib/freeDiameter/extensions/app_sip/tools/CMakeLists.txt rename to subprojects/freediameter/extensions/app_sip/tools/CMakeLists.txt diff --git a/lib/freeDiameter/extensions/app_sip/tools/app_sip_ppr.c b/subprojects/freediameter/extensions/app_sip/tools/app_sip_ppr.c similarity index 100% rename from lib/freeDiameter/extensions/app_sip/tools/app_sip_ppr.c rename to subprojects/freediameter/extensions/app_sip/tools/app_sip_ppr.c diff --git a/lib/freeDiameter/extensions/app_sip/tools/app_sip_rtr.c b/subprojects/freediameter/extensions/app_sip/tools/app_sip_rtr.c similarity index 100% rename from lib/freeDiameter/extensions/app_sip/tools/app_sip_rtr.c rename to subprojects/freediameter/extensions/app_sip/tools/app_sip_rtr.c diff --git a/lib/freeDiameter/extensions/app_sip/userauthorization.c b/subprojects/freediameter/extensions/app_sip/userauthorization.c similarity index 100% rename from lib/freeDiameter/extensions/app_sip/userauthorization.c rename to subprojects/freediameter/extensions/app_sip/userauthorization.c diff --git a/lib/freeDiameter/extensions/dbg_interactive/CMakeLists.txt b/subprojects/freediameter/extensions/dbg_interactive/CMakeLists.txt similarity index 100% rename from lib/freeDiameter/extensions/dbg_interactive/CMakeLists.txt rename to subprojects/freediameter/extensions/dbg_interactive/CMakeLists.txt diff --git a/lib/freeDiameter/extensions/dbg_interactive/dbg_interactive.c b/subprojects/freediameter/extensions/dbg_interactive/dbg_interactive.c similarity index 100% rename from lib/freeDiameter/extensions/dbg_interactive/dbg_interactive.c rename to subprojects/freediameter/extensions/dbg_interactive/dbg_interactive.c diff --git a/lib/freeDiameter/extensions/dbg_interactive/dbg_interactive.i b/subprojects/freediameter/extensions/dbg_interactive/dbg_interactive.i similarity index 100% rename from lib/freeDiameter/extensions/dbg_interactive/dbg_interactive.i rename to subprojects/freediameter/extensions/dbg_interactive/dbg_interactive.i diff --git a/lib/freeDiameter/extensions/dbg_interactive/dictionary.i b/subprojects/freediameter/extensions/dbg_interactive/dictionary.i similarity index 100% rename from lib/freeDiameter/extensions/dbg_interactive/dictionary.i rename to subprojects/freediameter/extensions/dbg_interactive/dictionary.i diff --git a/lib/freeDiameter/extensions/dbg_interactive/dispatch.i b/subprojects/freediameter/extensions/dbg_interactive/dispatch.i similarity index 100% rename from lib/freeDiameter/extensions/dbg_interactive/dispatch.i rename to subprojects/freediameter/extensions/dbg_interactive/dispatch.i diff --git a/lib/freeDiameter/extensions/dbg_interactive/endpoints.i b/subprojects/freediameter/extensions/dbg_interactive/endpoints.i similarity index 100% rename from lib/freeDiameter/extensions/dbg_interactive/endpoints.i rename to subprojects/freediameter/extensions/dbg_interactive/endpoints.i diff --git a/lib/freeDiameter/extensions/dbg_interactive/events.i b/subprojects/freediameter/extensions/dbg_interactive/events.i similarity index 100% rename from lib/freeDiameter/extensions/dbg_interactive/events.i rename to subprojects/freediameter/extensions/dbg_interactive/events.i diff --git a/lib/freeDiameter/extensions/dbg_interactive/helper/xxd.c b/subprojects/freediameter/extensions/dbg_interactive/helper/xxd.c similarity index 100% rename from lib/freeDiameter/extensions/dbg_interactive/helper/xxd.c rename to subprojects/freediameter/extensions/dbg_interactive/helper/xxd.c diff --git a/lib/freeDiameter/extensions/dbg_interactive/hooks.i b/subprojects/freediameter/extensions/dbg_interactive/hooks.i similarity index 100% rename from lib/freeDiameter/extensions/dbg_interactive/hooks.i rename to subprojects/freediameter/extensions/dbg_interactive/hooks.i diff --git a/lib/freeDiameter/extensions/dbg_interactive/lists.i b/subprojects/freediameter/extensions/dbg_interactive/lists.i similarity index 100% rename from lib/freeDiameter/extensions/dbg_interactive/lists.i rename to subprojects/freediameter/extensions/dbg_interactive/lists.i diff --git a/lib/freeDiameter/extensions/dbg_interactive/messages.i b/subprojects/freediameter/extensions/dbg_interactive/messages.i similarity index 100% rename from lib/freeDiameter/extensions/dbg_interactive/messages.i rename to subprojects/freediameter/extensions/dbg_interactive/messages.i diff --git a/lib/freeDiameter/extensions/dbg_interactive/peers.i b/subprojects/freediameter/extensions/dbg_interactive/peers.i similarity index 100% rename from lib/freeDiameter/extensions/dbg_interactive/peers.i rename to subprojects/freediameter/extensions/dbg_interactive/peers.i diff --git a/lib/freeDiameter/extensions/dbg_interactive/posix.i b/subprojects/freediameter/extensions/dbg_interactive/posix.i similarity index 100% rename from lib/freeDiameter/extensions/dbg_interactive/posix.i rename to subprojects/freediameter/extensions/dbg_interactive/posix.i diff --git a/lib/freeDiameter/extensions/dbg_interactive/queues.i b/subprojects/freediameter/extensions/dbg_interactive/queues.i similarity index 100% rename from lib/freeDiameter/extensions/dbg_interactive/queues.i rename to subprojects/freediameter/extensions/dbg_interactive/queues.i diff --git a/lib/freeDiameter/extensions/dbg_interactive/routing.i b/subprojects/freediameter/extensions/dbg_interactive/routing.i similarity index 100% rename from lib/freeDiameter/extensions/dbg_interactive/routing.i rename to subprojects/freediameter/extensions/dbg_interactive/routing.i diff --git a/lib/freeDiameter/extensions/dbg_interactive/sessions.i b/subprojects/freediameter/extensions/dbg_interactive/sessions.i similarity index 100% rename from lib/freeDiameter/extensions/dbg_interactive/sessions.i rename to subprojects/freediameter/extensions/dbg_interactive/sessions.i diff --git a/lib/freeDiameter/extensions/dbg_monitor/CMakeLists.txt b/subprojects/freediameter/extensions/dbg_monitor/CMakeLists.txt similarity index 100% rename from lib/freeDiameter/extensions/dbg_monitor/CMakeLists.txt rename to subprojects/freediameter/extensions/dbg_monitor/CMakeLists.txt diff --git a/lib/freeDiameter/extensions/dbg_monitor/dbg_monitor.c b/subprojects/freediameter/extensions/dbg_monitor/dbg_monitor.c similarity index 100% rename from lib/freeDiameter/extensions/dbg_monitor/dbg_monitor.c rename to subprojects/freediameter/extensions/dbg_monitor/dbg_monitor.c diff --git a/lib/freeDiameter/extensions/dbg_msg_dumps/CMakeLists.txt b/subprojects/freediameter/extensions/dbg_msg_dumps/CMakeLists.txt similarity index 100% rename from lib/freeDiameter/extensions/dbg_msg_dumps/CMakeLists.txt rename to subprojects/freediameter/extensions/dbg_msg_dumps/CMakeLists.txt diff --git a/lib/freeDiameter/extensions/dbg_msg_dumps/dbg_msg_dumps.c b/subprojects/freediameter/extensions/dbg_msg_dumps/dbg_msg_dumps.c similarity index 100% rename from lib/freeDiameter/extensions/dbg_msg_dumps/dbg_msg_dumps.c rename to subprojects/freediameter/extensions/dbg_msg_dumps/dbg_msg_dumps.c diff --git a/lib/freeDiameter/extensions/dbg_msg_timings/CMakeLists.txt b/subprojects/freediameter/extensions/dbg_msg_timings/CMakeLists.txt similarity index 100% rename from lib/freeDiameter/extensions/dbg_msg_timings/CMakeLists.txt rename to subprojects/freediameter/extensions/dbg_msg_timings/CMakeLists.txt diff --git a/lib/freeDiameter/extensions/dbg_msg_timings/dbg_msg_timings.c b/subprojects/freediameter/extensions/dbg_msg_timings/dbg_msg_timings.c similarity index 100% rename from lib/freeDiameter/extensions/dbg_msg_timings/dbg_msg_timings.c rename to subprojects/freediameter/extensions/dbg_msg_timings/dbg_msg_timings.c diff --git a/lib/freeDiameter/extensions/dbg_rt/CMakeLists.txt b/subprojects/freediameter/extensions/dbg_rt/CMakeLists.txt similarity index 100% rename from lib/freeDiameter/extensions/dbg_rt/CMakeLists.txt rename to subprojects/freediameter/extensions/dbg_rt/CMakeLists.txt diff --git a/lib/freeDiameter/extensions/dbg_rt/dbg_rt.c b/subprojects/freediameter/extensions/dbg_rt/dbg_rt.c similarity index 100% rename from lib/freeDiameter/extensions/dbg_rt/dbg_rt.c rename to subprojects/freediameter/extensions/dbg_rt/dbg_rt.c diff --git a/lib/freeDiameter/extensions/dict_dcca/CMakeLists.txt b/subprojects/freediameter/extensions/dict_dcca/CMakeLists.txt similarity index 100% rename from lib/freeDiameter/extensions/dict_dcca/CMakeLists.txt rename to subprojects/freediameter/extensions/dict_dcca/CMakeLists.txt diff --git a/lib/freeDiameter/extensions/dict_dcca/dict_dcca.c b/subprojects/freediameter/extensions/dict_dcca/dict_dcca.c similarity index 100% rename from lib/freeDiameter/extensions/dict_dcca/dict_dcca.c rename to subprojects/freediameter/extensions/dict_dcca/dict_dcca.c diff --git a/lib/freeDiameter/extensions/dict_dcca_3gpp/CMakeLists.txt b/subprojects/freediameter/extensions/dict_dcca_3gpp/CMakeLists.txt similarity index 100% rename from lib/freeDiameter/extensions/dict_dcca_3gpp/CMakeLists.txt rename to subprojects/freediameter/extensions/dict_dcca_3gpp/CMakeLists.txt diff --git a/lib/freeDiameter/extensions/dict_dcca_3gpp/dict_dcca_3gpp.c b/subprojects/freediameter/extensions/dict_dcca_3gpp/dict_dcca_3gpp.c similarity index 100% rename from lib/freeDiameter/extensions/dict_dcca_3gpp/dict_dcca_3gpp.c rename to subprojects/freediameter/extensions/dict_dcca_3gpp/dict_dcca_3gpp.c diff --git a/lib/freeDiameter/extensions/dict_dcca_3gpp/dict_dcca_3gpp.org b/subprojects/freediameter/extensions/dict_dcca_3gpp/dict_dcca_3gpp.org similarity index 100% rename from lib/freeDiameter/extensions/dict_dcca_3gpp/dict_dcca_3gpp.org rename to subprojects/freediameter/extensions/dict_dcca_3gpp/dict_dcca_3gpp.org diff --git a/lib/freeDiameter/extensions/dict_dcca_starent/CMakeLists.txt b/subprojects/freediameter/extensions/dict_dcca_starent/CMakeLists.txt similarity index 100% rename from lib/freeDiameter/extensions/dict_dcca_starent/CMakeLists.txt rename to subprojects/freediameter/extensions/dict_dcca_starent/CMakeLists.txt diff --git a/lib/freeDiameter/extensions/dict_dcca_starent/dict_dcca_starent.c b/subprojects/freediameter/extensions/dict_dcca_starent/dict_dcca_starent.c similarity index 100% rename from lib/freeDiameter/extensions/dict_dcca_starent/dict_dcca_starent.c rename to subprojects/freediameter/extensions/dict_dcca_starent/dict_dcca_starent.c diff --git a/lib/freeDiameter/extensions/dict_dcca_starent/dict_dcca_starent.org b/subprojects/freediameter/extensions/dict_dcca_starent/dict_dcca_starent.org similarity index 100% rename from lib/freeDiameter/extensions/dict_dcca_starent/dict_dcca_starent.org rename to subprojects/freediameter/extensions/dict_dcca_starent/dict_dcca_starent.org diff --git a/lib/freeDiameter/extensions/dict_eap/CMakeLists.txt b/subprojects/freediameter/extensions/dict_eap/CMakeLists.txt similarity index 100% rename from lib/freeDiameter/extensions/dict_eap/CMakeLists.txt rename to subprojects/freediameter/extensions/dict_eap/CMakeLists.txt diff --git a/lib/freeDiameter/extensions/dict_eap/dict_eap.c b/subprojects/freediameter/extensions/dict_eap/dict_eap.c similarity index 100% rename from lib/freeDiameter/extensions/dict_eap/dict_eap.c rename to subprojects/freediameter/extensions/dict_eap/dict_eap.c diff --git a/lib/freeDiameter/extensions/dict_legacy_xml/CMakeLists.txt b/subprojects/freediameter/extensions/dict_legacy_xml/CMakeLists.txt similarity index 100% rename from lib/freeDiameter/extensions/dict_legacy_xml/CMakeLists.txt rename to subprojects/freediameter/extensions/dict_legacy_xml/CMakeLists.txt diff --git a/lib/freeDiameter/extensions/dict_legacy_xml/dict_lxml.c b/subprojects/freediameter/extensions/dict_legacy_xml/dict_lxml.c similarity index 100% rename from lib/freeDiameter/extensions/dict_legacy_xml/dict_lxml.c rename to subprojects/freediameter/extensions/dict_legacy_xml/dict_lxml.c diff --git a/lib/freeDiameter/extensions/dict_legacy_xml/dict_lxml.h b/subprojects/freediameter/extensions/dict_legacy_xml/dict_lxml.h similarity index 100% rename from lib/freeDiameter/extensions/dict_legacy_xml/dict_lxml.h rename to subprojects/freediameter/extensions/dict_legacy_xml/dict_lxml.h diff --git a/lib/freeDiameter/extensions/dict_legacy_xml/dict_lxml.l b/subprojects/freediameter/extensions/dict_legacy_xml/dict_lxml.l similarity index 100% rename from lib/freeDiameter/extensions/dict_legacy_xml/dict_lxml.l rename to subprojects/freediameter/extensions/dict_legacy_xml/dict_lxml.l diff --git a/lib/freeDiameter/extensions/dict_legacy_xml/dict_lxml.y b/subprojects/freediameter/extensions/dict_legacy_xml/dict_lxml.y similarity index 100% rename from lib/freeDiameter/extensions/dict_legacy_xml/dict_lxml.y rename to subprojects/freediameter/extensions/dict_legacy_xml/dict_lxml.y diff --git a/lib/freeDiameter/extensions/dict_legacy_xml/dict_lxml_xml.c b/subprojects/freediameter/extensions/dict_legacy_xml/dict_lxml_xml.c similarity index 100% rename from lib/freeDiameter/extensions/dict_legacy_xml/dict_lxml_xml.c rename to subprojects/freediameter/extensions/dict_legacy_xml/dict_lxml_xml.c diff --git a/lib/freeDiameter/extensions/dict_mip6a/CMakeLists.txt b/subprojects/freediameter/extensions/dict_mip6a/CMakeLists.txt similarity index 100% rename from lib/freeDiameter/extensions/dict_mip6a/CMakeLists.txt rename to subprojects/freediameter/extensions/dict_mip6a/CMakeLists.txt diff --git a/lib/freeDiameter/extensions/dict_mip6a/dict_mip6a.c b/subprojects/freediameter/extensions/dict_mip6a/dict_mip6a.c similarity index 100% rename from lib/freeDiameter/extensions/dict_mip6a/dict_mip6a.c rename to subprojects/freediameter/extensions/dict_mip6a/dict_mip6a.c diff --git a/lib/freeDiameter/extensions/dict_mip6i/CMakeLists.txt b/subprojects/freediameter/extensions/dict_mip6i/CMakeLists.txt similarity index 100% rename from lib/freeDiameter/extensions/dict_mip6i/CMakeLists.txt rename to subprojects/freediameter/extensions/dict_mip6i/CMakeLists.txt diff --git a/lib/freeDiameter/extensions/dict_mip6i/dict_mip6i.c b/subprojects/freediameter/extensions/dict_mip6i/dict_mip6i.c similarity index 100% rename from lib/freeDiameter/extensions/dict_mip6i/dict_mip6i.c rename to subprojects/freediameter/extensions/dict_mip6i/dict_mip6i.c diff --git a/lib/freeDiameter/extensions/dict_nas_mipv6/CMakeLists.txt b/subprojects/freediameter/extensions/dict_nas_mipv6/CMakeLists.txt similarity index 100% rename from lib/freeDiameter/extensions/dict_nas_mipv6/CMakeLists.txt rename to subprojects/freediameter/extensions/dict_nas_mipv6/CMakeLists.txt diff --git a/lib/freeDiameter/extensions/dict_nas_mipv6/dict_nas_mipv6.c b/subprojects/freediameter/extensions/dict_nas_mipv6/dict_nas_mipv6.c similarity index 100% rename from lib/freeDiameter/extensions/dict_nas_mipv6/dict_nas_mipv6.c rename to subprojects/freediameter/extensions/dict_nas_mipv6/dict_nas_mipv6.c diff --git a/lib/freeDiameter/extensions/dict_nasreq/CMakeLists.txt b/subprojects/freediameter/extensions/dict_nasreq/CMakeLists.txt similarity index 100% rename from lib/freeDiameter/extensions/dict_nasreq/CMakeLists.txt rename to subprojects/freediameter/extensions/dict_nasreq/CMakeLists.txt diff --git a/lib/freeDiameter/extensions/dict_nasreq/dict_nasreq.c b/subprojects/freediameter/extensions/dict_nasreq/dict_nasreq.c similarity index 100% rename from lib/freeDiameter/extensions/dict_nasreq/dict_nasreq.c rename to subprojects/freediameter/extensions/dict_nasreq/dict_nasreq.c diff --git a/lib/freeDiameter/extensions/dict_rfc5777/CMakeLists.txt b/subprojects/freediameter/extensions/dict_rfc5777/CMakeLists.txt similarity index 100% rename from lib/freeDiameter/extensions/dict_rfc5777/CMakeLists.txt rename to subprojects/freediameter/extensions/dict_rfc5777/CMakeLists.txt diff --git a/lib/freeDiameter/extensions/dict_rfc5777/dict_rfc5777.c b/subprojects/freediameter/extensions/dict_rfc5777/dict_rfc5777.c similarity index 100% rename from lib/freeDiameter/extensions/dict_rfc5777/dict_rfc5777.c rename to subprojects/freediameter/extensions/dict_rfc5777/dict_rfc5777.c diff --git a/lib/freeDiameter/extensions/dict_s6a/dict_s6a.c b/subprojects/freediameter/extensions/dict_s6a/dict_s6a.c similarity index 99% rename from lib/freeDiameter/extensions/dict_s6a/dict_s6a.c rename to subprojects/freediameter/extensions/dict_s6a/dict_s6a.c index 28c351ad2..20e082457 100644 --- a/lib/freeDiameter/extensions/dict_s6a/dict_s6a.c +++ b/subprojects/freediameter/extensions/dict_s6a/dict_s6a.c @@ -2,7 +2,7 @@ * Software License Agreement (BSD License) * * Author: Sukchan Lee > * * * - * Copyright (c) 2017, NextEPC Group + * Copyright (c) 2017, Open5gs Group * All rights reserved. * * * * Written under contract by nfotex IT GmbH, http://nfotex.com/ * diff --git a/lib/freeDiameter/extensions/dict_sip/CMakeLists.txt b/subprojects/freediameter/extensions/dict_sip/CMakeLists.txt similarity index 100% rename from lib/freeDiameter/extensions/dict_sip/CMakeLists.txt rename to subprojects/freediameter/extensions/dict_sip/CMakeLists.txt diff --git a/lib/freeDiameter/extensions/dict_sip/dict_sip.c b/subprojects/freediameter/extensions/dict_sip/dict_sip.c similarity index 100% rename from lib/freeDiameter/extensions/dict_sip/dict_sip.c rename to subprojects/freediameter/extensions/dict_sip/dict_sip.c diff --git a/subprojects/freediameter/extensions/meson.build b/subprojects/freediameter/extensions/meson.build new file mode 100644 index 000000000..6181997bd --- /dev/null +++ b/subprojects/freediameter/extensions/meson.build @@ -0,0 +1,38 @@ +# Copyright (C) 2019 by Sukchan Lee + +# This file is part of Open5GS. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +fd_ext_sources = (''' + dbg_msg_dumps + dict_rfc5777 + dict_mip6i + dict_nasreq + dict_nas_mipv6 + dict_dcca + dict_dcca_3gpp + dict_s6a +'''.split()) + +foreach s : fd_ext_sources + shared_module(s, + sources : [files(join_paths(s, s+'.c'))], + include_directories : freeDiameter_includes, + dependencies : [libfdcore_dep], + name_prefix : '', + name_suffix : 'fdx', + install : true, + install_dir : freeDiameter_extensionsdir) +endforeach diff --git a/lib/freeDiameter/extensions/rt_busypeers/CMakeLists.txt b/subprojects/freediameter/extensions/rt_busypeers/CMakeLists.txt similarity index 100% rename from lib/freeDiameter/extensions/rt_busypeers/CMakeLists.txt rename to subprojects/freediameter/extensions/rt_busypeers/CMakeLists.txt diff --git a/lib/freeDiameter/extensions/rt_busypeers/rtbusy.c b/subprojects/freediameter/extensions/rt_busypeers/rtbusy.c similarity index 100% rename from lib/freeDiameter/extensions/rt_busypeers/rtbusy.c rename to subprojects/freediameter/extensions/rt_busypeers/rtbusy.c diff --git a/lib/freeDiameter/extensions/rt_busypeers/rtbusy.h b/subprojects/freediameter/extensions/rt_busypeers/rtbusy.h similarity index 100% rename from lib/freeDiameter/extensions/rt_busypeers/rtbusy.h rename to subprojects/freediameter/extensions/rt_busypeers/rtbusy.h diff --git a/lib/freeDiameter/extensions/rt_busypeers/rtbusy_conf.l b/subprojects/freediameter/extensions/rt_busypeers/rtbusy_conf.l similarity index 100% rename from lib/freeDiameter/extensions/rt_busypeers/rtbusy_conf.l rename to subprojects/freediameter/extensions/rt_busypeers/rtbusy_conf.l diff --git a/lib/freeDiameter/extensions/rt_busypeers/rtbusy_conf.y b/subprojects/freediameter/extensions/rt_busypeers/rtbusy_conf.y similarity index 100% rename from lib/freeDiameter/extensions/rt_busypeers/rtbusy_conf.y rename to subprojects/freediameter/extensions/rt_busypeers/rtbusy_conf.y diff --git a/lib/freeDiameter/extensions/rt_default/CMakeLists.txt b/subprojects/freediameter/extensions/rt_default/CMakeLists.txt similarity index 100% rename from lib/freeDiameter/extensions/rt_default/CMakeLists.txt rename to subprojects/freediameter/extensions/rt_default/CMakeLists.txt diff --git a/lib/freeDiameter/extensions/rt_default/rt_default-host.h.in b/subprojects/freediameter/extensions/rt_default/rt_default-host.h.in similarity index 100% rename from lib/freeDiameter/extensions/rt_default/rt_default-host.h.in rename to subprojects/freediameter/extensions/rt_default/rt_default-host.h.in diff --git a/lib/freeDiameter/extensions/rt_default/rt_default.c b/subprojects/freediameter/extensions/rt_default/rt_default.c similarity index 100% rename from lib/freeDiameter/extensions/rt_default/rt_default.c rename to subprojects/freediameter/extensions/rt_default/rt_default.c diff --git a/lib/freeDiameter/extensions/rt_default/rt_default.h b/subprojects/freediameter/extensions/rt_default/rt_default.h similarity index 100% rename from lib/freeDiameter/extensions/rt_default/rt_default.h rename to subprojects/freediameter/extensions/rt_default/rt_default.h diff --git a/lib/freeDiameter/extensions/rt_default/rtd_conf.l b/subprojects/freediameter/extensions/rt_default/rtd_conf.l similarity index 100% rename from lib/freeDiameter/extensions/rt_default/rtd_conf.l rename to subprojects/freediameter/extensions/rt_default/rtd_conf.l diff --git a/lib/freeDiameter/extensions/rt_default/rtd_conf.y b/subprojects/freediameter/extensions/rt_default/rtd_conf.y similarity index 100% rename from lib/freeDiameter/extensions/rt_default/rtd_conf.y rename to subprojects/freediameter/extensions/rt_default/rtd_conf.y diff --git a/lib/freeDiameter/extensions/rt_default/rtd_rules.c b/subprojects/freediameter/extensions/rt_default/rtd_rules.c similarity index 100% rename from lib/freeDiameter/extensions/rt_default/rtd_rules.c rename to subprojects/freediameter/extensions/rt_default/rtd_rules.c diff --git a/lib/freeDiameter/extensions/rt_ereg/CMakeLists.txt b/subprojects/freediameter/extensions/rt_ereg/CMakeLists.txt similarity index 100% rename from lib/freeDiameter/extensions/rt_ereg/CMakeLists.txt rename to subprojects/freediameter/extensions/rt_ereg/CMakeLists.txt diff --git a/lib/freeDiameter/extensions/rt_ereg/rtereg.c b/subprojects/freediameter/extensions/rt_ereg/rtereg.c similarity index 100% rename from lib/freeDiameter/extensions/rt_ereg/rtereg.c rename to subprojects/freediameter/extensions/rt_ereg/rtereg.c diff --git a/lib/freeDiameter/extensions/rt_ereg/rtereg.h b/subprojects/freediameter/extensions/rt_ereg/rtereg.h similarity index 100% rename from lib/freeDiameter/extensions/rt_ereg/rtereg.h rename to subprojects/freediameter/extensions/rt_ereg/rtereg.h diff --git a/lib/freeDiameter/extensions/rt_ereg/rtereg_conf.l b/subprojects/freediameter/extensions/rt_ereg/rtereg_conf.l similarity index 100% rename from lib/freeDiameter/extensions/rt_ereg/rtereg_conf.l rename to subprojects/freediameter/extensions/rt_ereg/rtereg_conf.l diff --git a/lib/freeDiameter/extensions/rt_ereg/rtereg_conf.y b/subprojects/freediameter/extensions/rt_ereg/rtereg_conf.y similarity index 100% rename from lib/freeDiameter/extensions/rt_ereg/rtereg_conf.y rename to subprojects/freediameter/extensions/rt_ereg/rtereg_conf.y diff --git a/lib/freeDiameter/extensions/rt_ignore_dh/CMakeLists.txt b/subprojects/freediameter/extensions/rt_ignore_dh/CMakeLists.txt similarity index 100% rename from lib/freeDiameter/extensions/rt_ignore_dh/CMakeLists.txt rename to subprojects/freediameter/extensions/rt_ignore_dh/CMakeLists.txt diff --git a/lib/freeDiameter/extensions/rt_ignore_dh/rt_ignore_dh.c b/subprojects/freediameter/extensions/rt_ignore_dh/rt_ignore_dh.c similarity index 100% rename from lib/freeDiameter/extensions/rt_ignore_dh/rt_ignore_dh.c rename to subprojects/freediameter/extensions/rt_ignore_dh/rt_ignore_dh.c diff --git a/lib/freeDiameter/extensions/rt_load_balance/CMakeLists.txt b/subprojects/freediameter/extensions/rt_load_balance/CMakeLists.txt similarity index 100% rename from lib/freeDiameter/extensions/rt_load_balance/CMakeLists.txt rename to subprojects/freediameter/extensions/rt_load_balance/CMakeLists.txt diff --git a/lib/freeDiameter/extensions/rt_load_balance/rt_load_balance.c b/subprojects/freediameter/extensions/rt_load_balance/rt_load_balance.c similarity index 100% rename from lib/freeDiameter/extensions/rt_load_balance/rt_load_balance.c rename to subprojects/freediameter/extensions/rt_load_balance/rt_load_balance.c diff --git a/lib/freeDiameter/extensions/rt_randomize/CMakeLists.txt b/subprojects/freediameter/extensions/rt_randomize/CMakeLists.txt similarity index 100% rename from lib/freeDiameter/extensions/rt_randomize/CMakeLists.txt rename to subprojects/freediameter/extensions/rt_randomize/CMakeLists.txt diff --git a/lib/freeDiameter/extensions/rt_randomize/rt_randomize.c b/subprojects/freediameter/extensions/rt_randomize/rt_randomize.c similarity index 100% rename from lib/freeDiameter/extensions/rt_randomize/rt_randomize.c rename to subprojects/freediameter/extensions/rt_randomize/rt_randomize.c diff --git a/lib/freeDiameter/extensions/rt_redirect/CMakeLists.txt b/subprojects/freediameter/extensions/rt_redirect/CMakeLists.txt similarity index 100% rename from lib/freeDiameter/extensions/rt_redirect/CMakeLists.txt rename to subprojects/freediameter/extensions/rt_redirect/CMakeLists.txt diff --git a/lib/freeDiameter/extensions/rt_redirect/redir_entries.c b/subprojects/freediameter/extensions/rt_redirect/redir_entries.c similarity index 100% rename from lib/freeDiameter/extensions/rt_redirect/redir_entries.c rename to subprojects/freediameter/extensions/rt_redirect/redir_entries.c diff --git a/lib/freeDiameter/extensions/rt_redirect/redir_expiry.c b/subprojects/freediameter/extensions/rt_redirect/redir_expiry.c similarity index 100% rename from lib/freeDiameter/extensions/rt_redirect/redir_expiry.c rename to subprojects/freediameter/extensions/rt_redirect/redir_expiry.c diff --git a/lib/freeDiameter/extensions/rt_redirect/redir_fwd.c b/subprojects/freediameter/extensions/rt_redirect/redir_fwd.c similarity index 100% rename from lib/freeDiameter/extensions/rt_redirect/redir_fwd.c rename to subprojects/freediameter/extensions/rt_redirect/redir_fwd.c diff --git a/lib/freeDiameter/extensions/rt_redirect/redir_out.c b/subprojects/freediameter/extensions/rt_redirect/redir_out.c similarity index 100% rename from lib/freeDiameter/extensions/rt_redirect/redir_out.c rename to subprojects/freediameter/extensions/rt_redirect/redir_out.c diff --git a/lib/freeDiameter/extensions/rt_redirect/rt_redir.c b/subprojects/freediameter/extensions/rt_redirect/rt_redir.c similarity index 100% rename from lib/freeDiameter/extensions/rt_redirect/rt_redir.c rename to subprojects/freediameter/extensions/rt_redirect/rt_redir.c diff --git a/lib/freeDiameter/extensions/rt_redirect/rt_redir.h b/subprojects/freediameter/extensions/rt_redirect/rt_redir.h similarity index 100% rename from lib/freeDiameter/extensions/rt_redirect/rt_redir.h rename to subprojects/freediameter/extensions/rt_redirect/rt_redir.h diff --git a/lib/freeDiameter/extensions/rt_redirect/uthash.h b/subprojects/freediameter/extensions/rt_redirect/uthash.h similarity index 100% rename from lib/freeDiameter/extensions/rt_redirect/uthash.h rename to subprojects/freediameter/extensions/rt_redirect/uthash.h diff --git a/lib/freeDiameter/extensions/test_acct/CMakeLists.txt b/subprojects/freediameter/extensions/test_acct/CMakeLists.txt similarity index 100% rename from lib/freeDiameter/extensions/test_acct/CMakeLists.txt rename to subprojects/freediameter/extensions/test_acct/CMakeLists.txt diff --git a/lib/freeDiameter/extensions/test_acct/test_acct.c b/subprojects/freediameter/extensions/test_acct/test_acct.c similarity index 100% rename from lib/freeDiameter/extensions/test_acct/test_acct.c rename to subprojects/freediameter/extensions/test_acct/test_acct.c diff --git a/lib/freeDiameter/extensions/test_app/CMakeLists.txt b/subprojects/freediameter/extensions/test_app/CMakeLists.txt similarity index 100% rename from lib/freeDiameter/extensions/test_app/CMakeLists.txt rename to subprojects/freediameter/extensions/test_app/CMakeLists.txt diff --git a/lib/freeDiameter/extensions/test_app/ta_bench.c b/subprojects/freediameter/extensions/test_app/ta_bench.c similarity index 100% rename from lib/freeDiameter/extensions/test_app/ta_bench.c rename to subprojects/freediameter/extensions/test_app/ta_bench.c diff --git a/lib/freeDiameter/extensions/test_app/ta_cli.c b/subprojects/freediameter/extensions/test_app/ta_cli.c similarity index 100% rename from lib/freeDiameter/extensions/test_app/ta_cli.c rename to subprojects/freediameter/extensions/test_app/ta_cli.c diff --git a/lib/freeDiameter/extensions/test_app/ta_conf.l b/subprojects/freediameter/extensions/test_app/ta_conf.l similarity index 100% rename from lib/freeDiameter/extensions/test_app/ta_conf.l rename to subprojects/freediameter/extensions/test_app/ta_conf.l diff --git a/lib/freeDiameter/extensions/test_app/ta_conf.y b/subprojects/freediameter/extensions/test_app/ta_conf.y similarity index 100% rename from lib/freeDiameter/extensions/test_app/ta_conf.y rename to subprojects/freediameter/extensions/test_app/ta_conf.y diff --git a/lib/freeDiameter/extensions/test_app/ta_dict.c b/subprojects/freediameter/extensions/test_app/ta_dict.c similarity index 100% rename from lib/freeDiameter/extensions/test_app/ta_dict.c rename to subprojects/freediameter/extensions/test_app/ta_dict.c diff --git a/lib/freeDiameter/extensions/test_app/ta_serv.c b/subprojects/freediameter/extensions/test_app/ta_serv.c similarity index 100% rename from lib/freeDiameter/extensions/test_app/ta_serv.c rename to subprojects/freediameter/extensions/test_app/ta_serv.c diff --git a/lib/freeDiameter/extensions/test_app/test_app.c b/subprojects/freediameter/extensions/test_app/test_app.c similarity index 100% rename from lib/freeDiameter/extensions/test_app/test_app.c rename to subprojects/freediameter/extensions/test_app/test_app.c diff --git a/lib/freeDiameter/extensions/test_app/test_app.h b/subprojects/freediameter/extensions/test_app/test_app.h similarity index 100% rename from lib/freeDiameter/extensions/test_app/test_app.h rename to subprojects/freediameter/extensions/test_app/test_app.h diff --git a/lib/freeDiameter/extensions/test_netemul/CMakeLists.txt b/subprojects/freediameter/extensions/test_netemul/CMakeLists.txt similarity index 100% rename from lib/freeDiameter/extensions/test_netemul/CMakeLists.txt rename to subprojects/freediameter/extensions/test_netemul/CMakeLists.txt diff --git a/lib/freeDiameter/extensions/test_netemul/test_netemul.c b/subprojects/freediameter/extensions/test_netemul/test_netemul.c similarity index 100% rename from lib/freeDiameter/extensions/test_netemul/test_netemul.c rename to subprojects/freediameter/extensions/test_netemul/test_netemul.c diff --git a/lib/freeDiameter/extensions/test_netemul/test_netemul.h b/subprojects/freediameter/extensions/test_netemul/test_netemul.h similarity index 100% rename from lib/freeDiameter/extensions/test_netemul/test_netemul.h rename to subprojects/freediameter/extensions/test_netemul/test_netemul.h diff --git a/lib/freeDiameter/extensions/test_netemul/test_netemul.l b/subprojects/freediameter/extensions/test_netemul/test_netemul.l similarity index 100% rename from lib/freeDiameter/extensions/test_netemul/test_netemul.l rename to subprojects/freediameter/extensions/test_netemul/test_netemul.l diff --git a/lib/freeDiameter/extensions/test_netemul/test_netemul.y b/subprojects/freediameter/extensions/test_netemul/test_netemul.y similarity index 100% rename from lib/freeDiameter/extensions/test_netemul/test_netemul.y rename to subprojects/freediameter/extensions/test_netemul/test_netemul.y diff --git a/lib/freeDiameter/extensions/test_netemul/tne_process.c b/subprojects/freediameter/extensions/test_netemul/tne_process.c similarity index 100% rename from lib/freeDiameter/extensions/test_netemul/tne_process.c rename to subprojects/freediameter/extensions/test_netemul/tne_process.c diff --git a/lib/freeDiameter/extensions/test_rt_any/CMakeLists.txt b/subprojects/freediameter/extensions/test_rt_any/CMakeLists.txt similarity index 100% rename from lib/freeDiameter/extensions/test_rt_any/CMakeLists.txt rename to subprojects/freediameter/extensions/test_rt_any/CMakeLists.txt diff --git a/lib/freeDiameter/extensions/test_rt_any/test_rt_any.c b/subprojects/freediameter/extensions/test_rt_any/test_rt_any.c similarity index 100% rename from lib/freeDiameter/extensions/test_rt_any/test_rt_any.c rename to subprojects/freediameter/extensions/test_rt_any/test_rt_any.c diff --git a/lib/freeDiameter/extensions/test_sip/CMakeLists.txt b/subprojects/freediameter/extensions/test_sip/CMakeLists.txt similarity index 100% rename from lib/freeDiameter/extensions/test_sip/CMakeLists.txt rename to subprojects/freediameter/extensions/test_sip/CMakeLists.txt diff --git a/lib/freeDiameter/extensions/test_sip/locationinfo.c b/subprojects/freediameter/extensions/test_sip/locationinfo.c similarity index 100% rename from lib/freeDiameter/extensions/test_sip/locationinfo.c rename to subprojects/freediameter/extensions/test_sip/locationinfo.c diff --git a/lib/freeDiameter/extensions/test_sip/locationinfosl.c b/subprojects/freediameter/extensions/test_sip/locationinfosl.c similarity index 100% rename from lib/freeDiameter/extensions/test_sip/locationinfosl.c rename to subprojects/freediameter/extensions/test_sip/locationinfosl.c diff --git a/lib/freeDiameter/extensions/test_sip/multimediaauth.c b/subprojects/freediameter/extensions/test_sip/multimediaauth.c similarity index 100% rename from lib/freeDiameter/extensions/test_sip/multimediaauth.c rename to subprojects/freediameter/extensions/test_sip/multimediaauth.c diff --git a/lib/freeDiameter/extensions/test_sip/registrationtermination.c b/subprojects/freediameter/extensions/test_sip/registrationtermination.c similarity index 100% rename from lib/freeDiameter/extensions/test_sip/registrationtermination.c rename to subprojects/freediameter/extensions/test_sip/registrationtermination.c diff --git a/lib/freeDiameter/extensions/test_sip/serverassignment.c b/subprojects/freediameter/extensions/test_sip/serverassignment.c similarity index 100% rename from lib/freeDiameter/extensions/test_sip/serverassignment.c rename to subprojects/freediameter/extensions/test_sip/serverassignment.c diff --git a/lib/freeDiameter/extensions/test_sip/test_sip.c b/subprojects/freediameter/extensions/test_sip/test_sip.c similarity index 100% rename from lib/freeDiameter/extensions/test_sip/test_sip.c rename to subprojects/freediameter/extensions/test_sip/test_sip.c diff --git a/lib/freeDiameter/extensions/test_sip/test_sip.h b/subprojects/freediameter/extensions/test_sip/test_sip.h similarity index 100% rename from lib/freeDiameter/extensions/test_sip/test_sip.h rename to subprojects/freediameter/extensions/test_sip/test_sip.h diff --git a/lib/freeDiameter/extensions/test_sip/test_sip.l b/subprojects/freediameter/extensions/test_sip/test_sip.l similarity index 100% rename from lib/freeDiameter/extensions/test_sip/test_sip.l rename to subprojects/freediameter/extensions/test_sip/test_sip.l diff --git a/lib/freeDiameter/extensions/test_sip/test_sip.y b/subprojects/freediameter/extensions/test_sip/test_sip.y similarity index 100% rename from lib/freeDiameter/extensions/test_sip/test_sip.y rename to subprojects/freediameter/extensions/test_sip/test_sip.y diff --git a/lib/freeDiameter/extensions/test_sip/userauthorization.c b/subprojects/freediameter/extensions/test_sip/userauthorization.c similarity index 100% rename from lib/freeDiameter/extensions/test_sip/userauthorization.c rename to subprojects/freediameter/extensions/test_sip/userauthorization.c diff --git a/lib/freeDiameter/freeDiameterd/CMakeLists.txt b/subprojects/freediameter/freeDiameterd/CMakeLists.txt similarity index 100% rename from lib/freeDiameter/freeDiameterd/CMakeLists.txt rename to subprojects/freediameter/freeDiameterd/CMakeLists.txt diff --git a/lib/freeDiameter/freeDiameterd/main.c b/subprojects/freediameter/freeDiameterd/main.c similarity index 100% rename from lib/freeDiameter/freeDiameterd/main.c rename to subprojects/freediameter/freeDiameterd/main.c diff --git a/lib/freeDiameter/include/freeDiameter/CMakeLists.txt b/subprojects/freediameter/include/freeDiameter/CMakeLists.txt similarity index 100% rename from lib/freeDiameter/include/freeDiameter/CMakeLists.txt rename to subprojects/freediameter/include/freeDiameter/CMakeLists.txt diff --git a/lib/freeDiameter/include/freeDiameter/extension.h b/subprojects/freediameter/include/freeDiameter/extension.h similarity index 100% rename from lib/freeDiameter/include/freeDiameter/extension.h rename to subprojects/freediameter/include/freeDiameter/extension.h diff --git a/lib/freeDiameter/include/freeDiameter/freeDiameter-host.h.in b/subprojects/freediameter/include/freeDiameter/freeDiameter-host.h.in similarity index 100% rename from lib/freeDiameter/include/freeDiameter/freeDiameter-host.h.in rename to subprojects/freediameter/include/freeDiameter/freeDiameter-host.h.in diff --git a/lib/freeDiameter/include/freeDiameter/freeDiameter-host.hin b/subprojects/freediameter/include/freeDiameter/freeDiameter-host.hin similarity index 100% rename from lib/freeDiameter/include/freeDiameter/freeDiameter-host.hin rename to subprojects/freediameter/include/freeDiameter/freeDiameter-host.hin diff --git a/lib/freeDiameter/include/freeDiameter/libfdcore.h b/subprojects/freediameter/include/freeDiameter/libfdcore.h similarity index 100% rename from lib/freeDiameter/include/freeDiameter/libfdcore.h rename to subprojects/freediameter/include/freeDiameter/libfdcore.h diff --git a/lib/freeDiameter/include/freeDiameter/libfdproto.h b/subprojects/freediameter/include/freeDiameter/libfdproto.h similarity index 100% rename from lib/freeDiameter/include/freeDiameter/libfdproto.h rename to subprojects/freediameter/include/freeDiameter/libfdproto.h diff --git a/subprojects/freediameter/include/freeDiameter/meson.build b/subprojects/freediameter/include/freeDiameter/meson.build new file mode 100644 index 000000000..dc92592cb --- /dev/null +++ b/subprojects/freediameter/include/freeDiameter/meson.build @@ -0,0 +1,188 @@ +# Copyright (C) 2019 by Sukchan Lee + +# This file is part of Open5GS. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +freeDiameter_version = '1.2.1' +freeDiameter_host_conf = configuration_data() +freeDiameter_version_conf = configuration_data() + +freeDiameter_sysconfdir = join_paths(sysconfdir, 'freeDiameter') +freeDiameter_extensionsdir = join_paths(libdir, 'freeDiameter') + +# Informations to display in daemon's help +freeDiameter_host_conf.set_quoted('FD_PROJECT_BINARY', meson.project_name() + 'd') +freeDiameter_host_conf.set_quoted('FD_PROJECT_NAME', meson.project_name()) +freeDiameter_host_conf.set_quoted('FD_PROJECT_VERSION', freeDiameter_version) +freeDiameter_host_conf.set_quoted('FD_PROJECT_COPYRIGHT', 'Copyright (c) 2008-2015, WIDE Project (www.wide.ad.jp) and NICT (www.nict.go.jp)') + +# Version of the source code +version_arr = freeDiameter_version.split('.') +freeDiameter_host_conf.set('FD_PROJECT_VERSION_MAJOR', version_arr[0].to_int()) +freeDiameter_host_conf.set('FD_PROJECT_VERSION_MINOR', version_arr[1].to_int()) +freeDiameter_host_conf.set('FD_PROJECT_VERSION_REV', version_arr[2].to_int()) + +# Version of the API with the library +freeDiameter_host_conf.set('FD_PROJECT_VERSION_API', 6) +freeDiameter_host_conf.set_quoted('DEFAULT_CONF_PATH', + freeDiameter_sysconfdir) +freeDiameter_host_conf.set_quoted('DEFAULT_EXTENSIONS_PATH', + freeDiameter_extensionsdir) +freeDiameter_host_conf.set_quoted('FD_DEFAULT_CONF_FILENAME', + 'freeDiameter.conf') + +if host_machine.endian() == 'big' + freeDiameter_host_conf.set('HOST_BIG_ENDIAN', 1) +endif + +freeDiameter_host_conf.set('FD_IS_CONFIG', true) +freeDiameter_host_conf.set('_GNU_SOURCE', true) +freeDiameter_host_conf.set('FD_HOOK_HANDLE_LIMIT', 5) + +freeDiameter_headers = (''' + malloc.h + signalent.h +'''.split()) + +foreach h : freeDiameter_headers + if cc.has_header(h) + define = 'HAVE_' + h.underscorify().to_upper() + freeDiameter_host_conf.set(define, 1) + endif +endforeach + +freeDiameter_functions = (''' + strndup + getopt_long + getifaddrs +'''.split()) + +foreach f : freeDiameter_functions + if cc.has_function(f) + define = 'HAVE_' + f.underscorify().to_upper() + freeDiameter_host_conf.set(define, 1) + set_variable('have_func_' + f, true) + else + set_variable('have_func_' + f, false) + endif +endforeach + +# Check for ntohll +if cc.has_header_symbol('netinet/in.h', 'ntohll') + freeDiameter_host_conf.set('HAVE_NTOHLL', 1) +endif + +# Check for AI_ADDRCONFIG +if cc.has_header_symbol('netdb.h', 'AI_ADDRCONFIG') + freeDiameter_host_conf.set('HAVE_AI_ADDRCONFIG', 1) +endif + +# Determination of thread implementation +threads = [] +if host_system == 'windows' and not get_option('force_posix_threads') +else + threads = dependency('threads') + if cc.has_header_symbol('pthread.h', 'pthread_barrier_wait') + freeDiameter_host_conf.set('HAVE_PTHREAD_BAR', 1) + endif +endif + +# Check for clock_gettime() +clock_gettime_test_code = ''' + #include + struct timespec t; + int main (int argc, char ** argv) { + return clock_gettime(CLOCK_REALTIME, &t); + }''' +librt = [] +if cc.links(clock_gettime_test_code, name : 'clock_gettime()') + freeDiameter_host_conf.set('HAVE_CLOCK_GETTIME', 1) +elif cc.links(clock_gettime_test_code, args : '-lrt', name : 'clock_gettime() in librt') + freeDiameter_host_conf.set('HAVE_CLOCK_GETTIME', 1) + librt = cc.find_library('rt') +elif cc.links(clock_gettime_test_code, args : '-lposix4', name : 'clock_gettime() in libposix4') + freeDiameter_host_conf.set('HAVE_CLOCK_GETTIME', 1) + librt = cc.find_library('posix4') +else + error('Could not find clock_gettime()') +endif + +# Check for dlopen() +dlopen_dlsym_test_code = ''' + #include + int underscore_test (void) { return 42; } + int main (int argc, char ** argv) { + void *f1 = (void*)0, *f2 = (void*)0, *handle; + handle = dlopen ((void*)0, 0); + if (handle) { + f1 = dlsym (handle, "underscore_test"); + f2 = dlsym (handle, "_underscore_test"); + } + return (!f2 || f1); + }''' +libdl = [] +if cc.links(dlopen_dlsym_test_code, name : 'dlopen() and dlsym() in system libraries') + freeDiameter_host_conf.set('HAVE_DLOPEN', 1) +elif cc.links(dlopen_dlsym_test_code, args : '-ldl', name : 'dlopen() and dlsym() in libdl') + freeDiameter_host_conf.set('HAVE_DLOPEN', 1) + libdl = cc.find_library('dl') +else + error('Could not find dlopen()') +endif + +# Check for gcrypt/idn library +libgcrypt = cc.find_library('gcrypt') +libidn = cc.find_library('idn') + +# Check for gnutls library +libgnutls = cc.find_library('gnutls') +if cc.has_function('gnutls_hash', args : '-lgnutls') + freeDiameter_host_conf.set('GNUTLS_VERSION_210', 1) +endif +if cc.has_function('gnutls_transport_set_vec_push_function', args : '-lgnutls') + freeDiameter_host_conf.set('GNUTLS_VERSION_212', 1) +endif +if cc.has_function('gnutls_x509_trust_list_verify_crt', args : '-lgnutls') + freeDiameter_host_conf.set('GNUTLS_VERSION_300', 1) +endif +if cc.has_function('gnutls_handshake_set_timeout', args : '-lgnutls') + freeDiameter_host_conf.set('GNUTLS_VERSION_310', 1) +endif + +# Check for SCTP +libsctp = cc.find_library('sctp', required : false) +if libsctp.found() + if cc.compiles('''#include + #include + int main (int argc, char ** argv) { + sctp_connectx(0, NULL, 0, NULL); + }''', name : 'sctp_connectx() accepts 4 arguments') + freeDiameter_host_conf.set('SCTP_CONNECTX_4_ARGS', 1) + endif + if host_system == 'freebsd' + freeDiameter_host_conf.set('SCTP_USE_MAPPED_ADDRESSES', 1) + endif +else + freeDiameter_host_conf.set('DISABLE_SCTP', 1) +endif + +configure_file(output : 'freeDiameter-host.h', + configuration : freeDiameter_host_conf, + install : false) + +configure_file(output : 'version.h', + configuration : freeDiameter_version_conf, + install : false) diff --git a/lib/freeDiameter/include/freeDiameter/version.h.in b/subprojects/freediameter/include/freeDiameter/version.h.in similarity index 100% rename from lib/freeDiameter/include/freeDiameter/version.h.in rename to subprojects/freediameter/include/freeDiameter/version.h.in diff --git a/lib/freeDiameter/libfdcore/CMakeLists.txt b/subprojects/freediameter/libfdcore/CMakeLists.txt similarity index 100% rename from lib/freeDiameter/libfdcore/CMakeLists.txt rename to subprojects/freediameter/libfdcore/CMakeLists.txt diff --git a/lib/freeDiameter/libfdcore/apps.c b/subprojects/freediameter/libfdcore/apps.c similarity index 100% rename from lib/freeDiameter/libfdcore/apps.c rename to subprojects/freediameter/libfdcore/apps.c diff --git a/lib/freeDiameter/libfdcore/cnxctx.c b/subprojects/freediameter/libfdcore/cnxctx.c similarity index 100% rename from lib/freeDiameter/libfdcore/cnxctx.c rename to subprojects/freediameter/libfdcore/cnxctx.c diff --git a/lib/freeDiameter/libfdcore/cnxctx.h b/subprojects/freediameter/libfdcore/cnxctx.h similarity index 100% rename from lib/freeDiameter/libfdcore/cnxctx.h rename to subprojects/freediameter/libfdcore/cnxctx.h diff --git a/lib/freeDiameter/libfdcore/config.c b/subprojects/freediameter/libfdcore/config.c similarity index 100% rename from lib/freeDiameter/libfdcore/config.c rename to subprojects/freediameter/libfdcore/config.c diff --git a/lib/freeDiameter/libfdcore/core.c b/subprojects/freediameter/libfdcore/core.c similarity index 100% rename from lib/freeDiameter/libfdcore/core.c rename to subprojects/freediameter/libfdcore/core.c diff --git a/lib/freeDiameter/libfdcore/dict_base_proto.c b/subprojects/freediameter/libfdcore/dict_base_proto.c similarity index 100% rename from lib/freeDiameter/libfdcore/dict_base_proto.c rename to subprojects/freediameter/libfdcore/dict_base_proto.c diff --git a/lib/freeDiameter/libfdcore/endpoints.c b/subprojects/freediameter/libfdcore/endpoints.c similarity index 100% rename from lib/freeDiameter/libfdcore/endpoints.c rename to subprojects/freediameter/libfdcore/endpoints.c diff --git a/lib/freeDiameter/libfdcore/events.c b/subprojects/freediameter/libfdcore/events.c similarity index 100% rename from lib/freeDiameter/libfdcore/events.c rename to subprojects/freediameter/libfdcore/events.c diff --git a/lib/freeDiameter/libfdcore/extensions.c b/subprojects/freediameter/libfdcore/extensions.c similarity index 100% rename from lib/freeDiameter/libfdcore/extensions.c rename to subprojects/freediameter/libfdcore/extensions.c diff --git a/lib/freeDiameter/libfdcore/fdcore-internal.h b/subprojects/freediameter/libfdcore/fdcore-internal.h similarity index 100% rename from lib/freeDiameter/libfdcore/fdcore-internal.h rename to subprojects/freediameter/libfdcore/fdcore-internal.h diff --git a/lib/freeDiameter/libfdcore/fdd.l b/subprojects/freediameter/libfdcore/fdd.l similarity index 100% rename from lib/freeDiameter/libfdcore/fdd.l rename to subprojects/freediameter/libfdcore/fdd.l diff --git a/lib/freeDiameter/libfdcore/fdd.y b/subprojects/freediameter/libfdcore/fdd.y similarity index 100% rename from lib/freeDiameter/libfdcore/fdd.y rename to subprojects/freediameter/libfdcore/fdd.y diff --git a/lib/freeDiameter/libfdcore/fifo_stats.c b/subprojects/freediameter/libfdcore/fifo_stats.c similarity index 100% rename from lib/freeDiameter/libfdcore/fifo_stats.c rename to subprojects/freediameter/libfdcore/fifo_stats.c diff --git a/lib/freeDiameter/libfdcore/hooks.c b/subprojects/freediameter/libfdcore/hooks.c similarity index 100% rename from lib/freeDiameter/libfdcore/hooks.c rename to subprojects/freediameter/libfdcore/hooks.c diff --git a/subprojects/freediameter/libfdcore/meson.build b/subprojects/freediameter/libfdcore/meson.build new file mode 100644 index 000000000..bbbd4aec8 --- /dev/null +++ b/subprojects/freediameter/libfdcore/meson.build @@ -0,0 +1,78 @@ +# Copyright (C) 2019 by Sukchan Lee + +# This file is part of Open5GS. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +fdcore_sources = files(''' + fdcore-internal.h + apps.c + cnxctx.h + config.c + core.c + cnxctx.c + endpoints.c + events.c + extensions.c + fifo_stats.c + hooks.c + dict_base_proto.c + messages.c + queues.c + peers.c + p_ce.c + p_cnx.c + p_dw.c + p_dp.c + p_expiry.c + p_out.c + p_psm.c + p_sr.c + routing_dispatch.c + server.c + tcp.c + version.c +'''.split()) + +if libsctp.found() +fdcore_sources += files('sctp.c', 'sctp3436.c') +endif + +lgen = generator(flex, + output : '@PLAINNAME@.yy.c', + arguments : ['-p', '-Cem', '-Pfdd', '-o', '@OUTPUT@', '@INPUT@']) + +lfiles = lgen.process('fdd.l') + +pgen = generator(bison, + output : ['@BASENAME@.tab.c', '@BASENAME@.tab.h'], + arguments : ['-p', 'fdd', '-d', + '@INPUT@', '--defines=@OUTPUT1@', '--output=@OUTPUT0@']) + +pfiles = pgen.process('fdd.y') + +libfdcore = library('fdcore', + sources : [lfiles, pfiles, fdcore_sources], + version : freeDiameter_version, + soversion : freeDiameter_soversion, + include_directories : freeDiameter_includes, + dependencies : [libfdproto_dep, + libdl, libsctp, libgcrypt, libgnutls], + install : true) + +libfdcore_dep = declare_dependency( + link_with : libfdcore, + include_directories : freeDiameter_includes, + dependencies : [libfdproto_dep, + libdl, libsctp, libgcrypt, libgnutls]) diff --git a/lib/freeDiameter/libfdcore/messages.c b/subprojects/freediameter/libfdcore/messages.c similarity index 100% rename from lib/freeDiameter/libfdcore/messages.c rename to subprojects/freediameter/libfdcore/messages.c diff --git a/lib/freeDiameter/libfdcore/p_ce.c b/subprojects/freediameter/libfdcore/p_ce.c similarity index 100% rename from lib/freeDiameter/libfdcore/p_ce.c rename to subprojects/freediameter/libfdcore/p_ce.c diff --git a/lib/freeDiameter/libfdcore/p_cnx.c b/subprojects/freediameter/libfdcore/p_cnx.c similarity index 100% rename from lib/freeDiameter/libfdcore/p_cnx.c rename to subprojects/freediameter/libfdcore/p_cnx.c diff --git a/lib/freeDiameter/libfdcore/p_dp.c b/subprojects/freediameter/libfdcore/p_dp.c similarity index 100% rename from lib/freeDiameter/libfdcore/p_dp.c rename to subprojects/freediameter/libfdcore/p_dp.c diff --git a/lib/freeDiameter/libfdcore/p_dw.c b/subprojects/freediameter/libfdcore/p_dw.c similarity index 100% rename from lib/freeDiameter/libfdcore/p_dw.c rename to subprojects/freediameter/libfdcore/p_dw.c diff --git a/lib/freeDiameter/libfdcore/p_expiry.c b/subprojects/freediameter/libfdcore/p_expiry.c similarity index 100% rename from lib/freeDiameter/libfdcore/p_expiry.c rename to subprojects/freediameter/libfdcore/p_expiry.c diff --git a/lib/freeDiameter/libfdcore/p_out.c b/subprojects/freediameter/libfdcore/p_out.c similarity index 100% rename from lib/freeDiameter/libfdcore/p_out.c rename to subprojects/freediameter/libfdcore/p_out.c diff --git a/lib/freeDiameter/libfdcore/p_psm.c b/subprojects/freediameter/libfdcore/p_psm.c similarity index 100% rename from lib/freeDiameter/libfdcore/p_psm.c rename to subprojects/freediameter/libfdcore/p_psm.c diff --git a/lib/freeDiameter/libfdcore/p_sr.c b/subprojects/freediameter/libfdcore/p_sr.c similarity index 100% rename from lib/freeDiameter/libfdcore/p_sr.c rename to subprojects/freediameter/libfdcore/p_sr.c diff --git a/lib/freeDiameter/libfdcore/peers.c b/subprojects/freediameter/libfdcore/peers.c similarity index 100% rename from lib/freeDiameter/libfdcore/peers.c rename to subprojects/freediameter/libfdcore/peers.c diff --git a/lib/freeDiameter/libfdcore/queues.c b/subprojects/freediameter/libfdcore/queues.c similarity index 100% rename from lib/freeDiameter/libfdcore/queues.c rename to subprojects/freediameter/libfdcore/queues.c diff --git a/lib/freeDiameter/libfdcore/routing_dispatch.c b/subprojects/freediameter/libfdcore/routing_dispatch.c similarity index 100% rename from lib/freeDiameter/libfdcore/routing_dispatch.c rename to subprojects/freediameter/libfdcore/routing_dispatch.c diff --git a/lib/freeDiameter/libfdcore/sctp.c b/subprojects/freediameter/libfdcore/sctp.c similarity index 100% rename from lib/freeDiameter/libfdcore/sctp.c rename to subprojects/freediameter/libfdcore/sctp.c diff --git a/lib/freeDiameter/libfdcore/sctp3436.c b/subprojects/freediameter/libfdcore/sctp3436.c similarity index 100% rename from lib/freeDiameter/libfdcore/sctp3436.c rename to subprojects/freediameter/libfdcore/sctp3436.c diff --git a/lib/freeDiameter/libfdcore/server.c b/subprojects/freediameter/libfdcore/server.c similarity index 100% rename from lib/freeDiameter/libfdcore/server.c rename to subprojects/freediameter/libfdcore/server.c diff --git a/lib/freeDiameter/libfdcore/tcp.c b/subprojects/freediameter/libfdcore/tcp.c similarity index 100% rename from lib/freeDiameter/libfdcore/tcp.c rename to subprojects/freediameter/libfdcore/tcp.c diff --git a/lib/freeDiameter/libfdcore/version.c b/subprojects/freediameter/libfdcore/version.c similarity index 100% rename from lib/freeDiameter/libfdcore/version.c rename to subprojects/freediameter/libfdcore/version.c diff --git a/lib/freeDiameter/libfdproto/CMakeLists.txt b/subprojects/freediameter/libfdproto/CMakeLists.txt similarity index 100% rename from lib/freeDiameter/libfdproto/CMakeLists.txt rename to subprojects/freediameter/libfdproto/CMakeLists.txt diff --git a/lib/freeDiameter/libfdproto/dictionary.c b/subprojects/freediameter/libfdproto/dictionary.c similarity index 100% rename from lib/freeDiameter/libfdproto/dictionary.c rename to subprojects/freediameter/libfdproto/dictionary.c diff --git a/lib/freeDiameter/libfdproto/dictionary_functions.c b/subprojects/freediameter/libfdproto/dictionary_functions.c similarity index 100% rename from lib/freeDiameter/libfdproto/dictionary_functions.c rename to subprojects/freediameter/libfdproto/dictionary_functions.c diff --git a/lib/freeDiameter/libfdproto/dispatch.c b/subprojects/freediameter/libfdproto/dispatch.c similarity index 100% rename from lib/freeDiameter/libfdproto/dispatch.c rename to subprojects/freediameter/libfdproto/dispatch.c diff --git a/lib/freeDiameter/libfdproto/fdproto-internal.h b/subprojects/freediameter/libfdproto/fdproto-internal.h similarity index 100% rename from lib/freeDiameter/libfdproto/fdproto-internal.h rename to subprojects/freediameter/libfdproto/fdproto-internal.h diff --git a/lib/freeDiameter/libfdproto/fifo.c b/subprojects/freediameter/libfdproto/fifo.c similarity index 100% rename from lib/freeDiameter/libfdproto/fifo.c rename to subprojects/freediameter/libfdproto/fifo.c diff --git a/lib/freeDiameter/libfdproto/init.c b/subprojects/freediameter/libfdproto/init.c similarity index 100% rename from lib/freeDiameter/libfdproto/init.c rename to subprojects/freediameter/libfdproto/init.c diff --git a/lib/freeDiameter/libfdproto/lists.c b/subprojects/freediameter/libfdproto/lists.c similarity index 100% rename from lib/freeDiameter/libfdproto/lists.c rename to subprojects/freediameter/libfdproto/lists.c diff --git a/lib/freeDiameter/libfdproto/log.c b/subprojects/freediameter/libfdproto/log.c similarity index 100% rename from lib/freeDiameter/libfdproto/log.c rename to subprojects/freediameter/libfdproto/log.c diff --git a/subprojects/freediameter/libfdproto/meson.build b/subprojects/freediameter/libfdproto/meson.build new file mode 100644 index 000000000..1bf09630b --- /dev/null +++ b/subprojects/freediameter/libfdproto/meson.build @@ -0,0 +1,48 @@ +# Copyright (C) 2019 by Sukchan Lee + +# This file is part of Open5GS. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +fdproto_sources = files(''' + fdproto-internal.h + dictionary.c + dictionary_functions.c + dispatch.c + fifo.c + init.c + lists.c + log.c + messages.c + ostr.c + portability.c + rt_data.c + sessions.c + utils.c + version.c +'''.split()) + +libfdproto = library('fdproto', + sources : [fdproto_sources], + version : freeDiameter_version, + soversion : freeDiameter_soversion, + include_directories : freeDiameter_includes, + dependencies : [threads, librt, libidn ], + install : true) + +libfdproto_dep = declare_dependency( + link_with : libfdproto, + include_directories : freeDiameter_includes, + dependencies : [threads, librt, libidn ], +) diff --git a/lib/freeDiameter/libfdproto/messages.c b/subprojects/freediameter/libfdproto/messages.c similarity index 100% rename from lib/freeDiameter/libfdproto/messages.c rename to subprojects/freediameter/libfdproto/messages.c diff --git a/lib/freeDiameter/libfdproto/ostr.c b/subprojects/freediameter/libfdproto/ostr.c similarity index 100% rename from lib/freeDiameter/libfdproto/ostr.c rename to subprojects/freediameter/libfdproto/ostr.c diff --git a/lib/freeDiameter/libfdproto/portability.c b/subprojects/freediameter/libfdproto/portability.c similarity index 100% rename from lib/freeDiameter/libfdproto/portability.c rename to subprojects/freediameter/libfdproto/portability.c diff --git a/lib/freeDiameter/libfdproto/rt_data.c b/subprojects/freediameter/libfdproto/rt_data.c similarity index 100% rename from lib/freeDiameter/libfdproto/rt_data.c rename to subprojects/freediameter/libfdproto/rt_data.c diff --git a/lib/freeDiameter/libfdproto/sessions.c b/subprojects/freediameter/libfdproto/sessions.c similarity index 100% rename from lib/freeDiameter/libfdproto/sessions.c rename to subprojects/freediameter/libfdproto/sessions.c diff --git a/lib/freeDiameter/libfdproto/utils.c b/subprojects/freediameter/libfdproto/utils.c similarity index 100% rename from lib/freeDiameter/libfdproto/utils.c rename to subprojects/freediameter/libfdproto/utils.c diff --git a/lib/freeDiameter/libfdproto/version.c b/subprojects/freediameter/libfdproto/version.c similarity index 100% rename from lib/freeDiameter/libfdproto/version.c rename to subprojects/freediameter/libfdproto/version.c diff --git a/subprojects/freediameter/meson.build b/subprojects/freediameter/meson.build new file mode 100644 index 000000000..61ec1d474 --- /dev/null +++ b/subprojects/freediameter/meson.build @@ -0,0 +1,72 @@ +# Copyright (C) 2019 by Sukchan Lee + +# This file is part of Open5GS. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +project('freediameter', 'c', + version : '1.2.1', + license : 'BSD-3-clause', + meson_version : '>= 0.43.0', + default_options : [ + 'warning_level=1', + 'c_std=gnu89', + 'prefix=/usr', + ], +) + +freeDiameter_version = meson.project_version() +freeDiameter_soversion = '6' + +prefix = get_option('prefix') +bindir = join_paths(prefix, get_option('bindir')) +libdir = join_paths(prefix, get_option('libdir')) +sysconfdir = join_paths(prefix, get_option('sysconfdir')) +localstatedir = join_paths(prefix, get_option('localstatedir')) + +cc = meson.get_compiler('c') +host_system = host_machine.system() + +flex = find_program('flex') +bison = find_program('bison') + +# Compiler flags +if cc.get_id() == 'gcc' or cc.get_id() == 'clang' + possible_cc_flags = [ + '-Wall', + '-Werror', + + '-Wno-unused-variable', + '-Wno-unused-but-set-variable', + '-Wno-maybe-uninitialized', + '-Wno-format-truncation', + '-Wno-stringop-truncation', + ] +else + possible_cc_flags = [] +endif + +add_project_arguments( + cc.get_supported_arguments(possible_cc_flags), + language : 'c') + +freeDiameter_includes = include_directories(''' + include + . +'''.split()) + +subdir('include/freeDiameter') +subdir('libfdproto') +subdir('libfdcore') +subdir('extensions') diff --git a/lib/freeDiameter/tests/CMakeLists.txt b/subprojects/freediameter/tests/CMakeLists.txt similarity index 100% rename from lib/freeDiameter/tests/CMakeLists.txt rename to subprojects/freediameter/tests/CMakeLists.txt diff --git a/lib/freeDiameter/tests/testappacct.c b/subprojects/freediameter/tests/testappacct.c similarity index 100% rename from lib/freeDiameter/tests/testappacct.c rename to subprojects/freediameter/tests/testappacct.c diff --git a/lib/freeDiameter/tests/testcnx.c b/subprojects/freediameter/tests/testcnx.c similarity index 100% rename from lib/freeDiameter/tests/testcnx.c rename to subprojects/freediameter/tests/testcnx.c diff --git a/lib/freeDiameter/tests/testdict.c b/subprojects/freediameter/tests/testdict.c similarity index 100% rename from lib/freeDiameter/tests/testdict.c rename to subprojects/freediameter/tests/testdict.c diff --git a/lib/freeDiameter/tests/testdisp.c b/subprojects/freediameter/tests/testdisp.c similarity index 100% rename from lib/freeDiameter/tests/testdisp.c rename to subprojects/freediameter/tests/testdisp.c diff --git a/lib/freeDiameter/tests/testfifo.c b/subprojects/freediameter/tests/testfifo.c similarity index 100% rename from lib/freeDiameter/tests/testfifo.c rename to subprojects/freediameter/tests/testfifo.c diff --git a/lib/freeDiameter/tests/testloadext.c b/subprojects/freediameter/tests/testloadext.c similarity index 100% rename from lib/freeDiameter/tests/testloadext.c rename to subprojects/freediameter/tests/testloadext.c diff --git a/lib/freeDiameter/tests/testmesg.c b/subprojects/freediameter/tests/testmesg.c similarity index 100% rename from lib/freeDiameter/tests/testmesg.c rename to subprojects/freediameter/tests/testmesg.c diff --git a/lib/freeDiameter/tests/testmesg_stress.c b/subprojects/freediameter/tests/testmesg_stress.c similarity index 100% rename from lib/freeDiameter/tests/testmesg_stress.c rename to subprojects/freediameter/tests/testmesg_stress.c diff --git a/lib/freeDiameter/tests/testostr.c b/subprojects/freediameter/tests/testostr.c similarity index 100% rename from lib/freeDiameter/tests/testostr.c rename to subprojects/freediameter/tests/testostr.c diff --git a/lib/freeDiameter/tests/testpeers.c b/subprojects/freediameter/tests/testpeers.c similarity index 100% rename from lib/freeDiameter/tests/testpeers.c rename to subprojects/freediameter/tests/testpeers.c diff --git a/lib/freeDiameter/tests/tests.h b/subprojects/freediameter/tests/tests.h similarity index 100% rename from lib/freeDiameter/tests/tests.h rename to subprojects/freediameter/tests/tests.h diff --git a/lib/freeDiameter/tests/testsctp.c b/subprojects/freediameter/tests/testsctp.c similarity index 100% rename from lib/freeDiameter/tests/testsctp.c rename to subprojects/freediameter/tests/testsctp.c diff --git a/lib/freeDiameter/tests/testsess.c b/subprojects/freediameter/tests/testsess.c similarity index 100% rename from lib/freeDiameter/tests/testsess.c rename to subprojects/freediameter/tests/testsess.c diff --git a/subprojects/usrsctp.wrap b/subprojects/usrsctp.wrap new file mode 100644 index 000000000..340062ff3 --- /dev/null +++ b/subprojects/usrsctp.wrap @@ -0,0 +1,4 @@ +[wrap-git] +directory = usrsctp +url = https://github.com/sctplab/usrsctp.git +revision = master diff --git a/support/Makefile.am b/support/Makefile.am deleted file mode 100644 index 09fcb7352..000000000 --- a/support/Makefile.am +++ /dev/null @@ -1,3 +0,0 @@ -## Process this file with automake to produce Makefile.in - -SUBDIRS = config freeDiameter systemd logrotate newsyslog diff --git a/support/README.md b/support/README.md deleted file mode 100644 index 1eaefc321..000000000 --- a/support/README.md +++ /dev/null @@ -1,8 +0,0 @@ - -* Network Configuration -user@host ~/Documents/git/nextepc/support$ \ - sudo ./network/restart.sh - -* Generate Key & Cert for Diameter -user@host ~/Documents/git/nextepc/support$ \ - ./make_certs.sh ./freeDiameter diff --git a/support/config/Makefile.am b/support/config/Makefile.am deleted file mode 100644 index ac76e78c9..000000000 --- a/support/config/Makefile.am +++ /dev/null @@ -1,12 +0,0 @@ -configfiles = \ - nextepc.conf \ - mme.conf \ - sgw.conf \ - pgw.conf \ - hss.conf \ - pcrf.conf \ - $(NULL) - -configdir = ${sysconfdir}/nextepc - -config_DATA = ${configfiles} diff --git a/support/config/hss.conf.in b/support/config/hss.conf.in deleted file mode 100644 index 6e94bf700..000000000 --- a/support/config/hss.conf.in +++ /dev/null @@ -1,11 +0,0 @@ -### For reference, see `nextepc.conf` - -db_uri: mongodb://localhost/nextepc - -logger: - file: @LOCALSTATE_DIR@/log/nextepc/hss.log - -parameter: - -hss: - freeDiameter: hss.conf diff --git a/support/config/pcrf.conf.in b/support/config/pcrf.conf.in deleted file mode 100644 index 8cf9cb354..000000000 --- a/support/config/pcrf.conf.in +++ /dev/null @@ -1,11 +0,0 @@ -### For reference, see `nextepc.conf` - -db_uri: mongodb://localhost/nextepc - -logger: - file: @LOCALSTATE_DIR@/log/nextepc/pcrf.log - -parameter: - -pcrf: - freeDiameter: pcrf.conf diff --git a/support/freeDiameter/Makefile.am b/support/freeDiameter/Makefile.am deleted file mode 100644 index 4aca9412d..000000000 --- a/support/freeDiameter/Makefile.am +++ /dev/null @@ -1,34 +0,0 @@ -EXTRA_DIST = \ - cacert.pem \ - hss.key.pem \ - mme.key.pem \ - pcrf.key.pem \ - pgw.key.pem \ - hss.cert.pem \ - mme.cert.pem \ - pcrf.cert.pem \ - pgw.cert.pem \ - $(NULL) - -configfiles = \ - mme.conf \ - hss.conf \ - pgw.conf \ - pcrf.conf \ - $(NULL) - -pemfiles = \ - cacert.pem \ - mme.key.pem \ - mme.cert.pem \ - hss.key.pem \ - hss.cert.pem \ - pgw.key.pem \ - pgw.cert.pem \ - pcrf.key.pem \ - pcrf.cert.pem \ - $(NULL) - -freeDiameterdir = ${sysconfdir}/nextepc/freeDiameter - -freeDiameter_DATA = ${configfiles} ${pemfiles} diff --git a/support/freeDiameter/cacert.pem b/support/freeDiameter/cacert.pem deleted file mode 100644 index 1f3e917cb..000000000 --- a/support/freeDiameter/cacert.pem +++ /dev/null @@ -1,17 +0,0 @@ ------BEGIN CERTIFICATE----- -MIICoTCCAgqgAwIBAgIJAM4pPqS92AJcMA0GCSqGSIb3DQEBCwUAMGgxFzAVBgNV -BAMMDmNhLmxvY2FsZG9tYWluMQswCQYDVQQGEwJLTzEOMAwGA1UECAwFU2VvdWwx -DjAMBgNVBAcMBU5vd29uMRAwDgYDVQQKDAdOZXh0RVBDMQ4wDAYDVQQLDAVUZXN0 -czAeFw0xODA4MTcwMDU4MjFaFw0yODA4MTQwMDU4MjFaMGgxFzAVBgNVBAMMDmNh -LmxvY2FsZG9tYWluMQswCQYDVQQGEwJLTzEOMAwGA1UECAwFU2VvdWwxDjAMBgNV -BAcMBU5vd29uMRAwDgYDVQQKDAdOZXh0RVBDMQ4wDAYDVQQLDAVUZXN0czCBnzAN -BgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAwED2MQYt+dCEa0jSZjmkpEMTy0KQHKUr -K9nXcd3T63tol6KlSoQ4vkiND0J867JW6K0oNPjfPL+n/j7q6OKWfN10ew/jgQdn -ZsE7gOs/EZYNvXrsKw0ArOC10gCWBuRbXkWMiiTHgYebicG6zFLwSWCCcv1mS7gU -kQ+5QbetJJECAwEAAaNTMFEwHQYDVR0OBBYEFF4SJr4d4t8o0Y0Izj3/FkB+GESu -MB8GA1UdIwQYMBaAFF4SJr4d4t8o0Y0Izj3/FkB+GESuMA8GA1UdEwEB/wQFMAMB -Af8wDQYJKoZIhvcNAQELBQADgYEAOMqRnLyCf/KrPpsFDgPfUGeYtTSrEp2n4oiN -7/IrT+bZm8JU7L7TEuzaR+rFqjAeJKftv0VPQIA5DvlsfSI015G433ZpO81oIJzu -a1fqKT2zyh8Er+HRf/sdQkKM7HGh61ZCipqiamNYbzlacq42W15wXJCDxr0yYzvi -B+VE1mQ= ------END CERTIFICATE----- diff --git a/support/freeDiameter/hss.cert.pem b/support/freeDiameter/hss.cert.pem deleted file mode 100644 index 943a947e3..000000000 --- a/support/freeDiameter/hss.cert.pem +++ /dev/null @@ -1,60 +0,0 @@ -Certificate: - Data: - Version: 3 (0x2) - Serial Number: 2 (0x2) - Signature Algorithm: sha256WithRSAEncryption - Issuer: CN=ca.localdomain, C=KO, ST=Seoul, L=Nowon, O=NextEPC, OU=Tests - Validity - Not Before: Aug 17 00:58:21 2018 GMT - Not After : Aug 14 00:58:21 2028 GMT - Subject: C=KO, ST=Seoul, O=NextEPC, OU=Tests, CN=hss.localdomain - Subject Public Key Info: - Public Key Algorithm: rsaEncryption - Public-Key: (1024 bit) - Modulus: - 00:e4:c5:4e:3a:92:46:30:6a:6b:b1:c9:e8:9a:40: - 35:57:6c:3b:4f:88:3e:bf:69:aa:71:24:a9:54:96: - 2f:6f:ca:77:a2:d9:3a:cb:d5:71:cc:89:46:c1:94: - 51:a8:a8:88:5b:58:8b:f2:b7:c7:66:c9:5e:93:b9: - 92:7f:c3:bd:9a:b9:93:6c:b9:c3:6a:cd:19:17:b9: - 36:b7:11:db:1b:a1:b0:8e:76:46:53:a8:0f:e5:89: - f7:2d:c1:6d:8e:12:35:c9:7f:16:6f:83:22:eb:e1: - b3:8c:d5:a4:75:3d:63:70:d5:6f:40:c3:ab:86:9c: - 43:53:6e:f2:a9:60:a8:11:2d - Exponent: 65537 (0x10001) - X509v3 extensions: - X509v3 Basic Constraints: - CA:FALSE - Netscape Comment: - OpenSSL Generated Certificate - X509v3 Subject Key Identifier: - 36:1B:B0:35:30:C2:27:9D:F8:9C:19:0C:72:81:9B:D1:EB:4F:FA:77 - X509v3 Authority Key Identifier: - keyid:5E:12:26:BE:1D:E2:DF:28:D1:8D:08:CE:3D:FF:16:40:7E:18:44:AE - - Signature Algorithm: sha256WithRSAEncryption - 4f:54:46:2a:0c:79:5d:e3:78:b5:90:96:9e:9d:1c:b3:01:87: - da:f6:d5:b1:ca:e8:0b:21:2f:b9:4f:06:0a:67:12:64:5d:b8: - 4b:a2:1e:66:72:2d:74:50:4f:ce:18:14:ee:77:e5:13:0d:f6: - cf:96:9e:0f:44:6b:a0:1b:ab:70:91:f8:af:7e:fc:e0:71:1a: - a0:96:7c:81:17:8e:3f:60:89:70:45:30:83:bb:76:da:2a:2a: - 01:40:bb:26:f3:69:19:64:da:78:ac:a5:bb:05:ca:7d:9b:b7: - 80:e6:38:04:17:f2:38:ab:38:f8:db:88:2a:bf:2a:a0:35:9d: - 30:b4 ------BEGIN CERTIFICATE----- -MIICsjCCAhugAwIBAgIBAjANBgkqhkiG9w0BAQsFADBoMRcwFQYDVQQDDA5jYS5s -b2NhbGRvbWFpbjELMAkGA1UEBhMCS08xDjAMBgNVBAgMBVNlb3VsMQ4wDAYDVQQH -DAVOb3dvbjEQMA4GA1UECgwHTmV4dEVQQzEOMAwGA1UECwwFVGVzdHMwHhcNMTgw -ODE3MDA1ODIxWhcNMjgwODE0MDA1ODIxWjBZMQswCQYDVQQGEwJLTzEOMAwGA1UE -CAwFU2VvdWwxEDAOBgNVBAoMB05leHRFUEMxDjAMBgNVBAsMBVRlc3RzMRgwFgYD -VQQDDA9oc3MubG9jYWxkb21haW4wgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGB -AOTFTjqSRjBqa7HJ6JpANVdsO0+IPr9pqnEkqVSWL2/Kd6LZOsvVccyJRsGUUaio -iFtYi/K3x2bJXpO5kn/DvZq5k2y5w2rNGRe5NrcR2xuhsI52RlOoD+WJ9y3BbY4S -Ncl/Fm+DIuvhs4zVpHU9Y3DVb0DDq4acQ1Nu8qlgqBEtAgMBAAGjezB5MAkGA1Ud -EwQCMAAwLAYJYIZIAYb4QgENBB8WHU9wZW5TU0wgR2VuZXJhdGVkIENlcnRpZmlj -YXRlMB0GA1UdDgQWBBQ2G7A1MMInnficGQxygZvR60/6dzAfBgNVHSMEGDAWgBRe -Eia+HeLfKNGNCM49/xZAfhhErjANBgkqhkiG9w0BAQsFAAOBgQBPVEYqDHld43i1 -kJaenRyzAYfa9tWxyugLIS+5TwYKZxJkXbhLoh5mci10UE/OGBTud+UTDfbPlp4P -RGugG6twkfivfvzgcRqglnyBF44/YIlwRTCDu3baKioBQLsm82kZZNp4rKW7Bcp9 -m7eA5jgEF/I4qzj424gqvyqgNZ0wtA== ------END CERTIFICATE----- diff --git a/support/freeDiameter/hss.key.pem b/support/freeDiameter/hss.key.pem deleted file mode 100644 index 73e05be60..000000000 --- a/support/freeDiameter/hss.key.pem +++ /dev/null @@ -1,15 +0,0 @@ ------BEGIN RSA PRIVATE KEY----- -MIICWwIBAAKBgQDkxU46kkYwamuxyeiaQDVXbDtPiD6/aapxJKlUli9vynei2TrL -1XHMiUbBlFGoqIhbWIvyt8dmyV6TuZJ/w72auZNsucNqzRkXuTa3EdsbobCOdkZT -qA/lifctwW2OEjXJfxZvgyLr4bOM1aR1PWNw1W9Aw6uGnENTbvKpYKgRLQIDAQAB -AoGAGQrYI2U7tbUQkOevRKNes3EvlOcvJzjj5XrD5nSCQNSDABqTaxi0WlV0n2Aj -CDlao9UvjKQ9eaz1Y2pe9QlySbanPwlg9Btd3aGs3/eAi3YHZ7Mo/fGAh5ZNNz3g -avH1CJffRwfojwm8mplAlS1NN4pV+c3pVdgFjy3oVZxcXIECQQDyaW4nJqAvcrZh -CSTK+yhk/TvGyBw6DU3ZwMBRI1V9lEa7U2xudOUAGcftLlS77DmH1ATPtNxeLgGO -OVg/Oq8dAkEA8Zggqioev40UfyCYVGqoIvoPJoL1d6DHQv1ZRg0+Ikx9qkmnHYtO -z3xabk6lCrGjFgb/Ag3MGCLojnP2rnP9UQJAe6FpnG4GpCxM95BCQ4N0Ro0gP3Ev -dCv02GmFq9vpbfKBYGhblLnpUPPVExHeBTmk3bE0AvqqqR2tjWuRpi23wQJAS1TH -IqgdjFbeREGSngffw4A7RyPgjFuqpj2/H3Ozoxg8uuNaY4DzowjAXdLR7YK0OoMV -8rsAn6oK35hTG9R48QJAdTYLTnmfxyu5OwHM7TyUdND02xSfnAOz1doc9pibfn0G -BvFY/YBF/q/0JJ7a1WZCFqPLDZiFyIF0HWOJSfjbTQ== ------END RSA PRIVATE KEY----- diff --git a/support/freeDiameter/mme.cert.pem b/support/freeDiameter/mme.cert.pem deleted file mode 100644 index 649c851d0..000000000 --- a/support/freeDiameter/mme.cert.pem +++ /dev/null @@ -1,60 +0,0 @@ -Certificate: - Data: - Version: 3 (0x2) - Serial Number: 1 (0x1) - Signature Algorithm: sha256WithRSAEncryption - Issuer: CN=ca.localdomain, C=KO, ST=Seoul, L=Nowon, O=NextEPC, OU=Tests - Validity - Not Before: Aug 17 00:58:21 2018 GMT - Not After : Aug 14 00:58:21 2028 GMT - Subject: C=KO, ST=Seoul, O=NextEPC, OU=Tests, CN=mme.localdomain - Subject Public Key Info: - Public Key Algorithm: rsaEncryption - Public-Key: (1024 bit) - Modulus: - 00:af:81:46:f0:74:9f:46:e0:e5:c1:35:2f:0b:4b: - fb:4c:ba:b4:6d:be:01:d5:2b:4c:ad:e0:06:ab:00: - c5:f4:be:db:fe:9d:7a:aa:32:81:98:06:47:b1:5b: - 7b:cb:25:0a:54:f9:74:3f:10:57:05:1a:2f:d1:32: - 8f:ad:21:dd:e1:f8:b4:fd:5d:67:d6:60:d2:d9:27: - 2a:75:36:55:82:9f:ed:4c:6f:99:b5:43:14:9b:27: - 83:2e:d6:05:ec:1e:8e:9e:b0:d1:84:83:49:20:fa: - 5a:12:5d:6c:b7:79:6a:81:25:19:1b:db:36:cb:1b: - 7d:3a:82:93:60:42:59:28:55 - Exponent: 65537 (0x10001) - X509v3 extensions: - X509v3 Basic Constraints: - CA:FALSE - Netscape Comment: - OpenSSL Generated Certificate - X509v3 Subject Key Identifier: - F9:F2:22:94:BC:0C:02:A3:CE:53:07:AA:55:FC:B8:17:B9:EC:A2:D4 - X509v3 Authority Key Identifier: - keyid:5E:12:26:BE:1D:E2:DF:28:D1:8D:08:CE:3D:FF:16:40:7E:18:44:AE - - Signature Algorithm: sha256WithRSAEncryption - a8:23:e3:25:7d:ca:05:6d:d9:43:43:8d:88:de:86:1a:26:a8: - 24:6d:d2:3f:4e:b5:19:00:c4:0f:15:58:7c:e5:5d:b4:17:c8: - 93:ba:45:c9:9d:5a:e8:95:c2:a1:f5:b9:d0:2d:7b:0e:51:80: - 72:1f:bf:9b:ed:9a:40:4a:1e:0f:e1:45:4e:3f:6a:11:80:73: - cf:70:d9:66:26:17:c6:c0:22:b2:de:da:70:21:48:37:5f:1a: - 9a:f5:60:36:cd:58:5e:88:c3:dc:c7:92:a4:74:f8:6b:ad:ba: - c7:b7:de:00:51:67:72:5c:ca:f3:aa:a8:9b:ff:15:71:3b:e6: - 75:53 ------BEGIN CERTIFICATE----- -MIICsjCCAhugAwIBAgIBATANBgkqhkiG9w0BAQsFADBoMRcwFQYDVQQDDA5jYS5s -b2NhbGRvbWFpbjELMAkGA1UEBhMCS08xDjAMBgNVBAgMBVNlb3VsMQ4wDAYDVQQH -DAVOb3dvbjEQMA4GA1UECgwHTmV4dEVQQzEOMAwGA1UECwwFVGVzdHMwHhcNMTgw -ODE3MDA1ODIxWhcNMjgwODE0MDA1ODIxWjBZMQswCQYDVQQGEwJLTzEOMAwGA1UE -CAwFU2VvdWwxEDAOBgNVBAoMB05leHRFUEMxDjAMBgNVBAsMBVRlc3RzMRgwFgYD -VQQDDA9tbWUubG9jYWxkb21haW4wgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGB -AK+BRvB0n0bg5cE1LwtL+0y6tG2+AdUrTK3gBqsAxfS+2/6deqoygZgGR7Fbe8sl -ClT5dD8QVwUaL9Eyj60h3eH4tP1dZ9Zg0tknKnU2VYKf7UxvmbVDFJsngy7WBewe -jp6w0YSDSSD6WhJdbLd5aoElGRvbNssbfTqCk2BCWShVAgMBAAGjezB5MAkGA1Ud -EwQCMAAwLAYJYIZIAYb4QgENBB8WHU9wZW5TU0wgR2VuZXJhdGVkIENlcnRpZmlj -YXRlMB0GA1UdDgQWBBT58iKUvAwCo85TB6pV/LgXueyi1DAfBgNVHSMEGDAWgBRe -Eia+HeLfKNGNCM49/xZAfhhErjANBgkqhkiG9w0BAQsFAAOBgQCoI+MlfcoFbdlD -Q42I3oYaJqgkbdI/TrUZAMQPFVh85V20F8iTukXJnVrolcKh9bnQLXsOUYByH7+b -7ZpASh4P4UVOP2oRgHPPcNlmJhfGwCKy3tpwIUg3Xxqa9WA2zVheiMPcx5KkdPhr -rbrHt94AUWdyXMrzqqib/xVxO+Z1Uw== ------END CERTIFICATE----- diff --git a/support/freeDiameter/mme.key.pem b/support/freeDiameter/mme.key.pem deleted file mode 100644 index a6b2280ba..000000000 --- a/support/freeDiameter/mme.key.pem +++ /dev/null @@ -1,15 +0,0 @@ ------BEGIN RSA PRIVATE KEY----- -MIICXAIBAAKBgQCvgUbwdJ9G4OXBNS8LS/tMurRtvgHVK0yt4AarAMX0vtv+nXqq -MoGYBkexW3vLJQpU+XQ/EFcFGi/RMo+tId3h+LT9XWfWYNLZJyp1NlWCn+1Mb5m1 -QxSbJ4Mu1gXsHo6esNGEg0kg+loSXWy3eWqBJRkb2zbLG306gpNgQlkoVQIDAQAB -AoGAb/s0oEhJOJhXAKhGlBavCY43ga4yzSkLjAXdO08K/9an2BXzJpWDStT2+Zs9 -qajApudj3Lk4TPEggYKZWga5411xbmnuY0JDv9q89w5RMpNveOo7t3tvaU/yeNHq -nNhArPQ2awZuc76pC1GmQpdSx9NUEWDkRN3IDHEjQvI6uQECQQDo+g4VdmlesAIC -+RE8Q/uz/tmbZBw1TbqL9m2KpBtFQjBx4SFre65x8I3Tw0fjaPeAsXZbHH4pM4H9 -6iGoa9GJAkEAwNlGyAk+3lciYOTtYnwYKE6QDrU4VJqGTIcRr9xczlfPbykCMBX3 -3U7cxt9uU85QQNxgqHlHmG9evLEnWlIpbQJAAv5DdA8jZ24HeJZOnGGbOELL9O0i -V6T6ApZV7fQRzZ/+E1h7H3BlW11l1RSrNcbBd0vQY3dIP6tDvkllyU4pUQJAL35T -HDiKrx8ubEZ03+hH2sVeXQDsWomjwX0SMglHIdomT+39h/IhFPOzE5c7CJCq2w5r -D5Kuuy/SWQ4X7vqFEQJBAMdvn/B2B3mFKpovYtv02wN00icGIpjEg7VGGiT4LVpM -RpRw+tgDq+zdOmZiLdoZhvuoo90age6QZ8xc7VXYEFM= ------END RSA PRIVATE KEY----- diff --git a/support/freeDiameter/pcrf.cert.pem b/support/freeDiameter/pcrf.cert.pem deleted file mode 100644 index 21a0ef5e0..000000000 --- a/support/freeDiameter/pcrf.cert.pem +++ /dev/null @@ -1,60 +0,0 @@ -Certificate: - Data: - Version: 3 (0x2) - Serial Number: 4 (0x4) - Signature Algorithm: sha256WithRSAEncryption - Issuer: CN=ca.localdomain, C=KO, ST=Seoul, L=Nowon, O=NextEPC, OU=Tests - Validity - Not Before: Aug 17 00:58:21 2018 GMT - Not After : Aug 14 00:58:21 2028 GMT - Subject: C=KO, ST=Seoul, O=NextEPC, OU=Tests, CN=pcrf.localdomain - Subject Public Key Info: - Public Key Algorithm: rsaEncryption - Public-Key: (1024 bit) - Modulus: - 00:bf:fc:c9:c1:5d:17:84:70:15:bb:f5:ee:be:61: - aa:fe:65:ae:0d:93:1f:5c:42:75:71:3b:4b:06:5a: - 18:d7:46:05:be:a0:0e:c9:b8:1c:22:d0:49:71:c2: - 55:21:7a:d1:15:91:d7:45:19:4a:44:de:fd:28:47: - ec:e3:ea:36:7e:bc:bb:c3:50:6b:ae:9e:00:5e:5d: - 7c:bf:65:ca:8a:1d:a7:6c:40:4e:7c:e6:74:88:8f: - 2a:f5:2e:f3:77:55:7a:72:ce:e6:5a:ef:db:1b:ef: - 47:8f:86:f5:4d:9d:ce:66:52:83:5d:73:d7:71:a7: - ab:74:a5:c3:88:15:2c:e3:4d - Exponent: 65537 (0x10001) - X509v3 extensions: - X509v3 Basic Constraints: - CA:FALSE - Netscape Comment: - OpenSSL Generated Certificate - X509v3 Subject Key Identifier: - 1C:27:03:08:96:FD:B9:5F:EE:90:A7:B4:CD:E8:EB:A1:AB:B6:21:1D - X509v3 Authority Key Identifier: - keyid:5E:12:26:BE:1D:E2:DF:28:D1:8D:08:CE:3D:FF:16:40:7E:18:44:AE - - Signature Algorithm: sha256WithRSAEncryption - 10:b7:d1:be:d7:2f:ac:a8:58:95:3a:83:a9:9e:8e:46:7d:7e: - 12:34:1b:3d:5e:39:e7:fb:b8:66:3e:3d:ce:fb:10:bf:2a:ec: - f6:e6:76:28:47:56:0d:fb:98:df:d9:e1:dd:bb:30:05:60:06: - 3e:38:63:af:06:67:9a:4d:7d:29:20:d9:2b:88:50:c9:a0:52: - b2:27:0c:2f:b7:be:a3:dc:51:93:a9:c5:43:99:a3:70:5e:11: - a6:92:ec:e2:92:1a:17:fd:f5:c8:ed:2f:fa:cf:1d:3a:ad:ee: - 5c:9a:54:1f:82:64:23:ee:52:af:8d:1c:7e:e6:1a:ec:72:c6: - af:f0 ------BEGIN CERTIFICATE----- -MIICszCCAhygAwIBAgIBBDANBgkqhkiG9w0BAQsFADBoMRcwFQYDVQQDDA5jYS5s -b2NhbGRvbWFpbjELMAkGA1UEBhMCS08xDjAMBgNVBAgMBVNlb3VsMQ4wDAYDVQQH -DAVOb3dvbjEQMA4GA1UECgwHTmV4dEVQQzEOMAwGA1UECwwFVGVzdHMwHhcNMTgw -ODE3MDA1ODIxWhcNMjgwODE0MDA1ODIxWjBaMQswCQYDVQQGEwJLTzEOMAwGA1UE -CAwFU2VvdWwxEDAOBgNVBAoMB05leHRFUEMxDjAMBgNVBAsMBVRlc3RzMRkwFwYD -VQQDDBBwY3JmLmxvY2FsZG9tYWluMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKB -gQC//MnBXReEcBW79e6+Yar+Za4Nkx9cQnVxO0sGWhjXRgW+oA7JuBwi0ElxwlUh -etEVkddFGUpE3v0oR+zj6jZ+vLvDUGuungBeXXy/ZcqKHadsQE585nSIjyr1LvN3 -VXpyzuZa79sb70ePhvVNnc5mUoNdc9dxp6t0pcOIFSzjTQIDAQABo3sweTAJBgNV -HRMEAjAAMCwGCWCGSAGG+EIBDQQfFh1PcGVuU1NMIEdlbmVyYXRlZCBDZXJ0aWZp -Y2F0ZTAdBgNVHQ4EFgQUHCcDCJb9uV/ukKe0zejroau2IR0wHwYDVR0jBBgwFoAU -XhImvh3i3yjRjQjOPf8WQH4YRK4wDQYJKoZIhvcNAQELBQADgYEAELfRvtcvrKhY -lTqDqZ6ORn1+EjQbPV455/u4Zj49zvsQvyrs9uZ2KEdWDfuY39nh3bswBWAGPjhj -rwZnmk19KSDZK4hQyaBSsicML7e+o9xRk6nFQ5mjcF4RppLs4pIaF/31yO0v+s8d -Oq3uXJpUH4JkI+5Sr40cfuYa7HLGr/A= ------END CERTIFICATE----- diff --git a/support/freeDiameter/pcrf.key.pem b/support/freeDiameter/pcrf.key.pem deleted file mode 100644 index 98907aba8..000000000 --- a/support/freeDiameter/pcrf.key.pem +++ /dev/null @@ -1,15 +0,0 @@ ------BEGIN RSA PRIVATE KEY----- -MIICXQIBAAKBgQC//MnBXReEcBW79e6+Yar+Za4Nkx9cQnVxO0sGWhjXRgW+oA7J -uBwi0ElxwlUhetEVkddFGUpE3v0oR+zj6jZ+vLvDUGuungBeXXy/ZcqKHadsQE58 -5nSIjyr1LvN3VXpyzuZa79sb70ePhvVNnc5mUoNdc9dxp6t0pcOIFSzjTQIDAQAB -AoGAEWRkHplBVSUWQvXPj/2nEO7DKsWmNKRsoTpe3I9y6qWURaWYUVvVaK33yU9y -iNrocAzLNJ5K5RxSUMDbS/Zew0ng0tpr1uG2sH0rFiF4jw2IchQymqQ6UahjV8Mj -DQhvRhxxcHO0Iz0ZhvftLJX9mEKfxH1Mx6agKPrS6XTsRWECQQD/jaEfSJ/ht6rR -Die8QZnjCkikfiMFWf+mCobgXrsDqWnqBo0Xi9ofKQHsrHRicaUoObGUUZ2egTWb -V1TRDNs5AkEAwFK13YqpFEQfOVDp0uZbCCSB+CVuwaDQSTJcsYxR7EzZpblChRtY -Al0Sx2yooRLANQX4D+8rzzh+IAe4S/EEtQJAI375pU3CH2kSie0sacK27ElOY8K9 -fI3Oq7KEn3+o/E44zu/QAzhCuNdKVCR0GgRtC1RQLSjU+uI5nvUXa94cSQJBAIv3 -pgQl9geZzF+aU5H5tCao6y39kC27K9sZm/xbcwPWqk/CFHdq/xI5SoF4wwD29Iui -XHa8SdX191S4SZh7QEECQQD2QGc+/e9tcmgTqBJxEW6pXg12ll9SEQnG1bCcTarZ -k0YLvAkw/Ve2Q7V4S3nzQWhoQVtEYXrTdsMojV/H0xYi ------END RSA PRIVATE KEY----- diff --git a/support/freeDiameter/pgw.cert.pem b/support/freeDiameter/pgw.cert.pem deleted file mode 100644 index fafbf99fb..000000000 --- a/support/freeDiameter/pgw.cert.pem +++ /dev/null @@ -1,60 +0,0 @@ -Certificate: - Data: - Version: 3 (0x2) - Serial Number: 3 (0x3) - Signature Algorithm: sha256WithRSAEncryption - Issuer: CN=ca.localdomain, C=KO, ST=Seoul, L=Nowon, O=NextEPC, OU=Tests - Validity - Not Before: Aug 17 00:58:21 2018 GMT - Not After : Aug 14 00:58:21 2028 GMT - Subject: C=KO, ST=Seoul, O=NextEPC, OU=Tests, CN=pgw.localdomain - Subject Public Key Info: - Public Key Algorithm: rsaEncryption - Public-Key: (1024 bit) - Modulus: - 00:ae:db:dc:af:a4:f7:f1:da:e0:34:3c:ff:9e:60: - 12:b5:05:ce:5c:b3:5f:80:12:99:48:41:94:cd:87: - 64:f0:17:e0:2f:83:ab:cb:dc:83:59:f2:fa:1f:e3: - d2:72:9b:b8:65:63:38:80:50:69:0e:6e:66:02:b5: - 19:7a:81:62:0a:63:34:4b:3a:11:46:06:42:9e:89: - f0:a5:a4:3e:74:00:c3:62:32:32:b4:d8:41:b0:15: - e4:eb:c7:1f:b3:ea:7b:5e:03:c8:44:4a:a1:35:9f: - b1:3c:a5:e0:83:d8:ff:6c:6f:45:5b:eb:9e:4b:cb: - a0:42:88:8d:81:ea:c7:4a:cd - Exponent: 65537 (0x10001) - X509v3 extensions: - X509v3 Basic Constraints: - CA:FALSE - Netscape Comment: - OpenSSL Generated Certificate - X509v3 Subject Key Identifier: - F3:FE:FA:87:88:75:6B:4E:94:73:D8:2A:A4:EC:79:13:91:D4:62:F8 - X509v3 Authority Key Identifier: - keyid:5E:12:26:BE:1D:E2:DF:28:D1:8D:08:CE:3D:FF:16:40:7E:18:44:AE - - Signature Algorithm: sha256WithRSAEncryption - ad:13:60:47:a5:23:13:d9:5e:14:24:cb:ec:4f:4b:e2:41:55: - b5:79:a6:b5:de:05:24:87:05:51:ed:c6:7c:9a:65:b8:7a:bd: - fd:ee:92:98:38:97:29:6f:e2:f3:a7:48:7a:77:d9:7d:22:d1: - 6d:0e:61:49:e7:e1:72:d9:9a:b2:d8:ef:9b:3a:b2:71:37:43: - 6d:0d:de:84:48:c4:e6:6c:cb:7c:05:8c:af:26:cf:aa:2b:e1: - d7:f2:65:f8:0d:45:33:ec:b7:9a:2a:bf:16:f1:4f:76:c7:2a: - 1d:14:f4:9a:30:14:8d:72:30:e7:f4:9c:1e:09:34:5b:79:26: - 4a:d9 ------BEGIN CERTIFICATE----- -MIICsjCCAhugAwIBAgIBAzANBgkqhkiG9w0BAQsFADBoMRcwFQYDVQQDDA5jYS5s -b2NhbGRvbWFpbjELMAkGA1UEBhMCS08xDjAMBgNVBAgMBVNlb3VsMQ4wDAYDVQQH -DAVOb3dvbjEQMA4GA1UECgwHTmV4dEVQQzEOMAwGA1UECwwFVGVzdHMwHhcNMTgw -ODE3MDA1ODIxWhcNMjgwODE0MDA1ODIxWjBZMQswCQYDVQQGEwJLTzEOMAwGA1UE -CAwFU2VvdWwxEDAOBgNVBAoMB05leHRFUEMxDjAMBgNVBAsMBVRlc3RzMRgwFgYD -VQQDDA9wZ3cubG9jYWxkb21haW4wgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGB -AK7b3K+k9/Ha4DQ8/55gErUFzlyzX4ASmUhBlM2HZPAX4C+Dq8vcg1ny+h/j0nKb -uGVjOIBQaQ5uZgK1GXqBYgpjNEs6EUYGQp6J8KWkPnQAw2IyMrTYQbAV5OvHH7Pq -e14DyERKoTWfsTyl4IPY/2xvRVvrnkvLoEKIjYHqx0rNAgMBAAGjezB5MAkGA1Ud -EwQCMAAwLAYJYIZIAYb4QgENBB8WHU9wZW5TU0wgR2VuZXJhdGVkIENlcnRpZmlj -YXRlMB0GA1UdDgQWBBTz/vqHiHVrTpRz2Cqk7HkTkdRi+DAfBgNVHSMEGDAWgBRe -Eia+HeLfKNGNCM49/xZAfhhErjANBgkqhkiG9w0BAQsFAAOBgQCtE2BHpSMT2V4U -JMvsT0viQVW1eaa13gUkhwVR7cZ8mmW4er397pKYOJcpb+Lzp0h6d9l9ItFtDmFJ -5+Fy2Zqy2O+bOrJxN0NtDd6ESMTmbMt8BYyvJs+qK+HX8mX4DUUz7LeaKr8W8U92 -xyodFPSaMBSNcjDn9JweCTRbeSZK2Q== ------END CERTIFICATE----- diff --git a/support/freeDiameter/pgw.key.pem b/support/freeDiameter/pgw.key.pem deleted file mode 100644 index ea9ae75a4..000000000 --- a/support/freeDiameter/pgw.key.pem +++ /dev/null @@ -1,15 +0,0 @@ ------BEGIN RSA PRIVATE KEY----- -MIICXgIBAAKBgQCu29yvpPfx2uA0PP+eYBK1Bc5cs1+AEplIQZTNh2TwF+Avg6vL -3INZ8vof49Jym7hlYziAUGkObmYCtRl6gWIKYzRLOhFGBkKeifClpD50AMNiMjK0 -2EGwFeTrxx+z6nteA8hESqE1n7E8peCD2P9sb0Vb655Ly6BCiI2B6sdKzQIDAQAB -AoGAERK4npHN/9huMcuO7ejVisVRW+3LslaejtaQb+z7ZxH9usXxfUs/rAW0dG6r -OrOHsqaYerbfOyB+Z19FaJe/ebi2LQxUvUA7wFDYnrw/jvS8IDJrIcCg3BTVJGHQ -W4yTbVzPgEeW768eGuJ4YJJbnZhMgV+ia/A5mwrXoJZ4kAUCQQDl9Y54uVeXmLuh -CnnWt8xcacmeEIOXQ+UXArLQdeBzGX6Z5BuCbjjZjPnIo93RQedl4PJ3CGdL4IoA -9vL3rpoXAkEAwqj2qf0DjoItnhcJFSpaLZuwZo2kcQOve9BzfpM1PojNHwuFl8hw -lwXQ+8BOtQo2qvk1UlkuH+mEQ3h/GmqkuwJBAI+v7cP1W4v3/VVU7GiEFAeyei5v -9ylvXRgRsZWb8hE5XufdpmrLYG5fLjx2V8XHPkVkV1yVPaYluVV8+LhWuyUCQQCr -Qe/RWhIY/JqZrXaGMn6oBYNKlm8IJs/qxFf4EhcT71NXbtGX2faER8+2zVfxmwzB -mwK4clFMLiv5GDfqy8wlAkEA08d6Z0/MW7bYOQIDfkmw26wJfuSIbqO5GHMuJOKh -NufvnoLYLVoPWxONVIVrP8mfQk7EJH8JpKOIFY5Vw8p7BA== ------END RSA PRIVATE KEY----- diff --git a/support/logrotate/Makefile.am b/support/logrotate/Makefile.am deleted file mode 100644 index ec120d322..000000000 --- a/support/logrotate/Makefile.am +++ /dev/null @@ -1 +0,0 @@ -EXTRA_DIST = nextepc.in diff --git a/support/logrotate/nextepc.in b/support/logrotate/nextepc.in deleted file mode 100644 index d58a86504..000000000 --- a/support/logrotate/nextepc.in +++ /dev/null @@ -1,16 +0,0 @@ -@LOCALSTATE_DIR@/log/nextepc/*.log { - daily - sharedscripts - missingok - compress - rotate 14 - create 640 nextepc nextepc - - postrotate - for i in pcrfd pgwd sgwd hssd mmed epcd; do - if [ -e @LOCALSTATE_DIR@/run/nextepc-$i/pid ] ; then - kill -HUP `cat @LOCALSTATE_DIR@/run/nextepc-$i/pid` - fi - done - endscript -} diff --git a/support/macosx/README.md b/support/macosx/README.md deleted file mode 100644 index 407207728..000000000 --- a/support/macosx/README.md +++ /dev/null @@ -1,31 +0,0 @@ -Install SCTP for Mac OS X 10.11(El Captian) -=========================================== - - Reference : https://github.com/sctplab/SCTP_NKE_ElCapitan - - Start up in OS X Recovery by holding down Command-R while the Mac is starting up - Choose Terminal from the Utilities menu. - Type 'csrutil disable' in Terminal and Reboot - - Download SCTP_NKE_ElCapitan_Install_01.dmg - xcode-select --install - sudo cp -R /Volumes/SCTP_NKE_ElCapitan_01/SCTPSupport.kext /Library/Extensions - sudo cp -R /Volumes/SCTP_NKE_ElCapitan_01/SCTP.kext /Library/Extensions - sudo cp /Volumes/SCTP_NKE_ElCapitan_01/socket.h /usr/include/sys/ - sudo cp /Volumes/SCTP_NKE_ElCapitan_01/sctp.h /usr/include/netinet/ - sudo cp /Volumes/SCTP_NKE_ElCapitan_01/sctp_uio.h /usr/include/netinet/ - sudo cp /Volumes/SCTP_NKE_ElCapitan_01/libsctp.dylib /usr/lib/ - sudo kextload /Library/Extensions/SCTP.kext - -Install Tuntap for Mac OS X -=========================================== - - brew tap caskroom/cask - - brew cask install tuntap - - Install tuntap_20150118.pkg in /usr/local/Caskroom/tuntap/20150118 - - sudo kextload /Library/Extensions/tun.kext - -Install FreeDiameter, MongoDB C driver -=========================================== - - brew install freediamter - - brew install mongo-c-driver - -Enable IP Fowarding -==================== - - sysctl -w net.inet.ip.forwarding=1 diff --git a/support/network/restart.sh b/support/network/restart.sh deleted file mode 100755 index 76857e654..000000000 --- a/support/network/restart.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/sh - -SYSTEM=`uname`; - -if [ "$SYSTEM" = "Linux" ]; then - if ! grep "pgwtun" /proc/net/dev > /dev/null; then - ip tuntap add name pgwtun mode tun - fi - if test "x`sysctl -n net.ipv6.conf.pgwtun.disable_ipv6`" = x1; then - echo "net.ipv6.conf.pgwtun.disable_ipv6=0" > /etc/sysctl.d/30-nextepc.conf - sysctl -p /etc/sysctl.d/30-nextepc.conf - fi - ip addr del 45.45.0.1/16 dev pgwtun 2> /dev/null - ip addr add 45.45.0.1/16 dev pgwtun - ip addr del cafe::1/64 dev pgwtun 2> /dev/null - ip addr add cafe::1/64 dev pgwtun - ip link set pgwtun up -else - sysctl -w net.inet.ip.forwarding=1 - ifconfig lo0 alias 127.0.0.2 netmask 255.255.255.255 - ifconfig lo0 alias 127.0.0.3 netmask 255.255.255.255 - ifconfig lo0 alias 127.0.0.4 netmask 255.255.255.255 - ifconfig lo0 alias 127.0.0.5 netmask 255.255.255.255 - if [ "$SYSTEM" = "Darwin" ]; then - if ! test -f /etc/pf.anchors/org.nextepc; then - sudo sh -c "echo 'nat on {en0} from 45.45.0.0/16 to any -> {en0}' > /etc/pf.anchors/org.nextepc" - fi - pfctl -e -f /etc/pf.anchors/org.nextepc - fi -fi diff --git a/support/newsyslog/Makefile.am b/support/newsyslog/Makefile.am deleted file mode 100644 index ce8450860..000000000 --- a/support/newsyslog/Makefile.am +++ /dev/null @@ -1 +0,0 @@ -EXTRA_DIST = nextepc.conf.in diff --git a/support/newsyslog/nextepc.conf.in b/support/newsyslog/nextepc.conf.in deleted file mode 100644 index ad6badb3f..000000000 --- a/support/newsyslog/nextepc.conf.in +++ /dev/null @@ -1,9 +0,0 @@ -# truncate rails logs every day at midnight, keep 14 previous logs, compress previous logs -# -# logfilename [owner:group] mode count size when flags [/pid_file] [sig_num] -@LOCALSTATE_DIR@/log/nextepc/pcrf.log 644 14 * $D0 GZ @LOCALSTATE_DIR@/run/nextepc-pcrfd/pid` -@LOCALSTATE_DIR@/log/nextepc/pgw.log 644 14 * $D0 GZ @LOCALSTATE_DIR@/run/nextepc-pgwd/pid` -@LOCALSTATE_DIR@/log/nextepc/sgw.log 644 14 * $D0 GZ @LOCALSTATE_DIR@/run/nextepc-sgwd/pid` -@LOCALSTATE_DIR@/log/nextepc/hss.log 644 14 * $D0 GZ @LOCALSTATE_DIR@/run/nextepc-hssd/pid` -@LOCALSTATE_DIR@/log/nextepc/mme.log 644 14 * $D0 GZ @LOCALSTATE_DIR@/run/nextepc-mmed/pid` -@LOCALSTATE_DIR@/log/nextepc/nextepc.log 644 14 * $D0 GZ @LOCALSTATE_DIR@/run/nextepc-epcd/pid` diff --git a/support/systemd/Makefile.am b/support/systemd/Makefile.am deleted file mode 100644 index 3a2c5f5e5..000000000 --- a/support/systemd/Makefile.am +++ /dev/null @@ -1,7 +0,0 @@ -EXTRA_DIST = \ - nextepc-mmed.service.in \ - nextepc-pgwd.service.in \ - nextepc-hssd.service.in \ - nextepc-pcrfd.service.in \ - nextepc-sgwd.service.in \ - $(NULL) diff --git a/tests/Makefile.am b/tests/Makefile.am deleted file mode 100644 index 692586411..000000000 --- a/tests/Makefile.am +++ /dev/null @@ -1,119 +0,0 @@ -## Process this file with automake to produce Makefile.in. - -bin_PROGRAMS = testunit testsimple testcomplex testvolte testcsfb - -configdir = ${sysconfdir}/nextepc/tests -config_DATA = \ - sample-simple.conf sample-complex.conf sample-volte.conf sample-csfb.conf \ - $(NULL) - -testunit_SOURCES = \ - common/test-packet.h common/test-packet.c \ - unit/abts-main.c \ - unit/s1ap-message-test.c unit/nas-message-test.c \ - unit/gtp-message-test.c unit/security-test.c \ - unit/sctp-test.c unit/crash-test.c \ - $(NULL) -testunit_LDADD = $(top_srcdir)/src/libepc.la - -testsimple_SOURCES = \ - common/test-packet.h common/test-packet.c \ - common/test-app.h common/test-app.c \ - simple/abts-main.c \ - simple/mnc3-test.c \ - $(NULL) -testsimple_LDADD = $(top_srcdir)/src/libepc.la - -testcomplex_SOURCES = \ - common/test-packet.h common/test-packet.c \ - common/test-app.h common/test-app.c \ - complex/abts-main.c \ - complex/s1setup-test.c \ - complex/attach-test.c complex/volte-test.c complex/handover-test.c \ - complex/crash-test.c \ - $(NULL) -testcomplex_LDADD = $(top_srcdir)/src/libepc.la - -testvolte_SOURCES = \ - common/test-packet.h common/test-packet.c \ - common/test-app.h common/test-app.c \ - volte/abts-main.c \ - volte/pcscf-fd-path.h volte/pcscf-fd-path.c \ - volte/volte-test.c \ - $(NULL) -testvolte_LDADD = $(top_srcdir)/src/libepc.la - -testcsfb_SOURCES = \ - common/test-packet.h common/test-packet.c \ - common/test-app.h common/test-app.c \ - csfb/abts-main.c \ - csfb/mo-idle-test.c csfb/mt-idle-test.c \ - csfb/mo-active-test.c csfb/mt-active-test.c \ - csfb/mo-sms-test.c csfb/mt-sms-test.c \ - csfb/crash-test.c \ - $(NULL) -testcsfb_LDADD = $(top_srcdir)/src/libepc.la - -AM_CPPFLAGS = \ - @OGSCORE_CFLAGS@ \ - @MONGOC_CFLAGS@ \ - -I$(top_srcdir)/lib \ - -I$(top_srcdir)/src \ - -I$(top_srcdir)/lib/asn1c/common \ - -I$(top_srcdir)/lib/asn1c/s1ap \ - -I$(top_srcdir)/lib/freeDiameter/include \ - -I$(top_srcdir)/tests/common \ - $(NULL) - -AM_CFLAGS = \ - -Wall -Werror \ - -Wno-unused-function -Wno-unused-variable -Wno-deprecated-declarations \ - @OSCPPFLAGS@ \ - $(NULL) - -DEFS = \ - @DEFS@ \ - -DFD_EXT_DIR=\"$(abs_top_builddir)/lib/freeDiameter/extensions\" \ - $(NULL) - -TESTSUITE = $(srcdir)/testsuite - -check-local: atconfig $(TESTSUITE) - $(SHELL) '$(TESTSUITE)' $(TESTSUITEFLAGS) - -#installcheck-local: atconfig $(TESTSUITE) -# $(SHELL) '$(TESTSUITE)' AUTOTEST_PATH='$(bindir)' \ -# $(TESTSUITEFLAGS) - -clean-local: - test ! -f '$(TESTSUITE)' || \ - $(SHELL) '$(TESTSUITE)' --clean - -AUTOM4TE = $(SHELL) $(top_srcdir)/build/missing --run autom4te -AUTOTEST = $(AUTOM4TE) --language=autotest -$(TESTSUITE): $(srcdir)/testsuite.at $(srcdir)/package.m4 - $(AUTOTEST) -I '$(srcdir)' -o $@.tmp $@.at - mv $@.tmp $@ - -# The `:;' works around a Bash 3.2 bug when the output is not writeable. -$(srcdir)/package.m4: $(top_srcdir)/configure.ac - :;{ \ - echo '# Signature of the current package.' && \ - echo 'm4_define([AT_PACKAGE_NAME],' && \ - echo ' [$(PACKAGE_NAME)])' && \ - echo 'm4_define([AT_PACKAGE_TARNAME],' && \ - echo ' [$(PACKAGE_TARNAME)])' && \ - echo 'm4_define([AT_PACKAGE_VERSION],' && \ - echo ' [$(PACKAGE_VERSION)])' && \ - echo 'm4_define([AT_PACKAGE_STRING],' && \ - echo ' [$(PACKAGE_STRING)])' && \ - echo 'm4_define([AT_PACKAGE_BUGREPORT],' && \ - echo ' [$(PACKAGE_BUGREPORT)])'; \ - echo 'm4_define([AT_PACKAGE_URL],' && \ - echo ' [$(PACKAGE_URL)])'; \ - } >'$(srcdir)/package.m4' - -EXTRA_DIST = testsuite.at $(srcdir)/package.m4 $(TESTSUITE) - -MAINTAINERCLEANFILES = Makefile.in -MOSTLYCLEANFILES = core *.stackdump diff --git a/lib/s1ap/Makefile.am b/tests/app/meson.build similarity index 59% rename from lib/s1ap/Makefile.am rename to tests/app/meson.build index f478138db..a645c6138 100644 --- a/lib/s1ap/Makefile.am +++ b/tests/app/meson.build @@ -15,29 +15,24 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -pkglib_LTLIBRARIES = libogss1ap.la +libtestapp_sources = files(''' + test-packet.h + test-app.h -libogss1ap_la_SOURCES = \ - conv.h conv.c message.h message.c \ - $(NULL) + test-packet.c + test-app.c +'''.split()) -libogss1ap_la_DEPENDENCIES = \ - $(top_srcdir)/lib/asn1c/libasn1c.la \ - $(NULL) +libtestapp_inc = include_directories('.') -libogss1ap_la_LIBADD = \ - @OGSCORE_LIBS@ \ - $(top_srcdir)/lib/asn1c/libasn1c.la \ - $(NULL) +libtestapp = static_library('testapp', + sources : libtestapp_sources, + c_args : testcore_cc_flags, + include_directories : libtestapp_inc, + dependencies : libtestepc_dep, + install : false) -AM_CPPFLAGS = \ - @OGSCORE_CFLAGS@ \ - -I$(top_srcdir)/lib/asn1c/common \ - -I$(top_srcdir)/lib/asn1c/s1ap \ - -I$(top_srcdir)/lib \ - $(NULL) - -AM_CFLAGS = \ - -DOGS_S1AP_COMPILATION \ - -Wall -Werror \ - $(NULL) +libtestapp_dep = declare_dependency( + link_with : libtestapp, + include_directories : libtestapp_inc, + dependencies : libtestepc_dep) diff --git a/tests/common/test-app.c b/tests/app/test-app.c similarity index 76% rename from tests/common/test-app.c rename to tests/app/test-app.c index df7377eb6..2f400eac2 100644 --- a/tests/common/test-app.c +++ b/tests/app/test-app.c @@ -18,6 +18,7 @@ */ #include "test-app.h" +#include "test-config-private.h" static int connected_count = 0; static void test_diam_logger_handler(enum fd_hook_type type, struct msg * msg, @@ -29,27 +30,18 @@ static void test_diam_logger_handler(enum fd_hook_type type, struct msg * msg, } } -void test_app_run(int argc, char **argv, - const char *name, void (*init)(char **argv)) +void test_app_run(int argc, const char *const argv[], + const char *name, void (*init)(const char * const argv[])) { int rv; bool user_config; /* '-f sample-XXXX.conf -e error' is always added */ - char *argv_out[argc+4], *new_argv[argc+4]; + const char *argv_out[argc+4], *new_argv[argc+4]; int argc_out; - char directory[OGS_MAX_FILEPATH_LEN]; - char exec_file[OGS_MAX_FILEPATH_LEN]; char conf_file[OGS_MAX_FILEPATH_LEN]; - ogs_path_remove_last_component(directory, argv[0]); - if (strstr(directory, ".libs")) { - ogs_path_remove_last_component(directory, directory); - if (strstr(directory, "tests")) - ogs_path_remove_last_component(directory, directory); - } - user_config = false; for (argc_out = 0; argc_out < argc; argc_out++) { if (strcmp("-c", argv[argc_out]) == 0) { @@ -60,15 +52,18 @@ void test_app_run(int argc, char **argv, argv_out[argc_out] = NULL; if (!user_config) { - ogs_snprintf(conf_file, sizeof conf_file, "%s/tests/%s", - directory, name); + /* buildroot/configs/XXX-conf.yaml */ + ogs_snprintf(conf_file, sizeof conf_file, "%s%s", + MESON_BUILD_ROOT OGS_DIR_SEPARATOR_S + "configs" OGS_DIR_SEPARATOR_S, name); argv_out[argc_out++] = "-c"; argv_out[argc_out++] = conf_file; argv_out[argc_out] = NULL; } - ogs_snprintf(exec_file, sizeof exec_file, "%s/nextepc-epcd", directory); - argv_out[0] = exec_file; + /* buildroot/src/open5gs-main */ + argv_out[0] = MESON_BUILD_ROOT OGS_DIR_SEPARATOR_S + "src" OGS_DIR_SEPARATOR_S "open5gs-main"; rv = abts_main(argc_out, argv_out, new_argv); ogs_assert(rv == OGS_OK); diff --git a/tests/common/test-app.h b/tests/app/test-app.h similarity index 65% rename from tests/common/test-app.h rename to tests/app/test-app.h index ad2c1f853..8f037c26b 100644 --- a/tests/common/test-app.h +++ b/tests/app/test-app.h @@ -5,17 +5,18 @@ extern "C" { #endif -#include "ogs-diameter.h" +#include "ogs-diameter-common.h" #include "ogs-sctp.h" #include "ogs-dbi.h" #include "ogs-app.h" #include "mme/mme-context.h" #include "core/abts.h" +#include "test-epc.h" #include "test-packet.h" -void test_app_run(int argc, char **argv, - const char *name, void (*init)(char **argv)); +void test_app_run(int argc, const char *const argv[], + const char *name, void (*init)(const char * const argv[])); void test_app_init(void); #define test_app_final ogs_mongoc_final diff --git a/tests/common/test-packet.c b/tests/app/test-packet.c similarity index 97% rename from tests/common/test-packet.c rename to tests/app/test-packet.c index 7bfe00f92..85601264c 100644 --- a/tests/common/test-packet.c +++ b/tests/app/test-packet.c @@ -21,6 +21,8 @@ #include "ogs-sctp.h" #include "ogs-app.h" +#include "pgw/pgw-config.h" + #if HAVE_NETINET_IP_H #include #endif @@ -302,7 +304,7 @@ int tests1ap_build_setup_req( int tests1ap_build_invalid_packet(ogs_pkbuf_t **pkbuf, int i) { - char *payload[TESTS1AP_MAX_MESSAGE] = { + const char *payload[TESTS1AP_MAX_MESSAGE] = { "0011002100000300 3b40080062f22400 0001700040000700 00004062f224002c" "00030a0100", "", @@ -324,7 +326,7 @@ int tests1ap_build_invalid_packet(ogs_pkbuf_t **pkbuf, int i) int tests1ap_build_initial_ue_msg(ogs_pkbuf_t **pkbuf, int i) { - char *payload[TESTS1AP_MAX_MESSAGE] = { + const char *payload[TESTS1AP_MAX_MESSAGE] = { "000c405800000500 0800020001001a00 302f177ca0b38802 0741020809101010" "3254869104e060c0 4000050221d031d1 5c0a003103e5e034 9011035758a65d01" "00004300060000f1 1030390064400800 00f1101079baf000 86400130", @@ -474,7 +476,7 @@ int tests1ap_build_initial_ue_msg(ogs_pkbuf_t **pkbuf, int i) int tests1ap_build_identity_response(ogs_pkbuf_t **pkbuf, int i) { - char *payload[TESTS1AP_MAX_MESSAGE] = { + const char *payload[TESTS1AP_MAX_MESSAGE] = { "", "", "000d" @@ -567,7 +569,7 @@ int tests1ap_build_identity_response(ogs_pkbuf_t **pkbuf, int i) int tests1ap_build_authentication_response(ogs_pkbuf_t **pkbuf, int i) { - char *payload[TESTS1AP_MAX_MESSAGE] = { + const char *payload[TESTS1AP_MAX_MESSAGE] = { /* 0 */ "000d403e00000500 000005c00100009d 000800020001001a 001211177c0bca9d" "030753086a91970e 838fd07900644008 0000f1101079baf0 004340060000f110" @@ -675,7 +677,7 @@ int tests1ap_build_authentication_response(ogs_pkbuf_t **pkbuf, int i) int tests1ap_build_authentication_failure(ogs_pkbuf_t **pkbuf, int i) { - char *payload[TESTS1AP_MAX_MESSAGE] = { + const char *payload[TESTS1AP_MAX_MESSAGE] = { "", "", "", @@ -727,7 +729,7 @@ int tests1ap_build_authentication_failure(ogs_pkbuf_t **pkbuf, int i) int tests1ap_build_security_mode_complete(ogs_pkbuf_t **pkbuf, int i) { - char *payload[TESTS1AP_MAX_MESSAGE] = { + const char *payload[TESTS1AP_MAX_MESSAGE] = { "000d403500000500 000005c00100009d 000800020001001a 000908476b8f5f64" "00075e0064400800 00f1101079baf000 4340060000f1105b a0", "", @@ -831,7 +833,7 @@ int tests1ap_build_security_mode_complete(ogs_pkbuf_t **pkbuf, int i) int tests1ap_build_esm_information_response(ogs_pkbuf_t **pkbuf, int i) { - char *payload[TESTS1AP_MAX_MESSAGE] = { + const char *payload[TESTS1AP_MAX_MESSAGE] = { "000d40808d000005 00000005c0010000 9d00080002000100 1a006160275c0667" "58010221da280908 696e7465726e6574 274a80c223150100 001510c09a2626c0" "9a2626c09a2626c0 9a2626c223150200 0015103d3dda5c72 4cc497354ae64653" @@ -939,7 +941,7 @@ int tests1ap_build_esm_information_response(ogs_pkbuf_t **pkbuf, int i) int tests1ap_build_ue_capability_info_indication(ogs_pkbuf_t **pkbuf, int i) { - char *payload[TESTS1AP_MAX_MESSAGE] = { + const char *payload[TESTS1AP_MAX_MESSAGE] = { "0016" "40809c0000030000 0005c00100009d00 0800020001004a40 8085808304040003" "04ec598007000820 81839b4e1e3ff8ff f1ffc7ff8ffe3ffc 7ff1ffe3ff8fff1f" @@ -1244,7 +1246,7 @@ int tests1ap_build_ue_context_modification_response( int tests1ap_build_initial_context_setup_failure(ogs_pkbuf_t **pkbuf, int i) { - char *payload[TESTS1AP_MAX_MESSAGE] = { + const char *payload[TESTS1AP_MAX_MESSAGE] = { "4009 0015000003000040 0200020008400200 01000240020000", "", "", @@ -1327,7 +1329,7 @@ int tests1ap_build_initial_context_setup_failure(ogs_pkbuf_t **pkbuf, int i) int tests1ap_build_attach_complete(ogs_pkbuf_t **pkbuf, int i) { - char *payload[TESTS1AP_MAX_MESSAGE] = { + const char *payload[TESTS1AP_MAX_MESSAGE] = { "000d" "403a000005000000 05c00100009d0008 00020001001a000e 0d27c183eb950207" "4300035200c20064 40080000f1101079 baf0004340060000 f1105ba0", @@ -1433,7 +1435,7 @@ int tests1ap_build_attach_complete(ogs_pkbuf_t **pkbuf, int i) int tests1ap_build_emm_status(ogs_pkbuf_t **pkbuf, int i) { - char *payload[TESTS1AP_MAX_MESSAGE] = { + const char *payload[TESTS1AP_MAX_MESSAGE] = { "", "", "", @@ -1471,7 +1473,7 @@ int tests1ap_build_emm_status(ogs_pkbuf_t **pkbuf, int i) int tests1ap_build_detach_request(ogs_pkbuf_t **pkbuf, int i) { - char *payload[TESTS1AP_MAX_MESSAGE] = { + const char *payload[TESTS1AP_MAX_MESSAGE] = { "000c404800000600 0800020002001a 001615172ba435db 040745090bf600f1" "10000201020003e6 004300060000f110 2b67006440080000 f1109d67aa500086" "4001300060000600 40020003e6", @@ -1553,7 +1555,7 @@ int tests1ap_build_detach_request(ogs_pkbuf_t **pkbuf, int i) int tests1ap_build_ue_context_release_request(ogs_pkbuf_t **pkbuf, int i) { - char *payload[TESTS1AP_MAX_MESSAGE] = { + const char *payload[TESTS1AP_MAX_MESSAGE] = { "0012" "4018000003000000 05c00100009d0008 0002000100024002 0280", "", @@ -1630,7 +1632,7 @@ int tests1ap_build_ue_context_release_request(ogs_pkbuf_t **pkbuf, int i) int tests1ap_build_ue_context_release_complete(ogs_pkbuf_t **pkbuf, int i) { - char *payload[TESTS1AP_MAX_MESSAGE] = { + const char *payload[TESTS1AP_MAX_MESSAGE] = { "2017001300000200 004005c00100009e 00084003400002", "2017001300000200 004005c000000001 00084003400001", "2017001200000200 004005c00100009f 000840020003", @@ -1723,7 +1725,7 @@ int tests1ap_build_service_request(ogs_pkbuf_t **pkbuf, uint32_t enb_ue_s1ap_id, uint8_t seq, uint16_t mac, uint32_t m_tmsi) { - char *payload[TESTS1AP_MAX_MESSAGE] = { + const char *payload[TESTS1AP_MAX_MESSAGE] = { "000c" "4037000006000800 020004001a0005 04c7049551004300 060000f110303900" "6440080000f11007 87b8000086400140 0060000600400000 0001", @@ -1761,7 +1763,7 @@ int tests1ap_build_tau_request(ogs_pkbuf_t **pkbuf, int i, uint32_t mme_ue_s1ap_id, uint32_t enb_ue_s1ap_id, uint8_t active_flag, uint32_t m_tmsi, uint8_t seq, uint32_t mac, uint8_t *knas_int) { - char *payload[TESTS1AP_MAX_MESSAGE] = { + const char *payload[TESTS1AP_MAX_MESSAGE] = { /* Initial UE Message */ "000c" "406d000006000800 020035001a003b3a 1797c955d80a0748 010bf600f1100002" @@ -1800,7 +1802,7 @@ int tests1ap_build_tau_request(ogs_pkbuf_t **pkbuf, int i, enb_ue_s1ap_id = htonl(enb_ue_s1ap_id << 8); memcpy((*pkbuf)->data + 11, &enb_ue_s1ap_id, 3); if (active_flag) { - char *active_buf = (*pkbuf)->data + 26; + unsigned char *active_buf = (*pkbuf)->data + 26; *active_buf |= 0x08; } mac = htonl(mac); @@ -1833,7 +1835,7 @@ int tests1ap_build_tau_request(ogs_pkbuf_t **pkbuf, int i, int tests1ap_build_extended_service_request(ogs_pkbuf_t **pkbuf, int i, uint8_t service_type, uint32_t m_tmsi, uint8_t seq, uint8_t *knas_int) { - char *payload[TESTS1AP_MAX_MESSAGE] = { + const char *payload[TESTS1AP_MAX_MESSAGE] = { "", "", "", @@ -1958,7 +1960,7 @@ int tests1ap_build_extended_service_request(ogs_pkbuf_t **pkbuf, int i, int tests1ap_build_pdn_connectivity_request( ogs_pkbuf_t **pkbuf, int i) { - char *payload[TESTS1AP_MAX_MESSAGE] = { + const char *payload[TESTS1AP_MAX_MESSAGE] = { "000d40640000" "0500000002 0001000800020001 001a003b3a277c 81dab50a0205d011" "281208696e746572 6e6574036e673204 6d6e6574271a8080 2110010000108106" @@ -2005,7 +2007,7 @@ int tests1ap_build_pdn_connectivity_request( int tests1ap_build_pdn_disconnectivity_request( ogs_pkbuf_t **pkbuf, int i) { - char *payload[TESTS1AP_MAX_MESSAGE] = { + const char *payload[TESTS1AP_MAX_MESSAGE] = { "000d40370000" "0500000005c08000 0108000800020001 001a000b0a2732 423c53040206d206" "006440080055f501 0019d01000434006 0055f5011022", @@ -2149,7 +2151,7 @@ int tests1ap_build_e_rab_setup_response( int tests1ap_build_e_rab_modify_response(ogs_pkbuf_t **pkbuf, int i) { - char *payload[TESTS1AP_MAX_MESSAGE] = { + const char *payload[TESTS1AP_MAX_MESSAGE] = { "2006" "001b000003000040 0480000001000840 020001001f400600 002500010e", "", @@ -2188,7 +2190,7 @@ int tests1ap_build_e_rab_modify_response(ogs_pkbuf_t **pkbuf, int i) int tests1ap_build_e_rab_release_response(ogs_pkbuf_t **pkbuf, int i) { - char *payload[TESTS1AP_MAX_MESSAGE] = { + const char *payload[TESTS1AP_MAX_MESSAGE] = { "200700190000" "0300004002 0001000840020001 0045400600000f 40010c", "200700190000" @@ -2229,7 +2231,7 @@ int tests1ap_build_e_rab_release_response(ogs_pkbuf_t **pkbuf, int i) int tests1ap_build_activate_default_bearer_accept( ogs_pkbuf_t **pkbuf, int i) { - char *payload[TESTS1AP_MAX_MESSAGE] = { + const char *payload[TESTS1AP_MAX_MESSAGE] = { "000d40360000" "0500000005c08000 0107000800020001 001a000a0927e7 f5bb400b6200c200" "6440080055f50100 19d0100043400600 55f5011022", @@ -2270,7 +2272,7 @@ int tests1ap_build_activate_default_bearer_accept( int tests1ap_build_activate_dedicated_bearer_accept( ogs_pkbuf_t **pkbuf, int i) { - char *payload[TESTS1AP_MAX_MESSAGE] = { + const char *payload[TESTS1AP_MAX_MESSAGE] = { "000d403600000500" "000005c000000001 00080002000100 1a000a0927078a5f 34037200c6006440" "080000f1109d67aa 50004340060000f1 102b67", @@ -2323,7 +2325,7 @@ int tests1ap_build_activate_dedicated_bearer_accept( int tests1ap_build_modify_bearer_accept( ogs_pkbuf_t **pkbuf, int i) { - char *payload[TESTS1AP_MAX_MESSAGE] = { + const char *payload[TESTS1AP_MAX_MESSAGE] = { "000d" "4035000005000000 0480000001000800 020001001a000a09 27a5c0d564067200" "ca006440080064f0 430020a000004340 060064f043020a", @@ -2371,7 +2373,7 @@ int tests1ap_build_modify_bearer_accept( int tests1ap_build_deactivate_bearer_accept( ogs_pkbuf_t **pkbuf, int i) { - char *payload[TESTS1AP_MAX_MESSAGE] = { + const char *payload[TESTS1AP_MAX_MESSAGE] = { "000d40330000" "0500000002 0001000800020001 001a000a09274c b2ebbd056200ce00" "6440080055f50100 19d0100043400600 55f5011022", @@ -2604,7 +2606,7 @@ int tests1ap_build_path_switch_request( int tests1ap_build_handover_required( ogs_pkbuf_t **pkbuf, int i) { - char *payload[TESTS1AP_MAX_MESSAGE] = { + const char *payload[TESTS1AP_MAX_MESSAGE] = { "0000" "0081030000060000 0005c0020000c400 080002000c000100 0100000240020220" "0004000d0000f110 0000043000f11030 3900680080d080ce 4080ab0f1014c598" @@ -2671,7 +2673,7 @@ int tests1ap_build_handover_required( int tests1ap_build_handover_failure(ogs_pkbuf_t **pkbuf, int i) { - char *payload[TESTS1AP_MAX_MESSAGE] = { + const char *payload[TESTS1AP_MAX_MESSAGE] = { "4001 0012000002000040 05c0020000c5 000240020000", "", @@ -2714,7 +2716,7 @@ int tests1ap_build_handover_request_ack( *Target_ToSource_TransparentContainer = NULL; char hexbuf[OGS_MAX_SDU_LEN]; - char *payload = + const char *payload = "00 80810bf900d8af40 00a0339057801f47 88009e81de2c20a4" "81de2c404a00ef16 2000010044013f21 2249008093efd243 3914cd2aa0a0142f" "f2214d6dfb82c194 0b10080000020040 bbfd55aeab41ad80 8fd50398381c08fd" @@ -2857,7 +2859,7 @@ int tests1ap_build_handover_request_ack( int tests1ap_build_handover_request_ack_static( ogs_pkbuf_t **pkbuf, int i) { - char *payload[TESTS1AP_MAX_MESSAGE] = { + const char *payload[TESTS1AP_MAX_MESSAGE] = { "2001" "0080e80000040000 4005c0020000c500 0840020008001240 47010014401f78a1" "f07f000001010007 080f807f00000101 0007090f807f0000 010100070a001440" @@ -2922,7 +2924,7 @@ int tests1ap_build_handover_request_ack_static( int tests1ap_build_enb_status_transfer( ogs_pkbuf_t **pkbuf, int i) { - char *payload[TESTS1AP_MAX_MESSAGE] = { + const char *payload[TESTS1AP_MAX_MESSAGE] = { "0018" "4027000003000000 05c0020000c40008 0002000c005a0011 00000059400b0500" "004b000000001100 00", @@ -2965,7 +2967,7 @@ int tests1ap_build_enb_status_transfer( int tests1ap_build_enb_configuration_transfer( ogs_pkbuf_t **pkbuf, int i) { - char *payload[TESTS1AP_MAX_MESSAGE] = { + const char *payload[TESTS1AP_MAX_MESSAGE] = { "0028" "403b000001008140 3440049699000004 3004969900020004 969900001f200496" "9900020000000098 401341f0ac110e02 0000009940070200 f8ac110e02", @@ -3007,7 +3009,7 @@ int tests1ap_build_enb_configuration_transfer( int tests1ap_build_handover_notify(ogs_pkbuf_t **pkbuf, int i) { - char *payload[TESTS1AP_MAX_MESSAGE] = { + const char *payload[TESTS1AP_MAX_MESSAGE] = { "0002" "4028000004000000 05c0020000c50008 0002000800644008 0000f11000043a00" "004340060000f110 3039", @@ -3049,7 +3051,7 @@ int tests1ap_build_handover_notify(ogs_pkbuf_t **pkbuf, int i) int tests1ap_build_handover_cancel(ogs_pkbuf_t **pkbuf, int i) { - char *payload[TESTS1AP_MAX_MESSAGE] = { + const char *payload[TESTS1AP_MAX_MESSAGE] = { "0004" "0018000003000000 05c0020000c60008 0002000d00024002 0120", "", @@ -3088,7 +3090,7 @@ int tests1ap_build_handover_cancel(ogs_pkbuf_t **pkbuf, int i) int tests1ap_build_s1_reset(ogs_pkbuf_t **pkbuf, int i) { - char *payload[TESTS1AP_MAX_MESSAGE] = { + const char *payload[TESTS1AP_MAX_MESSAGE] = { "000e001500000200 0240020060005c00 084000005b000220 04", "", "", @@ -3126,7 +3128,7 @@ int tests1ap_build_s1_reset(ogs_pkbuf_t **pkbuf, int i) int tests1ap_build_uplink_nas_transport(ogs_pkbuf_t **pkbuf, int i) { - char *payload[TESTS1AP_MAX_MESSAGE] = { + const char *payload[TESTS1AP_MAX_MESSAGE] = { "000d40809d000005 0000000200010008 00020001001a0074 7327f908d4bd0307" "636a390167000300 0581005155f55d11 030c914477680205 490000055ad2e2b1" "252d467ff6de6c47 efd568375b303613 166fb51c6d160cc2 8ab462b006a3d98a" @@ -3187,6 +3189,7 @@ int testgtpu_build_ping( pkbuf = ogs_pkbuf_alloc(NULL, 200 /* enough for ICMP; use smaller buffer */); ogs_pkbuf_put(pkbuf, 200); + memset(pkbuf->data, 0, pkbuf->len); gtp_h = (ogs_gtp_header_t *)pkbuf->data; gtp_h->flags = 0x30; @@ -3263,7 +3266,7 @@ int testgtpu_build_ping( int testgtpu_build_slacc_rs(ogs_pkbuf_t **pkbuf, int i) { - char *payload[TESTS1AP_MAX_MESSAGE] = { + const char *payload[TESTS1AP_MAX_MESSAGE] = { "32ff003400000001 00000000 6000000000083aff fe80000000000000 0000000000000002" "ff02000000000000 0000000000000002 85007d3500000000", @@ -3282,7 +3285,7 @@ int testgtpu_build_slacc_rs(ogs_pkbuf_t **pkbuf, int i) int testsgsap_location_update_accept(ogs_pkbuf_t **pkbuf, int i) { - char *payload[TESTS1AP_MAX_MESSAGE] = { + const char *payload[TESTS1AP_MAX_MESSAGE] = { "0a01082926240000 111893040509f107 09260e05f49ee88e 64", "0a01087942120000 000030040527f412 c9580e05f437ab9c c5", "", @@ -3304,7 +3307,7 @@ int testsgsap_location_update_accept(ogs_pkbuf_t **pkbuf, int i) int testsgsap_location_update_reject(ogs_pkbuf_t **pkbuf, int i) { - char *payload[TESTS1AP_MAX_MESSAGE] = { + const char *payload[TESTS1AP_MAX_MESSAGE] = { "0b01082926240000 1118930f01030405 09f1070926", "", "", @@ -3326,7 +3329,7 @@ int testsgsap_location_update_reject(ogs_pkbuf_t **pkbuf, int i) int testsgsap_imsi_detach_ack(ogs_pkbuf_t **pkbuf, int i) { - char *payload[TESTS1AP_MAX_MESSAGE] = { + const char *payload[TESTS1AP_MAX_MESSAGE] = { "1401082926240000 111893" "", "", @@ -3348,7 +3351,7 @@ int testsgsap_imsi_detach_ack(ogs_pkbuf_t **pkbuf, int i) int testsgsap_paging_request(ogs_pkbuf_t **pkbuf, int i) { - char *payload[TESTS1AP_MAX_MESSAGE] = { + const char *payload[TESTS1AP_MAX_MESSAGE] = { "0101082926240000 111893021003766c 72076578616d706c 65036e6574200101" "040509f1070926", "0101082926240000 111892021003766c 72076578616d706c 65036e6574200101" @@ -3382,7 +3385,7 @@ int testsgsap_paging_request(ogs_pkbuf_t **pkbuf, int i) int testsgsap_reset_indication(ogs_pkbuf_t **pkbuf, int i) { - char *payload[TESTS1AP_MAX_MESSAGE] = { + const char *payload[TESTS1AP_MAX_MESSAGE] = { "15021003766c7207 6578616d706c6503 6e6574", "", "", @@ -3404,7 +3407,7 @@ int testsgsap_reset_indication(ogs_pkbuf_t **pkbuf, int i) int testsgsap_release_request(ogs_pkbuf_t **pkbuf, int i) { - char *payload[TESTS1AP_MAX_MESSAGE] = { + const char *payload[TESTS1AP_MAX_MESSAGE] = { "1b01082926240000 111893", "", "", @@ -3426,7 +3429,7 @@ int testsgsap_release_request(ogs_pkbuf_t **pkbuf, int i) int testsgsap_downlink_unitdata(ogs_pkbuf_t **pkbuf, int i) { - char *payload[TESTS1AP_MAX_MESSAGE] = { + const char *payload[TESTS1AP_MAX_MESSAGE] = { "0701082926240000 1118931626090123 0100079144775810 0650001700048032" "2400009160404044 150009c8329bfd06 4d9b53", "", @@ -3449,7 +3452,7 @@ int testsgsap_downlink_unitdata(ogs_pkbuf_t **pkbuf, int i) int testsgsap_mm_information_request(ogs_pkbuf_t **pkbuf, int i) { - char *payload[TESTS1AP_MAX_MESSAGE] = { + const char *payload[TESTS1AP_MAX_MESSAGE] = { "1a01087942120000 0000301714430483 d46413450483d464 1347917071028401" "29", "", diff --git a/tests/common/test-packet.h b/tests/app/test-packet.h similarity index 100% rename from tests/common/test-packet.h rename to tests/app/test-packet.h diff --git a/tests/core/abts-main.c b/tests/core/abts-main.c new file mode 100644 index 000000000..bc9a6baf4 --- /dev/null +++ b/tests/core/abts-main.c @@ -0,0 +1,116 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "ogs-core.h" +#include "core/abts.h" + +abts_suite *test_list(abts_suite *suite); +abts_suite *test_pool(abts_suite *suite); +abts_suite *test_strings(abts_suite *suite); +abts_suite *test_time(abts_suite *suite); +abts_suite *test_conv(abts_suite *suite); +abts_suite *test_log(abts_suite *suite); +abts_suite *test_pkbuf(abts_suite *suite); +abts_suite *test_memory(abts_suite *suite); +abts_suite *test_rbtree(abts_suite *suite); +abts_suite *test_timer(abts_suite *suite); +abts_suite *test_thread(abts_suite *suite); +abts_suite *test_socket(abts_suite *suite); +abts_suite *test_queue(abts_suite *suite); +abts_suite *test_poll(abts_suite *suite); +abts_suite *test_tlv(abts_suite *suite); +abts_suite *test_fsm(abts_suite *suite); +abts_suite *test_hash(abts_suite *suite); + +const struct testlist { + abts_suite *(*func)(abts_suite *suite); +} alltests[] = { + {test_list}, + {test_pool}, + {test_strings}, + {test_time}, + {test_conv}, + {test_log}, + {test_pkbuf}, + {test_memory}, + {test_rbtree}, + {test_timer}, + {test_thread}, + {test_socket}, + {test_queue}, + {test_poll}, + {test_tlv}, + {test_fsm}, + {test_hash}, + {NULL}, +}; + +static void terminate(void) +{ + ogs_pkbuf_default_destroy(); + ogs_core_terminate(); +} + +int main(int argc, const char *const argv[]) +{ + int rv, i, opt; + ogs_getopt_t options; + struct { + char *log_level; + char *domain_mask; + } optarg; + const char *argv_out[argc+2]; /* '-e error' is always added */ + + abts_suite *suite = NULL; + ogs_pkbuf_config_t config; + + rv = abts_main(argc, argv, argv_out); + if (rv != OGS_OK) return rv; + + memset(&optarg, 0, sizeof(optarg)); + ogs_getopt_init(&options, (char**)argv_out); + + while ((opt = ogs_getopt(&options, "e:m:")) != -1) { + switch (opt) { + case 'e': + optarg.log_level = options.optarg; + break; + case 'm': + optarg.domain_mask = options.optarg; + break; + case '?': + default: + fprintf(stderr, "%s: should not be reached\n", OGS_FUNC); + return OGS_ERROR; + } + } + + ogs_core_initialize(); + ogs_pkbuf_default_init(&config); + ogs_pkbuf_default_create(&config); + atexit(terminate); + + rv = ogs_log_config_domain(optarg.domain_mask, optarg.log_level); + if (rv != OGS_OK) return rv; + + for (i = 0; alltests[i].func; i++) + suite = alltests[i].func(suite); + + return abts_report(suite); +} diff --git a/tests/core/conv-test.c b/tests/core/conv-test.c new file mode 100644 index 000000000..0863fb04a --- /dev/null +++ b/tests/core/conv-test.c @@ -0,0 +1,163 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "ogs-core.h" +#include "core/abts.h" + +static void conv_test2(abts_case *tc, void *data) +{ +#define K "4 6 5B5 CE8 B199B49FAA5F0A2EE238A6BC " +#define OP "5F1D289C 5D354D0A 140C2548 F5F3E3BA" +#define OPc "E8ED2 89D EBA9 52E4 283B 54E8 8E61 83CA" +#define AMF "8000" + uint8_t k[16] = "\x46\x5B\x5C\xE8\xB1\x99\xB4\x9F\xAA\x5F\x0A\x2E\xE2\x38\xA6\xBC"; + uint8_t op[16] = "\x5F\x1D\x28\x9C\x5D\x35\x4D\x0A\x14\x0C\x25\x48\xF5\xF3\xE3\xBA"; + uint8_t opc[16] = "\xE8\xED\x28\x9D\xEB\xA9\x52\xE4\x28\x3B\x54\xE8\x8E\x61\x83\xCA"; + uint8_t amf[2] = { 0x80, 0x00 }; +#define LOWER " 12abcdE F" + uint8_t lower[4] = "\x12\xab\xcd\xef"; + + char buffer[16]; + + ABTS_TRUE(tc, memcmp(k, OGS_HEX(K, strlen(K), buffer), 16) == 0); + + ABTS_TRUE(tc, memcmp(op, OGS_HEX(OP, strlen(OP), buffer), 16) == 0); + + ABTS_TRUE(tc, memcmp(opc, OGS_HEX(OPc, strlen(OPc), buffer), 16) == 0); + + ABTS_TRUE(tc, memcmp(amf, OGS_HEX(AMF, strlen(AMF), buffer), 2) == 0); + + ABTS_TRUE(tc, memcmp(lower, + OGS_HEX(LOWER, strlen(LOWER), buffer), 4) == 0); +} + +static void conv_test3(abts_case *tc, void *data) +{ + uint8_t k[16] = "\x46\x5B\x5C\xE8\xB1\x99\xB4\x9F\xAA\x5F\x0A\x2E\xE2\x38\xA6\xBC"; + uint8_t op[16] = "\x5F\x1D\x28\x9C\x5D\x35\x4D\x0A\x14\x0C\x25\x48\xF5\xF3\xE3\xBA"; + uint8_t opc[16] = "\xE8\xED\x28\x9D\xEB\xA9\x52\xE4\x28\x3B\x54\xE8\x8E\x61\x83\xCA"; + uint8_t amf[2] = { 0x80, 0x00 }; + uint8_t lower[4] = "\x12\xab\xcd\xef"; + uint8_t buffer[128]; + + ABTS_TRUE(tc, strcmp("465B5CE8 B199B49F AA5F0A2E E238A6BC", + ogs_hex_to_ascii(k, sizeof(k), buffer, sizeof(buffer))) == 0); + ABTS_TRUE(tc, strcmp("5F1D289C 5D354D0A 140C2548 F5F3E3BA", + ogs_hex_to_ascii(op, sizeof(op), buffer, sizeof(buffer))) == 0); + ABTS_TRUE(tc, strcmp("E8ED289D EBA952E4 283B54E8 8E6183CA", + ogs_hex_to_ascii(opc, sizeof(opc), buffer, sizeof(buffer))) == 0); + ABTS_TRUE(tc, strcmp("8000", + ogs_hex_to_ascii(amf, sizeof(amf), buffer, sizeof(buffer))) == 0); + ABTS_TRUE(tc, strcmp("12ABCDEF", + ogs_hex_to_ascii(lower, sizeof(lower), buffer, sizeof(buffer))) == 0); +} + +static void conv_test4(abts_case *tc, void *data) +{ +#define MAX_SIZE 8 + uint8_t tmp[MAX_SIZE] = "\x01\x23\x45\x67\x89\xab\xcd\xef"; + uint8_t buf[MAX_SIZE]; + uint64_t num; + + num = 0x0123456789abcdef; + ABTS_TRUE(tc, memcmp(tmp, ogs_uint64_to_buffer(num, 8, buf), 8) == 0); + num = 0x0123456789abcd; + ABTS_TRUE(tc, memcmp(tmp, ogs_uint64_to_buffer(num, 7, buf), 7) == 0); + num = 0x0123456789ab; + ABTS_TRUE(tc, memcmp(tmp, ogs_uint64_to_buffer(num, 6, buf), 6) == 0); + num = 0x0123456789; + ABTS_TRUE(tc, memcmp(tmp, ogs_uint64_to_buffer(num, 5, buf), 5) == 0); + num = 0x01234567; + ABTS_TRUE(tc, memcmp(tmp, ogs_uint64_to_buffer(num, 4, buf), 4) == 0); + num = 0x012345; + ABTS_TRUE(tc, memcmp(tmp, ogs_uint64_to_buffer(num, 3, buf), 3) == 0); + num = 0x0123; + ABTS_TRUE(tc, memcmp(tmp, ogs_uint64_to_buffer(num, 2, buf), 2) == 0); + num = 0x01; + ABTS_TRUE(tc, memcmp(tmp, ogs_uint64_to_buffer(num, 1, buf), 1) == 0); +} + +static void conv_test5(abts_case *tc, void *data) +{ + ABTS_TRUE(tc, 0x0123456789abcdef == + ogs_buffer_to_uint64((void*)"\x01\x23\x45\x67\x89\xab\xcd\xef", 8)); + ABTS_TRUE(tc, 0x0123456789abcd == + ogs_buffer_to_uint64((void*)"\x01\x23\x45\x67\x89\xab\xcd", 7)); + ABTS_TRUE(tc, 0x0123456789ab == + ogs_buffer_to_uint64((void*)"\x01\x23\x45\x67\x89\xab", 6)); + ABTS_TRUE(tc, 0x0123456789 == + ogs_buffer_to_uint64((void*)"\x01\x23\x45\x67\x89", 5)); + ABTS_TRUE(tc, 0x01234567 == + ogs_buffer_to_uint64((void*)"\x01\x23\x45\x67", 4)); + ABTS_TRUE(tc, 0x012345 == + ogs_buffer_to_uint64((void*)"\x01\x23\x45", 3)); + ABTS_TRUE(tc, 0x0123 == + ogs_buffer_to_uint64((void*)"\x01\x23", 2)); + ABTS_TRUE(tc, 0x01 == + ogs_buffer_to_uint64((void*)"\x01", 1)); +} + +static void conv_test6(abts_case *tc, void *data) +{ + char out[16]; + int out_len; +#define MSISDN "491725670014" + ogs_bcd_to_buffer(MSISDN, out, &out_len); + ABTS_TRUE(tc, memcmp("\x94\x71\x52\x76\x00\x41", out, out_len) == 0); +#define MEI "3516020019874800" + ogs_bcd_to_buffer(MEI, out, &out_len); + ABTS_TRUE(tc, + memcmp("\x53\x61\x20\x00\x91\x78\x84\x00", out, out_len) == 0); +#define IMSI "001010123456819" + ogs_bcd_to_buffer(IMSI, out, &out_len); + ABTS_TRUE(tc, + memcmp("\x00\x01\x01\x21\x43\x65\x18\xf9", out, out_len) == 0); +} + +static void conv_test7(abts_case *tc, void *data) +{ + char out[32]; + uint8_t buf1[6] = "\x94\x71\x52\x76\x00\x41"; + int buf1_len = 6; + uint8_t buf2[8] = "\x53\x61\x20\x00\x91\x78\x84\x00"; + int buf2_len = 8; + uint8_t buf3[8] = "\x00\x01\x01\x21\x43\x65\x18\xf9"; + int buf3_len = 8; + + ogs_buffer_to_bcd(buf1, buf1_len, out); + ABTS_TRUE(tc, strcmp("491725670014", out) == 0); + ogs_buffer_to_bcd(buf2, buf2_len, out); + ABTS_TRUE(tc, strcmp("3516020019874800", out) == 0); + ogs_buffer_to_bcd(buf3, buf3_len, out); + ABTS_TRUE(tc, strcmp("001010123456819", out) == 0); +} + +abts_suite *test_conv(abts_suite *suite) +{ + suite = ADD_SUITE(suite) + + abts_run_test(suite, conv_test2, NULL); + abts_run_test(suite, conv_test3, NULL); + abts_run_test(suite, conv_test4, NULL); + abts_run_test(suite, conv_test5, NULL); + abts_run_test(suite, conv_test6, NULL); + abts_run_test(suite, conv_test7, NULL); + + return suite; +} diff --git a/tests/core/fsm-test.c b/tests/core/fsm-test.c new file mode 100644 index 000000000..21ba6cd07 --- /dev/null +++ b/tests/core/fsm-test.c @@ -0,0 +1,282 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "ogs-core.h" +#include "core/abts.h" + +enum bomb_signal_t { + UP_SIG = OGS_FSM_USER_SIG, + DOWN_SIG, + ARM_SIG +}; + +typedef struct _tick_event_t { + int id; +} tick_event_t; + +typedef struct _bomb_t { + ogs_fsm_t fsm; + uint8_t timeout; + uint8_t code; + uint8_t defuse; +} bomb_t; + +void bomb_initial(bomb_t *s, tick_event_t *e); +void bomb_setting(bomb_t *s, tick_event_t *e); +void bomb_timing(bomb_t *s, tick_event_t *e); + +void bomb_create(bomb_t *s, uint8_t defuse) +{ + ogs_fsm_create(&s->fsm, &bomb_initial, 0); + s->defuse = defuse; +} + +void bomb_initial(bomb_t *s, tick_event_t *e) +{ + s->timeout = 10; + OGS_FSM_TRAN(s, &bomb_setting); +} + +void bomb_setting(bomb_t *s, tick_event_t *e) +{ + switch (e->id) { + case UP_SIG: + if (s->timeout < 12) { + ++s->timeout; + } + break; + case DOWN_SIG: + if (s->timeout > 8) { + --s->timeout; + } + break; + case ARM_SIG: + OGS_FSM_TRAN(s, &bomb_timing); + break; + } +} + +void bomb_timing(bomb_t *s, tick_event_t *e) +{ + switch (e->id) { + case OGS_FSM_ENTRY_SIG: + s->code = 0; + break; + case UP_SIG: + s->code <<= 1; + s->code |= 1; + break; + case DOWN_SIG: + s->code <<= 1; + break; + case ARM_SIG: + if (s->code == s->defuse) + { + OGS_FSM_TRAN(s, &bomb_setting); + break; + } + } +} + +static void test1_func(abts_case *tc, void *data) +{ + bomb_t bomb; + tick_event_t tick_event; + + bomb_create(&bomb, 14); + + ogs_fsm_init(&bomb, 0); + ABTS_PTR_EQUAL(tc, &bomb_setting, OGS_FSM_STATE(&bomb)); + ABTS_INT_EQUAL(tc, 10, bomb.timeout); + + tick_event.id = UP_SIG; + ogs_fsm_dispatch(&bomb, &tick_event); + ABTS_PTR_EQUAL(tc, &bomb_setting, OGS_FSM_STATE(&bomb)); + ABTS_INT_EQUAL(tc, 11, bomb.timeout); + ogs_fsm_dispatch(&bomb, &tick_event); + ABTS_PTR_EQUAL(tc, &bomb_setting, OGS_FSM_STATE(&bomb)); + ABTS_INT_EQUAL(tc, 12, bomb.timeout); + ogs_fsm_dispatch(&bomb, &tick_event); + ABTS_PTR_EQUAL(tc, &bomb_setting, OGS_FSM_STATE(&bomb)); + ABTS_INT_EQUAL(tc, 12, bomb.timeout); + + tick_event.id = DOWN_SIG; + ogs_fsm_dispatch(&bomb, &tick_event); + ABTS_PTR_EQUAL(tc, &bomb_setting, OGS_FSM_STATE(&bomb)); + ABTS_INT_EQUAL(tc, 11, bomb.timeout); + ogs_fsm_dispatch(&bomb, &tick_event); + ABTS_PTR_EQUAL(tc, &bomb_setting, OGS_FSM_STATE(&bomb)); + ABTS_INT_EQUAL(tc, 10, bomb.timeout); + ogs_fsm_dispatch(&bomb, &tick_event); + ABTS_PTR_EQUAL(tc, &bomb_setting, OGS_FSM_STATE(&bomb)); + ABTS_INT_EQUAL(tc, 9, bomb.timeout); + ogs_fsm_dispatch(&bomb, &tick_event); + ABTS_PTR_EQUAL(tc, &bomb_setting, OGS_FSM_STATE(&bomb)); + ABTS_INT_EQUAL(tc, 8, bomb.timeout); + ogs_fsm_dispatch(&bomb, &tick_event); + ABTS_PTR_EQUAL(tc, &bomb_setting, OGS_FSM_STATE(&bomb)); + ABTS_INT_EQUAL(tc, 8, bomb.timeout); + + tick_event.id = ARM_SIG; + ogs_fsm_dispatch((ogs_fsm_t *)&bomb, &tick_event); + ABTS_PTR_EQUAL(tc, &bomb_timing, OGS_FSM_STATE(&bomb)); + ABTS_INT_EQUAL(tc, 0, bomb.code); + + tick_event.id = UP_SIG; + ogs_fsm_dispatch((ogs_fsm_t *)&bomb, &tick_event); + ABTS_PTR_EQUAL(tc, &bomb_timing, OGS_FSM_STATE(&bomb)); + ABTS_INT_EQUAL(tc, 1, bomb.code); + + tick_event.id = UP_SIG; + ogs_fsm_dispatch((ogs_fsm_t *)&bomb, &tick_event); + ABTS_PTR_EQUAL(tc, &bomb_timing, OGS_FSM_STATE(&bomb)); + ABTS_INT_EQUAL(tc, 3, bomb.code); + + tick_event.id = UP_SIG; + ogs_fsm_dispatch((ogs_fsm_t *)&bomb, &tick_event); + ABTS_PTR_EQUAL(tc, &bomb_timing, OGS_FSM_STATE(&bomb)); + ABTS_INT_EQUAL(tc, 7, bomb.code); + + tick_event.id = DOWN_SIG; + ogs_fsm_dispatch((ogs_fsm_t *)&bomb, &tick_event); + ABTS_PTR_EQUAL(tc, &bomb_timing, OGS_FSM_STATE(&bomb)); + ABTS_INT_EQUAL(tc, 14, bomb.code); + + tick_event.id = ARM_SIG; + ogs_fsm_dispatch((ogs_fsm_t *)&bomb, &tick_event); + ABTS_PTR_EQUAL(tc, &bomb_setting, OGS_FSM_STATE(&bomb)); +} + +enum alarm_signal_e { + TICK_SIG = OGS_FSM_USER_SIG, + ALARM_SET_SIG, + ALARM_ON_SIG, + ALARM_OFF_SIG, + ALARM_SIG, + CLOCK_12H_SIG, + CLOCK_24H_SIG, + TIME_SIG, + TERMINATE_SIG +}; + +typedef struct alarm_s { + ogs_fsm_t fsm; + uint32_t time; +} alarm_t; + +typedef struct set_event_s { + int id; + uint8_t digit; +} set_event_t; + +typedef struct time_event_s { + int id; + uint8_t current_time; +} time_event_t; + +void alarm_initial(alarm_t *s, set_event_t *e); +void alarm_off(alarm_t *s, set_event_t *e); +void alarm_on(alarm_t *s, time_event_t *e); + +void alarm_initial(alarm_t *s, set_event_t *e) +{ + s->time = 12*60; + OGS_FSM_TRAN(s, &alarm_off); +} + +void alarm_off(alarm_t *s, set_event_t *e) +{ + uint32_t alarm; + + switch (e->id) { + case OGS_FSM_ENTRY_SIG: + s->time = (s->time/60)*100 + s->time%60; + break; + case OGS_FSM_EXIT_SIG: + s->time = (s->time/100)*60 + s->time%100; + break; + case ALARM_ON_SIG: + OGS_FSM_TRAN(s, &alarm_on); + break; + case ALARM_SET_SIG: + alarm = (10 * s->time + + e->digit) % 10000; + if ((alarm / 100 < 24) && (alarm % 100 < 60)) + { + s->time = alarm; + } + else + { + s->time = 0; + } + break; + } +} + +void alarm_on(alarm_t *s, time_event_t *e) +{ + switch (e->id) { + case OGS_FSM_ENTRY_SIG: + break; + case ALARM_SET_SIG: + break; + case ALARM_OFF_SIG: + OGS_FSM_TRAN(s, &alarm_off); + break; + } +} + +static void test2_func(abts_case *tc, void *data) +{ + alarm_t alarm; + set_event_t set_event; + time_event_t time_event; + + ogs_fsm_create(&alarm.fsm, &alarm_initial, 0); + + ogs_fsm_init(&alarm, 0); + ABTS_PTR_EQUAL(tc, &alarm_off, OGS_FSM_STATE(&alarm)); + ABTS_INT_EQUAL(tc, 1200, alarm.time); + + set_event.id = ALARM_ON_SIG; + ogs_fsm_dispatch(&alarm, &set_event); + ABTS_PTR_EQUAL(tc, &alarm_on, OGS_FSM_STATE(&alarm)); + ABTS_INT_EQUAL(tc, 720, alarm.time); + + time_event.id = ALARM_OFF_SIG; + ogs_fsm_dispatch(&alarm, &time_event); + ABTS_PTR_EQUAL(tc, &alarm_off, OGS_FSM_STATE(&alarm)); + ABTS_INT_EQUAL(tc, 1200, alarm.time); + + set_event.id = ALARM_SET_SIG; + set_event.digit = 0; + ogs_fsm_dispatch(&alarm, &set_event); + ABTS_PTR_EQUAL(tc, &alarm_off, OGS_FSM_STATE(&alarm)); + ABTS_INT_EQUAL(tc, 2000, alarm.time); +} + +abts_suite *test_fsm(abts_suite *suite) +{ + suite = ADD_SUITE(suite) + + abts_run_test(suite, test1_func, NULL); + abts_run_test(suite, test2_func, NULL); + + return suite; +} diff --git a/tests/core/hash-test.c b/tests/core/hash-test.c new file mode 100644 index 000000000..47223ca5d --- /dev/null +++ b/tests/core/hash-test.c @@ -0,0 +1,411 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "ogs-core.h" +#include "core/abts.h" + +#define MAX_LTH 256 +#define MAX_DEPTH 11 + +static int comp_string(const void *str1, const void *str2) +{ + return strcmp(str1,str2); +} + +static void dump_hash(ogs_hash_t *h, char str[][MAX_LTH]) +{ + ogs_hash_index_t *hi; + int i = 0; + + for (hi = ogs_hash_first(h); hi; hi = ogs_hash_next(hi)) { + const char *key = ogs_hash_this_key(hi); + int len = ogs_hash_this_key_len(hi); + char *val = ogs_hash_this_val(hi); + + str[i][0]='\0'; + ogs_snprintf(str[i], MAX_LTH, "%sKey %s (%d) Value %s\n", + str[i], key, len, val); + i++; + } + str[i][0]='\0'; + ogs_snprintf(str[i], MAX_LTH, "%s#entries %d\n", str[i], i); + + /* Sort the result strings so that they can be checked for expected results easily, + * without having to worry about platform quirks + */ + qsort( + str, /* Pointer to elements */ + i, /* number of elements */ + MAX_LTH, /* size of one element */ + comp_string /* Pointer to comparison routine */ + ); +} + +static void sum_hash(ogs_hash_t *h, int *pcount, int *keySum, int *valSum) +{ + ogs_hash_index_t *hi; + void *val, *key; + int count = 0; + + *keySum = 0; + *valSum = 0; + *pcount = 0; + for (hi = ogs_hash_first(h); hi; hi = ogs_hash_next(hi)) { + ogs_hash_this(hi, (void*)&key, NULL, &val); + *valSum += *(int *)val; + *keySum += *(int *)key; + count++; + } + *pcount=count; +} + +static void hash_make_test(abts_case *tc, void *data) +{ + ogs_hash_t *h = NULL; + + h = ogs_hash_make(); + ABTS_PTR_NOTNULL(tc, h); + + ogs_hash_destroy(h); +} + +static void hash_set_test(abts_case *tc, void *data) +{ + ogs_hash_t *h = NULL; + char *result = NULL; + + h = ogs_hash_make(); + ABTS_PTR_NOTNULL(tc, h); + + ogs_hash_set(h, "key", OGS_HASH_KEY_STRING, "value"); + result = ogs_hash_get(h, "key", OGS_HASH_KEY_STRING); + ABTS_STR_EQUAL(tc, "value", result); + + ogs_hash_destroy(h); +} + +static void hash_get_or_set_test(abts_case *tc, void *data) +{ + ogs_hash_t *h = NULL; + char *result = NULL; + + h = ogs_hash_make(); + ABTS_PTR_NOTNULL(tc, h); + + result = ogs_hash_get_or_set(h, "key", OGS_HASH_KEY_STRING, "value"); + ABTS_STR_EQUAL(tc, "value", result); + + result = ogs_hash_get_or_set(h, "key", OGS_HASH_KEY_STRING, "other"); + ABTS_STR_EQUAL(tc, "value", result); + + result = ogs_hash_get_or_set(h, "key", OGS_HASH_KEY_STRING, NULL); + ABTS_STR_EQUAL(tc, "value", result); + + ogs_hash_set(h, "key", OGS_HASH_KEY_STRING, NULL); + result = ogs_hash_get(h, "key", OGS_HASH_KEY_STRING); + ABTS_PTR_EQUAL(tc, NULL, result); + + result = ogs_hash_get_or_set(h, "key", OGS_HASH_KEY_STRING, NULL); + ABTS_PTR_EQUAL(tc, NULL, result); + + result = ogs_hash_get_or_set(h, "key", OGS_HASH_KEY_STRING, "other"); + ABTS_STR_EQUAL(tc, "other", result); + + ogs_hash_destroy(h); +} + +static void hash_reset(abts_case *tc, void *data) +{ + ogs_hash_t *h = NULL; + char *result = NULL; + + h = ogs_hash_make(); + ABTS_PTR_NOTNULL(tc, h); + + ogs_hash_set(h, "key", OGS_HASH_KEY_STRING, "value"); + result = ogs_hash_get(h, "key", OGS_HASH_KEY_STRING); + ABTS_STR_EQUAL(tc, "value", result); + + ogs_hash_set(h, "key", OGS_HASH_KEY_STRING, "new"); + result = ogs_hash_get(h, "key", OGS_HASH_KEY_STRING); + ABTS_STR_EQUAL(tc, "new", result); + + ogs_hash_destroy(h); +} + +static void same_value(abts_case *tc, void *data) +{ + ogs_hash_t *h = NULL; + char *result = NULL; + + h = ogs_hash_make(); + ABTS_PTR_NOTNULL(tc, h); + + ogs_hash_set(h, "same1", OGS_HASH_KEY_STRING, "same"); + result = ogs_hash_get(h, "same1", OGS_HASH_KEY_STRING); + ABTS_STR_EQUAL(tc, "same", result); + + ogs_hash_set(h, "same2", OGS_HASH_KEY_STRING, "same"); + result = ogs_hash_get(h, "same2", OGS_HASH_KEY_STRING); + ABTS_STR_EQUAL(tc, "same", result); + + ogs_hash_destroy(h); +} + +static unsigned int hash_custom( const char *key, int *klen) +{ + unsigned int hash = 0; + unsigned int len = *klen; + while( len ) { + (len) --; + hash = hash * 33 + key[ len ]; + } + return hash; +} + +static void same_value_custom(abts_case *tc, void *data) +{ + ogs_hash_t *h = NULL; + char *result = NULL; + + h = ogs_hash_make_custom(hash_custom); + ABTS_PTR_NOTNULL(tc, h); + + ogs_hash_set(h, "same1", 5, "same"); + result = ogs_hash_get(h, "same1", 5); + ABTS_STR_EQUAL(tc, "same", result); + + ogs_hash_set(h, "same2", 5, "same"); + result = ogs_hash_get(h, "same2", 5); + ABTS_STR_EQUAL(tc, "same", result); + + ogs_hash_destroy(h); +} + +static void key_space(abts_case *tc, void *data) +{ + ogs_hash_t *h = NULL; + char *result = NULL; + + h = ogs_hash_make(); + ABTS_PTR_NOTNULL(tc, h); + + ogs_hash_set(h, "key with space", OGS_HASH_KEY_STRING, "value"); + result = ogs_hash_get(h, "key with space", OGS_HASH_KEY_STRING); + ABTS_STR_EQUAL(tc, "value", result); + + ogs_hash_destroy(h); +} + +static void hash_clear_test(abts_case *tc, void *data) +{ + ogs_hash_t *h; + int num[10], i; + int c; + + h = ogs_hash_make(); + ABTS_PTR_NOTNULL(tc, h); + + for (i = 0; i < 10; i++) + { + num[i] = i; + ogs_hash_set(h, &num[i], sizeof(num[i]), &num[i]); + } + c = ogs_hash_count(h); + ABTS_INT_EQUAL(tc, 10, c); + + ogs_hash_clear(h); + c = ogs_hash_count(h); + ABTS_INT_EQUAL(tc, 0, c); + + ogs_hash_destroy(h); +} + +/* This is kind of a hack, but I am just keeping an existing test. This is + * really testing ogs_hash_first, ogs_hash_next, and ogs_ogs_hash_this which + * should be tested in three separate tests, but this will do for now. + */ +static void hash_traverse(abts_case *tc, void *data) +{ + ogs_hash_t *h; + char StrArray[MAX_DEPTH][MAX_LTH]; + + h = ogs_hash_make(); + ABTS_PTR_NOTNULL(tc, h); + + ogs_hash_set(h, "OVERWRITE", OGS_HASH_KEY_STRING, "should not see this"); + ogs_hash_set(h, "FOO3", OGS_HASH_KEY_STRING, "bar3"); + ogs_hash_set(h, "FOO3", OGS_HASH_KEY_STRING, "bar3"); + ogs_hash_set(h, "FOO1", OGS_HASH_KEY_STRING, "bar1"); + ogs_hash_set(h, "FOO2", OGS_HASH_KEY_STRING, "bar2"); + ogs_hash_set(h, "FOO4", OGS_HASH_KEY_STRING, "bar4"); + ogs_hash_set(h, "SAME1", OGS_HASH_KEY_STRING, "same"); + ogs_hash_set(h, "SAME2", OGS_HASH_KEY_STRING, "same"); + ogs_hash_set(h, "OVERWRITE", OGS_HASH_KEY_STRING, "Overwrite key"); + + dump_hash(h, StrArray); + + ABTS_STR_EQUAL(tc, "Key FOO1 (4) Value bar1\n", StrArray[0]); + ABTS_STR_EQUAL(tc, "Key FOO2 (4) Value bar2\n", StrArray[1]); + ABTS_STR_EQUAL(tc, "Key FOO3 (4) Value bar3\n", StrArray[2]); + ABTS_STR_EQUAL(tc, "Key FOO4 (4) Value bar4\n", StrArray[3]); + ABTS_STR_EQUAL(tc, "Key OVERWRITE (9) Value Overwrite key\n", StrArray[4]); + ABTS_STR_EQUAL(tc, "Key SAME1 (5) Value same\n", StrArray[5]); + ABTS_STR_EQUAL(tc, "Key SAME2 (5) Value same\n", StrArray[6]); + ABTS_STR_EQUAL(tc, "#entries 7\n", StrArray[7]); + + ogs_hash_destroy(h); +} + +/* This is kind of a hack, but I am just keeping an existing test. This is + * really testing ogs_hash_first, ogs_hash_next, and ogs_ogs_hash_this which + * should be tested in three separate tests, but this will do for now. + */ +static void summation_test(abts_case *tc, void *data) +{ + ogs_hash_t *h; + int sumKeys, sumVal, trySumKey, trySumVal; + int i, j, val[100], key[100]; + + h = ogs_hash_make(); + ABTS_PTR_NOTNULL(tc, h); + + sumKeys = 0; + sumVal = 0; + trySumKey = 0; + trySumVal = 0; + + for (i = 0; i < 100; i++) { + j = i * 10 + 1; + sumKeys += j; + sumVal += i; + key[i] = j; + val[i] = i; + ogs_hash_set(h, &key[i], sizeof(int), &val[i]); + } + + sum_hash(h, &i, &trySumKey, &trySumVal); + ABTS_INT_EQUAL(tc, 100, i); + ABTS_INT_EQUAL(tc, sumVal, trySumVal); + ABTS_INT_EQUAL(tc, sumKeys, trySumKey); + + ogs_hash_destroy(h); +} + +static void delete_key(abts_case *tc, void *data) +{ + ogs_hash_t *h = NULL; + char *result = NULL; + + h = ogs_hash_make(); + ABTS_PTR_NOTNULL(tc, h); + + ogs_hash_set(h, "key", OGS_HASH_KEY_STRING, "value"); + ogs_hash_set(h, "key2", OGS_HASH_KEY_STRING, "value2"); + + result = ogs_hash_get(h, "key", OGS_HASH_KEY_STRING); + ABTS_STR_EQUAL(tc, "value", result); + + result = ogs_hash_get(h, "key2", OGS_HASH_KEY_STRING); + ABTS_STR_EQUAL(tc, "value2", result); + + ogs_hash_set(h, "key", OGS_HASH_KEY_STRING, NULL); + + result = ogs_hash_get(h, "key", OGS_HASH_KEY_STRING); + ABTS_PTR_EQUAL(tc, NULL, result); + + result = ogs_hash_get(h, "key2", OGS_HASH_KEY_STRING); + ABTS_STR_EQUAL(tc, "value2", result); + + ogs_hash_destroy(h); +} + +static void hash_count_0(abts_case *tc, void *data) +{ + ogs_hash_t *h = NULL; + int count; + + h = ogs_hash_make(); + ABTS_PTR_NOTNULL(tc, h); + + count = ogs_hash_count(h); + ABTS_INT_EQUAL(tc, 0, count); + + ogs_hash_destroy(h); +} + +static void hash_count_1(abts_case *tc, void *data) +{ + ogs_hash_t *h = NULL; + int count; + + h = ogs_hash_make(); + ABTS_PTR_NOTNULL(tc, h); + + ogs_hash_set(h, "key", OGS_HASH_KEY_STRING, "value"); + + count = ogs_hash_count(h); + ABTS_INT_EQUAL(tc, 1, count); + + ogs_hash_destroy(h); +} + +static void hash_count_5(abts_case *tc, void *data) +{ + ogs_hash_t *h = NULL; + int count; + + h = ogs_hash_make(); + ABTS_PTR_NOTNULL(tc, h); + + ogs_hash_set(h, "key1", OGS_HASH_KEY_STRING, "value1"); + ogs_hash_set(h, "key2", OGS_HASH_KEY_STRING, "value2"); + ogs_hash_set(h, "key3", OGS_HASH_KEY_STRING, "value3"); + ogs_hash_set(h, "key4", OGS_HASH_KEY_STRING, "value4"); + ogs_hash_set(h, "key5", OGS_HASH_KEY_STRING, "value5"); + + count = ogs_hash_count(h); + ABTS_INT_EQUAL(tc, 5, count); + + ogs_hash_destroy(h); +} + +abts_suite *test_hash(abts_suite *suite) +{ + suite = ADD_SUITE(suite) + + abts_run_test(suite, hash_make_test, NULL); + abts_run_test(suite, hash_set_test, NULL); + abts_run_test(suite, hash_get_or_set_test, NULL); + abts_run_test(suite, hash_reset, NULL); + abts_run_test(suite, same_value, NULL); + abts_run_test(suite, same_value_custom, NULL); + abts_run_test(suite, key_space, NULL); + abts_run_test(suite, delete_key, NULL); + + abts_run_test(suite, hash_count_0, NULL); + abts_run_test(suite, hash_count_1, NULL); + abts_run_test(suite, hash_count_5, NULL); + + abts_run_test(suite, hash_clear_test, NULL); + abts_run_test(suite, hash_traverse, NULL); + abts_run_test(suite, summation_test, NULL); + + return suite; +} diff --git a/tests/core/list-test.c b/tests/core/list-test.c new file mode 100644 index 000000000..c80fb2281 --- /dev/null +++ b/tests/core/list-test.c @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "ogs-core.h" +#include "core/abts.h" + +typedef struct { + ogs_list_t list; + int m1; +} lt_type1; + +#define SIZE_OF_lt_type1 16 + +static OGS_LIST(tlist1); + +static void test_basic(abts_case *tc, void *data) +{ + int i; + lt_type1 *iter, *tmp, node[SIZE_OF_lt_type1]; + + for (i = 0; i < SIZE_OF_lt_type1; i++) + node[i].m1 = i; + + ogs_list_init(&tlist1); + ABTS_TRUE(tc, ogs_list_empty(&tlist1)); + ABTS_INT_EQUAL(tc, 0, ogs_list_count(&tlist1)); + + for (i = 0; i < 1; i++) + ogs_list_add(&tlist1, &node[i]); + ABTS_INT_EQUAL(tc, 1, ogs_list_count(&tlist1)); + + i = 0; + ogs_list_for_each(&tlist1, iter) + ABTS_PTR_EQUAL(tc, &node[i++], iter); + + for (i = 1; i < 3; i++) + ogs_list_add(&tlist1, &node[i]); + ABTS_INT_EQUAL(tc, 3, ogs_list_count(&tlist1)); + + i = 0; + ogs_list_for_each(&tlist1, iter) + ABTS_PTR_EQUAL(tc, &node[i++], iter); + + ogs_list_remove(&tlist1, &node[1]); + ABTS_INT_EQUAL(tc, 2, ogs_list_count(&tlist1)); + ABTS_TRUE(tc, !ogs_list_empty(&tlist1)); + + ogs_list_for_each_safe(&tlist1, tmp, iter) + ogs_list_remove(&tlist1, iter); + ABTS_INT_EQUAL(tc, 0, ogs_list_count(&tlist1)); + ABTS_TRUE(tc, ogs_list_empty(&tlist1)); +} + +abts_suite *test_list(abts_suite *suite) +{ + suite = ADD_SUITE(suite) + + abts_run_test(suite, test_basic, NULL); + + return suite; +} diff --git a/tests/core/log-test.c b/tests/core/log-test.c new file mode 100644 index 000000000..4e004b190 --- /dev/null +++ b/tests/core/log-test.c @@ -0,0 +1,113 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "ogs-core.h" +#include "core/abts.h" + +static void test_basic(abts_case *tc, void *data) +{ + int domain_id = -1; + int core_level = ogs_log_get_domain_level(ogs_log_get_domain_id("core")); + + ogs_log_set_domain_level(ogs_log_get_domain_id("core"), OGS_LOG_ERROR); + ogs_log_install_domain(&domain_id, "core", OGS_LOG_INFO); + ABTS_INT_EQUAL(tc, 1, domain_id); + ABTS_INT_EQUAL(tc, OGS_LOG_INFO, ogs_log_get_domain_level(domain_id)); + ogs_log_set_domain_level(domain_id, OGS_LOG_DEBUG); + ABTS_INT_EQUAL(tc, OGS_LOG_DEBUG, ogs_log_get_domain_level(domain_id)); + ogs_log_install_domain(&domain_id, "CORE1", OGS_LOG_INFO); + ABTS_INT_EQUAL(tc, OGS_LOG_INFO, ogs_log_get_domain_level(domain_id)); + ogs_log_install_domain(&domain_id, "COR2", OGS_LOG_WARN); + ogs_log_set_domain_level(domain_id, OGS_LOG_ERROR); + ABTS_INT_EQUAL(tc, OGS_LOG_ERROR, ogs_log_get_domain_level(domain_id)); + ogs_log_set_domain_level(ogs_log_get_domain_id("core"), OGS_LOG_ERROR); + ogs_log_install_domain(&domain_id, "CORE1", OGS_LOG_WARN); + ABTS_INT_EQUAL(tc, OGS_LOG_WARN, ogs_log_get_domain_level(domain_id)); + ogs_log_install_domain(&domain_id, "COR2", OGS_LOG_INFO); + ABTS_INT_EQUAL(tc, OGS_LOG_INFO, ogs_log_get_domain_level(domain_id)); + ogs_log_install_domain(&domain_id, "COR3", OGS_LOG_INFO); + ogs_log_set_domain_level(domain_id, OGS_LOG_NONE); + ABTS_INT_EQUAL(tc, OGS_LOG_NONE, ogs_log_get_domain_level(domain_id)); + ogs_log_install_domain(&domain_id, "core", OGS_LOG_FULL); + ABTS_INT_EQUAL(tc, 1, domain_id); + ABTS_INT_EQUAL(tc, OGS_LOG_FULL, ogs_log_get_domain_level(domain_id)); + domain_id = ogs_log_get_domain_id("core"); + ABTS_INT_EQUAL(tc, 1, domain_id); + ABTS_INT_EQUAL(tc, OGS_LOG_FULL, ogs_log_get_domain_level(domain_id)); + ogs_log_set_mask_level("COR2 COR3", OGS_LOG_ERROR); + + ABTS_INT_EQUAL(tc, OGS_LOG_ERROR, + ogs_log_get_domain_level(ogs_log_get_domain_id("COR2"))); + ABTS_INT_EQUAL(tc, OGS_LOG_ERROR, + ogs_log_get_domain_level(ogs_log_get_domain_id("COR3"))); + ABTS_INT_EQUAL(tc, OGS_LOG_FULL, + ogs_log_get_domain_level(ogs_log_get_domain_id("core"))); + ABTS_INT_EQUAL(tc, OGS_LOG_WARN, + ogs_log_get_domain_level(ogs_log_get_domain_id("CORE1"))); + + ogs_log_set_mask_level("COR2:COR3:COREE:core:CORE1", ogs_core()->log.level); + ABTS_INT_EQUAL(tc, ogs_core()->log.level, + ogs_log_get_domain_level(ogs_log_get_domain_id("COR2"))); + ABTS_INT_EQUAL(tc, ogs_core()->log.level, + ogs_log_get_domain_level(ogs_log_get_domain_id("COR3"))); + ABTS_INT_EQUAL(tc, ogs_core()->log.level, + ogs_log_get_domain_level(ogs_log_get_domain_id("core"))); + ABTS_INT_EQUAL(tc, ogs_core()->log.level, + ogs_log_get_domain_level(ogs_log_get_domain_id("CORE1"))); + + ogs_log_set_domain_level(ogs_log_get_domain_id("core"), core_level); + +#if 0 + ogs_error("alksdfjklsadf %d, %s", 555, "bbbbbb"); + ogs_error("sdofsadljflkasdjflksadfjlksadfjlkasdkjfasd\n"); + ogs_msleep(30); + ogs_warn("555555 %d, %s", 3333, "bbbbbb"); + ogs_fatal("ddd"); + ogs_log_print(OGS_LOG_INFO, "219380912839012830192830912380192390\n"); + ogs_usleep(3000); + ogs_info("29380912839012830192830912380192390"); + ogs_fatal("eee"); + + ogs_log_hexdump(OGS_LOG_WARN, "\x12\x34\x56\x78\x12\x34\x56" + "\x12\x34\x56\x78\x12\x34\x56" + "\x12\x34\x56\x78\x12\x34\x56" + "\x12\x34\x56\x78\x12\x34\x56" + "\x12\x34\x56\x78\x12\x34\x56" + "\x12\x34\x56\x78\x12\x34\x56" + "\x12\x34\x56\x78\x12\x34\x56", 49); + + ogs_log_hexdump(OGS_LOG_INFO, "\x12\x34\x56\x78\x12\x34\x56" + "\x12\x34\x56\x78\x12\x34\x56" + "\x12\x34\x56\x78\x12\x34\x56" + "\x12\x34\x56\x78\x12\x34\x56" + "\x12\x34\x56\x78", 32); + ogs_log_message(OGS_LOG_FATAL, OGS_ECONNREFUSED, "Error occurred"); + ogs_log_message(OGS_LOG_WARN, OGS_EAGAIN, "Error occurred"); + ogs_info("timezone : %d", (int)ogs_timezone()); +#endif +} + +abts_suite *test_log(abts_suite *suite) +{ + suite = ADD_SUITE(suite) + + abts_run_test(suite, test_basic, NULL); + + return suite; +} diff --git a/tests/core/memory-test.c b/tests/core/memory-test.c new file mode 100644 index 000000000..ec0d8a9cf --- /dev/null +++ b/tests/core/memory-test.c @@ -0,0 +1,83 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "ogs-core.h" +#include "core/abts.h" + +static void test1_func(abts_case *tc, void *data) +{ + char *ptr = ogs_malloc(256); + ABTS_PTR_NOTNULL(tc, ptr); + ogs_free(ptr); +} + +static void test2_func(abts_case *tc, void *data) +{ + char *ptr = ogs_calloc(2, 10); + int i; + for (i = 0; i < 2*10; i++) + { + ABTS_INT_EQUAL(tc, 0, ptr[i]); + } + ABTS_PTR_NOTNULL(tc, ptr); + ogs_free(ptr); +} + +static void test3_func(abts_case *tc, void *data) +{ + char *ptr = ogs_realloc(0, 10); + ABTS_PTR_NOTNULL(tc, ptr); + ogs_free(ptr); + + ptr = ogs_malloc(20); + ABTS_PTR_NOTNULL(tc, ptr); + ptr = ogs_realloc(ptr, 0); +} + +static void test4_func(abts_case *tc, void *data) +{ + char *p, *q; + + p = ogs_malloc(10); + ABTS_PTR_NOTNULL(tc, p); + memset(p, 1, 10); + + q = ogs_realloc(p, 128 - sizeof(ogs_pkbuf_t *) - 1); + ABTS_TRUE(tc, p == q); + + p = ogs_realloc(q, 128 - sizeof(ogs_pkbuf_t *)); + ABTS_TRUE(tc, p == q); + + q = ogs_realloc(p, 128 - sizeof(ogs_pkbuf_t *) + 1); + ABTS_TRUE(tc, p != q); + ABTS_TRUE(tc, memcmp(p, q, 10) == 0); + ogs_free(q); +} + +abts_suite *test_memory(abts_suite *suite) +{ + suite = ADD_SUITE(suite) + + abts_run_test(suite, test1_func, NULL); + abts_run_test(suite, test2_func, NULL); + abts_run_test(suite, test3_func, NULL); + abts_run_test(suite, test4_func, NULL); + + return suite; +} diff --git a/tests/core/meson.build b/tests/core/meson.build new file mode 100644 index 000000000..1a80fd565 --- /dev/null +++ b/tests/core/meson.build @@ -0,0 +1,55 @@ +# Copyright (C) 2019 by Sukchan Lee + +# This file is part of Open5GS. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +testcore_sources = files(''' + list-test.c + pool-test.c + strings-test.c + time-test.c + conv-test.c + log-test.c + pkbuf-test.c + memory-test.c + rbtree-test.c + timer-test.c + thread-test.c + socket-test.c + queue-test.c + poll-test.c + tlv-test.c + fsm-test.c + hash-test.c + abts-main.c +'''.split()) + +testcore_cc_flags = [] +if cc.get_id() == 'gcc' or cc.get_id() == 'clang' + testcore_cc_flags += cc.get_supported_arguments([ + '-Wno-missing-prototypes', + '-Wno-missing-declarations', + '-Wno-discarded-qualifiers', + '-Wno-incompatible-pointer-types', + '-Wno-unused-variable', + '-Wno-deprecated-declarations']) +endif + +testcore_exe = executable('core', + sources : testcore_sources, + c_args : testcore_cc_flags, + dependencies : libcore_dep) + +test('core', testcore_exe, is_parallel : false, suite: 'unit') diff --git a/tests/core/pkbuf-test.c b/tests/core/pkbuf-test.c new file mode 100644 index 000000000..797a71faa --- /dev/null +++ b/tests/core/pkbuf-test.c @@ -0,0 +1,81 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "ogs-core.h" +#include "core/abts.h" + +static void test1_func(abts_case *tc, void *data) +{ + ogs_pkbuf_t *pkbuf = NULL; + unsigned char *tmp = NULL; + + pkbuf = ogs_pkbuf_alloc(NULL, 100); + ABTS_PTR_NOTNULL(tc, pkbuf); + ogs_pkbuf_reserve(pkbuf, 50); + tmp = ogs_pkbuf_push(pkbuf, 50); + ABTS_PTR_NOTNULL(tc, tmp); + tmp = ogs_pkbuf_pull(pkbuf, 50); + ABTS_PTR_NOTNULL(tc, tmp); + tmp = ogs_pkbuf_put(pkbuf, 50); + ABTS_PTR_NOTNULL(tc, tmp); + + ogs_pkbuf_free(pkbuf); +} + +static void test2_func(abts_case *tc, void *data) +{ + ogs_pkbuf_t *pkbuf = NULL, *p2 = NULL, *p3 = NULL; + unsigned char *tmp = NULL; + + pkbuf = ogs_pkbuf_alloc(NULL, 100); + ABTS_PTR_NOTNULL(tc, pkbuf); + ogs_pkbuf_reserve(pkbuf, 50); + tmp = ogs_pkbuf_push(pkbuf, 50); + ABTS_PTR_NOTNULL(tc, tmp); + p2 = ogs_pkbuf_copy(pkbuf); + ABTS_PTR_NOTNULL(tc, p2); + ABTS_INT_EQUAL(tc, 50, p2->len); + ABTS_TRUE(tc, p2->head == p2->data); + ABTS_INT_EQUAL(tc, 50, (p2->tail-p2->data)); + ABTS_INT_EQUAL(tc, 50, (p2->end-p2->tail)); + tmp = ogs_pkbuf_pull(pkbuf, 50); + ABTS_PTR_NOTNULL(tc, tmp); + p3 = ogs_pkbuf_copy(pkbuf); + ABTS_PTR_NOTNULL(tc, p3); + ABTS_INT_EQUAL(tc, 0, p3->len); + ABTS_TRUE(tc, p3->tail == p3->data); + ABTS_INT_EQUAL(tc, 50, (p3->tail-p3->head)); + ABTS_INT_EQUAL(tc, 50, (p3->end-p3->tail)); + tmp = ogs_pkbuf_put(pkbuf, 50); + ABTS_PTR_NOTNULL(tc, tmp); + + ogs_pkbuf_free(pkbuf); + ogs_pkbuf_free(p2); + ogs_pkbuf_free(p3); +} + +abts_suite *test_pkbuf(abts_suite *suite) +{ + suite = ADD_SUITE(suite) + + abts_run_test(suite, test1_func, NULL); + abts_run_test(suite, test2_func, NULL); + + return suite; +} diff --git a/tests/core/poll-test.c b/tests/core/poll-test.c new file mode 100644 index 000000000..8fc1c671d --- /dev/null +++ b/tests/core/poll-test.c @@ -0,0 +1,452 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "ogs-core.h" +#include "core/abts.h" + +#define DATASTR "This is a test" +#define STRLEN 8092 +#define PORT 7777 +#define NUM 100 + +#ifndef AI_PASSIVE +#define AI_PASSIVE 1 +#endif + +#if 0 /* FIXME : Not working in WIN32, i585 */ +static int test1_called = 0; + +static void test1_handler(short when, ogs_socket_t fd, void *data) +{ + abts_case *tc = data; + char str[STRLEN]; + ssize_t size; + + ABTS_INT_EQUAL(tc, OGS_POLLIN, when); + + size = ogs_recv(fd, str, STRLEN, 0); + ABTS_INT_EQUAL(tc, strlen(DATASTR), size); + + test1_called++; +} + +static void test1_func(abts_case *tc, void *data) +{ + int rv; + int i; + ssize_t size; + ogs_poll_t *poll[NUM]; + ogs_sockaddr_t *addr; + ogs_socknode_t *server[NUM], *client[NUM]; + ogs_pollset_t *pollset = ogs_pollset_create(); + ABTS_PTR_NOTNULL(tc, pollset); + + for (i = 0; i < NUM; i++) { + rv = ogs_getaddrinfo(&addr, AF_INET, "127.0.0.1", PORT+i, AI_PASSIVE); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + server[i] = ogs_socknode_new(addr); + ABTS_PTR_NOTNULL(tc, server[i]); + ogs_udp_server(server[i]); + ABTS_PTR_NOTNULL(tc, server[i]->sock); + rv = ogs_getaddrinfo(&addr, AF_INET, "127.0.0.1", PORT+i, AI_PASSIVE); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + client[i] = ogs_socknode_new(addr); + ABTS_PTR_NOTNULL(tc, client[i]); + ogs_udp_client(client[i]); + ABTS_PTR_NOTNULL(tc, client[i]->sock); + } + + for (i = 0; i < NUM; i+=2) { + poll[i] = ogs_pollset_add(pollset, OGS_POLLIN, + server[i]->sock->fd, test1_handler, tc); + ABTS_PTR_NOTNULL(tc, poll); + + size = ogs_send(client[i]->sock->fd, DATASTR, strlen(DATASTR), 0); + ABTS_INT_EQUAL(tc, strlen(DATASTR), size); + } + + test1_called = 0; + rv = ogs_pollset_poll(pollset, OGS_INFINITE_TIME); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + ABTS_INT_EQUAL(tc, NUM/2, test1_called); + + for (i = 1; i < NUM; i+=2) { + poll[i] = ogs_pollset_add(pollset, OGS_POLLIN, + server[i]->sock->fd, test1_handler, tc); + ABTS_PTR_NOTNULL(tc, poll); + } + + for (i = 0; i < NUM; i++) { + size = ogs_send(client[i]->sock->fd, DATASTR, strlen(DATASTR), 0); + ABTS_INT_EQUAL(tc, strlen(DATASTR), size); + } + + test1_called = 0; + rv = ogs_pollset_poll(pollset, OGS_INFINITE_TIME); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + ABTS_INT_EQUAL(tc, NUM, test1_called); + + for (i = 0; i < NUM; i+=2) { + ogs_pollset_remove(poll[i]); + } + + for (i = 1; i < NUM; i+=2) { + size = ogs_send(client[i]->sock->fd, DATASTR, strlen(DATASTR), 0); + ABTS_INT_EQUAL(tc, strlen(DATASTR), size); + } + + test1_called = 0; + rv = ogs_pollset_poll(pollset, OGS_INFINITE_TIME); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + ABTS_INT_EQUAL(tc, NUM/2, test1_called); + + for (i = 1; i < NUM; i+=2) { + ogs_pollset_remove(poll[i]); + } + + rv = ogs_pollset_poll(pollset, ogs_time_from_msec(100)); + ABTS_INT_EQUAL(tc, OGS_TIMEUP, rv); + + for (i = 0; i < NUM; i++) { + ogs_socknode_free(client[i]); + ogs_socknode_free(server[i]); + } + + ogs_pollset_destroy(pollset); +} +#endif + +static ogs_socknode_t *test2_server, *test2_client; +static ogs_sock_t *test2_accept; +static int test2_okay = 1; + +static void test2_handler(short when, ogs_socket_t fd, void *data) +{ + abts_case *tc = data; + const char *test = "test string"; + int len; + + ABTS_INT_EQUAL(tc, OGS_POLLOUT, when); + + len = ogs_send(fd, test, (int)strlen(test) + 1, 0); + + if (len > 0) { + ogs_socknode_free(test2_client); + } + + test2_okay = 0; +} + +static void test2_func(abts_case *tc, void *data) +{ + int rv; + ogs_poll_t *poll; + ogs_sockaddr_t *addr; + ogs_pollset_t *pollset = ogs_pollset_create(); + ABTS_PTR_NOTNULL(tc, pollset); + + rv = ogs_getaddrinfo(&addr, AF_INET, "127.0.0.1", PORT, AI_PASSIVE); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + test2_server = ogs_socknode_new(addr); + ABTS_PTR_NOTNULL(tc, test2_server); + ogs_tcp_server(test2_server); + ABTS_PTR_NOTNULL(tc, test2_server->sock); + + rv = ogs_getaddrinfo(&addr, AF_INET, "127.0.0.1", PORT, AI_PASSIVE); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + test2_client = ogs_socknode_new(addr); + ABTS_PTR_NOTNULL(tc, test2_client); + ogs_tcp_client(test2_client); + ABTS_PTR_NOTNULL(tc, test2_client->sock); + + test2_accept = ogs_sock_accept(test2_server->sock); + ABTS_PTR_NOTNULL(tc, test2_accept); + + poll = ogs_pollset_add(pollset, OGS_POLLOUT, + test2_accept->fd, test2_handler, tc); + ABTS_PTR_NOTNULL(tc, poll); + + rv = ogs_pollset_poll(pollset, OGS_INFINITE_TIME); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + ABTS_INT_EQUAL(tc, 0, test2_okay); + + ogs_pollset_remove(poll); + + ogs_sock_destroy(test2_accept); + ogs_socknode_free(test2_server); + + ogs_pollset_destroy(pollset); +} + +static ogs_socket_t test3_fd[2]; +static int test3_okay = 1; + +static void test3_handler(short when, ogs_socket_t fd, void *data) +{ + abts_case *tc = data; + const char *test = "test string"; + int len; + + ABTS_INT_EQUAL(tc, OGS_POLLOUT, when); + + len = ogs_send(fd, test, (int)strlen(test) + 1, 0); + + if (len > 0) { + ogs_closesocket(test3_fd[0]); + } + test3_okay = 0; +} + +static void test3_func(abts_case *tc, void *data) +{ + int rv; + ogs_poll_t *poll = NULL; + ogs_pollset_t *pollset = ogs_pollset_create(); + ABTS_PTR_NOTNULL(tc, pollset); + + rv = ogs_socketpair(AF_SOCKPAIR, SOCK_STREAM, 0, test3_fd); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + poll = ogs_pollset_add(pollset, OGS_POLLOUT, + test3_fd[1], test3_handler, tc); + ABTS_PTR_NOTNULL(tc, poll); + + rv = ogs_pollset_poll(pollset, OGS_INFINITE_TIME); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + ogs_pollset_remove(poll); + + ABTS_INT_EQUAL(tc, 0, test3_okay); + + ogs_closesocket(test3_fd[1]); + + ogs_pollset_destroy(pollset); +} + +static ogs_thread_t *test4_thread; +static void test4_main(void *data) +{ + abts_case *tc = data; + int rv; + ogs_sock_t *udp; + ogs_sockaddr_t *sa; + ssize_t size; + + udp = ogs_udp_socket(AF_INET, NULL); + ABTS_PTR_NOTNULL(tc, udp); + + rv = ogs_getaddrinfo(&sa, AF_INET, NULL, PORT, 0); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + size = ogs_sendto(udp->fd, DATASTR, strlen(DATASTR), 0, sa); + ABTS_INT_EQUAL(tc, strlen(DATASTR), size); + + rv = ogs_freeaddrinfo(sa); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + ogs_sock_destroy(udp); +} + +static void test4_handler(short when, ogs_socket_t fd, void *data) +{ + abts_case *tc = data; + ssize_t size; + char str[STRLEN]; + ogs_sockaddr_t sa; + char buf[OGS_ADDRSTRLEN]; + + ABTS_INT_EQUAL(tc, OGS_POLLIN, when); + + size = ogs_recvfrom(fd, str, STRLEN, 0, &sa); + ABTS_INT_EQUAL(tc, strlen(DATASTR), size); + ABTS_STR_EQUAL(tc, "127.0.0.1", OGS_ADDR(&sa, buf)); +} + +static void test4_func(abts_case *tc, void *data) +{ + int rv; + ogs_sock_t *udp; + ogs_sockaddr_t *addr; + ogs_socknode_t *node; + ogs_pollset_t *pollset = ogs_pollset_create(); + ABTS_PTR_NOTNULL(tc, pollset); + + rv = ogs_getaddrinfo(&addr, AF_INET, NULL, PORT, AI_PASSIVE); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + node = ogs_socknode_new(addr); + ABTS_PTR_NOTNULL(tc, node); + ogs_socknode_set_poll(node, pollset, OGS_POLLIN, test4_handler, tc); + udp = ogs_udp_server(node); + ABTS_PTR_NOTNULL(tc, udp); + + test4_thread = ogs_thread_create(test4_main, tc); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + rv = ogs_pollset_poll(pollset, OGS_INFINITE_TIME); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + ogs_thread_destroy(test4_thread); + + ogs_socknode_free(node); + + ogs_pollset_destroy(pollset); +} + +static void test5_func(abts_case *tc, void *data) +{ + int rv; + ogs_pollset_t *pollset = ogs_pollset_create(); + ABTS_PTR_NOTNULL(tc, pollset); + + rv = ogs_pollset_poll(pollset, ogs_time_from_msec(100)); + ABTS_INT_EQUAL(tc, OGS_TIMEUP, rv); + rv = ogs_pollset_notify(pollset); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + rv = ogs_pollset_poll(pollset, ogs_time_from_msec(100)); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + rv = ogs_pollset_poll(pollset, ogs_time_from_msec(100)); + ABTS_INT_EQUAL(tc, OGS_TIMEUP, rv); + rv = ogs_pollset_notify(pollset); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + rv = ogs_pollset_notify(pollset); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + rv = ogs_pollset_notify(pollset); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + rv = ogs_pollset_poll(pollset, ogs_time_from_msec(100)); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + rv = ogs_pollset_poll(pollset, ogs_time_from_msec(100)); + ABTS_INT_EQUAL(tc, OGS_TIMEUP, rv); + + ogs_pollset_destroy(pollset); +} + +static int test6_okay = 1; +static void test6_handler(short when, ogs_socket_t fd, void *data) +{ + abts_case *tc = data; + + ABTS_TRUE(tc, (when & OGS_POLLIN)); + test6_okay = 0; +} + +static void test6_func(abts_case *tc, void *data) +{ + int rv; + ogs_socket_t fd[2]; + ogs_poll_t *poll = NULL; + ogs_pollset_t *pollset = ogs_pollset_create(); + ABTS_PTR_NOTNULL(tc, pollset); + + rv = ogs_socketpair(AF_SOCKPAIR, SOCK_STREAM, 0, fd); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + poll = ogs_pollset_add(pollset, OGS_POLLIN, fd[1], test6_handler, tc); + ABTS_PTR_NOTNULL(tc, poll); + + ogs_closesocket(fd[0]); + + rv = ogs_pollset_poll(pollset, OGS_INFINITE_TIME); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + ABTS_INT_EQUAL(tc, 0, test6_okay); + + ogs_pollset_remove(poll); + + ogs_closesocket(fd[1]); + + ogs_pollset_destroy(pollset); +} + +/* +static void test7_io_handler(ogs_poll_t *poll) +{ + ogs_poll_t *poll = NULL; + + poll = mme_poll_new(pollset, addr, ipv6); + ogs_assert(poll); + + ogs_poll_queue_push(poll); +} + +static void test7_queue_handler(ogs_poll_t *poll) +{ +} + +static void test7_queue_handler(ogs_poll_t *poll) +{ + mme_poll_data_t *data = _data; + ogs_assert(data); + + mme_poll_free(poll); +} +*/ + +static void test7_func(abts_case *tc, void *data) +{ + /* + int rv; + ogs_pollset_t *pollset = ogs_pollset_create(); + + ogs_poll_t *poll = NULL; + poll = ogs_poll_new(pollset, test7_handler, tc); + + rv = ogs_socketpair(AF_SOCKPAIR, SOCK_STREAM, 0, fd); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + ogs_poll_io_register(poll, OGS_POLLIN, fd[0]); + ogs_poll_io_unregister(poll); + + ogs_closesocket(fd[0]); + ogs_closesocket(fd[1]); + + ogs_poll_free(poll); + + ogs_poll_t *poll = NULL; + + poll = mme_poll_new(pollset, test7_queue_handler, addr, ipv6); + ogs_assert(poll); + + ogs_poll_queue_push(poll); + + ogs_poll_t *poll = NULL; + + poll = ogs_poll_timer_create(pollset, test7_handler, TIMER_ID); + ogs_poll_timer_start(poll); + + ogs_pollset_destroy(pollset); + */ +} + +abts_suite *test_poll(abts_suite *suite) +{ + suite = ADD_SUITE(suite) + +#if 0 /* FIXME : Not working in WIN32, i585 */ + abts_run_test(suite, test1_func, NULL); +#endif + + abts_run_test(suite, test2_func, NULL); + abts_run_test(suite, test3_func, NULL); + abts_run_test(suite, test4_func, NULL); + abts_run_test(suite, test5_func, NULL); + abts_run_test(suite, test6_func, NULL); + abts_run_test(suite, test7_func, NULL); + + return suite; +} diff --git a/tests/core/pool-test.c b/tests/core/pool-test.c new file mode 100644 index 000000000..89abcfefa --- /dev/null +++ b/tests/core/pool-test.c @@ -0,0 +1,240 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "ogs-core.h" +#include "core/abts.h" + +typedef struct { + char m1; + int m2; +} pt_type1; + +#define SIZE_OF_TPOOL1 5 +#define SIZE_OF_TPOOL2 5 + +typedef char type_of_tpool1; +typedef pt_type1 type_of_tpool2; + +static OGS_POOL(tpool1, type_of_tpool1); +static OGS_POOL(tpool2, type_of_tpool2); + +static void test_sub_func1(abts_case *tc, void *data, int start) +{ + int i, j, n; + + type_of_tpool1 *org[SIZE_OF_TPOOL1+1]; + type_of_tpool1 *node[SIZE_OF_TPOOL1+1]; + + ogs_pool_init(&tpool1, SIZE_OF_TPOOL1); + + n = ogs_pool_size(&tpool1); + ABTS_INT_EQUAL(tc, SIZE_OF_TPOOL1, n); + n = ogs_pool_avail(&tpool1); + ABTS_INT_EQUAL(tc, SIZE_OF_TPOOL1, n); + n = ogs_pool_size(&tpool1) - ogs_pool_avail(&tpool1); + ABTS_INT_EQUAL(tc, 0, n); + + for (i = 0; i < start; i++) { + ogs_pool_alloc(&tpool1, &node[i]); + ABTS_PTR_NOTNULL(tc, node[i]); + n = ogs_pool_avail(&tpool1); + ABTS_INT_EQUAL(tc, SIZE_OF_TPOOL1 - (i + 1), n); + } + + for (i = 0; i < start; i++) { + ogs_pool_free(&tpool1, node[i]); + n = ogs_pool_avail(&tpool1); + ABTS_INT_EQUAL(tc, SIZE_OF_TPOOL1 - start + (i + 1), n); + } + + for (i = 0; i < SIZE_OF_TPOOL1; i++) { + ogs_pool_alloc(&tpool1, &node[i]); + org[i] = node[i]; + ABTS_PTR_NOTNULL(tc, node[i]); + n = ogs_pool_avail(&tpool1); + ABTS_INT_EQUAL(tc, SIZE_OF_TPOOL1 - (i + 1), n); + } + + for (i = 0; i < SIZE_OF_TPOOL1; i++) { + ogs_pool_free(&tpool1, node[i]); + n = ogs_pool_avail(&tpool1); + ABTS_INT_EQUAL(tc, i + 1, n); + } + + n = 0; + for (i = 0; i < SIZE_OF_TPOOL1; i++) { + ogs_pool_alloc(&tpool1, &node[i]); + for (j = 0; j < SIZE_OF_TPOOL1; j++) { + if (node[i] == org[j]) + n++; + } + } + + for (i = 0; i < SIZE_OF_TPOOL1; i++) { + ogs_pool_free(&tpool1, node[i]); + n = ogs_pool_avail(&tpool1); + ABTS_INT_EQUAL(tc, i + 1, n); + } + + ogs_pool_final(&tpool1); +} + +static void test_sub_func2(abts_case *tc, void *data, int start) +{ + int i, j, n; + + type_of_tpool2 *org[SIZE_OF_TPOOL2+1]; + type_of_tpool2 *node[SIZE_OF_TPOOL2+1]; + + ogs_pool_init(&tpool2, SIZE_OF_TPOOL2); + + n = ogs_pool_size(&tpool2); + ABTS_INT_EQUAL(tc, SIZE_OF_TPOOL2, n); + n = ogs_pool_avail(&tpool2); + ABTS_INT_EQUAL(tc, SIZE_OF_TPOOL2, n); + n = ogs_pool_size(&tpool2) - ogs_pool_avail(&tpool2); + ABTS_INT_EQUAL(tc, 0, n); + + for (i = 0; i < start; i++) { + ogs_pool_alloc(&tpool2, &node[i]); + ABTS_PTR_NOTNULL(tc, node[i]); + n = ogs_pool_avail(&tpool2); + ABTS_INT_EQUAL(tc, SIZE_OF_TPOOL2 - (i + 1), n); + } + + for (i = 0; i < start; i++) { + ogs_pool_free(&tpool2, node[i]); + n = ogs_pool_avail(&tpool2); + ABTS_INT_EQUAL(tc, SIZE_OF_TPOOL2 - start + (i + 1), n); + } + + for (i = 0; i < SIZE_OF_TPOOL2; i++) { + ogs_pool_alloc(&tpool2, &node[i]); + org[i] = node[i]; + ABTS_PTR_NOTNULL(tc, node[i]); + n = ogs_pool_avail(&tpool2); + ABTS_INT_EQUAL(tc, SIZE_OF_TPOOL2 - (i + 1), n); + } + + for (i = 0; i < SIZE_OF_TPOOL2; i++) { + ogs_pool_free(&tpool2, node[i]); + n = ogs_pool_avail(&tpool2); + ABTS_INT_EQUAL(tc, i + 1, n); + } + + n = 0; + for (i = 0; i < SIZE_OF_TPOOL2; i++) { + ogs_pool_alloc(&tpool2, &node[i]); + for (j = 0; j < SIZE_OF_TPOOL2; j++) { + if (node[i] == org[j]) + n++; + } + } + + for (i = 0; i < SIZE_OF_TPOOL2; i++) { + ogs_pool_free(&tpool2, node[i]); + n = ogs_pool_avail(&tpool2); + ABTS_INT_EQUAL(tc, i + 1, n); + } + + ogs_pool_final(&tpool2); +} + +static void test1_func(abts_case *tc, void *data) +{ + int i; + + for (i = 0; i < SIZE_OF_TPOOL1; i++) + test_sub_func1(tc, data, i); +} + +static void test2_func(abts_case *tc, void *data) +{ + int i; + + for (i = 0; i < SIZE_OF_TPOOL2; i++) + test_sub_func2(tc, data, i); +} + +typedef char testnode_t; + +static OGS_POOL(testpool, testnode_t); + +static void test3_func(abts_case *tc, void *data) +{ + ogs_pool_init(&testpool, 5); + testnode_t *node[7] = {NULL, }; + int index; + + ogs_pool_alloc(&testpool, &node[0]); + ABTS_PTR_NOTNULL(tc, &node[0]); + ogs_pool_alloc(&testpool, &node[1]); + ABTS_PTR_NOTNULL(tc, &node[1]); + ogs_pool_alloc(&testpool, &node[2]); + ABTS_PTR_NOTNULL(tc, &node[2]); + ogs_pool_alloc(&testpool, &node[3]); + ABTS_PTR_NOTNULL(tc, &node[3]); + ogs_pool_alloc(&testpool, &node[4]); + ABTS_PTR_NOTNULL(tc, &node[4]); + + index = ogs_pool_index(&testpool, node[3]); + ABTS_PTR_NOTNULL(tc, ogs_pool_find(&testpool, index)); + ogs_pool_free(&testpool, node[3]); + ABTS_PTR_EQUAL(tc, 0, ogs_pool_find(&testpool, index)); + index = ogs_pool_index(&testpool, node[2]); + ABTS_PTR_NOTNULL(tc, ogs_pool_find(&testpool, index)); + ogs_pool_free(&testpool, node[2]); + ABTS_PTR_EQUAL(tc, 0, ogs_pool_find(&testpool, index)); + + ogs_pool_alloc(&testpool, &node[5]); + ABTS_PTR_NOTNULL(tc, &node[5]); + index = ogs_pool_index(&testpool, node[5]); + ABTS_PTR_NOTNULL(tc, ogs_pool_find(&testpool, index)); + ogs_pool_alloc(&testpool, &node[6]); + ABTS_PTR_NOTNULL(tc, &node[6]); + index = ogs_pool_index(&testpool, node[6]); + ABTS_PTR_NOTNULL(tc, ogs_pool_find(&testpool, index)); + + ABTS_INT_EQUAL(tc, 1, ogs_pool_index(&testpool, node[0])); + ABTS_INT_EQUAL(tc, 2, ogs_pool_index(&testpool, node[1])); + ABTS_INT_EQUAL(tc, 3, ogs_pool_index(&testpool, node[2])); + ABTS_INT_EQUAL(tc, 4, ogs_pool_index(&testpool, node[3])); + ABTS_INT_EQUAL(tc, 5, ogs_pool_index(&testpool, node[4])); + ABTS_INT_EQUAL(tc, 4, ogs_pool_index(&testpool, node[5])); + ABTS_INT_EQUAL(tc, 3, ogs_pool_index(&testpool, node[6])); + + ogs_pool_free(&testpool, node[0]); + ogs_pool_free(&testpool, node[1]); + ogs_pool_free(&testpool, node[2]); + ogs_pool_free(&testpool, node[3]); + ogs_pool_free(&testpool, node[4]); + + ogs_pool_final(&testpool); +} + +abts_suite *test_pool(abts_suite *suite) +{ + suite = ADD_SUITE(suite) + + abts_run_test(suite, test1_func, NULL); + abts_run_test(suite, test2_func, NULL); + abts_run_test(suite, test3_func, NULL); + + return suite; +} diff --git a/tests/core/queue-test.c b/tests/core/queue-test.c new file mode 100644 index 000000000..4dc1eba8b --- /dev/null +++ b/tests/core/queue-test.c @@ -0,0 +1,177 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "ogs-core.h" +#include "core/abts.h" + +#define NUMBER_CONSUMERS 3 +#define CONSUMER_ACTIVITY 4 +#define NUMBER_PRODUCERS 4 +#define PRODUCER_ACTIVITY 5 +#define QUEUE_SIZE 100 + +static ogs_queue_t *queue; + +static void consumer(void *data) +{ + long sleeprate; + abts_case *tc = data; + int rv; + void *v; + + sleeprate = 1000000/CONSUMER_ACTIVITY; + ogs_usleep((ogs_random32() % 4) * 1000000); /* sleep random seconds */ + + while (1) { + rv = ogs_queue_pop(queue, &v); + + if (rv == OGS_ERROR) + continue; + + if (rv == OGS_DONE) + break; + + ABTS_TRUE(tc, v == NULL); + ABTS_TRUE(tc, rv == OGS_OK); + + ogs_usleep(sleeprate); /* sleep this long to acheive our rate */ + } +} + +static void producer(void *data) +{ + long sleeprate; + abts_case *tc = data; + int rv; + + sleeprate = 1000000/PRODUCER_ACTIVITY; + ogs_usleep((ogs_random32() % 4) * 1000000); /* sleep random seconds */ + + while (1) + { + rv = ogs_queue_push(queue, NULL); + + if (rv == OGS_ERROR) + continue; + + if (rv == OGS_DONE) + break; + + ABTS_TRUE(tc, rv == OGS_OK); + + ogs_usleep(sleeprate); /* sleep this long to acheive our rate */ + } +} + +static void test_queue_producer_consumer(abts_case *tc, void *data) +{ + unsigned int i; + int rv; + ogs_thread_t *consumer_thread[NUMBER_CONSUMERS]; + ogs_thread_t *producer_thread[NUMBER_PRODUCERS]; + + queue = ogs_queue_create(QUEUE_SIZE); + ABTS_PTR_NOTNULL(tc, queue); + + for (i = 0; i < NUMBER_CONSUMERS; i++) { + consumer_thread[i] = ogs_thread_create(consumer, tc); + ABTS_PTR_NOTNULL(tc, consumer_thread[i]); + } + + for (i = 0; i < NUMBER_PRODUCERS; i++) { + producer_thread[i] = ogs_thread_create(producer, tc); + ABTS_PTR_NOTNULL(tc, producer_thread[i]); + } + + ogs_msleep(3000); /* sleep 3 seconds */ + + rv = ogs_queue_term(queue); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + for (i = 0; i < NUMBER_CONSUMERS; i++) { + ogs_thread_destroy(consumer_thread[i]); + } + + for (i = 0; i < NUMBER_PRODUCERS; i++) { + ogs_thread_destroy(producer_thread[i]); + } + + ogs_queue_destroy(queue); +} + +static void test_queue_timeout(abts_case *tc, void *data) +{ + ogs_queue_t *q; + int rv; + ogs_time_t start; + unsigned int i; + void *value; + + q = ogs_queue_create(5); + ABTS_PTR_NOTNULL(tc, q); + + for (i = 0; i < 2; ++i) { + rv = ogs_queue_timedpush(q, NULL, ogs_time_from_msec(1)); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + } + for (i = 0; i < 3; ++i) { + rv = ogs_queue_trypush(q, NULL); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + } + + start = ogs_get_monotonic_time(); + rv = ogs_queue_timedpush(q, NULL, ogs_time_from_msec(1)); + ABTS_INT_EQUAL(tc, OGS_TIMEUP, rv); + ABTS_TRUE(tc, ogs_get_monotonic_time() - start >= ogs_time_from_msec(1)); + + rv = ogs_queue_trypush(q, NULL); + ABTS_INT_EQUAL(tc, OGS_RETRY, rv); + + for (i = 0; i < 2; ++i) { + rv = ogs_queue_timedpop(q, &value, ogs_time_from_msec(1)); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + } + for (i = 0; i < 3; ++i) { + rv = ogs_queue_trypop(q, &value); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + } + + start = ogs_get_monotonic_time(); + rv = ogs_queue_timedpop(q, &value, ogs_time_from_sec(1)); + ABTS_INT_EQUAL(tc, OGS_TIMEUP, rv); + ABTS_TRUE(tc, ogs_get_monotonic_time() - start >= ogs_time_from_msec(1)); + + rv = ogs_queue_trypop(q, &value); + ABTS_INT_EQUAL(tc, OGS_RETRY, rv); + + rv = ogs_queue_term(q); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + ogs_queue_destroy(q); +} + +abts_suite *test_queue(abts_suite *suite) +{ + suite = ADD_SUITE(suite) + + abts_run_test(suite, test_queue_producer_consumer, NULL); + abts_run_test(suite, test_queue_timeout, NULL); + + return suite; +} diff --git a/tests/core/rbtree-test.c b/tests/core/rbtree-test.c new file mode 100644 index 000000000..e1abb6fc2 --- /dev/null +++ b/tests/core/rbtree-test.c @@ -0,0 +1,253 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "ogs-core.h" +#include "core/abts.h" + +#define TEST_RB_NUM 3000 +static void verify_properties(ogs_rbtree_t *tree); + +typedef struct t1_node_s { + ogs_rbnode_t node; + int key; +} t1_node_t; + +static void add_t1_node(ogs_rbtree_t *tree, t1_node_t *node) +{ + ogs_rbnode_t **new = NULL; + ogs_rbnode_t *parent = NULL; + ogs_assert(tree); + ogs_assert(node); + + new = &tree->root; + while (*new) { + t1_node_t *this = ogs_rb_entry(*new, t1_node_t, node); + + parent = *new; + if (node->key < this->key) + new = &(*new)->left; + else + new = &(*new)->right; + } + + ogs_rbtree_link_node(node, parent, new); + ogs_rbtree_insert_color(tree, node); +} + +static void test1_func(abts_case *tc, void *data) +{ + OGS_RBTREE(tree); + t1_node_t test_node[TEST_RB_NUM]; + t1_node_t *node, *next_node; + int i; + + ABTS_INT_EQUAL(tc, 0, ogs_rbtree_count(&tree)); + ABTS_TRUE(tc, ogs_rbtree_empty(&tree) == true); + + for (i = 0; i < TEST_RB_NUM; i++) { + test_node[i].key = ogs_random32() % TEST_RB_NUM; + add_t1_node(&tree, &test_node[i]); + verify_properties(&tree); + } + + ABTS_INT_EQUAL(tc, TEST_RB_NUM, ogs_rbtree_count(&tree)); + ABTS_TRUE(tc, ogs_rbtree_empty(&tree) == false); + + for (node = ogs_rbtree_first(&tree); + (node) && (next_node = ogs_rbtree_next(node), 1); node = next_node) { + if (next_node) + ogs_assert(node->key <= next_node->key); + } + + for (i = 0; i < TEST_RB_NUM; i++) { + ogs_rbtree_delete(&tree, &test_node[i]); + verify_properties(&tree); + } + + ABTS_INT_EQUAL(tc, 0, ogs_rbtree_count(&tree)); + ABTS_TRUE(tc, ogs_rbtree_empty(&tree) == true); +} + +typedef struct t2_node_s { + int key; + ogs_rbnode_t node; +} t2_node_t; + +static void add_t2_node(ogs_rbtree_t *tree, t2_node_t *node) +{ + ogs_rbnode_t **new = NULL; + ogs_rbnode_t *parent = NULL; + ogs_assert(tree); + ogs_assert(node); + + new = &tree->root; + while (*new) { + t2_node_t *this = ogs_rb_entry(*new, t2_node_t, node); + + parent = *new; + if (node->key < this->key) + new = &(*new)->left; + else + new = &(*new)->right; + } + + ogs_rbtree_link_node(&node->node, parent, new); + ogs_rbtree_insert_color(tree, &node->node); +} + +static void test2_func(abts_case *tc, void *data) +{ + OGS_RBTREE(tree); + t2_node_t test_node[TEST_RB_NUM]; + ogs_rbnode_t *node, *prev_node; + int i; + + ABTS_INT_EQUAL(tc, 0, ogs_rbtree_count(&tree)); + ABTS_TRUE(tc, ogs_rbtree_empty(&tree) == true); + + for (i = 0; i < TEST_RB_NUM; i++) { + test_node[i].key = ogs_random32() % TEST_RB_NUM; + add_t2_node(&tree, &test_node[i]); + verify_properties(&tree); + } + + ABTS_INT_EQUAL(tc, TEST_RB_NUM, ogs_rbtree_count(&tree)); + ABTS_TRUE(tc, ogs_rbtree_empty(&tree) == false); + + for (node = ogs_rbtree_last(&tree); + node && (prev_node = ogs_rbtree_prev(node), 1); node = prev_node) { + t2_node_t *this = ogs_rb_entry(node, t2_node_t, node); + if (prev_node) { + t2_node_t *prev = ogs_rb_entry(prev_node, t2_node_t, node); + ogs_assert(this->key >= prev->key); + } + } + + for (i = 0; i < TEST_RB_NUM; i++) { + ogs_rbtree_delete(&tree, &test_node[i].node); + verify_properties(&tree); + } + + ABTS_INT_EQUAL(tc, 0, ogs_rbtree_count(&tree)); + ABTS_TRUE(tc, ogs_rbtree_empty(&tree) == true); +} + +#define TEST_TIMER_NUM 5 + +static void test3_func(abts_case *tc, void *data) +{ + OGS_RBTREE(tree); + t1_node_t test_node[TEST_TIMER_NUM]; + int key[5] = { 500, 50, 200, 90, 800 }; + int i; + + ABTS_INT_EQUAL(tc, 0, ogs_rbtree_count(&tree)); + ABTS_TRUE(tc, ogs_rbtree_empty(&tree) == true); + + for (i = 0; i < TEST_TIMER_NUM; i++) { + test_node[i].key = key[i]; + add_t1_node(&tree, &test_node[i]); + verify_properties(&tree); + } + + ABTS_INT_EQUAL(tc, TEST_TIMER_NUM, ogs_rbtree_count(&tree)); + ABTS_TRUE(tc, ogs_rbtree_empty(&tree) == false); + + for (i = 0; i < TEST_TIMER_NUM; i++) { + ogs_rbtree_delete(&tree, &test_node[i]); + verify_properties(&tree); + } + + ABTS_INT_EQUAL(tc, 0, ogs_rbtree_count(&tree)); + ABTS_TRUE(tc, ogs_rbtree_empty(&tree) == true); +} + +abts_suite *test_rbtree(abts_suite *suite) +{ + suite = ADD_SUITE(suite) + + abts_run_test(suite, test1_func, NULL); + abts_run_test(suite, test2_func, NULL); + abts_run_test(suite, test3_func, NULL); + + return suite; +} + +static void verify_property_1(ogs_rbnode_t *node); +static void verify_property_2(ogs_rbnode_t *root); +static void verify_property_4(ogs_rbnode_t *node); +static void verify_property_5(ogs_rbnode_t *root); +static void verify_property_5_helper( + ogs_rbnode_t *node, int black_count, int* path_black_count); + +#define rb_is_red(r) ((r) && (r)->color == OGS_RBTREE_RED) +#define rb_is_black(r) ((!r) || (r)->color == OGS_RBTREE_BLACK) + +static void verify_properties(ogs_rbtree_t *tree) +{ + verify_property_1(tree->root); + verify_property_2(tree->root); + /* Property 3 is implicit */ + verify_property_4(tree->root); + verify_property_5(tree->root); +} +static void verify_property_1(ogs_rbnode_t *node) +{ + ogs_assert(rb_is_red(node) || rb_is_black(node)); + if (node == NULL) return; + verify_property_1(node->left); + verify_property_1(node->right); +} +static void verify_property_2(ogs_rbnode_t *root) +{ + ogs_assert(rb_is_black(root)); +} +static void verify_property_4(ogs_rbnode_t *node) +{ + if (rb_is_red(node)) { + ogs_assert(rb_is_black(node->left)); + ogs_assert(rb_is_black(node->right)); + ogs_assert(rb_is_black(node->parent)); + } + if (node == NULL) return; + verify_property_4(node->left); + verify_property_4(node->right); +} +static void verify_property_5(ogs_rbnode_t *root) +{ + int black_count_path = -1; + verify_property_5_helper(root, 0, &black_count_path); +} +static void verify_property_5_helper( + ogs_rbnode_t *node, int black_count, int* path_black_count) +{ + if (rb_is_black(node)) { + black_count++; + } + if (node == NULL) { + if (*path_black_count == -1) { + *path_black_count = black_count; + } else { + ogs_assert(black_count == *path_black_count); + } + return; + } + verify_property_5_helper(node->left, black_count, path_black_count); + verify_property_5_helper(node->right, black_count, path_black_count); +} diff --git a/tests/core/socket-test.c b/tests/core/socket-test.c new file mode 100644 index 000000000..064f1e90b --- /dev/null +++ b/tests/core/socket-test.c @@ -0,0 +1,444 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "ogs-core.h" +#include "core/abts.h" + +#define DATASTR "This is a test" +#define STRLEN 8092 +#define PORT 7777 +#define PORT2 7778 + +#ifndef AI_PASSIVE +#define AI_PASSIVE 1 +#endif + +static void test1_func(abts_case *tc, void *data) +{ + int rv; + ogs_sock_t *udp; + ogs_sockaddr_t *addr; + ogs_socknode_t *node; + + rv = ogs_getaddrinfo(&addr, AF_UNSPEC, NULL, PORT, AI_PASSIVE); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + node = ogs_socknode_new(addr); + ABTS_PTR_NOTNULL(tc, node); + udp = ogs_udp_server(node); + ABTS_PTR_NOTNULL(tc, udp); + ogs_socknode_free(node); + + rv = ogs_getaddrinfo(&addr, AF_UNSPEC, "127.0.0.1", PORT, AI_PASSIVE); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + node = ogs_socknode_new(addr); + ABTS_PTR_NOTNULL(tc, node); + udp = ogs_udp_server(node); + ABTS_PTR_NOTNULL(tc, udp); + ogs_socknode_free(node); + + rv = ogs_getaddrinfo(&addr, AF_UNSPEC, "::1", PORT, AI_PASSIVE); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + node = ogs_socknode_new(addr); + ABTS_PTR_NOTNULL(tc, node); + udp = ogs_udp_server(node); + ABTS_PTR_NOTNULL(tc, udp); + ogs_socknode_free(node); +} + +static ogs_thread_t *test2_thread; +static void test2_main(void *data) +{ + int rv; + abts_case *tc = data; + ogs_sock_t *tcp; + ogs_sockaddr_t *addr; + ogs_socknode_t *node; + char str[STRLEN]; + ssize_t size; + + rv = ogs_getaddrinfo(&addr, AF_UNSPEC, "::1", PORT, AI_PASSIVE); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + node = ogs_socknode_new(addr); + ABTS_PTR_NOTNULL(tc, node); + tcp = ogs_tcp_client(node); + ABTS_PTR_NOTNULL(tc, tcp); + + size = ogs_recv(tcp->fd, str, STRLEN, 0); + ABTS_INT_EQUAL(tc, strlen(DATASTR), size); + + ogs_socknode_free(node); +} + +static void test2_func(abts_case *tc, void *data) +{ + int rv; + ogs_sock_t *tcp, *tcp2; + ogs_sockaddr_t *addr; + ogs_socknode_t *node; + ssize_t size; + + rv = ogs_getaddrinfo(&addr, AF_INET6, NULL, PORT, AI_PASSIVE); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + node = ogs_socknode_new(addr); + ABTS_PTR_NOTNULL(tc, node); + tcp = ogs_tcp_server(node); + ABTS_PTR_NOTNULL(tc, tcp); + + test2_thread = ogs_thread_create(test2_main, tc); + ABTS_PTR_NOTNULL(tc, test2_thread); + + tcp2 = ogs_sock_accept(tcp); + ABTS_PTR_NOTNULL(tc, tcp2); + + size = ogs_send(tcp2->fd, DATASTR, strlen(DATASTR), 0); + ABTS_INT_EQUAL(tc, strlen(DATASTR), size); + + ogs_thread_destroy(test2_thread); + + ogs_sock_destroy(tcp2); + ogs_socknode_free(node); +} + +static ogs_thread_t *test3_thread; +static void test3_main(void *data) +{ + abts_case *tc = data; + int rv; + ogs_sock_t *udp; + ogs_sockaddr_t *addr; + ssize_t size; + + rv = ogs_getaddrinfo(&addr, AF_INET, NULL, PORT, 0); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + udp = ogs_udp_socket(AF_INET, NULL); + ABTS_PTR_NOTNULL(tc, udp); + + size = ogs_sendto(udp->fd, DATASTR, strlen(DATASTR), 0, addr); + ABTS_INT_EQUAL(tc, strlen(DATASTR), size); + + ogs_sock_destroy(udp); + + rv = ogs_freeaddrinfo(addr); + ABTS_INT_EQUAL(tc, OGS_OK, rv); +} + +static void test3_func(abts_case *tc, void *data) +{ + int rv; + ogs_sock_t *udp; + ssize_t size; + ogs_sockaddr_t sa; + ogs_sockaddr_t *addr; + ogs_socknode_t *node; + char str[STRLEN]; + char buf[OGS_ADDRSTRLEN]; + + rv = ogs_getaddrinfo(&addr, AF_INET, NULL, PORT, AI_PASSIVE); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + node = ogs_socknode_new(addr); + ABTS_PTR_NOTNULL(tc, node); + udp = ogs_udp_server(node); + ABTS_PTR_NOTNULL(tc, udp); + + test3_thread = ogs_thread_create(test3_main, tc); + ABTS_PTR_NOTNULL(tc, test3_thread); + + size = ogs_recvfrom(udp->fd, str, STRLEN, 0, &sa); + ABTS_INT_EQUAL(tc, strlen(DATASTR), size); + ABTS_STR_EQUAL(tc, "127.0.0.1", OGS_ADDR(&sa, buf)); + + ogs_thread_destroy(test3_thread); + + ogs_socknode_free(node); +} + +static ogs_thread_t *test4_thread; +static void test4_main(void *data) +{ + int rv; + abts_case *tc = data; + ogs_sock_t *udp; + ogs_sockaddr_t *addr; + ogs_socknode_t *node; + char str[STRLEN]; + ssize_t size; + + rv = ogs_getaddrinfo(&addr, AF_INET, NULL, PORT, 0); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + node = ogs_socknode_new(addr); + ABTS_PTR_NOTNULL(tc, node); + udp = ogs_udp_client(node); + ABTS_PTR_NOTNULL(tc, udp); + + size = ogs_send(udp->fd, DATASTR, strlen(DATASTR), 0); + ABTS_INT_EQUAL(tc, strlen(DATASTR), size); + + size = ogs_recv(udp->fd, str, STRLEN, 0); + ABTS_INT_EQUAL(tc, strlen(DATASTR), size); + + ogs_socknode_free(node); +} + +static void test4_func(abts_case *tc, void *data) +{ + int rv; + ogs_sock_t *udp; + ssize_t size; + ogs_sockaddr_t sa; + ogs_sockaddr_t *addr; + ogs_socknode_t *node; + char str[STRLEN]; + char buf[OGS_ADDRSTRLEN]; + + rv = ogs_getaddrinfo(&addr, AF_INET, NULL, PORT, AI_PASSIVE); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + node = ogs_socknode_new(addr); + ABTS_PTR_NOTNULL(tc, node); + udp = ogs_udp_server(node); + ABTS_PTR_NOTNULL(tc, udp); + + test4_thread = ogs_thread_create(test4_main, tc); + ABTS_PTR_NOTNULL(tc, test4_thread); + + size = ogs_recvfrom(udp->fd, str, STRLEN, 0, &sa); + ABTS_INT_EQUAL(tc, strlen(DATASTR), size); + ABTS_STR_EQUAL(tc, "127.0.0.1", OGS_ADDR(&sa, buf)); + + size = ogs_sendto(udp->fd, DATASTR, strlen(DATASTR), 0, &sa); + ABTS_INT_EQUAL(tc, strlen(DATASTR), size); + + ogs_thread_destroy(test4_thread); + + ogs_socknode_free(node); +} + +static ogs_thread_t *test5_thread; +static void test5_main(void *data) +{ + abts_case *tc = data; + int rv; + ogs_sock_t *udp; + ogs_sockaddr_t *addr; + ogs_socknode_t *node; + char str[STRLEN]; + ssize_t size; + + rv = ogs_getaddrinfo(&addr, AF_INET6, NULL, PORT2, AI_PASSIVE); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + node = ogs_socknode_new(addr); + ABTS_PTR_NOTNULL(tc, node); + udp = ogs_udp_server(node); + ABTS_PTR_NOTNULL(tc, udp); + + rv = ogs_getaddrinfo(&addr, AF_INET6, NULL, PORT, 0); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + rv = ogs_udp_connect(udp, addr); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + rv = ogs_freeaddrinfo(addr); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + size = ogs_send(udp->fd, DATASTR, strlen(DATASTR), 0); + ABTS_INT_EQUAL(tc, strlen(DATASTR), size); + + size = ogs_recv(udp->fd, str, STRLEN, 0); + ABTS_INT_EQUAL(tc, strlen(DATASTR), size); + + ogs_socknode_free(node); +} + +static void test5_func(abts_case *tc, void *data) +{ + ogs_sock_t *udp; + int rv; + ssize_t size; + ogs_sockaddr_t sa, *addr; + ogs_socknode_t *node; + char str[STRLEN]; + char buf[OGS_ADDRSTRLEN]; + + rv = ogs_getaddrinfo(&addr, AF_INET6, NULL, PORT, AI_PASSIVE); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + node = ogs_socknode_new(addr); + ABTS_PTR_NOTNULL(tc, node); + udp = ogs_udp_server(node); + ABTS_PTR_NOTNULL(tc, udp); + + rv = ogs_getaddrinfo(&addr, AF_INET6, NULL, PORT2, 0); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + rv = ogs_udp_connect(udp, addr); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + rv = ogs_freeaddrinfo(addr); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + test5_thread = ogs_thread_create(test5_main, tc); + ABTS_PTR_NOTNULL(tc, test5_thread); + + size = ogs_recvfrom(udp->fd, str, STRLEN, 0, &sa); + ABTS_INT_EQUAL(tc, strlen(DATASTR), size); + ABTS_STR_EQUAL(tc, "::1", OGS_ADDR(&sa, buf)); + + size = ogs_send(udp->fd, DATASTR, strlen(DATASTR), 0); + ABTS_INT_EQUAL(tc, strlen(DATASTR), size); + + ogs_thread_destroy(test5_thread); + + ogs_socknode_free(node); +} + +static void test6_func(abts_case *tc, void *data) +{ + ogs_sockaddr_t addr, *paddr, *dst; + char buf[OGS_ADDRSTRLEN]; + int rv; + + rv = ogs_inet_pton(AF_INET, "127.0.0.1", &addr); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + ABTS_STR_EQUAL(tc, "127.0.0.1", OGS_ADDR(&addr, buf)); + + rv = ogs_inet_pton(AF_INET6, "::1", &addr); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + ABTS_STR_EQUAL(tc, "::1", OGS_ADDR(&addr, buf)); + + paddr = NULL; + rv = ogs_addaddrinfo(&paddr, AF_UNSPEC, NULL, PORT, 0); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + rv = ogs_sortaddrinfo(&paddr, AF_INET6); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + ABTS_STR_EQUAL(tc, "::1", OGS_ADDR(paddr, buf)); + ABTS_PTR_NOTNULL(tc, paddr->next); + ABTS_STR_EQUAL(tc, "127.0.0.1", OGS_ADDR(paddr->next, buf)); + + rv = ogs_copyaddrinfo(&dst, paddr); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + ABTS_STR_EQUAL(tc, "::1", OGS_ADDR(dst, buf)); + ABTS_PTR_NOTNULL(tc, paddr->next); + ABTS_STR_EQUAL(tc, "127.0.0.1", OGS_ADDR(dst->next, buf)); + rv = ogs_freeaddrinfo(dst); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + rv = ogs_sortaddrinfo(&paddr, AF_INET); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + ABTS_STR_EQUAL(tc, "127.0.0.1", OGS_ADDR(paddr, buf)); + ABTS_PTR_NOTNULL(tc, paddr->next); + ABTS_STR_EQUAL(tc, "::1", OGS_ADDR(paddr->next, buf)); + + rv = ogs_filteraddrinfo(&paddr, AF_INET); + ABTS_PTR_NOTNULL(tc, paddr); + ABTS_STR_EQUAL(tc, "127.0.0.1", OGS_ADDR(paddr, buf)); + + rv = ogs_copyaddrinfo(&dst, paddr); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + ABTS_STR_EQUAL(tc, "127.0.0.1", OGS_ADDR(dst, buf)); + rv = ogs_addaddrinfo(&dst, AF_UNSPEC, NULL, PORT, 0); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + ABTS_STR_EQUAL(tc, "127.0.0.1", OGS_ADDR(dst, buf)); + + rv = ogs_freeaddrinfo(dst); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + rv = ogs_filteraddrinfo(&paddr, AF_INET6); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + ABTS_TRUE(tc, paddr == NULL); + + rv = ogs_copyaddrinfo(&dst, paddr); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + ABTS_TRUE(tc, dst == NULL); + + paddr = NULL; + rv = ogs_addaddrinfo(&paddr, AF_INET, "127.0.0.1", PORT, 0); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + rv = ogs_addaddrinfo(&paddr, AF_INET, "127.0.0.2", PORT, 0); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + rv = ogs_addaddrinfo(&paddr, AF_INET, "127.0.0.3", PORT, 0); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + rv = ogs_filteraddrinfo(&paddr, AF_INET6); + ABTS_INT_EQUAL(tc, OGS_OK, rv); +} + +static void test7_func(abts_case *tc, void *data) +{ + int rv; + ogs_socknode_t *node; + ogs_sockaddr_t *addr; + ogs_list_t list, list6; + + ogs_list_init(&list); + ogs_list_init(&list6); + + rv = ogs_getaddrinfo(&addr, AF_UNSPEC, "localhost", PORT, 0); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + node = ogs_socknode_add(&list, AF_INET, addr); + ABTS_PTR_NOTNULL(tc, node); + + ogs_freeaddrinfo(addr); + + ogs_socknode_remove_all(&list); + + rv = ogs_socknode_probe(&list, &list6, NULL, PORT); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + ogs_socknode_remove_all(&list); + ogs_socknode_remove_all(&list6); +} + +static void test8_func(abts_case *tc, void *data) +{ + int rv; + ogs_ipsubnet_t ipsub; + + rv = ogs_ipsubnet(&ipsub, "127.0.0.1", "8"); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + rv = ogs_ipsubnet(&ipsub, "fe80::1", "64"); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + rv = ogs_ipsubnet(&ipsub, "172.16.0.1", "16"); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + rv = ogs_ipsubnet(&ipsub, "cafe::1", "64"); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + rv = ogs_ipsubnet(&ipsub, "172.16.0.1", NULL); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + rv = ogs_ipsubnet(&ipsub, "cafe::1", NULL); + ABTS_INT_EQUAL(tc, OGS_OK, rv); +} + +abts_suite *test_socket(abts_suite *suite) +{ + suite = ADD_SUITE(suite) + + abts_run_test(suite, test1_func, NULL); + abts_run_test(suite, test2_func, NULL); + abts_run_test(suite, test3_func, NULL); + abts_run_test(suite, test4_func, NULL); + abts_run_test(suite, test5_func, NULL); + abts_run_test(suite, test6_func, NULL); + abts_run_test(suite, test7_func, NULL); + abts_run_test(suite, test8_func, NULL); + + return suite; +} diff --git a/tests/core/strings-test.c b/tests/core/strings-test.c new file mode 100644 index 000000000..18513dbdf --- /dev/null +++ b/tests/core/strings-test.c @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "ogs-core.h" +#include "core/abts.h" + +static void test_slprintf(abts_case *tc, void *data) +{ + char str[8]; + char *last = str + 8; + char *buffer = str; + + buffer = ogs_slprintf(buffer, last, "1234"); + ABTS_TRUE(tc, strcmp(str, "1234") == 0); + buffer = ogs_slprintf(buffer, last, "56"); + ABTS_TRUE(tc, strcmp(str, "123456") == 0); + buffer = ogs_slprintf(buffer, last, "7"); + ABTS_TRUE(tc, strcmp(str, "1234567") == 0); + buffer = ogs_slprintf(buffer, last, "8"); + ABTS_TRUE(tc, strcmp(str, "1234567") == 0); + buffer = ogs_slprintf(buffer, last, "9"); + ABTS_TRUE(tc, strcmp(str, "1234567") == 0); + buffer = ogs_slprintf(buffer, last, "10"); + ABTS_TRUE(tc, strcmp(str, "1234567") == 0); +} + +abts_suite *test_strings(abts_suite *suite) +{ + suite = ADD_SUITE(suite) + + abts_run_test(suite, test_slprintf, NULL); + + return suite; +} diff --git a/tests/core/thread-test.c b/tests/core/thread-test.c new file mode 100644 index 000000000..7b9d9cc7b --- /dev/null +++ b/tests/core/thread-test.c @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "ogs-core.h" +#include "core/abts.h" + +static ogs_thread_mutex_t lock; +static int x = 0; + +#define LOCK_LOOP 10000 +#define THREAD_NUM 100 + +static ogs_thread_t *thread[THREAD_NUM]; + +static void thread_func(void *data) +{ + int i; + + for (i = 0; i < LOCK_LOOP; i++) { + ogs_thread_mutex_lock(&lock); + x++; + ogs_thread_mutex_unlock(&lock); + } +} + +static void init_thread(abts_case *tc, void *data) +{ + ogs_thread_mutex_init(&lock); +} + +static void create_threads(abts_case *tc, void *data) +{ + int i = 0; + + for (i = 0; i < THREAD_NUM; i++) { + thread[i] = ogs_thread_create(thread_func, NULL); + } +} + +static void delete_threads(abts_case *tc, void *data) +{ + int i = 0; + + for (i = 0; i < THREAD_NUM; i++) { + ogs_thread_destroy(thread[i]); + } +} + +static void check_locks(abts_case *tc, void *data) +{ + ABTS_INT_EQUAL(tc, THREAD_NUM * LOCK_LOOP, x); +} + +static void final_thread(abts_case *tc, void *data) +{ + ogs_thread_mutex_destroy(&lock); +} + +abts_suite *test_thread(abts_suite *suite) +{ + suite = ADD_SUITE(suite) + + abts_run_test(suite, init_thread, NULL); + abts_run_test(suite, create_threads, NULL); + abts_run_test(suite, delete_threads, NULL); + abts_run_test(suite, check_locks, NULL); + abts_run_test(suite, final_thread, NULL); + + return suite; +} diff --git a/tests/core/time-test.c b/tests/core/time-test.c new file mode 100644 index 000000000..46a9935cc --- /dev/null +++ b/tests/core/time-test.c @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "ogs-core.h" +#include "core/abts.h" + +static void test_now(abts_case *tc, void *data) +{ + struct timeval tv; + time_t timediff; + time_t current; + time_t os_now; + + ogs_gettimeofday(&tv); + current = tv.tv_sec; + time(&os_now); + + timediff = os_now - current; + ABTS_ASSERT(tc, "ogs_gettimeofday() and time() do not agree", + (timediff > -2) && (timediff < 2)); +} + +#define STR_SIZE 100 + +static void test_strftime(abts_case *tc, void *data) +{ + struct tm tm; + char str[STR_SIZE+1]; + time_t now = (time_t)1542100786; + + ogs_gmtime(now, &tm); + strftime(str, sizeof str, "%Y/%m/%d %H:%M:%S", &tm); + ABTS_STR_EQUAL(tc, "2018/11/13 09:19:46", str); + + ogs_localtime(now, &tm); + strftime(str, sizeof str, "%Y/%m/%d %H:%M:%S", &tm); +#if 0 /* FIXME */ + ABTS_STR_EQUAL(tc, "2018/11/13 18:19:46", str); +#endif +} + +abts_suite *test_time(abts_suite *suite) +{ + suite = ADD_SUITE(suite) + + abts_run_test(suite, test_now, NULL); + abts_run_test(suite, test_strftime, NULL); + + return suite; +} diff --git a/tests/core/timer-test.c b/tests/core/timer-test.c new file mode 100644 index 000000000..125254e4e --- /dev/null +++ b/tests/core/timer-test.c @@ -0,0 +1,220 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "ogs-core.h" +#include "core/abts.h" + +#define TEST_TIMER_NUM 200 +#define TEST_TIMER_PRECISION 20000 +#define TEST_DURATION 400000 + +static uint8_t expire_check[TEST_DURATION/TEST_TIMER_PRECISION]; +static ogs_time_t timer_duration[] = { 500000, 50000, 200000, 90000, 800000 }; + +void test_expire_func_1(void *data) +{ + int index = (uintptr_t)data; + + expire_check[index] = TRUE; +} + +void test_expire_func_2(void *data) +{ + int index = (uintptr_t)data; + + expire_check[index]++; +} + +/* basic timer Test */ +static void test1_func(abts_case *tc, void *data) +{ + int n = 0; + ogs_pollset_t *pollset = NULL; + ogs_timer_mgr_t *timer = NULL; + ogs_timer_t *timer_array[TEST_TIMER_NUM]; + + memset(expire_check, 0, TEST_DURATION/TEST_TIMER_PRECISION); + + timer = ogs_timer_mgr_create(); + pollset = ogs_pollset_create(); + ogs_assert(timer); + for(n = 0; n < sizeof(timer_duration)/sizeof(ogs_time_t); n++) { + timer_array[n] = ogs_timer_add( + timer, test_expire_func_1, (void*)(uintptr_t)n); + ogs_assert(timer_array[n]); + ogs_timer_start(timer_array[n], timer_duration[n]); + } + + ogs_pollset_poll(pollset, ogs_timer_mgr_next(timer)); + ogs_timer_mgr_expire(timer); + + ABTS_INT_EQUAL(tc, 0, expire_check[0]); + ABTS_INT_EQUAL(tc, 1, expire_check[1]); + ABTS_INT_EQUAL(tc, 0, expire_check[2]); + ABTS_INT_EQUAL(tc, 0, expire_check[3]); + ABTS_INT_EQUAL(tc, 0, expire_check[4]); + + ogs_pollset_poll(pollset, ogs_timer_mgr_next(timer)); + ogs_timer_mgr_expire(timer); + + ABTS_INT_EQUAL(tc, 0, expire_check[0]); + ABTS_INT_EQUAL(tc, 1, expire_check[1]); + ABTS_INT_EQUAL(tc, 0, expire_check[2]); + ABTS_INT_EQUAL(tc, 1, expire_check[3]); + ABTS_INT_EQUAL(tc, 0, expire_check[4]); + + ogs_pollset_poll(pollset, ogs_timer_mgr_next(timer)); + ogs_timer_mgr_expire(timer); + + ABTS_INT_EQUAL(tc, 0, expire_check[0]); + ABTS_INT_EQUAL(tc, 1, expire_check[1]); + ABTS_INT_EQUAL(tc, 1, expire_check[2]); + ABTS_INT_EQUAL(tc, 1, expire_check[3]); + ABTS_INT_EQUAL(tc, 0, expire_check[4]); + + ogs_pollset_poll(pollset, ogs_timer_mgr_next(timer)); + ogs_timer_mgr_expire(timer); + + ABTS_INT_EQUAL(tc, 1, expire_check[0]); + ABTS_INT_EQUAL(tc, 1, expire_check[1]); + ABTS_INT_EQUAL(tc, 1, expire_check[2]); + ABTS_INT_EQUAL(tc, 1, expire_check[3]); + ABTS_INT_EQUAL(tc, 0, expire_check[4]); + + ogs_pollset_poll(pollset, ogs_timer_mgr_next(timer)); + ogs_timer_mgr_expire(timer); + ABTS_INT_EQUAL(tc, OGS_INFINITE_TIME, ogs_timer_mgr_next(timer)); + + ABTS_INT_EQUAL(tc, 1, expire_check[0]); + ABTS_INT_EQUAL(tc, 1, expire_check[1]); + ABTS_INT_EQUAL(tc, 1, expire_check[2]); + ABTS_INT_EQUAL(tc, 1, expire_check[3]); + ABTS_INT_EQUAL(tc, 1, expire_check[4]); + + for(n = 0; n < sizeof(timer_duration)/sizeof(ogs_time_t); n++) + ogs_timer_delete(timer_array[n]); + + ogs_timer_mgr_destroy(timer); + ogs_pollset_destroy(pollset); +} + +static void test2_func(abts_case *tc, void *data) +{ + int n = 0; + ogs_timer_mgr_t *timer = NULL; + ogs_timer_t *timer_array[TEST_TIMER_NUM]; + int duration; + int tm_num[TEST_DURATION/TEST_TIMER_PRECISION]; + int tm_idx; + + memset(expire_check, 0, TEST_DURATION/TEST_TIMER_PRECISION); + memset(tm_num, 0, sizeof(int)*(TEST_DURATION/TEST_TIMER_PRECISION)); + + timer = ogs_timer_mgr_create(); + ogs_assert(timer); + + for(n = 0; n < TEST_TIMER_NUM; n++) { + duration = (ogs_random32() % (TEST_DURATION/TEST_TIMER_PRECISION)) + * TEST_TIMER_PRECISION; + + tm_idx = duration/TEST_TIMER_PRECISION; + tm_num[tm_idx]++; + duration += (TEST_TIMER_PRECISION >> 1); + + timer_array[n] = ogs_timer_add( + timer, test_expire_func_2, (void*)(uintptr_t)tm_idx); + ogs_assert(timer_array[n]); + ogs_timer_start(timer_array[n], duration); + } + + for(n = 0; n < TEST_DURATION/TEST_TIMER_PRECISION; n++) { + ogs_usleep(TEST_TIMER_PRECISION); + ogs_timer_mgr_expire(timer); + ABTS_INT_EQUAL(tc, tm_num[n], expire_check[n]); + } + + for(n = 0; n < TEST_TIMER_NUM; n++) + ogs_timer_delete(timer_array[n]); + + ogs_timer_mgr_destroy(timer); +} + +static void test3_func(abts_case *tc, void *data) +{ + int n = 0; + ogs_timer_mgr_t *timer = NULL; + ogs_timer_t *timer_array[TEST_TIMER_NUM]; + int id_duration[TEST_TIMER_NUM]; + int duration; + int tm_num[TEST_DURATION/TEST_TIMER_PRECISION]; + int tm_idx, tm_check_id; + + memset(expire_check, 0, TEST_DURATION/TEST_TIMER_PRECISION); + memset(tm_num, 0, sizeof(int)*(TEST_DURATION/TEST_TIMER_PRECISION)); + + timer = ogs_timer_mgr_create(); + ogs_assert(timer); + + for(n = 0; n < TEST_TIMER_NUM; n++) { + duration = (ogs_random32() % (TEST_DURATION/TEST_TIMER_PRECISION)) + * TEST_TIMER_PRECISION; + + tm_idx = duration/TEST_TIMER_PRECISION; + tm_num[tm_idx]++; + id_duration[n] = duration; + duration += (TEST_TIMER_PRECISION >> 1); + + timer_array[n] = ogs_timer_add( + timer, test_expire_func_2, (void*)(uintptr_t)tm_idx); + ogs_assert(timer_array[n]); + ogs_timer_start(timer_array[n], duration); + } + + for(n = 0; n < TEST_TIMER_NUM / 10; n++) { + tm_idx = n*10 + ogs_random32()%10; + tm_check_id = id_duration[tm_idx]/TEST_TIMER_PRECISION; + tm_num[tm_check_id]--; + ogs_timer_delete(timer_array[tm_idx]); + timer_array[tm_idx] = NULL; + } + + for(n = 0; n < TEST_DURATION/TEST_TIMER_PRECISION; n++) { + ogs_usleep(TEST_TIMER_PRECISION); + ogs_timer_mgr_expire(timer); + ABTS_INT_EQUAL(tc, tm_num[n], expire_check[n]); + } + + for(n = 0; n < TEST_TIMER_NUM; n++) { + if (timer_array[n]) + ogs_timer_delete(timer_array[n]); + } + + ogs_timer_mgr_destroy(timer); +} + +abts_suite *test_timer(abts_suite *suite) +{ + suite = ADD_SUITE(suite) + + abts_run_test(suite, test1_func, NULL); + abts_run_test(suite, test2_func, NULL); + abts_run_test(suite, test3_func, NULL); + + return suite; +} diff --git a/tests/core/tlv-test.c b/tests/core/tlv-test.c new file mode 100644 index 000000000..820e54418 --- /dev/null +++ b/tests/core/tlv-test.c @@ -0,0 +1,873 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "ogs-core.h" +#include "core/abts.h" + +#define TLV_0_LEN 10 +#define TLV_1_LEN 20 +#define TLV_2_LEN 100 +#define TLV_3_LEN 200 +#define TLV_4_LEN 2 +#define TLV_5_LEN 2000 +#define TLV_0_INSTANCE 0 +#define TLV_1_INSTANCE 1 +#define TLV_2_INSTANCE 2 +#define TLV_3_INSTANCE 3 +#define TLV_4_INSTANCE 4 +#define TLV_5_INSTANCE 5 +#define TLV_VALUE_ARRAY_SIZE 3000 + +#define EMBED_TLV_TYPE 20 +#define EMBED_TLV_INSTANCE 7 + +typedef struct _test_tlv_element +{ + uint8_t type; + uint32_t length; + uint8_t instance; + uint8_t *value; + uint8_t val_char; +} test_tlv_element; + +uint8_t test_ogs_tlv_value[TLV_VALUE_ARRAY_SIZE]; + +test_tlv_element tlv_element[] ={ + {1, TLV_0_LEN, TLV_0_INSTANCE, 0, 0x0a}, + {50, TLV_1_LEN, TLV_1_INSTANCE, 0, 0x0b}, + {255, TLV_2_LEN, TLV_2_INSTANCE, 0, 0x0c}, + {254, TLV_3_LEN, TLV_3_INSTANCE, 0, 0x0d}, + {5, TLV_4_LEN, TLV_4_INSTANCE, 0, 0x0e}, + {30, TLV_5_LEN, TLV_5_INSTANCE, 0, 0x0f} +}; + +void ogs_tlv_test_set_ogs_tlv_value(void) +{ + uint32_t inc = 0; + + /* set test tlv value */ + tlv_element[0].value = test_ogs_tlv_value; + memset(tlv_element[0].value, tlv_element[0].val_char, tlv_element[0].length); + inc += tlv_element[0].length; + + tlv_element[1].value = test_ogs_tlv_value + inc; + memset(tlv_element[1].value, tlv_element[1].val_char, tlv_element[1].length); + inc += tlv_element[1].length; + + tlv_element[2].value = test_ogs_tlv_value + inc; + memset(tlv_element[2].value, tlv_element[2].val_char, tlv_element[2].length); + inc += tlv_element[2].length; + + tlv_element[3].value = test_ogs_tlv_value + inc; + memset(tlv_element[3].value, tlv_element[3].val_char, tlv_element[3].length); + inc += tlv_element[3].length; + + tlv_element[4].value = test_ogs_tlv_value + inc; + memset(tlv_element[4].value, tlv_element[4].val_char, tlv_element[4].length); + inc += tlv_element[4].length; + + return; +} + +void ogs_tlv_test_check_embed_ogs_tlv_test(abts_case *tc, ogs_tlv_t *root_tlv, int mode) +{ + uint32_t m; + uint32_t parent_block_len; + ogs_tlv_t *pTlv; + ogs_tlv_t *embed_tlv = NULL, *parent_tlv = NULL, *parsed_tlv = NULL; + uint8_t parent_block[4000]; + uint8_t *pos = NULL; + int result; + + memset(parent_block, 0x00, sizeof(parent_block)); + + parent_block_len = ogs_tlv_render(root_tlv, parent_block, + sizeof(parent_block), mode); + + ogs_tlv_free_all(root_tlv); + ABTS_INT_EQUAL(tc, ogs_tlv_pool_avail(), ogs_core()->tlv.pool); + + pos = parent_block; + + switch (mode) { + case OGS_TLV_MODE_T2_L2: + ABTS_INT_EQUAL(tc, 332, parent_block_len); + ABTS_INT_EQUAL(tc, *(pos++), tlv_element[0].type >> 8); + ABTS_INT_EQUAL(tc, *(pos++), tlv_element[0].type & 0xFF); + ABTS_INT_EQUAL(tc, *(pos++), tlv_element[0].length >> 8); + ABTS_INT_EQUAL(tc, *(pos++), tlv_element[0].length & 0xFF); + for(m = 0; m < tlv_element[0].length; m++) + ABTS_INT_EQUAL(tc, *(pos++), tlv_element[0].val_char); + + ABTS_INT_EQUAL(tc, *(pos++), EMBED_TLV_TYPE >> 8); + ABTS_INT_EQUAL(tc, *(pos++), EMBED_TLV_TYPE & 0xFF); + ABTS_INT_EQUAL(tc, *(pos++), (308 >> 8)); + ABTS_INT_EQUAL(tc, *(pos++), 308 & 0xFF); + + /* embedded ogs_tlv_t */ + ABTS_INT_EQUAL(tc, *(pos++), tlv_element[2].type >> 8); + ABTS_INT_EQUAL(tc, *(pos++), tlv_element[2].type & 0xFF); + ABTS_INT_EQUAL(tc, *(pos++), tlv_element[2].length >> 8); + ABTS_INT_EQUAL(tc, *(pos++), tlv_element[2].length & 0xFF); + for(m = 0; m < tlv_element[2].length; m++) + ABTS_INT_EQUAL(tc, *(pos++), tlv_element[2].val_char); + + + ABTS_INT_EQUAL(tc, *(pos++), tlv_element[3].type >> 8); + ABTS_INT_EQUAL(tc, *(pos++), tlv_element[3].type & 0xFF); + ABTS_INT_EQUAL(tc, *(pos++), tlv_element[3].length >> 8); + ABTS_INT_EQUAL(tc, *(pos++), tlv_element[3].length & 0xFF); + for(m = 0; m < tlv_element[3].length; m++) + ABTS_INT_EQUAL(tc, *(pos++), tlv_element[3].val_char); + + + ABTS_INT_EQUAL(tc, *(pos++), tlv_element[4].type >> 8); + ABTS_INT_EQUAL(tc, *(pos++), tlv_element[4].type & 0xFF); + ABTS_INT_EQUAL(tc, *(pos++), tlv_element[4].length >> 8); + ABTS_INT_EQUAL(tc, *(pos++), tlv_element[4].length & 0xFF); + + for(m = 0; m < tlv_element[4].length; m++) + ABTS_INT_EQUAL(tc, *(pos++), 0x0e); + break; + case OGS_TLV_MODE_T1_L2: + ABTS_INT_EQUAL(tc, 327, parent_block_len); + ABTS_INT_EQUAL(tc, *(pos++), tlv_element[0].type & 0xFF); + ABTS_INT_EQUAL(tc, *(pos++), tlv_element[0].length >> 8); + ABTS_INT_EQUAL(tc, *(pos++), tlv_element[0].length & 0xFF); + for(m = 0; m < tlv_element[0].length; m++) + ABTS_INT_EQUAL(tc, *(pos++), tlv_element[0].val_char); + + ABTS_INT_EQUAL(tc, *(pos++), EMBED_TLV_TYPE & 0xFF); + ABTS_INT_EQUAL(tc, *(pos++), (306 >> 8)); + ABTS_INT_EQUAL(tc, *(pos++), 306 & 0xFF); + + /* embedded ogs_tlv_t */ + ABTS_INT_EQUAL(tc, *(pos++), tlv_element[2].type & 0xFF); + ABTS_INT_EQUAL(tc, *(pos++), tlv_element[2].length >> 8); + ABTS_INT_EQUAL(tc, *(pos++), tlv_element[2].length & 0xFF); + for(m = 0; m < tlv_element[2].length; m++) + ABTS_INT_EQUAL(tc, *(pos++), tlv_element[2].val_char); + + + ABTS_INT_EQUAL(tc, *(pos++), tlv_element[3].type & 0xFF); + ABTS_INT_EQUAL(tc, *(pos++), tlv_element[3].length >> 8); + ABTS_INT_EQUAL(tc, *(pos++), tlv_element[3].length & 0xFF); + for(m = 0; m < tlv_element[3].length; m++) + ABTS_INT_EQUAL(tc, *(pos++), tlv_element[3].val_char); + + + ABTS_INT_EQUAL(tc, *(pos++), tlv_element[4].type & 0xFF); + ABTS_INT_EQUAL(tc, *(pos++), tlv_element[4].length >> 8); + ABTS_INT_EQUAL(tc, *(pos++), tlv_element[4].length & 0xFF); + + for(m = 0; m < tlv_element[4].length; m++) + ABTS_INT_EQUAL(tc, *(pos++), 0x0e); + break; + case OGS_TLV_MODE_T1_L2_I1: + ABTS_INT_EQUAL(tc, 332, parent_block_len); + ABTS_INT_EQUAL(tc, *(pos++), tlv_element[0].type & 0xFF); + ABTS_INT_EQUAL(tc, *(pos++), tlv_element[0].length >> 8); + ABTS_INT_EQUAL(tc, *(pos++), tlv_element[0].length & 0xFF); + ABTS_INT_EQUAL(tc, *(pos++), tlv_element[0].instance & 0xFF); + for(m = 0; m < tlv_element[0].length; m++) + ABTS_INT_EQUAL(tc, *(pos++), tlv_element[0].val_char); + + ABTS_INT_EQUAL(tc, *(pos++), EMBED_TLV_TYPE & 0xFF); + ABTS_INT_EQUAL(tc, *(pos++), (308 >> 8)); + ABTS_INT_EQUAL(tc, *(pos++), 308 & 0xFF); + ABTS_INT_EQUAL(tc, *(pos++), EMBED_TLV_INSTANCE); + + /* embedded ogs_tlv_t */ + ABTS_INT_EQUAL(tc, *(pos++), tlv_element[2].type & 0xFF); + ABTS_INT_EQUAL(tc, *(pos++), tlv_element[2].length >> 8); + ABTS_INT_EQUAL(tc, *(pos++), tlv_element[2].length & 0xFF); + ABTS_INT_EQUAL(tc, *(pos++), tlv_element[2].instance & 0xFF); + for(m = 0; m < tlv_element[2].length; m++) + ABTS_INT_EQUAL(tc, *(pos++), tlv_element[2].val_char); + + + ABTS_INT_EQUAL(tc, *(pos++), tlv_element[3].type & 0xFF); + ABTS_INT_EQUAL(tc, *(pos++), tlv_element[3].length >> 8); + ABTS_INT_EQUAL(tc, *(pos++), tlv_element[3].length & 0xFF); + ABTS_INT_EQUAL(tc, *(pos++), tlv_element[3].instance & 0xFF); + for(m = 0; m < tlv_element[3].length; m++) + ABTS_INT_EQUAL(tc, *(pos++), tlv_element[3].val_char); + + + ABTS_INT_EQUAL(tc, *(pos++), tlv_element[4].type & 0xFF); + ABTS_INT_EQUAL(tc, *(pos++), tlv_element[4].length >> 8); + ABTS_INT_EQUAL(tc, *(pos++), tlv_element[4].length & 0xFF); + ABTS_INT_EQUAL(tc, *(pos++), tlv_element[4].instance & 0xFF); + + for(m = 0; m < tlv_element[4].length; m++) + ABTS_INT_EQUAL(tc, *(pos++), 0x0e); + break; + default: + ABTS_TRUE(tc, 0); + break; + } + + parsed_tlv = ogs_tlv_parse_block(parent_block_len, + parent_block, mode); + ABTS_PTR_NOTNULL(tc, parsed_tlv); + + pTlv = parsed_tlv; + + ABTS_INT_EQUAL(tc, pTlv->type, tlv_element[0].type); + ABTS_INT_EQUAL(tc, pTlv->length, tlv_element[0].length); + ABTS_INT_EQUAL(tc, pTlv->instance, tlv_element[0].instance); + result = memcmp(pTlv->value, tlv_element[0].value, tlv_element[0].length); + ABTS_INT_EQUAL(tc, result, 0); + pTlv = pTlv->next; + + ABTS_INT_EQUAL(tc, pTlv->type, 20); + switch (mode) { + case OGS_TLV_MODE_T2_L2: + case OGS_TLV_MODE_T1_L2_I1: + ABTS_INT_EQUAL(tc, pTlv->length, 308); + break; + case OGS_TLV_MODE_T1_L2: + ABTS_INT_EQUAL(tc, pTlv->length, 306); + break; + default: + ABTS_TRUE(tc, 0); + break; + } + pTlv = pTlv->next; + + ABTS_INT_EQUAL(tc, pTlv->type, tlv_element[4].type); + ABTS_INT_EQUAL(tc, pTlv->length, tlv_element[4].length); + if (mode == OGS_TLV_MODE_T1_L2_I1) + ABTS_INT_EQUAL(tc, pTlv->instance, tlv_element[4].instance); + else + ABTS_INT_EQUAL(tc, pTlv->instance, 0); + result = memcmp(pTlv->value, tlv_element[4].value, tlv_element[4].length); + ABTS_INT_EQUAL(tc, result, 0); + pTlv = pTlv->next; + + ABTS_TRUE(tc, pTlv == NULL); + + parent_tlv = ogs_tlv_find(parsed_tlv,20); + ABTS_PTR_NOTNULL(tc, parent_tlv); + + ogs_tlv_parse_embedded_block(parent_tlv, mode); + embed_tlv = parent_tlv->embedded; + ABTS_PTR_NOTNULL(tc, embed_tlv); + + ABTS_INT_EQUAL(tc, embed_tlv->type, tlv_element[2].type); + ABTS_INT_EQUAL(tc, embed_tlv->length, tlv_element[2].length); + if (mode == OGS_TLV_MODE_T1_L2_I1) + ABTS_INT_EQUAL(tc, embed_tlv->instance, tlv_element[2].instance); + else + ABTS_INT_EQUAL(tc, embed_tlv->instance, 0); + for(m = 0; m < tlv_element[2].length; m++) { + ABTS_INT_EQUAL(tc, *((uint8_t*)embed_tlv->value+m), + tlv_element[2].val_char); + } + embed_tlv = embed_tlv->next; + + ABTS_INT_EQUAL(tc, embed_tlv->type, tlv_element[3].type); + ABTS_INT_EQUAL(tc, embed_tlv->length, tlv_element[3].length); + if (mode == OGS_TLV_MODE_T1_L2_I1) + ABTS_INT_EQUAL(tc, embed_tlv->instance, tlv_element[3].instance); + else + ABTS_INT_EQUAL(tc, embed_tlv->instance, 0); + for(m = 0; m < tlv_element[3].length; m++) { + ABTS_INT_EQUAL(tc, *((uint8_t*)embed_tlv->value+m), + tlv_element[3].val_char); + } + embed_tlv = embed_tlv->next; + + ABTS_TRUE(tc, embed_tlv == NULL); + + embed_tlv = ogs_tlv_find(parsed_tlv,254); + ABTS_PTR_NOTNULL(tc, embed_tlv); + + embed_tlv = ogs_tlv_find(parsed_tlv,253); + ABTS_TRUE(tc, embed_tlv == NULL); + + ogs_tlv_free_all(parsed_tlv); + ABTS_INT_EQUAL(tc, ogs_tlv_pool_avail(), ogs_core()->tlv.pool); + + return; +} + +/* basic encoding/decoding/finding Test */ +static void test1_func(abts_case *tc, void *data) +{ + uint32_t idx, m, parent_block_len; + ogs_tlv_t *root_tlv = NULL, *parsed_tlv = NULL, *pTlv; + uint8_t parent_block[4000]; + uint8_t *pos = NULL; + uint8_t mode = (uintptr_t)data; + + ogs_tlv_test_set_ogs_tlv_value(); + + /* tlv encoding for test */ + root_tlv = ogs_tlv_add(NULL,tlv_element[0].type, + tlv_element[0].length, tlv_element[0].instance, tlv_element[0].value); + + for (idx = 1; idx < 4; idx++) { + ogs_tlv_add(root_tlv, tlv_element[idx].type, + tlv_element[idx].length, tlv_element[idx].instance, + tlv_element[idx].value); + } + + memset(parent_block, 0x00, sizeof(parent_block)); + parent_block_len = ogs_tlv_render(root_tlv, parent_block, + sizeof(parent_block), mode); + + switch (mode) { + case OGS_TLV_MODE_T2_L2: + case OGS_TLV_MODE_T1_L2_I1: + ABTS_INT_EQUAL(tc, 346, parent_block_len); + break; + case OGS_TLV_MODE_T1_L2: + ABTS_INT_EQUAL(tc, 342, parent_block_len); + break; + case OGS_TLV_MODE_T1_L1: + ABTS_INT_EQUAL(tc, 338, parent_block_len); + break; + default: + ABTS_TRUE(tc, 0); + break; + } + + ogs_tlv_free_all(root_tlv); + ABTS_INT_EQUAL(tc, ogs_tlv_pool_avail(), ogs_core()->tlv.pool); + + pos = parent_block; + + for (idx = 0; idx < 4; idx++) { + switch (mode) { + case OGS_TLV_MODE_T2_L2: + ABTS_INT_EQUAL(tc, (tlv_element[idx].type >> 8), *(pos++)); + ABTS_INT_EQUAL(tc, tlv_element[idx].type & 0xFF, *(pos++)); + ABTS_INT_EQUAL(tc, (tlv_element[idx].length >> 8), *(pos++)); + ABTS_INT_EQUAL(tc, tlv_element[idx].length & 0xFF, *(pos++)); + break; + case OGS_TLV_MODE_T1_L2: + ABTS_INT_EQUAL(tc, tlv_element[idx].type & 0xFF, *(pos++)); + ABTS_INT_EQUAL(tc, (tlv_element[idx].length >> 8), *(pos++)); + ABTS_INT_EQUAL(tc, tlv_element[idx].length & 0xFF, *(pos++)); + break; + case OGS_TLV_MODE_T1_L1: + ABTS_INT_EQUAL(tc, tlv_element[idx].type & 0xFF, *(pos++)); + ABTS_INT_EQUAL(tc, tlv_element[idx].length & 0xFF, *(pos++)); + break; + case OGS_TLV_MODE_T1_L2_I1: + ABTS_INT_EQUAL(tc, tlv_element[idx].type & 0xFF, *(pos++)); + ABTS_INT_EQUAL(tc, (tlv_element[idx].length >> 8), *(pos++)); + ABTS_INT_EQUAL(tc, tlv_element[idx].length & 0xFF, *(pos++)); + ABTS_INT_EQUAL(tc, tlv_element[idx].instance & 0xFF, *(pos++)); + break; + default: + ABTS_TRUE(tc, 0); + break; + } + + for(m = 0; m < tlv_element[idx].length; m++) + ABTS_INT_EQUAL(tc, tlv_element[idx].val_char, *(pos++)); + } + + parsed_tlv = ogs_tlv_parse_block(parent_block_len,parent_block, mode); + ABTS_PTR_NOTNULL(tc, parsed_tlv); + + pTlv = parsed_tlv; + + idx = 0; + while (pTlv) { + int result; + ABTS_INT_EQUAL(tc, pTlv->type, tlv_element[idx].type); + ABTS_INT_EQUAL(tc, pTlv->length, tlv_element[idx].length); + if (mode == OGS_TLV_MODE_T1_L2_I1) + ABTS_INT_EQUAL(tc, pTlv->instance, tlv_element[idx].instance); + else + ABTS_INT_EQUAL(tc, pTlv->instance, 0); + result = memcmp(pTlv->value, tlv_element[idx].value, tlv_element[idx].length); + ABTS_INT_EQUAL(tc, result, 0); + + pTlv = pTlv->next; + idx++; + } + + ABTS_INT_EQUAL(tc, idx, 4); + + pTlv = ogs_tlv_find(parsed_tlv, 255); + ABTS_PTR_NOTNULL(tc, pTlv); + + pTlv = ogs_tlv_find(parsed_tlv, 253); + ABTS_TRUE(tc, pTlv == NULL); + + ogs_tlv_free_all(parsed_tlv); + ABTS_INT_EQUAL(tc, ogs_tlv_pool_avail(), ogs_core()->tlv.pool); + + return; +} + +/* embedded ogs_tlv_t test : first, make embedded tlv block for embeded tlv + and then make whole tlv block using embedded tlv block previously made*/ +static void test2_func(abts_case *tc, void *data) +{ + uint32_t embed_block_len; + ogs_tlv_t *root_tlv = NULL; + ogs_tlv_t *embed_tlv = NULL; + uint8_t embed_block[1000];; + uint8_t mode = (uintptr_t)data; + + ogs_tlv_test_set_ogs_tlv_value(); + + /* Tlv Encoding for embeded ogs_tlv_t */ + embed_tlv = ogs_tlv_add(NULL, tlv_element[2].type, + tlv_element[2].length, tlv_element[2].instance, tlv_element[2].value); + ogs_tlv_add(embed_tlv,tlv_element[3].type, + tlv_element[3].length, tlv_element[3].instance, tlv_element[3].value); + + embed_block_len = ogs_tlv_render(embed_tlv, embed_block, + sizeof(embed_block), mode); + switch (mode) { + case OGS_TLV_MODE_T2_L2: + case OGS_TLV_MODE_T1_L2_I1: + ABTS_INT_EQUAL(tc, embed_block_len, 308); + break; + case OGS_TLV_MODE_T1_L2: + ABTS_INT_EQUAL(tc, embed_block_len, 306); + break; + default: + ABTS_TRUE(tc, 0); + break; + } + + ogs_tlv_free_all(embed_tlv); + ABTS_INT_EQUAL(tc, ogs_tlv_pool_avail(), ogs_core()->tlv.pool); + + root_tlv = ogs_tlv_add(NULL,tlv_element[0].type, + tlv_element[0].length, tlv_element[0].instance, tlv_element[0].value); + + ogs_tlv_add(root_tlv, EMBED_TLV_TYPE, embed_block_len, + EMBED_TLV_INSTANCE, embed_block); + ogs_tlv_add(root_tlv,tlv_element[4].type, + tlv_element[4].length, tlv_element[4].instance, tlv_element[4].value); + + ogs_tlv_test_check_embed_ogs_tlv_test(tc, root_tlv, mode); + + return; +} + + +/* embedded ogs_tlv_t test : make parent and embedded tlv and then ogs_tlv_render + functions makes whole tlv block. the value member of each tlv must + point to vaild address at the time using ogs_tlv_rendering function */ +static void test3_func(abts_case *tc, void *data) +{ + ogs_tlv_t *root_tlv = NULL, *parent_tlv = NULL; + uint8_t mode = (uintptr_t)data; + + ogs_tlv_test_set_ogs_tlv_value(); + + /* Tlv Encoding for embeded ogs_tlv_t */ + root_tlv = ogs_tlv_add(NULL,tlv_element[0].type, + tlv_element[0].length, tlv_element[0].instance, tlv_element[0].value); + parent_tlv= ogs_tlv_add(root_tlv, EMBED_TLV_TYPE, 0, EMBED_TLV_INSTANCE, NULL); + ogs_tlv_add(root_tlv,tlv_element[4].type, + tlv_element[4].length, tlv_element[4].instance, tlv_element[4].value); + + ogs_tlv_embed(parent_tlv,tlv_element[2].type, + tlv_element[2].length, tlv_element[2].instance, tlv_element[2].value); + ogs_tlv_embed(parent_tlv,tlv_element[3].type, + tlv_element[3].length, tlv_element[3].instance, tlv_element[3].value); + + ogs_tlv_test_check_embed_ogs_tlv_test(tc, root_tlv, mode); + + return; +} + + +/* embedded ogs_tlv_t test : make parent and embedded tlv and then ogs_tlv_render + functions makes whole tlv block. The value member of each tlv is copied + to the buff of the root ogs_tlv_t, so the allocated resource for the value + member of each tlv can be deallocated after executing ogs_tlv_add or tlv embed + function*/ +static void test4_func(abts_case *tc, void *data) +{ + ogs_tlv_t *root_tlv = NULL, *parent_tlv = NULL; + uint8_t tlv_buff[2000]; + uint8_t mode = (uintptr_t)data; + + ogs_tlv_test_set_ogs_tlv_value(); + + root_tlv = ogs_tlv_copy(tlv_buff, sizeof(tlv_buff), + tlv_element[0].type, tlv_element[0].length, + tlv_element[0].instance, tlv_element[0].value); + parent_tlv = ogs_tlv_add(root_tlv, EMBED_TLV_TYPE, 0, EMBED_TLV_INSTANCE, NULL); + ogs_tlv_add(root_tlv, tlv_element[4].type, tlv_element[4].length, + tlv_element[4].instance, tlv_element[4].value); + + ogs_tlv_embed(parent_tlv,tlv_element[2].type, + tlv_element[2].length, tlv_element[2].instance, tlv_element[2].value); + ogs_tlv_embed(parent_tlv,tlv_element[3].type, + tlv_element[3].length, tlv_element[3].instance, tlv_element[3].value); + + memset(tlv_element[2].value, 0x00, tlv_element[2].length); + memset(tlv_element[3].value, 0xf0, tlv_element[3].length); + + ogs_tlv_test_check_embed_ogs_tlv_test(tc, root_tlv, mode); + + return; +} + +/* endian check test */ +static void test5_func(abts_case *tc, void *data) +{ + uint32_t parent_block_len; + ogs_tlv_t *root_tlv = NULL, *parsed_tlv = NULL, *p_tlv; + uint8_t parent_block[4000]; + uint8_t *pos = NULL; + uint16_t c_16 = 0x1122; + uint32_t c_32 = 0x11223344; + uint8_t mode = (uintptr_t)data; + + /* tlv encoding for test */ + c_16 = htobe16(c_16); + root_tlv = ogs_tlv_add(NULL, 10, 2, 0, (uint8_t*)&c_16); + c_32 = htobe32(c_32); + ogs_tlv_add(root_tlv, 20, 4, 0, (uint8_t*)&c_32); + + memset(parent_block, 0x00, sizeof(parent_block)); + parent_block_len = ogs_tlv_render(root_tlv, parent_block, + sizeof(parent_block), mode); + + ogs_tlv_free_all(root_tlv); + ABTS_INT_EQUAL(tc, ogs_tlv_pool_avail(), ogs_core()->tlv.pool); + + pos = parent_block; + + switch (mode) { + case OGS_TLV_MODE_T2_L2: + ABTS_INT_EQUAL(tc, *(pos++), 0); + ABTS_INT_EQUAL(tc, *(pos++), 10); + ABTS_INT_EQUAL(tc, *(pos++), 0); + ABTS_INT_EQUAL(tc, *(pos++), 2); + ABTS_INT_EQUAL(tc, *(pos++), 0x11); + ABTS_INT_EQUAL(tc, *(pos++), 0x22); + ABTS_INT_EQUAL(tc, *(pos++), 0); + ABTS_INT_EQUAL(tc, *(pos++), 20); + ABTS_INT_EQUAL(tc, *(pos++), 0); + ABTS_INT_EQUAL(tc, *(pos++), 4); + ABTS_INT_EQUAL(tc, *(pos++), 0x11); + ABTS_INT_EQUAL(tc, *(pos++), 0x22); + ABTS_INT_EQUAL(tc, *(pos++), 0x33); + ABTS_INT_EQUAL(tc, *(pos++), 0x44); + break; + case OGS_TLV_MODE_T1_L2: + ABTS_INT_EQUAL(tc, *(pos++), 10); + ABTS_INT_EQUAL(tc, *(pos++), 0); + ABTS_INT_EQUAL(tc, *(pos++), 2); + ABTS_INT_EQUAL(tc, *(pos++), 0x11); + ABTS_INT_EQUAL(tc, *(pos++), 0x22); + ABTS_INT_EQUAL(tc, *(pos++), 20); + ABTS_INT_EQUAL(tc, *(pos++), 0); + ABTS_INT_EQUAL(tc, *(pos++), 4); + ABTS_INT_EQUAL(tc, *(pos++), 0x11); + ABTS_INT_EQUAL(tc, *(pos++), 0x22); + ABTS_INT_EQUAL(tc, *(pos++), 0x33); + ABTS_INT_EQUAL(tc, *(pos++), 0x44); + break; + case OGS_TLV_MODE_T1_L2_I1: + ABTS_INT_EQUAL(tc, *(pos++), 10); + ABTS_INT_EQUAL(tc, *(pos++), 0); + ABTS_INT_EQUAL(tc, *(pos++), 2); + ABTS_INT_EQUAL(tc, *(pos++), 0); + ABTS_INT_EQUAL(tc, *(pos++), 0x11); + ABTS_INT_EQUAL(tc, *(pos++), 0x22); + ABTS_INT_EQUAL(tc, *(pos++), 20); + ABTS_INT_EQUAL(tc, *(pos++), 0); + ABTS_INT_EQUAL(tc, *(pos++), 4); + ABTS_INT_EQUAL(tc, *(pos++), 0); + ABTS_INT_EQUAL(tc, *(pos++), 0x11); + ABTS_INT_EQUAL(tc, *(pos++), 0x22); + ABTS_INT_EQUAL(tc, *(pos++), 0x33); + ABTS_INT_EQUAL(tc, *(pos++), 0x44); + break; + case OGS_TLV_MODE_T1_L1: + ABTS_INT_EQUAL(tc, *(pos++), 10); + ABTS_INT_EQUAL(tc, *(pos++), 2); + ABTS_INT_EQUAL(tc, *(pos++), 0x11); + ABTS_INT_EQUAL(tc, *(pos++), 0x22); + ABTS_INT_EQUAL(tc, *(pos++), 20); + ABTS_INT_EQUAL(tc, *(pos++), 4); + ABTS_INT_EQUAL(tc, *(pos++), 0x11); + ABTS_INT_EQUAL(tc, *(pos++), 0x22); + ABTS_INT_EQUAL(tc, *(pos++), 0x33); + ABTS_INT_EQUAL(tc, *(pos++), 0x44); + break; + default: + ABTS_TRUE(tc, 0); + break; + } + + p_tlv = parsed_tlv = ogs_tlv_parse_block(parent_block_len,parent_block, + mode); + ABTS_INT_EQUAL(tc, ogs_tlv_value_16(p_tlv), 0x1122); + p_tlv = parsed_tlv->next; + ABTS_INT_EQUAL(tc, ogs_tlv_value_32(p_tlv), 0x11223344); + + ogs_tlv_free_all(parsed_tlv); + ABTS_INT_EQUAL(tc, ogs_tlv_pool_avail(), ogs_core()->tlv.pool); + + return; +} + +#if 0 +/* Sample header for tlv_msg */ +#define TLV_AUTHORIZATION_POLICY_SUPPORT_TYPE 21 +#define TLV_AUTHORIZATION_POLICY_SUPPORT_LEN 1 +typedef tlv_uint8_t tlv_authorization_policy_support_t; +extern tlv_desc_t tlv_desc_authorization_policy_support; + +#define TLV_CLIENT_SECURITY_HISTORY_TYPE 108 +#define TLV_CLIENT_SECURITY_HISTORY_LEN TLV_VARIABLE_LEN +typedef struct _tlv_client_security_history_t { + tlv_presence_t presence; + tlv_authorization_policy_support_t authorization_policy_support0; + tlv_authorization_policy_support_t authorization_policy_support2; +} tlv_client_security_history_t; +extern tlv_desc_t tlv_desc_client_security_history; + +#define TLV_CLIENT_INFO_TYPE 103 +#define TLV_CLIENT_INFO_LEN TLV_VARIABLE_LEN +typedef struct _tlv_client_info_t { + tlv_presence_t presence; + tlv_client_security_history_t client_security_history; +} tlv_client_info_t; +extern tlv_desc_t tlv_desc_client_info; + +#define TLV_SERVER_NAME_TYPE 25 +#define TLV_SERVER_NAME_LEN TLV_VARIABLE_LEN +typedef tlv_octet_t tlv_server_name_t; +extern tlv_desc_t tlv_desc_server_name; + +#define TLV_SERVER_INFO_TYPE 26 +#define TLV_SERVER_INFO_LEN TLV_VARIABLE_LEN +typedef struct _tlv_server_info_t { + tlv_presence_t presence; + tlv_server_name_t TLV_1_OR_MORE(server_name); +} tlv_server_info_t; +extern tlv_desc_t tlv_desc_server_info; + +typedef struct _tlv_attach_req { + tlv_client_info_t client_info; + tlv_server_info_t server_info; +} tlv_attach_req; + +extern tlv_desc_t tlv_desc_attach_req; + +/* Sample source for tlv_msg */ +tlv_desc_t tlv_desc_authorization_policy_support0 = +{ + TLV_UINT8, + "Auth Policy0", + TLV_AUTHORIZATION_POLICY_SUPPORT_TYPE, + TLV_AUTHORIZATION_POLICY_SUPPORT_LEN, + 0, + sizeof(tlv_authorization_policy_support_t), + { NULL } +}; +tlv_desc_t tlv_desc_authorization_policy_support2 = +{ + TLV_UINT8, + "Auth Policy2", + TLV_AUTHORIZATION_POLICY_SUPPORT_TYPE, + TLV_AUTHORIZATION_POLICY_SUPPORT_LEN, + 2, + sizeof(tlv_authorization_policy_support_t), + { NULL } +}; + +tlv_desc_t tlv_desc_client_security_history = +{ + TLV_COMPOUND, + "Sec History", + TLV_CLIENT_SECURITY_HISTORY_TYPE, + TLV_CLIENT_SECURITY_HISTORY_LEN, + 0, + sizeof(tlv_client_security_history_t), + { + &tlv_desc_authorization_policy_support0, + &tlv_desc_authorization_policy_support2, + NULL, + } +}; + +tlv_desc_t tlv_desc_client_info = +{ + TLV_COMPOUND, + "Client Info", + TLV_CLIENT_INFO_TYPE, + TLV_CLIENT_INFO_LEN, + 0, + sizeof(tlv_client_info_t), + { + &tlv_desc_client_security_history, + NULL, + } +}; + +tlv_desc_t tlv_desc_server_name = +{ + TLV_VAR_STR, + "Server Name", + TLV_SERVER_NAME_TYPE, + TLV_SERVER_NAME_LEN, + 0, + sizeof(tlv_server_name_t), + { NULL } +}; + +tlv_desc_t tlv_desc_server_info = +{ + TLV_COMPOUND, + "Server Info", + TLV_SERVER_INFO_TYPE, + TLV_SERVER_INFO_LEN, + 0, + sizeof(tlv_server_info_t), + { + &tlv_desc_server_name, &tlv_desc_more2, + NULL, + } +}; + +tlv_desc_t tlv_desc_attach_req = { + TLV_MESSAGE, "Attach Req", 0, 0, 0, 0, { + &tlv_desc_client_info, + &tlv_desc_server_info, + NULL, +}}; + +static void test6_func(abts_case *tc, void *data) +{ + tlv_attach_req reqv; + tlv_attach_req reqv2; + + pkbuf_t *req = NULL; + char testbuf[1024]; + + /* Initialize message value structure */ + memset(&reqv, 0, sizeof(tlv_attach_req)); + + /* Set nessary members of message */ + reqv.client_info.presence = 1; + reqv.client_info.client_security_history.presence = 1; + reqv.client_info.client_security_history. + authorization_policy_support0.presence = 1; + reqv.client_info.client_security_history. + authorization_policy_support0.u8 = 0x3; + reqv.client_info.client_security_history. + authorization_policy_support2.presence = 1; + reqv.client_info.client_security_history. + authorization_policy_support2.u8 = 0x9; + + reqv.server_info.presence = 1; + reqv.server_info.server_name[0].presence = 1; + reqv.server_info.server_name[0].data = + (uint8_t*)"\x11\x22\x33\x44\x55\x66"; + reqv.server_info.server_name[0].len = 6; + + reqv.server_info.presence = 1; + reqv.server_info.server_name[1].presence = 1; + reqv.server_info.server_name[1].data = + (uint8_t*)"\xaa\xbb\xcc\xdd\xee\xff"; + reqv.server_info.server_name[1].len = 6; + + /* Build message */ + tlv_build_msg(&req, &tlv_desc_attach_req, &reqv, OGS_TLV_MODE_T1_L2_I1); +#define TEST_TLV_BUILD_MSG \ + "67000e00 6c000a00 15000100 03150001" \ + "02091a00 14001900 06001122 33445566" \ + "19000600 aabbccdd eeff" + + ABTS_INT_EQUAL(tc, 42, req->len); + ABTS_TRUE(tc, memcmp(req->payload, + CORE_HEX(TEST_TLV_BUILD_MSG, strlen(TEST_TLV_BUILD_MSG), testbuf), + req->len) == 0); + + /* Initialize message value structure */ + memset(&reqv2, 0, sizeof(tlv_attach_req)); + + /* Parse message */ + tlv_parse_msg(&reqv2, &tlv_desc_attach_req, req, + OGS_TLV_MODE_T1_L2_I1); + + ABTS_INT_EQUAL(tc, 1, reqv2.client_info.presence); + ABTS_INT_EQUAL(tc, 1, + reqv2.client_info.client_security_history.presence); + ABTS_INT_EQUAL(tc, 1, + reqv2.client_info.client_security_history. + authorization_policy_support0.presence); + ABTS_INT_EQUAL(tc, 0x3, reqv2.client_info. + client_security_history.authorization_policy_support0.u8); + ABTS_INT_EQUAL(tc, 1, + reqv2.client_info.client_security_history. + authorization_policy_support2.presence); + ABTS_INT_EQUAL(tc, 0x9, reqv2.client_info. + client_security_history.authorization_policy_support2.u8); + + ABTS_INT_EQUAL(tc, 1, reqv2.server_info.presence); + ABTS_INT_EQUAL(tc, 1, reqv2.server_info.server_name[0].presence); + ABTS_INT_EQUAL(tc, 1, reqv2.server_info.server_name[1].presence); + ABTS_INT_EQUAL(tc, 6, reqv2.server_info.server_name[0].len); + ABTS_TRUE(tc, memcmp(reqv2.server_info.server_name[0].data, + (uint8_t*)"\x11\x22\x33\x44\x55\x66", 6) == 0); + ABTS_INT_EQUAL(tc, 6, reqv2.server_info.server_name[1].len); + ABTS_TRUE(tc, memcmp(reqv2.server_info.server_name[1].data, + (uint8_t*)"\xaa\xbb\xcc\xdd\xee\xff", 6) == 0); + + pkbuf_free(req); +} +#endif + +abts_suite *test_tlv(abts_suite *suite) +{ + suite = ADD_SUITE(suite) + + abts_run_test(suite, test1_func, (void*)OGS_TLV_MODE_T2_L2); + abts_run_test(suite, test2_func, (void*)OGS_TLV_MODE_T2_L2); + abts_run_test(suite, test3_func, (void*)OGS_TLV_MODE_T2_L2); + abts_run_test(suite, test4_func, (void*)OGS_TLV_MODE_T2_L2); + abts_run_test(suite, test5_func, (void*)OGS_TLV_MODE_T2_L2); + abts_run_test(suite, test1_func, (void*)OGS_TLV_MODE_T1_L1); + abts_run_test(suite, test5_func, (void*)OGS_TLV_MODE_T1_L1); + abts_run_test(suite, test1_func, (void*)OGS_TLV_MODE_T1_L2); + abts_run_test(suite, test2_func, (void*)OGS_TLV_MODE_T1_L2); + abts_run_test(suite, test3_func, (void*)OGS_TLV_MODE_T1_L2); + abts_run_test(suite, test4_func, (void*)OGS_TLV_MODE_T1_L2); + abts_run_test(suite, test5_func, (void*)OGS_TLV_MODE_T1_L2); + abts_run_test(suite, test1_func, (void*)OGS_TLV_MODE_T1_L2_I1); + abts_run_test(suite, test2_func, (void*)OGS_TLV_MODE_T1_L2_I1); + abts_run_test(suite, test3_func, (void*)OGS_TLV_MODE_T1_L2_I1); + abts_run_test(suite, test4_func, (void*)OGS_TLV_MODE_T1_L2_I1); + abts_run_test(suite, test5_func, (void*)OGS_TLV_MODE_T1_L2_I1); + +#if 0 + abts_run_test(suite, test6_func, NULL); +#endif + + return suite; +} diff --git a/tests/crypt/abts-main.c b/tests/crypt/abts-main.c new file mode 100644 index 000000000..fd54230b4 --- /dev/null +++ b/tests/crypt/abts-main.c @@ -0,0 +1,87 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "ogs-core.h" +#include "ogs-crypt.h" +#include "core/abts.h" + +abts_suite *test_aes(abts_suite *suite); +abts_suite *test_sha(abts_suite *suite); + +const struct testlist { + abts_suite *(*func)(abts_suite *suite); +} alltests[] = { + {test_aes}, + {test_sha}, + {NULL}, +}; + +static void terminate(void) +{ + ogs_pkbuf_default_destroy(); + ogs_core_terminate(); +} + +int main(int argc, const char *const argv[]) +{ + int rv, i, opt; + ogs_getopt_t options; + struct { + char *log_level; + char *domain_mask; + } optarg; + const char *argv_out[argc+2]; /* '-e error' is always added */ + + abts_suite *suite = NULL; + ogs_pkbuf_config_t config; + + rv = abts_main(argc, argv, argv_out); + if (rv != OGS_OK) return rv; + + memset(&optarg, 0, sizeof(optarg)); + ogs_getopt_init(&options, (char**)argv_out); + + while ((opt = ogs_getopt(&options, "e:m:")) != -1) { + switch (opt) { + case 'e': + optarg.log_level = options.optarg; + break; + case 'm': + optarg.domain_mask = options.optarg; + break; + case '?': + default: + fprintf(stderr, "%s: should not be reached\n", OGS_FUNC); + return OGS_ERROR; + } + } + + ogs_core_initialize(); + ogs_pkbuf_default_init(&config); + ogs_pkbuf_default_create(&config); + atexit(terminate); + + rv = ogs_log_config_domain(optarg.domain_mask, optarg.log_level); + if (rv != OGS_OK) return rv; + + for (i = 0; alltests[i].func; i++) + suite = alltests[i].func(suite); + + return abts_report(suite); +} diff --git a/tests/crypt/aes-test.c b/tests/crypt/aes-test.c new file mode 100644 index 000000000..a7cbce734 --- /dev/null +++ b/tests/crypt/aes-test.c @@ -0,0 +1,410 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "ogs-core.h" +#include "ogs-crypt.h" +#include "core/abts.h" + +typedef struct { + unsigned char *key; + unsigned int *rk; + int key_bits; + unsigned char input[16]; + unsigned char cipher_output[16]; + unsigned char decipher_output[16]; +} aes_test_vector_t; + +static void aes_test1(abts_case *tc, void *data) +{ + const int key_bits = 128; + unsigned int rk[OGS_AES_RKLENGTH(128)]; + unsigned char key[16] = + "\x00\x01\x02\x03\x05\x06\x07\x08\x0A\x0B\x0C\x0D\x0F\x10\x11\x12"; + unsigned char pt[16] = "\x50\x68\x12\xA4\x5F\x08\xC8\x89\xB9\x7F\x59\x80\x03\x8B\x83\x59"; + unsigned char ct[16]; + unsigned char expected[16] = + "\xD8\xF5\x32\x53\x82\x89\xEF\x7D\x06\xB5\x06\xA4\xFD\x5B\xE9\xC9"; + int nrounds; + int rc; + + nrounds = ogs_aes_setup_enc(rk, key, key_bits); + ogs_aes_encrypt(rk ,nrounds, pt, ct); + + rc = memcmp(ct, expected, 16); + + ABTS_INT_EQUAL(tc, 0, rc); +} + +static void aes_test2(abts_case *tc, void *data) +{ + unsigned char tmp[16]; + int nrounds; + int rc; + aes_test_vector_t test_vector[3]; + int i; + + + test_vector[0].key_bits = 128; + test_vector[0].key = + ogs_malloc(sizeof(char)*OGS_AES_KEYLENGTH(test_vector[0].key_bits)); + test_vector[0].rk = + ogs_malloc(sizeof(unsigned int)*OGS_AES_RKLENGTH(test_vector[0].key_bits)); + memcpy(test_vector[0].key, + "\x95\xA8\xEE\x8E\x89\x97\x9B\x9E" + "\xFD\xCB\xC6\xEB\x97\x97\x52\x8D", + OGS_AES_KEYLENGTH(test_vector[0].key_bits)); + memcpy(test_vector[0].input, + "\x4E\xC1\x37\xA4\x26\xDA\xBF\x8A" + "\xA0\xBE\xB8\xBC\x0C\x2B\x89\xD6", + 16); + memcpy(test_vector[0].cipher_output, + "\xD9\xB6\x5D\x12\x32\xBA\x01\x99" + "\xCD\xBD\x48\x7B\x2A\x1F\xD6\x46", + 16); + memcpy(test_vector[0].decipher_output, + "\x95\x70\xC3\x43\x63\x56\x5B\x39" + "\x35\x03\xA0\x01\xC0\xE2\x3B\x65", + 16); + + test_vector[1].key_bits = 192; + test_vector[1].key = + ogs_malloc(sizeof(char)*OGS_AES_KEYLENGTH(test_vector[1].key_bits)); + test_vector[1].rk = + ogs_malloc(sizeof(unsigned int)*OGS_AES_RKLENGTH(test_vector[1].key_bits)); + memcpy(test_vector[1].key, + "\x95\xA8\xEE\x8E\x89\x97\x9B\x9E" + "\xFD\xCB\xC6\xEB\x97\x97\x52\x8D" + "\x43\x2D\xC2\x60\x61\x55\x38\x18", + OGS_AES_KEYLENGTH(test_vector[1].key_bits)); + memcpy(test_vector[1].input , + "\x4E\xC1\x37\xA4\x26\xDA\xBF\x8A" + "\xA0\xBE\xB8\xBC\x0C\x2B\x89\xD6", + 16); + memcpy(test_vector[1].cipher_output, + "\xB1\x8B\xB3\xE7\xE1\x07\x32\xBE" + "\x13\x58\x44\x3A\x50\x4D\xBB\x49", + 16); + memcpy(test_vector[1].decipher_output, + "\x29\xDF\xD7\x5B\x85\xCE\xE4\xDE" + "\x6E\x26\xA8\x08\xCD\xC2\xC9\xC3", + 16); + + test_vector[2].key_bits = 256; + test_vector[2].key = + ogs_malloc(sizeof(char)*OGS_AES_KEYLENGTH(test_vector[2].key_bits)); + test_vector[2].rk = + ogs_malloc(sizeof(unsigned int)*OGS_AES_RKLENGTH(test_vector[2].key_bits)); + memcpy(test_vector[2].key, + "\x95\xA8\xEE\x8E\x89\x97\x9B\x9E" + "\xFD\xCB\xC6\xEB\x97\x97\x52\x8D" + "\x43\x2D\xC2\x60\x61\x55\x38\x18" + "\xEA\x63\x5E\xC5\xD5\xA7\x72\x7E", + OGS_AES_KEYLENGTH(test_vector[2].key_bits)); + memcpy(test_vector[2].input , + "\x4E\xC1\x37\xA4\x26\xDA\xBF\x8A" + "\xA0\xBE\xB8\xBC\x0C\x2B\x89\xD6", + 16); + memcpy(test_vector[2].cipher_output, + "\x2F\x9C\xFD\xDB\xFF\xCD\xE6\xB9" + "\xF3\x7E\xF8\xE4\x0D\x51\x2C\xF4", + 16); + memcpy(test_vector[2].decipher_output, + "\x11\x0A\x35\x45\xCE\x49\xB8\x4B" + "\xBB\x7B\x35\x23\x61\x08\xFA\x6E", + 16); + + for (i=0; i<3; i++) + { + nrounds = ogs_aes_setup_enc(test_vector[i].rk, test_vector[i].key, + test_vector[i].key_bits); + ogs_aes_encrypt(test_vector[i].rk ,nrounds, test_vector[i].input, tmp); + + rc = memcmp(tmp, test_vector[i].cipher_output, 16); + ABTS_INT_EQUAL(tc, 0, rc); + + nrounds = ogs_aes_setup_dec(test_vector[i].rk, test_vector[i].key, + test_vector[i].key_bits); + ogs_aes_decrypt(test_vector[i].rk ,nrounds, test_vector[i].input, tmp); + rc = memcmp(tmp, test_vector[i].decipher_output, 16); + ABTS_INT_EQUAL(tc, 0, rc); + + ogs_free(test_vector[i].key); + ogs_free(test_vector[i].rk); + } +} + +#if 0 + Case #1: Encrypting 16 bytes (1 block) using AES-CBC with 128-bit key + Key : 0x06a9214036b8a15b512e03d534120006 + IV : 0x3dafba429d9eb430b422da802c9fac41 + Plaintext : "Single block msg" + Ciphertext: 0xe353779c1079aeb82708942dbe77181a + + Case #2: Encrypting 32 bytes (2 blocks) using AES-CBC with 128-bit key + Key : 0xc286696d887c9aa0611bbb3e2025a45a + IV : 0x562e17996d093d28ddb3ba695a2e6f58 + Plaintext : 0x000102030405060708090a0b0c0d0e0f + 101112131415161718191a1b1c1d1e1f + Ciphertext: 0xd296cd94c2cccf8a3a863028b5e1dc0a + 7586602d253cfff91b8266bea6d61ab1 + + Case #3: Encrypting 48 bytes (3 blocks) using AES-CBC with 128-bit key + Key : 0x6c3ea0477630ce21a2ce334aa746c2cd + IV : 0xc782dc4c098c66cbd9cd27d825682c81 + Plaintext : "This is a 48-byte message (exactly 3 AES blocks)" + Ciphertext: 0xd0a02b3836451753d493665d33f0e886 + 2dea54cdb293abc7506939276772f8d5 + 021c19216bad525c8579695d83ba2684 + + Case #4: Encrypting 64 bytes (4 blocks) using AES-CBC with 128-bit key + Key : 0x56e47a38c5598974bc46903dba290349 + IV : 0x8ce82eefbea0da3c44699ed7db51b7d9 + Plaintext : 0xa0a1a2a3a4a5a6a7a8a9aaabacadaeaf + b0b1b2b3b4b5b6b7b8b9babbbcbdbebf + c0c1c2c3c4c5c6c7c8c9cacbcccdcecf + d0d1d2d3d4d5d6d7d8d9dadbdcdddedf + Ciphertext: 0xc30e32ffedc0774e6aff6af0869f71aa + 0f3af07a9a31a9c684db207eb0ef8e4e + 35907aa632c3ffdf868bb7b29d3d46ad + 83ce9f9a102ee99d49a53e87f4c3da55 +#endif + +typedef struct { + unsigned char key[33]; + int key_bits; + unsigned char ivec[33]; + unsigned char plain[65]; + unsigned int plainlen; + unsigned char cipher[65]; + unsigned int cipherlen; +} aes_cbc_test_vector_t; + +static void aes_test3(abts_case *tc, void *data) +{ + aes_cbc_test_vector_t tv[5] = { + { + "\x06\xa9\x21\x40\x36\xb8\xa1\x5b\x51\x2e\x03\xd5\x34\x12\x00\x06", + 128, + "\x3d\xaf\xba\x42\x9d\x9e\xb4\x30\xb4\x22\xda\x80\x2c\x9f\xac\x41", + "Single block msg", + 16, + "\xe3\x53\x77\x9c\x10\x79\xae\xb8\x27\x08\x94\x2d\xbe\x77\x18\x1a", + 16 + }, { + "\xc2\x86\x69\x6d\x88\x7c\x9a\xa0\x61\x1b\xbb\x3e\x20\x25\xa4\x5a", + 128, + "\x56\x2e\x17\x99\x6d\x09\x3d\x28\xdd\xb3\xba\x69\x5a\x2e\x6f\x58", + "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f" + "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f", + 32, + "\xd2\x96\xcd\x94\xc2\xcc\xcf\x8a\x3a\x86\x30\x28\xb5\xe1\xdc\x0a" + "\x75\x86\x60\x2d\x25\x3c\xff\xf9\x1b\x82\x66\xbe\xa6\xd6\x1a\xb1", + 32 + }, { + + "\x6c\x3e\xa0\x47\x76\x30\xce\x21\xa2\xce\x33\x4a\xa7\x46\xc2\xcd", + 128, + "\xc7\x82\xdc\x4c\x09\x8c\x66\xcb\xd9\xcd\x27\xd8\x25\x68\x2c\x81", + "This is a 48-byte message (exactly 3 AES blocks)", + 48, + "\xd0\xa0\x2b\x38\x36\x45\x17\x53\xd4\x93\x66\x5d\x33\xf0\xe8\x86" + "\x2d\xea\x54\xcd\xb2\x93\xab\xc7\x50\x69\x39\x27\x67\x72\xf8\xd5" + "\x02\x1c\x19\x21\x6b\xad\x52\x5c\x85\x79\x69\x5d\x83\xba\x26\x84", + 48 + }, { + "\x56\xe4\x7a\x38\xc5\x59\x89\x74\xbc\x46\x90\x3d\xba\x29\x03\x49", + 128, + "\x8c\xe8\x2e\xef\xbe\xa0\xda\x3c\x44\x69\x9e\xd7\xdb\x51\xb7\xd9", + "\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf" + "\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf" + "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf" + "\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf", + 64, + "\xc3\x0e\x32\xff\xed\xc0\x77\x4e\x6a\xff\x6a\xf0\x86\x9f\x71\xaa" + "\x0f\x3a\xf0\x7a\x9a\x31\xa9\xc6\x84\xdb\x20\x7e\xb0\xef\x8e\x4e" + "\x35\x90\x7a\xa6\x32\xc3\xff\xdf\x86\x8b\xb7\xb2\x9d\x3d\x46\xad" + "\x83\xce\x9f\x9a\x10\x2e\xe9\x9d\x49\xa5\x3e\x87\xf4\xc3\xda\x55", + 64 + }, { + "\x56\xe4\x7a\x38\xc5\x59\x89\x74\xbc\x46\x90\x3d\xba\x29\x03\x49", + 128, + "\x8c\xe8\x2e\xef\xbe\xa0\xda\x3c\x44\x69\x9e\xd7\xdb\x51\xb7\xd9", + "\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf" + "\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf" + "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf" + "\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd", + 62, + "\xc3\x0e\x32\xff\xed\xc0\x77\x4e\x6a\xff\x6a\xf0\x86\x9f\x71\xaa" + "\x0f\x3a\xf0\x7a\x9a\x31\xa9\xc6\x84\xdb\x20\x7e\xb0\xef\x8e\x4e" + "\x35\x90\x7a\xa6\x32\xc3\xff\xdf\x86\x8b\xb7\xb2\x9d\x3d\x46\xad" + "\x5d\x96\x74\x07\xe9\x86\x0c\x0b\x50\x80\x4a\xfb\x69\xc1\x13\xaa", + 64 + } + }; + + unsigned char out[128]; + unsigned int i, rc, outlen; + uint8_t ivec[32]; + + for (i = 0; i < 5; i++) + { + outlen = sizeof(out); + memcpy(ivec, tv[i].ivec, 16); + ogs_aes_cbc_encrypt(tv[i].key, tv[i].key_bits, ivec, + tv[i].plain, tv[i].plainlen, out, &outlen); + ABTS_INT_EQUAL(tc, tv[i].cipherlen, outlen); + rc = memcmp(tv[i].cipher, out, tv[i].cipherlen); + ABTS_INT_EQUAL(tc, 0, rc); + + outlen = sizeof(out); + memcpy(ivec, tv[i].ivec, 16); + ogs_aes_cbc_decrypt(tv[i].key, tv[i].key_bits, ivec, + tv[i].cipher, tv[i].cipherlen, out, &outlen); + ABTS_INT_EQUAL(tc, tv[i].cipherlen, outlen); + rc = memcmp(tv[i].plain, out, tv[i].plainlen); + ABTS_INT_EQUAL(tc, 0, rc); + } +} + +/* RFC 4493 + + -------------------------------------------------- + Subkey Generation + K 2b7e1516 28aed2a6 abf71588 09cf4f3c + AES-128(key,0) 7df76b0c 1ab899b3 3e42f047 b91b546f + K1 fbeed618 35713366 7c85e08f 7236a8de + K2 f7ddac30 6ae266cc f90bc11e e46d513b + -------------------------------------------------- + + -------------------------------------------------- + Example 1: len = 0 + M + AES-CMAC bb1d6929 e9593728 7fa37d12 9b756746 + -------------------------------------------------- + + Example 2: len = 16 + M 6bc1bee2 2e409f96 e93d7e11 7393172a + AES-CMAC 070a16b4 6b4d4144 f79bdd9d d04a287c + -------------------------------------------------- + + Example 3: len = 40 + M 6bc1bee2 2e409f96 e93d7e11 7393172a + ae2d8a57 1e03ac9c 9eb76fac 45af8e51 + 30c81c46 a35ce411 + AES-CMAC dfa66747 de9ae630 30ca3261 1497c827 + -------------------------------------------------- + + Example 4: len = 64 + M 6bc1bee2 2e409f96 e93d7e11 7393172a + ae2d8a57 1e03ac9c 9eb76fac 45af8e51 + 30c81c46 a35ce411 e5fbc119 1a0a52ef + f69f2445 df4f9b17 ad2b417b e66c3710 + AES-CMAC 51f0bebf 7e3b9d92 fc497417 79363cfe + -------------------------------------------------- +*/ + +static void cmac_test(abts_case *tc, void *data) +{ + uint8_t key[16] = { + 0x2b,0x7e,0x15,0x16,0x28,0xae,0xd2,0xa6, + 0xab,0xf7,0x15,0x88,0x09,0xcf,0x4f,0x3c + }; + + uint8_t msg[4][64] = { + { + /* Empty string */ + }, + { + 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96, + 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a + }, { + 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96, + 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a, + 0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c, + 0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51, + 0x30,0xc8,0x1c,0x46,0xa3,0x5c,0xe4,0x11 + }, { + 0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96, + 0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a, + 0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c, + 0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51, + 0x30,0xc8,0x1c,0x46,0xa3,0x5c,0xe4,0x11, + 0xe5,0xfb,0xc1,0x19,0x1a,0x0a,0x52,0xef, + 0xf6,0x9f,0x24,0x45,0xdf,0x4f,0x9b,0x17, + 0xad,0x2b,0x41,0x7b,0xe6,0x6c,0x37,0x10 + } + }; + + uint32_t msglen[4] = {0, 16, 40, 64}; + + uint8_t cmac_answer[4][16] = { + { + 0xbb,0x1d,0x69,0x29,0xe9,0x59,0x37,0x28, + 0x7f,0xa3,0x7d,0x12,0x9b,0x75,0x67,0x46 + }, { + 0x07,0x0a,0x16,0xb4,0x6b,0x4d,0x41,0x44, + 0xf7,0x9b,0xdd,0x9d,0xd0,0x4a,0x28,0x7c + }, { + 0xdf,0xa6,0x67,0x47,0xde,0x9a,0xe6,0x30, + 0x30,0xca,0x32,0x61,0x14,0x97,0xc8,0x27 + }, { + 0x51,0xf0,0xbe,0xbf,0x7e,0x3b,0x9d,0x92, + 0xfc,0x49,0x74,0x17,0x79,0x36,0x3c,0xfe + } + }; + + uint8_t cmac[16]; + + int i, rc; + int rv; + + for (i = 0; i < 4; i++) + { + rv = ogs_aes_cmac_calculate(cmac, key, msg[i], msglen[i]); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + + rc = memcmp(cmac, cmac_answer[i], 16); + ABTS_INT_EQUAL(tc, 0, rc); + } + + for (i = 0; i < 4; i++) + { + rv = ogs_aes_cmac_verify(cmac_answer[i], key, msg[i], msglen[i]); + ABTS_INT_EQUAL(tc, OGS_OK, rv); + } + + key[0] = 0; + for (i = 0; i < 4; i++) + { + rv = ogs_aes_cmac_verify(cmac_answer[i], key, msg[i], msglen[i]); + ABTS_INT_EQUAL(tc, OGS_ERR_INVALID_CMAC, rv); + } +} + +abts_suite *test_aes(abts_suite *suite) +{ + suite = ADD_SUITE(suite) + + abts_run_test(suite, aes_test1, NULL); + abts_run_test(suite, aes_test2, NULL); + abts_run_test(suite, aes_test3, NULL); + abts_run_test(suite, cmac_test, NULL); + + return suite; +} diff --git a/lib/nas/Makefile.am b/tests/crypt/meson.build similarity index 68% rename from lib/nas/Makefile.am rename to tests/crypt/meson.build index 2a413a059..70fca9f9f 100644 --- a/lib/nas/Makefile.am +++ b/tests/crypt/meson.build @@ -15,23 +15,15 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -pkglib_LTLIBRARIES = libogsnas.la +testcrypt_sources = files(''' + aes-test.c + sha-test.c + abts-main.c +'''.split()) -libogsnas_la_SOURCES = \ - ies.h ies.c types.h types.c conv.h conv.c \ - message.h decoder.c encoder.c \ - $(NULL) +testcrypt_exe = executable('crypt', + sources : testcrypt_sources, + c_args : testcore_cc_flags, + dependencies : libcrypt_dep) -libogsnas_la_LIBADD = \ - @OGSCORE_LIBS@ \ - $(NULL) - -AM_CPPFLAGS = \ - @OGSCORE_CFLAGS@ \ - -I$(top_srcdir)/lib \ - $(NULL) - -AM_CFLAGS = \ - -DOGS_NAS_COMPILATION \ - -Wall -Werror \ - $(NULL) +test('crypt', testcrypt_exe, is_parallel : false, suite: 'unit') diff --git a/tests/crypt/sha-test.c b/tests/crypt/sha-test.c new file mode 100644 index 000000000..08f4f1a6f --- /dev/null +++ b/tests/crypt/sha-test.c @@ -0,0 +1,181 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "ogs-crypt.h" +#include "core/abts.h" + +static void sha1_test1(abts_case *tc, void *data) +{ + uint8_t msg1[] = "abc"; + uint8_t msg2[] = "abcdbcdecdefdefgefghfghighij" + "hijkijkljklmklmnlmnomnopnopq"; + + uint8_t digest1[] = { + 0xa9,0x99,0x3e,0x36,0x47,0x06,0x81,0x6a, + 0xba,0x3e,0x25,0x71,0x78,0x50,0xc2,0x6c, + 0x9c,0xd0,0xd8,0x9d + }; + uint8_t digest2[] = { + 0x84,0x98,0x3e,0x44,0x1c,0x3b,0xd2,0x6e, + 0xba,0xae,0x4a,0xa1,0xf9,0x51,0x29,0xe5, + 0xe5,0x46,0x70,0xf1 + }; + uint8_t digest3[] = { + 0x34,0xaa,0x97,0x3c,0xd4,0xc4,0xda,0xa4, + 0xf6,0x1e,0xeb,0x2b,0xdb,0xad,0x27,0x31, + 0x65,0x34,0x01,0x6f, + }; + + uint8_t digest[20]; + int i; + + ogs_sha1_ctx ctx; + + ogs_sha1_init(&ctx); + ogs_sha1_update(&ctx, msg1, sizeof(msg1) - 1); + ogs_sha1_final(&ctx, digest); + ABTS_INT_EQUAL(tc, 0, memcmp(digest1, digest, 20)); + + ogs_sha1_init(&ctx); + ogs_sha1_update(&ctx, msg2, sizeof(msg2) - 1); + ogs_sha1_final(&ctx, digest); + ABTS_INT_EQUAL(tc, 0, memcmp(digest2, digest, 20)); + + ogs_sha1_init(&ctx); + for (i = 0; i < 1000000; i++) + ogs_sha1_update(&ctx, (uint8_t*)"a", 1); + ogs_sha1_final(&ctx, digest); + ABTS_INT_EQUAL(tc, 0, memcmp(digest3, digest, 20)); + +} + +static void sha2_test1(abts_case *tc, void *data) +{ + const char *vectors[4][3] = + { /* SHA-224 */ + { + "\x23\x09\x7d\x22\x34\x05\xd8\x22\x86\x42\xa4\x77\xbd\xa2\x55\xb3\x2a\xad\xbc\xe4\xbd\xa0\xb3\xf7\xe3\x6c\x9d\xa7", + "\x75\x38\x8b\x16\x51\x27\x76\xcc\x5d\xba\x5d\xa1\xfd\x89\x01\x50\xb0\xc6\x45\x5c\xb4\xf5\x8b\x19\x52\x52\x25\x25", + "\x20\x79\x46\x55\x98\x0c\x91\xd8\xbb\xb4\xc1\xea\x97\x61\x8a\x4b\xf0\x3f\x42\x58\x19\x48\xb2\xee\x4e\xe7\xad\x67", + }, + /* SHA-\x25\x6 */ + { + "\xba\x78\x16\xbf\x8f\x01\xcf\xea\x41\x41\x40\xde\x5d\xae\x22\x23\xb0\x03\x61\xa3\x96\x17\x7a\x9c\xb4\x10\xff\x61\xf2\x00\x15\xad", + "\x24\x8d\x6a\x61\xd2\x06\x38\xb8\xe5\xc0\x26\x93\x0c\x3e\x60\x39\xa3\x3c\xe4\x59\x64\xff\x21\x67\xf6\xec\xed\xd4\x19\xdb\x06\xc1", + "\xcd\xc7\x6e\x5c\x99\x14\xfb\x92\x81\xa1\xc7\xe2\x84\xd7\x3e\x67\xf1\x80\x9a\x48\xa4\x97\x20\x0e\x04\x6d\x39\xcc\xc7\x11\x2c\xd0", + }, + /* SHA-\x38\x4 */ + { + "\xcb\x00\x75\x3f\x45\xa3\x5e\x8b\xb5\xa0\x3d\x69\x9a\xc6\x50\x07\x27\x2c\x32\xab\x0e\xde\xd1\x63\x1a\x8b\x60\x5a\x43\xff\x5b\xed" + "\x80\x86\x07\x2b\xa1\xe7\xcc\x23\x58\xba\xec\xa1\x34\xc8\x25\xa7", + "\x09\x33\x0c\x33\xf7\x11\x47\xe8\x3d\x19\x2f\xc7\x82\xcd\x1b\x47\x53\x11\x1b\x17\x3b\x3b\x05\xd2\x2f\xa0\x80\x86\xe3\xb0\xf7\x12" + "\xfc\xc7\xc7\x1a\x55\x7e\x2d\xb9\x66\xc3\xe9\xfa\x91\x74\x60\x39", + "\x9d\x0e\x18\x09\x71\x64\x74\xcb\x08\x6e\x83\x4e\x31\x0a\x4a\x1c\xed\x14\x9e\x9c\x00\xf2\x48\x52\x79\x72\xce\xc5\x70\x4c\x2a\x5b" + "\x07\xb8\xb3\xdc\x38\xec\xc4\xeb\xae\x97\xdd\xd8\x7f\x3d\x89\x85", + }, + /* SHA-\x51\x2 */ + { + "\xdd\xaf\x35\xa1\x93\x61\x7a\xba\xcc\x41\x73\x49\xae\x20\x41\x31\x12\xe6\xfa\x4e\x89\xa9\x7e\xa2\x0a\x9e\xee\xe6\x4b\x55\xd3\x9a" + "\x21\x92\x99\x2a\x27\x4f\xc1\xa8\x36\xba\x3c\x23\xa3\xfe\xeb\xbd\x45\x4d\x44\x23\x64\x3c\xe8\x0e\x2a\x9a\xc9\x4f\xa5\x4c\xa4\x9f", + "\x8e\x95\x9b\x75\xda\xe3\x13\xda\x8c\xf4\xf7\x28\x14\xfc\x14\x3f\x8f\x77\x79\xc6\xeb\x9f\x7f\xa1\x72\x99\xae\xad\xb6\x88\x90\x18" + "\x50\x1d\x28\x9e\x49\x00\xf7\xe4\x33\x1b\x99\xde\xc4\xb5\x43\x3a\xc7\xd3\x29\xee\xb6\xdd\x26\x54\x5e\x96\xe5\x5b\x87\x4b\xe9\x09", + "\xe7\x18\x48\x3d\x0c\xe7\x69\x64\x4e\x2e\x42\xc7\xbc\x15\xb4\x63\x8e\x1f\x98\xb1\x3b\x20\x44\x28\x56\x32\xa8\x03\xaf\xa9\x73\xeb" + "\xde\x0f\xf2\x44\x87\x7e\xa6\x0a\x4c\xb0\x43\x2c\xe5\x77\xc3\x1b\xeb\x00\x9c\x5c\x2c\x49\xaa\x2e\x4e\xad\xb2\x17\xad\x8c\xc0\x9b" + } + }; + + char message1[] = "abc"; + char message2a[] = "abcdbcdecdefdefgefghfghighijhi" + "jkijkljklmklmnlmnomnopnopq"; + char message2b[] = "abcdefghbcdefghicdefghijdefghijkefghij" + "klfghijklmghijklmnhijklmnoijklmnopjklm" + "nopqklmnopqrlmnopqrsmnopqrstnopqrstu"; + unsigned char *message3; + unsigned int message3_len = 1000000; + unsigned char digest[OGS_SHA512_DIGEST_SIZE]; + int rc; + + message3 = malloc(message3_len); + if (message3 == NULL) { + fprintf(stderr, "Can't allocate memory\n"); + return; + } + memset(message3, 'a', message3_len); + + /* OGS_SHA-2 FIPS 180-2 Validation tests. + * OGS_SHA-224 Test vector */ + + ogs_sha224((uint8_t *)message1, strlen((char *) message1), digest); + rc = memcmp(vectors[0][0], digest, OGS_SHA224_DIGEST_SIZE); + ABTS_INT_EQUAL(tc, 0, rc); + ogs_sha224((uint8_t *)message2a, strlen((char *) message2a), digest); + rc = memcmp(vectors[0][1], digest, OGS_SHA224_DIGEST_SIZE); + ABTS_INT_EQUAL(tc, 0, rc); + ogs_sha224((uint8_t *)message3, message3_len, digest); + rc = memcmp(vectors[0][2], digest, OGS_SHA224_DIGEST_SIZE); + ABTS_INT_EQUAL(tc, 0, rc); + + /* OGS_SHA-256 Test vector */ + + ogs_sha256((uint8_t *)message1, strlen((char *) message1), digest); + rc = memcmp(vectors[1][0], digest, OGS_SHA256_DIGEST_SIZE); + ABTS_INT_EQUAL(tc, 0, rc); + ogs_sha256((uint8_t *)message2a, strlen((char *) message2a), digest); + rc = memcmp(vectors[1][1], digest, OGS_SHA256_DIGEST_SIZE); + ABTS_INT_EQUAL(tc, 0, rc); + ogs_sha256((uint8_t *)message3, message3_len, digest); + rc = memcmp(vectors[1][2], digest, OGS_SHA256_DIGEST_SIZE); + ABTS_INT_EQUAL(tc, 0, rc); + + /* OGS_SHA-384 Test vector */ + + ogs_sha384((uint8_t *)message1, strlen((char *) message1), digest); + rc = memcmp(vectors[2][0], digest, OGS_SHA384_DIGEST_SIZE); + ABTS_INT_EQUAL(tc, 0, rc); + ogs_sha384((uint8_t *)message2b, strlen((char *) message2b), digest); + rc = memcmp(vectors[2][1], digest, OGS_SHA384_DIGEST_SIZE); + ABTS_INT_EQUAL(tc, 0, rc); + ogs_sha384((uint8_t *)message3, message3_len, digest); + rc = memcmp(vectors[2][2], digest, OGS_SHA384_DIGEST_SIZE); + ABTS_INT_EQUAL(tc, 0, rc); + + /* OGS_SHA-512 Test vector */ + ogs_sha512((uint8_t *)message1, strlen((char *) message1), digest); + rc = memcmp(vectors[3][0], digest, OGS_SHA512_DIGEST_SIZE); + ABTS_INT_EQUAL(tc, 0, rc); + ogs_sha512((uint8_t *)message2b, strlen((char *) message2b), digest); + rc = memcmp(vectors[3][1], digest, OGS_SHA512_DIGEST_SIZE); + ABTS_INT_EQUAL(tc, 0, rc); + ogs_sha512((uint8_t *)message3, message3_len, digest); + rc = memcmp(vectors[3][2], digest, OGS_SHA512_DIGEST_SIZE); + ABTS_INT_EQUAL(tc, 0, rc); + + free(message3); +} + + +abts_suite *test_sha(abts_suite *suite) +{ + suite = ADD_SUITE(suite) + + abts_run_test(suite, sha1_test1, NULL); + abts_run_test(suite, sha2_test1, NULL); + + return suite; +} diff --git a/tests/csfb/abts-main.c b/tests/csfb/abts-main.c index 3d5104bc6..942996701 100644 --- a/tests/csfb/abts-main.c +++ b/tests/csfb/abts-main.c @@ -50,7 +50,7 @@ static void terminate(void) { ogs_msleep(50); - epc_child_terminate(); + test_child_terminate(); ogs_info("MME try to terminate"); mme_terminate(); @@ -69,17 +69,17 @@ static void terminate(void) ogs_app_terminate(); } -static void initialize(char **argv) +static void initialize(const char *const argv[]) { int rv; rv = ogs_app_initialize(NULL, argv); ogs_assert(rv == OGS_OK); - pcrf_thread = epc_child_create("nextepc-pcrfd", argv); - pgw_thread = epc_child_create("nextepc-pgwd", argv); - sgw_thread = epc_child_create("nextepc-sgwd", argv); - hss_thread = epc_child_create("nextepc-hssd", argv); + pcrf_thread = test_child_create("pcrf", argv); + pgw_thread = test_child_create("pgw", argv); + sgw_thread = test_child_create("sgw", argv); + hss_thread = test_child_create("hss", argv); test_app_init(); ogs_sctp_init(ogs_config()->usrsctp.udp_port); @@ -92,13 +92,13 @@ static void initialize(char **argv) ogs_info("MME initialize...done"); } -int main(int argc, char **argv) +int main(int argc, const char *const argv[]) { int i; abts_suite *suite = NULL; atexit(terminate); - test_app_run(argc, argv, "sample-csfb.conf", initialize); + test_app_run(argc, argv, "csfb.yaml", initialize); for (i = 0; alltests[i].func; i++) suite = alltests[i].func(suite); diff --git a/lib/sctp/Makefile.am b/tests/csfb/meson.build similarity index 65% rename from lib/sctp/Makefile.am rename to tests/csfb/meson.build index e0281faf6..cab6fd7dd 100644 --- a/lib/sctp/Makefile.am +++ b/tests/csfb/meson.build @@ -15,28 +15,20 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -pkglib_LTLIBRARIES = libogssctp.la +testcsfb_sources = files(''' + abts-main.c + mo-idle-test.c + mt-idle-test.c + mo-active-test.c + mt-active-test.c + mo-sms-test.c + mt-sms-test.c + crash-test.c +'''.split()) -libogssctp_la_SOURCES = \ - ogs-sctp.h ogs-sctp.c \ - $(NULL) +testcsfb_exe = executable('csfb', + sources : testcsfb_sources, + c_args : testcore_cc_flags, + dependencies : libtestapp_dep) -if WITH_USRSCTP -libogssctp_la_SOURCES += ogs-usrsctp.c -else -libogssctp_la_SOURCES += ogs-lksctp.c -endif - -libogssctp_la_LIBADD = \ - @OGSCORE_LIBS@ \ - $(NULL) - -AM_CPPFLAGS = \ - @OGSCORE_CFLAGS@ \ - -I$(top_srcdir)/lib \ - $(NULL) - -AM_CFLAGS = \ - -DOGS_SCTP_COMPILATION \ - -Wall -Werror \ - $(NULL) +test('csfb', testcsfb_exe, is_parallel : false, suite: 'system') diff --git a/tests/csfb/mo-idle-test.c b/tests/csfb/mo-idle-test.c index 9a38c48cb..bd2b90d36 100644 --- a/tests/csfb/mo-idle-test.c +++ b/tests/csfb/mo-idle-test.c @@ -35,22 +35,22 @@ static void test1_func(abts_case *tc, void *data) uint32_t m_tmsi = 0; uint8_t tmp[OGS_MAX_SDU_LEN]; - char *_identity_request = + const char *_identity_request = "000b401700000300 0000020001000800 020001001a000403 075501"; - char *_authentication_request = + const char *_authentication_request = "000b403800000300 0000020001000800 020001001a002524 075200aa266700bc" "2887354e9f87368d 5d0ae710ab857af5 5f1a8000d71e5537 4ee176e9"; - char *_security_mode_command = + const char *_security_mode_command = "000b402400000300 0000020001000800 020001001a001110 378ccbca6000075d" "010005f0f0c04070"; - char *_esm_information_request = + const char *_esm_information_request = "000b401d00000300 0000020001000800 020001001a000a09 27d1237969010234" "d9"; - char *_sgsap_location_update_request = + const char *_sgsap_location_update_request = "0901082926240000 1118930937066d6d 65633031096d6d65 676930303032036d" "6d6503657063066d 6e63303730066d63 633930310b336770 706e6574776f726b" "036f72670a010104 0509f1070926"; - char *_initial_context_setup_request = + const char *_initial_context_setup_request = "00090080d7000006 0000000200010008 000200010042000a 183d090000603d09" "0000001800808800 0034008082450009 230f807f00000200 0000017327283f4c" "6102074202490620 09f1070007004152 34c101090908696e 7465726e65740501" @@ -58,10 +58,10 @@ static void test1_func(abts_case *tc, void *data) "0404000d04080808 08000d0408080404 500bf609f1070002 01d20064c31309f1" "0709262305f49ee8 8e64594964010100 6b00051c000e0000 00490020f9f4f80b" "206c33ae286c6daf f4c253585174c3a0 a12a661967f5e1ba 0a686c8c"; - char *_emm_information = + const char *_emm_information = "000b403800000300 0000020001000800 020001001a002524 2751034124030761" - "430f10004e006500 7800740045005000 4347916051216124 63490100"; - char *_sgsap_tmsi_reallocation_complete = + "430f10004f007000 65006e0035004700 5347916051216124 63490100"; + const char *_sgsap_tmsi_reallocation_complete = "0c01082926240000 111893"; mongoc_collection_t *collection = NULL; diff --git a/src/epc.c b/tests/epc/app-init.c similarity index 50% rename from src/epc.c rename to tests/epc/app-init.c index 362868793..1f6d219e0 100644 --- a/src/epc.c +++ b/tests/epc/app-init.c @@ -1,25 +1,48 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + #include "ogs-sctp.h" -#include "ogs-app.h" + +#include "test-epc.h" +#include "test-config-private.h" + +#define MAX_CHILD_PROCESS 8 +#define OGS_ARG_MAX 256 static ogs_thread_t *pcrf_thread = NULL; static ogs_thread_t *pgw_thread = NULL; static ogs_thread_t *sgw_thread = NULL; static ogs_thread_t *hss_thread = NULL; -#define MAX_CHILD_PROCESS 8 static ogs_proc_t process[MAX_CHILD_PROCESS]; static int process_num = 0; static void child_main(void *data) { - char **commandLine = data; + const char **commandLine = data; ogs_proc_t *current = NULL; FILE *out = NULL; char buf[OGS_HUGE_LEN]; int ret = 0, out_return_code = 0;; current = &process[process_num++]; - ret = ogs_proc_create((const char *const*)commandLine, + ret = ogs_proc_create(commandLine, ogs_proc_option_combined_stdout_stderr| ogs_proc_option_inherit_environment, current); @@ -39,13 +62,11 @@ static void child_main(void *data) ogs_assert(ret == 0); } -ogs_thread_t *epc_child_create(char *name, char **argv) +ogs_thread_t *test_child_create(const char *name, const char *const argv[]) { ogs_thread_t *child = NULL; -#define OGS_ARG_MAX 256 - char *commandLine[OGS_ARG_MAX]; + const char *commandLine[OGS_ARG_MAX]; int i = 0; - char directory[OGS_MAX_FILEPATH_LEN]; char command[OGS_MAX_FILEPATH_LEN]; while(argv[i] && i < 32) { @@ -54,19 +75,19 @@ ogs_thread_t *epc_child_create(char *name, char **argv) } commandLine[i] = NULL; - ogs_path_remove_last_component(directory, argv[0]); - if (strstr(directory, ".libs")) - ogs_path_remove_last_component(directory, directory); - ogs_snprintf(command, sizeof command, "%s/%s", directory, name); + /* buildroot/src/mme/open5gs-mmed */ + ogs_snprintf(command, sizeof command, "%s%s%s%sd", + MESON_BUILD_ROOT OGS_DIR_SEPARATOR_S "src" OGS_DIR_SEPARATOR_S, + name, OGS_DIR_SEPARATOR_S "open5gs-", name); commandLine[0] = command; - child = ogs_thread_create(child_main, (void*)commandLine); + child = ogs_thread_create(child_main, commandLine); ogs_msleep(50); return child; } -void epc_child_terminate(void) +void test_child_terminate(void) { int i; ogs_proc_t *current = NULL; @@ -76,18 +97,36 @@ void epc_child_terminate(void) } } -int app_initialize(char **argv) +int app_initialize(const char *const argv[]) { int rv; + const char *argv_out[OGS_ARG_MAX]; + bool user_config = false; + int i = 0; + + for (i = 0; argv[i]; i++) { + if (strcmp("-c", argv[i]) == 0) { + user_config = true; + } + argv_out[i] = argv[i]; + } + argv_out[i] = NULL; + + if (!user_config) { + argv_out[i++] = "-c"; + argv_out[i++] = DEFAULT_CONFIG_FILENAME; + argv_out[i] = NULL; + } + if (ogs_config()->parameter.no_pcrf == 0) - pcrf_thread = epc_child_create("nextepc-pcrfd", argv); + pcrf_thread = test_child_create("pcrf", argv_out); if (ogs_config()->parameter.no_pgw == 0) - pgw_thread = epc_child_create("nextepc-pgwd", argv); + pgw_thread = test_child_create("pgw", argv_out); if (ogs_config()->parameter.no_sgw == 0) - sgw_thread = epc_child_create("nextepc-sgwd", argv); + sgw_thread = test_child_create("sgw", argv_out); if (ogs_config()->parameter.no_hss == 0) - hss_thread = epc_child_create("nextepc-hssd", argv); + hss_thread = test_child_create("hss", argv_out); ogs_sctp_init(ogs_config()->usrsctp.udp_port); diff --git a/tests/epc/meson.build b/tests/epc/meson.build new file mode 100644 index 000000000..b4b7efa1c --- /dev/null +++ b/tests/epc/meson.build @@ -0,0 +1,60 @@ +# Copyright (C) 2019 by Sukchan Lee + +# This file is part of Open5GS. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +testepc_conf = configuration_data() +testepc_conf.set_quoted('MESON_BUILD_ROOT', meson.build_root()) +configure_file(output : 'test-config-private.h', configuration : testepc_conf) + +testepc_cc_args = '-DDEFAULT_CONFIG_FILENAME="@0@/configs/simple.yaml"'.format(meson.build_root()) + +libtestepc_sources = files(''' + app-init.c +'''.split()) + +libtestepc_inc = include_directories('.') + +libtestepc = static_library('epc', + sources : [libtestepc_sources], + c_args : testepc_cc_args, + include_directories : [libtestepc_inc, srcinc], + link_with : [libmme, libhss, libsgw, libpgw, libpcrf], + dependencies : [libmme_dep, + libhss_dep, + libsgw_dep, + libpgw_dep, + libpcrf_dep], + install : false) + +libtestepc_dep = declare_dependency( + link_with : libtestepc, + include_directories : [libtestepc_inc, srcinc], + dependencies : [libmme_dep, + libhss_dep, + libsgw_dep, + libpgw_dep, + libpcrf_dep]) + +testepc_sources = files(''' + ../../src/main.c +'''.split()) + +executable('epc', + sources : [testepc_sources], + c_args : testepc_cc_args, + include_directories : srcinc, + dependencies : [libtestepc_dep]) diff --git a/tests/epc/test-epc.h b/tests/epc/test-epc.h new file mode 100644 index 000000000..d806b0485 --- /dev/null +++ b/tests/epc/test-epc.h @@ -0,0 +1,17 @@ +#ifndef TEST_EPC_H +#define TEST_EPC_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "ogs-app.h" + +void test_child_terminate(void); +ogs_thread_t *test_child_create(const char *name, const char *const argv[]); + +#ifdef __cplusplus +} +#endif + +#endif /* TEST_EPC_H */ diff --git a/tests/meson.build b/tests/meson.build new file mode 100644 index 000000000..79b0d36ec --- /dev/null +++ b/tests/meson.build @@ -0,0 +1,27 @@ +# Copyright (C) 2019 by Sukchan Lee + +# This file is part of Open5GS. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +subdir('core') +subdir('crypt') +subdir('sctp') +subdir('epc') +subdir('app') +subdir('unit') +subdir('simple') +subdir('mnc3') +subdir('volte') +subdir('csfb') diff --git a/tests/complex/abts-main.c b/tests/mnc3/abts-main.c similarity index 74% rename from tests/complex/abts-main.c rename to tests/mnc3/abts-main.c index a9f8a2574..880e64531 100644 --- a/tests/complex/abts-main.c +++ b/tests/mnc3/abts-main.c @@ -19,20 +19,12 @@ #include "test-app.h" -abts_suite *test_s1setup(abts_suite *suite); -abts_suite *test_attach(abts_suite *suite); -abts_suite *test_volte(abts_suite *suite); -abts_suite *test_handover(abts_suite *suite); -abts_suite *test_crash(abts_suite *suite); +abts_suite *test_mnc3(abts_suite *suite); const struct testlist { abts_suite *(*func)(abts_suite *suite); } alltests[] = { - {test_s1setup}, - {test_attach}, - {test_volte}, - {test_handover}, - {test_crash}, + {test_mnc3}, {NULL}, }; @@ -40,14 +32,14 @@ static void terminate(void) { ogs_msleep(50); - epc_child_terminate(); + test_child_terminate(); app_terminate(); test_app_final(); ogs_app_terminate(); } -static void initialize(char **argv) +static void initialize(const char *const argv[]) { int rv; @@ -59,13 +51,13 @@ static void initialize(char **argv) ogs_assert(rv == OGS_OK); } -int main(int argc, char **argv) +int main(int argc, const char *const argv[]) { int i; abts_suite *suite = NULL; atexit(terminate); - test_app_run(argc, argv, "sample-complex.conf", initialize); + test_app_run(argc, argv, "mnc3.yaml", initialize); for (i = 0; alltests[i].func; i++) suite = alltests[i].func(suite); diff --git a/lib/gtp/Makefile.am b/tests/mnc3/meson.build similarity index 66% rename from lib/gtp/Makefile.am rename to tests/mnc3/meson.build index b186f9df7..618c48b8e 100644 --- a/lib/gtp/Makefile.am +++ b/tests/mnc3/meson.build @@ -15,23 +15,14 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -pkglib_LTLIBRARIES = libogsgtp.la +testmnc3_sources = files(''' + abts-main.c + mnc3-test.c +'''.split()) -libogsgtp_la_SOURCES = \ - tlv.h message.h types.h conv.h node.h path.h xact.h \ - tlv.c message.c types.c conv.c node.c path.c xact.c \ - $(NULL) +testmnc3_exe = executable('mnc3', + sources : testmnc3_sources, + c_args : testcore_cc_flags, + dependencies : libtestapp_dep) -libogsgtp_la_LIBADD = \ - @OGSCORE_LIBS@ \ - $(NULL) - -AM_CPPFLAGS = \ - @OGSCORE_CFLAGS@ \ - -I$(top_srcdir)/lib \ - $(NULL) - -AM_CFLAGS = \ - -DOGS_GTP_COMPILATION \ - -Wall -Werror \ - $(NULL) +test('mnc3', testmnc3_exe, is_parallel : false, suite: 'system') diff --git a/tests/simple/mnc3-test.c b/tests/mnc3/mnc3-test.c similarity index 97% rename from tests/simple/mnc3-test.c rename to tests/mnc3/mnc3-test.c index 2125ce910..a365fd049 100644 --- a/tests/simple/mnc3-test.c +++ b/tests/mnc3/mnc3-test.c @@ -34,16 +34,16 @@ static void test1_func(abts_case *tc, void *data) uint32_t m_tmsi = 0; uint8_t tmp[OGS_MAX_SDU_LEN]; - char *_authentication_request = + const char *_authentication_request = "000b403b00000300 000005c001a00102 000800020018001a 002524075200906d" "231ff57ef278c719 1d170303deb610d0 7c4defa47480001f 2b5350926bdb3a"; - char *_security_mode_command = + const char *_security_mode_command = "000b402400000300 000005c001a00102 000800020018001a 000e0d37c966d549" "00075d010002e0e0"; - char *_esm_information_request = + const char *_esm_information_request = "000b402000000300 000005c001a00102 000800020018001a 000a0927846a01a8" "010201d9"; - char *_initial_context_setup_request = + const char *_initial_context_setup_request = "00090080c1000006 00000005c001a001 0200080002001800 42000a183d090000" "603d090000001800 70000034006b4500 093d0f807f000002 000000015c279a3e" "783d02074201490c 0313401000320033 0034003500315201 c101090c07737461" @@ -52,9 +52,9 @@ static void test1_func(abts_case *tc, void *data) "00000049002046c7 89cba93e9b977583 35c097e6c386c872 e4b82434a48037c3" "0601590edd8e"; - char *_emm_information = + const char *_emm_information = "000b403b00000300 000005c001a00102 000800020018001a 0025242729f8b0bb" - "030761430f10004e 0065007800740045 0050004347914032 80113463490100"; + "030761430f10004f 00700065006e0035 0047005347914032 80113463490100"; mongoc_collection_t *collection = NULL; bson_t *doc = NULL; diff --git a/tests/sample-complex.conf.in b/tests/sample-complex.conf.in deleted file mode 100644 index f956130fb..000000000 --- a/tests/sample-complex.conf.in +++ /dev/null @@ -1,123 +0,0 @@ -db_uri: mongodb://localhost/nextepc - -logger: - -parameter: - no_ipv6: true - -mme: - freeDiameter: - identity: mme.localdomain - realm: localdomain - listen_on: 127.0.0.2 - load_extension: - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dbg_msg_dumps/.libs/dbg_msg_dumps.so - conf: 0x8888 - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_rfc5777/.libs/dict_rfc5777.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_mip6i/.libs/dict_mip6i.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_nasreq/.libs/dict_nasreq.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_nas_mipv6/.libs/dict_nas_mipv6.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_dcca/.libs/dict_dcca.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_dcca_3gpp/.libs/dict_dcca_3gpp.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_s6a/.libs/dict_s6a.so - connect: - - identity: hss.localdomain - addr: 127.0.0.4 - - s1ap: - addr: 127.0.0.1 - gtpc: - addr: 127.0.0.1 - gummei: - plmn_id: - mcc: 001 - mnc: 01 - mme_gid: 2 - mme_code: 1 - tai: - plmn_id: - mcc: 001 - mnc: 01 - tac: 12345 - security: - integrity_order : [ EIA1, EIA2, EIA0 ] - ciphering_order : [ EEA0, EEA1, EEA2 ] - - network_name: - full: NextEPC - -hss: - freeDiameter: - identity: hss.localdomain - realm: localdomain - listen_on: 127.0.0.4 - load_extension: - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dbg_msg_dumps/.libs/dbg_msg_dumps.so - conf: 0x8888 - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_rfc5777/.libs/dict_rfc5777.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_mip6i/.libs/dict_mip6i.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_nasreq/.libs/dict_nasreq.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_nas_mipv6/.libs/dict_nas_mipv6.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_dcca/.libs/dict_dcca.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_dcca_3gpp/.libs/dict_dcca_3gpp.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_s6a/.libs/dict_s6a.so - connect: - - identity: mme.localdomain - addr: 127.0.0.2 - -sgw: - gtpc: - addr: 127.0.0.2 - gtpu: - addr: 127.0.0.2 - -pgw: - freeDiameter: - identity: pgw.localdomain - realm: localdomain - listen_on: 127.0.0.3 - load_extension: - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dbg_msg_dumps/.libs/dbg_msg_dumps.so - conf: 0x8888 - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_rfc5777/.libs/dict_rfc5777.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_mip6i/.libs/dict_mip6i.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_nasreq/.libs/dict_nasreq.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_nas_mipv6/.libs/dict_nas_mipv6.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_dcca/.libs/dict_dcca.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_dcca_3gpp/.libs/dict_dcca_3gpp.so - connect: - - identity: pcrf.localdomain - addr: 127.0.0.5 - - gtpc: - addr: - - 127.0.0.3 - - ::1 - gtpu: - - addr: 127.0.0.3 - - addr: ::1 - ue_pool: - - addr: 45.45.0.1/16 - - addr: cafe::1/64 - dns: - - 8.8.8.8 - - 8.8.4.4 - - 2001:4860:4860::8888 - - 2001:4860:4860::8844 -pcrf: - freeDiameter: - identity: pcrf.localdomain - realm: localdomain - listen_on: 127.0.0.5 - load_extension: - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dbg_msg_dumps/.libs/dbg_msg_dumps.so - conf: 0x8888 - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_rfc5777/.libs/dict_rfc5777.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_mip6i/.libs/dict_mip6i.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_nasreq/.libs/dict_nasreq.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_nas_mipv6/.libs/dict_nas_mipv6.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_dcca/.libs/dict_dcca.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_dcca_3gpp/.libs/dict_dcca_3gpp.so - connect: - - identity: pgw.localdomain - addr: 127.0.0.3 diff --git a/tests/sample-csfb.conf.in b/tests/sample-csfb.conf.in deleted file mode 100644 index d720726e6..000000000 --- a/tests/sample-csfb.conf.in +++ /dev/null @@ -1,157 +0,0 @@ -db_uri: mongodb://localhost/nextepc - -logger: - -parameter: - no_ipv6: true - -mme: - freeDiameter: - identity: mme.localdomain - realm: localdomain - listen_on: 127.0.0.2 - load_extension: - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dbg_msg_dumps/.libs/dbg_msg_dumps.so - conf: 0x8888 - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_rfc5777/.libs/dict_rfc5777.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_mip6i/.libs/dict_mip6i.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_nasreq/.libs/dict_nasreq.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_nas_mipv6/.libs/dict_nas_mipv6.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_dcca/.libs/dict_dcca.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_dcca_3gpp/.libs/dict_dcca_3gpp.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_s6a/.libs/dict_s6a.so - connect: - - identity: hss.localdomain - addr: 127.0.0.4 - - s1ap: - addr: 127.0.0.1 - gtpc: - addr: 127.0.0.1 - sgsap: - - addr: 127.0.0.2 - map: - tai: - plmn_id: - mcc: 901 - mnc: 70 - tac: 7 - lai: - plmn_id: - mcc: 901 - mnc: 70 - lac: 2342 - map: - tai: - plmn_id: - mcc: 724 - mnc: 21 - tac: 12345 - lai: - plmn_id: - mcc: 724 - mnc: 21 - lac: 51544 - gummei: - - plmn_id: - mcc: 901 - mnc: 70 - mme_gid: 2 - mme_code: 1 - - plmn_id: - mcc: 724 - mnc: 21 - mme_gid: 2 - mme_code: 1 - tai: - plmn_id: - mcc: 901 - mnc: 70 - tac: 7 - tai: - plmn_id: - mcc: 724 - mnc: 21 - tac: 12345 - security: - integrity_order : [ EIA1, EIA2, EIA0 ] - ciphering_order : [ EEA0, EEA1, EEA2 ] - - network_name: - full: NextEPC - -hss: - freeDiameter: - identity: hss.localdomain - realm: localdomain - listen_on: 127.0.0.4 - load_extension: - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dbg_msg_dumps/.libs/dbg_msg_dumps.so - conf: 0x8888 - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_rfc5777/.libs/dict_rfc5777.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_mip6i/.libs/dict_mip6i.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_nasreq/.libs/dict_nasreq.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_nas_mipv6/.libs/dict_nas_mipv6.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_dcca/.libs/dict_dcca.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_dcca_3gpp/.libs/dict_dcca_3gpp.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_s6a/.libs/dict_s6a.so - connect: - - identity: mme.localdomain - addr: 127.0.0.2 - -sgw: - gtpc: - addr: 127.0.0.2 - gtpu: - addr: 127.0.0.2 - -pgw: - freeDiameter: - identity: pgw.localdomain - realm: localdomain - listen_on: 127.0.0.3 - load_extension: - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dbg_msg_dumps/.libs/dbg_msg_dumps.so - conf: 0x8888 - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_rfc5777/.libs/dict_rfc5777.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_mip6i/.libs/dict_mip6i.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_nasreq/.libs/dict_nasreq.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_nas_mipv6/.libs/dict_nas_mipv6.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_dcca/.libs/dict_dcca.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_dcca_3gpp/.libs/dict_dcca_3gpp.so - connect: - - identity: pcrf.localdomain - addr: 127.0.0.5 - - gtpc: - - addr: - - 127.0.0.3 - - ::1 - gtpu: - - addr: 127.0.0.3 - - addr: ::1 - ue_pool: - - addr: 45.45.0.1/16 - - addr: cafe::1/64 - dns: - - 8.8.8.8 - - 8.8.4.4 - - 2001:4860:4860::8888 - - 2001:4860:4860::8844 -pcrf: - freeDiameter: - identity: pcrf.localdomain - realm: localdomain - listen_on: 127.0.0.5 - load_extension: - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dbg_msg_dumps/.libs/dbg_msg_dumps.so - conf: 0x8888 - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_rfc5777/.libs/dict_rfc5777.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_mip6i/.libs/dict_mip6i.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_nasreq/.libs/dict_nasreq.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_nas_mipv6/.libs/dict_nas_mipv6.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_dcca/.libs/dict_dcca.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_dcca_3gpp/.libs/dict_dcca_3gpp.so - connect: - - identity: pgw.localdomain - addr: 127.0.0.3 diff --git a/tests/sample-simple.conf.in b/tests/sample-simple.conf.in deleted file mode 100644 index 165dfcce5..000000000 --- a/tests/sample-simple.conf.in +++ /dev/null @@ -1,126 +0,0 @@ -db_uri: mongodb://localhost/nextepc - -logger: - -parameter: - no_ipv6: true - -mme: - freeDiameter: - identity: mme.localdomain - realm: localdomain - listen_on: 127.0.0.2 - load_extension: - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dbg_msg_dumps/.libs/dbg_msg_dumps.so - conf: 0x8888 - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_rfc5777/.libs/dict_rfc5777.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_mip6i/.libs/dict_mip6i.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_nasreq/.libs/dict_nasreq.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_nas_mipv6/.libs/dict_nas_mipv6.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_dcca/.libs/dict_dcca.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_dcca_3gpp/.libs/dict_dcca_3gpp.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_s6a/.libs/dict_s6a.so - connect: - - identity: hss.localdomain - addr: 127.0.0.4 - - s1ap: - addr: 127.0.0.1 - gtpc: - addr: 127.0.0.1 - gummei: - plmn_id: - mcc: 310 - mnc: 014 - mme_gid: 32798 - mme_code: 100 - tai: - plmn_id: - mcc: 310 - mnc: 014 - tac: [50, 51, 52, 53] - security: - integrity_order : [ EIA1, EIA2, EIA0 ] - ciphering_order : [ EEA0, EEA1, EEA2 ] - - network_name: - full: NextEPC - -hss: - freeDiameter: - identity: hss.localdomain - realm: localdomain - listen_on: 127.0.0.4 - load_extension: - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dbg_msg_dumps/.libs/dbg_msg_dumps.so - conf: 0x8888 - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_rfc5777/.libs/dict_rfc5777.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_mip6i/.libs/dict_mip6i.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_nasreq/.libs/dict_nasreq.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_nas_mipv6/.libs/dict_nas_mipv6.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_dcca/.libs/dict_dcca.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_dcca_3gpp/.libs/dict_dcca_3gpp.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_s6a/.libs/dict_s6a.so - connect: - - identity: mme.localdomain - addr: 127.0.0.2 - -sgw: - gtpc: - addr: 127.0.0.2 - gtpu: - addr: 127.0.0.2 - -pgw: - freeDiameter: - identity: pgw.localdomain - realm: localdomain - listen_on: 127.0.0.3 - load_extension: - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dbg_msg_dumps/.libs/dbg_msg_dumps.so - conf: 0x8888 - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_rfc5777/.libs/dict_rfc5777.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_mip6i/.libs/dict_mip6i.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_nasreq/.libs/dict_nasreq.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_nas_mipv6/.libs/dict_nas_mipv6.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_dcca/.libs/dict_dcca.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_dcca_3gpp/.libs/dict_dcca_3gpp.so - connect: - - identity: pcrf.localdomain - addr: 127.0.0.5 - - gtpc: - - addr: - - 127.0.0.3 - - ::1 - - addr: - - 127.0.0.4 - apn: starent.com - gtpu: - - addr: 127.0.0.3 - - addr: ::1 - ue_pool: - - addr: 45.45.0.1/16 - - addr: cafe::1/64 - dns: - - 8.8.8.8 - - 8.8.4.4 - - 2001:4860:4860::8888 - - 2001:4860:4860::8844 -pcrf: - freeDiameter: - identity: pcrf.localdomain - realm: localdomain - listen_on: 127.0.0.5 - load_extension: - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dbg_msg_dumps/.libs/dbg_msg_dumps.so - conf: 0x8888 - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_rfc5777/.libs/dict_rfc5777.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_mip6i/.libs/dict_mip6i.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_nasreq/.libs/dict_nasreq.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_nas_mipv6/.libs/dict_nas_mipv6.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_dcca/.libs/dict_dcca.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_dcca_3gpp/.libs/dict_dcca_3gpp.so - connect: - - identity: pgw.localdomain - addr: 127.0.0.3 diff --git a/tests/sample-volte.conf.in b/tests/sample-volte.conf.in deleted file mode 100644 index 80ab9ec30..000000000 --- a/tests/sample-volte.conf.in +++ /dev/null @@ -1,142 +0,0 @@ -db_uri: mongodb://localhost/nextepc - -logger: - -parameter: - -mme: - freeDiameter: - identity: mme.open-ims.test - realm: open-ims.test -# port: 3868 -# sec_port: 5868 - listen_on: 127.0.0.2 - load_extension: - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dbg_msg_dumps/.libs/dbg_msg_dumps.so - conf: 0x8888 - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_rfc5777/.libs/dict_rfc5777.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_mip6i/.libs/dict_mip6i.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_nasreq/.libs/dict_nasreq.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_nas_mipv6/.libs/dict_nas_mipv6.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_dcca/.libs/dict_dcca.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_dcca_3gpp/.libs/dict_dcca_3gpp.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_s6a/.libs/dict_s6a.so - connect: - - identity: hss.open-ims.test - addr: 127.0.0.4 -# port: 3868 - - s1ap: - addr: 127.0.0.1 - gtpc: - addr: 127.0.0.1 - gummei: - plmn_id: - mcc: 001 - mnc: 01 - mme_gid: 2 - mme_code: 1 - tai: - plmn_id: - mcc: 001 - mnc: 01 - tac: 12345 - security: - integrity_order : [ EIA1, EIA2, EIA0 ] - ciphering_order : [ EEA0, EEA1, EEA2 ] - -hss: - freeDiameter: - identity: hss.open-ims.test - realm: open-ims.test -# port: 3868 -# sec_port: 5868 - listen_on: 127.0.0.4 - load_extension: - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dbg_msg_dumps/.libs/dbg_msg_dumps.so - conf: 0x8888 - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_rfc5777/.libs/dict_rfc5777.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_mip6i/.libs/dict_mip6i.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_nasreq/.libs/dict_nasreq.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_nas_mipv6/.libs/dict_nas_mipv6.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_dcca/.libs/dict_dcca.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_dcca_3gpp/.libs/dict_dcca_3gpp.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_s6a/.libs/dict_s6a.so - connect: - - identity: mme.open-ims.test - addr: 127.0.0.2 -# port: 3868 - -sgw: - gtpc: - addr: 127.0.0.2 - gtpu: - addr: 127.0.0.2 - -pgw: - freeDiameter: - identity: pgw.open-ims.test - realm: open-ims.test -# port: 3868 -# sec_port: 5868 - listen_on: 127.0.0.3 - load_extension: - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dbg_msg_dumps/.libs/dbg_msg_dumps.so - conf: 0x8888 - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_rfc5777/.libs/dict_rfc5777.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_mip6i/.libs/dict_mip6i.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_nasreq/.libs/dict_nasreq.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_nas_mipv6/.libs/dict_nas_mipv6.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_dcca/.libs/dict_dcca.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_dcca_3gpp/.libs/dict_dcca_3gpp.so - connect: - - identity: pcrf.open-ims.test - addr: 127.0.0.5 -# port: 3868 - - gtpc: - addr: - - 127.0.0.3 - - ::1 - gtpu: - - addr: 127.0.0.3 - - addr: ::1 - ue_pool: - - addr: 45.45.0.1/16 - - addr: cafe::1/64 - dns: - - 8.8.8.8 - - 8.8.4.4 - - 2001:4860:4860::8888 - - 2001:4860:4860::8844 -# -# -# -# o Proxy Call Session Control Function -# -# p-cscf: -# - 127.0.0.1 -# - ::1 -# - -pcrf: - freeDiameter: - identity: pcrf.open-ims.test - realm: open-ims.test -# port: 3868 -# sec_port: 5868 - listen_on: 127.0.0.5 - load_extension: - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dbg_msg_dumps/.libs/dbg_msg_dumps.so - conf: 0x8888 - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_rfc5777/.libs/dict_rfc5777.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_mip6i/.libs/dict_mip6i.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_nasreq/.libs/dict_nasreq.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_nas_mipv6/.libs/dict_nas_mipv6.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_dcca/.libs/dict_dcca.so - - module: @abs_top_builddir@/lib/freeDiameter/extensions/dict_dcca_3gpp/.libs/dict_dcca_3gpp.so - connect: - - identity: pgw.open-ims.test - addr: 127.0.0.3 - - identity: pcscf.open-ims.test - addr: 127.0.0.1 diff --git a/tests/sctp/abts-main.c b/tests/sctp/abts-main.c new file mode 100644 index 000000000..75ab8ef46 --- /dev/null +++ b/tests/sctp/abts-main.c @@ -0,0 +1,90 @@ +/* + * Copyright (C) 2019 by Sukchan Lee + * + * This file is part of Open5GS. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "ogs-sctp.h" +#include "core/abts.h" + +abts_suite *test_sctp(abts_suite *suite); + +const struct testlist { + abts_suite *(*func)(abts_suite *suite); +} alltests[] = { + {test_sctp}, + {NULL}, +}; + +static void terminate(void) +{ + ogs_sctp_final(); + + ogs_pkbuf_default_destroy(); + ogs_core_terminate(); +} + +int main(int argc, const char *const argv[]) +{ + int rv, i, opt; + ogs_getopt_t options; + struct { + char *log_level; + char *domain_mask; + } optarg; + const char *argv_out[argc+2]; /* '-e error' is always added */ + + abts_suite *suite = NULL; + ogs_pkbuf_config_t config; + + rv = abts_main(argc, argv, argv_out); + if (rv != OGS_OK) return rv; + + memset(&optarg, 0, sizeof(optarg)); + ogs_getopt_init(&options, (char**)argv_out); + + while ((opt = ogs_getopt(&options, "e:m:")) != -1) { + switch (opt) { + case 'e': + optarg.log_level = options.optarg; + break; + case 'm': + optarg.domain_mask = options.optarg; + break; + case '?': + default: + fprintf(stderr, "%s: should not be reached\n", OGS_FUNC); + return OGS_ERROR; + } + } + + ogs_core_initialize(); + ogs_pkbuf_default_init(&config); + ogs_pkbuf_default_create(&config); + + ogs_log_install_domain(&__ogs_sctp_domain, "sctp", OGS_LOG_ERROR); +#define USRSCTP_LOCAL_UDP_PORT 9899 + ogs_sctp_init(USRSCTP_LOCAL_UDP_PORT); + atexit(terminate); + + rv = ogs_log_config_domain(optarg.domain_mask, optarg.log_level); + if (rv != OGS_OK) return rv; + + for (i = 0; alltests[i].func; i++) + suite = alltests[i].func(suite); + + return abts_report(suite); +} diff --git a/tests/sctp/meson.build b/tests/sctp/meson.build new file mode 100644 index 000000000..20eb7c18b --- /dev/null +++ b/tests/sctp/meson.build @@ -0,0 +1,28 @@ +# Copyright (C) 2019 by Sukchan Lee + +# This file is part of Open5GS. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +testsctp_sources = files(''' + abts-main.c + sctp-test.c +'''.split()) + +testsctp_exe = executable('sctp', + sources : testsctp_sources, + c_args : testcore_cc_flags, + dependencies : libsctp_dep) + +test('sctp', testsctp_exe, is_parallel : false, suite: 'system') diff --git a/tests/unit/sctp-test.c b/tests/sctp/sctp-test.c similarity index 99% rename from tests/unit/sctp-test.c rename to tests/sctp/sctp-test.c index 251fbc0b5..aa482f14f 100644 --- a/tests/unit/sctp-test.c +++ b/tests/sctp/sctp-test.c @@ -17,7 +17,8 @@ * along with this program. If not, see . */ -#include "test-app.h" +#include "ogs-sctp.h" +#include "core/abts.h" #define DATASTR "This is a test" #define STRLEN 8092 diff --git a/tests/simple/abts-main.c b/tests/simple/abts-main.c index 793b70e55..dedb96e64 100644 --- a/tests/simple/abts-main.c +++ b/tests/simple/abts-main.c @@ -19,12 +19,20 @@ #include "test-app.h" -abts_suite *test_mnc3(abts_suite *suite); +abts_suite *test_s1setup(abts_suite *suite); +abts_suite *test_attach(abts_suite *suite); +abts_suite *test_volte(abts_suite *suite); +abts_suite *test_handover(abts_suite *suite); +abts_suite *test_crash(abts_suite *suite); const struct testlist { abts_suite *(*func)(abts_suite *suite); } alltests[] = { - {test_mnc3}, + {test_s1setup}, + {test_attach}, + {test_volte}, + {test_handover}, + {test_crash}, {NULL}, }; @@ -32,14 +40,14 @@ static void terminate(void) { ogs_msleep(50); - epc_child_terminate(); + test_child_terminate(); app_terminate(); test_app_final(); ogs_app_terminate(); } -static void initialize(char **argv) +static void initialize(const char *const argv[]) { int rv; @@ -51,13 +59,13 @@ static void initialize(char **argv) ogs_assert(rv == OGS_OK); } -int main(int argc, char **argv) +int main(int argc, const char *const argv[]) { int i; abts_suite *suite = NULL; atexit(terminate); - test_app_run(argc, argv, "sample-simple.conf", initialize); + test_app_run(argc, argv, "simple.yaml", initialize); for (i = 0; alltests[i].func; i++) suite = alltests[i].func(suite); diff --git a/tests/complex/attach-test.c b/tests/simple/attach-test.c similarity index 98% rename from tests/complex/attach-test.c rename to tests/simple/attach-test.c index 54ef57882..17ccec45f 100644 --- a/tests/complex/attach-test.c +++ b/tests/simple/attach-test.c @@ -38,16 +38,16 @@ static void attach_test1(abts_case *tc, void *data) uint32_t m_tmsi = 0; uint8_t tmp[OGS_MAX_SDU_LEN]; - char *_authentication_request = + const char *_authentication_request = "000b403b00000300 000005c00100009d 000800020001001a 0025240752002008" "0c3818183b522614 162c07601d0d10f1 1b89a2a8de8000ad 0ccf7f55e8b20d"; - char *_security_mode_command = + const char *_security_mode_command = "000b402700000300 000005c00100009d 000800020001001a 00111037f933b5d5" "00075d010005e060 c04070"; - char *_esm_information_request = + const char *_esm_information_request = "000b402000000300 000005c00100009d 000800020001001a 000a092779012320" "010221d9"; - char *_initial_context_setup_request = + const char *_initial_context_setup_request = "00090080d8000006 00000005c0010000 9d00080002000100 42000a183e800000" "603e800000001800 8086000034008080 450009200f807f00 0002000000017127" "4db5d98302074202 49064000f1105ba0 00485221c1010909 08696e7465726e65" @@ -55,9 +55,9 @@ static void attach_test1(abts_case *tc, void *data) "8106080808088306 08080404000d0408 080808000d040808 0404500bf600f110" "0002010000000153 12172c5949640125 006b000518000c00 00004900203311c6" "03c6a6d67f695e5a c02bb75b381b693c 3893a6d932fd9182 3544e3e79b"; - char *_emm_information = + const char *_emm_information = "000b403b00000300 000005c00100009d 000800020001001a 002524271f9b491e" - "030761430f10004e 0065007800740045 0050004347812072 11240563490100"; + "030761430f10004f 00700065006e0035 0047005347812072 11240563490100"; mongoc_collection_t *collection = NULL; bson_t *doc = NULL; @@ -290,8 +290,6 @@ static void attach_test1(abts_case *tc, void *data) m_tmsi = htonl(m_tmsi); memcpy(sendbuf->data + 36, &m_tmsi, 4); /* Update NAS MAC */ - void snow_3g_f9(uint8_t* key, uint32_t count, uint32_t fresh, - uint32_t dir, uint8_t *data, uint64_t length, uint8_t *out); snow_3g_f9(mme_ue->knas_int, 7, 0, 0, sendbuf->data + 24, (109 << 3), sendbuf->data+20); ABTS_INT_EQUAL(tc, OGS_OK, rv); @@ -796,20 +794,20 @@ static void attach_test3(abts_case *tc, void *data) uint32_t m_tmsi = 0; uint8_t tmp[OGS_MAX_SDU_LEN]; - char *_authentication_request = + const char *_authentication_request = "000b" "403b000003000000 05c0020000c80008 00020002001a0025 2407520042200639" "1c0021554d444928 4a1a062e10e543cb 257f1f800021f4f9 2d522a5b87"; - char *_security_mode_command = + const char *_security_mode_command = "000b402400000300 000005c0020000c8 000800020002001a 000e0d37a3761a13" "00075d010002f0f0"; - char *_esm_information_request = + const char *_esm_information_request = "000b" "4020000003000000 05c0020000c80008 00020002001a000a 09277330e06c0102" "01d9"; - char *_initial_context_setup_request = + const char *_initial_context_setup_request = "00090080c8000006 00000005c0020000 c800080002000200 42000a183e800000" "603e800000001800 7700003400724540 0920000000000000 00000f800a0123d8" "000000035b27a23a 27b4020742024906 4000f1102b670032 5201c10509ffffff" @@ -818,11 +816,11 @@ static void attach_test3(abts_case *tc, void *data) "006b00051e000e00 000049002040964d eb63a0afb5d0d374 c1da505f6252d1f9" "05ff9c6791b8503a 032c6effa7"; - char *_emm_information = + const char *_emm_information = "000b403b00000300 000005c0020000c8 000800020002001a 002524276782702a" - "030761430f10004e 0065007800740045 0050004347812072 11941563490100"; + "030761430f10004f 00700065006e0035 0047005347812072 11941563490100"; - char *_ue_context_release_command = + const char *_ue_context_release_command = "0017" "0013000002006300 070c020000c80002 0002400120"; diff --git a/tests/complex/crash-test.c b/tests/simple/crash-test.c similarity index 100% rename from tests/complex/crash-test.c rename to tests/simple/crash-test.c diff --git a/tests/complex/handover-test.c b/tests/simple/handover-test.c similarity index 99% rename from tests/complex/handover-test.c rename to tests/simple/handover-test.c index bc923ce11..64c787e4b 100644 --- a/tests/complex/handover-test.c +++ b/tests/simple/handover-test.c @@ -31,9 +31,9 @@ static void handover_test1(abts_case *tc, void *data) int msgindex = 9; uint8_t tmp[OGS_MAX_SDU_LEN]; - char *_nh1 = "10" + const char *_nh1 = "10" "3715a966536b75b4 d46e99774dcdb344 5ce5e893fbbf28f4 9f58508c36f827cc"; - char *_nh2 = "18" + const char *_nh2 = "18" "a29ed36339514717 481992f77f47a9af 934a7b763afcec39 edf5071461db6ae8"; mongoc_collection_t *collection = NULL; diff --git a/tests/simple/meson.build b/tests/simple/meson.build new file mode 100644 index 000000000..7a40f08f1 --- /dev/null +++ b/tests/simple/meson.build @@ -0,0 +1,33 @@ +# Copyright (C) 2019 by Sukchan Lee + +# This file is part of Open5GS. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +testsimple_sources = files(''' + abts-main.c + s1setup-test.c + attach-test.c + volte-test.c + handover-test.c + crash-test.c + +'''.split()) + +testsimple_exe = executable('simple', + sources : testsimple_sources, + c_args : testcore_cc_flags, + dependencies : libtestapp_dep) + +test('simple', testsimple_exe, is_parallel : false, suite: 'system') diff --git a/tests/complex/s1setup-test.c b/tests/simple/s1setup-test.c similarity index 100% rename from tests/complex/s1setup-test.c rename to tests/simple/s1setup-test.c diff --git a/tests/complex/volte-test.c b/tests/simple/volte-test.c similarity index 100% rename from tests/complex/volte-test.c rename to tests/simple/volte-test.c diff --git a/tests/testsuite.at b/tests/testsuite.at deleted file mode 100644 index 8ceda2ed5..000000000 --- a/tests/testsuite.at +++ /dev/null @@ -1,67 +0,0 @@ -AT_INIT -AT_BANNER([NextEPC Amazing Tests.]) - -AT_SETUP([unit]) -AT_KEYWORDS([unit]) -AT_CHECK_UNQUOTED( - [$abs_top_builddir/tests/testunit -q], - [0], [dnl -s1ap-message-test : SUCCESS -nas-message-test : SUCCESS -gtp-message-test : SUCCESS -security-test : SUCCESS -sctp-test : SUCCESS -crash-test : SUCCESS -All tests passed. -]) -AT_CLEANUP - -AT_SETUP([simple]) -AT_KEYWORDS([simple]) -AT_CHECK_UNQUOTED( - [$abs_top_builddir/tests/testsimple -q -c $abs_top_builddir/tests/sample-simple.conf], - [0], [dnl -mnc3-test : SUCCESS -All tests passed. -]) -AT_CLEANUP - -AT_SETUP([complex]) -AT_KEYWORDS([complex]) -AT_CHECK_UNQUOTED( - [$abs_top_builddir/tests/testcomplex -q -c $abs_top_builddir/tests/sample-complex.conf], - [0], [dnl -s1setup-test : SUCCESS -attach-test : SUCCESS -volte-test : SUCCESS -handover-test : SUCCESS -crash-test : SUCCESS -All tests passed. -]) -AT_CLEANUP - -AT_SETUP([volte]) -AT_KEYWORDS([volte]) -AT_CHECK_UNQUOTED( - [$abs_top_builddir/tests/testvolte -q -c $abs_top_builddir/tests/sample-volte.conf], - [0], [dnl -volte-test : SUCCESS -All tests passed. -]) -AT_CLEANUP - -AT_SETUP([csfb]) -AT_KEYWORDS([csfb]) -AT_CHECK_UNQUOTED( - [$abs_top_builddir/tests/testcsfb -q -c $abs_top_builddir/tests/sample-csfb.conf], - [0], [dnl -mo-idle-test : SUCCESS -mt-idle-test : SUCCESS -mo-active-test : SUCCESS -mt-active-test : SUCCESS -mo-sms-test : SUCCESS -mt-sms-test : SUCCESS -crash-test : SUCCESS -All tests passed. -]) -AT_CLEANUP diff --git a/tests/unit/abts-main.c b/tests/unit/abts-main.c index db5be6f9d..4e8977053 100644 --- a/tests/unit/abts-main.c +++ b/tests/unit/abts-main.c @@ -23,7 +23,6 @@ abts_suite *test_s1ap_message(abts_suite *suite); abts_suite *test_nas_message(abts_suite *suite); abts_suite *test_gtp_message(abts_suite *suite); abts_suite *test_security(abts_suite *suite); -abts_suite *test_sctp(abts_suite *suite); abts_suite *test_crash(abts_suite *suite); const struct testlist { @@ -33,7 +32,6 @@ const struct testlist { {test_nas_message}, {test_gtp_message}, {test_security}, - {test_sctp}, {test_crash}, {NULL}, }; @@ -41,14 +39,13 @@ const struct testlist { static void terminate(void) { mme_context_final(); - ogs_sctp_final(); ogs_pkbuf_default_destroy(); ogs_core_terminate(); } -int main(int argc, char **argv) +int main(int argc, const char *const argv[]) { int rv, i, opt; ogs_getopt_t options; @@ -56,7 +53,7 @@ int main(int argc, char **argv) char *log_level; char *domain_mask; } optarg; - char *argv_out[argc+2]; /* '-e error' is always added */ + const char *argv_out[argc+2]; /* '-e error' is always added */ abts_suite *suite = NULL; ogs_pkbuf_config_t config; @@ -65,7 +62,7 @@ int main(int argc, char **argv) if (rv != OGS_OK) return rv; memset(&optarg, 0, sizeof(optarg)); - ogs_getopt_init(&options, argv_out); + ogs_getopt_init(&options, (char**)argv_out); while ((opt = ogs_getopt(&options, "e:m:")) != -1) { switch (opt) { @@ -90,7 +87,6 @@ int main(int argc, char **argv) ogs_config_init(); mme_context_init(); - ogs_sctp_init(ogs_config()->usrsctp.udp_port); atexit(terminate); diff --git a/tests/unit/crash-test.c b/tests/unit/crash-test.c index 620683ae2..93b342b68 100644 --- a/tests/unit/crash-test.c +++ b/tests/unit/crash-test.c @@ -137,6 +137,7 @@ static void test1_func(abts_case *tc, void *data) e_rab->e_RABlevelQoSParameters.gbrQosInformation = gbrQosInformation; + memset(&sgw_s1u_ip, 0, sizeof(sgw_s1u_ip)); sgw_s1u_ip.ipv4 = 1; sgw_s1u_ip.ipv6 = 0; rv = ogs_s1ap_ip_to_BIT_STRING( @@ -335,7 +336,7 @@ static void test_parse_enb_configuration_transfer( static void test2_func(abts_case *tc, void *data) { - char *payload = + const char *payload = "0028" "4022000001008140 1b0009f124000000 1009f12458ac0009 f1240000002009f1" "2458ac00"; @@ -360,7 +361,7 @@ static void test2_func(abts_case *tc, void *data) static void test3_func(abts_case *tc, void *data) { - char *payload = + const char *payload = "0028" "4028000001008140 210009f124000000 2009f12458ac0009 f1240000001009f1" "2458ac500f80c0a8 683b"; diff --git a/tests/unit/gtp-message-test.c b/tests/unit/gtp-message-test.c index 192657c0a..2d25ab82e 100644 --- a/tests/unit/gtp-message-test.c +++ b/tests/unit/gtp-message-test.c @@ -23,7 +23,7 @@ static void gtp_message_test1(abts_case *tc, void *data) { int rv; /* Create Session Request */ - char *_payload = + const char *_payload = "0100080055153011 340010f44c000600 9471527600414b00 0800536120009178" "840056000d001855 f501102255f50100 019d015300030055 f501520001000657" "0009008a80000084 0a32360a57000901 87000000000a3236 254700220005766f" @@ -44,7 +44,7 @@ static void gtp_message_test1(abts_case *tc, void *data) ogs_paa_t paa; ogs_gtp_ambr_t ambr; ogs_pco_t pco; - char pcobuf[OGS_MAX_PCO_LEN]; + unsigned char pcobuf[OGS_MAX_PCO_LEN]; ogs_gtp_bearer_qos_t bearer_qos; char bearer_qos_buf[GTP_BEARER_QOS_LEN]; ogs_gtp_ue_timezone_t ue_timezone; @@ -106,7 +106,7 @@ static void gtp_message_test1(abts_case *tc, void *data) req.pgw_s5_s8_address_for_control_plane_or_pmip.len = OGS_GTP_F_TEID_IPV4_LEN; - _value = "05766f6c7465036e 6732046d6e657406 6d6e63303130066d 6363353535046770 7273"; + _value = (char*)"05766f6c7465036e 6732046d6e657406 6d6e63303130066d 6363353535046770 7273"; req.access_point_name.presence = 1; req.access_point_name.data = OGS_HEX(_value, strlen(_value), apnbuf); req.access_point_name.len = sizeof(apnbuf); @@ -194,19 +194,19 @@ static void gtp_message_test1(abts_case *tc, void *data) ABTS_INT_EQUAL(tc, 1, req.imsi.presence); ABTS_INT_EQUAL(tc, 8, req.imsi.len); - _value = "55153011 340010f4"; + _value = (char*)"55153011 340010f4"; ABTS_TRUE(tc, memcmp(OGS_HEX(_value, strlen(_value), hexbuf), req.imsi.data, req.imsi.len) == 0); ABTS_INT_EQUAL(tc, 1, req.msisdn.presence); ABTS_INT_EQUAL(tc, 6, req.msisdn.len); - _value = "94715276 0041"; + _value = (char*)"94715276 0041"; ABTS_TRUE(tc, memcmp(OGS_HEX(_value, strlen(_value), hexbuf), req.msisdn.data, req.msisdn.len) == 0); ABTS_INT_EQUAL(tc, 1, req.me_identity.presence); ABTS_INT_EQUAL(tc, 8, req.me_identity.len); - _value = "53612000 91788400"; + _value = (char*)"53612000 91788400"; ABTS_TRUE(tc, memcmp(OGS_HEX(_value, strlen(_value), hexbuf), req.me_identity.data, req.me_identity.len) == 0); diff --git a/tests/unit/meson.build b/tests/unit/meson.build new file mode 100644 index 000000000..8bd9304b4 --- /dev/null +++ b/tests/unit/meson.build @@ -0,0 +1,32 @@ +# Copyright (C) 2019 by Sukchan Lee + +# This file is part of Open5GS. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +testunit_sources = files(''' + abts-main.c + s1ap-message-test.c + nas-message-test.c + gtp-message-test.c + security-test.c + crash-test.c +'''.split()) + +testunit_exe = executable('unit', + sources : testunit_sources, + c_args : testcore_cc_flags, + dependencies : libtestapp_dep) + +test('unit', testunit_exe, is_parallel : false, suite: 'unit') diff --git a/tests/unit/nas-message-test.c b/tests/unit/nas-message-test.c index ad4b4420a..81384459b 100644 --- a/tests/unit/nas-message-test.c +++ b/tests/unit/nas-message-test.c @@ -23,7 +23,7 @@ static void ogs_nas_message_test1(abts_case *tc, void *data) { /* Attach Request */ - char *payload = + const char *payload = "0741020bf600f110000201030003e605" "f07000001000050215d011d15200f110" "30395c0a003103e5e0349011035758a6" @@ -49,7 +49,7 @@ static void ogs_nas_message_test1(abts_case *tc, void *data) static void ogs_nas_message_test2(abts_case *tc, void *data) { /* Attach Accept */ - char *payload = + const char *payload = "07420223060014f799303900325201c1" "01090908696e7465726e657405010ae1" "000a271b80802110020200108106c0a8" @@ -58,7 +58,7 @@ static void ogs_nas_message_test2(abts_case *tc, void *data) "fffd2305f400e102d4640123"; char buffer[92]; - char *esm_payload = + const char *esm_payload = "5201c101090908696e7465726e657405" "010ae1000a271b808021100202001081" "06c0a8a8018306c0a8a801000d04c0a8" @@ -135,7 +135,7 @@ static void ogs_nas_message_test2(abts_case *tc, void *data) static void ogs_nas_message_test3(abts_case *tc, void *data) { - char *payload = "074300035200c2"; + const char *payload = "074300035200c2"; ogs_nas_message_t message; ogs_pkbuf_t *pkbuf; @@ -157,7 +157,7 @@ static void ogs_nas_message_test3(abts_case *tc, void *data) static void ogs_nas_message_test4(abts_case *tc, void *data) { /* Attach Reject */ - char *payload = "074411"; + const char *payload = "074411"; char buffer[3]; ogs_nas_message_t message; @@ -197,7 +197,7 @@ static void ogs_nas_message_test5(abts_case *tc, void *data) static void ogs_nas_message_test6(abts_case *tc, void *data) { /* Identity Request */ - char *payload = "075501"; + const char *payload = "075501"; char hexbuf[OGS_MAX_SDU_LEN]; ogs_nas_message_t message; @@ -226,7 +226,7 @@ static void ogs_nas_message_test6(abts_case *tc, void *data) static void ogs_nas_message_test7(abts_case *tc, void *data) { /* Identity Response */ - char *payload = "0756080910101032548651"; + const char *payload = "0756080910101032548651"; char buffer[11]; ogs_nas_message_t message; @@ -271,7 +271,7 @@ static void ogs_nas_message_test7(abts_case *tc, void *data) static void ogs_nas_message_test8(abts_case *tc, void *data) { /* Security Request */ - char *payload = "c7a8640c"; + const char *payload = "c7a8640c"; char buffer[4]; ogs_nas_message_t message; diff --git a/tests/unit/s1ap-message-test.c b/tests/unit/s1ap-message-test.c index 87f1fb994..fb452ae42 100644 --- a/tests/unit/s1ap-message-test.c +++ b/tests/unit/s1ap-message-test.c @@ -7,7 +7,7 @@ static void s1ap_message_test1(abts_case *tc, void *data) { /* S1SetupRequest */ - char *payload = + const char *payload = "0011002d000004003b00090000f11040" "54f64010003c400903004a4c542d3632" "3100400007000c0e4000f11000894001" @@ -33,7 +33,7 @@ static void s1ap_message_test1(abts_case *tc, void *data) static void s1ap_message_test2(abts_case *tc, void *data) { /* InitialUE(Attach Request) */ - char *payload = + const char *payload = "000c406f000006000800020001001a00" "3c3b17df675aa8050741020bf600f110" "000201030003e605f070000010000502" @@ -63,7 +63,7 @@ static void s1ap_message_test2(abts_case *tc, void *data) static void s1ap_message_test3(abts_case *tc, void *data) { /* initial context setup response */ - char *payload = + const char *payload = "2009002500000300004005c0020000bf" "0008400200010033400f000032400a0a" "1f0a0123c601000908"; @@ -140,9 +140,8 @@ static void s1ap_message_test6(abts_case *tc, void *data) ogs_pkbuf_t *emmbuf = NULL; enb_ue_t enb_ue; int i; - ogs_s1ap_message_t message; char buffer[1024]; - char *_result = + const char *_result = "000b4080 8c000003 00000002 00010008 00020001 001a0079 78efefef efefefef" "efefefef efefefef efefefef efefefef efefefef efefefef efefefef efefefef" "efefefef efefefef efefefef efefefef efefefef efefefef efefefef efefefef" @@ -168,7 +167,7 @@ static void s1ap_message_test6(abts_case *tc, void *data) static void s1ap_message_test7(abts_case *tc, void *data) { /* InitialUE(Service Request) */ - char *payload = + const char *payload = "000c402d000005000800020071001a00 0504c706b410004300060013f1890001" "006440080013f189400bb75000864001 40006440080013f189400bb750004340" "060013f18900014300060013f1890001 006440080013f189400db09000864001" diff --git a/tests/unit/security-test.c b/tests/unit/security-test.c index 783844bc9..f4922fe71 100644 --- a/tests/unit/security-test.c +++ b/tests/unit/security-test.c @@ -26,19 +26,19 @@ static void security_test1(abts_case *tc, void *data) { - char *_k = "465b5ce8 b199b49f aa5f0a2e e238a6bc"; - char *_rand = "23553cbe 9637a89d 218ae64d ae47bf35"; - char *_sqn = "ff9bb4d0 b607"; - char *_amf = "b9b9"; - char *_op = "cdc202d5 123e20f6 2b6d676a c72cb318"; - char *_opc = "cd63cb71 954a9f4e 48a5994e 37a02baf"; - char *_mac_a = "4a9ffac3 54dfafb3"; - char *_mac_s = "01cfaf9e c4e871e9"; - char *_res = "a54211d5 e3ba50bf"; - char *_ck = "b40ba9a3 c58b2a05 bbf0d987 b21bf8cb"; - char *_ik = "f769bcd7 51044604 12767271 1c6d3441"; - char *_ak = "aa689c64 8370"; - char *_akstar = "451e8bec a43b"; + const char *_k = "465b5ce8 b199b49f aa5f0a2e e238a6bc"; + const char *_rand = "23553cbe 9637a89d 218ae64d ae47bf35"; + const char *_sqn = "ff9bb4d0 b607"; + const char *_amf = "b9b9"; + const char *_op = "cdc202d5 123e20f6 2b6d676a c72cb318"; + const char *_opc = "cd63cb71 954a9f4e 48a5994e 37a02baf"; + const char *_mac_a = "4a9ffac3 54dfafb3"; + const char *_mac_s = "01cfaf9e c4e871e9"; + const char *_res = "a54211d5 e3ba50bf"; + const char *_ck = "b40ba9a3 c58b2a05 bbf0d987 b21bf8cb"; + const char *_ik = "f769bcd7 51044604 12767271 1c6d3441"; + const char *_ak = "aa689c64 8370"; + const char *_akstar = "451e8bec a43b"; uint8_t k[16]; uint8_t rand[16]; @@ -81,9 +81,9 @@ static void security_test1(abts_case *tc, void *data) static void security_test2(abts_case *tc, void *data) { - char *_key = "4a656665"; - char *_message = "7768617420646f2079612077616e7420666f72206e6f7468696e673f"; - char *_hmac = "5bdcc146bf60754e6a042426089575c75a003f089d2739839dec58b964ec3843"; + const char *_key = "4a656665"; + const char *_message = "7768617420646f2079612077616e7420666f72206e6f7468696e673f"; + const char *_hmac = "5bdcc146bf60754e6a042426089575c75a003f089d2739839dec58b964ec3843"; uint8_t key[4]; uint8_t message[28]; @@ -99,12 +99,12 @@ static void security_test2(abts_case *tc, void *data) static void security_test3(abts_case *tc, void *data) { - char *_ck = "b40ba9a3c58b2a05 bbf0d987b21bf8cb"; - char *_ik = "f769bcd751044604 127672711c6d3441"; - char *_plmn_id = "024830"; - char *_sqn = "fd8eef40df7d"; - char *_ak = "aa689c648370"; - char *_kasme = + const char *_ck = "b40ba9a3c58b2a05 bbf0d987b21bf8cb"; + const char *_ik = "f769bcd751044604 127672711c6d3441"; + const char *_plmn_id = "024830"; + const char *_sqn = "fd8eef40df7d"; + const char *_ak = "aa689c648370"; + const char *_kasme = "238e457e0f758bad bca8d34bb2612c10 428d426757cb5553 b2b184fa64bfc549"; uint8_t ck[16]; uint8_t ik[16]; @@ -130,9 +130,9 @@ static void security_test4(abts_case *tc, void *data) { #define SECURITY_TEST4_BIT_LEN 88 #define SECURITY_TEST4_LEN ((SECURITY_TEST4_BIT_LEN+7)/8) - char *_ik = "2bd6459f 82c5b300 952c4910 4881ff48"; - char *_message = "33323462 63393861 37347900 00000000"; - char *_mact = "731f1165"; + const char *_ik = "2bd6459f 82c5b300 952c4910 4881ff48"; + const char *_message = "33323462 63393861 37347900 00000000"; + const char *_mact = "731f1165"; uint8_t ik[16]; uint8_t message[SECURITY_TEST4_LEN]; uint8_t mact[4]; @@ -141,7 +141,7 @@ static void security_test4(abts_case *tc, void *data) ogs_pkbuf_t *pkbuf = NULL; snow_3g_f9(OGS_HEX(_ik, strlen(_ik), ik), - 0x38a6f056, (0x1f << 27), 0, + 0x38a6f056, ((int64_t)0x1f << 27), 0, OGS_HEX(_message, strlen(_message), message), SECURITY_TEST4_BIT_LEN, mact); ABTS_TRUE(tc, memcmp(mact, OGS_HEX(_mact, strlen(_mact), tmp), 4) == 0); @@ -160,8 +160,8 @@ static void security_test5(abts_case *tc, void *data) { #define SECURITY_TEST5_BIT_LEN 800 #define SECURITY_TEST5_LEN ((SECURITY_TEST5_BIT_LEN+7)/8) - char *_ck = "2bd6459f 82c5b300 952c4910 4881ff48"; - char *_plain = + const char *_ck = "2bd6459f 82c5b300 952c4910 4881ff48"; + const char *_plain = "7ec61272 743bf161 4726446a 6c38ced1" "66f6ca76 eb543004 4286346c ef130f92" "922b0345 0d3a9975 e5bd2ea0 eb55ad8e" @@ -169,7 +169,7 @@ static void security_test5(abts_case *tc, void *data) "59b7bdfd 39bef4b2 484583d5 afe082ae" "e638bf5f d5a60619 3901a08f 4ab41aab" "9b134880"; - char *_cipher = + const char *_cipher = "8ceba629 43dced3a 0990b06e a1b0a2c4" "fb3cedc7 1b369f42 ba64c1eb 6665e72a" "a1c9bb0d eaa20fe8 6058b8ba ee2c2e7f" @@ -206,9 +206,9 @@ static void security_test6(abts_case *tc, void *data) { #define SECURITY_TEST6_BIT_LEN 64 #define SECURITY_TEST6_LEN ((SECURITY_TEST6_BIT_LEN+7)/8) - char *_ik = "d3c5d592 327fb11c 4035c668 0af8c6d1"; - char *_message = "484583d5 afe082ae"; - char *_mact = "b93787e6"; + const char *_ik = "d3c5d592 327fb11c 4035c668 0af8c6d1"; + const char *_message = "484583d5 afe082ae"; + const char *_mact = "b93787e6"; uint8_t ik[16]; uint8_t message[SECURITY_TEST6_LEN]; uint8_t mact[16]; @@ -245,13 +245,13 @@ static void security_test7(abts_case *tc, void *data) { #define SECURITY_TEST7_BIT_LEN 800 #define SECURITY_TEST7_LEN ((SECURITY_TEST7_BIT_LEN+7)/8) - char *_ck = "2bd6459f 82c440e0 952c4910 4805ff48"; - char *_plain = + const char *_ck = "2bd6459f 82c440e0 952c4910 4805ff48"; + const char *_plain = "7ec61272 743bf161 4726446a 6c38ced1 66f6ca76 eb543004 4286346c ef130f92" "922b0345 0d3a9975 e5bd2ea0 eb55ad8e 1b199e3e c4316020 e9a1b285 e7627953" "59b7bdfd 39bef4b2 484583d5 afe082ae e638bf5f d5a60619 3901a08f 4ab41aab" "9b134880"; - char *_cipher = + const char *_cipher = "59616053 53c64bdc a15b195e 288553a9 10632506 d6200aa7 90c4c806 c99904cf" "2445cc50 bb1cf168 a4967373 4e081b57 e324ce52 59c0e78d 4cd97b87 0976503c" "0943f2cb 5ae8f052 c7b7d392 239587b8 956086bc ab188360 42e2e6ce 42432a17" @@ -300,12 +300,12 @@ static void security_test8(abts_case *tc, void *data) { #define SECURITY_TEST8_BIT_LEN 584 #define SECURITY_TEST8_LEN ((SECURITY_TEST8_BIT_LEN+7)/8) - char *_ik = "c9 e6 ce c4 60 7c 72 db 00 0a ef a8 83 85 ab 0a"; - char *_message = + const char *_ik = "c9 e6 ce c4 60 7c 72 db 00 0a ef a8 83 85 ab 0a"; + const char *_message = "983b41d4 7d780c9e 1ad11d7e b70391b1 de0b35da 2dc62f83 e7b78d63 06ca0ea0" "7e941b7b e91348f9 fcb170e2 217fecd9 7f9f68ad b16e5d7d 21e569d2 80ed775c" "ebde3f40 93c53881 00000000"; - char *_mact = "24a842b3"; + const char *_mact = "24a842b3"; uint8_t ik[16]; uint8_t message[SECURITY_TEST8_LEN]; uint8_t mact[4]; @@ -340,10 +340,10 @@ static void security_test9(abts_case *tc, void *data) { #define SECURITY_TEST9_BIT_LEN 200 #define SECURITY_TEST9_LEN ((SECURITY_TEST9_BIT_LEN+7)/8) - char *_ck = "17 3d 14 ba 50 03 73 1d 7a 60 04 94 70 f0 0a 29"; - char *_plain = + const char *_ck = "17 3d 14 ba 50 03 73 1d 7a 60 04 94 70 f0 0a 29"; + const char *_plain = "6cf65340 735552ab 0c9752fa 6f9025fe 0bd675d9 005875b2 00000000"; - char *_cipher = + const char *_cipher = "a6c85fc6 6afb8533 aafc2518 dfe78494 0ee1e4b0 30238cc8 10000000"; uint8_t ck[16]; uint8_t plain[SECURITY_TEST9_LEN]; diff --git a/tests/volte/abts-main.c b/tests/volte/abts-main.c index 3d0ce284b..290db531e 100644 --- a/tests/volte/abts-main.c +++ b/tests/volte/abts-main.c @@ -40,7 +40,7 @@ static void terminate(void) { ogs_msleep(50); - epc_child_terminate(); + test_child_terminate(); if (mme_thread) ogs_thread_destroy(mme_thread); if (hss_thread) ogs_thread_destroy(hss_thread); @@ -56,18 +56,18 @@ static void terminate(void) ogs_app_terminate(); } -static void initialize(char **argv) +static void initialize(const char *const argv[]) { int rv; rv = ogs_app_initialize(NULL, argv); ogs_assert(rv == OGS_OK); - pcrf_thread = epc_child_create("nextepc-pcrfd", argv); - pgw_thread = epc_child_create("nextepc-pgwd", argv); - sgw_thread = epc_child_create("nextepc-sgwd", argv); - hss_thread = epc_child_create("nextepc-hssd", argv); - mme_thread = epc_child_create("nextepc-mmed", argv); + pcrf_thread = test_child_create("pcrf", argv); + pgw_thread = test_child_create("pgw", argv); + sgw_thread = test_child_create("sgw", argv); + hss_thread = test_child_create("hss", argv); + mme_thread = test_child_create("mme", argv); test_app_init(); ogs_sctp_init(ogs_config()->usrsctp.udp_port); @@ -76,13 +76,13 @@ static void initialize(char **argv) ogs_assert(rv == OGS_OK); } -int main(int argc, char **argv) +int main(int argc, const char *const argv[]) { int i; abts_suite *suite = NULL; atexit(terminate); - test_app_run(argc, argv, "sample-volte.conf", initialize); + test_app_run(argc, argv, "volte.yaml", initialize); for (i = 0; alltests[i].func; i++) suite = alltests[i].func(suite); diff --git a/tests/volte/meson.build b/tests/volte/meson.build new file mode 100644 index 000000000..0908b8ea6 --- /dev/null +++ b/tests/volte/meson.build @@ -0,0 +1,32 @@ +# Copyright (C) 2019 by Sukchan Lee + +# This file is part of Open5GS. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +testvolte_sources = files(''' + pcscf-fd-path.h + pcscf-fd-path.c + + abts-main.c + volte-test.c +'''.split()) + +testvolte_exe = executable('volte', + sources : testvolte_sources, + c_args : [testcore_cc_flags, + '-DFD_EXT_DIR="@0@"'.format(freediameter_extensions_builddir)], + dependencies : libtestapp_dep) + +test('volte', testvolte_exe, is_parallel : false, suite: 'system') diff --git a/tests/volte/pcscf-fd-path.c b/tests/volte/pcscf-fd-path.c index c3fa5ad0f..5f9986017 100644 --- a/tests/volte/pcscf-fd-path.c +++ b/tests/volte/pcscf-fd-path.c @@ -18,7 +18,7 @@ */ #include "ogs-gtp.h" -#include "diameter/ogs-rx.h" +#include "ogs-diameter-rx.h" #include "pcscf-fd-path.h" @@ -598,7 +598,7 @@ static int pcscf_rx_asr_cb( struct msg **msg, struct avp *avp, } /* Set the Origin-Host, Origin-Realm, andResult-Code AVPs */ - ret = fd_msg_rescode_set(ans, "DIAMETER_SUCCESS", NULL, NULL, 1); + ret = fd_msg_rescode_set(ans, (char*)"DIAMETER_SUCCESS", NULL, NULL, 1); ogs_assert(ret == 0); /* Store this value in the session */ @@ -847,7 +847,7 @@ out: return; } -void pcscf_diam_config() +void pcscf_diam_config(void) { memset(&diam_config, 0, sizeof(ogs_diam_config_t)); @@ -859,26 +859,26 @@ void pcscf_diam_config() diam_config.cnf_addr = "127.0.0.1"; diam_config.ext[diam_config.num_of_ext].module = - FD_EXT_DIR "/dbg_msg_dumps/.libs/dbg_msg_dumps.so"; + FD_EXT_DIR OGS_DIR_SEPARATOR_S "dbg_msg_dumps.fdx"; diam_config.ext[diam_config.num_of_ext].conf = "0x8888"; diam_config.num_of_ext++; diam_config.ext[diam_config.num_of_ext].module = - FD_EXT_DIR "/dict_rfc5777/.libs/dict_rfc5777.so"; + FD_EXT_DIR OGS_DIR_SEPARATOR_S "dict_rfc5777.fdx"; diam_config.num_of_ext++; diam_config.ext[diam_config.num_of_ext].module = - FD_EXT_DIR "/dict_mip6i/.libs/dict_mip6i.so"; + FD_EXT_DIR OGS_DIR_SEPARATOR_S "dict_mip6i.fdx"; diam_config.num_of_ext++; diam_config.ext[diam_config.num_of_ext].module = - FD_EXT_DIR "/dict_nasreq/.libs/dict_nasreq.so"; + FD_EXT_DIR OGS_DIR_SEPARATOR_S "dict_nasreq.fdx"; diam_config.num_of_ext++; diam_config.ext[diam_config.num_of_ext].module = - FD_EXT_DIR "/dict_nas_mipv6/.libs/dict_nas_mipv6.so"; + FD_EXT_DIR OGS_DIR_SEPARATOR_S "dict_nas_mipv6.fdx"; diam_config.num_of_ext++; diam_config.ext[diam_config.num_of_ext].module = - FD_EXT_DIR "/dict_dcca/.libs/dict_dcca.so"; + FD_EXT_DIR OGS_DIR_SEPARATOR_S "dict_dcca.fdx"; diam_config.num_of_ext++; diam_config.ext[diam_config.num_of_ext].module = - FD_EXT_DIR "/dict_dcca_3gpp/.libs/dict_dcca_3gpp.so"; + FD_EXT_DIR OGS_DIR_SEPARATOR_S "dict_dcca_3gpp.fdx"; diam_config.num_of_ext++; diam_config.conn[diam_config.num_of_conn].identity = "pcrf.open-ims.test"; diff --git a/webui/package-lock.json b/webui/package-lock.json index 045564985..c11ef13a1 100644 --- a/webui/package-lock.json +++ b/webui/package-lock.json @@ -1,6 +1,6 @@ { - "name": "nextepc", - "version": "0.5.1", + "name": "open5gs", + "version": "1.0.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/webui/package.json b/webui/package.json index f32759de5..c32a56905 100644 --- a/webui/package.json +++ b/webui/package.json @@ -1,10 +1,10 @@ { - "name": "nextepc", - "version": "0.5.1", - "description": "NextEPC", + "name": "open5gs", + "version": "1.0.0", + "description": "Open5gs", "main": "index.js", - "repository": "https://github.com/acetcom/nextepc", - "author": "NextEPC Group", + "repository": "https://github.com/open5gs/webui", + "author": "Open5gs Group", "license": "GPL-3.0", "dependencies": { "axios": "^0.16.2", diff --git a/webui/pages/_document.js b/webui/pages/_document.js index da9e383eb..e48386467 100644 --- a/webui/pages/_document.js +++ b/webui/pages/_document.js @@ -11,13 +11,13 @@ export default class MyDocument extends Document { return ( - NextEPC + Open5GS - + diff --git a/webui/server/index.js b/webui/server/index.js index a39637eec..e16098a7d 100644 --- a/webui/server/index.js +++ b/webui/server/index.js @@ -1,4 +1,4 @@ -process.env.DB_URI = process.env.DB_URI || 'mongodb://localhost/nextepc'; +process.env.DB_URI = process.env.DB_URI || 'mongodb://localhost/open5gs'; const co = require('co'); const next = require('next'); diff --git a/webui/src/components/Base/Login.js b/webui/src/components/Base/Login.js index ae97129b5..9c7e88668 100644 --- a/webui/src/components/Base/Login.js +++ b/webui/src/components/Base/Login.js @@ -168,7 +168,7 @@ const Login = ({ }) => (
    - NextEPC - Login + Open5gs - Login