diff --git a/README.txt b/README.txt index aec938c0d341e147599279c7c3a315d1aee63fd3..33c0df9d8dfe323fa9c367579d12727ae648b7a7 100644 --- a/README.txt +++ b/README.txt @@ -61,3 +61,4 @@ v1.0.0 -> January 2019. This version first implements the architectural split de S1-flex has been introduced. New tools: config library, telnet server, ... A lot of bugfixes and a proper automated Continuous Integration process validates contributions. +v1.0.1 -> February 2019: Bug fix for the UE L1 simulator. diff --git a/ci-scripts/Jenkinsfile-gitlab b/ci-scripts/Jenkinsfile-gitlab index fc0290fc44c2a03ed428511fb067b86c16ace0aa..f59208ed8b7a20b5bad87b0feb976307e7462047 100644 --- a/ci-scripts/Jenkinsfile-gitlab +++ b/ci-scripts/Jenkinsfile-gitlab @@ -104,6 +104,7 @@ pipeline { } else { echo "Git Branch is ${GIT_BRANCH}" echo "Git Commit is ${GIT_COMMIT}" + sh "git log -n1 --pretty=format:\"%s\" > .git/CI_COMMIT_MSG" sh "zip -r -qq localZip.zip ." // Running astyle options on all C/H files in the repository @@ -260,7 +261,7 @@ pipeline { expression {doRedHatBuild} } steps { - gitlabCommitStatus(name: "Build eNb-USRP-CentOS") { + gitlabCommitStatus(name: "Build eNb-USRP-RHE") { script { try { withCredentials([ @@ -572,6 +573,10 @@ OAI CI Team''', replyTo: 'no-reply@openairinterface.org', subject: '$PROJECT_NAME - Build # $BUILD_NUMBER - $BUILD_STATUS!', to: env.gitlabUserEmail + + if (fileExists('.git/CI_COMMIT_MSG')) { + sh "rm -f .git/CI_COMMIT_MSG" + } } } success { diff --git a/ci-scripts/cppcheck_suppressions.list b/ci-scripts/cppcheck_suppressions.list new file mode 100644 index 0000000000000000000000000000000000000000..d5aea7ae9d76b0230c9a8252d0653ee0e25876ae --- /dev/null +++ b/ci-scripts/cppcheck_suppressions.list @@ -0,0 +1,92 @@ +// *INDENT-OFF* cppcheck doesn't like "astyling" this file!!!! +// /* +// * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more +// * contributor license agreements. See the NOTICE file distributed with +// * this work for additional information regarding copyright ownership. +// * The OpenAirInterface Software Alliance licenses this file to You under +// * the OAI Public License, Version 1.1 (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.openairinterface.org/?page_id=698 +// * +// * 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. +// *------------------------------------------------------------------------------- +// * For more information about the OpenAirInterface (OAI) Software Alliance: +// * contact@openairinterface.org +// */ +//***************************************************************************** +//***************************************************************************** +// section for "valid" memory leaks: the related functions are allocators and +// the caller is responsible of freeing the memory. cppcheck has a mechanism +// to check more accuretaly this, by defining callers responsible of freeing +// but tools like valgring might be more suitable +// +//----------------------------------------------------------------------------- +// suppress error about keysP memory leak, free must be done by calling func +memleak:common/utils/hashtable/obj_hashtable.c +//----------------------------------------------------------------------------- +// suppress error about keys memory leak, free must be done by calling func +memleak:openair2/UTIL/OMG/omg_hashtable.c +//----------------------------------------------------------------------------- +// suppress error about data memory leak. This is the buffer where +// _emm_as_encode function creates the encoded buffer +// +memleak:openair3/NAS/UE/EMM/SAP/emm_as.c +//----------------------------------------------------------------------------- +//***************************************************************************** +// section for files not used in oai exec's included in CI. +// Possibly candidates for removal otherwise should be documented and updated +// for project rules enforcement +// ---------------------------------------------------------------------------- +// likely sources for test programs, maintained? +invalidPrintfArgType_sint:openair1/PHY/CODING/TESTBENCH/ltetest.c +memleak:openair1/PHY/CODING/TESTBENCH/ltetest.c +invalidPrintfArgType_sint:openair1/PHY/CODING/TESTBENCH/pdcch_test.c +// +//----------------------------------------------------------------------------- +// oaisim deprecated, remove? +doubleFree:openair3/TEST/oaisim_mme_list_benchmark.c +// +//----------------------------------------------------------------------------- +// is itti analyzer deprecated +nullPointer:common/utils/itti_analyzer/itti_analyzer.c +nullPointerRedundantCheck:common/utils/itti_analyzer/libbuffers/buffers.c +doubleFree:common/utils/itti_analyzer/libbuffers/socket.c +memleak:common/utils/itti_analyzer/libbuffers/socket.c +memleak:common/utils/itti_analyzer/libparser/array_type.c +memleak:common/utils/itti_analyzer/libui/ui_callbacks.c +//----------------------------------------------------------------------------- +// obviously never even compiled!!! +syntaxError:openair1/SIMULATION/LTE_PHY/dlsim_tm4.c +//----------------------------------------------------------------------------- +// omg, otg commented out in cmakelist to be cleaned up definitely? +arrayIndexOutOfBounds:openair2/UTIL/OMG/omg.c +uninitvar:openair2/UTIL/OTG/otg_rx_socket.c +// +//***************************************************************************** +// +// True problems we don't know how to fix, Suppression is commented out, +// as these kind of problem need either to be fixed or can be suppressed +// when fully uderstood +//----------------------------------------------------------------------------- +// the function [nv]fapi_pnf_p7_config_create should return +// _this. _this points to a structure and a dynamically allocated field is +// returned. cppcheck suspects _this will never be released, so do i +// memleak:nfapi/open-nFAPI/pnf/src/pnf_p7_interface.c +// memleak:nfapi/open-nFAPI/vnf/src/vnf_p7_interface.c +//----------------------------------------------------------------------------- +// may be security_data->kenb.value is released from calling functions. But even +// when, for test, freeing it before returning from emm_proc_security_mode_command +// which does the allocation, cppcheck complains. So something might be wrong... +// memleak:openair3/NAS/UE/EMM/SecurityModeControl.c +//----------------------------------------------------------------------------- +// when used, nobody but the original developer can guess if sn_data_cnf is set or not +// cppcheck found that in some cases it is not, code needs cleanup before fixing that... +// uninitvar:openair2/LAYER2/RLC/AM_v9.3.0/rlc_am_status_report.c +//***************************************************************************** +// *INDENT-ON* diff --git a/ci-scripts/doGitLabMerge.sh b/ci-scripts/doGitLabMerge.sh index 852b6407eabf34ab822aa67d6f99780f68e61475..6c9ee12b4ede0a9a2ef7d4b14badc9fa3a779baf 100755 --- a/ci-scripts/doGitLabMerge.sh +++ b/ci-scripts/doGitLabMerge.sh @@ -121,6 +121,7 @@ git config user.email "jenkins@openairinterface.org" git config user.name "OAI Jenkins" git checkout -f $SOURCE_COMMIT_ID +git log -n1 --pretty=format:\"%s\" > .git/CI_COMMIT_MSG git merge --ff $TARGET_COMMIT_ID -m "Temporary merge for CI" diff --git a/ci-scripts/oai-ci-vm-tool b/ci-scripts/oai-ci-vm-tool index 6e0a83e07dcde0b825e5a04f191b99ff362750b0..c28f51415ef5690b07af79e592f2d749d67b329a 100755 --- a/ci-scripts/oai-ci-vm-tool +++ b/ci-scripts/oai-ci-vm-tool @@ -264,7 +264,7 @@ case $key in ARCHIVES_LOC=cppcheck LOG_PATTERN=cppcheck.xml NB_PATTERN_FILES=1 - BUILD_OPTIONS="--enable=warning --force --xml --xml-version=2" + BUILD_OPTIONS="--enable=warning --force --xml --xml-version=2 --suppressions-list=ci-scripts/cppcheck_suppressions.list" NBARGS=$[$NBARGS+256] shift ;; @@ -340,11 +340,11 @@ case $key in ;; cppcheck) VM_NAME=ci-cppcheck - VM_MEMORY=8192 + VM_MEMORY=4096 ARCHIVES_LOC=cppcheck LOG_PATTERN=cppcheck.xml NB_PATTERN_FILES=1 - BUILD_OPTIONS="--enable=warning --force --xml --xml-version=2" + BUILD_OPTIONS="--enable=warning --force --xml --xml-version=2 --suppressions-list=ci-scripts/cppcheck_suppressions.list" NBARGS=$[$NBARGS+256] ;; enb-ethernet) diff --git a/ci-scripts/reportBuildLocally.sh b/ci-scripts/reportBuildLocally.sh index bfce7acd8fe241ecaea8f4028fe2763eb2cec629..08d2f784436188a6ac040c91e40c676bfac10e1c 100755 --- a/ci-scripts/reportBuildLocally.sh +++ b/ci-scripts/reportBuildLocally.sh @@ -363,6 +363,14 @@ function report_build { echo " <td bgcolor = \"lightcyan\" > <span class=\"glyphicon glyphicon-tag\"></span> Commit ID</td>" >> ./build_results.html echo " <td>$SOURCE_COMMIT_ID</td>" >> ./build_results.html echo " </tr>" >> ./build_results.html + if [ -e .git/CI_COMMIT_MSG ] + then + echo " <tr>" >> ./build_results.html + echo " <td bgcolor = \"lightcyan\" > <span class=\"glyphicon glyphicon-comment\"></span> Commit Message</td>" >> ./build_results.html + MSG=`cat .git/CI_COMMIT_MSG` + echo " <td>$MSG</td>" >> ./build_results.html + echo " </tr>" >> ./build_results.html + fi fi if [ $MR_TRIG -eq 1 ] then @@ -374,6 +382,14 @@ function report_build { echo " <td bgcolor = \"lightcyan\" > <span class=\"glyphicon glyphicon-tag\"></span> Source Commit ID</td>" >> ./build_results.html echo " <td>$SOURCE_COMMIT_ID</td>" >> ./build_results.html echo " </tr>" >> ./build_results.html + if [ -e .git/CI_COMMIT_MSG ] + then + echo " <tr>" >> ./build_results.html + echo " <td bgcolor = \"lightcyan\" > <span class=\"glyphicon glyphicon-comment\"></span> Source Commit Message</td>" >> ./build_results.html + MSG=`cat .git/CI_COMMIT_MSG` + echo " <td>$MSG</td>" >> ./build_results.html + echo " </tr>" >> ./build_results.html + fi echo " <tr>" >> ./build_results.html echo " <td bgcolor = \"lightcyan\" > <span class=\"glyphicon glyphicon-log-in\"></span> Target Branch</td>" >> ./build_results.html echo " <td>$TARGET_BRANCH</td>" >> ./build_results.html @@ -492,7 +508,7 @@ function report_build { if [ -e ./archives/red_hat ] then - echo " <h2>Red Hat (CentOS Linux release 7.4.1708) -- Summary</h2>" >> ./build_results.html + echo " <h2>Red Hat Enterprise Linux Server release 7.6) -- Summary</h2>" >> ./build_results.html summary_table_header "Red Hat -- OAI Build eNB -- USRP option" ./archives/red_hat summary_table_row "LTE SoftModem - Release 14" ./archives/red_hat/lte-softmodem.Rel14.txt "Built target lte-softmodem" ./enb_usrp_rh_row1.html diff --git a/ci-scripts/reportTestLocally.sh b/ci-scripts/reportTestLocally.sh index 004e021de10b293912a5c37774a531d40bf5ca59..63dc724b84296ef4b1cee5ca8816cc324d317066 100755 --- a/ci-scripts/reportTestLocally.sh +++ b/ci-scripts/reportTestLocally.sh @@ -139,6 +139,14 @@ function report_test { echo " <td bgcolor = \"lightcyan\" > <span class=\"glyphicon glyphicon-tag\"></span> Commit ID</td>" >> ./test_simulator_results.html echo " <td>$SOURCE_COMMIT_ID</td>" >> ./test_simulator_results.html echo " </tr>" >> ./test_simulator_results.html + if [ -e .git/CI_COMMIT_MSG ] + then + echo " <tr>" >> ./test_simulator_results.html + echo " <td bgcolor = \"lightcyan\" > <span class=\"glyphicon glyphicon-comment\"></span> Commit Message</td>" >> ./test_simulator_results.html + MSG=`cat .git/CI_COMMIT_MSG` + echo " <td>$MSG</td>" >> ./test_simulator_results.html + echo " </tr>" >> ./test_simulator_results.html + fi fi if [ $MR_TRIG -eq 1 ] then @@ -150,6 +158,14 @@ function report_test { echo " <td bgcolor = \"lightcyan\" > <span class=\"glyphicon glyphicon-tag\"></span> Source Commit ID</td>" >> ./test_simulator_results.html echo " <td>$SOURCE_COMMIT_ID</td>" >> ./test_simulator_results.html echo " </tr>" >> ./test_simulator_results.html + if [ -e .git/CI_COMMIT_MSG ] + then + echo " <tr>" >> ./test_simulator_results.html + echo " <td bgcolor = \"lightcyan\" > <span class=\"glyphicon glyphicon-comment\"></span> Commit Message</td>" >> ./test_simulator_results.html + MSG=`cat .git/CI_COMMIT_MSG` + echo " <td>$MSG</td>" >> ./test_simulator_results.html + echo " </tr>" >> ./test_simulator_results.html + fi echo " <tr>" >> ./test_simulator_results.html echo " <td bgcolor = \"lightcyan\" > <span class=\"glyphicon glyphicon-log-in\"></span> Target Branch</td>" >> ./test_simulator_results.html echo " <td>$TARGET_BRANCH</td>" >> ./test_simulator_results.html diff --git a/ci-scripts/runTestOnVM.sh b/ci-scripts/runTestOnVM.sh index 7ff04e23f89bdbab5583387a29a55cfc97c56810..9aa6606eea8a7cf7c059942218d9fae727256380 100755 --- a/ci-scripts/runTestOnVM.sh +++ b/ci-scripts/runTestOnVM.sh @@ -569,6 +569,7 @@ function start_l2_sim_enb { ENB_SYNC=1 echo "L2-SIM eNB is sync'ed: waiting for UE(s) to connect" fi + sleep 10 } function start_l2_sim_ue { @@ -604,10 +605,34 @@ function start_l2_sim_ue { if [ $i -lt 50 ] then UE_SYNC=0 - echo "L2-SIM UE is NOT sync'ed w/eNB" + echo "L2-SIM UE is NOT sync'ed w/ eNB" + return + else + UE_SYNC=1 + echo "L2-SIM UE is sync'ed w/ eNB" + fi + # Checking oip1 interface has now an IP address + i="0" + echo "ifconfig oip1 | egrep -c \"inet addr\"" > $1 + while [ $i -lt 10 ] + do + sleep 5 + CONNECTED=`ssh -o StrictHostKeyChecking=no ubuntu@$LOC_VM_IP_ADDR < $1` + if [ $CONNECTED -eq 1 ] + then + i="100" + else + i=$[$i+1] + fi + done + rm $1 + if [ $i -lt 50 ] + then + UE_SYNC=0 + echo "L2-SIM UE oip1 is NOT sync'ed w/ EPC" else UE_SYNC=1 - echo "L2-SIM UE is sync'ed w/eNB" + echo "L2-SIM UE oip1 is sync'ed w/ EPC" fi sleep 10 } diff --git a/cmake_targets/tools/build_helper b/cmake_targets/tools/build_helper index acfb75b1a8531a0a67bcf1c5bcdebd0e9d3c2872..048ba300e7ba5db425437b3905981c79d8bdd4f8 100755 --- a/cmake_targets/tools/build_helper +++ b/cmake_targets/tools/build_helper @@ -102,6 +102,7 @@ check_supported_distribution() { "ubuntu14.04") return 0 ;; "fedora24") return 0 ;; "rhel7") return 0 ;; + "rhel7.6") return 0 ;; "centos7") return 0 ;; esac return 1 @@ -310,10 +311,20 @@ install_usrp_uhd_driver() { # On newer kernels, it fails to install $SUDO apt-get -y install uhd-host fi + # quick workaround for RHE7.6 + local distribution=$(get_distribution_release) if [ -z $1 ]; then - $SUDO uhd_images_downloader + if [[ "$distribution" == "rhel7.6" ]]; then + $SUDO /usr/local/bin/uhd_images_downloader + else + $SUDO uhd_images_downloader + fi else - $SUDO uhd_images_downloader -i $1 + if [[ "$distribution" == "rhel7.6" ]]; then + $SUDO /usr/local/bin/uhd_images_downloader -i $1 + else + $SUDO uhd_images_downloader -i $1 + fi fi } diff --git a/common/config/config_cmdline.c b/common/config/config_cmdline.c index 4d32e9726fd86f0eaf8b820459cfa917ee8a7fd8..0083c2e66bf779924e549c1ee3506d8a721824e8 100644 --- a/common/config/config_cmdline.c +++ b/common/config/config_cmdline.c @@ -166,13 +166,14 @@ int config_check_unknown_cmdlineopt(char *prefix) { int unknowndetected=0; char testprefix[CONFIG_MAXOPTLENGTH]; int finalcheck = 0; + memset(testprefix,0,sizeof(testprefix)); memset(testprefix,0,sizeof(testprefix)); if (prefix != NULL) { if (strcmp(prefix,CONFIG_CHECKALLSECTIONS) == 0) finalcheck = 1; else if (strlen(prefix) > 0) { - sprintf(testprefix,"--%.*s.",CONFIG_MAXOPTLENGTH-1,prefix); + sprintf(testprefix,"--%.*s.",CONFIG_MAXOPTLENGTH-4,prefix); } } diff --git a/common/utils/T/local_tracer.c b/common/utils/T/local_tracer.c index f8e92881a96e79a000e57fcad814e8440719a895..4be0b35d16a28c3fa9492e5a60a81401d0ff9e5e 100644 --- a/common/utils/T/local_tracer.c +++ b/common/utils/T/local_tracer.c @@ -31,7 +31,7 @@ typedef struct { int remote_port; pthread_mutex_t lock; pthread_cond_t cond; - databuf * volatile head, *tail; + databuf *volatile head, *tail; uint64_t memusage; uint64_t last_warning_memusage; } forward_data; @@ -40,80 +40,115 @@ typedef struct { /* utility functions */ /****************************************************************************/ -static void new_thread(void *(*f)(void *), void *data) -{ +static void new_thread(void *(*f)(void *), void *data) { pthread_t t; pthread_attr_t att; - if (pthread_attr_init(&att)) - { fprintf(stderr, "pthread_attr_init err\n"); exit(1); } - if (pthread_attr_setdetachstate(&att, PTHREAD_CREATE_DETACHED)) - { fprintf(stderr, "pthread_attr_setdetachstate err\n"); exit(1); } - if (pthread_attr_setstacksize(&att, 10000000)) - { fprintf(stderr, "pthread_attr_setstacksize err\n"); exit(1); } - if (pthread_create(&t, &att, f, data)) - { fprintf(stderr, "pthread_create err\n"); exit(1); } - if (pthread_attr_destroy(&att)) - { fprintf(stderr, "pthread_attr_destroy err\n"); exit(1); } + if (pthread_attr_init(&att)) { + fprintf(stderr, "pthread_attr_init err\n"); + exit(1); + } + + if (pthread_attr_setdetachstate(&att, PTHREAD_CREATE_DETACHED)) { + fprintf(stderr, "pthread_attr_setdetachstate err\n"); + exit(1); + } + + if (pthread_attr_setstacksize(&att, 10000000)) { + fprintf(stderr, "pthread_attr_setstacksize err\n"); + exit(1); + } + + if (pthread_create(&t, &att, f, data)) { + fprintf(stderr, "pthread_create err\n"); + exit(1); + } + + if (pthread_attr_destroy(&att)) { + fprintf(stderr, "pthread_attr_destroy err\n"); + exit(1); + } } -static int get_connection(char *addr, int port) -{ +static int get_connection(char *addr, int port) { struct sockaddr_in a; socklen_t alen; int s, t; - printf("T tracer: waiting for connection on %s:%d\n", addr, port); - s = socket(AF_INET, SOCK_STREAM, 0); - if (s == -1) { perror("socket"); exit(1); } + + if (s == -1) { + perror("socket"); + exit(1); + } + t = 1; - if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &t, sizeof(int))) - { perror("setsockopt"); exit(1); } + + if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &t, sizeof(int))) { + perror("setsockopt"); + exit(1); + } a.sin_family = AF_INET; a.sin_port = htons(port); a.sin_addr.s_addr = inet_addr(addr); - if (bind(s, (struct sockaddr *)&a, sizeof(a))) { perror("bind"); exit(1); } - if (listen(s, 5)) { perror("bind"); exit(1); } + if (bind(s, (struct sockaddr *)&a, sizeof(a))) { + perror("bind"); + exit(1); + } + + if (listen(s, 5)) { + perror("bind"); + exit(1); + } + alen = sizeof(a); t = accept(s, (struct sockaddr *)&a, &alen); - if (t == -1) { perror("accept"); exit(1); } - close(s); - printf("T tracer: connected\n"); + if (t == -1) { + perror("accept"); + exit(1); + } + close(s); + printf("T tracer: connected\n"); return t; } static void forward(void *_forwarder, char *buf, int size); -void send_T_messages_txt(void *forwarder) -{ +void send_T_messages_txt(void *forwarder) { char buf[T_BUFFER_MAX]; char *T_LOCAL_buf = buf; int T_LOCAL_size; unsigned char *src; int src_len; - /* trace T_message.txt * Send several messages -1 with content followed by message -2. */ src = T_messages_txt; src_len = T_messages_txt_len; + while (src_len) { int send_size = src_len; + if (send_size > T_PAYLOAD_MAXSIZE - sizeof(int)) send_size = T_PAYLOAD_MAXSIZE - sizeof(int); + /* TODO: be careful, we use internal T stuff, to rewrite? */ T_LOCAL_size = 0; T_HEADER(T_ID(-1)); - T_PUT_buffer(1, ((T_buffer){addr:(src), length:(send_size)})); + T_PUT_buffer(1, ((T_buffer) { +addr: +(src), length: + (send_size) + })); forward(forwarder, buf, T_LOCAL_size); src += send_size; src_len -= send_size; } + T_LOCAL_size = 0; T_HEADER(T_ID(-2)); forward(forwarder, buf, T_LOCAL_size); @@ -123,49 +158,54 @@ void send_T_messages_txt(void *forwarder) /* forward functions */ /****************************************************************************/ -static void *data_sender(void *_f) -{ +static void *data_sender(void *_f) { forward_data *f = _f; databuf *cur; char *buf, *b; int size; - wait: + if (pthread_mutex_lock(&f->lock)) abort(); + while (f->head == NULL) if (pthread_cond_wait(&f->cond, &f->lock)) abort(); + cur = f->head; buf = cur->d; size = cur->l; f->head = cur->next; f->memusage -= size; + if (f->head == NULL) f->tail = NULL; + if (pthread_mutex_unlock(&f->lock)) abort(); + free(cur); goto process; - process: b = buf; + if (f->socket_remote != -1) - while (size) { - int l = write(f->socket_remote, b, size); - if (l <= 0) { - printf("T tracer: forward error\n"); - close(f->socket_remote); - f->socket_remote = -1; - break; + while (size) { + int l = write(f->socket_remote, b, size); + + if (l <= 0) { + printf("T tracer: forward error\n"); + close(f->socket_remote); + f->socket_remote = -1; + break; + } + + size -= l; + b += l; } - size -= l; - b += l; - } free(buf); - goto wait; } -static void *forward_remote_messages(void *_f) -{ + +static void *forward_remote_messages(void *_f) { #define PUT(x) do { \ if (bufsize == bufmaxsize) { \ bufmaxsize += 4096; \ @@ -180,7 +220,6 @@ static void *forward_remote_messages(void *_f) int len = l; \ while (len) { PUT(*zz); zz++; len--; } \ } while (0) - forward_data *f = _f; int from; int to; @@ -190,43 +229,53 @@ static void *forward_remote_messages(void *_f) int bufsize = 0; int bufmaxsize = 0; char t; - again: while (1) { from = f->socket_remote; to = f->socket_local; - bufsize = 0; - /* let's read and process messages */ - len = read(from, &t, 1); if (len <= 0) goto dead; + len = read(from, &t, 1); + + if (len <= 0) goto dead; + PUT(t); switch (t) { - case 0: - case 1: - /* message 0 and 1: get a length and then 'length' numbers */ - if (read(from, &len, sizeof(int)) != sizeof(int)) goto dead; - PUT_BUF(&len, 4); - while (len) { - if (read(from, &l, sizeof(int)) != sizeof(int)) goto dead; - PUT_BUF(&l, 4); - len--; - } - break; + case 0: + case 1: + + /* message 0 and 1: get a length and then 'length' numbers */ + if (read(from, &len, sizeof(int)) != sizeof(int)) goto dead; + + PUT_BUF(&len, 4); + + while (len) { + if (read(from, &l, sizeof(int)) != sizeof(int)) goto dead; + + PUT_BUF(&l, 4); + len--; + } + + break; + + case 2: + break; - case 2: break; - default: - printf("%s:%d:%s: unhandled message type %d\n", - __FILE__, __LINE__, __FUNCTION__, t); - abort(); + default: + printf("%s:%d:%s: unhandled message type %d\n", + __FILE__, __LINE__, __FUNCTION__, t); + abort(); } b = buf; + while (bufsize) { l = write(to, b, bufsize); + if (l <= 0) abort(); + bufsize -= l; b += l; } @@ -236,71 +285,80 @@ dead: /* socket died, let's stop all traces and wait for another tracer */ /* TODO: be careful with those write, they might write less than wanted */ buf[0] = 1; + if (write(to, buf, 1) != 1) abort(); + len = T_NUMBER_OF_IDS; + if (write(to, &len, sizeof(int)) != sizeof(int)) abort(); + l = 0; + while (len) { if (write(to, &l, sizeof(int)) != sizeof(int)) abort(); + len--; }; close(f->socket_remote); + f->socket_remote = get_connection("0.0.0.0", f->remote_port); + send_T_messages_txt(f); + goto again; return NULL; } -static void *forwarder(int port, int s) -{ +static void *forwarder(int port, int s) { forward_data *f; + f = malloc(sizeof(*f)); - f = malloc(sizeof(*f)); if (f == NULL) abort(); + if (f == NULL) abort(); pthread_mutex_init(&f->lock, NULL); pthread_cond_init(&f->cond, NULL); - f->socket_local = s; f->head = f->tail = NULL; - f->memusage = 0; f->last_warning_memusage = 0; - printf("T tracer: waiting for remote tracer on port %d\n", port); - f->remote_port = port; f->socket_remote = get_connection("0.0.0.0", port); send_T_messages_txt(f); - new_thread(data_sender, f); new_thread(forward_remote_messages, f); - return f; } -static void forward(void *_forwarder, char *buf, int size) -{ +static void forward(void *_forwarder, char *buf, int size) { forward_data *f = _forwarder; int32_t ssize = size; databuf *new; + new = malloc(sizeof(*new)); - new = malloc(sizeof(*new)); if (new == NULL) abort(); + if (new == NULL) abort(); if (pthread_mutex_lock(&f->lock)) abort(); - new->d = malloc(size + 4); if (new->d == NULL) abort(); + new->d = malloc(size + 4); + + if (new->d == NULL) abort(); + /* put the size of the message at the head */ memcpy(new->d, &ssize, 4); memcpy(new->d+4, buf, size); new->l = size+4; new->next = NULL; + if (f->head == NULL) f->head = new; + if (f->tail != NULL) f->tail->next = new; - f->tail = new; + f->tail = new; #if BASIC_SIMULATOR + /* When runnng the basic simulator, the tracer may be too slow. * Let's not take too much memory in the tracee and * wait if there is too much data to send. 200MB is @@ -308,26 +366,30 @@ static void forward(void *_forwarder, char *buf, int size) */ while (f->memusage > 200 * 1024 * 1024) { if (pthread_cond_signal(&f->cond)) abort(); + if (pthread_mutex_unlock(&f->lock)) abort(); + usleep(1000); + if (pthread_mutex_lock(&f->lock)) abort(); } -#endif /* BASIC_SIMULATOR */ +#endif /* BASIC_SIMULATOR */ f->memusage += size+4; + /* warn every 100MB */ if (f->memusage > f->last_warning_memusage && f->memusage - f->last_warning_memusage > 100000000) { f->last_warning_memusage += 100000000; printf("T tracer: WARNING: memory usage is over %"PRIu64"MB\n", f->last_warning_memusage / 1000000); - } else - if (f->memusage < f->last_warning_memusage && - f->last_warning_memusage - f->memusage > 100000000) { + } else if (f->memusage < f->last_warning_memusage && + f->last_warning_memusage - f->memusage > 100000000) { f->last_warning_memusage = (f->memusage/100000000) * 100000000; } if (pthread_cond_signal(&f->cond)) abort(); + if (pthread_mutex_unlock(&f->lock)) abort(); } @@ -335,14 +397,12 @@ static void forward(void *_forwarder, char *buf, int size) /* local functions */ /****************************************************************************/ -static void wait_message(void) -{ +static void wait_message(void) { while ((T_local_cache[T_busylist_head].busy & 0x02) == 0) usleep(1000); } void T_local_tracer_main(int remote_port, int wait_for_tracer, - int local_socket, void *shm_array) -{ + int local_socket, void *shm_array) { int s; int port = remote_port; int dont_wait = wait_for_tracer ? 0 : 1; @@ -350,16 +410,16 @@ void T_local_tracer_main(int remote_port, int wait_for_tracer, /* write on a socket fails if the other end is closed and we get SIGPIPE */ if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) { - printf("local tracer received SIGPIPE\n"); - abort(); + printf("local tracer received SIGPIPE\n"); + abort(); } T_local_cache = shm_array; - s = local_socket; if (dont_wait) { char t = 2; + if (write(s, &t, 1) != 1) abort(); } diff --git a/common/utils/T/tracer/gui/notify.c b/common/utils/T/tracer/gui/notify.c index 7ff40069411a1bd9bae7d0106b686c41b04b6ef6..84fb161b6ee09421e20cb5231517fe9580dcc3d0 100644 --- a/common/utils/T/tracer/gui/notify.c +++ b/common/utils/T/tracer/gui/notify.c @@ -5,46 +5,41 @@ #include <string.h> unsigned long register_notifier(gui *_g, char *notification, widget *w, - notifier handler, void *private) -{ + notifier handler, void *private) { struct gui *g = _g; unsigned long ret; - glock(g); if (g->next_notifier_id == 2UL * 1024 * 1024 * 1024) ERR("%s:%d: report a bug\n", __FILE__, __LINE__); g->notifiers = realloc(g->notifiers, - (g->notifiers_count+1) * sizeof(struct notifier)); + (g->notifiers_count+1) * sizeof(struct notifier)); + if (g->notifiers == NULL) abort(); ret = g->next_notifier_id; - g->notifiers[g->notifiers_count].handler = handler; g->notifiers[g->notifiers_count].id = g->next_notifier_id; g->next_notifier_id++; g->notifiers[g->notifiers_count].notification = strdup(notification); + if (g->notifiers[g->notifiers_count].notification == NULL) abort(); + g->notifiers[g->notifiers_count].w = w; g->notifiers[g->notifiers_count].private = private; /* initialize done to 1 so as not to call the handler if it's created * by the call of another one that is in progress */ g->notifiers[g->notifiers_count].done = 1; - g->notifiers_count++; - gunlock(g); - return ret; } -void unregister_notifier(gui *_g, unsigned long notifier_id) -{ +void unregister_notifier(gui *_g, unsigned long notifier_id) { struct gui *g = _g; int i; - glock(g); for (i = 0; i < g->notifiers_count; i++) @@ -54,13 +49,12 @@ void unregister_notifier(gui *_g, unsigned long notifier_id) ERR("%s:%d: notifier_id %ld not found\n", __FILE__,__LINE__,notifier_id); free(g->notifiers[i].notification); - memmove(g->notifiers + i, g->notifiers + i + 1, - (g->notifiers_count-1 - i) * sizeof(struct notifier)); - + (g->notifiers_count-1 - i) * sizeof(struct notifier)); g->notifiers_count--; g->notifiers = realloc(g->notifiers, - g->notifiers_count * sizeof(struct notifier)); + g->notifiers_count * sizeof(struct notifier)); + if (g->notifiers == NULL) abort(); gunlock(g); @@ -68,19 +62,19 @@ void unregister_notifier(gui *_g, unsigned long notifier_id) /* called with lock ON */ void gui_notify(struct gui *g, char *notification, widget *w, - void *notification_data) -{ + void *notification_data) { void *private; notifier handler; int i; - /* this function is not re-entrant, for the moment keep as is * and if the need is there, we'll make a new thread to handle * notifications (or something) * for now let's crash in case of recursive call */ static int inside = 0; + if (inside) ERR("%s:%d: BUG! contact the authors\n", __FILE__, __LINE__); + inside = 1; /* clear all handlers */ @@ -91,26 +85,25 @@ void gui_notify(struct gui *g, char *notification, widget *w, * need to be careful here */ loop: + for (i = 0; i < g->notifiers_count; i++) { if (g->notifiers[i].done == 1 || g->notifiers[i].w != w || strcmp(g->notifiers[i].notification, notification) != 0) continue; + break; } + if (i == g->notifiers_count) goto done; g->notifiers[i].done = 1; - handler = g->notifiers[i].handler; private = g->notifiers[i].private; - gunlock(g); handler(private, g, notification, w, notification_data); glock(g); - goto loop; - done: inside = 0; } diff --git a/common/utils/T/tracer/hacks/dump_nack_signal.c b/common/utils/T/tracer/hacks/dump_nack_signal.c index bb8f1a9477bda7894ba8465a068b2825db5e6737..02825202fb14544eb3074da8fdb0dbe1c5323cf6 100644 --- a/common/utils/T/tracer/hacks/dump_nack_signal.c +++ b/common/utils/T/tracer/hacks/dump_nack_signal.c @@ -7,21 +7,19 @@ #include "config.h" #include "../T_defs.h" -void usage(void) -{ +void usage(void) { printf( -"options:\n" -" -d <database file> this option is mandatory\n" -" -ip <host> connect to given IP address (default %s)\n" -" -p <port> connect to given port (default %d)\n", - DEFAULT_REMOTE_IP, - DEFAULT_REMOTE_PORT + "options:\n" + " -d <database file> this option is mandatory\n" + " -ip <host> connect to given IP address (default %s)\n" + " -p <port> connect to given port (default %d)\n", + DEFAULT_REMOTE_IP, + DEFAULT_REMOTE_PORT ); exit(1); } -int main(int n, char **v) -{ +int main(int n, char **v) { char *database_filename = NULL; void *database; char *ip = DEFAULT_REMOTE_IP; @@ -36,11 +34,28 @@ int main(int n, char **v) for (i = 1; i < n; i++) { if (!strcmp(v[i], "-h") || !strcmp(v[i], "--help")) usage(); - if (!strcmp(v[i], "-d")) - { if (i > n-2) usage(); database_filename = v[++i]; continue; } - if (!strcmp(v[i], "-ip")) { if (i > n-2) usage(); ip = v[++i]; continue; } - if (!strcmp(v[i], "-p")) - { if (i > n-2) usage(); port = atoi(v[++i]); continue; } + + if (!strcmp(v[i], "-d")) { + if (i > n-2) usage(); + + database_filename = v[++i]; + continue; + } + + if (!strcmp(v[i], "-ip")) { + if (i > n-2) usage(); + + ip = v[++i]; + continue; + } + + if (!strcmp(v[i], "-p")) { + if (i > n-2) usage(); + + port = atoi(v[++i]); + continue; + } + usage(); } @@ -50,71 +65,92 @@ int main(int n, char **v) } database = parse_database(database_filename); - load_config_file(database_filename); - number_of_events = number_of_ids(database); is_on = calloc(number_of_events, sizeof(int)); + if (is_on == NULL) abort(); on_off(database, "ENB_PHY_INPUT_SIGNAL", is_on, 1); on_off(database, "ENB_PHY_ULSCH_UE_NACK", is_on, 1); on_off(database, "ENB_PHY_ULSCH_UE_ACK", is_on, 1); - ev_input = event_id_from_name(database, "ENB_PHY_INPUT_SIGNAL"); ev_nack = event_id_from_name(database, "ENB_PHY_ULSCH_UE_NACK"); ev_ack = event_id_from_name(database, "ENB_PHY_ULSCH_UE_ACK"); - socket = connect_to(ip, port); - t = 1; + if (socket_send(socket, &t, 1) == -1 || socket_send(socket, &number_of_events, sizeof(int)) == -1 || socket_send(socket, is_on, number_of_events * sizeof(int)) == -1) abort(); OBUF ebuf = { osize: 0, omaxsize: 0, obuf: NULL }; - char dump[10][T_BUFFER_MAX]; event dump_ev[10]; -FILE *z = fopen("/tmp/dd", "w"); if (z == NULL) abort(); + FILE *z = fopen("/tmp/dd", "w"); + + if (z == NULL) abort(); + while (1) { char *v; event e; e = get_event(socket, &ebuf, database); v = ebuf.obuf; + if (e.type == -1) break; + if (e.type == ev_input) { int sf = e.e[2].i; - if (ebuf.osize > T_BUFFER_MAX) - { printf("event size too big\n"); exit(1); } + + if (ebuf.osize > T_BUFFER_MAX) { + printf("event size too big\n"); + exit(1); + } + memcpy(dump[sf], ebuf.obuf, ebuf.osize); dump_ev[sf] = e; printf("input %d/%d\n", e.e[1].i, sf); -if (fwrite(dump_ev[sf].e[4].b, dump_ev[sf].e[4].bsize, 1, z) != 1) abort(); -fflush(z); + + if (fwrite(dump_ev[sf].e[4].b, dump_ev[sf].e[4].bsize, 1, z) != 1) abort(); + + fflush(z); } + if (e.type == ev_nack) { int sf = e.e[2].i; printf("nack %d/%d\n", e.e[1].i, sf); - FILE *f = fopen("/tmp/dump.raw", "w"); if (f == NULL) abort(); + FILE *f = fopen("/tmp/dump.raw", "w"); + + if (f == NULL) abort(); + if (fwrite(dump[sf] + ((char *)dump_ev[sf].e[4].b - v), - dump_ev[sf].e[4].bsize, 1, f) != 1) abort(); + dump_ev[sf].e[4].bsize, 1, f) != 1) abort(); + if (fclose(f)) abort(); + printf("dumped... press enter (delta %d)\n", (int)((char *)dump_ev[sf].e[4].b - v)); -// getchar(); + // getchar(); } + if (e.type == ev_ack) { int sf = e.e[2].i; printf("ack %d/%d\n", e.e[1].i, sf); - FILE *f = fopen("/tmp/dump.raw", "w"); if (f == NULL) abort(); + FILE *f = fopen("/tmp/dump.raw", "w"); + + if (f == NULL) abort(); + if (fwrite(dump[sf] + ((char *)dump_ev[sf].e[4].b - v), - dump_ev[sf].e[4].bsize, 1, f) != 1) abort(); + dump_ev[sf].e[4].bsize, 1, f) != 1) abort(); + if (fclose(f)) abort(); + printf("dumped... press enter (delta %d)\n", (int)((char *)dump_ev[sf].e[4].b - v)); -// getchar(); + // getchar(); } } + if (z) + fclose(z); return 0; } diff --git a/common/utils/T/tracer/macpdu2wireshark.c b/common/utils/T/tracer/macpdu2wireshark.c index d9bcb8b7f5f255cca66ba4a36ffa561687aa0baf..7ea3b70bb40340d2305b9f39d0e0e9fdfda1b9e9 100644 --- a/common/utils/T/tracer/macpdu2wireshark.c +++ b/common/utils/T/tracer/macpdu2wireshark.c @@ -58,14 +58,11 @@ typedef struct { } ev_data; void trace(ev_data *d, int direction, int rnti_type, int rnti, - int frame, int subframe, void *buf, int bufsize, int preamble) -{ + int frame, int subframe, void *buf, int bufsize, int preamble) { ssize_t ret; int fsf; int i; - d->buf.osize = 0; - PUTS(&d->buf, MAC_LTE_START_STRING); PUTC(&d->buf, FDD_RADIO); PUTC(&d->buf, direction); @@ -92,16 +89,17 @@ void trace(ev_data *d, int direction, int rnti_type, int rnti, } PUTC(&d->buf, MAC_LTE_PAYLOAD_TAG); + for (i = 0; i < bufsize; i++) - PUTC(&d->buf, ((char*)buf)[i]); + PUTC(&d->buf, ((char *)buf)[i]); ret = sendto(d->socket, d->buf.obuf, d->buf.osize, 0, - (struct sockaddr *)&d->to, sizeof(struct sockaddr_in)); + (struct sockaddr *)&d->to, sizeof(struct sockaddr_in)); + if (ret != d->buf.osize) abort(); } -void ul(void *_d, event e) -{ +void ul(void *_d, event e) { ev_data *d = _d; trace(d, DIRECTION_UPLINK, C_RNTI, e.e[d->ul_rnti].i, e.e[d->ul_frame].i, e.e[d->ul_subframe].i, @@ -109,13 +107,14 @@ void ul(void *_d, event e) NO_PREAMBLE); } -void dl(void *_d, event e) -{ +void dl(void *_d, event e) { ev_data *d = _d; if (e.e[d->dl_rnti].i == 0xffff) { if (d->no_sib) return; + if (d->max_sib && d->cur_sib == d->max_sib) return; + d->cur_sib++; } @@ -126,22 +125,21 @@ void dl(void *_d, event e) NO_PREAMBLE); } -void mib(void *_d, event e) -{ +void mib(void *_d, event e) { ev_data *d = _d; if (d->no_mib) return; + if (d->max_mib && d->cur_mib == d->max_mib) return; - d->cur_mib++; + d->cur_mib++; trace(d, DIRECTION_DOWNLINK, NO_RNTI, 0, e.e[d->mib_frame].i, e.e[d->mib_subframe].i, e.e[d->mib_data].b, e.e[d->mib_data].bsize, NO_PREAMBLE); } -void preamble(void *_d, event e) -{ +void preamble(void *_d, event e) { ev_data *d = _d; trace(d, DIRECTION_UPLINK, NO_RNTI, 0, e.e[d->preamble_frame].i, e.e[d->preamble_subframe].i, @@ -149,8 +147,7 @@ void preamble(void *_d, event e) e.e[d->preamble_preamble].i); } -void rar(void *_d, event e) -{ +void rar(void *_d, event e) { ev_data *d = _d; trace(d, DIRECTION_DOWNLINK, RA_RNTI, e.e[d->rar_rnti].i, e.e[d->rar_frame].i, e.e[d->rar_subframe].i, @@ -159,114 +156,118 @@ void rar(void *_d, event e) } void setup_data(ev_data *d, void *database, int ul_id, int dl_id, int mib_id, - int preamble_id, int rar_id) -{ + int preamble_id, int rar_id) { database_event_format f; int i; - d->ul_rnti = -1; d->ul_frame = -1; d->ul_subframe = -1; d->ul_data = -1; - d->dl_rnti = -1; d->dl_frame = -1; d->dl_subframe = -1; d->dl_data = -1; - d->mib_frame = -1; d->mib_subframe = -1; d->mib_data = -1; - d->preamble_frame = -1; d->preamble_subframe = -1; d->preamble_preamble = -1; - d->rar_rnti = -1; d->rar_frame = -1; d->rar_subframe = -1; d->rar_data = -1; - #define G(var_name, var_type, var) \ if (!strcmp(f.name[i], var_name)) { \ if (strcmp(f.type[i], var_type)) goto error; \ var = i; \ continue; \ } - /* ul: rnti, frame, subframe, data */ f = get_format(database, ul_id); + for (i = 0; i < f.count; i++) { G("rnti", "int", d->ul_rnti); G("frame", "int", d->ul_frame); G("subframe", "int", d->ul_subframe); G("data", "buffer", d->ul_data); } + if (d->ul_rnti == -1 || d->ul_frame == -1 || d->ul_subframe == -1 || d->ul_data == -1) goto error; /* dl: rnti, frame, subframe, data */ f = get_format(database, dl_id); + for (i = 0; i < f.count; i++) { G("rnti", "int", d->dl_rnti); G("frame", "int", d->dl_frame); G("subframe", "int", d->dl_subframe); G("data", "buffer", d->dl_data); } + if (d->dl_rnti == -1 || d->dl_frame == -1 || d->dl_subframe == -1 || d->dl_data == -1) goto error; /* MIB: frame, subframe, data */ f = get_format(database, mib_id); + for (i = 0; i < f.count; i++) { G("frame", "int", d->mib_frame); G("subframe", "int", d->mib_subframe); G("data", "buffer", d->mib_data); } + if (d->mib_frame == -1 || d->mib_subframe == -1 || d->mib_data == -1) goto error; /* preamble: frame, subframe, preamble */ f = get_format(database, preamble_id); + for (i = 0; i < f.count; i++) { G("frame", "int", d->preamble_frame); G("subframe", "int", d->preamble_subframe); G("preamble", "int", d->preamble_preamble); } + if (d->preamble_frame == -1 || d->preamble_subframe == -1 || d->preamble_preamble == -1) goto error; /* rar: rnti, frame, subframe, data */ f = get_format(database, rar_id); + for (i = 0; i < f.count; i++) { G("rnti", "int", d->rar_rnti); G("frame", "int", d->rar_frame); G("subframe", "int", d->rar_subframe); G("data", "buffer", d->rar_data); } + if (d->rar_rnti == -1 || d->rar_frame == -1 || d->rar_subframe == -1 || d->rar_data == -1) goto error; #undef G - return; - error: printf("bad T_messages.txt\n"); abort(); } -void *receiver(void *_d) -{ +void *receiver(void *_d) { ev_data *d = _d; int s; char buf[100000]; - s = socket(AF_INET, SOCK_DGRAM, 0); - if (s == -1) { perror("socket"); abort(); } - if (bind(s, (struct sockaddr *)&d->to, sizeof(struct sockaddr_in)) == -1) - { perror("bind"); abort(); } + if (s == -1) { + perror("socket"); + abort(); + } + + if (bind(s, (struct sockaddr *)&d->to, sizeof(struct sockaddr_in)) == -1) { + perror("bind"); + abort(); + } while (1) { if (recv(s, buf, 100000, 0) <= 0) abort(); @@ -275,33 +276,31 @@ void *receiver(void *_d) return 0; } -void usage(void) -{ +void usage(void) { printf( -"options:\n" -" -d <database file> this option is mandatory\n" -" -i <dump file> read events from this dump file\n" -" -ip <IP address> send packets to this IP address (default %s)\n" -" -p <port> send packets to this port (default %d)\n" -" -no-mib do not report MIB\n" -" -no-sib do not report SIBs\n" -" -max-mib <n> report at maximum n MIB\n" -" -max-sib <n> report at maximum n SIBs\n" -" -live run live\n" -" -live-ip <IP address> tracee's IP address (default %p)\n" -" -live-port <por> tracee's port (default %d)\n" -"-i and -live are mutually exclusive options. One of them must be provided\n" -"but not both.\n", - DEFAULT_IP, - DEFAULT_PORT, - DEFAULT_LIVE_IP, - DEFAULT_LIVE_PORT + "options:\n" + " -d <database file> this option is mandatory\n" + " -i <dump file> read events from this dump file\n" + " -ip <IP address> send packets to this IP address (default %s)\n" + " -p <port> send packets to this port (default %d)\n" + " -no-mib do not report MIB\n" + " -no-sib do not report SIBs\n" + " -max-mib <n> report at maximum n MIB\n" + " -max-sib <n> report at maximum n SIBs\n" + " -live run live\n" + " -live-ip <IP address> tracee's IP address (default %s)\n" + " -live-port <por> tracee's port (default %d)\n" + "-i and -live are mutually exclusive options. One of them must be provided\n" + "but not both.\n", + DEFAULT_IP, + DEFAULT_PORT, + DEFAULT_LIVE_IP, + DEFAULT_LIVE_PORT ); exit(1); } -int main(int n, char **v) -{ +int main(int n, char **v) { char *database_filename = NULL; char *input_filename = NULL; void *database; @@ -315,28 +314,82 @@ int main(int n, char **v) char *live_ip = DEFAULT_LIVE_IP; int live_port = DEFAULT_LIVE_PORT; int live = 0; - memset(&d, 0, sizeof(ev_data)); for (i = 1; i < n; i++) { if (!strcmp(v[i], "-h") || !strcmp(v[i], "--help")) usage(); - if (!strcmp(v[i], "-d")) - { if (i > n-2) usage(); database_filename = v[++i]; continue; } - if (!strcmp(v[i], "-i")) - { if (i > n-2) usage(); input_filename = v[++i]; continue; } - if (!strcmp(v[i], "-ip")) { if (i > n-2) usage(); ip = v[++i]; continue; } - if (!strcmp(v[i], "-p")) {if(i>n-2)usage(); port=atoi(v[++i]); continue; } - if (!strcmp(v[i], "-no-mib")) { d.no_mib = 1; continue; } - if (!strcmp(v[i], "-no-sib")) { d.no_sib = 1; continue; } - if (!strcmp(v[i], "-max-mib")) - { if (i > n-2) usage(); d.max_mib = atoi(v[++i]); continue; } - if (!strcmp(v[i], "-max-sib")) - { if (i > n-2) usage(); d.max_sib = atoi(v[++i]); continue; } - if (!strcmp(v[i], "-live")) { live = 1; continue; } - if (!strcmp(v[i], "-live-ip")) - { if (i > n-2) usage(); live_ip = v[++i]; continue; } - if (!strcmp(v[i], "-live-port")) - { if (i > n-2) usage(); live_port = atoi(v[++i]); continue; } + + if (!strcmp(v[i], "-d")) { + if (i > n-2) usage(); + + database_filename = v[++i]; + continue; + } + + if (!strcmp(v[i], "-i")) { + if (i > n-2) usage(); + + input_filename = v[++i]; + continue; + } + + if (!strcmp(v[i], "-ip")) { + if (i > n-2) usage(); + + ip = v[++i]; + continue; + } + + if (!strcmp(v[i], "-p")) { + if(i>n-2)usage(); + + port=atoi(v[++i]); + continue; + } + + if (!strcmp(v[i], "-no-mib")) { + d.no_mib = 1; + continue; + } + + if (!strcmp(v[i], "-no-sib")) { + d.no_sib = 1; + continue; + } + + if (!strcmp(v[i], "-max-mib")) { + if (i > n-2) usage(); + + d.max_mib = atoi(v[++i]); + continue; + } + + if (!strcmp(v[i], "-max-sib")) { + if (i > n-2) usage(); + + d.max_sib = atoi(v[++i]); + continue; + } + + if (!strcmp(v[i], "-live")) { + live = 1; + continue; + } + + if (!strcmp(v[i], "-live-ip")) { + if (i > n-2) usage(); + + live_ip = v[++i]; + continue; + } + + if (!strcmp(v[i], "-live-port")) { + if (i > n-2) usage(); + + live_port = atoi(v[++i]); + continue; + } + usage(); } @@ -357,25 +410,34 @@ int main(int n, char **v) if (live == 0) { in = open(input_filename, O_RDONLY); - if (in == -1) { perror(input_filename); return 1; } + + if (in == -1) { + perror(input_filename); + return 1; + } } else in = connect_to(live_ip, live_port); database = parse_database(database_filename); load_config_file(database_filename); - h = new_handler(database); if (live) { char mt = 1; int number_of_events = number_of_ids(database); int *is_on = calloc(number_of_events, sizeof(int)); - if (is_on == NULL) { printf("ERROR: out of memory\n"); exit(1); } + + if (is_on == NULL) { + printf("ERROR: out of memory\n"); + exit(1); + } + on_off(database, "ENB_MAC_UE_UL_PDU_WITH_DATA", is_on, 1); on_off(database, "ENB_MAC_UE_DL_PDU_WITH_DATA", is_on, 1); on_off(database, "ENB_PHY_MIB", is_on, 1); on_off(database, "ENB_PHY_INITIATE_RA_PROCEDURE", is_on, 1); on_off(database, "ENB_MAC_UE_DL_RAR_PDU_WITH_DATA", is_on, 1); + /* activate selected traces */ if (socket_send(in, &mt, 1) == -1 || socket_send(in, &number_of_events, sizeof(int)) == -1 || @@ -383,6 +445,7 @@ int main(int n, char **v) printf("ERROR: socket_send failed\n"); exit(1); } + free(is_on); } @@ -392,31 +455,34 @@ int main(int n, char **v) preamble_id = event_id_from_name(database, "ENB_PHY_INITIATE_RA_PROCEDURE"); rar_id = event_id_from_name(database, "ENB_MAC_UE_DL_RAR_PDU_WITH_DATA"); setup_data(&d, database, ul_id, dl_id, mib_id, preamble_id, rar_id); - register_handler_function(h, ul_id, ul, &d); register_handler_function(h, dl_id, dl, &d); register_handler_function(h, mib_id, mib, &d); register_handler_function(h, preamble_id, preamble, &d); register_handler_function(h, rar_id, rar, &d); - d.socket = socket(AF_INET, SOCK_DGRAM, 0); - if (d.socket == -1) { perror("socket"); exit(1); } + + if (d.socket == -1) { + perror("socket"); + exit(1); + } d.to.sin_family = AF_INET; d.to.sin_port = htons(port); d.to.sin_addr.s_addr = inet_addr(ip); - new_thread(receiver, &d); - OBUF ebuf = { osize: 0, omaxsize: 0, obuf: NULL }; /* read messages */ while (1) { event e; e = get_event(in, &ebuf, database); + if (e.type == -1) break; + if (!(e.type == ul_id || e.type == dl_id || e.type == mib_id || e.type == preamble_id || e.type == rar_id)) continue; + handle_event(h, e); } diff --git a/common/utils/T/tracer/utils.c b/common/utils/T/tracer/utils.c index 7f58b6f5aa0061189d01a5107d8e6dcea035138a..2452254cf9167a4fbf6a4586e4370b58cdc5cae9 100644 --- a/common/utils/T/tracer/utils.c +++ b/common/utils/T/tracer/utils.c @@ -9,27 +9,38 @@ #include <arpa/inet.h> #include <math.h> -void new_thread(void *(*f)(void *), void *data) -{ +void new_thread(void *(*f)(void *), void *data) { pthread_t t; pthread_attr_t att; - if (pthread_attr_init(&att)) - { fprintf(stderr, "pthread_attr_init err\n"); exit(1); } - if (pthread_attr_setdetachstate(&att, PTHREAD_CREATE_DETACHED)) - { fprintf(stderr, "pthread_attr_setdetachstate err\n"); exit(1); } - if (pthread_attr_setstacksize(&att, 10000000)) - { fprintf(stderr, "pthread_attr_setstacksize err\n"); exit(1); } - if (pthread_create(&t, &att, f, data)) - { fprintf(stderr, "pthread_create err\n"); exit(1); } - if (pthread_attr_destroy(&att)) - { fprintf(stderr, "pthread_attr_destroy err\n"); exit(1); } + if (pthread_attr_init(&att)) { + fprintf(stderr, "pthread_attr_init err\n"); + exit(1); + } + + if (pthread_attr_setdetachstate(&att, PTHREAD_CREATE_DETACHED)) { + fprintf(stderr, "pthread_attr_setdetachstate err\n"); + exit(1); + } + + if (pthread_attr_setstacksize(&att, 10000000)) { + fprintf(stderr, "pthread_attr_setstacksize err\n"); + exit(1); + } + + if (pthread_create(&t, &att, f, data)) { + fprintf(stderr, "pthread_create err\n"); + exit(1); + } + + if (pthread_attr_destroy(&att)) { + fprintf(stderr, "pthread_attr_destroy err\n"); + exit(1); + } } -void sleepms(int ms) -{ +void sleepms(int ms) { struct timespec t; - t.tv_sec = ms / 1000; t.tv_nsec = (ms % 1000) * 1000000L; @@ -37,12 +48,15 @@ void sleepms(int ms) if (nanosleep(&t, NULL)) abort(); } -void bps(char *out, float v, char *suffix) -{ +void bps(char *out, float v, char *suffix) { static char *bps_unit[4] = { "", "k", "M", "G" }; int flog; - if (v < 1000) flog = 0; else flog = floor(floor(log10(v)) / 3); + + if (v < 1000) flog = 0; + else flog = floor(floor(log10(v)) / 3); + if (flog > 3) flog = 3; + v /= pow(10, flog*3); sprintf(out, "%g%s%s", round(v*100)/100, bps_unit[flog], suffix); } @@ -51,25 +65,31 @@ void bps(char *out, float v, char *suffix) /* list */ /****************************************************************************/ -list *list_remove_head(list *l) -{ +list *list_remove_head(list *l) { list *ret; + if (l == NULL) return NULL; + ret = l->next; + if (ret != NULL) ret->last = l->last; + free(l); return ret; } -list *list_append(list *l, void *data) -{ +list *list_append(list *l, void *data) { list *new = calloc(1, sizeof(list)); + if (new == NULL) abort(); + new->data = data; + if (l == NULL) { new->last = new; return new; } + l->last->next = new; l->last = new; return l; @@ -79,88 +99,107 @@ list *list_append(list *l, void *data) /* socket */ /****************************************************************************/ -int create_listen_socket(char *addr, int port) -{ +int create_listen_socket(char *addr, int port) { struct sockaddr_in a; int s; int v; - s = socket(AF_INET, SOCK_STREAM, 0); - if (s == -1) { perror("socket"); exit(1); } + + if (s == -1) { + perror("socket"); + exit(1); + } + v = 1; - if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &v, sizeof(int))) - { perror("setsockopt"); exit(1); } + + if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &v, sizeof(int))) { + perror("setsockopt"); + exit(1); + } a.sin_family = AF_INET; a.sin_port = htons(port); a.sin_addr.s_addr = inet_addr(addr); - if (bind(s, (struct sockaddr *)&a, sizeof(a))) { perror("bind"); exit(1); } - if (listen(s, 5)) { perror("listen"); exit(1); } + if (bind(s, (struct sockaddr *)&a, sizeof(a))) { + perror("bind"); + exit(1); + } + + if (listen(s, 5)) { + perror("listen"); + exit(1); + } return s; } -int socket_accept(int s) -{ +int socket_accept(int s) { struct sockaddr_in a; socklen_t alen; alen = sizeof(a); return accept(s, (struct sockaddr *)&a, &alen); } -int socket_send(int socket, void *buffer, int size) -{ +int socket_send(int socket, void *buffer, int size) { char *x = buffer; int ret; + while (size) { ret = write(socket, x, size); + if (ret <= 0) return -1; + size -= ret; x += ret; } + return 0; } -int get_connection(char *addr, int port) -{ +int get_connection(char *addr, int port) { int s, t; - printf("waiting for connection on %s:%d\n", addr, port); - s = create_listen_socket(addr, port); - t = socket_accept(s); - if (t == -1) { perror("accept"); exit(1); } - close(s); - printf("connected\n"); + if (t == -1) { + perror("accept"); + exit(1); + } + close(s); + printf("connected\n"); return t; } -int fullread(int fd, void *_buf, int count) -{ +int fullread(int fd, void *_buf, int count) { char *buf = _buf; int ret = 0; int l; + while (count) { l = read(fd, buf, count); + if (l <= 0) return -1; + count -= l; buf += l; ret += l; } + return ret; } -int try_connect_to(char *addr, int port) -{ +int try_connect_to(char *addr, int port) { int s; struct sockaddr_in a; - s = socket(AF_INET, SOCK_STREAM, 0); - if (s == -1) { perror("socket"); exit(1); } + + if (s == -1) { + perror("socket"); + exit(1); + } a.sin_family = AF_INET; a.sin_port = htons(port); @@ -175,14 +214,12 @@ int try_connect_to(char *addr, int port) return s; } -int connect_to(char *addr, int port) -{ +int connect_to(char *addr, int port) { int s; - printf("connecting to %s:%d\n", addr, port); - again: s = try_connect_to(addr, port); + if (s == -1) { printf("trying again in 1s\n"); sleep(1); @@ -196,49 +233,45 @@ again: /* buffer */ /****************************************************************************/ -void PUTC(OBUF *o, char c) -{ +void PUTC(OBUF *o, char c) { if (o->osize == o->omaxsize) { o->omaxsize += 512; o->obuf = realloc(o->obuf, o->omaxsize); + if (o->obuf == NULL) abort(); } + o->obuf[o->osize] = c; o->osize++; } -void PUTS(OBUF *o, char *s) -{ +void PUTS(OBUF *o, char *s) { while (*s) PUTC(o, *s++); } -static int clean(char c) -{ +static int clean(char c) { if (!isprint(c)) c = ' '; + return c; } -void PUTS_CLEAN(OBUF *o, char *s) -{ +void PUTS_CLEAN(OBUF *o, char *s) { while (*s) PUTC(o, clean(*s++)); } -void PUTI(OBUF *o, int i) -{ +void PUTI(OBUF *o, int i) { char s[64]; sprintf(s, "%d", i); PUTS(o, s); } -void PUTX2(OBUF *o, int i) -{ +void PUTX2(OBUF *o, int i) { char s[64]; sprintf(s, "%2.2x", i); PUTS(o, s); } -void PUTUL(OBUF *o, unsigned long l) -{ +void PUTUL(OBUF *o, unsigned long l) { char s[128]; sprintf(s, "%ld", l); PUTS(o, s); diff --git a/common/utils/backtrace.c b/common/utils/backtrace.c index 889e0d84d148f3694ce363a2f74ac33065cbeb26..f6de74f156ce1bc04ddb58aeb65c3097c8c1ba47 100644 --- a/common/utils/backtrace.c +++ b/common/utils/backtrace.c @@ -31,18 +31,18 @@ #include "backtrace.h" /* Obtain a backtrace and print it to stdout. */ -void display_backtrace(void) -{ +void display_backtrace(void) { void *array[10]; size_t size; char **strings; size_t i; - char* test=getenv("NO_BACKTRACE"); - if (test!=0) *((int*)0)=0; + char *test=getenv("NO_BACKTRACE"); + + if (test!=0) *((int *)0)=0; + size = backtrace(array, 10); strings = backtrace_symbols(array, size); - - printf("Obtained %zd stack frames.\n", size); + printf("Obtained %u stack frames.\n", (unsigned int)size); for (i = 0; i < size; i++) printf("%s\n", strings[i]); @@ -50,8 +50,7 @@ void display_backtrace(void) free(strings); } -void backtrace_handle_signal(siginfo_t *info) -{ +void backtrace_handle_signal(siginfo_t *info) { display_backtrace(); //exit(EXIT_FAILURE); } diff --git a/common/utils/hashtable/hashtable.c b/common/utils/hashtable/hashtable.c index 2c7b35744ca7cf766044f7efc2341aff5b9a2fb5..7b0fc422139c6bf566ea8c824924b5f40047c4d9 100644 --- a/common/utils/hashtable/hashtable.c +++ b/common/utils/hashtable/hashtable.c @@ -2,9 +2,9 @@ * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. - * The OpenAirInterface Software Alliance licenses this file to You under + * The OpenAirInterface Software Alliance licenses this file to You under * the OAI Public License, Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. + * except in compliance with the License. * You may obtain a copy of the License at * * http://www.openairinterface.org/?page_id=698 @@ -28,17 +28,33 @@ //------------------------------------------------------------------------------------------------------------------------------- -char* hashtable_rc_code2string(hashtable_rc_t rcP) +char *hashtable_rc_code2string(hashtable_rc_t rcP) //------------------------------------------------------------------------------------------------------------------------------- { - switch (rcP) { - case HASH_TABLE_OK: return "HASH_TABLE_OK";break; - case HASH_TABLE_INSERT_OVERWRITTEN_DATA: return "HASH_TABLE_INSERT_OVERWRITTEN_DATA";break; - case HASH_TABLE_KEY_NOT_EXISTS: return "HASH_TABLE_KEY_NOT_EXISTS";break; - case HASH_TABLE_KEY_ALREADY_EXISTS: return "HASH_TABLE_KEY_ALREADY_EXISTS";break; - case HASH_TABLE_BAD_PARAMETER_HASHTABLE: return "HASH_TABLE_BAD_PARAMETER_HASHTABLE";break; - default: return "UNKNOWN hashtable_rc_t"; - } + switch (rcP) { + case HASH_TABLE_OK: + return "HASH_TABLE_OK"; + break; + + case HASH_TABLE_INSERT_OVERWRITTEN_DATA: + return "HASH_TABLE_INSERT_OVERWRITTEN_DATA"; + break; + + case HASH_TABLE_KEY_NOT_EXISTS: + return "HASH_TABLE_KEY_NOT_EXISTS"; + break; + + case HASH_TABLE_KEY_ALREADY_EXISTS: + return "HASH_TABLE_KEY_ALREADY_EXISTS"; + break; + + case HASH_TABLE_BAD_PARAMETER_HASHTABLE: + return "HASH_TABLE_BAD_PARAMETER_HASHTABLE"; + break; + + default: + return "UNKNOWN hashtable_rc_t"; + } } //------------------------------------------------------------------------------------------------------------------------------- /* @@ -46,7 +62,7 @@ char* hashtable_rc_code2string(hashtable_rc_t rcP) * hash_free_int_func() is used when this hashtable is used to store int values as data (pointer = value). */ -void hash_free_int_func(void* memoryP){} +void hash_free_int_func(void *memoryP) {} //------------------------------------------------------------------------------------------------------------------------------- /* @@ -55,9 +71,8 @@ void hash_free_int_func(void* memoryP){} * This is a simple/naive hash function which adds the key's ASCII char values. It will probably generate lots of collisions on large hash tables. */ -static hash_size_t def_hashfunc(const uint64_t keyP) -{ - return (hash_size_t)keyP; +static hash_size_t def_hashfunc(const uint64_t keyP) { + return (hash_size_t)keyP; } //------------------------------------------------------------------------------------------------------------------------------- @@ -67,132 +82,147 @@ static hash_size_t def_hashfunc(const uint64_t keyP) * The user can also specify a hash function. If the hashfunc argument is NULL, a default hash function is used. * If an error occurred, NULL is returned. All other values in the returned hash_table_t pointer should be released with hashtable_destroy(). */ -hash_table_t *hashtable_create(const hash_size_t sizeP, hash_size_t (*hashfuncP)(const hash_key_t ), void (*freefuncP)(void*)) -{ - hash_table_t *hashtbl = NULL; +hash_table_t *hashtable_create(const hash_size_t sizeP, hash_size_t (*hashfuncP)(const hash_key_t ), void (*freefuncP)(void *)) { + hash_table_t *hashtbl = NULL; - if(!(hashtbl=malloc(sizeof(hash_table_t)))) { - return NULL; - } + if(!(hashtbl=malloc(sizeof(hash_table_t)))) { + return NULL; + } - if(!(hashtbl->nodes=calloc(sizeP, sizeof(hash_node_t*)))) { - free(hashtbl); - return NULL; - } + if(!(hashtbl->nodes=calloc(sizeP, sizeof(hash_node_t *)))) { + free(hashtbl); + return NULL; + } - hashtbl->size=sizeP; + hashtbl->size=sizeP; - if(hashfuncP) hashtbl->hashfunc=hashfuncP; - else hashtbl->hashfunc=def_hashfunc; + if(hashfuncP) hashtbl->hashfunc=hashfuncP; + else hashtbl->hashfunc=def_hashfunc; - if(freefuncP) hashtbl->freefunc=freefuncP; - else hashtbl->freefunc=free; + if(freefuncP) hashtbl->freefunc=freefuncP; + else hashtbl->freefunc=free; - return hashtbl; + return hashtbl; } //------------------------------------------------------------------------------------------------------------------------------- /* * Cleanup * The hashtable_destroy() walks through the linked lists for each possible hash value, and releases the elements. It also releases the nodes array and the hash_table_t. */ -hashtable_rc_t hashtable_destroy(hash_table_t * hashtblP) -{ - hash_size_t n; - hash_node_t *node, *oldnode; +hashtable_rc_t hashtable_destroy(hash_table_t **hashtblP) { + hash_size_t n; + hash_node_t *node, *oldnode; - if (hashtblP == NULL) { - return HASH_TABLE_BAD_PARAMETER_HASHTABLE; - } + if (*hashtblP == NULL) { + return HASH_TABLE_BAD_PARAMETER_HASHTABLE; + } + + for(n=0; n<(*hashtblP)->size; ++n) { + node=(*hashtblP)->nodes[n]; - for(n=0; n<hashtblP->size; ++n) { - node=hashtblP->nodes[n]; - while(node) { - oldnode=node; - node=node->next; - if (oldnode->data) { - hashtblP->freefunc(oldnode->data); - } - free(oldnode); - } + while(node) { + oldnode=node; + node=node->next; + + if (oldnode->data) { + (*hashtblP)->freefunc(oldnode->data); + } + + free(oldnode); } - free(hashtblP->nodes); - free(hashtblP); - hashtblP=NULL; - return HASH_TABLE_OK; + } + + free((*hashtblP)->nodes); + free((*hashtblP)); + *hashtblP=NULL; + return HASH_TABLE_OK; } //------------------------------------------------------------------------------------------------------------------------------- -hashtable_rc_t hashtable_is_key_exists (const hash_table_t * const hashtblP, const hash_key_t keyP) +hashtable_rc_t hashtable_is_key_exists (const hash_table_t *const hashtblP, const hash_key_t keyP) //------------------------------------------------------------------------------------------------------------------------------- { - hash_node_t *node = NULL; - hash_size_t hash = 0; + hash_node_t *node = NULL; + hash_size_t hash = 0; - if (hashtblP == NULL) { - return HASH_TABLE_BAD_PARAMETER_HASHTABLE; - } + if (hashtblP == NULL) { + return HASH_TABLE_BAD_PARAMETER_HASHTABLE; + } - hash=hashtblP->hashfunc(keyP)%hashtblP->size; - node=hashtblP->nodes[hash]; - while(node) { - if(node->key == keyP) { - return HASH_TABLE_OK; - } - node=node->next; + hash=hashtblP->hashfunc(keyP)%hashtblP->size; + node=hashtblP->nodes[hash]; + + while(node) { + if(node->key == keyP) { + return HASH_TABLE_OK; } - return HASH_TABLE_KEY_NOT_EXISTS; + + node=node->next; + } + + return HASH_TABLE_KEY_NOT_EXISTS; } //------------------------------------------------------------------------------------------------------------------------------- -hashtable_rc_t hashtable_apply_funct_on_elements (hash_table_t *const hashtblP, void functP(hash_key_t keyP, void* dataP, void* parameterP), void* parameterP) +hashtable_rc_t hashtable_apply_funct_on_elements (hash_table_t *const hashtblP, void functP(hash_key_t keyP, void *dataP, void *parameterP), void *parameterP) //------------------------------------------------------------------------------------------------------------------------------- { - hash_node_t *node = NULL; - unsigned int i = 0; - unsigned int num_elements = 0; - if (hashtblP == NULL) { - return HASH_TABLE_BAD_PARAMETER_HASHTABLE; - } - while ((num_elements < hashtblP->num_elements) && (i < hashtblP->size)) { - if (hashtblP->nodes[i] != NULL) { - node=hashtblP->nodes[i]; - while(node) { - num_elements += 1; - functP(node->key, node->data, parameterP); - node=node->next; - } - } - i += 1; + hash_node_t *node = NULL; + unsigned int i = 0; + unsigned int num_elements = 0; + + if (hashtblP == NULL) { + return HASH_TABLE_BAD_PARAMETER_HASHTABLE; + } + + while ((num_elements < hashtblP->num_elements) && (i < hashtblP->size)) { + if (hashtblP->nodes[i] != NULL) { + node=hashtblP->nodes[i]; + + while(node) { + num_elements += 1; + functP(node->key, node->data, parameterP); + node=node->next; + } } - return HASH_TABLE_OK; + + i += 1; + } + + return HASH_TABLE_OK; } //------------------------------------------------------------------------------------------------------------------------------- -hashtable_rc_t hashtable_dump_content (const hash_table_t * const hashtblP, char * const buffer_pP, int * const remaining_bytes_in_buffer_pP ) +hashtable_rc_t hashtable_dump_content (const hash_table_t *const hashtblP, char *const buffer_pP, int *const remaining_bytes_in_buffer_pP ) //------------------------------------------------------------------------------------------------------------------------------- { - hash_node_t *node = NULL; - unsigned int i = 0; - if (hashtblP == NULL) { + hash_node_t *node = NULL; + unsigned int i = 0; + + if (hashtblP == NULL) { + *remaining_bytes_in_buffer_pP = snprintf( + buffer_pP, + *remaining_bytes_in_buffer_pP, + "HASH_TABLE_BAD_PARAMETER_HASHTABLE"); + return HASH_TABLE_BAD_PARAMETER_HASHTABLE; + } + + while ((i < hashtblP->size) && (*remaining_bytes_in_buffer_pP > 0)) { + if (hashtblP->nodes[i] != NULL) { + node=hashtblP->nodes[i]; + + while(node) { *remaining_bytes_in_buffer_pP = snprintf( - buffer_pP, - *remaining_bytes_in_buffer_pP, - "HASH_TABLE_BAD_PARAMETER_HASHTABLE"); - return HASH_TABLE_BAD_PARAMETER_HASHTABLE; - } - while ((i < hashtblP->size) && (*remaining_bytes_in_buffer_pP > 0)) { - if (hashtblP->nodes[i] != NULL) { - node=hashtblP->nodes[i]; - while(node) { - *remaining_bytes_in_buffer_pP = snprintf( - buffer_pP, - *remaining_bytes_in_buffer_pP, - "Key 0x%"PRIx64" Element %p\n", - node->key, - node->data); - node=node->next; - } - } - i += 1; + buffer_pP, + *remaining_bytes_in_buffer_pP, + "Key 0x%"PRIx64" Element %p\n", + node->key, + node->data); + node=node->next; + } } - return HASH_TABLE_OK; + + i += 1; + } + + return HASH_TABLE_OK; } //------------------------------------------------------------------------------------------------------------------------------- @@ -200,97 +230,110 @@ hashtable_rc_t hashtable_dump_content (const hash_table_t * const hashtblP, char * Adding a new element * To make sure the hash value is not bigger than size, the result of the user provided hash function is used modulo size. */ -hashtable_rc_t hashtable_insert(hash_table_t * const hashtblP, const hash_key_t keyP, void *dataP) -{ - hash_node_t *node = NULL; - hash_size_t hash = 0; - if (hashtblP == NULL) { - return HASH_TABLE_BAD_PARAMETER_HASHTABLE; - } - hash=hashtblP->hashfunc(keyP)%hashtblP->size; +hashtable_rc_t hashtable_insert(hash_table_t *const hashtblP, const hash_key_t keyP, void *dataP) { + hash_node_t *node = NULL; + hash_size_t hash = 0; - node=hashtblP->nodes[hash]; - while(node) { - if(node->key == keyP) { - if (node->data) { - hashtblP->freefunc(node->data); - } - node->data=dataP; - return HASH_TABLE_INSERT_OVERWRITTEN_DATA; - } - node=node->next; - } - if(!(node=malloc(sizeof(hash_node_t)))) return -1; - node->key=keyP; - node->data=dataP; - if (hashtblP->nodes[hash]) { - node->next=hashtblP->nodes[hash]; - } else { - node->next = NULL; + if (hashtblP == NULL) { + return HASH_TABLE_BAD_PARAMETER_HASHTABLE; + } + + hash=hashtblP->hashfunc(keyP)%hashtblP->size; + node=hashtblP->nodes[hash]; + + while(node) { + if(node->key == keyP) { + if (node->data) { + hashtblP->freefunc(node->data); + } + + node->data=dataP; + return HASH_TABLE_INSERT_OVERWRITTEN_DATA; } - hashtblP->nodes[hash]=node; - hashtblP->num_elements += 1; - return HASH_TABLE_OK; + + node=node->next; + } + + if(!(node=malloc(sizeof(hash_node_t)))) return -1; + + node->key=keyP; + node->data=dataP; + + if (hashtblP->nodes[hash]) { + node->next=hashtblP->nodes[hash]; + } else { + node->next = NULL; + } + + hashtblP->nodes[hash]=node; + hashtblP->num_elements += 1; + return HASH_TABLE_OK; } //------------------------------------------------------------------------------------------------------------------------------- /* * To remove an element from the hash table, we just search for it in the linked list for that hash value, * and remove it if it is found. If it was not found, it is an error and -1 is returned. */ -hashtable_rc_t hashtable_remove(hash_table_t * const hashtblP, const hash_key_t keyP) -{ - hash_node_t *node, *prevnode=NULL; - hash_size_t hash = 0; +hashtable_rc_t hashtable_remove(hash_table_t *const hashtblP, const hash_key_t keyP) { + hash_node_t *node, *prevnode=NULL; + hash_size_t hash = 0; - if (hashtblP == NULL) { - return HASH_TABLE_BAD_PARAMETER_HASHTABLE; - } - hash=hashtblP->hashfunc(keyP)%hashtblP->size; - node=hashtblP->nodes[hash]; - while(node) { - if(node->key == keyP) { - if(prevnode) prevnode->next=node->next; - else hashtblP->nodes[hash]=node->next; - if (node->data) { - hashtblP->freefunc(node->data); - } - free(node); - hashtblP->num_elements -= 1; - return HASH_TABLE_OK; - } - prevnode=node; - node=node->next; + if (hashtblP == NULL) { + return HASH_TABLE_BAD_PARAMETER_HASHTABLE; + } + + hash=hashtblP->hashfunc(keyP)%hashtblP->size; + node=hashtblP->nodes[hash]; + + while(node) { + if(node->key == keyP) { + if(prevnode) prevnode->next=node->next; + else hashtblP->nodes[hash]=node->next; + + if (node->data) { + hashtblP->freefunc(node->data); + } + + free(node); + hashtblP->num_elements -= 1; + return HASH_TABLE_OK; } - return HASH_TABLE_KEY_NOT_EXISTS; + + prevnode=node; + node=node->next; + } + + return HASH_TABLE_KEY_NOT_EXISTS; } //------------------------------------------------------------------------------------------------------------------------------- /* * Searching for an element is easy. We just search through the linked list for the corresponding hash value. * NULL is returned if we didn't find it. */ -hashtable_rc_t hashtable_get(const hash_table_t * const hashtblP, const hash_key_t keyP, void** dataP) -{ - hash_node_t *node = NULL; - hash_size_t hash = 0; +hashtable_rc_t hashtable_get(const hash_table_t *const hashtblP, const hash_key_t keyP, void **dataP) { + hash_node_t *node = NULL; + hash_size_t hash = 0; - if (hashtblP == NULL) { - *dataP = NULL; - return HASH_TABLE_BAD_PARAMETER_HASHTABLE; - } - hash=hashtblP->hashfunc(keyP)%hashtblP->size; -/* fprintf(stderr, "hashtable_get() key=%s, hash=%d\n", key, hash);*/ + if (hashtblP == NULL) { + *dataP = NULL; + return HASH_TABLE_BAD_PARAMETER_HASHTABLE; + } - node=hashtblP->nodes[hash]; + hash=hashtblP->hashfunc(keyP)%hashtblP->size; + /* fprintf(stderr, "hashtable_get() key=%s, hash=%d\n", key, hash);*/ + node=hashtblP->nodes[hash]; - while(node) { - if(node->key == keyP) { - *dataP = node->data; - return HASH_TABLE_OK; - } - node=node->next; + while(node) { + if(node->key == keyP) { + *dataP = node->data; + return HASH_TABLE_OK; } - *dataP = NULL; - return HASH_TABLE_KEY_NOT_EXISTS; + + node=node->next; + } + + *dataP = NULL; + return HASH_TABLE_KEY_NOT_EXISTS; } //------------------------------------------------------------------------------------------------------------------------------- /* @@ -304,36 +347,33 @@ hashtable_rc_t hashtable_get(const hash_table_t * const hashtblP, const hash_key * After that, we can just free the old table and copy the elements from newtbl to hashtbl. */ -hashtable_rc_t hashtable_resize(hash_table_t * const hashtblP, const hash_size_t sizeP) -{ - hash_table_t newtbl; - hash_size_t n; - hash_node_t *node,*next; - - if (hashtblP == NULL) { - return HASH_TABLE_BAD_PARAMETER_HASHTABLE; - } +hashtable_rc_t hashtable_resize(hash_table_t *const hashtblP, const hash_size_t sizeP) { + hash_table_t newtbl; + hash_size_t n; + hash_node_t *node,*next; - newtbl.size = sizeP; - newtbl.hashfunc = hashtblP->hashfunc; + if (hashtblP == NULL) { + return HASH_TABLE_BAD_PARAMETER_HASHTABLE; + } - if(!(newtbl.nodes=calloc(sizeP, sizeof(hash_node_t*)))) return -1; + newtbl.size = sizeP; + newtbl.hashfunc = hashtblP->hashfunc; - for(n=0; n<hashtblP->size; ++n) { - for(node=hashtblP->nodes[n]; node; node=next) { - next = node->next; - hashtable_insert(&newtbl, node->key, node->data); - // Lionel GAUTHIER: BAD CODE TO BE REWRITTEN - hashtable_remove(hashtblP, node->key); + if(!(newtbl.nodes=calloc(sizeP, sizeof(hash_node_t *)))) return -1; - } + for(n=0; n<hashtblP->size; ++n) { + for(node=hashtblP->nodes[n]; node; node=next) { + next = node->next; + hashtable_insert(&newtbl, node->key, node->data); + // Lionel GAUTHIER: BAD CODE TO BE REWRITTEN + hashtable_remove(hashtblP, node->key); } + } - free(hashtblP->nodes); - hashtblP->size=newtbl.size; - hashtblP->nodes=newtbl.nodes; - - return HASH_TABLE_OK; + free(hashtblP->nodes); + hashtblP->size=newtbl.size; + hashtblP->nodes=newtbl.nodes; + return HASH_TABLE_OK; } diff --git a/common/utils/hashtable/hashtable.h b/common/utils/hashtable/hashtable.h index 62002fb60f89c738d8d2a941d9cd31fac9e268f5..3f770684fae9996f8973b4268f106a6526dafd0b 100644 --- a/common/utils/hashtable/hashtable.h +++ b/common/utils/hashtable/hashtable.h @@ -2,9 +2,9 @@ * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. - * The OpenAirInterface Software Alliance licenses this file to You under + * The OpenAirInterface Software Alliance licenses this file to You under * the OAI Public License, Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. + * except in compliance with the License. * You may obtain a copy of the License at * * http://www.openairinterface.org/?page_id=698 @@ -31,41 +31,41 @@ typedef uint64_t hash_key_t; #define HASHTABLE_NOT_A_KEY_VALUE ((uint64_t)-1) typedef enum hashtable_return_code_e { - HASH_TABLE_OK = 0, - HASH_TABLE_INSERT_OVERWRITTEN_DATA = 1, - HASH_TABLE_KEY_NOT_EXISTS = 2, - HASH_TABLE_KEY_ALREADY_EXISTS = 3, - HASH_TABLE_BAD_PARAMETER_HASHTABLE = 4, - HASH_TABLE_SYSTEM_ERROR = 5, - HASH_TABLE_CODE_MAX + HASH_TABLE_OK = 0, + HASH_TABLE_INSERT_OVERWRITTEN_DATA = 1, + HASH_TABLE_KEY_NOT_EXISTS = 2, + HASH_TABLE_KEY_ALREADY_EXISTS = 3, + HASH_TABLE_BAD_PARAMETER_HASHTABLE = 4, + HASH_TABLE_SYSTEM_ERROR = 5, + HASH_TABLE_CODE_MAX } hashtable_rc_t; typedef struct hash_node_s { - hash_key_t key; - void *data; - struct hash_node_s *next; + hash_key_t key; + void *data; + struct hash_node_s *next; } hash_node_t; typedef struct hash_table_s { - hash_size_t size; - hash_size_t num_elements; - struct hash_node_s **nodes; - hash_size_t (*hashfunc)(const hash_key_t); - void (*freefunc)(void*); + hash_size_t size; + hash_size_t num_elements; + struct hash_node_s **nodes; + hash_size_t (*hashfunc)(const hash_key_t); + void (*freefunc)(void *); } hash_table_t; -char* hashtable_rc_code2string(hashtable_rc_t rcP); -void hash_free_int_func(void* memoryP); -hash_table_t *hashtable_create (const hash_size_t size, hash_size_t (*hashfunc)(const hash_key_t ), void (*freefunc)(void*)); -hashtable_rc_t hashtable_destroy(hash_table_t * const hashtbl); -hashtable_rc_t hashtable_is_key_exists (const hash_table_t * const hashtbl, const uint64_t key); -hashtable_rc_t hashtable_apply_funct_on_elements (hash_table_t * const hashtblP, void funct(hash_key_t keyP, void* dataP, void* parameterP), void* parameterP); -hashtable_rc_t hashtable_dump_content (const hash_table_t * const hashtblP, char * const buffer_pP, int * const remaining_bytes_in_buffer_pP ); -hashtable_rc_t hashtable_insert (hash_table_t * const hashtbl, const hash_key_t key, void *data); -hashtable_rc_t hashtable_remove (hash_table_t * const hashtbl, const hash_key_t key); -hashtable_rc_t hashtable_get (const hash_table_t * const hashtbl, const hash_key_t key, void **dataP); -hashtable_rc_t hashtable_resize (hash_table_t * const hashtbl, const hash_size_t size); +char *hashtable_rc_code2string(hashtable_rc_t rcP); +void hash_free_int_func(void *memoryP); +hash_table_t *hashtable_create (const hash_size_t size, hash_size_t (*hashfunc)(const hash_key_t ), void (*freefunc)(void *)); +hashtable_rc_t hashtable_destroy(hash_table_t **hashtbl); +hashtable_rc_t hashtable_is_key_exists (const hash_table_t *const hashtbl, const uint64_t key); +hashtable_rc_t hashtable_apply_funct_on_elements (hash_table_t *const hashtblP, void funct(hash_key_t keyP, void *dataP, void *parameterP), void *parameterP); +hashtable_rc_t hashtable_dump_content (const hash_table_t *const hashtblP, char *const buffer_pP, int *const remaining_bytes_in_buffer_pP ); +hashtable_rc_t hashtable_insert (hash_table_t *const hashtbl, const hash_key_t key, void *data); +hashtable_rc_t hashtable_remove (hash_table_t *const hashtbl, const hash_key_t key); +hashtable_rc_t hashtable_get (const hash_table_t *const hashtbl, const hash_key_t key, void **dataP); +hashtable_rc_t hashtable_resize (hash_table_t *const hashtbl, const hash_size_t size); diff --git a/common/utils/hashtable/obj_hashtable.c b/common/utils/hashtable/obj_hashtable.c index 7fb68d16817993c86e75f211e2b0b2c257039e19..643dcce552ad72381f62b38f954e4d217e0ecb5a 100644 --- a/common/utils/hashtable/obj_hashtable.c +++ b/common/utils/hashtable/obj_hashtable.c @@ -2,9 +2,9 @@ * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. - * The OpenAirInterface Software Alliance licenses this file to You under + * The OpenAirInterface Software Alliance licenses this file to You under * the OAI Public License, Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. + * except in compliance with the License. * You may obtain a copy of the License at * * http://www.openairinterface.org/?page_id=698 @@ -30,13 +30,12 @@ * This is a simple/naive hash function which adds the key's ASCII char values. It will probably generate lots of collisions on large hash tables. */ -static hash_size_t def_hashfunc(const void *keyP, int key_sizeP) -{ - hash_size_t hash=0; +static hash_size_t def_hashfunc(const void *keyP, int key_sizeP) { + hash_size_t hash=0; - while(key_sizeP) hash^=((unsigned char*)keyP)[key_sizeP --]; + while(key_sizeP) hash^=((unsigned char *)keyP)[key_sizeP --]; - return hash; + return hash; } //------------------------------------------------------------------------------------------------------------------------------- @@ -46,201 +45,221 @@ static hash_size_t def_hashfunc(const void *keyP, int key_sizeP) * The user can also specify a hash function. If the hashfunc argument is NULL, a default hash function is used. * If an error occurred, NULL is returned. All other values in the returned obj_hash_table_t pointer should be released with hashtable_destroy(). */ -obj_hash_table_t *obj_hashtable_create(hash_size_t sizeP, hash_size_t (*hashfuncP)(const void*, int ), void (*freekeyfuncP)(void*), void (*freedatafuncP)(void*)) -{ - obj_hash_table_t *hashtbl; +obj_hash_table_t *obj_hashtable_create(hash_size_t sizeP, hash_size_t (*hashfuncP)(const void *, int ), void (*freekeyfuncP)(void *), void (*freedatafuncP)(void *)) { + obj_hash_table_t *hashtbl; - if(!(hashtbl=malloc(sizeof(obj_hash_table_t)))) return NULL; + if(!(hashtbl=malloc(sizeof(obj_hash_table_t)))) return NULL; - if(!(hashtbl->nodes=calloc(sizeP, sizeof(obj_hash_node_t*)))) { - free(hashtbl); - return NULL; - } + if(!(hashtbl->nodes=calloc(sizeP, sizeof(obj_hash_node_t *)))) { + free(hashtbl); + return NULL; + } - hashtbl->size=sizeP; + hashtbl->size=sizeP; - if(hashfuncP) hashtbl->hashfunc=hashfuncP; - else hashtbl->hashfunc=def_hashfunc; + if(hashfuncP) hashtbl->hashfunc=hashfuncP; + else hashtbl->hashfunc=def_hashfunc; - if(freekeyfuncP) hashtbl->freekeyfunc=freekeyfuncP; - else hashtbl->freekeyfunc=free; + if(freekeyfuncP) hashtbl->freekeyfunc=freekeyfuncP; + else hashtbl->freekeyfunc=free; - if(freedatafuncP) hashtbl->freedatafunc=freedatafuncP; - else hashtbl->freedatafunc=free; + if(freedatafuncP) hashtbl->freedatafunc=freedatafuncP; + else hashtbl->freedatafunc=free; - return hashtbl; + return hashtbl; } //------------------------------------------------------------------------------------------------------------------------------- /* * Cleanup * The hashtable_destroy() walks through the linked lists for each possible hash value, and releases the elements. It also releases the nodes array and the obj_hash_table_t. */ -hashtable_rc_t obj_hashtable_destroy(obj_hash_table_t *hashtblP) -{ - hash_size_t n; - obj_hash_node_t *node, *oldnode; +hashtable_rc_t obj_hashtable_destroy(obj_hash_table_t *hashtblP) { + hash_size_t n; + obj_hash_node_t *node, *oldnode; - for(n=0; n<hashtblP->size; ++n) { - node=hashtblP->nodes[n]; - while(node) { - oldnode=node; - node=node->next; - hashtblP->freekeyfunc(oldnode->key); - hashtblP->freedatafunc(oldnode->data); - free(oldnode); - } + for(n=0; n<hashtblP->size; ++n) { + node=hashtblP->nodes[n]; + + while(node) { + oldnode=node; + node=node->next; + hashtblP->freekeyfunc(oldnode->key); + hashtblP->freedatafunc(oldnode->data); + free(oldnode); } - free(hashtblP->nodes); - free(hashtblP); - return HASH_TABLE_OK; + } + + free(hashtblP->nodes); + free(hashtblP); + return HASH_TABLE_OK; } //------------------------------------------------------------------------------------------------------------------------------- -hashtable_rc_t obj_hashtable_is_key_exists (obj_hash_table_t *hashtblP, void* keyP, int key_sizeP) +hashtable_rc_t obj_hashtable_is_key_exists (obj_hash_table_t *hashtblP, void *keyP, int key_sizeP) //------------------------------------------------------------------------------------------------------------------------------- { - obj_hash_node_t *node; - hash_size_t hash; + obj_hash_node_t *node; + hash_size_t hash; - if (hashtblP == NULL) { - return HASH_TABLE_BAD_PARAMETER_HASHTABLE; - } - hash=hashtblP->hashfunc(keyP, key_sizeP)%hashtblP->size; - node=hashtblP->nodes[hash]; - while(node) { - if(node->key == keyP) { - return HASH_TABLE_OK; - } else if (node->key_size == key_sizeP) { - if (memcmp(node->key, keyP, key_sizeP) == 0) { - return HASH_TABLE_OK; - } - } - node=node->next; + if (hashtblP == NULL) { + return HASH_TABLE_BAD_PARAMETER_HASHTABLE; + } + + hash=hashtblP->hashfunc(keyP, key_sizeP)%hashtblP->size; + node=hashtblP->nodes[hash]; + + while(node) { + if(node->key == keyP) { + return HASH_TABLE_OK; + } else if (node->key_size == key_sizeP) { + if (memcmp(node->key, keyP, key_sizeP) == 0) { + return HASH_TABLE_OK; + } } - return HASH_TABLE_KEY_NOT_EXISTS; + + node=node->next; + } + + return HASH_TABLE_KEY_NOT_EXISTS; } //------------------------------------------------------------------------------------------------------------------------------- /* * Adding a new element * To make sure the hash value is not bigger than size, the result of the user provided hash function is used modulo size. */ -hashtable_rc_t obj_hashtable_insert(obj_hash_table_t *hashtblP, void* keyP, int key_sizeP, void *dataP) -{ - obj_hash_node_t *node; - hash_size_t hash; +hashtable_rc_t obj_hashtable_insert(obj_hash_table_t *hashtblP, void *keyP, int key_sizeP, void *dataP) { + obj_hash_node_t *node; + hash_size_t hash; - if (hashtblP == NULL) { - return HASH_TABLE_BAD_PARAMETER_HASHTABLE; - } - hash=hashtblP->hashfunc(keyP, key_sizeP)%hashtblP->size; - node=hashtblP->nodes[hash]; - while(node) { - if(node->key == keyP) { - if (node->data) { - hashtblP->freedatafunc(node->data); - } - node->data=dataP; - // waste of memory here (keyP is lost) we should free it now - return HASH_TABLE_INSERT_OVERWRITTEN_DATA; - } - node=node->next; - } - if(!(node=malloc(sizeof(obj_hash_node_t)))) return -1; - node->key=keyP; - node->data=dataP; - if (hashtblP->nodes[hash]) { - node->next=hashtblP->nodes[hash]; - } else { - node->next = NULL; + if (hashtblP == NULL) { + return HASH_TABLE_BAD_PARAMETER_HASHTABLE; + } + + hash=hashtblP->hashfunc(keyP, key_sizeP)%hashtblP->size; + node=hashtblP->nodes[hash]; + + while(node) { + if(node->key == keyP) { + if (node->data) { + hashtblP->freedatafunc(node->data); + } + + node->data=dataP; + // waste of memory here (keyP is lost) we should free it now + return HASH_TABLE_INSERT_OVERWRITTEN_DATA; } - hashtblP->nodes[hash]=node; - return HASH_TABLE_OK; + + node=node->next; + } + + if(!(node=malloc(sizeof(obj_hash_node_t)))) return -1; + + node->key=keyP; + node->data=dataP; + + if (hashtblP->nodes[hash]) { + node->next=hashtblP->nodes[hash]; + } else { + node->next = NULL; + } + + hashtblP->nodes[hash]=node; + return HASH_TABLE_OK; } //------------------------------------------------------------------------------------------------------------------------------- /* * To remove an element from the hash table, we just search for it in the linked list for that hash value, * and remove it if it is found. If it was not found, it is an error and -1 is returned. */ -hashtable_rc_t obj_hashtable_remove(obj_hash_table_t *hashtblP, const void* keyP, int key_sizeP) -{ - obj_hash_node_t *node, *prevnode=NULL; - hash_size_t hash; +hashtable_rc_t obj_hashtable_remove(obj_hash_table_t *hashtblP, const void *keyP, int key_sizeP) { + obj_hash_node_t *node, *prevnode=NULL; + hash_size_t hash; - if (hashtblP == NULL) { - return HASH_TABLE_BAD_PARAMETER_HASHTABLE; - } + if (hashtblP == NULL) { + return HASH_TABLE_BAD_PARAMETER_HASHTABLE; + } - hash=hashtblP->hashfunc(keyP, key_sizeP)%hashtblP->size; - node=hashtblP->nodes[hash]; - while(node) { - if ((node->key == keyP) || ((node->key_size == key_sizeP) && (memcmp(node->key, keyP, key_sizeP) == 0))){ - if(prevnode) { - prevnode->next=node->next; - } else { - hashtblP->nodes[hash]=node->next; - } - hashtblP->freekeyfunc(node->key); - hashtblP->freedatafunc(node->data); - free(node); - return HASH_TABLE_OK; - } - prevnode=node; - node=node->next; + hash=hashtblP->hashfunc(keyP, key_sizeP)%hashtblP->size; + node=hashtblP->nodes[hash]; + + while(node) { + if ((node->key == keyP) || ((node->key_size == key_sizeP) && (memcmp(node->key, keyP, key_sizeP) == 0))) { + if(prevnode) { + prevnode->next=node->next; + } else { + hashtblP->nodes[hash]=node->next; + } + + hashtblP->freekeyfunc(node->key); + hashtblP->freedatafunc(node->data); + free(node); + return HASH_TABLE_OK; } - return HASH_TABLE_KEY_NOT_EXISTS; + + prevnode=node; + node=node->next; + } + + return HASH_TABLE_KEY_NOT_EXISTS; } //------------------------------------------------------------------------------------------------------------------------------- /* * Searching for an element is easy. We just search through the linked list for the corresponding hash value. * NULL is returned if we didn't find it. */ -hashtable_rc_t obj_hashtable_get(obj_hash_table_t *hashtblP, const void* keyP, int key_sizeP, void** dataP) -{ - obj_hash_node_t *node; - hash_size_t hash; +hashtable_rc_t obj_hashtable_get(obj_hash_table_t *hashtblP, const void *keyP, int key_sizeP, void **dataP) { + obj_hash_node_t *node; + hash_size_t hash; - if (hashtblP == NULL) { - *dataP = NULL; - return HASH_TABLE_BAD_PARAMETER_HASHTABLE; - } - hash=hashtblP->hashfunc(keyP, key_sizeP)%hashtblP->size; - node=hashtblP->nodes[hash]; - while(node) { - if(node->key == keyP) { - *dataP = node->data; - return HASH_TABLE_OK; - } else if (node->key_size == key_sizeP) { - if (memcmp(node->key, keyP, key_sizeP) == 0) { - *dataP = node->data; - return HASH_TABLE_OK; - } - } - node=node->next; - } + if (hashtblP == NULL) { *dataP = NULL; - return HASH_TABLE_KEY_NOT_EXISTS; + return HASH_TABLE_BAD_PARAMETER_HASHTABLE; + } + + hash=hashtblP->hashfunc(keyP, key_sizeP)%hashtblP->size; + node=hashtblP->nodes[hash]; + + while(node) { + if(node->key == keyP) { + *dataP = node->data; + return HASH_TABLE_OK; + } else if (node->key_size == key_sizeP) { + if (memcmp(node->key, keyP, key_sizeP) == 0) { + *dataP = node->data; + return HASH_TABLE_OK; + } + } + + node=node->next; + } + + *dataP = NULL; + return HASH_TABLE_KEY_NOT_EXISTS; } //------------------------------------------------------------------------------------------------------------------------------- /* * Function to return all keys of an object hash table */ -hashtable_rc_t obj_hashtable_get_keys(obj_hash_table_t *hashtblP, void ** keysP, unsigned int *sizeP) -{ - size_t n = 0; - obj_hash_node_t *node = NULL; - obj_hash_node_t *next = NULL; - - *sizeP = 0; - keysP = calloc(hashtblP->num_elements, sizeof(void *)); - if (keysP) { - for(n=0; n<hashtblP->size; ++n) { - for(node=hashtblP->nodes[n]; node; node=next) { - keysP[*sizeP++] = node->key; - next = node->next; - } - } - return HASH_TABLE_OK; + +hashtable_rc_t obj_hashtable_get_keys(obj_hash_table_t *hashtblP, void **keysP, unsigned int *sizeP) { + size_t n = 0; + obj_hash_node_t *node = NULL; + obj_hash_node_t *next = NULL; + *sizeP = 0; + keysP = calloc(hashtblP->num_elements, sizeof(void *)); + + if (keysP) { + for(n=0; n<hashtblP->size; ++n) { + for(node=hashtblP->nodes[n]; node; node=next) { + keysP[*sizeP++] = node->key; + next = node->next; + } } - return HASH_TABLE_SYSTEM_ERROR; + + // cppcheck-suppress memleak + return HASH_TABLE_OK; + } + + return HASH_TABLE_SYSTEM_ERROR; } //------------------------------------------------------------------------------------------------------------------------------- /* @@ -253,34 +272,32 @@ hashtable_rc_t obj_hashtable_get_keys(obj_hash_table_t *hashtblP, void ** keysP, * This allows us to reuse hashtable_insert() and hashtable_remove(), when moving the elements to the new table. * After that, we can just free the old table and copy the elements from newtbl to hashtbl. */ -hashtable_rc_t obj_hashtable_resize(obj_hash_table_t *hashtblP, hash_size_t sizeP) -{ - obj_hash_table_t newtbl; - hash_size_t n; - obj_hash_node_t *node,*next; +hashtable_rc_t obj_hashtable_resize(obj_hash_table_t *hashtblP, hash_size_t sizeP) { + obj_hash_table_t newtbl; + hash_size_t n; + obj_hash_node_t *node,*next; - if (hashtblP == NULL) { - return HASH_TABLE_BAD_PARAMETER_HASHTABLE; - } + if (hashtblP == NULL) { + return HASH_TABLE_BAD_PARAMETER_HASHTABLE; + } - newtbl.size = sizeP; - newtbl.hashfunc = hashtblP->hashfunc; + newtbl.size = sizeP; + newtbl.hashfunc = hashtblP->hashfunc; - if(!(newtbl.nodes=calloc(sizeP, sizeof(obj_hash_node_t*)))) return HASH_TABLE_SYSTEM_ERROR; + if(!(newtbl.nodes=calloc(sizeP, sizeof(obj_hash_node_t *)))) return HASH_TABLE_SYSTEM_ERROR; - for(n=0; n<hashtblP->size; ++n) { - for(node=hashtblP->nodes[n]; node; node=next) { - next = node->next; - obj_hashtable_insert(&newtbl, node->key, node->key_size, node->data); - obj_hashtable_remove(hashtblP, node->key, node->key_size); - } + for(n=0; n<hashtblP->size; ++n) { + for(node=hashtblP->nodes[n]; node; node=next) { + next = node->next; + obj_hashtable_insert(&newtbl, node->key, node->key_size, node->data); + obj_hashtable_remove(hashtblP, node->key, node->key_size); } + } - free(hashtblP->nodes); - hashtblP->size=newtbl.size; - hashtblP->nodes=newtbl.nodes; - - return HASH_TABLE_OK; + free(hashtblP->nodes); + hashtblP->size=newtbl.size; + hashtblP->nodes=newtbl.nodes; + return HASH_TABLE_OK; } diff --git a/common/utils/memory_pools.c b/common/utils/memory_pools.c index 78b6923dc863f982683d57a126c539651ef3817d..9f37e4708083dfa9139186da76ac2aa57db88671 100644 --- a/common/utils/memory_pools.c +++ b/common/utils/memory_pools.c @@ -23,19 +23,19 @@ #include "memory_pools.h" #if T_TRACER -#include <string.h> -#include "T.h" + #include <string.h> + #include "T.h" #endif /*------------------------------------------------------------------------------*/ const static int mp_debug = 0; # define MP_DEBUG(x, args...) do { if (mp_debug) fprintf(stdout, "[MP][D]"x, ##args); fflush (stdout); } \ - while(0) + while(0) /*------------------------------------------------------------------------------*/ #ifndef CHARS_TO_UINT32 -#define CHARS_TO_UINT32(c1, c2, c3, c4) (((c1) << 24) | ((c2) << 16) | ((c3) << 8) | (c4)) + #define CHARS_TO_UINT32(c1, c2, c3, c4) (((c1) << 24) | ((c2) << 16) | ((c3) << 8) | (c4)) #endif #define MEMORY_POOL_ITEM_INFO_NUMBER 2 @@ -129,33 +129,25 @@ static const pool_start_mark_t POOL_START_MARK = CHARS_TO_UINT32 ('P' static const pools_start_mark_t POOLS_START_MARK = CHARS_TO_UINT32 ('P', 'S', 's', 't'); /*------------------------------------------------------------------------------*/ -static inline uint32_t items_group_number_items (items_group_t *items_group) -{ +static inline uint32_t items_group_number_items (items_group_t *items_group) { return items_group->number_plus_one - 1; } -static inline uint32_t items_group_free_items (items_group_t *items_group) -{ +static inline uint32_t items_group_free_items (items_group_t *items_group) { items_group_positions_t positions; uint32_t free_items; - positions.all = items_group->positions.all; - free_items = items_group->number_plus_one + positions.ind.put - positions.ind.get; free_items %= items_group->number_plus_one; - return free_items; } -static inline items_group_index_t items_group_get_free_item (items_group_t *items_group) -{ +static inline items_group_index_t items_group_get_free_item (items_group_t *items_group) { items_group_position_t get_raw; items_group_position_t put; items_group_position_t get; items_group_position_t free_items; - items_group_index_t index = ITEMS_GROUP_INDEX_INVALID; - /* Get current put position */ put = items_group->positions.ind.put % items_group->number_plus_one; /* Get current get position and increase it */ @@ -193,11 +185,9 @@ static inline items_group_index_t items_group_get_free_item (items_group_t *item return (index); } -static inline int items_group_put_free_item (items_group_t *items_group, items_group_index_t index) -{ +static inline int items_group_put_free_item (items_group_t *items_group, items_group_index_t index) { items_group_position_t put_raw; items_group_position_t put; - /* Get current put position and increase it */ put_raw = __sync_fetch_and_add (&items_group->positions.ind.put, 1); put = put_raw % items_group->number_plus_one; @@ -209,70 +199,54 @@ static inline int items_group_put_free_item (items_group_t *items_group, items_g AssertError (items_group->indexes[put] <= ITEMS_GROUP_INDEX_INVALID, return (EXIT_FAILURE), "Index at current put position (%d) is not marked as free (%d)!\n", put, items_group->number_plus_one); - /* Save freed item index at current put position */ items_group->indexes[put] = index; return (EXIT_SUCCESS); } /*------------------------------------------------------------------------------*/ -static inline memory_pools_t *memory_pools_from_handler (memory_pools_handle_t memory_pools_handle) -{ +static inline memory_pools_t *memory_pools_from_handler (memory_pools_handle_t memory_pools_handle) { memory_pools_t *memory_pools; - /* Recover memory_pools */ memory_pools = (memory_pools_t *) memory_pools_handle; /* Sanity check on passed handle */ AssertError (memory_pools->start_mark == POOLS_START_MARK, memory_pools = NULL, "Handle %p is not a valid memory pools handle, start mark is missing!\n", memory_pools_handle); - return (memory_pools); } -static inline memory_pool_item_t *memory_pool_item_from_handler (memory_pool_item_handle_t memory_pool_item_handle) -{ +static inline memory_pool_item_t *memory_pool_item_from_handler (memory_pool_item_handle_t memory_pool_item_handle) { void *address; memory_pool_item_t *memory_pool_item; - /* Recover memory_pools */ address = memory_pool_item_handle - sizeof(memory_pool_item_start_t); memory_pool_item = (memory_pool_item_t *) address; - /* Sanity check on passed handle */ AssertError (memory_pool_item->start.start_mark == POOL_ITEM_START_MARK, memory_pool_item = NULL, "Handle %p is not a valid memory pool item handle, start mark is missing!\n", memory_pool_item); - return (memory_pool_item); } -static inline memory_pool_item_t *memory_pool_item_from_index (memory_pool_t *memory_pool, items_group_index_t index) -{ +static inline memory_pool_item_t *memory_pool_item_from_index (memory_pool_t *memory_pool, items_group_index_t index) { void *address; - address = (void *) memory_pool->items; address += index * memory_pool->pool_item_size; - return (address); } /*------------------------------------------------------------------------------*/ -memory_pools_handle_t memory_pools_create (uint32_t pools_number) -{ +memory_pools_handle_t memory_pools_create (uint32_t pools_number) { memory_pools_t *memory_pools; pool_id_t pool; - AssertFatal (pools_number <= MAX_POOLS_NUMBER, "Too many memory pools requested (%d/%d)!\n", pools_number, MAX_POOLS_NUMBER); /* Limit to a reasonable number of pools */ - /* Allocate memory_pools */ memory_pools = malloc (sizeof(memory_pools_t)); AssertFatal (memory_pools != NULL, "Memory pools structure allocation failed!\n"); - /* Initialize memory_pools */ { memory_pools->start_mark = POOLS_START_MARK; memory_pools->pools_number = pools_number; memory_pools->pools_defined = 0; - /* Allocate pools */ memory_pools->pools = calloc (pools_number, sizeof(memory_pool_t)); AssertFatal (memory_pools->pools != NULL, "Memory pools allocation failed!\n"); @@ -282,12 +256,10 @@ memory_pools_handle_t memory_pools_create (uint32_t pools_number) memory_pools->pools[pool].start_mark = POOL_START_MARK; } } - return ((memory_pools_handle_t) memory_pools); } -char *memory_pools_statistics(memory_pools_handle_t memory_pools_handle) -{ +char *memory_pools_statistics(memory_pools_handle_t memory_pools_handle) { memory_pools_t *memory_pools; pool_id_t pool; char *statistics; @@ -296,13 +268,10 @@ char *memory_pools_statistics(memory_pools_handle_t memory_pools_handle) uint32_t allocated_pools_memory = 0; items_group_t *items_group; uint32_t pool_items_size; - /* Recover memory_pools */ memory_pools = memory_pools_from_handler (memory_pools_handle); AssertFatal (memory_pools != NULL, "Failed to retrieve memory pool for handle %p!\n", memory_pools_handle); - statistics = malloc(memory_pools->pools_defined * 200); - printed_chars = sprintf (&statistics[0], "Pool: size, number, minimum, free, address space and memory used in Kbytes\n"); for (pool = 0; pool < memory_pools->pools_defined; pool++) { @@ -321,32 +290,25 @@ char *memory_pools_statistics(memory_pools_handle_t memory_pools_handle) } printed_chars = sprintf (&statistics[printed_chars], "Pools memory %u Kbytes\n", allocated_pools_memory / (1024)); - return (statistics); } -int memory_pools_add_pool (memory_pools_handle_t memory_pools_handle, uint32_t pool_items_number, uint32_t pool_item_size) -{ +int memory_pools_add_pool (memory_pools_handle_t memory_pools_handle, uint32_t pool_items_number, uint32_t pool_item_size) { memory_pools_t *memory_pools; memory_pool_t *memory_pool; pool_id_t pool; items_group_index_t item_index; memory_pool_item_t *memory_pool_item; - AssertFatal (pool_items_number <= MAX_POOL_ITEMS_NUMBER, "Too many items for a memory pool (%u/%d)!\n", pool_items_number, MAX_POOL_ITEMS_NUMBER); /* Limit to a reasonable number of items */ AssertFatal (pool_item_size <= MAX_POOL_ITEM_SIZE, "Item size is too big for memory pool items (%u/%d)!\n", pool_item_size, MAX_POOL_ITEM_SIZE); /* Limit to a reasonable item size */ - /* Recover memory_pools */ memory_pools = memory_pools_from_handler (memory_pools_handle); AssertFatal (memory_pools != NULL, "Failed to retrieve memory pool for handle %p!\n", memory_pools_handle); - /* Check number of already created pools */ AssertFatal (memory_pools->pools_defined < memory_pools->pools_number, "Can not allocate more memory pool (%d)!\n", memory_pools->pools_number); - /* Select pool */ pool = memory_pools->pools_defined; memory_pool = &memory_pools->pools[pool]; - /* Initialize pool */ { memory_pool->pool_id = pool; @@ -357,7 +319,6 @@ int memory_pools_add_pool (memory_pools_handle_t memory_pools_handle, uint32_t p memory_pool->items_group_free.minimum = pool_items_number; memory_pool->items_group_free.positions.ind.put = pool_items_number; memory_pool->items_group_free.positions.ind.get = 0; - /* Allocate free indexes */ memory_pool->items_group_free.indexes = malloc(memory_pool->items_group_free.number_plus_one * sizeof(items_group_index_t)); AssertFatal (memory_pool->items_group_free.indexes != NULL, "Memory pool indexes allocation failed!\n"); @@ -369,7 +330,6 @@ int memory_pools_add_pool (memory_pools_handle_t memory_pools_handle, uint32_t p /* Last index is not allocated */ memory_pool->items_group_free.indexes[item_index] = ITEMS_GROUP_INDEX_INVALID; - /* Allocate items */ memory_pool->items = calloc (pool_items_number, memory_pool->pool_item_size); AssertFatal (memory_pool->items != NULL, "Memory pool items allocation failed!\n"); @@ -383,20 +343,16 @@ int memory_pools_add_pool (memory_pools_handle_t memory_pools_handle, uint32_t p memory_pool_item->data[memory_pool->item_data_number] = POOL_ITEM_END_MARK; } } - memory_pools->pools_defined ++; - return (0); } -memory_pool_item_handle_t memory_pools_allocate (memory_pools_handle_t memory_pools_handle, uint32_t item_size, uint16_t info_0, uint16_t info_1) -{ +memory_pool_item_handle_t memory_pools_allocate (memory_pools_handle_t memory_pools_handle, uint32_t item_size, uint16_t info_0, uint16_t info_1) { memory_pools_t *memory_pools; memory_pool_item_t *memory_pool_item; memory_pool_item_handle_t memory_pool_item_handle = NULL; pool_id_t pool; items_group_index_t item_index = ITEMS_GROUP_INDEX_INVALID; - /* Recover memory_pools */ memory_pools = memory_pools_from_handler (memory_pools_handle); AssertError (memory_pools != NULL, {}, "Failed to retrieve memory pool for handle %p!\n", memory_pools_handle); @@ -424,12 +380,10 @@ memory_pool_item_handle_t memory_pools_allocate (memory_pools_handle_t memory_po /* Sanity check on item status, must be free */ AssertFatal (memory_pool_item->start.item_status == ITEM_STATUS_FREE, "Item status is not set to free (%d) in pool %u, item %d!\n", memory_pool_item->start.item_status, pool, item_index); - memory_pool_item->start.item_status = ITEM_STATUS_ALLOCATED; memory_pool_item->start.info[0] = info_0; memory_pool_item->start.info[1] = info_1; memory_pool_item_handle = memory_pool_item->data; - MP_DEBUG(" Alloc [%2u][%6d]{%6d}, %3u %3u, %6u, %p, %p, %p\n", pool, item_index, items_group_free_items (&memory_pools->pools[pool].items_group_free), @@ -445,8 +399,7 @@ memory_pool_item_handle_t memory_pools_allocate (memory_pools_handle_t memory_po return memory_pool_item_handle; } -int memory_pools_free (memory_pools_handle_t memory_pools_handle, memory_pool_item_handle_t memory_pool_item_handle, uint16_t info_0) -{ +int memory_pools_free (memory_pools_handle_t memory_pools_handle, memory_pool_item_handle_t memory_pool_item_handle, uint16_t info_0) { memory_pools_t *memory_pools; memory_pool_item_t *memory_pool_item; pool_id_t pool; @@ -455,36 +408,29 @@ int memory_pools_free (memory_pools_handle_t memory_pools_handle, memory_pool_it uint32_t pool_item_size; uint16_t info_1; int result; - /* Recover memory_pools */ memory_pools = memory_pools_from_handler (memory_pools_handle); AssertError (memory_pools != NULL, return (EXIT_FAILURE), "Failed to retrieve memory pools for handle %p!\n", memory_pools_handle); - /* Recover memory pool item */ memory_pool_item = memory_pool_item_from_handler (memory_pool_item_handle); AssertError (memory_pool_item != NULL, return (EXIT_FAILURE), "Failed to retrieve memory pool item for handle %p!\n", memory_pool_item_handle); - info_1 = memory_pool_item->start.info[1]; - /* Recover pool index */ pool = memory_pool_item->start.pool_id; AssertFatal (pool < memory_pools->pools_defined, "Pool index is invalid (%u/%u)!\n", pool, memory_pools->pools_defined); - item_size = memory_pools->pools[pool].item_data_number; pool_item_size = memory_pools->pools[pool].pool_item_size; item_index = (((void *) memory_pool_item) - ((void *) memory_pools->pools[pool].items)) / pool_item_size; - MP_DEBUG(" Free [%2u][%6d]{%6d}, %3u %3u, %p, %p, %p, %u\n", pool, item_index, items_group_free_items (&memory_pools->pools[pool].items_group_free), memory_pool_item->start.info[0], info_1, memory_pool_item_handle, memory_pool_item, memory_pools->pools[pool].items, ((uint32_t) (item_size * sizeof(memory_pool_data_t)))); - /* Sanity check on calculated item index */ AssertFatal (memory_pool_item == memory_pool_item_from_index(&memory_pools->pools[pool], item_index), "Incorrect memory pool item address (%p, %p) for pool %u, item %d!\n", - memory_pool_item, memory_pool_item_from_index(&memory_pools->pools[pool], item_index), pool, item_index); + memory_pool_item,(void *)memory_pool_item_from_index(&memory_pools->pools[pool], item_index), pool, item_index); /* Sanity check on end marker, must still be present (no write overflow) */ AssertFatal (memory_pool_item->data[item_size] == POOL_ITEM_END_MARK, "Memory pool item is corrupted, end mark is not present for pool %u, item %d!\n", pool, item_index); @@ -492,31 +438,23 @@ int memory_pools_free (memory_pools_handle_t memory_pools_handle, memory_pool_it AssertFatal (memory_pool_item->start.item_status == ITEM_STATUS_ALLOCATED, "Trying to free a non allocated (%x) memory pool item (pool %u, item %d)!\n", memory_pool_item->start.item_status, pool, item_index); - memory_pool_item->start.item_status = ITEM_STATUS_FREE; - result = items_group_put_free_item(&memory_pools->pools[pool].items_group_free, item_index); - AssertError (result == EXIT_SUCCESS, {}, "Failed to free memory pool item (pool %u, item %d)!\n", pool, item_index); - return (result); } -void memory_pools_set_info (memory_pools_handle_t memory_pools_handle, memory_pool_item_handle_t memory_pool_item_handle, int index, uint16_t info) -{ +void memory_pools_set_info (memory_pools_handle_t memory_pools_handle, memory_pool_item_handle_t memory_pool_item_handle, int index, uint16_t info) { memory_pools_t *memory_pools; memory_pool_item_t *memory_pool_item; pool_id_t pool; items_group_index_t item_index; uint32_t item_size; uint32_t pool_item_size; - AssertFatal (index < MEMORY_POOL_ITEM_INFO_NUMBER, "Incorrect info index (%d/%d)!\n", index, MEMORY_POOL_ITEM_INFO_NUMBER); - /* Recover memory pool item */ memory_pool_item = memory_pool_item_from_handler (memory_pool_item_handle); AssertFatal (memory_pool_item != NULL, "Failed to retrieve memory pool item for handle %p!\n", memory_pool_item_handle); - /* Set info[1] */ memory_pool_item->start.info[index] = info; @@ -525,26 +463,22 @@ void memory_pools_set_info (memory_pools_handle_t memory_pools_handle, memory_po /* Recover memory_pools */ memory_pools = memory_pools_from_handler (memory_pools_handle); AssertFatal (memory_pools != NULL, "Failed to retrieve memory pool for handle %p!\n", memory_pools_handle); - /* Recover pool index */ pool = memory_pool_item->start.pool_id; AssertFatal (pool < memory_pools->pools_defined, "Pool index is invalid (%u/%u)!\n", pool, memory_pools->pools_defined); - item_size = memory_pools->pools[pool].item_data_number; pool_item_size = memory_pools->pools[pool].pool_item_size; item_index = (((void *) memory_pool_item) - ((void *) memory_pools->pools[pool].items)) / pool_item_size; - MP_DEBUG(" Info [%2u][%6d]{%6d}, %3u %3u, %p, %p, %p, %u\n", pool, item_index, items_group_free_items (&memory_pools->pools[pool].items_group_free), memory_pool_item->start.info[0], memory_pool_item->start.info[1], memory_pool_item_handle, memory_pool_item, memory_pools->pools[pool].items, ((uint32_t) (item_size * sizeof(memory_pool_data_t)))); - /* Sanity check on calculated item index */ AssertFatal (memory_pool_item == memory_pool_item_from_index(&memory_pools->pools[pool], item_index), "Incorrect memory pool item address (%p, %p) for pool %u, item %d!\n", - memory_pool_item, memory_pool_item_from_index(&memory_pools->pools[pool], item_index), pool, item_index); + memory_pool_item, (void *)memory_pool_item_from_index(&memory_pools->pools[pool], item_index), pool, item_index); /* Sanity check on end marker, must still be present (no write overflow) */ AssertFatal (memory_pool_item->data[item_size] == POOL_ITEM_END_MARK, "Memory pool item is corrupted, end mark is not present for pool %u, item %d!\n", pool, item_index); diff --git a/common/utils/msc/msc.h b/common/utils/msc/msc.h index 4a71d52ffa8741d0834d75c7cab321090a666000..60c483a168e7b6be9788956ecd8da7817bff0e1a 100644 --- a/common/utils/msc/msc.h +++ b/common/utils/msc/msc.h @@ -62,9 +62,9 @@ typedef enum { MSC_S11_MME, MSC_S6A_MME, MSC_HSS, - MAX_MSC_PROTOS, MSC_X2AP_SRC_ENB, MSC_X2AP_TARGET_ENB, + MAX_MSC_PROTOS, } msc_proto_t; diff --git a/common/utils/telnetsrv/telnetsrv.c b/common/utils/telnetsrv/telnetsrv.c index 4e8e2c7c7fdbb48197698127685de7c45c23680c..b6803ead6bb15a668928fed2458ce738f7f3e3e1 100644 --- a/common/utils/telnetsrv/telnetsrv.c +++ b/common/utils/telnetsrv/telnetsrv.c @@ -58,7 +58,7 @@ #include "telnetsrv_phycmd.h" #include "telnetsrv_proccmd.h" -static char *telnet_defstatmod[] = {"softmodem","phy","loader"}; +static char *telnet_defstatmod[] = {"softmodem","phy","loader","measur"}; static telnetsrv_params_t telnetparams; #define TELNETSRV_LISTENADDR 0 #define TELNETSRV_LISTENPORT 1 @@ -77,17 +77,17 @@ paramdef_t telnetoptions[] = { /* configuration parameters for telnet utility */ /* optname helpstr paramflags XXXptr defXXXval type numelt */ /*--------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ - {"listenaddr", "<listen ip address>\n", 0, uptr:&telnetparams.listenaddr, defstrval:"0.0.0.0", TYPE_IPV4ADDR, 0 }, - {"listenport", "<local port>\n", 0, uptr:&(telnetparams.listenport), defuintval:9090, TYPE_UINT, 0 }, - {"priority", "<scheduling policy (0-99)\n", 0, iptr:&telnetparams.priority, defuintval:0, TYPE_INT, 0 }, - {"debug", "<debug level>\n", 0, uptr:NULL, defuintval:0, TYPE_UINT, 0 }, - {"loopcount", "<loop command iterations>\n", 0, uptr:&(telnetparams.loopcount), defuintval:10, TYPE_UINT, 0 }, - {"loopdelay", "<loop command delay (ms)>\n", 0, uptr:&(telnetparams.loopdelay), defuintval:5000, TYPE_UINT, 0 }, - {"histfile", "<history file name>\n", PARAMFLAG_NOFREE, strptr:&(telnetparams.histfile), defstrval:"oaitelnet.history", TYPE_STRING, 0 }, - {"histsize", "<history sizes>\n", 0, iptr:&(telnetparams.histsize), defuintval:50, TYPE_INT, 0 }, - {"phypbsize", "<phy dump buff size (bytes)>\n",0, uptr:&(telnetparams.phyprntbuff_size),defuintval:65000, TYPE_UINT, 0 }, - {"staticmod", "<static modules selection>\n", 0, strlistptr:NULL, defstrlistval:telnet_defstatmod,TYPE_STRINGLIST,(sizeof(telnet_defstatmod)/sizeof(char *))}, - {"shrmod", "<dynamic modules selection>\n", 0, strlistptr:NULL, defstrlistval:NULL,TYPE_STRINGLIST,0 } + {"listenaddr", "<listen ip address>", 0, uptr:&telnetparams.listenaddr, defstrval:"0.0.0.0", TYPE_IPV4ADDR, 0 }, + {"listenport", "<local port>", 0, uptr:&(telnetparams.listenport), defuintval:9090, TYPE_UINT, 0 }, + {"priority", "<scheduling policy (0-99)", 0, iptr:&telnetparams.priority, defuintval:0, TYPE_INT, 0 }, + {"debug", "<debug level>", 0, uptr:NULL, defuintval:0, TYPE_UINT, 0 }, + {"loopcount", "<loop command iterations>", 0, uptr:&(telnetparams.loopcount), defuintval:10, TYPE_UINT, 0 }, + {"loopdelay", "<loop command delay (ms)>", 0, uptr:&(telnetparams.loopdelay), defuintval:5000, TYPE_UINT, 0 }, + {"histfile", "<history file name>", PARAMFLAG_NOFREE, strptr:&(telnetparams.histfile), defstrval:"oaitelnet.history", TYPE_STRING, 0 }, + {"histsize", "<history sizes>", 0, iptr:&(telnetparams.histsize), defuintval:50, TYPE_INT, 0 }, + {"phypbsize", "<phy dump buff size (bytes)>",0, uptr:&(telnetparams.phyprntbuff_size),defuintval:65000, TYPE_UINT, 0 }, + {"staticmod", "<static modules selection>", 0, strlistptr:NULL, defstrlistval:telnet_defstatmod,TYPE_STRINGLIST,(sizeof(telnet_defstatmod)/sizeof(char *))}, + {"shrmod", "<dynamic modules selection>", 0, strlistptr:NULL, defstrlistval:NULL,TYPE_STRINGLIST,0 } }; int get_phybsize(void) { @@ -355,7 +355,7 @@ int setgetvar(int moduleindex,char getorset,char *params) { char varname[TELNET_CMD_MAXSIZE]; char *varval=NULL; memset(varname,0,sizeof(varname)); - n = sscanf(params,"%s %ms",varname,&varval); + n = sscanf(params,"%19s %ms",varname,&varval); for ( i=0 ; telnetparams.CmdParsers[moduleindex].var[i].varvalptr != NULL ; i++) { if ( strncasecmp(telnetparams.CmdParsers[moduleindex].var[i].varname,varname,strlen(telnetparams.CmdParsers[moduleindex].var[i].varname)) == 0) { @@ -475,7 +475,7 @@ int process_command(char *buf) { memset(cmdb,0,sizeof(cmdb)); bufbck=strdup(buf); rt=CMDSTATUS_NOTFOUND; - j = sscanf(buf,"%9s %9s %[^\t\n]",modulename,cmd,cmdb); + j = sscanf(buf,"%9s %9s %2000[^\t\n]",modulename,cmd,cmdb); if (telnetparams.telnetdbg > 0) printf("process_command: %i words, module=%s cmd=%s, parameters= %s\n",j,modulename,cmd,cmdb); @@ -500,23 +500,32 @@ int process_command(char *buf) { }/* else */ }/* strncmp: module name test */ else if (strncasecmp(modulename,"loop",4) == 0 ) { - int lc; int f = fcntl(telnetparams.new_socket,F_GETFL); - fcntl (telnetparams.new_socket, F_SETFL, O_NONBLOCK | f); + int f1=fcntl (telnetparams.new_socket, F_SETFL, O_NONBLOCK | f); - for(lc=0; lc<telnetparams.loopcount; lc++) { + if (f<0 || f1 <0) { + client_printf( " Loop won't be cancelable: %s\n",strerror(errno) ); + } + + for(int lc=0; lc<telnetparams.loopcount; lc++) { char dummybuff[20]; char tbuff[64]; - int rs; client_printf(CSI "1J" CSI "1;10H " STDFMT "%s %i/%i\n", get_time(tbuff,sizeof(tbuff)),lc,telnetparams.loopcount ); process_command(bufbck+strlen("loop")+1); - usleep(telnetparams.loopdelay * 1000); - rs = read(telnetparams.new_socket,dummybuff,sizeof(dummybuff)); + errno=0; + int rs = read(telnetparams.new_socket,dummybuff,sizeof(dummybuff)); - if ( rs > 0 ) { + if (telnetparams.telnetdbg > 0) + client_printf("Received \"%s\" status %d, errno %s while running loop\n",dummybuff,rs,strerror(errno)); + + if ( errno != EAGAIN && errno != EWOULDBLOCK) { + client_printf( STDFMT " Loop canceled, iteration %i/%i\n",lc,telnetparams.loopcount ); + lc=telnetparams.loopcount; break; } + + usleep(telnetparams.loopdelay * 1000); } fcntl (telnetparams.new_socket, F_SETFL, f); diff --git a/common/utils/telnetsrv/telnetsrv.h b/common/utils/telnetsrv/telnetsrv.h index 2d3ef531aee8494ad080f00f42c9b42c1934eb50..89f6a8dda11bd3180790359ae666a9b638e2269f 100644 --- a/common/utils/telnetsrv/telnetsrv.h +++ b/common/utils/telnetsrv/telnetsrv.h @@ -69,7 +69,8 @@ typedef struct cmddef { #define TELNET_VARTYPE_INT64 3 #define TELNET_VARTYPE_STRING 4 #define TELNET_VARTYPE_DOUBLE 5 -//#define TELNET_VARTYPE_PTR 6 +#define TELNET_VARTYPE_INT8 6 +#define TELNET_VARTYPE_UINT 7 typedef struct variabledef { char varname[TELNET_CMD_MAXSIZE]; char vartype; diff --git a/common/utils/telnetsrv/telnetsrv_CMakeLists.txt b/common/utils/telnetsrv/telnetsrv_CMakeLists.txt index 5dee7db4c41fef1d5c3f96b18eb770d64e044054..3a07632bfecf36a7306be40fcdd040397962a530 100644 --- a/common/utils/telnetsrv/telnetsrv_CMakeLists.txt +++ b/common/utils/telnetsrv/telnetsrv_CMakeLists.txt @@ -9,6 +9,7 @@ set(TELNETSRV_SOURCE ${TELNETROOT}/telnetsrv_phycmd.c ${TELNETROOT}/telnetsrv_proccmd.c ${TELNETROOT}/telnetsrv_loader.c + ${TELNETROOT}/telnetsrv_measurements.c ) #set(TELNETSRV_ETHDEVCMD_SOURCE diff --git a/common/utils/telnetsrv/telnetsrv_cpumeasur_def.h b/common/utils/telnetsrv/telnetsrv_cpumeasur_def.h new file mode 100644 index 0000000000000000000000000000000000000000..0b91ef1d4fccc063eba8d7b15128d48d03ab57d4 --- /dev/null +++ b/common/utils/telnetsrv/telnetsrv_cpumeasur_def.h @@ -0,0 +1,99 @@ +/* + * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The OpenAirInterface Software Alliance licenses this file to You under + * the OAI Public License, Version 1.1 (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.openairinterface.org/?page_id=698 + * + * 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. + *------------------------------------------------------------------------------- + * For more information about the OpenAirInterface (OAI) Software Alliance: + * contact@openairinterface.org + */ + +/*! \file common/utils/telnetsrv/telnetsrv_cpumeasur_def.h + * \brief: definitions of macro used to initialize the telnet_ltemeasurdef_t + * \ strucures arrays which are then used by the display functions + * \ in telnetsrv_measurements.c. + * \author Francois TABURET + * \date 2019 + * \version 0.1 + * \company NOKIA BellLabs France + * \email: francois.taburet@nokia-bell-labs.com + * \note + * \warning + */ + + +#define CPU_PHYENB_MEASURE \ +{ \ + {"phy_proc_tx", &(phyvars->phy_proc_tx),0},\ + {"phy_proc_rx", &(phyvars->phy_proc_rx),0},\ + {"rx_prach", &(phyvars->rx_prach),0},\ + {"ofdm_mod", &(phyvars->ofdm_mod_stats),0},\ + {"dlsch_common_and_dci", &(phyvars->dlsch_common_and_dci),0},\ + {"dlsch_ue_specific", &(phyvars->dlsch_ue_specific),0},\ + {"dlsch_encoding", &(phyvars->dlsch_encoding_stats),0},\ + {"dlsch_modulation", &(phyvars->dlsch_modulation_stats),0},\ + {"dlsch_scrambling", &(phyvars->dlsch_scrambling_stats),0},\ + {"dlsch_rate_matching", &(phyvars->dlsch_rate_matching_stats),0},\ + {"dlsch_turbo_encod_prep", &(phyvars->dlsch_turbo_encoding_preperation_stats),0},\ + {"dlsch_turbo_encod_segm", &(phyvars->dlsch_turbo_encoding_segmentation_stats),0},\ + {"dlsch_turbo_encod", &(phyvars->dlsch_turbo_encoding_stats),0},\ + {"dlsch_turbo_encod_waiting", &(phyvars->dlsch_turbo_encoding_waiting_stats),0},\ + {"dlsch_turbo_encod_signal", &(phyvars->dlsch_turbo_encoding_signal_stats),0},\ + {"dlsch_turbo_encod_main", &(phyvars->dlsch_turbo_encoding_main_stats),0},\ + {"dlsch_turbo_encod_wakeup0", &(phyvars->dlsch_turbo_encoding_wakeup_stats0),0},\ + {"dlsch_turbo_encod_wakeup1", &(phyvars->dlsch_turbo_encoding_wakeup_stats1),0},\ + {"dlsch_interleaving", &(phyvars->dlsch_interleaving_stats),0},\ + {"rx_dft", &(phyvars->rx_dft_stats),0},\ + {"ulsch_channel_estimation", &(phyvars->ulsch_channel_estimation_stats),0},\ + {"ulsch_freq_offset_estimation", &(phyvars->ulsch_freq_offset_estimation_stats),0},\ + {"ulsch_decoding", &(phyvars->ulsch_decoding_stats),0},\ + {"ulsch_demodulation", &(phyvars->ulsch_demodulation_stats),0},\ + {"ulsch_rate_unmatching", &(phyvars->ulsch_rate_unmatching_stats),0},\ + {"ulsch_turbo_decoding", &(phyvars->ulsch_turbo_decoding_stats),0},\ + {"ulsch_deinterleaving", &(phyvars->ulsch_deinterleaving_stats),0},\ + {"ulsch_demultiplexing", &(phyvars->ulsch_demultiplexing_stats),0},\ + {"ulsch_llr", &(phyvars->ulsch_llr_stats),0},\ + {"ulsch_tc_init", &(phyvars->ulsch_tc_init_stats),0},\ + {"ulsch_tc_alpha", &(phyvars->ulsch_tc_alpha_stats),0},\ + {"ulsch_tc_beta", &(phyvars->ulsch_tc_beta_stats),0},\ + {"ulsch_tc_gamma", &(phyvars->ulsch_tc_gamma_stats),0},\ + {"ulsch_tc_ext", &(phyvars->ulsch_tc_ext_stats),0},\ + {"ulsch_tc_intl1", &(phyvars->ulsch_tc_intl1_stats),0},\ + {"ulsch_tc_intl2", &(phyvars->ulsch_tc_intl2_stats),0},\ +} + +#define CPU_MACENB_MEASURE \ +{ \ + {"eNB_scheduler", &(macvars->eNB_scheduler),0},\ + {"schedule_si", &(macvars->schedule_si),0},\ + {"schedule_ra", &(macvars->schedule_ra),0},\ + {"schedule_ulsch", &(macvars->schedule_ulsch),0},\ + {"fill_DLSCH_dci", &(macvars->fill_DLSCH_dci),0},\ + {"schedule_dlsch_pre", &(macvars->schedule_dlsch_preprocessor),0},\ + {"schedule_dlsch", &(macvars->schedule_dlsch),0},\ + {"schedule_mch", &(macvars->schedule_mch),0},\ + {"rx_ulsch_sdu", &(macvars->rx_ulsch_sdu),0},\ + {"schedule_pch", &(macvars->schedule_pch),0},\ +} + +#define CPU_PDCPENB_MEASURE \ +{ \ + {"pdcp_run", &(pdcpvars->pdcp_run),0},\ + {"data_req", &(pdcpvars->data_req),0},\ + {"data_ind", &(pdcpvars->data_ind),0},\ + {"apply_security", &(pdcpvars->apply_security),0},\ + {"validate_security", &(pdcpvars->validate_security),0},\ + {"pdcp_ip", &(pdcpvars->pdcp_ip),0},\ + {"ip_pdcp", &(pdcpvars->ip_pdcp),0},\ +} diff --git a/common/utils/telnetsrv/telnetsrv_measurements.c b/common/utils/telnetsrv/telnetsrv_measurements.c new file mode 100644 index 0000000000000000000000000000000000000000..7cfc6562254b0522f19cf1ba78d27a8fa956d557 --- /dev/null +++ b/common/utils/telnetsrv/telnetsrv_measurements.c @@ -0,0 +1,316 @@ +/* + * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The OpenAirInterface Software Alliance licenses this file to You under + * the OAI Public License, Version 1.1 (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.openairinterface.org/?page_id=698 + * + * 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. + *------------------------------------------------------------------------------- + * For more information about the OpenAirInterface (OAI) Software Alliance: + * contact@openairinterface.org + */ + +/*! \file common/utils/telnetsrv/telnetsrv_measurements.c + * \brief: implementation of telnet commands related to measurments + * \author Francois TABURET + * \date 2019 + * \version 0.1 + * \company NOKIA BellLabs France + * \email: francois.taburet@nokia-bell-labs.com + * \note + * \warning + */ +#define _GNU_SOURCE +#include <sys/types.h> +#include <stdio.h> +#include <unistd.h> +#include <errno.h> +#include <stdlib.h> +#include <string.h> +#include <stdarg.h> + + + + +#define TELNETSERVERCODE +#include "telnetsrv.h" +#define TELNETSRV_MEASURMENTS_MAIN +#include "common/utils/LOG/log.h" +#include "common/config/config_userapi.h" +#include "telnetsrv_measurements.h" +#include "telnetsrv_ltemeasur_def.h" +#include "telnetsrv_cpumeasur_def.h" +#include "openair2/LAYER2/MAC/mac.h" +#include "openair1/PHY/phy_extern.h" + +void measurcmd_display_macstats(telnet_printfunc_t prnt); +void measurcmd_display_macstats_ue(telnet_printfunc_t prnt); +void measurcmd_display_rlcstats(telnet_printfunc_t prnt); +void measurcmd_display_phycpu(telnet_printfunc_t prnt); +void measurcmd_display_maccpu(telnet_printfunc_t prnt); +void measurcmd_display_pdcpcpu(telnet_printfunc_t prnt); + + +static telnet_measurgroupdef_t measurgroups[] = { + {"enb", GROUP_LTESTATS,0, measurcmd_display_macstats, {NULL}}, + {"enbues",GROUP_LTESTATS,0, measurcmd_display_macstats_ue,{NULL}}, + {"rlc", GROUP_LTESTATS,0, measurcmd_display_rlcstats, {NULL}}, + {"phycpu",GROUP_CPUSTATS,0, measurcmd_display_phycpu, {NULL}}, + {"maccpu",GROUP_CPUSTATS,0, measurcmd_display_maccpu, {NULL}}, + {"pdcpcpu",GROUP_CPUSTATS,0, measurcmd_display_pdcpcpu, {NULL}}, +}; +#define TELNET_NUM_MEASURGROUPS (sizeof(measurgroups)/sizeof(telnet_measurgroupdef_t)) + +static int eNB_id =0; +static char *grouptypes[] = {"ltestats","cpustats"}; +static double cpufreq; +#define TELNET_NUM_MEASURTYPES (sizeof(grouptypes)/sizeof(char *)) + +#define HDR "---------------------------------" + +void measurcmd_display_groups(telnet_printfunc_t prnt) { + prnt(" %*s %10s %s\n",TELNET_MAXMEASURNAME_LEN-1,"name","type","nombre de mesures"); + + for(int i=0; i<TELNET_NUM_MEASURGROUPS; i++) + prnt("%02d %*s %10s %i\n",i,TELNET_MAXMEASURNAME_LEN-1,measurgroups[i].groupname, + grouptypes[measurgroups[i].type], measurgroups[i].size); +} /* measurcmd_display_groups */ +/*----------------------------------------------------------------------------------------------------*/ +/* cpu measurements functions */ +void measurcmd_display_cpumeasures(telnet_printfunc_t prnt, telnet_cpumeasurdef_t *cpumeasure, int cpumeasure_size) { + for (int i=0; i<cpumeasure_size; i++) { + prnt("%02d %*s: %15.3f us; %15d %s",i,TELNET_MAXMEASURNAME_LEN-1,(cpumeasure+i)->statname, + ((cpumeasure+i)->astatptr->trials!=0)?(((cpumeasure+i)->astatptr->diff)/((cpumeasure+i)->astatptr->trials))/cpufreq/1000:0, + (cpumeasure+i)->astatptr->trials, ((i%2)==1)?"|\n":" | " ); + } + + prnt("\n\n"); +} /* measurcmd_display_measures */ + +#define PRINT_CPUMEAS_STATE ((cpumeas(CPUMEAS_GETSTATE))?"enabled":"disabled") +void measurcmd_display_phycpu(telnet_printfunc_t prnt) { + PHY_VARS_eNB *phyvars = RC.eNB[eNB_id][0]; + telnet_cpumeasurdef_t cpumeasur[]=CPU_PHYENB_MEASURE; + prnt("%s cpu (%1.1g GHz) measurements: PHY (cpustats %s) %s\n",HDR,cpufreq, + PRINT_CPUMEAS_STATE,HDR); + measurcmd_display_cpumeasures(prnt, cpumeasur, sizeof(cpumeasur)/sizeof(telnet_cpumeasurdef_t)); +} + +void measurcmd_display_maccpu(telnet_printfunc_t prnt) { + eNB_MAC_INST *macvars = RC.mac[eNB_id]; + telnet_cpumeasurdef_t cpumeasur[]=CPU_MACENB_MEASURE; + prnt("%s cpu (%1.1g GHz) measurements: MAC (cpustats %s) %s\n",HDR,cpufreq, + PRINT_CPUMEAS_STATE,HDR); + measurcmd_display_cpumeasures(prnt, cpumeasur, sizeof(cpumeasur)/sizeof(telnet_cpumeasurdef_t)); +} + +void measurcmd_display_pdcpcpu(telnet_printfunc_t prnt) { + pdcp_stats_t *pdcpvars = &(eNB_pdcp_stats[eNB_id]); + telnet_cpumeasurdef_t cpumeasur[]=CPU_PDCPENB_MEASURE; + prnt("%s cpu (%1.1g GHz) measurements: PDCP (cpustats %s) %s \n",HDR,cpufreq, + PRINT_CPUMEAS_STATE,HDR); + measurcmd_display_cpumeasures(prnt, cpumeasur, sizeof(cpumeasur)/sizeof(telnet_cpumeasurdef_t)); +} +/*----------------------------------------------------------------------------------------------------*/ +/* lte measurements functions */ +uint64_t measurcmd_getstatvalue(telnet_ltemeasurdef_t *measur,telnet_printfunc_t prnt) { + uint64_t val; + + switch(measur->vtyp) { + case TELNET_VARTYPE_INT64: + val = (uint64_t)(*((uint64_t *)(measur->vptr))); + break; + + case TELNET_VARTYPE_INT32: + val = (uint64_t)(*((uint32_t *)(measur->vptr))); + break; + + case TELNET_VARTYPE_INT16: + val = (uint64_t)(*((uint16_t *)(measur->vptr))); + break; + + case TELNET_VARTYPE_INT8: + val = (uint64_t)(*((uint8_t *)(measur->vptr))); + break; + + case TELNET_VARTYPE_UINT: + val = (uint64_t)(*((unsigned int *)(measur->vptr))); + break; + + default: + prnt("%s %i: unknown type \n",measur->statname,measur->vtyp); + val = (uint64_t)(*((uint64_t *)(measur->vptr))); + break; + } + + return val; +} /* measurcmd_getstatvalue */ + +void measurcmd_display_measures(telnet_printfunc_t prnt, telnet_ltemeasurdef_t *statsptr, int stats_size) { + for (int i=0; i<stats_size; i++) { + prnt("%*s = %15llu%s",TELNET_MAXMEASURNAME_LEN-1,statsptr[i].statname, + measurcmd_getstatvalue(&(statsptr[i]),prnt), ((i%3)==2)?"\n":" "); + } + + prnt("\n\n"); +} /* measurcmd_display_measures */ + +void measurcmd_display_macstats_ue(telnet_printfunc_t prnt) { + UE_list_t *UE_list = &(RC.mac[eNB_id]->UE_list); + + for (int UE_id=UE_list->head; UE_id>=0; UE_id=UE_list->next[UE_id]) { + for (int i=0; i<UE_list->numactiveCCs[UE_id]; i++) { + int CC_id = UE_list->ordered_CCids[i][UE_id]; + prnt("%s UE %i Id %i CCid %i %s\n",HDR,i,UE_id,CC_id,HDR); + eNB_UE_STATS *macuestatptr = &(UE_list->eNB_UE_stats[CC_id][UE_id]); + telnet_ltemeasurdef_t statsptr[]=LTEMAC_UEMEASURE; + measurcmd_display_measures(prnt, statsptr, sizeof(statsptr)/sizeof(telnet_ltemeasurdef_t)); + } + } +} /* measurcmd_display_macstats_ue */ + +void measurcmd_display_macstats(telnet_printfunc_t prnt) { + for (int CC_id=0 ; CC_id < MAX_NUM_CCs; CC_id++) { + eNB_STATS *macstatptr=&(RC.mac[eNB_id]->eNB_stats[CC_id]); + telnet_ltemeasurdef_t statsptr[]=LTEMAC_MEASURE; + prnt("%s eNB %i mac stats CC %i frame %u %s\n", + HDR, eNB_id, CC_id, RC.mac[eNB_id]->frame,HDR); + measurcmd_display_measures(prnt,statsptr,sizeof(statsptr)/sizeof(telnet_ltemeasurdef_t)); + } +} /* measurcmd_display_macstats */ + + +void measurcmd_display_one_rlcstat(telnet_printfunc_t prnt, int UE_id, telnet_ltemeasurdef_t *statsptr, int num_rlcmeasure, unsigned int *rlcstats, + char *rbid_str, protocol_ctxt_t *ctxt, const srb_flag_t srb_flagP, const rb_id_t rb_idP) + +{ + int rlc_status = rlc_stat_req(ctxt,srb_flagP,rb_idP, + rlcstats, rlcstats+1, rlcstats+2, rlcstats+3, rlcstats+4, rlcstats+5, + rlcstats+6, rlcstats+7, rlcstats+8, rlcstats+9, rlcstats+10, rlcstats+11, + rlcstats+12, rlcstats+13, rlcstats+14, rlcstats+15, rlcstats+16, rlcstats+17, + rlcstats+18, rlcstats+19, rlcstats+20, rlcstats+21, rlcstats+22, rlcstats+23, + rlcstats+24, rlcstats+25, rlcstats+26, rlcstats+27); + + if (rlc_status == RLC_OP_STATUS_OK) { + prnt("%s UE %i RLC %s mode %s %s\n",HDR,UE_id, rbid_str, + (rlcstats[0]==RLC_MODE_AM)? "AM": (rlcstats[0]==RLC_MODE_UM)?"UM":"NONE",HDR); + measurcmd_display_measures(prnt, statsptr, num_rlcmeasure); + } +} /* status measurcmd_rlc_stat_req */ + + +void measurcmd_display_rlcstats(telnet_printfunc_t prnt) { + protocol_ctxt_t ctxt; + UE_list_t *UE_list = &(RC.mac[eNB_id]->UE_list); + telnet_ltemeasurdef_t statsptr[]=LTE_RLCMEASURE; + int num_rlcmeasure = sizeof(statsptr)/sizeof(telnet_ltemeasurdef_t ); + unsigned int *rlcstats = malloc(num_rlcmeasure*sizeof(unsigned int)); + eNB_MAC_INST *eNB = RC.mac[eNB_id]; + + for(int i=0; i <num_rlcmeasure ; i++) { + statsptr[i].vptr = rlcstats + i; + } + + for (int UE_id=UE_list->head; UE_id>=0; UE_id=UE_list->next[UE_id]) { +#define NB_eNB_INST 1 + PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt,eNB_id, ENB_FLAG_YES,UE_list->eNB_UE_stats[0][UE_id].crnti, + eNB->frame,eNB->subframe,eNB_id); + measurcmd_display_one_rlcstat(prnt, UE_id, statsptr, num_rlcmeasure, rlcstats, "DCCH", &ctxt, SRB_FLAG_YES, DCCH); + measurcmd_display_one_rlcstat(prnt, UE_id, statsptr, num_rlcmeasure, rlcstats, "DTCH", &ctxt, SRB_FLAG_NO, DTCH-2); + } +} /* measurcmd_display_macstats_ue */ + +/*------------------------------------------------------------------------------------------------------------------------*/ +/* function called by the telnet server when measur command is entered */ +int measurcmd_show(char *buf, int debug, telnet_printfunc_t prnt) { + char *subcmd=NULL; + int idx1, idx2; + int badcmd=1; + + if (debug > 0) + prnt(" measurcmd_show received %s\n",buf); + + // char tmp[20480]; + // dump_eNB_l2_stats(tmp, 0); + // prnt("%s\n",tmp); + int s = sscanf(buf,"%ms %i-%i\n",&subcmd, &idx1,&idx2); + + if (s>0) { + if ( strcmp(subcmd,"groups") == 0) { + measurcmd_display_groups(prnt); + badcmd=0; + } else { + for (int i=0; i<TELNET_NUM_MEASURTYPES; i++) { + if(strcmp(subcmd,grouptypes[i]) == 0) { + for(int j=0; j<TELNET_NUM_MEASURGROUPS; j++) { + if(i == measurgroups[j].type) { + badcmd=0; + measurgroups[j].displayfunc(prnt); + } + } /* for j...*/ + } + }/* for i...*/ + + for (int i=0; i<TELNET_NUM_MEASURGROUPS; i++) { + if(strcmp(subcmd,measurgroups[i].groupname) == 0) { + measurgroups[i].displayfunc(prnt); + badcmd=0; + break; + } + } + } + + free(subcmd); + } /* s>0 */ + + if (badcmd) { + prnt("%s: unknown measur command\n",buf); + } + + return CMDSTATUS_FOUND; +} + + +int measurcmd_cpustats(char *buf, int debug, telnet_printfunc_t prnt) { + char *subcmd=NULL; + int idx1, idx2; + int badcmd=1; + + if (debug > 0) + prnt(" measurcmd_show received %s\n",buf); + + int s = sscanf(buf,"%ms %i-%i\n",&subcmd, &idx1,&idx2); + + if (s>0) { + if ( strcmp(subcmd,"enable") == 0) { + cpumeas(CPUMEAS_ENABLE); + badcmd=0; + } else if ( strcmp(subcmd,"disable") == 0) { + cpumeas(CPUMEAS_DISABLE); + badcmd=0; + } + } + + if (badcmd) { + prnt("Cpu measurments state: %s\n",PRINT_CPUMEAS_STATE); + } + + free(subcmd); + return CMDSTATUS_FOUND; +} +/*-------------------------------------------------------------------------------------*/ + +/* function called at telnet server init to add the measur command */ +void add_measur_cmds(void) { + add_telnetcmd("measur",measur_vardef,measur_cmdarray); + cpufreq = get_cpu_freq_GHz(); +} diff --git a/common/utils/telnetsrv/telnetsrv_measurements.h b/common/utils/telnetsrv/telnetsrv_measurements.h new file mode 100644 index 0000000000000000000000000000000000000000..46f25da4c52ddc3e17ce071501c0a98481b01eb7 --- /dev/null +++ b/common/utils/telnetsrv/telnetsrv_measurements.h @@ -0,0 +1,88 @@ +/* + * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The OpenAirInterface Software Alliance licenses this file to You under + * the OAI Public License, Version 1.1 (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.openairinterface.org/?page_id=698 + * + * 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. + *------------------------------------------------------------------------------- + * For more information about the OpenAirInterface (OAI) Software Alliance: + * contact@openairinterface.org + */ + + +/*! \file common/utils/telnetsrv/telnetsrv_measurements.h + * \brief: Include file defining constants, structures and function prototypes + * \ used to implement the measurements functionality of the telnet server + * \author Francois TABURET + * \date 2019 + * \version 0.1 + * \company NOKIA BellLabs France + * \email: francois.taburet@nokia-bell-labs.com + * \note + * \warning + */ +#include <dlfcn.h> +#include "telnetsrv.h" +#include "openair1/PHY/defs_eNB.h" +#ifdef TELNETSRV_MEASURMENTS_MAIN + + +#define TELNET_MAXMEASURNAME_LEN 30 +#define TELNET_MAXMEASURGROUPS 10 + +telnetshell_vardef_t measur_vardef[] = { + {"",0,NULL} +}; + +typedef struct cpumeasurdef { + char statname[TELNET_MAXMEASURNAME_LEN]; + time_stats_t *astatptr; + unsigned int statemask; +} telnet_cpumeasurdef_t; + +typedef struct ltemeasurdef { + char statname[TELNET_MAXMEASURNAME_LEN]; + void *vptr; + char vtyp; + unsigned int statemask; +} telnet_ltemeasurdef_t; + +#define GROUP_LTESTATS 0 +#define GROUP_CPUSTATS 1 +typedef void(*measur_dislayfunc_t)(telnet_printfunc_t prnt); +typedef struct mesurgroupdef { + char groupname[TELNET_MAXMEASURNAME_LEN]; + unsigned char type; + unsigned char size; + measur_dislayfunc_t displayfunc; + union { + telnet_cpumeasurdef_t *cpustats; + telnet_ltemeasurdef_t *ltestats; + }; +} telnet_measurgroupdef_t; + +#define MACSTATS_NAME(valptr) #valptr +#define LTEMAC_MEASURGROUP_NAME "ltemac" +#define PHYCPU_MEASURGROUP_NAME "phycpu" + +int measurcmd_show(char *buf, int debug, telnet_printfunc_t prnt); +int measurcmd_cpustats(char *buf, int debug, telnet_printfunc_t prnt); +telnetshell_cmddef_t measur_cmdarray[] = { + {"show", "groups | <group name>" , measurcmd_show}, + {"cpustats","[enable | disable]",measurcmd_cpustats}, + {"","",NULL} +}; + +#else +extern void add_measur_cmds(void); +#endif /* TELNETSRV_MEASURCMD_MAIN */ diff --git a/common/utils/telnetsrv/telnetsrv_phycmd.c b/common/utils/telnetsrv/telnetsrv_phycmd.c index c60126f1c741e4d9d93323e761862d0f7458e561..35554a77a6109cd062959f4d695eace094cb2be8 100644 --- a/common/utils/telnetsrv/telnetsrv_phycmd.c +++ b/common/utils/telnetsrv/telnetsrv_phycmd.c @@ -29,7 +29,7 @@ * \note * \warning */ -#define _GNU_SOURCE +#define _GNU_SOURCE #include <string.h> #include <pthread.h> @@ -39,104 +39,88 @@ #define TELNETSRV_PHYCMD_MAIN #include "telnetsrv_phycmd.h" char *prnbuff; -extern int dump_eNB_stats(PHY_VARS_eNB *eNB, char* buffer, int length); - -void init_phytelnet(void) -{ -prnbuff=malloc(get_phybsize() ); -if (prnbuff == NULL) - { - fprintf(stderr,"Error %s on malloc in init_phytelnet()\n",strerror(errno)); - } -} +extern int dump_eNB_l2_stats(char *buffer, int length); + +void init_phytelnet(void) { + prnbuff=malloc(get_phybsize() ); -void display_uestatshead( telnet_printfunc_t prnt) -{ -prnt("cc ue rnti Dmcs Umcs tao tau Dbr Dtb \n"); + if (prnbuff == NULL) { + fprintf(stderr,"Error %s on malloc in init_phytelnet()\n",strerror(errno)); + } } -void dump_uestats(int debug, telnet_printfunc_t prnt, uint8_t prntflag) -{ +void display_uestatshead( telnet_printfunc_t prnt) { + prnt("cc ue rnti Dmcs Umcs tao tau Dbr Dtb \n"); +} -int p; +void dump_uestats(int debug, telnet_printfunc_t prnt, uint8_t prntflag) { + int p; + prnbuff=malloc(20480); + p=dump_eNB_l2_stats( prnbuff, 20480); - p=dump_eNB_l2_stats( prnbuff, 0); - if(prntflag>=1) - prnt("%s\n",prnbuff); - if(debug>=1) - prnt("%i bytes printed\n",p); + if(prntflag>=1) + prnt("%s\n",prnbuff); + if(debug>=1) + prnt("%i bytes printed\n",p); + free(prnbuff); } -void display_uestats(int debug, telnet_printfunc_t prnt, int ue) -{ - for (int cc=0; cc<1 ; cc++) - { - - - } +void display_uestats(int debug, telnet_printfunc_t prnt, int ue) { + for (int cc=0; cc<1 ; cc++) { + } } -void display_phycounters(char *buf, int debug, telnet_printfunc_t prnt) -{ - prnt(" DLSCH kb DLSCH kb/s\n"); - - dump_uestats(debug, prnt,0); - +void display_phycounters(char *buf, int debug, telnet_printfunc_t prnt) { + prnt(" DLSCH kb DLSCH kb/s\n"); + dump_uestats(debug, prnt,0); } -int dump_phyvars(char *buf, int debug, telnet_printfunc_t prnt) -{ - - - - if (debug > 0) - prnt("phy interface module received %s\n",buf); - if (strcasestr(buf,"phycnt") != NULL) - { - display_phycounters(buf, debug, prnt); - } - if (strcasestr(buf,"uestat") != NULL) - { - char *cptr=strcasestr(buf+sizeof("uestat"),"UE"); - display_uestatshead(prnt); - if (cptr != NULL) - { - int ueidx = strtol( cptr+sizeof("UE"), NULL, 10); - if (ueidx < NUMBER_OF_UE_MAX && ueidx >= 0) - { - display_uestats(debug, prnt,ueidx); - } - } /* if cptr != NULL */ - else - { - for (int ue=0; ue<NUMBER_OF_UE_MAX ; ue++) - { - display_uestats(debug, prnt,ue); - } - } /* else cptr != NULL */ - } /* uestat */ - if (strcasestr(buf,"uedump") != NULL) - { - dump_uestats(debug, prnt,1); - } - return 0; +int dump_phyvars(char *buf, int debug, telnet_printfunc_t prnt) { + if (debug > 0) + prnt("phy interface module received %s\n",buf); + + if (strcasestr(buf,"phycnt") != NULL) { + display_phycounters(buf, debug, prnt); + } + + if (strcasestr(buf,"uestat") != NULL) { + char *cptr=strcasestr(buf+sizeof("uestat"),"UE"); + display_uestatshead(prnt); + + if (cptr != NULL) { + int ueidx = strtol( cptr+sizeof("UE"), NULL, 10); + + if (ueidx < NUMBER_OF_UE_MAX && ueidx >= 0) { + display_uestats(debug, prnt,ueidx); + } + } /* if cptr != NULL */ + else { + for (int ue=0; ue<NUMBER_OF_UE_MAX ; ue++) { + display_uestats(debug, prnt,ue); + } + } /* else cptr != NULL */ + } /* uestat */ + + if (strcasestr(buf,"uedump") != NULL) { + dump_uestats(debug, prnt,1); + } + + return 0; } telnetshell_cmddef_t phy_cmdarray[] = { - {"disp","[phycnt,uedump,uestat UE<x>]", dump_phyvars}, + {"disp","[phycnt,uedump,uestat UE<x>]", dump_phyvars}, - {"","",NULL}, + {"","",NULL}, }; /*-------------------------------------------------------------------------------------*/ -void add_phy_cmds(void) -{ - - init_phytelnet(); - add_telnetcmd("phy", phy_vardef, phy_cmdarray); +void add_phy_cmds(void) { + init_phytelnet(); + add_telnetcmd("phy", phy_vardef, phy_cmdarray); } diff --git a/doc/FEATURE_SET.md b/doc/FEATURE_SET.md index fef47d9c271aae7eaf53640715baa9a48fb2a972..29163fd83208a670cb466769430d9257990181e1 100644 --- a/doc/FEATURE_SET.md +++ b/doc/FEATURE_SET.md @@ -124,6 +124,9 @@ The X2AP layer is based on **3GPP 36.423** v14.6.0 and implements the following - X2 Setup Request - X2 Setup Response + - X2 Setup Failure + - Handover Request + - Handover Request Acknowledge ## eNB Advanced Features ## diff --git a/nfapi/oai_integration/nfapi_vnf.c b/nfapi/oai_integration/nfapi_vnf.c index 3da2059ba7174e5b15b72860d050c4bf4ba5e03e..2597c9e8deb477d00e0d0fa0fd25aeb4f502ab0c 100644 --- a/nfapi/oai_integration/nfapi_vnf.c +++ b/nfapi/oai_integration/nfapi_vnf.c @@ -61,7 +61,7 @@ typedef struct { char local_addr[80]; int local_port; - char* remote_addr; + char *remote_addr; int remote_port; uint8_t duplex_mode; @@ -127,12 +127,12 @@ typedef struct mac mac_t; typedef struct mac { - void* user_data; + void *user_data; - void (*dl_config_req)(mac_t* mac, nfapi_dl_config_request_t* req); - void (*ul_config_req)(mac_t* mac, nfapi_ul_config_request_t* req); - void (*hi_dci0_req)(mac_t* mac, nfapi_hi_dci0_request_t* req); - void (*tx_req)(mac_t* mac, nfapi_tx_request_t* req); + void (*dl_config_req)(mac_t *mac, nfapi_dl_config_request_t *req); + void (*ul_config_req)(mac_t *mac, nfapi_ul_config_request_t *req); + void (*hi_dci0_req)(mac_t *mac, nfapi_hi_dci0_request_t *req); + void (*tx_req)(mac_t *mac, nfapi_tx_request_t *req); } mac_t; typedef struct { @@ -145,15 +145,15 @@ typedef struct { unsigned aperiodic_timing_enabled; unsigned periodic_timing_period; - // This is not really the right place if we have multiple PHY, + // This is not really the right place if we have multiple PHY, // should be part of the phy struct udp_data udp; uint8_t thread_started; - nfapi_vnf_p7_config_t* config; + nfapi_vnf_p7_config_t *config; - mac_t* mac; + mac_t *mac; } vnf_p7_info; @@ -165,24 +165,27 @@ typedef struct { } vnf_info; -int vnf_pack_vendor_extension_tlv(void* ve, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p4_p5_codec_config_t* codec) { +int vnf_pack_vendor_extension_tlv(void *ve, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p4_p5_codec_config_t *codec) { //NFAPI_TRACE(NFAPI_TRACE_INFO, "vnf_pack_vendor_extension_tlv\n"); - nfapi_tl_t* tlv = (nfapi_tl_t*)ve; + nfapi_tl_t *tlv = (nfapi_tl_t *)ve; + switch(tlv->tag) { - case VENDOR_EXT_TLV_2_TAG: - { - //NFAPI_TRACE(NFAPI_TRACE_INFO, "Packing VENDOR_EXT_TLV_2\n"); - vendor_ext_tlv_2* ve = (vendor_ext_tlv_2*)tlv; - if(!push32(ve->dummy, ppWritePackedMsg, end)) - return 0; - return 1; - } - break; + case VENDOR_EXT_TLV_2_TAG: { + //NFAPI_TRACE(NFAPI_TRACE_INFO, "Packing VENDOR_EXT_TLV_2\n"); + vendor_ext_tlv_2 *ve = (vendor_ext_tlv_2 *)tlv; + + if(!push32(ve->dummy, ppWritePackedMsg, end)) + return 0; + + return 1; + } + break; } + return -1; } -int vnf_unpack_vendor_extension_tlv(nfapi_tl_t* tl, uint8_t **ppReadPackedMessage, uint8_t *end, void** ve, nfapi_p4_p5_codec_config_t* codec) { +int vnf_unpack_vendor_extension_tlv(nfapi_tl_t *tl, uint8_t **ppReadPackedMessage, uint8_t *end, void **ve, nfapi_p4_p5_codec_config_t *codec) { return -1; } @@ -192,17 +195,14 @@ extern void init_eNB_afterRU(void); extern uint16_t sf_ahead; void oai_create_enb(void) { - int bodge_counter=0; PHY_VARS_eNB *eNB = RC.eNB[0][0]; - - printf("[VNF] RC.eNB[0][0]. Mod_id:%d CC_id:%d nb_CC[0]:%d abstraction_flag:%d single_thread_flag:%d if_inst:%p\n", eNB->Mod_id, eNB->CC_id, RC.nb_CC[0], eNB->abstraction_flag, eNB->single_thread_flag, eNB->if_inst); - + printf("[VNF] RC.eNB[0][0]. Mod_id:%d CC_id:%d nb_CC[0]:%d abstraction_flag:%d single_thread_flag:%d if_inst:%p\n", eNB->Mod_id, eNB->CC_id, RC.nb_CC[0], eNB->abstraction_flag, + eNB->single_thread_flag, eNB->if_inst); eNB->Mod_id = bodge_counter; eNB->CC_id = bodge_counter; eNB->abstraction_flag = 0; eNB->single_thread_flag = 0;//single_thread_flag; - RC.nb_CC[bodge_counter] = 1; if (eNB->if_inst==0) { @@ -213,7 +213,6 @@ void oai_create_enb(void) { // that will result in eNB->configured being set to TRUE. // See we need to wait for that to happen otherwise the NFAPI message exchanges won't contain the right parameter values if (RC.eNB[0][0]->if_inst==0 || RC.eNB[0][0]->if_inst->PHY_config_req==0 || RC.eNB[0][0]->if_inst->schedule_response==0) { - printf("RC.eNB[0][0]->if_inst->PHY_config_req is not installed - install it\n"); install_schedule_handlers(RC.eNB[0][0]->if_inst); } @@ -227,17 +226,13 @@ void oai_create_enb(void) { } void oai_enb_init(void) { - printf("%s() About to call init_eNB_afterRU()\n", __FUNCTION__); init_eNB_afterRU(); } -int pnf_connection_indication_cb(nfapi_vnf_config_t* config, int p5_idx) { - +int pnf_connection_indication_cb(nfapi_vnf_config_t *config, int p5_idx) { printf("[VNF] pnf connection indication idx:%d\n", p5_idx); - oai_create_enb(); - nfapi_pnf_param_request_t req; memset(&req, 0, sizeof(req)); req.header.message_id = NFAPI_PNF_PARAM_REQUEST; @@ -245,40 +240,29 @@ int pnf_connection_indication_cb(nfapi_vnf_config_t* config, int p5_idx) { return 0; } -int pnf_disconnection_indication_cb(nfapi_vnf_config_t* config, int p5_idx) { +int pnf_disconnection_indication_cb(nfapi_vnf_config_t *config, int p5_idx) { printf("[VNF] pnf disconnection indication idx:%d\n", p5_idx); - - vnf_info* vnf = (vnf_info*)(config->user_data); - + vnf_info *vnf = (vnf_info *)(config->user_data); pnf_info *pnf = vnf->pnfs; phy_info *phy = pnf->phys; - - vnf_p7_info* p7_vnf = vnf->p7_vnfs; + vnf_p7_info *p7_vnf = vnf->p7_vnfs; nfapi_vnf_p7_del_pnf((p7_vnf->config), phy->id); - return 0; } -int pnf_param_resp_cb(nfapi_vnf_config_t* config, int p5_idx, nfapi_pnf_param_response_t* resp) { - +int pnf_param_resp_cb(nfapi_vnf_config_t *config, int p5_idx, nfapi_pnf_param_response_t *resp) { printf("[VNF] pnf param response idx:%d error:%d\n", p5_idx, resp->error_code); - - vnf_info* vnf = (vnf_info*)(config->user_data); - + vnf_info *vnf = (vnf_info *)(config->user_data); pnf_info *pnf = vnf->pnfs; - for(int i = 0; i < resp->pnf_phy.number_of_phys; ++i) - { + for(int i = 0; i < resp->pnf_phy.number_of_phys; ++i) { phy_info phy; memset(&phy,0,sizeof(phy)); phy.index = resp->pnf_phy.phy[i].phy_config_index; - printf("[VNF] (PHY:%d) phy_config_idx:%d\n", i, resp->pnf_phy.phy[i].phy_config_index); - nfapi_vnf_allocate_phy(config, p5_idx, &(phy.id)); - for(int j = 0; j < resp->pnf_phy.phy[i].number_of_rfs; ++j) - { + for(int j = 0; j < resp->pnf_phy.phy[i].number_of_rfs; ++j) { printf("[VNF] (PHY:%d) (RF%d) %d\n", i, j, resp->pnf_phy.phy[i].rf_config[j].rf_config_index); phy.rfs[0] = resp->pnf_phy.phy[i].rf_config[j].rf_config_index; } @@ -290,16 +274,13 @@ int pnf_param_resp_cb(nfapi_vnf_config_t* config, int p5_idx, nfapi_pnf_param_re rf_info rf; memset(&rf,0,sizeof(rf)); rf.index = resp->pnf_rf.rf[i].rf_config_index; - printf("[VNF] (RF:%d) rf_config_idx:%d\n", i, resp->pnf_rf.rf[i].rf_config_index); - pnf->rfs[0] = rf; } nfapi_pnf_config_request_t req; memset(&req, 0, sizeof(req)); req.header.message_id = NFAPI_PNF_CONFIG_REQUEST; - req.pnf_phy_rf_config.tl.tag = NFAPI_PNF_PHY_RF_TAG; req.pnf_phy_rf_config.number_phy_rf_config_info = 2; // DJP pnf.phys.size(); printf("DJP:Hard coded num phy rf to 2\n"); @@ -311,25 +292,22 @@ int pnf_param_resp_cb(nfapi_vnf_config_t* config, int p5_idx, nfapi_pnf_param_re } nfapi_vnf_pnf_config_req(config, p5_idx, &req); - return 0; } -int pnf_config_resp_cb(nfapi_vnf_config_t* config, int p5_idx, nfapi_pnf_config_response_t* resp) { - +int pnf_config_resp_cb(nfapi_vnf_config_t *config, int p5_idx, nfapi_pnf_config_response_t *resp) { printf("[VNF] pnf config response idx:%d resp[header[phy_id:%u message_id:%02x message_length:%u]]\n", p5_idx, resp->header.phy_id, resp->header.message_id, resp->header.message_length); if(1) { - nfapi_pnf_start_request_t req; - memset(&req, 0, sizeof(req)); - req.header.phy_id = resp->header.phy_id; - req.header.message_id = NFAPI_PNF_START_REQUEST; - nfapi_vnf_pnf_start_req(config, p5_idx, &req); + nfapi_pnf_start_request_t req; + memset(&req, 0, sizeof(req)); + req.header.phy_id = resp->header.phy_id; + req.header.message_id = NFAPI_PNF_START_REQUEST; + nfapi_vnf_pnf_start_req(config, p5_idx, &req); } else { // Rather than send the pnf_start_request we will demonstrate // sending a vendor extention message. The start request will be - // send when the vendor extension response is received - + // send when the vendor extension response is received //vnf_info* vnf = (vnf_info*)(config->user_data); vendor_ext_p5_req req; memset(&req, 0, sizeof(req)); @@ -338,22 +316,17 @@ int pnf_config_resp_cb(nfapi_vnf_config_t* config, int p5_idx, nfapi_pnf_config_ req.dummy2 = 1977; nfapi_vnf_vendor_extension(config, p5_idx, &req.header); } + return 0; } int wake_eNB_rxtx(PHY_VARS_eNB *eNB, uint16_t sfn, uint16_t sf) { - L1_proc_t *proc=&eNB->proc; - L1_rxtx_proc_t *L1_proc= (sf&1)? &proc->L1_proc : &proc->L1_proc_tx; - LTE_DL_FRAME_PARMS *fp = &eNB->frame_parms; - //printf("%s(eNB:%p, sfn:%d, sf:%d)\n", __FUNCTION__, eNB, sfn, sf); - //int i; struct timespec wait; - wait.tv_sec=0; wait.tv_nsec=5000000L; @@ -368,10 +341,8 @@ int wake_eNB_rxtx(PHY_VARS_eNB *eNB, uint16_t sfn, uint16_t sf) { { static uint16_t old_sf = 0; static uint16_t old_sfn = 0; - proc->subframe_rx = old_sf; proc->frame_rx = old_sfn; - // Try to be 1 frame back old_sf = sf; old_sfn = sfn; @@ -380,9 +351,7 @@ int wake_eNB_rxtx(PHY_VARS_eNB *eNB, uint16_t sfn, uint16_t sf) { } ++L1_proc->instance_cnt; - //LOG_D( PHY,"[VNF-subframe_ind] sfn/sf:%d:%d proc[frame_rx:%d subframe_rx:%d] L1_proc->instance_cnt_rxtx:%d \n", sfn, sf, proc->frame_rx, proc->subframe_rx, L1_proc->instance_cnt_rxtx); - // We have just received and processed the common part of a subframe, say n. // TS_rx is the last received timestamp (start of 1st slot), TS_tx is the desired // transmitted timestamp of the next TX slot (first). @@ -407,7 +376,6 @@ int wake_eNB_rxtx(PHY_VARS_eNB *eNB, uint16_t sfn, uint16_t sf) { //LOG_D(PHY,"%s() About to attempt pthread_mutex_unlock\n", __FUNCTION__); pthread_mutex_unlock( &L1_proc->mutex ); //LOG_D(PHY,"%s() UNLOCKED pthread_mutex_unlock\n", __FUNCTION__); - return(0); } @@ -415,12 +383,10 @@ extern pthread_cond_t nfapi_sync_cond; extern pthread_mutex_t nfapi_sync_mutex; extern int nfapi_sync_var; -int phy_sync_indication(struct nfapi_vnf_p7_config* config, uint8_t sync) { - +int phy_sync_indication(struct nfapi_vnf_p7_config *config, uint8_t sync) { printf("[VNF] SYNC %s\n", sync==1 ? "ACHIEVED" : "LOST"); - - if (sync==1 && nfapi_sync_var!=0) { + if (sync==1 && nfapi_sync_var!=0) { printf("[VNF] Signal to OAI main code that it can go\n"); pthread_mutex_lock(&nfapi_sync_mutex); nfapi_sync_var=0; @@ -431,9 +397,9 @@ int phy_sync_indication(struct nfapi_vnf_p7_config* config, uint8_t sync) { return(0); } -int phy_subframe_indication(struct nfapi_vnf_p7_config* config, uint16_t phy_id, uint16_t sfn_sf) { - +int phy_subframe_indication(struct nfapi_vnf_p7_config *config, uint16_t phy_id, uint16_t sfn_sf) { static uint8_t first_time = 1; + if (first_time) { printf("[VNF] subframe indication %d\n", NFAPI_SFNSF2DEC(sfn_sf)); first_time = 0; @@ -442,40 +408,33 @@ int phy_subframe_indication(struct nfapi_vnf_p7_config* config, uint16_t phy_id, if (RC.eNB && RC.eNB[0][0]->configured) { uint16_t sfn = NFAPI_SFNSF2SFN(sfn_sf); uint16_t sf = NFAPI_SFNSF2SF(sfn_sf); - //LOG_D(PHY,"[VNF] subframe indication sfn_sf:%d sfn:%d sf:%d\n", sfn_sf, sfn, sf); - wake_eNB_rxtx(RC.eNB[0][0], sfn, sf); } else { printf("[VNF] %s() RC.eNB:%p\n", __FUNCTION__, RC.eNB); + if (RC.eNB) printf("RC.eNB[0][0]->configured:%d\n", RC.eNB[0][0]->configured); } return 0; } -int phy_rach_indication(struct nfapi_vnf_p7_config* config, nfapi_rach_indication_t* ind) { - +int phy_rach_indication(struct nfapi_vnf_p7_config *config, nfapi_rach_indication_t *ind) { LOG_D(MAC, "%s() NFAPI SFN/SF:%d number_of_preambles:%u\n", __FUNCTION__, NFAPI_SFNSF2DEC(ind->sfn_sf), ind->rach_indication_body.number_of_preambles); - struct PHY_VARS_eNB_s *eNB = RC.eNB[0][0]; - printf("[VNF] RACH_IND eNB:%p sfn_sf:%d number_of_preambles:%d\n", eNB, NFAPI_SFNSF2DEC(ind->sfn_sf), ind->rach_indication_body.number_of_preambles); - pthread_mutex_lock(&eNB->UL_INFO_mutex); - eNB->UL_INFO.rach_ind = *ind; eNB->UL_INFO.rach_ind.rach_indication_body.preamble_list = eNB->preamble_list; - for (int i=0;i<ind->rach_indication_body.number_of_preambles;i++) { + for (int i=0; i<ind->rach_indication_body.number_of_preambles; i++) { if (ind->rach_indication_body.preamble_list[i].preamble_rel8.tl.tag == NFAPI_PREAMBLE_REL8_TAG) { - - printf("preamble[%d]: rnti:%02x preamble:%d timing_advance:%d\n", - i, - ind->rach_indication_body.preamble_list[i].preamble_rel8.rnti, - ind->rach_indication_body.preamble_list[i].preamble_rel8.preamble, - ind->rach_indication_body.preamble_list[i].preamble_rel8.timing_advance - ); + printf("preamble[%d]: rnti:%02x preamble:%d timing_advance:%d\n", + i, + ind->rach_indication_body.preamble_list[i].preamble_rel8.rnti, + ind->rach_indication_body.preamble_list[i].preamble_rel8.preamble, + ind->rach_indication_body.preamble_list[i].preamble_rel8.timing_advance + ); } if(ind->rach_indication_body.preamble_list[i].preamble_rel13.tl.tag == NFAPI_PREAMBLE_REL13_TAG) { @@ -484,21 +443,17 @@ int phy_rach_indication(struct nfapi_vnf_p7_config* config, nfapi_rach_indicatio eNB->preamble_list[i] = ind->rach_indication_body.preamble_list[i]; } - pthread_mutex_unlock(&eNB->UL_INFO_mutex); + pthread_mutex_unlock(&eNB->UL_INFO_mutex); // vnf_p7_info* p7_vnf = (vnf_p7_info*)(config->user_data); //mac_rach_ind(p7_vnf->mac, ind); return 1; } -int phy_harq_indication(struct nfapi_vnf_p7_config* config, nfapi_harq_indication_t* ind) { - +int phy_harq_indication(struct nfapi_vnf_p7_config *config, nfapi_harq_indication_t *ind) { struct PHY_VARS_eNB_s *eNB = RC.eNB[0][0]; - LOG_D(MAC, "%s() NFAPI SFN/SF:%d number_of_harqs:%u\n", __FUNCTION__, NFAPI_SFNSF2DEC(ind->sfn_sf), ind->harq_indication_body.number_of_harqs); - pthread_mutex_lock(&eNB->UL_INFO_mutex); - eNB->UL_INFO.harq_ind = *ind; eNB->UL_INFO.harq_ind.harq_indication_body.harq_pdu_list = eNB->harq_pdu_list; @@ -507,51 +462,41 @@ int phy_harq_indication(struct nfapi_vnf_p7_config* config, nfapi_harq_indicatio } pthread_mutex_unlock(&eNB->UL_INFO_mutex); - // vnf_p7_info* p7_vnf = (vnf_p7_info*)(config->user_data); //mac_harq_ind(p7_vnf->mac, ind); - return 1; } -int phy_crc_indication(struct nfapi_vnf_p7_config* config, nfapi_crc_indication_t* ind) { - +int phy_crc_indication(struct nfapi_vnf_p7_config *config, nfapi_crc_indication_t *ind) { struct PHY_VARS_eNB_s *eNB = RC.eNB[0][0]; - pthread_mutex_lock(&eNB->UL_INFO_mutex); - eNB->UL_INFO.crc_ind = *ind; - nfapi_crc_indication_t *dest_ind = &eNB->UL_INFO.crc_ind; nfapi_crc_indication_pdu_t *dest_pdu_list = eNB->crc_pdu_list; - *dest_ind = *ind; dest_ind->crc_indication_body.crc_pdu_list = dest_pdu_list; if (ind->crc_indication_body.number_of_crcs==0) - LOG_D(MAC, "%s() NFAPI SFN/SF:%d IND:number_of_crcs:%u UL_INFO:crcs:%d\n", __FUNCTION__, NFAPI_SFNSF2DEC(ind->sfn_sf), ind->crc_indication_body.number_of_crcs, eNB->UL_INFO.crc_ind.crc_indication_body.number_of_crcs); + LOG_D(MAC, "%s() NFAPI SFN/SF:%d IND:number_of_crcs:%u UL_INFO:crcs:%d\n", __FUNCTION__, NFAPI_SFNSF2DEC(ind->sfn_sf), ind->crc_indication_body.number_of_crcs, + eNB->UL_INFO.crc_ind.crc_indication_body.number_of_crcs); for (int i=0; i<ind->crc_indication_body.number_of_crcs; i++) { memcpy(&dest_ind->crc_indication_body.crc_pdu_list[i], &ind->crc_indication_body.crc_pdu_list[i], sizeof(ind->crc_indication_body.crc_pdu_list[0])); - - LOG_D(MAC, "%s() NFAPI SFN/SF:%d CRC_IND:number_of_crcs:%u UL_INFO:crcs:%d PDU[%d] rnti:%04x UL_INFO:rnti:%04x\n", - __FUNCTION__, - NFAPI_SFNSF2DEC(ind->sfn_sf), ind->crc_indication_body.number_of_crcs, eNB->UL_INFO.crc_ind.crc_indication_body.number_of_crcs, - i, - ind->crc_indication_body.crc_pdu_list[i].rx_ue_information.rnti, - eNB->UL_INFO.crc_ind.crc_indication_body.crc_pdu_list[i].rx_ue_information.rnti); + LOG_D(MAC, "%s() NFAPI SFN/SF:%d CRC_IND:number_of_crcs:%u UL_INFO:crcs:%d PDU[%d] rnti:%04x UL_INFO:rnti:%04x\n", + __FUNCTION__, + NFAPI_SFNSF2DEC(ind->sfn_sf), ind->crc_indication_body.number_of_crcs, eNB->UL_INFO.crc_ind.crc_indication_body.number_of_crcs, + i, + ind->crc_indication_body.crc_pdu_list[i].rx_ue_information.rnti, + eNB->UL_INFO.crc_ind.crc_indication_body.crc_pdu_list[i].rx_ue_information.rnti); } pthread_mutex_unlock(&eNB->UL_INFO_mutex); - // vnf_p7_info* p7_vnf = (vnf_p7_info*)(config->user_data); //mac_crc_ind(p7_vnf->mac, ind); - return 1; } -int phy_rx_indication(struct nfapi_vnf_p7_config* config, nfapi_rx_indication_t* ind) { - +int phy_rx_indication(struct nfapi_vnf_p7_config *config, nfapi_rx_indication_t *ind) { struct PHY_VARS_eNB_s *eNB = RC.eNB[0][0]; if (ind->rx_indication_body.number_of_pdus==0) { @@ -559,198 +504,170 @@ int phy_rx_indication(struct nfapi_vnf_p7_config* config, nfapi_rx_indication_t* } pthread_mutex_lock(&eNB->UL_INFO_mutex); - nfapi_rx_indication_t *dest_ind = &eNB->UL_INFO.rx_ind; nfapi_rx_indication_pdu_t *dest_pdu_list = eNB->rx_pdu_list; - *dest_ind = *ind; dest_ind->rx_indication_body.rx_pdu_list = dest_pdu_list; for(int i=0; i<ind->rx_indication_body.number_of_pdus; i++) { nfapi_rx_indication_pdu_t *dest_pdu = &dest_ind->rx_indication_body.rx_pdu_list[i]; nfapi_rx_indication_pdu_t *src_pdu = &ind->rx_indication_body.rx_pdu_list[i]; - memcpy(dest_pdu, src_pdu, sizeof(*src_pdu)); - // DJP - TODO FIXME - intentional memory leak dest_pdu->data = malloc(dest_pdu->rx_indication_rel8.length); - memcpy(dest_pdu->data, src_pdu->data, dest_pdu->rx_indication_rel8.length); - LOG_D(PHY, "%s() NFAPI SFN/SF:%d PDUs:%d [PDU:%d] handle:%d rnti:%04x length:%d offset:%d ul_cqi:%d ta:%d data:%p\n", - __FUNCTION__, - NFAPI_SFNSF2DEC(ind->sfn_sf), ind->rx_indication_body.number_of_pdus, i, - dest_pdu->rx_ue_information.handle, - dest_pdu->rx_ue_information.rnti, - dest_pdu->rx_indication_rel8.length, - dest_pdu->rx_indication_rel8.offset, - dest_pdu->rx_indication_rel8.ul_cqi, - dest_pdu->rx_indication_rel8.timing_advance, - dest_pdu->data - ); + __FUNCTION__, + NFAPI_SFNSF2DEC(ind->sfn_sf), ind->rx_indication_body.number_of_pdus, i, + dest_pdu->rx_ue_information.handle, + dest_pdu->rx_ue_information.rnti, + dest_pdu->rx_indication_rel8.length, + dest_pdu->rx_indication_rel8.offset, + dest_pdu->rx_indication_rel8.ul_cqi, + dest_pdu->rx_indication_rel8.timing_advance, + dest_pdu->data + ); } pthread_mutex_unlock(&eNB->UL_INFO_mutex); - // vnf_p7_info* p7_vnf = (vnf_p7_info*)(config->user_data); //mac_rx_ind(p7_vnf->mac, ind); return 1; } -int phy_srs_indication(struct nfapi_vnf_p7_config* config, nfapi_srs_indication_t* ind) { +int phy_srs_indication(struct nfapi_vnf_p7_config *config, nfapi_srs_indication_t *ind) { // vnf_p7_info* p7_vnf = (vnf_p7_info*)(config->user_data); //mac_srs_ind(p7_vnf->mac, ind); return 1; } -int phy_sr_indication(struct nfapi_vnf_p7_config* config, nfapi_sr_indication_t* ind) { - +int phy_sr_indication(struct nfapi_vnf_p7_config *config, nfapi_sr_indication_t *ind) { struct PHY_VARS_eNB_s *eNB = RC.eNB[0][0]; - LOG_D(MAC, "%s() NFAPI SFN/SF:%d srs:%d\n", __FUNCTION__, NFAPI_SFNSF2DEC(ind->sfn_sf), ind->sr_indication_body.number_of_srs); - pthread_mutex_lock(&eNB->UL_INFO_mutex); - nfapi_sr_indication_t *dest_ind = &eNB->UL_INFO.sr_ind; nfapi_sr_indication_pdu_t *dest_pdu_list = eNB->sr_pdu_list; - *dest_ind = *ind; dest_ind->sr_indication_body.sr_pdu_list = dest_pdu_list; - LOG_D(MAC,"%s() eNB->UL_INFO.sr_ind.sr_indication_body.number_of_srs:%d\n", __FUNCTION__, eNB->UL_INFO.sr_ind.sr_indication_body.number_of_srs); - for (int i=0;i<eNB->UL_INFO.sr_ind.sr_indication_body.number_of_srs;i++) { + for (int i=0; i<eNB->UL_INFO.sr_ind.sr_indication_body.number_of_srs; i++) { nfapi_sr_indication_pdu_t *dest_pdu = &dest_ind->sr_indication_body.sr_pdu_list[i]; nfapi_sr_indication_pdu_t *src_pdu = &ind->sr_indication_body.sr_pdu_list[i]; - LOG_D(MAC, "SR_IND[PDU:%d][rnti:%x cqi:%d channel:%d]\n", i, src_pdu->rx_ue_information.rnti, src_pdu->ul_cqi_information.ul_cqi, src_pdu->ul_cqi_information.channel); - memcpy(dest_pdu, src_pdu, sizeof(*src_pdu)); } pthread_mutex_unlock(&eNB->UL_INFO_mutex); - // vnf_p7_info* p7_vnf = (vnf_p7_info*)(config->user_data); //mac_sr_ind(p7_vnf->mac, ind); - return 1; } -int phy_cqi_indication(struct nfapi_vnf_p7_config* config, nfapi_cqi_indication_t* ind) { - +int phy_cqi_indication(struct nfapi_vnf_p7_config *config, nfapi_cqi_indication_t *ind) { // vnf_p7_info* p7_vnf = (vnf_p7_info*)(config->user_data); //mac_cqi_ind(p7_vnf->mac, ind); struct PHY_VARS_eNB_s *eNB = RC.eNB[0][0]; - LOG_D(MAC, "%s() NFAPI SFN/SF:%d number_of_cqis:%u\n", __FUNCTION__, NFAPI_SFNSF2DEC(ind->sfn_sf), ind->cqi_indication_body.number_of_cqis); - pthread_mutex_lock(&eNB->UL_INFO_mutex); - eNB->UL_INFO.cqi_ind = ind->cqi_indication_body; - pthread_mutex_unlock(&eNB->UL_INFO_mutex); - return 1; } -int phy_lbt_dl_indication(struct nfapi_vnf_p7_config* config, nfapi_lbt_dl_indication_t* ind) { +int phy_lbt_dl_indication(struct nfapi_vnf_p7_config *config, nfapi_lbt_dl_indication_t *ind) { // vnf_p7_info* p7_vnf = (vnf_p7_info*)(config->user_data); //mac_lbt_dl_ind(p7_vnf->mac, ind); return 1; } -int phy_nb_harq_indication(struct nfapi_vnf_p7_config* config, nfapi_nb_harq_indication_t* ind) { +int phy_nb_harq_indication(struct nfapi_vnf_p7_config *config, nfapi_nb_harq_indication_t *ind) { // vnf_p7_info* p7_vnf = (vnf_p7_info*)(config->user_data); //mac_nb_harq_ind(p7_vnf->mac, ind); return 1; } -int phy_nrach_indication(struct nfapi_vnf_p7_config* config, nfapi_nrach_indication_t* ind) { +int phy_nrach_indication(struct nfapi_vnf_p7_config *config, nfapi_nrach_indication_t *ind) { // vnf_p7_info* p7_vnf = (vnf_p7_info*)(config->user_data); //mac_nrach_ind(p7_vnf->mac, ind); return 1; } -void* vnf_allocate(size_t size) { +void *vnf_allocate(size_t size) { //return (void*)memory_pool::allocate(size); - return (void*)malloc(size); + return (void *)malloc(size); } -void vnf_deallocate(void* ptr) { +void vnf_deallocate(void *ptr) { //memory_pool::deallocate((uint8_t*)ptr); free(ptr); } -void vnf_trace(nfapi_trace_level_t nfapi_level, const char* message, ...) { - +void vnf_trace(nfapi_trace_level_t nfapi_level, const char *message, ...) { va_list args; - va_start(args, message); nfapi_log("FILE>", "FUNC", 999, PHY, nfapitooai_level(nfapi_level), message, args); va_end(args); } -int phy_vendor_ext(struct nfapi_vnf_p7_config* config, nfapi_p7_message_header_t* msg) { - - if(msg->message_id == P7_VENDOR_EXT_IND) - { +int phy_vendor_ext(struct nfapi_vnf_p7_config *config, nfapi_p7_message_header_t *msg) { + if(msg->message_id == P7_VENDOR_EXT_IND) { //vendor_ext_p7_ind* ind = (vendor_ext_p7_ind*)msg; //printf("[VNF] vendor_ext (error_code:%d)\n", ind->error_code); - } - else - { + } else { printf("[VNF] unknown %02x\n", msg->message_id); } + return 0; } -nfapi_p7_message_header_t* phy_allocate_p7_vendor_ext(uint16_t message_id, uint16_t* msg_size) { - if(message_id == P7_VENDOR_EXT_IND) - { +nfapi_p7_message_header_t *phy_allocate_p7_vendor_ext(uint16_t message_id, uint16_t *msg_size) { + if(message_id == P7_VENDOR_EXT_IND) { *msg_size = sizeof(vendor_ext_p7_ind); - return (nfapi_p7_message_header_t*)malloc(sizeof(vendor_ext_p7_ind)); + return (nfapi_p7_message_header_t *)malloc(sizeof(vendor_ext_p7_ind)); } + return 0; } -void phy_deallocate_p7_vendor_ext(nfapi_p7_message_header_t* header) { +void phy_deallocate_p7_vendor_ext(nfapi_p7_message_header_t *header) { free(header); } -int phy_unpack_vendor_extension_tlv(nfapi_tl_t* tl, uint8_t **ppReadPackedMessage, uint8_t *end, void** ve, nfapi_p7_codec_config_t* codec) { - +int phy_unpack_vendor_extension_tlv(nfapi_tl_t *tl, uint8_t **ppReadPackedMessage, uint8_t *end, void **ve, nfapi_p7_codec_config_t *codec) { (void)tl; (void)ppReadPackedMessage; (void)ve; return -1; } -int phy_pack_vendor_extension_tlv(void* ve, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p7_codec_config_t* codec) { - +int phy_pack_vendor_extension_tlv(void *ve, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p7_codec_config_t *codec) { //NFAPI_TRACE(NFAPI_TRACE_INFO, "phy_pack_vendor_extension_tlv\n"); + nfapi_tl_t *tlv = (nfapi_tl_t *)ve; - nfapi_tl_t* tlv = (nfapi_tl_t*)ve; switch(tlv->tag) { - case VENDOR_EXT_TLV_1_TAG: - { - //NFAPI_TRACE(NFAPI_TRACE_INFO, "Packing VENDOR_EXT_TLV_1\n"); - vendor_ext_tlv_1* ve = (vendor_ext_tlv_1*)tlv; - if(!push32(ve->dummy, ppWritePackedMsg, end)) - return 0; - return 1; - } - break; + case VENDOR_EXT_TLV_1_TAG: { + //NFAPI_TRACE(NFAPI_TRACE_INFO, "Packing VENDOR_EXT_TLV_1\n"); + vendor_ext_tlv_1 *ve = (vendor_ext_tlv_1 *)tlv; + + if(!push32(ve->dummy, ppWritePackedMsg, end)) + return 0; + + return 1; + } + break; + default: return -1; break; } } -int phy_unpack_p7_vendor_extension(nfapi_p7_message_header_t* header, uint8_t** ppReadPackedMessage, uint8_t *end, nfapi_p7_codec_config_t* config) { - +int phy_unpack_p7_vendor_extension(nfapi_p7_message_header_t *header, uint8_t **ppReadPackedMessage, uint8_t *end, nfapi_p7_codec_config_t *config) { //NFAPI_TRACE(NFAPI_TRACE_INFO, "%s\n", __FUNCTION__); if(header->message_id == P7_VENDOR_EXT_IND) { - vendor_ext_p7_ind* req = (vendor_ext_p7_ind*)(header); + vendor_ext_p7_ind *req = (vendor_ext_p7_ind *)(header); + if(!pull16(ppReadPackedMessage, &req->error_code, end)) return 0; } @@ -758,54 +675,48 @@ int phy_unpack_p7_vendor_extension(nfapi_p7_message_header_t* header, uint8_t** return 1; } -int phy_pack_p7_vendor_extension(nfapi_p7_message_header_t* header, uint8_t** ppWritePackedMsg, uint8_t *end, nfapi_p7_codec_config_t* config) { +int phy_pack_p7_vendor_extension(nfapi_p7_message_header_t *header, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p7_codec_config_t *config) { //NFAPI_TRACE(NFAPI_TRACE_INFO, "%s\n", __FUNCTION__); if(header->message_id == P7_VENDOR_EXT_REQ) { //NFAPI_TRACE(NFAPI_TRACE_INFO, "%s\n", __FUNCTION__); - vendor_ext_p7_req* req = (vendor_ext_p7_req*)(header); + vendor_ext_p7_req *req = (vendor_ext_p7_req *)(header); + if(!(push16(req->dummy1, ppWritePackedMsg, end) && - push16(req->dummy2, ppWritePackedMsg, end))) + push16(req->dummy2, ppWritePackedMsg, end))) return 0; } + return 1; } -int vnf_pack_p4_p5_vendor_extension(nfapi_p4_p5_message_header_t* header, uint8_t** ppWritePackedMsg, uint8_t *end, nfapi_p4_p5_codec_config_t* codec) { - +int vnf_pack_p4_p5_vendor_extension(nfapi_p4_p5_message_header_t *header, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p4_p5_codec_config_t *codec) { //NFAPI_TRACE(NFAPI_TRACE_INFO, "%s\n", __FUNCTION__); if(header->message_id == P5_VENDOR_EXT_REQ) { - vendor_ext_p5_req* req = (vendor_ext_p5_req*)(header); + vendor_ext_p5_req *req = (vendor_ext_p5_req *)(header); //NFAPI_TRACE(NFAPI_TRACE_INFO, "%s %d %d\n", __FUNCTION__, req->dummy1, req->dummy2); return (!(push16(req->dummy1, ppWritePackedMsg, end) && - push16(req->dummy2, ppWritePackedMsg, end))); + push16(req->dummy2, ppWritePackedMsg, end))); } + return 0; } static pthread_t vnf_start_pthread; static pthread_t vnf_p7_start_pthread; -void* vnf_p7_start_thread(void *ptr) { - +void *vnf_p7_start_thread(void *ptr) { printf("%s()\n", __FUNCTION__); - pthread_setname_np(pthread_self(), "VNF_P7"); - - nfapi_vnf_p7_config_t* config = (nfapi_vnf_p7_config_t*)ptr; - + nfapi_vnf_p7_config_t *config = (nfapi_vnf_p7_config_t *)ptr; nfapi_vnf_p7_start(config); - return config; } void set_thread_priority(int priority); -void* vnf_p7_thread_start(void* ptr) { - +void *vnf_p7_thread_start(void *ptr) { set_thread_priority(79); - - vnf_p7_info* p7_vnf = (vnf_p7_info*)ptr; - + vnf_p7_info *p7_vnf = (vnf_p7_info *)ptr; p7_vnf->config->port = p7_vnf->local_port; p7_vnf->config->sync_indication = &phy_sync_indication; p7_vnf->config->subframe_indication = &phy_subframe_indication; @@ -821,117 +732,87 @@ void* vnf_p7_thread_start(void* ptr) { p7_vnf->config->nrach_indication = &phy_nrach_indication; p7_vnf->config->malloc = &vnf_allocate; p7_vnf->config->free = &vnf_deallocate; - p7_vnf->config->trace = &vnf_trace; - p7_vnf->config->vendor_ext = &phy_vendor_ext; p7_vnf->config->user_data = p7_vnf; - p7_vnf->mac->user_data = p7_vnf; - p7_vnf->config->codec_config.unpack_p7_vendor_extension = &phy_unpack_p7_vendor_extension; p7_vnf->config->codec_config.pack_p7_vendor_extension = &phy_pack_p7_vendor_extension; p7_vnf->config->codec_config.unpack_vendor_extension_tlv = &phy_unpack_vendor_extension_tlv; p7_vnf->config->codec_config.pack_vendor_extension_tlv = &phy_pack_vendor_extension_tlv; p7_vnf->config->codec_config.allocate = &vnf_allocate; p7_vnf->config->codec_config.deallocate = &vnf_deallocate; - p7_vnf->config->allocate_p7_vendor_ext = &phy_allocate_p7_vendor_ext; p7_vnf->config->deallocate_p7_vendor_ext = &phy_deallocate_p7_vendor_ext; - NFAPI_TRACE(NFAPI_TRACE_INFO, "[VNF] Creating VNF NFAPI start thread %s\n", __FUNCTION__); pthread_create(&vnf_p7_start_pthread, NULL, &vnf_p7_start_thread, p7_vnf->config); - return 0; } -int pnf_start_resp_cb(nfapi_vnf_config_t* config, int p5_idx, nfapi_pnf_start_response_t* resp) { - - vnf_info* vnf = (vnf_info*)(config->user_data); +int pnf_start_resp_cb(nfapi_vnf_config_t *config, int p5_idx, nfapi_pnf_start_response_t *resp) { + vnf_info *vnf = (vnf_info *)(config->user_data); vnf_p7_info *p7_vnf = vnf->p7_vnfs; pnf_info *pnf = vnf->pnfs; nfapi_param_request_t req; - printf("[VNF] pnf start response idx:%d config:%p user_data:%p p7_vnf[config:%p thread_started:%d]\n", p5_idx, config, config->user_data, vnf->p7_vnfs[0].config, vnf->p7_vnfs[0].thread_started); if(p7_vnf->thread_started == 0) { - pthread_t vnf_p7_thread; pthread_create(&vnf_p7_thread, NULL, &vnf_p7_thread_start, p7_vnf); p7_vnf->thread_started = 1; - } - else - { - // P7 thread already running. + } else { + // P7 thread already running. } // start all the phys in the pnf. printf("[VNF] Sending NFAPI_PARAM_REQUEST phy_id:%d\n", pnf->phys[0].id); - memset(&req, 0, sizeof(req)); req.header.message_id = NFAPI_PARAM_REQUEST; req.header.phy_id = pnf->phys[0].id; - nfapi_vnf_param_req(config, p5_idx, &req); - return 0; } extern uint32_t to_earfcn(int eutra_bandP,uint32_t dl_CarrierFreq,uint32_t bw); -int param_resp_cb(nfapi_vnf_config_t* config, int p5_idx, nfapi_param_response_t* resp) { - +int param_resp_cb(nfapi_vnf_config_t *config, int p5_idx, nfapi_param_response_t *resp) { printf("[VNF] Received NFAPI_PARAM_RESP idx:%d phy_id:%d\n", p5_idx, resp->header.phy_id); - - vnf_info* vnf = (vnf_info*)(config->user_data); + vnf_info *vnf = (vnf_info *)(config->user_data); vnf_p7_info *p7_vnf = vnf->p7_vnfs; - pnf_info *pnf = vnf->pnfs; phy_info *phy = pnf->phys; struct sockaddr_in pnf_p7_sockaddr; nfapi_config_request_t *req = &RC.mac[0]->config[0]; - phy->remote_port = resp->nfapi_config.p7_pnf_port.value; - memcpy(&pnf_p7_sockaddr.sin_addr.s_addr, &(resp->nfapi_config.p7_pnf_address_ipv4.address[0]), 4); - phy->remote_addr = inet_ntoa(pnf_p7_sockaddr.sin_addr); - // for now just 1 - - printf("[VNF] %d.%d pnf p7 %s:%d timing %u %u %u %u\n", p5_idx, phy->id, phy->remote_addr, phy->remote_port, p7_vnf->timing_window, p7_vnf->periodic_timing_period, p7_vnf->aperiodic_timing_enabled, p7_vnf->periodic_timing_period); - + printf("[VNF] %d.%d pnf p7 %s:%d timing %u %u %u %u\n", p5_idx, phy->id, phy->remote_addr, phy->remote_port, p7_vnf->timing_window, p7_vnf->periodic_timing_period, p7_vnf->aperiodic_timing_enabled, + p7_vnf->periodic_timing_period); req->header.message_id = NFAPI_CONFIG_REQUEST; req->header.phy_id = phy->id; - printf("[VNF] Send NFAPI_CONFIG_REQUEST\n"); - req->nfapi_config.p7_vnf_port.tl.tag = NFAPI_NFAPI_P7_VNF_PORT_TAG; req->nfapi_config.p7_vnf_port.value = p7_vnf->local_port; req->num_tlv++; - printf("[VNF] DJP local_port:%d\n", p7_vnf->local_port); - req->nfapi_config.p7_vnf_address_ipv4.tl.tag = NFAPI_NFAPI_P7_VNF_ADDRESS_IPV4_TAG; struct sockaddr_in vnf_p7_sockaddr; vnf_p7_sockaddr.sin_addr.s_addr = inet_addr(p7_vnf->local_addr); memcpy(&(req->nfapi_config.p7_vnf_address_ipv4.address[0]), &vnf_p7_sockaddr.sin_addr.s_addr, 4); req->num_tlv++; printf("[VNF] DJP local_addr:%s\n", p7_vnf->local_addr); - req->nfapi_config.timing_window.tl.tag = NFAPI_NFAPI_TIMING_WINDOW_TAG; req->nfapi_config.timing_window.value = p7_vnf->timing_window; printf("[VNF] Timing window:%u\n", p7_vnf->timing_window); req->num_tlv++; if(p7_vnf->periodic_timing_enabled || p7_vnf->aperiodic_timing_enabled) { - req->nfapi_config.timing_info_mode.tl.tag = NFAPI_NFAPI_TIMING_INFO_MODE_TAG; req->nfapi_config.timing_info_mode.value = (p7_vnf->aperiodic_timing_enabled << 1) | (p7_vnf->periodic_timing_enabled); req->num_tlv++; if(p7_vnf->periodic_timing_enabled) { - req->nfapi_config.timing_info_period.tl.tag = NFAPI_NFAPI_TIMING_INFO_PERIOD_TAG; req->nfapi_config.timing_info_period.value = p7_vnf->periodic_timing_period; req->num_tlv++; @@ -943,142 +824,110 @@ int param_resp_cb(nfapi_vnf_config_t* config, int p5_idx, nfapi_param_response_t ve2.tl.tag = VENDOR_EXT_TLV_2_TAG; ve2.dummy = 2016; req->vendor_extension = &ve2.tl; - nfapi_vnf_config_req(config, p5_idx, req); printf("[VNF] Sent NFAPI_CONFIG_REQ num_tlv:%u\n",req->num_tlv); - return 0; } -int config_resp_cb(nfapi_vnf_config_t* config, int p5_idx, nfapi_config_response_t* resp) { - +int config_resp_cb(nfapi_vnf_config_t *config, int p5_idx, nfapi_config_response_t *resp) { nfapi_start_request_t req; - printf("[VNF] Received NFAPI_CONFIG_RESP idx:%d phy_id:%d\n", p5_idx, resp->header.phy_id); - printf("[VNF] Calling oai_enb_init()\n"); oai_enb_init(); - memset(&req, 0, sizeof(req)); req.header.message_id = NFAPI_START_REQUEST; req.header.phy_id = resp->header.phy_id; nfapi_vnf_start_req(config, p5_idx, &req); - printf("[VNF] Send NFAPI_START_REQUEST idx:%d phy_id:%d\n", p5_idx, resp->header.phy_id); - return 0; } -int start_resp_cb(nfapi_vnf_config_t* config, int p5_idx, nfapi_start_response_t* resp) { - +int start_resp_cb(nfapi_vnf_config_t *config, int p5_idx, nfapi_start_response_t *resp) { printf("[VNF] Received NFAPI_START_RESP idx:%d phy_id:%d\n", p5_idx, resp->header.phy_id); - - vnf_info* vnf = (vnf_info*)(config->user_data); - + vnf_info *vnf = (vnf_info *)(config->user_data); pnf_info *pnf = vnf->pnfs; phy_info *phy = pnf->phys; vnf_p7_info *p7_vnf = vnf->p7_vnfs; nfapi_vnf_p7_add_pnf((p7_vnf->config), phy->remote_addr, phy->remote_port, phy->id); - return 0; } -int vendor_ext_cb(nfapi_vnf_config_t* config, int p5_idx, nfapi_p4_p5_message_header_t* msg) { - +int vendor_ext_cb(nfapi_vnf_config_t *config, int p5_idx, nfapi_p4_p5_message_header_t *msg) { printf("[VNF] %s\n", __FUNCTION__); switch(msg->message_id) { - case P5_VENDOR_EXT_RSP: - { - vendor_ext_p5_rsp* rsp = (vendor_ext_p5_rsp*)msg; - printf("[VNF] P5_VENDOR_EXT_RSP error_code:%d\n", rsp->error_code); - - // send the start request - - nfapi_pnf_start_request_t req; - memset(&req, 0, sizeof(req)); - req.header.message_id = NFAPI_PNF_START_REQUEST; - nfapi_vnf_pnf_start_req(config, p5_idx, &req); - } - break; + case P5_VENDOR_EXT_RSP: { + vendor_ext_p5_rsp *rsp = (vendor_ext_p5_rsp *)msg; + printf("[VNF] P5_VENDOR_EXT_RSP error_code:%d\n", rsp->error_code); + // send the start request + nfapi_pnf_start_request_t req; + memset(&req, 0, sizeof(req)); + req.header.message_id = NFAPI_PNF_START_REQUEST; + nfapi_vnf_pnf_start_req(config, p5_idx, &req); + } + break; } return 0; } -int vnf_unpack_p4_p5_vendor_extension(nfapi_p4_p5_message_header_t* header, uint8_t** ppReadPackedMessage, uint8_t *end, nfapi_p4_p5_codec_config_t* codec) { - +int vnf_unpack_p4_p5_vendor_extension(nfapi_p4_p5_message_header_t *header, uint8_t **ppReadPackedMessage, uint8_t *end, nfapi_p4_p5_codec_config_t *codec) { //NFAPI_TRACE(NFAPI_TRACE_INFO, "%s\n", __FUNCTION__); - if(header->message_id == P5_VENDOR_EXT_RSP) - { - vendor_ext_p5_rsp* req = (vendor_ext_p5_rsp*)(header); + if(header->message_id == P5_VENDOR_EXT_RSP) { + vendor_ext_p5_rsp *req = (vendor_ext_p5_rsp *)(header); return(!pull16(ppReadPackedMessage, &req->error_code, end)); } + return 0; } -nfapi_p4_p5_message_header_t* vnf_allocate_p4_p5_vendor_ext(uint16_t message_id, uint16_t* msg_size) { - +nfapi_p4_p5_message_header_t *vnf_allocate_p4_p5_vendor_ext(uint16_t message_id, uint16_t *msg_size) { if(message_id == P5_VENDOR_EXT_RSP) { *msg_size = sizeof(vendor_ext_p5_rsp); - return (nfapi_p4_p5_message_header_t*)malloc(sizeof(vendor_ext_p5_rsp)); + return (nfapi_p4_p5_message_header_t *)malloc(sizeof(vendor_ext_p5_rsp)); } + return 0; } -void vnf_deallocate_p4_p5_vendor_ext(nfapi_p4_p5_message_header_t* header) { +void vnf_deallocate_p4_p5_vendor_ext(nfapi_p4_p5_message_header_t *header) { free(header); } nfapi_vnf_config_t *config = 0; -void vnf_start_thread(void* ptr) { - +void vnf_start_thread(void *ptr) { NFAPI_TRACE(NFAPI_TRACE_INFO, "[VNF] VNF NFAPI thread - nfapi_vnf_start()%s\n", __FUNCTION__); - pthread_setname_np(pthread_self(), "VNF"); - - config = (nfapi_vnf_config_t*)ptr; - + config = (nfapi_vnf_config_t *)ptr; nfapi_vnf_start(config); } static vnf_info vnf; extern uint8_t nfapi_mode; /*------------------------------------------------------------------------------*/ -void configure_nfapi_vnf(char *vnf_addr, int vnf_p5_port) -{ +void configure_nfapi_vnf(char *vnf_addr, int vnf_p5_port) { nfapi_mode = 2; - memset(&vnf, 0, sizeof(vnf)); - memset(vnf.p7_vnfs, 0, sizeof(vnf.p7_vnfs)); - vnf.p7_vnfs[0].timing_window = 32; vnf.p7_vnfs[0].periodic_timing_enabled = 1; vnf.p7_vnfs[0].aperiodic_timing_enabled = 0; vnf.p7_vnfs[0].periodic_timing_period = 10; - vnf.p7_vnfs[0].config = nfapi_vnf_p7_config_create(); NFAPI_TRACE(NFAPI_TRACE_INFO, "[VNF] %s() vnf.p7_vnfs[0].config:%p VNF ADDRESS:%s:%d\n", __FUNCTION__, vnf.p7_vnfs[0].config, vnf_addr, vnf_p5_port); - strcpy(vnf.p7_vnfs[0].local_addr, vnf_addr); vnf.p7_vnfs[0].local_port = 50001; - vnf.p7_vnfs[0].mac = (mac_t*)malloc(sizeof(mac_t)); - - nfapi_vnf_config_t* config = nfapi_vnf_config_create(); - + vnf.p7_vnfs[0].mac = (mac_t *)malloc(sizeof(mac_t)); + nfapi_vnf_config_t *config = nfapi_vnf_config_create(); config->malloc = malloc; config->free = free; config->trace = &vnf_trace; - config->vnf_p5_port = vnf_p5_port; config->vnf_ipv4 = 1; config->vnf_ipv6 = 0; - config->pnf_list = 0; config->phy_list = 0; - config->pnf_connection_indication = &pnf_connection_indication_cb; config->pnf_disconnect_indication = &pnf_disconnection_indication_cb; config->pnf_param_resp = &pnf_param_resp_cb; @@ -1088,33 +937,26 @@ void configure_nfapi_vnf(char *vnf_addr, int vnf_p5_port) config->config_resp = &config_resp_cb; config->start_resp = &start_resp_cb; config->vendor_ext = &vendor_ext_cb; - config->user_data = &vnf; - // To allow custom vendor extentions to be added to nfapi config->codec_config.unpack_vendor_extension_tlv = &vnf_unpack_vendor_extension_tlv; config->codec_config.pack_vendor_extension_tlv = &vnf_pack_vendor_extension_tlv; - config->codec_config.unpack_p4_p5_vendor_extension = &vnf_unpack_p4_p5_vendor_extension; config->codec_config.pack_p4_p5_vendor_extension = &vnf_pack_p4_p5_vendor_extension; config->allocate_p4_p5_vendor_ext = &vnf_allocate_p4_p5_vendor_ext; config->deallocate_p4_p5_vendor_ext = &vnf_deallocate_p4_p5_vendor_ext; config->codec_config.allocate = &vnf_allocate; config->codec_config.deallocate = &vnf_deallocate; - NFAPI_TRACE(NFAPI_TRACE_INFO, "[VNF] Creating VNF NFAPI start thread %s\n", __FUNCTION__); - pthread_create(&vnf_start_pthread, NULL, (void*)&vnf_start_thread, config); + pthread_create(&vnf_start_pthread, NULL, (void *)&vnf_start_thread, config); NFAPI_TRACE(NFAPI_TRACE_INFO, "[VNF] Created VNF NFAPI start thread %s\n", __FUNCTION__); } -int oai_nfapi_dl_config_req(nfapi_dl_config_request_t *dl_config_req) -{ +int oai_nfapi_dl_config_req(nfapi_dl_config_request_t *dl_config_req) { nfapi_vnf_p7_config_t *p7_config = vnf.p7_vnfs[0].config; - dl_config_req->header.phy_id = 1; // DJP HACK TODO FIXME - need to pass this around!!!! dl_config_req->header.message_id = NFAPI_DL_CONFIG_REQUEST; int retval = nfapi_vnf_p7_dl_config_req(p7_config, dl_config_req); - dl_config_req->dl_config_request_body.number_pdcch_ofdm_symbols = 1; dl_config_req->dl_config_request_body.number_dci = 0; dl_config_req->dl_config_request_body.number_pdu = 0; @@ -1123,35 +965,31 @@ int oai_nfapi_dl_config_req(nfapi_dl_config_request_t *dl_config_req) if (retval!=0) { LOG_E(PHY, "%s() Problem sending retval:%d\n", __FUNCTION__, retval); } + return retval; } -int oai_nfapi_tx_req(nfapi_tx_request_t *tx_req) -{ +int oai_nfapi_tx_req(nfapi_tx_request_t *tx_req) { nfapi_vnf_p7_config_t *p7_config = vnf.p7_vnfs[0].config; - tx_req->header.phy_id = 1; // DJP HACK TODO FIXME - need to pass this around!!!! tx_req->header.message_id = NFAPI_TX_REQUEST; //LOG_D(PHY, "[VNF] %s() TX_REQ sfn_sf:%d number_of_pdus:%d\n", __FUNCTION__, NFAPI_SFNSF2DEC(tx_req->sfn_sf), tx_req->tx_request_body.number_of_pdus); - int retval = nfapi_vnf_p7_tx_req(p7_config, tx_req); - if (retval!=0) { LOG_E(PHY, "%s() Problem sending retval:%d\n", __FUNCTION__, retval); } else { tx_req->tx_request_body.number_of_pdus = 0; } + return retval; } int oai_nfapi_hi_dci0_req(nfapi_hi_dci0_request_t *hi_dci0_req) { nfapi_vnf_p7_config_t *p7_config = vnf.p7_vnfs[0].config; - hi_dci0_req->header.phy_id = 1; // DJP HACK TODO FIXME - need to pass this around!!!! hi_dci0_req->header.message_id = NFAPI_HI_DCI0_REQUEST; //LOG_D(PHY, "[VNF] %s() HI_DCI0_REQ sfn_sf:%d dci:%d hi:%d\n", __FUNCTION__, NFAPI_SFNSF2DEC(hi_dci0_req->sfn_sf), hi_dci0_req->hi_dci0_request_body.number_of_dci, hi_dci0_req->hi_dci0_request_body.number_of_hi); - int retval = nfapi_vnf_p7_hi_dci0_req(p7_config, hi_dci0_req); if (retval!=0) { @@ -1160,19 +998,16 @@ int oai_nfapi_hi_dci0_req(nfapi_hi_dci0_request_t *hi_dci0_req) { hi_dci0_req->hi_dci0_request_body.number_of_hi = 0; hi_dci0_req->hi_dci0_request_body.number_of_dci = 0; } + return retval; } int oai_nfapi_ul_config_req(nfapi_ul_config_request_t *ul_config_req) { - nfapi_vnf_p7_config_t *p7_config = vnf.p7_vnfs[0].config; - ul_config_req->header.phy_id = 1; // DJP HACK TODO FIXME - need to pass this around!!!! ul_config_req->header.message_id = NFAPI_UL_CONFIG_REQUEST; //LOG_D(PHY, "[VNF] %s() header message_id:%02x\n", __FUNCTION__, ul_config_req->header.message_id); - //LOG_D(PHY, "[VNF] %s() UL_CONFIG sfn_sf:%d PDUs:%d rach_prach_frequency_resources:%d srs_present:%d\n", __FUNCTION__, NFAPI_SFNSF2DEC(ul_config_req->sfn_sf), ul_config_req->ul_config_request_body.number_of_pdus, ul_config_req->ul_config_request_body.rach_prach_frequency_resources, ul_config_req->ul_config_request_body.srs_present); - int retval = nfapi_vnf_p7_ul_config_req(p7_config, ul_config_req); if (retval!=0) { @@ -1183,5 +1018,6 @@ int oai_nfapi_ul_config_req(nfapi_ul_config_request_t *ul_config_req) { ul_config_req->ul_config_request_body.rach_prach_frequency_resources = 0; ul_config_req->ul_config_request_body.srs_present = 0; } + return retval; } diff --git a/nfapi/open-nFAPI/nfapi/src/nfapi_p7.c b/nfapi/open-nFAPI/nfapi/src/nfapi_p7.c index c180b5b0f9cfa24ae620950e19548d2b99387f3b..6fe9b47409b1108e11adee776540b1d5cec4506f 100644 --- a/nfapi/open-nFAPI/nfapi/src/nfapi_p7.c +++ b/nfapi/open-nFAPI/nfapi/src/nfapi_p7.c @@ -1545,7 +1545,7 @@ static uint8_t pack_tx_request_body_value(void* tlv, uint8_t **ppWritePackedMsg, // DJP - if(pusharray8(pdu->segments[j].segment_data, (uint32_t)(-1), pdu->segments[j].segment_length, ppWritePackedMsg, end) == 0) int push_ret = pusharray8(pdu->segments[j].segment_data, 65535, pdu->segments[j].segment_length, ppWritePackedMsg, end); - if (0 && pdu->segments[j].segment_length == 3) + if (pdu->segments[j].segment_length == 3) { NFAPI_TRACE(NFAPI_TRACE_INFO, "%s() BCH? segment_data:%x %x %x\n", __FUNCTION__, pdu->segments[j].segment_data[0], @@ -4429,40 +4429,43 @@ static uint8_t unpack_tx_request(uint8_t **ppReadPackedMsg, uint8_t *end, void * for(i = 0; i < totalNumPdus; ++i) { nfapi_tx_request_pdu_t* pdu = &(pNfapiMsg->tx_request_body.tx_pdu_list[i]); + if (pdu) { + uint16_t length = 0; + uint16_t index = 0; - uint16_t length = 0; - uint16_t index = 0; - - if(!(pull16(ppReadPackedMsg, &length, end) && + if(!(pull16(ppReadPackedMsg, &length, end) && pull16(ppReadPackedMsg, &index, end))) - return 0; + return 0; - pdu->pdu_length = length; - pdu->pdu_index = index; + pdu->pdu_length = length; + pdu->pdu_index = index; // TODO : May need to rethink this bit - pdu->num_segments = 1; - pdu->segments[0].segment_length = pdu->pdu_length; - pdu->segments[0].segment_data = nfapi_p7_allocate(pdu->pdu_length, config); + pdu->num_segments = 1; + pdu->segments[0].segment_length = pdu->pdu_length; + pdu->segments[0].segment_data = nfapi_p7_allocate(pdu->pdu_length, config); - if(pdu->segments[0].segment_data) - { - if(!pullarray8(ppReadPackedMsg, pdu->segments[0].segment_data, pdu->segments[0].segment_length, pdu->segments[0].segment_length, end)) + if(pdu->segments[0].segment_data) + { + if(!pullarray8(ppReadPackedMsg, pdu->segments[0].segment_data, pdu->segments[0].segment_length, pdu->segments[0].segment_length, end)) return 0; - if (0 && pdu->segments[0].segment_length == 3) - { + if (pdu->segments[0].segment_length == 3) + { NFAPI_TRACE(NFAPI_TRACE_INFO, "%s() BCH? segment_data:%x %x %x\n", __FUNCTION__, pdu->segments[0].segment_data[0], pdu->segments[0].segment_data[1], pdu->segments[0].segment_data[2] ); - } - } - else - { + } + } + else + { NFAPI_TRACE(NFAPI_TRACE_ERROR, "unpack_tx_request: Failed to allocate pdu (len:%d) %d/%d %d\n", pdu->pdu_length, totalNumPdus, i, pdu->pdu_index); - } + } + } else { + NFAPI_TRACE(NFAPI_TRACE_ERROR, "NULL pdu\n"); + } } } break; diff --git a/nfapi/open-nFAPI/pnf_sim/src/fapi_stub.cpp b/nfapi/open-nFAPI/pnf_sim/src/fapi_stub.cpp index df0ca12305f6ca954c9f02f1874e31c46637022e..1c2f0bef8078a072d7abd9eab6de65cbe3b5568d 100644 --- a/nfapi/open-nFAPI/pnf_sim/src/fapi_stub.cpp +++ b/nfapi/open-nFAPI/pnf_sim/src/fapi_stub.cpp @@ -1,12 +1,12 @@ /* * Copyright 2017 Cisco Systems, Inc. - * + * * Licensed 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. @@ -34,609 +34,510 @@ #include <queue> #include <list> -struct phy_pdu -{ - phy_pdu() : buffer_len(1500), buffer(0), len(0) - { - buffer = (char*) malloc(buffer_len); - } - - virtual ~phy_pdu() - { - free(buffer); - } - - - unsigned buffer_len; - char* buffer; - unsigned len; +struct phy_pdu { + phy_pdu() : buffer_len(1500), buffer(0), len(0) { + buffer = (char *) malloc(buffer_len); + } + + virtual ~phy_pdu() { + free(buffer); + } + + + unsigned buffer_len; + char *buffer; + unsigned len; }; -class fapi_private -{ - std::mutex mutex; - std::queue<phy_pdu*> rx_buffer; - - std::queue<phy_pdu*> free_store; - public: - - fapi_private() - : byte_count(0), tick(0), first_dl_config(false) - { - } - - phy_pdu* allocate_phy_pdu() - { - phy_pdu* pdu = 0; - mutex.lock(); - if(free_store.empty()) - { - pdu = new phy_pdu(); - } - else - { - pdu = free_store.front(); - free_store.pop(); - } - mutex.unlock(); - return pdu; - } - - void release_phy_pdu(phy_pdu* pdu) - { - mutex.lock(); - free_store.push(pdu); - mutex.unlock(); - } - - bool rx_buffer_empty() - { - bool empty; - mutex.lock(); - empty = rx_buffer.empty(); - mutex.unlock(); - - return empty; - } - - - void push_rx_buffer(phy_pdu* buff) - { - mutex.lock(); - rx_buffer.push(buff); - mutex.unlock(); - } - - phy_pdu* pop_rx_buffer() - { - phy_pdu* buff = 0; - mutex.lock(); - if(!rx_buffer.empty()) - { - buff = rx_buffer.front(); - rx_buffer.pop(); - } - mutex.unlock(); - return buff; - } - - uint32_t byte_count; - uint32_t tick; - bool first_dl_config; +class fapi_private { + std::mutex mutex; + std::queue<phy_pdu *> rx_buffer; + + std::queue<phy_pdu *> free_store; + public: + + fapi_private() + : byte_count(0), tick(0), first_dl_config(false) { + } + + phy_pdu *allocate_phy_pdu() { + phy_pdu *pdu = 0; + mutex.lock(); + + if(free_store.empty()) { + pdu = new phy_pdu(); + } else { + pdu = free_store.front(); + free_store.pop(); + } + + mutex.unlock(); + return pdu; + } + + void release_phy_pdu(phy_pdu *pdu) { + mutex.lock(); + free_store.push(pdu); + mutex.unlock(); + } + + bool rx_buffer_empty() { + bool empty; + mutex.lock(); + empty = rx_buffer.empty(); + mutex.unlock(); + return empty; + } + + + void push_rx_buffer(phy_pdu *buff) { + mutex.lock(); + rx_buffer.push(buff); + mutex.unlock(); + } + + phy_pdu *pop_rx_buffer() { + phy_pdu *buff = 0; + mutex.lock(); + + if(!rx_buffer.empty()) { + buff = rx_buffer.front(); + rx_buffer.pop(); + } + + mutex.unlock(); + return buff; + } + + uint32_t byte_count; + uint32_t tick; + bool first_dl_config; }; extern "C" { - typedef struct fapi_internal - { - fapi_t _public; + typedef struct fapi_internal { + fapi_t _public; - fapi_cb_t callbacks; + fapi_cb_t callbacks; - uint8_t state; - fapi_config_t config; + uint8_t state; + fapi_config_t config; - int rx_sock; - int tx_sock; - struct sockaddr_in tx_addr; + int rx_sock; + int tx_sock; + struct sockaddr_in tx_addr; - uint32_t tx_byte_count; - uint32_t tick; - - fapi_private* fapi; + uint32_t tx_byte_count; + uint32_t tick; - } fapi_internal_t; + fapi_private *fapi; + + } fapi_internal_t; } extern void set_thread_priority(int); /* { - pthread_attr_t ptAttr; - - struct sched_param schedParam; - schedParam.__sched_priority = 79; - sched_setscheduler(0, SCHED_RR, &schedParam); + pthread_attr_t ptAttr; + + struct sched_param schedParam; + schedParam.__sched_priority = 79; + sched_setscheduler(0, SCHED_RR, &schedParam); - pthread_attr_setschedpolicy(&ptAttr, SCHED_RR); + pthread_attr_setschedpolicy(&ptAttr, SCHED_RR); - pthread_attr_setinheritsched(&ptAttr, PTHREAD_EXPLICIT_SCHED); + pthread_attr_setinheritsched(&ptAttr, PTHREAD_EXPLICIT_SCHED); - struct sched_param thread_params; - thread_params.sched_priority = 20; - pthread_attr_setschedparam(&ptAttr, &thread_params); + struct sched_param thread_params; + thread_params.sched_priority = 20; + pthread_attr_setschedparam(&ptAttr, &thread_params); } */ -void send_uplink_indications(fapi_internal_t* instance, uint16_t sfn_sf) -{ - fapi_harq_ind_t harq_ind; - (instance->callbacks.fapi_harq_ind)(&(instance->_public), &harq_ind); - - fapi_crc_ind_t crc_ind; - crc_ind.header.message_id = FAPI_CRC_INDICATION; - crc_ind.header.length = 0; //??; - crc_ind.sfn_sf = sfn_sf; - crc_ind.body.number_of_crcs = 1; - crc_ind.body.pdus[0].rx_ue_info.handle = 0; //?? - crc_ind.body.pdus[0].rx_ue_info.rnti = 0; //?? - crc_ind.body.pdus[0].rel8_pdu.crc_flag = 1; - - (instance->callbacks.fapi_crc_ind)(&(instance->_public), &crc_ind); - - if(!instance->fapi->rx_buffer_empty()) - { - fapi_rx_ulsch_ind_t rx_ind; - memset(&rx_ind, 0, sizeof(rx_ind)); - rx_ind.header.message_id = FAPI_RX_ULSCH_INDICATION; - rx_ind.sfn_sf = sfn_sf; - - - phy_pdu* buff = 0; - int i = 0; - std::list<phy_pdu*> free_list; - do - { - buff = instance->fapi->pop_rx_buffer(); - if(buff != 0) - { - if(buff->len == 0) - { - printf("[FAPI] Buffer length = 0\n"); - } - - rx_ind.body.pdus[i].rx_ue_info.handle = 0xDEADBEEF; - rx_ind.body.pdus[i].rx_ue_info.rnti = 0x4242; - - rx_ind.body.pdus[i].rel8_pdu.length = buff->len; - //rx_ind.pdus[i].rel8_pdu.data_offset; - //rx_ind.pdus[i].rel8_pdu.ul_cqi; - //rx_ind.pdus[i].rel8_pdu.timing_advance; - - rx_ind.body.data[i] = buff->buffer; - - rx_ind.body.number_of_pdus++; - i++; - - instance->fapi->byte_count += buff->len; - - free_list.push_back(buff); - } - }while(buff != 0 && i < 8); - - (instance->callbacks.fapi_rx_ulsch_ind)(&(instance->_public), &rx_ind); - - for(phy_pdu* pdu : free_list) - { - instance->fapi->release_phy_pdu(pdu); - //free(tx_req.tx_request_body.tx_pdu_list[j].segments[0].segment_data); - } - } - else - { - fapi_rx_ulsch_ind_t rx_ind; - memset(&rx_ind, 0, sizeof(rx_ind)); - rx_ind.header.message_id = FAPI_RX_ULSCH_INDICATION; - rx_ind.sfn_sf = sfn_sf; - (instance->callbacks.fapi_rx_ulsch_ind)(&(instance->_public), &rx_ind); - } - - - fapi_rx_cqi_ind_t cqi_ind; - cqi_ind.sfn_sf = sfn_sf; - (instance->callbacks.fapi_rx_cqi_ind)(&(instance->_public), &cqi_ind); - - fapi_rx_sr_ind_t sr_ind; - sr_ind.sfn_sf = sfn_sf; - (instance->callbacks.fapi_rx_sr_ind)(&(instance->_public), &sr_ind); - - fapi_rach_ind_t rach_ind; - rach_ind.sfn_sf = sfn_sf; - (instance->callbacks.fapi_rach_ind)(&(instance->_public), &rach_ind); - - fapi_srs_ind_t srs_ind; - srs_ind.sfn_sf = sfn_sf; - (instance->callbacks.fapi_srs_ind)(&(instance->_public), &srs_ind); - /* - nfapi_lbt_dl_indication_t lbt_ind; - memset(&lbt_ind, 0, sizeof(lbt_ind)); - lbt_ind.header.message_id = NFAPI_LBT_DL_INDICATION; - lbt_ind.header.phy_id = config->phy_id; - lbt_ind.sfn_sf = sfn_sf; - nfapi_pnf_p7_lbt_dl_ind(config, &lbt_ind); - - vendor_ext_p7_ind ve_p7_ind; - memset(&ve_p7_ind, 0, sizeof(ve_p7_ind)); - ve_p7_ind.header.message_id = P7_VENDOR_EXT_IND; - ve_p7_ind.header.phy_id = config->phy_id; - ve_p7_ind.error_code = NFAPI_MSG_OK; - nfapi_pnf_p7_vendor_extension(config, &(ve_p7_ind.header)); - */ - - fapi_nb_harq_ind_t nb_harq_ind; - nb_harq_ind.sfn_sf = sfn_sf; - (instance->callbacks.fapi_nb_harq_ind)(&(instance->_public), &nb_harq_ind); - - fapi_nrach_ind_t nrach_ind; - nrach_ind.sfn_sf = sfn_sf; - (instance->callbacks.fapi_nrach_ind)(&(instance->_public), &nrach_ind); - +void send_uplink_indications(fapi_internal_t *instance, uint16_t sfn_sf) { + fapi_harq_ind_t harq_ind; + (instance->callbacks.fapi_harq_ind)(&(instance->_public), &harq_ind); + fapi_crc_ind_t crc_ind; + crc_ind.header.message_id = FAPI_CRC_INDICATION; + crc_ind.header.length = 0; //??; + crc_ind.sfn_sf = sfn_sf; + crc_ind.body.number_of_crcs = 1; + crc_ind.body.pdus[0].rx_ue_info.handle = 0; //?? + crc_ind.body.pdus[0].rx_ue_info.rnti = 0; //?? + crc_ind.body.pdus[0].rel8_pdu.crc_flag = 1; + (instance->callbacks.fapi_crc_ind)(&(instance->_public), &crc_ind); + + if(!instance->fapi->rx_buffer_empty()) { + fapi_rx_ulsch_ind_t rx_ind; + memset(&rx_ind, 0, sizeof(rx_ind)); + rx_ind.header.message_id = FAPI_RX_ULSCH_INDICATION; + rx_ind.sfn_sf = sfn_sf; + phy_pdu *buff = 0; + int i = 0; + std::list<phy_pdu *> free_list; + + do { + buff = instance->fapi->pop_rx_buffer(); + + if(buff != 0) { + if(buff->len == 0) { + printf("[FAPI] Buffer length = 0\n"); + } + + rx_ind.body.pdus[i].rx_ue_info.handle = 0xDEADBEEF; + rx_ind.body.pdus[i].rx_ue_info.rnti = 0x4242; + rx_ind.body.pdus[i].rel8_pdu.length = buff->len; + //rx_ind.pdus[i].rel8_pdu.data_offset; + //rx_ind.pdus[i].rel8_pdu.ul_cqi; + //rx_ind.pdus[i].rel8_pdu.timing_advance; + rx_ind.body.data[i] = buff->buffer; + rx_ind.body.number_of_pdus++; + i++; + instance->fapi->byte_count += buff->len; + free_list.push_back(buff); + } + } while(buff != 0 && i < 8); + + (instance->callbacks.fapi_rx_ulsch_ind)(&(instance->_public), &rx_ind); + + for(phy_pdu *pdu : free_list) { + instance->fapi->release_phy_pdu(pdu); + //free(tx_req.tx_request_body.tx_pdu_list[j].segments[0].segment_data); + } + } else { + fapi_rx_ulsch_ind_t rx_ind; + memset(&rx_ind, 0, sizeof(rx_ind)); + rx_ind.header.message_id = FAPI_RX_ULSCH_INDICATION; + rx_ind.sfn_sf = sfn_sf; + (instance->callbacks.fapi_rx_ulsch_ind)(&(instance->_public), &rx_ind); + } + + fapi_rx_cqi_ind_t cqi_ind; + cqi_ind.sfn_sf = sfn_sf; + (instance->callbacks.fapi_rx_cqi_ind)(&(instance->_public), &cqi_ind); + fapi_rx_sr_ind_t sr_ind; + sr_ind.sfn_sf = sfn_sf; + (instance->callbacks.fapi_rx_sr_ind)(&(instance->_public), &sr_ind); + fapi_rach_ind_t rach_ind; + rach_ind.sfn_sf = sfn_sf; + (instance->callbacks.fapi_rach_ind)(&(instance->_public), &rach_ind); + fapi_srs_ind_t srs_ind; + srs_ind.sfn_sf = sfn_sf; + (instance->callbacks.fapi_srs_ind)(&(instance->_public), &srs_ind); + /* + nfapi_lbt_dl_indication_t lbt_ind; + memset(&lbt_ind, 0, sizeof(lbt_ind)); + lbt_ind.header.message_id = NFAPI_LBT_DL_INDICATION; + lbt_ind.header.phy_id = config->phy_id; + lbt_ind.sfn_sf = sfn_sf; + nfapi_pnf_p7_lbt_dl_ind(config, &lbt_ind); + + vendor_ext_p7_ind ve_p7_ind; + memset(&ve_p7_ind, 0, sizeof(ve_p7_ind)); + ve_p7_ind.header.message_id = P7_VENDOR_EXT_IND; + ve_p7_ind.header.phy_id = config->phy_id; + ve_p7_ind.error_code = NFAPI_MSG_OK; + nfapi_pnf_p7_vendor_extension(config, &(ve_p7_ind.header)); + */ + fapi_nb_harq_ind_t nb_harq_ind; + nb_harq_ind.sfn_sf = sfn_sf; + (instance->callbacks.fapi_nb_harq_ind)(&(instance->_public), &nb_harq_ind); + fapi_nrach_ind_t nrach_ind; + nrach_ind.sfn_sf = sfn_sf; + (instance->callbacks.fapi_nrach_ind)(&(instance->_public), &nrach_ind); } -void* fapi_thread_start(void* ptr) -{ - set_thread_priority(81); - - fapi_internal_t* instance = (fapi_internal_t*)ptr; - uint16_t sfn_sf_dec = 0; - uint32_t last_tv_usec = 0; - uint32_t last_tv_sec = 0; - - uint32_t millisec; - uint32_t last_millisec = -1; - uint16_t catchup = 0; - - while(1) - { - // get the time - struct timeval sf_start; - (void)gettimeofday(&sf_start, NULL); - - uint16_t sfn_sf = ((((sfn_sf_dec) / 10) << 4) | (((sfn_sf_dec) - (((sfn_sf_dec) / 10) * 10)) & 0xF)); - // increment the sfn/sf - for the next subframe - sfn_sf_dec++; - if(sfn_sf_dec > 10239) - sfn_sf_dec = 0; - - - fapi_subframe_ind_t ind; - ind.sfn_sf = sfn_sf; - - if(instance->fapi->first_dl_config) - send_uplink_indications(instance, sfn_sf); - - if(instance->tick == 1000) - { - if(instance->tx_byte_count > 0) - { - printf("[FAPI] Tx rate %d bytes/sec\n", instance->tx_byte_count); - instance->tx_byte_count = 0; - } - - instance->tick = 0; - } - - instance->tick++; - - (instance->callbacks.fapi_subframe_ind)(&(instance->_public), &ind); - - { - phy_pdu* pdu = instance->fapi->allocate_phy_pdu(); - int len = recvfrom(instance->rx_sock, pdu->buffer, pdu->buffer_len, MSG_DONTWAIT, 0, 0); - if(len > 0) - { - pdu->len = len; - instance->fapi->push_rx_buffer(pdu); - } - else - { - instance->fapi->release_phy_pdu(pdu); - } - } - - - if(catchup) - { - catchup--; - } - else - { - struct timespec now_ts; - struct timespec sleep_ts; - struct timespec sleep_rem_ts; - - // get the current time - clock_gettime(CLOCK_MONOTONIC, &now_ts); - - - // determine how long to sleep before the start of the next 1ms - sleep_ts.tv_sec = 0; - sleep_ts.tv_nsec = 1e6 - (now_ts.tv_nsec % 1000000); - - int nanosleep_result = nanosleep(&sleep_ts, &sleep_rem_ts); - - if(nanosleep_result != 0) - printf("*** nanosleep failed or was interrupted\n"); - - - clock_gettime(CLOCK_MONOTONIC, &now_ts); - millisec = now_ts.tv_nsec / 1e6; - - if(last_millisec != -1 && ((last_millisec + 1 ) % 1000) != millisec) - { - printf("*** missing millisec %d %d\n", last_millisec, millisec); - catchup = millisec - last_millisec - 1; - } - - last_millisec = millisec; - } - } +void *fapi_thread_start(void *ptr) { + set_thread_priority(81); + fapi_internal_t *instance = (fapi_internal_t *)ptr; + uint16_t sfn_sf_dec = 0; + uint32_t last_tv_usec = 0; + uint32_t last_tv_sec = 0; + uint32_t millisec; + uint32_t last_millisec = -1; + uint16_t catchup = 0; + + while(1) { + // get the time + struct timeval sf_start; + (void)gettimeofday(&sf_start, NULL); + uint16_t sfn_sf = ((((sfn_sf_dec) / 10) << 4) | (((sfn_sf_dec) - (((sfn_sf_dec) / 10) * 10)) & 0xF)); + // increment the sfn/sf - for the next subframe + sfn_sf_dec++; + + if(sfn_sf_dec > 10239) + sfn_sf_dec = 0; + + fapi_subframe_ind_t ind; + ind.sfn_sf = sfn_sf; + + if(instance->fapi->first_dl_config) + send_uplink_indications(instance, sfn_sf); + + if(instance->tick == 1000) { + if(instance->tx_byte_count > 0) { + printf("[FAPI] Tx rate %d bytes/sec\n", instance->tx_byte_count); + instance->tx_byte_count = 0; + } + + instance->tick = 0; + } + + instance->tick++; + (instance->callbacks.fapi_subframe_ind)(&(instance->_public), &ind); + { + phy_pdu *pdu = instance->fapi->allocate_phy_pdu(); + int len = recvfrom(instance->rx_sock, pdu->buffer, pdu->buffer_len, MSG_DONTWAIT, 0, 0); + + if(len > 0) { + pdu->len = len; + instance->fapi->push_rx_buffer(pdu); + } else { + instance->fapi->release_phy_pdu(pdu); + } + } + + if(catchup) { + catchup--; + } else { + struct timespec now_ts; + struct timespec sleep_ts; + struct timespec sleep_rem_ts; + // get the current time + clock_gettime(CLOCK_MONOTONIC, &now_ts); + // determine how long to sleep before the start of the next 1ms + sleep_ts.tv_sec = 0; + sleep_ts.tv_nsec = 1e6 - (now_ts.tv_nsec % 1000000); + int nanosleep_result = nanosleep(&sleep_ts, &sleep_rem_ts); + + if(nanosleep_result != 0) + printf("*** nanosleep failed or was interrupted\n"); + + clock_gettime(CLOCK_MONOTONIC, &now_ts); + millisec = now_ts.tv_nsec / 1e6; + + if(last_millisec != -1 && ((last_millisec + 1 ) % 1000) != millisec) { + printf("*** missing millisec %d %d\n", last_millisec, millisec); + catchup = millisec - last_millisec - 1; + } + + last_millisec = millisec; + } + } } extern "C" { - fapi_t* fapi_create(fapi_cb_t* callbacks, fapi_config_t* config) - { - fapi_internal_t* instance = (fapi_internal*)calloc(1, sizeof(fapi_internal_t)); - instance->callbacks = *callbacks; - instance->config = *config; - instance->state = 0; - - instance->fapi = new fapi_private(); - - return (fapi_t*)instance; - } - - void fapi_destroy(fapi_t* fapi) - { - fapi_internal_t* instance = (fapi_internal_t*)fapi; - - delete instance->fapi; - free(instance); - } - - void* fapi_rx_thread_start(void* ptr) - { - set_thread_priority(60); - - fapi_internal_t* instance = (fapi_internal_t*)ptr; - - while(1) - { - phy_pdu* pdu = instance->fapi->allocate_phy_pdu(); - int len = recvfrom(instance->rx_sock, pdu->buffer, pdu->buffer_len, 0, 0, 0); - if(len > 0) - { - pdu->len = len; - instance->fapi->push_rx_buffer(pdu); - } - else - { - instance->fapi->release_phy_pdu(pdu); - } - - } - } - - void fapi_start_data(fapi_t* fapi, unsigned rx_port, const char* tx_address, unsigned tx_port) - { - fapi_internal_t* instance = (fapi_internal_t*)fapi; - - printf("[FAPI] Rx Data from %d\n", rx_port); - printf("[FAPI] Tx Data to %s:%d\n", tx_address, tx_port); - - instance->rx_sock = socket(AF_INET, SOCK_DGRAM, 0); - - if(instance->rx_sock < 0) - { - printf("[FAPI] Failed to create socket\n"); - return; - } - - struct sockaddr_in addr; - memset(&addr, 0, sizeof(addr)); - addr.sin_family = AF_INET; - addr.sin_port = htons(rx_port); - addr.sin_addr.s_addr = INADDR_ANY; - - int bind_result = bind(instance->rx_sock, (struct sockaddr *)&addr, sizeof(struct sockaddr_in)); - - if(bind_result == -1) - { - printf("[FAPI] Failed to bind to port %d\n", rx_port); - close(instance->rx_sock); - return ; - } - - instance->tx_sock = socket(AF_INET, SOCK_DGRAM, 0); - instance->tx_addr.sin_family = AF_INET; - instance->tx_addr.sin_port = htons(tx_port); - instance->tx_addr.sin_addr.s_addr = inet_addr(tx_address); - - } - - - void fill_tlv(fapi_tlv_t tlvs[], uint8_t count, uint8_t tag, uint8_t len, uint16_t value) - { - tlvs[count].tag = tag; - tlvs[count].value = value; - tlvs[count].length = len; - - } - - int fapi_param_request(fapi_t* fapi, fapi_param_req_t* req) - { - fapi_internal_t* instance = (fapi_internal_t*)fapi; - - fapi_param_resp_t resp; - resp.header.message_id = FAPI_PARAM_RESPONSE; - - resp.error_code = FAPI_MSG_OK; - - resp.number_of_tlvs = 0; - fill_tlv(resp.tlvs, resp.number_of_tlvs++, FAPI_PHY_STATE_TAG, 2, instance->state); - - - if(instance->state == 0) - { - if(instance->config.duplex_mode == 0) - { - // -- TDD - // Downlink Bandwidth Support - // Uplink Bandwidth Support - // Downlink Modulation Support - // Uplink Modulation Support - // PHY Antenna Capability - // Release Capability - // MBSFN Capability - } - else if(instance->config.duplex_mode == 1) - { - // -- FDD - // Downlink Bandwidth Support - fill_tlv(resp.tlvs, resp.number_of_tlvs++, FAPI_PHY_CAPABILITIES_DL_BANDWIDTH_SUPPORT_TAG, 2, instance->config.dl_channel_bw_support); - // Uplink Bandwidth Support - fill_tlv(resp.tlvs, resp.number_of_tlvs++, FAPI_PHY_CAPABILITIES_UL_BANDWIDTH_SUPPORT_TAG, 2, instance->config.ul_channel_bw_support); - // Downlink Modulation Support - // Uplink Modulation Support - // PHY Antenna Capability - // Release Capability - // MBSFN Capability - // LAA Capability - } - } - else - { - if(instance->config.duplex_mode == 0) - { - // -- TDD - // Downlink Bandwidth Support - // Uplink Bandwidth Support - // Downlink Modulation Support - // Uplink Modulation Support - // PHY Antenna Capability - // Release Capability - // MBSFN Capability - // Duplexing Mode - // PCFICH Power Offset - // P-B - // DL Cyclic Prefix Type - // UL Cyclic Prefix Type - // RF Config - // PHICH Config - // SCH Config - // PRACH Config - // PUSCH Config - // PUCCH Config - // SRS Config - // Uplink Reference Signal Config - // TDD Frame Structure Config - // Data Report Mode - } - else if(instance->config.duplex_mode == 1) - { - // FDD - // Downlink Bandwidth Support - // Uplink Bandwidth Support - // Downlink Modulation Support - // Uplink Modulation Support - // PHY Antenna Capability - // Release Capability - // MBSFN Capability - // LAA Capability - // Duplexing Mode - // PCFICH Power Offset - // P-B - // DL Cyclic Prefix Type - // UL Cyclic Prefix Type - // RF Config - // PHICH Config - // SCH Config - // PRACH Config - // PUSCH Config - // PUCCH Config - // SRS Config - // Uplink Reference Signal Config - // Data Report Mode - } - } - - - //todo fill - (instance->callbacks.fapi_param_response)(fapi, &resp); - - return 0; - } - - int fapi_config_request(fapi_t* fapi, fapi_config_req_t* req) - { - fapi_internal_t* instance = (fapi_internal_t*)fapi; - - fapi_config_resp_t resp; - resp.header.message_id = FAPI_CONFIG_RESPONSE; - resp.error_code = FAPI_MSG_OK; - - (instance->callbacks.fapi_config_response)(fapi, &resp); - return 0; - } - - int fapi_start_request(fapi_t* fapi, fapi_start_req_t* req) - { - fapi_internal_t* instance = (fapi_internal_t*)fapi; - - pthread_t fapi_thread; - pthread_create(&fapi_thread, NULL, &fapi_thread_start, instance); - - return 0; - } - - int fapi_dl_config_request(fapi_t* fapi, fapi_dl_config_req_t* req) - { - fapi_internal_t* instance = (fapi_internal_t*)fapi; - instance->fapi->first_dl_config = true; - return 0; - } - int fapi_ul_config_request(fapi_t* fapi, fapi_ul_config_req_t* req) - { - fapi_internal_t* instance = (fapi_internal_t*)fapi; - return 0; - } - int fapi_hi_dci0_request(fapi_t* fapi, fapi_hi_dci0_req_t* req) - { - fapi_internal_t* instance = (fapi_internal_t*)fapi; - return 0; - } - int fapi_tx_request(fapi_t* fapi, fapi_tx_req_t* req) - { - fapi_internal_t* instance = (fapi_internal_t*)fapi; - - for(int i = 0; i < req->body.number_of_pdus; ++i) - { - uint16_t len = req->body.pdus[i].pdu_length; - uint32_t* data = req->body.pdus[i].tlvs[0].value; - //printf("[FAPI] sfnsf:%d len:%d\n", req->sfn_sf,len); - // - instance->tx_byte_count += len; - - int sendto_result = sendto(instance->tx_sock, data, len, 0, (struct sockaddr*)&(instance->tx_addr), sizeof(instance->tx_addr)); - - if(sendto_result == -1) - { - // error - } - } - - return 0; - } + fapi_t *fapi_create(fapi_cb_t *callbacks, fapi_config_t *config) { + fapi_internal_t *instance = (fapi_internal *)calloc(1, sizeof(fapi_internal_t)); + instance->callbacks = *callbacks; + instance->config = *config; + instance->state = 0; + instance->fapi = new fapi_private(); + return (fapi_t *)instance; + } + + void fapi_destroy(fapi_t *fapi) { + fapi_internal_t *instance = (fapi_internal_t *)fapi; + delete instance->fapi; + free(instance); + } + + void *fapi_rx_thread_start(void *ptr) { + set_thread_priority(60); + fapi_internal_t *instance = (fapi_internal_t *)ptr; + + while(1) { + phy_pdu *pdu = instance->fapi->allocate_phy_pdu(); + int len = recvfrom(instance->rx_sock, pdu->buffer, pdu->buffer_len, 0, 0, 0); + + if(len > 0) { + pdu->len = len; + instance->fapi->push_rx_buffer(pdu); + } else { + instance->fapi->release_phy_pdu(pdu); + } + } + } + + void fapi_start_data(fapi_t *fapi, unsigned rx_port, const char *tx_address, unsigned tx_port) { + fapi_internal_t *instance = (fapi_internal_t *)fapi; + printf("[FAPI] Rx Data from %u\n", rx_port); + printf("[FAPI] Tx Data to %s:%u\n", tx_address, tx_port); + instance->rx_sock = socket(AF_INET, SOCK_DGRAM, 0); + + if(instance->rx_sock < 0) { + printf("[FAPI] Failed to create socket\n"); + return; + } + + struct sockaddr_in addr; + + memset(&addr, 0, sizeof(addr)); + + addr.sin_family = AF_INET; + + addr.sin_port = htons(rx_port); + + addr.sin_addr.s_addr = INADDR_ANY; + + int bind_result = bind(instance->rx_sock, (struct sockaddr *)&addr, sizeof(struct sockaddr_in)); + + if(bind_result == -1) { + printf("[FAPI] Failed to bind to port %u\n", rx_port); + close(instance->rx_sock); + return ; + } + + instance->tx_sock = socket(AF_INET, SOCK_DGRAM, 0); + instance->tx_addr.sin_family = AF_INET; + instance->tx_addr.sin_port = htons(tx_port); + instance->tx_addr.sin_addr.s_addr = inet_addr(tx_address); + } + + + void fill_tlv(fapi_tlv_t tlvs[], uint8_t count, uint8_t tag, uint8_t len, uint16_t value) { + tlvs[count].tag = tag; + tlvs[count].value = value; + tlvs[count].length = len; + } + + int fapi_param_request(fapi_t *fapi, fapi_param_req_t *req) { + fapi_internal_t *instance = (fapi_internal_t *)fapi; + fapi_param_resp_t resp; + resp.header.message_id = FAPI_PARAM_RESPONSE; + resp.error_code = FAPI_MSG_OK; + resp.number_of_tlvs = 0; + fill_tlv(resp.tlvs, resp.number_of_tlvs++, FAPI_PHY_STATE_TAG, 2, instance->state); + + if(instance->state == 0) { + if(instance->config.duplex_mode == 0) { + // -- TDD + // Downlink Bandwidth Support + // Uplink Bandwidth Support + // Downlink Modulation Support + // Uplink Modulation Support + // PHY Antenna Capability + // Release Capability + // MBSFN Capability + } else if(instance->config.duplex_mode == 1) { + // -- FDD + // Downlink Bandwidth Support + fill_tlv(resp.tlvs, resp.number_of_tlvs++, FAPI_PHY_CAPABILITIES_DL_BANDWIDTH_SUPPORT_TAG, 2, instance->config.dl_channel_bw_support); + // Uplink Bandwidth Support + fill_tlv(resp.tlvs, resp.number_of_tlvs++, FAPI_PHY_CAPABILITIES_UL_BANDWIDTH_SUPPORT_TAG, 2, instance->config.ul_channel_bw_support); + // Downlink Modulation Support + // Uplink Modulation Support + // PHY Antenna Capability + // Release Capability + // MBSFN Capability + // LAA Capability + } + } else { + if(instance->config.duplex_mode == 0) { + // -- TDD + // Downlink Bandwidth Support + // Uplink Bandwidth Support + // Downlink Modulation Support + // Uplink Modulation Support + // PHY Antenna Capability + // Release Capability + // MBSFN Capability + // Duplexing Mode + // PCFICH Power Offset + // P-B + // DL Cyclic Prefix Type + // UL Cyclic Prefix Type + // RF Config + // PHICH Config + // SCH Config + // PRACH Config + // PUSCH Config + // PUCCH Config + // SRS Config + // Uplink Reference Signal Config + // TDD Frame Structure Config + // Data Report Mode + } else if(instance->config.duplex_mode == 1) { + // FDD + // Downlink Bandwidth Support + // Uplink Bandwidth Support + // Downlink Modulation Support + // Uplink Modulation Support + // PHY Antenna Capability + // Release Capability + // MBSFN Capability + // LAA Capability + // Duplexing Mode + // PCFICH Power Offset + // P-B + // DL Cyclic Prefix Type + // UL Cyclic Prefix Type + // RF Config + // PHICH Config + // SCH Config + // PRACH Config + // PUSCH Config + // PUCCH Config + // SRS Config + // Uplink Reference Signal Config + // Data Report Mode + } + } + + //todo fill + (instance->callbacks.fapi_param_response)(fapi, &resp); + return 0; + } + + int fapi_config_request(fapi_t *fapi, fapi_config_req_t *req) { + fapi_internal_t *instance = (fapi_internal_t *)fapi; + fapi_config_resp_t resp; + resp.header.message_id = FAPI_CONFIG_RESPONSE; + resp.error_code = FAPI_MSG_OK; + (instance->callbacks.fapi_config_response)(fapi, &resp); + return 0; + } + + int fapi_start_request(fapi_t *fapi, fapi_start_req_t *req) { + fapi_internal_t *instance = (fapi_internal_t *)fapi; + pthread_t fapi_thread; + pthread_create(&fapi_thread, NULL, &fapi_thread_start, instance); + return 0; + } + + int fapi_dl_config_request(fapi_t *fapi, fapi_dl_config_req_t *req) { + fapi_internal_t *instance = (fapi_internal_t *)fapi; + instance->fapi->first_dl_config = true; + return 0; + } + int fapi_ul_config_request(fapi_t *fapi, fapi_ul_config_req_t *req) { + fapi_internal_t *instance = (fapi_internal_t *)fapi; + return 0; + } + int fapi_hi_dci0_request(fapi_t *fapi, fapi_hi_dci0_req_t *req) { + fapi_internal_t *instance = (fapi_internal_t *)fapi; + return 0; + } + int fapi_tx_request(fapi_t *fapi, fapi_tx_req_t *req) { + fapi_internal_t *instance = (fapi_internal_t *)fapi; + + for(int i = 0; i < req->body.number_of_pdus; ++i) { + uint16_t len = req->body.pdus[i].pdu_length; + uint32_t *data = req->body.pdus[i].tlvs[0].value; + //printf("[FAPI] sfnsf:%d len:%d\n", req->sfn_sf,len); + // + instance->tx_byte_count += len; + int sendto_result = sendto(instance->tx_sock, data, len, 0, (struct sockaddr *)&(instance->tx_addr), sizeof(instance->tx_addr)); + + if(sendto_result == -1) { + // error + } + } + + return 0; + } } diff --git a/nfapi/open-nFAPI/pnf_sim/src/main.cpp b/nfapi/open-nFAPI/pnf_sim/src/main.cpp index e2622cf3c3636f1021633e1570c8949d31088f8c..251e2a48cbdd2156b61e84d83c26adc2858c780e 100644 --- a/nfapi/open-nFAPI/pnf_sim/src/main.cpp +++ b/nfapi/open-nFAPI/pnf_sim/src/main.cpp @@ -101,7 +101,7 @@ class phy_info { index = 0; id = 0; - + udp = 0; local_port = 0; remote_addr = 0; remote_port = 0; @@ -178,6 +178,7 @@ class pnf_info sync_mode = 0; location_mode = 0; + location_coordinates = 0; dl_config_timing = 0; ul_config_timing = 0; tx_timing = 0; diff --git a/nfapi/open-nFAPI/vnf_sim/src/mac.cpp b/nfapi/open-nFAPI/vnf_sim/src/mac.cpp index fa6f487be8e2274d55ac10c69b238070abfea6f6..88898afc744133966b9eb079235b4537d2be453d 100644 --- a/nfapi/open-nFAPI/vnf_sim/src/mac.cpp +++ b/nfapi/open-nFAPI/vnf_sim/src/mac.cpp @@ -1,12 +1,12 @@ /* * Copyright 2017 Cisco Systems, Inc. - * + * * Licensed 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. @@ -31,1297 +31,1130 @@ #include <queue> #include <list> -uint32_t rand_range(uint32_t min, uint32_t max) -{ - return ((rand() % (max + 1 - min)) + min); +uint32_t rand_range(uint32_t min, uint32_t max) { + return ((rand() % (max + 1 - min)) + min); } -struct mac_pdu -{ - mac_pdu() : buffer_len(1500), buffer(0), len(0) - { - buffer = (char*) malloc(buffer_len); - } - - virtual ~mac_pdu() - { - free(buffer); - } - - unsigned buffer_len; - char* buffer; - unsigned len; +struct mac_pdu { + mac_pdu() : buffer_len(1500), buffer(0), len(0) { + buffer = (char *) malloc(buffer_len); + } + + virtual ~mac_pdu() { + free(buffer); + } + + unsigned buffer_len; + char *buffer; + unsigned len; }; -class mac_private -{ - std::mutex mutex; - std::queue<mac_pdu*> rx_buffer; - - std::queue<mac_pdu*> free_store; - public: - - mac_private(bool _wireshark_test_mode) - : byte_count(0), tick(0), wireshark_test_mode(_wireshark_test_mode) - { - - } - - mac_pdu* allocate_mac_pdu() - { - mac_pdu* pdu = 0; - mutex.lock(); - if(free_store.empty()) - { - pdu = new mac_pdu(); - } - else - { - pdu = free_store.front(); - free_store.pop(); - } - mutex.unlock(); - return pdu; - } - - void release_mac_pdu(mac_pdu* pdu) - { - mutex.lock(); - free_store.push(pdu); - mutex.unlock(); - } - - - - void push_rx_buffer(mac_pdu* buff) - { - mutex.lock(); - rx_buffer.push(buff); - mutex.unlock(); - } - - mac_pdu* pop_rx_buffer() - { - mac_pdu* buff = 0; - mutex.lock(); - if(!rx_buffer.empty()) - { - buff = rx_buffer.front(); - rx_buffer.pop(); - } - mutex.unlock(); - return buff; - } - - uint32_t byte_count; - uint32_t tick; - - bool wireshark_test_mode; +class mac_private { + std::mutex mutex; + std::queue<mac_pdu *> rx_buffer; + + std::queue<mac_pdu *> free_store; + public: + + mac_private(bool _wireshark_test_mode) + : byte_count(0), tick(0), wireshark_test_mode(_wireshark_test_mode) { + } + + mac_pdu *allocate_mac_pdu() { + mac_pdu *pdu = 0; + mutex.lock(); + + if(free_store.empty()) { + pdu = new mac_pdu(); + } else { + pdu = free_store.front(); + free_store.pop(); + } + + mutex.unlock(); + return pdu; + } + + void release_mac_pdu(mac_pdu *pdu) { + mutex.lock(); + free_store.push(pdu); + mutex.unlock(); + } + + + + void push_rx_buffer(mac_pdu *buff) { + mutex.lock(); + rx_buffer.push(buff); + mutex.unlock(); + } + + mac_pdu *pop_rx_buffer() { + mac_pdu *buff = 0; + mutex.lock(); + + if(!rx_buffer.empty()) { + buff = rx_buffer.front(); + rx_buffer.pop(); + } + + mutex.unlock(); + return buff; + } + + uint32_t byte_count; + uint32_t tick; + + bool wireshark_test_mode; }; extern "C" { - typedef struct { - mac_t _public; - - int rx_sock; - int tx_sock; - struct sockaddr_in tx_addr; - - uint32_t tx_byte_count; - - mac_private* mac; - - } mac_internal_t; - - mac_t* mac_create(uint8_t wireshark_test_mode) - { - mac_internal_t* instance = (mac_internal_t*)malloc(sizeof(mac_internal_t)); - instance->mac = new mac_private((wireshark_test_mode >= 1)); - return (mac_t*)instance; - } - - void mac_destroy(mac_t* mac) - { - mac_internal_t* instance = (mac_internal_t*)mac; - delete instance->mac; - free(instance); - } - - void* mac_rx_thread_start(void* ptr) - { - mac_internal_t* instance = (mac_internal_t*)ptr; - - while(1) - { - mac_pdu* pdu = instance->mac->allocate_mac_pdu(); - int len = recvfrom(instance->rx_sock, pdu->buffer, pdu->buffer_len, 0, 0, 0); - if(len > 0) - { - pdu->len = len; - instance->mac->push_rx_buffer(pdu); - } - else - { - instance->mac->release_mac_pdu(pdu); - } - } - return 0; - } - - void mac_start_data(mac_t* mac, unsigned rx_port, const char* tx_address, unsigned tx_port) - { - mac_internal_t* instance = (mac_internal_t*)mac; - - printf("[MAC] Rx Data from %d\n", rx_port); - printf("[MAC] Tx Data to %s.%d\n", tx_address, tx_port); - - instance->rx_sock = socket(AF_INET, SOCK_DGRAM, 0); - - if(instance->rx_sock < 0) - { - printf("[MAC] Failed to create socket\n"); - return; - } - - struct sockaddr_in addr; - memset(&addr, 0, sizeof(0)); - addr.sin_family = AF_INET; - addr.sin_port = htons(rx_port); - addr.sin_addr.s_addr = INADDR_ANY; - - if(bind(instance->rx_sock, (struct sockaddr *)&addr, sizeof(struct sockaddr_in)) < 0) - { - printf("[MAC] Failed to bind to %d\n", rx_port); - close(instance->rx_sock); - return; - } - - pthread_t mac_rx_thread; - pthread_create(&mac_rx_thread, NULL, &mac_rx_thread_start, instance); - - instance->tx_sock = socket(AF_INET, SOCK_DGRAM, 0); - instance->tx_addr.sin_family = AF_INET; - instance->tx_addr.sin_port = htons(tx_port); - instance->tx_addr.sin_addr.s_addr = inet_addr(tx_address); - } - - - - void generate_test_subframe(mac_t *mac, uint16_t phy_id, uint16_t sfn_sf) - { - //mac_internal_t* instance = (mac_internal_t*)mac; - - uint8_t max_num_dl_pdus = 50; - nfapi_dl_config_request_pdu_t dl_config_pdus[max_num_dl_pdus]; - memset(&dl_config_pdus, 0, sizeof(dl_config_pdus)); - - nfapi_dl_config_request_t dl_config_req; - memset(&dl_config_req, 0, sizeof(dl_config_req)); - dl_config_req.header.message_id = NFAPI_DL_CONFIG_REQUEST; - dl_config_req.header.phy_id = phy_id; - dl_config_req.sfn_sf = sfn_sf; - dl_config_req.dl_config_request_body.tl.tag = NFAPI_DL_CONFIG_REQUEST_BODY_TAG; - - dl_config_req.dl_config_request_body.number_pdu = rand_range(4, max_num_dl_pdus); - - uint16_t i = 0; - for(i = 0; i < dl_config_req.dl_config_request_body.number_pdu; ++i) - { - dl_config_pdus[i].pdu_type = rand_range(0, 11); - - switch(dl_config_pdus[i].pdu_type) - { - case NFAPI_DL_CONFIG_DCI_DL_PDU_TYPE: - { - dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.tl.tag = NFAPI_DL_CONFIG_REQUEST_DCI_DL_PDU_REL8_TAG; - dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.dci_format = rand_range(0, 9); - dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.cce_idx = rand_range(0, 255); - dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level = rand_range(0, 32); - dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.rnti = rand_range(0, (uint16_t)-1); - dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.resource_allocation_type = rand_range(0, 1); - dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.virtual_resource_block_assignment_flag = rand_range(0, 1); - dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.resource_block_coding = rand_range(0, 320000); - dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.mcs_1 = rand_range(0, 31); - dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.redundancy_version_1 = rand_range(0, 3); - dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.new_data_indicator_1 = rand_range(0, 1); - dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.transport_block_to_codeword_swap_flag = rand_range(0, 1); - dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.mcs_2 = rand_range(0, 31); - dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.redundancy_version_2 = rand_range(0, 31); - dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.new_data_indicator_2 = rand_range(0, 1); - dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.harq_process = rand_range(0, 31); - dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.tpmi = rand_range(0, 15); - dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.pmi = rand_range(0, 1); - dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.precoding_information = rand_range(0, 63); - dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.tpc = rand_range(0, 3); - dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.downlink_assignment_index = rand_range(0, 15); - dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.ngap = rand_range(0, 1); - dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.transport_block_size_index = rand_range(0, 31); - dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.downlink_power_offset = rand_range(0, 1); - dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.allocate_prach_flag = rand_range(0, 1); - dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.preamble_index = rand_range(0, 63); - dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.prach_mask_index = rand_range(0, 15); - dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.rnti_type = rand_range(0, 3); - dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.transmission_power = rand_range(0, 10000); - - dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel9.tl.tag = NFAPI_DL_CONFIG_REQUEST_DCI_DL_PDU_REL9_TAG; - dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel9.mcch_flag = rand_range(0, 1); - dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel9.mcch_change_notification = rand_range(0, 255); - dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel9.scrambling_identity = rand_range(0, 1); - - dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel10.tl.tag = NFAPI_DL_CONFIG_REQUEST_DCI_DL_PDU_REL10_TAG; - dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel10.cross_carrier_scheduling_flag = rand_range(0, 1); - dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel10.carrier_indicator = rand_range(0, 7); - dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel10.srs_flag = rand_range(0, 1); - dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel10.srs_request = rand_range(0, 1); - dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel10.antenna_ports_scrambling_and_layers = rand_range(0, 15); - dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel10.total_dci_length_including_padding = rand_range(0, 255); - dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel10.n_dl_rb = rand_range(0, 100); - dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel11.tl.tag = NFAPI_DL_CONFIG_REQUEST_DCI_DL_PDU_REL11_TAG; - dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel11.harq_ack_resource_offset = rand_range(0, 3); - dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel11.pdsch_re_mapping_quasi_co_location_indicator = rand_range(0, 3); - - dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel12.tl.tag = NFAPI_DL_CONFIG_REQUEST_DCI_DL_PDU_REL12_TAG; - dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel12.primary_cell_type = rand_range(0, 2); - dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel12.ul_dl_configuration_flag = rand_range(0, 1); - dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel12.number_ul_dl_configurations = 2; - dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel12.ul_dl_configuration_indication[0] = rand_range(1, 5); - dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel12.ul_dl_configuration_indication[1] = rand_range(1, 5); - - - dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel13.tl.tag = NFAPI_DL_CONFIG_REQUEST_DCI_DL_PDU_REL13_TAG; - dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel13.laa_end_partial_sf_flag = rand_range(0, 1); - dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel13.laa_end_partial_sf_configuration = rand_range(0, 255); - dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel13.initial_lbt_sf = rand_range(0, 1); - dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel13.codebook_size_determination = rand_range(0, 1); - dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel13.drms_table_flag = rand_range(0, 1); - - // if the tpm extention is present of not. - if(rand_range(0, 1)) - { - dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel13.tpm_struct_flag = rand_range(0, 1); - dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel13.tpm.num_prb_per_subband = rand_range(0, 8); - dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel13.tpm.number_of_subbands = rand_range(0, 13); - dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel13.tpm.num_antennas = 1; // rand_range(0, 8); - - for(int j = 0; j < dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel13.tpm.number_of_subbands; ++j) - { - dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel13.tpm.subband_info[j].subband_index = j; - dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel13.tpm.subband_info[j].scheduled_ues = 1; //rand_range(1, 4); - - for(int k = 0; k < dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel13.tpm.num_antennas; ++k) - for(int l = 0; l < dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel13.tpm.subband_info[j].scheduled_ues; ++l) - dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel13.tpm.subband_info[j].precoding_value[k][l] = rand_range(0, 65535); - } - } - else - { - dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel13.tpm_struct_flag = 0; - } - - } - break; - - case NFAPI_DL_CONFIG_BCH_PDU_TYPE: - { - dl_config_pdus[i].bch_pdu.bch_pdu_rel8.tl.tag = NFAPI_DL_CONFIG_REQUEST_BCH_PDU_REL8_TAG; - dl_config_pdus[i].bch_pdu.bch_pdu_rel8.length = rand_range(0, 42); - dl_config_pdus[i].bch_pdu.bch_pdu_rel8.pdu_index = rand_range(0, 65535); - dl_config_pdus[i].bch_pdu.bch_pdu_rel8.transmission_power = rand_range(0, 10000); - } - break; - - case NFAPI_DL_CONFIG_MCH_PDU_TYPE: - { - dl_config_pdus[i].mch_pdu.mch_pdu_rel8.tl.tag = NFAPI_DL_CONFIG_REQUEST_MCH_PDU_REL8_TAG; - dl_config_pdus[i].mch_pdu.mch_pdu_rel8.length = rand_range(0, 42); - dl_config_pdus[i].mch_pdu.mch_pdu_rel8.pdu_index = rand_range(0, 65535); - dl_config_pdus[i].mch_pdu.mch_pdu_rel8.rnti = 0xFFFD; - dl_config_pdus[i].mch_pdu.mch_pdu_rel8.resource_allocation_type = 0; - dl_config_pdus[i].mch_pdu.mch_pdu_rel8.resource_block_coding = 0; - dl_config_pdus[i].mch_pdu.mch_pdu_rel8.modulation = rand_range(0, 8); - dl_config_pdus[i].mch_pdu.mch_pdu_rel8.transmission_power = rand_range(0, 10000); - dl_config_pdus[i].mch_pdu.mch_pdu_rel8.mbsfn_area_id = rand_range(0, 255); - } - break; - - case NFAPI_DL_CONFIG_DLSCH_PDU_TYPE: - { - dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.tl.tag = NFAPI_DL_CONFIG_REQUEST_DLSCH_PDU_REL8_TAG; - dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.length = rand_range(0, 42); - dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.pdu_index = rand_range(0, 65535); - dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.rnti = rand_range(1, 65535); - dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.resource_allocation_type = rand_range(0, 5); - dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.virtual_resource_block_assignment_flag = rand_range(0, 1); - dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.resource_block_coding = rand_range(0, 32000); - dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.modulation = rand_range(2, 8); - dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.redundancy_version = rand_range(0, 3); - dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.transport_blocks = rand_range(1, 2); - dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.transport_block_to_codeword_swap_flag = rand_range(0, 1); - dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.transmission_scheme = rand_range(0, 13); - dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.number_of_layers = rand_range(1, 8); - dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.number_of_subbands = 2; //rand_range(0, 13); - dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.codebook_index[0] = rand_range(0, 15); - dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.codebook_index[1] = rand_range(0, 15); - dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.ue_category_capacity = rand_range(0, 14); - dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.pa = rand_range(0, 7); - dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.delta_power_offset_index = rand_range(0, 1); - dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.ngap = rand_range(0, 1); - dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.nprb = rand_range(0, 1); - dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.transmission_mode = rand_range(1, 10); - dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.num_bf_prb_per_subband = 2; //rand_range(0, 1); - dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.num_bf_vector = 2; //rand_range(0, 1); - dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.bf_vector[0].subband_index = rand_range(0, 4); - dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.bf_vector[0].num_antennas = 1; - dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.bf_vector[0].bf_value[0] = rand_range(0, 128); - dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.bf_vector[1].subband_index = rand_range(0, 4); - dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.bf_vector[1].num_antennas = 1; - dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.bf_vector[1].bf_value[0] = rand_range(0, 128); - - dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel9.tl.tag = NFAPI_DL_CONFIG_REQUEST_DLSCH_PDU_REL9_TAG; - dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel9.nscid = rand_range(0, 1); - - dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel10.tl.tag = NFAPI_DL_CONFIG_REQUEST_DLSCH_PDU_REL10_TAG; - dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel10.csi_rs_flag = rand_range(0, 1); - dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel10.csi_rs_resource_config_r10 = 0; - dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel10.csi_rs_zero_tx_power_resource_config_bitmap_r10 = rand_range(0, 65535); - dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel10.csi_rs_number_nzp_configuration = 1; - dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel10.csi_rs_resource_config[0] = rand_range(0, 31); - dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel10.pdsch_start = rand_range(0, 4); - - dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel11.tl.tag = NFAPI_DL_CONFIG_REQUEST_DLSCH_PDU_REL11_TAG; - dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel11.drms_config_flag = rand_range(0, 1); - dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel11.drms_scrambling = rand_range(0, 503); - dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel11.csi_config_flag = rand_range(0, 1); - dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel11.csi_scrambling = rand_range(0, 503); - dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel11.pdsch_re_mapping_flag = rand_range(0, 1); - dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel11.pdsch_re_mapping_atenna_ports = rand_range(1,4); - dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel11.pdsch_re_mapping_freq_shift = rand_range(0, 5); - - dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel12.tl.tag = NFAPI_DL_CONFIG_REQUEST_DLSCH_PDU_REL12_TAG; - dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel12.altcqi_table_r12 = rand_range(0, 1); - dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel12.maxlayers = rand_range(1, 8); - dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel12.n_dl_harq = rand_range(0, 255); - - dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel13.dwpts_symbols = rand_range(3, 14); - dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel13.initial_lbt_sf = rand_range(0, 1); - dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel13.ue_type = rand_range(0, 2); - dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel13.pdsch_payload_type = rand_range(0, 2); - dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel13.initial_transmission_sf_io = rand_range(0, 10239); - dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel13.drms_table_flag = rand_range(0, 1); - } - break; - - case NFAPI_DL_CONFIG_PCH_PDU_TYPE: - { - dl_config_pdus[i].pch_pdu.pch_pdu_rel8.tl.tag = NFAPI_DL_CONFIG_REQUEST_PCH_PDU_REL8_TAG; - dl_config_pdus[i].pch_pdu.pch_pdu_rel8.length = rand_range(0, 42); - dl_config_pdus[i].pch_pdu.pch_pdu_rel8.pdu_index = rand_range(0, 65535); - dl_config_pdus[i].pch_pdu.pch_pdu_rel8.p_rnti = 0xFFFE; - dl_config_pdus[i].pch_pdu.pch_pdu_rel8.resource_allocation_type = rand_range(2, 6); - dl_config_pdus[i].pch_pdu.pch_pdu_rel8.virtual_resource_block_assignment_flag = rand_range(0, 1); - dl_config_pdus[i].pch_pdu.pch_pdu_rel8.resource_block_coding = rand_range(0, 34000); - dl_config_pdus[i].pch_pdu.pch_pdu_rel8.mcs = 0; - dl_config_pdus[i].pch_pdu.pch_pdu_rel8.redundancy_version = 0; - dl_config_pdus[i].pch_pdu.pch_pdu_rel8.number_of_transport_blocks = 1; - dl_config_pdus[i].pch_pdu.pch_pdu_rel8.transport_block_to_codeword_swap_flag = 0; - dl_config_pdus[i].pch_pdu.pch_pdu_rel8.transmission_scheme = rand_range(1, 6); - dl_config_pdus[i].pch_pdu.pch_pdu_rel8.number_of_layers = rand_range(1, 4); - dl_config_pdus[i].pch_pdu.pch_pdu_rel8.codebook_index = 0; - dl_config_pdus[i].pch_pdu.pch_pdu_rel8.ue_category_capacity = rand_range(0, 14); - dl_config_pdus[i].pch_pdu.pch_pdu_rel8.pa = rand_range(0, 7); - dl_config_pdus[i].pch_pdu.pch_pdu_rel8.transmission_power = rand_range(0, 10000); - dl_config_pdus[i].pch_pdu.pch_pdu_rel8.nprb = rand_range(0, 1); - dl_config_pdus[i].pch_pdu.pch_pdu_rel8.ngap = rand_range(0, 1); - dl_config_pdus[i].pch_pdu.pch_pdu_rel13.tl.tag = NFAPI_DL_CONFIG_REQUEST_PCH_PDU_REL13_TAG; - dl_config_pdus[i].pch_pdu.pch_pdu_rel13.ue_mode = rand_range(0, 1); - dl_config_pdus[i].pch_pdu.pch_pdu_rel13.initial_transmission_sf_io = rand_range(0, 10239); - } - break; - - case NFAPI_DL_CONFIG_PRS_PDU_TYPE: - { - dl_config_pdus[i].prs_pdu.prs_pdu_rel9.tl.tag = NFAPI_DL_CONFIG_REQUEST_PRS_PDU_REL9_TAG; - dl_config_pdus[i].prs_pdu.prs_pdu_rel9.transmission_power = rand_range(0, 10000); - dl_config_pdus[i].prs_pdu.prs_pdu_rel9.prs_bandwidth = rand_range(6, 100); - dl_config_pdus[i].prs_pdu.prs_pdu_rel9.prs_cyclic_prefix_type = rand_range(0, 1); - dl_config_pdus[i].prs_pdu.prs_pdu_rel9.prs_muting = rand_range(0, 1); - } - break; - - case NFAPI_DL_CONFIG_CSI_RS_PDU_TYPE: - { - dl_config_pdus[i].csi_rs_pdu.csi_rs_pdu_rel10.tl.tag = NFAPI_DL_CONFIG_REQUEST_CSI_RS_PDU_REL10_TAG; - dl_config_pdus[i].csi_rs_pdu.csi_rs_pdu_rel10.csi_rs_antenna_port_count_r10 = rand_range(1, 16); - dl_config_pdus[i].csi_rs_pdu.csi_rs_pdu_rel10.csi_rs_resource_config_r10 = 0; - dl_config_pdus[i].csi_rs_pdu.csi_rs_pdu_rel10.transmission_power = rand_range(0, 10000); - dl_config_pdus[i].csi_rs_pdu.csi_rs_pdu_rel10.csi_rs_zero_tx_power_resource_config_bitmap_r10 = rand_range(0, 8); - dl_config_pdus[i].csi_rs_pdu.csi_rs_pdu_rel10.csi_rs_number_of_nzp_configuration = 2; - dl_config_pdus[i].csi_rs_pdu.csi_rs_pdu_rel10.csi_rs_resource_config[0] = rand_range(0, 31); - dl_config_pdus[i].csi_rs_pdu.csi_rs_pdu_rel10.csi_rs_resource_config[1] = rand_range(0, 31); - dl_config_pdus[i].csi_rs_pdu.csi_rs_pdu_rel13.tl.tag = NFAPI_DL_CONFIG_REQUEST_CSI_RS_PDU_REL13_TAG; - dl_config_pdus[i].csi_rs_pdu.csi_rs_pdu_rel13.csi_rs_class = rand_range(0, 2); - dl_config_pdus[i].csi_rs_pdu.csi_rs_pdu_rel13.cdm_type = rand_range(0, 1); - dl_config_pdus[i].csi_rs_pdu.csi_rs_pdu_rel13.num_bf_vector = 0; // set to zero as not clear how to handle bf value array - dl_config_pdus[i].csi_rs_pdu.csi_rs_pdu_rel13.bf_vector[0].csi_rs_resource_index = rand_range(0, 7); - dl_config_pdus[i].csi_rs_pdu.csi_rs_pdu_rel13.bf_vector[0].bf_value[0] = 42; - } - break; - - case NFAPI_DL_CONFIG_EPDCCH_DL_PDU_TYPE: - { - dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.tl.tag = NFAPI_DL_CONFIG_REQUEST_EPDCCH_PDU_REL8_TAG; - dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.dci_format = rand_range(0, 9); - dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.cce_idx = rand_range(0, 255); - dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.aggregation_level = rand_range(0, 32); - dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.rnti = rand_range(0, (uint16_t)-1); - dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.resource_allocation_type = rand_range(0, 1); - dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.virtual_resource_block_assignment_flag = rand_range(0, 1); - dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.resource_block_coding = rand_range(0, 320000); - dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.mcs_1 = rand_range(0, 31); - dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.redundancy_version_1 = rand_range(0, 3); - dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.new_data_indicator_1 = rand_range(0, 1); - dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.transport_block_to_codeword_swap_flag = rand_range(0, 1); - dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.mcs_2 = rand_range(0, 31); - dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.redundancy_version_2 = rand_range(0, 31); - dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.new_data_indicator_2 = rand_range(0, 1); - dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.harq_process = rand_range(0, 31); - dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.tpmi = rand_range(0, 15); - dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.pmi = rand_range(0, 1); - dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.precoding_information = rand_range(0, 63); - dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.tpc = rand_range(0, 3); - dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.downlink_assignment_index = rand_range(0, 15); - dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.ngap = rand_range(0, 1); - dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.transport_block_size_index = rand_range(0, 31); - dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.downlink_power_offset = rand_range(0, 1); - dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.allocate_prach_flag = rand_range(0, 1); - dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.preamble_index = rand_range(0, 63); - dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.prach_mask_index = rand_range(0, 15); - dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.rnti_type = rand_range(0, 3); - dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.transmission_power = rand_range(0, 10000); - - - - dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel9.tl.tag = NFAPI_DL_CONFIG_REQUEST_EPDCCH_PDU_REL9_TAG; - dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel9.mcch_flag = rand_range(0, 1); - dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel9.mcch_change_notification = rand_range(0, 255); - dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel9.scrambling_identity = rand_range(0, 1); - - dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel10.tl.tag = NFAPI_DL_CONFIG_REQUEST_EPDCCH_PDU_REL10_TAG; - dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel10.cross_carrier_scheduling_flag = rand_range(0, 1); - dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel10.carrier_indicator = rand_range(0, 7); - dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel10.srs_flag = rand_range(0, 1); - dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel10.srs_request = rand_range(0, 1); - dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel10.antenna_ports_scrambling_and_layers = rand_range(0, 15); - dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel10.total_dci_length_including_padding = rand_range(0, 255); - dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel10.n_dl_rb = rand_range(0, 100); - - dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel11.tl.tag = NFAPI_DL_CONFIG_REQUEST_EPDCCH_PDU_REL11_TAG; - dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel11.harq_ack_resource_offset = rand_range(0, 3); - dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel11.pdsch_re_mapping_quasi_co_location_indicator = rand_range(0, 3); - - dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel12.tl.tag = NFAPI_DL_CONFIG_REQUEST_EPDCCH_PDU_REL12_TAG; - dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel12.primary_cell_type = rand_range(0, 2); - dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel12.ul_dl_configuration_flag = rand_range(0, 1); - dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel12.number_ul_dl_configurations = 2; - dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel12.ul_dl_configuration_indication[0] = rand_range(1, 5); - dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel12.ul_dl_configuration_indication[1] = rand_range(1, 5); - - dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel13.tl.tag = NFAPI_DL_CONFIG_REQUEST_EPDCCH_PDU_REL13_TAG; - dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel13.laa_end_partial_sf_flag = rand_range(0, 1); - dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel13.laa_end_partial_sf_configuration = rand_range(0, 255); - dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel13.initial_lbt_sf = rand_range(0, 1); - dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel13.codebook_size_determination = rand_range(0, 1); - dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel13.drms_table_flag = rand_range(0, 1); - - dl_config_pdus[i].epdcch_pdu.epdcch_params_rel11.tl.tag = NFAPI_DL_CONFIG_REQUEST_EPDCCH_PARAM_REL11_TAG; - dl_config_pdus[i].epdcch_pdu.epdcch_params_rel11.epdcch_resource_assignment_flag = rand_range(0, 1); - dl_config_pdus[i].epdcch_pdu.epdcch_params_rel11.epdcch_id = rand_range(0, 503); - dl_config_pdus[i].epdcch_pdu.epdcch_params_rel11.epdcch_start_symbol = rand_range(1, 4); - dl_config_pdus[i].epdcch_pdu.epdcch_params_rel11.epdcch_num_prb = rand_range(2, 8); - for(int j = 0; j < dl_config_pdus[i].epdcch_pdu.epdcch_params_rel11.epdcch_num_prb; ++j) - dl_config_pdus[i].epdcch_pdu.epdcch_params_rel11.epdcch_prb_index[j] = rand_range(0, 99); - dl_config_pdus[i].epdcch_pdu.epdcch_params_rel11.bf_vector.subband_index = rand_range(0, 25); - dl_config_pdus[i].epdcch_pdu.epdcch_params_rel11.bf_vector.num_antennas= rand_range(1, 4); - for(int j = 0; j < dl_config_pdus[i].epdcch_pdu.epdcch_params_rel11.epdcch_num_prb; ++j) - dl_config_pdus[i].epdcch_pdu.epdcch_params_rel11.bf_vector.bf_value[j] = rand_range(0, 65535); - - - dl_config_pdus[i].epdcch_pdu.epdcch_params_rel13.tl.tag = NFAPI_DL_CONFIG_REQUEST_EPDCCH_PARAM_REL13_TAG; - dl_config_pdus[i].epdcch_pdu.epdcch_params_rel13.dwpts_symbols = rand_range(3, 14); - dl_config_pdus[i].epdcch_pdu.epdcch_params_rel13.initial_lbt_sf = rand_range(0, 1); - } - break; - - case NFAPI_DL_CONFIG_MPDCCH_PDU_TYPE: - { - dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.tl.tag = NFAPI_DL_CONFIG_REQUEST_MPDCCH_PDU_REL13_TAG; - dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.mpdcch_narrow_band = rand_range(0, 15); - dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.number_of_prb_pairs = rand_range(2, 6); - dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.resource_block_assignment = rand_range(0, 14); - dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.mpdcch_tansmission_type = rand_range(0, 1); - dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.start_symbol = rand_range(1, 4); - dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.ecce_index = rand_range(0, 22); - dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.aggregation_level = rand_range(2, 24); - dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.rnti_type = rand_range(0, 4); - dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.rnti = rand_range(1, 65535); - dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.ce_mode = rand_range(1, 2); - dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.drms_scrambling_init = rand_range(0, 503); - dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.initial_transmission_sf_io = rand_range(0, 10239); - dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.transmission_power = rand_range(0, 10000); - dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.dci_format = rand_range(10, 12); - dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.resource_block_coding = rand_range(0, 0xFFFF); - dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.mcs = rand_range(0, 15); - dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.pdsch_reptition_levels = rand_range(1, 8); - dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.redundancy_version = rand_range(0, 3); - dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.new_data_indicator = rand_range(0, 1); - dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.harq_process = rand_range(0, 15); - dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.tpmi_length = rand_range(0, 4); - dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.tpmi = rand_range(0, 15); - dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.pmi_flag = rand_range(0, 1); - dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.pmi = rand_range(0, 1); - dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.harq_resource_offset = rand_range(0, 3); - dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.dci_subframe_repetition_number = rand_range(1, 4); - dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.tpc = rand_range(0, 3); - dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.downlink_assignment_index_length = rand_range(0, 4); - dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.downlink_assignment_index = rand_range(0, 15); - dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.allocate_prach_flag = rand_range(0, 63); - dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.preamble_index = rand_range(0, 15); - dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.prach_mask_index = rand_range(0, 3); - dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.starting_ce_level = rand_range(0, 1); - dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.srs_request = rand_range(0, 1); - dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.antenna_ports_and_scrambling_identity_flag = rand_range(0, 1); - dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.antenna_ports_and_scrambling_identity = rand_range(0, 3); - dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.frequency_hopping_enabled_flag = rand_range(0, 1); - dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.paging_direct_indication_differentiation_flag = rand_range(0, 1); - dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.direct_indication = rand_range(0, 255); - dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.total_dci_length_including_padding = rand_range(0, 1); - dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.number_of_tx_antenna_ports = rand_range(0, 8); - for(int j = 0 ; j < dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.number_of_tx_antenna_ports; ++j) - dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.precoding_value[j] = rand_range(0, 65535); - } - break; - - case NFAPI_DL_CONFIG_NBCH_PDU_TYPE: - { - dl_config_pdus[i].nbch_pdu.nbch_pdu_rel13.tl.tag = NFAPI_DL_CONFIG_REQUEST_NBCH_PDU_REL13_TAG; - dl_config_pdus[i].nbch_pdu.nbch_pdu_rel13.length = rand_range(0, 5555); - dl_config_pdus[i].nbch_pdu.nbch_pdu_rel13.pdu_index = rand_range(0, 65535); - dl_config_pdus[i].nbch_pdu.nbch_pdu_rel13.transmission_power = rand_range(0, 10000); - dl_config_pdus[i].nbch_pdu.nbch_pdu_rel13.hyper_sfn_2_lsbs = rand_range(0, 3); - } - break; - - case NFAPI_DL_CONFIG_NPDCCH_PDU_TYPE: - { - dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.tl.tag = NFAPI_DL_CONFIG_REQUEST_NPDCCH_PDU_REL13_TAG; - dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.length = rand_range(0, 5555); - dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.pdu_index = rand_range(0, 65535); - dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.ncce_index = rand_range(0, 1); - dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.aggregation_level = rand_range(1, 2); - dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.start_symbol = rand_range(0, 4); - dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.rnti_type = rand_range(0, 3); - dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.rnti = rand_range(1, 65535); - dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.scrambling_reinitialization_batch_index = rand_range(1, 4); - dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.nrs_antenna_ports_assumed_by_the_ue = rand_range(1, 2); - dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.dci_format = rand_range(0, 1); - dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.scheduling_delay = rand_range(0, 7); - dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.resource_assignment = rand_range(0, 7); - dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.repetition_number = rand_range(0, 15); - dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.mcs = rand_range(0, 13); - dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.new_data_indicator = rand_range(0, 1); - dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.harq_ack_resource = rand_range(0, 15); - dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.npdcch_order_indication = rand_range(0, 1); - dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.starting_number_of_nprach_repetitions = rand_range(0, 3); - dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.subcarrier_indication_of_nprach = rand_range(0, 63); - dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.paging_direct_indication_differentation_flag = rand_range(0, 1); - dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.direct_indication = rand_range(0, 255); - dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.dci_subframe_repetition_number = rand_range(0, 7); - dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.total_dci_length_including_padding = rand_range(0, 255); - } - break; - - case NFAPI_DL_CONFIG_NDLSCH_PDU_TYPE: - { - dl_config_pdus[i].ndlsch_pdu.ndlsch_pdu_rel13.tl.tag = NFAPI_DL_CONFIG_REQUEST_NDLSCH_PDU_REL13_TAG; - dl_config_pdus[i].ndlsch_pdu.ndlsch_pdu_rel13.length = rand_range(0, 5555); - dl_config_pdus[i].ndlsch_pdu.ndlsch_pdu_rel13.pdu_index = rand_range(0, 65535); - dl_config_pdus[i].ndlsch_pdu.ndlsch_pdu_rel13.start_symbol = rand_range(0, 4); - dl_config_pdus[i].ndlsch_pdu.ndlsch_pdu_rel13.rnti_type = rand_range(0, 1); - dl_config_pdus[i].ndlsch_pdu.ndlsch_pdu_rel13.rnti = rand_range(1, 65535); - dl_config_pdus[i].ndlsch_pdu.ndlsch_pdu_rel13.resource_assignment = rand_range(0, 7); - dl_config_pdus[i].ndlsch_pdu.ndlsch_pdu_rel13.repetition_number = rand_range(0, 15); - dl_config_pdus[i].ndlsch_pdu.ndlsch_pdu_rel13.modulation = 2; - dl_config_pdus[i].ndlsch_pdu.ndlsch_pdu_rel13.number_of_subframes_for_resource_assignment = rand_range(1, 10); - dl_config_pdus[i].ndlsch_pdu.ndlsch_pdu_rel13.scrambling_sequence_initialization_cinit = rand_range(0, 65535); - dl_config_pdus[i].ndlsch_pdu.ndlsch_pdu_rel13.sf_idx = rand_range(1, 10240); - dl_config_pdus[i].ndlsch_pdu.ndlsch_pdu_rel13.nrs_antenna_ports_assumed_by_the_ue = rand_range(1, 2); - } - break; - - }; - } - - - dl_config_req.dl_config_request_body.dl_config_pdu_list = dl_config_pdus; - mac->dl_config_req(mac, &dl_config_req); - - uint8_t num_ul_pdus = 18; - nfapi_ul_config_request_pdu_t ul_config_pdus[num_ul_pdus]; - memset(&ul_config_pdus, 0, sizeof(ul_config_pdus)); - - nfapi_ul_config_request_t ul_config_req; - memset(&ul_config_req, 0, sizeof(ul_config_req)); - ul_config_req.header.message_id = NFAPI_UL_CONFIG_REQUEST; - ul_config_req.header.phy_id = phy_id; - ul_config_req.sfn_sf = sfn_sf; - ul_config_req.ul_config_request_body.tl.tag = NFAPI_UL_CONFIG_REQUEST_BODY_TAG; - ul_config_req.ul_config_request_body.number_of_pdus = num_ul_pdus; - ul_config_req.ul_config_request_body.rach_prach_frequency_resources = rand_range(0, 255); - ul_config_req.ul_config_request_body.srs_present = rand_range(0, 1); - - auto ul_config_ulsch_pdu_test_gen = [](nfapi_ul_config_ulsch_pdu& ulsch_pdu) - { - ulsch_pdu.ulsch_pdu_rel8.tl.tag = NFAPI_UL_CONFIG_REQUEST_ULSCH_PDU_REL8_TAG; - ulsch_pdu.ulsch_pdu_rel8.handle = rand_range(0, 50000); - ulsch_pdu.ulsch_pdu_rel8.size = rand_range(0, 32000); - ulsch_pdu.ulsch_pdu_rel8.rnti = rand_range(1, 65535); - ulsch_pdu.ulsch_pdu_rel8.resource_block_start = rand_range(0, 99); - ulsch_pdu.ulsch_pdu_rel8.number_of_resource_blocks = rand_range(1, 100); - ulsch_pdu.ulsch_pdu_rel8.modulation_type = rand_range(2, 6); - ulsch_pdu.ulsch_pdu_rel8.cyclic_shift_2_for_drms = rand_range(0, 7); - ulsch_pdu.ulsch_pdu_rel8.frequency_hopping_enabled_flag = rand_range(0, 1); - ulsch_pdu.ulsch_pdu_rel8.frequency_hopping_bits = rand_range(0, 3); - ulsch_pdu.ulsch_pdu_rel8.new_data_indication = rand_range(0, 1); - ulsch_pdu.ulsch_pdu_rel8.redundancy_version = rand_range(0, 3); - ulsch_pdu.ulsch_pdu_rel8.harq_process_number = rand_range(0, 15); - ulsch_pdu.ulsch_pdu_rel8.ul_tx_mode = rand_range(0, 1); - ulsch_pdu.ulsch_pdu_rel8.current_tx_nb = rand_range(0, 5); - ulsch_pdu.ulsch_pdu_rel8.n_srs = rand_range(0, 1); - ulsch_pdu.ulsch_pdu_rel10.tl.tag = NFAPI_UL_CONFIG_REQUEST_ULSCH_PDU_REL10_TAG; - ulsch_pdu.ulsch_pdu_rel10.resource_allocation_type = rand_range(0, 1); - ulsch_pdu.ulsch_pdu_rel10.resource_block_coding = rand_range(0, 35000); - ulsch_pdu.ulsch_pdu_rel10.transport_blocks = rand_range(1, 2); - ulsch_pdu.ulsch_pdu_rel10.transmission_scheme = rand_range(0, 1); - ulsch_pdu.ulsch_pdu_rel10.number_of_layers = rand_range(1, 4); - ulsch_pdu.ulsch_pdu_rel10.codebook_index = rand_range(0, 23); - ulsch_pdu.ulsch_pdu_rel10.disable_sequence_hopping_flag = rand_range(0, 1); - ulsch_pdu.ulsch_pdu_rel11.tl.tag = NFAPI_UL_CONFIG_REQUEST_ULSCH_PDU_REL11_TAG; - ulsch_pdu.ulsch_pdu_rel11.virtual_cell_id_enabled_flag = rand_range(0, 1); - ulsch_pdu.ulsch_pdu_rel11.npusch_identity = rand_range(0, 509); - ulsch_pdu.ulsch_pdu_rel11.dmrs_config_flag = rand_range(0, 1); - ulsch_pdu.ulsch_pdu_rel11.ndmrs_csh_identity = rand_range(0, 509); - ulsch_pdu.ulsch_pdu_rel13.tl.tag = NFAPI_UL_CONFIG_REQUEST_ULSCH_PDU_REL13_TAG; - ulsch_pdu.ulsch_pdu_rel13.ue_type = rand_range(0, 2); - ulsch_pdu.ulsch_pdu_rel13.total_number_of_repetitions = rand_range(1, 2048); - ulsch_pdu.ulsch_pdu_rel13.repetition_number = rand_range(1, 2048); - ulsch_pdu.ulsch_pdu_rel13.initial_transmission_sf_io = rand_range(0, 10239); - ulsch_pdu.ulsch_pdu_rel13.empty_symbols_due_to_re_tunning = rand_range(0, 8); - }; - - auto ul_config_cqi_ri_info_test_gen = [](nfapi_ul_config_cqi_ri_information& cqi_ri_information) - { - cqi_ri_information.cqi_ri_information_rel8.tl.tag = NFAPI_UL_CONFIG_REQUEST_CQI_RI_INFORMATION_REL8_TAG; - cqi_ri_information.cqi_ri_information_rel8.dl_cqi_pmi_size_rank_1 = rand_range(0, 255); - cqi_ri_information.cqi_ri_information_rel8.dl_cqi_pmi_size_rank_greater_1 = rand_range(0, 255); - cqi_ri_information.cqi_ri_information_rel8.ri_size = rand_range(0, 3); - cqi_ri_information.cqi_ri_information_rel8.delta_offset_cqi = rand_range(0, 15); - cqi_ri_information.cqi_ri_information_rel8.delta_offset_ri = rand_range(0, 15); - - cqi_ri_information.cqi_ri_information_rel9.tl.tag = NFAPI_UL_CONFIG_REQUEST_CQI_RI_INFORMATION_REL9_TAG; - cqi_ri_information.cqi_ri_information_rel9.report_type = 1; // rand_range(0, 1); - cqi_ri_information.cqi_ri_information_rel9.delta_offset_cqi = rand_range(0, 15); - cqi_ri_information.cqi_ri_information_rel9.delta_offset_ri = rand_range(0, 15); - - if(cqi_ri_information.cqi_ri_information_rel9.report_type == 0) - { - cqi_ri_information.cqi_ri_information_rel9.periodic_cqi_pmi_ri_report.dl_cqi_pmi_ri_size = rand_range(0, 255); - cqi_ri_information.cqi_ri_information_rel9.periodic_cqi_pmi_ri_report.control_type = rand_range(0, 1); - } - else - { - cqi_ri_information.cqi_ri_information_rel9.aperiodic_cqi_pmi_ri_report.number_of_cc = 1; - cqi_ri_information.cqi_ri_information_rel9.aperiodic_cqi_pmi_ri_report.cc[0].ri_size = rand_range(0, 3); - cqi_ri_information.cqi_ri_information_rel9.aperiodic_cqi_pmi_ri_report.cc[0].dl_cqi_pmi_size[0] = rand_range(0, 255); - } - - cqi_ri_information.cqi_ri_information_rel13.tl.tag = NFAPI_UL_CONFIG_REQUEST_CQI_RI_INFORMATION_REL13_TAG; - cqi_ri_information.cqi_ri_information_rel13.report_type = rand_range(0, 1); - - if(cqi_ri_information.cqi_ri_information_rel13.report_type == 0) - { - cqi_ri_information.cqi_ri_information_rel13.periodic_cqi_pmi_ri_report.dl_cqi_pmi_ri_size_2 = rand_range(255, 10000); - } - }; - - auto ul_config_init_tx_params_test_gen = [](nfapi_ul_config_initial_transmission_parameters& initial_transmission_parameters) - { - initial_transmission_parameters.initial_transmission_parameters_rel8.tl.tag = NFAPI_UL_CONFIG_REQUEST_INITIAL_TRANSMISSION_PARAMETERS_REL8_TAG; - initial_transmission_parameters.initial_transmission_parameters_rel8.n_srs_initial = rand_range(0, 1); - initial_transmission_parameters.initial_transmission_parameters_rel8.initial_number_of_resource_blocks = rand_range(1, 100); - }; - - auto ul_config_harqinfo_test_gen = [](nfapi_ul_config_ulsch_harq_information& harq_information) - { - harq_information.harq_information_rel10.tl.tag = NFAPI_UL_CONFIG_REQUEST_ULSCH_HARQ_INFORMATION_REL10_TAG; - harq_information.harq_information_rel10.harq_size = rand_range(0, 21); - harq_information.harq_information_rel10.delta_offset_harq = rand_range(0, 15); - harq_information.harq_information_rel10.ack_nack_mode = rand_range(0, 5); - harq_information.harq_information_rel13.tl.tag = NFAPI_UL_CONFIG_REQUEST_ULSCH_HARQ_INFORMATION_REL13_TAG; - harq_information.harq_information_rel13.harq_size_2 = rand_range(0, 21); - harq_information.harq_information_rel13.delta_offset_harq_2 = rand_range(0, 15); - }; - - auto ul_config_sr_info_test_gen = [](nfapi_ul_config_sr_information& sr_info) - { - sr_info.sr_information_rel8.tl.tag = NFAPI_UL_CONFIG_REQUEST_SR_INFORMATION_REL8_TAG; - sr_info.sr_information_rel8.pucch_index = rand_range(0, 2047); - sr_info.sr_information_rel10.tl.tag = NFAPI_UL_CONFIG_REQUEST_SR_INFORMATION_REL10_TAG; - sr_info.sr_information_rel10.number_of_pucch_resources = rand_range(1, 2); - sr_info.sr_information_rel10.pucch_index_p1 = rand_range(0, 2047); - }; - - auto ul_config_ue_info_test_gen = [](nfapi_ul_config_ue_information& ue_information) - { - ue_information.ue_information_rel8.tl.tag = NFAPI_UL_CONFIG_REQUEST_UE_INFORMATION_REL8_TAG; - ue_information.ue_information_rel8.handle = rand_range(0, 99999); - ue_information.ue_information_rel8.rnti = rand_range(1, 65535); - ue_information.ue_information_rel11.tl.tag = NFAPI_UL_CONFIG_REQUEST_UE_INFORMATION_REL11_TAG; - ue_information.ue_information_rel11.virtual_cell_id_enabled_flag = rand_range(0, 1); - ue_information.ue_information_rel11.npusch_identity = rand_range(0, 503); - ue_information.ue_information_rel13.tl.tag = NFAPI_UL_CONFIG_REQUEST_UE_INFORMATION_REL13_TAG; - ue_information.ue_information_rel13.ue_type = rand_range(0, 2); - ue_information.ue_information_rel13.empty_symbols = rand_range(0, 2); - ue_information.ue_information_rel13.total_number_of_repetitions = rand_range(1, 32); - ue_information.ue_information_rel13.repetition_number = rand_range(1, 32); - }; - - auto ul_config_cqi_info_test_gen = [](nfapi_ul_config_cqi_information& cqi_information) - { - cqi_information.cqi_information_rel8.tl.tag = NFAPI_UL_CONFIG_REQUEST_CQI_INFORMATION_REL8_TAG; - cqi_information.cqi_information_rel8.pucch_index = rand_range(0, 1184); - cqi_information.cqi_information_rel8.dl_cqi_pmi_size = rand_range(0, 255); - cqi_information.cqi_information_rel10.tl.tag = NFAPI_UL_CONFIG_REQUEST_CQI_INFORMATION_REL10_TAG; - cqi_information.cqi_information_rel10.number_of_pucch_resource = rand_range(1, 2); - cqi_information.cqi_information_rel10.pucch_index_p1 = rand_range(0, 1184); - cqi_information.cqi_information_rel13.tl.tag = NFAPI_UL_CONFIG_REQUEST_CQI_INFORMATION_REL13_TAG; - cqi_information.cqi_information_rel13.csi_mode = rand_range(0, 2); - cqi_information.cqi_information_rel13.dl_cqi_pmi_size_2 = rand_range(0, 999); - cqi_information.cqi_information_rel13.starting_prb = rand_range(0, 109); - cqi_information.cqi_information_rel13.n_prb = rand_range(0, 7); - cqi_information.cqi_information_rel13.cdm_index = rand_range(0, 1); - cqi_information.cqi_information_rel13.n_srs = rand_range(0, 1); - }; - - auto ul_config_harq_info_test_gen = [](nfapi_ul_config_harq_information& harq_information) - { - harq_information.harq_information_rel10_tdd.tl.tag = NFAPI_UL_CONFIG_REQUEST_HARQ_INFORMATION_REL10_TDD_TAG; - harq_information.harq_information_rel10_tdd.harq_size = rand_range(0, 21); - harq_information.harq_information_rel10_tdd.ack_nack_mode = rand_range(0, 5); - harq_information.harq_information_rel10_tdd.number_of_pucch_resources = rand_range(0, 4); - harq_information.harq_information_rel10_tdd.n_pucch_1_0 = rand_range(0, 2047); - harq_information.harq_information_rel10_tdd.n_pucch_1_1 = rand_range(0, 2047); - harq_information.harq_information_rel10_tdd.n_pucch_1_2 = rand_range(0, 2047); - harq_information.harq_information_rel10_tdd.n_pucch_1_3 = rand_range(0, 2047); - harq_information.harq_information_rel8_fdd.tl.tag = NFAPI_UL_CONFIG_REQUEST_HARQ_INFORMATION_REL8_FDD_TAG; - harq_information.harq_information_rel8_fdd.n_pucch_1_0 = rand_range(0, 2047); - harq_information.harq_information_rel8_fdd.harq_size = rand_range(1, 2); - harq_information.harq_information_rel9_fdd.tl.tag = NFAPI_UL_CONFIG_REQUEST_HARQ_INFORMATION_REL9_FDD_TAG; - harq_information.harq_information_rel9_fdd.harq_size = rand_range(1, 10); - harq_information.harq_information_rel9_fdd.ack_nack_mode = rand_range(0, 4); - harq_information.harq_information_rel9_fdd.number_of_pucch_resources = rand_range(0, 4); - harq_information.harq_information_rel9_fdd.n_pucch_1_0 = rand_range(0, 2047); - harq_information.harq_information_rel9_fdd.n_pucch_1_1 = rand_range(0, 2047); - harq_information.harq_information_rel9_fdd.n_pucch_1_2 = rand_range(0, 2047); - harq_information.harq_information_rel9_fdd.n_pucch_1_3 = rand_range(0, 2047); - harq_information.harq_information_rel11.tl.tag = NFAPI_UL_CONFIG_REQUEST_HARQ_INFORMATION_REL11_TAG; - harq_information.harq_information_rel11.num_ant_ports = rand_range(1, 2); - harq_information.harq_information_rel11.n_pucch_2_0 = rand_range(0, 2047); - harq_information.harq_information_rel11.n_pucch_2_1 = rand_range(0, 2047); - harq_information.harq_information_rel11.n_pucch_2_2 = rand_range(0, 2047); - harq_information.harq_information_rel11.n_pucch_2_3 = rand_range(0, 2047); - harq_information.harq_information_rel13.tl.tag = NFAPI_UL_CONFIG_REQUEST_HARQ_INFORMATION_REL13_TAG; - harq_information.harq_information_rel13.harq_size_2 = rand_range(0, 999); - harq_information.harq_information_rel13.starting_prb = rand_range(0, 109); - harq_information.harq_information_rel13.n_prb = rand_range(0, 7); - harq_information.harq_information_rel13.cdm_index = rand_range(0, 1); - harq_information.harq_information_rel13.n_srs = rand_range(0, 1); - }; - - - ul_config_pdus[0].pdu_type = NFAPI_UL_CONFIG_ULSCH_PDU_TYPE; - ul_config_ulsch_pdu_test_gen(ul_config_pdus[0].ulsch_pdu); - - ul_config_pdus[1].pdu_type = NFAPI_UL_CONFIG_ULSCH_CQI_RI_PDU_TYPE; - ul_config_ulsch_pdu_test_gen(ul_config_pdus[1].ulsch_cqi_ri_pdu.ulsch_pdu); - ul_config_cqi_ri_info_test_gen(ul_config_pdus[1].ulsch_cqi_ri_pdu.cqi_ri_information); - ul_config_init_tx_params_test_gen(ul_config_pdus[1].ulsch_cqi_ri_pdu.initial_transmission_parameters); - - ul_config_pdus[2].pdu_type = NFAPI_UL_CONFIG_ULSCH_HARQ_PDU_TYPE; - ul_config_ulsch_pdu_test_gen(ul_config_pdus[2].ulsch_harq_pdu.ulsch_pdu); - ul_config_harqinfo_test_gen(ul_config_pdus[2].ulsch_harq_pdu.harq_information); - ul_config_init_tx_params_test_gen(ul_config_pdus[2].ulsch_harq_pdu.initial_transmission_parameters); - - ul_config_pdus[3].pdu_type = NFAPI_UL_CONFIG_ULSCH_CQI_HARQ_RI_PDU_TYPE; - ul_config_ulsch_pdu_test_gen(ul_config_pdus[3].ulsch_cqi_harq_ri_pdu.ulsch_pdu); - ul_config_cqi_ri_info_test_gen(ul_config_pdus[3].ulsch_cqi_harq_ri_pdu.cqi_ri_information); - ul_config_harqinfo_test_gen(ul_config_pdus[3].ulsch_cqi_harq_ri_pdu.harq_information); - ul_config_init_tx_params_test_gen(ul_config_pdus[3].ulsch_cqi_harq_ri_pdu.initial_transmission_parameters); - - - ul_config_pdus[4].pdu_type = NFAPI_UL_CONFIG_UCI_CQI_PDU_TYPE; - ul_config_ue_info_test_gen(ul_config_pdus[4].uci_cqi_pdu.ue_information); - ul_config_cqi_info_test_gen(ul_config_pdus[4].uci_cqi_pdu.cqi_information); - - ul_config_pdus[5].pdu_type = NFAPI_UL_CONFIG_UCI_SR_PDU_TYPE; - ul_config_ue_info_test_gen(ul_config_pdus[5].uci_sr_pdu.ue_information); - ul_config_sr_info_test_gen(ul_config_pdus[5].uci_sr_pdu.sr_information); - - - ul_config_pdus[6].pdu_type = NFAPI_UL_CONFIG_UCI_HARQ_PDU_TYPE; - ul_config_ue_info_test_gen(ul_config_pdus[6].uci_harq_pdu.ue_information); - ul_config_harq_info_test_gen(ul_config_pdus[6].uci_harq_pdu.harq_information); - - - ul_config_pdus[7].pdu_type = NFAPI_UL_CONFIG_UCI_SR_HARQ_PDU_TYPE; - ul_config_ue_info_test_gen(ul_config_pdus[7].uci_sr_harq_pdu.ue_information); - ul_config_sr_info_test_gen(ul_config_pdus[7].uci_sr_harq_pdu.sr_information); - ul_config_harq_info_test_gen(ul_config_pdus[7].uci_sr_harq_pdu.harq_information); - - ul_config_pdus[8].pdu_type = NFAPI_UL_CONFIG_UCI_CQI_HARQ_PDU_TYPE; - ul_config_ue_info_test_gen(ul_config_pdus[8].uci_cqi_harq_pdu.ue_information); - ul_config_cqi_info_test_gen(ul_config_pdus[8].uci_cqi_harq_pdu.cqi_information); - ul_config_harq_info_test_gen(ul_config_pdus[8].uci_cqi_harq_pdu.harq_information); - - ul_config_pdus[9].pdu_type = NFAPI_UL_CONFIG_UCI_CQI_SR_PDU_TYPE; - ul_config_ue_info_test_gen(ul_config_pdus[9].uci_cqi_sr_pdu.ue_information); - ul_config_cqi_info_test_gen(ul_config_pdus[9].uci_cqi_sr_pdu.cqi_information); - ul_config_sr_info_test_gen(ul_config_pdus[9].uci_cqi_sr_pdu.sr_information); - - ul_config_pdus[10].pdu_type = NFAPI_UL_CONFIG_UCI_CQI_SR_HARQ_PDU_TYPE; - ul_config_ue_info_test_gen(ul_config_pdus[10].uci_cqi_sr_harq_pdu.ue_information); - ul_config_cqi_info_test_gen(ul_config_pdus[10].uci_cqi_sr_harq_pdu.cqi_information); - ul_config_sr_info_test_gen(ul_config_pdus[10].uci_cqi_sr_harq_pdu.sr_information); - ul_config_harq_info_test_gen(ul_config_pdus[10].uci_cqi_sr_harq_pdu.harq_information); - - ul_config_pdus[11].pdu_type = NFAPI_UL_CONFIG_SRS_PDU_TYPE; - ul_config_pdus[11].srs_pdu.srs_pdu_rel8.tl.tag = NFAPI_UL_CONFIG_REQUEST_SRS_PDU_REL8_TAG; - ul_config_pdus[11].srs_pdu.srs_pdu_rel8.handle = rand_range(0, 9999); - ul_config_pdus[11].srs_pdu.srs_pdu_rel8.size = rand_range(1, 999); - ul_config_pdus[11].srs_pdu.srs_pdu_rel8.rnti = rand_range(1, 65535); - ul_config_pdus[11].srs_pdu.srs_pdu_rel8.srs_bandwidth = rand_range(0, 3); - ul_config_pdus[11].srs_pdu.srs_pdu_rel8.frequency_domain_position = rand_range(0, 23); - ul_config_pdus[11].srs_pdu.srs_pdu_rel8.srs_hopping_bandwidth = rand_range(0, 3); - ul_config_pdus[11].srs_pdu.srs_pdu_rel8.transmission_comb = rand_range(0, 3); - ul_config_pdus[11].srs_pdu.srs_pdu_rel8.i_srs = rand_range(0, 1023); - ul_config_pdus[11].srs_pdu.srs_pdu_rel8.sounding_reference_cyclic_shift = rand_range(0, 11); - ul_config_pdus[11].srs_pdu.srs_pdu_rel10.tl.tag = NFAPI_UL_CONFIG_REQUEST_SRS_PDU_REL10_TAG; - ul_config_pdus[11].srs_pdu.srs_pdu_rel10.antenna_port = rand_range(0, 2); - ul_config_pdus[11].srs_pdu.srs_pdu_rel13.tl.tag = NFAPI_UL_CONFIG_REQUEST_SRS_PDU_REL13_TAG; - ul_config_pdus[11].srs_pdu.srs_pdu_rel13.number_of_combs = rand_range(0, 1); - - ul_config_pdus[12].pdu_type = NFAPI_UL_CONFIG_HARQ_BUFFER_PDU_TYPE; - ul_config_ue_info_test_gen(ul_config_pdus[12].harq_buffer_pdu.ue_information); - - ul_config_pdus[13].pdu_type = NFAPI_UL_CONFIG_ULSCH_UCI_CSI_PDU_TYPE; - ul_config_ulsch_pdu_test_gen(ul_config_pdus[13].ulsch_uci_csi_pdu.ulsch_pdu); - ul_config_cqi_info_test_gen(ul_config_pdus[13].ulsch_uci_csi_pdu.csi_information); - - ul_config_pdus[14].pdu_type = NFAPI_UL_CONFIG_ULSCH_UCI_HARQ_PDU_TYPE; - ul_config_ulsch_pdu_test_gen(ul_config_pdus[14].ulsch_uci_harq_pdu.ulsch_pdu); - ul_config_harq_info_test_gen(ul_config_pdus[14].ulsch_uci_harq_pdu.harq_information); - - ul_config_pdus[15].pdu_type = NFAPI_UL_CONFIG_ULSCH_CSI_UCI_HARQ_PDU_TYPE; - ul_config_ulsch_pdu_test_gen(ul_config_pdus[15].ulsch_csi_uci_harq_pdu.ulsch_pdu); - ul_config_cqi_info_test_gen(ul_config_pdus[15].ulsch_csi_uci_harq_pdu.csi_information); - ul_config_harq_info_test_gen(ul_config_pdus[15].ulsch_csi_uci_harq_pdu.harq_information); - - ul_config_pdus[16].pdu_type = NFAPI_UL_CONFIG_NULSCH_PDU_TYPE; - ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.tl.tag = NFAPI_UL_CONFIG_REQUEST_NULSCH_PDU_REL13_TAG; - ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.nulsch_format = rand_range(0, 1); - ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.handle = rand_range(0, 0xFFFF); - ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.size = rand_range(0, 65535); - ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.rnti = rand_range(1, 65535); - ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.subcarrier_indication = rand_range(0, 47); - ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.resource_assignment = rand_range(0, 7); - ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.mcs = rand_range(0, 12); - ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.redudancy_version = rand_range(0, 1); - ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.repetition_number = rand_range(0, 7); - ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.new_data_indication = rand_range(0, 1); - ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.n_srs = rand_range(0, 1); - ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.scrambling_sequence_initialization_cinit = rand_range(0, 65535); - ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.sf_idx = rand_range(0, 40960); - - ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.ue_information.ue_information_rel8.tl.tag = NFAPI_UL_CONFIG_REQUEST_UE_INFORMATION_REL8_TAG; - ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.ue_information.ue_information_rel8.handle = rand_range(0, 0xFF); - ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.ue_information.ue_information_rel8.rnti = rand_range(1, 65535); - ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.ue_information.ue_information_rel11.tl.tag = NFAPI_UL_CONFIG_REQUEST_UE_INFORMATION_REL11_TAG; - ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.ue_information.ue_information_rel11.virtual_cell_id_enabled_flag = rand_range(0, 1); - ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.ue_information.ue_information_rel11.npusch_identity = rand_range(0, 503); - ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.ue_information.ue_information_rel13.tl.tag = NFAPI_UL_CONFIG_REQUEST_UE_INFORMATION_REL13_TAG; - ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.ue_information.ue_information_rel13.ue_type = rand_range(0, 2); - ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.ue_information.ue_information_rel13.empty_symbols = rand_range(0, 0x3); - ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.ue_information.ue_information_rel13.total_number_of_repetitions = rand_range(1, 32); - ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.ue_information.ue_information_rel13.repetition_number = rand_range(1, 32); - - ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.nb_harq_information.nb_harq_information_rel13_fdd.tl.tag = NFAPI_UL_CONFIG_REQUEST_NB_HARQ_INFORMATION_REL13_FDD_TAG; - ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.nb_harq_information.nb_harq_information_rel13_fdd.harq_ack_resource = rand_range(0, 15); - - ul_config_pdus[17].pdu_type = NFAPI_UL_CONFIG_NRACH_PDU_TYPE; - ul_config_pdus[17].nrach_pdu.nrach_pdu_rel13.tl.tag = NFAPI_UL_CONFIG_REQUEST_NRACH_PDU_REL13_TAG; - ul_config_pdus[17].nrach_pdu.nrach_pdu_rel13.nprach_config_0 = rand_range(0, 1); - ul_config_pdus[17].nrach_pdu.nrach_pdu_rel13.nprach_config_1 = rand_range(0, 1); - ul_config_pdus[17].nrach_pdu.nrach_pdu_rel13.nprach_config_2 = rand_range(0, 1); - - ul_config_req.ul_config_request_body.ul_config_pdu_list = ul_config_pdus; - mac->ul_config_req(mac, &ul_config_req); - - - uint8_t num_dci_pdus = 4; - uint8_t num_hi_pdus = 1; - nfapi_hi_dci0_request_pdu_t hi_dci0_pdus[num_dci_pdus + num_hi_pdus]; - memset(&hi_dci0_pdus, 0, sizeof(hi_dci0_pdus)); - - nfapi_hi_dci0_request_t hi_dci0_req; - memset(&hi_dci0_req, 0, sizeof(hi_dci0_req)); - hi_dci0_req.header.message_id = NFAPI_HI_DCI0_REQUEST; - hi_dci0_req.header.phy_id = phy_id; - hi_dci0_req.sfn_sf = sfn_sf; - - hi_dci0_req.hi_dci0_request_body.tl.tag = NFAPI_HI_DCI0_REQUEST_BODY_TAG; - hi_dci0_req.hi_dci0_request_body.sfnsf = sfn_sf; - hi_dci0_req.hi_dci0_request_body.number_of_dci = num_dci_pdus; - hi_dci0_req.hi_dci0_request_body.number_of_hi = num_hi_pdus; - - hi_dci0_pdus[0].pdu_type = NFAPI_HI_DCI0_HI_PDU_TYPE; - hi_dci0_pdus[0].hi_pdu.hi_pdu_rel8.tl.tag = NFAPI_HI_DCI0_REQUEST_HI_PDU_REL8_TAG; - hi_dci0_pdus[0].hi_pdu.hi_pdu_rel8.resource_block_start = rand_range(0, 100); - hi_dci0_pdus[0].hi_pdu.hi_pdu_rel8.cyclic_shift_2_for_drms = rand_range(0, 7); - hi_dci0_pdus[0].hi_pdu.hi_pdu_rel8.hi_value = rand_range(0, 1); - hi_dci0_pdus[0].hi_pdu.hi_pdu_rel8.i_phich = rand_range(0, 1); - hi_dci0_pdus[0].hi_pdu.hi_pdu_rel8.transmission_power = rand_range(0, 10000); - hi_dci0_pdus[0].hi_pdu.hi_pdu_rel10.tl.tag = NFAPI_HI_DCI0_REQUEST_HI_PDU_REL10_TAG; - hi_dci0_pdus[0].hi_pdu.hi_pdu_rel10.flag_tb2 = rand_range(0, 1); - hi_dci0_pdus[0].hi_pdu.hi_pdu_rel10.hi_value_2 = rand_range(0, 1); - - hi_dci0_pdus[1].pdu_type = NFAPI_HI_DCI0_DCI_PDU_TYPE; - hi_dci0_pdus[1].dci_pdu.dci_pdu_rel8.tl.tag = NFAPI_HI_DCI0_REQUEST_DCI_PDU_REL8_TAG; - hi_dci0_pdus[1].dci_pdu.dci_pdu_rel8.dci_format = rand_range(0, 4); - hi_dci0_pdus[1].dci_pdu.dci_pdu_rel8.cce_index = rand_range(0, 88); - hi_dci0_pdus[1].dci_pdu.dci_pdu_rel8.aggregation_level = rand_range(1, 8); - hi_dci0_pdus[1].dci_pdu.dci_pdu_rel8.rnti = rand_range(1, 65535); - hi_dci0_pdus[1].dci_pdu.dci_pdu_rel8.resource_block_start = rand_range(0, 100); - hi_dci0_pdus[1].dci_pdu.dci_pdu_rel8.number_of_resource_block = rand_range(0, 100); - hi_dci0_pdus[1].dci_pdu.dci_pdu_rel8.mcs_1 = rand_range(0, 31); - hi_dci0_pdus[1].dci_pdu.dci_pdu_rel8.cyclic_shift_2_for_drms = rand_range(0, 7); - hi_dci0_pdus[1].dci_pdu.dci_pdu_rel8.frequency_hopping_enabled_flag = rand_range(0, 1); - hi_dci0_pdus[1].dci_pdu.dci_pdu_rel8.frequency_hopping_bits = rand_range(0, 3); - hi_dci0_pdus[1].dci_pdu.dci_pdu_rel8.new_data_indication_1 = rand_range(0, 1); - hi_dci0_pdus[1].dci_pdu.dci_pdu_rel8.ue_tx_antenna_seleciton = rand_range(0, 2); - hi_dci0_pdus[1].dci_pdu.dci_pdu_rel8.tpc = rand_range(0, 3); - hi_dci0_pdus[1].dci_pdu.dci_pdu_rel8.cqi_csi_request = rand_range(0, 7); - hi_dci0_pdus[1].dci_pdu.dci_pdu_rel8.ul_index = rand_range(0, 3); - hi_dci0_pdus[1].dci_pdu.dci_pdu_rel8.dl_assignment_index = rand_range(1, 4); - hi_dci0_pdus[1].dci_pdu.dci_pdu_rel8.tpc_bitmap = rand_range(0, 9999); - hi_dci0_pdus[1].dci_pdu.dci_pdu_rel8.transmission_power = rand_range(0, 10000); - hi_dci0_pdus[1].dci_pdu.dci_pdu_rel10.tl.tag = NFAPI_HI_DCI0_REQUEST_DCI_PDU_REL10_TAG; - hi_dci0_pdus[1].dci_pdu.dci_pdu_rel10.cross_carrier_scheduling_flag = rand_range(0, 1); - hi_dci0_pdus[1].dci_pdu.dci_pdu_rel10.carrier_indicator = rand_range(0, 7); - hi_dci0_pdus[1].dci_pdu.dci_pdu_rel10.size_of_cqi_csi_feild = rand_range(0, 2); - hi_dci0_pdus[1].dci_pdu.dci_pdu_rel10.srs_flag = rand_range(0, 1); - hi_dci0_pdus[1].dci_pdu.dci_pdu_rel10.srs_request = rand_range(0, 1); - hi_dci0_pdus[1].dci_pdu.dci_pdu_rel10.resource_allocation_flag = rand_range(0, 1); - hi_dci0_pdus[1].dci_pdu.dci_pdu_rel10.resource_allocation_type = rand_range(0, 1); - hi_dci0_pdus[1].dci_pdu.dci_pdu_rel10.resource_block_coding = rand_range(0, 9999); - hi_dci0_pdus[1].dci_pdu.dci_pdu_rel10.mcs_2 = rand_range(0, 31); - hi_dci0_pdus[1].dci_pdu.dci_pdu_rel10.new_data_indication_2 = rand_range(0, 1); - hi_dci0_pdus[1].dci_pdu.dci_pdu_rel10.number_of_antenna_ports = rand_range(0, 2); - hi_dci0_pdus[1].dci_pdu.dci_pdu_rel10.tpmi = rand_range(0, 63); - hi_dci0_pdus[1].dci_pdu.dci_pdu_rel10.total_dci_length_including_padding = rand_range(0, 255); - hi_dci0_pdus[1].dci_pdu.dci_pdu_rel10.n_ul_rb = rand_range(6, 100); - hi_dci0_pdus[1].dci_pdu.dci_pdu_rel12.tl.tag = NFAPI_HI_DCI0_REQUEST_DCI_PDU_REL12_TAG; - hi_dci0_pdus[1].dci_pdu.dci_pdu_rel12.pscch_resource = rand_range(0, 16); - hi_dci0_pdus[1].dci_pdu.dci_pdu_rel12.time_resource_pattern = rand_range(0, 32); - - - hi_dci0_pdus[2].pdu_type = NFAPI_HI_DCI0_EPDCCH_DCI_PDU_TYPE; - hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel8.tl.tag = NFAPI_HI_DCI0_REQUEST_EPDCCH_DCI_PDU_REL8_TAG; - hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel8.dci_format = rand_range(0, 4); - hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel8.cce_index = rand_range(0, 88); - hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel8.aggregation_level = rand_range(1, 8); - hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel8.rnti = rand_range(1, 65535); - hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel8.resource_block_start = rand_range(0, 100); - hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel8.number_of_resource_block = rand_range(0, 100); - hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel8.mcs_1 = rand_range(0, 31); - hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel8.cyclic_shift_2_for_drms = rand_range(0, 7); - hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel8.frequency_hopping_enabled_flag = rand_range(0, 1); - hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel8.frequency_hopping_bits = rand_range(0, 3); - hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel8.new_data_indication_1 = rand_range(0, 1); - hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel8.ue_tx_antenna_seleciton = rand_range(0, 2); - hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel8.tpc = rand_range(0, 3); - hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel8.cqi_csi_request = rand_range(0, 7); - hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel8.ul_index = rand_range(0, 3); - hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel8.dl_assignment_index = rand_range(1, 4); - hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel8.tpc_bitmap = rand_range(0, 9999); - hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel8.transmission_power = rand_range(0, 10000); - hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel10.tl.tag = NFAPI_HI_DCI0_REQUEST_EPDCCH_DCI_PDU_REL10_TAG; - hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel10.cross_carrier_scheduling_flag = rand_range(0, 1); - hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel10.carrier_indicator = rand_range(0, 7); - hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel10.size_of_cqi_csi_feild = rand_range(0, 2); - hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel10.srs_flag = rand_range(0, 1); - hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel10.srs_request = rand_range(0, 1); - hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel10.resource_allocation_flag = rand_range(0, 1); - hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel10.resource_allocation_type = rand_range(0, 1); - hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel10.resource_block_coding = rand_range(0, 9999); - hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel10.mcs_2 = rand_range(0, 31); - hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel10.new_data_indication_2 = rand_range(0, 1); - hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel10.number_of_antenna_ports = rand_range(0, 2); - hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel10.tpmi = rand_range(0, 63); - hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel10.total_dci_length_including_padding = rand_range(0, 255); - hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel10.n_ul_rb = rand_range(6, 100); - hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_parameters_rel11.tl.tag = NFAPI_HI_DCI0_REQUEST_EPDCCH_PARAMETERS_REL11_TAG; - - hi_dci0_pdus[3].pdu_type = NFAPI_HI_DCI0_MPDCCH_DCI_PDU_TYPE; - hi_dci0_pdus[3].mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.tl.tag = NFAPI_HI_DCI0_REQUEST_MPDCCH_DCI_PDU_REL13_TAG; - - hi_dci0_pdus[4].pdu_type = NFAPI_HI_DCI0_NPDCCH_DCI_PDU_TYPE; - hi_dci0_pdus[4].npdcch_dci_pdu.npdcch_dci_pdu_rel13.tl.tag = NFAPI_HI_DCI0_REQUEST_NPDCCH_DCI_PDU_REL13_TAG; - hi_dci0_pdus[4].npdcch_dci_pdu.npdcch_dci_pdu_rel13.ncce_index = rand_range(0, 1); - hi_dci0_pdus[4].npdcch_dci_pdu.npdcch_dci_pdu_rel13.aggregation_level = rand_range(1, 2); - hi_dci0_pdus[4].npdcch_dci_pdu.npdcch_dci_pdu_rel13.start_symbol = rand_range(0, 4); - hi_dci0_pdus[4].npdcch_dci_pdu.npdcch_dci_pdu_rel13.rnti = rand_range(1, 65535); - hi_dci0_pdus[4].npdcch_dci_pdu.npdcch_dci_pdu_rel13.scrambling_reinitialization_batch_index = rand_range(1, 4); - hi_dci0_pdus[4].npdcch_dci_pdu.npdcch_dci_pdu_rel13.nrs_antenna_ports_assumed_by_the_ue = rand_range(1, 2); - hi_dci0_pdus[4].npdcch_dci_pdu.npdcch_dci_pdu_rel13.subcarrier_indication = rand_range(0, 63); - hi_dci0_pdus[4].npdcch_dci_pdu.npdcch_dci_pdu_rel13.resource_assignment = rand_range(0, 7); - hi_dci0_pdus[4].npdcch_dci_pdu.npdcch_dci_pdu_rel13.scheduling_delay = rand_range(0, 3); - hi_dci0_pdus[4].npdcch_dci_pdu.npdcch_dci_pdu_rel13.mcs = rand_range(0, 12); - hi_dci0_pdus[4].npdcch_dci_pdu.npdcch_dci_pdu_rel13.redudancy_version = rand_range(0, 1); - hi_dci0_pdus[4].npdcch_dci_pdu.npdcch_dci_pdu_rel13.repetition_number = rand_range(0, 7); - hi_dci0_pdus[4].npdcch_dci_pdu.npdcch_dci_pdu_rel13.new_data_indicator = rand_range(0, 1); - hi_dci0_pdus[4].npdcch_dci_pdu.npdcch_dci_pdu_rel13.dci_subframe_repetition_number = rand_range(0, 3); - - hi_dci0_req.hi_dci0_request_body.hi_dci0_pdu_list = hi_dci0_pdus; - mac->hi_dci0_req(mac, &hi_dci0_req); - - uint8_t num_tx_pdus = 2; - nfapi_tx_request_pdu_t tx_pdus[num_tx_pdus]; - memset(&tx_pdus, 0, sizeof(tx_pdus)); - - nfapi_tx_request_t tx_req; - memset(&tx_req, 0, sizeof(tx_req)); - tx_req.header.message_id = NFAPI_TX_REQUEST; - tx_req.header.phy_id = phy_id; - tx_req.sfn_sf = sfn_sf; - - tx_req.tx_request_body.tl.tag = NFAPI_TX_REQUEST_BODY_TAG; - tx_req.tx_request_body.number_of_pdus = num_tx_pdus; - - uint32_t data[2]; - data[0] = 0x11223344; - data[1] = 0x55667788; - - tx_pdus[0].pdu_length = 8; - tx_pdus[0].pdu_index = 1; - tx_pdus[0].num_segments = 2; - tx_pdus[0].segments[0].segment_length = 4; - tx_pdus[0].segments[0].segment_data = (uint8_t*)&data[0]; - tx_pdus[0].segments[1].segment_length = 4; - tx_pdus[0].segments[1].segment_data = (uint8_t*)&data[1]; - - tx_pdus[1].pdu_length = 8; - tx_pdus[1].pdu_index = 2; - tx_pdus[1].num_segments = 2; - tx_pdus[1].segments[0].segment_length = 4; - tx_pdus[1].segments[0].segment_data = (uint8_t*)&data[0]; - tx_pdus[1].segments[1].segment_length = 4; - tx_pdus[1].segments[1].segment_data = (uint8_t*)&data[1]; - - - tx_req.tx_request_body.tx_pdu_list = tx_pdus; - mac->tx_req(mac, &tx_req); - } - - void generate_subframe(mac_t *mac, uint16_t phy_id, uint16_t sfn_sf) - { - mac_internal_t* instance = (mac_internal_t*)mac; - - nfapi_dl_config_request_t dl_config_req; - memset(&dl_config_req, 0, sizeof(dl_config_req)); - dl_config_req.header.message_id = NFAPI_DL_CONFIG_REQUEST; - dl_config_req.header.phy_id = phy_id; - dl_config_req.sfn_sf = sfn_sf; - - dl_config_req.dl_config_request_body.tl.tag = NFAPI_DL_CONFIG_REQUEST_BODY_TAG; - dl_config_req.dl_config_request_body.number_pdu = 8; - - nfapi_dl_config_request_pdu_t pdus[8]; - memset(&pdus, 0, sizeof(pdus)); - for(int i = 0; i < 8; i++) - { - pdus[i].pdu_type = NFAPI_DL_CONFIG_BCH_PDU_TYPE; - - pdus[i].bch_pdu.bch_pdu_rel8.tl.tag = NFAPI_DL_CONFIG_REQUEST_BCH_PDU_REL8_TAG; - pdus[i].bch_pdu.bch_pdu_rel8.length = 42; - pdus[i].bch_pdu.bch_pdu_rel8.pdu_index = i; - pdus[i].bch_pdu.bch_pdu_rel8.transmission_power = 56; - - } - - dl_config_req.dl_config_request_body.dl_config_pdu_list = pdus; - - /* - vendor_ext_tlv_1 ve; - ve.tl.tag = VENDOR_EXT_TLV_1_TAG; - ve.dummy = 999; - dl_config_req.vendor_extension = &ve.tl; - */ - - mac->dl_config_req(mac, &dl_config_req); - - - nfapi_ul_config_request_t ul_config_req; - memset(&ul_config_req, 0, sizeof(ul_config_req)); - ul_config_req.header.message_id = NFAPI_UL_CONFIG_REQUEST; - ul_config_req.header.phy_id = phy_id; - ul_config_req.sfn_sf = sfn_sf; - mac->ul_config_req(mac, &ul_config_req); - - nfapi_hi_dci0_request_t hi_dci0_req; - memset(&hi_dci0_req, 0, sizeof(hi_dci0_req)); - hi_dci0_req.header.message_id = NFAPI_HI_DCI0_REQUEST; - hi_dci0_req.header.phy_id = phy_id; - hi_dci0_req.sfn_sf = sfn_sf; - mac->hi_dci0_req(mac, &hi_dci0_req); - - - - nfapi_tx_request_t tx_req; - memset(&tx_req, 0, sizeof(tx_req)); - tx_req.header.message_id = NFAPI_TX_REQUEST; - tx_req.header.phy_id = phy_id; - tx_req.sfn_sf = sfn_sf; - - nfapi_tx_request_pdu_t tx_pdus[8]; - - tx_req.tx_request_body.tl.tag = NFAPI_TX_REQUEST_BODY_TAG; - tx_req.tx_request_body.number_of_pdus = 0; - tx_req.tx_request_body.tx_pdu_list = &tx_pdus[0]; - - mac_pdu* buff = 0; - int i = 0; - std::list<mac_pdu*> free_list; - do - { - buff = instance->mac->pop_rx_buffer(); - if(buff != 0) - { - if(buff->len == 0) - { - printf("[MAC] Buffer length = 0\n"); - } - - tx_req.tx_request_body.tx_pdu_list[i].pdu_length = buff->len; - tx_req.tx_request_body.tx_pdu_list[i].pdu_index = i; - tx_req.tx_request_body.tx_pdu_list[i].num_segments = 1; - tx_req.tx_request_body.tx_pdu_list[i].segments[0].segment_length = buff->len; - tx_req.tx_request_body.tx_pdu_list[i].segments[0].segment_data = (uint8_t*)buff->buffer; - - tx_req.tx_request_body.number_of_pdus++; - i++; - - instance->mac->byte_count += buff->len; - - free_list.push_back(buff); - } - }while(buff != 0 && i < 8); - - mac->tx_req(mac, &tx_req); - - //for(int j = 0; j < tx_req.tx_request_body.number_of_pdus; ++j) - for(mac_pdu* pdu : free_list) - { - instance->mac->release_mac_pdu(pdu); - //free(tx_req.tx_request_body.tx_pdu_list[j].segments[0].segment_data); - } - } - - void mac_subframe_ind(mac_t *mac, uint16_t phy_id, uint16_t sfn_sf) - { - - - //printf("[MAC] subframe indication phyid:%d sfnsf:%d\n", phy_id, sfn_sf); - mac_internal_t* instance = (mac_internal_t*)mac; - - if(instance->mac->tick == 1000) - { - if(instance->mac->byte_count > 0) - { - printf("[MAC] Rx rate %d bytes/sec\n", instance->mac->byte_count); - instance->mac->byte_count = 0; - } - instance->mac->tick = 0; - } - instance->mac->tick++; - - if(instance->mac->wireshark_test_mode) - { - generate_test_subframe(mac, phy_id, sfn_sf); - } - else - { - generate_subframe(mac, phy_id, sfn_sf); - } - } - - void mac_harq_ind(mac_t* mac, nfapi_harq_indication_t* ind) - { - } - void mac_crc_ind(mac_t* mac, nfapi_crc_indication_t* ind) - { - } - void mac_rx_ind(mac_t* mac, nfapi_rx_indication_t* ind) - { - mac_internal_t* instance = (mac_internal_t*)mac; - - for(int i = 0; i < ind->rx_indication_body.number_of_pdus; ++i) - { - uint16_t len = ind->rx_indication_body.rx_pdu_list[i].rx_indication_rel8.length; - uint8_t* data = ind->rx_indication_body.rx_pdu_list[i].data; - //printf("[MAC] sfnsf:%d len:%d\n", ind->sfn_sf,len); - // - instance->tx_byte_count += len; - - int sendto_result = sendto(instance->tx_sock, data, len, 0, (struct sockaddr*)&(instance->tx_addr), sizeof(instance->tx_addr)); - - if(sendto_result < 0) - { - // error - } - } - - } - void mac_rach_ind(mac_t* mac, nfapi_rach_indication_t* ind) - { - } - void mac_srs_ind(mac_t* mac, nfapi_srs_indication_t* ind) - { - } - void mac_sr_ind(mac_t* mac, nfapi_sr_indication_t* ind) - { - } - void mac_cqi_ind(mac_t* mac, nfapi_cqi_indication_t* ind) - { - } - void mac_lbt_dl_ind(mac_t* mac, nfapi_lbt_dl_indication_t* ind) - { - } - void mac_nb_harq_ind(mac_t* mac, nfapi_nb_harq_indication_t* ind) - { - } - void mac_nrach_ind(mac_t* mac, nfapi_nrach_indication_t* ind) - { - } + typedef struct { + mac_t _public; + + int rx_sock; + int tx_sock; + struct sockaddr_in tx_addr; + + uint32_t tx_byte_count; + + mac_private *mac; + + } mac_internal_t; + + mac_t *mac_create(uint8_t wireshark_test_mode) { + mac_internal_t *instance = (mac_internal_t *)malloc(sizeof(mac_internal_t)); + instance->mac = new mac_private((wireshark_test_mode >= 1)); + return (mac_t *)instance; + } + + void mac_destroy(mac_t *mac) { + mac_internal_t *instance = (mac_internal_t *)mac; + delete instance->mac; + free(instance); + } + + void *mac_rx_thread_start(void *ptr) { + mac_internal_t *instance = (mac_internal_t *)ptr; + + while(1) { + mac_pdu *pdu = instance->mac->allocate_mac_pdu(); + int len = recvfrom(instance->rx_sock, pdu->buffer, pdu->buffer_len, 0, 0, 0); + + if(len > 0) { + pdu->len = len; + instance->mac->push_rx_buffer(pdu); + } else { + instance->mac->release_mac_pdu(pdu); + } + } + + return 0; + } + + void mac_start_data(mac_t *mac, unsigned rx_port, const char *tx_address, unsigned tx_port) { + mac_internal_t *instance = (mac_internal_t *)mac; + printf("[MAC] Rx Data from %u\n", rx_port); + printf("[MAC] Tx Data to %s.%u\n", tx_address, tx_port); + instance->rx_sock = socket(AF_INET, SOCK_DGRAM, 0); + + if(instance->rx_sock < 0) { + printf("[MAC] Failed to create socket\n"); + return; + } + + struct sockaddr_in addr; + + memset(&addr, 0, sizeof(sockaddr_in)); + + addr.sin_family = AF_INET; + + addr.sin_port = htons(rx_port); + + addr.sin_addr.s_addr = INADDR_ANY; + + if(bind(instance->rx_sock, (struct sockaddr *)&addr, sizeof(struct sockaddr_in)) < 0) { + printf("[MAC] Failed to bind to %u\n", rx_port); + close(instance->rx_sock); + return; + } + + pthread_t mac_rx_thread; + pthread_create(&mac_rx_thread, NULL, &mac_rx_thread_start, instance); + instance->tx_sock = socket(AF_INET, SOCK_DGRAM, 0); + instance->tx_addr.sin_family = AF_INET; + instance->tx_addr.sin_port = htons(tx_port); + instance->tx_addr.sin_addr.s_addr = inet_addr(tx_address); + } + + + + void generate_test_subframe(mac_t *mac, uint16_t phy_id, uint16_t sfn_sf) { + //mac_internal_t* instance = (mac_internal_t*)mac; + uint8_t max_num_dl_pdus = 50; + nfapi_dl_config_request_pdu_t dl_config_pdus[max_num_dl_pdus]; + memset(&dl_config_pdus, 0, sizeof(dl_config_pdus)); + nfapi_dl_config_request_t dl_config_req; + memset(&dl_config_req, 0, sizeof(dl_config_req)); + dl_config_req.header.message_id = NFAPI_DL_CONFIG_REQUEST; + dl_config_req.header.phy_id = phy_id; + dl_config_req.sfn_sf = sfn_sf; + dl_config_req.dl_config_request_body.tl.tag = NFAPI_DL_CONFIG_REQUEST_BODY_TAG; + dl_config_req.dl_config_request_body.number_pdu = rand_range(4, max_num_dl_pdus); + uint16_t i = 0; + + for(i = 0; i < dl_config_req.dl_config_request_body.number_pdu; ++i) { + dl_config_pdus[i].pdu_type = rand_range(0, 11); + + switch(dl_config_pdus[i].pdu_type) { + case NFAPI_DL_CONFIG_DCI_DL_PDU_TYPE: { + dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.tl.tag = NFAPI_DL_CONFIG_REQUEST_DCI_DL_PDU_REL8_TAG; + dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.dci_format = rand_range(0, 9); + dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.cce_idx = rand_range(0, 255); + dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level = rand_range(0, 32); + dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.rnti = rand_range(0, (uint16_t)-1); + dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.resource_allocation_type = rand_range(0, 1); + dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.virtual_resource_block_assignment_flag = rand_range(0, 1); + dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.resource_block_coding = rand_range(0, 320000); + dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.mcs_1 = rand_range(0, 31); + dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.redundancy_version_1 = rand_range(0, 3); + dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.new_data_indicator_1 = rand_range(0, 1); + dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.transport_block_to_codeword_swap_flag = rand_range(0, 1); + dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.mcs_2 = rand_range(0, 31); + dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.redundancy_version_2 = rand_range(0, 31); + dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.new_data_indicator_2 = rand_range(0, 1); + dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.harq_process = rand_range(0, 31); + dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.tpmi = rand_range(0, 15); + dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.pmi = rand_range(0, 1); + dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.precoding_information = rand_range(0, 63); + dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.tpc = rand_range(0, 3); + dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.downlink_assignment_index = rand_range(0, 15); + dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.ngap = rand_range(0, 1); + dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.transport_block_size_index = rand_range(0, 31); + dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.downlink_power_offset = rand_range(0, 1); + dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.allocate_prach_flag = rand_range(0, 1); + dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.preamble_index = rand_range(0, 63); + dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.prach_mask_index = rand_range(0, 15); + dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.rnti_type = rand_range(0, 3); + dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel8.transmission_power = rand_range(0, 10000); + dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel9.tl.tag = NFAPI_DL_CONFIG_REQUEST_DCI_DL_PDU_REL9_TAG; + dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel9.mcch_flag = rand_range(0, 1); + dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel9.mcch_change_notification = rand_range(0, 255); + dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel9.scrambling_identity = rand_range(0, 1); + dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel10.tl.tag = NFAPI_DL_CONFIG_REQUEST_DCI_DL_PDU_REL10_TAG; + dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel10.cross_carrier_scheduling_flag = rand_range(0, 1); + dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel10.carrier_indicator = rand_range(0, 7); + dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel10.srs_flag = rand_range(0, 1); + dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel10.srs_request = rand_range(0, 1); + dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel10.antenna_ports_scrambling_and_layers = rand_range(0, 15); + dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel10.total_dci_length_including_padding = rand_range(0, 255); + dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel10.n_dl_rb = rand_range(0, 100); + dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel11.tl.tag = NFAPI_DL_CONFIG_REQUEST_DCI_DL_PDU_REL11_TAG; + dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel11.harq_ack_resource_offset = rand_range(0, 3); + dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel11.pdsch_re_mapping_quasi_co_location_indicator = rand_range(0, 3); + dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel12.tl.tag = NFAPI_DL_CONFIG_REQUEST_DCI_DL_PDU_REL12_TAG; + dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel12.primary_cell_type = rand_range(0, 2); + dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel12.ul_dl_configuration_flag = rand_range(0, 1); + dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel12.number_ul_dl_configurations = 2; + dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel12.ul_dl_configuration_indication[0] = rand_range(1, 5); + dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel12.ul_dl_configuration_indication[1] = rand_range(1, 5); + dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel13.tl.tag = NFAPI_DL_CONFIG_REQUEST_DCI_DL_PDU_REL13_TAG; + dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel13.laa_end_partial_sf_flag = rand_range(0, 1); + dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel13.laa_end_partial_sf_configuration = rand_range(0, 255); + dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel13.initial_lbt_sf = rand_range(0, 1); + dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel13.codebook_size_determination = rand_range(0, 1); + dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel13.drms_table_flag = rand_range(0, 1); + + // if the tpm extention is present of not. + if(rand_range(0, 1)) { + dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel13.tpm_struct_flag = rand_range(0, 1); + dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel13.tpm.num_prb_per_subband = rand_range(0, 8); + dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel13.tpm.number_of_subbands = rand_range(0, 13); + dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel13.tpm.num_antennas = 1; // rand_range(0, 8); + + for(int j = 0; j < dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel13.tpm.number_of_subbands; ++j) { + dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel13.tpm.subband_info[j].subband_index = j; + dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel13.tpm.subband_info[j].scheduled_ues = 1; //rand_range(1, 4); + + for(int k = 0; k < dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel13.tpm.num_antennas; ++k) + for(int l = 0; l < dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel13.tpm.subband_info[j].scheduled_ues; ++l) + dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel13.tpm.subband_info[j].precoding_value[k][l] = rand_range(0, 65535); + } + } else { + dl_config_pdus[i].dci_dl_pdu.dci_dl_pdu_rel13.tpm_struct_flag = 0; + } + } + break; + + case NFAPI_DL_CONFIG_BCH_PDU_TYPE: { + dl_config_pdus[i].bch_pdu.bch_pdu_rel8.tl.tag = NFAPI_DL_CONFIG_REQUEST_BCH_PDU_REL8_TAG; + dl_config_pdus[i].bch_pdu.bch_pdu_rel8.length = rand_range(0, 42); + dl_config_pdus[i].bch_pdu.bch_pdu_rel8.pdu_index = rand_range(0, 65535); + dl_config_pdus[i].bch_pdu.bch_pdu_rel8.transmission_power = rand_range(0, 10000); + } + break; + + case NFAPI_DL_CONFIG_MCH_PDU_TYPE: { + dl_config_pdus[i].mch_pdu.mch_pdu_rel8.tl.tag = NFAPI_DL_CONFIG_REQUEST_MCH_PDU_REL8_TAG; + dl_config_pdus[i].mch_pdu.mch_pdu_rel8.length = rand_range(0, 42); + dl_config_pdus[i].mch_pdu.mch_pdu_rel8.pdu_index = rand_range(0, 65535); + dl_config_pdus[i].mch_pdu.mch_pdu_rel8.rnti = 0xFFFD; + dl_config_pdus[i].mch_pdu.mch_pdu_rel8.resource_allocation_type = 0; + dl_config_pdus[i].mch_pdu.mch_pdu_rel8.resource_block_coding = 0; + dl_config_pdus[i].mch_pdu.mch_pdu_rel8.modulation = rand_range(0, 8); + dl_config_pdus[i].mch_pdu.mch_pdu_rel8.transmission_power = rand_range(0, 10000); + dl_config_pdus[i].mch_pdu.mch_pdu_rel8.mbsfn_area_id = rand_range(0, 255); + } + break; + + case NFAPI_DL_CONFIG_DLSCH_PDU_TYPE: { + dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.tl.tag = NFAPI_DL_CONFIG_REQUEST_DLSCH_PDU_REL8_TAG; + dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.length = rand_range(0, 42); + dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.pdu_index = rand_range(0, 65535); + dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.rnti = rand_range(1, 65535); + dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.resource_allocation_type = rand_range(0, 5); + dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.virtual_resource_block_assignment_flag = rand_range(0, 1); + dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.resource_block_coding = rand_range(0, 32000); + dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.modulation = rand_range(2, 8); + dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.redundancy_version = rand_range(0, 3); + dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.transport_blocks = rand_range(1, 2); + dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.transport_block_to_codeword_swap_flag = rand_range(0, 1); + dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.transmission_scheme = rand_range(0, 13); + dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.number_of_layers = rand_range(1, 8); + dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.number_of_subbands = 2; //rand_range(0, 13); + dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.codebook_index[0] = rand_range(0, 15); + dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.codebook_index[1] = rand_range(0, 15); + dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.ue_category_capacity = rand_range(0, 14); + dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.pa = rand_range(0, 7); + dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.delta_power_offset_index = rand_range(0, 1); + dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.ngap = rand_range(0, 1); + dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.nprb = rand_range(0, 1); + dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.transmission_mode = rand_range(1, 10); + dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.num_bf_prb_per_subband = 2; //rand_range(0, 1); + dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.num_bf_vector = 2; //rand_range(0, 1); + dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.bf_vector[0].subband_index = rand_range(0, 4); + dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.bf_vector[0].num_antennas = 1; + dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.bf_vector[0].bf_value[0] = rand_range(0, 128); + dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.bf_vector[1].subband_index = rand_range(0, 4); + dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.bf_vector[1].num_antennas = 1; + dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel8.bf_vector[1].bf_value[0] = rand_range(0, 128); + dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel9.tl.tag = NFAPI_DL_CONFIG_REQUEST_DLSCH_PDU_REL9_TAG; + dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel9.nscid = rand_range(0, 1); + dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel10.tl.tag = NFAPI_DL_CONFIG_REQUEST_DLSCH_PDU_REL10_TAG; + dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel10.csi_rs_flag = rand_range(0, 1); + dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel10.csi_rs_resource_config_r10 = 0; + dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel10.csi_rs_zero_tx_power_resource_config_bitmap_r10 = rand_range(0, 65535); + dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel10.csi_rs_number_nzp_configuration = 1; + dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel10.csi_rs_resource_config[0] = rand_range(0, 31); + dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel10.pdsch_start = rand_range(0, 4); + dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel11.tl.tag = NFAPI_DL_CONFIG_REQUEST_DLSCH_PDU_REL11_TAG; + dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel11.drms_config_flag = rand_range(0, 1); + dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel11.drms_scrambling = rand_range(0, 503); + dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel11.csi_config_flag = rand_range(0, 1); + dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel11.csi_scrambling = rand_range(0, 503); + dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel11.pdsch_re_mapping_flag = rand_range(0, 1); + dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel11.pdsch_re_mapping_atenna_ports = rand_range(1,4); + dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel11.pdsch_re_mapping_freq_shift = rand_range(0, 5); + dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel12.tl.tag = NFAPI_DL_CONFIG_REQUEST_DLSCH_PDU_REL12_TAG; + dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel12.altcqi_table_r12 = rand_range(0, 1); + dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel12.maxlayers = rand_range(1, 8); + dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel12.n_dl_harq = rand_range(0, 255); + dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel13.dwpts_symbols = rand_range(3, 14); + dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel13.initial_lbt_sf = rand_range(0, 1); + dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel13.ue_type = rand_range(0, 2); + dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel13.pdsch_payload_type = rand_range(0, 2); + dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel13.initial_transmission_sf_io = rand_range(0, 10239); + dl_config_pdus[i].dlsch_pdu.dlsch_pdu_rel13.drms_table_flag = rand_range(0, 1); + } + break; + + case NFAPI_DL_CONFIG_PCH_PDU_TYPE: { + dl_config_pdus[i].pch_pdu.pch_pdu_rel8.tl.tag = NFAPI_DL_CONFIG_REQUEST_PCH_PDU_REL8_TAG; + dl_config_pdus[i].pch_pdu.pch_pdu_rel8.length = rand_range(0, 42); + dl_config_pdus[i].pch_pdu.pch_pdu_rel8.pdu_index = rand_range(0, 65535); + dl_config_pdus[i].pch_pdu.pch_pdu_rel8.p_rnti = 0xFFFE; + dl_config_pdus[i].pch_pdu.pch_pdu_rel8.resource_allocation_type = rand_range(2, 6); + dl_config_pdus[i].pch_pdu.pch_pdu_rel8.virtual_resource_block_assignment_flag = rand_range(0, 1); + dl_config_pdus[i].pch_pdu.pch_pdu_rel8.resource_block_coding = rand_range(0, 34000); + dl_config_pdus[i].pch_pdu.pch_pdu_rel8.mcs = 0; + dl_config_pdus[i].pch_pdu.pch_pdu_rel8.redundancy_version = 0; + dl_config_pdus[i].pch_pdu.pch_pdu_rel8.number_of_transport_blocks = 1; + dl_config_pdus[i].pch_pdu.pch_pdu_rel8.transport_block_to_codeword_swap_flag = 0; + dl_config_pdus[i].pch_pdu.pch_pdu_rel8.transmission_scheme = rand_range(1, 6); + dl_config_pdus[i].pch_pdu.pch_pdu_rel8.number_of_layers = rand_range(1, 4); + dl_config_pdus[i].pch_pdu.pch_pdu_rel8.codebook_index = 0; + dl_config_pdus[i].pch_pdu.pch_pdu_rel8.ue_category_capacity = rand_range(0, 14); + dl_config_pdus[i].pch_pdu.pch_pdu_rel8.pa = rand_range(0, 7); + dl_config_pdus[i].pch_pdu.pch_pdu_rel8.transmission_power = rand_range(0, 10000); + dl_config_pdus[i].pch_pdu.pch_pdu_rel8.nprb = rand_range(0, 1); + dl_config_pdus[i].pch_pdu.pch_pdu_rel8.ngap = rand_range(0, 1); + dl_config_pdus[i].pch_pdu.pch_pdu_rel13.tl.tag = NFAPI_DL_CONFIG_REQUEST_PCH_PDU_REL13_TAG; + dl_config_pdus[i].pch_pdu.pch_pdu_rel13.ue_mode = rand_range(0, 1); + dl_config_pdus[i].pch_pdu.pch_pdu_rel13.initial_transmission_sf_io = rand_range(0, 10239); + } + break; + + case NFAPI_DL_CONFIG_PRS_PDU_TYPE: { + dl_config_pdus[i].prs_pdu.prs_pdu_rel9.tl.tag = NFAPI_DL_CONFIG_REQUEST_PRS_PDU_REL9_TAG; + dl_config_pdus[i].prs_pdu.prs_pdu_rel9.transmission_power = rand_range(0, 10000); + dl_config_pdus[i].prs_pdu.prs_pdu_rel9.prs_bandwidth = rand_range(6, 100); + dl_config_pdus[i].prs_pdu.prs_pdu_rel9.prs_cyclic_prefix_type = rand_range(0, 1); + dl_config_pdus[i].prs_pdu.prs_pdu_rel9.prs_muting = rand_range(0, 1); + } + break; + + case NFAPI_DL_CONFIG_CSI_RS_PDU_TYPE: { + dl_config_pdus[i].csi_rs_pdu.csi_rs_pdu_rel10.tl.tag = NFAPI_DL_CONFIG_REQUEST_CSI_RS_PDU_REL10_TAG; + dl_config_pdus[i].csi_rs_pdu.csi_rs_pdu_rel10.csi_rs_antenna_port_count_r10 = rand_range(1, 16); + dl_config_pdus[i].csi_rs_pdu.csi_rs_pdu_rel10.csi_rs_resource_config_r10 = 0; + dl_config_pdus[i].csi_rs_pdu.csi_rs_pdu_rel10.transmission_power = rand_range(0, 10000); + dl_config_pdus[i].csi_rs_pdu.csi_rs_pdu_rel10.csi_rs_zero_tx_power_resource_config_bitmap_r10 = rand_range(0, 8); + dl_config_pdus[i].csi_rs_pdu.csi_rs_pdu_rel10.csi_rs_number_of_nzp_configuration = 2; + dl_config_pdus[i].csi_rs_pdu.csi_rs_pdu_rel10.csi_rs_resource_config[0] = rand_range(0, 31); + dl_config_pdus[i].csi_rs_pdu.csi_rs_pdu_rel10.csi_rs_resource_config[1] = rand_range(0, 31); + dl_config_pdus[i].csi_rs_pdu.csi_rs_pdu_rel13.tl.tag = NFAPI_DL_CONFIG_REQUEST_CSI_RS_PDU_REL13_TAG; + dl_config_pdus[i].csi_rs_pdu.csi_rs_pdu_rel13.csi_rs_class = rand_range(0, 2); + dl_config_pdus[i].csi_rs_pdu.csi_rs_pdu_rel13.cdm_type = rand_range(0, 1); + dl_config_pdus[i].csi_rs_pdu.csi_rs_pdu_rel13.num_bf_vector = 0; // set to zero as not clear how to handle bf value array + dl_config_pdus[i].csi_rs_pdu.csi_rs_pdu_rel13.bf_vector[0].csi_rs_resource_index = rand_range(0, 7); + dl_config_pdus[i].csi_rs_pdu.csi_rs_pdu_rel13.bf_vector[0].bf_value[0] = 42; + } + break; + + case NFAPI_DL_CONFIG_EPDCCH_DL_PDU_TYPE: { + dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.tl.tag = NFAPI_DL_CONFIG_REQUEST_EPDCCH_PDU_REL8_TAG; + dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.dci_format = rand_range(0, 9); + dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.cce_idx = rand_range(0, 255); + dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.aggregation_level = rand_range(0, 32); + dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.rnti = rand_range(0, (uint16_t)-1); + dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.resource_allocation_type = rand_range(0, 1); + dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.virtual_resource_block_assignment_flag = rand_range(0, 1); + dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.resource_block_coding = rand_range(0, 320000); + dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.mcs_1 = rand_range(0, 31); + dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.redundancy_version_1 = rand_range(0, 3); + dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.new_data_indicator_1 = rand_range(0, 1); + dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.transport_block_to_codeword_swap_flag = rand_range(0, 1); + dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.mcs_2 = rand_range(0, 31); + dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.redundancy_version_2 = rand_range(0, 31); + dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.new_data_indicator_2 = rand_range(0, 1); + dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.harq_process = rand_range(0, 31); + dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.tpmi = rand_range(0, 15); + dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.pmi = rand_range(0, 1); + dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.precoding_information = rand_range(0, 63); + dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.tpc = rand_range(0, 3); + dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.downlink_assignment_index = rand_range(0, 15); + dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.ngap = rand_range(0, 1); + dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.transport_block_size_index = rand_range(0, 31); + dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.downlink_power_offset = rand_range(0, 1); + dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.allocate_prach_flag = rand_range(0, 1); + dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.preamble_index = rand_range(0, 63); + dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.prach_mask_index = rand_range(0, 15); + dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.rnti_type = rand_range(0, 3); + dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel8.transmission_power = rand_range(0, 10000); + dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel9.tl.tag = NFAPI_DL_CONFIG_REQUEST_EPDCCH_PDU_REL9_TAG; + dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel9.mcch_flag = rand_range(0, 1); + dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel9.mcch_change_notification = rand_range(0, 255); + dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel9.scrambling_identity = rand_range(0, 1); + dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel10.tl.tag = NFAPI_DL_CONFIG_REQUEST_EPDCCH_PDU_REL10_TAG; + dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel10.cross_carrier_scheduling_flag = rand_range(0, 1); + dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel10.carrier_indicator = rand_range(0, 7); + dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel10.srs_flag = rand_range(0, 1); + dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel10.srs_request = rand_range(0, 1); + dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel10.antenna_ports_scrambling_and_layers = rand_range(0, 15); + dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel10.total_dci_length_including_padding = rand_range(0, 255); + dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel10.n_dl_rb = rand_range(0, 100); + dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel11.tl.tag = NFAPI_DL_CONFIG_REQUEST_EPDCCH_PDU_REL11_TAG; + dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel11.harq_ack_resource_offset = rand_range(0, 3); + dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel11.pdsch_re_mapping_quasi_co_location_indicator = rand_range(0, 3); + dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel12.tl.tag = NFAPI_DL_CONFIG_REQUEST_EPDCCH_PDU_REL12_TAG; + dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel12.primary_cell_type = rand_range(0, 2); + dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel12.ul_dl_configuration_flag = rand_range(0, 1); + dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel12.number_ul_dl_configurations = 2; + dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel12.ul_dl_configuration_indication[0] = rand_range(1, 5); + dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel12.ul_dl_configuration_indication[1] = rand_range(1, 5); + dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel13.tl.tag = NFAPI_DL_CONFIG_REQUEST_EPDCCH_PDU_REL13_TAG; + dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel13.laa_end_partial_sf_flag = rand_range(0, 1); + dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel13.laa_end_partial_sf_configuration = rand_range(0, 255); + dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel13.initial_lbt_sf = rand_range(0, 1); + dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel13.codebook_size_determination = rand_range(0, 1); + dl_config_pdus[i].epdcch_pdu.epdcch_pdu_rel13.drms_table_flag = rand_range(0, 1); + dl_config_pdus[i].epdcch_pdu.epdcch_params_rel11.tl.tag = NFAPI_DL_CONFIG_REQUEST_EPDCCH_PARAM_REL11_TAG; + dl_config_pdus[i].epdcch_pdu.epdcch_params_rel11.epdcch_resource_assignment_flag = rand_range(0, 1); + dl_config_pdus[i].epdcch_pdu.epdcch_params_rel11.epdcch_id = rand_range(0, 503); + dl_config_pdus[i].epdcch_pdu.epdcch_params_rel11.epdcch_start_symbol = rand_range(1, 4); + dl_config_pdus[i].epdcch_pdu.epdcch_params_rel11.epdcch_num_prb = rand_range(2, 8); + + for(int j = 0; j < dl_config_pdus[i].epdcch_pdu.epdcch_params_rel11.epdcch_num_prb; ++j) + dl_config_pdus[i].epdcch_pdu.epdcch_params_rel11.epdcch_prb_index[j] = rand_range(0, 99); + + dl_config_pdus[i].epdcch_pdu.epdcch_params_rel11.bf_vector.subband_index = rand_range(0, 25); + dl_config_pdus[i].epdcch_pdu.epdcch_params_rel11.bf_vector.num_antennas= rand_range(1, 4); + + for(int j = 0; j < dl_config_pdus[i].epdcch_pdu.epdcch_params_rel11.epdcch_num_prb; ++j) + dl_config_pdus[i].epdcch_pdu.epdcch_params_rel11.bf_vector.bf_value[j] = rand_range(0, 65535); + + dl_config_pdus[i].epdcch_pdu.epdcch_params_rel13.tl.tag = NFAPI_DL_CONFIG_REQUEST_EPDCCH_PARAM_REL13_TAG; + dl_config_pdus[i].epdcch_pdu.epdcch_params_rel13.dwpts_symbols = rand_range(3, 14); + dl_config_pdus[i].epdcch_pdu.epdcch_params_rel13.initial_lbt_sf = rand_range(0, 1); + } + break; + + case NFAPI_DL_CONFIG_MPDCCH_PDU_TYPE: { + dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.tl.tag = NFAPI_DL_CONFIG_REQUEST_MPDCCH_PDU_REL13_TAG; + dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.mpdcch_narrow_band = rand_range(0, 15); + dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.number_of_prb_pairs = rand_range(2, 6); + dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.resource_block_assignment = rand_range(0, 14); + dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.mpdcch_tansmission_type = rand_range(0, 1); + dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.start_symbol = rand_range(1, 4); + dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.ecce_index = rand_range(0, 22); + dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.aggregation_level = rand_range(2, 24); + dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.rnti_type = rand_range(0, 4); + dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.rnti = rand_range(1, 65535); + dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.ce_mode = rand_range(1, 2); + dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.drms_scrambling_init = rand_range(0, 503); + dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.initial_transmission_sf_io = rand_range(0, 10239); + dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.transmission_power = rand_range(0, 10000); + dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.dci_format = rand_range(10, 12); + dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.resource_block_coding = rand_range(0, 0xFFFF); + dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.mcs = rand_range(0, 15); + dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.pdsch_reptition_levels = rand_range(1, 8); + dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.redundancy_version = rand_range(0, 3); + dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.new_data_indicator = rand_range(0, 1); + dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.harq_process = rand_range(0, 15); + dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.tpmi_length = rand_range(0, 4); + dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.tpmi = rand_range(0, 15); + dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.pmi_flag = rand_range(0, 1); + dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.pmi = rand_range(0, 1); + dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.harq_resource_offset = rand_range(0, 3); + dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.dci_subframe_repetition_number = rand_range(1, 4); + dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.tpc = rand_range(0, 3); + dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.downlink_assignment_index_length = rand_range(0, 4); + dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.downlink_assignment_index = rand_range(0, 15); + dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.allocate_prach_flag = rand_range(0, 63); + dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.preamble_index = rand_range(0, 15); + dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.prach_mask_index = rand_range(0, 3); + dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.starting_ce_level = rand_range(0, 1); + dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.srs_request = rand_range(0, 1); + dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.antenna_ports_and_scrambling_identity_flag = rand_range(0, 1); + dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.antenna_ports_and_scrambling_identity = rand_range(0, 3); + dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.frequency_hopping_enabled_flag = rand_range(0, 1); + dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.paging_direct_indication_differentiation_flag = rand_range(0, 1); + dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.direct_indication = rand_range(0, 255); + dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.total_dci_length_including_padding = rand_range(0, 1); + dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.number_of_tx_antenna_ports = rand_range(0, 8); + + for(int j = 0 ; j < dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.number_of_tx_antenna_ports; ++j) + dl_config_pdus[i].mpdcch_pdu.mpdcch_pdu_rel13.precoding_value[j] = rand_range(0, 65535); + } + break; + + case NFAPI_DL_CONFIG_NBCH_PDU_TYPE: { + dl_config_pdus[i].nbch_pdu.nbch_pdu_rel13.tl.tag = NFAPI_DL_CONFIG_REQUEST_NBCH_PDU_REL13_TAG; + dl_config_pdus[i].nbch_pdu.nbch_pdu_rel13.length = rand_range(0, 5555); + dl_config_pdus[i].nbch_pdu.nbch_pdu_rel13.pdu_index = rand_range(0, 65535); + dl_config_pdus[i].nbch_pdu.nbch_pdu_rel13.transmission_power = rand_range(0, 10000); + dl_config_pdus[i].nbch_pdu.nbch_pdu_rel13.hyper_sfn_2_lsbs = rand_range(0, 3); + } + break; + + case NFAPI_DL_CONFIG_NPDCCH_PDU_TYPE: { + dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.tl.tag = NFAPI_DL_CONFIG_REQUEST_NPDCCH_PDU_REL13_TAG; + dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.length = rand_range(0, 5555); + dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.pdu_index = rand_range(0, 65535); + dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.ncce_index = rand_range(0, 1); + dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.aggregation_level = rand_range(1, 2); + dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.start_symbol = rand_range(0, 4); + dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.rnti_type = rand_range(0, 3); + dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.rnti = rand_range(1, 65535); + dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.scrambling_reinitialization_batch_index = rand_range(1, 4); + dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.nrs_antenna_ports_assumed_by_the_ue = rand_range(1, 2); + dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.dci_format = rand_range(0, 1); + dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.scheduling_delay = rand_range(0, 7); + dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.resource_assignment = rand_range(0, 7); + dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.repetition_number = rand_range(0, 15); + dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.mcs = rand_range(0, 13); + dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.new_data_indicator = rand_range(0, 1); + dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.harq_ack_resource = rand_range(0, 15); + dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.npdcch_order_indication = rand_range(0, 1); + dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.starting_number_of_nprach_repetitions = rand_range(0, 3); + dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.subcarrier_indication_of_nprach = rand_range(0, 63); + dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.paging_direct_indication_differentation_flag = rand_range(0, 1); + dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.direct_indication = rand_range(0, 255); + dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.dci_subframe_repetition_number = rand_range(0, 7); + dl_config_pdus[i].npdcch_pdu.npdcch_pdu_rel13.total_dci_length_including_padding = rand_range(0, 255); + } + break; + + case NFAPI_DL_CONFIG_NDLSCH_PDU_TYPE: { + dl_config_pdus[i].ndlsch_pdu.ndlsch_pdu_rel13.tl.tag = NFAPI_DL_CONFIG_REQUEST_NDLSCH_PDU_REL13_TAG; + dl_config_pdus[i].ndlsch_pdu.ndlsch_pdu_rel13.length = rand_range(0, 5555); + dl_config_pdus[i].ndlsch_pdu.ndlsch_pdu_rel13.pdu_index = rand_range(0, 65535); + dl_config_pdus[i].ndlsch_pdu.ndlsch_pdu_rel13.start_symbol = rand_range(0, 4); + dl_config_pdus[i].ndlsch_pdu.ndlsch_pdu_rel13.rnti_type = rand_range(0, 1); + dl_config_pdus[i].ndlsch_pdu.ndlsch_pdu_rel13.rnti = rand_range(1, 65535); + dl_config_pdus[i].ndlsch_pdu.ndlsch_pdu_rel13.resource_assignment = rand_range(0, 7); + dl_config_pdus[i].ndlsch_pdu.ndlsch_pdu_rel13.repetition_number = rand_range(0, 15); + dl_config_pdus[i].ndlsch_pdu.ndlsch_pdu_rel13.modulation = 2; + dl_config_pdus[i].ndlsch_pdu.ndlsch_pdu_rel13.number_of_subframes_for_resource_assignment = rand_range(1, 10); + dl_config_pdus[i].ndlsch_pdu.ndlsch_pdu_rel13.scrambling_sequence_initialization_cinit = rand_range(0, 65535); + dl_config_pdus[i].ndlsch_pdu.ndlsch_pdu_rel13.sf_idx = rand_range(1, 10240); + dl_config_pdus[i].ndlsch_pdu.ndlsch_pdu_rel13.nrs_antenna_ports_assumed_by_the_ue = rand_range(1, 2); + } + break; + }; + } + + dl_config_req.dl_config_request_body.dl_config_pdu_list = dl_config_pdus; + mac->dl_config_req(mac, &dl_config_req); + uint8_t num_ul_pdus = 18; + nfapi_ul_config_request_pdu_t ul_config_pdus[num_ul_pdus]; + memset(&ul_config_pdus, 0, sizeof(ul_config_pdus)); + nfapi_ul_config_request_t ul_config_req; + memset(&ul_config_req, 0, sizeof(ul_config_req)); + ul_config_req.header.message_id = NFAPI_UL_CONFIG_REQUEST; + ul_config_req.header.phy_id = phy_id; + ul_config_req.sfn_sf = sfn_sf; + ul_config_req.ul_config_request_body.tl.tag = NFAPI_UL_CONFIG_REQUEST_BODY_TAG; + ul_config_req.ul_config_request_body.number_of_pdus = num_ul_pdus; + ul_config_req.ul_config_request_body.rach_prach_frequency_resources = rand_range(0, 255); + ul_config_req.ul_config_request_body.srs_present = rand_range(0, 1); + auto ul_config_ulsch_pdu_test_gen = [](nfapi_ul_config_ulsch_pdu& ulsch_pdu) { + ulsch_pdu.ulsch_pdu_rel8.tl.tag = NFAPI_UL_CONFIG_REQUEST_ULSCH_PDU_REL8_TAG; + ulsch_pdu.ulsch_pdu_rel8.handle = rand_range(0, 50000); + ulsch_pdu.ulsch_pdu_rel8.size = rand_range(0, 32000); + ulsch_pdu.ulsch_pdu_rel8.rnti = rand_range(1, 65535); + ulsch_pdu.ulsch_pdu_rel8.resource_block_start = rand_range(0, 99); + ulsch_pdu.ulsch_pdu_rel8.number_of_resource_blocks = rand_range(1, 100); + ulsch_pdu.ulsch_pdu_rel8.modulation_type = rand_range(2, 6); + ulsch_pdu.ulsch_pdu_rel8.cyclic_shift_2_for_drms = rand_range(0, 7); + ulsch_pdu.ulsch_pdu_rel8.frequency_hopping_enabled_flag = rand_range(0, 1); + ulsch_pdu.ulsch_pdu_rel8.frequency_hopping_bits = rand_range(0, 3); + ulsch_pdu.ulsch_pdu_rel8.new_data_indication = rand_range(0, 1); + ulsch_pdu.ulsch_pdu_rel8.redundancy_version = rand_range(0, 3); + ulsch_pdu.ulsch_pdu_rel8.harq_process_number = rand_range(0, 15); + ulsch_pdu.ulsch_pdu_rel8.ul_tx_mode = rand_range(0, 1); + ulsch_pdu.ulsch_pdu_rel8.current_tx_nb = rand_range(0, 5); + ulsch_pdu.ulsch_pdu_rel8.n_srs = rand_range(0, 1); + ulsch_pdu.ulsch_pdu_rel10.tl.tag = NFAPI_UL_CONFIG_REQUEST_ULSCH_PDU_REL10_TAG; + ulsch_pdu.ulsch_pdu_rel10.resource_allocation_type = rand_range(0, 1); + ulsch_pdu.ulsch_pdu_rel10.resource_block_coding = rand_range(0, 35000); + ulsch_pdu.ulsch_pdu_rel10.transport_blocks = rand_range(1, 2); + ulsch_pdu.ulsch_pdu_rel10.transmission_scheme = rand_range(0, 1); + ulsch_pdu.ulsch_pdu_rel10.number_of_layers = rand_range(1, 4); + ulsch_pdu.ulsch_pdu_rel10.codebook_index = rand_range(0, 23); + ulsch_pdu.ulsch_pdu_rel10.disable_sequence_hopping_flag = rand_range(0, 1); + ulsch_pdu.ulsch_pdu_rel11.tl.tag = NFAPI_UL_CONFIG_REQUEST_ULSCH_PDU_REL11_TAG; + ulsch_pdu.ulsch_pdu_rel11.virtual_cell_id_enabled_flag = rand_range(0, 1); + ulsch_pdu.ulsch_pdu_rel11.npusch_identity = rand_range(0, 509); + ulsch_pdu.ulsch_pdu_rel11.dmrs_config_flag = rand_range(0, 1); + ulsch_pdu.ulsch_pdu_rel11.ndmrs_csh_identity = rand_range(0, 509); + ulsch_pdu.ulsch_pdu_rel13.tl.tag = NFAPI_UL_CONFIG_REQUEST_ULSCH_PDU_REL13_TAG; + ulsch_pdu.ulsch_pdu_rel13.ue_type = rand_range(0, 2); + ulsch_pdu.ulsch_pdu_rel13.total_number_of_repetitions = rand_range(1, 2048); + ulsch_pdu.ulsch_pdu_rel13.repetition_number = rand_range(1, 2048); + ulsch_pdu.ulsch_pdu_rel13.initial_transmission_sf_io = rand_range(0, 10239); + ulsch_pdu.ulsch_pdu_rel13.empty_symbols_due_to_re_tunning = rand_range(0, 8); + }; + auto ul_config_cqi_ri_info_test_gen = [](nfapi_ul_config_cqi_ri_information& cqi_ri_information) { + cqi_ri_information.cqi_ri_information_rel8.tl.tag = NFAPI_UL_CONFIG_REQUEST_CQI_RI_INFORMATION_REL8_TAG; + cqi_ri_information.cqi_ri_information_rel8.dl_cqi_pmi_size_rank_1 = rand_range(0, 255); + cqi_ri_information.cqi_ri_information_rel8.dl_cqi_pmi_size_rank_greater_1 = rand_range(0, 255); + cqi_ri_information.cqi_ri_information_rel8.ri_size = rand_range(0, 3); + cqi_ri_information.cqi_ri_information_rel8.delta_offset_cqi = rand_range(0, 15); + cqi_ri_information.cqi_ri_information_rel8.delta_offset_ri = rand_range(0, 15); + cqi_ri_information.cqi_ri_information_rel9.tl.tag = NFAPI_UL_CONFIG_REQUEST_CQI_RI_INFORMATION_REL9_TAG; + cqi_ri_information.cqi_ri_information_rel9.report_type = 1; // rand_range(0, 1); + cqi_ri_information.cqi_ri_information_rel9.delta_offset_cqi = rand_range(0, 15); + cqi_ri_information.cqi_ri_information_rel9.delta_offset_ri = rand_range(0, 15); + + if(cqi_ri_information.cqi_ri_information_rel9.report_type == 0) { + cqi_ri_information.cqi_ri_information_rel9.periodic_cqi_pmi_ri_report.dl_cqi_pmi_ri_size = rand_range(0, 255); + cqi_ri_information.cqi_ri_information_rel9.periodic_cqi_pmi_ri_report.control_type = rand_range(0, 1); + } else { + cqi_ri_information.cqi_ri_information_rel9.aperiodic_cqi_pmi_ri_report.number_of_cc = 1; + cqi_ri_information.cqi_ri_information_rel9.aperiodic_cqi_pmi_ri_report.cc[0].ri_size = rand_range(0, 3); + cqi_ri_information.cqi_ri_information_rel9.aperiodic_cqi_pmi_ri_report.cc[0].dl_cqi_pmi_size[0] = rand_range(0, 255); + } + + cqi_ri_information.cqi_ri_information_rel13.tl.tag = NFAPI_UL_CONFIG_REQUEST_CQI_RI_INFORMATION_REL13_TAG; + cqi_ri_information.cqi_ri_information_rel13.report_type = rand_range(0, 1); + + if(cqi_ri_information.cqi_ri_information_rel13.report_type == 0) { + cqi_ri_information.cqi_ri_information_rel13.periodic_cqi_pmi_ri_report.dl_cqi_pmi_ri_size_2 = rand_range(255, 10000); + } + }; + auto ul_config_init_tx_params_test_gen = [](nfapi_ul_config_initial_transmission_parameters& initial_transmission_parameters) { + initial_transmission_parameters.initial_transmission_parameters_rel8.tl.tag = NFAPI_UL_CONFIG_REQUEST_INITIAL_TRANSMISSION_PARAMETERS_REL8_TAG; + initial_transmission_parameters.initial_transmission_parameters_rel8.n_srs_initial = rand_range(0, 1); + initial_transmission_parameters.initial_transmission_parameters_rel8.initial_number_of_resource_blocks = rand_range(1, 100); + }; + auto ul_config_harqinfo_test_gen = [](nfapi_ul_config_ulsch_harq_information& harq_information) { + harq_information.harq_information_rel10.tl.tag = NFAPI_UL_CONFIG_REQUEST_ULSCH_HARQ_INFORMATION_REL10_TAG; + harq_information.harq_information_rel10.harq_size = rand_range(0, 21); + harq_information.harq_information_rel10.delta_offset_harq = rand_range(0, 15); + harq_information.harq_information_rel10.ack_nack_mode = rand_range(0, 5); + harq_information.harq_information_rel13.tl.tag = NFAPI_UL_CONFIG_REQUEST_ULSCH_HARQ_INFORMATION_REL13_TAG; + harq_information.harq_information_rel13.harq_size_2 = rand_range(0, 21); + harq_information.harq_information_rel13.delta_offset_harq_2 = rand_range(0, 15); + }; + auto ul_config_sr_info_test_gen = [](nfapi_ul_config_sr_information& sr_info) { + sr_info.sr_information_rel8.tl.tag = NFAPI_UL_CONFIG_REQUEST_SR_INFORMATION_REL8_TAG; + sr_info.sr_information_rel8.pucch_index = rand_range(0, 2047); + sr_info.sr_information_rel10.tl.tag = NFAPI_UL_CONFIG_REQUEST_SR_INFORMATION_REL10_TAG; + sr_info.sr_information_rel10.number_of_pucch_resources = rand_range(1, 2); + sr_info.sr_information_rel10.pucch_index_p1 = rand_range(0, 2047); + }; + auto ul_config_ue_info_test_gen = [](nfapi_ul_config_ue_information& ue_information) { + ue_information.ue_information_rel8.tl.tag = NFAPI_UL_CONFIG_REQUEST_UE_INFORMATION_REL8_TAG; + ue_information.ue_information_rel8.handle = rand_range(0, 99999); + ue_information.ue_information_rel8.rnti = rand_range(1, 65535); + ue_information.ue_information_rel11.tl.tag = NFAPI_UL_CONFIG_REQUEST_UE_INFORMATION_REL11_TAG; + ue_information.ue_information_rel11.virtual_cell_id_enabled_flag = rand_range(0, 1); + ue_information.ue_information_rel11.npusch_identity = rand_range(0, 503); + ue_information.ue_information_rel13.tl.tag = NFAPI_UL_CONFIG_REQUEST_UE_INFORMATION_REL13_TAG; + ue_information.ue_information_rel13.ue_type = rand_range(0, 2); + ue_information.ue_information_rel13.empty_symbols = rand_range(0, 2); + ue_information.ue_information_rel13.total_number_of_repetitions = rand_range(1, 32); + ue_information.ue_information_rel13.repetition_number = rand_range(1, 32); + }; + auto ul_config_cqi_info_test_gen = [](nfapi_ul_config_cqi_information& cqi_information) { + cqi_information.cqi_information_rel8.tl.tag = NFAPI_UL_CONFIG_REQUEST_CQI_INFORMATION_REL8_TAG; + cqi_information.cqi_information_rel8.pucch_index = rand_range(0, 1184); + cqi_information.cqi_information_rel8.dl_cqi_pmi_size = rand_range(0, 255); + cqi_information.cqi_information_rel10.tl.tag = NFAPI_UL_CONFIG_REQUEST_CQI_INFORMATION_REL10_TAG; + cqi_information.cqi_information_rel10.number_of_pucch_resource = rand_range(1, 2); + cqi_information.cqi_information_rel10.pucch_index_p1 = rand_range(0, 1184); + cqi_information.cqi_information_rel13.tl.tag = NFAPI_UL_CONFIG_REQUEST_CQI_INFORMATION_REL13_TAG; + cqi_information.cqi_information_rel13.csi_mode = rand_range(0, 2); + cqi_information.cqi_information_rel13.dl_cqi_pmi_size_2 = rand_range(0, 999); + cqi_information.cqi_information_rel13.starting_prb = rand_range(0, 109); + cqi_information.cqi_information_rel13.n_prb = rand_range(0, 7); + cqi_information.cqi_information_rel13.cdm_index = rand_range(0, 1); + cqi_information.cqi_information_rel13.n_srs = rand_range(0, 1); + }; + auto ul_config_harq_info_test_gen = [](nfapi_ul_config_harq_information& harq_information) { + harq_information.harq_information_rel10_tdd.tl.tag = NFAPI_UL_CONFIG_REQUEST_HARQ_INFORMATION_REL10_TDD_TAG; + harq_information.harq_information_rel10_tdd.harq_size = rand_range(0, 21); + harq_information.harq_information_rel10_tdd.ack_nack_mode = rand_range(0, 5); + harq_information.harq_information_rel10_tdd.number_of_pucch_resources = rand_range(0, 4); + harq_information.harq_information_rel10_tdd.n_pucch_1_0 = rand_range(0, 2047); + harq_information.harq_information_rel10_tdd.n_pucch_1_1 = rand_range(0, 2047); + harq_information.harq_information_rel10_tdd.n_pucch_1_2 = rand_range(0, 2047); + harq_information.harq_information_rel10_tdd.n_pucch_1_3 = rand_range(0, 2047); + harq_information.harq_information_rel8_fdd.tl.tag = NFAPI_UL_CONFIG_REQUEST_HARQ_INFORMATION_REL8_FDD_TAG; + harq_information.harq_information_rel8_fdd.n_pucch_1_0 = rand_range(0, 2047); + harq_information.harq_information_rel8_fdd.harq_size = rand_range(1, 2); + harq_information.harq_information_rel9_fdd.tl.tag = NFAPI_UL_CONFIG_REQUEST_HARQ_INFORMATION_REL9_FDD_TAG; + harq_information.harq_information_rel9_fdd.harq_size = rand_range(1, 10); + harq_information.harq_information_rel9_fdd.ack_nack_mode = rand_range(0, 4); + harq_information.harq_information_rel9_fdd.number_of_pucch_resources = rand_range(0, 4); + harq_information.harq_information_rel9_fdd.n_pucch_1_0 = rand_range(0, 2047); + harq_information.harq_information_rel9_fdd.n_pucch_1_1 = rand_range(0, 2047); + harq_information.harq_information_rel9_fdd.n_pucch_1_2 = rand_range(0, 2047); + harq_information.harq_information_rel9_fdd.n_pucch_1_3 = rand_range(0, 2047); + harq_information.harq_information_rel11.tl.tag = NFAPI_UL_CONFIG_REQUEST_HARQ_INFORMATION_REL11_TAG; + harq_information.harq_information_rel11.num_ant_ports = rand_range(1, 2); + harq_information.harq_information_rel11.n_pucch_2_0 = rand_range(0, 2047); + harq_information.harq_information_rel11.n_pucch_2_1 = rand_range(0, 2047); + harq_information.harq_information_rel11.n_pucch_2_2 = rand_range(0, 2047); + harq_information.harq_information_rel11.n_pucch_2_3 = rand_range(0, 2047); + harq_information.harq_information_rel13.tl.tag = NFAPI_UL_CONFIG_REQUEST_HARQ_INFORMATION_REL13_TAG; + harq_information.harq_information_rel13.harq_size_2 = rand_range(0, 999); + harq_information.harq_information_rel13.starting_prb = rand_range(0, 109); + harq_information.harq_information_rel13.n_prb = rand_range(0, 7); + harq_information.harq_information_rel13.cdm_index = rand_range(0, 1); + harq_information.harq_information_rel13.n_srs = rand_range(0, 1); + }; + ul_config_pdus[0].pdu_type = NFAPI_UL_CONFIG_ULSCH_PDU_TYPE; + ul_config_ulsch_pdu_test_gen(ul_config_pdus[0].ulsch_pdu); + ul_config_pdus[1].pdu_type = NFAPI_UL_CONFIG_ULSCH_CQI_RI_PDU_TYPE; + ul_config_ulsch_pdu_test_gen(ul_config_pdus[1].ulsch_cqi_ri_pdu.ulsch_pdu); + ul_config_cqi_ri_info_test_gen(ul_config_pdus[1].ulsch_cqi_ri_pdu.cqi_ri_information); + ul_config_init_tx_params_test_gen(ul_config_pdus[1].ulsch_cqi_ri_pdu.initial_transmission_parameters); + ul_config_pdus[2].pdu_type = NFAPI_UL_CONFIG_ULSCH_HARQ_PDU_TYPE; + ul_config_ulsch_pdu_test_gen(ul_config_pdus[2].ulsch_harq_pdu.ulsch_pdu); + ul_config_harqinfo_test_gen(ul_config_pdus[2].ulsch_harq_pdu.harq_information); + ul_config_init_tx_params_test_gen(ul_config_pdus[2].ulsch_harq_pdu.initial_transmission_parameters); + ul_config_pdus[3].pdu_type = NFAPI_UL_CONFIG_ULSCH_CQI_HARQ_RI_PDU_TYPE; + ul_config_ulsch_pdu_test_gen(ul_config_pdus[3].ulsch_cqi_harq_ri_pdu.ulsch_pdu); + ul_config_cqi_ri_info_test_gen(ul_config_pdus[3].ulsch_cqi_harq_ri_pdu.cqi_ri_information); + ul_config_harqinfo_test_gen(ul_config_pdus[3].ulsch_cqi_harq_ri_pdu.harq_information); + ul_config_init_tx_params_test_gen(ul_config_pdus[3].ulsch_cqi_harq_ri_pdu.initial_transmission_parameters); + ul_config_pdus[4].pdu_type = NFAPI_UL_CONFIG_UCI_CQI_PDU_TYPE; + ul_config_ue_info_test_gen(ul_config_pdus[4].uci_cqi_pdu.ue_information); + ul_config_cqi_info_test_gen(ul_config_pdus[4].uci_cqi_pdu.cqi_information); + ul_config_pdus[5].pdu_type = NFAPI_UL_CONFIG_UCI_SR_PDU_TYPE; + ul_config_ue_info_test_gen(ul_config_pdus[5].uci_sr_pdu.ue_information); + ul_config_sr_info_test_gen(ul_config_pdus[5].uci_sr_pdu.sr_information); + ul_config_pdus[6].pdu_type = NFAPI_UL_CONFIG_UCI_HARQ_PDU_TYPE; + ul_config_ue_info_test_gen(ul_config_pdus[6].uci_harq_pdu.ue_information); + ul_config_harq_info_test_gen(ul_config_pdus[6].uci_harq_pdu.harq_information); + ul_config_pdus[7].pdu_type = NFAPI_UL_CONFIG_UCI_SR_HARQ_PDU_TYPE; + ul_config_ue_info_test_gen(ul_config_pdus[7].uci_sr_harq_pdu.ue_information); + ul_config_sr_info_test_gen(ul_config_pdus[7].uci_sr_harq_pdu.sr_information); + ul_config_harq_info_test_gen(ul_config_pdus[7].uci_sr_harq_pdu.harq_information); + ul_config_pdus[8].pdu_type = NFAPI_UL_CONFIG_UCI_CQI_HARQ_PDU_TYPE; + ul_config_ue_info_test_gen(ul_config_pdus[8].uci_cqi_harq_pdu.ue_information); + ul_config_cqi_info_test_gen(ul_config_pdus[8].uci_cqi_harq_pdu.cqi_information); + ul_config_harq_info_test_gen(ul_config_pdus[8].uci_cqi_harq_pdu.harq_information); + ul_config_pdus[9].pdu_type = NFAPI_UL_CONFIG_UCI_CQI_SR_PDU_TYPE; + ul_config_ue_info_test_gen(ul_config_pdus[9].uci_cqi_sr_pdu.ue_information); + ul_config_cqi_info_test_gen(ul_config_pdus[9].uci_cqi_sr_pdu.cqi_information); + ul_config_sr_info_test_gen(ul_config_pdus[9].uci_cqi_sr_pdu.sr_information); + ul_config_pdus[10].pdu_type = NFAPI_UL_CONFIG_UCI_CQI_SR_HARQ_PDU_TYPE; + ul_config_ue_info_test_gen(ul_config_pdus[10].uci_cqi_sr_harq_pdu.ue_information); + ul_config_cqi_info_test_gen(ul_config_pdus[10].uci_cqi_sr_harq_pdu.cqi_information); + ul_config_sr_info_test_gen(ul_config_pdus[10].uci_cqi_sr_harq_pdu.sr_information); + ul_config_harq_info_test_gen(ul_config_pdus[10].uci_cqi_sr_harq_pdu.harq_information); + ul_config_pdus[11].pdu_type = NFAPI_UL_CONFIG_SRS_PDU_TYPE; + ul_config_pdus[11].srs_pdu.srs_pdu_rel8.tl.tag = NFAPI_UL_CONFIG_REQUEST_SRS_PDU_REL8_TAG; + ul_config_pdus[11].srs_pdu.srs_pdu_rel8.handle = rand_range(0, 9999); + ul_config_pdus[11].srs_pdu.srs_pdu_rel8.size = rand_range(1, 999); + ul_config_pdus[11].srs_pdu.srs_pdu_rel8.rnti = rand_range(1, 65535); + ul_config_pdus[11].srs_pdu.srs_pdu_rel8.srs_bandwidth = rand_range(0, 3); + ul_config_pdus[11].srs_pdu.srs_pdu_rel8.frequency_domain_position = rand_range(0, 23); + ul_config_pdus[11].srs_pdu.srs_pdu_rel8.srs_hopping_bandwidth = rand_range(0, 3); + ul_config_pdus[11].srs_pdu.srs_pdu_rel8.transmission_comb = rand_range(0, 3); + ul_config_pdus[11].srs_pdu.srs_pdu_rel8.i_srs = rand_range(0, 1023); + ul_config_pdus[11].srs_pdu.srs_pdu_rel8.sounding_reference_cyclic_shift = rand_range(0, 11); + ul_config_pdus[11].srs_pdu.srs_pdu_rel10.tl.tag = NFAPI_UL_CONFIG_REQUEST_SRS_PDU_REL10_TAG; + ul_config_pdus[11].srs_pdu.srs_pdu_rel10.antenna_port = rand_range(0, 2); + ul_config_pdus[11].srs_pdu.srs_pdu_rel13.tl.tag = NFAPI_UL_CONFIG_REQUEST_SRS_PDU_REL13_TAG; + ul_config_pdus[11].srs_pdu.srs_pdu_rel13.number_of_combs = rand_range(0, 1); + ul_config_pdus[12].pdu_type = NFAPI_UL_CONFIG_HARQ_BUFFER_PDU_TYPE; + ul_config_ue_info_test_gen(ul_config_pdus[12].harq_buffer_pdu.ue_information); + ul_config_pdus[13].pdu_type = NFAPI_UL_CONFIG_ULSCH_UCI_CSI_PDU_TYPE; + ul_config_ulsch_pdu_test_gen(ul_config_pdus[13].ulsch_uci_csi_pdu.ulsch_pdu); + ul_config_cqi_info_test_gen(ul_config_pdus[13].ulsch_uci_csi_pdu.csi_information); + ul_config_pdus[14].pdu_type = NFAPI_UL_CONFIG_ULSCH_UCI_HARQ_PDU_TYPE; + ul_config_ulsch_pdu_test_gen(ul_config_pdus[14].ulsch_uci_harq_pdu.ulsch_pdu); + ul_config_harq_info_test_gen(ul_config_pdus[14].ulsch_uci_harq_pdu.harq_information); + ul_config_pdus[15].pdu_type = NFAPI_UL_CONFIG_ULSCH_CSI_UCI_HARQ_PDU_TYPE; + ul_config_ulsch_pdu_test_gen(ul_config_pdus[15].ulsch_csi_uci_harq_pdu.ulsch_pdu); + ul_config_cqi_info_test_gen(ul_config_pdus[15].ulsch_csi_uci_harq_pdu.csi_information); + ul_config_harq_info_test_gen(ul_config_pdus[15].ulsch_csi_uci_harq_pdu.harq_information); + ul_config_pdus[16].pdu_type = NFAPI_UL_CONFIG_NULSCH_PDU_TYPE; + ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.tl.tag = NFAPI_UL_CONFIG_REQUEST_NULSCH_PDU_REL13_TAG; + ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.nulsch_format = rand_range(0, 1); + ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.handle = rand_range(0, 0xFFFF); + ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.size = rand_range(0, 65535); + ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.rnti = rand_range(1, 65535); + ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.subcarrier_indication = rand_range(0, 47); + ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.resource_assignment = rand_range(0, 7); + ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.mcs = rand_range(0, 12); + ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.redudancy_version = rand_range(0, 1); + ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.repetition_number = rand_range(0, 7); + ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.new_data_indication = rand_range(0, 1); + ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.n_srs = rand_range(0, 1); + ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.scrambling_sequence_initialization_cinit = rand_range(0, 65535); + ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.sf_idx = rand_range(0, 40960); + ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.ue_information.ue_information_rel8.tl.tag = NFAPI_UL_CONFIG_REQUEST_UE_INFORMATION_REL8_TAG; + ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.ue_information.ue_information_rel8.handle = rand_range(0, 0xFF); + ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.ue_information.ue_information_rel8.rnti = rand_range(1, 65535); + ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.ue_information.ue_information_rel11.tl.tag = NFAPI_UL_CONFIG_REQUEST_UE_INFORMATION_REL11_TAG; + ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.ue_information.ue_information_rel11.virtual_cell_id_enabled_flag = rand_range(0, 1); + ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.ue_information.ue_information_rel11.npusch_identity = rand_range(0, 503); + ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.ue_information.ue_information_rel13.tl.tag = NFAPI_UL_CONFIG_REQUEST_UE_INFORMATION_REL13_TAG; + ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.ue_information.ue_information_rel13.ue_type = rand_range(0, 2); + ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.ue_information.ue_information_rel13.empty_symbols = rand_range(0, 0x3); + ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.ue_information.ue_information_rel13.total_number_of_repetitions = rand_range(1, 32); + ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.ue_information.ue_information_rel13.repetition_number = rand_range(1, 32); + ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.nb_harq_information.nb_harq_information_rel13_fdd.tl.tag = NFAPI_UL_CONFIG_REQUEST_NB_HARQ_INFORMATION_REL13_FDD_TAG; + ul_config_pdus[16].nulsch_pdu.nulsch_pdu_rel13.nb_harq_information.nb_harq_information_rel13_fdd.harq_ack_resource = rand_range(0, 15); + ul_config_pdus[17].pdu_type = NFAPI_UL_CONFIG_NRACH_PDU_TYPE; + ul_config_pdus[17].nrach_pdu.nrach_pdu_rel13.tl.tag = NFAPI_UL_CONFIG_REQUEST_NRACH_PDU_REL13_TAG; + ul_config_pdus[17].nrach_pdu.nrach_pdu_rel13.nprach_config_0 = rand_range(0, 1); + ul_config_pdus[17].nrach_pdu.nrach_pdu_rel13.nprach_config_1 = rand_range(0, 1); + ul_config_pdus[17].nrach_pdu.nrach_pdu_rel13.nprach_config_2 = rand_range(0, 1); + ul_config_req.ul_config_request_body.ul_config_pdu_list = ul_config_pdus; + mac->ul_config_req(mac, &ul_config_req); + uint8_t num_dci_pdus = 4; + uint8_t num_hi_pdus = 1; + nfapi_hi_dci0_request_pdu_t hi_dci0_pdus[num_dci_pdus + num_hi_pdus]; + memset(&hi_dci0_pdus, 0, sizeof(hi_dci0_pdus)); + nfapi_hi_dci0_request_t hi_dci0_req; + memset(&hi_dci0_req, 0, sizeof(hi_dci0_req)); + hi_dci0_req.header.message_id = NFAPI_HI_DCI0_REQUEST; + hi_dci0_req.header.phy_id = phy_id; + hi_dci0_req.sfn_sf = sfn_sf; + hi_dci0_req.hi_dci0_request_body.tl.tag = NFAPI_HI_DCI0_REQUEST_BODY_TAG; + hi_dci0_req.hi_dci0_request_body.sfnsf = sfn_sf; + hi_dci0_req.hi_dci0_request_body.number_of_dci = num_dci_pdus; + hi_dci0_req.hi_dci0_request_body.number_of_hi = num_hi_pdus; + hi_dci0_pdus[0].pdu_type = NFAPI_HI_DCI0_HI_PDU_TYPE; + hi_dci0_pdus[0].hi_pdu.hi_pdu_rel8.tl.tag = NFAPI_HI_DCI0_REQUEST_HI_PDU_REL8_TAG; + hi_dci0_pdus[0].hi_pdu.hi_pdu_rel8.resource_block_start = rand_range(0, 100); + hi_dci0_pdus[0].hi_pdu.hi_pdu_rel8.cyclic_shift_2_for_drms = rand_range(0, 7); + hi_dci0_pdus[0].hi_pdu.hi_pdu_rel8.hi_value = rand_range(0, 1); + hi_dci0_pdus[0].hi_pdu.hi_pdu_rel8.i_phich = rand_range(0, 1); + hi_dci0_pdus[0].hi_pdu.hi_pdu_rel8.transmission_power = rand_range(0, 10000); + hi_dci0_pdus[0].hi_pdu.hi_pdu_rel10.tl.tag = NFAPI_HI_DCI0_REQUEST_HI_PDU_REL10_TAG; + hi_dci0_pdus[0].hi_pdu.hi_pdu_rel10.flag_tb2 = rand_range(0, 1); + hi_dci0_pdus[0].hi_pdu.hi_pdu_rel10.hi_value_2 = rand_range(0, 1); + hi_dci0_pdus[1].pdu_type = NFAPI_HI_DCI0_DCI_PDU_TYPE; + hi_dci0_pdus[1].dci_pdu.dci_pdu_rel8.tl.tag = NFAPI_HI_DCI0_REQUEST_DCI_PDU_REL8_TAG; + hi_dci0_pdus[1].dci_pdu.dci_pdu_rel8.dci_format = rand_range(0, 4); + hi_dci0_pdus[1].dci_pdu.dci_pdu_rel8.cce_index = rand_range(0, 88); + hi_dci0_pdus[1].dci_pdu.dci_pdu_rel8.aggregation_level = rand_range(1, 8); + hi_dci0_pdus[1].dci_pdu.dci_pdu_rel8.rnti = rand_range(1, 65535); + hi_dci0_pdus[1].dci_pdu.dci_pdu_rel8.resource_block_start = rand_range(0, 100); + hi_dci0_pdus[1].dci_pdu.dci_pdu_rel8.number_of_resource_block = rand_range(0, 100); + hi_dci0_pdus[1].dci_pdu.dci_pdu_rel8.mcs_1 = rand_range(0, 31); + hi_dci0_pdus[1].dci_pdu.dci_pdu_rel8.cyclic_shift_2_for_drms = rand_range(0, 7); + hi_dci0_pdus[1].dci_pdu.dci_pdu_rel8.frequency_hopping_enabled_flag = rand_range(0, 1); + hi_dci0_pdus[1].dci_pdu.dci_pdu_rel8.frequency_hopping_bits = rand_range(0, 3); + hi_dci0_pdus[1].dci_pdu.dci_pdu_rel8.new_data_indication_1 = rand_range(0, 1); + hi_dci0_pdus[1].dci_pdu.dci_pdu_rel8.ue_tx_antenna_seleciton = rand_range(0, 2); + hi_dci0_pdus[1].dci_pdu.dci_pdu_rel8.tpc = rand_range(0, 3); + hi_dci0_pdus[1].dci_pdu.dci_pdu_rel8.cqi_csi_request = rand_range(0, 7); + hi_dci0_pdus[1].dci_pdu.dci_pdu_rel8.ul_index = rand_range(0, 3); + hi_dci0_pdus[1].dci_pdu.dci_pdu_rel8.dl_assignment_index = rand_range(1, 4); + hi_dci0_pdus[1].dci_pdu.dci_pdu_rel8.tpc_bitmap = rand_range(0, 9999); + hi_dci0_pdus[1].dci_pdu.dci_pdu_rel8.transmission_power = rand_range(0, 10000); + hi_dci0_pdus[1].dci_pdu.dci_pdu_rel10.tl.tag = NFAPI_HI_DCI0_REQUEST_DCI_PDU_REL10_TAG; + hi_dci0_pdus[1].dci_pdu.dci_pdu_rel10.cross_carrier_scheduling_flag = rand_range(0, 1); + hi_dci0_pdus[1].dci_pdu.dci_pdu_rel10.carrier_indicator = rand_range(0, 7); + hi_dci0_pdus[1].dci_pdu.dci_pdu_rel10.size_of_cqi_csi_feild = rand_range(0, 2); + hi_dci0_pdus[1].dci_pdu.dci_pdu_rel10.srs_flag = rand_range(0, 1); + hi_dci0_pdus[1].dci_pdu.dci_pdu_rel10.srs_request = rand_range(0, 1); + hi_dci0_pdus[1].dci_pdu.dci_pdu_rel10.resource_allocation_flag = rand_range(0, 1); + hi_dci0_pdus[1].dci_pdu.dci_pdu_rel10.resource_allocation_type = rand_range(0, 1); + hi_dci0_pdus[1].dci_pdu.dci_pdu_rel10.resource_block_coding = rand_range(0, 9999); + hi_dci0_pdus[1].dci_pdu.dci_pdu_rel10.mcs_2 = rand_range(0, 31); + hi_dci0_pdus[1].dci_pdu.dci_pdu_rel10.new_data_indication_2 = rand_range(0, 1); + hi_dci0_pdus[1].dci_pdu.dci_pdu_rel10.number_of_antenna_ports = rand_range(0, 2); + hi_dci0_pdus[1].dci_pdu.dci_pdu_rel10.tpmi = rand_range(0, 63); + hi_dci0_pdus[1].dci_pdu.dci_pdu_rel10.total_dci_length_including_padding = rand_range(0, 255); + hi_dci0_pdus[1].dci_pdu.dci_pdu_rel10.n_ul_rb = rand_range(6, 100); + hi_dci0_pdus[1].dci_pdu.dci_pdu_rel12.tl.tag = NFAPI_HI_DCI0_REQUEST_DCI_PDU_REL12_TAG; + hi_dci0_pdus[1].dci_pdu.dci_pdu_rel12.pscch_resource = rand_range(0, 16); + hi_dci0_pdus[1].dci_pdu.dci_pdu_rel12.time_resource_pattern = rand_range(0, 32); + hi_dci0_pdus[2].pdu_type = NFAPI_HI_DCI0_EPDCCH_DCI_PDU_TYPE; + hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel8.tl.tag = NFAPI_HI_DCI0_REQUEST_EPDCCH_DCI_PDU_REL8_TAG; + hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel8.dci_format = rand_range(0, 4); + hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel8.cce_index = rand_range(0, 88); + hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel8.aggregation_level = rand_range(1, 8); + hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel8.rnti = rand_range(1, 65535); + hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel8.resource_block_start = rand_range(0, 100); + hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel8.number_of_resource_block = rand_range(0, 100); + hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel8.mcs_1 = rand_range(0, 31); + hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel8.cyclic_shift_2_for_drms = rand_range(0, 7); + hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel8.frequency_hopping_enabled_flag = rand_range(0, 1); + hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel8.frequency_hopping_bits = rand_range(0, 3); + hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel8.new_data_indication_1 = rand_range(0, 1); + hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel8.ue_tx_antenna_seleciton = rand_range(0, 2); + hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel8.tpc = rand_range(0, 3); + hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel8.cqi_csi_request = rand_range(0, 7); + hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel8.ul_index = rand_range(0, 3); + hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel8.dl_assignment_index = rand_range(1, 4); + hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel8.tpc_bitmap = rand_range(0, 9999); + hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel8.transmission_power = rand_range(0, 10000); + hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel10.tl.tag = NFAPI_HI_DCI0_REQUEST_EPDCCH_DCI_PDU_REL10_TAG; + hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel10.cross_carrier_scheduling_flag = rand_range(0, 1); + hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel10.carrier_indicator = rand_range(0, 7); + hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel10.size_of_cqi_csi_feild = rand_range(0, 2); + hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel10.srs_flag = rand_range(0, 1); + hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel10.srs_request = rand_range(0, 1); + hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel10.resource_allocation_flag = rand_range(0, 1); + hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel10.resource_allocation_type = rand_range(0, 1); + hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel10.resource_block_coding = rand_range(0, 9999); + hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel10.mcs_2 = rand_range(0, 31); + hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel10.new_data_indication_2 = rand_range(0, 1); + hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel10.number_of_antenna_ports = rand_range(0, 2); + hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel10.tpmi = rand_range(0, 63); + hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel10.total_dci_length_including_padding = rand_range(0, 255); + hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_dci_pdu_rel10.n_ul_rb = rand_range(6, 100); + hi_dci0_pdus[2].epdcch_dci_pdu.epdcch_parameters_rel11.tl.tag = NFAPI_HI_DCI0_REQUEST_EPDCCH_PARAMETERS_REL11_TAG; + hi_dci0_pdus[3].pdu_type = NFAPI_HI_DCI0_MPDCCH_DCI_PDU_TYPE; + hi_dci0_pdus[3].mpdcch_dci_pdu.mpdcch_dci_pdu_rel13.tl.tag = NFAPI_HI_DCI0_REQUEST_MPDCCH_DCI_PDU_REL13_TAG; + hi_dci0_pdus[4].pdu_type = NFAPI_HI_DCI0_NPDCCH_DCI_PDU_TYPE; + hi_dci0_pdus[4].npdcch_dci_pdu.npdcch_dci_pdu_rel13.tl.tag = NFAPI_HI_DCI0_REQUEST_NPDCCH_DCI_PDU_REL13_TAG; + hi_dci0_pdus[4].npdcch_dci_pdu.npdcch_dci_pdu_rel13.ncce_index = rand_range(0, 1); + hi_dci0_pdus[4].npdcch_dci_pdu.npdcch_dci_pdu_rel13.aggregation_level = rand_range(1, 2); + hi_dci0_pdus[4].npdcch_dci_pdu.npdcch_dci_pdu_rel13.start_symbol = rand_range(0, 4); + hi_dci0_pdus[4].npdcch_dci_pdu.npdcch_dci_pdu_rel13.rnti = rand_range(1, 65535); + hi_dci0_pdus[4].npdcch_dci_pdu.npdcch_dci_pdu_rel13.scrambling_reinitialization_batch_index = rand_range(1, 4); + hi_dci0_pdus[4].npdcch_dci_pdu.npdcch_dci_pdu_rel13.nrs_antenna_ports_assumed_by_the_ue = rand_range(1, 2); + hi_dci0_pdus[4].npdcch_dci_pdu.npdcch_dci_pdu_rel13.subcarrier_indication = rand_range(0, 63); + hi_dci0_pdus[4].npdcch_dci_pdu.npdcch_dci_pdu_rel13.resource_assignment = rand_range(0, 7); + hi_dci0_pdus[4].npdcch_dci_pdu.npdcch_dci_pdu_rel13.scheduling_delay = rand_range(0, 3); + hi_dci0_pdus[4].npdcch_dci_pdu.npdcch_dci_pdu_rel13.mcs = rand_range(0, 12); + hi_dci0_pdus[4].npdcch_dci_pdu.npdcch_dci_pdu_rel13.redudancy_version = rand_range(0, 1); + hi_dci0_pdus[4].npdcch_dci_pdu.npdcch_dci_pdu_rel13.repetition_number = rand_range(0, 7); + hi_dci0_pdus[4].npdcch_dci_pdu.npdcch_dci_pdu_rel13.new_data_indicator = rand_range(0, 1); + hi_dci0_pdus[4].npdcch_dci_pdu.npdcch_dci_pdu_rel13.dci_subframe_repetition_number = rand_range(0, 3); + hi_dci0_req.hi_dci0_request_body.hi_dci0_pdu_list = hi_dci0_pdus; + mac->hi_dci0_req(mac, &hi_dci0_req); + uint8_t num_tx_pdus = 2; + nfapi_tx_request_pdu_t tx_pdus[num_tx_pdus]; + memset(&tx_pdus, 0, sizeof(tx_pdus)); + nfapi_tx_request_t tx_req; + memset(&tx_req, 0, sizeof(tx_req)); + tx_req.header.message_id = NFAPI_TX_REQUEST; + tx_req.header.phy_id = phy_id; + tx_req.sfn_sf = sfn_sf; + tx_req.tx_request_body.tl.tag = NFAPI_TX_REQUEST_BODY_TAG; + tx_req.tx_request_body.number_of_pdus = num_tx_pdus; + uint32_t data[2]; + data[0] = 0x11223344; + data[1] = 0x55667788; + tx_pdus[0].pdu_length = 8; + tx_pdus[0].pdu_index = 1; + tx_pdus[0].num_segments = 2; + tx_pdus[0].segments[0].segment_length = 4; + tx_pdus[0].segments[0].segment_data = (uint8_t *)&data[0]; + tx_pdus[0].segments[1].segment_length = 4; + tx_pdus[0].segments[1].segment_data = (uint8_t *)&data[1]; + tx_pdus[1].pdu_length = 8; + tx_pdus[1].pdu_index = 2; + tx_pdus[1].num_segments = 2; + tx_pdus[1].segments[0].segment_length = 4; + tx_pdus[1].segments[0].segment_data = (uint8_t *)&data[0]; + tx_pdus[1].segments[1].segment_length = 4; + tx_pdus[1].segments[1].segment_data = (uint8_t *)&data[1]; + tx_req.tx_request_body.tx_pdu_list = tx_pdus; + mac->tx_req(mac, &tx_req); + } + + void generate_subframe(mac_t *mac, uint16_t phy_id, uint16_t sfn_sf) { + mac_internal_t *instance = (mac_internal_t *)mac; + nfapi_dl_config_request_t dl_config_req; + memset(&dl_config_req, 0, sizeof(dl_config_req)); + dl_config_req.header.message_id = NFAPI_DL_CONFIG_REQUEST; + dl_config_req.header.phy_id = phy_id; + dl_config_req.sfn_sf = sfn_sf; + dl_config_req.dl_config_request_body.tl.tag = NFAPI_DL_CONFIG_REQUEST_BODY_TAG; + dl_config_req.dl_config_request_body.number_pdu = 8; + nfapi_dl_config_request_pdu_t pdus[8]; + memset(&pdus, 0, sizeof(pdus)); + + for(int i = 0; i < 8; i++) { + pdus[i].pdu_type = NFAPI_DL_CONFIG_BCH_PDU_TYPE; + pdus[i].bch_pdu.bch_pdu_rel8.tl.tag = NFAPI_DL_CONFIG_REQUEST_BCH_PDU_REL8_TAG; + pdus[i].bch_pdu.bch_pdu_rel8.length = 42; + pdus[i].bch_pdu.bch_pdu_rel8.pdu_index = i; + pdus[i].bch_pdu.bch_pdu_rel8.transmission_power = 56; + } + + dl_config_req.dl_config_request_body.dl_config_pdu_list = pdus; + /* + vendor_ext_tlv_1 ve; + ve.tl.tag = VENDOR_EXT_TLV_1_TAG; + ve.dummy = 999; + dl_config_req.vendor_extension = &ve.tl; + */ + mac->dl_config_req(mac, &dl_config_req); + nfapi_ul_config_request_t ul_config_req; + memset(&ul_config_req, 0, sizeof(ul_config_req)); + ul_config_req.header.message_id = NFAPI_UL_CONFIG_REQUEST; + ul_config_req.header.phy_id = phy_id; + ul_config_req.sfn_sf = sfn_sf; + mac->ul_config_req(mac, &ul_config_req); + nfapi_hi_dci0_request_t hi_dci0_req; + memset(&hi_dci0_req, 0, sizeof(hi_dci0_req)); + hi_dci0_req.header.message_id = NFAPI_HI_DCI0_REQUEST; + hi_dci0_req.header.phy_id = phy_id; + hi_dci0_req.sfn_sf = sfn_sf; + mac->hi_dci0_req(mac, &hi_dci0_req); + nfapi_tx_request_t tx_req; + memset(&tx_req, 0, sizeof(tx_req)); + tx_req.header.message_id = NFAPI_TX_REQUEST; + tx_req.header.phy_id = phy_id; + tx_req.sfn_sf = sfn_sf; + nfapi_tx_request_pdu_t tx_pdus[8]; + tx_req.tx_request_body.tl.tag = NFAPI_TX_REQUEST_BODY_TAG; + tx_req.tx_request_body.number_of_pdus = 0; + tx_req.tx_request_body.tx_pdu_list = &tx_pdus[0]; + mac_pdu *buff = 0; + int i = 0; + std::list<mac_pdu *> free_list; + + do { + buff = instance->mac->pop_rx_buffer(); + + if(buff != 0) { + if(buff->len == 0) { + printf("[MAC] Buffer length = 0\n"); + } + + tx_req.tx_request_body.tx_pdu_list[i].pdu_length = buff->len; + tx_req.tx_request_body.tx_pdu_list[i].pdu_index = i; + tx_req.tx_request_body.tx_pdu_list[i].num_segments = 1; + tx_req.tx_request_body.tx_pdu_list[i].segments[0].segment_length = buff->len; + tx_req.tx_request_body.tx_pdu_list[i].segments[0].segment_data = (uint8_t *)buff->buffer; + tx_req.tx_request_body.number_of_pdus++; + i++; + instance->mac->byte_count += buff->len; + free_list.push_back(buff); + } + } while(buff != 0 && i < 8); + + mac->tx_req(mac, &tx_req); + + //for(int j = 0; j < tx_req.tx_request_body.number_of_pdus; ++j) + for(mac_pdu *pdu : free_list) { + instance->mac->release_mac_pdu(pdu); + //free(tx_req.tx_request_body.tx_pdu_list[j].segments[0].segment_data); + } + } + + void mac_subframe_ind(mac_t *mac, uint16_t phy_id, uint16_t sfn_sf) { + //printf("[MAC] subframe indication phyid:%d sfnsf:%d\n", phy_id, sfn_sf); + mac_internal_t *instance = (mac_internal_t *)mac; + + if(instance->mac->tick == 1000) { + if(instance->mac->byte_count > 0) { + printf("[MAC] Rx rate %d bytes/sec\n", instance->mac->byte_count); + instance->mac->byte_count = 0; + } + + instance->mac->tick = 0; + } + + instance->mac->tick++; + + if(instance->mac->wireshark_test_mode) { + generate_test_subframe(mac, phy_id, sfn_sf); + } else { + generate_subframe(mac, phy_id, sfn_sf); + } + } + + void mac_harq_ind(mac_t *mac, nfapi_harq_indication_t *ind) { + } + void mac_crc_ind(mac_t *mac, nfapi_crc_indication_t *ind) { + } + void mac_rx_ind(mac_t *mac, nfapi_rx_indication_t *ind) { + mac_internal_t *instance = (mac_internal_t *)mac; + + for(int i = 0; i < ind->rx_indication_body.number_of_pdus; ++i) { + uint16_t len = ind->rx_indication_body.rx_pdu_list[i].rx_indication_rel8.length; + uint8_t *data = ind->rx_indication_body.rx_pdu_list[i].data; + //printf("[MAC] sfnsf:%d len:%d\n", ind->sfn_sf,len); + // + instance->tx_byte_count += len; + int sendto_result = sendto(instance->tx_sock, data, len, 0, (struct sockaddr *)&(instance->tx_addr), sizeof(instance->tx_addr)); + + if(sendto_result < 0) { + // error + } + } + } + void mac_rach_ind(mac_t *mac, nfapi_rach_indication_t *ind) { + } + void mac_srs_ind(mac_t *mac, nfapi_srs_indication_t *ind) { + } + void mac_sr_ind(mac_t *mac, nfapi_sr_indication_t *ind) { + } + void mac_cqi_ind(mac_t *mac, nfapi_cqi_indication_t *ind) { + } + void mac_lbt_dl_ind(mac_t *mac, nfapi_lbt_dl_indication_t *ind) { + } + void mac_nb_harq_ind(mac_t *mac, nfapi_nb_harq_indication_t *ind) { + } + void mac_nrach_ind(mac_t *mac, nfapi_nrach_indication_t *ind) { + } } diff --git a/nfapi/open-nFAPI/vnf_sim/src/main.cpp b/nfapi/open-nFAPI/vnf_sim/src/main.cpp index 5dc7161157defe8b5c6e3b8d5b10c445cf79a25d..dedf06174f43b435fd1ddf97ec6cc30af9815767 100644 --- a/nfapi/open-nFAPI/vnf_sim/src/main.cpp +++ b/nfapi/open-nFAPI/vnf_sim/src/main.cpp @@ -1,12 +1,12 @@ /* * Copyright 2017 Cisco Systems, Inc. - * + * * Licensed 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. @@ -38,8 +38,8 @@ #include <boost/foreach.hpp> #include <boost/property_tree/xml_parser.hpp> #include <boost/property_tree/ptree.hpp> -#include <boost/exception/diagnostic_information.hpp> -#include <boost/exception_ptr.hpp> +#include <boost/exception/diagnostic_information.hpp> +#include <boost/exception_ptr.hpp> extern "C" { #include <nfapi_vnf_interface.h> @@ -48,606 +48,486 @@ extern "C" { #include <vendor_ext.h> -//int vnf_main(int iPortP5, int, int); -int start_simulated_mac(int*, int*); -int read_xml(const char *xml_file); + //int vnf_main(int iPortP5, int, int); + int start_simulated_mac(int *, int *); + int read_xml(const char *xml_file); } -static uint32_t rand_range(uint32_t min, uint32_t max) -{ - return ((rand() % (max + 1 - min)) + min); +static uint32_t rand_range(uint32_t min, uint32_t max) { + return ((rand() % (max + 1 - min)) + min); } -void* vnf_allocate(size_t size) -{ - return (void*)memory_pool::allocate(size); +void *vnf_allocate(size_t size) { + return (void *)memory_pool::allocate(size); } -void vnf_deallocate(void* ptr) -{ - memory_pool::deallocate((uint8_t*)ptr); +void vnf_deallocate(void *ptr) { + memory_pool::deallocate((uint8_t *)ptr); } -class udp_data -{ - public: - bool enabled; - uint32_t rx_port; - uint32_t tx_port; - std::string tx_addr; +class udp_data { + public: + bool enabled; + uint32_t rx_port; + uint32_t tx_port; + std::string tx_addr; }; -class phy_info -{ - public: +class phy_info { + public: - uint16_t index; - uint16_t id; + uint16_t index; + uint16_t id; - std::vector<uint16_t> rfs; - std::vector<uint16_t> excluded_rfs; + std::vector<uint16_t> rfs; + std::vector<uint16_t> excluded_rfs; - int remote_port; - std::string remote_addr; + int remote_port; + std::string remote_addr; - uint16_t earfcn; + uint16_t earfcn; }; -class rf_info -{ - public: +class rf_info { + public: - uint16_t index; - uint16_t band; + uint16_t index; + uint16_t band; }; -class pnf_info -{ - public: +class pnf_info { + public: - std::vector<phy_info> phys; - std::vector<rf_info> rfs; + std::vector<phy_info> phys; + std::vector<rf_info> rfs; }; -class vnf_p7_info -{ - public: - vnf_p7_info() - : thread_started(false), - config(nfapi_vnf_p7_config_create(), - [] (nfapi_vnf_p7_config_t* f) { nfapi_vnf_p7_config_destory(f); }), - mac(0) - { - local_port = 0; - - timing_window = 0; - periodic_timing_enabled = 0; - aperiodic_timing_enabled = 0; - periodic_timing_period = 0; - - //config = nfapi_vnf_p7_config_create(); - } - - vnf_p7_info(const vnf_p7_info& other) = default; - - vnf_p7_info(vnf_p7_info&& other) = default; - - vnf_p7_info& operator=(const vnf_p7_info&) = default; - - vnf_p7_info& operator=(vnf_p7_info&&) = default; - - - - virtual ~vnf_p7_info() - { - //NFAPI_TRACE(NFAPI_TRACE_INFO, "*** vnf_p7_info delete ***\n"); - - //nfapi_vnf_p7_config_destory(config); - - // should we delete the mac? - } - +class vnf_p7_info { + public: + + vnf_p7_info() + : thread_started(false), + config(nfapi_vnf_p7_config_create(), + [] (nfapi_vnf_p7_config_t *f) { + nfapi_vnf_p7_config_destory(f); + }), + mac(0) { + local_port = 0; + udp=0; + timing_window = 0; + periodic_timing_enabled = 0; + aperiodic_timing_enabled = 0; + periodic_timing_period = 0; + //config = nfapi_vnf_p7_config_create(); + } + + vnf_p7_info(const vnf_p7_info &other) = default; + + vnf_p7_info(vnf_p7_info &&other) = default; + + vnf_p7_info &operator=(const vnf_p7_info &) = default; + + vnf_p7_info &operator=(vnf_p7_info &&) = default; - int local_port; - std::string local_addr; - unsigned timing_window; - unsigned periodic_timing_enabled; - unsigned aperiodic_timing_enabled; - unsigned periodic_timing_period; - // This is not really the right place if we have multiple PHY, - // should be part of the phy struct - udp_data udp; + virtual ~vnf_p7_info() { + //NFAPI_TRACE(NFAPI_TRACE_INFO, "*** vnf_p7_info delete ***\n"); + //nfapi_vnf_p7_config_destory(config); + // should we delete the mac? + } - bool thread_started; - //nfapi_vnf_p7_config_t* config; - std::shared_ptr<nfapi_vnf_p7_config_t> config; + int local_port; + std::string local_addr; - mac_t* mac; + unsigned timing_window; + unsigned periodic_timing_enabled; + unsigned aperiodic_timing_enabled; + unsigned periodic_timing_period; + // This is not really the right place if we have multiple PHY, + // should be part of the phy struct + udp_data udp; + + bool thread_started; + + //nfapi_vnf_p7_config_t* config; + std::shared_ptr<nfapi_vnf_p7_config_t> config; + + mac_t *mac; }; -class vnf_info -{ - public: - - uint8_t wireshark_test_mode; +class vnf_info { + public: - std::map<uint16_t, pnf_info> pnfs; + uint8_t wireshark_test_mode; + + std::map<uint16_t, pnf_info> pnfs; + + std::vector<vnf_p7_info> p7_vnfs; - std::vector<vnf_p7_info> p7_vnfs; - }; /// maybe these should be in the mac file... -int phy_unpack_vendor_extension_tlv(nfapi_tl_t* tl, uint8_t **ppReadPackedMessage, uint8_t *end, void** ve, nfapi_p7_codec_config_t* codec) -{ - (void)tl; - (void)ppReadPackedMessage; - (void)ve; - return -1; +int phy_unpack_vendor_extension_tlv(nfapi_tl_t *tl, uint8_t **ppReadPackedMessage, uint8_t *end, void **ve, nfapi_p7_codec_config_t *codec) { + (void)tl; + (void)ppReadPackedMessage; + (void)ve; + return -1; } -int phy_pack_vendor_extension_tlv(void* ve, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p7_codec_config_t* codec) -{ - //NFAPI_TRACE(NFAPI_TRACE_INFO, "phy_pack_vendor_extension_tlv\n"); +int phy_pack_vendor_extension_tlv(void *ve, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p7_codec_config_t *codec) { + //NFAPI_TRACE(NFAPI_TRACE_INFO, "phy_pack_vendor_extension_tlv\n"); + nfapi_tl_t *tlv = (nfapi_tl_t *)ve; - nfapi_tl_t* tlv = (nfapi_tl_t*)ve; - switch(tlv->tag) - { - case VENDOR_EXT_TLV_1_TAG: - { - //NFAPI_TRACE(NFAPI_TRACE_INFO, "Packing VENDOR_EXT_TLV_1\n"); - vendor_ext_tlv_1* ve = (vendor_ext_tlv_1*)tlv; - if(!push32(ve->dummy, ppWritePackedMsg, end)) - return 0; - return 1; - } - break; - default: - return -1; - break; - } -} + switch(tlv->tag) { + case VENDOR_EXT_TLV_1_TAG: { + //NFAPI_TRACE(NFAPI_TRACE_INFO, "Packing VENDOR_EXT_TLV_1\n"); + vendor_ext_tlv_1 *ve = (vendor_ext_tlv_1 *)tlv; -int vnf_sim_pack_vendor_extension_tlv(void* ve, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p4_p5_codec_config_t* codec) -{ - //NFAPI_TRACE(NFAPI_TRACE_INFO, "pnf_sim_pack_vendor_extension_tlv\n"); - nfapi_tl_t* tlv = (nfapi_tl_t*)ve; - switch(tlv->tag) - { - case VENDOR_EXT_TLV_2_TAG: - { - //NFAPI_TRACE(NFAPI_TRACE_INFO, "Packing VENDOR_EXT_TLV_2\n"); - vendor_ext_tlv_2* ve = (vendor_ext_tlv_2*)tlv; - if(!push32(ve->dummy, ppWritePackedMsg, end)) - return 0; - return 1; - } - break; - } - return -1; -} + if(!push32(ve->dummy, ppWritePackedMsg, end)) + return 0; -int vnf_sim_unpack_vendor_extension_tlv(nfapi_tl_t* tl, uint8_t **ppReadPackedMessage, uint8_t *end, void** ve, nfapi_p4_p5_codec_config_t* codec) -{ - return -1; + return 1; + } + break; + + default: + return -1; + break; + } } +int vnf_sim_pack_vendor_extension_tlv(void *ve, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p4_p5_codec_config_t *codec) { + //NFAPI_TRACE(NFAPI_TRACE_INFO, "pnf_sim_pack_vendor_extension_tlv\n"); + nfapi_tl_t *tlv = (nfapi_tl_t *)ve; + switch(tlv->tag) { + case VENDOR_EXT_TLV_2_TAG: { + //NFAPI_TRACE(NFAPI_TRACE_INFO, "Packing VENDOR_EXT_TLV_2\n"); + vendor_ext_tlv_2 *ve = (vendor_ext_tlv_2 *)tlv; + if(!push32(ve->dummy, ppWritePackedMsg, end)) + return 0; -int phy_unpack_p7_vendor_extension(nfapi_p7_message_header_t* header, uint8_t** ppReadPackedMessage, uint8_t *end, nfapi_p7_codec_config_t* config) -{ - //NFAPI_TRACE(NFAPI_TRACE_INFO, "%s\n", __FUNCTION__); - if(header->message_id == P7_VENDOR_EXT_IND) - { - vendor_ext_p7_ind* req = (vendor_ext_p7_ind*)(header); - if(!pull16(ppReadPackedMessage, &req->error_code, end)) - return 0; - } - return 1; -} + return 1; + } + break; + } -int phy_pack_p7_vendor_extension(nfapi_p7_message_header_t* header, uint8_t** ppWritePackedMsg, uint8_t *end, nfapi_p7_codec_config_t* config) -{ - //NFAPI_TRACE(NFAPI_TRACE_INFO, "%s\n", __FUNCTION__); - if(header->message_id == P7_VENDOR_EXT_REQ) - { - //NFAPI_TRACE(NFAPI_TRACE_INFO, "%s\n", __FUNCTION__); - vendor_ext_p7_req* req = (vendor_ext_p7_req*)(header); - if(!(push16(req->dummy1, ppWritePackedMsg, end) && - push16(req->dummy2, ppWritePackedMsg, end))) - return 0; - } - return 1; + return -1; } -int vnf_sim_unpack_p4_p5_vendor_extension(nfapi_p4_p5_message_header_t* header, uint8_t** ppReadPackedMessage, uint8_t *end, nfapi_p4_p5_codec_config_t* codec) -{ - //NFAPI_TRACE(NFAPI_TRACE_INFO, "%s\n", __FUNCTION__); - if(header->message_id == P5_VENDOR_EXT_RSP) - { - vendor_ext_p5_rsp* req = (vendor_ext_p5_rsp*)(header); - return(!pull16(ppReadPackedMessage, &req->error_code, end)); - } - return 0; +int vnf_sim_unpack_vendor_extension_tlv(nfapi_tl_t *tl, uint8_t **ppReadPackedMessage, uint8_t *end, void **ve, nfapi_p4_p5_codec_config_t *codec) { + return -1; } -int vnf_sim_pack_p4_p5_vendor_extension(nfapi_p4_p5_message_header_t* header, uint8_t** ppWritePackedMsg, uint8_t *end, nfapi_p4_p5_codec_config_t* codec) -{ - //NFAPI_TRACE(NFAPI_TRACE_INFO, "%s\n", __FUNCTION__); - if(header->message_id == P5_VENDOR_EXT_REQ) - { - vendor_ext_p5_req* req = (vendor_ext_p5_req*)(header); - //NFAPI_TRACE(NFAPI_TRACE_INFO, "%s %d %d\n", __FUNCTION__, req->dummy1, req->dummy2); - return (!(push16(req->dummy1, ppWritePackedMsg, end) && - push16(req->dummy2, ppWritePackedMsg, end))); - } - return 0; + + + +int phy_unpack_p7_vendor_extension(nfapi_p7_message_header_t *header, uint8_t **ppReadPackedMessage, uint8_t *end, nfapi_p7_codec_config_t *config) { + //NFAPI_TRACE(NFAPI_TRACE_INFO, "%s\n", __FUNCTION__); + if(header->message_id == P7_VENDOR_EXT_IND) { + vendor_ext_p7_ind *req = (vendor_ext_p7_ind *)(header); + + if(!pull16(ppReadPackedMessage, &req->error_code, end)) + return 0; + } + + return 1; } -void vnf_sim_trace(nfapi_trace_level_t level, const char* message, ...) -{ - va_list args; - va_start(args, message); - vprintf(message, args); - va_end(args); +int phy_pack_p7_vendor_extension(nfapi_p7_message_header_t *header, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p7_codec_config_t *config) { + //NFAPI_TRACE(NFAPI_TRACE_INFO, "%s\n", __FUNCTION__); + if(header->message_id == P7_VENDOR_EXT_REQ) { + //NFAPI_TRACE(NFAPI_TRACE_INFO, "%s\n", __FUNCTION__); + vendor_ext_p7_req *req = (vendor_ext_p7_req *)(header); + + if(!(push16(req->dummy1, ppWritePackedMsg, end) && + push16(req->dummy2, ppWritePackedMsg, end))) + return 0; + } + + return 1; } -void mac_dl_config_req(mac_t* mac, nfapi_dl_config_request_t* req) -{ - vnf_p7_info* info = (vnf_p7_info*)(mac->user_data); +int vnf_sim_unpack_p4_p5_vendor_extension(nfapi_p4_p5_message_header_t *header, uint8_t **ppReadPackedMessage, uint8_t *end, nfapi_p4_p5_codec_config_t *codec) { + //NFAPI_TRACE(NFAPI_TRACE_INFO, "%s\n", __FUNCTION__); + if(header->message_id == P5_VENDOR_EXT_RSP) { + vendor_ext_p5_rsp *req = (vendor_ext_p5_rsp *)(header); + return(!pull16(ppReadPackedMessage, &req->error_code, end)); + } - nfapi_vnf_p7_dl_config_req(info->config.get(), req); + return 0; } -void mac_ul_config_req(mac_t* mac, nfapi_ul_config_request_t* req) -{ - vnf_p7_info* info = (vnf_p7_info*)(mac->user_data); +int vnf_sim_pack_p4_p5_vendor_extension(nfapi_p4_p5_message_header_t *header, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p4_p5_codec_config_t *codec) { + //NFAPI_TRACE(NFAPI_TRACE_INFO, "%s\n", __FUNCTION__); + if(header->message_id == P5_VENDOR_EXT_REQ) { + vendor_ext_p5_req *req = (vendor_ext_p5_req *)(header); + //NFAPI_TRACE(NFAPI_TRACE_INFO, "%s %d %d\n", __FUNCTION__, req->dummy1, req->dummy2); + return (!(push16(req->dummy1, ppWritePackedMsg, end) && + push16(req->dummy2, ppWritePackedMsg, end))); + } - nfapi_vnf_p7_ul_config_req(info->config.get(), req); + return 0; } -void mac_hi_dci0_req(mac_t* mac, nfapi_hi_dci0_request_t* req) -{ - vnf_p7_info* info = (vnf_p7_info*)(mac->user_data); +void vnf_sim_trace(nfapi_trace_level_t level, const char *message, ...) { + va_list args; + va_start(args, message); + vprintf(message, args); + va_end(args); +} - nfapi_vnf_p7_hi_dci0_req(info->config.get(), req); +void mac_dl_config_req(mac_t *mac, nfapi_dl_config_request_t *req) { + vnf_p7_info *info = (vnf_p7_info *)(mac->user_data); + nfapi_vnf_p7_dl_config_req(info->config.get(), req); } -void mac_tx_req(mac_t* mac, nfapi_tx_request_t* req) -{ - vnf_p7_info* info = (vnf_p7_info*)(mac->user_data); +void mac_ul_config_req(mac_t *mac, nfapi_ul_config_request_t *req) { + vnf_p7_info *info = (vnf_p7_info *)(mac->user_data); + nfapi_vnf_p7_ul_config_req(info->config.get(), req); +} - nfapi_vnf_p7_tx_req(info->config.get(), req); +void mac_hi_dci0_req(mac_t *mac, nfapi_hi_dci0_request_t *req) { + vnf_p7_info *info = (vnf_p7_info *)(mac->user_data); + nfapi_vnf_p7_hi_dci0_req(info->config.get(), req); } -int phy_subframe_indication(struct nfapi_vnf_p7_config* config, uint16_t phy_id, uint16_t sfn_sf) -{ - //printf("[VNF_SIM] subframe indication %d\n", sfn_sf); - vnf_p7_info* p7_vnf = (vnf_p7_info*)(config->user_data); - mac_subframe_ind(p7_vnf->mac, phy_id, sfn_sf); - return 0; +void mac_tx_req(mac_t *mac, nfapi_tx_request_t *req) { + vnf_p7_info *info = (vnf_p7_info *)(mac->user_data); + nfapi_vnf_p7_tx_req(info->config.get(), req); } -int phy_harq_indication(struct nfapi_vnf_p7_config* config, nfapi_harq_indication_t* ind) -{ - vnf_p7_info* p7_vnf = (vnf_p7_info*)(config->user_data); - mac_harq_ind(p7_vnf->mac, ind); - return 1; + +int phy_subframe_indication(struct nfapi_vnf_p7_config *config, uint16_t phy_id, uint16_t sfn_sf) { + //printf("[VNF_SIM] subframe indication %d\n", sfn_sf); + vnf_p7_info *p7_vnf = (vnf_p7_info *)(config->user_data); + mac_subframe_ind(p7_vnf->mac, phy_id, sfn_sf); + return 0; } -int phy_crc_indication(struct nfapi_vnf_p7_config* config, nfapi_crc_indication_t* ind) -{ - vnf_p7_info* p7_vnf = (vnf_p7_info*)(config->user_data); - mac_crc_ind(p7_vnf->mac, ind); - return 1; +int phy_harq_indication(struct nfapi_vnf_p7_config *config, nfapi_harq_indication_t *ind) { + vnf_p7_info *p7_vnf = (vnf_p7_info *)(config->user_data); + mac_harq_ind(p7_vnf->mac, ind); + return 1; } -int phy_rx_indication(struct nfapi_vnf_p7_config* config, nfapi_rx_indication_t* ind) -{ - vnf_p7_info* p7_vnf = (vnf_p7_info*)(config->user_data); - mac_rx_ind(p7_vnf->mac, ind); - return 1; +int phy_crc_indication(struct nfapi_vnf_p7_config *config, nfapi_crc_indication_t *ind) { + vnf_p7_info *p7_vnf = (vnf_p7_info *)(config->user_data); + mac_crc_ind(p7_vnf->mac, ind); + return 1; } -int phy_rach_indication(struct nfapi_vnf_p7_config* config, nfapi_rach_indication_t* ind) -{ - vnf_p7_info* p7_vnf = (vnf_p7_info*)(config->user_data); - mac_rach_ind(p7_vnf->mac, ind); - return 1; +int phy_rx_indication(struct nfapi_vnf_p7_config *config, nfapi_rx_indication_t *ind) { + vnf_p7_info *p7_vnf = (vnf_p7_info *)(config->user_data); + mac_rx_ind(p7_vnf->mac, ind); + return 1; } -int phy_srs_indication(struct nfapi_vnf_p7_config* config, nfapi_srs_indication_t* ind) -{ - vnf_p7_info* p7_vnf = (vnf_p7_info*)(config->user_data); - mac_srs_ind(p7_vnf->mac, ind); - return 1; +int phy_rach_indication(struct nfapi_vnf_p7_config *config, nfapi_rach_indication_t *ind) { + vnf_p7_info *p7_vnf = (vnf_p7_info *)(config->user_data); + mac_rach_ind(p7_vnf->mac, ind); + return 1; } -int phy_sr_indication(struct nfapi_vnf_p7_config* config, nfapi_sr_indication_t* ind) -{ - vnf_p7_info* p7_vnf = (vnf_p7_info*)(config->user_data); - mac_sr_ind(p7_vnf->mac, ind); - return 1; +int phy_srs_indication(struct nfapi_vnf_p7_config *config, nfapi_srs_indication_t *ind) { + vnf_p7_info *p7_vnf = (vnf_p7_info *)(config->user_data); + mac_srs_ind(p7_vnf->mac, ind); + return 1; } -int phy_cqi_indication(struct nfapi_vnf_p7_config* config, nfapi_cqi_indication_t* ind) -{ - vnf_p7_info* p7_vnf = (vnf_p7_info*)(config->user_data); - mac_cqi_ind(p7_vnf->mac, ind); - return 1; +int phy_sr_indication(struct nfapi_vnf_p7_config *config, nfapi_sr_indication_t *ind) { + vnf_p7_info *p7_vnf = (vnf_p7_info *)(config->user_data); + mac_sr_ind(p7_vnf->mac, ind); + return 1; } -int phy_lbt_dl_indication(struct nfapi_vnf_p7_config* config, nfapi_lbt_dl_indication_t* ind) -{ - vnf_p7_info* p7_vnf = (vnf_p7_info*)(config->user_data); - mac_lbt_dl_ind(p7_vnf->mac, ind); - return 1; +int phy_cqi_indication(struct nfapi_vnf_p7_config *config, nfapi_cqi_indication_t *ind) { + vnf_p7_info *p7_vnf = (vnf_p7_info *)(config->user_data); + mac_cqi_ind(p7_vnf->mac, ind); + return 1; } -int phy_nb_harq_indication(struct nfapi_vnf_p7_config* config, nfapi_nb_harq_indication_t* ind) -{ - vnf_p7_info* p7_vnf = (vnf_p7_info*)(config->user_data); - mac_nb_harq_ind(p7_vnf->mac, ind); - return 1; +int phy_lbt_dl_indication(struct nfapi_vnf_p7_config *config, nfapi_lbt_dl_indication_t *ind) { + vnf_p7_info *p7_vnf = (vnf_p7_info *)(config->user_data); + mac_lbt_dl_ind(p7_vnf->mac, ind); + return 1; } -int phy_nrach_indication(struct nfapi_vnf_p7_config* config, nfapi_nrach_indication_t* ind) -{ - vnf_p7_info* p7_vnf = (vnf_p7_info*)(config->user_data); - mac_nrach_ind(p7_vnf->mac, ind); - return 1; +int phy_nb_harq_indication(struct nfapi_vnf_p7_config *config, nfapi_nb_harq_indication_t *ind) { + vnf_p7_info *p7_vnf = (vnf_p7_info *)(config->user_data); + mac_nb_harq_ind(p7_vnf->mac, ind); + return 1; } -int phy_vendor_ext(struct nfapi_vnf_p7_config* config, nfapi_p7_message_header_t* msg) -{ - if(msg->message_id == P7_VENDOR_EXT_IND) - { - //vendor_ext_p7_ind* ind = (vendor_ext_p7_ind*)msg; - //printf("[VNF_SIM] vendor_ext (error_code:%d)\n", ind->error_code); - } - else - { - printf("[VNF_SIM] unknown %d\n", msg->message_id); - } - return 0; +int phy_nrach_indication(struct nfapi_vnf_p7_config *config, nfapi_nrach_indication_t *ind) { + vnf_p7_info *p7_vnf = (vnf_p7_info *)(config->user_data); + mac_nrach_ind(p7_vnf->mac, ind); + return 1; } -nfapi_p7_message_header_t* phy_allocate_p7_vendor_ext(uint16_t message_id, uint16_t* msg_size) -{ - if(message_id == P7_VENDOR_EXT_IND) - { - *msg_size = sizeof(vendor_ext_p7_ind); - return (nfapi_p7_message_header_t*)malloc(sizeof(vendor_ext_p7_ind)); - } - return 0; +int phy_vendor_ext(struct nfapi_vnf_p7_config *config, nfapi_p7_message_header_t *msg) { + if(msg->message_id == P7_VENDOR_EXT_IND) { + //vendor_ext_p7_ind* ind = (vendor_ext_p7_ind*)msg; + //printf("[VNF_SIM] vendor_ext (error_code:%d)\n", ind->error_code); + } else { + printf("[VNF_SIM] unknown %d\n", msg->message_id); + } + + return 0; } -void phy_deallocate_p7_vendor_ext(nfapi_p7_message_header_t* header) -{ - free(header); +nfapi_p7_message_header_t *phy_allocate_p7_vendor_ext(uint16_t message_id, uint16_t *msg_size) { + if(message_id == P7_VENDOR_EXT_IND) { + *msg_size = sizeof(vendor_ext_p7_ind); + return (nfapi_p7_message_header_t *)malloc(sizeof(vendor_ext_p7_ind)); + } + + return 0; +} +void phy_deallocate_p7_vendor_ext(nfapi_p7_message_header_t *header) { + free(header); } //static pthread_t vnf_start_pthread; static pthread_t vnf_p7_start_pthread; -void* vnf_p7_start_thread(void *ptr) -{ +void *vnf_p7_start_thread(void *ptr) { printf("%s()\n", __FUNCTION__); - //std::shared_ptr<nfapi_vnf_p7_config> config = std::shared_ptr<nfapi_vnf_p7_config>(ptr); nfapi_vnf_p7_config_t *config = (nfapi_vnf_p7_config_t *)ptr; - nfapi_vnf_p7_start(config); - return 0; } -void set_thread_priority(int priority) -{ - //printf("%s(priority:%d)\n", __FUNCTION__, priority); - - pthread_attr_t ptAttr; - - struct sched_param schedParam; - schedParam.__sched_priority = priority; //79; - if(sched_setscheduler(0, SCHED_RR, &schedParam) != 0) - { - printf("Failed to set scheduler to SCHED_RR\n"); - } - - if(pthread_attr_setschedpolicy(&ptAttr, SCHED_RR) != 0) - { - printf("Failed to set pthread sched policy SCHED_RR\n"); - } - - pthread_attr_setinheritsched(&ptAttr, PTHREAD_EXPLICIT_SCHED); - - struct sched_param thread_params; - thread_params.sched_priority = 20; - if(pthread_attr_setschedparam(&ptAttr, &thread_params) != 0) - { - printf("failed to set sched param\n"); - } -} - -void* vnf_p7_thread_start(void* ptr) -{ - printf("%s()\n", __FUNCTION__); - - set_thread_priority(79); - - vnf_p7_info* p7_vnf = (vnf_p7_info*)ptr; - - p7_vnf->config->port = p7_vnf->local_port; - p7_vnf->config->subframe_indication = &phy_subframe_indication; - p7_vnf->config->harq_indication = &phy_harq_indication; - p7_vnf->config->crc_indication = &phy_crc_indication; - p7_vnf->config->rx_indication = &phy_rx_indication; - p7_vnf->config->rach_indication = &phy_rach_indication; - p7_vnf->config->srs_indication = &phy_srs_indication; - p7_vnf->config->sr_indication = &phy_sr_indication; - p7_vnf->config->cqi_indication = &phy_cqi_indication; - p7_vnf->config->lbt_dl_indication = &phy_lbt_dl_indication; - p7_vnf->config->nb_harq_indication = &phy_nb_harq_indication; - p7_vnf->config->nrach_indication = &phy_nrach_indication; - p7_vnf->config->malloc = &vnf_allocate; - p7_vnf->config->free = &vnf_deallocate; - - p7_vnf->config->trace = &vnf_sim_trace; +void set_thread_priority(int priority) { + //printf("%s(priority:%d)\n", __FUNCTION__, priority); + pthread_attr_t ptAttr; + struct sched_param schedParam; + schedParam.__sched_priority = priority; //79; - p7_vnf->config->vendor_ext = &phy_vendor_ext; - p7_vnf->config->user_data = p7_vnf; + if(sched_setscheduler(0, SCHED_RR, &schedParam) != 0) { + printf("Failed to set scheduler to SCHED_RR\n"); + } - p7_vnf->mac->user_data = p7_vnf; + if(pthread_attr_setschedpolicy(&ptAttr, SCHED_RR) != 0) { + printf("Failed to set pthread sched policy SCHED_RR\n"); + } - p7_vnf->config->codec_config.unpack_p7_vendor_extension = &phy_unpack_p7_vendor_extension; - p7_vnf->config->codec_config.pack_p7_vendor_extension = &phy_pack_p7_vendor_extension; - p7_vnf->config->codec_config.unpack_vendor_extension_tlv = &phy_unpack_vendor_extension_tlv; - p7_vnf->config->codec_config.pack_vendor_extension_tlv = &phy_pack_vendor_extension_tlv; - p7_vnf->config->codec_config.allocate = &vnf_allocate; - p7_vnf->config->codec_config.deallocate = &vnf_deallocate; + pthread_attr_setinheritsched(&ptAttr, PTHREAD_EXPLICIT_SCHED); + struct sched_param thread_params; + thread_params.sched_priority = 20; - p7_vnf->config->allocate_p7_vendor_ext = &phy_allocate_p7_vendor_ext; - p7_vnf->config->deallocate_p7_vendor_ext = &phy_deallocate_p7_vendor_ext; - - printf("[VNF] Creating VNF NFAPI start thread %s\n", __FUNCTION__); - pthread_create(&vnf_p7_start_pthread, NULL, &vnf_p7_start_thread, p7_vnf->config.get()); - - return 0; + if(pthread_attr_setschedparam(&ptAttr, &thread_params) != 0) { + printf("failed to set sched param\n"); + } } -int pnf_connection_indication_cb(nfapi_vnf_config_t* config, int p5_idx) -{ - printf("[VNF_SIM] pnf connection indication idx:%d\n", p5_idx); - - pnf_info pnf; - vnf_info* vnf = (vnf_info*)(config->user_data); - vnf->pnfs.insert(std::pair<uint16_t, pnf_info>(p5_idx, pnf)); - - nfapi_pnf_param_request_t req; - memset(&req, 0, sizeof(req)); - req.header.message_id = NFAPI_PNF_PARAM_REQUEST; - nfapi_vnf_pnf_param_req(config, p5_idx, &req); - return 0; +void *vnf_p7_thread_start(void *ptr) { + printf("%s()\n", __FUNCTION__); + set_thread_priority(79); + vnf_p7_info *p7_vnf = (vnf_p7_info *)ptr; + p7_vnf->config->port = p7_vnf->local_port; + p7_vnf->config->subframe_indication = &phy_subframe_indication; + p7_vnf->config->harq_indication = &phy_harq_indication; + p7_vnf->config->crc_indication = &phy_crc_indication; + p7_vnf->config->rx_indication = &phy_rx_indication; + p7_vnf->config->rach_indication = &phy_rach_indication; + p7_vnf->config->srs_indication = &phy_srs_indication; + p7_vnf->config->sr_indication = &phy_sr_indication; + p7_vnf->config->cqi_indication = &phy_cqi_indication; + p7_vnf->config->lbt_dl_indication = &phy_lbt_dl_indication; + p7_vnf->config->nb_harq_indication = &phy_nb_harq_indication; + p7_vnf->config->nrach_indication = &phy_nrach_indication; + p7_vnf->config->malloc = &vnf_allocate; + p7_vnf->config->free = &vnf_deallocate; + p7_vnf->config->trace = &vnf_sim_trace; + p7_vnf->config->vendor_ext = &phy_vendor_ext; + p7_vnf->config->user_data = p7_vnf; + p7_vnf->mac->user_data = p7_vnf; + p7_vnf->config->codec_config.unpack_p7_vendor_extension = &phy_unpack_p7_vendor_extension; + p7_vnf->config->codec_config.pack_p7_vendor_extension = &phy_pack_p7_vendor_extension; + p7_vnf->config->codec_config.unpack_vendor_extension_tlv = &phy_unpack_vendor_extension_tlv; + p7_vnf->config->codec_config.pack_vendor_extension_tlv = &phy_pack_vendor_extension_tlv; + p7_vnf->config->codec_config.allocate = &vnf_allocate; + p7_vnf->config->codec_config.deallocate = &vnf_deallocate; + p7_vnf->config->allocate_p7_vendor_ext = &phy_allocate_p7_vendor_ext; + p7_vnf->config->deallocate_p7_vendor_ext = &phy_deallocate_p7_vendor_ext; + printf("[VNF] Creating VNF NFAPI start thread %s\n", __FUNCTION__); + pthread_create(&vnf_p7_start_pthread, NULL, &vnf_p7_start_thread, p7_vnf->config.get()); + return 0; } -int pnf_disconnection_indication_cb(nfapi_vnf_config_t* config, int p5_idx) -{ - printf("[VNF_SIM] pnf disconnection indication idx:%d\n", p5_idx); - - - vnf_info* vnf = (vnf_info*)(config->user_data); - auto find_result = vnf->pnfs.find(p5_idx); - - if(find_result != vnf->pnfs.end()) - { - pnf_info& pnf = find_result->second; - - for(phy_info& phy : pnf.phys) - { - vnf_p7_info& p7_vnf = vnf->p7_vnfs[0]; - nfapi_vnf_p7_del_pnf((p7_vnf.config.get()), phy.id); - } - } - return 0; +int pnf_connection_indication_cb(nfapi_vnf_config_t *config, int p5_idx) { + printf("[VNF_SIM] pnf connection indication idx:%d\n", p5_idx); + pnf_info pnf; + vnf_info *vnf = (vnf_info *)(config->user_data); + vnf->pnfs.insert(std::pair<uint16_t, pnf_info>(p5_idx, pnf)); + nfapi_pnf_param_request_t req; + memset(&req, 0, sizeof(req)); + req.header.message_id = NFAPI_PNF_PARAM_REQUEST; + nfapi_vnf_pnf_param_req(config, p5_idx, &req); + return 0; } +int pnf_disconnection_indication_cb(nfapi_vnf_config_t *config, int p5_idx) { + printf("[VNF_SIM] pnf disconnection indication idx:%d\n", p5_idx); + vnf_info *vnf = (vnf_info *)(config->user_data); + auto find_result = vnf->pnfs.find(p5_idx); -int pnf_param_resp_cb(nfapi_vnf_config_t* config, int p5_idx, nfapi_pnf_param_response_t* resp) -{ - printf("[VNF_SIM] pnf param response idx:%d error:%d\n", p5_idx, resp->error_code); - - vnf_info* vnf = (vnf_info*)(config->user_data); - - auto find_result = vnf->pnfs.find(p5_idx); - if(find_result != vnf->pnfs.end()) - { - pnf_info& pnf = find_result->second; - - for(int i = 0; i < resp->pnf_phy.number_of_phys; ++i) - { - phy_info phy; - phy.index = resp->pnf_phy.phy[i].phy_config_index; - - printf("[VNF_SIM] (PHY:%d) phy_config_idx:%d\n", i, resp->pnf_phy.phy[i].phy_config_index); - - nfapi_vnf_allocate_phy(config, p5_idx, &(phy.id)); - - - - for(int j = 0; j < resp->pnf_phy.phy[i].number_of_rfs; ++j) - { - printf("[VNF_SIM] (PHY:%d) (RF%d) %d\n", i, j, resp->pnf_phy.phy[i].rf_config[j].rf_config_index); - phy.rfs.push_back(resp->pnf_phy.phy[i].rf_config[j].rf_config_index); - } - - - pnf.phys.push_back(phy); - } - for(int i = 0; i < resp->pnf_rf.number_of_rfs; ++i) - { - rf_info rf; - rf.index = resp->pnf_rf.rf[i].rf_config_index; - - printf("[VNF_SIM] (RF:%d) rf_config_idx:%d\n", i, resp->pnf_rf.rf[i].rf_config_index); - - pnf.rfs.push_back(rf); - } - - nfapi_pnf_config_request_t req; - memset(&req, 0, sizeof(req)); - req.header.message_id = NFAPI_PNF_CONFIG_REQUEST; - - req.pnf_phy_rf_config.tl.tag = NFAPI_PNF_PHY_RF_TAG; - req.pnf_phy_rf_config.number_phy_rf_config_info = pnf.phys.size(); + if(find_result != vnf->pnfs.end()) { + pnf_info &pnf = find_result->second; - for(unsigned i = 0; i < pnf.phys.size(); ++i) - { - req.pnf_phy_rf_config.phy_rf_config[i].phy_id = pnf.phys[i].id; - req.pnf_phy_rf_config.phy_rf_config[i].phy_config_index = pnf.phys[i].index; - req.pnf_phy_rf_config.phy_rf_config[i].rf_config_index = pnf.phys[i].rfs[0]; - } + for(phy_info &phy : pnf.phys) { + vnf_p7_info &p7_vnf = vnf->p7_vnfs[0]; + nfapi_vnf_p7_del_pnf((p7_vnf.config.get()), phy.id); + } + } - - nfapi_vnf_pnf_config_req(config, p5_idx, &req); - } - return 0; + return 0; } -int pnf_config_resp_cb(nfapi_vnf_config_t* config, int p5_idx, nfapi_pnf_config_response_t* resp) -{ - printf("[VNF_SIM] pnf config response idx:%d\n", p5_idx); - - if(1) - { - vnf_info* vnf = (vnf_info*)(config->user_data); - auto find_result = vnf->pnfs.find(p5_idx); - if(find_result != vnf->pnfs.end()) - { - //pnf_info& pnf = find_result->second; - - nfapi_pnf_start_request_t req; - memset(&req, 0, sizeof(req)); - req.header.message_id = NFAPI_PNF_START_REQUEST; - nfapi_vnf_pnf_start_req(config, p5_idx, &req); - } - } - else - { - // Rather than send the pnf_start_request we will demonstrate - // sending a vendor extention message. The start request will be - // send when the vendor extension response is received - - //vnf_info* vnf = (vnf_info*)(config->user_data); - vendor_ext_p5_req req; - memset(&req, 0, sizeof(req)); - req.header.message_id = P5_VENDOR_EXT_REQ; - req.dummy1 = 45; - req.dummy2 = 1977; - nfapi_vnf_vendor_extension(config, p5_idx, &req.header); - } - return 0; +int pnf_param_resp_cb(nfapi_vnf_config_t *config, int p5_idx, nfapi_pnf_param_response_t *resp) { + printf("[VNF_SIM] pnf param response idx:%d error:%d\n", p5_idx, resp->error_code); + vnf_info *vnf = (vnf_info *)(config->user_data); + auto find_result = vnf->pnfs.find(p5_idx); + + if(find_result != vnf->pnfs.end()) { + pnf_info &pnf = find_result->second; + + for(int i = 0; i < resp->pnf_phy.number_of_phys; ++i) { + phy_info phy; + phy.index = resp->pnf_phy.phy[i].phy_config_index; + printf("[VNF_SIM] (PHY:%d) phy_config_idx:%d\n", i, resp->pnf_phy.phy[i].phy_config_index); + nfapi_vnf_allocate_phy(config, p5_idx, &(phy.id)); + + for(int j = 0; j < resp->pnf_phy.phy[i].number_of_rfs; ++j) { + printf("[VNF_SIM] (PHY:%d) (RF%d) %d\n", i, j, resp->pnf_phy.phy[i].rf_config[j].rf_config_index); + phy.rfs.push_back(resp->pnf_phy.phy[i].rf_config[j].rf_config_index); + } + + pnf.phys.push_back(phy); + } + + for(int i = 0; i < resp->pnf_rf.number_of_rfs; ++i) { + rf_info rf; + rf.index = resp->pnf_rf.rf[i].rf_config_index; + printf("[VNF_SIM] (RF:%d) rf_config_idx:%d\n", i, resp->pnf_rf.rf[i].rf_config_index); + pnf.rfs.push_back(rf); + } + + nfapi_pnf_config_request_t req; + memset(&req, 0, sizeof(req)); + req.header.message_id = NFAPI_PNF_CONFIG_REQUEST; + req.pnf_phy_rf_config.tl.tag = NFAPI_PNF_PHY_RF_TAG; + req.pnf_phy_rf_config.number_phy_rf_config_info = pnf.phys.size(); + + for(unsigned i = 0; i < pnf.phys.size(); ++i) { + req.pnf_phy_rf_config.phy_rf_config[i].phy_id = pnf.phys[i].id; + req.pnf_phy_rf_config.phy_rf_config[i].phy_config_index = pnf.phys[i].index; + req.pnf_phy_rf_config.phy_rf_config[i].rf_config_index = pnf.phys[i].rfs[0]; + } + + nfapi_vnf_pnf_config_req(config, p5_idx, &req); + } } - int pnf_start_resp_cb(nfapi_vnf_config_t* config, int p5_idx, nfapi_pnf_start_response_t* resp) { printf("[VNF_SIM] pnf start response idx:%d\n", p5_idx); @@ -716,7 +596,7 @@ int param_resp_cb(nfapi_vnf_config_t* config, int p5_idx, nfapi_param_response_t // for now just 1 vnf_p7_info& p7_vnf = vnf->p7_vnfs[0]; - printf("[VNF_SIM] %d.%d pnf p7 %s:%d timing %d %d %d %d\n", p5_idx, phy.id, phy.remote_addr.c_str(), phy.remote_port, p7_vnf.timing_window, p7_vnf.periodic_timing_period, p7_vnf.aperiodic_timing_enabled, p7_vnf.periodic_timing_period); + printf("[VNF_SIM] %d.%d pnf p7 %s:%d timing %u %u %u %u\n", p5_idx, phy.id, phy.remote_addr.c_str(), phy.remote_port, p7_vnf.timing_window, p7_vnf.periodic_timing_period, p7_vnf.aperiodic_timing_enabled, p7_vnf.periodic_timing_period); nfapi_config_request_t req; @@ -1065,461 +945,768 @@ int param_resp_cb(nfapi_vnf_config_t* config, int p5_idx, nfapi_param_response_t return 0; } -int config_resp_cb(nfapi_vnf_config_t* config, int p5_idx, nfapi_config_response_t* resp) -{ - printf("[VNF_SIM] config response idx:%d phy_id:%d\n", p5_idx, resp->header.phy_id); +int pnf_config_resp_cb(nfapi_vnf_config_t *config, int p5_idx, nfapi_pnf_config_response_t *resp) { + printf("[VNF_SIM] pnf config response idx:%d\n", p5_idx); + + if(1) { + vnf_info *vnf = (vnf_info *)(config->user_data); + auto find_result = vnf->pnfs.find(p5_idx); + + if(find_result != vnf->pnfs.end()) { + //pnf_info& pnf = find_result->second; + nfapi_pnf_start_request_t req; + memset(&req, 0, sizeof(req)); + req.header.message_id = NFAPI_PNF_START_REQUEST; + nfapi_vnf_pnf_start_req(config, p5_idx, &req); + } + } else { + // Rather than send the pnf_start_request we will demonstrate + // sending a vendor extention message. The start request will be + // send when the vendor extension response is received + //vnf_info* vnf = (vnf_info*)(config->user_data); + vendor_ext_p5_req req; + memset(&req, 0, sizeof(req)); + req.header.message_id = P5_VENDOR_EXT_REQ; + req.dummy1 = 45; + req.dummy2 = 1977; + nfapi_vnf_vendor_extension(config, p5_idx, &req.header); + } + return 0; +} - nfapi_start_request_t req; - memset(&req, 0, sizeof(req)); - req.header.message_id = NFAPI_START_REQUEST; - req.header.phy_id = resp->header.phy_id; - nfapi_vnf_start_req(config, p5_idx, &req); +int pnf_start_resp_cb(nfapi_vnf_config_t *config, int p5_idx, nfapi_pnf_start_response_t *resp) { + printf("[VNF_SIM] pnf start response idx:%d\n", p5_idx); + vnf_info *vnf = (vnf_info *)(config->user_data); + vnf_p7_info &p7_vnf = vnf->p7_vnfs[0]; + + if(p7_vnf.thread_started == false) { + pthread_t vnf_p7_thread; + pthread_create(&vnf_p7_thread, NULL, &vnf_p7_thread_start, &p7_vnf); + p7_vnf.thread_started = true; + } else { + // P7 thread already running. + } + + // start all the phys in the pnf. + auto find_result = vnf->pnfs.find(p5_idx); + + if(find_result != vnf->pnfs.end()) { + pnf_info &pnf = find_result->second; + + for(unsigned i = 0; i < pnf.phys.size(); ++i) { + pnf_info &pnf = find_result->second; + nfapi_param_request_t req; + memset(&req, 0, sizeof(req)); + req.header.message_id = NFAPI_PARAM_REQUEST; + req.header.phy_id = pnf.phys[i].id; + nfapi_vnf_param_req(config, p5_idx, &req); + } + } - return 0; + return 0; } +int param_resp_cb(nfapi_vnf_config_t *config, int p5_idx, nfapi_param_response_t *resp) { + printf("[VNF_SIM] param response idx:%d phy_id:%d\n", p5_idx, resp->header.phy_id); + vnf_info *vnf = (vnf_info *)(config->user_data); + auto find_result = vnf->pnfs.find(p5_idx); + + if(find_result != vnf->pnfs.end()) { + pnf_info &pnf = find_result->second; + auto found = std::find_if(pnf.phys.begin(), pnf.phys.end(), [&](phy_info& item) { + return item.id == resp->header.phy_id; + }); + + if(found != pnf.phys.end()) { + phy_info &phy = (*found); + phy.remote_port = resp->nfapi_config.p7_pnf_port.value; + struct sockaddr_in pnf_p7_sockaddr; + memcpy(&pnf_p7_sockaddr.sin_addr.s_addr, &(resp->nfapi_config.p7_pnf_address_ipv4.address[0]), 4); + phy.remote_addr = inet_ntoa(pnf_p7_sockaddr.sin_addr); + // for now just 1 + vnf_p7_info &p7_vnf = vnf->p7_vnfs[0]; + printf("[VNF_SIM] %d.%d pnf p7 %s:%d timing %u %u %u %u\n", p5_idx, phy.id, phy.remote_addr.c_str(), phy.remote_port, p7_vnf.timing_window, p7_vnf.periodic_timing_period, + p7_vnf.aperiodic_timing_enabled, p7_vnf.periodic_timing_period); + nfapi_config_request_t req; + memset(&req, 0, sizeof(req)); + req.header.message_id = NFAPI_CONFIG_REQUEST; + req.header.phy_id = phy.id; + req.nfapi_config.p7_vnf_port.tl.tag = NFAPI_NFAPI_P7_VNF_PORT_TAG; + req.nfapi_config.p7_vnf_port.value = p7_vnf.local_port; + req.num_tlv++; + req.nfapi_config.p7_vnf_address_ipv4.tl.tag = NFAPI_NFAPI_P7_VNF_ADDRESS_IPV4_TAG; + struct sockaddr_in vnf_p7_sockaddr; + vnf_p7_sockaddr.sin_addr.s_addr = inet_addr(p7_vnf.local_addr.c_str()); + memcpy(&(req.nfapi_config.p7_vnf_address_ipv4.address[0]), &vnf_p7_sockaddr.sin_addr.s_addr, 4); + req.num_tlv++; + req.nfapi_config.timing_window.tl.tag = NFAPI_NFAPI_TIMING_WINDOW_TAG; + req.nfapi_config.timing_window.value = p7_vnf.timing_window; + req.num_tlv++; + + if(p7_vnf.periodic_timing_enabled || p7_vnf.aperiodic_timing_enabled) { + req.nfapi_config.timing_info_mode.tl.tag = NFAPI_NFAPI_TIMING_INFO_MODE_TAG; + req.nfapi_config.timing_info_mode.value = (p7_vnf.aperiodic_timing_enabled << 1) | (p7_vnf.periodic_timing_enabled); + req.num_tlv++; + + if(p7_vnf.periodic_timing_enabled) { + req.nfapi_config.timing_info_period.tl.tag = NFAPI_NFAPI_TIMING_INFO_PERIOD_TAG; + req.nfapi_config.timing_info_period.value = p7_vnf.periodic_timing_period; + req.num_tlv++; + } + } + + req.nfapi_config.earfcn.tl.tag = NFAPI_NFAPI_EARFCN_TAG; + req.nfapi_config.earfcn.value = phy.earfcn; + req.num_tlv++; + + if(1) { + // Poplate all tlv for wireshark testing + req.subframe_config.duplex_mode.tl.tag = NFAPI_SUBFRAME_CONFIG_DUPLEX_MODE_TAG; + req.num_tlv++; + req.subframe_config.pcfich_power_offset.tl.tag = NFAPI_SUBFRAME_CONFIG_PCFICH_POWER_OFFSET_TAG; + req.num_tlv++; + req.subframe_config.pb.tl.tag = NFAPI_SUBFRAME_CONFIG_PB_TAG; + req.num_tlv++; + req.subframe_config.dl_cyclic_prefix_type.tl.tag = NFAPI_SUBFRAME_CONFIG_DL_CYCLIC_PREFIX_TYPE_TAG; + req.num_tlv++; + req.subframe_config.ul_cyclic_prefix_type.tl.tag = NFAPI_SUBFRAME_CONFIG_UL_CYCLIC_PREFIX_TYPE_TAG; + req.num_tlv++; + req.rf_config.dl_channel_bandwidth.tl.tag = NFAPI_RF_CONFIG_DL_CHANNEL_BANDWIDTH_TAG; + req.num_tlv++; + req.rf_config.ul_channel_bandwidth.tl.tag = NFAPI_RF_CONFIG_UL_CHANNEL_BANDWIDTH_TAG; + req.num_tlv++; + req.rf_config.reference_signal_power.tl.tag = NFAPI_RF_CONFIG_REFERENCE_SIGNAL_POWER_TAG; + req.num_tlv++; + req.rf_config.tx_antenna_ports.tl.tag = NFAPI_RF_CONFIG_TX_ANTENNA_PORTS_TAG; + req.num_tlv++; + req.rf_config.rx_antenna_ports.tl.tag = NFAPI_RF_CONFIG_RX_ANTENNA_PORTS_TAG; + req.num_tlv++; + req.phich_config.phich_resource.tl.tag = NFAPI_PHICH_CONFIG_PHICH_RESOURCE_TAG; + req.num_tlv++; + req.phich_config.phich_duration.tl.tag = NFAPI_PHICH_CONFIG_PHICH_DURATION_TAG; + req.num_tlv++; + req.phich_config.phich_power_offset.tl.tag = NFAPI_PHICH_CONFIG_PHICH_POWER_OFFSET_TAG; + req.num_tlv++; + req.sch_config.primary_synchronization_signal_epre_eprers.tl.tag = NFAPI_SCH_CONFIG_PRIMARY_SYNCHRONIZATION_SIGNAL_EPRE_EPRERS_TAG; + req.num_tlv++; + req.sch_config.secondary_synchronization_signal_epre_eprers.tl.tag = NFAPI_SCH_CONFIG_SECONDARY_SYNCHRONIZATION_SIGNAL_EPRE_EPRERS_TAG; + req.num_tlv++; + req.sch_config.physical_cell_id.tl.tag = NFAPI_SCH_CONFIG_PHYSICAL_CELL_ID_TAG; + req.num_tlv++; + req.prach_config.configuration_index.tl.tag = NFAPI_PRACH_CONFIG_CONFIGURATION_INDEX_TAG; + req.num_tlv++; + req.prach_config.root_sequence_index.tl.tag = NFAPI_PRACH_CONFIG_ROOT_SEQUENCE_INDEX_TAG; + req.num_tlv++; + req.prach_config.zero_correlation_zone_configuration.tl.tag = NFAPI_PRACH_CONFIG_ZERO_CORRELATION_ZONE_CONFIGURATION_TAG; + req.num_tlv++; + req.prach_config.high_speed_flag.tl.tag = NFAPI_PRACH_CONFIG_HIGH_SPEED_FLAG_TAG; + req.num_tlv++; + req.prach_config.frequency_offset.tl.tag = NFAPI_PRACH_CONFIG_FREQUENCY_OFFSET_TAG; + req.num_tlv++; + req.pusch_config.hopping_mode.tl.tag = NFAPI_PUSCH_CONFIG_HOPPING_MODE_TAG; + req.num_tlv++; + req.pusch_config.hopping_offset.tl.tag = NFAPI_PUSCH_CONFIG_HOPPING_OFFSET_TAG; + req.num_tlv++; + req.pusch_config.number_of_subbands.tl.tag = NFAPI_PUSCH_CONFIG_NUMBER_OF_SUBBANDS_TAG; + req.num_tlv++; + req.pucch_config.delta_pucch_shift.tl.tag = NFAPI_PUCCH_CONFIG_DELTA_PUCCH_SHIFT_TAG; + req.num_tlv++; + req.pucch_config.n_cqi_rb.tl.tag = NFAPI_PUCCH_CONFIG_N_CQI_RB_TAG; + req.num_tlv++; + req.pucch_config.n_an_cs.tl.tag = NFAPI_PUCCH_CONFIG_N_AN_CS_TAG; + req.num_tlv++; + req.pucch_config.n1_pucch_an.tl.tag = NFAPI_PUCCH_CONFIG_N1_PUCCH_AN_TAG; + req.num_tlv++; + req.srs_config.bandwidth_configuration.tl.tag = NFAPI_SRS_CONFIG_BANDWIDTH_CONFIGURATION_TAG; + req.num_tlv++; + req.srs_config.max_up_pts.tl.tag = NFAPI_SRS_CONFIG_MAX_UP_PTS_TAG; + req.num_tlv++; + req.srs_config.srs_subframe_configuration.tl.tag = NFAPI_SRS_CONFIG_SRS_SUBFRAME_CONFIGURATION_TAG; + req.num_tlv++; + req.srs_config.srs_acknack_srs_simultaneous_transmission.tl.tag = NFAPI_SRS_CONFIG_SRS_ACKNACK_SRS_SIMULTANEOUS_TRANSMISSION_TAG; + req.num_tlv++; + req.uplink_reference_signal_config.uplink_rs_hopping.tl.tag = NFAPI_UPLINK_REFERENCE_SIGNAL_CONFIG_UPLINK_RS_HOPPING_TAG; + req.num_tlv++; + req.uplink_reference_signal_config.group_assignment.tl.tag = NFAPI_UPLINK_REFERENCE_SIGNAL_CONFIG_GROUP_ASSIGNMENT_TAG; + req.num_tlv++; + req.uplink_reference_signal_config.cyclic_shift_1_for_drms.tl.tag = NFAPI_UPLINK_REFERENCE_SIGNAL_CONFIG_CYCLIC_SHIFT_1_FOR_DRMS_TAG; + req.num_tlv++; + req.laa_config.ed_threshold_lbt_pdsch.tl.tag = NFAPI_LAA_CONFIG_ED_THRESHOLD_FOR_LBT_FOR_PDSCH_TAG; + req.num_tlv++; + req.laa_config.ed_threshold_lbt_drs.tl.tag = NFAPI_LAA_CONFIG_ED_THRESHOLD_FOR_LBT_FOR_DRS_TAG; + req.num_tlv++; + req.laa_config.pd_threshold.tl.tag = NFAPI_LAA_CONFIG_PD_THRESHOLD_TAG; + req.num_tlv++; + req.laa_config.multi_carrier_type.tl.tag = NFAPI_LAA_CONFIG_MULTI_CARRIER_TYPE_TAG; + req.num_tlv++; + req.laa_config.multi_carrier_tx.tl.tag = NFAPI_LAA_CONFIG_MULTI_CARRIER_TX_TAG; + req.num_tlv++; + req.laa_config.multi_carrier_freeze.tl.tag = NFAPI_LAA_CONFIG_MULTI_CARRIER_FREEZE_TAG; + req.num_tlv++; + req.laa_config.tx_antenna_ports_drs.tl.tag = NFAPI_LAA_CONFIG_TX_ANTENNA_PORTS_FOR_DRS_TAG; + req.num_tlv++; + req.laa_config.tx_power_drs.tl.tag = NFAPI_LAA_CONFIG_TRANSMISSION_POWER_FOR_DRS_TAG; + req.num_tlv++; + req.emtc_config.pbch_repetitions_enable_r13.tl.tag = NFAPI_EMTC_CONFIG_PBCH_REPETITIONS_ENABLE_R13_TAG; + req.num_tlv++; + req.emtc_config.prach_catm_root_sequence_index.tl.tag = NFAPI_EMTC_CONFIG_PRACH_CATM_ROOT_SEQUENCE_INDEX_TAG; + req.num_tlv++; + req.emtc_config.prach_catm_zero_correlation_zone_configuration.tl.tag = NFAPI_EMTC_CONFIG_PRACH_CATM_ZERO_CORRELATION_ZONE_CONFIGURATION_TAG; + req.num_tlv++; + req.emtc_config.prach_catm_high_speed_flag.tl.tag = NFAPI_EMTC_CONFIG_PRACH_CATM_HIGH_SPEED_FLAG; + req.num_tlv++; + req.emtc_config.prach_ce_level_0_enable.tl.tag = NFAPI_EMTC_CONFIG_PRACH_CE_LEVEL_0_ENABLE_TAG; + req.num_tlv++; + req.emtc_config.prach_ce_level_0_configuration_index.tl.tag = NFAPI_EMTC_CONFIG_PRACH_CE_LEVEL_0_CONFIGURATION_INDEX_TAG; + req.num_tlv++; + req.emtc_config.prach_ce_level_0_frequency_offset.tl.tag = NFAPI_EMTC_CONFIG_PRACH_CE_LEVEL_0_FREQUENCY_OFFSET_TAG; + req.num_tlv++; + req.emtc_config.prach_ce_level_0_number_of_repetitions_per_attempt.tl.tag = NFAPI_EMTC_CONFIG_PRACH_CE_LEVEL_0_NUMBER_OF_REPETITIONS_PER_ATTEMPT_TAG; + req.num_tlv++; + req.emtc_config.prach_ce_level_0_starting_subframe_periodicity.tl.tag = NFAPI_EMTC_CONFIG_PRACH_CE_LEVEL_0_STARTING_SUBFRAME_PERIODICITY_TAG; + req.num_tlv++; + req.emtc_config.prach_ce_level_0_hopping_enable.tl.tag = NFAPI_EMTC_CONFIG_PRACH_CE_LEVEL_0_HOPPING_ENABLE_TAG; + req.num_tlv++; + req.emtc_config.prach_ce_level_0_hopping_offset.tl.tag = NFAPI_EMTC_CONFIG_PRACH_CE_LEVEL_0_HOPPING_OFFSET_TAG; + req.num_tlv++; + req.emtc_config.prach_ce_level_1_enable.tl.tag = NFAPI_EMTC_CONFIG_PRACH_CE_LEVEL_1_ENABLE_TAG; + req.num_tlv++; + req.emtc_config.prach_ce_level_1_configuration_index.tl.tag = NFAPI_EMTC_CONFIG_PRACH_CE_LEVEL_1_CONFIGURATION_INDEX_TAG; + req.num_tlv++; + req.emtc_config.prach_ce_level_1_frequency_offset.tl.tag = NFAPI_EMTC_CONFIG_PRACH_CE_LEVEL_1_FREQUENCY_OFFSET_TAG; + req.num_tlv++; + req.emtc_config.prach_ce_level_1_number_of_repetitions_per_attempt.tl.tag = NFAPI_EMTC_CONFIG_PRACH_CE_LEVEL_1_NUMBER_OF_REPETITIONS_PER_ATTEMPT_TAG; + req.num_tlv++; + req.emtc_config.prach_ce_level_1_starting_subframe_periodicity.tl.tag = NFAPI_EMTC_CONFIG_PRACH_CE_LEVEL_1_STARTING_SUBFRAME_PERIODICITY_TAG; + req.num_tlv++; + req.emtc_config.prach_ce_level_1_hopping_enable.tl.tag = NFAPI_EMTC_CONFIG_PRACH_CE_LEVEL_1_HOPPING_ENABLE_TAG; + req.num_tlv++; + req.emtc_config.prach_ce_level_1_hopping_offset.tl.tag = NFAPI_EMTC_CONFIG_PRACH_CE_LEVEL_1_HOPPING_OFFSET_TAG; + req.num_tlv++; + req.emtc_config.prach_ce_level_2_enable.tl.tag = NFAPI_EMTC_CONFIG_PRACH_CE_LEVEL_2_ENABLE_TAG; + req.num_tlv++; + req.emtc_config.prach_ce_level_2_configuration_index.tl.tag = NFAPI_EMTC_CONFIG_PRACH_CE_LEVEL_2_CONFIGURATION_INDEX_TAG; + req.num_tlv++; + req.emtc_config.prach_ce_level_2_frequency_offset.tl.tag = NFAPI_EMTC_CONFIG_PRACH_CE_LEVEL_2_FREQUENCY_OFFSET_TAG; + req.num_tlv++; + req.emtc_config.prach_ce_level_2_number_of_repetitions_per_attempt.tl.tag = NFAPI_EMTC_CONFIG_PRACH_CE_LEVEL_2_NUMBER_OF_REPETITIONS_PER_ATTEMPT_TAG; + req.num_tlv++; + req.emtc_config.prach_ce_level_2_starting_subframe_periodicity.tl.tag = NFAPI_EMTC_CONFIG_PRACH_CE_LEVEL_2_STARTING_SUBFRAME_PERIODICITY_TAG; + req.num_tlv++; + req.emtc_config.prach_ce_level_2_hopping_enable.tl.tag = NFAPI_EMTC_CONFIG_PRACH_CE_LEVEL_2_HOPPING_ENABLE_TAG; + req.num_tlv++; + req.emtc_config.prach_ce_level_2_hopping_offset.tl.tag = NFAPI_EMTC_CONFIG_PRACH_CE_LEVEL_2_HOPPING_OFFSET_TAG; + req.num_tlv++; + req.emtc_config.prach_ce_level_3_enable.tl.tag = NFAPI_EMTC_CONFIG_PRACH_CE_LEVEL_3_ENABLE_TAG; + req.num_tlv++; + req.emtc_config.prach_ce_level_3_configuration_index.tl.tag = NFAPI_EMTC_CONFIG_PRACH_CE_LEVEL_3_CONFIGURATION_INDEX_TAG; + req.num_tlv++; + req.emtc_config.prach_ce_level_3_frequency_offset.tl.tag = NFAPI_EMTC_CONFIG_PRACH_CE_LEVEL_3_FREQUENCY_OFFSET_TAG; + req.num_tlv++; + req.emtc_config.prach_ce_level_3_number_of_repetitions_per_attempt.tl.tag = NFAPI_EMTC_CONFIG_PRACH_CE_LEVEL_3_NUMBER_OF_REPETITIONS_PER_ATTEMPT_TAG; + req.num_tlv++; + req.emtc_config.prach_ce_level_3_starting_subframe_periodicity.tl.tag = NFAPI_EMTC_CONFIG_PRACH_CE_LEVEL_3_STARTING_SUBFRAME_PERIODICITY_TAG; + req.num_tlv++; + req.emtc_config.prach_ce_level_3_hopping_enable.tl.tag = NFAPI_EMTC_CONFIG_PRACH_CE_LEVEL_3_HOPPING_ENABLE_TAG; + req.num_tlv++; + req.emtc_config.prach_ce_level_3_hopping_offset.tl.tag = NFAPI_EMTC_CONFIG_PRACH_CE_LEVEL_3_HOPPING_OFFSET_TAG; + req.num_tlv++; + req.emtc_config.pucch_interval_ulhoppingconfigcommonmodea.tl.tag = NFAPI_EMTC_CONFIG_PUCCH_INTERVAL_ULHOPPINGCONFIGCOMMONMODEA_TAG; + req.num_tlv++; + req.emtc_config.pucch_interval_ulhoppingconfigcommonmodeb.tl.tag = NFAPI_EMTC_CONFIG_PUCCH_INTERVAL_ULHOPPINGCONFIGCOMMONMODEB_TAG; + req.num_tlv++; + req.nb_iot_config.operating_mode.tl.tag = NFAPI_NB_IOT_CONFIG_OPERATING_MODE_TAG; + req.nb_iot_config.operating_mode.value = rand_range(0, 3); + req.num_tlv++; + req.nb_iot_config.anchor.tl.tag = NFAPI_NB_IOT_CONFIG_ANCHOR_TAG; + req.nb_iot_config.anchor.value = rand_range(0, 1); + req.num_tlv++; + req.nb_iot_config.prb_index.tl.tag = NFAPI_NB_IOT_CONFIG_PRB_INDEX_TAG; + req.nb_iot_config.prb_index.value = rand_range(0, 0x1F); + req.num_tlv++; + req.nb_iot_config.control_region_size.tl.tag = NFAPI_NB_IOT_CONFIG_CONTROL_REGION_SIZE_TAG; + req.nb_iot_config.control_region_size.value = rand_range(1, 4); + req.num_tlv++; + req.nb_iot_config.assumed_crs_aps.tl.tag = NFAPI_NB_IOT_CONFIG_ASSUMED_CRS_APS_TAG; + req.nb_iot_config.assumed_crs_aps.value = rand_range(0, 1); + req.num_tlv++; + req.nb_iot_config.nprach_config_0_enabled.tl.tag = NFAPI_NB_IOT_CONFIG_NPRACH_CONFIG_0_ENABLED_TAG; + req.nb_iot_config.nprach_config_0_enabled.value = rand_range(0, 1); + req.num_tlv++; + req.nb_iot_config.nprach_config_0_sf_periodicity.tl.tag = NFAPI_NB_IOT_CONFIG_NPRACH_CONFIG_0_SF_PERIODICITY_TAG; + req.nb_iot_config.nprach_config_0_sf_periodicity.value = rand_range(0, 7); + req.num_tlv++; + req.nb_iot_config.nprach_config_0_start_time.tl.tag = NFAPI_NB_IOT_CONFIG_NPRACH_CONFIG_0_START_TIME_TAG; + req.nb_iot_config.nprach_config_0_start_time.value = rand_range(0, 7); + req.num_tlv++; + req.nb_iot_config.nprach_config_0_subcarrier_offset.tl.tag = NFAPI_NB_IOT_CONFIG_NPRACH_CONFIG_0_SUBCARRIER_OFFSET_TAG; + req.nb_iot_config.nprach_config_0_subcarrier_offset.value = rand_range(0, 6); + req.num_tlv++; + req.nb_iot_config.nprach_config_0_number_of_subcarriers.tl.tag = NFAPI_NB_IOT_CONFIG_NPRACH_CONFIG_0_NUMBER_OF_SUBCARRIERS_TAG; + req.nb_iot_config.nprach_config_0_number_of_subcarriers.value = rand_range(0, 3); + req.num_tlv++; + req.nb_iot_config.nprach_config_0_cp_length.tl.tag = NFAPI_NB_IOT_CONFIG_NPRACH_CONFIG_0_CP_LENGTH_TAG; + req.nb_iot_config.nprach_config_0_cp_length.value = rand_range(0, 1); + req.num_tlv++; + req.nb_iot_config.nprach_config_0_number_of_repetitions_per_attempt.tl.tag = NFAPI_NB_IOT_CONFIG_NPRACH_CONFIG_0_NUMBER_OF_REPETITIONS_PER_ATTEMPT_TAG; + req.nb_iot_config.nprach_config_0_number_of_repetitions_per_attempt.value = rand_range(0, 7); + req.num_tlv++; + req.nb_iot_config.nprach_config_1_enabled.tl.tag = NFAPI_NB_IOT_CONFIG_NPRACH_CONFIG_1_ENABLED_TAG; + req.nb_iot_config.nprach_config_1_enabled.value = rand_range(0, 1); + req.num_tlv++; + req.nb_iot_config.nprach_config_1_sf_periodicity.tl.tag = NFAPI_NB_IOT_CONFIG_NPRACH_CONFIG_1_SF_PERIODICITY_TAG; + req.nb_iot_config.nprach_config_1_sf_periodicity.value = rand_range(0, 7); + req.num_tlv++; + req.nb_iot_config.nprach_config_1_start_time.tl.tag = NFAPI_NB_IOT_CONFIG_NPRACH_CONFIG_1_START_TIME_TAG; + req.nb_iot_config.nprach_config_1_start_time.value = rand_range(0, 7); + req.num_tlv++; + req.nb_iot_config.nprach_config_1_subcarrier_offset.tl.tag = NFAPI_NB_IOT_CONFIG_NPRACH_CONFIG_1_SUBCARRIER_OFFSET_TAG; + req.nb_iot_config.nprach_config_1_subcarrier_offset.value = rand_range(0, 6); + req.num_tlv++; + req.nb_iot_config.nprach_config_1_number_of_subcarriers.tl.tag = NFAPI_NB_IOT_CONFIG_NPRACH_CONFIG_1_NUMBER_OF_SUBCARRIERS_TAG; + req.nb_iot_config.nprach_config_1_number_of_subcarriers.value = rand_range(0, 3); + req.num_tlv++; + req.nb_iot_config.nprach_config_1_cp_length.tl.tag = NFAPI_NB_IOT_CONFIG_NPRACH_CONFIG_1_CP_LENGTH_TAG; + req.nb_iot_config.nprach_config_1_cp_length.value = rand_range(0, 1); + req.num_tlv++; + req.nb_iot_config.nprach_config_1_number_of_repetitions_per_attempt.tl.tag = NFAPI_NB_IOT_CONFIG_NPRACH_CONFIG_1_NUMBER_OF_REPETITIONS_PER_ATTEMPT_TAG; + req.nb_iot_config.nprach_config_1_number_of_repetitions_per_attempt.value = rand_range(0, 7); + req.num_tlv++; + req.nb_iot_config.nprach_config_2_enabled.tl.tag = NFAPI_NB_IOT_CONFIG_NPRACH_CONFIG_2_ENABLED_TAG; + req.nb_iot_config.nprach_config_2_enabled.value = rand_range(0, 1); + req.num_tlv++; + req.nb_iot_config.nprach_config_2_sf_periodicity.tl.tag = NFAPI_NB_IOT_CONFIG_NPRACH_CONFIG_2_SF_PERIODICITY_TAG; + req.nb_iot_config.nprach_config_2_sf_periodicity.value = rand_range(0, 7); + req.num_tlv++; + req.nb_iot_config.nprach_config_2_start_time.tl.tag = NFAPI_NB_IOT_CONFIG_NPRACH_CONFIG_2_START_TIME_TAG; + req.nb_iot_config.nprach_config_2_start_time.value = rand_range(0, 7); + req.num_tlv++; + req.nb_iot_config.nprach_config_2_subcarrier_offset.tl.tag = NFAPI_NB_IOT_CONFIG_NPRACH_CONFIG_2_SUBCARRIER_OFFSET_TAG; + req.nb_iot_config.nprach_config_2_subcarrier_offset.value = rand_range(0, 6); + req.num_tlv++; + req.nb_iot_config.nprach_config_2_number_of_subcarriers.tl.tag = NFAPI_NB_IOT_CONFIG_NPRACH_CONFIG_2_NUMBER_OF_SUBCARRIERS_TAG; + req.nb_iot_config.nprach_config_2_number_of_subcarriers.value = rand_range(0, 3); + req.num_tlv++; + req.nb_iot_config.nprach_config_2_cp_length.tl.tag = NFAPI_NB_IOT_CONFIG_NPRACH_CONFIG_2_CP_LENGTH_TAG; + req.nb_iot_config.nprach_config_2_cp_length.value = rand_range(0, 1); + req.num_tlv++; + req.nb_iot_config.nprach_config_2_number_of_repetitions_per_attempt.tl.tag = NFAPI_NB_IOT_CONFIG_NPRACH_CONFIG_2_NUMBER_OF_REPETITIONS_PER_ATTEMPT_TAG; + req.nb_iot_config.nprach_config_2_number_of_repetitions_per_attempt.value = rand_range(0, 7); + req.num_tlv++; + req.nb_iot_config.three_tone_base_sequence.tl.tag = NFAPI_NB_IOT_CONFIG_THREE_TONE_BASE_SEQUENCE_TAG; + req.nb_iot_config.three_tone_base_sequence.value = rand_range(0, 0x0F); + req.num_tlv++; + req.nb_iot_config.six_tone_base_sequence.tl.tag = NFAPI_NB_IOT_CONFIG_SIX_TONE_BASE_SEQUENCE_TAG; + req.nb_iot_config.six_tone_base_sequence.value = rand_range(0, 0x03); + req.num_tlv++; + req.nb_iot_config.twelve_tone_base_sequence.tl.tag = NFAPI_NB_IOT_CONFIG_TWELVE_TONE_BASE_SEQUENCE_TAG; + req.nb_iot_config.twelve_tone_base_sequence.value = rand_range(0, 0x1F); + req.num_tlv++; + req.nb_iot_config.three_tone_cyclic_shift.tl.tag = NFAPI_NB_IOT_CONFIG_THREE_TONE_CYCLIC_SHIFT_TAG; + req.nb_iot_config.three_tone_cyclic_shift.value = rand_range(0, 5); // what is the max + req.num_tlv++; + req.nb_iot_config.six_tone_cyclic_shift.tl.tag = NFAPI_NB_IOT_CONFIG_SIX_TONE_CYCLIC_SHIFT_TAG; + req.nb_iot_config.six_tone_cyclic_shift.value = rand_range(0, 5); // what is the max + req.num_tlv++; + req.nb_iot_config.dl_gap_config_enable.tl.tag = NFAPI_NB_IOT_CONFIG_DL_GAP_CONFIG_ENABLE_TAG; + req.nb_iot_config.dl_gap_config_enable.value = rand_range(0, 1); + req.num_tlv++; + req.nb_iot_config.dl_gap_threshold.tl.tag = NFAPI_NB_IOT_CONFIG_DL_GAP_THRESHOLD_TAG; + req.nb_iot_config.dl_gap_threshold.value = rand_range(0, 3); + req.num_tlv++; + req.nb_iot_config.dl_gap_periodicity.tl.tag = NFAPI_NB_IOT_CONFIG_DL_GAP_PERIODICITY_TAG; + req.nb_iot_config.dl_gap_periodicity.value = rand_range(0, 3); + req.num_tlv++; + req.nb_iot_config.dl_gap_duration_coefficient.tl.tag = NFAPI_NB_IOT_CONFIG_DL_GAP_DURATION_COEFFICIENT_TAG; + req.nb_iot_config.dl_gap_duration_coefficient.value = rand_range(0, 3); + req.num_tlv++; + req.tdd_frame_structure_config.subframe_assignment.tl.tag = NFAPI_TDD_FRAME_STRUCTURE_SUBFRAME_ASSIGNMENT_TAG; + req.num_tlv++; + req.tdd_frame_structure_config.special_subframe_patterns.tl.tag = NFAPI_TDD_FRAME_STRUCTURE_SPECIAL_SUBFRAME_PATTERNS_TAG; + req.num_tlv++; + req.l23_config.data_report_mode.tl.tag = NFAPI_L23_CONFIG_DATA_REPORT_MODE_TAG; + req.num_tlv++; + req.l23_config.sfnsf.tl.tag = NFAPI_L23_CONFIG_SFNSF_TAG; + req.num_tlv++; + } + + vendor_ext_tlv_2 ve2; + memset(&ve2, 0, sizeof(ve2)); + ve2.tl.tag = VENDOR_EXT_TLV_2_TAG; + ve2.dummy = 2016; + req.vendor_extension = &ve2.tl; + nfapi_vnf_config_req(config, p5_idx, &req); + } else { + printf("[VNF_SIM] param response failed to find pnf %d phy %d\n", p5_idx, resp->header.phy_id); + } + } else { + printf("[VNF_SIM] param response failed to find pnf %d\n", p5_idx); + } -void test_p4_requests(nfapi_vnf_config_t* config, int p5_idx, int phy_id) -{ - { - nfapi_measurement_request_t req; - memset(&req, 0, sizeof(req)); - req.header.message_id = NFAPI_MEASUREMENT_REQUEST; - req.header.phy_id = phy_id; - - req.dl_rs_tx_power.tl.tag = NFAPI_MEASUREMENT_REQUEST_DL_RS_XTX_POWER_TAG; - req.dl_rs_tx_power.value = 42; - req.received_interference_power.tl.tag = NFAPI_MEASUREMENT_REQUEST_RECEIVED_INTERFERENCE_POWER_TAG; - req.received_interference_power.value = 42; - req.thermal_noise_power.tl.tag = NFAPI_MEASUREMENT_REQUEST_THERMAL_NOISE_POWER_TAG; - req.thermal_noise_power.value = 42; - - nfapi_vnf_measurement_req(config, p5_idx, &req); - } - { - nfapi_rssi_request_t lte_req; - memset(<e_req, 0, sizeof(lte_req)); - lte_req.header.message_id = NFAPI_RSSI_REQUEST; - lte_req.header.phy_id = phy_id; - - lte_req.rat_type = NFAPI_RAT_TYPE_LTE; - lte_req.lte_rssi_request.tl.tag = NFAPI_LTE_RSSI_REQUEST_TAG; - lte_req.lte_rssi_request.frequency_band_indicator = 2; - lte_req.lte_rssi_request.measurement_period = 1000; - lte_req.lte_rssi_request.bandwidth = 50; - lte_req.lte_rssi_request.timeout = 0; - lte_req.lte_rssi_request.number_of_earfcns = 2; - lte_req.lte_rssi_request.earfcn[0] = 389; - lte_req.lte_rssi_request.earfcn[1] = 123; - - nfapi_vnf_rssi_request(config, p5_idx, <e_req); - - nfapi_rssi_request_t utran_req; - memset(&utran_req, 0, sizeof(utran_req)); - utran_req.header.message_id = NFAPI_RSSI_REQUEST; - utran_req.header.phy_id = phy_id; - - utran_req.rat_type = NFAPI_RAT_TYPE_UTRAN; - utran_req.utran_rssi_request.tl.tag = NFAPI_UTRAN_RSSI_REQUEST_TAG; - utran_req.utran_rssi_request.frequency_band_indicator = 2; - utran_req.utran_rssi_request.measurement_period = 1000; - utran_req.utran_rssi_request.timeout = 0; - utran_req.utran_rssi_request.number_of_uarfcns = 2; - utran_req.utran_rssi_request.uarfcn[0] = 2348; - utran_req.utran_rssi_request.uarfcn[1] = 52; - - nfapi_vnf_rssi_request(config, p5_idx, &utran_req); - - - nfapi_rssi_request_t geran_req; - memset(&geran_req, 0, sizeof(geran_req)); - geran_req.header.message_id = NFAPI_RSSI_REQUEST; - geran_req.header.phy_id = phy_id; - - geran_req.rat_type = NFAPI_RAT_TYPE_GERAN; - geran_req.geran_rssi_request.tl.tag = NFAPI_GERAN_RSSI_REQUEST_TAG; - geran_req.geran_rssi_request.frequency_band_indicator = 2; - geran_req.geran_rssi_request.measurement_period = 1000; - geran_req.geran_rssi_request.timeout = 0; - geran_req.geran_rssi_request.number_of_arfcns = 1; - geran_req.geran_rssi_request.arfcn[0].arfcn = 34; - geran_req.geran_rssi_request.arfcn[0].direction = 0; - - nfapi_vnf_rssi_request(config, p5_idx, &geran_req); - } - { - nfapi_cell_search_request_t lte_req; - memset(<e_req, 0, sizeof(lte_req)); - lte_req.header.message_id = NFAPI_CELL_SEARCH_REQUEST; - lte_req.header.phy_id = phy_id; - - lte_req.rat_type = NFAPI_RAT_TYPE_LTE; - lte_req.lte_cell_search_request.tl.tag = NFAPI_LTE_CELL_SEARCH_REQUEST_TAG; - lte_req.lte_cell_search_request.earfcn = 1234; - lte_req.lte_cell_search_request.measurement_bandwidth = 50; - lte_req.lte_cell_search_request.exhaustive_search = 1; - lte_req.lte_cell_search_request.timeout = 1000; - lte_req.lte_cell_search_request.number_of_pci = 1; - lte_req.lte_cell_search_request.pci[0] = 234; - - nfapi_vnf_cell_search_request(config, p5_idx, <e_req); - - nfapi_cell_search_request_t utran_req; - memset(&utran_req, 0, sizeof(utran_req)); - utran_req.header.message_id = NFAPI_CELL_SEARCH_REQUEST; - utran_req.header.phy_id = phy_id; - - utran_req.rat_type = NFAPI_RAT_TYPE_UTRAN; - utran_req.utran_cell_search_request.tl.tag = NFAPI_UTRAN_CELL_SEARCH_REQUEST_TAG; - utran_req.utran_cell_search_request.uarfcn = 1234; - utran_req.utran_cell_search_request.exhaustive_search = 0; - utran_req.utran_cell_search_request.timeout = 1000; - utran_req.utran_cell_search_request.number_of_psc = 1; - utran_req.utran_cell_search_request.psc[0] = 234; - - nfapi_vnf_cell_search_request(config, p5_idx, &utran_req); - - nfapi_cell_search_request_t geran_req; - memset(&geran_req, 0, sizeof(geran_req)); - geran_req.header.message_id = NFAPI_CELL_SEARCH_REQUEST; - geran_req.header.phy_id = phy_id; - - geran_req.rat_type = NFAPI_RAT_TYPE_GERAN; - geran_req.geran_cell_search_request.tl.tag = NFAPI_GERAN_CELL_SEARCH_REQUEST_TAG; - geran_req.geran_cell_search_request.timeout = 1000; - geran_req.geran_cell_search_request.number_of_arfcn = 1; - geran_req.geran_cell_search_request.arfcn[0] = 8765; - - nfapi_vnf_cell_search_request(config, p5_idx, &geran_req); - } - { - nfapi_broadcast_detect_request_t lte_req; - memset(<e_req, 0, sizeof(lte_req)); - lte_req.header.message_id = NFAPI_BROADCAST_DETECT_REQUEST; - lte_req.header.phy_id = phy_id; - - lte_req.rat_type = NFAPI_RAT_TYPE_LTE; - lte_req.lte_broadcast_detect_request.tl.tag = NFAPI_LTE_BROADCAST_DETECT_REQUEST_TAG; - lte_req.lte_broadcast_detect_request.earfcn = 1234; - lte_req.lte_broadcast_detect_request.pci = 50; - lte_req.lte_broadcast_detect_request.timeout = 1000; - - lte_req.pnf_cell_search_state.tl.tag = NFAPI_PNF_CELL_SEARCH_STATE_TAG; - lte_req.pnf_cell_search_state.length = 3; - - nfapi_vnf_broadcast_detect_request(config, p5_idx, <e_req); - - nfapi_broadcast_detect_request_t utran_req; - memset(&utran_req, 0, sizeof(utran_req)); - utran_req.header.message_id = NFAPI_BROADCAST_DETECT_REQUEST; - utran_req.header.phy_id = phy_id; - - utran_req.rat_type = NFAPI_RAT_TYPE_LTE; - utran_req.utran_broadcast_detect_request.tl.tag = NFAPI_UTRAN_BROADCAST_DETECT_REQUEST_TAG; - utran_req.utran_broadcast_detect_request.uarfcn = 1234; - utran_req.utran_broadcast_detect_request.psc = 50; - utran_req.utran_broadcast_detect_request.timeout = 1000; - - utran_req.pnf_cell_search_state.tl.tag = NFAPI_PNF_CELL_SEARCH_STATE_TAG; - utran_req.pnf_cell_search_state.length = 3; - - nfapi_vnf_broadcast_detect_request(config, p5_idx, &utran_req); - } - { - nfapi_system_information_schedule_request_t lte_req; - memset(<e_req, 0, sizeof(lte_req)); - lte_req.header.message_id = NFAPI_SYSTEM_INFORMATION_SCHEDULE_REQUEST; - lte_req.header.phy_id = phy_id; - - lte_req.rat_type = NFAPI_RAT_TYPE_LTE; - lte_req.lte_system_information_schedule_request.tl.tag = NFAPI_LTE_SYSTEM_INFORMATION_SCHEDULE_REQUEST_TAG; - lte_req.lte_system_information_schedule_request.earfcn = 1234; - lte_req.lte_system_information_schedule_request.pci = 50; - lte_req.lte_system_information_schedule_request.downlink_channel_bandwidth = 100; - lte_req.lte_system_information_schedule_request.phich_configuration = 3; - lte_req.lte_system_information_schedule_request.number_of_tx_antenna = 2; - lte_req.lte_system_information_schedule_request.retry_count = 4; - lte_req.lte_system_information_schedule_request.timeout = 1000; - - lte_req.pnf_cell_broadcast_state.tl.tag = NFAPI_PNF_CELL_BROADCAST_STATE_TAG; - lte_req.pnf_cell_broadcast_state.length = 3; - - nfapi_vnf_system_information_schedule_request(config, p5_idx, <e_req); - } - { - nfapi_system_information_request_t lte_req; - memset(<e_req, 0, sizeof(lte_req)); - lte_req.header.message_id = NFAPI_SYSTEM_INFORMATION_REQUEST; - lte_req.header.phy_id = phy_id; - - lte_req.rat_type = NFAPI_RAT_TYPE_LTE; - lte_req.lte_system_information_request.tl.tag = NFAPI_LTE_SYSTEM_INFORMATION_REQUEST_TAG; - lte_req.lte_system_information_request.earfcn = 1234; - lte_req.lte_system_information_request.pci= 456; - lte_req.lte_system_information_request.downlink_channel_bandwidth = 5; - lte_req.lte_system_information_request.phich_configuration = 2; - lte_req.lte_system_information_request.number_of_tx_antenna = 2; - lte_req.lte_system_information_request.number_of_si_periodicity = 1; - lte_req.lte_system_information_request.si_periodicity[0].si_periodicity = 3; - lte_req.lte_system_information_request.si_periodicity[0].si_index = 3; - lte_req.lte_system_information_request.si_window_length = 15; - lte_req.lte_system_information_request.timeout = 1000; - - nfapi_vnf_system_information_request(config, p5_idx, <e_req); - - nfapi_system_information_request_t utran_req; - memset(&utran_req, 0, sizeof(utran_req)); - utran_req.header.message_id = NFAPI_SYSTEM_INFORMATION_REQUEST; - utran_req.header.phy_id = phy_id; - - utran_req.rat_type = NFAPI_RAT_TYPE_UTRAN; - utran_req.utran_system_information_request.tl.tag = NFAPI_UTRAN_SYSTEM_INFORMATION_REQUEST_TAG; - utran_req.utran_system_information_request.uarfcn = 1234; - utran_req.utran_system_information_request.psc = 456; - utran_req.utran_system_information_request.timeout = 1000; - - nfapi_vnf_system_information_request(config, p5_idx, &utran_req); - - nfapi_system_information_request_t geran_req; - memset(&geran_req, 0, sizeof(geran_req)); - geran_req.header.message_id = NFAPI_SYSTEM_INFORMATION_REQUEST; - geran_req.header.phy_id = phy_id; - - geran_req.rat_type = NFAPI_RAT_TYPE_GERAN; - geran_req.geran_system_information_request.tl.tag = NFAPI_GERAN_SYSTEM_INFORMATION_REQUEST_TAG; - geran_req.geran_system_information_request.arfcn = 1234; - geran_req.geran_system_information_request.bsic = 21; - geran_req.geran_system_information_request.timeout = 1000; - - nfapi_vnf_system_information_request(config, p5_idx, &geran_req); - } - { - nfapi_nmm_stop_request_t req; - memset(&req, 0, sizeof(req)); - req.header.message_id = NFAPI_NMM_STOP_REQUEST; - req.header.phy_id = phy_id; - nfapi_vnf_nmm_stop_request(config, p5_idx, &req); - } + return 0; } +int config_resp_cb(nfapi_vnf_config_t *config, int p5_idx, nfapi_config_response_t *resp) { + printf("[VNF_SIM] config response idx:%d phy_id:%d\n", p5_idx, resp->header.phy_id); + nfapi_start_request_t req; + memset(&req, 0, sizeof(req)); + req.header.message_id = NFAPI_START_REQUEST; + req.header.phy_id = resp->header.phy_id; + nfapi_vnf_start_req(config, p5_idx, &req); + return 0; +} -int start_resp_cb(nfapi_vnf_config_t* config, int p5_idx, nfapi_start_response_t* resp) -{ - printf("[VNF_SIM] start response idx:%d phy_id:%d\n", p5_idx, resp->header.phy_id); - - vnf_info* vnf = (vnf_info*)(config->user_data); - - if(vnf->wireshark_test_mode) - test_p4_requests(config, p5_idx, resp->header.phy_id); +void test_p4_requests(nfapi_vnf_config_t *config, int p5_idx, int phy_id) { + { + nfapi_measurement_request_t req; + memset(&req, 0, sizeof(req)); + req.header.message_id = NFAPI_MEASUREMENT_REQUEST; + req.header.phy_id = phy_id; + req.dl_rs_tx_power.tl.tag = NFAPI_MEASUREMENT_REQUEST_DL_RS_XTX_POWER_TAG; + req.dl_rs_tx_power.value = 42; + req.received_interference_power.tl.tag = NFAPI_MEASUREMENT_REQUEST_RECEIVED_INTERFERENCE_POWER_TAG; + req.received_interference_power.value = 42; + req.thermal_noise_power.tl.tag = NFAPI_MEASUREMENT_REQUEST_THERMAL_NOISE_POWER_TAG; + req.thermal_noise_power.value = 42; + nfapi_vnf_measurement_req(config, p5_idx, &req); + } + { + nfapi_rssi_request_t lte_req; + memset(<e_req, 0, sizeof(lte_req)); + lte_req.header.message_id = NFAPI_RSSI_REQUEST; + lte_req.header.phy_id = phy_id; + lte_req.rat_type = NFAPI_RAT_TYPE_LTE; + lte_req.lte_rssi_request.tl.tag = NFAPI_LTE_RSSI_REQUEST_TAG; + lte_req.lte_rssi_request.frequency_band_indicator = 2; + lte_req.lte_rssi_request.measurement_period = 1000; + lte_req.lte_rssi_request.bandwidth = 50; + lte_req.lte_rssi_request.timeout = 0; + lte_req.lte_rssi_request.number_of_earfcns = 2; + lte_req.lte_rssi_request.earfcn[0] = 389; + lte_req.lte_rssi_request.earfcn[1] = 123; + nfapi_vnf_rssi_request(config, p5_idx, <e_req); + nfapi_rssi_request_t utran_req; + memset(&utran_req, 0, sizeof(utran_req)); + utran_req.header.message_id = NFAPI_RSSI_REQUEST; + utran_req.header.phy_id = phy_id; + utran_req.rat_type = NFAPI_RAT_TYPE_UTRAN; + utran_req.utran_rssi_request.tl.tag = NFAPI_UTRAN_RSSI_REQUEST_TAG; + utran_req.utran_rssi_request.frequency_band_indicator = 2; + utran_req.utran_rssi_request.measurement_period = 1000; + utran_req.utran_rssi_request.timeout = 0; + utran_req.utran_rssi_request.number_of_uarfcns = 2; + utran_req.utran_rssi_request.uarfcn[0] = 2348; + utran_req.utran_rssi_request.uarfcn[1] = 52; + nfapi_vnf_rssi_request(config, p5_idx, &utran_req); + nfapi_rssi_request_t geran_req; + memset(&geran_req, 0, sizeof(geran_req)); + geran_req.header.message_id = NFAPI_RSSI_REQUEST; + geran_req.header.phy_id = phy_id; + geran_req.rat_type = NFAPI_RAT_TYPE_GERAN; + geran_req.geran_rssi_request.tl.tag = NFAPI_GERAN_RSSI_REQUEST_TAG; + geran_req.geran_rssi_request.frequency_band_indicator = 2; + geran_req.geran_rssi_request.measurement_period = 1000; + geran_req.geran_rssi_request.timeout = 0; + geran_req.geran_rssi_request.number_of_arfcns = 1; + geran_req.geran_rssi_request.arfcn[0].arfcn = 34; + geran_req.geran_rssi_request.arfcn[0].direction = 0; + nfapi_vnf_rssi_request(config, p5_idx, &geran_req); + } + { + nfapi_cell_search_request_t lte_req; + memset(<e_req, 0, sizeof(lte_req)); + lte_req.header.message_id = NFAPI_CELL_SEARCH_REQUEST; + lte_req.header.phy_id = phy_id; + lte_req.rat_type = NFAPI_RAT_TYPE_LTE; + lte_req.lte_cell_search_request.tl.tag = NFAPI_LTE_CELL_SEARCH_REQUEST_TAG; + lte_req.lte_cell_search_request.earfcn = 1234; + lte_req.lte_cell_search_request.measurement_bandwidth = 50; + lte_req.lte_cell_search_request.exhaustive_search = 1; + lte_req.lte_cell_search_request.timeout = 1000; + lte_req.lte_cell_search_request.number_of_pci = 1; + lte_req.lte_cell_search_request.pci[0] = 234; + nfapi_vnf_cell_search_request(config, p5_idx, <e_req); + nfapi_cell_search_request_t utran_req; + memset(&utran_req, 0, sizeof(utran_req)); + utran_req.header.message_id = NFAPI_CELL_SEARCH_REQUEST; + utran_req.header.phy_id = phy_id; + utran_req.rat_type = NFAPI_RAT_TYPE_UTRAN; + utran_req.utran_cell_search_request.tl.tag = NFAPI_UTRAN_CELL_SEARCH_REQUEST_TAG; + utran_req.utran_cell_search_request.uarfcn = 1234; + utran_req.utran_cell_search_request.exhaustive_search = 0; + utran_req.utran_cell_search_request.timeout = 1000; + utran_req.utran_cell_search_request.number_of_psc = 1; + utran_req.utran_cell_search_request.psc[0] = 234; + nfapi_vnf_cell_search_request(config, p5_idx, &utran_req); + nfapi_cell_search_request_t geran_req; + memset(&geran_req, 0, sizeof(geran_req)); + geran_req.header.message_id = NFAPI_CELL_SEARCH_REQUEST; + geran_req.header.phy_id = phy_id; + geran_req.rat_type = NFAPI_RAT_TYPE_GERAN; + geran_req.geran_cell_search_request.tl.tag = NFAPI_GERAN_CELL_SEARCH_REQUEST_TAG; + geran_req.geran_cell_search_request.timeout = 1000; + geran_req.geran_cell_search_request.number_of_arfcn = 1; + geran_req.geran_cell_search_request.arfcn[0] = 8765; + nfapi_vnf_cell_search_request(config, p5_idx, &geran_req); + } + { + nfapi_broadcast_detect_request_t lte_req; + memset(<e_req, 0, sizeof(lte_req)); + lte_req.header.message_id = NFAPI_BROADCAST_DETECT_REQUEST; + lte_req.header.phy_id = phy_id; + lte_req.rat_type = NFAPI_RAT_TYPE_LTE; + lte_req.lte_broadcast_detect_request.tl.tag = NFAPI_LTE_BROADCAST_DETECT_REQUEST_TAG; + lte_req.lte_broadcast_detect_request.earfcn = 1234; + lte_req.lte_broadcast_detect_request.pci = 50; + lte_req.lte_broadcast_detect_request.timeout = 1000; + lte_req.pnf_cell_search_state.tl.tag = NFAPI_PNF_CELL_SEARCH_STATE_TAG; + lte_req.pnf_cell_search_state.length = 3; + nfapi_vnf_broadcast_detect_request(config, p5_idx, <e_req); + nfapi_broadcast_detect_request_t utran_req; + memset(&utran_req, 0, sizeof(utran_req)); + utran_req.header.message_id = NFAPI_BROADCAST_DETECT_REQUEST; + utran_req.header.phy_id = phy_id; + utran_req.rat_type = NFAPI_RAT_TYPE_LTE; + utran_req.utran_broadcast_detect_request.tl.tag = NFAPI_UTRAN_BROADCAST_DETECT_REQUEST_TAG; + utran_req.utran_broadcast_detect_request.uarfcn = 1234; + utran_req.utran_broadcast_detect_request.psc = 50; + utran_req.utran_broadcast_detect_request.timeout = 1000; + utran_req.pnf_cell_search_state.tl.tag = NFAPI_PNF_CELL_SEARCH_STATE_TAG; + utran_req.pnf_cell_search_state.length = 3; + nfapi_vnf_broadcast_detect_request(config, p5_idx, &utran_req); + } + { + nfapi_system_information_schedule_request_t lte_req; + memset(<e_req, 0, sizeof(lte_req)); + lte_req.header.message_id = NFAPI_SYSTEM_INFORMATION_SCHEDULE_REQUEST; + lte_req.header.phy_id = phy_id; + lte_req.rat_type = NFAPI_RAT_TYPE_LTE; + lte_req.lte_system_information_schedule_request.tl.tag = NFAPI_LTE_SYSTEM_INFORMATION_SCHEDULE_REQUEST_TAG; + lte_req.lte_system_information_schedule_request.earfcn = 1234; + lte_req.lte_system_information_schedule_request.pci = 50; + lte_req.lte_system_information_schedule_request.downlink_channel_bandwidth = 100; + lte_req.lte_system_information_schedule_request.phich_configuration = 3; + lte_req.lte_system_information_schedule_request.number_of_tx_antenna = 2; + lte_req.lte_system_information_schedule_request.retry_count = 4; + lte_req.lte_system_information_schedule_request.timeout = 1000; + lte_req.pnf_cell_broadcast_state.tl.tag = NFAPI_PNF_CELL_BROADCAST_STATE_TAG; + lte_req.pnf_cell_broadcast_state.length = 3; + nfapi_vnf_system_information_schedule_request(config, p5_idx, <e_req); + } + { + nfapi_system_information_request_t lte_req; + memset(<e_req, 0, sizeof(lte_req)); + lte_req.header.message_id = NFAPI_SYSTEM_INFORMATION_REQUEST; + lte_req.header.phy_id = phy_id; + lte_req.rat_type = NFAPI_RAT_TYPE_LTE; + lte_req.lte_system_information_request.tl.tag = NFAPI_LTE_SYSTEM_INFORMATION_REQUEST_TAG; + lte_req.lte_system_information_request.earfcn = 1234; + lte_req.lte_system_information_request.pci= 456; + lte_req.lte_system_information_request.downlink_channel_bandwidth = 5; + lte_req.lte_system_information_request.phich_configuration = 2; + lte_req.lte_system_information_request.number_of_tx_antenna = 2; + lte_req.lte_system_information_request.number_of_si_periodicity = 1; + lte_req.lte_system_information_request.si_periodicity[0].si_periodicity = 3; + lte_req.lte_system_information_request.si_periodicity[0].si_index = 3; + lte_req.lte_system_information_request.si_window_length = 15; + lte_req.lte_system_information_request.timeout = 1000; + nfapi_vnf_system_information_request(config, p5_idx, <e_req); + nfapi_system_information_request_t utran_req; + memset(&utran_req, 0, sizeof(utran_req)); + utran_req.header.message_id = NFAPI_SYSTEM_INFORMATION_REQUEST; + utran_req.header.phy_id = phy_id; + utran_req.rat_type = NFAPI_RAT_TYPE_UTRAN; + utran_req.utran_system_information_request.tl.tag = NFAPI_UTRAN_SYSTEM_INFORMATION_REQUEST_TAG; + utran_req.utran_system_information_request.uarfcn = 1234; + utran_req.utran_system_information_request.psc = 456; + utran_req.utran_system_information_request.timeout = 1000; + nfapi_vnf_system_information_request(config, p5_idx, &utran_req); + nfapi_system_information_request_t geran_req; + memset(&geran_req, 0, sizeof(geran_req)); + geran_req.header.message_id = NFAPI_SYSTEM_INFORMATION_REQUEST; + geran_req.header.phy_id = phy_id; + geran_req.rat_type = NFAPI_RAT_TYPE_GERAN; + geran_req.geran_system_information_request.tl.tag = NFAPI_GERAN_SYSTEM_INFORMATION_REQUEST_TAG; + geran_req.geran_system_information_request.arfcn = 1234; + geran_req.geran_system_information_request.bsic = 21; + geran_req.geran_system_information_request.timeout = 1000; + nfapi_vnf_system_information_request(config, p5_idx, &geran_req); + } + { + nfapi_nmm_stop_request_t req; + memset(&req, 0, sizeof(req)); + req.header.message_id = NFAPI_NMM_STOP_REQUEST; + req.header.phy_id = phy_id; + nfapi_vnf_nmm_stop_request(config, p5_idx, &req); + } +} - auto find_result = vnf->pnfs.find(p5_idx); - if(find_result != vnf->pnfs.end()) - { - pnf_info& pnf = find_result->second; - - - auto found = std::find_if(pnf.phys.begin(), pnf.phys.end(), [&](phy_info& item) - { return item.id == resp->header.phy_id; }); - if(found != pnf.phys.end()) - { - phy_info& phy = (*found); +int start_resp_cb(nfapi_vnf_config_t *config, int p5_idx, nfapi_start_response_t *resp) { + printf("[VNF_SIM] start response idx:%d phy_id:%d\n", p5_idx, resp->header.phy_id); + vnf_info *vnf = (vnf_info *)(config->user_data); - vnf_p7_info& p7_vnf = vnf->p7_vnfs[0]; + if(vnf->wireshark_test_mode) + test_p4_requests(config, p5_idx, resp->header.phy_id); - nfapi_vnf_p7_add_pnf((p7_vnf.config.get()), phy.remote_addr.c_str(), phy.remote_port, phy.id); - + auto find_result = vnf->pnfs.find(p5_idx); - } + if(find_result != vnf->pnfs.end()) { + pnf_info &pnf = find_result->second; + auto found = std::find_if(pnf.phys.begin(), pnf.phys.end(), [&](phy_info& item) { + return item.id == resp->header.phy_id; + }); + if(found != pnf.phys.end()) { + phy_info &phy = (*found); + vnf_p7_info &p7_vnf = vnf->p7_vnfs[0]; + nfapi_vnf_p7_add_pnf((p7_vnf.config.get()), phy.remote_addr.c_str(), phy.remote_port, phy.id); + } + } - } - return 0; + return 0; } -nfapi_p4_p5_message_header_t* vnf_sim_allocate_p4_p5_vendor_ext(uint16_t message_id, uint16_t* msg_size) -{ - if(message_id == P5_VENDOR_EXT_RSP) - { - *msg_size = sizeof(vendor_ext_p5_rsp); - return (nfapi_p4_p5_message_header_t*)malloc(sizeof(vendor_ext_p5_rsp)); - } - return 0; +nfapi_p4_p5_message_header_t *vnf_sim_allocate_p4_p5_vendor_ext(uint16_t message_id, uint16_t *msg_size) { + if(message_id == P5_VENDOR_EXT_RSP) { + *msg_size = sizeof(vendor_ext_p5_rsp); + return (nfapi_p4_p5_message_header_t *)malloc(sizeof(vendor_ext_p5_rsp)); + } + + return 0; } -void vnf_sim_deallocate_p4_p5_vendor_ext(nfapi_p4_p5_message_header_t* header) -{ - free(header); +void vnf_sim_deallocate_p4_p5_vendor_ext(nfapi_p4_p5_message_header_t *header) { + free(header); } -int vendor_ext_cb(nfapi_vnf_config_t* config, int p5_idx, nfapi_p4_p5_message_header_t* msg) -{ - printf("[VNF_SIM] %s\n", __FUNCTION__); - - switch(msg->message_id) - { - case P5_VENDOR_EXT_RSP: - { - vendor_ext_p5_rsp* rsp = (vendor_ext_p5_rsp*)msg; - printf("[VNF_SIM] P5_VENDOR_EXT_RSP error_code:%d\n", rsp->error_code); - - // send the start request - - nfapi_pnf_start_request_t req; - memset(&req, 0, sizeof(req)); - req.header.message_id = NFAPI_PNF_START_REQUEST; - nfapi_vnf_pnf_start_req(config, p5_idx, &req); - } - break; - - } +int vendor_ext_cb(nfapi_vnf_config_t *config, int p5_idx, nfapi_p4_p5_message_header_t *msg) { + printf("[VNF_SIM] %s\n", __FUNCTION__); + + switch(msg->message_id) { + case P5_VENDOR_EXT_RSP: { + vendor_ext_p5_rsp *rsp = (vendor_ext_p5_rsp *)msg; + printf("[VNF_SIM] P5_VENDOR_EXT_RSP error_code:%d\n", rsp->error_code); + // send the start request + nfapi_pnf_start_request_t req; + memset(&req, 0, sizeof(req)); + req.header.message_id = NFAPI_PNF_START_REQUEST; + nfapi_vnf_pnf_start_req(config, p5_idx, &req); + } + break; + } - return 0; + return 0; } -int read_vnf_xml(vnf_info& vnf, const char* xml_file) -{ - try - { - - std::ifstream input(xml_file); - - using boost::property_tree::ptree; - ptree pt; - - read_xml(input, pt); - - - - for(const auto& v : pt.get_child("vnf.vnf_p7_list")) - { - if(v.first == "vnf_p7") - { - vnf_p7_info vnf_p7; - vnf_p7.local_port = v.second.get<unsigned>("port"); - vnf_p7.local_addr = v.second.get<std::string>("address"); - - vnf_p7.timing_window = v.second.get<unsigned>("timing_window"); - vnf_p7.periodic_timing_enabled = v.second.get<unsigned>("periodic_timing_enabled"); - vnf_p7.aperiodic_timing_enabled = v.second.get<unsigned>("aperiodic_timing_enabled"); - vnf_p7.periodic_timing_period = v.second.get<unsigned>("periodic_timing_window"); - - - boost::optional<const boost::property_tree::ptree&> d = v.second.get_child_optional("data.udp"); - if(d.is_initialized()) - { - vnf_p7.udp.enabled = true; - vnf_p7.udp.rx_port = d.get().get<unsigned>("rx_port"); - vnf_p7.udp.tx_port = d.get().get<unsigned>("tx_port"); - vnf_p7.udp.tx_addr = d.get().get<std::string>("tx_addr"); - } - else - { - vnf_p7.udp.enabled = false; - } - - vnf.wireshark_test_mode = v.second.get<unsigned>("wireshark_test_mode", 0); - - vnf_p7.mac = mac_create(vnf.wireshark_test_mode); - vnf_p7.mac->dl_config_req = &mac_dl_config_req; - vnf_p7.mac->ul_config_req = &mac_ul_config_req; - vnf_p7.mac->hi_dci0_req = &mac_hi_dci0_req; - vnf_p7.mac->tx_req = &mac_tx_req; - - if(vnf_p7.udp.enabled) - { - mac_start_data(vnf_p7.mac, - vnf_p7.udp.rx_port, - vnf_p7.udp.tx_addr.c_str(), - vnf_p7.udp.tx_port); - } - - vnf.p7_vnfs.push_back(vnf_p7); - } - } - } - catch(std::exception& e) - { - printf("%s", e.what()); - return -1; - } - catch(boost::exception& e) - { - printf("%s", boost::diagnostic_information(e).c_str()); - } - - struct ifaddrs *ifaddr; - getifaddrs(&ifaddr); - - - while(ifaddr) - { - int family = ifaddr->ifa_addr->sa_family; - if(family == AF_INET) - { - char host[128]; - getnameinfo(ifaddr->ifa_addr, sizeof(sockaddr_in), host, sizeof(host), NULL, 0, 0); - printf("%s\n", host); - } - ifaddr = ifaddr->ifa_next; - } - - return 0; +int read_vnf_xml(vnf_info &vnf, const char *xml_file) { + try { + std::ifstream input(xml_file); + using boost::property_tree::ptree; + ptree pt; + read_xml(input, pt); + + for(const auto &v : pt.get_child("vnf.vnf_p7_list")) { + if(v.first == "vnf_p7") { + vnf_p7_info vnf_p7; + vnf_p7.local_port = v.second.get<unsigned>("port"); + vnf_p7.local_addr = v.second.get<std::string>("address"); + vnf_p7.timing_window = v.second.get<unsigned>("timing_window"); + vnf_p7.periodic_timing_enabled = v.second.get<unsigned>("periodic_timing_enabled"); + vnf_p7.aperiodic_timing_enabled = v.second.get<unsigned>("aperiodic_timing_enabled"); + vnf_p7.periodic_timing_period = v.second.get<unsigned>("periodic_timing_window"); + boost::optional<const boost::property_tree::ptree &> d = v.second.get_child_optional("data.udp"); + + if(d.is_initialized()) { + vnf_p7.udp.enabled = true; + vnf_p7.udp.rx_port = d.get().get<unsigned>("rx_port"); + vnf_p7.udp.tx_port = d.get().get<unsigned>("tx_port"); + vnf_p7.udp.tx_addr = d.get().get<std::string>("tx_addr"); + } else { + vnf_p7.udp.enabled = false; + } + + vnf.wireshark_test_mode = v.second.get<unsigned>("wireshark_test_mode", 0); + vnf_p7.mac = mac_create(vnf.wireshark_test_mode); + vnf_p7.mac->dl_config_req = &mac_dl_config_req; + vnf_p7.mac->ul_config_req = &mac_ul_config_req; + vnf_p7.mac->hi_dci0_req = &mac_hi_dci0_req; + vnf_p7.mac->tx_req = &mac_tx_req; + + if(vnf_p7.udp.enabled) { + mac_start_data(vnf_p7.mac, + vnf_p7.udp.rx_port, + vnf_p7.udp.tx_addr.c_str(), + vnf_p7.udp.tx_port); + } + + vnf.p7_vnfs.push_back(vnf_p7); + } + } + } catch(std::exception &e) { + printf("%s", e.what()); + return -1; + } catch(boost::exception &e) { + printf("%s", boost::diagnostic_information(e).c_str()); + } + + struct ifaddrs *ifaddr; + + getifaddrs(&ifaddr); + + while(ifaddr) { + int family = ifaddr->ifa_addr->sa_family; + + if(family == AF_INET) { + char host[128]; + getnameinfo(ifaddr->ifa_addr, sizeof(sockaddr_in), host, sizeof(host), NULL, 0, 0); + printf("%s\n", host); + } + + ifaddr = ifaddr->ifa_next; + } + return 0; } -int main(int argc, char *argv[]) -{ - if (argc < 3) - { - printf("Use parameters: <P5 Port> <xml config file>\n"); - return 0; - } - - set_thread_priority(50); - - vnf_info vnf; - - if(read_vnf_xml(vnf, argv[2]) < 0) - { - printf("Failed to read xml file>\n"); - return 0; - } - - nfapi_vnf_config_t* config = nfapi_vnf_config_create(); - - config->vnf_ipv4 = 1; - config->vnf_p5_port = atoi(argv[1]); - config->pnf_connection_indication = &pnf_connection_indication_cb; - config->pnf_disconnect_indication = &pnf_disconnection_indication_cb; - config->pnf_param_resp = &pnf_param_resp_cb; - config->pnf_config_resp = &pnf_config_resp_cb; - config->pnf_start_resp = &pnf_start_resp_cb; - config->param_resp = ¶m_resp_cb; - config->config_resp = &config_resp_cb; - config->start_resp = &start_resp_cb; - config->vendor_ext = &vendor_ext_cb; - - - - config->trace = &vnf_sim_trace; - - config->malloc = &vnf_allocate; - config->free = &vnf_deallocate; - - config->user_data = &vnf; - - config->codec_config.unpack_vendor_extension_tlv = &vnf_sim_unpack_vendor_extension_tlv; - config->codec_config.pack_vendor_extension_tlv = &vnf_sim_pack_vendor_extension_tlv; - - config->codec_config.unpack_p4_p5_vendor_extension = &vnf_sim_unpack_p4_p5_vendor_extension; - config->codec_config.pack_p4_p5_vendor_extension = &vnf_sim_pack_p4_p5_vendor_extension; - config->allocate_p4_p5_vendor_ext = &vnf_sim_allocate_p4_p5_vendor_ext; - config->deallocate_p4_p5_vendor_ext = &vnf_sim_deallocate_p4_p5_vendor_ext; - config->codec_config.allocate = &vnf_allocate; - config->codec_config.deallocate = &vnf_deallocate; - - - printf("Calling nfapi_vnf_start\n"); - return nfapi_vnf_start(config); +int main(int argc, char *argv[]) { + if (argc < 3) { + printf("Use parameters: <P5 Port> <xml config file>\n"); + return 0; + } + + set_thread_priority(50); + vnf_info vnf; + + if(read_vnf_xml(vnf, argv[2]) < 0) { + printf("Failed to read xml file>\n"); + return 0; + } + + nfapi_vnf_config_t *config = nfapi_vnf_config_create(); + config->vnf_ipv4 = 1; + config->vnf_p5_port = atoi(argv[1]); + config->pnf_connection_indication = &pnf_connection_indication_cb; + config->pnf_disconnect_indication = &pnf_disconnection_indication_cb; + config->pnf_param_resp = &pnf_param_resp_cb; + config->pnf_config_resp = &pnf_config_resp_cb; + config->pnf_start_resp = &pnf_start_resp_cb; + config->param_resp = ¶m_resp_cb; + config->config_resp = &config_resp_cb; + config->start_resp = &start_resp_cb; + config->vendor_ext = &vendor_ext_cb; + config->trace = &vnf_sim_trace; + config->malloc = &vnf_allocate; + config->free = &vnf_deallocate; + config->user_data = &vnf; + config->codec_config.unpack_vendor_extension_tlv = &vnf_sim_unpack_vendor_extension_tlv; + config->codec_config.pack_vendor_extension_tlv = &vnf_sim_pack_vendor_extension_tlv; + config->codec_config.unpack_p4_p5_vendor_extension = &vnf_sim_unpack_p4_p5_vendor_extension; + config->codec_config.pack_p4_p5_vendor_extension = &vnf_sim_pack_p4_p5_vendor_extension; + config->allocate_p4_p5_vendor_ext = &vnf_sim_allocate_p4_p5_vendor_ext; + config->deallocate_p4_p5_vendor_ext = &vnf_sim_deallocate_p4_p5_vendor_ext; + config->codec_config.allocate = &vnf_allocate; + config->codec_config.deallocate = &vnf_deallocate; + printf("Calling nfapi_vnf_start\n"); + return nfapi_vnf_start(config); } diff --git a/openair1/PHY/CODING/ccoding_byte.c b/openair1/PHY/CODING/ccoding_byte.c index e4617d1404c6df009efab4be9d46a0e299c87d2f..576a947cff3641fffa72c01971e182e71d65eca4 100644 --- a/openair1/PHY/CODING/ccoding_byte.c +++ b/openair1/PHY/CODING/ccoding_byte.c @@ -130,7 +130,7 @@ ccodedot11_encode (unsigned int numbytes, *outPtr++ = (out>>1)&1; #ifdef DEBUG_CCODE - printf("%d: %u -> %d (%u)\n",dummy,state,out,ccodedot11_table[state]); + printf("%u: %u -> %d (%u)\n",dummy,state,out,ccodedot11_table[state]); dummy+=2; #endif //DEBUG_CCODE bit_index=(bit_index==0)?1:0; diff --git a/openair1/PHY/CODING/lte_rate_matching.c b/openair1/PHY/CODING/lte_rate_matching.c index f850d475494e2ed7eb47fbb05546527ebc83db97..548b7bfcba38bec0c8bb6aee29262872ad263c9f 100644 --- a/openair1/PHY/CODING/lte_rate_matching.c +++ b/openair1/PHY/CODING/lte_rate_matching.c @@ -236,7 +236,7 @@ void sub_block_deinterleaving_cc(uint32_t D,int8_t *d,int8_t *w) { ND = Kpi - D; #ifdef RM_DEBUG2 printf("sub_block_interleaving_cc : D = %d (%d), d %p, w %p\n",D,D*3,d,w); - printf("RCC = %d, Kpi=%d, ND=%ld\n",RCC,Kpi,ND); + printf("RCC = %d, Kpi=%d, ND=%ld\n",RCC,Kpi,(long)ND); #endif ND3 = ND*3; k=0; @@ -253,7 +253,8 @@ void sub_block_deinterleaving_cc(uint32_t D,int8_t *d,int8_t *w) { d[index3-ND3+1] = w[Kpi+k]; d[index3-ND3+2] = w[(Kpi<<1)+k]; #ifdef RM_DEBUG2 - printf("row %d, index %d k %d index3-ND3 %ld w(%d,%d,%d)\n",row,index,k,index3-ND3,w[k],w[Kpi+k],w[(Kpi<<1)+k]); + printf("row %d, index %d k %d index3-ND3 %ld w(%d,%d,%d)\n", + row,index,k,(long)(index3-ND3),w[k],w[Kpi+k],w[(Kpi<<1)+k]); #endif index3+=96; index+=32; @@ -453,7 +454,6 @@ uint32_t lte_rate_matching_turbo(uint32_t RTC, int threed =0; uint32_t nulled=0; static unsigned char *counter_buffer[MAX_NUM_DLSCH_SEGMENTS][4]; - FILE *counter_fd; char fname[512]; #endif @@ -476,7 +476,6 @@ uint32_t lte_rate_matching_turbo(uint32_t RTC, } else if(rvidx==3) { sprintf(fname, "mcs%d_rate_matching_RB_%d.txt", m, nb_rb); // sprintf(fname,"mcs0_rate_matching_RB_6.txt"); - counter_fd = fopen(fname,"w"); } #endif diff --git a/openair1/PHY/CODING/lte_segmentation.c b/openair1/PHY/CODING/lte_segmentation.c index 4dc531c58f9222b1b0460473154c640ae7fccea6..0f9f8b00e0b817d8c475105dcf9e53021da16be3 100644 --- a/openair1/PHY/CODING/lte_segmentation.c +++ b/openair1/PHY/CODING/lte_segmentation.c @@ -124,7 +124,8 @@ int lte_segmentation(unsigned char *input_buffer, Bprime,*Cplus,*Kplus,*Cminus,*Kminus); *F = ((*Cplus)*(*Kplus) + (*Cminus)*(*Kminus) - (Bprime)); #ifdef DEBUG_SEGMENTATION - printf("C %u, Cplus %u, Cminus %u, Kplus %u, Kminus %u, Bprime_bytes %u, Bprime %u, F %u\n",*C,*Cplus,*Cminus,*Kplus,*Kminus,Bprime>>3,Bprime,*F); + printf("C %u, Cplus %u, Cminus %u, Kplus %u, Kminus %u, Bprime_bytes %u, Bprime %u, F %u\n", + *C,*Cplus,*Cminus,*Kplus,*Kminus,Bprime>>3,Bprime,*F); #endif if ((input_buffer) && (output_buffers)) { diff --git a/openair1/PHY/LTE_REFSIG/lte_dl_mbsfn.c b/openair1/PHY/LTE_REFSIG/lte_dl_mbsfn.c index 54f52ef40b9d3990abbf044d48aed421cdb31f78..b0af8f6b0b0489de8b91a6bccf350e9aa7148079 100644 --- a/openair1/PHY/LTE_REFSIG/lte_dl_mbsfn.c +++ b/openair1/PHY/LTE_REFSIG/lte_dl_mbsfn.c @@ -35,30 +35,22 @@ int lte_dl_mbsfn(PHY_VARS_eNB *eNB, int32_t *output, short amp, int subframe, - unsigned char l) -{ - + unsigned char l) { unsigned int mprime,mprime_dword,mprime_qpsk_symb,m; unsigned short k=0,a; int32_t qpsk[4]; - a = (amp*ONE_OVER_SQRT2_Q15)>>15; ((short *)&qpsk[0])[0] = a; ((short *)&qpsk[0])[1] = a; - ((short *)&qpsk[1])[0] = -a; ((short *)&qpsk[1])[1] = a; ((short *)&qpsk[2])[0] = a; ((short *)&qpsk[2])[1] = -a; - ((short *)&qpsk[3])[0] = -a; ((short *)&qpsk[3])[1] = -a; - - mprime = 3*(110 - eNB->frame_parms.N_RB_DL); for (m=0; m<eNB->frame_parms.N_RB_DL*6; m++) { - if ((l==0) || (l==2)) k = m<<1; else if (l==1) @@ -69,7 +61,6 @@ int lte_dl_mbsfn(PHY_VARS_eNB *eNB, int32_t *output, } k+=eNB->frame_parms.first_carrier_offset; - mprime_dword = mprime>>4; mprime_qpsk_symb = mprime&0xf; @@ -80,22 +71,18 @@ int lte_dl_mbsfn(PHY_VARS_eNB *eNB, int32_t *output, output[k] = qpsk[(eNB->lte_gold_mbsfn_table[subframe][l][mprime_dword]>>(2*mprime_qpsk_symb))&3]; //output[k] = (lte_gold_table[eNB_offset][subframe][l][mprime_dword]>>(2*mprime_qpsk_symb))&3; - - #ifdef DEBUG_DL_MBSFN LOG_D(PHY,"subframe %d, l %d, m %d, mprime %d, mprime_dword %d, mprime_qpsk_symbol %d\n", - subframe,l,m,mprime,mprime_dword,mprime_qpsk_symb); + subframe,l,m,mprime,mprime_dword,mprime_qpsk_symb); LOG_D(PHY,"index = %d (k %d)(%x)\n",(eNB->lte_gold_mbsfn_table[subframe][l][mprime_dword]>>(2*mprime_qpsk_symb))&3,k,eNB->lte_gold_mbsfn_table[subframe][l][mprime_dword]); #endif mprime++; - #ifdef DEBUG_DL_MBSFN if (m<18) printf("subframe %d, l %d output[%d] = (%d,%d)\n",subframe,l,k,((short *)&output[k])[0],((short *)&output[k])[1]); #endif - } return(0); @@ -106,15 +93,11 @@ int lte_dl_mbsfn(PHY_VARS_eNB *eNB, int32_t *output, int lte_dl_mbsfn_rx(PHY_VARS_UE *ue, int *output, int subframe, - unsigned char l) -{ - + unsigned char l) { unsigned int mprime,mprime_dword,mprime_qpsk_symb,m; unsigned short k=0; unsigned int qpsk[4]; - // This includes complex conjugate for channel estimation - ((short *)&qpsk[0])[0] = ONE_OVER_SQRT2_Q15; ((short *)&qpsk[0])[1] = -ONE_OVER_SQRT2_Q15; ((short *)&qpsk[1])[0] = -ONE_OVER_SQRT2_Q15; @@ -123,23 +106,18 @@ int lte_dl_mbsfn_rx(PHY_VARS_UE *ue, ((short *)&qpsk[2])[1] = ONE_OVER_SQRT2_Q15; ((short *)&qpsk[3])[0] = -ONE_OVER_SQRT2_Q15; ((short *)&qpsk[3])[1] = ONE_OVER_SQRT2_Q15; - mprime = 3*(110 - ue->frame_parms.N_RB_DL); for (m=0; m<ue->frame_parms.N_RB_DL*6; m++) { - mprime_dword = mprime>>4; mprime_qpsk_symb = mprime&0xf; - // this is r_mprime from 3GPP 36-211 6.10.1.2 output[k] = qpsk[(ue->lte_gold_mbsfn_table[subframe][l][mprime_dword]>>(2*mprime_qpsk_symb))&3]; - #ifdef DEBUG_DL_MBSFN - printf("subframe %d, l %d, m %d, mprime %d, mprime_dword %d, mprime_qpsk_symbol %d\n", + printf("subframe %d, l %d, m %u, mprime %u, mprime_dword %u, mprime_qpsk_symbol %u\n", subframe,l,m,mprime, mprime_dword,mprime_qpsk_symb); printf("index = %d (k %d) (%x)\n",(ue->lte_gold_mbsfn_table[subframe][l][mprime_dword]>>(2*mprime_qpsk_symb))&3,k,ue->lte_gold_mbsfn_table[subframe][l][mprime_dword]); #endif - mprime++; #ifdef DEBUG_DL_MBSFN @@ -148,7 +126,6 @@ int lte_dl_mbsfn_rx(PHY_VARS_UE *ue, #endif k++; - } return(0); diff --git a/openair1/PHY/LTE_REFSIG/lte_ul_ref.c b/openair1/PHY/LTE_REFSIG/lte_ul_ref.c index ee7619c23c2bf9479b81a9d8e7b221a2e052e9a2..be090214f8475d28d6a81269c66860205856312d 100644 --- a/openair1/PHY/LTE_REFSIG/lte_ul_ref.c +++ b/openair1/PHY/LTE_REFSIG/lte_ul_ref.c @@ -20,9 +20,9 @@ */ #ifdef MAIN -#include <stdio.h> -#include <stdlib.h> -#include <math.h> + #include <stdio.h> + #include <stdlib.h> + #include <math.h> #endif #include "lte_refsig.h" #include "PHY/defs_eNB.h" @@ -43,8 +43,7 @@ char ref24[720] = { -1,3,1,-3,3,-1,1,3,-3,3,1,3,-3,3,1,1,-1,1,3,-3,3,-3,-1,-3,-3,3,-3,-3,-3,1,-3,-3,3,-1,1,1,1,3,1,-1,3,-3,-3,1,3,1,1,-3,3,-1,3,3,1,1,-3,3,3,3,3,1,-1,3,-1,1,1,-1,-3,-1,-1,1,3,3,-1,-3,1,1,3,-3,1,1,-3,-1,-1,1,3,1,3,1,-1,3,1,1,-3,-1,-3,-1,-1,-1,-1,-3,-3,-1,1,1,3,3,-1,3,-1,1,-1,-3,1,-1,-3,-3,1,-3,-1,-1,-3,1,1,3,-1,1,3,1,-3,1,-3,1,1,-1,-1,3,-1,-3,3,-3,-3,-3,1,1,1,1,-1,-1,3,-3,-3,3,-3,1,-1,-1,1,-1,1,1,-1,-3,-1,1,-1,3,-1,-3,-3,3,3,-1,-1,-3,-1,3,1,3,1,3,1,1,-1,3,1,-1,1,3,-3,-1,-1,1,-3,1,3,-3,1,-1,-3,3,-3,3,-1,-1,-1,-1,1,-3,-3,-3,1,-3,-3,-3,1,-3,1,1,-3,3,3,-1,-3,-1,3,-3,3,3,3,-1,1,1,-3,1,-1,1,1,-3,1,1,-1,1,-3,-3,3,-1,3,-1,-1,-3,-3,-3,-1,-3,-3,1,-1,1,3,3,-1,1,-1,3,1,3,3,-3,-3,1,3,1,-1,-3,-3,-3,3,3,-3,3,3,-1,-3,3,-1,1,-3,1,1,3,3,1,1,1,-1,-1,1,-3,3,-1,1,1,-3,3,3,-1,-3,3,-3,-1,-3,-1,3,-1,-1,-1,-1,-3,-1,3,3,1,-1,1,3,3,3,-1,1,1,-3,1,3,-1,-3,3,-3,-3,3,1,3,1,-3,3,1,3,1,1,3,3,-1,-1,-3,1,-3,-1,3,1,1,3,-1,-1,1,-3,1,3,-3,1,-1,-3,-1,3,1,3,1,-1,-3,-3,-1,-1,-3,-3,-3,-1,-1,-3,3,-1,-1,-1,-1,1,1,-3,3,1,3,3,1,-1,1,-3,1,-3,1,1,-3,-1,1,3,-1,3,3,-1,-3,1,-1,-3,3,3,3,-1,1,1,3,-1,-3,-1,3,-1,-1,-1,1,1,1,1,1,-1,3,-1,-3,1,1,3,-3,1,-3,-1,1,1,-3,-3,3,1,1,-3,1,3,3,1,-1,-3,3,-1,3,3,3,-3,1,-1,1,-1,-3,-1,1,3,-1,3,-3,-3,-1,-3,3,-3,-3,-3,-1,-1,-3,-1,-3,3,1,3,-3,-1,3,-1,1,-1,3,-3,1,-1,-3,-3,1,1,-1,1,-1,1,-1,3,1,-3,-1,1,-1,1,-1,-1,3,3,-3,-1,1,-3,-3,-1,-3,3,1,-1,-3,-1,-3,-3,3,-3,3,-3,-1,1,3,1,-3,1,3,3,-1,-3,-1,-1,-1,-1,3,3,3,1,3,3,-3,1,3,-1,3,-1,3,3,-3,3,1,-1,3,3,1,-1,3,3,-1,-3,3,-3,-1,-1,3,-1,3,-1,-1,1,1,1,1,-1,-1,-3,-1,3,1,-1,1,-1,3,-1,3,1,1,-1,-1,-3,1,1,-3,1,3,-3,1,1,-3,-3,-1,-1,-3,-1,1,3,1,1,-3,-1,-1,-3,3,-3,3,1,-3,3,-3,1,-1,1,-3,1,1,1,-1,-3,3,3,1,1,3,-1,-3,-1,-1,-1,3,1,-3,-3,-1,3,-3,-1,-3,-1,-3,-1,-1,-3,-1,-1,1,-3,-1,-1,1,-1,-3,1,1,-3,1,-3,-3,3,1,1,-1,3,-1,-1,1,1,-1,-1,-3,-1,3,-1,3,-1,1,3,1,-1,3,1,3,-3,-3,1,-1,-1,1,3 }; -void generate_ul_ref_sigs(void) -{ +void generate_ul_ref_sigs(void) { double qbar,phase; unsigned int u,v,Msc_RS,q,m,n; @@ -53,7 +52,7 @@ void generate_ul_ref_sigs(void) for (u=0; u<30; u++) { for (v=0; v<2; v++) { qbar = ref_primes[Msc_RS] * (u+1)/(double)31; - ul_ref_sigs[u][v][Msc_RS] = (int16_t*)malloc16(2*sizeof(int16_t)*dftsizes[Msc_RS]); + ul_ref_sigs[u][v][Msc_RS] = (int16_t *)malloc16(2*sizeof(int16_t)*dftsizes[Msc_RS]); if ((((int)floor(2*qbar))&1) == 0) q = (int)(floor(qbar+.5)) - v; @@ -61,7 +60,7 @@ void generate_ul_ref_sigs(void) q = (int)(floor(qbar+.5)) + v; #ifdef MAIN - printf("Msc_RS %d (%d), u %d, v %d -> q %d (qbar %f)\n",Msc_RS,dftsizes[Msc_RS],u,v,q,qbar); + printf("Msc_RS %u (%d), u %u, v %u -> q %u (qbar %f)\n",Msc_RS,dftsizes[Msc_RS],u,v,q,qbar); #endif for (n=0; n<dftsizes[Msc_RS]; n++) { @@ -89,32 +88,26 @@ void generate_ul_ref_sigs(void) // These are the sequences for RB 1 for (u=0; u<30; u++) { - ul_ref_sigs[u][0][0] = (int16_t*)malloc16(2*sizeof(int16_t)*dftsizes[0]); + ul_ref_sigs[u][0][0] = (int16_t *)malloc16(2*sizeof(int16_t)*dftsizes[0]); for (n=0; n<dftsizes[0]; n++) { ul_ref_sigs[u][0][0][n<<1] =(int16_t)(floor(32767*cos(M_PI*ref12[(u*12) + n]/4))); ul_ref_sigs[u][0][0][1+(n<<1)]=(int16_t)(floor(32767*sin(M_PI*ref12[(u*12) + n]/4))); } - } // These are the sequences for RB 2 for (u=0; u<30; u++) { - ul_ref_sigs[u][0][1] = (int16_t*)malloc16(2*sizeof(int16_t)*dftsizes[1]); + ul_ref_sigs[u][0][1] = (int16_t *)malloc16(2*sizeof(int16_t)*dftsizes[1]); for (n=0; n<dftsizes[1]; n++) { ul_ref_sigs[u][0][1][n<<1] =(int16_t)(floor(32767*cos(M_PI*ref24[(u*24) + n]/4))); ul_ref_sigs[u][0][1][1+(n<<1)]=(int16_t)(floor(32767*sin(M_PI*ref24[(u*24) + n]/4))); } - - - } - } -void generate_ul_ref_sigs_rx(void) -{ +void generate_ul_ref_sigs_rx(void) { double qbar,phase; unsigned int u,v,Msc_RS,q,m,n; @@ -123,7 +116,7 @@ void generate_ul_ref_sigs_rx(void) for (u=0; u<30; u++) { for (v=0; v<2; v++) { qbar = ref_primes[Msc_RS] * (u+1)/(double)31; - ul_ref_sigs_rx[u][v][Msc_RS] = (int16_t*)malloc16(2*sizeof(int16_t)*dftsizes[Msc_RS]); + ul_ref_sigs_rx[u][v][Msc_RS] = (int16_t *)malloc16(2*sizeof(int16_t)*dftsizes[Msc_RS]); if ((((int)floor(2*qbar))&1) == 0) q = (int)(floor(qbar+.5)) - v; @@ -131,7 +124,7 @@ void generate_ul_ref_sigs_rx(void) q = (int)(floor(qbar+.5)) + v; #ifdef MAIN - printf("Msc_RS %d (%d), u %d, v %d -> q %d (qbar %f)\n",Msc_RS,dftsizes[Msc_RS],u,v,q,qbar); + printf("Msc_RS %u (%d), u %u, v %u -> q %u (qbar %f)\n",Msc_RS,dftsizes[Msc_RS],u,v,q,qbar); #endif for (n=0; n<dftsizes[Msc_RS]; n++) { @@ -159,7 +152,7 @@ void generate_ul_ref_sigs_rx(void) // These are the sequences for RB 1 for (u=0; u<30; u++) { - ul_ref_sigs_rx[u][0][0] = (int16_t*)malloc16(2*sizeof(int16_t)*dftsizes[0]); + ul_ref_sigs_rx[u][0][0] = (int16_t *)malloc16(2*sizeof(int16_t)*dftsizes[0]); for (n=0; n<dftsizes[0]; n++) { ul_ref_sigs_rx[u][0][0][n<<1] = (int16_t)(floor(32767*cos(M_PI*ref12[(u*12) + n]/4))); @@ -169,21 +162,17 @@ void generate_ul_ref_sigs_rx(void) // These are the sequences for RB 2 for (u=0; u<30; u++) { - ul_ref_sigs_rx[u][0][1] = (int16_t*)malloc16(2*sizeof(int16_t)*dftsizes[1]); + ul_ref_sigs_rx[u][0][1] = (int16_t *)malloc16(2*sizeof(int16_t)*dftsizes[1]); for (n=0; n<dftsizes[1]; n++) { ul_ref_sigs_rx[u][0][1][n<<1] = (int16_t)(floor(32767*cos(M_PI*ref24[(u*24) + n]/4))); ul_ref_sigs_rx[u][0][1][1+(n<<1)]= (int16_t)(floor(32767*sin(M_PI*ref24[(u*24) + n]/4))); } - } - } -void free_ul_ref_sigs(void) -{ - +void free_ul_ref_sigs(void) { unsigned int u,v,Msc_RS; for (Msc_RS=0; Msc_RS<34; Msc_RS++) { @@ -204,9 +193,7 @@ void free_ul_ref_sigs(void) } #ifdef MAIN -main() -{ - +main() { generate_ul_ref_sigs(); generate_ul_ref_sigs_rx(); free_ul_ref_sigs(); diff --git a/openair1/PHY/LTE_TRANSPORT/dlsch_coding.c b/openair1/PHY/LTE_TRANSPORT/dlsch_coding.c index 3331ba50c357ffbb7c6567c2001aa0e269958e50..f8768012720716dc61e9afca92fadc9078a05dc6 100644 --- a/openair1/PHY/LTE_TRANSPORT/dlsch_coding.c +++ b/openair1/PHY/LTE_TRANSPORT/dlsch_coding.c @@ -53,71 +53,73 @@ */ #define is_not_pilot(pilots,first_pilot,re) (1) /*extern void thread_top_init(char *thread_name, - int affinity, - uint64_t runtime, - uint64_t deadline, - uint64_t period);*/ + int affinity, + uint64_t runtime, + uint64_t deadline, + uint64_t period);*/ extern WORKER_CONF_t get_thread_worker_conf(void); -void free_eNB_dlsch(LTE_eNB_DLSCH_t *dlsch) -{ +void free_eNB_dlsch(LTE_eNB_DLSCH_t *dlsch) { int i, r, aa, layer; if (dlsch) { for (layer=0; layer<4; layer++) { for (aa=0; aa<64; aa++) free16(dlsch->ue_spec_bf_weights[layer][aa], OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES*sizeof(int32_t)); - free16(dlsch->ue_spec_bf_weights[layer], 64*sizeof(int32_t*)); + + free16(dlsch->ue_spec_bf_weights[layer], 64*sizeof(int32_t *)); } + for (i=0; i<dlsch->Mdlharq; i++) { if (dlsch->harq_processes[i]) { if (dlsch->harq_processes[i]->b) { free16(dlsch->harq_processes[i]->b,MAX_DLSCH_PAYLOAD_BYTES); dlsch->harq_processes[i]->b = NULL; } + for (r=0; r<MAX_NUM_DLSCH_SEGMENTS; r++) { if (dlsch->harq_processes[i]->c[r]) { free16(dlsch->harq_processes[i]->c[r],((r==0)?8:0) + 3+768); dlsch->harq_processes[i]->c[r] = NULL; } + if (dlsch->harq_processes[i]->d[r]) { free16(dlsch->harq_processes[i]->d[r],(96+12+3+(3*6144))); dlsch->harq_processes[i]->d[r] = NULL; } - } - free16(dlsch->harq_processes[i],sizeof(LTE_DL_eNB_HARQ_t)); - dlsch->harq_processes[i] = NULL; + } + + free16(dlsch->harq_processes[i],sizeof(LTE_DL_eNB_HARQ_t)); + dlsch->harq_processes[i] = NULL; } } + free16(dlsch,sizeof(LTE_eNB_DLSCH_t)); - dlsch = NULL; } } -LTE_eNB_DLSCH_t *new_eNB_dlsch(unsigned char Kmimo,unsigned char Mdlharq,uint32_t Nsoft,unsigned char N_RB_DL, uint8_t abstraction_flag, LTE_DL_FRAME_PARMS* frame_parms) -{ - +LTE_eNB_DLSCH_t *new_eNB_dlsch(unsigned char Kmimo,unsigned char Mdlharq,uint32_t Nsoft,unsigned char N_RB_DL, uint8_t abstraction_flag, LTE_DL_FRAME_PARMS *frame_parms) { LTE_eNB_DLSCH_t *dlsch; unsigned char exit_flag = 0,i,j,r,aa,layer; int re; unsigned char bw_scaling =1; switch (N_RB_DL) { - case 6: - bw_scaling =16; - break; + case 6: + bw_scaling =16; + break; - case 25: - bw_scaling =4; - break; + case 25: + bw_scaling =4; + break; - case 50: - bw_scaling =2; - break; + case 50: + bw_scaling =2; + break; - default: - bw_scaling =1; - break; + default: + bw_scaling =1; + break; } dlsch = (LTE_eNB_DLSCH_t *)malloc16(sizeof(LTE_eNB_DLSCH_t)); @@ -128,15 +130,16 @@ LTE_eNB_DLSCH_t *new_eNB_dlsch(unsigned char Kmimo,unsigned char Mdlharq,uint32_ dlsch->Mdlharq = Mdlharq; dlsch->Mlimit = 8; dlsch->Nsoft = Nsoft; - + for (layer=0; layer<4; layer++) { - dlsch->ue_spec_bf_weights[layer] = (int32_t**)malloc16(64*sizeof(int32_t*)); - + dlsch->ue_spec_bf_weights[layer] = (int32_t **)malloc16(64*sizeof(int32_t *)); + for (aa=0; aa<64; aa++) { - dlsch->ue_spec_bf_weights[layer][aa] = (int32_t *)malloc16(OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES*sizeof(int32_t)); - for (re=0;re<OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES; re++) { - dlsch->ue_spec_bf_weights[layer][aa][re] = 0x00007fff; - } + dlsch->ue_spec_bf_weights[layer][aa] = (int32_t *)malloc16(OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES*sizeof(int32_t)); + + for (re=0; re<OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES; re++) { + dlsch->ue_spec_bf_weights[layer][aa][re] = 0x00007fff; + } } } @@ -159,7 +162,7 @@ LTE_eNB_DLSCH_t *new_eNB_dlsch(unsigned char Kmimo,unsigned char Mdlharq,uint32_ if (dlsch->harq_processes[i]) { bzero(dlsch->harq_processes[i],sizeof(LTE_DL_eNB_HARQ_t)); // dlsch->harq_processes[i]->first_tx=1; - dlsch->harq_processes[i]->b = (unsigned char*)malloc16(MAX_DLSCH_PAYLOAD_BYTES/bw_scaling); + dlsch->harq_processes[i]->b = (unsigned char *)malloc16(MAX_DLSCH_PAYLOAD_BYTES/bw_scaling); if (dlsch->harq_processes[i]->b) { bzero(dlsch->harq_processes[i]->b,MAX_DLSCH_PAYLOAD_BYTES/bw_scaling); @@ -171,14 +174,16 @@ LTE_eNB_DLSCH_t *new_eNB_dlsch(unsigned char Kmimo,unsigned char Mdlharq,uint32_ if (abstraction_flag==0) { for (r=0; r<MAX_NUM_DLSCH_SEGMENTS/bw_scaling; r++) { // account for filler in first segment and CRCs for multiple segment case - dlsch->harq_processes[i]->c[r] = (uint8_t*)malloc16(((r==0)?8:0) + 3+ 768); - dlsch->harq_processes[i]->d[r] = (uint8_t*)malloc16((96+12+3+(3*6144))); + dlsch->harq_processes[i]->c[r] = (uint8_t *)malloc16(((r==0)?8:0) + 3+ 768); + dlsch->harq_processes[i]->d[r] = (uint8_t *)malloc16((96+12+3+(3*6144))); + if (dlsch->harq_processes[i]->c[r]) { bzero(dlsch->harq_processes[i]->c[r],((r==0)?8:0) + 3+ 768); } else { printf("Can't get c\n"); exit_flag=2; } + if (dlsch->harq_processes[i]->d[r]) { bzero(dlsch->harq_processes[i]->d[r],(96+12+3+(3*6144))); } else { @@ -197,13 +202,12 @@ LTE_eNB_DLSCH_t *new_eNB_dlsch(unsigned char Kmimo,unsigned char Mdlharq,uint32_ for (i=0; i<Mdlharq; i++) { dlsch->harq_processes[i]->round=0; - for (j=0; j<96; j++) - for (r=0; r<MAX_NUM_DLSCH_SEGMENTS/bw_scaling; r++) { - // printf("dlsch->harq_processes[%d]->d[%d] %p\n",i,r,dlsch->harq_processes[i]->d[r]); - if (dlsch->harq_processes[i]->d[r]) - dlsch->harq_processes[i]->d[r][j] = LTE_NULL; - } - + for (j=0; j<96; j++) + for (r=0; r<MAX_NUM_DLSCH_SEGMENTS/bw_scaling; r++) { + // printf("dlsch->harq_processes[%d]->d[%d] %p\n",i,r,dlsch->harq_processes[i]->d[r]); + if (dlsch->harq_processes[i]->d[r]) + dlsch->harq_processes[i]->d[r][j] = LTE_NULL; + } } return(dlsch); @@ -211,16 +215,12 @@ LTE_eNB_DLSCH_t *new_eNB_dlsch(unsigned char Kmimo,unsigned char Mdlharq,uint32_ } LOG_D(PHY,"new_eNB_dlsch exit flag %d, size of %ld\n", - exit_flag, sizeof(LTE_eNB_DLSCH_t)); + exit_flag, sizeof(LTE_eNB_DLSCH_t)); free_eNB_dlsch(dlsch); return(NULL); - - } -void clean_eNb_dlsch(LTE_eNB_DLSCH_t *dlsch) -{ - +void clean_eNb_dlsch(LTE_eNB_DLSCH_t *dlsch) { unsigned char Mdlharq; unsigned char i,j,r; @@ -228,8 +228,10 @@ void clean_eNb_dlsch(LTE_eNB_DLSCH_t *dlsch) Mdlharq = dlsch->Mdlharq; dlsch->rnti = 0; #ifdef PHY_TX_THREAD + for (i=0; i<10; i++) dlsch->active[i] = 0; + #else dlsch->active = 0; #endif @@ -244,11 +246,10 @@ void clean_eNb_dlsch(LTE_eNB_DLSCH_t *dlsch) dlsch->harq_processes[i]->status = 0; dlsch->harq_processes[i]->round = 0; - for (j=0; j<96; j++) - for (r=0; r<MAX_NUM_DLSCH_SEGMENTS; r++) - if (dlsch->harq_processes[i]->d[r]) - dlsch->harq_processes[i]->d[r][j] = LTE_NULL; - + for (j=0; j<96; j++) + for (r=0; r<MAX_NUM_DLSCH_SEGMENTS; r++) + if (dlsch->harq_processes[i]->d[r]) + dlsch->harq_processes[i]->d[r][j] = LTE_NULL; } } } @@ -258,31 +259,24 @@ void clean_eNb_dlsch(LTE_eNB_DLSCH_t *dlsch) int dlsch_encoding_2threads0(te_params *tep) { - LTE_eNB_DLSCH_t *dlsch = tep->dlsch; unsigned int G = tep->G; unsigned char harq_pid = tep->harq_pid; unsigned int total_worker = tep->total_worker; unsigned int current_worker = tep->current_worker; - unsigned short nb_rb = dlsch->harq_processes[harq_pid]->nb_rb; unsigned int Kr=0,Kr_bytes,r,r_offset=0; // unsigned short m=dlsch->harq_processes[harq_pid]->mcs; - - VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_ENB_DLSCH_ENCODING_W, VCD_FUNCTION_IN); if (dlsch->harq_processes[harq_pid]->round == 0) { // this is a new packet - for (r=(dlsch->harq_processes[harq_pid]->C/(total_worker+1))*current_worker; r<(dlsch->harq_processes[harq_pid]->C/(total_worker+1))*(current_worker+1); r++) { - if (r<dlsch->harq_processes[harq_pid]->Cminus) Kr = dlsch->harq_processes[harq_pid]->Kminus; else Kr = dlsch->harq_processes[harq_pid]->Kplus; Kr_bytes = Kr>>3; - encoder(dlsch->harq_processes[harq_pid]->c[r], Kr>>3, &dlsch->harq_processes[harq_pid]->d[r][96], @@ -293,25 +287,24 @@ int dlsch_encoding_2threads0(te_params *tep) { &dlsch->harq_processes[harq_pid]->d[r][96], dlsch->harq_processes[harq_pid]->w[r]); } - } // Fill in the "e"-sequence from 36-212, V8.6 2009-03, p. 16-17 (for each "e") and concatenate the // outputs for each code segment, see Section 5.1.5 p.20 for (r=0,r_offset=0; r<(dlsch->harq_processes[harq_pid]->C/(total_worker+1))*(current_worker+1); r++) { - if(r<(dlsch->harq_processes[harq_pid]->C/(total_worker+1))*(current_worker)){ - int Nl=dlsch->harq_processes[harq_pid]->Nl; + if(r<(dlsch->harq_processes[harq_pid]->C/(total_worker+1))*(current_worker)) { + int Nl=dlsch->harq_processes[harq_pid]->Nl; int Qm=dlsch->harq_processes[harq_pid]->Qm; int C = dlsch->harq_processes[harq_pid]->C; int Gp = G/Nl/Qm; int GpmodC = Gp%C; + if (r < (C-(GpmodC))) - r_offset += Nl*Qm * (Gp/C); + r_offset += Nl*Qm * (Gp/C); else - r_offset += Nl*Qm * ((GpmodC==0?0:1) + (Gp/C)); - } - else{ + r_offset += Nl*Qm * ((GpmodC==0?0:1) + (Gp/C)); + } else { r_offset += lte_rate_matching_turbo(dlsch->harq_processes[harq_pid]->RTC[r], G, //G dlsch->harq_processes[harq_pid]->w[r], @@ -330,7 +323,6 @@ int dlsch_encoding_2threads0(te_params *tep) { } VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_ENB_DLSCH_ENCODING_W, VCD_FUNCTION_OUT); - return(0); } @@ -339,19 +331,16 @@ extern int oai_exit; void *te_thread(void *param) { cpu_set_t cpuset; CPU_ZERO(&cpuset); - thread_top_init("te_thread",1,200000,250000,500000); pthread_setname_np( pthread_self(),"te processing"); LOG_I(PHY,"thread te created id=%ld\n", syscall(__NR_gettid)); - - te_params *tep = (te_params *)param; - + //wait_sync("te_thread"); - - while (!oai_exit) { + while (!oai_exit) { if (wait_on_condition(&tep->mutex_te,&tep->cond_te,&tep->instance_cnt_te,"te thread")<0) break; + if(oai_exit) break; dlsch_encoding_2threads0(tep); @@ -363,6 +352,7 @@ void *te_thread(void *param) { exit_fun( "ERROR pthread_cond_signal" ); return(NULL); } + /*if(opp_enabled == 1 && te_wakeup_stats0->p_time>50*3000){ print_meas_now(te_wakeup_stats0,"coding_wakeup",stderr); printf("te_thread0 delay for waking up in frame_rx: %d subframe_rx: %d \n",proc->frame_rx,proc->subframe_rx); @@ -375,61 +365,56 @@ void *te_thread(void *param) { int dlsch_encoding_2threads(PHY_VARS_eNB *eNB, - unsigned char *a, - uint8_t num_pdcch_symbols, - LTE_eNB_DLSCH_t *dlsch, - int frame, - uint8_t subframe, - time_stats_t *rm_stats, - time_stats_t *te_stats, - time_stats_t *te_wait_stats, - time_stats_t *te_main_stats, - time_stats_t *te_wakeup_stats0, - time_stats_t *te_wakeup_stats1, - time_stats_t *i_stats, - int worker_num) -{ - + unsigned char *a, + uint8_t num_pdcch_symbols, + LTE_eNB_DLSCH_t *dlsch, + int frame, + uint8_t subframe, + time_stats_t *rm_stats, + time_stats_t *te_stats, + time_stats_t *te_wait_stats, + time_stats_t *te_main_stats, + time_stats_t *te_wakeup_stats0, + time_stats_t *te_wakeup_stats1, + time_stats_t *i_stats, + int worker_num) { //start_meas(&eNB->dlsch_turbo_encoding_preperation_stats); - LTE_DL_FRAME_PARMS *frame_parms = &eNB->frame_parms; L1_proc_t *proc = &eNB->proc; unsigned int G; unsigned int crc=1; - unsigned char harq_pid = dlsch->harq_ids[frame%2][subframe]; + if(harq_pid >= dlsch->Mdlharq) { LOG_E(PHY,"dlsch_encoding_2threads illegal harq_pid %d\n", harq_pid); return(-1); } + unsigned short nb_rb = dlsch->harq_processes[harq_pid]->nb_rb; unsigned int A; unsigned char mod_order; unsigned int Kr=0,Kr_bytes,r,r_offset=0; // unsigned short m=dlsch->harq_processes[harq_pid]->mcs; - VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_ENB_DLSCH_ENCODING, VCD_FUNCTION_IN); - A = dlsch->harq_processes[harq_pid]->TBS; //6228 mod_order = dlsch->harq_processes[harq_pid]->Qm; - G = get_G(frame_parms,nb_rb,dlsch->harq_processes[harq_pid]->rb_alloc,mod_order,dlsch->harq_processes[harq_pid]->Nl,num_pdcch_symbols,frame,subframe,dlsch->harq_processes[harq_pid]->mimo_mode==TM7?7:0); + G = get_G(frame_parms,nb_rb,dlsch->harq_processes[harq_pid]->rb_alloc,mod_order,dlsch->harq_processes[harq_pid]->Nl,num_pdcch_symbols,frame,subframe, + dlsch->harq_processes[harq_pid]->mimo_mode==TM7?7:0); if (dlsch->harq_processes[harq_pid]->round == 0) { // this is a new packet - start_meas(&eNB->dlsch_turbo_encoding_preperation_stats); // Add 24-bit crc (polynomial A) to payload crc = crc24a(a, A)>>8; stop_meas(&eNB->dlsch_turbo_encoding_preperation_stats); - a[A>>3] = ((uint8_t*)&crc)[2]; - a[1+(A>>3)] = ((uint8_t*)&crc)[1]; - a[2+(A>>3)] = ((uint8_t*)&crc)[0]; - + a[A>>3] = ((uint8_t *)&crc)[2]; + a[1+(A>>3)] = ((uint8_t *)&crc)[1]; + a[2+(A>>3)] = ((uint8_t *)&crc)[0]; dlsch->harq_processes[harq_pid]->B = A+24; memcpy(dlsch->harq_processes[harq_pid]->b,a,(A/8)+4); //stop_meas(&eNB->dlsch_turbo_encoding_preperation_stats); - start_meas(&eNB->dlsch_turbo_encoding_segmentation_stats); + if (lte_segmentation(dlsch->harq_processes[harq_pid]->b, dlsch->harq_processes[harq_pid]->c, dlsch->harq_processes[harq_pid]->B, @@ -442,48 +427,46 @@ int dlsch_encoding_2threads(PHY_VARS_eNB *eNB, return(-1); stop_meas(&eNB->dlsch_turbo_encoding_segmentation_stats); - start_meas(&eNB->dlsch_turbo_encoding_signal_stats); - for(int i=0;i<worker_num;i++) - { + + for(int i=0; i<worker_num; i++) { proc->tep[i].eNB = eNB; proc->tep[i].dlsch = dlsch; proc->tep[i].G = G; proc->tep[i].harq_pid = harq_pid; proc->tep[i].total_worker = worker_num; proc->tep[i].current_worker = i; - pthread_mutex_lock( &proc->tep[i].mutex_te ); + if (proc->tep[i].instance_cnt_te==0) { printf("[eNB] TE thread busy\n"); exit_fun("TE thread busy"); pthread_mutex_unlock( &proc->tep[i].mutex_te ); return(-1); } - + ++proc->tep[i].instance_cnt_te; - + // wakeup worker to do segments if (pthread_cond_signal(&proc->tep[i].cond_te) != 0) { printf("[eNB] ERROR pthread_cond_signal for te thread %d exit\n",i); exit_fun( "ERROR pthread_cond_signal" ); return (-1); } - + pthread_mutex_unlock( &proc->tep[i].mutex_te ); } stop_meas(&eNB->dlsch_turbo_encoding_signal_stats); start_meas(te_main_stats); - for (r=(dlsch->harq_processes[harq_pid]->C/(worker_num+1))*worker_num; r<dlsch->harq_processes[harq_pid]->C; r++) { + for (r=(dlsch->harq_processes[harq_pid]->C/(worker_num+1))*worker_num; r<dlsch->harq_processes[harq_pid]->C; r++) { if (r<dlsch->harq_processes[harq_pid]->Cminus) Kr = dlsch->harq_processes[harq_pid]->Kminus; else Kr = dlsch->harq_processes[harq_pid]->Kplus; Kr_bytes = Kr>>3; - start_meas(te_stats); encoder(dlsch->harq_processes[harq_pid]->c[r], Kr>>3, @@ -491,7 +474,6 @@ int dlsch_encoding_2threads(PHY_VARS_eNB *eNB, (r==0) ? dlsch->harq_processes[harq_pid]->F : 0 ); stop_meas(te_stats); - start_meas(i_stats); dlsch->harq_processes[harq_pid]->RTC[r] = sub_block_interleaving_turbo(4+(Kr_bytes*8), @@ -499,17 +481,14 @@ int dlsch_encoding_2threads(PHY_VARS_eNB *eNB, dlsch->harq_processes[harq_pid]->w[r]); stop_meas(i_stats); } - - } - else { - - for(int i=0;i<worker_num;i++) - { + } else { + for(int i=0; i<worker_num; i++) { proc->tep[i].eNB = eNB; proc->tep[i].dlsch = dlsch; proc->tep[i].G = G; proc->tep[i].total_worker = worker_num; proc->tep[i].current_worker = i; + if (pthread_cond_signal(&proc->tep[i].cond_te) != 0) { printf("[eNB] ERROR pthread_cond_signal for te thread exit\n"); exit_fun( "ERROR pthread_cond_signal" ); @@ -521,7 +500,6 @@ int dlsch_encoding_2threads(PHY_VARS_eNB *eNB, // Fill in the "e"-sequence from 36-212, V8.6 2009-03, p. 16-17 (for each "e") and concatenate the // outputs for each code segment, see Section 5.1.5 p.20 for (r=0,r_offset=0; r<dlsch->harq_processes[harq_pid]->C; r++) { - // get information for E for the segments that are handled by the worker thread if (r<(dlsch->harq_processes[harq_pid]->C/(worker_num+1))*worker_num) { int Nl=dlsch->harq_processes[harq_pid]->Nl; @@ -529,209 +507,186 @@ int dlsch_encoding_2threads(PHY_VARS_eNB *eNB, int C = dlsch->harq_processes[harq_pid]->C; int Gp = G/Nl/Qm; int GpmodC = Gp%C; + if (r < (C-(GpmodC))) - r_offset += Nl*Qm * (Gp/C); + r_offset += Nl*Qm * (Gp/C); else - r_offset += Nl*Qm * ((GpmodC==0?0:1) + (Gp/C)); - } - else { + r_offset += Nl*Qm * ((GpmodC==0?0:1) + (Gp/C)); + } else { start_meas(rm_stats); r_offset += lte_rate_matching_turbo(dlsch->harq_processes[harq_pid]->RTC[r], - G, //G - dlsch->harq_processes[harq_pid]->w[r], - dlsch->harq_processes[harq_pid]->e+r_offset, - dlsch->harq_processes[harq_pid]->C, // C - dlsch->Nsoft, // Nsoft, - dlsch->Mdlharq, - dlsch->Kmimo, - dlsch->harq_processes[harq_pid]->rvidx, - dlsch->harq_processes[harq_pid]->Qm, - dlsch->harq_processes[harq_pid]->Nl, - r, - nb_rb); - // m); // r + G, //G + dlsch->harq_processes[harq_pid]->w[r], + dlsch->harq_processes[harq_pid]->e+r_offset, + dlsch->harq_processes[harq_pid]->C, // C + dlsch->Nsoft, // Nsoft, + dlsch->Mdlharq, + dlsch->Kmimo, + dlsch->harq_processes[harq_pid]->rvidx, + dlsch->harq_processes[harq_pid]->Qm, + dlsch->harq_processes[harq_pid]->Nl, + r, + nb_rb); + // m); // r stop_meas(rm_stats); } } - stop_meas(te_main_stats); + stop_meas(te_main_stats); start_meas(te_wait_stats); - if(worker_num == 1) - { + + if(worker_num == 1) { wait_on_busy_condition(&proc->tep[0].mutex_te,&proc->tep[0].cond_te,&proc->tep[0].instance_cnt_te,"te thread 0"); - } - else if(worker_num == 2) - { + } else if(worker_num == 2) { wait_on_busy_condition(&proc->tep[0].mutex_te,&proc->tep[0].cond_te,&proc->tep[0].instance_cnt_te,"te thread 0"); wait_on_busy_condition(&proc->tep[1].mutex_te,&proc->tep[1].cond_te,&proc->tep[1].instance_cnt_te,"te thread 1"); - } - else - { + } else { wait_on_busy_condition(&proc->tep[0].mutex_te,&proc->tep[0].cond_te,&proc->tep[0].instance_cnt_te,"te thread 0"); wait_on_busy_condition(&proc->tep[1].mutex_te,&proc->tep[1].cond_te,&proc->tep[1].instance_cnt_te,"te thread 1"); wait_on_busy_condition(&proc->tep[2].mutex_te,&proc->tep[2].cond_te,&proc->tep[2].instance_cnt_te,"te thread 2"); } + stop_meas(te_wait_stats); - /*if(opp_enabled == 1 && te_wait_stats->p_time>100*3000){ print_meas_now(te_wait_stats,"coding_wait",stderr); - printf("coding delay in wait on codition in frame_rx: %d \n",proc->frame_rx); + printf("coding delay in wait on codition in frame_rx: %d \n",proc->frame_rx); }*/ - - VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_ENB_DLSCH_ENCODING, VCD_FUNCTION_OUT); - return(0); } int dlsch_encoding_all(PHY_VARS_eNB *eNB, - unsigned char *a, - uint8_t num_pdcch_symbols, - LTE_eNB_DLSCH_t *dlsch, - int frame, - uint8_t subframe, - time_stats_t *rm_stats, - time_stats_t *te_stats, - time_stats_t *te_wait_stats, - time_stats_t *te_main_stats, - time_stats_t *te_wakeup_stats0, - time_stats_t *te_wakeup_stats1, - time_stats_t *i_stats) -{ - int encoding_return = 0; - unsigned int L,C,B; - B = dlsch->harq_processes[dlsch->harq_ids[frame%2][subframe]]->B; - if(B<=6144) - { - L=0; - C=1; - } - else - { - L=24; - C = B/(6144-L); - if((6144-L)*C < B) - { - C = C+1; - } - } - - - if(get_thread_worker_conf() == WORKER_ENABLE) - { - if(C >= 8)//one main three worker - { - encoding_return = - dlsch_encoding_2threads(eNB, - a, - num_pdcch_symbols, - dlsch, - frame, - subframe, - rm_stats, - te_stats, - te_wait_stats, - te_main_stats, - te_wakeup_stats0, - te_wakeup_stats1, - i_stats, - 3); - } - else if(C >= 6)//one main two worker - { - encoding_return = - dlsch_encoding_2threads(eNB, - a, - num_pdcch_symbols, - dlsch, - frame, - subframe, - rm_stats, - te_stats, - te_wait_stats, - te_main_stats, - te_wakeup_stats0, - te_wakeup_stats1, - i_stats, - 2); - } - else if(C >= 4)//one main one worker - { - encoding_return = - dlsch_encoding_2threads(eNB, - a, - num_pdcch_symbols, - dlsch, - frame, - subframe, - rm_stats, - te_stats, - te_wait_stats, - te_main_stats, - te_wakeup_stats0, - te_wakeup_stats1, - i_stats, - 1); - } - else - { - encoding_return = - dlsch_encoding(eNB, - a, - num_pdcch_symbols, - dlsch, - frame, - subframe, - rm_stats, - te_stats, - i_stats); - } + unsigned char *a, + uint8_t num_pdcch_symbols, + LTE_eNB_DLSCH_t *dlsch, + int frame, + uint8_t subframe, + time_stats_t *rm_stats, + time_stats_t *te_stats, + time_stats_t *te_wait_stats, + time_stats_t *te_main_stats, + time_stats_t *te_wakeup_stats0, + time_stats_t *te_wakeup_stats1, + time_stats_t *i_stats) { + int encoding_return = 0; + unsigned int L,C,B; + B = dlsch->harq_processes[dlsch->harq_ids[frame%2][subframe]]->B; + + if(B<=6144) { + L=0; + C=1; + } else { + L=24; + C = B/(6144-L); + + if((6144-L)*C < B) { + C = C+1; } - else - { - encoding_return = - dlsch_encoding(eNB, - a, - num_pdcch_symbols, - dlsch, - frame, - subframe, - rm_stats, - te_stats, - i_stats); + } + + if(get_thread_worker_conf() == WORKER_ENABLE) { + if(C >= 8) { //one main three worker + encoding_return = + dlsch_encoding_2threads(eNB, + a, + num_pdcch_symbols, + dlsch, + frame, + subframe, + rm_stats, + te_stats, + te_wait_stats, + te_main_stats, + te_wakeup_stats0, + te_wakeup_stats1, + i_stats, + 3); + } else if(C >= 6) { //one main two worker + encoding_return = + dlsch_encoding_2threads(eNB, + a, + num_pdcch_symbols, + dlsch, + frame, + subframe, + rm_stats, + te_stats, + te_wait_stats, + te_main_stats, + te_wakeup_stats0, + te_wakeup_stats1, + i_stats, + 2); + } else if(C >= 4) { //one main one worker + encoding_return = + dlsch_encoding_2threads(eNB, + a, + num_pdcch_symbols, + dlsch, + frame, + subframe, + rm_stats, + te_stats, + te_wait_stats, + te_main_stats, + te_wakeup_stats0, + te_wakeup_stats1, + i_stats, + 1); + } else { + encoding_return = + dlsch_encoding(eNB, + a, + num_pdcch_symbols, + dlsch, + frame, + subframe, + rm_stats, + te_stats, + i_stats); } - return encoding_return; + } else { + encoding_return = + dlsch_encoding(eNB, + a, + num_pdcch_symbols, + dlsch, + frame, + subframe, + rm_stats, + te_stats, + i_stats); + } + + return encoding_return; } int dlsch_encoding(PHY_VARS_eNB *eNB, - unsigned char *a, + unsigned char *a, uint8_t num_pdcch_symbols, LTE_eNB_DLSCH_t *dlsch, int frame, uint8_t subframe, time_stats_t *rm_stats, time_stats_t *te_stats, - time_stats_t *i_stats) -{ - + time_stats_t *i_stats) { unsigned int G; unsigned int crc=1; - LTE_DL_FRAME_PARMS *frame_parms = &eNB->frame_parms; unsigned char harq_pid = dlsch->harq_ids[frame%2][subframe]; + if(harq_pid >= dlsch->Mdlharq) { LOG_E(PHY,"dlsch_encoding illegal harq_pid %d\n", harq_pid); return(-1); } + unsigned short nb_rb = dlsch->harq_processes[harq_pid]->nb_rb; unsigned int A; unsigned char mod_order; unsigned int Kr=0,Kr_bytes,r,r_offset=0; // unsigned short m=dlsch->harq_processes[harq_pid]->mcs; uint8_t beamforming_mode=0; - VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_ENB_DLSCH_ENCODING, VCD_FUNCTION_IN); - A = dlsch->harq_processes[harq_pid]->TBS; //6228 // printf("Encoder: A: %d\n",A); mod_order = dlsch->harq_processes[harq_pid]->Qm; @@ -742,8 +697,8 @@ int dlsch_encoding(PHY_VARS_eNB *eNB, beamforming_mode = 8; else if(dlsch->harq_processes[harq_pid]->mimo_mode == TM9_10) beamforming_mode = 9; - G = get_G(frame_parms,nb_rb,dlsch->harq_processes[harq_pid]->rb_alloc,mod_order,dlsch->harq_processes[harq_pid]->Nl,num_pdcch_symbols,frame,subframe,beamforming_mode); + G = get_G(frame_parms,nb_rb,dlsch->harq_processes[harq_pid]->rb_alloc,mod_order,dlsch->harq_processes[harq_pid]->Nl,num_pdcch_symbols,frame,subframe,beamforming_mode); // if (dlsch->harq_processes[harq_pid]->Ndi == 1) { // this is a new packet if (dlsch->harq_processes[harq_pid]->round == 0) { // this is a new packet @@ -758,14 +713,12 @@ int dlsch_encoding(PHY_VARS_eNB *eNB, printf("\n"); */ // Add 24-bit crc (polynomial A) to payload - crc = crc24a(a, A)>>8; - a[A>>3] = ((uint8_t*)&crc)[2]; - a[1+(A>>3)] = ((uint8_t*)&crc)[1]; - a[2+(A>>3)] = ((uint8_t*)&crc)[0]; + a[A>>3] = ((uint8_t *)&crc)[2]; + a[1+(A>>3)] = ((uint8_t *)&crc)[1]; + a[2+(A>>3)] = ((uint8_t *)&crc)[0]; // printf("CRC %x (A %d)\n",crc,A); - dlsch->harq_processes[harq_pid]->B = A+24; // dlsch->harq_processes[harq_pid]->b = a; memcpy(dlsch->harq_processes[harq_pid]->b,a,(A/8)+4); @@ -782,25 +735,20 @@ int dlsch_encoding(PHY_VARS_eNB *eNB, return(-1); for (r=0; r<dlsch->harq_processes[harq_pid]->C; r++) { - if (r<dlsch->harq_processes[harq_pid]->Cminus) Kr = dlsch->harq_processes[harq_pid]->Kminus; else Kr = dlsch->harq_processes[harq_pid]->Kplus; Kr_bytes = Kr>>3; - #ifdef DEBUG_DLSCH_CODING - printf("Generating Code Segment %d (%d bits)\n",r,Kr); + printf("Generating Code Segment %u (%u bits)\n",r,Kr); // generate codewords - - printf("bits_per_codeword (Kr)= %d, A %d\n",Kr,A); + printf("bits_per_codeword (Kr)= %u, A %u\n",Kr,A); printf("N_RB = %d\n",nb_rb); printf("Ncp %d\n",frame_parms->Ncp); printf("mod_order %d\n",mod_order); #endif - - start_meas(te_stats); encoder(dlsch->harq_processes[harq_pid]->c[r], Kr>>3, @@ -821,7 +769,6 @@ int dlsch_encoding(PHY_VARS_eNB *eNB, dlsch->harq_processes[harq_pid]->w[r]); stop_meas(i_stats); } - } // Fill in the "e"-sequence from 36-212, V8.6 2009-03, p. 16-17 (for each "e") and concatenate the @@ -829,16 +776,15 @@ int dlsch_encoding(PHY_VARS_eNB *eNB, for (r=0; r<dlsch->harq_processes[harq_pid]->C; r++) { #ifdef DEBUG_DLSCH_CODING - printf("Rate Matching, Code segment %d (coded bits (G) %d,unpunctured/repeated bits per code segment %d,mod_order %d, nb_rb %d)...\n", - r, - G, - Kr*3, - mod_order,nb_rb); + printf("Rate Matching, Code segment %u (coded bits (G) %u,unpunctured/repeated bits per code segment %u,mod_order %d, nb_rb %d)...\n", + r, + G, + Kr*3, + mod_order,nb_rb); #endif - start_meas(rm_stats); #ifdef DEBUG_DLSCH_CODING - printf("rvidx in encoding = %d\n", dlsch->harq_processes[harq_pid]->rvidx); + printf("rvidx in encoding = %d\n", dlsch->harq_processes[harq_pid]->rvidx); #endif r_offset += lte_rate_matching_turbo(dlsch->harq_processes[harq_pid]->RTC[r], G, //G @@ -853,7 +799,7 @@ int dlsch_encoding(PHY_VARS_eNB *eNB, dlsch->harq_processes[harq_pid]->Nl, r, nb_rb); - // m); // r + // m); // r stop_meas(rm_stats); #ifdef DEBUG_DLSCH_CODING @@ -864,7 +810,6 @@ int dlsch_encoding(PHY_VARS_eNB *eNB, } VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_ENB_DLSCH_ENCODING, VCD_FUNCTION_OUT); - return(0); } diff --git a/openair1/PHY/LTE_TRANSPORT/dlsch_modulation.c b/openair1/PHY/LTE_TRANSPORT/dlsch_modulation.c index bfdcdc1e94694f0f549e3ed885db322baef8bd2f..0b27392fd1e9a1f5b974c8f7af2853937e837ccf 100644 --- a/openair1/PHY/LTE_TRANSPORT/dlsch_modulation.c +++ b/openair1/PHY/LTE_TRANSPORT/dlsch_modulation.c @@ -1960,6 +1960,10 @@ int allocate_REs_in_RB_MCH(int32_t **txdataF, case 4: //16QAM + if (qam_table_s == NULL) { + LOG_E(PHY,"qam table pointer is NULL\n"); + return -1; + } qam16_table_offset_re = 0; qam16_table_offset_im = 0; @@ -2029,7 +2033,9 @@ int allocate_REs_in_RB_MCH(int32_t **txdataF, ((int16_t *)&txdataF[4][tti_offset])[1]=qam_table_s[qam64_table_offset_im];//(int16_t)(((int32_t)amp*qam64_table[qam64_table_offset_im])>>15); break; - + default: + LOG_E(PHY,"Invalid modulation order %i_n",mod_order); + break; } } diff --git a/openair1/PHY/LTE_TRANSPORT/pbch.c b/openair1/PHY/LTE_TRANSPORT/pbch.c index a27c6dbc9087d5b045104b16615c92c3c78b86b7..37997c94b49e97b8acd53c83673e75dc0caac716 100644 --- a/openair1/PHY/LTE_TRANSPORT/pbch.c +++ b/openair1/PHY/LTE_TRANSPORT/pbch.c @@ -308,7 +308,7 @@ int generate_pbch(LTE_eNB_PBCH *eNB_pbch, #ifdef DEBUG_PBCH if (frame_mod4==0) { - LOG_M"pbch_e.m","pbch_e", + LOG_M("pbch_e.m","pbch_e", eNB_pbch->pbch_e, pbch_E, 1, @@ -325,7 +325,7 @@ int generate_pbch(LTE_eNB_PBCH *eNB_pbch, pbch_E); #ifdef DEBUG_PBCH if (frame_mod4==0) { - LOG_M"pbch_e_s.m","pbch_e_s", + LOG_M("pbch_e_s.m","pbch_e_s", eNB_pbch->pbch_e, pbch_E, 1, diff --git a/openair1/PHY/LTE_TRANSPORT/phich_common.c b/openair1/PHY/LTE_TRANSPORT/phich_common.c index a3bc5250d5f79699e693cc77fd4855905a946801..72e9ad134ab60a1eb0b52e88140769783a8d90a9 100644 --- a/openair1/PHY/LTE_TRANSPORT/phich_common.c +++ b/openair1/PHY/LTE_TRANSPORT/phich_common.c @@ -33,105 +33,98 @@ #include "PHY/defs_eNB.h" -uint8_t get_mi(LTE_DL_FRAME_PARMS *frame_parms,uint8_t subframe) -{ - +uint8_t get_mi(LTE_DL_FRAME_PARMS *frame_parms,uint8_t subframe) { // for FDD if (frame_parms->frame_type == FDD) return 1; // for TDD switch (frame_parms->tdd_config) { + case 0: + if ((subframe==0) || (subframe==5)) + return(2); + else return(1); - case 0: - if ((subframe==0) || (subframe==5)) - return(2); - else return(1); + break; - break; + case 1: + if ((subframe==0) || (subframe==5)) + return(0); + else return(1); - case 1: - if ((subframe==0) || (subframe==5)) - return(0); - else return(1); + break; - break; + case 2: + if ((subframe==3) || (subframe==8)) + return(1); + else return(0); - case 2: - if ((subframe==3) || (subframe==8)) - return(1); - else return(0); + break; - break; + case 3: + if ((subframe==0) || (subframe==8) || (subframe==9)) + return(1); + else return(0); - case 3: - if ((subframe==0) || (subframe==8) || (subframe==9)) - return(1); - else return(0); + break; - break; + case 4: + if ((subframe==8) || (subframe==9)) + return(1); + else return(0); - case 4: - if ((subframe==8) || (subframe==9)) - return(1); - else return(0); - - break; + break; - case 5: - if (subframe==8) - return(1); - else return(0); + case 5: + if (subframe==8) + return(1); + else return(0); - break; + break; - case 6: - return(1); - break; + case 6: + return(1); + break; - default: - return(0); + default: + return(0); } } -unsigned char subframe2_ul_harq(LTE_DL_FRAME_PARMS *frame_parms,unsigned char subframe) -{ - +unsigned char subframe2_ul_harq(LTE_DL_FRAME_PARMS *frame_parms,unsigned char subframe) { if (frame_parms->frame_type == FDD) return(subframe&7); switch (frame_parms->tdd_config) { - case 3: - if ( (subframe == 8) || (subframe == 9) ) { - return(subframe-8); - } else if (subframe==0) - return(2); - else { - LOG_E(PHY,"phich.c: subframe2_ul_harq, illegal subframe %d for tdd_config %d\n", - subframe,frame_parms->tdd_config); - return(0); - } - - break; - - case 4: - if ( (subframe == 8) || (subframe == 9) ) { - return(subframe-8); - } else { - LOG_E(PHY,"phich.c: subframe2_ul_harq, illegal subframe %d for tdd_config %d\n", - subframe,frame_parms->tdd_config); - return(0); - } - - break; - + case 3: + if ( (subframe == 8) || (subframe == 9) ) { + return(subframe-8); + } else if (subframe==0) + return(2); + else { + LOG_E(PHY,"phich.c: subframe2_ul_harq, illegal subframe %d for tdd_config %d\n", + subframe,frame_parms->tdd_config); + return(0); + } + + break; + + case 4: + if ( (subframe == 8) || (subframe == 9) ) { + return(subframe-8); + } else { + LOG_E(PHY,"phich.c: subframe2_ul_harq, illegal subframe %d for tdd_config %d\n", + subframe,frame_parms->tdd_config); + return(0); + } + + break; } return(0); } -int phich_frame2_pusch_frame(LTE_DL_FRAME_PARMS *frame_parms, int frame, int subframe) -{ +int phich_frame2_pusch_frame(LTE_DL_FRAME_PARMS *frame_parms, int frame, int subframe) { int pusch_frame; if (frame_parms->frame_type == FDD) { @@ -145,127 +138,124 @@ int phich_frame2_pusch_frame(LTE_DL_FRAME_PARMS *frame_parms, int frame, int sub return pusch_frame % 1024; } -uint8_t phich_subframe2_pusch_subframe(LTE_DL_FRAME_PARMS *frame_parms,uint8_t subframe) -{ +uint8_t phich_subframe2_pusch_subframe(LTE_DL_FRAME_PARMS *frame_parms,uint8_t subframe) { uint8_t pusch_subframe = 255; if (frame_parms->frame_type == FDD) return subframe < 4 ? subframe + 6 : subframe - 4; switch (frame_parms->tdd_config) { - case 0: - if (subframe == 0) - pusch_subframe = (3); - else if (subframe == 5) { - pusch_subframe = (8); - } else if (subframe == 6) - pusch_subframe = (2); - else if (subframe == 1) - pusch_subframe = (7); - else { - AssertFatal(1==0,"phich.c: phich_subframe2_pusch_subframe, illegal subframe %d for tdd_config %d\n", - subframe,frame_parms->tdd_config); + case 0: + if (subframe == 0) + pusch_subframe = (3); + else if (subframe == 5) { + pusch_subframe = (8); + } else if (subframe == 6) + pusch_subframe = (2); + else if (subframe == 1) + pusch_subframe = (7); + else { + AssertFatal(1==0,"phich.c: phich_subframe2_pusch_subframe, illegal subframe %d for tdd_config %d\n", + subframe,frame_parms->tdd_config); + pusch_subframe = (0); + } + + break; + + case 1: + if (subframe == 6) + pusch_subframe = (2); + else if (subframe == 9) + pusch_subframe = (3); + else if (subframe == 1) + pusch_subframe = (7); + else if (subframe == 4) + pusch_subframe = (8); + else { + AssertFatal(1==0,"phich.c: phich_subframe2_pusch_subframe, illegal subframe %d for tdd_config %d\n", + subframe,frame_parms->tdd_config); + pusch_subframe = (0); + } + + break; + + case 2: + if (subframe == 8) + pusch_subframe = (2); + else if (subframe == 3) + pusch_subframe = (7); + else { + AssertFatal(1==0,"phich.c: phich_subframe2_pusch_subframe, illegal subframe %d for tdd_config %d\n", + subframe,frame_parms->tdd_config); + pusch_subframe = (0); + } + + break; + + case 3: + if ( (subframe == 8) || (subframe == 9) ) { + pusch_subframe = (subframe-6); + } else if (subframe==0) + pusch_subframe = (4); + else { + AssertFatal(1==0,"phich.c: phich_subframe2_pusch_subframe, illegal subframe %d for tdd_config %d\n", + subframe,frame_parms->tdd_config); + pusch_subframe = (0); + } + + break; + + case 4: + if ( (subframe == 8) || (subframe == 9) ) { + pusch_subframe = (subframe-6); + } else { + AssertFatal(1==0,"phich.c: phich_subframe2_pusch_subframe, illegal subframe %d for tdd_config %d\n", + subframe,frame_parms->tdd_config); + pusch_subframe = (0); + } + + break; + + case 5: + if (subframe == 8) { + pusch_subframe = (2); + } else { + AssertFatal(1==0,"phich.c: phich_subframe2_pusch_subframe, illegal subframe %d for tdd_config %d\n", + subframe,frame_parms->tdd_config); + pusch_subframe = (0); + } + + break; + + case 6: + if (subframe == 6) { + pusch_subframe = (2); + } else if (subframe == 9) { + pusch_subframe = (3); + } else if (subframe == 0) { + pusch_subframe = (4); + } else if (subframe == 1) { + pusch_subframe = (7); + } else if (subframe == 5) { + pusch_subframe = (8); + } else { + AssertFatal(1==0,"phich.c: phich_subframe2_pusch_subframe, illegal subframe %d for tdd_config %d\n", + subframe,frame_parms->tdd_config); + pusch_subframe = (0); + } + + break; + + default: + AssertFatal(1==0, "no implementation for TDD UL/DL-config = %d!\n", frame_parms->tdd_config); pusch_subframe = (0); - } - - break; - - case 1: - if (subframe == 6) - pusch_subframe = (2); - else if (subframe == 9) - pusch_subframe = (3); - else if (subframe == 1) - pusch_subframe = (7); - else if (subframe == 4) - pusch_subframe = (8); - else { - AssertFatal(1==0,"phich.c: phich_subframe2_pusch_subframe, illegal subframe %d for tdd_config %d\n", - subframe,frame_parms->tdd_config); - pusch_subframe = (0); - } - - break; - - case 2: - if (subframe == 8) - pusch_subframe = (2); - else if (subframe == 3) - pusch_subframe = (7); - else { - AssertFatal(1==0,"phich.c: phich_subframe2_pusch_subframe, illegal subframe %d for tdd_config %d\n", - subframe,frame_parms->tdd_config); - pusch_subframe = (0); - } - - break; - - case 3: - if ( (subframe == 8) || (subframe == 9) ) { - pusch_subframe = (subframe-6); - } else if (subframe==0) - pusch_subframe = (4); - else { - AssertFatal(1==0,"phich.c: phich_subframe2_pusch_subframe, illegal subframe %d for tdd_config %d\n", - subframe,frame_parms->tdd_config); - pusch_subframe = (0); - } - - break; - - case 4: - if ( (subframe == 8) || (subframe == 9) ) { - pusch_subframe = (subframe-6); - } else { - AssertFatal(1==0,"phich.c: phich_subframe2_pusch_subframe, illegal subframe %d for tdd_config %d\n", - subframe,frame_parms->tdd_config); - pusch_subframe = (0); - } - - break; - - case 5: - if (subframe == 8) { - pusch_subframe = (2); - } else { - AssertFatal(1==0,"phich.c: phich_subframe2_pusch_subframe, illegal subframe %d for tdd_config %d\n", - subframe,frame_parms->tdd_config); - pusch_subframe = (0); - } - - break; - - case 6: - if (subframe == 6) { - pusch_subframe = (2); - } else if (subframe == 9) { - pusch_subframe = (3); - } else if (subframe == 0) { - pusch_subframe = (4); - } else if (subframe == 1) { - pusch_subframe = (7); - } else if (subframe == 5) { - pusch_subframe = (8); - } else { - AssertFatal(1==0,"phich.c: phich_subframe2_pusch_subframe, illegal subframe %d for tdd_config %d\n", - subframe,frame_parms->tdd_config); - pusch_subframe = (0); - } - - break; - - default: - AssertFatal(1==0, "no implementation for TDD UL/DL-config = %d!\n", frame_parms->tdd_config); - pusch_subframe = (0); } LOG_D(PHY, "subframe %d: PUSCH subframe = %d\n", subframe, pusch_subframe); return pusch_subframe; } -int check_pcfich(LTE_DL_FRAME_PARMS *frame_parms,uint16_t reg) -{ - +int check_pcfich(LTE_DL_FRAME_PARMS *frame_parms,uint16_t reg) { if ((reg == frame_parms->pcfich_reg[0]) || (reg == frame_parms->pcfich_reg[1]) || (reg == frame_parms->pcfich_reg[2]) || @@ -275,9 +265,7 @@ int check_pcfich(LTE_DL_FRAME_PARMS *frame_parms,uint16_t reg) return(0); } -void generate_phich_reg_mapping(LTE_DL_FRAME_PARMS *frame_parms) -{ - +void generate_phich_reg_mapping(LTE_DL_FRAME_PARMS *frame_parms) { unsigned short n0 = (frame_parms->N_RB_DL * 2) - 4; // 2 REG per RB less the 4 used by PCFICH in first symbol unsigned short n1 = (frame_parms->N_RB_DL * 3); // 3 REG per RB in second and third symbol unsigned short n2 = n1; @@ -285,11 +273,9 @@ void generate_phich_reg_mapping(LTE_DL_FRAME_PARMS *frame_parms) unsigned short Ngroup_PHICH; // uint16_t *phich_reg = frame_parms->phich_reg; uint16_t *pcfich_reg = frame_parms->pcfich_reg; - // compute Ngroup_PHICH (see formula at beginning of Section 6.9 in 36-211 Ngroup_PHICH = (frame_parms->phich_config_common.phich_resource*frame_parms->N_RB_DL)/48; - if (((frame_parms->phich_config_common.phich_resource*frame_parms->N_RB_DL)%48) > 0) Ngroup_PHICH++; @@ -299,25 +285,24 @@ void generate_phich_reg_mapping(LTE_DL_FRAME_PARMS *frame_parms) } #ifdef DEBUG_PHICH - LOG_D(PHY,"Ngroup_PHICH %d (phich_config_common.phich_resource %d,phich_config_common.phich_duration %s, NidCell %d,Ncp %d, frame_type %d), smallest pcfich REG %d, n0 %d, n1 %d (first PHICH REG %d)\n", - ((frame_parms->Ncp == NORMAL)?Ngroup_PHICH:(Ngroup_PHICH>>1)), - frame_parms->phich_config_common.phich_resource, - frame_parms->phich_config_common.phich_duration==normal?"normal":"extended", - frame_parms->Nid_cell,frame_parms->Ncp,frame_parms->frame_type, - pcfich_reg[frame_parms->pcfich_first_reg_idx], - n0, - n1, - ((frame_parms->Nid_cell))%n0); + LOG_D(PHY, + "Ngroup_PHICH %d (phich_config_common.phich_resource %d,phich_config_common.phich_duration %s, NidCell %d,Ncp %d, frame_type %d), smallest pcfich REG %d, n0 %d, n1 %d (first PHICH REG %d)\n", + ((frame_parms->Ncp == NORMAL)?Ngroup_PHICH:(Ngroup_PHICH>>1)), + frame_parms->phich_config_common.phich_resource, + frame_parms->phich_config_common.phich_duration==normal?"normal":"extended", + frame_parms->Nid_cell,frame_parms->Ncp,frame_parms->frame_type, + pcfich_reg[frame_parms->pcfich_first_reg_idx], + n0, + n1, + ((frame_parms->Nid_cell))%n0); #endif // This is the algorithm from Section 6.9.3 in 36-211, it works only for normal PHICH duration for now ... - for (mprime=0; - mprime<((frame_parms->Ncp == NORMAL)?Ngroup_PHICH:(Ngroup_PHICH>>1)); + for (mprime=0; + mprime<((frame_parms->Ncp == NORMAL)?Ngroup_PHICH:(Ngroup_PHICH>>1)); mprime++) { - if (frame_parms->phich_config_common.phich_duration==normal) { // normal PHICH duration - frame_parms->phich_reg[mprime][0] = (frame_parms->Nid_cell + mprime)%n0; if (frame_parms->phich_reg[mprime][0]>=pcfich_reg[frame_parms->pcfich_first_reg_idx]) @@ -334,10 +319,9 @@ void generate_phich_reg_mapping(LTE_DL_FRAME_PARMS *frame_parms) frame_parms->phich_reg[mprime][1] = (frame_parms->Nid_cell + mprime + (n0/3))%n0; - if (frame_parms->phich_reg[mprime][1]>=pcfich_reg[frame_parms->pcfich_first_reg_idx]) frame_parms->phich_reg[mprime][1]++; - + if (frame_parms->phich_reg[mprime][1]>=pcfich_reg[(frame_parms->pcfich_first_reg_idx+1)&3]) frame_parms->phich_reg[mprime][1]++; @@ -346,10 +330,9 @@ void generate_phich_reg_mapping(LTE_DL_FRAME_PARMS *frame_parms) if (frame_parms->phich_reg[mprime][1]>=pcfich_reg[(frame_parms->pcfich_first_reg_idx+3)&3]) frame_parms->phich_reg[mprime][1]++; - frame_parms->phich_reg[mprime][2] = (frame_parms->Nid_cell + mprime + (2*n0/3))%n0; - + if (frame_parms->phich_reg[mprime][2]>=pcfich_reg[frame_parms->pcfich_first_reg_idx]) frame_parms->phich_reg[mprime][2]++; @@ -361,21 +344,19 @@ void generate_phich_reg_mapping(LTE_DL_FRAME_PARMS *frame_parms) if (frame_parms->phich_reg[mprime][2]>=pcfich_reg[(frame_parms->pcfich_first_reg_idx+3)&3]) frame_parms->phich_reg[mprime][2]++; - + #ifdef DEBUG_PHICH printf("phich_reg :%d => %d,%d,%d\n",mprime,frame_parms->phich_reg[mprime][0],frame_parms->phich_reg[mprime][1],frame_parms->phich_reg[mprime][2]); #endif } else { // extended PHICH duration frame_parms->phich_reg[mprime<<1][0] = (frame_parms->Nid_cell + mprime)%n0; frame_parms->phich_reg[1+(mprime<<1)][0] = (frame_parms->Nid_cell + mprime)%n0; - frame_parms->phich_reg[mprime<<1][1] = ((frame_parms->Nid_cell*n1/n0) + mprime + (n1/3))%n1; frame_parms->phich_reg[mprime<<1][2] = ((frame_parms->Nid_cell*n2/n0) + mprime + (2*n2/3))%n2; - frame_parms->phich_reg[1+(mprime<<1)][1] = ((frame_parms->Nid_cell*n1/n0) + mprime + (n1/3))%n1; frame_parms->phich_reg[1+(mprime<<1)][2] = ((frame_parms->Nid_cell*n2/n0) + mprime + (2*n2/3))%n2; //#ifdef DEBUG_PHICH - printf("phich_reg :%d => %d,%d,%d\n",mprime<<1,frame_parms->phich_reg[mprime<<1][0],frame_parms->phich_reg[mprime][1],frame_parms->phich_reg[mprime][2]); + printf("phich_reg :%u => %d,%d,%d\n",mprime<<1,frame_parms->phich_reg[mprime<<1][0],frame_parms->phich_reg[mprime][1],frame_parms->phich_reg[mprime][2]); printf("phich_reg :%d => %d,%d,%d\n",1+(mprime<<1),frame_parms->phich_reg[1+(mprime<<1)][0],frame_parms->phich_reg[1+(mprime<<1)][1],frame_parms->phich_reg[1+(mprime<<1)][2]); //#endif } diff --git a/openair1/PHY/LTE_TRANSPORT/prach.c b/openair1/PHY/LTE_TRANSPORT/prach.c index 59450cf08114a1329c9a572b76440f47c5071f73..2639e318c9e117a8025e9d7984b919826ac8456e 100644 --- a/openair1/PHY/LTE_TRANSPORT/prach.c +++ b/openair1/PHY/LTE_TRANSPORT/prach.c @@ -56,7 +56,7 @@ void rx_prach0(PHY_VARS_eNB *eNB, #endif ) { int i; - LTE_DL_FRAME_PARMS *fp; + LTE_DL_FRAME_PARMS *fp=NULL; lte_frame_type_t frame_type; uint16_t rootSequenceIndex; uint8_t prach_ConfigIndex; @@ -66,7 +66,7 @@ void rx_prach0(PHY_VARS_eNB *eNB, int subframe; int16_t *prachF=NULL; int16_t **rxsigF=NULL; - int nb_rx; + int nb_rx=0; int16_t *prach2; uint8_t preamble_index; uint16_t NCS,NCS2; @@ -96,13 +96,17 @@ void rx_prach0(PHY_VARS_eNB *eNB, int prach_ifft_cnt=0; #endif - if (ru) { - fp = &ru->frame_parms; - nb_rx = ru->nb_rx; - } else if (eNB) { - fp = &eNB->frame_parms; + + if(eNB) { + fp = &(eNB->frame_parms); nb_rx = fp->nb_antennas_rx; - } else AssertFatal(1==0,"rx_prach called without valid RU or eNB descriptor\n"); + } else { + fp = &(ru->frame_parms); + nb_rx = ru->nb_rx; + } + AssertFatal(fp!=NULL,"rx_prach called without valid RU or eNB descriptor\n"); + + frame_type = fp->frame_type; frame_type = fp->frame_type; #if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0)) @@ -148,29 +152,26 @@ void rx_prach0(PHY_VARS_eNB *eNB, prachF = eNB->prach_vars_br.prachF; rxsigF = eNB->prach_vars_br.rxsigF[ce_level]; - if (LOG_DEBUGFLAG(PRACH)) { - if (((ru->proc.frame_prach)&1023) < 20) LOG_I(PHY, - "PRACH (eNB) : running rx_prach (br_flag %d, ce_level %d) for frame %d subframe %d, prach_FreqOffset %d, prach_ConfigIndex %d, rootSequenceIndex %d, repetition number %d,numRepetitionsPrePreambleAttempt %d\n", - br_flag,ce_level,ru->proc.frame_prach,subframe, - fp->prach_emtc_config_common.prach_ConfigInfo.prach_FreqOffset[ce_level], - prach_ConfigIndex,rootSequenceIndex, - eNB->prach_vars_br.repetition_number[ce_level], - fp->prach_emtc_config_common.prach_ConfigInfo.prach_numRepetitionPerPreambleAttempt[ce_level]); + if (LOG_DEBUGFLAG(PRACH)){ + if (((eNB->proc.frame_prach)&1023) < 20) LOG_I(PHY,"PRACH (eNB) : running rx_prach (br_flag %d, ce_level %d) for frame %d subframe %d, prach_FreqOffset %d, prach_ConfigIndex %d, rootSequenceIndex %d, repetition number %d,numRepetitionsPrePreambleAttempt %d\n", + br_flag,ce_level,eNB->proc.frame_prach,subframe, + fp->prach_emtc_config_common.prach_ConfigInfo.prach_FreqOffset[ce_level], + prach_ConfigIndex,rootSequenceIndex, + eNB->prach_vars_br.repetition_number[ce_level], + fp->prach_emtc_config_common.prach_ConfigInfo.prach_numRepetitionPerPreambleAttempt[ce_level]); } } else #endif - { - prach_ifftp = eNB->prach_vars.prach_ifft[0]; - subframe = eNB->proc.subframe_prach; - prachF = eNB->prach_vars.prachF; - rxsigF = eNB->prach_vars.rxsigF[0]; - - if (LOG_DEBUGFLAG(PRACH)) { - if (((ru->proc.frame_prach)&1023) < 20) LOG_I(PHY,"PRACH (eNB) : running rx_prach for subframe %d, prach_FreqOffset %d, prach_ConfigIndex %d , rootSequenceIndex %d\n", subframe, - fp->prach_config_common.prach_ConfigInfo.prach_FreqOffset,prach_ConfigIndex,rootSequenceIndex); + { + prach_ifftp = eNB->prach_vars.prach_ifft[0]; + subframe = eNB->proc.subframe_prach; + prachF = eNB->prach_vars.prachF; + rxsigF = eNB->prach_vars.rxsigF[0]; + if (LOG_DEBUGFLAG(PRACH)){ + if (((eNB->proc.frame_prach)&1023) < 20) LOG_I(PHY,"PRACH (eNB) : running rx_prach for subframe %d, prach_FreqOffset %d, prach_ConfigIndex %d , rootSequenceIndex %d\n", subframe,fp->prach_config_common.prach_ConfigInfo.prach_FreqOffset,prach_ConfigIndex,rootSequenceIndex); + } } - } - } else { + } else { #if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0)) if (br_flag == 1) { @@ -421,7 +422,7 @@ void rx_prach0(PHY_VARS_eNB *eNB, } } - if ((eNB==NULL) && ru->function == NGFI_RRU_IF4p5) { + if ((eNB==NULL) && ru->function == NGFI_RRU_IF4p5) { /// **** send_IF4 of rxsigF to RAU **** /// #if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0)) if (br_flag == 1) send_IF4p5(ru, ru->proc.frame_prach, ru->proc.subframe_prach, IF4p5_PRACH+1+ce_level); @@ -445,26 +446,27 @@ void rx_prach0(PHY_VARS_eNB *eNB, uint8_t update_TA2 = 1; switch (eNB->frame_parms.N_RB_DL) { - case 6: - update_TA = 16; - break; - - case 25: - update_TA = 4; - break; - - case 50: - update_TA = 2; - break; - case 75: - update_TA = 3; - update_TA2 = 2; - break; + case 6: + update_TA = 16; + break; + + case 25: + update_TA = 4; + break; + + case 50: + update_TA = 2; + break; + + case 75: + update_TA = 3; + update_TA2 = 2; + break; + case 100: + update_TA = 1; + break; - case 100: - update_TA = 1; - break; } *max_preamble_energy=0; diff --git a/openair1/PHY/LTE_TRANSPORT/prach_common.c b/openair1/PHY/LTE_TRANSPORT/prach_common.c index 4962f6a7f917b3da8eda0af841d963c1bbd47d54..7e38d6a5907c9cb7fc25682b6b602c338f9deacb 100644 --- a/openair1/PHY/LTE_TRANSPORT/prach_common.c +++ b/openair1/PHY/LTE_TRANSPORT/prach_common.c @@ -565,17 +565,16 @@ int is_prach_subframe0(LTE_DL_FRAME_PARMS *frame_parms,uint8_t prach_ConfigIndex return(prach_mask); } -int is_prach_subframe(LTE_DL_FRAME_PARMS *frame_parms,uint32_t frame, uint8_t subframe) { +int is_prach_subframe(LTE_DL_FRAME_PARMS *frame_parms, uint32_t frame, uint8_t subframe) { uint8_t prach_ConfigIndex = frame_parms->prach_config_common.prach_ConfigInfo.prach_ConfigIndex; - int prach_mask = is_prach_subframe0(frame_parms,prach_ConfigIndex,frame,subframe); + int prach_mask = is_prach_subframe0(frame_parms, prach_ConfigIndex, frame, subframe); #if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0)) - int i; - - for (i=0;i<4;i++) { + for (int i=0; i<4; i++) { if (frame_parms->prach_emtc_config_common.prach_ConfigInfo.prach_CElevel_enable[i] == 1) - prach_mask|=(is_prach_subframe0(frame_parms,frame_parms->prach_emtc_config_common.prach_ConfigInfo.prach_ConfigIndex[i],frame,subframe)<<(i+1)); + prach_mask |= (is_prach_subframe0(frame_parms, frame_parms->prach_emtc_config_common.prach_ConfigInfo.prach_ConfigIndex[i], + frame, subframe) << (i+1)); } #endif return(prach_mask); diff --git a/openair1/PHY/LTE_TRANSPORT/ulsch_decoding.c b/openair1/PHY/LTE_TRANSPORT/ulsch_decoding.c index cc62f83f4c057f25862ab4f30e31e94dc905eaee..041679f649d1bfa541e6d6bbed15be9ffd25ff13 100644 --- a/openair1/PHY/LTE_TRANSPORT/ulsch_decoding.c +++ b/openair1/PHY/LTE_TRANSPORT/ulsch_decoding.c @@ -47,9 +47,7 @@ extern WORKER_CONF_t get_thread_worker_conf(void); -void free_eNB_ulsch(LTE_eNB_ULSCH_t *ulsch) -{ - +void free_eNB_ulsch(LTE_eNB_ULSCH_t *ulsch) { int i,r; if (ulsch) { @@ -77,33 +75,30 @@ void free_eNB_ulsch(LTE_eNB_ULSCH_t *ulsch) } free16(ulsch,sizeof(LTE_eNB_ULSCH_t)); - ulsch = NULL; } } -LTE_eNB_ULSCH_t *new_eNB_ulsch(uint8_t max_turbo_iterations,uint8_t N_RB_UL, uint8_t abstraction_flag) -{ - +LTE_eNB_ULSCH_t *new_eNB_ulsch(uint8_t max_turbo_iterations,uint8_t N_RB_UL, uint8_t abstraction_flag) { LTE_eNB_ULSCH_t *ulsch; uint8_t exit_flag = 0,i,r; unsigned char bw_scaling =1; switch (N_RB_UL) { - case 6: - bw_scaling =16; - break; + case 6: + bw_scaling =16; + break; - case 25: - bw_scaling =4; - break; + case 25: + bw_scaling =4; + break; - case 50: - bw_scaling =2; - break; + case 50: + bw_scaling =2; + break; - default: - bw_scaling =1; - break; + default: + bw_scaling =1; + break; } ulsch = (LTE_eNB_ULSCH_t *)malloc16(sizeof(LTE_eNB_ULSCH_t)); @@ -119,7 +114,7 @@ LTE_eNB_ULSCH_t *new_eNB_ulsch(uint8_t max_turbo_iterations,uint8_t N_RB_UL, uin if (ulsch->harq_processes[i]) { memset(ulsch->harq_processes[i],0,sizeof(LTE_UL_eNB_HARQ_t)); - ulsch->harq_processes[i]->b = (uint8_t*)malloc16(MAX_ULSCH_PAYLOAD_BYTES/bw_scaling); + ulsch->harq_processes[i]->b = (uint8_t *)malloc16(MAX_ULSCH_PAYLOAD_BYTES/bw_scaling); if (ulsch->harq_processes[i]->b) memset(ulsch->harq_processes[i]->b,0,MAX_ULSCH_PAYLOAD_BYTES/bw_scaling); @@ -128,13 +123,14 @@ LTE_eNB_ULSCH_t *new_eNB_ulsch(uint8_t max_turbo_iterations,uint8_t N_RB_UL, uin if (abstraction_flag==0) { for (r=0; r<MAX_NUM_ULSCH_SEGMENTS/bw_scaling; r++) { - ulsch->harq_processes[i]->c[r] = (uint8_t*)malloc16(((r==0)?8:0) + 3+768); + ulsch->harq_processes[i]->c[r] = (uint8_t *)malloc16(((r==0)?8:0) + 3+768); + if (ulsch->harq_processes[i]->c[r]) memset(ulsch->harq_processes[i]->c[r],0,((r==0)?8:0) + 3+768); else exit_flag=2; - ulsch->harq_processes[i]->d[r] = (short*)malloc16(((3*8*6144)+12+96)*sizeof(short)); + ulsch->harq_processes[i]->d[r] = (short *)malloc16(((3*8*6144)+12+96)*sizeof(short)); if (ulsch->harq_processes[i]->d[r]) memset(ulsch->harq_processes[i]->d[r],0,((3*8*6144)+12+96)*sizeof(short)); @@ -153,13 +149,10 @@ LTE_eNB_ULSCH_t *new_eNB_ulsch(uint8_t max_turbo_iterations,uint8_t N_RB_UL, uin LOG_E(PHY,"new_ue_ulsch: exit_flag = %d\n",exit_flag); free_eNB_ulsch(ulsch); - return(NULL); } -void clean_eNb_ulsch(LTE_eNB_ULSCH_t *ulsch) -{ - +void clean_eNb_ulsch(LTE_eNB_ULSCH_t *ulsch) { unsigned char i; //ulsch = (LTE_eNB_ULSCH_t *)malloc16(sizeof(LTE_eNB_ULSCH_t)); @@ -180,9 +173,11 @@ void clean_eNb_ulsch(LTE_eNB_ULSCH_t *ulsch) ulsch->harq_processes[i]->TBS = 0; ulsch->harq_processes[i]->Or1 = 0; ulsch->harq_processes[i]->Or2 = 0; + for ( int j = 0; j < 2; j++ ) { ulsch->harq_processes[i]->o_RI[j] = 0; } + ulsch->harq_processes[i]->O_ACK = 0; ulsch->harq_processes[i]->srs_active = 0; ulsch->harq_processes[i]->rvidx = 0; @@ -190,6 +185,7 @@ void clean_eNb_ulsch(LTE_eNB_ULSCH_t *ulsch) ulsch->harq_processes[i]->Nsymb_initial = 0; } } + ulsch->beta_offset_cqi_times8 = 0; ulsch->beta_offset_ri_times8 = 0; ulsch->beta_offset_harqack_times8 = 0; @@ -198,11 +194,8 @@ void clean_eNb_ulsch(LTE_eNB_ULSCH_t *ulsch) } -uint8_t extract_cqi_crc(uint8_t *cqi,uint8_t CQI_LENGTH) -{ - +uint8_t extract_cqi_crc(uint8_t *cqi,uint8_t CQI_LENGTH) { uint8_t crc; - crc = cqi[CQI_LENGTH>>3]; // printf("crc1: %x, shift %d\n",crc,CQI_LENGTH&0x7); crc = (crc<<(CQI_LENGTH&0x7)); @@ -212,22 +205,18 @@ uint8_t extract_cqi_crc(uint8_t *cqi,uint8_t CQI_LENGTH) crc |= (cqi[1+(CQI_LENGTH>>3)])>>(8-(CQI_LENGTH&0x7)); // clear crc bits //(((char *)cqi)[1+(CQI_LENGTH>>3)]) = 0; - // printf("crc : %x\n",crc); return(crc); - } -int ulsch_decoding_data_2thread0(td_params* tdp) { - +int ulsch_decoding_data_2thread0(td_params *tdp) { PHY_VARS_eNB *eNB = tdp->eNB; int UE_id = tdp->UE_id; int harq_pid = tdp->harq_pid; int llr8_flag = tdp->llr8_flag; - unsigned int r,r_offset=0,Kr,Kr_bytes; uint8_t crc_type; int offset = 0; @@ -247,11 +236,8 @@ int ulsch_decoding_data_2thread0(td_params* tdp) { else tc = decoder8; - - // go through first half of segments to get r_offset for (r=0; r<(ulsch_harq->C/2); r++) { - // Get Turbo interleaver parameters if (r<ulsch_harq->Cminus) Kr = ulsch_harq->Kminus; @@ -259,17 +245,15 @@ int ulsch_decoding_data_2thread0(td_params* tdp) { Kr = ulsch_harq->Kplus; Kr_bytes = Kr>>3; - // This is stolen from rate-matching algorithm to get the value of E - Gp = G/Nl/Q_m; GpmodC = Gp%C; - + if (r < (C-(GpmodC))) E = Nl*Q_m * (Gp/C); else E = Nl*Q_m * ((GpmodC==0?0:1) + (Gp/C)); - + r_offset += E; if (r==0) { @@ -281,8 +265,6 @@ int ulsch_decoding_data_2thread0(td_params* tdp) { // go through second half of segments for (; r<(ulsch_harq->C); r++) { - - // printf("before subblock deinterleaving c[%d] = %p\n",r,ulsch_harq->c[r]); // Get Turbo interleaver parameters if (r<ulsch_harq->Cminus) @@ -291,26 +273,23 @@ int ulsch_decoding_data_2thread0(td_params* tdp) { Kr = ulsch_harq->Kplus; Kr_bytes = Kr>>3; - memset(&dummy_w[r][0],0,3*(6144+64)*sizeof(short)); ulsch_harq->RTC[r] = generate_dummy_w(4+(Kr_bytes*8), - (uint8_t*)&dummy_w[r][0], + (uint8_t *)&dummy_w[r][0], (r==0) ? ulsch_harq->F : 0); - #ifdef DEBUG_ULSCH_DECODING - printf("Rate Matching Segment %d (coded bits (G) %d,unpunctured/repeated bits %d, Q_m %d, nb_rb %d, Nl %d)...\n", - r, G, - Kr*3, - Q_m, - nb_rb, - ulsch_harq->Nl); + printf("Rate Matching Segment %u (coded bits (G) %d,unpunctured/repeated bits %u, Q_m %d, nb_rb %d, Nl %d)...\n", + r, G, + Kr*3, + Q_m, + nb_rb, + ulsch_harq->Nl); #endif - if (lte_rate_matching_turbo_rx(ulsch_harq->RTC[r], G, ulsch_harq->w[r], - (uint8_t*) &dummy_w[r][0], + (uint8_t *) &dummy_w[r][0], ulsch_harq->e+r_offset, ulsch_harq->C, NSOFT, @@ -327,7 +306,6 @@ int ulsch_decoding_data_2thread0(td_params* tdp) { } r_offset += E; - sub_block_deinterleaving_turbo(4+Kr, &ulsch_harq->d[r][96], ulsch_harq->w[r]); @@ -336,44 +314,39 @@ int ulsch_decoding_data_2thread0(td_params* tdp) { crc_type = CRC24_A; else crc_type = CRC24_B; - - + ret = tc(&ulsch_harq->d[r][96], NULL, - ulsch_harq->c[r], + ulsch_harq->c[r], NULL, - Kr, - ulsch->max_turbo_iterations,//MAX_TURBO_ITERATIONS, - crc_type, - (r==0) ? ulsch_harq->F : 0, - &eNB->ulsch_tc_init_stats, - &eNB->ulsch_tc_alpha_stats, - &eNB->ulsch_tc_beta_stats, - &eNB->ulsch_tc_gamma_stats, - &eNB->ulsch_tc_ext_stats, - &eNB->ulsch_tc_intl1_stats, - &eNB->ulsch_tc_intl2_stats); - + Kr, + ulsch->max_turbo_iterations,//MAX_TURBO_ITERATIONS, + crc_type, + (r==0) ? ulsch_harq->F : 0, + &eNB->ulsch_tc_init_stats, + &eNB->ulsch_tc_alpha_stats, + &eNB->ulsch_tc_beta_stats, + &eNB->ulsch_tc_gamma_stats, + &eNB->ulsch_tc_ext_stats, + &eNB->ulsch_tc_intl1_stats, + &eNB->ulsch_tc_intl2_stats); + // Reassembly of Transport block here if (ret != (1+ulsch->max_turbo_iterations)) { if (r<ulsch_harq->Cminus) - Kr = ulsch_harq->Kminus; + Kr = ulsch_harq->Kminus; else - Kr = ulsch_harq->Kplus; - + Kr = ulsch_harq->Kplus; + Kr_bytes = Kr>>3; - memcpy(ulsch_harq->b+offset, - ulsch_harq->c[r], - Kr_bytes - ((ulsch_harq->C>1)?3:0)); + ulsch_harq->c[r], + Kr_bytes - ((ulsch_harq->C>1)?3:0)); offset += (Kr_bytes- ((ulsch_harq->C>1)?3:0)); - - } else { break; } - } return(ret); @@ -381,22 +354,21 @@ int ulsch_decoding_data_2thread0(td_params* tdp) { extern int oai_exit; void *td_thread(void *param) { - PHY_VARS_eNB *eNB = ((td_params*)param)->eNB; + PHY_VARS_eNB *eNB = ((td_params *)param)->eNB; L1_proc_t *proc = &eNB->proc; cpu_set_t cpuset; CPU_ZERO(&cpuset); - thread_top_init("td_thread",1,200000,250000,500000); pthread_setname_np( pthread_self(),"td processing"); LOG_I(PHY,"thread td created id=%ld\n", syscall(__NR_gettid)); //wait_sync("td_thread"); while (!oai_exit) { + if (wait_on_condition(&proc->mutex_td,&proc->cond_td,&proc->instance_cnt_td,"td thread")<0) break; - if (wait_on_condition(&proc->mutex_td,&proc->cond_td,&proc->instance_cnt_td,"td thread")<0) break; if(oai_exit) break; - ((td_params*)param)->ret = ulsch_decoding_data_2thread0((td_params*)param); + ((td_params *)param)->ret = ulsch_decoding_data_2thread0((td_params *)param); if (release_thread(&proc->mutex_td,&proc->instance_cnt_td,"td thread")<0) break; @@ -411,7 +383,6 @@ void *td_thread(void *param) { } int ulsch_decoding_data_2thread(PHY_VARS_eNB *eNB,int UE_id,int harq_pid,int llr8_flag) { - L1_proc_t *proc = &eNB->proc; unsigned int r,r_offset=0,Kr,Kr_bytes; uint8_t crc_type; @@ -420,18 +391,14 @@ int ulsch_decoding_data_2thread(PHY_VARS_eNB *eNB,int UE_id,int harq_pid,int llr int16_t dummy_w[MAX_NUM_ULSCH_SEGMENTS][3*(6144+64)]; LTE_eNB_ULSCH_t *ulsch = eNB->ulsch[UE_id]; LTE_UL_eNB_HARQ_t *ulsch_harq = ulsch->harq_processes[harq_pid]; - int G = ulsch_harq->G; unsigned int E; int Cby2; decoder_if_t *tc; - struct timespec wait; - wait.tv_sec=0; wait.tv_nsec=5000000L; - if (llr8_flag == 0) tc = decoder16; else @@ -443,23 +410,21 @@ int ulsch_decoding_data_2thread(PHY_VARS_eNB *eNB,int UE_id,int harq_pid,int llr exit_fun( "error locking mutex_fep" ); return -1; } - + if (proc->instance_cnt_td==0) { printf("[eNB] TD thread busy\n"); exit_fun("TD thread busy"); pthread_mutex_unlock( &proc->mutex_td ); return -1; } - + ++proc->instance_cnt_td; - proc->tdp.eNB = eNB; proc->tdp.UE_id = UE_id; proc->tdp.harq_pid = harq_pid; proc->tdp.llr8_flag = llr8_flag; - - - // wakeup worker to do second half segments + + // wakeup worker to do second half segments if (pthread_cond_signal(&proc->cond_td) != 0) { printf("[eNB] ERROR pthread_cond_signal for td thread exit\n"); exit_fun( "ERROR pthread_cond_signal" ); @@ -468,14 +433,12 @@ int ulsch_decoding_data_2thread(PHY_VARS_eNB *eNB,int UE_id,int harq_pid,int llr pthread_mutex_unlock( &proc->mutex_td ); Cby2 = ulsch_harq->C/2; - } - else { + } else { Cby2 = 1; } // go through first half of segments in main thread for (r=0; r<Cby2; r++) { - // printf("before subblock deinterleaving c[%d] = %p\n",r,ulsch_harq->c[r]); // Get Turbo interleaver parameters if (r<ulsch_harq->Cminus) @@ -484,27 +447,24 @@ int ulsch_decoding_data_2thread(PHY_VARS_eNB *eNB,int UE_id,int harq_pid,int llr Kr = ulsch_harq->Kplus; Kr_bytes = Kr>>3; - memset(&dummy_w[r][0],0,3*(6144+64)*sizeof(short)); ulsch_harq->RTC[r] = generate_dummy_w(4+(Kr_bytes*8), - (uint8_t*)&dummy_w[r][0], + (uint8_t *)&dummy_w[r][0], (r==0) ? ulsch_harq->F : 0); - #ifdef DEBUG_ULSCH_DECODING - printf("Rate Matching Segment %d (coded bits (G) %d,unpunctured/repeated bits %d, Q_m %d, nb_rb %d, Nl %d)...\n", - r, G, - Kr*3, - Q_m, - nb_rb, - ulsch_harq->Nl); + printf("Rate Matching Segment %u (coded bits (G) %d,unpunctured/repeated bits %u, Q_m %d, nb_rb %d, Nl %d)...\n", + r, G, + Kr*3, + Q_m, + nb_rb, + ulsch_harq->Nl); #endif - start_meas(&eNB->ulsch_rate_unmatching_stats); if (lte_rate_matching_turbo_rx(ulsch_harq->RTC[r], G, ulsch_harq->w[r], - (uint8_t*) &dummy_w[r][0], + (uint8_t *) &dummy_w[r][0], ulsch_harq->e+r_offset, ulsch_harq->C, NSOFT, @@ -522,7 +482,6 @@ int ulsch_decoding_data_2thread(PHY_VARS_eNB *eNB,int UE_id,int harq_pid,int llr stop_meas(&eNB->ulsch_rate_unmatching_stats); r_offset += E; - start_meas(&eNB->ulsch_deinterleaving_stats); sub_block_deinterleaving_turbo(4+Kr, &ulsch_harq->d[r][96], @@ -535,61 +494,57 @@ int ulsch_decoding_data_2thread(PHY_VARS_eNB *eNB,int UE_id,int harq_pid,int llr crc_type = CRC24_B; start_meas(&eNB->ulsch_turbo_decoding_stats); - ret = tc(&ulsch_harq->d[r][96], NULL, - ulsch_harq->c[r], + ulsch_harq->c[r], NULL, - Kr, - ulsch->max_turbo_iterations,//MAX_TURBO_ITERATIONS, - crc_type, - (r==0) ? ulsch_harq->F : 0, - &eNB->ulsch_tc_init_stats, - &eNB->ulsch_tc_alpha_stats, - &eNB->ulsch_tc_beta_stats, - &eNB->ulsch_tc_gamma_stats, - &eNB->ulsch_tc_ext_stats, - &eNB->ulsch_tc_intl1_stats, - &eNB->ulsch_tc_intl2_stats); - - // Reassembly of Transport block here + Kr, + ulsch->max_turbo_iterations,//MAX_TURBO_ITERATIONS, + crc_type, + (r==0) ? ulsch_harq->F : 0, + &eNB->ulsch_tc_init_stats, + &eNB->ulsch_tc_alpha_stats, + &eNB->ulsch_tc_beta_stats, + &eNB->ulsch_tc_gamma_stats, + &eNB->ulsch_tc_ext_stats, + &eNB->ulsch_tc_intl1_stats, + &eNB->ulsch_tc_intl2_stats); + + // Reassembly of Transport block here if (ret != (1+ulsch->max_turbo_iterations)) { if (r<ulsch_harq->Cminus) - Kr = ulsch_harq->Kminus; + Kr = ulsch_harq->Kminus; else - Kr = ulsch_harq->Kplus; - + Kr = ulsch_harq->Kplus; + Kr_bytes = Kr>>3; - + if (r==0) { - memcpy(ulsch_harq->b, - &ulsch_harq->c[0][(ulsch_harq->F>>3)], - Kr_bytes - (ulsch_harq->F>>3) - ((ulsch_harq->C>1)?3:0)); - offset = Kr_bytes - (ulsch_harq->F>>3) - ((ulsch_harq->C>1)?3:0); + memcpy(ulsch_harq->b, + &ulsch_harq->c[0][(ulsch_harq->F>>3)], + Kr_bytes - (ulsch_harq->F>>3) - ((ulsch_harq->C>1)?3:0)); + offset = Kr_bytes - (ulsch_harq->F>>3) - ((ulsch_harq->C>1)?3:0); } else { - memcpy(ulsch_harq->b+offset, - ulsch_harq->c[r], - Kr_bytes - ((ulsch_harq->C>1)?3:0)); - offset += (Kr_bytes- ((ulsch_harq->C>1)?3:0)); + memcpy(ulsch_harq->b+offset, + ulsch_harq->c[r], + Kr_bytes - ((ulsch_harq->C>1)?3:0)); + offset += (Kr_bytes- ((ulsch_harq->C>1)?3:0)); } - } else { break; } - stop_meas(&eNB->ulsch_turbo_decoding_stats); - //printf("/////////////////////////////////////////**************************loop for %d time in ulsch_decoding main\n",r); - } - // wait for worker to finish - - wait_on_busy_condition(&proc->mutex_td,&proc->cond_td,&proc->instance_cnt_td,"td thread"); + stop_meas(&eNB->ulsch_turbo_decoding_stats); + //printf("/////////////////////////////////////////**************************loop for %d time in ulsch_decoding main\n",r); + } + // wait for worker to finish + wait_on_busy_condition(&proc->mutex_td,&proc->cond_td,&proc->instance_cnt_td,"td thread"); return( (ret>proc->tdp.ret) ? ret : proc->tdp.ret ); } int ulsch_decoding_data(PHY_VARS_eNB *eNB,int UE_id,int harq_pid,int llr8_flag) { - unsigned int r,r_offset=0,Kr,Kr_bytes; uint8_t crc_type; int offset = 0; @@ -597,7 +552,6 @@ int ulsch_decoding_data(PHY_VARS_eNB *eNB,int UE_id,int harq_pid,int llr8_flag) int16_t dummy_w[MAX_NUM_ULSCH_SEGMENTS][3*(6144+64)]; LTE_eNB_ULSCH_t *ulsch = eNB->ulsch[UE_id]; LTE_UL_eNB_HARQ_t *ulsch_harq = ulsch->harq_processes[harq_pid]; - int G = ulsch_harq->G; unsigned int E; decoder_if_t *tc; @@ -607,9 +561,7 @@ int ulsch_decoding_data(PHY_VARS_eNB *eNB,int UE_id,int harq_pid,int llr8_flag) else tc = *decoder8; - for (r=0; r<ulsch_harq->C; r++) { - // printf("before subblock deinterleaving c[%d] = %p\n",r,ulsch_harq->c[r]); // Get Turbo interleaver parameters if (r<ulsch_harq->Cminus) @@ -618,27 +570,24 @@ int ulsch_decoding_data(PHY_VARS_eNB *eNB,int UE_id,int harq_pid,int llr8_flag) Kr = ulsch_harq->Kplus; Kr_bytes = Kr>>3; - memset(&dummy_w[r][0],0,3*(6144+64)*sizeof(short)); ulsch_harq->RTC[r] = generate_dummy_w(4+(Kr_bytes*8), - (uint8_t*)&dummy_w[r][0], + (uint8_t *)&dummy_w[r][0], (r==0) ? ulsch_harq->F : 0); - #ifdef DEBUG_ULSCH_DECODING - printf("Rate Matching Segment %d (coded bits (G) %d,unpunctured/repeated bits %d, Q_m %d, nb_rb %d, Nl %d)...\n", - r, G, - Kr*3, - Q_m, - nb_rb, - ulsch_harq->Nl); + printf("Rate Matching Segment %u (coded bits (G) %d,unpunctured/repeated bits %u, Q_m %d, nb_rb %d, Nl %d)...\n", + r, G, + Kr*3, + Q_m, + nb_rb, + ulsch_harq->Nl); #endif - start_meas(&eNB->ulsch_rate_unmatching_stats); if (lte_rate_matching_turbo_rx(ulsch_harq->RTC[r], G, ulsch_harq->w[r], - (uint8_t*) &dummy_w[r][0], + (uint8_t *) &dummy_w[r][0], ulsch_harq->e+r_offset, ulsch_harq->C, NSOFT, @@ -656,7 +605,6 @@ int ulsch_decoding_data(PHY_VARS_eNB *eNB,int UE_id,int harq_pid,int llr8_flag) stop_meas(&eNB->ulsch_rate_unmatching_stats); r_offset += E; - start_meas(&eNB->ulsch_deinterleaving_stats); sub_block_deinterleaving_turbo(4+Kr, &ulsch_harq->d[r][96], @@ -667,61 +615,55 @@ int ulsch_decoding_data(PHY_VARS_eNB *eNB,int UE_id,int harq_pid,int llr8_flag) crc_type = CRC24_A; else crc_type = CRC24_B; - - + start_meas(&eNB->ulsch_turbo_decoding_stats); - ret = tc(&ulsch_harq->d[r][96], NULL, - ulsch_harq->c[r], + ulsch_harq->c[r], NULL, - Kr, - ulsch->max_turbo_iterations,//MAX_TURBO_ITERATIONS, - crc_type, - (r==0) ? ulsch_harq->F : 0, - &eNB->ulsch_tc_init_stats, - &eNB->ulsch_tc_alpha_stats, - &eNB->ulsch_tc_beta_stats, - &eNB->ulsch_tc_gamma_stats, - &eNB->ulsch_tc_ext_stats, - &eNB->ulsch_tc_intl1_stats, - &eNB->ulsch_tc_intl2_stats); - + Kr, + ulsch->max_turbo_iterations,//MAX_TURBO_ITERATIONS, + crc_type, + (r==0) ? ulsch_harq->F : 0, + &eNB->ulsch_tc_init_stats, + &eNB->ulsch_tc_alpha_stats, + &eNB->ulsch_tc_beta_stats, + &eNB->ulsch_tc_gamma_stats, + &eNB->ulsch_tc_ext_stats, + &eNB->ulsch_tc_intl1_stats, + &eNB->ulsch_tc_intl2_stats); stop_meas(&eNB->ulsch_turbo_decoding_stats); - - // Reassembly of Transport block here + + // Reassembly of Transport block here if (ret != (1+ulsch->max_turbo_iterations)) { if (r<ulsch_harq->Cminus) - Kr = ulsch_harq->Kminus; + Kr = ulsch_harq->Kminus; else - Kr = ulsch_harq->Kplus; - + Kr = ulsch_harq->Kplus; + Kr_bytes = Kr>>3; - + if (r==0) { - memcpy(ulsch_harq->b, - &ulsch_harq->c[0][(ulsch_harq->F>>3)], - Kr_bytes - (ulsch_harq->F>>3) - ((ulsch_harq->C>1)?3:0)); - offset = Kr_bytes - (ulsch_harq->F>>3) - ((ulsch_harq->C>1)?3:0); + memcpy(ulsch_harq->b, + &ulsch_harq->c[0][(ulsch_harq->F>>3)], + Kr_bytes - (ulsch_harq->F>>3) - ((ulsch_harq->C>1)?3:0)); + offset = Kr_bytes - (ulsch_harq->F>>3) - ((ulsch_harq->C>1)?3:0); } else { - memcpy(ulsch_harq->b+offset, - ulsch_harq->c[r], - Kr_bytes - ((ulsch_harq->C>1)?3:0)); - offset += (Kr_bytes- ((ulsch_harq->C>1)?3:0)); + memcpy(ulsch_harq->b+offset, + ulsch_harq->c[r], + Kr_bytes - ((ulsch_harq->C>1)?3:0)); + offset += (Kr_bytes- ((ulsch_harq->C>1)?3:0)); } - } else { break; } - } return(ret); } -int ulsch_decoding_data_all(PHY_VARS_eNB *eNB,int UE_id,int harq_pid,int llr8_flag) -{ +int ulsch_decoding_data_all(PHY_VARS_eNB *eNB,int UE_id,int harq_pid,int llr8_flag) { int ret = 0; /*if(get_thread_worker_conf() == WORKER_ENABLE) { @@ -735,8 +677,7 @@ int ulsch_decoding_data_all(PHY_VARS_eNB *eNB,int UE_id,int harq_pid,int llr8_fl } static inline unsigned int lte_gold_unscram(unsigned int *x1, unsigned int *x2, unsigned char reset) __attribute__((always_inline)); -static inline unsigned int lte_gold_unscram(unsigned int *x1, unsigned int *x2, unsigned char reset) -{ +static inline unsigned int lte_gold_unscram(unsigned int *x1, unsigned int *x2, unsigned char reset) { int n; if (reset) { @@ -759,17 +700,13 @@ static inline unsigned int lte_gold_unscram(unsigned int *x1, unsigned int *x2, *x2 = *x2 ^ (*x2<<31) ^ (*x2<<30) ^ (*x2<<29) ^ (*x2<<28); return(*x1^*x2); // printf("n=%d : c %x\n",n,x1^x2); - } - + unsigned int ulsch_decoding(PHY_VARS_eNB *eNB,L1_rxtx_proc_t *proc, uint8_t UE_id, uint8_t control_only_flag, uint8_t Nbundled, - uint8_t llr8_flag) -{ - - + uint8_t llr8_flag) { int16_t *ulsch_llr = eNB->pusch_vars[UE_id]->llr; LTE_DL_FRAME_PARMS *frame_parms = &eNB->frame_parms; LTE_eNB_ULSCH_t *ulsch = eNB->ulsch[UE_id]; @@ -780,10 +717,8 @@ unsigned int ulsch_decoding(PHY_VARS_eNB *eNB,L1_rxtx_proc_t *proc, unsigned int i,i2,q,j,j2; int iprime; unsigned int ret=0; - // uint8_t dummy_channel_output[(3*8*block_length)+12]; int r,Kr; - uint8_t *columnset; unsigned int sumKr=0; unsigned int Qprime,L,G,Q_CQI,Q_RI,H,Hprime,Hpp,Cmux,Rmux_prime,O_RCC; @@ -799,13 +734,10 @@ unsigned int ulsch_decoding(PHY_VARS_eNB *eNB,L1_rxtx_proc_t *proc, // uint8_t ytag2[6*14*1200],*ytag2_ptr; int16_t cseq[6*14*1200] __attribute__((aligned(32))); int off; - int frame = proc->frame_rx; int subframe = proc->subframe_rx; LTE_UL_eNB_HARQ_t *ulsch_harq; - - #if (RRC_VERSION >= MAKE_VERSION(14, 0, 0)) if (ulsch->ue_type>0) harq_pid = 0; else @@ -819,56 +751,45 @@ unsigned int ulsch_decoding(PHY_VARS_eNB *eNB,L1_rxtx_proc_t *proc, // x1 is set in lte_gold_generic x2 = ((uint32_t)ulsch->rnti<<14) + ((uint32_t)subframe<<9) + frame_parms->Nid_cell; //this is c_init in 36.211 Sec 6.3.1 ulsch_harq = ulsch->harq_processes[harq_pid]; - AssertFatal(harq_pid!=255, "FATAL ERROR: illegal harq_pid, returning\n"); - AssertFatal(ulsch_harq->Nsymb_pusch != 0, "FATAL ERROR: harq_pid %d, Nsymb 0!\n",harq_pid); - - nb_rb = ulsch_harq->nb_rb; - A = ulsch_harq->TBS; - - Q_m = ulsch_harq->Qm; G = nb_rb * (12 * Q_m) * ulsch_harq->Nsymb_pusch; - - //#ifdef DEBUG_ULSCH_DECODING LOG_D(PHY,"[PUSCH %d] Frame %d, Subframe %d: ulsch_decoding (Nid_cell %d, rnti %x, x2 %x): A %d, round %d, RV %d, O_r1 %d, O_RI %d, O_ACK %d, G %d, Q_m %d Nsymb_pusch %d nb_rb %d\n", - harq_pid, - proc->frame_rx,subframe, - frame_parms->Nid_cell,ulsch->rnti,x2, - A, - ulsch_harq->round, - ulsch_harq->rvidx, - ulsch_harq->Or1, - ulsch_harq->O_RI, - ulsch_harq->O_ACK, - G, + harq_pid, + proc->frame_rx,subframe, + frame_parms->Nid_cell,ulsch->rnti,x2, + A, + ulsch_harq->round, + ulsch_harq->rvidx, + ulsch_harq->Or1, + ulsch_harq->O_RI, + ulsch_harq->O_ACK, + G, ulsch_harq->Qm, ulsch_harq->Nsymb_pusch, nb_rb); - //#endif //if (ulsch_harq->round == 0) { // delete for RB shortage pattern - // This is a new packet, so compute quantities regarding segmentation - ulsch_harq->B = A+24; - lte_segmentation(NULL, - NULL, - ulsch_harq->B, - &ulsch_harq->C, - &ulsch_harq->Cplus, - &ulsch_harq->Cminus, - &ulsch_harq->Kplus, - &ulsch_harq->Kminus, - &ulsch_harq->F); - // CLEAR LLR's HERE for first packet in process + // This is a new packet, so compute quantities regarding segmentation + ulsch_harq->B = A+24; + lte_segmentation(NULL, + NULL, + ulsch_harq->B, + &ulsch_harq->C, + &ulsch_harq->Cplus, + &ulsch_harq->Cminus, + &ulsch_harq->Kplus, + &ulsch_harq->Kminus, + &ulsch_harq->F); + // CLEAR LLR's HERE for first packet in process //} // printf("after segmentation c[%d] = %p\n",0,ulsch_harq->c[0]); - sumKr = 0; for (r=0; r<ulsch_harq->C; r++) { @@ -881,17 +802,15 @@ unsigned int ulsch_decoding(PHY_VARS_eNB *eNB,L1_rxtx_proc_t *proc, } AssertFatal(sumKr>0, - "[eNB] ulsch_decoding.c: FATAL sumKr is 0! (Nid_cell %d, rnti %x, x2 %x): harq_pid %d round %d, RV %d, O_RI %d, O_ACK %d, G %d, subframe %d\n", - frame_parms->Nid_cell,ulsch->rnti,x2, - harq_pid, - ulsch_harq->round, - ulsch_harq->rvidx, - ulsch_harq->O_RI, - ulsch_harq->O_ACK, - G, - subframe); - - + "[eNB] ulsch_decoding.c: FATAL sumKr is 0! (Nid_cell %d, rnti %x, x2 %x): harq_pid %d round %d, RV %d, O_RI %d, O_ACK %d, G %d, subframe %d\n", + frame_parms->Nid_cell,ulsch->rnti,x2, + harq_pid, + ulsch_harq->round, + ulsch_harq->rvidx, + ulsch_harq->O_RI, + ulsch_harq->O_ACK, + G, + subframe); // Compute Q_ri Qprime = ulsch_harq->O_RI*ulsch_harq->Msc_initial*ulsch_harq->Nsymb_initial * ulsch->beta_offset_ri_times8; @@ -907,10 +826,7 @@ unsigned int ulsch_decoding(PHY_VARS_eNB *eNB,L1_rxtx_proc_t *proc, Q_RI = Q_m*Qprime; Qprime_RI = Qprime; - - // Compute Q_ack - Qprime = ulsch_harq->O_ACK*ulsch_harq->Msc_initial*ulsch_harq->Nsymb_initial * ulsch->beta_offset_harqack_times8; if (Qprime > 0) { @@ -926,8 +842,8 @@ unsigned int ulsch_decoding(PHY_VARS_eNB *eNB,L1_rxtx_proc_t *proc, // Q_ACK = Qprime * Q_m; Qprime_ACK = Qprime; #ifdef DEBUG_ULSCH_DECODING - printf("ulsch_decoding.c: Qprime_ACK %d, Msc_initial %d, Nsymb_initial %d, sumKr %d\n", - Qprime_ACK,ulsch_harq->Msc_initial,ulsch_harq->Nsymb_initial,sumKr); + printf("ulsch_decoding.c: Qprime_ACK %u, Msc_initial %d, Nsymb_initial %d, sumKr %u\n", + Qprime_ACK,ulsch_harq->Msc_initial,ulsch_harq->Nsymb_initial,sumKr); #endif // Compute Q_cqi @@ -950,43 +866,27 @@ unsigned int ulsch_decoding(PHY_VARS_eNB *eNB,L1_rxtx_proc_t *proc, } G = nb_rb * (12 * Q_m) * (ulsch_harq->Nsymb_pusch); - - - Q_CQI = Q_m * Qprime; #ifdef DEBUG_ULSCH_DECODING - printf("ulsch_decoding: G %d, Q_RI %d, Q_CQI %d (L %d, Or1 %d) O_ACK %d\n",G,Q_RI,Q_CQI,L,ulsch_harq->Or1,ulsch_harq->O_ACK); + printf("ulsch_decoding: G %u, Q_RI %u, Q_CQI %u (L %u, Or1 %d) O_ACK %d\n",G,Q_RI,Q_CQI,L,ulsch_harq->Or1,ulsch_harq->O_ACK); #endif - G = G - Q_RI - Q_CQI; ulsch_harq->G = G; - AssertFatal((int)G > 0, "FATAL: ulsch_decoding.c G < 0 (%d) : Q_RI %d, Q_CQI %d\n",G,Q_RI,Q_CQI); - H = G + Q_CQI; Hprime = H/Q_m; - - // Demultiplexing/Deinterleaving of PUSCH/ACK/RI/CQI start_meas(&eNB->ulsch_demultiplexing_stats); Hpp = Hprime + Qprime_RI; - Cmux = ulsch_harq->Nsymb_pusch; Rmux_prime = Hpp/Cmux; - // Clear "tag" interleaving matrix to allow for CQI/DATA identification memset(ytag,0,Cmux*Rmux_prime); - - - i=0; memset(y,LTE_NULL,Q_m*Hpp); - // read in buffer and unscramble llrs for everything but placeholder bits // llrs stored per symbol correspond to columns of interleaving matrix - - s = lte_gold_unscram(&x1, &x2, 1); i2=0; @@ -998,26 +898,25 @@ unsigned int ulsch_decoding(PHY_VARS_eNB *eNB,L1_rxtx_proc_t *proc, */ #if defined(__x86_64__) || defined(__i386__) #ifndef __AVX2__ - ((__m128i*)cseq)[i2++] = ((__m128i*)unscrambling_lut)[(s&65535)<<1]; - ((__m128i*)cseq)[i2++] = ((__m128i*)unscrambling_lut)[1+((s&65535)<<1)]; + ((__m128i *)cseq)[i2++] = ((__m128i *)unscrambling_lut)[(s&65535)<<1]; + ((__m128i *)cseq)[i2++] = ((__m128i *)unscrambling_lut)[1+((s&65535)<<1)]; s>>=16; - ((__m128i*)cseq)[i2++] = ((__m128i*)unscrambling_lut)[(s&65535)<<1]; - ((__m128i*)cseq)[i2++] = ((__m128i*)unscrambling_lut)[1+((s&65535)<<1)]; + ((__m128i *)cseq)[i2++] = ((__m128i *)unscrambling_lut)[(s&65535)<<1]; + ((__m128i *)cseq)[i2++] = ((__m128i *)unscrambling_lut)[1+((s&65535)<<1)]; #else - ((__m256i*)cseq)[i2++] = ((__m256i*)unscrambling_lut)[s&65535]; - ((__m256i*)cseq)[i2++] = ((__m256i*)unscrambling_lut)[(s>>16)&65535]; + ((__m256i *)cseq)[i2++] = ((__m256i *)unscrambling_lut)[s&65535]; + ((__m256i *)cseq)[i2++] = ((__m256i *)unscrambling_lut)[(s>>16)&65535]; #endif #elif defined(__arm__) - ((int16x8_t*)cseq)[i2++] = ((int16x8_t*)unscrambling_lut)[(s&65535)<<1]; - ((int16x8_t*)cseq)[i2++] = ((int16x8_t*)unscrambling_lut)[1+((s&65535)<<1)]; + ((int16x8_t *)cseq)[i2++] = ((int16x8_t *)unscrambling_lut)[(s&65535)<<1]; + ((int16x8_t *)cseq)[i2++] = ((int16x8_t *)unscrambling_lut)[1+((s&65535)<<1)]; s>>=16; - ((int16x8_t*)cseq)[i2++] = ((int16x8_t*)unscrambling_lut)[(s&65535)<<1]; - ((int16x8_t*)cseq)[i2++] = ((int16x8_t*)unscrambling_lut)[1+((s&65535)<<1)]; + ((int16x8_t *)cseq)[i2++] = ((int16x8_t *)unscrambling_lut)[(s&65535)<<1]; + ((int16x8_t *)cseq)[i2++] = ((int16x8_t *)unscrambling_lut)[1+((s&65535)<<1)]; #endif s = lte_gold_unscram(&x1, &x2, 0); } - // printf("after unscrambling c[%d] = %p\n",0,ulsch_harq->c[0]); if (frame_parms->Ncp == 0) @@ -1040,7 +939,6 @@ unsigned int ulsch_decoding(PHY_VARS_eNB *eNB,L1_rxtx_proc_t *proc, cseq[off+q] = -1; // PUSCH_x j=(j+3)&3; - } // printf("after RI c[%d] = %p\n",0,ulsch_harq->c[0]); @@ -1069,87 +967,82 @@ unsigned int ulsch_decoding(PHY_VARS_eNB *eNB,L1_rxtx_proc_t *proc, } #ifdef DEBUG_ULSCH_DECODING - printf("ulsch_decoding.c: ACK i %d, r %d, j %d, ColumnSet[j] %d\n",i,r,j,columnset[j]); + printf("ulsch_decoding.c: ACK i %u, r %d, j %u, ColumnSet[j] %d\n",i,r,j,columnset[j]); #endif j=(j+3)&3; } - - i=0; switch (Q_m) { - case 2: - for (j=0; j<Cmux; j++) { - i2=j<<1; - - for (r=0; r<Rmux_prime; r++) { - c = cseq[i]; - // printf("ulsch %d: %d * ",i,c); - y[i2++] = c*ulsch_llr[i++]; - // printf("%d\n",ulsch_llr[i-1]); - c = cseq[i]; - // printf("ulsch %d: %d * ",i,c); - y[i2] = c*ulsch_llr[i++]; - // printf("%d\n",ulsch_llr[i-1]); - i2=(i2+(Cmux<<1)-1); + case 2: + for (j=0; j<Cmux; j++) { + i2=j<<1; + + for (r=0; r<Rmux_prime; r++) { + c = cseq[i]; + // printf("ulsch %d: %d * ",i,c); + y[i2++] = c*ulsch_llr[i++]; + // printf("%d\n",ulsch_llr[i-1]); + c = cseq[i]; + // printf("ulsch %d: %d * ",i,c); + y[i2] = c*ulsch_llr[i++]; + // printf("%d\n",ulsch_llr[i-1]); + i2=(i2+(Cmux<<1)-1); + } } - } - - break; - - case 4: - for (j=0; j<Cmux; j++) { - i2=j<<2; - - for (r=0; r<Rmux_prime; r++) { - /* - c = cseq[i]; - y[i2++] = c*ulsch_llr[i++]; - c = cseq[i]; - y[i2++] = c*ulsch_llr[i++]; - c = cseq[i]; - y[i2++] = c*ulsch_llr[i++]; - c = cseq[i]; - y[i2] = c*ulsch_llr[i++]; - i2=(i2+(Cmux<<2)-3); - */ - // slightly more optimized version (equivalent to above) for 16QAM to improve computational performance - *(__m64 *)&y[i2] = _mm_sign_pi16(*(__m64*)&ulsch_llr[i],*(__m64*)&cseq[i]);i+=4;i2+=(Cmux<<2); + break; + case 4: + for (j=0; j<Cmux; j++) { + i2=j<<2; + + for (r=0; r<Rmux_prime; r++) { + /* + c = cseq[i]; + y[i2++] = c*ulsch_llr[i++]; + c = cseq[i]; + y[i2++] = c*ulsch_llr[i++]; + c = cseq[i]; + y[i2++] = c*ulsch_llr[i++]; + c = cseq[i]; + y[i2] = c*ulsch_llr[i++]; + i2=(i2+(Cmux<<2)-3); + */ + // slightly more optimized version (equivalent to above) for 16QAM to improve computational performance + *(__m64 *)&y[i2] = _mm_sign_pi16(*(__m64 *)&ulsch_llr[i],*(__m64 *)&cseq[i]); + i+=4; + i2+=(Cmux<<2); + } } - } - break; - - case 6: - for (j=0; j<Cmux; j++) { - i2=j*6; - - for (r=0; r<Rmux_prime; r++) { - c = cseq[i]; - y[i2++] = c*ulsch_llr[i++]; - c = cseq[i]; - y[i2++] = c*ulsch_llr[i++]; - c = cseq[i]; - y[i2++] = c*ulsch_llr[i++]; - c = cseq[i]; - y[i2++] = c*ulsch_llr[i++]; - c = cseq[i]; - y[i2++] = c*ulsch_llr[i++]; - c = cseq[i]; - y[i2] = c*ulsch_llr[i++]; - i2=(i2+(Cmux*6)-5); + break; + + case 6: + for (j=0; j<Cmux; j++) { + i2=j*6; + + for (r=0; r<Rmux_prime; r++) { + c = cseq[i]; + y[i2++] = c*ulsch_llr[i++]; + c = cseq[i]; + y[i2++] = c*ulsch_llr[i++]; + c = cseq[i]; + y[i2++] = c*ulsch_llr[i++]; + c = cseq[i]; + y[i2++] = c*ulsch_llr[i++]; + c = cseq[i]; + y[i2++] = c*ulsch_llr[i++]; + c = cseq[i]; + y[i2] = c*ulsch_llr[i++]; + i2=(i2+(Cmux*6)-5); + } } - } - break; + break; } - - - if (i!=(H+Q_RI)) LOG_D(PHY,"ulsch_decoding.c: Error in input buffer length (j %d, H+Q_RI %d)\n",i,H+Q_RI); @@ -1164,33 +1057,33 @@ unsigned int ulsch_decoding(PHY_VARS_eNB *eNB,L1_rxtx_proc_t *proc, if (ulsch_harq->O_ACK == 1) { switch (Q_m) { - case 2: - len_ACK = 2; - break; + case 2: + len_ACK = 2; + break; - case 4: - len_ACK = 4; - break; + case 4: + len_ACK = 4; + break; - case 6: - len_ACK = 6; - break; + case 6: + len_ACK = 6; + break; } } if (ulsch_harq->O_ACK == 2) { switch (Q_m) { - case 2: - len_ACK = 6; - break; + case 2: + len_ACK = 6; + break; - case 4: - len_ACK = 12; - break; + case 4: + len_ACK = 12; + break; - case 6: - len_ACK = 18; - break; + case 6: + len_ACK = 18; + break; } } @@ -1202,13 +1095,13 @@ unsigned int ulsch_decoding(PHY_VARS_eNB *eNB,L1_rxtx_proc_t *proc, for (i=0; i<len_ACK; i++) ulsch_harq->q_ACK[i] = 0; - for (i=0; i<Qprime_ACK; i++) { r = Rmux_prime -1 - (i>>2); for (q=0; q<Q_m; q++) { if (y[q+(Q_m*((r*Cmux) + columnset[j]))]!=0) ulsch_harq->q_ACK[(q+(Q_m*i))%len_ACK] += y[q+(Q_m*((r*Cmux) + columnset[j]))]; + y[q+(Q_m*((r*Cmux) + columnset[j]))]=0; // NULL LLRs in ACK positions } @@ -1221,17 +1114,17 @@ unsigned int ulsch_decoding(PHY_VARS_eNB *eNB,L1_rxtx_proc_t *proc, if (ulsch_harq->O_RI == 1) { switch (Q_m) { - case 2: - len_RI=2; - break; + case 2: + len_RI=2; + break; - case 4: - len_RI=4; - break; + case 4: + len_RI=4; + break; - case 6: - len_RI=6; - break; + case 6: + len_RI=6; + break; } } @@ -1261,7 +1154,6 @@ unsigned int ulsch_decoding(PHY_VARS_eNB *eNB,L1_rxtx_proc_t *proc, } // printf("after RI2 c[%d] = %p\n",0,ulsch_harq->c[0]); - // CQI and Data bits j=0; j2=0; @@ -1269,116 +1161,108 @@ unsigned int ulsch_decoding(PHY_VARS_eNB *eNB,L1_rxtx_proc_t *proc, // r=0; if (Q_RI>0) { for (i=0; i<(Q_CQI/Q_m); i++) { - while (ytag[j]==LTE_NULL) { - j++; - j2+=Q_m; + j++; + j2+=Q_m; } - + for (q=0; q<Q_m; q++) { - // ys = y[q+(Q_m*((r*Cmux)+j))]; - ys = y[q+j2]; - - if (ys>127) - ulsch_harq->q[q+(Q_m*i)] = 127; - else if (ys<-128) - ulsch_harq->q[q+(Q_m*i)] = -128; - else - ulsch_harq->q[q+(Q_m*i)] = ys; + // ys = y[q+(Q_m*((r*Cmux)+j))]; + ys = y[q+j2]; + + if (ys>127) + ulsch_harq->q[q+(Q_m*i)] = 127; + else if (ys<-128) + ulsch_harq->q[q+(Q_m*i)] = -128; + else + ulsch_harq->q[q+(Q_m*i)] = ys; } - + j2+=Q_m; } - - + switch (Q_m) { - case 2: - for (iprime=0; iprime<G;) { - while (ytag[j]==LTE_NULL) { - j++; - j2+=2; - } - - ulsch_harq->e[iprime++] = y[j2++]; - ulsch_harq->e[iprime++] = y[j2++]; - - } - - - break; - - case 4: - for (iprime=0; iprime<G;) { - while (ytag[j]==LTE_NULL) { - j++; - j2+=4; - } - - ulsch_harq->e[iprime++] = y[j2++]; - ulsch_harq->e[iprime++] = y[j2++]; - ulsch_harq->e[iprime++] = y[j2++]; - ulsch_harq->e[iprime++] = y[j2++]; - - } - - break; - - case 6: - for (iprime=0; iprime<G;) { - while (ytag[j]==LTE_NULL) { - j++; - j2+=6; - } - - ulsch_harq->e[iprime++] = y[j2++]; - ulsch_harq->e[iprime++] = y[j2++]; - ulsch_harq->e[iprime++] = y[j2++]; - ulsch_harq->e[iprime++] = y[j2++]; - ulsch_harq->e[iprime++] = y[j2++]; - ulsch_harq->e[iprime++] = y[j2++]; - - } - - break; + case 2: + for (iprime=0; iprime<G;) { + while (ytag[j]==LTE_NULL) { + j++; + j2+=2; + } - } - + ulsch_harq->e[iprime++] = y[j2++]; + ulsch_harq->e[iprime++] = y[j2++]; + } + + break; + + case 4: + for (iprime=0; iprime<G;) { + while (ytag[j]==LTE_NULL) { + j++; + j2+=4; + } + + ulsch_harq->e[iprime++] = y[j2++]; + ulsch_harq->e[iprime++] = y[j2++]; + ulsch_harq->e[iprime++] = y[j2++]; + ulsch_harq->e[iprime++] = y[j2++]; + } + break; + + case 6: + for (iprime=0; iprime<G;) { + while (ytag[j]==LTE_NULL) { + j++; + j2+=6; + } + + ulsch_harq->e[iprime++] = y[j2++]; + ulsch_harq->e[iprime++] = y[j2++]; + ulsch_harq->e[iprime++] = y[j2++]; + ulsch_harq->e[iprime++] = y[j2++]; + ulsch_harq->e[iprime++] = y[j2++]; + ulsch_harq->e[iprime++] = y[j2++]; + } + + break; + } } // Q_RI>0 else { - for (i=0; i<(Q_CQI/Q_m); i++) { - for (q=0; q<Q_m; q++) { - ys = y[q+j2]; - if (ys>127) - ulsch_harq->q[q+(Q_m*i)] = 127; - else if (ys<-128) - ulsch_harq->q[q+(Q_m*i)] = -128; - else - ulsch_harq->q[q+(Q_m*i)] = ys; + ys = y[q+j2]; + + if (ys>127) + ulsch_harq->q[q+(Q_m*i)] = 127; + else if (ys<-128) + ulsch_harq->q[q+(Q_m*i)] = -128; + else + ulsch_harq->q[q+(Q_m*i)] = ys; } - + j2+=Q_m; } + /* To be improved according to alignment of j2 -#if defined(__x86_64__)||defined(__i386__) -#ifndef __AVX2__ + #if defined(__x86_64__)||defined(__i386__) + #ifndef __AVX2__ for (iprime=0; iprime<G;iprime+=8,j2+=8) *((__m128i *)&ulsch_harq->e[iprime]) = *((__m128i *)&y[j2]); -#else + #else for (iprime=0; iprime<G;iprime+=16,j2+=16) *((__m256i *)&ulsch_harq->e[iprime]) = *((__m256i *)&y[j2]); -#endif -#elif defined(__arm__) + #endif + #elif defined(__arm__) for (iprime=0; iprime<G;iprime+=8,j2+=8) *((int16x8_t *)&ulsch_harq->e[iprime]) = *((int16x8_t *)&y[j2]); -#endif + #endif */ int16_t *yp,*ep; - for (iprime=0,yp=&y[j2],ep=&ulsch_harq->e[0]; - iprime<G; - iprime+=8,j2+=8,ep+=8,yp+=8) { + + for (iprime=0,yp=&y[j2],ep=&ulsch_harq->e[0]; + iprime<G; + iprime+=8,j2+=8,ep+=8,yp+=8) { ep[0] = yp[0]; ep[1] = yp[1]; ep[2] = yp[2]; @@ -1389,14 +1273,10 @@ unsigned int ulsch_decoding(PHY_VARS_eNB *eNB,L1_rxtx_proc_t *proc, ep[7] = yp[7]; } } - - - stop_meas(&eNB->ulsch_demultiplexing_stats); + stop_meas(&eNB->ulsch_demultiplexing_stats); // printf("after ACKNAK2 c[%d] = %p (iprime %d, G %d)\n",0,ulsch_harq->c[0],iprime,G); - // Do CQI/RI/HARQ-ACK Decoding first and pass to MAC - // HARQ-ACK wACK_idx = (ulsch->bundling==0) ? 4 : ((Nbundled-1)&3); @@ -1412,22 +1292,23 @@ unsigned int ulsch_decoding(PHY_VARS_eNB *eNB,L1_rxtx_proc_t *proc, if (ulsch_harq->O_ACK == 2) { switch (Q_m) { - - case 2: - ulsch_harq->q_ACK[0] = ulsch_harq->q_ACK[0]*wACK_RX[wACK_idx][0] + ulsch_harq->q_ACK[3]*wACK_RX[wACK_idx][1]; - ulsch_harq->q_ACK[1] = ulsch_harq->q_ACK[1]*wACK_RX[wACK_idx][0] + ulsch_harq->q_ACK[4]*wACK_RX[wACK_idx][1]; - ulsch_harq->q_ACK[2] = ulsch_harq->q_ACK[2]*wACK_RX[wACK_idx][0] + ulsch_harq->q_ACK[5]*wACK_RX[wACK_idx][1]; - break; - case 4: - ulsch_harq->q_ACK[0] = ulsch_harq->q_ACK[0]*wACK_RX[wACK_idx][0] + ulsch_harq->q_ACK[5]*wACK_RX[wACK_idx][1]; - ulsch_harq->q_ACK[1] = ulsch_harq->q_ACK[1]*wACK_RX[wACK_idx][0] + ulsch_harq->q_ACK[8]*wACK_RX[wACK_idx][1]; - ulsch_harq->q_ACK[2] = ulsch_harq->q_ACK[4]*wACK_RX[wACK_idx][0] + ulsch_harq->q_ACK[9]*wACK_RX[wACK_idx][1]; - break; - case 6: - ulsch_harq->q_ACK[0] = ulsch_harq->q_ACK[0]*wACK_RX[wACK_idx][0] + ulsch_harq->q_ACK[7]*wACK_RX[wACK_idx][1]; - ulsch_harq->q_ACK[1] = ulsch_harq->q_ACK[1]*wACK_RX[wACK_idx][0] + ulsch_harq->q_ACK[12]*wACK_RX[wACK_idx][1]; - ulsch_harq->q_ACK[2] = ulsch_harq->q_ACK[6]*wACK_RX[wACK_idx][0] + ulsch_harq->q_ACK[13]*wACK_RX[wACK_idx][1]; - break; + case 2: + ulsch_harq->q_ACK[0] = ulsch_harq->q_ACK[0]*wACK_RX[wACK_idx][0] + ulsch_harq->q_ACK[3]*wACK_RX[wACK_idx][1]; + ulsch_harq->q_ACK[1] = ulsch_harq->q_ACK[1]*wACK_RX[wACK_idx][0] + ulsch_harq->q_ACK[4]*wACK_RX[wACK_idx][1]; + ulsch_harq->q_ACK[2] = ulsch_harq->q_ACK[2]*wACK_RX[wACK_idx][0] + ulsch_harq->q_ACK[5]*wACK_RX[wACK_idx][1]; + break; + + case 4: + ulsch_harq->q_ACK[0] = ulsch_harq->q_ACK[0]*wACK_RX[wACK_idx][0] + ulsch_harq->q_ACK[5]*wACK_RX[wACK_idx][1]; + ulsch_harq->q_ACK[1] = ulsch_harq->q_ACK[1]*wACK_RX[wACK_idx][0] + ulsch_harq->q_ACK[8]*wACK_RX[wACK_idx][1]; + ulsch_harq->q_ACK[2] = ulsch_harq->q_ACK[4]*wACK_RX[wACK_idx][0] + ulsch_harq->q_ACK[9]*wACK_RX[wACK_idx][1]; + break; + + case 6: + ulsch_harq->q_ACK[0] = ulsch_harq->q_ACK[0]*wACK_RX[wACK_idx][0] + ulsch_harq->q_ACK[7]*wACK_RX[wACK_idx][1]; + ulsch_harq->q_ACK[1] = ulsch_harq->q_ACK[1]*wACK_RX[wACK_idx][0] + ulsch_harq->q_ACK[12]*wACK_RX[wACK_idx][1]; + ulsch_harq->q_ACK[2] = ulsch_harq->q_ACK[6]*wACK_RX[wACK_idx][0] + ulsch_harq->q_ACK[13]*wACK_RX[wACK_idx][1]; + break; } ulsch_harq->o_ACK[0] = 1; @@ -1443,7 +1324,6 @@ unsigned int ulsch_decoding(PHY_VARS_eNB *eNB,L1_rxtx_proc_t *proc, metric_new = ulsch_harq->q_ACK[0]-ulsch_harq->q_ACK[1]+ulsch_harq->q_ACK[2]; - if (metric_new > metric) { ulsch_harq->o_ACK[0] = 1; ulsch_harq->o_ACK[1] = 0; @@ -1467,26 +1347,21 @@ unsigned int ulsch_decoding(PHY_VARS_eNB *eNB,L1_rxtx_proc_t *proc, } // CQI - // printf("before cqi c[%d] = %p\n",0,ulsch_harq->c[0]); ulsch_harq->cqi_crc_status = 0; + if (Q_CQI>0) { memset((void *)&dummy_w_cc[0],0,3*(ulsch_harq->Or1+8+32)); - O_RCC = generate_dummy_w_cc(ulsch_harq->Or1+8, &dummy_w_cc[0]); - - lte_rate_matching_cc_rx(O_RCC, Q_CQI, ulsch_harq->o_w, dummy_w_cc, ulsch_harq->q); - sub_block_deinterleaving_cc((unsigned int)(ulsch_harq->Or1+8), &ulsch_harq->o_d[96], &ulsch_harq->o_w[0]); - memset(ulsch_harq->o,0,(7+8+ulsch_harq->Or1) / 8); phy_viterbi_lte_sse2(ulsch_harq->o_d+96,ulsch_harq->o,8+ulsch_harq->Or1); @@ -1497,7 +1372,7 @@ unsigned int ulsch_decoding(PHY_VARS_eNB *eNB,L1_rxtx_proc_t *proc, printf("ulsch_decoding: Or1=%d\n",ulsch_harq->Or1); for (i=0; i<1+((8+ulsch_harq->Or1)/8); i++) - printf("ulsch_decoding: O[%d] %d\n",i,ulsch_harq->o[i]); + printf("ulsch_decoding: O[%u] %d\n",i,ulsch_harq->o[i]); if (ulsch_harq->cqi_crc_status == 1) printf("RX CQI CRC OK (%x)\n",extract_cqi_crc(ulsch_harq->o,ulsch_harq->Or1)); @@ -1508,12 +1383,8 @@ unsigned int ulsch_decoding(PHY_VARS_eNB *eNB,L1_rxtx_proc_t *proc, } LOG_D(PHY,"frame %d subframe %d O_ACK:%d o_ACK[]=%d:%d:%d:%d\n",frame,subframe,ulsch_harq->O_ACK,ulsch_harq->o_ACK[0],ulsch_harq->o_ACK[1],ulsch_harq->o_ACK[2],ulsch_harq->o_ACK[3]); - // Do ULSCH Decoding for data portion - ret = ulsch_decoding_data_all(eNB,UE_id,harq_pid,llr8_flag); - VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_ENB_ULSCH_DECODING0+harq_pid,0); - return(ret); } diff --git a/openair1/PHY/LTE_TRANSPORT/ulsch_demodulation.c b/openair1/PHY/LTE_TRANSPORT/ulsch_demodulation.c index 0c799d8494fcf416fe3682b10bbfca4d07b9be8c..8fab8cd0df8285d539f57fc5efa88f2e8221e66b 100644 --- a/openair1/PHY/LTE_TRANSPORT/ulsch_demodulation.c +++ b/openair1/PHY/LTE_TRANSPORT/ulsch_demodulation.c @@ -687,7 +687,7 @@ void ulsch_detection_mrc(LTE_DL_FRAME_PARMS *frame_parms, ul_ch_mag128_0[i] = _mm_adds_epi16(_mm_srai_epi16(ul_ch_mag128_0[i],1),_mm_srai_epi16(ul_ch_mag128_1[i],1)); ul_ch_mag128_0b[i] = _mm_adds_epi16(_mm_srai_epi16(ul_ch_mag128_0b[i],1),_mm_srai_epi16(ul_ch_mag128_1b[i],1)); rxdataF_comp128_0[i] = _mm_add_epi16(rxdataF_comp128_0[i],(*(__m128i*)&jitterc[0])); - + } #elif defined(__arm__) rxdataF_comp128_0 = (int16x8_t *)&rxdataF_comp[0][symbol*frame_parms->N_RB_DL*12]; rxdataF_comp128_1 = (int16x8_t *)&rxdataF_comp[1][symbol*frame_parms->N_RB_DL*12]; @@ -702,10 +702,10 @@ void ulsch_detection_mrc(LTE_DL_FRAME_PARMS *frame_parms, ul_ch_mag128_0[i] = vhaddq_s16(ul_ch_mag128_0[i],ul_ch_mag128_1[i]); ul_ch_mag128_0b[i] = vhaddq_s16(ul_ch_mag128_0b[i],ul_ch_mag128_1b[i]); rxdataF_comp128_0[i] = vqaddq_s16(rxdataF_comp128_0[i],(*(int16x8_t*)&jitterc[0])); - + } #endif - } + } #if defined(__x86_64__) || defined(__i386__) diff --git a/openair1/PHY/LTE_UE_TRANSPORT/dci_ue.c b/openair1/PHY/LTE_UE_TRANSPORT/dci_ue.c index 4a2c8481cb9e5ae903fcc18f44f022911a8ec84a..2c6f31e24461b3b88e32955be531849761b31546 100644 --- a/openair1/PHY/LTE_UE_TRANSPORT/dci_ue.c +++ b/openair1/PHY/LTE_UE_TRANSPORT/dci_ue.c @@ -362,6 +362,10 @@ void pdcch_channel_level(int32_t **dl_ch_estimates_ext, #elif defined(__arm__) int16x8_t *dl_ch128; int32x4_t *avg128P; +#else + int16_t *dl_ch128; + int32_t *avg128P; +#error Unsupported CPU architecture, cannot build __FILE__ #endif for (aatx=0; aatx<frame_parms->nb_antenna_ports_eNB; aatx++) for (aarx=0; aarx<frame_parms->nb_antennas_rx; aarx++) { @@ -370,7 +374,11 @@ void pdcch_channel_level(int32_t **dl_ch_estimates_ext, avg128P = _mm_setzero_si128(); dl_ch128=(__m128i *)&dl_ch_estimates_ext[(aatx<<1)+aarx][0]; #elif defined(__arm__) - + dl_ch128=&dl_ch_estimates_ext[(aatx<<1)+aarx][0]; +#error __arm__ not yet implemented, cannot build __FILE__ +#else + dl_ch128=&dl_ch_estimates_ext[(aatx<<1)+aarx][0]; +#error Unsupported CPU architecture, cannot build __FILE__ #endif for (rb=0; rb<nb_rb; rb++) { @@ -379,7 +387,8 @@ void pdcch_channel_level(int32_t **dl_ch_estimates_ext, avg128P = _mm_add_epi32(avg128P,_mm_madd_epi16(dl_ch128[1],dl_ch128[1])); avg128P = _mm_add_epi32(avg128P,_mm_madd_epi16(dl_ch128[2],dl_ch128[2])); #elif defined(__arm__) - +#else +#error Unsupported CPU architecture, cannot build __FILE__ #endif dl_ch128+=3; /* @@ -423,6 +432,8 @@ void pdcch_detection_mrc_i(LTE_DL_FRAME_PARMS *frame_parms, __m128i *rxdataF_comp128_0,*rxdataF_comp128_1,*rxdataF_comp128_i0,*rxdataF_comp128_i1,*rho128_0,*rho128_1,*rho128_i0,*rho128_i1; #elif defined(__arm__) int16x8_t *rxdataF_comp128_0,*rxdataF_comp128_1,*rxdataF_comp128_i0,*rxdataF_comp128_i1,*rho128_0,*rho128_1,*rho128_i0,*rho128_i1; +#else +#error Unsupported CPU architecture, cannot build __FILE__ #endif int32_t i; @@ -436,6 +447,8 @@ void pdcch_detection_mrc_i(LTE_DL_FRAME_PARMS *frame_parms, #elif defined(__arm__) rxdataF_comp128_0 = (int16x8_t *)&rxdataF_comp[(aatx<<1)][symbol*frame_parms->N_RB_DL*12]; rxdataF_comp128_1 = (int16x8_t *)&rxdataF_comp[(aatx<<1)+1][symbol*frame_parms->N_RB_DL*12]; +#else +#error Unsupported CPU architecture, cannot build __FILE__ #endif // MRC on each re of rb on MF output for (i=0; i<frame_parms->N_RB_DL*3; i++) { diff --git a/openair1/PHY/LTE_UE_TRANSPORT/dlsch_decoding.c b/openair1/PHY/LTE_UE_TRANSPORT/dlsch_decoding.c index 1b4ca3ed2fb37e19b5beaa284a00e55a7c7b7e00..4ca9a7c7625f19470fb3023269e37081ade943d2 100644 --- a/openair1/PHY/LTE_UE_TRANSPORT/dlsch_decoding.c +++ b/openair1/PHY/LTE_UE_TRANSPORT/dlsch_decoding.c @@ -40,9 +40,7 @@ //#define DEBUG_DLSCH_DECODING //#define UE_DEBUG_TRACE 1 -void free_ue_dlsch(LTE_UE_DLSCH_t *dlsch) -{ - +void free_ue_dlsch(LTE_UE_DLSCH_t *dlsch) { int i,r; if (dlsch) { @@ -70,34 +68,30 @@ void free_ue_dlsch(LTE_UE_DLSCH_t *dlsch) } free16(dlsch,sizeof(LTE_UE_DLSCH_t)); - dlsch = NULL; } } -LTE_UE_DLSCH_t *new_ue_dlsch(uint8_t Kmimo,uint8_t Mdlharq,uint32_t Nsoft,uint8_t max_turbo_iterations,uint8_t N_RB_DL, uint8_t abstraction_flag) -{ - +LTE_UE_DLSCH_t *new_ue_dlsch(uint8_t Kmimo,uint8_t Mdlharq,uint32_t Nsoft,uint8_t max_turbo_iterations,uint8_t N_RB_DL, uint8_t abstraction_flag) { LTE_UE_DLSCH_t *dlsch; uint8_t exit_flag = 0,i,r; - unsigned char bw_scaling =1; switch (N_RB_DL) { - case 6: - bw_scaling =16; - break; + case 6: + bw_scaling =16; + break; - case 25: - bw_scaling =4; - break; + case 25: + bw_scaling =4; + break; - case 50: - bw_scaling =2; - break; + case 50: + bw_scaling =2; + break; - default: - bw_scaling =1; - break; + default: + bw_scaling =1; + break; } dlsch = (LTE_UE_DLSCH_t *)malloc16(sizeof(LTE_UE_DLSCH_t)); @@ -116,7 +110,7 @@ LTE_UE_DLSCH_t *new_ue_dlsch(uint8_t Kmimo,uint8_t Mdlharq,uint32_t Nsoft,uint8_ if (dlsch->harq_processes[i]) { memset(dlsch->harq_processes[i],0,sizeof(LTE_DL_UE_HARQ_t)); dlsch->harq_processes[i]->first_tx=1; - dlsch->harq_processes[i]->b = (uint8_t*)malloc16(MAX_DLSCH_PAYLOAD_BYTES/bw_scaling); + dlsch->harq_processes[i]->b = (uint8_t *)malloc16(MAX_DLSCH_PAYLOAD_BYTES/bw_scaling); if (dlsch->harq_processes[i]->b) memset(dlsch->harq_processes[i]->b,0,MAX_DLSCH_PAYLOAD_BYTES/bw_scaling); @@ -125,14 +119,14 @@ LTE_UE_DLSCH_t *new_ue_dlsch(uint8_t Kmimo,uint8_t Mdlharq,uint32_t Nsoft,uint8_ if (abstraction_flag == 0) { for (r=0; r<MAX_NUM_DLSCH_SEGMENTS/bw_scaling; r++) { - dlsch->harq_processes[i]->c[r] = (uint8_t*)malloc16(((r==0)?8:0) + 3+ 768); + dlsch->harq_processes[i]->c[r] = (uint8_t *)malloc16(((r==0)?8:0) + 3+ 768); if (dlsch->harq_processes[i]->c[r]) memset(dlsch->harq_processes[i]->c[r],0,((r==0)?8:0) + 3+ 768); else exit_flag=2; - dlsch->harq_processes[i]->d[r] = (short*)malloc16(((3*8*6144)+12+96)*sizeof(short)); + dlsch->harq_processes[i]->d[r] = (short *)malloc16(((3*8*6144)+12+96)*sizeof(short)); if (dlsch->harq_processes[i]->d[r]) memset(dlsch->harq_processes[i]->d[r],0,((3*8*6144)+12+96)*sizeof(short)); @@ -151,7 +145,6 @@ LTE_UE_DLSCH_t *new_ue_dlsch(uint8_t Kmimo,uint8_t Mdlharq,uint32_t Nsoft,uint8_ printf("new_ue_dlsch with size %zu: exit_flag = %u\n",sizeof(LTE_DL_UE_HARQ_t), exit_flag); free_ue_dlsch(dlsch); - return(NULL); } @@ -164,9 +157,7 @@ uint32_t dlsch_decoding(PHY_VARS_UE *phy_vars_ue, uint8_t subframe, uint8_t harq_pid, uint8_t is_crnti, - uint8_t llr8_flag) -{ - + uint8_t llr8_flag) { #if UE_TIMING_TRACE time_stats_t *dlsch_rate_unmatching_stats=&phy_vars_ue->dlsch_rate_unmatching_stats; time_stats_t *dlsch_turbo_decoding_stats=&phy_vars_ue->dlsch_turbo_decoding_stats; @@ -186,26 +177,24 @@ uint32_t dlsch_decoding(PHY_VARS_UE *phy_vars_ue, #if 0 int Kr_last,skipped_last=0; uint8_t (*tc_2cw)(int16_t *y, - int16_t *y2, - uint8_t *, - uint8_t *, - uint16_t, - uint16_t, - uint16_t, - uint8_t, - uint8_t, - uint8_t, - time_stats_t *, - time_stats_t *, - time_stats_t *, - time_stats_t *, - time_stats_t *, - time_stats_t *, - time_stats_t *); - -#endif -decoder_if_t *tc; - + int16_t *y2, + uint8_t *, + uint8_t *, + uint16_t, + uint16_t, + uint16_t, + uint8_t, + uint8_t, + uint8_t, + time_stats_t *, + time_stats_t *, + time_stats_t *, + time_stats_t *, + time_stats_t *, + time_stats_t *, + time_stats_t *); +#endif + decoder_if_t *tc; if (!dlsch_llr) { printf("dlsch_decoding.c: NULL dlsch_llr pointer\n"); @@ -229,42 +218,32 @@ decoder_if_t *tc; if (dlsch->harq_ack[subframe].ack != 2) { LOG_D(PHY, "[UE %d] DLSCH @ SF%d : ACK bit is %d instead of DTX even before PDSCH is decoded!\n", - phy_vars_ue->Mod_id, subframe, dlsch->harq_ack[subframe].ack); + phy_vars_ue->Mod_id, subframe, dlsch->harq_ack[subframe].ack); } if (llr8_flag == 0) { tc = decoder16; - } - else - { + } else { AssertFatal (harq_process->TBS >= 256 , "Mismatch flag nbRB=%d TBS=%d mcs=%d Qm=%d RIV=%d round=%d \n", - harq_process->nb_rb, harq_process->TBS,harq_process->mcs,harq_process->Qm,harq_process->rvidx,harq_process->round); + harq_process->nb_rb, harq_process->TBS,harq_process->mcs,harq_process->Qm,harq_process->rvidx,harq_process->round); tc = decoder8; } - // nb_rb = dlsch->nb_rb; - /* if (nb_rb > frame_parms->N_RB_DL) { printf("dlsch_decoding.c: Illegal nb_rb %d\n",nb_rb); return(max_turbo_iterations); }*/ - /*harq_pid = dlsch->current_harq_pid[phy_vars_ue->current_thread_id[subframe]]; if (harq_pid >= 8) { printf("dlsch_decoding.c: Illegal harq_pid %d\n",harq_pid); return(max_turbo_iterations); } */ - harq_process->trials[harq_process->round]++; - A = harq_process->TBS; //2072 for QPSK 1/3 - ret = dlsch->max_turbo_iterations; - - G = harq_process->G; //get_G(frame_parms,nb_rb,dlsch->rb_alloc,mod_order,num_pdcch_symbols,phy_vars_ue->frame,subframe); @@ -293,40 +272,37 @@ decoder_if_t *tc; */ err_flag = 0; r_offset = 0; - unsigned char bw_scaling =1; switch (frame_parms->N_RB_DL) { - case 6: - bw_scaling =16; - break; + case 6: + bw_scaling =16; + break; - case 25: - bw_scaling =4; - break; + case 25: + bw_scaling =4; + break; - case 50: - bw_scaling =2; - break; + case 50: + bw_scaling =2; + break; - default: - bw_scaling =1; - break; + default: + bw_scaling =1; + break; } if (harq_process->C > MAX_NUM_DLSCH_SEGMENTS/bw_scaling) { LOG_E(PHY,"Illegal harq_process->C %d > %d\n",harq_process->C,MAX_NUM_DLSCH_SEGMENTS/bw_scaling); return((1+dlsch->max_turbo_iterations)); } + #ifdef DEBUG_DLSCH_DECODING printf("Segmentation: C %d, Cminus %d, Kminus %d, Kplus %d\n",harq_process->C,harq_process->Cminus,harq_process->Kminus,harq_process->Kplus); #endif - opp_enabled=1; for (r=0; r<harq_process->C; r++) { - - // Get Turbo interleaver parameters if (r<harq_process->Cminus) Kr = harq_process->Kminus; @@ -334,15 +310,13 @@ decoder_if_t *tc; Kr = harq_process->Kplus; Kr_bytes = Kr>>3; - #if UE_TIMING_TRACE start_meas(dlsch_rate_unmatching_stats); #endif memset(&dummy_w[r][0],0,3*(6144+64)*sizeof(short)); harq_process->RTC[r] = generate_dummy_w(4+(Kr_bytes*8), - (uint8_t*) &dummy_w[r][0], + (uint8_t *) &dummy_w[r][0], (r==0) ? harq_process->F : 0); - #ifdef DEBUG_DLSCH_DECODING LOG_D(PHY,"HARQ_PID %d Rate Matching Segment %d (coded bits %d,unpunctured/repeated bits %d, TBS %d, mod_order %d, nb_rb %d, Nl %d, rv %d, round %d)...\n", harq_pid,r, G, @@ -354,14 +328,14 @@ decoder_if_t *tc; harq_process->rvidx, harq_process->round); #endif - #ifdef DEBUG_DLSCH_DECODING printf(" in decoding dlsch->harq_processes[harq_pid]->rvidx = %d\n", dlsch->harq_processes[harq_pid]->rvidx); #endif + if (lte_rate_matching_turbo_rx(harq_process->RTC[r], G, harq_process->w[r], - (uint8_t*)&dummy_w[r][0], + (uint8_t *)&dummy_w[r][0], dlsch_llr+r_offset, harq_process->C, dlsch->Nsoft, @@ -378,14 +352,13 @@ decoder_if_t *tc; #endif LOG_E(PHY,"dlsch_decoding.c: Problem in rate_matching\n"); return(dlsch->max_turbo_iterations); - } else - { + } else { #if UE_TIMING_TRACE stop_meas(dlsch_rate_unmatching_stats); #endif } - r_offset += E; + r_offset += E; /* printf("Subblock deinterleaving, d %p w %p\n", harq_process->d[r], @@ -396,7 +369,6 @@ decoder_if_t *tc; #endif sub_block_deinterleaving_turbo(4+Kr, &harq_process->d[r][96], - harq_process->w[r]); #if UE_TIMING_TRACE stop_meas(dlsch_deinterleaving_stats); @@ -413,8 +385,6 @@ decoder_if_t *tc; printf("%d : %d\n",i,harq_process->d[r][96+i]); printf("\n");*/ #endif - - // printf("Clearing c, %p\n",harq_process->c[r]); memset(harq_process->c[r],0,Kr_bytes); @@ -432,21 +402,22 @@ decoder_if_t *tc; printf("%d : %d\n",i,harq_process->d[r][96+i]); printf("\n"); */ - //#ifndef __AVX2__ #if 1 + if (err_flag == 0) { -/* - LOG_I(PHY, "turbo algo Kr=%d cb_cnt=%d C=%d nbRB=%d crc_type %d TBSInput=%d TBSHarq=%d TBSplus24=%d mcs=%d Qm=%d RIV=%d round=%d maxIter %d\n", - Kr,r,harq_process->C,harq_process->nb_rb,crc_type,A,harq_process->TBS, - harq_process->B,harq_process->mcs,harq_process->Qm,harq_process->rvidx,harq_process->round,dlsch->max_turbo_iterations); -*/ - if (llr8_flag) { - AssertFatal (Kr >= 256, "turbo algo issue Kr=%d cb_cnt=%d C=%d nbRB=%d TBSInput=%d TBSHarq=%d TBSplus24=%d mcs=%d Qm=%d RIV=%d round=%d\n", - Kr,r,harq_process->C,harq_process->nb_rb,A,harq_process->TBS,harq_process->B,harq_process->mcs,harq_process->Qm,harq_process->rvidx,harq_process->round); - } + /* + LOG_I(PHY, "turbo algo Kr=%d cb_cnt=%d C=%d nbRB=%d crc_type %d TBSInput=%d TBSHarq=%d TBSplus24=%d mcs=%d Qm=%d RIV=%d round=%d maxIter %d\n", + Kr,r,harq_process->C,harq_process->nb_rb,crc_type,A,harq_process->TBS, + harq_process->B,harq_process->mcs,harq_process->Qm,harq_process->rvidx,harq_process->round,dlsch->max_turbo_iterations); + */ + if (llr8_flag) { + AssertFatal (Kr >= 256, "turbo algo issue Kr=%d cb_cnt=%d C=%d nbRB=%d TBSInput=%d TBSHarq=%d TBSplus24=%d mcs=%d Qm=%d RIV=%d round=%d\n", + Kr,r,harq_process->C,harq_process->nb_rb,A,harq_process->TBS,harq_process->B,harq_process->mcs,harq_process->Qm,harq_process->rvidx,harq_process->round); + } + #if UE_TIMING_TRACE - start_meas(dlsch_turbo_decoding_stats); + start_meas(dlsch_turbo_decoding_stats); #endif LOG_D(PHY,"AbsSubframe %d.%d Start turbo segment %d/%d \n",frame%1024,subframe,r,harq_process->C-1); ret = tc @@ -465,17 +436,17 @@ decoder_if_t *tc; &phy_vars_ue->dlsch_tc_ext_stats, &phy_vars_ue->dlsch_tc_intl1_stats, &phy_vars_ue->dlsch_tc_intl2_stats); //(is_crnti==0)?harq_pid:harq_pid+1); - #if UE_TIMING_TRACE stop_meas(dlsch_turbo_decoding_stats); #endif } + #else - if ((harq_process->C == 1) || - ((r==harq_process->C-1) && (skipped_last==0))) { // last segment with odd number of segments + if ((harq_process->C == 1) || + ((r==harq_process->C-1) && (skipped_last==0))) { // last segment with odd number of segments #if UE_TIMING_TRACE - start_meas(dlsch_turbo_decoding_stats); + start_meas(dlsch_turbo_decoding_stats); #endif ret = tc (&harq_process->d[r][96], @@ -491,123 +462,115 @@ decoder_if_t *tc; &phy_vars_ue->dlsch_tc_ext_stats, &phy_vars_ue->dlsch_tc_intl1_stats, &phy_vars_ue->dlsch_tc_intl2_stats); //(is_crnti==0)?harq_pid:harq_pid+1); - #if UE_TIMING_TRACE +#if UE_TIMING_TRACE stop_meas(dlsch_turbo_decoding_stats); #endif // printf("single decode, exit\n"); // exit(-1); - } - else { - // we can merge code segments + } else { + // we can merge code segments if ((skipped_last == 0) && (r<harq_process->C-1)) { - skipped_last = 1; - Kr_last = Kr; - } - else { - skipped_last=0; + skipped_last = 1; + Kr_last = Kr; + } else { + skipped_last=0; - if (Kr_last == Kr) { // decode 2 code segments with AVX2 version + if (Kr_last == Kr) { // decode 2 code segments with AVX2 version #ifdef DEBUG_DLSCH_DECODING - printf("single decoding segment %d (%p)\n",r-1,&harq_process->d[r-1][96]); + printf("single decoding segment %d (%p)\n",r-1,&harq_process->d[r-1][96]); #endif #if UE_TIMING_TRACE - start_meas(dlsch_turbo_decoding_stats); + start_meas(dlsch_turbo_decoding_stats); #endif #ifdef DEBUG_DLSCH_DECODING - printf("double decoding segments %d,%d (%p,%p)\n",r-1,r,&harq_process->d[r-1][96],&harq_process->d[r][96]); -#endif - ret = tc_2cw - (&harq_process->d[r-1][96], - &harq_process->d[r][96], - harq_process->c[r-1], - harq_process->c[r], - Kr, - dlsch->max_turbo_iterations, - crc_type, - (r==0) ? harq_process->F : 0, - &phy_vars_ue->dlsch_tc_init_stats, - &phy_vars_ue->dlsch_tc_alpha_stats, - &phy_vars_ue->dlsch_tc_beta_stats, - &phy_vars_ue->dlsch_tc_gamma_stats, - &phy_vars_ue->dlsch_tc_ext_stats, - &phy_vars_ue->dlsch_tc_intl1_stats, - &phy_vars_ue->dlsch_tc_intl2_stats); //(is_crnti==0)?harq_pid:harq_pid+1); - /* - ret = tc - (&harq_process->d[r-1][96], - harq_process->c[r-1], - Kr_last, - dlsch->max_turbo_iterations, - crc_type, - (r==0) ? harq_process->F : 0, - &phy_vars_ue->dlsch_tc_init_stats, - &phy_vars_ue->dlsch_tc_alpha_stats, - &phy_vars_ue->dlsch_tc_beta_stats, - &phy_vars_ue->dlsch_tc_gamma_stats, - &phy_vars_ue->dlsch_tc_ext_stats, - &phy_vars_ue->dlsch_tc_intl1_stats, - &phy_vars_ue->dlsch_tc_intl2_stats); //(is_crnti==0)?harq_pid:harq_pid+1); - - exit(-1);*/ + printf("double decoding segments %d,%d (%p,%p)\n",r-1,r,&harq_process->d[r-1][96],&harq_process->d[r][96]); +#endif + ret = tc_2cw + (&harq_process->d[r-1][96], + &harq_process->d[r][96], + harq_process->c[r-1], + harq_process->c[r], + Kr, + dlsch->max_turbo_iterations, + crc_type, + (r==0) ? harq_process->F : 0, + &phy_vars_ue->dlsch_tc_init_stats, + &phy_vars_ue->dlsch_tc_alpha_stats, + &phy_vars_ue->dlsch_tc_beta_stats, + &phy_vars_ue->dlsch_tc_gamma_stats, + &phy_vars_ue->dlsch_tc_ext_stats, + &phy_vars_ue->dlsch_tc_intl1_stats, + &phy_vars_ue->dlsch_tc_intl2_stats); //(is_crnti==0)?harq_pid:harq_pid+1); + /* + ret = tc + (&harq_process->d[r-1][96], + harq_process->c[r-1], + Kr_last, + dlsch->max_turbo_iterations, + crc_type, + (r==0) ? harq_process->F : 0, + &phy_vars_ue->dlsch_tc_init_stats, + &phy_vars_ue->dlsch_tc_alpha_stats, + &phy_vars_ue->dlsch_tc_beta_stats, + &phy_vars_ue->dlsch_tc_gamma_stats, + &phy_vars_ue->dlsch_tc_ext_stats, + &phy_vars_ue->dlsch_tc_intl1_stats, + &phy_vars_ue->dlsch_tc_intl2_stats); //(is_crnti==0)?harq_pid:harq_pid+1); + + exit(-1);*/ #if UE_TIMING_TRACE - stop_meas(dlsch_turbo_decoding_stats); + stop_meas(dlsch_turbo_decoding_stats); #endif - } - else { // Kr_last != Kr + } else { // Kr_last != Kr #if UE_TIMING_TRACE - start_meas(dlsch_turbo_decoding_stats); -#endif - ret = tc - (&harq_process->d[r-1][96], - harq_process->c[r-1], - Kr_last, - dlsch->max_turbo_iterations, - crc_type, - (r==0) ? harq_process->F : 0, - &phy_vars_ue->dlsch_tc_init_stats, - &phy_vars_ue->dlsch_tc_alpha_stats, - &phy_vars_ue->dlsch_tc_beta_stats, - &phy_vars_ue->dlsch_tc_gamma_stats, - &phy_vars_ue->dlsch_tc_ext_stats, - &phy_vars_ue->dlsch_tc_intl1_stats, - &phy_vars_ue->dlsch_tc_intl2_stats); //(is_crnti==0)?harq_pid:harq_pid+1); + start_meas(dlsch_turbo_decoding_stats); +#endif + ret = tc + (&harq_process->d[r-1][96], + harq_process->c[r-1], + Kr_last, + dlsch->max_turbo_iterations, + crc_type, + (r==0) ? harq_process->F : 0, + &phy_vars_ue->dlsch_tc_init_stats, + &phy_vars_ue->dlsch_tc_alpha_stats, + &phy_vars_ue->dlsch_tc_beta_stats, + &phy_vars_ue->dlsch_tc_gamma_stats, + &phy_vars_ue->dlsch_tc_ext_stats, + &phy_vars_ue->dlsch_tc_intl1_stats, + &phy_vars_ue->dlsch_tc_intl2_stats); //(is_crnti==0)?harq_pid:harq_pid+1); #if UE_TIMING_TRACE - stop_meas(dlsch_turbo_decoding_stats); - - start_meas(dlsch_turbo_decoding_stats); -#endif - - ret = tc - (&harq_process->d[r][96], - harq_process->c[r], - Kr, - dlsch->max_turbo_iterations, - crc_type, - (r==0) ? harq_process->F : 0, - &phy_vars_ue->dlsch_tc_init_stats, - &phy_vars_ue->dlsch_tc_alpha_stats, - &phy_vars_ue->dlsch_tc_beta_stats, - &phy_vars_ue->dlsch_tc_gamma_stats, - &phy_vars_ue->dlsch_tc_ext_stats, - &phy_vars_ue->dlsch_tc_intl1_stats, - &phy_vars_ue->dlsch_tc_intl2_stats); //(is_crnti==0)?harq_pid:harq_pid+1); - + stop_meas(dlsch_turbo_decoding_stats); + start_meas(dlsch_turbo_decoding_stats); +#endif + ret = tc + (&harq_process->d[r][96], + harq_process->c[r], + Kr, + dlsch->max_turbo_iterations, + crc_type, + (r==0) ? harq_process->F : 0, + &phy_vars_ue->dlsch_tc_init_stats, + &phy_vars_ue->dlsch_tc_alpha_stats, + &phy_vars_ue->dlsch_tc_beta_stats, + &phy_vars_ue->dlsch_tc_gamma_stats, + &phy_vars_ue->dlsch_tc_ext_stats, + &phy_vars_ue->dlsch_tc_intl1_stats, + &phy_vars_ue->dlsch_tc_intl2_stats); //(is_crnti==0)?harq_pid:harq_pid+1); #if UE_TIMING_TRACE - - stop_meas(dlsch_turbo_decoding_stats); - - /*printf("Segmentation: C %d r %d, dlsch_rate_unmatching_stats %5.3f dlsch_deinterleaving_stats %5.3f dlsch_turbo_decoding_stats %5.3f \n", - harq_process->C, - r, - dlsch_rate_unmatching_stats->p_time/(cpuf*1000.0), - dlsch_deinterleaving_stats->p_time/(cpuf*1000.0), - dlsch_turbo_decoding_stats->p_time/(cpuf*1000.0));*/ + stop_meas(dlsch_turbo_decoding_stats); + /*printf("Segmentation: C %d r %d, dlsch_rate_unmatching_stats %5.3f dlsch_deinterleaving_stats %5.3f dlsch_turbo_decoding_stats %5.3f \n", + harq_process->C, + r, + dlsch_rate_unmatching_stats->p_time/(cpuf*1000.0), + dlsch_deinterleaving_stats->p_time/(cpuf*1000.0), + dlsch_turbo_decoding_stats->p_time/(cpuf*1000.0));*/ #endif - } + } } } -#endif +#endif if ((err_flag == 0) && (ret>=(1+dlsch->max_turbo_iterations))) {// a Code segment is in error so break; LOG_D(PHY,"AbsSubframe %d.%d CRC failed, segment %d/%d \n",frame%1024,subframe,r,harq_process->C-1); @@ -617,16 +580,18 @@ decoder_if_t *tc; int32_t frame_rx_prev = frame; int32_t subframe_rx_prev = subframe - 1; + if (subframe_rx_prev < 0) { frame_rx_prev--; subframe_rx_prev += 10; } + frame_rx_prev = frame_rx_prev%1024; if (err_flag == 1) { #if UE_DEBUG_TRACE LOG_D(PHY,"[UE %d] DLSCH: Setting NAK for SFN/SF %d/%d (pid %d, status %d, round %d, TBS %d, mcs %d) Kr %d r %d harq_process->round %d\n", - phy_vars_ue->Mod_id, frame, subframe, harq_pid,harq_process->status, harq_process->round,harq_process->TBS,harq_process->mcs,Kr,r,harq_process->round); + phy_vars_ue->Mod_id, frame, subframe, harq_pid,harq_process->status, harq_process->round,harq_process->TBS,harq_process->mcs,Kr,r,harq_process->round); #endif dlsch->harq_ack[subframe].ack = 0; dlsch->harq_ack[subframe].harq_id = harq_pid; @@ -634,39 +599,36 @@ decoder_if_t *tc; harq_process->errors[harq_process->round]++; harq_process->round++; - // printf("Rate: [UE %d] DLSCH: Setting NACK for subframe %d (pid %d, round %d)\n",phy_vars_ue->Mod_id,subframe,harq_pid,harq_process->round); if (harq_process->round >= dlsch->Mdlharq) { harq_process->status = SCH_IDLE; harq_process->round = 0; } - if(is_crnti) - { - LOG_D(PHY,"[UE %d] DLSCH: Setting NACK for subframe %d (pid %d, pid status %d, round %d/Max %d, TBS %d)\n", - phy_vars_ue->Mod_id,subframe,harq_pid,harq_process->status,harq_process->round,dlsch->Mdlharq,harq_process->TBS); + + if(is_crnti) { + LOG_D(PHY,"[UE %d] DLSCH: Setting NACK for subframe %d (pid %d, pid status %d, round %d/Max %d, TBS %d)\n", + phy_vars_ue->Mod_id,subframe,harq_pid,harq_process->status,harq_process->round,dlsch->Mdlharq,harq_process->TBS); } return((1+dlsch->max_turbo_iterations)); } else { #if UE_DEBUG_TRACE - LOG_D(PHY,"[UE %d] DLSCH: Setting ACK for subframe %d TBS %d mcs %d nb_rb %d\n", - phy_vars_ue->Mod_id,subframe,harq_process->TBS,harq_process->mcs,harq_process->nb_rb); + LOG_D(PHY,"[UE %d] DLSCH: Setting ACK for subframe %d TBS %d mcs %d nb_rb %d\n", + phy_vars_ue->Mod_id,subframe,harq_process->TBS,harq_process->mcs,harq_process->nb_rb); #endif - harq_process->status = SCH_IDLE; harq_process->round = 0; dlsch->harq_ack[subframe].ack = 1; dlsch->harq_ack[subframe].harq_id = harq_pid; dlsch->harq_ack[subframe].send_harq_status = 1; //LOG_I(PHY,"[UE %d] DLSCH: Setting ACK for SFN/SF %d/%d (pid %d, status %d, round %d, TBS %d, mcs %d)\n", - // phy_vars_ue->Mod_id, frame, subframe, harq_pid, harq_process->status, harq_process->round,harq_process->TBS,harq_process->mcs); + // phy_vars_ue->Mod_id, frame, subframe, harq_pid, harq_process->status, harq_process->round,harq_process->TBS,harq_process->mcs); - if(is_crnti) - { - LOG_D(PHY,"[UE %d] DLSCH: Setting ACK for subframe %d (pid %d, round %d, TBS %d)\n",phy_vars_ue->Mod_id,subframe,harq_pid,harq_process->round,harq_process->TBS); + if(is_crnti) { + LOG_D(PHY,"[UE %d] DLSCH: Setting ACK for subframe %d (pid %d, round %d, TBS %d)\n",phy_vars_ue->Mod_id,subframe,harq_pid,harq_process->round,harq_process->TBS); } - //LOG_D(PHY,"[UE %d] DLSCH: Setting ACK for subframe %d (pid %d, round %d)\n",phy_vars_ue->Mod_id,subframe,harq_pid,harq_process->round); + //LOG_D(PHY,"[UE %d] DLSCH: Setting ACK for subframe %d (pid %d, round %d)\n",phy_vars_ue->Mod_id,subframe,harq_pid,harq_process->round); } // Reassembly of Transport block here @@ -706,24 +668,20 @@ decoder_if_t *tc; } dlsch->last_iteration_cnt = ret; - return(ret); } int dlsch_encoding_SIC(PHY_VARS_UE *ue, - unsigned char *a, - uint8_t num_pdcch_symbols, - LTE_eNB_DLSCH_t *dlsch, - int frame, - uint8_t subframe, - time_stats_t *rm_stats, - time_stats_t *te_stats, - time_stats_t *i_stats) -{ - + unsigned char *a, + uint8_t num_pdcch_symbols, + LTE_eNB_DLSCH_t *dlsch, + int frame, + uint8_t subframe, + time_stats_t *rm_stats, + time_stats_t *te_stats, + time_stats_t *i_stats) { unsigned int G; unsigned int crc=1; - LTE_DL_FRAME_PARMS *frame_parms = &ue->frame_parms; unsigned char harq_pid = ue->dlsch[subframe&2][0][0]->rnti; unsigned short nb_rb = dlsch->harq_processes[harq_pid]->nb_rb; @@ -732,9 +690,7 @@ int dlsch_encoding_SIC(PHY_VARS_UE *ue, unsigned int Kr=0,Kr_bytes,r,r_offset=0; // unsigned short m=dlsch->harq_processes[harq_pid]->mcs; uint8_t beamforming_mode=0; - VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_ENB_DLSCH_ENCODING, VCD_FUNCTION_IN); - A = dlsch->harq_processes[harq_pid]->TBS; //6228 // printf("Encoder: A: %d\n",A); mod_order = dlsch->harq_processes[harq_pid]->Qm; @@ -745,13 +701,13 @@ int dlsch_encoding_SIC(PHY_VARS_UE *ue, beamforming_mode = 8; else if(dlsch->harq_processes[harq_pid]->mimo_mode == TM9_10) beamforming_mode = 9; - G = get_G(frame_parms,nb_rb,dlsch->harq_processes[harq_pid]->rb_alloc,mod_order,dlsch->harq_processes[harq_pid]->Nl,num_pdcch_symbols,frame,subframe,beamforming_mode); + G = get_G(frame_parms,nb_rb,dlsch->harq_processes[harq_pid]->rb_alloc,mod_order,dlsch->harq_processes[harq_pid]->Nl,num_pdcch_symbols,frame,subframe,beamforming_mode); // if (dlsch->harq_processes[harq_pid]->Ndi == 1) { // this is a new packet if (dlsch->harq_processes[harq_pid]->round == 0) { // this is a new packet #ifdef DEBUG_DLSCH_CODING - printf("SIC encoding thinks this is a new packet \n"); + printf("SIC encoding thinks this is a new packet \n"); #endif /* int i; @@ -763,11 +719,10 @@ int dlsch_encoding_SIC(PHY_VARS_UE *ue, // Add 24-bit crc (polynomial A) to payload crc = crc24a(a, A)>>8; - a[A>>3] = ((uint8_t*)&crc)[2]; - a[1+(A>>3)] = ((uint8_t*)&crc)[1]; - a[2+(A>>3)] = ((uint8_t*)&crc)[0]; + a[A>>3] = ((uint8_t *)&crc)[2]; + a[1+(A>>3)] = ((uint8_t *)&crc)[1]; + a[2+(A>>3)] = ((uint8_t *)&crc)[0]; // printf("CRC %x (A %d)\n",crc,A); - dlsch->harq_processes[harq_pid]->B = A+24; // dlsch->harq_processes[harq_pid]->b = a; memcpy(dlsch->harq_processes[harq_pid]->b,a,(A/8)+4); @@ -784,25 +739,20 @@ int dlsch_encoding_SIC(PHY_VARS_UE *ue, return(-1); for (r=0; r<dlsch->harq_processes[harq_pid]->C; r++) { - if (r<dlsch->harq_processes[harq_pid]->Cminus) Kr = dlsch->harq_processes[harq_pid]->Kminus; else Kr = dlsch->harq_processes[harq_pid]->Kplus; Kr_bytes = Kr>>3; - #ifdef DEBUG_DLSCH_CODING - printf("Generating Code Segment %d (%d bits)\n",r,Kr); + printf("Generating Code Segment %u (%u bits)\n",r,Kr); // generate codewords - - printf("bits_per_codeword (Kr)= %d, A %d\n",Kr,A); + printf("bits_per_codeword (Kr)= %u, A %u\n",Kr,A); printf("N_RB = %d\n",nb_rb); printf("Ncp %d\n",frame_parms->Ncp); printf("mod_order %d\n",mod_order); #endif - - start_meas(te_stats); encoder(dlsch->harq_processes[harq_pid]->c[r], Kr>>3, @@ -823,7 +773,6 @@ int dlsch_encoding_SIC(PHY_VARS_UE *ue, dlsch->harq_processes[harq_pid]->w[r]); stop_meas(i_stats); } - } // Fill in the "e"-sequence from 36-212, V8.6 2009-03, p. 16-17 (for each "e") and concatenate the @@ -831,13 +780,12 @@ int dlsch_encoding_SIC(PHY_VARS_UE *ue, for (r=0; r<dlsch->harq_processes[harq_pid]->C; r++) { #ifdef DEBUG_DLSCH_CODING - printf("Rate Matching, Code segment %d (coded bits (G) %d,unpunctured/repeated bits per code segment %d,mod_order %d, nb_rb %d)...\n", - r, - G, - Kr*3, - mod_order,nb_rb); + printf("Rate Matching, Code segment %u (coded bits (G) %u,unpunctured/repeated bits per code segment %u,mod_order %d, nb_rb %d)...\n", + r, + G, + Kr*3, + mod_order,nb_rb); #endif - start_meas(rm_stats); #ifdef DEBUG_DLSCH_CODING printf("rvidx in SIC encoding = %d\n", dlsch->harq_processes[harq_pid]->rvidx); @@ -866,6 +814,5 @@ int dlsch_encoding_SIC(PHY_VARS_UE *ue, } VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_ENB_DLSCH_ENCODING, VCD_FUNCTION_OUT); - return(0); } diff --git a/openair1/PHY/LTE_UE_TRANSPORT/dlsch_demodulation.c b/openair1/PHY/LTE_UE_TRANSPORT/dlsch_demodulation.c index ace145930638a4315910c46a33b5cdc3861b20da..aafd579899ad023de7cbc7e0c843b75bab09215d 100644 --- a/openair1/PHY/LTE_UE_TRANSPORT/dlsch_demodulation.c +++ b/openair1/PHY/LTE_UE_TRANSPORT/dlsch_demodulation.c @@ -42,11 +42,11 @@ #include <string.h> #include <linux/version.h> #if RHEL_RELEASE_CODE >= 1796 -#include <lapacke/lapacke_utils.h> -#include <lapacke/lapacke.h> + #include <lapacke/lapacke_utils.h> + #include <lapacke/lapacke.h> #else -#include <lapacke_utils.h> -#include <lapacke.h> + #include <lapacke_utils.h> + #include <lapacke.h> #endif #include <cblas.h> #include "linear_preprocessing_rec.h" @@ -72,10 +72,12 @@ int16_t interf_unaw_shift = 13; // [MCS][i_mod (0,1,2) = (2,4,6)] unsigned char offset_mumimo_llr_drange_fix=0; //inferference-free case -unsigned char interf_unaw_shift_tm4_mcs[29]={5, 3, 4, 3, 3, 2, 1, 1, 2, 0, 1, 1, 1, 1, 0, 0, - 1, 1, 1, 1, 0, 2, 1, 0, 1, 0, 1, 0, 0} ; -unsigned char interf_unaw_shift_tm1_mcs[29]={5, 5, 4, 3, 3, 3, 2, 2, 4, 4, 2, 3, 3, 3, 1, 1, - 0, 1, 1, 2, 5, 4, 4, 6, 5, 1, 0, 5, 6} ; // mcs 21, 26, 28 seem to be errorneous +unsigned char interf_unaw_shift_tm4_mcs[29]= {5, 3, 4, 3, 3, 2, 1, 1, 2, 0, 1, 1, 1, 1, 0, 0, + 1, 1, 1, 1, 0, 2, 1, 0, 1, 0, 1, 0, 0 + } ; +unsigned char interf_unaw_shift_tm1_mcs[29]= {5, 5, 4, 3, 3, 3, 2, 2, 4, 4, 2, 3, 3, 3, 1, 1, + 0, 1, 1, 2, 5, 4, 4, 6, 5, 1, 0, 5, 6 + } ; // mcs 21, 26, 28 seem to be errorneous /* //original values from sebastion + same hand tuning @@ -83,14 +85,14 @@ unsigned char offset_mumimo_llr_drange[29][3]={{8,8,8},{7,7,7},{7,7,7},{7,7,7},{ {5,5,4},{5,5,5},{5,5,5},{3,3,3},{2,2,2},{2,2,2},{2,2,2}, // 16-QAM {2,2,1},{3,3,3},{3,3,3},{3,3,1},{2,2,2},{2,2,2},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0},{0,0,0}}; //64-QAM */ - /* - //first optimization try - unsigned char offset_mumimo_llr_drange[29][3]={{7, 8, 7},{6, 6, 7},{6, 6, 7},{6, 6, 6},{5, 6, 6},{5, 5, 6},{5, 5, 6},{4, 5, 4},{4, 3, 4},{3, 2, 2},{6, 5, 5},{5, 4, 4},{5, 5, 4},{3, 3, 2},{2, 2, 1},{2, 1, 1},{2, 2, 2},{3, 3, 3},{3, 3, 2},{3, 3, 2},{3, 2, 1},{2, 2, 2},{2, 2, 2},{0, 0, 0},{0, 0, 0},{0, 0, 0},{0, 0, 0},{0, 0, 0}}; - */ - //second optimization try - /* - unsigned char offset_mumimo_llr_drange[29][3]={{5, 8, 7},{4, 6, 8},{3, 6, 7},{7, 7, 6},{4, 7, 8},{4, 7, 4},{6, 6, 6},{3, 6, 6},{3, 6, 6},{1, 3, 4},{1, 1, 0},{3, 3, 2},{3, 4, 1},{4, 0, 1},{4, 2, 2},{3, 1, 2},{2, 1, 0},{2, 1, 1},{1, 0, 1},{1, 0, 1},{0, 0, 0},{1, 0, 0},{0, 0, 0},{0, 1, 0},{1, 0, 0},{0, 0, 0},{0, 0, 0},{0, 0, 0},{0, 0, 0}}; w - */ +/* +//first optimization try +unsigned char offset_mumimo_llr_drange[29][3]={{7, 8, 7},{6, 6, 7},{6, 6, 7},{6, 6, 6},{5, 6, 6},{5, 5, 6},{5, 5, 6},{4, 5, 4},{4, 3, 4},{3, 2, 2},{6, 5, 5},{5, 4, 4},{5, 5, 4},{3, 3, 2},{2, 2, 1},{2, 1, 1},{2, 2, 2},{3, 3, 3},{3, 3, 2},{3, 3, 2},{3, 2, 1},{2, 2, 2},{2, 2, 2},{0, 0, 0},{0, 0, 0},{0, 0, 0},{0, 0, 0},{0, 0, 0}}; +*/ +//second optimization try +/* + unsigned char offset_mumimo_llr_drange[29][3]={{5, 8, 7},{4, 6, 8},{3, 6, 7},{7, 7, 6},{4, 7, 8},{4, 7, 4},{6, 6, 6},{3, 6, 6},{3, 6, 6},{1, 3, 4},{1, 1, 0},{3, 3, 2},{3, 4, 1},{4, 0, 1},{4, 2, 2},{3, 1, 2},{2, 1, 0},{2, 1, 1},{1, 0, 1},{1, 0, 1},{0, 0, 0},{1, 0, 0},{0, 0, 0},{0, 1, 0},{1, 0, 0},{0, 0, 0},{0, 0, 0},{0, 0, 0},{0, 0, 0}}; w +*/ unsigned char offset_mumimo_llr_drange[29][3]= {{0, 6, 5},{0, 4, 5},{0, 4, 5},{0, 5, 4},{0, 5, 6},{0, 5, 3},{0, 4, 4},{0, 4, 4},{0, 3, 3},{0, 1, 2},{1, 1, 0},{1, 3, 2},{3, 4, 1},{2, 0, 0},{2, 2, 2},{1, 1, 1},{2, 1, 0},{2, 1, 1},{1, 0, 1},{1, 0, 1},{0, 0, 0},{1, 0, 0},{0, 0, 0},{0, 1, 0},{1, 0, 0},{0, 0, 0},{0, 0, 0},{0, 0, 0},{0, 0, 0}}; @@ -107,111 +109,99 @@ int rx_pdsch(PHY_VARS_UE *ue, unsigned char first_symbol_flag, RX_type_t rx_type, unsigned char i_mod, - unsigned char harq_pid) -{ - + unsigned char harq_pid) { LTE_UE_COMMON *common_vars = &ue->common_vars; LTE_UE_PDSCH **pdsch_vars; LTE_DL_FRAME_PARMS *frame_parms = &ue->frame_parms; PHY_MEASUREMENTS *measurements = &ue->measurements; LTE_UE_DLSCH_t **dlsch; - int avg[4]; int avg_0[2]; int avg_1[2]; unsigned short mmse_flag=0; - #if UE_TIMING_TRACE uint8_t slot = 0; #endif - unsigned char aatx,aarx; - unsigned short nb_rb = 0, round; int avgs = 0, rb; LTE_DL_UE_HARQ_t *dlsch0_harq,*dlsch1_harq = 0; - uint8_t beamforming_mode; uint32_t *rballoc; - int32_t **rxdataF_comp_ptr; int32_t **dl_ch_mag_ptr; int32_t codeword_TB0 = -1; int32_t codeword_TB1 = -1; - - switch (type) { - case SI_PDSCH: - pdsch_vars = &ue->pdsch_vars_SI[eNB_id]; - dlsch = &ue->dlsch_SI[eNB_id]; - dlsch0_harq = dlsch[0]->harq_processes[harq_pid]; - beamforming_mode = 0; - break; - - case RA_PDSCH: - pdsch_vars = &ue->pdsch_vars_ra[eNB_id]; - dlsch = &ue->dlsch_ra[eNB_id]; - dlsch0_harq = dlsch[0]->harq_processes[harq_pid]; - beamforming_mode = 0; - break; - - case PDSCH: - pdsch_vars = ue->pdsch_vars[ue->current_thread_id[subframe]]; - dlsch = ue->dlsch[ue->current_thread_id[subframe]][eNB_id]; - //printf("status TB0 = %d, status TB1 = %d \n", dlsch[0]->harq_processes[harq_pid]->status, dlsch[1]->harq_processes[harq_pid]->status); - LOG_D(PHY,"AbsSubframe %d.%d / Sym %d harq_pid %d, harq status %d.%d \n", - frame,subframe,symbol,harq_pid, - dlsch[0]->harq_processes[harq_pid]->status, - dlsch[1]->harq_processes[harq_pid]->status); - - if ((dlsch[0]->harq_processes[harq_pid]->status == ACTIVE) && - (dlsch[1]->harq_processes[harq_pid]->status == ACTIVE)){ - codeword_TB0 = dlsch[0]->harq_processes[harq_pid]->codeword; - codeword_TB1 = dlsch[1]->harq_processes[harq_pid]->codeword; - dlsch0_harq = dlsch[codeword_TB0]->harq_processes[harq_pid]; - dlsch1_harq = dlsch[codeword_TB1]->harq_processes[harq_pid]; + case SI_PDSCH: + pdsch_vars = &ue->pdsch_vars_SI[eNB_id]; + dlsch = &ue->dlsch_SI[eNB_id]; + dlsch0_harq = dlsch[0]->harq_processes[harq_pid]; + beamforming_mode = 0; + break; + + case RA_PDSCH: + pdsch_vars = &ue->pdsch_vars_ra[eNB_id]; + dlsch = &ue->dlsch_ra[eNB_id]; + dlsch0_harq = dlsch[0]->harq_processes[harq_pid]; + beamforming_mode = 0; + break; + + case PDSCH: + pdsch_vars = ue->pdsch_vars[ue->current_thread_id[subframe]]; + dlsch = ue->dlsch[ue->current_thread_id[subframe]][eNB_id]; + //printf("status TB0 = %d, status TB1 = %d \n", dlsch[0]->harq_processes[harq_pid]->status, dlsch[1]->harq_processes[harq_pid]->status); + LOG_D(PHY,"AbsSubframe %d.%d / Sym %d harq_pid %d, harq status %d.%d \n", + frame,subframe,symbol,harq_pid, + dlsch[0]->harq_processes[harq_pid]->status, + dlsch[1]->harq_processes[harq_pid]->status); + + if ((dlsch[0]->harq_processes[harq_pid]->status == ACTIVE) && + (dlsch[1]->harq_processes[harq_pid]->status == ACTIVE)) { + codeword_TB0 = dlsch[0]->harq_processes[harq_pid]->codeword; + codeword_TB1 = dlsch[1]->harq_processes[harq_pid]->codeword; + dlsch0_harq = dlsch[codeword_TB0]->harq_processes[harq_pid]; + dlsch1_harq = dlsch[codeword_TB1]->harq_processes[harq_pid]; #ifdef DEBUG_HARQ - printf("[DEMOD] I am assuming both TBs are active\n"); + printf("[DEMOD] I am assuming both TBs are active\n"); #endif - } - else if ((dlsch[0]->harq_processes[harq_pid]->status == ACTIVE) && - (dlsch[1]->harq_processes[harq_pid]->status != ACTIVE) ) { - codeword_TB0 = dlsch[0]->harq_processes[harq_pid]->codeword; - dlsch0_harq = dlsch[0]->harq_processes[harq_pid]; - dlsch1_harq = NULL; - codeword_TB1 = -1; + } else if ((dlsch[0]->harq_processes[harq_pid]->status == ACTIVE) && + (dlsch[1]->harq_processes[harq_pid]->status != ACTIVE) ) { + codeword_TB0 = dlsch[0]->harq_processes[harq_pid]->codeword; + dlsch0_harq = dlsch[0]->harq_processes[harq_pid]; + dlsch1_harq = NULL; + codeword_TB1 = -1; #ifdef DEBUG_HARQ - printf("[DEMOD] I am assuming only TB0 is active\n"); + printf("[DEMOD] I am assuming only TB0 is active\n"); #endif - } - else if ((dlsch[0]->harq_processes[harq_pid]->status != ACTIVE) && - (dlsch[1]->harq_processes[harq_pid]->status == ACTIVE) ){ - codeword_TB1 = dlsch[1]->harq_processes[harq_pid]->codeword; - dlsch0_harq = dlsch[1]->harq_processes[harq_pid]; - dlsch1_harq = NULL; - codeword_TB0 = -1; + } else if ((dlsch[0]->harq_processes[harq_pid]->status != ACTIVE) && + (dlsch[1]->harq_processes[harq_pid]->status == ACTIVE) ) { + codeword_TB1 = dlsch[1]->harq_processes[harq_pid]->codeword; + dlsch0_harq = dlsch[1]->harq_processes[harq_pid]; + dlsch1_harq = NULL; + codeword_TB0 = -1; #ifdef DEBUG_HARQ - printf("[DEMOD] I am assuming only TB1 is active, it is in cw %d\n", dlsch0_harq->codeword); + printf("[DEMOD] I am assuming only TB1 is active, it is in cw %d\n", dlsch0_harq->codeword); #endif - } - else { - LOG_E(PHY,"[UE][FATAL] Frame %d subframe %d: no active DLSCH\n",ue->proc.proc_rxtx[0].frame_rx,subframe); - return(-1); - } - beamforming_mode = ue->transmission_mode[eNB_id]<7?0:ue->transmission_mode[eNB_id]; - break; + } else { + LOG_E(PHY,"[UE][FATAL] Frame %d subframe %d: no active DLSCH\n",ue->proc.proc_rxtx[0].frame_rx,subframe); + return(-1); + } - default: - LOG_E(PHY,"[UE][FATAL] Frame %d subframe %d: Unknown PDSCH format %d\n",ue->proc.proc_rxtx[0].frame_rx,subframe,type); - return(-1); - break; + beamforming_mode = ue->transmission_mode[eNB_id]<7?0:ue->transmission_mode[eNB_id]; + break; + + default: + LOG_E(PHY,"[UE][FATAL] Frame %d subframe %d: Unknown PDSCH format %d\n",ue->proc.proc_rxtx[0].frame_rx,subframe,type); + return(-1); + break; } + #ifdef DEBUG_HARQ printf("[DEMOD] MIMO mode = %d\n", dlsch0_harq->mimo_mode); printf("[DEMOD] cw for TB0 = %d, cw for TB1 = %d\n", codeword_TB0, codeword_TB1); #endif - DevAssert(dlsch0_harq); round = dlsch0_harq->round; //printf("round = %d\n", round); @@ -247,15 +237,14 @@ int rx_pdsch(PHY_VARS_UE *ue, else rballoc = dlsch0_harq->rb_alloc_even; - if (dlsch0_harq->mimo_mode>DUALSTREAM_PUSCH_PRECODING) { LOG_E(PHY,"This transmission mode is not yet supported!\n"); return(-1); } - if ((dlsch0_harq->mimo_mode==LARGE_CDD) || ((dlsch0_harq->mimo_mode>=DUALSTREAM_UNIFORM_PRECODING1) && (dlsch0_harq->mimo_mode<=DUALSTREAM_PUSCH_PRECODING))) { DevAssert(dlsch1_harq); + if (eNB_id!=eNB_id_i) { LOG_E(PHY,"TM3/TM4 requires to set eNB_id==eNB_id_i!\n"); return(-1); @@ -263,12 +252,12 @@ int rx_pdsch(PHY_VARS_UE *ue, } #if UE_TIMING_TRACE - if(symbol > ue->frame_parms.symbols_per_tti>>1) - { - slot = 1; + + if(symbol > ue->frame_parms.symbols_per_tti>>1) { + slot = 1; } -#endif +#endif #ifdef DEBUG_HARQ printf("Demod dlsch0_harq->pmi_alloc %d\n", dlsch0_harq->pmi_alloc); #endif @@ -277,7 +266,6 @@ int rx_pdsch(PHY_VARS_UE *ue, #ifdef DEBUG_DLSCH_MOD LOG_I(PHY,"dlsch: using pmi %x (%p), rb_alloc %x\n",pmi2hex_2Ar1(dlsch0_harq->pmi_alloc),dlsch[0],dlsch0_harq->rb_alloc_even[0]); #endif - #if UE_TIMING_TRACE start_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]); #endif @@ -294,15 +282,17 @@ int rx_pdsch(PHY_VARS_UE *ue, frame_parms, dlsch0_harq->mimo_mode); #ifdef DEBUG_DLSCH_MOD - printf("dlsch: using pmi %lx, rb_alloc %x, pmi_ext ",pmi2hex_2Ar1(dlsch0_harq->pmi_alloc),*rballoc); - for (rb=0;rb<nb_rb;rb++) - printf("%d",pdsch_vars[eNB_id]->pmi_ext[rb]); - printf("\n"); + printf("dlsch: using pmi %lx, rb_alloc %x, pmi_ext ",pmi2hex_2Ar1(dlsch0_harq->pmi_alloc),*rballoc); + + for (rb=0; rb<nb_rb; rb++) + printf("%d",pdsch_vars[eNB_id]->pmi_ext[rb]); + + printf("\n"); #endif - if (rx_type >= rx_IC_single_stream) { + if (rx_type >= rx_IC_single_stream) { if (eNB_id_i<ue->n_connected_eNB) // we are in TM5 - nb_rb = dlsch_extract_rbs_dual(common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[subframe]].rxdataF, + nb_rb = dlsch_extract_rbs_dual(common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[subframe]].rxdataF, common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[subframe]].dl_ch_estimates[eNB_id_i], pdsch_vars[eNB_id_i]->rxdataF_ext, pdsch_vars[eNB_id_i]->dl_ch_estimates_ext, @@ -341,8 +331,8 @@ int rx_pdsch(PHY_VARS_UE *ue, ue->high_speed_flag, frame_parms); - if (rx_type==rx_IC_single_stream) { - if (eNB_id_i<ue->n_connected_eNB) + if (rx_type==rx_IC_single_stream) { + if (eNB_id_i<ue->n_connected_eNB) nb_rb = dlsch_extract_rbs_single(common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[subframe]].rxdataF, common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[subframe]].dl_ch_estimates[eNB_id_i], pdsch_vars[eNB_id_i]->rxdataF_ext, @@ -377,7 +367,6 @@ int rx_pdsch(PHY_VARS_UE *ue, subframe, ue->high_speed_flag, frame_parms); - } else if(beamforming_mode>7) { LOG_W(PHY,"dlsch_demodulation: beamforming mode not supported yet.\n"); } @@ -388,25 +377,21 @@ int rx_pdsch(PHY_VARS_UE *ue, return(-1); } - #if UE_TIMING_TRACE - stop_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]); + stop_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]); #if DISABLE_LOG_X - printf("[AbsSFN %d.%d] Slot%d Symbol %d Flag %d type %d: Pilot/Data extraction %5.2f \n",frame,subframe,slot, - symbol,ue->high_speed_flag,type,symbol,ue->generic_stat_bis[ue->current_thread_id[subframe]][slot].p_time/(cpuf*1000.0)); + printf("[AbsSFN %d.%d] Slot%d Symbol %d Flag %d type %d: Pilot/Data extraction %5.2f \n",frame,subframe,slot, + symbol,ue->high_speed_flag,type,ue->generic_stat_bis[ue->current_thread_id[subframe]][slot].p_time/(cpuf*1000.0)); #else - LOG_I(PHY, "[AbsSFN %d.%d] Slot%d Symbol %d Flag %d type %d: Pilot/Data extraction %5.2f \n",frame,subframe,slot,symbol, - ue->high_speed_flag,type,ue->generic_stat_bis[ue->current_thread_id[subframe]][slot].p_time/(cpuf*1000.0)); + LOG_I(PHY, "[AbsSFN %d.%d] Slot%d Symbol %d Flag %d type %d: Pilot/Data extraction %5.2f \n",frame,subframe,slot,symbol, + ue->high_speed_flag,type,ue->generic_stat_bis[ue->current_thread_id[subframe]][slot].p_time/(cpuf*1000.0)); #endif #endif - - #if UE_TIMING_TRACE - start_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]); + start_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]); #endif aatx = frame_parms->nb_antenna_ports_eNB; aarx = frame_parms->nb_antennas_rx; - dlsch_scale_channel(pdsch_vars[eNB_id]->dl_ch_estimates_ext, frame_parms, dlsch, @@ -417,8 +402,7 @@ int rx_pdsch(PHY_VARS_UE *ue, (rx_type==rx_IC_single_stream) && (eNB_id_i==ue->n_connected_eNB) && (dlsch0_harq->dl_power_off==0) - ) // TM5 two-user - { + ) { // TM5 two-user dlsch_scale_channel(pdsch_vars[eNB_id_i]->dl_ch_estimates_ext, frame_parms, dlsch, @@ -427,109 +411,100 @@ int rx_pdsch(PHY_VARS_UE *ue, } #if UE_TIMING_TRACE - stop_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]); + stop_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]); #if DISABLE_LOG_X - printf("[AbsSFN %d.%d] Slot%d Symbol %d: Channel Scale %5.2f \n",frame,subframe,slot,symbol,ue->generic_stat_bis[ue->current_thread_id[subframe]][slot].p_time/(cpuf*1000.0)); + printf("[AbsSFN %d.%d] Slot%d Symbol %d: Channel Scale %5.2f \n",frame,subframe,slot,symbol,ue->generic_stat_bis[ue->current_thread_id[subframe]][slot].p_time/(cpuf*1000.0)); #else - LOG_I(PHY, "[AbsSFN %d.%d] Slot%d Symbol %d: Channel Scale %5.2f \n",frame,subframe,slot,symbol,ue->generic_stat_bis[ue->current_thread_id[subframe]][slot].p_time/(cpuf*1000.0)); + LOG_I(PHY, "[AbsSFN %d.%d] Slot%d Symbol %d: Channel Scale %5.2f \n",frame,subframe,slot,symbol,ue->generic_stat_bis[ue->current_thread_id[subframe]][slot].p_time/(cpuf*1000.0)); #endif #endif - #if UE_TIMING_TRACE - start_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]); + start_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]); #endif + if (first_symbol_flag==1) { - if (beamforming_mode==0){ + if (beamforming_mode==0) { if (dlsch0_harq->mimo_mode<LARGE_CDD) { dlsch_channel_level(pdsch_vars[eNB_id]->dl_ch_estimates_ext, - frame_parms, - avg, - symbol, - nb_rb); + frame_parms, + avg, + symbol, + nb_rb); avgs = 0; - for (aatx=0;aatx<frame_parms->nb_antenna_ports_eNB;aatx++) - for (aarx=0;aarx<frame_parms->nb_antennas_rx;aarx++) + + for (aatx=0; aatx<frame_parms->nb_antenna_ports_eNB; aatx++) + for (aarx=0; aarx<frame_parms->nb_antennas_rx; aarx++) avgs = cmax(avgs,avg[(aatx<<1)+aarx]); pdsch_vars[eNB_id]->log2_maxh = (log2_approx(avgs)/2)+1; - } - else if ((dlsch0_harq->mimo_mode == LARGE_CDD) || - ((dlsch0_harq->mimo_mode >=DUALSTREAM_UNIFORM_PRECODING1) && - (dlsch0_harq->mimo_mode <=DUALSTREAM_PUSCH_PRECODING))) - { - dlsch_channel_level_TM34(pdsch_vars[eNB_id]->dl_ch_estimates_ext, - frame_parms, - pdsch_vars[eNB_id]->pmi_ext, - avg_0, - avg_1, - symbol, - nb_rb, - mmse_flag, - dlsch0_harq->mimo_mode); - - LOG_D(PHY,"Channel Level TM34 avg_0 %d, avg_1 %d, rx_type %d, rx_standard %d, dlsch_demod_shift %d \n", avg_0[0], + } else if ((dlsch0_harq->mimo_mode == LARGE_CDD) || + ((dlsch0_harq->mimo_mode >=DUALSTREAM_UNIFORM_PRECODING1) && + (dlsch0_harq->mimo_mode <=DUALSTREAM_PUSCH_PRECODING))) { + dlsch_channel_level_TM34(pdsch_vars[eNB_id]->dl_ch_estimates_ext, + frame_parms, + pdsch_vars[eNB_id]->pmi_ext, + avg_0, + avg_1, + symbol, + nb_rb, + mmse_flag, + dlsch0_harq->mimo_mode); + LOG_D(PHY,"Channel Level TM34 avg_0 %d, avg_1 %d, rx_type %d, rx_standard %d, dlsch_demod_shift %d \n", avg_0[0], avg_1[0], rx_type, rx_standard, dlsch_demod_shift); + if (rx_type>rx_standard) { avg_0[0] = (log2_approx(avg_0[0])/2) + dlsch_demod_shift;// + 2 ;//+ 4; avg_1[0] = (log2_approx(avg_1[0])/2) + dlsch_demod_shift;// + 2 ;//+ 4; pdsch_vars[eNB_id]->log2_maxh0 = cmax(avg_0[0],0); pdsch_vars[eNB_id]->log2_maxh1 = cmax(avg_1[0],0); - // printf("dlsch_demod_shift %d\n", dlsch_demod_shift); - } - else { + // printf("dlsch_demod_shift %d\n", dlsch_demod_shift); + } else { avg_0[0] = (log2_approx(avg_0[0])/2) - 13 + interf_unaw_shift; avg_1[0] = (log2_approx(avg_1[0])/2) - 13 + interf_unaw_shift; pdsch_vars[eNB_id]->log2_maxh0 = cmax(avg_0[0],0); pdsch_vars[eNB_id]->log2_maxh1 = cmax(avg_1[0],0); } - } - else if (dlsch0_harq->mimo_mode<DUALSTREAM_UNIFORM_PRECODING1) {// single-layer precoding (TM5, TM6) + } else if (dlsch0_harq->mimo_mode<DUALSTREAM_UNIFORM_PRECODING1) { // single-layer precoding (TM5, TM6) if ((rx_type==rx_IC_single_stream) && (eNB_id_i==ue->n_connected_eNB) && (dlsch0_harq->dl_power_off==0)) { - dlsch_channel_level_TM56(pdsch_vars[eNB_id]->dl_ch_estimates_ext, - frame_parms, - pdsch_vars[eNB_id]->pmi_ext, - avg, - symbol, - nb_rb); - avg[0] = log2_approx(avg[0]) - 13 + offset_mumimo_llr_drange[dlsch0_harq->mcs][(i_mod>>1)-1]; - pdsch_vars[eNB_id]->log2_maxh = cmax(avg[0],0); - - } - else if (dlsch0_harq->dl_power_off==1) { //TM6 - - dlsch_channel_level(pdsch_vars[eNB_id]->dl_ch_estimates_ext, + dlsch_channel_level_TM56(pdsch_vars[eNB_id]->dl_ch_estimates_ext, frame_parms, + pdsch_vars[eNB_id]->pmi_ext, avg, symbol, nb_rb); - + avg[0] = log2_approx(avg[0]) - 13 + offset_mumimo_llr_drange[dlsch0_harq->mcs][(i_mod>>1)-1]; + pdsch_vars[eNB_id]->log2_maxh = cmax(avg[0],0); + } else if (dlsch0_harq->dl_power_off==1) { //TM6 + dlsch_channel_level(pdsch_vars[eNB_id]->dl_ch_estimates_ext, + frame_parms, + avg, + symbol, + nb_rb); avgs = 0; - for (aatx=0;aatx<frame_parms->nb_antenna_ports_eNB;aatx++) - for (aarx=0;aarx<frame_parms->nb_antennas_rx;aarx++) + + for (aatx=0; aatx<frame_parms->nb_antenna_ports_eNB; aatx++) + for (aarx=0; aarx<frame_parms->nb_antennas_rx; aarx++) avgs = cmax(avgs,avg[(aatx<<1)+aarx]); pdsch_vars[eNB_id]->log2_maxh = (log2_approx(avgs)/2) + 1; pdsch_vars[eNB_id]->log2_maxh++; - } } - - } - else if (beamforming_mode==7) - dlsch_channel_level_TM7(pdsch_vars[eNB_id]->dl_bf_ch_estimates_ext, + } else if (beamforming_mode==7) + dlsch_channel_level_TM7(pdsch_vars[eNB_id]->dl_bf_ch_estimates_ext, frame_parms, avg, symbol, nb_rb); + #ifdef UE_DEBUG_TRACE LOG_D(PHY,"[DLSCH] AbsSubframe %d.%d log2_maxh = %d [log2_maxh0 %d log2_maxh1 %d] (%d,%d)\n", - frame%1024,subframe, pdsch_vars[eNB_id]->log2_maxh, - pdsch_vars[eNB_id]->log2_maxh0, - pdsch_vars[eNB_id]->log2_maxh1, - avg[0],avgs); + frame%1024,subframe, pdsch_vars[eNB_id]->log2_maxh, + pdsch_vars[eNB_id]->log2_maxh0, + pdsch_vars[eNB_id]->log2_maxh1, + avg[0],avgs); //LOG_D(PHY,"[DLSCH] mimo_mode = %d\n", dlsch0_harq->mimo_mode); #endif - //wait until pdcch is decoded //proc->channel_level = 1; } @@ -542,39 +517,36 @@ int rx_pdsch(PHY_VARS_UE *ue, wait++; } */ - #if T_TRACER - if (type == PDSCH) - { - T(T_UE_PHY_PDSCH_ENERGY, T_INT(eNB_id), T_INT(frame%1024), T_INT(subframe), - T_INT(avg[0]), T_INT(avg[1]), T_INT(avg[2]), T_INT(avg[3])); - } -#endif + if (type == PDSCH) { + T(T_UE_PHY_PDSCH_ENERGY, T_INT(eNB_id), T_INT(frame%1024), T_INT(subframe), + T_INT(avg[0]), T_INT(avg[1]), T_INT(avg[2]), T_INT(avg[3])); + } + +#endif #if UE_TIMING_TRACE - stop_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]); + stop_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]); #if DISABLE_LOG_X - printf("[AbsSFN %d.%d] Slot%d Symbol %d first_symbol_flag %d: Channel Level %5.2f \n",frame,subframe,slot,symbol,first_symbol_flag,ue->generic_stat_bis[ue->current_thread_id[subframe]][slot].p_time/(cpuf*1000.0)); + printf("[AbsSFN %d.%d] Slot%d Symbol %d first_symbol_flag %d: Channel Level %5.2f \n",frame,subframe,slot,symbol,first_symbol_flag, + ue->generic_stat_bis[ue->current_thread_id[subframe]][slot].p_time/(cpuf*1000.0)); #else - LOG_I(PHY, "[AbsSFN %d.%d] Slot%d Symbol %d first_symbol_flag %d: Channel Level %5.2f \n",frame,subframe,slot,symbol,first_symbol_flag,ue->generic_stat_bis[ue->current_thread_id[subframe]][slot].p_time/(cpuf*1000.0)); + LOG_I(PHY, "[AbsSFN %d.%d] Slot%d Symbol %d first_symbol_flag %d: Channel Level %5.2f \n",frame,subframe,slot,symbol,first_symbol_flag, + ue->generic_stat_bis[ue->current_thread_id[subframe]][slot].p_time/(cpuf*1000.0)); #endif #endif - - #if UE_TIMING_TRACE - start_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]); + start_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]); #endif - if (rx_type==rx_IC_dual_stream && mmse_flag==1){ - + if (rx_type==rx_IC_dual_stream && mmse_flag==1) { precode_channel_est(pdsch_vars[eNB_id]->dl_ch_estimates_ext, frame_parms, pdsch_vars[eNB_id], symbol, nb_rb, dlsch0_harq->mimo_mode); - - mmse_processing_oai(pdsch_vars[eNB_id], + mmse_processing_oai(pdsch_vars[eNB_id], frame_parms, measurements, first_symbol_flag, @@ -585,7 +557,7 @@ int rx_pdsch(PHY_VARS_UE *ue, nb_rb); } -// Now channel compensation + // Now channel compensation if (dlsch0_harq->mimo_mode<LARGE_CDD) { dlsch_channel_compensation(pdsch_vars[eNB_id]->rxdataF_ext, pdsch_vars[eNB_id]->dl_ch_estimates_ext, @@ -600,13 +572,14 @@ int rx_pdsch(PHY_VARS_UE *ue, nb_rb, pdsch_vars[eNB_id]->log2_maxh, measurements); // log2_maxh+I0_shift + if (symbol == 5) { - LOG_M("rxF_comp_d.m","rxF_c_d",&pdsch_vars[eNB_id]->rxdataF_comp0[0][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1); + LOG_M("rxF_comp_d.m","rxF_c_d",&pdsch_vars[eNB_id]->rxdataF_comp0[0][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1); } if ((rx_type==rx_IC_single_stream) && (eNB_id_i<ue->n_connected_eNB)) { - dlsch_channel_compensation(pdsch_vars[eNB_id_i]->rxdataF_ext, + dlsch_channel_compensation(pdsch_vars[eNB_id_i]->rxdataF_ext, pdsch_vars[eNB_id_i]->dl_ch_estimates_ext, pdsch_vars[eNB_id_i]->dl_ch_mag0, pdsch_vars[eNB_id_i]->dl_ch_magb0, @@ -619,6 +592,7 @@ int rx_pdsch(PHY_VARS_UE *ue, nb_rb, pdsch_vars[eNB_id]->log2_maxh, measurements); // log2_maxh+I0_shift + if (symbol == 5) { LOG_M("rxF_comp_d.m","rxF_c_d",&pdsch_vars[eNB_id]->rxdataF_comp0[0][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1); LOG_M("rxF_comp_i.m","rxF_c_i",&pdsch_vars[eNB_id_i]->rxdataF_comp0[0][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1); @@ -633,55 +607,58 @@ int rx_pdsch(PHY_VARS_UE *ue, pdsch_vars[eNB_id]->log2_maxh); } } else if ((dlsch0_harq->mimo_mode == LARGE_CDD) || ((dlsch0_harq->mimo_mode >=DUALSTREAM_UNIFORM_PRECODING1) && - (dlsch0_harq->mimo_mode <=DUALSTREAM_PUSCH_PRECODING))){ - dlsch_channel_compensation_TM34(frame_parms, - pdsch_vars[eNB_id], - measurements, - eNB_id, - symbol, - dlsch0_harq->Qm, - dlsch1_harq->Qm, - harq_pid, - dlsch0_harq->round, - dlsch0_harq->mimo_mode, - nb_rb, - mmse_flag, - pdsch_vars[eNB_id]->log2_maxh0, - pdsch_vars[eNB_id]->log2_maxh1); - if (symbol == 5) { - LOG_M("rxF_comp_d00.m","rxF_c_d00",&pdsch_vars[eNB_id]->rxdataF_comp0[0][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);// should be QAM - LOG_M("rxF_comp_d01.m","rxF_c_d01",&pdsch_vars[eNB_id]->rxdataF_comp0[1][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);//should be almost 0 - LOG_M("rxF_comp_d10.m","rxF_c_d10",&pdsch_vars[eNB_id]->rxdataF_comp1[harq_pid][round][0][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);//should be almost 0 - LOG_M("rxF_comp_d11.m","rxF_c_d11",&pdsch_vars[eNB_id]->rxdataF_comp1[harq_pid][round][1][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);//should be QAM - } - // compute correlation between signal and interference channels (rho12 and rho21) - dlsch_dual_stream_correlation(frame_parms, // this is doing h11'*h12 and h21'*h22 + (dlsch0_harq->mimo_mode <=DUALSTREAM_PUSCH_PRECODING))) { + dlsch_channel_compensation_TM34(frame_parms, + pdsch_vars[eNB_id], + measurements, + eNB_id, symbol, + dlsch0_harq->Qm, + dlsch1_harq->Qm, + harq_pid, + dlsch0_harq->round, + dlsch0_harq->mimo_mode, nb_rb, - pdsch_vars[eNB_id]->dl_ch_estimates_ext, - &(pdsch_vars[eNB_id]->dl_ch_estimates_ext[2]), - pdsch_vars[eNB_id]->dl_ch_rho2_ext, - pdsch_vars[eNB_id]->log2_maxh0); - //printf("rho stream1 =%d\n", &pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round] ); - //to be optimized (just take complex conjugate) - dlsch_dual_stream_correlation(frame_parms, // this is doing h12'*h11 and h22'*h21 - symbol, - nb_rb, - &(pdsch_vars[eNB_id]->dl_ch_estimates_ext[2]), - pdsch_vars[eNB_id]->dl_ch_estimates_ext, - pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round], + mmse_flag, + pdsch_vars[eNB_id]->log2_maxh0, pdsch_vars[eNB_id]->log2_maxh1); + + if (symbol == 5) { + LOG_M("rxF_comp_d00.m","rxF_c_d00",&pdsch_vars[eNB_id]->rxdataF_comp0[0][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);// should be QAM + LOG_M("rxF_comp_d01.m","rxF_c_d01",&pdsch_vars[eNB_id]->rxdataF_comp0[1][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);//should be almost 0 + LOG_M("rxF_comp_d10.m","rxF_c_d10",&pdsch_vars[eNB_id]->rxdataF_comp1[harq_pid][round][0][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);//should be almost 0 + LOG_M("rxF_comp_d11.m","rxF_c_d11",&pdsch_vars[eNB_id]->rxdataF_comp1[harq_pid][round][1][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);//should be QAM + } + + // compute correlation between signal and interference channels (rho12 and rho21) + dlsch_dual_stream_correlation(frame_parms, // this is doing h11'*h12 and h21'*h22 + symbol, + nb_rb, + pdsch_vars[eNB_id]->dl_ch_estimates_ext, + &(pdsch_vars[eNB_id]->dl_ch_estimates_ext[2]), + pdsch_vars[eNB_id]->dl_ch_rho2_ext, + pdsch_vars[eNB_id]->log2_maxh0); + //printf("rho stream1 =%d\n", &pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round] ); + //to be optimized (just take complex conjugate) + dlsch_dual_stream_correlation(frame_parms, // this is doing h12'*h11 and h22'*h21 + symbol, + nb_rb, + &(pdsch_vars[eNB_id]->dl_ch_estimates_ext[2]), + pdsch_vars[eNB_id]->dl_ch_estimates_ext, + pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round], + pdsch_vars[eNB_id]->log2_maxh1); + // printf("rho stream2 =%d\n",&pdsch_vars[eNB_id]->dl_ch_rho2_ext ); - //printf("TM3 log2_maxh : %d\n",pdsch_vars[eNB_id]->log2_maxh); - if (symbol == 5) { - LOG_M("rho0_0.m","rho0_0",&pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round][0][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);// should be QAM - LOG_M("rho2_0.m","rho2_0",&pdsch_vars[eNB_id]->dl_ch_rho2_ext[0][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);//should be almost 0 - LOG_M("rho0_1.m.m","rho0_1",&pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round][1][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);//should be almost 0 - LOG_M("rho2_1.m","rho2_1",&pdsch_vars[eNB_id]->dl_ch_rho2_ext[1][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);//should be QAM - } - } else if (dlsch0_harq->mimo_mode<DUALSTREAM_UNIFORM_PRECODING1) {// single-layer precoding (TM5, TM6) - if ((rx_type==rx_IC_single_stream) && (eNB_id_i==ue->n_connected_eNB) && (dlsch0_harq->dl_power_off==0)) { - dlsch_channel_compensation_TM56(pdsch_vars[eNB_id]->rxdataF_ext, + //printf("TM3 log2_maxh : %d\n",pdsch_vars[eNB_id]->log2_maxh); + if (symbol == 5) { + LOG_M("rho0_0.m","rho0_0",&pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round][0][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);// should be QAM + LOG_M("rho2_0.m","rho2_0",&pdsch_vars[eNB_id]->dl_ch_rho2_ext[0][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);//should be almost 0 + LOG_M("rho0_1.m.m","rho0_1",&pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round][1][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);//should be almost 0 + LOG_M("rho2_1.m","rho2_1",&pdsch_vars[eNB_id]->dl_ch_rho2_ext[1][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);//should be QAM + } + } else if (dlsch0_harq->mimo_mode<DUALSTREAM_UNIFORM_PRECODING1) {// single-layer precoding (TM5, TM6) + if ((rx_type==rx_IC_single_stream) && (eNB_id_i==ue->n_connected_eNB) && (dlsch0_harq->dl_power_off==0)) { + dlsch_channel_compensation_TM56(pdsch_vars[eNB_id]->rxdataF_ext, pdsch_vars[eNB_id]->dl_ch_estimates_ext, pdsch_vars[eNB_id]->dl_ch_mag0, pdsch_vars[eNB_id]->dl_ch_magb0, @@ -696,24 +673,29 @@ int rx_pdsch(PHY_VARS_UE *ue, pdsch_vars[eNB_id]->log2_maxh, dlsch0_harq->dl_power_off); - for (rb=0; rb<nb_rb; rb++) { - switch(pdsch_vars[eNB_id]->pmi_ext[rb]) { + for (rb=0; rb<nb_rb; rb++) { + switch(pdsch_vars[eNB_id]->pmi_ext[rb]) { case 0: pdsch_vars[eNB_id_i]->pmi_ext[rb]=1; break; - case 1: + + case 1: pdsch_vars[eNB_id_i]->pmi_ext[rb]=0; break; - case 2: + + case 2: pdsch_vars[eNB_id_i]->pmi_ext[rb]=3; break; + case 3: pdsch_vars[eNB_id_i]->pmi_ext[rb]=2; break; - } - // if (rb==0) + } + + // if (rb==0) // printf("pmi %d, pmi_i %d\n",pdsch_vars[eNB_id]->pmi_ext[rb],pdsch_vars[eNB_id_i]->pmi_ext[rb]); } + dlsch_channel_compensation_TM56(pdsch_vars[eNB_id_i]->rxdataF_ext, pdsch_vars[eNB_id_i]->dl_ch_estimates_ext, pdsch_vars[eNB_id_i]->dl_ch_mag0, @@ -728,9 +710,10 @@ int rx_pdsch(PHY_VARS_UE *ue, nb_rb, pdsch_vars[eNB_id]->log2_maxh, dlsch0_harq->dl_power_off); + if (symbol==5) { LOG_M("rxF_comp_d.m","rxF_c_d",&pdsch_vars[eNB_id]->rxdataF_comp0[0][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1); - LOG_M("rxF_comp_i.m","rxF_c_i",&pdsch_vars[eNB_id_i]->rxdataF_comp0[0][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1); + LOG_M("rxF_comp_i.m","rxF_c_i",&pdsch_vars[eNB_id_i]->rxdataF_comp0[0][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1); } dlsch_dual_stream_correlation(frame_parms, @@ -755,45 +738,43 @@ int rx_pdsch(PHY_VARS_UE *ue, nb_rb, pdsch_vars[eNB_id]->log2_maxh, 1); - - } - - - } else if (dlsch0_harq->mimo_mode==TM7) { //TM7 - - dlsch_channel_compensation(pdsch_vars[eNB_id]->rxdataF_ext, - pdsch_vars[eNB_id]->dl_bf_ch_estimates_ext, - pdsch_vars[eNB_id]->dl_ch_mag0, - pdsch_vars[eNB_id]->dl_ch_magb0, - pdsch_vars[eNB_id]->rxdataF_comp0, - (aatx>1) ? pdsch_vars[eNB_id]->rho : NULL, - frame_parms, - symbol, - first_symbol_flag, - get_Qm(dlsch0_harq->mcs), - nb_rb, - //9, - pdsch_vars[eNB_id]->log2_maxh, - measurements); // log2_maxh+I0_shift + } + } else if (dlsch0_harq->mimo_mode==TM7) { //TM7 + dlsch_channel_compensation(pdsch_vars[eNB_id]->rxdataF_ext, + pdsch_vars[eNB_id]->dl_bf_ch_estimates_ext, + pdsch_vars[eNB_id]->dl_ch_mag0, + pdsch_vars[eNB_id]->dl_ch_magb0, + pdsch_vars[eNB_id]->rxdataF_comp0, + (aatx>1) ? pdsch_vars[eNB_id]->rho : NULL, + frame_parms, + symbol, + first_symbol_flag, + get_Qm(dlsch0_harq->mcs), + nb_rb, + //9, + pdsch_vars[eNB_id]->log2_maxh, + measurements); // log2_maxh+I0_shift } #if UE_TIMING_TRACE - stop_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]); + stop_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]); #if DISABLE_LOG_X - printf("[AbsSFN %d.%d] Slot%d Symbol %d log2_maxh %d channel_level %d: Channel Comp %5.2f \n",frame,subframe,slot,symbol,pdsch_vars[eNB_id]->log2_maxh,proc->channel_level,ue->generic_stat_bis[ue->current_thread_id[subframe]][slot].p_time/(cpuf*1000.0)); + printf("[AbsSFN %d.%d] Slot%d Symbol %d log2_maxh %d channel_level %d: Channel Comp %5.2f \n",frame,subframe,slot,symbol,pdsch_vars[eNB_id]->log2_maxh,proc->channel_level, + ue->generic_stat_bis[ue->current_thread_id[subframe]][slot].p_time/(cpuf*1000.0)); #else - LOG_I(PHY, "[AbsSFN %d.%d] Slot%d Symbol %d log2_maxh %d Channel Comp %5.2f \n",frame,subframe,slot,symbol,pdsch_vars[eNB_id]->log2_maxh,ue->generic_stat_bis[ue->current_thread_id[subframe]][slot].p_time/(cpuf*1000.0)); + LOG_I(PHY, "[AbsSFN %d.%d] Slot%d Symbol %d log2_maxh %d Channel Comp %5.2f \n",frame,subframe,slot,symbol,pdsch_vars[eNB_id]->log2_maxh, + ue->generic_stat_bis[ue->current_thread_id[subframe]][slot].p_time/(cpuf*1000.0)); #endif #endif -// MRC + // MRC #if UE_TIMING_TRACE - start_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]); + start_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]); #endif - if (frame_parms->nb_antennas_rx > 1) { + if (frame_parms->nb_antennas_rx > 1) { if ((dlsch0_harq->mimo_mode == LARGE_CDD) || ((dlsch0_harq->mimo_mode >=DUALSTREAM_UNIFORM_PRECODING1) && - (dlsch0_harq->mimo_mode <=DUALSTREAM_PUSCH_PRECODING))){ // TM3 or TM4 + (dlsch0_harq->mimo_mode <=DUALSTREAM_PUSCH_PRECODING))) { // TM3 or TM4 if (frame_parms->nb_antenna_ports_eNB == 2) { dlsch_detection_mrc_TM34(frame_parms, pdsch_vars[eNB_id], @@ -802,9 +783,10 @@ int rx_pdsch(PHY_VARS_UE *ue, symbol, nb_rb, 1); - if (symbol == 5) { - LOG_M("rho0_mrc.m","rho0_0",&pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round][0][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);// should be QAM - LOG_M("rho2_mrc.m","rho2_0",&pdsch_vars[eNB_id]->dl_ch_rho2_ext[0][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);//should be almost 0 + + if (symbol == 5) { + LOG_M("rho0_mrc.m","rho0_0",&pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round][0][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);// should be QAM + LOG_M("rho2_mrc.m","rho2_0",&pdsch_vars[eNB_id]->dl_ch_rho2_ext[0][symbol*frame_parms->N_RB_DL*12],frame_parms->N_RB_DL*12,1,1);//should be almost 0 } } } else { @@ -822,11 +804,12 @@ int rx_pdsch(PHY_VARS_UE *ue, rx_type==rx_IC_single_stream); } } + // printf("Combining"); if ((dlsch0_harq->mimo_mode == SISO) || ((dlsch0_harq->mimo_mode >= UNIFORM_PRECODING11) && (dlsch0_harq->mimo_mode <= PUSCH_PRECODING0)) || - (dlsch0_harq->mimo_mode == TM7)) { + (dlsch0_harq->mimo_mode == TM7)) { /* dlsch_siso(frame_parms, pdsch_vars[eNB_id]->rxdataF_comp, @@ -849,24 +832,22 @@ int rx_pdsch(PHY_VARS_UE *ue, (dlsch0_harq->mimo_mode <=DUALSTREAM_PUSCH_PRECODING))) { rxdataF_comp_ptr = pdsch_vars[eNB_id]->rxdataF_comp1[harq_pid][round]; dl_ch_mag_ptr = pdsch_vars[eNB_id]->dl_ch_mag1[harq_pid][round]; - } - else { + } else { rxdataF_comp_ptr = pdsch_vars[eNB_id_i]->rxdataF_comp0; dl_ch_mag_ptr = pdsch_vars[eNB_id_i]->dl_ch_mag0; //i_mod should have been passed as a parameter } #if UE_TIMING_TRACE - stop_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]); + stop_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]); #if DISABLE_LOG_X - printf("[AbsSFN %d.%d] Slot%d Symbol %d: Channel Combine %5.2f \n",frame,subframe,slot,symbol,ue->generic_stat_bis[ue->current_thread_id[subframe]][slot].p_time/(cpuf*1000.0)); + printf("[AbsSFN %d.%d] Slot%d Symbol %d: Channel Combine %5.2f \n",frame,subframe,slot,symbol,ue->generic_stat_bis[ue->current_thread_id[subframe]][slot].p_time/(cpuf*1000.0)); #else - LOG_I(PHY, "[AbsSFN %d.%d] Slot%d Symbol %d: Channel Combine %5.2f \n",frame,subframe,slot,symbol,ue->generic_stat_bis[ue->current_thread_id[subframe]][slot].p_time/(cpuf*1000.0)); + LOG_I(PHY, "[AbsSFN %d.%d] Slot%d Symbol %d: Channel Combine %5.2f \n",frame,subframe,slot,symbol,ue->generic_stat_bis[ue->current_thread_id[subframe]][slot].p_time/(cpuf*1000.0)); #endif #endif - #if UE_TIMING_TRACE - start_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]); + start_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]); #endif //printf("LLR dlsch0_harq->Qm %d rx_type %d cw0 %d cw1 %d symbol %d \n",dlsch0_harq->Qm,rx_type,codeword_TB0,codeword_TB1,symbol); // compute LLRs @@ -875,10 +856,11 @@ int rx_pdsch(PHY_VARS_UE *ue, int8_t *pllr_symbol_cw1; uint32_t llr_offset_symbol; llr_offset_symbol = pdsch_vars[eNB_id]->llr_offset[symbol]; - pllr_symbol_cw0 = (int8_t*)pdsch_vars[eNB_id]->llr[0]; - pllr_symbol_cw1 = (int8_t*)pdsch_vars[eNB_id]->llr[1]; + pllr_symbol_cw0 = (int8_t *)pdsch_vars[eNB_id]->llr[0]; + pllr_symbol_cw1 = (int8_t *)pdsch_vars[eNB_id]->llr[1]; pllr_symbol_cw0 += llr_offset_symbol; pllr_symbol_cw1 += llr_offset_symbol; + /* LOG_I(PHY,"compute LLRs [AbsSubframe %d.%d-%d] NbRB %d Qm %d LLRs-Length %d LLR-Offset %d @LLR Buff %p @LLR Buff(symb) %p\n", frame, subframe,symbol, @@ -889,31 +871,26 @@ int rx_pdsch(PHY_VARS_UE *ue, pllr_symbol_cw0); */ switch (dlsch0_harq->Qm) { - case 2 : - if ((rx_type==rx_standard) || (codeword_TB1 == -1)) { - - + case 2 : + if ((rx_type==rx_standard) || (codeword_TB1 == -1)) { dlsch_qpsk_llr(frame_parms, pdsch_vars[eNB_id]->rxdataF_comp0, - (int16_t*)pllr_symbol_cw0, + (int16_t *)pllr_symbol_cw0, symbol, first_symbol_flag, nb_rb, adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,2,subframe,symbol), beamforming_mode); - - } else if (codeword_TB0 == -1){ - + } else if (codeword_TB0 == -1) { dlsch_qpsk_llr(frame_parms, pdsch_vars[eNB_id]->rxdataF_comp0, - (int16_t*)pllr_symbol_cw1, + (int16_t *)pllr_symbol_cw1, symbol, first_symbol_flag, nb_rb, adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,2,subframe,symbol), beamforming_mode); - } - else if (rx_type >= rx_IC_single_stream) { + } else if (rx_type >= rx_IC_single_stream) { if (dlsch1_harq->Qm == 2) { dlsch_qpsk_qpsk_llr(frame_parms, pdsch_vars[eNB_id]->rxdataF_comp0, @@ -923,6 +900,7 @@ int rx_pdsch(PHY_VARS_UE *ue, symbol,first_symbol_flag,nb_rb, adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,2,subframe,symbol), pdsch_vars[eNB_id]->llr128); + if (rx_type==rx_IC_dual_stream) { dlsch_qpsk_qpsk_llr(frame_parms, rxdataF_comp_ptr, @@ -933,8 +911,7 @@ int rx_pdsch(PHY_VARS_UE *ue, adjust_G2(frame_parms,dlsch1_harq->rb_alloc_even,2,subframe,symbol), pdsch_vars[eNB_id]->llr128_2ndstream); } - } - else if (dlsch1_harq->Qm == 4) { + } else if (dlsch1_harq->Qm == 4) { dlsch_qpsk_16qam_llr(frame_parms, pdsch_vars[eNB_id]->rxdataF_comp0, rxdataF_comp_ptr,//i @@ -944,6 +921,7 @@ int rx_pdsch(PHY_VARS_UE *ue, symbol,first_symbol_flag,nb_rb, adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,2,subframe,symbol), pdsch_vars[eNB_id]->llr128); + if (rx_type==rx_IC_dual_stream) { dlsch_16qam_qpsk_llr(frame_parms, rxdataF_comp_ptr, @@ -955,8 +933,7 @@ int rx_pdsch(PHY_VARS_UE *ue, adjust_G2(frame_parms,dlsch1_harq->rb_alloc_even,4,subframe,symbol), pdsch_vars[eNB_id]->llr128_2ndstream); } - } - else { + } else { dlsch_qpsk_64qam_llr(frame_parms, pdsch_vars[eNB_id]->rxdataF_comp0, rxdataF_comp_ptr,//i @@ -966,6 +943,7 @@ int rx_pdsch(PHY_VARS_UE *ue, symbol,first_symbol_flag,nb_rb, adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,2,subframe,symbol), pdsch_vars[eNB_id]->llr128); + if (rx_type==rx_IC_dual_stream) { dlsch_64qam_qpsk_llr(frame_parms, rxdataF_comp_ptr, @@ -979,260 +957,272 @@ int rx_pdsch(PHY_VARS_UE *ue, } } } - break; - case 4 : - if ((rx_type==rx_standard ) || (codeword_TB1 == -1)) { - dlsch_16qam_llr(frame_parms, - pdsch_vars[eNB_id]->rxdataF_comp0, - pdsch_vars[eNB_id]->llr[0], - pdsch_vars[eNB_id]->dl_ch_mag0, - symbol,first_symbol_flag,nb_rb, - adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,4,subframe,symbol), - pdsch_vars[eNB_id]->llr128, - beamforming_mode); - } else if (codeword_TB0 == -1){ - dlsch_16qam_llr(frame_parms, - pdsch_vars[eNB_id]->rxdataF_comp0, - pdsch_vars[eNB_id]->llr[1], - pdsch_vars[eNB_id]->dl_ch_mag0, - symbol,first_symbol_flag,nb_rb, - adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,4,subframe,symbol), - pdsch_vars[eNB_id]->llr128_2ndstream, - beamforming_mode); - } - else if (rx_type >= rx_IC_single_stream) { - if (dlsch1_harq->Qm == 2) { - dlsch_16qam_qpsk_llr(frame_parms, - pdsch_vars[eNB_id]->rxdataF_comp0, - rxdataF_comp_ptr,//i - pdsch_vars[eNB_id]->dl_ch_mag0, - pdsch_vars[eNB_id]->dl_ch_rho2_ext, - pdsch_vars[eNB_id]->llr[0], - symbol,first_symbol_flag,nb_rb, - adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,4,subframe,symbol), - pdsch_vars[eNB_id]->llr128); - if (rx_type==rx_IC_dual_stream) { - dlsch_qpsk_16qam_llr(frame_parms, - rxdataF_comp_ptr, - pdsch_vars[eNB_id]->rxdataF_comp0,//i - pdsch_vars[eNB_id]->dl_ch_mag0,//i - pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round], - pdsch_vars[eNB_id]->llr[1], + + break; + + case 4 : + if ((rx_type==rx_standard ) || (codeword_TB1 == -1)) { + dlsch_16qam_llr(frame_parms, + pdsch_vars[eNB_id]->rxdataF_comp0, + pdsch_vars[eNB_id]->llr[0], + pdsch_vars[eNB_id]->dl_ch_mag0, + symbol,first_symbol_flag,nb_rb, + adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,4,subframe,symbol), + pdsch_vars[eNB_id]->llr128, + beamforming_mode); + } else if (codeword_TB0 == -1) { + dlsch_16qam_llr(frame_parms, + pdsch_vars[eNB_id]->rxdataF_comp0, + pdsch_vars[eNB_id]->llr[1], + pdsch_vars[eNB_id]->dl_ch_mag0, + symbol,first_symbol_flag,nb_rb, + adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,4,subframe,symbol), + pdsch_vars[eNB_id]->llr128_2ndstream, + beamforming_mode); + } else if (rx_type >= rx_IC_single_stream) { + if (dlsch1_harq->Qm == 2) { + dlsch_16qam_qpsk_llr(frame_parms, + pdsch_vars[eNB_id]->rxdataF_comp0, + rxdataF_comp_ptr,//i + pdsch_vars[eNB_id]->dl_ch_mag0, + pdsch_vars[eNB_id]->dl_ch_rho2_ext, + pdsch_vars[eNB_id]->llr[0], symbol,first_symbol_flag,nb_rb, - adjust_G2(frame_parms,dlsch1_harq->rb_alloc_even,2,subframe,symbol), - pdsch_vars[eNB_id]->llr128_2ndstream); - } - } - else if (dlsch1_harq->Qm == 4) { - dlsch_16qam_16qam_llr(frame_parms, - pdsch_vars[eNB_id]->rxdataF_comp0, - rxdataF_comp_ptr,//i - pdsch_vars[eNB_id]->dl_ch_mag0, - dl_ch_mag_ptr,//i - pdsch_vars[eNB_id]->dl_ch_rho2_ext, - pdsch_vars[eNB_id]->llr[0], - symbol,first_symbol_flag,nb_rb, - adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,4,subframe,symbol), - pdsch_vars[eNB_id]->llr128); - if (rx_type==rx_IC_dual_stream) { + adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,4,subframe,symbol), + pdsch_vars[eNB_id]->llr128); + + if (rx_type==rx_IC_dual_stream) { + dlsch_qpsk_16qam_llr(frame_parms, + rxdataF_comp_ptr, + pdsch_vars[eNB_id]->rxdataF_comp0,//i + pdsch_vars[eNB_id]->dl_ch_mag0,//i + pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round], + pdsch_vars[eNB_id]->llr[1], + symbol,first_symbol_flag,nb_rb, + adjust_G2(frame_parms,dlsch1_harq->rb_alloc_even,2,subframe,symbol), + pdsch_vars[eNB_id]->llr128_2ndstream); + } + } else if (dlsch1_harq->Qm == 4) { dlsch_16qam_16qam_llr(frame_parms, - rxdataF_comp_ptr, - pdsch_vars[eNB_id]->rxdataF_comp0,//i - dl_ch_mag_ptr, - pdsch_vars[eNB_id]->dl_ch_mag0,//i - pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round], - pdsch_vars[eNB_id]->llr[1], + pdsch_vars[eNB_id]->rxdataF_comp0, + rxdataF_comp_ptr,//i + pdsch_vars[eNB_id]->dl_ch_mag0, + dl_ch_mag_ptr,//i + pdsch_vars[eNB_id]->dl_ch_rho2_ext, + pdsch_vars[eNB_id]->llr[0], symbol,first_symbol_flag,nb_rb, - adjust_G2(frame_parms,dlsch1_harq->rb_alloc_even,4,subframe,symbol), - pdsch_vars[eNB_id]->llr128_2ndstream); - } - } - else { - dlsch_16qam_64qam_llr(frame_parms, - pdsch_vars[eNB_id]->rxdataF_comp0, - rxdataF_comp_ptr,//i - pdsch_vars[eNB_id]->dl_ch_mag0, - dl_ch_mag_ptr,//i - pdsch_vars[eNB_id]->dl_ch_rho2_ext, - pdsch_vars[eNB_id]->llr[0], - symbol,first_symbol_flag,nb_rb, - adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,4,subframe,symbol), - pdsch_vars[eNB_id]->llr128); - if (rx_type==rx_IC_dual_stream) { - dlsch_64qam_16qam_llr(frame_parms, - rxdataF_comp_ptr, + adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,4,subframe,symbol), + pdsch_vars[eNB_id]->llr128); + + if (rx_type==rx_IC_dual_stream) { + dlsch_16qam_16qam_llr(frame_parms, + rxdataF_comp_ptr, + pdsch_vars[eNB_id]->rxdataF_comp0,//i + dl_ch_mag_ptr, + pdsch_vars[eNB_id]->dl_ch_mag0,//i + pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round], + pdsch_vars[eNB_id]->llr[1], + symbol,first_symbol_flag,nb_rb, + adjust_G2(frame_parms,dlsch1_harq->rb_alloc_even,4,subframe,symbol), + pdsch_vars[eNB_id]->llr128_2ndstream); + } + } else { + dlsch_16qam_64qam_llr(frame_parms, pdsch_vars[eNB_id]->rxdataF_comp0, - dl_ch_mag_ptr, + rxdataF_comp_ptr,//i pdsch_vars[eNB_id]->dl_ch_mag0, - pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round], - pdsch_vars[eNB_id]->llr[1], + dl_ch_mag_ptr,//i + pdsch_vars[eNB_id]->dl_ch_rho2_ext, + pdsch_vars[eNB_id]->llr[0], symbol,first_symbol_flag,nb_rb, - adjust_G2(frame_parms,dlsch1_harq->rb_alloc_even,6,subframe,symbol), - pdsch_vars[eNB_id]->llr128_2ndstream); + adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,4,subframe,symbol), + pdsch_vars[eNB_id]->llr128); + + if (rx_type==rx_IC_dual_stream) { + dlsch_64qam_16qam_llr(frame_parms, + rxdataF_comp_ptr, + pdsch_vars[eNB_id]->rxdataF_comp0, + dl_ch_mag_ptr, + pdsch_vars[eNB_id]->dl_ch_mag0, + pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round], + pdsch_vars[eNB_id]->llr[1], + symbol,first_symbol_flag,nb_rb, + adjust_G2(frame_parms,dlsch1_harq->rb_alloc_even,6,subframe,symbol), + pdsch_vars[eNB_id]->llr128_2ndstream); + } } } - } - break; - case 6 : - if ((rx_type==rx_standard) || (codeword_TB1 == -1)) { - dlsch_64qam_llr(frame_parms, - pdsch_vars[eNB_id]->rxdataF_comp0, - (int16_t*)pllr_symbol_cw0, - pdsch_vars[eNB_id]->dl_ch_mag0, - pdsch_vars[eNB_id]->dl_ch_magb0, - symbol,first_symbol_flag,nb_rb, - adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,6,subframe,symbol), - pdsch_vars[eNB_id]->llr_offset[symbol], - beamforming_mode); - } else if (codeword_TB0 == -1){ - dlsch_64qam_llr(frame_parms, - pdsch_vars[eNB_id]->rxdataF_comp0, - (int16_t*)pllr_symbol_cw1, - pdsch_vars[eNB_id]->dl_ch_mag0, - pdsch_vars[eNB_id]->dl_ch_magb0, - symbol,first_symbol_flag,nb_rb, - adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,6,subframe,symbol), - pdsch_vars[eNB_id]->llr_offset[symbol], - beamforming_mode); - } - else if (rx_type >= rx_IC_single_stream) { - if (dlsch1_harq->Qm == 2) { - dlsch_64qam_qpsk_llr(frame_parms, - pdsch_vars[eNB_id]->rxdataF_comp0, - rxdataF_comp_ptr,//i - pdsch_vars[eNB_id]->dl_ch_mag0, - pdsch_vars[eNB_id]->dl_ch_rho2_ext, - pdsch_vars[eNB_id]->llr[0], - symbol,first_symbol_flag,nb_rb, - adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,6,subframe,symbol), - pdsch_vars[eNB_id]->llr128); - if (rx_type==rx_IC_dual_stream) { - dlsch_qpsk_64qam_llr(frame_parms, - rxdataF_comp_ptr, - pdsch_vars[eNB_id]->rxdataF_comp0,//i + + break; + + case 6 : + if ((rx_type==rx_standard) || (codeword_TB1 == -1)) { + dlsch_64qam_llr(frame_parms, + pdsch_vars[eNB_id]->rxdataF_comp0, + (int16_t *)pllr_symbol_cw0, + pdsch_vars[eNB_id]->dl_ch_mag0, + pdsch_vars[eNB_id]->dl_ch_magb0, + symbol,first_symbol_flag,nb_rb, + adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,6,subframe,symbol), + pdsch_vars[eNB_id]->llr_offset[symbol], + beamforming_mode); + } else if (codeword_TB0 == -1) { + dlsch_64qam_llr(frame_parms, + pdsch_vars[eNB_id]->rxdataF_comp0, + (int16_t *)pllr_symbol_cw1, + pdsch_vars[eNB_id]->dl_ch_mag0, + pdsch_vars[eNB_id]->dl_ch_magb0, + symbol,first_symbol_flag,nb_rb, + adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,6,subframe,symbol), + pdsch_vars[eNB_id]->llr_offset[symbol], + beamforming_mode); + } else if (rx_type >= rx_IC_single_stream) { + if (dlsch1_harq->Qm == 2) { + dlsch_64qam_qpsk_llr(frame_parms, + pdsch_vars[eNB_id]->rxdataF_comp0, + rxdataF_comp_ptr,//i pdsch_vars[eNB_id]->dl_ch_mag0, - pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round], - pdsch_vars[eNB_id]->llr[1], + pdsch_vars[eNB_id]->dl_ch_rho2_ext, + pdsch_vars[eNB_id]->llr[0], symbol,first_symbol_flag,nb_rb, - adjust_G2(frame_parms,dlsch1_harq->rb_alloc_even,2,subframe,symbol), - pdsch_vars[eNB_id]->llr128_2ndstream); - } - } - else if (dlsch1_harq->Qm == 4) { - dlsch_64qam_16qam_llr(frame_parms, - pdsch_vars[eNB_id]->rxdataF_comp0, - rxdataF_comp_ptr,//i - pdsch_vars[eNB_id]->dl_ch_mag0, - dl_ch_mag_ptr,//i - pdsch_vars[eNB_id]->dl_ch_rho2_ext, - pdsch_vars[eNB_id]->llr[0], - symbol,first_symbol_flag,nb_rb, - adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,6,subframe,symbol), - pdsch_vars[eNB_id]->llr128); - if (rx_type==rx_IC_dual_stream) { - dlsch_16qam_64qam_llr(frame_parms, - rxdataF_comp_ptr, - pdsch_vars[eNB_id]->rxdataF_comp0,//i - dl_ch_mag_ptr, - pdsch_vars[eNB_id]->dl_ch_mag0,//i - pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round], - pdsch_vars[eNB_id]->llr[1], + adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,6,subframe,symbol), + pdsch_vars[eNB_id]->llr128); + + if (rx_type==rx_IC_dual_stream) { + dlsch_qpsk_64qam_llr(frame_parms, + rxdataF_comp_ptr, + pdsch_vars[eNB_id]->rxdataF_comp0,//i + pdsch_vars[eNB_id]->dl_ch_mag0, + pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round], + pdsch_vars[eNB_id]->llr[1], + symbol,first_symbol_flag,nb_rb, + adjust_G2(frame_parms,dlsch1_harq->rb_alloc_even,2,subframe,symbol), + pdsch_vars[eNB_id]->llr128_2ndstream); + } + } else if (dlsch1_harq->Qm == 4) { + dlsch_64qam_16qam_llr(frame_parms, + pdsch_vars[eNB_id]->rxdataF_comp0, + rxdataF_comp_ptr,//i + pdsch_vars[eNB_id]->dl_ch_mag0, + dl_ch_mag_ptr,//i + pdsch_vars[eNB_id]->dl_ch_rho2_ext, + pdsch_vars[eNB_id]->llr[0], symbol,first_symbol_flag,nb_rb, - adjust_G2(frame_parms,dlsch1_harq->rb_alloc_even,4,subframe,symbol), - pdsch_vars[eNB_id]->llr128_2ndstream); - } - } - else { - dlsch_64qam_64qam_llr(frame_parms, - pdsch_vars[eNB_id]->rxdataF_comp0, - rxdataF_comp_ptr,//i - pdsch_vars[eNB_id]->dl_ch_mag0, - dl_ch_mag_ptr,//i - pdsch_vars[eNB_id]->dl_ch_rho2_ext, - (int16_t*)pllr_symbol_cw0, - symbol,first_symbol_flag,nb_rb, - adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,6,subframe,symbol), - pdsch_vars[eNB_id]->llr_offset[symbol]); - if (rx_type==rx_IC_dual_stream) { + adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,6,subframe,symbol), + pdsch_vars[eNB_id]->llr128); + + if (rx_type==rx_IC_dual_stream) { + dlsch_16qam_64qam_llr(frame_parms, + rxdataF_comp_ptr, + pdsch_vars[eNB_id]->rxdataF_comp0,//i + dl_ch_mag_ptr, + pdsch_vars[eNB_id]->dl_ch_mag0,//i + pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round], + pdsch_vars[eNB_id]->llr[1], + symbol,first_symbol_flag,nb_rb, + adjust_G2(frame_parms,dlsch1_harq->rb_alloc_even,4,subframe,symbol), + pdsch_vars[eNB_id]->llr128_2ndstream); + } + } else { dlsch_64qam_64qam_llr(frame_parms, - rxdataF_comp_ptr, - pdsch_vars[eNB_id]->rxdataF_comp0,//i - dl_ch_mag_ptr, - pdsch_vars[eNB_id]->dl_ch_mag0,//i - pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round], - (int16_t*)pllr_symbol_cw1, + pdsch_vars[eNB_id]->rxdataF_comp0, + rxdataF_comp_ptr,//i + pdsch_vars[eNB_id]->dl_ch_mag0, + dl_ch_mag_ptr,//i + pdsch_vars[eNB_id]->dl_ch_rho2_ext, + (int16_t *)pllr_symbol_cw0, symbol,first_symbol_flag,nb_rb, - adjust_G2(frame_parms,dlsch1_harq->rb_alloc_even,6,subframe,symbol), + adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,6,subframe,symbol), pdsch_vars[eNB_id]->llr_offset[symbol]); + + if (rx_type==rx_IC_dual_stream) { + dlsch_64qam_64qam_llr(frame_parms, + rxdataF_comp_ptr, + pdsch_vars[eNB_id]->rxdataF_comp0,//i + dl_ch_mag_ptr, + pdsch_vars[eNB_id]->dl_ch_mag0,//i + pdsch_vars[eNB_id]->dl_ch_rho_ext[harq_pid][round], + (int16_t *)pllr_symbol_cw1, + symbol,first_symbol_flag,nb_rb, + adjust_G2(frame_parms,dlsch1_harq->rb_alloc_even,6,subframe,symbol), + pdsch_vars[eNB_id]->llr_offset[symbol]); + } } } - } - break; - default: - LOG_W(PHY,"rx_dlsch.c : Unknown mod_order!!!!\n"); - return(-1); - break; + + break; + + default: + LOG_W(PHY,"rx_dlsch.c : Unknown mod_order!!!!\n"); + return(-1); + break; } + if (dlsch1_harq) { - switch (get_Qm(dlsch1_harq->mcs)) { - case 2 : - if (rx_type==rx_standard) { - dlsch_qpsk_llr(frame_parms, - pdsch_vars[eNB_id]->rxdataF_comp0, - (int16_t*)pllr_symbol_cw0, - symbol,first_symbol_flag,nb_rb, - adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,2,subframe,symbol), - beamforming_mode); - } - break; - case 4: - if (rx_type==rx_standard) { - dlsch_16qam_llr(frame_parms, - pdsch_vars[eNB_id]->rxdataF_comp0, - pdsch_vars[eNB_id]->llr[0], - pdsch_vars[eNB_id]->dl_ch_mag0, - symbol,first_symbol_flag,nb_rb, - adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,4,subframe,symbol), - pdsch_vars[eNB_id]->llr128, - beamforming_mode); + switch (get_Qm(dlsch1_harq->mcs)) { + case 2 : + if (rx_type==rx_standard) { + dlsch_qpsk_llr(frame_parms, + pdsch_vars[eNB_id]->rxdataF_comp0, + (int16_t *)pllr_symbol_cw0, + symbol,first_symbol_flag,nb_rb, + adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,2,subframe,symbol), + beamforming_mode); + } + + break; + + case 4: + if (rx_type==rx_standard) { + dlsch_16qam_llr(frame_parms, + pdsch_vars[eNB_id]->rxdataF_comp0, + pdsch_vars[eNB_id]->llr[0], + pdsch_vars[eNB_id]->dl_ch_mag0, + symbol,first_symbol_flag,nb_rb, + adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,4,subframe,symbol), + pdsch_vars[eNB_id]->llr128, + beamforming_mode); + } + + break; + + case 6 : + if (rx_type==rx_standard) { + dlsch_64qam_llr(frame_parms, + pdsch_vars[eNB_id]->rxdataF_comp0, + (int16_t *)pllr_symbol_cw0, + pdsch_vars[eNB_id]->dl_ch_mag0, + pdsch_vars[eNB_id]->dl_ch_magb0, + symbol,first_symbol_flag,nb_rb, + adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,6,subframe,symbol), + pdsch_vars[eNB_id]->llr_offset[symbol], + beamforming_mode); + } + + break; + + default: + LOG_W(PHY,"rx_dlsch.c : Unknown mod_order!!!!\n"); + return(-1); + break; } - break; - case 6 : - if (rx_type==rx_standard) { - dlsch_64qam_llr(frame_parms, - pdsch_vars[eNB_id]->rxdataF_comp0, - (int16_t*)pllr_symbol_cw0, - pdsch_vars[eNB_id]->dl_ch_mag0, - pdsch_vars[eNB_id]->dl_ch_magb0, - symbol,first_symbol_flag,nb_rb, - adjust_G2(frame_parms,dlsch0_harq->rb_alloc_even,6,subframe,symbol), - pdsch_vars[eNB_id]->llr_offset[symbol], - beamforming_mode); - } - break; - default: - LOG_W(PHY,"rx_dlsch.c : Unknown mod_order!!!!\n"); - return(-1); - break; - } } #if UE_TIMING_TRACE - stop_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]); + stop_meas(&ue->generic_stat_bis[ue->current_thread_id[subframe]][slot]); #if DISABLE_LOG_X - printf("[AbsSFN %d.%d] Slot%d Symbol %d: LLR Computation %5.2f \n",frame,subframe,slot,symbol,ue->generic_stat_bis[ue->current_thread_id[subframe]][slot].p_time/(cpuf*1000.0)); + printf("[AbsSFN %d.%d] Slot%d Symbol %d: LLR Computation %5.2f \n",frame,subframe,slot,symbol,ue->generic_stat_bis[ue->current_thread_id[subframe]][slot].p_time/(cpuf*1000.0)); #else - LOG_D(PHY, "[AbsSFN %d.%d] Slot%d Symbol %d: LLR Computation %5.2f \n",frame,subframe,slot,symbol,ue->generic_stat_bis[ue->current_thread_id[subframe]][slot].p_time/(cpuf*1000.0)); + LOG_D(PHY, "[AbsSFN %d.%d] Slot%d Symbol %d: LLR Computation %5.2f \n",frame,subframe,slot,symbol,ue->generic_stat_bis[ue->current_thread_id[subframe]][slot].p_time/(cpuf*1000.0)); #endif #endif - - // Please keep it: useful for debugging + // Please keep it: useful for debugging #if 0 - if( (symbol == 13) && (subframe==0) && (dlsch0_harq->Qm == 6) /*&& (nb_rb==25)*/) - { - LOG_E(PHY,"Dump Phy Chan Est \n"); - if(1) - { + + if( (symbol == 13) && (subframe==0) && (dlsch0_harq->Qm == 6) /*&& (nb_rb==25)*/) { + LOG_E(PHY,"Dump Phy Chan Est \n"); + + if(1) { #if 1 LOG_M("rxdataF0.m" , "rxdataF0", &common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[subframe]].rxdataF[0][0],14*frame_parms->ofdm_symbol_size,1,1); //LOG_M("rxdataF1.m" , "rxdataF1", &common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[subframe]].rxdataF[0][0],14*frame_parms->ofdm_symbol_size,1,1); @@ -1240,8 +1230,6 @@ int rx_pdsch(PHY_VARS_UE *ue, //LOG_M("dl_ch_estimates01.m", "dl_ch_estimates01", &common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[subframe]].dl_ch_estimates[eNB_id][1][0],14*frame_parms->ofdm_symbol_size,1,1); //LOG_M("dl_ch_estimates10.m", "dl_ch_estimates10", &common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[subframe]].dl_ch_estimates[eNB_id][2][0],14*frame_parms->ofdm_symbol_size,1,1); //LOG_M("dl_ch_estimates11.m", "dl_ch_estimates11", &common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[subframe]].dl_ch_estimates[eNB_id][3][0],14*frame_parms->ofdm_symbol_size,1,1); - - //LOG_M("rxdataF_ext00.m" , "rxdataF_ext00", &pdsch_vars[eNB_id]->rxdataF_ext[0][0],14*frame_parms->N_RB_DL*12,1,1); //LOG_M("rxdataF_ext01.m" , "rxdataF_ext01", &pdsch_vars[eNB_id]->rxdataF_ext[1][0],14*frame_parms->N_RB_DL*12,1,1); //LOG_M("rxdataF_ext10.m" , "rxdataF_ext10", &pdsch_vars[eNB_id]->rxdataF_ext[2][0],14*frame_parms->N_RB_DL*12,1,1); @@ -1257,20 +1245,16 @@ int rx_pdsch(PHY_VARS_UE *ue, #endif LOG_M("llr0.m","llr0", &pdsch_vars[eNB_id]->llr[0][0],(14*nb_rb*12*dlsch1_harq->Qm) - 4*(nb_rb*4*dlsch1_harq->Qm),1,0); //LOG_M("llr1.m","llr1", &pdsch_vars[eNB_id]->llr[1][0],(14*nb_rb*12*dlsch1_harq->Qm) - 4*(nb_rb*4*dlsch1_harq->Qm),1,0); - - AssertFatal(0," "); - } - + } } -#endif +#endif T(T_UE_PHY_PDSCH_IQ, T_INT(eNB_id), T_INT(frame%1024), T_INT(subframe), T_INT(nb_rb), T_INT(frame_parms->N_RB_UL), T_INT(frame_parms->symbols_per_tti), T_BUFFER(&pdsch_vars[eNB_id]->rxdataF_comp0[eNB_id][0], 2 * /* ulsch[UE_id]->harq_processes[harq_pid]->nb_rb */ frame_parms->N_RB_UL *12*frame_parms->symbols_per_tti*2)); - return 0; } @@ -1290,20 +1274,15 @@ void dlsch_channel_compensation(int **rxdataF_ext, unsigned char mod_order, unsigned short nb_rb, unsigned char output_shift, - PHY_MEASUREMENTS *measurements) -{ - + PHY_MEASUREMENTS *measurements) { #if defined(__i386) || defined(__x86_64) - unsigned short rb; unsigned char aatx,aarx,symbol_mod,pilots=0; __m128i *dl_ch128,*dl_ch128_2,*dl_ch_mag128,*dl_ch_mag128b,*rxdataF128,*rxdataF_comp128,*rho128; __m128i mmtmpD0,mmtmpD1,mmtmpD2,mmtmpD3,QAM_amp128; - symbol_mod = (symbol>=(7-frame_parms->Ncp)) ? symbol-(7-frame_parms->Ncp) : symbol; if ((symbol_mod == 0) || (symbol_mod == (4-frame_parms->Ncp))) { - if (frame_parms->nb_antenna_ports_eNB==1) // 10 out of 12 so don't reduce size nb_rb=1+(5*nb_rb/6); else @@ -1312,6 +1291,7 @@ void dlsch_channel_compensation(int **rxdataF_ext, for (aatx=0; aatx<frame_parms->nb_antenna_ports_eNB; aatx++) { __m128i QAM_amp128b = _mm_setzero_si128(); + if (mod_order == 4) { QAM_amp128 = _mm_set1_epi16(QAM16_n1); // 2/sqrt(10) } else if (mod_order == 6) { @@ -1335,17 +1315,12 @@ void dlsch_channel_compensation(int **rxdataF_ext, for (rb=0; rb<nb_rb; rb++) { if (mod_order>2) { // get channel amplitude if not QPSK - mmtmpD0 = _mm_madd_epi16(dl_ch128[0],dl_ch128[0]); mmtmpD0 = _mm_srai_epi32(mmtmpD0,output_shift); - mmtmpD1 = _mm_madd_epi16(dl_ch128[1],dl_ch128[1]); mmtmpD1 = _mm_srai_epi32(mmtmpD1,output_shift); - mmtmpD0 = _mm_packs_epi32(mmtmpD0,mmtmpD1); - // store channel magnitude here in a new field of dlsch - dl_ch_mag128[0] = _mm_unpacklo_epi16(mmtmpD0,mmtmpD0); dl_ch_mag128b[0] = dl_ch_mag128[0]; dl_ch_mag128[0] = _mm_mulhi_epi16(dl_ch_mag128[0],QAM_amp128); @@ -1362,18 +1337,14 @@ void dlsch_channel_compensation(int **rxdataF_ext, mmtmpD0 = _mm_madd_epi16(dl_ch128[2],dl_ch128[2]); mmtmpD0 = _mm_srai_epi32(mmtmpD0,output_shift); mmtmpD1 = _mm_packs_epi32(mmtmpD0,mmtmpD0); - dl_ch_mag128[2] = _mm_unpacklo_epi16(mmtmpD1,mmtmpD1); dl_ch_mag128b[2] = dl_ch_mag128[2]; - dl_ch_mag128[2] = _mm_mulhi_epi16(dl_ch_mag128[2],QAM_amp128); dl_ch_mag128[2] = _mm_slli_epi16(dl_ch_mag128[2],1); } dl_ch_mag128b[0] = _mm_mulhi_epi16(dl_ch_mag128b[0],QAM_amp128b); dl_ch_mag128b[0] = _mm_slli_epi16(dl_ch_mag128b[0],1); - - dl_ch_mag128b[1] = _mm_mulhi_epi16(dl_ch_mag128b[1],QAM_amp128b); dl_ch_mag128b[1] = _mm_slli_epi16(dl_ch_mag128b[1],1); @@ -1385,11 +1356,10 @@ void dlsch_channel_compensation(int **rxdataF_ext, // multiply by conjugated channel mmtmpD0 = _mm_madd_epi16(dl_ch128[0],rxdataF128[0]); - // mmtmpD0 contains real part of 4 consecutive outputs (32-bit) mmtmpD1 = _mm_shufflelo_epi16(dl_ch128[0],_MM_SHUFFLE(2,3,0,1)); mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1,_MM_SHUFFLE(2,3,0,1)); - mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i*)&conjugate[0]); + mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i *)&conjugate[0]); // print_ints("im",&mmtmpD1); mmtmpD1 = _mm_madd_epi16(mmtmpD1,rxdataF128[0]); // mmtmpD1 contains imag part of 4 consecutive outputs (32-bit) @@ -1405,20 +1375,18 @@ void dlsch_channel_compensation(int **rxdataF_ext, // print_shorts("rx:",rxdataF128); // print_shorts("ch:",dl_ch128); // print_shorts("pack:",rxdataF_comp128); - // multiply by conjugated channel mmtmpD0 = _mm_madd_epi16(dl_ch128[1],rxdataF128[1]); // mmtmpD0 contains real part of 4 consecutive outputs (32-bit) mmtmpD1 = _mm_shufflelo_epi16(dl_ch128[1],_MM_SHUFFLE(2,3,0,1)); mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1,_MM_SHUFFLE(2,3,0,1)); - mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i*)conjugate); + mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i *)conjugate); mmtmpD1 = _mm_madd_epi16(mmtmpD1,rxdataF128[1]); // mmtmpD1 contains imag part of 4 consecutive outputs (32-bit) mmtmpD0 = _mm_srai_epi32(mmtmpD0,output_shift); mmtmpD1 = _mm_srai_epi32(mmtmpD1,output_shift); mmtmpD2 = _mm_unpacklo_epi32(mmtmpD0,mmtmpD1); mmtmpD3 = _mm_unpackhi_epi32(mmtmpD0,mmtmpD1); - rxdataF_comp128[1] = _mm_packs_epi32(mmtmpD2,mmtmpD3); // print_shorts("rx:",rxdataF128+1); // print_shorts("ch:",dl_ch128+1); @@ -1430,19 +1398,17 @@ void dlsch_channel_compensation(int **rxdataF_ext, // mmtmpD0 contains real part of 4 consecutive outputs (32-bit) mmtmpD1 = _mm_shufflelo_epi16(dl_ch128[2],_MM_SHUFFLE(2,3,0,1)); mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1,_MM_SHUFFLE(2,3,0,1)); - mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i*)conjugate); + mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i *)conjugate); mmtmpD1 = _mm_madd_epi16(mmtmpD1,rxdataF128[2]); // mmtmpD1 contains imag part of 4 consecutive outputs (32-bit) mmtmpD0 = _mm_srai_epi32(mmtmpD0,output_shift); mmtmpD1 = _mm_srai_epi32(mmtmpD1,output_shift); mmtmpD2 = _mm_unpacklo_epi32(mmtmpD0,mmtmpD1); mmtmpD3 = _mm_unpackhi_epi32(mmtmpD0,mmtmpD1); - rxdataF_comp128[2] = _mm_packs_epi32(mmtmpD2,mmtmpD3); // print_shorts("rx:",rxdataF128+2); // print_shorts("ch:",dl_ch128+2); - // print_shorts("pack:",rxdataF_comp128+2); - + // print_shorts("pack:",rxdataF_comp128+2); dl_ch128+=3; dl_ch_mag128+=3; dl_ch_mag128b+=3; @@ -1455,14 +1421,11 @@ void dlsch_channel_compensation(int **rxdataF_ext, rxdataF128+=2; rxdataF_comp128+=2; } - } } } if (rho) { - - for (aarx=0; aarx<frame_parms->nb_antennas_rx; aarx++) { rho128 = (__m128i *)&rho[aarx][symbol*frame_parms->N_RB_DL*12]; dl_ch128 = (__m128i *)&dl_ch_estimates_ext[aarx][symbol*frame_parms->N_RB_DL*12]; @@ -1472,11 +1435,10 @@ void dlsch_channel_compensation(int **rxdataF_ext, // multiply by conjugated channel mmtmpD0 = _mm_madd_epi16(dl_ch128[0],dl_ch128_2[0]); // print_ints("re",&mmtmpD0); - // mmtmpD0 contains real part of 4 consecutive outputs (32-bit) mmtmpD1 = _mm_shufflelo_epi16(dl_ch128[0],_MM_SHUFFLE(2,3,0,1)); mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1,_MM_SHUFFLE(2,3,0,1)); - mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i*)&conjugate[0]); + mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i *)&conjugate[0]); // print_ints("im",&mmtmpD1); mmtmpD1 = _mm_madd_epi16(mmtmpD1,dl_ch128_2[0]); // mmtmpD1 contains imag part of 4 consecutive outputs (32-bit) @@ -1489,25 +1451,21 @@ void dlsch_channel_compensation(int **rxdataF_ext, // print_ints("c0",&mmtmpD2); // print_ints("c1",&mmtmpD3); rho128[0] = _mm_packs_epi32(mmtmpD2,mmtmpD3); - //print_shorts("rx:",dl_ch128_2); //print_shorts("ch:",dl_ch128); //print_shorts("pack:",rho128); - // multiply by conjugated channel mmtmpD0 = _mm_madd_epi16(dl_ch128[1],dl_ch128_2[1]); // mmtmpD0 contains real part of 4 consecutive outputs (32-bit) mmtmpD1 = _mm_shufflelo_epi16(dl_ch128[1],_MM_SHUFFLE(2,3,0,1)); mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1,_MM_SHUFFLE(2,3,0,1)); - mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i*)conjugate); + mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i *)conjugate); mmtmpD1 = _mm_madd_epi16(mmtmpD1,dl_ch128_2[1]); // mmtmpD1 contains imag part of 4 consecutive outputs (32-bit) mmtmpD0 = _mm_srai_epi32(mmtmpD0,output_shift); mmtmpD1 = _mm_srai_epi32(mmtmpD1,output_shift); mmtmpD2 = _mm_unpacklo_epi32(mmtmpD0,mmtmpD1); mmtmpD3 = _mm_unpackhi_epi32(mmtmpD0,mmtmpD1); - - rho128[1] =_mm_packs_epi32(mmtmpD2,mmtmpD3); //print_shorts("rx:",dl_ch128_2+1); //print_shorts("ch:",dl_ch128+1); @@ -1517,23 +1475,20 @@ void dlsch_channel_compensation(int **rxdataF_ext, // mmtmpD0 contains real part of 4 consecutive outputs (32-bit) mmtmpD1 = _mm_shufflelo_epi16(dl_ch128[2],_MM_SHUFFLE(2,3,0,1)); mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1,_MM_SHUFFLE(2,3,0,1)); - mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i*)conjugate); + mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i *)conjugate); mmtmpD1 = _mm_madd_epi16(mmtmpD1,dl_ch128_2[2]); // mmtmpD1 contains imag part of 4 consecutive outputs (32-bit) mmtmpD0 = _mm_srai_epi32(mmtmpD0,output_shift); mmtmpD1 = _mm_srai_epi32(mmtmpD1,output_shift); mmtmpD2 = _mm_unpacklo_epi32(mmtmpD0,mmtmpD1); mmtmpD3 = _mm_unpackhi_epi32(mmtmpD0,mmtmpD1); - rho128[2] = _mm_packs_epi32(mmtmpD2,mmtmpD3); //print_shorts("rx:",dl_ch128_2+2); //print_shorts("ch:",dl_ch128+2); //print_shorts("pack:",rho128+2); - dl_ch128+=3; dl_ch128_2+=3; rho128+=3; - } if (first_symbol_flag==1) { @@ -1544,29 +1499,22 @@ void dlsch_channel_compensation(int **rxdataF_ext, _mm_empty(); _m_empty(); - #elif defined(__arm__) - - unsigned short rb; unsigned char aatx,aarx,symbol_mod,pilots=0; - int16x4_t *dl_ch128,*dl_ch128_2,*rxdataF128; int32x4_t mmtmpD0,mmtmpD1,mmtmpD0b,mmtmpD1b; int16x8_t *dl_ch_mag128,*dl_ch_mag128b,mmtmpD2,mmtmpD3,mmtmpD4; int16x8_t QAM_amp128,QAM_amp128b; int16x4x2_t *rxdataF_comp128,*rho128; - int16_t conj[4]__attribute__((aligned(16))) = {1,-1,1,-1}; int32x4_t output_shift128 = vmovq_n_s32(-(int32_t)output_shift); - symbol_mod = (symbol>=(7-frame_parms->Ncp)) ? symbol-(7-frame_parms->Ncp) : symbol; if ((symbol_mod == 0) || (symbol_mod == (4-frame_parms->Ncp))) { if (frame_parms->nb_antenna_ports_eNB==1) { // 10 out of 12 so don't reduce size nb_rb=1+(5*nb_rb/6); - } - else { + } else { pilots=1; } } @@ -1579,171 +1527,160 @@ void dlsch_channel_compensation(int **rxdataF_ext, QAM_amp128 = vmovq_n_s16(QAM64_n1); // QAM_amp128b = vmovq_n_s16(QAM64_n2); } + // printf("comp: rxdataF_comp %p, symbol %d\n",rxdataF_comp[0],symbol); for (aarx=0; aarx<frame_parms->nb_antennas_rx; aarx++) { - dl_ch128 = (int16x4_t*)&dl_ch_estimates_ext[aatx*frame_parms->nb_antennas_rx + aarx][symbol*frame_parms->N_RB_DL*12]; - dl_ch_mag128 = (int16x8_t*)&dl_ch_mag[aatx*frame_parms->nb_antennas_rx + aarx][symbol*frame_parms->N_RB_DL*12]; - dl_ch_mag128b = (int16x8_t*)&dl_ch_magb[aatx*frame_parms->nb_antennas_rx + aarx][symbol*frame_parms->N_RB_DL*12]; - rxdataF128 = (int16x4_t*)&rxdataF_ext[aarx][symbol*frame_parms->N_RB_DL*12]; - rxdataF_comp128 = (int16x4x2_t*)&rxdataF_comp[aatx*frame_parms->nb_antennas_rx + aarx][symbol*frame_parms->N_RB_DL*12]; + dl_ch128 = (int16x4_t *)&dl_ch_estimates_ext[aatx*frame_parms->nb_antennas_rx + aarx][symbol*frame_parms->N_RB_DL*12]; + dl_ch_mag128 = (int16x8_t *)&dl_ch_mag[aatx*frame_parms->nb_antennas_rx + aarx][symbol*frame_parms->N_RB_DL*12]; + dl_ch_mag128b = (int16x8_t *)&dl_ch_magb[aatx*frame_parms->nb_antennas_rx + aarx][symbol*frame_parms->N_RB_DL*12]; + rxdataF128 = (int16x4_t *)&rxdataF_ext[aarx][symbol*frame_parms->N_RB_DL*12]; + rxdataF_comp128 = (int16x4x2_t *)&rxdataF_comp[aatx*frame_parms->nb_antennas_rx + aarx][symbol*frame_parms->N_RB_DL*12]; for (rb=0; rb<nb_rb; rb++) { - if (mod_order>2) { - // get channel amplitude if not QPSK - mmtmpD0 = vmull_s16(dl_ch128[0], dl_ch128[0]); - // mmtmpD0 = [ch0*ch0,ch1*ch1,ch2*ch2,ch3*ch3]; - mmtmpD0 = vqshlq_s32(vqaddq_s32(mmtmpD0,vrev64q_s32(mmtmpD0)),output_shift128); - // mmtmpD0 = [ch0*ch0 + ch1*ch1,ch0*ch0 + ch1*ch1,ch2*ch2 + ch3*ch3,ch2*ch2 + ch3*ch3]>>output_shift128 on 32-bits - mmtmpD1 = vmull_s16(dl_ch128[1], dl_ch128[1]); - mmtmpD1 = vqshlq_s32(vqaddq_s32(mmtmpD1,vrev64q_s32(mmtmpD1)),output_shift128); - mmtmpD2 = vcombine_s16(vmovn_s32(mmtmpD0),vmovn_s32(mmtmpD1)); - // mmtmpD2 = [ch0*ch0 + ch1*ch1,ch0*ch0 + ch1*ch1,ch2*ch2 + ch3*ch3,ch2*ch2 + ch3*ch3,ch4*ch4 + ch5*ch5,ch4*ch4 + ch5*ch5,ch6*ch6 + ch7*ch7,ch6*ch6 + ch7*ch7]>>output_shift128 on 16-bits - mmtmpD0 = vmull_s16(dl_ch128[2], dl_ch128[2]); - mmtmpD0 = vqshlq_s32(vqaddq_s32(mmtmpD0,vrev64q_s32(mmtmpD0)),output_shift128); - mmtmpD1 = vmull_s16(dl_ch128[3], dl_ch128[3]); - mmtmpD1 = vqshlq_s32(vqaddq_s32(mmtmpD1,vrev64q_s32(mmtmpD1)),output_shift128); - mmtmpD3 = vcombine_s16(vmovn_s32(mmtmpD0),vmovn_s32(mmtmpD1)); - if (pilots==0) { - mmtmpD0 = vmull_s16(dl_ch128[4], dl_ch128[4]); - mmtmpD0 = vqshlq_s32(vqaddq_s32(mmtmpD0,vrev64q_s32(mmtmpD0)),output_shift128); - mmtmpD1 = vmull_s16(dl_ch128[5], dl_ch128[5]); - mmtmpD1 = vqshlq_s32(vqaddq_s32(mmtmpD1,vrev64q_s32(mmtmpD1)),output_shift128); - mmtmpD4 = vcombine_s16(vmovn_s32(mmtmpD0),vmovn_s32(mmtmpD1)); - } + if (mod_order>2) { + // get channel amplitude if not QPSK + mmtmpD0 = vmull_s16(dl_ch128[0], dl_ch128[0]); + // mmtmpD0 = [ch0*ch0,ch1*ch1,ch2*ch2,ch3*ch3]; + mmtmpD0 = vqshlq_s32(vqaddq_s32(mmtmpD0,vrev64q_s32(mmtmpD0)),output_shift128); + // mmtmpD0 = [ch0*ch0 + ch1*ch1,ch0*ch0 + ch1*ch1,ch2*ch2 + ch3*ch3,ch2*ch2 + ch3*ch3]>>output_shift128 on 32-bits + mmtmpD1 = vmull_s16(dl_ch128[1], dl_ch128[1]); + mmtmpD1 = vqshlq_s32(vqaddq_s32(mmtmpD1,vrev64q_s32(mmtmpD1)),output_shift128); + mmtmpD2 = vcombine_s16(vmovn_s32(mmtmpD0),vmovn_s32(mmtmpD1)); + // mmtmpD2 = [ch0*ch0 + ch1*ch1,ch0*ch0 + ch1*ch1,ch2*ch2 + ch3*ch3,ch2*ch2 + ch3*ch3,ch4*ch4 + ch5*ch5,ch4*ch4 + ch5*ch5,ch6*ch6 + ch7*ch7,ch6*ch6 + ch7*ch7]>>output_shift128 on 16-bits + mmtmpD0 = vmull_s16(dl_ch128[2], dl_ch128[2]); + mmtmpD0 = vqshlq_s32(vqaddq_s32(mmtmpD0,vrev64q_s32(mmtmpD0)),output_shift128); + mmtmpD1 = vmull_s16(dl_ch128[3], dl_ch128[3]); + mmtmpD1 = vqshlq_s32(vqaddq_s32(mmtmpD1,vrev64q_s32(mmtmpD1)),output_shift128); + mmtmpD3 = vcombine_s16(vmovn_s32(mmtmpD0),vmovn_s32(mmtmpD1)); - dl_ch_mag128b[0] = vqdmulhq_s16(mmtmpD2,QAM_amp128b); - dl_ch_mag128b[1] = vqdmulhq_s16(mmtmpD3,QAM_amp128b); - dl_ch_mag128[0] = vqdmulhq_s16(mmtmpD2,QAM_amp128); - dl_ch_mag128[1] = vqdmulhq_s16(mmtmpD3,QAM_amp128); + if (pilots==0) { + mmtmpD0 = vmull_s16(dl_ch128[4], dl_ch128[4]); + mmtmpD0 = vqshlq_s32(vqaddq_s32(mmtmpD0,vrev64q_s32(mmtmpD0)),output_shift128); + mmtmpD1 = vmull_s16(dl_ch128[5], dl_ch128[5]); + mmtmpD1 = vqshlq_s32(vqaddq_s32(mmtmpD1,vrev64q_s32(mmtmpD1)),output_shift128); + mmtmpD4 = vcombine_s16(vmovn_s32(mmtmpD0),vmovn_s32(mmtmpD1)); + } - if (pilots==0) { - dl_ch_mag128b[2] = vqdmulhq_s16(mmtmpD4,QAM_amp128b); - dl_ch_mag128[2] = vqdmulhq_s16(mmtmpD4,QAM_amp128); - } - } + dl_ch_mag128b[0] = vqdmulhq_s16(mmtmpD2,QAM_amp128b); + dl_ch_mag128b[1] = vqdmulhq_s16(mmtmpD3,QAM_amp128b); + dl_ch_mag128[0] = vqdmulhq_s16(mmtmpD2,QAM_amp128); + dl_ch_mag128[1] = vqdmulhq_s16(mmtmpD3,QAM_amp128); - mmtmpD0 = vmull_s16(dl_ch128[0], rxdataF128[0]); - //mmtmpD0 = [Re(ch[0])Re(rx[0]) Im(ch[0])Im(ch[0]) Re(ch[1])Re(rx[1]) Im(ch[1])Im(ch[1])] - mmtmpD1 = vmull_s16(dl_ch128[1], rxdataF128[1]); - //mmtmpD1 = [Re(ch[2])Re(rx[2]) Im(ch[2])Im(ch[2]) Re(ch[3])Re(rx[3]) Im(ch[3])Im(ch[3])] - mmtmpD0 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0),vget_high_s32(mmtmpD0)), - vpadd_s32(vget_low_s32(mmtmpD1),vget_high_s32(mmtmpD1))); - //mmtmpD0 = [Re(ch[0])Re(rx[0])+Im(ch[0])Im(ch[0]) Re(ch[1])Re(rx[1])+Im(ch[1])Im(ch[1]) Re(ch[2])Re(rx[2])+Im(ch[2])Im(ch[2]) Re(ch[3])Re(rx[3])+Im(ch[3])Im(ch[3])] - - mmtmpD0b = vmull_s16(vrev32_s16(vmul_s16(dl_ch128[0],*(int16x4_t*)conj)), rxdataF128[0]); - //mmtmpD0 = [-Im(ch[0])Re(rx[0]) Re(ch[0])Im(rx[0]) -Im(ch[1])Re(rx[1]) Re(ch[1])Im(rx[1])] - mmtmpD1b = vmull_s16(vrev32_s16(vmul_s16(dl_ch128[1],*(int16x4_t*)conj)), rxdataF128[1]); - //mmtmpD0 = [-Im(ch[2])Re(rx[2]) Re(ch[2])Im(rx[2]) -Im(ch[3])Re(rx[3]) Re(ch[3])Im(rx[3])] - mmtmpD1 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0b),vget_high_s32(mmtmpD0b)), - vpadd_s32(vget_low_s32(mmtmpD1b),vget_high_s32(mmtmpD1b))); - //mmtmpD1 = [-Im(ch[0])Re(rx[0])+Re(ch[0])Im(rx[0]) -Im(ch[1])Re(rx[1])+Re(ch[1])Im(rx[1]) -Im(ch[2])Re(rx[2])+Re(ch[2])Im(rx[2]) -Im(ch[3])Re(rx[3])+Re(ch[3])Im(rx[3])] - - mmtmpD0 = vqshlq_s32(mmtmpD0,output_shift128); - mmtmpD1 = vqshlq_s32(mmtmpD1,output_shift128); - rxdataF_comp128[0] = vzip_s16(vmovn_s32(mmtmpD0),vmovn_s32(mmtmpD1)); - mmtmpD0 = vmull_s16(dl_ch128[2], rxdataF128[2]); - mmtmpD1 = vmull_s16(dl_ch128[3], rxdataF128[3]); - mmtmpD0 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0),vget_high_s32(mmtmpD0)), - vpadd_s32(vget_low_s32(mmtmpD1),vget_high_s32(mmtmpD1))); - mmtmpD0b = vmull_s16(vrev32_s16(vmul_s16(dl_ch128[2],*(int16x4_t*)conj)), rxdataF128[2]); - mmtmpD1b = vmull_s16(vrev32_s16(vmul_s16(dl_ch128[3],*(int16x4_t*)conj)), rxdataF128[3]); - mmtmpD1 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0b),vget_high_s32(mmtmpD0b)), - vpadd_s32(vget_low_s32(mmtmpD1b),vget_high_s32(mmtmpD1b))); - mmtmpD0 = vqshlq_s32(mmtmpD0,output_shift128); - mmtmpD1 = vqshlq_s32(mmtmpD1,output_shift128); - rxdataF_comp128[1] = vzip_s16(vmovn_s32(mmtmpD0),vmovn_s32(mmtmpD1)); - - if (pilots==0) { - mmtmpD0 = vmull_s16(dl_ch128[4], rxdataF128[4]); - mmtmpD1 = vmull_s16(dl_ch128[5], rxdataF128[5]); - mmtmpD0 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0),vget_high_s32(mmtmpD0)), - vpadd_s32(vget_low_s32(mmtmpD1),vget_high_s32(mmtmpD1))); - - mmtmpD0b = vmull_s16(vrev32_s16(vmul_s16(dl_ch128[4],*(int16x4_t*)conj)), rxdataF128[4]); - mmtmpD1b = vmull_s16(vrev32_s16(vmul_s16(dl_ch128[5],*(int16x4_t*)conj)), rxdataF128[5]); - mmtmpD1 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0b),vget_high_s32(mmtmpD0b)), - vpadd_s32(vget_low_s32(mmtmpD1b),vget_high_s32(mmtmpD1b))); - - - mmtmpD0 = vqshlq_s32(mmtmpD0,output_shift128); - mmtmpD1 = vqshlq_s32(mmtmpD1,output_shift128); - rxdataF_comp128[2] = vzip_s16(vmovn_s32(mmtmpD0),vmovn_s32(mmtmpD1)); - - - dl_ch128+=6; - dl_ch_mag128+=3; - dl_ch_mag128b+=3; - rxdataF128+=6; - rxdataF_comp128+=3; - - } else { // we have a smaller PDSCH in symbols with pilots so skip last group of 4 REs and increment less - dl_ch128+=4; - dl_ch_mag128+=2; - dl_ch_mag128b+=2; - rxdataF128+=4; - rxdataF_comp128+=2; - } + if (pilots==0) { + dl_ch_mag128b[2] = vqdmulhq_s16(mmtmpD4,QAM_amp128b); + dl_ch_mag128[2] = vqdmulhq_s16(mmtmpD4,QAM_amp128); + } + } + + mmtmpD0 = vmull_s16(dl_ch128[0], rxdataF128[0]); + //mmtmpD0 = [Re(ch[0])Re(rx[0]) Im(ch[0])Im(ch[0]) Re(ch[1])Re(rx[1]) Im(ch[1])Im(ch[1])] + mmtmpD1 = vmull_s16(dl_ch128[1], rxdataF128[1]); + //mmtmpD1 = [Re(ch[2])Re(rx[2]) Im(ch[2])Im(ch[2]) Re(ch[3])Re(rx[3]) Im(ch[3])Im(ch[3])] + mmtmpD0 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0),vget_high_s32(mmtmpD0)), + vpadd_s32(vget_low_s32(mmtmpD1),vget_high_s32(mmtmpD1))); + //mmtmpD0 = [Re(ch[0])Re(rx[0])+Im(ch[0])Im(ch[0]) Re(ch[1])Re(rx[1])+Im(ch[1])Im(ch[1]) Re(ch[2])Re(rx[2])+Im(ch[2])Im(ch[2]) Re(ch[3])Re(rx[3])+Im(ch[3])Im(ch[3])] + mmtmpD0b = vmull_s16(vrev32_s16(vmul_s16(dl_ch128[0],*(int16x4_t *)conj)), rxdataF128[0]); + //mmtmpD0 = [-Im(ch[0])Re(rx[0]) Re(ch[0])Im(rx[0]) -Im(ch[1])Re(rx[1]) Re(ch[1])Im(rx[1])] + mmtmpD1b = vmull_s16(vrev32_s16(vmul_s16(dl_ch128[1],*(int16x4_t *)conj)), rxdataF128[1]); + //mmtmpD0 = [-Im(ch[2])Re(rx[2]) Re(ch[2])Im(rx[2]) -Im(ch[3])Re(rx[3]) Re(ch[3])Im(rx[3])] + mmtmpD1 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0b),vget_high_s32(mmtmpD0b)), + vpadd_s32(vget_low_s32(mmtmpD1b),vget_high_s32(mmtmpD1b))); + //mmtmpD1 = [-Im(ch[0])Re(rx[0])+Re(ch[0])Im(rx[0]) -Im(ch[1])Re(rx[1])+Re(ch[1])Im(rx[1]) -Im(ch[2])Re(rx[2])+Re(ch[2])Im(rx[2]) -Im(ch[3])Re(rx[3])+Re(ch[3])Im(rx[3])] + mmtmpD0 = vqshlq_s32(mmtmpD0,output_shift128); + mmtmpD1 = vqshlq_s32(mmtmpD1,output_shift128); + rxdataF_comp128[0] = vzip_s16(vmovn_s32(mmtmpD0),vmovn_s32(mmtmpD1)); + mmtmpD0 = vmull_s16(dl_ch128[2], rxdataF128[2]); + mmtmpD1 = vmull_s16(dl_ch128[3], rxdataF128[3]); + mmtmpD0 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0),vget_high_s32(mmtmpD0)), + vpadd_s32(vget_low_s32(mmtmpD1),vget_high_s32(mmtmpD1))); + mmtmpD0b = vmull_s16(vrev32_s16(vmul_s16(dl_ch128[2],*(int16x4_t *)conj)), rxdataF128[2]); + mmtmpD1b = vmull_s16(vrev32_s16(vmul_s16(dl_ch128[3],*(int16x4_t *)conj)), rxdataF128[3]); + mmtmpD1 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0b),vget_high_s32(mmtmpD0b)), + vpadd_s32(vget_low_s32(mmtmpD1b),vget_high_s32(mmtmpD1b))); + mmtmpD0 = vqshlq_s32(mmtmpD0,output_shift128); + mmtmpD1 = vqshlq_s32(mmtmpD1,output_shift128); + rxdataF_comp128[1] = vzip_s16(vmovn_s32(mmtmpD0),vmovn_s32(mmtmpD1)); + + if (pilots==0) { + mmtmpD0 = vmull_s16(dl_ch128[4], rxdataF128[4]); + mmtmpD1 = vmull_s16(dl_ch128[5], rxdataF128[5]); + mmtmpD0 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0),vget_high_s32(mmtmpD0)), + vpadd_s32(vget_low_s32(mmtmpD1),vget_high_s32(mmtmpD1))); + mmtmpD0b = vmull_s16(vrev32_s16(vmul_s16(dl_ch128[4],*(int16x4_t *)conj)), rxdataF128[4]); + mmtmpD1b = vmull_s16(vrev32_s16(vmul_s16(dl_ch128[5],*(int16x4_t *)conj)), rxdataF128[5]); + mmtmpD1 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0b),vget_high_s32(mmtmpD0b)), + vpadd_s32(vget_low_s32(mmtmpD1b),vget_high_s32(mmtmpD1b))); + mmtmpD0 = vqshlq_s32(mmtmpD0,output_shift128); + mmtmpD1 = vqshlq_s32(mmtmpD1,output_shift128); + rxdataF_comp128[2] = vzip_s16(vmovn_s32(mmtmpD0),vmovn_s32(mmtmpD1)); + dl_ch128+=6; + dl_ch_mag128+=3; + dl_ch_mag128b+=3; + rxdataF128+=6; + rxdataF_comp128+=3; + } else { // we have a smaller PDSCH in symbols with pilots so skip last group of 4 REs and increment less + dl_ch128+=4; + dl_ch_mag128+=2; + dl_ch_mag128b+=2; + rxdataF128+=4; + rxdataF_comp128+=2; + } } } } if (rho) { for (aarx=0; aarx<frame_parms->nb_antennas_rx; aarx++) { - rho128 = (int16x4x2_t*)&rho[aarx][symbol*frame_parms->N_RB_DL*12]; - dl_ch128 = (int16x4_t*)&dl_ch_estimates_ext[aarx][symbol*frame_parms->N_RB_DL*12]; - dl_ch128_2 = (int16x4_t*)&dl_ch_estimates_ext[2+aarx][symbol*frame_parms->N_RB_DL*12]; + rho128 = (int16x4x2_t *)&rho[aarx][symbol*frame_parms->N_RB_DL*12]; + dl_ch128 = (int16x4_t *)&dl_ch_estimates_ext[aarx][symbol*frame_parms->N_RB_DL*12]; + dl_ch128_2 = (int16x4_t *)&dl_ch_estimates_ext[2+aarx][symbol*frame_parms->N_RB_DL*12]; + for (rb=0; rb<nb_rb; rb++) { - mmtmpD0 = vmull_s16(dl_ch128[0], dl_ch128_2[0]); - mmtmpD1 = vmull_s16(dl_ch128[1], dl_ch128_2[1]); - mmtmpD0 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0),vget_high_s32(mmtmpD0)), - vpadd_s32(vget_low_s32(mmtmpD1),vget_high_s32(mmtmpD1))); - mmtmpD0b = vmull_s16(vrev32_s16(vmul_s16(dl_ch128[0],*(int16x4_t*)conj)), dl_ch128_2[0]); - mmtmpD1b = vmull_s16(vrev32_s16(vmul_s16(dl_ch128[1],*(int16x4_t*)conj)), dl_ch128_2[1]); - mmtmpD1 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0b),vget_high_s32(mmtmpD0b)), - vpadd_s32(vget_low_s32(mmtmpD1b),vget_high_s32(mmtmpD1b))); - - mmtmpD0 = vqshlq_s32(mmtmpD0,output_shift128); - mmtmpD1 = vqshlq_s32(mmtmpD1,output_shift128); - rho128[0] = vzip_s16(vmovn_s32(mmtmpD0),vmovn_s32(mmtmpD1)); - - mmtmpD0 = vmull_s16(dl_ch128[2], dl_ch128_2[2]); - mmtmpD1 = vmull_s16(dl_ch128[3], dl_ch128_2[3]); - mmtmpD0 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0),vget_high_s32(mmtmpD0)), - vpadd_s32(vget_low_s32(mmtmpD1),vget_high_s32(mmtmpD1))); - mmtmpD0b = vmull_s16(vrev32_s16(vmul_s16(dl_ch128[2],*(int16x4_t*)conj)), dl_ch128_2[2]); - mmtmpD1b = vmull_s16(vrev32_s16(vmul_s16(dl_ch128[3],*(int16x4_t*)conj)), dl_ch128_2[3]); - mmtmpD1 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0b),vget_high_s32(mmtmpD0b)), - vpadd_s32(vget_low_s32(mmtmpD1b),vget_high_s32(mmtmpD1b))); - - mmtmpD0 = vqshlq_s32(mmtmpD0,output_shift128); - mmtmpD1 = vqshlq_s32(mmtmpD1,output_shift128); - rho128[1] = vzip_s16(vmovn_s32(mmtmpD0),vmovn_s32(mmtmpD1)); - - mmtmpD0 = vmull_s16(dl_ch128[0], dl_ch128_2[0]); - mmtmpD1 = vmull_s16(dl_ch128[1], dl_ch128_2[1]); - mmtmpD0 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0),vget_high_s32(mmtmpD0)), - vpadd_s32(vget_low_s32(mmtmpD1),vget_high_s32(mmtmpD1))); - mmtmpD0b = vmull_s16(vrev32_s16(vmul_s16(dl_ch128[4],*(int16x4_t*)conj)), dl_ch128_2[4]); - mmtmpD1b = vmull_s16(vrev32_s16(vmul_s16(dl_ch128[5],*(int16x4_t*)conj)), dl_ch128_2[5]); - mmtmpD1 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0b),vget_high_s32(mmtmpD0b)), - vpadd_s32(vget_low_s32(mmtmpD1b),vget_high_s32(mmtmpD1b))); - - mmtmpD0 = vqshlq_s32(mmtmpD0,output_shift128); - mmtmpD1 = vqshlq_s32(mmtmpD1,output_shift128); - rho128[2] = vzip_s16(vmovn_s32(mmtmpD0),vmovn_s32(mmtmpD1)); - - - dl_ch128+=6; - dl_ch128_2+=6; - rho128+=3; + mmtmpD0 = vmull_s16(dl_ch128[0], dl_ch128_2[0]); + mmtmpD1 = vmull_s16(dl_ch128[1], dl_ch128_2[1]); + mmtmpD0 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0),vget_high_s32(mmtmpD0)), + vpadd_s32(vget_low_s32(mmtmpD1),vget_high_s32(mmtmpD1))); + mmtmpD0b = vmull_s16(vrev32_s16(vmul_s16(dl_ch128[0],*(int16x4_t *)conj)), dl_ch128_2[0]); + mmtmpD1b = vmull_s16(vrev32_s16(vmul_s16(dl_ch128[1],*(int16x4_t *)conj)), dl_ch128_2[1]); + mmtmpD1 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0b),vget_high_s32(mmtmpD0b)), + vpadd_s32(vget_low_s32(mmtmpD1b),vget_high_s32(mmtmpD1b))); + mmtmpD0 = vqshlq_s32(mmtmpD0,output_shift128); + mmtmpD1 = vqshlq_s32(mmtmpD1,output_shift128); + rho128[0] = vzip_s16(vmovn_s32(mmtmpD0),vmovn_s32(mmtmpD1)); + mmtmpD0 = vmull_s16(dl_ch128[2], dl_ch128_2[2]); + mmtmpD1 = vmull_s16(dl_ch128[3], dl_ch128_2[3]); + mmtmpD0 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0),vget_high_s32(mmtmpD0)), + vpadd_s32(vget_low_s32(mmtmpD1),vget_high_s32(mmtmpD1))); + mmtmpD0b = vmull_s16(vrev32_s16(vmul_s16(dl_ch128[2],*(int16x4_t *)conj)), dl_ch128_2[2]); + mmtmpD1b = vmull_s16(vrev32_s16(vmul_s16(dl_ch128[3],*(int16x4_t *)conj)), dl_ch128_2[3]); + mmtmpD1 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0b),vget_high_s32(mmtmpD0b)), + vpadd_s32(vget_low_s32(mmtmpD1b),vget_high_s32(mmtmpD1b))); + mmtmpD0 = vqshlq_s32(mmtmpD0,output_shift128); + mmtmpD1 = vqshlq_s32(mmtmpD1,output_shift128); + rho128[1] = vzip_s16(vmovn_s32(mmtmpD0),vmovn_s32(mmtmpD1)); + mmtmpD0 = vmull_s16(dl_ch128[0], dl_ch128_2[0]); + mmtmpD1 = vmull_s16(dl_ch128[1], dl_ch128_2[1]); + mmtmpD0 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0),vget_high_s32(mmtmpD0)), + vpadd_s32(vget_low_s32(mmtmpD1),vget_high_s32(mmtmpD1))); + mmtmpD0b = vmull_s16(vrev32_s16(vmul_s16(dl_ch128[4],*(int16x4_t *)conj)), dl_ch128_2[4]); + mmtmpD1b = vmull_s16(vrev32_s16(vmul_s16(dl_ch128[5],*(int16x4_t *)conj)), dl_ch128_2[5]); + mmtmpD1 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0b),vget_high_s32(mmtmpD0b)), + vpadd_s32(vget_low_s32(mmtmpD1b),vget_high_s32(mmtmpD1b))); + mmtmpD0 = vqshlq_s32(mmtmpD0,output_shift128); + mmtmpD1 = vqshlq_s32(mmtmpD1,output_shift128); + rho128[2] = vzip_s16(vmovn_s32(mmtmpD0),vmovn_s32(mmtmpD1)); + dl_ch128+=6; + dl_ch128_2+=6; + rho128+=3; } if (first_symbol_flag==1) { - measurements->rx_correlation[0][aarx] = signal_energy(&rho[aarx][symbol*frame_parms->N_RB_DL*12],rb*12); + measurements->rx_correlation[0][aarx] = signal_energy(&rho[aarx][symbol*frame_parms->N_RB_DL*12],rb*12); } } } + #endif } @@ -1761,7 +1698,6 @@ void dlsch_channel_compensation_core(int **rxdataF_ext, int start_point) { - unsigned short ii; int length_mod8 = 0; int length2; @@ -1771,6 +1707,7 @@ void dlsch_channel_compensation_core(int **rxdataF_ext, for (aatx=0; aatx<n_tx; aatx++) { __m128i QAM_amp128b; + if (mod_order == 4) { QAM_amp128 = _mm_set1_epi16(QAM16_n1); // 2/sqrt(10) QAM_amp128b = _mm_setzero_si128(); @@ -1785,31 +1722,25 @@ void dlsch_channel_compensation_core(int **rxdataF_ext, * Elena's commit. */ int x = n_rx > 1 ? n_rx : 2; - - dl_ch128 = (__m128i *)&dl_ch_estimates_ext[aatx*x + aarx][start_point]; - dl_ch_mag128 = (__m128i *)&dl_ch_mag[aatx*x + aarx][start_point]; - dl_ch_mag128b = (__m128i *)&dl_ch_magb[aatx*x + aarx][start_point]; - rxdataF128 = (__m128i *)&rxdataF_ext[aarx][start_point]; - rxdataF_comp128 = (__m128i *)&rxdataF_comp[aatx*x + aarx][start_point]; - + dl_ch128 = (__m128i *)&dl_ch_estimates_ext[aatx*x + aarx][start_point]; + dl_ch_mag128 = (__m128i *)&dl_ch_mag[aatx*x + aarx][start_point]; + dl_ch_mag128b = (__m128i *)&dl_ch_magb[aatx*x + aarx][start_point]; + rxdataF128 = (__m128i *)&rxdataF_ext[aarx][start_point]; + rxdataF_comp128 = (__m128i *)&rxdataF_comp[aatx*x + aarx][start_point]; length_mod8 = length&7; - if (length_mod8 == 0){ + + if (length_mod8 == 0) { length2 = length>>3; for (ii=0; ii<length2; ++ii) { if (mod_order>2) { // get channel amplitude if not QPSK - mmtmpD0 = _mm_madd_epi16(dl_ch128[0],dl_ch128[0]); mmtmpD0 = _mm_srai_epi32(mmtmpD0,output_shift); - mmtmpD1 = _mm_madd_epi16(dl_ch128[1],dl_ch128[1]); mmtmpD1 = _mm_srai_epi32(mmtmpD1,output_shift); - mmtmpD0 = _mm_packs_epi32(mmtmpD0,mmtmpD1); - // store channel magnitude here in a new field of dlsch - dl_ch_mag128[0] = _mm_unpacklo_epi16(mmtmpD0,mmtmpD0); dl_ch_mag128b[0] = dl_ch_mag128[0]; dl_ch_mag128[0] = _mm_mulhi_epi16(dl_ch_mag128[0],QAM_amp128); @@ -1821,22 +1752,18 @@ void dlsch_channel_compensation_core(int **rxdataF_ext, dl_ch_mag128b[1] = dl_ch_mag128[1]; dl_ch_mag128[1] = _mm_mulhi_epi16(dl_ch_mag128[1],QAM_amp128); dl_ch_mag128[1] = _mm_slli_epi16(dl_ch_mag128[1],1); - dl_ch_mag128b[0] = _mm_mulhi_epi16(dl_ch_mag128b[0],QAM_amp128b); dl_ch_mag128b[0] = _mm_slli_epi16(dl_ch_mag128b[0],1); - dl_ch_mag128b[1] = _mm_mulhi_epi16(dl_ch_mag128b[1],QAM_amp128b); dl_ch_mag128b[1] = _mm_slli_epi16(dl_ch_mag128b[1],1); - } // multiply by conjugated channel mmtmpD0 = _mm_madd_epi16(dl_ch128[0],rxdataF128[0]); - // mmtmpD0 contains real part of 4 consecutive outputs (32-bit) mmtmpD1 = _mm_shufflelo_epi16(dl_ch128[0],_MM_SHUFFLE(2,3,0,1)); mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1,_MM_SHUFFLE(2,3,0,1)); - mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i*)&conjugate[0]); + mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i *)&conjugate[0]); // print_ints("im",&mmtmpD1); mmtmpD1 = _mm_madd_epi16(mmtmpD1,rxdataF128[0]); // mmtmpD1 contains imag part of 4 consecutive outputs (32-bit) @@ -1852,59 +1779,53 @@ void dlsch_channel_compensation_core(int **rxdataF_ext, // print_shorts("rx:",rxdataF128); // print_shorts("ch:",dl_ch128); // print_shorts("pack:",rxdataF_comp128); - // multiply by conjugated channel mmtmpD0 = _mm_madd_epi16(dl_ch128[1],rxdataF128[1]); // mmtmpD0 contains real part of 4 consecutive outputs (32-bit) mmtmpD1 = _mm_shufflelo_epi16(dl_ch128[1],_MM_SHUFFLE(2,3,0,1)); mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1,_MM_SHUFFLE(2,3,0,1)); - mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i*)conjugate); + mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i *)conjugate); mmtmpD1 = _mm_madd_epi16(mmtmpD1,rxdataF128[1]); // mmtmpD1 contains imag part of 4 consecutive outputs (32-bit) mmtmpD0 = _mm_srai_epi32(mmtmpD0,output_shift); mmtmpD1 = _mm_srai_epi32(mmtmpD1,output_shift); mmtmpD2 = _mm_unpacklo_epi32(mmtmpD0,mmtmpD1); mmtmpD3 = _mm_unpackhi_epi32(mmtmpD0,mmtmpD1); - rxdataF_comp128[1] = _mm_packs_epi32(mmtmpD2,mmtmpD3); // print_shorts("rx:",rxdataF128+1); // print_shorts("ch:",dl_ch128+1); //print_shorts("pack:",rxdataF_comp128+1); - dl_ch128+=2; dl_ch_mag128+=2; dl_ch_mag128b+=2; rxdataF128+=2; rxdataF_comp128+=2; } - }else { + } else { printf ("Channel Compensation: Received number of subcarriers is not multiple of 8, \n" - "need to adapt the code!\n"); + "need to adapt the code!\n"); } } } -/*This part of code makes sense only for processing in 2x2 blocks*/ + /*This part of code makes sense only for processing in 2x2 blocks*/ if (rho) { - - for (aarx=0; aarx<n_rx; aarx++) { rho128 = (__m128i *)&rho[aarx][start_point]; dl_ch128 = (__m128i *)&dl_ch_estimates_ext[aarx][start_point]; dl_ch128_2 = (__m128i *)&dl_ch_estimates_ext[2+aarx][start_point]; - if (length_mod8 == 0){ + if (length_mod8 == 0) { length2 = length>>3; for (ii=0; ii<length2; ++ii) { // multiply by conjugated channel mmtmpD0 = _mm_madd_epi16(dl_ch128[0],dl_ch128_2[0]); // print_ints("re",&mmtmpD0); - // mmtmpD0 contains real part of 4 consecutive outputs (32-bit) mmtmpD1 = _mm_shufflelo_epi16(dl_ch128[0],_MM_SHUFFLE(2,3,0,1)); mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1,_MM_SHUFFLE(2,3,0,1)); - mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i*)&conjugate[0]); + mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i *)&conjugate[0]); // print_ints("im",&mmtmpD1); mmtmpD1 = _mm_madd_epi16(mmtmpD1,dl_ch128_2[0]); // mmtmpD1 contains imag part of 4 consecutive outputs (32-bit) @@ -1917,124 +1838,115 @@ void dlsch_channel_compensation_core(int **rxdataF_ext, // print_ints("c0",&mmtmpD2); // print_ints("c1",&mmtmpD3); rho128[0] = _mm_packs_epi32(mmtmpD2,mmtmpD3); - //print_shorts("rx:",dl_ch128_2); //print_shorts("ch:",dl_ch128); //print_shorts("pack:",rho128); - // multiply by conjugated channel mmtmpD0 = _mm_madd_epi16(dl_ch128[1],dl_ch128_2[1]); // mmtmpD0 contains real part of 4 consecutive outputs (32-bit) mmtmpD1 = _mm_shufflelo_epi16(dl_ch128[1],_MM_SHUFFLE(2,3,0,1)); mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1,_MM_SHUFFLE(2,3,0,1)); - mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i*)conjugate); + mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i *)conjugate); mmtmpD1 = _mm_madd_epi16(mmtmpD1,dl_ch128_2[1]); // mmtmpD1 contains imag part of 4 consecutive outputs (32-bit) mmtmpD0 = _mm_srai_epi32(mmtmpD0,output_shift); mmtmpD1 = _mm_srai_epi32(mmtmpD1,output_shift); mmtmpD2 = _mm_unpacklo_epi32(mmtmpD0,mmtmpD1); mmtmpD3 = _mm_unpackhi_epi32(mmtmpD0,mmtmpD1); - rho128[1] =_mm_packs_epi32(mmtmpD2,mmtmpD3); dl_ch128+=2; dl_ch128_2+=2; rho128+=2; } - }else { + } else { printf ("Channel Compensation: Received number of subcarriers is not multiple of 8, \n" - "need to adapt the code!\n"); + "need to adapt the code!\n"); } } } + _mm_empty(); _m_empty(); } #if defined(__x86_64__) || defined(__i386__) -void prec2A_TM56_128(unsigned char pmi,__m128i *ch0,__m128i *ch1) -{ - +void prec2A_TM56_128(unsigned char pmi,__m128i *ch0,__m128i *ch1) { __m128i amp; amp = _mm_set1_epi16(ONE_OVER_SQRT2_Q15); switch (pmi) { - - case 0 : // +1 +1 - // print_shorts("phase 0 :ch0",ch0); - // print_shorts("phase 0 :ch1",ch1); - ch0[0] = _mm_adds_epi16(ch0[0],ch1[0]); - break; - - case 1 : // +1 -1 - // print_shorts("phase 1 :ch0",ch0); - // print_shorts("phase 1 :ch1",ch1); - ch0[0] = _mm_subs_epi16(ch0[0],ch1[0]); - // print_shorts("phase 1 :ch0-ch1",ch0); - break; - - case 2 : // +1 +j - ch1[0] = _mm_sign_epi16(ch1[0],*(__m128i*)&conjugate[0]); - ch1[0] = _mm_shufflelo_epi16(ch1[0],_MM_SHUFFLE(2,3,0,1)); - ch1[0] = _mm_shufflehi_epi16(ch1[0],_MM_SHUFFLE(2,3,0,1)); - ch0[0] = _mm_subs_epi16(ch0[0],ch1[0]); - - break; // +1 -j - - case 3 : - ch1[0] = _mm_sign_epi16(ch1[0],*(__m128i*)&conjugate[0]); - ch1[0] = _mm_shufflelo_epi16(ch1[0],_MM_SHUFFLE(2,3,0,1)); - ch1[0] = _mm_shufflehi_epi16(ch1[0],_MM_SHUFFLE(2,3,0,1)); - ch0[0] = _mm_adds_epi16(ch0[0],ch1[0]); - break; + case 0 : // +1 +1 + // print_shorts("phase 0 :ch0",ch0); + // print_shorts("phase 0 :ch1",ch1); + ch0[0] = _mm_adds_epi16(ch0[0],ch1[0]); + break; + + case 1 : // +1 -1 + // print_shorts("phase 1 :ch0",ch0); + // print_shorts("phase 1 :ch1",ch1); + ch0[0] = _mm_subs_epi16(ch0[0],ch1[0]); + // print_shorts("phase 1 :ch0-ch1",ch0); + break; + + case 2 : // +1 +j + ch1[0] = _mm_sign_epi16(ch1[0],*(__m128i *)&conjugate[0]); + ch1[0] = _mm_shufflelo_epi16(ch1[0],_MM_SHUFFLE(2,3,0,1)); + ch1[0] = _mm_shufflehi_epi16(ch1[0],_MM_SHUFFLE(2,3,0,1)); + ch0[0] = _mm_subs_epi16(ch0[0],ch1[0]); + break; // +1 -j + + case 3 : + ch1[0] = _mm_sign_epi16(ch1[0],*(__m128i *)&conjugate[0]); + ch1[0] = _mm_shufflelo_epi16(ch1[0],_MM_SHUFFLE(2,3,0,1)); + ch1[0] = _mm_shufflehi_epi16(ch1[0],_MM_SHUFFLE(2,3,0,1)); + ch0[0] = _mm_adds_epi16(ch0[0],ch1[0]); + break; } ch0[0] = _mm_mulhi_epi16(ch0[0],amp); ch0[0] = _mm_slli_epi16(ch0[0],1); - _mm_empty(); _m_empty(); } #elif defined(__arm__) void prec2A_TM56_128(unsigned char pmi,__m128i *ch0,__m128i *ch1) { - // sqrt(2) is already taken into account in computation sqrt_rho_a, sqrt_rho_b, //so removed it //__m128i amp; //amp = _mm_set1_epi16(ONE_OVER_SQRT2_Q15); - switch (pmi) { - - case 0 : // +1 +1 - // print_shorts("phase 0 :ch0",ch0); - // print_shorts("phase 0 :ch1",ch1); - ch0[0] = _mm_adds_epi16(ch0[0],ch1[0]); - break; - case 1 : // +1 -1 - // print_shorts("phase 1 :ch0",ch0); - // print_shorts("phase 1 :ch1",ch1); - ch0[0] = _mm_subs_epi16(ch0[0],ch1[0]); - // print_shorts("phase 1 :ch0-ch1",ch0); - break; - case 2 : // +1 +j - ch1[0] = _mm_sign_epi16(ch1[0],*(__m128i*)&conjugate[0]); - ch1[0] = _mm_shufflelo_epi16(ch1[0],_MM_SHUFFLE(2,3,0,1)); - ch1[0] = _mm_shufflehi_epi16(ch1[0],_MM_SHUFFLE(2,3,0,1)); - ch0[0] = _mm_subs_epi16(ch0[0],ch1[0]); - - break; // +1 -j - case 3 : - ch1[0] = _mm_sign_epi16(ch1[0],*(__m128i*)&conjugate[0]); - ch1[0] = _mm_shufflelo_epi16(ch1[0],_MM_SHUFFLE(2,3,0,1)); - ch1[0] = _mm_shufflehi_epi16(ch1[0],_MM_SHUFFLE(2,3,0,1)); - ch0[0] = _mm_adds_epi16(ch0[0],ch1[0]); - break; + case 0 : // +1 +1 + // print_shorts("phase 0 :ch0",ch0); + // print_shorts("phase 0 :ch1",ch1); + ch0[0] = _mm_adds_epi16(ch0[0],ch1[0]); + break; + + case 1 : // +1 -1 + // print_shorts("phase 1 :ch0",ch0); + // print_shorts("phase 1 :ch1",ch1); + ch0[0] = _mm_subs_epi16(ch0[0],ch1[0]); + // print_shorts("phase 1 :ch0-ch1",ch0); + break; + + case 2 : // +1 +j + ch1[0] = _mm_sign_epi16(ch1[0],*(__m128i *)&conjugate[0]); + ch1[0] = _mm_shufflelo_epi16(ch1[0],_MM_SHUFFLE(2,3,0,1)); + ch1[0] = _mm_shufflehi_epi16(ch1[0],_MM_SHUFFLE(2,3,0,1)); + ch0[0] = _mm_subs_epi16(ch0[0],ch1[0]); + break; // +1 -j + + case 3 : + ch1[0] = _mm_sign_epi16(ch1[0],*(__m128i *)&conjugate[0]); + ch1[0] = _mm_shufflelo_epi16(ch1[0],_MM_SHUFFLE(2,3,0,1)); + ch1[0] = _mm_shufflehi_epi16(ch1[0],_MM_SHUFFLE(2,3,0,1)); + ch0[0] = _mm_adds_epi16(ch0[0],ch1[0]); + break; } //ch0[0] = _mm_mulhi_epi16(ch0[0],amp); //ch0[0] = _mm_slli_epi16(ch0[0],1); - _mm_empty(); _m_empty(); } @@ -2046,42 +1958,30 @@ void prec2A_TM56_128(unsigned char pmi,__m128i *ch0,__m128i *ch1) { short TM3_prec[8]__attribute__((aligned(16))) = {1,1,-1,-1,1,1,-1,-1} ; void prec2A_TM3_128(__m128i *ch0,__m128i *ch1) { - __m128i amp = _mm_set1_epi16(ONE_OVER_SQRT2_Q15); - __m128i tmp0,tmp1; - //_mm_mulhi_epi16 // print_shorts("prec2A_TM3 ch0 (before):",ch0); // print_shorts("prec2A_TM3 ch1 (before):",ch1); - tmp0 = ch0[0]; - tmp1 = _mm_sign_epi16(ch1[0],((__m128i*)&TM3_prec)[0]); + tmp1 = _mm_sign_epi16(ch1[0],((__m128i *)&TM3_prec)[0]); // print_shorts("prec2A_TM3 ch1*s (mid):",(__m128i*)TM3_prec); - ch0[0] = _mm_adds_epi16(ch0[0],tmp1); ch1[0] = _mm_subs_epi16(tmp0,tmp1); - ch0[0] = _mm_mulhi_epi16(ch0[0],amp); ch0[0] = _mm_slli_epi16(ch0[0],1); - ch1[0] = _mm_mulhi_epi16(ch1[0],amp); ch1[0] = _mm_slli_epi16(ch1[0],1); - // print_shorts("prec2A_TM3 ch0 (mid):",&tmp0); // print_shorts("prec2A_TM3 ch1 (mid):",ch1); - //ch0[0] = _mm_mulhi_epi16(ch0[0],amp); //ch0[0] = _mm_slli_epi16(ch0[0],1); //ch1[0] = _mm_mulhi_epi16(ch1[0],amp); //ch1[0] = _mm_slli_epi16(ch1[0],1); - //ch0[0] = _mm_srai_epi16(ch0[0],1); //ch1[0] = _mm_srai_epi16(ch1[0],1); - // print_shorts("prec2A_TM3 ch0 (after):",ch0); // print_shorts("prec2A_TM3 ch1 (after):",ch1); - _mm_empty(); _m_empty(); } @@ -2090,27 +1990,24 @@ void prec2A_TM3_128(__m128i *ch0,__m128i *ch1) { // pmi = 1 => stream 0 (1,j), stream 2 (1,-j) void prec2A_TM4_128(int pmi,__m128i *ch0,__m128i *ch1) { - -// sqrt(2) is already taken into account in computation sqrt_rho_a, sqrt_rho_b, -//so divide by 2 is replaced by divide by sqrt(2). - - // printf ("demod pmi=%d\n", pmi); - __m128i amp; - amp = _mm_set1_epi16(ONE_OVER_SQRT2_Q15); + // sqrt(2) is already taken into account in computation sqrt_rho_a, sqrt_rho_b, + //so divide by 2 is replaced by divide by sqrt(2). + // printf ("demod pmi=%d\n", pmi); + __m128i amp; + amp = _mm_set1_epi16(ONE_OVER_SQRT2_Q15); __m128i tmp0,tmp1; - // print_shorts("prec2A_TM4 ch0 (before):",ch0); - // print_shorts("prec2A_TM4 ch1 (before):",ch1); + // print_shorts("prec2A_TM4 ch0 (before):",ch0); + // print_shorts("prec2A_TM4 ch1 (before):",ch1); if (pmi == 0) { //[1 1;1 -1] tmp0 = ch0[0]; tmp1 = ch1[0]; ch0[0] = _mm_adds_epi16(tmp0,tmp1); ch1[0] = _mm_subs_epi16(tmp0,tmp1); - } - else { //ch0+j*ch1 ch0-j*ch1 + } else { //ch0+j*ch1 ch0-j*ch1 tmp0 = ch0[0]; - tmp1 = _mm_sign_epi16(ch1[0],*(__m128i*)&conjugate[0]); + tmp1 = _mm_sign_epi16(ch1[0],*(__m128i *)&conjugate[0]); tmp1 = _mm_shufflelo_epi16(tmp1,_MM_SHUFFLE(2,3,0,1)); tmp1 = _mm_shufflehi_epi16(tmp1,_MM_SHUFFLE(2,3,0,1)); ch0[0] = _mm_subs_epi16(tmp0,tmp1); @@ -2119,20 +2016,17 @@ void prec2A_TM4_128(int pmi,__m128i *ch0,__m128i *ch1) { //print_shorts("prec2A_TM4 ch0 (middle):",ch0); //print_shorts("prec2A_TM4 ch1 (middle):",ch1); - ch0[0] = _mm_mulhi_epi16(ch0[0],amp); ch0[0] = _mm_slli_epi16(ch0[0],1); ch1[0] = _mm_mulhi_epi16(ch1[0],amp); ch1[0] = _mm_slli_epi16(ch1[0],1); - - - // ch0[0] = _mm_srai_epi16(ch0[0],1); //divide by 2 - // ch1[0] = _mm_srai_epi16(ch1[0],1); //divide by 2 + // ch0[0] = _mm_srai_epi16(ch0[0],1); //divide by 2 + // ch1[0] = _mm_srai_epi16(ch1[0],1); //divide by 2 //print_shorts("prec2A_TM4 ch0 (end):",ch0); //print_shorts("prec2A_TM4 ch1 (end):",ch1); _mm_empty(); _m_empty(); - // print_shorts("prec2A_TM4 ch0 (end):",ch0); + // print_shorts("prec2A_TM4 ch0 (end):",ch0); //print_shorts("prec2A_TM4 ch1 (end):",ch1); } @@ -2149,25 +2043,21 @@ void dlsch_channel_compensation_TM56(int **rxdataF_ext, unsigned char mod_order, unsigned short nb_rb, unsigned char output_shift, - unsigned char dl_power_off) -{ - + unsigned char dl_power_off) { #if defined(__x86_64__) || defined(__i386__) - unsigned short rb,Nre; __m128i *dl_ch0_128,*dl_ch1_128,*dl_ch_mag128,*dl_ch_mag128b,*rxdataF128,*rxdataF_comp128; unsigned char aarx=0,symbol_mod,pilots=0; int precoded_signal_strength=0; __m128i mmtmpD0,mmtmpD1,mmtmpD2,mmtmpD3,QAM_amp128; - symbol_mod = (symbol>=(7-frame_parms->Ncp)) ? symbol-(7-frame_parms->Ncp) : symbol; if ((symbol_mod == 0) || (symbol_mod == (4-frame_parms->Ncp))) pilots=1; - //printf("comp prec: symbol %d, pilots %d\n",symbol, pilots); __m128i QAM_amp128b = _mm_setzero_si128(); + if (mod_order == 4) { QAM_amp128 = _mm_set1_epi16(QAM16_n1); } else if (mod_order == 6) { @@ -2176,17 +2066,13 @@ void dlsch_channel_compensation_TM56(int **rxdataF_ext, } for (aarx=0; aarx<frame_parms->nb_antennas_rx; aarx++) { - dl_ch0_128 = (__m128i *)&dl_ch_estimates_ext[aarx][symbol*frame_parms->N_RB_DL*12]; dl_ch1_128 = (__m128i *)&dl_ch_estimates_ext[2+aarx][symbol*frame_parms->N_RB_DL*12]; - - dl_ch_mag128 = (__m128i *)&dl_ch_mag[aarx][symbol*frame_parms->N_RB_DL*12]; dl_ch_mag128b = (__m128i *)&dl_ch_magb[aarx][symbol*frame_parms->N_RB_DL*12]; rxdataF128 = (__m128i *)&rxdataF_ext[aarx][symbol*frame_parms->N_RB_DL*12]; rxdataF_comp128 = (__m128i *)&rxdataF_comp[aarx][symbol*frame_parms->N_RB_DL*12]; - for (rb=0; rb<nb_rb; rb++) { // combine TX channels using precoder from pmi #ifdef DEBUG_DLSCH_DEMOD @@ -2196,31 +2082,22 @@ void dlsch_channel_compensation_TM56(int **rxdataF_ext, prec2A_TM56_128(pmi_ext[rb],&dl_ch0_128[1],&dl_ch1_128[1]); if (pilots==0) { - prec2A_TM56_128(pmi_ext[rb],&dl_ch0_128[2],&dl_ch1_128[2]); } if (mod_order>2) { // get channel amplitude if not QPSK - mmtmpD0 = _mm_madd_epi16(dl_ch0_128[0],dl_ch0_128[0]); mmtmpD0 = _mm_srai_epi32(mmtmpD0,output_shift); - mmtmpD1 = _mm_madd_epi16(dl_ch0_128[1],dl_ch0_128[1]); mmtmpD1 = _mm_srai_epi32(mmtmpD1,output_shift); - mmtmpD0 = _mm_packs_epi32(mmtmpD0,mmtmpD1); - dl_ch_mag128[0] = _mm_unpacklo_epi16(mmtmpD0,mmtmpD0); dl_ch_mag128b[0] = dl_ch_mag128[0]; dl_ch_mag128[0] = _mm_mulhi_epi16(dl_ch_mag128[0],QAM_amp128); dl_ch_mag128[0] = _mm_slli_epi16(dl_ch_mag128[0],1); - - //print_shorts("dl_ch_mag128[0]=",&dl_ch_mag128[0]); - //print_shorts("dl_ch_mag128[0]=",&dl_ch_mag128[0]); - dl_ch_mag128[1] = _mm_unpackhi_epi16(mmtmpD0,mmtmpD0); dl_ch_mag128b[1] = dl_ch_mag128[1]; dl_ch_mag128[1] = _mm_mulhi_epi16(dl_ch_mag128[1],QAM_amp128); @@ -2229,40 +2106,32 @@ void dlsch_channel_compensation_TM56(int **rxdataF_ext, if (pilots==0) { mmtmpD0 = _mm_madd_epi16(dl_ch0_128[2],dl_ch0_128[2]); mmtmpD0 = _mm_srai_epi32(mmtmpD0,output_shift); - mmtmpD1 = _mm_packs_epi32(mmtmpD0,mmtmpD0); - dl_ch_mag128[2] = _mm_unpacklo_epi16(mmtmpD1,mmtmpD1); dl_ch_mag128b[2] = dl_ch_mag128[2]; - dl_ch_mag128[2] = _mm_mulhi_epi16(dl_ch_mag128[2],QAM_amp128); dl_ch_mag128[2] = _mm_slli_epi16(dl_ch_mag128[2],1); } dl_ch_mag128b[0] = _mm_mulhi_epi16(dl_ch_mag128b[0],QAM_amp128b); dl_ch_mag128b[0] = _mm_slli_epi16(dl_ch_mag128b[0],1); - //print_shorts("dl_ch_mag128b[0]=",&dl_ch_mag128b[0]); - dl_ch_mag128b[1] = _mm_mulhi_epi16(dl_ch_mag128b[1],QAM_amp128b); dl_ch_mag128b[1] = _mm_slli_epi16(dl_ch_mag128b[1],1); if (pilots==0) { dl_ch_mag128b[2] = _mm_mulhi_epi16(dl_ch_mag128b[2],QAM_amp128b); dl_ch_mag128b[2] = _mm_slli_epi16(dl_ch_mag128b[2],1); - } } // MF multiply by conjugated channel mmtmpD0 = _mm_madd_epi16(dl_ch0_128[0],rxdataF128[0]); // print_ints("re",&mmtmpD0); - // mmtmpD0 contains real part of 4 consecutive outputs (32-bit) mmtmpD1 = _mm_shufflelo_epi16(dl_ch0_128[0],_MM_SHUFFLE(2,3,0,1)); mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1,_MM_SHUFFLE(2,3,0,1)); - mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i*)&conjugate[0]); - + mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i *)&conjugate[0]); // print_ints("im",&mmtmpD1); mmtmpD1 = _mm_madd_epi16(mmtmpD1,rxdataF128[0]); // mmtmpD1 contains imag part of 4 consecutive outputs (32-bit) @@ -2278,20 +2147,18 @@ void dlsch_channel_compensation_TM56(int **rxdataF_ext, // print_shorts("rx:",rxdataF128); // print_shorts("ch:",dl_ch128); // print_shorts("pack:",rxdataF_comp128); - // multiply by conjugated channel mmtmpD0 = _mm_madd_epi16(dl_ch0_128[1],rxdataF128[1]); // mmtmpD0 contains real part of 4 consecutive outputs (32-bit) mmtmpD1 = _mm_shufflelo_epi16(dl_ch0_128[1],_MM_SHUFFLE(2,3,0,1)); mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1,_MM_SHUFFLE(2,3,0,1)); - mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i*)conjugate); + mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i *)conjugate); mmtmpD1 = _mm_madd_epi16(mmtmpD1,rxdataF128[1]); // mmtmpD1 contains imag part of 4 consecutive outputs (32-bit) mmtmpD0 = _mm_srai_epi32(mmtmpD0,output_shift); mmtmpD1 = _mm_srai_epi32(mmtmpD1,output_shift); mmtmpD2 = _mm_unpacklo_epi32(mmtmpD0,mmtmpD1); mmtmpD3 = _mm_unpackhi_epi32(mmtmpD0,mmtmpD1); - rxdataF_comp128[1] = _mm_packs_epi32(mmtmpD2,mmtmpD3); // print_shorts("rx:",rxdataF128+1); // print_shorts("ch:",dl_ch128+1); @@ -2303,19 +2170,17 @@ void dlsch_channel_compensation_TM56(int **rxdataF_ext, // mmtmpD0 contains real part of 4 consecutive outputs (32-bit) mmtmpD1 = _mm_shufflelo_epi16(dl_ch0_128[2],_MM_SHUFFLE(2,3,0,1)); mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1,_MM_SHUFFLE(2,3,0,1)); - mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i*)conjugate); + mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i *)conjugate); mmtmpD1 = _mm_madd_epi16(mmtmpD1,rxdataF128[2]); // mmtmpD1 contains imag part of 4 consecutive outputs (32-bit) mmtmpD0 = _mm_srai_epi32(mmtmpD0,output_shift); mmtmpD1 = _mm_srai_epi32(mmtmpD1,output_shift); mmtmpD2 = _mm_unpacklo_epi32(mmtmpD0,mmtmpD1); mmtmpD3 = _mm_unpackhi_epi32(mmtmpD0,mmtmpD1); - rxdataF_comp128[2] = _mm_packs_epi32(mmtmpD2,mmtmpD3); // print_shorts("rx:",rxdataF128+2); // print_shorts("ch:",dl_ch128+2); // print_shorts("pack:",rxdataF_comp128+2); - dl_ch0_128+=3; dl_ch1_128+=3; dl_ch_mag128+=3; @@ -2333,45 +2198,37 @@ void dlsch_channel_compensation_TM56(int **rxdataF_ext, } Nre = (pilots==0) ? 12 : 8; - precoded_signal_strength += ((signal_energy_nodc(&dl_ch_estimates_ext[aarx][symbol*frame_parms->N_RB_DL*Nre], - (nb_rb*Nre))) - (measurements->n0_power[aarx])); + (nb_rb*Nre))) - (measurements->n0_power[aarx])); } // rx_antennas measurements->precoded_cqi_dB[eNB_id][0] = dB_fixed2(precoded_signal_strength,measurements->n0_power_tot); - //printf("eNB_id %d, symbol %d: precoded CQI %d dB\n",eNB_id,symbol, // measurements->precoded_cqi_dB[eNB_id][0]); - #elif defined(__arm__) - uint32_t rb,Nre; uint32_t aarx,symbol_mod,pilots=0; - int16x4_t *dl_ch0_128,*dl_ch1_128,*rxdataF128; int16x8_t *dl_ch0_128b,*dl_ch1_128b; int32x4_t mmtmpD0,mmtmpD1,mmtmpD0b,mmtmpD1b; int16x8_t *dl_ch_mag128,*dl_ch_mag128b,mmtmpD2,mmtmpD3,mmtmpD4,*rxdataF_comp128; int16x8_t QAM_amp128,QAM_amp128b; - int16_t conj[4]__attribute__((aligned(16))) = {1,-1,1,-1}; int32x4_t output_shift128 = vmovq_n_s32(-(int32_t)output_shift); int32_t precoded_signal_strength=0; - symbol_mod = (symbol>=(7-frame_parms->Ncp)) ? symbol-(7-frame_parms->Ncp) : symbol; - if ((symbol_mod == 0) || (symbol_mod == (4-frame_parms->Ncp))) { - if (frame_parms->nb_antenna_ports_eNB==1) // 10 out of 12 so don't reduce size - { nb_rb=1+(5*nb_rb/6); } - else - { pilots=1; } + if ((symbol_mod == 0) || (symbol_mod == (4-frame_parms->Ncp))) { + if (frame_parms->nb_antenna_ports_eNB==1) { // 10 out of 12 so don't reduce size + nb_rb=1+(5*nb_rb/6); + } else { + pilots=1; + } } - if (mod_order == 4) { QAM_amp128 = vmovq_n_s16(QAM16_n1); // 2/sqrt(10) QAM_amp128b = vmovq_n_s16(0); - } else if (mod_order == 6) { QAM_amp128 = vmovq_n_s16(QAM64_n1); // QAM_amp128b = vmovq_n_s16(QAM64_n2); @@ -2380,21 +2237,18 @@ void dlsch_channel_compensation_TM56(int **rxdataF_ext, // printf("comp: rxdataF_comp %p, symbol %d\n",rxdataF_comp[0],symbol); for (aarx=0; aarx<frame_parms->nb_antennas_rx; aarx++) { - - - - dl_ch0_128 = (int16x4_t*)&dl_ch_estimates_ext[aarx][symbol*frame_parms->N_RB_DL*12]; - dl_ch1_128 = (int16x4_t*)&dl_ch_estimates_ext[2+aarx][symbol*frame_parms->N_RB_DL*12]; - dl_ch0_128b = (int16x8_t*)&dl_ch_estimates_ext[aarx][symbol*frame_parms->N_RB_DL*12]; - dl_ch1_128b = (int16x8_t*)&dl_ch_estimates_ext[2+aarx][symbol*frame_parms->N_RB_DL*12]; - dl_ch_mag128 = (int16x8_t*)&dl_ch_mag[aarx][symbol*frame_parms->N_RB_DL*12]; - dl_ch_mag128b = (int16x8_t*)&dl_ch_magb[aarx][symbol*frame_parms->N_RB_DL*12]; - rxdataF128 = (int16x4_t*)&rxdataF_ext[aarx][symbol*frame_parms->N_RB_DL*12]; - rxdataF_comp128 = (int16x8_t*)&rxdataF_comp[aarx][symbol*frame_parms->N_RB_DL*12]; + dl_ch0_128 = (int16x4_t *)&dl_ch_estimates_ext[aarx][symbol*frame_parms->N_RB_DL*12]; + dl_ch1_128 = (int16x4_t *)&dl_ch_estimates_ext[2+aarx][symbol*frame_parms->N_RB_DL*12]; + dl_ch0_128b = (int16x8_t *)&dl_ch_estimates_ext[aarx][symbol*frame_parms->N_RB_DL*12]; + dl_ch1_128b = (int16x8_t *)&dl_ch_estimates_ext[2+aarx][symbol*frame_parms->N_RB_DL*12]; + dl_ch_mag128 = (int16x8_t *)&dl_ch_mag[aarx][symbol*frame_parms->N_RB_DL*12]; + dl_ch_mag128b = (int16x8_t *)&dl_ch_magb[aarx][symbol*frame_parms->N_RB_DL*12]; + rxdataF128 = (int16x4_t *)&rxdataF_ext[aarx][symbol*frame_parms->N_RB_DL*12]; + rxdataF_comp128 = (int16x8_t *)&rxdataF_comp[aarx][symbol*frame_parms->N_RB_DL*12]; for (rb=0; rb<nb_rb; rb++) { #ifdef DEBUG_DLSCH_DEMOD - printf("mode 6 prec: rb %d, pmi->%d\n",rb,pmi_ext[rb]); + printf("mode 6 prec: rb %d, pmi->%u\n",rb,pmi_ext[rb]); #endif prec2A_TM56_128(pmi_ext[rb],&dl_ch0_128b[0],&dl_ch1_128b[0]); prec2A_TM56_128(pmi_ext[rb],&dl_ch0_128b[1],&dl_ch1_128b[1]); @@ -2418,14 +2272,13 @@ void dlsch_channel_compensation_TM56(int **rxdataF_ext, mmtmpD1 = vmull_s16(dl_ch0_128[3], dl_ch0_128[3]); mmtmpD1 = vqshlq_s32(vqaddq_s32(mmtmpD1,vrev64q_s32(mmtmpD1)),output_shift128); mmtmpD3 = vcombine_s16(vmovn_s32(mmtmpD0),vmovn_s32(mmtmpD1)); + if (pilots==0) { mmtmpD0 = vmull_s16(dl_ch0_128[4], dl_ch0_128[4]); mmtmpD0 = vqshlq_s32(vqaddq_s32(mmtmpD0,vrev64q_s32(mmtmpD0)),output_shift128); mmtmpD1 = vmull_s16(dl_ch0_128[5], dl_ch0_128[5]); mmtmpD1 = vqshlq_s32(vqaddq_s32(mmtmpD1,vrev64q_s32(mmtmpD1)),output_shift128); mmtmpD4 = vcombine_s16(vmovn_s32(mmtmpD0),vmovn_s32(mmtmpD1)); - - } dl_ch_mag128b[0] = vqdmulhq_s16(mmtmpD2,QAM_amp128b); @@ -2433,12 +2286,12 @@ void dlsch_channel_compensation_TM56(int **rxdataF_ext, dl_ch_mag128[0] = vqdmulhq_s16(mmtmpD2,QAM_amp128); dl_ch_mag128[1] = vqdmulhq_s16(mmtmpD3,QAM_amp128); - if (pilots==0) { dl_ch_mag128b[2] = vqdmulhq_s16(mmtmpD4,QAM_amp128b); dl_ch_mag128[2] = vqdmulhq_s16(mmtmpD4,QAM_amp128); } } + mmtmpD0 = vmull_s16(dl_ch0_128[0], rxdataF128[0]); //mmtmpD0 = [Re(ch[0])Re(rx[0]) Im(ch[0])Im(ch[0]) Re(ch[1])Re(rx[1]) Im(ch[1])Im(ch[1])] mmtmpD1 = vmull_s16(dl_ch0_128[1], rxdataF128[1]); @@ -2446,29 +2299,24 @@ void dlsch_channel_compensation_TM56(int **rxdataF_ext, mmtmpD0 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0),vget_high_s32(mmtmpD0)), vpadd_s32(vget_low_s32(mmtmpD1),vget_high_s32(mmtmpD1))); //mmtmpD0 = [Re(ch[0])Re(rx[0])+Im(ch[0])Im(ch[0]) Re(ch[1])Re(rx[1])+Im(ch[1])Im(ch[1]) Re(ch[2])Re(rx[2])+Im(ch[2])Im(ch[2]) Re(ch[3])Re(rx[3])+Im(ch[3])Im(ch[3])] - - mmtmpD0b = vmull_s16(vrev32_s16(vmul_s16(dl_ch0_128[0],*(int16x4_t*)conj)), rxdataF128[0]); + mmtmpD0b = vmull_s16(vrev32_s16(vmul_s16(dl_ch0_128[0],*(int16x4_t *)conj)), rxdataF128[0]); //mmtmpD0 = [-Im(ch[0])Re(rx[0]) Re(ch[0])Im(rx[0]) -Im(ch[1])Re(rx[1]) Re(ch[1])Im(rx[1])] - mmtmpD1b = vmull_s16(vrev32_s16(vmul_s16(dl_ch0_128[1],*(int16x4_t*)conj)), rxdataF128[1]); + mmtmpD1b = vmull_s16(vrev32_s16(vmul_s16(dl_ch0_128[1],*(int16x4_t *)conj)), rxdataF128[1]); //mmtmpD0 = [-Im(ch[2])Re(rx[2]) Re(ch[2])Im(rx[2]) -Im(ch[3])Re(rx[3]) Re(ch[3])Im(rx[3])] mmtmpD1 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0b),vget_high_s32(mmtmpD0b)), vpadd_s32(vget_low_s32(mmtmpD1b),vget_high_s32(mmtmpD1b))); //mmtmpD1 = [-Im(ch[0])Re(rx[0])+Re(ch[0])Im(rx[0]) -Im(ch[1])Re(rx[1])+Re(ch[1])Im(rx[1]) -Im(ch[2])Re(rx[2])+Re(ch[2])Im(rx[2]) -Im(ch[3])Re(rx[3])+Re(ch[3])Im(rx[3])] - mmtmpD0 = vqshlq_s32(mmtmpD0,output_shift128); mmtmpD1 = vqshlq_s32(mmtmpD1,output_shift128); rxdataF_comp128[0] = vcombine_s16(vmovn_s32(mmtmpD0),vmovn_s32(mmtmpD1)); - mmtmpD0 = vmull_s16(dl_ch0_128[2], rxdataF128[2]); mmtmpD1 = vmull_s16(dl_ch0_128[3], rxdataF128[3]); mmtmpD0 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0),vget_high_s32(mmtmpD0)), vpadd_s32(vget_low_s32(mmtmpD1),vget_high_s32(mmtmpD1))); - - mmtmpD0b = vmull_s16(vrev32_s16(vmul_s16(dl_ch0_128[2],*(int16x4_t*)conj)), rxdataF128[2]); - mmtmpD1b = vmull_s16(vrev32_s16(vmul_s16(dl_ch0_128[3],*(int16x4_t*)conj)), rxdataF128[3]); + mmtmpD0b = vmull_s16(vrev32_s16(vmul_s16(dl_ch0_128[2],*(int16x4_t *)conj)), rxdataF128[2]); + mmtmpD1b = vmull_s16(vrev32_s16(vmul_s16(dl_ch0_128[3],*(int16x4_t *)conj)), rxdataF128[3]); mmtmpD1 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0b),vget_high_s32(mmtmpD0b)), vpadd_s32(vget_low_s32(mmtmpD1b),vget_high_s32(mmtmpD1b))); - mmtmpD0 = vqshlq_s32(mmtmpD0,output_shift128); mmtmpD1 = vqshlq_s32(mmtmpD1,output_shift128); rxdataF_comp128[1] = vcombine_s16(vmovn_s32(mmtmpD0),vmovn_s32(mmtmpD1)); @@ -2478,25 +2326,19 @@ void dlsch_channel_compensation_TM56(int **rxdataF_ext, mmtmpD1 = vmull_s16(dl_ch0_128[5], rxdataF128[5]); mmtmpD0 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0),vget_high_s32(mmtmpD0)), vpadd_s32(vget_low_s32(mmtmpD1),vget_high_s32(mmtmpD1))); - - mmtmpD0b = vmull_s16(vrev32_s16(vmul_s16(dl_ch0_128[4],*(int16x4_t*)conj)), rxdataF128[4]); - mmtmpD1b = vmull_s16(vrev32_s16(vmul_s16(dl_ch0_128[5],*(int16x4_t*)conj)), rxdataF128[5]); + mmtmpD0b = vmull_s16(vrev32_s16(vmul_s16(dl_ch0_128[4],*(int16x4_t *)conj)), rxdataF128[4]); + mmtmpD1b = vmull_s16(vrev32_s16(vmul_s16(dl_ch0_128[5],*(int16x4_t *)conj)), rxdataF128[5]); mmtmpD1 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0b),vget_high_s32(mmtmpD0b)), vpadd_s32(vget_low_s32(mmtmpD1b),vget_high_s32(mmtmpD1b))); - - mmtmpD0 = vqshlq_s32(mmtmpD0,output_shift128); mmtmpD1 = vqshlq_s32(mmtmpD1,output_shift128); rxdataF_comp128[2] = vcombine_s16(vmovn_s32(mmtmpD0),vmovn_s32(mmtmpD1)); - - dl_ch0_128+=6; dl_ch1_128+=6; dl_ch_mag128+=3; dl_ch_mag128b+=3; rxdataF128+=6; rxdataF_comp128+=3; - } else { // we have a smaller PDSCH in symbols with pilots so skip last group of 4 REs and increment less dl_ch0_128+=4; dl_ch1_128+=4; @@ -2508,109 +2350,103 @@ void dlsch_channel_compensation_TM56(int **rxdataF_ext, } Nre = (pilots==0) ? 12 : 8; - - precoded_signal_strength += ((signal_energy_nodc(&dl_ch_estimates_ext[aarx][symbol*frame_parms->N_RB_DL*Nre], - - (nb_rb*Nre))) - (measurements->n0_power[aarx])); + (nb_rb*Nre))) - (measurements->n0_power[aarx])); // rx_antennas } - measurements->precoded_cqi_dB[eNB_id][0] = dB_fixed2(precoded_signal_strength,measurements->n0_power_tot); + measurements->precoded_cqi_dB[eNB_id][0] = dB_fixed2(precoded_signal_strength,measurements->n0_power_tot); //printf("eNB_id %d, symbol %d: precoded CQI %d dB\n",eNB_id,symbol, // measurements->precoded_cqi_dB[eNB_id][0]); - #endif _mm_empty(); _m_empty(); } void precode_channel_est(int32_t **dl_ch_estimates_ext, - LTE_DL_FRAME_PARMS *frame_parms, - LTE_UE_PDSCH *pdsch_vars, - unsigned char symbol, - unsigned short nb_rb, - MIMO_mode_t mimo_mode){ - + LTE_DL_FRAME_PARMS *frame_parms, + LTE_UE_PDSCH *pdsch_vars, + unsigned char symbol, + unsigned short nb_rb, + MIMO_mode_t mimo_mode) { unsigned short rb; __m128i *dl_ch0_128,*dl_ch1_128; unsigned char aarx=0,symbol_mod,pilots=0; unsigned char *pmi_ext = pdsch_vars->pmi_ext; - symbol_mod = (symbol>=(7-frame_parms->Ncp)) ? symbol-(7-frame_parms->Ncp) : symbol; if ((symbol_mod == 0) || (symbol_mod == (4-frame_parms->Ncp))) pilots=1; - for (aarx=0;aarx<frame_parms->nb_antennas_rx;aarx++) { - + for (aarx=0; aarx<frame_parms->nb_antennas_rx; aarx++) { dl_ch0_128 = (__m128i *)&dl_ch_estimates_ext[aarx][symbol*frame_parms->N_RB_DL*12]; // this is h11 dl_ch1_128 = (__m128i *)&dl_ch_estimates_ext[2+aarx][symbol*frame_parms->N_RB_DL*12]; // this is h12 for (rb=0; rb<nb_rb; rb++) { if (mimo_mode==LARGE_CDD) { - prec2A_TM3_128(&dl_ch0_128[0],&dl_ch1_128[0]); - prec2A_TM3_128(&dl_ch0_128[1],&dl_ch1_128[1]); - if (pilots==0) { - prec2A_TM3_128(&dl_ch0_128[2],&dl_ch1_128[2]); - } - }else if (mimo_mode==DUALSTREAM_UNIFORM_PRECODING1) { - prec2A_TM4_128(0,&dl_ch0_128[0],&dl_ch1_128[0]); - prec2A_TM4_128(0,&dl_ch0_128[1],&dl_ch1_128[1]); - if (pilots==0) { - prec2A_TM4_128(0,&dl_ch0_128[2],&dl_ch1_128[2]); - } - }else if (mimo_mode==DUALSTREAM_UNIFORM_PRECODINGj) { - prec2A_TM4_128(1,&dl_ch0_128[0],&dl_ch1_128[0]); - prec2A_TM4_128(1,&dl_ch0_128[1],&dl_ch1_128[1]); - if (pilots==0) { - prec2A_TM4_128(1,&dl_ch0_128[2],&dl_ch1_128[2]); - } - }else if (mimo_mode==DUALSTREAM_PUSCH_PRECODING) { - prec2A_TM4_128(pmi_ext[rb],&dl_ch0_128[0],&dl_ch1_128[0]); - prec2A_TM4_128(pmi_ext[rb],&dl_ch0_128[1],&dl_ch1_128[1]); - if (pilots==0) { - prec2A_TM4_128(pmi_ext[rb],&dl_ch0_128[2],&dl_ch1_128[2]); - } - }else { - LOG_E(PHY,"Unknown MIMO mode\n"); - return; - } - if (pilots==0){ - dl_ch0_128+=3; - dl_ch1_128+=3; - }else { - dl_ch0_128+=2; - dl_ch1_128+=2; - } + prec2A_TM3_128(&dl_ch0_128[0],&dl_ch1_128[0]); + prec2A_TM3_128(&dl_ch0_128[1],&dl_ch1_128[1]); + + if (pilots==0) { + prec2A_TM3_128(&dl_ch0_128[2],&dl_ch1_128[2]); + } + } else if (mimo_mode==DUALSTREAM_UNIFORM_PRECODING1) { + prec2A_TM4_128(0,&dl_ch0_128[0],&dl_ch1_128[0]); + prec2A_TM4_128(0,&dl_ch0_128[1],&dl_ch1_128[1]); + + if (pilots==0) { + prec2A_TM4_128(0,&dl_ch0_128[2],&dl_ch1_128[2]); + } + } else if (mimo_mode==DUALSTREAM_UNIFORM_PRECODINGj) { + prec2A_TM4_128(1,&dl_ch0_128[0],&dl_ch1_128[0]); + prec2A_TM4_128(1,&dl_ch0_128[1],&dl_ch1_128[1]); + + if (pilots==0) { + prec2A_TM4_128(1,&dl_ch0_128[2],&dl_ch1_128[2]); + } + } else if (mimo_mode==DUALSTREAM_PUSCH_PRECODING) { + prec2A_TM4_128(pmi_ext[rb],&dl_ch0_128[0],&dl_ch1_128[0]); + prec2A_TM4_128(pmi_ext[rb],&dl_ch0_128[1],&dl_ch1_128[1]); + + if (pilots==0) { + prec2A_TM4_128(pmi_ext[rb],&dl_ch0_128[2],&dl_ch1_128[2]); } + } else { + LOG_E(PHY,"Unknown MIMO mode\n"); + return; + } + if (pilots==0) { + dl_ch0_128+=3; + dl_ch1_128+=3; + } else { + dl_ch0_128+=2; + dl_ch1_128+=2; } + } + } } void dlsch_channel_compensation_TM34(LTE_DL_FRAME_PARMS *frame_parms, - LTE_UE_PDSCH *pdsch_vars, - PHY_MEASUREMENTS *measurements, - int eNB_id, - unsigned char symbol, - unsigned char mod_order0, - unsigned char mod_order1, - int harq_pid, - int round, - MIMO_mode_t mimo_mode, - unsigned short nb_rb, - unsigned short mmse_flag, - unsigned char output_shift0, - unsigned char output_shift1) { - + LTE_UE_PDSCH *pdsch_vars, + PHY_MEASUREMENTS *measurements, + int eNB_id, + unsigned char symbol, + unsigned char mod_order0, + unsigned char mod_order1, + int harq_pid, + int round, + MIMO_mode_t mimo_mode, + unsigned short nb_rb, + unsigned short mmse_flag, + unsigned char output_shift0, + unsigned char output_shift1) { #if defined(__x86_64__) || defined(__i386__) - unsigned short rb,Nre; __m128i *dl_ch0_128,*dl_ch1_128,*dl_ch_mag0_128,*dl_ch_mag1_128,*dl_ch_mag0_128b,*dl_ch_mag1_128b,*rxdataF128,*rxdataF_comp0_128,*rxdataF_comp1_128; unsigned char aarx=0,symbol_mod,pilots=0; int precoded_signal_strength0=0,precoded_signal_strength1=0; int rx_power_correction; - int **rxdataF_ext = pdsch_vars->rxdataF_ext; int **dl_ch_estimates_ext = pdsch_vars->dl_ch_estimates_ext; int **dl_ch_mag0 = pdsch_vars->dl_ch_mag0; @@ -2621,17 +2457,15 @@ void dlsch_channel_compensation_TM34(LTE_DL_FRAME_PARMS *frame_parms, int **rxdataF_comp1 = pdsch_vars->rxdataF_comp1[harq_pid][round]; unsigned char *pmi_ext = pdsch_vars->pmi_ext; __m128i mmtmpD0,mmtmpD1,mmtmpD2,mmtmpD3,QAM_amp0_128,QAM_amp1_128; - symbol_mod = (symbol>=(7-frame_parms->Ncp)) ? symbol-(7-frame_parms->Ncp) : symbol; if ((symbol_mod == 0) || (symbol_mod == (4-frame_parms->Ncp))) pilots=1; rx_power_correction = 1; - - // printf("comp prec: symbol %d, pilots %d\n",symbol, pilots); - + // printf("comp prec: symbol %d, pilots %d\n",symbol, pilots); __m128i QAM_amp0_128b = _mm_setzero_si128(); + if (mod_order0 == 4) { QAM_amp0_128 = _mm_set1_epi16(QAM16_n1); } else if (mod_order0 == 6) { @@ -2640,6 +2474,7 @@ void dlsch_channel_compensation_TM34(LTE_DL_FRAME_PARMS *frame_parms, } __m128i QAM_amp1_128b = _mm_setzero_si128(); + if (mod_order1 == 4) { QAM_amp1_128 = _mm_set1_epi16(QAM16_n1); } else if (mod_order1 == 6) { @@ -2647,8 +2482,7 @@ void dlsch_channel_compensation_TM34(LTE_DL_FRAME_PARMS *frame_parms, QAM_amp1_128b = _mm_set1_epi16(QAM64_n2); } - for (aarx=0;aarx<frame_parms->nb_antennas_rx;aarx++) { - + for (aarx=0; aarx<frame_parms->nb_antennas_rx; aarx++) { dl_ch0_128 = (__m128i *)&dl_ch_estimates_ext[aarx][symbol*frame_parms->N_RB_DL*12]; // this is h11 dl_ch1_128 = (__m128i *)&dl_ch_estimates_ext[2+aarx][symbol*frame_parms->N_RB_DL*12]; // this is h12 dl_ch_mag0_128 = (__m128i *)&dl_ch_mag0[aarx][symbol*frame_parms->N_RB_DL*12]; //responsible for x1 @@ -2661,57 +2495,53 @@ void dlsch_channel_compensation_TM34(LTE_DL_FRAME_PARMS *frame_parms, for (rb=0; rb<nb_rb; rb++) { if (mmse_flag == 0) { - // combine TX channels using precoder from pmi + // combine TX channels using precoder from pmi if (mimo_mode==LARGE_CDD) { prec2A_TM3_128(&dl_ch0_128[0],&dl_ch1_128[0]); prec2A_TM3_128(&dl_ch0_128[1],&dl_ch1_128[1]); + if (pilots==0) { prec2A_TM3_128(&dl_ch0_128[2],&dl_ch1_128[2]); } - }else if (mimo_mode==DUALSTREAM_UNIFORM_PRECODING1) { + } else if (mimo_mode==DUALSTREAM_UNIFORM_PRECODING1) { prec2A_TM4_128(0,&dl_ch0_128[0],&dl_ch1_128[0]); prec2A_TM4_128(0,&dl_ch0_128[1],&dl_ch1_128[1]); + if (pilots==0) { prec2A_TM4_128(0,&dl_ch0_128[2],&dl_ch1_128[2]); } - }else if (mimo_mode==DUALSTREAM_UNIFORM_PRECODINGj) { + } else if (mimo_mode==DUALSTREAM_UNIFORM_PRECODINGj) { prec2A_TM4_128(1,&dl_ch0_128[0],&dl_ch1_128[0]); prec2A_TM4_128(1,&dl_ch0_128[1],&dl_ch1_128[1]); + if (pilots==0) { prec2A_TM4_128(1,&dl_ch0_128[2],&dl_ch1_128[2]); } - }else if (mimo_mode==DUALSTREAM_PUSCH_PRECODING) { + } else if (mimo_mode==DUALSTREAM_PUSCH_PRECODING) { prec2A_TM4_128(pmi_ext[rb],&dl_ch0_128[0],&dl_ch1_128[0]); prec2A_TM4_128(pmi_ext[rb],&dl_ch0_128[1],&dl_ch1_128[1]); + if (pilots==0) { prec2A_TM4_128(pmi_ext[rb],&dl_ch0_128[2],&dl_ch1_128[2]); } - }else { + } else { LOG_E(PHY,"Unknown MIMO mode\n"); return; } } - if (mod_order0>2) { // get channel amplitude if not QPSK - mmtmpD0 = _mm_madd_epi16(dl_ch0_128[0],dl_ch0_128[0]); mmtmpD0 = _mm_srai_epi32(mmtmpD0,output_shift0); - mmtmpD1 = _mm_madd_epi16(dl_ch0_128[1],dl_ch0_128[1]); mmtmpD1 = _mm_srai_epi32(mmtmpD1,output_shift0); - mmtmpD0 = _mm_packs_epi32(mmtmpD0,mmtmpD1); - dl_ch_mag0_128[0] = _mm_unpacklo_epi16(mmtmpD0,mmtmpD0); dl_ch_mag0_128b[0] = dl_ch_mag0_128[0]; dl_ch_mag0_128[0] = _mm_mulhi_epi16(dl_ch_mag0_128[0],QAM_amp0_128); dl_ch_mag0_128[0] = _mm_slli_epi16(dl_ch_mag0_128[0],1); - // print_shorts("dl_ch_mag0_128[0]=",&dl_ch_mag0_128[0]); - - dl_ch_mag0_128[1] = _mm_unpackhi_epi16(mmtmpD0,mmtmpD0); dl_ch_mag0_128b[1] = dl_ch_mag0_128[1]; dl_ch_mag0_128[1] = _mm_mulhi_epi16(dl_ch_mag0_128[1],QAM_amp0_128); @@ -2720,21 +2550,16 @@ void dlsch_channel_compensation_TM34(LTE_DL_FRAME_PARMS *frame_parms, if (pilots==0) { mmtmpD0 = _mm_madd_epi16(dl_ch0_128[2],dl_ch0_128[2]); mmtmpD0 = _mm_srai_epi32(mmtmpD0,output_shift0); - mmtmpD1 = _mm_packs_epi32(mmtmpD0,mmtmpD0); - dl_ch_mag0_128[2] = _mm_unpacklo_epi16(mmtmpD1,mmtmpD1); dl_ch_mag0_128b[2] = dl_ch_mag0_128[2]; - dl_ch_mag0_128[2] = _mm_mulhi_epi16(dl_ch_mag0_128[2],QAM_amp0_128); dl_ch_mag0_128[2] = _mm_slli_epi16(dl_ch_mag0_128[2],1); } dl_ch_mag0_128b[0] = _mm_mulhi_epi16(dl_ch_mag0_128b[0],QAM_amp0_128b); dl_ch_mag0_128b[0] = _mm_slli_epi16(dl_ch_mag0_128b[0],1); - - // print_shorts("dl_ch_mag0_128b[0]=",&dl_ch_mag0_128b[0]); - + // print_shorts("dl_ch_mag0_128b[0]=",&dl_ch_mag0_128b[0]); dl_ch_mag0_128b[1] = _mm_mulhi_epi16(dl_ch_mag0_128b[1],QAM_amp0_128b); dl_ch_mag0_128b[1] = _mm_slli_epi16(dl_ch_mag0_128b[1],1); @@ -2746,22 +2571,16 @@ void dlsch_channel_compensation_TM34(LTE_DL_FRAME_PARMS *frame_parms, if (mod_order1>2) { // get channel amplitude if not QPSK - mmtmpD0 = _mm_madd_epi16(dl_ch1_128[0],dl_ch1_128[0]); mmtmpD0 = _mm_srai_epi32(mmtmpD0,output_shift1); - mmtmpD1 = _mm_madd_epi16(dl_ch1_128[1],dl_ch1_128[1]); mmtmpD1 = _mm_srai_epi32(mmtmpD1,output_shift1); - mmtmpD0 = _mm_packs_epi32(mmtmpD0,mmtmpD1); - dl_ch_mag1_128[0] = _mm_unpacklo_epi16(mmtmpD0,mmtmpD0); dl_ch_mag1_128b[0] = dl_ch_mag1_128[0]; dl_ch_mag1_128[0] = _mm_mulhi_epi16(dl_ch_mag1_128[0],QAM_amp1_128); dl_ch_mag1_128[0] = _mm_slli_epi16(dl_ch_mag1_128[0],1); - - // print_shorts("dl_ch_mag1_128[0]=",&dl_ch_mag1_128[0]); - + // print_shorts("dl_ch_mag1_128[0]=",&dl_ch_mag1_128[0]); dl_ch_mag1_128[1] = _mm_unpackhi_epi16(mmtmpD0,mmtmpD0); dl_ch_mag1_128b[1] = dl_ch_mag1_128[1]; dl_ch_mag1_128[1] = _mm_mulhi_epi16(dl_ch_mag1_128[1],QAM_amp1_128); @@ -2770,21 +2589,16 @@ void dlsch_channel_compensation_TM34(LTE_DL_FRAME_PARMS *frame_parms, if (pilots==0) { mmtmpD0 = _mm_madd_epi16(dl_ch1_128[2],dl_ch1_128[2]); mmtmpD0 = _mm_srai_epi32(mmtmpD0,output_shift1); - mmtmpD1 = _mm_packs_epi32(mmtmpD0,mmtmpD0); - dl_ch_mag1_128[2] = _mm_unpacklo_epi16(mmtmpD1,mmtmpD1); dl_ch_mag1_128b[2] = dl_ch_mag1_128[2]; - dl_ch_mag1_128[2] = _mm_mulhi_epi16(dl_ch_mag1_128[2],QAM_amp1_128); dl_ch_mag1_128[2] = _mm_slli_epi16(dl_ch_mag1_128[2],1); } dl_ch_mag1_128b[0] = _mm_mulhi_epi16(dl_ch_mag1_128b[0],QAM_amp1_128b); dl_ch_mag1_128b[0] = _mm_slli_epi16(dl_ch_mag1_128b[0],1); - - // print_shorts("dl_ch_mag1_128b[0]=",&dl_ch_mag1_128b[0]); - + // print_shorts("dl_ch_mag1_128b[0]=",&dl_ch_mag1_128b[0]); dl_ch_mag1_128b[1] = _mm_mulhi_epi16(dl_ch_mag1_128b[1],QAM_amp1_128b); dl_ch_mag1_128b[1] = _mm_slli_epi16(dl_ch_mag1_128b[1],1); @@ -2797,47 +2611,43 @@ void dlsch_channel_compensation_TM34(LTE_DL_FRAME_PARMS *frame_parms, // layer 0 // MF multiply by conjugated channel mmtmpD0 = _mm_madd_epi16(dl_ch0_128[0],rxdataF128[0]); - // print_ints("re",&mmtmpD0); - + // print_ints("re",&mmtmpD0); // mmtmpD0 contains real part of 4 consecutive outputs (32-bit) mmtmpD1 = _mm_shufflelo_epi16(dl_ch0_128[0],_MM_SHUFFLE(2,3,0,1)); mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1,_MM_SHUFFLE(2,3,0,1)); - mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i*)&conjugate[0]); + mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i *)&conjugate[0]); mmtmpD1 = _mm_madd_epi16(mmtmpD1,rxdataF128[0]); - // print_ints("im",&mmtmpD1); + // print_ints("im",&mmtmpD1); // mmtmpD1 contains imag part of 4 consecutive outputs (32-bit) mmtmpD0 = _mm_srai_epi32(mmtmpD0,output_shift0); - // printf("Shift: %d\n",output_shift); - // print_ints("re(shift)",&mmtmpD0); + // printf("Shift: %d\n",output_shift); + // print_ints("re(shift)",&mmtmpD0); mmtmpD1 = _mm_srai_epi32(mmtmpD1,output_shift0); - // print_ints("im(shift)",&mmtmpD1); + // print_ints("im(shift)",&mmtmpD1); mmtmpD2 = _mm_unpacklo_epi32(mmtmpD0,mmtmpD1); mmtmpD3 = _mm_unpackhi_epi32(mmtmpD0,mmtmpD1); - // print_ints("c0",&mmtmpD2); - // print_ints("c1",&mmtmpD3); + // print_ints("c0",&mmtmpD2); + // print_ints("c1",&mmtmpD3); rxdataF_comp0_128[0] = _mm_packs_epi32(mmtmpD2,mmtmpD3); - - // print_shorts("rx:",rxdataF128); - // print_shorts("ch:",dl_ch0_128); + // print_shorts("rx:",rxdataF128); + // print_shorts("ch:",dl_ch0_128); //print_shorts("pack:",rxdataF_comp0_128); - // multiply by conjugated channel mmtmpD0 = _mm_madd_epi16(dl_ch0_128[1],rxdataF128[1]); // mmtmpD0 contains real part of 4 consecutive outputs (32-bit) mmtmpD1 = _mm_shufflelo_epi16(dl_ch0_128[1],_MM_SHUFFLE(2,3,0,1)); mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1,_MM_SHUFFLE(2,3,0,1)); - mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i*)conjugate); + mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i *)conjugate); mmtmpD1 = _mm_madd_epi16(mmtmpD1,rxdataF128[1]); // mmtmpD1 contains imag part of 4 consecutive outputs (32-bit) mmtmpD0 = _mm_srai_epi32(mmtmpD0,output_shift0); mmtmpD1 = _mm_srai_epi32(mmtmpD1,output_shift0); mmtmpD2 = _mm_unpacklo_epi32(mmtmpD0,mmtmpD1); mmtmpD3 = _mm_unpackhi_epi32(mmtmpD0,mmtmpD1); - rxdataF_comp0_128[1] = _mm_packs_epi32(mmtmpD2,mmtmpD3); - // print_shorts("rx:",rxdataF128+1); - // print_shorts("ch:",dl_ch0_128+1); - // print_shorts("pack:",rxdataF_comp0_128+1); + // print_shorts("rx:",rxdataF128+1); + // print_shorts("ch:",dl_ch0_128+1); + // print_shorts("pack:",rxdataF_comp0_128+1); if (pilots==0) { // multiply by conjugated channel @@ -2845,64 +2655,58 @@ void dlsch_channel_compensation_TM34(LTE_DL_FRAME_PARMS *frame_parms, // mmtmpD0 contains real part of 4 consecutive outputs (32-bit) mmtmpD1 = _mm_shufflelo_epi16(dl_ch0_128[2],_MM_SHUFFLE(2,3,0,1)); mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1,_MM_SHUFFLE(2,3,0,1)); - mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i*)conjugate); + mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i *)conjugate); mmtmpD1 = _mm_madd_epi16(mmtmpD1,rxdataF128[2]); // mmtmpD1 contains imag part of 4 consecutive outputs (32-bit) mmtmpD0 = _mm_srai_epi32(mmtmpD0,output_shift0); mmtmpD1 = _mm_srai_epi32(mmtmpD1,output_shift0); mmtmpD2 = _mm_unpacklo_epi32(mmtmpD0,mmtmpD1); mmtmpD3 = _mm_unpackhi_epi32(mmtmpD0,mmtmpD1); - rxdataF_comp0_128[2] = _mm_packs_epi32(mmtmpD2,mmtmpD3); - // print_shorts("rx:",rxdataF128+2); - // print_shorts("ch:",dl_ch0_128+2); - // print_shorts("pack:",rxdataF_comp0_128+2); - + // print_shorts("rx:",rxdataF128+2); + // print_shorts("ch:",dl_ch0_128+2); + // print_shorts("pack:",rxdataF_comp0_128+2); } - // layer 1 // MF multiply by conjugated channel mmtmpD0 = _mm_madd_epi16(dl_ch1_128[0],rxdataF128[0]); - // print_ints("re",&mmtmpD0); - - // mmtmpD0 contains real part of 4 consecutive outputs (32-bit) + // print_ints("re",&mmtmpD0); + // mmtmpD0 contains real part of 4 consecutive outputs (32-bit) mmtmpD1 = _mm_shufflelo_epi16(dl_ch1_128[0],_MM_SHUFFLE(2,3,0,1)); mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1,_MM_SHUFFLE(2,3,0,1)); - mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i*)&conjugate[0]); - // print_ints("im",&mmtmpD1); + mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i *)&conjugate[0]); + // print_ints("im",&mmtmpD1); mmtmpD1 = _mm_madd_epi16(mmtmpD1,rxdataF128[0]); // mmtmpD1 contains imag part of 4 consecutive outputs (32-bit) mmtmpD0 = _mm_srai_epi32(mmtmpD0,output_shift1); - // print_ints("re(shift)",&mmtmpD0); + // print_ints("re(shift)",&mmtmpD0); mmtmpD1 = _mm_srai_epi32(mmtmpD1,output_shift1); - // print_ints("im(shift)",&mmtmpD1); + // print_ints("im(shift)",&mmtmpD1); mmtmpD2 = _mm_unpacklo_epi32(mmtmpD0,mmtmpD1); mmtmpD3 = _mm_unpackhi_epi32(mmtmpD0,mmtmpD1); - // print_ints("c0",&mmtmpD2); - // print_ints("c1",&mmtmpD3); + // print_ints("c0",&mmtmpD2); + // print_ints("c1",&mmtmpD3); rxdataF_comp1_128[0] = _mm_packs_epi32(mmtmpD2,mmtmpD3); - // print_shorts("rx:",rxdataF128); - // print_shorts("ch:",dl_ch1_128); - // print_shorts("pack:",rxdataF_comp1_128); - - // multiply by conjugated channel + // print_shorts("rx:",rxdataF128); + // print_shorts("ch:",dl_ch1_128); + // print_shorts("pack:",rxdataF_comp1_128); + // multiply by conjugated channel mmtmpD0 = _mm_madd_epi16(dl_ch1_128[1],rxdataF128[1]); // mmtmpD0 contains real part of 4 consecutive outputs (32-bit) mmtmpD1 = _mm_shufflelo_epi16(dl_ch1_128[1],_MM_SHUFFLE(2,3,0,1)); mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1,_MM_SHUFFLE(2,3,0,1)); - mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i*)conjugate); + mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i *)conjugate); mmtmpD1 = _mm_madd_epi16(mmtmpD1,rxdataF128[1]); // mmtmpD1 contains imag part of 4 consecutive outputs (32-bit) mmtmpD0 = _mm_srai_epi32(mmtmpD0,output_shift1); mmtmpD1 = _mm_srai_epi32(mmtmpD1,output_shift1); mmtmpD2 = _mm_unpacklo_epi32(mmtmpD0,mmtmpD1); mmtmpD3 = _mm_unpackhi_epi32(mmtmpD0,mmtmpD1); - rxdataF_comp1_128[1] = _mm_packs_epi32(mmtmpD2,mmtmpD3); - // print_shorts("rx:",rxdataF128+1); - // print_shorts("ch:",dl_ch1_128+1); - // print_shorts("pack:",rxdataF_comp1_128+1); + // print_shorts("rx:",rxdataF128+1); + // print_shorts("ch:",dl_ch1_128+1); + // print_shorts("pack:",rxdataF_comp1_128+1); if (pilots==0) { // multiply by conjugated channel @@ -2910,19 +2714,17 @@ void dlsch_channel_compensation_TM34(LTE_DL_FRAME_PARMS *frame_parms, // mmtmpD0 contains real part of 4 consecutive outputs (32-bit) mmtmpD1 = _mm_shufflelo_epi16(dl_ch1_128[2],_MM_SHUFFLE(2,3,0,1)); mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1,_MM_SHUFFLE(2,3,0,1)); - mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i*)conjugate); + mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i *)conjugate); mmtmpD1 = _mm_madd_epi16(mmtmpD1,rxdataF128[2]); // mmtmpD1 contains imag part of 4 consecutive outputs (32-bit) mmtmpD0 = _mm_srai_epi32(mmtmpD0,output_shift1); mmtmpD1 = _mm_srai_epi32(mmtmpD1,output_shift1); mmtmpD2 = _mm_unpacklo_epi32(mmtmpD0,mmtmpD1); mmtmpD3 = _mm_unpackhi_epi32(mmtmpD0,mmtmpD1); - rxdataF_comp1_128[2] = _mm_packs_epi32(mmtmpD2,mmtmpD3); - // print_shorts("rx:",rxdataF128+2); - // print_shorts("ch:",dl_ch1_128+2); - // print_shorts("pack:",rxdataF_comp1_128+2); - + // print_shorts("rx:",rxdataF128+2); + // print_shorts("ch:",dl_ch1_128+2); + // print_shorts("pack:",rxdataF_comp1_128+2); dl_ch0_128+=3; dl_ch1_128+=3; dl_ch_mag0_128+=3; @@ -2932,8 +2734,7 @@ void dlsch_channel_compensation_TM34(LTE_DL_FRAME_PARMS *frame_parms, rxdataF128+=3; rxdataF_comp0_128+=3; rxdataF_comp1_128+=3; - } - else { + } else { dl_ch0_128+=2; dl_ch1_128+=2; dl_ch_mag0_128+=2; @@ -2944,40 +2745,32 @@ void dlsch_channel_compensation_TM34(LTE_DL_FRAME_PARMS *frame_parms, rxdataF_comp0_128+=2; rxdataF_comp1_128+=2; } - } // rb loop - Nre = (pilots==0) ? 12 : 8; + Nre = (pilots==0) ? 12 : 8; precoded_signal_strength0 += ((signal_energy_nodc(&dl_ch_estimates_ext[aarx][symbol*frame_parms->N_RB_DL*Nre], - (nb_rb*Nre))*rx_power_correction) - (measurements->n0_power[aarx])); - + (nb_rb*Nre))*rx_power_correction) - (measurements->n0_power[aarx])); precoded_signal_strength1 += ((signal_energy_nodc(&dl_ch_estimates_ext[aarx+2][symbol*frame_parms->N_RB_DL*Nre], - (nb_rb*Nre))*rx_power_correction) - (measurements->n0_power[aarx])); + (nb_rb*Nre))*rx_power_correction) - (measurements->n0_power[aarx])); } // rx_antennas measurements->precoded_cqi_dB[eNB_id][0] = dB_fixed2(precoded_signal_strength0,measurements->n0_power_tot); measurements->precoded_cqi_dB[eNB_id][1] = dB_fixed2(precoded_signal_strength1,measurements->n0_power_tot); - - // printf("eNB_id %d, symbol %d: precoded CQI %d dB\n",eNB_id,symbol, - // measurements->precoded_cqi_dB[eNB_id][0]); - + // printf("eNB_id %d, symbol %d: precoded CQI %d dB\n",eNB_id,symbol, + // measurements->precoded_cqi_dB[eNB_id][0]); _mm_empty(); _m_empty(); - - #elif defined(__arm__) - +#elif defined(__arm__) unsigned short rb,Nre; unsigned char aarx,symbol_mod,pilots=0; int precoded_signal_strength0=0,precoded_signal_strength1=0, rx_power_correction; int16x4_t *dl_ch0_128,*rxdataF128; int16x4_t *dl_ch1_128; int16x8_t *dl_ch0_128b,*dl_ch1_128b; - int32x4_t mmtmpD0,mmtmpD1,mmtmpD0b,mmtmpD1b; int16x8_t *dl_ch_mag0_128,*dl_ch_mag0_128b,*dl_ch_mag1_128,*dl_ch_mag1_128b,mmtmpD2,mmtmpD3,mmtmpD4,*rxdataF_comp0_128,*rxdataF_comp1_128; int16x8_t QAM_amp0_128,QAM_amp0_128b,QAM_amp1_128,QAM_amp1_128b; int32x4_t output_shift128 = vmovq_n_s32(-(int32_t)output_shift); - int **rxdataF_ext = pdsch_vars->rxdataF_ext; int **dl_ch_estimates_ext = pdsch_vars->dl_ch_estimates_ext; int **dl_ch_mag0 = pdsch_vars->dl_ch_mag0; @@ -2986,17 +2779,15 @@ void dlsch_channel_compensation_TM34(LTE_DL_FRAME_PARMS *frame_parms, int **dl_ch_magb1 = pdsch_vars->dl_ch_magb1[harq_pid][round]; int **rxdataF_comp0 = pdsch_vars->rxdataF_comp0; int **rxdataF_comp1 = pdsch_vars->rxdataF_comp1[harq_pid][round]; - int16_t conj[4]__attribute__((aligned(16))) = {1,-1,1,-1}; - symbol_mod = (symbol>=(7-frame_parms->Ncp)) ? symbol-(7-frame_parms->Ncp) : symbol; if ((symbol_mod == 0) || (symbol_mod == (4-frame_parms->Ncp))) { - if (frame_parms->nb_antenna_ports_eNB==1) // 10 out of 12 so don't reduce size - { nb_rb=1+(5*nb_rb/6); } - - else - { pilots=1; } + if (frame_parms->nb_antenna_ports_eNB==1) { // 10 out of 12 so don't reduce size + nb_rb=1+(5*nb_rb/6); + } else { + pilots=1; + } } rx_power_correction=1; @@ -3004,7 +2795,6 @@ void dlsch_channel_compensation_TM34(LTE_DL_FRAME_PARMS *frame_parms, if (mod_order0 == 4) { QAM_amp0_128 = vmovq_n_s16(QAM16_n1); // 2/sqrt(10) QAM_amp0_128b = vmovq_n_s16(0); - } else if (mod_order0 == 6) { QAM_amp0_128 = vmovq_n_s16(QAM64_n1); // QAM_amp0_128b = vmovq_n_s16(QAM64_n2); @@ -3013,7 +2803,6 @@ void dlsch_channel_compensation_TM34(LTE_DL_FRAME_PARMS *frame_parms, if (mod_order1 == 4) { QAM_amp1_128 = vmovq_n_s16(QAM16_n1); // 2/sqrt(10) QAM_amp1_128b = vmovq_n_s16(0); - } else if (mod_order1 == 6) { QAM_amp1_128 = vmovq_n_s16(QAM64_n1); // QAM_amp1_128b = vmovq_n_s16(QAM64_n2); @@ -3022,20 +2811,17 @@ void dlsch_channel_compensation_TM34(LTE_DL_FRAME_PARMS *frame_parms, // printf("comp: rxdataF_comp %p, symbol %d\n",rxdataF_comp[0],symbol); for (aarx=0; aarx<frame_parms->nb_antennas_rx; aarx++) { - - - - dl_ch0_128 = (int16x4_t*)&dl_ch_estimates_ext[aarx][symbol*frame_parms->N_RB_DL*12]; - dl_ch1_128 = (int16x4_t*)&dl_ch_estimates_ext[2+aarx][symbol*frame_parms->N_RB_DL*12]; - dl_ch0_128b = (int16x8_t*)&dl_ch_estimates_ext[aarx][symbol*frame_parms->N_RB_DL*12]; - dl_ch1_128b = (int16x8_t*)&dl_ch_estimates_ext[2+aarx][symbol*frame_parms->N_RB_DL*12]; - dl_ch_mag0_128 = (int16x8_t*)&dl_ch_mag0[aarx][symbol*frame_parms->N_RB_DL*12]; - dl_ch_mag0_128b = (int16x8_t*)&dl_ch_magb0[aarx][symbol*frame_parms->N_RB_DL*12]; - dl_ch_mag1_128 = (int16x8_t*)&dl_ch_mag1[aarx][symbol*frame_parms->N_RB_DL*12]; - dl_ch_mag1_128b = (int16x8_t*)&dl_ch_magb1[aarx][symbol*frame_parms->N_RB_DL*12]; - rxdataF128 = (int16x4_t*)&rxdataF_ext[aarx][symbol*frame_parms->N_RB_DL*12]; - rxdataF_comp0_128 = (int16x8_t*)&rxdataF_comp0[aarx][symbol*frame_parms->N_RB_DL*12]; - rxdataF_comp1_128 = (int16x8_t*)&rxdataF_comp1[aarx][symbol*frame_parms->N_RB_DL*12]; + dl_ch0_128 = (int16x4_t *)&dl_ch_estimates_ext[aarx][symbol*frame_parms->N_RB_DL*12]; + dl_ch1_128 = (int16x4_t *)&dl_ch_estimates_ext[2+aarx][symbol*frame_parms->N_RB_DL*12]; + dl_ch0_128b = (int16x8_t *)&dl_ch_estimates_ext[aarx][symbol*frame_parms->N_RB_DL*12]; + dl_ch1_128b = (int16x8_t *)&dl_ch_estimates_ext[2+aarx][symbol*frame_parms->N_RB_DL*12]; + dl_ch_mag0_128 = (int16x8_t *)&dl_ch_mag0[aarx][symbol*frame_parms->N_RB_DL*12]; + dl_ch_mag0_128b = (int16x8_t *)&dl_ch_magb0[aarx][symbol*frame_parms->N_RB_DL*12]; + dl_ch_mag1_128 = (int16x8_t *)&dl_ch_mag1[aarx][symbol*frame_parms->N_RB_DL*12]; + dl_ch_mag1_128b = (int16x8_t *)&dl_ch_magb1[aarx][symbol*frame_parms->N_RB_DL*12]; + rxdataF128 = (int16x4_t *)&rxdataF_ext[aarx][symbol*frame_parms->N_RB_DL*12]; + rxdataF_comp0_128 = (int16x8_t *)&rxdataF_comp0[aarx][symbol*frame_parms->N_RB_DL*12]; + rxdataF_comp1_128 = (int16x8_t *)&rxdataF_comp1[aarx][symbol*frame_parms->N_RB_DL*12]; for (rb=0; rb<nb_rb; rb++) { if (mmse_flag == 0) { @@ -3043,28 +2829,30 @@ void dlsch_channel_compensation_TM34(LTE_DL_FRAME_PARMS *frame_parms, if (mimo_mode==LARGE_CDD) { prec2A_TM3_128(&dl_ch0_128[0],&dl_ch1_128[0]); prec2A_TM3_128(&dl_ch0_128[1],&dl_ch1_128[1]); + if (pilots==0) { prec2A_TM3_128(&dl_ch0_128[2],&dl_ch1_128[2]); } - }else if (mimo_mode==DUALSTREAM_UNIFORM_PRECODING1) { + } else if (mimo_mode==DUALSTREAM_UNIFORM_PRECODING1) { prec2A_TM4_128(0,&dl_ch0_128[0],&dl_ch1_128[0]); prec2A_TM4_128(0,&dl_ch0_128[1],&dl_ch1_128[1]); + if (pilots==0) { prec2A_TM4_128(0,&dl_ch0_128[2],&dl_ch1_128[2]); } - }else if (mimo_mode==DUALSTREAM_UNIFORM_PRECODINGj) { + } else if (mimo_mode==DUALSTREAM_UNIFORM_PRECODINGj) { prec2A_TM4_128(1,&dl_ch0_128[0],&dl_ch1_128[0]); prec2A_TM4_128(1,&dl_ch0_128[1],&dl_ch1_128[1]); + if (pilots==0) { prec2A_TM4_128(1,&dl_ch0_128[2],&dl_ch1_128[2]); } - }else { + } else { LOG_E(PHY,"Unknown MIMO mode\n"); return; } } - if (mod_order0>2) { // get channel amplitude if not QPSK mmtmpD0 = vmull_s16(dl_ch0_128[0], dl_ch0_128[0]); @@ -3087,8 +2875,6 @@ void dlsch_channel_compensation_TM34(LTE_DL_FRAME_PARMS *frame_parms, mmtmpD1 = vmull_s16(dl_ch0_128[5], dl_ch0_128[5]); mmtmpD1 = vqshlq_s32(vqaddq_s32(mmtmpD1,vrev64q_s32(mmtmpD1)),output_shift128); mmtmpD4 = vcombine_s16(vmovn_s32(mmtmpD0),vmovn_s32(mmtmpD1)); - - } dl_ch_mag0_128b[0] = vqdmulhq_s16(mmtmpD2,QAM_amp0_128b); @@ -3096,7 +2882,6 @@ void dlsch_channel_compensation_TM34(LTE_DL_FRAME_PARMS *frame_parms, dl_ch_mag0_128[0] = vqdmulhq_s16(mmtmpD2,QAM_amp0_128); dl_ch_mag0_128[1] = vqdmulhq_s16(mmtmpD3,QAM_amp0_128); - if (pilots==0) { dl_ch_mag0_128b[2] = vqdmulhq_s16(mmtmpD4,QAM_amp0_128b); dl_ch_mag0_128[2] = vqdmulhq_s16(mmtmpD4,QAM_amp0_128); @@ -3125,8 +2910,6 @@ void dlsch_channel_compensation_TM34(LTE_DL_FRAME_PARMS *frame_parms, mmtmpD1 = vmull_s16(dl_ch1_128[5], dl_ch1_128[5]); mmtmpD1 = vqshlq_s32(vqaddq_s32(mmtmpD1,vrev64q_s32(mmtmpD1)),output_shift128); mmtmpD4 = vcombine_s16(vmovn_s32(mmtmpD0),vmovn_s32(mmtmpD1)); - - } dl_ch_mag1_128b[0] = vqdmulhq_s16(mmtmpD2,QAM_amp1_128b); @@ -3134,7 +2917,6 @@ void dlsch_channel_compensation_TM34(LTE_DL_FRAME_PARMS *frame_parms, dl_ch_mag1_128[0] = vqdmulhq_s16(mmtmpD2,QAM_amp1_128); dl_ch_mag1_128[1] = vqdmulhq_s16(mmtmpD3,QAM_amp1_128); - if (pilots==0) { dl_ch_mag1_128b[2] = vqdmulhq_s16(mmtmpD4,QAM_amp1_128b); dl_ch_mag1_128[2] = vqdmulhq_s16(mmtmpD4,QAM_amp1_128); @@ -3148,60 +2930,49 @@ void dlsch_channel_compensation_TM34(LTE_DL_FRAME_PARMS *frame_parms, mmtmpD0 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0),vget_high_s32(mmtmpD0)), vpadd_s32(vget_low_s32(mmtmpD1),vget_high_s32(mmtmpD1))); //mmtmpD0 = [Re(ch[0])Re(rx[0])+Im(ch[0])Im(ch[0]) Re(ch[1])Re(rx[1])+Im(ch[1])Im(ch[1]) Re(ch[2])Re(rx[2])+Im(ch[2])Im(ch[2]) Re(ch[3])Re(rx[3])+Im(ch[3])Im(ch[3])] - - mmtmpD0b = vmull_s16(vrev32_s16(vmul_s16(dl_ch0_128[0],*(int16x4_t*)conj)), rxdataF128[0]); + mmtmpD0b = vmull_s16(vrev32_s16(vmul_s16(dl_ch0_128[0],*(int16x4_t *)conj)), rxdataF128[0]); //mmtmpD0 = [-Im(ch[0])Re(rx[0]) Re(ch[0])Im(rx[0]) -Im(ch[1])Re(rx[1]) Re(ch[1])Im(rx[1])] - mmtmpD1b = vmull_s16(vrev32_s16(vmul_s16(dl_ch0_128[1],*(int16x4_t*)conj)), rxdataF128[1]); + mmtmpD1b = vmull_s16(vrev32_s16(vmul_s16(dl_ch0_128[1],*(int16x4_t *)conj)), rxdataF128[1]); //mmtmpD0 = [-Im(ch[2])Re(rx[2]) Re(ch[2])Im(rx[2]) -Im(ch[3])Re(rx[3]) Re(ch[3])Im(rx[3])] mmtmpD1 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0b),vget_high_s32(mmtmpD0b)), vpadd_s32(vget_low_s32(mmtmpD1b),vget_high_s32(mmtmpD1b))); //mmtmpD1 = [-Im(ch[0])Re(rx[0])+Re(ch[0])Im(rx[0]) -Im(ch[1])Re(rx[1])+Re(ch[1])Im(rx[1]) -Im(ch[2])Re(rx[2])+Re(ch[2])Im(rx[2]) -Im(ch[3])Re(rx[3])+Re(ch[3])Im(rx[3])] - mmtmpD0 = vqshlq_s32(mmtmpD0,output_shift128); mmtmpD1 = vqshlq_s32(mmtmpD1,output_shift128); rxdataF_comp0_128[0] = vcombine_s16(vmovn_s32(mmtmpD0),vmovn_s32(mmtmpD1)); - mmtmpD0 = vmull_s16(dl_ch0_128[2], rxdataF128[2]); mmtmpD1 = vmull_s16(dl_ch0_128[3], rxdataF128[3]); mmtmpD0 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0),vget_high_s32(mmtmpD0)), vpadd_s32(vget_low_s32(mmtmpD1),vget_high_s32(mmtmpD1))); - - mmtmpD0b = vmull_s16(vrev32_s16(vmul_s16(dl_ch0_128[2],*(int16x4_t*)conj)), rxdataF128[2]); - mmtmpD1b = vmull_s16(vrev32_s16(vmul_s16(dl_ch0_128[3],*(int16x4_t*)conj)), rxdataF128[3]); + mmtmpD0b = vmull_s16(vrev32_s16(vmul_s16(dl_ch0_128[2],*(int16x4_t *)conj)), rxdataF128[2]); + mmtmpD1b = vmull_s16(vrev32_s16(vmul_s16(dl_ch0_128[3],*(int16x4_t *)conj)), rxdataF128[3]); mmtmpD1 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0b),vget_high_s32(mmtmpD0b)), vpadd_s32(vget_low_s32(mmtmpD1b),vget_high_s32(mmtmpD1b))); - mmtmpD0 = vqshlq_s32(mmtmpD0,output_shift128); mmtmpD1 = vqshlq_s32(mmtmpD1,output_shift128); rxdataF_comp0_128[1] = vcombine_s16(vmovn_s32(mmtmpD0),vmovn_s32(mmtmpD1)); - // second stream mmtmpD0 = vmull_s16(dl_ch1_128[0], rxdataF128[0]); mmtmpD1 = vmull_s16(dl_ch1_128[1], rxdataF128[1]); mmtmpD0 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0),vget_high_s32(mmtmpD0)), vpadd_s32(vget_low_s32(mmtmpD1),vget_high_s32(mmtmpD1))); - mmtmpD0b = vmull_s16(vrev32_s16(vmul_s16(dl_ch0_128[0],*(int16x4_t*)conj)), rxdataF128[0]); - - mmtmpD1b = vmull_s16(vrev32_s16(vmul_s16(dl_ch0_128[1],*(int16x4_t*)conj)), rxdataF128[1]); + mmtmpD0b = vmull_s16(vrev32_s16(vmul_s16(dl_ch0_128[0],*(int16x4_t *)conj)), rxdataF128[0]); + mmtmpD1b = vmull_s16(vrev32_s16(vmul_s16(dl_ch0_128[1],*(int16x4_t *)conj)), rxdataF128[1]); //mmtmpD0 = [-Im(ch[2])Re(rx[2]) Re(ch[2])Im(rx[2]) -Im(ch[3])Re(rx[3]) Re(ch[3])Im(rx[3])] mmtmpD1 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0b),vget_high_s32(mmtmpD0b)), vpadd_s32(vget_low_s32(mmtmpD1b),vget_high_s32(mmtmpD1b))); //mmtmpD1 = [-Im(ch[0])Re(rx[0])+Re(ch[0])Im(rx[0]) -Im(ch[1])Re(rx[1])+Re(ch[1])Im(rx[1]) -Im(ch[2])Re(rx[2])+Re(ch[2])Im(rx[2]) -Im(ch[3])Re(rx[3])+Re(ch[3])Im(rx[3])] - mmtmpD0 = vqshlq_s32(mmtmpD0,output_shift128); mmtmpD1 = vqshlq_s32(mmtmpD1,output_shift128); rxdataF_comp1_128[0] = vcombine_s16(vmovn_s32(mmtmpD0),vmovn_s32(mmtmpD1)); - mmtmpD0 = vmull_s16(dl_ch1_128[2], rxdataF128[2]); mmtmpD1 = vmull_s16(dl_ch1_128[3], rxdataF128[3]); mmtmpD0 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0),vget_high_s32(mmtmpD0)), vpadd_s32(vget_low_s32(mmtmpD1),vget_high_s32(mmtmpD1))); - - mmtmpD0b = vmull_s16(vrev32_s16(vmul_s16(dl_ch0_128[2],*(int16x4_t*)conj)), rxdataF128[2]); - mmtmpD1b = vmull_s16(vrev32_s16(vmul_s16(dl_ch0_128[3],*(int16x4_t*)conj)), rxdataF128[3]); + mmtmpD0b = vmull_s16(vrev32_s16(vmul_s16(dl_ch0_128[2],*(int16x4_t *)conj)), rxdataF128[2]); + mmtmpD1b = vmull_s16(vrev32_s16(vmul_s16(dl_ch0_128[3],*(int16x4_t *)conj)), rxdataF128[3]); mmtmpD1 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0b),vget_high_s32(mmtmpD0b)), vpadd_s32(vget_low_s32(mmtmpD1b),vget_high_s32(mmtmpD1b))); - mmtmpD0 = vqshlq_s32(mmtmpD0,output_shift128); mmtmpD1 = vqshlq_s32(mmtmpD1,output_shift128); rxdataF_comp1_128[1] = vcombine_s16(vmovn_s32(mmtmpD0),vmovn_s32(mmtmpD1)); @@ -3211,13 +2982,10 @@ void dlsch_channel_compensation_TM34(LTE_DL_FRAME_PARMS *frame_parms, mmtmpD1 = vmull_s16(dl_ch0_128[5], rxdataF128[5]); mmtmpD0 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0),vget_high_s32(mmtmpD0)), vpadd_s32(vget_low_s32(mmtmpD1),vget_high_s32(mmtmpD1))); - - mmtmpD0b = vmull_s16(vrev32_s16(vmul_s16(dl_ch0_128[4],*(int16x4_t*)conj)), rxdataF128[4]); - mmtmpD1b = vmull_s16(vrev32_s16(vmul_s16(dl_ch0_128[5],*(int16x4_t*)conj)), rxdataF128[5]); + mmtmpD0b = vmull_s16(vrev32_s16(vmul_s16(dl_ch0_128[4],*(int16x4_t *)conj)), rxdataF128[4]); + mmtmpD1b = vmull_s16(vrev32_s16(vmul_s16(dl_ch0_128[5],*(int16x4_t *)conj)), rxdataF128[5]); mmtmpD1 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0b),vget_high_s32(mmtmpD0b)), vpadd_s32(vget_low_s32(mmtmpD1b),vget_high_s32(mmtmpD1b))); - - mmtmpD0 = vqshlq_s32(mmtmpD0,output_shift128); mmtmpD1 = vqshlq_s32(mmtmpD1,output_shift128); rxdataF_comp0_128[2] = vcombine_s16(vmovn_s32(mmtmpD0),vmovn_s32(mmtmpD1)); @@ -3225,37 +2993,27 @@ void dlsch_channel_compensation_TM34(LTE_DL_FRAME_PARMS *frame_parms, mmtmpD1 = vmull_s16(dl_ch1_128[5], rxdataF128[5]); mmtmpD0 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0),vget_high_s32(mmtmpD0)), vpadd_s32(vget_low_s32(mmtmpD1),vget_high_s32(mmtmpD1))); - - mmtmpD0b = vmull_s16(vrev32_s16(vmul_s16(dl_ch1_128[4],*(int16x4_t*)conj)), rxdataF128[4]); - mmtmpD1b = vmull_s16(vrev32_s16(vmul_s16(dl_ch1_128[5],*(int16x4_t*)conj)), rxdataF128[5]); + mmtmpD0b = vmull_s16(vrev32_s16(vmul_s16(dl_ch1_128[4],*(int16x4_t *)conj)), rxdataF128[4]); + mmtmpD1b = vmull_s16(vrev32_s16(vmul_s16(dl_ch1_128[5],*(int16x4_t *)conj)), rxdataF128[5]); mmtmpD1 = vcombine_s32(vpadd_s32(vget_low_s32(mmtmpD0b),vget_high_s32(mmtmpD0b)), vpadd_s32(vget_low_s32(mmtmpD1b),vget_high_s32(mmtmpD1b))); - - mmtmpD0 = vqshlq_s32(mmtmpD0,output_shift128); mmtmpD1 = vqshlq_s32(mmtmpD1,output_shift128); rxdataF_comp1_128[2] = vcombine_s16(vmovn_s32(mmtmpD0),vmovn_s32(mmtmpD1)); } } - - Nre = (pilots==0) ? 12 : 8; - // rx_antennas } - Nre = (pilots==0) ? 12 : 8; - precoded_signal_strength0 += ((signal_energy_nodc(&dl_ch_estimates_ext[aarx][symbol*frame_parms->N_RB_DL*Nre], - (nb_rb*Nre))*rx_power_correction) - (measurements->n0_power[aarx])); + (nb_rb*Nre))*rx_power_correction) - (measurements->n0_power[aarx])); precoded_signal_strength1 += ((signal_energy_nodc(&dl_ch_estimates_ext[aarx+2][symbol*frame_parms->N_RB_DL*Nre], - (nb_rb*Nre))*rx_power_correction) - (measurements->n0_power[aarx])); - + (nb_rb*Nre))*rx_power_correction) - (measurements->n0_power[aarx])); measurements->precoded_cqi_dB[eNB_id][0] = dB_fixed2(precoded_signal_strength0,measurements->n0_power_tot); measurements->precoded_cqi_dB[eNB_id][1] = dB_fixed2(precoded_signal_strength1,measurements->n0_power_tot); - #endif } @@ -3266,17 +3024,12 @@ void dlsch_dual_stream_correlation(LTE_DL_FRAME_PARMS *frame_parms, int **dl_ch_estimates_ext, int **dl_ch_estimates_ext_i, int **dl_ch_rho_ext, - unsigned char output_shift) -{ - + unsigned char output_shift) { #if defined(__x86_64__)||defined(__i386__) - unsigned short rb; __m128i *dl_ch128,*dl_ch128i,*dl_ch_rho128,mmtmpD0,mmtmpD1,mmtmpD2,mmtmpD3; unsigned char aarx,symbol_mod,pilots=0; - // printf("dlsch_dual_stream_correlation: symbol %d\n",symbol); - symbol_mod = (symbol>=(7-frame_parms->Ncp)) ? symbol-(7-frame_parms->Ncp) : symbol; if ((symbol_mod == 0) || (symbol_mod == (4-frame_parms->Ncp))) { @@ -3286,7 +3039,6 @@ void dlsch_dual_stream_correlation(LTE_DL_FRAME_PARMS *frame_parms, // printf("Dual stream correlation (%p)\n",dl_ch_estimates_ext_i); for (aarx=0; aarx<frame_parms->nb_antennas_rx; aarx++) { - dl_ch128 = (__m128i *)&dl_ch_estimates_ext[aarx][symbol*frame_parms->N_RB_DL*12]; if (dl_ch_estimates_ext_i == NULL) // TM3/4 @@ -3303,7 +3055,7 @@ void dlsch_dual_stream_correlation(LTE_DL_FRAME_PARMS *frame_parms, // mmtmpD0 contains real part of 4 consecutive outputs (32-bit) mmtmpD1 = _mm_shufflelo_epi16(dl_ch128[0],_MM_SHUFFLE(2,3,0,1)); mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1,_MM_SHUFFLE(2,3,0,1)); - mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i*)&conjugate[0]); + mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i *)&conjugate[0]); mmtmpD1 = _mm_madd_epi16(mmtmpD1,dl_ch128i[0]); // print_ints("im",&mmtmpD1); // mmtmpD1 contains imag part of 4 consecutive outputs (32-bit) @@ -3316,13 +3068,13 @@ void dlsch_dual_stream_correlation(LTE_DL_FRAME_PARMS *frame_parms, // print_ints("c0",&mmtmpD2); // print_ints("c1",&mmtmpD3); dl_ch_rho128[0] = _mm_packs_epi32(mmtmpD2,mmtmpD3); - // print_shorts("rho 0:",dl_ch_rho128); + // print_shorts("rho 0:",dl_ch_rho128); // multiply by conjugated channel mmtmpD0 = _mm_madd_epi16(dl_ch128[1],dl_ch128i[1]); // mmtmpD0 contains real part of 4 consecutive outputs (32-bit) mmtmpD1 = _mm_shufflelo_epi16(dl_ch128[1],_MM_SHUFFLE(2,3,0,1)); mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1,_MM_SHUFFLE(2,3,0,1)); - mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i*)conjugate); + mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i *)conjugate); mmtmpD1 = _mm_madd_epi16(mmtmpD1,dl_ch128i[1]); // mmtmpD1 contains imag part of 4 consecutive outputs (32-bit) mmtmpD0 = _mm_srai_epi32(mmtmpD0,output_shift); @@ -3331,15 +3083,13 @@ void dlsch_dual_stream_correlation(LTE_DL_FRAME_PARMS *frame_parms, mmtmpD3 = _mm_unpackhi_epi32(mmtmpD0,mmtmpD1); dl_ch_rho128[1] =_mm_packs_epi32(mmtmpD2,mmtmpD3); - if (pilots==0) { - // multiply by conjugated channel mmtmpD0 = _mm_madd_epi16(dl_ch128[2],dl_ch128i[2]); // mmtmpD0 contains real part of 4 consecutive outputs (32-bit) mmtmpD1 = _mm_shufflelo_epi16(dl_ch128[2],_MM_SHUFFLE(2,3,0,1)); mmtmpD1 = _mm_shufflehi_epi16(mmtmpD1,_MM_SHUFFLE(2,3,0,1)); - mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i*)conjugate); + mmtmpD1 = _mm_sign_epi16(mmtmpD1,*(__m128i *)conjugate); mmtmpD1 = _mm_madd_epi16(mmtmpD1,dl_ch128i[2]); // mmtmpD1 contains imag part of 4 consecutive outputs (32-bit) mmtmpD0 = _mm_srai_epi32(mmtmpD0,output_shift); @@ -3347,25 +3097,20 @@ void dlsch_dual_stream_correlation(LTE_DL_FRAME_PARMS *frame_parms, mmtmpD2 = _mm_unpacklo_epi32(mmtmpD0,mmtmpD1); mmtmpD3 = _mm_unpackhi_epi32(mmtmpD0,mmtmpD1); dl_ch_rho128[2] = _mm_packs_epi32(mmtmpD2,mmtmpD3); - - dl_ch128+=3; + dl_ch128+=3; dl_ch128i+=3; dl_ch_rho128+=3; } else { - dl_ch128+=2; dl_ch128i+=2; dl_ch_rho128+=2; } } - } _mm_empty(); _m_empty(); - #elif defined(__arm__) - #endif } @@ -3381,20 +3126,15 @@ void dlsch_detection_mrc(LTE_DL_FRAME_PARMS *frame_parms, int **dl_ch_magb_i, unsigned char symbol, unsigned short nb_rb, - unsigned char dual_stream_UE) -{ - + unsigned char dual_stream_UE) { #if defined(__x86_64__)||defined(__i386__) - unsigned char aatx; int i; __m128i *rxdataF_comp128_0,*rxdataF_comp128_1,*rxdataF_comp128_i0,*rxdataF_comp128_i1,*dl_ch_mag128_0,*dl_ch_mag128_1,*dl_ch_mag128_0b,*dl_ch_mag128_1b,*rho128_0,*rho128_1,*rho128_i0,*rho128_i1, - *dl_ch_mag128_i0,*dl_ch_mag128_i1,*dl_ch_mag128_i0b,*dl_ch_mag128_i1b; + *dl_ch_mag128_i0,*dl_ch_mag128_i1,*dl_ch_mag128_i0b,*dl_ch_mag128_i1b; if (frame_parms->nb_antennas_rx>1) { - for (aatx=0; aatx<frame_parms->nb_antenna_ports_eNB; aatx++) { - rxdataF_comp128_0 = (__m128i *)&rxdataF_comp[(aatx<<1)][symbol*frame_parms->N_RB_DL*12]; rxdataF_comp128_1 = (__m128i *)&rxdataF_comp[(aatx<<1)+1][symbol*frame_parms->N_RB_DL*12]; dl_ch_mag128_0 = (__m128i *)&dl_ch_mag[(aatx<<1)][symbol*frame_parms->N_RB_DL*12]; @@ -3403,29 +3143,28 @@ void dlsch_detection_mrc(LTE_DL_FRAME_PARMS *frame_parms, dl_ch_mag128_1b = (__m128i *)&dl_ch_magb[(aatx<<1)+1][symbol*frame_parms->N_RB_DL*12]; // MRC on each re of rb, both on MF output and magnitude (for 16QAM/64QAM llr computation) - for (i=0;i<nb_rb*3;i++) { + for (i=0; i<nb_rb*3; i++) { rxdataF_comp128_0[i] = _mm_adds_epi16(_mm_srai_epi16(rxdataF_comp128_0[i],1),_mm_srai_epi16(rxdataF_comp128_1[i],1)); dl_ch_mag128_0[i] = _mm_adds_epi16(_mm_srai_epi16(dl_ch_mag128_0[i],1),_mm_srai_epi16(dl_ch_mag128_1[i],1)); dl_ch_mag128_0b[i] = _mm_adds_epi16(_mm_srai_epi16(dl_ch_mag128_0b[i],1),_mm_srai_epi16(dl_ch_mag128_1b[i],1)); - // print_shorts("mrc comp0:",&rxdataF_comp128_0[i]); + // print_shorts("mrc comp0:",&rxdataF_comp128_0[i]); // print_shorts("mrc mag0:",&dl_ch_mag128_0[i]); // print_shorts("mrc mag0b:",&dl_ch_mag128_0b[i]); // print_shorts("mrc rho1:",&rho128_1[i]); - } } if (rho) { rho128_0 = (__m128i *) &rho[0][symbol*frame_parms->N_RB_DL*12]; rho128_1 = (__m128i *) &rho[1][symbol*frame_parms->N_RB_DL*12]; - for (i=0;i<nb_rb*3;i++) { + + for (i=0; i<nb_rb*3; i++) { // print_shorts("mrc rho0:",&rho128_0[i]); // print_shorts("mrc rho1:",&rho128_1[i]); rho128_0[i] = _mm_adds_epi16(_mm_srai_epi16(rho128_0[i],1),_mm_srai_epi16(rho128_1[i],1)); } } - if (dual_stream_UE == 1) { rho128_i0 = (__m128i *) &rho_i[0][symbol*frame_parms->N_RB_DL*12]; rho128_i1 = (__m128i *) &rho_i[1][symbol*frame_parms->N_RB_DL*12]; @@ -3439,7 +3178,6 @@ void dlsch_detection_mrc(LTE_DL_FRAME_PARMS *frame_parms, for (i=0; i<nb_rb*3; i++) { rxdataF_comp128_i0[i] = _mm_adds_epi16(_mm_srai_epi16(rxdataF_comp128_i0[i],1),_mm_srai_epi16(rxdataF_comp128_i1[i],1)); rho128_i0[i] = _mm_adds_epi16(_mm_srai_epi16(rho128_i0[i],1),_mm_srai_epi16(rho128_i1[i],1)); - dl_ch_mag128_i0[i] = _mm_adds_epi16(_mm_srai_epi16(dl_ch_mag128_i0[i],1),_mm_srai_epi16(dl_ch_mag128_i1[i],1)); dl_ch_mag128_i0b[i] = _mm_adds_epi16(_mm_srai_epi16(dl_ch_mag128_i0b[i],1),_mm_srai_epi16(dl_ch_mag128_i1b[i],1)); } @@ -3448,17 +3186,14 @@ void dlsch_detection_mrc(LTE_DL_FRAME_PARMS *frame_parms, _mm_empty(); _m_empty(); - #elif defined(__arm__) - unsigned char aatx; int i; - int16x8_t *rxdataF_comp128_0,*rxdataF_comp128_1,*rxdataF_comp128_i0,*rxdataF_comp128_i1,*dl_ch_mag128_0,*dl_ch_mag128_1,*dl_ch_mag128_0b,*dl_ch_mag128_1b,*rho128_0,*rho128_1,*rho128_i0,*rho128_i1,*dl_ch_mag128_i0,*dl_ch_mag128_i1,*dl_ch_mag128_i0b,*dl_ch_mag128_i1b; + int16x8_t *rxdataF_comp128_0,*rxdataF_comp128_1,*rxdataF_comp128_i0,*rxdataF_comp128_i1,*dl_ch_mag128_0,*dl_ch_mag128_1,*dl_ch_mag128_0b,*dl_ch_mag128_1b,*rho128_0,*rho128_1,*rho128_i0,*rho128_i1, + *dl_ch_mag128_i0,*dl_ch_mag128_i1,*dl_ch_mag128_i0b,*dl_ch_mag128_i1b; if (frame_parms->nb_antennas_rx>1) { - for (aatx=0; aatx<frame_parms->nb_antenna_ports_eNB; aatx++) { - rxdataF_comp128_0 = (int16x8_t *)&rxdataF_comp[(aatx<<1)][symbol*frame_parms->N_RB_DL*12]; rxdataF_comp128_1 = (int16x8_t *)&rxdataF_comp[(aatx<<1)+1][symbol*frame_parms->N_RB_DL*12]; dl_ch_mag128_0 = (int16x8_t *)&dl_ch_mag[(aatx<<1)][symbol*frame_parms->N_RB_DL*12]; @@ -3485,13 +3220,11 @@ void dlsch_detection_mrc(LTE_DL_FRAME_PARMS *frame_parms, } } - if (dual_stream_UE == 1) { rho128_i0 = (int16x8_t *) &rho_i[0][symbol*frame_parms->N_RB_DL*12]; rho128_i1 = (int16x8_t *) &rho_i[1][symbol*frame_parms->N_RB_DL*12]; rxdataF_comp128_i0 = (int16x8_t *)&rxdataF_comp_i[0][symbol*frame_parms->N_RB_DL*12]; rxdataF_comp128_i1 = (int16x8_t *)&rxdataF_comp_i[1][symbol*frame_parms->N_RB_DL*12]; - dl_ch_mag128_i0 = (int16x8_t *)&dl_ch_mag_i[0][symbol*frame_parms->N_RB_DL*12]; dl_ch_mag128_i1 = (int16x8_t *)&dl_ch_mag_i[1][symbol*frame_parms->N_RB_DL*12]; dl_ch_mag128_i0b = (int16x8_t *)&dl_ch_magb_i[0][symbol*frame_parms->N_RB_DL*12]; @@ -3500,7 +3233,6 @@ void dlsch_detection_mrc(LTE_DL_FRAME_PARMS *frame_parms, for (i=0; i<nb_rb*3; i++) { rxdataF_comp128_i0[i] = vhaddq_s16(rxdataF_comp128_i0[i],rxdataF_comp128_i1[i]); rho128_i0[i] = vhaddq_s16(rho128_i0[i],rho128_i1[i]); - dl_ch_mag128_i0[i] = vhaddq_s16(dl_ch_mag128_i0[i],dl_ch_mag128_i1[i]); dl_ch_mag128_i0b[i] = vhaddq_s16(dl_ch_mag128_i0b[i],dl_ch_mag128_i1b[i]); } @@ -3517,14 +3249,11 @@ void dlsch_detection_mrc_TM34(LTE_DL_FRAME_PARMS *frame_parms, unsigned char symbol, unsigned short nb_rb, unsigned char dual_stream_UE) { - int i; __m128i *rxdataF_comp128_0,*rxdataF_comp128_1; __m128i *dl_ch_mag128_0,*dl_ch_mag128_1; __m128i *dl_ch_mag128_0b,*dl_ch_mag128_1b; __m128i *rho128_0, *rho128_1; - - int **rxdataF_comp0 = pdsch_vars->rxdataF_comp0; int **rxdataF_comp1 = pdsch_vars->rxdataF_comp1[harq_pid][round]; int **dl_ch_rho_ext = pdsch_vars->dl_ch_rho_ext[harq_pid][round]; //for second stream @@ -3533,7 +3262,6 @@ void dlsch_detection_mrc_TM34(LTE_DL_FRAME_PARMS *frame_parms, int **dl_ch_mag1 = pdsch_vars->dl_ch_mag1[harq_pid][round]; int **dl_ch_magb0 = pdsch_vars->dl_ch_magb0; int **dl_ch_magb1 = pdsch_vars->dl_ch_magb1[harq_pid][round]; - rxdataF_comp128_0 = (__m128i *)&rxdataF_comp0[0][symbol*frame_parms->N_RB_DL*12]; rxdataF_comp128_1 = (__m128i *)&rxdataF_comp0[1][symbol*frame_parms->N_RB_DL*12]; dl_ch_mag128_0 = (__m128i *)&dl_ch_mag0[0][symbol*frame_parms->N_RB_DL*12]; @@ -3543,15 +3271,14 @@ void dlsch_detection_mrc_TM34(LTE_DL_FRAME_PARMS *frame_parms, rho128_0 = (__m128i *) &dl_ch_rho2_ext[0][symbol*frame_parms->N_RB_DL*12]; rho128_1 = (__m128i *) &dl_ch_rho2_ext[1][symbol*frame_parms->N_RB_DL*12]; - // MRC on each re of rb, both on MF output and magnitude (for 16QAM/64QAM llr computation) - for (i=0;i<nb_rb*3;i++) { + // MRC on each re of rb, both on MF output and magnitude (for 16QAM/64QAM llr computation) + for (i=0; i<nb_rb*3; i++) { rxdataF_comp128_0[i] = _mm_adds_epi16(_mm_srai_epi16(rxdataF_comp128_0[i],1),_mm_srai_epi16(rxdataF_comp128_1[i],1)); dl_ch_mag128_0[i] = _mm_adds_epi16(_mm_srai_epi16(dl_ch_mag128_0[i],1),_mm_srai_epi16(dl_ch_mag128_1[i],1)); dl_ch_mag128_0b[i] = _mm_adds_epi16(_mm_srai_epi16(dl_ch_mag128_0b[i],1),_mm_srai_epi16(dl_ch_mag128_1b[i],1)); rho128_0[i] = _mm_adds_epi16(_mm_srai_epi16(rho128_0[i],1),_mm_srai_epi16(rho128_1[i],1)); if (frame_parms->nb_antennas_rx>2) { - __m128i *rxdataF_comp128_2 = NULL; __m128i *rxdataF_comp128_3 = NULL; __m128i *dl_ch_mag128_2 = NULL; @@ -3560,7 +3287,6 @@ void dlsch_detection_mrc_TM34(LTE_DL_FRAME_PARMS *frame_parms, __m128i *dl_ch_mag128_3b = NULL; __m128i *rho128_2 = NULL; __m128i *rho128_3 = NULL; - rxdataF_comp128_2 = (__m128i *)&rxdataF_comp0[2][symbol*frame_parms->N_RB_DL*12]; rxdataF_comp128_3 = (__m128i *)&rxdataF_comp0[3][symbol*frame_parms->N_RB_DL*12]; dl_ch_mag128_2 = (__m128i *)&dl_ch_mag0[2][symbol*frame_parms->N_RB_DL*12]; @@ -3584,65 +3310,58 @@ void dlsch_detection_mrc_TM34(LTE_DL_FRAME_PARMS *frame_parms, } } - if (dual_stream_UE == 1) { - - __m128i *dl_ch_mag128_i0, *dl_ch_mag128_i1; - __m128i *dl_ch_mag128_i0b, *dl_ch_mag128_i1b; - __m128i *rho128_i0, *rho128_i1; - __m128i *rxdataF_comp128_i0, *rxdataF_comp128_i1; - - rxdataF_comp128_i0 = (__m128i *)&rxdataF_comp1[0][symbol*frame_parms->N_RB_DL*12]; - rxdataF_comp128_i1 = (__m128i *)&rxdataF_comp1[1][symbol*frame_parms->N_RB_DL*12]; - dl_ch_mag128_i0 = (__m128i *)&dl_ch_mag1[0][symbol*frame_parms->N_RB_DL*12]; - dl_ch_mag128_i1 = (__m128i *)&dl_ch_mag1[1][symbol*frame_parms->N_RB_DL*12]; - dl_ch_mag128_i0b = (__m128i *)&dl_ch_magb1[0][symbol*frame_parms->N_RB_DL*12]; - dl_ch_mag128_i1b = (__m128i *)&dl_ch_magb1[1][symbol*frame_parms->N_RB_DL*12]; - rho128_i0 = (__m128i *) &dl_ch_rho_ext[0][symbol*frame_parms->N_RB_DL*12]; - rho128_i1 = (__m128i *) &dl_ch_rho_ext[1][symbol*frame_parms->N_RB_DL*12]; - - - for (i=0;i<nb_rb*3;i++) { - rxdataF_comp128_i0[i] = _mm_adds_epi16(_mm_srai_epi16(rxdataF_comp128_i0[i],1),_mm_srai_epi16(rxdataF_comp128_i1[i],1)); - dl_ch_mag128_i0[i] = _mm_adds_epi16(_mm_srai_epi16(dl_ch_mag128_i0[i],1),_mm_srai_epi16(dl_ch_mag128_i1[i],1)); - dl_ch_mag128_i0b[i] = _mm_adds_epi16(_mm_srai_epi16(dl_ch_mag128_i0b[i],1),_mm_srai_epi16(dl_ch_mag128_i1b[i],1)); - rho128_i0[i] = _mm_adds_epi16(_mm_srai_epi16(rho128_i0[i],1),_mm_srai_epi16(rho128_i1[i],1)); - - if (frame_parms->nb_antennas_rx>2) { - - __m128i *rxdataF_comp128_i2 = NULL; - __m128i *rxdataF_comp128_i3 = NULL; - __m128i *dl_ch_mag128_i2 = NULL; - __m128i *dl_ch_mag128_i3 = NULL; - __m128i *dl_ch_mag128_i2b = NULL; - __m128i *dl_ch_mag128_i3b = NULL; - __m128i *rho128_i2 = NULL; - __m128i *rho128_i3 = NULL; - - rxdataF_comp128_i2 = (__m128i *)&rxdataF_comp1[2][symbol*frame_parms->N_RB_DL*12]; - rxdataF_comp128_i3 = (__m128i *)&rxdataF_comp1[3][symbol*frame_parms->N_RB_DL*12]; - dl_ch_mag128_i2 = (__m128i *)&dl_ch_mag1[2][symbol*frame_parms->N_RB_DL*12]; - dl_ch_mag128_i3 = (__m128i *)&dl_ch_mag1[3][symbol*frame_parms->N_RB_DL*12]; - dl_ch_mag128_i2b = (__m128i *)&dl_ch_magb1[2][symbol*frame_parms->N_RB_DL*12]; - dl_ch_mag128_i3b = (__m128i *)&dl_ch_magb1[3][symbol*frame_parms->N_RB_DL*12]; - rho128_i2 = (__m128i *) &dl_ch_rho_ext[2][symbol*frame_parms->N_RB_DL*12]; - rho128_i3 = (__m128i *) &dl_ch_rho_ext[3][symbol*frame_parms->N_RB_DL*12]; - - - /*rxdataF_comp*/ - rxdataF_comp128_i2[i] = _mm_adds_epi16(_mm_srai_epi16(rxdataF_comp128_i2[i],1),_mm_srai_epi16(rxdataF_comp128_i3[i],1)); - rxdataF_comp128_i0[i] = _mm_adds_epi16(_mm_srai_epi16(rxdataF_comp128_i0[i],1),_mm_srai_epi16(rxdataF_comp128_i2[i],1)); - /*dl_ch_mag*/ - dl_ch_mag128_i2[i] = _mm_adds_epi16(_mm_srai_epi16(dl_ch_mag128_i2[i],1),_mm_srai_epi16(dl_ch_mag128_i3[i],1)); - dl_ch_mag128_i0[i] = _mm_adds_epi16(_mm_srai_epi16(dl_ch_mag128_i0[i],1),_mm_srai_epi16(dl_ch_mag128_i2[i],1)); - /*dl_ch_mag*/ - dl_ch_mag128_i2b[i] = _mm_adds_epi16(_mm_srai_epi16(dl_ch_mag128_i2b[i],1),_mm_srai_epi16(dl_ch_mag128_i3b[i],1)); - dl_ch_mag128_i0b[i] = _mm_adds_epi16(_mm_srai_epi16(dl_ch_mag128_i0b[i],1),_mm_srai_epi16(dl_ch_mag128_i2b[i],1)); - /*rho*/ - rho128_i2[i] = _mm_adds_epi16(_mm_srai_epi16(rho128_i2[i],1),_mm_srai_epi16(rho128_i3[i],1)); - rho128_i0[i] = _mm_adds_epi16(_mm_srai_epi16(rho128_i0[i],1),_mm_srai_epi16(rho128_i2[i],1)); - } + if (dual_stream_UE == 1) { + __m128i *dl_ch_mag128_i0, *dl_ch_mag128_i1; + __m128i *dl_ch_mag128_i0b, *dl_ch_mag128_i1b; + __m128i *rho128_i0, *rho128_i1; + __m128i *rxdataF_comp128_i0, *rxdataF_comp128_i1; + rxdataF_comp128_i0 = (__m128i *)&rxdataF_comp1[0][symbol*frame_parms->N_RB_DL*12]; + rxdataF_comp128_i1 = (__m128i *)&rxdataF_comp1[1][symbol*frame_parms->N_RB_DL*12]; + dl_ch_mag128_i0 = (__m128i *)&dl_ch_mag1[0][symbol*frame_parms->N_RB_DL*12]; + dl_ch_mag128_i1 = (__m128i *)&dl_ch_mag1[1][symbol*frame_parms->N_RB_DL*12]; + dl_ch_mag128_i0b = (__m128i *)&dl_ch_magb1[0][symbol*frame_parms->N_RB_DL*12]; + dl_ch_mag128_i1b = (__m128i *)&dl_ch_magb1[1][symbol*frame_parms->N_RB_DL*12]; + rho128_i0 = (__m128i *) &dl_ch_rho_ext[0][symbol*frame_parms->N_RB_DL*12]; + rho128_i1 = (__m128i *) &dl_ch_rho_ext[1][symbol*frame_parms->N_RB_DL*12]; + + for (i=0; i<nb_rb*3; i++) { + rxdataF_comp128_i0[i] = _mm_adds_epi16(_mm_srai_epi16(rxdataF_comp128_i0[i],1),_mm_srai_epi16(rxdataF_comp128_i1[i],1)); + dl_ch_mag128_i0[i] = _mm_adds_epi16(_mm_srai_epi16(dl_ch_mag128_i0[i],1),_mm_srai_epi16(dl_ch_mag128_i1[i],1)); + dl_ch_mag128_i0b[i] = _mm_adds_epi16(_mm_srai_epi16(dl_ch_mag128_i0b[i],1),_mm_srai_epi16(dl_ch_mag128_i1b[i],1)); + rho128_i0[i] = _mm_adds_epi16(_mm_srai_epi16(rho128_i0[i],1),_mm_srai_epi16(rho128_i1[i],1)); + + if (frame_parms->nb_antennas_rx>2) { + __m128i *rxdataF_comp128_i2 = NULL; + __m128i *rxdataF_comp128_i3 = NULL; + __m128i *dl_ch_mag128_i2 = NULL; + __m128i *dl_ch_mag128_i3 = NULL; + __m128i *dl_ch_mag128_i2b = NULL; + __m128i *dl_ch_mag128_i3b = NULL; + __m128i *rho128_i2 = NULL; + __m128i *rho128_i3 = NULL; + rxdataF_comp128_i2 = (__m128i *)&rxdataF_comp1[2][symbol*frame_parms->N_RB_DL*12]; + rxdataF_comp128_i3 = (__m128i *)&rxdataF_comp1[3][symbol*frame_parms->N_RB_DL*12]; + dl_ch_mag128_i2 = (__m128i *)&dl_ch_mag1[2][symbol*frame_parms->N_RB_DL*12]; + dl_ch_mag128_i3 = (__m128i *)&dl_ch_mag1[3][symbol*frame_parms->N_RB_DL*12]; + dl_ch_mag128_i2b = (__m128i *)&dl_ch_magb1[2][symbol*frame_parms->N_RB_DL*12]; + dl_ch_mag128_i3b = (__m128i *)&dl_ch_magb1[3][symbol*frame_parms->N_RB_DL*12]; + rho128_i2 = (__m128i *) &dl_ch_rho_ext[2][symbol*frame_parms->N_RB_DL*12]; + rho128_i3 = (__m128i *) &dl_ch_rho_ext[3][symbol*frame_parms->N_RB_DL*12]; + /*rxdataF_comp*/ + rxdataF_comp128_i2[i] = _mm_adds_epi16(_mm_srai_epi16(rxdataF_comp128_i2[i],1),_mm_srai_epi16(rxdataF_comp128_i3[i],1)); + rxdataF_comp128_i0[i] = _mm_adds_epi16(_mm_srai_epi16(rxdataF_comp128_i0[i],1),_mm_srai_epi16(rxdataF_comp128_i2[i],1)); + /*dl_ch_mag*/ + dl_ch_mag128_i2[i] = _mm_adds_epi16(_mm_srai_epi16(dl_ch_mag128_i2[i],1),_mm_srai_epi16(dl_ch_mag128_i3[i],1)); + dl_ch_mag128_i0[i] = _mm_adds_epi16(_mm_srai_epi16(dl_ch_mag128_i0[i],1),_mm_srai_epi16(dl_ch_mag128_i2[i],1)); + /*dl_ch_mag*/ + dl_ch_mag128_i2b[i] = _mm_adds_epi16(_mm_srai_epi16(dl_ch_mag128_i2b[i],1),_mm_srai_epi16(dl_ch_mag128_i3b[i],1)); + dl_ch_mag128_i0b[i] = _mm_adds_epi16(_mm_srai_epi16(dl_ch_mag128_i0b[i],1),_mm_srai_epi16(dl_ch_mag128_i2b[i],1)); + /*rho*/ + rho128_i2[i] = _mm_adds_epi16(_mm_srai_epi16(rho128_i2[i],1),_mm_srai_epi16(rho128_i3[i],1)); + rho128_i0[i] = _mm_adds_epi16(_mm_srai_epi16(rho128_i0[i],1),_mm_srai_epi16(rho128_i2[i],1)); } } + } _mm_empty(); _m_empty(); @@ -3652,15 +3371,11 @@ void dlsch_scale_channel(int **dl_ch_estimates_ext, LTE_DL_FRAME_PARMS *frame_parms, LTE_UE_DLSCH_t **dlsch_ue, uint8_t symbol, - unsigned short nb_rb) -{ - + unsigned short nb_rb) { #if defined(__x86_64__)||defined(__i386__) - short rb, ch_amp; unsigned char aatx,aarx,pilots=0,symbol_mod; __m128i *dl_ch128, ch_amp128; - symbol_mod = (symbol>=(7-frame_parms->Ncp)) ? symbol-(7-frame_parms->Ncp) : symbol; if ((symbol_mod == 0) || (symbol_mod == (4-frame_parms->Ncp))) { @@ -3671,24 +3386,18 @@ void dlsch_scale_channel(int **dl_ch_estimates_ext, } // Determine scaling amplitude based the symbol - ch_amp = ((pilots) ? (dlsch_ue[0]->sqrt_rho_b) : (dlsch_ue[0]->sqrt_rho_a)); - LOG_D(PHY,"Scaling PDSCH Chest in OFDM symbol %d by %d, pilots %d nb_rb %d NCP %d symbol %d\n",symbol_mod,ch_amp,pilots,nb_rb,frame_parms->Ncp,symbol); - // printf("Scaling PDSCH Chest in OFDM symbol %d by %d\n",symbol_mod,ch_amp); - + // printf("Scaling PDSCH Chest in OFDM symbol %d by %d\n",symbol_mod,ch_amp); ch_amp128 = _mm_set1_epi16(ch_amp); // Q3.13 for (aatx=0; aatx<frame_parms->nb_antenna_ports_eNB; aatx++) { for (aarx=0; aarx<frame_parms->nb_antennas_rx; aarx++) { - dl_ch128=(__m128i *)&dl_ch_estimates_ext[(aatx<<1)+aarx][symbol*frame_parms->N_RB_DL*12]; - for (rb=0;rb<nb_rb;rb++) { - + for (rb=0; rb<nb_rb; rb++) { dl_ch128[0] = _mm_mulhi_epi16(dl_ch128[0],ch_amp128); dl_ch128[0] = _mm_slli_epi16(dl_ch128[0],3); - dl_ch128[1] = _mm_mulhi_epi16(dl_ch128[1],ch_amp128); dl_ch128[1] = _mm_slli_epi16(dl_ch128[1],3); @@ -3698,14 +3407,12 @@ void dlsch_scale_channel(int **dl_ch_estimates_ext, dl_ch128[2] = _mm_mulhi_epi16(dl_ch128[2],ch_amp128); dl_ch128[2] = _mm_slli_epi16(dl_ch128[2],3); dl_ch128+=3; - } } } } #elif defined(__arm__) - #endif } @@ -3714,16 +3421,12 @@ void dlsch_channel_level(int **dl_ch_estimates_ext, LTE_DL_FRAME_PARMS *frame_parms, int32_t *avg, uint8_t symbol, - unsigned short nb_rb) -{ - + unsigned short nb_rb) { #if defined(__x86_64__)||defined(__i386__) //printf("symbol = %d\n", symbol); - short rb; unsigned char aatx,aarx,nre=12,symbol_mod; __m128i *dl_ch128, avg128D; - symbol_mod = (symbol>=(7-frame_parms->Ncp)) ? symbol-(7-frame_parms->Ncp) : symbol; if (((symbol_mod == 0) || (symbol_mod == (frame_parms->Ncp-1)))&&(frame_parms->nb_antenna_ports_eNB!=1)) @@ -3739,17 +3442,13 @@ void dlsch_channel_level(int **dl_ch_estimates_ext, for (aatx=0; aatx<frame_parms->nb_antenna_ports_eNB; aatx++) for (aarx=0; aarx<frame_parms->nb_antennas_rx; aarx++) { - //clear average level + //clear average level //printf("aatx = %d, aarx = %d, aatx*frame_parms->nb_antennas_rx + aarx] = %d \n", aatx, aarx, aatx*frame_parms->nb_antennas_rx + aarx); - avg128D = _mm_setzero_si128(); // 5 is always a symbol with no pilots for both normal and extended prefix - - dl_ch128=(__m128i *)&dl_ch_estimates_ext[aatx*2 + aarx][symbol*frame_parms->N_RB_DL*12]; - for (rb=0;rb<nb_rb;rb++) { - + for (rb=0; rb<nb_rb; rb++) { //printf("rb %d : ",rb); avg128D = _mm_add_epi32(avg128D,_mm_srai_epi32(_mm_madd_epi16(dl_ch128[0],dl_ch128[0]),x)); avg128D = _mm_add_epi32(avg128D,_mm_srai_epi32(_mm_madd_epi16(dl_ch128[1],dl_ch128[1]),x)); @@ -3759,37 +3458,32 @@ void dlsch_channel_level(int **dl_ch_estimates_ext, if (((symbol_mod == 0) || (symbol_mod == (frame_parms->Ncp-1)))&&(frame_parms->nb_antenna_ports_eNB!=1)) { dl_ch128+=2; - } - else { - avg128D = _mm_add_epi32(avg128D,_mm_srai_epi32(_mm_madd_epi16(dl_ch128[2],dl_ch128[2]),x)); + } else { + avg128D = _mm_add_epi32(avg128D,_mm_srai_epi32(_mm_madd_epi16(dl_ch128[2],dl_ch128[2]),x)); //avg128D = _mm_add_epi32(avg128D,_mm_madd_epi16(dl_ch128[2],_mm_srai_epi16(_mm_mulhi_epi16(dl_ch128[2], coeff128),15))); dl_ch128+=3; } - /*if(rb==0){ - print_shorts("dl_ch128",&dl_ch128[0]); - print_shorts("dl_ch128",&dl_ch128[1]); - print_shorts("dl_ch128",&dl_ch128[2]); - }*/ - + /*if(rb==0){ + print_shorts("dl_ch128",&dl_ch128[0]); + print_shorts("dl_ch128",&dl_ch128[1]); + print_shorts("dl_ch128",&dl_ch128[2]); + }*/ } - avg[aatx*frame_parms->nb_antennas_rx + aarx] =(((int32_t*)&avg128D)[0] + - ((int32_t*)&avg128D)[1] + - ((int32_t*)&avg128D)[2] + - ((int32_t*)&avg128D)[3])/y; - } + avg[aatx*frame_parms->nb_antennas_rx + aarx] =(((int32_t *)&avg128D)[0] + + ((int32_t *)&avg128D)[1] + + ((int32_t *)&avg128D)[2] + + ((int32_t *)&avg128D)[3])/y; + } _mm_empty(); _m_empty(); - #elif defined(__arm__) - short rb; unsigned char aatx,aarx,nre=12,symbol_mod; int32x4_t avg128D; int16x4_t *dl_ch128; - symbol_mod = (symbol>=(7-frame_parms->Ncp)) ? symbol-(7-frame_parms->Ncp) : symbol; for (aatx=0; aatx<frame_parms->nb_antenna_ports_eNB; aatx++) @@ -3797,7 +3491,6 @@ void dlsch_channel_level(int **dl_ch_estimates_ext, //clear average level avg128D = vdupq_n_s32(0); // 5 is always a symbol with no pilots for both normal and extended prefix - dl_ch128=(int16x4_t *)&dl_ch_estimates_ext[aatx*frame_parms->nb_antennas_rx + aarx][symbol*frame_parms->N_RB_DL*12]; for (rb=0; rb<nb_rb; rb++) { @@ -3832,15 +3525,14 @@ void dlsch_channel_level(int **dl_ch_estimates_ext, else nre=12; - avg[aatx*frame_parms->nb_antennas_rx + aarx] = (((int32_t*)&avg128D)[0] + - ((int32_t*)&avg128D)[1] + - ((int32_t*)&avg128D)[2] + - ((int32_t*)&avg128D)[3])/(nb_rb*nre); - + avg[aatx*frame_parms->nb_antennas_rx + aarx] = (((int32_t *)&avg128D)[0] + + ((int32_t *)&avg128D)[1] + + ((int32_t *)&avg128D)[2] + + ((int32_t *)&avg128D)[3])/(nb_rb*nre); //printf("Channel level : %d\n",avg[aatx*(frame_parms->nb_antennas_rx-1) + aarx]); } -#endif +#endif } void dlsch_channel_level_core(int **dl_ch_estimates_ext, @@ -3848,63 +3540,50 @@ void dlsch_channel_level_core(int **dl_ch_estimates_ext, int n_tx, int n_rx, int length, - int start_point) -{ - + int start_point) { #if defined(__x86_64__)||defined(__i386__) - short ii; int aatx,aarx; int length_mod8; int length2; __m128i *dl_ch128, avg128D; - int16_t x = factor2(length); int16_t y = (length)>>x; for (aatx=0; aatx<n_tx; aatx++) for (aarx=0; aarx<n_rx; aarx++) { - avg128D = _mm_setzero_si128(); - dl_ch128=(__m128i *)&dl_ch_estimates_ext[aatx*2 + aarx][start_point]; - length_mod8=length&7; - if (length_mod8 == 0){ - + if (length_mod8 == 0) { length2 = length>>3; - for (ii=0;ii<length2;ii++) { + for (ii=0; ii<length2; ii++) { avg128D = _mm_add_epi32(avg128D,_mm_srai_epi32(_mm_madd_epi16(dl_ch128[0],dl_ch128[0]),x)); avg128D = _mm_add_epi32(avg128D,_mm_srai_epi32(_mm_madd_epi16(dl_ch128[1],dl_ch128[1]),x)); - dl_ch128+=2; } - }else { + } else { printf ("Channel level: Received number of subcarriers is not multiple of 4, \n" - "need to adapt the code!\n"); + "need to adapt the code!\n"); } - - avg[aatx*n_rx + aarx] =(((int32_t*)&avg128D)[0] + - ((int32_t*)&avg128D)[1] + - ((int32_t*)&avg128D)[2] + - ((int32_t*)&avg128D)[3])/y; + avg[aatx*n_rx + aarx] =(((int32_t *)&avg128D)[0] + + ((int32_t *)&avg128D)[1] + + ((int32_t *)&avg128D)[2] + + ((int32_t *)&avg128D)[3])/y; //printf("Channel level [%d]: %d\n",aatx*n_rx + aarx, avg[aatx*n_rx + aarx]); - } + } _mm_empty(); _m_empty(); - - /* FIXME This part needs to be adapted like the one above */ + /* FIXME This part needs to be adapted like the one above */ #elif defined(__arm__) - short rb; unsigned char aatx,aarx,nre=12,symbol_mod; int32x4_t avg128D; int16x4_t *dl_ch128; - symbol_mod = (symbol>=(7-frame_parms->Ncp)) ? symbol-(7-frame_parms->Ncp) : symbol; for (aatx=0; aatx<frame_parms->nb_antenna_ports_eNB; aatx++) @@ -3912,7 +3591,6 @@ void dlsch_channel_level_core(int **dl_ch_estimates_ext, //clear average level avg128D = vdupq_n_s32(0); // 5 is always a symbol with no pilots for both normal and extended prefix - dl_ch128=(int16x4_t *)&dl_ch_estimates_ext[aatx*frame_parms->nb_antennas_rx + aarx][symbol*frame_parms->N_RB_DL*12]; for (rb=0; rb<nb_rb; rb++) { @@ -3932,7 +3610,6 @@ void dlsch_channel_level_core(int **dl_ch_estimates_ext, } } - if (((symbol_mod == 0) || (symbol_mod == (frame_parms->Ncp-1)))&&(frame_parms->nb_antenna_ports_eNB!=1)) nre=8; else if (((symbol_mod == 0) || (symbol_mod == (frame_parms->Ncp-1)))&&(frame_parms->nb_antenna_ports_eNB==1)) @@ -3940,15 +3617,14 @@ void dlsch_channel_level_core(int **dl_ch_estimates_ext, else nre=12; - avg[aatx*frame_parms->nb_antennas_rx + aarx] = (((int32_t*)&avg128D)[0] + - ((int32_t*)&avg128D)[1] + - ((int32_t*)&avg128D)[2] + - ((int32_t*)&avg128D)[3])/(nb_rb*nre); - + avg[aatx*frame_parms->nb_antennas_rx + aarx] = (((int32_t *)&avg128D)[0] + + ((int32_t *)&avg128D)[1] + + ((int32_t *)&avg128D)[2] + + ((int32_t *)&avg128D)[3])/(nb_rb*nre); //printf("Channel level : %d\n",avg[aatx*(frame_parms->nb_antennas_rx-1) + aarx]); } -#endif +#endif } void dlsch_channel_level_median(int **dl_ch_estimates_ext, @@ -3956,11 +3632,8 @@ void dlsch_channel_level_median(int **dl_ch_estimates_ext, int n_tx, int n_rx, int length, - int start_point) -{ - + int start_point) { #if defined(__x86_64__)||defined(__i386__) - short ii; int aatx,aarx; int length2; @@ -3968,101 +3641,92 @@ void dlsch_channel_level_median(int **dl_ch_estimates_ext, int norm_pack; __m128i *dl_ch128, norm128D; - for (aatx=0; aatx<n_tx; aatx++){ + for (aatx=0; aatx<n_tx; aatx++) { for (aarx=0; aarx<n_rx; aarx++) { max = 0; min = 0; norm128D = _mm_setzero_si128(); - dl_ch128=(__m128i *)&dl_ch_estimates_ext[aatx*2 + aarx][start_point]; - length2 = length>>2; - for (ii=0;ii<length2;ii++) { + for (ii=0; ii<length2; ii++) { norm128D = _mm_srai_epi32( _mm_madd_epi16(dl_ch128[0],dl_ch128[0]), 1); - //print_ints("norm128D",&norm128D[0]); - - norm_pack = ((int32_t*)&norm128D)[0] + - ((int32_t*)&norm128D)[1] + - ((int32_t*)&norm128D)[2] + - ((int32_t*)&norm128D)[3]; + //print_ints("norm128D",&norm128D[0]); + norm_pack = ((int32_t *)&norm128D)[0] + + ((int32_t *)&norm128D)[1] + + ((int32_t *)&norm128D)[2] + + ((int32_t *)&norm128D)[3]; if (norm_pack > max) max = norm_pack; + if (norm_pack < min) min = norm_pack; dl_ch128+=1; } - median[aatx*n_rx + aarx] = (max+min)>>1; - - // printf("Channel level median [%d]: %d\n",aatx*n_rx + aarx, median[aatx*n_rx + aarx]); - } + median[aatx*n_rx + aarx] = (max+min)>>1; + // printf("Channel level median [%d]: %d\n",aatx*n_rx + aarx, median[aatx*n_rx + aarx]); } + } _mm_empty(); _m_empty(); - #elif defined(__arm__) - short rb; unsigned char aatx,aarx,nre=12,symbol_mod; int32x4_t norm128D; int16x4_t *dl_ch128; - for (aatx=0; aatx<frame_parms->nb_antenna_ports_eNB; aatx++){ + for (aatx=0; aatx<frame_parms->nb_antenna_ports_eNB; aatx++) { for (aarx=0; aarx<frame_parms->nb_antennas_rx; aarx++) { max = 0; min = 0; norm128D = vdupq_n_s32(0); - dl_ch128=(int16x4_t *)&dl_ch_estimates_ext[aatx*n_rx + aarx][start_point]; - length_mod8=length&3; length2 = length>>2; - for (ii=0;ii<length2;ii++) { + for (ii=0; ii<length2; ii++) { norm128D = vshrq_n_u32(vmull_s16(dl_ch128[0],dl_ch128[0]), 1); - norm_pack = ((int32_t*)&norm128D)[0] + - ((int32_t*)&norm128D)[1] + - ((int32_t*)&norm128D)[2] + - ((int32_t*)&norm128D)[3]; + norm_pack = ((int32_t *)&norm128D)[0] + + ((int32_t *)&norm128D)[1] + + ((int32_t *)&norm128D)[2] + + ((int32_t *)&norm128D)[3]; if (norm_pack > max) max = norm_pack; + if (norm_pack < min) min = norm_pack; - dl_ch128+=1; + dl_ch128+=1; } - median[aatx*n_rx + aarx] = (max+min)>>1; - + median[aatx*n_rx + aarx] = (max+min)>>1; //printf("Channel level median [%d]: %d\n",aatx*n_rx + aarx, median[aatx*n_rx + aarx]); - } } -#endif + } +#endif } void mmse_processing_oai(LTE_UE_PDSCH *pdsch_vars, - LTE_DL_FRAME_PARMS *frame_parms, - PHY_MEASUREMENTS *measurements, - unsigned char first_symbol_flag, - MIMO_mode_t mimo_mode, - unsigned short mmse_flag, - int noise_power, - unsigned char symbol, - unsigned short nb_rb){ - + LTE_DL_FRAME_PARMS *frame_parms, + PHY_MEASUREMENTS *measurements, + unsigned char first_symbol_flag, + MIMO_mode_t mimo_mode, + unsigned short mmse_flag, + int noise_power, + unsigned char symbol, + unsigned short nb_rb) { int **rxdataF_ext = pdsch_vars->rxdataF_ext; int **dl_ch_estimates_ext = pdsch_vars->dl_ch_estimates_ext; unsigned char *pmi_ext = pdsch_vars->pmi_ext; int avg_00[frame_parms->nb_antenna_ports_eNB*frame_parms->nb_antennas_rx]; int avg_01[frame_parms->nb_antenna_ports_eNB*frame_parms->nb_antennas_rx]; int symbol_mod, length, start_point, nre; - symbol_mod = (symbol>=(7-frame_parms->Ncp)) ? symbol-(7-frame_parms->Ncp) : symbol; if (((symbol_mod == 0) || (symbol_mod == (frame_parms->Ncp-1)))&&(frame_parms->nb_antenna_ports_eNB!=1)) @@ -4074,8 +3738,6 @@ void mmse_processing_oai(LTE_UE_PDSCH *pdsch_vars, length = nre*nb_rb; start_point = symbol*nb_rb*12; - - mmse_processing_core(rxdataF_ext, dl_ch_estimates_ext, noise_power, @@ -4084,7 +3746,6 @@ void mmse_processing_oai(LTE_UE_PDSCH *pdsch_vars, length, start_point); - /*dlsch_channel_aver_band(dl_ch_estimates_ext, frame_parms, chan_avg, @@ -4098,21 +3759,20 @@ void mmse_processing_oai(LTE_UE_PDSCH *pdsch_vars, // printf("H [%d] = (%f, %f) \n", aatx*frame_parms->nb_antennas_rx + aarx, creal(H[aatx*frame_parms->nb_antennas_rx + aarx]), cimag(H[aatx*frame_parms->nb_antennas_rx + aarx])); }*/ - if (first_symbol_flag == 1){ - dlsch_channel_level_TM34(dl_ch_estimates_ext, - frame_parms, - pmi_ext, - avg_00, - avg_01, - symbol, - nb_rb, - mmse_flag, - mimo_mode); - - avg_00[0] = (log2_approx(avg_00[0])/2) + dlsch_demod_shift+4;// + 2 ;//+ 4; - avg_01[0] = (log2_approx(avg_01[0])/2) + dlsch_demod_shift+4;// + 2 ;//+ 4; - pdsch_vars->log2_maxh0 = cmax(avg_00[0],0); - pdsch_vars->log2_maxh1 = cmax(avg_01[0],0); + if (first_symbol_flag == 1) { + dlsch_channel_level_TM34(dl_ch_estimates_ext, + frame_parms, + pmi_ext, + avg_00, + avg_01, + symbol, + nb_rb, + mmse_flag, + mimo_mode); + avg_00[0] = (log2_approx(avg_00[0])/2) + dlsch_demod_shift+4;// + 2 ;//+ 4; + avg_01[0] = (log2_approx(avg_01[0])/2) + dlsch_demod_shift+4;// + 2 ;//+ 4; + pdsch_vars->log2_maxh0 = cmax(avg_00[0],0); + pdsch_vars->log2_maxh1 = cmax(avg_01[0],0); } } @@ -4122,27 +3782,26 @@ void mmse_processing_core(int32_t **rxdataF_ext, int n_tx, int n_rx, int length, - int start_point){ - + int start_point) { int aatx, aarx, re; float imag; float real; + float complex **W_MMSE= malloc(n_tx*n_rx*sizeof(float complex *)); - - float complex **W_MMSE= malloc(n_tx*n_rx*sizeof(float complex*)); - for (int j=0; j<n_tx*n_rx; j++) { - W_MMSE[j] = malloc(sizeof(float complex)*length); + for (int j=0; j<n_tx*n_rx; j++) { + W_MMSE[j] = malloc(sizeof(float complex)*length); } float complex *H= malloc(n_tx*n_rx*sizeof(float complex)); float complex *W_MMSE_re= malloc(n_tx*n_rx*sizeof(float complex)); + float complex **dl_ch_estimates_ext_flcpx = malloc(n_tx*n_rx*sizeof(float complex *)); - float complex** dl_ch_estimates_ext_flcpx = malloc(n_tx*n_rx*sizeof(float complex*)); for (int j=0; j<n_tx*n_rx; j++) { dl_ch_estimates_ext_flcpx[j] = malloc(sizeof(float complex)*length); } - float complex** rxdataF_ext_flcpx = malloc(n_rx*sizeof(float complex*)); + float complex **rxdataF_ext_flcpx = malloc(n_rx*sizeof(float complex *)); + for (int j=0; j<n_rx; j++) { rxdataF_ext_flcpx[j] = malloc(sizeof(float complex)*length); } @@ -4154,16 +3813,18 @@ void mmse_processing_core(int32_t **rxdataF_ext, length, start_point); - for (re=0; re<length; re++){ - for (aatx=0; aatx<n_tx; aatx++){ + for (re=0; re<length; re++) { + for (aatx=0; aatx<n_tx; aatx++) { for (aarx=0; aarx<n_rx; aarx++) { imag = cimag(dl_ch_estimates_ext_flcpx[aatx*n_rx + aarx][re]); real = creal(dl_ch_estimates_ext_flcpx[aatx*n_rx + aarx][re]); H[aatx*n_rx + aarx] = real+ I*imag; } } + compute_MMSE(H, n_tx, noise_power, W_MMSE_re); - for (aatx=0; aatx<n_tx; aatx++){ + + for (aatx=0; aatx<n_tx; aatx++) { for (aarx=0; aarx<n_rx; aarx++) { W_MMSE[aatx*n_rx + aarx][re] = W_MMSE_re[aatx*n_rx + aarx]; } @@ -4175,49 +3836,40 @@ void mmse_processing_core(int32_t **rxdataF_ext, n_rx, length, start_point); - mult_mmse_rxdataF(W_MMSE, rxdataF_ext_flcpx, n_tx, n_rx, length, start_point); - - mult_mmse_chan_est(W_MMSE, dl_ch_estimates_ext_flcpx, n_tx, n_rx, length, start_point); - - float_to_rxdataF(rxdataF_ext, rxdataF_ext_flcpx, n_tx, n_rx, length, start_point); - - float_to_chan_est(dl_ch_estimates_ext, dl_ch_estimates_ext_flcpx, n_tx, n_rx, length, start_point); - -free(W_MMSE); -free(H); -free(W_MMSE_re); -free(dl_ch_estimates_ext_flcpx); -free(rxdataF_ext_flcpx); - + free(W_MMSE); + free(H); + free(W_MMSE_re); + free(dl_ch_estimates_ext_flcpx); + free(rxdataF_ext_flcpx); } /*THIS FUNCTION TAKES FLOAT_POINT INPUT. SHOULD NOT BE USED WITH OAI*/ -void mmse_processing_core_flp(float complex** rxdataF_ext_flcpx, +void mmse_processing_core_flp(float complex **rxdataF_ext_flcpx, float complex **H, int32_t **rxdataF_ext, int32_t **dl_ch_estimates_ext, @@ -4225,79 +3877,85 @@ void mmse_processing_core_flp(float complex** rxdataF_ext_flcpx, int n_tx, int n_rx, int length, - int start_point){ - + int start_point) { int aatx, aarx, re; float max = 0; float one_over_max = 0; + float complex **W_MMSE= malloc(n_tx*n_rx*sizeof(float complex *)); - float complex **W_MMSE= malloc(n_tx*n_rx*sizeof(float complex*)); - for (int j=0; j<n_tx*n_rx; j++) { - W_MMSE[j] = malloc(sizeof(float complex)*length); + for (int j=0; j<n_tx*n_rx; j++) { + W_MMSE[j] = malloc(sizeof(float complex)*length); } float complex *H_re= malloc(n_tx*n_rx*sizeof(float complex)); float complex *W_MMSE_re= malloc(n_tx*n_rx*sizeof(float complex)); - for (re=0; re<length; re++){ - for (aatx=0; aatx<n_tx; aatx++){ + for (re=0; re<length; re++) { + for (aatx=0; aatx<n_tx; aatx++) { for (aarx=0; aarx<n_rx; aarx++) { H_re[aatx*n_rx + aarx] = H[aatx*n_rx + aarx][re]; #ifdef DEBUG_MMSE + if (re == 0) - printf(" H_re[%d]= (%f + i%f)\n", aatx*n_rx + aarx, creal(H_re[aatx*n_rx + aarx]), cimag(H_re[aatx*n_rx + aarx])); + printf(" H_re[%d]= (%f + i%f)\n", aatx*n_rx + aarx, creal(H_re[aatx*n_rx + aarx]), cimag(H_re[aatx*n_rx + aarx])); + #endif } } + compute_MMSE(H_re, n_tx, noise_power, W_MMSE_re); - for (aatx=0; aatx<n_tx; aatx++){ + + for (aatx=0; aatx<n_tx; aatx++) { for (aarx=0; aarx<n_rx; aarx++) { W_MMSE[aatx*n_rx + aarx][re] = W_MMSE_re[aatx*n_rx + aarx]; + if (fabs(creal(W_MMSE_re[aatx*n_rx + aarx])) > max) max = fabs(creal(W_MMSE_re[aatx*n_rx + aarx])); + if (fabs(cimag(W_MMSE_re[aatx*n_rx + aarx])) > max) max = fabs(cimag(W_MMSE_re[aatx*n_rx + aarx])); } } } + one_over_max = 1.0/max; for (re=0; re<length; re++) for (aatx=0; aatx<n_tx; aatx++) - for (aarx=0; aarx<n_rx; aarx++){ + for (aarx=0; aarx<n_rx; aarx++) { #ifdef DEBUG_MMSE + if (re == 0) printf(" W_MMSE[%d] = (%f + i%f)\n", aatx*n_rx + aarx, creal(W_MMSE[aatx*n_rx + aarx][re]), cimag(W_MMSE[aatx*n_rx + aarx][re])); + #endif W_MMSE[aatx*n_rx + aarx][re] = one_over_max*W_MMSE[aatx*n_rx + aarx][re]; #ifdef DEBUG_MMSE + if (re == 0) printf(" AFTER NORM W_MMSE[%d] = (%f + i%f), max = %f \n", aatx*n_rx + aarx, creal(W_MMSE[aatx*n_rx + aarx][re]), cimag(W_MMSE[aatx*n_rx + aarx][re]), max); + #endif } - mult_mmse_rxdataF(W_MMSE, rxdataF_ext_flcpx, n_tx, n_rx, length, start_point); - mult_mmse_chan_est(W_MMSE, H, n_tx, n_rx, length, start_point); - float_to_rxdataF(rxdataF_ext, rxdataF_ext_flcpx, n_tx, n_rx, length, start_point); - float_to_chan_est(dl_ch_estimates_ext, H, n_tx, @@ -4307,7 +3965,6 @@ void mmse_processing_core_flp(float complex** rxdataF_ext_flcpx, free(H_re); free(W_MMSE); free(W_MMSE_re); - } @@ -4315,16 +3972,12 @@ void dlsch_channel_aver_band(int **dl_ch_estimates_ext, LTE_DL_FRAME_PARMS *frame_parms, struct complex32 *chan_avg, unsigned char symbol, - unsigned short nb_rb) -{ - + unsigned short nb_rb) { #if defined(__x86_64__)||defined(__i386__) - short rb; unsigned char aatx,aarx,nre=12,symbol_mod; __m128i *dl_ch128, avg128D; int32_t chan_est_avg[4]; - symbol_mod = (symbol>=(7-frame_parms->Ncp)) ? symbol-(7-frame_parms->Ncp) : symbol; if (((symbol_mod == 0) || (symbol_mod == (frame_parms->Ncp-1)))&&(frame_parms->nb_antenna_ports_eNB!=1)) @@ -4334,97 +3987,89 @@ void dlsch_channel_aver_band(int **dl_ch_estimates_ext, else nre=12; - for (aatx=0; aatx<frame_parms->nb_antenna_ports_eNB; aatx++){ + for (aatx=0; aatx<frame_parms->nb_antenna_ports_eNB; aatx++) { for (aarx=0; aarx<frame_parms->nb_antennas_rx; aarx++) { dl_ch128=(__m128i *)&dl_ch_estimates_ext[aatx*frame_parms->nb_antennas_rx + aarx][symbol*frame_parms->N_RB_DL*12]; avg128D = _mm_setzero_si128(); - // print_shorts("avg128D 1",&avg128D); + // print_shorts("avg128D 1",&avg128D); - for (rb=0;rb<nb_rb;rb++) { + for (rb=0; rb<nb_rb; rb++) { /* printf("symbol %d, ant %d, nre*nrb %d, rb %d \n", symbol, aatx*frame_parms->nb_antennas_rx + aarx, nb_rb*nre, rb); print_shorts("aver dl_ch128",&dl_ch128[0]); print_shorts("aver dl_ch128",&dl_ch128[1]); print_shorts("aver dl_ch128",&dl_ch128[2]); avg128D = _mm_add_epi16(avg128D, dl_ch128[0]);*/ //print_shorts("avg128D 2",&avg128D); - avg128D = _mm_add_epi16(avg128D, dl_ch128[1]); - // print_shorts("avg128D 3",&avg128D); + // print_shorts("avg128D 3",&avg128D); if (((symbol_mod == 0) || (symbol_mod == (frame_parms->Ncp-1)))&&(frame_parms->nb_antenna_ports_eNB!=1)) { dl_ch128+=2; - }else { + } else { avg128D = _mm_add_epi16(avg128D,dl_ch128[2]); - // print_shorts("avg128D 4",&avg128D); + // print_shorts("avg128D 4",&avg128D); dl_ch128+=3; } } - chan_avg[aatx*frame_parms->nb_antennas_rx + aarx].r =(((int16_t*)&avg128D)[0] + - ((int16_t*)&avg128D)[2] + - ((int16_t*)&avg128D)[4] + - ((int16_t*)&avg128D)[6])/(nb_rb*nre); - // printf("symb %d chan_avg re [%d] = %d\n", symbol, aatx*frame_parms->nb_antennas_rx + aarx, chan_avg[aatx*frame_parms->nb_antennas_rx + aarx].r); - - - - chan_avg[aatx*frame_parms->nb_antennas_rx + aarx].i =(((int16_t*)&avg128D)[1] + - ((int16_t*)&avg128D)[3] + - ((int16_t*)&avg128D)[5] + - ((int16_t*)&avg128D)[7])/(nb_rb*nre); - // printf("symb %d chan_avg im [%d] = %d\n", symbol, aatx*frame_parms->nb_antennas_rx + aarx, chan_avg[aatx*frame_parms->nb_antennas_rx + aarx].i); - + chan_avg[aatx*frame_parms->nb_antennas_rx + aarx].r =(((int16_t *)&avg128D)[0] + + ((int16_t *)&avg128D)[2] + + ((int16_t *)&avg128D)[4] + + ((int16_t *)&avg128D)[6])/(nb_rb*nre); + // printf("symb %d chan_avg re [%d] = %d\n", symbol, aatx*frame_parms->nb_antennas_rx + aarx, chan_avg[aatx*frame_parms->nb_antennas_rx + aarx].r); + chan_avg[aatx*frame_parms->nb_antennas_rx + aarx].i =(((int16_t *)&avg128D)[1] + + ((int16_t *)&avg128D)[3] + + ((int16_t *)&avg128D)[5] + + ((int16_t *)&avg128D)[7])/(nb_rb*nre); + // printf("symb %d chan_avg im [%d] = %d\n", symbol, aatx*frame_parms->nb_antennas_rx + aarx, chan_avg[aatx*frame_parms->nb_antennas_rx + aarx].i); //printf("symb %d chan_avg im [%d] = %d\n", symbol, aatx*frame_parms->nb_antennas_rx + aarx, chan_avg[aatx*frame_parms->nb_antennas_rx + aarx].i); - - chan_est_avg[aatx*frame_parms->nb_antennas_rx + aarx] = (((int32_t)chan_avg[aatx*frame_parms->nb_antennas_rx + aarx].i)<<16)|(((int32_t)chan_avg[aatx*frame_parms->nb_antennas_rx + aarx].r) & 0xffff); - //printf("symb %d chan_est_avg [%d] = %d\n", symbol, aatx*frame_parms->nb_antennas_rx + aarx, chan_est_avg[aatx*frame_parms->nb_antennas_rx + aarx]); - dl_ch128=(__m128i *)&dl_ch_estimates_ext[aatx*frame_parms->nb_antennas_rx + aarx][symbol*frame_parms->N_RB_DL*12]; - for (rb=0;rb<nb_rb;rb++) { + for (rb=0; rb<nb_rb; rb++) { dl_ch128[0] = _mm_set1_epi32(chan_est_avg[aatx*frame_parms->nb_antennas_rx + aarx]); dl_ch128[1] = _mm_set1_epi32(chan_est_avg[aatx*frame_parms->nb_antennas_rx + aarx]); + if (((symbol_mod == 0) || (symbol_mod == (frame_parms->Ncp-1)))&&(frame_parms->nb_antenna_ports_eNB!=1)) { dl_ch128+=2; - }else { - dl_ch128[2] = _mm_set1_epi32(chan_est_avg[aatx*frame_parms->nb_antennas_rx + aarx]); + } else { + dl_ch128[2] = _mm_set1_epi32(chan_est_avg[aatx*frame_parms->nb_antennas_rx + aarx]); dl_ch128+=3; } - } - } - } - - _mm_empty(); - _m_empty(); + } + } + } + _mm_empty(); + _m_empty(); #elif defined(__arm__) #endif - } +} void rxdataF_to_float(int32_t **rxdataF_ext, float complex **rxdataF_f, int n_rx, int length, - int start_point) -{ + int start_point) { short re; int aarx; int16_t imag; int16_t real; for (aarx=0; aarx<n_rx; aarx++) { - for (re=0; re<length; re++){ + for (re=0; re<length; re++) { imag = (int16_t) (rxdataF_ext[aarx][start_point + re] >> 16); real = (int16_t) (rxdataF_ext[aarx][start_point + re] & 0xffff); rxdataF_f[aarx][re] = (float)(real/(32768.0)) + I*(float)(imag/(32768.0)); #ifdef DEBUG_MMSE - if (re==0){ - printf("rxdataF_to_float: aarx = %d, real= %d, imag = %d\n", aarx, real, imag); - //printf("rxdataF_to_float: rxdataF_ext[%d][%d] = %d\n", aarx, start_point + re, rxdataF_ext[aarx][start_point + re]); - //printf("rxdataF_to_float: ant %d, re = %d, rxdataF_f real = %f, rxdataF_f imag = %f \n", aarx, re, creal(rxdataF_f[aarx][re]), cimag(rxdataF_f[aarx][re])); - } + + if (re==0) { + printf("rxdataF_to_float: aarx = %d, real= %d, imag = %d\n", aarx, real, imag); + //printf("rxdataF_to_float: rxdataF_ext[%d][%d] = %d\n", aarx, start_point + re, rxdataF_ext[aarx][start_point + re]); + //printf("rxdataF_to_float: ant %d, re = %d, rxdataF_f real = %f, rxdataF_f imag = %f \n", aarx, re, creal(rxdataF_f[aarx][re]), cimag(rxdataF_f[aarx][re])); + } + #endif } } @@ -4437,66 +4082,68 @@ void chan_est_to_float(int32_t **dl_ch_estimates_ext, int n_tx, int n_rx, int length, - int start_point) -{ + int start_point) { short re; int aatx,aarx; int16_t imag; int16_t real; - for (aatx=0; aatx<n_tx; aatx++){ + for (aatx=0; aatx<n_tx; aatx++) { for (aarx=0; aarx<n_rx; aarx++) { - for (re=0; re<length; re++){ + for (re=0; re<length; re++) { imag = (int16_t) (dl_ch_estimates_ext[aatx*n_rx + aarx][start_point + re] >> 16); real = (int16_t) (dl_ch_estimates_ext[aatx*n_rx + aarx][start_point+ re] & 0xffff); dl_ch_estimates_ext_f[aatx*n_rx + aarx][re] = (float)(real/(32768.0)) + I*(float)(imag/(32768.0)); #ifdef DEBUG_MMSE - if (re==0){ + + if (re==0) { printf("ant %d, re = %d, real = %d, imag = %d \n", aatx*n_rx + aarx, re, real, imag); printf("ant %d, re = %d, real = %f, imag = %f \n", aatx*n_rx + aarx, re, creal(dl_ch_estimates_ext_f[aatx*n_rx + aarx][re]), cimag(dl_ch_estimates_ext_f[aatx*n_rx + aarx][re])); } + #endif - } + } } } } void float_to_chan_est(int32_t **dl_ch_estimates_ext, - float complex **dl_ch_estimates_ext_f, - int n_tx, - int n_rx, - int length, - int start_point) -{ - + float complex **dl_ch_estimates_ext_f, + int n_tx, + int n_rx, + int length, + int start_point) { short re; int aarx, aatx; int16_t imag; int16_t real; - for (aatx=0; aatx<n_tx; aatx++){ + for (aatx=0; aatx<n_tx; aatx++) { for (aarx=0; aarx<n_rx; aarx++) { - for (re=0; re<length; re++){ + for (re=0; re<length; re++) { if (cimag(dl_ch_estimates_ext_f[aatx*n_rx + aarx][re])<-1) - imag = 0x8000; - else if (cimag(dl_ch_estimates_ext_f[aatx*n_rx + aarx][re])>=1) - imag = 0x7FFF; - else + imag = 0x8000; + else if (cimag(dl_ch_estimates_ext_f[aatx*n_rx + aarx][re])>=1) + imag = 0x7FFF; + else imag = cimag(dl_ch_estimates_ext_f[aatx*n_rx + aarx][re])*32768; - if (creal(dl_ch_estimates_ext_f[aatx*n_rx + aarx][re])<-1) - real = 0x8000; - else if (creal(dl_ch_estimates_ext_f[aatx*n_rx + aarx][re])>=1) - real = 0x7FFF; - else - real = creal(dl_ch_estimates_ext_f[aatx*n_rx + aarx][re])*32768; - - dl_ch_estimates_ext[aatx*n_rx + aarx][start_point + re] = (((int32_t)imag)<<16)|((int32_t)real & 0xffff); + + if (creal(dl_ch_estimates_ext_f[aatx*n_rx + aarx][re])<-1) + real = 0x8000; + else if (creal(dl_ch_estimates_ext_f[aatx*n_rx + aarx][re])>=1) + real = 0x7FFF; + else + real = creal(dl_ch_estimates_ext_f[aatx*n_rx + aarx][re])*32768; + + dl_ch_estimates_ext[aatx*n_rx + aarx][start_point + re] = (((int32_t)imag)<<16)|((int32_t)real & 0xffff); #ifdef DEBUG_MMSE - if (re==0){ + + if (re==0) { printf(" float_to_chan_est: chan est real = %f, chan est imag = %f\n",creal(dl_ch_estimates_ext_f[aatx*n_rx + aarx][re]), cimag(dl_ch_estimates_ext_f[aatx*n_rx + aarx][re])); printf("float_to_chan_est: real fixed = %d, imag fixed = %d\n", real, imag); printf("float_to_chan_est: ant %d, re = %d, dl_ch_estimates_ext = %d \n", aatx*n_rx + aarx, re, dl_ch_estimates_ext[aatx*n_rx + aarx][start_point + re]); } + #endif } } @@ -4509,76 +4156,81 @@ void float_to_rxdataF(int32_t **rxdataF_ext, int n_tx, int n_rx, int length, - int start_point) -{ - + int start_point) { short re; int aarx; int16_t imag; int16_t real; for (aarx=0; aarx<n_rx; aarx++) { - for (re=0; re<length; re++){ + for (re=0; re<length; re++) { if (cimag(rxdataF_f[aarx][re])<-1) imag = 0x8000; else if (cimag(rxdataF_f[aarx][re])>=1) imag = 0x7FFF; else imag = cimag(rxdataF_f[aarx][re])*32768; + if (creal(rxdataF_f[aarx][re])<-1) real = 0x8000; else if (creal(rxdataF_f[aarx][re])>=1) real = 0x7FFF; else real = creal(rxdataF_f[aarx][re])*32768; + rxdataF_ext[aarx][start_point + re] = (((int32_t)imag)<<16)|(((int32_t)real) & 0xffff); #ifdef DEBUG_MMSE - if (re==0){ - printf(" float_to_rxdataF: real = %f, imag = %f\n",creal(rxdataF_f[aarx][re]), cimag(rxdataF_f[aarx][re])); - printf("float_to_rxdataF: real fixed = %d, imag fixed = %d\n", real, imag); - printf("float_to_rxdataF: ant %d, re = %d, rxdataF_ext = %d \n", aarx, re, rxdataF_ext[aarx][start_point + re]); - } -#endif + + if (re==0) { + printf(" float_to_rxdataF: real = %f, imag = %f\n",creal(rxdataF_f[aarx][re]), cimag(rxdataF_f[aarx][re])); + printf("float_to_rxdataF: real fixed = %d, imag fixed = %d\n", real, imag); + printf("float_to_rxdataF: ant %d, re = %d, rxdataF_ext = %d \n", aarx, re, rxdataF_ext[aarx][start_point + re]); } + +#endif } + } } -void mult_mmse_rxdataF(float complex** Wmmse, - float complex** rxdataF_ext_f, +void mult_mmse_rxdataF(float complex **Wmmse, + float complex **rxdataF_ext_f, int n_tx, int n_rx, int length, - int start_point) -{ + int start_point) { short re; int aarx, aatx; + float complex *rxdata_re = malloc(n_rx*sizeof(float complex)); + float complex *rxdata_mmse_re = malloc(n_rx*sizeof(float complex)); + float complex *Wmmse_re = malloc(n_tx*n_rx*sizeof(float complex)); - - float complex* rxdata_re = malloc(n_rx*sizeof(float complex)); - float complex* rxdata_mmse_re = malloc(n_rx*sizeof(float complex)); - float complex* Wmmse_re = malloc(n_tx*n_rx*sizeof(float complex)); - - for (re=0;re<length; re++){ - for (aarx=0; aarx<n_rx; aarx++){ + for (re=0; re<length; re++) { + for (aarx=0; aarx<n_rx; aarx++) { rxdata_re[aarx] = rxdataF_ext_f[aarx][re]; #ifdef DEBUG_MMSE + if (re==0) printf("mult_mmse_rxdataF before: rxdata_re[%d] = (%f, %f)\n", aarx, creal(rxdata_re[aarx]), cimag(rxdata_re[aarx])); + #endif - } - for (aatx=0; aatx<n_tx; aatx++){ - for (aarx=0; aarx<n_rx; aarx++){ + } + + for (aatx=0; aatx<n_tx; aatx++) { + for (aarx=0; aarx<n_rx; aarx++) { Wmmse_re[aatx*n_rx + aarx] = Wmmse[aatx*n_rx + aarx][re]; } } + mutl_matrix_matrix_col_based(Wmmse_re, rxdata_re, n_rx, n_tx, n_rx, 1, rxdata_mmse_re); - for (aarx=0; aarx<n_rx; aarx++){ + for (aarx=0; aarx<n_rx; aarx++) { rxdataF_ext_f[aarx][re] = rxdata_mmse_re[aarx]; #ifdef DEBUG_MMSE - if (re==0) + + if (re==0) printf("mult_mmse_rxdataF after: rxdataF_ext_f[%d] = (%f, %f)\n", aarx, creal(rxdataF_ext_f[aarx][re]), cimag(rxdataF_ext_f[aarx][re])); + #endif } } @@ -4588,45 +4240,50 @@ void mult_mmse_rxdataF(float complex** Wmmse, free(Wmmse_re); } -void mult_mmse_chan_est(float complex** Wmmse, - float complex** dl_ch_estimates_ext_f, +void mult_mmse_chan_est(float complex **Wmmse, + float complex **dl_ch_estimates_ext_f, int n_tx, int n_rx, int length, - int start_point) -{ + int start_point) { short re; int aarx, aatx; + float complex *chan_est_re = malloc(n_tx*n_rx*sizeof(float complex)); + float complex *chan_est_mmse_re = malloc(n_tx*n_rx*sizeof(float complex)); + float complex *Wmmse_re = malloc(n_tx*n_rx*sizeof(float complex)); - float complex* chan_est_re = malloc(n_tx*n_rx*sizeof(float complex)); - float complex* chan_est_mmse_re = malloc(n_tx*n_rx*sizeof(float complex)); - float complex* Wmmse_re = malloc(n_tx*n_rx*sizeof(float complex)); - - for (re=0;re<length; re++){ - for (aatx=0; aatx<n_tx; aatx++){ - for (aarx=0; aarx<n_rx; aarx++){ + for (re=0; re<length; re++) { + for (aatx=0; aatx<n_tx; aatx++) { + for (aarx=0; aarx<n_rx; aarx++) { chan_est_re[aatx*n_rx + aarx] = dl_ch_estimates_ext_f[aatx*n_rx + aarx][re]; Wmmse_re[aatx*n_rx + aarx] = Wmmse[aatx*n_rx + aarx][re]; #ifdef DEBUG_MMSE + if (re==0) - printf("mult_mmse_chan_est: chan_est_re[%d] = (%f, %f)\n", aatx*n_rx + aarx, creal(chan_est_re[aatx*n_rx + aarx]), cimag(chan_est_re[aatx*n_rx + aarx])); + printf("mult_mmse_chan_est: chan_est_re[%d] = (%f, %f)\n", aatx*n_rx + aarx, creal(chan_est_re[aatx*n_rx + aarx]), cimag(chan_est_re[aatx*n_rx + aarx])); + #endif } } - mutl_matrix_matrix_col_based(Wmmse_re, chan_est_re, n_rx, n_tx, n_rx, n_tx, chan_est_mmse_re); - for (aatx=0; aatx<n_tx; aatx++){ - for (aarx=0; aarx<n_rx; aarx++){ - dl_ch_estimates_ext_f[aatx*n_rx + aarx][re] = chan_est_mmse_re[aatx*n_rx + aarx]; + + mutl_matrix_matrix_col_based(Wmmse_re, chan_est_re, n_rx, n_tx, n_rx, n_tx, chan_est_mmse_re); + + for (aatx=0; aatx<n_tx; aatx++) { + for (aarx=0; aarx<n_rx; aarx++) { + dl_ch_estimates_ext_f[aatx*n_rx + aarx][re] = chan_est_mmse_re[aatx*n_rx + aarx]; #ifdef DEBUG_MMSE - if (re==0) + + if (re==0) printf("mult_mmse_chan_est: dl_ch_estimates_ext_f[%d][%d] = (%f, %f)\n", aatx*n_rx + aarx, re, creal(dl_ch_estimates_ext_f[aatx*n_rx + aarx][re]), cimag(dl_ch_estimates_ext_f[aatx*n_rx + aarx][re])); + #endif - } } - } - free(Wmmse_re); - free(chan_est_re); - free(chan_est_mmse_re); + } + } + + free(Wmmse_re); + free(chan_est_re); + free(chan_est_mmse_re); } @@ -4642,19 +4299,15 @@ void dlsch_channel_level_TM34(int **dl_ch_estimates_ext, uint8_t symbol, unsigned short nb_rb, unsigned int mmse_flag, - MIMO_mode_t mimo_mode){ - + MIMO_mode_t mimo_mode) { #if defined(__x86_64__)||defined(__i386__) - short rb; unsigned char aarx,nre=12,symbol_mod; __m128i *dl_ch0_128,*dl_ch1_128, dl_ch0_128_tmp, dl_ch1_128_tmp, avg_0_128D, avg_1_128D; - symbol_mod = (symbol>=(7-frame_parms->Ncp)) ? symbol-(7-frame_parms->Ncp) : symbol; - //clear average level - // avg_0_128D = _mm_setzero_si128(); - // avg_1_128D = _mm_setzero_si128(); + // avg_0_128D = _mm_setzero_si128(); + // avg_1_128D = _mm_setzero_si128(); avg_0[0] = 0; avg_0[1] = 0; avg_1[0] = 0; @@ -4671,17 +4324,17 @@ void dlsch_channel_level_TM34(int **dl_ch_estimates_ext, for (aarx=0; aarx<frame_parms->nb_antennas_rx; aarx++) { dl_ch0_128 = (__m128i *)&dl_ch_estimates_ext[aarx][symbol*frame_parms->N_RB_DL*12]; dl_ch1_128 = (__m128i *)&dl_ch_estimates_ext[2+aarx][symbol*frame_parms->N_RB_DL*12]; - avg_0_128D = _mm_setzero_si128(); avg_1_128D = _mm_setzero_si128(); + for (rb=0; rb<nb_rb; rb++) { - // printf("rb %d : \n",rb); - //print_shorts("ch0\n",&dl_ch0_128[0]); - //print_shorts("ch1\n",&dl_ch1_128[0]); + // printf("rb %d : \n",rb); + //print_shorts("ch0\n",&dl_ch0_128[0]); + //print_shorts("ch1\n",&dl_ch1_128[0]); dl_ch0_128_tmp = _mm_load_si128(&dl_ch0_128[0]); dl_ch1_128_tmp = _mm_load_si128(&dl_ch1_128[0]); - if (mmse_flag == 0){ + if (mmse_flag == 0) { if (mimo_mode==LARGE_CDD) prec2A_TM3_128(&dl_ch0_128_tmp,&dl_ch1_128_tmp); else if (mimo_mode==DUALSTREAM_UNIFORM_PRECODING1) @@ -4694,13 +4347,11 @@ void dlsch_channel_level_TM34(int **dl_ch_estimates_ext, // mmtmpD0 = _mm_madd_epi16(dl_ch0_128_tmp,dl_ch0_128_tmp); avg_0_128D = _mm_add_epi32(avg_0_128D,_mm_madd_epi16(dl_ch0_128_tmp,dl_ch0_128_tmp)); - avg_1_128D = _mm_add_epi32(avg_1_128D,_mm_madd_epi16(dl_ch1_128_tmp,dl_ch1_128_tmp)); - dl_ch0_128_tmp = _mm_load_si128(&dl_ch0_128[1]); dl_ch1_128_tmp = _mm_load_si128(&dl_ch1_128[1]); - if (mmse_flag == 0){ + if (mmse_flag == 0) { if (mimo_mode==LARGE_CDD) prec2A_TM3_128(&dl_ch0_128_tmp,&dl_ch1_128_tmp); else if (mimo_mode==DUALSTREAM_UNIFORM_PRECODING1) @@ -4713,18 +4364,16 @@ void dlsch_channel_level_TM34(int **dl_ch_estimates_ext, // mmtmpD1 = _mm_madd_epi16(dl_ch0_128_tmp,dl_ch0_128_tmp); avg_0_128D = _mm_add_epi32(avg_0_128D,_mm_madd_epi16(dl_ch0_128_tmp,dl_ch0_128_tmp)); - avg_1_128D = _mm_add_epi32(avg_1_128D,_mm_madd_epi16(dl_ch1_128_tmp,dl_ch1_128_tmp)); if (((symbol_mod == 0) || (symbol_mod == (frame_parms->Ncp-1)))&&(frame_parms->nb_antenna_ports_eNB!=1)) { dl_ch0_128+=2; dl_ch1_128+=2; - } - else { + } else { dl_ch0_128_tmp = _mm_load_si128(&dl_ch0_128[2]); dl_ch1_128_tmp = _mm_load_si128(&dl_ch1_128[2]); - if (mmse_flag == 0){ + if (mmse_flag == 0) { if (mimo_mode==LARGE_CDD) prec2A_TM3_128(&dl_ch0_128_tmp,&dl_ch1_128_tmp); else if (mimo_mode==DUALSTREAM_UNIFORM_PRECODING1) @@ -4734,45 +4383,39 @@ void dlsch_channel_level_TM34(int **dl_ch_estimates_ext, else if (mimo_mode==DUALSTREAM_PUSCH_PRECODING) prec2A_TM4_128(pmi_ext[rb],&dl_ch0_128_tmp,&dl_ch1_128_tmp); } - // mmtmpD2 = _mm_madd_epi16(dl_ch0_128_tmp,dl_ch0_128_tmp); + // mmtmpD2 = _mm_madd_epi16(dl_ch0_128_tmp,dl_ch0_128_tmp); avg_1_128D = _mm_add_epi32(avg_1_128D,_mm_madd_epi16(dl_ch1_128_tmp,dl_ch1_128_tmp)); avg_0_128D = _mm_add_epi32(avg_0_128D,_mm_madd_epi16(dl_ch0_128_tmp,dl_ch0_128_tmp)); - dl_ch0_128+=3; dl_ch1_128+=3; } } - - avg_0[aarx] = (((int*)&avg_0_128D)[0])/(nb_rb*nre) + - (((int*)&avg_0_128D)[1])/(nb_rb*nre) + - (((int*)&avg_0_128D)[2])/(nb_rb*nre) + - (((int*)&avg_0_128D)[3])/(nb_rb*nre); + avg_0[aarx] = (((int *)&avg_0_128D)[0])/(nb_rb*nre) + + (((int *)&avg_0_128D)[1])/(nb_rb*nre) + + (((int *)&avg_0_128D)[2])/(nb_rb*nre) + + (((int *)&avg_0_128D)[3])/(nb_rb*nre); // printf("From Chan_level aver stream 0 %d =%d\n", aarx, avg_0[aarx]); - - avg_1[aarx] = (((int*)&avg_1_128D)[0])/(nb_rb*nre) + - (((int*)&avg_1_128D)[1])/(nb_rb*nre) + - (((int*)&avg_1_128D)[2])/(nb_rb*nre) + - (((int*)&avg_1_128D)[3])/(nb_rb*nre); - // printf("From Chan_level aver stream 1 %d =%d\n", aarx, avg_1[aarx]); + avg_1[aarx] = (((int *)&avg_1_128D)[0])/(nb_rb*nre) + + (((int *)&avg_1_128D)[1])/(nb_rb*nre) + + (((int *)&avg_1_128D)[2])/(nb_rb*nre) + + (((int *)&avg_1_128D)[3])/(nb_rb*nre); + // printf("From Chan_level aver stream 1 %d =%d\n", aarx, avg_1[aarx]); } -//avg_0[0] = max(avg_0[0],avg_0[1]); -//avg_1[0] = max(avg_1[0],avg_1[1]); -//avg_0[0]= max(avg_0[0], avg_1[0]); + //avg_0[0] = max(avg_0[0],avg_0[1]); + //avg_1[0] = max(avg_1[0],avg_1[1]); + //avg_0[0]= max(avg_0[0], avg_1[0]); avg_0[0] = avg_0[0] + avg_0[1]; - // printf("From Chan_level aver stream 0 final =%d\n", avg_0[0]); + // printf("From Chan_level aver stream 0 final =%d\n", avg_0[0]); avg_1[0] = avg_1[0] + avg_1[1]; - // printf("From Chan_level aver stream 1 final =%d\n", avg_1[0]); - avg_0[0] = min (avg_0[0], avg_1[0]); - avg_1[0] = avg_0[0]; - + // printf("From Chan_level aver stream 1 final =%d\n", avg_1[0]); + avg_0[0] = min (avg_0[0], avg_1[0]); + avg_1[0] = avg_0[0]; _mm_empty(); _m_empty(); - #elif defined(__arm__) - #endif } @@ -4782,17 +4425,12 @@ void dlsch_channel_level_TM56(int **dl_ch_estimates_ext, unsigned char *pmi_ext, int *avg, uint8_t symbol, - unsigned short nb_rb) -{ - + unsigned short nb_rb) { #if defined(__x86_64__)||defined(__i386__) - short rb; unsigned char aarx,nre=12,symbol_mod; __m128i *dl_ch0_128,*dl_ch1_128, dl_ch0_128_tmp, dl_ch1_128_tmp,avg128D; - symbol_mod = (symbol>=(7-frame_parms->Ncp)) ? symbol-(7-frame_parms->Ncp) : symbol; - //clear average level avg128D = _mm_setzero_si128(); avg[0] = 0; @@ -4811,17 +4449,13 @@ void dlsch_channel_level_TM56(int **dl_ch_estimates_ext, dl_ch1_128 = (__m128i *)&dl_ch_estimates_ext[2+aarx][symbol*frame_parms->N_RB_DL*12]; for (rb=0; rb<nb_rb; rb++) { - dl_ch0_128_tmp = _mm_load_si128(&dl_ch0_128[0]); dl_ch1_128_tmp = _mm_load_si128(&dl_ch1_128[0]); - prec2A_TM56_128(pmi_ext[rb],&dl_ch0_128_tmp,&dl_ch1_128_tmp); // mmtmpD0 = _mm_madd_epi16(dl_ch0_128_tmp,dl_ch0_128_tmp); avg128D = _mm_add_epi32(avg128D,_mm_madd_epi16(dl_ch0_128_tmp,dl_ch0_128_tmp)); - dl_ch0_128_tmp = _mm_load_si128(&dl_ch0_128[1]); dl_ch1_128_tmp = _mm_load_si128(&dl_ch1_128[1]); - prec2A_TM56_128(pmi_ext[rb],&dl_ch0_128_tmp,&dl_ch1_128_tmp); // mmtmpD1 = _mm_madd_epi16(dl_ch0_128_tmp,dl_ch0_128_tmp); avg128D = _mm_add_epi32(avg128D,_mm_madd_epi16(dl_ch0_128_tmp,dl_ch0_128_tmp)); @@ -4829,52 +4463,41 @@ void dlsch_channel_level_TM56(int **dl_ch_estimates_ext, if (((symbol_mod == 0) || (symbol_mod == (frame_parms->Ncp-1)))&&(frame_parms->nb_antenna_ports_eNB!=1)) { dl_ch0_128+=2; dl_ch1_128+=2; - } - else { + } else { dl_ch0_128_tmp = _mm_load_si128(&dl_ch0_128[2]); dl_ch1_128_tmp = _mm_load_si128(&dl_ch1_128[2]); - prec2A_TM56_128(pmi_ext[rb],&dl_ch0_128_tmp,&dl_ch1_128_tmp); // mmtmpD2 = _mm_madd_epi16(dl_ch0_128_tmp,dl_ch0_128_tmp); avg128D = _mm_add_epi32(avg128D,_mm_madd_epi16(dl_ch0_128_tmp,dl_ch0_128_tmp)); - dl_ch0_128+=3; dl_ch1_128+=3; } } - avg[aarx] = (((int*)&avg128D)[0])/(nb_rb*nre) + - (((int*)&avg128D)[1])/(nb_rb*nre) + - (((int*)&avg128D)[2])/(nb_rb*nre) + - (((int*)&avg128D)[3])/(nb_rb*nre); + avg[aarx] = (((int *)&avg128D)[0])/(nb_rb*nre) + + (((int *)&avg128D)[1])/(nb_rb*nre) + + (((int *)&avg128D)[2])/(nb_rb*nre) + + (((int *)&avg128D)[3])/(nb_rb*nre); } // choose maximum of the 2 effective channels avg[0] = cmax(avg[0],avg[1]); - _mm_empty(); _m_empty(); - #elif defined(__arm__) - - #endif } //compute average channel_level for TM7 void dlsch_channel_level_TM7(int **dl_bf_ch_estimates_ext, - LTE_DL_FRAME_PARMS *frame_parms, - int *avg, - uint8_t symbol, - unsigned short nb_rb) -{ - + LTE_DL_FRAME_PARMS *frame_parms, + int *avg, + uint8_t symbol, + unsigned short nb_rb) { #if defined(__x86_64__)||defined(__i386__) - short rb; unsigned char aatx,aarx,nre=12,symbol_mod; __m128i *dl_ch128,avg128D; - symbol_mod = (symbol>=(7-frame_parms->Ncp)) ? symbol-(7-frame_parms->Ncp) : symbol; for (aatx=0; aatx<frame_parms->nb_antenna_ports_eNB; aatx++) @@ -4882,7 +4505,6 @@ void dlsch_channel_level_TM7(int **dl_bf_ch_estimates_ext, //clear average level avg128D = _mm_setzero_si128(); // 5 is always a symbol with no pilots for both normal and extended prefix - dl_ch128=(__m128i *)&dl_bf_ch_estimates_ext[(aatx<<1)+aarx][symbol*frame_parms->N_RB_DL*12]; for (rb=0; rb<nb_rb; rb++) { @@ -4916,19 +4538,16 @@ void dlsch_channel_level_TM7(int **dl_bf_ch_estimates_ext, else nre=12; - avg[(aatx<<1)+aarx] = (((int*)&avg128D)[0] + - ((int*)&avg128D)[1] + - ((int*)&avg128D)[2] + - ((int*)&avg128D)[3])/(nb_rb*nre); - + avg[(aatx<<1)+aarx] = (((int *)&avg128D)[0] + + ((int *)&avg128D)[1] + + ((int *)&avg128D)[2] + + ((int *)&avg128D)[3])/(nb_rb*nre); // printf("Channel level : %d\n",avg[(aatx<<1)+aarx]); } _mm_empty(); _m_empty(); - #elif defined(__arm__) - #endif } //#define ONE_OVER_2_Q15 16384 @@ -4937,53 +4556,40 @@ void dlsch_alamouti(LTE_DL_FRAME_PARMS *frame_parms, int **dl_ch_mag, int **dl_ch_magb, unsigned char symbol, - unsigned short nb_rb) -{ - + unsigned short nb_rb) { #if defined(__x86_64__)||defined(__i386__) - short *rxF0,*rxF1; __m128i *ch_mag0,*ch_mag1,*ch_mag0b,*ch_mag1b, *rxF0_128; unsigned char rb,re; int jj = (symbol*frame_parms->N_RB_DL*12); uint8_t symbol_mod = (symbol>=(7-frame_parms->Ncp)) ? symbol-(7-frame_parms->Ncp) : symbol; uint8_t pilots = ((symbol_mod==0)||(symbol_mod==(4-frame_parms->Ncp))) ? 1 : 0; - rxF0_128 = (__m128i*) &rxdataF_comp[0][jj]; - + rxF0_128 = (__m128i *) &rxdataF_comp[0][jj]; //amp = _mm_set1_epi16(ONE_OVER_2_Q15); - - // printf("Doing alamouti!\n"); - rxF0 = (short*)&rxdataF_comp[0][jj]; //tx antenna 0 h0*y - rxF1 = (short*)&rxdataF_comp[2][jj]; //tx antenna 1 h1*y + rxF0 = (short *)&rxdataF_comp[0][jj]; //tx antenna 0 h0*y + rxF1 = (short *)&rxdataF_comp[2][jj]; //tx antenna 1 h1*y ch_mag0 = (__m128i *)&dl_ch_mag[0][jj]; ch_mag1 = (__m128i *)&dl_ch_mag[2][jj]; ch_mag0b = (__m128i *)&dl_ch_magb[0][jj]; ch_mag1b = (__m128i *)&dl_ch_magb[2][jj]; for (rb=0; rb<nb_rb; rb++) { - for (re=0; re<((pilots==0)?12:8); re+=2) { - // Alamouti RX combining - // printf("Alamouti: symbol %d, rb %d, re %d: rxF0 (%d,%d,%d,%d), rxF1 (%d,%d,%d,%d)\n",symbol,rb,re,rxF0[0],rxF0[1],rxF0[2],rxF0[3],rxF1[0],rxF1[1],rxF1[2],rxF1[3]); rxF0[0] = rxF0[0] + rxF1[2]; rxF0[1] = rxF0[1] - rxF1[3]; - rxF0[2] = rxF0[2] - rxF1[0]; rxF0[3] = rxF0[3] + rxF1[1]; - // printf("Alamouti: rxF0 after (%d,%d,%d,%d)\n",rxF0[0],rxF0[1],rxF0[2],rxF0[3]); rxF0+=4; rxF1+=4; - } // compute levels for 16QAM or 64 QAM llr unit ch_mag0[0] = _mm_adds_epi16(ch_mag0[0],ch_mag1[0]); ch_mag0[1] = _mm_adds_epi16(ch_mag0[1],ch_mag1[1]); - ch_mag0b[0] = _mm_adds_epi16(ch_mag0b[0],ch_mag1b[0]); ch_mag0b[1] = _mm_adds_epi16(ch_mag0b[1],ch_mag1b[1]); @@ -5001,21 +4607,14 @@ void dlsch_alamouti(LTE_DL_FRAME_PARMS *frame_parms, //rxF0_128[0] = _mm_srai_epi16(rxF0_128[0],1); //rxF0_128[1] = _mm_srai_epi16(rxF0_128[1],1); - - if (pilots==0) { ch_mag0[2] = _mm_adds_epi16(ch_mag0[2],ch_mag1[2]); ch_mag0b[2] = _mm_adds_epi16(ch_mag0b[2],ch_mag1b[2]); - //ch_mag0[2] = _mm_srai_epi16(ch_mag0[2],1); //ch_mag0b[2] = _mm_srai_epi16(ch_mag0b[2],1); - //rxF0_128[2] = _mm_mulhi_epi16(rxF0_128[2],amp); //rxF0_128[2] = _mm_slli_epi16(rxF0_128[2],1); - //rxF0_128[2] = _mm_srai_epi16(rxF0_128[2],1); - - ch_mag0+=3; ch_mag1+=3; ch_mag0b+=3; @@ -5032,9 +4631,7 @@ void dlsch_alamouti(LTE_DL_FRAME_PARMS *frame_parms, _mm_empty(); _m_empty(); - #elif defined(__arm__) - #endif } @@ -5054,18 +4651,11 @@ unsigned short dlsch_extract_rbs_single(int **rxdataF, unsigned char subframe, uint32_t high_speed_flag, LTE_DL_FRAME_PARMS *frame_parms) { - - - unsigned short rb,nb_rb=0; unsigned char rb_alloc_ind; unsigned char i,aarx,l,nsymb,skip_half=0,sss_symb,pss_symb=0; int *dl_ch0,*dl_ch0_ext,*rxF,*rxF_ext; - - - unsigned char symbol_mod,pilots=0,j=0,poffset=0; - symbol_mod = (symbol>=(7-frame_parms->Ncp)) ? symbol-(7-frame_parms->Ncp) : symbol; pilots = ((symbol_mod==0)||(symbol_mod==(4-frame_parms->Ncp))) ? 1 : 0; l=symbol; @@ -5083,21 +4673,17 @@ unsigned short dlsch_extract_rbs_single(int **rxdataF, poffset=3; for (aarx=0; aarx<frame_parms->nb_antennas_rx; aarx++) { - if (high_speed_flag == 1) dl_ch0 = &dl_ch_estimates[aarx][5+(symbol*(frame_parms->ofdm_symbol_size))]; else dl_ch0 = &dl_ch_estimates[aarx][5]; dl_ch0_ext = &dl_ch_estimates_ext[aarx][symbol*(frame_parms->N_RB_DL*12)]; - rxF_ext = &rxdataF_ext[aarx][symbol*(frame_parms->N_RB_DL*12)]; rxF = &rxdataF[aarx][(frame_parms->first_carrier_offset + (symbol*(frame_parms->ofdm_symbol_size)))]; if ((frame_parms->N_RB_DL&1) == 0) // even number of RBs - - for (rb=0;rb<frame_parms->N_RB_DL;rb++) { - + for (rb=0; rb<frame_parms->N_RB_DL; rb++) { if (rb < 32) rb_alloc_ind = (rb_alloc[0]>>rb) & 1; else if (rb < 64) @@ -5128,7 +4714,6 @@ unsigned short dlsch_extract_rbs_single(int **rxdataF, rb_alloc_ind = 0; } - if (frame_parms->frame_type == FDD) { //PSS if (((subframe==0)||(subframe==5)) && (rb>=((frame_parms->N_RB_DL>>1)-3)) && (rb<((frame_parms->N_RB_DL>>1)+3)) && (l==pss_symb) ) { @@ -5172,25 +4757,21 @@ unsigned short dlsch_extract_rbs_single(int **rxdataF, rxF_ext[j]=rxF[i]; // printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[j],*(1+(short*)&rxF_ext[j])); dl_ch0_ext[j++]=dl_ch0[i]; - } } dl_ch0_ext+=10; rxF_ext+=10; } - - } dl_ch0+=12; rxF+=12; - } else { // Odd number of RBs for (rb=0; rb<frame_parms->N_RB_DL>>1; rb++) { #ifdef DEBUG_DLSCH_DEMOD - printf("dlch_ext %d\n",dl_ch0_ext-&dl_ch_estimates_ext[aarx][0]); + printf("dlch_ext %u\n",dl_ch0_ext-&dl_ch_estimates_ext[aarx][0]); #endif skip_half=0; @@ -5208,7 +4789,6 @@ unsigned short dlsch_extract_rbs_single(int **rxdataF, if (rb_alloc_ind == 1) nb_rb++; - // PBCH if ((subframe==0) && (rb>((frame_parms->N_RB_DL>>1)-3)) && (rb<((frame_parms->N_RB_DL>>1)+3)) && (l>=(nsymb>>1)) && (l<((nsymb>>1) + 4))) { rb_alloc_ind = 0; @@ -5228,6 +4808,7 @@ unsigned short dlsch_extract_rbs_single(int **rxdataF, (l==sss_symb) ) { rb_alloc_ind = 0; } + //SSS if (((subframe==0)||(subframe==5)) && (rb==((frame_parms->N_RB_DL>>1)-3)) && @@ -5240,7 +4821,6 @@ unsigned short dlsch_extract_rbs_single(int **rxdataF, //PSS in subframe 0/5 if FDD if (frame_parms->frame_type == FDD) { //FDD - if (((subframe==0)||(subframe==5)) && (rb>((frame_parms->N_RB_DL>>1)-3)) && (rb<((frame_parms->N_RB_DL>>1)+3)) && @@ -5255,22 +4835,22 @@ unsigned short dlsch_extract_rbs_single(int **rxdataF, } if ((frame_parms->frame_type == TDD) && - (subframe==6)){ //TDD Subframe 6 + (subframe==6)) { //TDD Subframe 6 if ((rb>((frame_parms->N_RB_DL>>1)-3)) && (rb<((frame_parms->N_RB_DL>>1)+3)) && (l==pss_symb) ) { rb_alloc_ind = 0; } + if ((rb==((frame_parms->N_RB_DL>>1)-3)) && (l==pss_symb)) skip_half=1; else if ((rb==((frame_parms->N_RB_DL>>1)+3)) && (l==pss_symb)) skip_half=2; } - if (rb_alloc_ind==1) { - #ifdef DEBUG_DLSCH_DEMOD printf("rb %d/symbol %d (skip_half %d)\n",rb,l,skip_half); #endif + if (pilots==0) { // printf("Extracting w/o pilots (symbol %d, rb %d, skip_half %d)\n",l,rb,skip_half); if (skip_half==1) { @@ -5279,9 +4859,10 @@ unsigned short dlsch_extract_rbs_single(int **rxdataF, for (i=0; i<6; i++) { rxF_ext[i]=rxF[i]; #ifdef DEBUG_DLSCH_DEMOD - printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short*)&rxF_ext[i])); + printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short *)&rxF_ext[i])); #endif } + dl_ch0_ext+=6; rxF_ext+=6; } else if (skip_half==2) { @@ -5290,9 +4871,10 @@ unsigned short dlsch_extract_rbs_single(int **rxdataF, for (i=0; i<6; i++) { rxF_ext[i]=rxF[(i+6)]; #ifdef DEBUG_DLSCH_DEMOD - printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short*)&rxF_ext[i])); + printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short *)&rxF_ext[i])); #endif } + dl_ch0_ext+=6; rxF_ext+=6; } else { @@ -5301,9 +4883,10 @@ unsigned short dlsch_extract_rbs_single(int **rxdataF, for (i=0; i<12; i++) { rxF_ext[i]=rxF[i]; #ifdef DEBUG_DLSCH_DEMOD - printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short*)&rxF_ext[i])); + printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short *)&rxF_ext[i])); #endif } + dl_ch0_ext+=12; rxF_ext+=12; } @@ -5316,11 +4899,12 @@ unsigned short dlsch_extract_rbs_single(int **rxdataF, if (i!=((frame_parms->nushift+poffset)%6)) { rxF_ext[j]=rxF[i]; #ifdef DEBUG_DLSCH_DEMOD - printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[j],*(1+(short*)&rxF_ext[j])); + printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[j],*(1+(short *)&rxF_ext[j])); #endif dl_ch0_ext[j++]=dl_ch0[i]; } } + rxF_ext+=5; dl_ch0_ext+=5; } else if (skip_half==2) { @@ -5328,7 +4912,7 @@ unsigned short dlsch_extract_rbs_single(int **rxdataF, if (i!=((frame_parms->nushift+poffset)%6)) { rxF_ext[j]=rxF[(i+6)]; #ifdef DEBUG_DLSCH_DEMOD - printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[j],*(1+(short*)&rxF_ext[j])); + printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[j],*(1+(short *)&rxF_ext[j])); #endif dl_ch0_ext[j++]=dl_ch0[i+6]; } @@ -5342,10 +4926,9 @@ unsigned short dlsch_extract_rbs_single(int **rxdataF, (i!=((frame_parms->nushift+poffset+6)%12))) { rxF_ext[j]=rxF[i]; #ifdef DEBUG_DLSCH_DEMOD - printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[j],*(1+(short*)&rxF_ext[j])); + printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[j],*(1+(short *)&rxF_ext[j])); #endif dl_ch0_ext[j++]=dl_ch0[i]; - } } @@ -5354,11 +4937,11 @@ unsigned short dlsch_extract_rbs_single(int **rxdataF, } } } + dl_ch0+=12; rxF+=12; } // first half loop - // Do middle RB (around DC) if (rb < 32) rb_alloc_ind = (rb_alloc[0]>>rb) & 1; @@ -5371,7 +4954,6 @@ unsigned short dlsch_extract_rbs_single(int **rxdataF, else rb_alloc_ind = 0; - if (rb_alloc_ind == 1) nb_rb++; @@ -5402,13 +4984,13 @@ unsigned short dlsch_extract_rbs_single(int **rxdataF, rb_alloc_ind = 0; } - // printf("dlch_ext %d\n",dl_ch0_ext-&dl_ch_estimates_ext[aarx][0]); // printf("DC rb %d (%p)\n",rb,rxF); if (rb_alloc_ind==1) { #ifdef DEBUG_DLSCH_DEMOD printf("rb %d/symbol %d (skip_half %d)\n",rb,l,skip_half); #endif + if (pilots==0) { for (i=0; i<6; i++) { dl_ch0_ext[i]=dl_ch0[i]; @@ -5432,7 +5014,7 @@ unsigned short dlsch_extract_rbs_single(int **rxdataF, dl_ch0_ext[j]=dl_ch0[i]; rxF_ext[j++]=rxF[i]; #ifdef DEBUG_DLSCH_DEMOD - printf("**extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[j-1],*(1+(short*)&rxF_ext[j-1])); + printf("**extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[j-1],*(1+(short *)&rxF_ext[j-1])); #endif } } @@ -5444,7 +5026,7 @@ unsigned short dlsch_extract_rbs_single(int **rxdataF, dl_ch0_ext[j]=dl_ch0[i]; rxF_ext[j++]=rxF[(1+i-6)]; #ifdef DEBUG_DLSCH_DEMOD - printf("**extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[j-1],*(1+(short*)&rxF_ext[j-1])); + printf("**extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[j-1],*(1+(short *)&rxF_ext[j-1])); #endif } } @@ -5461,7 +5043,7 @@ unsigned short dlsch_extract_rbs_single(int **rxdataF, rxF+=7; rb++; - for (;rb<frame_parms->N_RB_DL;rb++) { + for (; rb<frame_parms->N_RB_DL; rb++) { // printf("dlch_ext %d\n",dl_ch0_ext-&dl_ch_estimates_ext[aarx][0]); // printf("rb %d (%p)\n",rb,rxF); skip_half=0; @@ -5484,6 +5066,7 @@ unsigned short dlsch_extract_rbs_single(int **rxdataF, if ((subframe==0) && (rb>((frame_parms->N_RB_DL>>1)-3)) && (rb<((frame_parms->N_RB_DL>>1)+3)) && (l>=nsymb>>1) && (l<((nsymb>>1) + 4))) { rb_alloc_ind = 0; } + //PBCH subframe 0, symbols nsymb>>1 ... nsymb>>1 + 3 if ((subframe==0) && (rb==((frame_parms->N_RB_DL>>1)-3)) && (l>=(nsymb>>1)) && (l<((nsymb>>1) + 4))) skip_half=1; @@ -5494,11 +5077,13 @@ unsigned short dlsch_extract_rbs_single(int **rxdataF, if (((subframe==0)||(subframe==5)) && (rb>((frame_parms->N_RB_DL>>1)-3)) && (rb<((frame_parms->N_RB_DL>>1)+3)) && (l==sss_symb) ) { rb_alloc_ind = 0; } + //SSS if (((subframe==0)||(subframe==5)) && (rb==((frame_parms->N_RB_DL>>1)-3)) && (l==sss_symb)) skip_half=1; else if (((subframe==0)||(subframe==5)) && (rb==((frame_parms->N_RB_DL>>1)+3)) && (l==sss_symb)) skip_half=2; + if (frame_parms->frame_type == FDD) { //PSS if (((subframe==0)||(subframe==5)) && (rb>((frame_parms->N_RB_DL>>1)-3)) && (rb<((frame_parms->N_RB_DL>>1)+3)) && (l==pss_symb) ) { @@ -5514,7 +5099,6 @@ unsigned short dlsch_extract_rbs_single(int **rxdataF, } if ((frame_parms->frame_type == TDD) && - (subframe==6)) { //TDD Subframe 6 if ((rb>((frame_parms->N_RB_DL>>1)-3)) && (rb<((frame_parms->N_RB_DL>>1)+3)) && (l==pss_symb) ) { rb_alloc_ind = 0; @@ -5530,6 +5114,7 @@ unsigned short dlsch_extract_rbs_single(int **rxdataF, #ifdef DEBUG_DLSCH_DEMOD printf("rb %d/symbol %d (skip_half %d)\n",rb,l,skip_half); #endif + /* printf("rb %d\n",rb); for (i=0;i<12;i++) @@ -5544,33 +5129,34 @@ unsigned short dlsch_extract_rbs_single(int **rxdataF, for (i=0; i<6; i++) { rxF_ext[i]=rxF[i]; #ifdef DEBUG_DLSCH_DEMOD - printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short*)&rxF_ext[i])); + printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short *)&rxF_ext[i])); #endif } + dl_ch0_ext+=6; rxF_ext+=6; - } else if (skip_half==2) { memcpy(dl_ch0_ext,dl_ch0+6,6*sizeof(int)); for (i=0; i<6; i++) { rxF_ext[i]=rxF[(i+6)]; #ifdef DEBUG_DLSCH_DEMOD - printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short*)&rxF_ext[i])); + printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short *)&rxF_ext[i])); #endif } + dl_ch0_ext+=6; rxF_ext+=6; - } else { memcpy(dl_ch0_ext,dl_ch0,12*sizeof(int)); for (i=0; i<12; i++) { rxF_ext[i]=rxF[i]; #ifdef DEBUG_DLSCH_DEMOD - printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short*)&rxF_ext[i])); + printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short *)&rxF_ext[i])); #endif } + dl_ch0_ext+=12; rxF_ext+=12; } @@ -5583,7 +5169,7 @@ unsigned short dlsch_extract_rbs_single(int **rxdataF, if (i!=((frame_parms->nushift+poffset)%6)) { rxF_ext[j]=rxF[i]; #ifdef DEBUG_DLSCH_DEMOD - printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[j],*(1+(short*)&rxF_ext[j])); + printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[j],*(1+(short *)&rxF_ext[j])); #endif dl_ch0_ext[j++]=dl_ch0[i]; } @@ -5596,7 +5182,7 @@ unsigned short dlsch_extract_rbs_single(int **rxdataF, if (i!=((frame_parms->nushift+poffset)%6)) { rxF_ext[j]=rxF[(i+6)]; #ifdef DEBUG_DLSCH_DEMOD - printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[j],*(1+(short*)&rxF_ext[j])); + printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[j],*(1+(short *)&rxF_ext[j])); #endif dl_ch0_ext[j++]=dl_ch0[i+6]; } @@ -5610,11 +5196,12 @@ unsigned short dlsch_extract_rbs_single(int **rxdataF, (i!=((frame_parms->nushift+poffset+6)%12))) { rxF_ext[j]=rxF[i]; #ifdef DEBUG_DLSCH_DEMOD - printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[j],*(1+(short*)&rxF_ext[j])); + printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[j],*(1+(short *)&rxF_ext[j])); #endif dl_ch0_ext[j++]=dl_ch0[i]; } } + dl_ch0_ext+=10; rxF_ext+=10; } @@ -5627,7 +5214,6 @@ unsigned short dlsch_extract_rbs_single(int **rxdataF, } } - return(nb_rb/frame_parms->nb_antennas_rx); } @@ -5643,7 +5229,6 @@ unsigned short dlsch_extract_rbs_dual(int **rxdataF, uint32_t high_speed_flag, LTE_DL_FRAME_PARMS *frame_parms, MIMO_mode_t mimo_mode) { - int prb,nb_rb=0; int prb_off,prb_off2; int rb_alloc_ind,skip_half=0,sss_symb,pss_symb=0,nsymb,l; @@ -5651,7 +5236,6 @@ unsigned short dlsch_extract_rbs_dual(int **rxdataF, int32_t *dl_ch0,*dl_ch0p,*dl_ch0_ext,*dl_ch1,*dl_ch1p,*dl_ch1_ext,*rxF,*rxF_ext; int symbol_mod,pilots=0,j=0; unsigned char *pmi_loc; - symbol_mod = (symbol>=(7-frame_parms->Ncp)) ? symbol-(7-frame_parms->Ncp) : symbol; // printf("extract_rbs: symbol_mod %d\n",symbol_mod); @@ -5670,7 +5254,6 @@ unsigned short dlsch_extract_rbs_dual(int **rxdataF, } for (aarx=0; aarx<frame_parms->nb_antennas_rx; aarx++) { - if (high_speed_flag==1) { dl_ch0 = &dl_ch_estimates[aarx][5+(symbol*(frame_parms->ofdm_symbol_size))]; dl_ch1 = &dl_ch_estimates[2+aarx][5+(symbol*(frame_parms->ofdm_symbol_size))]; @@ -5680,7 +5263,6 @@ unsigned short dlsch_extract_rbs_dual(int **rxdataF, } pmi_loc = pmi_ext; - // pointers to extracted RX signals and channel estimates rxF_ext = &rxdataF_ext[aarx][symbol*(frame_parms->N_RB_DL*12)]; dl_ch0_ext = &dl_ch_estimates_ext[aarx][symbol*(frame_parms->N_RB_DL*12)]; @@ -5701,8 +5283,7 @@ unsigned short dlsch_extract_rbs_dual(int **rxdataF, rb_alloc_ind = 0; if (rb_alloc_ind == 1) - nb_rb++; - + nb_rb++; if ((frame_parms->N_RB_DL&1) == 0) { // even number of RBs @@ -5726,8 +5307,6 @@ unsigned short dlsch_extract_rbs_dual(int **rxdataF, // printf("symbol %d / rb %d: skipping SSS REs\n",symbol,prb); } - - //PSS in subframe 0/5 if FDD if (frame_parms->frame_type == FDD) { //FDD if (((subframe==0)||(subframe==5)) && @@ -5749,35 +5328,29 @@ unsigned short dlsch_extract_rbs_dual(int **rxdataF, } if (rb_alloc_ind==1) { // PRB is allocated - - - prb_off = 12*prb; prb_off2 = 1+(12*(prb-(frame_parms->N_RB_DL>>1))); dl_ch0p = dl_ch0+(12*prb); dl_ch1p = dl_ch1+(12*prb); - if (prb<(frame_parms->N_RB_DL>>1)){ + + if (prb<(frame_parms->N_RB_DL>>1)) { rxF = &rxdataF[aarx][prb_off+ frame_parms->first_carrier_offset + (symbol*(frame_parms->ofdm_symbol_size))]; - } - else { + } else { rxF = &rxdataF[aarx][prb_off2+ (symbol*(frame_parms->ofdm_symbol_size))]; } - /* - if (mimo_mode <= PUSCH_PRECODING1) - *pmi_loc = (pmi>>((prb>>2)<<1))&3; - else - *pmi_loc=(pmi>>prb)&1;*/ - - *pmi_loc = get_pmi(frame_parms->N_RB_DL,mimo_mode,pmi,prb); + /* + if (mimo_mode <= PUSCH_PRECODING1) + *pmi_loc = (pmi>>((prb>>2)<<1))&3; + else + *pmi_loc=(pmi>>prb)&1;*/ + *pmi_loc = get_pmi(frame_parms->N_RB_DL,mimo_mode,pmi,prb); pmi_loc++; - if (pilots == 0) { - memcpy(dl_ch0_ext,dl_ch0p,12*sizeof(int)); memcpy(dl_ch1_ext,dl_ch1p,12*sizeof(int)); memcpy(rxF_ext,rxF,12*sizeof(int)); @@ -5786,6 +5359,7 @@ unsigned short dlsch_extract_rbs_dual(int **rxdataF, rxF_ext +=12; } else { // pilots==1 j=0; + for (i=0; i<12; i++) { if ((i!=frame_parms->nushift) && (i!=frame_parms->nushift+3) && @@ -5797,16 +5371,15 @@ unsigned short dlsch_extract_rbs_dual(int **rxdataF, dl_ch1_ext[j++]=dl_ch1p[i]; } } + dl_ch0_ext+=8; dl_ch1_ext+=8; rxF_ext+=8; } // pilots==1 - } } else { // Odd number of RBs - - // PBCH + // PBCH if ((subframe==0) && (prb>((frame_parms->N_RB_DL>>1)-3)) && (prb<((frame_parms->N_RB_DL>>1)+3)) && @@ -5826,8 +5399,6 @@ unsigned short dlsch_extract_rbs_dual(int **rxdataF, // printf("symbol %d / rb %d: skipping SSS REs\n",symbol,prb); } - - //PSS in subframe 0/5 if FDD if (frame_parms->frame_type == FDD) { //FDD if (((subframe==0)||(subframe==5)) && @@ -5882,7 +5453,6 @@ unsigned short dlsch_extract_rbs_dual(int **rxdataF, (((subframe==0)||(subframe==5)))) || //FDD Subframes 0,5 ((frame_parms->frame_type == TDD) && (((subframe==1) || (subframe==6))))) { //TDD Subframes 1,6 - if ((prb==((frame_parms->N_RB_DL>>1)-3)) && (l==pss_symb)) skip_half=1; @@ -5891,31 +5461,30 @@ unsigned short dlsch_extract_rbs_dual(int **rxdataF, skip_half=2; } - prb_off = 12*prb; prb_off2 = 7+(12*(prb-(frame_parms->N_RB_DL>>1)-1)); dl_ch0p = dl_ch0+(12*prb); dl_ch1p = dl_ch1+(12*prb); - if (prb<=(frame_parms->N_RB_DL>>1)){ + if (prb<=(frame_parms->N_RB_DL>>1)) { rxF = &rxdataF[aarx][prb_off+ frame_parms->first_carrier_offset + (symbol*(frame_parms->ofdm_symbol_size))]; - } - else { + } else { rxF = &rxdataF[aarx][prb_off2+ (symbol*(frame_parms->ofdm_symbol_size))]; } + #ifdef DEBUG_DLSCH_DEMOD printf("symbol %d / rb %d: alloc %d skip_half %d (rxF %p, rxF_ext %p) prb_off (%d,%d)\n",symbol,prb,rb_alloc_ind,skip_half,rxF,rxF_ext,prb_off,prb_off2); #endif - /* if (mimo_mode <= PUSCH_PRECODING1) - *pmi_loc = (pmi>>((prb>>2)<<1))&3; - else - *pmi_loc=(pmi>>prb)&1; - // printf("symbol_mod %d (pilots %d) rb %d, sb %d, pmi %d (pmi_loc %p,rxF %p, ch00 %p, ch01 %p, rxF_ext %p dl_ch0_ext %p dl_ch1_ext %p)\n",symbol_mod,pilots,prb,prb>>2,*pmi_loc,pmi_loc,rxF,dl_ch0, dl_ch1, rxF_ext,dl_ch0_ext,dl_ch1_ext); -*/ - *pmi_loc = get_pmi(frame_parms->N_RB_DL,mimo_mode,pmi,prb); + /* if (mimo_mode <= PUSCH_PRECODING1) + *pmi_loc = (pmi>>((prb>>2)<<1))&3; + else + *pmi_loc=(pmi>>prb)&1; + // printf("symbol_mod %d (pilots %d) rb %d, sb %d, pmi %d (pmi_loc %p,rxF %p, ch00 %p, ch01 %p, rxF_ext %p dl_ch0_ext %p dl_ch1_ext %p)\n",symbol_mod,pilots,prb,prb>>2,*pmi_loc,pmi_loc,rxF,dl_ch0, dl_ch1, rxF_ext,dl_ch0_ext,dl_ch1_ext); + */ + *pmi_loc = get_pmi(frame_parms->N_RB_DL,mimo_mode,pmi,prb); pmi_loc++; if (prb != (frame_parms->N_RB_DL>>1)) { // This PRB is not around DC @@ -5925,8 +5494,10 @@ unsigned short dlsch_extract_rbs_dual(int **rxdataF, memcpy(dl_ch1_ext,dl_ch1p,6*sizeof(int32_t)); memcpy(rxF_ext,rxF,6*sizeof(int32_t)); #ifdef DEBUG_DLSCH_DEMOD - for (i=0;i<6;i++) - printf("extract rb %d, re %d => (%d,%d)\n",prb,i,*(short *)&rxF_ext[i],*(1+(short*)&rxF_ext[i])); + + for (i=0; i<6; i++) + printf("extract rb %d, re %d => (%d,%d)\n",prb,i,*(short *)&rxF_ext[i],*(1+(short *)&rxF_ext[i])); + #endif dl_ch0_ext+=6; dl_ch1_ext+=6; @@ -5936,8 +5507,10 @@ unsigned short dlsch_extract_rbs_dual(int **rxdataF, memcpy(dl_ch1_ext,dl_ch1p+6,6*sizeof(int32_t)); memcpy(rxF_ext,rxF+6,6*sizeof(int32_t)); #ifdef DEBUG_DLSCH_DEMOD - for (i=0;i<6;i++) - printf("extract rb %d, re %d => (%d,%d)\n",prb,i,*(short *)&rxF_ext[i],*(1+(short*)&rxF_ext[i])); + + for (i=0; i<6; i++) + printf("extract rb %d, re %d => (%d,%d)\n",prb,i,*(short *)&rxF_ext[i],*(1+(short *)&rxF_ext[i])); + #endif dl_ch0_ext+=6; dl_ch1_ext+=6; @@ -5947,8 +5520,10 @@ unsigned short dlsch_extract_rbs_dual(int **rxdataF, memcpy(dl_ch1_ext,dl_ch1p,12*sizeof(int32_t)); memcpy(rxF_ext,rxF,12*sizeof(int32_t)); #ifdef DEBUG_DLSCH_DEMOD - for (i=0;i<12;i++) - printf("extract rb %d, re %d => (%d,%d)\n",prb,i,*(short *)&rxF_ext[i],*(1+(short*)&rxF_ext[i])); + + for (i=0; i<12; i++) + printf("extract rb %d, re %d => (%d,%d)\n",prb,i,*(short *)&rxF_ext[i],*(1+(short *)&rxF_ext[i])); + #endif dl_ch0_ext+=12; dl_ch1_ext+=12; @@ -5963,12 +5538,13 @@ unsigned short dlsch_extract_rbs_dual(int **rxdataF, (i!=((frame_parms->nushift+3)%6))) { rxF_ext[j]=rxF[i]; #ifdef DEBUG_DLSCH_DEMOD - printf("(pilots,skip1)extract rb %d, re %d (%d)=> (%d,%d)\n",prb,i,j,*(short *)&rxF_ext[j],*(1+(short*)&rxF_ext[j])); + printf("(pilots,skip1)extract rb %d, re %d (%d)=> (%d,%d)\n",prb,i,j,*(short *)&rxF_ext[j],*(1+(short *)&rxF_ext[j])); #endif dl_ch0_ext[j]=dl_ch0p[i]; dl_ch1_ext[j++]=dl_ch1p[i]; } } + dl_ch0_ext+=4; dl_ch1_ext+=4; rxF_ext+=4; @@ -5978,16 +5554,16 @@ unsigned short dlsch_extract_rbs_dual(int **rxdataF, (i!=((frame_parms->nushift+3)%6))) { rxF_ext[j]=rxF[(i+6)]; #ifdef DEBUG_DLSCH_DEMOD - printf("(pilots,skip2)extract rb %d, re %d (%d) => (%d,%d)\n",prb,i,j,*(short *)&rxF_ext[j],*(1+(short*)&rxF_ext[j])); + printf("(pilots,skip2)extract rb %d, re %d (%d) => (%d,%d)\n",prb,i,j,*(short *)&rxF_ext[j],*(1+(short *)&rxF_ext[j])); #endif dl_ch0_ext[j]=dl_ch0p[i+6]; dl_ch1_ext[j++]=dl_ch1p[i+6]; } } + dl_ch0_ext+=4; dl_ch1_ext+=4; rxF_ext+=4; - } else { //skip_half==0 for (i=0; i<12; i++) { if ((i!=frame_parms->nushift) && @@ -5996,43 +5572,45 @@ unsigned short dlsch_extract_rbs_dual(int **rxdataF, (i!=((frame_parms->nushift+9)%12))) { rxF_ext[j]=rxF[i]; #ifdef DEBUG_DLSCH_DEMOD - printf("(pilots)extract rb %d, re %d => (%d,%d)\n",prb,i,*(short *)&rxF_ext[j],*(1+(short*)&rxF_ext[j])); + printf("(pilots)extract rb %d, re %d => (%d,%d)\n",prb,i,*(short *)&rxF_ext[j],*(1+(short *)&rxF_ext[j])); #endif dl_ch0_ext[j] =dl_ch0p[i]; dl_ch1_ext[j++]=dl_ch1p[i]; } } + dl_ch0_ext+=8; dl_ch1_ext+=8; rxF_ext+=8; } //skip_half==0 } //pilots==1 } else { // Do middle RB (around DC) - if (pilots==0) { memcpy(dl_ch0_ext,dl_ch0p,6*sizeof(int32_t)); memcpy(dl_ch1_ext,dl_ch1p,6*sizeof(int32_t)); memcpy(rxF_ext,rxF,6*sizeof(int32_t)); #ifdef DEBUG_DLSCH_DEMOD + for (i=0; i<6; i++) { - printf("extract rb %d, re %d => (%d,%d)\n",prb,i,*(short *)&rxF_ext[i],*(1+(short*)&rxF_ext[i])); + printf("extract rb %d, re %d => (%d,%d)\n",prb,i,*(short *)&rxF_ext[i],*(1+(short *)&rxF_ext[i])); } + #endif rxF_ext+=6; dl_ch0_ext+=6; dl_ch1_ext+=6; dl_ch0p+=6; dl_ch1p+=6; - rxF = &rxdataF[aarx][1+((symbol*(frame_parms->ofdm_symbol_size)))]; - memcpy(dl_ch0_ext,dl_ch0p,6*sizeof(int32_t)); memcpy(dl_ch1_ext,dl_ch1p,6*sizeof(int32_t)); memcpy(rxF_ext,rxF,6*sizeof(int32_t)); #ifdef DEBUG_DLSCH_DEMOD + for (i=0; i<6; i++) { - printf("extract rb %d, re %d => (%d,%d)\n",prb,i,*(short *)&rxF_ext[i],*(1+(short*)&rxF_ext[i])); + printf("extract rb %d, re %d => (%d,%d)\n",prb,i,*(short *)&rxF_ext[i],*(1+(short *)&rxF_ext[i])); } + #endif rxF_ext+=6; dl_ch0_ext+=6; @@ -6047,10 +5625,11 @@ unsigned short dlsch_extract_rbs_dual(int **rxdataF, dl_ch1_ext[j]=dl_ch1p[i]; rxF_ext[j++]=rxF[i]; #ifdef DEBUG_DLSCH_DEMOD - printf("(pilots)extract rb %d, re %d (%d) => (%d,%d)\n",prb,i,j,*(short *)&rxF[i],*(1+(short*)&rxF[i])); + printf("(pilots)extract rb %d, re %d (%d) => (%d,%d)\n",prb,i,j,*(short *)&rxF[i],*(1+(short *)&rxF[i])); #endif } } + rxF = &rxdataF[aarx][1+symbol*(frame_parms->ofdm_symbol_size)]; for (; i<12; i++) { @@ -6060,7 +5639,7 @@ unsigned short dlsch_extract_rbs_dual(int **rxdataF, dl_ch1_ext[j]=dl_ch1p[i]; rxF_ext[j++]=rxF[i-6]; #ifdef DEBUG_DLSCH_DEMOD - printf("(pilots)extract rb %d, re %d (%d) => (%d,%d)\n",prb,i,j,*(short *)&rxF[1+i-6],*(1+(short*)&rxF[1+i-6])); + printf("(pilots)extract rb %d, re %d (%d) => (%d,%d)\n",prb,i,j,*(short *)&rxF[1+i-6],*(1+(short *)&rxF[1+i-6])); #endif } } @@ -6074,6 +5653,7 @@ unsigned short dlsch_extract_rbs_dual(int **rxdataF, } // if rballoc==1 } // for prb } // for aarx + return(nb_rb/frame_parms->nb_antennas_rx); } @@ -6085,26 +5665,22 @@ unsigned short dlsch_extract_rbs_TM7(int **rxdataF, unsigned char symbol, unsigned char subframe, uint32_t high_speed_flag, - LTE_DL_FRAME_PARMS *frame_parms) -{ - + LTE_DL_FRAME_PARMS *frame_parms) { unsigned short rb,nb_rb=0; unsigned char rb_alloc_ind; unsigned char i,aarx,l,nsymb,skip_half=0,sss_symb,pss_symb=0; int *dl_ch0,*dl_ch0_ext,*rxF,*rxF_ext; - unsigned char symbol_mod,pilots=0,uespec_pilots=0,j=0,poffset=0,uespec_poffset=0; int8_t uespec_nushift = frame_parms->Nid_cell%3; - symbol_mod = (symbol>=(7-frame_parms->Ncp)) ? symbol-(7-frame_parms->Ncp) : symbol; pilots = ((symbol_mod==0)||(symbol_mod==(4-frame_parms->Ncp))) ? 1 : 0; l=symbol; nsymb = (frame_parms->Ncp==NORMAL) ? 14:12; - if (frame_parms->Ncp==0){ + if (frame_parms->Ncp==0) { if (symbol==3 || symbol==6 || symbol==9 || symbol==12) uespec_pilots = 1; - } else{ + } else { if (symbol==4 || symbol==7 || symbol==10) uespec_pilots = 1; } @@ -6124,20 +5700,17 @@ unsigned short dlsch_extract_rbs_TM7(int **rxdataF, uespec_poffset=2; for (aarx=0; aarx<frame_parms->nb_antennas_rx; aarx++) { - if (high_speed_flag == 1) dl_ch0 = &dl_bf_ch_estimates[aarx][symbol*(frame_parms->ofdm_symbol_size)]; else dl_ch0 = &dl_bf_ch_estimates[aarx][0]; dl_ch0_ext = &dl_bf_ch_estimates_ext[aarx][symbol*(frame_parms->N_RB_DL*12)]; - rxF_ext = &rxdataF_ext[aarx][symbol*(frame_parms->N_RB_DL*12)]; rxF = &rxdataF[aarx][(frame_parms->first_carrier_offset + (symbol*(frame_parms->ofdm_symbol_size)))]; if ((frame_parms->N_RB_DL&1) == 0) // even number of RBs for (rb=0; rb<frame_parms->N_RB_DL; rb++) { - if (rb < 32) rb_alloc_ind = (rb_alloc[0]>>rb) & 1; else if (rb < 64) @@ -6149,7 +5722,7 @@ unsigned short dlsch_extract_rbs_TM7(int **rxdataF, else rb_alloc_ind = 0; - if (rb_alloc_ind == 1) + if (rb_alloc_ind == 1) nb_rb++; // For second half of RBs skip DC carrier @@ -6168,7 +5741,6 @@ unsigned short dlsch_extract_rbs_TM7(int **rxdataF, rb_alloc_ind = 0; } - if (frame_parms->frame_type == FDD) { //PSS if (((subframe==0)||(subframe==5)) && (rb>=((frame_parms->N_RB_DL>>1)-3)) && (rb<((frame_parms->N_RB_DL>>1)+3)) && (l==pss_symb) ) { @@ -6184,7 +5756,6 @@ unsigned short dlsch_extract_rbs_TM7(int **rxdataF, } if (rb_alloc_ind==1) { - /* printf("rb %d\n",rb); for (i=0;i<12;i++) @@ -6213,39 +5784,33 @@ unsigned short dlsch_extract_rbs_TM7(int **rxdataF, dl_ch0_ext+=10; rxF_ext+=10; - } else if (pilots==0 && uespec_pilots==1) { j=0; - - for (i=0; i<12; i++){ - if (frame_parms->Ncp==0){ - if (i!=uespec_nushift+uespec_poffset && i!=uespec_nushift+uespec_poffset+4 && i!=(uespec_nushift+uespec_poffset+8)%12){ - rxF_ext[j] = rxF[i]; + for (i=0; i<12; i++) { + if (frame_parms->Ncp==0) { + if (i!=uespec_nushift+uespec_poffset && i!=uespec_nushift+uespec_poffset+4 && i!=(uespec_nushift+uespec_poffset+8)%12) { + rxF_ext[j] = rxF[i]; dl_ch0_ext[j++]=dl_ch0[i]; } - } else{ - if (i!=uespec_nushift+uespec_poffset && i!=uespec_nushift+uespec_poffset+3 && i!=uespec_nushift+uespec_poffset+6 && i!=(uespec_nushift+uespec_poffset+9)%12){ - rxF_ext[j] = rxF[i]; + } else { + if (i!=uespec_nushift+uespec_poffset && i!=uespec_nushift+uespec_poffset+3 && i!=uespec_nushift+uespec_poffset+6 && i!=(uespec_nushift+uespec_poffset+9)%12) { + rxF_ext[j] = rxF[i]; dl_ch0_ext[j++]=dl_ch0[i]; } } - - } + } dl_ch0_ext+=9-frame_parms->Ncp; rxF_ext+=9-frame_parms->Ncp; - } else { LOG_E(PHY,"dlsch_extract_rbs_TM7(dl_demodulation.c):pilot or ue spec pilot detection error\n"); exit(-1); } - } dl_ch0+=12; rxF+=12; - } else { // Odd number of RBs for (rb=0; rb<frame_parms->N_RB_DL>>1; rb++) { @@ -6318,7 +5883,6 @@ unsigned short dlsch_extract_rbs_TM7(int **rxdataF, skip_half=2; } - if (rb_alloc_ind==1) { #ifdef DEBUG_DLSCH_DEMOD printf("rb %d/symbol %d pilots %d, uespec_pilots %d, (skip_half %d)\n",rb,l,pilots,uespec_pilots,skip_half); @@ -6326,14 +5890,13 @@ unsigned short dlsch_extract_rbs_TM7(int **rxdataF, if (pilots==0 && uespec_pilots==0) { //printf("Extracting w/o pilots (symbol %d, rb %d, skip_half %d)\n",l,rb,skip_half); - if (skip_half==1) { memcpy(dl_ch0_ext,dl_ch0,6*sizeof(int)); for (i=0; i<6; i++) { rxF_ext[i]=rxF[i]; #ifdef DEBUG_DLSCH_DEMOD - printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short*)&rxF_ext[i])); + printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short *)&rxF_ext[i])); #endif } @@ -6345,7 +5908,7 @@ unsigned short dlsch_extract_rbs_TM7(int **rxdataF, for (i=0; i<6; i++) { rxF_ext[i]=rxF[(i+6)]; #ifdef DEBUG_DLSCH_DEMOD - printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short*)&rxF_ext[i])); + printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short *)&rxF_ext[i])); #endif } @@ -6354,12 +5917,13 @@ unsigned short dlsch_extract_rbs_TM7(int **rxdataF, } else { memcpy(dl_ch0_ext,dl_ch0,12*sizeof(int)); - for (i=0; i<12; i++){ + for (i=0; i<12; i++) { rxF_ext[i]=rxF[i]; #ifdef DEBUG_DLSCH_DEMOD - printf("extract rb %d, re %d => (%d,%d)\n",symbol,rb,i,*(short *)&rxF[i],*(1+(short*)&rxF[i])); + printf("extract symbol %d rb %d, re %d => (%d,%d)\n",symbol,rb,i,*(short *)&rxF[i],*(1+(short *)&rxF[i])); #endif } + dl_ch0_ext+=12; rxF_ext+=12; } @@ -6373,7 +5937,7 @@ unsigned short dlsch_extract_rbs_TM7(int **rxdataF, rxF_ext[j]=rxF[i]; dl_ch0_ext[j++]=dl_ch0[i]; #ifdef DEBUG_DLSCH_DEMOD - printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short*)&rxF_ext[i])); + printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short *)&rxF_ext[i])); #endif } } @@ -6386,7 +5950,7 @@ unsigned short dlsch_extract_rbs_TM7(int **rxdataF, rxF_ext[j]=rxF[(i+6)]; dl_ch0_ext[j++]=dl_ch0[i+6]; #ifdef DEBUG_DLSCH_DEMOD - printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short*)&rxF_ext[i])); + printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short *)&rxF_ext[i])); #endif } } @@ -6399,107 +5963,103 @@ unsigned short dlsch_extract_rbs_TM7(int **rxdataF, (i!=((frame_parms->nushift+poffset+6)%12))) { rxF_ext[j]=rxF[i]; #ifdef DEBUG_DLSCH_DEMOD - printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[j],*(1+(short*)&rxF_ext[j])); + printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[j],*(1+(short *)&rxF_ext[j])); #endif dl_ch0_ext[j++]=dl_ch0[i]; - } } dl_ch0_ext+=10; rxF_ext+=10; } - } else if(pilots==0 && uespec_pilots==1){ + } else if(pilots==0 && uespec_pilots==1) { //printf("Extracting with uespec pilots (symbol %d, rb %d, skip_half %d)\n",l,rb,skip_half); j=0; if (skip_half==1) { - if (frame_parms->Ncp==0){ + if (frame_parms->Ncp==0) { for (i=0; i<6; i++) { - if (i!=uespec_nushift+uespec_poffset && i!=uespec_nushift+uespec_poffset+4 && i!=(uespec_nushift+uespec_poffset+8)%12){ + if (i!=uespec_nushift+uespec_poffset && i!=uespec_nushift+uespec_poffset+4 && i!=(uespec_nushift+uespec_poffset+8)%12) { rxF_ext[j]=rxF[i]; dl_ch0_ext[j++]=dl_ch0[i]; #ifdef DEBUG_DLSCH_DEMOD - printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short*)&rxF_ext[i])); + printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short *)&rxF_ext[i])); #endif } } + dl_ch0_ext+=6-(uespec_nushift+uespec_poffset<6)-(uespec_nushift+uespec_poffset+4<6)-((uespec_nushift+uespec_poffset+8)%12<6); rxF_ext+=6-(uespec_nushift+uespec_poffset<6)-(uespec_nushift+uespec_poffset+4<6)-((uespec_nushift+uespec_poffset+8)%12<6); - - } else{ + } else { for (i=0; i<6; i++) { - if (i!=uespec_nushift+uespec_poffset && i!=uespec_nushift+uespec_poffset+3 && i!=uespec_nushift+uespec_poffset+6 && i!=(uespec_nushift+uespec_poffset+9)%12){ + if (i!=uespec_nushift+uespec_poffset && i!=uespec_nushift+uespec_poffset+3 && i!=uespec_nushift+uespec_poffset+6 && i!=(uespec_nushift+uespec_poffset+9)%12) { rxF_ext[j]=rxF[i]; dl_ch0_ext[j++]=dl_ch0[i]; #ifdef DEBUG_DLSCH_DEMOD - printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short*)&rxF_ext[i])); + printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short *)&rxF_ext[i])); #endif } } + dl_ch0_ext+=4; rxF_ext+=4; } - } else if (skip_half==2) { - if(frame_parms->Ncp==0){ + if(frame_parms->Ncp==0) { for (i=0; i<6; i++) { - if (i!=uespec_nushift+uespec_poffset && i!=uespec_nushift+uespec_poffset+4 && i!=(uespec_nushift+uespec_poffset+8)%12){ + if (i!=uespec_nushift+uespec_poffset && i!=uespec_nushift+uespec_poffset+4 && i!=(uespec_nushift+uespec_poffset+8)%12) { rxF_ext[j]=rxF[(i+6)]; dl_ch0_ext[j++]=dl_ch0[i+6]; #ifdef DEBUG_DLSCH_DEMOD - printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short*)&rxF_ext[i])); + printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short *)&rxF_ext[i])); #endif } } + dl_ch0_ext+=6-(uespec_nushift+uespec_poffset>6)-(uespec_nushift+uespec_poffset+4>6)-((uespec_nushift+uespec_poffset+8)%12>6); rxF_ext+=6-(uespec_nushift+uespec_poffset>6)-(uespec_nushift+uespec_poffset+4>6)-((uespec_nushift+uespec_poffset+8)%12>6); - } else { for (i=0; i<6; i++) { - if (i!=uespec_nushift+uespec_poffset && i!=uespec_nushift+uespec_poffset+3 && i!=uespec_nushift+uespec_poffset+6 && i!=(uespec_nushift+uespec_poffset+9)%12){ + if (i!=uespec_nushift+uespec_poffset && i!=uespec_nushift+uespec_poffset+3 && i!=uespec_nushift+uespec_poffset+6 && i!=(uespec_nushift+uespec_poffset+9)%12) { rxF_ext[j]=rxF[(i+6)]; dl_ch0_ext[j++]=dl_ch0[i+6]; #ifdef DEBUG_DLSCH_DEMOD - printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short*)&rxF_ext[i])); + printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short *)&rxF_ext[i])); #endif } } + dl_ch0_ext+=4; rxF_ext+=4; } - } else { - - for (i=0; i<12; i++){ - if (frame_parms->Ncp==0){ - if (i!=uespec_nushift+uespec_poffset && i!=uespec_nushift+uespec_poffset+4 && i!=(uespec_nushift+uespec_poffset+8)%12){ - rxF_ext[j] = rxF[i]; + for (i=0; i<12; i++) { + if (frame_parms->Ncp==0) { + if (i!=uespec_nushift+uespec_poffset && i!=uespec_nushift+uespec_poffset+4 && i!=(uespec_nushift+uespec_poffset+8)%12) { + rxF_ext[j] = rxF[i]; dl_ch0_ext[j++] = dl_ch0[i]; #ifdef DEBUG_DLSCH_DEMOD - printf("extract rb %d, re %d, j %d => (%d,%d)\n",symbol,rb,i,j-1,*(short *)&dl_ch0[j],*(1+(short*)&dl_ch0[i])); + printf("extract symbol %d, rb %d, re %d, j %d => (%d,%d)\n", + symbol,rb,i,j-1,*(short *)&dl_ch0[j],*(1+(short *)&dl_ch0[i])); #endif } - } else{ - if (i!=uespec_nushift+uespec_poffset && i!=uespec_nushift+uespec_poffset+3 && i!=uespec_nushift+uespec_poffset+6 && i!=(uespec_nushift+uespec_poffset+9)%12){ - rxF_ext[j] = rxF[i]; + } else { + if (i!=uespec_nushift+uespec_poffset && i!=uespec_nushift+uespec_poffset+3 && i!=uespec_nushift+uespec_poffset+6 && i!=(uespec_nushift+uespec_poffset+9)%12) { + rxF_ext[j] = rxF[i]; dl_ch0_ext[j++]=dl_ch0[i]; #ifdef DEBUG_DLSCH_DEMOD - printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short*)&rxF_ext[i])); + printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short *)&rxF_ext[i])); #endif } } - - } + } dl_ch0_ext+=9-frame_parms->Ncp; rxF_ext+=9-frame_parms->Ncp; - } - + } } else { LOG_E(PHY,"dlsch_extract_rbs_TM7(dl_demodulation.c):pilot or ue spec pilot detection error\n"); exit(-1); - } } @@ -6507,7 +6067,6 @@ unsigned short dlsch_extract_rbs_TM7(int **rxdataF, rxF+=12; } // first half loop - // Do middle RB (around DC) if (rb < 32) rb_alloc_ind = (rb_alloc[0]>>rb) & 1; @@ -6556,7 +6115,7 @@ unsigned short dlsch_extract_rbs_TM7(int **rxdataF, dl_ch0_ext[i]=dl_ch0[i]; rxF_ext[i]=rxF[i]; #ifdef DEBUG_DLSCH_DEMOD - printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short*)&rxF_ext[i])); + printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short *)&rxF_ext[i])); #endif } @@ -6566,13 +6125,13 @@ unsigned short dlsch_extract_rbs_TM7(int **rxdataF, dl_ch0_ext[i]=dl_ch0[i]; rxF_ext[i]=rxF[(1+i-6)]; #ifdef DEBUG_DLSCH_DEMOD - printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short*)&rxF_ext[i])); + printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short *)&rxF_ext[i])); #endif } dl_ch0_ext+=12; rxF_ext+=12; - } else if(pilots==1 && uespec_pilots==0){ // pilots==1 + } else if(pilots==1 && uespec_pilots==0) { // pilots==1 j=0; for (i=0; i<6; i++) { @@ -6580,7 +6139,7 @@ unsigned short dlsch_extract_rbs_TM7(int **rxdataF, dl_ch0_ext[j]=dl_ch0[i]; rxF_ext[j++]=rxF[i]; #ifdef DEBUG_DLSCH_DEMOD - printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short*)&rxF_ext[i])); + printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short *)&rxF_ext[i])); #endif } } @@ -6592,7 +6151,7 @@ unsigned short dlsch_extract_rbs_TM7(int **rxdataF, dl_ch0_ext[j]=dl_ch0[i]; rxF_ext[j++]=rxF[(1+i-6)]; #ifdef DEBUG_DLSCH_DEMOD - printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short*)&rxF_ext[i])); + printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short *)&rxF_ext[i])); #endif } } @@ -6602,43 +6161,43 @@ unsigned short dlsch_extract_rbs_TM7(int **rxdataF, } else if(pilots==0 && uespec_pilots==1) { j=0; - for (i=0; i<6; i++) { - if (frame_parms->Ncp==0){ - if (i!=uespec_nushift+uespec_poffset && i!=uespec_nushift+uespec_poffset+4 && i!=(uespec_nushift+uespec_poffset+8)%12){ + for (i=0; i<6; i++) { + if (frame_parms->Ncp==0) { + if (i!=uespec_nushift+uespec_poffset && i!=uespec_nushift+uespec_poffset+4 && i!=(uespec_nushift+uespec_poffset+8)%12) { dl_ch0_ext[j]=dl_ch0[i]; - rxF_ext[j++] = rxF[i]; + rxF_ext[j++] = rxF[i]; #ifdef DEBUG_DLSCH_DEMOD - printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short*)&rxF_ext[i])); + printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short *)&rxF_ext[i])); #endif } } else { - if (i!=uespec_nushift+uespec_poffset && i!=uespec_nushift+uespec_poffset+3 && i!=uespec_nushift+uespec_poffset+6 && i!=(uespec_nushift+uespec_poffset+9)%12){ + if (i!=uespec_nushift+uespec_poffset && i!=uespec_nushift+uespec_poffset+3 && i!=uespec_nushift+uespec_poffset+6 && i!=(uespec_nushift+uespec_poffset+9)%12) { dl_ch0_ext[j]=dl_ch0[i]; - rxF_ext[j++] = rxF[i]; + rxF_ext[j++] = rxF[i]; #ifdef DEBUG_DLSCH_DEMOD - printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short*)&rxF_ext[i])); + printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short *)&rxF_ext[i])); #endif } } - } + } rxF = &rxdataF[aarx][((symbol*(frame_parms->ofdm_symbol_size)))]; for (; i<12; i++) { - if (frame_parms->Ncp==0){ - if (i!=uespec_nushift+uespec_poffset && i!=uespec_nushift+uespec_poffset+4 && i!=(uespec_nushift+uespec_poffset+8)%12){ + if (frame_parms->Ncp==0) { + if (i!=uespec_nushift+uespec_poffset && i!=uespec_nushift+uespec_poffset+4 && i!=(uespec_nushift+uespec_poffset+8)%12) { dl_ch0_ext[j]=dl_ch0[i]; rxF_ext[j++]=rxF[(1+i-6)]; #ifdef DEBUG_DLSCH_DEMOD - printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short*)&rxF_ext[i])); + printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short *)&rxF_ext[i])); #endif } } else { - if (i!=uespec_nushift+uespec_poffset && i!=uespec_nushift+uespec_poffset+3 && i!=uespec_nushift+uespec_poffset+6 && i!=(uespec_nushift+uespec_poffset+9)%12){ + if (i!=uespec_nushift+uespec_poffset && i!=uespec_nushift+uespec_poffset+3 && i!=uespec_nushift+uespec_poffset+6 && i!=(uespec_nushift+uespec_poffset+9)%12) { dl_ch0_ext[j]=dl_ch0[i]; - rxF_ext[j++] = rxF[(1+i-6)]; + rxF_ext[j++] = rxF[(1+i-6)]; #ifdef DEBUG_DLSCH_DEMOD - printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short*)&rxF_ext[i])); + printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short *)&rxF_ext[i])); #endif } } @@ -6646,9 +6205,7 @@ unsigned short dlsch_extract_rbs_TM7(int **rxdataF, dl_ch0_ext+=9-frame_parms->Ncp; rxF_ext+=9-frame_parms->Ncp; - - }// symbol_mod==0 - + }// symbol_mod==0 } // rballoc==1 else { rxF = &rxdataF[aarx][((symbol*(frame_parms->ofdm_symbol_size)))]; @@ -6724,8 +6281,9 @@ unsigned short dlsch_extract_rbs_TM7(int **rxdataF, if (rb_alloc_ind==1) { #ifdef DEBUG_DLSCH_DEMOD - printf("rb %d/symbol %d (skip_half %d)\n",rb,l,skip_half); + printf("rb %d/symbol %d (skip_half %d)\n",rb,l,skip_half); #endif + /* printf("rb %d\n",rb); for (i=0;i<12;i++) @@ -6740,26 +6298,24 @@ unsigned short dlsch_extract_rbs_TM7(int **rxdataF, for (i=0; i<6; i++) { rxF_ext[i]=rxF[i]; #ifdef DEBUG_DLSCH_DEMOD - printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short*)&rxF_ext[i])); + printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short *)&rxF_ext[i])); #endif } dl_ch0_ext+=6; rxF_ext+=6; - } else if (skip_half==2) { memcpy(dl_ch0_ext,dl_ch0+6,6*sizeof(int)); for (i=0; i<6; i++) { rxF_ext[i]=rxF[i+6]; #ifdef DEBUG_DLSCH_DEMOD - printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short*)&rxF_ext[i])); + printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short *)&rxF_ext[i])); #endif } dl_ch0_ext+=6; rxF_ext+=6; - } else { memcpy(dl_ch0_ext,dl_ch0,12*sizeof(int)); //printf("symbol %d, extract rb %d, => (%d,%d)\n",symbol,rb,*(short *)&dl_ch0[j],*(1+(short*)&dl_ch0[i])); @@ -6767,14 +6323,14 @@ unsigned short dlsch_extract_rbs_TM7(int **rxdataF, for (i=0; i<12; i++) { rxF_ext[i]=rxF[i]; #ifdef DEBUG_DLSCH_DEMOD - printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short*)&rxF_ext[i])); + printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short *)&rxF_ext[i])); #endif } dl_ch0_ext+=12; rxF_ext+=12; } - } else if (pilots==1 && uespec_pilots==0){ + } else if (pilots==1 && uespec_pilots==0) { //printf("Extracting with pilots (symbol %d, rb %d, skip_half %d)\n",l,rb,skip_half); j=0; @@ -6784,7 +6340,7 @@ unsigned short dlsch_extract_rbs_TM7(int **rxdataF, rxF_ext[j]=rxF[i]; dl_ch0_ext[j++]=dl_ch0[i]; #ifdef DEBUG_DLSCH_DEMOD - printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short*)&rxF_ext[i])); + printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short *)&rxF_ext[i])); #endif } } @@ -6797,7 +6353,7 @@ unsigned short dlsch_extract_rbs_TM7(int **rxdataF, rxF_ext[j]=rxF[(i+6)]; dl_ch0_ext[j++]=dl_ch0[i+6]; #ifdef DEBUG_DLSCH_DEMOD - printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short*)&rxF_ext[i])); + printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short *)&rxF_ext[i])); #endif } } @@ -6810,7 +6366,7 @@ unsigned short dlsch_extract_rbs_TM7(int **rxdataF, (i!=((frame_parms->nushift+poffset+6)%12))) { rxF_ext[j]=rxF[i]; #ifdef DEBUG_DLSCH_DEMOD - printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[j],*(1+(short*)&rxF_ext[j])); + printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[j],*(1+(short *)&rxF_ext[j])); #endif dl_ch0_ext[j++]=dl_ch0[i]; } @@ -6823,87 +6379,85 @@ unsigned short dlsch_extract_rbs_TM7(int **rxdataF, j=0; if (skip_half==1) { - if (frame_parms->Ncp==0){ + if (frame_parms->Ncp==0) { for (i=0; i<6; i++) { - if (i!=uespec_nushift+uespec_poffset && i!=uespec_nushift+uespec_poffset+4 && i!=(uespec_nushift+uespec_poffset+8)%12){ + if (i!=uespec_nushift+uespec_poffset && i!=uespec_nushift+uespec_poffset+4 && i!=(uespec_nushift+uespec_poffset+8)%12) { rxF_ext[j]=rxF[i]; dl_ch0_ext[j++]=dl_ch0[i]; #ifdef DEBUG_DLSCH_DEMOD - printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short*)&rxF_ext[i])); + printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short *)&rxF_ext[i])); #endif } } + dl_ch0_ext+=6-(uespec_nushift+uespec_poffset<6)-(uespec_nushift+uespec_poffset+4<6)-((uespec_nushift+uespec_poffset+8)%12<6); rxF_ext+=6-(uespec_nushift+uespec_poffset<6)-(uespec_nushift+uespec_poffset+4<6)-((uespec_nushift+uespec_poffset+8)%12<6); - - } else{ + } else { for (i=0; i<6; i++) { - if (i!=uespec_nushift+uespec_poffset && i!=uespec_nushift+uespec_poffset+3 && i!=uespec_nushift+uespec_poffset+6 && i!=(uespec_nushift+uespec_poffset+9)%12){ + if (i!=uespec_nushift+uespec_poffset && i!=uespec_nushift+uespec_poffset+3 && i!=uespec_nushift+uespec_poffset+6 && i!=(uespec_nushift+uespec_poffset+9)%12) { rxF_ext[j]=rxF[i]; dl_ch0_ext[j++]=dl_ch0[i]; #ifdef DEBUG_DLSCH_DEMOD - printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short*)&rxF_ext[i])); + printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short *)&rxF_ext[i])); #endif } } + dl_ch0_ext+=4; rxF_ext+=4; } - } else if (skip_half==2) { - if(frame_parms->Ncp==0){ + if(frame_parms->Ncp==0) { for (i=0; i<6; i++) { - if (i!=uespec_nushift+uespec_poffset && i!=uespec_nushift+uespec_poffset+4 && i!=(uespec_nushift+uespec_poffset+8)%12){ + if (i!=uespec_nushift+uespec_poffset && i!=uespec_nushift+uespec_poffset+4 && i!=(uespec_nushift+uespec_poffset+8)%12) { rxF_ext[j]=rxF[i+6]; dl_ch0_ext[j++]=dl_ch0[i+6]; #ifdef DEBUG_DLSCH_DEMOD - printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short*)&rxF_ext[i])); + printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short *)&rxF_ext[i])); #endif } } + dl_ch0_ext+=6-(uespec_nushift+uespec_poffset>6)-(uespec_nushift+uespec_poffset+4>6)-((uespec_nushift+uespec_poffset+8)%12>6); rxF_ext+=6-(uespec_nushift+uespec_poffset>6)-(uespec_nushift+uespec_poffset+4>6)-((uespec_nushift+uespec_poffset+8)%12>6); - } else { for (i=0; i<6; i++) { - if (i!=uespec_nushift+uespec_poffset && i!=uespec_nushift+uespec_poffset+3 && i!=uespec_nushift+uespec_poffset+6 && i!=(uespec_nushift+uespec_poffset+9)%12){ + if (i!=uespec_nushift+uespec_poffset && i!=uespec_nushift+uespec_poffset+3 && i!=uespec_nushift+uespec_poffset+6 && i!=(uespec_nushift+uespec_poffset+9)%12) { rxF_ext[j]=rxF[(i+6)]; dl_ch0_ext[j++]=dl_ch0[i+6]; #ifdef DEBUG_DLSCH_DEMOD - printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short*)&rxF_ext[i])); + printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short *)&rxF_ext[i])); #endif } } + dl_ch0_ext+=4; rxF_ext+=4; } - } else { - for (i=0; i<12; i++){ - if (frame_parms->Ncp==0){ - if (i!=uespec_nushift+uespec_poffset && i!=uespec_nushift+uespec_poffset+4 && i!=(uespec_nushift+uespec_poffset+8)%12){ - rxF_ext[j] = rxF[i]; + for (i=0; i<12; i++) { + if (frame_parms->Ncp==0) { + if (i!=uespec_nushift+uespec_poffset && i!=uespec_nushift+uespec_poffset+4 && i!=(uespec_nushift+uespec_poffset+8)%12) { + rxF_ext[j] = rxF[i]; dl_ch0_ext[j++]=dl_ch0[i]; #ifdef DEBUG_DLSCH_DEMOD - printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short*)&rxF_ext[i])); + printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short *)&rxF_ext[i])); #endif } - } else{ - if (i!=uespec_nushift+uespec_poffset && i!=uespec_nushift+uespec_poffset+3 && i!=uespec_nushift+uespec_poffset+6 && i!=(uespec_nushift+uespec_poffset+9)%12){ - rxF_ext[j] = rxF[i]; + } else { + if (i!=uespec_nushift+uespec_poffset && i!=uespec_nushift+uespec_poffset+3 && i!=uespec_nushift+uespec_poffset+6 && i!=(uespec_nushift+uespec_poffset+9)%12) { + rxF_ext[j] = rxF[i]; dl_ch0_ext[j++]=dl_ch0[i]; #ifdef DEBUG_DLSCH_DEMOD - printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short*)&rxF_ext[i])); + printf("extract rb %d, re %d => (%d,%d)\n",rb,i,*(short *)&rxF_ext[i],*(1+(short *)&rxF_ext[i])); #endif } } - } + } dl_ch0_ext+=9-frame_parms->Ncp; rxF_ext+=9-frame_parms->Ncp; - } - }// pilots=0 } @@ -6915,17 +6469,14 @@ unsigned short dlsch_extract_rbs_TM7(int **rxdataF, _mm_empty(); _m_empty(); - return(nb_rb/frame_parms->nb_antennas_rx); } //============================================================================================== -void dump_dlsch2(PHY_VARS_UE *ue,uint8_t eNB_id,uint8_t subframe,unsigned int *coded_bits_per_codeword,int round, unsigned char harq_pid) -{ +void dump_dlsch2(PHY_VARS_UE *ue,uint8_t eNB_id,uint8_t subframe,unsigned int *coded_bits_per_codeword,int round, unsigned char harq_pid) { #define NSYMB ((ue->frame_parms.Ncp == 0) ? 14 : 12) char fname[32],vname[32]; - sprintf(fname,"dlsch%d_rxF_r%d_ext0.m",eNB_id,round); sprintf(vname,"dl%d_rxF_r%d_ext0",eNB_id,round); LOG_M(fname,vname,ue->pdsch_vars[ue->current_thread_id[subframe]][eNB_id]->rxdataF_ext[0], @@ -6943,12 +6494,11 @@ void dump_dlsch2(PHY_VARS_UE *ue,uint8_t eNB_id,uint8_t subframe,unsigned int *c LOG_M(fname,vname,ue->pdsch_vars[ue->current_thread_id[subframe]][eNB_id]->dl_ch_estimates_ext[0], 12*(ue->frame_parms.N_RB_DL)*NSYMB,1,1); - if (ue->transmission_mode[eNB_id]==7){ + if (ue->transmission_mode[eNB_id]==7) { sprintf(fname,"dlsch%d_bf_ch_r%d.m",eNB_id,round); sprintf(vname,"dl%d_bf_ch_r%d",eNB_id,round); LOG_M(fname,vname,ue->pdsch_vars[ue->current_thread_id[subframe]][eNB_id]->dl_bf_ch_estimates[0],512*NSYMB,1,1); //LOG_M(fname,vname,phy_vars_ue->lte_ue_pdsch_vars[eNB_id]->dl_bf_ch_estimates[0],512,1,1); - sprintf(fname,"dlsch%d_bf_ch_r%d_ext00.m",eNB_id,round); sprintf(vname,"dl%d_bf_ch_r%d_ext00",eNB_id,round); LOG_M(fname,vname,ue->pdsch_vars[ue->current_thread_id[subframe]][eNB_id]->dl_bf_ch_estimates_ext[0], @@ -6958,8 +6508,8 @@ void dump_dlsch2(PHY_VARS_UE *ue,uint8_t eNB_id,uint8_t subframe,unsigned int *c if (ue->frame_parms.nb_antennas_rx == 2) { sprintf(fname,"dlsch%d_ch_r%d_ext01.m",eNB_id,round); sprintf(vname,"dl%d_ch_r%d_ext01",eNB_id,round); - LOG_M(fname,vname,ue->pdsch_vars[ue->current_thread_id[subframe]][eNB_id]->dl_ch_estimates_ext[1], - 12*(ue->frame_parms.N_RB_DL)*NSYMB,1,1); + LOG_M(fname,vname,ue->pdsch_vars[ue->current_thread_id[subframe]][eNB_id]->dl_ch_estimates_ext[1], + 12*(ue->frame_parms.N_RB_DL)*NSYMB,1,1); } if (ue->frame_parms.nb_antenna_ports_eNB == 2) { @@ -6980,7 +6530,6 @@ void dump_dlsch2(PHY_VARS_UE *ue,uint8_t eNB_id,uint8_t subframe,unsigned int *c sprintf(vname,"dl%d_rxF_r%d_uespec0",eNB_id,round); LOG_M(fname,vname,ue->pdsch_vars[ue->current_thread_id[subframe]][eNB_id]->rxdataF_uespec_pilots[0], 12*(ue->frame_parms.N_RB_DL)*NSYMB,1,1); - /* LOG_M("dlsch%d_ch_ext01.m","dl01_ch0_ext",pdsch_vars[eNB_id]->dl_ch_estimates_ext[1],12*N_RB_DL*NSYMB,1,1); LOG_M("dlsch%d_ch_ext10.m","dl10_ch0_ext",pdsch_vars[eNB_id]->dl_ch_estimates_ext[2],12*N_RB_DL*NSYMB,1,1); @@ -6988,20 +6537,17 @@ void dump_dlsch2(PHY_VARS_UE *ue,uint8_t eNB_id,uint8_t subframe,unsigned int *c */ sprintf(fname,"dlsch%d_r%d_rho.m",eNB_id,round); sprintf(vname,"dl_rho_r%d_%d",eNB_id,round); - LOG_M(fname,vname,ue->pdsch_vars[ue->current_thread_id[subframe]][eNB_id]->dl_ch_rho_ext[harq_pid][round][0], 12*(ue->frame_parms.N_RB_DL)*NSYMB,1,1); - sprintf(fname,"dlsch%d_r%d_rho2.m",eNB_id,round); sprintf(vname,"dl_rho2_r%d_%d",eNB_id,round); - LOG_M(fname,vname,ue->pdsch_vars[ue->current_thread_id[subframe]][eNB_id]->dl_ch_rho2_ext[0], 12*(ue->frame_parms.N_RB_DL)*NSYMB,1,1); - sprintf(fname,"dlsch%d_rxF_r%d_comp0.m",eNB_id,round); sprintf(vname,"dl%d_rxF_r%d_comp0",eNB_id,round); LOG_M(fname,vname,ue->pdsch_vars[ue->current_thread_id[subframe]][eNB_id]->rxdataF_comp0[0], 12*(ue->frame_parms.N_RB_DL)*NSYMB,1,1); + if (ue->frame_parms.nb_antenna_ports_eNB == 2) { sprintf(fname,"dlsch%d_rxF_r%d_comp1.m",eNB_id,round); sprintf(vname,"dl%d_rxF_r%d_comp1",eNB_id,round); @@ -7015,12 +6561,11 @@ void dump_dlsch2(PHY_VARS_UE *ue,uint8_t eNB_id,uint8_t subframe,unsigned int *c sprintf(fname,"dlsch%d_r%d_mag1.m",eNB_id,round); sprintf(vname,"dl%d_r%d_mag1",eNB_id,round); LOG_M(fname,vname,ue->pdsch_vars[ue->current_thread_id[subframe]][eNB_id]->dl_ch_mag0[0], - 12*(ue->frame_parms.N_RB_DL)*NSYMB,1,1); + 12*(ue->frame_parms.N_RB_DL)*NSYMB,1,1); sprintf(fname,"dlsch%d_r%d_mag2.m",eNB_id,round); sprintf(vname,"dl%d_r%d_mag2",eNB_id,round); LOG_M(fname,vname,ue->pdsch_vars[ue->current_thread_id[subframe]][eNB_id]->dl_ch_magb0[0], 12*(ue->frame_parms.N_RB_DL)*NSYMB,1,1); - } diff --git a/openair1/PHY/LTE_UE_TRANSPORT/ulsch_coding.c b/openair1/PHY/LTE_UE_TRANSPORT/ulsch_coding.c index b62c5c55449cc351fc1540e42d6175e2a2517c18..cc1f762e7046b9836d0c898d6c459afd9f34cb89 100644 --- a/openair1/PHY/LTE_UE_TRANSPORT/ulsch_coding.c +++ b/openair1/PHY/LTE_UE_TRANSPORT/ulsch_coding.c @@ -80,7 +80,6 @@ void free_ue_ulsch(LTE_UE_ULSCH_t *ulsch) } } free16(ulsch,sizeof(LTE_UE_ULSCH_t)); - ulsch = NULL; } } diff --git a/openair1/PHY/MODULATION/compute_bf_weights.c b/openair1/PHY/MODULATION/compute_bf_weights.c index 89d76058e6d2b1859124a14408704403fc9f778b..5c132062977ac574295022e232183738016013c9 100644 --- a/openair1/PHY/MODULATION/compute_bf_weights.c +++ b/openair1/PHY/MODULATION/compute_bf_weights.c @@ -22,6 +22,7 @@ int f_read(char *calibF_fname, int nb_ant, int nb_freq, int32_t **tdd_calib_coef } printf("%d\n",(int)tdd_calib_coeffs[0][0]); printf("%d\n",(int)tdd_calib_coeffs[1][599]); + fclose(calibF_fd); } else printf("%s not found, running with defaults\n",calibF_fname); /* TODO: what to return? is this code used at all? */ diff --git a/openair1/PHY/MODULATION/slot_fep.c b/openair1/PHY/MODULATION/slot_fep.c index b01979431dcf88212604aa71cf0d0470eb177d06..58cd46a73ffa6760b6c363f5ded012f7f590b160 100644 --- a/openair1/PHY/MODULATION/slot_fep.c +++ b/openair1/PHY/MODULATION/slot_fep.c @@ -33,9 +33,7 @@ int slot_fep(PHY_VARS_UE *ue, unsigned char Ns, int sample_offset, int no_prefix, - int reset_freq_est) -{ - + int reset_freq_est) { LTE_DL_FRAME_PARMS *frame_parms = &ue->frame_parms; LTE_UE_COMMON *common_vars = &ue->common_vars; uint8_t eNB_id = 0;//ue_common_vars->eNb_id; @@ -48,43 +46,41 @@ int slot_fep(PHY_VARS_UE *ue, int i; unsigned int frame_length_samples = frame_parms->samples_per_tti * 10; unsigned int rx_offset; - /*LTE_UE_DLSCH_t **dlsch_ue = phy_vars_ue->dlsch_ue[eNB_id]; - unsigned char harq_pid = dlsch_ue[0]->current_harq_pid; + unsigned char harq_pid = dlsch_ue[0]->current_harq_pid; LTE_DL_UE_HARQ_t *dlsch0_harq = dlsch_ue[0]->harq_processes[harq_pid]; int uespec_pilot[9][1200];*/ - void (*dft)(int16_t *,int16_t *, int); int tmp_dft_in[2048] __attribute__ ((aligned (32))); // This is for misalignment issues for 6 and 15 PRBs switch (frame_parms->ofdm_symbol_size) { - case 128: - dft = dft128; - break; + case 128: + dft = dft128; + break; - case 256: - dft = dft256; - break; + case 256: + dft = dft256; + break; - case 512: - dft = dft512; - break; + case 512: + dft = dft512; + break; - case 1024: - dft = dft1024; - break; + case 1024: + dft = dft1024; + break; - case 1536: - dft = dft1536; - break; + case 1536: + dft = dft1536; + break; - case 2048: - dft = dft2048; - break; + case 2048: + dft = dft2048; + break; - default: - dft = dft512; - break; + default: + dft = dft512; + break; } if (no_prefix) { @@ -97,7 +93,6 @@ int slot_fep(PHY_VARS_UE *ue, // subframe_offset_F = frame_parms->ofdm_symbol_size * frame_parms->symbols_per_tti * (Ns>>1); - if (l<0 || l>=7-frame_parms->Ncp) { printf("slot_fep: l must be between 0 and %d\n",7-frame_parms->Ncp); return(-1); @@ -108,17 +103,13 @@ int slot_fep(PHY_VARS_UE *ue, return(-1); } - - for (aa=0; aa<frame_parms->nb_antennas_rx; aa++) { memset(&common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[Ns>>1]].rxdataF[aa][frame_parms->ofdm_symbol_size*symbol],0,frame_parms->ofdm_symbol_size*sizeof(int)); - rx_offset = sample_offset + slot_offset + nb_prefix_samples0 + subframe_offset - SOFFSET; // Align with 256 bit // rx_offset = rx_offset&0xfffffff8; if (l==0) { - if (rx_offset > (frame_length_samples - frame_parms->ofdm_symbol_size)) memcpy((short *)&common_vars->rxdata[aa][frame_length_samples], (short *)&common_vars->rxdata[aa][0], @@ -132,30 +123,29 @@ int slot_fep(PHY_VARS_UE *ue, (int16_t *)&common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[Ns>>1]].rxdataF[aa][frame_parms->ofdm_symbol_size*symbol],1); } else { // use dft input from RX buffer directly #if UE_TIMING_TRACE - start_meas(&ue->rx_dft_stats); + start_meas(&ue->rx_dft_stats); #endif - dft((int16_t *)&common_vars->rxdata[aa][(rx_offset) % frame_length_samples], (int16_t *)&common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[Ns>>1]].rxdataF[aa][frame_parms->ofdm_symbol_size*symbol],1); #if UE_TIMING_TRACE stop_meas(&ue->rx_dft_stats); #endif - } } else { rx_offset += (frame_parms->ofdm_symbol_size+nb_prefix_samples)*l;// + // (frame_parms->ofdm_symbol_size+nb_prefix_samples)*(l-1); - #ifdef DEBUG_FEP // if (ue->frame <100) - LOG_I(PHY,"slot_fep: frame %d: slot %d, symbol %d, nb_prefix_samples %d, nb_prefix_samples0 %d, slot_offset %d, subframe_offset %d, sample_offset %d,rx_offset %d, frame_length_samples %d\n", ue->proc.proc_rxtx[(Ns>>1)&1].frame_rx,Ns, symbol, - nb_prefix_samples,nb_prefix_samples0,slot_offset,subframe_offset,sample_offset,rx_offset,frame_length_samples); + LOG_I(PHY,"slot_fep: frame %d: slot %d, symbol %d, nb_prefix_samples %d, nb_prefix_samples0 %d, slot_offset %d, subframe_offset %d, sample_offset %d,rx_offset %d, frame_length_samples %d\n", + ue->proc.proc_rxtx[(Ns>>1)&1].frame_rx,Ns, symbol, + nb_prefix_samples,nb_prefix_samples0,slot_offset,subframe_offset,sample_offset,rx_offset,frame_length_samples); #endif if (rx_offset > (frame_length_samples - frame_parms->ofdm_symbol_size)) memcpy((void *)&common_vars->rxdata[aa][frame_length_samples], (void *)&common_vars->rxdata[aa][0], frame_parms->ofdm_symbol_size*sizeof(int)); + #if UE_TIMING_TRACE start_meas(&ue->rx_dft_stats); #endif @@ -167,27 +157,25 @@ int slot_fep(PHY_VARS_UE *ue, dft((int16_t *)tmp_dft_in, (int16_t *)&common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[Ns>>1]].rxdataF[aa][frame_parms->ofdm_symbol_size*symbol],1); } else { // use dft input from RX buffer directly - dft((int16_t *)&common_vars->rxdata[aa][(rx_offset) % frame_length_samples], (int16_t *)&common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[Ns>>1]].rxdataF[aa][frame_parms->ofdm_symbol_size*symbol],1); } + #if UE_TIMING_TRACE stop_meas(&ue->rx_dft_stats); #endif - - } - #ifdef DEBUG_FEP - // if (ue->frame <100) - printf("slot_fep: frame %d: symbol %d rx_offset %d\n", ue->proc.proc_rxtx[(Ns>>1)&1].frame_rx, symbol,rx_offset); - #endif + +#ifdef DEBUG_FEP + // if (ue->frame <100) + printf("slot_fep: frame %d: symbol %d rx_offset %u\n", ue->proc.proc_rxtx[(Ns>>1)&1].frame_rx, symbol,rx_offset); +#endif } if (ue->perfect_ce == 0) { if ((l==0) || (l==(4-frame_parms->Ncp))) { for (aa=0; aa<frame_parms->nb_antenna_ports_eNB; aa++) { - #ifdef DEBUG_FEP printf("Channel estimation eNB %d, aatx %d, slot %d, symbol %d\n",eNB_id,aa,Ns,l); #endif @@ -212,7 +200,6 @@ int slot_fep(PHY_VARS_UE *ue, } } - // do frequency offset estimation here! // use channel estimates from current symbol (=ch_t) and last symbol (ch_{t-1}) #ifdef DEBUG_FEP @@ -220,23 +207,19 @@ int slot_fep(PHY_VARS_UE *ue, #endif if (l==(4-frame_parms->Ncp)) { - #if UE_TIMING_TRACE - start_meas(&ue->dlsch_freq_offset_estimation_stats); + start_meas(&ue->dlsch_freq_offset_estimation_stats); #endif - lte_est_freq_offset(common_vars->common_vars_rx_data_per_thread[ue->current_thread_id[Ns>>1]].dl_ch_estimates[0], frame_parms, l, &common_vars->freq_offset, - reset_freq_est); + reset_freq_est); #if UE_TIMING_TRACE stop_meas(&ue->dlsch_freq_offset_estimation_stats); #endif - } } - } #ifdef DEBUG_FEP @@ -246,11 +229,10 @@ int slot_fep(PHY_VARS_UE *ue, } int front_end_fft(PHY_VARS_UE *ue, - unsigned char l, - unsigned char Ns, - int sample_offset, - int no_prefix) -{ + unsigned char l, + unsigned char Ns, + int sample_offset, + int no_prefix) { LTE_DL_FRAME_PARMS *frame_parms = &ue->frame_parms; LTE_UE_COMMON *common_vars = &ue->common_vars; unsigned char aa; @@ -262,43 +244,41 @@ int front_end_fft(PHY_VARS_UE *ue, unsigned int frame_length_samples = frame_parms->samples_per_tti * 10; unsigned int rx_offset; uint8_t threadId; - /*LTE_UE_DLSCH_t **dlsch_ue = phy_vars_ue->dlsch_ue[eNB_id]; unsigned char harq_pid = dlsch_ue[0]->current_harq_pid; LTE_DL_UE_HARQ_t *dlsch0_harq = dlsch_ue[0]->harq_processes[harq_pid]; int uespec_pilot[9][1200];*/ - void (*dft)(int16_t *,int16_t *, int); int tmp_dft_in[2048] __attribute__ ((aligned (32))); // This is for misalignment issues for 6 and 15 PRBs switch (frame_parms->ofdm_symbol_size) { - case 128: - dft = dft128; - break; + case 128: + dft = dft128; + break; - case 256: - dft = dft256; - break; + case 256: + dft = dft256; + break; - case 512: - dft = dft512; - break; + case 512: + dft = dft512; + break; - case 1024: - dft = dft1024; - break; + case 1024: + dft = dft1024; + break; - case 1536: - dft = dft1536; - break; + case 1536: + dft = dft1536; + break; - case 2048: - dft = dft2048; - break; + case 2048: + dft = dft2048; + break; - default: - dft = dft512; - break; + default: + dft = dft512; + break; } if (no_prefix) { @@ -311,7 +291,6 @@ int front_end_fft(PHY_VARS_UE *ue, // subframe_offset_F = frame_parms->ofdm_symbol_size * frame_parms->symbols_per_tti * (Ns>>1); - if (l<0 || l>=7-frame_parms->Ncp) { printf("slot_fep: l must be between 0 and %d\n",7-frame_parms->Ncp); return(-1); @@ -322,19 +301,16 @@ int front_end_fft(PHY_VARS_UE *ue, return(-1); } - - threadId = ue->current_thread_id[Ns>>1]; + for (aa=0; aa<frame_parms->nb_antennas_rx; aa++) { - // change thread index + // change thread index memset(&common_vars->common_vars_rx_data_per_thread[threadId].rxdataF[aa][frame_parms->ofdm_symbol_size*symbol],0,frame_parms->ofdm_symbol_size*sizeof(int)); - rx_offset = sample_offset + slot_offset + nb_prefix_samples0 + subframe_offset - SOFFSET; // Align with 256 bit // rx_offset = rx_offset&0xfffffff8; if (l==0) { - if (rx_offset > (frame_length_samples - frame_parms->ofdm_symbol_size)) memcpy((short *)&common_vars->rxdata[aa][frame_length_samples], (short *)&common_vars->rxdata[aa][0], @@ -348,21 +324,19 @@ int front_end_fft(PHY_VARS_UE *ue, (int16_t *)&common_vars->common_vars_rx_data_per_thread[threadId].rxdataF[aa][frame_parms->ofdm_symbol_size*symbol],1); } else { // use dft input from RX buffer directly start_meas(&ue->rx_dft_stats); - dft((int16_t *)&common_vars->rxdata[aa][(rx_offset) % frame_length_samples], (int16_t *)&common_vars->common_vars_rx_data_per_thread[threadId].rxdataF[aa][frame_parms->ofdm_symbol_size*symbol],1); stop_meas(&ue->rx_dft_stats); - } } else { rx_offset += (frame_parms->ofdm_symbol_size+nb_prefix_samples)*l;// + // (frame_parms->ofdm_symbol_size+nb_prefix_samples)*(l-1); - #ifdef DEBUG_FEP // if (ue->frame <100) - LOG_I(PHY,"slot_fep: frame %d: slot %d, threadId %d, symbol %d, nb_prefix_samples %d, nb_prefix_samples0 %d, slot_offset %d, subframe_offset %d, sample_offset %d,rx_offset %d, frame_length_samples %d\n", - ue->proc.proc_rxtx[threadId].frame_rx,Ns, threadId,symbol, - nb_prefix_samples,nb_prefix_samples0,slot_offset,subframe_offset,sample_offset,rx_offset,frame_length_samples); + LOG_I(PHY, + "slot_fep: frame %d: slot %d, threadId %d, symbol %d, nb_prefix_samples %d, nb_prefix_samples0 %d, slot_offset %d, subframe_offset %d, sample_offset %d,rx_offset %d, frame_length_samples %d\n", + ue->proc.proc_rxtx[threadId].frame_rx,Ns, threadId,symbol, + nb_prefix_samples,nb_prefix_samples0,slot_offset,subframe_offset,sample_offset,rx_offset,frame_length_samples); #endif if (rx_offset > (frame_length_samples - frame_parms->ofdm_symbol_size)) @@ -379,29 +353,27 @@ int front_end_fft(PHY_VARS_UE *ue, dft((int16_t *)tmp_dft_in, (int16_t *)&common_vars->common_vars_rx_data_per_thread[threadId].rxdataF[aa][frame_parms->ofdm_symbol_size*symbol],1); } else { // use dft input from RX buffer directly - dft((int16_t *)&common_vars->rxdata[aa][(rx_offset) % frame_length_samples], (int16_t *)&common_vars->common_vars_rx_data_per_thread[threadId].rxdataF[aa][frame_parms->ofdm_symbol_size*symbol],1); } stop_meas(&ue->rx_dft_stats); - - } - #ifdef DEBUG_FEP - // if (ue->frame <100) - printf("slot_fep: frame %d: symbol %d rx_offset %d\n", ue->proc.proc_rxtx[threadId].frame_rx, symbol,rx_offset); - #endif +#ifdef DEBUG_FEP + // if (ue->frame <100) + printf("slot_fep: frame %d: symbol %d rx_offset %u\n", ue->proc.proc_rxtx[threadId].frame_rx, symbol,rx_offset); +#endif + } + return(0); } int front_end_chanEst(PHY_VARS_UE *ue, - unsigned char l, - unsigned char Ns, - int reset_freq_est) -{ + unsigned char l, + unsigned char Ns, + int reset_freq_est) { LTE_DL_FRAME_PARMS *frame_parms = &ue->frame_parms; LTE_UE_COMMON *common_vars = &ue->common_vars; uint8_t eNB_id = 0;//ue_common_vars->eNb_id; @@ -417,7 +389,6 @@ int front_end_chanEst(PHY_VARS_UE *ue, if (ue->perfect_ce == 0) { if ((l==0) || (l==(4-frame_parms->Ncp))) { for (aa=0; aa<frame_parms->nb_antenna_ports_eNB; aa++) { - #ifdef DEBUG_FEP printf("Channel estimation eNB %d, aatx %d, slot %d, symbol %d\n",eNB_id,aa,Ns,l); #endif @@ -438,7 +409,6 @@ int front_end_chanEst(PHY_VARS_UE *ue, } } - // do frequency offset estimation here! // use channel estimates from current symbol (=ch_t) and last symbol (ch_{t-1}) #ifdef DEBUG_FEP @@ -451,12 +421,11 @@ int front_end_chanEst(PHY_VARS_UE *ue, frame_parms, l, &common_vars->freq_offset, - reset_freq_est); + reset_freq_est); stop_meas(&ue->dlsch_freq_offset_estimation_stats); - } } - } + return(0); } diff --git a/openair1/PHY/TOOLS/lte_dfts.c b/openair1/PHY/TOOLS/lte_dfts.c index 45373ab9e2ac57f768c59f2a80e20123062587fc..b8633b5126c43ce23d34b21e1bf9970b589ded47 100644 --- a/openair1/PHY/TOOLS/lte_dfts.c +++ b/openair1/PHY/TOOLS/lte_dfts.c @@ -9494,7 +9494,7 @@ int main(int argc, char**argv) LOG_M("x24576.m","x24576",x,24576,1,1); int dftsizes[33]={24,36,48,60,72,96,108,120,144,180,192,216,240,288,300,324,360,384,432,480,540,576,600,648,720,768,864,900,960,972,1080,1152,1200}; - void (*dft[33])(int16_t *x,int16_t *y,uint8_t scale) = {dft24,dft36,dft48,dft60,dft72,dft96,dft108,dft120,dft144,dft180,dft192,dft216,dft240,dft288,dft300,dft324,dft360,dft384,dft432,dft480,dft540,dft576,dft600,dft648,dft720,dft768,dft864,dft900,dft960,dft972,dft1080,dft1152,dft1200}; + void (*dft)(int16_t *x,int16_t *y,uint8_t scale)[33] = {dft24,dft36,dft48,dft60,dft72,dft96,dft108,dft120,dft144,dft180,dft192,dft216,dft240,dft288,dft300,dft324,dft360,dft384,dft432,dft480,dft540,dft576,dft600,dft648,dft720,dft768,dft864,dft900,dft960,dft972,dft1080,dft1152,dft1200}; for (int n=0;n<33;n++) { // 4xN-point DFT memset((void*)x,0,dftsizes[n]*8*sizeof(int16_t)); diff --git a/openair1/PHY/TOOLS/read_F.c b/openair1/PHY/TOOLS/read_F.c index 32ade0dfdb698c69c1ccc0cf757c10e739787822..155b72c851e6ea0d710d507e0fbb45fcada963b5 100644 --- a/openair1/PHY/TOOLS/read_F.c +++ b/openair1/PHY/TOOLS/read_F.c @@ -19,6 +19,7 @@ int f_read(char *calibF_fname, int nb_antM, int nb_freq, int16_t (*calibF_mtx)[n } printf("%d\n",(int)calibF_mtx[0][0]); printf("%d\n",(int)calibF_mtx[1][599]); + fclose(calibF_fd); } else printf("%s not found, running with defaults\n",calibF_fname); } diff --git a/openair1/PHY/TOOLS/smbv.c b/openair1/PHY/TOOLS/smbv.c index e020ca0c5200573c391d2d0235a9d0bfb855b3cb..d3618725478cbec430fe0a986c704fd385773700 100644 --- a/openair1/PHY/TOOLS/smbv.c +++ b/openair1/PHY/TOOLS/smbv.c @@ -64,6 +64,7 @@ int smbv_init_config(const char* fname, uint16_t sequence_length) if (sequence_length>4) { msg("ERROR invalid sequence length: %d, maximum is 4\n", sequence_length); + fclose(f_ptr); return -1; } else slen = sequence_length; @@ -448,13 +449,6 @@ int smbv_send_config (const char* fname, char* smbv_ip) int bytes_sent, status, sockfd; char buf[BUFFER_LENGTH]; - if (fopen(fname,"r")!=NULL) { - msg("Configuration file: %s\n",fname); - } else { - msg("ERROR: can't open SMBV config file: %s\n",fname); - return -1; - } - memset(buf,0,BUFFER_LENGTH); // first, load up address structs with getaddrinfo(): diff --git a/openair1/PHY/TOOLS/time_meas.c b/openair1/PHY/TOOLS/time_meas.c index b37f146b0a8eb9b05f4c871f4e8562d0cc1e3afa..327efbaafae5f3386ad38d5760e91b37d12f281b 100644 --- a/openair1/PHY/TOOLS/time_meas.c +++ b/openair1/PHY/TOOLS/time_meas.c @@ -29,7 +29,6 @@ int opp_enabled = 0; double get_cpu_freq_GHz(void) { - time_stats_t ts = {0}; reset_meas(&ts); ts.trials++; @@ -38,32 +37,40 @@ double get_cpu_freq_GHz(void) { ts.diff = (rdtsc_oai()-ts.in); cpu_freq_GHz = (double)ts.diff/1000000000; printf("CPU Freq is %f \n", cpu_freq_GHz); - return cpu_freq_GHz; + return cpu_freq_GHz; } +int cpumeas(int action) { + switch (action) { + case CPUMEAS_ENABLE: + opp_enabled = 1; + break; + + case CPUMEAS_DISABLE: + opp_enabled = 0; + break; + + case CPUMEAS_GETSTATE: + default: + break; + } -void print_meas_now(time_stats_t *ts, const char* name, FILE* file_name){ - + return opp_enabled; +} +void print_meas_now(time_stats_t *ts, const char *name, FILE *file_name) { if (opp_enabled) { - //static double cpu_freq_GHz = 3.2; //if (cpu_freq_GHz == 0.0) - //cpu_freq_GHz = get_cpu_freq_GHz(); // super slow - + //cpu_freq_GHz = get_cpu_freq_GHz(); // super slow if (ts->trials>0) { - //fprintf(file_name,"Name %25s: Processing %15.3f ms for SF %d, diff_now %15.3f \n", name,(ts->p_time/(cpu_freq_GHz*1000000.0)),subframe,ts->p_time); fprintf(file_name,"%15.3f us, diff_now %15.3f \n",(ts->p_time/(cpu_freq_GHz*1000.0)),(double)ts->p_time); - } } } -void print_meas(time_stats_t *ts, const char* name, time_stats_t * total_exec_time, time_stats_t * sf_exec_time) -{ - +void print_meas(time_stats_t *ts, const char *name, time_stats_t *total_exec_time, time_stats_t *sf_exec_time) { if (opp_enabled) { - static int first_time = 0; static double cpu_freq_GHz = 0.0; @@ -81,7 +88,6 @@ void print_meas(time_stats_t *ts, const char* name, time_stats_t * total_exec_ti if (ts->trials>0) { //printf("%20s: total: %10.3f ms, average: %10.3f us (%10d trials)\n", name, ts->diff/cpu_freq_GHz/1000000.0, ts->diff/ts->trials/cpu_freq_GHz/1000.0, ts->trials); - if ((total_exec_time == NULL) || (sf_exec_time== NULL)) { fprintf(stderr, "%25s: %15.3f us; %15d;\n", name, @@ -98,12 +104,9 @@ void print_meas(time_stats_t *ts, const char* name, time_stats_t * total_exec_ti } } } - } -double get_time_meas_us(time_stats_t *ts) -{ - +double get_time_meas_us(time_stats_t *ts) { static double cpu_freq_GHz = 0.0; if (cpu_freq_GHz == 0.0) diff --git a/openair1/PHY/TOOLS/time_meas.h b/openair1/PHY/TOOLS/time_meas.h index eac057095a42d41ef89efc86a090715f9c09292a..797acef8e724259436248b3d6b85143c25fbc658 100644 --- a/openair1/PHY/TOOLS/time_meas.h +++ b/openair1/PHY/TOOLS/time_meas.h @@ -61,23 +61,21 @@ static inline void start_meas(time_stats_t *ts) __attribute__((always_inline)); static inline void stop_meas(time_stats_t *ts) __attribute__((always_inline)); -void print_meas_now(time_stats_t *ts, const char* name, FILE* file_name); -void print_meas(time_stats_t *ts, const char* name, time_stats_t * total_exec_time, time_stats_t * sf_exec_time); +void print_meas_now(time_stats_t *ts, const char *name, FILE *file_name); +void print_meas(time_stats_t *ts, const char *name, time_stats_t *total_exec_time, time_stats_t *sf_exec_time); double get_time_meas_us(time_stats_t *ts); double get_cpu_freq_GHz(void); #if defined(__i386__) static inline unsigned long long rdtsc_oai(void) __attribute__((always_inline)); -static inline unsigned long long rdtsc_oai(void) -{ +static inline unsigned long long rdtsc_oai(void) { unsigned long long int x; __asm__ volatile (".byte 0x0f, 0x31" : "=A" (x)); return x; } #elif defined(__x86_64__) static inline unsigned long long rdtsc_oai(void) __attribute__((always_inline)); -static inline unsigned long long rdtsc_oai(void) -{ +static inline unsigned long long rdtsc_oai(void) { unsigned long long a, d; __asm__ volatile ("rdtsc" : "=a" (a), "=d" (d)); return (d<<32) | a; @@ -85,61 +83,54 @@ static inline unsigned long long rdtsc_oai(void) #elif defined(__arm__) static inline uint32_t rdtsc_oai(void) __attribute__((always_inline)); -static inline uint32_t rdtsc_oai(void) -{ +static inline uint32_t rdtsc_oai(void) { uint32_t r = 0; asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r"(r) ); return r; } #endif -static inline void start_meas(time_stats_t *ts) -{ - +#define CPUMEAS_DISABLE 0 +#define CPUMEAS_ENABLE 1 +#define CPUMEAS_GETSTATE 2 +int cpumeas(int action); +static inline void start_meas(time_stats_t *ts) { if (opp_enabled) { if (ts->meas_flag==0) { ts->trials++; ts->in = rdtsc_oai(); ts->meas_flag=1; - } - else { + } else { ts->in = rdtsc_oai(); } } } -static inline void stop_meas(time_stats_t *ts) -{ - +static inline void stop_meas(time_stats_t *ts) { if (opp_enabled) { long long out = rdtsc_oai(); - ts->diff += (out-ts->in); /// process duration is the difference between two clock points ts->p_time = (out-ts->in); ts->diff_square += (out-ts->in)*(out-ts->in); - + if ((out-ts->in) > ts->max) ts->max = out-ts->in; - ts->meas_flag=0; + ts->meas_flag=0; } } static inline void reset_meas(time_stats_t *ts) { - ts->trials=0; ts->diff=0; ts->p_time=0; ts->diff_square=0; ts->max=0; ts->meas_flag=0; - } -static inline void copy_meas(time_stats_t *dst_ts,time_stats_t *src_ts) -{ - +static inline void copy_meas(time_stats_t *dst_ts,time_stats_t *src_ts) { if (opp_enabled) { dst_ts->trials=src_ts->trials; dst_ts->diff=src_ts->diff; diff --git a/openair1/SCHED/phy_procedures_lte_eNb.c b/openair1/SCHED/phy_procedures_lte_eNb.c index 7750f614a576235a854919b64632fcdbcc4552b0..f7b433be9e070429ab0fc34d5c343bc3b73c9d0e 100644 --- a/openair1/SCHED/phy_procedures_lte_eNb.c +++ b/openair1/SCHED/phy_procedures_lte_eNb.c @@ -1670,7 +1670,12 @@ int getM(PHY_VARS_eNB *eNB,int frame,int subframe) { subframe, m); frame_tx = ul_ACK_subframe2_dl_frame(&eNB->frame_parms,frame, - subframe,subframe_tx); + subframe,subframe_tx); + if (dlsch0 == NULL || dlsch1 == NULL) { + LOG_E(PHY, "dlsch0 and/or dlsch1 NULL, getM frame %i, subframe %i\n",frame,subframe); + return Mtx; + } + harq_pid = dlsch0->harq_ids[frame_tx%2][subframe_tx]; if (harq_pid>=0 && harq_pid<10) { diff --git a/openair1/SCHED_UE/phy_procedures_lte_ue.c b/openair1/SCHED_UE/phy_procedures_lte_ue.c index d9c674406943bc34d47599cf352f9d8bdac4a960..807c79e6e0928c9b375de73baaa19fa1197600de 100644 --- a/openair1/SCHED_UE/phy_procedures_lte_ue.c +++ b/openair1/SCHED_UE/phy_procedures_lte_ue.c @@ -1900,16 +1900,6 @@ void ue_pucch_procedures(PHY_VARS_UE *ue,UE_rxtx_proc_t *proc,uint8_t eNB_id,uin uint8_t isShortenPucch = (pSoundingrs_ul_config_dedicated->srsCellSubframe && frame_parms->soundingrs_ul_config_common.ackNackSRS_SimultaneousTransmission); bundling_flag = ue->pucch_config_dedicated[eNB_id].tdd_AckNackFeedbackMode; - if ((frame_parms->frame_type==FDD) || - (bundling_flag==bundling) || - ((frame_parms->frame_type==TDD)&&(frame_parms->tdd_config==1)&&((subframe_tx!=2)||(subframe_tx!=7)))) { - format = pucch_format1a; - // LOG_D(PHY,"[UE] PUCCH 1a\n"); - } else { - format = pucch_format1b; - // LOG_D(PHY,"[UE] PUCCH 1b\n"); - } - // Part - I // Collect feedback that should be transmitted at this subframe // - SR @@ -3000,7 +2990,7 @@ void ue_pdsch_procedures(PHY_VARS_UE *ue, UE_rxtx_proc_t *proc, int eNB_id, PDSC int i_mod,eNB_id_i,dual_stream_UE; int first_symbol_flag=0; - if (dlsch0->active == 0) + if (dlsch0 && dlsch0->active == 0) return; for (m=s0; m<=s1; m++) { @@ -4209,7 +4199,7 @@ int phy_procedures_slot_parallelization_UE_RX(PHY_VARS_UE *ue,UE_rxtx_proc_t *pr ue->dlsch_ra[eNB_id]->active = 0; } - if (LOG_DEBUGFLAG(UE_TIMING) + if (LOG_DEBUGFLAG(UE_TIMING)) { stop_meas(&ue->dlsch_procedures_stat[ue->current_thread_id[subframe_rx]]); LOG_I(PHY, "[AbsSFN %d.%d] Channel Decoder: %5.2f \n",frame_rx,subframe_rx,ue->dlsch_procedures_stat[ue->current_thread_id[subframe_rx]].p_time/(cpuf*1000.0)); } diff --git a/openair1/SIMULATION/LTE_PHY/dlsim.c b/openair1/SIMULATION/LTE_PHY/dlsim.c index b557df3c92653bfcf7a47a90b807022af4d6b959..64a41e829867e18e47d6aac515843822b20cfaa5 100644 --- a/openair1/SIMULATION/LTE_PHY/dlsim.c +++ b/openair1/SIMULATION/LTE_PHY/dlsim.c @@ -89,14 +89,11 @@ THREAD_STRUCT thread_struct; int emulate_rf = 0; -void handler(int sig) -{ +void handler(int sig) { void *array[10]; size_t size; - // get void*'s for all entries on the stack size = backtrace(array, 10); - // print out all the frames to stderr fprintf(stderr, "Error: signal %d:\n", sig); backtrace_symbols_fd(array, size, 2); @@ -114,17 +111,13 @@ uint64_t DLSCH_alloc_pdu_1[2]; #define CCCH_RB_ALLOC computeRIV(eNB->frame_parms.N_RB_UL,0,2) //#define DLSCH_RB_ALLOC 0x1fbf // igore DC component,RB13 //#define DLSCH_RB_ALLOC 0x0001 -void do_OFDM_mod_l(int32_t **txdataF, int32_t **txdata, uint16_t next_slot, LTE_DL_FRAME_PARMS *frame_parms) -{ - +void do_OFDM_mod_l(int32_t **txdataF, int32_t **txdata, uint16_t next_slot, LTE_DL_FRAME_PARMS *frame_parms) { int aa, slot_offset, slot_offset_F; - slot_offset_F = (next_slot)*(frame_parms->ofdm_symbol_size)*((frame_parms->Ncp==1) ? 6 : 7); slot_offset = (next_slot)*(frame_parms->samples_per_tti>>1); for (aa=0; aa<frame_parms->nb_antennas_tx; aa++) { // printf("Thread %d starting ... aa %d (%llu)\n",omp_get_thread_num(),aa,rdtsc()); - if (frame_parms->Ncp == 1) PHY_ofdm_mod(&txdataF[aa][slot_offset_F], // input &txdata[aa][slot_offset], // output @@ -138,15 +131,11 @@ void do_OFDM_mod_l(int32_t **txdataF, int32_t **txdata, uint16_t next_slot, LTE_ 7, frame_parms); } - - } - } void DL_channel(RU_t *ru,PHY_VARS_UE *UE,uint subframe,int awgn_flag,double SNR, int tx_lev,int hold_channel,int abstx, int num_rounds, int trials, int round, channel_desc_t *eNB2UE[4], - double *s_re[2],double *s_im[2],double *r_re[2],double *r_im[2],FILE *csv_fd) { - + double *s_re[2],double *s_im[2],double *r_re[2],double *r_im[2],FILE *csv_fd) { int i,u; int aa,aarx,aatx; double channelx,channely; @@ -157,19 +146,18 @@ void DL_channel(RU_t *ru,PHY_VARS_UE *UE,uint subframe,int awgn_flag,double SNR, for (i=0; i<2*UE->frame_parms.samples_per_tti; i++) { for (aa=0; aa<ru->frame_parms.nb_antennas_tx; aa++) { if (awgn_flag == 0) { - s_re[aa][i] = ((double)(((short *)ru->common.txdata[aa]))[(2*subframe*UE->frame_parms.samples_per_tti) + (i<<1)]); - s_im[aa][i] = ((double)(((short *)ru->common.txdata[aa]))[(2*subframe*UE->frame_parms.samples_per_tti) +(i<<1)+1]); + s_re[aa][i] = ((double)(((short *)ru->common.txdata[aa]))[(2*subframe*UE->frame_parms.samples_per_tti) + (i<<1)]); + s_im[aa][i] = ((double)(((short *)ru->common.txdata[aa]))[(2*subframe*UE->frame_parms.samples_per_tti) +(i<<1)+1]); } else { - for (aarx=0; aarx<UE->frame_parms.nb_antennas_rx; aarx++) { - if (aa==0) { - r_re[aarx][i] = ((double)(((short *)ru->common.txdata[aa]))[(2*subframe*UE->frame_parms.samples_per_tti) +(i<<1)]); - r_im[aarx][i] = ((double)(((short *)ru->common.txdata[aa]))[(2*subframe*UE->frame_parms.samples_per_tti) +(i<<1)+1]); - } else { - r_re[aarx][i] += ((double)(((short *)ru->common.txdata[aa]))[(2*subframe*UE->frame_parms.samples_per_tti) +(i<<1)]); - r_im[aarx][i] += ((double)(((short *)ru->common.txdata[aa]))[(2*subframe*UE->frame_parms.samples_per_tti) +(i<<1)+1]); - } - - } + for (aarx=0; aarx<UE->frame_parms.nb_antennas_rx; aarx++) { + if (aa==0) { + r_re[aarx][i] = ((double)(((short *)ru->common.txdata[aa]))[(2*subframe*UE->frame_parms.samples_per_tti) +(i<<1)]); + r_im[aarx][i] = ((double)(((short *)ru->common.txdata[aa]))[(2*subframe*UE->frame_parms.samples_per_tti) +(i<<1)+1]); + } else { + r_re[aarx][i] += ((double)(((short *)ru->common.txdata[aa]))[(2*subframe*UE->frame_parms.samples_per_tti) +(i<<1)]); + r_im[aarx][i] += ((double)(((short *)ru->common.txdata[aa]))[(2*subframe*UE->frame_parms.samples_per_tti) +(i<<1)+1]); + } + } } } } @@ -177,27 +165,26 @@ void DL_channel(RU_t *ru,PHY_VARS_UE *UE,uint subframe,int awgn_flag,double SNR, // Multipath channel if (awgn_flag == 0) { multipath_channel(eNB2UE[round],s_re,s_im,r_re,r_im, - 2*UE->frame_parms.samples_per_tti,hold_channel); + 2*UE->frame_parms.samples_per_tti,hold_channel); // printf("amc: ****************** eNB2UE[%d]->n_rx = %d,dd %d\n",round,eNB2UE[round]->nb_rx,eNB2UE[round]->channel_offset); if(abstx==1 && num_rounds>1) if(round==0 && hold_channel==0) { - random_channel(eNB2UE[1],0); - random_channel(eNB2UE[2],0); - random_channel(eNB2UE[3],0); + random_channel(eNB2UE[1],0); + random_channel(eNB2UE[2],0); + random_channel(eNB2UE[3],0); } if (UE->perfect_ce==1) { // fill in perfect channel estimates freq_channel(eNB2UE[round],UE->frame_parms.N_RB_DL,12*UE->frame_parms.N_RB_DL + 1); /* - LOG_M("channel.m","ch",eNB2UE[round]->ch[0],eNB2UE[round]->channel_length,1,8); - LOG_M("channelF.m","chF",eNB2UE[round]->chF[0],12*UE->frame_parms.N_RB_DL + 1,1,8); + LOG_M("channel.m","ch",eNB2UE[round]->ch[0],eNB2UE[round]->channel_length,1,8); + LOG_M("channelF.m","chF",eNB2UE[round]->chF[0],12*UE->frame_parms.N_RB_DL + 1,1,8); */ } } - if(abstx) { if (trials==0 && round==0) { // calculate freq domain representation to compute SINR @@ -206,51 +193,51 @@ void DL_channel(RU_t *ru,PHY_VARS_UE *UE,uint subframe,int awgn_flag,double SNR, fprintf(csv_fd,"%f,",SNR); for (u=0; u<2*ru->frame_parms.N_RB_DL; u++) { - for (aarx=0; aarx<eNB2UE[0]->nb_rx; aarx++) { - for (aatx=0; aatx<eNB2UE[0]->nb_tx; aatx++) { - channelx = eNB2UE[0]->chF[aarx+(aatx*eNB2UE[0]->nb_rx)][u].x; - channely = eNB2UE[0]->chF[aarx+(aatx*eNB2UE[0]->nb_rx)][u].y; - fprintf(csv_fd,"%e+i*(%e),",channelx,channely); - } - } + for (aarx=0; aarx<eNB2UE[0]->nb_rx; aarx++) { + for (aatx=0; aatx<eNB2UE[0]->nb_tx; aatx++) { + channelx = eNB2UE[0]->chF[aarx+(aatx*eNB2UE[0]->nb_rx)][u].x; + channely = eNB2UE[0]->chF[aarx+(aatx*eNB2UE[0]->nb_rx)][u].y; + fprintf(csv_fd,"%e+i*(%e),",channelx,channely); + } + } } if(num_rounds>1) { - freq_channel(eNB2UE[1], ru->frame_parms.N_RB_DL,2*ru->frame_parms.N_RB_DL + 1); - - for (u=0; u<2*ru->frame_parms.N_RB_DL; u++) { - for (aarx=0; aarx<eNB2UE[1]->nb_rx; aarx++) { - for (aatx=0; aatx<eNB2UE[1]->nb_tx; aatx++) { - channelx = eNB2UE[1]->chF[aarx+(aatx*eNB2UE[1]->nb_rx)][u].x; - channely = eNB2UE[1]->chF[aarx+(aatx*eNB2UE[1]->nb_rx)][u].y; - fprintf(csv_fd,"%e+i*(%e),",channelx,channely); - } - } - } + freq_channel(eNB2UE[1], ru->frame_parms.N_RB_DL,2*ru->frame_parms.N_RB_DL + 1); + + for (u=0; u<2*ru->frame_parms.N_RB_DL; u++) { + for (aarx=0; aarx<eNB2UE[1]->nb_rx; aarx++) { + for (aatx=0; aatx<eNB2UE[1]->nb_tx; aatx++) { + channelx = eNB2UE[1]->chF[aarx+(aatx*eNB2UE[1]->nb_rx)][u].x; + channely = eNB2UE[1]->chF[aarx+(aatx*eNB2UE[1]->nb_rx)][u].y; + fprintf(csv_fd,"%e+i*(%e),",channelx,channely); + } + } + } - freq_channel(eNB2UE[2], ru->frame_parms.N_RB_DL,2*ru->frame_parms.N_RB_DL + 1); + freq_channel(eNB2UE[2], ru->frame_parms.N_RB_DL,2*ru->frame_parms.N_RB_DL + 1); - for (u=0; u<2*ru->frame_parms.N_RB_DL; u++) { - for (aarx=0; aarx<eNB2UE[2]->nb_rx; aarx++) { - for (aatx=0; aatx<eNB2UE[2]->nb_tx; aatx++) { - channelx = eNB2UE[2]->chF[aarx+(aatx*eNB2UE[2]->nb_rx)][u].x; - channely = eNB2UE[2]->chF[aarx+(aatx*eNB2UE[2]->nb_rx)][u].y; - fprintf(csv_fd,"%e+i*(%e),",channelx,channely); - } - } - } + for (u=0; u<2*ru->frame_parms.N_RB_DL; u++) { + for (aarx=0; aarx<eNB2UE[2]->nb_rx; aarx++) { + for (aatx=0; aatx<eNB2UE[2]->nb_tx; aatx++) { + channelx = eNB2UE[2]->chF[aarx+(aatx*eNB2UE[2]->nb_rx)][u].x; + channely = eNB2UE[2]->chF[aarx+(aatx*eNB2UE[2]->nb_rx)][u].y; + fprintf(csv_fd,"%e+i*(%e),",channelx,channely); + } + } + } - freq_channel(eNB2UE[3], ru->frame_parms.N_RB_DL,2*ru->frame_parms.N_RB_DL + 1); + freq_channel(eNB2UE[3], ru->frame_parms.N_RB_DL,2*ru->frame_parms.N_RB_DL + 1); - for (u=0; u<2*ru->frame_parms.N_RB_DL; u++) { - for (aarx=0; aarx<eNB2UE[3]->nb_rx; aarx++) { - for (aatx=0; aatx<eNB2UE[3]->nb_tx; aatx++) { - channelx = eNB2UE[3]->chF[aarx+(aatx*eNB2UE[3]->nb_rx)][u].x; - channely = eNB2UE[3]->chF[aarx+(aatx*eNB2UE[3]->nb_rx)][u].y; - fprintf(csv_fd,"%e+i*(%e),",channelx,channely); - } - } - } + for (u=0; u<2*ru->frame_parms.N_RB_DL; u++) { + for (aarx=0; aarx<eNB2UE[3]->nb_rx; aarx++) { + for (aatx=0; aatx<eNB2UE[3]->nb_tx; aatx++) { + channelx = eNB2UE[3]->chF[aarx+(aatx*eNB2UE[3]->nb_rx)][u].x; + channely = eNB2UE[3]->chF[aarx+(aatx*eNB2UE[3]->nb_rx)][u].y; + fprintf(csv_fd,"%e+i*(%e),",channelx,channely); + } + } + } } } } @@ -264,25 +251,23 @@ void DL_channel(RU_t *ru,PHY_VARS_UE *UE,uint subframe,int awgn_flag,double SNR, for (i=0; i<2*UE->frame_parms.samples_per_tti; i++) { for (aa=0; aa<UE->frame_parms.nb_antennas_rx; aa++) { //printf("s_re[0][%d]=> %f , r_re[0][%d]=> %f\n",i,s_re[aa][i],i,r_re[aa][i]); - ((short*) UE->common_vars.rxdata[aa])[(2*subframe*UE->frame_parms.samples_per_tti)+2*i] = - (short) (r_re[aa][i] + sqrt(sigma2/2)*gaussdouble(0.0,1.0)); - ((short*) UE->common_vars.rxdata[aa])[(2*subframe*UE->frame_parms.samples_per_tti)+2*i+1] = - (short) (r_im[aa][i] + (iqim*r_re[aa][i]) + sqrt(sigma2/2)*gaussdouble(0.0,1.0)); + ((short *) UE->common_vars.rxdata[aa])[(2*subframe*UE->frame_parms.samples_per_tti)+2*i] = + (short) (r_re[aa][i] + sqrt(sigma2/2)*gaussdouble(0.0,1.0)); + ((short *) UE->common_vars.rxdata[aa])[(2*subframe*UE->frame_parms.samples_per_tti)+2*i+1] = + (short) (r_im[aa][i] + (iqim*r_re[aa][i]) + sqrt(sigma2/2)*gaussdouble(0.0,1.0)); } } } uint16_t fill_tx_req(nfapi_tx_request_body_t *tx_req_body, - uint16_t absSF, - uint16_t pdu_length, - uint16_t pdu_index, - uint8_t *pdu) -{ + uint16_t absSF, + uint16_t pdu_length, + uint16_t pdu_index, + uint8_t *pdu) { nfapi_tx_request_pdu_t *TX_req = &tx_req_body->tx_pdu_list[tx_req_body->number_of_pdus]; LOG_D(MAC, "Filling TX_req %d for pdu length %d\n", - tx_req_body->number_of_pdus, pdu_length); - + tx_req_body->number_of_pdus, pdu_length); TX_req->pdu_length = pdu_length; TX_req->pdu_index = pdu_index; TX_req->num_segments = 1; @@ -290,40 +275,37 @@ fill_tx_req(nfapi_tx_request_body_t *tx_req_body, TX_req->segments[0].segment_data = pdu; tx_req_body->tl.tag = NFAPI_TX_REQUEST_BODY_TAG; tx_req_body->number_of_pdus++; - return (((absSF / 10) << 4) + (absSF % 10)); } void -fill_dlsch_config(nfapi_dl_config_request_body_t * dl_req, - uint16_t length, - uint16_t pdu_index, - uint16_t rnti, - uint8_t resource_allocation_type, - uint8_t virtual_resource_block_assignment_flag, - uint16_t resource_block_coding, - uint8_t modulation, - uint8_t redundancy_version, - uint8_t transport_blocks, - uint8_t transport_block_to_codeword_swap_flag, - uint8_t transmission_scheme, - uint8_t number_of_layers, - uint8_t number_of_subbands, - // uint8_t codebook_index, - uint8_t ue_category_capacity, - uint8_t pa, - uint8_t delta_power_offset_index, - uint8_t ngap, - uint8_t nprb, - uint8_t transmission_mode, - uint8_t num_bf_prb_per_subband, - uint8_t num_bf_vector) -{ +fill_dlsch_config(nfapi_dl_config_request_body_t *dl_req, + uint16_t length, + uint16_t pdu_index, + uint16_t rnti, + uint8_t resource_allocation_type, + uint8_t virtual_resource_block_assignment_flag, + uint16_t resource_block_coding, + uint8_t modulation, + uint8_t redundancy_version, + uint8_t transport_blocks, + uint8_t transport_block_to_codeword_swap_flag, + uint8_t transmission_scheme, + uint8_t number_of_layers, + uint8_t number_of_subbands, + // uint8_t codebook_index, + uint8_t ue_category_capacity, + uint8_t pa, + uint8_t delta_power_offset_index, + uint8_t ngap, + uint8_t nprb, + uint8_t transmission_mode, + uint8_t num_bf_prb_per_subband, + uint8_t num_bf_vector) { nfapi_dl_config_request_pdu_t *dl_config_pdu = &dl_req->dl_config_pdu_list[dl_req->number_pdu]; memset((void *) dl_config_pdu, 0, - sizeof(nfapi_dl_config_request_pdu_t)); - + sizeof(nfapi_dl_config_request_pdu_t)); dl_config_pdu->pdu_type = NFAPI_DL_CONFIG_DLSCH_PDU_TYPE; dl_config_pdu->pdu_size = (uint8_t) (2 + sizeof(nfapi_dl_config_dlsch_pdu)); dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.tl.tag = NFAPI_DL_CONFIG_REQUEST_DLSCH_PDU_REL8_TAG; @@ -354,159 +336,132 @@ fill_dlsch_config(nfapi_dl_config_request_body_t * dl_req, } void fill_DCI(PHY_VARS_eNB *eNB, - int frame, - int subframe, - Sched_Rsp_t *sched_resp, - uint8_t input_buffer[NUMBER_OF_UE_MAX][20000], - int n_rnti, - int n_users, - int transmission_mode, - int retrans, - int common_flag, - int NB_RB, - int DLSCH_RB_ALLOC, - int TPC, - int mcs1, - int mcs2, - int ndi, - int rv, - int pa, - int *num_common_dci, - int *num_ue_spec_dci, - int *num_dci) { - + int frame, + int subframe, + Sched_Rsp_t *sched_resp, + uint8_t input_buffer[NUMBER_OF_UE_MAX][20000], + int n_rnti, + int n_users, + int transmission_mode, + int retrans, + int common_flag, + int NB_RB, + int DLSCH_RB_ALLOC, + int TPC, + int mcs1, + int mcs2, + int ndi, + int rv, + int pa, + int *num_common_dci, + int *num_ue_spec_dci, + int *num_dci) { int k; - nfapi_dl_config_request_body_t *dl_req=&sched_resp->DL_req->dl_config_request_body; nfapi_dl_config_request_pdu_t *dl_config_pdu; nfapi_tx_request_body_t *TX_req=&sched_resp->TX_req->tx_request_body; int NB_RB4TBS = common_flag == 0 ? NB_RB : (2+TPC); - dl_req->number_dci=0; dl_req->number_pdu=0; TX_req->number_of_pdus=0; for(k=0; k<n_users; k++) { switch(transmission_mode) { - case 1: - - case 2: - - case 7: - dl_config_pdu = &dl_req->dl_config_pdu_list[dl_req->number_pdu]; - memset((void *) dl_config_pdu, 0, - sizeof(nfapi_dl_config_request_pdu_t)); - dl_config_pdu->pdu_type = NFAPI_DL_CONFIG_DCI_DL_PDU_TYPE; - dl_config_pdu->pdu_size = (uint8_t) (2 + sizeof(nfapi_dl_config_dci_dl_pdu)); - dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.dci_format = (common_flag == 0) ? NFAPI_DL_DCI_FORMAT_1 : NFAPI_DL_DCI_FORMAT_1A; - dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level = 4; - dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.tl.tag = NFAPI_DL_CONFIG_REQUEST_DCI_DL_PDU_REL8_TAG; - dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti = (common_flag == 0) ? n_rnti+k : SI_RNTI; - dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti_type = (common_flag ==0 ) ? 1: 2; // CRNTI : see Table 4-10 from SCF082 - nFAPI specifications - dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.transmission_power = 6000; // equal to RS power - - dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.harq_process = 0; - dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.tpc = TPC; // dont adjust power when retransmitting - dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.new_data_indicator_1 = (common_flag == 0) ? ndi : 0; - dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.mcs_1 = mcs1; - dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.redundancy_version_1 = rv; - dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.resource_block_coding = (common_flag == 0) ? DLSCH_RB_ALLOC : computeRIV(eNB->frame_parms.N_RB_DL,0,NB_RB); - //deactivate second codeword - dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.mcs_2 = 0; - dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.redundancy_version_2 = 1; - - dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.downlink_assignment_index = 0; - dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.cce_idx = 0; - - dl_req->number_dci++; - dl_req->number_pdu++; - dl_req->tl.tag = NFAPI_DL_CONFIG_REQUEST_BODY_TAG; - - AssertFatal(TPC>=0 && TPC<2, "TPC should be 0 or 1\n"); - - fill_dlsch_config(dl_req, - get_TBS_DL(mcs1,NB_RB4TBS), - (retrans > 0) ? -1 : 0, /* retransmission, no pdu_index */ - (common_flag == 0) ? n_rnti : SI_RNTI, - 0, // type 0 allocation from 7.1.6 in 36.213 - 0, // virtual_resource_block_assignment_flag, unused here - DLSCH_RB_ALLOC, // resource_block_coding, - get_Qm(mcs1), - rv, // redundancy version - 1, // transport blocks - 0, // transport block to codeword swap flag - transmission_mode == 1 ? 0 : 1, // transmission_scheme - 1, // number of layers - 1, // number of subbands - // uint8_t codebook_index, - 4, // UE category capacity - pa, // pa - 0, // delta_power_offset for TM5 - 0, // ngap - 0, // nprb - transmission_mode, - 0, //number of PRBs treated as one subband, not used here - 0 // number of beamforming vectors, not used here - ); - fill_tx_req(TX_req, - (frame * 10) + subframe, - get_TBS_DL(mcs1,NB_RB4TBS), - 0, - input_buffer[k]); - - - break; - - case 3: - if (common_flag == 0) { - - if (eNB->frame_parms.nb_antennas_tx == 2) { - - if (eNB->frame_parms.frame_type == TDD) { - - } - else { - - } - } - } - break; - - case 4: - if (common_flag == 0) { - - if (eNB->frame_parms.nb_antennas_tx == 2) { - - if (eNB->frame_parms.frame_type == TDD) { - - - } - - else { - - } - } else if (eNB->frame_parms.nb_antennas_tx == 4) { + case 1: + case 2: + case 7: + dl_config_pdu = &dl_req->dl_config_pdu_list[dl_req->number_pdu]; + memset((void *) dl_config_pdu, 0, + sizeof(nfapi_dl_config_request_pdu_t)); + dl_config_pdu->pdu_type = NFAPI_DL_CONFIG_DCI_DL_PDU_TYPE; + dl_config_pdu->pdu_size = (uint8_t) (2 + sizeof(nfapi_dl_config_dci_dl_pdu)); + dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.dci_format = (common_flag == 0) ? NFAPI_DL_DCI_FORMAT_1 : NFAPI_DL_DCI_FORMAT_1A; + dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level = 4; + dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.tl.tag = NFAPI_DL_CONFIG_REQUEST_DCI_DL_PDU_REL8_TAG; + dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti = (common_flag == 0) ? n_rnti+k : SI_RNTI; + dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti_type = (common_flag ==0 ) ? 1: 2; // CRNTI : see Table 4-10 from SCF082 - nFAPI specifications + dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.transmission_power = 6000; // equal to RS power + dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.harq_process = 0; + dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.tpc = TPC; // dont adjust power when retransmitting + dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.new_data_indicator_1 = (common_flag == 0) ? ndi : 0; + dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.mcs_1 = mcs1; + dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.redundancy_version_1 = rv; + dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.resource_block_coding = (common_flag == 0) ? DLSCH_RB_ALLOC : computeRIV(eNB->frame_parms.N_RB_DL,0,NB_RB); + //deactivate second codeword + dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.mcs_2 = 0; + dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.redundancy_version_2 = 1; + dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.downlink_assignment_index = 0; + dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.cce_idx = 0; + dl_req->number_dci++; + dl_req->number_pdu++; + dl_req->tl.tag = NFAPI_DL_CONFIG_REQUEST_BODY_TAG; + AssertFatal(TPC>=0 && TPC<2, "TPC should be 0 or 1\n"); + fill_dlsch_config(dl_req, + get_TBS_DL(mcs1,NB_RB4TBS), + (retrans > 0) ? -1 : 0, /* retransmission, no pdu_index */ + (common_flag == 0) ? n_rnti : SI_RNTI, + 0, // type 0 allocation from 7.1.6 in 36.213 + 0, // virtual_resource_block_assignment_flag, unused here + DLSCH_RB_ALLOC, // resource_block_coding, + get_Qm(mcs1), + rv, // redundancy version + 1, // transport blocks + 0, // transport block to codeword swap flag + transmission_mode == 1 ? 0 : 1, // transmission_scheme + 1, // number of layers + 1, // number of subbands + // uint8_t codebook_index, + 4, // UE category capacity + pa, // pa + 0, // delta_power_offset for TM5 + 0, // ngap + 0, // nprb + transmission_mode, + 0, //number of PRBs treated as one subband, not used here + 0 // number of beamforming vectors, not used here + ); + fill_tx_req(TX_req, + (frame * 10) + subframe, + get_TBS_DL(mcs1,NB_RB4TBS), + 0, + input_buffer[k]); + break; - } + case 3: + if (common_flag == 0) { + if (eNB->frame_parms.nb_antennas_tx == 2) { + if (eNB->frame_parms.frame_type == TDD) { + } else { + } + } + } - } - else { + break; + case 4: + if (common_flag == 0) { + if (eNB->frame_parms.nb_antennas_tx == 2) { + if (eNB->frame_parms.frame_type == TDD) { + } else { + } + } else if (eNB->frame_parms.nb_antennas_tx == 4) { + } + } else { } break; case 5: case 6: - break; - default: - printf("Unsupported Transmission Mode %d!!!\n",transmission_mode); - exit(-1); - break; + default: + printf("Unsupported Transmission Mode %d!!!\n",transmission_mode); + exit(-1); + break; } } + *num_dci = dl_req->number_dci; *num_ue_spec_dci = dl_req->number_dci; *num_common_dci = 0; @@ -541,46 +496,33 @@ int verbose=0, help=0; double SNR,snr0=-2.0,snr1,rate = 0; int print_perf=0; -int main(int argc, char **argv) -{ - +int main(int argc, char **argv) { int k,i,j,aa; int re; - int s,Kr,Kr_bytes; - - LTE_DL_FRAME_PARMS *frame_parms; double s_re0[30720*2],s_im0[30720*2],r_re0[30720*2],r_im0[30720*2]; double s_re1[30720*2],s_im1[30720*2],r_re1[30720*2],r_im1[30720*2]; - double *s_re[2]={s_re0,s_re1}; - double *s_im[2]={s_im0,s_im1}; - double *r_re[2]={r_re0,r_re1}; - double *r_im[2]={r_im0,r_im1}; - - + double *s_re[2]= {s_re0,s_re1}; + double *s_im[2]= {s_im0,s_im1}; + double *r_re[2]= {r_re0,r_re1}; + double *r_im[2]= {r_im0,r_im1}; uint8_t transmission_mode=1,n_tx_port=1,n_tx_phy=1,n_rx=2; - int eNB_id = 0; unsigned char round; unsigned char i_mod = 2; int NB_RB; - SCM_t channel_model=Rayleigh1; // unsigned char *input_data,*decoded_output; - DCI_ALLOC_t da; DCI_ALLOC_t *dci_alloc = &da; - unsigned int coded_bits_per_codeword=0,nsymb; //,tbs=0; - unsigned int tx_lev=0,tx_lev_dB=0,trials; unsigned int errs[4],errs2[4],round_trials[4],dci_errors[4];//,num_layers; memset(errs,0,4*sizeof(unsigned int)); memset(errs2,0,4*sizeof(unsigned int)); memset(round_trials,0,4*sizeof(unsigned int)); memset(dci_errors,0,4*sizeof(unsigned int)); - //int re_allocated; char fname[32],vname[32]; FILE *bler_fd; @@ -589,25 +531,20 @@ int main(int argc, char **argv) char time_meas_fname[256]; // FILE *tikz_fd; // char tikz_fname[256]; - FILE *input_trch_fd=NULL; unsigned char input_trch_file=0; FILE *input_fd=NULL; unsigned char input_file=0; - channel_desc_t *eNB2UE[4]; //uint8_t num_pdcch_symbols_2=0; //char stats_buffer[4096]; //int len; - //int u; int n=0; //int iii; - int ch_realization; //int pmi_feedback=0; int hold_channel=0; - // void *data; // int ii; // int bler; @@ -617,23 +554,18 @@ int main(int argc, char **argv) frame_t frame_type = FDD; FD_lte_phy_scope_ue *form_ue = NULL; char title[255]; - int numCCE=0; //int dci_length_bytes=0,dci_length=0; //double channel_bandwidth = 5.0, sampling_rate=7.68; int common_flag=0,TPC=0; - double cpu_freq_GHz; // time_stats_t ts;//,sts,usts; int avg_iter,iter_trials; int rballocset=0; int test_passed=0; - double effective_rate=0.0; char channel_model_input[10]="I"; - int TB0_active = 1; - // LTE_DL_UE_HARQ_t *dlsch0_ue_harq; // LTE_DL_eNB_HARQ_t *dlsch0_eNB_harq; uint8_t Kmimo; @@ -642,15 +574,13 @@ int main(int argc, char **argv) int sf; int CCE_table[800]; opp_enabled=1; // to enable the time meas - FILE *csv_fd=NULL; char csv_fname[FILENAME_MAX]; int DLSCH_RB_ALLOC = 0; - int dci_received; PHY_VARS_eNB *eNB; RU_t *ru; - PHY_VARS_UE *UE; + PHY_VARS_UE *UE=NULL; nfapi_dl_config_request_t DL_req; nfapi_ul_config_request_t UL_req; nfapi_hi_dci0_request_t HI_DCI0_req; @@ -659,42 +589,40 @@ int main(int argc, char **argv) nfapi_tx_request_t TX_req; Sched_Rsp_t sched_resp; int pa=dB0; - #if defined(__arm__) FILE *proc_fd = NULL; char buf[64]; - + memset(buf,0,sizeof(buf)); proc_fd = fopen("/sys/devices/system/cpu/cpu4/cpufreq/cpuinfo_cur_freq", "r"); + if(!proc_fd) - printf("cannot open /sys/devices/system/cpu/cpu4/cpufreq/cpuinfo_cur_freq"); + printf("cannot open /sys/devices/system/cpu/cpu4/cpufreq/cpuinfo_cur_freq"); else { - while(fgets(buf, 63, proc_fd)) - printf("%s", buf); + while(fgets(buf, 63, proc_fd)) + printf("%s", buf); } + fclose(proc_fd); cpu_freq_GHz = ((double)atof(buf))/1e6; #else cpu_freq_GHz = get_cpu_freq_GHz(); #endif printf("Detected cpu_freq %f GHz\n",cpu_freq_GHz); - memset((void*)&sched_resp,0,sizeof(sched_resp)); + memset((void *)&sched_resp,0,sizeof(sched_resp)); sched_resp.DL_req = &DL_req; sched_resp.UL_req = &UL_req; sched_resp.HI_DCI0_req = &HI_DCI0_req; sched_resp.TX_req = &TX_req; - memset((void*)&DL_req,0,sizeof(DL_req)); - memset((void*)&UL_req,0,sizeof(UL_req)); - memset((void*)&HI_DCI0_req,0,sizeof(HI_DCI0_req)); - memset((void*)&TX_req,0,sizeof(TX_req)); - + memset((void *)&DL_req,0,sizeof(DL_req)); + memset((void *)&UL_req,0,sizeof(UL_req)); + memset((void *)&HI_DCI0_req,0,sizeof(HI_DCI0_req)); + memset((void *)&TX_req,0,sizeof(TX_req)); DL_req.dl_config_request_body.dl_config_pdu_list = dl_config_pdu_list; TX_req.tx_request_body.tx_pdu_list = tx_pdu_list; set_parallel_conf("PARALLEL_SINGLE_THREAD"); cpuf = cpu_freq_GHz; - //signal(SIGSEGV, handler); //signal(SIGABRT, handler); - // default parameters n_frames = 1000; snr0 = 0; @@ -748,13 +676,8 @@ int main(int argc, char **argv) { "help", "display help and exit", PARAMFLAG_BOOL, iptr:&help, defintval:0, TYPE_INT, 0 }, { "", "",0, iptr:NULL, defintval:0, TYPE_INT, 0 }, }; - - - struct option * long_options = parse_oai_options(options); - - + struct option *long_options = parse_oai_options(options); int option_index; - int res; while ((res=getopt_long_only(argc, argv, "", long_options, &option_index)) == 0) { @@ -769,16 +692,16 @@ int main(int argc, char **argv) case TYPE_DOUBLE: *(double *)options[option_index].dblptr=atof(optarg); break; - - case TYPE_UINT8: - *(uint8_t *)options[option_index].dblptr=atoi(optarg); - break; - - case TYPE_UINT16: - *(uint16_t *)options[option_index].dblptr=atoi(optarg); - break; - - default: + + case TYPE_UINT8: + *(uint8_t *)options[option_index].dblptr=atoi(optarg); + break; + + case TYPE_UINT16: + *(uint16_t *)options[option_index].dblptr=atoi(optarg); + break; + + default: printf("not decoded type.\n"); exit(1); } @@ -787,51 +710,51 @@ int main(int argc, char **argv) } switch (long_options[option_index].name[0]) { - case 'a': - awgn_flag = 1; - channel_model = AWGN; - break; + case 'a': + awgn_flag = 1; + channel_model = AWGN; + break; - case 'D': - frame_type=TDD; - break; + case 'D': + frame_type=TDD; + break; - case 'e': - num_rounds=1; - common_flag = 1; - TPC = atoi(optarg); - break; + case 'e': + num_rounds=1; + common_flag = 1; + TPC = atoi(optarg); + break; - case 'i': - input_fd = fopen(optarg,"r"); - input_file=1; - dci_flag = 1; - break; + case 'i': + input_fd = fopen(optarg,"r"); + input_file=1; + dci_flag = 1; + break; - case 'I': - input_trch_fd = fopen(optarg,"r"); - input_trch_file=1; - break; + case 'I': + input_trch_fd = fopen(optarg,"r"); + input_trch_file=1; + break; - case 't': - mcs_i = atoi(optarg); - i_mod = get_Qm(mcs_i); - break; + case 't': + mcs_i = atoi(optarg); + i_mod = get_Qm(mcs_i); + break; - case 'r': - DLSCH_RB_ALLOC = atoi(optarg); - rballocset = 1; - break; + case 'r': + DLSCH_RB_ALLOC = atoi(optarg); + rballocset = 1; + break; - case 'g': - strncpy(channel_model_input,optarg,9); - struct tmp { - char opt; - int m; - int M; - } - tmp[]= { - {'A',SCM_A,2}, + case 'g': + strncpy(channel_model_input,optarg,9); + struct tmp { + char opt; + int m; + int M; + } + tmp[]= { + {'A',SCM_A,2}, {'B',SCM_B,3}, {'C',SCM_C,4}, {'D',SCM_D,5}, @@ -858,96 +781,99 @@ int main(int argc, char **argv) AssertFatal(ptr->opt != 0, "Unsupported channel model: %s !\n", optarg ); break; - case 'u': - dual_stream_UE=1; - UE->use_ia_receiver = 1; - - if ((n_tx_port!=2) || (transmission_mode!=5)) { - printf("IA receiver only supported for TM5!"); - exit(-1); - } - - break; + case 'u': + dual_stream_UE=1; + if (UE != NULL) + UE->use_ia_receiver = 1; + else { + printf("UE is NULL\n"); + exit(-1); + } + if ((n_tx_port!=2) || (transmission_mode!=5)) { + printf("IA receiver only supported for TM5!"); + exit(-1); + } - case 'v': - i_mod = atoi(optarg); + break; - if (i_mod!=2 && i_mod!=4 && i_mod!=6) { - printf("Wrong i_mod %d, should be 2,4 or 6\n",i_mod); - exit(-1); - } + case 'v': + i_mod = atoi(optarg); - break; + if (i_mod!=2 && i_mod!=4 && i_mod!=6) { + printf("Wrong i_mod %d, should be 2,4 or 6\n",i_mod); + exit(-1); + } - case 'q': - n_tx_port=atoi(optarg); + break; - if ((n_tx_port==0) || ((n_tx_port>2))) { - printf("Unsupported number of cell specific antennas ports %d\n",n_tx_port); - exit(-1); - } + case 'q': + n_tx_port=atoi(optarg); - break; + if ((n_tx_port==0) || ((n_tx_port>2))) { + printf("Unsupported number of cell specific antennas ports %d\n",n_tx_port); + exit(-1); + } + break; - case 'x': - transmission_mode=atoi(optarg); + case 'x': + transmission_mode=atoi(optarg); + + if ((transmission_mode!=1) && + (transmission_mode!=2) && + (transmission_mode!=3) && + (transmission_mode!=4) && + (transmission_mode!=5) && + (transmission_mode!=6) && + (transmission_mode!=7)) { + printf("Unsupported transmission mode %d\n",transmission_mode); + exit(-1); + } - if ((transmission_mode!=1) && - (transmission_mode!=2) && - (transmission_mode!=3) && - (transmission_mode!=4) && - (transmission_mode!=5) && - (transmission_mode!=6) && - (transmission_mode!=7)) { - printf("Unsupported transmission mode %d\n",transmission_mode); - exit(-1); - } + if (transmission_mode>1 && transmission_mode<7) { + n_tx_port = 2; + } - if (transmission_mode>1 && transmission_mode<7) { - n_tx_port = 2; - } + break; - break; + case 'y': + n_tx_phy=atoi(optarg); - case 'y': - n_tx_phy=atoi(optarg); + if (n_tx_phy < n_tx_port) { + printf("n_tx_phy mush not be smaller than n_tx_port"); + exit(-1); + } - if (n_tx_phy < n_tx_port) { - printf("n_tx_phy mush not be smaller than n_tx_port"); - exit(-1); - } + if ((transmission_mode>1 && transmission_mode<7) && n_tx_port<2) { + printf("n_tx_port must be >1 for transmission_mode %d\n",transmission_mode); + exit(-1); + } - if ((transmission_mode>1 && transmission_mode<7) && n_tx_port<2) { - printf("n_tx_port must be >1 for transmission_mode %d\n",transmission_mode); - exit(-1); - } + if (transmission_mode==7 && (n_tx_phy!=1 && n_tx_phy!=2 && n_tx_phy!=4 && n_tx_phy!=8 && n_tx_phy!=16 && n_tx_phy!=64 && n_tx_phy!=128)) { + printf("Physical number of antennas not supported for TM7.\n"); + exit(-1); + } - if (transmission_mode==7 && (n_tx_phy!=1 && n_tx_phy!=2 && n_tx_phy!=4 && n_tx_phy!=8 && n_tx_phy!=16 && n_tx_phy!=64 && n_tx_phy!=128)) { - printf("Physical number of antennas not supported for TM7.\n"); - exit(-1); - } + break; - break; + case 'z': + n_rx=atoi(optarg); - case 'z': - n_rx=atoi(optarg); + if ((n_rx==0) || (n_rx>2)) { + printf("Unsupported number of rx antennas %d\n",n_rx); + exit(-1); + } - if ((n_rx==0) || (n_rx>2)) { - printf("Unsupported number of rx antennas %d\n",n_rx); - exit(-1); - } + break; - break; + case 'Q': + set_parallel_conf(optarg); + break; - case 'Q': - set_parallel_conf(optarg); - break; - - default: - printf("Wrong option: %s\n",long_options[option_index].name); - exit(1); - break; + default: + printf("Wrong option: %s\n",long_options[option_index].name); + exit(1); + break; } } @@ -957,18 +883,19 @@ int main(int argc, char **argv) } if (help || verbose ) - display_options_values(options, true); + display_options_values(options, true); + if (help) exit(0); - + if (thread_struct.parallel_conf != PARALLEL_SINGLE_THREAD) set_worker_conf("WORKER_ENABLE"); if (transmission_mode>1) pa=dBm3; - printf("dlsim: tmode %d, pa %d\n",transmission_mode,pa); + printf("dlsim: tmode %d, pa %d\n",transmission_mode,pa); AssertFatal(load_configmodule(argc,argv, CONFIG_ENABLECMDLINEONLY) != NULL, - "cannot load configuration module, exiting\n"); + "cannot load configuration module, exiting\n"); logInit(); set_glog_onlinelog(true); // enable these lines if you need debug info @@ -981,29 +908,33 @@ int main(int argc, char **argv) if (common_flag == 0) { switch (N_RB_DL) { - case 6: - if (rballocset==0) DLSCH_RB_ALLOC = 0x3f; - num_pdcch_symbols = 3; - break; - - case 25: - if (rballocset==0) DLSCH_RB_ALLOC = 0x1fff; - break; - - case 50: - if (rballocset==0) DLSCH_RB_ALLOC = 0x1ffff; - break; - - case 100: - if (rballocset==0) DLSCH_RB_ALLOC = 0x1ffffff; - break; + case 6: + if (rballocset==0) DLSCH_RB_ALLOC = 0x3f; + + num_pdcch_symbols = 3; + break; + + case 25: + if (rballocset==0) DLSCH_RB_ALLOC = 0x1fff; + + break; + + case 50: + if (rballocset==0) DLSCH_RB_ALLOC = 0x1ffff; + + break; + + case 100: + if (rballocset==0) DLSCH_RB_ALLOC = 0x1ffffff; + + break; } - + NB_RB = conv_nprb(0,DLSCH_RB_ALLOC,N_RB_DL); - } - else { + } else { if (rballocset==0) NB_RB = 8; else NB_RB = DLSCH_RB_ALLOC; + AssertFatal(NB_RB <= N_RB_DL,"illegal NB_RB %d\n",NB_RB); } @@ -1014,10 +945,15 @@ int main(int argc, char **argv) fl_show_form (form_ue->lte_phy_scope_ue, FL_PLACE_HOTSPOT, FL_FULLBORDER, title); if (!dual_stream_UE==0) { - UE->use_ia_receiver = 1; - fl_set_button(form_ue->button_0,1); - fl_set_object_label(form_ue->button_0, "IA Receiver ON"); - fl_set_object_color(form_ue->button_0, FL_GREEN, FL_GREEN); + if (UE) { + UE->use_ia_receiver = 1; + fl_set_button(form_ue->button_0,1); + fl_set_object_label(form_ue->button_0, "IA Receiver ON"); + fl_set_object_color(form_ue->button_0, FL_GREEN, FL_GREEN); + } else { + printf("UE is NULL\n"); + exit(-1); + } } } @@ -1025,42 +961,44 @@ int main(int argc, char **argv) n_users = 2; printf("dual_stream_UE=%d\n", dual_stream_UE); } + RC.nb_L1_inst = 1; RC.nb_RU = 1; - lte_param_init(&eNB,&UE,&ru, - n_tx_port, - n_tx_phy, - 1, + n_tx_port, + n_tx_phy, + 1, n_rx, - transmission_mode, - extended_prefix_flag, - frame_type, - Nid_cell, - tdd_config, - N_RB_DL, - pa, - threequarter_fs, - osf, - perfect_ce); - RC.eNB = (PHY_VARS_eNB ***)malloc(sizeof(PHY_VARS_eNB **)); + transmission_mode, + extended_prefix_flag, + frame_type, + Nid_cell, + tdd_config, + N_RB_DL, + pa, + threequarter_fs, + osf, + perfect_ce); + RC.eNB = (PHY_VARS_eNB ** *)malloc(sizeof(PHY_VARS_eNB **)); RC.eNB[0] = (PHY_VARS_eNB **)malloc(sizeof(PHY_VARS_eNB *)); RC.ru = (RU_t **)malloc(sizeof(RC.ru)); RC.eNB[0][0] = eNB; RC.ru[0] = ru; printf("lte_param_init done\n"); + if ((transmission_mode==1) || (transmission_mode==7)) { for (aa=0; aa<ru->nb_tx; aa++) - for (re=0; re<ru->frame_parms.ofdm_symbol_size; re++) - ru->beam_weights[0][0][aa][re] = 0x00007fff/eNB->frame_parms.nb_antennas_tx; + for (re=0; re<ru->frame_parms.ofdm_symbol_size; re++) + ru->beam_weights[0][0][aa][re] = 0x00007fff/eNB->frame_parms.nb_antennas_tx; } if (transmission_mode<7) - ru->do_precoding=0; + ru->do_precoding=0; else - ru->do_precoding=1; + ru->do_precoding=1; eNB->mac_enabled=1; + if(get_thread_worker_conf() == WORKER_ENABLE) { extern void init_td_thread(PHY_VARS_eNB *); extern void init_te_thread(PHY_VARS_eNB *); @@ -1069,27 +1007,21 @@ int main(int argc, char **argv) } // callback functions required for phy_procedures_tx - // eNB_id_i = UE->n_connected_eNB; - printf("Setting mcs1 = %d\n",mcs1); printf("Setting mcs2 = %d\n",mcs2); printf("NPRB = %d\n",NB_RB); printf("n_frames = %d\n",n_frames); printf("Transmission mode %d with %dx%d antenna configuration, Extended Prefix %d\n",transmission_mode,n_tx_phy,n_rx,extended_prefix_flag); - snr1 = snr0+snr_int; printf("SNR0 %f, SNR1 %f\n",snr0,snr1); - uint8_t input_buffer[NUMBER_OF_UE_MAX][20000]; - for (i=0;i<n_users;i++) - for (j=0;j<20000;j++) input_buffer[i][j] = (uint8_t)((taus())&255); + for (i=0; i<n_users; i++) + for (j=0; j<20000; j++) input_buffer[i][j] = (uint8_t)((taus())&255); frame_parms = &eNB->frame_parms; - nsymb = (eNB->frame_parms.Ncp == 0) ? 14 : 12; - printf("Channel Model= (%s,%d)\n",channel_model_input, channel_model); printf("SCM-A=%d, SCM-B=%d, SCM-C=%d, SCM-D=%d, EPA=%d, EVA=%d, ETU=%d, Rayleigh8=%d, Rayleigh1=%d, Rayleigh1_corr=%d, Rayleigh1_anticorr=%d, Rice1=%d, Rice8=%d\n", SCM_A, SCM_B, SCM_C, SCM_D, EPA, EVA, ETU, Rayleigh8, Rayleigh1, Rayleigh1_corr, Rayleigh1_anticorr, Rice1, Rice8); @@ -1100,10 +1032,12 @@ int main(int argc, char **argv) sprintf(bler_fname,"bler_tx%d_chan%d_nrx%d_mcs%d.csv",transmission_mode,channel_model,n_rx,mcs1); bler_fd = fopen(bler_fname,"w"); + if (bler_fd==NULL) { fprintf(stderr,"Cannot create file %s!\n",bler_fname); exit(-1); } + fprintf(bler_fd,"SNR; MCS; TBS; rate; err0; trials0; err1; trials1; err2; trials2; err3; trials3; dci_err\n"); if (test_perf != 0) { @@ -1117,6 +1051,7 @@ int main(int argc, char **argv) N_RB_DL,mcs1,n_tx_phy,n_rx,num_pdcch_symbols,channel_model_input,transmission_mode); //mkdir(dirname,0777); time_meas_fd = fopen(time_meas_fname,"w"); + if (time_meas_fd==NULL) { fprintf(stderr,"Cannot create file %s!\n",time_meas_fname); exit(-1); @@ -1127,11 +1062,13 @@ int main(int argc, char **argv) // CSV file sprintf(csv_fname,"dataout_tx%d_u2%d_mcs%d_chan%d_nsimus%d_R%d.m",transmission_mode,dual_stream_UE,mcs1,channel_model,n_frames,num_rounds); csv_fd = fopen(csv_fname,"w"); - fprintf(csv_fd,"data_all%d=[",mcs1); + if (csv_fd==NULL) { fprintf(stderr,"Cannot create file %s!\n",csv_fname); exit(-1); } + + fprintf(csv_fd,"data_all%d=[",mcs1); } /* @@ -1230,38 +1167,35 @@ int main(int argc, char **argv) break; } */ - - UE->pdcch_vars[UE->current_thread_id[subframe]][0]->crnti = n_rnti; UE->n_connected_eNB = 1; - printf("Allocating %dx%d eNB->UE channel descriptor\n",eNB->frame_parms.nb_antennas_tx,UE->frame_parms.nb_antennas_rx); eNB2UE[0] = new_channel_desc_scm(eNB->frame_parms.nb_antennas_tx, UE->frame_parms.nb_antennas_rx, channel_model, N_RB2sampling_rate(eNB->frame_parms.N_RB_DL), - N_RB2channel_bandwidth(eNB->frame_parms.N_RB_DL), + N_RB2channel_bandwidth(eNB->frame_parms.N_RB_DL), forgetting_factor, rx_sample_offset, 0); - reset_meas(&eNB2UE[0]->random_channel); reset_meas(&eNB2UE[0]->interp_time); + if(num_rounds>1) { for(n=1; n<4; n++) { eNB2UE[n] = new_channel_desc_scm(eNB->frame_parms.nb_antennas_tx, UE->frame_parms.nb_antennas_rx, channel_model, - N_RB2sampling_rate(eNB->frame_parms.N_RB_DL), - N_RB2channel_bandwidth(eNB->frame_parms.N_RB_DL), - forgetting_factor, + N_RB2sampling_rate(eNB->frame_parms.N_RB_DL), + N_RB2channel_bandwidth(eNB->frame_parms.N_RB_DL), + forgetting_factor, rx_sample_offset, 0); reset_meas(&eNB2UE[n]->random_channel); reset_meas(&eNB2UE[n]->interp_time); } } - + if (eNB2UE[0]==NULL) { printf("Problem generating channel model. Exiting.\n"); exit(-1); @@ -1273,20 +1207,23 @@ int main(int argc, char **argv) Kmimo=1; switch (ue_category) { - case 1: - Nsoft = 250368; - break; - case 2: - case 3: - Nsoft = 1237248; - break; - case 4: - Nsoft = 1827072; - break; - default: - printf("Unsupported UE category %d\n",ue_category); - exit(-1); - break; + case 1: + Nsoft = 250368; + break; + + case 2: + case 3: + Nsoft = 1237248; + break; + + case 4: + Nsoft = 1827072; + break; + + default: + printf("Unsupported UE category %d\n",ue_category); + exit(-1); + break; } for (k=0; k<NUMBER_OF_UE_MAX; k++) { @@ -1321,15 +1258,13 @@ int main(int argc, char **argv) } } - UE->dlsch_SI[0] = new_ue_dlsch(1,1,Nsoft,MAX_TURBO_ITERATIONS,N_RB_DL,0); - UE->dlsch_ra[0] = new_ue_dlsch(1,1,Nsoft,MAX_TURBO_ITERATIONS,N_RB_DL,0); - UE->ulsch[0] = new_ue_ulsch(N_RB_DL,0); - + UE->dlsch_SI[0] = new_ue_dlsch(1,1,Nsoft,MAX_TURBO_ITERATIONS,N_RB_DL,0); + UE->dlsch_ra[0] = new_ue_dlsch(1,1,Nsoft,MAX_TURBO_ITERATIONS,N_RB_DL,0); + UE->ulsch[0] = new_ue_ulsch(N_RB_DL,0); // structure for SIC at UE UE->dlsch_eNB[0] = new_eNB_dlsch(Kmimo,8,Nsoft,N_RB_DL,0,&eNB->frame_parms); if (DLSCH_alloc_pdu2_1E[0].tpmi == 5) { - eNB->UE_stats[0].DL_pmi_single = (unsigned short)(taus()&0xffff); if (n_users>1) @@ -1344,38 +1279,33 @@ int main(int argc, char **argv) L1_rxtx_proc_t *proc_eNB = &eNB->proc.L1_proc; if (input_fd==NULL) { - DL_req.dl_config_request_body.number_pdcch_ofdm_symbols = num_pdcch_symbols; DL_req.sfn_sf = (proc_eNB->frame_tx<<4)+subframe; TX_req.sfn_sf = (proc_eNB->frame_tx<<4)+subframe; // UE specific DCI fill_DCI(eNB, - proc_eNB->frame_tx,subframe, - &sched_resp, - input_buffer, - n_rnti, - n_users, - transmission_mode, - 0, - common_flag, - NB_RB, - DLSCH_RB_ALLOC, - TPC, - mcs1, - mcs2, - 1, - 0, - pa, - &num_common_dci, - &num_ue_spec_dci, - &num_dci); - + proc_eNB->frame_tx,subframe, + &sched_resp, + input_buffer, + n_rnti, + n_users, + transmission_mode, + 0, + common_flag, + NB_RB, + DLSCH_RB_ALLOC, + TPC, + mcs1, + mcs2, + 1, + 0, + pa, + &num_common_dci, + &num_ue_spec_dci, + &num_dci); numCCE = get_nCCE(num_pdcch_symbols,&eNB->frame_parms,get_mi(&eNB->frame_parms,subframe)); if (n_frames==1) printf("num_pdcch_symbols %d, numCCE %d, num_dci %d/%d/%d\n",num_pdcch_symbols,numCCE, num_dci,num_ue_spec_dci,num_common_dci); - - - } snr_step = input_snr_step; @@ -1401,13 +1331,11 @@ int main(int argc, char **argv) round_trials[1] = 0; round_trials[2] = 0; round_trials[3] = 0; - dci_errors[0]=0; dci_errors[1]=0; dci_errors[2]=0; dci_errors[3]=0; // avg_ber = 0; - round=0; avg_iter = 0; iter_trials=0; @@ -1422,15 +1350,17 @@ int main(int argc, char **argv) reset_meas(&eNB->dlsch_turbo_encoding_stats); reset_meas(&eNB->dlsch_common_and_dci); reset_meas(&eNB->dlsch_ue_specific); + for (int i=0; i<RX_NB_TH; i++) { - reset_meas(&UE->phy_proc_rx[i]); // total UE rx - reset_meas(&UE->ue_front_end_stat[i]); + reset_meas(&UE->phy_proc_rx[i]); // total UE rx + reset_meas(&UE->ue_front_end_stat[i]); reset_meas(&UE->pdsch_procedures_stat[i]); - reset_meas(&UE->dlsch_procedures_stat[i]); - reset_meas(&UE->dlsch_decoding_stats[i]); - reset_meas(&UE->dlsch_llr_stats_parallelization[i][0]); - reset_meas(&UE->dlsch_llr_stats_parallelization[i][1]); + reset_meas(&UE->dlsch_procedures_stat[i]); + reset_meas(&UE->dlsch_decoding_stats[i]); + reset_meas(&UE->dlsch_llr_stats_parallelization[i][0]); + reset_meas(&UE->dlsch_llr_stats_parallelization[i][1]); } + reset_meas(&UE->ofdm_demod_stats); reset_meas(&UE->crnti_procedures_stats); reset_meas(&UE->dlsch_channel_estimation_stats); @@ -1449,7 +1379,7 @@ int main(int argc, char **argv) reset_meas(&UE->dlsch_tc_intl1_stats); reset_meas(&UE->dlsch_tc_intl2_stats); // initialization - // initialization + // initialization varArray_t *table_tx=initVarArray(1000,sizeof(double)); varArray_t *table_tx_ifft=initVarArray(1000,sizeof(double)); varArray_t *table_tx_mod=initVarArray(1000,sizeof(double)); @@ -1466,17 +1396,16 @@ int main(int argc, char **argv) varArray_t *table_rx_dec=initVarArray(1000,sizeof(double)); for (trials = 0; trials<n_frames; trials++) { - //printf("Trial %d\n",trials); + //printf("Trial %d\n",trials); fflush(stdout); round=0; - //if (trials%100==0) eNB2UE[0]->first_run = 1; - UE->dlsch[UE->current_thread_id[subframe]][eNB_id][0]->harq_ack[subframe].ack = 0; - UE->dlsch[UE->current_thread_id[subframe]][eNB_id][1]->harq_ack[subframe].ack = 0; + UE->dlsch[UE->current_thread_id[subframe]][eNB_id][0]->harq_ack[subframe].ack = 0; + UE->dlsch[UE->current_thread_id[subframe]][eNB_id][1]->harq_ack[subframe].ack = 0; while ((round < num_rounds) && (UE->dlsch[UE->current_thread_id[subframe]][eNB_id][0]->harq_ack[subframe].ack == 0)) { - // printf("Trial %d, round %d\n",trials,round); + // printf("Trial %d, round %d\n",trials,round); round_trials[round]++; //if(transmission_mode>=5) @@ -1492,7 +1421,7 @@ int main(int argc, char **argv) } else hold_channel = 0;//(round==0) ? 0 : 1; - //PMI_FEEDBACK: + //PMI_FEEDBACK: // printf("Trial %d : Round %d, pmi_feedback %d \n",trials,round,pmi_feedback); for (aa=0; aa<eNB->frame_parms.nb_antennas_tx; aa++) { @@ -1500,91 +1429,73 @@ int main(int argc, char **argv) } if (input_fd==NULL) { - - // Simulate HARQ procedures!!! - memset(CCE_table,0,800*sizeof(int)); - if (/*common_flag == 0*/ 1) { + memset(CCE_table,0,800*sizeof(int)); - num_dci=0; - num_common_dci=0; - num_ue_spec_dci=0; + if (/*common_flag == 0*/ 1) { + num_dci=0; + num_common_dci=0; + num_ue_spec_dci=0; if (round == 0) { // First round TB0_active = 1; - eNB->dlsch[0][0]->harq_processes[0]->rvidx = round&3; - DL_req.sfn_sf = (proc_eNB->frame_tx<<4)+subframe; - TX_req.sfn_sf = (proc_eNB->frame_tx<<4)+subframe; - fill_DCI(eNB,proc_eNB->frame_tx,subframe,&sched_resp,input_buffer,n_rnti,n_users,transmission_mode,0,common_flag,NB_RB,DLSCH_RB_ALLOC,TPC, - mcs1,mcs2,!(trials&1),round&3,pa,&num_common_dci,&num_ue_spec_dci,&num_dci); - } - else { - DL_req.sfn_sf = (proc_eNB->frame_tx<<4)+subframe; - TX_req.sfn_sf = (proc_eNB->frame_tx<<4)+subframe; - fill_DCI(eNB,proc_eNB->frame_tx,subframe,&sched_resp,input_buffer,n_rnti,n_users,transmission_mode,1,common_flag,NB_RB,DLSCH_RB_ALLOC,TPC, - (TB0_active==1)?mcs1:0,mcs2,!(trials&1),(TB0_active==1)?round&3:0,pa,&num_common_dci,&num_ue_spec_dci,&num_dci); - } - } - - proc_eNB->subframe_tx = subframe; - sched_resp.subframe=subframe; - sched_resp.frame=proc_eNB->frame_tx; - - eNB->abstraction_flag=0; - schedule_response(&sched_resp); - phy_procedures_eNB_TX(eNB,proc_eNB,1); - - if (uncoded_ber_bit == NULL) { - // this is for user 0 only - printf("nb_rb %d, rb_alloc %x, mcs %d\n", - eNB->dlsch[0][0]->harq_processes[0]->nb_rb, - eNB->dlsch[0][0]->harq_processes[0]->rb_alloc[0], - eNB->dlsch[0][0]->harq_processes[0]->mcs); - - coded_bits_per_codeword = get_G(&eNB->frame_parms, - eNB->dlsch[0][0]->harq_processes[0]->nb_rb, - eNB->dlsch[0][0]->harq_processes[0]->rb_alloc, - get_Qm(eNB->dlsch[0][0]->harq_processes[0]->mcs), - eNB->dlsch[0][0]->harq_processes[0]->Nl, - num_pdcch_symbols, - 0, - subframe, - transmission_mode>=7?transmission_mode:0); - - uncoded_ber_bit = (short*) malloc(sizeof(short)*coded_bits_per_codeword); - printf("uncoded_ber_bit=%p\n",uncoded_ber_bit); - } - - start_meas(&eNB->ofdm_mod_stats); - - ru->proc.subframe_tx=subframe; - memcpy((void*)&ru->frame_parms,(void*)&eNB->frame_parms,sizeof(LTE_DL_FRAME_PARMS)); - feptx_prec(ru); - feptx_ofdm(ru); - - stop_meas(&eNB->ofdm_mod_stats); - - - - // generate next subframe for channel estimation - - DL_req.dl_config_request_body.number_dci=0; - DL_req.dl_config_request_body.number_pdu=0; - TX_req.tx_request_body.number_of_pdus=0; - proc_eNB->subframe_tx = subframe+1; - sched_resp.subframe=subframe+1; - schedule_response(&sched_resp); - phy_procedures_eNB_TX(eNB,proc_eNB,0); - - - ru->proc.subframe_tx=(subframe+1)%10; - feptx_prec(ru); - feptx_ofdm(ru); - + DL_req.sfn_sf = (proc_eNB->frame_tx<<4)+subframe; + TX_req.sfn_sf = (proc_eNB->frame_tx<<4)+subframe; + fill_DCI(eNB,proc_eNB->frame_tx,subframe,&sched_resp,input_buffer,n_rnti,n_users,transmission_mode,0,common_flag,NB_RB,DLSCH_RB_ALLOC,TPC, + mcs1,mcs2,!(trials&1),round&3,pa,&num_common_dci,&num_ue_spec_dci,&num_dci); + } else { + DL_req.sfn_sf = (proc_eNB->frame_tx<<4)+subframe; + TX_req.sfn_sf = (proc_eNB->frame_tx<<4)+subframe; + fill_DCI(eNB,proc_eNB->frame_tx,subframe,&sched_resp,input_buffer,n_rnti,n_users,transmission_mode,1,common_flag,NB_RB,DLSCH_RB_ALLOC,TPC, + (TB0_active==1)?mcs1:0,mcs2,!(trials&1),(TB0_active==1)?round&3:0,pa,&num_common_dci,&num_ue_spec_dci,&num_dci); + } + } - proc_eNB->frame_tx++; + proc_eNB->subframe_tx = subframe; + sched_resp.subframe=subframe; + sched_resp.frame=proc_eNB->frame_tx; + eNB->abstraction_flag=0; + schedule_response(&sched_resp); + phy_procedures_eNB_TX(eNB,proc_eNB,1); + + if (uncoded_ber_bit == NULL) { + // this is for user 0 only + printf("nb_rb %d, rb_alloc %x, mcs %d\n", + eNB->dlsch[0][0]->harq_processes[0]->nb_rb, + eNB->dlsch[0][0]->harq_processes[0]->rb_alloc[0], + eNB->dlsch[0][0]->harq_processes[0]->mcs); + coded_bits_per_codeword = get_G(&eNB->frame_parms, + eNB->dlsch[0][0]->harq_processes[0]->nb_rb, + eNB->dlsch[0][0]->harq_processes[0]->rb_alloc, + get_Qm(eNB->dlsch[0][0]->harq_processes[0]->mcs), + eNB->dlsch[0][0]->harq_processes[0]->Nl, + num_pdcch_symbols, + 0, + subframe, + transmission_mode>=7?transmission_mode:0); + uncoded_ber_bit = (short *) malloc(sizeof(short)*coded_bits_per_codeword); + printf("uncoded_ber_bit=%p\n",uncoded_ber_bit); + } + start_meas(&eNB->ofdm_mod_stats); + ru->proc.subframe_tx=subframe; + memcpy((void *)&ru->frame_parms,(void *)&eNB->frame_parms,sizeof(LTE_DL_FRAME_PARMS)); + feptx_prec(ru); + feptx_ofdm(ru); + stop_meas(&eNB->ofdm_mod_stats); + // generate next subframe for channel estimation + DL_req.dl_config_request_body.number_dci=0; + DL_req.dl_config_request_body.number_pdu=0; + TX_req.tx_request_body.number_of_pdus=0; + proc_eNB->subframe_tx = subframe+1; + sched_resp.subframe=subframe+1; + schedule_response(&sched_resp); + phy_procedures_eNB_TX(eNB,proc_eNB,0); + ru->proc.subframe_tx=(subframe+1)%10; + feptx_prec(ru); + feptx_ofdm(ru); + proc_eNB->frame_tx++; tx_lev = 0; for (aa=0; aa<eNB->frame_parms.nb_antennas_tx; aa++) { @@ -1595,176 +1506,153 @@ int main(int argc, char **argv) tx_lev_dB = (unsigned int) dB_fixed(tx_lev); - - if (n_frames==1) { - printf("tx_lev = %d (%d dB)\n",tx_lev,tx_lev_dB); - + printf("tx_lev = %u (%u dB)\n",tx_lev,tx_lev_dB); LOG_M("txsig0.m","txs0", &ru->common.txdata[0][subframe* eNB->frame_parms.samples_per_tti], eNB->frame_parms.samples_per_tti,1,1); if (transmission_mode<7) { - LOG_M("txsigF0.m","txsF0x", &ru->common.txdataF_BF[0][subframe*nsymb*eNB->frame_parms.ofdm_symbol_size],nsymb*eNB->frame_parms.ofdm_symbol_size,1,1); + LOG_M("txsigF0.m","txsF0x", &ru->common.txdataF_BF[0][subframe*nsymb*eNB->frame_parms.ofdm_symbol_size],nsymb*eNB->frame_parms.ofdm_symbol_size,1,1); } else if (transmission_mode == 7) { LOG_M("txsigF0.m","txsF0", &ru->common.txdataF_BF[5][subframe*nsymb*eNB->frame_parms.ofdm_symbol_size],nsymb*eNB->frame_parms.ofdm_symbol_size,1,1); LOG_M("txsigF0_BF.m","txsF0_BF", &ru->common.txdataF_BF[0][0],eNB->frame_parms.ofdm_symbol_size,1,1); } } - } - - DL_channel(ru,UE,subframe,awgn_flag,SNR,tx_lev,hold_channel,abstx,num_rounds,trials,round,eNB2UE,s_re,s_im,r_re,r_im,csv_fd); - - - UE_rxtx_proc_t *proc = &UE->proc.proc_rxtx[UE->current_thread_id[subframe]]; - proc->subframe_rx = subframe; - UE->UE_mode[0] = PUSCH; - - // first symbol has to be done separately in one-shot mode - slot_fep(UE, - 0, - (proc->subframe_rx<<1), - UE->rx_offset, - 0, - 0); - - if (n_frames==1) printf("Running phy_procedures_UE_RX\n"); - - if (dci_flag==0) { - memcpy(dci_alloc,eNB->pdcch_vars[subframe&1].dci_alloc,num_dci*sizeof(DCI_ALLOC_t)); - UE->pdcch_vars[UE->current_thread_id[proc->subframe_rx]][eNB_id]->num_pdcch_symbols = num_pdcch_symbols; - if (n_frames==1) - printf("bypassing PDCCH/DCI detection\n"); - if (generate_ue_dlsch_params_from_dci(proc->frame_rx, - proc->subframe_rx, - (void *)&dci_alloc[0].dci_pdu, - common_flag == 0 ? n_rnti : SI_RNTI, - dci_alloc[0].format, - UE->pdcch_vars[UE->current_thread_id[proc->subframe_rx]][eNB_id], - UE->pdsch_vars[UE->current_thread_id[proc->subframe_rx]][eNB_id], - UE->dlsch[UE->current_thread_id[proc->subframe_rx]][0], - &UE->frame_parms, - UE->pdsch_config_dedicated, - SI_RNTI, - 0, - P_RNTI, - UE->transmission_mode[eNB_id]<7?0:UE->transmission_mode[eNB_id], - 0)==0) { - - dump_dci(&UE->frame_parms, &dci_alloc[0]); - - //UE->dlsch[UE->current_thread_id[proc->subframe_rx]][eNB_id][0]->active = 1; - //UE->dlsch[UE->current_thread_id[proc->subframe_rx]][eNB_id][1]->active = 1; - - UE->pdcch_vars[UE->current_thread_id[proc->subframe_rx]][eNB_id]->num_pdcch_symbols = num_pdcch_symbols; - - UE->dlsch_received[eNB_id]++; - } else { - LOG_E(PHY,"Problem in DCI!\n"); - } - } - - dci_received = UE->pdcch_vars[UE->current_thread_id[proc->subframe_rx]][eNB_id]->dci_received; - - phy_procedures_UE_RX(UE,proc,0,0,dci_flag,normal_txrx); - - dci_received = dci_received - UE->pdcch_vars[UE->current_thread_id[proc->subframe_rx]][eNB_id]->dci_received; - - if (dci_flag && (dci_received == 0)) { - printf("DCI not received\n"); - dci_errors[round]++; - - LOG_M("pdcchF0_ext.m","pdcchF_ext", UE->pdcch_vars[0][eNB_id]->rxdataF_ext[0],2*3*UE->frame_parms.ofdm_symbol_size,1,1); - LOG_M("pdcch00_ch0_ext.m","pdcch00_ch0_ext",UE->pdcch_vars[0][eNB_id]->dl_ch_estimates_ext[0],300*3,1,1); - - LOG_M("pdcch_rxF_comp0.m","pdcch0_rxF_comp0",UE->pdcch_vars[0][eNB_id]->rxdataF_comp[0],4*300,1,1); - LOG_M("pdcch_rxF_llr.m","pdcch_llr",UE->pdcch_vars[0][eNB_id]->llr,2400,1,4); - - LOG_M("rxsig0.m","rxs0", &UE->common_vars.rxdata[0][0],10*UE->frame_parms.samples_per_tti,1,1); - LOG_M("rxsigF0.m","rxsF0", &UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].rxdataF[0][0],UE->frame_parms.ofdm_symbol_size*nsymb,1,1); - - - exit(-1); + } - } + DL_channel(ru,UE,subframe,awgn_flag,SNR,tx_lev,hold_channel,abstx,num_rounds,trials,round,eNB2UE,s_re,s_im,r_re,r_im,csv_fd); + UE_rxtx_proc_t *proc = &UE->proc.proc_rxtx[UE->current_thread_id[subframe]]; + proc->subframe_rx = subframe; + UE->UE_mode[0] = PUSCH; + // first symbol has to be done separately in one-shot mode + slot_fep(UE, + 0, + (proc->subframe_rx<<1), + UE->rx_offset, + 0, + 0); - int bit_errors=0; - if ((test_perf ==0 ) && (n_frames==1)) { + if (n_frames==1) printf("Running phy_procedures_UE_RX\n"); - dlsch_unscrambling(&eNB->frame_parms, - 0, - UE->dlsch[UE->current_thread_id[subframe]][0][0], - coded_bits_per_codeword, - UE->pdsch_vars[UE->current_thread_id[subframe]][0]->llr[0], - 0, - subframe<<1); - for (i=0;i<coded_bits_per_codeword;i++) - if ((eNB->dlsch[0][0]->harq_processes[0]->e[i]==1 && UE->pdsch_vars[UE->current_thread_id[subframe]][0]->llr[0][i] > 0)|| - (eNB->dlsch[0][0]->harq_processes[0]->e[i]==0 && UE->pdsch_vars[UE->current_thread_id[subframe]][0]->llr[0][i] < 0)) { - uncoded_ber_bit[bit_errors++] = 1; - printf("error in pos %d : %d => %d\n",i, - eNB->dlsch[0][0]->harq_processes[0]->e[i], - UE->pdsch_vars[UE->current_thread_id[subframe]][0]->llr[0][i]); - } - else { - /* - printf("no error in pos %d : %d => %d\n",i, - eNB->dlsch[0][0]->harq_processes[0]->e[i], - UE->pdsch_vars[UE->current_thread_id[subframe]][0]->llr[0][i]); - */ - } - - LOG_M("dlsch_ber_bit.m","ber_bit",uncoded_ber_bit,coded_bits_per_codeword,1,0); - LOG_M("ch0.m","ch0",eNB2UE[0]->ch[0],eNB2UE[0]->channel_length,1,8); - - if (eNB->frame_parms.nb_antennas_tx>1) - LOG_M("ch1.m","ch1",eNB2UE[0]->ch[eNB->frame_parms.nb_antennas_rx],eNB2UE[0]->channel_length,1,8); - - //common vars - LOG_M("rxsig0.m","rxs0", &UE->common_vars.rxdata[0][0],10*UE->frame_parms.samples_per_tti,1,1); - - LOG_M("rxsigF0.m","rxsF0", &UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].rxdataF[0][0],UE->frame_parms.ofdm_symbol_size*nsymb,1,1); - - if (UE->frame_parms.nb_antennas_rx>1) { - LOG_M("rxsig1.m","rxs1", UE->common_vars.rxdata[1],UE->frame_parms.samples_per_tti,1,1); - LOG_M("rxsigF1.m","rxsF1", UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].rxdataF[1],UE->frame_parms.ofdm_symbol_size*nsymb,1,1); - } - - LOG_M("dlsch00_r0.m","dl00_r0", - &(UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].dl_ch_estimates[eNB_id][0][0]), - UE->frame_parms.ofdm_symbol_size*nsymb,1,1); - - if (UE->frame_parms.nb_antennas_rx>1) - LOG_M("dlsch01_r0.m","dl01_r0", - &(UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].dl_ch_estimates[eNB_id][1][0]), - UE->frame_parms.ofdm_symbol_size*nsymb,1,1); + if (dci_flag==0) { + memcpy(dci_alloc,eNB->pdcch_vars[subframe&1].dci_alloc,num_dci*sizeof(DCI_ALLOC_t)); + UE->pdcch_vars[UE->current_thread_id[proc->subframe_rx]][eNB_id]->num_pdcch_symbols = num_pdcch_symbols; - if (eNB->frame_parms.nb_antennas_tx>1) - LOG_M("dlsch10_r0.m","dl10_r0", - &(UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].dl_ch_estimates[eNB_id][2][0]), - UE->frame_parms.ofdm_symbol_size*nsymb,1,1); + if (n_frames==1) + printf("bypassing PDCCH/DCI detection\n"); + + if (generate_ue_dlsch_params_from_dci(proc->frame_rx, + proc->subframe_rx, + (void *)&dci_alloc[0].dci_pdu, + common_flag == 0 ? n_rnti : SI_RNTI, + dci_alloc[0].format, + UE->pdcch_vars[UE->current_thread_id[proc->subframe_rx]][eNB_id], + UE->pdsch_vars[UE->current_thread_id[proc->subframe_rx]][eNB_id], + UE->dlsch[UE->current_thread_id[proc->subframe_rx]][0], + &UE->frame_parms, + UE->pdsch_config_dedicated, + SI_RNTI, + 0, + P_RNTI, + UE->transmission_mode[eNB_id]<7?0:UE->transmission_mode[eNB_id], + 0)==0) { + dump_dci(&UE->frame_parms, &dci_alloc[0]); + //UE->dlsch[UE->current_thread_id[proc->subframe_rx]][eNB_id][0]->active = 1; + //UE->dlsch[UE->current_thread_id[proc->subframe_rx]][eNB_id][1]->active = 1; + UE->pdcch_vars[UE->current_thread_id[proc->subframe_rx]][eNB_id]->num_pdcch_symbols = num_pdcch_symbols; + UE->dlsch_received[eNB_id]++; + } else { + LOG_E(PHY,"Problem in DCI!\n"); + } + } - if ((UE->frame_parms.nb_antennas_rx>1) && (eNB->frame_parms.nb_antennas_tx>1)) - LOG_M("dlsch11_r0.m","dl11_r0", - &(UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].dl_ch_estimates[eNB_id][3][0]), - UE->frame_parms.ofdm_symbol_size*nsymb/2,1,1); + dci_received = UE->pdcch_vars[UE->current_thread_id[proc->subframe_rx]][eNB_id]->dci_received; + phy_procedures_UE_RX(UE,proc,0,0,dci_flag,normal_txrx); + dci_received = dci_received - UE->pdcch_vars[UE->current_thread_id[proc->subframe_rx]][eNB_id]->dci_received; + + if (dci_flag && (dci_received == 0)) { + printf("DCI not received\n"); + dci_errors[round]++; + LOG_M("pdcchF0_ext.m","pdcchF_ext", UE->pdcch_vars[0][eNB_id]->rxdataF_ext[0],2*3*UE->frame_parms.ofdm_symbol_size,1,1); + LOG_M("pdcch00_ch0_ext.m","pdcch00_ch0_ext",UE->pdcch_vars[0][eNB_id]->dl_ch_estimates_ext[0],300*3,1,1); + LOG_M("pdcch_rxF_comp0.m","pdcch0_rxF_comp0",UE->pdcch_vars[0][eNB_id]->rxdataF_comp[0],4*300,1,1); + LOG_M("pdcch_rxF_llr.m","pdcch_llr",UE->pdcch_vars[0][eNB_id]->llr,2400,1,4); + LOG_M("rxsig0.m","rxs0", &UE->common_vars.rxdata[0][0],10*UE->frame_parms.samples_per_tti,1,1); + LOG_M("rxsigF0.m","rxsF0", &UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].rxdataF[0][0],UE->frame_parms.ofdm_symbol_size*nsymb,1,1); + exit(-1); + } - //pdsch_vars - printf("coded_bits_per_codeword %d\n",coded_bits_per_codeword); + int bit_errors=0; + + if ((test_perf ==0 ) && (n_frames==1)) { + dlsch_unscrambling(&eNB->frame_parms, + 0, + UE->dlsch[UE->current_thread_id[subframe]][0][0], + coded_bits_per_codeword, + UE->pdsch_vars[UE->current_thread_id[subframe]][0]->llr[0], + 0, + subframe<<1); + + for (i=0; i<coded_bits_per_codeword; i++) + if ((eNB->dlsch[0][0]->harq_processes[0]->e[i]==1 && UE->pdsch_vars[UE->current_thread_id[subframe]][0]->llr[0][i] > 0)|| + (eNB->dlsch[0][0]->harq_processes[0]->e[i]==0 && UE->pdsch_vars[UE->current_thread_id[subframe]][0]->llr[0][i] < 0)) { + uncoded_ber_bit[bit_errors++] = 1; + printf("error in pos %d : %d => %d\n",i, + eNB->dlsch[0][0]->harq_processes[0]->e[i], + UE->pdsch_vars[UE->current_thread_id[subframe]][0]->llr[0][i]); + } else { + /* + printf("no error in pos %d : %d => %d\n",i, + eNB->dlsch[0][0]->harq_processes[0]->e[i], + UE->pdsch_vars[UE->current_thread_id[subframe]][0]->llr[0][i]); + */ + } - dump_dlsch2(UE,eNB_id,subframe,&coded_bits_per_codeword,round, UE->dlsch[UE->current_thread_id[subframe]][0][0]->current_harq_pid); + LOG_M("dlsch_ber_bit.m","ber_bit",uncoded_ber_bit,coded_bits_per_codeword,1,0); + LOG_M("ch0.m","ch0",eNB2UE[0]->ch[0],eNB2UE[0]->channel_length,1,8); - LOG_M("dlsch_e.m","e",eNB->dlsch[0][0]->harq_processes[0]->e,coded_bits_per_codeword,1,4); + if (eNB->frame_parms.nb_antennas_tx>1) + LOG_M("ch1.m","ch1",eNB2UE[0]->ch[eNB->frame_parms.nb_antennas_rx],eNB2UE[0]->channel_length,1,8); - //pdcch_vars - LOG_M("pdcchF0_ext.m","pdcchF_ext", UE->pdcch_vars[0][eNB_id]->rxdataF_ext[0],2*3*UE->frame_parms.ofdm_symbol_size,1,1); - LOG_M("pdcch00_ch0_ext.m","pdcch00_ch0_ext",UE->pdcch_vars[0][eNB_id]->dl_ch_estimates_ext[0],300*3,1,1); + //common vars + LOG_M("rxsig0.m","rxs0", &UE->common_vars.rxdata[0][0],10*UE->frame_parms.samples_per_tti,1,1); + LOG_M("rxsigF0.m","rxsF0", &UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].rxdataF[0][0],UE->frame_parms.ofdm_symbol_size*nsymb,1,1); - LOG_M("pdcch_rxF_comp0.m","pdcch0_rxF_comp0",UE->pdcch_vars[0][eNB_id]->rxdataF_comp[0],4*300,1,1); - LOG_M("pdcch_rxF_llr.m","pdcch_llr",UE->pdcch_vars[0][eNB_id]->llr,2400,1,4); + if (UE->frame_parms.nb_antennas_rx>1) { + LOG_M("rxsig1.m","rxs1", UE->common_vars.rxdata[1],UE->frame_parms.samples_per_tti,1,1); + LOG_M("rxsigF1.m","rxsF1", UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].rxdataF[1],UE->frame_parms.ofdm_symbol_size*nsymb,1,1); + } - } + LOG_M("dlsch00_r0.m","dl00_r0", + &(UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].dl_ch_estimates[eNB_id][0][0]), + UE->frame_parms.ofdm_symbol_size*nsymb,1,1); + + if (UE->frame_parms.nb_antennas_rx>1) + LOG_M("dlsch01_r0.m","dl01_r0", + &(UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].dl_ch_estimates[eNB_id][1][0]), + UE->frame_parms.ofdm_symbol_size*nsymb,1,1); + + if (eNB->frame_parms.nb_antennas_tx>1) + LOG_M("dlsch10_r0.m","dl10_r0", + &(UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].dl_ch_estimates[eNB_id][2][0]), + UE->frame_parms.ofdm_symbol_size*nsymb,1,1); + + if ((UE->frame_parms.nb_antennas_rx>1) && (eNB->frame_parms.nb_antennas_tx>1)) + LOG_M("dlsch11_r0.m","dl11_r0", + &(UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].dl_ch_estimates[eNB_id][3][0]), + UE->frame_parms.ofdm_symbol_size*nsymb/2,1,1); + + //pdsch_vars + printf("coded_bits_per_codeword %u\n",coded_bits_per_codeword); + dump_dlsch2(UE,eNB_id,subframe,&coded_bits_per_codeword,round, UE->dlsch[UE->current_thread_id[subframe]][0][0]->current_harq_pid); + LOG_M("dlsch_e.m","e",eNB->dlsch[0][0]->harq_processes[0]->e,coded_bits_per_codeword,1,4); + //pdcch_vars + LOG_M("pdcchF0_ext.m","pdcchF_ext", UE->pdcch_vars[0][eNB_id]->rxdataF_ext[0],2*3*UE->frame_parms.ofdm_symbol_size,1,1); + LOG_M("pdcch00_ch0_ext.m","pdcch00_ch0_ext",UE->pdcch_vars[0][eNB_id]->dl_ch_estimates_ext[0],300*3,1,1); + LOG_M("pdcch_rxF_comp0.m","pdcch0_rxF_comp0",UE->pdcch_vars[0][eNB_id]->rxdataF_comp[0],4*300,1,1); + LOG_M("pdcch_rxF_llr.m","pdcch_llr",UE->pdcch_vars[0][eNB_id]->llr,2400,1,4); + } if (UE->dlsch[UE->current_thread_id[subframe]][eNB_id][0]->harq_ack[subframe].ack == 1) { - avg_iter += UE->dlsch[UE->current_thread_id[subframe]][eNB_id][0]->last_iteration_cnt; iter_trials++; @@ -1773,18 +1661,13 @@ int main(int argc, char **argv) UE->total_TBS[eNB_id] = UE->total_TBS[eNB_id] + UE->dlsch[UE->current_thread_id[subframe]][eNB_id][0]->harq_processes[UE->dlsch[UE->current_thread_id[subframe]][eNB_id][0]->current_harq_pid]->TBS; TB0_active = 0; - - - } // DLSCH received ok - else { + } // DLSCH received ok + else { errs[round]++; - avg_iter += UE->dlsch[UE->current_thread_id[subframe]][eNB_id][0]->last_iteration_cnt-1; iter_trials++; if (n_frames==1) { - - //if ((n_frames==1) || (SNR>=30)) { printf("DLSCH errors found (round %d), uncoded ber %f\n",round,(double)bit_errors/coded_bits_per_codeword); @@ -1795,11 +1678,11 @@ int main(int argc, char **argv) Kr = UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[0]->Kplus; Kr_bytes = Kr>>3; - printf("Decoded_output (Segment %d):\n",s); for (i=0; i<Kr_bytes; i++) - printf("%d : %x (%x)\n",i,UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[0]->c[s][i],UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[0]->c[s][i]^eNB->dlsch[0][0]->harq_processes[0]->c[s][i]); + printf("%d : %x (%x)\n",i,UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[0]->c[s][i], + UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[0]->c[s][i]^eNB->dlsch[0][0]->harq_processes[0]->c[s][i]); } sprintf(fname,"rxsig0_r%d.m",round); @@ -1807,7 +1690,6 @@ int main(int argc, char **argv) LOG_M(fname,vname, &UE->common_vars.rxdata[0][0],10*UE->frame_parms.samples_per_tti,1,1); sprintf(fname,"rxsigF0_r%d.m",round); sprintf(vname,"rxs0F_r%d",round); - LOG_M(fname,vname, &UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].rxdataF[0][0],UE->frame_parms.ofdm_symbol_size*nsymb,1,1); if (UE->frame_parms.nb_antennas_rx>1) { @@ -1822,67 +1704,63 @@ int main(int argc, char **argv) sprintf(fname,"dlsch00_r%d.m",round); sprintf(vname,"dl00_r%d",round); LOG_M(fname,vname, - &(UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].dl_ch_estimates[eNB_id][0][0]), - UE->frame_parms.ofdm_symbol_size*nsymb,1,1); + &(UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].dl_ch_estimates[eNB_id][0][0]), + UE->frame_parms.ofdm_symbol_size*nsymb,1,1); if (UE->frame_parms.nb_antennas_rx>1) { sprintf(fname,"dlsch01_r%d.m",round); sprintf(vname,"dl01_r%d",round); LOG_M(fname,vname, - &(UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].dl_ch_estimates[eNB_id][1][0]), - UE->frame_parms.ofdm_symbol_size*nsymb/2,1,1); + &(UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].dl_ch_estimates[eNB_id][1][0]), + UE->frame_parms.ofdm_symbol_size*nsymb/2,1,1); } if (eNB->frame_parms.nb_antennas_tx>1) { sprintf(fname,"dlsch10_r%d.m",round); sprintf(vname,"dl10_r%d",round); LOG_M(fname,vname, - &(UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].dl_ch_estimates[eNB_id][2][0]), - UE->frame_parms.ofdm_symbol_size*nsymb/2,1,1); + &(UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].dl_ch_estimates[eNB_id][2][0]), + UE->frame_parms.ofdm_symbol_size*nsymb/2,1,1); } if ((UE->frame_parms.nb_antennas_rx>1) && (eNB->frame_parms.nb_antennas_tx>1)) { sprintf(fname,"dlsch11_r%d.m",round); sprintf(vname,"dl11_r%d",round); LOG_M(fname,vname, - &(UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].dl_ch_estimates[eNB_id][3][0]), - UE->frame_parms.ofdm_symbol_size*nsymb/2,1,1); + &(UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].dl_ch_estimates[eNB_id][3][0]), + UE->frame_parms.ofdm_symbol_size*nsymb/2,1,1); } //pdsch_vars dump_dlsch2(UE,eNB_id,subframe,&coded_bits_per_codeword,round, UE->dlsch[UE->current_thread_id[subframe]][0][0]->current_harq_pid); - - //LOG_M("dlsch_e.m","e",eNB->dlsch[0][0]->harq_processes[0]->e,coded_bits_per_codeword,1,4); //LOG_M("dlsch_ber_bit.m","ber_bit",uncoded_ber_bit,coded_bits_per_codeword,1,0); //LOG_M("dlsch_w.m","w",eNB->dlsch[0][0]->harq_processes[0]->w[0],3*(tbs+64),1,4); //LOG_M("dlsch_w.m","w",UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[0]->w[0],3*(tbs+64),1,0); - //pdcch_vars - LOG_M("pdcchF0_ext.m","pdcchF_ext", UE->pdcch_vars[0][eNB_id]->rxdataF_ext[0],2*3*UE->frame_parms.ofdm_symbol_size,1,1); - LOG_M("pdcch00_ch0_ext.m","pdcch00_ch0_ext",UE->pdcch_vars[0][eNB_id]->dl_ch_estimates_ext[0],300*3,1,1); - - LOG_M("pdcch_rxF_comp0.m","pdcch0_rxF_comp0",UE->pdcch_vars[0][eNB_id]->rxdataF_comp[0],4*300,1,1); - LOG_M("pdcch_rxF_llr.m","pdcch_llr",UE->pdcch_vars[0][eNB_id]->llr,2400,1,4); + //pdcch_vars + LOG_M("pdcchF0_ext.m","pdcchF_ext", UE->pdcch_vars[0][eNB_id]->rxdataF_ext[0],2*3*UE->frame_parms.ofdm_symbol_size,1,1); + LOG_M("pdcch00_ch0_ext.m","pdcch00_ch0_ext",UE->pdcch_vars[0][eNB_id]->dl_ch_estimates_ext[0],300*3,1,1); + LOG_M("pdcch_rxF_comp0.m","pdcch0_rxF_comp0",UE->pdcch_vars[0][eNB_id]->rxdataF_comp[0],4*300,1,1); + LOG_M("pdcch_rxF_llr.m","pdcch_llr",UE->pdcch_vars[0][eNB_id]->llr,2400,1,4); if (round == 3) exit(-1); } // printf("round %d errors %d/%d\n",round,errs[round],trials); - round++; // UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[0]->round++; } - if (xforms==1) { - phy_scope_UE(form_ue, - UE, - eNB_id, - 0,// UE_id - subframe); - } + if (xforms==1) { + phy_scope_UE(form_ue, + UE, + eNB_id, + 0,// UE_id + subframe); + } - UE->proc.proc_rxtx[UE->current_thread_id[subframe]].frame_rx++; - } //round + UE->proc.proc_rxtx[UE->current_thread_id[subframe]].frame_rx++; + } //round // printf("\n"); @@ -1899,40 +1777,34 @@ int main(int argc, char **argv) UE->total_TBS_last[eNB_id] = UE->total_TBS[eNB_id]; } - - - /* calculate the total processing time for each packet, * get the max, min, and number of packets that exceed t>2000us */ - double t_tx = inMicroS(eNB->phy_proc_tx.p_time); + double t_tx = inMicroS(eNB->phy_proc_tx.p_time); double t_tx_ifft = inMicroS(eNB->ofdm_mod_stats.p_time); double t_rx = inMicroS(UE->phy_proc_rx[UE->current_thread_id[subframe]].p_time); - sumUpStats(&phy_proc_rx_tot, UE->phy_proc_rx, UE->current_thread_id[subframe]); - sumUpStats(&ue_front_end_tot, UE->ue_front_end_stat, UE->current_thread_id[subframe]); - sumUpStats(&pdsch_procedures_tot, UE->pdsch_procedures_stat, UE->current_thread_id[subframe]); - sumUpStats(&dlsch_procedures_tot, UE->dlsch_procedures_stat, UE->current_thread_id[subframe]); - sumUpStats(&dlsch_decoding_tot, UE->dlsch_decoding_stats, UE->current_thread_id[subframe]); - sumUpStatsSlot(&dlsch_llr_tot, UE->dlsch_llr_stats_parallelization, UE->current_thread_id[subframe]); - - - double t_rx_fft = inMicroS(UE->ofdm_demod_stats.p_time); + sumUpStats(&phy_proc_rx_tot, UE->phy_proc_rx, UE->current_thread_id[subframe]); + sumUpStats(&ue_front_end_tot, UE->ue_front_end_stat, UE->current_thread_id[subframe]); + sumUpStats(&pdsch_procedures_tot, UE->pdsch_procedures_stat, UE->current_thread_id[subframe]); + sumUpStats(&dlsch_procedures_tot, UE->dlsch_procedures_stat, UE->current_thread_id[subframe]); + sumUpStats(&dlsch_decoding_tot, UE->dlsch_decoding_stats, UE->current_thread_id[subframe]); + sumUpStatsSlot(&dlsch_llr_tot, UE->dlsch_llr_stats_parallelization, UE->current_thread_id[subframe]); + double t_rx_fft = inMicroS(UE->ofdm_demod_stats.p_time); double t_rx_demod = inMicroS(UE->dlsch_rx_pdcch_stats.p_time); double t_rx_dec = inMicroS(UE->dlsch_decoding_stats[UE->current_thread_id[subframe]].p_time); if (t_tx > 2000 )// 2ms is too much time for a subframe n_tx_dropped++; - + if (t_rx > 2000 ) n_rx_dropped++; - - appendVarArray(table_tx, &t_tx); + + appendVarArray(table_tx, &t_tx); appendVarArray(table_tx_ifft, &t_tx_ifft); appendVarArray(table_rx, &t_rx ); appendVarArray(table_rx_fft, &t_rx_fft ); appendVarArray(table_rx_demod, &t_rx_demod ); appendVarArray(table_rx_dec, &t_rx_dec ); - } //trials // round_trials[0]: number of code word : goodput the protocol @@ -1953,12 +1825,10 @@ int main(int argc, char **argv) } effective_rate = 1.0-((double)(errs[0]+errs[1]+errs[2]+errs[3])/((double)round_trials[0] + round_trials[1] + round_trials[2] + round_trials[3])); - printf("\n**********************SNR = %f dB (tx_lev %f)**************************\n", SNR, (double)tx_lev_dB+10*log10(UE->frame_parms.ofdm_symbol_size/(NB_RB*12))); - - printf("Errors (%d(%d)/%d %d/%d %d/%d %d/%d), Pe = (%e,%e,%e,%e), dci_errors %d/%d, Pe = %e => effective rate %f, normalized delay %f (%f)\n", + printf("Errors (%u(%u)/%u %u/%u %u/%u %u/%u), Pe = (%e,%e,%e,%e), dci_errors %u/%u, Pe = %e => effective rate %f, normalized delay %f (%f)\n", errs[0], errs2[0], round_trials[0], @@ -1982,39 +1852,37 @@ int main(int argc, char **argv) (1.0*(round_trials[0]-errs[0])+2.0*(round_trials[1]-errs[1])+3.0*(round_trials[2]-errs[2])+4.0*(round_trials[3]-errs[3]))/((double)round_trials[0])/ (double)eNB->dlsch[0][0]->harq_processes[0]->TBS, (1.0*(round_trials[0]-errs[0])+2.0*(round_trials[1]-errs[1])+3.0*(round_trials[2]-errs[2])+4.0*(round_trials[3]-errs[3]))/((double)round_trials[0])); - double timeBase=1/(1000*cpu_freq_GHz); + if (print_perf==1) { printf("\neNB TX function statistics (per 1ms subframe)\n"); - printDistribution(&eNB->phy_proc_tx,table_tx,"PHY proc tx"); - printStatIndent(&eNB->dlsch_common_and_dci,"DL common channels and dci time"); - printStatIndent(&eNB->dlsch_ue_specific,"DL per ue part time"); - printStatIndent2(&eNB->dlsch_encoding_stats,"DLSCH encoding time"); - printStatIndent3(&eNB->dlsch_rate_matching_stats,"DLSCH rate matching time"); - printStatIndent3(&eNB->dlsch_turbo_encoding_stats,"DLSCH turbo encoding time"); - printStatIndent3(&eNB->dlsch_interleaving_stats,"DLSCH interleaving time"); - printStatIndent2(&eNB->dlsch_scrambling_stats, "DLSCH scrambling time"); - printStatIndent2(&eNB->dlsch_modulation_stats, "DLSCH modulation time"); - printDistribution(&eNB->ofdm_mod_stats,table_tx_ifft,"OFDM_mod (idft) time"); - + printDistribution(&eNB->phy_proc_tx,table_tx,"PHY proc tx"); + printStatIndent(&eNB->dlsch_common_and_dci,"DL common channels and dci time"); + printStatIndent(&eNB->dlsch_ue_specific,"DL per ue part time"); + printStatIndent2(&eNB->dlsch_encoding_stats,"DLSCH encoding time"); + printStatIndent3(&eNB->dlsch_rate_matching_stats,"DLSCH rate matching time"); + printStatIndent3(&eNB->dlsch_turbo_encoding_stats,"DLSCH turbo encoding time"); + printStatIndent3(&eNB->dlsch_interleaving_stats,"DLSCH interleaving time"); + printStatIndent2(&eNB->dlsch_scrambling_stats, "DLSCH scrambling time"); + printStatIndent2(&eNB->dlsch_modulation_stats, "DLSCH modulation time"); + printDistribution(&eNB->ofdm_mod_stats,table_tx_ifft,"OFDM_mod (idft) time"); printf("\nUE RX function statistics (per 1ms subframe)\n"); - printDistribution(&phy_proc_rx_tot, table_rx,"Total PHY proc rx"); - printStatIndent(&ue_front_end_tot,"Front end processing"); - printStatIndent(&dlsch_llr_tot,"rx_pdsch processing"); - printStatIndent2(&pdsch_procedures_tot,"pdsch processing"); - printStatIndent2(&dlsch_procedures_tot,"dlsch processing"); - printStatIndent2(&UE->crnti_procedures_stats,"C-RNTI processing"); - printStatIndent(&UE->ofdm_demod_stats,"ofdm demodulation"); - printStatIndent(&UE->dlsch_channel_estimation_stats,"DLSCH channel estimation time"); - printStatIndent(&UE->dlsch_freq_offset_estimation_stats,"DLSCH frequency offset estimation time"); - printStatIndent(&dlsch_decoding_tot, "DLSCH Decoding time "); - printStatIndent(&UE->dlsch_unscrambling_stats,"DLSCH unscrambling time"); + printDistribution(&phy_proc_rx_tot, table_rx,"Total PHY proc rx"); + printStatIndent(&ue_front_end_tot,"Front end processing"); + printStatIndent(&dlsch_llr_tot,"rx_pdsch processing"); + printStatIndent2(&pdsch_procedures_tot,"pdsch processing"); + printStatIndent2(&dlsch_procedures_tot,"dlsch processing"); + printStatIndent2(&UE->crnti_procedures_stats,"C-RNTI processing"); + printStatIndent(&UE->ofdm_demod_stats,"ofdm demodulation"); + printStatIndent(&UE->dlsch_channel_estimation_stats,"DLSCH channel estimation time"); + printStatIndent(&UE->dlsch_freq_offset_estimation_stats,"DLSCH frequency offset estimation time"); + printStatIndent(&dlsch_decoding_tot, "DLSCH Decoding time "); + printStatIndent(&UE->dlsch_unscrambling_stats,"DLSCH unscrambling time"); printStatIndent(&UE->dlsch_rate_unmatching_stats,"DLSCH Rate Unmatching"); - printf("|__ DLSCH Turbo Decoding(%d bits), avg iterations: %.1f %.2f us (%d cycles, %d trials)\n", - UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[0]->Cminus ? - UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[0]->Kminus : - UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[0]->Kplus, - + printf("|__ DLSCH Turbo Decoding(%d bits), avg iterations: %.1f %.2f us (%d cycles, %d trials)\n", + UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[0]->Cminus ? + UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[0]->Kminus : + UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[0]->Kplus, UE->dlsch_tc_intl1_stats.trials/(double)UE->dlsch_tc_init_stats.trials, (double)UE->dlsch_turbo_decoding_stats.diff/UE->dlsch_turbo_decoding_stats.trials*timeBase, (int)((double)UE->dlsch_turbo_decoding_stats.diff/UE->dlsch_turbo_decoding_stats.trials), @@ -2026,11 +1894,10 @@ int main(int argc, char **argv) printStatIndent2(&UE->dlsch_tc_ext_stats,"ext"); printStatIndent2(&UE->dlsch_tc_intl1_stats,"turbo internal interleaver"); printStatIndent2(&UE->dlsch_tc_intl2_stats,"intl2+HardDecode+CRC"); - } if ((transmission_mode != 3) && (transmission_mode != 4)) { - fprintf(bler_fd,"%f;%d;%d;%f;%d;%d;%d;%d;%d;%d;%d;%d;%d\n", + fprintf(bler_fd,"%f;%d;%d;%f;%u;%u;%u;%u;%u;%u;%u;%u;%u\n", SNR, mcs1, eNB->dlsch[0][0]->harq_processes[0]->TBS, @@ -2045,7 +1912,7 @@ int main(int argc, char **argv) round_trials[3], dci_errors[0]); } else { - fprintf(bler_fd,"%f;%d;%d;%d;%d;%f;%d;%d;%d;%d;%d;%d;%d;%d;%d\n", + fprintf(bler_fd,"%f;%d;%d;%d;%d;%f;%u;%u;%u;%u;%u;%u;%u;%u;%u\n", SNR, mcs1,mcs2, eNB->dlsch[0][0]->harq_processes[0]->TBS, @@ -2062,7 +1929,6 @@ int main(int argc, char **argv) dci_errors[0]); } - if(abstx) { //ABSTRACTION blerr[0] = (double)errs[0]/(round_trials[0]); @@ -2079,7 +1945,7 @@ int main(int argc, char **argv) if ( (test_perf != 0) && (100 * effective_rate > test_perf )) { //fprintf(time_meas_fd,"SNR; MCS; TBS; rate; err0; trials0; err1; trials1; err2; trials2; err3; trials3; dci_err\n"); if ((transmission_mode != 3) && (transmission_mode != 4)) { - fprintf(time_meas_fd,"%f;%d;%d;%f;%d;%d;%d;%d;%d;%d;%d;%d;%d;", + fprintf(time_meas_fd,"%f;%d;%d;%f;%u;%u;%u;%u;%u;%u;%u;%u;%u;", SNR, mcs1, eNB->dlsch[0][0]->harq_processes[0]->TBS, @@ -2093,9 +1959,8 @@ int main(int argc, char **argv) errs[3], round_trials[3], dci_errors[0]); - //fprintf(time_meas_fd,"SNR; MCS; TBS; rate; DL_DECOD_ITER; err0; trials0; err1; trials1; err2; trials2; err3; trials3; PE; dci_err;PE;ND;\n"); - fprintf(time_meas_fd,"%f;%d;%d;%f; %2.1f%%;%f;%f;%d;%d;%d;%d;%d;%d;%d;%d;%e;%e;%e;%e;%d;%d;%e;%f;%f;", + fprintf(time_meas_fd,"%f;%d;%d;%f; %2.1f%%;%f;%f;%u;%u;%u;%u;%u;%u;%u;%u;%e;%e;%e;%e;%u;%u;%e;%f;%f;", SNR, mcs1, eNB->dlsch[0][0]->harq_processes[0]->TBS, @@ -2122,7 +1987,7 @@ int main(int argc, char **argv) (double)eNB->dlsch[0][0]->harq_processes[0]->TBS, (1.0*(round_trials[0]-errs[0])+2.0*(round_trials[1]-errs[1])+3.0*(round_trials[2]-errs[2])+4.0*(round_trials[3]-errs[3]))/((double)round_trials[0])); } else { - fprintf(time_meas_fd,"%f;%d;%d;%d;%d;%f;%d;%d;%d;%d;%d;%d;%d;%d;%d;", + fprintf(time_meas_fd,"%f;%d;%d;%d;%d;%f;%u;%u;%u;%u;%u;%u;%u;%u;%u;", SNR, mcs1,mcs2, eNB->dlsch[0][0]->harq_processes[0]->TBS, @@ -2137,9 +2002,8 @@ int main(int argc, char **argv) errs[3], round_trials[3], dci_errors[0]); - //fprintf(time_meas_fd,"SNR; MCS; TBS; rate; DL_DECOD_ITER; err0; trials0; err1; trials1; err2; trials2; err3; trials3; PE; dci_err;PE;ND;\n"); - fprintf(time_meas_fd,"%f;%d;%d;%d;%d;%f;%2.1f;%f;%f;%d;%d;%d;%d;%d;%d;%d;%d;%e;%e;%e;%e;%d;%d;%e;%f;%f;", + fprintf(time_meas_fd,"%f;%d;%d;%d;%d;%f;%2.1f;%f;%f;%u;%u;%u;%u;%u;%u;%u;%u;%e;%e;%e;%e;%u;%u;%e;%f;%f;", SNR, mcs1,mcs2, eNB->dlsch[0][0]->harq_processes[0]->TBS, @@ -2199,49 +2063,45 @@ int main(int argc, char **argv) fprintf(time_meas_fd,"%f;%f;%f;%f;%f;%f;%d;",squareRoot(&UE->phy_proc_tx), t_tx_max, t_tx_min, median(table_tx), q1(table_tx), q3(table_tx), n_tx_dropped); //fprintf(time_meas_fd,"IFFT;\n"); fprintf(time_meas_fd,"%f;%f;%f;%f;", - squareRoot(&eNB->ofdm_mod_stats), + squareRoot(&eNB->ofdm_mod_stats), median(table_tx_ifft),q1(table_tx_ifft),q3(table_tx_ifft)); //fprintf(time_meas_fd,"MOD;\n"); fprintf(time_meas_fd,"%f;%f;%f;%f;", - squareRoot(&eNB->dlsch_modulation_stats), + squareRoot(&eNB->dlsch_modulation_stats), median(table_tx_mod), q1(table_tx_mod), q3(table_tx_mod)); //fprintf(time_meas_fd,"ENC;\n"); fprintf(time_meas_fd,"%f;%f;%f;%f;", - squareRoot(&eNB->dlsch_encoding_stats), + squareRoot(&eNB->dlsch_encoding_stats), median(table_tx_enc),q1(table_tx_enc),q3(table_tx_enc)); //fprintf(time_meas_fd,"eNB_PROC_RX_STD;eNB_PROC_RX_MAX;eNB_PROC_RX_MIN;eNB_PROC_RX_MED;eNB_PROC_RX_Q1;eNB_PROC_RX_Q3;eNB_PROC_RX_DROPPED;\n"); fprintf(time_meas_fd,"%f;%f;%f;%f;%f;%f;%d;", - squareRoot(&phy_proc_rx_tot), t_rx_max, t_rx_min, + squareRoot(&phy_proc_rx_tot), t_rx_max, t_rx_min, median(table_rx), q1(table_rx), q3(table_rx), n_rx_dropped); //fprintf(time_meas_fd,"FFT;\n"); fprintf(time_meas_fd,"%f;%f;%f;%f;", - squareRoot(&UE->ofdm_demod_stats), + squareRoot(&UE->ofdm_demod_stats), median(table_rx_fft), q1(table_rx_fft), q3(table_rx_fft)); //fprintf(time_meas_fd,"DEMOD;\n"); fprintf(time_meas_fd,"%f;%f;%f;%f;", - squareRoot(&UE->dlsch_demodulation_stats), + squareRoot(&UE->dlsch_demodulation_stats), median(table_rx_demod), q1(table_rx_demod), q3(table_rx_demod)); //fprintf(time_meas_fd,"DEC;\n"); fprintf(time_meas_fd,"%f;%f;%f;%f\n", - squareRoot(&UE->dlsch_decoding_stats[subframe]), + squareRoot(&UE->dlsch_decoding_stats[subframe]), median(table_rx_dec), q1(table_rx_dec), q3(table_rx_dec)); - printf("[passed] effective rate : %f (%2.1f%%,%f)): log and break \n",rate*effective_rate, 100*effective_rate, rate ); - test_passed = 1; + test_passed = 1; break; } else if (test_perf !=0 ) { printf("[continue] effective rate : %f (%2.1f%%,%f)): increase snr \n",rate*effective_rate, 100*effective_rate, rate); - test_passed = 0; + test_passed = 0; } if (((double)errs[0]/(round_trials[0]))<(10.0/n_frames)) break; }// SNR - - } //ch_realization - fclose(bler_fd); if (test_perf !=0) @@ -2265,7 +2125,6 @@ int main(int argc, char **argv) free(uncoded_ber_bit); uncoded_ber_bit = NULL; - printf("Freeing dlsch structures\n"); for (i=0; i<2; i++) { diff --git a/openair1/SIMULATION/LTE_PHY/dlsim_tm7.c b/openair1/SIMULATION/LTE_PHY/dlsim_tm7.c index 570c13c0b64f0abec0a817b1cfc1223583fffb61..87b17fbf3f8c25a75b71b464fbfe33d57293453b 100644 --- a/openair1/SIMULATION/LTE_PHY/dlsim_tm7.c +++ b/openair1/SIMULATION/LTE_PHY/dlsim_tm7.c @@ -68,14 +68,11 @@ double t_rx_min = 1000000000; /*!< \brief initial min process time for rx */ int n_tx_dropped = 0; /*!< \brief initial max process time for tx */ int n_rx_dropped = 0; /*!< \brief initial max process time for rx */ -void handler(int sig) -{ +void handler(int sig) { void *array[10]; size_t size; - // get void*'s for all entries on the stack size = backtrace(array, 10); - // print out all the frames to stderr fprintf(stderr, "Error: signal %d:\n", sig); backtrace_symbols_fd(array, size, 2); @@ -94,28 +91,21 @@ uint64_t DLSCH_alloc_pdu_1[2]; //#define DLSCH_RB_ALLOC 0x1fbf // igore DC component,RB13 //#define DLSCH_RB_ALLOC 0x0001 -int main(int argc, char **argv) -{ - +int main(int argc, char **argv) { int c; int k,i,j,aa,aarx,aatx; int re; - int s,Kr,Kr_bytes; - double sigma2, sigma2_dB=10,SNR,snr0=-2.0,snr1,rate; double snr_step=1,input_snr_step=1, snr_int=30; - LTE_DL_FRAME_PARMS *frame_parms; double **s_re,**s_im,**r_re,**r_im; double forgetting_factor=0.0; //in [0,1] 0 means a new channel every time, 1 means keep the same channel double iqim=0.0; - uint8_t extended_prefix_flag=0,transmission_mode=1,n_tx_port=1,n_tx_phy=1,n_rx=1; uint16_t Nid_cell=0; int32_t **cell_spec_bf_weights; int32_t *ue_spec_bf_weights; - int eNB_id = 0, eNB_id_i = 1; unsigned char mcs1=0,mcs2=0,mcs_i=0,dual_stream_UE = 0,awgn_flag=0,round,dci_flag=0; unsigned char i_mod = 2; @@ -124,15 +114,12 @@ int main(int argc, char **argv) uint16_t tdd_config=3; uint16_t n_rnti=0x1234; int n_users = 1; - SCM_t channel_model=Rayleigh1; // unsigned char *input_data,*decoded_output; - unsigned char *input_buffer0[2],*input_buffer1[2]; unsigned short input_buffer_length0,input_buffer_length1; unsigned int ret; unsigned int coded_bits_per_codeword=0,nsymb,dci_cnt,tbs=0; - unsigned int tx_lev=0,tx_lev_dB=0,trials,errs[4]= {0,0,0,0},errs2[4]= {0,0,0,0},round_trials[4]= {0,0,0,0},dci_errors=0,dlsch_active=0;//,num_layers; int re_allocated; char fname[32],vname[32]; @@ -142,23 +129,17 @@ int main(int argc, char **argv) char time_meas_fname[256]; // FILE *tikz_fd; // char tikz_fname[256]; - FILE *input_trch_fd=NULL; unsigned char input_trch_file=0; FILE *input_fd=NULL; unsigned char input_file=0; // char input_val_str[50],input_val_str2[50]; - char input_trch_val[16]; double channelx,channely; - unsigned char pbch_pdu[6]; - DCI_ALLOC_t dci_alloc[8],dci_alloc_rx[8]; int num_common_dci=0,num_ue_spec_dci=0,num_dci=0; - // FILE *rx_frame_file; - int n_frames; int n_ch_rlz = 1; channel_desc_t *eNB2UE[4]; @@ -178,7 +159,6 @@ int main(int argc, char **argv) int ch_realization; int pmi_feedback=0; int hold_channel=0; - // void *data; // int ii; // int bler; @@ -194,7 +174,6 @@ int main(int argc, char **argv) int dci_length_bytes=0,dci_length=0; //double channel_bandwidth = 5.0, sampling_rate=7.68; int common_flag=0,TPC=0; - double cpu_freq_GHz; // time_stats_t ts;//,sts,usts; int avg_iter,iter_trials; @@ -203,50 +182,40 @@ int main(int argc, char **argv) int test_perf=0; int dump_table=0; int llr8_flag=0; - double effective_rate=0.0; char channel_model_input[10]="I"; - int TB0_active = 1; uint32_t perfect_ce = 0; - // LTE_DL_UE_HARQ_t *dlsch0_ue_harq; // LTE_DL_eNB_HARQ_t *dlsch0_eNB_harq; uint8_t Kmimo; uint8_t ue_category=4; uint32_t Nsoft; - - - int CCE_table[800]; - int threequarter_fs=0; - opp_enabled=1; // to enable the time meas - #if defined(__arm__) FILE *proc_fd = NULL; char buf[64]; - proc_fd = fopen("/sys/devices/system/cpu/cpu4/cpufreq/cpuinfo_cur_freq", "r"); - if(!proc_fd) - printf("cannot open /sys/devices/system/cpu/cpu4/cpufreq/cpuinfo_cur_freq"); - else { - while(fgets(buf, 63, proc_fd)) - printf("%s", buf); + + if(!proc_fd) { + printf("cannot open /sys/devices/system/cpu/cpu4/cpufreq/cpuinfo_cur_freq"); + exit(-1); + } else { + while(fgets(buf, 63, proc_fd)) + printf("%s", buf); } + fclose(proc_fd); cpu_freq_GHz = ((double)atof(buf))/1e6; #else cpu_freq_GHz = get_cpu_freq_GHz(); #endif printf("Detected cpu_freq %f GHz\n",cpu_freq_GHz); - //signal(SIGSEGV, handler); //signal(SIGABRT, handler); - logInit(); - // default parameters n_frames = 1000; snr0 = 0; @@ -255,362 +224,363 @@ int main(int argc, char **argv) while ((c = getopt (argc, argv, "ahdpZDe:Em:n:o:s:f:t:c:g:r:F:x:p:y:z:AM:N:I:i:O:R:S:C:T:b:u:v:w:B:PLl:XY")) != -1) { switch (c) { - case 'a': - awgn_flag = 1; - channel_model = AWGN; - break; - - case 'A': - abstx = 1; - break; - - case 'b': - tdd_config=atoi(optarg); - break; - - case 'B': - N_RB_DL=atoi(optarg); - break; - - case 'c': - num_pdcch_symbols=atoi(optarg); - break; - - case 'C': - Nid_cell = atoi(optarg); - break; - - case 'd': - dci_flag = 1; - break; - - case 'D': - frame_type=TDD; - break; - - case 'e': - num_rounds=1; - common_flag = 1; - TPC = atoi(optarg); - break; - - case 'E': - threequarter_fs=1; - break; - - case 'f': - input_snr_step= atof(optarg); - break; - - case 'F': - forgetting_factor = atof(optarg); - break; - - case 'i': - input_fd = fopen(optarg,"r"); - input_file=1; - dci_flag = 1; - break; - - case 'I': - input_trch_fd = fopen(optarg,"r"); - input_trch_file=1; - break; - - case 'L': - llr8_flag=1; - break; - - case 'l': - offset_mumimo_llr_drange_fix=atoi(optarg); - break; - - case 'm': - mcs1 = atoi(optarg); - break; + case 'a': + awgn_flag = 1; + channel_model = AWGN; + break; - case 'M': - mcs2 = atoi(optarg); - break; + case 'A': + abstx = 1; + break; - case 'O': - test_perf=atoi(optarg); - //print_perf =1; - break; + case 'b': + tdd_config=atoi(optarg); + break; - case 't': - mcs_i = atoi(optarg); - i_mod = get_Qm(mcs_i); - break; + case 'B': + N_RB_DL=atoi(optarg); + break; - case 'n': - n_frames = atoi(optarg); - break; + case 'c': + num_pdcch_symbols=atoi(optarg); + break; - case 'o': - rx_sample_offset = atoi(optarg); - break; + case 'C': + Nid_cell = atoi(optarg); + break; - case 'r': - DLSCH_RB_ALLOC = atoi(optarg); - rballocset = 1; - break; + case 'd': + dci_flag = 1; + break; - case 's': - snr0 = atof(optarg); - break; + case 'D': + frame_type=TDD; + break; - case 'w': - snr_int = atof(optarg); - break; + case 'e': + num_rounds=1; + common_flag = 1; + TPC = atoi(optarg); + break; - case 'N': - n_ch_rlz= atof(optarg); - break; + case 'E': + threequarter_fs=1; + break; - case 'p': - extended_prefix_flag=1; - break; + case 'f': + input_snr_step= atof(optarg); + break; - case 'g': - memcpy(channel_model_input,optarg,10); + case 'F': + forgetting_factor = atof(optarg); + break; - switch((char)*optarg) { - case 'A': - channel_model=SCM_A; + case 'i': + input_fd = fopen(optarg,"r"); + input_file=1; + dci_flag = 1; break; - case 'B': - channel_model=SCM_B; + case 'I': + input_trch_fd = fopen(optarg,"r"); + input_trch_file=1; break; - case 'C': - channel_model=SCM_C; + case 'L': + llr8_flag=1; break; - case 'D': - channel_model=SCM_D; + case 'l': + offset_mumimo_llr_drange_fix=atoi(optarg); break; - case 'E': - channel_model=EPA; + case 'm': + mcs1 = atoi(optarg); break; - case 'F': - channel_model=EVA; + case 'M': + mcs2 = atoi(optarg); break; - case 'G': - channel_model=ETU; + case 'O': + test_perf=atoi(optarg); + //print_perf =1; break; - case 'H': - channel_model=Rayleigh8; + case 't': + mcs_i = atoi(optarg); + i_mod = get_Qm(mcs_i); break; - case 'I': - channel_model=Rayleigh1; + case 'n': + n_frames = atoi(optarg); break; - case 'J': - channel_model=Rayleigh1_corr; + case 'o': + rx_sample_offset = atoi(optarg); break; - case 'K': - channel_model=Rayleigh1_anticorr; + case 'r': + DLSCH_RB_ALLOC = atoi(optarg); + rballocset = 1; break; - case 'L': - channel_model=Rice8; + case 's': + snr0 = atof(optarg); break; - case 'M': - channel_model=Rice1; + case 'w': + snr_int = atof(optarg); break; case 'N': - channel_model=AWGN; + n_ch_rlz= atof(optarg); break; - default: - msg("Unsupported channel model!\n"); - exit(-1); - } - break; + case 'p': + extended_prefix_flag=1; + break; - case 'R': - num_rounds=atoi(optarg); - break; + case 'g': + memcpy(channel_model_input,optarg,10); - case 'S': - subframe=atoi(optarg); - break; + switch((char)*optarg) { + case 'A': + channel_model=SCM_A; + break; - case 'T': - n_rnti=atoi(optarg); - break; + case 'B': + channel_model=SCM_B; + break; - case 'u': - dual_stream_UE=1; - UE->use_ia_receiver = 1; + case 'C': + channel_model=SCM_C; + break; - if ((n_tx_port!=2) || (transmission_mode!=5)) { - msg("IA receiver only supported for TM5!"); - exit(-1); - } + case 'D': + channel_model=SCM_D; + break; - break; + case 'E': + channel_model=EPA; + break; - case 'v': - i_mod = atoi(optarg); + case 'F': + channel_model=EVA; + break; - if (i_mod!=2 && i_mod!=4 && i_mod!=6) { - msg("Wrong i_mod %d, should be 2,4 or 6\n",i_mod); - exit(-1); - } + case 'G': + channel_model=ETU; + break; - break; + case 'H': + channel_model=Rayleigh8; + break; - case 'P': - print_perf=1; - break; + case 'I': + channel_model=Rayleigh1; + break; - case 'q': - n_tx_port=atoi(optarg); + case 'J': + channel_model=Rayleigh1_corr; + break; - if ((n_tx_port==0) || ((n_tx_port>2))) { - msg("Unsupported number of cell specific antennas ports %d\n",n_tx_port); - exit(-1); - } + case 'K': + channel_model=Rayleigh1_anticorr; + break; - break; + case 'L': + channel_model=Rice8; + break; + case 'M': + channel_model=Rice1; + break; - case 'x': - transmission_mode=atoi(optarg); + case 'N': + channel_model=AWGN; + break; - if ((transmission_mode!=1) && - (transmission_mode!=2) && - (transmission_mode!=3) && - (transmission_mode!=4) && - (transmission_mode!=5) && - (transmission_mode!=6) && - (transmission_mode!=7)) { - msg("Unsupported transmission mode %d\n",transmission_mode); - exit(-1); - } + default: + msg("Unsupported channel model!\n"); + exit(-1); + } - if (transmission_mode>1 && transmission_mode<7) { - n_tx_port = 2; - } + break; - break; + case 'R': + num_rounds=atoi(optarg); + break; + + case 'S': + subframe=atoi(optarg); + break; - case 'y': - n_tx_phy=atoi(optarg); - - if (transmission_mode>1&&transmission_mode<7) { - if(n_tx_phy==1) { - msg("n_tx_phy must be >1 for transmission_mode %d\n",transmission_mode); + case 'T': + n_rnti=atoi(optarg); + break; + + case 'u': + dual_stream_UE=1; + UE->use_ia_receiver = 1; + + if ((n_tx_port!=2) || (transmission_mode!=5)) { + msg("IA receiver only supported for TM5!"); exit(-1); - } - } + } - if (transmission_mode==7 && (n_tx_phy!=1 && n_tx_phy!=2 && n_tx_phy!=4 && n_tx_phy!=8 && n_tx_phy!=16 && n_tx_phy!=64 && n_tx_phy!=128)) { - msg("Physical number of antennas not supported for TM7.\n"); - exit(-1); - } + break; - break; + case 'v': + i_mod = atoi(optarg); - case 'X': - xforms=1; - break; + if (i_mod!=2 && i_mod!=4 && i_mod!=6) { + msg("Wrong i_mod %d, should be 2,4 or 6\n",i_mod); + exit(-1); + } - case 'Y': - perfect_ce=1; - break; + break; - case 'z': - n_rx=atoi(optarg); + case 'P': + print_perf=1; + break; - if ((n_rx==0) || (n_rx>2)) { - msg("Unsupported number of rx antennas %d\n",n_rx); - exit(-1); - } + case 'q': + n_tx_port=atoi(optarg); - break; + if ((n_tx_port==0) || ((n_tx_port>2))) { + msg("Unsupported number of cell specific antennas ports %d\n",n_tx_port); + exit(-1); + } - case 'Z': - dump_table=1; - break; + break; + case 'x': + transmission_mode=atoi(optarg); + + if ((transmission_mode!=1) && + (transmission_mode!=2) && + (transmission_mode!=3) && + (transmission_mode!=4) && + (transmission_mode!=5) && + (transmission_mode!=6) && + (transmission_mode!=7)) { + msg("Unsupported transmission mode %d\n",transmission_mode); + exit(-1); + } + if (transmission_mode>1 && transmission_mode<7) { + n_tx_port = 2; + } - case 'h': - default: - printf("%s -h(elp) -a(wgn on) -d(ci decoding on) -p(extended prefix on) -m mcs1 -M mcs2 -n n_frames -s snr0 -x transmission mode (1,2,5,6,7) -y TXant -z RXant -I trch_file\n",argv[0]); - printf("-h This message\n"); - printf("-a Use AWGN channel and not multipath\n"); - printf("-c Number of PDCCH symbols\n"); - printf("-m MCS1 for TB 1\n"); - printf("-M MCS2 for TB 2\n"); - printf("-d Transmit the DCI and compute its error statistics and the overall throughput\n"); - printf("-p Use extended prefix mode\n"); - printf("-n Number of frames to simulate\n"); - printf("-o Sample offset for receiver\n"); - printf("-s Starting SNR, runs from SNR to SNR+%.1fdB in steps of %.1fdB. If n_frames is 1 then just SNR is simulated and MATLAB/OCTAVE output is generated\n", snr_int, snr_step); - printf("-f step size of SNR, default value is 1.\n"); - printf("-r ressource block allocation (see section 7.1.6.3 in 36.213\n"); - printf("-g [A:M] Use 3GPP 25.814 SCM-A/B/C/D('A','B','C','D') or 36-101 EPA('E'), EVA ('F'),ETU('G') models (ignores delay spread and Ricean factor), Rayghleigh8 ('H'), Rayleigh1('I'), Rayleigh1_corr('J'), Rayleigh1_anticorr ('K'), Rice8('L'), Rice1('M')\n"); - printf("-F forgetting factor (0 new channel every trial, 1 channel constant\n"); - printf("-x Transmission mode (1,2,6,7 for the moment)\n"); - printf("-q Number of TX antennas ports used in eNB\n"); - printf("-y Number of physical TX antennas used in eNB\n"); - printf("-z Number of RX antennas used in UE\n"); - printf("-t MCS of interfering UE\n"); - printf("-R Number of HARQ rounds (fixed)\n"); - printf("-A Turns on calibration mode for abstraction.\n"); - printf("-N Determines the number of Channel Realizations in Abstraction mode. Default value is 1. \n"); - printf("-O Set the percenatge of effective rate to testbench the modem performance (typically 30 and 70, range 1-100) \n"); - printf("-I Input filename for TrCH data (binary)\n"); - printf("-u Enables the Interference Aware Receiver for TM5 (default is normal receiver)\n"); - exit(1); - break; + break; + + case 'y': + n_tx_phy=atoi(optarg); + + if (transmission_mode>1&&transmission_mode<7) { + if(n_tx_phy==1) { + msg("n_tx_phy must be >1 for transmission_mode %d\n",transmission_mode); + exit(-1); + } + } + + if (transmission_mode==7 && (n_tx_phy!=1 && n_tx_phy!=2 && n_tx_phy!=4 && n_tx_phy!=8 && n_tx_phy!=16 && n_tx_phy!=64 && n_tx_phy!=128)) { + msg("Physical number of antennas not supported for TM7.\n"); + exit(-1); + } + + break; + + case 'X': + xforms=1; + break; + + case 'Y': + perfect_ce=1; + break; + + case 'z': + n_rx=atoi(optarg); + + if ((n_rx==0) || (n_rx>2)) { + msg("Unsupported number of rx antennas %d\n",n_rx); + exit(-1); + } + + break; + + case 'Z': + dump_table=1; + break; + + case 'h': + default: + printf("%s -h(elp) -a(wgn on) -d(ci decoding on) -p(extended prefix on) -m mcs1 -M mcs2 -n n_frames -s snr0 -x transmission mode (1,2,5,6,7) -y TXant -z RXant -I trch_file\n",argv[0]); + printf("-h This message\n"); + printf("-a Use AWGN channel and not multipath\n"); + printf("-c Number of PDCCH symbols\n"); + printf("-m MCS1 for TB 1\n"); + printf("-M MCS2 for TB 2\n"); + printf("-d Transmit the DCI and compute its error statistics and the overall throughput\n"); + printf("-p Use extended prefix mode\n"); + printf("-n Number of frames to simulate\n"); + printf("-o Sample offset for receiver\n"); + printf("-s Starting SNR, runs from SNR to SNR+%.1fdB in steps of %.1fdB. If n_frames is 1 then just SNR is simulated and MATLAB/OCTAVE output is generated\n", snr_int, snr_step); + printf("-f step size of SNR, default value is 1.\n"); + printf("-r ressource block allocation (see section 7.1.6.3 in 36.213\n"); + printf("-g [A:M] Use 3GPP 25.814 SCM-A/B/C/D('A','B','C','D') or 36-101 EPA('E'), EVA ('F'),ETU('G') models (ignores delay spread and Ricean factor), Rayghleigh8 ('H'), Rayleigh1('I'), Rayleigh1_corr('J'), Rayleigh1_anticorr ('K'), Rice8('L'), Rice1('M')\n"); + printf("-F forgetting factor (0 new channel every trial, 1 channel constant\n"); + printf("-x Transmission mode (1,2,6,7 for the moment)\n"); + printf("-q Number of TX antennas ports used in eNB\n"); + printf("-y Number of physical TX antennas used in eNB\n"); + printf("-z Number of RX antennas used in UE\n"); + printf("-t MCS of interfering UE\n"); + printf("-R Number of HARQ rounds (fixed)\n"); + printf("-A Turns on calibration mode for abstraction.\n"); + printf("-N Determines the number of Channel Realizations in Abstraction mode. Default value is 1. \n"); + printf("-O Set the percenatge of effective rate to testbench the modem performance (typically 30 and 70, range 1-100) \n"); + printf("-I Input filename for TrCH data (binary)\n"); + printf("-u Enables the Interference Aware Receiver for TM5 (default is normal receiver)\n"); + exit(1); + break; } } if (common_flag == 0) { switch (N_RB_DL) { - case 6: - if (rballocset==0) DLSCH_RB_ALLOC = 0x3f; - num_pdcch_symbols = 3; - break; + case 6: + if (rballocset==0) DLSCH_RB_ALLOC = 0x3f; - case 25: - if (rballocset==0) DLSCH_RB_ALLOC = 0x1fff; - break; + num_pdcch_symbols = 3; + break; - case 50: - if (rballocset==0) DLSCH_RB_ALLOC = 0x1ffff; - break; + case 25: + if (rballocset==0) DLSCH_RB_ALLOC = 0x1fff; - case 100: - if (rballocset==0) DLSCH_RB_ALLOC = 0x1ffffff; - break; + break; + + case 50: + if (rballocset==0) DLSCH_RB_ALLOC = 0x1ffff; + + break; + + case 100: + if (rballocset==0) DLSCH_RB_ALLOC = 0x1ffffff; + + break; } NB_RB=conv_nprb(0,DLSCH_RB_ALLOC,N_RB_DL); } else NB_RB = 4; - if (xforms==1) { fl_initialize (&argc, argv, NULL, 0, 0); form_ue = create_lte_phy_scope_ue(); sprintf (title, "LTE PHY SCOPE eNB"); fl_show_form (form_ue->lte_phy_scope_ue, FL_PLACE_HOTSPOT, FL_FULLBORDER, title); - + if (!dual_stream_UE==0) { UE->use_ia_receiver = 1; fl_set_button(form_ue->button_0,1); @@ -625,9 +595,7 @@ int main(int argc, char **argv) } lte_param_init(n_tx_port,n_tx_phy,n_rx,transmission_mode,extended_prefix_flag,frame_type,Nid_cell,tdd_config,N_RB_DL,threequarter_fs,osf,perfect_ce); - frame_parms = &eNB->frame_parms; - /* cell_spec_bf_weights = eNB->common_vars.beam_weights[0][0]; for(aa=0;aa<n_tx_phy;aa++) { @@ -641,35 +609,27 @@ int main(int argc, char **argv) else if (n_tx_phy==64) cell_spec_bf_weights[aa][re] = 0x00007fff>>4; } - } + } if (transmission_mode==7){ lte_gold_ue_spec_port5(eNB->lte_gold_uespec_port5_table[0],Nid_cell,n_rnti); lte_gold_ue_spec_port5(UE->lte_gold_uespec_port5_table,Nid_cell,n_rnti); }*/ - - eNB_id_i = UE->n_connected_eNB; - printf("Setting mcs1 = %d\n",mcs1); printf("Setting mcs2 = %d\n",mcs2); printf("NPRB = %d\n",NB_RB); printf("n_frames = %d\n",n_frames); printf("Transmission mode %d with %dx%d antenna configuration, Extended Prefix %d\n",transmission_mode,n_tx_phy,n_rx,extended_prefix_flag); - snr1 = snr0+snr_int; printf("SNR0 %f, SNR1 %f\n",snr0,snr1); - - - s_re = malloc(n_tx_phy*sizeof(double*)); - s_im = malloc(n_tx_phy*sizeof(double*)); - r_re = malloc(2*sizeof(double*)); - r_im = malloc(2*sizeof(double*)); + s_re = malloc(n_tx_phy*sizeof(double *)); + s_im = malloc(n_tx_phy*sizeof(double *)); + r_re = malloc(2*sizeof(double *)); + r_im = malloc(2*sizeof(double *)); // r_re0 = malloc(2*sizeof(double*)); // r_im0 = malloc(2*sizeof(double*)); - nsymb = (eNB->frame_parms.Ncp == 0) ? 14 : 12; - printf("Channel Model= (%s,%d)\n",channel_model_input, channel_model); printf("SCM-A=%d, SCM-B=%d, SCM-C=%d, SCM-D=%d, EPA=%d, EVA=%d, ETU=%d, Rayleigh8=%d, Rayleigh1=%d, Rayleigh1_corr=%d, Rayleigh1_anticorr=%d, Rice1=%d, Rice8=%d\n", SCM_A, SCM_B, SCM_C, SCM_D, EPA, EVA, ETU, Rayleigh8, Rayleigh1, Rayleigh1_corr, Rayleigh1_anticorr, Rice1, Rice8); @@ -680,10 +640,12 @@ int main(int argc, char **argv) sprintf(bler_fname,"bler_tm%d_chan%d_perfce%d_ntx%d_nrx%d_mcs%d.csv",transmission_mode,channel_model,perfect_ce,n_tx_phy,n_rx,mcs1); bler_fd = fopen(bler_fname,"w"); + if (bler_fd==NULL) { fprintf(stderr,"Cannot create file %s!\n",bler_fname); exit(-1); } + fprintf(bler_fd,"SNR; MCS; TBS; rate; err0; trials0; err1; trials1; err2; trials2; err3; trials3; dci_err\n"); if (test_perf != 0) { @@ -697,6 +659,7 @@ int main(int argc, char **argv) N_RB_DL,mcs1,n_tx_phy,n_rx,num_pdcch_symbols,channel_model_input,transmission_mode); //mkdir(dirname,0777); time_meas_fd = fopen(time_meas_fname,"w"); + if (time_meas_fd==NULL) { fprintf(stderr,"Cannot create file %s!\n",time_meas_fname); exit(-1); @@ -707,11 +670,11 @@ int main(int argc, char **argv) // CSV file sprintf(csv_fname,"dataout_tx%d_u2%d_mcs%d_chan%d_nsimus%d_R%d.m",transmission_mode,dual_stream_UE,mcs1,channel_model,n_frames,num_rounds); csv_fd = fopen(csv_fname,"w"); - fprintf(csv_fd,"data_all%d=[",mcs1); if (csv_fd==NULL) { fprintf(stderr,"Cannot create file %s!\n",csv_fname); exit(-1); } + fprintf(csv_fd,"data_all%d=[",mcs1); } /* @@ -811,7 +774,7 @@ int main(int argc, char **argv) } */ - for (i=0; i<n_tx_phy; i++){ + for (i=0; i<n_tx_phy; i++) { s_re[i] = malloc(FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double)); s_im[i] = malloc(FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double)); } @@ -825,9 +788,7 @@ int main(int argc, char **argv) // bzero(r_im0[i],FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double)); } - UE->pdcch_vars[0]->crnti = n_rnti; - // Fill in UL_alloc UL_alloc_pdu.type = 0; UL_alloc_pdu.hopping = 0; @@ -836,14 +797,12 @@ int main(int argc, char **argv) UL_alloc_pdu.ndi = 1; UL_alloc_pdu.TPC = 0; UL_alloc_pdu.cqi_req = 1; - CCCH_alloc_pdu.type = 0; CCCH_alloc_pdu.vrb_type = 0; CCCH_alloc_pdu.rballoc = CCCH_RB_ALLOC; CCCH_alloc_pdu.ndi = 1; CCCH_alloc_pdu.mcs = 1; CCCH_alloc_pdu.harq_pid = 0; - DLSCH_alloc_pdu2_1E[0].rah = 0; DLSCH_alloc_pdu2_1E[0].rballoc = DLSCH_RB_ALLOC; DLSCH_alloc_pdu2_1E[0].TPC = 0; @@ -856,7 +815,6 @@ int main(int argc, char **argv) // Forget second codeword DLSCH_alloc_pdu2_1E[0].tpmi = (transmission_mode>=5 ? 5 : 0); // precoding DLSCH_alloc_pdu2_1E[0].dl_power_off = (transmission_mode==5 ? 0 : 1); - DLSCH_alloc_pdu2_1E[1].rah = 0; DLSCH_alloc_pdu2_1E[1].rballoc = DLSCH_RB_ALLOC; DLSCH_alloc_pdu2_1E[1].TPC = 0; @@ -869,12 +827,11 @@ int main(int argc, char **argv) // Forget second codeword DLSCH_alloc_pdu2_1E[1].tpmi = (transmission_mode>=5 ? 5 : 0) ; // precoding DLSCH_alloc_pdu2_1E[1].dl_power_off = (transmission_mode==5 ? 0 : 1); - eNB2UE[0] = new_channel_desc_scm(eNB->frame_parms.nb_antennas_tx, UE->frame_parms.nb_antennas_rx, channel_model, N_RB2sampling_rate(eNB->frame_parms.N_RB_DL), - N_RB2channel_bandwidth(eNB->frame_parms.N_RB_DL), + N_RB2channel_bandwidth(eNB->frame_parms.N_RB_DL), forgetting_factor, rx_sample_offset, 0); @@ -884,9 +841,9 @@ int main(int argc, char **argv) eNB2UE[n] = new_channel_desc_scm(eNB->frame_parms.nb_antennas_tx, UE->frame_parms.nb_antennas_rx, channel_model, - N_RB2sampling_rate(eNB->frame_parms.N_RB_DL), - N_RB2channel_bandwidth(eNB->frame_parms.N_RB_DL), - forgetting_factor, + N_RB2sampling_rate(eNB->frame_parms.N_RB_DL), + N_RB2channel_bandwidth(eNB->frame_parms.N_RB_DL), + forgetting_factor, rx_sample_offset, 0); } @@ -902,20 +859,23 @@ int main(int argc, char **argv) Kmimo=1; switch (ue_category) { - case 1: - Nsoft = 250368; - break; - case 2: - case 3: - Nsoft = 1237248; - break; - case 4: - Nsoft = 1827072; - break; - default: - printf("Unsupported UE category %d\n",ue_category); - exit(-1); - break; + case 1: + Nsoft = 250368; + break; + + case 2: + case 3: + Nsoft = 1237248; + break; + + case 4: + Nsoft = 1827072; + break; + + default: + printf("Unsupported UE category %d\n",ue_category); + exit(-1); + break; } for (k=0; k<n_users; k++) { @@ -927,12 +887,12 @@ int main(int argc, char **argv) printf("Can't get eNB dlsch structures\n"); exit(-1); } else { - // this initilisation may should be moved to another place - for (j=0; j<4; j++) { - for (aa=0; aa<n_tx_phy; aa++) { + // this initilisation may should be moved to another place + for (j=0; j<4; j++) { + for (aa=0; aa<n_tx_phy; aa++) { ue_spec_bf_weights = eNB->dlsch[k][i]->ue_spec_bf_weights[j][aa]; - for (re=0;re<OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES;re++) { + for (re=0; re<OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES; re++) { if (n_tx_phy==1 || n_tx_phy==2) ue_spec_bf_weights[re] = 0x00007fff; else if (n_tx_phy==4 || n_tx_phy==8) @@ -942,10 +902,8 @@ int main(int argc, char **argv) else if (n_tx_phy==64) ue_spec_bf_weights[re] = 0x00007fff>>4; } - } - } - + } } eNB->dlsch[k][i]->rnti = n_rnti+k; @@ -967,7 +925,6 @@ int main(int argc, char **argv) UE->dlsch_eNB[0] = new_eNB_dlsch(Kmimo,8,Nsoft,N_RB_DL,0,&eNB->frame_parms); if (DLSCH_alloc_pdu2_1E[0].tpmi == 5) { - eNB->UE_stats[0].DL_pmi_single = (unsigned short)(taus()&0xffff); if (n_users>1) @@ -984,8 +941,6 @@ int main(int argc, char **argv) //read_calibration_matrix(calib_fname, nb_ant, nb_freq, eNB->common_vars.tdd_calib_coeffs[0]); if (input_fd==NULL) { - - /* // common DCI memcpy(&dci_alloc[num_dci].dci_pdu[0],&CCCH_alloc_pdu,sizeof(DCI1A_5MHz_TDD_1_6_t)); @@ -999,955 +954,917 @@ int main(int argc, char **argv) // UE specific DCI for(k=0; k<n_users; k++) { switch(transmission_mode) { - case 1: - case 2: - case 7: - if (common_flag == 0) { - - if (eNB->frame_parms.frame_type == TDD) { - - switch (eNB->frame_parms.N_RB_DL) { - case 6: - dci_length = sizeof_DCI1_1_5MHz_TDD_t; - dci_length_bytes = sizeof(DCI1_1_5MHz_TDD_t); - ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->rah = 0; - ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc = DLSCH_RB_ALLOC; - ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->TPC = 0; - ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->dai = 0; - ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; - ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->mcs = mcs1; - ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->ndi = 1; - ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->rv = 0; - break; - - case 25: - dci_length = sizeof_DCI1_5MHz_TDD_t; - dci_length_bytes = sizeof(DCI1_5MHz_TDD_t); - ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->rah = 0; - ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc = DLSCH_RB_ALLOC; - ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->TPC = 0; - ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->dai = 0; - ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; - ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->mcs = mcs1; - ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->ndi = 1; - ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->rv = 0; - break; - - case 50: - dci_length = sizeof_DCI1_10MHz_TDD_t; - dci_length_bytes = sizeof(DCI1_10MHz_TDD_t); - ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->rah = 0; - ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc = DLSCH_RB_ALLOC; - ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->TPC = 0; - ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->dai = 0; - ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; - ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->mcs = mcs1; - ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->ndi = 1; - ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->rv = 0; - break; - - case 100: - ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->rah = 0; - ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc = DLSCH_RB_ALLOC; - ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->TPC = 0; - ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->dai = 0; - ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; - ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->mcs = mcs1; - ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->ndi = 1; - ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->rv = 0; - dci_length = sizeof_DCI1_20MHz_TDD_t; - dci_length_bytes = sizeof(DCI1_20MHz_TDD_t); - break; - } - } else { - switch (eNB->frame_parms.N_RB_DL) { - case 6: - dci_length = sizeof_DCI1_1_5MHz_FDD_t; - dci_length_bytes = sizeof(DCI1_1_5MHz_FDD_t); - ((DCI1_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rah = 0; - ((DCI1_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc = DLSCH_RB_ALLOC; - ((DCI1_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC = 0; - ((DCI1_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; - ((DCI1_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs = mcs1; - ((DCI1_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi = 1; - ((DCI1_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv = 0; - break; - - case 25: - dci_length = sizeof_DCI1_5MHz_FDD_t; - dci_length_bytes = sizeof(DCI1_5MHz_FDD_t); - ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rah = 0; - ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc = DLSCH_RB_ALLOC; - ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC = 0; - ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; - ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs = mcs1; - ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi = 1; - ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv = 0; - break; - - case 50: - dci_length = sizeof_DCI1_10MHz_FDD_t; - dci_length_bytes = sizeof(DCI1_10MHz_FDD_t); - ((DCI1_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rah = 0; - ((DCI1_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc = DLSCH_RB_ALLOC; - ((DCI1_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC = 0; - ((DCI1_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; - ((DCI1_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs = mcs1; - ((DCI1_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi = 1; - ((DCI1_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv = 0; - break; - - case 100: - dci_length = sizeof_DCI1_20MHz_FDD_t; - dci_length_bytes = sizeof(DCI1_20MHz_FDD_t); - ((DCI1_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rah = 0; - ((DCI1_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc = DLSCH_RB_ALLOC; - ((DCI1_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC = 0; - ((DCI1_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; - ((DCI1_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs = mcs1; - ((DCI1_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi = 1; - ((DCI1_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv = 0; - break; + case 1: + case 2: + case 7: + if (common_flag == 0) { + if (eNB->frame_parms.frame_type == TDD) { + switch (eNB->frame_parms.N_RB_DL) { + case 6: + dci_length = sizeof_DCI1_1_5MHz_TDD_t; + dci_length_bytes = sizeof(DCI1_1_5MHz_TDD_t); + ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->rah = 0; + ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc = DLSCH_RB_ALLOC; + ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->TPC = 0; + ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->dai = 0; + ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; + ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->mcs = mcs1; + ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->ndi = 1; + ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->rv = 0; + break; + + case 25: + dci_length = sizeof_DCI1_5MHz_TDD_t; + dci_length_bytes = sizeof(DCI1_5MHz_TDD_t); + ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->rah = 0; + ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc = DLSCH_RB_ALLOC; + ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->TPC = 0; + ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->dai = 0; + ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; + ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->mcs = mcs1; + ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->ndi = 1; + ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->rv = 0; + break; + + case 50: + dci_length = sizeof_DCI1_10MHz_TDD_t; + dci_length_bytes = sizeof(DCI1_10MHz_TDD_t); + ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->rah = 0; + ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc = DLSCH_RB_ALLOC; + ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->TPC = 0; + ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->dai = 0; + ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; + ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->mcs = mcs1; + ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->ndi = 1; + ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->rv = 0; + break; + + case 100: + ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->rah = 0; + ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc = DLSCH_RB_ALLOC; + ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->TPC = 0; + ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->dai = 0; + ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; + ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->mcs = mcs1; + ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->ndi = 1; + ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu_1[k])->rv = 0; + dci_length = sizeof_DCI1_20MHz_TDD_t; + dci_length_bytes = sizeof(DCI1_20MHz_TDD_t); + break; + } + } else { + switch (eNB->frame_parms.N_RB_DL) { + case 6: + dci_length = sizeof_DCI1_1_5MHz_FDD_t; + dci_length_bytes = sizeof(DCI1_1_5MHz_FDD_t); + ((DCI1_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rah = 0; + ((DCI1_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc = DLSCH_RB_ALLOC; + ((DCI1_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC = 0; + ((DCI1_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; + ((DCI1_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs = mcs1; + ((DCI1_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi = 1; + ((DCI1_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv = 0; + break; + + case 25: + dci_length = sizeof_DCI1_5MHz_FDD_t; + dci_length_bytes = sizeof(DCI1_5MHz_FDD_t); + ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rah = 0; + ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc = DLSCH_RB_ALLOC; + ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC = 0; + ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; + ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs = mcs1; + ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi = 1; + ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv = 0; + break; + + case 50: + dci_length = sizeof_DCI1_10MHz_FDD_t; + dci_length_bytes = sizeof(DCI1_10MHz_FDD_t); + ((DCI1_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rah = 0; + ((DCI1_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc = DLSCH_RB_ALLOC; + ((DCI1_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC = 0; + ((DCI1_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; + ((DCI1_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs = mcs1; + ((DCI1_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi = 1; + ((DCI1_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv = 0; + break; + + case 100: + dci_length = sizeof_DCI1_20MHz_FDD_t; + dci_length_bytes = sizeof(DCI1_20MHz_FDD_t); + ((DCI1_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rah = 0; + ((DCI1_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc = DLSCH_RB_ALLOC; + ((DCI1_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC = 0; + ((DCI1_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; + ((DCI1_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs = mcs1; + ((DCI1_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi = 1; + ((DCI1_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv = 0; + break; + } } - } - memcpy(&dci_alloc[num_dci].dci_pdu[0],&DLSCH_alloc_pdu_1[k],dci_length_bytes); - dci_alloc[num_dci].dci_length = dci_length; - dci_alloc[num_dci].L = 1; - dci_alloc[num_dci].rnti = n_rnti+k; - dci_alloc[num_dci].format = format1; - dci_alloc[num_dci].search_space = DCI_UE_SPACE; - dump_dci(&eNB->frame_parms,&dci_alloc[num_dci]); - - printf("Generating dlsch params for user %d\n",k); - generate_eNB_dlsch_params_from_dci(0, - subframe, - &DLSCH_alloc_pdu_1[0], - n_rnti+k, - format1, - eNB->dlsch[0], - &eNB->frame_parms, - eNB->pdsch_config_dedicated, - SI_RNTI, - 0, - P_RNTI, - eNB->UE_stats[0].DL_pmi_single, - transmission_mode<7?0:transmission_mode); - - /*if (transmission_mode == 7) - eNB->dlsch[0][0]->harq_processes[0]->mimo_mode = TM7; //Xiwen: to check about harq_pid*/ - - num_dci++; - num_ue_spec_dci++; - } else { - if (eNB->frame_parms.frame_type == TDD) { - - switch (eNB->frame_parms.N_RB_DL) { - case 6: - dci_length = sizeof_DCI1A_1_5MHz_TDD_1_6_t; - dci_length_bytes = sizeof(DCI1A_1_5MHz_TDD_1_6_t); - ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->type = 1; - ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->vrb_type = 0; - ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rballoc = computeRIV(eNB->frame_parms.N_RB_DL,0,9); - ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->TPC = TPC; - ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->dai = 0; - ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; - ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->mcs = mcs1; - ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->ndi = 0; - ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rv = 0; - break; - - case 25: - dci_length = sizeof_DCI1A_5MHz_TDD_1_6_t; - dci_length_bytes = sizeof(DCI1A_5MHz_TDD_1_6_t); - ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->type = 1; - ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->vrb_type = 0; - ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rballoc = computeRIV(eNB->frame_parms.N_RB_DL,0,9); - ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->TPC = TPC; - ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->dai = 0; - ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; - ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->mcs = mcs1; - ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->ndi = 0; - ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rv = 1; - break; - - case 50: - dci_length = sizeof_DCI1A_10MHz_TDD_1_6_t; - dci_length_bytes = sizeof(DCI1A_10MHz_TDD_1_6_t); - ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->type = 1; - ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->vrb_type = 1; - ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rballoc = computeRIV(eNB->frame_parms.N_RB_DL,0,9); - ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->TPC = TPC; - ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->dai = 0; - ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; - ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->mcs = mcs1; - ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->ndi = 0; - ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rv = 0; - break; - - case 100: - ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->type = 1; - ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->vrb_type = 1; - ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rballoc = computeRIV(eNB->frame_parms.N_RB_DL,0,9); - ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->TPC = TPC; - ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->dai = 0; - ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; - ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->mcs = mcs1; - ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->ndi = 0; - ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rv = 0; - dci_length = sizeof_DCI1A_20MHz_TDD_1_6_t; - dci_length_bytes = sizeof(DCI1A_20MHz_TDD_1_6_t); - break; - } + memcpy(&dci_alloc[num_dci].dci_pdu[0],&DLSCH_alloc_pdu_1[k],dci_length_bytes); + dci_alloc[num_dci].dci_length = dci_length; + dci_alloc[num_dci].L = 1; + dci_alloc[num_dci].rnti = n_rnti+k; + dci_alloc[num_dci].format = format1; + dci_alloc[num_dci].search_space = DCI_UE_SPACE; + dump_dci(&eNB->frame_parms,&dci_alloc[num_dci]); + printf("Generating dlsch params for user %d\n",k); + generate_eNB_dlsch_params_from_dci(0, + subframe, + &DLSCH_alloc_pdu_1[0], + n_rnti+k, + format1, + eNB->dlsch[0], + &eNB->frame_parms, + eNB->pdsch_config_dedicated, + SI_RNTI, + 0, + P_RNTI, + eNB->UE_stats[0].DL_pmi_single, + transmission_mode<7?0:transmission_mode); + /*if (transmission_mode == 7) + eNB->dlsch[0][0]->harq_processes[0]->mimo_mode = TM7; //Xiwen: to check about harq_pid*/ + num_dci++; + num_ue_spec_dci++; } else { - switch (eNB->frame_parms.N_RB_DL) { - case 6: - dci_length = sizeof_DCI1A_1_5MHz_FDD_t; - dci_length_bytes = sizeof(DCI1A_1_5MHz_FDD_t); - ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->type = 1; - ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->vrb_type = 1; - ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc = computeRIV(eNB->frame_parms.N_RB_DL,0,9); - ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC = TPC; - ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; - ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs = mcs1; - ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi = 0; - ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv = 0; - break; - - case 25: - dci_length = sizeof_DCI1A_5MHz_FDD_t; - dci_length_bytes = sizeof(DCI1A_5MHz_FDD_t); - ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->type = 1; - ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->vrb_type = 1; - ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc = computeRIV(eNB->frame_parms.N_RB_DL,0,9); - ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC = TPC; - ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; - ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs = mcs1; - ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi = 0; - ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv = 0; - break; - - case 50: - dci_length = sizeof_DCI1A_10MHz_FDD_t; - dci_length_bytes = sizeof(DCI1A_10MHz_FDD_t); - ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->type = 1; - ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->vrb_type = 1; - ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc = computeRIV(eNB->frame_parms.N_RB_DL,0,9); - ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC = TPC; - ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; - ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs = mcs1; - ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi = 0; - ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv = 0; - break; - - case 100: - dci_length = sizeof_DCI1A_20MHz_FDD_t; - dci_length_bytes = sizeof(DCI1A_20MHz_FDD_t); - ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->type = 1; - ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->vrb_type = 1; - ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc = computeRIV(eNB->frame_parms.N_RB_DL,0,9); - ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC = TPC; - ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; - ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs = mcs1; - ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi = 0; - ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv = 0; - break; + if (eNB->frame_parms.frame_type == TDD) { + switch (eNB->frame_parms.N_RB_DL) { + case 6: + dci_length = sizeof_DCI1A_1_5MHz_TDD_1_6_t; + dci_length_bytes = sizeof(DCI1A_1_5MHz_TDD_1_6_t); + ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->type = 1; + ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->vrb_type = 0; + ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rballoc = computeRIV(eNB->frame_parms.N_RB_DL,0,9); + ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->TPC = TPC; + ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->dai = 0; + ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; + ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->mcs = mcs1; + ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->ndi = 0; + ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rv = 0; + break; + + case 25: + dci_length = sizeof_DCI1A_5MHz_TDD_1_6_t; + dci_length_bytes = sizeof(DCI1A_5MHz_TDD_1_6_t); + ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->type = 1; + ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->vrb_type = 0; + ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rballoc = computeRIV(eNB->frame_parms.N_RB_DL,0,9); + ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->TPC = TPC; + ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->dai = 0; + ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; + ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->mcs = mcs1; + ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->ndi = 0; + ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rv = 1; + break; + + case 50: + dci_length = sizeof_DCI1A_10MHz_TDD_1_6_t; + dci_length_bytes = sizeof(DCI1A_10MHz_TDD_1_6_t); + ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->type = 1; + ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->vrb_type = 1; + ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rballoc = computeRIV(eNB->frame_parms.N_RB_DL,0,9); + ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->TPC = TPC; + ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->dai = 0; + ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; + ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->mcs = mcs1; + ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->ndi = 0; + ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rv = 0; + break; + + case 100: + ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->type = 1; + ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->vrb_type = 1; + ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rballoc = computeRIV(eNB->frame_parms.N_RB_DL,0,9); + ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->TPC = TPC; + ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->dai = 0; + ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; + ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->mcs = mcs1; + ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->ndi = 0; + ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rv = 0; + dci_length = sizeof_DCI1A_20MHz_TDD_1_6_t; + dci_length_bytes = sizeof(DCI1A_20MHz_TDD_1_6_t); + break; + } + } else { + switch (eNB->frame_parms.N_RB_DL) { + case 6: + dci_length = sizeof_DCI1A_1_5MHz_FDD_t; + dci_length_bytes = sizeof(DCI1A_1_5MHz_FDD_t); + ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->type = 1; + ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->vrb_type = 1; + ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc = computeRIV(eNB->frame_parms.N_RB_DL,0,9); + ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC = TPC; + ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; + ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs = mcs1; + ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi = 0; + ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv = 0; + break; + + case 25: + dci_length = sizeof_DCI1A_5MHz_FDD_t; + dci_length_bytes = sizeof(DCI1A_5MHz_FDD_t); + ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->type = 1; + ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->vrb_type = 1; + ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc = computeRIV(eNB->frame_parms.N_RB_DL,0,9); + ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC = TPC; + ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; + ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs = mcs1; + ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi = 0; + ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv = 0; + break; + + case 50: + dci_length = sizeof_DCI1A_10MHz_FDD_t; + dci_length_bytes = sizeof(DCI1A_10MHz_FDD_t); + ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->type = 1; + ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->vrb_type = 1; + ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc = computeRIV(eNB->frame_parms.N_RB_DL,0,9); + ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC = TPC; + ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; + ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs = mcs1; + ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi = 0; + ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv = 0; + break; + + case 100: + dci_length = sizeof_DCI1A_20MHz_FDD_t; + dci_length_bytes = sizeof(DCI1A_20MHz_FDD_t); + ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->type = 1; + ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->vrb_type = 1; + ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc = computeRIV(eNB->frame_parms.N_RB_DL,0,9); + ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC = TPC; + ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; + ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs = mcs1; + ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi = 0; + ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv = 0; + break; + } } + + memcpy(&dci_alloc[num_dci].dci_pdu[0],&DLSCH_alloc_pdu_1[k],dci_length_bytes); + dci_alloc[num_dci].dci_length = dci_length; + dci_alloc[num_dci].L = 1; + dci_alloc[num_dci].rnti = SI_RNTI; + dci_alloc[num_dci].format = format1A; + dci_alloc[num_dci].firstCCE = 0; + dci_alloc[num_dci].search_space = DCI_COMMON_SPACE; + dump_dci(&eNB->frame_parms,&dci_alloc[num_dci]); + printf("Generating dlsch params for user %d\n",k); + generate_eNB_dlsch_params_from_dci(0, + subframe, + &DLSCH_alloc_pdu_1[0], + SI_RNTI, + format1A, + eNB->dlsch[0], + &eNB->frame_parms, + eNB->pdsch_config_dedicated, + SI_RNTI, + 0, + P_RNTI, + eNB->UE_stats[0].DL_pmi_single, + 0); + num_common_dci++; + num_dci++; } - memcpy(&dci_alloc[num_dci].dci_pdu[0],&DLSCH_alloc_pdu_1[k],dci_length_bytes); - dci_alloc[num_dci].dci_length = dci_length; - dci_alloc[num_dci].L = 1; - dci_alloc[num_dci].rnti = SI_RNTI; - dci_alloc[num_dci].format = format1A; - dci_alloc[num_dci].firstCCE = 0; - dci_alloc[num_dci].search_space = DCI_COMMON_SPACE; - dump_dci(&eNB->frame_parms,&dci_alloc[num_dci]); + break; - printf("Generating dlsch params for user %d\n",k); - generate_eNB_dlsch_params_from_dci(0, - subframe, - &DLSCH_alloc_pdu_1[0], - SI_RNTI, - format1A, - eNB->dlsch[0], - &eNB->frame_parms, - eNB->pdsch_config_dedicated, - SI_RNTI, - 0, - P_RNTI, - eNB->UE_stats[0].DL_pmi_single, - 0); + case 3: + if (common_flag == 0) { + if (eNB->frame_parms.nb_antennas_tx == 2) { + if (eNB->frame_parms.frame_type == TDD) { + switch (eNB->frame_parms.N_RB_DL) { + case 6: + dci_length = sizeof_DCI2A_1_5MHz_2A_TDD_t; + dci_length_bytes = sizeof(DCI2A_1_5MHz_2A_TDD_t); + ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc = DLSCH_RB_ALLOC; + ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->TPC = 0; + ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->dai = 0; + ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; + ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->mcs1 = mcs1; + ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->ndi1 = 1; + ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rv1 = 0; + ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->mcs2 = mcs2; + ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->ndi2 = 1; + ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rv2 = 0; + break; - num_common_dci++; - num_dci++; + case 25: + dci_length = sizeof_DCI2A_5MHz_2A_TDD_t; + dci_length_bytes = sizeof(DCI2A_5MHz_2A_TDD_t); + ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rah = 0; + ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc = DLSCH_RB_ALLOC; + ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->TPC = 0; + ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->dai = 0; + ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; + ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->mcs1 = mcs1; + ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->ndi1 = 1; + ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rv1 = 0; + ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->mcs2 = mcs2; + ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->ndi2 = 1; + ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rv2 = 0; + break; - } - - break; + case 50: + dci_length = sizeof_DCI2A_10MHz_2A_TDD_t; + dci_length_bytes = sizeof(DCI2A_10MHz_2A_TDD_t); + ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rah = 0; + ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc = DLSCH_RB_ALLOC; + ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->TPC = 0; + ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->dai = 0; + ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; + ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->mcs1 = mcs1; + ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->ndi1 = 1; + ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rv1 = 0; + ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->mcs2 = mcs2; + ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->ndi2 = 1; + ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rv2 = 0; + break; - case 3: - if (common_flag == 0) { + case 100: + ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rah = 0; + ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc = DLSCH_RB_ALLOC; + ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->TPC = 0; + ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->dai = 0; + ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; + ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->mcs1 = mcs1; + ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->ndi1 = 1; + ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rv1 = 0; + ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->mcs2 = mcs2; + ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->ndi2 = 1; + ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rv2 = 0; + dci_length = sizeof_DCI2A_20MHz_2A_TDD_t; + dci_length_bytes = sizeof(DCI2A_20MHz_2A_TDD_t); + break; + } + } else { + switch (eNB->frame_parms.N_RB_DL) { + case 6: + dci_length = sizeof_DCI2A_1_5MHz_2A_FDD_t; + dci_length_bytes = sizeof(DCI2A_1_5MHz_2A_FDD_t); + ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc = DLSCH_RB_ALLOC; + ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC = 0; + ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; + ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs1 = mcs1; + ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi1 = 1; + ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv1 = 0; + ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs2 = mcs2; + ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi2 = 1; + ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv2 = 0; + break; - if (eNB->frame_parms.nb_antennas_tx == 2) { + case 25: + dci_length = sizeof_DCI2A_5MHz_2A_FDD_t; + dci_length_bytes = sizeof(DCI2A_5MHz_2A_FDD_t); + ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rah = 0; + ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc = DLSCH_RB_ALLOC; + ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC = 0; + ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; + ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs1 = mcs1; + ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi1 = 1; + ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv1 = 0; + ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs2 = mcs2; + ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi2 = 1; + ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv2 = 0; + break; - if (eNB->frame_parms.frame_type == TDD) { + case 50: + dci_length = sizeof_DCI2A_10MHz_2A_FDD_t; + dci_length_bytes = sizeof(DCI2A_10MHz_2A_FDD_t); + ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rah = 0; + ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc = DLSCH_RB_ALLOC; + ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC = 0; + ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; + ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs1 = mcs1; + ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi1 = 1; + ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv1 = 0; + ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs2 = mcs2; + ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi2 = 1; + ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv2 = 0; + break; - switch (eNB->frame_parms.N_RB_DL) { - case 6: - dci_length = sizeof_DCI2A_1_5MHz_2A_TDD_t; - dci_length_bytes = sizeof(DCI2A_1_5MHz_2A_TDD_t); - ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc = DLSCH_RB_ALLOC; - ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->TPC = 0; - ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->dai = 0; - ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; - ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->mcs1 = mcs1; - ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->ndi1 = 1; - ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rv1 = 0; - ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->mcs2 = mcs2; - ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->ndi2 = 1; - ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rv2 = 0; - break; - - case 25: - dci_length = sizeof_DCI2A_5MHz_2A_TDD_t; - dci_length_bytes = sizeof(DCI2A_5MHz_2A_TDD_t); - ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rah = 0; - ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc = DLSCH_RB_ALLOC; - ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->TPC = 0; - ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->dai = 0; - ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; - ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->mcs1 = mcs1; - ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->ndi1 = 1; - ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rv1 = 0; - ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->mcs2 = mcs2; - ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->ndi2 = 1; - ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rv2 = 0; - break; - - case 50: - dci_length = sizeof_DCI2A_10MHz_2A_TDD_t; - dci_length_bytes = sizeof(DCI2A_10MHz_2A_TDD_t); - ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rah = 0; - ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc = DLSCH_RB_ALLOC; - ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->TPC = 0; - ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->dai = 0; - ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; - ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->mcs1 = mcs1; - ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->ndi1 = 1; - ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rv1 = 0; - ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->mcs2 = mcs2; - ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->ndi2 = 1; - ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rv2 = 0; - break; - - case 100: - ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rah = 0; - ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc = DLSCH_RB_ALLOC; - ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->TPC = 0; - ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->dai = 0; - ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; - ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->mcs1 = mcs1; - ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->ndi1 = 1; - ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rv1 = 0; - ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->mcs2 = mcs2; - ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->ndi2 = 1; - ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rv2 = 0; - dci_length = sizeof_DCI2A_20MHz_2A_TDD_t; - dci_length_bytes = sizeof(DCI2A_20MHz_2A_TDD_t); - break; + case 100: + dci_length = sizeof_DCI2A_20MHz_2A_FDD_t; + dci_length_bytes = sizeof(DCI2A_20MHz_2A_FDD_t); + ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rah = 0; + ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc = DLSCH_RB_ALLOC; + ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC = 0; + ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; + ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs1 = mcs1; + ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi1 = 1; + ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv1 = 0; + ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs2 = mcs2; + ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi2 = 1; + ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv2 = 0; + break; + } } + } else if (eNB->frame_parms.nb_antennas_tx == 4) { } - else { + memcpy(&dci_alloc[num_dci].dci_pdu[0],&DLSCH_alloc_pdu_1[k],dci_length_bytes); + dci_alloc[num_dci].dci_length = dci_length; + dci_alloc[num_dci].L = 1; + dci_alloc[num_dci].rnti = n_rnti+k; + dci_alloc[num_dci].format = format2A; + dci_alloc[num_dci].search_space = DCI_UE_SPACE; + dump_dci(&eNB->frame_parms,&dci_alloc[num_dci]); + printf("Generating dlsch params for user %d / format 2A (%d)\n",k,format2A); + generate_eNB_dlsch_params_from_dci(0, + subframe, + &DLSCH_alloc_pdu_1[0], + n_rnti+k, + format2A, + eNB->dlsch[0], + &eNB->frame_parms, + eNB->pdsch_config_dedicated, + SI_RNTI, + 0, + P_RNTI, + eNB->UE_stats[0].DL_pmi_single, + 0); + num_dci++; + num_ue_spec_dci++; + } else { + if (eNB->frame_parms.frame_type == TDD) { + switch (eNB->frame_parms.N_RB_DL) { + case 6: + dci_length = sizeof_DCI1A_1_5MHz_TDD_1_6_t; + dci_length_bytes = sizeof(DCI1A_1_5MHz_TDD_1_6_t); + ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->type = 1; + ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->vrb_type = 0; + ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rballoc = computeRIV(eNB->frame_parms.N_RB_DL,0,9); + ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->TPC = TPC; + ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->dai = 0; + ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; + ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->mcs = mcs1; + ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->ndi = 0; + ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rv = 0; + break; + + case 25: + dci_length = sizeof_DCI1A_5MHz_TDD_1_6_t; + dci_length_bytes = sizeof(DCI1A_5MHz_TDD_1_6_t); + ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->type = 1; + ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->vrb_type = 0; + ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rballoc = computeRIV(eNB->frame_parms.N_RB_DL,0,9); + ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->TPC = TPC; + ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->dai = 0; + ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; + ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->mcs = mcs1; + ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->ndi = 0; + ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rv = 1; + break; + + case 50: + dci_length = sizeof_DCI1A_10MHz_TDD_1_6_t; + dci_length_bytes = sizeof(DCI1A_10MHz_TDD_1_6_t); + ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->type = 1; + ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->vrb_type = 1; + ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rballoc = computeRIV(eNB->frame_parms.N_RB_DL,0,9); + ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->TPC = TPC; + ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->dai = 0; + ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; + ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->mcs = mcs1; + ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->ndi = 0; + ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rv = 0; + break; + + case 100: + ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->type = 1; + ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->vrb_type = 1; + ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rballoc = computeRIV(eNB->frame_parms.N_RB_DL,0,9); + ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->TPC = TPC; + ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->dai = 0; + ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; + ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->mcs = mcs1; + ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->ndi = 0; + ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rv = 0; + dci_length = sizeof_DCI1A_20MHz_TDD_1_6_t; + dci_length_bytes = sizeof(DCI1A_20MHz_TDD_1_6_t); + break; + } + } else { switch (eNB->frame_parms.N_RB_DL) { - case 6: - dci_length = sizeof_DCI2A_1_5MHz_2A_FDD_t; - dci_length_bytes = sizeof(DCI2A_1_5MHz_2A_FDD_t); - ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc = DLSCH_RB_ALLOC; - ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC = 0; - ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; - ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs1 = mcs1; - ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi1 = 1; - ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv1 = 0; - ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs2 = mcs2; - ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi2 = 1; - ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv2 = 0; - break; - - case 25: - dci_length = sizeof_DCI2A_5MHz_2A_FDD_t; - dci_length_bytes = sizeof(DCI2A_5MHz_2A_FDD_t); - ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rah = 0; - ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc = DLSCH_RB_ALLOC; - ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC = 0; - ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; - ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs1 = mcs1; - ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi1 = 1; - ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv1 = 0; - ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs2 = mcs2; - ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi2 = 1; - ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv2 = 0; - break; - - case 50: - dci_length = sizeof_DCI2A_10MHz_2A_FDD_t; - dci_length_bytes = sizeof(DCI2A_10MHz_2A_FDD_t); - ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rah = 0; - ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc = DLSCH_RB_ALLOC; - ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC = 0; - ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; - ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs1 = mcs1; - ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi1 = 1; - ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv1 = 0; - ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs2 = mcs2; - ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi2 = 1; - ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv2 = 0; - break; - - case 100: - dci_length = sizeof_DCI2A_20MHz_2A_FDD_t; - dci_length_bytes = sizeof(DCI2A_20MHz_2A_FDD_t); - ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rah = 0; - ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc = DLSCH_RB_ALLOC; - ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC = 0; - ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; - ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs1 = mcs1; - ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi1 = 1; - ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv1 = 0; - ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs2 = mcs2; - ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi2 = 1; - ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv2 = 0; - break; + case 6: + dci_length = sizeof_DCI1A_1_5MHz_FDD_t; + dci_length_bytes = sizeof(DCI1A_1_5MHz_FDD_t); + ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->type = 1; + ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->vrb_type = 1; + ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc = computeRIV(eNB->frame_parms.N_RB_DL,0,9); + ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC = TPC; + ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; + ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs = mcs1; + ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi = 0; + ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv = 0; + break; + + case 25: + dci_length = sizeof_DCI1A_5MHz_FDD_t; + dci_length_bytes = sizeof(DCI1A_5MHz_FDD_t); + ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->type = 1; + ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->vrb_type = 1; + ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc = computeRIV(eNB->frame_parms.N_RB_DL,0,9); + ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC = TPC; + ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; + ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs = mcs1; + ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi = 0; + ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv = 0; + break; + + case 50: + dci_length = sizeof_DCI1A_10MHz_FDD_t; + dci_length_bytes = sizeof(DCI1A_10MHz_FDD_t); + ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->type = 1; + ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->vrb_type = 1; + ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc = computeRIV(eNB->frame_parms.N_RB_DL,0,9); + ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC = TPC; + ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; + ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs = mcs1; + ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi = 0; + ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv = 0; + break; + + case 100: + dci_length = sizeof_DCI1A_20MHz_FDD_t; + dci_length_bytes = sizeof(DCI1A_20MHz_FDD_t); + ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->type = 1; + ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->vrb_type = 1; + ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc = computeRIV(eNB->frame_parms.N_RB_DL,0,9); + ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC = TPC; + ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; + ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs = mcs1; + ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi = 0; + ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv = 0; + break; } } - } else if (eNB->frame_parms.nb_antennas_tx == 4) { + memcpy(&dci_alloc[num_dci].dci_pdu[0],&DLSCH_alloc_pdu_1[k],dci_length_bytes); + dci_alloc[num_dci].dci_length = dci_length; + dci_alloc[num_dci].L = 1; + dci_alloc[num_dci].rnti = SI_RNTI; + dci_alloc[num_dci].format = format1A; + dci_alloc[num_dci].firstCCE = 0; + dci_alloc[num_dci].search_space = DCI_COMMON_SPACE; + dump_dci(&eNB->frame_parms,&dci_alloc[num_dci]); + printf("Generating dlsch params for user %d\n",k); + generate_eNB_dlsch_params_from_dci(0, + subframe, + &DLSCH_alloc_pdu_1[0], + SI_RNTI, + format1A, + eNB->dlsch[0], + &eNB->frame_parms, + eNB->pdsch_config_dedicated, + SI_RNTI, + 0, + P_RNTI, + eNB->UE_stats[0].DL_pmi_single, + 0); + num_common_dci++; + num_dci++; } - memcpy(&dci_alloc[num_dci].dci_pdu[0],&DLSCH_alloc_pdu_1[k],dci_length_bytes); - dci_alloc[num_dci].dci_length = dci_length; - dci_alloc[num_dci].L = 1; - dci_alloc[num_dci].rnti = n_rnti+k; - dci_alloc[num_dci].format = format2A; - dci_alloc[num_dci].search_space = DCI_UE_SPACE; - dump_dci(&eNB->frame_parms,&dci_alloc[num_dci]); - - printf("Generating dlsch params for user %d / format 2A (%d)\n",k,format2A); - generate_eNB_dlsch_params_from_dci(0, - subframe, - &DLSCH_alloc_pdu_1[0], - n_rnti+k, - format2A, - eNB->dlsch[0], - &eNB->frame_parms, - eNB->pdsch_config_dedicated, - SI_RNTI, - 0, - P_RNTI, - eNB->UE_stats[0].DL_pmi_single, - 0); - - num_dci++; - num_ue_spec_dci++; - } else { - if (eNB->frame_parms.frame_type == TDD) { - - switch (eNB->frame_parms.N_RB_DL) { - case 6: - dci_length = sizeof_DCI1A_1_5MHz_TDD_1_6_t; - dci_length_bytes = sizeof(DCI1A_1_5MHz_TDD_1_6_t); - ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->type = 1; - ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->vrb_type = 0; - ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rballoc = computeRIV(eNB->frame_parms.N_RB_DL,0,9); - ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->TPC = TPC; - ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->dai = 0; - ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; - ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->mcs = mcs1; - ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->ndi = 0; - ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rv = 0; - break; - - case 25: - dci_length = sizeof_DCI1A_5MHz_TDD_1_6_t; - dci_length_bytes = sizeof(DCI1A_5MHz_TDD_1_6_t); - ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->type = 1; - ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->vrb_type = 0; - ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rballoc = computeRIV(eNB->frame_parms.N_RB_DL,0,9); - ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->TPC = TPC; - ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->dai = 0; - ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; - ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->mcs = mcs1; - ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->ndi = 0; - ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rv = 1; - break; - - case 50: - dci_length = sizeof_DCI1A_10MHz_TDD_1_6_t; - dci_length_bytes = sizeof(DCI1A_10MHz_TDD_1_6_t); - ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->type = 1; - ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->vrb_type = 1; - ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rballoc = computeRIV(eNB->frame_parms.N_RB_DL,0,9); - ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->TPC = TPC; - ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->dai = 0; - ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; - ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->mcs = mcs1; - ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->ndi = 0; - ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rv = 0; - break; - - case 100: - ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->type = 1; - ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->vrb_type = 1; - ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rballoc = computeRIV(eNB->frame_parms.N_RB_DL,0,9); - ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->TPC = TPC; - ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->dai = 0; - ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; - ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->mcs = mcs1; - ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->ndi = 0; - ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rv = 0; - dci_length = sizeof_DCI1A_20MHz_TDD_1_6_t; - dci_length_bytes = sizeof(DCI1A_20MHz_TDD_1_6_t); - break; - } - } else { - switch (eNB->frame_parms.N_RB_DL) { - case 6: - dci_length = sizeof_DCI1A_1_5MHz_FDD_t; - dci_length_bytes = sizeof(DCI1A_1_5MHz_FDD_t); - ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->type = 1; - ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->vrb_type = 1; - ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc = computeRIV(eNB->frame_parms.N_RB_DL,0,9); - ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC = TPC; - ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; - ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs = mcs1; - ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi = 0; - ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv = 0; - break; - - case 25: - dci_length = sizeof_DCI1A_5MHz_FDD_t; - dci_length_bytes = sizeof(DCI1A_5MHz_FDD_t); - ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->type = 1; - ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->vrb_type = 1; - ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc = computeRIV(eNB->frame_parms.N_RB_DL,0,9); - ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC = TPC; - ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; - ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs = mcs1; - ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi = 0; - ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv = 0; - break; - - case 50: - dci_length = sizeof_DCI1A_10MHz_FDD_t; - dci_length_bytes = sizeof(DCI1A_10MHz_FDD_t); - ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->type = 1; - ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->vrb_type = 1; - ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc = computeRIV(eNB->frame_parms.N_RB_DL,0,9); - ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC = TPC; - ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; - ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs = mcs1; - ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi = 0; - ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv = 0; - break; - - case 100: - dci_length = sizeof_DCI1A_20MHz_FDD_t; - dci_length_bytes = sizeof(DCI1A_20MHz_FDD_t); - ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->type = 1; - ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->vrb_type = 1; - ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc = computeRIV(eNB->frame_parms.N_RB_DL,0,9); - ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC = TPC; - ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; - ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs = mcs1; - ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi = 0; - ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv = 0; - break; - } - } + printf("Generated DCI format 2A (Transmission Mode 3)\n"); + break; - memcpy(&dci_alloc[num_dci].dci_pdu[0],&DLSCH_alloc_pdu_1[k],dci_length_bytes); - dci_alloc[num_dci].dci_length = dci_length; - dci_alloc[num_dci].L = 1; - dci_alloc[num_dci].rnti = SI_RNTI; - dci_alloc[num_dci].format = format1A; - dci_alloc[num_dci].firstCCE = 0; - dci_alloc[num_dci].search_space = DCI_COMMON_SPACE; - dump_dci(&eNB->frame_parms,&dci_alloc[num_dci]); + case 4: + if (common_flag == 0) { + if (eNB->frame_parms.nb_antennas_tx == 2) { + if (eNB->frame_parms.frame_type == TDD) { + switch (eNB->frame_parms.N_RB_DL) { + case 6: + dci_length = sizeof_DCI2_1_5MHz_2A_TDD_t; + dci_length_bytes = sizeof(DCI2_1_5MHz_2A_TDD_t); + ((DCI2_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc = DLSCH_RB_ALLOC; + ((DCI2_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->TPC = 0; + ((DCI2_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->dai = 0; + ((DCI2_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; + ((DCI2_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->mcs1 = mcs1; + ((DCI2_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->ndi1 = 1; + ((DCI2_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rv1 = 0; + ((DCI2_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->mcs2 = mcs2; + ((DCI2_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->ndi2 = 1; + ((DCI2_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rv2 = 0; + break; - printf("Generating dlsch params for user %d\n",k); - generate_eNB_dlsch_params_from_dci(0, - subframe, - &DLSCH_alloc_pdu_1[0], - SI_RNTI, - format1A, - eNB->dlsch[0], - &eNB->frame_parms, - eNB->pdsch_config_dedicated, - SI_RNTI, - 0, - P_RNTI, - eNB->UE_stats[0].DL_pmi_single, - 0); + case 25: + dci_length = sizeof_DCI2_5MHz_2A_TDD_t; + dci_length_bytes = sizeof(DCI2_5MHz_2A_TDD_t); + ((DCI2_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rah = 0; + ((DCI2_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc = DLSCH_RB_ALLOC; + ((DCI2_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->TPC = 0; + ((DCI2_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->dai = 0; + ((DCI2_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; + ((DCI2_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->mcs1 = mcs1; + ((DCI2_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->ndi1 = 1; + ((DCI2_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rv1 = 0; + ((DCI2_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->mcs2 = mcs2; + ((DCI2_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->ndi2 = 1; + ((DCI2_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rv2 = 0; + break; - num_common_dci++; - num_dci++; + case 50: + dci_length = sizeof_DCI2_10MHz_2A_TDD_t; + dci_length_bytes = sizeof(DCI2_10MHz_2A_TDD_t); + ((DCI2_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rah = 0; + ((DCI2_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc = DLSCH_RB_ALLOC; + ((DCI2_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->TPC = 0; + ((DCI2_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->dai = 0; + ((DCI2_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; + ((DCI2_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->mcs1 = mcs1; + ((DCI2_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->ndi1 = 1; + ((DCI2_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rv1 = 0; + ((DCI2_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->mcs2 = mcs2; + ((DCI2_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->ndi2 = 1; + ((DCI2_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rv2 = 0; + break; - } + case 100: + ((DCI2_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rah = 0; + ((DCI2_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc = DLSCH_RB_ALLOC; + ((DCI2_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->TPC = 0; + ((DCI2_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->dai = 0; + ((DCI2_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; + ((DCI2_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->mcs1 = mcs1; + ((DCI2_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->ndi1 = 1; + ((DCI2_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rv1 = 0; + ((DCI2_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->mcs2 = mcs2; + ((DCI2_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->ndi2 = 1; + ((DCI2_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rv2 = 0; + dci_length = sizeof_DCI2_20MHz_2A_TDD_t; + dci_length_bytes = sizeof(DCI2_20MHz_2A_TDD_t); + break; + } + } else { + switch (eNB->frame_parms.N_RB_DL) { + case 6: + dci_length = sizeof_DCI2_1_5MHz_2A_FDD_t; + dci_length_bytes = sizeof(DCI2_1_5MHz_2A_FDD_t); + ((DCI2_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc = DLSCH_RB_ALLOC; + ((DCI2_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC = 0; + ((DCI2_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; + ((DCI2_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs1 = mcs1; + ((DCI2_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi1 = 1; + ((DCI2_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv1 = 0; + ((DCI2_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs2 = mcs2; + ((DCI2_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi2 = 1; + ((DCI2_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv2 = 0; + break; - printf("Generated DCI format 2A (Transmission Mode 3)\n"); - break; + case 25: + dci_length = sizeof_DCI2_5MHz_2A_FDD_t; + dci_length_bytes = sizeof(DCI2_5MHz_2A_FDD_t); + ((DCI2_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rah = 0; + ((DCI2_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc = DLSCH_RB_ALLOC; + ((DCI2_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC = 0; + ((DCI2_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; + ((DCI2_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs1 = mcs1; + ((DCI2_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi1 = 1; + ((DCI2_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv1 = 0; + ((DCI2_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs2 = mcs2; + ((DCI2_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi2 = 1; + ((DCI2_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv2 = 0; + break; - case 4: - if (common_flag == 0) { + case 50: + dci_length = sizeof_DCI2_10MHz_2A_FDD_t; + dci_length_bytes = sizeof(DCI2_10MHz_2A_FDD_t); + ((DCI2_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rah = 0; + ((DCI2_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc = DLSCH_RB_ALLOC; + ((DCI2_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC = 0; + ((DCI2_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; + ((DCI2_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs1 = mcs1; + ((DCI2_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi1 = 1; + ((DCI2_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv1 = 0; + ((DCI2_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs2 = mcs2; + ((DCI2_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi2 = 1; + ((DCI2_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv2 = 0; + break; - if (eNB->frame_parms.nb_antennas_tx == 2) { + case 100: + dci_length = sizeof_DCI2_20MHz_2A_FDD_t; + dci_length_bytes = sizeof(DCI2_20MHz_2A_FDD_t); + ((DCI2_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rah = 0; + ((DCI2_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc = DLSCH_RB_ALLOC; + ((DCI2_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC = 0; + ((DCI2_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; + ((DCI2_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs1 = mcs1; + ((DCI2_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi1 = 1; + ((DCI2_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv1 = 0; + ((DCI2_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs2 = mcs2; + ((DCI2_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi2 = 1; + ((DCI2_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv2 = 0; + break; + } + } + } else if (eNB->frame_parms.nb_antennas_tx == 4) { + } + memcpy(&dci_alloc[num_dci].dci_pdu[0],&DLSCH_alloc_pdu_1[k],dci_length_bytes); + dci_alloc[num_dci].dci_length = dci_length; + dci_alloc[num_dci].L = 1; + dci_alloc[num_dci].rnti = n_rnti+k; + dci_alloc[num_dci].format = format2; + dci_alloc[num_dci].search_space = DCI_UE_SPACE; + dump_dci(&eNB->frame_parms,&dci_alloc[num_dci]); + printf("Generating dlsch params for user %d\n",k); + generate_eNB_dlsch_params_from_dci(0, + subframe, + &DLSCH_alloc_pdu_1[0], + n_rnti+k, + format2, + eNB->dlsch[0], + &eNB->frame_parms, + eNB->pdsch_config_dedicated, + SI_RNTI, + 0, + P_RNTI, + eNB->UE_stats[0].DL_pmi_single, + 0); + num_dci++; + num_ue_spec_dci++; + } else { if (eNB->frame_parms.frame_type == TDD) { - switch (eNB->frame_parms.N_RB_DL) { - case 6: - dci_length = sizeof_DCI2_1_5MHz_2A_TDD_t; - dci_length_bytes = sizeof(DCI2_1_5MHz_2A_TDD_t); - ((DCI2_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc = DLSCH_RB_ALLOC; - ((DCI2_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->TPC = 0; - ((DCI2_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->dai = 0; - ((DCI2_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; - ((DCI2_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->mcs1 = mcs1; - ((DCI2_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->ndi1 = 1; - ((DCI2_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rv1 = 0; - ((DCI2_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->mcs2 = mcs2; - ((DCI2_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->ndi2 = 1; - ((DCI2_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rv2 = 0; - break; - - case 25: - dci_length = sizeof_DCI2_5MHz_2A_TDD_t; - dci_length_bytes = sizeof(DCI2_5MHz_2A_TDD_t); - ((DCI2_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rah = 0; - ((DCI2_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc = DLSCH_RB_ALLOC; - ((DCI2_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->TPC = 0; - ((DCI2_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->dai = 0; - ((DCI2_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; - ((DCI2_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->mcs1 = mcs1; - ((DCI2_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->ndi1 = 1; - ((DCI2_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rv1 = 0; - ((DCI2_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->mcs2 = mcs2; - ((DCI2_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->ndi2 = 1; - ((DCI2_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rv2 = 0; - break; - - case 50: - dci_length = sizeof_DCI2_10MHz_2A_TDD_t; - dci_length_bytes = sizeof(DCI2_10MHz_2A_TDD_t); - ((DCI2_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rah = 0; - ((DCI2_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc = DLSCH_RB_ALLOC; - ((DCI2_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->TPC = 0; - ((DCI2_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->dai = 0; - ((DCI2_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; - ((DCI2_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->mcs1 = mcs1; - ((DCI2_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->ndi1 = 1; - ((DCI2_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rv1 = 0; - ((DCI2_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->mcs2 = mcs2; - ((DCI2_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->ndi2 = 1; - ((DCI2_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rv2 = 0; - break; - - case 100: - ((DCI2_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rah = 0; - ((DCI2_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc = DLSCH_RB_ALLOC; - ((DCI2_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->TPC = 0; - ((DCI2_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->dai = 0; - ((DCI2_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; - ((DCI2_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->mcs1 = mcs1; - ((DCI2_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->ndi1 = 1; - ((DCI2_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rv1 = 0; - ((DCI2_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->mcs2 = mcs2; - ((DCI2_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->ndi2 = 1; - ((DCI2_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[k])->rv2 = 0; - dci_length = sizeof_DCI2_20MHz_2A_TDD_t; - dci_length_bytes = sizeof(DCI2_20MHz_2A_TDD_t); - break; + case 6: + dci_length = sizeof_DCI1A_1_5MHz_TDD_1_6_t; + dci_length_bytes = sizeof(DCI1A_1_5MHz_TDD_1_6_t); + ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->type = 1; + ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->vrb_type = 0; + ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rballoc = computeRIV(eNB->frame_parms.N_RB_DL,0,9); + ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->TPC = TPC; + ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->dai = 0; + ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; + ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->mcs = mcs1; + ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->ndi = 0; + ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rv = 0; + break; + + case 25: + dci_length = sizeof_DCI1A_5MHz_TDD_1_6_t; + dci_length_bytes = sizeof(DCI1A_5MHz_TDD_1_6_t); + ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->type = 1; + ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->vrb_type = 0; + ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rballoc = computeRIV(eNB->frame_parms.N_RB_DL,0,9); + ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->TPC = TPC; + ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->dai = 0; + ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; + ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->mcs = mcs1; + ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->ndi = 0; + ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rv = 1; + break; + + case 50: + dci_length = sizeof_DCI1A_10MHz_TDD_1_6_t; + dci_length_bytes = sizeof(DCI1A_10MHz_TDD_1_6_t); + ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->type = 1; + ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->vrb_type = 1; + ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rballoc = computeRIV(eNB->frame_parms.N_RB_DL,0,9); + ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->TPC = TPC; + ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->dai = 0; + ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; + ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->mcs = mcs1; + ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->ndi = 0; + ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rv = 0; + break; + + case 100: + ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->type = 1; + ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->vrb_type = 1; + ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rballoc = computeRIV(eNB->frame_parms.N_RB_DL,0,9); + ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->TPC = TPC; + ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->dai = 0; + ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; + ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->mcs = mcs1; + ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->ndi = 0; + ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rv = 0; + dci_length = sizeof_DCI1A_20MHz_TDD_1_6_t; + dci_length_bytes = sizeof(DCI1A_20MHz_TDD_1_6_t); + break; } - } - - else { + } else { switch (eNB->frame_parms.N_RB_DL) { - case 6: - dci_length = sizeof_DCI2_1_5MHz_2A_FDD_t; - dci_length_bytes = sizeof(DCI2_1_5MHz_2A_FDD_t); - ((DCI2_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc = DLSCH_RB_ALLOC; - ((DCI2_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC = 0; - ((DCI2_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; - ((DCI2_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs1 = mcs1; - ((DCI2_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi1 = 1; - ((DCI2_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv1 = 0; - ((DCI2_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs2 = mcs2; - ((DCI2_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi2 = 1; - ((DCI2_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv2 = 0; - break; - - case 25: - dci_length = sizeof_DCI2_5MHz_2A_FDD_t; - dci_length_bytes = sizeof(DCI2_5MHz_2A_FDD_t); - ((DCI2_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rah = 0; - ((DCI2_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc = DLSCH_RB_ALLOC; - ((DCI2_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC = 0; - ((DCI2_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; - ((DCI2_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs1 = mcs1; - ((DCI2_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi1 = 1; - ((DCI2_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv1 = 0; - ((DCI2_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs2 = mcs2; - ((DCI2_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi2 = 1; - ((DCI2_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv2 = 0; - break; - - case 50: - dci_length = sizeof_DCI2_10MHz_2A_FDD_t; - dci_length_bytes = sizeof(DCI2_10MHz_2A_FDD_t); - ((DCI2_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rah = 0; - ((DCI2_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc = DLSCH_RB_ALLOC; - ((DCI2_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC = 0; - ((DCI2_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; - ((DCI2_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs1 = mcs1; - ((DCI2_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi1 = 1; - ((DCI2_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv1 = 0; - ((DCI2_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs2 = mcs2; - ((DCI2_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi2 = 1; - ((DCI2_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv2 = 0; - break; - - case 100: - dci_length = sizeof_DCI2_20MHz_2A_FDD_t; - dci_length_bytes = sizeof(DCI2_20MHz_2A_FDD_t); - ((DCI2_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rah = 0; - ((DCI2_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc = DLSCH_RB_ALLOC; - ((DCI2_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC = 0; - ((DCI2_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; - ((DCI2_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs1 = mcs1; - ((DCI2_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi1 = 1; - ((DCI2_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv1 = 0; - ((DCI2_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs2 = mcs2; - ((DCI2_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi2 = 1; - ((DCI2_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv2 = 0; - break; + case 6: + dci_length = sizeof_DCI1A_1_5MHz_FDD_t; + dci_length_bytes = sizeof(DCI1A_1_5MHz_FDD_t); + ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->type = 1; + ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->vrb_type = 1; + ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc = computeRIV(eNB->frame_parms.N_RB_DL,0,9); + ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC = TPC; + ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; + ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs = mcs1; + ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi = 0; + ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv = 0; + break; + + case 25: + dci_length = sizeof_DCI1A_5MHz_FDD_t; + dci_length_bytes = sizeof(DCI1A_5MHz_FDD_t); + ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->type = 1; + ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->vrb_type = 1; + ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc = computeRIV(eNB->frame_parms.N_RB_DL,0,9); + ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC = TPC; + ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; + ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs = mcs1; + ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi = 0; + ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv = 0; + break; + + case 50: + dci_length = sizeof_DCI1A_10MHz_FDD_t; + dci_length_bytes = sizeof(DCI1A_10MHz_FDD_t); + ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->type = 1; + ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->vrb_type = 1; + ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc = computeRIV(eNB->frame_parms.N_RB_DL,0,9); + ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC = TPC; + ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; + ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs = mcs1; + ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi = 0; + ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv = 0; + break; + + case 100: + dci_length = sizeof_DCI1A_20MHz_FDD_t; + dci_length_bytes = sizeof(DCI1A_20MHz_FDD_t); + ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->type = 1; + ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->vrb_type = 1; + ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc = computeRIV(eNB->frame_parms.N_RB_DL,0,9); + ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC = TPC; + ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; + ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs = mcs1; + ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi = 0; + ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv = 0; + break; } } - } else if (eNB->frame_parms.nb_antennas_tx == 4) { + memcpy(&dci_alloc[num_dci].dci_pdu[0],&DLSCH_alloc_pdu_1[k],dci_length_bytes); + dci_alloc[num_dci].dci_length = dci_length; + dci_alloc[num_dci].L = 1; + dci_alloc[num_dci].rnti = SI_RNTI; + dci_alloc[num_dci].format = format1A; + dci_alloc[num_dci].firstCCE = 0; + dci_alloc[num_dci].search_space = DCI_COMMON_SPACE; + dump_dci(&eNB->frame_parms,&dci_alloc[num_dci]); + printf("Generating dlsch params for user %d\n",k); + generate_eNB_dlsch_params_from_dci(0, + subframe, + &DLSCH_alloc_pdu_1[0], + SI_RNTI, + format1A, + eNB->dlsch[0], + &eNB->frame_parms, + eNB->pdsch_config_dedicated, + SI_RNTI, + 0, + P_RNTI, + eNB->UE_stats[0].DL_pmi_single, + 0); + num_common_dci++; + num_dci++; } - memcpy(&dci_alloc[num_dci].dci_pdu[0],&DLSCH_alloc_pdu_1[k],dci_length_bytes); - dci_alloc[num_dci].dci_length = dci_length; + break; + + case 5: + case 6: + memcpy(&dci_alloc[num_dci].dci_pdu[0],&DLSCH_alloc_pdu2_1E[k],sizeof(DCI1E_5MHz_2A_M10PRB_TDD_t)); + dci_alloc[num_dci].dci_length = sizeof_DCI1E_5MHz_2A_M10PRB_TDD_t; dci_alloc[num_dci].L = 1; dci_alloc[num_dci].rnti = n_rnti+k; - dci_alloc[num_dci].format = format2; + dci_alloc[num_dci].format = format1E_2A_M10PRB; + dci_alloc[num_dci].firstCCE = 4*k; dci_alloc[num_dci].search_space = DCI_UE_SPACE; - dump_dci(&eNB->frame_parms,&dci_alloc[num_dci]); - printf("Generating dlsch params for user %d\n",k); generate_eNB_dlsch_params_from_dci(0, - subframe, - &DLSCH_alloc_pdu_1[0], + subframe, + &DLSCH_alloc_pdu2_1E[k], n_rnti+k, - format2, - eNB->dlsch[0], + format1E_2A_M10PRB, + eNB->dlsch[k], &eNB->frame_parms, eNB->pdsch_config_dedicated, SI_RNTI, 0, P_RNTI, - eNB->UE_stats[0].DL_pmi_single, + eNB->UE_stats[k].DL_pmi_single, 0); - - num_dci++; - num_ue_spec_dci++; - } else { - if (eNB->frame_parms.frame_type == TDD) { - - switch (eNB->frame_parms.N_RB_DL) { - case 6: - dci_length = sizeof_DCI1A_1_5MHz_TDD_1_6_t; - dci_length_bytes = sizeof(DCI1A_1_5MHz_TDD_1_6_t); - ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->type = 1; - ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->vrb_type = 0; - ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rballoc = computeRIV(eNB->frame_parms.N_RB_DL,0,9); - ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->TPC = TPC; - ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->dai = 0; - ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; - ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->mcs = mcs1; - ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->ndi = 0; - ((DCI1A_1_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rv = 0; - break; - - case 25: - dci_length = sizeof_DCI1A_5MHz_TDD_1_6_t; - dci_length_bytes = sizeof(DCI1A_5MHz_TDD_1_6_t); - ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->type = 1; - ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->vrb_type = 0; - ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rballoc = computeRIV(eNB->frame_parms.N_RB_DL,0,9); - ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->TPC = TPC; - ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->dai = 0; - ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; - ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->mcs = mcs1; - ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->ndi = 0; - ((DCI1A_5MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rv = 1; - break; - - case 50: - dci_length = sizeof_DCI1A_10MHz_TDD_1_6_t; - dci_length_bytes = sizeof(DCI1A_10MHz_TDD_1_6_t); - ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->type = 1; - ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->vrb_type = 1; - ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rballoc = computeRIV(eNB->frame_parms.N_RB_DL,0,9); - ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->TPC = TPC; - ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->dai = 0; - ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; - ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->mcs = mcs1; - ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->ndi = 0; - ((DCI1A_10MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rv = 0; - break; - - case 100: - ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->type = 1; - ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->vrb_type = 1; - ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rballoc = computeRIV(eNB->frame_parms.N_RB_DL,0,9); - ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->TPC = TPC; - ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->dai = 0; - ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; - ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->mcs = mcs1; - ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->ndi = 0; - ((DCI1A_20MHz_TDD_1_6_t *)&DLSCH_alloc_pdu_1[k])->rv = 0; - dci_length = sizeof_DCI1A_20MHz_TDD_1_6_t; - dci_length_bytes = sizeof(DCI1A_20MHz_TDD_1_6_t); - break; - } - } else { - switch (eNB->frame_parms.N_RB_DL) { - case 6: - dci_length = sizeof_DCI1A_1_5MHz_FDD_t; - dci_length_bytes = sizeof(DCI1A_1_5MHz_FDD_t); - ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->type = 1; - ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->vrb_type = 1; - ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc = computeRIV(eNB->frame_parms.N_RB_DL,0,9); - ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC = TPC; - ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; - ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs = mcs1; - ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi = 0; - ((DCI1A_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv = 0; - break; - - case 25: - dci_length = sizeof_DCI1A_5MHz_FDD_t; - dci_length_bytes = sizeof(DCI1A_5MHz_FDD_t); - ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->type = 1; - ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->vrb_type = 1; - ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc = computeRIV(eNB->frame_parms.N_RB_DL,0,9); - ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC = TPC; - ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; - ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs = mcs1; - ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi = 0; - ((DCI1A_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv = 0; - break; - - case 50: - dci_length = sizeof_DCI1A_10MHz_FDD_t; - dci_length_bytes = sizeof(DCI1A_10MHz_FDD_t); - ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->type = 1; - ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->vrb_type = 1; - ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc = computeRIV(eNB->frame_parms.N_RB_DL,0,9); - ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC = TPC; - ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; - ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs = mcs1; - ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi = 0; - ((DCI1A_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv = 0; - break; - - case 100: - dci_length = sizeof_DCI1A_20MHz_FDD_t; - dci_length_bytes = sizeof(DCI1A_20MHz_FDD_t); - ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->type = 1; - ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->vrb_type = 1; - ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rballoc = computeRIV(eNB->frame_parms.N_RB_DL,0,9); - ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->TPC = TPC; - ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->harq_pid = 0; - ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->mcs = mcs1; - ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->ndi = 0; - ((DCI1A_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[k])->rv = 0; - break; - } - } - - memcpy(&dci_alloc[num_dci].dci_pdu[0],&DLSCH_alloc_pdu_1[k],dci_length_bytes); - dci_alloc[num_dci].dci_length = dci_length; - dci_alloc[num_dci].L = 1; - dci_alloc[num_dci].rnti = SI_RNTI; - dci_alloc[num_dci].format = format1A; - dci_alloc[num_dci].firstCCE = 0; - dci_alloc[num_dci].search_space = DCI_COMMON_SPACE; dump_dci(&eNB->frame_parms,&dci_alloc[num_dci]); - - printf("Generating dlsch params for user %d\n",k); - generate_eNB_dlsch_params_from_dci(0, - subframe, - &DLSCH_alloc_pdu_1[0], - SI_RNTI, - format1A, - eNB->dlsch[0], - &eNB->frame_parms, - eNB->pdsch_config_dedicated, - SI_RNTI, - 0, - P_RNTI, - eNB->UE_stats[0].DL_pmi_single, - 0); - - num_common_dci++; + num_ue_spec_dci++; num_dci++; + break; - } - - break; - - case 5: - case 6: - memcpy(&dci_alloc[num_dci].dci_pdu[0],&DLSCH_alloc_pdu2_1E[k],sizeof(DCI1E_5MHz_2A_M10PRB_TDD_t)); - dci_alloc[num_dci].dci_length = sizeof_DCI1E_5MHz_2A_M10PRB_TDD_t; - dci_alloc[num_dci].L = 1; - dci_alloc[num_dci].rnti = n_rnti+k; - dci_alloc[num_dci].format = format1E_2A_M10PRB; - dci_alloc[num_dci].firstCCE = 4*k; - dci_alloc[num_dci].search_space = DCI_UE_SPACE; - printf("Generating dlsch params for user %d\n",k); - generate_eNB_dlsch_params_from_dci(0, - subframe, - &DLSCH_alloc_pdu2_1E[k], - n_rnti+k, - format1E_2A_M10PRB, - eNB->dlsch[k], - &eNB->frame_parms, - eNB->pdsch_config_dedicated, - SI_RNTI, - 0, - P_RNTI, - eNB->UE_stats[k].DL_pmi_single, - 0); - - dump_dci(&eNB->frame_parms,&dci_alloc[num_dci]); - num_ue_spec_dci++; - num_dci++; - - break; - - default: - printf("Unsupported Transmission Mode!!!"); - exit(-1); - break; + default: + printf("Unsupported Transmission Mode!!!"); + exit(-1); + break; } - - - /* memcpy(&dci_alloc[1].dci_pdu[0],&UL_alloc_pdu,sizeof(DCI0_5MHz_TDD0_t)); dci_alloc[1].dci_length = sizeof_DCI0_5MHz_TDD_0_t; @@ -1966,13 +1883,12 @@ int main(int argc, char **argv) memset(CCE_table,0,800*sizeof(int)); for (i=num_common_dci; i<num_dci; i++) { - dci_alloc[i].firstCCE = get_nCCE_offset_l1(CCE_table, - 1<<dci_alloc[i].L, - numCCE, - (dci_alloc[i].rnti==SI_RNTI)? 1 : 0, - dci_alloc[i].rnti, - subframe); + 1<<dci_alloc[i].L, + numCCE, + (dci_alloc[i].rnti==SI_RNTI)? 1 : 0, + dci_alloc[i].rnti, + subframe); if (n_frames==1) printf("dci %d: rnti %x, format %d : nCCE %d/%d\n",i,dci_alloc[i].rnti, dci_alloc[i].format, @@ -1980,7 +1896,6 @@ int main(int argc, char **argv) } for (k=0; k<n_users; k++) { - input_buffer_length0 = eNB->dlsch[k][0]->harq_processes[0]->TBS/8; input_buffer0[k] = (unsigned char *)malloc(input_buffer_length0+4); memset(input_buffer0[k],0,input_buffer_length0+4); @@ -1997,13 +1912,11 @@ int main(int argc, char **argv) for (i=0; i<input_buffer_length1; i++) { input_buffer1[k][i]= (unsigned char)(taus()&0xff); } - } - - else { + } else { i=0; while ((!feof(input_trch_fd)) && (i<input_buffer_length0<<3)) { - ret=fscanf(input_trch_fd,"%s",input_trch_val); + ret=fscanf(input_trch_fd,"%15s",input_trch_val); if (input_trch_val[0] == '1') input_buffer0[k][i>>3]+=(1<<(7-(i&7))); @@ -2030,12 +1943,10 @@ int main(int argc, char **argv) eNB->dlsch[0][0]->harq_processes[0]->Nl, num_pdcch_symbols, 0, - subframe, - (transmission_mode<7?0:transmission_mode)); - - uncoded_ber_bit = (short*) malloc(sizeof(short)*coded_bits_per_codeword); + subframe, + (transmission_mode<7?0:transmission_mode)); + uncoded_ber_bit = (short *) malloc(sizeof(short)*coded_bits_per_codeword); printf("uncoded_ber_bit=%p\n",uncoded_ber_bit); - snr_step = input_snr_step; UE->high_speed_flag = 0; //1 UE->ch_est_alpha=0; @@ -2059,10 +1970,8 @@ int main(int argc, char **argv) round_trials[1] = 0; round_trials[2] = 0; round_trials[3] = 0; - dci_errors=0; // avg_ber = 0; - round=0; avg_iter = 0; iter_trials=0; @@ -2075,7 +1984,6 @@ int main(int argc, char **argv) reset_meas(&eNB->dlsch_interleaving_stats); reset_meas(&eNB->dlsch_rate_matching_stats); reset_meas(&eNB->dlsch_turbo_encoding_stats); - reset_meas(&UE->phy_proc_rx[UE->current_thread_id[subframe]]); // total UE rx reset_meas(&UE->ofdm_demod_stats); reset_meas(&UE->dlsch_channel_estimation_stats); @@ -2101,7 +2009,6 @@ int main(int argc, char **argv) initialize(&time_vector_tx_mod); struct list time_vector_tx_enc; initialize(&time_vector_tx_enc); - struct list time_vector_rx; initialize(&time_vector_rx); struct list time_vector_rx_fft; @@ -2115,14 +2022,12 @@ int main(int argc, char **argv) // printf("Trial %d\n",trials); fflush(stdout); round=0; - //if (trials%100==0) eNB2UE[0]->first_run = 1; - ret = UE->dlsch[UE->current_thread_id[subframe]][0][0]->max_turbo_iterations+1; while ((round < num_rounds) && (ret > UE->dlsch[UE->current_thread_id[subframe]][0][0]->max_turbo_iterations)) { - //printf("Trial %d, round %d\n",trials,round); + //printf("Trial %d, round %d\n",trials,round); round_trials[round]++; if(transmission_mode>=5&&transmission_mode<7) @@ -2140,31 +2045,30 @@ int main(int argc, char **argv) PMI_FEEDBACK: - //make sure dlsim is called with perfect channel estimation option (for freq_channel) - //fill drs_ch_estimates with data from eNB2UE->chF - for(aa=0; aa<frame_parms->nb_antenna_ports_eNB; aa++) { - for (aarx=0; aarx<frame_parms->nb_antennas_rx; aarx++) { - for (i=0; i<frame_parms->N_RB_DL*12; i++) { - for (l=0; l<frame_parms->symbols_per_tti; l++) { - ((int16_t *) eNB->pusch_vars[0]->drs_ch_estimates[0][(aa<<1)+aarx])[2*i+(l*frame_parms->ofdm_symbol_size)*2]=(int16_t)(eNB2UE[round]->chF[aarx+(aa*frame_parms->nb_antennas_rx)][i].x*AMP); - //printf("x=%d,AMP=%d\n",eNB2UE[round]->chF[aarx+(aa*frame_parms->nb_antennas_rx)][i].x,AMP); - ((int16_t *) eNB->pusch_vars[0]->drs_ch_estimates[0][(aa<<1)+aarx])[2*i+1+(l*frame_parms->ofdm_symbol_size)*2]=(int16_t)(eNB2UE[round]->chF[aarx+(aa*frame_parms->nb_antennas_rx)][i].y*AMP); - } - } - } - } - - estimate_DLCSI_from_ULCSI(eNB->dlsch[0][0]->calib_dl_ch_estimates, - &eNB->pusch_vars[0]->drs_ch_estimates[0][0/*position of second DMRS*/], - eNB->common_vars.tdd_calib_coeffs[0], - frame_parms->nb_antennas_tx, - frame_parms->N_RB_DL*12); - - compute_BF_weights(eNB->dlsch[0][0]->ue_spec_bf_weights[0], - eNB->dlsch[0][0]->calib_dl_ch_estimates, - MRT, - frame_parms->nb_antennas_tx, - frame_parms->N_RB_DL*12); + //make sure dlsim is called with perfect channel estimation option (for freq_channel) + //fill drs_ch_estimates with data from eNB2UE->chF + for(aa=0; aa<frame_parms->nb_antenna_ports_eNB; aa++) { + for (aarx=0; aarx<frame_parms->nb_antennas_rx; aarx++) { + for (i=0; i<frame_parms->N_RB_DL*12; i++) { + for (l=0; l<frame_parms->symbols_per_tti; l++) { + ((int16_t *) eNB->pusch_vars[0]->drs_ch_estimates[0][(aa<<1)+aarx])[2*i+(l*frame_parms->ofdm_symbol_size)*2]=(int16_t)(eNB2UE[round]->chF[aarx+(aa*frame_parms->nb_antennas_rx)][i].x*AMP); + //printf("x=%d,AMP=%d\n",eNB2UE[round]->chF[aarx+(aa*frame_parms->nb_antennas_rx)][i].x,AMP); + ((int16_t *) eNB->pusch_vars[0]->drs_ch_estimates[0][(aa<<1)+aarx])[2*i+1+(l*frame_parms->ofdm_symbol_size)*2]=(int16_t)(eNB2UE[round]->chF[aarx+(aa*frame_parms->nb_antennas_rx)][i].y*AMP); + } + } + } + } + + estimate_DLCSI_from_ULCSI(eNB->dlsch[0][0]->calib_dl_ch_estimates, + &eNB->pusch_vars[0]->drs_ch_estimates[0][0/*position of second DMRS*/], + eNB->common_vars.tdd_calib_coeffs[0], + frame_parms->nb_antennas_tx, + frame_parms->N_RB_DL*12); + compute_BF_weights(eNB->dlsch[0][0]->ue_spec_bf_weights[0], + eNB->dlsch[0][0]->calib_dl_ch_estimates, + MRT, + frame_parms->nb_antennas_tx, + frame_parms->N_RB_DL*12); //printf("Trial %d : Round %d, pmi_feedback %d \n",trials,round,pmi_feedback); for (aa=0; aa<NB_ANTENNA_PORTS_ENB; aa++) { @@ -2172,397 +2076,390 @@ PMI_FEEDBACK: } if (input_fd==NULL) { - start_meas(&eNB->phy_proc_tx); // Simulate HARQ procedures!!! if (common_flag == 0) { - if (round == 0) { // First round TB0_active = 1; - eNB->dlsch[0][0]->harq_processes[0]->rvidx = round&3; if (eNB->frame_parms.frame_type == TDD) { - switch (transmission_mode) { - case 1: - case 2: - case 7: - switch (eNB->frame_parms.N_RB_DL) { - case 6: - ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi = trials&1; - ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv = 0; - memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI1_1_5MHz_TDD_t)); - break; - - case 25: - ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi = trials&1; - ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv = 0; - memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI1_5MHz_TDD_t)); - break; - - case 50: - ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi = trials&1; - ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv = 0; - memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI1_10MHz_TDD_t)); - break; - - case 100: - ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi = trials&1; - ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv = 0; - memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI1_20MHz_TDD_t)); - break; - } - - break; + case 1: + case 2: + case 7: + switch (eNB->frame_parms.N_RB_DL) { + case 6: + ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi = trials&1; + ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv = 0; + memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI1_1_5MHz_TDD_t)); + break; + + case 25: + ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi = trials&1; + ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv = 0; + memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI1_5MHz_TDD_t)); + break; + + case 50: + ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi = trials&1; + ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv = 0; + memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI1_10MHz_TDD_t)); + break; + + case 100: + ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi = trials&1; + ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv = 0; + memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI1_20MHz_TDD_t)); + break; + } - case 3: - switch (eNB->frame_parms.N_RB_DL) { - case 6: - ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi1 = trials&1; - ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv1 = 0; - ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2 = trials&1; - ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv2 = 0; - memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI2A_1_5MHz_2A_TDD_t)); break; - case 25: - ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi1 = trials&1; - ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv1 = 0; - ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2 = trials&1; - ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv2 = 0; - memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI2A_5MHz_2A_TDD_t)); - break; + case 3: + switch (eNB->frame_parms.N_RB_DL) { + case 6: + ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi1 = trials&1; + ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv1 = 0; + ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2 = trials&1; + ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv2 = 0; + memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI2A_1_5MHz_2A_TDD_t)); + break; + + case 25: + ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi1 = trials&1; + ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv1 = 0; + ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2 = trials&1; + ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv2 = 0; + memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI2A_5MHz_2A_TDD_t)); + break; + + case 50: + ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi1 = trials&1; + ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv1 = 0; + ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2 = trials&1; + ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv2 = 0; + memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI2A_10MHz_2A_TDD_t)); + break; + + case 100: + ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi1 = trials&1; + ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv1 = 0; + ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2 = trials&1; + ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv2 = 0; + memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI2A_20MHz_2A_TDD_t)); + break; + } - case 50: - ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi1 = trials&1; - ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv1 = 0; - ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2 = trials&1; - ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv2 = 0; - memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI2A_10MHz_2A_TDD_t)); break; - case 100: - ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi1 = trials&1; - ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv1 = 0; - ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2 = trials&1; - ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv2 = 0; - memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI2A_20MHz_2A_TDD_t)); + case 5: + DLSCH_alloc_pdu2_1E[0].ndi = trials&1; + DLSCH_alloc_pdu2_1E[0].rv = 0; + memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu2_1E[0],sizeof(DCI1E_5MHz_2A_M10PRB_TDD_t)); break; - } - - break; - - case 5: - DLSCH_alloc_pdu2_1E[0].ndi = trials&1; - DLSCH_alloc_pdu2_1E[0].rv = 0; - memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu2_1E[0],sizeof(DCI1E_5MHz_2A_M10PRB_TDD_t)); - break; - } } else { // FDD switch (transmission_mode) { - case 1: - case 2: - case 7: - switch (eNB->frame_parms.N_RB_DL) { - case 6: - ((DCI1_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi = trials&1; - ((DCI1_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv = 0; - memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI1_1_5MHz_FDD_t)); - break; - - case 25: - ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi = trials&1; - ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv = 0; - memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI1_5MHz_FDD_t)); - break; - - case 50: - ((DCI1_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi = trials&1; - ((DCI1_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv = 0; - memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI1_10MHz_FDD_t)); - break; - - case 100: - ((DCI1_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi = trials&1; - ((DCI1_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv = 0; - memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI1_20MHz_FDD_t)); - break; - } + case 1: + case 2: + case 7: + switch (eNB->frame_parms.N_RB_DL) { + case 6: + ((DCI1_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi = trials&1; + ((DCI1_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv = 0; + memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI1_1_5MHz_FDD_t)); + break; + + case 25: + ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi = trials&1; + ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv = 0; + memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI1_5MHz_FDD_t)); + break; + + case 50: + ((DCI1_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi = trials&1; + ((DCI1_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv = 0; + memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI1_10MHz_FDD_t)); + break; + + case 100: + ((DCI1_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi = trials&1; + ((DCI1_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv = 0; + memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI1_20MHz_FDD_t)); + break; + } - break; - case 3: - switch (eNB->frame_parms.N_RB_DL) { - case 6: - ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi1 = trials&1; - ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv1 = 0; - ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2 = trials&1; - ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv2 = 0; - memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI2A_1_5MHz_2A_FDD_t)); break; - case 25: - ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi1 = trials&1; - ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv1 = 0; - ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2 = trials&1; - ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv2 = 0; - memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI2A_5MHz_2A_FDD_t)); - break; + case 3: + switch (eNB->frame_parms.N_RB_DL) { + case 6: + ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi1 = trials&1; + ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv1 = 0; + ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2 = trials&1; + ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv2 = 0; + memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI2A_1_5MHz_2A_FDD_t)); + break; + + case 25: + ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi1 = trials&1; + ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv1 = 0; + ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2 = trials&1; + ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv2 = 0; + memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI2A_5MHz_2A_FDD_t)); + break; + + case 50: + ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi1 = trials&1; + ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv1 = 0; + ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2 = trials&1; + ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv2 = 0; + memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI2A_10MHz_2A_FDD_t)); + break; + + case 100: + ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi1 = trials&1; + ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv1 = 0; + ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2 = trials&1; + ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv2 = 0; + memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI2A_20MHz_2A_FDD_t)); + break; + } - case 50: - ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi1 = trials&1; - ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv1 = 0; - ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2 = trials&1; - ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv2 = 0; - memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI2A_10MHz_2A_FDD_t)); break; - case 100: - ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi1 = trials&1; - ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv1 = 0; - ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2 = trials&1; - ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv2 = 0; - memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI2A_20MHz_2A_FDD_t)); + case 5: + DLSCH_alloc_pdu2_1E[0].ndi = trials&1; + DLSCH_alloc_pdu2_1E[0].rv = 0; + memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu2_1E[0],sizeof(DCI1E_5MHz_2A_M10PRB_TDD_t)); break; - } - - break; - - case 5: - DLSCH_alloc_pdu2_1E[0].ndi = trials&1; - DLSCH_alloc_pdu2_1E[0].rv = 0; - memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu2_1E[0],sizeof(DCI1E_5MHz_2A_M10PRB_TDD_t)); - break; } - } } else { eNB->dlsch[0][0]->harq_processes[0]->rvidx = round&3; if (eNB->frame_parms.frame_type == TDD) { - - switch (transmission_mode) { - case 1: - case 2: - case 7: - switch (eNB->frame_parms.N_RB_DL) { - case 6: - ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi = trials&1; - ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv = round&3;; - memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI1_1_5MHz_TDD_t)); - break; - - case 25: - ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi = trials&1; - ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv = round&3; - memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI1_5MHz_TDD_t)); - break; - - case 50: - ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi = trials&1; - ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv = round&3; - memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI1_10MHz_TDD_t)); - break; - - case 100: - ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi = trials&1; - ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv = round&3; - memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI1_20MHz_TDD_t)); - break; - } - - break; - - case 3: - switch (eNB->frame_parms.N_RB_DL) { - case 6: - if (TB0_active==1) { - ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi1 = trials&1; - ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv1 = round&3; - ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2 = trials&1; - ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv2 = round&3; - } else { // deactivate TB0 - ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->mcs1 = 0; - ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv1 = 1; - ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2 = trials&1; - ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv2 = round&3; + case 1: + case 2: + case 7: + switch (eNB->frame_parms.N_RB_DL) { + case 6: + ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi = trials&1; + ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv = round&3;; + memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI1_1_5MHz_TDD_t)); + break; + + case 25: + ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi = trials&1; + ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv = round&3; + memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI1_5MHz_TDD_t)); + break; + + case 50: + ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi = trials&1; + ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv = round&3; + memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI1_10MHz_TDD_t)); + break; + + case 100: + ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi = trials&1; + ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv = round&3; + memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI1_20MHz_TDD_t)); + break; } - memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI2A_1_5MHz_2A_TDD_t)); break; - case 25: - if (TB0_active==1) { - ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi1 = trials&1; - ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv1 = round&3; - ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2 = trials&1; - ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv2 = round&3; - } else { // deactivate TB0 - ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->mcs1 = 0; - ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv1 = 1; - ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2 = trials&1; - ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv2 = round&3; - } + case 3: + switch (eNB->frame_parms.N_RB_DL) { + case 6: + if (TB0_active==1) { + ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi1 = trials&1; + ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv1 = round&3; + ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2 = trials&1; + ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv2 = round&3; + } else { // deactivate TB0 + ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->mcs1 = 0; + ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv1 = 1; + ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2 = trials&1; + ((DCI2A_1_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv2 = round&3; + } - memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI2A_5MHz_2A_TDD_t)); - break; + memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI2A_1_5MHz_2A_TDD_t)); + break; + + case 25: + if (TB0_active==1) { + ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi1 = trials&1; + ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv1 = round&3; + ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2 = trials&1; + ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv2 = round&3; + } else { // deactivate TB0 + ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->mcs1 = 0; + ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv1 = 1; + ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2 = trials&1; + ((DCI2A_5MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv2 = round&3; + } - case 50: - if (TB0_active==1) { - ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi1 = trials&1; - ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv1 = round&3; - ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2 = trials&1; - ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv2 = round&3; - } else { // deactivate TB0 - ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->mcs1 = 0; - ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv1 = 1; - ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2 = trials&1; - ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv2 = round&3; - } + memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI2A_5MHz_2A_TDD_t)); + break; + + case 50: + if (TB0_active==1) { + ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi1 = trials&1; + ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv1 = round&3; + ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2 = trials&1; + ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv2 = round&3; + } else { // deactivate TB0 + ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->mcs1 = 0; + ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv1 = 1; + ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2 = trials&1; + ((DCI2A_10MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv2 = round&3; + } - memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI2A_10MHz_2A_TDD_t)); - break; + memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI2A_10MHz_2A_TDD_t)); + break; + + case 100: + if (TB0_active==1) { + ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi1 = trials&1; + ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv1 = round&3; + ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2 = trials&1; + ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv2 = round&3; + } else { // deactivate TB0 + ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->mcs1 = 0; + ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv1 = 1; + ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2 = trials&1; + ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv2 = round&3; + } - case 100: - if (TB0_active==1) { - ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi1 = trials&1; - ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv1 = round&3; - ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2 = trials&1; - ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv2 = round&3; - } else { // deactivate TB0 - ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->mcs1 = 0; - ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv1 = 1; - ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2 = trials&1; - ((DCI2A_20MHz_2A_TDD_t *)&DLSCH_alloc_pdu_1[0])->rv2 = round&3; + memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI2A_20MHz_2A_TDD_t)); + break; } - memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI2A_20MHz_2A_TDD_t)); break; - } - - break; - case 5: - DLSCH_alloc_pdu2_1E[0].ndi = trials&1; - DLSCH_alloc_pdu2_1E[0].rv = round&3; - memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu2_1E[0],sizeof(DCI1E_5MHz_2A_M10PRB_TDD_t)); - break; + case 5: + DLSCH_alloc_pdu2_1E[0].ndi = trials&1; + DLSCH_alloc_pdu2_1E[0].rv = round&3; + memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu2_1E[0],sizeof(DCI1E_5MHz_2A_M10PRB_TDD_t)); + break; } } else { switch (transmission_mode) { - case 1: - case 2: - case 7: - switch (eNB->frame_parms.N_RB_DL) { - case 6: - ((DCI1_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi = trials&1; - ((DCI1_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv = round&3;; - memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI1_1_5MHz_FDD_t)); - break; - - case 25: - ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi = trials&1; - ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv = round&3; - memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI1_5MHz_FDD_t)); - break; - - case 50: - ((DCI1_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi = trials&1; - ((DCI1_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv = round&3; - memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI1_10MHz_FDD_t)); - break; - - case 100: - ((DCI1_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi = trials&1; - ((DCI1_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv = round&3; - memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI1_20MHz_FDD_t)); - break; - } - - break; - - case 3: - switch (eNB->frame_parms.N_RB_DL) { - case 6: - if (TB0_active==1) { - ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi1 = trials&1; - ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv1 = round&3; - ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2 = trials&1; - ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv2 = round&3; - } else { // deactivate TB0 - ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->mcs1 = 0; - ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv1 = 1; - ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2 = trials&1; - ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv2 = round&3; + case 1: + case 2: + case 7: + switch (eNB->frame_parms.N_RB_DL) { + case 6: + ((DCI1_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi = trials&1; + ((DCI1_1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv = round&3;; + memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI1_1_5MHz_FDD_t)); + break; + + case 25: + ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi = trials&1; + ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv = round&3; + memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI1_5MHz_FDD_t)); + break; + + case 50: + ((DCI1_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi = trials&1; + ((DCI1_10MHz_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv = round&3; + memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI1_10MHz_FDD_t)); + break; + + case 100: + ((DCI1_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi = trials&1; + ((DCI1_20MHz_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv = round&3; + memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI1_20MHz_FDD_t)); + break; } - memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI2A_1_5MHz_2A_FDD_t)); break; - case 25: - if (TB0_active==1) { - ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi1 = trials&1; - ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv1 = round&3; - ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2 = trials&1; - ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv2 = round&3; - } else { // deactivate TB0 - ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->mcs1 = 0; - ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv1 = 1; - ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2 = trials&1; - ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv2 = round&3; - } + case 3: + switch (eNB->frame_parms.N_RB_DL) { + case 6: + if (TB0_active==1) { + ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi1 = trials&1; + ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv1 = round&3; + ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2 = trials&1; + ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv2 = round&3; + } else { // deactivate TB0 + ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->mcs1 = 0; + ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv1 = 1; + ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2 = trials&1; + ((DCI2A_1_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv2 = round&3; + } - memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI2A_5MHz_2A_FDD_t)); - break; + memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI2A_1_5MHz_2A_FDD_t)); + break; + + case 25: + if (TB0_active==1) { + ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi1 = trials&1; + ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv1 = round&3; + ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2 = trials&1; + ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv2 = round&3; + } else { // deactivate TB0 + ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->mcs1 = 0; + ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv1 = 1; + ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2 = trials&1; + ((DCI2A_5MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv2 = round&3; + } - case 50: - if (TB0_active==1) { - ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi1 = trials&1; - ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv1 = round&3; - ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2 = trials&1; - ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv2 = round&3; - } else { // deactivate TB0 - ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->mcs1 = 0; - ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv1 = 1; - ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2 = trials&1; - ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv2 = round&3; - } + memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI2A_5MHz_2A_FDD_t)); + break; + + case 50: + if (TB0_active==1) { + ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi1 = trials&1; + ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv1 = round&3; + ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2 = trials&1; + ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv2 = round&3; + } else { // deactivate TB0 + ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->mcs1 = 0; + ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv1 = 1; + ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2 = trials&1; + ((DCI2A_10MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv2 = round&3; + } - memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI2A_10MHz_2A_FDD_t)); - break; + memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI2A_10MHz_2A_FDD_t)); + break; + + case 100: + if (TB0_active==1) { + ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi1 = trials&1; + ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv1 = round&3; + ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2 = trials&1; + ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv2 = round&3; + } else { // deactivate TB0 + ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->mcs1 = 0; + ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv1 = 1; + ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2 = trials&1; + ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv2 = round&3; + } - case 100: - if (TB0_active==1) { - ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi1 = trials&1; - ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv1 = round&3; - ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2 = trials&1; - ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv2 = round&3; - } else { // deactivate TB0 - ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->mcs1 = 0; - ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv1 = 1; - ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->ndi2 = trials&1; - ((DCI2A_20MHz_2A_FDD_t *)&DLSCH_alloc_pdu_1[0])->rv2 = round&3; + memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI2A_20MHz_2A_FDD_t)); + break; } - memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu_1[0],sizeof(DCI2A_20MHz_2A_FDD_t)); break; - } - - break; - case 5: - DLSCH_alloc_pdu2_1E[0].ndi = trials&1; - DLSCH_alloc_pdu2_1E[0].rv = round&3; - memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu2_1E[0],sizeof(DCI1E_5MHz_2A_M10PRB_TDD_t)); - break; + case 5: + DLSCH_alloc_pdu2_1E[0].ndi = trials&1; + DLSCH_alloc_pdu2_1E[0].rv = round&3; + memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu2_1E[0],sizeof(DCI1E_5MHz_2A_M10PRB_TDD_t)); + break; } } } } - + num_pdcch_symbols_2 = generate_dci_top(num_ue_spec_dci + num_common_dci, dci_alloc, 0, @@ -2570,7 +2467,7 @@ PMI_FEEDBACK: &eNB->frame_parms, eNB->common_vars.txdataF[eNB_id], subframe); - + if (num_pdcch_symbols_2 > num_pdcch_symbols) { msg("Error: given num_pdcch_symbols not big enough (%d > %d)\n",num_pdcch_symbols_2,num_pdcch_symbols); exit(-1); @@ -2585,9 +2482,8 @@ PMI_FEEDBACK: eNB->dlsch[k][cw]->harq_processes[0]->Nl, num_pdcch_symbols, 0, - subframe, - (transmission_mode<7?0:transmission_mode)); - + subframe, + (transmission_mode<7?0:transmission_mode)); #ifdef TBS_FIX // This is for MESH operation!!! tbs = (double)3*TBStable[get_I_TBS(eNB->dlsch[k][cw]->harq_processes[0]->mcs)][eNB->dlsch[k][cw]->nb_rb-1]/4; #else @@ -2596,7 +2492,7 @@ PMI_FEEDBACK: rate = (double)tbs/(double)coded_bits_per_codeword; if ((SNR==snr0) && (trials==0) && (round==0)) - printf("User %d, cw %d: Rate = %f (%f bits/dim) (G %d, TBS %d, mod %d, pdcch_sym %d, ndi %d)\n", + printf("User %d, cw %d: Rate = %f (%f bits/dim) (G %u, TBS %u, mod %d, pdcch_sym %d, ndi %d)\n", k,cw,rate,rate*get_Qm(eNB->dlsch[k][0]->harq_processes[0]->mcs), coded_bits_per_codeword, tbs, @@ -2621,11 +2517,10 @@ PMI_FEEDBACK: */ } - start_meas(&eNB->dlsch_encoding_stats); if (dlsch_encoding(eNB, - ((cw==0) ? input_buffer0[k] : input_buffer1[k]), + ((cw==0) ? input_buffer0[k] : input_buffer1[k]), num_pdcch_symbols, eNB->dlsch[k][cw], 0,subframe, @@ -2649,7 +2544,6 @@ PMI_FEEDBACK: } */ stop_meas(&eNB->dlsch_encoding_stats); - eNB->dlsch[k][cw]->rnti = (common_flag==0) ? n_rnti+k : SI_RNTI; start_meas(&eNB->dlsch_scrambling_stats); dlsch_scrambling(&eNB->frame_parms, @@ -2674,19 +2568,18 @@ PMI_FEEDBACK: } } } - + start_meas(&eNB->dlsch_modulation_stats); re_allocated = dlsch_modulation(eNB, - eNB->common_vars.txdataF[eNB_id], + eNB->common_vars.txdataF[eNB_id], AMP, frame, subframe, num_pdcch_symbols, eNB->dlsch[k][0], - eNB->dlsch[k][1]); + eNB->dlsch[k][1]); /* avoid gcc warnings */ (void)re_allocated; - stop_meas(&eNB->dlsch_modulation_stats); /* if (trials==0 && round==0) @@ -2694,174 +2587,172 @@ PMI_FEEDBACK: */ } //n_users - generate_pilots(eNB, eNB->common_vars.txdataF[eNB_id], AMP, LTE_NUMBER_OF_SUBFRAMES_PER_FRAME); -/* - //PSS/SSS - if (eNB->frame_parms.frame_type == FDD) { - generate_pss(eNB->common_vars.txdataF[0], - AMP, - &eNB->frame_parms, - (eNB->frame_parms.Ncp==NORMAL) ? 6 : 5, - 0); - generate_sss(eNB->common_vars.txdataF[0], - AMP, - &eNB->frame_parms, - (eNB->frame_parms.Ncp==NORMAL) ? 5 : 4, - 0); - generate_pss(eNB->common_vars.txdataF[0], - AMP, - &eNB->frame_parms, - (eNB->frame_parms.Ncp==NORMAL) ? 6 : 5, - 10); - generate_sss(eNB->common_vars.txdataF[0], - AMP, - &eNB->frame_parms, - (eNB->frame_parms.Ncp==NORMAL) ? 5 : 4, - 10); - } - else if (eNB->frame_parms.frame_type == TDD) { - generate_sss(eNB->common_vars.txdataF[0], - AMP, - &eNB->frame_parms, - (eNB->frame_parms.Ncp==NORMAL) ? 6 : 5, - 1); - generate_pss(eNB->common_vars.txdataF[0], - AMP, - &eNB->frame_parms, - 2, - 2); - generate_sss(eNB->common_vars.txdataF[0], - AMP, - &eNB->frame_parms, - (eNB->frame_parms.Ncp==NORMAL) ? 6 : 5, - 11); - generate_pss(eNB->common_vars.txdataF[0], - AMP, - &eNB->frame_parms, - 2, - 12); - } + /* + //PSS/SSS + if (eNB->frame_parms.frame_type == FDD) { + generate_pss(eNB->common_vars.txdataF[0], + AMP, + &eNB->frame_parms, + (eNB->frame_parms.Ncp==NORMAL) ? 6 : 5, + 0); + generate_sss(eNB->common_vars.txdataF[0], + AMP, + &eNB->frame_parms, + (eNB->frame_parms.Ncp==NORMAL) ? 5 : 4, + 0); + generate_pss(eNB->common_vars.txdataF[0], + AMP, + &eNB->frame_parms, + (eNB->frame_parms.Ncp==NORMAL) ? 6 : 5, + 10); + generate_sss(eNB->common_vars.txdataF[0], + AMP, + &eNB->frame_parms, + (eNB->frame_parms.Ncp==NORMAL) ? 5 : 4, + 10); + } + else if (eNB->frame_parms.frame_type == TDD) { + generate_sss(eNB->common_vars.txdataF[0], + AMP, + &eNB->frame_parms, + (eNB->frame_parms.Ncp==NORMAL) ? 6 : 5, + 1); + generate_pss(eNB->common_vars.txdataF[0], + AMP, + &eNB->frame_parms, + 2, + 2); + generate_sss(eNB->common_vars.txdataF[0], + AMP, + &eNB->frame_parms, + (eNB->frame_parms.Ncp==NORMAL) ? 6 : 5, + 11); + generate_pss(eNB->common_vars.txdataF[0], + AMP, + &eNB->frame_parms, + 2, + 12); + } - //PBCH - pbch_pdu[2] = 0; + //PBCH + pbch_pdu[2] = 0; - // FIXME setting pbch_pdu[2] to zero makes the switch statement easier: remove all the or-operators - switch (eNB->frame_parms.N_RB_DL) { - case 6: - pbch_pdu[2] = (pbch_pdu[2]&0x1f) | (0<<5); - break; - - case 15: - pbch_pdu[2] = (pbch_pdu[2]&0x1f) | (1<<5); - break; - - case 25: - pbch_pdu[2] = (pbch_pdu[2]&0x1f) | (2<<5); - break; - - case 50: - pbch_pdu[2] = (pbch_pdu[2]&0x1f) | (3<<5); - break; - - case 75: - pbch_pdu[2] = (pbch_pdu[2]&0x1f) | (4<<5); - break; - - case 100: - pbch_pdu[2] = (pbch_pdu[2]&0x1f) | (5<<5); - break; - - default: - // FIXME if we get here, this should be flagged as an error, right? - pbch_pdu[2] = (pbch_pdu[2]&0x1f) | (2<<5); - break; - } + // FIXME setting pbch_pdu[2] to zero makes the switch statement easier: remove all the or-operators + switch (eNB->frame_parms.N_RB_DL) { + case 6: + pbch_pdu[2] = (pbch_pdu[2]&0x1f) | (0<<5); + break; + + case 15: + pbch_pdu[2] = (pbch_pdu[2]&0x1f) | (1<<5); + break; - pbch_pdu[2] = (pbch_pdu[2]&0xef) | - ((eNB->frame_parms.phich_config_common.phich_duration << 4)&0x10); + case 25: + pbch_pdu[2] = (pbch_pdu[2]&0x1f) | (2<<5); + break; - switch (eNB->frame_parms.phich_config_common.phich_resource) { - case oneSixth: - pbch_pdu[2] = (pbch_pdu[2]&0xf3) | (0<<2); - break; + case 50: + pbch_pdu[2] = (pbch_pdu[2]&0x1f) | (3<<5); + break; - case half: - pbch_pdu[2] = (pbch_pdu[2]&0xf3) | (1<<2); - break; + case 75: + pbch_pdu[2] = (pbch_pdu[2]&0x1f) | (4<<5); + break; - case one: - pbch_pdu[2] = (pbch_pdu[2]&0xf3) | (2<<2); - break; + case 100: + pbch_pdu[2] = (pbch_pdu[2]&0x1f) | (5<<5); + break; - case two: - pbch_pdu[2] = (pbch_pdu[2]&0xf3) | (3<<2); - break; + default: + // FIXME if we get here, this should be flagged as an error, right? + pbch_pdu[2] = (pbch_pdu[2]&0x1f) | (2<<5); + break; + } - default: - // unreachable - break; - + pbch_pdu[2] = (pbch_pdu[2]&0xef) | + ((eNB->frame_parms.phich_config_common.phich_duration << 4)&0x10); - pbch_pdu[2] = (pbch_pdu[2]&0xfc) | ((0>>8)&0x3); - pbch_pdu[1] = 0&0xfc; - pbch_pdu[0] = 0; - } + switch (eNB->frame_parms.phich_config_common.phich_resource) { + case oneSixth: + pbch_pdu[2] = (pbch_pdu[2]&0xf3) | (0<<2); + break; - generate_pbch(&eNB->lte_eNB_pbch, - eNB->common_vars.txdataF[0], - AMP, - &eNB->frame_parms, - pbch_pdu, - 0&3); -*/ + case half: + pbch_pdu[2] = (pbch_pdu[2]&0xf3) | (1<<2); + break; + + case one: + pbch_pdu[2] = (pbch_pdu[2]&0xf3) | (2<<2); + break; + + case two: + pbch_pdu[2] = (pbch_pdu[2]&0xf3) | (3<<2); + break; + + default: + // unreachable + break; + + + pbch_pdu[2] = (pbch_pdu[2]&0xfc) | ((0>>8)&0x3); + pbch_pdu[1] = 0&0xfc; + pbch_pdu[0] = 0; + } + generate_pbch(&eNB->lte_eNB_pbch, + eNB->common_vars.txdataF[0], + AMP, + &eNB->frame_parms, + pbch_pdu, + 0&3); + */ start_meas(&eNB->ofdm_mod_stats); -/* - for(i=0;i<20;i++){ - - do_OFDM_mod_l(eNB->common_vars.txdataF[eNB_id], - eNB->common_vars.txdata[eNB_id], - i, - &eNB->frame_parms); - } + /* + for(i=0;i<20;i++){ -*/ - do_OFDM_mod_symbol(&eNB->common_vars, - eNB_id, - (subframe*2), - &eNB->frame_parms); + do_OFDM_mod_l(eNB->common_vars.txdataF[eNB_id], + eNB->common_vars.txdata[eNB_id], + i, + &eNB->frame_parms); + } + */ do_OFDM_mod_symbol(&eNB->common_vars, - eNB_id, - (subframe*2)+1, - &eNB->frame_parms); - + eNB_id, + (subframe*2), + &eNB->frame_parms); + do_OFDM_mod_symbol(&eNB->common_vars, + eNB_id, + (subframe*2)+1, + &eNB->frame_parms); stop_meas(&eNB->ofdm_mod_stats); stop_meas(&eNB->phy_proc_tx); - /* do_OFDM_mod_l(&eNB->common_vars, - eNB_id, - (subframe*2)+2, - &eNB->frame_parms); */ + /* do_OFDM_mod_l(&eNB->common_vars, + eNB_id, + (subframe*2)+2, + &eNB->frame_parms); */ if (n_frames==1) { if (transmission_mode<7) LOG_M("txsigF0.m","txsF0", &eNB->common_vars.txdataF[eNB_id][0][subframe*nsymb*eNB->frame_parms.ofdm_symbol_size], - nsymb*eNB->frame_parms.ofdm_symbol_size,1,1); + nsymb*eNB->frame_parms.ofdm_symbol_size,1,1); else if (transmission_mode==7) LOG_M("txsigF0.m","txsF0", &eNB->common_vars.txdataF[eNB_id][5][subframe*nsymb*eNB->frame_parms.ofdm_symbol_size], - nsymb*eNB->frame_parms.ofdm_symbol_size,1,1); + nsymb*eNB->frame_parms.ofdm_symbol_size,1,1); + LOG_M("txsigF0_BF.m","txsF0_BF", &eNB->common_vars.txdataF_BF[eNB_id][0][0], - eNB->frame_parms.ofdm_symbol_size,1,1); + eNB->frame_parms.ofdm_symbol_size,1,1); if (eNB->frame_parms.nb_antennas_tx>1)// to be updated LOG_M("txsigF1.m","txsF1", &eNB->common_vars.txdataF[eNB_id][1][subframe*nsymb*eNB->frame_parms.ofdm_symbol_size], - nsymb*eNB->frame_parms.ofdm_symbol_size,1,1); + nsymb*eNB->frame_parms.ofdm_symbol_size,1,1); } + tx_lev = 0; for (aa=0; aa<eNB->frame_parms.nb_antennas_tx; aa++) { @@ -2873,7 +2764,7 @@ PMI_FEEDBACK: tx_lev_dB = (unsigned int) dB_fixed(tx_lev); if (n_frames==1) { - printf("tx_lev = %d (%d dB)\n",tx_lev,tx_lev_dB); + printf("tx_lev = %u (%u dB)\n",tx_lev,tx_lev_dB); LOG_M("txsig0.m","txs0", &eNB->common_vars.txdata[eNB_id][0][subframe*eNB->frame_parms.samples_per_tti],eNB->frame_parms.samples_per_tti,1,1); // LOG_M("txsig0.m","txs0",&eNB->common_vars.txdata[eNB_id][0][0*eNB->frame_parms.samples_per_tti],eNB->frame_parms.samples_per_tti*10,1,1); } @@ -2920,7 +2811,6 @@ PMI_FEEDBACK: r_re[aarx][i] += (double)(((short *)eNB->common_vars.txdata[eNB_id][aa]))[(2*subframe*UE->frame_parms.samples_per_tti) +(i<<1)]; r_im[aarx][i] += (double)(((short *)eNB->common_vars.txdata[eNB_id][aa]))[(2*subframe*UE->frame_parms.samples_per_tti) +(i<<1)+1]; } - } } } @@ -2938,16 +2828,16 @@ PMI_FEEDBACK: random_channel(eNB2UE[2],0); random_channel(eNB2UE[3],0); } - - if (UE->perfect_ce==1) { - // fill in perfect channel estimates - freq_channel(eNB2UE[round],UE->frame_parms.N_RB_DL,12*UE->frame_parms.N_RB_DL + 1); - /* - LOG_M("channel.m","ch",eNB2UE[round]->ch[0],eNB2UE[round]->channel_length,1,8); - LOG_M("channelF.m","chF",eNB2UE[round]->chF[0],12*UE->frame_parms.N_RB_DL + 1,1,8); - */ - } - } + + if (UE->perfect_ce==1) { + // fill in perfect channel estimates + freq_channel(eNB2UE[round],UE->frame_parms.N_RB_DL,12*UE->frame_parms.N_RB_DL + 1); + /* + LOG_M("channel.m","ch",eNB2UE[round]->ch[0],eNB2UE[round]->channel_length,1,8); + LOG_M("channelF.m","chF",eNB2UE[round]->chF[0],12*UE->frame_parms.N_RB_DL + 1,1,8); + */ + } + } if(abstx) { if (trials==0 && round==0) { @@ -3017,17 +2907,16 @@ PMI_FEEDBACK: for (i=0; i<2*frame_parms->samples_per_tti; i++) { for (aa=0; aa<eNB->frame_parms.nb_antennas_rx; aa++) { // printf("s_re[0][%d]=> %f , r_re[0][%d]=> %f\n",i,s_re[aa][i],i,r_re[aa][i]); - ((short*) UE->common_vars.rxdata[aa])[(2*subframe*UE->frame_parms.samples_per_tti)+2*i] = + ((short *) UE->common_vars.rxdata[aa])[(2*subframe*UE->frame_parms.samples_per_tti)+2*i] = (short) (r_re[aa][i] + sqrt(sigma2/2)*gaussdouble(0.0,1.0)); - ((short*) UE->common_vars.rxdata[aa])[(2*subframe*UE->frame_parms.samples_per_tti)+2*i+1] = + ((short *) UE->common_vars.rxdata[aa])[(2*subframe*UE->frame_parms.samples_per_tti)+2*i+1] = (short) (r_im[aa][i] + (iqim*r_re[aa][i]) + sqrt(sigma2/2)*gaussdouble(0.0,1.0)); //((short*) UE->common_vars.rxdata[aa])[(2*subframe*UE->frame_parms.samples_per_tti)+2*i] = (short) r_re[aa][i]; - //((short*) UE->common_vars.rxdata[aa])[(2*subframe*UE->frame_parms.samples_per_tti)+2*i+1] = (short) r_im[aa][i]; + //((short*) UE->common_vars.rxdata[aa])[(2*subframe*UE->frame_parms.samples_per_tti)+2*i+1] = (short) r_im[aa][i]; //printf("rxdata[%d][%d]=> %d, %d\n",aa,subframe*UE->frame_parms.samples_per_tti+i,r_re[aa][i],r_im[aa][i]); } } - // lte_sync_time_init(eNB->frame_parms,common_vars); // lte_sync_time(common_vars->rxdata, eNB->frame_parms); // lte_sync_time_free(); @@ -3064,12 +2953,11 @@ PMI_FEEDBACK: pilot2 = 6; pilot3 = 9; } - start_meas(&UE->phy_proc_rx[UE->current_thread_id[subframe]]); // Inner receiver scheduling for 3 slots - + for (Ns=(2*subframe); Ns<((2*subframe)+3); Ns++) { for (l=0; l<pilot2; l++) { if (n_frames==1) @@ -3087,14 +2975,13 @@ PMI_FEEDBACK: no_prefix if 1 prefix is removed by HW */ - start_meas(&UE->ofdm_demod_stats); slot_fep(UE, l, Ns%20, 0, 0, - 0); + 0); stop_meas(&UE->ofdm_demod_stats); if (UE->perfect_ce==1) { @@ -3103,26 +2990,27 @@ PMI_FEEDBACK: for(aa=0; aa<frame_parms->nb_antenna_ports_eNB; aa++) { for (aarx=0; aarx<frame_parms->nb_antennas_rx; aarx++) { for (i=0; i<frame_parms->N_RB_DL*12; i++) { - ((int16_t *) UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].dl_ch_estimates[k][(aa<<1)+aarx])[2*i+((l+(Ns%2)*pilot2)*frame_parms->ofdm_symbol_size+LTE_CE_FILTER_LENGTH)*2]=(int16_t)( - eNB2UE[round]->chF[aarx+(aa*frame_parms->nb_antennas_rx)][i].x*AMP); + ((int16_t *) UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].dl_ch_estimates[k][(aa<<1)+aarx])[2*i+((l+(Ns%2)*pilot2)*frame_parms->ofdm_symbol_size + +LTE_CE_FILTER_LENGTH)*2]=(int16_t)( + eNB2UE[round]->chF[aarx+(aa*frame_parms->nb_antennas_rx)][i].x*AMP); //printf("x=%d,AMP=%d\n",eNB2UE[round]->chF[aarx+(aa*frame_parms->nb_antennas_rx)][i].x,AMP); - ((int16_t *) UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].dl_ch_estimates[k][(aa<<1)+aarx])[2*i+1+((l+(Ns%2)*pilot2)*frame_parms->ofdm_symbol_size+LTE_CE_FILTER_LENGTH)*2]=(int16_t)( - eNB2UE[round]->chF[aarx+(aa*frame_parms->nb_antennas_rx)][i].y*AMP); + ((int16_t *) UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].dl_ch_estimates[k][(aa<<1)+aarx])[2*i+1+((l+(Ns%2)*pilot2)*frame_parms->ofdm_symbol_size + +LTE_CE_FILTER_LENGTH)*2]=(int16_t)( + eNB2UE[round]->chF[aarx+(aa*frame_parms->nb_antennas_rx)][i].y*AMP); - if (transmission_mode == 7){ - //this should include the BF weights! Will not work for a random channel + if (transmission_mode == 7) { + //this should include the BF weights! Will not work for a random channel if (UE->high_speed_flag==0) { ((int16_t *)UE->pdsch_vars[UE->current_thread_id[subframe]][0]->dl_bf_ch_estimates[(aa<<1)+aarx])[2*i]=(int16_t)( - eNB2UE[round]->chF[aarx+(aa*frame_parms->nb_antennas_rx)][i].x*AMP); + eNB2UE[round]->chF[aarx+(aa*frame_parms->nb_antennas_rx)][i].x*AMP); ((int16_t *)UE->pdsch_vars[UE->current_thread_id[subframe]][0]->dl_bf_ch_estimates[(aa<<1)+aarx])[2*i+1]=(int16_t)( - eNB2UE[round]->chF[aarx+(aa*frame_parms->nb_antennas_rx)][i].y*AMP); + eNB2UE[round]->chF[aarx+(aa*frame_parms->nb_antennas_rx)][i].y*AMP); //printf("**,x=%d,AMP=%d\n",eNB2UE[round]->chF[aarx+(aa*frame_parms->nb_antennas_rx)][i].x,AMP); } else { ((int16_t *)UE->pdsch_vars[UE->current_thread_id[subframe]][0]->dl_bf_ch_estimates[(aa<<1)+aarx])[2*i+((l+(Ns%2)*pilot2)*frame_parms->ofdm_symbol_size)*2]=(int16_t)( - eNB2UE[round]->chF[aarx+(aa*frame_parms->nb_antennas_rx)][i].x*AMP); + eNB2UE[round]->chF[aarx+(aa*frame_parms->nb_antennas_rx)][i].x*AMP); ((int16_t *)UE->pdsch_vars[UE->current_thread_id[subframe]][0]->dl_bf_ch_estimates[(aa<<1)+aarx])[2*i+1+((l+(Ns%2)*pilot2)*frame_parms->ofdm_symbol_size)*2]=(int16_t)( - eNB2UE[round]->chF[aarx+(aa*frame_parms->nb_antennas_rx)][i].y*AMP); - + eNB2UE[round]->chF[aarx+(aa*frame_parms->nb_antennas_rx)][i].y*AMP); } } } @@ -3133,10 +3021,13 @@ PMI_FEEDBACK: for(aa=0; aa<frame_parms->nb_antenna_ports_eNB; aa++) { for (aarx=0; aarx<frame_parms->nb_antennas_rx; aarx++) { for (i=0; i<frame_parms->N_RB_DL*12; i++) { - ((int16_t *) UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].dl_ch_estimates[0][(aa<<1)+aarx])[2*i+((l+(Ns%2)*pilot2)*frame_parms->ofdm_symbol_size+LTE_CE_FILTER_LENGTH)*2]=(short)(AMP); - ((int16_t *) UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].dl_ch_estimates[0][(aa<<1)+aarx])[2*i+1+((l+(Ns%2)*pilot2)*frame_parms->ofdm_symbol_size+LTE_CE_FILTER_LENGTH)*2]=0/2; + ((int16_t *) UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].dl_ch_estimates[0][(aa<<1)+aarx])[2*i+((l+(Ns%2)*pilot2)*frame_parms->ofdm_symbol_size + +LTE_CE_FILTER_LENGTH)*2]=(short)(AMP); + ((int16_t *) UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].dl_ch_estimates[0][(aa<<1)+aarx])[2*i+1+((l+(Ns%2)*pilot2)*frame_parms->ofdm_symbol_size + +LTE_CE_FILTER_LENGTH)*2]=0/2; + if (transmission_mode == 7) { - if (UE->high_speed_flag==0){ + if (UE->high_speed_flag==0) { ((int16_t *) UE->pdsch_vars[UE->current_thread_id[subframe]][0]->dl_bf_ch_estimates[(aa<<1)+aarx])[2*i]=(short)(AMP); ((int16_t *) UE->pdsch_vars[UE->current_thread_id[subframe]][0]->dl_bf_ch_estimates[(aa<<1)+aarx])[2*i+1]=0/2; } else { @@ -3150,7 +3041,6 @@ PMI_FEEDBACK: } } - if ((Ns==((2*subframe))) && (l==0)) { lte_ue_measurements(UE, subframe*UE->frame_parms.samples_per_tti, @@ -3186,12 +3076,9 @@ PMI_FEEDBACK: goto PMI_FEEDBACK; } } - } - if ((Ns==(2*subframe)) && (l==pilot1)) {// process symbols 0,1,2 - if (dci_flag == 1) { UE->UE_mode[0] = PUSCH; start_meas(&UE->dlsch_rx_pdcch_stats); @@ -3207,7 +3094,6 @@ PMI_FEEDBACK: stop_meas(&UE->dlsch_rx_pdcch_stats); // overwrite number of pdcch symbols UE->pdcch_vars[0]->num_pdcch_symbols = num_pdcch_symbols; - dci_cnt = dci_decoding_procedure(UE, dci_alloc_rx,1, eNB_id, @@ -3224,7 +3110,7 @@ PMI_FEEDBACK: //round_trials[0]++; if (n_frames==1) - printf("DCI error trial %d errs[0] %d\n",trials,errs[0]); + printf("DCI error trial %u errs[0] %u\n",trials,errs[0]); } // for (i=1;i<=round;i++) @@ -3238,7 +3124,7 @@ PMI_FEEDBACK: if ((dci_alloc_rx[i].rnti == n_rnti) && (generate_ue_dlsch_params_from_dci(0, - subframe, + subframe, dci_alloc_rx[i].dci_pdu, dci_alloc_rx[i].rnti, dci_alloc_rx[i].format, @@ -3259,18 +3145,16 @@ PMI_FEEDBACK: UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[UE->dlsch[UE->current_thread_id[subframe]][0][0]->current_harq_pid]->Nl, UE->pdcch_vars[0]->num_pdcch_symbols, 0, - subframe, - (transmission_mode<7?0:transmission_mode)); - /*if (transmission_mode==7 && common_flag==0) - UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[0]->mimo_mode = TM7; */ - + subframe, + (transmission_mode<7?0:transmission_mode)); + /*if (transmission_mode==7 && common_flag==0) + UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[0]->mimo_mode = TM7; */ /* rate = (double)dlsch_tbs25[get_I_TBS(UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[UE->dlsch[UE->current_thread_id[subframe]][0][0]->current_harq_pid]->mcs)][UE->dlsch[UE->current_thread_id[subframe]][0][0]->nb_rb-1]/(coded_bits_per_codeword); rate*=get_Qm(UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[UE->dlsch[UE->current_thread_id[subframe]][0][0]->current_harq_pid]->mcs); */ - printf("num_pdcch_symbols %d, G %d, TBS %d\n",UE->pdcch_vars[0]->num_pdcch_symbols,coded_bits_per_codeword, + printf("num_pdcch_symbols %d, G %u, TBS %d\n",UE->pdcch_vars[0]->num_pdcch_symbols,coded_bits_per_codeword, UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[UE->dlsch[UE->current_thread_id[subframe]][0][0]->current_harq_pid]->TBS); - dlsch_active = 1; } else { dlsch_active = 0; @@ -3282,8 +3166,8 @@ PMI_FEEDBACK: round=5; if (n_frames==1) - printf("DCI misdetection trial %d\n",trials); - + printf("DCI misdetection trial %u\n",trials); +>>>>>>> new set of cppcheck fixes } // for (i=1;i<=round;i++) @@ -3293,86 +3177,84 @@ PMI_FEEDBACK: } } // if dci_flag==1 else { //dci_flag == 0 - UE->pdcch_vars[0]->crnti = n_rnti; UE->pdcch_vars[0]->num_pdcch_symbols = num_pdcch_symbols; if (round == 0) UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[0]->first_tx=1; switch (transmission_mode) { - case 1: - case 2: - case 7: - generate_ue_dlsch_params_from_dci(0, - subframe, - &DLSCH_alloc_pdu_1[0], - (common_flag==0)? C_RNTI : SI_RNTI, - (common_flag==0)? format1 : format1A, - UE->pdcch_vars[UE->current_thread_id[subframe]][eNB_id], - UE->pdsch_vars[UE->current_thread_id[subframe]][eNB_id], - UE->dlsch[UE->current_thread_id[subframe]][0], - &UE->frame_parms, - UE->pdsch_config_dedicated, - SI_RNTI, - 0, - P_RNTI, - transmission_mode<7?0:transmission_mode); - /*if(transmission_mode==7 && common_flag==0) - UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[0]->mimo_mode = TM7;*/ - break; - - case 3: - // printf("Rate: TM3 (before) round %d (%d) first_tx %d\n",round,UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[0]->round,UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[0]->first_tx); - generate_ue_dlsch_params_from_dci(0, - subframe, - &DLSCH_alloc_pdu_1[0], - (common_flag==0)? C_RNTI : SI_RNTI, - (common_flag==0)? format2A : format1A, - UE->dlsch[UE->current_thread_id[subframe]][0], - &UE->frame_parms, - UE->pdsch_config_dedicated, - SI_RNTI, - 0, - P_RNTI, - 0); - // printf("Rate: TM3 (after) round %d (%d) first_tx %d\n",round,UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[0]->round,UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[0]->first_tx); - break; + case 1: + case 2: + case 7: + generate_ue_dlsch_params_from_dci(0, + subframe, + &DLSCH_alloc_pdu_1[0], + (common_flag==0)? C_RNTI : SI_RNTI, + (common_flag==0)? format1 : format1A, + UE->pdcch_vars[UE->current_thread_id[subframe]][eNB_id], + UE->pdsch_vars[UE->current_thread_id[subframe]][eNB_id], + UE->dlsch[UE->current_thread_id[subframe]][0], + &UE->frame_parms, + UE->pdsch_config_dedicated, + SI_RNTI, + 0, + P_RNTI, + transmission_mode<7?0:transmission_mode); + /*if(transmission_mode==7 && common_flag==0) + UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[0]->mimo_mode = TM7;*/ + break; - case 4: - generate_ue_dlsch_params_from_dci(0, - subframe, - &DLSCH_alloc_pdu_1[0], - (common_flag==0)? C_RNTI : SI_RNTI, - (common_flag==0)? format2 : format1A, - UE->pdcch_vars[UE->current_thread_id[subframe]][eNB_id], - UE->pdsch_vars[UE->current_thread_id[subframe]][eNB_id], - UE->dlsch[UE->current_thread_id[subframe]][0], - &UE->frame_parms, - UE->pdsch_config_dedicated, - SI_RNTI, - 0, - P_RNTI, - 0); - break; + case 3: + // printf("Rate: TM3 (before) round %d (%d) first_tx %d\n",round,UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[0]->round,UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[0]->first_tx); + generate_ue_dlsch_params_from_dci(0, + subframe, + &DLSCH_alloc_pdu_1[0], + (common_flag==0)? C_RNTI : SI_RNTI, + (common_flag==0)? format2A : format1A, + UE->dlsch[UE->current_thread_id[subframe]][0], + &UE->frame_parms, + UE->pdsch_config_dedicated, + SI_RNTI, + 0, + P_RNTI, + 0); + // printf("Rate: TM3 (after) round %d (%d) first_tx %d\n",round,UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[0]->round,UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[0]->first_tx); + break; - case 5: - case 6: - generate_ue_dlsch_params_from_dci(0, - subframe, - &DLSCH_alloc_pdu2_1E[0], - C_RNTI, - format1E_2A_M10PRB, - ue->pdcch_vars[UE->current_thread_id[subframe]][eNB_id], - ue->pdsch_vars[UE->current_thread_id[subframe]][eNB_id], - UE->dlsch[UE->current_thread_id[subframe]][0], - &UE->frame_parms, - UE->pdsch_config_dedicated, - SI_RNTI, - 0, - P_RNTI, - 0); - break; + case 4: + generate_ue_dlsch_params_from_dci(0, + subframe, + &DLSCH_alloc_pdu_1[0], + (common_flag==0)? C_RNTI : SI_RNTI, + (common_flag==0)? format2 : format1A, + UE->pdcch_vars[UE->current_thread_id[subframe]][eNB_id], + UE->pdsch_vars[UE->current_thread_id[subframe]][eNB_id], + UE->dlsch[UE->current_thread_id[subframe]][0], + &UE->frame_parms, + UE->pdsch_config_dedicated, + SI_RNTI, + 0, + P_RNTI, + 0); + break; + case 5: + case 6: + generate_ue_dlsch_params_from_dci(0, + subframe, + &DLSCH_alloc_pdu2_1E[0], + C_RNTI, + format1E_2A_M10PRB, + ue->pdcch_vars[UE->current_thread_id[subframe]][eNB_id], + ue->pdsch_vars[UE->current_thread_id[subframe]][eNB_id], + UE->dlsch[UE->current_thread_id[subframe]][0], + &UE->frame_parms, + UE->pdsch_config_dedicated, + SI_RNTI, + 0, + P_RNTI, + 0); + break; } dlsch_active = 1; @@ -3380,21 +3262,19 @@ PMI_FEEDBACK: } if (dlsch_active == 1) { - - if (transmission_mode==7) { - if (UE->frame_parms.Ncp==0) { - if ((Ns==(2*subframe) && ((l==3) || (l==6))) || - (Ns==(1+2*subframe) && ((l==2) || (l==5)))) { - if (perfect_ce==0) - lte_dl_bf_channel_estimation(UE,eNB_id,0,Ns,5,l+7*(Ns%2==1)); - } - } else { - msg("Beamforming channel estimation not supported yet for TM7 extented CP.\n"); - } - } + if (transmission_mode==7) { + if (UE->frame_parms.Ncp==0) { + if ((Ns==(2*subframe) && ((l==3) || (l==6))) || + (Ns==(1+2*subframe) && ((l==2) || (l==5)))) { + if (perfect_ce==0) + lte_dl_bf_channel_estimation(UE,eNB_id,0,Ns,5,l+7*(Ns%2==1)); + } + } else { + msg("Beamforming channel estimation not supported yet for TM7 extented CP.\n"); + } + } if ((Ns==(1+(2*subframe))) && (l==0)) {// process PDSCH symbols 1,2,3,4,5,(6 Normal Prefix) - if ((transmission_mode == 5) && (UE->dlsch[UE->current_thread_id[subframe]][eNB_id][0]->harq_processes[UE->dlsch[UE->current_thread_id[subframe]][0][0]->current_harq_pid]->dl_power_off==0) && (UE->use_ia_receiver ==1)) { @@ -3403,7 +3283,6 @@ PMI_FEEDBACK: dual_stream_UE = 0; } - start_meas(&UE->dlsch_llr_stats); for (m=UE->pdcch_vars[0]->num_pdcch_symbols; @@ -3480,7 +3359,6 @@ PMI_FEEDBACK: stop_meas(&UE->dlsch_llr_stats); } - if (test_perf ==0 ) { if ((n_frames==1) && (Ns==(2+(2*subframe))) && (l==0)) { LOG_M("ch0.m","ch0",eNB2UE[0]->ch[0],eNB2UE[0]->channel_length,1,8); @@ -3500,36 +3378,33 @@ PMI_FEEDBACK: } LOG_M("dlsch00_r0.m","dl00_r0", - &(UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].dl_ch_estimates[eNB_id][0][0]), - UE->frame_parms.ofdm_symbol_size*nsymb,1,1); + &(UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].dl_ch_estimates[eNB_id][0][0]), + UE->frame_parms.ofdm_symbol_size*nsymb,1,1); if (UE->frame_parms.nb_antennas_rx>1) LOG_M("dlsch01_r0.m","dl01_r0", - &(UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].dl_ch_estimates[eNB_id][1][0]), - UE->frame_parms.ofdm_symbol_size*nsymb,1,1); + &(UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].dl_ch_estimates[eNB_id][1][0]), + UE->frame_parms.ofdm_symbol_size*nsymb,1,1); if (eNB->frame_parms.nb_antennas_tx>1) LOG_M("dlsch10_r0.m","dl10_r0", - &(UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].dl_ch_estimates[eNB_id][2][0]), - UE->frame_parms.ofdm_symbol_size*nsymb,1,1); + &(UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].dl_ch_estimates[eNB_id][2][0]), + UE->frame_parms.ofdm_symbol_size*nsymb,1,1); if ((UE->frame_parms.nb_antennas_rx>1) && (eNB->frame_parms.nb_antennas_tx>1)) LOG_M("dlsch11_r0.m","dl11_r0", - &(UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].dl_ch_estimates[eNB_id][3][0]), - UE->frame_parms.ofdm_symbol_size*nsymb/2,1,1); + &(UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].dl_ch_estimates[eNB_id][3][0]), + UE->frame_parms.ofdm_symbol_size*nsymb/2,1,1); //pdsch_vars dump_dlsch2(UE,eNB_id,subframe,&coded_bits_per_codeword,round); //dump_dlsch2(UE,eNB_id_i,coded_bits_per_codeword); LOG_M("dlsch_e.m","e",eNB->dlsch[0][0]->harq_processes[0]->e,coded_bits_per_codeword,1,4); - //pdcch_vars LOG_M("pdcchF0_ext.m","pdcchF_ext", UE->pdcch_vars[eNB_id]->rxdataF_ext[0],2*3*UE->frame_parms.ofdm_symbol_size,1,1); LOG_M("pdcch00_ch0_ext.m","pdcch00_ch0_ext",UE->pdcch_vars[eNB_id]->dl_ch_estimates_ext[0],300*3,1,1); - LOG_M("pdcch_rxF_comp0.m","pdcch0_rxF_comp0",UE->pdcch_vars[eNB_id]->rxdataF_comp[0],4*300,1,1); LOG_M("pdcch_rxF_llr.m","pdcch_llr",UE->pdcch_vars[eNB_id]->llr,2400,1,4); - } } } @@ -3557,21 +3432,17 @@ PMI_FEEDBACK: eNB->dlsch[0][cw]->harq_processes[0]->Nl, num_pdcch_symbols, 0, - subframe, - (transmission_mode<7?0:transmission_mode)); - + subframe, + (transmission_mode<7?0:transmission_mode)); UE->dlsch[UE->current_thread_id[subframe]][0][cw]->harq_processes[UE->dlsch[UE->current_thread_id[subframe]][0][cw]->current_harq_pid]->G = coded_bits_per_codeword; - - - // calculate uncoded BLER uncoded_ber=0; - for (i=0;i<coded_bits_per_codeword;i++) + + for (i=0; i<coded_bits_per_codeword; i++) if (eNB->dlsch[0][0]->harq_processes[0]->e[i] != (UE->pdsch_vars[UE->current_thread_id[subframe]][0]->llr[0][i]<0)) { uncoded_ber_bit[i] = 1; uncoded_ber++; - } - else + } else uncoded_ber_bit[i] = 0; uncoded_ber/=coded_bits_per_codeword; @@ -3579,7 +3450,6 @@ PMI_FEEDBACK: if (n_frames==1) LOG_M("uncoded_ber_bit.m","uncoded_ber_bit",uncoded_ber_bit,coded_bits_per_codeword,1,0); - start_meas(&UE->dlsch_unscrambling_stats); dlsch_unscrambling(&UE->frame_parms, @@ -3590,7 +3460,6 @@ PMI_FEEDBACK: 0, subframe<<1); stop_meas(&UE->dlsch_unscrambling_stats); - start_meas(&UE->dlsch_decoding_stats); ret = dlsch_decoding(UE, UE->pdsch_vars[UE->current_thread_id[subframe]][eNB_id]->llr[cw], @@ -3610,12 +3479,9 @@ PMI_FEEDBACK: } } - stop_meas(&UE->phy_proc_rx[UE->current_thread_id[subframe]]); - if (ret <= UE->dlsch[UE->current_thread_id[subframe]][0][0]->max_turbo_iterations) { - avg_iter += ret; iter_trials++; @@ -3625,7 +3491,8 @@ PMI_FEEDBACK: UE->total_TBS[eNB_id] = UE->total_TBS[eNB_id] + UE->dlsch[UE->current_thread_id[subframe]][eNB_id][0]->harq_processes[UE->dlsch[UE->current_thread_id[subframe]][eNB_id][0]->current_harq_pid]->TBS; TB0_active = 0; - if (UE->dlsch[UE->current_thread_id[subframe]][eNB_id][0]->harq_processes[UE->dlsch[UE->current_thread_id[subframe]][eNB_id][0]->current_harq_pid]->mimo_mode == LARGE_CDD) { //try to decode second stream using SIC + if (UE->dlsch[UE->current_thread_id[subframe]][eNB_id][0]->harq_processes[UE->dlsch[UE->current_thread_id[subframe]][eNB_id][0]->current_harq_pid]->mimo_mode == + LARGE_CDD) { //try to decode second stream using SIC /* for (round = 0 ; round < UE->dlsch[UE->current_thread_id[subframe]][eNB_id][0]->harq_processes[UE->dlsch[UE->current_thread_id[subframe]][eNB_id][0]->current_harq_pid]->round ; round++) { // re-encoding of first stream @@ -3667,12 +3534,11 @@ PMI_FEEDBACK: } } else { errs[round]++; - avg_iter += ret-1; iter_trials++; if (n_frames==1) { - //if ((n_frames==1) || (SNR>=30)) + //if ((n_frames==1) || (SNR>=30)) printf("DLSCH errors found (round %d), uncoded ber %f\n",round,uncoded_ber); for (s=0; s<UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[0]->C; s++) { @@ -3682,11 +3548,11 @@ PMI_FEEDBACK: Kr = UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[0]->Kplus; Kr_bytes = Kr>>3; - printf("Decoded_output (Segment %d):\n",s); for (i=0; i<Kr_bytes; i++) - printf("%d : %x (%x)\n",i,UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[0]->c[s][i],UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[0]->c[s][i]^eNB->dlsch[0][0]->harq_processes[0]->c[s][i]); + printf("%d : %x (%x)\n",i,UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[0]->c[s][i], + UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[0]->c[s][i]^eNB->dlsch[0][0]->harq_processes[0]->c[s][i]); } sprintf(fname,"rxsig0_r%d.m",round); @@ -3695,7 +3561,7 @@ PMI_FEEDBACK: sprintf(fname,"rxsigF0_r%d.m",round); sprintf(vname,"rxs0F_r%d",round); LOG_M(fname,vname, &UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].rxdataF[0][0],2*UE->frame_parms.ofdm_symbol_size*nsymb,2,1); - + if (UE->frame_parms.nb_antennas_rx>1) { sprintf(fname,"rxsig1_r%d.m",round); sprintf(vname,"rxs1_r%d.m",round); @@ -3708,31 +3574,31 @@ PMI_FEEDBACK: sprintf(fname,"dlsch00_r%d.m",round); sprintf(vname,"dl00_r%d",round); LOG_M(fname,vname, - &(UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].dl_ch_estimates[eNB_id][0][0]), - UE->frame_parms.ofdm_symbol_size*nsymb,1,1); + &(UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].dl_ch_estimates[eNB_id][0][0]), + UE->frame_parms.ofdm_symbol_size*nsymb,1,1); if (UE->frame_parms.nb_antennas_rx>1) { sprintf(fname,"dlsch01_r%d.m",round); sprintf(vname,"dl01_r%d",round); LOG_M(fname,vname, - &(UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].dl_ch_estimates[eNB_id][1][0]), - UE->frame_parms.ofdm_symbol_size*nsymb/2,1,1); + &(UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].dl_ch_estimates[eNB_id][1][0]), + UE->frame_parms.ofdm_symbol_size*nsymb/2,1,1); } if (eNB->frame_parms.nb_antennas_tx>1) { sprintf(fname,"dlsch10_r%d.m",round); sprintf(vname,"dl10_r%d",round); LOG_M(fname,vname, - &(UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].dl_ch_estimates[eNB_id][2][0]), - UE->frame_parms.ofdm_symbol_size*nsymb/2,1,1); + &(UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].dl_ch_estimates[eNB_id][2][0]), + UE->frame_parms.ofdm_symbol_size*nsymb/2,1,1); } if ((UE->frame_parms.nb_antennas_rx>1) && (eNB->frame_parms.nb_antennas_tx>1)) { sprintf(fname,"dlsch11_r%d.m",round); sprintf(vname,"dl11_r%d",round); LOG_M(fname,vname, - &(UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].dl_ch_estimates[eNB_id][3][0]), - UE->frame_parms.ofdm_symbol_size*nsymb/2,1,1); + &(UE->common_vars.common_vars_rx_data_per_thread[UE->current_thread_id[subframe]].dl_ch_estimates[eNB_id][3][0]), + UE->frame_parms.ofdm_symbol_size*nsymb/2,1,1); } //pdsch_vars @@ -3748,19 +3614,17 @@ PMI_FEEDBACK: } // printf("round %d errors %d/%d\n",round,errs[round],trials); - round++; // UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[0]->round++; } - if (xforms==1) { - phy_scope_UE(form_ue, - UE, - eNB_id, - 0,// UE_id - subframe); - } - + if (xforms==1) { + phy_scope_UE(form_ue, + UE, + eNB_id, + 0,// UE_id + subframe); + } } //round // printf("\n"); @@ -3778,9 +3642,7 @@ PMI_FEEDBACK: UE->total_TBS_last[eNB_id] = UE->total_TBS[eNB_id]; } - UE->proc.proc_rxtx[UE->current_thread_id[subframe]].frame_rx++; - /* calculate the total processing time for each packet, * get the max, min, and number of packets that exceed t>2000us */ @@ -3788,8 +3650,6 @@ PMI_FEEDBACK: double t_tx_ifft = (double)eNB->ofdm_mod_stats.p_time/cpu_freq_GHz/1000.0; double t_tx_mod = (double)eNB->dlsch_modulation_stats.p_time/cpu_freq_GHz/1000.0; double t_tx_enc = (double)eNB->dlsch_encoding_stats.p_time/cpu_freq_GHz/1000.0; - - double t_rx = (double)UE->phy_proc_rx[UE->current_thread_id[subframe]].p_time/cpu_freq_GHz/1000.0; double t_rx_fft = (double)UE->ofdm_demod_stats.p_time/cpu_freq_GHz/1000.0; double t_rx_demod = (double)UE->dlsch_rx_pdcch_stats.p_time/cpu_freq_GHz/1000.0; @@ -3817,13 +3677,10 @@ PMI_FEEDBACK: push_front(&time_vector_tx_ifft, t_tx_ifft); push_front(&time_vector_tx_mod, t_tx_mod); push_front(&time_vector_tx_enc, t_tx_enc); - push_front(&time_vector_rx, t_rx); push_front(&time_vector_rx_fft, t_rx_fft); push_front(&time_vector_rx_demod, t_rx_demod); push_front(&time_vector_rx_dec, t_rx_dec); - - } //trials // round_trials[0]: number of code word : goodput the protocol @@ -3835,7 +3692,6 @@ PMI_FEEDBACK: totable(table_tx_mod, &time_vector_tx_mod); double table_tx_enc[time_vector_tx_enc.size]; totable(table_tx_enc, &time_vector_tx_enc); - double table_rx[time_vector_rx.size]; totable(table_rx, &time_vector_rx); double table_rx_fft[time_vector_rx_fft.size]; @@ -3844,8 +3700,6 @@ PMI_FEEDBACK: totable(table_rx_demod, &time_vector_rx_demod); double table_rx_dec[time_vector_rx_dec.size]; totable(table_rx_dec, &time_vector_rx_dec); - - // sort table qsort (table_tx, time_vector_tx.size, sizeof(double), &compare); qsort (table_rx, time_vector_rx.size, sizeof(double), &compare); @@ -3859,53 +3713,41 @@ PMI_FEEDBACK: double tx_median = table_tx[time_vector_tx.size/2]; double tx_q1 = table_tx[time_vector_tx.size/4]; double tx_q3 = table_tx[3*time_vector_tx.size/4]; - double tx_ifft_median = table_tx_ifft[time_vector_tx_ifft.size/2]; double tx_ifft_q1 = table_tx_ifft[time_vector_tx_ifft.size/4]; double tx_ifft_q3 = table_tx_ifft[3*time_vector_tx_ifft.size/4]; - double tx_mod_median = table_tx_mod[time_vector_tx_mod.size/2]; double tx_mod_q1 = table_tx_mod[time_vector_tx_mod.size/4]; double tx_mod_q3 = table_tx_mod[3*time_vector_tx_mod.size/4]; - double tx_enc_median = table_tx_enc[time_vector_tx_enc.size/2]; double tx_enc_q1 = table_tx_enc[time_vector_tx_enc.size/4]; double tx_enc_q3 = table_tx_enc[3*time_vector_tx_enc.size/4]; - double rx_median = table_rx[time_vector_rx.size/2]; double rx_q1 = table_rx[time_vector_rx.size/4]; double rx_q3 = table_rx[3*time_vector_rx.size/4]; - double rx_fft_median = table_rx_fft[time_vector_rx_fft.size/2]; double rx_fft_q1 = table_rx_fft[time_vector_rx_fft.size/4]; double rx_fft_q3 = table_rx_fft[3*time_vector_rx_fft.size/4]; - double rx_demod_median = table_rx_demod[time_vector_rx_demod.size/2]; double rx_demod_q1 = table_rx_demod[time_vector_rx_demod.size/4]; double rx_demod_q3 = table_rx_demod[3*time_vector_rx_demod.size/4]; - double rx_dec_median = table_rx_dec[time_vector_rx_dec.size/2]; double rx_dec_q1 = table_rx_dec[time_vector_rx_dec.size/4]; double rx_dec_q3 = table_rx_dec[3*time_vector_rx_dec.size/4]; - double std_phy_proc_tx=0; double std_phy_proc_tx_ifft=0; double std_phy_proc_tx_mod=0; double std_phy_proc_tx_enc=0; - double std_phy_proc_rx=0; double std_phy_proc_rx_fft=0; double std_phy_proc_rx_demod=0; double std_phy_proc_rx_dec=0; - effective_rate = ((double)(round_trials[0]-dci_errors)/((double)round_trials[0] + round_trials[1] + round_trials[2] + round_trials[3])); - printf("\n**********************SNR = %f dB (tx_lev %f, sigma2_dB %f)**************************\n", SNR, (double)tx_lev_dB+10*log10(UE->frame_parms.ofdm_symbol_size/(NB_RB*12)), sigma2_dB); - - printf("Errors (%d(%d)/%d %d/%d %d/%d %d/%d), Pe = (%e,%e,%e,%e), dci_errors %d/%d, Pe = %e => effective rate %f (%2.1f%%,%f, %f), normalized delay %f (%f)\n", + printf("Errors (%u(%u)/%u %u/%u %u/%u %u/%u), Pe = (%e,%e,%e,%e), dci_errors %u/%u, Pe = %e => effective rate %f (%2.1f%%,%f, %f), normalized delay %f (%f)\n", errs[0], errs2[0], round_trials[0], @@ -3962,11 +3804,12 @@ PMI_FEEDBACK: printf("|__ DLSCH sub-block interleaving time :%f us (%d trials)\n", ((double)eNB->dlsch_interleaving_stats.trials/eNB->dlsch_encoding_stats.trials)*(double) eNB->dlsch_interleaving_stats.diff/eNB->dlsch_interleaving_stats.trials/cpu_freq_GHz/1000.0,eNB->dlsch_interleaving_stats.trials); - printf("\n\nUE RX function statistics (per 1ms subframe)\n\n"); std_phy_proc_rx = sqrt((double)UE->phy_proc_rx[UE->current_thread_id[subframe]].diff_square/pow(cpu_freq_GHz,2)/pow(1000, - 2)/UE->phy_proc_rx[UE->current_thread_id[subframe]].trials - pow((double)UE->phy_proc_rx[UE->current_thread_id[subframe]].diff/UE->phy_proc_rx[UE->current_thread_id[subframe]].trials/cpu_freq_GHz/1000,2)); - printf("Total PHY proc rx :%f us (%d trials)\n",(double)UE->phy_proc_rx[UE->current_thread_id[subframe]].diff/UE->phy_proc_rx[UE->current_thread_id[subframe]].trials/cpu_freq_GHz/1000.0, + 2)/UE->phy_proc_rx[UE->current_thread_id[subframe]].trials - pow((double) + UE->phy_proc_rx[UE->current_thread_id[subframe]].diff/UE->phy_proc_rx[UE->current_thread_id[subframe]].trials/cpu_freq_GHz/1000,2)); + printf("Total PHY proc rx :%f us (%d trials)\n", + (double)UE->phy_proc_rx[UE->current_thread_id[subframe]].diff/UE->phy_proc_rx[UE->current_thread_id[subframe]].trials/cpu_freq_GHz/1000.0, UE->phy_proc_rx[UE->current_thread_id[subframe]].trials*2/3); printf("|__Statistcs std: %fus max: %fus min: %fus median %fus q1 %fus q3 %fus n_dropped: %d packet \n", std_phy_proc_rx, t_rx_max, t_rx_min, rx_median, rx_q1, rx_q3, n_rx_dropped); @@ -4001,7 +3844,8 @@ PMI_FEEDBACK: printf("|__ DLSCH Rate Unmatching :%f us (%d trials)\n", (double)UE->dlsch_rate_unmatching_stats.diff/UE->dlsch_rate_unmatching_stats.trials/cpu_freq_GHz/1000.0,UE->dlsch_rate_unmatching_stats.trials); printf("|__ DLSCH Turbo Decoding(%d bits) :%f us (%d trials)\n", - UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[0]->Cminus ? UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[0]->Kminus : UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[0]->Kplus, + UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[0]->Cminus ? UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[0]->Kminus : + UE->dlsch[UE->current_thread_id[subframe]][0][0]->harq_processes[0]->Kplus, (double)UE->dlsch_turbo_decoding_stats.diff/UE->dlsch_turbo_decoding_stats.trials/cpu_freq_GHz/1000.0,UE->dlsch_turbo_decoding_stats.trials); printf(" |__ init %f us (cycles/iter %f, %d trials)\n", (double)UE->dlsch_tc_init_stats.diff/UE->dlsch_tc_init_stats.trials/cpu_freq_GHz/1000.0, @@ -4034,7 +3878,7 @@ PMI_FEEDBACK: } if ((transmission_mode != 3) && (transmission_mode != 4)) { - fprintf(bler_fd,"%f;%d;%d;%f;%d;%d;%d;%d;%d;%d;%d;%d;%d\n", + fprintf(bler_fd,"%f;%d;%d;%f;%u;%u;%u;%u;%u;%u;%u;%u;%u\n", SNR, mcs1, eNB->dlsch[0][0]->harq_processes[0]->TBS, @@ -4049,7 +3893,7 @@ PMI_FEEDBACK: round_trials[3], dci_errors); } else { - fprintf(bler_fd,"%f;%d;%d;%d;%d;%f;%d;%d;%d;%d;%d;%d;%d;%d;%d\n", + fprintf(bler_fd,"%f;%d;%d;%d;%d;%f;%u;%u;%u;%u;%u;%u;%u;%u;%u\n", SNR, mcs1,mcs2, eNB->dlsch[0][0]->harq_processes[0]->TBS, @@ -4066,7 +3910,6 @@ PMI_FEEDBACK: dci_errors); } - if(abstx) { //ABSTRACTION blerr[0] = (double)errs[0]/(round_trials[0]); @@ -4083,7 +3926,7 @@ PMI_FEEDBACK: if ( (test_perf != 0) && (100 * effective_rate > test_perf )) { //fprintf(time_meas_fd,"SNR; MCS; TBS; rate; err0; trials0; err1; trials1; err2; trials2; err3; trials3; dci_err\n"); if ((transmission_mode != 3) && (transmission_mode != 4)) { - fprintf(time_meas_fd,"%f;%d;%d;%f;%d;%d;%d;%d;%d;%d;%d;%d;%d;", + fprintf(time_meas_fd,"%f;%d;%d;%f;%u;%u;%u;%u;%u;%u;%u;%u;%u;", SNR, mcs1, eNB->dlsch[0][0]->harq_processes[0]->TBS, @@ -4097,9 +3940,8 @@ PMI_FEEDBACK: errs[3], round_trials[3], dci_errors); - //fprintf(time_meas_fd,"SNR; MCS; TBS; rate; DL_DECOD_ITER; err0; trials0; err1; trials1; err2; trials2; err3; trials3; PE; dci_err;PE;ND;\n"); - fprintf(time_meas_fd,"%f;%d;%d;%f; %2.1f%%;%f;%f;%d;%d;%d;%d;%d;%d;%d;%d;%e;%e;%e;%e;%d;%d;%e;%f;%f;", + fprintf(time_meas_fd,"%f;%d;%d;%f; %2.1f%%;%f;%f;%u;%u;%u;%u;%u;%u;%u;%u;%e;%e;%e;%e;%u;%u;%e;%f;%f;", SNR, mcs1, eNB->dlsch[0][0]->harq_processes[0]->TBS, @@ -4126,7 +3968,7 @@ PMI_FEEDBACK: (double)eNB->dlsch[0][0]->harq_processes[0]->TBS, (1.0*(round_trials[0]-errs[0])+2.0*(round_trials[1]-errs[1])+3.0*(round_trials[2]-errs[2])+4.0*(round_trials[3]-errs[3]))/((double)round_trials[0])); } else { - fprintf(time_meas_fd,"%f;%d;%d;%d;%d;%f;%d;%d;%d;%d;%d;%d;%d;%d;%d;", + fprintf(time_meas_fd,"%f;%d;%d;%d;%d;%f;%u;%u;%u;%u;%u;%u;%u;%u;%u;", SNR, mcs1,mcs2, eNB->dlsch[0][0]->harq_processes[0]->TBS, @@ -4141,9 +3983,8 @@ PMI_FEEDBACK: errs[3], round_trials[3], dci_errors); - //fprintf(time_meas_fd,"SNR; MCS; TBS; rate; DL_DECOD_ITER; err0; trials0; err1; trials1; err2; trials2; err3; trials3; PE; dci_err;PE;ND;\n"); - fprintf(time_meas_fd,"%f;%d;%d;%d;%d;%f;%2.1f;%f;%f;%d;%d;%d;%d;%d;%d;%d;%d;%e;%e;%e;%e;%d;%d;%e;%f;%f;", + fprintf(time_meas_fd,"%f;%d;%d;%d;%d;%f;%2.1f;%f;%f;%u;%u;%u;%u;%u;%u;%u;%u;%e;%e;%e;%e;%u;%u;%e;%f;%f;", SNR, mcs1,mcs2, eNB->dlsch[0][0]->harq_processes[0]->TBS, @@ -4201,30 +4042,20 @@ PMI_FEEDBACK: ); //fprintf(time_meas_fd,"eNB_PROC_TX_STD;eNB_PROC_TX_MAX;eNB_PROC_TX_MIN;eNB_PROC_TX_MED;eNB_PROC_TX_Q1;eNB_PROC_TX_Q3;eNB_PROC_TX_DROPPED;\n"); fprintf(time_meas_fd,"%f;%f;%f;%f;%f;%f;%d;", std_phy_proc_tx, t_tx_max, t_tx_min, tx_median, tx_q1, tx_q3, n_tx_dropped); - //fprintf(time_meas_fd,"IFFT;\n"); fprintf(time_meas_fd,"%f;%f;%f;%f;", std_phy_proc_tx_ifft, tx_ifft_median, tx_ifft_q1, tx_ifft_q3); - //fprintf(time_meas_fd,"MOD;\n"); fprintf(time_meas_fd,"%f;%f;%f;%f;", std_phy_proc_tx_mod, tx_mod_median, tx_mod_q1, tx_mod_q3); - //fprintf(time_meas_fd,"ENC;\n"); fprintf(time_meas_fd,"%f;%f;%f;%f;", std_phy_proc_tx_enc, tx_enc_median, tx_enc_q1, tx_enc_q3); - - //fprintf(time_meas_fd,"UE_PROC_RX_STD;UE_PROC_RX_MAX;UE_PROC_RX_MIN;UE_PROC_RX_MED;UE_PROC_RX_Q1;UE_PROC_RX_Q3;UE_PROC_RX_DROPPED;\n"); fprintf(time_meas_fd,"%f;%f;%f;%f;%f;%f;%d;", std_phy_proc_rx, t_rx_max, t_rx_min, rx_median, rx_q1, rx_q3, n_rx_dropped); - //fprintf(time_meas_fd,"FFT;\n"); fprintf(time_meas_fd,"%f;%f;%f;%f;", std_phy_proc_rx_fft, rx_fft_median, rx_fft_q1, rx_fft_q3); - //fprintf(time_meas_fd,"DEMOD;\n"); fprintf(time_meas_fd,"%f;%f;%f;%f;", std_phy_proc_rx_demod,rx_demod_median, rx_demod_q1, rx_demod_q3); - //fprintf(time_meas_fd,"DEC;\n"); fprintf(time_meas_fd,"%f;%f;%f;%f\n", std_phy_proc_rx_dec, rx_dec_median, rx_dec_q1, rx_dec_q3); - - /* fprintf(time_meas_fd,"%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;%d;", eNB->phy_proc_tx.trials, @@ -4248,11 +4079,8 @@ PMI_FEEDBACK: if (((double)errs[0]/(round_trials[0]))<(10.0/n_frames)) break; }// SNR - - } //ch_realization - fclose(bler_fd); if (test_perf !=0) @@ -4293,10 +4121,9 @@ PMI_FEEDBACK: free_ue_dlsch(UE->dlsch[UE->current_thread_id[subframe]][0][i]); } - printf("Freeing channel I/O\n"); - for (i=0; i<n_tx_phy; i++){ + for (i=0; i<n_tx_phy; i++) { free(s_re[i]); free(s_im[i]); } @@ -4306,16 +4133,12 @@ PMI_FEEDBACK: free(r_im[i]); } - free(s_re); free(s_im); free(r_re); free(r_im); - // lte_sync_time_free(); - // printf("[MUMIMO] mcs %d, mcsi %d, offset %d, bler %f\n",mcs,mcs_i,offset_mumimo_llr_drange_fix,((double)errs[0])/((double)round_trials[0])); - return(0); } diff --git a/openair1/SIMULATION/LTE_PHY/mbmssim.c b/openair1/SIMULATION/LTE_PHY/mbmssim.c index 9910c97af838db34ec814a0019c3b9e036f622c6..65415e7c68b97633eff7557dfe51ffba935f70f5 100644 --- a/openair1/SIMULATION/LTE_PHY/mbmssim.c +++ b/openair1/SIMULATION/LTE_PHY/mbmssim.c @@ -36,7 +36,7 @@ #include "LAYER2/MAC/vars.h" #ifdef XFORMS -#include "PHY/TOOLS/lte_phy_scope.h" + #include "PHY/TOOLS/lte_phy_scope.h" #endif //XFORMS @@ -52,11 +52,8 @@ double cpuf; DCI1E_5MHz_2A_M10PRB_TDD_t DLSCH_alloc_pdu2_1E[2]; #define UL_RB_ALLOC 0x1ff; #define CCCH_RB_ALLOC computeRIV(eNB->frame_parms.N_RB_UL,0,2) -int main(int argc, char **argv) -{ - +int main(int argc, char **argv) { char c; - int i,l,l2,aa,aarx,k; double sigma2, sigma2_dB=0,SNR,snr0=-2.0,snr1=0.0; uint8_t snr1set=0; @@ -64,48 +61,34 @@ int main(int argc, char **argv) int **txdata; double s_re0[2*30720],s_im0[2*30720],s_re1[2*30720],s_im1[2*30720]; double r_re0[2*30720],r_im0[2*30720],r_re1[2*30720],r_im1[2*30720]; - double *s_re[2]={s_re0,s_re1},*s_im[2]={s_im0,s_im1},*r_re[2]={r_re0,r_re1},*r_im[2]={r_im0,r_im1}; + double *s_re[2]= {s_re0,s_re1},*s_im[2]= {s_im0,s_im1},*r_re[2]= {r_re0,r_re1},*r_im[2]= {r_im0,r_im1}; double iqim = 0.0; int subframe=1; char fname[40];//, vname[40]; uint8_t transmission_mode = 1,n_tx=1,n_rx=2; uint16_t Nid_cell=0; - FILE *fd; - int eNB_id = 0; unsigned char mcs=0,awgn_flag=0,round; - int n_frames=1; channel_desc_t *eNB2UE; uint32_t nsymb,tx_lev,tx_lev_dB; uint8_t extended_prefix_flag=1; LTE_DL_FRAME_PARMS *frame_parms; int hold_channel=0; - - uint16_t NB_RB=25; - int tdd_config=3; - SCM_t channel_model=MBSFN; - - unsigned char *input_buffer; unsigned short input_buffer_length; unsigned int ret; - unsigned int trials,errs[4]= {0,0,0,0}; //,round_trials[4]={0,0,0,0}; - uint8_t N_RB_DL=25,osf=1; uint32_t perfect_ce = 0; - lte_frame_type_t frame_type = FDD; - uint32_t Nsoft = 1827072; - /* -#ifdef XFORMS + #ifdef XFORMS FD_lte_phy_scope_ue *form_ue; char title[255]; @@ -113,114 +96,110 @@ int main(int argc, char **argv) form_ue = create_lte_phy_scope_ue(); sprintf (title, "LTE DL SCOPE UE"); fl_show_form (form_ue->lte_phy_scope_ue, FL_PLACE_HOTSPOT, FL_FULLBORDER, title); -#endif + #endif */ - cpuf = get_cpu_freq_GHz(); - logInit(); number_of_cards = 1; while ((c = getopt (argc, argv, "ahA:Cp:n:s:S:t:x:y:z:N:F:R:O:dm:i:Y")) != -1) { switch (c) { - case 'a': - awgn_flag=1; - break; - - case 'd': - frame_type = 0; - break; - - case 'n': - n_frames = atoi(optarg); - break; - - case 'm': - mcs=atoi(optarg); - break; - - case 's': - snr0 = atof(optarg); - msg("Setting SNR0 to %f\n",snr0); - break; - - case 'i': - input_snr_step = atof(optarg); - break; - - case 'S': - snr1 = atof(optarg); - snr1set=1; - msg("Setting SNR1 to %f\n",snr1); - break; - - case 'p': // subframe no; - subframe=atoi(optarg); - break; - - case 'z': - n_rx=atoi(optarg); - - if ((n_rx==0) || (n_rx>2)) { - msg("Unsupported number of rx antennas %d\n",n_rx); - exit(-1); - } - - break; - - case 'N': - Nid_cell = atoi(optarg); - break; - - case 'R': - N_RB_DL = atoi(optarg); + case 'a': + awgn_flag=1; + break; + + case 'd': + frame_type = 0; + break; + + case 'n': + n_frames = atoi(optarg); + break; + + case 'm': + mcs=atoi(optarg); + break; + + case 's': + snr0 = atof(optarg); + msg("Setting SNR0 to %f\n",snr0); + break; + + case 'i': + input_snr_step = atof(optarg); + break; + + case 'S': + snr1 = atof(optarg); + snr1set=1; + msg("Setting SNR1 to %f\n",snr1); + break; + + case 'p': // subframe no; + subframe=atoi(optarg); + break; + + case 'z': + n_rx=atoi(optarg); + + if ((n_rx==0) || (n_rx>2)) { + msg("Unsupported number of rx antennas %d\n",n_rx); + exit(-1); + } - if ((N_RB_DL!=6) && (N_RB_DL!=25) && (N_RB_DL!=50) && (N_RB_DL!=100)) { - printf("Unsupported Bandwidth %d\n",N_RB_DL); - exit(-1); - } + break; - break; + case 'N': + Nid_cell = atoi(optarg); + break; - case 'O': - osf = atoi(optarg); - break; + case 'R': + N_RB_DL = atoi(optarg); - case 'Y': - perfect_ce = 1; - break; + if ((N_RB_DL!=6) && (N_RB_DL!=25) && (N_RB_DL!=50) && (N_RB_DL!=100)) { + printf("Unsupported Bandwidth %d\n",N_RB_DL); + exit(-1); + } - default: - case 'h': - printf("%s -h(elp) -p(subframe) -N cell_id -g channel_model -n n_frames -t Delayspread -s snr0 -S snr1 -i snr increment -z RXant \n",argv[0]); - printf("-h This message\n"); - printf("-a Use AWGN Channel\n"); - printf("-p Use extended prefix mode\n"); - printf("-d Use TDD\n"); - printf("-n Number of frames to simulate\n"); - printf("-s Starting SNR, runs from SNR0 to SNR0 + 5 dB. If n_frames is 1 then just SNR is simulated\n"); - printf("-S Ending SNR, runs from SNR0 to SNR1\n"); - printf("-t Delay spread for multipath channel\n"); - printf("-g [A,B,C,D,E,F,G] Use 3GPP SCM (A,B,C,D) or 36-101 (E-EPA,F-EVA,G-ETU) models (ignores delay spread and Ricean factor)\n"); - printf("-x Transmission mode (1,2,6 for the moment)\n"); - printf("-y Number of TX antennas used in eNB\n"); - printf("-z Number of RX antennas used in UE\n"); - printf("-i Relative strength of first intefering eNB (in dB) - cell_id mod 3 = 1\n"); - printf("-j Relative strength of second intefering eNB (in dB) - cell_id mod 3 = 2\n"); - printf("-N Nid_cell\n"); - printf("-R N_RB_DL\n"); - printf("-O oversampling factor (1,2,4,8,16)\n"); - printf("-A Interpolation_filname Run with Abstraction to generate Scatter plot using interpolation polynomial in file\n"); - printf("-C Generate Calibration information for Abstraction (effective SNR adjustment to remove Pe bias w.r.t. AWGN)\n"); - printf("-f Output filename (.txt format) for Pe/SNR results\n"); - printf("-F Input filename (.txt format) for RX conformance testing\n"); - exit (-1); - break; + break; + + case 'O': + osf = atoi(optarg); + break; + + case 'Y': + perfect_ce = 1; + break; + + default: + case 'h': + printf("%s -h(elp) -p(subframe) -N cell_id -g channel_model -n n_frames -t Delayspread -s snr0 -S snr1 -i snr increment -z RXant \n",argv[0]); + printf("-h This message\n"); + printf("-a Use AWGN Channel\n"); + printf("-p Use extended prefix mode\n"); + printf("-d Use TDD\n"); + printf("-n Number of frames to simulate\n"); + printf("-s Starting SNR, runs from SNR0 to SNR0 + 5 dB. If n_frames is 1 then just SNR is simulated\n"); + printf("-S Ending SNR, runs from SNR0 to SNR1\n"); + printf("-t Delay spread for multipath channel\n"); + printf("-g [A,B,C,D,E,F,G] Use 3GPP SCM (A,B,C,D) or 36-101 (E-EPA,F-EVA,G-ETU) models (ignores delay spread and Ricean factor)\n"); + printf("-x Transmission mode (1,2,6 for the moment)\n"); + printf("-y Number of TX antennas used in eNB\n"); + printf("-z Number of RX antennas used in UE\n"); + printf("-i Relative strength of first intefering eNB (in dB) - cell_id mod 3 = 1\n"); + printf("-j Relative strength of second intefering eNB (in dB) - cell_id mod 3 = 2\n"); + printf("-N Nid_cell\n"); + printf("-R N_RB_DL\n"); + printf("-O oversampling factor (1,2,4,8,16)\n"); + printf("-A Interpolation_filname Run with Abstraction to generate Scatter plot using interpolation polynomial in file\n"); + printf("-C Generate Calibration information for Abstraction (effective SNR adjustment to remove Pe bias w.r.t. AWGN)\n"); + printf("-f Output filename (.txt format) for Pe/SNR results\n"); + printf("-F Input filename (.txt format) for RX conformance testing\n"); + exit (-1); + break; } } - - if (awgn_flag == 1) channel_model = AWGN; @@ -229,7 +208,6 @@ int main(int argc, char **argv) if ((subframe == 0) || (subframe == 5) || // TDD and FDD SFn 0,5; ((frame_type == FDD) && ((subframe == 4) || (subframe == 9))) || // FDD SFn 4,9; ((frame_type == TDD ) && ((subframe<3) || (subframe==6)))) { // TDD SFn 1,2,6; - printf("Illegal subframe %d for eMBMS transmission (frame_type %d)\n",subframe,frame_type); exit(-1); } @@ -239,16 +217,16 @@ int main(int argc, char **argv) lte_param_init(n_tx, n_tx, - n_rx, - transmission_mode, - extended_prefix_flag, - frame_type, - Nid_cell, - tdd_config, - N_RB_DL, - 0, - osf, - perfect_ce); + n_rx, + transmission_mode, + extended_prefix_flag, + frame_type, + Nid_cell, + tdd_config, + N_RB_DL, + 0, + osf, + perfect_ce); if (snr1set==0) { if (n_frames==1) @@ -258,7 +236,6 @@ int main(int argc, char **argv) } printf("SNR0 %f, SNR1 %f\n",snr0,snr1); - frame_parms = &eNB->frame_parms; if (awgn_flag == 0) @@ -270,7 +247,6 @@ int main(int argc, char **argv) printf("Cannot open %s, check permissions\n",fname); exit(-1); } - if (awgn_flag==0) fprintf(fd,"SNR_%d_%d=[];errs_mch_%d_%d=[];mch_trials_%d_%d=[];\n", @@ -284,23 +260,18 @@ int main(int argc, char **argv) mcs,N_RB_DL); fflush(fd); - txdata = eNB->common_vars.txdata[0]; - nsymb = 12; - printf("FFT Size %d, Extended Prefix %d, Samples per subframe %d, Symbols per subframe %d, AWGN %d\n",NUMBER_OF_OFDM_CARRIERS, frame_parms->Ncp,frame_parms->samples_per_tti,nsymb,awgn_flag); - eNB2UE = new_channel_desc_scm(eNB->frame_parms.nb_antennas_tx, UE->frame_parms.nb_antennas_rx, channel_model, - N_RB2sampling_rate(eNB->frame_parms.N_RB_DL), - N_RB2channel_bandwidth(eNB->frame_parms.N_RB_DL), + N_RB2sampling_rate(eNB->frame_parms.N_RB_DL), + N_RB2channel_bandwidth(eNB->frame_parms.N_RB_DL), 0, 0, 0); - // Create transport channel structures for 2 transport blocks (MIMO) eNB->dlsch_MCH = new_eNB_dlsch(1,8,Nsoft,N_RB_DL,0,&eNB->frame_parms); @@ -310,7 +281,6 @@ int main(int argc, char **argv) } UE->dlsch_MCH[0] = new_ue_dlsch(1,8,Nsoft,MAX_TURBO_ITERATIONS_MBSFN,N_RB_DL,0); - eNB->frame_parms.num_MBSFN_config = 1; eNB->frame_parms.MBSFN_config[0].radioframeAllocationPeriod = 0; eNB->frame_parms.MBSFN_config[0].radioframeAllocationOffset = 0; @@ -321,7 +291,6 @@ int main(int argc, char **argv) UE->frame_parms.MBSFN_config[0].radioframeAllocationOffset = 0; UE->frame_parms.MBSFN_config[0].fourFrames_flag = 0; UE->frame_parms.MBSFN_config[0].mbsfn_SubframeConfig=0xff; // activate all possible subframes - fill_eNB_dlsch_MCH(eNB,mcs,1,0); fill_UE_dlsch_MCH(UE,mcs,1,0,0); @@ -333,7 +302,6 @@ int main(int argc, char **argv) exit(-1); } - input_buffer_length = eNB->dlsch_MCH->harq_processes[0]->TBS/8; input_buffer = (unsigned char *)malloc(input_buffer_length+4); memset(input_buffer,0,input_buffer_length+4); @@ -342,14 +310,12 @@ int main(int argc, char **argv) input_buffer[i]= (unsigned char)(taus()&0xff); } - snr_step = input_snr_step; for (SNR=snr0; SNR<snr1; SNR+=snr_step) { UE->proc.proc_rxtx[0].frame_tx=0; eNB->proc.proc_rxtx[0].frame_tx=0; eNB->proc.proc_rxtx[0].subframe_tx=subframe; - errs[0]=0; errs[1]=0; errs[2]=0; @@ -365,14 +331,11 @@ int main(int argc, char **argv) // printf("Trial %d\n",trials); fflush(stdout); round=0; - //if (trials%100==0) //eNB2UE[0]->first_run = 1; eNB2UE->first_run = 1; memset(&eNB->common_vars.txdataF[0][0][0],0,FRAME_LENGTH_COMPLEX_SAMPLES_NO_PREFIX*sizeof(int32_t)); generate_mch(eNB,&eNB->proc.proc_rxtx[0],input_buffer); - - PHY_ofdm_mod(eNB->common_vars.txdataF[0][0], // input, txdata[0], // output frame_parms->ofdm_symbol_size, @@ -382,7 +345,7 @@ int main(int argc, char **argv) if (n_frames==1) { LOG_M("txsigF0.m","txsF0", &eNB->common_vars.txdataF[0][0][subframe*nsymb*eNB->frame_parms.ofdm_symbol_size], - nsymb*eNB->frame_parms.ofdm_symbol_size,1,1); + nsymb*eNB->frame_parms.ofdm_symbol_size,1,1); //if (eNB->frame_parms.nb_antennas_tx>1) //LOG_M("txsigF1.m","txsF1", &eNB->lte_eNB_common_vars.txdataF[eNB_id][1][subframe*nsymb*eNB->frame_parms.ofdm_symbol_size],nsymb*eNB->frame_parms.ofdm_symbol_size,1,1); } @@ -400,11 +363,9 @@ int main(int argc, char **argv) if (n_frames==1) { printf("tx_lev = %d (%d dB)\n",tx_lev,tx_lev_dB); // LOG_M("txsig0.m","txs0", &eNB->common_vars.txdata[0][0][subframe* eNB->frame_parms.samples_per_tti], - // eNB->frame_parms.samples_per_tti,1,1); } - for (i=0; i<2*frame_parms->samples_per_tti; i++) { for (aa=0; aa<eNB->frame_parms.nb_antennas_tx; aa++) { s_re[aa][i] = ((double)(((short *)eNB->common_vars.txdata[0][aa]))[(2*subframe*UE->frame_parms.samples_per_tti) + (i<<1)]); @@ -415,7 +376,6 @@ int main(int argc, char **argv) //Multipath channel multipath_channel(eNB2UE,s_re,s_im,r_re,r_im, 2*frame_parms->samples_per_tti,hold_channel); - //AWGN sigma2_dB = 10*log10((double)tx_lev) +10*log10((double)eNB->frame_parms.ofdm_symbol_size/(NB_RB*12)) - SNR; sigma2 = pow(10,sigma2_dB/10); @@ -426,67 +386,70 @@ int main(int argc, char **argv) for (i=0; i<2*frame_parms->samples_per_tti; i++) { for (aa=0; aa<eNB->frame_parms.nb_antennas_rx; aa++) { //printf("s_re[0][%d]=> %f , r_re[0][%d]=> %f\n",i,s_re[aa][i],i,r_re[aa][i]); - ((short*) UE->common_vars.rxdata[aa])[(2*subframe*UE->frame_parms.samples_per_tti)+2*i] = + ((short *) UE->common_vars.rxdata[aa])[(2*subframe*UE->frame_parms.samples_per_tti)+2*i] = (short) (r_re[aa][i] + sqrt(sigma2/2)*gaussdouble(0.0,1.0)); - ((short*) UE->common_vars.rxdata[aa])[(2*subframe*UE->frame_parms.samples_per_tti)+2*i+1] = + ((short *) UE->common_vars.rxdata[aa])[(2*subframe*UE->frame_parms.samples_per_tti)+2*i+1] = (short) (r_im[aa][i] + (iqim*r_re[aa][i]) + sqrt(sigma2/2)*gaussdouble(0.0,1.0)); } } for (l=2; l<12; l++) { - slot_fep_mbsfn(UE, l, subframe%10, 0, 0); - if (UE->perfect_ce==1) { - // fill in perfect channel estimates - freq_channel(eNB2UE,UE->frame_parms.N_RB_DL,12*UE->frame_parms.N_RB_DL + 1); - for(k=0; k<NUMBER_OF_eNB_MAX; k++) { - for(aa=0; aa<frame_parms->nb_antennas_tx; aa++) { - for (aarx=0; aarx<frame_parms->nb_antennas_rx; aarx++) { - for (i=0; i<frame_parms->N_RB_DL*12; i++) { - ((int16_t *) UE->common_vars.common_vars_rx_data_per_thread[subframe&0x1].dl_ch_estimates[k][(aa<<1)+aarx])[2*i+(l*frame_parms->ofdm_symbol_size+LTE_CE_FILTER_LENGTH)*2]=(int16_t)(eNB2UE->chF[aarx+(aa*frame_parms->nb_antennas_rx)][i].x*AMP); - ((int16_t *) UE->common_vars.common_vars_rx_data_per_thread[subframe&0x1].dl_ch_estimates[k][(aa<<1)+aarx])[2*i+1+(l*frame_parms->ofdm_symbol_size+LTE_CE_FILTER_LENGTH)*2]=(int16_t)(eNB2UE->chF[aarx+(aa*frame_parms->nb_antennas_rx)][i].y*AMP); - } - } - } - } - } - - if (l==6) - for (l2=2;l2<7;l2++) - rx_pmch(UE, - 0, - subframe%10, - l2); - if (l==6) - for (l2=2;l2<7;l2++) - rx_pmch(UE, - 0, - subframe%10, - l2); - if (l==11) - for (l2=7;l2<12;l2++) - rx_pmch(UE, - 0, - subframe%10, - l2); + + if (UE->perfect_ce==1) { + // fill in perfect channel estimates + freq_channel(eNB2UE,UE->frame_parms.N_RB_DL,12*UE->frame_parms.N_RB_DL + 1); + + for(k=0; k<NUMBER_OF_eNB_MAX; k++) { + for(aa=0; aa<frame_parms->nb_antennas_tx; aa++) { + for (aarx=0; aarx<frame_parms->nb_antennas_rx; aarx++) { + for (i=0; i<frame_parms->N_RB_DL*12; i++) { + ((int16_t *) UE->common_vars.common_vars_rx_data_per_thread[subframe&0x1].dl_ch_estimates[k][(aa<<1)+aarx])[2*i+(l*frame_parms->ofdm_symbol_size+LTE_CE_FILTER_LENGTH)*2]=(int16_t)(eNB2UE->chF[aarx+ + (aa*frame_parms->nb_antennas_rx)][i].x*AMP); + ((int16_t *) UE->common_vars.common_vars_rx_data_per_thread[subframe&0x1].dl_ch_estimates[k][(aa<<1)+aarx])[2*i+1+(l*frame_parms->ofdm_symbol_size+LTE_CE_FILTER_LENGTH)*2]=(int16_t)(eNB2UE->chF[aarx+ + (aa*frame_parms->nb_antennas_rx)][i].y*AMP); + } + } + } + } + } + + if (l==6) + for (l2=2; l2<7; l2++) + rx_pmch(UE, + 0, + subframe%10, + l2); + + if (l==6) + for (l2=2; l2<7; l2++) + rx_pmch(UE, + 0, + subframe%10, + l2); + + if (l==11) + for (l2=7; l2<12; l2++) + rx_pmch(UE, + 0, + subframe%10, + l2); } UE->dlsch_MCH[0]->harq_processes[0]->G = get_G(&UE->frame_parms, - UE->dlsch_MCH[0]->harq_processes[0]->nb_rb, - UE->dlsch_MCH[0]->harq_processes[0]->rb_alloc_even, - get_Qm(UE->dlsch_MCH[0]->harq_processes[0]->mcs), - 1,2, - UE->proc.proc_rxtx[0].frame_tx,subframe,0); + UE->dlsch_MCH[0]->harq_processes[0]->nb_rb, + UE->dlsch_MCH[0]->harq_processes[0]->rb_alloc_even, + get_Qm(UE->dlsch_MCH[0]->harq_processes[0]->mcs), + 1,2, + UE->proc.proc_rxtx[0].frame_tx,subframe,0); UE->dlsch_MCH[0]->harq_processes[0]->Qm = get_Qm(UE->dlsch_MCH[0]->harq_processes[0]->mcs); - dlsch_unscrambling(&UE->frame_parms,1,UE->dlsch_MCH[0], UE->dlsch_MCH[0]->harq_processes[0]->G, UE->pdsch_vars_MCH[0]->llr[0],0,subframe<<1); - ret = dlsch_decoding(UE, UE->pdsch_vars_MCH[0]->llr[0], &UE->frame_parms, @@ -497,7 +460,7 @@ int main(int argc, char **argv) 0,0,0); if (n_frames==1) - printf("MCH decoding returns %d\n",ret); + printf("MCH decoding returns %u\n",ret); if (ret == (1+UE->dlsch_MCH[0]->max_turbo_iterations)) errs[0]++; @@ -506,15 +469,15 @@ int main(int argc, char **argv) eNB->proc.proc_rxtx[0].frame_tx++; } - printf("errors %d/%d (Pe %e)\n",errs[round],trials,(double)errs[round]/trials); + printf("errors %u/%u (Pe %e)\n",errs[round],trials,(double)errs[round]/trials); if (awgn_flag==0) - fprintf(fd,"SNR_%d_%d = [SNR_%d_%d %f]; errs_mch_%d_%d =[errs_mch_%d_%d %d]; mch_trials_%d_%d =[mch_trials_%d_%d %d];\n", + fprintf(fd,"SNR_%d_%d = [SNR_%d_%d %f]; errs_mch_%d_%d =[errs_mch_%d_%d %u]; mch_trials_%d_%d =[mch_trials_%d_%d %u];\n", mcs,N_RB_DL,mcs,N_RB_DL,SNR, mcs,N_RB_DL,mcs,N_RB_DL,errs[0], mcs,N_RB_DL,mcs,N_RB_DL,trials); else - fprintf(fd,"SNR_awgn_%d = [SNR_awgn_%d %f]; errs_mch_awgn_%d =[errs_mch_awgn_%d %d]; mch_trials_awgn_%d =[mch_trials_awgn_%d %d];\n", + fprintf(fd,"SNR_awgn_%d = [SNR_awgn_%d %f]; errs_mch_awgn_%d =[errs_mch_awgn_%d %u]; mch_trials_awgn_%d =[mch_trials_awgn_%d %u];\n", N_RB_DL,N_RB_DL,SNR, N_RB_DL,N_RB_DL,errs[0], N_RB_DL,N_RB_DL,trials); @@ -525,7 +488,6 @@ int main(int argc, char **argv) break; } - if (n_frames==1) { printf("Dumping PMCH files ( G %d)\n",UE->dlsch_MCH[0]->harq_processes[0]->G); dump_mch(UE,0, @@ -536,9 +498,7 @@ int main(int argc, char **argv) printf("Freeing dlsch structures\n"); free_eNB_dlsch(eNB->dlsch_MCH); free_ue_dlsch(UE->dlsch_MCH[0]); - fclose(fd); - return(0); } diff --git a/openair1/SIMULATION/LTE_PHY/pbchsim.c b/openair1/SIMULATION/LTE_PHY/pbchsim.c index f44ed7b3a21665ec1bd40ba2b3e7fa11d30fbfef..00ad03c52dc8f0ffb038fe2b98328087bd6787e2 100644 --- a/openair1/SIMULATION/LTE_PHY/pbchsim.c +++ b/openair1/SIMULATION/LTE_PHY/pbchsim.c @@ -37,7 +37,7 @@ #include "LAYER2/MAC/vars.h" #ifdef XFORMS -#include "PHY/TOOLS/lte_phy_scope.h" + #include "PHY/TOOLS/lte_phy_scope.h" #endif #include "OCG_vars.h" @@ -58,11 +58,8 @@ int32_t dummy2[2048*14]; int32_t dummy3[2048*14]; -int main(int argc, char **argv) -{ - +int main(int argc, char **argv) { char c; - int i,l,aa; double sigma2, sigma2_dB=0,SNR,snr0=-2.0,snr1; uint8_t snr1set=0; @@ -81,127 +78,119 @@ int main(int argc, char **argv) int trial, n_trials, ntrials=1, n_errors,n_errors2,n_alamouti; uint8_t transmission_mode = 1,n_tx=1,n_rx=1; uint16_t Nid_cell=0; - int n_frames=1; channel_desc_t *eNB2UE,*eNB2UE1 = NULL,*eNB2UE2 = NULL; uint32_t nsymb,tx_lev,tx_lev1 = 0,tx_lev2 = 0; uint8_t extended_prefix_flag=0; int8_t interf1=-21,interf2=-21; LTE_DL_FRAME_PARMS *frame_parms; - FILE *input_fd=NULL,*pbch_file_fd=NULL; char input_val_str[50],input_val_str2[50]; // double input_val1,input_val2; // uint16_t amask=0; uint8_t frame_mod4,num_pdcch_symbols = 0; uint16_t NB_RB=25; - SCM_t channel_model=AWGN;//Rayleigh1_anticorr; - //DCI_ALLOC_t dci_alloc[8]; uint8_t abstraction_flag=0;//,calibration_flag=0; double pbch_sinr; int pbch_tx_ant; uint8_t N_RB_DL=25,osf=1; - unsigned char frame_type = 0; unsigned char pbch_phase = 0; - #ifdef XFORMS FD_lte_phy_scope_ue *form_ue; char title[255]; #endif - cpuf = get_cpu_freq_GHz(); - logInit(); number_of_cards = 1; while ((c = getopt (argc, argv, "f:hA:pf:g:i:j:n:s:S:t:x:y:z:N:F:GR:O:dP:")) != -1) { switch (c) { - case 'f': - write_output_file=1; - output_fd = fopen(optarg,"w"); + case 'f': + write_output_file=1; + output_fd = fopen(optarg,"w"); - if (output_fd==NULL) { - printf("Error opening %s\n",optarg); - exit(-1); - } - - break; - - case 'd': - frame_type = 1; - break; + if (output_fd==NULL) { + printf("Error opening %s\n",optarg); + exit(-1); + } - case 'g': - switch((char)*optarg) { - case 'A': - channel_model=SCM_A; break; - case 'B': - channel_model=SCM_B; + case 'd': + frame_type = 1; break; - case 'C': - channel_model=SCM_C; - break; + case 'g': + switch((char)*optarg) { + case 'A': + channel_model=SCM_A; + break; - case 'D': - channel_model=SCM_D; - break; + case 'B': + channel_model=SCM_B; + break; - case 'E': - channel_model=EPA; - break; + case 'C': + channel_model=SCM_C; + break; - case 'F': - channel_model=EVA; - break; + case 'D': + channel_model=SCM_D; + break; - case 'G': - channel_model=ETU; - break; + case 'E': + channel_model=EPA; + break; - default: - msg("Unsupported channel model!\n"); - exit(-1); - } + case 'F': + channel_model=EVA; + break; - break; + case 'G': + channel_model=ETU; + break; - case 'i': - interf1=atoi(optarg); - break; + default: + msg("Unsupported channel model!\n"); + exit(-1); + } - case 'j': - interf2=atoi(optarg); - break; + break; - case 'n': - n_frames = atoi(optarg); - break; + case 'i': + interf1=atoi(optarg); + break; - case 's': - snr0 = atof(optarg); - msg("Setting SNR0 to %f\n",snr0); - break; + case 'j': + interf2=atoi(optarg); + break; - case 'S': - snr1 = atof(optarg); - snr1set=1; - msg("Setting SNR1 to %f\n",snr1); - break; + case 'n': + n_frames = atoi(optarg); + break; + + case 's': + snr0 = atof(optarg); + msg("Setting SNR0 to %f\n",snr0); + break; + + case 'S': + snr1 = atof(optarg); + snr1set=1; + msg("Setting SNR1 to %f\n",snr1); + break; /* case 't': Td= atof(optarg); break; */ - case 'p': - extended_prefix_flag=1; - break; + case 'p': + extended_prefix_flag=1; + break; /* case 'r': @@ -212,111 +201,111 @@ int main(int argc, char **argv) } break; */ - case 'x': - transmission_mode=atoi(optarg); - - if ((transmission_mode!=1) && - (transmission_mode!=2) && - (transmission_mode!=6)) { - msg("Unsupported transmission mode %d\n",transmission_mode); - exit(-1); - } + case 'x': + transmission_mode=atoi(optarg); + + if ((transmission_mode!=1) && + (transmission_mode!=2) && + (transmission_mode!=6)) { + msg("Unsupported transmission mode %d\n",transmission_mode); + exit(-1); + } - break; + break; - case 'y': - n_tx=atoi(optarg); + case 'y': + n_tx=atoi(optarg); - if ((n_tx==0) || (n_tx>2)) { - msg("Unsupported number of tx antennas %d\n",n_tx); - exit(-1); - } + if ((n_tx==0) || (n_tx>2)) { + msg("Unsupported number of tx antennas %d\n",n_tx); + exit(-1); + } - break; + break; - case 'z': - n_rx=atoi(optarg); + case 'z': + n_rx=atoi(optarg); - if ((n_rx==0) || (n_rx>2)) { - msg("Unsupported number of rx antennas %d\n",n_rx); - exit(-1); - } - - break; + if ((n_rx==0) || (n_rx>2)) { + msg("Unsupported number of rx antennas %d\n",n_rx); + exit(-1); + } - case 'A': - abstraction_flag=1; - ntrials=10000; - msg("Running Abstraction test\n"); - pbch_file_fd=fopen(optarg,"r"); + break; - if (pbch_file_fd==NULL) { - printf("Problem with filename %s\n",optarg); - exit(-1); - } + case 'A': + abstraction_flag=1; + ntrials=10000; + msg("Running Abstraction test\n"); + pbch_file_fd=fopen(optarg,"r"); + + if (pbch_file_fd==NULL) { + printf("Problem with filename %s\n",optarg); + exit(-1); + } - break; + break; // case 'C': // calibration_flag=1; // msg("Running Abstraction calibration for Bias removal\n"); // break; - case 'N': - Nid_cell = atoi(optarg); - break; + case 'N': + Nid_cell = atoi(optarg); + break; - case 'R': - N_RB_DL = atoi(optarg); - break; + case 'R': + N_RB_DL = atoi(optarg); + break; - case 'O': - osf = atoi(optarg); - break; + case 'O': + osf = atoi(optarg); + break; - case 'F': - input_fd = fopen(optarg,"r"); + case 'F': + input_fd = fopen(optarg,"r"); - if (input_fd==NULL) { - printf("Problem with filename %s\n",optarg); - exit(-1); - } + if (input_fd==NULL) { + printf("Problem with filename %s\n",optarg); + exit(-1); + } - break; + break; - case 'P': - pbch_phase = atoi(optarg); + case 'P': + pbch_phase = atoi(optarg); - if (pbch_phase>3) - printf("Illegal PBCH phase (0-3) got %d\n",pbch_phase); + if (pbch_phase>3) + printf("Illegal PBCH phase (0-3) got %d\n",pbch_phase); - break; + break; - default: - case 'h': - printf("%s -h(elp) -p(extended_prefix) -N cell_id -f output_filename -F input_filename -g channel_model -n n_frames -t Delayspread -s snr0 -S snr1 -x transmission_mode -y TXant -z RXant -i Intefrence0 -j Interference1 -A interpolation_file -C(alibration offset dB) -N CellId\n", - argv[0]); - printf("-h This message\n"); - printf("-p Use extended prefix mode\n"); - printf("-d Use TDD\n"); - printf("-n Number of frames to simulate\n"); - printf("-s Starting SNR, runs from SNR0 to SNR0 + 5 dB. If n_frames is 1 then just SNR is simulated\n"); - printf("-S Ending SNR, runs from SNR0 to SNR1\n"); - printf("-t Delay spread for multipath channel\n"); - printf("-g [A,B,C,D,E,F,G] Use 3GPP SCM (A,B,C,D) or 36-101 (E-EPA,F-EVA,G-ETU) models (ignores delay spread and Ricean factor)\n"); - printf("-x Transmission mode (1,2,6 for the moment)\n"); - printf("-y Number of TX antennas used in eNB\n"); - printf("-z Number of RX antennas used in UE\n"); - printf("-i Relative strength of first intefering eNB (in dB) - cell_id mod 3 = 1\n"); - printf("-j Relative strength of second intefering eNB (in dB) - cell_id mod 3 = 2\n"); - printf("-N Nid_cell\n"); - printf("-R N_RB_DL\n"); - printf("-O oversampling factor (1,2,4,8,16)\n"); - printf("-A Interpolation_filname Run with Abstraction to generate Scatter plot using interpolation polynomial in file\n"); - // printf("-C Generate Calibration information for Abstraction (effective SNR adjustment to remove Pe bias w.r.t. AWGN)\n"); - printf("-f Output filename (.txt format) for Pe/SNR results\n"); - printf("-F Input filename (.txt format) for RX conformance testing\n"); - exit (-1); - break; + default: + case 'h': + printf("%s -h(elp) -p(extended_prefix) -N cell_id -f output_filename -F input_filename -g channel_model -n n_frames -t Delayspread -s snr0 -S snr1 -x transmission_mode -y TXant -z RXant -i Intefrence0 -j Interference1 -A interpolation_file -C(alibration offset dB) -N CellId\n", + argv[0]); + printf("-h This message\n"); + printf("-p Use extended prefix mode\n"); + printf("-d Use TDD\n"); + printf("-n Number of frames to simulate\n"); + printf("-s Starting SNR, runs from SNR0 to SNR0 + 5 dB. If n_frames is 1 then just SNR is simulated\n"); + printf("-S Ending SNR, runs from SNR0 to SNR1\n"); + printf("-t Delay spread for multipath channel\n"); + printf("-g [A,B,C,D,E,F,G] Use 3GPP SCM (A,B,C,D) or 36-101 (E-EPA,F-EVA,G-ETU) models (ignores delay spread and Ricean factor)\n"); + printf("-x Transmission mode (1,2,6 for the moment)\n"); + printf("-y Number of TX antennas used in eNB\n"); + printf("-z Number of RX antennas used in UE\n"); + printf("-i Relative strength of first intefering eNB (in dB) - cell_id mod 3 = 1\n"); + printf("-j Relative strength of second intefering eNB (in dB) - cell_id mod 3 = 2\n"); + printf("-N Nid_cell\n"); + printf("-R N_RB_DL\n"); + printf("-O oversampling factor (1,2,4,8,16)\n"); + printf("-A Interpolation_filname Run with Abstraction to generate Scatter plot using interpolation polynomial in file\n"); + // printf("-C Generate Calibration information for Abstraction (effective SNR adjustment to remove Pe bias w.r.t. AWGN)\n"); + printf("-f Output filename (.txt format) for Pe/SNR results\n"); + printf("-F Input filename (.txt format) for RX conformance testing\n"); + exit (-1); + break; } } @@ -324,7 +313,6 @@ int main(int argc, char **argv) n_tx=2; lte_param_init(n_tx, n_tx,n_rx,transmission_mode,extended_prefix_flag,frame_type,Nid_cell,3,N_RB_DL,0,osf,0); - eNB1 = malloc(sizeof(PHY_VARS_eNB)); eNB2 = malloc(sizeof(PHY_VARS_eNB)); UE->measurements.n_adj_cells=2; @@ -334,19 +322,16 @@ int main(int argc, char **argv) for (i=0; i<3; i++) lte_gold(&eNB->frame_parms,UE->lte_gold_table[i],Nid_cell+i); - memcpy((void*)&eNB1->frame_parms,(void*)&eNB->frame_parms,sizeof(LTE_DL_FRAME_PARMS)); + memcpy((void *)&eNB1->frame_parms,(void *)&eNB->frame_parms,sizeof(LTE_DL_FRAME_PARMS)); eNB1->frame_parms.Nid_cell=Nid_cell+1; eNB1->frame_parms.nushift=(Nid_cell+1)%6; eNB1->Mod_id=1; - - memcpy((void*)&eNB2->frame_parms,(void*)&eNB->frame_parms,sizeof(LTE_DL_FRAME_PARMS)); + memcpy((void *)&eNB2->frame_parms,(void *)&eNB->frame_parms,sizeof(LTE_DL_FRAME_PARMS)); eNB2->frame_parms.Nid_cell=Nid_cell+2; eNB2->frame_parms.nushift=(Nid_cell+2)%6; eNB2->Mod_id=2; - phy_init_lte_eNB(eNB1,0,0); phy_init_lte_eNB(eNB2,0,0); - #ifdef XFORMS fl_initialize (&argc, argv, NULL, 0, 0); form_ue = create_lte_phy_scope_ue(); @@ -362,38 +347,27 @@ int main(int argc, char **argv) } printf("SNR0 %f, SNR1 %f\n",snr0,snr1); - frame_parms = &eNB->frame_parms; - - - txdata = eNB->common_vars.txdata[0]; txdata1 = eNB1->common_vars.txdata[0]; txdata2 = eNB2->common_vars.txdata[0]; - - - s_re = malloc(2*sizeof(double*)); - s_im = malloc(2*sizeof(double*)); - s_re1 = malloc(2*sizeof(double*)); - s_im1 = malloc(2*sizeof(double*)); - s_re2 = malloc(2*sizeof(double*)); - s_im2 = malloc(2*sizeof(double*)); - r_re = malloc(2*sizeof(double*)); - r_im = malloc(2*sizeof(double*)); - r_re1 = malloc(2*sizeof(double*)); - r_im1 = malloc(2*sizeof(double*)); - r_re2 = malloc(2*sizeof(double*)); - r_im2 = malloc(2*sizeof(double*)); - + s_re = malloc(2*sizeof(double *)); + s_im = malloc(2*sizeof(double *)); + s_re1 = malloc(2*sizeof(double *)); + s_im1 = malloc(2*sizeof(double *)); + s_re2 = malloc(2*sizeof(double *)); + s_im2 = malloc(2*sizeof(double *)); + r_re = malloc(2*sizeof(double *)); + r_im = malloc(2*sizeof(double *)); + r_re1 = malloc(2*sizeof(double *)); + r_im1 = malloc(2*sizeof(double *)); + r_re2 = malloc(2*sizeof(double *)); + r_im2 = malloc(2*sizeof(double *)); nsymb = (frame_parms->Ncp == 0) ? 14 : 12; - printf("FFT Size %d, Extended Prefix %d, Samples per subframe %d, Symbols per subframe %d, interf (%d,%d)\n",NUMBER_OF_OFDM_CARRIERS, frame_parms->Ncp,frame_parms->samples_per_tti,nsymb,interf1,interf2); - printf("eNB1->common_vars.txdataF[0][0] = %p\n", eNB1->common_vars.txdataF[0][0]); - - DLSCH_alloc_pdu2.rah = 0; DLSCH_alloc_pdu2.rballoc = DLSCH_RB_ALLOC; DLSCH_alloc_pdu2.TPC = 0; @@ -405,12 +379,11 @@ int main(int argc, char **argv) DLSCH_alloc_pdu2.rv1 = 0; // Forget second codeword DLSCH_alloc_pdu2.tpmi = (transmission_mode==6 ? 5 : 0) ; // precoding - eNB2UE = new_channel_desc_scm(eNB->frame_parms.nb_antennas_tx, UE->frame_parms.nb_antennas_rx, channel_model, - N_RB2sampling_rate(eNB->frame_parms.N_RB_DL), - N_RB2channel_bandwidth(eNB->frame_parms.N_RB_DL), + N_RB2sampling_rate(eNB->frame_parms.N_RB_DL), + N_RB2channel_bandwidth(eNB->frame_parms.N_RB_DL), 0, 0, 0); @@ -419,8 +392,8 @@ int main(int argc, char **argv) eNB2UE1 = new_channel_desc_scm(eNB->frame_parms.nb_antennas_tx, UE->frame_parms.nb_antennas_rx, channel_model, - N_RB2sampling_rate(eNB->frame_parms.N_RB_DL), - N_RB2channel_bandwidth(eNB->frame_parms.N_RB_DL), + N_RB2sampling_rate(eNB->frame_parms.N_RB_DL), + N_RB2channel_bandwidth(eNB->frame_parms.N_RB_DL), 0, 4, 0); @@ -429,20 +402,18 @@ int main(int argc, char **argv) eNB2UE2 = new_channel_desc_scm(eNB->frame_parms.nb_antennas_tx, UE->frame_parms.nb_antennas_rx, channel_model, - N_RB2sampling_rate(eNB->frame_parms.N_RB_DL), - N_RB2channel_bandwidth(eNB->frame_parms.N_RB_DL), + N_RB2sampling_rate(eNB->frame_parms.N_RB_DL), + N_RB2channel_bandwidth(eNB->frame_parms.N_RB_DL), 0, 8, 0); - if (eNB2UE==NULL) { msg("Problem generating channel model. Exiting.\n"); exit(-1); } for (i=0; i<2; i++) { - s_re[i] = malloc(FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double)); bzero(s_re[i],FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double)); s_im[i] = malloc(FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double)); @@ -455,7 +426,6 @@ int main(int argc, char **argv) bzero(s_re2[i],FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double)); s_im2[i] = malloc(FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double)); bzero(s_im2[i],FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double)); - r_re[i] = malloc(FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double)); bzero(r_re[i],FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double)); r_im[i] = malloc(FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double)); @@ -487,7 +457,6 @@ int main(int argc, char **argv) } if (input_fd==NULL) { - // for (i=0;i<6;i++) // pbch_pdu[i] = i; pbch_pdu[0]=100; @@ -515,7 +484,6 @@ int main(int argc, char **argv) &eNB->frame_parms, (eNB->frame_parms.Ncp==0) ? 5 : 4, 10); - } else { generate_sss(eNB->common_vars.txdataF[0], AMP, @@ -537,8 +505,6 @@ int main(int argc, char **argv) &eNB->frame_parms, 2, 12); - - } /* @@ -552,16 +518,12 @@ int main(int argc, char **argv) dci_alloc[1].L = 3; dci_alloc[1].rnti = 0x1234; */ - printf("Generating PBCH for mode1_flag = %d\n", eNB->frame_parms.mode1_flag); - - generate_pilots(eNB, eNB->common_vars.txdataF[0], AMP, LTE_NUMBER_OF_SUBFRAMES_PER_FRAME); - /* num_pdcch_symbols = generate_dci_top(1, dci_alloc, @@ -572,7 +534,6 @@ int main(int argc, char **argv) 0); */ - if (num_pdcch_symbols<3) { printf("Less than 3 pdcch symbols\n"); // exit(-1); @@ -584,7 +545,7 @@ int main(int argc, char **argv) dummybuf[2] = dummy2; dummybuf[3] = dummy3; generate_pbch(&eNB->pbch, - (int32_t**)dummybuf, + (int32_t **)dummybuf, AMP, &eNB->frame_parms, pbch_pdu, @@ -618,15 +579,12 @@ int main(int argc, char **argv) eNB1->common_vars.txdataF[0], AMP, LTE_NUMBER_OF_SUBFRAMES_PER_FRAME); - - generate_pbch(&eNB1->pbch, eNB1->common_vars.txdataF[0], AMP, &eNB1->frame_parms, pbch_pdu, 0); - } if (interf2>-20) { @@ -638,27 +596,19 @@ int main(int argc, char **argv) 0); */ - - - generate_pilots(eNB2, eNB2->common_vars.txdataF[0], AMP, LTE_NUMBER_OF_SUBFRAMES_PER_FRAME); - - generate_pbch(&eNB2->pbch, eNB2->common_vars.txdataF[0], AMP, &eNB2->frame_parms, pbch_pdu, 0); - } - // LOG_M("pilotsF.m","rsF",txdataF[0],frame_parms->ofdm_symbol_size,1,1); - LOG_M("txsigF0.m","txsF0", eNB->common_vars.txdataF[0][0],FRAME_LENGTH_COMPLEX_SAMPLES_NO_PREFIX,1,1); if (eNB->frame_parms.nb_antennas_tx>1) @@ -668,9 +618,6 @@ int main(int argc, char **argv) tx_lev1 = 0; tx_lev2 = 0; - - - for (aa=0; aa<eNB->frame_parms.nb_antennas_tx; aa++) { if (frame_parms->Ncp == 1) PHY_ofdm_mod(eNB->common_vars.txdataF[0][aa], // input, @@ -743,7 +690,6 @@ int main(int argc, char **argv) } // tx_lev_dB = (unsigned int) dB_fixed(tx_lev); - LOG_M("txsig0.m","txs0", txdata[0],FRAME_LENGTH_COMPLEX_SAMPLES,1,1); if (frame_parms->nb_antennas_tx>1) @@ -762,17 +708,17 @@ int main(int argc, char **argv) i=0; while (!feof(input_fd)) { - if (fscanf(input_fd,"%s %s",input_val_str,input_val_str2) != 2) { //&input_val1,&input_val2); + if (fscanf(input_fd,"%49s %49s",input_val_str,input_val_str2) != 2) { //&input_val1,&input_val2); printf("%s:%d:%s: error with fscanf, exiting\n", __FILE__, __LINE__, __FUNCTION__); exit(1); } if ((i%4)==0) { - ((short*)txdata[0])[i/2] = (short)((1<<15)*strtod(input_val_str,NULL)); - ((short*)txdata[0])[(i/2)+1] = (short)((1<<15)*strtod(input_val_str2,NULL)); + ((short *)txdata[0])[i/2] = (short)((1<<15)*strtod(input_val_str,NULL)); + ((short *)txdata[0])[(i/2)+1] = (short)((1<<15)*strtod(input_val_str2,NULL)); if ((i/4)<100) - printf("sample %d => %e + j%e (%d +j%d)\n",i/4,strtod(input_val_str,NULL),strtod(input_val_str2,NULL),((short*)txdata[0])[i/4],((short*)txdata[0])[(i/4)+1]);//1,input_val2,); + printf("sample %d => %e + j%e (%d +j%d)\n",i/4,strtod(input_val_str,NULL),strtod(input_val_str2,NULL),((short *)txdata[0])[i/4],((short *)txdata[0])[(i/4)+1]); //1,input_val2,); } i++; @@ -789,7 +735,6 @@ int main(int argc, char **argv) // tx_lev_dB = (unsigned int) dB_fixed(tx_lev); } - // multipath channel for (i=0; i<2*nsymb*OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES; i++) { @@ -809,10 +754,7 @@ int main(int argc, char **argv) } } - for (SNR=snr0; SNR<snr1; SNR+=.2) { - - n_errors = 0; n_errors2 = 0; n_alamouti = 0; @@ -824,8 +766,6 @@ int main(int argc, char **argv) printf("*********************** trial %d ***************************\n",trial); while (pbch_sinr>-2.0) { - - multipath_channel(eNB2UE,s_re,s_im,r_re,r_im, 2*nsymb*OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES,0); @@ -882,8 +822,8 @@ int main(int argc, char **argv) r_im[aa][i] += (pow(10.0,.05*interf1)*r_im1[aa][i] + pow(10.0,.05*interf2)*r_im2[aa][i]); } - ((short*) UE->common_vars.rxdata[aa])[2*i] = (short) (.167*(r_re[aa][i] +sqrt(sigma2/2)*gaussdouble(0.0,1.0))); - ((short*) UE->common_vars.rxdata[aa])[2*i+1] = (short) (.167*(r_im[aa][i] + (iqim*r_re[aa][i]) + sqrt(sigma2/2)*gaussdouble(0.0,1.0))); + ((short *) UE->common_vars.rxdata[aa])[2*i] = (short) (.167*(r_re[aa][i] +sqrt(sigma2/2)*gaussdouble(0.0,1.0))); + ((short *) UE->common_vars.rxdata[aa])[2*i+1] = (short) (.167*(r_im[aa][i] + (iqim*r_re[aa][i]) + sqrt(sigma2/2)*gaussdouble(0.0,1.0))); } } @@ -892,7 +832,6 @@ int main(int argc, char **argv) 10*log10(signal_energy(&UE->common_vars.rxdata[0][frame_parms->samples_per_tti/2],4*OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES))); } - /* // optional: read rx_frame from file if ((rx_frame_file = fopen("rx_frame.dat","r")) == NULL) @@ -911,19 +850,15 @@ int main(int argc, char **argv) fclose(rx_frame_file); */ - for (l=0; l<eNB->frame_parms.symbols_per_tti; l++) { - // subframe_offset = (l/eNB->frame_parms.symbols_per_tti)*eNB->frame_parms.samples_per_tti; // printf("subframe_offset = %d\n",subframe_offset); - slot_fep(UE, l%(eNB->frame_parms.symbols_per_tti/2), l/(eNB->frame_parms.symbols_per_tti/2), 0, 0, - 0); - + 0); if (l==0) { lte_ue_measurements(UE, @@ -961,16 +896,14 @@ int main(int argc, char **argv) //sprintf(fname,"dl_ch00_%d.m",l); //sprintf(vname,"dl_ch00_%d",l); //LOG_M(fname,vname,&(common_vars->dl_ch_estimates[0][frame_parms->ofdm_symbol_size*(l%6)]),frame_parms->ofdm_symbol_size,1,1); - lte_est_freq_offset(UE->common_vars.common_vars_rx_data_per_thread[/*subframe*/0&0x1].dl_ch_estimates[0], &UE->frame_parms, l, &freq_offset, - 1); + 1); } if (l==((eNB->frame_parms.Ncp==0)?10:9)) { - for (frame_mod4=0; frame_mod4<4; frame_mod4++) { pbch_tx_ant = rx_pbch(&UE->common_vars, UE->pbch_vars[0], @@ -1003,7 +936,6 @@ int main(int argc, char **argv) } } - if ((pbch_tx_ant>0) && (pbch_tx_ant<4)) { if (n_frames==1) msg("pbch decoded sucessfully mode1_flag %d, frame_mod4 %d, tx_ant %d!\n", @@ -1023,7 +955,6 @@ int main(int argc, char **argv) UE, 0,0,1); #endif - } //noise trials if (abstraction_flag==1) { @@ -1049,7 +980,6 @@ int main(int argc, char **argv) } // NSR if (n_frames==1) { - LOG_M("H00.m","h00",&(UE->common_vars.common_vars_rx_data_per_thread[/*subframe*/0&0x1].dl_ch_estimates[0][0][0]),((frame_parms->Ncp==0)?7:6)*(eNB->frame_parms.ofdm_symbol_size),1,1); if (n_tx==2) @@ -1062,7 +992,6 @@ int main(int argc, char **argv) LOG_M("PBCH_rxF_llr.m","pbch_llr",UE->pbch_vars[0]->llr,(frame_parms->Ncp==0) ? 1920 : 1728,1,4); } - for (i=0; i<2; i++) { free(s_re[i]); free(s_im[i]); @@ -1074,15 +1003,15 @@ int main(int argc, char **argv) free(s_im); free(r_re); free(r_im); - - lte_sync_time_free(); if (write_output_file) fclose(output_fd); - return(n_errors); + if (input_fd != NULL) + fclose(input_fd); + return(n_errors); } diff --git a/openair1/SIMULATION/LTE_PHY/pdcchsim.c b/openair1/SIMULATION/LTE_PHY/pdcchsim.c index 569d2226deb1e7953da67a8d39c7c9690e1bb39e..004eb24243bff7b6ab4272568e2281737f4e3364 100644 --- a/openair1/SIMULATION/LTE_PHY/pdcchsim.c +++ b/openair1/SIMULATION/LTE_PHY/pdcchsim.c @@ -34,7 +34,7 @@ #include "OCG_vars.h" #ifdef XFORMS -#include "PHY/TOOLS/lte_phy_scope.h" + #include "PHY/TOOLS/lte_phy_scope.h" #endif #include "unitary_defs.h" @@ -51,303 +51,284 @@ double cpuf; DCI_PDU DCI_pdu; -DCI_PDU *get_dci(LTE_DL_FRAME_PARMS *lte_frame_parms,uint8_t log2L, uint8_t log2Lcommon, DCI_format_t format_selector[MAX_NUM_DCI], uint8_t num_dci, uint32_t rnti) -{ +DCI_PDU *get_dci(LTE_DL_FRAME_PARMS *lte_frame_parms,uint8_t log2L, uint8_t log2Lcommon, DCI_format_t format_selector[MAX_NUM_DCI], uint8_t num_dci, uint32_t rnti) { uint32_t BCCH_alloc_pdu[2]; uint32_t DLSCH_alloc_pdu[2]; uint32_t UL_alloc_pdu[2]; - int ind; int dci_length_bytes=0,dci_length=0; int BCCH_pdu_size_bits=0, BCCH_pdu_size_bytes=0; int UL_pdu_size_bits=0, UL_pdu_size_bytes=0; int mcs = 3; - DCI_pdu.Num_dci = 0; if (lte_frame_parms->frame_type == TDD) { switch (lte_frame_parms->N_RB_DL) { - case 6: - dci_length = sizeof_DCI1_1_5MHz_TDD_t; - dci_length_bytes = sizeof(DCI1_1_5MHz_TDD_t); - ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu[0])->rah = 0; - ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu[0])->rballoc = DLSCH_RB_ALLOC; - ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu[0])->mcs = mcs; - ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu[0])->harq_pid = 0; - ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu[0])->ndi = 1; - ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu[0])->rv = 0; - ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu[0])->TPC = 0; - ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu[0])->dai = 0; - - ((DCI1A_1_5MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->type = 1; - ((DCI1A_1_5MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->vrb_type = 0; - ((DCI1A_1_5MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->rballoc = computeRIV(lte_frame_parms->N_RB_DL, 0, 4); - ((DCI1A_1_5MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->ndi = 1; - ((DCI1A_1_5MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->rv = 0; - ((DCI1A_1_5MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->mcs = 2; - ((DCI1A_1_5MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->harq_pid = 0; - ((DCI1A_1_5MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->TPC = 1; - BCCH_pdu_size_bits = sizeof_DCI1A_1_5MHz_TDD_1_6_t; - BCCH_pdu_size_bytes = sizeof(DCI1A_1_5MHz_TDD_1_6_t); - - ((DCI0_1_5MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->type = 0; - ((DCI0_1_5MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->hopping = 0; - ((DCI0_1_5MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->rballoc = DLSCH_RB_ALLOC; - ((DCI0_1_5MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->mcs = mcs; - ((DCI0_1_5MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->ndi = 1; - ((DCI0_1_5MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->TPC = 2; - ((DCI0_1_5MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->cshift = 3; - ((DCI0_1_5MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->dai = 1; - ((DCI0_1_5MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->cqi_req = 1; - UL_pdu_size_bits = sizeof_DCI0_1_5MHz_TDD_1_6_t; - UL_pdu_size_bytes = sizeof(DCI0_1_5MHz_TDD_1_6_t); - break; + case 6: + dci_length = sizeof_DCI1_1_5MHz_TDD_t; + dci_length_bytes = sizeof(DCI1_1_5MHz_TDD_t); + ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu[0])->rah = 0; + ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu[0])->rballoc = DLSCH_RB_ALLOC; + ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu[0])->mcs = mcs; + ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu[0])->harq_pid = 0; + ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu[0])->ndi = 1; + ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu[0])->rv = 0; + ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu[0])->TPC = 0; + ((DCI1_1_5MHz_TDD_t *)&DLSCH_alloc_pdu[0])->dai = 0; + ((DCI1A_1_5MHz_TDD_1_6_t *)&BCCH_alloc_pdu[0])->type = 1; + ((DCI1A_1_5MHz_TDD_1_6_t *)&BCCH_alloc_pdu[0])->vrb_type = 0; + ((DCI1A_1_5MHz_TDD_1_6_t *)&BCCH_alloc_pdu[0])->rballoc = computeRIV(lte_frame_parms->N_RB_DL, 0, 4); + ((DCI1A_1_5MHz_TDD_1_6_t *)&BCCH_alloc_pdu[0])->ndi = 1; + ((DCI1A_1_5MHz_TDD_1_6_t *)&BCCH_alloc_pdu[0])->rv = 0; + ((DCI1A_1_5MHz_TDD_1_6_t *)&BCCH_alloc_pdu[0])->mcs = 2; + ((DCI1A_1_5MHz_TDD_1_6_t *)&BCCH_alloc_pdu[0])->harq_pid = 0; + ((DCI1A_1_5MHz_TDD_1_6_t *)&BCCH_alloc_pdu[0])->TPC = 1; + BCCH_pdu_size_bits = sizeof_DCI1A_1_5MHz_TDD_1_6_t; + BCCH_pdu_size_bytes = sizeof(DCI1A_1_5MHz_TDD_1_6_t); + ((DCI0_1_5MHz_TDD_1_6_t *)&UL_alloc_pdu[0])->type = 0; + ((DCI0_1_5MHz_TDD_1_6_t *)&UL_alloc_pdu[0])->hopping = 0; + ((DCI0_1_5MHz_TDD_1_6_t *)&UL_alloc_pdu[0])->rballoc = DLSCH_RB_ALLOC; + ((DCI0_1_5MHz_TDD_1_6_t *)&UL_alloc_pdu[0])->mcs = mcs; + ((DCI0_1_5MHz_TDD_1_6_t *)&UL_alloc_pdu[0])->ndi = 1; + ((DCI0_1_5MHz_TDD_1_6_t *)&UL_alloc_pdu[0])->TPC = 2; + ((DCI0_1_5MHz_TDD_1_6_t *)&UL_alloc_pdu[0])->cshift = 3; + ((DCI0_1_5MHz_TDD_1_6_t *)&UL_alloc_pdu[0])->dai = 1; + ((DCI0_1_5MHz_TDD_1_6_t *)&UL_alloc_pdu[0])->cqi_req = 1; + UL_pdu_size_bits = sizeof_DCI0_1_5MHz_TDD_1_6_t; + UL_pdu_size_bytes = sizeof(DCI0_1_5MHz_TDD_1_6_t); + break; - case 25: - dci_length = sizeof_DCI1_5MHz_TDD_t; - dci_length_bytes = sizeof(DCI1_5MHz_TDD_t); - ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu[0])->rah = 0; - ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu[0])->rballoc = DLSCH_RB_ALLOC; - ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu[0])->mcs = mcs; - ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu[0])->harq_pid = 0; - ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu[0])->ndi = 1; - ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu[0])->rv = 0; - ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu[0])->TPC = 0; - ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu[0])->dai = 0; - - ((DCI1A_5MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->type = 1; - ((DCI1A_5MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->vrb_type = 0; - ((DCI1A_5MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->rballoc = computeRIV(lte_frame_parms->N_RB_DL, 18, 4); - ((DCI1A_5MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->ndi = 1; - ((DCI1A_5MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->rv = 0; - ((DCI1A_5MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->mcs = 2; - ((DCI1A_5MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->harq_pid = 0; - ((DCI1A_5MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->TPC = 1; - BCCH_pdu_size_bits = sizeof_DCI1A_5MHz_TDD_1_6_t; - BCCH_pdu_size_bytes = sizeof(DCI1A_5MHz_TDD_1_6_t); - - ((DCI0_5MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->type = 0; - ((DCI0_5MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->hopping = 0; - ((DCI0_5MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->rballoc = DLSCH_RB_ALLOC; - ((DCI0_5MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->mcs = mcs; - ((DCI0_5MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->ndi = 1; - ((DCI0_5MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->TPC = 2; - ((DCI0_5MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->cshift = 3; - ((DCI0_5MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->dai = 1; - ((DCI0_5MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->cqi_req = 1; - UL_pdu_size_bits = sizeof_DCI0_5MHz_TDD_1_6_t; - UL_pdu_size_bytes = sizeof(DCI0_5MHz_TDD_1_6_t); - break; + case 25: + dci_length = sizeof_DCI1_5MHz_TDD_t; + dci_length_bytes = sizeof(DCI1_5MHz_TDD_t); + ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu[0])->rah = 0; + ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu[0])->rballoc = DLSCH_RB_ALLOC; + ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu[0])->mcs = mcs; + ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu[0])->harq_pid = 0; + ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu[0])->ndi = 1; + ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu[0])->rv = 0; + ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu[0])->TPC = 0; + ((DCI1_5MHz_TDD_t *)&DLSCH_alloc_pdu[0])->dai = 0; + ((DCI1A_5MHz_TDD_1_6_t *)&BCCH_alloc_pdu[0])->type = 1; + ((DCI1A_5MHz_TDD_1_6_t *)&BCCH_alloc_pdu[0])->vrb_type = 0; + ((DCI1A_5MHz_TDD_1_6_t *)&BCCH_alloc_pdu[0])->rballoc = computeRIV(lte_frame_parms->N_RB_DL, 18, 4); + ((DCI1A_5MHz_TDD_1_6_t *)&BCCH_alloc_pdu[0])->ndi = 1; + ((DCI1A_5MHz_TDD_1_6_t *)&BCCH_alloc_pdu[0])->rv = 0; + ((DCI1A_5MHz_TDD_1_6_t *)&BCCH_alloc_pdu[0])->mcs = 2; + ((DCI1A_5MHz_TDD_1_6_t *)&BCCH_alloc_pdu[0])->harq_pid = 0; + ((DCI1A_5MHz_TDD_1_6_t *)&BCCH_alloc_pdu[0])->TPC = 1; + BCCH_pdu_size_bits = sizeof_DCI1A_5MHz_TDD_1_6_t; + BCCH_pdu_size_bytes = sizeof(DCI1A_5MHz_TDD_1_6_t); + ((DCI0_5MHz_TDD_1_6_t *)&UL_alloc_pdu[0])->type = 0; + ((DCI0_5MHz_TDD_1_6_t *)&UL_alloc_pdu[0])->hopping = 0; + ((DCI0_5MHz_TDD_1_6_t *)&UL_alloc_pdu[0])->rballoc = DLSCH_RB_ALLOC; + ((DCI0_5MHz_TDD_1_6_t *)&UL_alloc_pdu[0])->mcs = mcs; + ((DCI0_5MHz_TDD_1_6_t *)&UL_alloc_pdu[0])->ndi = 1; + ((DCI0_5MHz_TDD_1_6_t *)&UL_alloc_pdu[0])->TPC = 2; + ((DCI0_5MHz_TDD_1_6_t *)&UL_alloc_pdu[0])->cshift = 3; + ((DCI0_5MHz_TDD_1_6_t *)&UL_alloc_pdu[0])->dai = 1; + ((DCI0_5MHz_TDD_1_6_t *)&UL_alloc_pdu[0])->cqi_req = 1; + UL_pdu_size_bits = sizeof_DCI0_5MHz_TDD_1_6_t; + UL_pdu_size_bytes = sizeof(DCI0_5MHz_TDD_1_6_t); + break; - case 50: - dci_length = sizeof_DCI1_10MHz_TDD_t; - dci_length_bytes = sizeof(DCI1_10MHz_TDD_t); - ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu[0])->rah = 0; - ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu[0])->rballoc = DLSCH_RB_ALLOC; - ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu[0])->mcs = mcs; - ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu[0])->harq_pid = 0; - ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu[0])->ndi = 1; - ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu[0])->rv = 0; - ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu[0])->TPC = 0; - ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu[0])->dai = 0; - - ((DCI1A_10MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->type = 1; - ((DCI1A_10MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->vrb_type = 0; - ((DCI1A_10MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->rballoc = computeRIV(lte_frame_parms->N_RB_DL, 30, 4); - ((DCI1A_10MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->ndi = 1; - ((DCI1A_10MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->rv = 0; - ((DCI1A_10MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->mcs = 2; - ((DCI1A_10MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->harq_pid = 0; - ((DCI1A_10MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->TPC = 1; - BCCH_pdu_size_bits = sizeof_DCI1A_10MHz_TDD_1_6_t; - BCCH_pdu_size_bytes = sizeof(DCI1A_10MHz_TDD_1_6_t); - - ((DCI0_10MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->type = 0; - ((DCI0_10MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->hopping = 0; - ((DCI0_10MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->rballoc = DLSCH_RB_ALLOC; - ((DCI0_10MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->mcs = mcs; - ((DCI0_10MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->ndi = 1; - ((DCI0_10MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->TPC = 2; - ((DCI0_10MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->cshift = 3; - ((DCI0_10MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->dai = 1; - ((DCI0_10MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->cqi_req = 1; - UL_pdu_size_bits = sizeof_DCI0_10MHz_TDD_1_6_t; - UL_pdu_size_bytes = sizeof(DCI0_10MHz_TDD_1_6_t); - break; + case 50: + dci_length = sizeof_DCI1_10MHz_TDD_t; + dci_length_bytes = sizeof(DCI1_10MHz_TDD_t); + ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu[0])->rah = 0; + ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu[0])->rballoc = DLSCH_RB_ALLOC; + ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu[0])->mcs = mcs; + ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu[0])->harq_pid = 0; + ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu[0])->ndi = 1; + ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu[0])->rv = 0; + ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu[0])->TPC = 0; + ((DCI1_10MHz_TDD_t *)&DLSCH_alloc_pdu[0])->dai = 0; + ((DCI1A_10MHz_TDD_1_6_t *)&BCCH_alloc_pdu[0])->type = 1; + ((DCI1A_10MHz_TDD_1_6_t *)&BCCH_alloc_pdu[0])->vrb_type = 0; + ((DCI1A_10MHz_TDD_1_6_t *)&BCCH_alloc_pdu[0])->rballoc = computeRIV(lte_frame_parms->N_RB_DL, 30, 4); + ((DCI1A_10MHz_TDD_1_6_t *)&BCCH_alloc_pdu[0])->ndi = 1; + ((DCI1A_10MHz_TDD_1_6_t *)&BCCH_alloc_pdu[0])->rv = 0; + ((DCI1A_10MHz_TDD_1_6_t *)&BCCH_alloc_pdu[0])->mcs = 2; + ((DCI1A_10MHz_TDD_1_6_t *)&BCCH_alloc_pdu[0])->harq_pid = 0; + ((DCI1A_10MHz_TDD_1_6_t *)&BCCH_alloc_pdu[0])->TPC = 1; + BCCH_pdu_size_bits = sizeof_DCI1A_10MHz_TDD_1_6_t; + BCCH_pdu_size_bytes = sizeof(DCI1A_10MHz_TDD_1_6_t); + ((DCI0_10MHz_TDD_1_6_t *)&UL_alloc_pdu[0])->type = 0; + ((DCI0_10MHz_TDD_1_6_t *)&UL_alloc_pdu[0])->hopping = 0; + ((DCI0_10MHz_TDD_1_6_t *)&UL_alloc_pdu[0])->rballoc = DLSCH_RB_ALLOC; + ((DCI0_10MHz_TDD_1_6_t *)&UL_alloc_pdu[0])->mcs = mcs; + ((DCI0_10MHz_TDD_1_6_t *)&UL_alloc_pdu[0])->ndi = 1; + ((DCI0_10MHz_TDD_1_6_t *)&UL_alloc_pdu[0])->TPC = 2; + ((DCI0_10MHz_TDD_1_6_t *)&UL_alloc_pdu[0])->cshift = 3; + ((DCI0_10MHz_TDD_1_6_t *)&UL_alloc_pdu[0])->dai = 1; + ((DCI0_10MHz_TDD_1_6_t *)&UL_alloc_pdu[0])->cqi_req = 1; + UL_pdu_size_bits = sizeof_DCI0_10MHz_TDD_1_6_t; + UL_pdu_size_bytes = sizeof(DCI0_10MHz_TDD_1_6_t); + break; - case 100: - dci_length = sizeof_DCI1_20MHz_TDD_t; - dci_length_bytes = sizeof(DCI1_20MHz_TDD_t); - ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu[0])->rah = 0; - ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu[0])->rballoc = DLSCH_RB_ALLOC; - ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu[0])->mcs = mcs; - ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu[0])->harq_pid = 0; - ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu[0])->ndi = 1; - ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu[0])->rv = 0; - ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu[0])->TPC = 0; - ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu[0])->dai = 0; - - ((DCI1A_20MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->type = 1; - ((DCI1A_20MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->vrb_type = 0; - ((DCI1A_20MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->rballoc = computeRIV(lte_frame_parms->N_RB_DL, 70, 4); - ((DCI1A_20MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->ndi = 1; - ((DCI1A_20MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->rv = 0; - ((DCI1A_20MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->mcs = 2; - ((DCI1A_20MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->harq_pid = 0; - ((DCI1A_20MHz_TDD_1_6_t*)&BCCH_alloc_pdu[0])->TPC = 1; - BCCH_pdu_size_bits = sizeof_DCI1A_20MHz_TDD_1_6_t; - BCCH_pdu_size_bytes = sizeof(DCI1A_20MHz_TDD_1_6_t); - - ((DCI0_20MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->type = 0; - ((DCI0_20MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->hopping = 0; - ((DCI0_20MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->rballoc = DLSCH_RB_ALLOC; - ((DCI0_20MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->mcs = mcs; - ((DCI0_20MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->ndi = 1; - ((DCI0_20MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->TPC = 2; - ((DCI0_20MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->cshift = 3; - ((DCI0_20MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->dai = 1; - ((DCI0_20MHz_TDD_1_6_t*)&UL_alloc_pdu[0])->cqi_req = 1; - UL_pdu_size_bits = sizeof_DCI0_20MHz_TDD_1_6_t; - UL_pdu_size_bytes = sizeof(DCI0_20MHz_TDD_1_6_t); - break; + case 100: + dci_length = sizeof_DCI1_20MHz_TDD_t; + dci_length_bytes = sizeof(DCI1_20MHz_TDD_t); + ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu[0])->rah = 0; + ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu[0])->rballoc = DLSCH_RB_ALLOC; + ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu[0])->mcs = mcs; + ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu[0])->harq_pid = 0; + ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu[0])->ndi = 1; + ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu[0])->rv = 0; + ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu[0])->TPC = 0; + ((DCI1_20MHz_TDD_t *)&DLSCH_alloc_pdu[0])->dai = 0; + ((DCI1A_20MHz_TDD_1_6_t *)&BCCH_alloc_pdu[0])->type = 1; + ((DCI1A_20MHz_TDD_1_6_t *)&BCCH_alloc_pdu[0])->vrb_type = 0; + ((DCI1A_20MHz_TDD_1_6_t *)&BCCH_alloc_pdu[0])->rballoc = computeRIV(lte_frame_parms->N_RB_DL, 70, 4); + ((DCI1A_20MHz_TDD_1_6_t *)&BCCH_alloc_pdu[0])->ndi = 1; + ((DCI1A_20MHz_TDD_1_6_t *)&BCCH_alloc_pdu[0])->rv = 0; + ((DCI1A_20MHz_TDD_1_6_t *)&BCCH_alloc_pdu[0])->mcs = 2; + ((DCI1A_20MHz_TDD_1_6_t *)&BCCH_alloc_pdu[0])->harq_pid = 0; + ((DCI1A_20MHz_TDD_1_6_t *)&BCCH_alloc_pdu[0])->TPC = 1; + BCCH_pdu_size_bits = sizeof_DCI1A_20MHz_TDD_1_6_t; + BCCH_pdu_size_bytes = sizeof(DCI1A_20MHz_TDD_1_6_t); + ((DCI0_20MHz_TDD_1_6_t *)&UL_alloc_pdu[0])->type = 0; + ((DCI0_20MHz_TDD_1_6_t *)&UL_alloc_pdu[0])->hopping = 0; + ((DCI0_20MHz_TDD_1_6_t *)&UL_alloc_pdu[0])->rballoc = DLSCH_RB_ALLOC; + ((DCI0_20MHz_TDD_1_6_t *)&UL_alloc_pdu[0])->mcs = mcs; + ((DCI0_20MHz_TDD_1_6_t *)&UL_alloc_pdu[0])->ndi = 1; + ((DCI0_20MHz_TDD_1_6_t *)&UL_alloc_pdu[0])->TPC = 2; + ((DCI0_20MHz_TDD_1_6_t *)&UL_alloc_pdu[0])->cshift = 3; + ((DCI0_20MHz_TDD_1_6_t *)&UL_alloc_pdu[0])->dai = 1; + ((DCI0_20MHz_TDD_1_6_t *)&UL_alloc_pdu[0])->cqi_req = 1; + UL_pdu_size_bits = sizeof_DCI0_20MHz_TDD_1_6_t; + UL_pdu_size_bytes = sizeof(DCI0_20MHz_TDD_1_6_t); + break; } } else { //FDD switch (lte_frame_parms->N_RB_DL) { - case 6: - dci_length = sizeof_DCI1_1_5MHz_FDD_t; - dci_length_bytes = sizeof(DCI1_1_5MHz_FDD_t); - ((DCI1_1_5MHz_FDD_t *)&DLSCH_alloc_pdu[0])->rah = 0; - ((DCI1_1_5MHz_FDD_t *)&DLSCH_alloc_pdu[0])->rballoc = DLSCH_RB_ALLOC; - ((DCI1_1_5MHz_FDD_t *)&DLSCH_alloc_pdu[0])->mcs = mcs; - ((DCI1_1_5MHz_FDD_t *)&DLSCH_alloc_pdu[0])->harq_pid = 0; - ((DCI1_1_5MHz_FDD_t *)&DLSCH_alloc_pdu[0])->ndi = 1; - ((DCI1_1_5MHz_FDD_t *)&DLSCH_alloc_pdu[0])->rv = 0; - ((DCI1_1_5MHz_FDD_t *)&DLSCH_alloc_pdu[0])->TPC = 0; - - ((DCI1A_1_5MHz_FDD_t*)&BCCH_alloc_pdu[0])->type = 1; - ((DCI1A_1_5MHz_FDD_t*)&BCCH_alloc_pdu[0])->vrb_type = 0; - ((DCI1A_1_5MHz_FDD_t*)&BCCH_alloc_pdu[0])->rballoc = computeRIV(lte_frame_parms->N_RB_DL, 0, 4); - ((DCI1A_1_5MHz_FDD_t*)&BCCH_alloc_pdu[0])->ndi = 1; - ((DCI1A_1_5MHz_FDD_t*)&BCCH_alloc_pdu[0])->rv = 0; - ((DCI1A_1_5MHz_FDD_t*)&BCCH_alloc_pdu[0])->mcs = 2; - ((DCI1A_1_5MHz_FDD_t*)&BCCH_alloc_pdu[0])->harq_pid = 0; - ((DCI1A_1_5MHz_FDD_t*)&BCCH_alloc_pdu[0])->TPC = 1; - BCCH_pdu_size_bits = sizeof_DCI1A_1_5MHz_FDD_t; - BCCH_pdu_size_bytes = sizeof(DCI1A_1_5MHz_FDD_t); - - ((DCI0_1_5MHz_FDD_t*)&UL_alloc_pdu[0])->type = 0; - ((DCI0_1_5MHz_FDD_t*)&UL_alloc_pdu[0])->hopping = 0; - ((DCI0_1_5MHz_FDD_t*)&UL_alloc_pdu[0])->rballoc = DLSCH_RB_ALLOC; - ((DCI0_1_5MHz_FDD_t*)&UL_alloc_pdu[0])->mcs = mcs; - ((DCI0_1_5MHz_FDD_t*)&UL_alloc_pdu[0])->ndi = 1; - ((DCI0_1_5MHz_FDD_t*)&UL_alloc_pdu[0])->TPC = 2; - ((DCI0_1_5MHz_FDD_t*)&UL_alloc_pdu[0])->cshift = 3; - ((DCI0_1_5MHz_FDD_t*)&UL_alloc_pdu[0])->cqi_req = 1; - UL_pdu_size_bits = sizeof_DCI0_1_5MHz_FDD_t; - UL_pdu_size_bytes = sizeof(DCI0_1_5MHz_FDD_t); - break; + case 6: + dci_length = sizeof_DCI1_1_5MHz_FDD_t; + dci_length_bytes = sizeof(DCI1_1_5MHz_FDD_t); + ((DCI1_1_5MHz_FDD_t *)&DLSCH_alloc_pdu[0])->rah = 0; + ((DCI1_1_5MHz_FDD_t *)&DLSCH_alloc_pdu[0])->rballoc = DLSCH_RB_ALLOC; + ((DCI1_1_5MHz_FDD_t *)&DLSCH_alloc_pdu[0])->mcs = mcs; + ((DCI1_1_5MHz_FDD_t *)&DLSCH_alloc_pdu[0])->harq_pid = 0; + ((DCI1_1_5MHz_FDD_t *)&DLSCH_alloc_pdu[0])->ndi = 1; + ((DCI1_1_5MHz_FDD_t *)&DLSCH_alloc_pdu[0])->rv = 0; + ((DCI1_1_5MHz_FDD_t *)&DLSCH_alloc_pdu[0])->TPC = 0; + ((DCI1A_1_5MHz_FDD_t *)&BCCH_alloc_pdu[0])->type = 1; + ((DCI1A_1_5MHz_FDD_t *)&BCCH_alloc_pdu[0])->vrb_type = 0; + ((DCI1A_1_5MHz_FDD_t *)&BCCH_alloc_pdu[0])->rballoc = computeRIV(lte_frame_parms->N_RB_DL, 0, 4); + ((DCI1A_1_5MHz_FDD_t *)&BCCH_alloc_pdu[0])->ndi = 1; + ((DCI1A_1_5MHz_FDD_t *)&BCCH_alloc_pdu[0])->rv = 0; + ((DCI1A_1_5MHz_FDD_t *)&BCCH_alloc_pdu[0])->mcs = 2; + ((DCI1A_1_5MHz_FDD_t *)&BCCH_alloc_pdu[0])->harq_pid = 0; + ((DCI1A_1_5MHz_FDD_t *)&BCCH_alloc_pdu[0])->TPC = 1; + BCCH_pdu_size_bits = sizeof_DCI1A_1_5MHz_FDD_t; + BCCH_pdu_size_bytes = sizeof(DCI1A_1_5MHz_FDD_t); + ((DCI0_1_5MHz_FDD_t *)&UL_alloc_pdu[0])->type = 0; + ((DCI0_1_5MHz_FDD_t *)&UL_alloc_pdu[0])->hopping = 0; + ((DCI0_1_5MHz_FDD_t *)&UL_alloc_pdu[0])->rballoc = DLSCH_RB_ALLOC; + ((DCI0_1_5MHz_FDD_t *)&UL_alloc_pdu[0])->mcs = mcs; + ((DCI0_1_5MHz_FDD_t *)&UL_alloc_pdu[0])->ndi = 1; + ((DCI0_1_5MHz_FDD_t *)&UL_alloc_pdu[0])->TPC = 2; + ((DCI0_1_5MHz_FDD_t *)&UL_alloc_pdu[0])->cshift = 3; + ((DCI0_1_5MHz_FDD_t *)&UL_alloc_pdu[0])->cqi_req = 1; + UL_pdu_size_bits = sizeof_DCI0_1_5MHz_FDD_t; + UL_pdu_size_bytes = sizeof(DCI0_1_5MHz_FDD_t); + break; - case 25: - dci_length = sizeof_DCI1_5MHz_FDD_t; - dci_length_bytes = sizeof(DCI1_5MHz_FDD_t); - ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu[0])->rah = 0; - ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu[0])->rballoc = DLSCH_RB_ALLOC; - ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu[0])->mcs = mcs; - ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu[0])->harq_pid = 0; - ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu[0])->ndi = 1; - ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu[0])->rv = 0; - ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu[0])->TPC = 0; - - ((DCI1A_5MHz_FDD_t*)&BCCH_alloc_pdu[0])->type = 1; - ((DCI1A_5MHz_FDD_t*)&BCCH_alloc_pdu[0])->vrb_type = 0; - ((DCI1A_5MHz_FDD_t*)&BCCH_alloc_pdu[0])->rballoc = computeRIV(lte_frame_parms->N_RB_DL, 18, 4); - ((DCI1A_5MHz_FDD_t*)&BCCH_alloc_pdu[0])->ndi = 1; - ((DCI1A_5MHz_FDD_t*)&BCCH_alloc_pdu[0])->rv = 0; - ((DCI1A_5MHz_FDD_t*)&BCCH_alloc_pdu[0])->mcs = 2; - ((DCI1A_5MHz_FDD_t*)&BCCH_alloc_pdu[0])->harq_pid = 0; - ((DCI1A_5MHz_FDD_t*)&BCCH_alloc_pdu[0])->TPC = 1; - BCCH_pdu_size_bits = sizeof_DCI1A_5MHz_FDD_t; - BCCH_pdu_size_bytes = sizeof(DCI1A_5MHz_FDD_t); - - ((DCI0_5MHz_FDD_t*)&UL_alloc_pdu[0])->type = 0; - ((DCI0_5MHz_FDD_t*)&UL_alloc_pdu[0])->hopping = 0; - ((DCI0_5MHz_FDD_t*)&UL_alloc_pdu[0])->rballoc = DLSCH_RB_ALLOC; - ((DCI0_5MHz_FDD_t*)&UL_alloc_pdu[0])->mcs = mcs; - ((DCI0_5MHz_FDD_t*)&UL_alloc_pdu[0])->ndi = 1; - ((DCI0_5MHz_FDD_t*)&UL_alloc_pdu[0])->TPC = 2; - ((DCI0_5MHz_FDD_t*)&UL_alloc_pdu[0])->cshift = 3; - ((DCI0_5MHz_FDD_t*)&UL_alloc_pdu[0])->cqi_req = 1; - UL_pdu_size_bits = sizeof_DCI0_5MHz_FDD_t; - UL_pdu_size_bytes = sizeof(DCI0_5MHz_FDD_t); - break; + case 25: + dci_length = sizeof_DCI1_5MHz_FDD_t; + dci_length_bytes = sizeof(DCI1_5MHz_FDD_t); + ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu[0])->rah = 0; + ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu[0])->rballoc = DLSCH_RB_ALLOC; + ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu[0])->mcs = mcs; + ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu[0])->harq_pid = 0; + ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu[0])->ndi = 1; + ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu[0])->rv = 0; + ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu[0])->TPC = 0; + ((DCI1A_5MHz_FDD_t *)&BCCH_alloc_pdu[0])->type = 1; + ((DCI1A_5MHz_FDD_t *)&BCCH_alloc_pdu[0])->vrb_type = 0; + ((DCI1A_5MHz_FDD_t *)&BCCH_alloc_pdu[0])->rballoc = computeRIV(lte_frame_parms->N_RB_DL, 18, 4); + ((DCI1A_5MHz_FDD_t *)&BCCH_alloc_pdu[0])->ndi = 1; + ((DCI1A_5MHz_FDD_t *)&BCCH_alloc_pdu[0])->rv = 0; + ((DCI1A_5MHz_FDD_t *)&BCCH_alloc_pdu[0])->mcs = 2; + ((DCI1A_5MHz_FDD_t *)&BCCH_alloc_pdu[0])->harq_pid = 0; + ((DCI1A_5MHz_FDD_t *)&BCCH_alloc_pdu[0])->TPC = 1; + BCCH_pdu_size_bits = sizeof_DCI1A_5MHz_FDD_t; + BCCH_pdu_size_bytes = sizeof(DCI1A_5MHz_FDD_t); + ((DCI0_5MHz_FDD_t *)&UL_alloc_pdu[0])->type = 0; + ((DCI0_5MHz_FDD_t *)&UL_alloc_pdu[0])->hopping = 0; + ((DCI0_5MHz_FDD_t *)&UL_alloc_pdu[0])->rballoc = DLSCH_RB_ALLOC; + ((DCI0_5MHz_FDD_t *)&UL_alloc_pdu[0])->mcs = mcs; + ((DCI0_5MHz_FDD_t *)&UL_alloc_pdu[0])->ndi = 1; + ((DCI0_5MHz_FDD_t *)&UL_alloc_pdu[0])->TPC = 2; + ((DCI0_5MHz_FDD_t *)&UL_alloc_pdu[0])->cshift = 3; + ((DCI0_5MHz_FDD_t *)&UL_alloc_pdu[0])->cqi_req = 1; + UL_pdu_size_bits = sizeof_DCI0_5MHz_FDD_t; + UL_pdu_size_bytes = sizeof(DCI0_5MHz_FDD_t); + break; - case 50: - dci_length = sizeof_DCI1_10MHz_FDD_t; - dci_length_bytes = sizeof(DCI1_10MHz_FDD_t); - ((DCI1_10MHz_FDD_t *)&DLSCH_alloc_pdu[0])->rah = 0; - ((DCI1_10MHz_FDD_t *)&DLSCH_alloc_pdu[0])->rballoc = DLSCH_RB_ALLOC; - ((DCI1_10MHz_FDD_t *)&DLSCH_alloc_pdu[0])->mcs = mcs; - ((DCI1_10MHz_FDD_t *)&DLSCH_alloc_pdu[0])->harq_pid = 0; - ((DCI1_10MHz_FDD_t *)&DLSCH_alloc_pdu[0])->ndi = 1; - ((DCI1_10MHz_FDD_t *)&DLSCH_alloc_pdu[0])->rv = 0; - ((DCI1_10MHz_FDD_t *)&DLSCH_alloc_pdu[0])->TPC = 0; - - ((DCI1A_10MHz_FDD_t*)&BCCH_alloc_pdu[0])->type = 1; - ((DCI1A_10MHz_FDD_t*)&BCCH_alloc_pdu[0])->vrb_type = 0; - ((DCI1A_10MHz_FDD_t*)&BCCH_alloc_pdu[0])->rballoc = computeRIV(lte_frame_parms->N_RB_DL, 30, 4); - ((DCI1A_10MHz_FDD_t*)&BCCH_alloc_pdu[0])->ndi = 1; - ((DCI1A_10MHz_FDD_t*)&BCCH_alloc_pdu[0])->rv = 0; - ((DCI1A_10MHz_FDD_t*)&BCCH_alloc_pdu[0])->mcs = 2; - ((DCI1A_10MHz_FDD_t*)&BCCH_alloc_pdu[0])->harq_pid = 0; - ((DCI1A_10MHz_FDD_t*)&BCCH_alloc_pdu[0])->TPC = 1; - BCCH_pdu_size_bits = sizeof_DCI1A_10MHz_FDD_t; - BCCH_pdu_size_bytes = sizeof(DCI1A_10MHz_FDD_t); - - ((DCI0_10MHz_FDD_t*)&UL_alloc_pdu[0])->type = 0; - ((DCI0_10MHz_FDD_t*)&UL_alloc_pdu[0])->hopping = 0; - ((DCI0_10MHz_FDD_t*)&UL_alloc_pdu[0])->rballoc = DLSCH_RB_ALLOC; - ((DCI0_10MHz_FDD_t*)&UL_alloc_pdu[0])->mcs = mcs; - ((DCI0_10MHz_FDD_t*)&UL_alloc_pdu[0])->ndi = 1; - ((DCI0_10MHz_FDD_t*)&UL_alloc_pdu[0])->TPC = 2; - ((DCI0_10MHz_FDD_t*)&UL_alloc_pdu[0])->cshift = 3; - ((DCI0_10MHz_FDD_t*)&UL_alloc_pdu[0])->cqi_req = 1; - UL_pdu_size_bits = sizeof_DCI0_10MHz_FDD_t; - UL_pdu_size_bytes = sizeof(DCI0_10MHz_FDD_t); - break; + case 50: + dci_length = sizeof_DCI1_10MHz_FDD_t; + dci_length_bytes = sizeof(DCI1_10MHz_FDD_t); + ((DCI1_10MHz_FDD_t *)&DLSCH_alloc_pdu[0])->rah = 0; + ((DCI1_10MHz_FDD_t *)&DLSCH_alloc_pdu[0])->rballoc = DLSCH_RB_ALLOC; + ((DCI1_10MHz_FDD_t *)&DLSCH_alloc_pdu[0])->mcs = mcs; + ((DCI1_10MHz_FDD_t *)&DLSCH_alloc_pdu[0])->harq_pid = 0; + ((DCI1_10MHz_FDD_t *)&DLSCH_alloc_pdu[0])->ndi = 1; + ((DCI1_10MHz_FDD_t *)&DLSCH_alloc_pdu[0])->rv = 0; + ((DCI1_10MHz_FDD_t *)&DLSCH_alloc_pdu[0])->TPC = 0; + ((DCI1A_10MHz_FDD_t *)&BCCH_alloc_pdu[0])->type = 1; + ((DCI1A_10MHz_FDD_t *)&BCCH_alloc_pdu[0])->vrb_type = 0; + ((DCI1A_10MHz_FDD_t *)&BCCH_alloc_pdu[0])->rballoc = computeRIV(lte_frame_parms->N_RB_DL, 30, 4); + ((DCI1A_10MHz_FDD_t *)&BCCH_alloc_pdu[0])->ndi = 1; + ((DCI1A_10MHz_FDD_t *)&BCCH_alloc_pdu[0])->rv = 0; + ((DCI1A_10MHz_FDD_t *)&BCCH_alloc_pdu[0])->mcs = 2; + ((DCI1A_10MHz_FDD_t *)&BCCH_alloc_pdu[0])->harq_pid = 0; + ((DCI1A_10MHz_FDD_t *)&BCCH_alloc_pdu[0])->TPC = 1; + BCCH_pdu_size_bits = sizeof_DCI1A_10MHz_FDD_t; + BCCH_pdu_size_bytes = sizeof(DCI1A_10MHz_FDD_t); + ((DCI0_10MHz_FDD_t *)&UL_alloc_pdu[0])->type = 0; + ((DCI0_10MHz_FDD_t *)&UL_alloc_pdu[0])->hopping = 0; + ((DCI0_10MHz_FDD_t *)&UL_alloc_pdu[0])->rballoc = DLSCH_RB_ALLOC; + ((DCI0_10MHz_FDD_t *)&UL_alloc_pdu[0])->mcs = mcs; + ((DCI0_10MHz_FDD_t *)&UL_alloc_pdu[0])->ndi = 1; + ((DCI0_10MHz_FDD_t *)&UL_alloc_pdu[0])->TPC = 2; + ((DCI0_10MHz_FDD_t *)&UL_alloc_pdu[0])->cshift = 3; + ((DCI0_10MHz_FDD_t *)&UL_alloc_pdu[0])->cqi_req = 1; + UL_pdu_size_bits = sizeof_DCI0_10MHz_FDD_t; + UL_pdu_size_bytes = sizeof(DCI0_10MHz_FDD_t); + break; - case 100: - dci_length = sizeof_DCI1_20MHz_FDD_t; - dci_length_bytes = sizeof(DCI1_20MHz_FDD_t); - ((DCI1_20MHz_FDD_t *)&DLSCH_alloc_pdu[0])->rah = 0; - ((DCI1_20MHz_FDD_t *)&DLSCH_alloc_pdu[0])->rballoc = DLSCH_RB_ALLOC; - ((DCI1_20MHz_FDD_t *)&DLSCH_alloc_pdu[0])->mcs = mcs; - ((DCI1_20MHz_FDD_t *)&DLSCH_alloc_pdu[0])->harq_pid = 0; - ((DCI1_20MHz_FDD_t *)&DLSCH_alloc_pdu[0])->ndi = 1; - ((DCI1_20MHz_FDD_t *)&DLSCH_alloc_pdu[0])->rv = 0; - ((DCI1_20MHz_FDD_t *)&DLSCH_alloc_pdu[0])->TPC = 0; - - ((DCI1A_20MHz_FDD_t*)&BCCH_alloc_pdu[0])->type = 1; - ((DCI1A_20MHz_FDD_t*)&BCCH_alloc_pdu[0])->vrb_type = 0; - ((DCI1A_20MHz_FDD_t*)&BCCH_alloc_pdu[0])->rballoc = computeRIV(lte_frame_parms->N_RB_DL, 70, 4); - ((DCI1A_20MHz_FDD_t*)&BCCH_alloc_pdu[0])->ndi = 1; - ((DCI1A_20MHz_FDD_t*)&BCCH_alloc_pdu[0])->rv = 0; - ((DCI1A_20MHz_FDD_t*)&BCCH_alloc_pdu[0])->mcs = 2; - ((DCI1A_20MHz_FDD_t*)&BCCH_alloc_pdu[0])->harq_pid = 0; - ((DCI1A_20MHz_FDD_t*)&BCCH_alloc_pdu[0])->TPC = 1; - BCCH_pdu_size_bits = sizeof_DCI1A_20MHz_FDD_t; - BCCH_pdu_size_bytes = sizeof(DCI1A_20MHz_FDD_t); - - ((DCI0_20MHz_FDD_t*)&UL_alloc_pdu[0])->type = 0; - ((DCI0_20MHz_FDD_t*)&UL_alloc_pdu[0])->hopping = 0; - ((DCI0_20MHz_FDD_t*)&UL_alloc_pdu[0])->rballoc = DLSCH_RB_ALLOC; - ((DCI0_20MHz_FDD_t*)&UL_alloc_pdu[0])->mcs = mcs; - ((DCI0_20MHz_FDD_t*)&UL_alloc_pdu[0])->ndi = 1; - ((DCI0_20MHz_FDD_t*)&UL_alloc_pdu[0])->TPC = 2; - ((DCI0_20MHz_FDD_t*)&UL_alloc_pdu[0])->cshift = 3; - ((DCI0_20MHz_FDD_t*)&UL_alloc_pdu[0])->cqi_req = 1; - UL_pdu_size_bits = sizeof_DCI0_20MHz_FDD_t; - UL_pdu_size_bytes = sizeof(DCI0_20MHz_FDD_t); - break; + case 100: + dci_length = sizeof_DCI1_20MHz_FDD_t; + dci_length_bytes = sizeof(DCI1_20MHz_FDD_t); + ((DCI1_20MHz_FDD_t *)&DLSCH_alloc_pdu[0])->rah = 0; + ((DCI1_20MHz_FDD_t *)&DLSCH_alloc_pdu[0])->rballoc = DLSCH_RB_ALLOC; + ((DCI1_20MHz_FDD_t *)&DLSCH_alloc_pdu[0])->mcs = mcs; + ((DCI1_20MHz_FDD_t *)&DLSCH_alloc_pdu[0])->harq_pid = 0; + ((DCI1_20MHz_FDD_t *)&DLSCH_alloc_pdu[0])->ndi = 1; + ((DCI1_20MHz_FDD_t *)&DLSCH_alloc_pdu[0])->rv = 0; + ((DCI1_20MHz_FDD_t *)&DLSCH_alloc_pdu[0])->TPC = 0; + ((DCI1A_20MHz_FDD_t *)&BCCH_alloc_pdu[0])->type = 1; + ((DCI1A_20MHz_FDD_t *)&BCCH_alloc_pdu[0])->vrb_type = 0; + ((DCI1A_20MHz_FDD_t *)&BCCH_alloc_pdu[0])->rballoc = computeRIV(lte_frame_parms->N_RB_DL, 70, 4); + ((DCI1A_20MHz_FDD_t *)&BCCH_alloc_pdu[0])->ndi = 1; + ((DCI1A_20MHz_FDD_t *)&BCCH_alloc_pdu[0])->rv = 0; + ((DCI1A_20MHz_FDD_t *)&BCCH_alloc_pdu[0])->mcs = 2; + ((DCI1A_20MHz_FDD_t *)&BCCH_alloc_pdu[0])->harq_pid = 0; + ((DCI1A_20MHz_FDD_t *)&BCCH_alloc_pdu[0])->TPC = 1; + BCCH_pdu_size_bits = sizeof_DCI1A_20MHz_FDD_t; + BCCH_pdu_size_bytes = sizeof(DCI1A_20MHz_FDD_t); + ((DCI0_20MHz_FDD_t *)&UL_alloc_pdu[0])->type = 0; + ((DCI0_20MHz_FDD_t *)&UL_alloc_pdu[0])->hopping = 0; + ((DCI0_20MHz_FDD_t *)&UL_alloc_pdu[0])->rballoc = DLSCH_RB_ALLOC; + ((DCI0_20MHz_FDD_t *)&UL_alloc_pdu[0])->mcs = mcs; + ((DCI0_20MHz_FDD_t *)&UL_alloc_pdu[0])->ndi = 1; + ((DCI0_20MHz_FDD_t *)&UL_alloc_pdu[0])->TPC = 2; + ((DCI0_20MHz_FDD_t *)&UL_alloc_pdu[0])->cshift = 3; + ((DCI0_20MHz_FDD_t *)&UL_alloc_pdu[0])->cqi_req = 1; + UL_pdu_size_bits = sizeof_DCI0_20MHz_FDD_t; + UL_pdu_size_bytes = sizeof(DCI0_20MHz_FDD_t); + break; } } @@ -360,11 +341,10 @@ DCI_PDU *get_dci(LTE_DL_FRAME_PARMS *lte_frame_parms,uint8_t log2L, uint8_t log2 DCI_pdu.dci_alloc[ind].format = format1A; DCI_pdu.dci_alloc[ind].ra_flag = 0; DCI_pdu.dci_alloc[ind].search_space = DCI_COMMON_SPACE; - memcpy((void*)&DCI_pdu.dci_alloc[ind].dci_pdu[0], &BCCH_alloc_pdu[0], BCCH_pdu_size_bytes); + memcpy((void *)&DCI_pdu.dci_alloc[ind].dci_pdu[0], &BCCH_alloc_pdu[0], BCCH_pdu_size_bytes); DCI_pdu.Num_dci++; printf("Added common dci (%d) for rnti %x\n",ind,SI_RNTI); } - if (format_selector[ind]==format1) { DCI_pdu.dci_alloc[ind].dci_length = dci_length; @@ -373,10 +353,10 @@ DCI_PDU *get_dci(LTE_DL_FRAME_PARMS *lte_frame_parms,uint8_t log2L, uint8_t log2 DCI_pdu.dci_alloc[ind].format = format1; DCI_pdu.dci_alloc[ind].ra_flag = 0; DCI_pdu.dci_alloc[ind].search_space = DCI_UE_SPACE; - memcpy((void*)&DCI_pdu.dci_alloc[ind].dci_pdu[0], &DLSCH_alloc_pdu[0], dci_length_bytes); + memcpy((void *)&DCI_pdu.dci_alloc[ind].dci_pdu[0], &DLSCH_alloc_pdu[0], dci_length_bytes); DCI_pdu.Num_dci++; } - + if (format_selector[ind]==format0) { DCI_pdu.dci_alloc[ind].dci_length = UL_pdu_size_bits; DCI_pdu.dci_alloc[ind].L = log2L; @@ -384,24 +364,20 @@ DCI_PDU *get_dci(LTE_DL_FRAME_PARMS *lte_frame_parms,uint8_t log2L, uint8_t log2 DCI_pdu.dci_alloc[ind].format = format0; DCI_pdu.dci_alloc[ind].ra_flag = 0; DCI_pdu.dci_alloc[ind].search_space = DCI_UE_SPACE; - memcpy((void*)&DCI_pdu.dci_alloc[ind].dci_pdu[0], &UL_alloc_pdu[0], UL_pdu_size_bytes); + memcpy((void *)&DCI_pdu.dci_alloc[ind].dci_pdu[0], &UL_alloc_pdu[0], UL_pdu_size_bytes); DCI_pdu.Num_dci++; } } - + return(&DCI_pdu); } extern int QPSK[4],QPSK2[4]; -int main(int argc, char **argv) -{ - +int main(int argc, char **argv) { char c; - int i,l,aa; double sigma2, sigma2_dB=0,SNR,snr0=-2.0,snr1; - int **txdata; double s_re[2][30720*2],s_im[2][30720*2],r_re[2][30720*2],r_im[2][30720*2]; double iqim=0.0; @@ -413,7 +389,6 @@ int main(int argc, char **argv) #endif int trial, n_errors_common=0,n_errors_ul=0,n_errors_dl=0,n_errors_cfi=0,n_errors_hi=0; unsigned char eNb_id = 0; - uint8_t awgn_flag=0; int n_frames=1; channel_desc_t *eNB2UE; @@ -427,25 +402,18 @@ int main(int argc, char **argv) DCI_format_t format_selector[MAX_NUM_DCI]; uint8_t num_dci=0; uint8_t numCCE,common_active=0,ul_active=0,dl_active=0; - uint32_t n_trials_common=0,n_trials_ul=0,n_trials_dl=0,false_detection_cnt=0; uint8_t common_rx,ul_rx,dl_rx; uint8_t tdd_config=3; - FILE *input_fd=NULL; char input_val_str[50],input_val_str2[50]; uint16_t n_rnti=0x1234; uint8_t osf=1,N_RB_DL=25; - SCM_t channel_model=Rayleigh1_anticorr; - DCI_ALLOC_t dci_alloc_rx[8]; - int ret; - uint8_t harq_pid; uint8_t phich_ACK; - uint8_t num_phich_interf = 0; lte_frame_type_t frame_type=TDD; // int re_offset; @@ -454,75 +422,71 @@ int main(int argc, char **argv) int k; uint32_t perfect_ce = 0; int CCE_table[800]; - number_of_cards = 1; - cpuf = get_cpu_freq_GHz(); - logInit(); - while ((c = getopt (argc, argv, "hapFg:R:c:n:s:x:y:z:L:M:N:I:f:i:S:P:Y")) != -1) { switch (c) { - case 'a': - printf("Running AWGN simulation\n"); - awgn_flag = 1; - break; - - case 'R': - N_RB_DL = atoi(optarg); - break; + case 'a': + printf("Running AWGN simulation\n"); + awgn_flag = 1; + break; - case 'F': - frame_type = FDD; - break; + case 'R': + N_RB_DL = atoi(optarg); + break; - case 'c': - tdd_config=atoi(optarg); + case 'F': + frame_type = FDD; + break; - if (tdd_config>6) { - printf("Illegal tdd_config %d (should be 0-6)\n",tdd_config); - exit(-1); - } + case 'c': + tdd_config=atoi(optarg); - break; + if (tdd_config>6) { + printf("Illegal tdd_config %d (should be 0-6)\n",tdd_config); + exit(-1); + } - case 'g': - switch((char)*optarg) { - case 'A': - channel_model=SCM_A; break; - case 'B': - channel_model=SCM_B; - break; + case 'g': + switch((char)*optarg) { + case 'A': + channel_model=SCM_A; + break; - case 'C': - channel_model=SCM_C; - break; + case 'B': + channel_model=SCM_B; + break; - case 'D': - channel_model=SCM_D; - break; + case 'C': + channel_model=SCM_C; + break; - case 'E': - channel_model=EPA; - break; + case 'D': + channel_model=SCM_D; + break; - case 'F': - channel_model=EVA; - break; + case 'E': + channel_model=EPA; + break; - case 'G': - channel_model=ETU; - break; + case 'F': + channel_model=EVA; + break; - default: - printf("Unsupported channel model!\n"); - exit(-1); - } + case 'G': + channel_model=ETU; + break; - break; + default: + printf("Unsupported channel model!\n"); + exit(-1); + } + + break; /* case 'i': @@ -532,164 +496,169 @@ int main(int argc, char **argv) interf2=atoi(optarg); break; */ - case 'n': - n_frames = atoi(optarg); - break; + case 'n': + n_frames = atoi(optarg); + break; - case 's': - snr0 = atoi(optarg); - break; + case 's': + snr0 = atoi(optarg); + break; - case 'p': - extended_prefix_flag=1; - break; + case 'p': + extended_prefix_flag=1; + break; - case 'x': - transmission_mode=atoi(optarg); + case 'x': + transmission_mode=atoi(optarg); - if ((transmission_mode!=1) && - (transmission_mode!=2) && - (transmission_mode!=6)) { - printf("Unsupported transmission mode %d\n",transmission_mode); - exit(-1); - } + if ((transmission_mode!=1) && + (transmission_mode!=2) && + (transmission_mode!=6)) { + printf("Unsupported transmission mode %d\n",transmission_mode); + exit(-1); + } - break; + break; - case 'y': - n_tx=atoi(optarg); + case 'y': + n_tx=atoi(optarg); - if ((n_tx==0) || (n_tx>2)) { - printf("Unsupported number of tx antennas %d\n",n_tx); - exit(-1); - } + if ((n_tx==0) || (n_tx>2)) { + printf("Unsupported number of tx antennas %d\n",n_tx); + exit(-1); + } - break; + break; - case 'z': - n_rx=atoi(optarg); + case 'z': + n_rx=atoi(optarg); - if ((n_rx==0) || (n_rx>2)) { - printf("Unsupported number of rx antennas %d\n",n_rx); - exit(-1); - } + if ((n_rx==0) || (n_rx>2)) { + printf("Unsupported number of rx antennas %d\n",n_rx); + exit(-1); + } - break; + break; - case 'S': - subframe=atoi(optarg); - break; + case 'S': + subframe=atoi(optarg); + break; - case 'L': - log2L=atoi(optarg); + case 'L': + log2L=atoi(optarg); - if ((log2L!=0)&& - (log2L!=1)&& - (log2L!=2)&& - (log2L!=3)) { - printf("Unsupported DCI aggregation level %d (should be 0,1,2,3)\n",log2L); - exit(-1); - } + if ((log2L!=0)&& + (log2L!=1)&& + (log2L!=2)&& + (log2L!=3)) { + printf("Unsupported DCI aggregation level %d (should be 0,1,2,3)\n",log2L); + exit(-1); + } - break; + break; - case 'M': - log2Lcommon=atoi(optarg); + case 'M': + log2Lcommon=atoi(optarg); - if ((log2Lcommon!=2)&& - (log2Lcommon!=3)) { - printf("Unsupported Common DCI aggregation level %d (should be 2 or 3)\n",log2Lcommon); - exit(-1); - } + if ((log2Lcommon!=2)&& + (log2Lcommon!=3)) { + printf("Unsupported Common DCI aggregation level %d (should be 2 or 3)\n",log2Lcommon); + exit(-1); + } - break; + break; - case 'N': - format_selector[num_dci] = (DCI_format_t) atoi(optarg); - if ((format_selector[num_dci]<format0) || (format_selector[num_dci] > format1A)) { - printf("only formats 0, 1, and 1A supported for the moment\n"); - exit(-1); - } - if (format_selector[num_dci]==format0) ul_active=1; - if (format_selector[num_dci]==format1A) common_active=1; - if (format_selector[num_dci]==format1) dl_active=1; - num_dci++; - break; + case 'N': + format_selector[num_dci] = (DCI_format_t) atoi(optarg); - case 'O': - osf = atoi(optarg); - break; + if ((format_selector[num_dci]<format0) || (format_selector[num_dci] > format1A)) { + printf("only formats 0, 1, and 1A supported for the moment\n"); + exit(-1); + } - case 'I': - Nid_cell = atoi(optarg); - break; + if (format_selector[num_dci]==format0) ul_active=1; - case 'f': - input_fd = fopen(optarg,"r"); + if (format_selector[num_dci]==format1A) common_active=1; - if (input_fd==NULL) { - printf("Problem with filename %s\n",optarg); - exit(-1); - } + if (format_selector[num_dci]==format1) dl_active=1; - break; + num_dci++; + break; - case 'i': - n_rnti=atoi(optarg); - break; + case 'O': + osf = atoi(optarg); + break; - case 'P': - num_phich_interf=atoi(optarg); - break; + case 'I': + Nid_cell = atoi(optarg); + break; - case 'Y': - perfect_ce = 1; - break; + case 'f': + input_fd = fopen(optarg,"r"); - case 'h': - printf("%s -h(elp) -a(wgn on) -c tdd_config -n n_frames -r RiceanFactor -s snr0 -t Delayspread -x transmission mode (1,2,6) -y TXant -z RXant -L AggregLevelUEspec -M AggregLevelCommonDCI -N DCIFormat\n\n", - argv[0]); - printf("-h This message\n"); - printf("-a Use AWGN channel and not multipath\n"); - printf("-c TDD config\n"); - printf("-S Subframe number (0..9)\n"); - printf("-R N_RB_DL\n"); - printf("-F use FDD frame\n"); - printf("-p Use extended prefix mode\n"); - printf("-n Number of frames to simulate\n"); - printf("-r Ricean factor (dB, 0 means Rayleigh, 100 is almost AWGN\n"); - printf("-s Starting SNR, runs from SNR to SNR + 5 dB. If n_frames is 1 then just SNR is simulated\n"); - printf("-t Delay spread for multipath channel\n"); - printf("-x Transmission mode (1,2,6 for the moment)\n"); - printf("-y Number of TX antennas used in eNB\n"); - printf("-z Number of RX antennas used in UE\n"); - printf("-P Number of interfering PHICH\n"); - printf("-L log2 of Aggregation level for UE Specific DCI (0,1,2,3)\n"); - printf("-M log2 Aggregation level for Common DCI (4,8)\n"); - printf("-N Format for UE Spec DCI (0 - format0,\n"); - printf(" 1 - format1,\n"); - printf(" 2 - format1A,\n"); - printf(" 3 - format1B_2A,\n"); - printf(" 4 - format1B_4A,\n"); - printf(" 5 - format1C,\n"); - printf(" 6 - format1D_2A,\n"); - printf(" 7 - format1D_4A,\n"); - printf(" 8 - format2A_2A_L10PRB,\n"); - printf(" 9 - format2A_2A_M10PRB,\n"); - printf(" 10 - format2A_4A_L10PRB,\n"); - printf(" 11 - format2A_4A_M10PRB,\n"); - printf(" 12 - format2_2A_L10PRB,\n"); - printf(" 13 - format2_2A_M10PRB,\n"); - printf(" 14 - format2_4A_L10PRB,\n"); - printf(" 15 - format2_4A_M10PRB\n"); - printf(" 16 - format2_2D_M10PRB\n"); - printf(" 17 - format2_2D_L10PRB\n"); - printf(" can be called multiple times to add more than one DCI\n"); - printf("-O Oversampling factor\n"); - printf("-I Cell Id\n"); - printf("-F Input sample stream\n"); - exit(1); - break; + if (input_fd==NULL) { + printf("Problem with filename %s\n",optarg); + exit(-1); + } + + break; + + case 'i': + n_rnti=atoi(optarg); + break; + + case 'P': + num_phich_interf=atoi(optarg); + break; + + case 'Y': + perfect_ce = 1; + break; + + case 'h': + printf("%s -h(elp) -a(wgn on) -c tdd_config -n n_frames -r RiceanFactor -s snr0 -t Delayspread -x transmission mode (1,2,6) -y TXant -z RXant -L AggregLevelUEspec -M AggregLevelCommonDCI -N DCIFormat\n\n", + argv[0]); + printf("-h This message\n"); + printf("-a Use AWGN channel and not multipath\n"); + printf("-c TDD config\n"); + printf("-S Subframe number (0..9)\n"); + printf("-R N_RB_DL\n"); + printf("-F use FDD frame\n"); + printf("-p Use extended prefix mode\n"); + printf("-n Number of frames to simulate\n"); + printf("-r Ricean factor (dB, 0 means Rayleigh, 100 is almost AWGN\n"); + printf("-s Starting SNR, runs from SNR to SNR + 5 dB. If n_frames is 1 then just SNR is simulated\n"); + printf("-t Delay spread for multipath channel\n"); + printf("-x Transmission mode (1,2,6 for the moment)\n"); + printf("-y Number of TX antennas used in eNB\n"); + printf("-z Number of RX antennas used in UE\n"); + printf("-P Number of interfering PHICH\n"); + printf("-L log2 of Aggregation level for UE Specific DCI (0,1,2,3)\n"); + printf("-M log2 Aggregation level for Common DCI (4,8)\n"); + printf("-N Format for UE Spec DCI (0 - format0,\n"); + printf(" 1 - format1,\n"); + printf(" 2 - format1A,\n"); + printf(" 3 - format1B_2A,\n"); + printf(" 4 - format1B_4A,\n"); + printf(" 5 - format1C,\n"); + printf(" 6 - format1D_2A,\n"); + printf(" 7 - format1D_4A,\n"); + printf(" 8 - format2A_2A_L10PRB,\n"); + printf(" 9 - format2A_2A_M10PRB,\n"); + printf(" 10 - format2A_4A_L10PRB,\n"); + printf(" 11 - format2A_4A_M10PRB,\n"); + printf(" 12 - format2_2A_L10PRB,\n"); + printf(" 13 - format2_2A_M10PRB,\n"); + printf(" 14 - format2_4A_L10PRB,\n"); + printf(" 15 - format2_4A_M10PRB\n"); + printf(" 16 - format2_2D_M10PRB\n"); + printf(" 17 - format2_2D_L10PRB\n"); + printf(" can be called multiple times to add more than one DCI\n"); + printf("-O Oversampling factor\n"); + printf("-I Cell Id\n"); + printf("-F Input sample stream\n"); + exit(1); + break; } } @@ -701,22 +670,19 @@ int main(int argc, char **argv) n_rx, transmission_mode, extended_prefix_flag, - frame_type, + frame_type, Nid_cell, tdd_config, N_RB_DL, - 0, + 0, osf, perfect_ce); - #ifdef XFORMS fl_initialize (&argc, argv, NULL, 0, 0); form_ue = create_lte_phy_scope_ue(); sprintf (title, "LTE PHY SCOPE UE"); fl_show_form (form_ue->lte_phy_scope_ue, FL_PLACE_HOTSPOT, FL_FULLBORDER, title); #endif - - mac_xface->computeRIV = computeRIV; mac_xface->frame_parms = &eNB->frame_parms; // init_transport_channels(transmission_mode); @@ -727,35 +693,25 @@ int main(int argc, char **argv) snr1 = snr0+8.0; printf("SNR0 %f, SNR1 %f\n",snr0,snr1); - frame_parms = &eNB->frame_parms; printf("Getting %d dcis\n",num_dci); - get_dci(frame_parms, log2L, log2Lcommon, format_selector, num_dci, n_rnti); - txdata = eNB->common_vars.txdata[eNb_id]; - nsymb = (eNB->frame_parms.Ncp == 0) ? 14 : 12; - printf("Subframe %d, FFT Size %d, Extended Prefix %d, Samples per subframe %d, Symbols per subframe %d\n", subframe,NUMBER_OF_OFDM_CARRIERS, eNB->frame_parms.Ncp,eNB->frame_parms.samples_per_tti,nsymb); - eNB2UE = new_channel_desc_scm(eNB->frame_parms.nb_antennas_tx, UE->frame_parms.nb_antennas_rx, channel_model, - N_RB2sampling_rate(eNB->frame_parms.N_RB_DL), - N_RB2channel_bandwidth(eNB->frame_parms.N_RB_DL), + N_RB2sampling_rate(eNB->frame_parms.N_RB_DL), + N_RB2channel_bandwidth(eNB->frame_parms.N_RB_DL), 0, 0, 0); - L1_rxtx_proc_t *proc_rxtx = (subframe == 0)? &eNB->proc.L1_proc: &eNB->proc.L1_proc_tx; - eNB->ulsch[0] = new_eNB_ulsch(MAX_TURBO_ITERATIONS,N_RB_DL,0); UE->ulsch[0] = new_ue_ulsch(N_RB_DL,0); - - proc_rxtx->frame_tx = 0; proc_rxtx->subframe_tx = subframe; @@ -765,7 +721,7 @@ int main(int argc, char **argv) i=0; while (!feof(input_fd)) { - ret=fscanf(input_fd,"%s %s",input_val_str,input_val_str2);//&input_val1,&input_val2); + ret=fscanf(input_fd,"%49s %49s",input_val_str,input_val_str2);//&input_val1,&input_val2); if (ret != 2) { printf("%s:%d:%s: fscanf error, exiting\n", __FILE__, __LINE__, __FUNCTION__); @@ -773,11 +729,11 @@ int main(int argc, char **argv) } if ((i%4)==0) { - ((short*)txdata[0])[i/2] = (short)((1<<15)*strtod(input_val_str,NULL)); - ((short*)txdata[0])[(i/2)+1] = (short)((1<<15)*strtod(input_val_str2,NULL)); + ((short *)txdata[0])[i/2] = (short)((1<<15)*strtod(input_val_str,NULL)); + ((short *)txdata[0])[(i/2)+1] = (short)((1<<15)*strtod(input_val_str2,NULL)); if ((i/4)<100) - printf("sample %d => %e + j%e (%d +j%d)\n",i/4,strtod(input_val_str,NULL),strtod(input_val_str2,NULL),((short*)txdata[0])[i/4],((short*)txdata[0])[(i/4)+1]);//1,input_val2,); + printf("sample %d => %e + j%e (%d +j%d)\n",i/4,strtod(input_val_str,NULL),strtod(input_val_str2,NULL),((short *)txdata[0])[i/4],((short *)txdata[0])[(i/4)+1]); //1,input_val2,); } i++; @@ -794,7 +750,6 @@ int main(int argc, char **argv) tx_lev_dB = (unsigned int) dB_fixed(tx_lev); } - UE->UE_mode[0] = PUSCH; // nCCE_max = get_nCCE(3,&eNB->frame_parms,get_mi(&eNB->frame_parms,0)); @@ -802,8 +757,6 @@ int main(int argc, char **argv) //printf("num_phich interferers %d\n",num_phich_interf); for (SNR=snr0; SNR<snr1; SNR+=0.2) { - - n_errors_common = 0; n_errors_ul = 0; n_errors_dl = 0; @@ -814,14 +767,11 @@ int main(int argc, char **argv) n_trials_dl=0; for (trial=0; trial<n_frames; trial++) { - // printf("DCI (SF %d): txdataF %p (0 %p)\n",subframe,&eNB->common_vars.txdataF[eNb_id][aa][512*14*subframe],&eNB->common_vars.txdataF[eNb_id][aa][0]); for (aa=0; aa<eNB->frame_parms.nb_antennas_tx; aa++) { memset(&eNB->common_vars.txdataF[eNb_id][aa][0],0,FRAME_LENGTH_COMPLEX_SAMPLES_NO_PREFIX*sizeof(int32_t)); - } - generate_pilots_slot(eNB, eNB->common_vars.txdataF[eNb_id], AMP, //1024, @@ -833,24 +783,26 @@ int main(int argc, char **argv) (subframe*2)+1, 0); - if (input_fd == NULL) { numCCE=0; n_trials_common++; common_active = 1; - if (eNB->frame_parms.N_RB_DL >= 50) { - if (ul_active==1) { - n_trials_ul++; - } - } - if (eNB->frame_parms.N_RB_DL >= 25) { - if (dl_active==1) { - n_trials_dl++; - } - } + + if (eNB->frame_parms.N_RB_DL >= 50) { + if (ul_active==1) { + n_trials_ul++; + } + } + + if (eNB->frame_parms.N_RB_DL >= 25) { + if (dl_active==1) { + n_trials_dl++; + } + } + num_pdcch_symbols = get_num_pdcch_symbols(DCI_pdu.Num_dci, DCI_pdu.dci_alloc, frame_parms, subframe); - numCCE = get_nCCE(num_pdcch_symbols,&eNB->frame_parms,get_mi(&eNB->frame_parms,subframe)); + numCCE = get_nCCE(num_pdcch_symbols,&eNB->frame_parms,get_mi(&eNB->frame_parms,subframe)); if (n_frames==1) { printf("num_dci %d, num_pddch_symbols %d, nCCE %d\n", @@ -859,35 +811,35 @@ int main(int argc, char **argv) } // apply RNTI-based nCCE allocation - memset(CCE_table,0,800*sizeof(int)); + memset(CCE_table,0,800*sizeof(int)); for (i = 0; i < DCI_pdu.Num_dci; i++) { // SI RNTI if (DCI_pdu.dci_alloc[i].rnti == SI_RNTI) { DCI_pdu.dci_alloc[i].firstCCE = get_nCCE_offset_l1(CCE_table, - 1<<DCI_pdu.dci_alloc[i].L, - numCCE, - 1, - SI_RNTI, - subframe); + 1<<DCI_pdu.dci_alloc[i].L, + numCCE, + 1, + SI_RNTI, + subframe); } // RA RNTI else if (DCI_pdu.dci_alloc[i].ra_flag == 1) { DCI_pdu.dci_alloc[i].firstCCE = get_nCCE_offset_l1(CCE_table, - 1<<DCI_pdu.dci_alloc[i].L, - numCCE, - 1, - DCI_pdu.dci_alloc[i].rnti, - subframe); + 1<<DCI_pdu.dci_alloc[i].L, + numCCE, + 1, + DCI_pdu.dci_alloc[i].rnti, + subframe); } // C RNTI else { DCI_pdu.dci_alloc[i].firstCCE = get_nCCE_offset_l1(CCE_table, - 1<<DCI_pdu.dci_alloc[i].L, - numCCE, - 0, - DCI_pdu.dci_alloc[i].rnti, - subframe); + 1<<DCI_pdu.dci_alloc[i].L, + numCCE, + 0, + DCI_pdu.dci_alloc[i].rnti, + subframe); } if (n_frames==1) @@ -914,19 +866,16 @@ int main(int argc, char **argv) printf("generating PHICH\n"); harq_pid = phich_subframe_to_harq_pid(&eNB->frame_parms, proc_rxtx->frame_tx, subframe); - phich_ACK = taus()&1; eNB->ulsch[0]->harq_processes[harq_pid]->phich_active = 1; eNB->ulsch[0]->harq_processes[harq_pid]->first_rb = 0; eNB->ulsch[0]->harq_processes[harq_pid]->n_DMRS = 0; eNB->ulsch[0]->harq_processes[harq_pid]->phich_ACK = phich_ACK; eNB->ulsch[0]->harq_processes[harq_pid]->dci_alloc = 1; - UE->ulsch[0]->harq_processes[harq_pid]->first_rb = 0; UE->ulsch[0]->harq_processes[harq_pid]->n_DMRS = 0; - generate_phich_top(eNB,proc_rxtx,AMP,0); - + // generate 3 interfering PHICH if (num_phich_interf>0) { eNB->ulsch[0]->harq_processes[harq_pid]->first_rb = 4; @@ -938,15 +887,14 @@ int main(int argc, char **argv) eNB->ulsch[0]->harq_processes[harq_pid]->n_DMRS = 1; generate_phich_top(eNB,proc_rxtx,1024,0); } + if (num_phich_interf>2) { eNB->ulsch[0]->harq_processes[harq_pid]->first_rb = 12; eNB->ulsch[0]->harq_processes[harq_pid]->n_DMRS = 1; generate_phich_top(eNB,proc_rxtx,1024,0); - } eNB->ulsch[0]->harq_processes[harq_pid]->first_rb = 0; - } // LOG_M("pilotsF.m","rsF",txdataF[0],lte_eNB->frame_parms.ofdm_symbol_size,1,1); @@ -960,7 +908,6 @@ int main(int argc, char **argv) tx_lev = 0; - for (aa=0; aa<eNB->frame_parms.nb_antenna_ports_eNB; aa++) { if (eNB->frame_parms.Ncp == 1) PHY_ofdm_mod(&eNB->common_vars.txdataF[eNb_id][aa][subframe*nsymb*eNB->frame_parms.ofdm_symbol_size], // input, @@ -1002,15 +949,12 @@ int main(int argc, char **argv) } } - - if (awgn_flag == 0) { multipath_channel(eNB2UE,s_re,s_im,r_re,r_im, 2*nsymb*OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES,0); } //LOG_M("channel0.m","chan0",ch[0],channel_length,1,8); - // scale by path_loss = NOW - P_noise //sigma2 = pow(10,sigma2_dB/10); //N0W = -95.87; @@ -1025,9 +969,8 @@ int main(int argc, char **argv) // printf("Sigma2 %f (sigma2_dB %f)\n",sigma2,sigma2_dB); for (i=0; i<2*nsymb*OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES; i++) { for (aa=0; aa<UE->frame_parms.nb_antennas_rx; aa++) { - - ((short*) UE->common_vars.rxdata[aa])[(2*subframe*UE->frame_parms.samples_per_tti) + 2*i] = (short) (.667*(r_re[aa][i] + sqrt(sigma2/2)*gaussdouble(0.0,1.0))); - ((short*) UE->common_vars.rxdata[aa])[(2*subframe*UE->frame_parms.samples_per_tti) + 2*i+1] = (short) (.667*(r_im[aa][i] + (iqim*r_re[aa][i]) + sqrt(sigma2/2)*gaussdouble( + ((short *) UE->common_vars.rxdata[aa])[(2*subframe*UE->frame_parms.samples_per_tti) + 2*i] = (short) (.667*(r_re[aa][i] + sqrt(sigma2/2)*gaussdouble(0.0,1.0))); + ((short *) UE->common_vars.rxdata[aa])[(2*subframe*UE->frame_parms.samples_per_tti) + 2*i+1] = (short) (.667*(r_im[aa][i] + (iqim*r_re[aa][i]) + sqrt(sigma2/2)*gaussdouble( 0.0,1.0))); /* ((short*)UE->common_vars.rxdata[aa])[(2*subframe*UE->frame_parms.samples_per_tti) + 2*i] = @@ -1040,16 +983,14 @@ int main(int argc, char **argv) // UE receiver for (l=0; l<eNB->frame_parms.symbols_per_tti; l++) { - // subframe_offset = (l/eNB->frame_parms.symbols_per_tti)*eNB->frame_parms.samples_per_tti; // printf("subframe_offset = %d\n",subframe_offset); - slot_fep(UE, l%(eNB->frame_parms.symbols_per_tti/2), (2*subframe)+(l/(eNB->frame_parms.symbols_per_tti/2)), 0, 0, - 0); + 0); if (UE->perfect_ce == 1) { if (awgn_flag==0) { @@ -1083,12 +1024,9 @@ int main(int argc, char **argv) } if (l==((eNB->frame_parms.Ncp==0)?4:3)) { - // LOG_M("H00.m","h00",&(UE->common_vars.dl_ch_estimates[0][0][0]),((frame_parms->Ncp==0)?7:6)*(eNB->frame_parms.ofdm_symbol_size),1,1); - // do PDCCH procedures here UE->pdcch_vars[0][0]->crnti = n_rnti; - // printf("Doing RX : num_pdcch_symbols at TX %d\n",num_pdcch_symbols); rx_pdcch(UE, trial, @@ -1102,7 +1040,7 @@ int main(int argc, char **argv) UE->ulsch[0]->harq_processes[phich_subframe_to_harq_pid(&UE->frame_parms,0,subframe)]->status = ACTIVE; //UE->ulsch[0]->harq_processes[phich_subframe_to_harq_pid(&UE->frame_parms,0,subframe)]->Ndi = 1; rx_phich(UE, - &UE->proc.proc_rxtx[subframe&1], + &UE->proc.proc_rxtx[subframe&1], subframe, 0); } @@ -1112,7 +1050,6 @@ int main(int argc, char **argv) dci_cnt = dci_decoding_procedure(UE, dci_alloc_rx,1, 0,subframe); - common_rx=0; ul_rx=0; dl_rx=0; @@ -1179,7 +1116,6 @@ int main(int argc, char **argv) if (n_errors_cfi > 10) break; } - } // symbol loop if (n_errors_cfi > 100) @@ -1193,17 +1129,17 @@ int main(int argc, char **argv) UE, eNb_id,0,subframe); #endif - } //trials - + if (common_active) printf("SNR %f : n_errors_common = %d/%d (%e)\n", SNR,n_errors_common,n_trials_common,(double)n_errors_common/n_trials_common); + if (ul_active==1) printf("SNR %f : n_errors_ul = %d/%d (%e)\n", SNR,n_errors_ul,n_trials_ul,(double)n_errors_ul/n_trials_ul); + if (dl_active==1) printf("SNR %f : n_errors_dl = %d/%d (%e)\n", SNR,n_errors_dl,n_trials_dl,(double)n_errors_dl/n_trials_dl); + printf("SNR %f : n_errors_cfi = %d/%d (%e)\n", SNR,n_errors_cfi,trial,(double)n_errors_cfi/trial); printf("SNR %f : n_errors_hi = %d/%d (%e)\n", SNR,n_errors_hi,trial,(double)n_errors_hi/trial); - } // SNR - if (n_frames==1) { LOG_M("txsig0.m","txs0", txdata[0],FRAME_LENGTH_COMPLEX_SAMPLES,1,1); @@ -1231,9 +1167,11 @@ int main(int argc, char **argv) lte_sync_time_free(); - return(n_errors_ul); + if ( input_fd != NULL) + fclose(input_fd); - } + return(n_errors_ul); +} diff --git a/openair1/SIMULATION/LTE_PHY/prachsim.c b/openair1/SIMULATION/LTE_PHY/prachsim.c index 7475017d85becb53cb083ee93165c49795302d17..0771917bfba865ac0daacad3e7f0d75303ff4a69 100644 --- a/openair1/SIMULATION/LTE_PHY/prachsim.c +++ b/openair1/SIMULATION/LTE_PHY/prachsim.c @@ -48,11 +48,8 @@ extern uint16_t prach_root_sequence_map0_3[838]; void dump_prach_config(LTE_DL_FRAME_PARMS *frame_parms,uint8_t subframe); -int main(int argc, char **argv) -{ - +int main(int argc, char **argv) { char c; - int i,aa,aarx; double sigma2, sigma2_dB=0,SNR,snr0=-2.0,snr1=0.0,ue_speed0=0.0,ue_speed1=0.0; uint8_t snr1set=0; @@ -64,7 +61,6 @@ int main(int argc, char **argv) int trial; //, ntrials=1; uint8_t transmission_mode = 1,n_tx=1,n_rx=1; uint16_t Nid_cell=0; - uint8_t awgn_flag=0; uint8_t hs_flag=0; int n_frames=1; @@ -73,9 +69,7 @@ int main(int argc, char **argv) uint8_t extended_prefix_flag=0; // int8_t interf1=-19,interf2=-19; LTE_DL_FRAME_PARMS *frame_parms; - SCM_t channel_model=Rayleigh1; - // uint8_t abstraction_flag=0,calibration_flag=0; // double prach_sinr; uint8_t osf=1,N_RB_DL=25; @@ -91,211 +85,212 @@ int main(int argc, char **argv) double ue_speed = 0; int NCS_config = 1,rootSequenceIndex=0; int threequarter_fs = 0; - cpuf = get_cpu_freq_GHz(); - logInit(); - number_of_cards = 1; - - while ((c = getopt (argc, argv, "hHaA:Cr:p:g:n:s:S:t:x:y:v:V:z:N:F:d:Z:L:R:E")) != -1) { switch (c) { - case 'a': - printf("Running AWGN simulation\n"); - awgn_flag = 1; - /* ntrials not used later, no need to set */ - //ntrials=1; - break; - - case 'd': - delay = atoi(optarg); - break; - - case 'g': - switch((char)*optarg) { - case 'A': - channel_model=SCM_A; + case 'a': + printf("Running AWGN simulation\n"); + awgn_flag = 1; + /* ntrials not used later, no need to set */ + //ntrials=1; break; - case 'B': - channel_model=SCM_B; + case 'd': + delay = atoi(optarg); break; - case 'C': - channel_model=SCM_C; - break; + case 'g': + switch((char)*optarg) { + case 'A': + channel_model=SCM_A; + break; - case 'D': - channel_model=SCM_D; - break; + case 'B': + channel_model=SCM_B; + break; - case 'E': - channel_model=EPA; - break; + case 'C': + channel_model=SCM_C; + break; - case 'F': - channel_model=EVA; - break; + case 'D': + channel_model=SCM_D; + break; - case 'G': - channel_model=ETU; - break; + case 'E': + channel_model=EPA; + break; - case 'H': - channel_model=Rayleigh8; + case 'F': + channel_model=EVA; + break; - case 'I': - channel_model=Rayleigh1; + case 'G': + channel_model=ETU; + break; - case 'J': - channel_model=Rayleigh1_corr; + case 'H': + channel_model=Rayleigh8; + break; - case 'K': - channel_model=Rayleigh1_anticorr; + case 'I': + channel_model=Rayleigh1; + break; - case 'L': - channel_model=Rice8; + case 'J': + channel_model=Rayleigh1_corr; + break; - case 'M': - channel_model=Rice1; + case 'K': + channel_model=Rayleigh1_anticorr; + break; + + case 'L': + channel_model=Rice8; + break; + + case 'M': + channel_model=Rice1; + break; + + case 'N': + channel_model=Rayleigh1_800; + break; + + default: + msg("Unsupported channel model!\n"); + exit(-1); + } - case 'N': - channel_model=Rayleigh1_800; break; - default: - msg("Unsupported channel model!\n"); - exit(-1); - } + case 'E': + threequarter_fs=1; + break; - break; + case 'n': + n_frames = atoi(optarg); + break; - case 'E': - threequarter_fs=1; - break; + case 's': + snr0 = atof(optarg); + msg("Setting SNR0 to %f\n",snr0); + break; - case 'n': - n_frames = atoi(optarg); - break; + case 'S': + snr1 = atof(optarg); + snr1set=1; + msg("Setting SNR1 to %f\n",snr1); + break; - case 's': - snr0 = atof(optarg); - msg("Setting SNR0 to %f\n",snr0); - break; + case 'p': + preamble_tx=atoi(optarg); + break; - case 'S': - snr1 = atof(optarg); - snr1set=1; - msg("Setting SNR1 to %f\n",snr1); - break; + case 'v': + ue_speed0 = atoi(optarg); + break; - case 'p': - preamble_tx=atoi(optarg); - break; + case 'V': + ue_speed1 = atoi(optarg); + ue_speed1set = 1; + break; - case 'v': - ue_speed0 = atoi(optarg); - break; + case 'Z': + NCS_config = atoi(optarg); - case 'V': - ue_speed1 = atoi(optarg); - ue_speed1set = 1; - break; + if ((NCS_config > 15) || (NCS_config < 0)) + printf("Illegal NCS_config %d, (should be 0-15)\n",NCS_config); - case 'Z': - NCS_config = atoi(optarg); + break; - if ((NCS_config > 15) || (NCS_config < 0)) - printf("Illegal NCS_config %d, (should be 0-15)\n",NCS_config); + case 'H': + printf("High-Speed Flag enabled\n"); + hs_flag = 1; + break; - break; + case 'L': + rootSequenceIndex = atoi(optarg); - case 'H': - printf("High-Speed Flag enabled\n"); - hs_flag = 1; - break; + if ((rootSequenceIndex < 0) || (rootSequenceIndex > 837)) + printf("Illegal rootSequenceNumber %d, (should be 0-837)\n",rootSequenceIndex); - case 'L': - rootSequenceIndex = atoi(optarg); + break; - if ((rootSequenceIndex < 0) || (rootSequenceIndex > 837)) - printf("Illegal rootSequenceNumber %d, (should be 0-837)\n",rootSequenceIndex); + case 'x': + transmission_mode=atoi(optarg); - break; + if ((transmission_mode!=1) && + (transmission_mode!=2) && + (transmission_mode!=6)) { + msg("Unsupported transmission mode %d\n",transmission_mode); + exit(-1); + } - case 'x': - transmission_mode=atoi(optarg); + break; - if ((transmission_mode!=1) && - (transmission_mode!=2) && - (transmission_mode!=6)) { - msg("Unsupported transmission mode %d\n",transmission_mode); - exit(-1); - } + case 'y': + n_tx=atoi(optarg); - break; + if ((n_tx==0) || (n_tx>2)) { + msg("Unsupported number of tx antennas %d\n",n_tx); + exit(-1); + } - case 'y': - n_tx=atoi(optarg); + break; - if ((n_tx==0) || (n_tx>2)) { - msg("Unsupported number of tx antennas %d\n",n_tx); - exit(-1); - } + case 'z': + n_rx=atoi(optarg); - break; + if ((n_rx==0) || (n_rx>2)) { + msg("Unsupported number of rx antennas %d\n",n_rx); + exit(-1); + } - case 'z': - n_rx=atoi(optarg); + break; - if ((n_rx==0) || (n_rx>2)) { - msg("Unsupported number of rx antennas %d\n",n_rx); - exit(-1); - } + case 'N': + Nid_cell = atoi(optarg); + break; + + case 'R': + N_RB_DL = atoi(optarg); + break; - break; - - case 'N': - Nid_cell = atoi(optarg); - break; - - case 'R': - N_RB_DL = atoi(optarg); - break; - - case 'O': - osf = atoi(optarg); - break; - - case 'F': - break; - - default: - case 'h': - printf("%s -h(elp) -a(wgn on) -p(extended_prefix) -N cell_id -f output_filename -F input_filename -g channel_model -n n_frames -s snr0 -S snr1 -x transmission_mode -y TXant -z RXant -i Intefrence0 -j Interference1 -A interpolation_file -C(alibration offset dB) -N CellId\n", - argv[0]); - printf("-h This message\n"); - printf("-a Use AWGN channel and not multipath\n"); - printf("-n Number of frames to simulate\n"); - printf("-s Starting SNR, runs from SNR0 to SNR0 + 5 dB. If n_frames is 1 then just SNR is simulated\n"); - printf("-S Ending SNR, runs from SNR0 to SNR1\n"); - printf("-g [A,B,C,D,E,F,G,I,N] Use 3GPP SCM (A,B,C,D) or 36-101 (E-EPA,F-EVA,G-ETU) or Rayleigh1 (I) or Rayleigh1_800 (N) models (ignores delay spread and Ricean factor)\n"); - printf("-z Number of RX antennas used in eNB\n"); - printf("-N Nid_cell\n"); - printf("-O oversampling factor (1,2,4,8,16)\n"); - // printf("-f PRACH format (0=1,1=2,2=3,3=4)\n"); - printf("-d Channel delay \n"); - printf("-v Starting UE velocity in km/h, runs from 'v' to 'v+50km/h'. If n_frames is 1 just 'v' is simulated \n"); - printf("-V Ending UE velocity in km/h, runs from 'v' to 'V'"); - printf("-L rootSequenceIndex (0-837)\n"); - printf("-Z NCS_config (ZeroCorrelationZone) (0-15)\n"); - printf("-H Run with High-Speed Flag enabled \n"); - printf("-R Number of PRB (6,15,25,50,75,100)\n"); - printf("-F Input filename (.txt format) for RX conformance testing\n"); - exit (-1); - break; + case 'O': + osf = atoi(optarg); + break; + + case 'F': + break; + + default: + case 'h': + printf("%s -h(elp) -a(wgn on) -p(extended_prefix) -N cell_id -f output_filename -F input_filename -g channel_model -n n_frames -s snr0 -S snr1 -x transmission_mode -y TXant -z RXant -i Intefrence0 -j Interference1 -A interpolation_file -C(alibration offset dB) -N CellId\n", + argv[0]); + printf("-h This message\n"); + printf("-a Use AWGN channel and not multipath\n"); + printf("-n Number of frames to simulate\n"); + printf("-s Starting SNR, runs from SNR0 to SNR0 + 5 dB. If n_frames is 1 then just SNR is simulated\n"); + printf("-S Ending SNR, runs from SNR0 to SNR1\n"); + printf("-g [A,B,C,D,E,F,G,I,N] Use 3GPP SCM (A,B,C,D) or 36-101 (E-EPA,F-EVA,G-ETU) or Rayleigh1 (I) or Rayleigh1_800 (N) models (ignores delay spread and Ricean factor)\n"); + printf("-z Number of RX antennas used in eNB\n"); + printf("-N Nid_cell\n"); + printf("-O oversampling factor (1,2,4,8,16)\n"); + // printf("-f PRACH format (0=1,1=2,2=3,3=4)\n"); + printf("-d Channel delay \n"); + printf("-v Starting UE velocity in km/h, runs from 'v' to 'v+50km/h'. If n_frames is 1 just 'v' is simulated \n"); + printf("-V Ending UE velocity in km/h, runs from 'v' to 'V'"); + printf("-L rootSequenceIndex (0-837)\n"); + printf("-Z NCS_config (ZeroCorrelationZone) (0-15)\n"); + printf("-H Run with High-Speed Flag enabled \n"); + printf("-R Number of PRB (6,15,25,50,75,100)\n"); + printf("-F Input filename (.txt format) for RX conformance testing\n"); + exit (-1); + break; } } @@ -304,17 +299,16 @@ int main(int argc, char **argv) lte_param_init(n_tx, n_tx, - n_rx, - transmission_mode, - extended_prefix_flag, - FDD, - Nid_cell, - 3, - N_RB_DL, - threequarter_fs, - osf, - 0); - + n_rx, + transmission_mode, + extended_prefix_flag, + FDD, + Nid_cell, + 3, + N_RB_DL, + threequarter_fs, + osf, + 0); if (snr1set==0) { if (n_frames==1) @@ -331,30 +325,22 @@ int main(int argc, char **argv) } printf("SNR0 %f, SNR1 %f\n",snr0,snr1); - frame_parms = &eNB->frame_parms; - - txdata = UE->common_vars.txdata; printf("txdata %p\n",&txdata[0][subframe*frame_parms->samples_per_tti]); - - s_re = malloc(2*sizeof(double*)); - s_im = malloc(2*sizeof(double*)); - r_re = malloc(2*sizeof(double*)); - r_im = malloc(2*sizeof(double*)); + s_re = malloc(2*sizeof(double *)); + s_im = malloc(2*sizeof(double *)); + r_re = malloc(2*sizeof(double *)); + r_im = malloc(2*sizeof(double *)); nsymb = (frame_parms->Ncp == 0) ? 14 : 12; - printf("FFT Size %d, Extended Prefix %d, Samples per subframe %d, Symbols per subframe %d\n",NUMBER_OF_OFDM_CARRIERS, frame_parms->Ncp,frame_parms->samples_per_tti,nsymb); - - - msg("[SIM] Using SCM/101\n"); UE2eNB = new_channel_desc_scm(UE->frame_parms.nb_antennas_tx, eNB->frame_parms.nb_antennas_rx, channel_model, - N_RB2sampling_rate(eNB->frame_parms.N_RB_UL), - N_RB2channel_bandwidth(eNB->frame_parms.N_RB_UL), + N_RB2sampling_rate(eNB->frame_parms.N_RB_UL), + N_RB2channel_bandwidth(eNB->frame_parms.N_RB_UL), 0.0, delay, 0); @@ -365,12 +351,10 @@ int main(int argc, char **argv) } for (i=0; i<2; i++) { - s_re[i] = malloc(FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double)); bzero(s_re[i],FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double)); s_im[i] = malloc(FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double)); bzero(s_im[i],FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double)); - r_re[i] = malloc(FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double)); bzero(r_re[i],FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double)); r_im[i] = malloc(FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double)); @@ -382,30 +366,22 @@ int main(int argc, char **argv) UE->frame_parms.prach_config_common.prach_ConfigInfo.zeroCorrelationZoneConfig=NCS_config; UE->frame_parms.prach_config_common.prach_ConfigInfo.highSpeedFlag=hs_flag; UE->frame_parms.prach_config_common.prach_ConfigInfo.prach_FreqOffset=0; - - eNB->frame_parms.prach_config_common.rootSequenceIndex=rootSequenceIndex; eNB->frame_parms.prach_config_common.prach_ConfigInfo.prach_ConfigIndex=0; eNB->frame_parms.prach_config_common.prach_ConfigInfo.zeroCorrelationZoneConfig=NCS_config; eNB->frame_parms.prach_config_common.prach_ConfigInfo.highSpeedFlag=hs_flag; eNB->frame_parms.prach_config_common.prach_ConfigInfo.prach_FreqOffset=0; - eNB->node_function = eNodeB_3GPP; eNB->proc.subframe_rx = subframe; eNB->proc.subframe_prach = subframe; - /* N_ZC not used later, so prach_fmt is also useless, don't set */ //prach_fmt = get_prach_fmt(eNB->frame_parms.prach_config_common.prach_ConfigInfo.prach_ConfigIndex, // eNB->frame_parms.frame_type); /* N_ZC not used later, no need to set */ //N_ZC = (prach_fmt <4)?839:139; - compute_prach_seq(&eNB->frame_parms.prach_config_common,eNB->frame_parms.frame_type,eNB->X_u); - compute_prach_seq(&UE->frame_parms.prach_config_common,UE->frame_parms.frame_type,UE->X_u); - UE->prach_vars[0]->amp = AMP; - UE->prach_resources[0] = &prach_resources; if (preamble_tx == 99) @@ -416,18 +392,14 @@ int main(int argc, char **argv) UE->prach_resources[0]->ra_PreambleIndex = preamble_tx; UE->prach_resources[0]->ra_TDD_map_index = 0; - tx_lev = generate_prach(UE, 0, //eNB_id, subframe, 0); //Nf - /* tx_lev_dB not used later, no need to set */ //tx_lev_dB = (unsigned int) dB_fixed(tx_lev); - LOG_M("txsig0_new.m","txs0", &txdata[0][subframe*frame_parms->samples_per_tti],frame_parms->samples_per_tti,1,1); //LOG_M("txsig1.m","txs1", txdata[1],FRAME_LENGTH_COMPLEX_SAMPLES,1,1); - // multipath channel dump_prach_config(&eNB->frame_parms,subframe); @@ -450,8 +422,6 @@ int main(int argc, char **argv) } } - - for (SNR=snr0; SNR<snr1; SNR+=.2) { for (ue_speed=ue_speed0; ue_speed<ue_speed1; ue_speed+=10) { delay_avg = 0.0; @@ -461,7 +431,6 @@ int main(int argc, char **argv) prach_errors=0; for (trial=0; trial<n_frames; trial++) { - sigma2_dB = 10*log10((double)tx_lev) - SNR; if (n_frames==1) @@ -471,7 +440,6 @@ int main(int argc, char **argv) sigma2 = pow(10,sigma2_dB/10); // printf("Sigma2 %f (sigma2_dB %f)\n",sigma2,sigma2_dB); - if (awgn_flag == 0) { multipath_tv_channel(UE2eNB,s_re,s_im,r_re,r_im, 2*frame_parms->samples_per_tti,0); @@ -485,9 +453,8 @@ int main(int argc, char **argv) for (i=0; i<frame_parms->samples_per_tti; i++) { for (aa=0; aa<eNB->frame_parms.nb_antennas_rx; aa++) { - - ((short*) &eNB->common_vars.rxdata[0][aa][subframe*frame_parms->samples_per_tti])[2*i] = (short) (.167*(r_re[aa][i] +sqrt(sigma2/2)*gaussdouble(0.0,1.0))); - ((short*) &eNB->common_vars.rxdata[0][aa][subframe*frame_parms->samples_per_tti])[2*i+1] = (short) (.167*(r_im[aa][i] + (iqim*r_re[aa][i]) + sqrt(sigma2/2)*gaussdouble(0.0,1.0))); + ((short *) &eNB->common_vars.rxdata[0][aa][subframe*frame_parms->samples_per_tti])[2*i] = (short) (.167*(r_re[aa][i] +sqrt(sigma2/2)*gaussdouble(0.0,1.0))); + ((short *) &eNB->common_vars.rxdata[0][aa][subframe*frame_parms->samples_per_tti])[2*i+1] = (short) (.167*(r_im[aa][i] + (iqim*r_re[aa][i]) + sqrt(sigma2/2)*gaussdouble(0.0,1.0))); } } @@ -496,7 +463,6 @@ int main(int argc, char **argv) preamble_delay_list, 0, //Nf 0); //tdd_mapindex - preamble_energy_max = preamble_energy_list[0]; preamble_max = 0; @@ -524,8 +490,8 @@ int main(int argc, char **argv) LOG_M("prach0.m","prach0", &txdata[0][subframe*frame_parms->samples_per_tti],frame_parms->samples_per_tti,1,1); LOG_M("prachF0.m","prachF0", &eNB->prach_vars.prachF[0],24576,1,1); LOG_M("rxsig0.m","rxs0", - &eNB->common_vars.rxdata[0][0][subframe*frame_parms->samples_per_tti], - frame_parms->samples_per_tti,1,1); + &eNB->common_vars.rxdata[0][0][subframe*frame_parms->samples_per_tti], + frame_parms->samples_per_tti,1,1); LOG_M("rxsigF0.m","rxsF0", eNB->prach_vars.rxsigF[0],6144,1,1); LOG_M("prach_preamble.m","prachp",&eNB->X_u[0],839,1,1); } @@ -539,7 +505,6 @@ int main(int argc, char **argv) // printf("(%f,%f)\n",SNR,(double)prach_errors/(double)n_frames); } //SNR loop - for (i=0; i<2; i++) { free(s_re[i]); free(s_im[i]); @@ -551,11 +516,8 @@ int main(int argc, char **argv) free(s_im); free(r_re); free(r_im); - lte_sync_time_free(); - return(0); - } diff --git a/openair1/SIMULATION/LTE_PHY/pucchsim.c b/openair1/SIMULATION/LTE_PHY/pucchsim.c index ad236a6f7568bb9a7d6aeb4a81195bf48a60039e..a58f844945706b37c30457494964734f55540502 100644 --- a/openair1/SIMULATION/LTE_PHY/pucchsim.c +++ b/openair1/SIMULATION/LTE_PHY/pucchsim.c @@ -45,37 +45,29 @@ PHY_VARS_UE *UE; double cpuf; -int main(int argc, char **argv) -{ - +int main(int argc, char **argv) { char c; - int i,l,aa; double sigma2, sigma2_dB=0,SNR,snr0=-2.0,snr1=0.0; uint8_t snr1set=0; //mod_sym_t **txdataF; int **txdata; double s_re0[30720],s_re1[30720],s_im0[30720],s_im1[30720],r_re0[30720],r_im0[30720],r_re1[30720],r_im1[30720]; - double *s_re[2]={s_re0,s_re1}; - double *s_im[2]={s_im0,s_im1}; - double *r_re[2]={r_re0,r_re1}; - double *r_im[2]={r_im0,r_im1}; + double *s_re[2]= {s_re0,s_re1}; + double *s_im[2]= {s_im0,s_im1}; + double *r_re[2]= {r_re0,r_re1}; + double *r_im[2]= {r_im0,r_im1}; double ricean_factor=0.0000005,iqim=0.0; - int trial, n_trials, ntrials=1, n_errors; uint8_t transmission_mode = 1,n_tx=1,n_rx=1; unsigned char eNB_id = 0; uint16_t Nid_cell=0; - int n_frames=1; channel_desc_t *UE2eNB; uint32_t nsymb,tx_lev; uint8_t extended_prefix_flag=0; - LTE_DL_FRAME_PARMS *frame_parms; - SCM_t channel_model=Rayleigh1_corr; - // double pucch_sinr; uint8_t osf=1,N_RB_DL=25; uint32_t pucch_tx=0,pucch1_missed=0,pucch1_false=0,pucch3_false=0,sig; @@ -90,202 +82,203 @@ int main(int argc, char **argv) double stat_no_sig,stat_sig; uint8_t N0=40; uint8_t pucch1_thres=10; - uint16_t n1_pucch = 0; uint16_t n2_pucch = 0; uint16_t n3_pucch = 20; - uint16_t n_rnti=0x1234; - number_of_cards = 1; - cpuf = get_cpu_freq_GHz(); while ((c = getopt (argc, argv, "har:pf:g:n:s:S:x:y:z:N:F:T:R:")) != -1) { switch (c) { - case 'a': - printf("Running AWGN simulation\n"); - channel_model = AWGN; - ntrials=1; - break; - - case 'f': - if (atoi(optarg)==0) - pucch_format = pucch_format1; - else if (atoi(optarg)==1) - pucch_format = pucch_format1a; - else if (atoi(optarg)==2) - pucch_format = pucch_format1b; - else if (atoi(optarg)==6) // 3,4,5 is reserved for format2,2a,2b - pucch_format = pucch_format3; - else { - printf("Unsupported pucch_format %d\n",atoi(optarg)); - exit(-1); - } + case 'a': + printf("Running AWGN simulation\n"); + channel_model = AWGN; + ntrials=1; + break; - break; + case 'f': + if (atoi(optarg)==0) + pucch_format = pucch_format1; + else if (atoi(optarg)==1) + pucch_format = pucch_format1a; + else if (atoi(optarg)==2) + pucch_format = pucch_format1b; + else if (atoi(optarg)==6) // 3,4,5 is reserved for format2,2a,2b + pucch_format = pucch_format3; + else { + printf("Unsupported pucch_format %d\n",atoi(optarg)); + exit(-1); + } - case 'g': - switch((char)*optarg) { - case 'A': - channel_model=SCM_A; break; - case 'B': - channel_model=SCM_B; - break; + case 'g': + switch((char)*optarg) { + case 'A': + channel_model=SCM_A; + break; - case 'C': - channel_model=SCM_C; - break; + case 'B': + channel_model=SCM_B; + break; - case 'D': - channel_model=SCM_D; - break; + case 'C': + channel_model=SCM_C; + break; - case 'E': - channel_model=EPA; - break; + case 'D': + channel_model=SCM_D; + break; - case 'F': - channel_model=EVA; - break; + case 'E': + channel_model=EPA; + break; - case 'G': - channel_model=ETU; - break; + case 'F': + channel_model=EVA; + break; + + case 'G': + channel_model=ETU; + break; + + case 'H': + channel_model=Rayleigh8; + break; - case 'H': - channel_model=Rayleigh8; + case 'I': + channel_model=Rayleigh1; + break; - case 'I': - channel_model=Rayleigh1; + case 'J': + channel_model=Rayleigh1_corr; + break; - case 'J': - channel_model=Rayleigh1_corr; + case 'K': + channel_model=Rayleigh1_anticorr; + break; - case 'K': - channel_model=Rayleigh1_anticorr; + case 'L': + channel_model=Rice8; + break; - case 'L': - channel_model=Rice8; + case 'M': + channel_model=Rice1; + break; + + default: + printf("Unsupported channel model!\n"); + exit(-1); + } - case 'M': - channel_model=Rice1; break; - default: - printf("Unsupported channel model!\n"); - exit(-1); - } + case 'n': + n_frames = atoi(optarg); + break; - break; + case 's': + snr0 = atof(optarg); + printf("Setting SNR0 to %f\n",snr0); + break; - case 'n': - n_frames = atoi(optarg); - break; + case 'S': + snr1 = atof(optarg); + snr1set=1; + printf("Setting SNR1 to %f\n",snr1); + break; - case 's': - snr0 = atof(optarg); - printf("Setting SNR0 to %f\n",snr0); - break; + case 'p': + extended_prefix_flag=1; + break; - case 'S': - snr1 = atof(optarg); - snr1set=1; - printf("Setting SNR1 to %f\n",snr1); - break; + case 'r': + ricean_factor = pow(10,-.1*atof(optarg)); - case 'p': - extended_prefix_flag=1; - break; + if (ricean_factor>1) { + printf("Ricean factor must be between 0 and 1\n"); + exit(-1); + } - case 'r': - ricean_factor = pow(10,-.1*atof(optarg)); + break; - if (ricean_factor>1) { - printf("Ricean factor must be between 0 and 1\n"); - exit(-1); - } + case 'x': + transmission_mode=atoi(optarg); - break; + if ((transmission_mode!=1) && + (transmission_mode!=2) && + (transmission_mode!=6)) { + printf("Unsupported transmission mode %d\n",transmission_mode); + exit(-1); + } - case 'x': - transmission_mode=atoi(optarg); + break; - if ((transmission_mode!=1) && - (transmission_mode!=2) && - (transmission_mode!=6)) { - printf("Unsupported transmission mode %d\n",transmission_mode); - exit(-1); - } + case 'y': + n_tx=atoi(optarg); - break; + if ((n_tx==0) || (n_tx>2)) { + printf("Unsupported number of tx antennas %d\n",n_tx); + exit(-1); + } - case 'y': - n_tx=atoi(optarg); + break; - if ((n_tx==0) || (n_tx>2)) { - printf("Unsupported number of tx antennas %d\n",n_tx); - exit(-1); - } + case 'z': + n_rx=atoi(optarg); - break; + if ((n_rx==0) || (n_rx>2)) { + printf("Unsupported number of rx antennas %d\n",n_rx); + exit(-1); + } - case 'z': - n_rx=atoi(optarg); + break; - if ((n_rx==0) || (n_rx>2)) { - printf("Unsupported number of rx antennas %d\n",n_rx); - exit(-1); - } + case 'N': + N0 = atoi(optarg); + break; + + case 'T': + pucch1_thres = atoi(optarg); + break; + + case 'R': + N_RB_DL = atoi(optarg); + break; - break; - - case 'N': - N0 = atoi(optarg); - break; - - case 'T': - pucch1_thres = atoi(optarg); - break; - - case 'R': - N_RB_DL = atoi(optarg); - break; - - case 'O': - osf = atoi(optarg); - break; - - case 'F': - break; - - default: - case 'h': - printf("%s -h(elp) -a(wgn on) -p(extended_prefix) -N cell_id -f output_filename -F input_filename -g channel_model -n n_frames -t Delayspread -r Ricean_FactordB -s snr0 -S snr1 -x transmission_mode -y TXant -z RXant -N CellId\n", - argv[0]); - printf("-h This message\n"); - printf("-a Use AWGN channel and not multipath\n"); - printf("-p Use extended prefix mode\n"); - printf("-n Number of frames to simulate\n"); - printf("-r Ricean factor (dB, 0 means Rayleigh, 100 is almost AWGN\n"); - printf("-s Starting SNR, runs from SNR0 to SNR0 + 5 dB. If n_frames is 1 then just SNR is simulated\n"); - printf("-S Ending SNR, runs from SNR0 to SNR1\n"); - printf("-t Delay spread for multipath channel\n"); - printf("-g [A,B,C,D,E,F,G] Use 3GPP SCM (A,B,C,D) or 36-101 (E-EPA,F-EVA,G-ETU) models (ignores delay spread and Ricean factor)\n"); - printf("-x Transmission mode (1,2,6 for the moment)\n"); - printf("-y Number of TX antennas used in eNB\n"); - printf("-z Number of RX antennas used in UE\n"); - printf("-i Relative strength of first intefering eNB (in dB) - cell_id mod 3 = 1\n"); - printf("-j Relative strength of second intefering eNB (in dB) - cell_id mod 3 = 2\n"); - printf("-N Noise variance in dB\n"); - printf("-R N_RB_DL\n"); - printf("-O oversampling factor (1,2,4,8,16)\n"); - printf("-f PUCCH format (0=1,1=1a,2=1b,6=3), formats 2/2a/2b not supported\n"); - printf("-F Input filename (.txt format) for RX conformance testing\n"); - exit (-1); - break; + case 'O': + osf = atoi(optarg); + break; + + case 'F': + break; + + default: + case 'h': + printf("%s -h(elp) -a(wgn on) -p(extended_prefix) -N cell_id -f output_filename -F input_filename -g channel_model -n n_frames -t Delayspread -r Ricean_FactordB -s snr0 -S snr1 -x transmission_mode -y TXant -z RXant -N CellId\n", + argv[0]); + printf("-h This message\n"); + printf("-a Use AWGN channel and not multipath\n"); + printf("-p Use extended prefix mode\n"); + printf("-n Number of frames to simulate\n"); + printf("-r Ricean factor (dB, 0 means Rayleigh, 100 is almost AWGN\n"); + printf("-s Starting SNR, runs from SNR0 to SNR0 + 5 dB. If n_frames is 1 then just SNR is simulated\n"); + printf("-S Ending SNR, runs from SNR0 to SNR1\n"); + printf("-t Delay spread for multipath channel\n"); + printf("-g [A,B,C,D,E,F,G] Use 3GPP SCM (A,B,C,D) or 36-101 (E-EPA,F-EVA,G-ETU) models (ignores delay spread and Ricean factor)\n"); + printf("-x Transmission mode (1,2,6 for the moment)\n"); + printf("-y Number of TX antennas used in eNB\n"); + printf("-z Number of RX antennas used in UE\n"); + printf("-i Relative strength of first intefering eNB (in dB) - cell_id mod 3 = 1\n"); + printf("-j Relative strength of second intefering eNB (in dB) - cell_id mod 3 = 2\n"); + printf("-N Noise variance in dB\n"); + printf("-R N_RB_DL\n"); + printf("-O oversampling factor (1,2,4,8,16)\n"); + printf("-f PUCCH format (0=1,1=1a,2=1b,6=3), formats 2/2a/2b not supported\n"); + printf("-F Input filename (.txt format) for RX conformance testing\n"); + exit (-1); + break; } } @@ -299,17 +292,16 @@ int main(int argc, char **argv) lte_param_init(n_tx, n_tx, - n_rx, - transmission_mode, - extended_prefix_flag, - FDD, - Nid_cell, - 3, - N_RB_DL, - 0, - osf, - 0); - + n_rx, + transmission_mode, + extended_prefix_flag, + FDD, + Nid_cell, + 3, + N_RB_DL, + 0, + osf, + 0); if (snr1set==0) { if (n_frames==1) @@ -319,42 +311,30 @@ int main(int argc, char **argv) } printf("SNR0 %f, SNR1 %f\n",snr0,snr1); - frame_parms = &eNB->frame_parms; - - txdata = eNB->common_vars.txdata[eNB_id]; - nsymb = (frame_parms->Ncp == 0) ? 14 : 12; - printf("FFT Size %d, Extended Prefix %d, Samples per subframe %d, Symbols per subframe %d\n",NUMBER_OF_OFDM_CARRIERS, frame_parms->Ncp,frame_parms->samples_per_tti,nsymb); - - - printf("[SIM] Using SCM/101\n"); UE2eNB = new_channel_desc_scm(eNB->frame_parms.nb_antennas_tx, UE->frame_parms.nb_antennas_rx, channel_model, - N_RB2sampling_rate(eNB->frame_parms.N_RB_UL), - N_RB2channel_bandwidth(eNB->frame_parms.N_RB_UL), + N_RB2sampling_rate(eNB->frame_parms.N_RB_UL), + N_RB2channel_bandwidth(eNB->frame_parms.N_RB_UL), 0.0, 0, 0); - if (UE2eNB==NULL) { printf("Problem generating channel model. Exiting.\n"); exit(-1); } init_ncs_cell(&eNB->frame_parms,eNB->ncs_cell); - init_ncs_cell(&UE->frame_parms,UE->ncs_cell); - init_ul_hopping(&eNB->frame_parms); init_ul_hopping(&UE->frame_parms); - eNB->frame_parms.pucch_config_common.deltaPUCCH_Shift = 2; eNB->frame_parms.pucch_config_common.nRB_CQI = 4; eNB->frame_parms.pucch_config_common.nCS_AN = 6; @@ -362,40 +342,38 @@ int main(int argc, char **argv) UE->frame_parms.pucch_config_common.nRB_CQI = 4; UE->frame_parms.pucch_config_common.nCS_AN = 6; - - if( (pucch_format == pucch_format1) || (pucch_format == pucch_format1a) || (pucch_format == pucch_format1b) ){ + if( (pucch_format == pucch_format1) || (pucch_format == pucch_format1a) || (pucch_format == pucch_format1b) ) { pucch_payload = 0; generate_pucch1x(UE->common_vars.txdataF, - frame_parms, - UE->ncs_cell, - pucch_format, - &pucch_config_dedicated, - n1_pucch, - 0, //shortened_format, - &pucch_payload, - AMP, //amp, - subframe); //subframe - }else if( pucch_format == pucch_format3){ - for(i=0;i<pucch3_payload_size;i++) + frame_parms, + UE->ncs_cell, + pucch_format, + &pucch_config_dedicated, + n1_pucch, + 0, //shortened_format, + &pucch_payload, + AMP, //amp, + subframe); //subframe + } else if( pucch_format == pucch_format3) { + for(i=0; i<pucch3_payload_size; i++) pucch3_payload[i]=(uint8_t)(taus()&0x1); + generate_pucch3x(UE->common_vars.txdataF, - frame_parms, - UE->ncs_cell, - pucch_format, - &pucch_config_dedicated, - n3_pucch, - 0, //shortened_format, - pucch3_payload, - AMP, //amp, - subframe, //subframe - n_rnti); //rnti + frame_parms, + UE->ncs_cell, + pucch_format, + &pucch_config_dedicated, + n3_pucch, + 0, //shortened_format, + pucch3_payload, + AMP, //amp, + subframe, //subframe + n_rnti); //rnti } - LOG_M("txsigF0.m","txsF0", &UE->common_vars.txdataF[0][2*subframe*nsymb*OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES_NO_PREFIX],OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES_NO_PREFIX*nsymb,1,1); + LOG_M("txsigF0.m","txsF0", &UE->common_vars.txdataF[0][2*subframe*nsymb*OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES_NO_PREFIX],OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES_NO_PREFIX*nsymb,1,1); tx_lev = 0; - - for (aa=0; aa<eNB->frame_parms.nb_antennas_tx; aa++) { if (frame_parms->Ncp == 1) PHY_ofdm_mod(&UE->common_vars.txdataF[aa][2*subframe*nsymb*OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES_NO_PREFIX], // input, @@ -413,16 +391,12 @@ int main(int argc, char **argv) //apply_7_5_kHz(UE,UE->common_vars.txdata[aa],1+(subframe<<1)); apply_7_5_kHz(UE,&txdata[aa][eNB->frame_parms.samples_per_tti*subframe],0); apply_7_5_kHz(UE,&txdata[aa][eNB->frame_parms.samples_per_tti*subframe],1); - - } tx_lev += signal_energy(&txdata[aa][subframe*eNB->frame_parms.samples_per_tti], OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES); } - - LOG_M("txsig0.m","txs0", txdata[0], FRAME_LENGTH_COMPLEX_SAMPLES,1,1); //LOG_M("txsig1.m","txs1", txdata[1],FRAME_LENGTH_COMPLEX_SAMPLES,1,1); @@ -435,28 +409,19 @@ int main(int argc, char **argv) } } - - for (SNR=snr0; SNR<snr1; SNR+=.2) { - printf("n_frames %d SNR %f\n",n_frames,SNR); - n_errors = 0; pucch_tx = 0; pucch1_missed=0; pucch1_false=0; pucch3_false=0; - stat_no_sig = 0; stat_sig = 0; for (trial=0; trial<n_frames; trial++) { - - - multipath_channel(UE2eNB,s_re,s_im,r_re,r_im, eNB->frame_parms.samples_per_tti,0); - sigma2_dB = N0;//10*log10((double)tx_lev) - SNR; tx_gain = sqrt(pow(10.0,.1*(N0+SNR))/(double)tx_lev); @@ -478,11 +443,11 @@ int main(int argc, char **argv) sig=1; } else { if (trial<(n_frames>>1)) { - //printf("no sig =>"); + //printf("no sig =>"); sig= 0; } else { sig=1; - //printf("sig =>"); + //printf("sig =>"); pucch_tx++; } } @@ -493,14 +458,11 @@ int main(int argc, char **argv) // fill measurement symbol (19) with noise for (i=0; i<OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES; i++) { for (aa=0; aa<eNB->frame_parms.nb_antennas_rx; aa++) { - - ((short*) &eNB->common_vars.rxdata[0][aa][(frame_parms->samples_per_tti<<1) -frame_parms->ofdm_symbol_size])[2*i] = (short) ((sqrt(sigma2/2)*gaussdouble(0.0,1.0))); - ((short*) &eNB->common_vars.rxdata[0][aa][(frame_parms->samples_per_tti<<1) -frame_parms->ofdm_symbol_size])[2*i+1] = (short) ((sqrt(sigma2/2)*gaussdouble(0.0,1.0))); + ((short *) &eNB->common_vars.rxdata[0][aa][(frame_parms->samples_per_tti<<1) -frame_parms->ofdm_symbol_size])[2*i] = (short) ((sqrt(sigma2/2)*gaussdouble(0.0,1.0))); + ((short *) &eNB->common_vars.rxdata[0][aa][(frame_parms->samples_per_tti<<1) -frame_parms->ofdm_symbol_size])[2*i+1] = (short) ((sqrt(sigma2/2)*gaussdouble(0.0,1.0))); } } - - for (i=0; i<2*nsymb*OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES; i++) { for (aa=0; aa<eNB->frame_parms.nb_antennas_rx; aa++) { if (n_trials==0) { @@ -508,14 +470,12 @@ int main(int argc, char **argv) // r_im[aa][i] += (pow(10.0,.05*interf1)*r_im1[aa][i] + pow(10.0,.05*interf2)*r_im2[aa][i]); } - if (sig==1) { - ((short*) &eNB->common_vars.rxdata[0][aa][subframe*frame_parms->samples_per_tti])[2*i] = (short) (((tx_gain*r_re[aa][i]) +sqrt(sigma2/2)*gaussdouble(0.0,1.0))); - ((short*) &eNB->common_vars.rxdata[0][aa][subframe*frame_parms->samples_per_tti])[2*i+1] = (short) (((tx_gain*r_im[aa][i]) + (iqim*r_re[aa][i]*tx_gain) + sqrt(sigma2/2)*gaussdouble(0.0,1.0))); + ((short *) &eNB->common_vars.rxdata[0][aa][subframe*frame_parms->samples_per_tti])[2*i] = (short) (((tx_gain*r_re[aa][i]) +sqrt(sigma2/2)*gaussdouble(0.0,1.0))); + ((short *) &eNB->common_vars.rxdata[0][aa][subframe*frame_parms->samples_per_tti])[2*i+1] = (short) (((tx_gain*r_im[aa][i]) + (iqim*r_re[aa][i]*tx_gain) + sqrt(sigma2/2)*gaussdouble(0.0,1.0))); } else { - ((short*) &eNB->common_vars.rxdata[0][aa][subframe*frame_parms->samples_per_tti])[2*i] = (short) ((sqrt(sigma2/2)*gaussdouble(0.0,1.0))); - ((short*) &eNB->common_vars.rxdata[0][aa][subframe*frame_parms->samples_per_tti])[2*i+1] = (short) ((sqrt(sigma2/2)*gaussdouble(0.0,1.0))); - + ((short *) &eNB->common_vars.rxdata[0][aa][subframe*frame_parms->samples_per_tti])[2*i] = (short) ((sqrt(sigma2/2)*gaussdouble(0.0,1.0))); + ((short *) &eNB->common_vars.rxdata[0][aa][subframe*frame_parms->samples_per_tti])[2*i+1] = (short) ((sqrt(sigma2/2)*gaussdouble(0.0,1.0))); } } } @@ -524,7 +484,6 @@ int main(int argc, char **argv) remove_7_5_kHz(eNB,1+(subframe<<1)); for (l=0; l<eNB->frame_parms.symbols_per_tti/2; l++) { - slot_fep_ul(&eNB->frame_parms, &eNB->common_vars, l, @@ -539,16 +498,13 @@ int main(int argc, char **argv) 0, 0 ); - - } - // if (sig == 1) // printf("*"); lte_eNB_I0_measurements(eNB, subframe, - 0, + 0, 1); eNB->measurements[0].n0_power_tot_dB = N0;//(int8_t)(sigma2_dB-10*log10(eNB->frame_parms.ofdm_symbol_size/(12*NB_RB))); stat = rx_pucch(eNB, @@ -580,9 +536,9 @@ int main(int argc, char **argv) }*/ } else if( (pucch_format==pucch_format1a) || (pucch_format==pucch_format1b) ) { pucch1_false = (pucch_payload_rx != pucch_payload) ? (pucch1_false+1) : pucch1_false; - } else if (pucch_format==pucch_format3){ - for(i=0;i<pucch3_payload_size;i++){ - if(pucch3_payload[i]!=pucch3_payload_rx[i]){ + } else if (pucch_format==pucch_format3) { + for(i=0; i<pucch3_payload_size; i++) { + if(pucch3_payload[i]!=pucch3_payload_rx[i]) { pucch3_false = (pucch3_false+1); break; } @@ -611,11 +567,8 @@ int main(int argc, char **argv) LOG_M("rxsigF0.m","rxsF0", &eNB->common_vars.rxdataF[0][0][0],512*nsymb*2,2,1); } - lte_sync_time_free(); - return(n_errors); - } diff --git a/openair1/SIMULATION/LTE_PHY/scansim.c b/openair1/SIMULATION/LTE_PHY/scansim.c index cb419f57c248a5f7011a126639d831b118104a0b..5ceeee7f2f5d5d16575183e05cb2d5185186ed1e 100644 --- a/openair1/SIMULATION/LTE_PHY/scansim.c +++ b/openair1/SIMULATION/LTE_PHY/scansim.c @@ -38,7 +38,7 @@ #include "LAYER2/MAC/vars.h" #ifdef XFORMS -#include "PHY/TOOLS/lte_phy_scope.h" + #include "PHY/TOOLS/lte_phy_scope.h" #endif #include "OCG_vars.h" @@ -58,11 +58,8 @@ mod_sym_t dummy2[2048*14]; mod_sym_t dummy3[2048*14]; -int main(int argc, char **argv) -{ - +int main(int argc, char **argv) { char c; - int i,l,aa; double sigma2, sigma2_dB=0,SNR,snr0=-2.0,snr1; uint8_t snr1set=0; @@ -82,226 +79,192 @@ int main(int argc, char **argv) int trial, n_trials, ntrials=1, n_errors,n_errors2,n_alamouti; uint8_t transmission_mode = 1,n_tx=1,n_rx=1; uint16_t Nid_cell=0; - int n_frames=1; channel_desc_t *eNB2UE,*eNB2UE1,*eNB2UE2; uint32_t nsymb,tx_lev,tx_lev1,tx_lev2; uint8_t extended_prefix_flag=0; LTE_DL_FRAME_PARMS *frame_parms; - FILE *input_fd=NULL,*pbch_file_fd=NULL; char input_val_str[50],input_val_str2[50]; // double input_val1,input_val2; // uint16_t amask=0; uint8_t frame_mod4,num_pdcch_symbols; uint16_t NB_RB=25; - SCM_t channel_model=AWGN;//Rayleigh1_anticorr; - DCI_ALLOC_t dci_alloc[8]; uint8_t abstraction_flag=0;//,calibration_flag=0; int pbch_tx_ant; uint8_t N_RB_DL=100,osf=1; - unsigned char frame_type = FDD; unsigned char pbch_phase = 0; - #ifdef XFORMS FD_lte_phy_scope_ue *form_ue; char title[255]; #endif - logInit(); number_of_cards = 1; openair_daq_vars.rx_rf_mode = 1; - /* - rxdataF = (int **)malloc16(2*sizeof(int*)); - rxdataF[0] = (int *)malloc16(FRAME_LENGTH_BYTES); - rxdataF[1] = (int *)malloc16(FRAME_LENGTH_BYTES); - - rxdata = (int **)malloc16(2*sizeof(int*)); - rxdata[0] = (int *)malloc16(FRAME_LENGTH_BYTES); - rxdata[1] = (int *)malloc16(FRAME_LENGTH_BYTES); - */ while ((c = getopt (argc, argv, "f:hpf:g:n:s:S:t:x:y:z:N:F:GdP:")) != -1) { switch (c) { - case 'f': - write_output_file=1; - output_fd = fopen(optarg,"w"); - - if (output_fd==NULL) { - printf("Error opening %s\n",optarg); - exit(-1); - } + case 'f': + write_output_file=1; + output_fd = fopen(optarg,"w"); - break; - - case 'd': - frame_type = TDD; - break; + if (output_fd==NULL) { + printf("Error opening %s\n",optarg); + exit(-1); + } - case 'g': - switch((char)*optarg) { - case 'A': - channel_model=SCM_A; break; - case 'B': - channel_model=SCM_B; + case 'd': + frame_type = TDD; break; - case 'C': - channel_model=SCM_C; - break; + case 'g': + switch((char)*optarg) { + case 'A': + channel_model=SCM_A; + break; - case 'D': - channel_model=SCM_D; - break; + case 'B': + channel_model=SCM_B; + break; - case 'E': - channel_model=EPA; - break; + case 'C': + channel_model=SCM_C; + break; + + case 'D': + channel_model=SCM_D; + break; + + case 'E': + channel_model=EPA; + break; + + case 'F': + channel_model=EVA; + break; + + case 'G': + channel_model=ETU; + break; + + default: + msg("Unsupported channel model!\n"); + exit(-1); + } - case 'F': - channel_model=EVA; break; - case 'G': - channel_model=ETU; + case 'n': + n_frames = atoi(optarg); break; - default: - msg("Unsupported channel model!\n"); - exit(-1); - } + case 's': + snr0 = atof(optarg); + msg("Setting SNR0 to %f\n",snr0); + break; - break; + case 'S': + snr1 = atof(optarg); + snr1set=1; + msg("Setting SNR1 to %f\n",snr1); + break; - case 'n': - n_frames = atoi(optarg); - break; + case 'p': + extended_prefix_flag=1; + break; - case 's': - snr0 = atof(optarg); - msg("Setting SNR0 to %f\n",snr0); - break; + case 'x': + transmission_mode=atoi(optarg); - case 'S': - snr1 = atof(optarg); - snr1set=1; - msg("Setting SNR1 to %f\n",snr1); - break; + if ((transmission_mode!=1) && + (transmission_mode!=2) && + (transmission_mode!=6)) { + msg("Unsupported transmission mode %d\n",transmission_mode); + exit(-1); + } - /* - case 't': - Td= atof(optarg); break; - */ - case 'p': - extended_prefix_flag=1; - break; - /* - case 'r': - ricean_factor = pow(10,-.1*atof(optarg)); - if (ricean_factor>1) { - printf("Ricean factor must be between 0 and 1\n"); - exit(-1); + case 'y': + n_tx=atoi(optarg); + + if ((n_tx==0) || (n_tx>2)) { + msg("Unsupported number of tx antennas %d\n",n_tx); + exit(-1); } - break; - */ - case 'x': - transmission_mode=atoi(optarg); - - if ((transmission_mode!=1) && - (transmission_mode!=2) && - (transmission_mode!=6)) { - msg("Unsupported transmission mode %d\n",transmission_mode); - exit(-1); - } - break; + break; - case 'y': - n_tx=atoi(optarg); + case 'z': + n_rx=atoi(optarg); - if ((n_tx==0) || (n_tx>2)) { - msg("Unsupported number of tx antennas %d\n",n_tx); - exit(-1); - } + if ((n_rx==0) || (n_rx>2)) { + msg("Unsupported number of rx antennas %d\n",n_rx); + exit(-1); + } - break; + break; - case 'z': - n_rx=atoi(optarg); + case 'A': + abstraction_flag=1; + ntrials=10000; + msg("Running Abstraction test\n"); + pbch_file_fd=fopen(optarg,"r"); + + if (pbch_file_fd==NULL) { + printf("Problem with filename %s\n",optarg); + exit(-1); + } - if ((n_rx==0) || (n_rx>2)) { - msg("Unsupported number of rx antennas %d\n",n_rx); - exit(-1); - } + break; - break; + case 'N': + Nid_cell = atoi(optarg); + break; - case 'A': - abstraction_flag=1; - ntrials=10000; - msg("Running Abstraction test\n"); - pbch_file_fd=fopen(optarg,"r"); + case 'F': + input_fd = fopen(optarg,"r"); - if (pbch_file_fd==NULL) { - printf("Problem with filename %s\n",optarg); - exit(-1); - } + if (input_fd==NULL) { + printf("Problem with filename %s\n",optarg); + exit(-1); + } - break; + break; - // case 'C': - // calibration_flag=1; - // msg("Running Abstraction calibration for Bias removal\n"); - // break; - case 'N': - Nid_cell = atoi(optarg); - break; + case 'P': + pbch_phase = atoi(optarg); - case 'F': - input_fd = fopen(optarg,"r"); + if (pbch_phase>3) + printf("Illegal PBCH phase (0-3) got %d\n",pbch_phase); - if (input_fd==NULL) { - printf("Problem with filename %s\n",optarg); - exit(-1); - } + break; - break; - - case 'P': - pbch_phase = atoi(optarg); - - if (pbch_phase>3) - printf("Illegal PBCH phase (0-3) got %d\n",pbch_phase); - - break; - - default: - case 'h': - printf("%s -h(elp) -p(extended_prefix) -N cell_id -f output_filename -F input_filename -g channel_model -n n_frames -t Delayspread -s snr0 -S snr1 -x transmission_mode -y TXant -z RXant -N CellId\n", - argv[0]); - printf("-h This message\n"); - printf("-p Use extended prefix mode\n"); - printf("-d Use TDD\n"); - printf("-n Number of frames to simulate\n"); - printf("-s Starting SNR, runs from SNR0 to SNR0 + 5 dB. If n_frames is 1 then just SNR is simulated\n"); - printf("-S Ending SNR, runs from SNR0 to SNR1\n"); - printf("-t Delay spread for multipath channel\n"); - printf("-g [A,B,C,D,E,F,G] Use 3GPP SCM (A,B,C,D) or 36-101 (E-EPA,F-EVA,G-ETU) models (ignores delay spread and Ricean factor)\n"); - printf("-x Transmission mode (1,2,6 for the moment)\n"); - printf("-y Number of TX antennas used in eNB\n"); - printf("-z Number of RX antennas used in UE\n"); - printf("-N Nid_cell\n"); - printf("-f Output filename (.txt format) for Pe/SNR results\n"); - printf("-F Input filename (.txt format) for RX conformance testing\n"); - exit (-1); - break; + default: + case 'h': + printf("%s -h(elp) -p(extended_prefix) -N cell_id -f output_filename -F input_filename -g channel_model -n n_frames -t Delayspread -s snr0 -S snr1 -x transmission_mode -y TXant -z RXant -N CellId\n", + argv[0]); + printf("-h This message\n"); + printf("-p Use extended prefix mode\n"); + printf("-d Use TDD\n"); + printf("-n Number of frames to simulate\n"); + printf("-s Starting SNR, runs from SNR0 to SNR0 + 5 dB. If n_frames is 1 then just SNR is simulated\n"); + printf("-S Ending SNR, runs from SNR0 to SNR1\n"); + printf("-t Delay spread for multipath channel\n"); + printf("-g [A,B,C,D,E,F,G] Use 3GPP SCM (A,B,C,D) or 36-101 (E-EPA,F-EVA,G-ETU) models (ignores delay spread and Ricean factor)\n"); + printf("-x Transmission mode (1,2,6 for the moment)\n"); + printf("-y Number of TX antennas used in eNB\n"); + printf("-z Number of RX antennas used in UE\n"); + printf("-N Nid_cell\n"); + printf("-f Output filename (.txt format) for Pe/SNR results\n"); + printf("-F Input filename (.txt format) for RX conformance testing\n"); + exit (-1); + break; } } @@ -309,16 +272,15 @@ int main(int argc, char **argv) n_tx=2; lte_param_init(n_tx, - n_rx, - transmission_mode, - extended_prefix_flag, - frame_type, - Nid_cell, - 3, - N_RB_DL, - osf, - 0); - + n_rx, + transmission_mode, + extended_prefix_flag, + frame_type, + Nid_cell, + 3, + N_RB_DL, + osf, + 0); #ifdef XFORMS fl_initialize (&argc, argv, NULL, 0, 0); form_ue = create_lte_phy_scope_ue(); @@ -334,38 +296,27 @@ int main(int argc, char **argv) } printf("SNR0 %f, SNR1 %f\n",snr0,snr1); - frame_parms = &PHY_vars_eNB->lte_frame_parms; - - - txdata = PHY_vars_eNB->lte_eNB_common_vars.txdata[0]; txdata1 = PHY_vars_eNB1->lte_eNB_common_vars.txdata[0]; txdata2 = PHY_vars_eNB2->lte_eNB_common_vars.txdata[0]; - - - s_re = malloc(2*sizeof(double*)); - s_im = malloc(2*sizeof(double*)); - s_re1 = malloc(2*sizeof(double*)); - s_im1 = malloc(2*sizeof(double*)); - s_re2 = malloc(2*sizeof(double*)); - s_im2 = malloc(2*sizeof(double*)); - r_re = malloc(2*sizeof(double*)); - r_im = malloc(2*sizeof(double*)); - r_re1 = malloc(2*sizeof(double*)); - r_im1 = malloc(2*sizeof(double*)); - r_re2 = malloc(2*sizeof(double*)); - r_im2 = malloc(2*sizeof(double*)); - + s_re = malloc(2*sizeof(double *)); + s_im = malloc(2*sizeof(double *)); + s_re1 = malloc(2*sizeof(double *)); + s_im1 = malloc(2*sizeof(double *)); + s_re2 = malloc(2*sizeof(double *)); + s_im2 = malloc(2*sizeof(double *)); + r_re = malloc(2*sizeof(double *)); + r_im = malloc(2*sizeof(double *)); + r_re1 = malloc(2*sizeof(double *)); + r_im1 = malloc(2*sizeof(double *)); + r_re2 = malloc(2*sizeof(double *)); + r_im2 = malloc(2*sizeof(double *)); nsymb = (frame_parms->Ncp == 0) ? 14 : 12; - printf("FFT Size %d, Extended Prefix %d, Samples per subframe %d, Symbols per subframe %d\n",NUMBER_OF_OFDM_CARRIERS, frame_parms->Ncp,frame_parms->samples_per_tti,nsymb); - printf("PHY_vars_eNB1->lte_eNB_common_vars.txdataF[0][0] = %p\n", PHY_vars_eNB1->lte_eNB_common_vars.txdataF[0][0]); - - DLSCH_alloc_pdu2.rah = 0; DLSCH_alloc_pdu2.rballoc = DLSCH_RB_ALLOC; DLSCH_alloc_pdu2.TPC = 0; @@ -377,16 +328,14 @@ int main(int argc, char **argv) DLSCH_alloc_pdu2.rv1 = 0; // Forget second codeword DLSCH_alloc_pdu2.tpmi = (transmission_mode==6 ? 5 : 0) ; // precoding - eNB2UE = new_channel_desc_scm(PHY_vars_eNB->lte_frame_parms.nb_antennas_tx, - PHY_vars_UE->lte_frame_parms.nb_antennas_rx, - channel_model, - N_RB2sampling_rate(PHY_vars_eNB->lte_frame_parms.N_RB_DL), - N_RB2channel_bandwidth(PHY_vars_eNB->lte_frame_parms.N_RB_DL), - 0, - 0, - 0); - + PHY_vars_UE->lte_frame_parms.nb_antennas_rx, + channel_model, + N_RB2sampling_rate(PHY_vars_eNB->lte_frame_parms.N_RB_DL), + N_RB2channel_bandwidth(PHY_vars_eNB->lte_frame_parms.N_RB_DL), + 0, + 0, + 0); if (eNB2UE==NULL) { msg("Problem generating channel model. Exiting.\n"); @@ -394,7 +343,6 @@ int main(int argc, char **argv) } for (i=0; i<2; i++) { - s_re[i] = malloc(FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double)); bzero(s_re[i],FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double)); s_im[i] = malloc(FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double)); @@ -407,7 +355,6 @@ int main(int argc, char **argv) bzero(s_re2[i],FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double)); s_im2[i] = malloc(FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double)); bzero(s_im2[i],FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double)); - r_re[i] = malloc(FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double)); bzero(r_re[i],FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double)); r_im[i] = malloc(FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double)); @@ -450,9 +397,7 @@ int main(int argc, char **argv) (PHY_vars_eNB->lte_frame_parms.Ncp==0) ? 5 : 4, 10); */ - } else { - generate_sss(PHY_vars_eNB->lte_eNB_common_vars.txdataF[0], AMP, &PHY_vars_eNB->lte_frame_parms, @@ -473,11 +418,8 @@ int main(int argc, char **argv) &PHY_vars_eNB->lte_frame_parms, 2, 12); - - } - /* generate_pilots(PHY_vars_eNB, PHY_vars_eNB->lte_eNB_common_vars.txdataF[0], @@ -494,7 +436,6 @@ int main(int argc, char **argv) PHY_vars_eNB->lte_eNB_common_vars.txdataF[0], 0); */ - /* if (num_pdcch_symbols<3) { printf("Less than 3 pdcch symbols\n"); @@ -530,9 +471,6 @@ int main(int argc, char **argv) tx_lev1 = 0; tx_lev2 = 0; - - - for (aa=0; aa<PHY_vars_eNB->lte_frame_parms.nb_antennas_tx; aa++) { if (frame_parms->Ncp == 1) PHY_ofdm_mod(PHY_vars_eNB->lte_eNB_common_vars.txdataF[0][aa], // input, @@ -552,7 +490,6 @@ int main(int argc, char **argv) OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES); } - LOG_M("txsig0.m","txs0", txdata[0],FRAME_LENGTH_COMPLEX_SAMPLES,1,1); if (frame_parms->nb_antennas_tx>1) @@ -567,19 +504,14 @@ int main(int argc, char **argv) } } - for (SNR=snr0; SNR<snr1; SNR+=.2) { - - n_errors = 0; n_errors2 = 0; n_alamouti = 0; for (trial=0; trial<n_frames; trial++) { - multipath_channel(eNB2UE,s_re,s_im,r_re,r_im, 2*nsymb*OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES,0); - sigma2_dB = 10*log10((double)tx_lev) +10*log10((double)PHY_vars_eNB->lte_frame_parms.ofdm_symbol_size/(double)(12*NB_RB)) - SNR; if (n_frames==1) @@ -603,8 +535,8 @@ int main(int argc, char **argv) //printf("n_trial %d\n",n_trials); for (i=0; i<2*nsymb*OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES; i++) { for (aa=0; aa<PHY_vars_eNB->lte_frame_parms.nb_antennas_rx; aa++) { - ((short*) PHY_vars_UE->lte_ue_common_vars.rxdata[aa])[2*i] = (short) ((r_re[aa][i] +sqrt(sigma2/2)*gaussdouble(0.0,1.0))); - ((short*) PHY_vars_UE->lte_ue_common_vars.rxdata[aa])[2*i+1] = (short) ((r_im[aa][i] + (iqim*r_re[aa][i]) + sqrt(sigma2/2)*gaussdouble(0.0,1.0))); + ((short *) PHY_vars_UE->lte_ue_common_vars.rxdata[aa])[2*i] = (short) ((r_re[aa][i] +sqrt(sigma2/2)*gaussdouble(0.0,1.0))); + ((short *) PHY_vars_UE->lte_ue_common_vars.rxdata[aa])[2*i+1] = (short) ((r_im[aa][i] + (iqim*r_re[aa][i]) + sqrt(sigma2/2)*gaussdouble(0.0,1.0))); } } @@ -614,8 +546,6 @@ int main(int argc, char **argv) printf("rx_level data symbol %f\n", 10*log10(signal_energy(&PHY_vars_UE->lte_ue_common_vars.rxdata[0][frame_parms->samples_per_tti/2],4*OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES))); } - - } //noise trials } // trials @@ -629,30 +559,65 @@ int main(int argc, char **argv) } // NSR if (n_frames==1) { - } - for (i=0; i<2; i++) { free(s_re[i]); free(s_im[i]); + + if (s_im1) + free(s_im1[i]); + + if (s_im2) + free(s_im2[i]); + free(r_re[i]); + + if (r_re1) + free(r_re1[i]); + + if (r_re2) + free(r_re2[i]); + free(r_im[i]); + + if (s_re1) + free(s_re1[i]); + + if (s_re2) + free(s_re2[i]); + + if (r_im1) + free(r_im1[i]); + + if (r_im2) + free(r_im2[i]); } free(s_re); + free(s_re1); + free(s_re2); free(s_im); + free(s_im1); + free(s_im2); free(r_re); + free(r_re1); + free(r_re2); free(r_im); - - + free(r_im1); + free(r_im2); lte_sync_time_free(); if (write_output_file) fclose(output_fd); - return(n_errors); + if (input_fd) + fclose(input_fd); + + if (pbch_file_fd) + fclose(pbch_file_fd); + return(n_errors); } diff --git a/openair1/SIMULATION/LTE_PHY/syncsim.c b/openair1/SIMULATION/LTE_PHY/syncsim.c index 59116bc5e176ebf4565fd1bde7f2ff27148ba56b..2c0385efbfdcaa3c6de6ceceaef45e36d8b3728e 100644 --- a/openair1/SIMULATION/LTE_PHY/syncsim.c +++ b/openair1/SIMULATION/LTE_PHY/syncsim.c @@ -37,7 +37,7 @@ #include "PHY/vars.h" #include "MAC_INTERFACE/vars.h" #ifdef IFFT_FPGA -#include "PHY/LTE_REFSIG/mod_table.h" + #include "PHY/LTE_REFSIG/mod_table.h" #endif #include "SCHED/defs.h" #include "SCHED/vars.h" @@ -47,8 +47,8 @@ #include "LAYER2/MAC/vars.h" #ifdef XFORMS -#include <forms.h> -#include "../../USERSPACE_TOOLS/SCOPE/lte_scope.h" + #include <forms.h> + #include "../../USERSPACE_TOOLS/SCOPE/lte_scope.h" #endif //XFORMS @@ -77,11 +77,8 @@ void do_forms2(FD_lte_scope *form, int16_t *dlsch_llr, int16_t *pbch_comp, int8_t *pbch_llr, - int coded_bits_per_codeword) -{ - + int coded_bits_per_codeword) { int i,j,k,s; - float Re,Im; float mag_sig[NB_ANTENNAS_RX*4*NUMBER_OF_OFDM_CARRIERS*NUMBER_OF_OFDM_SYMBOLS_PER_SLOT], sig_time[NB_ANTENNAS_RX*4*NUMBER_OF_OFDM_CARRIERS*NUMBER_OF_OFDM_SYMBOLS_PER_SLOT], @@ -91,15 +88,11 @@ void do_forms2(FD_lte_scope *form, *llr,*llr_time; int ind; float avg, cum_avg; - - extern int* sync_corr_ue0; - + extern int *sync_corr_ue0; // uint16_t nsymb = (frame_parms->Ncp == 0) ? 14 : 12; - llr = malloc(max(coded_bits_per_codeword,1920)*sizeof(float)); llr_time = malloc(max(coded_bits_per_codeword,1920)*sizeof(float)); - // Channel frequency response if (channel_f[0] != NULL) { cum_avg = 0; @@ -122,7 +115,6 @@ void do_forms2(FD_lte_scope *form, } avg = cum_avg/NUMBER_OF_USEFUL_CARRIERS; - //fl_set_xyplot_ybounds(form->channel_f,30,70); fl_set_xyplot_data(form->channel_f,sig_time,mag_sig,ind,"","",""); } @@ -196,7 +188,6 @@ void do_forms2(FD_lte_scope *form, //fl_set_xyplot_ybounds(form->scatter_plot,-100,100); } - // PDCCH I/Q j=0; @@ -210,7 +201,6 @@ void do_forms2(FD_lte_scope *form, //fl_set_xyplot_xbounds(form->scatter_plot,-100,100); //fl_set_xyplot_ybounds(form->scatter_plot,-100,100); - // DLSCH LLR if (dlsch_llr != NULL) { for(i=0; i<coded_bits_per_codeword; i++) { @@ -246,35 +236,25 @@ void do_forms2(FD_lte_scope *form, //fl_set_xyplot_ybounds(form->scatter_plot,-2000,2000); } - free(llr); free(llr_time); - } #endif -void lte_param_init(unsigned char N_tx, unsigned char N_rx,unsigned char transmission_mode,unsigned char extended_prefix_flag,uint8_t frame_type,uint16_t Nid_cell,uint8_t N_RB_DL,uint8_t osf) -{ - +void lte_param_init(unsigned char N_tx, unsigned char N_rx,unsigned char transmission_mode,unsigned char extended_prefix_flag,uint8_t frame_type,uint16_t Nid_cell,uint8_t N_RB_DL,uint8_t osf) { LTE_DL_FRAME_PARMS *lte_frame_parms; int i; - printf("Start lte_param_init, frame_type %d, extended_prefix %d\n",frame_type,extended_prefix_flag); PHY_vars_eNB = malloc(sizeof(PHY_VARS_eNB)); PHY_vars_eNB1 = malloc(sizeof(PHY_VARS_eNB)); PHY_vars_eNB2 = malloc(sizeof(PHY_VARS_eNB)); - PHY_vars_UE[0] = malloc(sizeof(PHY_VARS_UE)); PHY_vars_UE[1] = malloc(sizeof(PHY_VARS_UE)); //PHY_config = malloc(sizeof(PHY_CONFIG)); mac_xface = malloc(sizeof(MAC_xface)); - randominit(0); set_taus_seed(0); - - lte_frame_parms = &(PHY_vars_eNB->lte_frame_parms); - lte_frame_parms->N_RB_DL = N_RB_DL; //50 for 10MHz and 25 for 5 MHz lte_frame_parms->N_RB_UL = N_RB_DL; lte_frame_parms->Ncp = extended_prefix_flag; @@ -292,63 +272,42 @@ void lte_param_init(unsigned char N_tx, unsigned char N_rx,unsigned char transmi lte_frame_parms->frame_type = frame_type; lte_frame_parms->node_id = 2; init_frame_parms(lte_frame_parms,osf); - - - - phy_init_top(lte_frame_parms); //allocation - lte_frame_parms->twiddle_fft = twiddle_fft; lte_frame_parms->twiddle_ifft = twiddle_ifft; lte_frame_parms->rev = rev; - phy_init_lte_top(lte_frame_parms); - - memcpy((void*)&PHY_vars_UE[0]->lte_frame_parms,(void*)&PHY_vars_eNB->lte_frame_parms,sizeof(LTE_DL_FRAME_PARMS)); - memcpy((void*)&PHY_vars_UE[1]->lte_frame_parms,(void*)&PHY_vars_eNB->lte_frame_parms,sizeof(LTE_DL_FRAME_PARMS)); - + memcpy((void *)&PHY_vars_UE[0]->lte_frame_parms,(void *)&PHY_vars_eNB->lte_frame_parms,sizeof(LTE_DL_FRAME_PARMS)); + memcpy((void *)&PHY_vars_UE[1]->lte_frame_parms,(void *)&PHY_vars_eNB->lte_frame_parms,sizeof(LTE_DL_FRAME_PARMS)); phy_init_lte_ue(PHY_vars_UE[0],1,0); for (i=0; i<3; i++) lte_gold(lte_frame_parms,PHY_vars_UE[0]->lte_gold_table[i],i); PHY_vars_UE[0]->Mod_id = 0; - phy_init_lte_ue(PHY_vars_UE[1],1,0); for (i=0; i<3; i++) lte_gold(lte_frame_parms,PHY_vars_UE[1]->lte_gold_table[i],i); PHY_vars_UE[1]->Mod_id = 1; - phy_init_lte_eNB(PHY_vars_eNB,0,0,0); - - memcpy((void*)&PHY_vars_eNB1->lte_frame_parms,(void*)&PHY_vars_eNB->lte_frame_parms,sizeof(LTE_DL_FRAME_PARMS)); + memcpy((void *)&PHY_vars_eNB1->lte_frame_parms,(void *)&PHY_vars_eNB->lte_frame_parms,sizeof(LTE_DL_FRAME_PARMS)); PHY_vars_eNB1->lte_frame_parms.nushift=1; PHY_vars_eNB1->lte_frame_parms.Nid_cell=2; - - memcpy((void*)&PHY_vars_eNB2->lte_frame_parms,(void*)&PHY_vars_eNB->lte_frame_parms,sizeof(LTE_DL_FRAME_PARMS)); + memcpy((void *)&PHY_vars_eNB2->lte_frame_parms,(void *)&PHY_vars_eNB->lte_frame_parms,sizeof(LTE_DL_FRAME_PARMS)); PHY_vars_eNB2->lte_frame_parms.nushift=2; PHY_vars_eNB2->lte_frame_parms.Nid_cell=3; - phy_init_lte_eNB(PHY_vars_eNB1,0,0,0); - phy_init_lte_eNB(PHY_vars_eNB2,0,0,0); - phy_init_lte_top(lte_frame_parms); - printf("Done lte_param_init\n"); - - } -int main(int argc, char **argv) -{ - +int main(int argc, char **argv) { char c; - int i,iout,l,aa,aarx; double sigma2, sigma2_dB=0,SNR,snr0=10.0,snr1=11.0; uint8_t snr1set=0; @@ -373,26 +332,19 @@ int main(int argc, char **argv) uint8_t extended_prefix_flag=0,frame_type=1; int8_t interf1=-21,interf2=-21; LTE_DL_FRAME_PARMS *frame_parms; - FILE *input_fd=NULL,*pbch_file_fd=NULL; char input_val_str[50],input_val_str2[50]; uint8_t num_pdcch_symbols=1; uint16_t NB_RB=25; - SCM_t channel_model=Rayleigh8; - uint8_t abstraction_flag=0; double pbch_sinr; uint8_t N_RB_DL=25,osf=1; - int openair_fd=(int)0; int tcxo=74,fc=0; unsigned char temp[4]; - int oai_hw_input=0; int oai_hw_output=0; - - DCI_ALLOC_t dci_alloc[8],dci_alloc_rx[8]; uint16_t n_rnti=1234,dci_cnt; unsigned int coded_bits_per_codeword; @@ -406,21 +358,16 @@ int main(int argc, char **argv) uint32_t rxgain[4]= {30,30,30,30}; uint32_t do_forms=0; int ret; - #ifdef XFORMS FD_lte_scope *form_dl=NULL; FD_lte_scope *form_dl1=NULL; char title[255]; #endif - int UE_idx,N_carriers=1,subframe=2; int dual_stream_flag=0; unsigned char i_mod = 2; - int rx_offset_mod; - logInit(); - number_of_cards = 1; openair_daq_vars.rx_rf_mode = 1; @@ -435,141 +382,141 @@ int main(int argc, char **argv) */ while ((c = getopt (argc, argv, "aehc:f:g:i:j:n:r:s:t:x:y:z:A:F:N:O:R:S:ZYDT:C:G:dB:U:u")) != -1) { switch (c) { - case 'a': - printf("Running AWGN simulation\n"); - awgn_flag = 1; - break; - - case 'f': - output_fd = fopen(optarg,"w"); - write_output_file=1; - break; - - case 'g': - switch((char)*optarg) { - case 'A': - channel_model=SCM_A; + case 'a': + printf("Running AWGN simulation\n"); + awgn_flag = 1; break; - case 'B': - channel_model=SCM_B; + case 'f': + output_fd = fopen(optarg,"w"); + write_output_file=1; break; - case 'C': - channel_model=SCM_C; - break; + case 'g': + switch((char)*optarg) { + case 'A': + channel_model=SCM_A; + break; - case 'D': - channel_model=SCM_D; - break; + case 'B': + channel_model=SCM_B; + break; - case 'E': - channel_model=EPA; - break; + case 'C': + channel_model=SCM_C; + break; - case 'F': - channel_model=EVA; - break; + case 'D': + channel_model=SCM_D; + break; - case 'G': - channel_model=ETU; - break; + case 'E': + channel_model=EPA; + break; - default: - msg("Unsupported channel model!\n"); - exit(-1); - } + case 'F': + channel_model=EVA; + break; - break; + case 'G': + channel_model=ETU; + break; - case 'C': - sscanf(optarg,"%d,%d,%d,%d",&carrier_freq[0],&carrier_freq[1],&carrier_freq[2],&carrier_freq[3]); - printf("Configuring for frequencies %d,%d,%d,%d\n",carrier_freq[0],carrier_freq[1],carrier_freq[2],carrier_freq[3]); - //carrier_freq = atoi(optarg); - break; + default: + msg("Unsupported channel model!\n"); + exit(-1); + } - case 'G': - sscanf(optarg,"%d,%d,%d,%d",&rxgain[0],&rxgain[1],&rxgain[2],&rxgain[3]); - printf("Configuring for gains %d,%d,%d,%d\n",rxgain[0],rxgain[1],rxgain[2],rxgain[3]); - //rxgain = atoi(optarg); - break; + break; - case 'i': - interf1=atoi(optarg); - break; + case 'C': + sscanf(optarg,"%d,%d,%d,%d",&carrier_freq[0],&carrier_freq[1],&carrier_freq[2],&carrier_freq[3]); + printf("Configuring for frequencies %d,%d,%d,%d\n",carrier_freq[0],carrier_freq[1],carrier_freq[2],carrier_freq[3]); + //carrier_freq = atoi(optarg); + break; - case 'c': - deltaF=atof(optarg); - break; + case 'G': + sscanf(optarg,"%d,%d,%d,%d",&rxgain[0],&rxgain[1],&rxgain[2],&rxgain[3]); + printf("Configuring for gains %d,%d,%d,%d\n",rxgain[0],rxgain[1],rxgain[2],rxgain[3]); + //rxgain = atoi(optarg); + break; - case 'j': - interf2=atoi(optarg); - break; + case 'i': + interf1=atoi(optarg); + break; - case 'n': - n_frames = atoi(optarg); - break; + case 'c': + deltaF=atof(optarg); + break; - case 's': - snr0 = atof(optarg); - msg("Setting SNR0 to %f\n",snr0); - break; + case 'j': + interf2=atoi(optarg); + break; - case 'S': - snr1 = atof(optarg); - snr1set=1; - msg("Setting SNR1 to %f\n",snr1); - break; + case 'n': + n_frames = atoi(optarg); + break; + + case 's': + snr0 = atof(optarg); + msg("Setting SNR0 to %f\n",snr0); + break; + + case 'S': + snr1 = atof(optarg); + snr1set=1; + msg("Setting SNR1 to %f\n",snr1); + break; /* case 't': Td= atof(optarg); break; */ - case 'e': - extended_prefix_flag=1; - break; + case 'e': + extended_prefix_flag=1; + break; - case 'd': - do_forms=1; - break; + case 'd': + do_forms=1; + break; - case 'r': - n_rnti=atoi(optarg); - break; + case 'r': + n_rnti=atoi(optarg); + break; - case 'x': - transmission_mode=atoi(optarg); + case 'x': + transmission_mode=atoi(optarg); - if ((transmission_mode!=1) && - (transmission_mode!=2) && - (transmission_mode!=5) && - (transmission_mode!=6)) { - msg("Unsupported transmission mode %d\n",transmission_mode); - exit(-1); - } + if ((transmission_mode!=1) && + (transmission_mode!=2) && + (transmission_mode!=5) && + (transmission_mode!=6)) { + msg("Unsupported transmission mode %d\n",transmission_mode); + exit(-1); + } - break; + break; - case 'y': - n_tx=atoi(optarg); + case 'y': + n_tx=atoi(optarg); - if ((n_tx==0) || (n_tx>2)) { - msg("Unsupported number of tx antennas %d\n",n_tx); - exit(-1); - } + if ((n_tx==0) || (n_tx>2)) { + msg("Unsupported number of tx antennas %d\n",n_tx); + exit(-1); + } - break; + break; - case 'z': - n_rx=atoi(optarg); + case 'z': + n_rx=atoi(optarg); - if ((n_rx==0) || (n_rx>2)) { - msg("Unsupported number of rx antennas %d\n",n_rx); - exit(-1); - } + if ((n_rx==0) || (n_rx>2)) { + msg("Unsupported number of rx antennas %d\n",n_rx); + exit(-1); + } - break; + break; /* case 'A': @@ -583,96 +530,96 @@ int main(int argc, char **argv) } break; */ - case 'D': - frame_type=0; - msg("Running in FDD\n"); - break; + case 'D': + frame_type=0; + msg("Running in FDD\n"); + break; - case 'N': - Nid_cell = atoi(optarg); - break; + case 'N': + Nid_cell = atoi(optarg); + break; - case 'R': - N_RB_DL = atoi(optarg); - break; + case 'R': + N_RB_DL = atoi(optarg); + break; - case 'O': - osf = atoi(optarg); - break; + case 'O': + osf = atoi(optarg); + break; - case 'Z': - oai_hw_input = 1; - break; + case 'Z': + oai_hw_input = 1; + break; - case 'Y': - oai_hw_output = 1; - break; + case 'Y': + oai_hw_output = 1; + break; - case 'F': - input_fd = fopen(optarg,"r"); + case 'F': + input_fd = fopen(optarg,"r"); - if (input_fd==NULL) { - printf("Problem with filename %s\n",optarg); - exit(-1); - } + if (input_fd==NULL) { + printf("Problem with filename %s\n",optarg); + exit(-1); + } - break; + break; - case 'T': - tcxo = atoi(optarg); - break; + case 'T': + tcxo = atoi(optarg); + break; - case 'B': - N_carriers = atoi(optarg); + case 'B': + N_carriers = atoi(optarg); - if ((N_carriers!=1) && (N_carriers!=2)) { - printf("N_carriers must be 1 or 2!\n"); - exit(-1); - } + if ((N_carriers!=1) && (N_carriers!=2)) { + printf("N_carriers must be 1 or 2!\n"); + exit(-1); + } - break; + break; - case 'U': - subframe = atoi(optarg); - break; + case 'U': + subframe = atoi(optarg); + break; - case 'u': - dual_stream_flag=1; - break; + case 'u': + dual_stream_flag=1; + break; - default: - case 'h': - printf("-h This message\n"); - printf("-a Use AWGN channel and not multipath\n"); - printf("-e Use extended prefix mode\n"); - printf("-d Display signal output on XFORMS scope\n"); - printf("-D Use FDD frame\n"); - printf("-n Number of frames to simulate\n"); - printf("-r RNTI for DCI detection in SF 0/5\n"); - printf("-s Starting SNR, runs from SNR0 to SNR0 + 5 dB. If n_frames is 1 then just SNR is simulated\n"); - printf("-S Ending SNR, runs from SNR0 to SNR1\n"); - printf("-t Delay spread for multipath channel\n"); - printf("-g [A,B,C,D,E,F,G] Use 3GPP SCM (A,B,C,D) or 36-101 (E-EPA,F-EVA,G-ETU) models (ignores delay spread and Ricean factor)\n"); - printf("-c Frequency offset\n"); - printf("-x Transmission mode (1,2,6 for the moment)\n"); - printf("-y Number of TX antennas used in eNB\n"); - printf("-z Number of RX antennas used in UE\n"); - printf("-i Relative strength of first intefering eNB (in dB) - cell_id mod 3 = 1\n"); - printf("-j Relative strength of second intefering eNB (in dB) - cell_id mod 3 = 2\n"); - printf("-N Nid_cell\n"); - printf("-R N_RB_DL\n"); - printf("-O oversampling factor (1,2,4,8,16)\n"); - //printf("-A Interpolation_filname Run with Abstraction to generate Scatter plot using interpolation polynomial in file\n"); - printf("-f Output filename (.txt format) for Pe/SNR results\n"); - printf("-F Input filename (.txt format) for RX conformance testing\n"); - printf("-Y just generate tx frame and send it to hardware\n"); - printf("-Z grab frame from hardware and do rx processing\n"); - printf("-T set TCXO parameter on CBMIMO1 hardware\n"); - printf("-C set frequency for ExpressMIMO hardware. Can take up to four parameters in format f1,f2,f3,f4\n"); - printf("-G set RX gain for ExpressMIMO hardware. Can take up to four parameters in format g1,g2,g3,g4\n"); - printf("-d enables the graphical display"); - exit (-1); - break; + default: + case 'h': + printf("-h This message\n"); + printf("-a Use AWGN channel and not multipath\n"); + printf("-e Use extended prefix mode\n"); + printf("-d Display signal output on XFORMS scope\n"); + printf("-D Use FDD frame\n"); + printf("-n Number of frames to simulate\n"); + printf("-r RNTI for DCI detection in SF 0/5\n"); + printf("-s Starting SNR, runs from SNR0 to SNR0 + 5 dB. If n_frames is 1 then just SNR is simulated\n"); + printf("-S Ending SNR, runs from SNR0 to SNR1\n"); + printf("-t Delay spread for multipath channel\n"); + printf("-g [A,B,C,D,E,F,G] Use 3GPP SCM (A,B,C,D) or 36-101 (E-EPA,F-EVA,G-ETU) models (ignores delay spread and Ricean factor)\n"); + printf("-c Frequency offset\n"); + printf("-x Transmission mode (1,2,6 for the moment)\n"); + printf("-y Number of TX antennas used in eNB\n"); + printf("-z Number of RX antennas used in UE\n"); + printf("-i Relative strength of first intefering eNB (in dB) - cell_id mod 3 = 1\n"); + printf("-j Relative strength of second intefering eNB (in dB) - cell_id mod 3 = 2\n"); + printf("-N Nid_cell\n"); + printf("-R N_RB_DL\n"); + printf("-O oversampling factor (1,2,4,8,16)\n"); + //printf("-A Interpolation_filname Run with Abstraction to generate Scatter plot using interpolation polynomial in file\n"); + printf("-f Output filename (.txt format) for Pe/SNR results\n"); + printf("-F Input filename (.txt format) for RX conformance testing\n"); + printf("-Y just generate tx frame and send it to hardware\n"); + printf("-Z grab frame from hardware and do rx processing\n"); + printf("-T set TCXO parameter on CBMIMO1 hardware\n"); + printf("-C set frequency for ExpressMIMO hardware. Can take up to four parameters in format f1,f2,f3,f4\n"); + printf("-G set RX gain for ExpressMIMO hardware. Can take up to four parameters in format g1,g2,g3,g4\n"); + printf("-d enables the graphical display"); + exit (-1); + break; } } @@ -707,7 +654,6 @@ int main(int argc, char **argv) } printf("SNR0 %f, SNR1 %f\n",snr0,snr1); - frame_parms = &PHY_vars_eNB->lte_frame_parms; frame_parms->dual_tx = 0; frame_parms->freq_idx = 0; @@ -738,22 +684,18 @@ int main(int argc, char **argv) if ((oai_hw_input==1) || (oai_hw_output==1)) { msg("setting TCXO to %d\n",tcxo); - ioctl(openair_fd,openair_SET_TCXO_DAC,(void *)&tcxo); } #ifdef IFFT_FPGA - txdata = (int **)malloc16(2*sizeof(int*)); + txdata = (int **)malloc16(2*sizeof(int *)); txdata[0] = (int *)malloc16(FRAME_LENGTH_BYTES); txdata[1] = (int *)malloc16(FRAME_LENGTH_BYTES); - bzero(txdata[0],FRAME_LENGTH_BYTES); bzero(txdata[1],FRAME_LENGTH_BYTES); - - txdataF2 = (int **)malloc16(2*sizeof(int*)); + txdataF2 = (int **)malloc16(2*sizeof(int *)); txdataF2[0] = (int *)malloc16(FRAME_LENGTH_BYTES_NO_PREFIX); txdataF2[1] = (int *)malloc16(FRAME_LENGTH_BYTES_NO_PREFIX); - bzero(txdataF2[0],FRAME_LENGTH_BYTES_NO_PREFIX); bzero(txdataF2[1],FRAME_LENGTH_BYTES_NO_PREFIX); #else @@ -761,26 +703,21 @@ int main(int argc, char **argv) txdata1 = PHY_vars_eNB1->lte_eNB_common_vars.txdata[eNb_id]; txdata2 = PHY_vars_eNB2->lte_eNB_common_vars.txdata[eNb_id]; #endif - - s_re = malloc(2*sizeof(double*)); - s_im = malloc(2*sizeof(double*)); - s_re1 = malloc(2*sizeof(double*)); - s_im1 = malloc(2*sizeof(double*)); - s_re2 = malloc(2*sizeof(double*)); - s_im2 = malloc(2*sizeof(double*)); - r_re = malloc(2*sizeof(double*)); - r_im = malloc(2*sizeof(double*)); - r_re1 = malloc(2*sizeof(double*)); - r_im1 = malloc(2*sizeof(double*)); - r_re2 = malloc(2*sizeof(double*)); - r_im2 = malloc(2*sizeof(double*)); - + s_re = malloc(2*sizeof(double *)); + s_im = malloc(2*sizeof(double *)); + s_re1 = malloc(2*sizeof(double *)); + s_im1 = malloc(2*sizeof(double *)); + s_re2 = malloc(2*sizeof(double *)); + s_im2 = malloc(2*sizeof(double *)); + r_re = malloc(2*sizeof(double *)); + r_im = malloc(2*sizeof(double *)); + r_re1 = malloc(2*sizeof(double *)); + r_im1 = malloc(2*sizeof(double *)); + r_re2 = malloc(2*sizeof(double *)); + r_im2 = malloc(2*sizeof(double *)); nsymb = (frame_parms->Ncp == 0) ? 14 : 12; - printf("FFT Size %d, Extended Prefix %d, Samples per subframe %d, Symbols per subframe %d\n",NUMBER_OF_OFDM_CARRIERS, frame_parms->Ncp,frame_parms->samples_per_tti,nsymb); - - eNB2UE = new_channel_desc_scm(PHY_vars_eNB->lte_frame_parms.nb_antennas_tx, PHY_vars_UE[0]->lte_frame_parms.nb_antennas_rx, channel_model, @@ -807,14 +744,12 @@ int main(int argc, char **argv) 0, 0); - if (eNB2UE==NULL) { msg("Problem generating channel model. Exiting.\n"); exit(-1); } for (i=0; i<2; i++) { - s_re[i] = malloc(FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double)); bzero(s_re[i],FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double)); s_im[i] = malloc(FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double)); @@ -827,7 +762,6 @@ int main(int argc, char **argv) bzero(s_re2[i],FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double)); s_im2[i] = malloc(FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double)); bzero(s_im2[i],FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double)); - r_re[i] = malloc(FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double)); bzero(r_re[i],FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double)); r_im[i] = malloc(FRAME_LENGTH_COMPLEX_SAMPLES*sizeof(double)); @@ -867,69 +801,67 @@ int main(int argc, char **argv) // load_pbch_desc(pbch_file_fd); // } - if ((input_fd==NULL)&&(oai_hw_input==0)) { - // for (i=0;i<6;i++) // pbch_pdu[i] = i; //pbch_pdu[0]=100; //pbch_pdu[1]=1; //pbch_pdu[2]=0; - ((uint8_t*) pbch_pdu)[0] = 0; + ((uint8_t *) pbch_pdu)[0] = 0; switch (PHY_vars_eNB->lte_frame_parms.N_RB_DL) { - case 6: - ((uint8_t*) pbch_pdu)[0] = (((uint8_t*) pbch_pdu)[0]&0x1f) | (0<<5); - break; + case 6: + ((uint8_t *) pbch_pdu)[0] = (((uint8_t *) pbch_pdu)[0]&0x1f) | (0<<5); + break; - case 15: - ((uint8_t*) pbch_pdu)[0] = (((uint8_t*) pbch_pdu)[0]&0x1f) | (1<<5); - break; + case 15: + ((uint8_t *) pbch_pdu)[0] = (((uint8_t *) pbch_pdu)[0]&0x1f) | (1<<5); + break; - case 25: - ((uint8_t*) pbch_pdu)[0] = (((uint8_t*) pbch_pdu)[0]&0x1f) | (2<<5); - break; + case 25: + ((uint8_t *) pbch_pdu)[0] = (((uint8_t *) pbch_pdu)[0]&0x1f) | (2<<5); + break; - case 50: - ((uint8_t*) pbch_pdu)[0] = (((uint8_t*) pbch_pdu)[0]&0x1f) | (3<<5); - break; + case 50: + ((uint8_t *) pbch_pdu)[0] = (((uint8_t *) pbch_pdu)[0]&0x1f) | (3<<5); + break; - case 100: - ((uint8_t*) pbch_pdu)[0] = (((uint8_t*) pbch_pdu)[0]&0x1f) | (4<<5); - break; + case 100: + ((uint8_t *) pbch_pdu)[0] = (((uint8_t *) pbch_pdu)[0]&0x1f) | (4<<5); + break; - default: - ((uint8_t*) pbch_pdu)[0] = (((uint8_t*) pbch_pdu)[0]&0x1f) | (2<<5); - break; + default: + ((uint8_t *) pbch_pdu)[0] = (((uint8_t *) pbch_pdu)[0]&0x1f) | (2<<5); + break; } - ((uint8_t*) pbch_pdu)[0] = (((uint8_t*) pbch_pdu)[0]&0xef) | - ((PHY_vars_eNB->lte_frame_parms.phich_config_common.phich_duration << 4)&0x10); + ((uint8_t *) pbch_pdu)[0] = (((uint8_t *) pbch_pdu)[0]&0xef) | + ((PHY_vars_eNB->lte_frame_parms.phich_config_common.phich_duration << 4)&0x10); switch (PHY_vars_eNB->lte_frame_parms.phich_config_common.phich_resource) { - case oneSixth: - ((uint8_t*) pbch_pdu)[0] = (((uint8_t*) pbch_pdu)[0]&0xf3) | (0<<3); - break; + case oneSixth: + ((uint8_t *) pbch_pdu)[0] = (((uint8_t *) pbch_pdu)[0]&0xf3) | (0<<3); + break; - case half: - ((uint8_t*) pbch_pdu)[0] = (((uint8_t*) pbch_pdu)[0]&0xf3) | (1<<3); - break; + case half: + ((uint8_t *) pbch_pdu)[0] = (((uint8_t *) pbch_pdu)[0]&0xf3) | (1<<3); + break; - case one: - ((uint8_t*) pbch_pdu)[0] = (((uint8_t*) pbch_pdu)[0]&0xf3) | (2<<3); - break; + case one: + ((uint8_t *) pbch_pdu)[0] = (((uint8_t *) pbch_pdu)[0]&0xf3) | (2<<3); + break; - case two: - ((uint8_t*) pbch_pdu)[0] = (((uint8_t*) pbch_pdu)[0]&0xf3) | (3<<3); - break; + case two: + ((uint8_t *) pbch_pdu)[0] = (((uint8_t *) pbch_pdu)[0]&0xf3) | (3<<3); + break; - default: - break; + default: + break; } - ((uint8_t*) pbch_pdu)[0] = (((uint8_t*) pbch_pdu)[0]&0xfc) | ((PHY_vars_eNB->frame>>8)&0x3); - ((uint8_t*) pbch_pdu)[1] = PHY_vars_eNB->frame&0xfc; - ((uint8_t*) pbch_pdu)[2] = 0; + ((uint8_t *) pbch_pdu)[0] = (((uint8_t *) pbch_pdu)[0]&0xfc) | ((PHY_vars_eNB->frame>>8)&0x3); + ((uint8_t *) pbch_pdu)[1] = PHY_vars_eNB->frame&0xfc; + ((uint8_t *) pbch_pdu)[2] = 0; if (PHY_vars_eNB->lte_frame_parms.frame_type == 1) { generate_pss(PHY_vars_eNB->lte_eNB_common_vars.txdataF[0], @@ -975,21 +907,11 @@ int main(int argc, char **argv) 10); } - - printf("Generating PBCH for mode1_flag = %d, frame_type %d\n", PHY_vars_eNB->lte_frame_parms.mode1_flag,PHY_vars_eNB->lte_frame_parms.frame_type); - - generate_pilots(PHY_vars_eNB, PHY_vars_eNB->lte_eNB_common_vars.txdataF[0], AMP, LTE_NUMBER_OF_SUBFRAMES_PER_FRAME); - - - - - - generate_pbch(&PHY_vars_eNB->lte_eNB_pbch, PHY_vars_eNB->lte_eNB_common_vars.txdataF[0], AMP, @@ -1010,24 +932,16 @@ int main(int argc, char **argv) &PHY_vars_eNB1->lte_frame_parms, (PHY_vars_eNB1->lte_frame_parms.Ncp==0)?6:5, 0); - - - - - generate_pilots(PHY_vars_eNB1, PHY_vars_eNB1->lte_eNB_common_vars.txdataF[0], AMP, LTE_NUMBER_OF_SUBFRAMES_PER_FRAME); - - generate_pbch(&PHY_vars_eNB1->lte_eNB_pbch, PHY_vars_eNB1->lte_eNB_common_vars.txdataF[0], AMP, &PHY_vars_eNB1->lte_frame_parms, pbch_pdu, 0); - } if (interf2>-20) { @@ -1036,36 +950,28 @@ int main(int argc, char **argv) &PHY_vars_eNB2->lte_frame_parms, (PHY_vars_eNB2->lte_frame_parms.Ncp==0)?6:5, 0); - - - - - generate_pilots(PHY_vars_eNB2, PHY_vars_eNB2->lte_eNB_common_vars.txdataF[0], AMP, LTE_NUMBER_OF_SUBFRAMES_PER_FRAME); - - generate_pbch(&PHY_vars_eNB2->lte_eNB_pbch, PHY_vars_eNB2->lte_eNB_common_vars.txdataF[0], AMP, &PHY_vars_eNB2->lte_frame_parms, pbch_pdu, 0); - } // Generate two PDCCH if (frame_type == 0) { - ((DCI1_5MHz_FDD_t*)&DLSCH_alloc_pdu)->rah = 0; - ((DCI1_5MHz_FDD_t*)&DLSCH_alloc_pdu)->rballoc = DLSCH_RB_ALLOC; - ((DCI1_5MHz_FDD_t*)&DLSCH_alloc_pdu)->TPC = 0; - ((DCI1_5MHz_FDD_t*)&DLSCH_alloc_pdu)->harq_pid = 0; - ((DCI1_5MHz_FDD_t*)&DLSCH_alloc_pdu)->mcs = 0; - ((DCI1_5MHz_FDD_t*)&DLSCH_alloc_pdu)->ndi = 1; - ((DCI1_5MHz_FDD_t*)&DLSCH_alloc_pdu)->rv = 0; + ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu)->rah = 0; + ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu)->rballoc = DLSCH_RB_ALLOC; + ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu)->TPC = 0; + ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu)->harq_pid = 0; + ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu)->mcs = 0; + ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu)->ndi = 1; + ((DCI1_5MHz_FDD_t *)&DLSCH_alloc_pdu)->rv = 0; dci_alloc[0].dci_length = sizeof_DCI1_5MHz_FDD_t; memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu,sizeof(DCI1_5MHz_FDD_t)); dci_alloc[0].L = 2; @@ -1073,16 +979,16 @@ int main(int argc, char **argv) dci_alloc[0].format = format1; dci_alloc[0].search_space = DCI_UE_SPACE; } else { - ((DCI1E_5MHz_2A_M10PRB_TDD_t*)&DLSCH_alloc_pdu)->rah = 0; - ((DCI1E_5MHz_2A_M10PRB_TDD_t*)&DLSCH_alloc_pdu)->rballoc = DLSCH_RB_ALLOC; - ((DCI1E_5MHz_2A_M10PRB_TDD_t*)&DLSCH_alloc_pdu)->TPC = 0; - ((DCI1E_5MHz_2A_M10PRB_TDD_t*)&DLSCH_alloc_pdu)->dai = 0; - ((DCI1E_5MHz_2A_M10PRB_TDD_t*)&DLSCH_alloc_pdu)->harq_pid = 0; - ((DCI1E_5MHz_2A_M10PRB_TDD_t*)&DLSCH_alloc_pdu)->mcs = 0; - ((DCI1E_5MHz_2A_M10PRB_TDD_t*)&DLSCH_alloc_pdu)->ndi = 1; - ((DCI1E_5MHz_2A_M10PRB_TDD_t*)&DLSCH_alloc_pdu)->rv = 0; - ((DCI1E_5MHz_2A_M10PRB_TDD_t*)&DLSCH_alloc_pdu)->tpmi = (transmission_mode>=5 ? 5 : 0); // precoding - ((DCI1E_5MHz_2A_M10PRB_TDD_t*)&DLSCH_alloc_pdu)->dl_power_off = (transmission_mode==5 ? 0 : 1); + ((DCI1E_5MHz_2A_M10PRB_TDD_t *)&DLSCH_alloc_pdu)->rah = 0; + ((DCI1E_5MHz_2A_M10PRB_TDD_t *)&DLSCH_alloc_pdu)->rballoc = DLSCH_RB_ALLOC; + ((DCI1E_5MHz_2A_M10PRB_TDD_t *)&DLSCH_alloc_pdu)->TPC = 0; + ((DCI1E_5MHz_2A_M10PRB_TDD_t *)&DLSCH_alloc_pdu)->dai = 0; + ((DCI1E_5MHz_2A_M10PRB_TDD_t *)&DLSCH_alloc_pdu)->harq_pid = 0; + ((DCI1E_5MHz_2A_M10PRB_TDD_t *)&DLSCH_alloc_pdu)->mcs = 0; + ((DCI1E_5MHz_2A_M10PRB_TDD_t *)&DLSCH_alloc_pdu)->ndi = 1; + ((DCI1E_5MHz_2A_M10PRB_TDD_t *)&DLSCH_alloc_pdu)->rv = 0; + ((DCI1E_5MHz_2A_M10PRB_TDD_t *)&DLSCH_alloc_pdu)->tpmi = (transmission_mode>=5 ? 5 : 0); // precoding + ((DCI1E_5MHz_2A_M10PRB_TDD_t *)&DLSCH_alloc_pdu)->dl_power_off = (transmission_mode==5 ? 0 : 1); dci_alloc[0].dci_length = sizeof_DCI1E_5MHz_2A_M10PRB_TDD_t; memcpy(&dci_alloc[0].dci_pdu[0],&DLSCH_alloc_pdu,sizeof(DCI1E_5MHz_2A_M10PRB_TDD_t)); dci_alloc[0].L = 2; @@ -1107,7 +1013,6 @@ int main(int argc, char **argv) PHY_vars_eNB->lte_eNB_common_vars.txdataF[eNb_id], 5); */ - // LOG_M("pilotsF.m","rsF",txdataF[0],lte_frame_parms->ofdm_symbol_size,1,1); #ifdef IFFT_FPGA LOG_M("txsigF0.m","txsF0", PHY_vars_eNB->lte_eNB_common_vars.txdataF[eNb_id][0],300*120,1,4); @@ -1116,8 +1021,7 @@ int main(int argc, char **argv) LOG_M("txsigF1.m","txsF1", PHY_vars_eNB->lte_eNB_common_vars.txdataF[eNb_id][1],300*120,1,4); for (i=0; i<10; i++) - debug_msg("%08x\n",((unsigned int*)&PHY_vars_eNB->lte_eNB_common_vars.txdataF[0][0][1*(PHY_vars_eNB->lte_frame_parms.N_RB_DL*12)*(PHY_vars_eNB->lte_frame_parms.symbols_per_tti>>1)])[i]); - + debug_msg("%08x\n",((unsigned int *)&PHY_vars_eNB->lte_eNB_common_vars.txdataF[0][0][1*(PHY_vars_eNB->lte_frame_parms.N_RB_DL*12)*(PHY_vars_eNB->lte_frame_parms.symbols_per_tti>>1)])[i]); // do talbe lookup and write results to txdataF2 for (aa=0; aa<PHY_vars_eNB->lte_frame_parms.nb_antennas_tx; aa++) { @@ -1125,9 +1029,9 @@ int main(int argc, char **argv) for (i=0; i<FRAME_LENGTH_COMPLEX_SAMPLES_NO_PREFIX; i++) if ((i%512>=1) && (i%512<=150)) - txdataF2[aa][i] = ((int*)mod_table)[PHY_vars_eNB->lte_eNB_common_vars.txdataF[eNb_id][aa][l++]]; + txdataF2[aa][i] = ((int *)mod_table)[PHY_vars_eNB->lte_eNB_common_vars.txdataF[eNb_id][aa][l++]]; else if (i%512>=362) - txdataF2[aa][i] = ((int*)mod_table)[PHY_vars_eNB->lte_eNB_common_vars.txdataF[eNb_id][aa][l++]]; + txdataF2[aa][i] = ((int *)mod_table)[PHY_vars_eNB->lte_eNB_common_vars.txdataF[eNb_id][aa][l++]]; else txdataF2[aa][i] = 0; @@ -1139,11 +1043,9 @@ int main(int argc, char **argv) if (PHY_vars_eNB->lte_frame_parms.nb_antennas_tx>1) LOG_M("txsigF21.m","txsF21", txdataF2[1],FRAME_LENGTH_COMPLEX_SAMPLES_NO_PREFIX,1,1); - tx_lev=0; for (aa=0; aa<PHY_vars_eNB->lte_frame_parms.nb_antennas_tx; aa++) { - if (frame_parms->Ncp == 1) PHY_ofdm_mod(txdataF2[aa], // input txdata[aa], // output @@ -1169,9 +1071,6 @@ int main(int argc, char **argv) tx_lev = 0; - - - for (aa=0; aa<PHY_vars_eNB->lte_frame_parms.nb_antennas_tx; aa++) { if (frame_parms->Ncp == 1) PHY_ofdm_mod(PHY_vars_eNB->lte_eNB_common_vars.txdataF[eNb_id][aa], // input, @@ -1234,9 +1133,6 @@ int main(int argc, char **argv) } #endif - - - LOG_M("txsig0.m","txs0", txdata[0],FRAME_LENGTH_COMPLEX_SAMPLES,1,1); if (frame_parms->nb_antennas_tx>1) @@ -1245,7 +1141,7 @@ int main(int argc, char **argv) i=0; while (!feof(input_fd)) { - ret=fscanf(input_fd,"%s %s",input_val_str,input_val_str2);//&input_val1,&input_val2); + ret=fscanf(input_fd,"%49s %49s",input_val_str,input_val_str2);//&input_val1,&input_val2); /* if ((i%4)==0) { ((short*)txdata[0])[i/2] = (short)((1<<15)*strtod(input_val_str,NULL)); @@ -1254,9 +1150,8 @@ int main(int argc, char **argv) printf("sample %d => %e + j%e (%d +j%d)\n",i/4,strtod(input_val_str,NULL),strtod(input_val_str2,NULL),((short*)txdata[0])[i/4],((short*)txdata[0])[(i/4)+1]);//1,input_val2,); } */ - ((short*)txdata[0])[i<<1] = 16*(short)(strtod(input_val_str,NULL)); - ((short*)txdata[0])[(i<<1)+1] = 16*(short)(strtod(input_val_str2,NULL)); - + ((short *)txdata[0])[i<<1] = 16*(short)(strtod(input_val_str,NULL)); + ((short *)txdata[0])[(i<<1)+1] = 16*(short)(strtod(input_val_str2,NULL)); i++; if (i==(FRAME_LENGTH_COMPLEX_SAMPLES)) @@ -1270,8 +1165,6 @@ int main(int argc, char **argv) OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES); } else { // get from OAI HW // set check if we have to set up a signal generator here - - printf("Doing Acquisition from OAI HW\n"); snr0=snr1-.1; } @@ -1283,13 +1176,10 @@ int main(int argc, char **argv) sn = sin(2*M_PI*foff*i); for (aa=0; aa<PHY_vars_eNB->lte_frame_parms.nb_antennas_tx; aa++) { - - tmp_re = (double)((short*)txdata[aa])[(i<<1)]*cs - (double)((short*)txdata[aa])[1+(i<<1)]*sn; - - tmp_im = (double)((short*)txdata[aa])[1+(i<<1)]*cs + (double)((short*)txdata[aa])[(i<<1)]*sn; + tmp_re = (double)((short *)txdata[aa])[(i<<1)]*cs - (double)((short *)txdata[aa])[1+(i<<1)]*sn; + tmp_im = (double)((short *)txdata[aa])[1+(i<<1)]*cs + (double)((short *)txdata[aa])[(i<<1)]*sn; if (awgn_flag == 0) { - s_re[aa][i] = tmp_re; s_im[aa][i] = tmp_im; @@ -1302,7 +1192,6 @@ int main(int argc, char **argv) s_re2[aa][i] = ((double)(((short *)txdata2[aa]))[(i<<1)]); s_im2[aa][i] = ((double)(((short *)txdata2[aa]))[(i<<1)+1]); } - } else { for (aarx=0; aarx<PHY_vars_UE[0]->lte_frame_parms.nb_antennas_rx; aarx++) { if (aa==0) { @@ -1330,19 +1219,14 @@ int main(int argc, char **argv) } if (oai_hw_output==0) { - for (SNR=snr0; SNR<snr1; SNR+=.2) { - n_errors = 0; n_errors2 = 0; n_alamouti = 0; for (trial=0; trial<n_frames; trial++) { - if (oai_hw_input == 0) { - if (awgn_flag == 0) { - multipath_channel(eNB2UE,s_re,s_im,r_re,r_im, FRAME_LENGTH_COMPLEX_SAMPLES,0);//LTE_NUMBER_OF_SUBFRAMES_PER_FRAME*nsymb*OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES,0); @@ -1353,7 +1237,6 @@ int main(int argc, char **argv) if (interf2>-20) multipath_channel(eNB2UE2,s_re2,s_im2,r_re2,r_im2, LTE_NUMBER_OF_SUBFRAMES_PER_FRAME*nsymb*OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES,0); - } // awgn_flag sigma2_dB = 10*log10((double)tx_lev) +10*log10(PHY_vars_eNB->lte_frame_parms.ofdm_symbol_size/(12*NB_RB)) - SNR; @@ -1363,7 +1246,6 @@ int main(int argc, char **argv) //AWGN sigma2 = pow(10,sigma2_dB/10); - /* if (n_frames==1) { printf("rx_level data symbol %f, tx_lev %f\n", @@ -1371,16 +1253,14 @@ int main(int argc, char **argv) 10*log10(tx_lev)); } */ - iout = 0;//taus()%(FRAME_LENGTH_COMPLEX_SAMPLES>>2); for (i=0; i<FRAME_LENGTH_COMPLEX_SAMPLES; i++) { //nsymb*OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES; i++) { for (aa=0; aa<PHY_vars_eNB->lte_frame_parms.nb_antennas_rx; aa++) { r_re[aa][i] += (pow(10.0,.05*interf1)*r_re1[aa][i] + pow(10.0,.05*interf2)*r_re2[aa][i]); r_im[aa][i] += (pow(10.0,.05*interf1)*r_im1[aa][i] + pow(10.0,.05*interf2)*r_im2[aa][i]); - - ((short*) PHY_vars_UE[0]->lte_ue_common_vars.rxdata[aa])[2*i] = (short) (.167*(r_re[aa][i] +sqrt(sigma2/2)*gaussdouble(0.0,1.0))); - ((short*) PHY_vars_UE[0]->lte_ue_common_vars.rxdata[aa])[(2*i)+1] = (short) (.167*(r_im[aa][i] + (iqim*r_re[aa][i]) + sqrt(sigma2/2)*gaussdouble(0.0,1.0))); + ((short *) PHY_vars_UE[0]->lte_ue_common_vars.rxdata[aa])[2*i] = (short) (.167*(r_re[aa][i] +sqrt(sigma2/2)*gaussdouble(0.0,1.0))); + ((short *) PHY_vars_UE[0]->lte_ue_common_vars.rxdata[aa])[(2*i)+1] = (short) (.167*(r_im[aa][i] + (iqim*r_re[aa][i]) + sqrt(sigma2/2)*gaussdouble(0.0,1.0))); } iout++; @@ -1440,11 +1320,9 @@ int main(int argc, char **argv) 0); } - PHY_vars_UE[UE_idx]->lte_ue_pdcch_vars[0]->crnti = n_rnti; PHY_vars_UE[UE_idx]->transmission_mode[0] = transmission_mode; PHY_vars_UE[UE_idx]->UE_mode[0] = PUSCH; - printf("Fine Frequency offset %d\n",PHY_vars_UE[UE_idx]->lte_ue_common_vars.freq_offset); printf("Doing PDCCH RX : num_pdcch_symbols at TX %d\n",num_pdcch_symbols); rx_pdcch(&PHY_vars_UE[UE_idx]->lte_ue_common_vars, @@ -1456,7 +1334,6 @@ int main(int argc, char **argv) (PHY_vars_UE[UE_idx]->lte_frame_parms.mode1_flag == 1) ? SISO : ALAMOUTI, PHY_vars_UE[UE_idx]->is_secondary_ue); printf("Got PCFICH for %d pdcch symbols\n",PHY_vars_UE[UE_idx]->lte_ue_pdcch_vars[0]->num_pdcch_symbols); - dci_cnt = dci_decoding_procedure(PHY_vars_UE[UE_idx], dci_alloc_rx, 0, @@ -1475,9 +1352,7 @@ int main(int argc, char **argv) SI_RNTI, 0, P_RNTI); - i_mod = get_Qm(PHY_vars_UE[UE_idx]->dlsch_ue[0][0]->harq_processes[0]->mcs); - /* // overwrite some values until source is sure PHY_vars_UE[UE_idx]->dlsch_ue[0][0]->nb_rb = 25; @@ -1485,7 +1360,6 @@ int main(int argc, char **argv) PHY_vars_UE[UE_idx]->dlsch_ue[0][0]->harq_processes[0]->Ndi = 1; PHY_vars_UE[UE_idx]->dlsch_ue[0][0]->harq_processes[0]->mcs = 0; */ - dump_dci(&PHY_vars_UE[UE_idx]->lte_frame_parms, &dci_alloc_rx[0]); for (l=PHY_vars_UE[UE_idx]->lte_ue_pdcch_vars[0]->num_pdcch_symbols; @@ -1590,20 +1464,16 @@ int main(int argc, char **argv) i_mod); } - - coded_bits_per_codeword = get_G(&PHY_vars_UE[UE_idx]->lte_frame_parms, PHY_vars_UE[UE_idx]->dlsch_ue[0][0]->nb_rb, PHY_vars_UE[UE_idx]->dlsch_ue[0][0]->rb_alloc, get_Qm(PHY_vars_UE[UE_idx]->dlsch_ue[0][0]->harq_processes[PHY_vars_UE[UE_idx]->dlsch_ue[0][0]->current_harq_pid]->mcs), PHY_vars_UE[UE_idx]->lte_ue_pdcch_vars[0]->num_pdcch_symbols, subframe); - - printf("G %d, TBS %d, pdcch_sym %d\n", + printf("G %u, TBS %d, pdcch_sym %d\n", coded_bits_per_codeword, dlsch_tbs25[get_I_TBS(PHY_vars_UE[UE_idx]->dlsch_ue[0][0]->harq_processes[0]->mcs)][PHY_vars_UE[UE_idx]->dlsch_ue[0][0]->nb_rb-1], num_pdcch_symbols); - dlsch_unscrambling(&PHY_vars_UE[UE_idx]->lte_frame_parms, PHY_vars_UE[UE_idx]->lte_ue_pdcch_vars[0]->num_pdcch_symbols, PHY_vars_UE[UE_idx]->dlsch_ue[0][0], @@ -1611,7 +1481,6 @@ int main(int argc, char **argv) PHY_vars_UE[UE_idx]->lte_ue_pdsch_vars[0]->llr[0], 0, subframe<<1); - ret = dlsch_decoding(PHY_vars_UE[UE_idx], PHY_vars_UE[UE_idx]->lte_ue_pdsch_vars[0]->llr[0], &PHY_vars_UE[UE_idx]->lte_frame_parms, @@ -1635,53 +1504,52 @@ int main(int argc, char **argv) n_errors++; } - #ifdef XFORMS if (do_forms==1) { do_forms2(form_dl, frame_parms, PHY_vars_UE[0]->lte_ue_pdcch_vars[0]->num_pdcch_symbols, - (int16_t**)PHY_vars_UE[0]->lte_ue_common_vars.dl_ch_estimates_time, - (int16_t**)PHY_vars_UE[0]->lte_ue_common_vars.common_vars_rx_data_per_thread[subframe&0x1].dl_ch_estimates[0], - (int16_t**)PHY_vars_UE[0]->lte_ue_common_vars.rxdata, - (int16_t**)PHY_vars_UE[0]->lte_ue_common_vars.common_vars_rx_data_per_thread[subframe&0x1].rxdataF, - (int16_t*)PHY_vars_UE[0]->lte_ue_pdcch_vars[0]->rxdataF_comp[0], - (int16_t*)PHY_vars_UE[0]->lte_ue_pdsch_vars[0]->rxdataF_comp[0], - (int16_t*)PHY_vars_UE[0]->lte_ue_pdsch_vars[1]->rxdataF_comp[0], - (int16_t*)PHY_vars_UE[0]->lte_ue_pdsch_vars[0]->llr[0], - (int16_t*)PHY_vars_UE[0]->lte_ue_pbch_vars[0]->rxdataF_comp[0], - (int8_t*)PHY_vars_UE[0]->lte_ue_pbch_vars[0]->llr, + (int16_t **)PHY_vars_UE[0]->lte_ue_common_vars.dl_ch_estimates_time, + (int16_t **)PHY_vars_UE[0]->lte_ue_common_vars.common_vars_rx_data_per_thread[subframe&0x1].dl_ch_estimates[0], + (int16_t **)PHY_vars_UE[0]->lte_ue_common_vars.rxdata, + (int16_t **)PHY_vars_UE[0]->lte_ue_common_vars.common_vars_rx_data_per_thread[subframe&0x1].rxdataF, + (int16_t *)PHY_vars_UE[0]->lte_ue_pdcch_vars[0]->rxdataF_comp[0], + (int16_t *)PHY_vars_UE[0]->lte_ue_pdsch_vars[0]->rxdataF_comp[0], + (int16_t *)PHY_vars_UE[0]->lte_ue_pdsch_vars[1]->rxdataF_comp[0], + (int16_t *)PHY_vars_UE[0]->lte_ue_pdsch_vars[0]->llr[0], + (int16_t *)PHY_vars_UE[0]->lte_ue_pbch_vars[0]->rxdataF_comp[0], + (int8_t *)PHY_vars_UE[0]->lte_ue_pbch_vars[0]->llr, coded_bits_per_codeword); if (N_carriers==2) do_forms2(form_dl1, frame_parms, PHY_vars_UE[1]->lte_ue_pdcch_vars[0]->num_pdcch_symbols, - (int16_t**)PHY_vars_UE[1]->lte_ue_common_vars.dl_ch_estimates_time, - (int16_t**)PHY_vars_UE[1]->lte_ue_common_vars.common_vars_rx_data_per_thread[subframe&0x1].dl_ch_estimates[0], - (int16_t**)PHY_vars_UE[1]->lte_ue_common_vars.rxdata, - (int16_t**)PHY_vars_UE[1]->lte_ue_common_vars.common_vars_rx_data_per_thread[subframe&0x1].rxdataF, - (int16_t*)PHY_vars_UE[1]->lte_ue_pdcch_vars[0]->rxdataF_comp[0], - (int16_t*)PHY_vars_UE[1]->lte_ue_pdsch_vars[0]->rxdataF_comp[0], - (int16_t*)PHY_vars_UE[1]->lte_ue_pdsch_vars[3]->rxdataF_comp[0], - (int16_t*)PHY_vars_UE[1]->lte_ue_pdsch_vars[0]->llr[0], - (int16_t*)PHY_vars_UE[1]->lte_ue_pbch_vars[0]->rxdataF_comp[0], - (int8_t*)PHY_vars_UE[1]->lte_ue_pbch_vars[0]->llr, + (int16_t **)PHY_vars_UE[1]->lte_ue_common_vars.dl_ch_estimates_time, + (int16_t **)PHY_vars_UE[1]->lte_ue_common_vars.common_vars_rx_data_per_thread[subframe&0x1].dl_ch_estimates[0], + (int16_t **)PHY_vars_UE[1]->lte_ue_common_vars.rxdata, + (int16_t **)PHY_vars_UE[1]->lte_ue_common_vars.common_vars_rx_data_per_thread[subframe&0x1].rxdataF, + (int16_t *)PHY_vars_UE[1]->lte_ue_pdcch_vars[0]->rxdataF_comp[0], + (int16_t *)PHY_vars_UE[1]->lte_ue_pdsch_vars[0]->rxdataF_comp[0], + (int16_t *)PHY_vars_UE[1]->lte_ue_pdsch_vars[3]->rxdataF_comp[0], + (int16_t *)PHY_vars_UE[1]->lte_ue_pdsch_vars[0]->llr[0], + (int16_t *)PHY_vars_UE[1]->lte_ue_pbch_vars[0]->rxdataF_comp[0], + (int8_t *)PHY_vars_UE[1]->lte_ue_pbch_vars[0]->llr, 1920); } #endif - } // trials } // SNR if (n_frames==1) { - - LOG_M("H00.m","h00",&(PHY_vars_UE[0]->lte_ue_common_vars.common_vars_rx_data_per_thread[subframe&0x1].dl_ch_estimates[0][0][0]),((frame_parms->Ncp==0)?7:6)*(PHY_vars_eNB->lte_frame_parms.ofdm_symbol_size),1,1); + LOG_M("H00.m","h00",&(PHY_vars_UE[0]->lte_ue_common_vars.common_vars_rx_data_per_thread[subframe&0x1].dl_ch_estimates[0][0][0]), + ((frame_parms->Ncp==0)?7:6)*(PHY_vars_eNB->lte_frame_parms.ofdm_symbol_size),1,1); if (n_tx==2) - LOG_M("H10.m","h10",&(PHY_vars_UE[0]->lte_ue_common_vars.common_vars_rx_data_per_thread[subframe&0x1].dl_ch_estimates[0][2][0]),((frame_parms->Ncp==0)?7:6)*(PHY_vars_eNB->lte_frame_parms.ofdm_symbol_size),1,1); + LOG_M("H10.m","h10",&(PHY_vars_UE[0]->lte_ue_common_vars.common_vars_rx_data_per_thread[subframe&0x1].dl_ch_estimates[0][2][0]), + ((frame_parms->Ncp==0)?7:6)*(PHY_vars_eNB->lte_frame_parms.ofdm_symbol_size),1,1); LOG_M("rxsig0.m","rxs0", PHY_vars_UE[0]->lte_ue_common_vars.rxdata[0],FRAME_LENGTH_COMPLEX_SAMPLES,1,1); LOG_M("rxsigF0.m","rxsF0", PHY_vars_UE[0]->lte_ue_common_vars.rxdataF[0],NUMBER_OF_OFDM_CARRIERS*LTE_NUMBER_OF_SUBFRAMES_PER_FRAME*nsymb,2,1); @@ -1691,16 +1559,13 @@ int main(int argc, char **argv) LOG_M("pdcch_rxF_ext0.m","pdcch_rxF_ext0",PHY_vars_UE[0]->lte_ue_pdcch_vars[eNb_id]->rxdataF_ext[0],3*300,1,1); LOG_M("pdcch_rxF_comp0.m","pdcch0_rxF_comp0",PHY_vars_UE[0]->lte_ue_pdcch_vars[eNb_id]->rxdataF_comp[0],4*300,1,1); LOG_M("pdcch_rxF_llr.m","pdcch_llr",PHY_vars_UE[0]->lte_ue_pdcch_vars[eNb_id]->llr,2400,1,4); - coded_bits_per_codeword = get_G(&PHY_vars_UE[0]->lte_frame_parms, PHY_vars_UE[0]->dlsch_ue[0][0]->nb_rb, PHY_vars_UE[0]->dlsch_ue[0][0]->rb_alloc, get_Qm(PHY_vars_UE[0]->dlsch_ue[0][0]->harq_processes[0]->mcs), PHY_vars_UE[0]->lte_ue_pdcch_vars[0]->num_pdcch_symbols, 0); - dump_dlsch2(PHY_vars_UE[0],0,0,&coded_bits_per_codeword); - } } else { printf("Sending frame to OAI HW\n"); @@ -1720,8 +1585,6 @@ int main(int argc, char **argv) } #endif - - #ifdef IFFT_FPGA free(txdataF2[0]); free(txdataF2[1]); @@ -1750,20 +1613,20 @@ int main(int argc, char **argv) free(r_re); printf("Freeing r_im\n"); free(r_im); - - lte_sync_time_free(); if (write_output_file) fclose(output_fd); + if (input_fd) + fclose(input_fd); + if ((oai_hw_input==1)|| (oai_hw_output==1)) { close(openair_fd); } return(n_errors); - } diff --git a/openair1/SIMULATION/LTE_PHY/ulsim.c b/openair1/SIMULATION/LTE_PHY/ulsim.c index 09d0bb9150ebda157ea30b2009352345e1cb0434..0c17e21acc647ea7489860fed86e7fd73a3ffd22 100644 --- a/openair1/SIMULATION/LTE_PHY/ulsim.c +++ b/openair1/SIMULATION/LTE_PHY/ulsim.c @@ -349,19 +349,6 @@ int main(int argc, char **argv) { char input_val_str[50],input_val_str2[50]; // FILE *rx_frame_file; FILE *csv_fdUL=NULL; - /* - FILE *fperen=NULL; - char fperen_name[512]; - - FILE *fmageren=NULL; - char fmageren_name[512]; - - FILE *flogeren=NULL; - char flogeren_name[512]; - */ - /* FILE *ftxlev; - char ftxlev_name[512]; - */ char csv_fname[512]; static int n_frames=5000; static int n_ch_rlz = 1; @@ -405,7 +392,6 @@ int main(int argc, char **argv) { cpu_freq_GHz = (double)get_cpu_freq_GHz(); cpuf = cpu_freq_GHz; set_parallel_conf("PARALLEL_SINGLE_THREAD"); - printf("Detected cpu_freq %f GHz\n",cpu_freq_GHz); AssertFatal(load_configmodule(argc,argv,CONFIG_ENABLECMDLINEONLY) != NULL, "cannot load configuration module, exiting\n"); @@ -456,10 +442,8 @@ int main(int argc, char **argv) { { "help", "display help and exit", PARAMFLAG_BOOL, iptr:&help, defintval:0, TYPE_INT, 0 }, { "", "",0, iptr:NULL, defintval:0, TYPE_INT, 0 }, }; - struct option * long_options = parse_oai_options(options); - + struct option *long_options = parse_oai_options(options); int option_index; - int res; while ((res=getopt_long_only(argc, argv, "", long_options, &option_index)) == 0) { @@ -467,125 +451,125 @@ int main(int argc, char **argv) { if (long_options[option_index].has_arg==no_argument) *(bool *)options[option_index].iptr=1; else switch (options[option_index].type) { - case TYPE_INT: - *(int *)options[option_index].iptr=atoi(optarg); - break; - - case TYPE_DOUBLE: - *(double *)options[option_index].dblptr=atof(optarg); - break; - - case TYPE_UINT8: - *(uint8_t *)options[option_index].dblptr=atoi(optarg); - break; - - case TYPE_UINT16: - *(uint16_t *)options[option_index].dblptr=atoi(optarg); - break; - - default: - printf("not decoded type.\n"); - exit(1); + case TYPE_INT: + *(int *)options[option_index].iptr=atoi(optarg); + break; + + case TYPE_DOUBLE: + *(double *)options[option_index].dblptr=atof(optarg); + break; + + case TYPE_UINT8: + *(uint8_t *)options[option_index].dblptr=atoi(optarg); + break; + + case TYPE_UINT16: + *(uint16_t *)options[option_index].dblptr=atoi(optarg); + break; + + default: + printf("not decoded type.\n"); + exit(1); } continue; } switch (long_options[option_index].name[0]) { - case 'T': - tdd_config=atoi(optarg); - frame_type=TDD; - break; + case 'T': + tdd_config=atoi(optarg); + frame_type=TDD; + break; - case 'a': - channel_model = AWGN; - chMod = 1; - break; + case 'a': + channel_model = AWGN; + chMod = 1; + break; - case 'g': - strncpy(channel_model_input,optarg,9); - struct tmp { - char opt; - int m; - int M; - } - tmp[]= { - {'A',SCM_A,2}, - {'B',SCM_B,3}, - {'C',SCM_C,4}, - {'D',SCM_D,5}, - {'E',EPA,6}, - {'G',ETU,8}, - {'H',Rayleigh8,9}, - {'I',Rayleigh1,10}, - {'J',Rayleigh1_corr,11}, - {'K',Rayleigh1_anticorr,12}, - {'L',Rice8,13}, - {'M',Rice1,14}, - {'N',AWGN,1}, - {0,0,0} - }; - struct tmp *ptr; - - for (ptr=tmp; ptr->opt!=0; ptr++) - if ( ptr->opt == optarg[0] ) { - channel_model=ptr->m; - chMod=ptr->M; - break; - } - - AssertFatal(ptr->opt != 0, "Unsupported channel model: %s !\n", optarg ); - break; + case 'g': + strncpy(channel_model_input,optarg,9); + struct tmp { + char opt; + int m; + int M; + } + tmp[]= { + {'A',SCM_A,2}, + {'B',SCM_B,3}, + {'C',SCM_C,4}, + {'D',SCM_D,5}, + {'E',EPA,6}, + {'G',ETU,8}, + {'H',Rayleigh8,9}, + {'I',Rayleigh1,10}, + {'J',Rayleigh1_corr,11}, + {'K',Rayleigh1_anticorr,12}, + {'L',Rice8,13}, + {'M',Rice1,14}, + {'N',AWGN,1}, + {0,0,0} + }; + struct tmp *ptr; + + for (ptr=tmp; ptr->opt!=0; ptr++) + if ( ptr->opt == optarg[0] ) { + channel_model=ptr->m; + chMod=ptr->M; + break; + } - case 'x': - transmission_m=atoi(optarg); - AssertFatal(transmission_m==1 || transmission_m==2, - "Unsupported transmission mode %d\n",transmission_m); - break; + AssertFatal(ptr->opt != 0, "Unsupported channel model: %s !\n", optarg ); + break; - case 'r': - nb_rb = atoi(optarg); - nb_rb_set = 1; - break; + case 'x': + transmission_m=atoi(optarg); + AssertFatal(transmission_m==1 || transmission_m==2, + "Unsupported transmission mode %d\n",transmission_m); + break; + + case 'r': + nb_rb = atoi(optarg); + nb_rb_set = 1; + break; //case 'c': // cyclic_shift = atoi(optarg); // break; - case 'i': - input_fdUL = fopen(optarg,"r"); - printf("Reading in %s (%p)\n",optarg,input_fdUL); - AssertFatal(input_fdUL != (FILE *)NULL,"Unknown file %s\n",optarg); - break; + case 'i': + input_fdUL = fopen(optarg,"r"); + printf("Reading in %s (%p)\n",optarg,input_fdUL); + AssertFatal(input_fdUL != (FILE *)NULL,"Unknown file %s\n",optarg); + break; - case 'A': - beta_ACK = atoi(optarg); - AssertFatal(beta_ACK>15,"beta_ack must be in (0..15)\n"); - break; + case 'A': + beta_ACK = atoi(optarg); + AssertFatal(beta_ACK>15,"beta_ack must be in (0..15)\n"); + break; - case 'C': - beta_CQI = atoi(optarg); - AssertFatal((beta_CQI>15)||(beta_CQI<2),"beta_cqi must be in (2..15)\n"); - break; + case 'C': + beta_CQI = atoi(optarg); + AssertFatal((beta_CQI>15)||(beta_CQI<2),"beta_cqi must be in (2..15)\n"); + break; - case 'R': - beta_RI = atoi(optarg); - AssertFatal((beta_RI>15)||(beta_RI<2),"beta_ri must be in (0..13)\n"); - break; + case 'R': + beta_RI = atoi(optarg); + AssertFatal((beta_RI>15)||(beta_RI<2),"beta_ri must be in (0..13)\n"); + break; - case 'P': - dump_perf=1; - opp_enabled=1; - break; + case 'P': + dump_perf=1; + opp_enabled=1; + break; - case 'L': - set_parallel_conf(optarg); - break; - - default: - printf("Wrong option: %s\n",long_options[option_index].name); - exit(1); - break; + case 'L': + set_parallel_conf(optarg); + break; + + default: + printf("Wrong option: %s\n",long_options[option_index].name); + exit(1); + break; } } @@ -594,14 +578,15 @@ int main(int argc, char **argv) { exit(1); } - if (help || verbose ) - display_options_values(options, true); + display_options_values(options, true); + if (help) exit(0); - + if (thread_struct.parallel_conf != PARALLEL_SINGLE_THREAD) set_worker_conf("WORKER_ENABLE"); + RC.nb_L1_inst = 1; RC.nb_RU = 1; lte_param_init(&eNB,&UE,&ru, @@ -619,7 +604,7 @@ int main(int argc, char **argv) { threequarter_fs, osf, 0); - RC.eNB = (PHY_VARS_eNB ***)malloc(sizeof(PHY_VARS_eNB **)); + RC.eNB = (PHY_VARS_eNB ** *)malloc(sizeof(PHY_VARS_eNB **)); RC.eNB[0] = (PHY_VARS_eNB **)malloc(sizeof(PHY_VARS_eNB *)); RC.ru = (RU_t **)malloc(sizeof(RC.ru)); RC.eNB[0][0] = eNB; @@ -637,7 +622,7 @@ int main(int argc, char **argv) { eNB->UL_INFO.cqi_ind.cqi_raw_pdu_list = eNB->cqi_raw_pdu_list; printf("lte_param_init done\n"); // for a call to phy_reset_ue later we need PHY_vars_UE_g allocated and pointing to UE - PHY_vars_UE_g = (PHY_VARS_UE ***)malloc(sizeof(PHY_VARS_UE **)); + PHY_vars_UE_g = (PHY_VARS_UE ** *)malloc(sizeof(PHY_VARS_UE **)); PHY_vars_UE_g[0] = (PHY_VARS_UE **) malloc(sizeof(PHY_VARS_UE *)); PHY_vars_UE_g[0][0] = UE; @@ -822,7 +807,7 @@ int main(int argc, char **argv) { if (cqi_flag == 1) coded_bits_per_codeword-=UE->ulsch[0]->O; rate = (double)dlsch_tbs25[get_I_TBS(mcs)][nb_rb-1]/(coded_bits_per_codeword); - printf("Rate = %f (mod %d), coded bits %d\n",rate,get_Qm_ul(mcs),coded_bits_per_codeword); + printf("Rate = %f (mod %d), coded bits %u\n",rate,get_Qm_ul(mcs),coded_bits_per_codeword); for (ch_realization=0; ch_realization<n_ch_rlz; ch_realization++) { /* @@ -884,7 +869,7 @@ int main(int argc, char **argv) { i=0; while (!feof(input_fdUL)) { - ret=fscanf(input_fdUL,"%s %s",input_val_str,input_val_str2);//&input_val1,&input_val2); + ret=fscanf(input_fdUL,"%49s %49s",input_val_str,input_val_str2);//&input_val1,&input_val2); if (ret != 2) printf("ERROR: error reading file\n"); @@ -971,7 +956,7 @@ int main(int argc, char **argv) { eNB->ulsch[0]->harq_processes[harq_pid]->round=round; UE->ulsch[0]->harq_processes[harq_pid]->round=round; - if (n_frames==1) printf("filling ulsch: Trial %d : Round %d (subframe %d, frame %d)\n",trials,round,proc_rxtx_ue->subframe_tx,proc_rxtx_ue->frame_tx); + if (n_frames==1) printf("filling ulsch: Trial %u : Round %d (subframe %d, frame %d)\n",trials,round,proc_rxtx_ue->subframe_tx,proc_rxtx_ue->frame_tx); round_trials[round]++; UL_req.sfn_sf = (1<<4)+subframe; @@ -1062,10 +1047,10 @@ int main(int argc, char **argv) { sigma2_dB = N0;//-10*log10(UE->frame_parms.ofdm_symbol_size/(UE->frame_parms.N_RB_DL*12));//10*log10((double)tx_lev) +10*log10(UE->frame_parms.ofdm_symbol_size/(UE->frame_parms.N_RB_DL*12)) - SNR; sigma2 = pow(10,sigma2_dB/10); // compute tx_gain to achieve target SNR (per resource element!) - tx_gain = sqrt(pow(10.0,.1*(N0+SNR))/(double)tx_lev);//*(nb_rb*12/(double)UE->frame_parms.ofdm_symbol_size)/(double)tx_lev); + tx_gain = sqrt(pow(10.0,.1*(N0+SNR))/(double)tx_lev);// *(nb_rb*12/(double)UE->frame_parms.ofdm_symbol_size)/(double)tx_lev); if (n_frames==1) - printf("tx_lev = %d (%d.%d dB,%f), gain %f\n",tx_lev,tx_lev_dB/10,tx_lev_dB,10*log10((double)tx_lev),10*log10(tx_gain)); + printf("tx_lev = %u (%u.%u dB,%f), gain %f\n",tx_lev,tx_lev_dB/10,tx_lev_dB,10*log10((double)tx_lev),10*log10(tx_gain)); // fill measurement symbol (19) with noise for (i=0; i<OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES; i++) { @@ -1100,7 +1085,7 @@ int main(int argc, char **argv) { // calculate freq domain representation to compute SINR freq_channel(UE2eNB, N_RB_DL,12*N_RB_DL + 1); // snr=pow(10.0,.1*SNR); - fprintf(csv_fdUL,"%f,%d,%d,%f,%f,%f,",SNR,tx_lev,tx_lev_dB,sigma2_dB,tx_gain,SNR2); + fprintf(csv_fdUL,"%f,%u,%u,%f,%f,%f,",SNR,tx_lev,tx_lev_dB,sigma2_dB,tx_gain,SNR2); //fprintf(csv_fdUL,"%f,",SNR); for (u=0; u<12*nb_rb; u++) { @@ -1156,12 +1141,12 @@ int main(int argc, char **argv) { if (eNB->frame_parms.nb_antennas_rx>1) LOG_M("rxsig1UL.m","rxs1", &ru->common.rxdata[1][eNB->frame_parms.samples_per_tti*subframe],eNB->frame_parms.samples_per_tti,1,1); } - start_meas(&eNB->phy_proc_rx); + start_meas(&eNB->phy_proc_rx); ru->feprx = (get_thread_worker_conf() == WORKER_ENABLE) ? ru_fep_full_2thread : fep_full; ru->feprx(ru); phy_procedures_eNB_uespec_RX(eNB,proc_rxtx); - stop_meas(&eNB->phy_proc_rx); - + stop_meas(&eNB->phy_proc_rx); + if (cqi_flag > 0) { cqi_error = 0; @@ -1227,10 +1212,11 @@ int main(int argc, char **argv) { dump_ulsch(eNB,eNB->proc.frame_rx,subframe,0,round); - if (round == 4) exit(-1); + round=5; + } - if (n_frames==1) printf("round %d errors %d/%d\n",round,errs[round],trials); + if (n_frames==1) printf("round %d errors %u/%u\n",round,errs[round],trials); round++; @@ -1288,7 +1274,7 @@ int main(int argc, char **argv) { LOG_UDUMPMSG(SIM,dataArray(table_rx),table_rx->size,LOG_DUMP_DOUBLE,"The receiver raw data: \n"); } - printf("\n**********rb: %d ***mcs : %d *********SNR = %f dB (%f): TX %d dB (gain %f dB), N0W %f dB, I0 %d dB, delta_IF %d [ (%d,%d) dB / (%d,%d) dB ]**************************\n", + printf("\n**********rb: %d ***mcs : %d *********SNR = %f dB (%f): TX %u dB (gain %f dB), N0W %f dB, I0 %d dB, delta_IF %d [ (%d,%d) dB / (%d,%d) dB ]**************************\n", nb_rb,mcs,SNR,SNR2, tx_lev_dB, 20*log10(tx_gain), @@ -1300,7 +1286,7 @@ int main(int argc, char **argv) { eNB->measurements.n0_power_dB[0], eNB->measurements.n0_power_dB[1]); effective_rate = ((double)(round_trials[0])/((double)round_trials[0] + round_trials[1] + round_trials[2] + round_trials[3])); - printf("Errors (%d/%d %d/%d %d/%d %d/%d), Pe = (%e,%e,%e,%e) => effective rate %f (%3.1f%%,%f,%f), normalized delay %f (%f)\n", + printf("Errors (%u/%u %u/%u %u/%u %u/%u), Pe = (%e,%e,%e,%e) => effective rate %f (%3.1f%%,%f,%f), normalized delay %f (%f)\n", errs[0], round_trials[0], errs[1], @@ -1322,16 +1308,16 @@ int main(int argc, char **argv) { (1.0*(round_trials[0]-errs[0])+2.0*(round_trials[1]-errs[1])+3.0*(round_trials[2]-errs[2])+4.0*(round_trials[3]-errs[3]))/((double)round_trials[0])); if (cqi_flag >0) { - printf("CQI errors %d/%d,false positives %d/%d, CQI false negatives %d/%d\n", + printf("CQI errors %d/%u,false positives %d/%u, CQI false negatives %d/%u\n", cqi_errors,round_trials[0]+round_trials[1]+round_trials[2]+round_trials[3], cqi_crc_falsepositives,round_trials[0]+round_trials[1]+round_trials[2]+round_trials[3], cqi_crc_falsenegatives,round_trials[0]+round_trials[1]+round_trials[2]+round_trials[3]); } if (eNB->ulsch[0]->harq_processes[harq_pid]->o_ACK[0] > 0) - printf("ACK/NAK errors %d/%d\n",ack_errors,round_trials[0]+round_trials[1]+round_trials[2]+round_trials[3]); + printf("ACK/NAK errors %d/%u\n",ack_errors,round_trials[0]+round_trials[1]+round_trials[2]+round_trials[3]); - fprintf(bler_fd,"%f;%d;%d;%d;%f;%d;%d;%d;%d;%d;%d;%d;%d\n", + fprintf(bler_fd,"%f;%d;%d;%d;%f;%u;%u;%u;%u;%u;%u;%u;%u\n", SNR, mcs, nb_rb, @@ -1358,15 +1344,15 @@ int main(int argc, char **argv) { printStatIndent(&UE->ulsch_rate_matching_stats,"ULSCH rate-matching time"); printStatIndent(&UE->ulsch_interleaving_stats,"ULSCH sub-block interleaving"); printStatIndent(&UE->ulsch_multiplexing_stats,"ULSCH multiplexing time"); - printf("\n"); + printf("\n"); printDistribution(&eNB->phy_proc_rx,table_rx,"Total PHY proc rx subframe"); printDistribution(&ru->ofdm_demod_stats,table_rx_fft,"|__ OFDM_demod time"); printDistribution(&eNB->ulsch_demodulation_stats,table_rx_demod,"|__ ULSCH demodulation time"); - printDistribution(&eNB->ulsch_decoding_stats,table_rx_dec,"|__ ULSCH Decoding time"); + printDistribution(&eNB->ulsch_decoding_stats,table_rx_dec,"|__ ULSCH Decoding time"); printf(" (%.2f Mbit/s, avg iter %.2f, max %.2f)\n", UE->ulsch[0]->harq_processes[harq_pid]->TBS/1000.0, - (double)iter_trials, - (double)eNB->ulsch_decoding_stats.max*timeBase); + (double)iter_trials, + (double)eNB->ulsch_decoding_stats.max*timeBase); printStatIndent2(&eNB->ulsch_deinterleaving_stats,"sub-block interleaving" ); printStatIndent2(&eNB->ulsch_demultiplexing_stats,"sub-block demultiplexing" ); printStatIndent2(&eNB->ulsch_rate_unmatching_stats,"sub-block rate-matching" ); @@ -1404,7 +1390,7 @@ int main(int argc, char **argv) { if ( (test_perf != 0) && (100 * effective_rate > test_perf )) { //fprintf(time_meas_fd,"SNR; MCS; TBS; rate; err0; trials0; err1; trials1; err2; trials2; err3; trials3\n"); - fprintf(time_meas_fd,"%f;%d;%d;%f;%d;%d;%d;%d;%d;%d;%d;%d;", + fprintf(time_meas_fd,"%f;%d;%d;%f;%u;%u;%u;%u;%u;%u;%u;%u;", SNR, mcs, eNB->ulsch[0]->harq_processes[harq_pid]->TBS, @@ -1418,7 +1404,7 @@ int main(int argc, char **argv) { errs[3], round_trials[3]); //fprintf(time_meas_fd,"SNR; MCS; TBS; rate; err0; trials0; err1; trials1; err2; trials2; err3; trials3;ND;\n"); - fprintf(time_meas_fd,"%f;%d;%d;%f;%2.1f;%f;%d;%d;%d;%d;%d;%d;%d;%d;%e;%e;%e;%e;%f;%f;", + fprintf(time_meas_fd,"%f;%d;%d;%f;%2.1f;%f;%u;%u;%u;%u;%u;%u;%u;%u;%e;%e;%e;%e;%f;%f;", SNR, mcs, eNB->ulsch[0]->harq_processes[harq_pid]->TBS, @@ -1463,34 +1449,34 @@ int main(int argc, char **argv) { ); //fprintf(time_meas_fd,"UE_PROC_TX_STD;UE_PROC_TX_MAX;UE_PROC_TX_MIN;UE_PROC_TX_MED;UE_PROC_TX_Q1;UE_PROC_TX_Q3;UE_PROC_TX_DROPPED;\n"); fprintf(time_meas_fd,"%f;%f;%f;%f;%f;%f;%d;", - squareRoot(&UE->phy_proc_tx), t_tx_max, t_tx_min, median(table_tx), q1(table_tx), q3(table_tx), n_tx_dropped); + squareRoot(&UE->phy_proc_tx), t_tx_max, t_tx_min, median(table_tx), q1(table_tx), q3(table_tx), n_tx_dropped); //fprintf(time_meas_fd,"IFFT;\n"); fprintf(time_meas_fd,"%f;%f;%f;%f;", - squareRoot(&UE->ofdm_mod_stats), + squareRoot(&UE->ofdm_mod_stats), median(table_tx_ifft),q1(table_tx_ifft),q3(table_tx_ifft)); //fprintf(time_meas_fd,"MOD;\n"); fprintf(time_meas_fd,"%f;%f;%f;%f;", - squareRoot(&UE->ulsch_modulation_stats), + squareRoot(&UE->ulsch_modulation_stats), median(table_tx_mod), q1(table_tx_mod), q3(table_tx_mod)); //fprintf(time_meas_fd,"ENC;\n"); fprintf(time_meas_fd,"%f;%f;%f;%f;", - squareRoot(&UE->ulsch_encoding_stats), + squareRoot(&UE->ulsch_encoding_stats), median(table_tx_enc),q1(table_tx_enc),q3(table_tx_enc)); //fprintf(time_meas_fd,"eNB_PROC_RX_STD;eNB_PROC_RX_MAX;eNB_PROC_RX_MIN;eNB_PROC_RX_MED;eNB_PROC_RX_Q1;eNB_PROC_RX_Q3;eNB_PROC_RX_DROPPED;\n"); fprintf(time_meas_fd,"%f;%f;%f;%f;%f;%f;%d;", - squareRoot(&eNB->phy_proc_rx), t_rx_max, t_rx_min, + squareRoot(&eNB->phy_proc_rx), t_rx_max, t_rx_min, median(table_rx), q1(table_rx), q3(table_rx), n_rx_dropped); //fprintf(time_meas_fd,"FFT;\n"); fprintf(time_meas_fd,"%f;%f;%f;%f;", - squareRoot(&ru->ofdm_demod_stats), + squareRoot(&ru->ofdm_demod_stats), median(table_rx_fft), q1(table_rx_fft), q3(table_rx_fft)); //fprintf(time_meas_fd,"DEMOD;\n"); fprintf(time_meas_fd,"%f;%f;%f;%f;", - squareRoot(&eNB->ulsch_demodulation_stats), + squareRoot(&eNB->ulsch_demodulation_stats), median(table_rx_demod), q1(table_rx_demod), q3(table_rx_demod)); //fprintf(time_meas_fd,"DEC;\n"); fprintf(time_meas_fd,"%f;%f;%f;%f\n", - squareRoot(&eNB->ulsch_decoding_stats), + squareRoot(&eNB->ulsch_decoding_stats), median(table_rx_dec), q1(table_rx_dec), q3(table_rx_dec)); printf("[passed] effective rate : %f (%2.1f%%,%f)): log and break \n",rate*effective_rate, 100*effective_rate, rate ); break; diff --git a/openair1/SIMULATION/TOOLS/abstraction.c b/openair1/SIMULATION/TOOLS/abstraction.c index 6b846bb2d5db9e584d54cfd027792506d6363ae8..7ac19804176115087bb1db54b803543bd20a7bf9 100644 --- a/openair1/SIMULATION/TOOLS/abstraction.c +++ b/openair1/SIMULATION/TOOLS/abstraction.c @@ -32,17 +32,14 @@ // NEW code with lookup table for sin/cos based on delay profile (TO BE TESTED) -double **cos_lut=NULL,**sin_lut=NULL; +double **cos_lut=NULL,* *sin_lut=NULL; //#if 1 -int init_freq_channel(channel_desc_t *desc,uint16_t nb_rb,int16_t n_samples) -{ - - +int init_freq_channel(channel_desc_t *desc,uint16_t nb_rb,int16_t n_samples) { double delta_f,freq; // 90 kHz spacing double delay; int16_t f; @@ -50,21 +47,18 @@ int init_freq_channel(channel_desc_t *desc,uint16_t nb_rb,int16_t n_samples) if ((n_samples&1)==0) { fprintf(stderr, "freq_channel_init: n_samples has to be odd\n"); - return(-1); + return(-1); } - cos_lut = (double **)malloc(n_samples*sizeof(double*)); - sin_lut = (double **)malloc(n_samples*sizeof(double*)); - + cos_lut = (double **)malloc(n_samples*sizeof(double *)); + sin_lut = (double **)malloc(n_samples*sizeof(double *)); delta_f = nb_rb*180000/(n_samples-1); for (f=-(n_samples>>1); f<=(n_samples>>1); f++) { freq=delta_f*(double)f*1e-6;// due to the fact that delays is in mus - cos_lut[f+(n_samples>>1)] = (double *)malloc((int)desc->nb_taps*sizeof(double)); sin_lut[f+(n_samples>>1)] = (double *)malloc((int)desc->nb_taps*sizeof(double)); - for (l=0; l<(int)desc->nb_taps; l++) { if (desc->nb_taps==1) delay = desc->delays[l]; @@ -74,17 +68,13 @@ int init_freq_channel(channel_desc_t *desc,uint16_t nb_rb,int16_t n_samples) cos_lut[f+(n_samples>>1)][l] = cos(2*M_PI*freq*delay); sin_lut[f+(n_samples>>1)][l] = sin(2*M_PI*freq*delay); //printf("values cos:%d, sin:%d\n", cos_lut[f][l], sin_lut[f][l]); - } } return(0); } -int freq_channel(channel_desc_t *desc,uint16_t nb_rb,int16_t n_samples) -{ - - +int freq_channel(channel_desc_t *desc,uint16_t nb_rb,int16_t n_samples) { int16_t f,f2,d; uint8_t aarx,aatx,l; double *clut,*slut; @@ -95,7 +85,7 @@ int freq_channel(channel_desc_t *desc,uint16_t nb_rb,int16_t n_samples) // n_samples has to be a odd number because we assume the spectrum is symmetric around the DC and includes the DC if ((n_samples&1)==0) { fprintf(stderr, "freq_channel: n_samples has to be odd\n"); - return(-1); + return(-1); } // printf("no of taps:%d,",(int)desc->nb_taps); @@ -104,6 +94,7 @@ int freq_channel(channel_desc_t *desc,uint16_t nb_rb,int16_t n_samples) // we are initializing the lut for the largets possible n_samples=12*nb_rb+1 // if called with n_samples<12*nb_rb+1, we decimate the lut n_samples_max=12*nb_rb+1; + if (init_freq_channel(desc,nb_rb,n_samples_max)==0) freq_channel_init=1; else @@ -111,9 +102,7 @@ int freq_channel(channel_desc_t *desc,uint16_t nb_rb,int16_t n_samples) } d=(n_samples_max-1)/(n_samples-1); - //printf("no_samples=%d, n_samples_max=%d, d=%d\n",n_samples,n_samples_max,d); - start_meas(&desc->interp_freq); for (f=-n_samples_max/2,f2=-n_samples/2; f<n_samples_max/2; f+=d,f2++) { @@ -126,7 +115,6 @@ int freq_channel(channel_desc_t *desc,uint16_t nb_rb,int16_t n_samples) desc->chF[aarx+(aatx*desc->nb_rx)][n_samples/2+f2].y=0.0; for (l=0; l<(int)desc->nb_taps; l++) { - desc->chF[aarx+(aatx*desc->nb_rx)][n_samples/2+f2].x+=(desc->a[l][aarx+(aatx*desc->nb_rx)].x*clut[l]+ desc->a[l][aarx+(aatx*desc->nb_rx)].y*slut[l]); desc->chF[aarx+(aatx*desc->nb_rx)][n_samples/2+f2].y+=(-desc->a[l][aarx+(aatx*desc->nb_rx)].x*slut[l]+ @@ -137,7 +125,6 @@ int freq_channel(channel_desc_t *desc,uint16_t nb_rb,int16_t n_samples) } stop_meas(&desc->interp_freq); - return(0); } @@ -146,16 +133,13 @@ double compute_pbch_sinr(channel_desc_t *desc, channel_desc_t *desc_i2, double snr_dB,double snr_i1_dB, double snr_i2_dB, - uint16_t nb_rb) -{ - + uint16_t nb_rb) { double avg_sinr,snr=pow(10.0,.1*snr_dB),snr_i1=pow(10.0,.1*snr_i1_dB),snr_i2=pow(10.0,.1*snr_i2_dB); uint16_t f; uint8_t aarx,aatx; double S; struct complex S_i1; struct complex S_i2; - avg_sinr=0.0; // printf("nb_rb %d\n",nb_rb); @@ -202,18 +186,14 @@ double compute_sinr(channel_desc_t *desc, channel_desc_t *desc_i2, double snr_dB,double snr_i1_dB, double snr_i2_dB, - uint16_t nb_rb) -{ - + uint16_t nb_rb) { double avg_sinr,snr=pow(10.0,.1*snr_dB),snr_i1=pow(10.0,.1*snr_i1_dB),snr_i2=pow(10.0,.1*snr_i2_dB); uint16_t f; uint8_t aarx,aatx; double S; struct complex S_i1; struct complex S_i2; - DevAssert( nb_rb > 0 ); - avg_sinr=0.0; // printf("nb_rb %d\n",nb_rb); @@ -256,12 +236,9 @@ double compute_sinr(channel_desc_t *desc, int pbch_polynomial_degree=6; double pbch_awgn_polynomial[7]= {-7.2926e-05, -2.8749e-03, -4.5064e-02, -3.5301e-01, -1.4655e+00, -3.6282e+00, -6.6907e+00}; -void load_pbch_desc(FILE *pbch_file_fd) -{ - +void load_pbch_desc(FILE *pbch_file_fd) { int i, ret; char dummy[25]; - ret = fscanf(pbch_file_fd,"%d",&pbch_polynomial_degree); if (ret < 0) { @@ -277,7 +254,7 @@ void load_pbch_desc(FILE *pbch_file_fd) printf("PBCH polynomial : "); for (i=0; i<=pbch_polynomial_degree; i++) { - ret = fscanf(pbch_file_fd,"%s",dummy); + ret = fscanf(pbch_file_fd,"%24s",dummy); if (ret < 0) { printf("fscanf failed: %s\n", strerror(errno)); @@ -291,9 +268,7 @@ void load_pbch_desc(FILE *pbch_file_fd) printf("\n"); } -double pbch_bler(double sinr) -{ - +double pbch_bler(double sinr) { int i; double log10_bler=pbch_awgn_polynomial[pbch_polynomial_degree]; double sinrpow=sinr; @@ -317,6 +292,5 @@ double pbch_bler(double sinr) //printf ("sinr %f bler %f\n",sinr,bler); return(bler); - } diff --git a/openair1/SIMULATION/TOOLS/ch_desc_proto.c b/openair1/SIMULATION/TOOLS/ch_desc_proto.c index 8b07a596a925774c1c6cdc4a9296bcec2e8673be..b1e71fcfb4a0c99bd2066e9d58dedf342860de9d 100644 --- a/openair1/SIMULATION/TOOLS/ch_desc_proto.c +++ b/openair1/SIMULATION/TOOLS/ch_desc_proto.c @@ -31,17 +31,14 @@ enum sector {SEC1, SEC2, SEC3}; scenario_desc_t scenario; -void get_chan_desc(node_desc_t* node_tx, node_desc_t* node_rx, channel_desc_t *ch_desc, scenario_desc_t* scenario) -{ +void get_chan_desc(node_desc_t *node_tx, node_desc_t *node_rx, channel_desc_t *ch_desc, scenario_desc_t *scenario) { double dist; dist = sqrt(pow((node_tx->x - node_rx->x), 2) + pow((node_tx->y - node_rx->y), 2)); - /* conversion of distance into KM 3gpp (36-942)*/ ch_desc->path_loss_dB = (128.1 + 37.6 * log10(dist/1000)); } -int main() -{ +int main() { int enb_count = 16; int ue_count = 50; double sect_angle[3]= {0,2*PI/3,4*PI/3}; @@ -75,19 +72,16 @@ int main() "bler_9.csv", "bler_10.csv", "bler_11.csv", "bler_12.csv", "bler_13.csv", "bler_14.csv", "bler_15.csv", "bler_16.csv", "bler_17.csv", "bler_18.csv", "bler_19.csv", "bler_20.csv", "bler_21.csv", "bler_22.csv" }; - double beta[MCS_COUNT] = {0, 0, 0, 0, 0.9459960937499999, 1.2912109374999994, 1.0133789062499998, 1.000390625, 1.02392578125, 1.8595703124999998, 2.424389648437498, 2.3946533203124982, 2.5790039062499988, 2.4084960937499984, 2.782617187499999, 2.7868652343749996, 3.92099609375, 4.0392578125, 4.56109619140625, 5.03338623046875, 5.810888671875, 6.449108886718749 }; - double enb_position[][2] = {{1100,1100},{1100,2100},{1100,3100},{1100,4100}, {2100,1100},{2100,2100},{2100,3100},{2100,4100}, {3100,1100},{3100,2100},{3100,3100},{3100,4100}, {4100,1100},{4100,2100},{4100,3100},{4100,4100} }; - double ue_position[][2] = {{3340,4740},{1500,620},{1780,4220},{1300,3540},{780,3100}, {1140,540},{1340,3660},{860,1220},{2700,2140},{3860,3060}, {3740,1060},{1700,3060},{2180,1620},{4420,1060},{1300,3340}, @@ -99,15 +93,12 @@ int main() {3420,2820},{1580,3940},{660,2100},{2740,1180},{2500,2500}, {3580,3580},{3740,3140},{3020,3020},{4340,4140},{980,4300} }; - randominit(0); - ///////////////////////////////////////////////////////////////////////////////////////////////// int tabl_len=0; double local_table[MCS_COUNT][9][9]; for (mcs = 5; mcs <= MCS_COUNT; mcs++) { - fp = fopen(file_name[mcs - 1],"r"); if (fp == NULL) { @@ -117,7 +108,6 @@ int main() tabl_len=0; while (!feof(fp)) { - sinr_bler = strtok(buffer, ";"); local_table[mcs-1][0][tabl_len] = atof(sinr_bler); sinr_bler = strtok(NULL,";"); @@ -133,12 +123,8 @@ int main() for (tabl_len=0; tabl_len<9; tabl_len++) printf("%lf %lf \n ",local_table[mcs-1][0][tabl_len],local_table[mcs-1][1][tabl_len]); - - } - - //////////////////////////////////////////////////////////////////////////////////////////////////// for (enb_index = 0; enb_index < enb_count; enb_index++) @@ -172,7 +158,6 @@ int main() ul_channel[ue_index][enb_index] = new_channel_desc_scm(1, 1, SCM_C, 7.68, 0, 0, 0); dl_channel[ue_index][enb_index] = new_channel_desc_scm(1, 1, SCM_C, 7.68, 0, 0, 0); //printf("ue %d enb %d\n", ue_index, enb_index); - /* Calculating the angle in the range -pi to pi from the slope */ //(ue_data[ue_index])->alpha_rad[enb_index] = (double)(atan2((ue_data[ue_index]->x - enb_data[enb_index]->x), (ue_data[ue_index]->y - enb_data[enb_index]->y))); ue_data[ue_index]->alpha_rad[enb_index] = atan2((ue_data[ue_index]->x - enb_data[enb_index]->x), (ue_data[ue_index]->y - enb_data[enb_index]->y)); @@ -190,8 +175,7 @@ int main() /* gain = -min(Am , 12 * (theta/theta_3dB)^2) */ gain_max = (gain_sec[SEC1] > gain_sec[SEC2]) ? ((gain_sec[SEC1] > gain_sec[SEC3]) ? gain_sec[SEC1]:gain_sec[SEC3]) : - ((gain_sec[SEC2] > gain_sec[SEC3]) ? gain_sec[SEC2]:gain_sec[SEC3]); - + ((gain_sec[SEC2] > gain_sec[SEC3]) ? gain_sec[SEC2]:gain_sec[SEC3]); get_chan_desc(enb_data[enb_index], ue_data[ue_index], ul_channel[ue_index][enb_index], &scenario); get_chan_desc(enb_data[enb_index], ue_data[ue_index], dl_channel[ue_index][enb_index], &scenario); @@ -204,7 +188,6 @@ int main() //return_value = random_channel(ul_channel[ue_index][enb_index]); return_value = random_channel(dl_channel[ue_index][enb_index]); - /* Thermal noise is calculated using 10log10(K*T*B) K = Boltzmann´s constant T = room temperature B = bandwidth */ /* Taken as constant for the time being since the BW is not changing */ thermal_noise = -105; //value in dBm @@ -222,7 +205,6 @@ int main() - (thermal_noise + ue_data[ue_index]->rx_noise_level) + 10 * log10 (pow(dl_channel[ue_index][enb_index]->chF[0][count].r, 2) + pow(dl_channel[ue_index][enb_index]->chF[0][count].i, 2)); - //printf("Dl_link SNR for res. block %d is %lf\n", count, sinr[enb_index][count]); } } @@ -252,7 +234,6 @@ int main() //printf("mcs value %d \n",mcs); //printf("beta value %lf \n",-beta[mcs-1]); //printf("snr_eff value %lf \n",log(sinr_eff[ue_index][mcs-1])); - sinr_eff[ue_index][mcs-1] = -beta[mcs-1] *log((sinr_eff[ue_index][mcs-1])/(2*nb_rb));// //printf("snr_eff value %lf \n",sinr_eff[ue_index][mcs-1]); sinr_eff[ue_index][mcs-1] = 10 * log10(sinr_eff[ue_index][mcs-1]); @@ -264,9 +245,7 @@ int main() } sinr_eff[ue_index][mcs-1] /= 10; - //printf("Effective snr %lf \n",sinr_eff[ue_index][mcs-1]); - bler[ue_index][mcs-1] = 0; /*line_num = 0; @@ -295,37 +274,31 @@ int main() } fclose(fp);*/ for (tabl_len=0; tabl_len<9; tabl_len++) { - if(tabl_len==0) if (sinr_eff[ue_index][mcs-1] < local_table[mcs-1][0][tabl_len]) { bler[ue_index][mcs-1] = 1; break; } - if (sinr_eff[ue_index][mcs-1] == local_table[mcs-1][0][tabl_len]) { bler[ue_index][mcs-1] = local_table[mcs-1][1][tabl_len]; } - } //printf("\n###Dl_link UE %d attached to eNB %d \n MCS %d effective SNR %lf BLER %lf", ue_index, att_enb_index, mcs,sinr_eff[ue_index][mcs-1],bler[ue_index][mcs-1]); } //printf("\n\n"); - printf("\n Ue_ix enb_ix mcs5 mcs6 mcs7 mcs8 mcs9 mcs10 mcs11 mcs12 mcs13\ mcs14 mcs15 mcs16 mcs17 mcs18 mcs19 mcs20 mcs21 mcs22\n"); - printf("SINR %4d %4d %+4.2f %+4.2f %+4.2f %+4.2f %+4.2f %+4.2f %+4.2f %+4.2f\ - %+4.2f %+4.2f %+4.2f %+4.2f %+4.2f %+4.2f %+4.2f %+4.2f %+4.2f %+4.2f\n", + %+4.2f %+4.2f %+4.2f %+4.2f %+4.2f %+4.2f %+4.2f %+4.2f %+4.2f %+4.2f %+4.2f\n", ue_index, att_enb_index, sinr_eff[ue_index][4], sinr_eff[ue_index][5], sinr_eff[ue_index][6], sinr_eff[ue_index][7], sinr_eff[ue_index][8], sinr_eff[ue_index][9], sinr_eff[ue_index][10], sinr_eff[ue_index][11], sinr_eff[ue_index][12], sinr_eff[ue_index][13], sinr_eff[ue_index][14], sinr_eff[ue_index][15], sinr_eff[ue_index][16], sinr_eff[ue_index][17], sinr_eff[ue_index][18], sinr_eff[ue_index][19], sinr_eff[ue_index][20], sinr_eff[ue_index][21], sinr_eff[ue_index][22]); - printf("BLER %4d %4d %+4.2f %+4.2f %+4.2f %+4.2f %+4.2f %+4.2f %+4.2f %+4.2f\ - %+4.2f %+4.2f %+4.2f %+4.2f %+4.2f %+4.2f %+4.2f %+4.2f %+4.2f %+4.2f\n", + %+4.2f %+4.2f %+4.2f %+4.2f %+4.2f %+4.2f %+4.2f %+4.2f %+4.2f %+4.2f %+4.2f\n", ue_index, att_enb_index, bler[ue_index][4], bler[ue_index][5], bler[ue_index][6], bler[ue_index][7], bler[ue_index][8], bler[ue_index][9], bler[ue_index][10], bler[ue_index][11], bler[ue_index][12], bler[ue_index][13], bler[ue_index][14], bler[ue_index][15], bler[ue_index][16], bler[ue_index][17], diff --git a/openair1/SIMULATION/TOOLS/gauss.c b/openair1/SIMULATION/TOOLS/gauss.c index f69748270b0cc8a4baf23e54ae8fc0259159913e..cc4b1fb793e1115bc2c8de5bc7abb5b603f7369d 100644 --- a/openair1/SIMULATION/TOOLS/gauss.c +++ b/openair1/SIMULATION/TOOLS/gauss.c @@ -27,20 +27,15 @@ unsigned int *generate_gauss_LUT(unsigned char Nbits, unsigned char L - ) -{ - + ) { unsigned int *LUT_ptr,i; - LUT_ptr = (unsigned int *)malloc((1<<(Nbits-1))*sizeof(int)); assert(LUT_ptr); - for (i=0; i<(1<<(Nbits-1)); i++) { LUT_ptr[i] = (unsigned int)((double)((unsigned int)(1<<31))*erf(i*L/(double)(1<<(Nbits-1)))); - #ifdef LUTDEBUG - printf("pos %d : LUT_ptr[%d]=%x (%f)\n",i,i,LUT_ptr[i],(double)(erf(i*L/(double)(1<<(Nbits-1))))); + printf("pos %u : LUT_ptr[%u]=%x (%f)\n",i,i,LUT_ptr[i],(double)(erf(i*L/(double)(1<<(Nbits-1))))); #endif //LUTDEBUG } @@ -51,40 +46,29 @@ unsigned int *generate_gauss_LUT(unsigned char Nbits, int gauss(unsigned int *gauss_LUT, unsigned char Nbits - ) -{ - + ) { unsigned int search_pos,step_size,u,tmp,tmpm1,tmpp1,s; - // Get a 32-bit uniform random-variable u = taus(); - #ifdef DEBUG printf("u = %u\n",u); #endif //DEBUG - // if it is larger than 2^31 (here negative), save the sign and rescale down to 31-bits. - s = u & 0x80000000; u &= 0x7fffffff; - - #ifdef DEBUG - printf("u = %x,s=%d\n",u,s); + printf("u = %x,s=%u\n",u,s); #endif //DEBUG - search_pos = (1<<(Nbits-2)); // starting position of the binary search step_size = search_pos; do { - step_size >>= 1; - tmp = gauss_LUT[search_pos]; tmpm1 = gauss_LUT[search_pos-1]; tmpp1 = gauss_LUT[search_pos+1]; #ifdef DEBUG - printf("search_pos %d, step_size %d: t %x tm %x,tp %x\n",search_pos,step_size,tmp,tmpm1,tmpp1); + printf("search_pos %u, step_size %u: t %x tm %x,tp %x\n",search_pos,step_size,tmp,tmpm1,tmpp1); #endif //DEBUG if (u <= tmp) @@ -96,12 +80,10 @@ int gauss(unsigned int *gauss_LUT, return s==0 ? search_pos : - search_pos; else search_pos += step_size; - } while (step_size > 0); // If it gets here we're beyond the positive edge so return max return s==0 ? (1<<(Nbits-1))-1 : 1-((1<<(Nbits-1))); - } @@ -109,9 +91,7 @@ int gauss(unsigned int *gauss_LUT, #define Nhistbits 8 -void main(int argc,char **argv) -{ - +void main(int argc,char **argv) { unsigned int *gauss_LUT_ptr,i; unsigned int hist[(1<<Nhistbits)]; int gvar,maxg=0,ming=9999999,maxnum=0,L,Ntrials,Nbits; @@ -125,7 +105,6 @@ void main(int argc,char **argv) Nbits = atoi(argv[1]); L = atoi(argv[2]); Ntrials = atoi(argv[3]); - set_taus_seed(); // Generate Gaussian LUT 12-bit quantization over 5 standard deviations gauss_LUT_ptr = generate_gauss_LUT(Nbits,L); @@ -134,7 +113,6 @@ void main(int argc,char **argv) hist[i] = 0; for (i=0; i<Ntrials; i++) { - gvar = gauss(gauss_LUT_ptr,Nbits); if (gvar == ((1<<(Nbits-1))-1)) @@ -151,10 +129,8 @@ void main(int argc,char **argv) printf("Tail probability = %e(%x)\n",2*erfc((double)L*gauss_LUT_ptr[(1<<(Nbits-1))-1]/(unsigned int)(1<<31)),gauss_LUT_ptr[(1<<(Nbits-1))-1]); printf("max %d, min %d, mean %f, stddev %f, Pr(maxnum)=%e(%d)\n",maxg,ming,meang,sqrt(varg),(double)maxnum/Ntrials,maxnum); - // for (i=0;i<(1<<Nhistbits);i++) // printf("%d : %u\n",i,hist[i]); - free(gauss_LUT_ptr); } diff --git a/openair1/SIMULATION/TOOLS/multipath_tv_channel.c b/openair1/SIMULATION/TOOLS/multipath_tv_channel.c index daa3462b1c85c1f4cf6ec22fcb29cea1e740c6e3..f4835570bf386eef8435720825d8e620c3b49c37 100644 --- a/openair1/SIMULATION/TOOLS/multipath_tv_channel.c +++ b/openair1/SIMULATION/TOOLS/multipath_tv_channel.c @@ -37,24 +37,18 @@ void multipath_tv_channel(channel_desc_t *desc, double **rx_sig_re, double **rx_sig_im, uint16_t length, - uint8_t keep_channel) -{ - - double complex **tx,**rx,***H_t,*rx_temp;//, *tv_H_t; + uint8_t keep_channel) { + double complex **tx,**rx,* **H_t,*rx_temp; //, *tv_H_t; double path_loss = pow(10,desc->path_loss_dB/20); int i,j,k,dd; - dd = abs(desc->channel_offset); - #ifdef DEBUG_CH - printf("[TV CHANNEL] keep = %d : path_loss = %g (%f), nb_rx %d, nb_tx %d, dd %d, len %d max_doppler %d\n",keep_channel,path_loss,desc->path_loss_dB,desc->nb_rx,desc->nb_tx,dd,desc->channel_length, + printf("[TV CHANNEL] keep = %d : path_loss = %g (%f), nb_rx %d, nb_tx %d, dd %d, len %d max_doppler %g\n",keep_channel,path_loss,desc->path_loss_dB,desc->nb_rx,desc->nb_tx,dd,desc->channel_length, desc->max_Doppler); #endif - tx = (double complex **)malloc(desc->nb_tx*sizeof(double complex)); rx = (double complex **)malloc(desc->nb_rx*sizeof(double complex)); - - H_t= (double complex ***) malloc(desc->nb_tx*desc->nb_rx*sizeof(double complex **)); + H_t= (double complex ** *) malloc(desc->nb_tx*desc->nb_rx*sizeof(double complex **)); // tv_H_t = (double complex *) malloc(length*sizeof(double complex)); rx_temp= (double complex *) calloc(length,sizeof(double complex)); @@ -128,17 +122,13 @@ void multipath_tv_channel(channel_desc_t *desc, } free(H_t); - free(rx_temp); } //TODO: make phi_rad a parameter of this function -void tv_channel(channel_desc_t *desc,double complex ***H,uint16_t length) -{ - +void tv_channel(channel_desc_t *desc,double complex ***H,uint16_t length) { int i,j,p,l,k; double *alpha,*phi_rad,pi=acos(-1),*w_Hz; - alpha = (double *)calloc(desc->nb_paths,sizeof(double)); phi_rad = (double *)calloc(desc->nb_paths,sizeof(double)); w_Hz = (double *)calloc(desc->nb_paths,sizeof(double)); @@ -203,21 +193,17 @@ void tv_channel(channel_desc_t *desc,double complex ***H,uint16_t length) } // time varying convolution -void tv_conv(double complex **h, double complex *x, double complex *y, uint16_t nb_samples, uint8_t nb_taps, int dd) -{ - +void tv_conv(double complex **h, double complex *x, double complex *y, uint16_t nb_samples, uint8_t nb_taps, int dd) { int i,j; for(i=0; i<((int)nb_samples-dd); i++) { for(j=0; j<nb_taps; j++) { if(i>j) y[i+dd] += creal(h[i][j])*creal(x[i-j])-cimag(h[i][j])*cimag(x[i-j]) + I*(creal(h[i][j])*cimag(x[i-j])+cimag(h[i][j])*creal(x[i-j])); - } } } -double frand_a_b(double a, double b) -{ +double frand_a_b(double a, double b) { return (rand()/(double)RAND_MAX)*(b-a)+a; } diff --git a/openair2/COMMON/s1ap_messages_def.h b/openair2/COMMON/s1ap_messages_def.h index f98782f19ec238bb32de3fd0ce770372fa032f37..57201721ced6b4019577343a897bae1bdb3db2cd 100644 --- a/openair2/COMMON/s1ap_messages_def.h +++ b/openair2/COMMON/s1ap_messages_def.h @@ -39,6 +39,8 @@ MESSAGE_DEF(S1AP_PAGING_LOG , MESSAGE_PRIORITY_MED, IttiMsgText MESSAGE_DEF(S1AP_E_RAB_RELEASE_REQUEST_LOG , MESSAGE_PRIORITY_MED, IttiMsgText , s1ap_e_rab_release_request_log) MESSAGE_DEF(S1AP_E_RAB_RELEASE_RESPONSE_LOG , MESSAGE_PRIORITY_MED, IttiMsgText , s1ap_e_rab_release_response_log) MESSAGE_DEF(S1AP_ERROR_INDICATION_LOG , MESSAGE_PRIORITY_MED, IttiMsgText , s1ap_error_indication_log) +MESSAGE_DEF(S1AP_PATH_SWITCH_REQ_LOG , MESSAGE_PRIORITY_MED, IttiMsgText , s1ap_path_switch_req_log) +MESSAGE_DEF(S1AP_PATH_SWITCH_REQ_ACK_LOG , MESSAGE_PRIORITY_MED, IttiMsgText , s1ap_path_switch_req_ack_log) /* eNB application layer -> S1AP messages */ MESSAGE_DEF(S1AP_REGISTER_ENB_REQ , MESSAGE_PRIORITY_MED, s1ap_register_enb_req_t , s1ap_register_enb_req) @@ -62,6 +64,8 @@ MESSAGE_DEF(S1AP_E_RAB_SETUP_RESP , MESSAGE_PRIORITY_MED, s1ap_e_rab_se MESSAGE_DEF(S1AP_E_RAB_SETUP_REQUEST_FAIL , MESSAGE_PRIORITY_MED, s1ap_e_rab_setup_req_fail_t , s1ap_e_rab_setup_request_fail) MESSAGE_DEF(S1AP_E_RAB_MODIFY_RESP , MESSAGE_PRIORITY_MED, s1ap_e_rab_modify_resp_t , s1ap_e_rab_modify_resp) MESSAGE_DEF(S1AP_E_RAB_RELEASE_RESPONSE , MESSAGE_PRIORITY_MED, s1ap_e_rab_release_resp_t , s1ap_e_rab_release_resp) +MESSAGE_DEF(S1AP_PATH_SWITCH_REQ , MESSAGE_PRIORITY_MED, s1ap_path_switch_req_t , s1ap_path_switch_req) +MESSAGE_DEF(S1AP_PATH_SWITCH_REQ_ACK , MESSAGE_PRIORITY_MED, s1ap_path_switch_req_ack_t , s1ap_path_switch_req_ack) /* S1AP -> RRC messages */ MESSAGE_DEF(S1AP_DOWNLINK_NAS , MESSAGE_PRIORITY_MED, s1ap_downlink_nas_t , s1ap_downlink_nas ) diff --git a/openair2/COMMON/s1ap_messages_types.h b/openair2/COMMON/s1ap_messages_types.h index f56a340cb24d7df4c9db45b4c6f6b156568c2817..2ea8237184fa96462c3fffe17f7877b3f2200db5 100644 --- a/openair2/COMMON/s1ap_messages_types.h +++ b/openair2/COMMON/s1ap_messages_types.h @@ -42,6 +42,8 @@ #define S1AP_E_RAB_SETUP_RESP(mSGpTR) (mSGpTR)->ittiMsg.s1ap_e_rab_setup_resp #define S1AP_E_RAB_SETUP_FAIL(mSGpTR) (mSGpTR)->ittiMsg.s1ap_e_rab_setup_req_fail #define S1AP_E_RAB_MODIFY_RESP(mSGpTR) (mSGpTR)->ittiMsg.s1ap_e_rab_modify_resp +#define S1AP_PATH_SWITCH_REQ(mSGpTR) (mSGpTR)->ittiMsg.s1ap_path_switch_req +#define S1AP_PATH_SWITCH_REQ_ACK(mSGpTR) (mSGpTR)->ittiMsg.s1ap_path_switch_req_ack #define S1AP_DOWNLINK_NAS(mSGpTR) (mSGpTR)->ittiMsg.s1ap_downlink_nas #define S1AP_INITIAL_CONTEXT_SETUP_REQ(mSGpTR) (mSGpTR)->ittiMsg.s1ap_initial_context_setup_req @@ -269,6 +271,17 @@ typedef struct e_rab_setup_s { uint32_t gtp_teid; } e_rab_setup_t; +typedef struct e_rab_tobeswitched_s { + /* Unique e_rab_id for the UE. */ + uint8_t e_rab_id; + + /* The transport layer address for the IP packets */ + transport_layer_addr_t sgw_addr; + + /* S-GW Tunnel endpoint identifier */ + uint32_t gtp_teid; +} e_rab_tobeswitched_t; + typedef struct e_rab_modify_s { /* Unique e_rab_id for the UE. */ uint8_t e_rab_id; @@ -480,6 +493,8 @@ typedef struct s1ap_initial_context_setup_req_s { /* eNB ue s1ap id as initialized by S1AP layer */ unsigned eNB_ue_s1ap_id:24; + uint32_t mme_ue_s1ap_id; + /* UE aggregate maximum bitrate */ ambr_t ue_ambr; @@ -533,7 +548,7 @@ typedef struct s1ap_e_rab_setup_req_s { uint16_t ue_initial_id; /* MME UE id */ - uint16_t mme_ue_s1ap_id; + uint32_t mme_ue_s1ap_id; /* eNB ue s1ap id as initialized by S1AP layer */ unsigned eNB_ue_s1ap_id:24; @@ -560,6 +575,58 @@ typedef struct s1ap_e_rab_setup_resp_s { e_rab_failed_t e_rabs_failed[S1AP_MAX_E_RAB]; } s1ap_e_rab_setup_resp_t; +typedef struct s1ap_path_switch_req_s { + + unsigned eNB_ue_s1ap_id:24; + + /* Number of e_rab setup-ed in the list */ + uint8_t nb_of_e_rabs; + + /* list of e_rab setup-ed by RRC layers */ + e_rab_setup_t e_rabs_tobeswitched[S1AP_MAX_E_RAB]; + + /* MME UE id */ + uint32_t mme_ue_s1ap_id; + + s1ap_gummei_t ue_gummei; + + uint16_t ue_initial_id; + + /* Security algorithms */ + security_capabilities_t security_capabilities; + +} s1ap_path_switch_req_t; + +typedef struct s1ap_path_switch_req_ack_s { + + /* UE id for initial connection to S1AP */ + uint16_t ue_initial_id; + + unsigned eNB_ue_s1ap_id:24; + + /* MME UE id */ + uint32_t mme_ue_s1ap_id; + + /* UE aggregate maximum bitrate */ + ambr_t ue_ambr; + + /* Number of e_rab setup-ed in the list */ + uint8_t nb_e_rabs_tobeswitched; + + /* list of e_rab to be switched by RRC layers */ + e_rab_tobeswitched_t e_rabs_tobeswitched[S1AP_MAX_E_RAB]; + + /* Number of e_rabs to be released by RRC */ + uint8_t nb_e_rabs_tobereleased; + + /* list of e_rabs to be released */ + e_rab_failed_t e_rabs_tobereleased[S1AP_MAX_E_RAB]; + + /* Security key */ + int next_hop_chain_count; + uint8_t next_security_key[SECURITY_KEY_LENGTH]; + +} s1ap_path_switch_req_ack_t; // S1AP --> RRC messages typedef struct s1ap_ue_release_command_s { @@ -582,7 +649,7 @@ typedef struct s1ap_e_rab_modify_req_s { uint16_t ue_initial_id; /* MME UE id */ - uint16_t mme_ue_s1ap_id; + uint32_t mme_ue_s1ap_id; /* eNB ue s1ap id as initialized by S1AP layer */ unsigned eNB_ue_s1ap_id:24; @@ -615,7 +682,7 @@ typedef struct e_rab_release_s { typedef struct s1ap_e_rab_release_command_s { /* MME UE id */ - uint16_t mme_ue_s1ap_id; + uint32_t mme_ue_s1ap_id; /* eNB ue s1ap id as initialized by S1AP layer */ unsigned eNB_ue_s1ap_id:24; @@ -633,7 +700,7 @@ typedef struct s1ap_e_rab_release_command_s { typedef struct s1ap_e_rab_release_resp_s { /* MME UE id */ - uint16_t mme_ue_s1ap_id; + uint32_t mme_ue_s1ap_id; /* eNB ue s1ap id as initialized by S1AP layer */ unsigned eNB_ue_s1ap_id:24; diff --git a/openair2/COMMON/x2ap_messages_types.h b/openair2/COMMON/x2ap_messages_types.h index 9b744ded6b5641b13ca03ccd52e27c9a9d30584a..7cdd0ff0ff37a605e59604a0186e951ae6d47463 100644 --- a/openair2/COMMON/x2ap_messages_types.h +++ b/openair2/COMMON/x2ap_messages_types.h @@ -22,6 +22,7 @@ #ifndef X2AP_MESSAGES_TYPES_H_ #define X2AP_MESSAGES_TYPES_H_ +#include "s1ap_messages_types.h" #include "LTE_PhysCellId.h" //-------------------------------------------------------------------------------------------// @@ -132,7 +133,7 @@ typedef struct x2ap_handover_req_s { int source_rnti; /* TODO: to be fixed/remove */ int source_x2id; /* TODO: to be fixed/remove */ - unsigned old_eNB_ue_s1ap_id:24; + int old_eNB_ue_x2ap_id; LTE_PhysCellId_t target_physCellId; @@ -158,10 +159,14 @@ typedef struct x2ap_handover_req_s { /* list of e_rab setup-ed by RRC layers */ e_rab_setup_t e_rabs_tobesetup[S1AP_MAX_E_RAB]; - /* ue_context_pP->ue_context.e_rab[i].param.sgw_addr; */ + /* list of e_rab to be setup by RRC layers */ + e_rab_t e_rab_param[S1AP_MAX_E_RAB]; x2ap_lastvisitedcell_info_t lastvisitedcell_info; + uint8_t rrc_buffer[1024 /* arbitrary, big enough */]; + int rrc_buffer_size; + /* TODO: this parameter has to be removed */ int target_mod_id; } x2ap_handover_req_t; @@ -171,6 +176,15 @@ typedef struct x2ap_handover_req_ack_s { int source_x2id; /* TODO: to be fixed/remove */ /* TODO: this parameter has to be removed */ int target_mod_id; + + uint8_t nb_e_rabs_tobesetup; + + /* list of e_rab setup-ed by RRC layers */ + e_rab_setup_t e_rabs_tobesetup[S1AP_MAX_E_RAB]; + + /* list of e_rab to be setup by RRC layers */ + e_rab_t e_rab_param[S1AP_MAX_E_RAB]; + uint8_t rrc_buffer[1024 /* arbitrary, big enough */]; int rrc_buffer_size; diff --git a/openair2/ENB_APP/NB_IoT_config.c b/openair2/ENB_APP/NB_IoT_config.c index 08c3d30fa366cc0012c9550ea202d9b396567112..272fa48b3e09079df1b4ca8a8533eff3f52dd9d1 100644 --- a/openair2/ENB_APP/NB_IoT_config.c +++ b/openair2/ENB_APP/NB_IoT_config.c @@ -34,11 +34,11 @@ #include "log_extern.h" #include "assertions.h" #if defined(ENABLE_ITTI) -# include "intertask_interface.h" -# if defined(ENABLE_USE_MME) -# include "s1ap_eNB.h" -# include "sctp_eNB_task.h" -# endif + #include "intertask_interface.h" + #if defined(ENABLE_USE_MME) + #include "s1ap_eNB.h" + #include "sctp_eNB_task.h" + #endif #endif #include "SystemInformationBlockType2.h" @@ -56,11 +56,10 @@ void RCconfig_NbIoTL1(void) { paramdef_t NbIoT_L1_Params[] = L1PARAMS_DESC; paramlist_def_t NbIoT_L1_ParamList = {NBIOT_L1LIST_CONFIG_STRING,NULL,0}; + /* No component carrier for NbIoT, ignore number of CC */ + // NbIoT_L1_Params[L1_CC_IDX ].paramflags = PARAMFLAG_DONOTREAD; + config_getlist( &NbIoT_L1_ParamList,NbIoT_L1_Params,sizeof(NbIoT_L1_Params)/sizeof(paramdef_t), NULL); -/* No component carrier for NbIoT, ignore number of CC */ -// NbIoT_L1_Params[L1_CC_IDX ].paramflags = PARAMFLAG_DONOTREAD; - - config_getlist( &NbIoT_L1_ParamList,NbIoT_L1_Params,sizeof(NbIoT_L1_Params)/sizeof(paramdef_t), NULL); if (NbIoT_L1_ParamList.numelt > 0) { if (RC.L1_NB_IoT == NULL) { RC.L1_NB_IoT = (PHY_VARS_eNB_NB_IoT **)malloc(RC.nb_nb_iot_L1_inst*sizeof(PHY_VARS_eNB_NB_IoT *)); @@ -68,219 +67,190 @@ void RCconfig_NbIoTL1(void) { memset(RC.L1_NB_IoT,0,RC.nb_nb_iot_L1_inst*sizeof(PHY_VARS_eNB_NB_IoT *)); } - - for(int j = 0; j <NbIoT_L1_ParamList.numelt ; j++) { + for(int j = 0; j <NbIoT_L1_ParamList.numelt ; j++) { if (RC.L1_NB_IoT[j] == NULL) { - RC.L1_NB_IoT[j] = (PHY_VARS_eNB_NB_IoT *)malloc(sizeof(PHY_VARS_eNB_NB_IoT)); - LOG_I(PHY,"RC.L1_NB_IoT[%d] = %p\n",j,RC.L1_NB_IoT[j]); - memset(RC.L1_NB_IoT[j],0,sizeof(PHY_VARS_eNB_NB_IoT)); + RC.L1_NB_IoT[j] = (PHY_VARS_eNB_NB_IoT *)malloc(sizeof(PHY_VARS_eNB_NB_IoT)); + LOG_I(PHY,"RC.L1_NB_IoT[%d] = %p\n",j,RC.L1_NB_IoT[j]); + memset(RC.L1_NB_IoT[j],0,sizeof(PHY_VARS_eNB_NB_IoT)); } - if (strcmp(*(NbIoT_L1_ParamList.paramarray[j][L1_TRANSPORT_N_PREFERENCE_IDX].strptr), "local_mac") == 0) { + if (strcmp(*(NbIoT_L1_ParamList.paramarray[j][L1_TRANSPORT_N_PREFERENCE_IDX].strptr), "local_mac") == 0) { + } else if (strcmp(*(NbIoT_L1_ParamList.paramarray[j][L1_TRANSPORT_N_PREFERENCE_IDX].strptr), "nfapi") == 0) { + RC.L1_NB_IoT[j]->eth_params_n.local_if_name = strdup(*(NbIoT_L1_ParamList.paramarray[j][L1_LOCAL_N_IF_NAME_IDX].strptr)); + RC.L1_NB_IoT[j]->eth_params_n.my_addr = strdup(*(NbIoT_L1_ParamList.paramarray[j][L1_LOCAL_N_ADDRESS_IDX].strptr)); + RC.L1_NB_IoT[j]->eth_params_n.remote_addr = strdup(*(NbIoT_L1_ParamList.paramarray[j][L1_REMOTE_N_ADDRESS_IDX].strptr)); + RC.L1_NB_IoT[j]->eth_params_n.my_portc = *(NbIoT_L1_ParamList.paramarray[j][L1_LOCAL_N_PORTC_IDX].iptr); + RC.L1_NB_IoT[j]->eth_params_n.remote_portc = *(NbIoT_L1_ParamList.paramarray[j][L1_REMOTE_N_PORTC_IDX].iptr); + RC.L1_NB_IoT[j]->eth_params_n.my_portd = *(NbIoT_L1_ParamList.paramarray[j][L1_LOCAL_N_PORTD_IDX].iptr); + RC.L1_NB_IoT[j]->eth_params_n.remote_portd = *(NbIoT_L1_ParamList.paramarray[j][L1_REMOTE_N_PORTD_IDX].iptr); + RC.L1_NB_IoT[j]->eth_params_n.transp_preference = ETH_UDP_MODE; + } else { // other midhaul } - else if (strcmp(*(NbIoT_L1_ParamList.paramarray[j][L1_TRANSPORT_N_PREFERENCE_IDX].strptr), "nfapi") == 0) { - RC.L1_NB_IoT[j]->eth_params_n.local_if_name = strdup(*(NbIoT_L1_ParamList.paramarray[j][L1_LOCAL_N_IF_NAME_IDX].strptr)); - RC.L1_NB_IoT[j]->eth_params_n.my_addr = strdup(*(NbIoT_L1_ParamList.paramarray[j][L1_LOCAL_N_ADDRESS_IDX].strptr)); - RC.L1_NB_IoT[j]->eth_params_n.remote_addr = strdup(*(NbIoT_L1_ParamList.paramarray[j][L1_REMOTE_N_ADDRESS_IDX].strptr)); - RC.L1_NB_IoT[j]->eth_params_n.my_portc = *(NbIoT_L1_ParamList.paramarray[j][L1_LOCAL_N_PORTC_IDX].iptr); - RC.L1_NB_IoT[j]->eth_params_n.remote_portc = *(NbIoT_L1_ParamList.paramarray[j][L1_REMOTE_N_PORTC_IDX].iptr); - RC.L1_NB_IoT[j]->eth_params_n.my_portd = *(NbIoT_L1_ParamList.paramarray[j][L1_LOCAL_N_PORTD_IDX].iptr); - RC.L1_NB_IoT[j]->eth_params_n.remote_portd = *(NbIoT_L1_ParamList.paramarray[j][L1_REMOTE_N_PORTD_IDX].iptr); - RC.L1_NB_IoT[j]->eth_params_n.transp_preference = ETH_UDP_MODE; - } - - else { // other midhaul - } }// j=0..num_inst + printf("Initializing northbound interface for NB-IoT L1\n"); l1_north_init_NB_IoT(); } else { - LOG_I(PHY,"No " NBIOT_L1LIST_CONFIG_STRING " configuration found"); + LOG_I(PHY,"No " NBIOT_L1LIST_CONFIG_STRING " configuration found"); } } void RCconfig_NbIoTmacrlc(void) { - - - paramdef_t NbIoT_MacRLC_Params[] = MACRLCPARAMS_DESC; paramlist_def_t NbIoT_MacRLC_ParamList = {NBIOT_MACRLCLIST_CONFIG_STRING,NULL,0}; - - -/* No component carrier for NbIoT, ignore number of CC */ -// NbIoT_MacRLC_Params[MACRLC_CC_IDX ].paramflags = PARAMFLAG_DONOTREAD; - - config_getlist( &NbIoT_MacRLC_ParamList,NbIoT_MacRLC_Params,sizeof(NbIoT_MacRLC_Params)/sizeof(paramdef_t), NULL); - + /* No component carrier for NbIoT, ignore number of CC */ + // NbIoT_MacRLC_Params[MACRLC_CC_IDX ].paramflags = PARAMFLAG_DONOTREAD; + config_getlist( &NbIoT_MacRLC_ParamList,NbIoT_MacRLC_Params,sizeof(NbIoT_MacRLC_Params)/sizeof(paramdef_t), NULL); if ( NbIoT_MacRLC_ParamList.numelt > 0) { mac_top_init_eNB_NB_IoT(); - for (int j=0;j<RC.nb_nb_iot_macrlc_inst;j++) { + for (int j=0; j<RC.nb_nb_iot_macrlc_inst; j++) { if (strcmp(*(NbIoT_MacRLC_ParamList.paramarray[j][MACRLC_TRANSPORT_N_PREFERENCE_IDX].strptr), "local_RRC") == 0) { - // check number of instances is same as RRC/PDCP - + // check number of instances is same as RRC/PDCP } else if (strcmp(*(NbIoT_MacRLC_ParamList.paramarray[j][MACRLC_TRANSPORT_N_PREFERENCE_IDX].strptr), "cudu") == 0) { - RC.nb_iot_mac[j]->eth_params_n.local_if_name = strdup(*(NbIoT_MacRLC_ParamList.paramarray[j][MACRLC_LOCAL_N_IF_NAME_IDX].strptr)); - RC.nb_iot_mac[j]->eth_params_n.my_addr = strdup(*(NbIoT_MacRLC_ParamList.paramarray[j][MACRLC_LOCAL_N_ADDRESS_IDX].strptr)); - RC.nb_iot_mac[j]->eth_params_n.remote_addr = strdup(*(NbIoT_MacRLC_ParamList.paramarray[j][MACRLC_REMOTE_N_ADDRESS_IDX].strptr)); - RC.nb_iot_mac[j]->eth_params_n.my_portc = *(NbIoT_MacRLC_ParamList.paramarray[j][MACRLC_LOCAL_N_PORTC_IDX].iptr); - RC.nb_iot_mac[j]->eth_params_n.remote_portc = *(NbIoT_MacRLC_ParamList.paramarray[j][MACRLC_REMOTE_N_PORTC_IDX].iptr); - RC.nb_iot_mac[j]->eth_params_n.my_portd = *(NbIoT_MacRLC_ParamList.paramarray[j][MACRLC_LOCAL_N_PORTD_IDX].iptr); - RC.nb_iot_mac[j]->eth_params_n.remote_portd = *(NbIoT_MacRLC_ParamList.paramarray[j][MACRLC_REMOTE_N_PORTD_IDX].iptr);; - RC.nb_iot_mac[j]->eth_params_n.transp_preference = ETH_UDP_MODE; + RC.nb_iot_mac[j]->eth_params_n.local_if_name = strdup(*(NbIoT_MacRLC_ParamList.paramarray[j][MACRLC_LOCAL_N_IF_NAME_IDX].strptr)); + RC.nb_iot_mac[j]->eth_params_n.my_addr = strdup(*(NbIoT_MacRLC_ParamList.paramarray[j][MACRLC_LOCAL_N_ADDRESS_IDX].strptr)); + RC.nb_iot_mac[j]->eth_params_n.remote_addr = strdup(*(NbIoT_MacRLC_ParamList.paramarray[j][MACRLC_REMOTE_N_ADDRESS_IDX].strptr)); + RC.nb_iot_mac[j]->eth_params_n.my_portc = *(NbIoT_MacRLC_ParamList.paramarray[j][MACRLC_LOCAL_N_PORTC_IDX].iptr); + RC.nb_iot_mac[j]->eth_params_n.remote_portc = *(NbIoT_MacRLC_ParamList.paramarray[j][MACRLC_REMOTE_N_PORTC_IDX].iptr); + RC.nb_iot_mac[j]->eth_params_n.my_portd = *(NbIoT_MacRLC_ParamList.paramarray[j][MACRLC_LOCAL_N_PORTD_IDX].iptr); + RC.nb_iot_mac[j]->eth_params_n.remote_portd = *(NbIoT_MacRLC_ParamList.paramarray[j][MACRLC_REMOTE_N_PORTD_IDX].iptr);; + RC.nb_iot_mac[j]->eth_params_n.transp_preference = ETH_UDP_MODE; } else { // other midhaul - AssertFatal(1==0,"MACRLC %d: %s unknown northbound midhaul\n",j, *(NbIoT_MacRLC_ParamList.paramarray[j][MACRLC_TRANSPORT_N_PREFERENCE_IDX].strptr)); - } + AssertFatal(1==0,"MACRLC %d: %s unknown northbound midhaul\n",j, *(NbIoT_MacRLC_ParamList.paramarray[j][MACRLC_TRANSPORT_N_PREFERENCE_IDX].strptr)); + } if (strcmp(*(NbIoT_MacRLC_ParamList.paramarray[j][MACRLC_TRANSPORT_S_PREFERENCE_IDX].strptr), "local_L1") == 0) { - - } else if (strcmp(*(NbIoT_MacRLC_ParamList.paramarray[j][MACRLC_TRANSPORT_S_PREFERENCE_IDX].strptr), "nfapi") == 0) { - RC.nb_iot_mac[j]->eth_params_s.local_if_name = strdup(*(NbIoT_MacRLC_ParamList.paramarray[j][MACRLC_LOCAL_S_IF_NAME_IDX].strptr)); - RC.nb_iot_mac[j]->eth_params_s.my_addr = strdup(*(NbIoT_MacRLC_ParamList.paramarray[j][MACRLC_LOCAL_S_ADDRESS_IDX].strptr)); - RC.nb_iot_mac[j]->eth_params_s.remote_addr = strdup(*(NbIoT_MacRLC_ParamList.paramarray[j][MACRLC_REMOTE_S_ADDRESS_IDX].strptr)); - RC.nb_iot_mac[j]->eth_params_s.my_portc = *(NbIoT_MacRLC_ParamList.paramarray[j][MACRLC_LOCAL_S_PORTC_IDX].iptr); - RC.nb_iot_mac[j]->eth_params_s.remote_portc = *(NbIoT_MacRLC_ParamList.paramarray[j][MACRLC_REMOTE_S_PORTC_IDX].iptr); - RC.nb_iot_mac[j]->eth_params_s.my_portd = *(NbIoT_MacRLC_ParamList.paramarray[j][MACRLC_LOCAL_S_PORTD_IDX].iptr); - RC.nb_iot_mac[j]->eth_params_s.remote_portd = *(NbIoT_MacRLC_ParamList.paramarray[j][MACRLC_REMOTE_S_PORTD_IDX].iptr); - RC.nb_iot_mac[j]->eth_params_s.transp_preference = ETH_UDP_MODE; + RC.nb_iot_mac[j]->eth_params_s.local_if_name = strdup(*(NbIoT_MacRLC_ParamList.paramarray[j][MACRLC_LOCAL_S_IF_NAME_IDX].strptr)); + RC.nb_iot_mac[j]->eth_params_s.my_addr = strdup(*(NbIoT_MacRLC_ParamList.paramarray[j][MACRLC_LOCAL_S_ADDRESS_IDX].strptr)); + RC.nb_iot_mac[j]->eth_params_s.remote_addr = strdup(*(NbIoT_MacRLC_ParamList.paramarray[j][MACRLC_REMOTE_S_ADDRESS_IDX].strptr)); + RC.nb_iot_mac[j]->eth_params_s.my_portc = *(NbIoT_MacRLC_ParamList.paramarray[j][MACRLC_LOCAL_S_PORTC_IDX].iptr); + RC.nb_iot_mac[j]->eth_params_s.remote_portc = *(NbIoT_MacRLC_ParamList.paramarray[j][MACRLC_REMOTE_S_PORTC_IDX].iptr); + RC.nb_iot_mac[j]->eth_params_s.my_portd = *(NbIoT_MacRLC_ParamList.paramarray[j][MACRLC_LOCAL_S_PORTD_IDX].iptr); + RC.nb_iot_mac[j]->eth_params_s.remote_portd = *(NbIoT_MacRLC_ParamList.paramarray[j][MACRLC_REMOTE_S_PORTD_IDX].iptr); + RC.nb_iot_mac[j]->eth_params_s.transp_preference = ETH_UDP_MODE; } else { // other midhaul - AssertFatal(1==0,"MACRLC %d: %s unknown southbound midhaul\n",j,*(NbIoT_MacRLC_ParamList.paramarray[j][MACRLC_TRANSPORT_S_PREFERENCE_IDX].strptr)); - } + AssertFatal(1==0,"MACRLC %d: %s unknown southbound midhaul\n",j,*(NbIoT_MacRLC_ParamList.paramarray[j][MACRLC_TRANSPORT_S_PREFERENCE_IDX].strptr)); + } }// j=0..num_inst */ } else {// MacRLC_ParamList.numelt > 0 - AssertFatal (0, - "No " NBIOT_MACRLCLIST_CONFIG_STRING " configuration found"); + AssertFatal (0, + "No " NBIOT_MACRLCLIST_CONFIG_STRING " configuration found"); } } - -int RCconfig_NbIoTRRC(MessageDef *msg_p, int nbiotrrc_id,eNB_RRC_INST_NB_IoT *nbiotrrc) { - +int RCconfig_NbIoTRRC(MessageDef *msg_p, int nbiotrrc_id,eNB_RRC_INST_NB_IoT *nbiotrrc) { char instprefix[MAX_OPTNAME_SIZE*3 + 32]; - - - checkedparam_t NBIoTCheckParams[] = NBIOT_RRCPARAMS_CHECK_DESC; + checkedparam_t NBIoTCheckParams[] = NBIOT_RRCPARAMS_CHECK_DESC_0_14; + checkedparam_t NBIoTCheckParamsB[] = NBIOT_RRCPARAMS_CHECK_DESC_15_end; paramdef_t NBIoTParams[] = NBIOTRRCPARAMS_DESC; - paramdef_t NBIoTPrachParams[] = NBIOTRRC_NPRACH_PARAMS_DESC; checkedparam_t NBIoTPrachCheckParams[] = NBIOT_RRCLIST_NPRACHPARAMSCHECK_DESC; - paramdef_t NBIoTRRCRefParams[] = NBIOTRRCPARAMS_RRCREF_DESC; - paramdef_t NBIoTLteCCParams[] = NBIOT_LTECCPARAMS_DESC; checkedparam_t NBIoTLteCCCheckParams[] = NBIOT_LTECCPARAMS_CHECK_DESC; -/* map parameter checking array instances to parameter definition array instances */ + + /* map parameter checking array instances to parameter definition array instances */ for (int i=0; (i<sizeof(NBIoTParams)/sizeof(paramdef_t)) && (i<sizeof(NBIoTCheckParams)/sizeof(checkedparam_t)); i++ ) { - NBIoTParams[i].chkPptr = &(NBIoTCheckParams[i]); - } + NBIoTParams[i].chkPptr = &(NBIoTCheckParams[i]); + } + + for (int i=0; (i<sizeof(NBIoTParams)/sizeof(paramdef_t)) && (i<sizeof(NBIoTCheckParamsB)/sizeof(checkedparam_t)); i++ ) { + NBIoTParams[i+15].chkPptr = &(NBIoTCheckParamsB[i]); + } + for (int i=0; (i<sizeof(NBIoTPrachParams)/sizeof(paramdef_t)) && (i<sizeof(NBIoTPrachCheckParams)/sizeof(checkedparam_t)); i++ ) { - NBIoTPrachParams[i].chkPptr = &(NBIoTPrachCheckParams[i]); + NBIoTPrachParams[i].chkPptr = &(NBIoTPrachCheckParams[i]); } -/* brut force itti message fields assignment, to be redesigned with itti replacement */ + /* brut force itti message fields assignment, to be redesigned with itti replacement */ NBIoTParams[NBIOT_RACH_RARESPONSEWINDOWSIZE_NB_IDX].uptr = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).rach_raResponseWindowSize_NB); NBIoTParams[NBIOT_RACH_MACCONTENTIONRESOLUTIONTIMER_NB_IDX].uptr = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).rach_macContentionResolutionTimer_NB); - NBIoTParams[NBIOT_RACH_POWERRAMPINGSTEP_NB_IDX].uptr = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).rach_powerRampingStep_NB); + NBIoTParams[NBIOT_RACH_POWERRAMPINGSTEP_NB_IDX].uptr = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).rach_powerRampingStep_NB); NBIoTParams[NBIOT_RACH_PREAMBLEINITIALRECEIVEDTARGETPOWER_NB_IDX].uptr = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).rach_preambleInitialReceivedTargetPower_NB); - NBIoTParams[NBIOT_RACH_PREAMBLETRANSMAX_CE_NB_IDX].uptr = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).rach_preambleTransMax_CE_NB); - NBIoTParams[NBIOT_BCCH_MODIFICATIONPERIODCOEFF_NB_IDX].uptr = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).bcch_modificationPeriodCoeff_NB); - NBIoTParams[NBIOT_PCCH_DEFAULTPAGINGCYCLE_NB_IDX].uptr = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).pcch_defaultPagingCycle_NB); - NBIoTParams[NBIOT_NPRACH_CP_LENGTH_IDX].uptr = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).nprach_CP_Length); - NBIoTParams[NBIOT_NPRACH_RSRP_RANGE_IDX].uptr = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).nprach_rsrp_range); - - - + NBIoTParams[NBIOT_RACH_PREAMBLETRANSMAX_CE_NB_IDX].uptr = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).rach_preambleTransMax_CE_NB); + NBIoTParams[NBIOT_BCCH_MODIFICATIONPERIODCOEFF_NB_IDX].uptr = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).bcch_modificationPeriodCoeff_NB); + NBIoTParams[NBIOT_PCCH_DEFAULTPAGINGCYCLE_NB_IDX].uptr = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).pcch_defaultPagingCycle_NB); + NBIoTParams[NBIOT_NPRACH_CP_LENGTH_IDX].uptr = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).nprach_CP_Length); + NBIoTParams[NBIOT_NPRACH_RSRP_RANGE_IDX].uptr = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).nprach_rsrp_range); NBIoTParams[NBIOT_MAXNUMPREAMBLEATTEMPTCE_NB_IDX].uptr = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).maxNumPreambleAttemptCE_NB); - - NBIoTParams[NBIOT_NPDSCH_NRS_POWER_IDX].uptr = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).npdsch_nrs_Power); - NBIoTParams[NBIOT_NPUSCH_ACK_NACK_NUMREPETITIONS_NB_IDX].uptr = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p). npusch_ack_nack_numRepetitions_NB); - NBIoTParams[NBIOT_NPUSCH_SRS_SUBFRAMECONFIG_NB_IDX].uptr = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p). npusch_srs_SubframeConfig_NB); - NBIoTParams[NBIOT_NPUSCH_THREETONE_CYCLICSHIFT_R13_IDX].uptr = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).npusch_threeTone_CyclicShift_r13); + NBIoTParams[NBIOT_NPDSCH_NRS_POWER_IDX].uptr = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).npdsch_nrs_Power); + NBIoTParams[NBIOT_NPUSCH_ACK_NACK_NUMREPETITIONS_NB_IDX].uptr = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p). npusch_ack_nack_numRepetitions_NB); + NBIoTParams[NBIOT_NPUSCH_SRS_SUBFRAMECONFIG_NB_IDX].uptr = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p). npusch_srs_SubframeConfig_NB); + NBIoTParams[NBIOT_NPUSCH_THREETONE_CYCLICSHIFT_R13_IDX].uptr = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).npusch_threeTone_CyclicShift_r13); NBIoTParams[NBIOT_NPUSCH_SIXTONE_CYCLICSHIFT_R13_IDX].uptr = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).npusch_sixTone_CyclicShift_r13); - NBIoTParams[NBIOT_NPUSCH_GROUPASSIGNMENTNPUSCH_R13_IDX].uptr = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).npusch_groupAssignmentNPUSCH_r13); - NBIoTParams[NBIOT_DL_GAPTHRESHOLD_NB_IDX].uptr = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).dl_GapThreshold_NB); - NBIoTParams[NBIOT_DL_GAPPERIODICITY_NB_IDX].uptr = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).dl_GapPeriodicity_NB); - - NBIoTParams[NBIOT_NPUSCH_P0_NOMINALNPUSCH_IDX].uptr = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).npusch_p0_NominalNPUSCH); - - NBIoTParams[NBIOT_DELTAPREAMBLEMSG3_IDX].uptr = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).deltaPreambleMsg3); - NBIoTParams[NBIOT_UE_TIMERSANDCONSTANTS_T300_NB_IDX].uptr = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).ue_TimersAndConstants_t300_NB); + NBIoTParams[NBIOT_DL_GAPTHRESHOLD_NB_IDX].uptr = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).dl_GapThreshold_NB); + NBIoTParams[NBIOT_DL_GAPPERIODICITY_NB_IDX].uptr = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).dl_GapPeriodicity_NB); + NBIoTParams[NBIOT_NPUSCH_P0_NOMINALNPUSCH_IDX].uptr = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).npusch_p0_NominalNPUSCH); + NBIoTParams[NBIOT_DELTAPREAMBLEMSG3_IDX].uptr = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).deltaPreambleMsg3); + NBIoTParams[NBIOT_UE_TIMERSANDCONSTANTS_T300_NB_IDX].uptr = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).ue_TimersAndConstants_t300_NB); NBIoTParams[NBIOT_UE_TIMERSANDCONSTANTS_T301_NB_IDX].uptr = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).ue_TimersAndConstants_t301_NB); - NBIoTParams[NBIOT_UE_TIMERSANDCONSTANTS_T310_NB_IDX].uptr = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).ue_TimersAndConstants_t310_NB); - NBIoTParams[NBIOT_UE_TIMERSANDCONSTANTS_T311_NB_IDX].uptr = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).ue_TimersAndConstants_t311_NB); - NBIoTParams[NBIOT_UE_TIMERSANDCONSTANTS_N310_NB_IDX].uptr = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).ue_TimersAndConstants_n310_NB); + NBIoTParams[NBIOT_UE_TIMERSANDCONSTANTS_T310_NB_IDX].uptr = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).ue_TimersAndConstants_t310_NB); + NBIoTParams[NBIOT_UE_TIMERSANDCONSTANTS_T311_NB_IDX].uptr = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).ue_TimersAndConstants_t311_NB); + NBIoTParams[NBIOT_UE_TIMERSANDCONSTANTS_N310_NB_IDX].uptr = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).ue_TimersAndConstants_n310_NB); NBIoTParams[NBIOT_UE_TIMERSANDCONSTANTS_N311_NB_IDX].uptr = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).ue_TimersAndConstants_n311_NB); - sprintf(instprefix, NBIOT_RRCLIST_CONFIG_STRING ".[%i]",nbiotrrc_id); - config_get( NBIoTParams,sizeof(NBIoTParams)/sizeof(paramdef_t),instprefix); - + config_get( NBIoTParams,sizeof(NBIoTParams)/sizeof(paramdef_t),instprefix); NBIOTRRC_CONFIGURATION_REQ (msg_p).nprach_SubcarrierMSG3_RangeStart = config_get_processedint( &(NBIoTParams[NBIOT_NPRACH_SUBCARRIERMSG3_RANGESTART_IDX]) ); - NBIOTRRC_CONFIGURATION_REQ (msg_p).npusch_groupHoppingEnabled = config_get_processedint( &(NBIoTParams[NBIOT_NPUSCH_GROUPHOPPINGENABLED_IDX] ) ); - NBIOTRRC_CONFIGURATION_REQ (msg_p).dl_GapDurationCoeff_NB = config_get_processedint( &(NBIoTParams[NBIOT_DL_GAPDURATIONCOEFF_NB_IDX] ) ); + NBIOTRRC_CONFIGURATION_REQ (msg_p).npusch_groupHoppingEnabled = config_get_processedint( &(NBIoTParams[NBIOT_NPUSCH_GROUPHOPPINGENABLED_IDX] ) ); + NBIOTRRC_CONFIGURATION_REQ (msg_p).dl_GapDurationCoeff_NB = config_get_processedint( &(NBIoTParams[NBIOT_DL_GAPDURATIONCOEFF_NB_IDX] ) ); NBIOTRRC_CONFIGURATION_REQ (msg_p).npusch_alpha = config_get_processedint( &(NBIoTParams[NBIOT_NPUSCH_ALPHA_IDX] ) ); + for (int i=0; i<MAX_NUM_NBIOT_CELEVELS; i++) { - char *tmpptr=NULL; - NBIoTPrachParams[NBIOT_NPRACH_PERIODICITY_IDX ].uptr = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).nprach_Periodicity[i]); - NBIoTPrachParams[NBIOT_NPRACH_STARTTIME_IDX].uptr = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).nprach_StartTime[i]); - NBIoTPrachParams[NBIOT_NPRACH_SUBCARRIEROFFSET_IDX].uptr = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).nprach_SubcarrierOffset[i]); - NBIoTPrachParams[NBIOT_NPRACH_NUMSUBCARRIERS_IDX].uptr = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).nprach_NumSubcarriers[i]); - NBIoTPrachParams[NBIOT_NUMREPETITIONSPERPREAMBLEATTEMPT_NB_IDX].uptr = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).numRepetitionsPerPreambleAttempt_NB[i]); - NBIoTParams[NBIOT_NPDCCH_NUMREPETITIONS_RA_IDX].uptr = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).npdcch_NumRepetitions_RA[i]); - NBIoTParams[NBIOT_NPDCCH_STARTSF_CSS_RA_IDX].uptr = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).npdcch_StartSF_CSS_RA[i]); - NBIoTParams[NBIOT_NPDCCH_OFFSET_RA_IDX].strptr = &tmpptr; - sprintf(instprefix, "%s.[%i].%s.[%i]",NBIOT_RRCLIST_CONFIG_STRING, nbiotrrc_id,NBIOT_RRCLIST_NPRACHPARAMS_CONFIG_STRING,i); - config_get( NBIoTPrachParams,sizeof(NBIoTPrachParams)/sizeof(paramdef_t),instprefix); - NBIOTRRC_CONFIGURATION_REQ (msg_p).npdcch_Offset_RA[i] = config_get_processedint( &(NBIoTPrachParams[NBIOT_NPDCCH_OFFSET_RA_IDX]) ); + char *tmpptr=NULL; + NBIoTPrachParams[NBIOT_NPRACH_PERIODICITY_IDX ].uptr = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).nprach_Periodicity[i]); + NBIoTPrachParams[NBIOT_NPRACH_STARTTIME_IDX].uptr = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).nprach_StartTime[i]); + NBIoTPrachParams[NBIOT_NPRACH_SUBCARRIEROFFSET_IDX].uptr = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).nprach_SubcarrierOffset[i]); + NBIoTPrachParams[NBIOT_NPRACH_NUMSUBCARRIERS_IDX].uptr = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).nprach_NumSubcarriers[i]); + NBIoTPrachParams[NBIOT_NUMREPETITIONSPERPREAMBLEATTEMPT_NB_IDX].uptr = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).numRepetitionsPerPreambleAttempt_NB[i]); + NBIoTParams[NBIOT_NPDCCH_NUMREPETITIONS_RA_IDX].uptr = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).npdcch_NumRepetitions_RA[i]); + NBIoTParams[NBIOT_NPDCCH_STARTSF_CSS_RA_IDX].uptr = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).npdcch_StartSF_CSS_RA[i]); + NBIoTParams[NBIOT_NPDCCH_OFFSET_RA_IDX].strptr = &tmpptr; + sprintf(instprefix, "%s.[%i].%s.[%i]",NBIOT_RRCLIST_CONFIG_STRING, nbiotrrc_id,NBIOT_RRCLIST_NPRACHPARAMS_CONFIG_STRING,i); + config_get( NBIoTPrachParams,sizeof(NBIoTPrachParams)/sizeof(paramdef_t),instprefix); + NBIOTRRC_CONFIGURATION_REQ (msg_p).npdcch_Offset_RA[i] = config_get_processedint( &(NBIoTPrachParams[NBIOT_NPDCCH_OFFSET_RA_IDX]) ); } -/* get the LTE RRC and CC this NB-IoT RRC instance is attached to */ - sprintf(instprefix, NBIOT_RRCLIST_CONFIG_STRING ".[%i]." NBIOT_LTERRCREF_CONFIG_STRING, nbiotrrc_id ); - config_get( NBIoTRRCRefParams,sizeof(NBIoTRRCRefParams)/sizeof(paramdef_t),instprefix); -/* read SIB1 parameters in the LTE RRC and CC sections */ + /* get the LTE RRC and CC this NB-IoT RRC instance is attached to */ + sprintf(instprefix, NBIOT_RRCLIST_CONFIG_STRING ".[%i]." NBIOT_LTERRCREF_CONFIG_STRING, nbiotrrc_id ); + config_get( NBIoTRRCRefParams,sizeof(NBIoTRRCRefParams)/sizeof(paramdef_t),instprefix); + /* read SIB1 parameters in the LTE RRC and CC sections */ sprintf(instprefix, ENB_CONFIG_STRING_ENB_LIST ".[%i]." ENB_CONFIG_STRING_COMPONENT_CARRIERS ".[%i]", - *(NBIoTRRCRefParams[NBIOT_RRCINST_IDX].uptr), *(NBIoTRRCRefParams[NBIOT_CCINST_IDX].uptr)); - - NBIoTLteCCParams[LTECCPARAMS_TDD_CONFIG_IDX ].uptr = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).tdd_config); - NBIoTLteCCParams[LTECCPARAMS_TDD_CONFIG_S_IDX].uptr = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).tdd_config_s); - NBIoTLteCCParams[LTECCPARAMS_EUTRA_BAND_IDX ].uptr = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).eutra_band); - NBIoTLteCCParams[LTECCPARAMS_DOWNLINK_FREQUENCY_IDX].uptr = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).downlink_frequency); + *(NBIoTRRCRefParams[NBIOT_RRCINST_IDX].uptr), *(NBIoTRRCRefParams[NBIOT_CCINST_IDX].uptr)); + NBIoTLteCCParams[LTECCPARAMS_TDD_CONFIG_IDX ].uptr = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).tdd_config); + NBIoTLteCCParams[LTECCPARAMS_TDD_CONFIG_S_IDX].uptr = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).tdd_config_s); + NBIoTLteCCParams[LTECCPARAMS_EUTRA_BAND_IDX ].uptr = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).eutra_band); + NBIoTLteCCParams[LTECCPARAMS_DOWNLINK_FREQUENCY_IDX].uptr = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).downlink_frequency); NBIoTLteCCParams[LTECCPARAMS_UPLINK_FREQUENCY_OFFSET_IDX].uptr = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).uplink_frequency_offset); - NBIoTLteCCParams[LTECCPARAMS_NID_CELL_IDX].uptr = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).Nid_cell); - NBIoTLteCCParams[LTECCPARAMS_N_RB_DL_IDX].uptr = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).N_RB_DL); + NBIoTLteCCParams[LTECCPARAMS_NID_CELL_IDX].uptr = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).Nid_cell); + NBIoTLteCCParams[LTECCPARAMS_N_RB_DL_IDX].uptr = (uint32_t *)&(NBIOTRRC_CONFIGURATION_REQ (msg_p).N_RB_DL); for (int i=0; (i<sizeof(NBIoTLteCCParams)/sizeof(paramdef_t)) && (i<sizeof(NBIoTLteCCCheckParams)/sizeof(checkedparam_t)); i++ ) { - NBIoTLteCCParams[i].chkPptr = &(NBIoTLteCCCheckParams[i]); + NBIoTLteCCParams[i].chkPptr = &(NBIoTLteCCCheckParams[i]); } - config_get( NBIoTLteCCParams,sizeof(NBIoTLteCCParams)/sizeof(paramdef_t),instprefix); - NBIOTRRC_CONFIGURATION_REQ (msg_p).frame_type = config_get_processedint( &(NBIoTLteCCParams[LTECCPARAMS_FRAME_TYPE_IDX]) ); + + config_get( NBIoTLteCCParams,sizeof(NBIoTLteCCParams)/sizeof(paramdef_t),instprefix); + NBIOTRRC_CONFIGURATION_REQ (msg_p).frame_type = config_get_processedint( &(NBIoTLteCCParams[LTECCPARAMS_FRAME_TYPE_IDX]) ); NBIOTRRC_CONFIGURATION_REQ (msg_p).prefix_type = config_get_processedint( &(NBIoTLteCCParams[LTECCPARAMS_PREFIX_TYPE_IDX]) ); NBIOTRRC_CONFIGURATION_REQ (msg_p).prefix_type = config_get_processedint( &(NBIoTLteCCParams[LTECCPARAMS_PREFIX_TYPE_UL_IDX]) ); -return 0; + return 0; } void RCConfig_NbIoT(RAN_CONTEXT_t *RC) { - paramlist_def_t NbIoT_MACRLCParamList = {NBIOT_MACRLCLIST_CONFIG_STRING,NULL,0}; paramlist_def_t NbIoT_L1ParamList = {NBIOT_L1LIST_CONFIG_STRING,NULL,0}; paramlist_def_t NbIoT_ParamList = {NBIOT_RRCLIST_CONFIG_STRING,NULL,0}; - - config_getlist( &NbIoT_ParamList,NULL,0,NULL); RC->nb_nb_iot_rrc_inst = NbIoT_ParamList.numelt; - - - - - config_getlist( &NbIoT_MACRLCParamList,NULL,0, NULL); - RC->nb_nb_iot_macrlc_inst = NbIoT_MACRLCParamList.numelt; - // Get num L1 instances - config_getlist( &NbIoT_L1ParamList,NULL,0, NULL); - RC->nb_nb_iot_L1_inst = NbIoT_L1ParamList.numelt; - + config_getlist( &NbIoT_MACRLCParamList,NULL,0, NULL); + RC->nb_nb_iot_macrlc_inst = NbIoT_MACRLCParamList.numelt; + // Get num L1 instances + config_getlist( &NbIoT_L1ParamList,NULL,0, NULL); + RC->nb_nb_iot_L1_inst = NbIoT_L1ParamList.numelt; } diff --git a/openair2/ENB_APP/enb_config.c b/openair2/ENB_APP/enb_config.c index e1f995a7b541699c4810dfefb5e531ddfbf812a7..5e830af0098d3ac3ee16bd1249a263b47dd03ea8 100644 --- a/openair2/ENB_APP/enb_config.c +++ b/openair2/ENB_APP/enb_config.c @@ -1909,7 +1909,7 @@ int RCconfig_S1( default: { LOG_E(S1AP, "Default I-DRX value in conf file is invalid (%i). Should be 32, 64, 128 or 256. \ - Default DRX set to 32 in MME configuration\n", + Default DRX set to 32 in MME configuration\n", ccparams_lte.pcch_defaultPagingCycle); S1AP_REGISTER_ENB_REQ(msg_p).default_drx = 0; } @@ -1927,7 +1927,9 @@ int RCconfig_S1( if (strcmp(*(S1ParamList.paramarray[l][ENB_MME_IP_ADDRESS_PREFERENCE_IDX].strptr), "ipv4") == 0) { S1AP_REGISTER_ENB_REQ (msg_p).mme_ip_address[l].ipv4 = 1; + S1AP_REGISTER_ENB_REQ (msg_p).mme_ip_address[l].ipv6 = 0; } else if (strcmp(*(S1ParamList.paramarray[l][ENB_MME_IP_ADDRESS_PREFERENCE_IDX].strptr), "ipv6") == 0) { + S1AP_REGISTER_ENB_REQ (msg_p).mme_ip_address[l].ipv4 = 0; S1AP_REGISTER_ENB_REQ (msg_p).mme_ip_address[l].ipv6 = 1; } else if (strcmp(*(S1ParamList.paramarray[l][ENB_MME_IP_ADDRESS_PREFERENCE_IDX].strptr), "no") == 0) { S1AP_REGISTER_ENB_REQ (msg_p).mme_ip_address[l].ipv4 = 1; diff --git a/openair2/ENB_APP/flexran_agent_common.c b/openair2/ENB_APP/flexran_agent_common.c index 1a92c9e2621e37ae028e1ceba277d7357527db7f..19a1394cbd2b844790be33bc89fed5cf98d51c07 100644 --- a/openair2/ENB_APP/flexran_agent_common.c +++ b/openair2/ENB_APP/flexran_agent_common.c @@ -17,10 +17,10 @@ *------------------------------------------------------------------------------- * For more information about the OpenAirInterface (OAI) Software Alliance: * contact@openairinterface.org - */ + */ /*! \file flexran_agent_common.c - * \brief common primitives for all agents + * \brief common primitives for all agents * \author Xenofon Foukas, Mohamed Kassem and Navid Nikaein, shahab SHARIAT BAGHERI * \date 2017 * \version 0.1 @@ -49,18 +49,19 @@ */ int flexran_agent_serialize_message(Protocol__FlexranMessage *msg, void **buf, int *size) { - *size = protocol__flexran_message__get_packed_size(msg); - - *buf = malloc(*size); + if (buf == NULL) goto error; - + + *buf = malloc(*size); + + if (*buf == NULL) + goto error; + protocol__flexran_message__pack(msg, *buf); - return 0; - - error: +error: LOG_E(FLEXRAN_AGENT, "an error occured\n"); // change the com return -1; } @@ -71,12 +72,12 @@ int flexran_agent_serialize_message(Protocol__FlexranMessage *msg, void **buf, i Should be chekced durint Tx/Rx */ int flexran_agent_deserialize_message(void *data, int size, Protocol__FlexranMessage **msg) { *msg = protocol__flexran_message__unpack(NULL, size, data); + if (*msg == NULL) goto error; return 0; - - error: +error: //LOG_E(MAC, "%s: an error occured\n", __FUNCTION__); return -1; } @@ -84,115 +85,120 @@ int flexran_agent_deserialize_message(void *data, int size, Protocol__FlexranMes int flexran_create_header(xid_t xid, Protocol__FlexType type, Protocol__FlexHeader **header) { - *header = malloc(sizeof(Protocol__FlexHeader)); + if(*header == NULL) goto error; - + protocol__flex_header__init(*header); (*header)->version = FLEXRAN_VERSION; - (*header)->has_version = 1; + (*header)->has_version = 1; // check if the type is set (*header)->type = type; (*header)->has_type = 1; (*header)->xid = xid; (*header)->has_xid = 1; return 0; - - error: +error: LOG_E(FLEXRAN_AGENT, "%s: an error occured\n", __FUNCTION__); return -1; } int flexran_agent_hello(mid_t mod_id, const void *params, Protocol__FlexranMessage **msg) { - Protocol__FlexHeader *header = NULL; /*TODO: Need to set random xid or xid from received hello message*/ xid_t xid = 1; - Protocol__FlexHello *hello_msg; hello_msg = malloc(sizeof(Protocol__FlexHello)); + if(hello_msg == NULL) goto error; + protocol__flex_hello__init(hello_msg); if (flexran_create_header(xid, PROTOCOL__FLEX_TYPE__FLPT_HELLO, &header) != 0) goto error; hello_msg->header = header; - *msg = malloc(sizeof(Protocol__FlexranMessage)); + if(*msg == NULL) goto error; - + protocol__flexran_message__init(*msg); (*msg)->msg_case = PROTOCOL__FLEXRAN_MESSAGE__MSG_HELLO_MSG; (*msg)->msg_dir = PROTOCOL__FLEXRAN_DIRECTION__SUCCESSFUL_OUTCOME; (*msg)->has_msg_dir = 1; (*msg)->hello_msg = hello_msg; return 0; - - error: +error: + if(header != NULL) free(header); + if(hello_msg != NULL) free(hello_msg); + if(*msg != NULL) free(*msg); + LOG_E(FLEXRAN_AGENT, "%s: an error occured\n", __FUNCTION__); return -1; } int flexran_agent_destroy_hello(Protocol__FlexranMessage *msg) { - if(msg->msg_case != PROTOCOL__FLEXRAN_MESSAGE__MSG_HELLO_MSG) goto error; - + free(msg->hello_msg->header); free(msg->hello_msg); free(msg); return 0; - - error: +error: LOG_E(FLEXRAN_AGENT, "%s: an error occured\n", __FUNCTION__); return -1; } -int flexran_agent_echo_request(mid_t mod_id, const void* params, Protocol__FlexranMessage **msg) { +int flexran_agent_echo_request(mid_t mod_id, const void *params, Protocol__FlexranMessage **msg) { Protocol__FlexHeader *header = NULL; /*TODO: Need to set a random xid*/ xid_t xid = 1; - Protocol__FlexEchoRequest *echo_request_msg = NULL; echo_request_msg = malloc(sizeof(Protocol__FlexEchoRequest)); + if(echo_request_msg == NULL) goto error; + protocol__flex_echo_request__init(echo_request_msg); if (flexran_create_header(xid, PROTOCOL__FLEX_TYPE__FLPT_ECHO_REQUEST, &header) != 0) goto error; echo_request_msg->header = header; - *msg = malloc(sizeof(Protocol__FlexranMessage)); + if(*msg == NULL) goto error; + protocol__flexran_message__init(*msg); (*msg)->msg_case = PROTOCOL__FLEXRAN_MESSAGE__MSG_ECHO_REQUEST_MSG; (*msg)->msg_dir = PROTOCOL__FLEXRAN_DIRECTION__INITIATING_MESSAGE; (*msg)->echo_request_msg = echo_request_msg; return 0; +error: - error: if(header != NULL) free(header); + if(echo_request_msg != NULL) free(echo_request_msg); + if(*msg != NULL) free(*msg); + //LOG_E(MAC, "%s: an error occured\n", __FUNCTION__); return -1; } @@ -201,13 +207,12 @@ int flexran_agent_echo_request(mid_t mod_id, const void* params, Protocol__Flexr int flexran_agent_destroy_echo_request(Protocol__FlexranMessage *msg) { if(msg->msg_case != PROTOCOL__FLEXRAN_MESSAGE__MSG_ECHO_REQUEST_MSG) goto error; - + free(msg->echo_request_msg->header); free(msg->echo_request_msg); free(msg); return 0; - - error: +error: LOG_E(FLEXRAN_AGENT, "%s: an error occured\n", __FUNCTION__); return -1; } @@ -215,41 +220,45 @@ int flexran_agent_destroy_echo_request(Protocol__FlexranMessage *msg) { int flexran_agent_echo_reply(mid_t mod_id, const void *params, Protocol__FlexranMessage **msg) { - xid_t xid; Protocol__FlexHeader *header = NULL; Protocol__FlexranMessage *input = (Protocol__FlexranMessage *)params; Protocol__FlexEchoRequest *echo_req = input->echo_request_msg; xid = (echo_req->header)->xid; - Protocol__FlexEchoReply *echo_reply_msg = NULL; echo_reply_msg = malloc(sizeof(Protocol__FlexEchoReply)); + if(echo_reply_msg == NULL) goto error; + protocol__flex_echo_reply__init(echo_reply_msg); if (flexran_create_header(xid, PROTOCOL__FLEX_TYPE__FLPT_ECHO_REPLY, &header) != 0) goto error; echo_reply_msg->header = header; - *msg = malloc(sizeof(Protocol__FlexranMessage)); + if(*msg == NULL) goto error; + protocol__flexran_message__init(*msg); (*msg)->msg_case = PROTOCOL__FLEXRAN_MESSAGE__MSG_ECHO_REPLY_MSG; (*msg)->msg_dir = PROTOCOL__FLEXRAN_DIRECTION__SUCCESSFUL_OUTCOME; (*msg)->has_msg_dir = 1; (*msg)->echo_reply_msg = echo_reply_msg; return 0; +error: - error: if(header != NULL) free(header); + if(echo_reply_msg != NULL) free(echo_reply_msg); + if(*msg != NULL) free(*msg); + LOG_E(FLEXRAN_AGENT, "%s: an error occured\n", __FUNCTION__); return -1; } @@ -258,13 +267,12 @@ int flexran_agent_echo_reply(mid_t mod_id, const void *params, Protocol__Flexran int flexran_agent_destroy_echo_reply(Protocol__FlexranMessage *msg) { if(msg->msg_case != PROTOCOL__FLEXRAN_MESSAGE__MSG_ECHO_REPLY_MSG) goto error; - + free(msg->echo_reply_msg->header); free(msg->echo_reply_msg); free(msg); return 0; - - error: +error: LOG_E(FLEXRAN_AGENT, "%s: an error occured\n", __FUNCTION__); return -1; } @@ -273,46 +281,56 @@ int flexran_agent_destroy_echo_reply(Protocol__FlexranMessage *msg) { int flexran_agent_destroy_enb_config_reply(Protocol__FlexranMessage *msg) { if(msg->msg_case != PROTOCOL__FLEXRAN_MESSAGE__MSG_ENB_CONFIG_REPLY_MSG) goto error; + free(msg->enb_config_reply_msg->header); int i, j; Protocol__FlexEnbConfigReply *reply = msg->enb_config_reply_msg; - - for(i = 0; i < reply->n_cell_config;i++) { + + for(i = 0; i < reply->n_cell_config; i++) { free(reply->cell_config[i]->mbsfn_subframe_config_rfoffset); free(reply->cell_config[i]->mbsfn_subframe_config_rfperiod); free(reply->cell_config[i]->mbsfn_subframe_config_sfalloc); + if (reply->cell_config[i]->si_config != NULL) { - for(j = 0; j < reply->cell_config[i]->si_config->n_si_message;j++){ - free(reply->cell_config[i]->si_config->si_message[j]); + for(j = 0; j < reply->cell_config[i]->si_config->n_si_message; j++) { + free(reply->cell_config[i]->si_config->si_message[j]); } + free(reply->cell_config[i]->si_config->si_message); free(reply->cell_config[i]->si_config); } + if (reply->cell_config[i]->slice_config != NULL) { for (j = 0; j < reply->cell_config[i]->slice_config->n_dl; ++j) { if (reply->cell_config[i]->slice_config->dl[j]->n_sorting > 0) free(reply->cell_config[i]->slice_config->dl[j]->sorting); + free(reply->cell_config[i]->slice_config->dl[j]->scheduler_name); free(reply->cell_config[i]->slice_config->dl[j]); } + free(reply->cell_config[i]->slice_config->dl); + for (j = 0; j < reply->cell_config[i]->slice_config->n_ul; ++j) { if (reply->cell_config[i]->slice_config->ul[j]->n_sorting > 0) free(reply->cell_config[i]->slice_config->ul[j]->sorting); + free(reply->cell_config[i]->slice_config->ul[j]->scheduler_name); free(reply->cell_config[i]->slice_config->ul[j]); } + free(reply->cell_config[i]->slice_config->ul); free(reply->cell_config[i]->slice_config); } + free(reply->cell_config[i]); } + free(reply->cell_config); free(reply); free(msg); - return 0; - error: +error: //LOG_E(FLEXRAN_AGENT, "%s: an error occured\n", __FUNCTION__); return -1; } @@ -320,20 +338,21 @@ int flexran_agent_destroy_enb_config_reply(Protocol__FlexranMessage *msg) { int flexran_agent_destroy_ue_config_reply(Protocol__FlexranMessage *msg) { if(msg->msg_case != PROTOCOL__FLEXRAN_MESSAGE__MSG_UE_CONFIG_REPLY_MSG) goto error; + free(msg->ue_config_reply_msg->header); int i; Protocol__FlexUeConfigReply *reply = msg->ue_config_reply_msg; - - for(i = 0; i < reply->n_ue_config;i++){ + + for(i = 0; i < reply->n_ue_config; i++) { free(reply->ue_config[i]->capabilities); free(reply->ue_config[i]); } + free(reply->ue_config); free(reply); free(msg); - return 0; - error: +error: //LOG_E(FLEXRAN_AGENT, "%s: an error occured\n", __FUNCTION__); return -1; } @@ -344,18 +363,21 @@ int flexran_agent_destroy_lc_config_reply(Protocol__FlexranMessage *msg) { int i, j; free(msg->lc_config_reply_msg->header); + for (i = 0; i < msg->lc_config_reply_msg->n_lc_ue_config; i++) { for (j = 0; j < msg->lc_config_reply_msg->lc_ue_config[i]->n_lc_config; j++) { free(msg->lc_config_reply_msg->lc_ue_config[i]->lc_config[j]); } + free(msg->lc_config_reply_msg->lc_ue_config[i]->lc_config); free(msg->lc_config_reply_msg->lc_ue_config[i]); } + free(msg->lc_config_reply_msg->lc_ue_config); free(msg->lc_config_reply_msg); free(msg); return 0; - error: +error: //LOG_E(FLEXRAN_AGENT, "%s: an error occured\n", __FUNCTION__); return -1; } @@ -364,12 +386,12 @@ int flexran_agent_destroy_lc_config_reply(Protocol__FlexranMessage *msg) { int flexran_agent_destroy_enb_config_request(Protocol__FlexranMessage *msg) { if(msg->msg_case != PROTOCOL__FLEXRAN_MESSAGE__MSG_ENB_CONFIG_REQUEST_MSG) goto error; + free(msg->enb_config_request_msg->header); free(msg->enb_config_request_msg); free(msg); return 0; - - error: +error: //LOG_E(FLEXRAN_AGENT, "%s: an error occured\n", __FUNCTION__); return -1; } @@ -386,24 +408,22 @@ int flexran_agent_destroy_lc_config_request(Protocol__FlexranMessage *msg) { // call this function to start a nanosecond-resolution timer struct timespec timer_start(void) { - struct timespec start_time; - clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &start_time); - return start_time; + struct timespec start_time; + clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &start_time); + return start_time; } // call this function to end a timer, returning nanoseconds elapsed as a long -long timer_end(struct timespec start_time){ - struct timespec end_time; - clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &end_time); - long diffInNanos = end_time.tv_nsec - start_time.tv_nsec; - return diffInNanos; +long timer_end(struct timespec start_time) { + struct timespec end_time; + clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &end_time); + long diffInNanos = end_time.tv_nsec - start_time.tv_nsec; + return diffInNanos; } int flexran_agent_control_delegation(mid_t mod_id, const void *params, Protocol__FlexranMessage **msg) { - Protocol__FlexranMessage *input = (Protocol__FlexranMessage *)params; Protocol__FlexControlDelegation *control_delegation_msg = input->control_delegation_msg; - // struct timespec vartime = timer_start(); //Write the payload lib into a file in the cache and load the lib char lib_name[120]; @@ -411,14 +431,13 @@ int flexran_agent_control_delegation(mid_t mod_id, const void *params, Protocol_ snprintf(lib_name, sizeof(lib_name), "/%s.so", control_delegation_msg->name); strcpy(target, RC.flexran[mod_id]->cache_name); strcat(target, lib_name); - FILE *f; f = fopen(target, "wb"); + if (f) { fwrite(control_delegation_msg->payload.data, control_delegation_msg->payload.len, 1, f); fclose(f); - } - else { + } else { LOG_W(FLEXRAN_AGENT, "[%d] can not write control delegation data to %s\n", mod_id, target); } @@ -426,7 +445,6 @@ int flexran_agent_control_delegation(mid_t mod_id, const void *params, Protocol_ // long time_elapsed_nanos = timer_end(vartime); *msg = NULL; return 0; - } int flexran_agent_destroy_control_delegation(Protocol__FlexranMessage *msg) { @@ -437,9 +455,7 @@ int flexran_agent_destroy_control_delegation(Protocol__FlexranMessage *msg) { int flexran_agent_reconfiguration(mid_t mod_id, const void *params, Protocol__FlexranMessage **msg) { Protocol__FlexranMessage *input = (Protocol__FlexranMessage *)params; Protocol__FlexAgentReconfiguration *agent_reconfiguration_msg = input->agent_reconfiguration_msg; - apply_reconfiguration_policy(mod_id, agent_reconfiguration_msg->policy, strlen(agent_reconfiguration_msg->policy)); - *msg = NULL; return 0; } @@ -451,126 +467,133 @@ int flexran_agent_destroy_agent_reconfiguration(Protocol__FlexranMessage *msg) { int flexran_agent_lc_config_reply(mid_t mod_id, const void *params, Protocol__FlexranMessage **msg) { - xid_t xid; Protocol__FlexHeader *header = NULL; Protocol__FlexranMessage *input = (Protocol__FlexranMessage *)params; Protocol__FlexLcConfigRequest *lc_config_request_msg = input->lc_config_request_msg; xid = (lc_config_request_msg->header)->xid; - int i, j; int UE_id; - Protocol__FlexLcConfigReply *lc_config_reply_msg; lc_config_reply_msg = malloc(sizeof(Protocol__FlexLcConfigReply)); + if(lc_config_reply_msg == NULL) goto error; + protocol__flex_lc_config_reply__init(lc_config_reply_msg); if(flexran_create_header(xid, PROTOCOL__FLEX_TYPE__FLPT_GET_LC_CONFIG_REPLY, &header) != 0) goto error; lc_config_reply_msg->header = header; - lc_config_reply_msg->n_lc_ue_config = flexran_get_num_ues(mod_id); - Protocol__FlexLcUeConfig **lc_ue_config; + if (lc_config_reply_msg->n_lc_ue_config > 0) { lc_ue_config = malloc(sizeof(Protocol__FlexLcUeConfig *) * lc_config_reply_msg->n_lc_ue_config); + if (lc_ue_config == NULL) { goto error; } + // Fill the config for each UE for (i = 0; i < lc_config_reply_msg->n_lc_ue_config; i++) { lc_ue_config[i] = malloc(sizeof(Protocol__FlexLcUeConfig)); protocol__flex_lc_ue_config__init(lc_ue_config[i]); - UE_id = flexran_get_ue_id(mod_id, i); - lc_ue_config[i]->has_rnti = 1; lc_ue_config[i]->rnti = flexran_get_ue_crnti(mod_id, UE_id); - //TODO: Set the number of LC configurations that will be reported for this UE //Set this according to the current state of the UE. This is only a temporary fix int status = 0; status = mac_eNB_get_rrc_status(mod_id, flexran_get_ue_crnti(mod_id, UE_id)); + /* TODO needs to be revised and appropriate API to be implemented */ if (status < RRC_CONNECTED) { - lc_ue_config[i]->n_lc_config = 0; + lc_ue_config[i]->n_lc_config = 0; } else if (status == RRC_CONNECTED) { - lc_ue_config[i]->n_lc_config = 1; + lc_ue_config[i]->n_lc_config = 1; } else { - lc_ue_config[i]->n_lc_config = 3; + lc_ue_config[i]->n_lc_config = 3; } Protocol__FlexLcConfig **lc_config; + if (lc_ue_config[i]->n_lc_config > 0) { - lc_config = malloc(sizeof(Protocol__FlexLcConfig *) * lc_ue_config[i]->n_lc_config); - if (lc_config == NULL) { - goto error; - } - for (j = 0; j < lc_ue_config[i]->n_lc_config; j++) { - lc_config[j] = malloc(sizeof(Protocol__FlexLcConfig)); - protocol__flex_lc_config__init(lc_config[j]); - - lc_config[j]->has_lcid = 1; - lc_config[j]->lcid = j+1; - - int lcg = flexran_get_lcg(mod_id, UE_id, j+1); - if (lcg >= 0 && lcg <= 3) { - lc_config[j]->has_lcg = 1; - lc_config[j]->lcg = flexran_get_lcg(mod_id, UE_id, j+1); - } - - lc_config[j]->has_direction = 1; - lc_config[j]->direction = flexran_get_direction(UE_id, j+1); - //TODO: Bearer type. One of FLQBT_* values. Currently only default bearer supported - lc_config[j]->has_qos_bearer_type = 1; - lc_config[j]->qos_bearer_type = PROTOCOL__FLEX_QOS_BEARER_TYPE__FLQBT_NON_GBR; - - //TODO: Set the QCI defined in TS 23.203, coded as defined in TS 36.413 - // One less than the actual QCI value. Needs to be generalized - lc_config[j]->has_qci = 1; - lc_config[j]->qci = 1; - if (lc_config[j]->direction == PROTOCOL__FLEX_QOS_BEARER_TYPE__FLQBT_GBR) { + lc_config = malloc(sizeof(Protocol__FlexLcConfig *) * lc_ue_config[i]->n_lc_config); + + if (lc_config == NULL) { + goto error; + } + + for (j = 0; j < lc_ue_config[i]->n_lc_config; j++) { + lc_config[j] = malloc(sizeof(Protocol__FlexLcConfig)); + protocol__flex_lc_config__init(lc_config[j]); + lc_config[j]->has_lcid = 1; + lc_config[j]->lcid = j+1; + int lcg = flexran_get_lcg(mod_id, UE_id, j+1); + + if (lcg >= 0 && lcg <= 3) { + lc_config[j]->has_lcg = 1; + lc_config[j]->lcg = flexran_get_lcg(mod_id, UE_id, j+1); + } + + lc_config[j]->has_direction = 1; + lc_config[j]->direction = flexran_get_direction(UE_id, j+1); + //TODO: Bearer type. One of FLQBT_* values. Currently only default bearer supported + lc_config[j]->has_qos_bearer_type = 1; + lc_config[j]->qos_bearer_type = PROTOCOL__FLEX_QOS_BEARER_TYPE__FLQBT_NON_GBR; + //TODO: Set the QCI defined in TS 23.203, coded as defined in TS 36.413 + // One less than the actual QCI value. Needs to be generalized + lc_config[j]->has_qci = 1; + lc_config[j]->qci = 1; + + if (lc_config[j]->direction == PROTOCOL__FLEX_QOS_BEARER_TYPE__FLQBT_GBR) { /* TODO all of the need to be taken from API */ - //TODO: Set the max bitrate (UL) - lc_config[j]->has_e_rab_max_bitrate_ul = 0; - lc_config[j]->e_rab_max_bitrate_ul = 0; - //TODO: Set the max bitrate (DL) - lc_config[j]->has_e_rab_max_bitrate_dl = 0; - lc_config[j]->e_rab_max_bitrate_dl = 0; - //TODO: Set the guaranteed bitrate (UL) - lc_config[j]->has_e_rab_guaranteed_bitrate_ul = 0; - lc_config[j]->e_rab_guaranteed_bitrate_ul = 0; - //TODO: Set the guaranteed bitrate (DL) - lc_config[j]->has_e_rab_guaranteed_bitrate_dl = 0; - lc_config[j]->e_rab_guaranteed_bitrate_dl = 0; - } - } - lc_ue_config[i]->lc_config = lc_config; + //TODO: Set the max bitrate (UL) + lc_config[j]->has_e_rab_max_bitrate_ul = 0; + lc_config[j]->e_rab_max_bitrate_ul = 0; + //TODO: Set the max bitrate (DL) + lc_config[j]->has_e_rab_max_bitrate_dl = 0; + lc_config[j]->e_rab_max_bitrate_dl = 0; + //TODO: Set the guaranteed bitrate (UL) + lc_config[j]->has_e_rab_guaranteed_bitrate_ul = 0; + lc_config[j]->e_rab_guaranteed_bitrate_ul = 0; + //TODO: Set the guaranteed bitrate (DL) + lc_config[j]->has_e_rab_guaranteed_bitrate_dl = 0; + lc_config[j]->e_rab_guaranteed_bitrate_dl = 0; + } + } + + lc_ue_config[i]->lc_config = lc_config; } } // end for UE + lc_config_reply_msg->lc_ue_config = lc_ue_config; } // lc_config_reply_msg->n_lc_ue_config > 0 + *msg = malloc(sizeof(Protocol__FlexranMessage)); + if (*msg == NULL) goto error; + protocol__flexran_message__init(*msg); (*msg)->msg_case = PROTOCOL__FLEXRAN_MESSAGE__MSG_LC_CONFIG_REPLY_MSG; (*msg)->msg_dir = PROTOCOL__FLEXRAN_DIRECTION__SUCCESSFUL_OUTCOME; (*msg)->lc_config_reply_msg = lc_config_reply_msg; - return 0; +error: - error: // TODO: Need to make proper error handling if (header != NULL) free(header); + if (lc_config_reply_msg != NULL) free(lc_config_reply_msg); + if(*msg != NULL) free(*msg); + //LOG_E(FLEXRAN_AGENT, "%s: an error occured\n", __FUNCTION__); return -1; } @@ -582,39 +605,38 @@ int flexran_agent_lc_config_reply(mid_t mod_id, const void *params, Protocol__Fl */ int flexran_agent_ue_config_reply(mid_t mod_id, const void *params, Protocol__FlexranMessage **msg) { - xid_t xid; Protocol__FlexHeader *header = NULL; Protocol__FlexranMessage *input = (Protocol__FlexranMessage *)params; Protocol__FlexUeConfigRequest *ue_config_request_msg = input->ue_config_request_msg; xid = (ue_config_request_msg->header)->xid; - int i; int UE_id; - Protocol__FlexUeConfigReply *ue_config_reply_msg; ue_config_reply_msg = malloc(sizeof(Protocol__FlexUeConfigReply)); + if(ue_config_reply_msg == NULL) goto error; + protocol__flex_ue_config_reply__init(ue_config_reply_msg); if(flexran_create_header(xid, PROTOCOL__FLEX_TYPE__FLPT_GET_UE_CONFIG_REPLY, &header) != 0) goto error; ue_config_reply_msg->header = header; - ue_config_reply_msg->n_ue_config = flexran_get_num_ues(mod_id); - Protocol__FlexUeConfig **ue_config; + if (ue_config_reply_msg->n_ue_config > 0) { ue_config = malloc(sizeof(Protocol__FlexUeConfig *) * ue_config_reply_msg->n_ue_config); + if (ue_config == NULL) { goto error; } + for (i = 0; i < ue_config_reply_msg->n_ue_config; i++) { ue_config[i] = malloc(sizeof(Protocol__FlexUeConfig)); protocol__flex_ue_config__init(ue_config[i]); - UE_id = flexran_get_ue_id(mod_id, i); ue_config[i]->rnti = flexran_get_ue_crnti(mod_id, UE_id); ue_config[i]->has_rnti = 1; @@ -636,12 +658,13 @@ int flexran_agent_ue_config_reply(mid_t mod_id, const void *params, Protocol__Fl ue_config[i]->meas_gap_config_pattern = flexran_get_meas_gap_config(mod_id, UE_id); ue_config[i]->has_meas_gap_config_pattern = 1; } - + if (ue_config[i]->has_meas_gap_config_pattern == 1 && - ue_config[i]->meas_gap_config_pattern != PROTOCOL__FLEX_MEAS_GAP_CONFIG_PATTERN__FLMGCP_OFF) { - ue_config[i]->meas_gap_config_sf_offset = flexran_get_meas_gap_config_offset(mod_id, UE_id); - ue_config[i]->has_meas_gap_config_sf_offset = 1; + ue_config[i]->meas_gap_config_pattern != PROTOCOL__FLEX_MEAS_GAP_CONFIG_PATTERN__FLMGCP_OFF) { + ue_config[i]->meas_gap_config_sf_offset = flexran_get_meas_gap_config_offset(mod_id, UE_id); + ue_config[i]->has_meas_gap_config_sf_offset = 1; } + //TODO: Set the SPS configuration (Optional) //Not supported for noe, so we do not set it @@ -652,16 +675,14 @@ int flexran_agent_ue_config_reply(mid_t mod_id, const void *params, Protocol__Fl //We do not set it for now if (flexran_get_ue_transmission_mode(mod_id, UE_id) != -1) { - ue_config[i]->transmission_mode = flexran_get_ue_transmission_mode(mod_id, UE_id); - ue_config[i]->has_transmission_mode = 1; + ue_config[i]->transmission_mode = flexran_get_ue_transmission_mode(mod_id, UE_id); + ue_config[i]->has_transmission_mode = 1; } ue_config[i]->ue_aggregated_max_bitrate_ul = flexran_get_ue_aggregated_max_bitrate_ul(mod_id, UE_id); ue_config[i]->has_ue_aggregated_max_bitrate_ul = 1; - ue_config[i]->ue_aggregated_max_bitrate_dl = flexran_get_ue_aggregated_max_bitrate_dl(mod_id, UE_id); ue_config[i]->has_ue_aggregated_max_bitrate_dl = 1; - Protocol__FlexUeCapabilities *capabilities; capabilities = malloc(sizeof(Protocol__FlexUeCapabilities)); protocol__flex_ue_capabilities__init(capabilities); @@ -679,18 +700,18 @@ int flexran_agent_ue_config_reply(mid_t mod_id, const void *params, Protocol__Fl ue_config[i]->capabilities = capabilities; if (flexran_get_ue_transmission_antenna(mod_id, UE_id) != -1) { - ue_config[i]->has_ue_transmission_antenna = 1; - ue_config[i]->ue_transmission_antenna = flexran_get_ue_transmission_antenna(mod_id, UE_id); + ue_config[i]->has_ue_transmission_antenna = 1; + ue_config[i]->ue_transmission_antenna = flexran_get_ue_transmission_antenna(mod_id, UE_id); } if (flexran_get_tti_bundling(mod_id, UE_id) != -1) { - ue_config[i]->has_tti_bundling = 1; - ue_config[i]->tti_bundling = flexran_get_tti_bundling(mod_id, UE_id); + ue_config[i]->has_tti_bundling = 1; + ue_config[i]->tti_bundling = flexran_get_tti_bundling(mod_id, UE_id); } if (flexran_get_maxHARQ_TX(mod_id, UE_id) != -1) { - ue_config[i]->has_max_harq_tx = 1; - ue_config[i]->max_harq_tx = flexran_get_maxHARQ_TX(mod_id, UE_id); + ue_config[i]->has_max_harq_tx = 1; + ue_config[i]->max_harq_tx = flexran_get_maxHARQ_TX(mod_id, UE_id); } if (flexran_get_beta_offset_ack_index(mod_id, UE_id) != -1) { @@ -699,86 +720,95 @@ int flexran_agent_ue_config_reply(mid_t mod_id, const void *params, Protocol__Fl } if (flexran_get_beta_offset_ri_index(mod_id, UE_id) != -1) { - ue_config[i]->has_beta_offset_ri_index = 1; + ue_config[i]->has_beta_offset_ri_index = 1; ue_config[i]->beta_offset_ri_index = flexran_get_beta_offset_ri_index(mod_id, UE_id); } if (flexran_get_beta_offset_cqi_index(mod_id, UE_id) != -1) { - ue_config[i]->has_beta_offset_cqi_index = 1; - ue_config[i]->beta_offset_cqi_index = flexran_get_beta_offset_cqi_index(mod_id, UE_id); + ue_config[i]->has_beta_offset_cqi_index = 1; + ue_config[i]->beta_offset_cqi_index = flexran_get_beta_offset_cqi_index(mod_id, UE_id); } - + /* assume primary carrier */ if (flexran_get_ack_nack_simultaneous_trans(mod_id, UE_id, 0) != -1) { - ue_config[i]->has_ack_nack_simultaneous_trans = 1; - ue_config[i]->ack_nack_simultaneous_trans = flexran_get_ack_nack_simultaneous_trans(mod_id, UE_id, 0); + ue_config[i]->has_ack_nack_simultaneous_trans = 1; + ue_config[i]->ack_nack_simultaneous_trans = flexran_get_ack_nack_simultaneous_trans(mod_id, UE_id, 0); } - + if (flexran_get_simultaneous_ack_nack_cqi(mod_id, UE_id) != -1) { - ue_config[i]->has_simultaneous_ack_nack_cqi = 1; - ue_config[i]->simultaneous_ack_nack_cqi = flexran_get_simultaneous_ack_nack_cqi(mod_id, UE_id); + ue_config[i]->has_simultaneous_ack_nack_cqi = 1; + ue_config[i]->simultaneous_ack_nack_cqi = flexran_get_simultaneous_ack_nack_cqi(mod_id, UE_id); } - + if (flexran_get_aperiodic_cqi_rep_mode(mod_id, UE_id) != -1) { - ue_config[i]->has_aperiodic_cqi_rep_mode = 1; - int mode = flexran_get_aperiodic_cqi_rep_mode(mod_id, UE_id); - if (mode > 4) { - ue_config[i]->aperiodic_cqi_rep_mode = PROTOCOL__FLEX_APERIODIC_CQI_REPORT_MODE__FLACRM_NONE; - } else { - ue_config[i]->aperiodic_cqi_rep_mode = mode; - } + ue_config[i]->has_aperiodic_cqi_rep_mode = 1; + int mode = flexran_get_aperiodic_cqi_rep_mode(mod_id, UE_id); + + if (mode > 4) { + ue_config[i]->aperiodic_cqi_rep_mode = PROTOCOL__FLEX_APERIODIC_CQI_REPORT_MODE__FLACRM_NONE; + } else { + ue_config[i]->aperiodic_cqi_rep_mode = mode; + } } - + if (flexran_get_tdd_ack_nack_feedback_mode(mod_id, UE_id) != -1) { - ue_config[i]->has_tdd_ack_nack_feedback = 1; - ue_config[i]->tdd_ack_nack_feedback = flexran_get_tdd_ack_nack_feedback_mode(mod_id, UE_id); + ue_config[i]->has_tdd_ack_nack_feedback = 1; + ue_config[i]->tdd_ack_nack_feedback = flexran_get_tdd_ack_nack_feedback_mode(mod_id, UE_id); } - + if(flexran_get_ack_nack_repetition_factor(mod_id, UE_id) != -1) { - ue_config[i]->has_ack_nack_repetition_factor = 1; - ue_config[i]->ack_nack_repetition_factor = flexran_get_ack_nack_repetition_factor(mod_id, UE_id); + ue_config[i]->has_ack_nack_repetition_factor = 1; + ue_config[i]->ack_nack_repetition_factor = flexran_get_ack_nack_repetition_factor(mod_id, UE_id); } - + if (flexran_get_extended_bsr_size(mod_id, UE_id) != -1) { - ue_config[i]->has_extended_bsr_size = 1; - ue_config[i]->extended_bsr_size = flexran_get_extended_bsr_size(mod_id, UE_id); + ue_config[i]->has_extended_bsr_size = 1; + ue_config[i]->extended_bsr_size = flexran_get_extended_bsr_size(mod_id, UE_id); } + //TODO: Set carrier aggregation support (boolean) ue_config[i]->has_ca_support = 0; ue_config[i]->ca_support = 0; - ue_config[i]->has_pcell_carrier_index = 1; ue_config[i]->pcell_carrier_index = UE_PCCID(mod_id, UE_id); - if(ue_config[i]->has_ca_support){ - //TODO: Set cross carrier scheduling support (boolean) - ue_config[i]->has_cross_carrier_sched_support = 0; - ue_config[i]->cross_carrier_sched_support = 0; - //TODO: Set secondary cells configuration - // We do not set it for now. No carrier aggregation support - //TODO: Set deactivation timer for secondary cell - ue_config[i]->has_scell_deactivation_timer = 0; - ue_config[i]->scell_deactivation_timer = 0; + + if(ue_config[i]->has_ca_support) { + //TODO: Set cross carrier scheduling support (boolean) + ue_config[i]->has_cross_carrier_sched_support = 0; + ue_config[i]->cross_carrier_sched_support = 0; + //TODO: Set secondary cells configuration + // We do not set it for now. No carrier aggregation support + //TODO: Set deactivation timer for secondary cell + ue_config[i]->has_scell_deactivation_timer = 0; + ue_config[i]->scell_deactivation_timer = 0; } } + ue_config_reply_msg->ue_config = ue_config; } + *msg = malloc(sizeof(Protocol__FlexranMessage)); + if (*msg == NULL) goto error; + protocol__flexran_message__init(*msg); (*msg)->msg_case = PROTOCOL__FLEXRAN_MESSAGE__MSG_UE_CONFIG_REPLY_MSG; (*msg)->msg_dir = PROTOCOL__FLEXRAN_DIRECTION__SUCCESSFUL_OUTCOME; (*msg)->ue_config_reply_msg = ue_config_reply_msg; return 0; +error: - error: // TODO: Need to make proper error handling if (header != NULL) free(header); + if (ue_config_reply_msg != NULL) free(ue_config_reply_msg); + if(*msg != NULL) free(*msg); + //LOG_E(FLEXRAN_AGENT, "%s: an error occured\n", __FUNCTION__); return -1; } @@ -790,173 +820,169 @@ int flexran_agent_ue_config_reply(mid_t mod_id, const void *params, Protocol__Fl * ************************************ */ -int flexran_agent_enb_config_request(mid_t mod_id, const void* params, Protocol__FlexranMessage **msg) { - - Protocol__FlexHeader *header = NULL; - xid_t xid = 1; - - Protocol__FlexEnbConfigRequest *enb_config_request_msg; - enb_config_request_msg = malloc(sizeof(Protocol__FlexEnbConfigRequest)); - if(enb_config_request_msg == NULL) - goto error; - protocol__flex_enb_config_request__init(enb_config_request_msg); - - if(flexran_create_header(xid,PROTOCOL__FLEX_TYPE__FLPT_GET_ENB_CONFIG_REQUEST, &header) != 0) - goto error; - - enb_config_request_msg->header = header; - - *msg = malloc(sizeof(Protocol__FlexranMessage)); - if(*msg == NULL) - goto error; - - protocol__flexran_message__init(*msg); - (*msg)->msg_case = PROTOCOL__FLEXRAN_MESSAGE__MSG_ENB_CONFIG_REQUEST_MSG; - (*msg)->msg_dir = PROTOCOL__FLEXRAN_DIRECTION__INITIATING_MESSAGE; - (*msg)->enb_config_request_msg = enb_config_request_msg; - return 0; - - error: - // TODO: Need to make proper error handling - if (header != NULL) - free(header); - if (enb_config_request_msg != NULL) - free(enb_config_request_msg); - if(*msg != NULL) - free(*msg); - //LOG_E(MAC, "%s: an error occured\n", __FUNCTION__); - return -1; +int flexran_agent_enb_config_request(mid_t mod_id, const void *params, Protocol__FlexranMessage **msg) { + Protocol__FlexHeader *header = NULL; + xid_t xid = 1; + Protocol__FlexEnbConfigRequest *enb_config_request_msg; + enb_config_request_msg = malloc(sizeof(Protocol__FlexEnbConfigRequest)); + + if(enb_config_request_msg == NULL) + goto error; + + protocol__flex_enb_config_request__init(enb_config_request_msg); + + if(flexran_create_header(xid,PROTOCOL__FLEX_TYPE__FLPT_GET_ENB_CONFIG_REQUEST, &header) != 0) + goto error; + + enb_config_request_msg->header = header; + *msg = malloc(sizeof(Protocol__FlexranMessage)); + + if(*msg == NULL) + goto error; + + protocol__flexran_message__init(*msg); + (*msg)->msg_case = PROTOCOL__FLEXRAN_MESSAGE__MSG_ENB_CONFIG_REQUEST_MSG; + (*msg)->msg_dir = PROTOCOL__FLEXRAN_DIRECTION__INITIATING_MESSAGE; + (*msg)->enb_config_request_msg = enb_config_request_msg; + return 0; +error: + + // TODO: Need to make proper error handling + if (header != NULL) + free(header); + + if (enb_config_request_msg != NULL) + free(enb_config_request_msg); + + if(*msg != NULL) + free(*msg); + + //LOG_E(MAC, "%s: an error occured\n", __FUNCTION__); + return -1; } int flexran_agent_enb_config_reply(mid_t mod_id, const void *params, Protocol__FlexranMessage **msg) { - xid_t xid; Protocol__FlexHeader *header = NULL; Protocol__FlexranMessage *input = (Protocol__FlexranMessage *)params; Protocol__FlexEnbConfigRequest *enb_config_req_msg = input->enb_config_request_msg; xid = (enb_config_req_msg->header)->xid; - int i, j; - Protocol__FlexEnbConfigReply *enb_config_reply_msg; enb_config_reply_msg = malloc(sizeof(Protocol__FlexEnbConfigReply)); + if(enb_config_reply_msg == NULL) goto error; + protocol__flex_enb_config_reply__init(enb_config_reply_msg); if(flexran_create_header(xid, PROTOCOL__FLEX_TYPE__FLPT_GET_ENB_CONFIG_REPLY, &header) != 0) goto error; - - enb_config_reply_msg->header = header; + enb_config_reply_msg->header = header; enb_config_reply_msg->enb_id = RC.flexran[mod_id]->agent_id; enb_config_reply_msg->has_enb_id = 1; - enb_config_reply_msg->n_cell_config = MAX_NUM_CCs; - Protocol__FlexCellConfig **cell_conf; - if(enb_config_reply_msg->n_cell_config > 0){ + + if(enb_config_reply_msg->n_cell_config > 0) { cell_conf = malloc(sizeof(Protocol__FlexCellConfig *) * enb_config_reply_msg->n_cell_config); + if(cell_conf == NULL) goto error; - for(i = 0; i < enb_config_reply_msg->n_cell_config; i++){ + + for(i = 0; i < enb_config_reply_msg->n_cell_config; i++) { cell_conf[i] = malloc(sizeof(Protocol__FlexCellConfig)); protocol__flex_cell_config__init(cell_conf[i]); - cell_conf[i]->phy_cell_id = flexran_get_cell_id(mod_id,i); cell_conf[i]->has_phy_cell_id = 1; - cell_conf[i]->cell_id = i; cell_conf[i]->has_cell_id = 1; - cell_conf[i]->pusch_hopping_offset = flexran_get_hopping_offset(mod_id,i); cell_conf[i]->has_pusch_hopping_offset = 1; if (flexran_get_hopping_mode(mod_id,i) == 0) { - cell_conf[i]->hopping_mode = PROTOCOL__FLEX_HOPPING_MODE__FLHM_INTER; + cell_conf[i]->hopping_mode = PROTOCOL__FLEX_HOPPING_MODE__FLHM_INTER; } else if(flexran_get_hopping_mode(mod_id,i) == 1) { - cell_conf[i]->hopping_mode = PROTOCOL__FLEX_HOPPING_MODE__FLHM_INTERINTRA; + cell_conf[i]->hopping_mode = PROTOCOL__FLEX_HOPPING_MODE__FLHM_INTERINTRA; } - cell_conf[i]->has_hopping_mode = 1; + cell_conf[i]->has_hopping_mode = 1; cell_conf[i]->n_sb = flexran_get_n_SB(mod_id,i); cell_conf[i]->has_n_sb = 1; if (flexran_get_phich_resource(mod_id,i) == 0) { - cell_conf[i]->phich_resource = PROTOCOL__FLEX_PHICH_RESOURCE__FLPR_ONE_SIXTH; //0 + cell_conf[i]->phich_resource = PROTOCOL__FLEX_PHICH_RESOURCE__FLPR_ONE_SIXTH; //0 } else if (flexran_get_phich_resource(mod_id,i) == 1) { - cell_conf[i]->phich_resource = PROTOCOL__FLEX_PHICH_RESOURCE__FLPR_HALF; //1 + cell_conf[i]->phich_resource = PROTOCOL__FLEX_PHICH_RESOURCE__FLPR_HALF; //1 } else if (flexran_get_phich_resource(mod_id,i) == 2) { - cell_conf[i]->phich_resource = PROTOCOL__FLEX_PHICH_RESOURCE__FLPR_ONE; // 2 + cell_conf[i]->phich_resource = PROTOCOL__FLEX_PHICH_RESOURCE__FLPR_ONE; // 2 } else if (flexran_get_phich_resource(mod_id,i) == 3) { - cell_conf[i]->phich_resource = PROTOCOL__FLEX_PHICH_RESOURCE__FLPR_TWO;//3 + cell_conf[i]->phich_resource = PROTOCOL__FLEX_PHICH_RESOURCE__FLPR_TWO;//3 } + cell_conf[i]->has_phich_resource = 1; if (flexran_get_phich_duration(mod_id,i) == 0) { - cell_conf[i]->phich_duration = PROTOCOL__FLEX_PHICH_DURATION__FLPD_NORMAL; + cell_conf[i]->phich_duration = PROTOCOL__FLEX_PHICH_DURATION__FLPD_NORMAL; } else if(flexran_get_phich_duration(mod_id,i) == 1) { - cell_conf[i]->phich_duration = PROTOCOL__FLEX_PHICH_DURATION__FLPD_EXTENDED; + cell_conf[i]->phich_duration = PROTOCOL__FLEX_PHICH_DURATION__FLPD_EXTENDED; } + cell_conf[i]->has_phich_duration = 1; cell_conf[i]->init_nr_pdcch_ofdm_sym = flexran_get_num_pdcch_symb(mod_id,i); cell_conf[i]->has_init_nr_pdcch_ofdm_sym = 1; Protocol__FlexSiConfig *si_config; si_config = malloc(sizeof(Protocol__FlexSiConfig)); + if(si_config == NULL) goto error; - protocol__flex_si_config__init(si_config); + protocol__flex_si_config__init(si_config); si_config->sfn = flexran_get_current_system_frame_num(mod_id); si_config->has_sfn = 1; - si_config->sib1_length = flexran_get_sib1_length(mod_id,i); si_config->has_sib1_length = 1; - si_config->si_window_length = (uint32_t) flexran_get_si_window_length(mod_id, i); si_config->has_si_window_length = 1; - si_config->n_si_message = 0; - /* Protocol__FlexSiMessage **si_message; */ /* si_message = malloc(sizeof(Protocol__FlexSiMessage *) * si_config->n_si_message); */ /* if(si_message == NULL) */ - /* goto error; */ + /* goto error; */ /* for(j = 0; j < si_config->n_si_message; j++){ */ - /* si_message[j] = malloc(sizeof(Protocol__FlexSiMessage)); */ - /* if(si_message[j] == NULL) */ - /* goto error; */ - /* protocol__flex_si_message__init(si_message[j]); */ - /* //TODO: Fill in with actual value, Periodicity of SI msg in radio frames */ - /* si_message[j]->periodicity = 1; //SIPeriod */ - /* si_message[j]->has_periodicity = 1; */ - /* //TODO: Fill in with actual value, rhe length of the SI message in bytes */ - /* si_message[j]->length = 10; */ - /* si_message[j]->has_length = 1; */ + /* si_message[j] = malloc(sizeof(Protocol__FlexSiMessage)); */ + /* if(si_message[j] == NULL) */ + /* goto error; */ + /* protocol__flex_si_message__init(si_message[j]); */ + /* //TODO: Fill in with actual value, Periodicity of SI msg in radio frames */ + /* si_message[j]->periodicity = 1; //SIPeriod */ + /* si_message[j]->has_periodicity = 1; */ + /* //TODO: Fill in with actual value, rhe length of the SI message in bytes */ + /* si_message[j]->length = 10; */ + /* si_message[j]->has_length = 1; */ /* } */ /* if(si_config->n_si_message > 0){ */ - /* si_config->si_message = si_message; */ + /* si_config->si_message = si_message; */ /* } */ - cell_conf[i]->si_config = si_config; - cell_conf[i]->dl_bandwidth = flexran_get_N_RB_DL(mod_id,i); cell_conf[i]->has_dl_bandwidth = 1; - cell_conf[i]->ul_bandwidth = flexran_get_N_RB_UL(mod_id,i); cell_conf[i]->has_ul_bandwidth = 1; if (flexran_get_ul_cyclic_prefix_length(mod_id, i) == 0) { - cell_conf[i]->ul_cyclic_prefix_length = PROTOCOL__FLEX_UL_CYCLIC_PREFIX_LENGTH__FLUCPL_NORMAL; + cell_conf[i]->ul_cyclic_prefix_length = PROTOCOL__FLEX_UL_CYCLIC_PREFIX_LENGTH__FLUCPL_NORMAL; } else if(flexran_get_ul_cyclic_prefix_length(mod_id, i) == 1) { - cell_conf[i]->ul_cyclic_prefix_length = PROTOCOL__FLEX_UL_CYCLIC_PREFIX_LENGTH__FLUCPL_EXTENDED; + cell_conf[i]->ul_cyclic_prefix_length = PROTOCOL__FLEX_UL_CYCLIC_PREFIX_LENGTH__FLUCPL_EXTENDED; } + cell_conf[i]->has_ul_cyclic_prefix_length = 1; if (flexran_get_ul_cyclic_prefix_length(mod_id,i) == 0) { - cell_conf[i]->ul_cyclic_prefix_length = PROTOCOL__FLEX_DL_CYCLIC_PREFIX_LENGTH__FLDCPL_NORMAL; + cell_conf[i]->ul_cyclic_prefix_length = PROTOCOL__FLEX_DL_CYCLIC_PREFIX_LENGTH__FLDCPL_NORMAL; } else if (flexran_get_ul_cyclic_prefix_length(mod_id,i) == 1) { - cell_conf[i]->ul_cyclic_prefix_length = PROTOCOL__FLEX_DL_CYCLIC_PREFIX_LENGTH__FLDCPL_EXTENDED; + cell_conf[i]->ul_cyclic_prefix_length = PROTOCOL__FLEX_DL_CYCLIC_PREFIX_LENGTH__FLDCPL_EXTENDED; } cell_conf[i]->has_dl_cyclic_prefix_length = 1; @@ -964,10 +990,11 @@ int flexran_agent_enb_config_reply(mid_t mod_id, const void *params, Protocol__F cell_conf[i]->has_antenna_ports_count = 1; if (flexran_get_duplex_mode(mod_id,i) == 1) { - cell_conf[i]->duplex_mode = PROTOCOL__FLEX_DUPLEX_MODE__FLDM_FDD; + cell_conf[i]->duplex_mode = PROTOCOL__FLEX_DUPLEX_MODE__FLDM_FDD; } else if(flexran_get_duplex_mode(mod_id,i) == 0) { - cell_conf[i]->duplex_mode = PROTOCOL__FLEX_DUPLEX_MODE__FLDM_TDD; + cell_conf[i]->duplex_mode = PROTOCOL__FLEX_DUPLEX_MODE__FLDM_TDD; } + cell_conf[i]->has_duplex_mode = 1; cell_conf[i]->subframe_assignment = flexran_get_subframe_assignment(mod_id, i); cell_conf[i]->has_subframe_assignment = 1; @@ -977,158 +1004,140 @@ int flexran_agent_enb_config_reply(mid_t mod_id, const void *params, Protocol__F cell_conf[i]->n_mbsfn_subframe_config_rfperiod = 0; uint32_t *elem_rfperiod; elem_rfperiod = (uint32_t *) malloc(sizeof(uint32_t) *cell_conf[i]->n_mbsfn_subframe_config_rfperiod); + if(elem_rfperiod == NULL) - goto error; - for(j = 0; j < cell_conf[i]->n_mbsfn_subframe_config_rfperiod; j++){ - elem_rfperiod[j] = 1; + goto error; + + for(j = 0; j < cell_conf[i]->n_mbsfn_subframe_config_rfperiod; j++) { + elem_rfperiod[j] = 1; } - cell_conf[i]->mbsfn_subframe_config_rfperiod = elem_rfperiod; + cell_conf[i]->mbsfn_subframe_config_rfperiod = elem_rfperiod; //TODO: Fill in with actual value, The MBSFN radio frame offset cell_conf[i]->n_mbsfn_subframe_config_rfoffset = 0; uint32_t *elem_rfoffset; elem_rfoffset = (uint32_t *) malloc(sizeof(uint32_t) *cell_conf[i]->n_mbsfn_subframe_config_rfoffset); + if(elem_rfoffset == NULL) - goto error; - for(j = 0; j < cell_conf[i]->n_mbsfn_subframe_config_rfoffset; j++){ - elem_rfoffset[j] = 1; + goto error; + + for(j = 0; j < cell_conf[i]->n_mbsfn_subframe_config_rfoffset; j++) { + elem_rfoffset[j] = 1; } - cell_conf[i]->mbsfn_subframe_config_rfoffset = elem_rfoffset; + cell_conf[i]->mbsfn_subframe_config_rfoffset = elem_rfoffset; //TODO: Fill in with actual value, Bitmap indicating the MBSFN subframes cell_conf[i]->n_mbsfn_subframe_config_sfalloc = 0; uint32_t *elem_sfalloc; elem_sfalloc = (uint32_t *) malloc(sizeof(uint32_t) *cell_conf[i]->n_mbsfn_subframe_config_sfalloc); + if(elem_sfalloc == NULL) - goto error; - for(j = 0; j < cell_conf[i]->n_mbsfn_subframe_config_sfalloc; j++){ - elem_sfalloc[j] = 1; + goto error; + + for(j = 0; j < cell_conf[i]->n_mbsfn_subframe_config_sfalloc; j++) { + elem_sfalloc[j] = 1; } - cell_conf[i]->mbsfn_subframe_config_sfalloc = elem_sfalloc; + cell_conf[i]->mbsfn_subframe_config_sfalloc = elem_sfalloc; cell_conf[i]->prach_config_index = flexran_get_prach_ConfigIndex(mod_id,i); cell_conf[i]->has_prach_config_index = 1; - cell_conf[i]->prach_freq_offset = flexran_get_prach_FreqOffset(mod_id,i); cell_conf[i]->has_prach_freq_offset = 1; - cell_conf[i]->ra_response_window_size = flexran_get_ra_ResponseWindowSize(mod_id,i); cell_conf[i]->has_ra_response_window_size = 1; - cell_conf[i]->mac_contention_resolution_timer = flexran_get_mac_ContentionResolutionTimer(mod_id,i); cell_conf[i]->has_mac_contention_resolution_timer = 1; - cell_conf[i]->max_harq_msg3tx = flexran_get_maxHARQ_Msg3Tx(mod_id,i); cell_conf[i]->has_max_harq_msg3tx = 1; - cell_conf[i]->n1pucch_an = flexran_get_n1pucch_an(mod_id,i); cell_conf[i]->has_n1pucch_an = 1; - cell_conf[i]->deltapucch_shift = flexran_get_deltaPUCCH_Shift(mod_id,i); cell_conf[i]->has_deltapucch_shift = 1; - cell_conf[i]->nrb_cqi = flexran_get_nRB_CQI(mod_id,i); cell_conf[i]->has_nrb_cqi = 1; - cell_conf[i]->srs_subframe_config = flexran_get_srs_SubframeConfig(mod_id,i); cell_conf[i]->has_srs_subframe_config = 1; - cell_conf[i]->srs_bw_config = flexran_get_srs_BandwidthConfig(mod_id,i); cell_conf[i]->has_srs_bw_config = 1; - cell_conf[i]->srs_mac_up_pts = flexran_get_srs_MaxUpPts(mod_id,i); cell_conf[i]->has_srs_mac_up_pts = 1; - cell_conf[i]->dl_freq = flexran_agent_get_operating_dl_freq (mod_id,i); cell_conf[i]->has_dl_freq = 1; - cell_conf[i]->ul_freq = flexran_agent_get_operating_ul_freq (mod_id, i); cell_conf[i]->has_ul_freq = 1; - cell_conf[i]->eutra_band = flexran_agent_get_operating_eutra_band (mod_id,i); cell_conf[i]->has_eutra_band = 1; - cell_conf[i]->dl_pdsch_power = flexran_agent_get_operating_pdsch_refpower(mod_id, i); cell_conf[i]->has_dl_pdsch_power = 1; - cell_conf[i]->ul_pusch_power = flexran_agent_get_operating_pusch_p0 (mod_id,i); cell_conf[i]->has_ul_pusch_power = 1; if (flexran_get_enable64QAM(mod_id,i) == 0) { - cell_conf[i]->enable_64qam = PROTOCOL__FLEX_QAM__FLEQ_MOD_16QAM; + cell_conf[i]->enable_64qam = PROTOCOL__FLEX_QAM__FLEQ_MOD_16QAM; } else if(flexran_get_enable64QAM(mod_id,i) == 1) { - cell_conf[i]->enable_64qam = PROTOCOL__FLEX_QAM__FLEQ_MOD_64QAM; + cell_conf[i]->enable_64qam = PROTOCOL__FLEX_QAM__FLEQ_MOD_64QAM; } - cell_conf[i]->has_enable_64qam = 1; + cell_conf[i]->has_enable_64qam = 1; cell_conf[i]->carrier_index = i; cell_conf[i]->has_carrier_index = 1; - /* get a pointer to the config which is maintained in the agent throughout * its lifetime */ cell_conf[i]->slice_config = flexran_agent_get_slice_config(mod_id); } + enb_config_reply_msg->cell_config=cell_conf; } + *msg = malloc(sizeof(Protocol__FlexranMessage)); + if(*msg == NULL) goto error; + protocol__flexran_message__init(*msg); (*msg)->msg_case = PROTOCOL__FLEXRAN_MESSAGE__MSG_ENB_CONFIG_REPLY_MSG; (*msg)->msg_dir = PROTOCOL__FLEXRAN_DIRECTION__SUCCESSFUL_OUTCOME; (*msg)->enb_config_reply_msg = enb_config_reply_msg; - return 0; - - error: +error: + // TODO: Need to make proper error handling if (header != NULL) free(header); + if (enb_config_reply_msg != NULL) free(enb_config_reply_msg); + if(*msg != NULL) free(*msg); + //LOG_E(FLEXRAN_AGENT, "%s: an error occured\n", __FUNCTION__); return -1; } int flexran_agent_rrc_measurement(mid_t mod_id, const void *params, Protocol__FlexranMessage **msg) { - protocol_ctxt_t ctxt; - Protocol__FlexranMessage *input = (Protocol__FlexranMessage *)params; Protocol__FlexRrcTriggering *triggering = input->rrc_triggering; - agent_reconf_rrc *reconf_param = malloc(sizeof(agent_reconf_rrc)); - - reconf_param->trigger_policy = triggering->rrc_trigger; - struct rrc_eNB_ue_context_s *ue_context_p = NULL; - - RB_FOREACH(ue_context_p, rrc_ue_tree_s, &(RC.rrc[mod_id]->rrc_ue_head)){ - - - PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, mod_id, ENB_FLAG_YES, ue_context_p->ue_context.rnti, flexran_get_current_frame(mod_id), flexran_get_current_subframe (mod_id), mod_id); - - flexran_rrc_eNB_generate_defaultRRCConnectionReconfiguration(&ctxt, ue_context_p, 0, reconf_param); - + RB_FOREACH(ue_context_p, rrc_ue_tree_s, &(RC.rrc[mod_id]->rrc_ue_head)) { + PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, mod_id, ENB_FLAG_YES, ue_context_p->ue_context.rnti, flexran_get_current_frame(mod_id), flexran_get_current_subframe (mod_id), mod_id); + flexran_rrc_eNB_generate_defaultRRCConnectionReconfiguration(&ctxt, ue_context_p, 0, reconf_param); } - - *msg = NULL; return 0; } -int flexran_agent_destroy_rrc_measurement(Protocol__FlexranMessage *msg){ +int flexran_agent_destroy_rrc_measurement(Protocol__FlexranMessage *msg) { // TODO return 0; } -int flexran_agent_handle_enb_config_reply(mid_t mod_id, const void *params, Protocol__FlexranMessage **msg) -{ +int flexran_agent_handle_enb_config_reply(mid_t mod_id, const void *params, Protocol__FlexranMessage **msg) { Protocol__FlexranMessage *input = (Protocol__FlexranMessage *)params; Protocol__FlexEnbConfigReply *enb_config = input->enb_config_reply_msg; @@ -1141,6 +1150,7 @@ int flexran_agent_handle_enb_config_reply(mid_t mod_id, const void *params, Prot if (enb_config->n_cell_config > 1) LOG_W(FLEXRAN_AGENT, "ignoring slice configs for other cell except cell 0\n"); + if (enb_config->cell_config[0]->slice_config) { prepare_update_slice_config(mod_id, enb_config->cell_config[0]->slice_config); } else { @@ -1151,8 +1161,7 @@ int flexran_agent_handle_enb_config_reply(mid_t mod_id, const void *params, Prot return 0; } -int flexran_agent_handle_ue_config_reply(mid_t mod_id, const void *params, Protocol__FlexranMessage **msg) -{ +int flexran_agent_handle_ue_config_reply(mid_t mod_id, const void *params, Protocol__FlexranMessage **msg) { int i; Protocol__FlexranMessage *input = (Protocol__FlexranMessage *)params; Protocol__FlexUeConfigReply *ue_config_reply = input->ue_config_reply_msg; diff --git a/openair2/ENB_APP/flexran_agent_timer.c b/openair2/ENB_APP/flexran_agent_timer.c index dda302735388ce56f5ce57d9e39de10a5cd712b8..143c2df889294377819bbeba08b28de2be5b8c63 100644 --- a/openair2/ENB_APP/flexran_agent_timer.c +++ b/openair2/ENB_APP/flexran_agent_timer.c @@ -17,10 +17,10 @@ *------------------------------------------------------------------------------- * For more information about the OpenAirInterface (OAI) Software Alliance: * contact@openairinterface.org - */ + */ /*! \file flexran_agent_timer.c - * \brief FlexRAN Timer + * \brief FlexRAN Timer * \author shahab SHARIAT BAGHERI * \date 2017 * \version 0.1 @@ -35,23 +35,23 @@ //struct flexran_agent_map agent_map; flexran_agent_timer_instance_t timer_instance; int agent_timer_init = 0; -err_code_t flexran_agent_init_timer(void){ - +err_code_t flexran_agent_init_timer(void) { LOG_I(FLEXRAN_AGENT, "init RB tree\n"); + if (!agent_timer_init) { RB_INIT(&timer_instance.flexran_agent_head); agent_timer_init = 1; } - - return PROTOCOL__FLEXRAN_ERR__NO_ERR; + + return PROTOCOL__FLEXRAN_ERR__NO_ERR; } RB_GENERATE(flexran_agent_map, flexran_agent_timer_element_s, entry, flexran_agent_compare_timer); /* The timer_id might not be the best choice for the comparison */ -int flexran_agent_compare_timer(struct flexran_agent_timer_element_s *a, struct flexran_agent_timer_element_s *b){ - +int flexran_agent_compare_timer(struct flexran_agent_timer_element_s *a, struct flexran_agent_timer_element_s *b) { if (a->timer_id < b->timer_id) return -1; + if (a->timer_id > b->timer_id) return 1; // equal timers @@ -59,52 +59,53 @@ int flexran_agent_compare_timer(struct flexran_agent_timer_element_s *a, struct } err_code_t flexran_agent_create_timer(uint32_t interval_sec, - uint32_t interval_usec, - agent_id_t agent_id, - instance_t instance, - uint32_t timer_type, - xid_t xid, - flexran_agent_timer_callback_t cb, - void* timer_args, - long *timer_id){ - + uint32_t interval_usec, + agent_id_t agent_id, + instance_t instance, + uint32_t timer_type, + xid_t xid, + flexran_agent_timer_callback_t cb, + void *timer_args, + long *timer_id) { struct flexran_agent_timer_element_s *e = calloc(1, sizeof(*e)); DevAssert(e != NULL); - -//uint32_t timer_id; + //uint32_t timer_id; int ret=-1; - - if ((interval_sec == 0) && (interval_usec == 0 )) + + if ((interval_sec == 0) && (interval_usec == 0 )) { + free(e); return TIMER_NULL; - - if (timer_type >= FLEXRAN_AGENT_TIMER_TYPE_MAX) + } + + if (timer_type >= FLEXRAN_AGENT_TIMER_TYPE_MAX) { + free(e); return TIMER_TYPE_INVALIDE; - - if (timer_type == FLEXRAN_AGENT_TIMER_TYPE_ONESHOT){ - ret = timer_setup(interval_sec, - interval_usec, - TASK_FLEXRAN_AGENT, - instance, - TIMER_ONE_SHOT, - timer_args, - timer_id); - - e->type = TIMER_ONE_SHOT; } - else if (timer_type == FLEXRAN_AGENT_TIMER_TYPE_PERIODIC ){ - ret = timer_setup(interval_sec, - interval_usec, - TASK_FLEXRAN_AGENT, - instance, - TIMER_PERIODIC, - timer_args, - timer_id); - + + if (timer_type == FLEXRAN_AGENT_TIMER_TYPE_ONESHOT) { + ret = timer_setup(interval_sec, + interval_usec, + TASK_FLEXRAN_AGENT, + instance, + TIMER_ONE_SHOT, + timer_args, + timer_id); + + e->type = TIMER_ONE_SHOT; + } else if (timer_type == FLEXRAN_AGENT_TIMER_TYPE_PERIODIC ) { + ret = timer_setup(interval_sec, + interval_usec, + TASK_FLEXRAN_AGENT, + instance, + TIMER_PERIODIC, + timer_args, + timer_id); e->type = TIMER_PERIODIC; } - + if (ret < 0 ) { - return TIMER_SETUP_FAILED; + free(e); + return TIMER_SETUP_FAILED; } e->agent_id = agent_id; @@ -112,19 +113,16 @@ err_code_t flexran_agent_create_timer(uint32_t interval_sec, e->state = FLEXRAN_AGENT_TIMER_STATE_ACTIVE; e->timer_id = *timer_id; e->xid = xid; - e->timer_args = timer_args; + e->timer_args = timer_args; e->cb = cb; /*element should be a real pointer*/ - RB_INSERT(flexran_agent_map, &timer_instance.flexran_agent_head, e); - + RB_INSERT(flexran_agent_map, &timer_instance.flexran_agent_head, e); LOG_I(FLEXRAN_AGENT,"Created a new timer with id 0x%lx for agent %d, instance %d \n", - e->timer_id, e->agent_id, e->instance); - - return 0; + e->timer_id, e->agent_id, e->instance); + return 0; } -err_code_t flexran_agent_destroy_timer(long timer_id){ - +err_code_t flexran_agent_destroy_timer(long timer_id) { struct flexran_agent_timer_element_s *e = get_timer_entry(timer_id); if (e != NULL ) { @@ -132,13 +130,12 @@ err_code_t flexran_agent_destroy_timer(long timer_id){ flexran_agent_destroy_flexran_message(e->timer_args->msg); free(e); } - - if (timer_remove(timer_id) < 0 ) + + if (timer_remove(timer_id) < 0 ) goto error; - - return 0; - error: + return 0; +error: LOG_E(FLEXRAN_AGENT, "timer can't be removed\n"); return TIMER_REMOVED_FAILED ; } @@ -152,66 +149,59 @@ err_code_t flexran_agent_destroy_timer_by_task_id(xid_t xid) { RB_REMOVE(flexran_agent_map, &timer_instance.flexran_agent_head, e); flexran_agent_destroy_flexran_message(e->timer_args->msg); free(e); - if (timer_remove(timer_id) < 0 ) { - goto error; + + if (timer_remove(timer_id) < 0 ) { + goto error; } } } return 0; - - error: +error: LOG_E(FLEXRAN_AGENT, "timer can't be removed\n"); return TIMER_REMOVED_FAILED ; } -err_code_t flexran_agent_destroy_timers(void){ - +err_code_t flexran_agent_destroy_timers(void) { struct flexran_agent_timer_element_s *e = NULL; - RB_FOREACH(e, flexran_agent_map, &timer_instance.flexran_agent_head) { RB_REMOVE(flexran_agent_map, &timer_instance.flexran_agent_head, e); timer_remove(e->timer_id); flexran_agent_destroy_flexran_message(e->timer_args->msg); free(e); - } - + } return 0; - } void flexran_agent_sleep_until(struct timespec *ts, int delay) { ts->tv_nsec += delay; - if(ts->tv_nsec >= 1000*1000*1000){ + + if(ts->tv_nsec >= 1000*1000*1000) { ts->tv_nsec -= 1000*1000*1000; ts->tv_sec++; } + clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, ts, NULL); } -err_code_t flexran_agent_stop_timer(long timer_id){ - +err_code_t flexran_agent_stop_timer(long timer_id) { struct flexran_agent_timer_element_s *e=NULL; struct flexran_agent_timer_element_s search; memset(&search, 0, sizeof(struct flexran_agent_timer_element_s)); search.timer_id = timer_id; - e = RB_FIND(flexran_agent_map, &timer_instance.flexran_agent_head, &search); if (e != NULL ) { e->state = FLEXRAN_AGENT_TIMER_STATE_STOPPED; } - + timer_remove(timer_id); - return 0; } -struct flexran_agent_timer_element_s * get_timer_entry(long timer_id) { - +struct flexran_agent_timer_element_s *get_timer_entry(long timer_id) { struct flexran_agent_timer_element_s search; memset(&search, 0, sizeof(struct flexran_agent_timer_element_s)); search.timer_id = timer_id; - - return RB_FIND(flexran_agent_map, &timer_instance.flexran_agent_head, &search); + return RB_FIND(flexran_agent_map, &timer_instance.flexran_agent_head, &search); } diff --git a/openair2/LAYER2/MAC/config.c b/openair2/LAYER2/MAC/config.c index 3252bb6b92f6a629a1c965db5b31c7f793e33b44..1a334a36b9a3c32434c55b0800279119832cfd61 100644 --- a/openair2/LAYER2/MAC/config.c +++ b/openair2/LAYER2/MAC/config.c @@ -134,42 +134,37 @@ static const eutra_bandentry_t eutra_bandtable[] = { {68, 6980, 7280, 7530, 7830, 67536} }; -uint32_t to_earfcn(int eutra_bandP, uint32_t dl_CarrierFreq, uint32_t bw) -{ +#define BANDTABLE_SIZE (sizeof(eutra_bandtable)/sizeof(eutra_bandentry_t)) + +uint32_t to_earfcn(int eutra_bandP, uint32_t dl_CarrierFreq, uint32_t bw) { uint32_t dl_CarrierFreq_by_100k = dl_CarrierFreq / 100000; int bw_by_100 = bw / 100; - int i; - AssertFatal(eutra_bandP < 69, "eutra_band %d > 68\n", eutra_bandP); - for (i = 0; i < 69 && eutra_bandtable[i].band != eutra_bandP; i++); + + for (i = 0; i < BANDTABLE_SIZE && eutra_bandtable[i].band != eutra_bandP; i++); AssertFatal(dl_CarrierFreq_by_100k >= eutra_bandtable[i].dl_min, - "Band %d, bw %u : DL carrier frequency %u Hz < %u\n", - eutra_bandP, bw, dl_CarrierFreq, - eutra_bandtable[i].dl_min); + "Band %d, bw %u : DL carrier frequency %u Hz < %u\n", + eutra_bandP, bw, dl_CarrierFreq, + eutra_bandtable[i].dl_min); AssertFatal(dl_CarrierFreq_by_100k <= - (eutra_bandtable[i].dl_max - bw_by_100), - "Band %d, bw %u: DL carrier frequency %u Hz > %d\n", - eutra_bandP, bw, dl_CarrierFreq, - eutra_bandtable[i].dl_max - bw_by_100); - - + (eutra_bandtable[i].dl_max - bw_by_100), + "Band %d, bw %u: DL carrier frequency %u Hz > %d\n", + eutra_bandP, bw, dl_CarrierFreq, + eutra_bandtable[i].dl_max - bw_by_100); return (dl_CarrierFreq_by_100k - eutra_bandtable[i].dl_min + - (eutra_bandtable[i].N_OFFs_DL / 10)); + (eutra_bandtable[i].N_OFFs_DL / 10)); } -uint32_t to_earfcn_DL(int eutra_bandP, long long int dl_CarrierFreq, uint32_t bw) -{ - +uint32_t to_earfcn_DL(int eutra_bandP, long long int dl_CarrierFreq, uint32_t bw) { uint32_t dl_CarrierFreq_by_100k = dl_CarrierFreq / 100000; int bw_by_100 = bw / 100; - int i; - AssertFatal(eutra_bandP < 69, "eutra_band %d > 68\n", eutra_bandP); - for (i = 0; i < 69 && eutra_bandtable[i].band != eutra_bandP; i++); + + for (i = 0; i < BANDTABLE_SIZE && eutra_bandtable[i].band != eutra_bandP; i++); AssertFatal(dl_CarrierFreq_by_100k >= eutra_bandtable[i].dl_min, "Band %d, bw %u : DL carrier frequency %lld Hz < %u\n", @@ -180,22 +175,17 @@ uint32_t to_earfcn_DL(int eutra_bandP, long long int dl_CarrierFreq, uint32_t bw "Band %d, bw %u : DL carrier frequency %lld Hz > %d\n", eutra_bandP, bw, dl_CarrierFreq, eutra_bandtable[i].dl_max - bw_by_100); - - return (dl_CarrierFreq_by_100k - eutra_bandtable[i].dl_min + (eutra_bandtable[i].N_OFFs_DL / 10)); } -uint32_t to_earfcn_UL(int eutra_bandP, long long int ul_CarrierFreq, uint32_t bw) -{ - +uint32_t to_earfcn_UL(int eutra_bandP, long long int ul_CarrierFreq, uint32_t bw) { uint32_t ul_CarrierFreq_by_100k = ul_CarrierFreq / 100000; int bw_by_100 = bw / 100; - int i; - AssertFatal(eutra_bandP < 69, "eutra_band %d > 68\n", eutra_bandP); - for (i = 0; i < 69 && eutra_bandtable[i].band != eutra_bandP; i++); + + for (i = 0; i < BANDTABLE_SIZE && eutra_bandtable[i].band != eutra_bandP; i++); AssertFatal(ul_CarrierFreq_by_100k >= eutra_bandtable[i].ul_min, "Band %d, bw %u : UL carrier frequency %lld Hz < %u\n", @@ -206,30 +196,26 @@ uint32_t to_earfcn_UL(int eutra_bandP, long long int ul_CarrierFreq, uint32_t bw "Band %d, bw %u : UL carrier frequency %lld Hz > %d\n", eutra_bandP, bw, ul_CarrierFreq, eutra_bandtable[i].ul_max - bw_by_100); - - return (ul_CarrierFreq_by_100k - eutra_bandtable[i].ul_min + ((eutra_bandtable[i].N_OFFs_DL + 180000) / 10)); } -uint32_t from_earfcn(int eutra_bandP, uint32_t dl_earfcn) -{ - +uint32_t from_earfcn(int eutra_bandP, uint32_t dl_earfcn) { int i; - AssertFatal(eutra_bandP < 69, "eutra_band %d > 68\n", eutra_bandP); - for (i = 0; i < 69 && eutra_bandtable[i].band != eutra_bandP; i++); + + for (i = 0; i < BANDTABLE_SIZE && eutra_bandtable[i].band != eutra_bandP; i++); return (eutra_bandtable[i].dl_min + - (dl_earfcn - (eutra_bandtable[i].N_OFFs_DL / 10))) * 100000; + (dl_earfcn - (eutra_bandtable[i].N_OFFs_DL / 10))) * 100000; } -int32_t get_uldl_offset(int eutra_bandP) -{ +int32_t get_uldl_offset(int eutra_bandP) { int i; - for (i = 0; i < 69 && eutra_bandtable[i].band != eutra_bandP; i++); + for (i = 0; i < BANDTABLE_SIZE && eutra_bandtable[i].band != eutra_bandP; i++); + return (eutra_bandtable[i].dl_min - eutra_bandtable[i].ul_min); } @@ -892,6 +878,19 @@ int rrc_mac_config_req_eNB(module_id_t Mod_idP, } } // mib != NULL + if (mobilityControlInfo !=NULL){ + if ((UE_id = add_new_ue(Mod_idP, CC_idP, + rntiP, -1 +#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0)) + , + -1 +#endif + )) == -1) + { + LOG_E(MAC, "%s:%d: fatal\n", __FILE__, __LINE__); + abort(); + } + } // SRB2_lchan_config->choice.explicitValue.ul_SpecificParameters->logicalChannelGroup if (logicalChannelConfig != NULL) { // check for eMTC specific things diff --git a/openair2/LAYER2/MAC/config_ue.c b/openair2/LAYER2/MAC/config_ue.c index bec39aa8dc4ecf7968afae647e4e49149b067685..19dc16c13ffb52d6dafd9207ba8ea841484fb207 100644 --- a/openair2/LAYER2/MAC/config_ue.c +++ b/openair2/LAYER2/MAC/config_ue.c @@ -374,7 +374,9 @@ rrc_mac_config_req_ue(module_id_t Mod_idP, #endif if (measObj != NULL) { - if (measObj[0] != NULL) { + if (measObj[0] != NULL && + measObj[0]->measObject.present == LTE_MeasObjectToAddMod__measObject_PR_measObjectEUTRA && + measObj[0]->measObject.choice.measObjectEUTRA.cellsToAddModList != NULL) { UE_mac_inst[Mod_idP].n_adj_cells = measObj[0]->measObject.choice. measObjectEUTRA.cellsToAddModList->list.count; diff --git a/openair2/LAYER2/MAC/eNB_scheduler_RA.c b/openair2/LAYER2/MAC/eNB_scheduler_RA.c index 23b709f58e607df84b1880f916c82a94ac096a26..ff4b1e6517b3693bb3ebe874a1ecf9040346a252 100644 --- a/openair2/LAYER2/MAC/eNB_scheduler_RA.c +++ b/openair2/LAYER2/MAC/eNB_scheduler_RA.c @@ -112,7 +112,7 @@ add_msg3(module_id_t module_idP, int CC_id, RA_t * ra, frame_t frameP, nfapi_hi_dci0_request_body_t *hi_dci0_req_body; nfapi_hi_dci0_request_pdu_t *hi_dci0_pdu; uint8_t sf_ahead_dl; - uint8_t rvseq[4] = { 0, 2, 3, 1 }; + uint8_t rvseq[4] = {0, 2, 3, 1}; ul_req = &mac->UL_req_tmp[CC_id][ra->Msg3_subframe]; @@ -1536,14 +1536,14 @@ cancel_ra_proc(module_id_t module_idP, int CC_id, frame_t frameP, module_idP, CC_id, frameP, rnti); for (i = 0; i < NB_RA_PROC_MAX; i++) { - if (rnti == ra[i].rnti) { - ra[i].state = IDLE; - ra[i].timing_offset = 0; - ra[i].RRC_timer = 20; - ra[i].rnti = 0; - ra[i].msg3_round = 0; - LOG_I(MAC,"[eNB %d][RAPROC] CC_id %d Frame %d Canceled RA procedure for UE rnti %x\n", module_idP, CC_id, frameP, rnti); - } + if (rnti == ra[i].rnti) { + ra[i].state = IDLE; + ra[i].timing_offset = 0; + ra[i].RRC_timer = 20; + ra[i].rnti = 0; + ra[i].msg3_round = 0; + LOG_I(MAC,"[eNB %d][RAPROC] CC_id %d Frame %d Canceled RA procedure for UE rnti %x\n", module_idP, CC_id, frameP, rnti); + } } } diff --git a/openair2/LAYER2/MAC/eNB_scheduler_fairRR.c b/openair2/LAYER2/MAC/eNB_scheduler_fairRR.c index 86f7e16acfd028b5024ad2c4511fa1ef3c11b81d..8698c14b95020b5a9bf98dc12dd20188debd4723 100644 --- a/openair2/LAYER2/MAC/eNB_scheduler_fairRR.c +++ b/openair2/LAYER2/MAC/eNB_scheduler_fairRR.c @@ -1013,7 +1013,7 @@ schedule_ue_spec_fairRR(module_id_t module_idP, eNB_UE_stats->dlsch_mcs1 = cqi_to_mcs[ue_sched_ctl->dl_cqi[CC_id]]; } - eNB_UE_stats->dlsch_mcs1 = eNB_UE_stats->dlsch_mcs1; //cmin(eNB_UE_stats->dlsch_mcs1, openair_daq_vars.target_ue_dl_mcs); + //eNB_UE_stats->dlsch_mcs1 = cmin(eNB_UE_stats->dlsch_mcs1, openair_daq_vars.target_ue_dl_mcs); // store stats //UE_list->eNB_UE_stats[CC_id][UE_id].dl_cqi= eNB_UE_stats->dl_cqi; @@ -2583,7 +2583,7 @@ schedule_ulsch_fairRR(module_id_t module_idP, frame_t frameP, frame_parms->prach_config_common.prach_ConfigInfo.prach_ConfigIndex, frame_parms->prach_config_common.prach_ConfigInfo.prach_FreqOffset, 0,//tdd_mapindex - frameP); //Nf + frameP); //Nf --> shouldn't it be sched_frame ??? ulsch_ue_select[CC_id].list[ulsch_ue_select[CC_id].ue_num].nb_rb = 6; ulsch_ue_select[CC_id].list[ulsch_ue_select[CC_id].ue_num].UE_id = -1; ulsch_ue_select[CC_id].ue_num++; diff --git a/openair2/LAYER2/MAC/eNB_scheduler_primitives.c b/openair2/LAYER2/MAC/eNB_scheduler_primitives.c index 9bcec88bf7092af13af90a6a749e01ac208f2108..deb766e7fea813827b7dc04b5daefd3747f6465e 100644 --- a/openair2/LAYER2/MAC/eNB_scheduler_primitives.c +++ b/openair2/LAYER2/MAC/eNB_scheduler_primitives.c @@ -48,7 +48,7 @@ #include "pdcp.h" #if defined(ENABLE_ITTI) -#include "intertask_interface.h" + #include "intertask_interface.h" #endif #include "T.h" @@ -63,19 +63,20 @@ extern uint16_t frame_cnt; extern RAN_CONTEXT_t RC; extern uint8_t nfapi_mode; -int choose(int n, int k) -{ +int choose(int n, int k) { int res = 1; int res2 = 1; int i; if (k > n) return (0); + if (n == k) return (1); for (i = n; i > k; i--) res *= i; + for (i = 2; i <= (n - k); i++) res2 *= i; @@ -83,21 +84,20 @@ int choose(int n, int k) } // Patented algorithm from Yang et al, US Patent 2009, "Channel Quality Indexing and Reverse Indexing" -void reverse_index(int N, int M, int r, int *v) -{ +void reverse_index(int N, int M, int r, int *v) { int BaseValue = 0; int IncreaseValue, ThresholdValue; int sumV; int i; - r = choose(N, M) - 1 - r; memset((void *) v, 0, M * sizeof(int)); - sumV = 0; i = M; + while (i > 0 && r > 0) { IncreaseValue = choose(N - M + 1 - sumV - v[i - 1] + i - 2, i - 1); ThresholdValue = BaseValue + IncreaseValue; + if (r >= ThresholdValue) { v[i - 1]++; BaseValue = ThresholdValue; @@ -110,37 +110,30 @@ void reverse_index(int N, int M, int r, int *v) } } -int to_prb(int dl_Bandwidth) -{ +int to_prb(int dl_Bandwidth) { int prbmap[6] = { 6, 15, 25, 50, 75, 100 }; - AssertFatal(dl_Bandwidth < 6, "dl_Bandwidth is 0..5\n"); return (prbmap[dl_Bandwidth]); } -int to_rbg(int dl_Bandwidth) -{ +int to_rbg(int dl_Bandwidth) { int rbgmap[6] = { 6, 8, 13, 17, 19, 25 }; - AssertFatal(dl_Bandwidth < 6, "dl_Bandwidth is 0..5\n"); return (rbgmap[dl_Bandwidth]); } -int get_phich_resource_times6(COMMON_channels_t * cc) -{ +int get_phich_resource_times6(COMMON_channels_t *cc) { int phichmap[4] = { 1, 3, 6, 12 }; AssertFatal(cc != NULL, "cc is null\n"); AssertFatal(cc->mib != NULL, "cc->mib is null\n"); AssertFatal((cc->mib->message.phich_Config.phich_Resource >= 0) && - (cc->mib->message.phich_Config.phich_Resource < 4), - "phich_Resource %d not in 0..3\n", - (int) cc->mib->message.phich_Config.phich_Resource); - + (cc->mib->message.phich_Config.phich_Resource < 4), + "phich_Resource %d not in 0..3\n", + (int) cc->mib->message.phich_Config.phich_Resource); return (phichmap[cc->mib->message.phich_Config.phich_Resource]); } -uint16_t mac_computeRIV(uint16_t N_RB_DL, uint16_t RBstart, uint16_t Lcrbs) -{ +uint16_t mac_computeRIV(uint16_t N_RB_DL, uint16_t RBstart, uint16_t Lcrbs) { uint16_t RIV; if (Lcrbs <= (1 + (N_RB_DL >> 1))) RIV = (N_RB_DL * (Lcrbs - 1)) + RBstart; @@ -149,8 +142,7 @@ uint16_t mac_computeRIV(uint16_t N_RB_DL, uint16_t RBstart, uint16_t Lcrbs) return (RIV); } -uint8_t getQm(uint8_t mcs) -{ +uint8_t getQm(uint8_t mcs) { if (mcs < 10) return (2); else if (mcs < 17) return (4); else return (6); @@ -158,14 +150,12 @@ uint8_t getQm(uint8_t mcs) void get_Msg3alloc(COMMON_channels_t *cc, - sub_frame_t current_subframe, - frame_t current_frame, - frame_t *frame, - sub_frame_t *subframe) -{ + sub_frame_t current_subframe, + frame_t current_frame, + frame_t *frame, + sub_frame_t *subframe) { // Fill in other TDD Configuration!!!! - - if (cc->tdd_Config == NULL) { // FDD + if (cc->tdd_Config == NULL) { // FDD *subframe = current_subframe + 6; if (*subframe > 9) { @@ -174,94 +164,90 @@ get_Msg3alloc(COMMON_channels_t *cc, } else { *frame = current_frame; } - } else { // TDD + } else { // TDD if (cc->tdd_Config->subframeAssignment == 1) { switch (current_subframe) { - - case 0: - *subframe = 7; - *frame = current_frame; - break; + case 0: + *subframe = 7; + *frame = current_frame; + break; - case 4: - *subframe = 2; - *frame = (current_frame + 1) & 1023; - break; + case 4: + *subframe = 2; + *frame = (current_frame + 1) & 1023; + break; - case 5: - *subframe = 2; - *frame = (current_frame + 1) & 1023; - break; - - case 9: - *subframe = 7; - *frame = (current_frame + 1) & 1023; - break; + case 5: + *subframe = 2; + *frame = (current_frame + 1) & 1023; + break; + + case 9: + *subframe = 7; + *frame = (current_frame + 1) & 1023; + break; } } else if (cc->tdd_Config->subframeAssignment == 3) { switch (current_subframe) { + case 0: + case 5: + case 6: + *subframe = 2; + *frame = (current_frame + 1) & 1023; + break; - case 0: - case 5: - case 6: - *subframe = 2; - *frame = (current_frame + 1) & 1023; - break; + case 7: + *subframe = 3; + *frame = (current_frame + 1) & 1023; + break; - case 7: - *subframe = 3; - *frame = (current_frame + 1) & 1023; - break; + case 8: + *subframe = 4; + *frame = (current_frame + 1) & 1023; + break; - case 8: - *subframe = 4; - *frame = (current_frame + 1) & 1023; - break; - - case 9: - *subframe = 2; - *frame = (current_frame + 2) & 1023; - break; + case 9: + *subframe = 2; + *frame = (current_frame + 2) & 1023; + break; } } else if (cc->tdd_Config->subframeAssignment == 4) { switch (current_subframe) { + case 0: + case 4: + case 5: + case 6: + *subframe = 2; + *frame = (current_frame + 1) & 1023; + break; - case 0: - case 4: - case 5: - case 6: - *subframe = 2; - *frame = (current_frame + 1) & 1023; - break; - - case 7: - *subframe = 3; - *frame = (current_frame + 1) & 1023; - break; + case 7: + *subframe = 3; + *frame = (current_frame + 1) & 1023; + break; - case 8: - case 9: - *subframe = 2; - *frame = (current_frame + 2) & 1023; - break; + case 8: + case 9: + *subframe = 2; + *frame = (current_frame + 2) & 1023; + break; } } else if (cc->tdd_Config->subframeAssignment == 5) { switch (current_subframe) { + case 0: + case 4: + case 5: + case 6: + *subframe = 2; + *frame = (current_frame + 1) & 1023; + break; - case 0: - case 4: - case 5: - case 6: - *subframe = 2; - *frame = (current_frame + 1) & 1023; - break; - - case 7: - case 8: - case 9: - *subframe = 2; - *frame = (current_frame + 2) & 1023; - break; + case 7: + case 8: + case 9: + *subframe = 2; + *frame = (current_frame + 2) & 1023; + break; } } } @@ -270,12 +256,11 @@ get_Msg3alloc(COMMON_channels_t *cc, void -get_Msg3allocret(COMMON_channels_t * cc, - sub_frame_t current_subframe, - frame_t current_frame, - frame_t * frame, sub_frame_t * subframe) -{ - if (cc->tdd_Config == NULL) { //FDD +get_Msg3allocret(COMMON_channels_t *cc, + sub_frame_t current_subframe, + frame_t current_frame, + frame_t *frame, sub_frame_t *subframe) { + if (cc->tdd_Config == NULL) { //FDD /* always retransmit in n+8 */ *subframe = current_subframe + 8; @@ -309,149 +294,153 @@ get_Msg3allocret(COMMON_channels_t * cc, } uint8_t -subframe2harqpid(COMMON_channels_t * cc, frame_t frame, - sub_frame_t subframe) +subframe2harqpid(COMMON_channels_t *cc, + frame_t frame, + sub_frame_t subframe) { uint8_t ret = 255; - AssertFatal(cc != NULL, "cc is null\n"); - if (cc->tdd_Config == NULL) { // FDD + if (cc->tdd_Config == NULL) { // FDD ret = (((frame << 1) + subframe) & 7); } else { switch (cc->tdd_Config->subframeAssignment) { - case 1: - if ((subframe == 2) || - (subframe == 3) || (subframe == 7) || (subframe == 8)) - switch (subframe) { - case 2: - case 3: - ret = (subframe - 2); - break; - case 7: - case 8: - ret = (subframe - 5); - break; - default: - AssertFatal(1 == 0, - "subframe2_harq_pid, Illegal subframe %d for TDD mode %d\n", - subframe, - (int) cc->tdd_Config->subframeAssignment); - break; - } + case 1: + switch (subframe) { + case 2: + case 3: + ret = (subframe - 2); + break; - break; + case 7: + case 8: + ret = (subframe - 5); + break; - case 2: - AssertFatal((subframe == 2) || (subframe == 7), - "subframe2_harq_pid, Illegal subframe %d for TDD mode %d\n", - subframe, - (int) cc->tdd_Config->subframeAssignment); + default: + AssertFatal(1 == 0, "subframe2_harq_pid, Illegal subframe %d for TDD mode %d\n", + subframe, (int) cc->tdd_Config->subframeAssignment); + break; + } + break; - ret = (subframe / 7); - break; + case 2: + AssertFatal((subframe == 2) || (subframe == 7), + "subframe2_harq_pid, Illegal subframe %d for TDD mode %d\n", + subframe, (int) cc->tdd_Config->subframeAssignment); + ret = (subframe / 7); + break; - case 3: - AssertFatal((subframe > 1) && (subframe < 5), - "subframe2_harq_pid, Illegal subframe %d for TDD mode %d\n", - subframe, - (int) cc->tdd_Config->subframeAssignment); - ret = (subframe - 2); - break; + case 3: + AssertFatal((subframe > 1) && (subframe < 5), + "subframe2_harq_pid, Illegal subframe %d for TDD mode %d\n", + subframe, (int) cc->tdd_Config->subframeAssignment); + ret = (subframe - 2); + break; - case 4: - AssertFatal((subframe > 1) && (subframe < 4), - "subframe2_harq_pid, Illegal subframe %d for TDD mode %d\n", - subframe, - (int) cc->tdd_Config->subframeAssignment); - ret = (subframe - 2); - break; + case 4: + AssertFatal((subframe > 1) && (subframe < 4), + "subframe2_harq_pid, Illegal subframe %d for TDD mode %d\n", + subframe, (int) cc->tdd_Config->subframeAssignment); + ret = (subframe - 2); + break; - case 5: - AssertFatal(subframe == 2, - "subframe2_harq_pid, Illegal subframe %d for TDD mode %d\n", - subframe, - (int) cc->tdd_Config->subframeAssignment); - ret = (subframe - 2); - break; + case 5: + AssertFatal(subframe == 2, + "subframe2_harq_pid, Illegal subframe %d for TDD mode %d\n", + subframe, (int) cc->tdd_Config->subframeAssignment); + ret = (subframe - 2); + break; - default: - AssertFatal(1 == 0, - "subframe2_harq_pid, Unsupported TDD mode %d\n", - (int) cc->tdd_Config->subframeAssignment); + default: + AssertFatal(1 == 0, + "subframe2_harq_pid, Unsupported TDD mode %d\n", + (int) cc->tdd_Config->subframeAssignment); + break; } } return ret; } uint8_t -get_Msg3harqpid(COMMON_channels_t * cc, - frame_t frame, sub_frame_t current_subframe) -{ +get_Msg3harqpid(COMMON_channels_t *cc, + frame_t frame, sub_frame_t current_subframe) { uint8_t ul_subframe = 0; uint32_t ul_frame = 0; - if (cc->tdd_Config == NULL) { // FDD + if (cc->tdd_Config == NULL) { // FDD ul_subframe = (current_subframe > 3) ? (current_subframe - 4) : (current_subframe + 6); ul_frame = (current_subframe > 3) ? ((frame + 1) & 1023) : frame; } else { switch (cc->tdd_Config->subframeAssignment) { - case 1: - switch (current_subframe) { - case 9: - case 0: - ul_subframe = 7; - break; - case 5: - case 7: - ul_subframe = 2; - break; - } - break; - case 3: - switch (current_subframe) { - case 0: - case 5: - case 6: - ul_subframe = 2; - break; - case 7: - ul_subframe = 3; - break; - case 8: - ul_subframe = 4; - break; - case 9: - ul_subframe = 2; - break; - } - break; - case 4: - switch (current_subframe) { - case 0: + case 1: + switch (current_subframe) { + case 9: + case 0: + ul_subframe = 7; + break; + + case 5: + case 7: + ul_subframe = 2; + break; + } + + break; + + case 3: + switch (current_subframe) { + case 0: + case 5: + case 6: + ul_subframe = 2; + break; + + case 7: + ul_subframe = 3; + break; + + case 8: + ul_subframe = 4; + break; + + case 9: + ul_subframe = 2; + break; + } + + break; + + case 4: + switch (current_subframe) { + case 0: + case 5: + case 6: + case 8: + case 9: + ul_subframe = 2; + break; + + case 7: + ul_subframe = 3; + break; + } + + break; + case 5: - case 6: - case 8: - case 9: - ul_subframe = 2; - break; - case 7: - ul_subframe = 3; - break; - } - break; - case 5: - ul_subframe = 2; - break; - default: - LOG_E(PHY, - "get_Msg3_harq_pid: Unsupported TDD configuration %d\n", - (int) cc->tdd_Config->subframeAssignment); - AssertFatal(1 == 0, - "get_Msg3_harq_pid: Unsupported TDD configuration"); - break; + ul_subframe = 2; + break; + + default: + LOG_E(PHY, + "get_Msg3_harq_pid: Unsupported TDD configuration %d\n", + (int) cc->tdd_Config->subframeAssignment); + AssertFatal(1 == 0, + "get_Msg3_harq_pid: Unsupported TDD configuration"); + break; } } @@ -459,37 +448,35 @@ get_Msg3harqpid(COMMON_channels_t * cc, } uint32_t -pdcchalloc2ulframe(COMMON_channels_t * ccP, uint32_t frame, uint8_t n) -{ +pdcchalloc2ulframe(COMMON_channels_t *ccP, uint32_t frame, uint8_t n) { uint32_t ul_frame; - if ((ccP->tdd_Config) && (ccP->tdd_Config->subframeAssignment == 1) && ((n == 1) || (n == 6))) // tdd_config 0,1 SF 1,5 + if ((ccP->tdd_Config) && (ccP->tdd_Config->subframeAssignment == 1) && ((n == 1) || (n == 6))) // tdd_config 0,1 SF 1,5 ul_frame = (frame + (n == 1 ? 0 : 1)); else if ((ccP->tdd_Config) && - (ccP->tdd_Config->subframeAssignment == 6) && - ((n == 0) || (n == 1) || (n == 5) || (n == 6))) + (ccP->tdd_Config->subframeAssignment == 6) && + ((n == 0) || (n == 1) || (n == 5) || (n == 6))) ul_frame = (frame + (n >= 5 ? 1 : 0)); - else if ((ccP->tdd_Config) && (ccP->tdd_Config->subframeAssignment == 6) && (n == 9)) // tdd_config 6 SF 9 + else if ((ccP->tdd_Config) && (ccP->tdd_Config->subframeAssignment == 6) && (n == 9)) // tdd_config 6 SF 9 ul_frame = (frame + 1); else ul_frame = (frame + (n >= 6 ? 1 : 0)); LOG_D(PHY, "frame %d subframe %d: PUSCH frame = %d\n", frame, n, - ul_frame); + ul_frame); return ul_frame; } -uint8_t pdcchalloc2ulsubframe(COMMON_channels_t * ccP, uint8_t n) -{ +uint8_t pdcchalloc2ulsubframe(COMMON_channels_t *ccP, uint8_t n) { uint8_t ul_subframe; - if ((ccP->tdd_Config) && (ccP->tdd_Config->subframeAssignment == 1) && ((n == 1) || (n == 6))) // tdd_config 0,1 SF 1,5 + if ((ccP->tdd_Config) && (ccP->tdd_Config->subframeAssignment == 1) && ((n == 1) || (n == 6))) // tdd_config 0,1 SF 1,5 ul_subframe = ((n + 6) % 10); else if ((ccP->tdd_Config) && - (ccP->tdd_Config->subframeAssignment == 6) && - ((n == 0) || (n == 1) || (n == 5) || (n == 6))) + (ccP->tdd_Config->subframeAssignment == 6) && + ((n == 0) || (n == 1) || (n == 5) || (n == 6))) ul_subframe = ((n + 7) % 10); - else if ((ccP->tdd_Config) && (ccP->tdd_Config->subframeAssignment == 6) && (n == 9)) // tdd_config 6 SF 9 + else if ((ccP->tdd_Config) && (ccP->tdd_Config->subframeAssignment == 6) && (n == 9)) // tdd_config 6 SF 9 ul_subframe = ((n + 5) % 10); else ul_subframe = ((n + 4) % 10); @@ -498,116 +485,131 @@ uint8_t pdcchalloc2ulsubframe(COMMON_channels_t * ccP, uint8_t n) return ul_subframe; } -int is_UL_sf(COMMON_channels_t * ccP, sub_frame_t subframeP) -{ +int is_UL_sf(COMMON_channels_t *ccP, sub_frame_t subframeP) { // if FDD return dummy value if (ccP->tdd_Config == NULL) return (0); switch (ccP->tdd_Config->subframeAssignment) { - case 1: - switch (subframeP) { - case 0: - case 4: - case 5: - case 9: - return (0); + case 1: + switch (subframeP) { + case 0: + case 4: + case 5: + case 9: + return (0); + break; + + case 2: + case 3: + case 7: + case 8: + return (1); + break; + + default: + return (0); + break; + } + break; - case 2: + case 3: - case 7: - case 8: - return (1); + if ((subframeP <= 1) || (subframeP >= 5)) + return (0); + else if ((subframeP > 1) && (subframeP < 5)) + return (1); + else + AssertFatal(1 == 0, "Unknown subframe number\n"); + + break; + + case 4: + if ((subframeP <= 1) || (subframeP >= 4)) + return (0); + else if ((subframeP > 1) && (subframeP < 4)) + return (1); + else + AssertFatal(1 == 0, "Unknown subframe number\n"); + break; + + case 5: + if ((subframeP <= 1) || (subframeP >= 3)) + return (0); + else if ((subframeP > 1) && (subframeP < 3)) + return (1); + else + AssertFatal(1 == 0, "Unknown subframe number\n"); + + break; + default: - return (0); + AssertFatal(1 == 0, + "subframe %d Unsupported TDD configuration %d\n", + subframeP, (int) ccP->tdd_Config->subframeAssignment); break; - } - break; - case 3: - if ((subframeP <= 1) || (subframeP >= 5)) - return (0); - else if ((subframeP > 1) && (subframeP < 5)) - return (1); - else - AssertFatal(1 == 0, "Unknown subframe number\n"); - break; - case 4: - if ((subframeP <= 1) || (subframeP >= 4)) - return (0); - else if ((subframeP > 1) && (subframeP < 4)) - return (1); - else - AssertFatal(1 == 0, "Unknown subframe number\n"); - break; - case 5: - if ((subframeP <= 1) || (subframeP >= 3)) - return (0); - else if ((subframeP > 1) && (subframeP < 3)) - return (1); - else - AssertFatal(1 == 0, "Unknown subframe number\n"); - break; - default: - AssertFatal(1 == 0, - "subframe %d Unsupported TDD configuration %d\n", - subframeP, (int) ccP->tdd_Config->subframeAssignment); - break; } } -int is_S_sf(COMMON_channels_t * ccP, sub_frame_t subframeP) -{ - // if FDD return dummy value - if (ccP->tdd_Config == NULL) +int is_S_sf(COMMON_channels_t *ccP, sub_frame_t subframeP) { + // if FDD return dummy value + if (ccP->tdd_Config == NULL) return (0); - switch (subframeP) { + switch (subframeP) { case 1: - return (1); - break; + return (1); + break; case 6: - if(ccP->tdd_Config->subframeAssignment == 0 || ccP->tdd_Config->subframeAssignment == 1 - || ccP->tdd_Config->subframeAssignment == 2 || ccP->tdd_Config->subframeAssignment == 6) + if(ccP->tdd_Config->subframeAssignment == 0 || ccP->tdd_Config->subframeAssignment == 1 + || ccP->tdd_Config->subframeAssignment == 2 || ccP->tdd_Config->subframeAssignment == 6) return (1); - break; + + break; default: - return (0); - break; - } - return 0; + return (0); + break; + } + + return 0; } -uint8_t ul_subframe2_k_phich(COMMON_channels_t * cc, sub_frame_t ul_subframe){ +uint8_t ul_subframe2_k_phich(COMMON_channels_t *cc, sub_frame_t ul_subframe) { + if(cc->tdd_Config) { //TODO fill other tdd config + switch(cc->tdd_Config->subframeAssignment) { + case 0: + break; - if(cc->tdd_Config){//TODO fill other tdd config - switch(cc->tdd_Config->subframeAssignment){ - case 0: - break; - case 1: - if(ul_subframe == 2 || ul_subframe == 7) - return 4; - else if(ul_subframe == 3 || ul_subframe == 8) - return 6; - else return 255; - break; - case 2: - break; - case 3: - break; - case 4: - break; - case 5: - break; - } + case 1: + if(ul_subframe == 2 || ul_subframe == 7) + return 4; + else if(ul_subframe == 3 || ul_subframe == 8) + return 6; + else return 255; + + break; + + case 2: + break; + + case 3: + break; + + case 4: + break; + + case 5: + break; } - return 4; //idk sf_ahead? + } + + return 4; //idk sf_ahead? } -uint16_t get_pucch1_absSF(COMMON_channels_t * cc, uint16_t dlsch_absSF) -{ +uint16_t get_pucch1_absSF(COMMON_channels_t *cc, uint16_t dlsch_absSF) { uint16_t sf, f, nextf; if (cc->tdd_Config == NULL) { //FDD n+4 @@ -618,242 +620,267 @@ uint16_t get_pucch1_absSF(COMMON_channels_t * cc, uint16_t dlsch_absSF) nextf = (f + 1) & 1023; switch (cc->tdd_Config->subframeAssignment) { - case 0: - if ((sf == 0) || (sf == 5)) - return ((10 * f) + sf + 4)% 10240; // ACK/NAK in SF 4,9 same frame - else if (sf == 6) - return ((10 * nextf) + 2)% 10240; // ACK/NAK in SF 2 next frame - else if (sf == 1) - return ((10 * f) + 7)% 10240; // ACK/NAK in SF 7 same frame - else - AssertFatal(1 == 0, - "Impossible dlsch subframe %d for TDD configuration 0\n", - sf); + case 0: + if ((sf == 0) || (sf == 5)) + return ((10 * f) + sf + 4)% 10240; // ACK/NAK in SF 4,9 same frame + else if (sf == 6) + return ((10 * nextf) + 2)% 10240; // ACK/NAK in SF 2 next frame + else if (sf == 1) + return ((10 * f) + 7)% 10240; // ACK/NAK in SF 7 same frame + else + AssertFatal(1 == 0, + "Impossible dlsch subframe %d for TDD configuration 0\n", + sf); - break; - case 1: - if ((sf == 5) || (sf == 6)) - return ((10 * nextf) + 2)% 10240; // ACK/NAK in SF 2 next frame - else if (sf == 9) - return ((10 * nextf) + 3)% 10240; // ACK/NAK in SF 3 next frame - else if ((sf == 0) || (sf == 1)) - return ((10 * f) + 7)% 10240; // ACK/NAK in SF 7 same frame - else if (sf == 4) - return ((10 * f) + 8)% 10240; // ACK/NAK in SF 8 same frame - else - AssertFatal(1 == 0, - "Impossible dlsch subframe %d for TDD configuration 1\n", - sf); - break; - case 2: - if ((sf == 4) || (sf == 5) || (sf == 6) || (sf == 8)) - return ((10 * nextf) + 2)% 10240; // ACK/NAK in SF 2 next frame - else if (sf == 9) - return ((10 * nextf) + 7)% 10240; // ACK/NAK in SF 7 next frame - else if ((sf == 0) || (sf == 1) || (sf == 3)) - return ((10 * f) + 7)% 10240; // ACK/NAK in SF 7 same frame - else - AssertFatal(1 == 0, - "Impossible dlsch subframe %d for TDD configuration 2\n", - sf); - break; - case 3: - if ((sf == 5) || (sf == 6) || (sf == 7) || (sf == 8) - || (sf == 9)) - return ((10 * nextf) + ((sf-1) >> 1))% 10240; // ACK/NAK in 2,3,4 resp. next frame - else if (sf == 1) - return ((10 * nextf) + 2)% 10240; // ACK/NAK in 2 next frame - else if (sf == 0) - return ((10 * f) + 4)% 10240; // ACK/NAK in 4 same frame - else - AssertFatal(1 == 0, - "Impossible dlsch subframe %d for TDD configuration 3\n", - sf); - break; - case 4: - if ((sf == 6) || (sf == 7) || (sf == 8) || (sf == 9)) - return (((10 * nextf) + 3) % 10240); // ACK/NAK in SF 3 next frame - else if ((sf == 0) || (sf == 1) || (sf == 4) || (sf == 5)) - return (((10 * nextf) + 2) % 10240); // ACK/NAK in SF 2 next frame - else - AssertFatal(1 == 0, - "Impossible dlsch subframe %d for TDD configuration 4\n", - sf); - break; - case 5: - if ((sf == 0) || (sf == 1) || (sf == 3) || (sf == 4) - || (sf == 5) || (sf == 6) || (sf == 7) || (sf == 8)) - return (((10 * nextf) + 2) % 10240); // ACK/NAK in SF 3 next frame - else if (sf == 9) - return (((10 * (1 + nextf)) + 2) % 10240); // ACK/NAK in SF 2 next frame - else - AssertFatal(1 == 0, - "Impossible dlsch subframe %d for TDD configuration 5\n", - sf); - break; - case 6: - if ((sf == 5) || (sf == 6)) - return ((10 * f) + sf + 7)% 10240; // ACK/NAK in SF 2,3 next frame - else if (sf == 9) - return ((10 * nextf) + 4)% 10240; // ACK/NAK in SF 4 next frame - else if ((sf == 1) || (sf == 0)) - return ((10 * f) + sf + 7)% 10240; // ACK/NAK in SF 7 same frame - else - AssertFatal(1 == 0, - "Impossible dlsch subframe %d for TDD configuration 6\n", - sf); - break; - default: - AssertFatal(1 == 0, "Illegal TDD subframe Assigment %d\n", - (int) cc->tdd_Config->subframeAssignment); - break; + break; + + case 1: + if ((sf == 5) || (sf == 6)) + return ((10 * nextf) + 2)% 10240; // ACK/NAK in SF 2 next frame + else if (sf == 9) + return ((10 * nextf) + 3)% 10240; // ACK/NAK in SF 3 next frame + else if ((sf == 0) || (sf == 1)) + return ((10 * f) + 7)% 10240; // ACK/NAK in SF 7 same frame + else if (sf == 4) + return ((10 * f) + 8)% 10240; // ACK/NAK in SF 8 same frame + else + AssertFatal(1 == 0, + "Impossible dlsch subframe %d for TDD configuration 1\n", + sf); + + break; + + case 2: + if ((sf == 4) || (sf == 5) || (sf == 6) || (sf == 8)) + return ((10 * nextf) + 2)% 10240; // ACK/NAK in SF 2 next frame + else if (sf == 9) + return ((10 * nextf) + 7)% 10240; // ACK/NAK in SF 7 next frame + else if ((sf == 0) || (sf == 1) || (sf == 3)) + return ((10 * f) + 7)% 10240; // ACK/NAK in SF 7 same frame + else + AssertFatal(1 == 0, + "Impossible dlsch subframe %d for TDD configuration 2\n", + sf); + + break; + + case 3: + if ((sf == 5) || (sf == 6) || (sf == 7) || (sf == 8) + || (sf == 9)) + return ((10 * nextf) + ((sf-1) >> 1))% 10240; // ACK/NAK in 2,3,4 resp. next frame + else if (sf == 1) + return ((10 * nextf) + 2)% 10240; // ACK/NAK in 2 next frame + else if (sf == 0) + return ((10 * f) + 4)% 10240; // ACK/NAK in 4 same frame + else + AssertFatal(1 == 0, + "Impossible dlsch subframe %d for TDD configuration 3\n", + sf); + + break; + + case 4: + if ((sf == 6) || (sf == 7) || (sf == 8) || (sf == 9)) + return (((10 * nextf) + 3) % 10240); // ACK/NAK in SF 3 next frame + else if ((sf == 0) || (sf == 1) || (sf == 4) || (sf == 5)) + return (((10 * nextf) + 2) % 10240); // ACK/NAK in SF 2 next frame + else + AssertFatal(1 == 0, + "Impossible dlsch subframe %d for TDD configuration 4\n", + sf); + + break; + + case 5: + if ((sf == 0) || (sf == 1) || (sf == 3) || (sf == 4) + || (sf == 5) || (sf == 6) || (sf == 7) || (sf == 8)) + return (((10 * nextf) + 2) % 10240); // ACK/NAK in SF 3 next frame + else if (sf == 9) + return (((10 * (1 + nextf)) + 2) % 10240); // ACK/NAK in SF 2 next frame + else + AssertFatal(1 == 0, + "Impossible dlsch subframe %d for TDD configuration 5\n", + sf); + + break; + + case 6: + if ((sf == 5) || (sf == 6)) + return ((10 * f) + sf + 7)% 10240; // ACK/NAK in SF 2,3 next frame + else if (sf == 9) + return ((10 * nextf) + 4)% 10240; // ACK/NAK in SF 4 next frame + else if ((sf == 1) || (sf == 0)) + return ((10 * f) + sf + 7)% 10240; // ACK/NAK in SF 7 same frame + else + AssertFatal(1 == 0, + "Impossible dlsch subframe %d for TDD configuration 6\n", + sf); + + break; + + default: + AssertFatal(1 == 0, "Illegal TDD subframe Assigment %d\n", + (int) cc->tdd_Config->subframeAssignment); + break; } } + AssertFatal(1 == 0, "Shouldn't get here\n"); } void -get_srs_pos(COMMON_channels_t * cc, uint16_t isrs, - uint16_t * psrsPeriodicity, uint16_t * psrsOffset) -{ - if (cc->tdd_Config) { // TDD +get_srs_pos(COMMON_channels_t *cc, uint16_t isrs, + uint16_t *psrsPeriodicity, uint16_t *psrsOffset) { + if (cc->tdd_Config) { // TDD AssertFatal(isrs >= 10, "2 ms SRS periodicity not supported"); if ((isrs > 9) && (isrs < 15)) { *psrsPeriodicity = 5; *psrsOffset = isrs - 10; } + if ((isrs > 14) && (isrs < 25)) { *psrsPeriodicity = 10; *psrsOffset = isrs - 15; } + if ((isrs > 24) && (isrs < 45)) { *psrsPeriodicity = 20; *psrsOffset = isrs - 25; } + if ((isrs > 44) && (isrs < 85)) { *psrsPeriodicity = 40; *psrsOffset = isrs - 45; } + if ((isrs > 84) && (isrs < 165)) { *psrsPeriodicity = 80; *psrsOffset = isrs - 85; } + if ((isrs > 164) && (isrs < 325)) { *psrsPeriodicity = 160; *psrsOffset = isrs - 165; } + if ((isrs > 324) && (isrs < 645)) { *psrsPeriodicity = 320; *psrsOffset = isrs - 325; } AssertFatal(isrs <= 644, "Isrs out of range %d>644\n", isrs); - } // TDD - else { // FDD + } // TDD + else { // FDD if (isrs < 2) { *psrsPeriodicity = 2; *psrsOffset = isrs; } + if ((isrs > 1) && (isrs < 7)) { *psrsPeriodicity = 5; *psrsOffset = isrs - 2; } + if ((isrs > 6) && (isrs < 17)) { *psrsPeriodicity = 10; *psrsOffset = isrs - 7; } + if ((isrs > 16) && (isrs < 37)) { *psrsPeriodicity = 20; *psrsOffset = isrs - 17; } + if ((isrs > 36) && (isrs < 77)) { *psrsPeriodicity = 40; *psrsOffset = isrs - 37; } + if ((isrs > 76) && (isrs < 157)) { *psrsPeriodicity = 80; *psrsOffset = isrs - 77; } + if ((isrs > 156) && (isrs < 317)) { *psrsPeriodicity = 160; *psrsOffset = isrs - 157; } + if ((isrs > 316) && (isrs < 637)) { *psrsPeriodicity = 320; *psrsOffset = isrs - 317; } + AssertFatal(isrs <= 636, "Isrs out of range %d>636\n", isrs); } } void -get_csi_params(COMMON_channels_t * cc, - struct LTE_CQI_ReportPeriodic *cqi_ReportPeriodic, - uint16_t * Npd, uint16_t * N_OFFSET_CQI, int *H) -{ +get_csi_params(COMMON_channels_t *cc, + struct LTE_CQI_ReportPeriodic *cqi_ReportPeriodic, + uint16_t *Npd, uint16_t *N_OFFSET_CQI, int *H) { + AssertFatal(cqi_ReportPeriodic != NULL, + "cqi_ReportPeriodic is null!\n"); + uint16_t cqi_PMI_ConfigIndex = cqi_ReportPeriodic->choice.setup.cqi_pmi_ConfigIndex; uint8_t Jtab[6] = { 0, 2, 2, 3, 4, 4 }; - AssertFatal(cqi_ReportPeriodic != NULL, - "cqi_ReportPeriodic is null!\n"); - - if (cc->tdd_Config == NULL) { //FDD - if (cqi_PMI_ConfigIndex <= 1) { // 2 ms CQI_PMI period + if (cc->tdd_Config == NULL) { //FDD + if (cqi_PMI_ConfigIndex <= 1) { // 2 ms CQI_PMI period *Npd = 2; *N_OFFSET_CQI = cqi_PMI_ConfigIndex; - } else if (cqi_PMI_ConfigIndex <= 6) { // 5 ms CQI_PMI period + } else if (cqi_PMI_ConfigIndex <= 6) { // 5 ms CQI_PMI period *Npd = 5; *N_OFFSET_CQI = cqi_PMI_ConfigIndex - 2; - } else if (cqi_PMI_ConfigIndex <= 16) { // 10ms CQI_PMI period + } else if (cqi_PMI_ConfigIndex <= 16) { // 10ms CQI_PMI period *Npd = 10; *N_OFFSET_CQI = cqi_PMI_ConfigIndex - 7; - } else if (cqi_PMI_ConfigIndex <= 36) { // 20 ms CQI_PMI period + } else if (cqi_PMI_ConfigIndex <= 36) { // 20 ms CQI_PMI period *Npd = 20; *N_OFFSET_CQI = cqi_PMI_ConfigIndex - 17; - } else if (cqi_PMI_ConfigIndex <= 76) { // 40 ms CQI_PMI period + } else if (cqi_PMI_ConfigIndex <= 76) { // 40 ms CQI_PMI period *Npd = 40; *N_OFFSET_CQI = cqi_PMI_ConfigIndex - 37; - } else if (cqi_PMI_ConfigIndex <= 156) { // 80 ms CQI_PMI period + } else if (cqi_PMI_ConfigIndex <= 156) { // 80 ms CQI_PMI period *Npd = 80; *N_OFFSET_CQI = cqi_PMI_ConfigIndex - 77; - } else if (cqi_PMI_ConfigIndex <= 316) { // 160 ms CQI_PMI period + } else if (cqi_PMI_ConfigIndex <= 316) { // 160 ms CQI_PMI period *Npd = 160; *N_OFFSET_CQI = cqi_PMI_ConfigIndex - 157; } else if (cqi_PMI_ConfigIndex > 317) { - - if (cqi_PMI_ConfigIndex <= 349) { // 32 ms CQI_PMI period - *Npd = 32; - *N_OFFSET_CQI = cqi_PMI_ConfigIndex - 318; - } else if (cqi_PMI_ConfigIndex <= 413) { // 64 ms CQI_PMI period - *Npd = 64; - *N_OFFSET_CQI = cqi_PMI_ConfigIndex - 350; - } else if (cqi_PMI_ConfigIndex <= 541) { // 128 ms CQI_PMI period - *Npd = 128; - *N_OFFSET_CQI = cqi_PMI_ConfigIndex - 414; + if (cqi_PMI_ConfigIndex <= 349) { // 32 ms CQI_PMI period + *Npd = 32; + *N_OFFSET_CQI = cqi_PMI_ConfigIndex - 318; + } else if (cqi_PMI_ConfigIndex <= 413) { // 64 ms CQI_PMI period + *Npd = 64; + *N_OFFSET_CQI = cqi_PMI_ConfigIndex - 350; + } else if (cqi_PMI_ConfigIndex <= 541) { // 128 ms CQI_PMI period + *Npd = 128; + *N_OFFSET_CQI = cqi_PMI_ConfigIndex - 414; } } - } else { // TDD - if (cqi_PMI_ConfigIndex == 0) { // all UL subframes + } else { // TDD + if (cqi_PMI_ConfigIndex == 0) { // all UL subframes *Npd = 1; *N_OFFSET_CQI = 0; - } else if (cqi_PMI_ConfigIndex <= 6) { // 5 ms CQI_PMI period + } else if (cqi_PMI_ConfigIndex <= 6) { // 5 ms CQI_PMI period *Npd = 5; *N_OFFSET_CQI = cqi_PMI_ConfigIndex - 1; - } else if (cqi_PMI_ConfigIndex <= 16) { // 10ms CQI_PMI period + } else if (cqi_PMI_ConfigIndex <= 16) { // 10ms CQI_PMI period *Npd = 10; *N_OFFSET_CQI = cqi_PMI_ConfigIndex - 6; - } else if (cqi_PMI_ConfigIndex <= 36) { // 20 ms CQI_PMI period + } else if (cqi_PMI_ConfigIndex <= 36) { // 20 ms CQI_PMI period *Npd = 20; *N_OFFSET_CQI = cqi_PMI_ConfigIndex - 16; - } else if (cqi_PMI_ConfigIndex <= 76) { // 40 ms CQI_PMI period + } else if (cqi_PMI_ConfigIndex <= 76) { // 40 ms CQI_PMI period *Npd = 40; *N_OFFSET_CQI = cqi_PMI_ConfigIndex - 36; - } else if (cqi_PMI_ConfigIndex <= 156) { // 80 ms CQI_PMI period + } else if (cqi_PMI_ConfigIndex <= 156) { // 80 ms CQI_PMI period *Npd = 80; *N_OFFSET_CQI = cqi_PMI_ConfigIndex - 76; - } else if (cqi_PMI_ConfigIndex <= 316) { // 160 ms CQI_PMI period + } else if (cqi_PMI_ConfigIndex <= 316) { // 160 ms CQI_PMI period *Npd = 160; *N_OFFSET_CQI = cqi_PMI_ConfigIndex - 156; } @@ -864,173 +891,189 @@ get_csi_params(COMMON_channels_t * cc, present == LTE_CQI_ReportPeriodic__setup__cqi_FormatIndicatorPeriodic_PR_subbandCQI) *H = 1 + - (Jtab[cc->mib->message.dl_Bandwidth] * - cqi_ReportPeriodic->choice.setup. - cqi_FormatIndicatorPeriodic.choice.subbandCQI.k); + (Jtab[cc->mib->message.dl_Bandwidth] * + cqi_ReportPeriodic->choice.setup. + cqi_FormatIndicatorPeriodic.choice.subbandCQI.k); else *H = 1; } uint8_t -get_dl_cqi_pmi_size_pusch(COMMON_channels_t * cc, uint8_t tmode, - uint8_t ri, - LTE_CQI_ReportModeAperiodic_t * - cqi_ReportModeAperiodic) -{ +get_dl_cqi_pmi_size_pusch(COMMON_channels_t *cc, uint8_t tmode, + uint8_t ri, + LTE_CQI_ReportModeAperiodic_t * + cqi_ReportModeAperiodic) { int Ntab[6] = { 0, 4, 7, 9, 10, 13 }; int N = Ntab[cc->mib->message.dl_Bandwidth]; int Ltab_uesel[6] = { 0, 6, 9, 13, 15, 18 }; int L = Ltab_uesel[cc->mib->message.dl_Bandwidth]; - AssertFatal(cqi_ReportModeAperiodic != NULL, - "cqi_ReportPeriodic is null!\n"); + "cqi_ReportPeriodic is null!\n"); switch (*cqi_ReportModeAperiodic) { - case LTE_CQI_ReportModeAperiodic_rm12: - AssertFatal(tmode == 4 || tmode == 6 || tmode == 8 || tmode == 9 - || tmode == 10, - "Illegal TM (%d) for CQI_ReportModeAperiodic_rm12\n", - tmode); - AssertFatal(cc->p_eNB <= 4, - "only up to 4 antenna ports supported here\n"); - if (ri == 1 && cc->p_eNB == 2) + case LTE_CQI_ReportModeAperiodic_rm12: + AssertFatal(tmode == 4 || tmode == 6 || tmode == 8 || tmode == 9 + || tmode == 10, + "Illegal TM (%d) for CQI_ReportModeAperiodic_rm12\n", + tmode); + AssertFatal(cc->p_eNB <= 4, + "only up to 4 antenna ports supported here\n"); + + if (ri == 1 && cc->p_eNB == 2) + return (4 + (N << 1)); + else if (ri == 2 && cc->p_eNB == 2) + return (8 + N); + else if (ri == 1 && cc->p_eNB == 4) + return (4 + (N << 2)); + else if (ri > 1 && cc->p_eNB == 4) + return (8 + (N << 2)); + + break; + + case LTE_CQI_ReportModeAperiodic_rm20: + // Table 5.2.2.6.3-1 (36.212) + AssertFatal(tmode == 1 || tmode == 2 || tmode == 3 || tmode == 7 + || tmode == 9 + || tmode == 10, + "Illegal TM (%d) for CQI_ReportModeAperiodic_rm20\n", + tmode); + AssertFatal(tmode != 9 + && tmode != 10, + "TM9/10 will be handled later for CQI_ReportModeAperiodic_rm20\n"); + return (4 + 2 + L); + break; + + case LTE_CQI_ReportModeAperiodic_rm22: + // Table 5.2.2.6.3-2 (36.212) + AssertFatal(tmode == 4 || tmode == 6 || tmode == 8 || tmode == 9 + || tmode == 10, + "Illegal TM (%d) for CQI_ReportModeAperiodic_rm22\n", + tmode); + AssertFatal(tmode != 9 + && tmode != 10, + "TM9/10 will be handled later for CQI_ReportModeAperiodic_rm22\n"); + + if (ri == 1 && cc->p_eNB == 2) + return (4 + 2 + 0 + 0 + L + 4); + + if (ri == 2 && cc->p_eNB == 2) + return (4 + 2 + 4 + 2 + L + 2); + + if (ri == 1 && cc->p_eNB == 4) + return (4 + 2 + 0 + 0 + L + 8); + + if (ri >= 2 && cc->p_eNB == 4) + return (4 + 2 + 4 + 2 + L + 8); + + break; + + case LTE_CQI_ReportModeAperiodic_rm30: + // Table 5.2.2.6.2-1 (36.212) + AssertFatal(tmode == 1 || tmode == 2 || tmode == 3 || tmode == 7 + || tmode == 8 || tmode == 9 + || tmode == 10, + "Illegal TM (%d) for CQI_ReportModeAperiodic_rm30\n", + tmode); + AssertFatal(tmode != 8 && tmode != 9 + && tmode != 10, + "TM8/9/10 will be handled later for CQI_ReportModeAperiodic_rm30\n"); return (4 + (N << 1)); - else if (ri == 2 && cc->p_eNB == 2) - return (8 + N); - else if (ri == 1 && cc->p_eNB == 4) - return (4 + (N << 2)); - else if (ri > 1 && cc->p_eNB == 4) - return (8 + (N << 2)); - break; - case LTE_CQI_ReportModeAperiodic_rm20: - // Table 5.2.2.6.3-1 (36.212) - AssertFatal(tmode == 1 || tmode == 2 || tmode == 3 || tmode == 7 - || tmode == 9 - || tmode == 10, - "Illegal TM (%d) for CQI_ReportModeAperiodic_rm20\n", - tmode); - AssertFatal(tmode != 9 - && tmode != 10, - "TM9/10 will be handled later for CQI_ReportModeAperiodic_rm20\n"); - return (4 + 2 + L); - break; - case LTE_CQI_ReportModeAperiodic_rm22: - // Table 5.2.2.6.3-2 (36.212) - AssertFatal(tmode == 4 || tmode == 6 || tmode == 8 || tmode == 9 - || tmode == 10, - "Illegal TM (%d) for CQI_ReportModeAperiodic_rm22\n", - tmode); - AssertFatal(tmode != 9 - && tmode != 10, - "TM9/10 will be handled later for CQI_ReportModeAperiodic_rm22\n"); - if (ri == 1 && cc->p_eNB == 2) - return (4 + 2 + 0 + 0 + L + 4); - if (ri == 2 && cc->p_eNB == 2) - return (4 + 2 + 4 + 2 + L + 2); - if (ri == 1 && cc->p_eNB == 4) - return (4 + 2 + 0 + 0 + L + 8); - if (ri >= 2 && cc->p_eNB == 4) - return (4 + 2 + 4 + 2 + L + 8); - break; - case LTE_CQI_ReportModeAperiodic_rm30: - // Table 5.2.2.6.2-1 (36.212) - AssertFatal(tmode == 1 || tmode == 2 || tmode == 3 || tmode == 7 - || tmode == 8 || tmode == 9 - || tmode == 10, - "Illegal TM (%d) for CQI_ReportModeAperiodic_rm30\n", - tmode); - AssertFatal(tmode != 8 && tmode != 9 - && tmode != 10, - "TM8/9/10 will be handled later for CQI_ReportModeAperiodic_rm30\n"); - return (4 + (N << 1)); - break; - case LTE_CQI_ReportModeAperiodic_rm31: - // Table 5.2.2.6.2-2 (36.212) - AssertFatal(tmode == 4 || tmode == 6 || tmode == 8 || tmode == 9 - || tmode == 10, - "Illegal TM (%d) for CQI_ReportModeAperiodic_rm31\n", - tmode); - AssertFatal(tmode != 8 && tmode != 9 - && tmode != 10, - "TM8/9/10 will be handled later for CQI_ReportModeAperiodic_rm31\n"); - if (ri == 1 && cc->p_eNB == 2) - return (4 + (N << 1) + 0 + 0 + 2); - else if (ri == 2 && cc->p_eNB == 2) - return (4 + (N << 1) + 4 + (N << 1) + 1); - else if (ri == 1 && cc->p_eNB == 4) - return (4 + (N << 1) + 0 + 0 + 4); - else if (ri >= 2 && cc->p_eNB == 4) - return (4 + (N << 1) + 4 + (N << 1) + 4); - break; + break; + + case LTE_CQI_ReportModeAperiodic_rm31: + // Table 5.2.2.6.2-2 (36.212) + AssertFatal(tmode == 4 || tmode == 6 || tmode == 8 || tmode == 9 + || tmode == 10, + "Illegal TM (%d) for CQI_ReportModeAperiodic_rm31\n", + tmode); + AssertFatal(tmode != 8 && tmode != 9 + && tmode != 10, + "TM8/9/10 will be handled later for CQI_ReportModeAperiodic_rm31\n"); + + if (ri == 1 && cc->p_eNB == 2) + return (4 + (N << 1) + 0 + 0 + 2); + else if (ri == 2 && cc->p_eNB == 2) + return (4 + (N << 1) + 4 + (N << 1) + 1); + else if (ri == 1 && cc->p_eNB == 4) + return (4 + (N << 1) + 0 + 0 + 4); + else if (ri >= 2 && cc->p_eNB == 4) + return (4 + (N << 1) + 4 + (N << 1) + 4); + + break; #if (LTE_RRC_VERSION >= MAKE_VERSION(12, 5, 0)) - case LTE_CQI_ReportModeAperiodic_rm32_v1250: - AssertFatal(tmode == 4 || tmode == 6 || tmode == 8 || tmode == 9 - || tmode == 10, - "Illegal TM (%d) for CQI_ReportModeAperiodic_rm32\n", - tmode); - AssertFatal(1 == 0, - "CQI_ReportModeAperiodic_rm32_v1250 not supported yet\n"); - break; - case LTE_CQI_ReportModeAperiodic_rm10_v1310: - // Table 5.2.2.6.1-1F/G (36.212) - if (ri == 1) - return (4); // F - else - return (7); // G - break; - case LTE_CQI_ReportModeAperiodic_rm11_v1310: - // Table 5.2.2.6.1-1H (36.212) - AssertFatal(tmode == 4 || tmode == 6 || tmode == 8 || tmode == 9 - || tmode == 10, - "Illegal TM (%d) for CQI_ReportModeAperiodic_rm11\n", - tmode); - AssertFatal(cc->p_eNB <= 4, - "only up to 4 antenna ports supported here\n"); - if (ri == 1 && cc->p_eNB == 2) - return (4 + 0 + 2); - else if (ri == 2 && cc->p_eNB == 2) - return (4 + 4 + 1); - else if (ri == 1 && cc->p_eNB == 4) - return (4 + 0 + 4); - else if (ri > 1 && cc->p_eNB == 4) - return (4 + 4 + 4); - - break; + + case LTE_CQI_ReportModeAperiodic_rm32_v1250: + AssertFatal(tmode == 4 || tmode == 6 || tmode == 8 || tmode == 9 + || tmode == 10, + "Illegal TM (%d) for CQI_ReportModeAperiodic_rm32\n", + tmode); + AssertFatal(1 == 0, + "CQI_ReportModeAperiodic_rm32_v1250 not supported yet\n"); + break; + + case LTE_CQI_ReportModeAperiodic_rm10_v1310: + + // Table 5.2.2.6.1-1F/G (36.212) + if (ri == 1) + return (4); // F + else + return (7); // G + + break; + + case LTE_CQI_ReportModeAperiodic_rm11_v1310: + // Table 5.2.2.6.1-1H (36.212) + AssertFatal(tmode == 4 || tmode == 6 || tmode == 8 || tmode == 9 + || tmode == 10, + "Illegal TM (%d) for CQI_ReportModeAperiodic_rm11\n", + tmode); + AssertFatal(cc->p_eNB <= 4, + "only up to 4 antenna ports supported here\n"); + + if (ri == 1 && cc->p_eNB == 2) + return (4 + 0 + 2); + else if (ri == 2 && cc->p_eNB == 2) + return (4 + 4 + 1); + else if (ri == 1 && cc->p_eNB == 4) + return (4 + 0 + 4); + else if (ri > 1 && cc->p_eNB == 4) + return (4 + 4 + 4); + + break; #endif /* #if (LTE_RRC_VERSION >= MAKE_VERSION(12, 5, 0)) */ } + AssertFatal(1 == 0, "Shouldn't get here\n"); return (0); } uint8_t -get_rel8_dl_cqi_pmi_size(UE_sched_ctrl * sched_ctl, int CC_idP, - COMMON_channels_t * cc, uint8_t tmode, - struct LTE_CQI_ReportPeriodic * cqi_ReportPeriodic) -{ +get_rel8_dl_cqi_pmi_size(UE_sched_ctrl *sched_ctl, int CC_idP, + COMMON_channels_t *cc, uint8_t tmode, + struct LTE_CQI_ReportPeriodic *cqi_ReportPeriodic) { int no_pmi = 0; // Ltab[6] = {0,log2(15/4/2),log2(25/4/2),log2(50/6/3),log2(75/8/4),log2(100/8/4)}; - uint8_t Ltab[6] = { 0, 1, 2, 2, 2, 2 }; uint8_t ri = sched_ctl->periodic_ri_received[CC_idP]; - AssertFatal(cqi_ReportPeriodic != NULL, - "cqi_ReportPeriodic is null!\n"); + "cqi_ReportPeriodic is null!\n"); AssertFatal(cqi_ReportPeriodic->present != LTE_CQI_ReportPeriodic_PR_NOTHING, - "cqi_ReportPeriodic->present == CQI_ReportPeriodic_PR_NOTHING!\n"); + "cqi_ReportPeriodic->present == CQI_ReportPeriodic_PR_NOTHING!\n"); AssertFatal(cqi_ReportPeriodic->choice. - setup.cqi_FormatIndicatorPeriodic.present != LTE_CQI_ReportPeriodic__setup__cqi_FormatIndicatorPeriodic_PR_NOTHING, - "cqi_ReportPeriodic->cqi_FormatIndicatorPeriodic.choice.setup.present == CQI_ReportPeriodic__setup__cqi_FormatIndicatorPeriodic_PR_NOTHING!\n"); + setup.cqi_FormatIndicatorPeriodic.present != LTE_CQI_ReportPeriodic__setup__cqi_FormatIndicatorPeriodic_PR_NOTHING, + "cqi_ReportPeriodic->cqi_FormatIndicatorPeriodic.choice.setup.present == CQI_ReportPeriodic__setup__cqi_FormatIndicatorPeriodic_PR_NOTHING!\n"); switch (tmode) { - case 1: - case 2: - case 5: - case 6: - case 7: - no_pmi = 1; - break; - default: - no_pmi = 0; + case 1: + case 2: + case 5: + case 6: + case 7: + no_pmi = 1; + break; + + default: + no_pmi = 0; } if ((cqi_ReportPeriodic->choice.setup.cqi_FormatIndicatorPeriodic.present == LTE_CQI_ReportPeriodic__setup__cqi_FormatIndicatorPeriodic_PR_widebandCQI) @@ -1043,35 +1086,34 @@ get_rel8_dl_cqi_pmi_size(UE_sched_ctrl * sched_ctl, int CC_idP, else if ((cc->p_eNB == 4) && (ri == 2)) return (11); else AssertFatal(1 == 0, - "illegal combination p %d, ri %d, no_pmi %d\n", - cc->p_eNB, ri, no_pmi); + "illegal combination p %d, ri %d, no_pmi %d\n", + cc->p_eNB, ri, no_pmi); } else if (cqi_ReportPeriodic->choice.setup.cqi_FormatIndicatorPeriodic.present == LTE_CQI_ReportPeriodic__setup__cqi_FormatIndicatorPeriodic_PR_subbandCQI) { if ((no_pmi == 1) || ri == 1) return (4 + Ltab[cc->mib->message.dl_Bandwidth]); else return (7 + Ltab[cc->mib->message.dl_Bandwidth]); } AssertFatal(1 == 0, - "Shouldn't get here : cqi_ReportPeriodic->present %d\n", - cqi_ReportPeriodic->choice.setup.cqi_FormatIndicatorPeriodic.present); + "Shouldn't get here : cqi_ReportPeriodic->present %d\n", + cqi_ReportPeriodic->choice.setup.cqi_FormatIndicatorPeriodic.present); } void fill_nfapi_dl_dci_1A(nfapi_dl_config_request_pdu_t *dl_config_pdu, - uint8_t aggregation_level, - uint16_t rnti, - uint8_t rnti_type, - uint8_t harq_process, - uint8_t tpc, - uint16_t resource_block_coding, - uint8_t mcs, - uint8_t ndi, - uint8_t rv, - uint8_t vrb_flag) -{ + uint8_t aggregation_level, + uint16_t rnti, + uint8_t rnti_type, + uint8_t harq_process, + uint8_t tpc, + uint16_t resource_block_coding, + uint8_t mcs, + uint8_t ndi, + uint8_t rv, + uint8_t vrb_flag) { memset((void *) dl_config_pdu, 0, - sizeof(nfapi_dl_config_request_pdu_t)); + sizeof(nfapi_dl_config_request_pdu_t)); dl_config_pdu->pdu_type = NFAPI_DL_CONFIG_DCI_DL_PDU_TYPE; dl_config_pdu->pdu_size = (uint8_t) (2 + sizeof(nfapi_dl_config_dci_dl_pdu)); dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.tl.tag = NFAPI_DL_CONFIG_REQUEST_DCI_DL_PDU_REL8_TAG; @@ -1079,7 +1121,7 @@ fill_nfapi_dl_dci_1A(nfapi_dl_config_request_pdu_t *dl_config_pdu, dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level = aggregation_level; dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti = rnti; dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti_type = rnti_type; - dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.transmission_power = 6000; // equal to RS power + dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.transmission_power = 6000; // equal to RS power dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.harq_process = harq_process; dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.tpc = tpc; dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.resource_block_coding = resource_block_coding; @@ -1091,9 +1133,8 @@ fill_nfapi_dl_dci_1A(nfapi_dl_config_request_pdu_t *dl_config_pdu, void program_dlsch_acknak(module_id_t module_idP, int CC_idP, int UE_idP, - frame_t frameP, sub_frame_t subframeP, - uint8_t cce_idx) -{ + frame_t frameP, sub_frame_t subframeP, + uint8_t cce_idx) { eNB_MAC_INST *eNB = RC.mac[module_idP]; COMMON_channels_t *cc = eNB->common_channels; UE_list_t *UE_list = &eNB->UE_list; @@ -1103,7 +1144,6 @@ program_dlsch_acknak(module_id_t module_idP, int CC_idP, int UE_idP, int use_simultaneous_pucch_pusch = 0; nfapi_ul_config_ulsch_harq_information *ulsch_harq_information = NULL; nfapi_ul_config_harq_information *harq_information = NULL; - #if (LTE_RRC_VERSION >= MAKE_VERSION(10, 2, 0)) if ((UE_list->UE_template[CC_idP][UE_idP].physicalConfigDedicated->ext2) @@ -1111,8 +1151,8 @@ program_dlsch_acknak(module_id_t module_idP, int CC_idP, int UE_idP, && (UE_list->UE_template[CC_idP][UE_idP].physicalConfigDedicated->ext2->pucch_ConfigDedicated_v1020->simultaneousPUCCH_PUSCH_r10) && (*UE_list->UE_template[CC_idP][UE_idP].physicalConfigDedicated->ext2->pucch_ConfigDedicated_v1020->simultaneousPUCCH_PUSCH_r10 == LTE_PUCCH_ConfigDedicated_v1020__simultaneousPUCCH_PUSCH_r10_true)) use_simultaneous_pucch_pusch = 1; -#endif +#endif // pucch1 and pusch feedback is similar, namely in n+k subframes from now // This is used in the following "if/else" condition to check if there isn't or is already an UL grant in n+k int16_t ul_absSF = get_pucch1_absSF(&cc[CC_idP], subframeP + (10 * frameP)); @@ -1120,161 +1160,168 @@ program_dlsch_acknak(module_id_t module_idP, int CC_idP, int UE_idP, if ((ul_config_pdu = has_ul_grant(module_idP, CC_idP,ul_absSF, rnti)) == NULL) { // no UL grant so // Program ACK/NAK alone Format 1a/b or 3 - ul_req = &RC.mac[module_idP]->UL_req_tmp[CC_idP][ul_absSF %10].ul_config_request_body; ul_config_pdu = &ul_req->ul_config_pdu_list[ul_req->number_of_pdus]; // Do PUCCH fill_nfapi_uci_acknak(module_idP, - CC_idP, - rnti, (frameP * 10) + subframeP, cce_idx); + CC_idP, + rnti, (frameP * 10) + subframeP, cce_idx); } else { /* there is already an existing UL grant so update it if needed * on top of some other UL resource (PUSCH,combined SR/CQI/HARQ on PUCCH, etc) */ switch (ul_config_pdu->pdu_type) { - /* [ulsch] to [ulsch + harq] or [ulsch + harq on pucch] */ - - case NFAPI_UL_CONFIG_ULSCH_PDU_TYPE: - if (use_simultaneous_pucch_pusch == 1) { - // Convert it to an NFAPI_UL_CONFIG_ULSCH_UCI_HARQ_PDU_TYPE - harq_information = &ul_config_pdu->ulsch_uci_harq_pdu.harq_information; - ul_config_pdu->pdu_type = NFAPI_UL_CONFIG_ULSCH_UCI_HARQ_PDU_TYPE; - LOG_D(MAC, - "Frame %d, Subframe %d: Switched UCI HARQ to ULSCH UCI HARQ\n", - frameP, subframeP); - } else { - // Convert it to an NFAPI_UL_CONFIG_ULSCH_HARQ_PDU_TYPE - ulsch_harq_information = &ul_config_pdu->ulsch_harq_pdu.harq_information; - ul_config_pdu->pdu_type = NFAPI_UL_CONFIG_ULSCH_HARQ_PDU_TYPE; - ul_config_pdu->ulsch_harq_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.tl.tag = NFAPI_UL_CONFIG_REQUEST_INITIAL_TRANSMISSION_PARAMETERS_REL8_TAG; - ul_config_pdu->ulsch_harq_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.n_srs_initial = 0; // last symbol not punctured - ul_config_pdu->ulsch_harq_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.initial_number_of_resource_blocks = ul_config_pdu->ulsch_harq_pdu.ulsch_pdu.ulsch_pdu_rel8.number_of_resource_blocks; // we don't change the number of resource blocks across retransmissions yet - LOG_D(MAC, - "Frame %d, Subframe %d: Switched UCI HARQ to ULSCH HARQ\n", - frameP, subframeP); - } - break; - case NFAPI_UL_CONFIG_ULSCH_HARQ_PDU_TYPE: - AssertFatal(use_simultaneous_pucch_pusch == 0, - "Cannot be NFAPI_UL_CONFIG_ULSCH_HARQ_PDU_TYPE, simultaneous_pucch_pusch is active"); - break; - case NFAPI_UL_CONFIG_ULSCH_UCI_HARQ_PDU_TYPE: - AssertFatal(use_simultaneous_pucch_pusch == 1, - "Cannot be NFAPI_UL_CONFIG_ULSCH_UCI_PDU_TYPE, simultaneous_pucch_pusch is inactive\n"); - break; + case NFAPI_UL_CONFIG_ULSCH_PDU_TYPE: + if (use_simultaneous_pucch_pusch == 1) { + // Convert it to an NFAPI_UL_CONFIG_ULSCH_UCI_HARQ_PDU_TYPE + harq_information = &ul_config_pdu->ulsch_uci_harq_pdu.harq_information; + ul_config_pdu->pdu_type = NFAPI_UL_CONFIG_ULSCH_UCI_HARQ_PDU_TYPE; + LOG_D(MAC, + "Frame %d, Subframe %d: Switched UCI HARQ to ULSCH UCI HARQ\n", + frameP, subframeP); + } else { + // Convert it to an NFAPI_UL_CONFIG_ULSCH_HARQ_PDU_TYPE + ulsch_harq_information = &ul_config_pdu->ulsch_harq_pdu.harq_information; + ul_config_pdu->pdu_type = NFAPI_UL_CONFIG_ULSCH_HARQ_PDU_TYPE; + ul_config_pdu->ulsch_harq_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.tl.tag = NFAPI_UL_CONFIG_REQUEST_INITIAL_TRANSMISSION_PARAMETERS_REL8_TAG; + ul_config_pdu->ulsch_harq_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.n_srs_initial = 0; // last symbol not punctured + ul_config_pdu->ulsch_harq_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.initial_number_of_resource_blocks = + ul_config_pdu->ulsch_harq_pdu.ulsch_pdu.ulsch_pdu_rel8.number_of_resource_blocks; // we don't change the number of resource blocks across retransmissions yet + LOG_D(MAC, + "Frame %d, Subframe %d: Switched UCI HARQ to ULSCH HARQ\n", + frameP, subframeP); + } + + break; + + case NFAPI_UL_CONFIG_ULSCH_HARQ_PDU_TYPE: + AssertFatal(use_simultaneous_pucch_pusch == 0, + "Cannot be NFAPI_UL_CONFIG_ULSCH_HARQ_PDU_TYPE, simultaneous_pucch_pusch is active"); + break; + + case NFAPI_UL_CONFIG_ULSCH_UCI_HARQ_PDU_TYPE: + AssertFatal(use_simultaneous_pucch_pusch == 1, + "Cannot be NFAPI_UL_CONFIG_ULSCH_UCI_PDU_TYPE, simultaneous_pucch_pusch is inactive\n"); + break; /* [ulsch + cqi] to [ulsch + cqi + harq] */ - case NFAPI_UL_CONFIG_ULSCH_CQI_RI_PDU_TYPE: - // Convert it to an NFAPI_UL_CONFIG_ULSCH_CQI_HARQ_RI_PDU_TYPE - ulsch_harq_information = &ul_config_pdu->ulsch_cqi_harq_ri_pdu.harq_information; - ul_config_pdu->pdu_type = NFAPI_UL_CONFIG_ULSCH_CQI_HARQ_RI_PDU_TYPE; - /* TODO: check this - when converting from nfapi_ul_config_ulsch_cqi_ri_pdu to - * nfapi_ul_config_ulsch_cqi_harq_ri_pdu, shouldn't we copy initial_transmission_parameters - * from the one to the other? - * Those two types are not compatible. 'initial_transmission_parameters' is not at the - * place in both. - */ - ul_config_pdu->ulsch_cqi_harq_ri_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.tl.tag = NFAPI_UL_CONFIG_REQUEST_INITIAL_TRANSMISSION_PARAMETERS_REL8_TAG; - ul_config_pdu->ulsch_cqi_harq_ri_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.n_srs_initial = 0; // last symbol not punctured - ul_config_pdu->ulsch_cqi_harq_ri_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.initial_number_of_resource_blocks = ul_config_pdu->ulsch_harq_pdu.ulsch_pdu.ulsch_pdu_rel8.number_of_resource_blocks; // we don't change the number of resource blocks across retransmissions yet - break; - case NFAPI_UL_CONFIG_ULSCH_CQI_HARQ_RI_PDU_TYPE: - AssertFatal(use_simultaneous_pucch_pusch == 0, - "Cannot be NFAPI_UL_CONFIG_ULSCH_CQI_HARQ_RI_PDU_TYPE, simultaneous_pucch_pusch is active\n"); - break; + case NFAPI_UL_CONFIG_ULSCH_CQI_RI_PDU_TYPE: + // Convert it to an NFAPI_UL_CONFIG_ULSCH_CQI_HARQ_RI_PDU_TYPE + ulsch_harq_information = &ul_config_pdu->ulsch_cqi_harq_ri_pdu.harq_information; + ul_config_pdu->pdu_type = NFAPI_UL_CONFIG_ULSCH_CQI_HARQ_RI_PDU_TYPE; + /* TODO: check this - when converting from nfapi_ul_config_ulsch_cqi_ri_pdu to + * nfapi_ul_config_ulsch_cqi_harq_ri_pdu, shouldn't we copy initial_transmission_parameters + * from the one to the other? + * Those two types are not compatible. 'initial_transmission_parameters' is not at the + * place in both. + */ + ul_config_pdu->ulsch_cqi_harq_ri_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.tl.tag = + NFAPI_UL_CONFIG_REQUEST_INITIAL_TRANSMISSION_PARAMETERS_REL8_TAG; + ul_config_pdu->ulsch_cqi_harq_ri_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.n_srs_initial = 0; // last symbol not punctured + ul_config_pdu->ulsch_cqi_harq_ri_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.initial_number_of_resource_blocks = + ul_config_pdu->ulsch_harq_pdu.ulsch_pdu.ulsch_pdu_rel8.number_of_resource_blocks; // we don't change the number of resource blocks across retransmissions yet + break; + + case NFAPI_UL_CONFIG_ULSCH_CQI_HARQ_RI_PDU_TYPE: + AssertFatal(use_simultaneous_pucch_pusch == 0, + "Cannot be NFAPI_UL_CONFIG_ULSCH_CQI_HARQ_RI_PDU_TYPE, simultaneous_pucch_pusch is active\n"); + break; /* [ulsch + cqi on pucch] to [ulsch + cqi on pucch + harq on pucch] */ - case NFAPI_UL_CONFIG_ULSCH_UCI_CSI_PDU_TYPE: - // convert it to an NFAPI_UL_CONFIG_ULSCH_CSI_UCI_HARQ_PDU_TYPE - harq_information = &ul_config_pdu->ulsch_csi_uci_harq_pdu.harq_information; - ul_config_pdu->pdu_type = NFAPI_UL_CONFIG_ULSCH_CSI_UCI_HARQ_PDU_TYPE; - break; - case NFAPI_UL_CONFIG_ULSCH_CSI_UCI_HARQ_PDU_TYPE: - AssertFatal(use_simultaneous_pucch_pusch == 1, - "Cannot be NFAPI_UL_CONFIG_ULSCH_CSI_UCI_HARQ_PDU_TYPE, simultaneous_pucch_pusch is inactive\n"); - break; + case NFAPI_UL_CONFIG_ULSCH_UCI_CSI_PDU_TYPE: + // convert it to an NFAPI_UL_CONFIG_ULSCH_CSI_UCI_HARQ_PDU_TYPE + harq_information = &ul_config_pdu->ulsch_csi_uci_harq_pdu.harq_information; + ul_config_pdu->pdu_type = NFAPI_UL_CONFIG_ULSCH_CSI_UCI_HARQ_PDU_TYPE; + break; + + case NFAPI_UL_CONFIG_ULSCH_CSI_UCI_HARQ_PDU_TYPE: + AssertFatal(use_simultaneous_pucch_pusch == 1, + "Cannot be NFAPI_UL_CONFIG_ULSCH_CSI_UCI_HARQ_PDU_TYPE, simultaneous_pucch_pusch is inactive\n"); + break; /* [sr] to [sr + harq] */ - case NFAPI_UL_CONFIG_UCI_SR_PDU_TYPE: - // convert to NFAPI_UL_CONFIG_UCI_SR_HARQ_PDU_TYPE - ul_config_pdu->pdu_type = NFAPI_UL_CONFIG_UCI_SR_HARQ_PDU_TYPE; - harq_information = &ul_config_pdu->uci_sr_harq_pdu.harq_information; - break; - case NFAPI_UL_CONFIG_UCI_SR_HARQ_PDU_TYPE: - /* nothing to do */ - break; + case NFAPI_UL_CONFIG_UCI_SR_PDU_TYPE: + // convert to NFAPI_UL_CONFIG_UCI_SR_HARQ_PDU_TYPE + ul_config_pdu->pdu_type = NFAPI_UL_CONFIG_UCI_SR_HARQ_PDU_TYPE; + harq_information = &ul_config_pdu->uci_sr_harq_pdu.harq_information; + break; + + case NFAPI_UL_CONFIG_UCI_SR_HARQ_PDU_TYPE: + /* nothing to do */ + break; + /* [cqi] to [cqi + harq] */ - case NFAPI_UL_CONFIG_UCI_CQI_PDU_TYPE: - // convert to NFAPI_UL_CONFIG_UCI_CQI_HARQ_PDU_TYPE - ul_config_pdu->pdu_type = NFAPI_UL_CONFIG_UCI_CQI_HARQ_PDU_TYPE; - harq_information = &ul_config_pdu->uci_cqi_harq_pdu.harq_information; - break; - case NFAPI_UL_CONFIG_UCI_CQI_HARQ_PDU_TYPE: - /* nothing to do */ - break; + case NFAPI_UL_CONFIG_UCI_CQI_PDU_TYPE: + // convert to NFAPI_UL_CONFIG_UCI_CQI_HARQ_PDU_TYPE + ul_config_pdu->pdu_type = NFAPI_UL_CONFIG_UCI_CQI_HARQ_PDU_TYPE; + harq_information = &ul_config_pdu->uci_cqi_harq_pdu.harq_information; + break; + + case NFAPI_UL_CONFIG_UCI_CQI_HARQ_PDU_TYPE: + /* nothing to do */ + break; + /* [cqi + sr] to [cqr + sr + harq] */ - case NFAPI_UL_CONFIG_UCI_CQI_SR_PDU_TYPE: - // convert to NFAPI_UL_CONFIG_UCI_CQI_SR_HARQ_PDU_TYPE - ul_config_pdu->pdu_type = NFAPI_UL_CONFIG_UCI_CQI_SR_HARQ_PDU_TYPE; - harq_information = &ul_config_pdu->uci_cqi_sr_harq_pdu.harq_information; - break; - case NFAPI_UL_CONFIG_UCI_CQI_SR_HARQ_PDU_TYPE: - /* nothing to do */ - break; + case NFAPI_UL_CONFIG_UCI_CQI_SR_PDU_TYPE: + // convert to NFAPI_UL_CONFIG_UCI_CQI_SR_HARQ_PDU_TYPE + ul_config_pdu->pdu_type = NFAPI_UL_CONFIG_UCI_CQI_SR_HARQ_PDU_TYPE; + harq_information = &ul_config_pdu->uci_cqi_sr_harq_pdu.harq_information; + break; + + case NFAPI_UL_CONFIG_UCI_CQI_SR_HARQ_PDU_TYPE: + /* nothing to do */ + break; } } if (ulsch_harq_information) fill_nfapi_ulsch_harq_information(module_idP, CC_idP, rnti, ulsch_harq_information, subframeP); if (harq_information) fill_nfapi_harq_information(module_idP, CC_idP, - rnti, - (frameP * 10) + subframeP, - harq_information, cce_idx); + rnti, + (frameP * 10) + subframeP, + harq_information, cce_idx); } -uint8_t get_V_UL_DAI(module_id_t module_idP, int CC_idP, uint16_t rntiP,sub_frame_t subframeP) -{ +uint8_t get_V_UL_DAI(module_id_t module_idP, int CC_idP, uint16_t rntiP,sub_frame_t subframeP) { nfapi_hi_dci0_request_body_t *HI_DCI0_req = &RC.mac[module_idP]->HI_DCI0_req[CC_idP][subframeP].hi_dci0_request_body; nfapi_hi_dci0_request_pdu_t *hi_dci0_pdu = &HI_DCI0_req->hi_dci0_pdu_list[0]; for (int i = 0; i < HI_DCI0_req->number_of_dci; i++) { if ((hi_dci0_pdu[i].pdu_type == NFAPI_HI_DCI0_DCI_PDU_TYPE) && - (hi_dci0_pdu[i].dci_pdu.dci_pdu_rel8.rnti == rntiP)) + (hi_dci0_pdu[i].dci_pdu.dci_pdu_rel8.rnti == rntiP)) return (hi_dci0_pdu[i].dci_pdu.dci_pdu_rel8.dl_assignment_index); } - return (4); // this is rule from Section 7.3 in 36.213 + + return (4); // this is rule from Section 7.3 in 36.213 } void fill_nfapi_ulsch_harq_information(module_id_t module_idP, - int CC_idP, - uint16_t rntiP, - nfapi_ul_config_ulsch_harq_information *harq_information, - sub_frame_t subframeP) + int CC_idP, + uint16_t rntiP, + nfapi_ul_config_ulsch_harq_information *harq_information, + sub_frame_t subframeP) { eNB_MAC_INST *eNB = RC.mac[module_idP]; COMMON_channels_t *cc = &eNB->common_channels[CC_idP]; UE_list_t *UE_list = &eNB->UE_list; - int UE_id = find_UE_id(module_idP, rntiP); - LTE_PUSCH_ConfigDedicated_t *puschConfigDedicated; // PUSCH_ConfigDedicated_v1020_t *puschConfigDedicated_v1020; // PUSCH_ConfigDedicated_v1130_t *puschConfigDedicated_v1130; // PUSCH_ConfigDedicated_v1250_t *puschConfigDedicated_v1250; - AssertFatal(UE_id >= 0, "UE_id cannot be found, impossible\n"); AssertFatal(UE_list != NULL, "UE_list is null\n"); AssertFatal(UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated != NULL, - "physicalConfigDedicated for rnti %x is null\n", rntiP); + "physicalConfigDedicated for rnti %x is null\n", rntiP); AssertFatal((puschConfigDedicated = (LTE_PUSCH_ConfigDedicated_t *) - UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated->pusch_ConfigDedicated) != NULL, - "physicalConfigDedicated->puschConfigDedicated for rnti %x is null\n", - rntiP); + UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated->pusch_ConfigDedicated) != NULL, + "physicalConfigDedicated->puschConfigDedicated for rnti %x is null\n", + rntiP); #if (LTE_RRC_VERSION >= MAKE_VERSION(10, 2, 0)) /* if (UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated->ext2) puschConfigDedicated_v1020 = UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated->ext2->pusch_ConfigDedicated_v1020; #endif @@ -1289,51 +1336,54 @@ fill_nfapi_ulsch_harq_information(module_id_t module_ harq_information->harq_information_rel10.delta_offset_harq = puschConfigDedicated->betaOffset_ACK_Index; harq_information->harq_information_rel10.tl.tag = NFAPI_UL_CONFIG_REQUEST_ULSCH_HARQ_INFORMATION_REL10_TAG; AssertFatal(UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated->pucch_ConfigDedicated != NULL, - "pucch_ConfigDedicated is null!\n"); + "pucch_ConfigDedicated is null!\n"); + if ((UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated->pucch_ConfigDedicated->tdd_AckNackFeedbackMode != NULL) && (*UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated->pucch_ConfigDedicated->tdd_AckNackFeedbackMode == LTE_PUCCH_ConfigDedicated__tdd_AckNackFeedbackMode_multiplexing)) - harq_information->harq_information_rel10.ack_nack_mode = 1; // multiplexing + harq_information->harq_information_rel10.ack_nack_mode = 1; // multiplexing else - harq_information->harq_information_rel10.ack_nack_mode = 0; // bundling + harq_information->harq_information_rel10.ack_nack_mode = 0; // bundling switch (get_tmode(module_idP, CC_idP, UE_id)) { - case 1: - case 2: - case 5: - case 6: - case 7: - if (cc->tdd_Config == NULL) // FDD - harq_information->harq_information_rel10.harq_size = 1; - else { - if (harq_information->harq_information_rel10.ack_nack_mode == 1) - harq_information->harq_information_rel10.harq_size = get_V_UL_DAI(module_idP, CC_idP, rntiP, subframeP); - else + case 1: + case 2: + case 5: + case 6: + case 7: + if (cc->tdd_Config == NULL) // FDD harq_information->harq_information_rel10.harq_size = 1; - } - break; - default: // for any other TM we need 2 bits harq - if (cc->tdd_Config == NULL) { - harq_information->harq_information_rel10.harq_size = 2; - } else { - if (harq_information->harq_information_rel10.ack_nack_mode == 1) - harq_information->harq_information_rel10.harq_size = get_V_UL_DAI(module_idP, CC_idP, rntiP, subframeP); - else - harq_information->harq_information_rel10.harq_size = 2; - } - break; - } // get Tmode + else { + if (harq_information->harq_information_rel10.ack_nack_mode == 1) + harq_information->harq_information_rel10.harq_size = get_V_UL_DAI(module_idP, CC_idP, rntiP, subframeP); + else + harq_information->harq_information_rel10.harq_size = 1; + } + break; + + default: // for any other TM we need 2 bits harq + if (cc->tdd_Config == NULL) { + harq_information->harq_information_rel10.harq_size = 2; + } else { + if (harq_information->harq_information_rel10.ack_nack_mode == 1) + harq_information->harq_information_rel10.harq_size = get_V_UL_DAI(module_idP, CC_idP, rntiP, subframeP); + else + harq_information->harq_information_rel10.harq_size = 2; + } + break; + } // get Tmode + return; } uint8_t Np[6][4]= {{0,1,3,5}, - {0,3,8,13}, - {0,5,13,22}, - {0,11,27,44}, - {0,16,41,66}, - {0,22,55,88}}; + {0,3,8,13}, + {0,5,13,22}, + {0,11,27,44}, + {0,16,41,66}, + {0,22,55,88} +}; // This is part of the PUCCH allocation procedure (see Section 10.1 36.213) -uint16_t getNp(int dl_Bandwidth,uint8_t nCCE,uint8_t plus1) -{ +uint16_t getNp(int dl_Bandwidth,uint8_t nCCE,uint8_t plus1) { AssertFatal(dl_Bandwidth<6,"dl_Bandwidth %d>5\n",dl_Bandwidth); if (nCCE>=Np[dl_Bandwidth][2]) @@ -1346,152 +1396,146 @@ uint16_t getNp(int dl_Bandwidth,uint8_t nCCE,uint8_t plus1) void fill_nfapi_harq_information(module_id_t module_idP, - int CC_idP, - uint16_t rntiP, - uint16_t absSFP, - nfapi_ul_config_harq_information *harq_information, - uint8_t cce_idxP) -{ + int CC_idP, + uint16_t rntiP, + uint16_t absSFP, + nfapi_ul_config_harq_information *harq_information, + uint8_t cce_idxP) { eNB_MAC_INST *eNB = RC.mac[module_idP]; COMMON_channels_t *cc = &eNB->common_channels[CC_idP]; UE_list_t *UE_list = &eNB->UE_list; - int UE_id = find_UE_id(module_idP, rntiP); - AssertFatal(UE_id >= 0, "UE_id cannot be found, impossible\n"); AssertFatal(UE_list != NULL, "UE_list is null\n"); - harq_information->harq_information_rel11.tl.tag = NFAPI_UL_CONFIG_REQUEST_HARQ_INFORMATION_REL11_TAG; harq_information->harq_information_rel11.num_ant_ports = 1; switch (get_tmode(module_idP, CC_idP, UE_id)) { - case 1: - case 2: - case 5: - case 6: - case 7: - if (cc->tdd_Config != NULL) { -// AssertFatal(UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated->pucch_ConfigDedicated != NULL, -// "pucch_ConfigDedicated is null for TDD!\n"); - if (UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated != NULL - && UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated->pucch_ConfigDedicated != NULL - && (UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated->pucch_ConfigDedicated->tdd_AckNackFeedbackMode != NULL) - && (*UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated->pucch_ConfigDedicated->tdd_AckNackFeedbackMode == LTE_PUCCH_ConfigDedicated__tdd_AckNackFeedbackMode_multiplexing)) - { - harq_information->harq_information_rel10_tdd.harq_size = 2; // 2-bit ACK/NAK - harq_information->harq_information_rel10_tdd.ack_nack_mode = 1; // multiplexing + case 1: + case 2: + case 5: + case 6: + case 7: + if (cc->tdd_Config != NULL) { + // AssertFatal(UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated->pucch_ConfigDedicated != NULL, + // "pucch_ConfigDedicated is null for TDD!\n"); + if (UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated != NULL + && UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated->pucch_ConfigDedicated != NULL + && (UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated->pucch_ConfigDedicated->tdd_AckNackFeedbackMode != NULL) + && (*UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated->pucch_ConfigDedicated->tdd_AckNackFeedbackMode == LTE_PUCCH_ConfigDedicated__tdd_AckNackFeedbackMode_multiplexing)) { + harq_information->harq_information_rel10_tdd.harq_size = 2; // 2-bit ACK/NAK + harq_information->harq_information_rel10_tdd.ack_nack_mode = 1; // multiplexing + } else { + harq_information->harq_information_rel10_tdd.harq_size = 1; // 1-bit ACK/NAK + harq_information->harq_information_rel10_tdd.ack_nack_mode = 0; // bundling + } + + harq_information->harq_information_rel10_tdd.tl.tag = NFAPI_UL_CONFIG_REQUEST_HARQ_INFORMATION_REL10_TDD_TAG; + harq_information->harq_information_rel10_tdd.n_pucch_1_0 = getNp(cc->mib->message.dl_Bandwidth,cce_idxP,0) + + cc->radioResourceConfigCommon->pucch_ConfigCommon.n1PUCCH_AN + cce_idxP; + harq_information->harq_information_rel10_tdd.number_of_pucch_resources = 1; } else { - harq_information->harq_information_rel10_tdd.harq_size = 1; // 1-bit ACK/NAK - harq_information->harq_information_rel10_tdd.ack_nack_mode = 0; // bundling + harq_information->harq_information_rel9_fdd.tl.tag = NFAPI_UL_CONFIG_REQUEST_HARQ_INFORMATION_REL9_FDD_TAG; + harq_information->harq_information_rel9_fdd.number_of_pucch_resources = 1; + harq_information->harq_information_rel9_fdd.harq_size = 1; // 1-bit ACK/NAK + harq_information->harq_information_rel9_fdd.n_pucch_1_0 = cc->radioResourceConfigCommon->pucch_ConfigCommon.n1PUCCH_AN + cce_idxP; } - harq_information->harq_information_rel10_tdd.tl.tag = NFAPI_UL_CONFIG_REQUEST_HARQ_INFORMATION_REL10_TDD_TAG; - harq_information->harq_information_rel10_tdd.n_pucch_1_0 = getNp(cc->mib->message.dl_Bandwidth,cce_idxP,0) + - cc->radioResourceConfigCommon->pucch_ConfigCommon.n1PUCCH_AN + cce_idxP; - harq_information->harq_information_rel10_tdd.number_of_pucch_resources = 1; - } else { - harq_information->harq_information_rel9_fdd.tl.tag = NFAPI_UL_CONFIG_REQUEST_HARQ_INFORMATION_REL9_FDD_TAG; - harq_information->harq_information_rel9_fdd.number_of_pucch_resources = 1; - harq_information->harq_information_rel9_fdd.harq_size = 1; // 1-bit ACK/NAK - harq_information->harq_information_rel9_fdd.n_pucch_1_0 = cc->radioResourceConfigCommon->pucch_ConfigCommon.n1PUCCH_AN + cce_idxP; - } - break; - default: // for any other TM we need 2 bits harq - if (cc->tdd_Config != NULL) { - AssertFatal(UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated->pucch_ConfigDedicated != NULL, - "pucch_ConfigDedicated is null for TDD!\n"); - if ((UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated->pucch_ConfigDedicated->tdd_AckNackFeedbackMode != NULL) - && (*UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated->pucch_ConfigDedicated->tdd_AckNackFeedbackMode == LTE_PUCCH_ConfigDedicated__tdd_AckNackFeedbackMode_multiplexing)) { - harq_information->harq_information_rel10_tdd.ack_nack_mode = 1; // multiplexing + + break; + + default: // for any other TM we need 2 bits harq + if (cc->tdd_Config != NULL) { + AssertFatal(UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated->pucch_ConfigDedicated != NULL, + "pucch_ConfigDedicated is null for TDD!\n"); + + if ((UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated->pucch_ConfigDedicated->tdd_AckNackFeedbackMode != NULL) + && (*UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated->pucch_ConfigDedicated->tdd_AckNackFeedbackMode == LTE_PUCCH_ConfigDedicated__tdd_AckNackFeedbackMode_multiplexing)) { + harq_information->harq_information_rel10_tdd.ack_nack_mode = 1; // multiplexing + } else { + harq_information->harq_information_rel10_tdd.ack_nack_mode = 0; // bundling + } + + harq_information->harq_information_rel10_tdd.tl.tag = NFAPI_UL_CONFIG_REQUEST_HARQ_INFORMATION_REL10_TDD_TAG; + harq_information->harq_information_rel10_tdd.harq_size = 2; + harq_information->harq_information_rel10_tdd.n_pucch_1_0 = cc->radioResourceConfigCommon->pucch_ConfigCommon.n1PUCCH_AN + cce_idxP; + harq_information->harq_information_rel10_tdd.number_of_pucch_resources = 1; } else { - harq_information->harq_information_rel10_tdd.ack_nack_mode = 0; // bundling + harq_information->harq_information_rel9_fdd.tl.tag = NFAPI_UL_CONFIG_REQUEST_HARQ_INFORMATION_REL9_FDD_TAG; + harq_information->harq_information_rel9_fdd.number_of_pucch_resources = 1; + harq_information->harq_information_rel9_fdd.ack_nack_mode = 0; // 1a/b + harq_information->harq_information_rel9_fdd.harq_size = 2; + harq_information->harq_information_rel9_fdd.n_pucch_1_0 = cc->radioResourceConfigCommon->pucch_ConfigCommon.n1PUCCH_AN + cce_idxP; } - harq_information->harq_information_rel10_tdd.tl.tag = NFAPI_UL_CONFIG_REQUEST_HARQ_INFORMATION_REL10_TDD_TAG; - harq_information->harq_information_rel10_tdd.harq_size = 2; - harq_information->harq_information_rel10_tdd.n_pucch_1_0 = cc->radioResourceConfigCommon->pucch_ConfigCommon.n1PUCCH_AN + cce_idxP; - harq_information->harq_information_rel10_tdd.number_of_pucch_resources = 1; - } else { - harq_information->harq_information_rel9_fdd.tl.tag = NFAPI_UL_CONFIG_REQUEST_HARQ_INFORMATION_REL9_FDD_TAG; - harq_information->harq_information_rel9_fdd.number_of_pucch_resources = 1; - harq_information->harq_information_rel9_fdd.ack_nack_mode = 0; // 1a/b - harq_information->harq_information_rel9_fdd.harq_size = 2; - harq_information->harq_information_rel9_fdd.n_pucch_1_0 = cc->radioResourceConfigCommon->pucch_ConfigCommon.n1PUCCH_AN + cce_idxP; - } - break; - } // get Tmode + + break; + } // get Tmode } uint16_t fill_nfapi_uci_acknak(module_id_t module_idP, - int CC_idP, - uint16_t rntiP, - uint16_t absSFP, - uint8_t cce_idxP) -{ + int CC_idP, + uint16_t rntiP, + uint16_t absSFP, + uint8_t cce_idxP) { eNB_MAC_INST *eNB = RC.mac[module_idP]; COMMON_channels_t *cc = &eNB->common_channels[CC_idP]; int ackNAK_absSF = get_pucch1_absSF(cc, absSFP); nfapi_ul_config_request_t *ul_req = &eNB->UL_req_tmp[CC_idP][ackNAK_absSF % 10]; nfapi_ul_config_request_body_t *ul_req_body = &ul_req->ul_config_request_body; nfapi_ul_config_request_pdu_t *ul_config_pdu = &ul_req_body->ul_config_pdu_list[ul_req_body->number_of_pdus]; - memset((void *) ul_config_pdu, 0, sizeof(nfapi_ul_config_request_pdu_t)); ul_config_pdu->pdu_type = NFAPI_UL_CONFIG_UCI_HARQ_PDU_TYPE; ul_config_pdu->pdu_size = (uint8_t) (2 + sizeof(nfapi_ul_config_uci_harq_pdu)); ul_config_pdu->uci_harq_pdu.ue_information.ue_information_rel8.tl.tag = NFAPI_UL_CONFIG_REQUEST_UE_INFORMATION_REL8_TAG; - ul_config_pdu->uci_harq_pdu.ue_information.ue_information_rel8.handle = 0; // don't know how to use this + ul_config_pdu->uci_harq_pdu.ue_information.ue_information_rel8.handle = 0; // don't know how to use this ul_config_pdu->uci_harq_pdu.ue_information.ue_information_rel8.rnti = rntiP; - fill_nfapi_harq_information(module_idP, CC_idP, - rntiP, - absSFP, - &ul_config_pdu->uci_harq_pdu.harq_information, cce_idxP); + rntiP, + absSFP, + &ul_config_pdu->uci_harq_pdu.harq_information, cce_idxP); LOG_D(MAC, - "Filled in UCI HARQ request for rnti %x SF %d.%d acknakSF %d.%d, cce_idxP %d-> n1_pucch %d\n", - rntiP, absSFP / 10, absSFP % 10, ackNAK_absSF / 10, - ackNAK_absSF % 10, cce_idxP, - ul_config_pdu->uci_harq_pdu. - harq_information.harq_information_rel9_fdd.n_pucch_1_0); - + "Filled in UCI HARQ request for rnti %x SF %d.%d acknakSF %d.%d, cce_idxP %d-> n1_pucch %d\n", + rntiP, absSFP / 10, absSFP % 10, ackNAK_absSF / 10, + ackNAK_absSF % 10, cce_idxP, + ul_config_pdu->uci_harq_pdu. + harq_information.harq_information_rel9_fdd.n_pucch_1_0); ul_req_body->number_of_pdus++; ul_req_body->tl.tag = NFAPI_UL_CONFIG_REQUEST_BODY_TAG; ul_req->header.message_id = NFAPI_UL_CONFIG_REQUEST; ul_req->sfn_sf = (ackNAK_absSF/10) << 4 | ackNAK_absSF%10; - return (((ackNAK_absSF / 10) << 4) + (ackNAK_absSF % 10)); } void -fill_nfapi_dlsch_config(eNB_MAC_INST * eNB, - nfapi_dl_config_request_body_t * dl_req, - uint16_t length, - int16_t pdu_index, - uint16_t rnti, - uint8_t resource_allocation_type, - uint8_t - virtual_resource_block_assignment_flag, - uint16_t resource_block_coding, - uint8_t modulation, - uint8_t redundancy_version, - uint8_t transport_blocks, - uint8_t transport_block_to_codeword_swap_flag, - uint8_t transmission_scheme, - uint8_t number_of_layers, - uint8_t number_of_subbands, - // uint8_t codebook_index, - uint8_t ue_category_capacity, - uint8_t pa, - uint8_t delta_power_offset_index, - uint8_t ngap, - uint8_t nprb, - uint8_t transmission_mode, - uint8_t num_bf_prb_per_subband, - uint8_t num_bf_vector) -{ +fill_nfapi_dlsch_config(eNB_MAC_INST *eNB, + nfapi_dl_config_request_body_t *dl_req, + uint16_t length, + int16_t pdu_index, + uint16_t rnti, + uint8_t resource_allocation_type, + uint8_t + virtual_resource_block_assignment_flag, + uint16_t resource_block_coding, + uint8_t modulation, + uint8_t redundancy_version, + uint8_t transport_blocks, + uint8_t transport_block_to_codeword_swap_flag, + uint8_t transmission_scheme, + uint8_t number_of_layers, + uint8_t number_of_subbands, + // uint8_t codebook_index, + uint8_t ue_category_capacity, + uint8_t pa, + uint8_t delta_power_offset_index, + uint8_t ngap, + uint8_t nprb, + uint8_t transmission_mode, + uint8_t num_bf_prb_per_subband, + uint8_t num_bf_vector) { nfapi_dl_config_request_pdu_t *dl_config_pdu = &dl_req->dl_config_pdu_list[dl_req->number_pdu]; memset((void *) dl_config_pdu, 0, - sizeof(nfapi_dl_config_request_pdu_t)); - + sizeof(nfapi_dl_config_request_pdu_t)); dl_config_pdu->pdu_type = NFAPI_DL_CONFIG_DLSCH_PDU_TYPE; dl_config_pdu->pdu_size = (uint8_t) (2 + sizeof(nfapi_dl_config_dlsch_pdu)); dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.tl.tag = NFAPI_DL_CONFIG_REQUEST_DLSCH_PDU_REL8_TAG; @@ -1522,15 +1566,13 @@ fill_nfapi_dlsch_config(eNB_MAC_INST * eNB, uint16_t fill_nfapi_tx_req(nfapi_tx_request_body_t *tx_req_body, - uint16_t absSF, - uint16_t pdu_length, - int16_t pdu_index, - uint8_t *pdu) -{ + uint16_t absSF, + uint16_t pdu_length, + int16_t pdu_index, + uint8_t *pdu) { nfapi_tx_request_pdu_t *TX_req = &tx_req_body->tx_pdu_list[tx_req_body->number_of_pdus]; LOG_D(MAC, "Filling TX_req %d for pdu length %d\n", - tx_req_body->number_of_pdus, pdu_length); - + tx_req_body->number_of_pdus, pdu_length); TX_req->pdu_length = pdu_length; TX_req->pdu_index = pdu_index; TX_req->num_segments = 1; @@ -1538,34 +1580,34 @@ fill_nfapi_tx_req(nfapi_tx_request_body_t *tx_req_body, TX_req->segments[0].segment_data = pdu; tx_req_body->tl.tag = NFAPI_TX_REQUEST_BODY_TAG; tx_req_body->number_of_pdus++; - return (((absSF / 10) << 4) + (absSF % 10)); } void -fill_nfapi_ulsch_config_request_rel8(nfapi_ul_config_request_pdu_t *ul_config_pdu, - uint8_t cqi_req, - COMMON_channels_t *cc, - struct LTE_PhysicalConfigDedicated *physicalConfigDedicated, - uint8_t tmode, - uint32_t handle, - uint16_t rnti, - uint8_t resource_block_start, - uint8_t number_of_resource_blocks, - uint8_t mcs, - uint8_t cyclic_shift_2_for_drms, - uint8_t frequency_hopping_enabled_flag, - uint8_t frequency_hopping_bits, - uint8_t new_data_indication, - uint8_t redundancy_version, - uint8_t harq_process_number, - uint8_t ul_tx_mode, - uint8_t current_tx_nb, - uint8_t n_srs, - uint16_t size) +fill_nfapi_ulsch_config_request_rel8(nfapi_ul_config_request_pdu_t *ul_config_pdu, + uint8_t cqi_req, + COMMON_channels_t *cc, + struct LTE_PhysicalConfigDedicated *physicalConfigDedicated, + uint8_t tmode, + uint32_t handle, + uint16_t rnti, + uint8_t resource_block_start, + uint8_t number_of_resource_blocks, + uint8_t mcs, + uint8_t cyclic_shift_2_for_drms, + uint8_t frequency_hopping_enabled_flag, + uint8_t frequency_hopping_bits, + uint8_t new_data_indication, + uint8_t redundancy_version, + uint8_t harq_process_number, + uint8_t ul_tx_mode, + uint8_t current_tx_nb, + uint8_t n_srs, + uint16_t size) { - memset((void *) ul_config_pdu, 0, sizeof(nfapi_ul_config_request_pdu_t)); + uint8_t ri_size = 0; + memset((void *) ul_config_pdu, 0, sizeof(nfapi_ul_config_request_pdu_t)); ul_config_pdu->pdu_type = NFAPI_UL_CONFIG_ULSCH_PDU_TYPE; ul_config_pdu->pdu_size = (uint8_t) (2 + sizeof(nfapi_ul_config_ulsch_pdu)); ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8.tl.tag = NFAPI_UL_CONFIG_REQUEST_ULSCH_PDU_REL8_TAG; @@ -1573,10 +1615,12 @@ fill_nfapi_ulsch_config_request_rel8(nfapi_ul_config_request_pdu_t *ul_config_pd ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8.rnti = rnti; ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8.resource_block_start = resource_block_start; ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8.number_of_resource_blocks = number_of_resource_blocks; + if (mcs < 11) ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8.modulation_type = 2; else if (mcs < 21) ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8.modulation_type = 4; else if(mcs < 29) ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8.modulation_type = 6; else ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8.modulation_type = 0; + ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8.cyclic_shift_2_for_drms = cyclic_shift_2_for_drms; ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8.frequency_hopping_enabled_flag = frequency_hopping_enabled_flag; ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8.frequency_hopping_bits = frequency_hopping_bits; @@ -1597,37 +1641,37 @@ fill_nfapi_ulsch_config_request_rel8(nfapi_ul_config_request_pdu_t *ul_config_pd ul_config_pdu->ulsch_cqi_ri_pdu.cqi_ri_information.cqi_ri_information_rel9.aperiodic_cqi_pmi_ri_report.number_of_cc = 1; LOG_D(MAC, "report_type %d\n",ul_config_pdu->ulsch_cqi_ri_pdu.cqi_ri_information.cqi_ri_information_rel9.report_type); - if (cc->p_eNB <= 2 - && (tmode == 3 || tmode == 4 || tmode == 8 || tmode == 9 || tmode == 10)) - ul_config_pdu->ulsch_cqi_ri_pdu.cqi_ri_information.cqi_ri_information_rel9.aperiodic_cqi_pmi_ri_report.cc[0].ri_size = 1; - else if (cc->p_eNB <= 2) ul_config_pdu->ulsch_cqi_ri_pdu.cqi_ri_information.cqi_ri_information_rel9.aperiodic_cqi_pmi_ri_report.cc[0].ri_size = 0; - else if (cc->p_eNB == 4) ul_config_pdu->ulsch_cqi_ri_pdu.cqi_ri_information.cqi_ri_information_rel9.aperiodic_cqi_pmi_ri_report.cc[0].ri_size = 2; + if (cc->p_eNB <= 2 && (tmode == 3 || tmode == 4 || tmode == 8 || tmode == 9 || tmode == 10)) ri_size = 1; + else if (cc->p_eNB <= 2) ri_size = 0; + else if (cc->p_eNB == 4) ri_size = 2; + ul_config_pdu->ulsch_cqi_ri_pdu.cqi_ri_information.cqi_ri_information_rel9.aperiodic_cqi_pmi_ri_report.cc[0].ri_size = ri_size; AssertFatal(physicalConfigDedicated->cqi_ReportConfig != NULL,"physicalConfigDedicated->cqi_ReportConfig is null!\n"); AssertFatal(physicalConfigDedicated->cqi_ReportConfig->cqi_ReportModeAperiodic != NULL,"physicalConfigDedicated->cqi_ReportModeAperiodic is null!\n"); AssertFatal(physicalConfigDedicated->pusch_ConfigDedicated != NULL,"physicalConfigDedicated->puschConfigDedicated is null!\n"); - for (int ri = 0; - ri < (1 << ul_config_pdu->ulsch_cqi_ri_pdu.cqi_ri_information.cqi_ri_information_rel9.aperiodic_cqi_pmi_ri_report.cc[0].ri_size); - ri++) - ul_config_pdu->ulsch_cqi_ri_pdu.cqi_ri_information.cqi_ri_information_rel9.aperiodic_cqi_pmi_ri_report.cc[0].dl_cqi_pmi_size[ri] = get_dl_cqi_pmi_size_pusch(cc,tmode,1 + ri,physicalConfigDedicated->cqi_ReportConfig->cqi_ReportModeAperiodic); + for (int ri = 0; ri < (1 << ri_size); ri++) { + ul_config_pdu->ulsch_cqi_ri_pdu.cqi_ri_information.cqi_ri_information_rel9.aperiodic_cqi_pmi_ri_report.cc[0].dl_cqi_pmi_size[ri] = + get_dl_cqi_pmi_size_pusch(cc,tmode,1 + ri, physicalConfigDedicated->cqi_ReportConfig->cqi_ReportModeAperiodic); + } - ul_config_pdu->ulsch_cqi_ri_pdu.cqi_ri_information.cqi_ri_information_rel9.delta_offset_cqi = physicalConfigDedicated->pusch_ConfigDedicated->betaOffset_CQI_Index; - ul_config_pdu->ulsch_cqi_ri_pdu.cqi_ri_information.cqi_ri_information_rel9.delta_offset_ri = physicalConfigDedicated->pusch_ConfigDedicated->betaOffset_RI_Index; + ul_config_pdu->ulsch_cqi_ri_pdu.cqi_ri_information.cqi_ri_information_rel9.delta_offset_cqi = + physicalConfigDedicated->pusch_ConfigDedicated->betaOffset_CQI_Index; + ul_config_pdu->ulsch_cqi_ri_pdu.cqi_ri_information.cqi_ri_information_rel9.delta_offset_ri = + physicalConfigDedicated->pusch_ConfigDedicated->betaOffset_RI_Index; } } #if (LTE_RRC_VERSION >= MAKE_VERSION(13, 0, 0)) void fill_nfapi_ulsch_config_request_emtc(nfapi_ul_config_request_pdu_t * - ul_config_pdu, uint8_t ue_type, - uint16_t - total_number_of_repetitions, - uint16_t repetition_number, - uint16_t initial_transmission_sf_io) + ul_config_pdu, uint8_t ue_type, + uint16_t + total_number_of_repetitions, + uint16_t repetition_number, + uint16_t initial_transmission_sf_io) { // Re13 fields - ul_config_pdu->ulsch_pdu.ulsch_pdu_rel13.tl.tag = NFAPI_UL_CONFIG_REQUEST_ULSCH_PDU_REL13_TAG; ul_config_pdu->ulsch_pdu.ulsch_pdu_rel13.ue_type = ue_type; ul_config_pdu->ulsch_pdu.ulsch_pdu_rel13.total_number_of_repetitions = total_number_of_repetitions; @@ -1635,18 +1679,14 @@ fill_nfapi_ulsch_config_request_emtc(nfapi_ul_config_request_pdu_t * ul_config_pdu->ulsch_pdu.ulsch_pdu_rel13.initial_transmission_sf_io = initial_transmission_sf_io; } -int get_numnarrowbands(long dl_Bandwidth) -{ +int get_numnarrowbands(long dl_Bandwidth) { int nb_tab[6] = { 1, 2, 4, 8, 12, 16 }; - AssertFatal(dl_Bandwidth < 7 || dl_Bandwidth >= 0, "dl_Bandwidth not in [0..6]\n"); return (nb_tab[dl_Bandwidth]); } -int get_numnarrowbandbits(long dl_Bandwidth) -{ +int get_numnarrowbandbits(long dl_Bandwidth) { int nbbits_tab[6] = { 0, 1, 2, 3, 4, 4 }; - AssertFatal(dl_Bandwidth < 7 || dl_Bandwidth >= 0, "dl_Bandwidth not in [0..6]\n"); return (nbbits_tab[dl_Bandwidth]); } @@ -1656,99 +1696,114 @@ int startSF_fdd_RA_times2[8] = { 2, 3, 4, 5, 8, 10, 16, 20 }; int startSF_tdd_RA[7] = { 1, 2, 4, 5, 8, 10, 20 }; int -mpdcch_sf_condition(eNB_MAC_INST * eNB, int CC_id, frame_t frameP, - sub_frame_t subframeP, int rmax, - MPDCCH_TYPES_t mpdcch_type, int UE_id) -{ +mpdcch_sf_condition(eNB_MAC_INST *eNB, int CC_id, frame_t frameP, + sub_frame_t subframeP, int rmax, + MPDCCH_TYPES_t mpdcch_type, int UE_id) { struct LTE_PRACH_ConfigSIB_v1310 *ext4_prach = - eNB->common_channels[CC_id].radioResourceConfigCommon_BR-> - ext4->prach_ConfigCommon_v1310; - + eNB->common_channels[CC_id].radioResourceConfigCommon_BR-> + ext4->prach_ConfigCommon_v1310; int T; LTE_EPDCCH_SetConfig_r11_t *epdcch_setconfig_r11; switch (mpdcch_type) { - case TYPE0: - AssertFatal(1 == 0, "MPDCCH Type 0 not handled yet\n"); - break; - case TYPE1: - AssertFatal(1 == 0, "MPDCCH Type 1 not handled yet\n"); - break; - case TYPE1A: - AssertFatal(1 == 0, "MPDCCH Type 1A not handled yet\n"); - break; - case TYPE2: // RAR - AssertFatal(ext4_prach->mpdcch_startSF_CSS_RA_r13 != NULL, - "mpdcch_startSF_CSS_RA_r13 is null\n"); - AssertFatal(rmax > 0, "rmax is 0!\b"); - if (eNB->common_channels[CC_id].tdd_Config == NULL) //FDD - T = rmax *startSF_fdd_RA_times2[ext4_prach-> - mpdcch_startSF_CSS_RA_r13-> - choice.fdd_r13] >> 1; - else //TDD - T = rmax *startSF_tdd_RA[ext4_prach-> - mpdcch_startSF_CSS_RA_r13->choice.tdd_r13]; - break; - case TYPE2A: - AssertFatal(1 == 0, "MPDCCH Type 2A not handled yet\n"); - break; - case TYPEUESPEC: - epdcch_setconfig_r11 = - eNB->UE_list.UE_template[CC_id][UE_id].physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.choice.setup.setConfigToAddModList_r11->list.array[0]; - - AssertFatal(epdcch_setconfig_r11 != NULL, - " epdcch_setconfig_r11 is null for UE specific \n"); - AssertFatal(epdcch_setconfig_r11->ext2 != NULL, - " ext2 doesn't exist in epdcch config ' \n"); - - if (eNB->common_channels[CC_id].tdd_Config == NULL) //FDD - T = rmax *startSF_fdd_RA_times2[epdcch_setconfig_r11->ext2->mpdcch_config_r13->choice.setup.mpdcch_StartSF_UESS_r13.choice.fdd_r13] >> 1; - else //TDD - T = rmax *startSF_tdd_RA[epdcch_setconfig_r11->ext2->mpdcch_config_r13->choice.setup.mpdcch_StartSF_UESS_r13.choice.tdd_r13]; - break; - default: - return (0); + case TYPE0: + AssertFatal(1 == 0, "MPDCCH Type 0 not handled yet\n"); + break; + + case TYPE1: + AssertFatal(1 == 0, "MPDCCH Type 1 not handled yet\n"); + break; + + case TYPE1A: + AssertFatal(1 == 0, "MPDCCH Type 1A not handled yet\n"); + break; + + case TYPE2: // RAR + AssertFatal(ext4_prach->mpdcch_startSF_CSS_RA_r13 != NULL, + "mpdcch_startSF_CSS_RA_r13 is null\n"); + AssertFatal(rmax > 0, "rmax is 0!\b"); + + if (eNB->common_channels[CC_id].tdd_Config == NULL) //FDD + T = rmax *startSF_fdd_RA_times2[ext4_prach-> + mpdcch_startSF_CSS_RA_r13-> + choice.fdd_r13] >> 1; + else //TDD + T = rmax *startSF_tdd_RA[ext4_prach-> + mpdcch_startSF_CSS_RA_r13->choice.tdd_r13]; + + break; + + case TYPE2A: + AssertFatal(1 == 0, "MPDCCH Type 2A not handled yet\n"); + break; + + case TYPEUESPEC: + epdcch_setconfig_r11 = + eNB->UE_list.UE_template[CC_id][UE_id].physicalConfigDedicated->ext4->epdcch_Config_r11->config_r11.choice.setup.setConfigToAddModList_r11->list.array[0]; + AssertFatal(epdcch_setconfig_r11 != NULL, + " epdcch_setconfig_r11 is null for UE specific \n"); + AssertFatal(epdcch_setconfig_r11->ext2 != NULL, + " ext2 doesn't exist in epdcch config ' \n"); + + if (eNB->common_channels[CC_id].tdd_Config == NULL) //FDD + T = rmax *startSF_fdd_RA_times2[epdcch_setconfig_r11->ext2->mpdcch_config_r13->choice.setup.mpdcch_StartSF_UESS_r13.choice.fdd_r13] >> 1; + else //TDD + T = rmax *startSF_tdd_RA[epdcch_setconfig_r11->ext2->mpdcch_config_r13->choice.setup.mpdcch_StartSF_UESS_r13.choice.tdd_r13]; + + break; + + default: + return (0); } AssertFatal(T > 0, "T is 0!\n"); + if (((10 * frameP) + subframeP) % T == 0) return (1); else return (0); } -int narrowband_to_first_rb(COMMON_channels_t * cc, int nb_index) -{ +int narrowband_to_first_rb(COMMON_channels_t *cc, int nb_index) { switch (cc->mib->message.dl_Bandwidth) { - case 0: // 6 PRBs, N_NB=1, i_0=0 - return (0); - break; - case 3: // 50 PRBs, N_NB=8, i_0=1 - return ((int) (1 + (6 * nb_index))); - break; - case 5: // 100 PRBs, N_NB=16, i_0=2 - return ((int) (2 + (6 * nb_index))); - break; - case 1: // 15 PRBs N_NB=2, i_0=1 - if (nb_index > 0) - return (1); - else + case 0: // 6 PRBs, N_NB=1, i_0=0 return (0); - break; - case 2: // 25 PRBs, N_NB=4, i_0=0 - if (nb_index > 1) - return (1 + (6 * nb_index)); - else - return ((6 * nb_index)); - break; - case 4: // 75 PRBs, N_NB=12, i_0=1 - if (nb_index > 5) - return (2 + (6 * nb_index)); - else - return (1 + (6 * nb_index)); - break; - default: - AssertFatal(1 == 0, "Impossible dl_Bandwidth %d\n", - (int) cc->mib->message.dl_Bandwidth); - break; + break; + + case 3: // 50 PRBs, N_NB=8, i_0=1 + return ((int) (1 + (6 * nb_index))); + break; + + case 5: // 100 PRBs, N_NB=16, i_0=2 + return ((int) (2 + (6 * nb_index))); + break; + + case 1: // 15 PRBs N_NB=2, i_0=1 + if (nb_index > 0) + return (1); + else + return (0); + + break; + + case 2: // 25 PRBs, N_NB=4, i_0=0 + if (nb_index > 1) + return (1 + (6 * nb_index)); + else + return ((6 * nb_index)); + + break; + + case 4: // 75 PRBs, N_NB=12, i_0=1 + if (nb_index > 5) + return (2 + (6 * nb_index)); + else + return (1 + (6 * nb_index)); + + break; + + default: + AssertFatal(1 == 0, "Impossible dl_Bandwidth %d\n", + (int) cc->mib->message.dl_Bandwidth); + break; } } #endif @@ -1762,15 +1817,15 @@ void init_ue_sched_info(void) for (i = 0; i < NUMBER_OF_eNB_MAX; i++) { for (k = 0; k < MAX_NUM_CCs; k++) { for (j = 0; j < MAX_MOBILES_PER_ENB; j++) { - // init DL - eNB_dlsch_info[i][k][j].weight = 0; - eNB_dlsch_info[i][k][j].subframe = 0; - eNB_dlsch_info[i][k][j].serving_num = 0; - eNB_dlsch_info[i][k][j].status = S_DL_NONE; - // init UL - eNB_ulsch_info[i][k][j].subframe = 0; - eNB_ulsch_info[i][k][j].serving_num = 0; - eNB_ulsch_info[i][k][j].status = S_UL_NONE; + // init DL + eNB_dlsch_info[i][k][j].weight = 0; + eNB_dlsch_info[i][k][j].subframe = 0; + eNB_dlsch_info[i][k][j].serving_num = 0; + eNB_dlsch_info[i][k][j].status = S_DL_NONE; + // init UL + eNB_ulsch_info[i][k][j].subframe = 0; + eNB_ulsch_info[i][k][j].serving_num = 0; + eNB_ulsch_info[i][k][j].status = S_UL_NONE; } } } @@ -1795,8 +1850,9 @@ int find_UE_id(module_id_t mod_idP, rnti_t rntiP) for (UE_id = 0; UE_id < MAX_MOBILES_PER_ENB; UE_id++) { if (UE_list->active[UE_id] != TRUE) continue; + if (UE_list->UE_template[UE_PCCID(mod_idP, UE_id)][UE_id].rnti == - rntiP) { + rntiP) { return (UE_id); } } @@ -1810,23 +1866,23 @@ int find_RA_id(module_id_t mod_idP, int CC_idP, rnti_t rntiP) { int RA_id; AssertFatal(RC.mac[mod_idP], "RC.mac[%d] is null\n", mod_idP); - RA_t *ra = (RA_t *) & RC.mac[mod_idP]->common_channels[CC_idP].ra[0]; for (RA_id = 0; RA_id < NB_RA_PROC_MAX; RA_id++) { LOG_D(MAC, - "Checking RA_id %d for %x : state %d\n", - RA_id, rntiP, ra[RA_id].state); + "Checking RA_id %d for %x : state %d\n", + RA_id, rntiP, ra[RA_id].state); if (ra[RA_id].state != IDLE && - ra[RA_id].rnti == rntiP) + ra[RA_id].rnti == rntiP) return (RA_id); } + return (-1); } //------------------------------------------------------------------------------ -int UE_num_active_CC(UE_list_t * listP, int ue_idP) +int UE_num_active_CC(UE_list_t *listP, int ue_idP) //------------------------------------------------------------------------------ { return (listP->numactiveCCs[ue_idP]); @@ -1837,6 +1893,7 @@ int UE_PCCID(module_id_t mod_idP, int ue_idP) //------------------------------------------------------------------------------ { if (!RC.mac || !RC.mac[mod_idP]) return 0; + return (RC.mac[mod_idP]->UE_list.pCC_id[ue_idP]); } @@ -1845,6 +1902,7 @@ rnti_t UE_RNTI(module_id_t mod_idP, int ue_idP) //------------------------------------------------------------------------------ { if (!RC.mac || !RC.mac[mod_idP]) return 0; + rnti_t rnti = RC.mac[mod_idP]-> UE_list.UE_template[UE_PCCID(mod_idP, ue_idP)][ue_idP].rnti; @@ -1863,47 +1921,48 @@ boolean_t is_UE_active(module_id_t mod_idP, int ue_idP) //------------------------------------------------------------------------------ { if (!RC.mac || !RC.mac[mod_idP]) return 0; + return (RC.mac[mod_idP]->UE_list.active[ue_idP]); } unsigned char -get_aggregation(uint8_t bw_index, uint8_t cqi, uint8_t dci_fmt) -{ +get_aggregation(uint8_t bw_index, uint8_t cqi, uint8_t dci_fmt) { unsigned char aggregation = 3; switch (dci_fmt) { - case format0: - aggregation = cqi2fmt0_agg[bw_index][cqi]; - break; - case format1: - case format1A: - case format1B: - case format1D: - aggregation = cqi2fmt1x_agg[bw_index][cqi]; - break; - case format2: - case format2A: - case format2B: - case format2C: - case format2D: - aggregation = cqi2fmt2x_agg[bw_index][cqi]; - break; - case format1C: - case format1E_2A_M10PRB: - case format3: - case format3A: - case format4: - default: - LOG_W(MAC, "unsupported DCI format %d\n", dci_fmt); + case format0: + aggregation = cqi2fmt0_agg[bw_index][cqi]; + break; + + case format1: + case format1A: + case format1B: + case format1D: + aggregation = cqi2fmt1x_agg[bw_index][cqi]; + break; + + case format2: + case format2A: + case format2B: + case format2C: + case format2D: + aggregation = cqi2fmt2x_agg[bw_index][cqi]; + break; + + case format1C: + case format1E_2A_M10PRB: + case format3: + case format3A: + case format4: + default: + LOG_W(MAC, "unsupported DCI format %d\n", dci_fmt); } LOG_D(MAC, "Aggregation level %d (cqi %d, bw_index %d, format %d)\n", 1 << aggregation, cqi, bw_index, dci_fmt); - return 1 << aggregation; } -void dump_ue_list(UE_list_t * listP, int ul_flag) -{ +void dump_ue_list(UE_list_t *listP, int ul_flag) { int j; if (ul_flag == 0) { @@ -1919,26 +1978,24 @@ void dump_ue_list(UE_list_t * listP, int ul_flag) int add_new_ue(module_id_t mod_idP, int cc_idP, rnti_t rntiP, int harq_pidP #if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0)) - , uint8_t rach_resource_type + , uint8_t rach_resource_type #endif - ) -{ + ) { int UE_id; int i, j; - UE_list_t *UE_list = &RC.mac[mod_idP]->UE_list; - LOG_D(MAC, - "[eNB %d, CC_id %d] Adding UE with rnti %x (next avail %d, num_UEs %d)\n", - mod_idP, cc_idP, rntiP, UE_list->avail, UE_list->num_UEs); + "[eNB %d, CC_id %d] Adding UE with rnti %x (next avail %d, num_UEs %d)\n", + mod_idP, cc_idP, rntiP, UE_list->avail, UE_list->num_UEs); dump_ue_list(UE_list, 0); for (i = 0; i < MAX_MOBILES_PER_ENB; i++) { if (UE_list->active[i] == TRUE) continue; + UE_id = i; memset(&UE_list->UE_template[cc_idP][UE_id], 0, - sizeof(UE_TEMPLATE)); + sizeof(UE_TEMPLATE)); UE_list->UE_template[cc_idP][UE_id].rnti = rntiP; UE_list->UE_template[cc_idP][UE_id].configured = FALSE; UE_list->numactiveCCs[UE_id] = 1; @@ -1950,28 +2007,24 @@ int add_new_ue(module_id_t mod_idP, int cc_idP, rnti_t rntiP, int harq_pidP UE_list->active[UE_id] = TRUE; #if defined(USRP_REC_PLAY) // not specific to record/playback ? UE_list->UE_template[cc_idP][UE_id].pre_assigned_mcs_ul = 0; -#endif - +#endif #if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0)) UE_list->UE_template[cc_idP][UE_id].rach_resource_type = rach_resource_type; #endif - memset((void *) &UE_list->UE_sched_ctrl[UE_id], 0, - sizeof(UE_sched_ctrl)); + sizeof(UE_sched_ctrl)); memset((void *) &UE_list->eNB_UE_stats[cc_idP][UE_id], 0, - sizeof(eNB_UE_STATS)); + sizeof(eNB_UE_STATS)); UE_list->UE_sched_ctrl[UE_id].ue_reestablishment_reject_timer = 0; - /* default slice in case there was something different */ UE_list->assoc_dl_slice_idx[UE_id] = 0; UE_list->assoc_ul_slice_idx[UE_id] = 0; - UE_list->UE_sched_ctrl[UE_id].ta_update = 31; for (j = 0; j < 8; j++) { - UE_list->UE_template[cc_idP][UE_id].oldNDI[j] = (j == 0) ? 1 : 0; // 1 because first transmission is with format1A (Msg4) for harq_pid 0 - UE_list->UE_template[cc_idP][UE_id].oldNDI_UL[j] = (j == harq_pidP) ? 0 : 1; // 1st transmission is with Msg3; + UE_list->UE_template[cc_idP][UE_id].oldNDI[j] = (j == 0) ? 1 : 0; // 1 because first transmission is with format1A (Msg4) for harq_pid 0 + UE_list->UE_template[cc_idP][UE_id].oldNDI_UL[j] = (j == harq_pidP) ? 0 : 1; // 1st transmission is with Msg3; UE_list->UE_sched_ctrl[UE_id].round[cc_idP][j] = 8; UE_list->UE_sched_ctrl[UE_id].round_UL[cc_idP][j] = 0; } @@ -1979,14 +2032,14 @@ int add_new_ue(module_id_t mod_idP, int cc_idP, rnti_t rntiP, int harq_pidP eNB_ulsch_info[mod_idP][cc_idP][UE_id].status = S_UL_WAITING; eNB_dlsch_info[mod_idP][cc_idP][UE_id].status = S_DL_WAITING; LOG_D(MAC, "[eNB %d] Add UE_id %d on Primary CC_id %d: rnti %x\n", - mod_idP, UE_id, cc_idP, rntiP); + mod_idP, UE_id, cc_idP, rntiP); dump_ue_list(UE_list, 0); return (UE_id); } printf("MAC: cannot add new UE for rnti %x\n", rntiP); LOG_E(MAC, - "error in add_new_ue(), could not find space in UE_list, Dumping UE list\n"); + "error in add_new_ue(), could not find space in UE_list, Dumping UE list\n"); dump_ue_list(UE_list, 0); return (-1); } @@ -1995,101 +2048,103 @@ int add_new_ue(module_id_t mod_idP, int cc_idP, rnti_t rntiP, int harq_pidP int rrc_mac_remove_ue(module_id_t mod_idP, rnti_t rntiP) //------------------------------------------------------------------------------ { - int j; UE_list_t *UE_list = &RC.mac[mod_idP]->UE_list; int UE_id = find_UE_id(mod_idP,rntiP); int pCC_id; - + if (UE_id == -1) { LOG_W(MAC,"rrc_mac_remove_ue: UE %x not found\n", rntiP); return 0; } - + pCC_id = UE_PCCID(mod_idP,UE_id); - LOG_I(MAC,"Removing UE %d from Primary CC_id %d (rnti %x)\n",UE_id,pCC_id, rntiP); dump_ue_list(UE_list,0); - UE_list->active[UE_id] = FALSE; UE_list->num_UEs--; - + if (UE_list->head == UE_id) UE_list->head=UE_list->next[UE_id]; else UE_list->next[prev(UE_list,UE_id,0)]=UE_list->next[UE_id]; + if (UE_list->head_ul == UE_id) UE_list->head_ul=UE_list->next_ul[UE_id]; else UE_list->next_ul[prev(UE_list,UE_id,0)]=UE_list->next_ul[UE_id]; - + // clear all remaining pending transmissions /* UE_list->UE_template[pCC_id][UE_id].bsr_info[LCGID0] = 0; UE_list->UE_template[pCC_id][UE_id].bsr_info[LCGID1] = 0; UE_list->UE_template[pCC_id][UE_id].bsr_info[LCGID2] = 0; UE_list->UE_template[pCC_id][UE_id].bsr_info[LCGID3] = 0; - + UE_list->UE_template[pCC_id][UE_id].ul_SR = 0; UE_list->UE_template[pCC_id][UE_id].rnti = NOT_A_RNTI; UE_list->UE_template[pCC_id][UE_id].ul_active = FALSE; */ memset (&UE_list->UE_template[pCC_id][UE_id],0,sizeof(UE_TEMPLATE)); - UE_list->eNB_UE_stats[pCC_id][UE_id].total_rbs_used = 0; UE_list->eNB_UE_stats[pCC_id][UE_id].total_rbs_used_retx = 0; + for ( j = 0; j < NB_RB_MAX; j++ ) { UE_list->eNB_UE_stats[pCC_id][UE_id].num_pdu_tx[j] = 0; UE_list->eNB_UE_stats[pCC_id][UE_id].num_bytes_tx[j] = 0; } + UE_list->eNB_UE_stats[pCC_id][UE_id].num_retransmission = 0; UE_list->eNB_UE_stats[pCC_id][UE_id].total_sdu_bytes = 0; UE_list->eNB_UE_stats[pCC_id][UE_id].total_pdu_bytes = 0; UE_list->eNB_UE_stats[pCC_id][UE_id].total_num_pdus = 0; UE_list->eNB_UE_stats[pCC_id][UE_id].total_rbs_used_rx = 0; + for ( j = 0; j < NB_RB_MAX; j++ ) { UE_list->eNB_UE_stats[pCC_id][UE_id].num_pdu_rx[j] = 0; UE_list->eNB_UE_stats[pCC_id][UE_id].num_bytes_rx[j] = 0; } + UE_list->eNB_UE_stats[pCC_id][UE_id].num_errors_rx = 0; UE_list->eNB_UE_stats[pCC_id][UE_id].total_pdu_bytes_rx = 0; UE_list->eNB_UE_stats[pCC_id][UE_id].total_num_pdus_rx = 0; UE_list->eNB_UE_stats[pCC_id][UE_id].total_num_errors_rx = 0; - eNB_ulsch_info[mod_idP][pCC_id][UE_id].rnti = NOT_A_RNTI; eNB_ulsch_info[mod_idP][pCC_id][UE_id].status = S_UL_NONE; eNB_dlsch_info[mod_idP][pCC_id][UE_id].rnti = NOT_A_RNTI; eNB_dlsch_info[mod_idP][pCC_id][UE_id].status = S_DL_NONE; - eNB_ulsch_info[mod_idP][pCC_id][UE_id].serving_num = 0; eNB_dlsch_info[mod_idP][pCC_id][UE_id].serving_num = 0; - + // check if this has an RA process active if(find_RA_id(mod_idP, pCC_id, rntiP) != -1) { cancel_ra_proc(mod_idP, pCC_id, 0, rntiP); } pthread_mutex_lock(&rrc_release_freelist); - if(rrc_release_info.num_UEs > 0){ + + if(rrc_release_info.num_UEs > 0) { uint16_t release_total = 0; - for(uint16_t release_num = 0;release_num < NUMBER_OF_UE_MAX;release_num++){ - if(rrc_release_info.RRC_release_ctrl[release_num].flag > 0){ + + for(uint16_t release_num = 0; release_num < NUMBER_OF_UE_MAX; release_num++) { + if(rrc_release_info.RRC_release_ctrl[release_num].flag > 0) { release_total++; - }else{ + } else { continue; } - if(rrc_release_info.RRC_release_ctrl[release_num].rnti == rntiP){ + + if(rrc_release_info.RRC_release_ctrl[release_num].rnti == rntiP) { rrc_release_info.RRC_release_ctrl[release_num].flag = 0; rrc_release_info.num_UEs--; release_total--; } - if(release_total >= rrc_release_info.num_UEs){ + + if(release_total >= rrc_release_info.num_UEs) { break; } } } + pthread_mutex_unlock(&rrc_release_freelist); - return 0; } -int prev(UE_list_t * listP, int nodeP, int ul_flag) -{ +int prev(UE_list_t *listP, int nodeP, int ul_flag) { int j; if (ul_flag == 0) { @@ -2099,7 +2154,7 @@ int prev(UE_list_t * listP, int nodeP, int ul_flag) for (j = listP->head; j >= 0; j = listP->next[j]) { if (listP->next[j] == nodeP) { - return (j); + return (j); } } } else { @@ -2109,29 +2164,24 @@ int prev(UE_list_t * listP, int nodeP, int ul_flag) for (j = listP->head_ul; j >= 0; j = listP->next_ul[j]) { if (listP->next_ul[j] == nodeP) { - return (j); + return (j); } } } LOG_E(MAC, - "error in prev(), could not find previous to %d in UE_list %s, should never happen, Dumping UE list\n", - nodeP, (ul_flag == 0) ? "DL" : "UL"); + "error in prev(), could not find previous to %d in UE_list %s, should never happen, Dumping UE list\n", + nodeP, (ul_flag == 0) ? "DL" : "UL"); dump_ue_list(listP, ul_flag); - return (-1); } -void swap_UEs(UE_list_t * listP, int nodeiP, int nodejP, int ul_flag) -{ +void swap_UEs(UE_list_t *listP, int nodeiP, int nodejP, int ul_flag) { int prev_i, prev_j, next_i, next_j; - LOG_T(MAC, "Swapping UE %d,%d\n", nodeiP, nodejP); dump_ue_list(listP, ul_flag); - prev_i = prev(listP, nodeiP, ul_flag); prev_j = prev(listP, nodejP, ul_flag); - AssertFatal((prev_i >= 0) && (prev_j >= 0), "swap_UEs: problem"); if (ul_flag == 0) { @@ -2143,91 +2193,86 @@ void swap_UEs(UE_list_t * listP, int nodeiP, int nodejP, int ul_flag) } LOG_T(MAC, "[%s] next_i %d, next_i, next_j %d, head %d \n", - (ul_flag == 0) ? "DL" : "UL", next_i, next_j, listP->head); + (ul_flag == 0) ? "DL" : "UL", next_i, next_j, listP->head); if (ul_flag == 0) { - - if (next_i == nodejP) { // case ... p(i) i j n(j) ... => ... p(j) j i n(i) ... + if (next_i == nodejP) { // case ... p(i) i j n(j) ... => ... p(j) j i n(i) ... LOG_T(MAC, - "Case ... p(i) i j n(j) ... => ... p(j) j i n(i) ...\n"); - + "Case ... p(i) i j n(j) ... => ... p(j) j i n(i) ...\n"); listP->next[nodeiP] = next_j; listP->next[nodejP] = nodeiP; - if (nodeiP == listP->head) { // case i j n(j) - listP->head = nodejP; + if (nodeiP == listP->head) { // case i j n(j) + listP->head = nodejP; } else { - listP->next[prev_i] = nodejP; + listP->next[prev_i] = nodejP; } - } else if (next_j == nodeiP) { // case ... p(j) j i n(i) ... => ... p(i) i j n(j) ... + } else if (next_j == nodeiP) { // case ... p(j) j i n(i) ... => ... p(i) i j n(j) ... LOG_T(MAC, - "Case ... p(j) j i n(i) ... => ... p(i) i j n(j) ...\n"); + "Case ... p(j) j i n(i) ... => ... p(i) i j n(j) ...\n"); listP->next[nodejP] = next_i; listP->next[nodeiP] = nodejP; - if (nodejP == listP->head) { // case j i n(i) - listP->head = nodeiP; + if (nodejP == listP->head) { // case j i n(i) + listP->head = nodeiP; } else { - listP->next[prev_j] = nodeiP; + listP->next[prev_j] = nodeiP; } - } else { // case ... p(i) i n(i) ... p(j) j n(j) ... + } else { // case ... p(i) i n(i) ... p(j) j n(j) ... listP->next[nodejP] = next_i; listP->next[nodeiP] = next_j; if (nodeiP == listP->head) { - LOG_T(MAC, "changing head to %d\n", nodejP); - listP->head = nodejP; - listP->next[prev_j] = nodeiP; + LOG_T(MAC, "changing head to %d\n", nodejP); + listP->head = nodejP; + listP->next[prev_j] = nodeiP; } else if (nodejP == listP->head) { - LOG_D(MAC, "changing head to %d\n", nodeiP); - listP->head = nodeiP; - listP->next[prev_i] = nodejP; + LOG_D(MAC, "changing head to %d\n", nodeiP); + listP->head = nodeiP; + listP->next[prev_i] = nodejP; } else { - listP->next[prev_i] = nodejP; - listP->next[prev_j] = nodeiP; + listP->next[prev_i] = nodejP; + listP->next[prev_j] = nodeiP; } } - } else { // ul_flag - - if (next_i == nodejP) { // case ... p(i) i j n(j) ... => ... p(j) j i n(i) ... + } else { // ul_flag + if (next_i == nodejP) { // case ... p(i) i j n(j) ... => ... p(j) j i n(i) ... LOG_T(MAC, - "[UL] Case ... p(i) i j n(j) ... => ... p(j) j i n(i) ...\n"); - + "[UL] Case ... p(i) i j n(j) ... => ... p(j) j i n(i) ...\n"); listP->next_ul[nodeiP] = next_j; listP->next_ul[nodejP] = nodeiP; - if (nodeiP == listP->head_ul) { // case i j n(j) - listP->head_ul = nodejP; + if (nodeiP == listP->head_ul) { // case i j n(j) + listP->head_ul = nodejP; } else { - listP->next_ul[prev_i] = nodejP; + listP->next_ul[prev_i] = nodejP; } - } else if (next_j == nodeiP) { // case ... p(j) j i n(i) ... => ... p(i) i j n(j) ... + } else if (next_j == nodeiP) { // case ... p(j) j i n(i) ... => ... p(i) i j n(j) ... LOG_T(MAC, - "[UL]Case ... p(j) j i n(i) ... => ... p(i) i j n(j) ...\n"); + "[UL]Case ... p(j) j i n(i) ... => ... p(i) i j n(j) ...\n"); listP->next_ul[nodejP] = next_i; listP->next_ul[nodeiP] = nodejP; - if (nodejP == listP->head_ul) { // case j i n(i) - listP->head_ul = nodeiP; + if (nodejP == listP->head_ul) { // case j i n(i) + listP->head_ul = nodeiP; } else { - listP->next_ul[prev_j] = nodeiP; + listP->next_ul[prev_j] = nodeiP; } - } else { // case ... p(i) i n(i) ... p(j) j n(j) ... - + } else { // case ... p(i) i n(i) ... p(j) j n(j) ... listP->next_ul[nodejP] = next_i; listP->next_ul[nodeiP] = next_j; if (nodeiP == listP->head_ul) { - LOG_T(MAC, "[UL]changing head to %d\n", nodejP); - listP->head_ul = nodejP; - listP->next_ul[prev_j] = nodeiP; + LOG_T(MAC, "[UL]changing head to %d\n", nodejP); + listP->head_ul = nodejP; + listP->next_ul[prev_j] = nodeiP; } else if (nodejP == listP->head_ul) { - LOG_T(MAC, "[UL]changing head to %d\n", nodeiP); - listP->head_ul = nodeiP; - listP->next_ul[prev_i] = nodejP; + LOG_T(MAC, "[UL]changing head to %d\n", nodeiP); + listP->head_ul = nodeiP; + listP->next_ul[prev_i] = nodejP; } else { - listP->next_ul[prev_i] = nodejP; - listP->next_ul[prev_j] = nodeiP; + listP->next_ul[prev_i] = nodejP; + listP->next_ul[prev_j] = nodeiP; } } } @@ -2238,158 +2283,152 @@ void swap_UEs(UE_list_t * listP, int nodeiP, int nodejP, int ul_flag) // This has to be updated to include BSR information uint8_t -UE_is_to_be_scheduled(module_id_t module_idP, int CC_id, uint8_t UE_id) +UE_is_to_be_scheduled(module_id_t module_idP, + int CC_id, + uint8_t UE_id) { - UE_TEMPLATE *UE_template = - &RC.mac[module_idP]->UE_list.UE_template[CC_id][UE_id]; - UE_sched_ctrl *UE_sched_ctl = - &RC.mac[module_idP]->UE_list.UE_sched_ctrl[UE_id]; + UE_TEMPLATE *UE_template = &RC.mac[module_idP]->UE_list.UE_template[CC_id][UE_id]; + UE_sched_ctrl *UE_sched_ctl = &RC.mac[module_idP]->UE_list.UE_sched_ctrl[UE_id]; // do not schedule UE if UL is not working - if (UE_sched_ctl->ul_failure_timer > 0) - return (0); - if (UE_sched_ctl->ul_out_of_sync > 0) - return (0); + if (UE_sched_ctl->ul_failure_timer > 0 || UE_sched_ctl->ul_out_of_sync > 0) + return 0; LOG_D(MAC, "[eNB %d][PUSCH] Checking UL requirements UE %d/%x\n", - module_idP, UE_id, UE_RNTI(module_idP, UE_id)); + module_idP, UE_id, UE_RNTI(module_idP, UE_id)); if ((UE_template->scheduled_ul_bytes < UE_template->estimated_ul_buffer) || - (UE_template->ul_SR > 0) || // uplink scheduling request - ((UE_sched_ctl->ul_inactivity_timer > 20) && (UE_sched_ctl->ul_scheduled == 0)) || // every 2 frames when RRC_CONNECTED - ((UE_sched_ctl->ul_inactivity_timer > 10) && (UE_sched_ctl->ul_scheduled == 0) && (mac_eNB_get_rrc_status(module_idP, UE_RNTI(module_idP, UE_id)) < RRC_CONNECTED))) // every Frame when not RRC_CONNECTED - { - LOG_D(MAC, - "[eNB %d][PUSCH] UE %d/%x should be scheduled (BSR0 estimated size %d, SR %d)\n", - module_idP, UE_id, UE_RNTI(module_idP, UE_id), - UE_template->ul_buffer_info[LCGID0], UE_template->ul_SR); - return (1); - } else { - return (0); + (UE_template->ul_SR > 0) || // uplink scheduling request + ((UE_sched_ctl->ul_inactivity_timer > 20) && (UE_sched_ctl->ul_scheduled == 0)) || // every 2 frames when RRC_CONNECTED + ((UE_sched_ctl->ul_inactivity_timer > 10) && (UE_sched_ctl->ul_scheduled == 0) && + (mac_eNB_get_rrc_status(module_idP, UE_RNTI(module_idP, UE_id)) < RRC_CONNECTED))) { // every Frame when not RRC_CONNECTED + LOG_D(MAC, + "[eNB %d][PUSCH] UE %d/%x should be scheduled (BSR0 estimated size %d, SR %d)\n", + module_idP, UE_id, UE_RNTI(module_idP, UE_id), + UE_template->ul_buffer_info[LCGID0], UE_template->ul_SR); + return 1; } + return 0; } -uint8_t get_tmode(module_id_t module_idP, int CC_idP, int UE_idP) +uint8_t +get_tmode(module_id_t module_idP, + int CC_idP, + int UE_idP) { eNB_MAC_INST *eNB = RC.mac[module_idP]; COMMON_channels_t *cc = &eNB->common_channels[CC_idP]; - struct LTE_PhysicalConfigDedicated *physicalConfigDedicated = eNB->UE_list.UE_template[CC_idP][UE_idP].physicalConfigDedicated; - if (physicalConfigDedicated == NULL) { // RRCConnectionSetup not received by UE yet - AssertFatal(cc->p_eNB <= 2, "p_eNB is %d, should be <2\n", - cc->p_eNB); + if (physicalConfigDedicated == NULL) { // RRCConnectionSetup not received by UE yet + AssertFatal(cc->p_eNB <= 2, "p_eNB is %d, should be <2\n", cc->p_eNB); return (cc->p_eNB); - } else { - AssertFatal(physicalConfigDedicated->antennaInfo != NULL, - "antennaInfo (mod_id %d) is null for CCId %d, UEid %d, physicalConfigDedicated %p\n", module_idP,CC_idP, - UE_idP,physicalConfigDedicated); - - AssertFatal(physicalConfigDedicated->antennaInfo->present != - LTE_PhysicalConfigDedicated__antennaInfo_PR_NOTHING, - "antennaInfo (mod_id %d, CC_id %d) is set to NOTHING\n", - module_idP, CC_idP); - - if (physicalConfigDedicated->antennaInfo->present == - LTE_PhysicalConfigDedicated__antennaInfo_PR_explicitValue) { - return (1+physicalConfigDedicated->antennaInfo-> - choice.explicitValue.transmissionMode); - } else if (physicalConfigDedicated->antennaInfo->present == - LTE_PhysicalConfigDedicated__antennaInfo_PR_defaultValue) { - AssertFatal(cc->p_eNB <= 2, "p_eNB is %d, should be <2\n", - cc->p_eNB); - return (cc->p_eNB); - } else - AssertFatal(1 == 0, "Shouldn't be here\n"); - } + } + + AssertFatal(physicalConfigDedicated->antennaInfo != NULL, + "antennaInfo (mod_id %d) is null for CCId %d, UEid %d, physicalConfigDedicated %p\n", + module_idP, CC_idP, UE_idP,physicalConfigDedicated); + + AssertFatal(physicalConfigDedicated->antennaInfo->present != LTE_PhysicalConfigDedicated__antennaInfo_PR_NOTHING, + "antennaInfo (mod_id %d, CC_id %d) is set to NOTHING\n", module_idP, CC_idP); + + if (physicalConfigDedicated->antennaInfo->present == LTE_PhysicalConfigDedicated__antennaInfo_PR_explicitValue) { + return (1 + physicalConfigDedicated->antennaInfo->choice.explicitValue.transmissionMode); + } + + if (physicalConfigDedicated->antennaInfo->present == LTE_PhysicalConfigDedicated__antennaInfo_PR_defaultValue) { + AssertFatal(cc->p_eNB <= 2, "p_eNB is %d, should be <2\n", cc->p_eNB); + return (cc->p_eNB); + } + + AssertFatal(1 == 0, "Shouldn't be here\n"); + return 0; } int8_t get_ULharq(module_id_t module_idP, int CC_idP, uint16_t frameP, - uint8_t subframeP) -{ + uint8_t subframeP) { uint8_t ret = -1; eNB_MAC_INST *eNB = RC.mac[module_idP]; COMMON_channels_t *cc = &eNB->common_channels[CC_idP]; - if (cc->tdd_Config == NULL) { // FDD + if (cc->tdd_Config == NULL) { // FDD ret = (((frameP << 1) + subframeP) & 7); } else { switch (cc->tdd_Config->subframeAssignment) { - case 1: - if ((subframeP == 2) || - (subframeP == 3) || (subframeP == 7) || (subframeP == 8)) - switch (subframeP) { - case 2: - case 3: - ret = (subframeP - 2); - break; - - case 7: - case 8: - ret = (subframeP - 5); - break; - - default: - AssertFatal(1 == 0, - "subframe2_harq_pid, Illegal subframe %d for TDD mode %d\n", - subframeP, - (int) cc->tdd_Config->subframeAssignment); - break; - } + case 1: + if ((subframeP == 2) || + (subframeP == 3) || (subframeP == 7) || (subframeP == 8)) + switch (subframeP) { + case 2: + case 3: + ret = (subframeP - 2); + break; - break; + case 7: + case 8: + ret = (subframeP - 5); + break; - case 2: - AssertFatal((subframeP == 2) || (subframeP == 7), - "subframe2_harq_pid, Illegal subframe %d for TDD mode %d\n", - subframeP, - (int) cc->tdd_Config->subframeAssignment); - ret = (subframeP / 7); - break; + default: + AssertFatal(1 == 0, + "subframe2_harq_pid, Illegal subframe %d for TDD mode %d\n", + subframeP, + (int) cc->tdd_Config->subframeAssignment); + break; + } - case 3: - AssertFatal((subframeP > 1) && (subframeP < 5), - "subframe2_harq_pid, Illegal subframe %d for TDD mode %d\n", - subframeP, - (int) cc->tdd_Config->subframeAssignment); - ret = (subframeP - 2); - break; + break; - case 4: - AssertFatal((subframeP > 1) && (subframeP < 4), - "subframe2_harq_pid, Illegal subframe %d for TDD mode %d\n", - subframeP, - (int) cc->tdd_Config->subframeAssignment); - ret = (subframeP - 2); - break; + case 2: + AssertFatal((subframeP == 2) || (subframeP == 7), + "subframe2_harq_pid, Illegal subframe %d for TDD mode %d\n", + subframeP, + (int) cc->tdd_Config->subframeAssignment); + ret = (subframeP / 7); + break; - case 5: - AssertFatal(subframeP == 2, - "subframe2_harq_pid, Illegal subframe %d for TDD mode %d\n", - subframeP, - (int) cc->tdd_Config->subframeAssignment); - ret = (subframeP - 2); - break; + case 3: + AssertFatal((subframeP > 1) && (subframeP < 5), + "subframe2_harq_pid, Illegal subframe %d for TDD mode %d\n", + subframeP, + (int) cc->tdd_Config->subframeAssignment); + ret = (subframeP - 2); + break; - default: - AssertFatal(1 == 0, - "subframe2_harq_pid, Unsupported TDD mode %d\n", - (int) cc->tdd_Config->subframeAssignment); - break; + case 4: + AssertFatal((subframeP > 1) && (subframeP < 4), + "subframe2_harq_pid, Illegal subframe %d for TDD mode %d\n", + subframeP, + (int) cc->tdd_Config->subframeAssignment); + ret = (subframeP - 2); + break; + + case 5: + AssertFatal(subframeP == 2, + "subframe2_harq_pid, Illegal subframe %d for TDD mode %d\n", + subframeP, + (int) cc->tdd_Config->subframeAssignment); + ret = (subframeP - 2); + break; + + default: + AssertFatal(1 == 0, + "subframe2_harq_pid, Unsupported TDD mode %d\n", + (int) cc->tdd_Config->subframeAssignment); + break; } } AssertFatal(ret != -1, - "invalid harq_pid(%d) at SFN/SF = %d/%d\n", (int8_t) ret, - frameP, subframeP); + "invalid harq_pid(%d) at SFN/SF = %d/%d\n", (int8_t) ret, + frameP, subframeP); return ret; } -uint16_t getRIV(uint16_t N_RB_DL, uint16_t RBstart, uint16_t Lcrbs) -{ +uint16_t getRIV(uint16_t N_RB_DL, uint16_t RBstart, uint16_t Lcrbs) { uint16_t RIV; if (Lcrbs <= (1 + (N_RB_DL >> 1))) @@ -2402,8 +2441,7 @@ uint16_t getRIV(uint16_t N_RB_DL, uint16_t RBstart, uint16_t Lcrbs) uint32_t allocate_prbs(int UE_id, unsigned char nb_rb, int N_RB_DL, - uint32_t * rballoc) -{ + uint32_t *rballoc) { int i; uint32_t rballoc_dci = 0; unsigned char nb_rb_alloc = 0; @@ -2430,82 +2468,77 @@ allocate_prbs(int UE_id, unsigned char nb_rb, int N_RB_DL, return (rballoc_dci); } -int get_bw_index(module_id_t module_id, uint8_t CC_id) -{ +int get_bw_index(module_id_t module_id, uint8_t CC_id) { int bw_index = 0; - int N_RB_DL = to_prb(RC.mac[module_id]->common_channels[CC_id].mib->message.dl_Bandwidth); switch (N_RB_DL) { - case 6: // 1.4 MHz - bw_index = 0; - break; + case 6: // 1.4 MHz + bw_index = 0; + break; - case 25: // 5HMz - bw_index = 1; - break; + case 25: // 5HMz + bw_index = 1; + break; - case 50: // 10HMz - bw_index = 2; - break; + case 50: // 10HMz + bw_index = 2; + break; - case 100: // 20HMz - bw_index = 3; - break; + case 100: // 20HMz + bw_index = 3; + break; - default: - bw_index = 1; - LOG_W(MAC, - "[eNB %d] N_RB_DL %d unknown for CC_id %d, setting bw_index to 1\n", - module_id, N_RB_DL, CC_id); - break; + default: + bw_index = 1; + LOG_W(MAC, + "[eNB %d] N_RB_DL %d unknown for CC_id %d, setting bw_index to 1\n", + module_id, N_RB_DL, CC_id); + break; } return bw_index; } -int get_min_rb_unit(module_id_t module_id, uint8_t CC_id) -{ +int get_min_rb_unit(module_id_t module_id, uint8_t CC_id) { int min_rb_unit = 0; int N_RB_DL = to_prb(RC.mac[module_id]->common_channels[CC_id].mib->message.dl_Bandwidth); switch (N_RB_DL) { - case 6: // 1.4 MHz - min_rb_unit = 1; - break; + case 6: // 1.4 MHz + min_rb_unit = 1; + break; - case 25: // 5HMz - min_rb_unit = 2; - break; + case 25: // 5HMz + min_rb_unit = 2; + break; - case 50: // 10HMz - min_rb_unit = 3; - break; + case 50: // 10HMz + min_rb_unit = 3; + break; - case 100: // 20HMz - min_rb_unit = 4; - break; + case 100: // 20HMz + min_rb_unit = 4; + break; - default: - min_rb_unit = 2; - LOG_W(MAC, - "[eNB %d] N_DL_RB %d unknown for CC_id %d, setting min_rb_unit to 2\n", - module_id, N_RB_DL, CC_id); - break; + default: + min_rb_unit = 2; + LOG_W(MAC, + "[eNB %d] N_DL_RB %d unknown for CC_id %d, setting min_rb_unit to 2\n", + module_id, N_RB_DL, CC_id); + break; } return min_rb_unit; } uint32_t -allocate_prbs_sub(int nb_rb, int N_RB_DL, int N_RBG, uint8_t * rballoc) -{ - int check = 0; //check1=0,check2=0; +allocate_prbs_sub(int nb_rb, int N_RB_DL, int N_RBG, uint8_t *rballoc) { + int check = 0; //check1=0,check2=0; uint32_t rballoc_dci = 0; //uint8_t number_of_subbands=13; - LOG_T(MAC, "*****Check1RBALLOC****: %d%d%d%d (nb_rb %d,N_RBG %d)\n", - rballoc[3], rballoc[2], rballoc[1], rballoc[0], nb_rb, N_RBG); + rballoc[3], rballoc[2], rballoc[1], rballoc[0], nb_rb, N_RBG); while ((nb_rb > 0) && (check < N_RBG)) { //printf("rballoc[%d] %d\n",check,rballoc[check]); @@ -2513,33 +2546,34 @@ allocate_prbs_sub(int nb_rb, int N_RB_DL, int N_RBG, uint8_t * rballoc) rballoc_dci |= (1 << ((N_RBG - 1) - check)); switch (N_RB_DL) { - case 6: - nb_rb--; - break; + case 6: + nb_rb--; + break; - case 25: - if ((check == N_RBG - 1)) { - nb_rb--; - } else { - nb_rb -= 2; - } + case 25: + if ((check == N_RBG - 1)) { + nb_rb--; + } else { + nb_rb -= 2; + } - break; + break; - case 50: - if ((check == N_RBG - 1)) { - nb_rb -= 2; - } else { - nb_rb -= 3; - } + case 50: + if ((check == N_RBG - 1)) { + nb_rb -= 2; + } else { + nb_rb -= 3; + } - break; + break; - case 100: - nb_rb -= 4; - break; + case 100: + nb_rb -= 4; + break; } } + // printf("rb_alloc %x\n",rballoc_dci); check = check + 1; // check1 = check1+2; @@ -2551,67 +2585,71 @@ allocate_prbs_sub(int nb_rb, int N_RB_DL, int N_RBG, uint8_t * rballoc) return (rballoc_dci); } -int get_subbandsize(uint8_t dl_Bandwidth) -{ +int get_subbandsize(uint8_t dl_Bandwidth) { uint8_t ss[6] = { 6, 4, 4, 6, 8, 8 }; - AssertFatal(dl_Bandwidth < 6, "dl_Bandwidth %d is out of bounds\n", - dl_Bandwidth); - + dl_Bandwidth); return (ss[dl_Bandwidth]); } -int get_nb_subband(int N_RB_DL) -{ +int get_nb_subband(int N_RB_DL) { int nb_sb = 0; switch (N_RB_DL) { - case 6: - nb_sb = 0; - break; + case 6: + nb_sb = 0; + break; - case 15: - nb_sb = 4; // sb_size =4 + case 15: + nb_sb = 4; // sb_size =4 + break; - case 25: - nb_sb = 7; // sb_size =4, 1 sb with 1PRB, 6 with 2 RBG, each has 2 PRBs - break; + case 25: + nb_sb = 7; // sb_size =4, 1 sb with 1PRB, 6 with 2 RBG, each has 2 PRBs + break; - case 50: // sb_size =6 - nb_sb = 9; - break; + case 50: // sb_size =6 + nb_sb = 9; + break; - case 75: // sb_size =8 - nb_sb = 10; - break; + case 75: // sb_size =8 + nb_sb = 10; + break; - case 100: // sb_size =8 , 1 sb with 1 RBG + 12 sb with 2RBG, each RBG has 4 PRBs - nb_sb = 13; - break; + case 100: // sb_size =8 , 1 sb with 1 RBG + 12 sb with 2RBG, each RBG has 4 PRBs + nb_sb = 13; + break; - default: - nb_sb = 0; - break; + default: + nb_sb = 0; + break; } return nb_sb; } - -void init_CCE_table(int module_idP, int CC_idP) +/* +void +init_CCE_table(int module_idP, + int CC_idP) { memset(RC.mac[module_idP]->CCE_table[CC_idP], 0, 800 * sizeof(int)); } - +*/ +void +init_CCE_table(int *CCE_table) +{ + memset(CCE_table, 0, 800 * sizeof(int)); +} int get_nCCE_offset(int *CCE_table, - const unsigned char L, - const int nCCE, - const int common_dci, - const unsigned short rnti, const unsigned char subframe) -{ + const unsigned char L, + const int nCCE, + const int common_dci, + const unsigned short rnti, const unsigned char subframe) { int search_space_free, m, nb_candidates = 0, l, i; unsigned int Yk; + /* printf("CCE Allocation: "); for (i=0;i<nCCE;i++) @@ -2626,30 +2664,27 @@ get_nCCE_offset(int *CCE_table, // printf("Common DCI nb_candidates %d, L %d\n",nb_candidates,L); for (m = nb_candidates - 1; m >= 0; m--) { - search_space_free = 1; - for (l = 0; l < L; l++) { - // printf("CCE_table[%d] %d\n",(m*L)+l,CCE_table[(m*L)+l]); - if (CCE_table[(m * L) + l] == 1) { - search_space_free = 0; - break; - } + for (l = 0; l < L; l++) { + // printf("CCE_table[%d] %d\n",(m*L)+l,CCE_table[(m*L)+l]); + if (CCE_table[(m * L) + l] == 1) { + search_space_free = 0; + break; + } } if (search_space_free == 1) { + // printf("returning %d\n",m*L); + for (l = 0; l < L; l++) + CCE_table[(m * L) + l] = 1; - // printf("returning %d\n",m*L); - - for (l = 0; l < L; l++) - CCE_table[(m * L) + l] = 1; - return (m * L); + return (m * L); } } return (-1); - - } else { // Find first available in ue specific search space + } else { // Find first available in ue specific search space // according to procedure in Section 9.1.1 of 36.213 (v. 8.6) // compute Yk Yk = (unsigned int) rnti; @@ -2660,40 +2695,41 @@ get_nCCE_offset(int *CCE_table, Yk = Yk % (nCCE / L); switch (L) { - case 1: - case 2: - nb_candidates = 6; - break; + case 1: + case 2: + nb_candidates = 6; + break; - case 4: - case 8: - nb_candidates = 2; - break; + case 4: + case 8: + nb_candidates = 2; + break; - default: - DevParam(L, nCCE, rnti); - break; + default: + DevParam(L, nCCE, rnti); + break; } LOG_D(MAC, "rnti %x, Yk = %d, nCCE %d (nCCE/L %d),nb_cand %d\n", - rnti, Yk, nCCE, nCCE / L, nb_candidates); + rnti, Yk, nCCE, nCCE / L, nb_candidates); for (m = 0; m < nb_candidates; m++) { search_space_free = 1; for (l = 0; l < L; l++) { - int cce = (((Yk + m) % (nCCE / L)) * L) + l; - if (cce >= nCCE || CCE_table[cce] == 1) { - search_space_free = 0; - break; - } + int cce = (((Yk + m) % (nCCE / L)) * L) + l; + + if (cce >= nCCE || CCE_table[cce] == 1) { + search_space_free = 0; + break; + } } if (search_space_free == 1) { - for (l = 0; l < L; l++) - CCE_table[(((Yk + m) % (nCCE / L)) * L) + l] = 1; + for (l = 0; l < L; l++) + CCE_table[(((Yk + m) % (nCCE / L)) * L) + l] = 1; - return (((Yk + m) % (nCCE / L)) * L); + return (((Yk + m) % (nCCE / L)) * L); } } @@ -2703,14 +2739,14 @@ get_nCCE_offset(int *CCE_table, void dump_CCE_table(int *CCE_table, const int nCCE, - const unsigned short rnti, const int subframe, int L) -{ + const unsigned short rnti, const int subframe, int L) { int nb_candidates = 0, i; unsigned int Yk; - printf("CCE 0: "); + for (i = 0; i < nCCE; i++) { printf("%1d.", CCE_table[i]); + if ((i & 7) == 7) printf("\n CCE %d: ", i); } @@ -2720,39 +2756,35 @@ dump_CCE_table(int *CCE_table, const int nCCE, for (i = 0; i <= subframe; i++) Yk = (Yk * 39827) % 65537; - Yk = Yk % (nCCE / L); + Yk = Yk % (nCCE / L); + + switch (L) { + case 1: + case 2: + nb_candidates = 6; + break; + + case 4: + case 8: + nb_candidates = 2; + break; - switch (L) { - case 1: - case 2: - nb_candidates = 6; - break; - - case 4: - case 8: - nb_candidates = 2; - break; - - default: - DevParam(L, nCCE, rnti); - break; + default: + DevParam(L, nCCE, rnti); + break; } - printf("rnti %x, Yk*L = %d, nCCE %d (nCCE/L %d),nb_cand*L %d\n", rnti, - Yk * L, nCCE, nCCE / L, nb_candidates * L); + printf("rnti %x, Yk*L = %u, nCCE %d (nCCE/L %d),nb_cand*L %d\n", rnti, + Yk * L, nCCE, nCCE / L, nb_candidates * L); } uint16_t -getnquad(COMMON_channels_t * cc, uint8_t num_pdcch_symbols, uint8_t mi) -{ +getnquad(COMMON_channels_t *cc, uint8_t num_pdcch_symbols, uint8_t mi) { uint16_t Nreg = 0; - AssertFatal(cc != NULL, "cc is null\n"); AssertFatal(cc->mib != NULL, "cc->mib is null\n"); - int N_RB_DL = to_prb(cc->mib->message.dl_Bandwidth); int phich_resource = get_phich_resource_times6(cc); - uint8_t Ngroup_PHICH = (phich_resource * N_RB_DL) / 48; if (((phich_resource * N_RB_DL) % 48) > 0) @@ -2766,515 +2798,505 @@ getnquad(COMMON_channels_t * cc, uint8_t num_pdcch_symbols, uint8_t mi) if ((num_pdcch_symbols > 0) && (num_pdcch_symbols < 4)) switch (N_RB_DL) { - case 6: - Nreg = 12 + (num_pdcch_symbols - 1) * 18; - break; + case 6: + Nreg = 12 + (num_pdcch_symbols - 1) * 18; + break; - case 25: - Nreg = 50 + (num_pdcch_symbols - 1) * 75; - break; + case 25: + Nreg = 50 + (num_pdcch_symbols - 1) * 75; + break; - case 50: - Nreg = 100 + (num_pdcch_symbols - 1) * 150; - break; + case 50: + Nreg = 100 + (num_pdcch_symbols - 1) * 150; + break; - case 100: - Nreg = 200 + (num_pdcch_symbols - 1) * 300; - break; + case 100: + Nreg = 200 + (num_pdcch_symbols - 1) * 300; + break; - default: - return (0); + default: + return (0); } + // printf("Nreg %d (%d)\n",Nreg,Nreg - 4 - (3*Ngroup_PHICH)); return (Nreg - 4 - (3 * Ngroup_PHICH)); } uint16_t -getnCCE(COMMON_channels_t * cc, uint8_t num_pdcch_symbols, uint8_t mi) -{ +getnCCE(COMMON_channels_t *cc, uint8_t num_pdcch_symbols, uint8_t mi) { AssertFatal(cc != NULL, "cc is null\n"); return (getnquad(cc, num_pdcch_symbols, mi) / 9); } -uint8_t getmi(COMMON_channels_t * cc, int subframe) -{ +uint8_t getmi(COMMON_channels_t *cc, int subframe) { AssertFatal(cc != NULL, "cc is null\n"); // for FDD - if (cc->tdd_Config == NULL) // FDD + if (cc->tdd_Config == NULL) // FDD return 1; // for TDD switch (cc->tdd_Config->subframeAssignment) { - case 0: - if ((subframe == 0) || (subframe == 5)) - return (2); - else - return (1); + case 0: + if ((subframe == 0) || (subframe == 5)) + return (2); + else + return (1); - break; + break; - case 1: - if ((subframe == 0) || (subframe == 5)) - return (0); - else - return (1); + case 1: + if ((subframe == 0) || (subframe == 5)) + return (0); + else + return (1); - break; + break; - case 2: - if ((subframe == 3) || (subframe == 8)) - return (1); - else - return (0); + case 2: + if ((subframe == 3) || (subframe == 8)) + return (1); + else + return (0); - break; + break; - case 3: - if ((subframe == 0) || (subframe == 8) || (subframe == 9)) - return (1); - else - return (0); + case 3: + if ((subframe == 0) || (subframe == 8) || (subframe == 9)) + return (1); + else + return (0); - break; + break; - case 4: - if ((subframe == 8) || (subframe == 9)) - return (1); - else - return (0); + case 4: + if ((subframe == 8) || (subframe == 9)) + return (1); + else + return (0); - break; + break; - case 5: - if (subframe == 8) - return (1); - else - return (0); + case 5: + if (subframe == 8) + return (1); + else + return (0); - break; + break; - case 6: - return (1); - break; + case 6: + return (1); + break; - default: - return (0); + default: + return (0); } } uint16_t -get_nCCE_max(COMMON_channels_t * cc, int num_pdcch_symbols, int subframe) -{ +get_nCCE_max(COMMON_channels_t *cc, int num_pdcch_symbols, int subframe) { AssertFatal(cc != NULL, "cc is null\n"); return (getnCCE(cc, num_pdcch_symbols, getmi(cc, subframe))); } // Allocate the CCEs int -allocate_CCEs(int module_idP, int CC_idP, frame_t frameP, sub_frame_t subframeP, int test_onlyP) +allocate_CCEs(int module_idP, + int CC_idP, + frame_t frameP, + sub_frame_t subframeP, + int test_onlyP) { - int *CCE_table = RC.mac[module_idP]->CCE_table[CC_idP]; - nfapi_dl_config_request_body_t *DL_req = - &RC.mac[module_idP]->DL_req[CC_idP].dl_config_request_body; - nfapi_hi_dci0_request_body_t *HI_DCI0_req = - &RC.mac[module_idP]->HI_DCI0_req[CC_idP][subframeP].hi_dci0_request_body; - nfapi_dl_config_request_pdu_t *dl_config_pdu = - &DL_req->dl_config_pdu_list[0]; - nfapi_hi_dci0_request_pdu_t *hi_dci0_pdu = - &HI_DCI0_req->hi_dci0_pdu_list[0]; - int nCCE_max = - get_nCCE_max(&RC.mac[module_idP]->common_channels[CC_idP], 1, - subframeP); + eNB_MAC_INST *eNB = RC.mac[module_idP]; + int *CCE_table = eNB->CCE_table[CC_idP]; + nfapi_dl_config_request_body_t *DL_req = &eNB->DL_req[CC_idP].dl_config_request_body; + nfapi_hi_dci0_request_body_t *HI_DCI0_req = &eNB->HI_DCI0_req[CC_idP][subframeP].hi_dci0_request_body; + nfapi_dl_config_request_pdu_t *dl_config_pdu = &DL_req->dl_config_pdu_list[0]; + nfapi_hi_dci0_request_pdu_t *hi_dci0_pdu = &HI_DCI0_req->hi_dci0_pdu_list[0]; + COMMON_channels_t *cc = &eNB->common_channels[CC_idP]; + int nCCE_max = get_nCCE_max(cc, 1, subframeP); int fCCE; int i, j, idci; int nCCE = 0; int max_symbol; - - eNB_MAC_INST *eNB = RC.mac[module_idP]; - COMMON_channels_t *cc = &eNB->common_channels[CC_idP]; int ackNAK_absSF = get_pucch1_absSF(cc, (frameP*10+subframeP)); + nfapi_dl_config_request_pdu_t *dl_config_pduLoop; + nfapi_hi_dci0_request_pdu_t *hi_dci0_pduLoop; + if (cc->tdd_Config!=NULL && is_S_sf(cc,subframeP) > 0) max_symbol = 2; else max_symbol = 3; nfapi_ul_config_request_body_t *ul_req = &eNB->UL_req_tmp[CC_idP][ackNAK_absSF % 10].ul_config_request_body; - - LOG_D(MAC, - "Allocate CCEs subframe %d, test %d : (DL PDU %d, DL DCI %d, UL %d)\n", - subframeP, test_onlyP, DL_req->number_pdu, DL_req->number_dci, - HI_DCI0_req->number_of_dci); + LOG_D(MAC, "Allocate CCEs subframe %d, test %d : (DL PDU %d, DL DCI %d, UL %d)\n", + subframeP, + test_onlyP, + DL_req->number_pdu, + DL_req->number_dci, + HI_DCI0_req->number_of_dci); DL_req->number_pdcch_ofdm_symbols = 1; - try_again: - init_CCE_table(module_idP, CC_idP); +try_again: + + init_CCE_table(CCE_table); nCCE = 0; for (i = 0, idci = 0; i < DL_req->number_pdu; i++) { + dl_config_pduLoop = &dl_config_pdu[i]; // allocate DL common DCIs first - if ((dl_config_pdu[i].pdu_type == NFAPI_DL_CONFIG_DCI_DL_PDU_TYPE) - && (dl_config_pdu[i].dci_dl_pdu.dci_dl_pdu_rel8.rnti_type == - 2)) { - LOG_D(MAC, - "Trying to allocate COMMON DCI %d/%d (%d,%d) : rnti %x, aggreg %d nCCE %d / %d (num_pdcch_symbols %d)\n", - idci, DL_req->number_dci + HI_DCI0_req->number_of_dci, - DL_req->number_dci, HI_DCI0_req->number_of_dci, - dl_config_pdu[i].dci_dl_pdu.dci_dl_pdu_rel8.rnti, - dl_config_pdu[i].dci_dl_pdu. - dci_dl_pdu_rel8.aggregation_level, nCCE, nCCE_max, - DL_req->number_pdcch_ofdm_symbols); - - if (nCCE + - (dl_config_pdu[i].dci_dl_pdu. - dci_dl_pdu_rel8.aggregation_level) > nCCE_max) { - if (DL_req->number_pdcch_ofdm_symbols == max_symbol) - goto failed; - LOG_D(MAC, - "Can't fit DCI allocations with %d PDCCH symbols, increasing by 1\n", - DL_req->number_pdcch_ofdm_symbols); - DL_req->number_pdcch_ofdm_symbols++; - nCCE_max = - get_nCCE_max(&RC.mac[module_idP]-> - common_channels[CC_idP], - DL_req->number_pdcch_ofdm_symbols, - subframeP); - goto try_again; + if (dl_config_pduLoop->pdu_type == NFAPI_DL_CONFIG_DCI_DL_PDU_TYPE && + dl_config_pduLoop->dci_dl_pdu.dci_dl_pdu_rel8.rnti_type == 2) { + LOG_D(MAC, "Trying to allocate COMMON DCI %d/%d (%d,%d) : rnti %x, aggreg %d nCCE %d / %d (num_pdcch_symbols %d)\n", + idci, + DL_req->number_dci + HI_DCI0_req->number_of_dci, + DL_req->number_dci, + HI_DCI0_req->number_of_dci, + dl_config_pduLoop->dci_dl_pdu.dci_dl_pdu_rel8.rnti, + dl_config_pduLoop->dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level, + nCCE, + nCCE_max, + DL_req->number_pdcch_ofdm_symbols); + + if (nCCE + (dl_config_pduLoop->dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level) > nCCE_max) { + if (DL_req->number_pdcch_ofdm_symbols == max_symbol) + return -1; + + LOG_D(MAC, "Can't fit DCI allocations with %d PDCCH symbols, increasing by 1\n", + DL_req->number_pdcch_ofdm_symbols); + DL_req->number_pdcch_ofdm_symbols++; + nCCE_max = get_nCCE_max(cc, DL_req->number_pdcch_ofdm_symbols, subframeP); + goto try_again; } + // number of CCEs left can potentially hold this allocation fCCE = get_nCCE_offset(CCE_table, - dl_config_pdu[i]. - dci_dl_pdu.dci_dl_pdu_rel8. - aggregation_level, nCCE_max, 1, - dl_config_pdu[i]. - dci_dl_pdu.dci_dl_pdu_rel8.rnti, - subframeP); + dl_config_pduLoop->dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level, + nCCE_max, + 1, + dl_config_pduLoop->dci_dl_pdu.dci_dl_pdu_rel8.rnti, + subframeP); + if (fCCE == -1) { - if (DL_req->number_pdcch_ofdm_symbols == max_symbol) { - LOG_D(MAC, - "subframe %d: Dropping Allocation for RNTI %x\n", - subframeP, - dl_config_pdu[i].dci_dl_pdu.dci_dl_pdu_rel8. - rnti); - for (j = 0; j <= i; j++) { - if (dl_config_pdu[j].pdu_type == - NFAPI_DL_CONFIG_DCI_DL_PDU_TYPE) - LOG_D(MAC, - "DCI %d/%d (%d,%d) : rnti %x dci format %d, aggreg %d nCCE %d / %d (num_pdcch_symbols %d)\n", - j, - DL_req->number_dci + - HI_DCI0_req->number_of_dci, - DL_req->number_dci, - HI_DCI0_req->number_of_dci, - dl_config_pdu[j]. - dci_dl_pdu.dci_dl_pdu_rel8.rnti, - dl_config_pdu[j]. - dci_dl_pdu.dci_dl_pdu_rel8.dci_format, - dl_config_pdu[j]. - dci_dl_pdu.dci_dl_pdu_rel8. - aggregation_level, nCCE, nCCE_max, - DL_req->number_pdcch_ofdm_symbols); - } - //dump_CCE_table(CCE_table,nCCE_max,subframeP,dci_alloc->rnti,1<<dci_alloc->L); - goto failed; - } - LOG_D(MAC, - "Can't fit DCI allocations with %d PDCCH symbols (rnti condition), increasing by 1\n", - DL_req->number_pdcch_ofdm_symbols); - - DL_req->number_pdcch_ofdm_symbols++; - nCCE_max = get_nCCE_max(&RC.mac[module_idP]-> - common_channels[CC_idP], - DL_req->number_pdcch_ofdm_symbols, - subframeP); - goto try_again; - } // fCCE==-1 + if (DL_req->number_pdcch_ofdm_symbols == max_symbol) { + LOG_D(MAC, "subframe %d: Dropping Allocation for RNTI %x\n", + subframeP, + dl_config_pduLoop->dci_dl_pdu.dci_dl_pdu_rel8.rnti); + + for (j = 0; j <= i; j++) { + dl_config_pduLoop = &dl_config_pdu[j]; + if (dl_config_pduLoop->pdu_type == NFAPI_DL_CONFIG_DCI_DL_PDU_TYPE) + LOG_D(MAC, "DCI %d/%d (%d,%d) : rnti %x dci format %d, aggreg %d nCCE %d / %d (num_pdcch_symbols %d)\n", + j, + DL_req->number_dci + HI_DCI0_req->number_of_dci, + DL_req->number_dci, + HI_DCI0_req->number_of_dci, + dl_config_pduLoop->dci_dl_pdu.dci_dl_pdu_rel8.rnti, + dl_config_pduLoop->dci_dl_pdu.dci_dl_pdu_rel8.dci_format, + dl_config_pduLoop->dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level, + nCCE, nCCE_max, DL_req->number_pdcch_ofdm_symbols); + } + //dump_CCE_table(CCE_table,nCCE_max,subframeP,dci_alloc->rnti,1<<dci_alloc->L); + return -1; + } + + LOG_D(MAC, "Can't fit DCI allocations with %d PDCCH symbols (rnti condition), increasing by 1\n", + DL_req->number_pdcch_ofdm_symbols); + DL_req->number_pdcch_ofdm_symbols++; + nCCE_max = get_nCCE_max(cc, DL_req->number_pdcch_ofdm_symbols, subframeP); + goto try_again; + } // fCCE==-1 // the allocation is feasible, rnti rule passes - nCCE += dl_config_pdu[i].dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level; + nCCE += dl_config_pduLoop->dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level; LOG_D(MAC, "Allocating at nCCE %d\n", fCCE); + if ((test_onlyP%2) == 0) { - dl_config_pdu[i].dci_dl_pdu.dci_dl_pdu_rel8.cce_idx = fCCE; - LOG_D(MAC, - "Allocate COMMON DCI CCEs subframe %d, test %d => L %d fCCE %d\n", - subframeP, test_onlyP, - dl_config_pdu[i].dci_dl_pdu. - dci_dl_pdu_rel8.aggregation_level, fCCE); + dl_config_pduLoop->dci_dl_pdu.dci_dl_pdu_rel8.cce_idx = fCCE; + LOG_D(MAC, "Allocate COMMON DCI CCEs subframe %d, test %d => L %d fCCE %d\n", + subframeP, + test_onlyP, + dl_config_pduLoop->dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level, + fCCE); } + idci++; } - } // for i = 0 ... num_DL_DCIs + } // for i = 0 ... num_DL_DCIs // no try to allocate UL DCIs - for (i = 0; i < HI_DCI0_req->number_of_dci + HI_DCI0_req->number_of_hi; - i++) { - + for (i = 0; i < HI_DCI0_req->number_of_dci + HI_DCI0_req->number_of_hi; i++) { + hi_dci0_pduLoop = &hi_dci0_pdu[i]; // allocate UL DCIs if (hi_dci0_pdu[i].pdu_type == NFAPI_HI_DCI0_DCI_PDU_TYPE) { - - LOG_D(MAC, - "Trying to allocate format 0 DCI %d/%d (%d,%d) : rnti %x, aggreg %d nCCE %d / %d (num_pdcch_symbols %d)\n", - idci, DL_req->number_dci + HI_DCI0_req->number_of_dci, - DL_req->number_dci, HI_DCI0_req->number_of_dci, - hi_dci0_pdu[i].dci_pdu.dci_pdu_rel8.rnti, - hi_dci0_pdu[i].dci_pdu.dci_pdu_rel8.aggregation_level, - nCCE, nCCE_max, DL_req->number_pdcch_ofdm_symbols); - - if (nCCE + (hi_dci0_pdu[i].dci_pdu.dci_pdu_rel8.aggregation_level) > nCCE_max) { - if (DL_req->number_pdcch_ofdm_symbols == max_symbol) - goto failed; - LOG_D(MAC, - "Can't fit DCI allocations with %d PDCCH symbols, increasing by 1\n", - DL_req->number_pdcch_ofdm_symbols); - - DL_req->number_pdcch_ofdm_symbols++; - nCCE_max = - get_nCCE_max(&RC.mac[module_idP]->common_channels[CC_idP], - DL_req->number_pdcch_ofdm_symbols, - subframeP); - goto try_again; + LOG_D(MAC, "Trying to allocate format 0 DCI %d/%d (%d,%d) : rnti %x, aggreg %d nCCE %d / %d (num_pdcch_symbols %d)\n", + idci, + DL_req->number_dci + HI_DCI0_req->number_of_dci, + DL_req->number_dci, + HI_DCI0_req->number_of_dci, + hi_dci0_pduLoop->dci_pdu.dci_pdu_rel8.rnti, + hi_dci0_pduLoop->dci_pdu.dci_pdu_rel8.aggregation_level, + nCCE, nCCE_max, + DL_req->number_pdcch_ofdm_symbols); + + if (nCCE + hi_dci0_pduLoop->dci_pdu.dci_pdu_rel8.aggregation_level > nCCE_max) { + if (DL_req->number_pdcch_ofdm_symbols == max_symbol) + return -1; + + LOG_D(MAC, "Can't fit DCI allocations with %d PDCCH symbols, increasing by 1\n", + DL_req->number_pdcch_ofdm_symbols); + DL_req->number_pdcch_ofdm_symbols++; + nCCE_max = get_nCCE_max(cc, DL_req->number_pdcch_ofdm_symbols, subframeP); + goto try_again; } + // number of CCEs left can potentially hold this allocation fCCE = get_nCCE_offset(CCE_table, - hi_dci0_pdu[i].dci_pdu. - dci_pdu_rel8.aggregation_level, - nCCE_max, 0, - hi_dci0_pdu[i].dci_pdu.dci_pdu_rel8. - rnti, subframeP); + hi_dci0_pduLoop->dci_pdu.dci_pdu_rel8.aggregation_level, + nCCE_max, + 0, + hi_dci0_pduLoop->dci_pdu.dci_pdu_rel8.rnti, + subframeP); + if (fCCE == -1) { - if (DL_req->number_pdcch_ofdm_symbols == max_symbol) { - LOG_D(MAC, - "subframe %d: Dropping Allocation for RNTI %x\n", - subframeP, - hi_dci0_pdu[i].dci_pdu.dci_pdu_rel8.rnti); - for (j = 0; j <= i; j++) { - if (hi_dci0_pdu[j].pdu_type == - NFAPI_HI_DCI0_DCI_PDU_TYPE) - LOG_D(MAC, - "DCI %d/%d (%d,%d) : rnti %x dci format %d, aggreg %d nCCE %d / %d (num_pdcch_symbols %d)\n", - j, - DL_req->number_dci + HI_DCI0_req->number_of_dci, - DL_req->number_dci, - HI_DCI0_req->number_of_dci, - hi_dci0_pdu[j].dci_pdu.dci_pdu_rel8.rnti, - hi_dci0_pdu[j].dci_pdu.dci_pdu_rel8. - dci_format, - hi_dci0_pdu[j].dci_pdu. - dci_pdu_rel8.aggregation_level, nCCE, - nCCE_max, - DL_req->number_pdcch_ofdm_symbols); - } - //dump_CCE_table(CCE_table,nCCE_max,subframeP,dci_alloc->rnti,1<<dci_alloc->L); - goto failed; - } - LOG_D(MAC, - "Can't fit DCI allocations with %d PDCCH symbols (rnti condition), increasing by 1\n", - DL_req->number_pdcch_ofdm_symbols); - - DL_req->number_pdcch_ofdm_symbols++; - nCCE_max = - get_nCCE_max(&RC.mac[module_idP]->common_channels[CC_idP], - DL_req->number_pdcch_ofdm_symbols, - subframeP); - goto try_again; - } // fCCE==-1 + if (DL_req->number_pdcch_ofdm_symbols == max_symbol) { + LOG_D(MAC, "subframe %d: Dropping Allocation for RNTI %x\n", + subframeP, + hi_dci0_pduLoop->dci_pdu.dci_pdu_rel8.rnti); + + for (j = 0; j <= i; j++) { + hi_dci0_pduLoop = &hi_dci0_pdu[j]; + if (hi_dci0_pdu[j].pdu_type == NFAPI_HI_DCI0_DCI_PDU_TYPE) + LOG_D(MAC, "DCI %d/%d (%d,%d) : rnti %x dci format %d, aggreg %d nCCE %d / %d (num_pdcch_symbols %d)\n", + j, + DL_req->number_dci + HI_DCI0_req->number_of_dci, + DL_req->number_dci, + HI_DCI0_req->number_of_dci, + hi_dci0_pduLoop->dci_pdu.dci_pdu_rel8.rnti, + hi_dci0_pduLoop->dci_pdu.dci_pdu_rel8.dci_format, + hi_dci0_pduLoop->dci_pdu.dci_pdu_rel8.aggregation_level, + nCCE, nCCE_max, DL_req->number_pdcch_ofdm_symbols); + } + //dump_CCE_table(CCE_table,nCCE_max,subframeP,dci_alloc->rnti,1<<dci_alloc->L); + return -1; + } + + LOG_D(MAC, "Can't fit DCI allocations with %d PDCCH symbols (rnti condition), increasing by 1\n", + DL_req->number_pdcch_ofdm_symbols); + DL_req->number_pdcch_ofdm_symbols++; + nCCE_max = get_nCCE_max(cc, DL_req->number_pdcch_ofdm_symbols, subframeP); + goto try_again; + } // fCCE==-1 // the allocation is feasible, rnti rule passes - nCCE += hi_dci0_pdu[i].dci_pdu.dci_pdu_rel8.aggregation_level; - LOG_D(MAC, "Allocating at nCCE %d\n", fCCE); + nCCE += hi_dci0_pduLoop->dci_pdu.dci_pdu_rel8.aggregation_level; + LOG_D(MAC, "Allocating at nCCE %d\n", + fCCE); + if ((test_onlyP%2) == 0) { - hi_dci0_pdu[i].dci_pdu.dci_pdu_rel8.cce_index = fCCE; - LOG_D(MAC, "Allocate CCEs subframe %d, test %d\n", - subframeP, test_onlyP); + hi_dci0_pduLoop->dci_pdu.dci_pdu_rel8.cce_index = fCCE; + LOG_D(MAC, "Allocate CCEs subframe %d, test %d\n", + subframeP, + test_onlyP); } + idci++; } - } // for i = 0 ... num_UL_DCIs + } // for i = 0 ... num_UL_DCIs for (i = 0; i < DL_req->number_pdu; i++) { + dl_config_pduLoop = &dl_config_pdu[i]; // allocate DL UE specific DCIs if ((dl_config_pdu[i].pdu_type == NFAPI_DL_CONFIG_DCI_DL_PDU_TYPE) - && (dl_config_pdu[i].dci_dl_pdu.dci_dl_pdu_rel8.rnti_type == - 1)) { - LOG_D(MAC, - "Trying to allocate DL UE-SPECIFIC DCI %d/%d (%d,%d) : rnti %x, aggreg %d nCCE %d / %d (num_pdcch_symbols %d)\n", - idci, DL_req->number_dci + HI_DCI0_req->number_of_dci, - DL_req->number_dci, HI_DCI0_req->number_of_dci, - dl_config_pdu[i].dci_dl_pdu.dci_dl_pdu_rel8.rnti, - dl_config_pdu[i].dci_dl_pdu. - dci_dl_pdu_rel8.aggregation_level, nCCE, nCCE_max, - DL_req->number_pdcch_ofdm_symbols); - - if (nCCE + (dl_config_pdu[i].dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level) > nCCE_max) { - if (DL_req->number_pdcch_ofdm_symbols == max_symbol) - goto failed; - LOG_D(MAC, - "Can't fit DCI allocations with %d PDCCH symbols, increasing by 1\n", - DL_req->number_pdcch_ofdm_symbols); - - DL_req->number_pdcch_ofdm_symbols++; - nCCE_max = get_nCCE_max(&RC.mac[module_idP]->common_channels[CC_idP], - DL_req->number_pdcch_ofdm_symbols, - subframeP); - goto try_again; + && (dl_config_pduLoop->dci_dl_pdu.dci_dl_pdu_rel8.rnti_type == 1)) { + LOG_D(MAC, "Trying to allocate DL UE-SPECIFIC DCI %d/%d (%d,%d) : rnti %x, aggreg %d nCCE %d / %d (num_pdcch_symbols %d)\n", + idci, + DL_req->number_dci + HI_DCI0_req->number_of_dci, + DL_req->number_dci, HI_DCI0_req->number_of_dci, + dl_config_pduLoop->dci_dl_pdu.dci_dl_pdu_rel8.rnti, + dl_config_pduLoop->dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level, + nCCE, + nCCE_max, + DL_req->number_pdcch_ofdm_symbols); + + if (nCCE + (dl_config_pduLoop->dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level) > nCCE_max) { + if (DL_req->number_pdcch_ofdm_symbols == max_symbol) + return -1; + + LOG_D(MAC, "Can't fit DCI allocations with %d PDCCH symbols, increasing by 1\n", + DL_req->number_pdcch_ofdm_symbols); + DL_req->number_pdcch_ofdm_symbols++; + nCCE_max = get_nCCE_max(cc, DL_req->number_pdcch_ofdm_symbols, subframeP); + goto try_again; } + // number of CCEs left can potentially hold this allocation fCCE = get_nCCE_offset(CCE_table, - dl_config_pdu[i].dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level, nCCE_max, 0, - dl_config_pdu[i].dci_dl_pdu.dci_dl_pdu_rel8.rnti, - subframeP); + dl_config_pduLoop->dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level, + nCCE_max, + 0, + dl_config_pduLoop->dci_dl_pdu.dci_dl_pdu_rel8.rnti, + subframeP); + if (fCCE == -1) { - if (DL_req->number_pdcch_ofdm_symbols == max_symbol) { - LOG_I(MAC, - "subframe %d: Dropping Allocation for RNTI %x\n", - subframeP, - dl_config_pdu[i].dci_dl_pdu.dci_dl_pdu_rel8. - rnti); - for (j = 0; j <= i; j++) { - if (dl_config_pdu[j].pdu_type == NFAPI_DL_CONFIG_DCI_DL_PDU_TYPE) - LOG_D(MAC, - "DCI %d/%d (%d,%d) : rnti %x dci format %d, aggreg %d nCCE %d / %d (num_pdcch_symbols %d)\n", - j, - DL_req->number_dci + HI_DCI0_req->number_of_dci, - DL_req->number_dci, - HI_DCI0_req->number_of_dci, - dl_config_pdu[j].dci_dl_pdu.dci_dl_pdu_rel8.rnti, - dl_config_pdu[j].dci_dl_pdu.dci_dl_pdu_rel8.dci_format, - dl_config_pdu[j].dci_dl_pdu.dci_dl_pdu_rel8. - aggregation_level, - nCCE, - nCCE_max, - DL_req->number_pdcch_ofdm_symbols); - } - //dump_CCE_table(CCE_table,nCCE_max,subframeP,dci_alloc->rnti,1<<dci_alloc->L); - goto failed; - } - LOG_D(MAC, - "Can't fit DCI allocations with %d PDCCH symbols (rnti condition), increasing by 1\n", - DL_req->number_pdcch_ofdm_symbols); - - DL_req->number_pdcch_ofdm_symbols++; - nCCE_max = - get_nCCE_max(&RC.mac[module_idP]->common_channels[CC_idP], - DL_req->number_pdcch_ofdm_symbols, - subframeP); - goto try_again; - } // fCCE==-1 + if (DL_req->number_pdcch_ofdm_symbols == max_symbol) { + LOG_I(MAC, "subframe %d: Dropping Allocation for RNTI %x\n", + subframeP, + dl_config_pduLoop->dci_dl_pdu.dci_dl_pdu_rel8.rnti); + + for (j = 0; j <= i; j++) { + dl_config_pduLoop = &dl_config_pdu[j]; + if (dl_config_pduLoop->pdu_type == NFAPI_DL_CONFIG_DCI_DL_PDU_TYPE) + LOG_D(MAC, "DCI %d/%d (%d,%d) : rnti %x dci format %d, aggreg %d nCCE %d / %d (num_pdcch_symbols %d)\n", + j, + DL_req->number_dci + HI_DCI0_req->number_of_dci, + DL_req->number_dci, + HI_DCI0_req->number_of_dci, + dl_config_pduLoop->dci_dl_pdu.dci_dl_pdu_rel8.rnti, + dl_config_pduLoop->dci_dl_pdu.dci_dl_pdu_rel8.dci_format, + dl_config_pduLoop->dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level, + nCCE, + nCCE_max, + DL_req->number_pdcch_ofdm_symbols); + } + //dump_CCE_table(CCE_table,nCCE_max,subframeP,dci_alloc->rnti,1<<dci_alloc->L); + return -1; + } + + LOG_D(MAC, "Can't fit DCI allocations with %d PDCCH symbols (rnti condition), increasing by 1\n", + DL_req->number_pdcch_ofdm_symbols); + DL_req->number_pdcch_ofdm_symbols++; + nCCE_max = get_nCCE_max(cc, DL_req->number_pdcch_ofdm_symbols, subframeP); + goto try_again; + } // fCCE==-1 // the allocation is feasible, rnti rule passes - nCCE += dl_config_pdu[i].dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level; - LOG_D(MAC, "Allocating at nCCE %d\n", fCCE); + nCCE += dl_config_pduLoop->dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level; + LOG_D(MAC, "Allocating at nCCE %d\n", + fCCE); + if ((test_onlyP%2) == 0) { - dl_config_pdu[i].dci_dl_pdu.dci_dl_pdu_rel8.cce_idx = fCCE; - LOG_D(MAC, "Allocate CCEs subframe %d, test %d\n", - subframeP, test_onlyP); + dl_config_pduLoop->dci_dl_pdu.dci_dl_pdu_rel8.cce_idx = fCCE; + LOG_D(MAC, "Allocate CCEs subframe %d, test %d\n", + subframeP, + test_onlyP); } + if ((test_onlyP/2) == 1) { - for(int ack_int = 0;ack_int < ul_req->number_of_pdus; ack_int++){ - if(((ul_req->ul_config_pdu_list[ack_int].pdu_type == NFAPI_UL_CONFIG_UCI_HARQ_PDU_TYPE) || - (ul_req->ul_config_pdu_list[ack_int].pdu_type == NFAPI_UL_CONFIG_UCI_SR_HARQ_PDU_TYPE)) && - (ul_req->ul_config_pdu_list[ack_int].uci_harq_pdu.ue_information.ue_information_rel8.rnti == dl_config_pdu[i].dci_dl_pdu.dci_dl_pdu_rel8.rnti)){ - if (cc->tdd_Config==NULL) - ul_req->ul_config_pdu_list[ack_int].uci_harq_pdu.harq_information.harq_information_rel9_fdd.n_pucch_1_0 = - cc->radioResourceConfigCommon->pucch_ConfigCommon.n1PUCCH_AN + fCCE; - else - ul_req->ul_config_pdu_list[ack_int].uci_harq_pdu.harq_information.harq_information_rel10_tdd.n_pucch_1_0 = - cc->radioResourceConfigCommon->pucch_ConfigCommon.n1PUCCH_AN + fCCE + getNp(cc->mib->message.dl_Bandwidth,fCCE,0) ; + for(int ack_int = 0; ack_int < ul_req->number_of_pdus; ack_int++) { + if(((ul_req->ul_config_pdu_list[ack_int].pdu_type == NFAPI_UL_CONFIG_UCI_HARQ_PDU_TYPE) || + (ul_req->ul_config_pdu_list[ack_int].pdu_type == NFAPI_UL_CONFIG_UCI_SR_HARQ_PDU_TYPE)) && + (ul_req->ul_config_pdu_list[ack_int].uci_harq_pdu.ue_information.ue_information_rel8.rnti == dl_config_pdu[i].dci_dl_pdu.dci_dl_pdu_rel8.rnti)) { + if (cc->tdd_Config==NULL) + ul_req->ul_config_pdu_list[ack_int].uci_harq_pdu.harq_information.harq_information_rel9_fdd.n_pucch_1_0 = + cc->radioResourceConfigCommon->pucch_ConfigCommon.n1PUCCH_AN + fCCE; + else + ul_req->ul_config_pdu_list[ack_int].uci_harq_pdu.harq_information.harq_information_rel10_tdd.n_pucch_1_0 = + cc->radioResourceConfigCommon->pucch_ConfigCommon.n1PUCCH_AN + fCCE + getNp(cc->mib->message.dl_Bandwidth,fCCE,0) ; + } } - } } + idci++; } - } // for i = 0 ... num_DL_DCIs - + } // for i = 0 ... num_DL_DCIs return 0; - - failed: - return -1; } nfapi_ul_config_request_pdu_t *has_ul_grant(module_id_t module_idP, - int CC_idP, uint16_t absSFP, - uint16_t rnti) -{ + int CC_idP, uint16_t absSFP, + uint16_t rnti) { nfapi_ul_config_request_body_t *ul_req; nfapi_ul_config_request_pdu_t *ul_config_pdu; - ul_req = &RC.mac[module_idP]->UL_req_tmp[CC_idP][absSFP % 10].ul_config_request_body; ul_config_pdu = &ul_req->ul_config_pdu_list[0]; LOG_D(MAC, - "Checking for rnti %x UL grant in subframeP %d (num pdu %d)\n", - rnti, absSFP % 10, ul_req->number_of_pdus); + "Checking for rnti %x UL grant in subframeP %d (num pdu %d)\n", + rnti, absSFP % 10, ul_req->number_of_pdus); for (int i = 0; i < ul_req->number_of_pdus; i++) { LOG_D(MAC, "PDU %d : type %d,rnti %x\n", i,ul_config_pdu[i].pdu_type, rnti); + if ((ul_config_pdu[i].pdu_type == NFAPI_UL_CONFIG_ULSCH_PDU_TYPE) - && (ul_config_pdu[i].ulsch_pdu.ulsch_pdu_rel8.rnti == rnti)) + && (ul_config_pdu[i].ulsch_pdu.ulsch_pdu_rel8.rnti == rnti)) return (&ul_config_pdu[i]); + if ((ul_config_pdu[i].pdu_type == NFAPI_UL_CONFIG_ULSCH_CQI_RI_PDU_TYPE) - && (ul_config_pdu[i].ulsch_cqi_ri_pdu.ulsch_pdu.ulsch_pdu_rel8.rnti == rnti)) + && (ul_config_pdu[i].ulsch_cqi_ri_pdu.ulsch_pdu.ulsch_pdu_rel8.rnti == rnti)) return (&ul_config_pdu[i]); + if ((ul_config_pdu[i].pdu_type == NFAPI_UL_CONFIG_ULSCH_HARQ_PDU_TYPE) - && (ul_config_pdu[i].ulsch_harq_pdu.ulsch_pdu.ulsch_pdu_rel8.rnti == rnti)) + && (ul_config_pdu[i].ulsch_harq_pdu.ulsch_pdu.ulsch_pdu_rel8.rnti == rnti)) return (&ul_config_pdu[i]); + if ((ul_config_pdu[i].pdu_type == NFAPI_UL_CONFIG_ULSCH_CQI_HARQ_RI_PDU_TYPE) - && (ul_config_pdu[i].ulsch_cqi_harq_ri_pdu.ulsch_pdu.ulsch_pdu_rel8.rnti == rnti)) + && (ul_config_pdu[i].ulsch_cqi_harq_ri_pdu.ulsch_pdu.ulsch_pdu_rel8.rnti == rnti)) return (&ul_config_pdu[i]); if ((ul_config_pdu[i].pdu_type == NFAPI_UL_CONFIG_UCI_CQI_PDU_TYPE) - && (ul_config_pdu[i].uci_cqi_pdu.ue_information.ue_information_rel8.rnti == rnti)) + && (ul_config_pdu[i].uci_cqi_pdu.ue_information.ue_information_rel8.rnti == rnti)) return (&ul_config_pdu[i]); + if ((ul_config_pdu[i].pdu_type == NFAPI_UL_CONFIG_UCI_SR_PDU_TYPE) - && (ul_config_pdu[i].uci_sr_pdu.ue_information.ue_information_rel8.rnti == rnti)) + && (ul_config_pdu[i].uci_sr_pdu.ue_information.ue_information_rel8.rnti == rnti)) return (&ul_config_pdu[i]); + if ((ul_config_pdu[i].pdu_type == NFAPI_UL_CONFIG_UCI_HARQ_PDU_TYPE) - && (ul_config_pdu[i].uci_harq_pdu.ue_information.ue_information_rel8.rnti == rnti)) + && (ul_config_pdu[i].uci_harq_pdu.ue_information.ue_information_rel8.rnti == rnti)) return (&ul_config_pdu[i]); + if ((ul_config_pdu[i].pdu_type == NFAPI_UL_CONFIG_UCI_SR_HARQ_PDU_TYPE) - && (ul_config_pdu[i].uci_sr_harq_pdu.ue_information.ue_information_rel8.rnti == rnti)) + && (ul_config_pdu[i].uci_sr_harq_pdu.ue_information.ue_information_rel8.rnti == rnti)) return (&ul_config_pdu[i]); + if ((ul_config_pdu[i].pdu_type == NFAPI_UL_CONFIG_UCI_CQI_HARQ_PDU_TYPE) - && (ul_config_pdu[i].uci_cqi_harq_pdu.ue_information.ue_information_rel8.rnti == rnti)) + && (ul_config_pdu[i].uci_cqi_harq_pdu.ue_information.ue_information_rel8.rnti == rnti)) return (&ul_config_pdu[i]); + if ((ul_config_pdu[i].pdu_type == NFAPI_UL_CONFIG_UCI_CQI_SR_PDU_TYPE) - && (ul_config_pdu[i].uci_cqi_sr_pdu.ue_information.ue_information_rel8.rnti == rnti)) + && (ul_config_pdu[i].uci_cqi_sr_pdu.ue_information.ue_information_rel8.rnti == rnti)) return (&ul_config_pdu[i]); + if ((ul_config_pdu[i].pdu_type == NFAPI_UL_CONFIG_UCI_CQI_SR_HARQ_PDU_TYPE) - && (ul_config_pdu[i].uci_cqi_sr_harq_pdu.ue_information.ue_information_rel8.rnti == rnti)) + && (ul_config_pdu[i].uci_cqi_sr_harq_pdu.ue_information.ue_information_rel8.rnti == rnti)) return (&ul_config_pdu[i]); if ((ul_config_pdu[i].pdu_type == NFAPI_UL_CONFIG_ULSCH_UCI_CSI_PDU_TYPE) - && (ul_config_pdu[i].ulsch_uci_csi_pdu.ulsch_pdu.ulsch_pdu_rel8.rnti == rnti)) + && (ul_config_pdu[i].ulsch_uci_csi_pdu.ulsch_pdu.ulsch_pdu_rel8.rnti == rnti)) return (&ul_config_pdu[i]); + if ((ul_config_pdu[i].pdu_type == NFAPI_UL_CONFIG_ULSCH_UCI_HARQ_PDU_TYPE) - && (ul_config_pdu[i].ulsch_uci_harq_pdu.ulsch_pdu.ulsch_pdu_rel8.rnti == rnti)) + && (ul_config_pdu[i].ulsch_uci_harq_pdu.ulsch_pdu.ulsch_pdu_rel8.rnti == rnti)) return (&ul_config_pdu[i]); + if ((ul_config_pdu[i].pdu_type == NFAPI_UL_CONFIG_ULSCH_CSI_UCI_HARQ_PDU_TYPE) - && (ul_config_pdu[i].ulsch_csi_uci_harq_pdu.ulsch_pdu.ulsch_pdu_rel8.rnti == rnti)) + && (ul_config_pdu[i].ulsch_csi_uci_harq_pdu.ulsch_pdu.ulsch_pdu_rel8.rnti == rnti)) return (&ul_config_pdu[i]); } - return (NULL); // no ul grant at all for this UE + return (NULL); // no ul grant at all for this UE } +//----------------------------------------------------------------------------- boolean_t CCE_allocation_infeasible(int module_idP, - int CC_idP, - int format_flag, - int subframe, int aggregation, int rnti) + int CC_idP, + int format_flag, + int subframe, + int aggregation, + int rnti) +//----------------------------------------------------------------------------- { nfapi_dl_config_request_body_t *DL_req = &RC.mac[module_idP]->DL_req[CC_idP].dl_config_request_body; nfapi_dl_config_request_pdu_t *dl_config_pdu = &DL_req->dl_config_pdu_list[DL_req->number_pdu]; nfapi_hi_dci0_request_body_t *HI_DCI0_req = &RC.mac[module_idP]->HI_DCI0_req[CC_idP][subframe].hi_dci0_request_body; nfapi_hi_dci0_request_pdu_t *hi_dci0_pdu = &HI_DCI0_req->hi_dci0_pdu_list[HI_DCI0_req->number_of_dci + HI_DCI0_req->number_of_hi]; - int ret; - boolean_t res = FALSE; + boolean_t res = TRUE; - if (format_flag != 2) { // DL DCI + if (format_flag != 2) { // DL DCI if (DL_req->number_pdu == MAX_NUM_DL_PDU) { - LOG_W(MAC, - "Subframe %d: FAPI DL structure is full, skip scheduling UE %d\n", - subframe, rnti); + LOG_W(MAC, "Subframe %d: FAPI DL structure is full, skip scheduling UE %d\n", subframe, rnti); } else { dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.tl.tag = NFAPI_DL_CONFIG_REQUEST_DCI_DL_PDU_REL8_TAG; dl_config_pdu->pdu_type = NFAPI_DL_CONFIG_DCI_DL_PDU_TYPE; @@ -3282,229 +3304,219 @@ CCE_allocation_infeasible(int module_idP, dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti_type = (format_flag == 0) ? 2 : 1; dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level = aggregation; DL_req->number_pdu++; - LOG_D(MAC, - "Subframe %d: Checking CCE feasibility format %d : (%x,%d) (%x,%d,%d)\n", - subframe, format_flag, rnti, aggregation, - dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti, - dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8. - aggregation_level, - dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti_type); - ret = allocate_CCEs(module_idP, CC_idP, 0, subframe, 0); - if (ret == -1) res = TRUE; + LOG_D(MAC, "Subframe %d: Checking CCE feasibility format %d : (%x,%d) \n", + subframe, format_flag, rnti, aggregation); + + if (allocate_CCEs(module_idP, CC_idP, 0, subframe, 0) != -1) + res = FALSE; DL_req->number_pdu--; } - } else { // ue-specific UL DCI + } else { // ue-specific UL DCI if (HI_DCI0_req->number_of_dci + HI_DCI0_req->number_of_hi == MAX_NUM_HI_DCI0_PDU) { - LOG_W(MAC, - "Subframe %d: FAPI UL structure is full, skip scheduling UE %d\n", - subframe, rnti); + LOG_W(MAC, "Subframe %d: FAPI UL structure is full, skip scheduling UE %d\n", subframe, rnti); } else { hi_dci0_pdu->pdu_type = NFAPI_HI_DCI0_DCI_PDU_TYPE; hi_dci0_pdu->dci_pdu.dci_pdu_rel8.tl.tag = NFAPI_HI_DCI0_REQUEST_DCI_PDU_REL8_TAG; hi_dci0_pdu->dci_pdu.dci_pdu_rel8.rnti = rnti; hi_dci0_pdu->dci_pdu.dci_pdu_rel8.aggregation_level = aggregation; HI_DCI0_req->number_of_dci++; - ret = allocate_CCEs(module_idP, CC_idP, 0, subframe, 0); - if (ret == -1) res = TRUE; + + if (allocate_CCEs(module_idP, CC_idP, 0, subframe, 0) != -1) + res = FALSE; HI_DCI0_req->number_of_dci--; } } return res; } + void get_retransmission_timing(LTE_TDD_Config_t *tdd_Config, frame_t *frameP, - sub_frame_t *subframeP) -{ + sub_frame_t *subframeP) { + if (tdd_Config == NULL) { + if (*subframeP > 1) + *frameP = (*frameP + 1) % 1024; - if (tdd_Config == NULL) - { - if (*subframeP > 1) - *frameP = (*frameP + 1) % 1024; - *subframeP = (*subframeP + 8) % 10; - } - else - { - switch (tdd_Config->subframeAssignment)//TODO fill in other TDD configs - { - default: printf("%s:%d: TODO\n", __FILE__, __LINE__); abort(); - case 1: - if (*subframeP == 0 || *subframeP == 5) - { - *subframeP += 19; - *frameP = (*frameP + *subframeP/10) % 1024; - *subframeP %= 10; - } - else if (*subframeP == 4 || *subframeP == 9) - { - *subframeP += 16; - *frameP = (*frameP + *subframeP/10) % 1024; - *subframeP %= 10; - } - else - { - AssertFatal(2 == 1, - "Illegal dl subframe %d for tdd config %ld\n", *subframeP, - tdd_Config->subframeAssignment); - } - break; + *subframeP = (*subframeP + 8) % 10; + } else { + switch (tdd_Config->subframeAssignment) { //TODO fill in other TDD configs + default: + printf("%s:%d: TODO\n", __FILE__, __LINE__); + abort(); + + case 1: + if (*subframeP == 0 || *subframeP == 5) { + *subframeP += 19; + *frameP = (*frameP + *subframeP/10) % 1024; + *subframeP %= 10; + } else if (*subframeP == 4 || *subframeP == 9) { + *subframeP += 16; + *frameP = (*frameP + *subframeP/10) % 1024; + *subframeP %= 10; + } else { + AssertFatal(2 == 1, + "Illegal dl subframe %d for tdd config %ld\n", *subframeP, + tdd_Config->subframeAssignment); } + + break; } + } } -uint8_t get_dl_subframe_count(int tdd_config_sfa, sub_frame_t subframeP){ - - uint8_t tdd1[10] = {1,-1,-1,-1,2,3,-1,-1,-1,4}; // special subframes 1,6 are excluded +uint8_t get_dl_subframe_count(int tdd_config_sfa, sub_frame_t subframeP) { + uint8_t tdd1[10] = {1,-1,-1,-1,2,3,-1,-1,-1,4}; // special subframes 1,6 are excluded - switch(tdd_config_sfa){// TODO fill in other tdd configs + switch(tdd_config_sfa) { // TODO fill in other tdd configs case 1 : - return tdd1[subframeP]; - break; - } - return -1; + return tdd1[subframeP]; + break; + } + + return -1; } -uint8_t frame_subframe2_dl_harq_pid(LTE_TDD_Config_t *tdd_Config, int abs_frameP, sub_frame_t subframeP){ - int harq_pid; - if(tdd_Config){ - - switch(tdd_Config->subframeAssignment){ //TODO fill in other tdd config - case 1: - harq_pid = (((frame_cnt*1024 + abs_frameP) * 4) - 1 + get_dl_subframe_count(tdd_Config->subframeAssignment,subframeP))%7;//4 dl subframe in a frame - if(harq_pid < 0) - harq_pid += 7; - LOG_D(MAC,"[frame_subframe2_dl_harq_pid] (%d,%d) calculate harq_pid ((( %d * 1024 + %d) *4) - 1 + %d) = %d \n", - (abs_frameP+1024)%1024,subframeP,frame_cnt,abs_frameP, - get_dl_subframe_count(tdd_Config->subframeAssignment,subframeP),harq_pid); - return harq_pid; - break; - } - }else{ - return ((abs_frameP*10)+subframeP)&7; +uint8_t frame_subframe2_dl_harq_pid(LTE_TDD_Config_t *tdd_Config, int abs_frameP, sub_frame_t subframeP) { + int harq_pid; + + if(tdd_Config) { + switch(tdd_Config->subframeAssignment) { //TODO fill in other tdd config + case 1: + harq_pid = (((frame_cnt*1024 + abs_frameP) * 4) - 1 + get_dl_subframe_count(tdd_Config->subframeAssignment,subframeP))%7;//4 dl subframe in a frame + + if(harq_pid < 0) + harq_pid += 7; + + LOG_D(MAC,"[frame_subframe2_dl_harq_pid] (%d,%d) calculate harq_pid ((( %d * 1024 + %d) *4) - 1 + %d) = %d \n", + (abs_frameP+1024)%1024,subframeP,frame_cnt,abs_frameP, + get_dl_subframe_count(tdd_Config->subframeAssignment,subframeP),harq_pid); + return harq_pid; + break; } - return -1; -} + } else { + return ((abs_frameP*10)+subframeP)&7; + } -unsigned char ul_ACK_subframe2M(LTE_TDD_Config_t *tdd_Config,unsigned char subframe) -{ + return -1; +} +unsigned char ul_ACK_subframe2M(LTE_TDD_Config_t *tdd_Config,unsigned char subframe) { if (tdd_Config == NULL) { return(1); } else { switch (tdd_Config->subframeAssignment) { - case 1: + case 1: return 1; // don't ACK special subframe for now - if (subframe == 2) { // ACK subframes 5 and 6 - return(2); - } else if (subframe == 3) { // ACK subframe 9 - return(1); // To be updated - } else if (subframe == 7) { // ACK subframes 0 and 1 - return(2); // To be updated - } else if (subframe == 8) { // ACK subframe 4 - return(1); // To be updated - } else { - AssertFatal(1==0,"illegal subframe %d for tdd_config %ld\n", - subframe,tdd_Config->subframeAssignment); - } + if (subframe == 2) { // ACK subframes 5 and 6 + return(2); + } else if (subframe == 3) { // ACK subframe 9 + return(1); // To be updated + } else if (subframe == 7) { // ACK subframes 0 and 1 + return(2); // To be updated + } else if (subframe == 8) { // ACK subframe 4 + return(1); // To be updated + } else { + AssertFatal(1==0,"illegal subframe %d for tdd_config %ld\n", + subframe,tdd_Config->subframeAssignment); + } - break; - case 3: - if (subframe == 2) { // ACK subframes 5 and 6 - return(2); // should be 3 - } else if (subframe == 3) { // ACK subframes 7 and 8 - return(2); // To be updated - } else if (subframe == 4) { // ACK subframes 9 and 0 - return(2); - } else { - AssertFatal(1==0,"illegal subframe %d for tdd_config %ld\n", - subframe,tdd_Config->subframeAssignment); - } + break; - break; + case 3: + if (subframe == 2) { // ACK subframes 5 and 6 + return(2); // should be 3 + } else if (subframe == 3) { // ACK subframes 7 and 8 + return(2); // To be updated + } else if (subframe == 4) { // ACK subframes 9 and 0 + return(2); + } else { + AssertFatal(1==0,"illegal subframe %d for tdd_config %ld\n", + subframe,tdd_Config->subframeAssignment); + } - case 4: - if (subframe == 2) { // ACK subframes 0,4 and 5 - return(3); // should be 4 - } else if (subframe == 3) { // ACK subframes 6,7,8 and 9 - return(4); - } else { - AssertFatal(1==0,"illegal subframe %d for tdd_config %ld\n", - subframe,tdd_Config->subframeAssignment); - } + break; - break; + case 4: + if (subframe == 2) { // ACK subframes 0,4 and 5 + return(3); // should be 4 + } else if (subframe == 3) { // ACK subframes 6,7,8 and 9 + return(4); + } else { + AssertFatal(1==0,"illegal subframe %d for tdd_config %ld\n", + subframe,tdd_Config->subframeAssignment); + } - case 5: - if (subframe == 2) { // ACK subframes 0,3,4,5,6,7,8 and 9 - return(8); // should be 3 - } else { - AssertFatal(1==0,"illegal subframe %d for tdd_config %ld\n", - subframe,tdd_Config->subframeAssignment); - } + break; - break; + case 5: + if (subframe == 2) { // ACK subframes 0,3,4,5,6,7,8 and 9 + return(8); // should be 3 + } else { + AssertFatal(1==0,"illegal subframe %d for tdd_config %ld\n", + subframe,tdd_Config->subframeAssignment); + } + + break; } } return(0); } -unsigned char ul_ACK_subframe2dl_subframe(LTE_TDD_Config_t *tdd_Config,unsigned char subframe,unsigned char ACK_index) -{ - +unsigned char ul_ACK_subframe2dl_subframe(LTE_TDD_Config_t *tdd_Config,unsigned char subframe,unsigned char ACK_index) { if (tdd_Config == NULL) { return((subframe<4) ? subframe+6 : subframe-4); } else { switch (tdd_Config->subframeAssignment) { - case 3: - if (subframe == 2) { // ACK subframes 5 and 6 - if (ACK_index==2) - return(1); - - return(5+ACK_index); - } else if (subframe == 3) { // ACK subframes 7 and 8 - return(7+ACK_index); // To be updated - } else if (subframe == 4) { // ACK subframes 9 and 0 - return((9+ACK_index)%10); - } else { - AssertFatal(1==0,"illegal subframe %d for tdd_config->subframeAssignment %ld\n", - subframe,tdd_Config->subframeAssignment); - } + case 3: + if (subframe == 2) { // ACK subframes 5 and 6 + if (ACK_index==2) + return(1); + + return(5+ACK_index); + } else if (subframe == 3) { // ACK subframes 7 and 8 + return(7+ACK_index); // To be updated + } else if (subframe == 4) { // ACK subframes 9 and 0 + return((9+ACK_index)%10); + } else { + AssertFatal(1==0,"illegal subframe %d for tdd_config->subframeAssignment %ld\n", + subframe,tdd_Config->subframeAssignment); + } - break; + break; - case 4: - if (subframe == 2) { // ACK subframes 0, 4 and 5 - //if (ACK_index==2) - // return(1); TBC - if (ACK_index==2) + case 4: + if (subframe == 2) { // ACK subframes 0, 4 and 5 + //if (ACK_index==2) + // return(1); TBC + if (ACK_index==2) return(0); - return(4+ACK_index); - } else if (subframe == 3) { // ACK subframes 6, 7 8 and 9 - return(6+ACK_index); // To be updated - } else { - AssertFatal(1==0,"illegal subframe %d for tdd_config %ld\n", - subframe,tdd_Config->subframeAssignment); - } + return(4+ACK_index); + } else if (subframe == 3) { // ACK subframes 6, 7 8 and 9 + return(6+ACK_index); // To be updated + } else { + AssertFatal(1==0,"illegal subframe %d for tdd_config %ld\n", + subframe,tdd_Config->subframeAssignment); + } - break; + break; - case 1: - if (subframe == 2) { // ACK subframes 5 and 6 - return(5+ACK_index); - } else if (subframe == 3) { // ACK subframe 9 - return(9); // To be updated - } else if (subframe == 7) { // ACK subframes 0 and 1 - return(ACK_index); // To be updated - } else if (subframe == 8) { // ACK subframe 4 - return(4); // To be updated - } else { - AssertFatal(1==0,"illegal subframe %d for tdd_config %ld\n", - subframe,tdd_Config->subframeAssignment); - } + case 1: + if (subframe == 2) { // ACK subframes 5 and 6 + return(5+ACK_index); + } else if (subframe == 3) { // ACK subframe 9 + return(9); // To be updated + } else if (subframe == 7) { // ACK subframes 0 and 1 + return(ACK_index); // To be updated + } else if (subframe == 8) { // ACK subframe 4 + return(4); // To be updated + } else { + AssertFatal(1==0,"illegal subframe %d for tdd_config %ld\n", + subframe,tdd_Config->subframeAssignment); + } - break; + break; } } @@ -3513,9 +3525,8 @@ unsigned char ul_ACK_subframe2dl_subframe(LTE_TDD_Config_t *tdd_Config,unsigned void extract_harq(module_id_t mod_idP, int CC_idP, int UE_id, - frame_t frameP, sub_frame_t subframeP, - void *harq_indication, int format) -{ + frame_t frameP, sub_frame_t subframeP, + void *harq_indication, int format) { UE_list_t *UE_list = &RC.mac[mod_idP]->UE_list; UE_sched_ctrl *sched_ctl = &UE_list->UE_sched_ctrl[UE_id]; rnti_t rnti = UE_RNTI(mod_idP, UE_id); @@ -3532,496 +3543,551 @@ extract_harq(module_id_t mod_idP, int CC_idP, int UE_id, sub_frame_t subframe_tx; int frame_tx; uint8_t harq_pid; - #if (LTE_RRC_VERSION >= MAKE_VERSION(13, 0, 0)) + if (UE_list->UE_template[pCCid][UE_id].physicalConfigDedicated != NULL && UE_list->UE_template[pCCid][UE_id].physicalConfigDedicated->pucch_ConfigDedicated != NULL && (UE_list->UE_template[pCCid][UE_id].physicalConfigDedicated->ext7) && (UE_list->UE_template[pCCid][UE_id].physicalConfigDedicated->ext7->pucch_ConfigDedicated_r13) && (((UE_list->UE_template[pCCid][UE_id].physicalConfigDedicated->ext7->pucch_ConfigDedicated_r13->spatialBundlingPUCCH_r13) && (format == 0)) - || ((UE_list->UE_template[pCCid][UE_id].physicalConfigDedicated->ext7->pucch_ConfigDedicated_r13->spatialBundlingPUSCH_r13) - && (format == 1)))) + || ((UE_list->UE_template[pCCid][UE_id].physicalConfigDedicated->ext7->pucch_ConfigDedicated_r13->spatialBundlingPUSCH_r13) + && (format == 1)))) spatial_bundling = 1; + #endif + for (i = 0; i < numCC; i++) tmode[i] = get_tmode(mod_idP, i, UE_id); - + if (cc->tdd_Config) { harq_indication_tdd = (nfapi_harq_indication_tdd_rel13_t *) harq_indication; // pdu = &harq_indication_tdd->harq_tb_n[0]; - num_ack_nak = harq_indication_tdd->number_of_ack_nack; - + switch (harq_indication_tdd->mode) { - case 0: // Format 1a/b bundling - AssertFatal(numCC == 1, "numCC %d > 1, should not be using Format1a/b\n", numCC); - int M = ul_ACK_subframe2M(cc->tdd_Config,subframeP); - for(m=0;m<M;m++){ - subframe_tx = ul_ACK_subframe2dl_subframe(cc->tdd_Config,subframeP,m); - if(frameP==1023&&subframeP>5) - frame_tx=-1; - else - frame_tx = subframeP < 4 ? frameP -1 : frameP; - harq_pid = frame_subframe2_dl_harq_pid(cc->tdd_Config,frame_tx,subframe_tx); - RA_t *ra = &RC.mac[mod_idP]->common_channels[CC_idP].ra[0]; - - if(num_ack_nak==1){ - if(harq_indication_tdd->harq_data[0].bundling.value_0==1){ //ack - sched_ctl->round[CC_idP][harq_pid] = 8; // release HARQ process - sched_ctl->tbcnt[CC_idP][harq_pid] = 0; - LOG_D(MAC,"frame %d subframe %d Acking (%d,%d) harq_pid %d round %d\n",frameP,subframeP,frame_tx,subframe_tx,harq_pid,sched_ctl->round[CC_idP][harq_pid]); - }else{ //nack - if( sched_ctl->round[CC_idP][harq_pid]<8) sched_ctl->round[CC_idP][harq_pid]++; - if (sched_ctl->round[CC_idP][harq_pid] == 4) { - sched_ctl->round[CC_idP][harq_pid] = 8; // release HARQ process - sched_ctl->tbcnt[CC_idP][harq_pid] = 0; - } - LOG_D(MAC,"frame %d subframe %d Nacking (%d,%d) harq_pid %d round %d\n",frameP,subframeP,frame_tx,subframe_tx,harq_pid,sched_ctl->round[CC_idP][harq_pid]); - if(sched_ctl->round[CC_idP][harq_pid] == 8){ - for (uint8_t ra_i = 0; ra_i < NB_RA_PROC_MAX; ra_i++) { - if((ra[ra_i].rnti == rnti) && (ra[ra_i].state == WAITMSG4ACK)){ - //Msg NACK num to MAC ,remove UE - // add UE info to freeList - LOG_I(RRC, "put UE %x into freeList\n", rnti); - put_UE_in_freelist(mod_idP, rnti, 1); - } - } - } - } - } - for (uint8_t ra_i = 0; ra_i < NB_RA_PROC_MAX; ra_i++) { - if ((ra[ra_i].rnti == rnti) && (ra[ra_i].state == MSGCRNTI_ACK) && (ra[ra_i].crnti_harq_pid == harq_pid)) { - LOG_D(MAC,"CRNTI Reconfiguration: ACK %d rnti %x round %d frame %d subframe %d \n",harq_indication_tdd->harq_data[0].bundling.value_0,rnti,sched_ctl->round[CC_idP][harq_pid],frameP,subframeP); - if(num_ack_nak == 1 && harq_indication_tdd->harq_data[0].bundling.value_0 == 1) { - cancel_ra_proc(mod_idP, CC_idP, frameP, ra[ra_i].rnti); - }else{ - if(sched_ctl->round[CC_idP][harq_pid] == 7){ - cancel_ra_proc(mod_idP, CC_idP, frameP, ra[ra_i].rnti); + case 0: // Format 1a/b bundling + AssertFatal(numCC == 1, "numCC %d > 1, should not be using Format1a/b\n", numCC); + int M = ul_ACK_subframe2M(cc->tdd_Config,subframeP); + + for(m=0; m<M; m++) { + subframe_tx = ul_ACK_subframe2dl_subframe(cc->tdd_Config,subframeP,m); + + if(frameP==1023&&subframeP>5) + frame_tx=-1; + else + frame_tx = subframeP < 4 ? frameP -1 : frameP; + + harq_pid = frame_subframe2_dl_harq_pid(cc->tdd_Config,frame_tx,subframe_tx); + RA_t *ra = &RC.mac[mod_idP]->common_channels[CC_idP].ra[0]; + + if(num_ack_nak==1) { + if(harq_indication_tdd->harq_data[0].bundling.value_0==1) { //ack + sched_ctl->round[CC_idP][harq_pid] = 8; // release HARQ process + sched_ctl->tbcnt[CC_idP][harq_pid] = 0; + LOG_D(MAC,"frame %d subframe %d Acking (%d,%d) harq_pid %d round %d\n",frameP,subframeP,frame_tx,subframe_tx,harq_pid,sched_ctl->round[CC_idP][harq_pid]); + } else { //nack + if( sched_ctl->round[CC_idP][harq_pid]<8) sched_ctl->round[CC_idP][harq_pid]++; + + if (sched_ctl->round[CC_idP][harq_pid] == 4) { + sched_ctl->round[CC_idP][harq_pid] = 8; // release HARQ process + sched_ctl->tbcnt[CC_idP][harq_pid] = 0; + } + + LOG_D(MAC,"frame %d subframe %d Nacking (%d,%d) harq_pid %d round %d\n",frameP,subframeP,frame_tx,subframe_tx,harq_pid,sched_ctl->round[CC_idP][harq_pid]); + + if(sched_ctl->round[CC_idP][harq_pid] == 8) { + for (uint8_t ra_i = 0; ra_i < NB_RA_PROC_MAX; ra_i++) { + if((ra[ra_i].rnti == rnti) && (ra[ra_i].state == WAITMSG4ACK)) { + //Msg NACK num to MAC ,remove UE + // add UE info to freeList + LOG_I(RRC, "put UE %x into freeList\n", rnti); + put_UE_in_freelist(mod_idP, rnti, 1); + } + } + } + } + } + + for (uint8_t ra_i = 0; ra_i < NB_RA_PROC_MAX; ra_i++) { + if ((ra[ra_i].rnti == rnti) && (ra[ra_i].state == MSGCRNTI_ACK) && (ra[ra_i].crnti_harq_pid == harq_pid)) { + LOG_D(MAC,"CRNTI Reconfiguration: ACK %d rnti %x round %d frame %d subframe %d \n",harq_indication_tdd->harq_data[0].bundling.value_0,rnti,sched_ctl->round[CC_idP][harq_pid],frameP,subframeP); + + if(num_ack_nak == 1 && harq_indication_tdd->harq_data[0].bundling.value_0 == 1) { + cancel_ra_proc(mod_idP, CC_idP, frameP, ra[ra_i].rnti); + } else { + if(sched_ctl->round[CC_idP][harq_pid] == 7) { + cancel_ra_proc(mod_idP, CC_idP, frameP, ra[ra_i].rnti); + } + } + + break; + } } - } - break; } - } - } - break; - case 1: // Channel Selection - break; - case 2: // Format 3 - break; - case 3: // Format 4 - break; - case 4: // Format 5 - break; + + break; + + case 1: // Channel Selection + break; + + case 2: // Format 3 + break; + + case 3: // Format 4 + break; + + case 4: // Format 5 + break; } } else { harq_indication_fdd = (nfapi_harq_indication_fdd_rel13_t *) harq_indication; num_ack_nak = harq_indication_fdd->number_of_ack_nack; pdu = &harq_indication_fdd->harq_tb_n[0]; - harq_pid = ((10 * frameP) + subframeP + 10236) & 7; - LOG_D(MAC,"frame %d subframe %d harq_pid %d mode %d tmode[0] %d num_ack_nak %d round %d\n",frameP,subframeP,harq_pid,harq_indication_fdd->mode,tmode[0],num_ack_nak,sched_ctl->round[CC_idP][harq_pid]); // use 1 HARQ proces of BL/CE UE for now if (UE_list->UE_template[pCCid][UE_id].rach_resource_type > 0) harq_pid = 0; switch (harq_indication_fdd->mode) { - case 0: // Format 1a/b (10.1.2.1) - AssertFatal(numCC == 1, - "numCC %d > 1, should not be using Format1a/b\n", - numCC); - if (tmode[0] == 1 || tmode[0] == 2 || tmode[0] == 5 || tmode[0] == 6 || tmode[0] == 7) { // NOTE: have to handle the case of TM9-10 with 1 antenna port - // single ACK/NAK bit - AssertFatal(num_ack_nak == 1, - "num_ack_nak %d > 1 for 1 CC and single-layer transmission frame:%d subframe:%d\n", - num_ack_nak,frameP,subframeP); - - // In case of nFAPI, sometimes timing of eNB and UE become different. - // So if nfapi_mode == 2(VNF) , this function don't check assertion to avoid process exit. - if (nfapi_mode != 2){ - AssertFatal(sched_ctl->round[CC_idP][harq_pid] < 8, - "Got ACK/NAK for inactive harq_pid %d for UE %d/%x\n", - harq_pid, UE_id, rnti); - } else { - if(sched_ctl->round[CC_idP][harq_pid] == 8){ - LOG_E(MAC,"Got ACK/NAK for inactive harq_pid %d for UE %d/%x\n",harq_pid, UE_id, rnti); - return; - } - } - AssertFatal(pdu[0] == 1 || pdu[0] == 2 - || pdu[0] == 4, - "Received ACK/NAK %d which is not 1 or 2 for harq_pid %d from UE %d/%x\n", - pdu[0], harq_pid, UE_id, rnti); - LOG_D(MAC, "Received %d for harq_pid %d\n", pdu[0], - harq_pid); - - RA_t *ra = &RC.mac[mod_idP]->common_channels[CC_idP].ra[0]; - for (uint8_t ra_i = 0; ra_i < NB_RA_PROC_MAX; ra_i++) { - if ((ra[ra_i].rnti == rnti) && (ra[ra_i].state == MSGCRNTI_ACK) && - (ra[ra_i].crnti_harq_pid == harq_pid)) { - LOG_D(MAC,"CRNTI Reconfiguration: ACK %d rnti %x round %d frame %d subframe %d \n",pdu[0],rnti,sched_ctl->round[CC_idP][harq_pid],frameP,subframeP); - if(pdu[0] == 1){ - cancel_ra_proc(mod_idP, CC_idP, frameP, ra[ra_i].rnti); - }else{ - if(sched_ctl->round[CC_idP][harq_pid] == 7){ - cancel_ra_proc(mod_idP, CC_idP, frameP, ra[ra_i].rnti); - } - } - break; - } - } - - if (pdu[0] == 1) { // ACK - sched_ctl->round[CC_idP][harq_pid] = 8; // release HARQ process - sched_ctl->tbcnt[CC_idP][harq_pid] = 0; - } else if (pdu[0] == 2 || pdu[0] == 4) { // NAK (treat DTX as NAK) - sched_ctl->round[CC_idP][harq_pid]++; // increment round - if (sched_ctl->round[CC_idP][harq_pid] == 4) { - sched_ctl->round[CC_idP][harq_pid] = 8; // release HARQ process - sched_ctl->tbcnt[CC_idP][harq_pid] = 0; + case 0: // Format 1a/b (10.1.2.1) + AssertFatal(numCC == 1, "numCC %d > 1, should not be using Format1a/b\n", numCC); + if (tmode[0] == 1 || tmode[0] == 2 || tmode[0] == 5 || tmode[0] == 6 || tmode[0] == 7) { // NOTE: have to handle the case of TM9-10 with 1 antenna port + // single ACK/NAK bit + AssertFatal(num_ack_nak == 1, "num_ack_nak %d > 1 for 1 CC and single-layer transmission frame:%d subframe:%d\n", num_ack_nak,frameP,subframeP); + + // In case of nFAPI, sometimes timing of eNB and UE become different. + // So if nfapi_mode == 2(VNF) , this function don't check assertion to avoid process exit. + if (nfapi_mode != 2) { + AssertFatal(sched_ctl->round[CC_idP][harq_pid] < 8, "Got ACK/NAK for inactive harq_pid %d for UE %d/%x\n", + harq_pid, + UE_id, + rnti); + } else { + if (sched_ctl->round[CC_idP][harq_pid] == 8) { + LOG_E(MAC,"Got ACK/NAK for inactive harq_pid %d for UE %d/%x\n", harq_pid, UE_id, rnti); + return; + } } - if (sched_ctl->round[CC_idP][harq_pid] == 8){ - for (uint8_t ra_i = 0; ra_i < NB_RA_PROC_MAX; ra_i++) { - if((ra[ra_i].rnti == rnti) && (ra[ra_i].state == WAITMSG4ACK)){ - //Msg NACK num to MAC ,remove UE - // add UE info to freeList - LOG_I(RRC, "put UE %x into freeList\n", rnti); - put_UE_in_freelist(mod_idP, rnti, 1); + + AssertFatal(pdu[0] == 1 || pdu[0] == 2 || pdu[0] == 4, "Received ACK/NAK %d which is not 1 or 2 for harq_pid %d from UE %d/%x\n", + pdu[0], + harq_pid, + UE_id, + rnti); + + LOG_D(MAC, "Received %d for harq_pid %d\n", pdu[0], harq_pid); + + RA_t *ra = &RC.mac[mod_idP]->common_channels[CC_idP].ra[0]; + + for (uint8_t ra_i = 0; ra_i < NB_RA_PROC_MAX; ra_i++) { + if ((ra[ra_i].rnti == rnti) && (ra[ra_i].state == MSGCRNTI_ACK) && (ra[ra_i].crnti_harq_pid == harq_pid)) { + LOG_D(MAC,"CRNTI Reconfiguration: ACK %d rnti %x round %d frame %d subframe %d \n", + pdu[0], + rnti, + sched_ctl->round[CC_idP][harq_pid], + frameP,subframeP); + + if (pdu[0] == 1) { + cancel_ra_proc(mod_idP, CC_idP, frameP, ra[ra_i].rnti); + } else { + if(sched_ctl->round[CC_idP][harq_pid] == 7) { + cancel_ra_proc(mod_idP, CC_idP, frameP, ra[ra_i].rnti); + } + } + + break; } - } } - } - } else { - // one or two ACK/NAK bits - AssertFatal(num_ack_nak <= 2, - "num_ack_nak %d > 2 for 1 CC and TM3/4/8/9/10\n", - num_ack_nak); - if ((num_ack_nak == 2) - && (sched_ctl->round[CC_idP][harq_pid] < 8) - && (sched_ctl->tbcnt[CC_idP][harq_pid] == 1) - && (pdu[0] == 1) && (pdu[1] == 1)) { - sched_ctl->round[CC_idP][harq_pid] = 8; - sched_ctl->tbcnt[CC_idP][harq_pid] = 0; - } - if ((num_ack_nak == 2) - && (sched_ctl->round[CC_idP][harq_pid] < 8) - && (sched_ctl->tbcnt[CC_idP][harq_pid] == 1) - && (pdu[0] == 2) && (pdu[1] == 2)) { - sched_ctl->round[CC_idP][harq_pid]++; - if (sched_ctl->round[CC_idP][harq_pid] == 4) { - sched_ctl->round[CC_idP][harq_pid] = 8; // release HARQ process + + if (pdu[0] == 1) { // ACK + sched_ctl->round[CC_idP][harq_pid] = 8; // release HARQ process sched_ctl->tbcnt[CC_idP][harq_pid] = 0; + } else if (pdu[0] == 2 || pdu[0] == 4) { // NAK (treat DTX as NAK) + sched_ctl->round[CC_idP][harq_pid]++; // increment round + + if (sched_ctl->round[CC_idP][harq_pid] == 4) { + sched_ctl->round[CC_idP][harq_pid] = 8; // release HARQ process + sched_ctl->tbcnt[CC_idP][harq_pid] = 0; + } + + if (sched_ctl->round[CC_idP][harq_pid] == 8) { + for (uint8_t ra_i = 0; ra_i < NB_RA_PROC_MAX; ra_i++) { + if((ra[ra_i].rnti == rnti) && (ra[ra_i].state == WAITMSG4ACK)) { + //Msg NACK num to MAC ,remove UE + // add UE info to freeList + LOG_I(RRC, "put UE %x into freeList\n", rnti); + put_UE_in_freelist(mod_idP, rnti, 1); + } + } + } } - } - else if (((num_ack_nak == 2) - && (sched_ctl->round[CC_idP][harq_pid] < 8) - && (sched_ctl->tbcnt[0][harq_pid] == 2) - && (pdu[0] == 1) && (pdu[1] == 2)) - || ((num_ack_nak == 2) - && (sched_ctl->round[CC_idP][harq_pid] < 8) - && (sched_ctl->tbcnt[CC_idP][harq_pid] == 2) - && (pdu[0] == 2) && (pdu[1] == 1))) { - sched_ctl->round[CC_idP][harq_pid]++; - sched_ctl->tbcnt[CC_idP][harq_pid] = 1; - if (sched_ctl->round[CC_idP][harq_pid] == 4) { - sched_ctl->round[CC_idP][harq_pid] = 8; // release HARQ process - sched_ctl->tbcnt[CC_idP][harq_pid] = 0; /* TODO: do we have to set it to 0? */ - } - } else if ((num_ack_nak == 2) - && (sched_ctl->round[CC_idP][harq_pid] < 8) - && (sched_ctl->tbcnt[CC_idP][harq_pid] == 2) - && (pdu[0] == 2) && (pdu[1] == 2)) { - sched_ctl->round[CC_idP][harq_pid]++; - if (sched_ctl->round[CC_idP][harq_pid] == 4) { - sched_ctl->round[CC_idP][harq_pid] = 8; // release HARQ process + } else { + // one or two ACK/NAK bits + AssertFatal(num_ack_nak <= 2, + "num_ack_nak %d > 2 for 1 CC and TM3/4/8/9/10\n", + num_ack_nak); + + if ((num_ack_nak == 2) + && (sched_ctl->round[CC_idP][harq_pid] < 8) + && (sched_ctl->tbcnt[CC_idP][harq_pid] == 1) + && (pdu[0] == 1) && (pdu[1] == 1)) { + sched_ctl->round[CC_idP][harq_pid] = 8; sched_ctl->tbcnt[CC_idP][harq_pid] = 0; } + + if ((num_ack_nak == 2) + && (sched_ctl->round[CC_idP][harq_pid] < 8) + && (sched_ctl->tbcnt[CC_idP][harq_pid] == 1) + && (pdu[0] == 2) && (pdu[1] == 2)) { + sched_ctl->round[CC_idP][harq_pid]++; + + if (sched_ctl->round[CC_idP][harq_pid] == 4) { + sched_ctl->round[CC_idP][harq_pid] = 8; // release HARQ process + sched_ctl->tbcnt[CC_idP][harq_pid] = 0; + } + } else if (((num_ack_nak == 2) + && (sched_ctl->round[CC_idP][harq_pid] < 8) + && (sched_ctl->tbcnt[0][harq_pid] == 2) + && (pdu[0] == 1) && (pdu[1] == 2)) + || ((num_ack_nak == 2) + && (sched_ctl->round[CC_idP][harq_pid] < 8) + && (sched_ctl->tbcnt[CC_idP][harq_pid] == 2) + && (pdu[0] == 2) && (pdu[1] == 1))) { + sched_ctl->round[CC_idP][harq_pid]++; + sched_ctl->tbcnt[CC_idP][harq_pid] = 1; + + if (sched_ctl->round[CC_idP][harq_pid] == 4) { + sched_ctl->round[CC_idP][harq_pid] = 8; // release HARQ process + sched_ctl->tbcnt[CC_idP][harq_pid] = 0; /* TODO: do we have to set it to 0? */ + } + } else if ((num_ack_nak == 2) + && (sched_ctl->round[CC_idP][harq_pid] < 8) + && (sched_ctl->tbcnt[CC_idP][harq_pid] == 2) + && (pdu[0] == 2) && (pdu[1] == 2)) { + sched_ctl->round[CC_idP][harq_pid]++; + + if (sched_ctl->round[CC_idP][harq_pid] == 4) { + sched_ctl->round[CC_idP][harq_pid] = 8; // release HARQ process + sched_ctl->tbcnt[CC_idP][harq_pid] = 0; + } + } else + AssertFatal(1 == 0, + "Illegal ACK/NAK/round combination (%d,%d,%d,%d,%d) for harq_pid %d, UE %d/%x\n", + num_ack_nak, + sched_ctl->round[CC_idP][harq_pid], + sched_ctl->round[CC_idP][harq_pid], pdu[0], + pdu[1], harq_pid, UE_id, rnti); } - else - AssertFatal(1 == 0, - "Illegal ACK/NAK/round combination (%d,%d,%d,%d,%d) for harq_pid %d, UE %d/%x\n", - num_ack_nak, - sched_ctl->round[CC_idP][harq_pid], - sched_ctl->round[CC_idP][harq_pid], pdu[0], - pdu[1], harq_pid, UE_id, rnti); - } - break; - case 1: // FDD Channel Selection (10.1.2.2.1), must be received for 2 serving cells - AssertFatal(numCC == 2, - "Should not receive harq indication with channel selection with %d active CCs\n", - numCC); - - if ((num_ack_nak == 2) - && (sched_ctl->round[pCCid][harq_pid] < 8) - && (sched_ctl->round[1 - pCCid][harq_pid] < 8) - && (sched_ctl->tbcnt[pCCid][harq_pid] == 1) - && (sched_ctl->tbcnt[1 - pCCid][harq_pid] == 1)) { - AssertFatal(pdu[0] <= 3, "pdu[0] %d is not ACK/NAK/DTX\n", - pdu[0]); - AssertFatal(pdu[1] <= 3, "pdu[1] %d is not ACK/NAK/DTX\n", - pdu[1]); - if (pdu[0] == 1) - sched_ctl->round[pCCid][harq_pid] = 8; - else { - sched_ctl->round[pCCid][harq_pid]++; - if (sched_ctl->round[pCCid][harq_pid] == 4) - sched_ctl->round[pCCid][harq_pid] = 8; - } - if (pdu[1] == 1) - sched_ctl->round[1 - pCCid][harq_pid] = 8; - else { - sched_ctl->round[1 - pCCid][harq_pid]++; - if (sched_ctl->round[1 - pCCid][harq_pid] == 4) - sched_ctl->round[1 - pCCid][harq_pid] = 8; - } - } // A=2 - else if ((num_ack_nak == 3) - && (sched_ctl->round[pCCid][harq_pid] < 8) - && (sched_ctl->tbcnt[pCCid][harq_pid] == 2) - && (sched_ctl->round[1 - pCCid][harq_pid] < 8) - && (sched_ctl->tbcnt[1 - pCCid][harq_pid] == 1)) { - AssertFatal(pdu[0] <= 3, "pdu[0] %d is not ACK/NAK/DTX\n", - pdu[0]); - AssertFatal(pdu[1] <= 3, "pdu[1] %d is not ACK/NAK/DTX\n", - pdu[1]); - AssertFatal(pdu[2] <= 3, "pdu[2] %d is not ACK/NAK/DTX\n", - pdu[2]); - AssertFatal(sched_ctl->tbcnt[pCCid][harq_pid] == 2, - "sched_ctl->tbcnt[%d][%d] != 2 for UE %d/%x\n", - pCCid, harq_pid, UE_id, rnti); - AssertFatal(sched_ctl->tbcnt[1 - pCCid][harq_pid] == 1, - "sched_ctl->tbcnt[%d][%d] != 1 for UE %d/%x\n", - 1 - pCCid, harq_pid, UE_id, rnti); - if ((pdu[0] == 1) && (pdu[1] == 1)) { // both ACK - sched_ctl->round[pCCid][harq_pid] = 8; - sched_ctl->tbcnt[pCCid][harq_pid] = 0; - } else if (((pdu[0] == 2) && (pdu[1] == 1)) || - ((pdu[0] == 1) && (pdu[1] == 2))) { - sched_ctl->round[pCCid][harq_pid]++; - sched_ctl->tbcnt[pCCid][harq_pid] = 1; - if (sched_ctl->round[pCCid][harq_pid] == 4) { - sched_ctl->round[pCCid][harq_pid] = 8; - sched_ctl->tbcnt[pCCid][harq_pid] = 0; /* TODO: do we have to set it to 0? */ + + break; + + case 1: // FDD Channel Selection (10.1.2.2.1), must be received for 2 serving cells + AssertFatal(numCC == 2, + "Should not receive harq indication with channel selection with %d active CCs\n", + numCC); + + if ((num_ack_nak == 2) + && (sched_ctl->round[pCCid][harq_pid] < 8) + && (sched_ctl->round[1 - pCCid][harq_pid] < 8) + && (sched_ctl->tbcnt[pCCid][harq_pid] == 1) + && (sched_ctl->tbcnt[1 - pCCid][harq_pid] == 1)) { + AssertFatal(pdu[0] <= 3, "pdu[0] %d is not ACK/NAK/DTX\n", + pdu[0]); + AssertFatal(pdu[1] <= 3, "pdu[1] %d is not ACK/NAK/DTX\n", + pdu[1]); + + if (pdu[0] == 1) + sched_ctl->round[pCCid][harq_pid] = 8; + else { + sched_ctl->round[pCCid][harq_pid]++; + + if (sched_ctl->round[pCCid][harq_pid] == 4) + sched_ctl->round[pCCid][harq_pid] = 8; } - } else { - sched_ctl->round[pCCid][harq_pid]++; - if (sched_ctl->round[pCCid][harq_pid] == 4) { - sched_ctl->round[pCCid][harq_pid] = 8; - sched_ctl->tbcnt[pCCid][harq_pid] = 0; + + if (pdu[1] == 1) + sched_ctl->round[1 - pCCid][harq_pid] = 8; + else { + sched_ctl->round[1 - pCCid][harq_pid]++; + + if (sched_ctl->round[1 - pCCid][harq_pid] == 4) + sched_ctl->round[1 - pCCid][harq_pid] = 8; } - } + } // A=2 + else if ((num_ack_nak == 3) + && (sched_ctl->round[pCCid][harq_pid] < 8) + && (sched_ctl->tbcnt[pCCid][harq_pid] == 2) + && (sched_ctl->round[1 - pCCid][harq_pid] < 8) + && (sched_ctl->tbcnt[1 - pCCid][harq_pid] == 1)) { + AssertFatal(pdu[0] <= 3, "pdu[0] %d is not ACK/NAK/DTX\n", + pdu[0]); + AssertFatal(pdu[1] <= 3, "pdu[1] %d is not ACK/NAK/DTX\n", + pdu[1]); + AssertFatal(pdu[2] <= 3, "pdu[2] %d is not ACK/NAK/DTX\n", + pdu[2]); + AssertFatal(sched_ctl->tbcnt[pCCid][harq_pid] == 2, + "sched_ctl->tbcnt[%d][%d] != 2 for UE %d/%x\n", + pCCid, harq_pid, UE_id, rnti); + AssertFatal(sched_ctl->tbcnt[1 - pCCid][harq_pid] == 1, + "sched_ctl->tbcnt[%d][%d] != 1 for UE %d/%x\n", + 1 - pCCid, harq_pid, UE_id, rnti); + + if ((pdu[0] == 1) && (pdu[1] == 1)) { // both ACK + sched_ctl->round[pCCid][harq_pid] = 8; + sched_ctl->tbcnt[pCCid][harq_pid] = 0; + } else if (((pdu[0] == 2) && (pdu[1] == 1)) || + ((pdu[0] == 1) && (pdu[1] == 2))) { + sched_ctl->round[pCCid][harq_pid]++; + sched_ctl->tbcnt[pCCid][harq_pid] = 1; + + if (sched_ctl->round[pCCid][harq_pid] == 4) { + sched_ctl->round[pCCid][harq_pid] = 8; + sched_ctl->tbcnt[pCCid][harq_pid] = 0; /* TODO: do we have to set it to 0? */ + } + } else { + sched_ctl->round[pCCid][harq_pid]++; - if (pdu[2] == 1) - sched_ctl->round[1 - pCCid][harq_pid] = 8; - else { - sched_ctl->round[1 - pCCid][harq_pid]++; - if (sched_ctl->round[1 - pCCid][harq_pid] == 4) { - sched_ctl->round[1 - pCCid][harq_pid] = 8; + if (sched_ctl->round[pCCid][harq_pid] == 4) { + sched_ctl->round[pCCid][harq_pid] = 8; + sched_ctl->tbcnt[pCCid][harq_pid] = 0; + } } - } - } // A=3 primary cell has 2 TBs - else if ((num_ack_nak == 3) - && (sched_ctl->round[1 - pCCid][harq_pid] < 8) - && (sched_ctl->round[pCCid][harq_pid] < 8) - && (sched_ctl->tbcnt[1 - pCCid][harq_pid] == 2) - && (sched_ctl->tbcnt[pCCid][harq_pid] == 1)) { - AssertFatal(pdu[0] <= 3, "pdu[0] %d is not ACK/NAK/DTX\n", - pdu[0]); - AssertFatal(pdu[1] <= 3, "pdu[1] %d is not ACK/NAK/DTX\n", - pdu[1]); - AssertFatal(pdu[2] <= 3, "pdu[2] %d is not ACK/NAK/DTX\n", - pdu[2]); - AssertFatal(sched_ctl->tbcnt[1 - pCCid][harq_pid] == 2, - "sched_ctl->tbcnt[%d][%d] != 2 for UE %d/%x\n", - 1 - pCCid, harq_pid, UE_id, rnti); - AssertFatal(sched_ctl->tbcnt[pCCid][harq_pid] == 1, - "sched_ctl->tbcnt[%d][%d] != 1 for UE %d/%x\n", - pCCid, harq_pid, UE_id, rnti); - if ((pdu[0] == 1) && (pdu[1] == 1)) { // both ACK - sched_ctl->round[1 - pCCid][harq_pid] = 8; - sched_ctl->tbcnt[1 - pCCid][harq_pid] = 0; - } else if (((pdu[0] >= 2) && (pdu[1] == 1)) - || ((pdu[0] == 1) && (pdu[1] >= 2))) { // one ACK - sched_ctl->round[1 - pCCid][harq_pid]++; - sched_ctl->tbcnt[1 - pCCid][harq_pid] = 1; - if (sched_ctl->round[1 - pCCid][harq_pid] == 4) { - sched_ctl->round[1 - pCCid][harq_pid] = 8; - sched_ctl->tbcnt[1 - pCCid][harq_pid] = 0; + + if (pdu[2] == 1) + sched_ctl->round[1 - pCCid][harq_pid] = 8; + else { + sched_ctl->round[1 - pCCid][harq_pid]++; + + if (sched_ctl->round[1 - pCCid][harq_pid] == 4) { + sched_ctl->round[1 - pCCid][harq_pid] = 8; + } } - } else { // both NAK/DTX - sched_ctl->round[1 - pCCid][harq_pid]++; - if (sched_ctl->round[1 - pCCid][harq_pid] == 4) { - sched_ctl->round[1 - pCCid][harq_pid] = 8; - sched_ctl->tbcnt[1 - pCCid][harq_pid] = 0; + } // A=3 primary cell has 2 TBs + else if ((num_ack_nak == 3) + && (sched_ctl->round[1 - pCCid][harq_pid] < 8) + && (sched_ctl->round[pCCid][harq_pid] < 8) + && (sched_ctl->tbcnt[1 - pCCid][harq_pid] == 2) + && (sched_ctl->tbcnt[pCCid][harq_pid] == 1)) { + AssertFatal(pdu[0] <= 3, "pdu[0] %d is not ACK/NAK/DTX\n", + pdu[0]); + AssertFatal(pdu[1] <= 3, "pdu[1] %d is not ACK/NAK/DTX\n", + pdu[1]); + AssertFatal(pdu[2] <= 3, "pdu[2] %d is not ACK/NAK/DTX\n", + pdu[2]); + AssertFatal(sched_ctl->tbcnt[1 - pCCid][harq_pid] == 2, + "sched_ctl->tbcnt[%d][%d] != 2 for UE %d/%x\n", + 1 - pCCid, harq_pid, UE_id, rnti); + AssertFatal(sched_ctl->tbcnt[pCCid][harq_pid] == 1, + "sched_ctl->tbcnt[%d][%d] != 1 for UE %d/%x\n", + pCCid, harq_pid, UE_id, rnti); + + if ((pdu[0] == 1) && (pdu[1] == 1)) { // both ACK + sched_ctl->round[1 - pCCid][harq_pid] = 8; + sched_ctl->tbcnt[1 - pCCid][harq_pid] = 0; + } else if (((pdu[0] >= 2) && (pdu[1] == 1)) + || ((pdu[0] == 1) && (pdu[1] >= 2))) { // one ACK + sched_ctl->round[1 - pCCid][harq_pid]++; + sched_ctl->tbcnt[1 - pCCid][harq_pid] = 1; + + if (sched_ctl->round[1 - pCCid][harq_pid] == 4) { + sched_ctl->round[1 - pCCid][harq_pid] = 8; + sched_ctl->tbcnt[1 - pCCid][harq_pid] = 0; + } + } else { // both NAK/DTX + sched_ctl->round[1 - pCCid][harq_pid]++; + + if (sched_ctl->round[1 - pCCid][harq_pid] == 4) { + sched_ctl->round[1 - pCCid][harq_pid] = 8; + sched_ctl->tbcnt[1 - pCCid][harq_pid] = 0; + } } - } - if (pdu[2] == 1) - sched_ctl->round[pCCid][harq_pid] = 8; - else { - sched_ctl->round[pCCid][harq_pid]++; - if (sched_ctl->round[pCCid][harq_pid] == 4) { - sched_ctl->round[pCCid][harq_pid] = 8; + if (pdu[2] == 1) + sched_ctl->round[pCCid][harq_pid] = 8; + else { + sched_ctl->round[pCCid][harq_pid]++; + + if (sched_ctl->round[pCCid][harq_pid] == 4) { + sched_ctl->round[pCCid][harq_pid] = 8; + } } - } - } // A=3 secondary cell has 2 TBs + } // A=3 secondary cell has 2 TBs + #if MAX_NUM_CCs>1 - else if ((num_ack_nak == 4) - && (sched_ctl->round[0][harq_pid] < 8) - && (sched_ctl->round[1][harq_pid] < 8) - && (sched_ctl->tbcnt[1 - pCCid][harq_pid] == 2) - && (sched_ctl->tbcnt[pCCid][harq_pid] == 2)) { - AssertFatal(pdu[0] <= 3, "pdu[0] %d is not ACK/NAK/DTX\n", - pdu[0]); - AssertFatal(pdu[1] <= 3, "pdu[1] %d is not ACK/NAK/DTX\n", - pdu[1]); - AssertFatal(pdu[2] <= 3, "pdu[2] %d is not ACK/NAK/DTX\n", - pdu[2]); - AssertFatal(pdu[3] <= 3, "pdu[3] %d is not ACK/NAK/DTX\n", - pdu[3]); - AssertFatal(sched_ctl->tbcnt[0][harq_pid] == 2, - "sched_ctl->tbcnt[0][%d] != 2 for UE %d/%x\n", - harq_pid, UE_id, rnti); - AssertFatal(sched_ctl->tbcnt[1][harq_pid] == 2, - "sched_ctl->tbcnt[1][%d] != 2 for UE %d/%x\n", - harq_pid, UE_id, rnti); - if ((pdu[0] == 1) && (pdu[1] == 1)) { // both ACK - sched_ctl->round[0][harq_pid] = 8; - sched_ctl->tbcnt[0][harq_pid] = 0; - } else if (((pdu[0] >= 2) && (pdu[1] == 1)) - || ((pdu[0] == 1) && (pdu[1] >= 2))) { // one ACK - sched_ctl->round[0][harq_pid]++; - sched_ctl->tbcnt[0][harq_pid] = 1; - if (sched_ctl->round[0][harq_pid] == 4) { - sched_ctl->round[0][harq_pid] = 8; - sched_ctl->tbcnt[0][harq_pid] = 0; - } - } else { // both NAK/DTX - sched_ctl->round[0][harq_pid]++; - if (sched_ctl->round[0][harq_pid] == 4) { - sched_ctl->round[0][harq_pid] = 8; - sched_ctl->tbcnt[0][harq_pid] = 0; + else if ((num_ack_nak == 4) + && (sched_ctl->round[0][harq_pid] < 8) + && (sched_ctl->round[1][harq_pid] < 8) + && (sched_ctl->tbcnt[1 - pCCid][harq_pid] == 2) + && (sched_ctl->tbcnt[pCCid][harq_pid] == 2)) { + AssertFatal(pdu[0] <= 3, "pdu[0] %d is not ACK/NAK/DTX\n", + pdu[0]); + AssertFatal(pdu[1] <= 3, "pdu[1] %d is not ACK/NAK/DTX\n", + pdu[1]); + AssertFatal(pdu[2] <= 3, "pdu[2] %d is not ACK/NAK/DTX\n", + pdu[2]); + AssertFatal(pdu[3] <= 3, "pdu[3] %d is not ACK/NAK/DTX\n", + pdu[3]); + AssertFatal(sched_ctl->tbcnt[0][harq_pid] == 2, + "sched_ctl->tbcnt[0][%d] != 2 for UE %d/%x\n", + harq_pid, UE_id, rnti); + AssertFatal(sched_ctl->tbcnt[1][harq_pid] == 2, + "sched_ctl->tbcnt[1][%d] != 2 for UE %d/%x\n", + harq_pid, UE_id, rnti); + + if ((pdu[0] == 1) && (pdu[1] == 1)) { // both ACK + sched_ctl->round[0][harq_pid] = 8; + sched_ctl->tbcnt[0][harq_pid] = 0; + } else if (((pdu[0] >= 2) && (pdu[1] == 1)) + || ((pdu[0] == 1) && (pdu[1] >= 2))) { // one ACK + sched_ctl->round[0][harq_pid]++; + sched_ctl->tbcnt[0][harq_pid] = 1; + + if (sched_ctl->round[0][harq_pid] == 4) { + sched_ctl->round[0][harq_pid] = 8; + sched_ctl->tbcnt[0][harq_pid] = 0; + } + } else { // both NAK/DTX + sched_ctl->round[0][harq_pid]++; + + if (sched_ctl->round[0][harq_pid] == 4) { + sched_ctl->round[0][harq_pid] = 8; + sched_ctl->tbcnt[0][harq_pid] = 0; + } } - } - if ((pdu[2] == 1) && (pdu[3] == 1)) { // both ACK - sched_ctl->round[1][harq_pid] = 8; - sched_ctl->tbcnt[1][harq_pid] = 0; - } else if (((pdu[2] >= 2) && (pdu[3] == 1)) - || ((pdu[2] == 1) && (pdu[3] >= 2))) { // one ACK - sched_ctl->round[1][harq_pid]++; - sched_ctl->tbcnt[1][harq_pid] = 1; - if (sched_ctl->round[1][harq_pid] == 4) { - sched_ctl->round[1][harq_pid] = 8; - sched_ctl->tbcnt[1][harq_pid] = 0; + if ((pdu[2] == 1) && (pdu[3] == 1)) { // both ACK + sched_ctl->round[1][harq_pid] = 8; + sched_ctl->tbcnt[1][harq_pid] = 0; + } else if (((pdu[2] >= 2) && (pdu[3] == 1)) + || ((pdu[2] == 1) && (pdu[3] >= 2))) { // one ACK + sched_ctl->round[1][harq_pid]++; + sched_ctl->tbcnt[1][harq_pid] = 1; + + if (sched_ctl->round[1][harq_pid] == 4) { + sched_ctl->round[1][harq_pid] = 8; + sched_ctl->tbcnt[1][harq_pid] = 0; + } + } else { // both NAK/DTX + sched_ctl->round[1][harq_pid]++; + + if (sched_ctl->round[1][harq_pid] == 4) { + sched_ctl->round[1][harq_pid] = 8; + sched_ctl->tbcnt[1][harq_pid] = 0; + } } - } else { // both NAK/DTX - sched_ctl->round[1][harq_pid]++; - if (sched_ctl->round[1][harq_pid] == 4) { - sched_ctl->round[1][harq_pid] = 8; - sched_ctl->tbcnt[1][harq_pid] = 0; + } // A=4 both serving cells have 2 TBs + +#endif + break; + + case 2: // Format 3 + AssertFatal(numCC > 2, + "Should not receive harq indication with FDD format 3 with %d < 3 active CCs\n", + numCC); + + for (i = 0, j = 0; i < numCC; i++) { + if ((sched_ctl->round[i][harq_pid] < 8)) { + if (tmode[i] == 1 || tmode[i] == 2 || tmode[0] == 5 + || tmode[0] == 6 || tmode[0] == 7) { + if (pdu[j] == 1) { + sched_ctl->round[i][harq_pid] = 8; + sched_ctl->tbcnt[i][harq_pid] = 0; + } else if (pdu[j] == 2) { + sched_ctl->round[i][harq_pid]++; + + if (sched_ctl->round[i][harq_pid] == 4) { + sched_ctl->round[i][harq_pid] = 8; + sched_ctl->tbcnt[i][harq_pid] = 0; + } + } else + AssertFatal(1 == 0, + "Illegal harq_ack value for CC %d harq_pid %d (%d) UE %d/%x\n", + i, harq_pid, pdu[j], UE_id, rnti); + + j++; + } else if (spatial_bundling == 0) { + if ((sched_ctl->tbcnt[i][harq_pid] == 2) + && (pdu[j] == 1) && (pdu[j + 1] == 1)) { + sched_ctl->round[i][harq_pid] = 8; + sched_ctl->tbcnt[i][harq_pid] = 0; + } else if ((sched_ctl->tbcnt[i][harq_pid] == 2) + && (pdu[j] == 1) && (pdu[j + 1] == 2)) { + sched_ctl->round[i][harq_pid]++; + sched_ctl->tbcnt[i][harq_pid] = 1; + + if (sched_ctl->round[i][harq_pid] == 4) { + sched_ctl->round[i][harq_pid] = 8; + sched_ctl->tbcnt[i][harq_pid] = 0; + } + } else if ((sched_ctl->tbcnt[i][harq_pid] == 2) + && (pdu[j] == 2) && (pdu[j + 1] == 1)) { + sched_ctl->round[i][harq_pid]++; + sched_ctl->tbcnt[i][harq_pid] = 1; + + if (sched_ctl->round[i][harq_pid] == 4) { + sched_ctl->round[i][harq_pid] = 8; + sched_ctl->tbcnt[i][harq_pid] = 0; + } + } else if ((sched_ctl->tbcnt[i][harq_pid] == 2) + && (pdu[j] == 2) && (pdu[j + 1] == 2)) { + sched_ctl->round[i][harq_pid]++; + + if (sched_ctl->round[i][harq_pid] == 4) { + sched_ctl->round[i][harq_pid] = 8; + sched_ctl->tbcnt[i][harq_pid] = 0; + } + } else + AssertFatal(1 == 0, + "Illegal combination for CC %d harq_pid %d (%d,%d,%d) UE %d/%x\n", + i, harq_pid, + sched_ctl->tbcnt[i][harq_pid], + pdu[j], pdu[j + 1], UE_id, rnti); + + j += 2; + } else if (spatial_bundling == 1) { + if (pdu[j] == 1) { + sched_ctl->round[i][harq_pid] = 8; + sched_ctl->tbcnt[i][harq_pid] = 0; + } else if (pdu[j] == 2) { + sched_ctl->round[i][harq_pid]++; + + if (sched_ctl->round[i][harq_pid] == 4) { + sched_ctl->round[i][harq_pid] = 8; + sched_ctl->tbcnt[i][harq_pid] = 0; + } + } else + AssertFatal(1 == 0, + "Illegal hack_nak value %d for CC %d harq_pid %d UE %d/%x\n", + pdu[j], i, harq_pid, UE_id, rnti); + + j++; + } else + AssertFatal(1 == 0, + "Illegal value for spatial_bundling %d\n", + spatial_bundling); } } - } // A=4 both serving cells have 2 TBs -#endif - break; - case 2: // Format 3 - AssertFatal(numCC > 2, - "Should not receive harq indication with FDD format 3 with %d < 3 active CCs\n", - numCC); - for (i = 0, j = 0; i < numCC; i++) { - if ((sched_ctl->round[i][harq_pid] < 8)) { - if (tmode[i] == 1 || tmode[i] == 2 || tmode[0] == 5 - || tmode[0] == 6 || tmode[0] == 7) { - if (pdu[j] == 1) { - sched_ctl->round[i][harq_pid] = 8; - sched_ctl->tbcnt[i][harq_pid] = 0; - } else if (pdu[j] == 2) { - sched_ctl->round[i][harq_pid]++; - if (sched_ctl->round[i][harq_pid] == 4) { - sched_ctl->round[i][harq_pid] = 8; - sched_ctl->tbcnt[i][harq_pid] = 0; - } - } - else - AssertFatal(1 == 0, - "Illegal harq_ack value for CC %d harq_pid %d (%d) UE %d/%x\n", - i, harq_pid, pdu[j], UE_id, rnti); - j++; - } else if (spatial_bundling == 0) { - if ((sched_ctl->tbcnt[i][harq_pid] == 2) - && (pdu[j] == 1) && (pdu[j + 1] == 1)) { - sched_ctl->round[i][harq_pid] = 8; - sched_ctl->tbcnt[i][harq_pid] = 0; - } else if ((sched_ctl->tbcnt[i][harq_pid] == 2) - && (pdu[j] == 1) && (pdu[j + 1] == 2)) { - sched_ctl->round[i][harq_pid]++; - sched_ctl->tbcnt[i][harq_pid] = 1; - if (sched_ctl->round[i][harq_pid] == 4) { - sched_ctl->round[i][harq_pid] = 8; - sched_ctl->tbcnt[i][harq_pid] = 0; - } - } else if ((sched_ctl->tbcnt[i][harq_pid] == 2) - && (pdu[j] == 2) && (pdu[j + 1] == 1)) { - sched_ctl->round[i][harq_pid]++; - sched_ctl->tbcnt[i][harq_pid] = 1; - if (sched_ctl->round[i][harq_pid] == 4) { - sched_ctl->round[i][harq_pid] = 8; - sched_ctl->tbcnt[i][harq_pid] = 0; - } - } else if ((sched_ctl->tbcnt[i][harq_pid] == 2) - && (pdu[j] == 2) && (pdu[j + 1] == 2)) { - sched_ctl->round[i][harq_pid]++; - if (sched_ctl->round[i][harq_pid] == 4) { - sched_ctl->round[i][harq_pid] = 8; - sched_ctl->tbcnt[i][harq_pid] = 0; - } - } else - AssertFatal(1 == 0, - "Illegal combination for CC %d harq_pid %d (%d,%d,%d) UE %d/%x\n", - i, harq_pid, - sched_ctl->tbcnt[i][harq_pid], - pdu[j], pdu[j + 1], UE_id, rnti); - j += 2; - } else if (spatial_bundling == 1) { - if (pdu[j] == 1) { - sched_ctl->round[i][harq_pid] = 8; - sched_ctl->tbcnt[i][harq_pid] = 0; - } else if (pdu[j] == 2) { - sched_ctl->round[i][harq_pid]++; - if (sched_ctl->round[i][harq_pid] == 4) { - sched_ctl->round[i][harq_pid] = 8; - sched_ctl->tbcnt[i][harq_pid] = 0; - } - } else - AssertFatal(1 == 0, - "Illegal hack_nak value %d for CC %d harq_pid %d UE %d/%x\n", - pdu[j], i, harq_pid, UE_id, rnti); - j++; - } else - AssertFatal(1 == 0, - "Illegal value for spatial_bundling %d\n", - spatial_bundling); - } - } - break; - case 3: // Format 4 - AssertFatal(1 == 0, - "Should not receive harq indication with Format 4\n"); - break; - case 4: // Format 5 - AssertFatal(1 == 0, - "Should not receive harq indication with Format 5\n"); - break; + + break; + + case 3: // Format 4 + AssertFatal(1 == 0, + "Should not receive harq indication with Format 4\n"); + break; + + case 4: // Format 5 + AssertFatal(1 == 0, + "Should not receive harq indication with Format 5\n"); + break; } } } void extract_pucch_csi(module_id_t mod_idP, int CC_idP, int UE_id, - frame_t frameP, sub_frame_t subframeP, - uint8_t * pdu, uint8_t length) -{ + frame_t frameP, sub_frame_t subframeP, + uint8_t *pdu, uint8_t length) { UE_list_t *UE_list = &RC.mac[mod_idP]->UE_list; UE_sched_ctrl *sched_ctl = &UE_list->UE_sched_ctrl[UE_id]; COMMON_channels_t *cc = &RC.mac[mod_idP]->common_channels[CC_idP]; @@ -4030,25 +4096,21 @@ extract_pucch_csi(module_id_t mod_idP, int CC_idP, int UE_id, uint8_t Ltab[6] = { 0, 2, 4, 4, 4, 4 }; uint8_t Jtab[6] = { 0, 2, 2, 3, 4, 4 }; int feedback_cnt; - AssertFatal(UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated != NULL, - "physicalConfigDedicated is null for UE %d\n", UE_id); + "physicalConfigDedicated is null for UE %d\n", UE_id); AssertFatal(UE_list-> - UE_template[CC_idP][UE_id].physicalConfigDedicated->cqi_ReportConfig != NULL, - "cqi_ReportConfig is null for UE %d\n", UE_id); + UE_template[CC_idP][UE_id].physicalConfigDedicated->cqi_ReportConfig != NULL, + "cqi_ReportConfig is null for UE %d\n", UE_id); AssertFatal((cqi_ReportPeriodic = UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated->cqi_ReportConfig->cqi_ReportPeriodic) != NULL, - "cqi_ReportPeriodic is null for UE %d\n", UE_id); - + "cqi_ReportPeriodic is null for UE %d\n", UE_id); // determine feedback mode AssertFatal(cqi_ReportPeriodic->present != LTE_CQI_ReportPeriodic_PR_NOTHING, - "cqi_ReportPeriodic->present == LTE_CQI_ReportPeriodic_PR_NOTHING!\n"); + "cqi_ReportPeriodic->present == LTE_CQI_ReportPeriodic_PR_NOTHING!\n"); AssertFatal(cqi_ReportPeriodic->choice.setup.cqi_FormatIndicatorPeriodic.present != LTE_CQI_ReportPeriodic__setup__cqi_FormatIndicatorPeriodic_PR_NOTHING, - "cqi_ReportPeriodic->cqi_FormatIndicatorPeriodic.choice.setup.present == LTE_CQI_ReportPeriodic__setup__cqi_FormatIndicatorPeriodic_PR_NOTHING!\n"); - + "cqi_ReportPeriodic->cqi_FormatIndicatorPeriodic.choice.setup.present == LTE_CQI_ReportPeriodic__setup__cqi_FormatIndicatorPeriodic_PR_NOTHING!\n"); uint16_t Npd, N_OFFSET_CQI; int H, K, bandwidth_part, L, Lmask; int ri = sched_ctl->periodic_ri_received[CC_idP]; - get_csi_params(cc, cqi_ReportPeriodic, &Npd, &N_OFFSET_CQI, &H); K = (H - 1) / Jtab[cc->mib->message.dl_Bandwidth]; L = Ltab[cc->mib->message.dl_Bandwidth]; @@ -4061,30 +4123,31 @@ extract_pucch_csi(module_id_t mod_idP, int CC_idP, int UE_id, bandwidth_part = 0; switch (get_tmode(mod_idP, CC_idP, UE_id)) { - case 1: - case 2: - case 3: - case 7: - no_pmi = 1; - break; - case 4: - case 5: - case 6: - no_pmi = 0; - break; - default: - // note: need to check TM8-10 without PMI/RI or with 1 antenna port (see Section 5.2.3.3.1 from 36.213) - no_pmi = 0; + case 1: + case 2: + case 3: + case 7: + no_pmi = 1; + break; + + case 4: + case 5: + case 6: + no_pmi = 0; + break; + + default: + // note: need to check TM8-10 without PMI/RI or with 1 antenna port (see Section 5.2.3.3.1 from 36.213) + no_pmi = 0; } if ((cqi_ReportPeriodic->choice.setup.cqi_FormatIndicatorPeriodic.present == LTE_CQI_ReportPeriodic__setup__cqi_FormatIndicatorPeriodic_PR_widebandCQI) || (feedback_cnt == 0)) { // Note: This implements only Tables: 5.3.3.1-1,5.3.3.1-1A and 5.3.3.1-2 from 36.213 (1,2,4 antenna ports Wideband CQI/PMI) - - if (no_pmi == 1) { // get spatial_diffcqi if needed + if (no_pmi == 1) { // get spatial_diffcqi if needed sched_ctl->periodic_wideband_cqi[CC_idP] = pdu[0] & 0xF; sched_ctl->periodic_wideband_spatial_diffcqi[CC_idP] = - (pdu[0] >> 4) & 7; + (pdu[0] >> 4) & 7; } else if ((cc->p_eNB == 2) && (ri == 1)) { // p=2 Rank 1 wideband CQI/PMI 6 bits sched_ctl->periodic_wideband_cqi[CC_idP] = pdu[0] & 0xF; @@ -4093,43 +4156,41 @@ extract_pucch_csi(module_id_t mod_idP, int CC_idP, int UE_id, // p=2 Rank 2 wideband CQI/PMI 8 bits sched_ctl->periodic_wideband_cqi[CC_idP] = pdu[0] & 0xF; sched_ctl->periodic_wideband_spatial_diffcqi[CC_idP] = - (pdu[0] >> 4) & 7; + (pdu[0] >> 4) & 7; sched_ctl->periodic_wideband_pmi[CC_idP] = (pdu[0] >> 7) & 1; } else if ((cc->p_eNB == 4) && (ri == 1)) { // p=4 Rank 1 wideband CQI/PMI 8 bits sched_ctl->periodic_wideband_cqi[CC_idP] = pdu[0] & 0xF; sched_ctl->periodic_wideband_pmi[CC_idP] = - (pdu[0] >> 4) & 0x0F; + (pdu[0] >> 4) & 0x0F; } else if ((cc->p_eNB == 4) && (ri > 1)) { // p=4 Rank 2 wideband CQI/PMI 11 bits sched_ctl->periodic_wideband_cqi[CC_idP] = pdu[0] & 0xF; sched_ctl->periodic_wideband_spatial_diffcqi[CC_idP] = - (pdu[0] >> 4) & 7; + (pdu[0] >> 4) & 7; sched_ctl->periodic_wideband_pmi[CC_idP] = (pdu[0] >> 7) & 0xF; } else AssertFatal(1 == 0, - "illegal combination p %d, ri %d, no_pmi %d\n", - cc->p_eNB, ri, no_pmi); - } else if (cqi_ReportPeriodic->choice.setup.cqi_FormatIndicatorPeriodic.present == LTE_CQI_ReportPeriodic__setup__cqi_FormatIndicatorPeriodic_PR_subbandCQI) - { - // This is Table 5.2.3.3.2-2 for 36.213 - if (ri == 1) { - //4+Ltab[cc->mib->message.dl_Bandwidth] bits - sched_ctl->periodic_subband_cqi[CC_idP][(bandwidth_part * L) +((pdu[0] >> 4) & Lmask)] = pdu[0] & 0xF; - } else if (ri > 1) { - //7+Ltab[cc->mib->message.dl_Bandwidth] bits; - sched_ctl->periodic_subband_spatial_diffcqi[CC_idP][(bandwidth_part * L) + ((pdu[0] >> 7) & Lmask)] = (pdu[0] >> 4) & 7; - sched_ctl->periodic_subband_cqi[CC_idP][(bandwidth_part * L) + ((pdu[0] >> 7) & Lmask)] = - pdu[0] & 0xF; - } + "illegal combination p %d, ri %d, no_pmi %d\n", + cc->p_eNB, ri, no_pmi); + } else if (cqi_ReportPeriodic->choice.setup.cqi_FormatIndicatorPeriodic.present == LTE_CQI_ReportPeriodic__setup__cqi_FormatIndicatorPeriodic_PR_subbandCQI) { + // This is Table 5.2.3.3.2-2 for 36.213 + if (ri == 1) { + //4+Ltab[cc->mib->message.dl_Bandwidth] bits + sched_ctl->periodic_subband_cqi[CC_idP][(bandwidth_part * L) +((pdu[0] >> 4) & Lmask)] = pdu[0] & 0xF; + } else if (ri > 1) { + //7+Ltab[cc->mib->message.dl_Bandwidth] bits; + sched_ctl->periodic_subband_spatial_diffcqi[CC_idP][(bandwidth_part * L) + ((pdu[0] >> 7) & Lmask)] = (pdu[0] >> 4) & 7; + sched_ctl->periodic_subband_cqi[CC_idP][(bandwidth_part * L) + ((pdu[0] >> 7) & Lmask)] = + pdu[0] & 0xF; } + } } void extract_pusch_csi(module_id_t mod_idP, int CC_idP, int UE_id, - frame_t frameP, sub_frame_t subframeP, - uint8_t * pdu, uint8_t length) -{ + frame_t frameP, sub_frame_t subframeP, + uint8_t *pdu, uint8_t length) { UE_list_t *UE_list = &RC.mac[mod_idP]->UE_list; COMMON_channels_t *cc = &RC.mac[mod_idP]->common_channels[CC_idP]; UE_sched_ctrl *sched_ctl = &UE_list->UE_sched_ctrl[UE_id]; @@ -4142,14 +4203,12 @@ extract_pusch_csi(module_id_t mod_idP, int CC_idP, int UE_id, uint64_t p = *(uint64_t *) pdu; int curbyte, curbit; LTE_CQI_ReportModeAperiodic_t *cqi_ReportModeAperiodic; - AssertFatal(UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated != NULL, - "physicalConfigDedicated is null for UE %d\n", UE_id); + "physicalConfigDedicated is null for UE %d\n", UE_id); AssertFatal(UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated->cqi_ReportConfig != NULL, - "cqi_ReportConfig is null for UE %d\n", UE_id); + "cqi_ReportConfig is null for UE %d\n", UE_id); AssertFatal((cqi_ReportModeAperiodic = UE_list->UE_template[CC_idP][UE_id].physicalConfigDedicated->cqi_ReportConfig->cqi_ReportModeAperiodic) != NULL, - "cqi_ReportModeAperiodic is null for UE %d\n", UE_id); - + "cqi_ReportModeAperiodic is null for UE %d\n", UE_id); int N = Ntab[cc->mib->message.dl_Bandwidth]; int tmode = get_tmode(mod_idP, CC_idP, UE_id); int ri = sched_ctl->aperiodic_ri_received[CC_idP]; @@ -4158,277 +4217,309 @@ extract_pusch_csi(module_id_t mod_idP, int CC_idP, int UE_id, int m; switch (*cqi_ReportModeAperiodic) { - case LTE_CQI_ReportModeAperiodic_rm12: - AssertFatal(0 == 1, "to be fixed, don't use p but pdu directly\n"); - // wideband multiple PMI (TM4/6), Table 5.2.2.6.1-1 (for TM4/6) - AssertFatal(tmode == 4 || tmode == 6 || tmode == 8 || tmode == 9 || tmode == 10, - "Illegal transmission mode %d for CQI_ReportModeAperiodic_rm12\n", - tmode); - if (tmode <= 6) { //Table 5.2.2.6.1-1 36.213 - if ((ri == 1) && (cc->p_eNB == 2)) { - sched_ctl->aperiodic_wideband_cqi0[CC_idP] = (uint8_t) (p & 0x0F); - p >>= 4; - for (i = 0; i < N; i++) { - sched_ctl->aperiodic_subband_pmi[CC_idP][i] = (uint8_t) (p & 0x03); - p >>= 2; - } - } - if ((ri == 2) && (cc->p_eNB == 2)) { - sched_ctl->aperiodic_wideband_cqi0[CC_idP] = (uint8_t) (p & 0x0F); - p >>= 4; - sched_ctl->aperiodic_wideband_cqi1[CC_idP] = (uint8_t) (p & 0x0F); - p >>= 4; - for (i = 0; i < N; i++) { - sched_ctl->aperiodic_subband_pmi[CC_idP][i] = (uint8_t) (p & 0x01); - p >>= 1; - } - } - if ((ri == 1) && (cc->p_eNB == 4)) { - sched_ctl->aperiodic_wideband_cqi0[CC_idP] = (uint8_t) (p & 0x0F); - p >>= 4; - for (i = 0; i < N; i++) { - sched_ctl->aperiodic_subband_pmi[CC_idP][i] = (uint8_t) (p & 0x03); - p >>= 4; - } - } - if ((ri == 2) && (cc->p_eNB == 4)) { - sched_ctl->aperiodic_wideband_cqi0[CC_idP] = (uint8_t) (p & 0x0F); - p >>= 4; - sched_ctl->aperiodic_wideband_cqi1[CC_idP] = (uint8_t) (p & 0x0F); - p >>= 4; - for (i = 0; i < N; i++) { - sched_ctl->aperiodic_subband_pmi[CC_idP][i] = (uint8_t) (p & 0x01); - p >>= 4; - } + case LTE_CQI_ReportModeAperiodic_rm12: + AssertFatal(0 == 1, "to be fixed, don't use p but pdu directly\n"); + // wideband multiple PMI (TM4/6), Table 5.2.2.6.1-1 (for TM4/6) + AssertFatal(tmode == 4 || tmode == 6 || tmode == 8 || tmode == 9 || tmode == 10, + "Illegal transmission mode %d for CQI_ReportModeAperiodic_rm12\n", + tmode); + + if (tmode <= 6) { //Table 5.2.2.6.1-1 36.213 + if ((ri == 1) && (cc->p_eNB == 2)) { + sched_ctl->aperiodic_wideband_cqi0[CC_idP] = (uint8_t) (p & 0x0F); + p >>= 4; + + for (i = 0; i < N; i++) { + sched_ctl->aperiodic_subband_pmi[CC_idP][i] = (uint8_t) (p & 0x03); + p >>= 2; + } + } + + if ((ri == 2) && (cc->p_eNB == 2)) { + sched_ctl->aperiodic_wideband_cqi0[CC_idP] = (uint8_t) (p & 0x0F); + p >>= 4; + sched_ctl->aperiodic_wideband_cqi1[CC_idP] = (uint8_t) (p & 0x0F); + p >>= 4; + + for (i = 0; i < N; i++) { + sched_ctl->aperiodic_subband_pmi[CC_idP][i] = (uint8_t) (p & 0x01); + p >>= 1; + } + } + + if ((ri == 1) && (cc->p_eNB == 4)) { + sched_ctl->aperiodic_wideband_cqi0[CC_idP] = (uint8_t) (p & 0x0F); + p >>= 4; + + for (i = 0; i < N; i++) { + sched_ctl->aperiodic_subband_pmi[CC_idP][i] = (uint8_t) (p & 0x03); + p >>= 4; + } + } + + if ((ri == 2) && (cc->p_eNB == 4)) { + sched_ctl->aperiodic_wideband_cqi0[CC_idP] = (uint8_t) (p & 0x0F); + p >>= 4; + sched_ctl->aperiodic_wideband_cqi1[CC_idP] = (uint8_t) (p & 0x0F); + p >>= 4; + + for (i = 0; i < N; i++) { + sched_ctl->aperiodic_subband_pmi[CC_idP][i] = (uint8_t) (p & 0x01); + p >>= 4; + } + } + } // if (tmode <= 6) { //Table 5.2.2.6.1-1 36.213 + else { + AssertFatal(1 == 0, "support for TM 8-10 to be done\n"); } - } // if (tmode <= 6) { //Table 5.2.2.6.1-1 36.213 - else { - AssertFatal(1 == 0, "support for TM 8-10 to be done\n"); - } - break; - case LTE_CQI_ReportModeAperiodic_rm20: - AssertFatal(0 == 1, "to be fixed, don't use p but pdu directly\n"); - // UE-selected subband CQI no PMI (TM1/2/3/7) , Table 5.2.2.6.3-1 from 36.213 - AssertFatal(tmode == 1 || tmode == 2 || tmode == 3 - || tmode == 7, - "Illegal transmission mode %d for CQI_ReportModeAperiodic_rm20\n", - tmode); - - sched_ctl->aperiodic_wideband_cqi0[CC_idP] = (uint8_t) (p & 0x0F); - p >>= 4; - diffcqi0 = (uint8_t) (p & 0x03); - p >>= 2; - r = (uint8_t) (p & ((1 >> Ltab_uesel[bw]) - 1)); - reverse_index(Ntab_uesel[bw], Mtab_uesel[bw], r, v); - for (m = 0; m < Mtab_uesel[bw]; m++) - sched_ctl->aperiodic_subband_diffcqi0[CC_idP][v[m]] = diffcqi0; - break; - case LTE_CQI_ReportModeAperiodic_rm22: - AssertFatal(0 == 1, "to be fixed, don't use p but pdu directly\n"); - // UE-selected subband CQI multiple PMI (TM4/6) Table 5.2.2.6.3-2 from 36.213 - - AssertFatal(tmode == 4 || tmode == 6 || tmode == 8 || tmode == 9 - || tmode == 10, - "Illegal transmission mode %d for CQI_ReportModeAperiodic_rm22\n", - tmode); - - sched_ctl->aperiodic_wideband_cqi0[CC_idP] = (uint8_t) (p & 0x0F); - p >>= 4; - diffcqi0 = (uint8_t) (p & 0x03); - p >>= 2; - - if (ri > 1) { - sched_ctl->aperiodic_wideband_cqi1[CC_idP] = - (uint8_t) (p & 0x0F); + break; + + case LTE_CQI_ReportModeAperiodic_rm20: + AssertFatal(0 == 1, "to be fixed, don't use p but pdu directly\n"); + // UE-selected subband CQI no PMI (TM1/2/3/7) , Table 5.2.2.6.3-1 from 36.213 + AssertFatal(tmode == 1 || tmode == 2 || tmode == 3 + || tmode == 7, + "Illegal transmission mode %d for CQI_ReportModeAperiodic_rm20\n", + tmode); + sched_ctl->aperiodic_wideband_cqi0[CC_idP] = (uint8_t) (p & 0x0F); p >>= 4; - diffcqi1 = (uint8_t) (p & 0x03); - p >>= 2; - } - r = (uint8_t) (p & ((1 >> Ltab_uesel[bw]) - 1)); - p >>= Ltab_uesel[bw]; - reverse_index(Ntab_uesel[bw], Mtab_uesel[bw], r, v); - if ((ri == 1) && (cc->p_eNB == 2)) { - pmi_uesel = p & 0x3; + diffcqi0 = (uint8_t) (p & 0x03); p >>= 2; - sched_ctl->aperiodic_wideband_pmi[CC_idP] = p & 0x3; - } else if ((ri == 2) && (cc->p_eNB == 2)) { - pmi_uesel = p & 0x1; - p >>= 1; - sched_ctl->aperiodic_wideband_pmi[CC_idP] = p & 0x1; - } else if (cc->p_eNB == 4) { - pmi_uesel = p & 0x0F; + r = (uint8_t) (p & ((1 >> Ltab_uesel[bw]) - 1)); + reverse_index(Ntab_uesel[bw], Mtab_uesel[bw], r, v); + + for (m = 0; m < Mtab_uesel[bw]; m++) + sched_ctl->aperiodic_subband_diffcqi0[CC_idP][v[m]] = diffcqi0; + + break; + + case LTE_CQI_ReportModeAperiodic_rm22: + AssertFatal(0 == 1, "to be fixed, don't use p but pdu directly\n"); + // UE-selected subband CQI multiple PMI (TM4/6) Table 5.2.2.6.3-2 from 36.213 + AssertFatal(tmode == 4 || tmode == 6 || tmode == 8 || tmode == 9 + || tmode == 10, + "Illegal transmission mode %d for CQI_ReportModeAperiodic_rm22\n", + tmode); + sched_ctl->aperiodic_wideband_cqi0[CC_idP] = (uint8_t) (p & 0x0F); p >>= 4; - sched_ctl->aperiodic_wideband_pmi[CC_idP] = p & 0x0F; - } - for (m = 0; m < Mtab_uesel[bw]; m++) { - sched_ctl->aperiodic_subband_diffcqi0[CC_idP][v[m]] = diffcqi0; - if (ri > 1) - sched_ctl->aperiodic_subband_diffcqi1[CC_idP][v[m]] = - diffcqi1; - sched_ctl->aperiodic_subband_pmi[CC_idP][v[m]] = pmi_uesel; - } - break; - case LTE_CQI_ReportModeAperiodic_rm30: - //subband CQI no PMI (TM1/2/3/7) - AssertFatal(tmode == 1 || tmode == 2 || tmode == 3 - || tmode == 7, - "Illegal transmission mode %d for CQI_ReportModeAperiodic_rm30\n", - tmode); - sched_ctl->aperiodic_wideband_cqi0[CC_idP] = pdu[0] >> 4; - curbyte = 0; - curbit = 3; - for (i = 0; i < N; i++) { - sched_ctl->aperiodic_subband_diffcqi0[CC_idP][i] = - (pdu[curbyte] >> (curbit - 1)) & 0x03; - curbit -= 2; - if (curbit < 0) { - curbit = 7; - curbyte++; + diffcqi0 = (uint8_t) (p & 0x03); + p >>= 2; + + if (ri > 1) { + sched_ctl->aperiodic_wideband_cqi1[CC_idP] = + (uint8_t) (p & 0x0F); + p >>= 4; + diffcqi1 = (uint8_t) (p & 0x03); + p >>= 2; } - } - sched_ctl->dl_cqi[CC_idP] = - sched_ctl->aperiodic_wideband_cqi0[CC_idP]; - break; - case LTE_CQI_ReportModeAperiodic_rm31: - AssertFatal(0 == 1, "to be fixed, don't use p but pdu directly\n"); - //subband CQI single PMI (TM4/5/6) - AssertFatal(tmode == 4 || tmode == 5 || tmode == 6 || tmode == 8 - || tmode == 9 - || tmode == 10, - "Illegal transmission mode %d for CQI_ReportModeAperiodic_rm31\n", - tmode); - - if ((ri == 1) && (cc->p_eNB == 2)) { - sched_ctl->aperiodic_wideband_cqi0[CC_idP] = - (uint8_t) (p & 0x0F); - p >>= 4; - for (i = 0; i < N; i++) { - sched_ctl->aperiodic_subband_diffcqi0[CC_idP][i] = - (uint8_t) (p & 0x03); - p >>= 2; + + r = (uint8_t) (p & ((1 >> Ltab_uesel[bw]) - 1)); + p >>= Ltab_uesel[bw]; + reverse_index(Ntab_uesel[bw], Mtab_uesel[bw], r, v); + + if ((ri == 1) && (cc->p_eNB == 2)) { + pmi_uesel = p & 0x3; + p >>= 2; + sched_ctl->aperiodic_wideband_pmi[CC_idP] = p & 0x3; + } else if ((ri == 2) && (cc->p_eNB == 2)) { + pmi_uesel = p & 0x1; + p >>= 1; + sched_ctl->aperiodic_wideband_pmi[CC_idP] = p & 0x1; + } else if (cc->p_eNB == 4) { + pmi_uesel = p & 0x0F; + p >>= 4; + sched_ctl->aperiodic_wideband_pmi[CC_idP] = p & 0x0F; } - sched_ctl->aperiodic_wideband_pmi[CC_idP] = p & 0x03; - } - if ((ri == 2) && (cc->p_eNB == 2)) { - sched_ctl->aperiodic_wideband_cqi0[CC_idP] = - (uint8_t) (p & 0x0F); - p >>= 4; - for (i = 0; i < N; i++) { - sched_ctl->aperiodic_subband_pmi[CC_idP][i] = - (uint8_t) (p & 0x01); - p >>= 1; + + for (m = 0; m < Mtab_uesel[bw]; m++) { + sched_ctl->aperiodic_subband_diffcqi0[CC_idP][v[m]] = diffcqi0; + + if (ri > 1) + sched_ctl->aperiodic_subband_diffcqi1[CC_idP][v[m]] = + diffcqi1; + + sched_ctl->aperiodic_subband_pmi[CC_idP][v[m]] = pmi_uesel; } - sched_ctl->aperiodic_wideband_cqi1[CC_idP] = - (uint8_t) (p & 0x0F); - p >>= 4; + + break; + + case LTE_CQI_ReportModeAperiodic_rm30: + //subband CQI no PMI (TM1/2/3/7) + AssertFatal(tmode == 1 || tmode == 2 || tmode == 3 + || tmode == 7, + "Illegal transmission mode %d for CQI_ReportModeAperiodic_rm30\n", + tmode); + sched_ctl->aperiodic_wideband_cqi0[CC_idP] = pdu[0] >> 4; + curbyte = 0; + curbit = 3; + for (i = 0; i < N; i++) { - sched_ctl->aperiodic_subband_pmi[CC_idP][i] = - (uint8_t) (p & 0x01); - p >>= 1; + sched_ctl->aperiodic_subband_diffcqi0[CC_idP][i] = + (pdu[curbyte] >> (curbit - 1)) & 0x03; + curbit -= 2; + + if (curbit < 0) { + curbit = 7; + curbyte++; + } } - sched_ctl->aperiodic_wideband_pmi[CC_idP] = p & 0x01; - } - if ((ri == 1) && (cc->p_eNB == 4)) { - sched_ctl->aperiodic_wideband_cqi0[CC_idP] = - (uint8_t) (p & 0x0F); - p >>= 4; - for (i = 0; i < N; i++) { - sched_ctl->aperiodic_subband_diffcqi0[CC_idP][i] = - (uint8_t) (p & 0x03); - p >>= 2; + + sched_ctl->dl_cqi[CC_idP] = + sched_ctl->aperiodic_wideband_cqi0[CC_idP]; + break; + + case LTE_CQI_ReportModeAperiodic_rm31: + AssertFatal(0 == 1, "to be fixed, don't use p but pdu directly\n"); + //subband CQI single PMI (TM4/5/6) + AssertFatal(tmode == 4 || tmode == 5 || tmode == 6 || tmode == 8 + || tmode == 9 + || tmode == 10, + "Illegal transmission mode %d for CQI_ReportModeAperiodic_rm31\n", + tmode); + + if ((ri == 1) && (cc->p_eNB == 2)) { + sched_ctl->aperiodic_wideband_cqi0[CC_idP] = + (uint8_t) (p & 0x0F); + p >>= 4; + + for (i = 0; i < N; i++) { + sched_ctl->aperiodic_subband_diffcqi0[CC_idP][i] = + (uint8_t) (p & 0x03); + p >>= 2; + } + + sched_ctl->aperiodic_wideband_pmi[CC_idP] = p & 0x03; } - sched_ctl->aperiodic_wideband_pmi[CC_idP] = p & 0x0F; - } - if ((ri > 1) && (cc->p_eNB == 4)) { // Note : 64 bits for 20 MHz - sched_ctl->aperiodic_wideband_cqi0[CC_idP] = - (uint8_t) (p & 0x0F); - p >>= 4; - for (i = 0; i < N; i++) { - sched_ctl->aperiodic_subband_pmi[CC_idP][i] = - (uint8_t) (p & 0x01); - p >>= 1; + + if ((ri == 2) && (cc->p_eNB == 2)) { + sched_ctl->aperiodic_wideband_cqi0[CC_idP] = + (uint8_t) (p & 0x0F); + p >>= 4; + + for (i = 0; i < N; i++) { + sched_ctl->aperiodic_subband_pmi[CC_idP][i] = + (uint8_t) (p & 0x01); + p >>= 1; + } + + sched_ctl->aperiodic_wideband_cqi1[CC_idP] = + (uint8_t) (p & 0x0F); + p >>= 4; + + for (i = 0; i < N; i++) { + sched_ctl->aperiodic_subband_pmi[CC_idP][i] = + (uint8_t) (p & 0x01); + p >>= 1; + } + + sched_ctl->aperiodic_wideband_pmi[CC_idP] = p & 0x01; } - sched_ctl->aperiodic_wideband_cqi1[CC_idP] = - (uint8_t) (p & 0x0F); - p >>= 4; - for (i = 0; i < N; i++) { - sched_ctl->aperiodic_subband_pmi[CC_idP][i] = - (uint8_t) (p & 0x01); - p >>= 2; + + if ((ri == 1) && (cc->p_eNB == 4)) { + sched_ctl->aperiodic_wideband_cqi0[CC_idP] = + (uint8_t) (p & 0x0F); + p >>= 4; + + for (i = 0; i < N; i++) { + sched_ctl->aperiodic_subband_diffcqi0[CC_idP][i] = + (uint8_t) (p & 0x03); + p >>= 2; + } + + sched_ctl->aperiodic_wideband_pmi[CC_idP] = p & 0x0F; + } + + if ((ri > 1) && (cc->p_eNB == 4)) { // Note : 64 bits for 20 MHz + sched_ctl->aperiodic_wideband_cqi0[CC_idP] = + (uint8_t) (p & 0x0F); + p >>= 4; + + for (i = 0; i < N; i++) { + sched_ctl->aperiodic_subband_pmi[CC_idP][i] = + (uint8_t) (p & 0x01); + p >>= 1; + } + + sched_ctl->aperiodic_wideband_cqi1[CC_idP] = + (uint8_t) (p & 0x0F); + p >>= 4; + + for (i = 0; i < N; i++) { + sched_ctl->aperiodic_subband_pmi[CC_idP][i] = + (uint8_t) (p & 0x01); + p >>= 2; + } + + sched_ctl->aperiodic_wideband_pmi[CC_idP] = p & 0x0F; } - sched_ctl->aperiodic_wideband_pmi[CC_idP] = p & 0x0F; - } - break; + break; #if (LTE_RRC_VERSION >= MAKE_VERSION(12, 5, 0)) - case LTE_CQI_ReportModeAperiodic_rm32_v1250: - AssertFatal(tmode == 4 || tmode == 5 || tmode == 6 || tmode == 8 - || tmode == 9 - || tmode == 10, - "Illegal transmission mode %d for CQI_ReportModeAperiodic_rm32\n", - tmode); - AssertFatal(1 == 0, "CQI_ReportModeAperiodic_rm32 to be done\n"); - break; + + case LTE_CQI_ReportModeAperiodic_rm32_v1250: + AssertFatal(tmode == 4 || tmode == 5 || tmode == 6 || tmode == 8 + || tmode == 9 + || tmode == 10, + "Illegal transmission mode %d for CQI_ReportModeAperiodic_rm32\n", + tmode); + AssertFatal(1 == 0, "CQI_ReportModeAperiodic_rm32 to be done\n"); + break; #endif #if (LTE_RRC_VERSION >= MAKE_VERSION(13, 1, 0)) - case LTE_CQI_ReportModeAperiodic_rm10_v1310: - AssertFatal(tmode == 1 || tmode == 2 || tmode == 3 - || tmode == 7, - "Illegal transmission mode %d for CQI_ReportModeAperiodic_rm10\n", - tmode); - AssertFatal(1 == 0, "CQI_ReportModeAperiodic_rm10 to be done\n"); - break; - case LTE_CQI_ReportModeAperiodic_rm11_v1310: - AssertFatal(tmode == 4 || tmode == 5 || tmode == 6 || tmode == 8 - || tmode == 9 - || tmode == 10, - "Illegal transmission mode %d for CQI_ReportModeAperiodic_rm11\n", - tmode); - AssertFatal(1 == 0, "CQI_ReportModeAperiodic_rm11 to be done\n"); - break; + + case LTE_CQI_ReportModeAperiodic_rm10_v1310: + AssertFatal(tmode == 1 || tmode == 2 || tmode == 3 + || tmode == 7, + "Illegal transmission mode %d for CQI_ReportModeAperiodic_rm10\n", + tmode); + AssertFatal(1 == 0, "CQI_ReportModeAperiodic_rm10 to be done\n"); + break; + + case LTE_CQI_ReportModeAperiodic_rm11_v1310: + AssertFatal(tmode == 4 || tmode == 5 || tmode == 6 || tmode == 8 + || tmode == 9 + || tmode == 10, + "Illegal transmission mode %d for CQI_ReportModeAperiodic_rm11\n", + tmode); + AssertFatal(1 == 0, "CQI_ReportModeAperiodic_rm11 to be done\n"); + break; #endif /* #if (LTE_RRC_VERSION >= MAKE_VERSION(13, 1, 0)) */ } } void cqi_indication(module_id_t mod_idP, int CC_idP, frame_t frameP, - sub_frame_t subframeP, rnti_t rntiP, - nfapi_cqi_indication_rel9_t * rel9, uint8_t * pdu, - nfapi_ul_cqi_information_t * ul_cqi_information) -{ + sub_frame_t subframeP, rnti_t rntiP, + nfapi_cqi_indication_rel9_t *rel9, uint8_t *pdu, + nfapi_ul_cqi_information_t *ul_cqi_information) { int UE_id = find_UE_id(mod_idP, rntiP); UE_list_t *UE_list = &RC.mac[mod_idP]->UE_list; + if (UE_id == -1) { LOG_W(MAC, "cqi_indication: UE %x not found\n", rntiP); return; } + UE_sched_ctrl *sched_ctl = &UE_list->UE_sched_ctrl[UE_id]; if (UE_id >= 0) { - LOG_D(MAC,"%s() UE_id:%d channel:%d cqi:%d\n", __FUNCTION__, UE_id, ul_cqi_information->channel, ul_cqi_information->ul_cqi); - if (ul_cqi_information->channel == 0) { // PUCCH - + if (ul_cqi_information->channel == 0) { // PUCCH // extract pucch csi information before changing RI information extract_pucch_csi(mod_idP, CC_idP, UE_id, frameP, subframeP, - pdu, rel9->length); - + pdu, rel9->length); memcpy((void *) sched_ctl->periodic_ri_received, - (void *) rel9->ri, rel9->number_of_cc_reported); - + (void *) rel9->ri, rel9->number_of_cc_reported); // SNR for PUCCH2 sched_ctl->pucch2_snr[CC_idP] = ul_cqi_information->ul_cqi; - } else { //PUSCH + } else { //PUSCH memcpy((void *) sched_ctl->aperiodic_ri_received, - (void *) rel9->ri, rel9->number_of_cc_reported); - + (void *) rel9->ri, rel9->number_of_cc_reported); extract_pusch_csi(mod_idP, CC_idP, UE_id, frameP, subframeP, - pdu, rel9->length); - + pdu, rel9->length); LOG_D(MAC,"Frame %d Subframe %d update CQI:%d\n",frameP,subframeP,sched_ctl->dl_cqi[CC_idP]); - sched_ctl->cqi_req_flag &= (~(1 << subframeP)); sched_ctl->cqi_received = 1; } @@ -4441,108 +4532,112 @@ cqi_indication(module_id_t mod_idP, int CC_idP, frame_t frameP, void SR_indication(module_id_t mod_idP, int cc_idP, frame_t frameP, - sub_frame_t subframeP, rnti_t rntiP, uint8_t ul_cqi) -{ + sub_frame_t subframeP, rnti_t rntiP, uint8_t ul_cqi) { T(T_ENB_MAC_SCHEDULING_REQUEST, T_INT(mod_idP), T_INT(cc_idP), T_INT(frameP), T_INT(subframeP), T_INT(rntiP)); - int UE_id = find_UE_id(mod_idP, rntiP); UE_list_t *UE_list = &RC.mac[mod_idP]->UE_list; if (UE_id != -1) { if (mac_eNB_get_rrc_status(mod_idP, UE_RNTI(mod_idP, UE_id)) < - RRC_CONNECTED) + RRC_CONNECTED) LOG_D(MAC, - "[eNB %d][SR %x] Frame %d subframeP %d Signaling SR for UE %d on CC_id %d\n", - mod_idP, rntiP, frameP, subframeP, UE_id, cc_idP); + "[eNB %d][SR %x] Frame %d subframeP %d Signaling SR for UE %d on CC_id %d\n", + mod_idP, rntiP, frameP, subframeP, UE_id, cc_idP); UE_list->UE_template[cc_idP][UE_id].ul_SR = 1; UE_list->UE_template[cc_idP][UE_id].ul_active = TRUE; VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME - (VCD_SIGNAL_DUMPER_FUNCTIONS_SR_INDICATION, 1); + (VCD_SIGNAL_DUMPER_FUNCTIONS_SR_INDICATION, 1); VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME - (VCD_SIGNAL_DUMPER_FUNCTIONS_SR_INDICATION, 0); + (VCD_SIGNAL_DUMPER_FUNCTIONS_SR_INDICATION, 0); } else { // AssertFatal(0, "find_UE_id(%u,rnti %d) not found", enb_mod_idP, rntiP); // AssertError(0, 0, "Frame %d: find_UE_id(%u,rnti %d) not found\n", frameP, enb_mod_idP, rntiP); LOG_D(MAC, - "[eNB %d][SR %x] Frame %d subframeP %d Signaling SR for UE %d (unknown UEid) on CC_id %d\n", - mod_idP, rntiP, frameP, subframeP, UE_id, cc_idP); + "[eNB %d][SR %x] Frame %d subframeP %d Signaling SR for UE %d (unknown UEid) on CC_id %d\n", + mod_idP, rntiP, frameP, subframeP, UE_id, cc_idP); } } void UL_failure_indication(module_id_t mod_idP, int cc_idP, frame_t frameP, - rnti_t rntiP, sub_frame_t subframeP) -{ + rnti_t rntiP, sub_frame_t subframeP) { int UE_id = find_UE_id(mod_idP, rntiP); UE_list_t *UE_list = &RC.mac[mod_idP]->UE_list; if (UE_id != -1) { LOG_D(MAC, - "[eNB %d][UE %d/%x] Frame %d subframeP %d Signaling UL Failure for UE %d on CC_id %d (timer %d)\n", - mod_idP, UE_id, rntiP, frameP, subframeP, UE_id, cc_idP, - UE_list->UE_sched_ctrl[UE_id].ul_failure_timer); + "[eNB %d][UE %d/%x] Frame %d subframeP %d Signaling UL Failure for UE %d on CC_id %d (timer %d)\n", + mod_idP, UE_id, rntiP, frameP, subframeP, UE_id, cc_idP, + UE_list->UE_sched_ctrl[UE_id].ul_failure_timer); + if (UE_list->UE_sched_ctrl[UE_id].ul_failure_timer == 0) UE_list->UE_sched_ctrl[UE_id].ul_failure_timer = 1; } else { // AssertFatal(0, "find_UE_id(%u,rnti %d) not found", enb_mod_idP, rntiP); // AssertError(0, 0, "Frame %d: find_UE_id(%u,rnti %d) not found\n", frameP, enb_mod_idP, rntiP); LOG_W(MAC, - "[eNB %d][SR %x] Frame %d subframeP %d Signaling UL Failure for UE %d (unknown UEid) on CC_id %d\n", - mod_idP, rntiP, frameP, subframeP, UE_id, cc_idP); + "[eNB %d][SR %x] Frame %d subframeP %d Signaling UL Failure for UE %d (unknown UEid) on CC_id %d\n", + mod_idP, rntiP, frameP, subframeP, UE_id, cc_idP); } } static int nack_or_dtx_reported( - COMMON_channels_t *cc, - nfapi_harq_indication_pdu_t *harq_pdu) -{ + COMMON_channels_t *cc, + nfapi_harq_indication_pdu_t *harq_pdu) { int i; if (cc->tdd_Config) { nfapi_harq_indication_tdd_rel13_t *hi = &harq_pdu->harq_indication_tdd_rel13; + for (i = 0; i < hi->number_of_ack_nack; hi++) if (hi->harq_data[0].bundling.value_0 != 1) //only bundling is used for tdd for now return 1; + return 0; } else { nfapi_harq_indication_fdd_rel13_t *hi = &harq_pdu->harq_indication_fdd_rel13; + for (i = 0; i < hi->number_of_ack_nack; hi++) if (hi->harq_tb_n[i] != 1) return 1; + return 0; } } void harq_indication(module_id_t mod_idP, int CC_idP, frame_t frameP, - sub_frame_t subframeP, - nfapi_harq_indication_pdu_t * harq_pdu) -{ + sub_frame_t subframeP, + nfapi_harq_indication_pdu_t *harq_pdu) { rnti_t rnti = harq_pdu->rx_ue_information.rnti; uint8_t ul_cqi = harq_pdu->ul_cqi_information.ul_cqi; uint8_t channel = harq_pdu->ul_cqi_information.channel; int UE_id = find_UE_id(mod_idP, rnti); + if (UE_id == -1) { LOG_W(MAC, "harq_indication: UE %x not found\n", rnti); return; } + UE_list_t *UE_list = &RC.mac[mod_idP]->UE_list; UE_sched_ctrl *sched_ctl = &UE_list->UE_sched_ctrl[UE_id]; COMMON_channels_t *cc = &RC.mac[mod_idP]->common_channels[CC_idP]; // extract HARQ Information LOG_D(MAC, - "Frame %d, subframe %d: Received harq indication (%d) from UE %d/%x, ul_cqi %d\n", - frameP, subframeP, channel, UE_id, rnti, ul_cqi); + "Frame %d, subframe %d: Received harq indication (%d) from UE %d/%x, ul_cqi %d\n", + frameP, subframeP, channel, UE_id, rnti, ul_cqi); + if (cc->tdd_Config) extract_harq(mod_idP, CC_idP, UE_id, frameP, subframeP, - (void *) &harq_pdu->harq_indication_tdd_rel13, - channel); + (void *) &harq_pdu->harq_indication_tdd_rel13, + channel); else extract_harq(mod_idP, CC_idP, UE_id, frameP, subframeP, - (void *) &harq_pdu->harq_indication_fdd_rel13, - channel); + (void *) &harq_pdu->harq_indication_fdd_rel13, + channel); + /* don't care about cqi reporting if NACK/DTX is there */ if (channel == 0 && !nack_or_dtx_reported(cc, harq_pdu)) { sched_ctl->pucch1_snr[CC_idP] = ul_cqi; @@ -4552,31 +4647,31 @@ harq_indication(module_id_t mod_idP, int CC_idP, frame_t frameP, // Flexran Slicing functions -uint16_t nb_rbs_allowed_slice(float rb_percentage, int total_rbs) -{ - return (uint16_t) floor(rb_percentage * total_rbs); +uint16_t nb_rbs_allowed_slice(float rb_percentage, int total_rbs) { + return (uint16_t) floor(rb_percentage * total_rbs); } -int ue_dl_slice_membership(module_id_t mod_id, int UE_id, int slice_idx) -{ +int ue_dl_slice_membership(module_id_t mod_id, int UE_id, int slice_idx) { if ((slice_idx < 0) || (slice_idx >= RC.mac[mod_id]->slice_info.n_dl)) { LOG_W(MAC, "out of range slice index %d (slice ID %d)\n", slice_idx, RC.mac[mod_id]->slice_info.dl[slice_idx].id); return 0; } + return RC.mac[mod_id]->UE_list.active[UE_id] == TRUE && RC.mac[mod_id]->UE_list.assoc_dl_slice_idx[UE_id] == slice_idx; } -int ue_ul_slice_membership(module_id_t mod_id, int UE_id, int slice_idx) +int ue_ul_slice_membership(module_id_t mod_id, + int UE_id, + int slice_idx) { - if ((slice_idx < 0) - || (slice_idx >= RC.mac[mod_id]->slice_info.n_ul)) { + if ((slice_idx < 0) || (slice_idx >= RC.mac[mod_id]->slice_info.n_ul)) { LOG_W(MAC, "out of range slice index %d (slice ID %d)\n", slice_idx, RC.mac[mod_id]->slice_info.dl[slice_idx].id); return 0; } - return RC.mac[mod_id]->UE_list.active[UE_id] == TRUE - && RC.mac[mod_id]->UE_list.assoc_ul_slice_idx[UE_id] == slice_idx; + + return RC.mac[mod_id]->UE_list.active[UE_id] == TRUE && RC.mac[mod_id]->UE_list.assoc_ul_slice_idx[UE_id] == slice_idx; } diff --git a/openair2/LAYER2/MAC/eNB_scheduler_ulsch.c b/openair2/LAYER2/MAC/eNB_scheduler_ulsch.c index c4a6a59e2b482dd66fdc8e11ddd4a1752cdeb07f..10d4fc1523d837e886a5c31bd26b5d98a6a15b29 100644 --- a/openair2/LAYER2/MAC/eNB_scheduler_ulsch.c +++ b/openair2/LAYER2/MAC/eNB_scheduler_ulsch.c @@ -31,8 +31,6 @@ /* indented with: indent -kr eNB_scheduler_RA.c */ - - #include "LAYER2/MAC/mac.h" #include "LAYER2/MAC/mac_proto.h" #include "LAYER2/MAC/mac_extern.h" @@ -47,7 +45,6 @@ #include "RRC/L2_INTERFACE/openair_rrc_L2_interface.h" #include "assertions.h" -//#include "LAYER2/MAC/pre_processor.c" #include "pdcp.h" #if defined(ENABLE_ITTI) @@ -77,12 +74,21 @@ extern uint8_t nfapi_mode; // This table holds the allowable PRB sizes for ULSCH transmissions uint8_t rb_table[34] = { - 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, 16, 18, 20, 24, 25, 27, 30, 32, - 36, 40, 45, 48, 50, 54, 60, 64, 72, 75, 80, 81, 90, 96, 100 + 1, 2, 3, 4, 5, // 0-4 + 6, 8, 9, 10, 12, // 5-9 + 15, 16, 18, 20, 24, // 10-14 + 25, 27, 30, 32, 36, // 15-19 + 40, 45, 48, 50, 54, // 20-24 + 60, 64, 72, 75, 80, // 25-29 + 81, 90, 96, 100 // 30-33 }; -extern mui_t rrc_eNB_mui; +extern mui_t rrc_eNB_mui; +//----------------------------------------------------------------------------- +/* +* When data are received on PHY and transmitted to MAC +*/ void rx_sdu(const module_id_t enb_mod_idP, const int CC_idP, @@ -91,47 +97,67 @@ rx_sdu(const module_id_t enb_mod_idP, const rnti_t rntiP, uint8_t *sduP, const uint16_t sdu_lenP, - const uint16_t timing_advance, const uint8_t ul_cqi) { - int current_rnti = rntiP; - unsigned char rx_ces[MAX_NUM_CE], num_ce, num_sdu, i, *payload_ptr; + const uint16_t timing_advance, + const uint8_t ul_cqi) +//----------------------------------------------------------------------------- +{ + int current_rnti = 0; + int UE_id = -1; + int RA_id = 0; + int old_rnti = -1; + int old_UE_id = -1; + int crnti_rx = 0; + int harq_pid = 0; + int first_rb = 0; + unsigned char num_ce = 0; + unsigned char num_sdu = 0; + unsigned char *payload_ptr = NULL; + unsigned char rx_ces[MAX_NUM_CE]; unsigned char rx_lcids[NB_RB_MAX]; unsigned short rx_lengths[NB_RB_MAX]; - int UE_id = find_UE_id(enb_mod_idP, current_rnti); - int RA_id; - int ii, j; - eNB_MAC_INST *mac = RC.mac[enb_mod_idP]; - int harq_pid = - subframe2harqpid(&mac->common_channels[CC_idP], frameP, subframeP); + uint8_t lcgid = 0; int lcgid_updated[4] = {0, 0, 0, 0}; - UE_list_t *UE_list = &mac->UE_list; - int crnti_rx = 0; - int first_rb = 0; + eNB_MAC_INST *mac = NULL; + UE_list_t *UE_list = NULL; rrc_eNB_ue_context_t *ue_contextP = NULL; - start_meas(&mac->rx_ulsch_sdu); - if ((UE_id > MAX_MOBILES_PER_ENB) || (UE_id == -1)) - for (ii = 0; ii < NB_RB_MAX; ii++) { - rx_lengths[ii] = 0; - } + /* Init */ + current_rnti = rntiP; + UE_id = find_UE_id(enb_mod_idP, current_rnti); + mac = RC.mac[enb_mod_idP]; + harq_pid = subframe2harqpid(&mac->common_channels[CC_idP], frameP, subframeP); + UE_list = &mac->UE_list; + memset(rx_ces, 0, MAX_NUM_CE * sizeof(unsigned char)); + memset(rx_lcids, 0, NB_RB_MAX * sizeof(unsigned char)); + memset(rx_lengths, 0, NB_RB_MAX * sizeof(unsigned short)); + + start_meas(&mac->rx_ulsch_sdu); - VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME - (VCD_SIGNAL_DUMPER_FUNCTIONS_RX_SDU, 1); + VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RX_SDU, 1); if (opt_enabled == 1) { - trace_pdu(DIRECTION_UPLINK, sduP, sdu_lenP, 0, WS_C_RNTI, current_rnti, frameP, subframeP, - 0, 0); - LOG_D(OPT, "[eNB %d][ULSCH] Frame %d rnti %x with size %d\n", - enb_mod_idP, frameP, current_rnti, sdu_lenP); + trace_pdu(DIRECTION_UPLINK, sduP, sdu_lenP, 0, WS_C_RNTI, current_rnti, frameP, subframeP, 0, 0); + + LOG_D(OPT, "[eNB %d][ULSCH] Frame %d rnti %x with size %d\n", + enb_mod_idP, + frameP, + current_rnti, + sdu_lenP); } if (UE_id != -1) { - LOG_D(MAC, - "[eNB %d][PUSCH %d] CC_id %d %d.%d Received ULSCH sdu round %d from PHY (rnti %x, UE_id %d) ul_cqi %d\n", - enb_mod_idP, harq_pid, CC_idP,frameP,subframeP, + LOG_D(MAC, "[eNB %d][PUSCH %d] CC_id %d %d.%d Received ULSCH sdu round %d from PHY (rnti %x, UE_id %d) ul_cqi %d\n", + enb_mod_idP, + harq_pid, + CC_idP, + frameP, + subframeP, UE_list->UE_sched_ctrl[UE_id].round_UL[CC_idP][harq_pid], - current_rnti, UE_id, ul_cqi); - AssertFatal(UE_list->UE_sched_ctrl[UE_id]. - round_UL[CC_idP][harq_pid] < 8, "round >= 8\n"); + current_rnti, + UE_id, + ul_cqi); + + AssertFatal(UE_list->UE_sched_ctrl[UE_id].round_UL[CC_idP][harq_pid] < 8, "round >= 8\n"); if (sduP != NULL) { UE_list->UE_sched_ctrl[UE_id].ul_inactivity_timer = 0; @@ -145,63 +171,78 @@ rx_sdu(const module_id_t enb_mod_idP, UE_list->UE_sched_ctrl[UE_id].ta_update = (UE_list->UE_sched_ctrl[UE_id].ta_update * 3 + timing_advance) / 4; UE_list->UE_sched_ctrl[UE_id].pusch_snr[CC_idP] = ul_cqi; UE_list->UE_sched_ctrl[UE_id].ul_consecutive_errors = 0; + first_rb = UE_list->UE_template[CC_idP][UE_id].first_rb_ul[harq_pid]; if (UE_list->UE_sched_ctrl[UE_id].ul_out_of_sync > 0) { UE_list->UE_sched_ctrl[UE_id].ul_out_of_sync = 0; - mac_eNB_rrc_ul_in_sync(enb_mod_idP, CC_idP, frameP, - subframeP, UE_RNTI(enb_mod_idP, - UE_id)); + mac_eNB_rrc_ul_in_sync(enb_mod_idP, CC_idP, frameP, subframeP, current_rnti); } - /* update scheduled bytes */ + /* Update bytes to schedule */ UE_list->UE_template[CC_idP][UE_id].scheduled_ul_bytes -= UE_list->UE_template[CC_idP][UE_id].TBS_UL[harq_pid]; - if (UE_list->UE_template[CC_idP][UE_id].scheduled_ul_bytes < 0) + if (UE_list->UE_template[CC_idP][UE_id].scheduled_ul_bytes < 0) { UE_list->UE_template[CC_idP][UE_id].scheduled_ul_bytes = 0; - } else { // we've got an error - LOG_I(MAC, - "[eNB %d][PUSCH %d] CC_id %d %d.%d ULSCH in error in round %d, ul_cqi %d\n", - enb_mod_idP, harq_pid, CC_idP,frameP,subframeP, - UE_list->UE_sched_ctrl[UE_id].round_UL[CC_idP][harq_pid], - ul_cqi); - - if(ul_cqi>200) { // too high energy pattern - UE_list->UE_sched_ctrl[UE_id].pusch_snr[CC_idP] = ul_cqi; } + } else { // sduP == NULL => error + LOG_W(MAC, "[eNB %d][PUSCH %d] CC_id %d %d.%d ULSCH in error in round %d, ul_cqi %d, UE_id %d, RNTI %x\n", + enb_mod_idP, + harq_pid, + CC_idP, + frameP, + subframeP, + UE_list->UE_sched_ctrl[UE_id].round_UL[CC_idP][harq_pid], + ul_cqi, + UE_id, + current_rnti); + + if (ul_cqi > 200) { // too high energy pattern + UE_list->UE_sched_ctrl[UE_id].pusch_snr[CC_idP] = ul_cqi; + LOG_W(MAC, "[MAC] Too high energy pattern\n"); + } - // AssertFatal(1==0,"ulsch in error\n"); if (UE_list->UE_sched_ctrl[UE_id].round_UL[CC_idP][harq_pid] == 3) { UE_list->UE_sched_ctrl[UE_id].ul_scheduled &= (~(1 << harq_pid)); UE_list->UE_sched_ctrl[UE_id].round_UL[CC_idP][harq_pid] = 0; - if (UE_list->UE_sched_ctrl[UE_id].ul_consecutive_errors++ == 10) + if (UE_list->UE_sched_ctrl[UE_id].ul_consecutive_errors++ == 10) { UE_list->UE_sched_ctrl[UE_id].ul_failure_timer = 1; + } - /* update scheduled bytes */ + /* Update scheduled bytes */ UE_list->UE_template[CC_idP][UE_id].scheduled_ul_bytes -= UE_list->UE_template[CC_idP][UE_id].TBS_UL[harq_pid]; - if (UE_list->UE_template[CC_idP][UE_id].scheduled_ul_bytes < 0) + if (UE_list->UE_template[CC_idP][UE_id].scheduled_ul_bytes < 0) { UE_list->UE_template[CC_idP][UE_id].scheduled_ul_bytes = 0; + } - if (find_RA_id(enb_mod_idP, CC_idP, current_rnti) != -1) + if (find_RA_id(enb_mod_idP, CC_idP, current_rnti) != -1) { cancel_ra_proc(enb_mod_idP, CC_idP, frameP, current_rnti); - } else + } + + } else { UE_list->UE_sched_ctrl[UE_id].round_UL[CC_idP][harq_pid]++; + } first_rb = UE_list->UE_template[CC_idP][UE_id].first_rb_ul[harq_pid]; - // Program NACK for PHICH - LOG_D(MAC, - "Programming PHICH NACK for rnti %x harq_pid %d (first_rb %d)\n", - current_rnti, harq_pid, first_rb); - nfapi_hi_dci0_request_t *hi_dci0_req; + + /* Program NACK for PHICH */ + LOG_D(MAC, "Programming PHICH NACK for rnti %x harq_pid %d (first_rb %d)\n", + current_rnti, + harq_pid, + first_rb); + + nfapi_hi_dci0_request_t *hi_dci0_req = NULL; uint8_t sf_ahead_dl = ul_subframe2_k_phich(&mac->common_channels[CC_idP], subframeP); - hi_dci0_req = &mac->HI_DCI0_req[CC_idP][(subframeP+sf_ahead_dl)%10]; + hi_dci0_req = &mac->HI_DCI0_req[CC_idP][(subframeP + sf_ahead_dl) % 10]; + nfapi_hi_dci0_request_body_t *hi_dci0_req_body = &hi_dci0_req->hi_dci0_request_body; - nfapi_hi_dci0_request_pdu_t *hi_dci0_pdu = - &hi_dci0_req_body->hi_dci0_pdu_list[hi_dci0_req_body->number_of_dci + hi_dci0_req_body->number_of_hi]; + nfapi_hi_dci0_request_pdu_t *hi_dci0_pdu = &hi_dci0_req_body->hi_dci0_pdu_list[hi_dci0_req_body->number_of_dci + hi_dci0_req_body->number_of_hi]; + memset((void *) hi_dci0_pdu, 0, sizeof(nfapi_hi_dci0_request_pdu_t)); + hi_dci0_pdu->pdu_type = NFAPI_HI_DCI0_HI_PDU_TYPE; hi_dci0_pdu->pdu_size = 2 + sizeof(nfapi_hi_dci0_hi_pdu); hi_dci0_pdu->hi_pdu.hi_pdu_rel8.tl.tag = NFAPI_HI_DCI0_REQUEST_HI_PDU_REL8_TAG; @@ -215,44 +256,54 @@ rx_sdu(const module_id_t enb_mod_idP, hi_dci0_req->header.message_id = NFAPI_HI_DCI0_REQUEST; return; } + // if UE_id == -1 } else if ((RA_id = find_RA_id(enb_mod_idP, CC_idP, current_rnti)) != -1) { // Check if this is an RA process for the rnti - RA_t *ra = (RA_t *) & mac->common_channels[CC_idP].ra[RA_id]; + RA_t *ra = (RA_t *) &(mac->common_channels[CC_idP].ra[RA_id]); #if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0)) - if (ra->rach_resource_type > 0) harq_pid=0; + if (ra->rach_resource_type > 0) { + harq_pid = 0; + } #endif - AssertFatal(mac->common_channels[CC_idP]. - radioResourceConfigCommon->rach_ConfigCommon. - maxHARQ_Msg3Tx > 1, + + AssertFatal(mac->common_channels[CC_idP].radioResourceConfigCommon->rach_ConfigCommon.maxHARQ_Msg3Tx > 1, "maxHARQ %d should be greater than 1\n", - (int) mac->common_channels[CC_idP]. - radioResourceConfigCommon->rach_ConfigCommon. - maxHARQ_Msg3Tx); - LOG_D(MAC, - "[eNB %d][PUSCH %d] CC_id %d [RAPROC Msg3] Received ULSCH sdu round %d from PHY (rnti %x, RA_id %d) ul_cqi %d\n", - enb_mod_idP, harq_pid, CC_idP, ra->msg3_round, - current_rnti, RA_id, ul_cqi); + (int) mac->common_channels[CC_idP].radioResourceConfigCommon->rach_ConfigCommon.maxHARQ_Msg3Tx); + + LOG_D(MAC, "[eNB %d][PUSCH %d] CC_id %d [RAPROC Msg3] Received ULSCH sdu round %d from PHY (rnti %x, RA_id %d) ul_cqi %d\n", + enb_mod_idP, + harq_pid, + CC_idP, + ra->msg3_round, + current_rnti, + RA_id, + ul_cqi); + first_rb = ra->msg3_first_rb; if (sduP == NULL) { // we've got an error on Msg3 - LOG_D(MAC, - "[eNB %d] CC_id %d, RA %d ULSCH in error in round %d/%d\n", - enb_mod_idP, CC_idP, RA_id, - ra->msg3_round, - (int) mac->common_channels[CC_idP]. - radioResourceConfigCommon->rach_ConfigCommon. - maxHARQ_Msg3Tx); + LOG_D(MAC, "[eNB %d] CC_id %d, RA %d ULSCH in error in round %d/%d\n", + enb_mod_idP, + CC_idP, + RA_id, + ra->msg3_round, + (int) mac->common_channels[CC_idP].radioResourceConfigCommon->rach_ConfigCommon.maxHARQ_Msg3Tx); if (ra->msg3_round >= mac->common_channels[CC_idP].radioResourceConfigCommon->rach_ConfigCommon.maxHARQ_Msg3Tx - 1) { cancel_ra_proc(enb_mod_idP, CC_idP, frameP, current_rnti); } else { - first_rb = UE_list->UE_template[CC_idP][UE_id].first_rb_ul[harq_pid]; + // first_rb = UE_list->UE_template[CC_idP][UE_id].first_rb_ul[harq_pid]; // UE_id = -1 !!!! ra->msg3_round++; - // prepare handling of retransmission + + /* Prepare handling of retransmission */ get_Msg3allocret(&mac->common_channels[CC_idP], - ra->Msg3_subframe, ra->Msg3_frame, - &ra->Msg3_frame, &ra->Msg3_subframe); + ra->Msg3_subframe, + ra->Msg3_frame, + &ra->Msg3_frame, + &ra->Msg3_subframe); + // prepare handling of retransmission + add_msg3(enb_mod_idP, CC_idP, ra, frameP, subframeP); } @@ -260,87 +311,141 @@ rx_sdu(const module_id_t enb_mod_idP, return; } } else { - LOG_W(MAC, - "Cannot find UE or RA corresponding to ULSCH rnti %x, dropping it\n", - current_rnti); + LOG_W(MAC, "Cannot find UE or RA corresponding to ULSCH rnti %x, dropping it\n", current_rnti); + return; } payload_ptr = parse_ulsch_header(sduP, &num_ce, &num_sdu, rx_ces, rx_lcids, rx_lengths, sdu_lenP); - if(payload_ptr == NULL) { + if (payload_ptr == NULL) { LOG_E(MAC,"[eNB %d][PUSCH %d] CC_id %d ulsch header unknown lcid(rnti %x, UE_id %d)\n", - enb_mod_idP, harq_pid, CC_idP,current_rnti, UE_id); + enb_mod_idP, + harq_pid, + CC_idP, + current_rnti, + UE_id); + return; } - T(T_ENB_MAC_UE_UL_PDU, T_INT(enb_mod_idP), T_INT(CC_idP), - T_INT(current_rnti), T_INT(frameP), T_INT(subframeP), - T_INT(harq_pid), T_INT(sdu_lenP), T_INT(num_ce), T_INT(num_sdu)); - T(T_ENB_MAC_UE_UL_PDU_WITH_DATA, T_INT(enb_mod_idP), T_INT(CC_idP), - T_INT(current_rnti), T_INT(frameP), T_INT(subframeP), - T_INT(harq_pid), T_INT(sdu_lenP), T_INT(num_ce), T_INT(num_sdu), + T(T_ENB_MAC_UE_UL_PDU, + T_INT(enb_mod_idP), + T_INT(CC_idP), + T_INT(current_rnti), + T_INT(frameP), + T_INT(subframeP), + T_INT(harq_pid), + T_INT(sdu_lenP), + T_INT(num_ce), + T_INT(num_sdu)); + + T(T_ENB_MAC_UE_UL_PDU_WITH_DATA, + T_INT(enb_mod_idP), + T_INT(CC_idP), + T_INT(current_rnti), + T_INT(frameP), + T_INT(subframeP), + T_INT(harq_pid), + T_INT(sdu_lenP), + T_INT(num_ce), + T_INT(num_sdu), T_BUFFER(sduP, sdu_lenP)); + mac->eNB_stats[CC_idP].ulsch_bytes_rx = sdu_lenP; mac->eNB_stats[CC_idP].total_ulsch_bytes_rx += sdu_lenP; mac->eNB_stats[CC_idP].total_ulsch_pdus_rx += 1; - UE_list->UE_sched_ctrl[UE_id].round_UL[CC_idP][harq_pid] = 0; - - // control element - for (i = 0; i < num_ce; i++) { - T(T_ENB_MAC_UE_UL_CE, T_INT(enb_mod_idP), T_INT(CC_idP), - T_INT(current_rnti), T_INT(frameP), T_INT(subframeP), + if (UE_id != -1) { + UE_list->UE_sched_ctrl[UE_id].round_UL[CC_idP][harq_pid] = 0; + } + + /* Control element */ + for (int i = 0; i < num_ce; i++) { + T(T_ENB_MAC_UE_UL_CE, + T_INT(enb_mod_idP), + T_INT(CC_idP), + T_INT(current_rnti), + T_INT(frameP), + T_INT(subframeP), T_INT(rx_ces[i])); - switch (rx_ces[i]) { // implement and process BSR + CRNTI + + switch (rx_ces[i]) { // implement and process PHR + CRNTI + BSR case POWER_HEADROOM: if (UE_id != -1) { - UE_list->UE_template[CC_idP][UE_id].phr_info = - (payload_ptr[0] & 0x3f) - PHR_MAPPING_OFFSET + (int8_t)(hundred_times_log10_NPRB[UE_list->UE_template[CC_idP][UE_id].nb_rb_ul[harq_pid]-1]/100); + UE_list->UE_template[CC_idP][UE_id].phr_info = (payload_ptr[0] & 0x3f) - PHR_MAPPING_OFFSET + (int8_t)(hundred_times_log10_NPRB[UE_list->UE_template[CC_idP][UE_id].nb_rb_ul[harq_pid] - 1] / 100); - if(UE_list->UE_template[CC_idP][UE_id].phr_info > 40) + if (UE_list->UE_template[CC_idP][UE_id].phr_info > 40) { UE_list->UE_template[CC_idP][UE_id].phr_info = 40; + } - LOG_D(MAC, - "[eNB %d] CC_id %d MAC CE_LCID %d : Received PHR PH = %d (db)\n", - enb_mod_idP, CC_idP, rx_ces[i], - UE_list->UE_template[CC_idP][UE_id].phr_info); - UE_list->UE_template[CC_idP][UE_id].phr_info_configured = - 1; + LOG_D(MAC, "[eNB %d] CC_id %d MAC CE_LCID %d : Received PHR PH = %d (db)\n", + enb_mod_idP, + CC_idP, + rx_ces[i], + UE_list->UE_template[CC_idP][UE_id].phr_info); + + UE_list->UE_template[CC_idP][UE_id].phr_info_configured = 1; UE_list->UE_sched_ctrl[UE_id].phr_received = 1; } payload_ptr += sizeof(POWER_HEADROOM_CMD); + break; - case CRNTI: { - int old_rnti = - (((uint16_t) payload_ptr[0]) << 8) + payload_ptr[1]; - int old_UE_id = find_UE_id(enb_mod_idP, old_rnti); - LOG_D(MAC, - "[eNB %d] Frame %d, Subframe %d CC_id %d MAC CE_LCID %d (ce %d/%d): CRNTI %x (UE_id %d) in Msg3\n", - enb_mod_idP, frameP, subframeP, CC_idP, rx_ces[i], i, - num_ce, old_rnti, old_UE_id); - - /* receiving CRNTI means that the current rnti has to go away */ - //cancel_ra_proc(enb_mod_idP, CC_idP, frameP, - // current_rnti); + case CRNTI: + old_rnti = (((uint16_t) payload_ptr[0]) << 8) + payload_ptr[1]; + old_UE_id = find_UE_id(enb_mod_idP, old_rnti); + + LOG_D(MAC, "[eNB %d] Frame %d, Subframe %d CC_id %d MAC CE_LCID %d (ce %d/%d): CRNTI %x (UE_id %d) in Msg3\n", + enb_mod_idP, + frameP, + subframeP, + CC_idP, + rx_ces[i], + i, + num_ce, + old_rnti, + old_UE_id); + + /* Receiving CRNTI means that the current rnti has to go away */ if (old_UE_id != -1) { - /* TODO: if the UE did random access (followed by a MAC uplink with - * CRNTI) because none of its scheduling request was granted, then - * according to 36.321 5.4.4 the UE's MAC will notify RRC to release - * PUCCH/SRS. According to 36.331 5.3.13 the UE will then apply - * default configuration for CQI reporting and scheduling requests, - * which basically means that the CQI requests won't work anymore and - * that the UE won't do any scheduling request anymore as long as the - * eNB doesn't reconfigure the UE. - * We have to take care of this. As the code is, nothing is done and - * the UE state in the eNB is wrong. - */ - for (ii = 0; ii < NB_RA_PROC_MAX; ii++) { - RA_t *ra = &mac->common_channels[CC_idP].ra[ii]; - - if ((ra->rnti == current_rnti) && (ra->state != IDLE)) { + if (mac_eNB_get_rrc_status(enb_mod_idP,old_rnti) == RRC_HO_EXECUTION) { + LOG_I(MAC, + "[eNB %d] Frame %d, Subframe %d CC_id %d : (rnti %x UE_id %d) Handover case\n", + enb_mod_idP, frameP, subframeP, CC_idP, old_rnti, old_UE_id); + UE_id = old_UE_id; + current_rnti = old_rnti; + //clear timer + UE_list->UE_sched_ctrl[UE_id].uplane_inactivity_timer = 0; + UE_list->UE_sched_ctrl[UE_id].ul_inactivity_timer = 0; + UE_list->UE_sched_ctrl[UE_id].ul_failure_timer = 0; + + if (UE_list->UE_sched_ctrl[UE_id].ul_out_of_sync > 0) { + UE_list->UE_sched_ctrl[UE_id].ul_out_of_sync = 0; + mac_eNB_rrc_ul_in_sync(enb_mod_idP, CC_idP, frameP, + subframeP, old_rnti); + } + + UE_list->UE_template[CC_idP][UE_id].ul_SR = 1; + UE_list->UE_sched_ctrl[UE_id].crnti_reconfigurationcomplete_flag = 1; + UE_list->UE_template[UE_PCCID(enb_mod_idP, UE_id)][UE_id].configured = 1; + cancel_ra_proc(enb_mod_idP, CC_idP, frameP,current_rnti); + } else { + /* TODO: if the UE did random access (followed by a MAC uplink with + * CRNTI) because none of its scheduling request was granted, then + * according to 36.321 5.4.4 the UE's MAC will notify RRC to release + * PUCCH/SRS. According to 36.331 5.3.13 the UE will then apply + * default configuration for CQI reporting and scheduling requests, + * which basically means that the CQI requests won't work anymore and + * that the UE won't do any scheduling request anymore as long as the + * eNB doesn't reconfigure the UE. + * We have to take care of this. As the code is, nothing is done and + * the UE state in the eNB is wrong. + */ + RA_id = find_RA_id(enb_mod_idP, CC_idP, current_rnti); + + if (RA_id != -1) { + RA_t *ra = &(mac->common_channels[CC_idP].ra[RA_id]); mac_rrc_data_ind(enb_mod_idP, CC_idP, frameP, subframeP, @@ -350,93 +455,101 @@ rx_sdu(const module_id_t enb_mod_idP, rx_lengths[i], 0 #if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0)) - ,ra->rach_resource_type>0 + ,ra->rach_resource_type > 0 #endif - ); - // prepare transmission of Msg4(RRCConnectionReconfiguration) + ); + /* Prepare transmission of Msg4(RRCConnectionReconfiguration) */ ra->state = MSGCRNTI; - LOG_I(MAC, - "[eNB %d] Frame %d, Subframe %d CC_id %d : (rnti %x UE_id %d) RRCConnectionReconfiguration(Msg4)\n", - enb_mod_idP, frameP, subframeP, CC_idP, old_rnti, old_UE_id); + LOG_I(MAC, "[eNB %d] Frame %d, Subframe %d CC_id %d : (rnti %x UE_id %d) RRCConnectionReconfiguration(Msg4)\n", + enb_mod_idP, + frameP, + subframeP, + CC_idP, + old_rnti, + old_UE_id); UE_id = old_UE_id; current_rnti = old_rnti; ra->rnti = old_rnti; ra->crnti_rrc_mui = rrc_eNB_mui-1; ra->crnti_harq_pid = -1; - //clear timer + /* Clear timer */ + UE_list->UE_sched_ctrl[UE_id].uplane_inactivity_timer = 0; UE_list->UE_sched_ctrl[UE_id].uplane_inactivity_timer = 0; UE_list->UE_sched_ctrl[UE_id].ul_inactivity_timer = 0; UE_list->UE_sched_ctrl[UE_id].ul_failure_timer = 0; if (UE_list->UE_sched_ctrl[UE_id].ul_out_of_sync > 0) { UE_list->UE_sched_ctrl[UE_id].ul_out_of_sync = 0; - mac_eNB_rrc_ul_in_sync(enb_mod_idP, CC_idP, frameP, - subframeP, old_rnti); + mac_eNB_rrc_ul_in_sync(enb_mod_idP, CC_idP, frameP, subframeP, old_rnti); } UE_list->UE_template[CC_idP][UE_id].ul_SR = 1; UE_list->UE_sched_ctrl[UE_id].crnti_reconfigurationcomplete_flag = 1; - break; + // break; } } } else { - cancel_ra_proc(enb_mod_idP, CC_idP, frameP,current_rnti); + cancel_ra_proc(enb_mod_idP, CC_idP, frameP, current_rnti); + LOG_W(MAC, "[MAC] Can't find old UE_id\n"); } crnti_rx = 1; - payload_ptr += 2; + payload_ptr += 2; // sizeof(CRNTI) + break; - } case TRUNCATED_BSR: - case SHORT_BSR: { - uint8_t lcgid; + + case SHORT_BSR: lcgid = (payload_ptr[0] >> 6); - LOG_D(MAC, - "[eNB %d] CC_id %d MAC CE_LCID %d : Received short BSR LCGID = %u bsr = %d\n", - enb_mod_idP, CC_idP, rx_ces[i], lcgid, - payload_ptr[0] & 0x3f); - if (crnti_rx == 1) - LOG_D(MAC, - "[eNB %d] CC_id %d MAC CE_LCID %d : Received short BSR LCGID = %u bsr = %d\n", - enb_mod_idP, CC_idP, rx_ces[i], lcgid, - payload_ptr[0] & 0x3f); + LOG_D(MAC, "[eNB %d] CC_id %d MAC CE_LCID %d : Received short BSR LCGID = %u bsr = %d\n", + enb_mod_idP, + CC_idP, + rx_ces[i], + lcgid, + payload_ptr[0] & 0x3f); if (UE_id != -1) { - int bsr = payload_ptr[0] & 0x3f; + int bsr = 0; + + bsr = payload_ptr[0] & 0x3f; lcgid_updated[lcgid] = 1; - // update buffer info + + /* Update buffer info */ UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[lcgid] = BSR_TABLE[bsr]; UE_list->UE_template[CC_idP][UE_id].estimated_ul_buffer = UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID0] + UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID1] + UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID2] + UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID3]; - //UE_list->UE_template[CC_idP][UE_id].estimated_ul_buffer += UE_list->UE_template[CC_idP][UE_id].estimated_ul_buffer / 4; + RC.eNB[enb_mod_idP][CC_idP]->pusch_stats_bsr[UE_id][(frameP * 10) + subframeP] = (payload_ptr[0] & 0x3f); - if (UE_id == UE_list->head) - VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLES_UE0_BSR, - RC.eNB[enb_mod_idP][CC_idP]->pusch_stats_bsr - [UE_id][(frameP * 10) + subframeP]); + if (UE_id == UE_list->head) { + VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLES_UE0_BSR, (payload_ptr[0] & 0x3f)); + } if (UE_list->UE_template[CC_idP][UE_id].ul_buffer_creation_time[lcgid] == 0) { UE_list->UE_template[CC_idP][UE_id].ul_buffer_creation_time[lcgid] = frameP; } - if (mac_eNB_get_rrc_status(enb_mod_idP,UE_RNTI(enb_mod_idP, UE_id)) < RRC_CONNECTED) - LOG_D(MAC, - "[eNB %d] CC_id %d MAC CE_LCID %d : estimated_ul_buffer = %d (lcg increment %d)\n", - enb_mod_idP, CC_idP, rx_ces[i], - UE_list->UE_template[CC_idP][UE_id].estimated_ul_buffer, - UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[lcgid]); + if (mac_eNB_get_rrc_status(enb_mod_idP,UE_RNTI(enb_mod_idP, UE_id)) < RRC_CONNECTED) { + LOG_D(MAC, "[eNB %d] CC_id %d MAC CE_LCID %d : estimated_ul_buffer = %d (lcg increment %d)\n", + enb_mod_idP, + CC_idP, + rx_ces[i], + UE_list->UE_template[CC_idP][UE_id].estimated_ul_buffer, + UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[lcgid]); + } + } else { + /* Need error message */ } - payload_ptr += 1; //sizeof(SHORT_BSR); // fixme - } - break; + payload_ptr += 1; // sizeof(SHORT_BSR) + + break; case LONG_BSR: if (UE_id != -1) { @@ -444,201 +557,218 @@ rx_sdu(const module_id_t enb_mod_idP, int bsr1 = ((payload_ptr[0] & 0x03) << 4) | ((payload_ptr[1] & 0xF0) >> 4); int bsr2 = ((payload_ptr[1] & 0x0F) << 2) | ((payload_ptr[2] & 0xC0) >> 6); int bsr3 = payload_ptr[2] & 0x3F; + lcgid_updated[LCGID0] = 1; lcgid_updated[LCGID1] = 1; lcgid_updated[LCGID2] = 1; lcgid_updated[LCGID3] = 1; - // update buffer info + + /* Update buffer info */ UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID0] = BSR_TABLE[bsr0]; UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID1] = BSR_TABLE[bsr1]; UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID2] = BSR_TABLE[bsr2]; UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID3] = BSR_TABLE[bsr3]; + UE_list->UE_template[CC_idP][UE_id].estimated_ul_buffer = UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID0] + UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID1] + UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID2] + UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID3]; - //UE_list->UE_template[CC_idP][UE_id].estimated_ul_buffer += UE_list->UE_template[CC_idP][UE_id].estimated_ul_buffer / 4; - LOG_D(MAC, - "[eNB %d] CC_id %d MAC CE_LCID %d: Received long BSR. Size is LCGID0 = %u LCGID1 = " - "%u LCGID2 = %u LCGID3 = %u\n", enb_mod_idP, CC_idP, - rx_ces[i], - UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID0], - UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID1], - UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID2], - UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID3]); - - if (crnti_rx == 1) - LOG_D(MAC, - "[eNB %d] CC_id %d MAC CE_LCID %d: Received long BSR. Size is LCGID0 = %u LCGID1 = " - "%u LCGID2 = %u LCGID3 = %u\n", enb_mod_idP, - CC_idP, rx_ces[i], - UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID0], - UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID1], - UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID2], - UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID3]); - - if (UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID0] == 0) { - UE_list->UE_template[CC_idP][UE_id].ul_buffer_creation_time[LCGID0] = 0; - } else if (UE_list->UE_template[CC_idP][UE_id].ul_buffer_creation_time[LCGID0] == 0) { - UE_list->UE_template[CC_idP][UE_id].ul_buffer_creation_time[LCGID0] = frameP; - } - - if (UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID1] == 0) { - UE_list->UE_template[CC_idP][UE_id].ul_buffer_creation_time[LCGID1] = 0; - } else if (UE_list->UE_template[CC_idP][UE_id].ul_buffer_creation_time[LCGID1] == 0) { - UE_list->UE_template[CC_idP][UE_id].ul_buffer_creation_time[LCGID1] = frameP; - } - - if (UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID2] == 0) { - UE_list->UE_template[CC_idP][UE_id].ul_buffer_creation_time[LCGID2] = 0; - } else if (UE_list->UE_template[CC_idP][UE_id].ul_buffer_creation_time[LCGID2] == 0) { - UE_list->UE_template[CC_idP][UE_id].ul_buffer_creation_time[LCGID2] = frameP; + + LOG_D(MAC, "[eNB %d] CC_id %d MAC CE_LCID %d: Received long BSR. Size is LCGID0 = %u LCGID1 = %u LCGID2 = %u LCGID3 = %u\n", + enb_mod_idP, + CC_idP, + rx_ces[i], + UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID0], + UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID1], + UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID2], + UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID3]); + + if (crnti_rx == 1) { + LOG_D(MAC, "[eNB %d] CC_id %d MAC CE_LCID %d: Received CRNTI.\n", + enb_mod_idP, + CC_idP, + rx_ces[i]); } - - if (UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[LCGID3] == 0) { - UE_list->UE_template[CC_idP][UE_id].ul_buffer_creation_time[LCGID3] = 0; - } else if (UE_list->UE_template[CC_idP][UE_id].ul_buffer_creation_time[LCGID3] == 0) { - UE_list->UE_template[CC_idP][UE_id].ul_buffer_creation_time[LCGID3] = frameP; + + for(int lcgid = 0; lcgid <= LCGID3; lcgid++) { + if (UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[lcgid] == 0) { + UE_list->UE_template[CC_idP][UE_id].ul_buffer_creation_time[lcgid] = 0; + } else if (UE_list->UE_template[CC_idP][UE_id].ul_buffer_creation_time[lcgid] == 0) { + UE_list->UE_template[CC_idP][UE_id].ul_buffer_creation_time[lcgid] = frameP; + } } } - payload_ptr += 3; ////sizeof(LONG_BSR); + payload_ptr += 3; // sizeof(LONG_BSR) break; default: - LOG_E(MAC, - "[eNB %d] CC_id %d Received unknown MAC header (0x%02x)\n", - enb_mod_idP, CC_idP, rx_ces[i]); + LOG_E(MAC, "[eNB %d] CC_id %d Received unknown MAC header (0x%02x)\n", + enb_mod_idP, + CC_idP, + rx_ces[i]); + break; - } - } - for (i = 0; i < num_sdu; i++) { + } // end switch on control element + } // end for loop on control element + + for (int i = 0; i < num_sdu; i++) { LOG_D(MAC, "SDU Number %d MAC Subheader SDU_LCID %d, length %d\n", - i, rx_lcids[i], rx_lengths[i]); - T(T_ENB_MAC_UE_UL_SDU, T_INT(enb_mod_idP), T_INT(CC_idP), - T_INT(current_rnti), T_INT(frameP), T_INT(subframeP), - T_INT(rx_lcids[i]), T_INT(rx_lengths[i])); - T(T_ENB_MAC_UE_UL_SDU_WITH_DATA, T_INT(enb_mod_idP), T_INT(CC_idP), - T_INT(current_rnti), T_INT(frameP), T_INT(subframeP), - T_INT(rx_lcids[i]), T_INT(rx_lengths[i]), T_BUFFER(payload_ptr, - rx_lengths - [i])); + i, + rx_lcids[i], + rx_lengths[i]); + + T(T_ENB_MAC_UE_UL_SDU, + T_INT(enb_mod_idP), + T_INT(CC_idP), + T_INT(current_rnti), + T_INT(frameP), + T_INT(subframeP), + T_INT(rx_lcids[i]), + T_INT(rx_lengths[i])); + + T(T_ENB_MAC_UE_UL_SDU_WITH_DATA, + T_INT(enb_mod_idP), + T_INT(CC_idP), + T_INT(current_rnti), + T_INT(frameP), + T_INT(subframeP), + T_INT(rx_lcids[i]), + T_INT(rx_lengths[i]), + T_BUFFER(payload_ptr, rx_lengths[i])); switch (rx_lcids[i]) { - case CCCH: - if (rx_lengths[i] > CCCH_PAYLOAD_SIZE_MAX) { - LOG_E(MAC, - "[eNB %d/%d] frame %d received CCCH of size %d (too big, maximum allowed is %d, sdu_len %d), dropping packet\n", - enb_mod_idP, CC_idP, frameP, rx_lengths[i], - CCCH_PAYLOAD_SIZE_MAX, sdu_lenP); - break; - } - LOG_D(MAC, - "[eNB %d][RAPROC] CC_id %d Frame %d, Received CCCH: %x.%x.%x.%x.%x.%x, Terminating RA procedure for UE rnti %x\n", - enb_mod_idP, CC_idP, frameP, payload_ptr[0], - payload_ptr[1], payload_ptr[2], payload_ptr[3], - payload_ptr[4], payload_ptr[5], current_rnti); - VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_TERMINATE_RA_PROC, 1); - VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_TERMINATE_RA_PROC, 0); - for (ii = 0; ii < NB_RA_PROC_MAX; ii++) { - RA_t *ra = &mac->common_channels[CC_idP].ra[ii]; - - LOG_D(MAC, - "[mac %d][RAPROC] CC_id %d Checking proc %d : rnti (%x, %x), state %d\n", - enb_mod_idP, CC_idP, ii, ra->rnti, - current_rnti, ra->state); - - if ((ra->rnti == current_rnti) && (ra->state != IDLE)) { - - //payload_ptr = parse_ulsch_header(msg3,&num_ce,&num_sdu,rx_ces,rx_lcids,rx_lengths,msg3_len); - - if (UE_id < 0) { - memcpy(&ra->cont_res_id[0], payload_ptr, 6); - LOG_D(MAC, - "[eNB %d][RAPROC] CC_id %d Frame %d CCCH: Received Msg3: length %d, offset %ld\n", - enb_mod_idP, CC_idP, frameP, rx_lengths[i], - payload_ptr - sduP); - - if ((UE_id = add_new_ue(enb_mod_idP, CC_idP, - mac->common_channels[CC_idP]. - ra->rnti, harq_pid + case CCCH: + if (rx_lengths[i] > CCCH_PAYLOAD_SIZE_MAX) { + LOG_E(MAC, "[eNB %d/%d] frame %d received CCCH of size %d (too big, maximum allowed is %d, sdu_len %d), dropping packet\n", + enb_mod_idP, + CC_idP, + frameP, + rx_lengths[i], + CCCH_PAYLOAD_SIZE_MAX, + sdu_lenP); + + break; + } + + LOG_D(MAC, "[eNB %d][RAPROC] CC_id %d Frame %d, Received CCCH: %x.%x.%x.%x.%x.%x, Terminating RA procedure for UE rnti %x\n", + enb_mod_idP, + CC_idP, + frameP, + payload_ptr[0], payload_ptr[1], payload_ptr[2], payload_ptr[3], payload_ptr[4], payload_ptr[5], + current_rnti); + + VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_TERMINATE_RA_PROC, 1); + VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_TERMINATE_RA_PROC, 0); + + RA_id = find_RA_id(enb_mod_idP, CC_idP, current_rnti); + + if (RA_id != -1) { + RA_t *ra = &(mac->common_channels[CC_idP].ra[RA_id]); + + LOG_D(MAC, "[mac %d][RAPROC] CC_id %d Checking proc %d : rnti (%x, %x), state %d\n", + enb_mod_idP, + CC_idP, + RA_id, + ra->rnti, + current_rnti, + ra->state); + + if (UE_id < 0) { + memcpy(&(ra->cont_res_id[0]), payload_ptr, 6); + + LOG_D(MAC, "[eNB %d][RAPROC] CC_id %d Frame %d CCCH: Received Msg3: length %d, offset %ld\n", + enb_mod_idP, + CC_idP, + frameP, + rx_lengths[i], + payload_ptr - sduP); + + if ((UE_id = add_new_ue(enb_mod_idP, CC_idP, mac->common_channels[CC_idP].ra->rnti, harq_pid #if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0)) - , - mac->common_channels[CC_idP]. - ra->rach_resource_type + , mac->common_channels[CC_idP].ra->rach_resource_type #endif - )) == -1) { + )) == -1) { LOG_E(MAC,"[MAC][eNB] Max user count reached\n"); - cancel_ra_proc(enb_mod_idP, CC_idP, frameP,current_rnti); + + cancel_ra_proc(enb_mod_idP, CC_idP, frameP, current_rnti); // send Connection Reject ??? + break; - // kill RA procedure - } else - LOG_D(MAC, - "[eNB %d][RAPROC] CC_id %d Frame %d Added user with rnti %x => UE %d\n", - enb_mod_idP, CC_idP, frameP, ra->rnti, - UE_id); - } else { - LOG_D(MAC, - "[eNB %d][RAPROC] CC_id %d Frame %d CCCH: Received Msg3 from already registered UE %d: length %d, offset %ld\n", - enb_mod_idP, CC_idP, frameP, UE_id, - rx_lengths[i], payload_ptr - sduP); - // kill RA procedure - } - - mac_rrc_data_ind(enb_mod_idP, - CC_idP, - frameP, subframeP, - current_rnti, - CCCH, - (uint8_t *) payload_ptr, - rx_lengths[i], - 0 + // kill RA proc + } else { + LOG_D(MAC, "[eNB %d][RAPROC] CC_id %d Frame %d Added user with rnti %x => UE %d\n", + enb_mod_idP, + CC_idP, + frameP, + ra->rnti, + UE_id); + } + } else { + LOG_D(MAC, "[eNB %d][RAPROC] CC_id %d Frame %d CCCH: Received Msg3 from already registered UE %d: length %d, offset %ld\n", + enb_mod_idP, + CC_idP, + frameP, + UE_id, + rx_lengths[i], + payload_ptr - sduP); + // kill RA proc + } + + mac_rrc_data_ind(enb_mod_idP, + CC_idP, + frameP, subframeP, + current_rnti, + CCCH, + (uint8_t *) payload_ptr, + rx_lengths[i], + 0 #if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0)) - ,ra->rach_resource_type>0 + ,ra->rach_resource_type > 0 #endif - ); - - - if (num_ce > 0) { // handle msg3 which is not RRCConnectionRequest - // process_ra_message(msg3,num_ce,rx_lcids,rx_ces); - } - // prepare transmission of Msg4 - ra->state = MSG4; - - if(mac->common_channels[CC_idP].tdd_Config!=NULL) { - switch(mac->common_channels[CC_idP].tdd_Config->subframeAssignment) { - case 1: - ra->Msg4_frame = frameP + ((subframeP > 2) ? 1 : 0); - ra->Msg4_subframe = (subframeP + 7) % 10; - break; - - default: - printf("%s:%d: TODO\n", __FILE__, __LINE__); - abort(); - // TODO need to be complete for other tdd configs. - } - } else { - // Program Msg4 PDCCH+DLSCH/MPDCCH transmission 4 subframes from now, // Check if this is ok for BL/CE, or if the rule is different - ra->Msg4_frame = frameP + ((subframeP > 5) ? 1 : 0); - ra->Msg4_subframe = (subframeP + 4) % 10; - } - - UE_list->UE_sched_ctrl[UE_id].crnti_reconfigurationcomplete_flag = 0; - } // if process is active - } // loop on RA processes + ); + + if (num_ce > 0) { // handle msg3 which is not RRCConnectionRequest + // process_ra_message(msg3,num_ce,rx_lcids,rx_ces); + } + + // prepare transmission of Msg4 + ra->state = MSG4; + + if(mac->common_channels[CC_idP].tdd_Config != NULL) { + switch(mac->common_channels[CC_idP].tdd_Config->subframeAssignment) { + case 1: + ra->Msg4_frame = frameP + ((subframeP > 2) ? 1 : 0); + ra->Msg4_subframe = (subframeP + 7) % 10; + break; + + default: + printf("%s:%d: TODO\n", __FILE__, __LINE__); + abort(); + // TODO need to be complete for other tdd configs. + } + } else { + /* Program Msg4 PDCCH+DLSCH/MPDCCH transmission 4 subframes from now, + * Check if this is ok for BL/CE, or if the rule is different + */ + ra->Msg4_frame = frameP + ((subframeP > 5) ? 1 : 0); + ra->Msg4_subframe = (subframeP + 4) % 10; + } + + UE_list->UE_sched_ctrl[UE_id].crnti_reconfigurationcomplete_flag = 0; + } // if RA process is active + + break; + + case DCCH: + + case DCCH1: - break; - - case DCCH: - case DCCH1: - // if(eNB_mac_inst[module_idP][CC_idP].Dcch_lchan[UE_id].Active==1){ #if defined(ENABLE_MAC_PAYLOAD_DEBUG) - LOG_T(MAC, "offset: %d\n", - (unsigned char) ((unsigned char *) payload_ptr - sduP)); + LOG_T(MAC, "offset: %d\n", (unsigned char) ((unsigned char *) payload_ptr - sduP)); - for (j = 0; j < 32; j++) { + for (int j = 0; j < 32; j++) { LOG_T(MAC, "%x ", payload_ptr[j]); } @@ -647,7 +777,7 @@ rx_sdu(const module_id_t enb_mod_idP, if (UE_id != -1) { if (lcgid_updated[UE_list->UE_template[CC_idP][UE_id].lcgidmap[rx_lcids[i]]] == 0) { - // adjust buffer occupancy of the correponding logical channel group + /* Adjust buffer occupancy of the correponding logical channel group */ if (UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[UE_list->UE_template[CC_idP][UE_id].lcgidmap[rx_lcids[i]]] >= rx_lengths[i]) UE_list->UE_template[CC_idP][UE_id].ul_buffer_info[UE_list->UE_template[CC_idP][UE_id].lcgidmap[rx_lcids[i]]] -= rx_lengths[i]; else @@ -670,8 +800,6 @@ rx_sdu(const module_id_t enb_mod_idP, UE_list->eNB_UE_stats[CC_idP][UE_id].num_bytes_rx[rx_lcids[i]] += rx_lengths[i]; } - /* UE_id != -1 */ - // } break; // all the DRBS @@ -681,7 +809,7 @@ rx_sdu(const module_id_t enb_mod_idP, LOG_T(MAC, "offset: %d\n", (unsigned char) ((unsigned char *) payload_ptr - sduP)); - for (j = 0; j < 32; j++) { + for (int j = 0; j < 32; j++) { LOG_T(MAC, "%x ", payload_ptr[j]); } @@ -698,7 +826,7 @@ rx_sdu(const module_id_t enb_mod_idP, rx_lcids[i]); if (UE_id != -1) { - // adjust buffer occupancy of the correponding logical channel group + /* Adjust buffer occupancy of the correponding logical channel group */ LOG_D(MAC, "[eNB %d] CC_id %d Frame %d : ULSCH -> UL-DTCH, received %d bytes from UE %d for lcid %d, removing from LCGID %ld, %d\n", enb_mod_idP, CC_idP, @@ -727,9 +855,11 @@ rx_sdu(const module_id_t enb_mod_idP, mac_rlc_data_ind(enb_mod_idP, current_rnti, enb_mod_idP, frameP, ENB_FLAG_YES, MBMS_FLAG_NO, rx_lcids[i], (char *) payload_ptr, rx_lengths[i], 1, NULL); UE_list->eNB_UE_stats[CC_idP][UE_id].num_pdu_rx[rx_lcids[i]] += 1; UE_list->eNB_UE_stats[CC_idP][UE_id].num_bytes_rx[rx_lcids[i]] += rx_lengths[i]; - //clear uplane_inactivity_timer + + /* Clear uplane_inactivity_timer */ UE_list->UE_sched_ctrl[UE_id].uplane_inactivity_timer = 0; - // reset RRC inactivity timer after uplane activity + + /* Reset RRC inactivity timer after uplane activity */ ue_contextP = rrc_eNB_get_ue_context(RC.rrc[enb_mod_idP], current_rnti); if (ue_contextP != NULL) { ue_contextP->ue_context.ue_rrc_inactivity_timer = 1; @@ -739,8 +869,10 @@ rx_sdu(const module_id_t enb_mod_idP, CC_idP, current_rnti); } - } else { /* rx_length[i] */ + + } else { /* rx_length[i] Max size */ UE_list->eNB_UE_stats[CC_idP][UE_id].num_errors_rx += 1; + LOG_E(MAC, "[eNB %d] CC_id %d Frame %d : Max size of transport block reached LCID %d from UE %d ", enb_mod_idP, CC_idP, @@ -757,24 +889,29 @@ rx_sdu(const module_id_t enb_mod_idP, UE_id); } } - break; } payload_ptr += rx_lengths[i]; } - // Program ACK for PHICH - LOG_D(MAC, - "Programming PHICH ACK for rnti %x harq_pid %d (first_rb %d)\n", - current_rnti, harq_pid, first_rb); + /* Program ACK for PHICH */ + LOG_D(MAC, "Programming PHICH ACK for rnti %x harq_pid %d (first_rb %d)\n", + current_rnti, + harq_pid, + first_rb); + nfapi_hi_dci0_request_t *hi_dci0_req; + uint8_t sf_ahead_dl = ul_subframe2_k_phich(&mac->common_channels[CC_idP], subframeP); + hi_dci0_req = &mac->HI_DCI0_req[CC_idP][(subframeP+sf_ahead_dl)%10]; nfapi_hi_dci0_request_body_t *hi_dci0_req_body = &hi_dci0_req->hi_dci0_request_body; - nfapi_hi_dci0_request_pdu_t *hi_dci0_pdu = - &hi_dci0_req_body->hi_dci0_pdu_list[hi_dci0_req_body->number_of_dci + hi_dci0_req_body->number_of_hi]; + nfapi_hi_dci0_request_pdu_t *hi_dci0_pdu = &hi_dci0_req_body->hi_dci0_pdu_list[hi_dci0_req_body->number_of_dci + + hi_dci0_req_body->number_of_hi]; + memset((void *) hi_dci0_pdu, 0, sizeof(nfapi_hi_dci0_request_pdu_t)); + hi_dci0_pdu->pdu_type = NFAPI_HI_DCI0_HI_PDU_TYPE; hi_dci0_pdu->pdu_size = 2 + sizeof(nfapi_hi_dci0_hi_pdu); hi_dci0_pdu->hi_pdu.hi_pdu_rel8.tl.tag = NFAPI_HI_DCI0_REQUEST_HI_PDU_REL8_TAG; @@ -792,13 +929,6 @@ rx_sdu(const module_id_t enb_mod_idP, if (UE_id != -1) UE_list->eNB_UE_stats[CC_idP][UE_id].total_num_errors_rx += 1; - /* - if (msg3_flagP != NULL) { - if( *msg3_flagP == 1 ) { - LOG_I(MAC,"[eNB %d] CC_id %d frame %d : false msg3 detection: signal phy to canceling RA and remove the UE\n", enb_mod_idP, CC_idP, frameP); - *msg3_flagP=0; - } - } */ } else { if (UE_id != -1) { UE_list->eNB_UE_stats[CC_idP][UE_id].pdu_bytes_rx = sdu_lenP; @@ -811,7 +941,14 @@ rx_sdu(const module_id_t enb_mod_idP, stop_meas(&mac->rx_ulsch_sdu); } -uint32_t bytes_to_bsr_index(int32_t nbytes) { +//----------------------------------------------------------------------------- +/* + * Return the BSR table index corresponding to the number of bytes in input + */ +uint32_t +bytes_to_bsr_index(int32_t nbytes) +//----------------------------------------------------------------------------- +{ uint32_t i = 0; if (nbytes < 0) { @@ -825,27 +962,49 @@ uint32_t bytes_to_bsr_index(int32_t nbytes) { return (i - 1); } +//----------------------------------------------------------------------------- +/* + * Add ue info in eNB_ulsch_info[module_idP][CC_id][UE_id] struct + */ void -add_ue_ulsch_info(module_id_t module_idP, int CC_id, int UE_id, - sub_frame_t subframeP, UE_ULSCH_STATUS status) { +add_ue_ulsch_info(module_id_t module_idP, + int CC_id, + int UE_id, + sub_frame_t subframeP, + UE_ULSCH_STATUS status) +//----------------------------------------------------------------------------- +{ eNB_ulsch_info[module_idP][CC_id][UE_id].rnti = UE_RNTI(module_idP, UE_id); eNB_ulsch_info[module_idP][CC_id][UE_id].subframe = subframeP; eNB_ulsch_info[module_idP][CC_id][UE_id].status = status; eNB_ulsch_info[module_idP][CC_id][UE_id].serving_num++; } -unsigned char *parse_ulsch_header(unsigned char *mac_header, - unsigned char *num_ce, - unsigned char *num_sdu, - unsigned char *rx_ces, - unsigned char *rx_lcids, - unsigned short *rx_lengths, - unsigned short tb_length) { - unsigned char not_done = 1, num_ces = 0, num_sdus = - 0, lcid, num_sdu_cnt; - unsigned char *mac_header_ptr = mac_header; +//----------------------------------------------------------------------------- +/* + * Parse MAC header from ULSCH + */ +unsigned char * +parse_ulsch_header(unsigned char *mac_header, + unsigned char *num_ce, + unsigned char *num_sdu, + unsigned char *rx_ces, + unsigned char *rx_lcids, + unsigned short *rx_lengths, + unsigned short tb_length) +//----------------------------------------------------------------------------- +{ + unsigned char not_done = 1; + unsigned char num_ces = 0; + unsigned char num_sdus = 0; + unsigned char lcid = 0; + unsigned char num_sdu_cnt = 0; + unsigned char *mac_header_ptr = NULL; unsigned short length, ce_len = 0; + /* Init */ + mac_header_ptr = mac_header; + while (not_done == 1) { if (((SCH_SUBHEADER_FIXED *) mac_header_ptr)->E == 0) { not_done = 0; @@ -858,8 +1017,7 @@ unsigned char *parse_ulsch_header(unsigned char *mac_header, mac_header_ptr++; length = tb_length - (mac_header_ptr - mac_header) - ce_len; - for (num_sdu_cnt = 0; num_sdu_cnt < num_sdus; - num_sdu_cnt++) { + for (num_sdu_cnt = 0; num_sdu_cnt < num_sdus; num_sdu_cnt++) { length -= rx_lengths[num_sdu_cnt]; } } else { @@ -867,22 +1025,24 @@ unsigned char *parse_ulsch_header(unsigned char *mac_header, length = ((SCH_SUBHEADER_SHORT *) mac_header_ptr)->L; mac_header_ptr += 2; //sizeof(SCH_SUBHEADER_SHORT); } else { // F = 1 - length = - ((((SCH_SUBHEADER_LONG *) mac_header_ptr)->L_MSB & - 0x7f) << 8) | (((SCH_SUBHEADER_LONG *) - mac_header_ptr)->L_LSB & 0xff); + length = ((((SCH_SUBHEADER_LONG *) mac_header_ptr)->L_MSB & 0x7f) << 8) | + (((SCH_SUBHEADER_LONG *) mac_header_ptr)->L_LSB & 0xff); mac_header_ptr += 3; //sizeof(SCH_SUBHEADER_LONG); } } - LOG_D(MAC, - "[eNB] sdu %d lcid %d tb_length %d length %d (offset now %ld)\n", - num_sdus, lcid, tb_length, length, - mac_header_ptr - mac_header); + LOG_D(MAC, "[eNB] sdu %d lcid %d tb_length %d length %d (offset now %ld)\n", + num_sdus, + lcid, + tb_length, + length, + mac_header_ptr - mac_header); + rx_lcids[num_sdus] = lcid; rx_lengths[num_sdus] = length; num_sdus++; - } else { // This is a control element subheader POWER_HEADROOM, BSR and CRNTI + + } else { // This is a control element subheader POWER_HEADROOM, BSR and CRNTI if (lcid == SHORT_PADDING) { mac_header_ptr++; } else { @@ -894,13 +1054,10 @@ unsigned char *parse_ulsch_header(unsigned char *mac_header, ce_len += 3; } else if (lcid == CRNTI) { ce_len += 2; - } else if ((lcid == POWER_HEADROOM) - || (lcid == TRUNCATED_BSR) - || (lcid == SHORT_BSR)) { + } else if ((lcid == POWER_HEADROOM) || (lcid == TRUNCATED_BSR) || (lcid == SHORT_BSR)) { ce_len++; } else { LOG_E(MAC, "unknown CE %d \n", lcid); - //AssertFatal(1 == 0, "unknown CE"); return NULL; } } @@ -912,47 +1069,72 @@ unsigned char *parse_ulsch_header(unsigned char *mac_header, return (mac_header_ptr); } +//----------------------------------------------------------------------------- /* This function is called by PHY layer when it schedules some * uplink for a random access message 3. * The MAC scheduler has to skip the RBs used by this message 3 * (done below in schedule_ulsch). + * This function seems to be unused, the Msg3_subframe is set somewhere else... + * In NFAPI?? */ void set_msg3_subframe(module_id_t mod_id, - int CC_id, - int frame, - int subframe, int rnti, int Msg3_frame, - int Msg3_subframe) { - eNB_MAC_INST *mac = RC.mac[mod_id]; - int i; - - for (i = 0; i < NB_RA_PROC_MAX; i++) { - if (mac->common_channels[CC_id].ra[i].state != IDLE && - mac->common_channels[CC_id].ra[i].rnti == rnti) { - mac->common_channels[CC_id].ra[i].Msg3_subframe = - Msg3_subframe; - break; - } + int CC_id, + int frame, // Not used, remove? + int subframe, // Not used, remove? + int rnti, + int Msg3_frame, // Not used, remove? + int Msg3_subframe) +//----------------------------------------------------------------------------- +{ + int RA_id = 0; + + /* Init */ + RA_id = find_RA_id(mod_id, CC_id, rnti); // state == WAITMSG3 instead of state != IDLE (?) + + if (RA_id != -1) { + RC.mac[mod_id]->common_channels[CC_id].ra[RA_id].Msg3_subframe = Msg3_subframe; + } else { + LOG_E(MAC, "[MAC] Unknown RAPROC associated to RNTI %x\n", rnti); } + + return; } +//----------------------------------------------------------------------------- +/* + * Main function called for uplink scheduling (DCI0). + */ void -schedule_ulsch(module_id_t module_idP, frame_t frameP, - sub_frame_t subframeP) { - uint16_t first_rb[NFAPI_CC_MAX], i; - int CC_id; - eNB_MAC_INST *mac = RC.mac[module_idP]; - slice_info_t *sli = &RC.mac[module_idP]->slice_info; - COMMON_channels_t *cc; - start_meas(&mac->schedule_ulsch); - int sched_frame=frameP; - int sched_subframe = (subframeP + 4) % 10; - cc = &mac->common_channels[0]; - int tdd_sfa; - - // for TDD: check subframes where we have to act and return if nothing should be done now - if (cc->tdd_Config) { - tdd_sfa = cc->tdd_Config->subframeAssignment; +schedule_ulsch(module_id_t module_idP, + frame_t frameP, + sub_frame_t subframeP) +//----------------------------------------------------------------------------- +{ + uint16_t first_rb[NFAPI_CC_MAX]; + eNB_MAC_INST *mac = NULL; + slice_info_t *sli = NULL; + COMMON_channels_t *cc = NULL; + + /* Init */ + mac = RC.mac[module_idP]; + sli = &(mac->slice_info); + memset(first_rb, 0, NFAPI_CC_MAX * sizeof(uint16_t)); + + start_meas(&(mac->schedule_ulsch)); + + /* Second setup step */ + int sched_subframe = 0; + int sched_frame = 0; + + /* Second init step */ + sched_subframe = (subframeP + 4) % 10; + sched_frame = frameP; + cc = mac->common_channels; + + /* For TDD: check subframes where we have to act and return if nothing should be done now */ + if (cc->tdd_Config) { // Done only for CC_id = 0, assume tdd_Config for all CC_id + int tdd_sfa = cc->tdd_Config->subframeAssignment; switch (subframeP) { case 0: @@ -975,10 +1157,7 @@ schedule_ulsch(module_id_t module_idP, frame_t frameP, break; - default: - return; - - case 2: // Don't schedule UL in subframe 2 for TDD + case 2: // Don't schedule UL in subframe 2 for TDD return; case 3: @@ -1037,260 +1216,305 @@ schedule_ulsch(module_id_t module_idP, frame_t frameP, return; break; + + default: + return; } } + if (sched_subframe < subframeP) { + sched_frame++; + } #if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0)) - int emtc_active[5]; - memset(emtc_active,0,5*sizeof(int)); + int emtc_active[5]; + memset(emtc_active, 0, 5 * sizeof(int)); schedule_ulsch_rnti_emtc(module_idP, frameP, subframeP, sched_subframe, emtc_active); #endif - if (sched_subframe < subframeP) sched_frame++; - - - //leave out first RB for PUCCH and first narrowband if emtc - for (CC_id = 0; CC_id < RC.nb_mac_CC[module_idP]; CC_id++) { - //leave out first RB for PUCCH - first_rb[CC_id] = 1; + /* Note: RC.nb_mac_CC[module_idP] should be lower than or equal to NFAPI_CC_MAX */ + for (int CC_id = 0; CC_id < RC.nb_mac_CC[module_idP]; CC_id++, cc++) { + first_rb[CC_id] = 1; // leave out first RB for PUCCH #if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0)) first_rb[CC_id] = (emtc_active[CC_id] == 1) ? 7 : 1; #else first_rb[CC_id] = 1; #endif - // UE data info; - // check which UE has data to transmit - // function to decide the scheduling - // e.g. scheduling_rslt = Greedy(granted_UEs, nb_RB) - - // default function for default scheduling - // - - // output of scheduling, the UE numbers in RBs, where it is in the code??? - // check if RA (Msg3) is active in this subframeP, if so skip the PRBs used for Msg3 - // Msg3 is using 1 PRB so we need to increase first_rb accordingly - // not sure about the break (can there be more than 1 active RA procedure?) - - for (i = 0; i < NB_RA_PROC_MAX; i++) { - if ((cc->ra[i].state == WAITMSG3) && - (cc->ra[i].Msg3_subframe == sched_subframe)) { - if (first_rb[CC_id] < cc->ra[i].msg3_first_rb + cc->ra[i].msg3_nb_rb) - first_rb[CC_id] = cc->ra[i].msg3_first_rb + cc->ra[i].msg3_nb_rb; - - // cc->ray[i].Msg3_subframe = -1; - break; + + RA_t *ra_ptr = cc->ra; + + /* From Louis-Adrien to François: + * The comment bloc below is to configure with a command line. + * I took it from the equivalent part in the fairRR scheduler (around line 2578 in eNB_scheduler_fairRR.c). + * As said in the meeting, it seems to work only for small TBS. + * The cause of false RA still present with this fix is to investigate. + * + * Note: in the get_prach_prb_offset() function below, the last argument is frameP in eNB_scheduler_fairRR.c + * I think it should be sched_frame instead. This parameter has only impacts in case TDD and preamble format 4. + * To confirm. + */ + /* + int start_rb = 0; + int nb_rb = 6; + LTE_DL_FRAME_PARMS *frame_parms = &(RC.eNB[module_idP][CC_id]->frame_parms); + + if (is_prach_subframe(frame_parms, sched_frame, sched_subframe) == 1) { + start_rb = get_prach_prb_offset(frame_parms, + frame_parms->prach_config_common.prach_ConfigInfo.prach_ConfigIndex, + frame_parms->prach_config_common.prach_ConfigInfo.prach_FreqOffset, + 0, // tdd_mapindex + sched_frame); // Nf + + first_rb[CC_id] = start_rb + nb_rb; + } + */ + + /* + * Check if RA (Msg3) is active in this subframeP, if so skip the PRB used for Msg3 + * Msg3 is using 1 PRB so we need to increase first_rb accordingly + * Not sure about the break (can there be more than 1 active RA procedure per CC_id and per subframe?) + */ + for (int ra_index = 0; ra_index < NB_RA_PROC_MAX; ra_index++, ra_ptr++) { + if ((ra_ptr->state == WAITMSG3) && (ra_ptr->Msg3_subframe == sched_subframe)) { + if (first_rb[CC_id] < ra_ptr->msg3_first_rb + ra_ptr->msg3_nb_rb) { + first_rb[CC_id] = ra_ptr->msg3_first_rb + ra_ptr->msg3_nb_rb; + } + /* Louis-Adrien: I couldn't find an interdiction of multiple Msg3 scheduling + * on the same time resources. Also the performance improvement of breaking is low, + * since we will loop until the end, most of the time. + * I'm letting the break as a reminder, in case of misunderstanding the spec. + */ + // break; } } } - for (i = 0; i < sli->n_ul; i++) { - // Run each enabled slice-specific schedulers one by one + /* Run each enabled slice-specific schedulers one by one */ + for (int i = 0; i < sli->n_ul; i++) { + /* By default the scheduler is schedule_ulsch_rnti (see below) */ sli->ul[i].sched_cb(module_idP, i, frameP, subframeP, sched_subframe, first_rb); } stop_meas(&mac->schedule_ulsch); } - -void schedule_ulsch_rnti(module_id_t module_idP, - int slice_idx, - frame_t frameP, - sub_frame_t subframeP, - unsigned char sched_subframeP, uint16_t * first_rb) +//----------------------------------------------------------------------------- +/* + * Default scheduler for ULSCH (DCI0) + */ +void +schedule_ulsch_rnti(module_id_t module_idP, + int slice_idx, + frame_t frameP, + sub_frame_t subframeP, + unsigned char sched_subframeP, + uint16_t *first_rb) +//----------------------------------------------------------------------------- { - int UE_id; - uint8_t aggregation = 2; rnti_t rnti = -1; - uint8_t round = 0; + uint8_t aggregation = 2; + uint8_t round_index = 0; uint8_t harq_pid = 0; uint8_t status = 0; uint8_t rb_table_index = -1; - uint32_t cqi_req, cshift, ndi, tpc; - int32_t normalized_rx_power, target_rx_power; + uint8_t dlsch_flag = 0; + uint16_t ul_req_index = 0; + uint32_t cqi_req = 0; + uint32_t cshift = 0; + uint32_t ndi = 0; + uint32_t tpc = 0; + int32_t normalized_rx_power = 0; + int32_t target_rx_power = 0; + int32_t framex10psubframe = 0; static int32_t tpc_accumulated = 0; - int n; + int sched_frame = 0; int CC_id = 0; - int drop_ue = 0; - int N_RB_UL; - eNB_MAC_INST *mac = RC.mac[module_idP]; - COMMON_channels_t *cc = mac->common_channels; - UE_list_t *UE_list = &mac->UE_list; - slice_info_t *sli = &RC.mac[module_idP]->slice_info; - UE_TEMPLATE *UE_template; - UE_sched_ctrl *UE_sched_ctrl; - int sched_frame = frameP; - int rvidx_tab[4] = { 0, 2, 3, 1 }; - uint16_t ul_req_index; - uint8_t dlsch_flag; + eNB_MAC_INST *mac = NULL; + COMMON_channels_t *cc = NULL; + UE_list_t *UE_list = NULL; + slice_info_t *sli = NULL; + UE_TEMPLATE *UE_template_ptr = NULL; + UE_sched_ctrl *UE_sched_ctrl_ptr = NULL; + int rvidx_tab[4] = {0, 2, 3, 1}; int first_rb_slice[NFAPI_CC_MAX]; - - if (sched_subframeP < subframeP) + int n_rb_ul_tab[NFAPI_CC_MAX]; + + /* Init */ + mac = RC.mac[module_idP]; + cc = mac->common_channels; + UE_list = &(mac->UE_list); + sli = &(mac->slice_info); + memset(first_rb_slice, 0, NFAPI_CC_MAX * sizeof(int)); + memset(n_rb_ul_tab, 0, NFAPI_CC_MAX * sizeof(int)); + sched_frame = frameP; + + if (sched_subframeP < subframeP) { sched_frame++; + } - nfapi_hi_dci0_request_t *hi_dci0_req = &mac->HI_DCI0_req[CC_id][subframeP]; - nfapi_hi_dci0_request_body_t *hi_dci0_req_body = &hi_dci0_req->hi_dci0_request_body; + /* NFAPI struct init */ + nfapi_hi_dci0_request_t *hi_dci0_req = &(mac->HI_DCI0_req[CC_id][subframeP]); + nfapi_hi_dci0_request_body_t *hi_dci0_req_body = &(hi_dci0_req->hi_dci0_request_body); nfapi_hi_dci0_request_pdu_t *hi_dci0_pdu; - nfapi_ul_config_request_t *ul_req_tmp = &mac->UL_req_tmp[CC_id][sched_subframeP]; - nfapi_ul_config_request_body_t *ul_req_tmp_body = &ul_req_tmp->ul_config_request_body; + nfapi_ul_config_request_t *ul_req_tmp = &(mac->UL_req_tmp[CC_id][sched_subframeP]); + nfapi_ul_config_request_body_t *ul_req_tmp_body = &(ul_req_tmp->ul_config_request_body); nfapi_ul_config_ulsch_harq_information *ulsch_harq_information; - for (CC_id = 0; CC_id < RC.nb_mac_CC[module_idP]; ++CC_id) { - N_RB_UL = to_prb(cc[CC_id].ul_Bandwidth); - UE_list->first_rb_offset[CC_id][slice_idx] = cmin(N_RB_UL, sli->ul[slice_idx].first_rb); + hi_dci0_req->sfn_sf = (frameP << 4) + subframeP; + + /* Note: RC.nb_mac_CC[module_idP] should be lower than or equal to NFAPI_CC_MAX */ + for (CC_id = 0; CC_id < RC.nb_mac_CC[module_idP]; CC_id++) { + n_rb_ul_tab[CC_id] = to_prb(cc[CC_id].ul_Bandwidth); // return total number of PRB + UE_list->first_rb_offset[CC_id][slice_idx] = cmin(n_rb_ul_tab[CC_id], sli->ul[slice_idx].first_rb); } - //LOG_D(MAC, "entering ulsch preprocesor\n"); + /* ULSCH preprocessor: set UE_template-> + * pre_allocated_nb_rb_ul[slice_idx] + * pre_assigned_mcs_ul + * pre_allocated_rb_table_index_ul + */ ulsch_scheduler_pre_processor(module_idP, slice_idx, frameP, subframeP, sched_subframeP, first_rb); - for (CC_id = 0; CC_id < RC.nb_mac_CC[module_idP]; ++CC_id) { + for (CC_id = 0; CC_id < RC.nb_mac_CC[module_idP]; CC_id++) { first_rb_slice[CC_id] = first_rb[CC_id] + UE_list->first_rb_offset[CC_id][slice_idx]; } - //LOG_D(MAC, "exiting ulsch preprocesor\n"); - hi_dci0_req->sfn_sf = (frameP << 4) + subframeP; - - // loop over all active UEs - for (UE_id = UE_list->head_ul; UE_id >= 0; - UE_id = UE_list->next_ul[UE_id]) { - if (!ue_ul_slice_membership(module_idP, UE_id, slice_idx)) + // loop over all active UEs until end of function + for (int UE_id = UE_list->head_ul; UE_id >= 0; UE_id = UE_list->next_ul[UE_id]) { + if (!ue_ul_slice_membership(module_idP, UE_id, slice_idx)) { continue; + } + + // don't schedule if Msg5 is not received yet + if (UE_list->UE_template[UE_PCCID(module_idP, UE_id)][UE_id].configured == FALSE) { + LOG_D(MAC, "[eNB %d] frame %d, subframe %d, UE %d: not configured, skipping UE scheduling \n", + module_idP, + frameP, + subframeP, + UE_id); - // don't schedule if Msg4 is not received yet - if (UE_list->UE_template[UE_PCCID(module_idP, UE_id)][UE_id]. - configured == FALSE) { - LOG_D(MAC, - "[eNB %d] frame %d subfarme %d, UE %d: not configured, skipping UE scheduling \n", - module_idP, frameP, subframeP, UE_id); continue; } rnti = UE_RNTI(module_idP, UE_id); if (rnti == NOT_A_RNTI) { - LOG_W(MAC, "[eNB %d] frame %d subfarme %d, UE %d: no RNTI \n", - module_idP, frameP, subframeP, UE_id); - continue; - } - - drop_ue = 0; - - /* let's drop the UE if get_eNB_UE_stats returns NULL when calling it with any of the UE's active UL CCs */ - /* TODO: refine? - - for (n=0; n<UE_list->numactiveULCCs[UE_id]; n++) { - CC_id = UE_list->ordered_ULCCids[n][UE_id]; - - if (mac_xface->get_eNB_UE_stats(module_idP,CC_id,rnti) == NULL) { - LOG_W(MAC,"[eNB %d] frame %d subframe %d, UE %d/%x CC %d: no PHY context\n", module_idP,frameP,subframeP,UE_id,rnti,CC_id); - drop_ue = 1; - break; - } - } */ - if (drop_ue == 1) { - /* we can't come here, ulsch_scheduler_pre_processor won't put in the list a UE with no PHY context */ - abort(); - - /* TODO: this is a hack. Sometimes the UE has no PHY context but - * is still present in the MAC with 'ul_failure_timer' = 0 and - * 'ul_out_of_sync' = 0. It seems wrong and the UE stays there forever. Let's - * start an UL out of sync procedure in this case. - * The root cause of this problem has to be found and corrected. - * In the meantime, this hack... - */ - if (UE_list->UE_sched_ctrl[UE_id].ul_failure_timer == 0 && - UE_list->UE_sched_ctrl[UE_id].ul_out_of_sync == 0) { - LOG_W(MAC, - "[eNB %d] frame %d subframe %d, UE %d/%x CC %d: UE in weird state, let's put it 'out of sync'\n", - module_idP, frameP, subframeP, UE_id, rnti, CC_id); - // inform RRC of failure and clear timer - mac_eNB_rrc_ul_failure(module_idP, CC_id, frameP, - subframeP, rnti); - UE_list->UE_sched_ctrl[UE_id].ul_failure_timer = 0; - UE_list->UE_sched_ctrl[UE_id].ul_out_of_sync = 1; - } + LOG_W(MAC, "[eNB %d] frame %d, subframe %d, UE %d: no RNTI \n", + module_idP, + frameP, + subframeP, + UE_id); continue; } - // loop over all active UL CC_ids for this UE - for (n = 0; n < UE_list->numactiveULCCs[UE_id]; n++) { - // This is the actual CC_id in the list + // loop over all active UL CC_ids for this UE until end of function + for (int n = 0; n < UE_list->numactiveULCCs[UE_id]; n++) { + /* This is the actual CC_id in the list */ CC_id = UE_list->ordered_ULCCids[n][UE_id]; - N_RB_UL = to_prb(cc[CC_id].ul_Bandwidth); - - /* - aggregation=get_aggregation(get_bw_index(module_idP,CC_id), - eNB_UE_stats->dl_cqi, - format0); - */ - - if (CCE_allocation_infeasible - (module_idP, CC_id, 1, subframeP, aggregation, rnti)) { - LOG_W(MAC, - "[eNB %d] frame %d subframe %d, UE %d/%x CC %d: not enough nCCE\n", - module_idP, frameP, subframeP, UE_id, rnti, CC_id); - continue; // break; - } - /* be sure that there are some free RBs */ - if (first_rb_slice[CC_id] >= N_RB_UL - 1) { - LOG_W(MAC, - "[eNB %d] frame %d subframe %d, UE %d/%x CC %d: dropping, not enough RBs\n", - module_idP, frameP, subframeP, UE_id, rnti, CC_id); + /* Be sure that there are some free RBs */ + if (first_rb_slice[CC_id] >= n_rb_ul_tab[CC_id] - 1) { + LOG_W(MAC, "[eNB %d] frame %d, subframe %d, UE %d/%x CC %d: dropping, not enough RBs\n", + module_idP, + frameP, + subframeP, + UE_id, + rnti, + CC_id); + continue; } - // if (eNB_UE_stats->mode == PUSCH) { // ue has a ulsch channel - UE_template = &UE_list->UE_template[CC_id][UE_id]; - UE_sched_ctrl = &UE_list->UE_sched_ctrl[UE_id]; + /* Should format_flag be 2 in CCE_allocation_infeasible??? */ + /* This test seems to be way too long, can we provide an optimization? */ + if (CCE_allocation_infeasible(module_idP, CC_id, 1, subframeP, aggregation, rnti)) { + LOG_W(MAC, "[eNB %d] frame %d, subframe %d, UE %d/%x CC %d: not enough CCE\n", + module_idP, + frameP, + subframeP, + UE_id, + rnti, + CC_id); + + continue; + } + + /* UE is active and can be scheduled, setting up struct */ + UE_template_ptr = &(UE_list->UE_template[CC_id][UE_id]); + UE_sched_ctrl_ptr = &(UE_list->UE_sched_ctrl[UE_id]); harq_pid = subframe2harqpid(&cc[CC_id], sched_frame, sched_subframeP); - round = UE_sched_ctrl->round_UL[CC_id][harq_pid]; - AssertFatal(round < 8, "round %d > 7 for UE %d/%x\n", round, - UE_id, rnti); - LOG_D(MAC, - "[eNB %d] frame %d subframe %d (sched_frame %d, sched_subframe %d), Checking PUSCH %d for UE %d/%x CC %d : aggregation level %d, N_RB_UL %d\n", - module_idP, frameP, subframeP, sched_frame, sched_subframeP, harq_pid, UE_id, rnti, - CC_id, aggregation, N_RB_UL); - RC.eNB[module_idP][CC_id]->pusch_stats_BO[UE_id][(frameP * 10) + subframeP] = UE_template->estimated_ul_buffer; - VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLES_UE0_BO,RC.eNB[module_idP][CC_id]->pusch_stats_BO[UE_id][(frameP * - 10) + - subframeP]); - - if (UE_is_to_be_scheduled(module_idP, CC_id, UE_id) > 0 || round > 0) // || ((frameP%10)==0)) - // if there is information on bsr of DCCH, DTCH or if there is UL_SR, or if there is a packet to retransmit, or we want to schedule a periodic feedback every 10 frames - { - LOG_D(MAC, - "[eNB %d][PUSCH %d] Frame %d subframe %d Scheduling UE %d/%x in round %d(SR %d,UL_inactivity timer %d,UL_failure timer %d,cqi_req_timer %d)\n", - module_idP, harq_pid, frameP, subframeP, UE_id, rnti, - round, UE_template->ul_SR, - UE_sched_ctrl->ul_inactivity_timer, - UE_sched_ctrl->ul_failure_timer, - UE_sched_ctrl->cqi_req_timer); + round_index = UE_sched_ctrl_ptr->round_UL[CC_id][harq_pid]; + + AssertFatal(round_index < 8, "round %d > 7 for UE %d/%x\n", + round_index, + UE_id, + rnti); + + LOG_D(MAC, "[eNB %d] frame %d subframe %d (sched_frame %d, sched_subframe %d), Checking PUSCH %d for UE %d/%x CC %d : aggregation level %d, N_RB_UL %d\n", + module_idP, + frameP, + subframeP, + sched_frame, + sched_subframeP, + harq_pid, + UE_id, + rnti, + CC_id, + aggregation, + n_rb_ul_tab[CC_id]); + + /* Seems unused, only for debug */ + RC.eNB[module_idP][CC_id]->pusch_stats_BO[UE_id][(frameP * 10) + subframeP] = UE_template_ptr->estimated_ul_buffer; + VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLES_UE0_BO, UE_template_ptr->estimated_ul_buffer); + + /* + * If there is information on bsr of DCCH, DTCH or if there is UL_SR, + * or if there is a packet to retransmit, or we want to schedule a periodic feedback + */ + /* Shouldn't this test be done earlier?? */ + if (UE_is_to_be_scheduled(module_idP, CC_id, UE_id) > 0 || round_index > 0) { + LOG_D(MAC, "[eNB %d][PUSCH %d] Frame %d subframe %d Scheduling UE %d/%x in round %d(SR %d,UL_inactivity timer %d,UL_failure timer %d,cqi_req_timer %d)\n", + module_idP, + harq_pid, + frameP, + subframeP, + UE_id, + rnti, + round_index, + UE_template_ptr->ul_SR, + UE_sched_ctrl_ptr->ul_inactivity_timer, + UE_sched_ctrl_ptr->ul_failure_timer, + UE_sched_ctrl_ptr->cqi_req_timer); + // reset the scheduling request - UE_template->ul_SR = 0; + UE_template_ptr->ul_SR = 0; status = mac_eNB_get_rrc_status(module_idP, rnti); cqi_req = 0; - if (status >= RRC_CONNECTED && UE_sched_ctrl->cqi_req_timer > 30) { - if (UE_sched_ctrl->cqi_received == 0) { + /* Handle the aperiodic CQI report */ + /* These aperiodic reports behave as periodic ones... */ + if (status >= RRC_CONNECTED && UE_sched_ctrl_ptr->cqi_req_timer > 30) { + if (UE_sched_ctrl_ptr->cqi_received == 0) { if (nfapi_mode) { cqi_req = 0; } else { cqi_req = 1; - // To be safe , do not ask CQI in special Subframes:36.213/7.2.3 CQI definition + /* TDD: to be safe, do not ask CQI in special Subframes:36.213/7.2.3 CQI definition */ if (cc[CC_id].tdd_Config) { switch (cc[CC_id].tdd_Config->subframeAssignment) { case 1: - if( subframeP == 1 || subframeP == 6 ) cqi_req=0; - + if(subframeP == 1 || subframeP == 6) { + cqi_req=0; + } break; case 3: - if( subframeP == 1 ) cqi_req=0; - + if(subframeP == 1) { + cqi_req=0; + } break; default: @@ -1299,125 +1523,135 @@ void schedule_ulsch_rnti(module_id_t module_idP, } } - if(cqi_req == 1) UE_sched_ctrl->cqi_req_flag |= 1 << sched_subframeP; + if(cqi_req == 1) { + UE_sched_ctrl_ptr->cqi_req_flag |= 1 << sched_subframeP; + } } - } else if (UE_sched_ctrl->cqi_received == 1) { - UE_sched_ctrl->cqi_req_flag = 0; - UE_sched_ctrl->cqi_received = 0; - UE_sched_ctrl->cqi_req_timer = 0; + } else { + UE_sched_ctrl_ptr->cqi_req_flag = 0; + UE_sched_ctrl_ptr->cqi_received = 0; + UE_sched_ctrl_ptr->cqi_req_timer = 0; } } - //power control - //compute the expected ULSCH RX power (for the stats) - // this is the normalized RX power and this should be constant (regardless of mcs - //is not in dBm, unit from nfapi, converting to dBm: ToDo: Noise power hard coded to 30 - normalized_rx_power = (5*UE_sched_ctrl->pusch_snr[CC_id]-640)/10+30; - target_rx_power= mac->puSch10xSnr/10 + 30; - //printf("\n mac->puSch10xSnr = %d, normalized_rx_power = %d, target_rx_power = %d \n",mac->puSch10xSnr,normalized_rx_power,target_rx_power); - // this assumes accumulated tpc - // make sure that we are only sending a tpc update once a frame, otherwise the control loop will freak out - int32_t framex10psubframe = UE_template->pusch_tpc_tx_frame * 10 + UE_template->pusch_tpc_tx_subframe; - - if (((framex10psubframe + 10) <= (frameP * 10 + subframeP)) || //normal case + /* Power control */ + /* + * Compute the expected ULSCH RX power (for the stats) + * This is the normalized RX power and this should be constant (regardless of mcs) + * Is not in dBm, unit from nfapi, converting to dBm + * ToDo: Noise power hard coded to 30 + */ + normalized_rx_power = ((5 * UE_sched_ctrl_ptr->pusch_snr[CC_id] - 640) / 10) + 30; + target_rx_power = (mac->puSch10xSnr / 10) + 30; + + /* + * This assumes accumulated tpc + * Make sure that we are only sending a tpc update once a frame, otherwise the control loop will freak out + */ + framex10psubframe = (UE_template_ptr->pusch_tpc_tx_frame * 10) + UE_template_ptr->pusch_tpc_tx_subframe; + + if (((framex10psubframe + 10) <= (frameP * 10 + subframeP)) || // normal case ((framex10psubframe > (frameP * 10 + subframeP)) && (((10240 - framex10psubframe + frameP * 10 + subframeP) >= 10)))) { //frame wrap-around - UE_template->pusch_tpc_tx_frame = frameP; - UE_template->pusch_tpc_tx_subframe = subframeP; + + UE_template_ptr->pusch_tpc_tx_frame = frameP; + UE_template_ptr->pusch_tpc_tx_subframe = subframeP; if (normalized_rx_power > (target_rx_power + 4)) { - tpc = 0; //-1 + tpc = 0; // -1 tpc_accumulated--; } else if (normalized_rx_power < (target_rx_power - 4)) { - tpc = 2; //+1 + tpc = 2; // +1 tpc_accumulated++; } else { - tpc = 1; //0 + tpc = 1; // 0 } } else { - tpc = 1; //0 + tpc = 1; // 0 } - //tpc = 1; if (tpc != 1) { - LOG_D(MAC, - "[eNB %d] ULSCH scheduler: frame %d, subframe %d, harq_pid %d, tpc %d, accumulated %d, normalized/target rx power %d/%d\n", - module_idP, frameP, subframeP, harq_pid, tpc, - tpc_accumulated, normalized_rx_power, - target_rx_power); + LOG_D(MAC, "[eNB %d] ULSCH scheduler: frame %d, subframe %d, harq_pid %d, tpc %d, accumulated %d, normalized/target rx power %d/%d\n", + module_idP, + frameP, + subframeP, + harq_pid, + tpc, + tpc_accumulated, + normalized_rx_power, + target_rx_power); } - // new transmission - if (round == 0) { - ndi = 1 - UE_template->oldNDI_UL[harq_pid]; - UE_template->oldNDI_UL[harq_pid] = ndi; + /* New transmission */ + if (round_index == 0) { + ndi = 1 - UE_template_ptr->oldNDI_UL[harq_pid]; // NDI: new data indicator + UE_template_ptr->oldNDI_UL[harq_pid] = ndi; UE_list->eNB_UE_stats[CC_id][UE_id].normalized_rx_power = normalized_rx_power; UE_list->eNB_UE_stats[CC_id][UE_id].target_rx_power = target_rx_power; - UE_template->mcs_UL[harq_pid] = cmin(UE_template->pre_assigned_mcs_ul, sli->ul[slice_idx].maxmcs); - UE_list->eNB_UE_stats[CC_id][UE_id].ulsch_mcs1= UE_template->mcs_UL[harq_pid]; + UE_template_ptr->mcs_UL[harq_pid] = cmin(UE_template_ptr->pre_assigned_mcs_ul, sli->ul[slice_idx].maxmcs); + UE_list->eNB_UE_stats[CC_id][UE_id].ulsch_mcs1= UE_template_ptr->mcs_UL[harq_pid]; - //cmin (UE_template->pre_assigned_mcs_ul, openair_daq_vars.target_ue_ul_mcs); // adjust, based on user-defined MCS - if (UE_template->pre_allocated_rb_table_index_ul >= 0) { - rb_table_index = UE_template->pre_allocated_rb_table_index_ul; + if (UE_template_ptr->pre_allocated_rb_table_index_ul >= 0) { + rb_table_index = UE_template_ptr->pre_allocated_rb_table_index_ul; } else { - UE_template->mcs_UL[harq_pid] = 10; //cmin (10, openair_daq_vars.target_ue_ul_mcs); + UE_template_ptr->mcs_UL[harq_pid] = 10; rb_table_index = 5; // for PHR } - UE_list->eNB_UE_stats[CC_id][UE_id].ulsch_mcs2 = UE_template->mcs_UL[harq_pid]; - // buffer_occupancy = UE_template->ul_total_buffer; - - while (((rb_table[rb_table_index] > (N_RB_UL - first_rb_slice[CC_id])) - || (rb_table[rb_table_index] > 45)) - && (rb_table_index > 0)) { + UE_list->eNB_UE_stats[CC_id][UE_id].ulsch_mcs2 = UE_template_ptr->mcs_UL[harq_pid]; + + while (((rb_table[rb_table_index] > (n_rb_ul_tab[CC_id] - first_rb_slice[CC_id])) || + (rb_table[rb_table_index] > 45)) && (rb_table_index > 0)) { rb_table_index--; } - UE_template->TBS_UL[harq_pid] = get_TBS_UL(UE_template->mcs_UL[harq_pid], - rb_table[rb_table_index]); + UE_template_ptr->TBS_UL[harq_pid] = get_TBS_UL(UE_template_ptr->mcs_UL[harq_pid], rb_table[rb_table_index]); UE_list->eNB_UE_stats[CC_id][UE_id].total_rbs_used_rx += rb_table[rb_table_index]; - UE_list->eNB_UE_stats[CC_id][UE_id].ulsch_TBS = UE_template->TBS_UL[harq_pid]; - UE_list->eNB_UE_stats[CC_id][UE_id].total_ulsch_TBS += UE_template->TBS_UL[harq_pid]; - // buffer_occupancy -= TBS; - T(T_ENB_MAC_UE_UL_SCHEDULE, T_INT(module_idP), - T_INT(CC_id), T_INT(rnti), T_INT(frameP), - T_INT(subframeP), T_INT(harq_pid), - T_INT(UE_template->mcs_UL[harq_pid]), + UE_list->eNB_UE_stats[CC_id][UE_id].ulsch_TBS = UE_template_ptr->TBS_UL[harq_pid]; + UE_list->eNB_UE_stats[CC_id][UE_id].total_ulsch_TBS += UE_template_ptr->TBS_UL[harq_pid]; + + T(T_ENB_MAC_UE_UL_SCHEDULE, + T_INT(module_idP), + T_INT(CC_id), + T_INT(rnti), + T_INT(frameP), + T_INT(subframeP), + T_INT(harq_pid), + T_INT(UE_template_ptr->mcs_UL[harq_pid]), T_INT(first_rb_slice[CC_id]), T_INT(rb_table[rb_table_index]), - T_INT(UE_template->TBS_UL[harq_pid]), T_INT(ndi)); - - if (mac_eNB_get_rrc_status(module_idP, rnti) < RRC_CONNECTED) - LOG_D(MAC, - "[eNB %d][PUSCH %d/%x] CC_id %d Frame %d subframeP %d Scheduled UE %d (mcs %d, first rb %d, nb_rb %d, rb_table_index %d, TBS %d, harq_pid %d)\n", - module_idP, harq_pid, rnti, CC_id, frameP, - subframeP, UE_id, - UE_template->mcs_UL[harq_pid], - first_rb_slice[CC_id], rb_table[rb_table_index], - rb_table_index, - UE_template->TBS_UL[harq_pid], harq_pid); - - // bad indices : 20 (40 PRB), 21 (45 PRB), 22 (48 PRB) - //store for possible retransmission - UE_template->nb_rb_ul[harq_pid] = rb_table[rb_table_index]; - UE_template->first_rb_ul[harq_pid] = first_rb_slice[CC_id]; - UE_sched_ctrl->ul_scheduled |= (1 << harq_pid); - - if (UE_id == UE_list->head) - VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLES_UE0_SCHEDULED, - UE_sched_ctrl->ul_scheduled); - - // adjust scheduled UL bytes by TBS, wait for UL sdus to do final update - LOG_D(MAC, - "[eNB %d] CC_id %d UE %d/%x : adjusting scheduled_ul_bytes, old %d, TBS %d\n", - module_idP, CC_id, UE_id, rnti, - UE_template->scheduled_ul_bytes, - UE_template->TBS_UL[harq_pid]); - UE_template->scheduled_ul_bytes += UE_template->TBS_UL[harq_pid]; - LOG_D(MAC, "scheduled_ul_bytes, new %d\n", UE_template->scheduled_ul_bytes); - // Cyclic shift for DM RS + T_INT(UE_template_ptr->TBS_UL[harq_pid]), + T_INT(ndi)); + + /* Store information for possible retransmission */ + UE_template_ptr->nb_rb_ul[harq_pid] = rb_table[rb_table_index]; + UE_template_ptr->first_rb_ul[harq_pid] = first_rb_slice[CC_id]; + UE_sched_ctrl_ptr->ul_scheduled |= (1 << harq_pid); + + if (UE_id == UE_list->head) { + VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLES_UE0_SCHEDULED, UE_sched_ctrl_ptr->ul_scheduled); + } + + /* Adjust scheduled UL bytes by TBS, wait for UL sdus to do final update */ + LOG_D(MAC, "[eNB %d] CC_id %d UE %d/%x : adjusting scheduled_ul_bytes, old %d, TBS %d\n", + module_idP, + CC_id, + UE_id, + rnti, + UE_template_ptr->scheduled_ul_bytes, + UE_template_ptr->TBS_UL[harq_pid]); + + UE_template_ptr->scheduled_ul_bytes += UE_template_ptr->TBS_UL[harq_pid]; + + LOG_D(MAC, "scheduled_ul_bytes, new %d\n", + UE_template_ptr->scheduled_ul_bytes); + + /* Cyclic shift for DM-RS */ cshift = 0; // values from 0 to 7 can be used for mapping the cyclic shift (36.211 , Table 5.5.2.1.1-1) - // save it for a potential retransmission - UE_template->cshift[harq_pid] = cshift; + + /* Save it for a potential retransmission */ + UE_template_ptr->cshift[harq_pid] = cshift; + + /* Setting DCI0 NFAPI struct */ hi_dci0_pdu = &hi_dci0_req_body->hi_dci0_pdu_list[hi_dci0_req_body->number_of_dci + hi_dci0_req_body->number_of_hi]; memset((void *) hi_dci0_pdu, 0,sizeof(nfapi_hi_dci0_request_pdu_t)); hi_dci0_pdu->pdu_type = NFAPI_HI_DCI0_DCI_PDU_TYPE; @@ -1429,84 +1663,99 @@ void schedule_ulsch_rnti(module_id_t module_idP, hi_dci0_pdu->dci_pdu.dci_pdu_rel8.transmission_power = 6000; hi_dci0_pdu->dci_pdu.dci_pdu_rel8.resource_block_start = first_rb_slice[CC_id]; hi_dci0_pdu->dci_pdu.dci_pdu_rel8.number_of_resource_block = rb_table[rb_table_index]; - hi_dci0_pdu->dci_pdu.dci_pdu_rel8.mcs_1 = UE_template->mcs_UL[harq_pid]; + hi_dci0_pdu->dci_pdu.dci_pdu_rel8.mcs_1 = UE_template_ptr->mcs_UL[harq_pid]; hi_dci0_pdu->dci_pdu.dci_pdu_rel8.cyclic_shift_2_for_drms = cshift; hi_dci0_pdu->dci_pdu.dci_pdu_rel8.frequency_hopping_enabled_flag = 0; hi_dci0_pdu->dci_pdu.dci_pdu_rel8.new_data_indication_1 = ndi; hi_dci0_pdu->dci_pdu.dci_pdu_rel8.tpc = tpc; hi_dci0_pdu->dci_pdu.dci_pdu_rel8.cqi_csi_request = cqi_req; - hi_dci0_pdu->dci_pdu.dci_pdu_rel8.dl_assignment_index = UE_template->DAI_ul[sched_subframeP]; + hi_dci0_pdu->dci_pdu.dci_pdu_rel8.dl_assignment_index = UE_template_ptr->DAI_ul[sched_subframeP]; hi_dci0_pdu->dci_pdu.dci_pdu_rel8.harq_pid = harq_pid; hi_dci0_req_body->number_of_dci++; - hi_dci0_req_body->sfnsf = sfnsf_add_subframe(sched_frame, sched_subframeP, 0); //(frameP, subframeP, 4); + hi_dci0_req_body->sfnsf = sfnsf_add_subframe(sched_frame, sched_subframeP, 0); hi_dci0_req_body->tl.tag = NFAPI_HI_DCI0_REQUEST_BODY_TAG; - hi_dci0_req->sfn_sf = frameP<<4|subframeP; // sfnsf_add_subframe(sched_frame, sched_subframeP, 0); // sunday! + hi_dci0_req->sfn_sf = frameP << 4 | subframeP; hi_dci0_req->header.message_id = NFAPI_HI_DCI0_REQUEST; - LOG_D(MAC, - "[PUSCH %d] Frame %d, Subframe %d: Adding UL CONFIG.Request for UE %d/%x, ulsch_frame %d, ulsch_subframe %d\n", - harq_pid, frameP, subframeP, UE_id, rnti, - sched_frame, sched_subframeP); + + LOG_D(MAC, "[PUSCH %d] Frame %d, Subframe %d: Adding UL CONFIG.Request for UE %d/%x, ulsch_frame %d, ulsch_subframe %d\n", + harq_pid, + frameP, + subframeP, + UE_id, + rnti, + sched_frame, + sched_subframeP); + ul_req_index = 0; dlsch_flag = 0; for(ul_req_index = 0; ul_req_index < ul_req_tmp_body->number_of_pdus; ul_req_index++) { if(ul_req_tmp_body->ul_config_pdu_list[ul_req_index].pdu_type == NFAPI_UL_CONFIG_UCI_HARQ_PDU_TYPE && - ul_req_tmp_body->ul_config_pdu_list[ul_req_index].uci_harq_pdu.ue_information.ue_information_rel8.rnti == rnti) { + ul_req_tmp_body->ul_config_pdu_list[ul_req_index].uci_harq_pdu.ue_information.ue_information_rel8.rnti == rnti) { + dlsch_flag = 1; - LOG_D(MAC,"Frame %d, Subframe %d:rnti %x ul_req_index %d Switched UCI HARQ to ULSCH HARQ(first)\n",frameP,subframeP,rnti,ul_req_index); + + LOG_D(MAC, "Frame %d, Subframe %d:rnti %x ul_req_index %d Switched UCI HARQ to ULSCH HARQ(first)\n", + frameP, + subframeP, + rnti, + ul_req_index); + break; } } - // Add UL_config PDUs - fill_nfapi_ulsch_config_request_rel8(&ul_req_tmp_body->ul_config_pdu_list[ul_req_index], cqi_req, cc, UE_template->physicalConfigDedicated, get_tmode(module_idP, CC_id, UE_id), mac->ul_handle, rnti, - first_rb_slice[CC_id], // resource_block_start - rb_table[rb_table_index], // number_of_resource_blocks - UE_template->mcs_UL[harq_pid], cshift, // cyclic_shift_2_for_drms - 0, // frequency_hopping_enabled_flag - 0, // frequency_hopping_bits - ndi, // new_data_indication - 0, // redundancy_version - harq_pid, // harq_process_number - 0, // ul_tx_mode - 0, // current_tx_nb - 0, // n_srs - get_TBS_UL - (UE_template-> - mcs_UL[harq_pid], - rb_table - [rb_table_index])); -#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0)) + /* Add UL_config PDUs */ + fill_nfapi_ulsch_config_request_rel8(&ul_req_tmp_body->ul_config_pdu_list[ul_req_index], + cqi_req, + cc, + UE_template_ptr->physicalConfigDedicated, + get_tmode(module_idP, CC_id, UE_id), + mac->ul_handle, + rnti, + first_rb_slice[CC_id], // resource_block_start + rb_table[rb_table_index], // number_of_resource_blocks + UE_template_ptr->mcs_UL[harq_pid], + cshift, // cyclic_shift_2_for_drms + 0, // frequency_hopping_enabled_flag + 0, // frequency_hopping_bits + ndi, // new_data_indication + 0, // redundancy_version + harq_pid, // harq_process_number + 0, // ul_tx_mode + 0, // current_tx_nb + 0, // n_srs + get_TBS_UL(UE_template_ptr->mcs_UL[harq_pid], rb_table[rb_table_index])); - if (UE_template->rach_resource_type > 0) { // This is a BL/CE UE allocation - fill_nfapi_ulsch_config_request_emtc(&ul_req_tmp_body->ul_config_pdu_list[ul_req_index], UE_template->rach_resource_type > 2 ? 2 : 1, 1, //total_number_of_repetitions - 1, //repetition_number - (frameP * - 10) + - subframeP); +#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0)) + /* This is a BL/CE UE allocation */ + if (UE_template_ptr->rach_resource_type > 0) { + fill_nfapi_ulsch_config_request_emtc(&ul_req_tmp_body->ul_config_pdu_list[ul_req_index], + UE_template_ptr->rach_resource_type > 2 ? 2 : 1, + 1, // total_number_of_repetitions + 1, // repetition_number + (frameP * 10) + subframeP); } #endif - if(dlsch_flag == 1) { - if(cqi_req == 1) { + if (dlsch_flag == 1) { + if (cqi_req == 1) { ul_req_tmp_body->ul_config_pdu_list[ul_req_index].pdu_type = NFAPI_UL_CONFIG_ULSCH_CQI_HARQ_RI_PDU_TYPE; ulsch_harq_information = &ul_req_tmp_body->ul_config_pdu_list[ul_req_index].ulsch_cqi_harq_ri_pdu.harq_information; - ul_req_tmp_body->ul_config_pdu_list[ul_req_index].ulsch_cqi_harq_ri_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.tl.tag= - NFAPI_UL_CONFIG_REQUEST_INITIAL_TRANSMISSION_PARAMETERS_REL8_TAG; - ul_req_tmp_body->ul_config_pdu_list[ul_req_index].ulsch_cqi_harq_ri_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.n_srs_initial = 0; // last symbol not punctured - ul_req_tmp_body->ul_config_pdu_list[ul_req_index].ulsch_cqi_harq_ri_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.initial_number_of_resource_blocks = - rb_table[rb_table_index]; + ul_req_tmp_body->ul_config_pdu_list[ul_req_index].ulsch_cqi_harq_ri_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.tl.tag = NFAPI_UL_CONFIG_REQUEST_INITIAL_TRANSMISSION_PARAMETERS_REL8_TAG; + ul_req_tmp_body->ul_config_pdu_list[ul_req_index].ulsch_cqi_harq_ri_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.n_srs_initial = 0; // last symbol not punctured + ul_req_tmp_body->ul_config_pdu_list[ul_req_index].ulsch_cqi_harq_ri_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.initial_number_of_resource_blocks = rb_table[rb_table_index]; } else { ul_req_tmp_body->ul_config_pdu_list[ul_req_index].pdu_type = NFAPI_UL_CONFIG_ULSCH_HARQ_PDU_TYPE; ulsch_harq_information = &ul_req_tmp_body->ul_config_pdu_list[ul_req_index].ulsch_harq_pdu.harq_information; - ul_req_tmp_body->ul_config_pdu_list[ul_req_index].ulsch_harq_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.tl.tag = - NFAPI_UL_CONFIG_REQUEST_INITIAL_TRANSMISSION_PARAMETERS_REL8_TAG; + ul_req_tmp_body->ul_config_pdu_list[ul_req_index].ulsch_harq_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.tl.tag = NFAPI_UL_CONFIG_REQUEST_INITIAL_TRANSMISSION_PARAMETERS_REL8_TAG; ul_req_tmp_body->ul_config_pdu_list[ul_req_index].ulsch_harq_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.n_srs_initial = 0; // last symbol not punctured ul_req_tmp_body->ul_config_pdu_list[ul_req_index].ulsch_harq_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.initial_number_of_resource_blocks = rb_table[rb_table_index]; } fill_nfapi_ulsch_harq_information(module_idP, CC_id,rnti, ulsch_harq_information,subframeP); + } else { ul_req_tmp_body->number_of_pdus++; } @@ -1514,63 +1763,102 @@ void schedule_ulsch_rnti(module_id_t module_idP, ul_req_tmp->header.message_id = NFAPI_UL_CONFIG_REQUEST; ul_req_tmp_body->tl.tag = NFAPI_UL_CONFIG_REQUEST_BODY_TAG; mac->ul_handle++; - uint16_t ul_sched_frame = sched_frame; - uint16_t ul_sched_subframeP = sched_subframeP; - //add_subframe(&ul_sched_frame, &ul_sched_subframeP, 2); - ul_req_tmp->sfn_sf = ul_sched_frame<<4|ul_sched_subframeP; - add_ue_ulsch_info(module_idP, - CC_id, UE_id, subframeP, - S_UL_SCHEDULED); - LOG_D(MAC, "[eNB %d] CC_id %d Frame %d, subframeP %d: Generated ULSCH DCI for next UE_id %d, format 0\n", module_idP, CC_id, frameP, subframeP, UE_id); - LOG_D(MAC,"[PUSCH %d] SFN/SF:%04d%d UL_CFG:SFN/SF:%04d%d CQI:%d for UE %d/%x\n", harq_pid,frameP,subframeP,ul_sched_frame,ul_sched_subframeP,cqi_req,UE_id,rnti); - // increment first rb for next UE allocation + ul_req_tmp->sfn_sf = sched_frame << 4 | sched_subframeP; + + add_ue_ulsch_info(module_idP, CC_id, UE_id, subframeP, S_UL_SCHEDULED); + + LOG_D(MAC, "[eNB %d] CC_id %d Frame %d, subframeP %d: Generated ULSCH DCI for next UE_id %d, format 0\n", + module_idP, + CC_id, + frameP, + subframeP, + UE_id); + + LOG_D(MAC, "[PUSCH %d] SFN/SF:%04d%d UL_CFG:SFN/SF:%04d%d CQI:%d for UE %d/%x\n", + harq_pid, + frameP, + subframeP, + sched_frame, + sched_subframeP, + cqi_req, + UE_id, + rnti); + + /* Increment first rb for next UE allocation */ first_rb_slice[CC_id] += rb_table[rb_table_index]; - } else { // round > 0 => retransmission + + } else { // round_index > 0 => retransmission T(T_ENB_MAC_UE_UL_SCHEDULE_RETRANSMISSION, - T_INT(module_idP), T_INT(CC_id), T_INT(rnti), - T_INT(frameP), T_INT(subframeP), T_INT(harq_pid), - T_INT(UE_template->mcs_UL[harq_pid]), + T_INT(module_idP), + T_INT(CC_id), + T_INT(rnti), + T_INT(frameP), + T_INT(subframeP), + T_INT(harq_pid), + T_INT(UE_template_ptr->mcs_UL[harq_pid]), T_INT(first_rb_slice[CC_id]), - T_INT(rb_table[rb_table_index]), T_INT(round)); - // Add UL_config PDUs - LOG_D(MAC, - "[PUSCH %d] Frame %d, Subframe %d: Adding UL CONFIG.Request for UE %d/%x, ulsch_frame %d, ulsch_subframe %d\n", - harq_pid, frameP, subframeP, UE_id, rnti, - sched_frame, sched_subframeP); + T_INT(rb_table[rb_table_index]), + T_INT(round_index)); + + /* Add UL_config PDUs */ + LOG_D(MAC, "[PUSCH %d] Frame %d, Subframe %d: Adding UL CONFIG.Request for UE %d/%x, ulsch_frame %d, ulsch_subframe %d\n", + harq_pid, + frameP, + subframeP, + UE_id, + rnti, + sched_frame, + sched_subframeP); + ul_req_index = 0; dlsch_flag = 0; for(ul_req_index = 0; ul_req_index < ul_req_tmp_body->number_of_pdus; ul_req_index++) { if(ul_req_tmp_body->ul_config_pdu_list[ul_req_index].pdu_type == NFAPI_UL_CONFIG_UCI_HARQ_PDU_TYPE && - ul_req_tmp_body->ul_config_pdu_list[ul_req_index].uci_harq_pdu.ue_information.ue_information_rel8.rnti == rnti) { + ul_req_tmp_body->ul_config_pdu_list[ul_req_index].uci_harq_pdu.ue_information.ue_information_rel8.rnti == rnti) { + dlsch_flag = 1; - LOG_D(MAC,"Frame %d, Subframe %d:rnti %x ul_req_index %d Switched UCI HARQ to ULSCH HARQ(first)\n",frameP,subframeP,rnti,ul_req_index); + + LOG_D(MAC, "Frame %d, Subframe %d:rnti %x ul_req_index %d Switched UCI HARQ to ULSCH HARQ(first)\n", + frameP, + subframeP, + rnti, + ul_req_index); + break; } } - fill_nfapi_ulsch_config_request_rel8(&ul_req_tmp_body->ul_config_pdu_list[ul_req_index], cqi_req, cc, UE_template->physicalConfigDedicated, get_tmode(module_idP, CC_id, UE_id), mac->ul_handle, rnti, - UE_template->first_rb_ul[harq_pid], // resource_block_start - UE_template->nb_rb_ul[harq_pid], // number_of_resource_blocks - UE_template->mcs_UL[harq_pid], cshift, // cyclic_shift_2_for_drms - 0, // frequency_hopping_enabled_flag - 0, // frequency_hopping_bits - UE_template->oldNDI_UL[harq_pid], // new_data_indication - rvidx_tab[round & 3], // redundancy_version - harq_pid, // harq_process_number - 0, // ul_tx_mode - 0, // current_tx_nb - 0, // n_srs - UE_template-> - TBS_UL[harq_pid]); + fill_nfapi_ulsch_config_request_rel8(&ul_req_tmp_body->ul_config_pdu_list[ul_req_index], + cqi_req, + cc, + UE_template_ptr->physicalConfigDedicated, + get_tmode(module_idP, CC_id, UE_id), + mac->ul_handle, + rnti, + UE_template_ptr->first_rb_ul[harq_pid], // resource_block_start + UE_template_ptr->nb_rb_ul[harq_pid], // number_of_resource_blocks + UE_template_ptr->mcs_UL[harq_pid], + cshift, // cyclic_shift_2_for_drms + 0, // frequency_hopping_enabled_flag + 0, // frequency_hopping_bits + UE_template_ptr->oldNDI_UL[harq_pid], // new_data_indication + rvidx_tab[round_index & 3], // redundancy_version + harq_pid, // harq_process_number + 0, // ul_tx_mode + 0, // current_tx_nb + 0, // n_srs + UE_template_ptr->TBS_UL[harq_pid]); + #if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0)) - if (UE_template->rach_resource_type > 0) { // This is a BL/CE UE allocation - fill_nfapi_ulsch_config_request_emtc(&ul_req_tmp_body->ul_config_pdu_list[ul_req_index], UE_template->rach_resource_type > 2 ? 2 : 1, 1, //total_number_of_repetitions - 1, //repetition_number - (frameP * - 10) + - subframeP); + /* This is a BL/CE UE allocation */ + if (UE_template_ptr->rach_resource_type > 0) { + fill_nfapi_ulsch_config_request_emtc(&ul_req_tmp_body->ul_config_pdu_list[ul_req_index], + UE_template_ptr->rach_resource_type > 2 ? 2 : 1, + 1, // total_number_of_repetitions + 1, // repetition_number + (frameP * 10) + subframeP); } #endif @@ -1583,7 +1871,7 @@ void schedule_ulsch_rnti(module_id_t module_idP, NFAPI_UL_CONFIG_REQUEST_INITIAL_TRANSMISSION_PARAMETERS_REL8_TAG; ul_req_tmp_body->ul_config_pdu_list[ul_req_index].ulsch_cqi_harq_ri_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.n_srs_initial = 0; // last symbol not punctured ul_req_tmp_body->ul_config_pdu_list[ul_req_index].ulsch_cqi_harq_ri_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.initial_number_of_resource_blocks = - UE_template->nb_rb_ul[harq_pid]; + UE_template_ptr->nb_rb_ul[harq_pid]; } else { ul_req_tmp_body->ul_config_pdu_list[ul_req_index].pdu_type = NFAPI_UL_CONFIG_ULSCH_HARQ_PDU_TYPE; ulsch_harq_information = &ul_req_tmp_body->ul_config_pdu_list[ul_req_index].ulsch_harq_pdu.harq_information; @@ -1591,10 +1879,11 @@ void schedule_ulsch_rnti(module_id_t module_idP, NFAPI_UL_CONFIG_REQUEST_INITIAL_TRANSMISSION_PARAMETERS_REL8_TAG; ul_req_tmp_body->ul_config_pdu_list[ul_req_index].ulsch_harq_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.n_srs_initial = 0; // last symbol not punctured ul_req_tmp_body->ul_config_pdu_list[ul_req_index].ulsch_harq_pdu.initial_transmission_parameters.initial_transmission_parameters_rel8.initial_number_of_resource_blocks = - UE_template->nb_rb_ul[harq_pid]; + UE_template_ptr->nb_rb_ul[harq_pid]; } - fill_nfapi_ulsch_harq_information(module_idP, CC_id,rnti, ulsch_harq_information,subframeP); + fill_nfapi_ulsch_harq_information(module_idP, CC_id,rnti, ulsch_harq_information, subframeP); + } else { ul_req_tmp_body->number_of_pdus++; } @@ -1603,41 +1892,20 @@ void schedule_ulsch_rnti(module_id_t module_idP, ul_req_tmp_body->tl.tag = NFAPI_UL_CONFIG_REQUEST_BODY_TAG; ul_req_tmp->sfn_sf = sched_frame<<4|sched_subframeP; ul_req_tmp->header.message_id = NFAPI_UL_CONFIG_REQUEST; - LOG_D(MAC,"[PUSCH %d] Frame %d, Subframe %d: Adding UL CONFIG.Request for UE %d/%x, ulsch_frame %d, ulsch_subframe %d cqi_req %d\n", - harq_pid,frameP,subframeP,UE_id,rnti,sched_frame,sched_subframeP,cqi_req); - } /* - else if (round > 0) { //we schedule a retransmission - - ndi = UE_template->oldNDI_UL[harq_pid]; - - if ((round&3)==0) { - mcs = openair_daq_vars.target_ue_ul_mcs; - } else { - mcs = rvidx_tab[round&3] + 28; //not correct for round==4! - - } - - LOG_I(MAC,"[eNB %d][PUSCH %d/%x] CC_id %d Frame %d subframeP %d Scheduled UE retransmission (mcs %d, first rb %d, nb_rb %d, harq_pid %d, round %d)\n", - module_idP,UE_id,rnti,CC_id,frameP,subframeP,mcs, - first_rb[CC_id],UE_template->nb_rb_ul[harq_pid], - harq_pid, round); - - rballoc = mac_xface->computeRIV(frame_parms->N_RB_UL, - first_rb[CC_id], - UE_template->nb_rb_ul[harq_pid]); - first_rb[CC_id]+=UE_template->nb_rb_ul[harq_pid]; // increment for next UE allocation - - UE_list->eNB_UE_stats[CC_id][UE_id].num_retransmission_rx+=1; - UE_list->eNB_UE_stats[CC_id][UE_id].rbs_used_retx_rx=UE_template->nb_rb_ul[harq_pid]; - UE_list->eNB_UE_stats[CC_id][UE_id].total_rbs_used_rx+=UE_template->nb_rb_ul[harq_pid]; - UE_list->eNB_UE_stats[CC_id][UE_id].ulsch_mcs1=mcs; - UE_list->eNB_UE_stats[CC_id][UE_id].ulsch_mcs2=mcs; - } - */ - } // UE_is_to_be_scheduled - } // loop over UE_id - } // loop of CC_id + LOG_D(MAC, "[PUSCH %d] Frame %d, Subframe %d: Adding UL CONFIG.Request for UE %d/%x, ulsch_frame %d, ulsch_subframe %d cqi_req %d\n", + harq_pid, + frameP, + subframeP, + UE_id, + rnti, + sched_frame, + sched_subframeP, + cqi_req); + } // end of round > 0 + } // UE_is_to_be_scheduled + } // loop over all active CC_ids + } // loop over UE_ids } #if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0)) diff --git a/openair2/LAYER2/MAC/mac.h b/openair2/LAYER2/MAC/mac.h index 55112166780aa0c6c7149bfb75c47abab48bb028..5aefdf14e73983ea0b17d253697c1aa2fa548b06 100644 --- a/openair2/LAYER2/MAC/mac.h +++ b/openair2/LAYER2/MAC/mac.h @@ -995,6 +995,7 @@ typedef struct { uint8_t crnti_reconfigurationcomplete_flag; uint8_t cqi_req_flag; } UE_sched_ctrl; + /*! \brief eNB template for the Random access information */ typedef struct { /// Flag to indicate this process is active diff --git a/openair2/LAYER2/MAC/mac_proto.h b/openair2/LAYER2/MAC/mac_proto.h index 883010e8d5e5dbe3db04d06e245dbb8e46c64117..6824e1b056fec72e7257850296b173d0825d6f46 100644 --- a/openair2/LAYER2/MAC/mac_proto.h +++ b/openair2/LAYER2/MAC/mac_proto.h @@ -452,7 +452,7 @@ uint8_t get_aggregation(uint8_t bw_index, uint8_t cqi, uint8_t dci_fmt); int8_t find_active_UEs_with_traffic(module_id_t module_idP); -void init_CCE_table(int module_idP, int CC_idP); +void init_CCE_table(int *CCE_table); int get_nCCE_offset(int *CCE_table, const unsigned char L, @@ -734,7 +734,7 @@ void ulsch_scheduler_pre_processor(module_id_t module_idP, int slice_idx, int fr uint16_t * first_rb); void store_ulsch_buffer(module_id_t module_idP, int frameP, sub_frame_t subframeP); -void sort_ue_ul(module_id_t module_idP, int frameP, sub_frame_t subframeP); +void sort_ue_ul(module_id_t module_idP, int slice_idx, int frameP, sub_frame_t subframeP, rnti_t *rntiTable); void assign_max_mcs_min_rb(module_id_t module_idP, int slice_idx, int frameP, sub_frame_t subframeP, uint16_t * first_rb); void adjust_bsr_info(int buffer_occupancy, uint16_t TBS, diff --git a/openair2/LAYER2/MAC/pre_processor.c b/openair2/LAYER2/MAC/pre_processor.c index e98019eff9d3e8cf4da6ac56b135722ed9a921dc..608321d71d183bbfaf56689b5d2634aa01c9d8d6 100644 --- a/openair2/LAYER2/MAC/pre_processor.c +++ b/openair2/LAYER2/MAC/pre_processor.c @@ -68,12 +68,12 @@ int phy_stats_exist(module_id_t Mod_id, int rnti) UE_list_t *UE_list = &RC.mac[Mod_id]->UE_list; if (UE_id == -1) { LOG_W(MAC, "[eNB %d] UE %x not found, should be there (in phy_stats_exist)\n", - Mod_id, rnti); + Mod_id, rnti); return 0; } if (UE_list->numactiveCCs[UE_id] == 0) { LOG_W(MAC, "[eNB %d] UE %x has no active CC (in phy_stats_exist)\n", - Mod_id, rnti); + Mod_id, rnti); return 0; } for (i = 0; i < UE_list->numactiveCCs[UE_id]; i++) { @@ -91,7 +91,6 @@ store_dlsch_buffer(module_id_t Mod_id, int slice_idx, frame_t frameP, sub_frame_t subframeP) { - int UE_id, lcid; rnti_t rnti; mac_rlc_status_resp_t rlc_status; @@ -100,13 +99,12 @@ store_dlsch_buffer(module_id_t Mod_id, for (UE_id = 0; UE_id < MAX_MOBILES_PER_ENB; UE_id++) { if (UE_list->active[UE_id] != TRUE) - continue; + continue; if (!ue_dl_slice_membership(Mod_id, UE_id, slice_idx)) continue; UE_template = &UE_list->UE_template[UE_PCCID(Mod_id, UE_id)][UE_id]; - // clear logical channel interface variables UE_template->dl_buffer_total = 0; UE_template->dl_pdus_total = 0; @@ -121,25 +119,23 @@ store_dlsch_buffer(module_id_t Mod_id, rnti = UE_RNTI(Mod_id, UE_id); for (lcid = 0; lcid < MAX_NUM_LCID; ++lcid) { // loop over all the logical channels - - rlc_status = mac_rlc_status_ind(Mod_id, rnti, Mod_id, frameP, subframeP, - ENB_FLAG_YES, MBMS_FLAG_NO, lcid, 0 -#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0)) - ,0, 0 -#endif - ); + rlc_status = mac_rlc_status_ind(Mod_id, rnti, Mod_id, frameP, subframeP, + ENB_FLAG_YES, MBMS_FLAG_NO, lcid, 0 + #if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0)) + ,0, 0 + #endif + ); UE_template->dl_buffer_info[lcid] = rlc_status.bytes_in_buffer; //storing the dlsch buffer for each logical channel UE_template->dl_pdus_in_buffer[lcid] = rlc_status.pdus_in_buffer; UE_template->dl_buffer_head_sdu_creation_time[lcid] = rlc_status.head_sdu_creation_time; UE_template->dl_buffer_head_sdu_creation_time_max = - cmax(UE_template->dl_buffer_head_sdu_creation_time_max, rlc_status.head_sdu_creation_time); + cmax(UE_template->dl_buffer_head_sdu_creation_time_max, rlc_status.head_sdu_creation_time); UE_template->dl_buffer_head_sdu_remaining_size_to_send[lcid] = rlc_status.head_sdu_remaining_size_to_send; UE_template->dl_buffer_head_sdu_is_segmented[lcid] = rlc_status.head_sdu_is_segmented; UE_template->dl_buffer_total += UE_template->dl_buffer_info[lcid]; //storing the total dlsch buffer UE_template->dl_pdus_total += UE_template->dl_pdus_in_buffer[lcid]; -#ifdef DEBUG_eNB_SCHEDULER - + #ifdef DEBUG_eNB_SCHEDULER /* note for dl_buffer_head_sdu_remaining_size_to_send[lcid] : * 0 if head SDU has not been segmented (yet), else remaining size not already segmented and sent */ @@ -152,9 +148,7 @@ store_dlsch_buffer(module_id_t Mod_id, UE_template->dl_buffer_head_sdu_creation_time[lcid], UE_template->dl_buffer_head_sdu_remaining_size_to_send[lcid], UE_template->dl_buffer_head_sdu_is_segmented[lcid]); - -#endif - + #endif } @@ -178,11 +172,8 @@ assign_rbs_required(module_id_t Mod_id, frame_t frameP, sub_frame_t subframe, uint16_t nb_rbs_required[NFAPI_CC_MAX][MAX_MOBILES_PER_ENB], - int min_rb_unit[NFAPI_CC_MAX]) -{ - + int min_rb_unit[NFAPI_CC_MAX]) { uint16_t TBS = 0; - int UE_id, n, i, j, CC_id, pCCid, tmp; UE_list_t *UE_list = &RC.mac[Mod_id]->UE_list; slice_info_t *sli = &RC.mac[Mod_id]->slice_info; @@ -192,25 +183,27 @@ assign_rbs_required(module_id_t Mod_id, // clear rb allocations across all CC_id for (UE_id = 0; UE_id < MAX_MOBILES_PER_ENB; UE_id++) { if (UE_list->active[UE_id] != TRUE) continue; + if (!ue_dl_slice_membership(Mod_id, UE_id, slice_idx)) continue; + pCCid = UE_PCCID(Mod_id, UE_id); //update CQI information across component carriers for (n = 0; n < UE_list->numactiveCCs[UE_id]; n++) { - CC_id = UE_list->ordered_CCids[n][UE_id]; eNB_UE_stats = &UE_list->eNB_UE_stats[CC_id][UE_id]; -// eNB_UE_stats->dlsch_mcs1 = cmin(cqi_to_mcs[UE_list->UE_sched_ctrl[UE_id].dl_cqi[CC_id]], sli->dl[slice_idx].maxmcs); + // eNB_UE_stats->dlsch_mcs1 = cmin(cqi_to_mcs[UE_list->UE_sched_ctrl[UE_id].dl_cqi[CC_id]], sli->dl[slice_idx].maxmcs); eNB_UE_stats->dlsch_mcs1 = cmin(cqi2mcs(UE_list->UE_sched_ctrl[UE_id].dl_cqi[CC_id]), sli->dl[slice_idx].maxmcs); - } // provide the list of CCs sorted according to MCS for (i = 0; i < UE_list->numactiveCCs[UE_id]; ++i) { eNB_UE_stats_i = &UE_list->eNB_UE_stats[UE_list->ordered_CCids[i][UE_id]][UE_id]; + for (j = i + 1; j < UE_list->numactiveCCs[UE_id]; j++) { DevAssert(j < NFAPI_CC_MAX); eNB_UE_stats_j = &UE_list->eNB_UE_stats[UE_list->ordered_CCids[j][UE_id]][UE_id]; + if (eNB_UE_stats_j->dlsch_mcs1 > eNB_UE_stats_i->dlsch_mcs1) { tmp = UE_list->ordered_CCids[i][UE_id]; UE_list->ordered_CCids[i][UE_id] = UE_list->ordered_CCids[j][UE_id]; @@ -233,18 +226,15 @@ assign_rbs_required(module_id_t Mod_id, } TBS = get_TBS_DL(eNB_UE_stats->dlsch_mcs1, nb_rbs_required[CC_id][UE_id]); - LOG_D(MAC, "[preprocessor] start RB assignement for UE %d CC_id %d dl buffer %d (RB unit %d, MCS %d, TBS %d) \n", UE_id, CC_id, UE_list->UE_template[pCCid][UE_id].dl_buffer_total, nb_rbs_required[CC_id][UE_id], eNB_UE_stats->dlsch_mcs1, TBS); - N_RB_DL = to_prb(RC.mac[Mod_id]->common_channels[CC_id].mib->message.dl_Bandwidth); - UE_list->UE_sched_ctrl[UE_id].max_rbs_allowed_slice[CC_id][slice_idx] = - nb_rbs_allowed_slice(sli->dl[slice_idx].pct, N_RB_DL); + nb_rbs_allowed_slice(sli->dl[slice_idx].pct, N_RB_DL); /* calculating required number of RBs for each UE */ while (TBS < UE_list->UE_template[pCCid][UE_id].dl_buffer_total) { @@ -255,6 +245,7 @@ assign_rbs_required(module_id_t Mod_id, nb_rbs_required[CC_id][UE_id] = UE_list->UE_sched_ctrl[UE_id].max_rbs_allowed_slice[CC_id][slice_idx]; break; } + TBS = get_TBS_DL(eNB_UE_stats->dlsch_mcs1, nb_rbs_required[CC_id][UE_id]); } // end of while @@ -263,7 +254,6 @@ assign_rbs_required(module_id_t Mod_id, Mod_id, frameP, UE_id, CC_id, min_rb_unit[CC_id], nb_rbs_required[CC_id][UE_id], TBS, eNB_UE_stats->dlsch_mcs1); - sli->pre_processor_results[slice_idx].mcs[CC_id][UE_id] = eNB_UE_stats->dlsch_mcs1; } } @@ -275,7 +265,6 @@ assign_rbs_required(module_id_t Mod_id, int maxround(module_id_t Mod_id, uint16_t rnti, int frame, sub_frame_t subframe, uint8_t ul_flag) { - uint8_t round, round_max = 0, UE_id; int CC_id, harq_pid; UE_list_t *UE_list = &RC.mac[Mod_id]->UE_list; @@ -283,11 +272,10 @@ maxround(module_id_t Mod_id, uint16_t rnti, int frame, for (CC_id = 0; CC_id < RC.nb_mac_CC[Mod_id]; CC_id++) { cc = &RC.mac[Mod_id]->common_channels[CC_id]; - UE_id = find_UE_id(Mod_id, rnti); - harq_pid = frame_subframe2_dl_harq_pid(cc->tdd_Config,frame ,subframe); - + harq_pid = frame_subframe2_dl_harq_pid(cc->tdd_Config,frame,subframe); round = UE_list->UE_sched_ctrl[UE_id].round[CC_id][harq_pid]; + if (round > round_max) { round_max = round; } @@ -329,44 +317,39 @@ long min_lcgidpriority(module_id_t Mod_id, int32_t UE_id) { } struct sort_ue_dl_params { - int Mod_idP; - int frameP; - int subframeP; - int slice_idx; + int Mod_idP; + int frameP; + int subframeP; + int slice_idx; }; -static int ue_dl_compare(const void *_a, const void *_b, void *_params) -{ +static int ue_dl_compare(const void *_a, const void *_b, void *_params) { struct sort_ue_dl_params *params = _params; UE_list_t *UE_list = &RC.mac[params->Mod_idP]->UE_list; - int i; int slice_idx = params->slice_idx; int UE_id1 = *(const int *) _a; int UE_id2 = *(const int *) _b; - int rnti1 = UE_RNTI(params->Mod_idP, UE_id1); int pCC_id1 = UE_PCCID(params->Mod_idP, UE_id1); int round1 = maxround(params->Mod_idP, rnti1, params->frameP, params->subframeP, 1); - int rnti2 = UE_RNTI(params->Mod_idP, UE_id2); int pCC_id2 = UE_PCCID(params->Mod_idP, UE_id2); int round2 = maxround(params->Mod_idP, rnti2, params->frameP, params->subframeP, 1); - int cqi1 = maxcqi(params->Mod_idP, UE_id1); int cqi2 = maxcqi(params->Mod_idP, UE_id2); - long lcgid1 = min_lcgidpriority(params->Mod_idP, UE_id1); long lcgid2 = min_lcgidpriority(params->Mod_idP, UE_id2); for (i = 0; i < CR_NUM; ++i) { switch (UE_list->sorting_criteria[slice_idx][i]) { - case CR_ROUND : if (round1 > round2) return -1; + if (round1 < round2) return 1; + break; case CR_SRB12 : @@ -375,41 +358,50 @@ static int ue_dl_compare(const void *_a, const void *_b, void *_params) UE_list->UE_template[pCC_id2][UE_id2].dl_buffer_info[1] + UE_list->UE_template[pCC_id2][UE_id2].dl_buffer_info[2]) return -1; + if (UE_list->UE_template[pCC_id1][UE_id1].dl_buffer_info[1] + UE_list->UE_template[pCC_id1][UE_id1].dl_buffer_info[2] < UE_list->UE_template[pCC_id2][UE_id2].dl_buffer_info[1] + UE_list->UE_template[pCC_id2][UE_id2].dl_buffer_info[2]) return 1; + break; case CR_HOL : if (UE_list-> UE_template[pCC_id1][UE_id1].dl_buffer_head_sdu_creation_time_max > UE_list-> UE_template[pCC_id2][UE_id2].dl_buffer_head_sdu_creation_time_max) return -1; + if (UE_list-> UE_template[pCC_id1][UE_id1].dl_buffer_head_sdu_creation_time_max < UE_list-> UE_template[pCC_id2][UE_id2].dl_buffer_head_sdu_creation_time_max) return 1; + break; case CR_LC : if (UE_list->UE_template[pCC_id1][UE_id1].dl_buffer_total > UE_list->UE_template[pCC_id2][UE_id2].dl_buffer_total) return -1; + if (UE_list->UE_template[pCC_id1][UE_id1].dl_buffer_total < UE_list->UE_template[pCC_id2][UE_id2].dl_buffer_total) return 1; + break; case CR_CQI : if (cqi1 > cqi2) return -1; + if (cqi1 < cqi2) return 1; + break; case CR_LCP : if (lcgid1 < lcgid2) return -1; + if (lcgid1 > lcgid2) return 1; @@ -418,12 +410,11 @@ static int ue_dl_compare(const void *_a, const void *_b, void *_params) } } - return 0; + return 0; } void decode_sorting_policy(module_id_t Mod_idP, int slice_idx) { int i; - UE_list_t *UE_list = &RC.mac[Mod_idP]->UE_list; uint32_t policy = RC.mac[Mod_idP]->slice_info.dl[slice_idx].sorting; uint32_t mask = 0x0000000F; @@ -431,6 +422,7 @@ void decode_sorting_policy(module_id_t Mod_idP, int slice_idx) { for (i = 0; i < CR_NUM; ++i) { criterion = (uint16_t) (policy >> 4 * (CR_NUM - 1 - i) & mask); + if (criterion >= CR_NUM) { LOG_W(MAC, "Invalid criterion in slice index %d ID %d policy, revert to default policy \n", @@ -438,14 +430,14 @@ void decode_sorting_policy(module_id_t Mod_idP, int slice_idx) { RC.mac[Mod_idP]->slice_info.dl[slice_idx].sorting = 0x12345; break; } + UE_list->sorting_criteria[slice_idx][i] = criterion; } } void decode_slice_positioning(module_id_t Mod_idP, int slice_idx, - uint8_t slice_allocation_mask[NFAPI_CC_MAX][N_RBG_MAX]) -{ + uint8_t slice_allocation_mask[NFAPI_CC_MAX][N_RBG_MAX]) { uint8_t CC_id; int RBG, start_frequency, end_frequency; @@ -458,6 +450,7 @@ void decode_slice_positioning(module_id_t Mod_idP, start_frequency = RC.mac[Mod_idP]->slice_info.dl[slice_idx].pos_low; end_frequency = RC.mac[Mod_idP]->slice_info.dl[slice_idx].pos_high; + for (CC_id = 0; CC_id < RC.nb_mac_CC[Mod_idP]; ++CC_id) { for (RBG = start_frequency; RBG <= end_frequency; ++RBG) { slice_allocation_mask[CC_id][RBG] = 1; @@ -467,20 +460,20 @@ void decode_slice_positioning(module_id_t Mod_idP, // This fuction sorts the UE in order their dlsch buffer and CQI -void sort_UEs(module_id_t Mod_idP, int slice_idx, int frameP, sub_frame_t subframeP) -{ +void sort_UEs(module_id_t Mod_idP, int slice_idx, int frameP, sub_frame_t subframeP) { int i; int list[MAX_MOBILES_PER_ENB]; int list_size = 0; struct sort_ue_dl_params params = {Mod_idP, frameP, subframeP, slice_idx}; - UE_list_t *UE_list = &RC.mac[Mod_idP]->UE_list; for (i = 0; i < MAX_MOBILES_PER_ENB; i++) { - if (UE_list->active[i] == FALSE) continue; + if (UE_RNTI(Mod_idP, i) == NOT_A_RNTI) continue; + if (UE_list->UE_sched_ctrl[i].ul_out_of_sync == 1) continue; + if (!ue_dl_slice_membership(Mod_idP, i, slice_idx)) continue; list[list_size] = i; @@ -488,12 +481,12 @@ void sort_UEs(module_id_t Mod_idP, int slice_idx, int frameP, sub_frame_t subfra } decode_sorting_policy(Mod_idP, slice_idx); - qsort_r(list, list_size, sizeof(int), ue_dl_compare, ¶ms); if (list_size) { for (i = 0; i < list_size - 1; ++i) UE_list->next[list[i]] = list[i + 1]; + UE_list->next[list[list_size - 1]] = -1; UE_list->head = list[0]; } else { @@ -502,18 +495,18 @@ void sort_UEs(module_id_t Mod_idP, int slice_idx, int frameP, sub_frame_t subfra } void dlsch_scheduler_pre_processor_partitioning(module_id_t Mod_id, - int slice_idx, - const uint8_t rbs_retx[NFAPI_CC_MAX]) -{ + int slice_idx, + const uint8_t rbs_retx[NFAPI_CC_MAX]) { int UE_id, CC_id, N_RB_DL, i; UE_list_t *UE_list = &RC.mac[Mod_id]->UE_list; UE_sched_ctrl *ue_sched_ctl; uint16_t available_rbs; for (UE_id = UE_list->head; UE_id >= 0; UE_id = UE_list->next[UE_id]) { - if (UE_RNTI(Mod_id, UE_id) == NOT_A_RNTI) continue; + if (UE_list->UE_sched_ctrl[UE_id].ul_out_of_sync == 1) continue; + if (!ue_dl_slice_membership(Mod_id, UE_id, slice_idx)) continue; ue_sched_ctl = &UE_list->UE_sched_ctrl[UE_id]; @@ -522,6 +515,7 @@ void dlsch_scheduler_pre_processor_partitioning(module_id_t Mod_id, CC_id = UE_list->ordered_CCids[i][UE_id]; N_RB_DL = to_prb(RC.mac[Mod_id]->common_channels[CC_id].mib->message.dl_Bandwidth); available_rbs = nb_rbs_allowed_slice(RC.mac[Mod_id]->slice_info.dl[slice_idx].pct, N_RB_DL); + if (rbs_retx[CC_id] < available_rbs) ue_sched_ctl->max_rbs_allowed_slice[CC_id][slice_idx] = available_rbs - rbs_retx[CC_id]; else @@ -531,16 +525,14 @@ void dlsch_scheduler_pre_processor_partitioning(module_id_t Mod_id, } void dlsch_scheduler_pre_processor_accounting(module_id_t Mod_id, - int slice_idx, - frame_t frameP, - sub_frame_t subframeP, - int min_rb_unit[NFAPI_CC_MAX], - uint16_t nb_rbs_required[NFAPI_CC_MAX][MAX_MOBILES_PER_ENB], - uint16_t nb_rbs_accounted[NFAPI_CC_MAX][MAX_MOBILES_PER_ENB]) -{ + int slice_idx, + frame_t frameP, + sub_frame_t subframeP, + int min_rb_unit[NFAPI_CC_MAX], + uint16_t nb_rbs_required[NFAPI_CC_MAX][MAX_MOBILES_PER_ENB], + uint16_t nb_rbs_accounted[NFAPI_CC_MAX][MAX_MOBILES_PER_ENB]) { int UE_id, CC_id; int i; - rnti_t rnti; uint8_t harq_pid, round; uint16_t available_rbs[NFAPI_CC_MAX]; @@ -550,7 +542,6 @@ void dlsch_scheduler_pre_processor_accounting(module_id_t Mod_id, int ue_count_newtx[NFAPI_CC_MAX]; int ue_count_retx[NFAPI_CC_MAX]; //uint8_t ue_retx_flag[NFAPI_CC_MAX][MAX_MOBILES_PER_ENB]; - UE_list_t *UE_list = &RC.mac[Mod_id]->UE_list; UE_sched_ctrl *ue_sched_ctl; COMMON_channels_t *cc; @@ -571,15 +562,18 @@ void dlsch_scheduler_pre_processor_accounting(module_id_t Mod_id, // Find total UE count, and account the RBs required for retransmissions for (UE_id = UE_list->head; UE_id >= 0; UE_id = UE_list->next[UE_id]) { rnti = UE_RNTI(Mod_id, UE_id); + if (rnti == NOT_A_RNTI) continue; + if (UE_list->UE_sched_ctrl[UE_id].ul_out_of_sync == 1) continue; + if (!ue_dl_slice_membership(Mod_id, UE_id, slice_idx)) continue; for (i = 0; i < UE_num_active_CC(UE_list, UE_id); ++i) { CC_id = UE_list->ordered_CCids[i][UE_id]; ue_sched_ctl = &UE_list->UE_sched_ctrl[UE_id]; cc = &RC.mac[Mod_id]->common_channels[CC_id]; - harq_pid = frame_subframe2_dl_harq_pid(cc->tdd_Config,frameP ,subframeP); + harq_pid = frame_subframe2_dl_harq_pid(cc->tdd_Config,frameP,subframeP); round = ue_sched_ctl->round[CC_id][harq_pid]; if (nb_rbs_required[CC_id][UE_id] > 0) { @@ -603,46 +597,53 @@ void dlsch_scheduler_pre_processor_accounting(module_id_t Mod_id, for (CC_id = 0; CC_id < RC.nb_mac_CC[Mod_id]; ++CC_id) { if (UE_list->head < 0) continue; // no UEs in list - // max_rbs_allowed_slice is saved in every UE, so take it from the first one + + // max_rbs_allowed_slice is saved in every UE, so take it from the first one ue_sched_ctl = &UE_list->UE_sched_ctrl[UE_list->head]; available_rbs[CC_id] = ue_sched_ctl->max_rbs_allowed_slice[CC_id][slice_idx]; } switch (RC.mac[Mod_id]->slice_info.dl[slice_idx].accounting) { - // If greedy scheduling, try to account all the required RBs case POL_GREEDY: - for (UE_id = UE_list->head; UE_id >= 0; UE_id = UE_list->next[UE_id]) { rnti = UE_RNTI(Mod_id, UE_id); + if (rnti == NOT_A_RNTI) continue; + if (UE_list->UE_sched_ctrl[UE_id].ul_out_of_sync == 1) continue; + if (!ue_dl_slice_membership(Mod_id, UE_id, slice_idx)) continue; for (i = 0; i < UE_num_active_CC(UE_list, UE_id); i++) { CC_id = UE_list->ordered_CCids[i][UE_id]; + if (available_rbs[CC_id] == 0) continue; + nb_rbs_accounted[CC_id][UE_id] = cmin(nb_rbs_required[CC_id][UE_id], available_rbs[CC_id]); available_rbs[CC_id] -= nb_rbs_accounted[CC_id][UE_id]; } } + break; // Use the old, fair algorithm // Loop over all active UEs and account the avg number of RBs to each UE, based on all non-retx UEs. // case POL_FAIR: default: + // FIXME: This is not ideal, why loop on UEs to find average_rbs_per_user[], that is per-CC? // TODO: Look how to loop on active CCs only without using the UE_num_active_CC() function. for (UE_id = UE_list->head; UE_id >= 0; UE_id = UE_list->next[UE_id]) { rnti = UE_RNTI(Mod_id, UE_id); if (rnti == NOT_A_RNTI) continue; + if (UE_list->UE_sched_ctrl[UE_id].ul_out_of_sync == 1) continue; + if (!ue_dl_slice_membership(Mod_id, UE_id, slice_idx)) continue; for (i = 0; i < UE_num_active_CC(UE_list, UE_id); ++i) { - CC_id = UE_list->ordered_CCids[i][UE_id]; ue_sched_ctl = &UE_list->UE_sched_ctrl[UE_id]; available_rbs[CC_id] = ue_sched_ctl->max_rbs_allowed_slice[CC_id][slice_idx]; @@ -662,8 +663,11 @@ void dlsch_scheduler_pre_processor_accounting(module_id_t Mod_id, // extend nb_rbs_required to capture per LCID RB required for (UE_id = UE_list->head; UE_id >= 0; UE_id = UE_list->next[UE_id]) { rnti = UE_RNTI(Mod_id, UE_id); + if (rnti == NOT_A_RNTI) continue; + if (UE_list->UE_sched_ctrl[UE_id].ul_out_of_sync == 1) continue; + if (!ue_dl_slice_membership(Mod_id, UE_id, slice_idx)) continue; for (i = 0; i < UE_num_active_CC(UE_list, UE_id); i++) { @@ -671,25 +675,26 @@ void dlsch_scheduler_pre_processor_accounting(module_id_t Mod_id, nb_rbs_accounted[CC_id][UE_id] = cmin(average_rbs_per_user[CC_id], nb_rbs_required[CC_id][UE_id]); } } + break; } - - - // Check retransmissions // TODO: Do this once at the beginning for (UE_id = UE_list->head; UE_id >= 0; UE_id = UE_list->next[UE_id]) { rnti = UE_RNTI(Mod_id, UE_id); + if (rnti == NOT_A_RNTI) continue; + if (UE_list->UE_sched_ctrl[UE_id].ul_out_of_sync == 1) continue; + if (!ue_dl_slice_membership(Mod_id, UE_id, slice_idx)) continue; for (i = 0; i < UE_num_active_CC(UE_list, UE_id); i++) { CC_id = UE_list->ordered_CCids[i][UE_id]; ue_sched_ctl = &UE_list->UE_sched_ctrl[UE_id]; cc = &RC.mac[Mod_id]->common_channels[CC_id]; - harq_pid = frame_subframe2_dl_harq_pid(cc->tdd_Config,frameP ,subframeP); + harq_pid = frame_subframe2_dl_harq_pid(cc->tdd_Config,frameP,subframeP); round = ue_sched_ctl->round[CC_id][harq_pid]; // control channel or retransmission @@ -702,23 +707,23 @@ void dlsch_scheduler_pre_processor_accounting(module_id_t Mod_id, } void dlsch_scheduler_pre_processor_positioning(module_id_t Mod_id, - int slice_idx, - int min_rb_unit[NFAPI_CC_MAX], - uint16_t nb_rbs_required[NFAPI_CC_MAX][MAX_MOBILES_PER_ENB], - uint16_t nb_rbs_accounted[NFAPI_CC_MAX][MAX_MOBILES_PER_ENB], - uint16_t nb_rbs_remaining[NFAPI_CC_MAX][MAX_MOBILES_PER_ENB], - uint8_t rballoc_sub[NFAPI_CC_MAX][N_RBG_MAX], - uint8_t MIMO_mode_indicator[NFAPI_CC_MAX][N_RBG_MAX]) -{ + int slice_idx, + int min_rb_unit[NFAPI_CC_MAX], + uint16_t nb_rbs_required[NFAPI_CC_MAX][MAX_MOBILES_PER_ENB], + uint16_t nb_rbs_accounted[NFAPI_CC_MAX][MAX_MOBILES_PER_ENB], + uint16_t nb_rbs_remaining[NFAPI_CC_MAX][MAX_MOBILES_PER_ENB], + uint8_t rballoc_sub[NFAPI_CC_MAX][N_RBG_MAX], + uint8_t MIMO_mode_indicator[NFAPI_CC_MAX][N_RBG_MAX]) { int UE_id, CC_id; int i; -#ifdef TM5 + + #ifdef TM5 uint8_t transmission_mode; -#endif + #endif + uint8_t slice_allocation_mask[NFAPI_CC_MAX][N_RBG_MAX]; int N_RBG[NFAPI_CC_MAX]; UE_list_t *UE_list = &RC.mac[Mod_id]->UE_list; - decode_slice_positioning(Mod_id, slice_idx, slice_allocation_mask); for (CC_id = 0; CC_id < RC.nb_mac_CC[Mod_id]; CC_id++) { @@ -728,17 +733,19 @@ void dlsch_scheduler_pre_processor_positioning(module_id_t Mod_id, // Try to allocate accounted RBs for (UE_id = UE_list->head; UE_id >= 0; UE_id = UE_list->next[UE_id]) { - if (UE_RNTI(Mod_id, UE_id) == NOT_A_RNTI) continue; + if (UE_list->UE_sched_ctrl[UE_id].ul_out_of_sync == 1) continue; + if (!ue_dl_slice_membership(Mod_id, UE_id, slice_idx)) continue; for (i = 0; i < UE_num_active_CC(UE_list, UE_id); i++) { CC_id = UE_list->ordered_CCids[i][UE_id]; nb_rbs_remaining[CC_id][UE_id] = nb_rbs_accounted[CC_id][UE_id]; -#ifdef TM5 + + #ifdef TM5 transmission_mode = get_tmode(Mod_id, CC_id, UE_id); -#endif + #endif if (nb_rbs_required[CC_id][UE_id] > 0) LOG_D(MAC, @@ -764,191 +771,183 @@ void dlsch_scheduler_pre_processor_positioning(module_id_t Mod_id, slice_allocation_mask, MIMO_mode_indicator); -#ifdef TM5 + #ifdef TM5 // data chanel TM5: to be revisited - if ((round == 0) && - (transmission_mode == 5) && - (ue_sched_ctl->dl_pow_off[CC_id] != 1)) { - + if ((round == 0) && + (transmission_mode == 5) && + (ue_sched_ctl->dl_pow_off[CC_id] != 1)) { for (j = 0; j < N_RBG[CC_id]; j += 2) { - - if ((((j == (N_RBG[CC_id] - 1)) - && (rballoc_sub[CC_id][j] == 0) - && (ue_sched_ctl-> - rballoc_sub_UE[CC_id][j] == 0)) - || ((j < (N_RBG[CC_id] - 1)) - && (rballoc_sub[CC_id][j + 1] == 0) - && - (ue_sched_ctl->rballoc_sub_UE - [CC_id][j + 1] == 0))) - && (nb_rbs_remaining[CC_id][UE_id] - > 0)) { - + if ((((j == (N_RBG[CC_id] - 1)) + && (rballoc_sub[CC_id][j] == 0) + && (ue_sched_ctl-> + rballoc_sub_UE[CC_id][j] == 0)) + || ((j < (N_RBG[CC_id] - 1)) + && (rballoc_sub[CC_id][j + 1] == 0) + && + (ue_sched_ctl->rballoc_sub_UE + [CC_id][j + 1] == 0))) + && (nb_rbs_remaining[CC_id][UE_id] + > 0)) { for (i = UE_list->next[UE_id + 1]; i >= 0; i = UE_list->next[i]) { - - UE_id2 = i; - rnti2 = UE_RNTI(Mod_id, UE_id2); - ue_sched_ctl2 = + UE_id2 = i; + rnti2 = UE_RNTI(Mod_id, UE_id2); + ue_sched_ctl2 = &UE_list->UE_sched_ctrl[UE_id2]; - round2 = ue_sched_ctl2->round[CC_id]; - if (rnti2 == NOT_A_RNTI) + round2 = ue_sched_ctl2->round[CC_id]; + + if (rnti2 == NOT_A_RNTI) continue; - if (UE_list-> - UE_sched_ctrl - [UE_id2].ul_out_of_sync == 1) + + if (UE_list-> + UE_sched_ctrl + [UE_id2].ul_out_of_sync == 1) continue; - eNB_UE_stats2 = + eNB_UE_stats2 = UE_list-> eNB_UE_stats[CC_id][UE_id2]; - //mac_xface->get_ue_active_harq_pid(Mod_id,CC_id,rnti2,frameP,subframeP,&harq_pid2,&round2,0); - - if ((mac_eNB_get_rrc_status - (Mod_id, - rnti2) >= RRC_RECONFIGURED) - && (round2 == 0) - && - (get_tmode(Mod_id, CC_id, UE_id2) - == 5) - && (ue_sched_ctl-> - dl_pow_off[CC_id] != 1)) { + //mac_xface->get_ue_active_harq_pid(Mod_id,CC_id,rnti2,frameP,subframeP,&harq_pid2,&round2,0); + if ((mac_eNB_get_rrc_status + (Mod_id, + rnti2) >= RRC_RECONFIGURED) + && (round2 == 0) + && + (get_tmode(Mod_id, CC_id, UE_id2) + == 5) + && (ue_sched_ctl-> + dl_pow_off[CC_id] != 1)) { if ((((j == (N_RBG[CC_id] - 1)) && (ue_sched_ctl->rballoc_sub_UE [CC_id][j] == 0)) || ((j < (N_RBG[CC_id] - 1)) - && - (ue_sched_ctl-> - rballoc_sub_UE[CC_id][j + - 1] - == 0))) + && + (ue_sched_ctl-> + rballoc_sub_UE[CC_id][j + + 1] + == 0))) && (nb_rbs_remaining [CC_id] [UE_id2] > 0)) { - - if ((((eNB_UE_stats2-> - DL_pmi_single ^ - eNB_UE_stats1-> - DL_pmi_single) - << (14 - j)) & 0xc000) == 0x4000) { //MU-MIMO only for 25 RBs configuration - + if ((((eNB_UE_stats2-> + DL_pmi_single ^ + eNB_UE_stats1-> + DL_pmi_single) + << (14 - j)) & 0xc000) == 0x4000) { //MU-MIMO only for 25 RBs configuration rballoc_sub[CC_id][j] = 1; ue_sched_ctl-> - rballoc_sub_UE[CC_id] - [j] = 1; + rballoc_sub_UE[CC_id] + [j] = 1; ue_sched_ctl2-> - rballoc_sub_UE[CC_id] - [j] = 1; + rballoc_sub_UE[CC_id] + [j] = 1; MIMO_mode_indicator[CC_id] - [j] = 0; + [j] = 0; if (j < N_RBG[CC_id] - 1) { - rballoc_sub[CC_id][j + - 1] = - 1; - ue_sched_ctl-> - rballoc_sub_UE - [CC_id][j + 1] = 1; - ue_sched_ctl2->rballoc_sub_UE - [CC_id][j + 1] = 1; - MIMO_mode_indicator - [CC_id][j + 1] + rballoc_sub[CC_id][j + + 1] = + 1; + ue_sched_ctl-> + rballoc_sub_UE + [CC_id][j + 1] = 1; + ue_sched_ctl2->rballoc_sub_UE + [CC_id][j + 1] = 1; + MIMO_mode_indicator + [CC_id][j + 1] = 0; } ue_sched_ctl-> - dl_pow_off[CC_id] - = 0; + dl_pow_off[CC_id] + = 0; ue_sched_ctl2-> - dl_pow_off[CC_id] - = 0; - + dl_pow_off[CC_id] + = 0; if ((j == N_RBG[CC_id] - 1) && ((N_RB_DL == 25) - || (N_RB_DL == - 50))) { - - nb_rbs_remaining - [CC_id][UE_id] = + || (N_RB_DL == + 50))) { + nb_rbs_remaining + [CC_id][UE_id] = nb_rbs_remaining [CC_id][UE_id] - min_rb_unit[CC_id] + 1; - ue_sched_ctl->pre_nb_available_rbs - [CC_id] = + ue_sched_ctl->pre_nb_available_rbs + [CC_id] = ue_sched_ctl->pre_nb_available_rbs [CC_id] + min_rb_unit[CC_id] - 1; - nb_rbs_remaining - [CC_id][UE_id2] = + nb_rbs_remaining + [CC_id][UE_id2] = nb_rbs_remaining [CC_id][UE_id2] - min_rb_unit[CC_id] + 1; - ue_sched_ctl2->pre_nb_available_rbs - [CC_id] = + ue_sched_ctl2->pre_nb_available_rbs + [CC_id] = ue_sched_ctl2->pre_nb_available_rbs [CC_id] + min_rb_unit[CC_id] - 1; } else { - - nb_rbs_remaining - [CC_id][UE_id] = + nb_rbs_remaining + [CC_id][UE_id] = nb_rbs_remaining [CC_id][UE_id] - 4; - ue_sched_ctl->pre_nb_available_rbs - [CC_id] = + ue_sched_ctl->pre_nb_available_rbs + [CC_id] = ue_sched_ctl->pre_nb_available_rbs [CC_id] + 4; - nb_rbs_remaining - [CC_id][UE_id2] = + nb_rbs_remaining + [CC_id][UE_id2] = nb_rbs_remaining [CC_id][UE_id2] - 4; - ue_sched_ctl2->pre_nb_available_rbs - [CC_id] = + ue_sched_ctl2->pre_nb_available_rbs + [CC_id] = ue_sched_ctl2->pre_nb_available_rbs [CC_id] + 4; } - break; - } - } + } } + } } - } - } + } } -#endif + } + #endif + } } } void dlsch_scheduler_pre_processor_intraslice_sharing(module_id_t Mod_id, - int slice_idx, - int min_rb_unit[NFAPI_CC_MAX], - uint16_t nb_rbs_required[NFAPI_CC_MAX][MAX_MOBILES_PER_ENB], - uint16_t nb_rbs_accounted[NFAPI_CC_MAX][MAX_MOBILES_PER_ENB], - uint16_t nb_rbs_remaining[NFAPI_CC_MAX][MAX_MOBILES_PER_ENB], - uint8_t rballoc_sub[NFAPI_CC_MAX][N_RBG_MAX], - uint8_t MIMO_mode_indicator[NFAPI_CC_MAX][N_RBG_MAX]) -{ + int slice_idx, + int min_rb_unit[NFAPI_CC_MAX], + uint16_t nb_rbs_required[NFAPI_CC_MAX][MAX_MOBILES_PER_ENB], + uint16_t nb_rbs_accounted[NFAPI_CC_MAX][MAX_MOBILES_PER_ENB], + uint16_t nb_rbs_remaining[NFAPI_CC_MAX][MAX_MOBILES_PER_ENB], + uint8_t rballoc_sub[NFAPI_CC_MAX][N_RBG_MAX], + uint8_t MIMO_mode_indicator[NFAPI_CC_MAX][N_RBG_MAX]) { int UE_id, CC_id; int i; -#ifdef TM5 + + #ifdef TM5 uint8_t transmission_mode; -#endif + #endif + UE_list_t *UE_list = &RC.mac[Mod_id]->UE_list; int N_RBG[NFAPI_CC_MAX]; slice_info_t *sli = &RC.mac[Mod_id]->slice_info; uint8_t (*slice_allocation_mask)[N_RBG_MAX] = sli->pre_processor_results[slice_idx].slice_allocation_mask; - decode_slice_positioning(Mod_id, slice_idx, slice_allocation_mask); for (CC_id = 0; CC_id < RC.nb_mac_CC[Mod_id]; CC_id++) { @@ -958,20 +957,23 @@ void dlsch_scheduler_pre_processor_intraslice_sharing(module_id_t Mod_id, // Remaining RBs are allocated to high priority UEs for (UE_id = UE_list->head; UE_id >= 0; UE_id = UE_list->next[UE_id]) { - if (UE_RNTI(Mod_id, UE_id) == NOT_A_RNTI) continue; + if (UE_list->UE_sched_ctrl[UE_id].ul_out_of_sync == 1) continue; + if (!ue_dl_slice_membership(Mod_id, UE_id, slice_idx)) continue; for (i = 0; i < UE_num_active_CC(UE_list, UE_id); i++) { CC_id = UE_list->ordered_CCids[i][UE_id]; nb_rbs_remaining[CC_id][UE_id] = - nb_rbs_required[CC_id][UE_id] - nb_rbs_accounted[CC_id][UE_id] + nb_rbs_remaining[CC_id][UE_id]; + nb_rbs_required[CC_id][UE_id] - nb_rbs_accounted[CC_id][UE_id] + nb_rbs_remaining[CC_id][UE_id]; + if (nb_rbs_remaining[CC_id][UE_id] < 0) abort(); -#ifdef TM5 + + #ifdef TM5 transmission_mode = get_tmode(Mod_id, CC_id, UE_id); -#endif + #endif if (nb_rbs_required[CC_id][UE_id] > 0) LOG_D(MAC, @@ -997,168 +999,161 @@ void dlsch_scheduler_pre_processor_intraslice_sharing(module_id_t Mod_id, slice_allocation_mask, MIMO_mode_indicator); -#ifdef TM5 + #ifdef TM5 // data chanel TM5: to be revisited - if ((round == 0) && - (transmission_mode == 5) && - (ue_sched_ctl->dl_pow_off[CC_id] != 1)) { - - for (j = 0; j < N_RBG[CC_id]; j += 2) { - - if ((((j == (N_RBG[CC_id] - 1)) - && (rballoc_sub[CC_id][j] == 0) - && (ue_sched_ctl-> - rballoc_sub_UE[CC_id][j] == 0)) - || ((j < (N_RBG[CC_id] - 1)) - && (rballoc_sub[CC_id][j + 1] == 0) - && - (ue_sched_ctl->rballoc_sub_UE - [CC_id][j + 1] == 0))) - && (nb_rbs_remaining[CC_id][UE_id] - > 0)) { - - for (i = UE_list->next[UE_id + 1]; i >= 0; - i = UE_list->next[i]) { - - UE_id2 = i; - rnti2 = UE_RNTI(Mod_id, UE_id2); - ue_sched_ctl2 = - &UE_list->UE_sched_ctrl[UE_id2]; - round2 = ue_sched_ctl2->round[CC_id]; - if (rnti2 == NOT_A_RNTI) - continue; - if (UE_list-> - UE_sched_ctrl - [UE_id2].ul_out_of_sync == 1) - continue; - - eNB_UE_stats2 = - UE_list-> - eNB_UE_stats[CC_id][UE_id2]; - //mac_xface->get_ue_active_harq_pid(Mod_id,CC_id,rnti2,frameP,subframeP,&harq_pid2,&round2,0); - - if ((mac_eNB_get_rrc_status - (Mod_id, - rnti2) >= RRC_RECONFIGURED) - && (round2 == 0) - && - (get_tmode(Mod_id, CC_id, UE_id2) - == 5) - && (ue_sched_ctl-> - dl_pow_off[CC_id] != 1)) { - - if ((((j == (N_RBG[CC_id] - 1)) + if ((round == 0) && + (transmission_mode == 5) && + (ue_sched_ctl->dl_pow_off[CC_id] != 1)) { + for (j = 0; j < N_RBG[CC_id]; j += 2) { + if ((((j == (N_RBG[CC_id] - 1)) + && (rballoc_sub[CC_id][j] == 0) + && (ue_sched_ctl-> + rballoc_sub_UE[CC_id][j] == 0)) + || ((j < (N_RBG[CC_id] - 1)) + && (rballoc_sub[CC_id][j + 1] == 0) + && + (ue_sched_ctl->rballoc_sub_UE + [CC_id][j + 1] == 0))) + && (nb_rbs_remaining[CC_id][UE_id] + > 0)) { + for (i = UE_list->next[UE_id + 1]; i >= 0; + i = UE_list->next[i]) { + UE_id2 = i; + rnti2 = UE_RNTI(Mod_id, UE_id2); + ue_sched_ctl2 = + &UE_list->UE_sched_ctrl[UE_id2]; + round2 = ue_sched_ctl2->round[CC_id]; + + if (rnti2 == NOT_A_RNTI) + continue; + + if (UE_list-> + UE_sched_ctrl + [UE_id2].ul_out_of_sync == 1) + continue; + + eNB_UE_stats2 = + UE_list-> + eNB_UE_stats[CC_id][UE_id2]; + //mac_xface->get_ue_active_harq_pid(Mod_id,CC_id,rnti2,frameP,subframeP,&harq_pid2,&round2,0); + + if ((mac_eNB_get_rrc_status + (Mod_id, + rnti2) >= RRC_RECONFIGURED) + && (round2 == 0) && - (ue_sched_ctl->rballoc_sub_UE - [CC_id][j] == 0)) - || ((j < (N_RBG[CC_id] - 1)) - && - (ue_sched_ctl-> - rballoc_sub_UE[CC_id][j + - 1] - == 0))) - && - (nb_rbs_remaining - [CC_id] - [UE_id2] > 0)) { - - if ((((eNB_UE_stats2-> - DL_pmi_single ^ - eNB_UE_stats1-> - DL_pmi_single) - << (14 - j)) & 0xc000) == 0x4000) { //MU-MIMO only for 25 RBs configuration - - rballoc_sub[CC_id][j] = 1; - ue_sched_ctl-> + (get_tmode(Mod_id, CC_id, UE_id2) + == 5) + && (ue_sched_ctl-> + dl_pow_off[CC_id] != 1)) { + if ((((j == (N_RBG[CC_id] - 1)) + && + (ue_sched_ctl->rballoc_sub_UE + [CC_id][j] == 0)) + || ((j < (N_RBG[CC_id] - 1)) + && + (ue_sched_ctl-> + rballoc_sub_UE[CC_id][j + + 1] + == 0))) + && + (nb_rbs_remaining + [CC_id] + [UE_id2] > 0)) { + if ((((eNB_UE_stats2-> + DL_pmi_single ^ + eNB_UE_stats1-> + DL_pmi_single) + << (14 - j)) & 0xc000) == 0x4000) { //MU-MIMO only for 25 RBs configuration + rballoc_sub[CC_id][j] = 1; + ue_sched_ctl-> rballoc_sub_UE[CC_id] [j] = 1; - ue_sched_ctl2-> + ue_sched_ctl2-> rballoc_sub_UE[CC_id] [j] = 1; - MIMO_mode_indicator[CC_id] + MIMO_mode_indicator[CC_id] [j] = 0; - if (j < N_RBG[CC_id] - 1) { - rballoc_sub[CC_id][j + - 1] = - 1; - ue_sched_ctl-> - rballoc_sub_UE - [CC_id][j + 1] = 1; - ue_sched_ctl2->rballoc_sub_UE - [CC_id][j + 1] = 1; - MIMO_mode_indicator - [CC_id][j + 1] - = 0; - } + if (j < N_RBG[CC_id] - 1) { + rballoc_sub[CC_id][j + + 1] = + 1; + ue_sched_ctl-> + rballoc_sub_UE + [CC_id][j + 1] = 1; + ue_sched_ctl2->rballoc_sub_UE + [CC_id][j + 1] = 1; + MIMO_mode_indicator + [CC_id][j + 1] + = 0; + } - ue_sched_ctl-> + ue_sched_ctl-> dl_pow_off[CC_id] - = 0; - ue_sched_ctl2-> + = 0; + ue_sched_ctl2-> dl_pow_off[CC_id] - = 0; - - - if ((j == N_RBG[CC_id] - 1) - && ((N_RB_DL == 25) - || (N_RB_DL == - 50))) { - - nb_rbs_remaining - [CC_id][UE_id] = - nb_rbs_remaining - [CC_id][UE_id] - - min_rb_unit[CC_id] - + 1; - ue_sched_ctl->pre_nb_available_rbs - [CC_id] = - ue_sched_ctl->pre_nb_available_rbs - [CC_id] + - min_rb_unit[CC_id] - - 1; - nb_rbs_remaining - [CC_id][UE_id2] = - nb_rbs_remaining - [CC_id][UE_id2] - - min_rb_unit[CC_id] - + 1; - ue_sched_ctl2->pre_nb_available_rbs - [CC_id] = - ue_sched_ctl2->pre_nb_available_rbs - [CC_id] + - min_rb_unit[CC_id] - - 1; - } else { - - nb_rbs_remaining - [CC_id][UE_id] = - nb_rbs_remaining - [CC_id][UE_id] - 4; - ue_sched_ctl->pre_nb_available_rbs - [CC_id] = - ue_sched_ctl->pre_nb_available_rbs - [CC_id] + 4; - nb_rbs_remaining - [CC_id][UE_id2] = - nb_rbs_remaining - [CC_id][UE_id2] - - 4; - ue_sched_ctl2->pre_nb_available_rbs - [CC_id] = - ue_sched_ctl2->pre_nb_available_rbs - [CC_id] + 4; - } + = 0; - break; + if ((j == N_RBG[CC_id] - 1) + && ((N_RB_DL == 25) + || (N_RB_DL == + 50))) { + nb_rbs_remaining + [CC_id][UE_id] = + nb_rbs_remaining + [CC_id][UE_id] - + min_rb_unit[CC_id] + + 1; + ue_sched_ctl->pre_nb_available_rbs + [CC_id] = + ue_sched_ctl->pre_nb_available_rbs + [CC_id] + + min_rb_unit[CC_id] + - 1; + nb_rbs_remaining + [CC_id][UE_id2] = + nb_rbs_remaining + [CC_id][UE_id2] - + min_rb_unit[CC_id] + + 1; + ue_sched_ctl2->pre_nb_available_rbs + [CC_id] = + ue_sched_ctl2->pre_nb_available_rbs + [CC_id] + + min_rb_unit[CC_id] + - 1; + } else { + nb_rbs_remaining + [CC_id][UE_id] = + nb_rbs_remaining + [CC_id][UE_id] - 4; + ue_sched_ctl->pre_nb_available_rbs + [CC_id] = + ue_sched_ctl->pre_nb_available_rbs + [CC_id] + 4; + nb_rbs_remaining + [CC_id][UE_id2] = + nb_rbs_remaining + [CC_id][UE_id2] - + 4; + ue_sched_ctl2->pre_nb_available_rbs + [CC_id] = + ue_sched_ctl2->pre_nb_available_rbs + [CC_id] + 4; + } + + break; + } } + } } - } - } + } } - } - } -#endif + } + #endif + } } } @@ -1170,24 +1165,19 @@ dlsch_scheduler_pre_processor(module_id_t Mod_id, frame_t frameP, sub_frame_t subframeP, int *mbsfn_flag, - uint8_t rballoc_sub[NFAPI_CC_MAX][N_RBG_MAX]) -{ + uint8_t rballoc_sub[NFAPI_CC_MAX][N_RBG_MAX]) { int UE_id; uint8_t CC_id; uint16_t i, j; - int min_rb_unit[NFAPI_CC_MAX]; - slice_info_t *sli = &RC.mac[Mod_id]->slice_info; uint16_t (*nb_rbs_required)[MAX_MOBILES_PER_ENB] = sli->pre_processor_results[slice_idx].nb_rbs_required; uint16_t (*nb_rbs_accounted)[MAX_MOBILES_PER_ENB] = sli->pre_processor_results[slice_idx].nb_rbs_accounted; uint16_t (*nb_rbs_remaining)[MAX_MOBILES_PER_ENB] = sli->pre_processor_results[slice_idx].nb_rbs_remaining; uint8_t (*MIMO_mode_indicator)[N_RBG_MAX] = sli->pre_processor_results[slice_idx].MIMO_mode_indicator; - UE_list_t *UE_list = &RC.mac[Mod_id]->UE_list; UE_sched_ctrl *ue_sched_ctl; -// int rrc_status = RRC_IDLE; - + // int rrc_status = RRC_IDLE; #ifdef TM5 int harq_pid1 = 0; int round1 = 0, round2 = 0; @@ -1198,7 +1188,6 @@ dlsch_scheduler_pre_processor(module_id_t Mod_id, LTE_eNB_UE_stats *eNB_UE_stats2 = NULL; UE_sched_ctrl *ue_sched_ctl1, *ue_sched_ctl2; #endif - // Initialize scheduling information for all active UEs memset(&sli->pre_processor_results[slice_idx], 0, sizeof(sli->pre_processor_results[slice_idx])); // FIXME: After the memset above, some of the resets in reset() are redundant @@ -1208,46 +1197,43 @@ dlsch_scheduler_pre_processor(module_id_t Mod_id, rballoc_sub, MIMO_mode_indicator, mbsfn_flag); // FIXME: Not sure if useful - // STATUS // Store the DLSCH buffer for each logical channel store_dlsch_buffer(Mod_id, slice_idx, frameP, subframeP); - // Calculate the number of RBs required by each UE on the basis of logical channel's buffer assign_rbs_required(Mod_id, slice_idx, frameP, subframeP, nb_rbs_required, min_rb_unit); - // Sorts the user on the basis of dlsch logical channel buffer and CQI sort_UEs(Mod_id, slice_idx, frameP, subframeP); - // ACCOUNTING // This procedure decides the number of RBs to allocate dlsch_scheduler_pre_processor_accounting(Mod_id, slice_idx, frameP, subframeP, - min_rb_unit, - nb_rbs_required, - nb_rbs_accounted); + min_rb_unit, + nb_rbs_required, + nb_rbs_accounted); // POSITIONING // This procedure does the main allocation of the RBs dlsch_scheduler_pre_processor_positioning(Mod_id, slice_idx, - min_rb_unit, - nb_rbs_required, - nb_rbs_accounted, - nb_rbs_remaining, - rballoc_sub, - MIMO_mode_indicator); + min_rb_unit, + nb_rbs_required, + nb_rbs_accounted, + nb_rbs_remaining, + rballoc_sub, + MIMO_mode_indicator); // SHARING // If there are available RBs left in the slice, allocate them to the highest priority UEs if (RC.mac[Mod_id]->slice_info.intraslice_share_active) { dlsch_scheduler_pre_processor_intraslice_sharing(Mod_id, slice_idx, - min_rb_unit, - nb_rbs_required, - nb_rbs_accounted, - nb_rbs_remaining, - rballoc_sub, - MIMO_mode_indicator); + min_rb_unit, + nb_rbs_required, + nb_rbs_accounted, + nb_rbs_remaining, + rballoc_sub, + MIMO_mode_indicator); } #ifdef TM5 + // This has to be revisited!!!! for (CC_id = 0; CC_id < RC.nb_mac_CC[Mod_id]; CC_id++) { COMMON_channels_t *cc = &RC.mac[Mod_id]->common_channels[CC_id]; @@ -1258,42 +1244,42 @@ dlsch_scheduler_pre_processor(module_id_t Mod_id, for (j = 0; j < N_RBG; j++) { if (MIMO_mode_indicator[CC_id][j] == 2) { - i1 = i1 + 1; + i1 = i1 + 1; } else if (MIMO_mode_indicator[CC_id][j] == 1) { - i2 = i2 + 1; + i2 = i2 + 1; } else if (MIMO_mode_indicator[CC_id][j] == 0) { - i3 = i3 + 1; + i3 = i3 + 1; } } if ((i1 < N_RBG) && (i2 > 0) && (i3 == 0)) { PHY_vars_eNB_g[Mod_id][CC_id]->check_for_SUMIMO_transmissions = - PHY_vars_eNB_g[Mod_id][CC_id]-> - check_for_SUMIMO_transmissions + 1; + PHY_vars_eNB_g[Mod_id][CC_id]-> + check_for_SUMIMO_transmissions + 1; } if (i3 == N_RBG && i1 == 0 && i2 == 0) { PHY_vars_eNB_g[Mod_id][CC_id]->FULL_MUMIMO_transmissions = - PHY_vars_eNB_g[Mod_id][CC_id]->FULL_MUMIMO_transmissions + - 1; + PHY_vars_eNB_g[Mod_id][CC_id]->FULL_MUMIMO_transmissions + + 1; } if ((i1 < N_RBG) && (i3 > 0)) { PHY_vars_eNB_g[Mod_id][CC_id]->check_for_MUMIMO_transmissions = - PHY_vars_eNB_g[Mod_id][CC_id]-> - check_for_MUMIMO_transmissions + 1; + PHY_vars_eNB_g[Mod_id][CC_id]-> + check_for_MUMIMO_transmissions + 1; } PHY_vars_eNB_g[Mod_id][CC_id]->check_for_total_transmissions = PHY_vars_eNB_g[Mod_id][CC_id]->check_for_total_transmissions + 1; - } + #endif for (UE_id = UE_list->head; UE_id >= 0; UE_id = UE_list->next[UE_id]) { - ue_sched_ctl = &UE_list->UE_sched_ctrl[UE_id]; + for (i = 0; i < UE_num_active_CC(UE_list, UE_id); i++) { CC_id = UE_list->ordered_CCids[i][UE_id]; //PHY_vars_eNB_g[Mod_id]->mu_mimo_mode[UE_id].dl_pow_off = dl_pow_off[UE_id]; @@ -1330,9 +1316,7 @@ dlsch_scheduler_pre_processor_reset(module_id_t module_idP, uint16_t nb_rbs_required[NFAPI_CC_MAX][MAX_MOBILES_PER_ENB], uint8_t rballoc_sub[NFAPI_CC_MAX][N_RBG_MAX], uint8_t MIMO_mode_indicator[NFAPI_CC_MAX][N_RBG_MAX], - int *mbsfn_flag) -{ - + int *mbsfn_flag) { int UE_id; uint8_t CC_id; int i, j; @@ -1340,17 +1324,15 @@ dlsch_scheduler_pre_processor_reset(module_id_t module_idP, UE_sched_ctrl *ue_sched_ctl; int N_RB_DL, RBGsize, RBGsize_last; int N_RBG[NFAPI_CC_MAX]; - #ifdef SF0_LIMIT int sf0_lower, sf0_upper; #endif - rnti_t rnti; uint8_t *vrb_map; COMMON_channels_t *cc; -// - for (CC_id = 0; CC_id < RC.nb_mac_CC[module_idP]; CC_id++) { + // + for (CC_id = 0; CC_id < RC.nb_mac_CC[module_idP]; CC_id++) { LOG_D(MAC, "Running preprocessor for UE %d (%x)\n", UE_id,(int)(UE_RNTI(module_idP, UE_id))); // initialize harq_pid and round cc = &RC.mac[module_idP]->common_channels[CC_id]; @@ -1361,13 +1343,10 @@ dlsch_scheduler_pre_processor_reset(module_id_t module_idP, continue; for (UE_id = 0; UE_id < MAX_MOBILES_PER_ENB; ++UE_id) { - - UE_list = &RC.mac[module_idP]->UE_list; ue_sched_ctl = &UE_list->UE_sched_ctrl[UE_id]; rnti = UE_RNTI(module_idP, UE_id); - if (rnti == NOT_A_RNTI) continue; @@ -1378,11 +1357,11 @@ dlsch_scheduler_pre_processor_reset(module_id_t module_idP, continue; LOG_D(MAC, "Running preprocessor for UE %d (%x)\n", UE_id, rnti); + // initialize harq_pid and round if (ue_sched_ctl->ta_timer) ue_sched_ctl->ta_timer--; - /* eNB_UE_stats *eNB_UE_stats; @@ -1440,7 +1419,6 @@ dlsch_scheduler_pre_processor_reset(module_id_t module_idP, VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLES_UE0_TIMING_ADVANCE,ue_sched_ctl->ta_update); } */ - nb_rbs_required[CC_id][UE_id] = 0; ue_sched_ctl->pre_nb_available_rbs[CC_id] = 0; ue_sched_ctl->dl_pow_off[CC_id] = 2; @@ -1451,32 +1429,38 @@ dlsch_scheduler_pre_processor_reset(module_id_t module_idP, } N_RB_DL = to_prb(RC.mac[module_idP]->common_channels[CC_id].mib->message.dl_Bandwidth); - #ifdef SF0_LIMIT + switch (N_RBG[CC_id]) { case 6: sf0_lower = 0; sf0_upper = 5; break; + case 8: sf0_lower = 2; sf0_upper = 5; break; + case 13: sf0_lower = 4; sf0_upper = 7; break; + case 17: sf0_lower = 7; sf0_upper = 9; break; + case 25: sf0_lower = 11; sf0_upper = 13; break; + default: AssertFatal(1 == 0, "unsupported RBs (%d)\n", N_RB_DL); } + #endif switch (N_RB_DL) { @@ -1484,37 +1468,43 @@ dlsch_scheduler_pre_processor_reset(module_id_t module_idP, RBGsize = 1; RBGsize_last = 1; break; + case 15: RBGsize = 2; RBGsize_last = 1; break; + case 25: RBGsize = 2; RBGsize_last = 1; break; + case 50: RBGsize = 3; RBGsize_last = 2; break; + case 75: RBGsize = 4; RBGsize_last = 3; break; + case 100: RBGsize = 4; RBGsize_last = 4; break; + default: AssertFatal(1 == 0, "unsupported RBs (%d)\n", N_RB_DL); } vrb_map = RC.mac[module_idP]->common_channels[CC_id].vrb_map; + // Initialize Subbands according to VRB map for (i = 0; i < N_RBG[CC_id]; i++) { int rb_size = i == N_RBG[CC_id] - 1 ? RBGsize_last : RBGsize; - - #ifdef SF0_LIMIT + // for avoiding 6+ PRBs around DC in subframe 0 (avoid excessive errors) /* TODO: make it proper - allocate those RBs, do not "protect" them, but * compute number of available REs and limit MCS according to the @@ -1522,6 +1512,7 @@ dlsch_scheduler_pre_processor_reset(module_id_t module_idP, */ if (subframeP == 0 && i >= sf0_lower && i <= sf0_upper) rballoc_sub[CC_id][i] = 1; + #endif // for SI-RNTI,RA-RNTI and P-RNTI allocations @@ -1532,8 +1523,9 @@ dlsch_scheduler_pre_processor_reset(module_id_t module_idP, break; } } + //LOG_D(MAC, "Frame %d Subframe %d CC_id %d RBG %i : rb_alloc %d\n", - //frameP, subframeP, CC_id, i, rballoc_sub[CC_id][i]); + //frameP, subframeP, CC_id, i, rballoc_sub[CC_id][i]); MIMO_mode_indicator[CC_id][i] = 2; } } @@ -1550,8 +1542,7 @@ dlsch_scheduler_pre_processor_allocate(module_id_t Mod_id, uint16_t nb_rbs_remaining[NFAPI_CC_MAX][MAX_MOBILES_PER_ENB], uint8_t rballoc_sub[NFAPI_CC_MAX][N_RBG_MAX], uint8_t slice_allocation_mask[NFAPI_CC_MAX][N_RBG_MAX], - uint8_t MIMO_mode_indicator[NFAPI_CC_MAX][N_RBG_MAX]) -{ + uint8_t MIMO_mode_indicator[NFAPI_CC_MAX][N_RBG_MAX]) { int i; int tm = get_tmode(Mod_id, CC_id, UE_id); UE_list_t *UE_list = &RC.mac[Mod_id]->UE_list; @@ -1559,12 +1550,16 @@ dlsch_scheduler_pre_processor_allocate(module_id_t Mod_id, int N_RB_DL = to_prb(RC.mac[Mod_id]->common_channels[CC_id].mib->message.dl_Bandwidth); for (i = 0; i < N_RBG; i++) { - if (rballoc_sub[CC_id][i] != 0) continue; + if (ue_sched_ctl->rballoc_sub_UE[CC_id][i] != 0) continue; + if (nb_rbs_remaining[CC_id][UE_id] <= 0) continue; + if (ue_sched_ctl->pre_nb_available_rbs[CC_id] >= nb_rbs_required[CC_id][UE_id]) continue; + if (ue_sched_ctl->dl_pow_off[CC_id] == 0) continue; + if (slice_allocation_mask[CC_id][i] == 0) continue; if ((i == N_RBG - 1) && ((N_RB_DL == 25) || (N_RB_DL == 50))) { @@ -1573,9 +1568,11 @@ dlsch_scheduler_pre_processor_allocate(module_id_t Mod_id, rballoc_sub[CC_id][i] = 1; ue_sched_ctl->rballoc_sub_UE[CC_id][i] = 1; MIMO_mode_indicator[CC_id][i] = 1; + if (tm == 5) { ue_sched_ctl->dl_pow_off[CC_id] = 1; } + nb_rbs_remaining[CC_id][UE_id] = nb_rbs_remaining[CC_id][UE_id] - min_rb_unit + 1; ue_sched_ctl->pre_nb_available_rbs[CC_id] = ue_sched_ctl->pre_nb_available_rbs[CC_id] + min_rb_unit - 1; } @@ -1585,9 +1582,11 @@ dlsch_scheduler_pre_processor_allocate(module_id_t Mod_id, rballoc_sub[CC_id][i] = 1; ue_sched_ctl->rballoc_sub_UE[CC_id][i] = 1; MIMO_mode_indicator[CC_id][i] = 1; + if (tm == 5) { ue_sched_ctl->dl_pow_off[CC_id] = 1; } + nb_rbs_remaining[CC_id][UE_id] = nb_rbs_remaining[CC_id][UE_id] - min_rb_unit; ue_sched_ctl->pre_nb_available_rbs[CC_id] = ue_sched_ctl->pre_nb_available_rbs[CC_id] + min_rb_unit; } @@ -1603,254 +1602,204 @@ void ulsch_scheduler_pre_processor(module_id_t module_idP, int frameP, sub_frame_t subframeP, unsigned char sched_subframeP, - uint16_t *first_rb) -{ - int16_t i; - uint16_t UE_id, n, r; - uint8_t CC_id, harq_pid; - uint16_t nb_allocated_rbs[NFAPI_CC_MAX][MAX_MOBILES_PER_ENB], - total_allocated_rbs[NFAPI_CC_MAX], - average_rbs_per_user[NFAPI_CC_MAX]; - int16_t total_remaining_rbs[NFAPI_CC_MAX]; - uint16_t total_ue_count[NFAPI_CC_MAX]; - rnti_t rnti = -1; - UE_list_t *UE_list = &RC.mac[module_idP]->UE_list; - slice_info_t *sli = &RC.mac[module_idP]->slice_info; - UE_TEMPLATE *UE_template = 0; - UE_sched_ctrl *ue_sched_ctl; - int N_RB_UL = 0; - uint16_t available_rbs, first_rb_offset; - - LOG_D(MAC, "In ulsch_preprocessor: assign max mcs min rb\n"); - // maximize MCS and then allocate required RB according to the buffer occupancy with the limit of max available UL RB - assign_max_mcs_min_rb(module_idP, slice_idx, frameP, subframeP, first_rb); - - LOG_D(MAC, "In ulsch_preprocessor: sort ue \n"); - // sort ues - sort_ue_ul(module_idP, frameP, subframeP); - - - // we need to distribute RBs among UEs - // step1: reset the vars - for (CC_id = 0; CC_id < RC.nb_mac_CC[module_idP]; CC_id++) { - total_allocated_rbs[CC_id] = 0; - total_remaining_rbs[CC_id] = 0; - average_rbs_per_user[CC_id] = 0; - total_ue_count[CC_id] = 0; - } + uint16_t *first_rb) { + int UE_id; + uint16_t n; + uint8_t CC_id, harq_pid; + uint16_t nb_allocated_rbs[NFAPI_CC_MAX][MAX_MOBILES_PER_ENB]; + uint16_t total_allocated_rbs[NFAPI_CC_MAX]; + uint16_t average_rbs_per_user[NFAPI_CC_MAX]; + int16_t total_remaining_rbs[NFAPI_CC_MAX]; + uint16_t total_ue_count[NFAPI_CC_MAX]; + UE_list_t *UE_list = &RC.mac[module_idP]->UE_list; + slice_info_t *sli = &RC.mac[module_idP]->slice_info; + UE_TEMPLATE *UE_template = 0; + UE_sched_ctrl *ue_sched_ctl; + int N_RB_UL = 0; + uint16_t available_rbs, first_rb_offset; + rnti_t rntiTable[MAX_MOBILES_PER_ENB]; // Rnti array => Add SSR 12-2018 + + // sort ues + LOG_D(MAC, "In ulsch_preprocessor: sort ue \n"); + sort_ue_ul(module_idP, slice_idx, frameP, subframeP, rntiTable); + // maximize MCS and then allocate required RB according to the buffer occupancy with the limit of max available UL RB + LOG_D(MAC, "In ulsch_preprocessor: assign max mcs min rb\n"); + assign_max_mcs_min_rb(module_idP, slice_idx, frameP, subframeP, first_rb); + // we need to distribute RBs among UEs + // step1: reset the vars + uint8_t CC_nb = (uint8_t) RC.nb_mac_CC[module_idP]; + + for (CC_id = 0; CC_id < CC_nb; CC_id++) { + total_allocated_rbs[CC_id] = 0; + total_remaining_rbs[CC_id] = 0; + average_rbs_per_user[CC_id] = 0; + total_ue_count[CC_id] = 0; + } - // Step 1.5: Calculate total_ue_count - for (i = UE_list->head_ul; i >= 0; i = UE_list->next_ul[i]) { - for (n = 0; n < UE_list->numactiveULCCs[i]; n++) { - // This is the actual CC_id in the list - CC_id = UE_list->ordered_ULCCids[n][i]; - UE_template = &UE_list->UE_template[CC_id][i]; - if (!ue_ul_slice_membership(module_idP, i, slice_idx)) - continue; - if (UE_template->pre_allocated_nb_rb_ul[slice_idx] > 0) { - total_ue_count[CC_id] += 1; - } + // Step 1.5: Calculate total_ue_count + for (UE_id = UE_list->head_ul; UE_id >= 0; UE_id = UE_list->next_ul[UE_id]) { + // This is not the actual CC_id in the list + for (n = 0; n < UE_list->numactiveULCCs[UE_id]; n++) { + CC_id = UE_list->ordered_ULCCids[n][UE_id]; + UE_template = &UE_list->UE_template[CC_id][UE_id]; + + if (UE_template->pre_allocated_nb_rb_ul[slice_idx] > 0) { + total_ue_count[CC_id]++; } } + } - LOG_D(MAC, "In ulsch_preprocessor: step2 \n"); - // step 2: calculate the average rb per UE - for (i = UE_list->head_ul; i >= 0; i = UE_list->next_ul[i]) { - - rnti = UE_RNTI(module_idP, i); - UE_id = i; - - + // step 2: calculate the average rb per UE + LOG_D(MAC, "In ulsch_preprocessor: step2 \n"); + for (UE_id = UE_list->head_ul; UE_id >= 0; UE_id = UE_list->next_ul[UE_id]) { if (UE_list->UE_template[CC_id][UE_id].rach_resource_type > 0) continue; - rnti = UE_RNTI(module_idP,i); + LOG_D(MAC, "In ulsch_preprocessor: handling UE %d/%x\n", + UE_id, + rntiTable[UE_id]); - if (rnti == NOT_A_RNTI) - continue; - - if (UE_list->UE_sched_ctrl[i].ul_out_of_sync == 1) - continue; - - if (!ue_ul_slice_membership(module_idP, UE_id, slice_idx)) - continue; + for (n = 0; n < UE_list->numactiveULCCs[UE_id]; n++) { + // This is the actual CC_id in the list + CC_id = UE_list->ordered_ULCCids[n][UE_id]; + LOG_D(MAC, "In ulsch_preprocessor: handling UE %d/%x CCid %d\n", + UE_id, + rntiTable[UE_id], + CC_id); + /* + if((mac_xface->get_nCCE_max(module_idP,CC_id,3,subframeP) - nCCE_to_be_used[CC_id]) > (1<<aggregation)) { + nCCE_to_be_used[CC_id] = nCCE_to_be_used[CC_id] + (1<<aggregation); + max_num_ue_to_be_scheduled+=1; + } */ + N_RB_UL = to_prb(RC.mac[module_idP]->common_channels[CC_id].ul_Bandwidth); + ue_sched_ctl = &UE_list->UE_sched_ctrl[UE_id]; + ue_sched_ctl->max_rbs_allowed_slice_uplink[CC_id][slice_idx] = + nb_rbs_allowed_slice(sli->ul[slice_idx].pct, N_RB_UL); + first_rb_offset = UE_list->first_rb_offset[CC_id][slice_idx]; + available_rbs = + cmin(ue_sched_ctl->max_rbs_allowed_slice_uplink[CC_id][slice_idx], N_RB_UL - first_rb[CC_id] - first_rb_offset); - LOG_D(MAC, "In ulsch_preprocessor: handling UE %d/%x\n", UE_id, - rnti); - for (n = 0; n < UE_list->numactiveULCCs[UE_id]; n++) { - // This is the actual CC_id in the list - CC_id = UE_list->ordered_ULCCids[n][UE_id]; - LOG_D(MAC, - "In ulsch_preprocessor: handling UE %d/%x CCid %d\n", - UE_id, rnti, CC_id); + if (available_rbs < 0) + available_rbs = 0; + if (total_ue_count[CC_id] == 0) { average_rbs_per_user[CC_id] = 0; + } else if (total_ue_count[CC_id] == 1) { // increase the available RBs, special case, + average_rbs_per_user[CC_id] = (uint16_t) (available_rbs + 1); + } else if (total_ue_count[CC_id] <= available_rbs) { + average_rbs_per_user[CC_id] = (uint16_t) floor(available_rbs / total_ue_count[CC_id]); + } else { + average_rbs_per_user[CC_id] = 1; + LOG_W(MAC, "[eNB %d] frame %d subframe %d: UE %d CC %d: can't get average rb per user (should not be here)\n", + module_idP, + frameP, + subframeP, + UE_id, + CC_id); + } - /* - if((mac_xface->get_nCCE_max(module_idP,CC_id,3,subframeP) - nCCE_to_be_used[CC_id]) > (1<<aggregation)) { - nCCE_to_be_used[CC_id] = nCCE_to_be_used[CC_id] + (1<<aggregation); - max_num_ue_to_be_scheduled+=1; - } */ - - - - N_RB_UL = to_prb(RC.mac[module_idP]->common_channels[CC_id].ul_Bandwidth); - ue_sched_ctl = &UE_list->UE_sched_ctrl[UE_id]; - ue_sched_ctl->max_rbs_allowed_slice_uplink[CC_id][slice_idx] = - nb_rbs_allowed_slice(sli->ul[slice_idx].pct, N_RB_UL); - - first_rb_offset = UE_list->first_rb_offset[CC_id][slice_idx]; - available_rbs = cmin(ue_sched_ctl->max_rbs_allowed_slice_uplink[CC_id][slice_idx], - N_RB_UL - first_rb[CC_id] - first_rb_offset); - if (available_rbs < 0) - available_rbs = 0; - - if (total_ue_count[CC_id] == 0) { - average_rbs_per_user[CC_id] = 0; - } else if (total_ue_count[CC_id] == 1) { // increase the available RBs, special case, - average_rbs_per_user[CC_id] = (uint16_t) (available_rbs + 1); - } else if (total_ue_count[CC_id] <= available_rbs) { - average_rbs_per_user[CC_id] = (uint16_t) floor(available_rbs / total_ue_count[CC_id]); - } else { - average_rbs_per_user[CC_id] = 1; - LOG_W(MAC, - "[eNB %d] frame %d subframe %d: UE %d CC %d: can't get average rb per user (should not be here)\n", - module_idP, frameP, subframeP, UE_id, CC_id); - } - if (total_ue_count[CC_id] > 0) - LOG_D(MAC, "[eNB %d] Frame %d subframe %d: total ue to be scheduled %d\n", - module_idP, frameP, subframeP, total_ue_count[CC_id]); + if (total_ue_count[CC_id] > 0) { + LOG_D(MAC, "[eNB %d] Frame %d subframe %d: total ue to be scheduled %d\n", + module_idP, + frameP, + subframeP, + total_ue_count[CC_id]); } } + } - // step 3: assigne RBS - for (i = UE_list->head_ul; i >= 0; i = UE_list->next_ul[i]) { - rnti = UE_RNTI(module_idP, i); - - if (rnti == NOT_A_RNTI) - continue; - if (UE_list->UE_sched_ctrl[i].ul_out_of_sync == 1) - continue; - if (!ue_ul_slice_membership(module_idP, i, slice_idx)) - continue; - - - UE_id = i; - - for (n = 0; n < UE_list->numactiveULCCs[UE_id]; n++) { - // This is the actual CC_id in the list - CC_id = UE_list->ordered_ULCCids[n][UE_id]; - UE_template = &UE_list->UE_template[CC_id][UE_id]; - harq_pid = subframe2harqpid(&RC.mac[module_idP]->common_channels[CC_id], - frameP, sched_subframeP); + // step 3: assigne RBS + for (UE_id = UE_list->head_ul; UE_id >= 0; UE_id = UE_list->next_ul[UE_id]) { + // if (continueTable[UE_id]) continue; - // mac_xface->get_ue_active_harq_pid(module_idP,CC_id,rnti,frameP,subframeP,&harq_pid,&round,openair_harq_UL); + for (n = 0; n < UE_list->numactiveULCCs[UE_id]; n++) { + // This is the actual CC_id in the list + CC_id = UE_list->ordered_ULCCids[n][UE_id]; + UE_template = &UE_list->UE_template[CC_id][UE_id]; + harq_pid = subframe2harqpid(&RC.mac[module_idP]->common_channels[CC_id], + frameP, sched_subframeP); - if (UE_list->UE_sched_ctrl[UE_id].round_UL[CC_id] > 0) { - nb_allocated_rbs[CC_id][UE_id] = UE_list->UE_template[CC_id][UE_id].nb_rb_ul[harq_pid]; - } else { - nb_allocated_rbs[CC_id][UE_id] = - cmin(UE_list->UE_template[CC_id][UE_id].pre_allocated_nb_rb_ul[slice_idx], - average_rbs_per_user[CC_id]); - } + // mac_xface->get_ue_active_harq_pid(module_idP,CC_id,rnti,frameP,subframeP,&harq_pid,&round,openair_harq_UL); - total_allocated_rbs[CC_id] += nb_allocated_rbs[CC_id][UE_id]; - LOG_D(MAC, - "In ulsch_preprocessor: assigning %d RBs for UE %d/%x CCid %d, harq_pid %d\n", - nb_allocated_rbs[CC_id][UE_id], UE_id, rnti, CC_id, - harq_pid); + if (UE_list->UE_sched_ctrl[UE_id].round_UL[CC_id] > 0) { + nb_allocated_rbs[CC_id][UE_id] = UE_list->UE_template[CC_id][UE_id].nb_rb_ul[harq_pid]; + } else { + nb_allocated_rbs[CC_id][UE_id] = + cmin(UE_list->UE_template[CC_id][UE_id].pre_allocated_nb_rb_ul[slice_idx], average_rbs_per_user[CC_id]); } - } - // step 4: assigne the remaining RBs and set the pre_allocated rbs accordingly - for (r = 0; r < 2; r++) { - - for (i = UE_list->head_ul; i >= 0; i = UE_list->next_ul[i]) { - rnti = UE_RNTI(module_idP, i); + total_allocated_rbs[CC_id] += nb_allocated_rbs[CC_id][UE_id]; + LOG_D(MAC, "In ulsch_preprocessor: assigning %d RBs for UE %d/%x CCid %d, harq_pid %d\n", + nb_allocated_rbs[CC_id][UE_id], + UE_id, + rntiTable[UE_id], + CC_id, + harq_pid); + } + } - if (rnti == NOT_A_RNTI) - continue; - if (UE_list->UE_sched_ctrl[i].ul_out_of_sync == 1) - continue; - if (!ue_ul_slice_membership(module_idP, i, slice_idx)) - continue; + // step 4: assigne the remaining RBs and set the pre_allocated rbs accordingly + for (UE_id = UE_list->head_ul; UE_id >= 0; UE_id = UE_list->next_ul[UE_id]) { + // if (continueTable[UE_id]) continue; - UE_id = i; - ue_sched_ctl = &UE_list->UE_sched_ctrl[UE_id]; + ue_sched_ctl = &UE_list->UE_sched_ctrl[UE_id]; - for (n = 0; n < UE_list->numactiveULCCs[UE_id]; n++) { - // This is the actual CC_id in the list - CC_id = UE_list->ordered_ULCCids[n][UE_id]; - UE_template = &UE_list->UE_template[CC_id][UE_id]; - N_RB_UL = to_prb(RC.mac[module_idP]->common_channels[CC_id].ul_Bandwidth); - first_rb_offset = UE_list->first_rb_offset[CC_id][slice_idx]; - available_rbs = cmin(ue_sched_ctl->max_rbs_allowed_slice_uplink[CC_id][slice_idx], - N_RB_UL - first_rb[CC_id] - first_rb_offset); - total_remaining_rbs[CC_id] = available_rbs - total_allocated_rbs[CC_id]; + for (n = 0; n < UE_list->numactiveULCCs[UE_id]; n++) { + // This is the actual CC_id in the list + CC_id = UE_list->ordered_ULCCids[n][UE_id]; + UE_template = &UE_list->UE_template[CC_id][UE_id]; + N_RB_UL = to_prb(RC.mac[module_idP]->common_channels[CC_id].ul_Bandwidth); + first_rb_offset = UE_list->first_rb_offset[CC_id][slice_idx]; + available_rbs = cmin(ue_sched_ctl->max_rbs_allowed_slice_uplink[CC_id][slice_idx], N_RB_UL - first_rb[CC_id] - first_rb_offset); + total_remaining_rbs[CC_id] = available_rbs - total_allocated_rbs[CC_id]; - if (total_ue_count[CC_id] == 1) { - total_remaining_rbs[CC_id] += 1; - } + if (total_ue_count[CC_id] == 1) { + total_remaining_rbs[CC_id]++; + } - if (r == 0) { - while ((UE_template->pre_allocated_nb_rb_ul[slice_idx] > 0) - && (nb_allocated_rbs[CC_id][UE_id] < UE_template->pre_allocated_nb_rb_ul[slice_idx]) - && (total_remaining_rbs[CC_id] > 0)) { - nb_allocated_rbs[CC_id][UE_id] = - cmin(nb_allocated_rbs[CC_id][UE_id] + 1, - UE_template->pre_allocated_nb_rb_ul[slice_idx]); - total_remaining_rbs[CC_id]--; - total_allocated_rbs[CC_id]++; - } - } else { - UE_template->pre_allocated_nb_rb_ul[slice_idx] = - nb_allocated_rbs[CC_id][UE_id]; - LOG_D(MAC, - "******************UL Scheduling Information for UE%d CC_id %d ************************\n", - UE_id, CC_id); - LOG_D(MAC, - "[eNB %d] total RB allocated for UE%d CC_id %d = %d\n", - module_idP, UE_id, CC_id, - UE_template->pre_allocated_nb_rb_ul[slice_idx]); - } + while (UE_template->pre_allocated_nb_rb_ul[slice_idx] > 0 && + nb_allocated_rbs[CC_id][UE_id] < UE_template->pre_allocated_nb_rb_ul[slice_idx] && + total_remaining_rbs[CC_id] > 0) { + nb_allocated_rbs[CC_id][UE_id] = cmin(nb_allocated_rbs[CC_id][UE_id] + 1, UE_template->pre_allocated_nb_rb_ul[slice_idx]); + total_remaining_rbs[CC_id]--; + total_allocated_rbs[CC_id]++; } + + UE_template->pre_allocated_nb_rb_ul[slice_idx] = nb_allocated_rbs[CC_id][UE_id]; + LOG_D(MAC, "******************UL Scheduling Information for UE%d CC_id %d ************************\n", + UE_id, + CC_id); + LOG_D(MAC, "[eNB %d] total RB allocated for UE%d CC_id %d = %d\n", + module_idP, + UE_id, + CC_id, + UE_template->pre_allocated_nb_rb_ul[slice_idx]); } } + + return; } void -assign_max_mcs_min_rb(module_id_t module_idP, int slice_idx, int frameP, - sub_frame_t subframeP, uint16_t * first_rb) -{ - +assign_max_mcs_min_rb(module_id_t module_idP, + int slice_idx, + int frameP, + sub_frame_t subframeP, + uint16_t *first_rb) { int i; uint16_t n, UE_id; uint8_t CC_id; - rnti_t rnti = -1; int mcs; int rb_table_index = 0, tbs, tx_power; eNB_MAC_INST *eNB = RC.mac[module_idP]; UE_list_t *UE_list = &eNB->UE_list; - slice_info_t *sli = &RC.mac[module_idP]->slice_info; - + slice_info_t *sli = &eNB->slice_info; UE_TEMPLATE *UE_template; UE_sched_ctrl *ue_sched_ctl; int Ncp; int N_RB_UL; int first_rb_offset, available_rbs; - for (i = 0; i < MAX_MOBILES_PER_ENB; i++) { - if (UE_list->active[i] != TRUE) - continue; - - rnti = UE_RNTI(module_idP, i); - - if (rnti == NOT_A_RNTI) - continue; - if (UE_list->UE_sched_ctrl[i].ul_out_of_sync == 1) - continue; - if (!ue_ul_slice_membership(module_idP, i, slice_idx)) - continue; - + for (i = UE_list->head_ul; i >= 0; i = UE_list->next_ul[i]) { if (UE_list->UE_sched_ctrl[i].phr_received == 1) { /* if we've received the power headroom information the UE, we can go to * maximum mcs */ @@ -1865,22 +1814,18 @@ assign_max_mcs_min_rb(module_id_t module_idP, int slice_idx, int frameP, for (n = 0; n < UE_list->numactiveULCCs[UE_id]; n++) { // This is the actual CC_id in the list CC_id = UE_list->ordered_ULCCids[n][UE_id]; - - - - AssertFatal(CC_id < RC.nb_mac_CC[module_idP], - "CC_id %u should be < %u, loop n=%u < numactiveULCCs[%u]=%u", - CC_id, NFAPI_CC_MAX, n, UE_id, + AssertFatal(CC_id < RC.nb_mac_CC[module_idP], "CC_id %u should be < %u, loop n=%u < numactiveULCCs[%u]=%u", + CC_id, + NFAPI_CC_MAX, + n, + UE_id, UE_list->numactiveULCCs[UE_id]); - UE_template = &UE_list->UE_template[CC_id][UE_id]; UE_template->pre_assigned_mcs_ul = mcs; ue_sched_ctl = &UE_list->UE_sched_ctrl[UE_id]; - - Ncp = RC.mac[module_idP]->common_channels[CC_id].Ncp; - N_RB_UL = to_prb(RC.mac[module_idP]->common_channels[CC_id].ul_Bandwidth); - ue_sched_ctl->max_rbs_allowed_slice_uplink[CC_id][slice_idx] = - nb_rbs_allowed_slice(sli->ul[slice_idx].pct, N_RB_UL); + Ncp = eNB->common_channels[CC_id].Ncp; + N_RB_UL = to_prb(eNB->common_channels[CC_id].ul_Bandwidth); + ue_sched_ctl->max_rbs_allowed_slice_uplink[CC_id][slice_idx] = nb_rbs_allowed_slice(sli->ul[slice_idx].pct, N_RB_UL); int bytes_to_schedule = UE_template->estimated_ul_buffer - UE_template->scheduled_ul_bytes; if (bytes_to_schedule < 0) bytes_to_schedule = 0; @@ -1890,13 +1835,10 @@ assign_max_mcs_min_rb(module_id_t module_idP, int slice_idx, int frameP, if (bits_to_schedule > 0) { tbs = get_TBS_UL(UE_template->pre_assigned_mcs_ul, 3) << 3; // 1 or 2 PRB with cqi enabled does not work well! rb_table_index = 2; - // fixme: set use_srs flag tx_power = estimate_ue_tx_power(tbs, rb_table[rb_table_index], 0, Ncp, 0); - while ((((UE_template->phr_info - tx_power) < 0) - || (tbs > bits_to_schedule)) - && (UE_template->pre_assigned_mcs_ul > 3)) { + while ((UE_template->phr_info - tx_power < 0 || tbs > bits_to_schedule) && UE_template->pre_assigned_mcs_ul > 3) { // LOG_I(MAC,"UE_template->phr_info %d tx_power %d mcs %d\n", UE_template->phr_info,tx_power, mcs); UE_template->pre_assigned_mcs_ul--; tbs = get_TBS_UL(UE_template->pre_assigned_mcs_ul, rb_table[rb_table_index]) << 3; @@ -1904,13 +1846,13 @@ assign_max_mcs_min_rb(module_id_t module_idP, int slice_idx, int frameP, } first_rb_offset = UE_list->first_rb_offset[CC_id][slice_idx]; - available_rbs = cmin(ue_sched_ctl->max_rbs_allowed_slice_uplink[CC_id][slice_idx], - N_RB_UL - first_rb[CC_id] - first_rb_offset); + available_rbs = + cmin(ue_sched_ctl->max_rbs_allowed_slice_uplink[CC_id][slice_idx], N_RB_UL - first_rb[CC_id] - first_rb_offset); - while ((tbs < bits_to_schedule) - && (rb_table[rb_table_index] < available_rbs) - && ((UE_template->phr_info - tx_power) > 0) - && (rb_table_index < 32)) { + while (tbs < bits_to_schedule && + rb_table[rb_table_index] < available_rbs && + UE_template->phr_info - tx_power > 0 && + rb_table_index < 32) { rb_table_index++; tbs = get_TBS_UL(UE_template->pre_assigned_mcs_ul, rb_table[rb_table_index]) << 3; tx_power = estimate_ue_tx_power(tbs, rb_table[rb_table_index], 0, Ncp, 0); @@ -1919,16 +1861,20 @@ assign_max_mcs_min_rb(module_id_t module_idP, int slice_idx, int frameP, if (rb_table[rb_table_index] > (available_rbs - 1)) { rb_table_index--; } + // 1 or 2 PRB with cqi enabled does not work well if (rb_table[rb_table_index] < 3) { - rb_table_index = 2; //3PRB + rb_table_index = 2; //3PRB } UE_template->pre_allocated_rb_table_index_ul = rb_table_index; UE_template->pre_allocated_nb_rb_ul[slice_idx] = rb_table[rb_table_index]; - LOG_D(MAC, - "[eNB %d] frame %d subframe %d: for UE %d CC %d: pre-assigned mcs %d, pre-allocated rb_table[%d]=%d RBs (phr %d, tx power %d)\n", - module_idP, frameP, subframeP, UE_id, CC_id, + LOG_D(MAC, "[eNB %d] frame %d subframe %d: for UE %d CC %d: pre-assigned mcs %d, pre-allocated rb_table[%d]=%d RBs (phr %d, tx power %d)\n", + module_idP, + frameP, + subframeP, + UE_id, + CC_id, UE_template->pre_assigned_mcs_ul, UE_template->pre_allocated_rb_table_index_ul, UE_template->pre_allocated_nb_rb_ul[slice_idx], @@ -1952,91 +1898,97 @@ assign_max_mcs_min_rb(module_id_t module_idP, int slice_idx, int frameP, } struct sort_ue_ul_params { - int module_idP; - int frameP; - int subframeP; + int module_idP; + int frameP; + int subframeP; }; -static int ue_ul_compare(const void *_a, const void *_b, void *_params) -{ - struct sort_ue_ul_params *params = _params; - UE_list_t *UE_list = &RC.mac[params->module_idP]->UE_list; - - int UE_id1 = *(const int *) _a; - int UE_id2 = *(const int *) _b; - - int rnti1 = UE_RNTI(params->module_idP, UE_id1); - int pCCid1 = UE_PCCID(params->module_idP, UE_id1); - int round1 = maxround(params->module_idP, rnti1, params->frameP, - params->subframeP, 1); - - int rnti2 = UE_RNTI(params->module_idP, UE_id2); - int pCCid2 = UE_PCCID(params->module_idP, UE_id2); - int round2 = maxround(params->module_idP, rnti2, params->frameP, - params->subframeP, 1); - - if (round1 > round2) - return -1; - if (round1 < round2) - return 1; - - if (UE_list->UE_template[pCCid1][UE_id1].ul_buffer_info[LCGID0] > - UE_list->UE_template[pCCid2][UE_id2].ul_buffer_info[LCGID0]) - return -1; - if (UE_list->UE_template[pCCid1][UE_id1].ul_buffer_info[LCGID0] < - UE_list->UE_template[pCCid2][UE_id2].ul_buffer_info[LCGID0]) - return 1; - - int bytes_to_schedule1 = UE_list->UE_template[pCCid1][UE_id1].estimated_ul_buffer - UE_list->UE_template[pCCid1][UE_id1].scheduled_ul_bytes; - if (bytes_to_schedule1 < 0) bytes_to_schedule1 = 0; - int bytes_to_schedule2 = UE_list->UE_template[pCCid2][UE_id2].estimated_ul_buffer - UE_list->UE_template[pCCid2][UE_id2].scheduled_ul_bytes; - if (bytes_to_schedule2 < 0) bytes_to_schedule2 = 0; - - if (bytes_to_schedule1 > bytes_to_schedule2) - return -1; - if (bytes_to_schedule1 < bytes_to_schedule2) - return 1; - - if (UE_list->UE_template[pCCid1][UE_id1].pre_assigned_mcs_ul > - UE_list->UE_template[pCCid2][UE_id2].pre_assigned_mcs_ul) - return -1; - if (UE_list->UE_template[pCCid1][UE_id1].pre_assigned_mcs_ul < - UE_list->UE_template[pCCid2][UE_id2].pre_assigned_mcs_ul) - return 1; +static int ue_ul_compare(const void *_a, const void *_b, void *_params) { + struct sort_ue_ul_params *params = _params; + UE_list_t *UE_list = &RC.mac[params->module_idP]->UE_list; + int UE_id1 = *(const int *) _a; + int UE_id2 = *(const int *) _b; + int rnti1 = UE_RNTI(params->module_idP, UE_id1); + int pCCid1 = UE_PCCID(params->module_idP, UE_id1); + int round1 = maxround(params->module_idP, rnti1, params->frameP, + params->subframeP, 1); + int rnti2 = UE_RNTI(params->module_idP, UE_id2); + int pCCid2 = UE_PCCID(params->module_idP, UE_id2); + int round2 = maxround(params->module_idP, rnti2, params->frameP, + params->subframeP, 1); - return 0; + if (round1 > round2) + return -1; + + if (round1 < round2) + return 1; + + if (UE_list->UE_template[pCCid1][UE_id1].ul_buffer_info[LCGID0] > + UE_list->UE_template[pCCid2][UE_id2].ul_buffer_info[LCGID0]) + return -1; + + if (UE_list->UE_template[pCCid1][UE_id1].ul_buffer_info[LCGID0] < + UE_list->UE_template[pCCid2][UE_id2].ul_buffer_info[LCGID0]) + return 1; + + int bytes_to_schedule1 = UE_list->UE_template[pCCid1][UE_id1].estimated_ul_buffer - UE_list->UE_template[pCCid1][UE_id1].scheduled_ul_bytes; + + if (bytes_to_schedule1 < 0) bytes_to_schedule1 = 0; + + int bytes_to_schedule2 = UE_list->UE_template[pCCid2][UE_id2].estimated_ul_buffer - UE_list->UE_template[pCCid2][UE_id2].scheduled_ul_bytes; + + if (bytes_to_schedule2 < 0) bytes_to_schedule2 = 0; + + if (bytes_to_schedule1 > bytes_to_schedule2) + return -1; + + if (bytes_to_schedule1 < bytes_to_schedule2) + return 1; + + if (UE_list->UE_template[pCCid1][UE_id1].pre_assigned_mcs_ul > + UE_list->UE_template[pCCid2][UE_id2].pre_assigned_mcs_ul) + return -1; + + if (UE_list->UE_template[pCCid1][UE_id1].pre_assigned_mcs_ul < + UE_list->UE_template[pCCid2][UE_id2].pre_assigned_mcs_ul) + return 1; + + return 0; } -void sort_ue_ul(module_id_t module_idP, int frameP, sub_frame_t subframeP) +void +sort_ue_ul(module_id_t module_idP, + int slice_idx, + int frameP, + sub_frame_t subframeP, + rnti_t *rntiTable) { - int i; - int list[MAX_MOBILES_PER_ENB]; - int list_size = 0; - int rnti; - struct sort_ue_ul_params params = { module_idP, frameP, subframeP }; - - UE_list_t *UE_list = &RC.mac[module_idP]->UE_list; - - for (i = 0; i < MAX_MOBILES_PER_ENB; i++) { - if (UE_list->active[i] == FALSE) - continue; - if ((rnti = UE_RNTI(module_idP, i)) == NOT_A_RNTI) - continue; - if (UE_list->UE_sched_ctrl[i].ul_out_of_sync == 1) - continue; - - list[list_size] = i; - list_size++; + int i; + int list[MAX_MOBILES_PER_ENB]; + int list_size = 0; + struct sort_ue_ul_params params = { module_idP, frameP, subframeP }; + UE_list_t *UE_list = &RC.mac[module_idP]->UE_list; + + for (i = 0; i < MAX_MOBILES_PER_ENB; i++) { + rntiTable[i] = UE_RNTI(module_idP, i); + // Valid element and is not the actual CC_id in the list + if (UE_list->active[i] == TRUE && + rntiTable[i] != NOT_A_RNTI && + UE_list->UE_sched_ctrl[i].ul_out_of_sync != 1 && + ue_ul_slice_membership(module_idP, i, slice_idx)) { + list[list_size++] = i; // Add to list } + } - qsort_r(list, list_size, sizeof(int), ue_ul_compare, ¶ms); + qsort_r(list, list_size, sizeof(int), ue_ul_compare, ¶ms); - if (list_size) { - for (i = 0; i < list_size - 1; i++) - UE_list->next_ul[list[i]] = list[i + 1]; - UE_list->next_ul[list[list_size - 1]] = -1; - UE_list->head_ul = list[0]; - } else { - UE_list->head_ul = -1; - } + if (list_size) { // At mimimum one list element + for (i = 0; i < list_size - 1; i++) + UE_list->next_ul[list[i]] = list[i + 1]; + + UE_list->next_ul[list[list_size - 1]] = -1; + UE_list->head_ul = list[0]; + } else { // No element + UE_list->head_ul = -1; + } } diff --git a/openair2/LAYER2/PDCP_v10.1.0/pdcp.c b/openair2/LAYER2/PDCP_v10.1.0/pdcp.c index b21a5c24220b565f002cd448ce73dfac3e5971ea..a5ec0b7a21608dcf706e944e1a29e017b0bff470 100644 --- a/openair2/LAYER2/PDCP_v10.1.0/pdcp.c +++ b/openair2/LAYER2/PDCP_v10.1.0/pdcp.c @@ -51,35 +51,35 @@ #include "msc.h" #include "targets/COMMON/openairinterface5g_limits.h" #if defined(ENABLE_SECURITY) -# include "UTIL/OSA/osa_defs.h" + #include "UTIL/OSA/osa_defs.h" #endif #if defined(ENABLE_ITTI) -# include "intertask_interface.h" + #include "intertask_interface.h" #endif #if defined(LINK_ENB_PDCP_TO_GTPV1U) -# include "gtpv1u_eNB_task.h" -# include "gtpv1u.h" + #include "gtpv1u_eNB_task.h" + #include "gtpv1u.h" #endif extern int otg_enabled; #if defined(ENABLE_USE_MME) -extern uint8_t nfapi_mode; + extern uint8_t nfapi_mode; #endif #include "common/ran_context.h" extern RAN_CONTEXT_t RC; hash_table_t *pdcp_coll_p = NULL; #ifdef MBMS_MULTICAST_OUT -# include <sys/types.h> -# include <sys/socket.h> -# include <netinet/in.h> -# include <netinet/ip.h> -# include <netinet/udp.h> -# include <unistd.h> - -static int mbms_socket = -1; + #include <sys/types.h> + #include <sys/socket.h> + #include <netinet/in.h> + #include <netinet/ip.h> + #include <netinet/udp.h> + #include <unistd.h> + + static int mbms_socket = -1; #endif //----------------------------------------------------------------------------- @@ -91,7 +91,7 @@ static int mbms_socket = -1; * code at targets/TEST/PDCP/test_pdcp.c:test_pdcp_data_req() */ boolean_t pdcp_data_req( - protocol_ctxt_t* ctxt_pP, + protocol_ctxt_t *ctxt_pP, const srb_flag_t srb_flagP, const rb_id_t rb_idP, const mui_t muiP, @@ -100,13 +100,12 @@ boolean_t pdcp_data_req( unsigned char *const sdu_buffer_pP, const pdcp_transmission_mode_t modeP #if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0)) - ,const uint32_t * const sourceL2Id - ,const uint32_t * const destinationL2Id + ,const uint32_t *const sourceL2Id + ,const uint32_t *const destinationL2Id #endif ) //----------------------------------------------------------------------------- { - pdcp_t *pdcp_p = NULL; uint8_t i = 0; uint8_t pdcp_header_len = 0; @@ -116,17 +115,17 @@ boolean_t pdcp_data_req( mem_block_t *pdcp_pdu_p = NULL; rlc_op_status_t rlc_status; boolean_t ret = TRUE; - hash_key_t key = HASHTABLE_NOT_A_KEY_VALUE; hashtable_rc_t h_rc; uint8_t rb_offset= (srb_flagP == 0) ? DTCH -1 : 0; uint16_t pdcp_uid=0; VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PDCP_DATA_REQ,VCD_FUNCTION_IN); CHECK_CTXT_ARGS(ctxt_pP); - #if T_TRACER + if (ctxt_pP->enb_flag != ENB_FLAG_NO) T(T_ENB_PDCP_DL, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->rnti), T_INT(rb_idP), T_INT(sdu_buffer_sizeP)); + #endif if (sdu_buffer_sizeP == 0) { @@ -138,8 +137,8 @@ boolean_t pdcp_data_req( * XXX MAX_IP_PACKET_SIZE is 4096, shouldn't this be MAX SDU size, which is 8188 bytes? */ AssertFatal(sdu_buffer_sizeP<= MAX_IP_PACKET_SIZE,"Requested SDU size (%d) is bigger than that can be handled by PDCP (%u)!\n", - sdu_buffer_sizeP, MAX_IP_PACKET_SIZE); - + sdu_buffer_sizeP, MAX_IP_PACKET_SIZE); + if (modeP == PDCP_TRANSMISSION_MODE_TRANSPARENT) { AssertError (rb_idP < NB_RB_MBMS_MAX, return FALSE, "RB id is too high (%u/%d) %u %u!\n", rb_idP, NB_RB_MBMS_MAX, ctxt_pP->module_id, ctxt_pP->rnti); } else { @@ -151,21 +150,21 @@ boolean_t pdcp_data_req( } key = PDCP_COLL_KEY_VALUE(ctxt_pP->module_id, ctxt_pP->rnti, ctxt_pP->enb_flag, rb_idP, srb_flagP); - h_rc = hashtable_get(pdcp_coll_p, key, (void**)&pdcp_p); + h_rc = hashtable_get(pdcp_coll_p, key, (void **)&pdcp_p); if (h_rc != HASH_TABLE_OK) { if (modeP != PDCP_TRANSMISSION_MODE_TRANSPARENT) { LOG_W(PDCP, PROTOCOL_CTXT_FMT" Instance is not configured for rb_id %d Ignoring SDU...\n", - PROTOCOL_CTXT_ARGS(ctxt_pP), - rb_idP); + PROTOCOL_CTXT_ARGS(ctxt_pP), + rb_idP); ctxt_pP->configured=FALSE; return FALSE; } - }else{ + } else { // instance for a given RB is configured ctxt_pP->configured=TRUE; } - + if (ctxt_pP->enb_flag == ENB_FLAG_YES) { start_meas(&eNB_pdcp_stats[ctxt_pP->module_id].data_req); } else { @@ -182,7 +181,7 @@ boolean_t pdcp_data_req( memcpy(&pdcp_pdu_p->data[0], sdu_buffer_pP, sdu_buffer_sizeP); #if defined(DEBUG_PDCP_PAYLOAD) rlc_util_print_hex_octets(PDCP, - (unsigned char*)&pdcp_pdu_p->data[0], + (unsigned char *)&pdcp_pdu_p->data[0], sdu_buffer_sizeP); #endif LOG_D(PDCP, "Before rlc_data_req 1, srb_flagP: %d, rb_idP: %d \n", srb_flagP, rb_idP); @@ -190,7 +189,7 @@ boolean_t pdcp_data_req( #if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0)) ,NULL, NULL #endif - ); + ); } else { rlc_status = RLC_OP_STATUS_OUT_OF_RESSOURCES; LOG_W(PDCP,PROTOCOL_CTXT_FMT" PDCP_DATA_REQ SDU DROPPED, OUT OF MEMORY \n", @@ -212,13 +211,11 @@ boolean_t pdcp_data_req( } pdcp_pdu_size = sdu_buffer_sizeP + pdcp_header_len + pdcp_tailer_len; - LOG_D(PDCP, PROTOCOL_PDCP_CTXT_FMT"Data request notification pdu size %d (header%d, trailer%d)\n", PROTOCOL_PDCP_CTXT_ARGS(ctxt_pP,pdcp_p), pdcp_pdu_size, pdcp_header_len, pdcp_tailer_len); - /* * Allocate a new block for the new PDU (i.e. PDU header and SDU payload) */ @@ -230,7 +227,6 @@ boolean_t pdcp_data_req( * * Place User Plane PDCP Data PDU header first */ - if (srb_flagP) { // this Control plane PDCP Data PDU pdcp_control_plane_data_pdu_header pdu_header; pdu_header.sn = pdcp_get_next_tx_seq_number(pdcp_p); @@ -238,7 +234,7 @@ boolean_t pdcp_data_req( memset(&pdu_header.mac_i[0],0,PDCP_CONTROL_PLANE_DATA_PDU_MAC_I_SIZE); memset(&pdcp_pdu_p->data[sdu_buffer_sizeP + pdcp_header_len],0,PDCP_CONTROL_PLANE_DATA_PDU_MAC_I_SIZE); - if (pdcp_serialize_control_plane_data_pdu_with_SRB_sn_buffer((unsigned char*)pdcp_pdu_p->data, &pdu_header) == FALSE) { + if (pdcp_serialize_control_plane_data_pdu_with_SRB_sn_buffer((unsigned char *)pdcp_pdu_p->data, &pdu_header) == FALSE) { LOG_E(PDCP, PROTOCOL_PDCP_CTXT_FMT" Cannot fill PDU buffer with relevant header fields!\n", PROTOCOL_PDCP_CTXT_ARGS(ctxt_pP,pdcp_p)); @@ -257,12 +253,11 @@ boolean_t pdcp_data_req( pdu_header.sn = pdcp_get_next_tx_seq_number(pdcp_p); current_sn = pdu_header.sn ; - if (pdcp_serialize_user_plane_data_pdu_with_long_sn_buffer((unsigned char*)pdcp_pdu_p->data, &pdu_header) == FALSE) { + if (pdcp_serialize_user_plane_data_pdu_with_long_sn_buffer((unsigned char *)pdcp_pdu_p->data, &pdu_header) == FALSE) { LOG_E(PDCP, PROTOCOL_PDCP_CTXT_FMT" Cannot fill PDU buffer with relevant header fields!\n", PROTOCOL_PDCP_CTXT_ARGS(ctxt_pP,pdcp_p)); - - if (ctxt_pP->enb_flag == ENB_FLAG_YES) { + if (ctxt_pP->enb_flag == ENB_FLAG_YES) { stop_meas(&eNB_pdcp_stats[ctxt_pP->module_id].data_req); } else { stop_meas(&UE_pdcp_stats[ctxt_pP->module_id].data_req); @@ -281,7 +276,6 @@ boolean_t pdcp_data_req( "There must be a problem with PDCP initialization, ignoring this PDU...\n", PROTOCOL_PDCP_CTXT_ARGS(ctxt_pP,pdcp_p), current_sn); - free_mem_block(pdcp_pdu_p, __func__); if (ctxt_pP->enb_flag == ENB_FLAG_YES) { @@ -295,7 +289,6 @@ boolean_t pdcp_data_req( } LOG_D(PDCP, "Sequence number %d is assigned to current PDU\n", current_sn); - /* Then append data... */ memcpy(&pdcp_pdu_p->data[pdcp_header_len], sdu_buffer_pP, sdu_buffer_sizeP); @@ -311,7 +304,6 @@ boolean_t pdcp_data_req( if ((pdcp_p->security_activated != 0) && (((pdcp_p->cipheringAlgorithm) != 0) || ((pdcp_p->integrityProtAlgorithm) != 0))) { - if (ctxt_pP->enb_flag == ENB_FLAG_YES) { start_meas(&eNB_pdcp_stats[ctxt_pP->module_id].apply_security); } else { @@ -335,7 +327,6 @@ boolean_t pdcp_data_req( } #endif - /* Print octets of outgoing data in hexadecimal form */ LOG_D(PDCP, "Following content with size %d will be sent over RLC (PDCP PDU header is the first two bytes)\n", pdcp_pdu_size); @@ -366,45 +357,42 @@ boolean_t pdcp_data_req( * Ask sublayer to transmit data and check return value * to see if RLC succeeded */ - LOG_DUMPMSG(PDCP,DEBUG_PDCP,(char *)pdcp_pdu_p->data,pdcp_pdu_size, "[MSG] PDCP DL %s PDU on rb_id %d\n",(srb_flagP)? "CONTROL" : "DATA", rb_idP); - LOG_D(PDCP, "Before rlc_data_req 2, srb_flagP: %d, rb_idP: %d \n", srb_flagP, rb_idP); rlc_status = rlc_data_req(ctxt_pP, srb_flagP, MBMS_FLAG_NO, rb_idP, muiP, confirmP, pdcp_pdu_size, pdcp_pdu_p #if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0)) - ,sourceL2Id - ,destinationL2Id + ,sourceL2Id + ,destinationL2Id #endif ); - } switch (rlc_status) { - case RLC_OP_STATUS_OK: - LOG_D(PDCP, "Data sending request over RLC succeeded!\n"); - ret=TRUE; - break; - - case RLC_OP_STATUS_BAD_PARAMETER: - LOG_W(PDCP, "Data sending request over RLC failed with 'Bad Parameter' reason!\n"); - ret= FALSE; - break; - - case RLC_OP_STATUS_INTERNAL_ERROR: - LOG_W(PDCP, "Data sending request over RLC failed with 'Internal Error' reason!\n"); - ret= FALSE; - break; - - case RLC_OP_STATUS_OUT_OF_RESSOURCES: - LOG_W(PDCP, "Data sending request over RLC failed with 'Out of Resources' reason!\n"); - ret= FALSE; - break; - - default: - LOG_W(PDCP, "RLC returned an unknown status code after PDCP placed the order to send some data (Status Code:%d)\n", rlc_status); - ret= FALSE; - break; + case RLC_OP_STATUS_OK: + LOG_D(PDCP, "Data sending request over RLC succeeded!\n"); + ret=TRUE; + break; + + case RLC_OP_STATUS_BAD_PARAMETER: + LOG_W(PDCP, "Data sending request over RLC failed with 'Bad Parameter' reason!\n"); + ret= FALSE; + break; + + case RLC_OP_STATUS_INTERNAL_ERROR: + LOG_W(PDCP, "Data sending request over RLC failed with 'Internal Error' reason!\n"); + ret= FALSE; + break; + + case RLC_OP_STATUS_OUT_OF_RESSOURCES: + LOG_W(PDCP, "Data sending request over RLC failed with 'Out of Resources' reason!\n"); + ret= FALSE; + break; + + default: + LOG_W(PDCP, "RLC returned an unknown status code after PDCP placed the order to send some data (Status Code:%d)\n", rlc_status); + ret= FALSE; + break; } if (ctxt_pP->enb_flag == ENB_FLAG_YES) { @@ -418,7 +406,7 @@ boolean_t pdcp_data_req( * so we return TRUE afterwards */ - for (pdcp_uid=0; pdcp_uid< MAX_MOBILES_PER_ENB;pdcp_uid++){ + for (pdcp_uid=0; pdcp_uid< MAX_MOBILES_PER_ENB; pdcp_uid++) { if (pdcp_enb[ctxt_pP->module_id].rnti[pdcp_uid] == ctxt_pP->rnti ) break; } @@ -429,26 +417,23 @@ boolean_t pdcp_data_req( Pdcp_stats_tx_bytes[ctxt_pP->module_id][pdcp_uid][rb_idP+rb_offset]+=sdu_buffer_sizeP; Pdcp_stats_tx_bytes_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_idP+rb_offset]+=sdu_buffer_sizeP; Pdcp_stats_tx_sn[ctxt_pP->module_id][pdcp_uid][rb_idP+rb_offset]=current_sn; - Pdcp_stats_tx_aiat[ctxt_pP->module_id][pdcp_uid][rb_idP+rb_offset]+= (pdcp_enb[ctxt_pP->module_id].sfn - Pdcp_stats_tx_iat[ctxt_pP->module_id][pdcp_uid][rb_idP+rb_offset]); - Pdcp_stats_tx_aiat_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_idP+rb_offset]+= (pdcp_enb[ctxt_pP->module_id].sfn - Pdcp_stats_tx_iat[ctxt_pP->module_id][pdcp_uid][rb_idP+rb_offset]); + Pdcp_stats_tx_aiat_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_idP+rb_offset]+= (pdcp_enb[ctxt_pP->module_id].sfn - Pdcp_stats_tx_iat[ctxt_pP->module_id][pdcp_uid][rb_idP+rb_offset]); Pdcp_stats_tx_iat[ctxt_pP->module_id][pdcp_uid][rb_idP+rb_offset]=pdcp_enb[ctxt_pP->module_id].sfn; - VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PDCP_DATA_REQ,VCD_FUNCTION_OUT); return ret; - } //----------------------------------------------------------------------------- boolean_t pdcp_data_ind( - const protocol_ctxt_t* const ctxt_pP, + const protocol_ctxt_t *const ctxt_pP, const srb_flag_t srb_flagP, const MBMS_flag_t MBMS_flagP, const rb_id_t rb_idP, const sdu_size_t sdu_buffer_sizeP, - mem_block_t* const sdu_buffer_pP + mem_block_t *const sdu_buffer_pP ) //----------------------------------------------------------------------------- { @@ -464,22 +449,20 @@ pdcp_data_ind( hash_key_t key = HASHTABLE_NOT_A_KEY_VALUE; hashtable_rc_t h_rc; uint8_t rb_offset= (srb_flagP == 0) ? DTCH -1 :0; - uint16_t pdcp_uid=0; + uint16_t pdcp_uid=0; uint8_t oo_flag=0; #if defined(LINK_ENB_PDCP_TO_GTPV1U) MessageDef *message_p = NULL; uint8_t *gtpu_buffer_p = NULL; #endif - - VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PDCP_DATA_IND,VCD_FUNCTION_IN); LOG_DUMPMSG(PDCP,DEBUG_PDCP,(char *)sdu_buffer_pP->data,sdu_buffer_sizeP, "[MSG] PDCP UL %s PDU on rb_id %d\n", (srb_flagP)? "CONTROL" : "DATA", rb_idP); - - #if T_TRACER + if (ctxt_pP->enb_flag != ENB_FLAG_NO) T(T_ENB_PDCP_UL, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->rnti), T_INT(rb_idP), T_INT(sdu_buffer_sizeP)); + #endif if (MBMS_flagP) { @@ -498,7 +481,6 @@ pdcp_data_ind( rb_idP, sdu_buffer_sizeP, ctxt_pP->enb_flag); - } else { LOG_D(PDCP, "Data indication notification for PDCP entity from UE %x to eNB %u " "and radio bearer ID %d rlc sdu size %d ctxt_pP->enb_flag %d\n", @@ -508,7 +490,6 @@ pdcp_data_ind( sdu_buffer_sizeP, ctxt_pP->enb_flag); } - } else { rb_id = rb_idP % LTE_maxDRB; AssertError (rb_id < LTE_maxDRB, return FALSE, "RB id is too high (%u/%d) %u UE %x!\n", @@ -522,7 +503,7 @@ pdcp_data_ind( ctxt_pP->module_id, ctxt_pP->rnti); key = PDCP_COLL_KEY_VALUE(ctxt_pP->module_id, ctxt_pP->rnti, ctxt_pP->enb_flag, rb_id, srb_flagP); - h_rc = hashtable_get(pdcp_coll_p, key, (void**)&pdcp_p); + h_rc = hashtable_get(pdcp_coll_p, key, (void **)&pdcp_p); if (h_rc != HASH_TABLE_OK) { LOG_W(PDCP, @@ -557,16 +538,16 @@ pdcp_data_ind( if (srb_flagP) { //SRB1/2 pdcp_header_len = PDCP_CONTROL_PLANE_DATA_PDU_SN_SIZE; pdcp_tailer_len = PDCP_CONTROL_PLANE_DATA_PDU_MAC_I_SIZE; - sequence_number = pdcp_get_sequence_number_of_pdu_with_SRB_sn((unsigned char*)sdu_buffer_pP->data); + sequence_number = pdcp_get_sequence_number_of_pdu_with_SRB_sn((unsigned char *)sdu_buffer_pP->data); } else { // DRB pdcp_tailer_len = 0; if (pdcp_p->seq_num_size == PDCP_SN_7BIT) { pdcp_header_len = PDCP_USER_PLANE_DATA_PDU_SHORT_SN_HEADER_SIZE; - sequence_number = pdcp_get_sequence_number_of_pdu_with_short_sn((unsigned char*)sdu_buffer_pP->data); + sequence_number = pdcp_get_sequence_number_of_pdu_with_short_sn((unsigned char *)sdu_buffer_pP->data); } else if (pdcp_p->seq_num_size == PDCP_SN_12BIT) { pdcp_header_len = PDCP_USER_PLANE_DATA_PDU_LONG_SN_HEADER_SIZE; - sequence_number = pdcp_get_sequence_number_of_pdu_with_long_sn((unsigned char*)sdu_buffer_pP->data); + sequence_number = pdcp_get_sequence_number_of_pdu_with_long_sn((unsigned char *)sdu_buffer_pP->data); } else { //sequence_number = 4095; LOG_E(PDCP, @@ -648,19 +629,18 @@ pdcp_data_ind( #endif //rrc_lite_data_ind(module_id, //Modified MW - L2 Interface - MSC_LOG_TX_MESSAGE( - (ctxt_pP->enb_flag == ENB_FLAG_NO)? MSC_PDCP_UE:MSC_PDCP_ENB, + MSC_LOG_TX_MESSAGE( + (ctxt_pP->enb_flag == ENB_FLAG_NO)? MSC_PDCP_UE:MSC_PDCP_ENB, (ctxt_pP->enb_flag == ENB_FLAG_NO)? MSC_RRC_UE:MSC_RRC_ENB, NULL,0, PROTOCOL_PDCP_CTXT_FMT" DATA-IND len %u", PROTOCOL_PDCP_CTXT_ARGS(ctxt_pP, pdcp_p), sdu_buffer_sizeP - pdcp_header_len - pdcp_tailer_len); - rrc_data_ind(ctxt_pP, - rb_id, - sdu_buffer_sizeP - pdcp_header_len - pdcp_tailer_len, - (uint8_t*)&sdu_buffer_pP->data[pdcp_header_len]); - free_mem_block(sdu_buffer_pP, __func__); - + rrc_data_ind(ctxt_pP, + rb_id, + sdu_buffer_sizeP - pdcp_header_len - pdcp_tailer_len, + (uint8_t *)&sdu_buffer_pP->data[pdcp_header_len]); + free_mem_block(sdu_buffer_pP, __func__); // free_mem_block(new_sdu, __func__); if (ctxt_pP->enb_flag) { @@ -701,7 +681,6 @@ pdcp_data_ind( } else { stop_meas(&UE_pdcp_stats[ctxt_pP->module_id].validate_security); } - } #endif @@ -724,7 +703,6 @@ pdcp_data_ind( } // XXX Decompression would be done at this point - /* * After checking incoming sequence number PDCP header * has to be stripped off so here we copy SDU buffer starting @@ -735,13 +713,13 @@ pdcp_data_ind( if ((TRUE == ctxt_pP->enb_flag) && (FALSE == srb_flagP)) { MSC_LOG_TX_MESSAGE( - MSC_PDCP_ENB, - MSC_GTPU_ENB, - NULL,0, - "0 GTPV1U_ENB_TUNNEL_DATA_REQ ue %x rab %u len %u", - ctxt_pP->rnti, - rb_id + 4, - sdu_buffer_sizeP - payload_offset); + MSC_PDCP_ENB, + MSC_GTPU_ENB, + NULL,0, + "0 GTPV1U_ENB_TUNNEL_DATA_REQ ue %x rab %u len %u", + ctxt_pP->rnti, + rb_id + 4, + sdu_buffer_sizeP - payload_offset); //LOG_T(PDCP,"Sending to GTPV1U %d bytes\n", sdu_buffer_sizeP - payload_offset); gtpu_buffer_p = itti_malloc(TASK_PDCP_ENB, TASK_GTPV1_U, sdu_buffer_sizeP - payload_offset + GTPU_HEADER_OVERHEAD_MAX); @@ -755,26 +733,25 @@ pdcp_data_ind( GTPV1U_ENB_TUNNEL_DATA_REQ(message_p).rnti = ctxt_pP->rnti; GTPV1U_ENB_TUNNEL_DATA_REQ(message_p).rab_id = rb_id + 4; itti_send_msg_to_task(TASK_GTPV1_U, INSTANCE_DEFAULT, message_p); - packet_forwarded = TRUE; + packet_forwarded = TRUE; } - + #else packet_forwarded = FALSE; #endif - #ifdef MBMS_MULTICAST_OUT + if ((MBMS_flagP != 0) && (mbms_socket != -1)) { - struct iphdr *ip_header = (struct iphdr*)&sdu_buffer_pP->data[payload_offset]; - struct udphdr *udp_header = (struct udphdr*)&sdu_buffer_pP->data[payload_offset + sizeof(struct iphdr)]; + struct iphdr *ip_header = (struct iphdr *)&sdu_buffer_pP->data[payload_offset]; + struct udphdr *udp_header = (struct udphdr *)&sdu_buffer_pP->data[payload_offset + sizeof(struct iphdr)]; struct sockaddr_in dest_addr; - dest_addr.sin_family = AF_INET; dest_addr.sin_port = udp_header->dest; dest_addr.sin_addr.s_addr = ip_header->daddr; - - sendto(mbms_socket, &sdu_buffer_pP->data[payload_offset], sdu_buffer_sizeP - payload_offset, MSG_DONTWAIT, (struct sockaddr*)&dest_addr, sizeof(dest_addr)); + sendto(mbms_socket, &sdu_buffer_pP->data[payload_offset], sdu_buffer_sizeP - payload_offset, MSG_DONTWAIT, (struct sockaddr *)&dest_addr, sizeof(dest_addr)); packet_forwarded = TRUE; } + #endif if (FALSE == packet_forwarded) { @@ -797,84 +774,79 @@ pdcp_data_ind( if (ctxt_pP->enb_flag == ENB_FLAG_NO) { ((pdcp_data_ind_header_t *) new_sdu_p->data)->rb_id = rb_id; #if defined(ENABLE_USE_MME) + /* for the UE compiled in S1 mode, we need 1 here * for the UE compiled in noS1 mode, we need 0 * TODO: be sure of this */ if (nfapi_mode == 3) { #ifdef UESIM_EXPANSION - ((pdcp_data_ind_header_t*) new_sdu_p->data)->inst = 0; + ((pdcp_data_ind_header_t *) new_sdu_p->data)->inst = 0; #else - ((pdcp_data_ind_header_t*) new_sdu_p->data)->inst = ctxt_pP->module_id; + ((pdcp_data_ind_header_t *) new_sdu_p->data)->inst = ctxt_pP->module_id; #endif } else { - ((pdcp_data_ind_header_t*) new_sdu_p->data)->inst = 1; + ((pdcp_data_ind_header_t *) new_sdu_p->data)->inst = 1; } + #endif } else { - ((pdcp_data_ind_header_t*) new_sdu_p->data)->rb_id = rb_id + (ctxt_pP->module_id * LTE_maxDRB); - ((pdcp_data_ind_header_t*) new_sdu_p->data)->inst = ctxt_pP->module_id; + ((pdcp_data_ind_header_t *) new_sdu_p->data)->rb_id = rb_id + (ctxt_pP->module_id * LTE_maxDRB); + ((pdcp_data_ind_header_t *) new_sdu_p->data)->inst = ctxt_pP->module_id; } + // new_sdu_p->data->inst is set again in UE case so move to above. //Panos: Commented this out because it cancels the assignment in #if defined(ENABLE_USE_MME) case //((pdcp_data_ind_header_t*) new_sdu_p->data)->inst = ctxt_pP->module_id; - #ifdef DEBUG_PDCP_FIFO_FLUSH_SDU static uint32_t pdcp_inst = 0; - ((pdcp_data_ind_header_t*) new_sdu_p->data)->inst = pdcp_inst++; - LOG_D(PDCP, "inst=%d size=%d\n", ((pdcp_data_ind_header_t*) new_sdu_p->data)->inst, ((pdcp_data_ind_header_t *) new_sdu_p->data)->data_size); + ((pdcp_data_ind_header_t *) new_sdu_p->data)->inst = pdcp_inst++; + LOG_D(PDCP, "inst=%d size=%d\n", ((pdcp_data_ind_header_t *) new_sdu_p->data)->inst, ((pdcp_data_ind_header_t *) new_sdu_p->data)->data_size); #endif //((pdcp_data_ind_header_t*) new_sdu_p->data)->inst = 1; //pdcp_inst++; - memcpy(&new_sdu_p->data[sizeof (pdcp_data_ind_header_t)], \ &sdu_buffer_pP->data[payload_offset], \ sdu_buffer_sizeP - payload_offset); list_add_tail_eurecom (new_sdu_p, sdu_list_p); - - - } - /* Print octets of incoming data in hexadecimal form */ - LOG_D(PDCP, "Following content has been received from RLC (%d,%d)(PDCP header has already been removed):\n", - sdu_buffer_sizeP - payload_offset + (int)sizeof(pdcp_data_ind_header_t), - sdu_buffer_sizeP - payload_offset); - //util_print_hex_octets(PDCP, &new_sdu_p->data[sizeof (pdcp_data_ind_header_t)], sdu_buffer_sizeP - payload_offset); - //util_flush_hex_octets(PDCP, &new_sdu_p->data[sizeof (pdcp_data_ind_header_t)], sdu_buffer_sizeP - payload_offset); - - /* - * Update PDCP statistics - * XXX Following two actions are identical, is there a merge error? - */ - - for (pdcp_uid=0; pdcp_uid< MAX_MOBILES_PER_ENB;pdcp_uid++){ - if (pdcp_enb[ctxt_pP->module_id].rnti[pdcp_uid] == ctxt_pP->rnti ){ - break; + /* Print octets of incoming data in hexadecimal form */ + LOG_D(PDCP, "Following content has been received from RLC (%d,%d)(PDCP header has already been removed):\n", + sdu_buffer_sizeP - payload_offset + (int)sizeof(pdcp_data_ind_header_t), + sdu_buffer_sizeP - payload_offset); + //util_print_hex_octets(PDCP, &new_sdu_p->data[sizeof (pdcp_data_ind_header_t)], sdu_buffer_sizeP - payload_offset); + //util_flush_hex_octets(PDCP, &new_sdu_p->data[sizeof (pdcp_data_ind_header_t)], sdu_buffer_sizeP - payload_offset); + + /* + * Update PDCP statistics + * XXX Following two actions are identical, is there a merge error? + */ + + for (pdcp_uid=0; pdcp_uid< MAX_MOBILES_PER_ENB; pdcp_uid++) { + if (pdcp_enb[ctxt_pP->module_id].rnti[pdcp_uid] == ctxt_pP->rnti ) { + break; + } } - } - - Pdcp_stats_rx[ctxt_pP->module_id][pdcp_uid][rb_idP+rb_offset]++; - Pdcp_stats_rx_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_idP+rb_offset]++; - Pdcp_stats_rx_bytes[ctxt_pP->module_id][pdcp_uid][rb_idP+rb_offset]+=(sdu_buffer_sizeP - payload_offset); - Pdcp_stats_rx_bytes_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_idP+rb_offset]+=(sdu_buffer_sizeP - payload_offset); - - Pdcp_stats_rx_sn[ctxt_pP->module_id][pdcp_uid][rb_idP+rb_offset]=sequence_number; - - if (oo_flag == 1 ) - Pdcp_stats_rx_outoforder[ctxt_pP->module_id][pdcp_uid][rb_idP+rb_offset]++; - - Pdcp_stats_rx_aiat[ctxt_pP->module_id][pdcp_uid][rb_idP+rb_offset]+= (pdcp_enb[ctxt_pP->module_id].sfn - Pdcp_stats_rx_iat[ctxt_pP->module_id][pdcp_uid][rb_idP+rb_offset]); - Pdcp_stats_rx_aiat_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_idP+rb_offset]+=(pdcp_enb[ctxt_pP->module_id].sfn - Pdcp_stats_rx_iat[ctxt_pP->module_id][pdcp_uid][rb_idP+rb_offset]); - Pdcp_stats_rx_iat[ctxt_pP->module_id][pdcp_uid][rb_idP+rb_offset]=pdcp_enb[ctxt_pP->module_id].sfn; - - + + Pdcp_stats_rx[ctxt_pP->module_id][pdcp_uid][rb_idP+rb_offset]++; + Pdcp_stats_rx_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_idP+rb_offset]++; + Pdcp_stats_rx_bytes[ctxt_pP->module_id][pdcp_uid][rb_idP+rb_offset]+=(sdu_buffer_sizeP - payload_offset); + Pdcp_stats_rx_bytes_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_idP+rb_offset]+=(sdu_buffer_sizeP - payload_offset); + Pdcp_stats_rx_sn[ctxt_pP->module_id][pdcp_uid][rb_idP+rb_offset]=sequence_number; + + if (oo_flag == 1 ) + Pdcp_stats_rx_outoforder[ctxt_pP->module_id][pdcp_uid][rb_idP+rb_offset]++; + + Pdcp_stats_rx_aiat[ctxt_pP->module_id][pdcp_uid][rb_idP+rb_offset]+= (pdcp_enb[ctxt_pP->module_id].sfn - Pdcp_stats_rx_iat[ctxt_pP->module_id][pdcp_uid][rb_idP+rb_offset]); + Pdcp_stats_rx_aiat_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_idP+rb_offset]+=(pdcp_enb[ctxt_pP->module_id].sfn - Pdcp_stats_rx_iat[ctxt_pP->module_id][pdcp_uid][rb_idP+rb_offset]); + Pdcp_stats_rx_iat[ctxt_pP->module_id][pdcp_uid][rb_idP+rb_offset]=pdcp_enb[ctxt_pP->module_id].sfn; #if defined(STOP_ON_IP_TRAFFIC_OVERLOAD) else { AssertFatal(0, PROTOCOL_PDCP_CTXT_FMT" PDCP_DATA_IND SDU DROPPED, OUT OF MEMORY \n", PROTOCOL_PDCP_CTXT_ARGS(ctxt_pP, pdcp_p)); } -#endif +#endif } free_mem_block(sdu_buffer_pP, __func__); @@ -889,63 +861,62 @@ pdcp_data_ind( return TRUE; } -void pdcp_update_stats(const protocol_ctxt_t* const ctxt_pP){ - +void pdcp_update_stats(const protocol_ctxt_t *const ctxt_pP) { uint16_t pdcp_uid = 0; uint8_t rb_id = 0; - - // these stats are measured for both eNB and UE on per seond basis - for (rb_id =0; rb_id < NB_RB_MAX; rb_id ++){ - for (pdcp_uid=0; pdcp_uid< MAX_MOBILES_PER_ENB;pdcp_uid++){ + + // these stats are measured for both eNB and UE on per seond basis + for (rb_id =0; rb_id < NB_RB_MAX; rb_id ++) { + for (pdcp_uid=0; pdcp_uid< MAX_MOBILES_PER_ENB; pdcp_uid++) { //printf("frame %d and subframe %d \n", pdcp_enb[ctxt_pP->module_id].frame, pdcp_enb[ctxt_pP->module_id].subframe); // tx stats if (Pdcp_stats_tx_window_ms[ctxt_pP->module_id][pdcp_uid] > 0 && - pdcp_enb[ctxt_pP->module_id].sfn % Pdcp_stats_tx_window_ms[ctxt_pP->module_id][pdcp_uid] == 0){ - // unit: bit/s - Pdcp_stats_tx_throughput_w[ctxt_pP->module_id][pdcp_uid][rb_id]=Pdcp_stats_tx_bytes_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_id]*8; - Pdcp_stats_tx_w[ctxt_pP->module_id][pdcp_uid][rb_id]= Pdcp_stats_tx_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_id]; - Pdcp_stats_tx_bytes_w[ctxt_pP->module_id][pdcp_uid][rb_id]= Pdcp_stats_tx_bytes_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_id]; - if (Pdcp_stats_tx_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_id] > 0){ - Pdcp_stats_tx_aiat_w[ctxt_pP->module_id][pdcp_uid][rb_id]=(Pdcp_stats_tx_aiat_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_id]/Pdcp_stats_tx_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_id]); - }else { - Pdcp_stats_tx_aiat_w[ctxt_pP->module_id][pdcp_uid][rb_id]=0; - } - // reset the tmp vars - Pdcp_stats_tx_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_id]=0; - Pdcp_stats_tx_bytes_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_id]=0; - Pdcp_stats_tx_aiat_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_id]=0; - + pdcp_enb[ctxt_pP->module_id].sfn % Pdcp_stats_tx_window_ms[ctxt_pP->module_id][pdcp_uid] == 0) { + // unit: bit/s + Pdcp_stats_tx_throughput_w[ctxt_pP->module_id][pdcp_uid][rb_id]=Pdcp_stats_tx_bytes_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_id]*8; + Pdcp_stats_tx_w[ctxt_pP->module_id][pdcp_uid][rb_id]= Pdcp_stats_tx_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_id]; + Pdcp_stats_tx_bytes_w[ctxt_pP->module_id][pdcp_uid][rb_id]= Pdcp_stats_tx_bytes_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_id]; + + if (Pdcp_stats_tx_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_id] > 0) { + Pdcp_stats_tx_aiat_w[ctxt_pP->module_id][pdcp_uid][rb_id]=(Pdcp_stats_tx_aiat_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_id]/Pdcp_stats_tx_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_id]); + } else { + Pdcp_stats_tx_aiat_w[ctxt_pP->module_id][pdcp_uid][rb_id]=0; + } + + // reset the tmp vars + Pdcp_stats_tx_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_id]=0; + Pdcp_stats_tx_bytes_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_id]=0; + Pdcp_stats_tx_aiat_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_id]=0; } + if (Pdcp_stats_rx_window_ms[ctxt_pP->module_id][pdcp_uid] > 0 && - pdcp_enb[ctxt_pP->module_id].sfn % Pdcp_stats_rx_window_ms[ctxt_pP->module_id][pdcp_uid] == 0){ - // rx stats - Pdcp_stats_rx_goodput_w[ctxt_pP->module_id][pdcp_uid][rb_id]=Pdcp_stats_rx_bytes_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_id]*8; - Pdcp_stats_rx_w[ctxt_pP->module_id][pdcp_uid][rb_id]= Pdcp_stats_rx_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_id]; - Pdcp_stats_rx_bytes_w[ctxt_pP->module_id][pdcp_uid][rb_id]= Pdcp_stats_rx_bytes_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_id]; - - if(Pdcp_stats_rx_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_id] > 0){ - Pdcp_stats_rx_aiat_w[ctxt_pP->module_id][pdcp_uid][rb_id]= (Pdcp_stats_rx_aiat_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_id]/Pdcp_stats_rx_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_id]); - } else { - Pdcp_stats_rx_aiat_w[ctxt_pP->module_id][pdcp_uid][rb_id]=0; - } - - // reset the tmp vars - Pdcp_stats_rx_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_id]=0; - Pdcp_stats_rx_bytes_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_id]=0; - Pdcp_stats_rx_aiat_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_id]=0; - } + pdcp_enb[ctxt_pP->module_id].sfn % Pdcp_stats_rx_window_ms[ctxt_pP->module_id][pdcp_uid] == 0) { + // rx stats + Pdcp_stats_rx_goodput_w[ctxt_pP->module_id][pdcp_uid][rb_id]=Pdcp_stats_rx_bytes_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_id]*8; + Pdcp_stats_rx_w[ctxt_pP->module_id][pdcp_uid][rb_id]= Pdcp_stats_rx_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_id]; + Pdcp_stats_rx_bytes_w[ctxt_pP->module_id][pdcp_uid][rb_id]= Pdcp_stats_rx_bytes_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_id]; + + if(Pdcp_stats_rx_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_id] > 0) { + Pdcp_stats_rx_aiat_w[ctxt_pP->module_id][pdcp_uid][rb_id]= (Pdcp_stats_rx_aiat_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_id]/Pdcp_stats_rx_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_id]); + } else { + Pdcp_stats_rx_aiat_w[ctxt_pP->module_id][pdcp_uid][rb_id]=0; + } + + // reset the tmp vars + Pdcp_stats_rx_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_id]=0; + Pdcp_stats_rx_bytes_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_id]=0; + Pdcp_stats_rx_aiat_tmp_w[ctxt_pP->module_id][pdcp_uid][rb_id]=0; + } } - } } //----------------------------------------------------------------------------- void pdcp_run ( - const protocol_ctxt_t* const ctxt_pP + const protocol_ctxt_t *const ctxt_pP ) //----------------------------------------------------------------------------- { - if (ctxt_pP->enb_flag) { start_meas(&eNB_pdcp_stats[ctxt_pP->module_id].pdcp_run); } else { @@ -953,12 +924,10 @@ pdcp_run ( } pdcp_enb[ctxt_pP->module_id].sfn++; // range: 0 to 18,446,744,073,709,551,615 - pdcp_enb[ctxt_pP->module_id].frame=ctxt_pP->frame; // 1023 + pdcp_enb[ctxt_pP->module_id].frame=ctxt_pP->frame; // 1023 pdcp_enb[ctxt_pP->module_id].subframe= ctxt_pP->subframe; pdcp_update_stats(ctxt_pP); - VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PDCP_RUN, VCD_FUNCTION_IN); - #if defined(ENABLE_ITTI) MessageDef *msg_p; int result; @@ -969,66 +938,66 @@ pdcp_run ( itti_poll_msg (ctxt_pP->enb_flag ? TASK_PDCP_ENB : TASK_PDCP_UE, &msg_p); if (msg_p != NULL) { - switch (ITTI_MSG_ID(msg_p)) { - case RRC_DCCH_DATA_REQ: - PROTOCOL_CTXT_SET_BY_MODULE_ID( - &ctxt, - RRC_DCCH_DATA_REQ (msg_p).module_id, - RRC_DCCH_DATA_REQ (msg_p).enb_flag, - RRC_DCCH_DATA_REQ (msg_p).rnti, - RRC_DCCH_DATA_REQ (msg_p).frame, - 0, - RRC_DCCH_DATA_REQ (msg_p).eNB_index); - LOG_D(PDCP, PROTOCOL_CTXT_FMT"Received %s from %s: instance %d, rb_id %d, muiP %d, confirmP %d, mode %d\n", - PROTOCOL_CTXT_ARGS(&ctxt), - ITTI_MSG_NAME (msg_p), - ITTI_MSG_ORIGIN_NAME(msg_p), - ITTI_MSG_INSTANCE (msg_p), - RRC_DCCH_DATA_REQ (msg_p).rb_id, - RRC_DCCH_DATA_REQ (msg_p).muip, - RRC_DCCH_DATA_REQ (msg_p).confirmp, - RRC_DCCH_DATA_REQ (msg_p).mode); - - LOG_D(PDCP, "Before calling pdcp_data_req from pdcp_run! RRC_DCCH_DATA_REQ (msg_p).rb_id: %d \n", RRC_DCCH_DATA_REQ (msg_p).rb_id); - result = pdcp_data_req (&ctxt, - SRB_FLAG_YES, - RRC_DCCH_DATA_REQ (msg_p).rb_id, - RRC_DCCH_DATA_REQ (msg_p).muip, - RRC_DCCH_DATA_REQ (msg_p).confirmp, - RRC_DCCH_DATA_REQ (msg_p).sdu_size, - RRC_DCCH_DATA_REQ (msg_p).sdu_p, - RRC_DCCH_DATA_REQ (msg_p).mode + case RRC_DCCH_DATA_REQ: + PROTOCOL_CTXT_SET_BY_MODULE_ID( + &ctxt, + RRC_DCCH_DATA_REQ (msg_p).module_id, + RRC_DCCH_DATA_REQ (msg_p).enb_flag, + RRC_DCCH_DATA_REQ (msg_p).rnti, + RRC_DCCH_DATA_REQ (msg_p).frame, + 0, + RRC_DCCH_DATA_REQ (msg_p).eNB_index); + LOG_D(PDCP, PROTOCOL_CTXT_FMT"Received %s from %s: instance %d, rb_id %d, muiP %d, confirmP %d, mode %d\n", + PROTOCOL_CTXT_ARGS(&ctxt), + ITTI_MSG_NAME (msg_p), + ITTI_MSG_ORIGIN_NAME(msg_p), + ITTI_MSG_INSTANCE (msg_p), + RRC_DCCH_DATA_REQ (msg_p).rb_id, + RRC_DCCH_DATA_REQ (msg_p).muip, + RRC_DCCH_DATA_REQ (msg_p).confirmp, + RRC_DCCH_DATA_REQ (msg_p).mode); + LOG_D(PDCP, "Before calling pdcp_data_req from pdcp_run! RRC_DCCH_DATA_REQ (msg_p).rb_id: %d \n", RRC_DCCH_DATA_REQ (msg_p).rb_id); + result = pdcp_data_req (&ctxt, + SRB_FLAG_YES, + RRC_DCCH_DATA_REQ (msg_p).rb_id, + RRC_DCCH_DATA_REQ (msg_p).muip, + RRC_DCCH_DATA_REQ (msg_p).confirmp, + RRC_DCCH_DATA_REQ (msg_p).sdu_size, + RRC_DCCH_DATA_REQ (msg_p).sdu_p, + RRC_DCCH_DATA_REQ (msg_p).mode #if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0)) - , NULL, NULL + , NULL, NULL #endif - ); - if (result != TRUE) - LOG_E(PDCP, "PDCP data request failed!\n"); + ); - // Message buffer has been processed, free it now. - result = itti_free (ITTI_MSG_ORIGIN_ID(msg_p), RRC_DCCH_DATA_REQ (msg_p).sdu_p); - AssertFatal (result == EXIT_SUCCESS, "Failed to free memory (%d)!\n", result); - break; + if (result != TRUE) + LOG_E(PDCP, "PDCP data request failed!\n"); - case RRC_PCCH_DATA_REQ: - { - sdu_size_t sdu_buffer_sizeP; - sdu_buffer_sizeP = RRC_PCCH_DATA_REQ(msg_p).sdu_size; - uint8_t CC_id = RRC_PCCH_DATA_REQ(msg_p).CC_id; - uint8_t ue_index = RRC_PCCH_DATA_REQ(msg_p).ue_index; - RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sizeof_paging[ue_index] = sdu_buffer_sizeP; - if (sdu_buffer_sizeP > 0) { - memcpy(RC.rrc[ctxt_pP->module_id]->carrier[CC_id].paging[ue_index], RRC_PCCH_DATA_REQ(msg_p).sdu_p, sdu_buffer_sizeP); - } - //paging pdcp log - LOG_D(PDCP, "PDCP Received RRC_PCCH_DATA_REQ CC_id %d length %d \n", CC_id, sdu_buffer_sizeP); - } - break; + // Message buffer has been processed, free it now. + result = itti_free (ITTI_MSG_ORIGIN_ID(msg_p), RRC_DCCH_DATA_REQ (msg_p).sdu_p); + AssertFatal (result == EXIT_SUCCESS, "Failed to free memory (%d)!\n", result); + break; - default: - LOG_E(PDCP, "Received unexpected message %s\n", ITTI_MSG_NAME (msg_p)); + case RRC_PCCH_DATA_REQ: { + sdu_size_t sdu_buffer_sizeP; + sdu_buffer_sizeP = RRC_PCCH_DATA_REQ(msg_p).sdu_size; + uint8_t CC_id = RRC_PCCH_DATA_REQ(msg_p).CC_id; + uint8_t ue_index = RRC_PCCH_DATA_REQ(msg_p).ue_index; + RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sizeof_paging[ue_index] = sdu_buffer_sizeP; + + if (sdu_buffer_sizeP > 0) { + memcpy(RC.rrc[ctxt_pP->module_id]->carrier[CC_id].paging[ue_index], RRC_PCCH_DATA_REQ(msg_p).sdu_p, sdu_buffer_sizeP); + } + + //paging pdcp log + LOG_D(PDCP, "PDCP Received RRC_PCCH_DATA_REQ CC_id %d length %d \n", CC_id, sdu_buffer_sizeP); + } break; + + default: + LOG_E(PDCP, "Received unexpected message %s\n", ITTI_MSG_NAME (msg_p)); + break; } result = itti_free (ITTI_MSG_ORIGIN_ID(msg_p), msg_p); @@ -1037,7 +1006,6 @@ pdcp_run ( } while(msg_p != NULL); #endif - // IP/NAS -> PDCP traffic : TX, read the pkt from the upper layer buffer #if defined(LINK_ENB_PDCP_TO_GTPV1U) @@ -1050,9 +1018,7 @@ pdcp_run ( // PDCP -> NAS/IP traffic: RX if (ctxt_pP->enb_flag) { start_meas(&eNB_pdcp_stats[ctxt_pP->module_id].pdcp_ip); - } - - else { + } else { start_meas(&UE_pdcp_stats[ctxt_pP->module_id].pdcp_ip); } @@ -1069,36 +1035,40 @@ pdcp_run ( } else { stop_meas(&UE_pdcp_stats[ctxt_pP->module_id].pdcp_run); } + VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PDCP_RUN, VCD_FUNCTION_OUT); } -void pdcp_add_UE(const protocol_ctxt_t* const ctxt_pP){ +void pdcp_add_UE(const protocol_ctxt_t *const ctxt_pP) { int i, ue_flag=1; //, ret=-1; to be decied later - for (i=0; i < MAX_MOBILES_PER_ENB; i++){ + + for (i=0; i < MAX_MOBILES_PER_ENB; i++) { if (pdcp_enb[ctxt_pP->module_id].rnti[i] == ctxt_pP->rnti) { ue_flag=-1; break; } } - if (ue_flag == 1 ){ - for (i=0; i < MAX_MOBILES_PER_ENB ; i++){ - if (pdcp_enb[ctxt_pP->module_id].rnti[i] == 0 ){ - pdcp_enb[ctxt_pP->module_id].rnti[i]=ctxt_pP->rnti; - pdcp_enb[ctxt_pP->module_id].uid[i]=i; - pdcp_enb[ctxt_pP->module_id].num_ues++; - printf("add new uid is %d %x\n\n", i, ctxt_pP->rnti); - // ret=1; - break; + + if (ue_flag == 1 ) { + for (i=0; i < MAX_MOBILES_PER_ENB ; i++) { + if (pdcp_enb[ctxt_pP->module_id].rnti[i] == 0 ) { + pdcp_enb[ctxt_pP->module_id].rnti[i]=ctxt_pP->rnti; + pdcp_enb[ctxt_pP->module_id].uid[i]=i; + pdcp_enb[ctxt_pP->module_id].num_ues++; + printf("add new uid is %d %x\n\n", i, ctxt_pP->rnti); + // ret=1; + break; } } } + //return ret; } //----------------------------------------------------------------------------- boolean_t pdcp_remove_UE( - const protocol_ctxt_t* const ctxt_pP + const protocol_ctxt_t *const ctxt_pP ) //----------------------------------------------------------------------------- { @@ -1106,11 +1076,11 @@ pdcp_remove_UE( LTE_DRB_Identity_t drb_id = 0; hash_key_t key = HASHTABLE_NOT_A_KEY_VALUE; hashtable_rc_t h_rc; - int i; - // check and remove SRBs first + int i; + // check and remove SRBs first - for(int i = 0;i<MAX_MOBILES_PER_ENB;i++){ - if(pdcp_eNB_UE_instance_to_rnti[i] == ctxt_pP->rnti){ + for(int i = 0; i<MAX_MOBILES_PER_ENB; i++) { + if(pdcp_eNB_UE_instance_to_rnti[i] == ctxt_pP->rnti) { pdcp_eNB_UE_instance_to_rnti[i] = NOT_A_RNTI; break; } @@ -1124,24 +1094,23 @@ pdcp_remove_UE( for (drb_id=0; drb_id<LTE_maxDRB; drb_id++) { key = PDCP_COLL_KEY_VALUE(ctxt_pP->module_id, ctxt_pP->rnti, ctxt_pP->enb_flag, drb_id, SRB_FLAG_NO); h_rc = hashtable_remove(pdcp_coll_p, key); - } (void)h_rc; /* remove gcc warning "set but not used" */ // remove ue for pdcp enb inst - for (i=0; i < MAX_MOBILES_PER_ENB; i++) { + for (i=0; i < MAX_MOBILES_PER_ENB; i++) { if (pdcp_enb[ctxt_pP->module_id].rnti[i] == ctxt_pP->rnti ) { LOG_I(PDCP, "remove uid is %d/%d %x\n", i, - pdcp_enb[ctxt_pP->module_id].uid[i], - pdcp_enb[ctxt_pP->module_id].rnti[i]); + pdcp_enb[ctxt_pP->module_id].uid[i], + pdcp_enb[ctxt_pP->module_id].rnti[i]); pdcp_enb[ctxt_pP->module_id].uid[i]=0; pdcp_enb[ctxt_pP->module_id].rnti[i]=0; pdcp_enb[ctxt_pP->module_id].num_ues--; break; } } - + return 1; } @@ -1149,7 +1118,7 @@ pdcp_remove_UE( //----------------------------------------------------------------------------- boolean_t rrc_pdcp_config_asn1_req ( - const protocol_ctxt_t* const ctxt_pP, + const protocol_ctxt_t *const ctxt_pP, LTE_SRB_ToAddModList_t *const srb2add_list_pP, LTE_DRB_ToAddModList_t *const drb2add_list_pP, LTE_DRB_ToReleaseList_t *const drb2release_list_pP, @@ -1158,9 +1127,9 @@ rrc_pdcp_config_asn1_req ( uint8_t *const kRRCint_pP, uint8_t *const kUPenc_pP #if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0)) - ,LTE_PMCH_InfoList_r9_t* const pmch_InfoList_r9_pP + ,LTE_PMCH_InfoList_r9_t *const pmch_InfoList_r9_pP #endif - ,rb_id_t *const defaultDRB + ,rb_id_t *const defaultDRB ) //----------------------------------------------------------------------------- { @@ -1179,7 +1148,6 @@ rrc_pdcp_config_asn1_req ( LTE_SRB_ToAddMod_t *srb_toaddmod_p = NULL; LTE_DRB_ToAddMod_t *drb_toaddmod_p = NULL; pdcp_t *pdcp_p = NULL; - hash_key_t key = HASHTABLE_NOT_A_KEY_VALUE; hashtable_rc_t h_rc; hash_key_t key_defaultDRB = HASHTABLE_NOT_A_KEY_VALUE; @@ -1189,7 +1157,6 @@ rrc_pdcp_config_asn1_req ( LTE_MBMS_SessionInfoList_r9_t *mbms_SessionInfoList_r9_p = NULL; LTE_MBMS_SessionInfo_r9_t *MBMS_SessionInfo_p = NULL; #endif - LOG_T(PDCP, PROTOCOL_CTXT_FMT" %s() SRB2ADD %p DRB2ADD %p DRB2RELEASE %p\n", PROTOCOL_CTXT_ARGS(ctxt_pP), __FUNCTION__, @@ -1206,7 +1173,7 @@ rrc_pdcp_config_asn1_req ( rlc_type = RLC_MODE_AM; lc_id = srb_id; key = PDCP_COLL_KEY_VALUE(ctxt_pP->module_id, ctxt_pP->rnti, ctxt_pP->enb_flag, srb_id, SRB_FLAG_YES); - h_rc = hashtable_get(pdcp_coll_p, key, (void**)&pdcp_p); + h_rc = hashtable_get(pdcp_coll_p, key, (void **)&pdcp_p); if (h_rc == HASH_TABLE_OK) { action = CONFIG_ACTION_MODIFY; @@ -1224,9 +1191,8 @@ rrc_pdcp_config_asn1_req ( key); free(pdcp_p); return TRUE; - - } else { - LOG_D(PDCP, PROTOCOL_PDCP_CTXT_FMT" CONFIG_ACTION_ADD key 0x%"PRIx64"\n", + } else { + LOG_D(PDCP, PROTOCOL_PDCP_CTXT_FMT" CONFIG_ACTION_ADD key 0x%"PRIx64"\n", PROTOCOL_PDCP_CTXT_ARGS(ctxt_pP, pdcp_p), key); } @@ -1234,15 +1200,37 @@ rrc_pdcp_config_asn1_req ( if (srb_toaddmod_p->rlc_Config) { switch (srb_toaddmod_p->rlc_Config->present) { - case LTE_SRB_ToAddMod__rlc_Config_PR_NOTHING: - break; + case LTE_SRB_ToAddMod__rlc_Config_PR_NOTHING: + break; + + case LTE_SRB_ToAddMod__rlc_Config_PR_explicitValue: + switch (srb_toaddmod_p->rlc_Config->choice.explicitValue.present) { + case LTE_RLC_Config_PR_NOTHING: + break; + + default: + pdcp_config_req_asn1 ( + ctxt_pP, + pdcp_p, + SRB_FLAG_YES, + rlc_type, + action, + lc_id, + mch_id, + srb_id, + srb_sn, + 0, // drb_report + 0, // header compression + security_modeP, + kRRCenc_pP, + kRRCint_pP, + kUPenc_pP); + break; + } - case LTE_SRB_ToAddMod__rlc_Config_PR_explicitValue: - switch (srb_toaddmod_p->rlc_Config->choice.explicitValue.present) { - case LTE_RLC_Config_PR_NOTHING: break; - default: + case LTE_SRB_ToAddMod__rlc_Config_PR_defaultValue: pdcp_config_req_asn1 ( ctxt_pP, pdcp_p, @@ -1259,34 +1247,12 @@ rrc_pdcp_config_asn1_req ( kRRCenc_pP, kRRCint_pP, kUPenc_pP); + // already the default values break; - } - - break; - - case LTE_SRB_ToAddMod__rlc_Config_PR_defaultValue: - pdcp_config_req_asn1 ( - ctxt_pP, - pdcp_p, - SRB_FLAG_YES, - rlc_type, - action, - lc_id, - mch_id, - srb_id, - srb_sn, - 0, // drb_report - 0, // header compression - security_modeP, - kRRCenc_pP, - kRRCint_pP, - kUPenc_pP); - // already the default values - break; - default: - DevParam(srb_toaddmod_p->rlc_Config->present, ctxt_pP->module_id, ctxt_pP->rnti); - break; + default: + DevParam(srb_toaddmod_p->rlc_Config->present, ctxt_pP->module_id, ctxt_pP->rnti); + break; } } } @@ -1296,10 +1262,9 @@ rrc_pdcp_config_asn1_req ( if (drb2add_list_pP != NULL) { for (cnt=0; cnt<drb2add_list_pP->list.count; cnt++) { - drb_toaddmod_p = drb2add_list_pP->list.array[cnt]; - drb_id = drb_toaddmod_p->drb_Identity;// + drb_id_offset; + if (drb_toaddmod_p->logicalChannelIdentity) { lc_id = *(drb_toaddmod_p->logicalChannelIdentity); } else { @@ -1315,14 +1280,13 @@ rrc_pdcp_config_asn1_req ( DevCheck4(drb_id < LTE_maxDRB, drb_id, LTE_maxDRB, ctxt_pP->module_id, ctxt_pP->rnti); key = PDCP_COLL_KEY_VALUE(ctxt_pP->module_id, ctxt_pP->rnti, ctxt_pP->enb_flag, drb_id, SRB_FLAG_NO); - h_rc = hashtable_get(pdcp_coll_p, key, (void**)&pdcp_p); + h_rc = hashtable_get(pdcp_coll_p, key, (void **)&pdcp_p); if (h_rc == HASH_TABLE_OK) { action = CONFIG_ACTION_MODIFY; LOG_D(PDCP, PROTOCOL_PDCP_CTXT_FMT" CONFIG_ACTION_MODIFY key 0x%"PRIx64"\n", PROTOCOL_PDCP_CTXT_ARGS(ctxt_pP, pdcp_p), key); - } else { action = CONFIG_ACTION_ADD; pdcp_p = calloc(1, sizeof(pdcp_t)); @@ -1352,7 +1316,7 @@ rrc_pdcp_config_asn1_req ( LOG_D(PDCP, PROTOCOL_PDCP_CTXT_FMT" CONFIG_ACTION_ADD ADD key 0x%"PRIx64"\n", PROTOCOL_PDCP_CTXT_ARGS(ctxt_pP, pdcp_p), key); - } + } } if (drb_toaddmod_p->pdcp_Config) { @@ -1372,44 +1336,44 @@ rrc_pdcp_config_asn1_req ( } switch (drb_toaddmod_p->pdcp_Config->headerCompression.present) { - case LTE_PDCP_Config__headerCompression_PR_NOTHING: - case LTE_PDCP_Config__headerCompression_PR_notUsed: - header_compression_profile=0x0; - break; - - case LTE_PDCP_Config__headerCompression_PR_rohc: - - // parse the struc and get the rohc profile - if(drb_toaddmod_p->pdcp_Config->headerCompression.choice.rohc.profiles.profile0x0001) { - header_compression_profile=0x0001; - } else if(drb_toaddmod_p->pdcp_Config->headerCompression.choice.rohc.profiles.profile0x0002) { - header_compression_profile=0x0002; - } else if(drb_toaddmod_p->pdcp_Config->headerCompression.choice.rohc.profiles.profile0x0003) { - header_compression_profile=0x0003; - } else if(drb_toaddmod_p->pdcp_Config->headerCompression.choice.rohc.profiles.profile0x0004) { - header_compression_profile=0x0004; - } else if(drb_toaddmod_p->pdcp_Config->headerCompression.choice.rohc.profiles.profile0x0006) { - header_compression_profile=0x0006; - } else if(drb_toaddmod_p->pdcp_Config->headerCompression.choice.rohc.profiles.profile0x0101) { - header_compression_profile=0x0101; - } else if(drb_toaddmod_p->pdcp_Config->headerCompression.choice.rohc.profiles.profile0x0102) { - header_compression_profile=0x0102; - } else if(drb_toaddmod_p->pdcp_Config->headerCompression.choice.rohc.profiles.profile0x0103) { - header_compression_profile=0x0103; - } else if(drb_toaddmod_p->pdcp_Config->headerCompression.choice.rohc.profiles.profile0x0104) { - header_compression_profile=0x0104; - } else { + case LTE_PDCP_Config__headerCompression_PR_NOTHING: + case LTE_PDCP_Config__headerCompression_PR_notUsed: header_compression_profile=0x0; - LOG_W(PDCP,"unknown header compresion profile\n"); - } + break; - // set the applicable profile - break; + case LTE_PDCP_Config__headerCompression_PR_rohc: + + // parse the struc and get the rohc profile + if(drb_toaddmod_p->pdcp_Config->headerCompression.choice.rohc.profiles.profile0x0001) { + header_compression_profile=0x0001; + } else if(drb_toaddmod_p->pdcp_Config->headerCompression.choice.rohc.profiles.profile0x0002) { + header_compression_profile=0x0002; + } else if(drb_toaddmod_p->pdcp_Config->headerCompression.choice.rohc.profiles.profile0x0003) { + header_compression_profile=0x0003; + } else if(drb_toaddmod_p->pdcp_Config->headerCompression.choice.rohc.profiles.profile0x0004) { + header_compression_profile=0x0004; + } else if(drb_toaddmod_p->pdcp_Config->headerCompression.choice.rohc.profiles.profile0x0006) { + header_compression_profile=0x0006; + } else if(drb_toaddmod_p->pdcp_Config->headerCompression.choice.rohc.profiles.profile0x0101) { + header_compression_profile=0x0101; + } else if(drb_toaddmod_p->pdcp_Config->headerCompression.choice.rohc.profiles.profile0x0102) { + header_compression_profile=0x0102; + } else if(drb_toaddmod_p->pdcp_Config->headerCompression.choice.rohc.profiles.profile0x0103) { + header_compression_profile=0x0103; + } else if(drb_toaddmod_p->pdcp_Config->headerCompression.choice.rohc.profiles.profile0x0104) { + header_compression_profile=0x0104; + } else { + header_compression_profile=0x0; + LOG_W(PDCP,"unknown header compresion profile\n"); + } + + // set the applicable profile + break; - default: - LOG_W(PDCP,PROTOCOL_PDCP_CTXT_FMT"[RB %ld] unknown drb_toaddmod->PDCP_Config->headerCompression->present \n", - PROTOCOL_PDCP_CTXT_ARGS(ctxt_pP,pdcp_p), drb_id); - break; + default: + LOG_W(PDCP,PROTOCOL_PDCP_CTXT_FMT"[RB %ld] unknown drb_toaddmod->PDCP_Config->headerCompression->present \n", + PROTOCOL_PDCP_CTXT_ARGS(ctxt_pP,pdcp_p), drb_id); + break; } pdcp_config_req_asn1 ( @@ -1437,7 +1401,7 @@ rrc_pdcp_config_asn1_req ( pdrb_id_p = drb2release_list_pP->list.array[cnt]; drb_id = *pdrb_id_p; key = PDCP_COLL_KEY_VALUE(ctxt_pP->module_id, ctxt_pP->rnti, ctxt_pP->enb_flag, drb_id, SRB_FLAG_NO); - h_rc = hashtable_get(pdcp_coll_p, key, (void**)&pdcp_p); + h_rc = hashtable_get(pdcp_coll_p, key, (void **)&pdcp_p); if (h_rc != HASH_TABLE_OK) { LOG_E(PDCP, PROTOCOL_CTXT_FMT" PDCP REMOVE FAILED drb_id %ld\n", @@ -1445,8 +1409,8 @@ rrc_pdcp_config_asn1_req ( drb_id); continue; } - lc_id = pdcp_p->lcid; + lc_id = pdcp_p->lcid; action = CONFIG_ACTION_REMOVE; pdcp_config_req_asn1 ( ctxt_pP, @@ -1469,7 +1433,7 @@ rrc_pdcp_config_asn1_req ( if ((defaultDRB != NULL) && (*defaultDRB == drb_id)) { // default DRB being removed. nevertheless this shouldn't happen as removing default DRB is not allowed in standard key_defaultDRB = PDCP_COLL_KEY_DEFAULT_DRB_VALUE(ctxt_pP->module_id, ctxt_pP->rnti, ctxt_pP->enb_flag); - h_defaultDRB_rc = hashtable_get(pdcp_coll_p, key_defaultDRB, (void**)&pdcp_p); + h_defaultDRB_rc = hashtable_get(pdcp_coll_p, key_defaultDRB, (void **)&pdcp_p); if (h_defaultDRB_rc == HASH_TABLE_OK) { h_defaultDRB_rc = hashtable_remove(pdcp_coll_p, key_defaultDRB); @@ -1490,12 +1454,14 @@ rrc_pdcp_config_asn1_req ( for (j=0; j<mbms_SessionInfoList_r9_p->list.count; j++) { MBMS_SessionInfo_p = mbms_SessionInfoList_r9_p->list.array[j]; + if (MBMS_SessionInfo_p->sessionId_r9) lc_id = MBMS_SessionInfo_p->sessionId_r9->buf[0]; else lc_id = MBMS_SessionInfo_p->logicalChannelIdentity_r9; + mch_id = MBMS_SessionInfo_p->tmgi_r9.serviceId_r9.buf[2]; //serviceId is 3-octet string -// mch_id = j; + // mch_id = j; // can set the mch_id = i if (ctxt_pP->enb_flag) { @@ -1517,13 +1483,12 @@ rrc_pdcp_config_asn1_req ( } LOG_D(PDCP, "lc_id (%02ld) mch_id(%02x,%02x,%02x) drb_id(%ld) action(%d)\n", - lc_id, - MBMS_SessionInfo_p->tmgi_r9.serviceId_r9.buf[0], - MBMS_SessionInfo_p->tmgi_r9.serviceId_r9.buf[1], - MBMS_SessionInfo_p->tmgi_r9.serviceId_r9.buf[2], - drb_id, - action); - + lc_id, + MBMS_SessionInfo_p->tmgi_r9.serviceId_r9.buf[0], + MBMS_SessionInfo_p->tmgi_r9.serviceId_r9.buf[1], + MBMS_SessionInfo_p->tmgi_r9.serviceId_r9.buf[2], + drb_id, + action); pdcp_config_req_asn1 ( ctxt_pP, NULL, // unused for MBMS @@ -1551,8 +1516,8 @@ rrc_pdcp_config_asn1_req ( //----------------------------------------------------------------------------- boolean_t pdcp_config_req_asn1 ( - const protocol_ctxt_t* const ctxt_pP, - pdcp_t * const pdcp_pP, + const protocol_ctxt_t *const ctxt_pP, + pdcp_t *const pdcp_pP, const srb_flag_t srb_flagP, const rlc_mode_t rlc_modeP, const config_action_t actionP, @@ -1568,179 +1533,183 @@ pdcp_config_req_asn1 ( uint8_t *const kUPenc_pP) //----------------------------------------------------------------------------- { - switch (actionP) { - case CONFIG_ACTION_ADD: - DevAssert(pdcp_pP != NULL); - if (ctxt_pP->enb_flag == ENB_FLAG_YES) { - pdcp_pP->is_ue = FALSE; - pdcp_add_UE(ctxt_pP); - - //pdcp_eNB_UE_instance_to_rnti[ctxtP->module_id] = ctxt_pP->rnti; -// pdcp_eNB_UE_instance_to_rnti[pdcp_eNB_UE_instance_to_rnti_index] = ctxt_pP->rnti; - if( srb_flagP == SRB_FLAG_NO ) { - for(int i = 0;i<MAX_MOBILES_PER_ENB;i++){ - if(pdcp_eNB_UE_instance_to_rnti[pdcp_eNB_UE_instance_to_rnti_index] == NOT_A_RNTI){ - break; - } - pdcp_eNB_UE_instance_to_rnti_index = (pdcp_eNB_UE_instance_to_rnti_index + 1) % MAX_MOBILES_PER_ENB; + case CONFIG_ACTION_ADD: + DevAssert(pdcp_pP != NULL); + + if (ctxt_pP->enb_flag == ENB_FLAG_YES) { + pdcp_pP->is_ue = FALSE; + pdcp_add_UE(ctxt_pP); + + //pdcp_eNB_UE_instance_to_rnti[ctxtP->module_id] = ctxt_pP->rnti; + // pdcp_eNB_UE_instance_to_rnti[pdcp_eNB_UE_instance_to_rnti_index] = ctxt_pP->rnti; + if( srb_flagP == SRB_FLAG_NO ) { + for(int i = 0; i<MAX_MOBILES_PER_ENB; i++) { + if(pdcp_eNB_UE_instance_to_rnti[pdcp_eNB_UE_instance_to_rnti_index] == NOT_A_RNTI) { + break; + } + + pdcp_eNB_UE_instance_to_rnti_index = (pdcp_eNB_UE_instance_to_rnti_index + 1) % MAX_MOBILES_PER_ENB; } + pdcp_eNB_UE_instance_to_rnti[pdcp_eNB_UE_instance_to_rnti_index] = ctxt_pP->rnti; pdcp_eNB_UE_instance_to_rnti_index = (pdcp_eNB_UE_instance_to_rnti_index + 1) % MAX_MOBILES_PER_ENB; + } + + //pdcp_eNB_UE_instance_to_rnti_index = (pdcp_eNB_UE_instance_to_rnti_index + 1) % MAX_MOBILES_PER_ENB; + } else { + pdcp_pP->is_ue = TRUE; + pdcp_UE_UE_module_id_to_rnti[ctxt_pP->module_id] = ctxt_pP->rnti; } - //pdcp_eNB_UE_instance_to_rnti_index = (pdcp_eNB_UE_instance_to_rnti_index + 1) % MAX_MOBILES_PER_ENB; - } else { - pdcp_pP->is_ue = TRUE; - pdcp_UE_UE_module_id_to_rnti[ctxt_pP->module_id] = ctxt_pP->rnti; - } - pdcp_pP->is_srb = (srb_flagP == SRB_FLAG_YES) ? TRUE : FALSE; - pdcp_pP->lcid = lc_idP; - pdcp_pP->rb_id = rb_idP; - pdcp_pP->header_compression_profile = header_compression_profileP; - pdcp_pP->status_report = rb_reportP; - - if (rb_snP == LTE_PDCP_Config__rlc_UM__pdcp_SN_Size_len12bits) { - pdcp_pP->seq_num_size = PDCP_SN_12BIT; - } else if (rb_snP == LTE_PDCP_Config__rlc_UM__pdcp_SN_Size_len7bits) { - pdcp_pP->seq_num_size = PDCP_SN_7BIT; - } else { - pdcp_pP->seq_num_size = PDCP_SN_5BIT; - } + pdcp_pP->is_srb = (srb_flagP == SRB_FLAG_YES) ? TRUE : FALSE; + pdcp_pP->lcid = lc_idP; + pdcp_pP->rb_id = rb_idP; + pdcp_pP->header_compression_profile = header_compression_profileP; + pdcp_pP->status_report = rb_reportP; - pdcp_pP->rlc_mode = rlc_modeP; - pdcp_pP->next_pdcp_tx_sn = 0; - pdcp_pP->next_pdcp_rx_sn = 0; - pdcp_pP->next_pdcp_rx_sn_before_integrity = 0; - pdcp_pP->tx_hfn = 0; - pdcp_pP->rx_hfn = 0; - pdcp_pP->last_submitted_pdcp_rx_sn = 4095; - pdcp_pP->first_missing_pdu = -1; - pdcp_pP->rx_hfn_offset = 0; + if (rb_snP == LTE_PDCP_Config__rlc_UM__pdcp_SN_Size_len12bits) { + pdcp_pP->seq_num_size = PDCP_SN_12BIT; + } else if (rb_snP == LTE_PDCP_Config__rlc_UM__pdcp_SN_Size_len7bits) { + pdcp_pP->seq_num_size = PDCP_SN_7BIT; + } else { + pdcp_pP->seq_num_size = PDCP_SN_5BIT; + } - LOG_I(PDCP, PROTOCOL_PDCP_CTXT_FMT" Action ADD LCID %d (%s id %d) " + pdcp_pP->rlc_mode = rlc_modeP; + pdcp_pP->next_pdcp_tx_sn = 0; + pdcp_pP->next_pdcp_rx_sn = 0; + pdcp_pP->next_pdcp_rx_sn_before_integrity = 0; + pdcp_pP->tx_hfn = 0; + pdcp_pP->rx_hfn = 0; + pdcp_pP->last_submitted_pdcp_rx_sn = 4095; + pdcp_pP->first_missing_pdu = -1; + pdcp_pP->rx_hfn_offset = 0; + LOG_I(PDCP, PROTOCOL_PDCP_CTXT_FMT" Action ADD LCID %d (%s id %d) " "configured with SN size %d bits and RLC %s\n", - PROTOCOL_PDCP_CTXT_ARGS(ctxt_pP,pdcp_pP), - lc_idP, - (srb_flagP == SRB_FLAG_YES) ? "SRB" : "DRB", + PROTOCOL_PDCP_CTXT_ARGS(ctxt_pP,pdcp_pP), + lc_idP, + (srb_flagP == SRB_FLAG_YES) ? "SRB" : "DRB", + rb_idP, + pdcp_pP->seq_num_size, + (rlc_modeP == RLC_MODE_AM ) ? "AM" : (rlc_modeP == RLC_MODE_TM) ? "TM" : "UM"); + + /* Setup security */ + if (security_modeP != 0xff) { + pdcp_config_set_security( + ctxt_pP, + pdcp_pP, rb_idP, - pdcp_pP->seq_num_size, - (rlc_modeP == RLC_MODE_AM ) ? "AM" : (rlc_modeP == RLC_MODE_TM) ? "TM" : "UM"); - /* Setup security */ - if (security_modeP != 0xff) { - pdcp_config_set_security( - ctxt_pP, - pdcp_pP, - rb_idP, - lc_idP, - security_modeP, - kRRCenc_pP, - kRRCint_pP, - kUPenc_pP); - } - break; + lc_idP, + security_modeP, + kRRCenc_pP, + kRRCint_pP, + kUPenc_pP); + } - case CONFIG_ACTION_MODIFY: - DevAssert(pdcp_pP != NULL); - pdcp_pP->header_compression_profile=header_compression_profileP; - pdcp_pP->status_report = rb_reportP; - pdcp_pP->rlc_mode = rlc_modeP; + break; - /* Setup security */ - if (security_modeP != 0xff) { - pdcp_config_set_security( - ctxt_pP, - pdcp_pP, - rb_idP, - lc_idP, - security_modeP, - kRRCenc_pP, - kRRCint_pP, - kUPenc_pP); - } + case CONFIG_ACTION_MODIFY: + DevAssert(pdcp_pP != NULL); + pdcp_pP->header_compression_profile=header_compression_profileP; + pdcp_pP->status_report = rb_reportP; + pdcp_pP->rlc_mode = rlc_modeP; - if (rb_snP == LTE_PDCP_Config__rlc_UM__pdcp_SN_Size_len7bits) { - pdcp_pP->seq_num_size = 7; - } else if (rb_snP == LTE_PDCP_Config__rlc_UM__pdcp_SN_Size_len12bits) { - pdcp_pP->seq_num_size = 12; - } else { - pdcp_pP->seq_num_size=5; - } + /* Setup security */ + if (security_modeP != 0xff) { + pdcp_config_set_security( + ctxt_pP, + pdcp_pP, + rb_idP, + lc_idP, + security_modeP, + kRRCenc_pP, + kRRCint_pP, + kUPenc_pP); + } - LOG_I(PDCP,PROTOCOL_PDCP_CTXT_FMT" Action MODIFY LCID %d " + if (rb_snP == LTE_PDCP_Config__rlc_UM__pdcp_SN_Size_len7bits) { + pdcp_pP->seq_num_size = 7; + } else if (rb_snP == LTE_PDCP_Config__rlc_UM__pdcp_SN_Size_len12bits) { + pdcp_pP->seq_num_size = 12; + } else { + pdcp_pP->seq_num_size=5; + } + + LOG_I(PDCP,PROTOCOL_PDCP_CTXT_FMT" Action MODIFY LCID %d " "RB id %d reconfigured with SN size %d and RLC %s \n", - PROTOCOL_PDCP_CTXT_ARGS(ctxt_pP,pdcp_pP), - lc_idP, - rb_idP, - rb_snP, + PROTOCOL_PDCP_CTXT_ARGS(ctxt_pP,pdcp_pP), + lc_idP, + rb_idP, + rb_snP, (rlc_modeP == RLC_MODE_AM) ? "AM" : (rlc_modeP == RLC_MODE_TM) ? "TM" : "UM"); - break; + break; - case CONFIG_ACTION_REMOVE: - DevAssert(pdcp_pP != NULL); -//#warning "TODO pdcp_module_id_to_rnti" - //pdcp_module_id_to_rnti[ctxt_pP.module_id ][dst_id] = NOT_A_RNTI; - LOG_D(PDCP, PROTOCOL_PDCP_CTXT_FMT" CONFIG_ACTION_REMOVE LCID %d RBID %d configured\n", - PROTOCOL_PDCP_CTXT_ARGS(ctxt_pP,pdcp_pP), - lc_idP, - rb_idP); + case CONFIG_ACTION_REMOVE: + DevAssert(pdcp_pP != NULL); + //#warning "TODO pdcp_module_id_to_rnti" + //pdcp_module_id_to_rnti[ctxt_pP.module_id ][dst_id] = NOT_A_RNTI; + LOG_D(PDCP, PROTOCOL_PDCP_CTXT_FMT" CONFIG_ACTION_REMOVE LCID %d RBID %d configured\n", + PROTOCOL_PDCP_CTXT_ARGS(ctxt_pP,pdcp_pP), + lc_idP, + rb_idP); - if (ctxt_pP->enb_flag == ENB_FLAG_YES) { - // pdcp_remove_UE(ctxt_pP); - } + if (ctxt_pP->enb_flag == ENB_FLAG_YES) { + // pdcp_remove_UE(ctxt_pP); + } - /* Security keys */ - if (pdcp_pP->kUPenc != NULL) { - free(pdcp_pP->kUPenc); - } + /* Security keys */ + if (pdcp_pP->kUPenc != NULL) { + free(pdcp_pP->kUPenc); + } - if (pdcp_pP->kRRCint != NULL) { - free(pdcp_pP->kRRCint); - } + if (pdcp_pP->kRRCint != NULL) { + free(pdcp_pP->kRRCint); + } - if (pdcp_pP->kRRCenc != NULL) { - free(pdcp_pP->kRRCenc); - } + if (pdcp_pP->kRRCenc != NULL) { + free(pdcp_pP->kRRCenc); + } - memset(pdcp_pP, 0, sizeof(pdcp_t)); - break; + memset(pdcp_pP, 0, sizeof(pdcp_t)); + break; #if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0)) - case CONFIG_ACTION_MBMS_ADD: - case CONFIG_ACTION_MBMS_MODIFY: - LOG_D(PDCP," %s service_id/mch index %d, session_id/lcid %d, rbid %d configured\n", - //PROTOCOL_PDCP_CTXT_ARGS(ctxt_pP,pdcp_pP), - actionP == CONFIG_ACTION_MBMS_ADD ? "CONFIG_ACTION_MBMS_ADD" : "CONFIG_ACTION_MBMS_MODIFY", - mch_idP, - lc_idP, - rb_idP); + case CONFIG_ACTION_MBMS_ADD: + case CONFIG_ACTION_MBMS_MODIFY: + LOG_D(PDCP," %s service_id/mch index %d, session_id/lcid %d, rbid %d configured\n", + //PROTOCOL_PDCP_CTXT_ARGS(ctxt_pP,pdcp_pP), + actionP == CONFIG_ACTION_MBMS_ADD ? "CONFIG_ACTION_MBMS_ADD" : "CONFIG_ACTION_MBMS_MODIFY", + mch_idP, + lc_idP, + rb_idP); - if (ctxt_pP->enb_flag == ENB_FLAG_YES) { - pdcp_mbms_array_eNB[ctxt_pP->module_id][mch_idP][lc_idP].instanciated_instance = TRUE ; - pdcp_mbms_array_eNB[ctxt_pP->module_id][mch_idP][lc_idP].rb_id = rb_idP; - } else { - pdcp_mbms_array_ue[ctxt_pP->module_id][mch_idP][lc_idP].instanciated_instance = TRUE ; - pdcp_mbms_array_ue[ctxt_pP->module_id][mch_idP][lc_idP].rb_id = rb_idP; - } + if (ctxt_pP->enb_flag == ENB_FLAG_YES) { + pdcp_mbms_array_eNB[ctxt_pP->module_id][mch_idP][lc_idP].instanciated_instance = TRUE ; + pdcp_mbms_array_eNB[ctxt_pP->module_id][mch_idP][lc_idP].rb_id = rb_idP; + } else { + pdcp_mbms_array_ue[ctxt_pP->module_id][mch_idP][lc_idP].instanciated_instance = TRUE ; + pdcp_mbms_array_ue[ctxt_pP->module_id][mch_idP][lc_idP].rb_id = rb_idP; + } - break; + break; #endif - case CONFIG_ACTION_SET_SECURITY_MODE: - pdcp_config_set_security( - ctxt_pP, - pdcp_pP, - rb_idP, - lc_idP, - security_modeP, - kRRCenc_pP, - kRRCint_pP, - kUPenc_pP); - break; - - default: - DevParam(actionP, ctxt_pP->module_id, ctxt_pP->rnti); - break; + case CONFIG_ACTION_SET_SECURITY_MODE: + pdcp_config_set_security( + ctxt_pP, + pdcp_pP, + rb_idP, + lc_idP, + security_modeP, + kRRCenc_pP, + kRRCint_pP, + kUPenc_pP); + break; + + default: + DevParam(actionP, ctxt_pP->module_id, ctxt_pP->rnti); + break; } return 0; @@ -1749,14 +1718,14 @@ pdcp_config_req_asn1 ( //----------------------------------------------------------------------------- void pdcp_config_set_security( - const protocol_ctxt_t* const ctxt_pP, - pdcp_t * const pdcp_pP, + const protocol_ctxt_t *const ctxt_pP, + pdcp_t *const pdcp_pP, const rb_id_t rb_idP, const uint16_t lc_idP, const uint8_t security_modeP, - uint8_t * const kRRCenc, - uint8_t * const kRRCint, - uint8_t * const kUPenc) + uint8_t *const kRRCenc, + uint8_t *const kRRCint, + uint8_t *const kUPenc) //----------------------------------------------------------------------------- { DevAssert(pdcp_pP != NULL); @@ -1764,30 +1733,27 @@ pdcp_config_set_security( if ((security_modeP >= 0) && (security_modeP <= 0x77)) { pdcp_pP->cipheringAlgorithm = security_modeP & 0x0f; pdcp_pP->integrityProtAlgorithm = (security_modeP>>4) & 0xf; - LOG_D(PDCP, PROTOCOL_PDCP_CTXT_FMT" CONFIG_ACTION_SET_SECURITY_MODE: cipheringAlgorithm %d integrityProtAlgorithm %d\n", PROTOCOL_PDCP_CTXT_ARGS(ctxt_pP,pdcp_pP), - pdcp_pP->cipheringAlgorithm, - pdcp_pP->integrityProtAlgorithm); - + pdcp_pP->cipheringAlgorithm, + pdcp_pP->integrityProtAlgorithm); pdcp_pP->kRRCenc = kRRCenc; pdcp_pP->kRRCint = kRRCint; pdcp_pP->kUPenc = kUPenc; - /* Activate security */ pdcp_pP->security_activated = 1; - MSC_LOG_EVENT( - (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_PDCP_ENB:MSC_PDCP_UE, - "0 Set security ciph %X integ %x UE %"PRIx16" ", - pdcp_pP->cipheringAlgorithm, - pdcp_pP->integrityProtAlgorithm, - ctxt_pP->rnti); + MSC_LOG_EVENT( + (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_PDCP_ENB:MSC_PDCP_UE, + "0 Set security ciph %X integ %x UE %"PRIx16" ", + pdcp_pP->cipheringAlgorithm, + pdcp_pP->integrityProtAlgorithm, + ctxt_pP->rnti); } else { - MSC_LOG_EVENT( - (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_PDCP_ENB:MSC_PDCP_UE, - "0 Set security failed UE %"PRIx16" ", - ctxt_pP->rnti); - LOG_E(PDCP,PROTOCOL_PDCP_CTXT_FMT" bad security mode %d", + MSC_LOG_EVENT( + (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_PDCP_ENB:MSC_PDCP_UE, + "0 Set security failed UE %"PRIx16" ", + ctxt_pP->rnti); + LOG_E(PDCP,PROTOCOL_PDCP_CTXT_FMT" bad security mode %d", PROTOCOL_PDCP_CTXT_ARGS(ctxt_pP,pdcp_pP), security_modeP); } @@ -1796,7 +1762,7 @@ pdcp_config_set_security( //----------------------------------------------------------------------------- void rrc_pdcp_config_req ( - const protocol_ctxt_t* const ctxt_pP, + const protocol_ctxt_t *const ctxt_pP, const srb_flag_t srb_flagP, const uint32_t actionP, const rb_id_t rb_idP, @@ -1806,102 +1772,23 @@ rrc_pdcp_config_req ( pdcp_t *pdcp_p = NULL; hash_key_t key = PDCP_COLL_KEY_VALUE(ctxt_pP->module_id, ctxt_pP->rnti, ctxt_pP->enb_flag, rb_idP, srb_flagP); hashtable_rc_t h_rc; - h_rc = hashtable_get(pdcp_coll_p, key, (void**)&pdcp_p); + h_rc = hashtable_get(pdcp_coll_p, key, (void **)&pdcp_p); if (h_rc == HASH_TABLE_OK) { - - /* - * Initialize sequence number state variables of relevant PDCP entity - */ - switch (actionP) { - case CONFIG_ACTION_ADD: - pdcp_p->is_srb = srb_flagP; - pdcp_p->rb_id = rb_idP; - - if (ctxt_pP->enb_flag == ENB_FLAG_NO) { - pdcp_p->is_ue = TRUE; - pdcp_UE_UE_module_id_to_rnti[ctxt_pP->module_id] = ctxt_pP->rnti; - } else { - pdcp_p->is_ue = FALSE; - } - - pdcp_p->next_pdcp_tx_sn = 0; - pdcp_p->next_pdcp_rx_sn = 0; - pdcp_p->tx_hfn = 0; - pdcp_p->rx_hfn = 0; - /* SN of the last PDCP SDU delivered to upper layers */ - pdcp_p->last_submitted_pdcp_rx_sn = 4095; - - if (rb_idP < DTCH) { // SRB - pdcp_p->seq_num_size = 5; - } else { // DRB - pdcp_p->seq_num_size = 12; - } - - pdcp_p->first_missing_pdu = -1; - LOG_D(PDCP,PROTOCOL_PDCP_CTXT_FMT" Config request : Action ADD: radio bearer id %d (already added) configured\n", - PROTOCOL_PDCP_CTXT_ARGS(ctxt_pP,pdcp_p), - rb_idP); - break; - - case CONFIG_ACTION_MODIFY: - break; - - case CONFIG_ACTION_REMOVE: - LOG_D(PDCP, PROTOCOL_PDCP_CTXT_FMT" CONFIG_ACTION_REMOVE: radio bearer id %d configured\n", - PROTOCOL_PDCP_CTXT_ARGS(ctxt_pP,pdcp_p), - rb_idP); - pdcp_p->next_pdcp_tx_sn = 0; - pdcp_p->next_pdcp_rx_sn = 0; - pdcp_p->tx_hfn = 0; - pdcp_p->rx_hfn = 0; - pdcp_p->last_submitted_pdcp_rx_sn = 4095; - pdcp_p->seq_num_size = 0; - pdcp_p->first_missing_pdu = -1; - pdcp_p->security_activated = 0; - h_rc = hashtable_remove(pdcp_coll_p, key); - - break; - - case CONFIG_ACTION_SET_SECURITY_MODE: - if ((security_modeP >= 0) && (security_modeP <= 0x77)) { - pdcp_p->cipheringAlgorithm= security_modeP & 0x0f; - pdcp_p->integrityProtAlgorithm = (security_modeP>>4) & 0xf; - LOG_D(PDCP, PROTOCOL_PDCP_CTXT_FMT" CONFIG_ACTION_SET_SECURITY_MODE: cipheringAlgorithm %d integrityProtAlgorithm %d\n", - PROTOCOL_PDCP_CTXT_ARGS(ctxt_pP,pdcp_p), - pdcp_p->cipheringAlgorithm, - pdcp_p->integrityProtAlgorithm ); - } else { - LOG_W(PDCP,PROTOCOL_PDCP_CTXT_FMT" bad security mode %d", PROTOCOL_PDCP_CTXT_ARGS(ctxt_pP,pdcp_p), security_modeP); - } - - break; - - default: - DevParam(actionP, ctxt_pP->module_id, ctxt_pP->rnti); - break; - } - } else { + /* + * Initialize sequence number state variables of relevant PDCP entity + */ switch (actionP) { - case CONFIG_ACTION_ADD: - pdcp_p = calloc(1, sizeof(pdcp_t)); - h_rc = hashtable_insert(pdcp_coll_p, key, pdcp_p); - - if (h_rc != HASH_TABLE_OK) { - LOG_E(PDCP, PROTOCOL_PDCP_CTXT_FMT" PDCP ADD FAILED\n", - PROTOCOL_PDCP_CTXT_ARGS(ctxt_pP, pdcp_p)); - free(pdcp_p); - - } else { + case CONFIG_ACTION_ADD: pdcp_p->is_srb = srb_flagP; pdcp_p->rb_id = rb_idP; if (ctxt_pP->enb_flag == ENB_FLAG_NO) { pdcp_p->is_ue = TRUE; - pdcp_UE_UE_module_id_to_rnti[ctxt_pP->module_id] = ctxt_pP->rnti; + pdcp_UE_UE_module_id_to_rnti[ctxt_pP->module_id] = ctxt_pP->rnti; } else { pdcp_p->is_ue = FALSE; - } + } pdcp_p->next_pdcp_tx_sn = 0; pdcp_p->next_pdcp_rx_sn = 0; @@ -1912,46 +1799,119 @@ rrc_pdcp_config_req ( if (rb_idP < DTCH) { // SRB pdcp_p->seq_num_size = 5; - } else { // DRB pdcp_p->seq_num_size = 12; } pdcp_p->first_missing_pdu = -1; - LOG_D(PDCP,PROTOCOL_PDCP_CTXT_FMT" Inserting PDCP instance in collection key 0x%"PRIx64"\n", - PROTOCOL_PDCP_CTXT_ARGS(ctxt_pP,pdcp_p), key); - LOG_D(PDCP,PROTOCOL_PDCP_CTXT_FMT" Config request : Action ADD: radio bearer id %d configured\n", + LOG_D(PDCP,PROTOCOL_PDCP_CTXT_FMT" Config request : Action ADD: radio bearer id %d (already added) configured\n", PROTOCOL_PDCP_CTXT_ARGS(ctxt_pP,pdcp_p), rb_idP); - } + break; - break; + case CONFIG_ACTION_MODIFY: + break; - case CONFIG_ACTION_REMOVE: - LOG_D(PDCP, PROTOCOL_CTXT_FMT" CONFIG_REQ PDCP CONFIG_ACTION_REMOVE PDCP instance not found\n", - PROTOCOL_CTXT_ARGS(ctxt_pP)); - break; + case CONFIG_ACTION_REMOVE: + LOG_D(PDCP, PROTOCOL_PDCP_CTXT_FMT" CONFIG_ACTION_REMOVE: radio bearer id %d configured\n", + PROTOCOL_PDCP_CTXT_ARGS(ctxt_pP,pdcp_p), + rb_idP); + pdcp_p->next_pdcp_tx_sn = 0; + pdcp_p->next_pdcp_rx_sn = 0; + pdcp_p->tx_hfn = 0; + pdcp_p->rx_hfn = 0; + pdcp_p->last_submitted_pdcp_rx_sn = 4095; + pdcp_p->seq_num_size = 0; + pdcp_p->first_missing_pdu = -1; + pdcp_p->security_activated = 0; + h_rc = hashtable_remove(pdcp_coll_p, key); + break; - default: - LOG_E(PDCP, PROTOCOL_CTXT_FMT" CONFIG_REQ PDCP NOT FOUND\n", - PROTOCOL_CTXT_ARGS(ctxt_pP)); + case CONFIG_ACTION_SET_SECURITY_MODE: + if ((security_modeP >= 0) && (security_modeP <= 0x77)) { + pdcp_p->cipheringAlgorithm= security_modeP & 0x0f; + pdcp_p->integrityProtAlgorithm = (security_modeP>>4) & 0xf; + LOG_D(PDCP, PROTOCOL_PDCP_CTXT_FMT" CONFIG_ACTION_SET_SECURITY_MODE: cipheringAlgorithm %d integrityProtAlgorithm %d\n", + PROTOCOL_PDCP_CTXT_ARGS(ctxt_pP,pdcp_p), + pdcp_p->cipheringAlgorithm, + pdcp_p->integrityProtAlgorithm ); + } else { + LOG_W(PDCP,PROTOCOL_PDCP_CTXT_FMT" bad security mode %d", PROTOCOL_PDCP_CTXT_ARGS(ctxt_pP,pdcp_p), security_modeP); + } + + break; + + default: + DevParam(actionP, ctxt_pP->module_id, ctxt_pP->rnti); + break; + } + } else { + switch (actionP) { + case CONFIG_ACTION_ADD: + pdcp_p = calloc(1, sizeof(pdcp_t)); + h_rc = hashtable_insert(pdcp_coll_p, key, pdcp_p); + + if (h_rc != HASH_TABLE_OK) { + LOG_E(PDCP, PROTOCOL_PDCP_CTXT_FMT" PDCP ADD FAILED\n", + PROTOCOL_PDCP_CTXT_ARGS(ctxt_pP, pdcp_p)); + free(pdcp_p); + } else { + pdcp_p->is_srb = srb_flagP; + pdcp_p->rb_id = rb_idP; + + if (ctxt_pP->enb_flag == ENB_FLAG_NO) { + pdcp_p->is_ue = TRUE; + pdcp_UE_UE_module_id_to_rnti[ctxt_pP->module_id] = ctxt_pP->rnti; + } else { + pdcp_p->is_ue = FALSE; + } + + pdcp_p->next_pdcp_tx_sn = 0; + pdcp_p->next_pdcp_rx_sn = 0; + pdcp_p->tx_hfn = 0; + pdcp_p->rx_hfn = 0; + /* SN of the last PDCP SDU delivered to upper layers */ + pdcp_p->last_submitted_pdcp_rx_sn = 4095; + + if (rb_idP < DTCH) { // SRB + pdcp_p->seq_num_size = 5; + } else { // DRB + pdcp_p->seq_num_size = 12; + } + + pdcp_p->first_missing_pdu = -1; + LOG_D(PDCP,PROTOCOL_PDCP_CTXT_FMT" Inserting PDCP instance in collection key 0x%"PRIx64"\n", + PROTOCOL_PDCP_CTXT_ARGS(ctxt_pP,pdcp_p), key); + LOG_D(PDCP,PROTOCOL_PDCP_CTXT_FMT" Config request : Action ADD: radio bearer id %d configured\n", + PROTOCOL_PDCP_CTXT_ARGS(ctxt_pP,pdcp_p), + rb_idP); + } + + break; + + case CONFIG_ACTION_REMOVE: + LOG_D(PDCP, PROTOCOL_CTXT_FMT" CONFIG_REQ PDCP CONFIG_ACTION_REMOVE PDCP instance not found\n", + PROTOCOL_CTXT_ARGS(ctxt_pP)); + break; + + default: + LOG_E(PDCP, PROTOCOL_CTXT_FMT" CONFIG_REQ PDCP NOT FOUND\n", + PROTOCOL_CTXT_ARGS(ctxt_pP)); } } } //----------------------------------------------------------------------------- - + int pdcp_module_init ( void ) //----------------------------------------------------------------------------- { - #ifdef PDCP_USE_RT_FIFO int ret; - ret=rtf_create(PDCP2NW_DRIVER_FIFO,32768); if (ret < 0) { @@ -1966,7 +1926,6 @@ pdcp_module_init ( if (ret < 0) { LOG_E(PDCP, "Cannot create NW_DRIVER2PDCP_FIFO fifo %d (ERROR %d)\n", NW_DRIVER2PDCP_FIFO, ret); - return -1; } else { LOG_D(PDCP, "Created NW_DRIVER2PDCP_FIFO fifo %d\n", NW_DRIVER2PDCP_FIFO); @@ -1977,18 +1936,17 @@ pdcp_module_init ( pdcp_input_sdu_remaining_size_to_read=0; pdcp_input_sdu_size_read=0; #endif - return 0; } //----------------------------------------------------------------------------- void pdcp_free ( - void* pdcp_pP + void *pdcp_pP ) //----------------------------------------------------------------------------- { - pdcp_t* pdcp_p = (pdcp_t*)pdcp_pP; + pdcp_t *pdcp_p = (pdcp_t *)pdcp_pP; if (pdcp_p != NULL) { if (pdcp_p->kUPenc != NULL) { @@ -2022,7 +1980,6 @@ void pdcp_module_cleanup (void) void pdcp_layer_init(void) //----------------------------------------------------------------------------- { - module_id_t instance; int i,j; #if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0)) @@ -2044,12 +2001,13 @@ void pdcp_layer_init(void) memset(&pdcp_mbms_array_ue[instance][service_id][session_id], 0, sizeof(pdcp_mbms_t)); } } + #endif pdcp_eNB_UE_instance_to_rnti[instance] = NOT_A_RNTI; } - pdcp_eNB_UE_instance_to_rnti_index = 0; - + pdcp_eNB_UE_instance_to_rnti_index = 0; + for (instance = 0; instance < NUMBER_OF_eNB_MAX; instance++) { #if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0)) @@ -2064,28 +2022,26 @@ void pdcp_layer_init(void) #ifdef MBMS_MULTICAST_OUT mbms_socket = socket(AF_INET, SOCK_RAW, IPPROTO_RAW); + if (mbms_socket == -1) LOG_W(PDCP, "Could not create RAW socket, MBMS packets will not be put to the network\n"); -#endif +#endif LOG_I(PDCP, "PDCP layer has been initialized\n"); - pdcp_output_sdu_bytes_to_write=0; pdcp_output_header_bytes_to_write=0; pdcp_input_sdu_remaining_size_to_read=0; - memset(pdcp_enb, 0, sizeof(pdcp_enb_t)); - - memset(Pdcp_stats_tx_window_ms, 0, sizeof(Pdcp_stats_tx_window_ms)); memset(Pdcp_stats_rx_window_ms, 0, sizeof(Pdcp_stats_rx_window_ms)); - for (i =0; i< MAX_NUM_CCs ; i ++){ - for (j=0; j< MAX_MOBILES_PER_ENB;j++){ + + for (i =0; i< MAX_NUM_CCs ; i ++) { + for (j=0; j< MAX_MOBILES_PER_ENB; j++) { Pdcp_stats_tx_window_ms[i][j]=100; Pdcp_stats_rx_window_ms[i][j]=100; } } - + memset(Pdcp_stats_tx, 0, sizeof(Pdcp_stats_tx)); memset(Pdcp_stats_tx_w, 0, sizeof(Pdcp_stats_tx_w)); memset(Pdcp_stats_tx_tmp_w, 0, sizeof(Pdcp_stats_tx_tmp_w)); @@ -2096,8 +2052,6 @@ void pdcp_layer_init(void) memset(Pdcp_stats_tx_throughput_w, 0, sizeof(Pdcp_stats_tx_throughput_w)); memset(Pdcp_stats_tx_aiat, 0, sizeof(Pdcp_stats_tx_aiat)); memset(Pdcp_stats_tx_iat, 0, sizeof(Pdcp_stats_tx_iat)); - - memset(Pdcp_stats_rx, 0, sizeof(Pdcp_stats_rx)); memset(Pdcp_stats_rx_w, 0, sizeof(Pdcp_stats_rx_w)); memset(Pdcp_stats_rx_tmp_w, 0, sizeof(Pdcp_stats_rx_tmp_w)); @@ -2109,7 +2063,6 @@ void pdcp_layer_init(void) memset(Pdcp_stats_rx_aiat, 0, sizeof(Pdcp_stats_rx_aiat)); memset(Pdcp_stats_rx_iat, 0, sizeof(Pdcp_stats_rx_iat)); memset(Pdcp_stats_rx_outoforder, 0, sizeof(Pdcp_stats_rx_outoforder)); - } //----------------------------------------------------------------------------- @@ -2117,15 +2070,17 @@ void pdcp_layer_cleanup (void) //----------------------------------------------------------------------------- { list_free (&pdcp_sdu_list); - hashtable_destroy(pdcp_coll_p); + hashtable_destroy(&pdcp_coll_p); #ifdef MBMS_MULTICAST_OUT + if(mbms_socket != -1) { close(mbms_socket); mbms_socket = -1; } + #endif } #ifdef PDCP_USE_RT_FIFO -EXPORT_SYMBOL(pdcp_2_nas_irq); + EXPORT_SYMBOL(pdcp_2_nas_irq); #endif //PDCP_USE_RT_FIFO diff --git a/openair2/LAYER2/RLC/AM_v9.3.0/rlc_am_test.c b/openair2/LAYER2/RLC/AM_v9.3.0/rlc_am_test.c index d9eb6de7cccf4c1de70f3d19ca42e466bb7ef23e..7a95a62787a58c65e114ca76bf4723e2c9c15ade 100644 --- a/openair2/LAYER2/RLC/AM_v9.3.0/rlc_am_test.c +++ b/openair2/LAYER2/RLC/AM_v9.3.0/rlc_am_test.c @@ -128,6 +128,8 @@ void rlc_am_v9_3_0_test_windows() rlc_am_entity_t am2; unsigned int i; unsigned int j; + memset(am1,0,sizeof(rlc_am_entity_t)); + memset(am2,0,sizeof(rlc_am_entity_t)); rlc_am_init(&am1, g_frame); rlc_am_init(&am2, g_frame); @@ -215,19 +217,16 @@ void rlc_am_v9_3_0_test_windows() assert(rlc_am_in_rx_window(&am1, i) == 0); } } - } //----------------------------------------------------------------------------- void rlc_am_v9_3_0_test_read_write_bit_field() //----------------------------------------------------------------------------- { unsigned int bit_pos_write = 0; // range from 0 (MSB/left) to 7 (LSB/right) - uint8_t* byte_pos_write = g_buffer; - + uint8_t *byte_pos_write = g_buffer; unsigned int bit_pos_read = 0; // range from 0 (MSB/left) to 7 (LSB/right) - uint8_t* byte_pos_read = g_buffer; + uint8_t *byte_pos_read = g_buffer; uint16_t read_value; - memset (g_buffer, 0, sizeof(g_buffer)); // byte 0 rlc_am_write8_bit_field(&byte_pos_write, &bit_pos_write, 1, 1); @@ -240,7 +239,6 @@ void rlc_am_v9_3_0_test_read_write_bit_field() rlc_am_write8_bit_field(&byte_pos_write, &bit_pos_write, 1, 0); assert(g_buffer[0] == 0x96); assert(g_buffer[1] == 0x00); - // byte 1 rlc_am_write8_bit_field(&byte_pos_write, &bit_pos_write, 1, 1); rlc_am_write8_bit_field(&byte_pos_write, &bit_pos_write, 1, 1); @@ -251,10 +249,8 @@ void rlc_am_v9_3_0_test_read_write_bit_field() rlc_am_write8_bit_field(&byte_pos_write, &bit_pos_write, 1, 0); rlc_am_write8_bit_field(&byte_pos_write, &bit_pos_write, 1, 1); assert(g_buffer[0] == 0x96); - assert(g_buffer[1] == 0xD9); assert(g_buffer[2] == 0x00); - // byte 2 rlc_am_write8_bit_field(&byte_pos_write, &bit_pos_write, 1, 0); rlc_am_write8_bit_field(&byte_pos_write, &bit_pos_write, 1, 0); @@ -266,7 +262,6 @@ void rlc_am_v9_3_0_test_read_write_bit_field() rlc_am_write8_bit_field(&byte_pos_write, &bit_pos_write, 1, 1); assert(g_buffer[0] == 0x96); assert(g_buffer[1] == 0xD9); - assert(g_buffer[2] == 0x11); assert(g_buffer[3] == 0x00); // byte 3 & 4 @@ -282,7 +277,6 @@ void rlc_am_v9_3_0_test_read_write_bit_field() assert(g_buffer[0] == 0x96); assert(g_buffer[1] == 0xD9); assert(g_buffer[2] == 0x11); - assert(g_buffer[3] == 0x99); assert(g_buffer[4] == 0xA7); assert(g_buffer[5] == 0x00); @@ -298,7 +292,6 @@ void rlc_am_v9_3_0_test_read_write_bit_field() assert(g_buffer[2] == 0x11); assert(g_buffer[3] == 0x99); assert(g_buffer[4] == 0xA7); - assert(g_buffer[5] == 0xF4); assert(g_buffer[6] == 0x86); assert(g_buffer[7] == 0x00); @@ -317,7 +310,6 @@ void rlc_am_v9_3_0_test_read_write_bit_field() assert(g_buffer[4] == 0xA7); assert(g_buffer[5] == 0xF4); assert(g_buffer[6] == 0x86); - assert(g_buffer[7] == 0xCD); assert(g_buffer[8] == 0x7D); assert(g_buffer[9] == 0x58); @@ -337,7 +329,6 @@ void rlc_am_v9_3_0_test_read_write_bit_field() assert(g_buffer[7] == 0xCD); assert(g_buffer[8] == 0x7D); assert(g_buffer[9] == 0x58); - assert(g_buffer[10] == 0xAA); assert(g_buffer[11] == 0xDB); assert(g_buffer[12] == 0xAA); @@ -368,7 +359,6 @@ void rlc_am_v9_3_0_test_read_write_bit_field() assert(g_buffer[12] == 0xAA); assert(g_buffer[13] == 0xBD); assert(g_buffer[14] == 0x34); - assert(g_buffer[15] == 0xE0); assert(g_buffer[16] == 0x3F); assert(g_buffer[17] == 0x84); @@ -385,7 +375,6 @@ void rlc_am_v9_3_0_test_read_write_bit_field() assert(g_buffer[28] == 0x87); assert(g_buffer[29] == 0x88); assert(g_buffer[30] == 0x00); - // 0x96 0xD9 read_value = rlc_am_read_bit_field(&byte_pos_read, &bit_pos_read, 1);// b0 assert(read_value == 1); @@ -419,7 +408,6 @@ void rlc_am_v9_3_0_test_read_write_bit_field() assert(read_value == 0); read_value = rlc_am_read_bit_field(&byte_pos_read, &bit_pos_read, 1);// b15 assert(read_value == 1); - // 0x11 0x99 read_value = rlc_am_read_bit_field(&byte_pos_read, &bit_pos_read, 2); assert(read_value == 0); @@ -439,7 +427,6 @@ void rlc_am_v9_3_0_test_read_write_bit_field() assert(read_value == 2); read_value = rlc_am_read_bit_field(&byte_pos_read, &bit_pos_read, 2); assert(read_value == 1); - // 0xA7 0xF4 0x86 0xCD 0x7D; read_value = rlc_am_read_bit_field(&byte_pos_read, &bit_pos_read, 10); assert(read_value == 0x29F); @@ -449,10 +436,8 @@ void rlc_am_v9_3_0_test_read_write_bit_field() assert(read_value == 0x1B3); read_value = rlc_am_read_bit_field(&byte_pos_read, &bit_pos_read, 10); assert(read_value == 0x17D); - // 0x58 0xAA 0xDB 0xAA 0xBD 0x34 // 0xE0 0x3F 0x84 0xBA 0x91 0xEC - read_value = rlc_am_read_bit_field(&byte_pos_read, &bit_pos_read, 1); assert(read_value == 0); read_value = rlc_am_read_bit_field(&byte_pos_read, &bit_pos_read, 10); @@ -475,7 +460,6 @@ void rlc_am_v9_3_0_test_read_write_bit_field() assert(read_value == 0x2EA); read_value = rlc_am_read_bit_field(&byte_pos_read, &bit_pos_read, 10); assert(read_value == 0x11E); - bit_pos_read = 0; byte_pos_read = g_buffer; // 0x96 0xD9 0x11 0x99 0xA7 0xF4 0x86 0xCD 0x7D 0x58 0xAA 0xDB 0xAA 0xBD 0x34 @@ -523,30 +507,24 @@ void rlc_am_v9_3_0_test_send_sdu(rlc_am_entity_t *am_txP, int sdu_indexP) printf("[FRAME %05d][RLC][MOD %02d][RB %02d] TX SDU %d %04d bytes\n",g_frame,am_txP->module_id, am_txP->rb_id, sdu_indexP, strlen(g_sdus[sdu_indexP]) + 1); memset (sdu->data, 0, sizeof (struct rlc_am_data_req_alloc)); strcpy (&sdu->data[sizeof (struct rlc_am_data_req_alloc)],g_sdus[sdu_indexP]); - ((struct rlc_am_data_req *) (sdu->data))->data_size = strlen(g_sdus[sdu_indexP])+ 1; ((struct rlc_am_data_req *) (sdu->data))->conf = 1; ((struct rlc_am_data_req *) (sdu->data))->mui = g_mui++; ((struct rlc_am_data_req *) (sdu->data))->data_offset = sizeof (struct rlc_am_data_req_alloc); rlc_am_data_req(am_txP, g_frame, sdu); - g_send_sdu_ids[g_send_id_write_index[am_txP->rb_id]++][am_txP->rb_id] = sdu_indexP; assert(g_send_id_write_index[am_txP->rb_id] < TEST_MAX_SEND_SDU); } else { printf("Out of memory error\n"); -// exit(-1); + // exit(-1); } } //----------------------------------------------------------------------------- -void rlc_am_v9_3_0_test_mac_rlc_loop (struct mac_data_ind *data_indP, struct mac_data_req *data_requestP, int* drop_countP, int *tx_packetsP, - int* dropped_tx_packetsP) //----------------------------------------------------------------------------- -{ - - - mem_block_t* tb_src; - mem_block_t* tb_dst; +void rlc_am_v9_3_0_test_mac_rlc_loop (struct mac_data_ind *data_indP, struct mac_data_req *data_requestP, int *drop_countP, int *tx_packetsP, + int *dropped_tx_packetsP) { //----------------------------------------------------------------------------- + mem_block_t *tb_src; + mem_block_t *tb_dst; unsigned int tb_size; - data_indP->no_tb = 0; while (data_requestP->data.nb_elements > 0) { @@ -554,10 +532,9 @@ void rlc_am_v9_3_0_test_mac_rlc_loop (struct mac_data_ind *data_indP, struct ma if (tb_src != NULL) { tb_size = ((struct mac_tb_req *) (tb_src->data))->tb_size_in_bits >> 3; - printf("[RLC-LOOP] FOUND TB SIZE IN BITS %d IN BYTES %d sizeof (mac_rlc_max_rx_header_size_t) %d\n", + printf("[RLC-LOOP] FOUND TB SIZE IN BITS %d IN BYTES %u sizeof (mac_rlc_max_rx_header_size_t) %d\n", ((struct mac_tb_req *) (tb_src->data))->tb_size_in_bits, tb_size, sizeof (mac_rlc_max_rx_header_size_t)); - *tx_packetsP = *tx_packetsP + 1; if (*drop_countP == 0) { @@ -568,16 +545,14 @@ void rlc_am_v9_3_0_test_mac_rlc_loop (struct mac_data_ind *data_indP, struct ma ((struct mac_tb_ind *) (tb_dst->data))->data_ptr = &tb_dst->data[sizeof (mac_rlc_max_rx_header_size_t)]; ((struct mac_tb_ind *) (tb_dst->data))->size = tb_size; ((struct mac_tb_ind *) (tb_dst->data))->error_indication = 0; - memcpy(((struct mac_tb_ind *) (tb_dst->data))->data_ptr, &((struct mac_tb_req *) (tb_src->data))->data_ptr[0], tb_size); - list_add_tail_eurecom(tb_dst, &data_indP->data); data_indP->no_tb += 1; } else { printf("Out of memory error\n"); -// exit(-1); + // exit(-1); } } else { printf("[RLC-LOOP] DROPPING 1 TB\n"); @@ -607,8 +582,6 @@ void rlc_am_v9_3_0_test_exchange_pdus(rlc_am_entity_t *am_txP, struct mac_status_ind tx_status; struct mac_status_resp mac_rlc_status_resp_tx; struct mac_status_resp mac_rlc_status_resp_rx; - - memset(&data_request_tx, 0, sizeof(struct mac_data_req)); memset(&data_request_rx, 0, sizeof(struct mac_data_req)); memset(&data_ind_tx, 0, sizeof(struct mac_data_ind)); @@ -616,19 +589,15 @@ void rlc_am_v9_3_0_test_exchange_pdus(rlc_am_entity_t *am_txP, memset(&tx_status, 0, sizeof(struct mac_status_ind)); memset(&mac_rlc_status_resp_tx, 0, sizeof(struct mac_status_resp)); memset(&mac_rlc_status_resp_rx, 0, sizeof(struct mac_status_resp)); - mac_rlc_status_resp_tx = rlc_am_mac_status_indication(am_txP, g_frame, bytes_txP, tx_status); data_request_tx = rlc_am_mac_data_request(am_txP, g_frame); mac_rlc_status_resp_rx = rlc_am_mac_status_indication(am_rxP, g_frame, bytes_rxP, tx_status); data_request_rx = rlc_am_mac_data_request(am_rxP, g_frame); - - rlc_am_v9_3_0_test_mac_rlc_loop(&data_ind_rx, &data_request_tx, &g_drop_tx, &g_tx_packets, &g_dropped_tx_packets); rlc_am_v9_3_0_test_mac_rlc_loop(&data_ind_tx, &data_request_rx, &g_drop_rx, &g_rx_packets, &g_dropped_rx_packets); rlc_am_mac_data_indication(am_rxP, g_frame, am_txP->is_enb, data_ind_rx); rlc_am_mac_data_indication(am_txP, g_frame, am_txP->is_enb, data_ind_tx); g_frame += 1; - //rlc_am_tx_buffer_display(am_txP,NULL); //assert(am_txP->t_status_prohibit.time_out != 1); //assert(am_rxP->t_status_prohibit.time_out != 1); @@ -660,14 +629,12 @@ void rlc_am_v9_3_0_test_data_ind (module_id_t module_idP, rb_id_t rb_idP, sdu_si assert(g_send_id_write_index[rb_idP^1] > g_send_id_read_index[rb_idP]); if (g_send_sdu_ids[g_send_id_read_index[rb_idP]][rb_idP^1] != i) { - printf("[FRAME %05d][RLC][MOD %d][RB %d][DATA-IND] g_send_sdu_ids[%d] = %d\n",g_frame,module_idP, rb_idP, g_send_id_read_index[rb_idP]-2, g_send_sdu_ids[g_send_id_read_index[rb_idP]-2][rb_idP^1]); printf("[FRAME %05d][RLC][MOD %d][RB %d][DATA-IND] g_send_sdu_ids[%d] = %d\n",g_frame,module_idP, rb_idP, g_send_id_read_index[rb_idP]-1, g_send_sdu_ids[g_send_id_read_index[rb_idP]-1][rb_idP^1]); printf("[FRAME %05d][RLC][MOD %d][RB %d][DATA-IND] g_send_sdu_ids[%d] = %d\n",g_frame,module_idP, rb_idP, g_send_id_read_index[rb_idP], g_send_sdu_ids[g_send_id_read_index[rb_idP]][rb_idP^1]); - printf("[FRAME %05d][RLC][MOD %d][RB %d][DATA-IND] g_send_id_read_index = %d sdu sent = %d\n",g_frame,module_idP, rb_idP, g_send_id_read_index[rb_idP], i); } @@ -693,17 +660,13 @@ void rlc_am_v9_3_0_test_tx_rx() uint32_t t_reordering = 5000; uint32_t t_status_prohibit = 10; int i,j,r; - srand (0); - rlc_am_init(&g_am_tx, g_frame); rlc_am_init(&g_am_rx, g_frame); rlc_am_set_debug_infos(&g_am_tx, g_frame, 0, 0, 0, 1, 1 /* LC-id = DRB-id */); rlc_am_set_debug_infos(&g_am_rx, g_frame, 1, 1, 1, 1, 1 /* LC-id = DRB-id */); - rlc_am_configure(&g_am_tx, g_frame, max_retx_threshold, poll_pdu, poll_byte, t_poll_retransmit, t_reordering, t_status_prohibit); rlc_am_configure(&g_am_rx, g_frame, max_retx_threshold, poll_pdu, poll_byte, t_poll_retransmit, t_reordering, t_status_prohibit); - #ifdef TEST1 srand (0); rlc_am_v9_3_0_test_reset_sdus(); @@ -730,7 +693,6 @@ void rlc_am_v9_3_0_test_tx_rx() rlc_am_rx_list_display(&g_am_rx, "RLC-AM RX:"); assert (g_send_id_read_index[1] == g_send_id_write_index[0]); printf("\n\n\n\n\n\n-----------------------------------------------------------------------------------------rlc_am_v9_3_0_test 1: END OF SIMPLE TEST SEVERAL SDUs IN PDU\n\n\n\n"); - rlc_am_v9_3_0_test_reset_sdus(); // RANDOM TESTS @@ -800,7 +762,6 @@ void rlc_am_v9_3_0_test_tx_rx() rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 2000, 200); rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 2000, 200); rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 2000, 200); - rlc_am_v9_3_0_test_send_sdu(&g_am_tx, 1); rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 30, 200); rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 31, 200); @@ -957,7 +918,6 @@ void rlc_am_v9_3_0_test_tx_rx() rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 15, 100); rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 15, 100); rlc_am_v9_3_0_test_exchange_pdus(&g_am_tx, &g_am_rx, 15, 100); - t_poll_retransmit = 6; rlc_am_configure(&g_am_tx, g_frame, max_retx_threshold, poll_pdu, poll_byte, t_poll_retransmit, t_reordering, t_status_prohibit); @@ -1178,7 +1138,6 @@ void rlc_am_v9_3_0_test_tx_rx() assert (g_send_id_read_index[0] == g_send_id_write_index[1]); printf("REAL BLER TX=%d (TARGET=%d) BLER RX=%d (TARGET=%d) \n",(g_dropped_tx_packets*100)/g_tx_packets, g_target_tx_error_rate, (g_dropped_rx_packets*100)/g_rx_packets, g_target_rx_error_rate); - } } @@ -1193,11 +1152,10 @@ void rlc_am_v9_3_0_test_print_trace (void) size_t size; char **strings; size_t i; - size = backtrace (array, 100); strings = backtrace_symbols (array, size); + printf ("Obtained %lu stack frames.\n", (unsigned long)size); - printf ("Obtained %d stack frames.\n", size); for (i = 0; i < size; i++) { printf ("%s\n", strings[i]); @@ -1213,15 +1171,10 @@ void rlc_am_v9_3_0_test(void) // initscr(); // cbreak(); // keypad(stdscr, TRUE); - - - // under test pool_buffer_init(); set_comp_log(RLC, LOG_ERR, LOG_MED, 1); - rlc_am_v9_3_0_test_tx_rx(); - // already tested rlc_am_v9_3_0_test_windows(); rlc_am_v9_3_0_test_read_write_bit_field(); diff --git a/openair2/LAYER2/RLC/UM_v9.3.0/rlc_um_test.c b/openair2/LAYER2/RLC/UM_v9.3.0/rlc_um_test.c index 4d238ea84175da06fa29faaad63813b505c3eafe..fda84879be06681705e62bbd15b1b7fe3f769284 100644 --- a/openair2/LAYER2/RLC/UM_v9.3.0/rlc_um_test.c +++ b/openair2/LAYER2/RLC/UM_v9.3.0/rlc_um_test.c @@ -125,7 +125,7 @@ static int8_t *g_sdus[] = {"En dépit de son volontarisme affiché, le premier m #define RLC_2_PRINT_BUFFER_LEN 10000 static char rlc_2_print_buffer[RLC_2_PRINT_BUFFER_LEN]; //----------------------------------------------------------------------------- -void rlc_util_print_hex_octets(comp_name_t componentP, unsigned char* dataP, unsigned long sizeP) +void rlc_util_print_hex_octets(comp_name_t componentP, unsigned char *dataP, unsigned long sizeP) //----------------------------------------------------------------------------- { unsigned long octet_index = 0; @@ -136,7 +136,6 @@ void rlc_util_print_hex_octets(comp_name_t componentP, unsigned char* dataP, uns return; } - LOG_D(RLC, "------+-------------------------------------------------|\n"); LOG_D(RLC, " | 0 1 2 3 4 5 6 7 8 9 a b c d e f |\n"); LOG_D(RLC, "------+-------------------------------------------------|\n"); @@ -149,7 +148,8 @@ void rlc_util_print_hex_octets(comp_name_t componentP, unsigned char* dataP, uns buffer_marker = 0; } - buffer_marker+=snprintf(&rlc_2_print_buffer[buffer_marker], RLC_2_PRINT_BUFFER_LEN - buffer_marker, " %04ld |", octet_index); + buffer_marker+=snprintf(&rlc_2_print_buffer[buffer_marker], RLC_2_PRINT_BUFFER_LEN - buffer_marker, + " %04lu |", octet_index); } /* @@ -180,17 +180,13 @@ void rlc_um_v9_3_0_test_windows_10() rlc_um_entity_t um1; rlc_um_entity_t um2; unsigned int h,w, sn, result; - uint32_t timer_reordering = 2000; uint32_t sn_field_length = 10; uint32_t is_mXch = 0; // boolean, true if configured for MTCH or MCCH - rlc_um_init(&um1); rlc_um_init(&um2); - rlc_um_set_debug_infos(&um1, g_frame, 0, 0, 0, 1, 1 /*LC-id = RAB-id*/); rlc_um_set_debug_infos(&um2, g_frame, 1, 1, 1, 1, 1 /*LC-id = RAB-id*/); - rlc_um_configure(&um1, g_frame, timer_reordering, sn_field_length, sn_field_length, is_mXch); rlc_um_configure(&um2, g_frame, timer_reordering, sn_field_length, sn_field_length, is_mXch); @@ -223,7 +219,6 @@ void rlc_um_v9_3_0_test_windows_10() assert(rlc_um_in_window(&um1, g_frame, (um1.vr_uh - um1.rx_um_window_size) & RLC_UM_SN_10_BITS_MASK, sn, (um1.vr_uh -1) & RLC_UM_SN_10_BITS_MASK) < 0); assert(rlc_um_in_reordering_window(&um1, g_frame, sn) < 0); } - } } } @@ -234,17 +229,13 @@ void rlc_um_v9_3_0_test_windows_5() rlc_um_entity_t um1; rlc_um_entity_t um2; unsigned int h,w, sn, result; - uint32_t timer_reordering = 2000; uint32_t sn_field_length = 5; uint32_t is_mXch = 0; // boolean, true if configured for MTCH or MCCH - rlc_um_init(&um1); rlc_um_init(&um2); - rlc_um_set_debug_infos(&um1, g_frame, 0, 0, 0, 1, 1 /* LC-id = DRB-id */); rlc_um_set_debug_infos(&um2, g_frame, 1, 1, 1, 1, 1 /* LC-id = DRB-id */); - rlc_um_configure(&um1, g_frame, timer_reordering, sn_field_length, sn_field_length, is_mXch); rlc_um_configure(&um2, g_frame, timer_reordering, sn_field_length, sn_field_length, is_mXch); @@ -277,7 +268,6 @@ void rlc_um_v9_3_0_test_windows_5() assert(rlc_um_in_window(&um1, g_frame, (um1.vr_uh - um1.rx_um_window_size) & RLC_UM_SN_5_BITS_MASK, sn, (um1.vr_uh -1) & RLC_UM_SN_5_BITS_MASK) < 0); assert(rlc_um_in_reordering_window(&um1, g_frame, sn) < 0); } - } } } @@ -308,25 +298,23 @@ void rlc_um_v9_3_0_test_send_sdu(rlc_um_entity_t *um_txP, int sdu_indexP) printf("[FRAME %05d][RLC][MOD %02d][RB %02d] TX SDU %d %04d bytes\n",g_frame,um_txP->module_id, um_txP->rb_id, sdu_indexP, strlen(g_sdus[sdu_indexP]) + 1); memset (sdu->data, 0, sizeof (struct rlc_um_data_req_alloc)); strcpy (&sdu->data[sizeof (struct rlc_um_data_req_alloc)],g_sdus[sdu_indexP]); - ((struct rlc_um_data_req *) (sdu->data))->data_size = strlen(g_sdus[sdu_indexP])+ 1; ((struct rlc_um_data_req *) (sdu->data))->data_offset = sizeof (struct rlc_um_data_req_alloc); rlc_um_data_req(um_txP, g_frame, sdu); - g_send_sdu_ids[g_send_id_write_index[um_txP->rb_id]++][um_txP->rb_id] = sdu_indexP; assert(g_send_id_write_index[um_txP->rb_id] < TEST_MAX_SEND_SDU); } else { printf("Out of memory error\n"); -// exit(-1); + // exit(-1); } } //----------------------------------------------------------------------------- -void rlc_um_v9_3_0_buffer_delayed_rx_mac_data_ind(struct mac_data_ind* data_indP, signed int time_delayedP) +void rlc_um_v9_3_0_buffer_delayed_rx_mac_data_ind(struct mac_data_ind *data_indP, signed int time_delayedP) //----------------------------------------------------------------------------- { int frame_modulo; - mem_block_t* tb; + mem_block_t *tb; if (time_delayedP <= 0) { frame_modulo = g_frame % MAX_TIME_DELAYED_PDU_DUE_TO_HARQ; @@ -351,11 +339,11 @@ void rlc_um_v9_3_0_buffer_delayed_rx_mac_data_ind(struct mac_data_ind* data_indP assert(data_indP->data.head == NULL); } //----------------------------------------------------------------------------- -void rlc_um_v9_3_0_buffer_delayed_tx_mac_data_ind(struct mac_data_ind* data_indP, signed int time_delayedP) +void rlc_um_v9_3_0_buffer_delayed_tx_mac_data_ind(struct mac_data_ind *data_indP, signed int time_delayedP) //----------------------------------------------------------------------------- { int frame_modulo; - mem_block_t* tb; + mem_block_t *tb; if (time_delayedP <= 0) { frame_modulo = g_frame % MAX_TIME_DELAYED_PDU_DUE_TO_HARQ; @@ -381,16 +369,13 @@ void rlc_um_v9_3_0_buffer_delayed_tx_mac_data_ind(struct mac_data_ind* data_indP } //----------------------------------------------------------------------------- -void rlc_um_v9_3_0_test_mac_rlc_loop (struct mac_data_ind* data_indP, struct mac_data_req* data_requestP, int* drop_countP, int* tx_packetsP, - int* dropped_tx_packetsP) +void rlc_um_v9_3_0_test_mac_rlc_loop (struct mac_data_ind *data_indP, struct mac_data_req *data_requestP, int *drop_countP, int *tx_packetsP, + int *dropped_tx_packetsP) //----------------------------------------------------------------------------- { - - - mem_block_t* tb_src; - mem_block_t* tb_dst; + mem_block_t *tb_src; + mem_block_t *tb_dst; unsigned int tb_size; - data_indP->no_tb = 0; while (data_requestP->data.nb_elements > 0) { @@ -398,14 +383,14 @@ void rlc_um_v9_3_0_test_mac_rlc_loop (struct mac_data_ind* data_indP, struct ma if (tb_src != NULL) { tb_size = ((struct mac_tb_req *) (tb_src->data))->tb_size_in_bits >> 3; - printf("[RLC-LOOP] FOUND TB SIZE IN BITS %d IN BYTES %d sizeof (mac_rlc_max_rx_header_size_t) %d\n", + printf("[RLC-LOOP] FOUND TB SIZE IN BITS %d IN BYTES %u sizeof (mac_rlc_max_rx_header_size_t) %d\n", ((struct mac_tb_req *) (tb_src->data))->tb_size_in_bits, tb_size, sizeof (mac_rlc_max_rx_header_size_t)); - *tx_packetsP = *tx_packetsP + 1; if (*drop_countP == 0) { tb_dst = get_free_mem_block(sizeof (mac_rlc_max_rx_header_size_t) + tb_size, __func__); + if (tb_dst != NULL) { memset(tb_dst->data, 0, sizeof (mac_rlc_max_rx_header_size_t) + tb_size); //printf("[RLC-LOOP] Testing tb_dst (1)\n"); @@ -415,18 +400,16 @@ void rlc_um_v9_3_0_test_mac_rlc_loop (struct mac_data_ind* data_indP, struct ma ((struct mac_tb_ind *) (tb_dst->data))->data_ptr = &tb_dst->data[sizeof (mac_rlc_max_rx_header_size_t)]; ((struct mac_tb_ind *) (tb_dst->data))->size = tb_size; ((struct mac_tb_ind *) (tb_dst->data))->error_indication = 0; - memcpy(((struct mac_tb_ind *) (tb_dst->data))->data_ptr, &((struct mac_tb_req *) (tb_src->data))->data_ptr[0], tb_size); - list_add_tail_eurecom(tb_dst, &data_indP->data); data_indP->no_tb += 1; //printf("[RLC-LOOP] Testing tb_dst (2)\n"); check_free_mem_block(tb_dst, __func__); } else { printf("Out of memory error\n"); -// exit(-1); + // exit(-1); } } else { printf("[RLC-LOOP] DROPPING 1 TB\n"); @@ -434,10 +417,8 @@ void rlc_um_v9_3_0_test_mac_rlc_loop (struct mac_data_ind* data_indP, struct ma *dropped_tx_packetsP = *dropped_tx_packetsP + 1; } - //printf("[RLC-LOOP] Testing tb_src\n"); check_free_mem_block(tb_src, __func__); - free_mem_block(tb_src, __func__); if (data_indP->no_tb > 0) { @@ -460,8 +441,6 @@ void rlc_um_v9_3_0_test_exchange_pdus(rlc_um_entity_t *um_txP, struct mac_status_ind tx_status; struct mac_status_resp mac_rlc_status_resp_tx; struct mac_status_resp mac_rlc_status_resp_rx; - - memset(&data_request_tx, 0, sizeof(struct mac_data_req)); memset(&data_request_rx, 0, sizeof(struct mac_data_req)); memset(&data_ind_tx, 0, sizeof(struct mac_data_ind)); @@ -469,13 +448,10 @@ void rlc_um_v9_3_0_test_exchange_pdus(rlc_um_entity_t *um_txP, memset(&tx_status, 0, sizeof(struct mac_status_ind)); memset(&mac_rlc_status_resp_tx, 0, sizeof(struct mac_status_resp)); memset(&mac_rlc_status_resp_rx, 0, sizeof(struct mac_status_resp)); - mac_rlc_status_resp_tx = rlc_um_mac_status_indication(um_txP, g_frame, 1, bytes_txP, tx_status,ENB_FLAG_YES); data_request_tx = rlc_um_mac_data_request(um_txP, g_frame); mac_rlc_status_resp_rx = rlc_um_mac_status_indication(um_rxP, g_frame, 0, bytes_rxP, tx_status,ENB_FLAG_YES); data_request_rx = rlc_um_mac_data_request(um_rxP, g_frame); - - rlc_um_v9_3_0_test_mac_rlc_loop(&data_ind_rx, &data_request_tx, &g_drop_tx, &g_tx_packets, &g_dropped_tx_packets); rlc_um_v9_3_0_test_mac_rlc_loop(&data_ind_tx, &data_request_rx, &g_drop_rx, &g_rx_packets, &g_dropped_rx_packets); rlc_um_mac_data_indication(um_rxP, g_frame, um_rxP->is_enb, data_ind_rx); @@ -506,8 +482,6 @@ void rlc_um_v9_3_0_test_exchange_delayed_pdus(rlc_um_entity_t *um_txP, struct mac_status_resp mac_rlc_status_resp_tx; struct mac_status_resp mac_rlc_status_resp_rx; int frame_modulo = g_frame % MAX_TIME_DELAYED_PDU_DUE_TO_HARQ; - - memset(&data_request_tx, 0, sizeof(struct mac_data_req)); memset(&data_request_rx, 0, sizeof(struct mac_data_req)); memset(&data_ind_tx, 0, sizeof(struct mac_data_ind)); @@ -515,23 +489,16 @@ void rlc_um_v9_3_0_test_exchange_delayed_pdus(rlc_um_entity_t *um_txP, memset(&tx_status, 0, sizeof(struct mac_status_ind)); memset(&mac_rlc_status_resp_tx, 0, sizeof(struct mac_status_resp)); memset(&mac_rlc_status_resp_rx, 0, sizeof(struct mac_status_resp)); - mac_rlc_status_resp_tx = rlc_um_mac_status_indication(um_txP, g_frame, 1, bytes_txP, tx_status,ENB_FLAG_YES); data_request_tx = rlc_um_mac_data_request(um_txP, g_frame); mac_rlc_status_resp_rx = rlc_um_mac_status_indication(um_rxP, g_frame, 0, bytes_rxP, tx_status,ENB_FLAG_YES); data_request_rx = rlc_um_mac_data_request(um_rxP, g_frame); - - rlc_um_v9_3_0_test_mac_rlc_loop(&data_ind_rx, &data_request_tx, &g_drop_tx, &g_tx_packets, &g_dropped_tx_packets); rlc_um_v9_3_0_test_mac_rlc_loop(&data_ind_tx, &data_request_rx, &g_drop_rx, &g_rx_packets, &g_dropped_rx_packets); - rlc_um_v9_3_0_buffer_delayed_rx_mac_data_ind(&data_ind_rx, time_tx_delayedP); rlc_um_v9_3_0_buffer_delayed_tx_mac_data_ind(&data_ind_tx, time_rx_delayedP); - - rlc_um_mac_data_indication(um_rxP, g_frame, um_rxP->is_enb, g_rx_delayed_indications[frame_modulo]); memset(&g_rx_delayed_indications[frame_modulo], 0, sizeof(struct mac_data_ind)); - rlc_um_mac_data_indication(um_txP, g_frame, um_txP->is_enb, g_tx_delayed_indications[frame_modulo]); memset(&g_tx_delayed_indications[frame_modulo], 0, sizeof(struct mac_data_ind)); @@ -564,14 +531,12 @@ void rlc_um_v9_3_0_test_data_ind (module_id_t module_idP, rb_id_t rb_idP, sdu_si assert(g_send_id_write_index[rb_idP^1] > g_send_id_read_index[rb_idP]); if (g_send_sdu_ids[g_send_id_read_index[rb_idP]][rb_idP^1] != i) { - printf("[FRAME %05d][RLC][MOD %d][RB %d][DATA-IND] g_send_sdu_ids[%d] = %d\n",g_frame,module_idP, rb_idP, g_send_id_read_index[rb_idP]-2, g_send_sdu_ids[g_send_id_read_index[rb_idP]-2][rb_idP^1]); printf("[FRAME %05d][RLC][MOD %d][RB %d][DATA-IND] g_send_sdu_ids[%d] = %d\n",g_frame,module_idP, rb_idP, g_send_id_read_index[rb_idP]-1, g_send_sdu_ids[g_send_id_read_index[rb_idP]-1][rb_idP^1]); printf("[FRAME %05d][RLC][MOD %d][RB %d][DATA-IND] g_send_sdu_ids[%d] = %d\n",g_frame,module_idP, rb_idP, g_send_id_read_index[rb_idP], g_send_sdu_ids[g_send_id_read_index[rb_idP]][rb_idP^1]); - printf("[FRAME %05d][RLC][MOD %d][RB %d][DATA-IND] g_send_id_read_index = %d sdu sent = %d\n",g_frame,module_idP, rb_idP, g_send_id_read_index[rb_idP], i); } @@ -607,23 +572,15 @@ void rlc_um_v9_3_0_test_reordering(uint32_t sn_field_lengthP) { rlc_um_info_t um_info; int i,j,r; - um_info.timer_reordering = (32 * sn_field_lengthP * sn_field_lengthP)/100; um_info.sn_field_length = sn_field_lengthP; um_info.is_mXch = 0; - srand (0); config_req_rlc_um (&um_tx, 0,0,0, &um_info, 0, SIGNALLING_RADIO_BEARER, SIGNALLING_RADIO_BEARER /*LC-id = DRB-id*/); config_req_rlc_um (&um_rx, 0,1,1, &um_info, 1, SIGNALLING_RADIO_BEARER, SIGNALLING_RADIO_BEARER /*LC-id = DRB-id*/); - rlc_um_display_rx_window(&um_tx); - rlc_um_display_rx_window(&um_rx); - - srand (0); - - // BIG SDU SMALL PDUS NO ERRORS rlc_um_v9_3_0_test_reset_sdus(); @@ -665,21 +622,16 @@ void rlc_um_v9_3_0_test_reordering(uint32_t sn_field_lengthP) rlc_um_v9_3_0_test_exchange_delayed_pdus(&um_tx, &um_rx, 2000, 200, 0, 0, INCREMENT_FRAME_YES); rlc_um_v9_3_0_test_exchange_delayed_pdus(&um_tx, &um_rx, 2000, 200, 0, 0, INCREMENT_FRAME_YES); rlc_um_v9_3_0_test_exchange_delayed_pdus(&um_tx, &um_rx, 2000, 200, 0, 0, INCREMENT_FRAME_YES); - assert (g_send_id_read_index[1] == g_send_id_write_index[0]); printf("\n\n\n\n\n\n\n\n"); - } printf("\n\n\n\n\n\n-----------------------------------------------------------------------------------------rlc_um_v9_3_0_test_reordering 3: END OF TEST BIG SDU, SMALL PDUs\n\n\n\n"); - rlc_um_v9_3_0_test_reset_sdus(); for (j = 0; j < 16; j++) { //i = getchar(); - rlc_um_v9_3_0_test_reset_sdus(); - rlc_um_v9_3_0_test_send_sdu(&um_tx, 1); for (i = 0; i < 32; i++) { @@ -688,8 +640,6 @@ void rlc_um_v9_3_0_test_reordering(uint32_t sn_field_lengthP) rlc_um_v9_3_0_test_exchange_delayed_pdus(&um_tx, &um_rx, 2000, 200, 0, 0, INCREMENT_FRAME_YES); assert (g_send_id_read_index[1] == g_send_id_write_index[0]); - - rlc_um_v9_3_0_test_send_sdu(&um_tx, 1); rlc_um_v9_3_0_test_exchange_delayed_pdus(&um_tx, &um_rx, 3, 200, 0, 0, INCREMENT_FRAME_YES); rlc_um_v9_3_0_test_exchange_delayed_pdus(&um_tx, &um_rx, 3, 200, 0, 0, INCREMENT_FRAME_YES); @@ -702,7 +652,6 @@ void rlc_um_v9_3_0_test_reordering(uint32_t sn_field_lengthP) rlc_um_v9_3_0_test_exchange_delayed_pdus(&um_tx, &um_rx, 2000, 200, 0, 0, INCREMENT_FRAME_YES); printf("g_send_id_read_index[1]=%d g_send_id_write_index[0]=%d Loop %d (1)\n", g_send_id_read_index[1], g_send_id_write_index[0], j); assert (g_send_id_read_index[1] != g_send_id_write_index[0]); - rlc_um_v9_3_0_test_send_sdu(&um_tx, 1); rlc_um_v9_3_0_test_exchange_delayed_pdus(&um_tx, &um_rx, 3, 200, 0, 0, INCREMENT_FRAME_YES); @@ -716,7 +665,6 @@ void rlc_um_v9_3_0_test_reordering(uint32_t sn_field_lengthP) rlc_um_v9_3_0_test_exchange_delayed_pdus(&um_tx, &um_rx, 2000, 200, 0, 0, INCREMENT_FRAME_YES); printf("g_send_id_read_index[1]=%d g_send_id_write_index[0]=%d Loop %d (2)\n", g_send_id_read_index[1], g_send_id_write_index[0], j); - assert (g_send_id_read_index[1] != g_send_id_write_index[0]); } @@ -728,21 +676,14 @@ void rlc_um_v9_3_0_test_tx_rx_10(void) { rlc_um_info_t um_info; int i,j,r; - - um_info.timer_reordering = 32; um_info.sn_field_length = 10; um_info.is_mXch = 0; - srand (0); config_req_rlc_um (&um_tx, 0,0,0, &um_info, 0, SIGNALLING_RADIO_BEARER, SIGNALLING_RADIO_BEARER /*LC-id = DRB-id*/); config_req_rlc_um (&um_rx, 0,1,1, &um_info, 1, SIGNALLING_RADIO_BEARER, SIGNALLING_RADIO_BEARER /*LC-id = DRB-id*/); - rlc_um_display_rx_window(&um_tx); - rlc_um_display_rx_window(&um_rx); - - #ifdef TEST1 srand (0); rlc_um_v9_3_0_test_reset_sdus(); @@ -765,7 +706,6 @@ void rlc_um_v9_3_0_test_tx_rx_10(void) rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 1000, 200); rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 1000, 200); rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 1000, 200); - assert (g_send_id_read_index[1] == g_send_id_write_index[0]); printf("\n\n\n\n\n\n-----------------------------------------------------------------------------------------rlc_um_v9_3_0_test 1: END OF SIMPLE TEST SEVERAL SDUs IN PDU\n\n\n\n"); sleep(2); @@ -837,7 +777,6 @@ void rlc_um_v9_3_0_test_tx_rx_10(void) rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 2000, 200); rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 2000, 200); rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 2000, 200); - rlc_um_v9_3_0_test_send_sdu(&um_tx, 1); rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 30, 200); rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 31, 200); @@ -983,8 +922,6 @@ void rlc_um_v9_3_0_test_tx_rx_10(void) rlc_um_v9_3_0_test_send_sdu(&um_tx, g_random_sdu); g_random_sdu = rand() % 37; //rlc_um_v9_3_0_test_send_sdu(&um_rx, g_random_sdu); - - g_random_nb_frames = rand() % 4; for (j = 0; j < g_random_nb_frames; j++) { @@ -995,7 +932,6 @@ void rlc_um_v9_3_0_test_tx_rx_10(void) //rlc_um_display_rx_window(&um_tx); rlc_um_display_rx_window(&um_rx); - int dropped = (rand() % 3); if ((dropped == 0) && (g_tx_packets > 0)) { @@ -1028,7 +964,6 @@ void rlc_um_v9_3_0_test_tx_rx_10(void) g_target_tx_error_rate, (g_rx_packets >0)?(g_dropped_rx_packets*100)/g_rx_packets:0, g_target_rx_error_rate); - } } @@ -1057,21 +992,14 @@ void rlc_um_v9_3_0_test_tx_rx_5(void) { rlc_um_info_t um_info; int i,j,r; - - um_info.timer_reordering = 32; um_info.sn_field_length = 5; um_info.is_mXch = 0; - srand (0); config_req_rlc_um (&um_tx, 0,0,0, &um_info, 0, SIGNALLING_RADIO_BEARER, SIGNALLING_RADIO_BEARER /*LC-id = DRB-id*/); config_req_rlc_um (&um_rx, 0,1,1, &um_info, 1, SIGNALLING_RADIO_BEARER, SIGNALLING_RADIO_BEARER /*LC-id = DRB-id*/); - rlc_um_display_rx_window(&um_tx); - rlc_um_display_rx_window(&um_rx); - - #ifdef TEST1 srand (0); printf("\n\n\n\n\n\n-----------------------------------------------------------------------------------------rlc_um_v9_3_0_test_5 1: START OF SIMPLE TEST SEVERAL SDUs IN PDU\n\n\n\n"); @@ -1095,7 +1023,6 @@ void rlc_um_v9_3_0_test_tx_rx_5(void) rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 1000, 200); rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 1000, 200); rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 1000, 200); - assert (g_send_id_read_index[1] == g_send_id_write_index[0]); printf("\n\n\n\n\n\n-----------------------------------------------------------------------------------------rlc_um_v9_3_0_test_5 1: END OF SIMPLE TEST SEVERAL SDUs IN PDU\n\n\n\n"); sleep(2); @@ -1163,7 +1090,6 @@ void rlc_um_v9_3_0_test_tx_rx_5(void) rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 2000, 200); rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 2000, 200); rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 2000, 200); - rlc_um_v9_3_0_test_send_sdu(&um_tx, 1); rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 26, 200); rlc_um_v9_3_0_test_exchange_pdus(&um_tx, &um_rx, 27, 200); @@ -1301,8 +1227,6 @@ void rlc_um_v9_3_0_test_tx_rx_5(void) rlc_um_v9_3_0_test_send_sdu(&um_tx, g_random_sdu); g_random_sdu = rand() % 37; //rlc_um_v9_3_0_test_send_sdu(&um_rx, g_random_sdu); - - g_random_nb_frames = rand() % 4; for (j = 0; j < g_random_nb_frames; j++) { @@ -1313,7 +1237,6 @@ void rlc_um_v9_3_0_test_tx_rx_5(void) //rlc_um_display_rx_window(&um_tx); rlc_um_display_rx_window(&um_rx); - int dropped = (rand() % 3); if ((dropped == 0) && (g_tx_packets > 0)) { @@ -1346,7 +1269,6 @@ void rlc_um_v9_3_0_test_tx_rx_5(void) g_target_tx_error_rate, (g_rx_packets >0)?(g_dropped_rx_packets*100)/g_rx_packets:0, g_target_rx_error_rate); - } } @@ -1378,11 +1300,9 @@ void rlc_um_v9_3_0_test_print_trace (void) size_t size; char **strings; size_t i; - size = backtrace (array, 100); strings = backtrace_symbols (array, size); - - printf ("Obtained %d stack frames.\n", size); + printf ("Obtained %lu stack frames.\n", (unsigned long)size); for (i = 0; i < size; i++) { printf ("%s\n", strings[i]); @@ -1395,23 +1315,15 @@ void rlc_um_v9_3_0_test(void) //----------------------------------------------------------------------------- { pool_buffer_init(); - set_comp_log(RLC, LOG_TRACE, LOG_MED, 1); - - // tested OK rlc_um_v9_3_0_test_reordering(10); - rlc_um_v9_3_0_test_tx_rx_10(); - // tested OK rlc_um_v9_3_0_test_windows_10(); - rlc_um_v9_3_0_test_tx_rx_5(); rlc_um_v9_3_0_test_windows_5(); rlc_um_v9_3_0_test_reordering(5); - - printf("rlc_um_v9_3_0_test: END OF TESTS\n"); exit(0); } diff --git a/openair2/LAYER2/RLC/rlc.c b/openair2/LAYER2/RLC/rlc.c index e5d9977de75b3f0a16570cada2921ad32355d80d..74e22194f9c7fc2308721b941bf50fce5e4b8600 100644 --- a/openair2/LAYER2/RLC/rlc.c +++ b/openair2/LAYER2/RLC/rlc.c @@ -677,7 +677,7 @@ void rlc_module_cleanup (void) //----------------------------------------------------------------------------- { - hashtable_destroy(rlc_coll_p); + hashtable_destroy(&rlc_coll_p); } //----------------------------------------------------------------------------- void diff --git a/openair2/LAYER2/openair2_proc.c b/openair2/LAYER2/openair2_proc.c index 78a893cfae0b2fe72eb2cb87172885c5d3393745..50c8ac58b430881edf33360a2c9e8b5591d4b881 100644 --- a/openair2/LAYER2/openair2_proc.c +++ b/openair2/LAYER2/openair2_proc.c @@ -39,644 +39,586 @@ #include "common/ran_context.h" static mapping rrc_status_names[] = { - {"RRC_INACTIVE", 0}, - {"RRC_IDLE", 1}, - {"RRC_SI_RECEIVED",2}, - {"RRC_CONNECTED",3}, - {"RRC_RECONFIGURED",4}, - {"RRC_HO_EXECUTION",5}, - {NULL, -1} + {"RRC_INACTIVE", 0}, + {"RRC_IDLE", 1}, + {"RRC_SI_RECEIVED",2}, + {"RRC_CONNECTED",3}, + {"RRC_RECONFIGURED",4}, + {"RRC_HO_EXECUTION",5}, + {NULL, -1} }; extern RAN_CONTEXT_t RC; -int dump_eNB_l2_stats(char *buffer, int length) -{ - - int eNB_id,UE_id,number_of_cards; - int len= length; - int CC_id=0; - int i; - protocol_ctxt_t ctxt; - rlc_op_status_t rlc_status; - unsigned int stat_rlc_mode; - unsigned int stat_tx_pdcp_sdu; - unsigned int stat_tx_pdcp_bytes; - unsigned int stat_tx_pdcp_sdu_discarded; - unsigned int stat_tx_pdcp_bytes_discarded; - unsigned int stat_tx_data_pdu; - unsigned int stat_tx_data_bytes; - unsigned int stat_tx_retransmit_pdu_by_status; - unsigned int stat_tx_retransmit_bytes_by_status; - unsigned int stat_tx_retransmit_pdu; - unsigned int stat_tx_retransmit_bytes; - unsigned int stat_tx_control_pdu; - unsigned int stat_tx_control_bytes; - unsigned int stat_rx_pdcp_sdu; - unsigned int stat_rx_pdcp_bytes; - unsigned int stat_rx_data_pdus_duplicate; - unsigned int stat_rx_data_bytes_duplicate; - unsigned int stat_rx_data_pdu; - unsigned int stat_rx_data_bytes; - unsigned int stat_rx_data_pdu_dropped; - unsigned int stat_rx_data_bytes_dropped; - unsigned int stat_rx_data_pdu_out_of_window; - unsigned int stat_rx_data_bytes_out_of_window; - unsigned int stat_rx_control_pdu; - unsigned int stat_rx_control_bytes; - unsigned int stat_timer_reordering_timed_out; - unsigned int stat_timer_poll_retransmit_timed_out; - unsigned int stat_timer_status_prohibit_timed_out; - +int dump_eNB_l2_stats(char *buffer, int length) { + int eNB_id,UE_id,number_of_cards; + int len= length; + int CC_id=0; + int i; + protocol_ctxt_t ctxt; + rlc_op_status_t rlc_status; + unsigned int stat_rlc_mode; + unsigned int stat_tx_pdcp_sdu; + unsigned int stat_tx_pdcp_bytes; + unsigned int stat_tx_pdcp_sdu_discarded; + unsigned int stat_tx_pdcp_bytes_discarded; + unsigned int stat_tx_data_pdu; + unsigned int stat_tx_data_bytes; + unsigned int stat_tx_retransmit_pdu_by_status; + unsigned int stat_tx_retransmit_bytes_by_status; + unsigned int stat_tx_retransmit_pdu; + unsigned int stat_tx_retransmit_bytes; + unsigned int stat_tx_control_pdu; + unsigned int stat_tx_control_bytes; + unsigned int stat_rx_pdcp_sdu; + unsigned int stat_rx_pdcp_bytes; + unsigned int stat_rx_data_pdus_duplicate; + unsigned int stat_rx_data_bytes_duplicate; + unsigned int stat_rx_data_pdu; + unsigned int stat_rx_data_bytes; + unsigned int stat_rx_data_pdu_dropped; + unsigned int stat_rx_data_bytes_dropped; + unsigned int stat_rx_data_pdu_out_of_window; + unsigned int stat_rx_data_bytes_out_of_window; + unsigned int stat_rx_control_pdu; + unsigned int stat_rx_control_bytes; + unsigned int stat_timer_reordering_timed_out; + unsigned int stat_timer_poll_retransmit_timed_out; + unsigned int stat_timer_status_prohibit_timed_out; #ifdef EXMIMO - number_of_cards=1; + number_of_cards=1; #else - number_of_cards=NB_eNB_INST; + number_of_cards=NB_eNB_INST; #endif - eNB_MAC_INST *eNB; - UE_list_t *UE_list; - - for (eNB_id=0; eNB_id<number_of_cards; eNB_id++) { - /* reset the values */ - eNB = RC.mac[eNB_id]; - UE_list = &eNB->UE_list; - - for (CC_id=0 ; CC_id < MAX_NUM_CCs; CC_id++) { - eNB->eNB_stats[CC_id].dlsch_bitrate= 0; - - len += sprintf(&buffer[len],"eNB %d CC %d Frame %d: Active UEs %d, Available PRBs %d, nCCE %d, Scheduling decisions %d, Missed Deadlines %d \n", - eNB_id, CC_id, eNB->frame, - eNB->eNB_stats[CC_id].num_dlactive_UEs, - eNB->eNB_stats[CC_id].available_prbs, - eNB->eNB_stats[CC_id].available_ncces, - eNB->eNB_stats[CC_id].sched_decisions, - eNB->eNB_stats[CC_id].missed_deadlines); - - len += sprintf(&buffer[len],"BCCH , NB_TX_MAC = %d, transmitted bytes (TTI %d, total %d) MCS (TTI %d)\n", - eNB->eNB_stats[CC_id].total_num_bcch_pdu, - eNB->eNB_stats[CC_id].bcch_buffer, - eNB->eNB_stats[CC_id].total_bcch_buffer, - eNB->eNB_stats[CC_id].bcch_mcs); - - len += sprintf(&buffer[len],"PCCH , NB_TX_MAC = %d, transmitted bytes (TTI %d, total %d) MCS (TTI %d)\n", - eNB->eNB_stats[CC_id].total_num_pcch_pdu, - eNB->eNB_stats[CC_id].pcch_buffer, - eNB->eNB_stats[CC_id].total_pcch_buffer, - eNB->eNB_stats[CC_id].pcch_mcs); - - eNB->eNB_stats[CC_id].dlsch_bitrate=((eNB->eNB_stats[CC_id].dlsch_bytes_tx*8)/((eNB->frame + 1)*10)); - eNB->eNB_stats[CC_id].total_dlsch_pdus_tx+=eNB->eNB_stats[CC_id].dlsch_pdus_tx; - eNB->eNB_stats[CC_id].total_dlsch_bytes_tx+=eNB->eNB_stats[CC_id].dlsch_bytes_tx; - eNB->eNB_stats[CC_id].total_dlsch_bitrate=((eNB->eNB_stats[CC_id].total_dlsch_bytes_tx*8)/((eNB->frame + 1)*10)); - - eNB->eNB_stats[CC_id].ulsch_bitrate=((eNB->eNB_stats[CC_id].ulsch_bytes_rx*8)/((eNB->frame + 1)*10)); - eNB->eNB_stats[CC_id].total_ulsch_bitrate=((eNB->eNB_stats[CC_id].total_ulsch_bytes_rx*8)/((eNB->frame + 1)*10)); - - len += sprintf(&buffer[len],"DLSCH bitrate (TTI %u, avg %u) kbps, Transmitted bytes (TTI %u, total %u), Transmitted PDU (TTI %u, total %u) \n", - eNB->eNB_stats[CC_id].dlsch_bitrate, - eNB->eNB_stats[CC_id].total_dlsch_bitrate, - eNB->eNB_stats[CC_id].dlsch_bytes_tx, - eNB->eNB_stats[CC_id].total_dlsch_bytes_tx, - eNB->eNB_stats[CC_id].dlsch_pdus_tx, - eNB->eNB_stats[CC_id].total_dlsch_pdus_tx); - - len += sprintf(&buffer[len],"ULSCH bitrate (TTI %u, avg %u) kbps, Received bytes (TTI %u, total %u), Received PDU (TTI %lu, total %u) \n", - eNB->eNB_stats[CC_id].ulsch_bitrate, - eNB->eNB_stats[CC_id].total_ulsch_bitrate, - eNB->eNB_stats[CC_id].ulsch_bytes_rx, - eNB->eNB_stats[CC_id].total_ulsch_bytes_rx, - eNB->eNB_stats[CC_id].ulsch_pdus_rx, - eNB->eNB_stats[CC_id].total_ulsch_pdus_rx); - } + eNB_MAC_INST *eNB; + UE_list_t *UE_list; + + for (eNB_id=0; eNB_id<number_of_cards; eNB_id++) { + /* reset the values */ + eNB = RC.mac[eNB_id]; + UE_list = &eNB->UE_list; + + for (CC_id=0 ; CC_id < MAX_NUM_CCs; CC_id++) { + eNB->eNB_stats[CC_id].dlsch_bitrate= 0; + len += sprintf(&buffer[len],"eNB %d CC %d Frame %d: Active UEs %d, Available PRBs %d, nCCE %d, Scheduling decisions %d, Missed Deadlines %d \n", + eNB_id, CC_id, eNB->frame, + eNB->eNB_stats[CC_id].num_dlactive_UEs, + eNB->eNB_stats[CC_id].available_prbs, + eNB->eNB_stats[CC_id].available_ncces, + eNB->eNB_stats[CC_id].sched_decisions, + eNB->eNB_stats[CC_id].missed_deadlines); + len += sprintf(&buffer[len],"BCCH , NB_TX_MAC = %d, transmitted bytes (TTI %d, total %d) MCS (TTI %d)\n", + eNB->eNB_stats[CC_id].total_num_bcch_pdu, + eNB->eNB_stats[CC_id].bcch_buffer, + eNB->eNB_stats[CC_id].total_bcch_buffer, + eNB->eNB_stats[CC_id].bcch_mcs); + len += sprintf(&buffer[len],"PCCH , NB_TX_MAC = %d, transmitted bytes (TTI %d, total %d) MCS (TTI %d)\n", + eNB->eNB_stats[CC_id].total_num_pcch_pdu, + eNB->eNB_stats[CC_id].pcch_buffer, + eNB->eNB_stats[CC_id].total_pcch_buffer, + eNB->eNB_stats[CC_id].pcch_mcs); + eNB->eNB_stats[CC_id].dlsch_bitrate=((eNB->eNB_stats[CC_id].dlsch_bytes_tx*8)/((eNB->frame + 1)*10)); + eNB->eNB_stats[CC_id].total_dlsch_pdus_tx+=eNB->eNB_stats[CC_id].dlsch_pdus_tx; + eNB->eNB_stats[CC_id].total_dlsch_bytes_tx+=eNB->eNB_stats[CC_id].dlsch_bytes_tx; + eNB->eNB_stats[CC_id].total_dlsch_bitrate=((eNB->eNB_stats[CC_id].total_dlsch_bytes_tx*8)/((eNB->frame + 1)*10)); + eNB->eNB_stats[CC_id].ulsch_bitrate=((eNB->eNB_stats[CC_id].ulsch_bytes_rx*8)/((eNB->frame + 1)*10)); + eNB->eNB_stats[CC_id].total_ulsch_bitrate=((eNB->eNB_stats[CC_id].total_ulsch_bytes_rx*8)/((eNB->frame + 1)*10)); + len += sprintf(&buffer[len],"DLSCH bitrate (TTI %u, avg %u) kbps, Transmitted bytes (TTI %u, total %u), Transmitted PDU (TTI %u, total %u) \n", + eNB->eNB_stats[CC_id].dlsch_bitrate, + eNB->eNB_stats[CC_id].total_dlsch_bitrate, + eNB->eNB_stats[CC_id].dlsch_bytes_tx, + eNB->eNB_stats[CC_id].total_dlsch_bytes_tx, + eNB->eNB_stats[CC_id].dlsch_pdus_tx, + eNB->eNB_stats[CC_id].total_dlsch_pdus_tx); + len += sprintf(&buffer[len],"ULSCH bitrate (TTI %u, avg %u) kbps, Received bytes (TTI %u, total %u), Received PDU (TTI %lu, total %u) \n", + eNB->eNB_stats[CC_id].ulsch_bitrate, + eNB->eNB_stats[CC_id].total_ulsch_bitrate, + eNB->eNB_stats[CC_id].ulsch_bytes_rx, + eNB->eNB_stats[CC_id].total_ulsch_bytes_rx, + eNB->eNB_stats[CC_id].ulsch_pdus_rx, + eNB->eNB_stats[CC_id].total_ulsch_pdus_rx); + } + + len += sprintf(&buffer[len],"\n"); + + for (UE_id=UE_list->head; UE_id>=0; UE_id=UE_list->next[UE_id]) { + for (i=0; i<UE_list->numactiveCCs[UE_id]; i++) { + CC_id=UE_list->ordered_CCids[i][UE_id]; + UE_list->eNB_UE_stats[CC_id][UE_id].dlsch_bitrate=((UE_list->eNB_UE_stats[CC_id][UE_id].TBS*8)/((eNB->frame + 1)*10)); + UE_list->eNB_UE_stats[CC_id][UE_id].total_dlsch_bitrate= ((UE_list->eNB_UE_stats[CC_id][UE_id].total_pdu_bytes*8)/((eNB->frame + 1)*10)); + UE_list->eNB_UE_stats[CC_id][UE_id].total_overhead_bytes+= UE_list->eNB_UE_stats[CC_id][UE_id].overhead_bytes; + UE_list->eNB_UE_stats[CC_id][UE_id].avg_overhead_bytes=((UE_list->eNB_UE_stats[CC_id][UE_id].total_overhead_bytes*8)/((eNB->frame + 1)*10)); + UE_list->eNB_UE_stats[CC_id][UE_id].ulsch_bitrate=((UE_list->eNB_UE_stats[CC_id][UE_id].ulsch_TBS*8)/((eNB->frame + 1)*10)); + UE_list->eNB_UE_stats[CC_id][UE_id].total_ulsch_bitrate= ((UE_list->eNB_UE_stats[CC_id][UE_id].total_pdu_bytes_rx*8)/((eNB->frame + 1)*10)); + len += sprintf(&buffer[len],"[MAC] UE %d (DLSCH),status %s, RNTI %x : CQI %d, MCS1 %d, MCS2 %d, RB (tx %d, retx %d, total %d), ncce (tx %d, retx %d) \n", + UE_id, + map_int_to_str(rrc_status_names, UE_list->eNB_UE_stats[CC_id][UE_id].rrc_status), + UE_list->eNB_UE_stats[CC_id][UE_id].crnti, + UE_list->UE_sched_ctrl[UE_id].dl_cqi[CC_id], + UE_list->eNB_UE_stats[CC_id][UE_id].dlsch_mcs1, + UE_list->eNB_UE_stats[CC_id][UE_id].dlsch_mcs2, + UE_list->eNB_UE_stats[CC_id][UE_id].rbs_used, + UE_list->eNB_UE_stats[CC_id][UE_id].rbs_used_retx, + UE_list->eNB_UE_stats[CC_id][UE_id].total_rbs_used, + UE_list->eNB_UE_stats[CC_id][UE_id].ncce_used, + UE_list->eNB_UE_stats[CC_id][UE_id].ncce_used_retx + ); + len += sprintf(&buffer[len], + "[MAC] DLSCH bitrate (TTI %d, avg %d), Transmitted bytes " + "(TTI %d, total %"PRIu64"), Total Transmitted PDU %d, Overhead " + "(TTI %"PRIu64", total %"PRIu64", avg %"PRIu64")\n", + UE_list->eNB_UE_stats[CC_id][UE_id].dlsch_bitrate, + UE_list->eNB_UE_stats[CC_id][UE_id].total_dlsch_bitrate, + UE_list->eNB_UE_stats[CC_id][UE_id].TBS, + UE_list->eNB_UE_stats[CC_id][UE_id].total_pdu_bytes, + UE_list->eNB_UE_stats[CC_id][UE_id].total_num_pdus, + UE_list->eNB_UE_stats[CC_id][UE_id].overhead_bytes, + UE_list->eNB_UE_stats[CC_id][UE_id].total_overhead_bytes, + UE_list->eNB_UE_stats[CC_id][UE_id].avg_overhead_bytes + ); + len += sprintf(&buffer[len],"[MAC] UE %d (ULSCH), Status %s, Failute timer %d, RNTI %x : rx power (normalized %d, target %d), MCS (pre %d, post %d), RB (rx %d, retx %d, total %d), Current TBS %d \n", + UE_id, + map_int_to_str(rrc_status_names, UE_list->eNB_UE_stats[CC_id][UE_id].rrc_status), + UE_list->UE_sched_ctrl[UE_id].ul_failure_timer, + UE_list->eNB_UE_stats[CC_id][UE_id].crnti, + UE_list->eNB_UE_stats[CC_id][UE_id].normalized_rx_power, + UE_list->eNB_UE_stats[CC_id][UE_id].target_rx_power, + UE_list->eNB_UE_stats[CC_id][UE_id].ulsch_mcs1, + UE_list->eNB_UE_stats[CC_id][UE_id].ulsch_mcs2, + UE_list->eNB_UE_stats[CC_id][UE_id].rbs_used_rx, + UE_list->eNB_UE_stats[CC_id][UE_id].rbs_used_retx_rx, + UE_list->eNB_UE_stats[CC_id][UE_id].total_rbs_used_rx, + UE_list->eNB_UE_stats[CC_id][UE_id].ulsch_TBS + ); + len += sprintf(&buffer[len], + "[MAC] ULSCH bitrate (TTI %d, avg %d), received bytes (total %"PRIu64")," + "Total received PDU %d, Total errors %d\n", + UE_list->eNB_UE_stats[CC_id][UE_id].ulsch_bitrate, + UE_list->eNB_UE_stats[CC_id][UE_id].total_ulsch_bitrate, + UE_list->eNB_UE_stats[CC_id][UE_id].total_pdu_bytes_rx, + UE_list->eNB_UE_stats[CC_id][UE_id].total_num_pdus_rx, + UE_list->eNB_UE_stats[CC_id][UE_id].num_errors_rx); + len+= sprintf(&buffer[len],"[MAC] Received PHR PH = %d (db)\n", UE_list->UE_template[CC_id][UE_id].phr_info); + len+= sprintf(&buffer[len],"[MAC] Estimated size LCGID[0][1][2][3] = %u %u %u %u\n", + UE_list->UE_template[CC_id][UE_id].ul_buffer_info[LCGID0], + UE_list->UE_template[CC_id][UE_id].ul_buffer_info[LCGID1], + UE_list->UE_template[CC_id][UE_id].ul_buffer_info[LCGID2], + UE_list->UE_template[CC_id][UE_id].ul_buffer_info[LCGID3] + ); + } + + PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, + eNB_id, + ENB_FLAG_YES, + UE_list->eNB_UE_stats[0][UE_id].crnti,//UE_PCCID(eNB_id,UE_id)][UE_id].crnti, + eNB->frame, + eNB->subframe, + eNB_id); + rlc_status = rlc_stat_req(&ctxt, + SRB_FLAG_YES, + DCCH, + &stat_rlc_mode, + &stat_tx_pdcp_sdu, + &stat_tx_pdcp_bytes, + &stat_tx_pdcp_sdu_discarded, + &stat_tx_pdcp_bytes_discarded, + &stat_tx_data_pdu, + &stat_tx_data_bytes, + &stat_tx_retransmit_pdu_by_status, + &stat_tx_retransmit_bytes_by_status, + &stat_tx_retransmit_pdu, + &stat_tx_retransmit_bytes, + &stat_tx_control_pdu, + &stat_tx_control_bytes, + &stat_rx_pdcp_sdu, + &stat_rx_pdcp_bytes, + &stat_rx_data_pdus_duplicate, + &stat_rx_data_bytes_duplicate, + &stat_rx_data_pdu, + &stat_rx_data_bytes, + &stat_rx_data_pdu_dropped, + &stat_rx_data_bytes_dropped, + &stat_rx_data_pdu_out_of_window, + &stat_rx_data_bytes_out_of_window, + &stat_rx_control_pdu, + &stat_rx_control_bytes, + &stat_timer_reordering_timed_out, + &stat_timer_poll_retransmit_timed_out, + &stat_timer_status_prohibit_timed_out); + + if (rlc_status == RLC_OP_STATUS_OK) { + len+=sprintf(&buffer[len],"[RLC] DCCH Mode %s, NB_SDU_TO_TX = %u (bytes %u)\tNB_SDU_TO_TX_DISC %u (bytes %u)\n", + (stat_rlc_mode==RLC_MODE_AM)? "AM": (stat_rlc_mode==RLC_MODE_UM)?"UM":"NONE", + stat_tx_pdcp_sdu, + stat_tx_pdcp_bytes, + stat_tx_pdcp_sdu_discarded, + stat_tx_pdcp_bytes_discarded); + len+=sprintf(&buffer[len],"[RLC] DCCH Mode %s, NB_TX_DATA = %u (bytes %u)\tNB_TX_CONTROL %u (bytes %u)\tNB_TX_RETX %u (bytes %u)\tNB_TX_RETX_BY_STATUS = %u (bytes %u)\n", + (stat_rlc_mode==RLC_MODE_AM)? "AM": (stat_rlc_mode==RLC_MODE_UM)?"UM":"NONE", + stat_tx_data_pdu, + stat_tx_data_bytes, + stat_tx_control_pdu, + stat_tx_control_bytes, + stat_tx_retransmit_pdu, + stat_tx_retransmit_bytes, + stat_tx_retransmit_pdu_by_status, + stat_tx_retransmit_bytes_by_status); + len+=sprintf(&buffer[len],"[RLC] DCCH Mode %s, NB_RX_DATA = %u (bytes %u)\tNB_RX_CONTROL %u (bytes %u)\tNB_RX_DUPL %u (bytes %u)\tNB_RX_DROP = %u (bytes %u)\tNB_RX_OUT_OF_WINDOW = %u (bytes %u)\n", + (stat_rlc_mode==RLC_MODE_AM)? "AM": (stat_rlc_mode==RLC_MODE_UM)?"UM":"NONE", + stat_rx_data_pdu, + stat_rx_data_bytes, + stat_rx_control_pdu, + stat_rx_control_bytes, + stat_rx_data_pdus_duplicate, + stat_rx_data_bytes_duplicate, + stat_rx_data_pdu_dropped, + stat_rx_data_bytes_dropped, + stat_rx_data_pdu_out_of_window, + stat_rx_data_bytes_out_of_window); + len+=sprintf(&buffer[len],"[RLC] DCCH Mode %s, RX_REODERING_TIMEOUT = %u\tRX_POLL_RET_TIMEOUT %u\tRX_PROHIBIT_TIME_OUT %u\n", + (stat_rlc_mode==RLC_MODE_AM)? "AM": (stat_rlc_mode==RLC_MODE_UM)?"UM":"NONE", + stat_timer_reordering_timed_out, + stat_timer_poll_retransmit_timed_out, + stat_timer_status_prohibit_timed_out); + len+=sprintf(&buffer[len],"[RLC] DCCH Mode %s, NB_SDU_TO_RX = %u (bytes %u)\n", + (stat_rlc_mode==RLC_MODE_AM)? "AM": (stat_rlc_mode==RLC_MODE_UM)?"UM":"NONE", + stat_rx_pdcp_sdu, + stat_rx_pdcp_bytes); + } - len += sprintf(&buffer[len],"\n"); - - for (UE_id=UE_list->head; UE_id>=0; UE_id=UE_list->next[UE_id]) { - for (i=0; i<UE_list->numactiveCCs[UE_id]; i++) { - CC_id=UE_list->ordered_CCids[i][UE_id]; - - UE_list->eNB_UE_stats[CC_id][UE_id].dlsch_bitrate=((UE_list->eNB_UE_stats[CC_id][UE_id].TBS*8)/((eNB->frame + 1)*10)); - UE_list->eNB_UE_stats[CC_id][UE_id].total_dlsch_bitrate= ((UE_list->eNB_UE_stats[CC_id][UE_id].total_pdu_bytes*8)/((eNB->frame + 1)*10)); - UE_list->eNB_UE_stats[CC_id][UE_id].total_overhead_bytes+= UE_list->eNB_UE_stats[CC_id][UE_id].overhead_bytes; - UE_list->eNB_UE_stats[CC_id][UE_id].avg_overhead_bytes=((UE_list->eNB_UE_stats[CC_id][UE_id].total_overhead_bytes*8)/((eNB->frame + 1)*10)); - - UE_list->eNB_UE_stats[CC_id][UE_id].ulsch_bitrate=((UE_list->eNB_UE_stats[CC_id][UE_id].ulsch_TBS*8)/((eNB->frame + 1)*10)); - UE_list->eNB_UE_stats[CC_id][UE_id].total_ulsch_bitrate= ((UE_list->eNB_UE_stats[CC_id][UE_id].total_pdu_bytes_rx*8)/((eNB->frame + 1)*10)); - - len += sprintf(&buffer[len],"[MAC] UE %d (DLSCH),status %s, RNTI %x : CQI %d, MCS1 %d, MCS2 %d, RB (tx %d, retx %d, total %d), ncce (tx %d, retx %d) \n", - UE_id, - map_int_to_str(rrc_status_names, UE_list->eNB_UE_stats[CC_id][UE_id].rrc_status), - UE_list->eNB_UE_stats[CC_id][UE_id].crnti, - UE_list->UE_sched_ctrl[UE_id].dl_cqi[CC_id], - UE_list->eNB_UE_stats[CC_id][UE_id].dlsch_mcs1, - UE_list->eNB_UE_stats[CC_id][UE_id].dlsch_mcs2, - UE_list->eNB_UE_stats[CC_id][UE_id].rbs_used, - UE_list->eNB_UE_stats[CC_id][UE_id].rbs_used_retx, - UE_list->eNB_UE_stats[CC_id][UE_id].total_rbs_used, - UE_list->eNB_UE_stats[CC_id][UE_id].ncce_used, - UE_list->eNB_UE_stats[CC_id][UE_id].ncce_used_retx - ); - - len += sprintf(&buffer[len], - "[MAC] DLSCH bitrate (TTI %d, avg %d), Transmitted bytes " - "(TTI %d, total %"PRIu64"), Total Transmitted PDU %d, Overhead " - "(TTI %"PRIu64", total %"PRIu64", avg %"PRIu64")\n", - UE_list->eNB_UE_stats[CC_id][UE_id].dlsch_bitrate, - UE_list->eNB_UE_stats[CC_id][UE_id].total_dlsch_bitrate, - UE_list->eNB_UE_stats[CC_id][UE_id].TBS, - UE_list->eNB_UE_stats[CC_id][UE_id].total_pdu_bytes, - UE_list->eNB_UE_stats[CC_id][UE_id].total_num_pdus, - UE_list->eNB_UE_stats[CC_id][UE_id].overhead_bytes, - UE_list->eNB_UE_stats[CC_id][UE_id].total_overhead_bytes, - UE_list->eNB_UE_stats[CC_id][UE_id].avg_overhead_bytes - ); - - - len += sprintf(&buffer[len],"[MAC] UE %d (ULSCH), Status %s, Failute timer %d, RNTI %x : rx power (normalized %d, target %d), MCS (pre %d, post %d), RB (rx %d, retx %d, total %d), Current TBS %d \n", - UE_id, - map_int_to_str(rrc_status_names, UE_list->eNB_UE_stats[CC_id][UE_id].rrc_status), - UE_list->UE_sched_ctrl[UE_id].ul_failure_timer, - UE_list->eNB_UE_stats[CC_id][UE_id].crnti, - UE_list->eNB_UE_stats[CC_id][UE_id].normalized_rx_power, - UE_list->eNB_UE_stats[CC_id][UE_id].target_rx_power, - UE_list->eNB_UE_stats[CC_id][UE_id].ulsch_mcs1, - UE_list->eNB_UE_stats[CC_id][UE_id].ulsch_mcs2, - UE_list->eNB_UE_stats[CC_id][UE_id].rbs_used_rx, - UE_list->eNB_UE_stats[CC_id][UE_id].rbs_used_retx_rx, - UE_list->eNB_UE_stats[CC_id][UE_id].total_rbs_used_rx, - UE_list->eNB_UE_stats[CC_id][UE_id].ulsch_TBS - ); - - len += sprintf(&buffer[len], - "[MAC] ULSCH bitrate (TTI %d, avg %d), received bytes (total %"PRIu64")," - "Total received PDU %d, Total errors %d\n", - UE_list->eNB_UE_stats[CC_id][UE_id].ulsch_bitrate, - UE_list->eNB_UE_stats[CC_id][UE_id].total_ulsch_bitrate, - UE_list->eNB_UE_stats[CC_id][UE_id].total_pdu_bytes_rx, - UE_list->eNB_UE_stats[CC_id][UE_id].total_num_pdus_rx, - UE_list->eNB_UE_stats[CC_id][UE_id].num_errors_rx); - - len+= sprintf(&buffer[len],"[MAC] Received PHR PH = %d (db)\n", UE_list->UE_template[CC_id][UE_id].phr_info); - len+= sprintf(&buffer[len],"[MAC] Estimated size LCGID[0][1][2][3] = %u %u %u %u\n", - UE_list->UE_template[CC_id][UE_id].ul_buffer_info[LCGID0], - UE_list->UE_template[CC_id][UE_id].ul_buffer_info[LCGID1], - UE_list->UE_template[CC_id][UE_id].ul_buffer_info[LCGID2], - UE_list->UE_template[CC_id][UE_id].ul_buffer_info[LCGID3] - ); - } - - PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, - eNB_id, - ENB_FLAG_YES, - UE_list->eNB_UE_stats[0][UE_id].crnti,//UE_PCCID(eNB_id,UE_id)][UE_id].crnti, - eNB->frame, - eNB->subframe, - eNB_id); - - rlc_status = rlc_stat_req(&ctxt, - SRB_FLAG_YES, - DCCH, - &stat_rlc_mode, - &stat_tx_pdcp_sdu, - &stat_tx_pdcp_bytes, - &stat_tx_pdcp_sdu_discarded, - &stat_tx_pdcp_bytes_discarded, - &stat_tx_data_pdu, - &stat_tx_data_bytes, - &stat_tx_retransmit_pdu_by_status, - &stat_tx_retransmit_bytes_by_status, - &stat_tx_retransmit_pdu, - &stat_tx_retransmit_bytes, - &stat_tx_control_pdu, - &stat_tx_control_bytes, - &stat_rx_pdcp_sdu, - &stat_rx_pdcp_bytes, - &stat_rx_data_pdus_duplicate, - &stat_rx_data_bytes_duplicate, - &stat_rx_data_pdu, - &stat_rx_data_bytes, - &stat_rx_data_pdu_dropped, - &stat_rx_data_bytes_dropped, - &stat_rx_data_pdu_out_of_window, - &stat_rx_data_bytes_out_of_window, - &stat_rx_control_pdu, - &stat_rx_control_bytes, - &stat_timer_reordering_timed_out, - &stat_timer_poll_retransmit_timed_out, - &stat_timer_status_prohibit_timed_out); - - if (rlc_status == RLC_OP_STATUS_OK) { - len+=sprintf(&buffer[len],"[RLC] DCCH Mode %s, NB_SDU_TO_TX = %d (bytes %d)\tNB_SDU_TO_TX_DISC %d (bytes %d)\n", - (stat_rlc_mode==RLC_MODE_AM)? "AM": (stat_rlc_mode==RLC_MODE_UM)?"UM":"NONE", - stat_tx_pdcp_sdu, - stat_tx_pdcp_bytes, - stat_tx_pdcp_sdu_discarded, - stat_tx_pdcp_bytes_discarded); - - len+=sprintf(&buffer[len],"[RLC] DCCH Mode %s, NB_TX_DATA = %d (bytes %d)\tNB_TX_CONTROL %d (bytes %d)\tNB_TX_RETX %d (bytes %d)\tNB_TX_RETX_BY_STATUS = %d (bytes %d)\n", - (stat_rlc_mode==RLC_MODE_AM)? "AM": (stat_rlc_mode==RLC_MODE_UM)?"UM":"NONE", - stat_tx_data_pdu, - stat_tx_data_bytes, - stat_tx_control_pdu, - stat_tx_control_bytes, - stat_tx_retransmit_pdu, - stat_tx_retransmit_bytes, - stat_tx_retransmit_pdu_by_status, - stat_tx_retransmit_bytes_by_status); - - - len+=sprintf(&buffer[len],"[RLC] DCCH Mode %s, NB_RX_DATA = %d (bytes %d)\tNB_RX_CONTROL %d (bytes %d)\tNB_RX_DUPL %d (bytes %d)\tNB_RX_DROP = %d (bytes %d)\tNB_RX_OUT_OF_WINDOW = %d (bytes %d)\n", - (stat_rlc_mode==RLC_MODE_AM)? "AM": (stat_rlc_mode==RLC_MODE_UM)?"UM":"NONE", - stat_rx_data_pdu, - stat_rx_data_bytes, - stat_rx_control_pdu, - stat_rx_control_bytes, - stat_rx_data_pdus_duplicate, - stat_rx_data_bytes_duplicate, - stat_rx_data_pdu_dropped, - stat_rx_data_bytes_dropped, - stat_rx_data_pdu_out_of_window, - stat_rx_data_bytes_out_of_window); - - - len+=sprintf(&buffer[len],"[RLC] DCCH Mode %s, RX_REODERING_TIMEOUT = %d\tRX_POLL_RET_TIMEOUT %d\tRX_PROHIBIT_TIME_OUT %d\n", - (stat_rlc_mode==RLC_MODE_AM)? "AM": (stat_rlc_mode==RLC_MODE_UM)?"UM":"NONE", - stat_timer_reordering_timed_out, - stat_timer_poll_retransmit_timed_out, - stat_timer_status_prohibit_timed_out); - - len+=sprintf(&buffer[len],"[RLC] DCCH Mode %s, NB_SDU_TO_RX = %d (bytes %d)\n", - (stat_rlc_mode==RLC_MODE_AM)? "AM": (stat_rlc_mode==RLC_MODE_UM)?"UM":"NONE", - stat_rx_pdcp_sdu, - stat_rx_pdcp_bytes); - } - - rlc_status = rlc_stat_req(&ctxt, - SRB_FLAG_NO, - DTCH-2, // DRB_IDENTITY - &stat_rlc_mode, - &stat_tx_pdcp_sdu, - &stat_tx_pdcp_bytes, - &stat_tx_pdcp_sdu_discarded, - &stat_tx_pdcp_bytes_discarded, - &stat_tx_data_pdu, - &stat_tx_data_bytes, - &stat_tx_retransmit_pdu_by_status, - &stat_tx_retransmit_bytes_by_status, - &stat_tx_retransmit_pdu, - &stat_tx_retransmit_bytes, - &stat_tx_control_pdu, - &stat_tx_control_bytes, - &stat_rx_pdcp_sdu, - &stat_rx_pdcp_bytes, - &stat_rx_data_pdus_duplicate, - &stat_rx_data_bytes_duplicate, - &stat_rx_data_pdu, - &stat_rx_data_bytes, - &stat_rx_data_pdu_dropped, - &stat_rx_data_bytes_dropped, - &stat_rx_data_pdu_out_of_window, - &stat_rx_data_bytes_out_of_window, - &stat_rx_control_pdu, - &stat_rx_control_bytes, - &stat_timer_reordering_timed_out, - &stat_timer_poll_retransmit_timed_out, - &stat_timer_status_prohibit_timed_out); - - if (rlc_status == RLC_OP_STATUS_OK) { - len+=sprintf(&buffer[len],"[RLC] DTCH Mode %s, NB_SDU_TO_TX = %d (bytes %d)\tNB_SDU_TO_TX_DISC %d (bytes %d)\n", - (stat_rlc_mode==RLC_MODE_AM)? "AM": (stat_rlc_mode==RLC_MODE_UM)?"UM":"NONE", - stat_tx_pdcp_sdu, - stat_tx_pdcp_bytes, - stat_tx_pdcp_sdu_discarded, - stat_tx_pdcp_bytes_discarded); - - len+=sprintf(&buffer[len],"[RLC] DTCH Mode %s, NB_TX_DATA = %d (bytes %d)\tNB_TX_CONTROL %d (bytes %d)\tNB_TX_RETX %d (bytes %d)\tNB_TX_RETX_BY_STATUS = %d (bytes %d)\n", - (stat_rlc_mode==RLC_MODE_AM)? "AM": (stat_rlc_mode==RLC_MODE_UM)?"UM":"NONE", - stat_tx_data_pdu, - stat_tx_data_bytes, - stat_tx_control_pdu, - stat_tx_control_bytes, - stat_tx_retransmit_pdu, - stat_tx_retransmit_bytes, - stat_tx_retransmit_pdu_by_status, - stat_tx_retransmit_bytes_by_status); - - - len+=sprintf(&buffer[len],"[RLC] DTCH Mode %s, NB_RX_DATA = %d (bytes %d)\tNB_RX_CONTROL %d (bytes %d)\tNB_RX_DUPL %d (bytes %d)\tNB_RX_DROP = %d (bytes %d)\tNB_RX_OUT_OF_WINDOW = %d (bytes %d)\n", - (stat_rlc_mode==RLC_MODE_AM)? "AM": (stat_rlc_mode==RLC_MODE_UM)?"UM":"NONE", - stat_rx_data_pdu, - stat_rx_data_bytes, - stat_rx_control_pdu, - stat_rx_control_bytes, - stat_rx_data_pdus_duplicate, - stat_rx_data_bytes_duplicate, - stat_rx_data_pdu_dropped, - stat_rx_data_bytes_dropped, - stat_rx_data_pdu_out_of_window, - stat_rx_data_bytes_out_of_window); - - - len+=sprintf(&buffer[len],"[RLC] DTCH Mode %s, RX_REODERING_TIMEOUT = %d\tRX_POLL_RET_TIMEOUT %d\tRX_PROHIBIT_TIME_OUT %d\n", - (stat_rlc_mode==RLC_MODE_AM)? "AM": (stat_rlc_mode==RLC_MODE_UM)?"UM":"NONE", - stat_timer_reordering_timed_out, - stat_timer_poll_retransmit_timed_out, - stat_timer_status_prohibit_timed_out); - - len+=sprintf(&buffer[len],"[RLC] DTCH Mode %s, NB_SDU_TO_RX = %d (bytes %d)\n", - (stat_rlc_mode==RLC_MODE_AM)? "AM": (stat_rlc_mode==RLC_MODE_UM)?"UM":"NONE", - stat_rx_pdcp_sdu, - stat_rx_pdcp_bytes); - - } + rlc_status = rlc_stat_req(&ctxt, + SRB_FLAG_NO, + DTCH-2, // DRB_IDENTITY + &stat_rlc_mode, + &stat_tx_pdcp_sdu, + &stat_tx_pdcp_bytes, + &stat_tx_pdcp_sdu_discarded, + &stat_tx_pdcp_bytes_discarded, + &stat_tx_data_pdu, + &stat_tx_data_bytes, + &stat_tx_retransmit_pdu_by_status, + &stat_tx_retransmit_bytes_by_status, + &stat_tx_retransmit_pdu, + &stat_tx_retransmit_bytes, + &stat_tx_control_pdu, + &stat_tx_control_bytes, + &stat_rx_pdcp_sdu, + &stat_rx_pdcp_bytes, + &stat_rx_data_pdus_duplicate, + &stat_rx_data_bytes_duplicate, + &stat_rx_data_pdu, + &stat_rx_data_bytes, + &stat_rx_data_pdu_dropped, + &stat_rx_data_bytes_dropped, + &stat_rx_data_pdu_out_of_window, + &stat_rx_data_bytes_out_of_window, + &stat_rx_control_pdu, + &stat_rx_control_bytes, + &stat_timer_reordering_timed_out, + &stat_timer_poll_retransmit_timed_out, + &stat_timer_status_prohibit_timed_out); + + if (rlc_status == RLC_OP_STATUS_OK) { + len+=sprintf(&buffer[len],"[RLC] DTCH Mode %s, NB_SDU_TO_TX = %u (bytes %u)\tNB_SDU_TO_TX_DISC %u (bytes %u)\n", + (stat_rlc_mode==RLC_MODE_AM)? "AM": (stat_rlc_mode==RLC_MODE_UM)?"UM":"NONE", + stat_tx_pdcp_sdu, + stat_tx_pdcp_bytes, + stat_tx_pdcp_sdu_discarded, + stat_tx_pdcp_bytes_discarded); + len+=sprintf(&buffer[len],"[RLC] DTCH Mode %s, NB_TX_DATA = %u (bytes %u)\tNB_TX_CONTROL %u (bytes %u)\tNB_TX_RETX %u (bytes %u)\tNB_TX_RETX_BY_STATUS = %u (bytes %u)\n", + (stat_rlc_mode==RLC_MODE_AM)? "AM": (stat_rlc_mode==RLC_MODE_UM)?"UM":"NONE", + stat_tx_data_pdu, + stat_tx_data_bytes, + stat_tx_control_pdu, + stat_tx_control_bytes, + stat_tx_retransmit_pdu, + stat_tx_retransmit_bytes, + stat_tx_retransmit_pdu_by_status, + stat_tx_retransmit_bytes_by_status); + len+=sprintf(&buffer[len],"[RLC] DTCH Mode %s, NB_RX_DATA = %u (bytes %u)\tNB_RX_CONTROL %u (bytes %u)\tNB_RX_DUPL %u (bytes %u)\tNB_RX_DROP = %u (bytes %u)\tNB_RX_OUT_OF_WINDOW = %u (bytes %u)\n", + (stat_rlc_mode==RLC_MODE_AM)? "AM": (stat_rlc_mode==RLC_MODE_UM)?"UM":"NONE", + stat_rx_data_pdu, + stat_rx_data_bytes, + stat_rx_control_pdu, + stat_rx_control_bytes, + stat_rx_data_pdus_duplicate, + stat_rx_data_bytes_duplicate, + stat_rx_data_pdu_dropped, + stat_rx_data_bytes_dropped, + stat_rx_data_pdu_out_of_window, + stat_rx_data_bytes_out_of_window); + len+=sprintf(&buffer[len],"[RLC] DTCH Mode %s, RX_REODERING_TIMEOUT = %u\tRX_POLL_RET_TIMEOUT %u\tRX_PROHIBIT_TIME_OUT %u\n", + (stat_rlc_mode==RLC_MODE_AM)? "AM": (stat_rlc_mode==RLC_MODE_UM)?"UM":"NONE", + stat_timer_reordering_timed_out, + stat_timer_poll_retransmit_timed_out, + stat_timer_status_prohibit_timed_out); + len+=sprintf(&buffer[len],"[RLC] DTCH Mode %s, NB_SDU_TO_RX = %u (bytes %u)\n", + (stat_rlc_mode==RLC_MODE_AM)? "AM": (stat_rlc_mode==RLC_MODE_UM)?"UM":"NONE", + stat_rx_pdcp_sdu, + stat_rx_pdcp_bytes); + } + } } - } - - return len + 1 /* SR: for trailing \0 */; -} + return len + 1 /* SR: for trailing \0 */; +} #ifdef PROC -int openair2_stats_read(char *buffer, char **my_buffer, off_t off, int length) -{ - - int len = 0,fg,Overhead, Sign; - unsigned int i,j,k,kk; - unsigned int Mod_id = 0,CH_index; - unsigned int tx_pdcp_sdu; - unsigned int tx_pdcp_sdu_discarded; - unsigned int tx_retransmit_pdu_unblock; - unsigned int tx_retransmit_pdu_by_status; - unsigned int tx_retransmit_pdu; - unsigned int tx_data_pdu; - unsigned int tx_control_pdu; - unsigned int rx_sdu; - unsigned int rx_error_pdu; - unsigned int rx_data_pdu; - unsigned int rx_data_pdu_out_of_window; - unsigned int rx_control_pdu; - - // if (mac_xface->is_cluster_head == 0) { - for (k=0; k<NB_INST; k++) { - - - - if (Mac_rlc_xface->Is_cluster_head[k] == 0) { +int openair2_stats_read(char *buffer, char **my_buffer, off_t off, int length) { + int len = 0,fg,Overhead, Sign; + unsigned int i,j,k,kk; + unsigned int Mod_id = 0,CH_index; + unsigned int tx_pdcp_sdu; + unsigned int tx_pdcp_sdu_discarded; + unsigned int tx_retransmit_pdu_unblock; + unsigned int tx_retransmit_pdu_by_status; + unsigned int tx_retransmit_pdu; + unsigned int tx_data_pdu; + unsigned int tx_control_pdu; + unsigned int rx_sdu; + unsigned int rx_error_pdu; + unsigned int rx_data_pdu; + unsigned int rx_data_pdu_out_of_window; + unsigned int rx_control_pdu; + + // if (mac_xface->is_cluster_head == 0) { + for (k=0; k<NB_INST; k++) { + if (Mac_rlc_xface->Is_cluster_head[k] == 0) { #ifndef PHY_EMUL_ONE_MACHINE - Mod_id=k-NB_CH_INST; - - len+=sprintf(&buffer[len],"UE TTI: %d\n",Mac_rlc_xface->frame); - - for (CH_index = 0; CH_index<NB_CNX_UE; CH_index++) { - - - if (UE_mac_inst[Mod_id].Dcch_lchan[CH_index].Active==1) { - len+=sprintf(&buffer[len],"CH %d: Wideband SINR %d dB---\n", - CH_index,UE_mac_inst[Mod_id].Def_meas[CH_index].Wideband_sinr); - len+=sprintf(&buffer[len],"CH %d: Subband SINR (dB) :", - CH_index); - - for (fg=0; fg<NUMBER_OF_MEASUREMENT_SUBBANDS; fg++) { - len+=sprintf(&buffer[len],"%d ",UE_mac_inst[Mod_id].Def_meas[CH_index].Sinr_meas[0][fg]); - } - - len+=sprintf(&buffer[len],"\n"); - - - len+=sprintf(&buffer[len],"BCCH %d, NB_RX_MAC = %d (%d errors)\n", - UE_mac_inst[Mod_id].Bcch_lchan[CH_index].Lchan_info.Lchan_id.Index, - UE_mac_inst[Mod_id].Bcch_lchan[CH_index].Lchan_info.NB_RX, - UE_mac_inst[Mod_id].Bcch_lchan[CH_index].Lchan_info.NB_RX_ERRORS); - - - - len+=sprintf(&buffer[len],"CCCH %d, NB_RX_MAC = %d (%d errors)\n", - UE_mac_inst[Mod_id].Ccch_lchan[CH_index].Lchan_info.Lchan_id.Index, - UE_mac_inst[Mod_id].Ccch_lchan[CH_index].Lchan_info.NB_RX, - UE_mac_inst[Mod_id].Ccch_lchan[CH_index].Lchan_info.NB_RX_ERRORS); - - - len+=sprintf(&buffer[len],"LCHAN %d (DCCH), NB_TX_MAC = %d (%d bits/TTI, %d kbits/sec), NB_RX_MAC = %d (%d errors)\n", - UE_mac_inst[Mod_id].Dcch_lchan[CH_index].Lchan_info.Lchan_id.Index, - UE_mac_inst[Mod_id].Dcch_lchan[CH_index].Lchan_info.NB_TX, - UE_mac_inst[Mod_id].Dcch_lchan[CH_index].Lchan_info.output_rate, - (10*UE_mac_inst[Mod_id].Dcch_lchan[CH_index].Lchan_info.output_rate)>>5, - UE_mac_inst[Mod_id].Dcch_lchan[CH_index].Lchan_info.NB_RX, - UE_mac_inst[Mod_id].Dcch_lchan[CH_index].Lchan_info.NB_RX_ERRORS); - - for(i=1; i<NB_RAB_MAX; i++) { - if (UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Active==1) { - Overhead=UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.output_rate - Pdcp_stats_tx_rate[k][CH_index][i]; - - if(Overhead<0) { - Overhead=-Overhead; - Sign=-1; - } else { - Sign=1; - } - - len+=sprintf(&buffer[len], - "[PDCP]LCHAN %d: NB_TX = %d ,Tx_rate =(%d bits/TTI ,%d Kbits/s), NB_RX = %d ,Rx_rate =(%d bits/TTI ,%d Kbits/s) , LAYER2 TX OVERHEAD: %d Kbits/s\n", - UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.Lchan_id.Index, - Pdcp_stats_tx[k][CH_index][i], - Pdcp_stats_tx_rate[k][CH_index][i], - (10*Pdcp_stats_tx_rate[k][CH_index][i])>>5, - Pdcp_stats_rx[k][CH_index][i], - Pdcp_stats_rx_rate[k][CH_index][i], - (10*Pdcp_stats_rx_rate[k][CH_index][i])>>5, - Sign*(10*Overhead)>>5); - - - int status = rlc_stat_req (k, - UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.Lchan_id.Index, - &tx_pdcp_sdu, - &tx_pdcp_sdu_discarded, - &tx_retransmit_pdu_unblock, - &tx_retransmit_pdu_by_status, - &tx_retransmit_pdu, - &tx_data_pdu, - &tx_control_pdu, - &rx_sdu, - &rx_error_pdu, - &rx_data_pdu, - &rx_data_pdu_out_of_window, - &rx_control_pdu) ; - - if (status == RLC_OP_STATUS_OK) { - len+=sprintf(&buffer[len],"RLC LCHAN %d, NB_SDU_TO_TX = %d\tNB_SDU_DISC %d\tNB_RX_SDU %d\n", - UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.Lchan_id.Index, + Mod_id=k-NB_CH_INST; + len+=sprintf(&buffer[len],"UE TTI: %d\n",Mac_rlc_xface->frame); + + for (CH_index = 0; CH_index<NB_CNX_UE; CH_index++) { + if (UE_mac_inst[Mod_id].Dcch_lchan[CH_index].Active==1) { + len+=sprintf(&buffer[len],"CH %u: Wideband SINR %d dB---\n", + CH_index,UE_mac_inst[Mod_id].Def_meas[CH_index].Wideband_sinr); + len+=sprintf(&buffer[len],"CH %u: Subband SINR (dB) :", + CH_index); + + for (fg=0; fg<NUMBER_OF_MEASUREMENT_SUBBANDS; fg++) { + len+=sprintf(&buffer[len],"%d ",UE_mac_inst[Mod_id].Def_meas[CH_index].Sinr_meas[0][fg]); + } + + len+=sprintf(&buffer[len],"\n"); + len+=sprintf(&buffer[len],"BCCH %d, NB_RX_MAC = %d (%d errors)\n", + UE_mac_inst[Mod_id].Bcch_lchan[CH_index].Lchan_info.Lchan_id.Index, + UE_mac_inst[Mod_id].Bcch_lchan[CH_index].Lchan_info.NB_RX, + UE_mac_inst[Mod_id].Bcch_lchan[CH_index].Lchan_info.NB_RX_ERRORS); + len+=sprintf(&buffer[len],"CCCH %d, NB_RX_MAC = %d (%d errors)\n", + UE_mac_inst[Mod_id].Ccch_lchan[CH_index].Lchan_info.Lchan_id.Index, + UE_mac_inst[Mod_id].Ccch_lchan[CH_index].Lchan_info.NB_RX, + UE_mac_inst[Mod_id].Ccch_lchan[CH_index].Lchan_info.NB_RX_ERRORS); + len+=sprintf(&buffer[len],"LCHAN %d (DCCH), NB_TX_MAC = %d (%d bits/TTI, %d kbits/sec), NB_RX_MAC = %d (%d errors)\n", + UE_mac_inst[Mod_id].Dcch_lchan[CH_index].Lchan_info.Lchan_id.Index, + UE_mac_inst[Mod_id].Dcch_lchan[CH_index].Lchan_info.NB_TX, + UE_mac_inst[Mod_id].Dcch_lchan[CH_index].Lchan_info.output_rate, + (10*UE_mac_inst[Mod_id].Dcch_lchan[CH_index].Lchan_info.output_rate)>>5, + UE_mac_inst[Mod_id].Dcch_lchan[CH_index].Lchan_info.NB_RX, + UE_mac_inst[Mod_id].Dcch_lchan[CH_index].Lchan_info.NB_RX_ERRORS); + + for(i=1; i<NB_RAB_MAX; i++) { + if (UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Active==1) { + Overhead=UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.output_rate - Pdcp_stats_tx_rate[k][CH_index][i]; + + if(Overhead<0) { + Overhead=-Overhead; + Sign=-1; + } else { + Sign=1; + } + + len+=sprintf(&buffer[len], + "[PDCP]LCHAN %d: NB_TX = %d ,Tx_rate =(%d bits/TTI ,%d Kbits/s), NB_RX = %d ,Rx_rate =(%d bits/TTI ,%d Kbits/s) , LAYER2 TX OVERHEAD: %d Kbits/s\n", + UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.Lchan_id.Index, + Pdcp_stats_tx[k][CH_index][i], + Pdcp_stats_tx_rate[k][CH_index][i], + (10*Pdcp_stats_tx_rate[k][CH_index][i])>>5, + Pdcp_stats_rx[k][CH_index][i], + Pdcp_stats_rx_rate[k][CH_index][i], + (10*Pdcp_stats_rx_rate[k][CH_index][i])>>5, + Sign*(10*Overhead)>>5); + int status = rlc_stat_req (k, + UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.Lchan_id.Index, + &tx_pdcp_sdu, + &tx_pdcp_sdu_discarded, + &tx_retransmit_pdu_unblock, + &tx_retransmit_pdu_by_status, + &tx_retransmit_pdu, + &tx_data_pdu, + &tx_control_pdu, + &rx_sdu, + &rx_error_pdu, + &rx_data_pdu, + &rx_data_pdu_out_of_window, + &rx_control_pdu) ; + + if (status == RLC_OP_STATUS_OK) { + len+=sprintf(&buffer[len],"RLC LCHAN %d, NB_SDU_TO_TX = %u\tNB_SDU_DISC %u\tNB_RX_SDU %u\n", + UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.Lchan_id.Index, + tx_pdcp_sdu, + tx_pdcp_sdu_discarded, + rx_sdu); + len+=sprintf(&buffer[len],"RLC LCHAN %d, NB_TB_TX_DATA = %u\tNB_TB_TX_CONTROL %u\tNB_TX_TB_RETRANS %u", + UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.Lchan_id.Index, + tx_data_pdu, + tx_control_pdu, + tx_retransmit_pdu); + len+=sprintf(&buffer[len],"\tRLC LCHAN %d, NB_TX_TB_RETRANS_BY_STATUS = %u\tNB_TX_TB_RETRANS_PADD %u\n", + UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.Lchan_id.Index, + tx_retransmit_pdu_by_status, + tx_retransmit_pdu_unblock); + len+=sprintf(&buffer[len],"RLC LCHAN %d, NB_RX_DATA = %u\tNB_RX_TB_OUT_WIN %u\tNB_RX_TB_CORRUPT %u\n", + UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.Lchan_id.Index, + rx_data_pdu, + rx_data_pdu_out_of_window, + rx_error_pdu); + } + + len+=sprintf(&buffer[len],"[MAC]: LCHAN %d, NB_TX_MAC = %d (%d bits/TTI, %d kbits/s), NB_RX_MAC = %d (%d errors)\n", + UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.Lchan_id.Index, + UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.NB_TX, + UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.output_rate, + (10*UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.output_rate)>>5, + UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.NB_RX, + UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.NB_RX_ERRORS); + len+=sprintf(&buffer[len]," TX per TB: "); + + for(kk=0; kk<MAX_NUMBER_TB_PER_LCHAN/2; kk++) { + len+=sprintf(&buffer[len],"%d . ",UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.NB_TX_TB[kk]); + } + + len+=sprintf(&buffer[len],"\n"); + len+=sprintf(&buffer[len]," RXerr per TB: "); + + for(kk=0; kk<MAX_NUMBER_TB_PER_LCHAN/2; kk++) + len+=sprintf(&buffer[len],"%d/%d . ",UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.NB_RX_ERRORS_TB[kk], + UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.NB_RX_TB[kk]); + + len+=sprintf(&buffer[len],"\n"); + } + } + } + } + +#endif //PHY_EMUL_ONE_MACHINE + } else if(Mac_rlc_xface->Is_cluster_head[k] ==1) { + Mod_id=k; + len+=sprintf(&buffer[len], + "-------------------------------------------------------------------CH %d: TTI: %d------------------------------------------------------------------\n", + NODE_ID[Mod_id],Mac_rlc_xface->frame); + + for(i=1; i<=NB_CNX_CH; i++) { + if (CH_mac_inst[Mod_id].Dcch_lchan[i].Active==1) { + len+=sprintf(&buffer[len],"\nMR index %u: DL SINR (feedback) %d dB, CQI: %s\n\n", + i,//CH_rrc_inst[Mod_id].Info.UE_list[i].L2_id[0], + CH_mac_inst[Mod_id].Def_meas[i].Wideband_sinr, + print_cqi(CH_mac_inst[Mod_id].Def_meas[i].cqi)); + len+=sprintf(&buffer[len], + "[MAC] LCHAN %d (DCCH), NB_TX_MAC= %d (%d bits/TTI, %d kbits/s), NB_RX_MAC= %d (errors %d, sacch errors %d, sach errors %d, sach_missing %d)\n\n", + CH_mac_inst[Mod_id].Dcch_lchan[i].Lchan_info.Lchan_id.Index, + CH_mac_inst[Mod_id].Dcch_lchan[i].Lchan_info.NB_TX, + CH_mac_inst[Mod_id].Dcch_lchan[i].Lchan_info.output_rate, + (10*CH_mac_inst[Mod_id].Dcch_lchan[i].Lchan_info.output_rate)>>5, + CH_mac_inst[Mod_id].Dcch_lchan[i].Lchan_info.NB_RX, + CH_mac_inst[Mod_id].Dcch_lchan[i].Lchan_info.NB_RX_ERRORS, + CH_mac_inst[Mod_id].Dcch_lchan[i].Lchan_info.NB_RX_SACCH_ERRORS, + CH_mac_inst[Mod_id].Dcch_lchan[i].Lchan_info.NB_RX_SACH_ERRORS, + CH_mac_inst[Mod_id].Dcch_lchan[i].Lchan_info.NB_RX_SACH_MISSING); + + for(j=0; j<NB_RAB_MAX; j++) { + if (CH_mac_inst[Mod_id].Dtch_lchan[j][i].Active==1) { + Overhead=CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.output_rate - Pdcp_stats_tx_rate[k][i][j]; + + if(Overhead<0) { + Overhead=-Overhead; + Sign=-1; + } else { + Sign=1; + } + + len+=sprintf(&buffer[len], + "[PDCP]LCHAN %d: NB_TX = %d ,Tx_rate =(%d bits/TTI ,%d Kbits/s), NB_RX = %d ,Rx_rate =(%d bits/TTI ,%d Kbits/s), LAYER2 TX OVERHEAD= %d Kbits/s\n", + CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.Lchan_id.Index, + Pdcp_stats_tx[k][i][j], + Pdcp_stats_tx_rate[k][i][j], + (10*Pdcp_stats_tx_rate[k][i][j])>>5, + Pdcp_stats_rx[k][i][j], + Pdcp_stats_rx_rate[k][i][j], + (10*Pdcp_stats_rx_rate[k][i][j])>>5, + Sign*(10*Overhead)>>5); + int status = rlc_stat_req (k, + CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.Lchan_id.Index, + &tx_pdcp_sdu, + &tx_pdcp_sdu_discarded, + &tx_retransmit_pdu_unblock, + &tx_retransmit_pdu_by_status, + &tx_retransmit_pdu, + &tx_data_pdu, + &tx_control_pdu, + &rx_sdu, + &rx_error_pdu, + &rx_data_pdu, + &rx_data_pdu_out_of_window, + &rx_control_pdu) ; + /* + if (status == RLC_OP_STATUS_OK) { + len+=sprintf(&buffer[len],"\t[RLC] LCHAN %d, NB_SDU_TO_TX = %d\tNB_SDU_DISC %d\tNB_RX_SDU %d\n", + CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.Lchan_id.Index, tx_pdcp_sdu, tx_pdcp_sdu_discarded, rx_sdu); - len+=sprintf(&buffer[len],"RLC LCHAN %d, NB_TB_TX_DATA = %d\tNB_TB_TX_CONTROL %d\tNB_TX_TB_RETRANS %d", - UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.Lchan_id.Index, + len+=sprintf(&buffer[len],"\t[RLC] LCHAN %d, NB_TB_TX_DATA = %d\tNB_TB_TX_CONTROL %d\tNB_TX_TB_RETRANS %\n", + CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.Lchan_id.Index, tx_data_pdu, tx_control_pdu, tx_retransmit_pdu); - len+=sprintf(&buffer[len],"\tRLC LCHAN %d, NB_TX_TB_RETRANS_BY_STATUS = %d\tNB_TX_TB_RETRANS_PADD %d\n", - UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.Lchan_id.Index, + len+=sprintf(&buffer[len],"\t[RLC] LCHAN %d, NB_TX_TB_RETRANS_BY_STATUS = %d\tNB_TX_TB_RETRANS_PADD %d\n", + CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.Lchan_id.Index, tx_retransmit_pdu_by_status, tx_retransmit_pdu_unblock); - len+=sprintf(&buffer[len],"RLC LCHAN %d, NB_RX_DATA = %d\tNB_RX_TB_OUT_WIN %d\tNB_RX_TB_CORRUPT %d\n", - UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.Lchan_id.Index, + len+=sprintf(&buffer[len],"\t[RLC] LCHAN %d, NB_RX_DATA = %d\tNB_RX_TB_OUT_WIN %d\tNB_RX_TB_CORRUPT %d\n", + CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.Lchan_id.Index, rx_data_pdu, rx_data_pdu_out_of_window, rx_error_pdu); - } - - len+=sprintf(&buffer[len],"[MAC]: LCHAN %d, NB_TX_MAC = %d (%d bits/TTI, %d kbits/s), NB_RX_MAC = %d (%d errors)\n", - UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.Lchan_id.Index, - UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.NB_TX, - UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.output_rate, - (10*UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.output_rate)>>5, - UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.NB_RX, - UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.NB_RX_ERRORS); - len+=sprintf(&buffer[len]," TX per TB: "); - - for(kk=0; kk<MAX_NUMBER_TB_PER_LCHAN/2; kk++) { - len+=sprintf(&buffer[len],"%d . ",UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.NB_TX_TB[kk]); - } - - len+=sprintf(&buffer[len],"\n"); - len+=sprintf(&buffer[len]," RXerr per TB: "); - - for(kk=0; kk<MAX_NUMBER_TB_PER_LCHAN/2; kk++) - len+=sprintf(&buffer[len],"%d/%d . ",UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.NB_RX_ERRORS_TB[kk], - UE_mac_inst[Mod_id].Dtch_lchan[i][CH_index].Lchan_info.NB_RX_TB[kk]); - - len+=sprintf(&buffer[len],"\n"); - - - + } + */ + len+=sprintf(&buffer[len], + "[MAC]LCHAN %d (CNX %u,RAB %u), NB_TX_MAC= %d (%d bits/TTI, %d kbit/s), NB_RX_MAC= %d (errors %d, sacch_errors %d, sach_errors %d, sach_missing %d)\n", + CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.Lchan_id.Index, + i,j, + CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.NB_TX, + CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.output_rate, + (10*CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.output_rate)>>5, + CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.NB_RX, + CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.NB_RX_ERRORS, + CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.NB_RX_SACCH_ERRORS, + CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.NB_RX_SACH_ERRORS, + CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.NB_RX_SACH_MISSING); + len+=sprintf(&buffer[len],"[MAC][SCHEDULER] TX Arrival Rate %d, TX Service Rate %d, RX Arrival rate %d, RX Service rate %d, NB_BW_REQ_RX %d\n\n", + CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.Arrival_rate, + CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.Tx_rate, + CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.Req_rate, + CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.Rx_rate, + CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.NB_BW_REQ_RX); + /* + len+=sprintf(&buffer[len]," TX per TB: "); + for(kk=0;kk<MAX_NUMBER_TB_PER_LCHAN/2;kk++) + len+=sprintf(&buffer[len],"%d.",CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.NB_TX_TB[kk]); + len+=sprintf(&buffer[len],"\n"); + len+=sprintf(&buffer[len]," RXerr per TB: "); + for(kk=0;kk<MAX_NUMBER_TB_PER_LCHAN/2;kk++) + len+=sprintf(&buffer[len],"%d/%d . ",CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.NB_RX_ERRORS_TB[kk], + CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.NB_RX_TB[kk]); + len+=sprintf(&buffer[len],"\n"); + */ + } + } + } } - - } } - } - -#endif //PHY_EMUL_ONE_MACHINE - } else if(Mac_rlc_xface->Is_cluster_head[k] ==1) { - - Mod_id=k; - len+=sprintf(&buffer[len], - "-------------------------------------------------------------------CH %d: TTI: %d------------------------------------------------------------------\n", - NODE_ID[Mod_id],Mac_rlc_xface->frame); - - for(i=1; i<=NB_CNX_CH; i++) { - if (CH_mac_inst[Mod_id].Dcch_lchan[i].Active==1) { - len+=sprintf(&buffer[len],"\nMR index %d: DL SINR (feedback) %d dB, CQI: %s\n\n", - i,//CH_rrc_inst[Mod_id].Info.UE_list[i].L2_id[0], - CH_mac_inst[Mod_id].Def_meas[i].Wideband_sinr, - print_cqi(CH_mac_inst[Mod_id].Def_meas[i].cqi)); - - len+=sprintf(&buffer[len], - "[MAC] LCHAN %d (DCCH), NB_TX_MAC= %d (%d bits/TTI, %d kbits/s), NB_RX_MAC= %d (errors %d, sacch errors %d, sach errors %d, sach_missing %d)\n\n", - CH_mac_inst[Mod_id].Dcch_lchan[i].Lchan_info.Lchan_id.Index, - CH_mac_inst[Mod_id].Dcch_lchan[i].Lchan_info.NB_TX, - CH_mac_inst[Mod_id].Dcch_lchan[i].Lchan_info.output_rate, - (10*CH_mac_inst[Mod_id].Dcch_lchan[i].Lchan_info.output_rate)>>5, - CH_mac_inst[Mod_id].Dcch_lchan[i].Lchan_info.NB_RX, - CH_mac_inst[Mod_id].Dcch_lchan[i].Lchan_info.NB_RX_ERRORS, - CH_mac_inst[Mod_id].Dcch_lchan[i].Lchan_info.NB_RX_SACCH_ERRORS, - CH_mac_inst[Mod_id].Dcch_lchan[i].Lchan_info.NB_RX_SACH_ERRORS, - CH_mac_inst[Mod_id].Dcch_lchan[i].Lchan_info.NB_RX_SACH_MISSING); - - for(j=0; j<NB_RAB_MAX; j++) { - if (CH_mac_inst[Mod_id].Dtch_lchan[j][i].Active==1) { - Overhead=CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.output_rate - Pdcp_stats_tx_rate[k][i][j]; - - if(Overhead<0) { - Overhead=-Overhead; - Sign=-1; - } else { - Sign=1; - } - - len+=sprintf(&buffer[len], - "[PDCP]LCHAN %d: NB_TX = %d ,Tx_rate =(%d bits/TTI ,%d Kbits/s), NB_RX = %d ,Rx_rate =(%d bits/TTI ,%d Kbits/s), LAYER2 TX OVERHEAD= %d Kbits/s\n", - CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.Lchan_id.Index, - Pdcp_stats_tx[k][i][j], - Pdcp_stats_tx_rate[k][i][j], - (10*Pdcp_stats_tx_rate[k][i][j])>>5, - Pdcp_stats_rx[k][i][j], - Pdcp_stats_rx_rate[k][i][j], - (10*Pdcp_stats_rx_rate[k][i][j])>>5, - Sign*(10*Overhead)>>5); - int status = rlc_stat_req (k, - CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.Lchan_id.Index, - &tx_pdcp_sdu, - &tx_pdcp_sdu_discarded, - &tx_retransmit_pdu_unblock, - &tx_retransmit_pdu_by_status, - &tx_retransmit_pdu, - &tx_data_pdu, - &tx_control_pdu, - &rx_sdu, - &rx_error_pdu, - &rx_data_pdu, - &rx_data_pdu_out_of_window, - &rx_control_pdu) ; - /* - if (status == RLC_OP_STATUS_OK) { - len+=sprintf(&buffer[len],"\t[RLC] LCHAN %d, NB_SDU_TO_TX = %d\tNB_SDU_DISC %d\tNB_RX_SDU %d\n", - CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.Lchan_id.Index, - tx_pdcp_sdu, - tx_pdcp_sdu_discarded, - rx_sdu); - len+=sprintf(&buffer[len],"\t[RLC] LCHAN %d, NB_TB_TX_DATA = %d\tNB_TB_TX_CONTROL %d\tNB_TX_TB_RETRANS %\n", - CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.Lchan_id.Index, - tx_data_pdu, - tx_control_pdu, - tx_retransmit_pdu); - len+=sprintf(&buffer[len],"\t[RLC] LCHAN %d, NB_TX_TB_RETRANS_BY_STATUS = %d\tNB_TX_TB_RETRANS_PADD %d\n", - CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.Lchan_id.Index, - tx_retransmit_pdu_by_status, - tx_retransmit_pdu_unblock); - len+=sprintf(&buffer[len],"\t[RLC] LCHAN %d, NB_RX_DATA = %d\tNB_RX_TB_OUT_WIN %d\tNB_RX_TB_CORRUPT %d\n", - CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.Lchan_id.Index, - rx_data_pdu, - rx_data_pdu_out_of_window, - rx_error_pdu); - } - */ - len+=sprintf(&buffer[len], - "[MAC]LCHAN %d (CNX %d,RAB %d), NB_TX_MAC= %d (%d bits/TTI, %d kbit/s), NB_RX_MAC= %d (errors %d, sacch_errors %d, sach_errors %d, sach_missing %d)\n", - CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.Lchan_id.Index, - i,j, - CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.NB_TX, - CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.output_rate, - (10*CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.output_rate)>>5, - CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.NB_RX, - CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.NB_RX_ERRORS, - CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.NB_RX_SACCH_ERRORS, - CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.NB_RX_SACH_ERRORS, - CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.NB_RX_SACH_MISSING); - len+=sprintf(&buffer[len],"[MAC][SCHEDULER] TX Arrival Rate %d, TX Service Rate %d, RX Arrival rate %d, RX Service rate %d, NB_BW_REQ_RX %d\n\n", - CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.Arrival_rate, - CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.Tx_rate, - CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.Req_rate, - CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.Rx_rate, - CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.NB_BW_REQ_RX); - - /* - len+=sprintf(&buffer[len]," TX per TB: "); - for(kk=0;kk<MAX_NUMBER_TB_PER_LCHAN/2;kk++) - len+=sprintf(&buffer[len],"%d.",CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.NB_TX_TB[kk]); - len+=sprintf(&buffer[len],"\n"); - len+=sprintf(&buffer[len]," RXerr per TB: "); - for(kk=0;kk<MAX_NUMBER_TB_PER_LCHAN/2;kk++) - len+=sprintf(&buffer[len],"%d/%d . ",CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.NB_RX_ERRORS_TB[kk], - CH_mac_inst[Mod_id].Dtch_lchan[j][i].Lchan_info.NB_RX_TB[kk]); - len+=sprintf(&buffer[len],"\n"); - */ - } - } - } - } - } - } - return len; + return len; } #endif diff --git a/openair2/NETWORK_DRIVER/LITE/RB_TOOL/rb_tool.c b/openair2/NETWORK_DRIVER/LITE/RB_TOOL/rb_tool.c index e918f209e37f3dab584a81a3bdcbd6f67f077550..465e134d768ee0ca4dc5f6cb09a4cb5f3e22ea51 100644 --- a/openair2/NETWORK_DRIVER/LITE/RB_TOOL/rb_tool.c +++ b/openair2/NETWORK_DRIVER/LITE/RB_TOOL/rb_tool.c @@ -46,22 +46,22 @@ #define NIPADDR(addr) \ - (uint8_t)(addr & 0x000000FF), \ - (uint8_t)((addr & 0x0000FF00) >> 8), \ - (uint8_t)((addr & 0x00FF0000) >> 16), \ - (uint8_t)((addr & 0xFF000000) >> 24) + (uint8_t)(addr & 0x000000FF), \ + (uint8_t)((addr & 0x0000FF00) >> 8), \ + (uint8_t)((addr & 0x00FF0000) >> 16), \ + (uint8_t)((addr & 0xFF000000) >> 24) #define NIP6ADDR(addr) \ - ntohs((addr)->s6_addr16[0]), \ - ntohs((addr)->s6_addr16[1]), \ - ntohs((addr)->s6_addr16[2]), \ - ntohs((addr)->s6_addr16[3]), \ - ntohs((addr)->s6_addr16[4]), \ - ntohs((addr)->s6_addr16[5]), \ - ntohs((addr)->s6_addr16[6]), \ - ntohs((addr)->s6_addr16[7]) + ntohs((addr)->s6_addr16[0]), \ + ntohs((addr)->s6_addr16[1]), \ + ntohs((addr)->s6_addr16[2]), \ + ntohs((addr)->s6_addr16[3]), \ + ntohs((addr)->s6_addr16[4]), \ + ntohs((addr)->s6_addr16[5]), \ + ntohs((addr)->s6_addr16[6]), \ + ntohs((addr)->s6_addr16[7]) // Global variables @@ -76,12 +76,9 @@ struct oai_nw_drv_ioctl gifr; void IAL_NAS_ioctl_init(int inst) //--------------------------------------------------------------------------- { - struct oai_nw_drv_msg_statistic_reply *msgrep; int err,rc; - sprintf(gifr.name, "oai%d",inst); - // Get an UDP IPv6 socket ?? fd=socket(AF_INET6, SOCK_DGRAM, 0); @@ -91,7 +88,6 @@ void IAL_NAS_ioctl_init(int inst) } sprintf(gifr.name, "oai%d",inst); - gifr.type = OAI_NW_DRV_MSG_STATISTIC_REQUEST; memset ((void *)dummy_buffer,0,800); gifr.msg= &(dummy_buffer[0]); @@ -160,7 +156,6 @@ int main(int argc,char **argv) char addr_str[46]; char mask_len_delims[] = "/"; char *result; - // scan options rb[0] = '\0'; cx[0] = '\0'; @@ -171,155 +166,154 @@ int main(int argc,char **argv) while ((c = getopt (argc, argv, "adr:i:c:f:l:m:s:t:x:y:z:")) != -1) switch (c) { - case 'a': - action = ADD_RB; - break; - - case 'd': - action = DEL_RB; - break; - - case 'r': - strcpy(rb,optarg); - rbset = 1; - break; - - case 'i': - strcpy(inst,optarg); - instset = 1; - break; - - case 'c': - strcpy(cx,optarg); - cxset = 1; - break; - - case 'f': - strcpy(classref,optarg); - classrefset = 1; - break; - - case 'l': - strcpy(mpls_outgoinglabel,optarg); - mpls_outlabelset=1; - break; - - case 'm': - strcpy(mpls_incominglabel,optarg); - mpls_inlabelset=1; - break; - - case 's': - result = strtok( optarg, mask_len_delims ); - - if ( result != NULL ) { - inet_aton(result,&saddr_ipv4); - printf("Arg Source Addr IPv4 string: %s\n",result); - saddr_ipv4set = 1; - } else { - printf("Arg Source Addr IPv4 string: ERROR\n"); + case 'a': + action = ADD_RB; break; - } - result = strtok( NULL, mask_len_delims ); + case 'd': + action = DEL_RB; + break; - if ( result != NULL ) { - splen = atoi(result); - } else { - splen = 32; - } + case 'r': + strcpy(rb,optarg); + rbset = 1; + break; - printf("Arg Source Addr IPv4 mask len: %d\n",splen); - break; + case 'i': + strcpy(inst,optarg); + instset = 1; + break; - case 't': - result = strtok( optarg, mask_len_delims ); + case 'c': + strcpy(cx,optarg); + cxset = 1; + break; - if ( result != NULL ) { - inet_aton(result,&daddr_ipv4); - printf("Arg Dest Addr IPv4 string: %s\n",result); - daddr_ipv4set = 1; - } else { - printf("Arg Dest Addr IPv4 string: ERROR\n"); + case 'f': + strcpy(classref,optarg); + classrefset = 1; + break; + + case 'l': + strcpy(mpls_outgoinglabel,optarg); + mpls_outlabelset=1; break; - } - result = strtok( NULL, mask_len_delims ); + case 'm': + strcpy(mpls_incominglabel,optarg); + mpls_inlabelset=1; + break; - if ( result != NULL ) { - dplen = atoi(result); - } else { - dplen = 32; - } + case 's': + result = strtok( optarg, mask_len_delims ); - printf("Arg Dest Addr IPv4 mask len: %d\n",dplen); - break; + if ( result != NULL ) { + inet_aton(result,&saddr_ipv4); + printf("Arg Source Addr IPv4 string: %s\n",result); + saddr_ipv4set = 1; + } else { + printf("Arg Source Addr IPv4 string: ERROR\n"); + break; + } - case 'x': - result = strtok( optarg, mask_len_delims ); + result = strtok( NULL, mask_len_delims ); - if ( result != NULL ) { - printf("Arg Source Addr IPv6 string: %s\n",result); - inet_pton(AF_INET6,result,(void *)&saddr_ipv6); - saddr_ipv6set = 1; - } else { - printf("Arg Source Addr IPv6 string: ERROR\n"); + if ( result != NULL ) { + splen = atoi(result); + } else { + splen = 32; + } + + printf("Arg Source Addr IPv4 mask len: %d\n",splen); break; - } - result = strtok( NULL, mask_len_delims ); + case 't': + result = strtok( optarg, mask_len_delims ); - if ( result != NULL ) { - splen = atoi(result); - } else { - splen = 128; - } + if ( result != NULL ) { + inet_aton(result,&daddr_ipv4); + printf("Arg Dest Addr IPv4 string: %s\n",result); + daddr_ipv4set = 1; + } else { + printf("Arg Dest Addr IPv4 string: ERROR\n"); + break; + } - printf("Arg Source Addr IPv6 mask len: %d\n",splen); - break; + result = strtok( NULL, mask_len_delims ); - case 'y': - result = strtok( optarg, mask_len_delims ); + if ( result != NULL ) { + dplen = atoi(result); + } else { + dplen = 32; + } - if ( result != NULL ) { - printf("Arg Dest Addr IPv6 string: %s\n",result); - inet_pton(AF_INET6,result,(void *)&daddr_ipv6); - daddr_ipv6set = 1; - } else { - printf("Arg Dest Addr IPv6 string: ERROR\n"); + printf("Arg Dest Addr IPv4 mask len: %d\n",dplen); break; - } - result = strtok( NULL, mask_len_delims ); + case 'x': + result = strtok( optarg, mask_len_delims ); - if ( result != NULL ) { - dplen = atoi(result); - } else { - dplen = 128; - } + if ( result != NULL ) { + printf("Arg Source Addr IPv6 string: %s\n",result); + inet_pton(AF_INET6,result,(void *)&saddr_ipv6); + saddr_ipv6set = 1; + } else { + printf("Arg Source Addr IPv6 string: ERROR\n"); + break; + } - printf("Arg Dest Addr IPv6 mask len: %d\n",dplen); - break; + result = strtok( NULL, mask_len_delims ); - case 'z': - dscpset=1; - strcpy(dscp,optarg); - break; + if ( result != NULL ) { + splen = atoi(result); + } else { + splen = 128; + } - case '?': - if (isprint (optopt)) - fprintf (stderr, "Unknown option `-%c'.\n", optopt); - else - fprintf (stderr, - "Unknown option character `\\x%x'.\n", - optopt); + printf("Arg Source Addr IPv6 mask len: %d\n",splen); + break; - return 1; + case 'y': + result = strtok( optarg, mask_len_delims ); - default: - abort (); - } + if ( result != NULL ) { + printf("Arg Dest Addr IPv6 string: %s\n",result); + inet_pton(AF_INET6,result,(void *)&daddr_ipv6); + daddr_ipv6set = 1; + } else { + printf("Arg Dest Addr IPv6 string: ERROR\n"); + break; + } + result = strtok( NULL, mask_len_delims ); + + if ( result != NULL ) { + dplen = atoi(result); + } else { + dplen = 128; + } + + printf("Arg Dest Addr IPv6 mask len: %d\n",dplen); + break; + + case 'z': + dscpset=1; + strcpy(dscp,optarg); + break; + + case '?': + if (isprint (optopt)) + fprintf (stderr, "Unknown option `-%c'.\n", optopt); + else + fprintf (stderr, + "Unknown option character `\\x%x'.\n", + optopt); + + return 1; + + default: + abort (); + } printf ("action = %d, rb = %s,cx = %s\n", action, rb, cx); @@ -364,13 +358,11 @@ int main(int argc,char **argv) } IAL_NAS_ioctl_init(atoi(inst)); - msgreq = (struct oai_nw_drv_msg_rb_establishment_request *)(gifr.msg); msgreq->rab_id = atoi(rb); msgreq->lcr = atoi(cx); msgreq->qos = 0; - if (action == ADD_RB) { gifr.type = OAI_NW_DRV_MSG_RB_ESTABLISHMENT_REQUEST; printf("OAI_NW_DRV_MSG_RB_ESTABLISHMENT_REQUEST: RB %d LCR %d QOS %d\n ", msgreq->rab_id, msgreq->lcr, msgreq->qos); @@ -405,8 +397,6 @@ int main(int argc,char **argv) printf(" IPV4: Dest = %d.%d.%d.%d/%d\n", NIPADDR(msgreq_class->daddr.ipv4), msgreq_class->dplen); gifr.type = OAI_NW_DRV_MSG_CLASS_ADD_REQUEST; err=ioctl(fd, OAI_NW_DRV_IOCTL_RRM, &gifr); - - msgreq_class->rab_id = atoi(rb); msgreq_class->lcr = atoi(cx); msgreq_class->version = 4; @@ -420,7 +410,6 @@ int main(int argc,char **argv) printf("OAI_NW_DRV_MSG_CLASS_ADD_REQUEST: OAI_NW_DRV_DIRECTION_RECEIVE RB %d LCR %d ClassRef %d ", msgreq_class->rab_id, msgreq_class->lcr, msgreq_class->classref); printf("IPV4: Source = %d.%d.%d.%d/%d ", NIPADDR(msgreq_class->saddr.ipv4), msgreq_class->splen); printf("IPV4: Dest = %d.%d.%d.%d/%d\n", NIPADDR(msgreq_class->daddr.ipv4), msgreq_class->dplen); - gifr.type = OAI_NW_DRV_MSG_CLASS_ADD_REQUEST; err=ioctl(fd, OAI_NW_DRV_IOCTL_RRM, &gifr); } @@ -443,7 +432,6 @@ int main(int argc,char **argv) msgreq_class->fct = OAI_NW_DRV_FCT_QOS_SEND; // TO BE FIXED WHEN WE CAN SPECIFY A PROTOCOL-based rule msgreq_class->protocol = OAI_NW_DRV_PROTOCOL_DEFAULT; - memcpy(&msgreq_class->saddr.ipv6,&saddr_ipv6,16); memcpy(&msgreq_class->daddr.ipv6,&daddr_ipv6,16); printf("OAI_NW_DRV_MSG_CLASS_ADD_REQUEST: OAI_NW_DRV_DIRECTION_SEND RB %d LCR %d ClassRef %d ", msgreq_class->rab_id, msgreq_class->lcr, msgreq_class->classref); @@ -451,7 +439,6 @@ int main(int argc,char **argv) printf("IPV6: Dest = %x:%x:%x:%x:%x:%x:%x:%x/%d\n", NIP6ADDR(&msgreq_class->daddr.ipv6), msgreq_class->dplen); gifr.type = OAI_NW_DRV_MSG_CLASS_ADD_REQUEST; err=ioctl(fd, OAI_NW_DRV_IOCTL_RRM, &gifr); - msgreq_class->rab_id = atoi(rb); msgreq_class->lcr = atoi(cx); msgreq_class->dplen = splen; @@ -468,7 +455,6 @@ int main(int argc,char **argv) } if (mpls_inlabelset == 1) { - msgreq_class = (struct oai_nw_drv_msg_class_add_request *)(gifr.msg); msgreq_class->rab_id = atoi(rb); msgreq_class->lcr = atoi(cx); @@ -483,40 +469,26 @@ int main(int argc,char **argv) //msgreq_class->classref = 4 + (msgreq_class->lcr<<3); msgreq_class->dir=OAI_NW_DRV_DIRECTION_SEND; msgreq_class->fct=OAI_NW_DRV_FCT_QOS_SEND; - // TO BE FIXED WHEN WE CAN SPECIFY A PROTOCOL-based rule msgreq_class->protocol = OAI_NW_DRV_PROTOCOL_DEFAULT; - mpls_outlabel = atoi(mpls_outgoinglabel); - - printf("Setting MPLS outlabel %d with exp %d\n",mpls_outlabel,msgreq_class->dscp); - + printf("Setting MPLS outlabel %u with exp %d\n",mpls_outlabel,msgreq_class->dscp); msgreq_class->daddr.mpls_label = mpls_outlabel; - gifr.type = OAI_NW_DRV_MSG_CLASS_ADD_REQUEST; err=ioctl(fd, OAI_NW_DRV_IOCTL_RRM, &gifr); - msgreq_class->rab_id = atoi(rb); msgreq_class->lcr = atoi(cx); - msgreq_class->classref = atoi(classref) + 1 + (msgreq_class->lcr<<8); //msgreq_class->classref = 5 + (msgreq_class->lcr<<3); msgreq_class->dir=OAI_NW_DRV_DIRECTION_RECEIVE; - - // TO BE FIXED WHEN WE CAN SPECIFY A PROTOCOL-based rule msgreq_class->protocol = OAI_NW_DRV_PROTOCOL_DEFAULT; - mpls_inlabel = atoi(mpls_incominglabel); - - printf("Setting MPLS inlabel %d with exp %d\n",mpls_inlabel,msgreq_class->dscp); - + printf("Setting MPLS inlabel %u with exp %d\n",mpls_inlabel,msgreq_class->dscp); msgreq_class->daddr.mpls_label = mpls_inlabel; - gifr.type = OAI_NW_DRV_MSG_CLASS_ADD_REQUEST; err=ioctl(fd, OAI_NW_DRV_IOCTL_RRM, &gifr); } - } else if (action == DEL_RB) { gifr.type = OAI_NW_DRV_MSG_RB_RELEASE_REQUEST; err=ioctl(fd, OAI_NW_DRV_IOCTL_RRM, &gifr); diff --git a/openair2/NETWORK_DRIVER/MESH/RB_TOOL/rb_tool.c b/openair2/NETWORK_DRIVER/MESH/RB_TOOL/rb_tool.c index 8e231895d97a0961da97e9f060c673a5cbe80e39..e02bf896c30399dba28555056dd917fd3fb063dd 100644 --- a/openair2/NETWORK_DRIVER/MESH/RB_TOOL/rb_tool.c +++ b/openair2/NETWORK_DRIVER/MESH/RB_TOOL/rb_tool.c @@ -108,12 +108,9 @@ int NAS_RALconnect(void) void IAL_NAS_ioctl_init(int inst) //--------------------------------------------------------------------------- { - struct nas_msg_statistic_reply *msgrep; int err; - sprintf(gifr.name, "oai%d",inst); - // Get an UDP IPv6 socket ?? fd=socket(AF_INET6, SOCK_DGRAM, 0); @@ -123,7 +120,6 @@ void IAL_NAS_ioctl_init(int inst) } sprintf(gifr.name, "oai%d",inst); - gifr.type = NAS_MSG_STATISTIC_REQUEST; memset ((void *)dummy_buffer,0,800); gifr.msg= &(dummy_buffer[0]); @@ -139,8 +135,6 @@ void IAL_NAS_ioctl_init(int inst) printf("tx_bytes = %u, rx_bytes = %u\n", msgrep->tx_bytes, msgrep->rx_bytes); printf("tx_errors = %u, rx_errors = %u\n", msgrep->tx_errors, msgrep->rx_errors); printf("tx_dropped = %u, rx_dropped = %u\n", msgrep->tx_dropped, msgrep->rx_dropped); - - } @@ -160,11 +154,7 @@ int main(int argc,char **argv) in_addr_t saddr_ipv4 = 0,daddr_ipv4 = 0; struct in6_addr saddr_ipv6,daddr_ipv6; unsigned int mpls_outlabel=0,mpls_inlabel=0; - char addr_str[46]; - - - // scan options rb[0] = '\0'; cx[0] = '\0'; @@ -174,89 +164,87 @@ int main(int argc,char **argv) while ((c = getopt (argc, argv, "adr:i:c:l:m:s:t:x:y:z:")) != -1) switch (c) { - case 'a': - action = ADD_RB; - break; - - case 'd': - action = DEL_RB; - break; - - case 'r': - strcpy(rb,optarg); - rbset = 1; - break; - - case 'i': - strcpy(inst,optarg); - instset = 1; - break; - - case 'c': - strcpy(cx,optarg); - cxset = 1; - break; - - case 'l': - strcpy(mpls_outgoinglabel,optarg); - mpls_outlabelset=1; - break; - - case 'm': - strcpy(mpls_incominglabel,optarg); - mpls_inlabelset=1; - break; - - case 's': { - struct in_addr a; - inet_aton(optarg,&a); - saddr_ipv4 = a.s_addr; - saddr_ipv4set = 1; - break; - } - - case 't': { - struct in_addr a; - inet_aton(optarg,&a); - daddr_ipv4 = a.s_addr; - daddr_ipv4set = 1; - break; - } - - case 'x': - printf("IPv6: %s\n",optarg); - inet_pton(AF_INET6,optarg,(void *)&saddr_ipv6); - saddr_ipv6set = 1; - break; - - case 'y': - inet_pton(AF_INET6,optarg,(void *)&daddr_ipv6); - daddr_ipv6set = 1; - break; - - case 'z': - dscpset=1; - strcpy(dscp,optarg); - break; - - case '?': - if (isprint (optopt)) - fprintf (stderr, "Unknown option `-%c'.\n", optopt); - else - fprintf (stderr, - "Unknown option character `\\x%x'.\n", - optopt); - - return 1; - - default: - abort (); + case 'a': + action = ADD_RB; + break; + + case 'd': + action = DEL_RB; + break; + + case 'r': + strcpy(rb,optarg); + rbset = 1; + break; + + case 'i': + strcpy(inst,optarg); + instset = 1; + break; + + case 'c': + strcpy(cx,optarg); + cxset = 1; + break; + + case 'l': + strcpy(mpls_outgoinglabel,optarg); + mpls_outlabelset=1; + break; + + case 'm': + strcpy(mpls_incominglabel,optarg); + mpls_inlabelset=1; + break; + + case 's': { + struct in_addr a; + inet_aton(optarg,&a); + saddr_ipv4 = a.s_addr; + saddr_ipv4set = 1; + break; + } + + case 't': { + struct in_addr a; + inet_aton(optarg,&a); + daddr_ipv4 = a.s_addr; + daddr_ipv4set = 1; + break; + } + + case 'x': + printf("IPv6: %s\n",optarg); + inet_pton(AF_INET6,optarg,(void *)&saddr_ipv6); + saddr_ipv6set = 1; + break; + + case 'y': + inet_pton(AF_INET6,optarg,(void *)&daddr_ipv6); + daddr_ipv6set = 1; + break; + + case 'z': + dscpset=1; + strcpy(dscp,optarg); + break; + + case '?': + if (isprint (optopt)) + fprintf (stderr, "Unknown option `-%c'.\n", optopt); + else + fprintf (stderr, + "Unknown option character `\\x%x'.\n", + optopt); + + return 1; + + default: + abort (); } - printf ("action = %d, rb = %s,cx = %s\n", action, rb, cx); - if (rbset==0) { printf("ERROR: Specify a RAB id!!\n"); exit(-1); @@ -293,31 +281,27 @@ int main(int argc,char **argv) } IAL_NAS_ioctl_init(atoi(inst)); - msgreq = (struct nas_msg_rb_establishment_request *)(gifr.msg); msgreq->rab_id = atoi(rb); msgreq->lcr = atoi(cx); msgreq->qos = 0; - if (action == ADD_RB) { gifr.type = NAS_MSG_RB_ESTABLISHMENT_REQUEST; err=ioctl(fd, NAS_IOCTL_RRM, &gifr); - if (err == -1) perror("ioctl"); + if (err == -1) perror("ioctl"); if (saddr_ipv4set == 1) { msgreq_class = (struct nas_msg_class_add_request *)(gifr.msg); msgreq_class->rab_id = atoi(rb); msgreq_class->lcr = atoi(cx); msgreq_class->version = 4; - msgreq_class->classref = 0 + (msgreq_class->lcr<<3); msgreq_class->dir = NAS_DIRECTION_SEND; msgreq_class->fct = NAS_FCT_QOS_SEND; msgreq_class->saddr.ipv4 = saddr_ipv4; msgreq_class->daddr.ipv4 = daddr_ipv4; - // TO BE FIXED WHEN WE CAN SPECIFY A PROTOCOL-based rule msgreq_class->protocol = NAS_PROTOCOL_DEFAULT; @@ -326,21 +310,20 @@ int main(int argc,char **argv) else msgreq_class->dscp=atoi(dscp); - gifr.type = NAS_MSG_CLASS_ADD_REQUEST; err=ioctl(fd, NAS_IOCTL_RRM, &gifr); + if (err == -1) perror("ioctl"); + msgreq_class->rab_id = atoi(rb); msgreq_class->lcr = atoi(cx); - msgreq_class->classref = 1+(msgreq_class->lcr<<3); msgreq_class->dir = NAS_DIRECTION_RECEIVE; - - msgreq_class->daddr.ipv4 = saddr_ipv4; msgreq_class->saddr.ipv4 = daddr_ipv4; gifr.type = NAS_MSG_CLASS_ADD_REQUEST; err=ioctl(fd, NAS_IOCTL_RRM, &gifr); + if (err == -1) perror("ioctl"); } @@ -358,38 +341,32 @@ int main(int argc,char **argv) msgreq_class->classref = 2+(msgreq_class->lcr<<3); msgreq_class->dir=NAS_DIRECTION_SEND; msgreq_class->fct=NAS_FCT_QOS_SEND; - // TO BE FIXED WHEN WE CAN SPECIFY A PROTOCOL-based rule msgreq_class->protocol = NAS_PROTOCOL_DEFAULT; - memcpy(&msgreq_class->saddr.ipv6,&saddr_ipv6,16); memcpy(&msgreq_class->daddr.ipv6,&daddr_ipv6,16); - inet_ntop(AF_INET6,(void *)&saddr_ipv6,addr_str,46); printf("IPV6: Source %s\n",addr_str); inet_ntop(AF_INET6,(void *)&daddr_ipv6,addr_str,46); printf("IPV6: Dest %s\n",addr_str); - gifr.type = NAS_MSG_CLASS_ADD_REQUEST; err=ioctl(fd, NAS_IOCTL_RRM, &gifr); + if (err == -1) perror("ioctl"); msgreq_class->rab_id = atoi(rb); msgreq_class->lcr = atoi(cx); - msgreq_class->classref = 3+(msgreq_class->lcr<<3); msgreq_class->dir=NAS_DIRECTION_RECEIVE; memcpy(&msgreq_class->daddr.ipv6,&saddr_ipv6,16); memcpy(&msgreq_class->saddr.ipv6,&daddr_ipv6,16); gifr.type = NAS_MSG_CLASS_ADD_REQUEST; err=ioctl(fd, NAS_IOCTL_RRM, &gifr); - if (err == -1) perror("ioctl"); - + if (err == -1) perror("ioctl"); } if (mpls_inlabelset == 1) { - msgreq_class = (struct nas_msg_class_add_request *)(gifr.msg); msgreq_class->rab_id = atoi(rb); msgreq_class->lcr = atoi(cx); @@ -403,50 +380,34 @@ int main(int argc,char **argv) msgreq_class->classref = 4 + (msgreq_class->lcr<<3); msgreq_class->dir=NAS_DIRECTION_SEND; msgreq_class->fct=NAS_FCT_QOS_SEND; - // TO BE FIXED WHEN WE CAN SPECIFY A PROTOCOL-based rule msgreq_class->protocol = NAS_PROTOCOL_DEFAULT; - mpls_outlabel = atoi(mpls_outgoinglabel); - - printf("Setting MPLS outlabel %d with exp %d\n",mpls_outlabel,msgreq_class->dscp); - + printf("Setting MPLS outlabel %u with exp %d\n",mpls_outlabel,msgreq_class->dscp); msgreq_class->daddr.mpls_label = mpls_outlabel; - gifr.type = NAS_MSG_CLASS_ADD_REQUEST; err=ioctl(fd, NAS_IOCTL_RRM, &gifr); + if (err == -1) perror("ioctl"); msgreq_class->rab_id = atoi(rb); msgreq_class->lcr = atoi(cx); - msgreq_class->classref = 5 + (msgreq_class->lcr<<3); msgreq_class->dir=NAS_DIRECTION_RECEIVE; - - // TO BE FIXED WHEN WE CAN SPECIFY A PROTOCOL-based rule msgreq_class->protocol = NAS_PROTOCOL_DEFAULT; - mpls_inlabel = atoi(mpls_incominglabel); - - printf("Setting MPLS inlabel %d with exp %d\n",mpls_inlabel,msgreq_class->dscp); - + printf("Setting MPLS inlabel %u with exp %d\n",mpls_inlabel,msgreq_class->dscp); msgreq_class->daddr.mpls_label = mpls_inlabel; - gifr.type = NAS_MSG_CLASS_ADD_REQUEST; err=ioctl(fd, NAS_IOCTL_RRM, &gifr); - if (err == -1) perror("ioctl"); - + if (err == -1) perror("ioctl"); } } else if (action == DEL_RB) { gifr.type = NAS_MSG_RB_RELEASE_REQUEST; err=ioctl(fd, NAS_IOCTL_RRM, &gifr); + if (err == -1) perror("ioctl"); } - - - - - } diff --git a/openair2/NETWORK_DRIVER/MESH/classifier.c b/openair2/NETWORK_DRIVER/MESH/classifier.c index a22ac2f20045b4457b9ec6adaeed72d931a0555a..15ac51158c404368e559042229c5a33003b85391 100644 --- a/openair2/NETWORK_DRIVER/MESH/classifier.c +++ b/openair2/NETWORK_DRIVER/MESH/classifier.c @@ -37,7 +37,7 @@ //#define MPLS #ifdef MPLS -#include <net/mpls.h> + #include <net/mpls.h> #endif @@ -46,12 +46,9 @@ //--------------------------------------------------------------------------- // Add a new classifier rule (send direction) -struct classifier_entity *nas_CLASS_add_sclassifier(struct cx_entity *cx, uint8_t dscp, uint16_t classref) -{ +struct classifier_entity *nas_CLASS_add_sclassifier(struct cx_entity *cx, uint8_t dscp, uint16_t classref) { //--------------------------------------------------------------------------- struct classifier_entity *gc; - - #ifdef NAS_DEBUG_CLASS printk("NAS_CLASS_ADD_SCLASSIFIER: begin for dscp %d, classref %d\n", dscp,classref); #endif @@ -91,8 +88,7 @@ struct classifier_entity *nas_CLASS_add_sclassifier(struct cx_entity *cx, uint8_ // Add a new classifier rule (receive direction) struct classifier_entity *nas_CLASS_add_rclassifier(uint8_t dscp, uint16_t classref, - struct nas_priv *gpriv) -{ + struct nas_priv *gpriv) { //--------------------------------------------------------------------------- struct classifier_entity *gc; #ifdef NAS_DEBUG_CLASS @@ -125,8 +121,7 @@ struct classifier_entity *nas_CLASS_add_rclassifier(uint8_t dscp, //--------------------------------------------------------------------------- // Add a new classifier rule (forwarding) -struct classifier_entity *nas_CLASS_add_fclassifier(struct cx_entity *cx, uint8_t dscp, uint16_t classref) -{ +struct classifier_entity *nas_CLASS_add_fclassifier(struct cx_entity *cx, uint8_t dscp, uint16_t classref) { //--------------------------------------------------------------------------- struct classifier_entity *gc; #ifdef NAS_DEBUG_CLASS @@ -166,8 +161,7 @@ struct classifier_entity *nas_CLASS_add_fclassifier(struct cx_entity *cx, uint8_ //--------------------------------------------------------------------------- -void nas_CLASS_flush_sclassifier(struct cx_entity *cx) -{ +void nas_CLASS_flush_sclassifier(struct cx_entity *cx) { //--------------------------------------------------------------------------- uint8_t dscpi; struct classifier_entity *gc; @@ -196,8 +190,7 @@ void nas_CLASS_flush_sclassifier(struct cx_entity *cx) #endif } //--------------------------------------------------------------------------- -void nas_CLASS_flush_fclassifier(struct cx_entity *cx) -{ +void nas_CLASS_flush_fclassifier(struct cx_entity *cx) { //--------------------------------------------------------------------------- uint8_t dscpi; struct classifier_entity *gc; @@ -227,8 +220,7 @@ void nas_CLASS_flush_fclassifier(struct cx_entity *cx) } //--------------------------------------------------------------------------- -void nas_CLASS_flush_rclassifier(struct nas_priv *gpriv) -{ +void nas_CLASS_flush_rclassifier(struct nas_priv *gpriv) { //--------------------------------------------------------------------------- uint8_t dscpi; struct classifier_entity *gc; @@ -251,8 +243,7 @@ void nas_CLASS_flush_rclassifier(struct nas_priv *gpriv) //--------------------------------------------------------------------------- // Delete a classifier rule (send direction) -void nas_CLASS_del_sclassifier(struct cx_entity *cx, uint8_t dscp, uint16_t classref) -{ +void nas_CLASS_del_sclassifier(struct cx_entity *cx, uint8_t dscp, uint16_t classref) { //--------------------------------------------------------------------------- struct classifier_entity *p,*np; #ifdef NAS_DEBUG_CLASS @@ -295,8 +286,7 @@ void nas_CLASS_del_sclassifier(struct cx_entity *cx, uint8_t dscp, uint16_t clas //--------------------------------------------------------------------------- // Delete a classifier rule (send direction) -void nas_CLASS_del_fclassifier(struct cx_entity *cx, uint8_t dscp, uint16_t classref) -{ +void nas_CLASS_del_fclassifier(struct cx_entity *cx, uint8_t dscp, uint16_t classref) { //--------------------------------------------------------------------------- struct classifier_entity *p,*np; #ifdef NAS_DEBUG_CLASS @@ -339,8 +329,7 @@ void nas_CLASS_del_fclassifier(struct cx_entity *cx, uint8_t dscp, uint16_t clas //--------------------------------------------------------------------------- // Delete a classifier rule (receive direction) -void nas_CLASS_del_rclassifier(uint8_t dscp, uint16_t classref,struct nas_priv *gpriv) -{ +void nas_CLASS_del_rclassifier(uint8_t dscp, uint16_t classref,struct nas_priv *gpriv) { //--------------------------------------------------------------------------- struct classifier_entity *p,*np; #ifdef NAS_DEBUG_CLASS @@ -379,8 +368,7 @@ struct cx_entity *nas_CLASS_cx6(struct sk_buff *skb, unsigned char dscp, struct nas_priv *gpriv, int inst, - unsigned char *cx_searcher) -{ + unsigned char *cx_searcher) { //--------------------------------------------------------------------------- unsigned char cxi; unsigned int *addr,*dst=NULL; @@ -388,17 +376,12 @@ struct cx_entity *nas_CLASS_cx6(struct sk_buff *skb, struct classifier_entity *p=NULL; if (skb!=NULL) { - for (cxi=*cx_searcher; cxi<NAS_CX_MAX; cxi++) { - (*cx_searcher)++; - p = gpriv->cx[cxi].sclassifier[dscp]; while (p!=NULL) { if (p->version == 6) { // verify that this is an IPv4 rule - - if ((addr = (unsigned int *)(&(p->daddr.ipv6)))== NULL) { printk("nas_CLASS_cx6: addr is null \n"); p = p->next; @@ -409,9 +392,8 @@ struct cx_entity *nas_CLASS_cx6(struct sk_buff *skb, printk("cx %d : %X,%X.%X,%X\n",cxi,addr[0],addr[1],addr[2],addr[3]); #endif //NAS_DEBUG_CLASS - //if ((dst = (unsigned int*)&(((struct rt6_info *)skbdst)->rt6i_gateway)) == 0){ - if ( (dst = &((struct iphdr*)(skb_network_header(skb)))->daddr) == NULL) { + if ( (dst = &((struct iphdr *)(skb_network_header(skb)))->daddr) == NULL) { printk("nas_CLASS_cx6: dst addr is null \n"); p = p->next; continue; @@ -446,11 +428,15 @@ struct cx_entity *nas_CLASS_cx6(struct sk_buff *skb, } } - printk("nas_CLASS_cx6 NOT FOUND: %X.%X.%X.%X\n", - dst[0], - dst[1], - dst[2], - dst[3]); + + if (dst ) { + printk("nas_CLASS_cx6 NOT FOUND: %X.%X.%X.%X\n", + dst[0], + dst[1], + dst[2], + dst[3]); + } + return default_ip; } @@ -460,8 +446,7 @@ struct cx_entity *nas_CLASS_cx4(struct sk_buff *skb, unsigned char dscp, struct nas_priv *gpriv, int inst, - unsigned char *cx_searcher) -{ + unsigned char *cx_searcher) { //--------------------------------------------------------------------------- unsigned char cxi; unsigned char *addr; @@ -473,10 +458,9 @@ struct cx_entity *nas_CLASS_cx4(struct sk_buff *skb, // return(gpriv->cx); //dump to clusterhead if (skb!=NULL) { - daddr = ((struct iphdr*)(skb_network_header(skb)))->daddr; + daddr = ((struct iphdr *)(skb_network_header(skb)))->daddr; if (daddr!=0) { - #ifdef NAS_DEBUG_CLASS printk("[NAS][CLASS][IPv4] Searching for %d.%d.%d.%d\n", ((unsigned char *)&daddr)[0], @@ -491,7 +475,6 @@ struct cx_entity *nas_CLASS_cx4(struct sk_buff *skb, while (p!=NULL) { if (p->version == 4) { // verify that this is an IPv4 rule - #ifdef NAS_DEBUG_CLASS addr = (char *)(&(p->daddr.ipv4)); printk("found classifier cx %d for destination: %d.%d.%d.%d\n",cxi,addr[0],addr[1],addr[2],addr[3]); @@ -536,32 +519,23 @@ struct cx_entity *nas_CLASS_MPLS(struct sk_buff *skb, unsigned char exp, struct nas_priv *gpriv, int inst, - unsigned char *cx_searcher) -{ + unsigned char *cx_searcher) { //--------------------------------------------------------------------------- unsigned char cxi; - struct cx_entity *default_label=NULL; struct classifier_entity *p=NULL; - // if (inst >0) // return(gpriv->cx); //dump to clusterhead - - #ifdef NAS_DEBUG_CLASS - - printk("[NAS][CLASS][MPLS] Searching for label %d\n",MPLSCB(skb)->label); #endif for (cxi=*cx_searcher; cxi<NAS_CX_MAX; ++cxi) { - (*cx_searcher)++; p = gpriv->cx[cxi].sclassifier[exp]; while (p!=NULL) { if (p->version == NAS_MPLS_VERSION_CODE) { // verify that this is an MPLS rule - #ifdef NAS_DEBUG_CLASS printk("cx %d : label %d\n",cxi,p->daddr.mpls_label); #endif //NAS_DEBUG_CLASS @@ -588,11 +562,8 @@ struct cx_entity *nas_CLASS_MPLS(struct sk_buff *skb, // goto to next classification rule for the connection p = p->next; } - } - - return default_label; } @@ -600,8 +571,7 @@ struct cx_entity *nas_CLASS_MPLS(struct sk_buff *skb, //--------------------------------------------------------------------------- // Search the sending function -void nas_CLASS_send(struct sk_buff *skb,int inst) -{ +void nas_CLASS_send(struct sk_buff *skb,int inst) { //--------------------------------------------------------------------------- struct classifier_entity *p, *sp; uint8_t *protocolh,version; @@ -609,15 +579,10 @@ void nas_CLASS_send(struct sk_buff *skb,int inst) uint16_t classref; struct cx_entity *cx; //unsigned int i; - //unsigned int router_adv = 0; struct net_device *dev=nasdev[inst]; - struct nas_priv *gpriv=netdev_priv(dev); - unsigned char cx_searcher,no_connection=1; - - #ifdef NAS_DEBUG_CLASS printk("NAS_CLASS_SEND: begin - inst %d\n",inst); #endif @@ -629,9 +594,7 @@ void nas_CLASS_send(struct sk_buff *skb,int inst) return; } - #ifdef NAS_DEBUG_SEND - printk("[NAS][CLASS][SEND] Got packet from kernel:\n"); for (i=0; i<256; i++) @@ -641,80 +604,65 @@ void nas_CLASS_send(struct sk_buff *skb,int inst) #endif // find all connections related to socket cx_searcher = 0; - no_connection = 1; - //while (cx_searcher<NAS_CX_MAX) { - cx = NULL; // Address classification switch (ntohs(skb->protocol)) { - case ETH_P_IPV6: - version = 6; - - protocolh=nas_TOOL_get_protocol6( - (struct ipv6hdr *)(skb_network_header(skb)), - &protocol); - dscp=nas_TOOL_get_dscp6( - (struct ipv6hdr *)(skb_network_header(skb)) - ); + case ETH_P_IPV6: + version = 6; + protocolh=nas_TOOL_get_protocol6( + (struct ipv6hdr *)(skb_network_header(skb)), + &protocol); + dscp=nas_TOOL_get_dscp6( + (struct ipv6hdr *)(skb_network_header(skb)) + ); #ifdef NAS_DEBUG_CLASS - printk("NAS_CLASS_SEND: %p %d %p %d %p \n",skb, dscp, gpriv, inst, &cx_searcher); + printk("NAS_CLASS_SEND: %p %d %p %d %p \n",skb, dscp, gpriv, inst, &cx_searcher); #endif - cx=nas_CLASS_cx6(skb,dscp,gpriv,inst,&cx_searcher); - - + cx=nas_CLASS_cx6(skb,dscp,gpriv,inst,&cx_searcher); #ifdef NAS_DEBUG_CLASS - printk("NAS_CLASS_SEND: Got IPv6 packet, dscp = %d\n",dscp); + printk("NAS_CLASS_SEND: Got IPv6 packet, dscp = %d\n",dscp); #endif - break; - - case ETH_P_IP: - + break; - dscp=nas_TOOL_get_dscp4((struct iphdr *)(skb_network_header(skb))); - cx=nas_CLASS_cx4(skb,dscp,gpriv,inst,&cx_searcher); - protocolh=nas_TOOL_get_protocol4( - (struct iphdr *)(skb_network_header(skb)), - &protocol); + case ETH_P_IP: + dscp=nas_TOOL_get_dscp4((struct iphdr *)(skb_network_header(skb))); + cx=nas_CLASS_cx4(skb,dscp,gpriv,inst,&cx_searcher); + protocolh=nas_TOOL_get_protocol4( + (struct iphdr *)(skb_network_header(skb)), + &protocol); #ifdef NAS_DEBUG_CLASS - printk("NAS_CLASS_SEND: Got IPv4 packet (%x), dscp = %d, cx = %x\n",ntohs(skb->protocol),dscp,cx); + printk("NAS_CLASS_SEND: Got IPv4 packet (%x), dscp = %d, cx = %x\n",ntohs(skb->protocol),dscp,cx); #endif - version = 4; - - break; + version = 4; + break; #ifdef MPLS - case ETH_P_MPLS_UC: - cx=nas_CLASS_MPLS(skb,MPLSCB(skb)->exp,gpriv,inst,&cx_searcher); - + case ETH_P_MPLS_UC: + cx=nas_CLASS_MPLS(skb,MPLSCB(skb)->exp,gpriv,inst,&cx_searcher); #ifdef NAS_DEBUG_CLASS - printk("NAS_CLASS_SEND: Got MPLS unicast packet, exp = %d, label = %d, cx = %x\n",MPLSCB(skb)->exp,MPLSCB(skb)->label,cx); + printk("NAS_CLASS_SEND: Got MPLS unicast packet, exp = %d, label = %d, cx = %x\n",MPLSCB(skb)->exp,MPLSCB(skb)->label,cx); #endif - - dscp = MPLSCB(skb)->exp; - version = NAS_MPLS_VERSION_CODE; - protocol = version; - break; + dscp = MPLSCB(skb)->exp; + version = NAS_MPLS_VERSION_CODE; + protocol = version; + break; #endif - default: - printk("NAS_CLASS_SEND: Unknown protocol\n"); - version = 0; - return; + default: + printk("NAS_CLASS_SEND: Unknown protocol\n"); + version = 0; + return; } - - // If a valid connection for the DSCP/EXP with destination address // is found scan all protocol-based classification rules if (cx) { - classref=0; sp=NULL; - #ifdef NAS_DEBUG_CLASS printk("[NAS][CLASSIFIER] DSCP/EXP %d : looking for classifier entry\n",dscp); #endif @@ -738,12 +686,10 @@ void nas_CLASS_send(struct sk_buff *skb,int inst) classref=sp->classref; break; } - } if (sp!=NULL) { #ifdef NAS_DEBUG_CLASS - char sfct[10], sprotocol[10]; if (sp->fct==nas_COMMON_QOS_send) @@ -759,41 +705,38 @@ void nas_CLASS_send(struct sk_buff *skb,int inst) strcpy(sfct, "dc"); switch(protocol) { - case NAS_PROTOCOL_UDP: - strcpy(sprotocol, "udp"); - printk("udp packet\n"); - break; - - case NAS_PROTOCOL_TCP: - strcpy(sprotocol, "tcp"); - printk("tcp packet\n"); - break; - - case NAS_PROTOCOL_ICMP4: - strcpy(sprotocol, "icmp4"); - printk("icmp4 packet\n"); - break; - - case NAS_PROTOCOL_ICMP6: - strcpy(sprotocol, "icmp6"); - print_TOOL_pk_icmp6((struct icmp6hdr*)protocolh); - break; + case NAS_PROTOCOL_UDP: + strcpy(sprotocol, "udp"); + printk("udp packet\n"); + break; + + case NAS_PROTOCOL_TCP: + strcpy(sprotocol, "tcp"); + printk("tcp packet\n"); + break; + + case NAS_PROTOCOL_ICMP4: + strcpy(sprotocol, "icmp4"); + printk("icmp4 packet\n"); + break; + + case NAS_PROTOCOL_ICMP6: + strcpy(sprotocol, "icmp6"); + print_TOOL_pk_icmp6((struct icmp6hdr *)protocolh); + break; #ifdef MPLS - case NAS_MPLS_VERSION_CODE: - strcpy(sprotocol,"mpls"); - break; + case NAS_MPLS_VERSION_CODE: + strcpy(sprotocol,"mpls"); + break; #endif } printk("NAS_CLASS_SEND: (dscp %u, %s) received, (classref %u, fct %s, rab_id %u) classifier rule\n", dscp, sprotocol, sp->classref, sfct, sp->rab_id); #endif - sp->fct(skb, cx, sp,inst, NULL); - } // if classifier entry match found - else { printk("NAS_CLASS_SEND: no corresponding item in the classifier, so the message is dropped\n"); // nas_COMMON_del_send(skb, cx, NULL,inst); @@ -802,20 +745,14 @@ void nas_CLASS_send(struct sk_buff *skb,int inst) no_connection = 0; } // if connection found - #ifdef NAS_DEBUG_CLASS if (no_connection == 1) printk("NAS_CLASS_SEND: no corresponding connection, so the message is dropped\n"); #endif /* NAS_DEBUG_CLASS */ - - // } // while loop over connections - - #ifdef NAS_DEBUG_CLASS printk("NAS_CLASS_SEND: end\n"); #endif - } diff --git a/openair2/NETWORK_DRIVER/UE_IP/netlink.c b/openair2/NETWORK_DRIVER/UE_IP/netlink.c index e8e36619d1b6942dcc0c1bbc73e353078baddcb5..5089a28d94b6dfe3da4e80b78ad9cec8fa927758 100644 --- a/openair2/NETWORK_DRIVER/UE_IP/netlink.c +++ b/openair2/NETWORK_DRIVER/UE_IP/netlink.c @@ -110,7 +110,7 @@ int ue_ip_netlink_init(void) # if LINUX_VERSION_CODE < KERNEL_VERSION(3,8,0) THIS_MODULE, # endif - &cfg + &cfg); #else /* LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0) */ nas_nl_sk = netlink_kernel_create( &init_net, @@ -120,7 +120,7 @@ int ue_ip_netlink_init(void) &nasmesh_mutex, // NULL THIS_MODULE); #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0) */ - ); + if (nas_nl_sk == NULL) { diff --git a/openair2/RRC/LTE/MESSAGES/asn1_msg.c b/openair2/RRC/LTE/MESSAGES/asn1_msg.c index 0bb11fa03761ccdb819633609c627a664274af51..b8cfad9cca032c03722dd66bedcea0ebdababd09 100644 --- a/openair2/RRC/LTE/MESSAGES/asn1_msg.c +++ b/openair2/RRC/LTE/MESSAGES/asn1_msg.c @@ -52,6 +52,8 @@ #include "LTE_RRCConnectionSetup.h" #include "LTE_SRB-ToAddModList.h" #include "LTE_DRB-ToAddModList.h" +#include "LTE_HandoverPreparationInformation.h" +#include "LTE_HandoverCommand.h" #if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0)) #include "LTE_MCCH-Message.h" //#define MRB1 1 @@ -3414,6 +3416,7 @@ uint16_t do_RRCConnectionReconfiguration(const protocol_ctxt_t *const ctx LTE_MAC_MainConfig_t *mac_MainConfig, LTE_MeasGapConfig_t *measGapConfig, LTE_MobilityControlInfo_t *mobilityInfo, + LTE_SecurityConfigHO_t *securityConfigHO, struct LTE_MeasConfig__speedStatePars *speedStatePars, LTE_RSRP_Range_t *rsrp, LTE_C_RNTI_t *cba_rnti, @@ -3504,8 +3507,16 @@ uint16_t do_RRCConnectionReconfiguration(const protocol_ctxt_t *const ctx rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.mobilityControlInfo = NULL; } + if (securityConfigHO != NULL) { + rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.securityConfigHO = CALLOC(1, + sizeof(*rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.securityConfigHO)); + memcpy((void*)rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.securityConfigHO, (void*)securityConfigHO, + sizeof(LTE_SecurityConfigHO_t)); + } else { + rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.securityConfigHO = NULL; + } + rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.dedicatedInfoNASList = dedicatedInfoNASList; - rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.securityConfigHO = NULL; //TTN for D2D //allocate dedicated resource pools for SL communication (sl_CommConfig_r12) @@ -4177,6 +4188,88 @@ uint8_t do_ULInformationTransfer(uint8_t **buffer, uint32_t pdu_length, uint8_t return encoded; } +int do_HandoverPreparation(char *ho_buf, int ho_size, LTE_UE_EUTRA_Capability_t *ue_eutra_cap, int rrc_size) +{ + asn_enc_rval_t enc_rval; + LTE_HandoverPreparationInformation_t ho; + LTE_HandoverPreparationInformation_r8_IEs_t *ho_info; + LTE_UE_CapabilityRAT_Container_t *ue_cap_rat_container; + + char rrc_buf[rrc_size]; + + memset(rrc_buf, 0, rrc_size); + + enc_rval = uper_encode_to_buffer(&asn_DEF_LTE_UE_EUTRA_Capability, + NULL, + ue_eutra_cap, + rrc_buf, + rrc_size); + + /* TODO: free the OCTET_STRING */ + + AssertFatal (enc_rval.encoded > 0, "ASN1 message encoding failed (%s, %lu)!\n", + enc_rval.failed_type->name, enc_rval.encoded); + + + memset(&ho, 0, sizeof(ho)); + + ho.criticalExtensions.present = LTE_HandoverPreparationInformation__criticalExtensions_PR_c1; + ho.criticalExtensions.choice.c1.present = LTE_HandoverPreparationInformation__criticalExtensions__c1_PR_handoverPreparationInformation_r8; + + ho_info = &ho.criticalExtensions.choice.c1.choice.handoverPreparationInformation_r8; + { + ue_cap_rat_container = (LTE_UE_CapabilityRAT_Container_t *)calloc(1,sizeof(LTE_UE_CapabilityRAT_Container_t)); + ue_cap_rat_container->rat_Type = LTE_RAT_Type_eutra; + + AssertFatal (OCTET_STRING_fromBuf( + &ue_cap_rat_container->ueCapabilityRAT_Container, + rrc_buf, rrc_size) != -1, "fatal: OCTET_STRING_fromBuf failed\n"); + + ASN_SEQUENCE_ADD(&ho_info->ue_RadioAccessCapabilityInfo.list, ue_cap_rat_container); + } + + enc_rval = uper_encode_to_buffer(&asn_DEF_LTE_HandoverPreparationInformation, + NULL, + &ho, + ho_buf, + ho_size); + + /* TODO: free the OCTET_STRING */ + + AssertFatal (enc_rval.encoded > 0, "ASN1 message encoding failed (%s, %lu)!\n", + enc_rval.failed_type->name, enc_rval.encoded); + + return((enc_rval.encoded+7)/8); +} + +int do_HandoverCommand(char *ho_buf, int ho_size, char *rrc_buf, int rrc_size) +{ + asn_enc_rval_t enc_rval; + LTE_HandoverCommand_t ho; + + memset(&ho, 0, sizeof(ho)); + + ho.criticalExtensions.present = LTE_HandoverCommand__criticalExtensions_PR_c1; + ho.criticalExtensions.choice.c1.present = LTE_HandoverCommand__criticalExtensions__c1_PR_handoverCommand_r8; + + AssertFatal (OCTET_STRING_fromBuf( + &ho.criticalExtensions.choice.c1.choice.handoverCommand_r8.handoverCommandMessage, + rrc_buf, rrc_size) != -1, "fatal: OCTET_STRING_fromBuf failed\n"); + + enc_rval = uper_encode_to_buffer(&asn_DEF_LTE_HandoverCommand, + NULL, + &ho, + ho_buf, + ho_size); + + /* TODO: free the OCTET_STRING */ + + AssertFatal (enc_rval.encoded > 0, "ASN1 message encoding failed (%s, %lu)!\n", + enc_rval.failed_type->name, enc_rval.encoded); + + return((enc_rval.encoded+7)/8); +} + OAI_UECapability_t *fill_ue_capability(char *UE_EUTRA_Capability_xer_fname) { static OAI_UECapability_t UECapability; /* TODO declared static to allow returning this has an address should be allocated in a cleaner way. */ static LTE_SupportedBandEUTRA_t Bandlist[4]; // the macro ASN_SEQUENCE_ADD() does not copy the source, but only stores a reference to it diff --git a/openair2/RRC/LTE/MESSAGES/asn1_msg.h b/openair2/RRC/LTE/MESSAGES/asn1_msg.h index 819f90c33639f3308788f8cec2c604fc9ba9b945..eb9572f4d2617ed30519d3054ee34e7c7bd8b5f8 100644 --- a/openair2/RRC/LTE/MESSAGES/asn1_msg.h +++ b/openair2/RRC/LTE/MESSAGES/asn1_msg.h @@ -247,6 +247,7 @@ do_RRCConnectionReconfiguration( LTE_MAC_MainConfig_t *mac_MainConfig, LTE_MeasGapConfig_t *measGapConfig, LTE_MobilityControlInfo_t *mobilityInfo, + LTE_SecurityConfigHO_t *securityConfigHO, struct LTE_MeasConfig__speedStatePars *speedStatePars, LTE_RSRP_Range_t *rsrp, LTE_C_RNTI_t *cba_rnti, @@ -337,6 +338,10 @@ uint8_t do_Paging(uint8_t Mod_id, uint8_t *buffer, ue_paging_identity_t ue_pagin uint8_t do_ULInformationTransfer(uint8_t **buffer, uint32_t pdu_length, uint8_t *pdu_buffer); +int do_HandoverPreparation(char *ho_buf, int ho_size, LTE_UE_EUTRA_Capability_t *ue_eutra_cap, int rrc_size); + +int do_HandoverCommand(char *ho_buf, int ho_size, char *rrc_buf, int rrc_size); + OAI_UECapability_t *fill_ue_capability(char *LTE_UE_EUTRA_Capability_xer); uint8_t diff --git a/openair2/RRC/LTE/rrc_defs.h b/openair2/RRC/LTE/rrc_defs.h index f28b34982b393429b39bab03a35bf28ff4dac129..6b616546bf4ac133478b5e626f145a47d72a559f 100644 --- a/openair2/RRC/LTE/rrc_defs.h +++ b/openair2/RRC/LTE/rrc_defs.h @@ -344,10 +344,13 @@ typedef enum UE_STATE_e { typedef enum HO_STATE_e { HO_IDLE=0, - HO_MEASURMENT, + HO_MEASUREMENT, HO_PREPARE, HO_CMD, // initiated by the src eNB - HO_COMPLETE // initiated by the target eNB + HO_COMPLETE, // initiated by the target eNB + HO_REQUEST, + HO_ACK, + HO_CONFIGURED } HO_STATE_t; typedef enum SL_TRIGGER_e { @@ -433,6 +436,7 @@ typedef enum e_rab_satus_e { E_RAB_STATUS_NEW, E_RAB_STATUS_DONE, // from the eNB perspective E_RAB_STATUS_ESTABLISHED, // get the reconfigurationcomplete form UE + E_RAB_STATUS_REESTABLISHED, // after HO E_RAB_STATUS_FAILED, E_RAB_STATUS_TORELEASE // to release DRB between eNB and UE } e_rab_status_t; @@ -446,14 +450,13 @@ typedef struct e_rab_param_s { } __attribute__ ((__packed__)) e_rab_param_t; #endif - - /* Intermediate structure for Handover management. Associated per-UE in eNB_RRC_INST */ typedef struct HANDOVER_INFO_s { uint8_t ho_prepare; uint8_t ho_complete; - uint8_t modid_s; //module_idP of serving cell - uint8_t modid_t; //module_idP of target cell + HO_STATE_t state; //current state of handover + uint32_t modid_s; //module_idP of serving cell + uint32_t modid_t; //module_idP of target cell uint8_t ueid_s; //UE index in serving cell uint8_t ueid_t; //UE index in target cell LTE_AS_Config_t as_config; /* these two parameters are taken from 36.331 section 10.2.2: HandoverPreparationInformation-r8-IEs */ @@ -511,6 +514,14 @@ typedef struct HANDOVER_INFO_UE_s { uint8_t measFlag; } HANDOVER_INFO_UE; +typedef struct rrc_gummei_s { + uint16_t mcc; + uint16_t mnc; + uint8_t mnc_len; + uint8_t mme_code; + uint16_t mme_group_id; +} rrc_gummei_t; + typedef struct eNB_RRC_UE_s { uint8_t primaryCC_id; #if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0)) @@ -537,8 +548,10 @@ typedef struct eNB_RRC_UE_s { LTE_MeasConfig_t *measConfig; HANDOVER_INFO *handover_info; LTE_MeasResults_t *measResults; + LTE_MobilityControlInfo_t *mobilityInfo; LTE_UE_EUTRA_Capability_t *UE_Capability; + int UE_Capability_size; ImsiMobileIdentity_t imsi; #if defined(ENABLE_SECURITY) @@ -570,8 +583,15 @@ typedef struct eNB_RRC_UE_s { /* Information from S1AP initial_context_setup_req */ uint32_t eNB_ue_s1ap_id :24; + uint32_t mme_ue_s1ap_id; + rrc_gummei_t ue_gummei; + security_capabilities_t security_capabilities; + int next_hop_chain_count; + + uint8_t next_security_key[SECURITY_KEY_LENGTH]; + /* Total number of e_rab already setup in the list */ uint8_t setup_e_rabs; /* Number of e_rab to be setup in the list */ @@ -582,8 +602,12 @@ typedef struct eNB_RRC_UE_s { e_rab_param_t modify_e_rab[NB_RB_MAX];//[S1AP_MAX_E_RAB]; /* list of e_rab to be setup by RRC layers */ e_rab_param_t e_rab[NB_RB_MAX];//[S1AP_MAX_E_RAB]; + /* UE aggregate maximum bitrate */ + ambr_t ue_ambr; //release e_rabs uint8_t nb_release_of_e_rabs; + /* list of e_rab to be released by RRC layers */ + uint8_t e_rabs_tobereleased[NB_RB_MAX]; e_rab_failed_t e_rabs_release_failed[S1AP_MAX_E_RAB]; // LG: For GTPV1 TUNNELS uint32_t enb_gtp_teid[S1AP_MAX_E_RAB]; @@ -641,6 +665,8 @@ typedef struct { int p_eNB; uint32_t dl_CarrierFreq; uint32_t ul_CarrierFreq; + uint32_t eutra_band; + uint32_t N_RB_DL; uint32_t pbch_repetition; LTE_BCCH_BCH_Message_t mib; LTE_BCCH_DL_SCH_Message_t siblock1; diff --git a/openair2/RRC/LTE/rrc_eNB.c b/openair2/RRC/LTE/rrc_eNB.c index 792299f4ae47d7f5fdbb03bbf9f30bf889955672..5a30ad4822f48fc1b6a412538cdbdbe0497f707f 100644 --- a/openair2/RRC/LTE/rrc_eNB.c +++ b/openair2/RRC/LTE/rrc_eNB.c @@ -53,6 +53,7 @@ #include "LTE_UL-DCCH-Message.h" #include "LTE_DL-DCCH-Message.h" #include "LTE_TDD-Config.h" +#include "LTE_HandoverPreparationInformation.h" #include "LTE_HandoverCommand.h" #include "rlc.h" #include "rrc_eNB_UE_context.h" @@ -120,6 +121,8 @@ extern uint16_t two_tier_hexagonal_cellIds[7]; mui_t rrc_eNB_mui = 0; +extern uint32_t to_earfcn_DL(int eutra_bandP, uint32_t dl_CarrierFreq, uint32_t bw); + void openair_rrc_on( const protocol_ctxt_t *const ctxt_pP @@ -161,6 +164,8 @@ init_SI( RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Ncp = configuration->prefix_type[CC_id]; RC.rrc[ctxt_pP->module_id]->carrier[CC_id].dl_CarrierFreq = configuration->downlink_frequency[CC_id]; RC.rrc[ctxt_pP->module_id]->carrier[CC_id].ul_CarrierFreq = configuration->downlink_frequency[CC_id]+ configuration->uplink_frequency_offset[CC_id]; + RC.rrc[ctxt_pP->module_id]->carrier[CC_id].eutra_band = configuration->eutra_band[CC_id]; + RC.rrc[ctxt_pP->module_id]->carrier[CC_id].N_RB_DL = configuration->N_RB_DL[CC_id]; #if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0)) RC.rrc[ctxt_pP->module_id]->carrier[CC_id].pbch_repetition = configuration->pbch_repetition[CC_id]; #endif @@ -1396,16 +1401,12 @@ rrc_eNB_process_RRCConnectionReestablishmentComplete( } } - SRB_configList2 = &ue_context_pP->ue_context.SRB_configList2[next_xid]; - DRB_configList2 = &ue_context_pP->ue_context.DRB_configList2[next_xid]; + SRB_configList2 = &(ue_context_pP->ue_context.SRB_configList2[next_xid]); + DRB_configList2 = &(ue_context_pP->ue_context.DRB_configList2[next_xid]); - if(SRB_configList2!=NULL) { - if (*SRB_configList2) { - free(*SRB_configList2); - LOG_D(RRC, "free(ue_context_pP->ue_context.SRB_configList2[%d])\n", next_xid); - } - } else { - LOG_E(RRC, "SRB_configList2 is null\n"); + if (*SRB_configList2) { + free(*SRB_configList2); + LOG_D(RRC, "free(ue_context_pP->ue_context.SRB_configList2[%d])\n", next_xid); } *SRB_configList2 = CALLOC(1, sizeof(**SRB_configList2)); @@ -1423,13 +1424,9 @@ rrc_eNB_process_RRCConnectionReestablishmentComplete( LOG_W(RRC,"SRB2 configuration does not exist in SRB configuration list\n"); } - if(DRB_configList2!=NULL) { - if (*DRB_configList2) { - free(*DRB_configList2); - LOG_D(RRC, "free(ue_context_pP->ue_context.DRB_configList2[%d])\n", next_xid); - } - } else { - LOG_E(RRC, "DRB_configList2 is null\n"); + if (*DRB_configList2) { + free(*DRB_configList2); + LOG_D(RRC, "free(ue_context_pP->ue_context.DRB_configList2[%d])\n", next_xid); } *DRB_configList2 = CALLOC(1, sizeof(**DRB_configList2)); @@ -1606,7 +1603,7 @@ rrc_eNB_process_RRCConnectionReestablishmentComplete( ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.reportAmount = LTE_ReportConfigEUTRA__reportAmount_infinity; ASN_SEQUENCE_ADD(&ReportConfig_list->list, ReportConfig_A1); - if (RC.rrc[ctxt_pP->module_id]->HO_flag == 1 /*HO_MEASURMENT */ ) { + if (RC.rrc[ctxt_pP->module_id]->HO_flag == 1 /*HO_MEASUREMENT */ ) { LOG_I(RRC, "[eNB %d] frame %d: requesting A2, A3, A4, A5, and A6 event reporting\n", ctxt_pP->module_id, ctxt_pP->frame); ReportConfig_A2->reportConfigId = 3; @@ -1811,6 +1808,7 @@ rrc_eNB_process_RRCConnectionReestablishmentComplete( (LTE_MAC_MainConfig_t *)ue_context_pP->ue_context.mac_MainConfig, (LTE_MeasGapConfig_t *)NULL, (LTE_MobilityControlInfo_t *)NULL, + (LTE_SecurityConfigHO_t *)NULL, (struct LTE_MeasConfig__speedStatePars *)Sparams, // Sparams, (LTE_RSRP_Range_t *)rsrp, // rsrp, (LTE_C_RNTI_t *)cba_RNTI, // cba_RNTI @@ -2235,7 +2233,7 @@ rrc_eNB_generate_dedicatedRRCConnectionReconfiguration(const protocol_ctxt_t *co (LTE_DRB_ToReleaseList_t *)NULL, // DRB2_list, (struct LTE_SPS_Config *)NULL, // *sps_Config, NULL, NULL, NULL, NULL,NULL, - NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, (struct LTE_RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList *)dedicatedInfoNASList, (LTE_SL_CommConfig_r12_t *)NULL, (LTE_SL_DiscConfig_r12_t *)NULL @@ -2486,7 +2484,7 @@ rrc_eNB_modify_dedicatedRRCConnectionReconfiguration(const protocol_ctxt_t *cons (LTE_DRB_ToReleaseList_t *)NULL, // DRB2_list, (struct LTE_SPS_Config *)NULL, // *sps_Config, NULL, NULL, NULL, NULL,NULL, - NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, (struct LTE_RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList *)dedicatedInfoNASList, (LTE_SL_CommConfig_r12_t *)NULL, (LTE_SL_DiscConfig_r12_t *)NULL @@ -2601,6 +2599,7 @@ rrc_eNB_generate_dedicatedRRCConnectionReconfiguration_release( const protocol_ NULL, NULL, NULL, + NULL, (struct LTE_RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList *)dedicatedInfoNASList, (LTE_SL_CommConfig_r12_t *)NULL, (LTE_SL_DiscConfig_r12_t *)NULL @@ -2695,8 +2694,8 @@ rrc_eNB_generate_defaultRRCConnectionReconfiguration(const protocol_ctxt_t *cons LTE_RSRP_Range_t *rsrp = NULL; struct LTE_MeasConfig__speedStatePars *Sparams = NULL; LTE_QuantityConfig_t *quantityConfig = NULL; - LTE_CellsToAddMod_t *CellToAdd = NULL; - LTE_CellsToAddModList_t *CellsToAddModList = NULL; + //LTE_CellsToAddMod_t *CellToAdd = NULL; + //LTE_CellsToAddModList_t *CellsToAddModList = NULL; struct LTE_RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList *dedicatedInfoNASList = NULL; LTE_DedicatedInfoNAS_t *dedicatedInfoNas = NULL; /* for no gcc warnings */ @@ -2995,8 +2994,8 @@ rrc_eNB_generate_defaultRRCConnectionReconfiguration(const protocol_ctxt_t *cons memset((void *)MeasObj, 0, sizeof(*MeasObj)); MeasObj->measObjectId = 1; MeasObj->measObject.present = LTE_MeasObjectToAddMod__measObject_PR_measObjectEUTRA; - MeasObj->measObject.choice.measObjectEUTRA.carrierFreq = 3350; //band 7, 2.68GHz - //MeasObj->measObject.choice.measObjectEUTRA.carrierFreq = 36090; //band 33, 1.909GHz + MeasObj->measObject.choice.measObjectEUTRA.carrierFreq = (LTE_ARFCN_ValueEUTRA_t)to_earfcn_DL(RC.rrc[ctxt_pP->module_id]->carrier[0].eutra_band, RC.rrc[ctxt_pP->module_id]->carrier[0].dl_CarrierFreq, + RC.rrc[ctxt_pP->module_id]->carrier[0].N_RB_DL); MeasObj->measObject.choice.measObjectEUTRA.allowedMeasBandwidth = LTE_AllowedMeasBandwidth_mbw25; MeasObj->measObject.choice.measObjectEUTRA.presenceAntennaPort1 = 1; MeasObj->measObject.choice.measObjectEUTRA.neighCellConfig.buf = CALLOC(1, sizeof(uint8_t)); @@ -3004,18 +3003,18 @@ rrc_eNB_generate_defaultRRCConnectionReconfiguration(const protocol_ctxt_t *cons MeasObj->measObject.choice.measObjectEUTRA.neighCellConfig.size = 1; MeasObj->measObject.choice.measObjectEUTRA.neighCellConfig.bits_unused = 6; MeasObj->measObject.choice.measObjectEUTRA.offsetFreq = NULL; // Default is 15 or 0dB - MeasObj->measObject.choice.measObjectEUTRA.cellsToAddModList = - (LTE_CellsToAddModList_t *) CALLOC(1, sizeof(*CellsToAddModList)); - CellsToAddModList = MeasObj->measObject.choice.measObjectEUTRA.cellsToAddModList; - - // Add adjacent cell lists (6 per eNB) - for (i = 0; i < 6; i++) { - CellToAdd = (LTE_CellsToAddMod_t *) CALLOC(1, sizeof(*CellToAdd)); - CellToAdd->cellIndex = i + 1; - CellToAdd->physCellId = get_adjacent_cell_id(ctxt_pP->module_id, i); - CellToAdd->cellIndividualOffset = LTE_Q_OffsetRange_dB0; - ASN_SEQUENCE_ADD(&CellsToAddModList->list, CellToAdd); - } +// MeasObj->measObject.choice.measObjectEUTRA.cellsToAddModList = +// (LTE_CellsToAddModList_t *) CALLOC(1, sizeof(*CellsToAddModList)); +// CellsToAddModList = MeasObj->measObject.choice.measObjectEUTRA.cellsToAddModList; +// +// // Add adjacent cell lists (6 per eNB) +// for (i = 0; i < 6; i++) { +// CellToAdd = (LTE_CellsToAddMod_t *) CALLOC(1, sizeof(*CellToAdd)); +// CellToAdd->cellIndex = i + 1; +// CellToAdd->physCellId = get_adjacent_cell_id(ctxt_pP->module_id, i); +// CellToAdd->cellIndividualOffset = LTE_Q_OffsetRange_dB0; +// ASN_SEQUENCE_ADD(&CellsToAddModList->list, CellToAdd); +// } ASN_SEQUENCE_ADD(&MeasObj_list->list, MeasObj); // LTE_RRCConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig->measObjectToAddModList = MeasObj_list; @@ -3056,129 +3055,131 @@ rrc_eNB_generate_defaultRRCConnectionReconfiguration(const protocol_ctxt_t *cons ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.reportAmount = LTE_ReportConfigEUTRA__reportAmount_infinity; ASN_SEQUENCE_ADD(&ReportConfig_list->list, ReportConfig_A1); - if (ho_state == 1 /*HO_MEASURMENT */ ) { - LOG_I(RRC, "[eNB %d] frame %d: requesting A2, A3, A4, A5, and A6 event reporting\n", - ctxt_pP->module_id, ctxt_pP->frame); - ReportConfig_A2->reportConfigId = 3; - ReportConfig_A2->reportConfig.present = LTE_ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA; - ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.triggerType.present = - LTE_ReportConfigEUTRA__triggerType_PR_event; - ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.present = - LTE_ReportConfigEUTRA__triggerType__event__eventId_PR_eventA2; - ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice. - eventA2.a2_Threshold.present = LTE_ThresholdEUTRA_PR_threshold_RSRP; - ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice. - eventA2.a2_Threshold.choice.threshold_RSRP = 10; - ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.triggerQuantity = - LTE_ReportConfigEUTRA__triggerQuantity_rsrp; - ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.reportQuantity = LTE_ReportConfigEUTRA__reportQuantity_both; - ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.maxReportCells = 2; - ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.reportInterval = LTE_ReportInterval_ms120; - ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.reportAmount = LTE_ReportConfigEUTRA__reportAmount_infinity; - ASN_SEQUENCE_ADD(&ReportConfig_list->list, ReportConfig_A2); - ReportConfig_A3->reportConfigId = 4; - ReportConfig_A3->reportConfig.present = LTE_ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA; - ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.present = - LTE_ReportConfigEUTRA__triggerType_PR_event; - ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.present = - LTE_ReportConfigEUTRA__triggerType__event__eventId_PR_eventA3; - ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.eventA3.a3_Offset = 1; //10; - ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice. - eventA3.reportOnLeave = 1; - ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerQuantity = - LTE_ReportConfigEUTRA__triggerQuantity_rsrp; - ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.reportQuantity = LTE_ReportConfigEUTRA__reportQuantity_both; - ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.maxReportCells = 2; - ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.reportInterval = LTE_ReportInterval_ms120; - ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.reportAmount = LTE_ReportConfigEUTRA__reportAmount_infinity; - ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.hysteresis = 0.5; // FIXME ...hysteresis is of type long! - ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.timeToTrigger = - LTE_TimeToTrigger_ms40; - ASN_SEQUENCE_ADD(&ReportConfig_list->list, ReportConfig_A3); - ReportConfig_A4->reportConfigId = 5; - ReportConfig_A4->reportConfig.present = LTE_ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA; - ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.triggerType.present = - LTE_ReportConfigEUTRA__triggerType_PR_event; - ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.present = - LTE_ReportConfigEUTRA__triggerType__event__eventId_PR_eventA4; - ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice. - eventA4.a4_Threshold.present = LTE_ThresholdEUTRA_PR_threshold_RSRP; - ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice. - eventA4.a4_Threshold.choice.threshold_RSRP = 10; - ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.triggerQuantity = - LTE_ReportConfigEUTRA__triggerQuantity_rsrp; - ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.reportQuantity = LTE_ReportConfigEUTRA__reportQuantity_both; - ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.maxReportCells = 2; - ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.reportInterval = LTE_ReportInterval_ms120; - ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.reportAmount = LTE_ReportConfigEUTRA__reportAmount_infinity; - ASN_SEQUENCE_ADD(&ReportConfig_list->list, ReportConfig_A4); - ReportConfig_A5->reportConfigId = 6; - ReportConfig_A5->reportConfig.present = LTE_ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA; - ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerType.present = - LTE_ReportConfigEUTRA__triggerType_PR_event; - ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.present = - LTE_ReportConfigEUTRA__triggerType__event__eventId_PR_eventA5; - ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice. - eventA5.a5_Threshold1.present = LTE_ThresholdEUTRA_PR_threshold_RSRP; - ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice. - eventA5.a5_Threshold2.present = LTE_ThresholdEUTRA_PR_threshold_RSRP; - ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice. - eventA5.a5_Threshold1.choice.threshold_RSRP = 10; - ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice. - eventA5.a5_Threshold2.choice.threshold_RSRP = 10; - ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerQuantity = - LTE_ReportConfigEUTRA__triggerQuantity_rsrp; - ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.reportQuantity = LTE_ReportConfigEUTRA__reportQuantity_both; - ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.maxReportCells = 2; - ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.reportInterval = LTE_ReportInterval_ms120; - ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.reportAmount = LTE_ReportConfigEUTRA__reportAmount_infinity; - ASN_SEQUENCE_ADD(&ReportConfig_list->list, ReportConfig_A5); - // LTE_RRCConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig->reportConfigToAddModList = ReportConfig_list; - rsrp = CALLOC(1, sizeof(LTE_RSRP_Range_t)); - *rsrp = 20; - Sparams = CALLOC(1, sizeof(*Sparams)); - Sparams->present = LTE_MeasConfig__speedStatePars_PR_setup; - Sparams->choice.setup.timeToTrigger_SF.sf_High = LTE_SpeedStateScaleFactors__sf_Medium_oDot75; - Sparams->choice.setup.timeToTrigger_SF.sf_Medium = LTE_SpeedStateScaleFactors__sf_High_oDot5; - Sparams->choice.setup.mobilityStateParameters.n_CellChangeHigh = 10; - Sparams->choice.setup.mobilityStateParameters.n_CellChangeMedium = 5; - Sparams->choice.setup.mobilityStateParameters.t_Evaluation = LTE_MobilityStateParameters__t_Evaluation_s60; - Sparams->choice.setup.mobilityStateParameters.t_HystNormal = LTE_MobilityStateParameters__t_HystNormal_s120; - quantityConfig = CALLOC(1, sizeof(*quantityConfig)); - memset((void *)quantityConfig, 0, sizeof(*quantityConfig)); - quantityConfig->quantityConfigEUTRA = CALLOC(1, sizeof(struct LTE_QuantityConfigEUTRA)); - memset((void *)quantityConfig->quantityConfigEUTRA, 0, sizeof(*quantityConfig->quantityConfigEUTRA)); - quantityConfig->quantityConfigCDMA2000 = NULL; - quantityConfig->quantityConfigGERAN = NULL; - quantityConfig->quantityConfigUTRA = NULL; - quantityConfig->quantityConfigEUTRA->filterCoefficientRSRP = - CALLOC(1, sizeof(*(quantityConfig->quantityConfigEUTRA->filterCoefficientRSRP))); - quantityConfig->quantityConfigEUTRA->filterCoefficientRSRQ = - CALLOC(1, sizeof(*(quantityConfig->quantityConfigEUTRA->filterCoefficientRSRQ))); - *quantityConfig->quantityConfigEUTRA->filterCoefficientRSRP = LTE_FilterCoefficient_fc4; - *quantityConfig->quantityConfigEUTRA->filterCoefficientRSRQ = LTE_FilterCoefficient_fc4; - LOG_I(RRC, - "[eNB %d] Frame %d: potential handover preparation: store the information in an intermediate structure in case of failure\n", - ctxt_pP->module_id, ctxt_pP->frame); - // store the information in an intermediate structure for Hanodver management - //rrc_inst->handover_info.as_config.sourceRadioResourceConfig.srb_ToAddModList = CALLOC(1,sizeof()); - ue_context_pP->ue_context.handover_info = CALLOC(1, sizeof(*(ue_context_pP->ue_context.handover_info))); - //memcpy((void *)rrc_inst->handover_info[ue_mod_idP]->as_config.sourceRadioResourceConfig.srb_ToAddModList,(void *)SRB_list,sizeof(LTE_SRB_ToAddModList_t)); - ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.srb_ToAddModList = *SRB_configList2; - //memcpy((void *)rrc_inst->handover_info[ue_mod_idP]->as_config.sourceRadioResourceConfig.drb_ToAddModList,(void *)DRB_list,sizeof(LTE_DRB_ToAddModList_t)); - ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.drb_ToAddModList = *DRB_configList; - ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.drb_ToReleaseList = NULL; - ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.mac_MainConfig = - CALLOC(1, sizeof(*ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.mac_MainConfig)); - memcpy((void *)ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.mac_MainConfig, - (void *)mac_MainConfig, sizeof(LTE_MAC_MainConfig_t)); - ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.physicalConfigDedicated = - CALLOC(1, sizeof(LTE_PhysicalConfigDedicated_t)); - memcpy((void *)ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.physicalConfigDedicated, - (void *)ue_context_pP->ue_context.physicalConfigDedicated, sizeof(LTE_PhysicalConfigDedicated_t)); - ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.sps_Config = NULL; - //memcpy((void *)rrc_inst->handover_info[ue_mod_idP]->as_config.sourceRadioResourceConfig.sps_Config,(void *)rrc_inst->sps_Config[ue_mod_idP],sizeof(SPS_Config_t)); - } + //if (ho_state == 1 /*HO_MEASURMENT */ ) { + LOG_I(RRC, "[eNB %d] frame %d: requesting A2, A3, A4, and A5 event reporting\n", + ctxt_pP->module_id, ctxt_pP->frame); + ReportConfig_A2->reportConfigId = 3; + ReportConfig_A2->reportConfig.present = LTE_ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA; + ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.triggerType.present = + LTE_ReportConfigEUTRA__triggerType_PR_event; + ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.present = + LTE_ReportConfigEUTRA__triggerType__event__eventId_PR_eventA2; + ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice. + eventA2.a2_Threshold.present = LTE_ThresholdEUTRA_PR_threshold_RSRP; + ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice. + eventA2.a2_Threshold.choice.threshold_RSRP = 10; + ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.triggerQuantity = + LTE_ReportConfigEUTRA__triggerQuantity_rsrp; + ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.reportQuantity = LTE_ReportConfigEUTRA__reportQuantity_both; + ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.maxReportCells = 2; + ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.reportInterval = LTE_ReportInterval_ms120; + ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.reportAmount = LTE_ReportConfigEUTRA__reportAmount_infinity; + ASN_SEQUENCE_ADD(&ReportConfig_list->list, ReportConfig_A2); + ReportConfig_A3->reportConfigId = 4; + ReportConfig_A3->reportConfig.present = LTE_ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA; + ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.present = + LTE_ReportConfigEUTRA__triggerType_PR_event; + ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.present = + LTE_ReportConfigEUTRA__triggerType__event__eventId_PR_eventA3; + ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.eventA3.a3_Offset = 0; //10; + ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice. + eventA3.reportOnLeave = 1; + ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerQuantity = + LTE_ReportConfigEUTRA__triggerQuantity_rsrp; + ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.reportQuantity = LTE_ReportConfigEUTRA__reportQuantity_both; + ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.maxReportCells = 2; + ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.reportInterval = LTE_ReportInterval_ms120; + ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.reportAmount = LTE_ReportConfigEUTRA__reportAmount_infinity; + ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.hysteresis = 0; // FIXME ...hysteresis is of type long! + ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.timeToTrigger = + LTE_TimeToTrigger_ms40; + ASN_SEQUENCE_ADD(&ReportConfig_list->list, ReportConfig_A3); + ReportConfig_A4->reportConfigId = 5; + ReportConfig_A4->reportConfig.present = LTE_ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA; + ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.triggerType.present = + LTE_ReportConfigEUTRA__triggerType_PR_event; + ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.present = + LTE_ReportConfigEUTRA__triggerType__event__eventId_PR_eventA4; + ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice. + eventA4.a4_Threshold.present = LTE_ThresholdEUTRA_PR_threshold_RSRP; + ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice. + eventA4.a4_Threshold.choice.threshold_RSRP = 10; + ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.triggerQuantity = + LTE_ReportConfigEUTRA__triggerQuantity_rsrp; + ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.reportQuantity = LTE_ReportConfigEUTRA__reportQuantity_both; + ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.maxReportCells = 2; + ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.reportInterval = LTE_ReportInterval_ms120; + ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.reportAmount = LTE_ReportConfigEUTRA__reportAmount_infinity; + ASN_SEQUENCE_ADD(&ReportConfig_list->list, ReportConfig_A4); + ReportConfig_A5->reportConfigId = 6; + ReportConfig_A5->reportConfig.present = LTE_ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA; + ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerType.present = + LTE_ReportConfigEUTRA__triggerType_PR_event; + ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.present = + LTE_ReportConfigEUTRA__triggerType__event__eventId_PR_eventA5; + ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice. + eventA5.a5_Threshold1.present = LTE_ThresholdEUTRA_PR_threshold_RSRP; + ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice. + eventA5.a5_Threshold2.present = LTE_ThresholdEUTRA_PR_threshold_RSRP; + ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice. + eventA5.a5_Threshold1.choice.threshold_RSRP = 10; + ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice. + eventA5.a5_Threshold2.choice.threshold_RSRP = 10; + ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerQuantity = + LTE_ReportConfigEUTRA__triggerQuantity_rsrp; + ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.reportQuantity = LTE_ReportConfigEUTRA__reportQuantity_both; + ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.maxReportCells = 2; + ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.reportInterval = LTE_ReportInterval_ms120; + ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.reportAmount = LTE_ReportConfigEUTRA__reportAmount_infinity; + ASN_SEQUENCE_ADD(&ReportConfig_list->list, ReportConfig_A5); + // LTE_RRCConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig->reportConfigToAddModList = ReportConfig_list; + rsrp = CALLOC(1, sizeof(LTE_RSRP_Range_t)); + *rsrp = 20; + Sparams = CALLOC(1, sizeof(*Sparams)); + Sparams->present = LTE_MeasConfig__speedStatePars_PR_setup; + Sparams->choice.setup.timeToTrigger_SF.sf_High = LTE_SpeedStateScaleFactors__sf_Medium_oDot75; + Sparams->choice.setup.timeToTrigger_SF.sf_Medium = LTE_SpeedStateScaleFactors__sf_High_oDot5; + Sparams->choice.setup.mobilityStateParameters.n_CellChangeHigh = 10; + Sparams->choice.setup.mobilityStateParameters.n_CellChangeMedium = 5; + Sparams->choice.setup.mobilityStateParameters.t_Evaluation = LTE_MobilityStateParameters__t_Evaluation_s60; + Sparams->choice.setup.mobilityStateParameters.t_HystNormal = LTE_MobilityStateParameters__t_HystNormal_s120; + quantityConfig = CALLOC(1, sizeof(*quantityConfig)); + memset((void *)quantityConfig, 0, sizeof(*quantityConfig)); + quantityConfig->quantityConfigEUTRA = CALLOC(1, sizeof(struct LTE_QuantityConfigEUTRA)); + memset((void *)quantityConfig->quantityConfigEUTRA, 0, sizeof(*quantityConfig->quantityConfigEUTRA)); + quantityConfig->quantityConfigCDMA2000 = NULL; + quantityConfig->quantityConfigGERAN = NULL; + quantityConfig->quantityConfigUTRA = NULL; + quantityConfig->quantityConfigEUTRA->filterCoefficientRSRP = + CALLOC(1, sizeof(*(quantityConfig->quantityConfigEUTRA->filterCoefficientRSRP))); + quantityConfig->quantityConfigEUTRA->filterCoefficientRSRQ = + CALLOC(1, sizeof(*(quantityConfig->quantityConfigEUTRA->filterCoefficientRSRQ))); + *quantityConfig->quantityConfigEUTRA->filterCoefficientRSRP = LTE_FilterCoefficient_fc4; + *quantityConfig->quantityConfigEUTRA->filterCoefficientRSRQ = LTE_FilterCoefficient_fc4; +#if 0 + LOG_I(RRC, + "[eNB %d] Frame %d: potential handover preparation: store the information in an intermediate structure in case of failure\n", + ctxt_pP->module_id, ctxt_pP->frame); + // store the information in an intermediate structure for Hanodver management + //rrc_inst->handover_info.as_config.sourceRadioResourceConfig.srb_ToAddModList = CALLOC(1,sizeof()); + ue_context_pP->ue_context.handover_info = CALLOC(1, sizeof(*(ue_context_pP->ue_context.handover_info))); + //memcpy((void *)rrc_inst->handover_info[ue_mod_idP]->as_config.sourceRadioResourceConfig.srb_ToAddModList,(void *)SRB_list,sizeof(LTE_SRB_ToAddModList_t)); + ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.srb_ToAddModList = *SRB_configList2; + //memcpy((void *)rrc_inst->handover_info[ue_mod_idP]->as_config.sourceRadioResourceConfig.drb_ToAddModList,(void *)DRB_list,sizeof(LTE_DRB_ToAddModList_t)); + ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.drb_ToAddModList = *DRB_configList; + ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.drb_ToReleaseList = NULL; + ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.mac_MainConfig = + CALLOC(1, sizeof(*ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.mac_MainConfig)); + memcpy((void *)ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.mac_MainConfig, + (void *)mac_MainConfig, sizeof(LTE_MAC_MainConfig_t)); + ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.physicalConfigDedicated = + CALLOC(1, sizeof(LTE_PhysicalConfigDedicated_t)); + memcpy((void *)ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.physicalConfigDedicated, + (void *)ue_context_pP->ue_context.physicalConfigDedicated, sizeof(LTE_PhysicalConfigDedicated_t)); + ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.sps_Config = NULL; + //memcpy((void *)rrc_inst->handover_info[ue_mod_idP]->as_config.sourceRadioResourceConfig.sps_Config,(void *)rrc_inst->sps_Config[ue_mod_idP],sizeof(SPS_Config_t)); +#endif + //} #if defined(ENABLE_ITTI) /* Initialize NAS list */ @@ -3223,17 +3224,18 @@ rrc_eNB_generate_defaultRRCConnectionReconfiguration(const protocol_ctxt_t *cons (LTE_DRB_ToReleaseList_t *)NULL, // DRB2_list, (struct LTE_SPS_Config *)NULL, // *sps_Config, (struct LTE_PhysicalConfigDedicated *)*physicalConfigDedicated, -#ifdef EXMIMO_IOT - NULL, NULL, NULL,NULL, -#else +//#ifdef EXMIMO_IOT +// NULL, NULL, NULL,NULL, +//#else (LTE_MeasObjectToAddModList_t *)MeasObj_list, (LTE_ReportConfigToAddModList_t *)ReportConfig_list, (LTE_QuantityConfig_t *)quantityConfig, (LTE_MeasIdToAddModList_t *)MeasId_list, -#endif +//#endif (LTE_MAC_MainConfig_t *)mac_MainConfig, (LTE_MeasGapConfig_t *)NULL, (LTE_MobilityControlInfo_t *)NULL, + (LTE_SecurityConfigHO_t *)NULL, (struct LTE_MeasConfig__speedStatePars *)Sparams, (LTE_RSRP_Range_t *)rsrp, (LTE_C_RNTI_t *)cba_RNTI, @@ -3736,6 +3738,7 @@ flexran_rrc_eNB_generate_defaultRRCConnectionReconfiguration(const protocol_ctxt (LTE_MAC_MainConfig_t *)mac_MainConfig, (LTE_MeasGapConfig_t *)NULL, (LTE_MobilityControlInfo_t *)NULL, + (LTE_SecurityConfigHO_t *)NULL, (struct LTE_MeasConfig__speedStatePars *)Sparams, (LTE_RSRP_Range_t *)rsrp, (LTE_C_RNTI_t *)cba_RNTI, @@ -3827,6 +3830,7 @@ rrc_eNB_generate_RRCConnectionReconfiguration_SCell( (LTE_MAC_MainConfig_t *)NULL, (LTE_MeasGapConfig_t *)NULL, (LTE_MobilityControlInfo_t *)NULL, + (LTE_SecurityConfigHO_t *)NULL, (struct LTE_MeasConfig__speedStatePars *)NULL, (LTE_RSRP_Range_t *)NULL, (LTE_C_RNTI_t *)NULL, @@ -3872,6 +3876,8 @@ rrc_eNB_process_MeasurementReport( { int i=0; int neighboring_cells=-1; + int ncell_index = 0; + long ncell_max = -150; T(T_ENB_RRC_MEASUREMENT_REPORT, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame), T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti)); @@ -3884,6 +3890,38 @@ rrc_eNB_process_MeasurementReport( } ue_context_pP->ue_context.measResults->measId=measResults2->measId; + + switch (measResults2->measId) { + case 1: + LOG_D(RRC,"Periodic report at frame %d and subframe %d \n", ctxt_pP->frame, ctxt_pP->subframe); + break; + + case 2: + LOG_D(RRC,"A1 event report (Serving becomes better than absolute threshold) at frame %d and subframe %d \n", ctxt_pP->frame, ctxt_pP->subframe); + break; + + case 3: + LOG_D(RRC,"A2 event report (Serving becomes worse than absolute threshold) at frame %d and subframe %d \n", ctxt_pP->frame, ctxt_pP->subframe); + break; + + case 4: + LOG_D(RRC,"A3 event report (Neighbour becomes amount of offset better than PCell) at frame %d and subframe %d \n", ctxt_pP->frame, ctxt_pP->subframe); + break; + + case 5: + LOG_D(RRC,"A4 event report (Neighbour becomes better than absolute threshold) at frame %d and subframe %d \n", ctxt_pP->frame, ctxt_pP->subframe); + break; + + case 6: + LOG_D(RRC,"A5 event report (PCell becomes worse than absolute threshold1 AND Neighbour becomes better than another absolute threshold2) at frame %d and subframe %d \n", ctxt_pP->frame, + ctxt_pP->subframe); + break; + + default: + LOG_D(RRC,"Other event report frame %d and subframe %d \n", ctxt_pP->frame, ctxt_pP->subframe); + break; + } + ue_context_pP->ue_context.measResults->measResultPCell.rsrpResult=measResults2->measResultPCell.rsrpResult; ue_context_pP->ue_context.measResults->measResultPCell.rsrqResult=measResults2->measResultPCell.rsrqResult; LOG_D(RRC, "[eNB %d]Frame %d: UE %x (Measurement Id %d): RSRP of Source %ld\n", ctxt_pP->module_id, ctxt_pP->frame, ctxt_pP->rnti, (int)measResults2->measId, @@ -3899,51 +3937,121 @@ rrc_eNB_process_MeasurementReport( neighboring_cells = measResults2->measResultNeighCells->choice.measResultListEUTRA.list.count; if (ue_context_pP->ue_context.measResults->measResultNeighCells == NULL) { - ue_context_pP->ue_context.measResults->measResultNeighCells = CALLOC(1, sizeof(*measResults2->measResultNeighCells)*neighboring_cells); + ue_context_pP->ue_context.measResults->measResultNeighCells = CALLOC(1, sizeof(*ue_context_pP->ue_context.measResults->measResultNeighCells)); } - ue_context_pP->ue_context.measResults->measResultNeighCells->choice.measResultListEUTRA.list.count = neighboring_cells; - for (i=0; i < neighboring_cells; i++) { - memcpy (ue_context_pP->ue_context.measResults->measResultNeighCells->choice.measResultListEUTRA.list.array[i], - measResults2->measResultNeighCells->choice.measResultListEUTRA.list.array[i], - sizeof(LTE_MeasResultListEUTRA_t)); + if (i>=ue_context_pP->ue_context.measResults->measResultNeighCells->choice.measResultListEUTRA.list.count) { + //printf("NeighCells number: %d \n", ue_context_pP->ue_context.measResults->measResultNeighCells->choice.measResultListEUTRA.list.count); + ASN_SEQUENCE_ADD(&ue_context_pP->ue_context.measResults->measResultNeighCells->choice.measResultListEUTRA.list,measResults2->measResultNeighCells->choice.measResultListEUTRA.list.array[i]); + } + + ue_context_pP->ue_context.measResults->measResultNeighCells->choice.measResultListEUTRA.list.array[i]->physCellId = + measResults2->measResultNeighCells->choice.measResultListEUTRA.list.array[i]->physCellId; + ue_context_pP->ue_context.measResults->measResultNeighCells->choice.measResultListEUTRA.list.array[i]->measResult.rsrpResult = + measResults2->measResultNeighCells->choice.measResultListEUTRA.list.array[i]->measResult.rsrpResult; + ue_context_pP->ue_context.measResults->measResultNeighCells->choice.measResultListEUTRA.list.array[i]->measResult.rsrqResult = + measResults2->measResultNeighCells->choice.measResultListEUTRA.list.array[i]->measResult.rsrqResult; LOG_D(RRC, "Physical Cell Id %d\n", (int)ue_context_pP->ue_context.measResults->measResultNeighCells->choice.measResultListEUTRA.list.array[i]->physCellId); - LOG_D(RRC, "RSRP of Target %d\n", - (int)*(ue_context_pP->ue_context.measResults->measResultNeighCells->choice.measResultListEUTRA.list.array[i]->measResult.rsrpResult)); - LOG_D(RRC, "RSRQ of Target %d\n", - (int)*(ue_context_pP->ue_context.measResults->measResultNeighCells->choice.measResultListEUTRA.list.array[i]->measResult.rsrqResult)); + LOG_D(RRC, "RSRP of Target %ld\n", + (*ue_context_pP->ue_context.measResults->measResultNeighCells->choice.measResultListEUTRA.list.array[i]->measResult.rsrpResult)-140); + LOG_D(RRC, "RSRQ of Target %ld\n", + (*ue_context_pP->ue_context.measResults->measResultNeighCells->choice.measResultListEUTRA.list.array[i]->measResult.rsrqResult)/2 - 20); + + if ( *measResults2->measResultNeighCells->choice.measResultListEUTRA.list.array[i]->measResult.rsrpResult >= ncell_max ) { + ncell_max = *measResults2->measResultNeighCells->choice.measResultListEUTRA.list.array[i]->measResult.rsrpResult; + ncell_index = i; + } + + //LOG_D(RRC, "Physical Cell Id2 %d\n", + //(int)measResults2->measResultNeighCells->choice.measResultListEUTRA.list.array[i]->physCellId); + //LOG_D(RRC, "RSRP of Target2 %ld\n", + //(*(measResults2->measResultNeighCells->choice.measResultListEUTRA.list.array[i]-> + //measResult.rsrpResult))-140); + //LOG_D(RRC, "RSRQ of Target2 %ld\n", + //(*(measResults2->measResultNeighCells->choice.measResultListEUTRA.list.array[i]-> + //measResult.rsrqResult))/2 - 20); } } - // #if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0)) - // #else - // LOG_I(RRC, "RSRP of Source %d\n", measResults2->measResultServCell.rsrpResult); - // LOG_I(RRC, "RSRQ of Source %d\n", measResults2->measResultServCell.rsrqResult); - // #endif - // if (ue_context_pP->ue_context.handover_info->ho_prepare != 0xF0) { - // rrc_eNB_generate_HandoverPreparationInformation(ctxt_pP, - // ue_context_pP, - // measResults2->measResultNeighCells->choice. - // measResultListEUTRA.list.array[0]->physCellId); - // } else { - // LOG_D(RRC, "[eNB %d] Frame %d: Ignoring MeasReport from UE %x as Handover is in progress... \n", ctxt_pP->module_id, ctxt_pP->frame, - // ctxt_pP->rnti); - // } - //Look for IP address of the target eNB - //Send Handover Request -> target eNB - //Wait for Handover Acknowledgement <- target eNB - //Send Handover Command - //x2delay(); - // handover_request_x2(ue_mod_idP,enb_mod_idP,measResults2->measResultNeighCells->choice.measResultListEUTRA.list.array[0]->physCellId); - // uint8_t buffer[100]; - // int size=rrc_eNB_generate_Handover_Command_TeNB(0,0,buffer); - // - // send_check_message((char*)buffer,size); - //send_handover_command(); + /* Decide whether to trigger HO or not */ + if (!(measResults2->measId == 4)) + return; + + LOG_D(RRC, "A3 event is triggered...\n"); + + /* if the UE is not in handover mode, start handover procedure */ + if (ue_context_pP->ue_context.Status != RRC_HO_EXECUTION) { + MessageDef *msg; + LOG_I(RRC, "Send HO preparation message at frame %d and subframe %d \n", ctxt_pP->frame, ctxt_pP->subframe); + /* HO info struct may not be needed anymore */ + ue_context_pP->ue_context.handover_info = CALLOC(1, sizeof(*(ue_context_pP->ue_context.handover_info))); + ue_context_pP->ue_context.Status = RRC_HO_EXECUTION; + ue_context_pP->ue_context.handover_info->state = HO_REQUEST; + /* HO Preparation message */ + msg = itti_alloc_new_message(TASK_RRC_ENB, X2AP_HANDOVER_REQ); + rrc_eNB_generate_HandoverPreparationInformation( + ue_context_pP, + X2AP_HANDOVER_REQ(msg).rrc_buffer, + &X2AP_HANDOVER_REQ(msg).rrc_buffer_size); + X2AP_HANDOVER_REQ(msg).source_rnti = ctxt_pP->rnti; + X2AP_HANDOVER_REQ(msg).old_eNB_ue_x2ap_id = 0; + X2AP_HANDOVER_REQ(msg).target_physCellId = measResults2->measResultNeighCells->choice. + measResultListEUTRA.list.array[ncell_index]->physCellId; + X2AP_HANDOVER_REQ(msg).ue_gummei.mcc = ue_context_pP->ue_context.ue_gummei.mcc; + X2AP_HANDOVER_REQ(msg).ue_gummei.mnc = ue_context_pP->ue_context.ue_gummei.mnc; + X2AP_HANDOVER_REQ(msg).ue_gummei.mnc_len = ue_context_pP->ue_context.ue_gummei.mnc_len; + X2AP_HANDOVER_REQ(msg).ue_gummei.mme_code = ue_context_pP->ue_context.ue_gummei.mme_code; + X2AP_HANDOVER_REQ(msg).ue_gummei.mme_group_id = ue_context_pP->ue_context.ue_gummei.mme_group_id; + // Don't know how to get this ID? + X2AP_HANDOVER_REQ(msg).mme_ue_s1ap_id = ue_context_pP->ue_context.mme_ue_s1ap_id; + X2AP_HANDOVER_REQ(msg).security_capabilities = ue_context_pP->ue_context.security_capabilities; + memcpy (X2AP_HANDOVER_REQ(msg).kenb, + ue_context_pP->ue_context.kenb, + 32); + X2AP_HANDOVER_REQ(msg).kenb_ncc = ue_context_pP->ue_context.kenb_ncc; + //X2AP_HANDOVER_REQ(msg).ue_ambr=ue_context_pP->ue_context.ue_ambr; + X2AP_HANDOVER_REQ(msg).nb_e_rabs_tobesetup = ue_context_pP->ue_context.setup_e_rabs; + + for (int i=0; i<ue_context_pP->ue_context.setup_e_rabs; i++) { + X2AP_HANDOVER_REQ(msg).e_rabs_tobesetup[i].e_rab_id = ue_context_pP->ue_context.e_rab[i].param.e_rab_id; + X2AP_HANDOVER_REQ(msg).e_rabs_tobesetup[i].eNB_addr = ue_context_pP->ue_context.e_rab[i].param.sgw_addr; + X2AP_HANDOVER_REQ(msg).e_rabs_tobesetup[i].gtp_teid = ue_context_pP->ue_context.e_rab[i].param.gtp_teid; + X2AP_HANDOVER_REQ(msg).e_rab_param[i].qos.qci = ue_context_pP->ue_context.e_rab[i].param.qos.qci; + X2AP_HANDOVER_REQ(msg).e_rab_param[i].qos.allocation_retention_priority.priority_level = ue_context_pP->ue_context.e_rab[i].param.qos.allocation_retention_priority.priority_level; + X2AP_HANDOVER_REQ(msg).e_rab_param[i].qos.allocation_retention_priority.pre_emp_capability = ue_context_pP->ue_context.e_rab[i].param.qos.allocation_retention_priority.pre_emp_capability; + X2AP_HANDOVER_REQ(msg).e_rab_param[i].qos.allocation_retention_priority.pre_emp_vulnerability = ue_context_pP->ue_context.e_rab[i].param.qos.allocation_retention_priority.pre_emp_vulnerability; + } + + /* TODO: don't do that, X2AP should find the target by itself */ + //X2AP_HANDOVER_REQ(msg).target_mod_id = 0; + LOG_I(RRC, + "[eNB %d] Frame %d: potential handover preparation: store the information in an intermediate structure in case of failure\n", + ctxt_pP->module_id, ctxt_pP->frame); + itti_send_msg_to_task(TASK_X2AP, ENB_MODULE_ID_TO_INSTANCE(ctxt_pP->module_id), msg); + } else { + LOG_D(RRC, "[eNB %d] Frame %d: Ignoring MeasReport from UE %x as Handover is in progress... \n", ctxt_pP->module_id, ctxt_pP->frame, + ctxt_pP->rnti); + } +} + +//----------------------------------------------------------------------------- +void +rrc_eNB_generate_HandoverPreparationInformation( + //const protocol_ctxt_t* const ctxt_pP, + rrc_eNB_ue_context_t *const ue_context_pP, + uint8_t *buffer, + int *_size +) { + memset(buffer, 0, RRC_BUF_SIZE); + char *ho_buf = (char *) buffer; + int ho_size; + ho_size = do_HandoverPreparation(ho_buf, 1024, ue_context_pP->ue_context.UE_Capability, ue_context_pP->ue_context.UE_Capability_size); + *_size = ho_size; } +#if 0 //----------------------------------------------------------------------------- void rrc_eNB_generate_HandoverPreparationInformation( @@ -3992,138 +4100,1337 @@ rrc_eNB_generate_HandoverPreparationInformation( ue_context_pP->ue_context.handover_info->ho_prepare = 0xFF; //0xF0; ue_context_pP->ue_context.handover_info->ho_complete = 0; - if (mod_id_target != 0xFF) { - //UE_id_target = rrc_find_free_ue_index(modid_target); - ue_context_target_p = - rrc_eNB_get_ue_context( - RC.rrc[mod_id_target], - ue_context_pP->ue_context.rnti); + if (mod_id_target != 0xFF) { + //UE_id_target = rrc_find_free_ue_index(modid_target); + ue_context_target_p = + rrc_eNB_get_ue_context( + RC.rrc[mod_id_target], + ue_context_pP->ue_context.rnti); + + /*UE_id_target = rrc_eNB_get_next_free_UE_index( + mod_id_target, + RC.rrc[ctxt_pP->module_id]->Info.UE_list[ue_mod_idP]); //this should return a new index*/ + + if (ue_context_target_p == NULL) { // if not already in target cell + ue_context_target_p = rrc_eNB_allocate_new_UE_context(RC.rrc[ctxt_pP->module_id]); + ue_context_target_p->ue_id_rnti = ue_context_pP->ue_context.rnti; // LG: should not be the same + ue_context_target_p->ue_context.rnti = ue_context_target_p->ue_id_rnti; // idem + LOG_I(RRC, + "[eNB %d] Frame %d : Emulate sending HandoverPreparationInformation msg from eNB source %d to eNB target %ld: source UE_id %x target UE_id %x source_modId: %d target_modId: %d\n", + ctxt_pP->module_id, + ctxt_pP->frame, + RC.rrc[ctxt_pP->module_id]->carrier[0] /* CROUX TBC */.physCellId, + targetPhyId, + ue_context_pP->ue_context.rnti, + ue_context_target_p->ue_id_rnti, + ctxt_pP->module_id, + mod_id_target); + ue_context_target_p->ue_context.handover_info = + CALLOC(1, sizeof(*(ue_context_target_p->ue_context.handover_info))); + memcpy((void *)&ue_context_target_p->ue_context.handover_info->as_context, + (void *)&ue_context_pP->ue_context.handover_info->as_context, + sizeof(LTE_AS_Context_t)); + memcpy((void *)&ue_context_target_p->ue_context.handover_info->as_config, + (void *)&ue_context_pP->ue_context.handover_info->as_config, + sizeof(LTE_AS_Config_t)); + ue_context_target_p->ue_context.handover_info->ho_prepare = 0x00;// 0xFF; + ue_context_target_p->ue_context.handover_info->ho_complete = 0; + ue_context_pP->ue_context.handover_info->modid_t = mod_id_target; + ue_context_pP->ue_context.handover_info->ueid_s = ue_context_pP->ue_context.rnti; + ue_context_pP->ue_context.handover_info->modid_s = ctxt_pP->module_id; + ue_context_target_p->ue_context.handover_info->modid_t = mod_id_target; + ue_context_target_p->ue_context.handover_info->modid_s = ctxt_pP->module_id; + ue_context_target_p->ue_context.handover_info->ueid_t = ue_context_target_p->ue_context.rnti; + } else { + LOG_E(RRC, "\nError in obtaining free UE id in target eNB %ld for handover \n", targetPhyId); + } + } else { + LOG_E(RRC, "\nError in obtaining Module ID of target eNB for handover \n"); + } +} +#endif + +void rrc_eNB_process_handoverPreparationInformation(int mod_id, x2ap_handover_req_t *m) { + struct rrc_eNB_ue_context_s *ue_context_target_p = NULL; + /* TODO: get proper UE rnti */ + int rnti = taus() & 0xffff; + int i; + //global_rnti = rnti; + //HandoverPreparationInformation_t *ho = NULL; + //HandoverPreparationInformation_r8_IEs_t *ho_info; + //asn_dec_rval_t dec_rval; + ue_context_target_p = rrc_eNB_get_ue_context(RC.rrc[mod_id], rnti); + + if (ue_context_target_p != NULL) { + LOG_E(RRC, "\nError in obtaining free UE id in target eNB for handover \n"); + return; + } + + ue_context_target_p = rrc_eNB_allocate_new_UE_context(RC.rrc[mod_id]); + + if (ue_context_target_p == NULL) { + LOG_E(RRC, "Cannot create new UE context\n"); + return; + } + + ue_context_target_p->ue_id_rnti = rnti; + ue_context_target_p->ue_context.rnti = rnti; + RB_INSERT(rrc_ue_tree_s, &RC.rrc[mod_id]->rrc_ue_head, ue_context_target_p); + LOG_D(RRC, "eNB %d: Created new UE context uid %u\n", mod_id, ue_context_target_p->local_uid); + ue_context_target_p->ue_context.handover_info = CALLOC(1, sizeof(*(ue_context_target_p->ue_context.handover_info))); + //ue_context_target_p->ue_context.handover_info->source_x2id = m->source_x2id; + ue_context_target_p->ue_context.Status = RRC_HO_EXECUTION; + ue_context_target_p->ue_context.handover_info->state = HO_ACK; + /* TODO: remove this hack */ + //ue_context_target_p->ue_context.handover_info->modid_t = mod_id; + ue_context_target_p->ue_context.handover_info->modid_t = m->target_mod_id; + //ue_context_target_p->ue_context.handover_info->modid_s = 1-mod_id; + //ue_context_target_p->ue_context.handover_info->ueid_s = m->source_rnti; + memset (ue_context_target_p->ue_context.nh, 0, 32); + ue_context_target_p->ue_context.nh_ncc = -1; + memcpy (ue_context_target_p->ue_context.kenb, m->kenb, 32); + ue_context_target_p->ue_context.kenb_ncc = m->kenb_ncc; + ue_context_target_p->ue_context.security_capabilities.encryption_algorithms = m->security_capabilities.encryption_algorithms; + ue_context_target_p->ue_context.security_capabilities.integrity_algorithms = m->security_capabilities.integrity_algorithms; + /* + dec_rval = uper_decode(NULL, + &asn_DEF_HandoverPreparationInformation, + (void **)&ho, + m->rrc_buffer, + m->rrc_buffer_size, 0, 0); + + if (dec_rval.code != RC_OK || + ho->criticalExtensions.present != HandoverPreparationInformation__criticalExtensions_PR_c1 || + ho->criticalExtensions.choice.c1.present != HandoverPreparationInformation__criticalExtensions__c1_PR_handoverPreparationInformation_r8) { + LOG_E(RRC, "could not decode Handover Preparation\n"); + abort(); + } + + ho_info = &ho->criticalExtensions.choice.c1.choice.handoverPreparationInformation_r8; + + if (ue_context_target_p->ue_context.UE_Capability) { + LOG_I(RRC, "freeing old UE capabilities for UE %x\n", rnti); + ASN_STRUCT_FREE(asn_DEF_UE_EUTRA_Capability, + ue_context_target_p->ue_context.UE_Capability); + ue_context_target_p->ue_context.UE_Capability = 0; + } + + dec_rval = uper_decode(NULL, + &asn_DEF_UE_EUTRA_Capability, + (void **)&ue_context_target_p->ue_context.UE_Capability, + ho_info->ue_RadioAccessCapabilityInfo.list.array[0]->ueCapabilityRAT_Container.buf, + ho_info->ue_RadioAccessCapabilityInfo.list.array[0]->ueCapabilityRAT_Container.size, 0, 0); + + ue_context_target_p->ue_context.UE_Capability_size = ho_info->ue_RadioAccessCapabilityInfo.list.array[0]->ueCapabilityRAT_Container.size; + + if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) { + xer_fprint(stdout, &asn_DEF_UE_EUTRA_Capability, ue_context_target_p->ue_context.UE_Capability); + } + + if ((dec_rval.code != RC_OK) && (dec_rval.consumed == 0)) { + LOG_E(RRC, "Failed to decode UE capabilities (%zu bytes)\n", dec_rval.consumed); + ASN_STRUCT_FREE(asn_DEF_UE_EUTRA_Capability, + ue_context_target_p->ue_context.UE_Capability); + ue_context_target_p->ue_context.UE_Capability = 0; + } + */ + ue_context_target_p->ue_context.nb_of_e_rabs = m->nb_e_rabs_tobesetup; + ue_context_target_p->ue_context.setup_e_rabs = m->nb_e_rabs_tobesetup; + ue_context_target_p->ue_context.mme_ue_s1ap_id = m->mme_ue_s1ap_id; + ue_context_target_p->ue_context.ue_gummei.mcc = m->ue_gummei.mcc; + ue_context_target_p->ue_context.ue_gummei.mnc = m->ue_gummei.mnc; + ue_context_target_p->ue_context.ue_gummei.mnc_len = m->ue_gummei.mnc_len; + ue_context_target_p->ue_context.ue_gummei.mme_code = m->ue_gummei.mme_code; + ue_context_target_p->ue_context.ue_gummei.mme_group_id = m->ue_gummei.mme_group_id; + LOG_I(RRC, "eNB %d: Update the E-RABS %u\n", mod_id, ue_context_target_p->ue_context.nb_of_e_rabs); + + for (i = 0; i < ue_context_target_p->ue_context.nb_of_e_rabs; i++) { + ue_context_target_p->ue_context.e_rab[i].status = E_RAB_STATUS_NEW; + ue_context_target_p->ue_context.e_rab[i].param.e_rab_id = m->e_rabs_tobesetup[i].e_rab_id; + ue_context_target_p->ue_context.e_rab[i].param.sgw_addr = m->e_rabs_tobesetup[i].eNB_addr; + ue_context_target_p->ue_context.e_rab[i].param.gtp_teid= m->e_rabs_tobesetup[i].gtp_teid; + LOG_I(RRC, "eNB %d: Update the UE context after HO, e_rab_id %u gtp_teid %u\n", mod_id, + ue_context_target_p->ue_context.e_rab[i].param.e_rab_id, + ue_context_target_p->ue_context.e_rab[i].param.gtp_teid); + } +} + +void rrc_eNB_process_handoverCommand( + int mod_id, + struct rrc_eNB_ue_context_s *ue_context, + x2ap_handover_req_ack_t *m) { + asn_dec_rval_t dec_rval; + LTE_HandoverCommand_t *ho = NULL; + dec_rval = uper_decode( + NULL, + &asn_DEF_LTE_HandoverCommand, + (void **)&ho, + m->rrc_buffer, + m->rrc_buffer_size, + 0, + 0); + + if (dec_rval.code != RC_OK || + ho->criticalExtensions.present != LTE_HandoverCommand__criticalExtensions_PR_c1 || + ho->criticalExtensions.choice.c1.present != LTE_HandoverCommand__criticalExtensions__c1_PR_handoverCommand_r8) { + LOG_E(RRC, "could not decode Handover Command\n"); + abort(); + } + + unsigned char *buf = ho->criticalExtensions.choice.c1.choice.handoverCommand_r8.handoverCommandMessage.buf; + int size = ho->criticalExtensions.choice.c1.choice.handoverCommand_r8.handoverCommandMessage.size; + + if (size > RRC_BUF_SIZE) { + printf("%s:%d: fatal\n", __FILE__, __LINE__); + abort(); + } + + memcpy(ue_context->ue_context.handover_info->buf, buf, size); + ue_context->ue_context.handover_info->size = size; +} + +#if 0 +//----------------------------------------------------------------------------- +void +rrc_eNB_process_handoverPreparationInformation( + const protocol_ctxt_t *const ctxt_pP, + rrc_eNB_ue_context_t *const ue_context_pP +) +//----------------------------------------------------------------------------- +{ + T(T_ENB_RRC_HANDOVER_PREPARATION_INFORMATION, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame), + T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti)); + LOG_I(RRC, + "[eNB %d] Frame %d : Logical Channel UL-DCCH, processing RRCHandoverPreparationInformation, sending LTE_RRCConnectionReconfiguration to UE %d \n", + ctxt_pP->module_id, ctxt_pP->frame, ue_context_pP->ue_context.rnti); + rrc_eNB_generate_RRCConnectionReconfiguration_handover( + ctxt_pP, + ue_context_pP, + NULL, + 0); +} +#endif + +void +check_handovers( + protocol_ctxt_t *const ctxt_pP +) +//----------------------------------------------------------------------------- +{ + int result; + struct rrc_eNB_ue_context_s *ue_context_p; + RB_FOREACH(ue_context_p, rrc_ue_tree_s, &(RC.rrc[ctxt_pP->module_id]->rrc_ue_head)) { + ctxt_pP->rnti = ue_context_p->ue_id_rnti; + + if (ue_context_p->ue_context.Status == RRC_HO_EXECUTION && ue_context_p->ue_context.handover_info != NULL) { + /* in the source, UE in HO_PREPARE mode */ + if (ue_context_p->ue_context.handover_info->state == HO_PREPARE) { + LOG_D(RRC, + "[eNB %d] Frame %d: Incoming handover detected for new UE_id %x) \n", + ctxt_pP->module_id, + ctxt_pP->frame, + ctxt_pP->rnti); + // source eNB generates rrcconnectionreconfiguration to prepare the HO + LOG_I(RRC, + "[eNB %d] Frame %d : Logical Channel UL-DCCH, processing RRCHandoverPreparationInformation, sending RRCConnectionReconfiguration to UE %d \n", + ctxt_pP->module_id, ctxt_pP->frame, ue_context_p->ue_context.rnti); + result = pdcp_data_req(ctxt_pP, + SRB_FLAG_YES, + DCCH, + rrc_eNB_mui++, + SDU_CONFIRM_NO, + ue_context_p->ue_context.handover_info->size, + ue_context_p->ue_context.handover_info->buf, + PDCP_TRANSMISSION_MODE_CONTROL +#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0)) + ,NULL, NULL +#endif + ); + AssertFatal(result == TRUE, "PDCP data request failed!\n"); + ue_context_p->ue_context.handover_info->state = HO_COMPLETE; + LOG_I(RRC, "RRC Sends RRCConnectionReconfiguration to UE %d at frame %d and subframe %d \n", ue_context_p->ue_context.rnti, ctxt_pP->frame,ctxt_pP->subframe); + } + + /* in the target, UE in HO_ACK mode */ + if (ue_context_p->ue_context.handover_info->state == HO_ACK) { + MessageDef *msg; + // Configure target + ue_context_p->ue_context.handover_info->state = HO_CONFIGURED; + msg = itti_alloc_new_message(TASK_RRC_ENB, X2AP_HANDOVER_REQ_ACK); + rrc_eNB_generate_HO_RRCConnectionReconfiguration(ctxt_pP, ue_context_p, X2AP_HANDOVER_REQ_ACK(msg).rrc_buffer, + &X2AP_HANDOVER_REQ_ACK(msg).rrc_buffer_size); + rrc_eNB_configure_rbs_handover(ue_context_p,ctxt_pP); + /* TODO: remove this hack */ + //X2AP_HANDOVER_REQ_ACK(msg).target_mod_id = 1 - ctxt_pP->module_id; + X2AP_HANDOVER_REQ_ACK(msg).target_mod_id = ue_context_p->ue_context.handover_info->modid_t; + //X2AP_HANDOVER_REQ_ACK(msg).source_x2id = ue_context_p->ue_context.handover_info->source_x2id; + /* Call admission control not implemented yet */ + X2AP_HANDOVER_REQ_ACK(msg).nb_e_rabs_tobesetup = ue_context_p->ue_context.setup_e_rabs; + + for (int i=0; i<ue_context_p->ue_context.setup_e_rabs; i++) { + X2AP_HANDOVER_REQ_ACK(msg).e_rabs_tobesetup[i].e_rab_id = ue_context_p->ue_context.e_rab[i].param.e_rab_id; + } + + itti_send_msg_to_task(TASK_X2AP, ENB_MODULE_ID_TO_INSTANCE(ctxt_pP->module_id), msg); + LOG_I(RRC, "RRC Sends X2 HO ACK to the source eNB at frame %d and subframe %d \n", ctxt_pP->frame,ctxt_pP->subframe); + } + } + } +} + +#if 0 +//----------------------------------------------------------------------------- +void +check_handovers( + protocol_ctxt_t *const ctxt_pP +) +//----------------------------------------------------------------------------- +{ + int result; + struct rrc_eNB_ue_context_s *ue_context_p; + RB_FOREACH(ue_context_p, rrc_ue_tree_s, &RC.rrc[ctxt_pP->module_id]->rrc_ue_head) { + ctxt_pP->rnti = ue_context_p->ue_id_rnti; + + if (ue_context_p->ue_context.handover_info != NULL) { + if (ue_context_p->ue_context.handover_info->ho_prepare == 0xFF) { + LOG_D(RRC, + "[eNB %d] Frame %d: Incoming handover detected for new UE_idx %d (source eNB %d->target eNB %d) \n", + ctxt_pP->module_id, + ctxt_pP->frame, + ctxt_pP->rnti, + ctxt_pP->module_id, + ue_context_p->ue_context.handover_info->modid_t); + // source eNB generates LTE_RRCConnectionreconfiguration to prepare the HO + rrc_eNB_process_handoverPreparationInformation( + ctxt_pP, + ue_context_p); + ue_context_p->ue_context.handover_info->ho_prepare = 0xF1; + } + + if (ue_context_p->ue_context.handover_info->ho_complete == 0xF1) { + LOG_D(RRC, + "[eNB %d] Frame %d: handover Command received for new UE_id %x current eNB %d target eNB: %d \n", + ctxt_pP->module_id, + ctxt_pP->frame, + ctxt_pP->rnti, + ctxt_pP->module_id, + ue_context_p->ue_context.handover_info->modid_t); + //rrc_eNB_process_handoverPreparationInformation(enb_mod_idP,frameP,i); + result = pdcp_data_req(ctxt_pP, + SRB_FLAG_YES, + DCCH, + rrc_eNB_mui++, + SDU_CONFIRM_NO, + ue_context_p->ue_context.handover_info->size, + ue_context_p->ue_context.handover_info->buf, + PDCP_TRANSMISSION_MODE_CONTROL +#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0)) + ,NULL, NULL +#endif + ); + + //AssertFatal(result == TRUE, "PDCP data request failed!\n"); + if(result != TRUE) { + LOG_I(RRC, "PDCP data request failed!\n"); + return; + } + + ue_context_p->ue_context.handover_info->ho_complete = 0xF2; + } + } + } +} +#endif + +void +rrc_eNB_generate_HO_RRCConnectionReconfiguration(const protocol_ctxt_t *const ctxt_pP, + rrc_eNB_ue_context_t *const ue_context_pP, + uint8_t *buffer, + int *_size + //const uint8_t ho_state + ) +//----------------------------------------------------------------------------- +{ + uint16_t size; + int i; + uint8_t rv[2]; + // configure SRB1/SRB2, PhysicalConfigDedicated, MAC_MainConfig for UE + eNB_RRC_INST *rrc_inst = RC.rrc[ctxt_pP->module_id]; + struct LTE_PhysicalConfigDedicated **physicalConfigDedicated = &ue_context_pP->ue_context.physicalConfigDedicated; + // phy config dedicated + LTE_PhysicalConfigDedicated_t *physicalConfigDedicated2; + // srb 1: for HO + struct LTE_SRB_ToAddMod *SRB1_config = NULL; + struct LTE_SRB_ToAddMod__rlc_Config *SRB1_rlc_config = NULL; + struct LTE_SRB_ToAddMod__logicalChannelConfig *SRB1_lchan_config = NULL; + struct LTE_LogicalChannelConfig__ul_SpecificParameters + *SRB1_ul_SpecificParameters = NULL; + struct LTE_SRB_ToAddMod *SRB2_config = NULL; + struct LTE_SRB_ToAddMod__rlc_Config *SRB2_rlc_config = NULL; + struct LTE_SRB_ToAddMod__logicalChannelConfig *SRB2_lchan_config = NULL; + struct LTE_LogicalChannelConfig__ul_SpecificParameters + *SRB2_ul_SpecificParameters = NULL; + LTE_SRB_ToAddModList_t *SRB_configList = ue_context_pP->ue_context.SRB_configList; + LTE_SRB_ToAddModList_t **SRB_configList2 = NULL; + struct LTE_DRB_ToAddMod *DRB_config = NULL; + struct LTE_RLC_Config *DRB_rlc_config = NULL; + struct LTE_PDCP_Config *DRB_pdcp_config = NULL; + struct LTE_PDCP_Config__rlc_AM *PDCP_rlc_AM = NULL; + struct LTE_PDCP_Config__rlc_UM *PDCP_rlc_UM = NULL; + struct LTE_LogicalChannelConfig *DRB_lchan_config = NULL; + struct LTE_LogicalChannelConfig__ul_SpecificParameters + *DRB_ul_SpecificParameters = NULL; + LTE_DRB_ToAddModList_t **DRB_configList = &ue_context_pP->ue_context.DRB_configList; + LTE_DRB_ToAddModList_t **DRB_configList2 = NULL; + LTE_MAC_MainConfig_t *mac_MainConfig = NULL; + LTE_MeasObjectToAddModList_t *MeasObj_list = NULL; + LTE_MeasObjectToAddMod_t *MeasObj = NULL; + LTE_ReportConfigToAddModList_t *ReportConfig_list = NULL; + LTE_ReportConfigToAddMod_t *ReportConfig_per, *ReportConfig_A1, + *ReportConfig_A2, *ReportConfig_A3, *ReportConfig_A4, *ReportConfig_A5; + LTE_MeasIdToAddModList_t *MeasId_list = NULL; + LTE_MeasIdToAddMod_t *MeasId0, *MeasId1, *MeasId2, *MeasId3, *MeasId4, *MeasId5; +#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0)) + long *sr_ProhibitTimer_r9 = NULL; + // uint8_t sCellIndexToAdd = rrc_find_free_SCell_index(enb_mod_idP, ue_mod_idP, 1); + //uint8_t sCellIndexToAdd = 0; +#endif + long *logicalchannelgroup, *logicalchannelgroup_drb; + long *maxHARQ_Tx, *periodicBSR_Timer; + LTE_RSRP_Range_t *rsrp = NULL; + struct LTE_MeasConfig__speedStatePars *Sparams = NULL; + LTE_QuantityConfig_t *quantityConfig = NULL; + LTE_MobilityControlInfo_t *mobilityInfo = NULL; + LTE_SecurityConfigHO_t *securityConfigHO = NULL; + //CellsToAddMod_t *CellToAdd = NULL; + //CellsToAddModList_t *CellsToAddModList = NULL; + struct LTE_RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList *dedicatedInfoNASList = NULL; + LTE_DedicatedInfoNAS_t *dedicatedInfoNas = NULL; + /* for no gcc warnings */ + (void)dedicatedInfoNas; + LTE_C_RNTI_t *cba_RNTI = NULL; + uint8_t xid = rrc_eNB_get_next_transaction_identifier(ctxt_pP->module_id); //Transaction_id, +#ifdef CBA + //struct PUSCH_CBAConfigDedicated_vlola *pusch_CBAConfigDedicated_vlola; + uint8_t *cba_RNTI_buf; + cba_RNTI = CALLOC(1, sizeof(C_RNTI_t)); + cba_RNTI_buf = CALLOC(1, 2 * sizeof(uint8_t)); + cba_RNTI->buf = cba_RNTI_buf; + cba_RNTI->size = 2; + cba_RNTI->bits_unused = 0; + + // associate UEs to the CBa groups as a function of their UE id + if (rrc_inst->num_active_cba_groups) { + cba_RNTI->buf[0] = rrc_inst->cba_rnti[ue_mod_idP % rrc_inst->num_active_cba_groups] & 0xff; + cba_RNTI->buf[1] = 0xff; + LOG_D(RRC, + "[eNB %d] Frame %d: cba_RNTI = %x in group %d is attribued to UE %d\n", + enb_mod_idP, frameP, + rrc_inst->cba_rnti[ue_mod_idP % rrc_inst->num_active_cba_groups], + ue_mod_idP % rrc_inst->num_active_cba_groups, ue_mod_idP); + } else { + cba_RNTI->buf[0] = 0x0; + cba_RNTI->buf[1] = 0x0; + LOG_D(RRC, "[eNB %d] Frame %d: no cba_RNTI is configured for UE %d\n", enb_mod_idP, frameP, ue_mod_idP); + } + +#endif + T(T_ENB_RRC_CONNECTION_RECONFIGURATION, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame), + T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti)); + rv[0] = (ue_context_pP->ue_context.rnti >> 8) & 255; + rv[1] = ue_context_pP->ue_context.rnti & 255; + LOG_I(RRC, "target UE rnti = %x (decimal: %d)\n", ue_context_pP->ue_context.rnti, ue_context_pP->ue_context.rnti); + LOG_D(RRC, "[eNB %d] Frame %d : handover preparation: add target eNB SRB1 and PHYConfigDedicated reconfiguration\n", + ctxt_pP->module_id, ctxt_pP->frame); + + if (SRB_configList) { + free(SRB_configList); + } + + SRB_configList = CALLOC(1, sizeof(*SRB_configList)); + memset(SRB_configList, 0, sizeof(*SRB_configList)); + SRB1_config = CALLOC(1, sizeof(*SRB1_config)); + SRB1_config->srb_Identity = 1; + SRB1_rlc_config = CALLOC(1, sizeof(*SRB1_rlc_config)); + SRB1_config->rlc_Config = SRB1_rlc_config; + SRB1_rlc_config->present = LTE_SRB_ToAddMod__rlc_Config_PR_explicitValue; + SRB1_rlc_config->choice.explicitValue.present = LTE_RLC_Config_PR_am; + SRB1_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.t_PollRetransmit = LTE_T_PollRetransmit_ms15; + SRB1_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.pollPDU = LTE_PollPDU_p8; + SRB1_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.pollByte = LTE_PollByte_kB1000; + SRB1_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.maxRetxThreshold = LTE_UL_AM_RLC__maxRetxThreshold_t16; + SRB1_rlc_config->choice.explicitValue.choice.am.dl_AM_RLC.t_Reordering = LTE_T_Reordering_ms35; + SRB1_rlc_config->choice.explicitValue.choice.am.dl_AM_RLC.t_StatusProhibit = LTE_T_StatusProhibit_ms10; + SRB1_lchan_config = CALLOC(1, sizeof(*SRB1_lchan_config)); + SRB1_config->logicalChannelConfig = SRB1_lchan_config; + SRB1_lchan_config->present = LTE_SRB_ToAddMod__logicalChannelConfig_PR_explicitValue; + SRB1_ul_SpecificParameters = CALLOC(1, sizeof(*SRB1_ul_SpecificParameters)); + SRB1_lchan_config->choice.explicitValue.ul_SpecificParameters = SRB1_ul_SpecificParameters; + SRB1_ul_SpecificParameters->priority = 1; + //assign_enum(&SRB1_ul_SpecificParameters->prioritisedBitRate,LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_infinity); + SRB1_ul_SpecificParameters->prioritisedBitRate = + LTE_LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_infinity; + //assign_enum(&SRB1_ul_SpecificParameters->bucketSizeDuration,LogicalChannelConfig__ul_SpecificParameters__bucketSizeDuration_ms50); + SRB1_ul_SpecificParameters->bucketSizeDuration = + LTE_LogicalChannelConfig__ul_SpecificParameters__bucketSizeDuration_ms50; + logicalchannelgroup = CALLOC(1, sizeof(long)); + *logicalchannelgroup = 0; + SRB1_ul_SpecificParameters->logicalChannelGroup = logicalchannelgroup; + ASN_SEQUENCE_ADD(&SRB_configList->list, SRB1_config); + ue_context_pP->ue_context.SRB_configList = SRB_configList; + // Configure SRB2 + /// SRB2 + SRB_configList2=&ue_context_pP->ue_context.SRB_configList2[xid]; + + if (*SRB_configList2) { + free(*SRB_configList2); + } + + *SRB_configList2 = CALLOC(1, sizeof(**SRB_configList2)); + memset(*SRB_configList2, 0, sizeof(**SRB_configList2)); + SRB2_config = CALLOC(1, sizeof(*SRB2_config)); + SRB2_config->srb_Identity = 2; + SRB2_rlc_config = CALLOC(1, sizeof(*SRB2_rlc_config)); + SRB2_config->rlc_Config = SRB2_rlc_config; + SRB2_rlc_config->present = LTE_SRB_ToAddMod__rlc_Config_PR_explicitValue; + SRB2_rlc_config->choice.explicitValue.present = LTE_RLC_Config_PR_am; + SRB2_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.t_PollRetransmit = LTE_T_PollRetransmit_ms15; + SRB2_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.pollPDU = LTE_PollPDU_p8; + SRB2_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.pollByte = LTE_PollByte_kB1000; + SRB2_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.maxRetxThreshold = LTE_UL_AM_RLC__maxRetxThreshold_t32; + SRB2_rlc_config->choice.explicitValue.choice.am.dl_AM_RLC.t_Reordering = LTE_T_Reordering_ms35; + SRB2_rlc_config->choice.explicitValue.choice.am.dl_AM_RLC.t_StatusProhibit = LTE_T_StatusProhibit_ms10; + SRB2_lchan_config = CALLOC(1, sizeof(*SRB2_lchan_config)); + SRB2_config->logicalChannelConfig = SRB2_lchan_config; + SRB2_lchan_config->present = LTE_SRB_ToAddMod__logicalChannelConfig_PR_explicitValue; + SRB2_ul_SpecificParameters = CALLOC(1, sizeof(*SRB2_ul_SpecificParameters)); + SRB2_ul_SpecificParameters->priority = 3; // let some priority for SRB1 and dedicated DRBs + SRB2_ul_SpecificParameters->prioritisedBitRate = + LTE_LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_infinity; + SRB2_ul_SpecificParameters->bucketSizeDuration = + LTE_LogicalChannelConfig__ul_SpecificParameters__bucketSizeDuration_ms50; + // LCG for CCCH and DCCH is 0 as defined in 36331 + logicalchannelgroup = CALLOC(1, sizeof(long)); + *logicalchannelgroup = 0; + SRB2_ul_SpecificParameters->logicalChannelGroup = logicalchannelgroup; + SRB2_lchan_config->choice.explicitValue.ul_SpecificParameters = SRB2_ul_SpecificParameters; + // this list has the configuration for SRB1 and SRB2 + ASN_SEQUENCE_ADD(&SRB_configList->list, SRB2_config); + // this list has only the configuration for SRB2 + ASN_SEQUENCE_ADD(&(*SRB_configList2)->list, SRB2_config); + + // Configure DRB + //*DRB_configList = CALLOC(1, sizeof(*DRB_configList)); + // list for all the configured DRB + if (*DRB_configList) { + free(*DRB_configList); + } + + *DRB_configList = CALLOC(1, sizeof(**DRB_configList)); + memset(*DRB_configList, 0, sizeof(**DRB_configList)); + // list for the configured DRB for a this xid + DRB_configList2=&ue_context_pP->ue_context.DRB_configList2[xid]; + + if (*DRB_configList2) { + free(*DRB_configList2); + } + + *DRB_configList2 = CALLOC(1, sizeof(**DRB_configList2)); + memset(*DRB_configList2, 0, sizeof(**DRB_configList2)); + /// DRB + DRB_config = CALLOC(1, sizeof(*DRB_config)); + DRB_config->eps_BearerIdentity = CALLOC(1, sizeof(long)); + *(DRB_config->eps_BearerIdentity) = 5L; // LW set to first value, allowed value 5..15, value : x+4 + // DRB_config->drb_Identity = (DRB_Identity_t) 1; //allowed values 1..32 + // NN: this is the 1st DRB for this ue, so set it to 1 + DRB_config->drb_Identity = (LTE_DRB_Identity_t) 1; // (ue_mod_idP+1); //allowed values 1..32, value: x + DRB_config->logicalChannelIdentity = CALLOC(1, sizeof(long)); + *(DRB_config->logicalChannelIdentity) = (long)3; // value : x+2 + DRB_rlc_config = CALLOC(1, sizeof(*DRB_rlc_config)); + DRB_config->rlc_Config = DRB_rlc_config; +#ifdef RRC_DEFAULT_RAB_IS_AM + DRB_rlc_config->present = RLC_Config_PR_am; + DRB_rlc_config->choice.am.ul_AM_RLC.t_PollRetransmit = T_PollRetransmit_ms50; + DRB_rlc_config->choice.am.ul_AM_RLC.pollPDU = PollPDU_p16; + DRB_rlc_config->choice.am.ul_AM_RLC.pollByte = PollByte_kBinfinity; + DRB_rlc_config->choice.am.ul_AM_RLC.maxRetxThreshold = UL_AM_RLC__maxRetxThreshold_t8; + DRB_rlc_config->choice.am.dl_AM_RLC.t_Reordering = T_Reordering_ms35; + DRB_rlc_config->choice.am.dl_AM_RLC.t_StatusProhibit = T_StatusProhibit_ms25; +#else + DRB_rlc_config->present = LTE_RLC_Config_PR_um_Bi_Directional; + DRB_rlc_config->choice.um_Bi_Directional.ul_UM_RLC.sn_FieldLength = LTE_SN_FieldLength_size10; + DRB_rlc_config->choice.um_Bi_Directional.dl_UM_RLC.sn_FieldLength = LTE_SN_FieldLength_size10; +#ifdef CBA + DRB_rlc_config->choice.um_Bi_Directional.dl_UM_RLC.t_Reordering = LTE_T_Reordering_ms5;//T_Reordering_ms25; +#else + DRB_rlc_config->choice.um_Bi_Directional.dl_UM_RLC.t_Reordering = LTE_T_Reordering_ms35; +#endif +#endif + DRB_pdcp_config = CALLOC(1, sizeof(*DRB_pdcp_config)); + DRB_config->pdcp_Config = DRB_pdcp_config; + DRB_pdcp_config->discardTimer = CALLOC(1, sizeof(long)); + *DRB_pdcp_config->discardTimer = LTE_PDCP_Config__discardTimer_infinity; + DRB_pdcp_config->rlc_AM = NULL; + DRB_pdcp_config->rlc_UM = NULL; + /* avoid gcc warnings */ + (void)PDCP_rlc_AM; + (void)PDCP_rlc_UM; +#ifdef RRC_DEFAULT_RAB_IS_AM // EXMIMO_IOT + PDCP_rlc_AM = CALLOC(1, sizeof(*PDCP_rlc_AM)); + DRB_pdcp_config->rlc_AM = PDCP_rlc_AM; + PDCP_rlc_AM->statusReportRequired = FALSE; +#else + PDCP_rlc_UM = CALLOC(1, sizeof(*PDCP_rlc_UM)); + DRB_pdcp_config->rlc_UM = PDCP_rlc_UM; + PDCP_rlc_UM->pdcp_SN_Size = LTE_PDCP_Config__rlc_UM__pdcp_SN_Size_len12bits; +#endif + DRB_pdcp_config->headerCompression.present = LTE_PDCP_Config__headerCompression_PR_notUsed; + DRB_lchan_config = CALLOC(1, sizeof(*DRB_lchan_config)); + DRB_config->logicalChannelConfig = DRB_lchan_config; + DRB_ul_SpecificParameters = CALLOC(1, sizeof(*DRB_ul_SpecificParameters)); + DRB_lchan_config->ul_SpecificParameters = DRB_ul_SpecificParameters; + DRB_ul_SpecificParameters->priority = 12; // lower priority than srb1, srb2 and other dedicated bearer + DRB_ul_SpecificParameters->prioritisedBitRate =LTE_LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_kBps8 ; + //LogicalChannelConfig__ul_SpecificParameters__prioritisedBitRate_infinity; + DRB_ul_SpecificParameters->bucketSizeDuration = + LTE_LogicalChannelConfig__ul_SpecificParameters__bucketSizeDuration_ms50; + // LCG for DTCH can take the value from 1 to 3 as defined in 36331: normally controlled by upper layers (like RRM) + logicalchannelgroup_drb = CALLOC(1, sizeof(long)); + *logicalchannelgroup_drb = 1; + DRB_ul_SpecificParameters->logicalChannelGroup = logicalchannelgroup_drb; + ASN_SEQUENCE_ADD(&(*DRB_configList)->list, DRB_config); + ASN_SEQUENCE_ADD(&(*DRB_configList2)->list, DRB_config); + //ue_context_pP->ue_context.DRB_configList2[0] = &(*DRB_configList); + mac_MainConfig = CALLOC(1, sizeof(*mac_MainConfig)); + ue_context_pP->ue_context.mac_MainConfig = mac_MainConfig; + mac_MainConfig->ul_SCH_Config = CALLOC(1, sizeof(*mac_MainConfig->ul_SCH_Config)); + maxHARQ_Tx = CALLOC(1, sizeof(long)); + *maxHARQ_Tx = LTE_MAC_MainConfig__ul_SCH_Config__maxHARQ_Tx_n5; + mac_MainConfig->ul_SCH_Config->maxHARQ_Tx = maxHARQ_Tx; + periodicBSR_Timer = CALLOC(1, sizeof(long)); + *periodicBSR_Timer = LTE_PeriodicBSR_Timer_r12_sf64; + mac_MainConfig->ul_SCH_Config->periodicBSR_Timer = periodicBSR_Timer; + mac_MainConfig->ul_SCH_Config->retxBSR_Timer = LTE_RetxBSR_Timer_r12_sf320; + mac_MainConfig->ul_SCH_Config->ttiBundling = 0; // FALSE + mac_MainConfig->timeAlignmentTimerDedicated = LTE_TimeAlignmentTimer_infinity; + mac_MainConfig->drx_Config = NULL; + mac_MainConfig->phr_Config = CALLOC(1, sizeof(*mac_MainConfig->phr_Config)); + mac_MainConfig->phr_Config->present = LTE_MAC_MainConfig__phr_Config_PR_setup; + mac_MainConfig->phr_Config->choice.setup.periodicPHR_Timer = LTE_MAC_MainConfig__phr_Config__setup__periodicPHR_Timer_sf20; // sf20 = 20 subframes + mac_MainConfig->phr_Config->choice.setup.prohibitPHR_Timer = LTE_MAC_MainConfig__phr_Config__setup__prohibitPHR_Timer_sf20; // sf20 = 20 subframes + mac_MainConfig->phr_Config->choice.setup.dl_PathlossChange = LTE_MAC_MainConfig__phr_Config__setup__dl_PathlossChange_dB1; // Value dB1 =1 dB, dB3 = 3 dB +#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0)) + sr_ProhibitTimer_r9 = CALLOC(1, sizeof(long)); + *sr_ProhibitTimer_r9 = 0; // SR tx on PUCCH, Value in number of SR period(s). Value 0 = no timer for SR, Value 2= 2*SR + mac_MainConfig->ext1 = CALLOC(1, sizeof(struct LTE_MAC_MainConfig__ext1)); + mac_MainConfig->ext1->sr_ProhibitTimer_r9 = sr_ProhibitTimer_r9; + //sps_RA_ConfigList_rlola = NULL; +#endif + + //change the transmission mode for the primary component carrier + //TODO: add codebook subset restriction here + //TODO: change TM for secondary CC in SCelltoaddmodlist + /// now reconfigure phy config dedicated + if (*physicalConfigDedicated) { + free(*physicalConfigDedicated); + } + + //if (*physicalConfigDedicated) { + physicalConfigDedicated2 = CALLOC(1, sizeof(*physicalConfigDedicated2)); + *physicalConfigDedicated = physicalConfigDedicated2; + physicalConfigDedicated2->pdsch_ConfigDedicated = + CALLOC(1, sizeof(*physicalConfigDedicated2->pdsch_ConfigDedicated)); + physicalConfigDedicated2->pucch_ConfigDedicated = + CALLOC(1, sizeof(*physicalConfigDedicated2->pucch_ConfigDedicated)); + physicalConfigDedicated2->pusch_ConfigDedicated = + CALLOC(1, sizeof(*physicalConfigDedicated2->pusch_ConfigDedicated)); + physicalConfigDedicated2->uplinkPowerControlDedicated = + CALLOC(1, sizeof(*physicalConfigDedicated2->uplinkPowerControlDedicated)); + physicalConfigDedicated2->tpc_PDCCH_ConfigPUCCH = + CALLOC(1, sizeof(*physicalConfigDedicated2->tpc_PDCCH_ConfigPUCCH)); + physicalConfigDedicated2->tpc_PDCCH_ConfigPUSCH = + CALLOC(1, sizeof(*physicalConfigDedicated2->tpc_PDCCH_ConfigPUSCH)); + physicalConfigDedicated2->cqi_ReportConfig = NULL; //CALLOC(1,sizeof(*physicalConfigDedicated2->cqi_ReportConfig)); + physicalConfigDedicated2->soundingRS_UL_ConfigDedicated = NULL; //CALLOC(1,sizeof(*physicalConfigDedicated2->soundingRS_UL_ConfigDedicated)); + physicalConfigDedicated2->antennaInfo = CALLOC(1, sizeof(*physicalConfigDedicated2->antennaInfo)); + physicalConfigDedicated2->schedulingRequestConfig = + CALLOC(1, sizeof(*physicalConfigDedicated2->schedulingRequestConfig)); + // PDSCH + //assign_enum(&physicalConfigDedicated2->pdsch_ConfigDedicated->p_a, + // PDSCH_ConfigDedicated__p_a_dB0); + physicalConfigDedicated2->pdsch_ConfigDedicated->p_a = LTE_PDSCH_ConfigDedicated__p_a_dB0; + // PUCCH + physicalConfigDedicated2->pucch_ConfigDedicated->ackNackRepetition.present = + LTE_PUCCH_ConfigDedicated__ackNackRepetition_PR_release; + physicalConfigDedicated2->pucch_ConfigDedicated->ackNackRepetition.choice.release = 0; + physicalConfigDedicated2->pucch_ConfigDedicated->tdd_AckNackFeedbackMode = NULL; //PUCCH_ConfigDedicated__tdd_AckNackFeedbackMode_multiplexing; + // Pusch_config_dedicated + physicalConfigDedicated2->pusch_ConfigDedicated->betaOffset_ACK_Index = 0; // 2.00 + physicalConfigDedicated2->pusch_ConfigDedicated->betaOffset_RI_Index = 0; // 1.25 + physicalConfigDedicated2->pusch_ConfigDedicated->betaOffset_CQI_Index = 8; // 2.25 + // UplinkPowerControlDedicated + physicalConfigDedicated2->uplinkPowerControlDedicated->p0_UE_PUSCH = 0; // 0 dB + //assign_enum(&physicalConfigDedicated2->uplinkPowerControlDedicated->deltaMCS_Enabled, + // UplinkPowerControlDedicated__deltaMCS_Enabled_en1); + physicalConfigDedicated2->uplinkPowerControlDedicated->deltaMCS_Enabled = + LTE_UplinkPowerControlDedicated__deltaMCS_Enabled_en1; + physicalConfigDedicated2->uplinkPowerControlDedicated->accumulationEnabled = 1; // should be TRUE in order to have 0dB power offset + physicalConfigDedicated2->uplinkPowerControlDedicated->p0_UE_PUCCH = 0; // 0 dB + physicalConfigDedicated2->uplinkPowerControlDedicated->pSRS_Offset = 0; // 0 dB + physicalConfigDedicated2->uplinkPowerControlDedicated->filterCoefficient = + CALLOC(1, sizeof(*physicalConfigDedicated2->uplinkPowerControlDedicated->filterCoefficient)); + // assign_enum(physicalConfigDedicated2->uplinkPowerControlDedicated->filterCoefficient,FilterCoefficient_fc4); // fc4 dB + *physicalConfigDedicated2->uplinkPowerControlDedicated->filterCoefficient = LTE_FilterCoefficient_fc4; // fc4 dB + // TPC-PDCCH-Config + physicalConfigDedicated2->tpc_PDCCH_ConfigPUCCH->present = LTE_TPC_PDCCH_Config_PR_setup; + physicalConfigDedicated2->tpc_PDCCH_ConfigPUCCH->choice.setup.tpc_Index.present = LTE_TPC_Index_PR_indexOfFormat3; + physicalConfigDedicated2->tpc_PDCCH_ConfigPUCCH->choice.setup.tpc_Index.choice.indexOfFormat3 = 1; + physicalConfigDedicated2->tpc_PDCCH_ConfigPUCCH->choice.setup.tpc_RNTI.buf = CALLOC(1, 2); + physicalConfigDedicated2->tpc_PDCCH_ConfigPUCCH->choice.setup.tpc_RNTI.size = 2; + physicalConfigDedicated2->tpc_PDCCH_ConfigPUCCH->choice.setup.tpc_RNTI.buf[0] = 0x12; + physicalConfigDedicated2->tpc_PDCCH_ConfigPUCCH->choice.setup.tpc_RNTI.buf[1] = 0x34 + ue_context_pP->local_uid; + physicalConfigDedicated2->tpc_PDCCH_ConfigPUCCH->choice.setup.tpc_RNTI.bits_unused = 0; + physicalConfigDedicated2->tpc_PDCCH_ConfigPUSCH->present = LTE_TPC_PDCCH_Config_PR_setup; + physicalConfigDedicated2->tpc_PDCCH_ConfigPUSCH->choice.setup.tpc_Index.present = LTE_TPC_Index_PR_indexOfFormat3; + physicalConfigDedicated2->tpc_PDCCH_ConfigPUSCH->choice.setup.tpc_Index.choice.indexOfFormat3 = 1; + physicalConfigDedicated2->tpc_PDCCH_ConfigPUSCH->choice.setup.tpc_RNTI.buf = CALLOC(1, 2); + physicalConfigDedicated2->tpc_PDCCH_ConfigPUSCH->choice.setup.tpc_RNTI.size = 2; + physicalConfigDedicated2->tpc_PDCCH_ConfigPUSCH->choice.setup.tpc_RNTI.buf[0] = 0x22; + physicalConfigDedicated2->tpc_PDCCH_ConfigPUSCH->choice.setup.tpc_RNTI.buf[1] = 0x34 + ue_context_pP->local_uid; + physicalConfigDedicated2->tpc_PDCCH_ConfigPUSCH->choice.setup.tpc_RNTI.bits_unused = 0; + //AntennaInfoDedicated + physicalConfigDedicated2->antennaInfo = CALLOC(1, sizeof(*physicalConfigDedicated2->antennaInfo)); + physicalConfigDedicated2->antennaInfo->present = LTE_PhysicalConfigDedicated__antennaInfo_PR_explicitValue; + //if ((*physicalConfigDedicated)->antennaInfo) { + (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.transmissionMode = rrc_inst->configuration.radioresourceconfig[0].ue_TransmissionMode; + LOG_D(RRC,"Setting transmission mode to %ld+1\n",rrc_inst->configuration.radioresourceconfig[0].ue_TransmissionMode); + + if (rrc_inst->configuration.radioresourceconfig[0].ue_TransmissionMode==LTE_AntennaInfoDedicated__transmissionMode_tm3) { + (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction= + CALLOC(1,sizeof(LTE_AntennaInfoDedicated__codebookSubsetRestriction_PR)); + (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->present = + LTE_AntennaInfoDedicated__codebookSubsetRestriction_PR_n2TxAntenna_tm3; + (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm3.buf= MALLOC(1); + (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm3.buf[0] = 0xc0; + (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm3.size=1; + (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm3.bits_unused=6; + } else if (rrc_inst->configuration.radioresourceconfig[0].ue_TransmissionMode==LTE_AntennaInfoDedicated__transmissionMode_tm4) { + (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction= + CALLOC(1,sizeof(LTE_AntennaInfoDedicated__codebookSubsetRestriction_PR)); + (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->present = + LTE_AntennaInfoDedicated__codebookSubsetRestriction_PR_n2TxAntenna_tm4; + (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm4.buf= MALLOC(1); + (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm4.buf[0] = 0xfc; + (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm4.size=1; + (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm4.bits_unused=2; + } else if (rrc_inst->configuration.radioresourceconfig[0].ue_TransmissionMode==LTE_AntennaInfoDedicated__transmissionMode_tm5) { + (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction= + CALLOC(1,sizeof(LTE_AntennaInfoDedicated__codebookSubsetRestriction_PR)); + (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->present = + LTE_AntennaInfoDedicated__codebookSubsetRestriction_PR_n2TxAntenna_tm5; + (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm5.buf= MALLOC(1); + (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm5.buf[0] = 0xf0; + (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm5.size=1; + (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm5.bits_unused=4; + } else if (rrc_inst->configuration.radioresourceconfig[0].ue_TransmissionMode==LTE_AntennaInfoDedicated__transmissionMode_tm6) { + (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction= + CALLOC(1,sizeof(LTE_AntennaInfoDedicated__codebookSubsetRestriction_PR)); + (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->present = + LTE_AntennaInfoDedicated__codebookSubsetRestriction_PR_n2TxAntenna_tm6; + (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm6.buf= MALLOC(1); + (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm6.buf[0] = 0xf0; + (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm6.size=1; + (*physicalConfigDedicated)->antennaInfo->choice.explicitValue.codebookSubsetRestriction->choice.n2TxAntenna_tm6.bits_unused=4; + } + + physicalConfigDedicated2->antennaInfo->choice.explicitValue.ue_TransmitAntennaSelection.present = + LTE_AntennaInfoDedicated__ue_TransmitAntennaSelection_PR_release; + physicalConfigDedicated2->antennaInfo->choice.explicitValue.ue_TransmitAntennaSelection.choice.release = 0; + //} + //else { + //LOG_E(RRC,"antenna_info not present in physical_config_dedicated. Not reconfiguring!\n"); + //} + // CQI ReportConfig + physicalConfigDedicated2->cqi_ReportConfig = CALLOC(1,sizeof(*physicalConfigDedicated2->cqi_ReportConfig)); + physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportModeAperiodic = CALLOC(1,sizeof(*physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportModeAperiodic)); + physicalConfigDedicated2->cqi_ReportConfig->nomPDSCH_RS_EPRE_Offset = 0; // 0 dB + //physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportPeriodic=NULL; + physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportPeriodic=CALLOC(1,sizeof(*physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportPeriodic)); + physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportPeriodic->present = LTE_CQI_ReportPeriodic_PR_release; + + //if ((*physicalConfigDedicated)->cqi_ReportConfig) { + if ((rrc_inst->configuration.radioresourceconfig[0].ue_TransmissionMode==LTE_AntennaInfoDedicated__transmissionMode_tm4) || + (rrc_inst->configuration.radioresourceconfig[0].ue_TransmissionMode==LTE_AntennaInfoDedicated__transmissionMode_tm5) || + (rrc_inst->configuration.radioresourceconfig[0].ue_TransmissionMode==LTE_AntennaInfoDedicated__transmissionMode_tm6)) { + //feedback mode needs to be set as well + //TODO: I think this is taken into account in the PHY automatically based on the transmission mode variable + printf("setting cqi reporting mode to rm31\n"); +#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0)) + *((*physicalConfigDedicated)->cqi_ReportConfig->cqi_ReportModeAperiodic)=LTE_CQI_ReportModeAperiodic_rm31; +#else + *((*physicalConfigDedicated)->cqi_ReportConfig->cqi_ReportModeAperiodic)=CQI_ReportConfig__cqi_ReportModeAperiodic_rm31; // HLC CQI, no PMI +#endif + } else { +#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0)) + *physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportModeAperiodic= LTE_CQI_ReportModeAperiodic_rm30; +#else + *physicalConfigDedicated2->cqi_ReportConfig->cqi_ReportModeAperiodic=CQI_ReportConfig__cqi_ReportModeAperiodic_rm30; // HLC CQI, no PMI +#endif + } + + //} + //else { + //LOG_E(RRC,"cqi_ReportConfig not present in physical_config_dedicated. Not reconfiguring!\n"); + //} + // SchedulingRequestConfig + physicalConfigDedicated2->schedulingRequestConfig->present = LTE_SchedulingRequestConfig_PR_setup; + physicalConfigDedicated2->schedulingRequestConfig->choice.setup.sr_PUCCH_ResourceIndex = ue_context_pP->local_uid; + + if (rrc_inst->carrier[0].sib1->tdd_Config==NULL) { // FDD + physicalConfigDedicated2->schedulingRequestConfig->choice.setup.sr_ConfigIndex = 5 + (ue_context_pP->local_uid % + 10); // Isr = 5 (every 10 subframes, offset=2+UE_id mod3) + } else { + switch (rrc_inst->carrier[0].sib1->tdd_Config->subframeAssignment) { + case 1: + physicalConfigDedicated2->schedulingRequestConfig->choice.setup.sr_ConfigIndex = 7 + (ue_context_pP->local_uid & 1) + (( + ue_context_pP->local_uid & 3) >> 1) * 5; // Isr = 5 (every 10 subframes, offset=2 for UE0, 3 for UE1, 7 for UE2, 8 for UE3 , 2 for UE4 etc..) + break; + + case 3: + physicalConfigDedicated2->schedulingRequestConfig->choice.setup.sr_ConfigIndex = 7 + (ue_context_pP->local_uid % + 3); // Isr = 5 (every 10 subframes, offset=2 for UE0, 3 for UE1, 3 for UE2, 2 for UE3 , etc..) + break; + + case 4: + physicalConfigDedicated2->schedulingRequestConfig->choice.setup.sr_ConfigIndex = 7 + (ue_context_pP->local_uid & + 1); // Isr = 5 (every 10 subframes, offset=2 for UE0, 3 for UE1, 3 for UE2, 2 for UE3 , etc..) + break; + + default: + physicalConfigDedicated2->schedulingRequestConfig->choice.setup.sr_ConfigIndex = 7; // Isr = 5 (every 10 subframes, offset=2 for all UE0 etc..) + break; + } + } + + // assign_enum(&physicalConfigDedicated2->schedulingRequestConfig->choice.setup.dsr_TransMax, + //SchedulingRequestConfig__setup__dsr_TransMax_n4); + // assign_enum(&physicalConfigDedicated2->schedulingRequestConfig->choice.setup.dsr_TransMax = SchedulingRequestConfig__setup__dsr_TransMax_n4; + physicalConfigDedicated2->schedulingRequestConfig->choice.setup.dsr_TransMax = + LTE_SchedulingRequestConfig__setup__dsr_TransMax_n4; + //} + //else { + //LOG_E(RRC,"physical_config_dedicated not present in RRCConnectionReconfiguration. Not reconfiguring!\n"); + //} + // Measurement ID list + MeasId_list = CALLOC(1, sizeof(*MeasId_list)); + memset((void *)MeasId_list, 0, sizeof(*MeasId_list)); + MeasId0 = CALLOC(1, sizeof(*MeasId0)); + MeasId0->measId = 1; + MeasId0->measObjectId = 1; + MeasId0->reportConfigId = 1; + ASN_SEQUENCE_ADD(&MeasId_list->list, MeasId0); + MeasId1 = CALLOC(1, sizeof(*MeasId1)); + MeasId1->measId = 2; + MeasId1->measObjectId = 1; + MeasId1->reportConfigId = 2; + ASN_SEQUENCE_ADD(&MeasId_list->list, MeasId1); + MeasId2 = CALLOC(1, sizeof(*MeasId2)); + MeasId2->measId = 3; + MeasId2->measObjectId = 1; + MeasId2->reportConfigId = 3; + ASN_SEQUENCE_ADD(&MeasId_list->list, MeasId2); + MeasId3 = CALLOC(1, sizeof(*MeasId3)); + MeasId3->measId = 4; + MeasId3->measObjectId = 1; + MeasId3->reportConfigId = 4; + ASN_SEQUENCE_ADD(&MeasId_list->list, MeasId3); + MeasId4 = CALLOC(1, sizeof(*MeasId4)); + MeasId4->measId = 5; + MeasId4->measObjectId = 1; + MeasId4->reportConfigId = 5; + ASN_SEQUENCE_ADD(&MeasId_list->list, MeasId4); + MeasId5 = CALLOC(1, sizeof(*MeasId5)); + MeasId5->measId = 6; + MeasId5->measObjectId = 1; + MeasId5->reportConfigId = 6; + ASN_SEQUENCE_ADD(&MeasId_list->list, MeasId5); + // rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig->measIdToAddModList = MeasId_list; + // Add one EUTRA Measurement Object + MeasObj_list = CALLOC(1, sizeof(*MeasObj_list)); + memset((void *)MeasObj_list, 0, sizeof(*MeasObj_list)); + // Configure MeasObject + MeasObj = CALLOC(1, sizeof(*MeasObj)); + memset((void *)MeasObj, 0, sizeof(*MeasObj)); + MeasObj->measObjectId = 1; + MeasObj->measObject.present = LTE_MeasObjectToAddMod__measObject_PR_measObjectEUTRA; + MeasObj->measObject.choice.measObjectEUTRA.carrierFreq = (LTE_ARFCN_ValueEUTRA_t)to_earfcn_DL(RC.rrc[ctxt_pP->module_id]->carrier[0].eutra_band, RC.rrc[ctxt_pP->module_id]->carrier[0].dl_CarrierFreq, + RC.rrc[ctxt_pP->module_id]->carrier[0].N_RB_DL); + MeasObj->measObject.choice.measObjectEUTRA.allowedMeasBandwidth = LTE_AllowedMeasBandwidth_mbw25; + MeasObj->measObject.choice.measObjectEUTRA.presenceAntennaPort1 = 1; + MeasObj->measObject.choice.measObjectEUTRA.neighCellConfig.buf = CALLOC(1, sizeof(uint8_t)); + MeasObj->measObject.choice.measObjectEUTRA.neighCellConfig.buf[0] = 0; + MeasObj->measObject.choice.measObjectEUTRA.neighCellConfig.size = 1; + MeasObj->measObject.choice.measObjectEUTRA.neighCellConfig.bits_unused = 6; + MeasObj->measObject.choice.measObjectEUTRA.offsetFreq = NULL; // Default is 15 or 0dB + //MeasObj->measObject.choice.measObjectEUTRA.cellsToAddModList = + //(CellsToAddModList_t *) CALLOC(1, sizeof(*CellsToAddModList)); + //CellsToAddModList = MeasObj->measObject.choice.measObjectEUTRA.cellsToAddModList; + // Add adjacent cell lists (6 per eNB) + //for (i = 0; i < 6; i++) { + //CellToAdd = (CellsToAddMod_t *) CALLOC(1, sizeof(*CellToAdd)); + //CellToAdd->cellIndex = 1;//i + 1; + //CellToAdd->physCellId = 1;//get_adjacent_cell_id(ctxt_pP->module_id, i); + //CellToAdd->cellIndividualOffset = Q_OffsetRange_dB0; + //ASN_SEQUENCE_ADD(&CellsToAddModList->list, CellToAdd); + //} + ASN_SEQUENCE_ADD(&MeasObj_list->list, MeasObj); + // rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig->measObjectToAddModList = MeasObj_list; + // Report Configurations for periodical, A1-A5 events + ReportConfig_list = CALLOC(1, sizeof(*ReportConfig_list)); + ReportConfig_per = CALLOC(1, sizeof(*ReportConfig_per)); + ReportConfig_A1 = CALLOC(1, sizeof(*ReportConfig_A1)); + ReportConfig_A2 = CALLOC(1, sizeof(*ReportConfig_A2)); + ReportConfig_A3 = CALLOC(1, sizeof(*ReportConfig_A3)); + ReportConfig_A4 = CALLOC(1, sizeof(*ReportConfig_A4)); + ReportConfig_A5 = CALLOC(1, sizeof(*ReportConfig_A5)); + ReportConfig_per->reportConfigId = 1; + ReportConfig_per->reportConfig.present = LTE_ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA; + ReportConfig_per->reportConfig.choice.reportConfigEUTRA.triggerType.present = + LTE_ReportConfigEUTRA__triggerType_PR_periodical; + ReportConfig_per->reportConfig.choice.reportConfigEUTRA.triggerType.choice.periodical.purpose = + LTE_ReportConfigEUTRA__triggerType__periodical__purpose_reportStrongestCells; + ReportConfig_per->reportConfig.choice.reportConfigEUTRA.triggerQuantity = LTE_ReportConfigEUTRA__triggerQuantity_rsrp; + ReportConfig_per->reportConfig.choice.reportConfigEUTRA.reportQuantity = LTE_ReportConfigEUTRA__reportQuantity_both; + ReportConfig_per->reportConfig.choice.reportConfigEUTRA.maxReportCells = 2; + ReportConfig_per->reportConfig.choice.reportConfigEUTRA.reportInterval = LTE_ReportInterval_ms120; + ReportConfig_per->reportConfig.choice.reportConfigEUTRA.reportAmount = LTE_ReportConfigEUTRA__reportAmount_infinity; + ASN_SEQUENCE_ADD(&ReportConfig_list->list, ReportConfig_per); + ReportConfig_A1->reportConfigId = 2; + ReportConfig_A1->reportConfig.present = LTE_ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA; + ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.triggerType.present = + LTE_ReportConfigEUTRA__triggerType_PR_event; + ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.present = + LTE_ReportConfigEUTRA__triggerType__event__eventId_PR_eventA1; + ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.eventA1. + a1_Threshold.present = LTE_ThresholdEUTRA_PR_threshold_RSRP; + ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.eventA1. + a1_Threshold.choice.threshold_RSRP = 10; + ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.triggerQuantity = LTE_ReportConfigEUTRA__triggerQuantity_rsrp; + ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.reportQuantity = LTE_ReportConfigEUTRA__reportQuantity_both; + ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.maxReportCells = 2; + ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.reportInterval = LTE_ReportInterval_ms120; + ReportConfig_A1->reportConfig.choice.reportConfigEUTRA.reportAmount = LTE_ReportConfigEUTRA__reportAmount_infinity; + ASN_SEQUENCE_ADD(&ReportConfig_list->list, ReportConfig_A1); + // if (ho_state == 1 /*HO_MEASUREMENT */ ) { + LOG_I(RRC, "[eNB %d] frame %d: requesting A2, A3, A4, and A5 event reporting\n", + ctxt_pP->module_id, ctxt_pP->frame); + ReportConfig_A2->reportConfigId = 3; + ReportConfig_A2->reportConfig.present = LTE_ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA; + ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.triggerType.present = + LTE_ReportConfigEUTRA__triggerType_PR_event; + ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.present = + LTE_ReportConfigEUTRA__triggerType__event__eventId_PR_eventA2; + ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice. + eventA2.a2_Threshold.present = LTE_ThresholdEUTRA_PR_threshold_RSRP; + ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice. + eventA2.a2_Threshold.choice.threshold_RSRP = 10; + ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.triggerQuantity = + LTE_ReportConfigEUTRA__triggerQuantity_rsrp; + ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.reportQuantity = LTE_ReportConfigEUTRA__reportQuantity_both; + ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.maxReportCells = 2; + ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.reportInterval = LTE_ReportInterval_ms120; + ReportConfig_A2->reportConfig.choice.reportConfigEUTRA.reportAmount = LTE_ReportConfigEUTRA__reportAmount_infinity; + ASN_SEQUENCE_ADD(&ReportConfig_list->list, ReportConfig_A2); + ReportConfig_A3->reportConfigId = 4; + ReportConfig_A3->reportConfig.present = LTE_ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA; + ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.present = + LTE_ReportConfigEUTRA__triggerType_PR_event; + ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.present = + LTE_ReportConfigEUTRA__triggerType__event__eventId_PR_eventA3; + ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice.eventA3.a3_Offset = 0; //10; + ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice. + eventA3.reportOnLeave = 1; + ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerQuantity = + LTE_ReportConfigEUTRA__triggerQuantity_rsrp; + ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.reportQuantity = LTE_ReportConfigEUTRA__reportQuantity_both; + ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.maxReportCells = 2; + ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.reportInterval = LTE_ReportInterval_ms120; + ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.reportAmount = LTE_ReportConfigEUTRA__reportAmount_infinity; + ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.hysteresis = 0; // FIXME ...hysteresis is of type long! + ReportConfig_A3->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.timeToTrigger = + LTE_TimeToTrigger_ms40; + ASN_SEQUENCE_ADD(&ReportConfig_list->list, ReportConfig_A3); + ReportConfig_A4->reportConfigId = 5; + ReportConfig_A4->reportConfig.present = LTE_ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA; + ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.triggerType.present = + LTE_ReportConfigEUTRA__triggerType_PR_event; + ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.present = + LTE_ReportConfigEUTRA__triggerType__event__eventId_PR_eventA4; + ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice. + eventA4.a4_Threshold.present = LTE_ThresholdEUTRA_PR_threshold_RSRP; + ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice. + eventA4.a4_Threshold.choice.threshold_RSRP = 10; + ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.triggerQuantity = + LTE_ReportConfigEUTRA__triggerQuantity_rsrp; + ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.reportQuantity = LTE_ReportConfigEUTRA__reportQuantity_both; + ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.maxReportCells = 2; + ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.reportInterval = LTE_ReportInterval_ms120; + ReportConfig_A4->reportConfig.choice.reportConfigEUTRA.reportAmount = LTE_ReportConfigEUTRA__reportAmount_infinity; + ASN_SEQUENCE_ADD(&ReportConfig_list->list, ReportConfig_A4); + ReportConfig_A5->reportConfigId = 6; + ReportConfig_A5->reportConfig.present = LTE_ReportConfigToAddMod__reportConfig_PR_reportConfigEUTRA; + ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerType.present = + LTE_ReportConfigEUTRA__triggerType_PR_event; + ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.present = + LTE_ReportConfigEUTRA__triggerType__event__eventId_PR_eventA5; + ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice. + eventA5.a5_Threshold1.present = LTE_ThresholdEUTRA_PR_threshold_RSRP; + ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice. + eventA5.a5_Threshold2.present = LTE_ThresholdEUTRA_PR_threshold_RSRP; + ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice. + eventA5.a5_Threshold1.choice.threshold_RSRP = 10; + ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerType.choice.event.eventId.choice. + eventA5.a5_Threshold2.choice.threshold_RSRP = 10; + ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.triggerQuantity = + LTE_ReportConfigEUTRA__triggerQuantity_rsrp; + ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.reportQuantity = LTE_ReportConfigEUTRA__reportQuantity_both; + ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.maxReportCells = 2; + ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.reportInterval = LTE_ReportInterval_ms120; + ReportConfig_A5->reportConfig.choice.reportConfigEUTRA.reportAmount = LTE_ReportConfigEUTRA__reportAmount_infinity; + ASN_SEQUENCE_ADD(&ReportConfig_list->list, ReportConfig_A5); + // rrcConnectionReconfiguration->criticalExtensions.choice.c1.choice.rrcConnectionReconfiguration_r8.measConfig->reportConfigToAddModList = ReportConfig_list; + rsrp = CALLOC(1, sizeof(RSRP_Range_t)); + *rsrp = 20; + Sparams = CALLOC(1, sizeof(*Sparams)); + Sparams->present = LTE_MeasConfig__speedStatePars_PR_setup; + Sparams->choice.setup.timeToTrigger_SF.sf_High = LTE_SpeedStateScaleFactors__sf_Medium_oDot75; + Sparams->choice.setup.timeToTrigger_SF.sf_Medium = LTE_SpeedStateScaleFactors__sf_High_oDot5; + Sparams->choice.setup.mobilityStateParameters.n_CellChangeHigh = 10; + Sparams->choice.setup.mobilityStateParameters.n_CellChangeMedium = 5; + Sparams->choice.setup.mobilityStateParameters.t_Evaluation = LTE_MobilityStateParameters__t_Evaluation_s60; + Sparams->choice.setup.mobilityStateParameters.t_HystNormal = LTE_MobilityStateParameters__t_HystNormal_s120; + quantityConfig = CALLOC(1, sizeof(*quantityConfig)); + memset((void *)quantityConfig, 0, sizeof(*quantityConfig)); + quantityConfig->quantityConfigEUTRA = CALLOC(1, sizeof(struct LTE_QuantityConfigEUTRA)); + memset((void *)quantityConfig->quantityConfigEUTRA, 0, sizeof(*quantityConfig->quantityConfigEUTRA)); + quantityConfig->quantityConfigCDMA2000 = NULL; + quantityConfig->quantityConfigGERAN = NULL; + quantityConfig->quantityConfigUTRA = NULL; + quantityConfig->quantityConfigEUTRA->filterCoefficientRSRP = + CALLOC(1, sizeof(*(quantityConfig->quantityConfigEUTRA->filterCoefficientRSRP))); + quantityConfig->quantityConfigEUTRA->filterCoefficientRSRQ = + CALLOC(1, sizeof(*(quantityConfig->quantityConfigEUTRA->filterCoefficientRSRQ))); + *quantityConfig->quantityConfigEUTRA->filterCoefficientRSRP = LTE_FilterCoefficient_fc4; + *quantityConfig->quantityConfigEUTRA->filterCoefficientRSRQ = LTE_FilterCoefficient_fc4; + /* mobilityinfo */ + mobilityInfo = ue_context_pP->ue_context.mobilityInfo; + + if (mobilityInfo) { + free(mobilityInfo); + } + + mobilityInfo = CALLOC(1, sizeof(*mobilityInfo)); + memset((void *)mobilityInfo, 0, sizeof(*mobilityInfo)); + mobilityInfo->targetPhysCellId = RC.rrc[ctxt_pP->module_id]->carrier[0].physCellId; + //(PhysCellId_t) two_tier_hexagonal_cellIds[ue_context_pP->ue_context.handover_info->modid_t]; + LOG_D(RRC, "[eNB %d] Frame %d: handover preparation: targetPhysCellId: %ld mod_id: %d ue: %x \n", + ctxt_pP->module_id, + ctxt_pP->frame, + mobilityInfo->targetPhysCellId, + ctxt_pP->module_id, // get_adjacent_cell_mod_id(mobilityInfo->targetPhysCellId), + ue_context_pP->ue_context.rnti); + mobilityInfo->additionalSpectrumEmission = CALLOC(1, sizeof(*mobilityInfo->additionalSpectrumEmission)); + *mobilityInfo->additionalSpectrumEmission = (LTE_AdditionalSpectrumEmission_t) 1; //Check this value! + mobilityInfo->t304 = LTE_MobilityControlInfo__t304_ms200; // need to configure an appropriate value here + // New UE Identity (C-RNTI) to identify an UE uniquely in a cell + mobilityInfo->newUE_Identity.size = 2; + mobilityInfo->newUE_Identity.bits_unused = 0; + mobilityInfo->newUE_Identity.buf = rv; + mobilityInfo->newUE_Identity.buf[0] = rv[0]; + mobilityInfo->newUE_Identity.buf[1] = rv[1]; + //memset((void *)&mobilityInfo->radioResourceConfigCommon,(void *)&rrc_inst->sib2->radioResourceConfigCommon,sizeof(RadioResourceConfigCommon_t)); + //memset((void *)&mobilityInfo->radioResourceConfigCommon,0,sizeof(RadioResourceConfigCommon_t)); + // Configuring radioResourceConfigCommon + mobilityInfo->radioResourceConfigCommon.rach_ConfigCommon = + CALLOC(1, sizeof(*mobilityInfo->radioResourceConfigCommon.rach_ConfigCommon)); + memcpy((void *)mobilityInfo->radioResourceConfigCommon.rach_ConfigCommon, + (void *)&rrc_inst->carrier[0] /* CROUX TBC */.sib2->radioResourceConfigCommon.rach_ConfigCommon, sizeof(LTE_RACH_ConfigCommon_t)); + mobilityInfo->radioResourceConfigCommon.prach_Config.prach_ConfigInfo = + CALLOC(1, sizeof(*mobilityInfo->radioResourceConfigCommon.prach_Config.prach_ConfigInfo)); + memcpy((void *)mobilityInfo->radioResourceConfigCommon.prach_Config.prach_ConfigInfo, + (void *)&rrc_inst->carrier[0] /* CROUX TBC */.sib2->radioResourceConfigCommon.prach_Config.prach_ConfigInfo, + sizeof(LTE_PRACH_ConfigInfo_t)); + mobilityInfo->radioResourceConfigCommon.prach_Config.rootSequenceIndex = + rrc_inst->carrier[0] /* CROUX TBC */.sib2->radioResourceConfigCommon.prach_Config.rootSequenceIndex; + mobilityInfo->radioResourceConfigCommon.pdsch_ConfigCommon = + CALLOC(1, sizeof(*mobilityInfo->radioResourceConfigCommon.pdsch_ConfigCommon)); + memcpy((void *)mobilityInfo->radioResourceConfigCommon.pdsch_ConfigCommon, + (void *)&rrc_inst->carrier[0] /* CROUX TBC */.sib2->radioResourceConfigCommon.pdsch_ConfigCommon, sizeof(LTE_PDSCH_ConfigCommon_t)); + memcpy((void *)&mobilityInfo->radioResourceConfigCommon.pusch_ConfigCommon, + (void *)&rrc_inst->carrier[0] /* CROUX TBC */.sib2->radioResourceConfigCommon.pusch_ConfigCommon, sizeof(LTE_PUSCH_ConfigCommon_t)); + mobilityInfo->radioResourceConfigCommon.phich_Config = NULL; + mobilityInfo->radioResourceConfigCommon.pucch_ConfigCommon = + CALLOC(1, sizeof(*mobilityInfo->radioResourceConfigCommon.pucch_ConfigCommon)); + memcpy((void *)mobilityInfo->radioResourceConfigCommon.pucch_ConfigCommon, + (void *)&rrc_inst->carrier[0] /* CROUX TBC */.sib2->radioResourceConfigCommon.pucch_ConfigCommon, sizeof(LTE_PUCCH_ConfigCommon_t)); + mobilityInfo->radioResourceConfigCommon.soundingRS_UL_ConfigCommon = + CALLOC(1, sizeof(*mobilityInfo->radioResourceConfigCommon.soundingRS_UL_ConfigCommon)); + memcpy((void *)mobilityInfo->radioResourceConfigCommon.soundingRS_UL_ConfigCommon, + (void *)&rrc_inst->carrier[0] /* CROUX TBC */.sib2->radioResourceConfigCommon.soundingRS_UL_ConfigCommon, + sizeof(LTE_SoundingRS_UL_ConfigCommon_t)); + mobilityInfo->radioResourceConfigCommon.uplinkPowerControlCommon = + CALLOC(1, sizeof(*mobilityInfo->radioResourceConfigCommon.uplinkPowerControlCommon)); + memcpy((void *)mobilityInfo->radioResourceConfigCommon.uplinkPowerControlCommon, + (void *)&rrc_inst->carrier[0] /* CROUX TBC */.sib2->radioResourceConfigCommon.uplinkPowerControlCommon, + sizeof(LTE_UplinkPowerControlCommon_t)); + mobilityInfo->radioResourceConfigCommon.antennaInfoCommon = NULL; + mobilityInfo->radioResourceConfigCommon.p_Max = NULL; // CALLOC(1,sizeof(*mobilityInfo->radioResourceConfigCommon.p_Max)); + //memcpy((void *)mobilityInfo->radioResourceConfigCommon.p_Max,(void *)rrc_inst->sib1->p_Max,sizeof(P_Max_t)); + mobilityInfo->radioResourceConfigCommon.tdd_Config = NULL; //CALLOC(1,sizeof(TDD_Config_t)); + //memcpy((void *)mobilityInfo->radioResourceConfigCommon.tdd_Config,(void *)rrc_inst->sib1->tdd_Config,sizeof(TDD_Config_t)); + mobilityInfo->radioResourceConfigCommon.ul_CyclicPrefixLength = + rrc_inst->carrier[0] /* CROUX TBC */.sib2->radioResourceConfigCommon.ul_CyclicPrefixLength; + //End of configuration of radioResourceConfigCommon + mobilityInfo->carrierFreq = CALLOC(1, sizeof(*mobilityInfo->carrierFreq)); //CALLOC(1,sizeof(CarrierFreqEUTRA_t)); 36090 + mobilityInfo->carrierFreq->dl_CarrierFreq = (LTE_ARFCN_ValueEUTRA_t)to_earfcn_DL(RC.rrc[ctxt_pP->module_id]->carrier[0].eutra_band, RC.rrc[ctxt_pP->module_id]->carrier[0].dl_CarrierFreq, + RC.rrc[ctxt_pP->module_id]->carrier[0].N_RB_DL); + mobilityInfo->carrierFreq->ul_CarrierFreq = NULL; + mobilityInfo->carrierBandwidth = CALLOC(1, sizeof( + *mobilityInfo->carrierBandwidth)); //CALLOC(1,sizeof(struct CarrierBandwidthEUTRA)); AllowedMeasBandwidth_mbw25 + mobilityInfo->carrierBandwidth->dl_Bandwidth = LTE_CarrierBandwidthEUTRA__dl_Bandwidth_n25; + mobilityInfo->carrierBandwidth->ul_Bandwidth = NULL; + mobilityInfo->rach_ConfigDedicated = NULL; + ue_context_pP->ue_context.mobilityInfo = mobilityInfo; +#if 0 + LOG_I(RRC, + "[eNB %d] Frame %d: potential handover preparation: store the information in an intermediate structure in case of failure\n", + ctxt_pP->module_id, ctxt_pP->frame); + // store the information in an intermediate structure for Hanodver management + //rrc_inst->handover_info.as_config.sourceRadioResourceConfig.srb_ToAddModList = CALLOC(1,sizeof()); + ue_context_pP->ue_context.handover_info = CALLOC(1, sizeof(*(ue_context_pP->ue_context.handover_info))); + //memcpy((void *)rrc_inst->handover_info[ue_mod_idP]->as_config.sourceRadioResourceConfig.srb_ToAddModList,(void *)SRB_list,sizeof(SRB_ToAddModList_t)); + ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.srb_ToAddModList = *SRB_configList2; + //memcpy((void *)rrc_inst->handover_info[ue_mod_idP]->as_config.sourceRadioResourceConfig.drb_ToAddModList,(void *)DRB_list,sizeof(DRB_ToAddModList_t)); + ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.drb_ToAddModList = *DRB_configList; + ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.drb_ToReleaseList = NULL; + ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.mac_MainConfig = + CALLOC(1, sizeof(*ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.mac_MainConfig)); + memcpy((void *)ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.mac_MainConfig, + (void *)mac_MainConfig, sizeof(MAC_MainConfig_t)); + ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.physicalConfigDedicated = + CALLOC(1, sizeof(PhysicalConfigDedicated_t)); + memcpy((void *)ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.physicalConfigDedicated, + (void *)ue_context_pP->ue_context.physicalConfigDedicated, sizeof(PhysicalConfigDedicated_t)); + ue_context_pP->ue_context.handover_info->as_config.sourceRadioResourceConfig.sps_Config = NULL; + //memcpy((void *)rrc_inst->handover_info[ue_mod_idP]->as_config.sourceRadioResourceConfig.sps_Config,(void *)rrc_inst->sps_Config[ue_mod_idP],sizeof(SPS_Config_t)); +#endif + // } + securityConfigHO = CALLOC(1, sizeof(*securityConfigHO)); + memset((void *)securityConfigHO, 0, sizeof(*securityConfigHO)); + securityConfigHO->handoverType.present = LTE_SecurityConfigHO__handoverType_PR_intraLTE; + securityConfigHO->handoverType.choice.intraLTE.securityAlgorithmConfig = NULL; /* TODO: to be checked */ + securityConfigHO->handoverType.choice.intraLTE.keyChangeIndicator = 0; + securityConfigHO->handoverType.choice.intraLTE.nextHopChainingCount = 0; +#if defined(ENABLE_ITTI) + /* Initialize NAS list */ + dedicatedInfoNASList = CALLOC(1, sizeof(struct LTE_RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList)); + + /* Add all NAS PDUs to the list */ + for (i = 0; i < ue_context_pP->ue_context.nb_of_e_rabs; i++) { + if (ue_context_pP->ue_context.e_rab[i].param.nas_pdu.buffer != NULL) { + dedicatedInfoNas = CALLOC(1, sizeof(LTE_DedicatedInfoNAS_t)); + memset(dedicatedInfoNas, 0, sizeof(OCTET_STRING_t)); + OCTET_STRING_fromBuf(dedicatedInfoNas, + (char *)ue_context_pP->ue_context.e_rab[i].param.nas_pdu.buffer, + ue_context_pP->ue_context.e_rab[i].param.nas_pdu.length); + ASN_SEQUENCE_ADD(&dedicatedInfoNASList->list, dedicatedInfoNas); + } - /*UE_id_target = rrc_eNB_get_next_free_UE_index( - mod_id_target, - RC.rrc[ctxt_pP->module_id]->Info.UE_list[ue_mod_idP]); //this should return a new index*/ + /* TODO parameters yet to process ... */ + { + // ue_context_pP->ue_context.e_rab[i].param.qos; + // ue_context_pP->ue_context.e_rab[i].param.sgw_addr; + // ue_context_pP->ue_context.e_rab[i].param.gtp_teid; + } + /* TODO should test if e RAB are Ok before! */ + ue_context_pP->ue_context.e_rab[i].status = E_RAB_STATUS_DONE; + LOG_D(RRC, "setting the status for the default DRB (index %d) to (%d,%s)\n", + i, ue_context_pP->ue_context.e_rab[i].status, "E_RAB_STATUS_DONE"); + } - if (ue_context_target_p == NULL) { // if not already in target cell - ue_context_target_p = rrc_eNB_allocate_new_UE_context(RC.rrc[ctxt_pP->module_id]); - ue_context_target_p->ue_id_rnti = ue_context_pP->ue_context.rnti; // LG: should not be the same - ue_context_target_p->ue_context.rnti = ue_context_target_p->ue_id_rnti; // idem - LOG_I(RRC, - "[eNB %d] Frame %d : Emulate sending HandoverPreparationInformation msg from eNB source %d to eNB target %ld: source UE_id %x target UE_id %x source_modId: %d target_modId: %d\n", - ctxt_pP->module_id, - ctxt_pP->frame, - RC.rrc[ctxt_pP->module_id]->carrier[0] /* CROUX TBC */.physCellId, - targetPhyId, - ue_context_pP->ue_context.rnti, - ue_context_target_p->ue_id_rnti, - ctxt_pP->module_id, - mod_id_target); - ue_context_target_p->ue_context.handover_info = - CALLOC(1, sizeof(*(ue_context_target_p->ue_context.handover_info))); - memcpy((void *)&ue_context_target_p->ue_context.handover_info->as_context, - (void *)&ue_context_pP->ue_context.handover_info->as_context, - sizeof(LTE_AS_Context_t)); - memcpy((void *)&ue_context_target_p->ue_context.handover_info->as_config, - (void *)&ue_context_pP->ue_context.handover_info->as_config, - sizeof(LTE_AS_Config_t)); - ue_context_target_p->ue_context.handover_info->ho_prepare = 0x00;// 0xFF; - ue_context_target_p->ue_context.handover_info->ho_complete = 0; - ue_context_pP->ue_context.handover_info->modid_t = mod_id_target; - ue_context_pP->ue_context.handover_info->ueid_s = ue_context_pP->ue_context.rnti; - ue_context_pP->ue_context.handover_info->modid_s = ctxt_pP->module_id; - ue_context_target_p->ue_context.handover_info->modid_t = mod_id_target; - ue_context_target_p->ue_context.handover_info->modid_s = ctxt_pP->module_id; - ue_context_target_p->ue_context.handover_info->ueid_t = ue_context_target_p->ue_context.rnti; - } else { - LOG_E(RRC, "\nError in obtaining free UE id in target eNB %ld for handover \n", targetPhyId); + /* If list is empty free the list and reset the address */ + if (dedicatedInfoNASList->list.count == 0) { + free(dedicatedInfoNASList); + dedicatedInfoNASList = NULL; + } + +#endif + memset(buffer, 0, RRC_BUF_SIZE); + char rrc_buf[1000 /* arbitrary, should be big enough, has to be less than size of return buf by a few bits/bytes */]; + int rrc_size; + rrc_size = do_RRCConnectionReconfiguration(ctxt_pP, + (unsigned char *)rrc_buf, + xid, //Transaction_id, + NULL, // SRB_configList + NULL, + NULL, // DRB2_list, + (struct LTE_SPS_Config *)NULL, // *sps_Config, + (struct LTE_PhysicalConfigDedicated *)*physicalConfigDedicated, + //#ifdef EXMIMO_IOT + // NULL, NULL, NULL,NULL, + //#else + (LTE_MeasObjectToAddModList_t *)MeasObj_list, + (LTE_ReportConfigToAddModList_t *)ReportConfig_list, + (LTE_QuantityConfig_t *)quantityConfig, + (LTE_MeasIdToAddModList_t *)MeasId_list, + //#endif + (LTE_MAC_MainConfig_t *)mac_MainConfig, + (LTE_MeasGapConfig_t *)NULL, + (LTE_MobilityControlInfo_t *)mobilityInfo, + (LTE_SecurityConfigHO_t *)securityConfigHO, + (struct LTE_MeasConfig__speedStatePars *)Sparams, + (LTE_RSRP_Range_t *)rsrp, + (LTE_C_RNTI_t *)cba_RNTI, + (struct LTE_RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList *)dedicatedInfoNASList, + (LTE_SL_CommConfig_r12_t *)NULL, + (LTE_SL_DiscConfig_r12_t *)NULL +#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0)) + , (LTE_SCellToAddMod_r10_t *)NULL +#endif + ); + + if (rrc_size <= 0) { + printf("%s:%d: fatal\n", __FILE__, __LINE__); + abort(); + } + + char *ho_buf = (char *)buffer; + int ho_size; + ho_size = do_HandoverCommand( + ho_buf, 1024 /* TODO: this is the value found in struct x2ap_handover_req_ack_s for array rrc_buffer */, + rrc_buf, + rrc_size); + *_size = size = ho_size; + LOG_DUMPMSG(RRC,DEBUG_RRC,(char *)buffer,size, + "[MSG] RRC Connection Reconfiguration handover\n"); +#if defined(ENABLE_ITTI) + + /* Free all NAS PDUs */ + for (i = 0; i < ue_context_pP->ue_context.nb_of_e_rabs; i++) { + if (ue_context_pP->ue_context.e_rab[i].param.nas_pdu.buffer != NULL) { + /* Free the NAS PDU buffer and invalidate it */ + free(ue_context_pP->ue_context.e_rab[i].param.nas_pdu.buffer); + ue_context_pP->ue_context.e_rab[i].param.nas_pdu.buffer = NULL; } - } else { - LOG_E(RRC, "\nError in obtaining Module ID of target eNB for handover \n"); } -} -//----------------------------------------------------------------------------- -void -rrc_eNB_process_handoverPreparationInformation( - const protocol_ctxt_t *const ctxt_pP, - rrc_eNB_ue_context_t *const ue_context_pP -) -//----------------------------------------------------------------------------- -{ - T(T_ENB_RRC_HANDOVER_PREPARATION_INFORMATION, T_INT(ctxt_pP->module_id), T_INT(ctxt_pP->frame), - T_INT(ctxt_pP->subframe), T_INT(ctxt_pP->rnti)); +#endif LOG_I(RRC, - "[eNB %d] Frame %d : Logical Channel UL-DCCH, processing RRCHandoverPreparationInformation, sending LTE_RRCConnectionReconfiguration to UE %d \n", - ctxt_pP->module_id, ctxt_pP->frame, ue_context_pP->ue_context.rnti); - rrc_eNB_generate_RRCConnectionReconfiguration_handover( - ctxt_pP, - ue_context_pP, - NULL, - 0); + "[eNB %d] Frame %d, Logical Channel DL-DCCH, Generate RRCConnectionReconfiguration handover (bytes %d, UE id %x)\n", + ctxt_pP->module_id, ctxt_pP->frame, size, ue_context_pP->ue_context.rnti); + LOG_D(RRC, + "[FRAME %05d][RRC_eNB][MOD %u][][--- PDCP_DATA_REQ/%d Bytes (rrcConnectionReconfiguration handover to UE %x MUI %d) --->][PDCP][MOD %u][RB %u]\n", + ctxt_pP->frame, ctxt_pP->module_id, size, ue_context_pP->ue_context.rnti, rrc_eNB_mui, ctxt_pP->module_id, DCCH); + MSC_LOG_TX_MESSAGE( + MSC_RRC_ENB, + MSC_RRC_UE, + buffer, + size, + MSC_AS_TIME_FMT" rrcConnectionReconfiguration handover UE %x MUI %d size %u", + MSC_AS_TIME_ARGS(ctxt_pP), + ue_context_pP->ue_context.rnti, + rrc_eNB_mui, + size); } - -//----------------------------------------------------------------------------- void -check_handovers( - protocol_ctxt_t *const ctxt_pP -) -//----------------------------------------------------------------------------- -{ - int result; - struct rrc_eNB_ue_context_s *ue_context_p; - RB_FOREACH(ue_context_p, rrc_ue_tree_s, &RC.rrc[ctxt_pP->module_id]->rrc_ue_head) { - ctxt_pP->rnti = ue_context_p->ue_id_rnti; - - if (ue_context_p->ue_context.handover_info != NULL) { - if (ue_context_p->ue_context.handover_info->ho_prepare == 0xFF) { - LOG_D(RRC, - "[eNB %d] Frame %d: Incoming handover detected for new UE_idx %d (source eNB %d->target eNB %d) \n", - ctxt_pP->module_id, - ctxt_pP->frame, - ctxt_pP->rnti, - ctxt_pP->module_id, - ue_context_p->ue_context.handover_info->modid_t); - // source eNB generates LTE_RRCConnectionreconfiguration to prepare the HO - rrc_eNB_process_handoverPreparationInformation( - ctxt_pP, - ue_context_p); - ue_context_p->ue_context.handover_info->ho_prepare = 0xF1; - } - - if (ue_context_p->ue_context.handover_info->ho_complete == 0xF1) { - LOG_D(RRC, - "[eNB %d] Frame %d: handover Command received for new UE_id %x current eNB %d target eNB: %d \n", - ctxt_pP->module_id, - ctxt_pP->frame, - ctxt_pP->rnti, - ctxt_pP->module_id, - ue_context_p->ue_context.handover_info->modid_t); - //rrc_eNB_process_handoverPreparationInformation(enb_mod_idP,frameP,i); - result = pdcp_data_req(ctxt_pP, - SRB_FLAG_YES, - DCCH, - rrc_eNB_mui++, - SDU_CONFIRM_NO, - ue_context_p->ue_context.handover_info->size, - ue_context_p->ue_context.handover_info->buf, - PDCP_TRANSMISSION_MODE_CONTROL +rrc_eNB_configure_rbs_handover(struct rrc_eNB_ue_context_s *ue_context_p, protocol_ctxt_t *const ctxt_pP) { + uint16_t Idx; + Idx = DCCH; +#if 1 + // Activate the radio bearers + // SRB1 + ue_context_p->ue_context.Srb1.Active = 1; + ue_context_p->ue_context.Srb1.Srb_info.Srb_id = Idx; + memcpy(&ue_context_p->ue_context.Srb1.Srb_info.Lchan_desc[0], &DCCH_LCHAN_DESC, LCHAN_DESC_SIZE); + memcpy(&ue_context_p->ue_context.Srb1.Srb_info.Lchan_desc[1], &DCCH_LCHAN_DESC, LCHAN_DESC_SIZE); + // SRB2 + ue_context_p->ue_context.Srb2.Active = 1; + ue_context_p->ue_context.Srb2.Srb_info.Srb_id = Idx; + memcpy(&ue_context_p->ue_context.Srb2.Srb_info.Lchan_desc[0], &DCCH_LCHAN_DESC, LCHAN_DESC_SIZE); + memcpy(&ue_context_p->ue_context.Srb2.Srb_info.Lchan_desc[1], &DCCH_LCHAN_DESC, LCHAN_DESC_SIZE); +#endif + LOG_I(RRC, "[eNB %d] CALLING RLC CONFIG SRB1 (rbid %d) for UE %x\n", + ctxt_pP->module_id, Idx, ue_context_p->ue_context.rnti); + // Configure PDCP/RLC for the target + rrc_pdcp_config_asn1_req(ctxt_pP, + ue_context_p->ue_context.SRB_configList, + (LTE_DRB_ToAddModList_t *) NULL, + (LTE_DRB_ToReleaseList_t *) NULL, + 0xff, + NULL, + NULL, + NULL +#if defined(Rel10) || defined(Rel14) + , (LTE_PMCH_InfoList_r9_t *) NULL +#endif + , NULL); + rrc_rlc_config_asn1_req(ctxt_pP, + ue_context_p->ue_context.SRB_configList, + (LTE_DRB_ToAddModList_t *) NULL, + (LTE_DRB_ToReleaseList_t *) NULL +#if defined(Rel10) || defined(Rel14) + , (LTE_PMCH_InfoList_r9_t *) NULL + , 0, 0 +#endif + ); + // Add a new user (called during the HO procedure) + LOG_I(RRC, "rrc_eNB_target_add_ue_handover module_id %d rnti %d\n", ctxt_pP->module_id, ctxt_pP->rnti); + // Configure MAC for the target + rrc_mac_config_req_eNB( + ctxt_pP->module_id, + ue_context_p->ue_context.primaryCC_id, + 0,0,0,0,0, #if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0)) - ,NULL, NULL + 0, +#endif + ue_context_p->ue_context.rnti, + (LTE_BCCH_BCH_Message_t *) NULL, + (LTE_RadioResourceConfigCommonSIB_t *) NULL, +#if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0)) + (LTE_RadioResourceConfigCommonSIB_t *) NULL, +#endif + ue_context_p->ue_context.physicalConfigDedicated, +#if (LTE_RRC_VERSION >= MAKE_VERSION(10, 0, 0)) + (LTE_SCellToAddMod_r10_t *)NULL, + //(struct PhysicalConfigDedicatedSCell_r10 *)NULL, +#endif + (LTE_MeasObjectToAddMod_t **) NULL, + ue_context_p->ue_context.mac_MainConfig, + 1, + NULL,//SRB1_logicalChannelConfig, + ue_context_p->ue_context.measGapConfig, + (LTE_TDD_Config_t *) NULL, + (LTE_MobilityControlInfo_t *) ue_context_p->ue_context.mobilityInfo, + (LTE_SchedulingInfoList_t *) NULL, + 0, + NULL, + NULL, + (LTE_MBSFN_SubframeConfigList_t *) NULL +#if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0)) + , 0, (LTE_MBSFN_AreaInfoList_r9_t *) NULL, (LTE_PMCH_InfoList_r9_t *) NULL +#endif +#if (LTE_RRC_VERSION >= MAKE_VERSION(13, 0, 0)) + , + (LTE_SystemInformationBlockType1_v1310_IEs_t *)NULL +#endif + ); +#if 0 +} #endif - ); - - //AssertFatal(result == TRUE, "PDCP data request failed!\n"); - if(result != TRUE) { - LOG_I(RRC, "PDCP data request failed!\n"); - return; - } - - ue_context_p->ue_context.handover_info->ho_complete = 0xF2; - } - } - } } +#if 0 // 5.3.5.4 LTE_RRCConnectionReconfiguration including the mobilityControlInfo to prepare the UE handover //----------------------------------------------------------------------------- void @@ -4913,6 +6220,7 @@ rrc_eNB_generate_RRCConnectionReconfiguration_handover( ue_context_pP->ue_context.measGapConfig, (LTE_TDD_Config_t *) NULL, (LTE_MobilityControlInfo_t *) mobilityInfo, + (LTE_SecurityConfigHO_t *)NULL, (LTE_SchedulingInfoList_t *) NULL, 0, NULL, NULL, (LTE_MBSFN_SubframeConfigList_t *) NULL #if (LTE_RRC_VERSION >= MAKE_VERSION(9, 0, 0)) , 0, (LTE_MBSFN_AreaInfoList_r9_t *) NULL, (LTE_PMCH_InfoList_r9_t *) NULL @@ -4952,6 +6260,7 @@ rrc_eNB_generate_RRCConnectionReconfiguration_handover( #endif } +#endif /* void ue_rrc_process_rrcConnectionReconfiguration(uint8_t enb_mod_idP,frame_t frameP, @@ -6203,6 +7512,22 @@ rrc_eNB_decode_dcch( dedicated_DRB = 2; RC.mac[ctxt_pP->module_id]->UE_list.UE_sched_ctrl[UE_id].crnti_reconfigurationcomplete_flag = 0; } + } else if (ue_context_p->ue_context.Status == RRC_HO_EXECUTION) { + int16_t UE_id = find_UE_id(ctxt_pP->module_id, ctxt_pP->rnti); + + if(UE_id == -1) { + LOG_E(RRC, + PROTOCOL_RRC_CTXT_UE_FMT" RRCConnectionReconfigurationComplete without rnti %x, fault\n", + PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),ctxt_pP->rnti); + break; + } + + dedicated_DRB = 3; + RC.mac[ctxt_pP->module_id]->UE_list.UE_sched_ctrl[UE_id].crnti_reconfigurationcomplete_flag = 0; + ue_context_p->ue_context.Status = RRC_RECONFIGURED; + LOG_I(RRC, + PROTOCOL_RRC_CTXT_UE_FMT" UE State = RRC_HO_EXECUTION (xid %ld)\n", + PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP),ul_dcch_msg->message.choice.c1.choice.rrcConnectionReconfigurationComplete.rrc_TransactionIdentifier); } else { dedicated_DRB = 0; ue_context_p->ue_context.Status = RRC_RECONFIGURED; @@ -6301,6 +7626,17 @@ rrc_eNB_decode_dcch( ue_context_p->ue_context.e_rab[e_rab].status = E_RAB_STATUS_FAILED; } } + } else if(dedicated_DRB == 3) { //x2 path switch + for (uint8_t e_rab = 0; e_rab < ue_context_p->ue_context.nb_of_e_rabs; e_rab++) { + if (ue_context_p->ue_context.e_rab[e_rab].status == E_RAB_STATUS_DONE) { + ue_context_p->ue_context.e_rab[e_rab].status = E_RAB_STATUS_ESTABLISHED; + } else { + ue_context_p->ue_context.e_rab[e_rab].status = E_RAB_STATUS_FAILED; + } + } + + LOG_I(RRC,"issue rrc_eNB_send_PATH_SWITCH_REQ \n"); + rrc_eNB_send_PATH_SWITCH_REQ(ctxt_pP,ue_context_p); } #endif @@ -6574,6 +7910,9 @@ rrc_eNB_decode_dcch( ul_dcch_msg->message.choice.c1.choice.ueCapabilityInformation.criticalExtensions. choice.c1.choice.ueCapabilityInformation_r8.ue_CapabilityRAT_ContainerList.list. array[0]->ueCapabilityRAT_Container.size, 0, 0); + ue_context_p->ue_context.UE_Capability_size = ul_dcch_msg->message.choice.c1.choice.ueCapabilityInformation.criticalExtensions. + choice.c1.choice.ueCapabilityInformation_r8.ue_CapabilityRAT_ContainerList.list. + array[0]->ueCapabilityRAT_Container.size; if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) { xer_fprint(stdout, &asn_DEF_LTE_UE_EUTRA_Capability, ue_context_p->ue_context.UE_Capability); @@ -6910,8 +8249,33 @@ void *rrc_enb_process_itti_msg(void *notUsed) { } break; + + case S1AP_PATH_SWITCH_REQ_ACK: + LOG_I(RRC, "[eNB %d] received path switch ack %s\n", instance, msg_name_p); + rrc_eNB_process_S1AP_PATH_SWITCH_REQ_ACK(msg_p, msg_name_p, instance); + break; # endif + case X2AP_HANDOVER_REQ: + LOG_I(RRC, "[eNB %d] target eNB Receives X2 HO Req %s at frame %d subframe %d\n", instance, msg_name_p, + ctxt.frame, ctxt.subframe); + rrc_eNB_process_handoverPreparationInformation(instance, &X2AP_HANDOVER_REQ(msg_p)); + break; + + case X2AP_HANDOVER_REQ_ACK: { + struct rrc_eNB_ue_context_s *ue_context_p = NULL; + ue_context_p = rrc_eNB_get_ue_context(RC.rrc[instance], ctxt.rnti); + LOG_I(RRC, "[eNB %d] source eNB receives the X2 HO ACK %s at frame %d subframe %d \n", instance, msg_name_p, + ctxt.frame,ctxt.subframe); + DevAssert(ue_context_p != NULL); + + if (ue_context_p->ue_context.handover_info->state != HO_REQUEST) abort(); + + rrc_eNB_process_handoverCommand(instance, ue_context_p, &X2AP_HANDOVER_REQ_ACK(msg_p)); + ue_context_p->ue_context.handover_info->state = HO_PREPARE; + break; + } + /* Messages from eNB app */ case RRC_CONFIGURATION_REQ: LOG_I(RRC, "[eNB %d] Received %s : %p\n", instance, msg_name_p,&RRC_CONFIGURATION_REQ(msg_p)); @@ -7161,7 +8525,7 @@ rrc_eNB_generate_RRCConnectionReconfiguration_Sidelink( (LTE_DRB_ToReleaseList_t *)NULL, // DRB2_list, (struct LTE_SPS_Config *)NULL, // *sps_Config, NULL, NULL, NULL, NULL,NULL, - NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, (struct LTE_RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList *)NULL, (LTE_SL_CommConfig_r12_t *)&sl_CommConfig, (LTE_SL_DiscConfig_r12_t *)NULL @@ -7185,7 +8549,7 @@ rrc_eNB_generate_RRCConnectionReconfiguration_Sidelink( (LTE_DRB_ToReleaseList_t *)NULL, // DRB2_list, (struct LTE_SPS_Config *)NULL, // *sps_Config, NULL, NULL, NULL, NULL,NULL, - NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, (struct LTE_RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList *)NULL, (LTE_SL_CommConfig_r12_t *)NULL, (LTE_SL_DiscConfig_r12_t *)&sl_DiscConfig diff --git a/openair2/RRC/LTE/rrc_eNB_S1AP.c b/openair2/RRC/LTE/rrc_eNB_S1AP.c index ebacfc838119b779badc14625022513390247db5..5bfa8c443b7e4a47bdb834d4e734bc81cbbdf813 100644 --- a/openair2/RRC/LTE/rrc_eNB_S1AP.c +++ b/openair2/RRC/LTE/rrc_eNB_S1AP.c @@ -36,6 +36,7 @@ # include "rrc_eNB_S1AP.h" # include "enb_config.h" # include "common/ran_context.h" +# include "gtpv1u.h" # include "s1ap_eNB_defs.h" # include "s1ap_eNB_management_procedures.h" @@ -67,6 +68,11 @@ extern RAN_CONTEXT_t RC; +extern int +gtpv1u_delete_s1u_tunnel( + const instance_t instanceP, + const gtpv1u_enb_delete_tunnel_req_t * const req_pP); + /* Value to indicate an invalid UE initial id */ static const uint16_t UE_INITIAL_ID_INVALID = 0; @@ -270,7 +276,7 @@ rrc_eNB_S1AP_get_ue_ids( } else { LOG_E(RRC, "[eNB %ld] Incoherence between RRC context and S1AP context (%d != %d) for UE RNTI %d or UE RRC context doesn't exist\n", rrc_instance_pP - RC.rrc[0], - ue_context_p->ue_context.eNB_ue_s1ap_id, + (ue_context_p==NULL)?99999:ue_context_p->ue_context.eNB_ue_s1ap_id, eNB_ue_s1ap_id, result->ue_rnti); } @@ -300,8 +306,7 @@ rrc_eNB_S1AP_remove_ue_ids( ) //------------------------------------------------------------------------------ { - const uint16_t ue_initial_id = ue_ids_pP->ue_initial_id; - const uint32_t eNB_ue_s1ap_id = ue_ids_pP->eNB_ue_s1ap_id; + hashtable_rc_t h_rc; if (rrc_instance_pP == NULL) { @@ -313,7 +318,8 @@ rrc_eNB_S1AP_remove_ue_ids( LOG_E(RRC, "Trying to free a NULL S1AP UE IDs\n"); return; } - + const uint16_t ue_initial_id = ue_ids_pP->ue_initial_id; + const uint32_t eNB_ue_s1ap_id = ue_ids_pP->eNB_ue_s1ap_id; if (eNB_ue_s1ap_id > 0) { h_rc = hashtable_remove(rrc_instance_pP->s1ap_id2_s1ap_ids, (hash_key_t)eNB_ue_s1ap_id); @@ -840,6 +846,13 @@ rrc_eNB_send_S1AP_NAS_FIRST_REQ( S1AP_NAS_FIRST_REQ (message_p).ue_identity.gummei.mme_code = BIT_STRING_to_uint8 (&r_mme->mmec); S1AP_NAS_FIRST_REQ (message_p).ue_identity.gummei.mme_group_id = BIT_STRING_to_uint16 (&r_mme->mmegi); + + ue_context_pP->ue_context.ue_gummei.mcc = S1AP_NAS_FIRST_REQ (message_p).ue_identity.gummei.mcc; + ue_context_pP->ue_context.ue_gummei.mnc = S1AP_NAS_FIRST_REQ (message_p).ue_identity.gummei.mnc; + ue_context_pP->ue_context.ue_gummei.mnc_len = S1AP_NAS_FIRST_REQ (message_p).ue_identity.gummei.mnc_len; + ue_context_pP->ue_context.ue_gummei.mme_code = S1AP_NAS_FIRST_REQ (message_p).ue_identity.gummei.mme_code; + ue_context_pP->ue_context.ue_gummei.mme_group_id = S1AP_NAS_FIRST_REQ (message_p).ue_identity.gummei.mme_group_id; + MSC_LOG_TX_MESSAGE(MSC_S1AP_ENB, MSC_S1AP_MME, (const char *)&message_p->ittiMsg.s1ap_nas_first_req, @@ -996,6 +1009,8 @@ int rrc_eNB_process_S1AP_INITIAL_CONTEXT_SETUP_REQ(MessageDef *msg_p, const char } else { PROTOCOL_CTXT_SET_BY_INSTANCE(&ctxt, instance, ENB_FLAG_YES, ue_context_p->ue_context.rnti, 0, 0); ue_context_p->ue_context.eNB_ue_s1ap_id = S1AP_INITIAL_CONTEXT_SETUP_REQ (msg_p).eNB_ue_s1ap_id; + ue_context_p->ue_context.mme_ue_s1ap_id = S1AP_INITIAL_CONTEXT_SETUP_REQ (msg_p).mme_ue_s1ap_id; + /* Save e RAB information for later */ { int i; @@ -1931,5 +1946,231 @@ int rrc_eNB_process_PAGING_IND(MessageDef *msg_p, const char *msg_name, instance return (0); } +/*NN: careful about the typcast of xid (long -> uint8_t*/ +int rrc_eNB_send_PATH_SWITCH_REQ(const protocol_ctxt_t* const ctxt_pP, + rrc_eNB_ue_context_t* const ue_context_pP){ + + MessageDef *msg_p = NULL; + int e_rab = 0; + int e_rabs_done = 0; + + rrc_ue_s1ap_ids_t* rrc_ue_s1ap_ids_p = NULL; + hashtable_rc_t h_rc; + + gtpv1u_enb_create_tunnel_req_t create_tunnel_req; + gtpv1u_enb_create_tunnel_resp_t create_tunnel_resp; + + uint8_t inde_list[ue_context_pP->ue_context.nb_of_e_rabs]; + memset(inde_list, 0, ue_context_pP->ue_context.nb_of_e_rabs*sizeof(uint8_t)); + + msg_p = itti_alloc_new_message (TASK_RRC_ENB, S1AP_PATH_SWITCH_REQ); + + ue_context_pP->ue_context.ue_initial_id = get_next_ue_initial_id (ctxt_pP->module_id); + S1AP_PATH_SWITCH_REQ (msg_p).ue_initial_id = ue_context_pP->ue_context.ue_initial_id; + + rrc_ue_s1ap_ids_p = malloc(sizeof(*rrc_ue_s1ap_ids_p)); + rrc_ue_s1ap_ids_p->ue_initial_id = ue_context_pP->ue_context.ue_initial_id; + rrc_ue_s1ap_ids_p->eNB_ue_s1ap_id = UE_INITIAL_ID_INVALID; + rrc_ue_s1ap_ids_p->ue_rnti = ctxt_pP->rnti; + + h_rc = hashtable_insert(RC.rrc[ctxt_pP->module_id]->initial_id2_s1ap_ids, + (hash_key_t)ue_context_pP->ue_context.ue_initial_id, + rrc_ue_s1ap_ids_p); + if (h_rc != HASH_TABLE_OK) { + LOG_E(S1AP, "[eNB %d] Error while hashtable_insert in initial_id2_s1ap_ids ue_initial_id %u\n", + ctxt_pP->module_id, ue_context_pP->ue_context.ue_initial_id); + } + + S1AP_PATH_SWITCH_REQ (msg_p).eNB_ue_s1ap_id = ue_context_pP->ue_context.eNB_ue_s1ap_id; + + S1AP_PATH_SWITCH_REQ (msg_p).mme_ue_s1ap_id = ue_context_pP->ue_context.mme_ue_s1ap_id; + + S1AP_PATH_SWITCH_REQ (msg_p).ue_gummei.mcc = ue_context_pP->ue_context.ue_gummei.mcc; + S1AP_PATH_SWITCH_REQ (msg_p).ue_gummei.mnc = ue_context_pP->ue_context.ue_gummei.mnc; + S1AP_PATH_SWITCH_REQ (msg_p).ue_gummei.mnc_len = ue_context_pP->ue_context.ue_gummei.mnc_len; + S1AP_PATH_SWITCH_REQ (msg_p).ue_gummei.mme_code = ue_context_pP->ue_context.ue_gummei.mme_code; + S1AP_PATH_SWITCH_REQ (msg_p).ue_gummei.mme_group_id = ue_context_pP->ue_context.ue_gummei.mme_group_id; + + S1AP_PATH_SWITCH_REQ (msg_p).security_capabilities.encryption_algorithms=ue_context_pP->ue_context.security_capabilities.encryption_algorithms; + S1AP_PATH_SWITCH_REQ (msg_p).security_capabilities.integrity_algorithms=ue_context_pP->ue_context.security_capabilities.integrity_algorithms; + + LOG_I (RRC,"Path switch request: nb nb_of_e_rabs %u status %u\n", + ue_context_pP->ue_context.nb_of_e_rabs, + ue_context_pP->ue_context.e_rab[e_rab].status); + + memset(&create_tunnel_req, 0 , sizeof(create_tunnel_req)); + // the context for UE to be handovered is obtained through ho_req message + for (e_rab = 0; e_rab < ue_context_pP->ue_context.nb_of_e_rabs ; e_rab++) { + + if (ue_context_pP->ue_context.e_rab[e_rab].status == E_RAB_STATUS_ESTABLISHED) { + + create_tunnel_req.eps_bearer_id[e_rabs_done] = ue_context_pP->ue_context.e_rab[e_rab].param.e_rab_id; + create_tunnel_req.sgw_S1u_teid[e_rabs_done] = ue_context_pP->ue_context.e_rab[e_rab].param.gtp_teid; + memcpy(&create_tunnel_req.sgw_addr[e_rabs_done], + &ue_context_pP->ue_context.e_rab[e_rab].param.sgw_addr, + sizeof(transport_layer_addr_t)); + + inde_list[e_rabs_done] = e_rab; + e_rabs_done++; + } + } + + S1AP_PATH_SWITCH_REQ (msg_p).nb_of_e_rabs = e_rabs_done; + + create_tunnel_req.rnti = ue_context_pP->ue_context.rnti; + create_tunnel_req.num_tunnels = e_rabs_done; + + gtpv1u_create_s1u_tunnel( + ctxt_pP->instance, + &create_tunnel_req, + &create_tunnel_resp); + + rrc_eNB_process_GTPV1U_CREATE_TUNNEL_RESP( + ctxt_pP, + &create_tunnel_resp, + &inde_list[0]); + + for (e_rab = 0; e_rab < e_rabs_done; e_rab++) { + + S1AP_PATH_SWITCH_REQ (msg_p).e_rabs_tobeswitched[e_rab].e_rab_id = create_tunnel_resp.eps_bearer_id[e_rab]; + S1AP_PATH_SWITCH_REQ (msg_p).e_rabs_tobeswitched[e_rab].gtp_teid = create_tunnel_resp.enb_S1u_teid[e_rab]; + S1AP_PATH_SWITCH_REQ (msg_p).e_rabs_tobeswitched[e_rab].eNB_addr = create_tunnel_resp.enb_addr; + + LOG_I (RRC,"enb_gtp_addr (msg index %d, e_rab index %d, status %d): nb_of_e_rabs %d, e_rab_id %d, teid: %u, addr: %d.%d.%d.%d \n ", + e_rabs_done, e_rab, ue_context_pP->ue_context.e_rab[inde_list[e_rab]].status, + ue_context_pP->ue_context.nb_of_e_rabs, + S1AP_PATH_SWITCH_REQ (msg_p).e_rabs_tobeswitched[e_rab].e_rab_id, + S1AP_PATH_SWITCH_REQ (msg_p).e_rabs_tobeswitched[e_rab].gtp_teid, + S1AP_PATH_SWITCH_REQ (msg_p).e_rabs_tobeswitched[e_rab].eNB_addr.buffer[0], + S1AP_PATH_SWITCH_REQ (msg_p).e_rabs_tobeswitched[e_rab].eNB_addr.buffer[1], + S1AP_PATH_SWITCH_REQ (msg_p).e_rabs_tobeswitched[e_rab].eNB_addr.buffer[2], + S1AP_PATH_SWITCH_REQ (msg_p).e_rabs_tobeswitched[e_rab].eNB_addr.buffer[3]); + } + + // NN: add conditions for e_rabs_failed + if (e_rabs_done > 0) { + + LOG_I(RRC,"S1AP_PATH_SWITCH_REQ: sending the message: nb_of_erabstobeswitched %d, total e_rabs %d, index %d\n", + ue_context_pP->ue_context.nb_of_e_rabs, ue_context_pP->ue_context.setup_e_rabs, e_rab); + + MSC_LOG_TX_MESSAGE( + MSC_RRC_ENB, + MSC_S1AP_ENB, + (const char *)&S1AP_PATH_SWITCH_REQ (msg_p), + sizeof(s1ap_path_switch_req_t), + MSC_AS_TIME_FMT" PATH_SWITCH_REQ UE %X eNB_ue_s1ap_id %u e_rabs:%u succ", + MSC_AS_TIME_ARGS(ctxt_pP), + ue_context_pP->ue_id_rnti, + S1AP_PATH_SWITCH_REQ (msg_p).eNB_ue_s1ap_id, + e_rabs_done); + + + itti_send_msg_to_task (TASK_S1AP, ctxt_pP->instance, msg_p); + } + + return 0; +} + +int rrc_eNB_process_S1AP_PATH_SWITCH_REQ_ACK (MessageDef *msg_p, const char *msg_name, instance_t instance) +{ + uint16_t ue_initial_id; + uint32_t eNB_ue_s1ap_id; + //gtpv1u_enb_create_tunnel_req_t create_tunnel_req; + //gtpv1u_enb_create_tunnel_resp_t create_tunnel_resp; + + gtpv1u_enb_delete_tunnel_req_t delete_tunnel_req; + + struct rrc_eNB_ue_context_s* ue_context_p = NULL; + protocol_ctxt_t ctxt; + int i; + + ue_initial_id = S1AP_PATH_SWITCH_REQ_ACK (msg_p).ue_initial_id; + eNB_ue_s1ap_id = S1AP_PATH_SWITCH_REQ_ACK (msg_p).eNB_ue_s1ap_id; + ue_context_p = rrc_eNB_get_ue_context_from_s1ap_ids(instance, ue_initial_id, eNB_ue_s1ap_id); + LOG_I(RRC, "[eNB %d] Received %s: ue_initial_id %d, eNB_ue_s1ap_id %d, nb_of_e_rabs %d\n", + instance, msg_name, ue_initial_id, eNB_ue_s1ap_id, S1AP_E_RAB_SETUP_REQ (msg_p).nb_e_rabs_tosetup); + + if (ue_context_p == NULL) { + /* Can not associate this message to an UE index, send a failure to S1AP and discard it! */ + //MessageDef *msg_fail_p = NULL; + + LOG_W(RRC, "[eNB %d] In S1AP_PATH_SWITCH_REQ_ACK: unknown UE from S1AP ids (%d, %d)\n", instance, ue_initial_id, eNB_ue_s1ap_id); + + //msg_fail_p = itti_alloc_new_message (TASK_RRC_ENB, S1AP_PATH_SWITCH_REQ_ACK_FAIL); + //S1AP_PATH_SWITCH_REQ_ACK (msg_fail_p).eNB_ue_s1ap_id = eNB_ue_s1ap_id; + + // TODO add failure cause when defined! + + //itti_send_msg_to_task (TASK_S1AP, instance, msg_fail_p); + return (-1); + } else { + + PROTOCOL_CTXT_SET_BY_INSTANCE(&ctxt, instance, ENB_FLAG_YES, ue_context_p->ue_context.rnti, 0, 0); + ue_context_p->ue_context.eNB_ue_s1ap_id = S1AP_PATH_SWITCH_REQ_ACK (msg_p).eNB_ue_s1ap_id; + ue_context_p->ue_context.mme_ue_s1ap_id = S1AP_PATH_SWITCH_REQ_ACK (msg_p).mme_ue_s1ap_id; + + /* Save e RAB information for later */ + { + for (i = 0; + i < ue_context_p->ue_context.setup_e_rabs; // go over total number of e_rabs received through x2_ho_req msg + i++) { + // assume that we are releasing all the DRBs + ue_context_p->ue_context.e_rab[i].status = E_RAB_STATUS_TORELEASE; + } + + //memset(&create_tunnel_req, 0 , sizeof(create_tunnel_req)); + //uint8_t nb_e_rabs_tobeswitched = S1AP_PATH_SWITCH_REQ_ACK (msg_p).nb_e_rabs_tobeswitched; + + // keep the previous bearer + // the index for the rec + for (i = 0; + i < 1;//nb_e_rabs_tobeswitched; // go over total number of e_rabs received through x2_ho_req msg + i++) { + LOG_I(RRC,"Bearer re-established with ID: %d\n", ue_context_p->ue_context.e_rab[i].param.e_rab_id); + /* Harmonize with enb_gtp_teid, enb_gtp_addrs, and enb_gtp_rbi vars in the top level structure */ + ue_context_p->ue_context.e_rab[i].status = E_RAB_STATUS_REESTABLISHED; + //ue_context_p->ue_context.e_rab[i].param.e_rab_id = S1AP_PATH_SWITCH_REQ_ACK (msg_p).e_rabs_tobeswitched[i].e_rab_id; + //ue_context_p->ue_context.e_rab[i].param.sgw_addr= S1AP_PATH_SWITCH_REQ_ACK (msg_p).e_rabs_tobeswitched[i].sgw_addr; + //ue_context_p->ue_context.e_rab[i].param.gtp_teid = S1AP_PATH_SWITCH_REQ_ACK (msg_p).e_rabs_tobeswitched[i].gtp_teid; + /* Tunnel must have been already created in X2_HO_REQ procedure */ + } + + ue_context_p->ue_context.setup_e_rabs=i; + ue_context_p->ue_context.nb_of_e_rabs=i; + } + + ue_context_p->ue_context.ue_ambr=S1AP_PATH_SWITCH_REQ_ACK (msg_p).ue_ambr; + + + ue_context_p->ue_context.nb_release_of_e_rabs = S1AP_PATH_SWITCH_REQ_ACK (msg_p).nb_e_rabs_tobereleased; + memset(&delete_tunnel_req, 0 , sizeof(delete_tunnel_req)); + for (i = 0; + i < ue_context_p->ue_context.nb_release_of_e_rabs; + i++) { + LOG_I(RRC,"Bearer released with ID: %d\n", ue_context_p->ue_context.e_rab[i].param.e_rab_id); + ue_context_p->ue_context.e_rabs_tobereleased[i]=S1AP_PATH_SWITCH_REQ_ACK (msg_p).e_rabs_tobereleased[i].e_rab_id; + delete_tunnel_req.eps_bearer_id[i] = S1AP_PATH_SWITCH_REQ_ACK (msg_p).e_rabs_tobereleased[i].e_rab_id; + + } + if (ue_context_p->ue_context.nb_release_of_e_rabs>0){ + delete_tunnel_req.rnti= ue_context_p->ue_context.rnti; + delete_tunnel_req.num_erab= ue_context_p->ue_context.nb_release_of_e_rabs; + /* this could also be done through ITTI message */ + gtpv1u_delete_s1u_tunnel(instance, + &delete_tunnel_req); + /* TBD: release the DRB not admitted */ + //rrc_eNB_generate_dedicatedRRCConnectionReconfiguration(&ctxt, ue_context_p, 0); + } + + /* Security key */ + ue_context_p->ue_context.next_hop_chain_count=S1AP_PATH_SWITCH_REQ_ACK (msg_p).next_hop_chain_count; + memcpy ( ue_context_p->ue_context.next_security_key, + S1AP_PATH_SWITCH_REQ_ACK (msg_p).next_security_key, + SECURITY_KEY_LENGTH); + + return (0); + } +} + # endif /* defined(ENABLE_ITTI) */ #endif /* defined(ENABLE_USE_MME) */ diff --git a/openair2/RRC/LTE/rrc_eNB_S1AP.h b/openair2/RRC/LTE/rrc_eNB_S1AP.h index eb427bc7bd9e474cac11326d4241947408bdfd10..dc6caf15263f8e61752ff8515998d71517d94e59 100644 --- a/openair2/RRC/LTE/rrc_eNB_S1AP.h +++ b/openair2/RRC/LTE/rrc_eNB_S1AP.h @@ -269,6 +269,10 @@ int rrc_eNB_process_S1AP_E_RAB_RELEASE_COMMAND(MessageDef *msg_p, const char *ms */ int rrc_eNB_send_S1AP_E_RAB_RELEASE_RESPONSE(const protocol_ctxt_t* const ctxt_pP, rrc_eNB_ue_context_t* const ue_context_pP, uint8_t xid ); +int rrc_eNB_send_PATH_SWITCH_REQ(const protocol_ctxt_t* const ctxt_pP, + rrc_eNB_ue_context_t* const ue_context_pP); +int rrc_eNB_process_S1AP_PATH_SWITCH_REQ_ACK (MessageDef *msg_p, const char *msg_name, instance_t instance); + # endif # endif /* defined(ENABLE_USE_MME) */ #endif /* RRC_ENB_S1AP_H_ */ diff --git a/openair2/RRC/LTE/rrc_proto.h b/openair2/RRC/LTE/rrc_proto.h index 3777f3ea26b5c3b71e338e7ab61c30856cbdf8e0..831f8d11ac6ab5497a700883216bbfa2d5d669e6 100644 --- a/openair2/RRC/LTE/rrc_proto.h +++ b/openair2/RRC/LTE/rrc_proto.h @@ -32,7 +32,7 @@ */ #include "RRC/LTE/rrc_defs.h" - +#include "x2ap_messages_types.h" #include "flexran_agent_extern.h" //main.c @@ -309,6 +309,15 @@ flexran_rrc_eNB_generate_defaultRRCConnectionReconfiguration( const uint8_t ho_state, agent_reconf_rrc * trig_param ); +void +rrc_eNB_generate_HO_RRCConnectionReconfiguration(const protocol_ctxt_t* const ctxt_pP, + rrc_eNB_ue_context_t* const ue_context_pP, + uint8_t* buffer, + int *_size + //const uint8_t ho_state + ); +void +rrc_eNB_configure_rbs_handover(struct rrc_eNB_ue_context_s* ue_context_p, protocol_ctxt_t* const ctxt_pP); int freq_to_arfcn10(int band, unsigned long freq); @@ -349,6 +358,8 @@ void *rrc_enb_task(void *args_p); void *rrc_ue_task(void *args_p); #endif +void rrc_eNB_process_handoverPreparationInformation(int mod_id, x2ap_handover_req_t *m); + /**\brief Generate/decode the handover RRCConnectionReconfiguration at eNB \param module_idP Instance ID for eNB/CH \param frame Frame index @@ -580,9 +591,11 @@ rrc_eNB_process_MeasurementReport( void rrc_eNB_generate_HandoverPreparationInformation( - const protocol_ctxt_t* const ctxt_pP, + //const protocol_ctxt_t* const ctxt_pP, rrc_eNB_ue_context_t* const ue_context_pP, - LTE_PhysCellId_t targetPhyId + uint8_t* buffer, + int *_size + //LTE_PhysCellId_t targetPhyId ); void diff --git a/openair2/UTIL/ASYNC_IF/message_queue.c b/openair2/UTIL/ASYNC_IF/message_queue.c index 5a33fbfabe7c8a027e15a3dedb6d2e7da2cff67a..2581840388a8ed4e3dfe6380c1d31790d313001e 100644 --- a/openair2/UTIL/ASYNC_IF/message_queue.c +++ b/openair2/UTIL/ASYNC_IF/message_queue.c @@ -193,10 +193,11 @@ int main(void) sprintf(s, "hello"); if (message_put(q, s, 6, 0)) goto error; destroy_message_queue(q); - + free(s); return 0; error: + free(s); printf("error\n"); return 1; } diff --git a/openair2/UTIL/FIFO/pad_list.c b/openair2/UTIL/FIFO/pad_list.c index 32a9f3519640a020df52ebc60add66f9a0fb3bac..e15041118d0f182492d34f596c829c988c0dd371 100644 --- a/openair2/UTIL/FIFO/pad_list.c +++ b/openair2/UTIL/FIFO/pad_list.c @@ -35,25 +35,19 @@ //#include <mpi.h> -void job_list_init (Job_List_t * listP) -{ - +void job_list_init (Job_List_t *listP) { listP->tail = NULL; listP->head = NULL; listP->nb_elements = 0; } -void event_list_init (Event_List_t * listP) -{ - +void event_list_init (Event_List_t *listP) { listP->tail = NULL; listP->head = NULL; listP->nb_elements = 0; } -void pkt_list_init (Packet_OTG_List_t * listP) -{ - +void pkt_list_init (Packet_OTG_List_t *listP) { listP->tail = NULL; listP->head = NULL; listP->nb_elements = 0; @@ -61,8 +55,7 @@ void pkt_list_init (Packet_OTG_List_t * listP) //----------------------------------------------------------------------------- -void job_list_free (Job_List_t * listP) -{ +void job_list_free (Job_List_t *listP) { Job_elt_t *le; while ((le = job_list_remove_head (listP))) { @@ -70,8 +63,7 @@ void job_list_free (Job_List_t * listP) } } -void event_list_free (Event_List_t * listP) -{ +void event_list_free (Event_List_t *listP) { Event_elt_t *le; while ((le = event_list_remove_head (listP))) { @@ -79,8 +71,7 @@ void event_list_free (Event_List_t * listP) } } -void pkt_list_free (Packet_OTG_List_t * listP) -{ +void pkt_list_free (Packet_OTG_List_t *listP) { Packet_otg_elt_t *le; while ((le = pkt_list_remove_head (listP))) { @@ -90,18 +81,15 @@ void pkt_list_free (Packet_OTG_List_t * listP) //----------------------------------------------------------------------------- -Job_elt_t * job_list_get_head (Job_List_t * listP) -{ +Job_elt_t *job_list_get_head (Job_List_t *listP) { return listP->head; } -Event_elt_t * event_list_get_head (Event_List_t * listP) -{ +Event_elt_t *event_list_get_head (Event_List_t *listP) { return listP->head; } -Packet_otg_elt_t * pkt_list_get_head (Packet_OTG_List_t * listP) -{ +Packet_otg_elt_t *pkt_list_get_head (Packet_OTG_List_t *listP) { return listP->head; } @@ -112,9 +100,7 @@ Packet_otg_elt_t * pkt_list_get_head (Packet_OTG_List_t * listP) * @param pointer on targeted list * @return pointer on removed Job_elt_t */ -Job_elt_t * job_list_remove_head (Job_List_t * listP) -{ - +Job_elt_t *job_list_remove_head (Job_List_t *listP) { // access optimisation Job_elt_t *head; head = listP->head; @@ -137,9 +123,7 @@ Job_elt_t * job_list_remove_head (Job_List_t * listP) return head; } -Event_elt_t * event_list_remove_head (Event_List_t * listP) -{ - +Event_elt_t *event_list_remove_head (Event_List_t *listP) { // access optimisation Event_elt_t *head; head = listP->head; @@ -162,9 +146,7 @@ Event_elt_t * event_list_remove_head (Event_List_t * listP) return head; } -Packet_otg_elt_t * pkt_list_remove_head (Packet_OTG_List_t * listP) -{ - +Packet_otg_elt_t *pkt_list_remove_head (Packet_OTG_List_t *listP) { // access optimisation Packet_otg_elt_t *head; head = listP->head; @@ -189,9 +171,7 @@ Packet_otg_elt_t * pkt_list_remove_head (Packet_OTG_List_t * listP) //----------------------------------------------------------------------------- -Job_elt_t * job_list_remove_element (Job_elt_t * elementP, Job_List_t * listP) -{ - +Job_elt_t *job_list_remove_element (Job_elt_t *elementP, Job_List_t *listP) { // access optimisation; Job_elt_t *head; @@ -233,9 +213,7 @@ Job_elt_t * job_list_remove_element (Job_elt_t * elementP, Job_List_t * listP) return elementP; } -Event_elt_t * event_list_remove_element (Event_elt_t * elementP, Event_List_t * listP) -{ - +Event_elt_t *event_list_remove_element (Event_elt_t *elementP, Event_List_t *listP) { // access optimisation; Event_elt_t *head; @@ -277,9 +255,7 @@ Event_elt_t * event_list_remove_element (Event_elt_t * elementP, Event_List_t * return elementP; } -Packet_otg_elt_t * pkt_list_remove_element (Packet_otg_elt_t * elementP, Packet_OTG_List_t * listP) -{ - +Packet_otg_elt_t *pkt_list_remove_element (Packet_otg_elt_t *elementP, Packet_OTG_List_t *listP) { // access optimisation; Packet_otg_elt_t *head; @@ -328,9 +304,7 @@ Packet_otg_elt_t * pkt_list_remove_element (Packet_otg_elt_t * elementP, Packet_ * @return pointer on removed Job_elt_t */ -void job_list_add_head (Job_elt_t * elementP, Job_List_t * listP) -{ - +void job_list_add_head (Job_elt_t *elementP, Job_List_t *listP) { // access optimisation; Job_elt_t *head; @@ -349,9 +323,7 @@ void job_list_add_head (Job_elt_t * elementP, Job_List_t * listP) } } -void event_list_add_head (Event_elt_t * elementP, Event_List_t * listP) -{ - +void event_list_add_head (Event_elt_t *elementP, Event_List_t *listP) { // access optimisation; Event_elt_t *head; @@ -370,9 +342,7 @@ void event_list_add_head (Event_elt_t * elementP, Event_List_t * listP) } } -void pkt_list_add_head (Packet_otg_elt_t * elementP, Packet_OTG_List_t * listP) -{ - +void pkt_list_add_head (Packet_otg_elt_t *elementP, Packet_OTG_List_t *listP) { // access optimisation; Packet_otg_elt_t *head; @@ -391,14 +361,12 @@ void pkt_list_add_head (Packet_otg_elt_t * elementP, Packet_OTG_List_t * listP) } } -void event_list_add_element (Event_elt_t * elementP, Event_elt_t * previous, Event_List_t * listP) -{ - +void event_list_add_element (Event_elt_t *elementP, Event_elt_t *previous, Event_List_t *listP) { // access optimisation; Event_elt_t *next; - elementP->next = NULL; if (elementP != NULL && previous != NULL) { + elementP->next = NULL; next = previous->next; listP->nb_elements = listP->nb_elements + 1; @@ -420,8 +388,7 @@ void event_list_add_element (Event_elt_t * elementP, Event_elt_t * previous, Eve * @param pointer on targeted list * @return pointer on removed Job_elt_t */ -void job_list_add_tail_eurecom (Job_elt_t * elementP, Job_List_t * listP) -{ +void job_list_add_tail_eurecom (Job_elt_t *elementP, Job_List_t *listP) { Job_elt_t *tail; if (elementP != NULL) { @@ -443,8 +410,7 @@ void job_list_add_tail_eurecom (Job_elt_t * elementP, Job_List_t * listP) } } -void event_list_add_tail_eurecom (Event_elt_t * elementP, Event_List_t * listP) -{ +void event_list_add_tail_eurecom (Event_elt_t *elementP, Event_List_t *listP) { Event_elt_t *tail; if (elementP != NULL) { @@ -466,8 +432,7 @@ void event_list_add_tail_eurecom (Event_elt_t * elementP, Event_List_t * listP) } } -void pkt_list_add_tail_eurecom (Packet_otg_elt_t * elementP, Packet_OTG_List_t * listP) -{ +void pkt_list_add_tail_eurecom (Packet_otg_elt_t *elementP, Packet_OTG_List_t *listP) { Packet_otg_elt_t *tail; if (elementP != NULL) { @@ -490,14 +455,11 @@ void pkt_list_add_tail_eurecom (Packet_otg_elt_t * elementP, Packet_OTG_List_t * } //----------------------------------------------------------------------------- -void job_list_add_list (Job_List_t * sublistP, Job_List_t * listP) -{ - +void job_list_add_list (Job_List_t *sublistP, Job_List_t *listP) { if (sublistP) { if (sublistP->head) { // access optimisation Job_elt_t *tail; - tail = listP->tail; // almost one element @@ -517,14 +479,11 @@ void job_list_add_list (Job_List_t * sublistP, Job_List_t * listP) } } -void event_list_add_list (Event_List_t * sublistP, Event_List_t * listP) -{ - +void event_list_add_list (Event_List_t *sublistP, Event_List_t *listP) { if (sublistP) { if (sublistP->head) { // access optimisation Event_elt_t *tail; - tail = listP->tail; // almost one element @@ -544,14 +503,11 @@ void event_list_add_list (Event_List_t * sublistP, Event_List_t * listP) } } -void pkt_list_add_list (Packet_OTG_List_t * sublistP, Packet_OTG_List_t * listP) -{ - +void pkt_list_add_list (Packet_OTG_List_t *sublistP, Packet_OTG_List_t *listP) { if (sublistP) { if (sublistP->head) { // access optimisation Packet_otg_elt_t *tail; - tail = listP->tail; // almost one element @@ -572,11 +528,8 @@ void pkt_list_add_list (Packet_OTG_List_t * sublistP, Packet_OTG_List_t * listP) } //----------------------------------------------------------------------------- -void job_list_display (Job_List_t * listP) -{ - +void job_list_display (Job_List_t *listP) { //Correct the output once the content of struct Job is fixed - /*Job_elt_t *cursor; unsigned short nb_elements = 0; @@ -605,8 +558,7 @@ void job_list_display (Job_List_t * listP) }*/ } -void event_list_display (Event_List_t * listP) -{ +void event_list_display (Event_List_t *listP) { Event_elt_t *cursor; unsigned short nb_elements = 0; @@ -630,8 +582,7 @@ void event_list_display (Event_List_t * listP) } } -void pkt_list_display (Packet_OTG_List_t * listP) -{ +void pkt_list_display (Packet_OTG_List_t *listP) { Packet_otg_elt_t *cursor; unsigned short nb_elements = 0; diff --git a/openair2/UTIL/MATH/taus.c b/openair2/UTIL/MATH/taus.c index 632b1544dd0970b484fbe0a2ef4d585cae550604..6f1b2214e51b92ec07cbc21d9699664077f40633 100644 --- a/openair2/UTIL/MATH/taus.c +++ b/openair2/UTIL/MATH/taus.c @@ -41,9 +41,7 @@ unsigned int s0[MAX_NUM_COMPS], s1[MAX_NUM_COMPS], s2[MAX_NUM_COMPS], b[MAX_NUM_ -inline unsigned int taus(unsigned int comp) -{ - +inline unsigned int taus(unsigned int comp) { b[comp] = (((s0[comp] << 13) ^ s0[comp]) >> 19); s0[comp] = (((s0[comp] & 0xFFFFFFFE) << 12)^ b[comp]); b[comp] = (((s1[comp] << 2) ^ s1[comp]) >> 25); @@ -54,42 +52,36 @@ inline unsigned int taus(unsigned int comp) return r[comp]; } -void set_taus_seed(unsigned int seed_type) -{ - +void set_taus_seed(unsigned int seed_type) { unsigned int i; // i index of component for (i=MIN_NUM_COMPS; i < MAX_NUM_COMPS ; i ++) { - switch (seed_type) { - case 0: // use rand func - if (i == 0) srand(time(NULL)); - - s0[i] = ((unsigned int)rand()); - s1[i] = ((unsigned int)rand()); - s2[i] = ((unsigned int)rand()); - printf("Initial seeds use rand: s0[%d] = 0x%x, s1[%d] = 0x%x, s2[%d] = 0x%x\n", i, s0[i], i, s1[i], i, s2[i]); - break; - - case 1: // use rand with seed - if (i == 0) srand(0x1e23d851); - - s0[i] = ((unsigned int)rand()); - s1[i] = ((unsigned int)rand()); - s2[i] = ((unsigned int)rand()); - printf("Initial seeds use rand with seed : s0[%d] = 0x%x, s1[%d] = 0x%x, s2[%d] = 0x%x\n", i, s0[i], i, s1[i], i, s2[i]); - - break; - - default: - break; - + case 0: // use rand func + if (i == 0) srand(time(NULL)); + + s0[i] = ((unsigned int)rand()); + s1[i] = ((unsigned int)rand()); + s2[i] = ((unsigned int)rand()); + printf("Initial seeds use rand: s0[%u] = 0x%x, s1[%u] = 0x%x, s2[%u] = 0x%x\n", i, s0[i], i, s1[i], i, s2[i]); + break; + + case 1: // use rand with seed + if (i == 0) srand(0x1e23d851); + + s0[i] = ((unsigned int)rand()); + s1[i] = ((unsigned int)rand()); + s2[i] = ((unsigned int)rand()); + printf("Initial seeds use rand with seed : s0[%u] = 0x%x, s1[%u] = 0x%x, s2[%u] = 0x%x\n", i, s0[i], i, s1[i], i, s2[i]); + break; + + default: + break; } } } -int get_rand (unsigned int comp) -{ +int get_rand (unsigned int comp) { if ((comp > MIN_NUM_COMPS) && (comp < MAX_NUM_COMPS)) return r[comp]; else { @@ -98,9 +90,7 @@ int get_rand (unsigned int comp) } } -unsigned int dtaus(unsigned int comp, unsigned int a, unsigned b) -{ - +unsigned int dtaus(unsigned int comp, unsigned int a, unsigned b) { return (int) (((double)taus(comp)/(double)0xffffffff)* (double)(b-a) + (double)a); } /* diff --git a/openair2/UTIL/OCG/OCG_config_mobi.c b/openair2/UTIL/OCG/OCG_config_mobi.c index cef4c5543b0705f90c9122c0ec6e69dd8d208417..b3100a421463dbc6bc8d3c1e7222c7166b2907cb 100644 --- a/openair2/UTIL/OCG/OCG_config_mobi.c +++ b/openair2/UTIL/OCG/OCG_config_mobi.c @@ -39,84 +39,60 @@ #include "OCG_config_mobi.h" /*----------------------------------------------------------------------------*/ -int config_mobi(char mobigen_filename[FILENAME_LENGTH_MAX], char filename[FILENAME_LENGTH_MAX]) -{ +int config_mobi(char mobigen_filename[FILENAME_LENGTH_MAX], char filename[FILENAME_LENGTH_MAX]) { // for the xml writer, refer to http://xmlsoft.org/html/libxml-xmlwriter.html - - char dir_to_mobigen_file[FILENAME_LENGTH_MAX + DIR_LENGTH_MAX] = ""; + char dir_to_mobigen_file[FILENAME_LENGTH_MAX + DIR_LENGTH_MAX]; char mobi_file[FILENAME_LENGTH_MAX + DIR_LENGTH_MAX] = ""; xmlTextWriterPtr writer; - strcpy(dir_to_mobigen_file, DIR_TO_MOBIGEN); strcat(dir_to_mobigen_file, mobigen_filename); /* Create a new XmlWriter for uri, with no compression. */ writer = xmlNewTextWriterFilename(dir_to_mobigen_file, 0); - // set the output format of the XML file xmlTextWriterSetIndent(writer, 1); xmlTextWriterSetIndentString(writer, " "); - /* Start the document with the xml default for the version, * encoding ISO 8859-1 and the default for the standalone * declaration. */ xmlTextWriterStartDocument(writer, NULL, NULL, NULL); - /* Start an element named "EXAMPLE". Since this is the first * element, this will be the root element of the document. */ xmlTextWriterStartElement(writer, "universe"); - /* Write an element named "X_ORDER_ID" as child of HEADER. */ xmlTextWriterWriteFormatElement(writer, "dimx", "%lf", oai_emulation.topo_config.area.x); - /* Write an element named "X_ORDER_ID" as child of HEADER. */ xmlTextWriterWriteFormatElement(writer, "dimy", "%lf", oai_emulation.topo_config.area.y); - xmlTextWriterWriteFormatElement(writer, "seed", "%d", 1); - xmlTextWriterStartElement(writer, "extension"); xmlTextWriterWriteAttribute(writer, "class", "de.uni_stuttgart.informatik.canu.mobisim.simulations.TimeSimulation"); xmlTextWriterWriteFormatAttribute(writer, "param", "%lf", oai_emulation.emu_config.emu_time); xmlTextWriterEndElement(writer); - xmlTextWriterStartElement(writer, "extension"); xmlTextWriterWriteAttribute(writer, "class", "de.uni_stuttgart.informatik.canu.spatialmodel.core.SpatialModel"); xmlTextWriterWriteFormatAttribute(writer, "max_x", "%lf", oai_emulation.topo_config.area.x); xmlTextWriterWriteFormatAttribute(writer, "max_y", "%lf", oai_emulation.topo_config.area.y); xmlTextWriterWriteAttribute(writer, "min_x", "0"); xmlTextWriterWriteAttribute(writer, "min_y", "0"); - xmlTextWriterWriteFormatElement(writer, "dump_boundary_points", "%s", "false"); - xmlTextWriterWriteFormatElement(writer, "separated_flow", "%s", "false"); - xmlTextWriterWriteFormatElement(writer, "max_traffic_lights", "%d", 500); - xmlTextWriterEndElement(writer); - xmlTextWriterStartElement(writer, "extension"); xmlTextWriterWriteAttribute(writer, "class", "de.uni_stuttgart.informatik.canu.mobisim.extensions.ReportNodeMobility"); - strcpy(mobi_file, MOBI_XML_FOLDER); strcat(mobi_file, filename); xmlTextWriterWriteAttribute(writer, "output", mobi_file); - xmlTextWriterWriteFormatElement(writer, "step", "%d", 1); - xmlTextWriterEndElement(writer); - xmlTextWriterStartElement(writer, "nodegroup"); xmlTextWriterWriteAttribute(writer, "car2x", "false"); xmlTextWriterWriteAttribute(writer, "id", ""); xmlTextWriterWriteAttribute(writer, "n", "50"); xmlTextWriterWriteAttribute(writer, "type", "car"); - xmlTextWriterStartElement(writer, "position"); xmlTextWriterWriteAttribute(writer, "random", "true"); - xmlTextWriterWriteFormatElement(writer, "z", "%s", "0.0"); - xmlTextWriterEndElement(writer); - xmlTextWriterStartElement(writer, "extension"); xmlTextWriterWriteAttribute(writer, "class", "de.uni_stuttgart.informatik.canu.mobisim.mobilitymodels.RandomWaypointWalk"); @@ -134,12 +110,8 @@ int config_mobi(char mobigen_filename[FILENAME_LENGTH_MAX], char filename[FILENA // Close the element named HEADER. xmlTextWriterEndElement(writer); - - xmlTextWriterEndDocument(writer); - xmlFreeTextWriter(writer); - return MODULE_OK; } diff --git a/openair2/UTIL/OCG/OCG_generate_report.c b/openair2/UTIL/OCG/OCG_generate_report.c index fa1ed191e62afa1cc9fa7cb1d9b8a5f38ac9dcc6..a48b3a7af7583bf46628dfe5053364ca65886dd8 100644 --- a/openair2/UTIL/OCG/OCG_generate_report.c +++ b/openair2/UTIL/OCG/OCG_generate_report.c @@ -42,39 +42,29 @@ /*----------------------------------------------------------------------------*/ -int generate_report(char dst_dir[DIR_LENGTH_MAX], char filename[FILENAME_LENGTH_MAX]) -{ +int generate_report(char dst_dir[DIR_LENGTH_MAX], char filename[FILENAME_LENGTH_MAX]) { // for the xml writer, refer to http://xmlsoft.org/html/libxml-xmlwriter.html - - char dst_file[FILENAME_LENGTH_MAX + DIR_LENGTH_MAX] = ""; - strncat(dst_file, dst_dir, FILENAME_LENGTH_MAX + DIR_LENGTH_MAX - strlen(dst_file) - 1); - strncat(dst_file, filename, FILENAME_LENGTH_MAX + DIR_LENGTH_MAX - strlen(dst_file) - 1); - + char dst_file[FILENAME_LENGTH_MAX + DIR_LENGTH_MAX]; + strncpy(dst_file, dst_dir, FILENAME_LENGTH_MAX + DIR_LENGTH_MAX - strlen(filename) - 1); + strcat(dst_file, filename); xmlTextWriterPtr writer; - writer = xmlNewTextWriterFilename(dst_file, 0); - // set the output format of the XML file xmlTextWriterSetIndent(writer, 1); - xmlTextWriterSetIndentString(writer,(unsigned char*) " "); - + xmlTextWriterSetIndentString(writer,(unsigned char *) " "); xmlTextWriterStartDocument(writer, NULL, NULL, NULL); - /* Write an element named "X_ORDER_ID" as child of HEADER. */ - xmlTextWriterWriteFormatElement(writer,(unsigned char*) "COMMENT ", " in this output file, %d means NOT_PROCESSED; %d means NO_FILE; %d means ERROR; %d means OK ", MODULE_NOT_PROCESSED, + xmlTextWriterWriteFormatElement(writer,(unsigned char *) "COMMENT ", " in this output file, %d means NOT_PROCESSED; %d means NO_FILE; %d means ERROR; %d means OK ", MODULE_NOT_PROCESSED, NO_FILE, MODULE_ERROR, MODULE_OK); - xmlTextWriterWriteFormatElement(writer,(unsigned char*) "OCG_GET_OPT ", " %d ", get_opt_OK); - xmlTextWriterWriteFormatElement(writer,(unsigned char*) "OCG_DETECT_FILE ", " %d ", detect_file_OK); - xmlTextWriterWriteFormatElement(writer,(unsigned char*) "OCG_PARSE_FILENAME", " %d ", parse_filename_OK); - xmlTextWriterWriteFormatElement(writer,(unsigned char*) "OCG_CREATE_DIR ", " %d ", create_dir_OK); - xmlTextWriterWriteFormatElement(writer,(unsigned char*) "OCG_PARSE_XML ", " %d ", parse_XML_OK); - xmlTextWriterWriteFormatElement(writer,(unsigned char*) "OCG_SAVE_XML ", " %d ", save_XML_OK); + xmlTextWriterWriteFormatElement(writer,(unsigned char *) "OCG_GET_OPT ", " %d ", get_opt_OK); + xmlTextWriterWriteFormatElement(writer,(unsigned char *) "OCG_DETECT_FILE ", " %d ", detect_file_OK); + xmlTextWriterWriteFormatElement(writer,(unsigned char *) "OCG_PARSE_FILENAME", " %d ", parse_filename_OK); + xmlTextWriterWriteFormatElement(writer,(unsigned char *) "OCG_CREATE_DIR ", " %d ", create_dir_OK); + xmlTextWriterWriteFormatElement(writer,(unsigned char *) "OCG_PARSE_XML ", " %d ", parse_XML_OK); + xmlTextWriterWriteFormatElement(writer,(unsigned char *) "OCG_SAVE_XML ", " %d ", save_XML_OK); // xmlTextWriterWriteFormatElement(writer, "OCG_CALL_EMU ", " %d ", call_emu_OK); - xmlTextWriterEndDocument(writer); - xmlFreeTextWriter(writer); - LOG_I(OCG, "A report of OCG is generated in directory \"%s\"\n\n", dst_dir); return MODULE_OK; } diff --git a/openair2/UTIL/OMG/omg.c b/openair2/UTIL/OMG/omg.c index 6a1ada01568b1d079b69f1e05264de868ff00fff..f13da86c9f7395f6d2076aa9325ae3f535239ac4 100644 --- a/openair2/UTIL/OMG/omg.c +++ b/openair2/UTIL/OMG/omg.c @@ -46,21 +46,20 @@ #include "grid.h" #include "steadystaterwp.h" #ifdef SUMO_IF -#include "sumo.h" -#endif + #include "sumo.h" +#endif #include "../OMV/structures.h" //#define STANDALONE float n_frames = 20.0; -int omv_write (int pfd, node_list * ue_node_list, Data_Flow_Unit omv_data); +int omv_write (int pfd, node_list *ue_node_list, Data_Flow_Unit omv_data); void omv_end (int pfd, Data_Flow_Unit omv_data); int omv_enabled; /*initialze global parameters*/ void -init_omg_global_params (void) -{ +init_omg_global_params (void) { int mob_t, node_t, i; xloc_div = 10.0; yloc_div = 10.0; @@ -86,92 +85,86 @@ init_omg_global_params (void) /*initiate mobility generator*/ void -init_mobility_generator (omg_global_param omg_param_list[]) -{ +init_mobility_generator (omg_global_param omg_param_list[]) { int node_t, mobility_t; for (node_t = eNB; node_t < MAX_NUM_NODE_TYPES; node_t++) { - mobility_t = omg_param_list[node_t].mobility_type; switch (mobility_t) { + case STATIC: + start_static_generator (omg_param_list[node_t]); + break; - case STATIC: - start_static_generator (omg_param_list[node_t]); - break; - - case RWP: - start_rwp_generator (omg_param_list[node_t]); - break; + case RWP: + start_rwp_generator (omg_param_list[node_t]); + break; - case RWALK: - start_rwalk_generator (omg_param_list[node_t]); - break; + case RWALK: + start_rwalk_generator (omg_param_list[node_t]); + break; - case TRACE: - start_trace_generator (omg_param_list[node_t]); - break; + case TRACE: + start_trace_generator (omg_param_list[node_t]); + break; #ifdef SUMO_IF - case SUMO: - start_sumo_generator (omg_param_list[node_t]); - break; -#endif - case STEADY_RWP: - start_steadystaterwp_generator (omg_param_list[node_t]); - break; - default: - LOG_W (OMG, "Unsupported generator\n"); - } + case SUMO: + start_sumo_generator (omg_param_list[node_t]); + break; +#endif + case STEADY_RWP: + start_steadystaterwp_generator (omg_param_list[node_t]); + break; + default: + LOG_W (OMG, "Unsupported generator\n"); + } } - } /**************************************************************************************/ /*stop sumo mobiity generator*/ void -stop_mobility_generator (omg_global_param * omg_param_list) -{ +stop_mobility_generator (omg_global_param *omg_param_list) { int i; for (i = 0; i < MAX_NUM_NODE_TYPES; i++) { switch (omg_param_list[i].mobility_type) { + case STATIC: + break; - case STATIC: - break; - - case RWP: - break; + case RWP: + break; - case RWALK: - break; + case RWALK: + break; - case TRACE: - clear_list (); - break; + case TRACE: + clear_list (); + break; - case STEADY_RWP: - break; + case STEADY_RWP: + break; #ifdef SUMO_IF - case SUMO: - stop_sumo_generator (); - //LOG_D(OMG," --------OMG will interface with SUMO for mobility generation-------- \n"); - break; -#endif - default: - LOG_W (OMG, "Unsupported generator\n"); + + case SUMO: + stop_sumo_generator (); + //LOG_D(OMG," --------OMG will interface with SUMO for mobility generation-------- \n"); + break; +#endif + + default: + LOG_W (OMG, "Unsupported generator\n"); } } - } /*****************************************************************************/ void -update_nodes (double cur_time) -{ +update_nodes (double cur_time) { //LOG_D(OMG, "UPDATE NODES" ); int i = 0; @@ -180,38 +173,38 @@ update_nodes (double cur_time) update_node_vector (i, cur_time); } } - } void -update_node_vector (int mobility_type, double cur_time) -{ +update_node_vector (int mobility_type, double cur_time) { //set_time(cur_time); switch (mobility_type) { - case RWP: - update_rwp_nodes (cur_time); - break; + case RWP: + update_rwp_nodes (cur_time); + break; - case RWALK: - update_rwalk_nodes (cur_time); - break; + case RWALK: + update_rwalk_nodes (cur_time); + break; - case TRACE: - update_trace_nodes (cur_time); - break; + case TRACE: + update_trace_nodes (cur_time); + break; #ifdef SUMO_IF - case SUMO: - // printf("in SUMO case \n"); - update_sumo_nodes (cur_time); - break; -#endif - case STEADY_RWP: - update_steadystaterwp_nodes (cur_time); - break; - - default: - LOG_W (OMG, "STATIC or Unsupported generator\n"); + + case SUMO: + // printf("in SUMO case \n"); + update_sumo_nodes (cur_time); + break; +#endif + + case STEADY_RWP: + update_steadystaterwp_nodes (cur_time); + break; + + default: + LOG_W (OMG, "STATIC or Unsupported generator\n"); } } @@ -219,50 +212,45 @@ update_node_vector (int mobility_type, double cur_time) /*return updated node position for a given node type*/ node_list * -get_current_positions (int mobility_type, int node_type, double cur_time) -{ - - +get_current_positions (int mobility_type, int node_type, double cur_time) { get_nodes_positions (mobility_type, cur_time); return node_vector[node_type]; - } /*update current position of nodes for specific mobility type*/ void -get_nodes_positions (int mobility_type, double cur_time) -{ +get_nodes_positions (int mobility_type, double cur_time) { //printf("%d \n",mobility_type); - switch (mobility_type) { - case STATIC: - break; + case STATIC: + break; - case RWP: - get_rwp_positions_updated (cur_time); - break; + case RWP: + get_rwp_positions_updated (cur_time); + break; - case RWALK: - get_rwalk_positions_updated (cur_time); - break; + case RWALK: + get_rwalk_positions_updated (cur_time); + break; - case TRACE: - get_trace_positions_updated (cur_time); - break; + case TRACE: + get_trace_positions_updated (cur_time); + break; #ifdef SUMO_IF - case SUMO: - LOG_I (OMG, "getting positions from SUMO\n"); - get_sumo_positions_updated (cur_time); - break; -#endif - case STEADY_RWP: - get_steadystaterwp_positions_updated (cur_time); - break; - - default: - LOG_E (OMG, " Unsupported generator \n"); - } + case SUMO: + LOG_I (OMG, "getting positions from SUMO\n"); + get_sumo_positions_updated (cur_time); + break; +#endif + + case STEADY_RWP: + get_steadystaterwp_positions_updated (cur_time); + break; + + default: + LOG_E (OMG, " Unsupported generator \n"); + } } /***************************************************************/ @@ -270,10 +258,8 @@ get_nodes_positions (int mobility_type, double cur_time) // get the position for a specific node node_struct * -get_node_position (int node_type, int nid) -{ +get_node_position (int node_type, int nid) { node_list *tmp; - tmp = node_vector[node_type]; while (tmp != NULL) { @@ -289,15 +275,12 @@ get_node_position (int node_type, int nid) /*set new mobility for a node*/ void -set_new_mob_type (int id, int node_t, int mob_t, double cur_time) -{ - +set_new_mob_type (int id, int node_t, int mob_t, double cur_time) { int prev_mob; node_list *tmp; //job_list *tmp2, *prev_job; pair_struct *pair; double pause_p; - //find previous mobility type tmp = node_vector[node_t]; @@ -313,7 +296,6 @@ set_new_mob_type (int id, int node_t, int mob_t, double cur_time) //end if (tmp != NULL && prev_mob != mob_t) { - //initialize node position if (mob_t == STATIC || mob_t == RWP || mob_t == RWALK || mob_t == STEADY_RWP) { tmp->node->x_pos = @@ -341,61 +323,57 @@ set_new_mob_type (int id, int node_t, int mob_t, double cur_time) //end switch (mob_t) { - - case STATIC: - - break; - - case RWP: - pair = (pair_struct *) malloc (sizeof (struct pair_struct)); - pair->b = tmp->node; - sleep_rwp_node (pair, cur_time); - job_vector[RWP] = addjob (pair, job_vector[RWP]); - break; - - case RWALK: - pair = (pair_struct *) malloc (sizeof (struct pair_struct)); - pair->b = tmp->node; - sleep_rwalk_node (pair, cur_time); - job_vector[RWALK] = addjob (pair, job_vector[RWALK]); - break; - - case STEADY_RWP: - tmp->node->event_num = 0; - pair = (pair_struct *) malloc (sizeof (struct pair_struct)); - pair->b = tmp->node; - pause_p = pause_probability (omg_param_list[node_t]); - - if (randomgen (0, 1) < pause_p) - sleep_steadystaterwp_node (pair, cur_time); - else - move_steadystaterwp_node (pair, cur_time); - - break; + case STATIC: + break; + + case RWP: + pair = (pair_struct *) malloc (sizeof (struct pair_struct)); + pair->b = tmp->node; + sleep_rwp_node (pair, cur_time); + job_vector[RWP] = addjob (pair, job_vector[RWP]); + break; + + case RWALK: + pair = (pair_struct *) malloc (sizeof (struct pair_struct)); + pair->b = tmp->node; + sleep_rwalk_node (pair, cur_time); + job_vector[RWALK] = addjob (pair, job_vector[RWALK]); + break; + + case STEADY_RWP: + tmp->node->event_num = 0; + pair = (pair_struct *) malloc (sizeof (struct pair_struct)); + pair->b = tmp->node; + pause_p = pause_probability (omg_param_list[node_t]); + + if (randomgen (0, 1) < pause_p) + sleep_steadystaterwp_node (pair, cur_time); + else + move_steadystaterwp_node (pair, cur_time); + + break; #ifdef SUMO_IF - case SUMO: - LOG_E (OMG, "not possible to change mobility type to sumo \n"); - break; + + case SUMO: + LOG_E (OMG, "not possible to change mobility type to sumo \n"); + break; #endif - case TRACE: - LOG_E (OMG, "not possible to change mobility type to trace \n"); - break; - default: - LOG_E (OMG, " Unsupported generator \n"); - } + case TRACE: + LOG_E (OMG, "not possible to change mobility type to trace \n"); + break; + default: + LOG_E (OMG, " Unsupported generator \n"); + } } - - } #ifdef STANDALONE /************************** get options ************************************/ void -usage (void) -{ +usage (void) { fprintf (stderr, "\n\t-X: assign maximum width of the simulation area for UE nodes(X_max)" "\n\t-x: assign minimum width of the simulation area for UE nodes(X_min)" @@ -443,8 +421,7 @@ usage (void) int -get_options (int argc, char *argv[]) -{ +get_options (int argc, char *argv[]) { int node_t; char tag; @@ -452,345 +429,342 @@ get_options (int argc, char *argv[]) getopt (argc, argv, "U:u:E:e:R:r:A:a:B:b:C:c:D:d:f:g:hI:i:J:j:k:L:l:N:n:P:p:S:s:T:t:vW:w:X:x:Y:y:Z:z:")) != EOF) { - - switch (tag) { - - case 'U': - if (atoi (optarg) < 0) { - usage (); - exit (1); - } - - omg_param_list[UE].nodes = atoi (optarg); - LOG_D (OMG, "#Number of UE nodes : %d \n", - omg_param_list[UE].nodes); - break; - - case 'E': - if (atoi (optarg) < 0) { - usage (); - exit (1); - } - - omg_param_list[eNB].nodes = atoi (optarg); - LOG_D (OMG, "#Number of eNB nodes : %d \n", - omg_param_list[eNB].nodes); - break; - - case 'R': - if (atoi (optarg) < 0) { - usage (); - exit (1); - } - - omg_param_list[RELAY].nodes = atoi (optarg); - LOG_D (OMG, "#Number of relay nodes : %d \n", - omg_param_list[RELAY].nodes); - break; - - case 'k': - if (atof (optarg) < 0) - LOG_E (OMG, "#Number of frames can not be negative \n"); - - n_frames = abs (atof (optarg)); - LOG_D (OMG, "#Number of frames : %f \n", n_frames); - break; - - case 'u': - if (atoi (optarg) < 0 || atoi (optarg) >= MAX_NUM_MOB_TYPES) { - usage (); - exit (1); - } - - omg_param_list[UE].mobility_type = atoi (optarg); - LOG_D (OMG, "#UE nodes mobility type: %d \n", - omg_param_list[UE].mobility_type); - break; - - case 'e': - if (atoi (optarg) < 0 || atoi (optarg) >= MAX_NUM_MOB_TYPES) { + case 'U': + if (atoi (optarg) < 0) { + usage (); + exit (1); + } + + omg_param_list[UE].nodes = atoi (optarg); + LOG_D (OMG, "#Number of UE nodes : %d \n", + omg_param_list[UE].nodes); + break; + + case 'E': + if (atoi (optarg) < 0) { + usage (); + exit (1); + } + + omg_param_list[eNB].nodes = atoi (optarg); + LOG_D (OMG, "#Number of eNB nodes : %d \n", + omg_param_list[eNB].nodes); + break; + + case 'R': + if (atoi (optarg) < 0) { + usage (); + exit (1); + } + + omg_param_list[RELAY].nodes = atoi (optarg); + LOG_D (OMG, "#Number of relay nodes : %d \n", + omg_param_list[RELAY].nodes); + break; + + case 'k': + if (atof (optarg) < 0) + LOG_E (OMG, "#Number of frames can not be negative \n"); + + n_frames = abs (atof (optarg)); + LOG_D (OMG, "#Number of frames : %f \n", n_frames); + break; + + case 'u': + if (atoi (optarg) < 0 || atoi (optarg) >= MAX_NUM_MOB_TYPES) { + usage (); + exit (1); + } + + omg_param_list[UE].mobility_type = atoi (optarg); + LOG_D (OMG, "#UE nodes mobility type: %d \n", + omg_param_list[UE].mobility_type); + break; + + case 'e': + if (atoi (optarg) < 0 || atoi (optarg) >= MAX_NUM_MOB_TYPES) { + usage (); + exit (1); + } + + omg_param_list[eNB].mobility_type = atoi (optarg); + LOG_D (OMG, "#eNB nodes mobility type: %d \n", + omg_param_list[eNB].mobility_type); + break; + + case 'r': + if (atoi (optarg) < 0 || atoi (optarg) >= MAX_NUM_MOB_TYPES) { + usage (); + exit (1); + } + + omg_param_list[RELAY].mobility_type = atoi (optarg); + LOG_D (OMG, "#relay nodes mobility type: %d \n", + omg_param_list[RELAY].mobility_type); + break; + + case 's': + if (atof (optarg) < 0) + LOG_E (OMG, "#min sleep can not be negative \n"); + + omg_param_list[UE].min_sleep = fabs (atof (optarg)); + LOG_D (OMG, "#UE min sleep is set to: %.2f \n", + omg_param_list[UE].min_sleep); + break; + + case 'S': + if (atof (optarg) < 0) + LOG_E (OMG, "#max_sleep can not be negative \n"); + + omg_param_list[UE].max_sleep = fabs (atof (optarg)); + LOG_D (OMG, "#UE max_sleep is set to : %.2f \n", + omg_param_list[UE].max_sleep); + break; + + case 'l': + if (atof (optarg) < 0) + LOG_E (OMG, "#min sleep can not be negative or zero \n"); + + if (atof (optarg) != 0) + omg_param_list[eNB].min_sleep = fabs (atof (optarg)); + + LOG_D (OMG, "#eNB min sleep is set to : %.2f \n", + omg_param_list[eNB].min_sleep); + break; + + case 'L': + if (atof (optarg) <= 0) + LOG_E (OMG, "#max_sleep can not be negative or zero \n"); + + if (atof (optarg) != 0) + omg_param_list[eNB].max_sleep = fabs (atof (optarg)); + + LOG_D (OMG, "#eNB max_sleep is set to : %.2f \n", + omg_param_list[eNB].max_sleep); + break; + + case 'p': + if (atof (optarg) < 0) + LOG_E (OMG, "#min sleep can not be negative \n"); + + omg_param_list[RELAY].min_sleep = fabs (atof (optarg)); + LOG_D (OMG, "#relay min sleep is set to: %.2f \n", + omg_param_list[RELAY].min_sleep); + break; + + case 'P': + if (atof (optarg) < 0) + LOG_E (OMG, "#max_sleep can not be negative \n"); + + omg_param_list[RELAY].max_sleep = fabs (atof (optarg)); + LOG_D (OMG, "#relay max_sleep is set to : %.2f \n", + omg_param_list[RELAY].max_sleep); + break; + + case 'd': + if (atof (optarg) < 0) + LOG_E (OMG, "#min_speed can not be negative \n"); + + if (atof (optarg) != 0) + omg_param_list[UE].min_speed = fabs (atof (optarg)); + + LOG_D (OMG, "#UE min_speed is set to: %.2f \n", + omg_param_list[UE].min_speed); + break; + + case 'D': + if (atof (optarg) < 0) + LOG_E (OMG, "#max_speed can not be negative \n"); + + omg_param_list[UE].max_speed = fabs (atof (optarg)); + LOG_D (OMG, "#UE max_speed is set to: %.2f \n", + omg_param_list[UE].max_speed); + break; + + case 'i': + if (atof (optarg) < 0) + LOG_E (OMG, "#min_speed can not be negative \n"); + + if (atof (optarg) != 0) + omg_param_list[eNB].min_speed = fabs (atof (optarg)); + + LOG_D (OMG, "#eNB min_speed is set to: %.2f \n", + omg_param_list[eNB].min_speed); + break; + + case 'I': + if (atof (optarg) < 0) + LOG_E (OMG, "#max_speed can not be negative \n"); + + omg_param_list[eNB].max_speed = fabs (atof (optarg)); + LOG_D (OMG, "#eNB max_speed is set to : %.2f \n", + omg_param_list[eNB].max_speed); + break; + + case 'a': + if (atof (optarg) < 0) + LOG_E (OMG, "#min_speed can not be negative \n"); + + if (atof (optarg) != 0) + omg_param_list[RELAY].min_speed = fabs (atof (optarg)); + + LOG_D (OMG, "#relay min_speed is set to : %.2f \n", + omg_param_list[RELAY].min_speed); + break; + + case 'A': + if (atof (optarg) < 0) + LOG_E (OMG, "#max_speed can not be negative \n"); + + omg_param_list[RELAY].max_speed = fabs (atof (optarg)); + LOG_D (OMG, "#relay max_speed is set to: %.2f \n", + omg_param_list[RELAY].max_speed); + break; + + case 'v': + omv_enabled = 1; + break; + + case 'X': + omg_param_list[UE].max_x = fabs (atof (optarg)); + LOG_D (OMG, "#UE X_max : %.2f \n", omg_param_list[UE].max_x); + break; + + case 'x': + omg_param_list[UE].min_x = fabs (atof (optarg)); + LOG_D (OMG, "#UE X_min : %.2f \n", omg_param_list[UE].min_x); + break; + + case 'C': + omg_param_list[eNB].max_x = fabs (atof (optarg)); + LOG_D (OMG, "#eNB X_max : %.2f \n", omg_param_list[eNB].max_x); + break; + + case 'c': + omg_param_list[eNB].min_x = fabs (atof (optarg)); + LOG_D (OMG, "#eNB X_min : %.2f \n", omg_param_list[eNB].min_x); + break; + + case 'B': + omg_param_list[RELAY].max_x = fabs (atof (optarg)); + LOG_D (OMG, "#relay X_max : %.2f \n", omg_param_list[RELAY].max_x); + break; + + case 'b': + omg_param_list[RELAY].min_x = fabs (atof (optarg)); + LOG_D (OMG, "#relay X_min : %.2f \n", omg_param_list[RELAY].min_x); + break; + + case 'Y': + omg_param_list[UE].max_y = fabs (atof (optarg)); + LOG_D (OMG, "#UE Y_max : %.2f \n", omg_param_list[UE].max_y); + break; + + case 'y': + omg_param_list[UE].min_y = fabs (atof (optarg)); + LOG_D (OMG, "#UE Y_min : %.2f \n", omg_param_list[UE].min_y); + break; + + case 'Z': + omg_param_list[eNB].max_y = fabs (atof (optarg)); + LOG_D (OMG, "#eNB Y_max : %.2f \n", omg_param_list[eNB].max_y); + break; + + case 'z': + omg_param_list[eNB].min_y = fabs (atof (optarg)); + LOG_D (OMG, "#eNB Y_min : %.2f \n", omg_param_list[eNB].min_y); + break; + + case 'W': + omg_param_list[RELAY].max_y = fabs (atof (optarg)); + LOG_D (OMG, "#relay Y_max : %.2f \n", omg_param_list[RELAY].max_y); + break; + + case 'w': + omg_param_list[RELAY].min_y = fabs (atof (optarg)); + LOG_D (OMG, "#relay Y_min : %.2f \n", omg_param_list[RELAY].min_y); + break; + + case 'J': + if (atof (optarg) < 0) + LOG_E (OMG, "#Journey_time_max can not be negative \n"); + + omg_param_list[UE].max_journey_time = fabs (atof (optarg)); + LOG_D (OMG, "UE Journey_time_max : %.2f \n", + omg_param_list[UE].max_journey_time); + break; + + case 'j': + if (atof (optarg) < 0) + LOG_E (OMG, "#Journey_time_min can not be negative \n"); + + omg_param_list[UE].min_journey_time = fabs (atof (optarg)); + LOG_D (OMG, "#UE Journey_time_min : %.2f \n", + omg_param_list[UE].min_journey_time); + break; + + case 'T': + if (atof (optarg) < 0) + LOG_E (OMG, "#Journey_time_max can not be negative \n"); + + omg_param_list[eNB].max_journey_time = fabs (atof (optarg)); + LOG_D (OMG, "#eNB Journey_time_max : %.2f \n", + omg_param_list[eNB].max_journey_time); + break; + + case 't': + if (atof (optarg) < 0) + LOG_E (OMG, "#Journey_time_min can not be negative \n"); + + omg_param_list[eNB].min_journey_time = fabs (atof (optarg)); + LOG_D (OMG, "#eNB Journey_time_min : %.2f \n", + omg_param_list[eNB].min_journey_time); + break; + + case 'N': + if (atof (optarg) < 0) + LOG_E (OMG, "#Journey_time_max can not be negative \n"); + + omg_param_list[RELAY].max_journey_time = fabs (atof (optarg)); + LOG_D (OMG, "#relay Journey_time_max : %.2f \n", + omg_param_list[RELAY].max_journey_time); + break; + + case 'n': + if (atof (optarg) < 0) + LOG_E (OMG, "#Journey_time_min can not be negative \n"); + + omg_param_list[RELAY].min_journey_time = fabs (atof (optarg)); + LOG_D (OMG, "#relay Journey_time_min : %.2f \n", + omg_param_list[RELAY].min_journey_time); + break; + + case 'f': + for (node_t = eNB; node_t < MAX_NUM_NODE_TYPES; node_t++) { + omg_param_list[node_t].seed = atoi (optarg); + LOG_D (OMG, "#Seed is %d \n", omg_param_list[node_t].seed); + } + + break; + + case 'g': + if (atoi (optarg) < 1 || atoi (optarg) > 2) { + LOG_E (OMG, "#value given for graph should be 1 or 2 \n"); + exit (-1); + } + + grid = abs (atof (optarg)); + LOG_D (OMG, "#graph value is %d \n", grid); + break; + + case 'h': usage (); - exit (1); - } - - omg_param_list[eNB].mobility_type = atoi (optarg); - LOG_D (OMG, "#eNB nodes mobility type: %d \n", - omg_param_list[eNB].mobility_type); - break; + break; - case 'r': - if (atoi (optarg) < 0 || atoi (optarg) >= MAX_NUM_MOB_TYPES) { + default: usage (); exit (1); - } - - omg_param_list[RELAY].mobility_type = atoi (optarg); - LOG_D (OMG, "#relay nodes mobility type: %d \n", - omg_param_list[RELAY].mobility_type); - break; - - case 's': - if (atof (optarg) < 0) - LOG_E (OMG, "#min sleep can not be negative \n"); - - omg_param_list[UE].min_sleep = fabs (atof (optarg)); - LOG_D (OMG, "#UE min sleep is set to: %.2f \n", - omg_param_list[UE].min_sleep); - break; - - case 'S': - if (atof (optarg) < 0) - LOG_E (OMG, "#max_sleep can not be negative \n"); - - omg_param_list[UE].max_sleep = fabs (atof (optarg)); - LOG_D (OMG, "#UE max_sleep is set to : %.2f \n", - omg_param_list[UE].max_sleep); - break; - - case 'l': - if (atof (optarg) < 0) - LOG_E (OMG, "#min sleep can not be negative or zero \n"); - - if (atof (optarg) != 0) - omg_param_list[eNB].min_sleep = fabs (atof (optarg)); - - LOG_D (OMG, "#eNB min sleep is set to : %.2f \n", - omg_param_list[eNB].min_sleep); - break; - - case 'L': - if (atof (optarg) <= 0) - LOG_E (OMG, "#max_sleep can not be negative or zero \n"); - - if (atof (optarg) != 0) - omg_param_list[eNB].max_sleep = fabs (atof (optarg)); - - LOG_D (OMG, "#eNB max_sleep is set to : %.2f \n", - omg_param_list[eNB].max_sleep); - break; - - case 'p': - if (atof (optarg) < 0) - LOG_E (OMG, "#min sleep can not be negative \n"); - - omg_param_list[RELAY].min_sleep = fabs (atof (optarg)); - LOG_D (OMG, "#relay min sleep is set to: %.2f \n", - omg_param_list[RELAY].min_sleep); - break; - - case 'P': - if (atof (optarg) < 0) - LOG_E (OMG, "#max_sleep can not be negative \n"); - - omg_param_list[RELAY].max_sleep = fabs (atof (optarg)); - LOG_D (OMG, "#relay max_sleep is set to : %.2f \n", - omg_param_list[RELAY].max_sleep); - break; - - case 'd': - if (atof (optarg) < 0) - LOG_E (OMG, "#min_speed can not be negative \n"); - - if (atof (optarg) != 0) - omg_param_list[UE].min_speed = fabs (atof (optarg)); - - LOG_D (OMG, "#UE min_speed is set to: %.2f \n", - omg_param_list[UE].min_speed); - break; - - case 'D': - if (atof (optarg) < 0) - LOG_E (OMG, "#max_speed can not be negative \n"); - - omg_param_list[UE].max_speed = fabs (atof (optarg)); - LOG_D (OMG, "#UE max_speed is set to: %.2f \n", - omg_param_list[UE].max_speed); - break; - - case 'i': - if (atof (optarg) < 0) - LOG_E (OMG, "#min_speed can not be negative \n"); - - if (atof (optarg) != 0) - omg_param_list[eNB].min_speed = fabs (atof (optarg)); - - LOG_D (OMG, "#eNB min_speed is set to: %.2f \n", - omg_param_list[eNB].min_speed); - break; - - case 'I': - if (atof (optarg) < 0) - LOG_E (OMG, "#max_speed can not be negative \n"); - - omg_param_list[eNB].max_speed = fabs (atof (optarg)); - LOG_D (OMG, "#eNB max_speed is set to : %.2f \n", - omg_param_list[eNB].max_speed); - break; - - case 'a': - if (atof (optarg) < 0) - LOG_E (OMG, "#min_speed can not be negative \n"); - - if (atof (optarg) != 0) - omg_param_list[RELAY].min_speed = fabs (atof (optarg)); - - LOG_D (OMG, "#relay min_speed is set to : %.2f \n", - omg_param_list[RELAY].min_speed); - break; - - case 'A': - if (atof (optarg) < 0) - LOG_E (OMG, "#max_speed can not be negative \n"); - - omg_param_list[RELAY].max_speed = fabs (atof (optarg)); - LOG_D (OMG, "#relay max_speed is set to: %.2f \n", - omg_param_list[RELAY].max_speed); - break; - - case 'v': - omv_enabled = 1; - break; - - case 'X': - omg_param_list[UE].max_x = fabs (atof (optarg)); - LOG_D (OMG, "#UE X_max : %.2f \n", omg_param_list[UE].max_x); - break; - - case 'x': - omg_param_list[UE].min_x = fabs (atof (optarg)); - LOG_D (OMG, "#UE X_min : %.2f \n", omg_param_list[UE].min_x); - break; - - case 'C': - omg_param_list[eNB].max_x = fabs (atof (optarg)); - LOG_D (OMG, "#eNB X_max : %.2f \n", omg_param_list[eNB].max_x); - break; - - case 'c': - omg_param_list[eNB].min_x = fabs (atof (optarg)); - LOG_D (OMG, "#eNB X_min : %.2f \n", omg_param_list[eNB].min_x); - break; - - case 'B': - omg_param_list[RELAY].max_x = fabs (atof (optarg)); - LOG_D (OMG, "#relay X_max : %.2f \n", omg_param_list[RELAY].max_x); - break; - - case 'b': - omg_param_list[RELAY].min_x = fabs (atof (optarg)); - LOG_D (OMG, "#relay X_min : %.2f \n", omg_param_list[RELAY].min_x); - break; - - case 'Y': - omg_param_list[UE].max_y = fabs (atof (optarg)); - LOG_D (OMG, "#UE Y_max : %.2f \n", omg_param_list[UE].max_y); - break; - - case 'y': - omg_param_list[UE].min_y = fabs (atof (optarg)); - LOG_D (OMG, "#UE Y_min : %.2f \n", omg_param_list[UE].min_y); - break; - - case 'Z': - omg_param_list[eNB].max_y = fabs (atof (optarg)); - LOG_D (OMG, "#eNB Y_max : %.2f \n", omg_param_list[eNB].max_y); - break; - - case 'z': - omg_param_list[eNB].min_y = fabs (atof (optarg)); - LOG_D (OMG, "#eNB Y_min : %.2f \n", omg_param_list[eNB].min_y); - break; - - case 'W': - omg_param_list[RELAY].max_y = fabs (atof (optarg)); - LOG_D (OMG, "#relay Y_max : %.2f \n", omg_param_list[RELAY].max_y); - break; - - case 'w': - omg_param_list[RELAY].min_y = fabs (atof (optarg)); - LOG_D (OMG, "#relay Y_min : %.2f \n", omg_param_list[RELAY].min_y); - break; - - case 'J': - if (atof (optarg) < 0) - LOG_E (OMG, "#Journey_time_max can not be negative \n"); - - omg_param_list[UE].max_journey_time = fabs (atof (optarg)); - LOG_D (OMG, "UE Journey_time_max : %.2f \n", - omg_param_list[UE].max_journey_time); - break; - - case 'j': - if (atof (optarg) < 0) - LOG_E (OMG, "#Journey_time_min can not be negative \n"); - - omg_param_list[UE].min_journey_time = fabs (atof (optarg)); - LOG_D (OMG, "#UE Journey_time_min : %.2f \n", - omg_param_list[UE].min_journey_time); - break; - - case 'T': - if (atof (optarg) < 0) - LOG_E (OMG, "#Journey_time_max can not be negative \n"); - - omg_param_list[eNB].max_journey_time = fabs (atof (optarg)); - LOG_D (OMG, "#eNB Journey_time_max : %.2f \n", - omg_param_list[eNB].max_journey_time); - break; - - case 't': - if (atof (optarg) < 0) - LOG_E (OMG, "#Journey_time_min can not be negative \n"); - - omg_param_list[eNB].min_journey_time = fabs (atof (optarg)); - LOG_D (OMG, "#eNB Journey_time_min : %.2f \n", - omg_param_list[eNB].min_journey_time); - break; - - case 'N': - if (atof (optarg) < 0) - LOG_E (OMG, "#Journey_time_max can not be negative \n"); - - omg_param_list[RELAY].max_journey_time = fabs (atof (optarg)); - LOG_D (OMG, "#relay Journey_time_max : %.2f \n", - omg_param_list[RELAY].max_journey_time); - break; - - case 'n': - if (atof (optarg) < 0) - LOG_E (OMG, "#Journey_time_min can not be negative \n"); - - omg_param_list[RELAY].min_journey_time = fabs (atof (optarg)); - LOG_D (OMG, "#relay Journey_time_min : %.2f \n", - omg_param_list[RELAY].min_journey_time); - break; - - case 'f': - for (node_t = eNB; node_t < MAX_NUM_NODE_TYPES; node_t++) { - omg_param_list[node_t].seed = atoi (optarg); - LOG_D (OMG, "#Seed is %d \n", omg_param_list[node_t].seed); - } - - break; - - case 'g': - if (atoi (optarg) < 1 || atoi (optarg) > 2) { - LOG_E (OMG, "#value given for graph should be 1 or 2 \n"); - exit (-1); - } - - grid = abs (atof (optarg)); - LOG_D (OMG, "#graph value is %d \n", grid); - break; - - case 'h': - usage (); - break; - - default: - usage (); - exit (1); } } @@ -800,8 +774,7 @@ get_options (int argc, char *argv[]) /**************************** main **********************************/ int -main (int argc, char *argv[]) -{ +main (int argc, char *argv[]) { int i, node_type; double cur_time = 0.0; double ms = 0.0; @@ -824,8 +797,6 @@ main (int argc, char *argv[]) //default parameters for (node_type = eNB; node_type < MAX_NUM_NODE_TYPES; node_type++) { - - if (node_type == UE) omg_param_list[node_type].nodes = 5; else @@ -857,22 +828,16 @@ main (int argc, char *argv[]) omg_param_list[node_type].sumo_port = 8890; } - init_omg_global_params (); //initialize global paramaters - get_options (argc, argv); // overwrite the default params if any input parameter for (node_type = eNB; node_type < MAX_NUM_NODE_TYPES; node_type++) { omg_param_list[node_type].max_vertices = max_vertices_ongrid (omg_param_list[node_type]); - omg_param_list[node_type].max_block_num = max_connecteddomains_ongrid (omg_param_list[node_type]); - } - - init_mobility_generator (omg_param_list); //initialize choosen mobility generator // ****************init omv******************** @@ -884,30 +849,25 @@ main (int argc, char *argv[]) LOG_I (EMU, "Stating the OMV path %s pfd[0] %d pfd[1] %d \n", full_name, pfd[0], pfd[1]); - - - - switch (fork ()) { - case -1: - perror ("fork failed \n"); - break; - - case 0: - if (close (pfd[1]) == -1) - perror ("close on write\n"); - - sprintf (fdstr, "%d", pfd[0]); - sprintf (num_enb, "%d", 1); - sprintf (num_ue, "%d", omg_param_list[UE].nodes); - sprintf (x_area, "%f", omg_param_list[UE].max_x); - sprintf (y_area, "%f", omg_param_list[UE].max_y); - sprintf (z_area, "%f", 200.0); - sprintf (frames, "%d", (int) n_frames); - - execl (full_name, "OMV", fdstr, frames, num_enb, num_ue, x_area, - y_area, z_area, NULL); - perror ("error in execl the OMV"); + case -1: + perror ("fork failed \n"); + break; + + case 0: + if (close (pfd[1]) == -1) + perror ("close on write\n"); + + sprintf (fdstr, "%d", pfd[0]); + sprintf (num_enb, "%d", 1); + sprintf (num_ue, "%d", omg_param_list[UE].nodes); + sprintf (x_area, "%f", omg_param_list[UE].max_x); + sprintf (y_area, "%f", omg_param_list[UE].max_y); + sprintf (z_area, "%f", 200.0); + sprintf (frames, "%d", (int) n_frames); + execl (full_name, "OMV", fdstr, frames, num_enb, num_ue, x_area, + y_area, z_area, NULL); + perror ("error in execl the OMV"); } //parent @@ -918,7 +878,6 @@ main (int argc, char *argv[]) //****************************** for (emu_info_time = 0.0; emu_info_time <= n_frames; emu_info_time += 0.1) { - update_nodes (emu_info_time); time_s = round (emu_info_time * 1000.0); @@ -929,7 +888,6 @@ main (int argc, char *argv[]) node_type, emu_info_time); if (current_positions != NULL) - display_job_list (emu_info_time, job_vector[omg_param_list [node_type].mobility_type]); @@ -939,12 +897,9 @@ main (int argc, char *argv[]) nodes_avgspeed(job_vector[omg_param_list [node_type].mobility_type])); */ } - //display current postion of nodes if (omv_enabled == 1) omv_write (pfd[1], node_vector[SUMO], omv_data); - - } /*LOG_I(OMG,"#-----event average-----\n"); @@ -953,22 +908,19 @@ main (int argc, char *argv[]) if(events[i]!=0) LOG_D(OMG,"%d %d \n",i,event_sum[i]/events[i]); } */ - stop_mobility_generator (omg_param_list); if (omv_enabled == 1) omv_end (pfd[1], omv_data); //clear_mem(); - return 0; } /**********************************sumo****************************/ int -omv_write (int pfd, node_list * ue_node_list, Data_Flow_Unit omv_data) -{ +omv_write (int pfd, node_list *ue_node_list, Data_Flow_Unit omv_data) { int i = 0, j; omv_data.end = 0; // enb @@ -979,7 +931,7 @@ omv_write (int pfd, node_list * ue_node_list, Data_Flow_Unit omv_data) omv_data.geo[i].node_type = 0; //eNB omv_data.geo[i].Neighbors = 0; - for (i = 1; i < omg_param_list[SUMO].nodes + 1; i++) { + for (i = 1; i < omg_param_list[SUMO-1].nodes + 1; i++) { if (ue_node_list != NULL) { omv_data.geo[i].x = (int) (ue_node_list->node->x_pos < @@ -988,7 +940,7 @@ omv_write (int pfd, node_list * ue_node_list, Data_Flow_Unit omv_data) (int) (ue_node_list->node->y_pos < 0.0) ? 0.0 : ue_node_list->node->y_pos; omv_data.geo[i].z = 1.0; - omv_data.geo[i].mobility_type = omg_param_list[SUMO].mobility_type; + omv_data.geo[i].mobility_type = omg_param_list[SUMO-1].mobility_type; omv_data.geo[i].node_type = 1; //UE ue_node_list = ue_node_list->next; omv_data.geo[i].Neighbors = 0; @@ -1004,8 +956,7 @@ omv_write (int pfd, node_list * ue_node_list, Data_Flow_Unit omv_data) } void -omv_end (int pfd, Data_Flow_Unit omv_data) -{ +omv_end (int pfd, Data_Flow_Unit omv_data) { omv_data.end = 1; if (write (pfd, &omv_data, sizeof (struct Data_Flow_Unit)) == -1) diff --git a/openair2/UTIL/OMG/omg_hashtable.c b/openair2/UTIL/OMG/omg_hashtable.c index 32b3840af3966e51dc32469e1dce68e04a51beaa..a545c5fc6227da90c08bc11310d10a9f51b83dd9 100644 --- a/openair2/UTIL/OMG/omg_hashtable.c +++ b/openair2/UTIL/OMG/omg_hashtable.c @@ -43,8 +43,7 @@ * @returns hash_table_element_t object when success * @returns NULL when no memory */ -hash_table_element_t * hash_table_element_new(void) -{ +hash_table_element_t *hash_table_element_new(void) { //INFO("creating a new hash table element"); return calloc(1, hash_table_element_s); } @@ -54,8 +53,7 @@ hash_table_element_t * hash_table_element_new(void) * @param table table from which element has to be deleted * @param element hash table element to be deleted */ -void hash_table_element_delete(omg_hash_table_t * table, hash_table_element_t * element) -{ +void hash_table_element_delete(omg_hash_table_t *table, hash_table_element_t *element) { //INFO("Deleting an hash table element"); if (table->mode == MODE_COPY) { free(element->value); @@ -74,8 +72,7 @@ void hash_table_element_delete(omg_hash_table_t * table, hash_table_element_t * * @returns omg_hash_table_t object which references the hash table * @returns NULL when no memory */ -omg_hash_table_t * hash_table_new(hash_table_mode_t mode) -{ +omg_hash_table_t *hash_table_new(hash_table_mode_t mode) { //INFO("Creating a new hash table"); omg_hash_table_t *table = calloc(1, SIZEOF_HASH_TABLE); @@ -102,14 +99,13 @@ omg_hash_table_t * hash_table_new(hash_table_mode_t mode) * Function to delete the hash table * @param table hash table to be deleted */ -void hash_table_delete(omg_hash_table_t * table) -{ +void hash_table_delete(omg_hash_table_t *table) { //INFO("Deleating a hash table"); size_t i=0; for (; i<HASH_LEN; i++) { while (table->store_house[i]) { - hash_table_element_t * temp = table->store_house[i]; + hash_table_element_t *temp = table->store_house[i]; table->store_house[i] = table->store_house[i]->next; hash_table_element_delete(table, temp); } @@ -129,8 +125,7 @@ void hash_table_delete(omg_hash_table_t * table) * @returns 0 on sucess * @returns -1 when no memory */ -int hash_table_add(omg_hash_table_t * table, void * key, size_t key_len, void * value, size_t value_len) -{ +int hash_table_add(omg_hash_table_t *table, void *key, size_t key_len, void *value, size_t value_len) { if ((table->key_count / table->key_num) >= table->key_ratio) { //LOG("Ratio(%d) reached the set limit %d\nExpanding hash_table", (table->key_count / table->key_num), table->key_ratio); hash_table_resize(table, table->key_num*2); @@ -138,7 +133,7 @@ int hash_table_add(omg_hash_table_t * table, void * key, size_t key_len, void * } size_t hash = HASH(key, key_len); - hash_table_element_t * element = hash_table_element_new(); + hash_table_element_t *element = hash_table_element_new(); if (!element) { //INFO("Cannot allocate memory for element"); @@ -197,7 +192,7 @@ int hash_table_add(omg_hash_table_t * table, void * key, size_t key_len, void * table->key_count++; } else { //LOG("Conflicts adding element at %d", (int)hash); - hash_table_element_t * temp = table->store_house[hash]; + hash_table_element_t *temp = table->store_house[hash]; while(temp->next) { while(temp->next && temp->next->key_len!=key_len) { @@ -234,8 +229,7 @@ int hash_table_add(omg_hash_table_t * table, void * key, size_t key_len, void * * @returns 0 on sucess * @returns -1 when key is not found */ -int hash_table_remove(omg_hash_table_t * table, void * key, size_t key_len) -{ +int hash_table_remove(omg_hash_table_t *table, void *key, size_t key_len) { //INFO("Deleting a key-value pair from the hash table"); if ((table->key_num/ table->key_count) >= table->key_ratio) { //LOG("Ratio(%d) reached the set limit %d\nContracting hash_table", (table->key_num / table->key_count), table->key_ratio); @@ -290,8 +284,7 @@ int hash_table_remove(omg_hash_table_t * table, void * key, size_t key_len) * @returns NULL when key is not found in the hash table * @returns void* pointer to the value in the table */ -void * hash_table_lookup(omg_hash_table_t * table, void * key, size_t key_len) -{ +void *hash_table_lookup(omg_hash_table_t *table, void *key, size_t key_len) { size_t hash = HASH(key, key_len); //LOG("Looking up a key-value pair for hash -> %d", (int)hash); @@ -328,8 +321,7 @@ void * hash_table_lookup(omg_hash_table_t * table, void * key, size_t key_len) * @returns 0 when key is not found * @returns 1 when key is found */ -int hash_table_has_key(omg_hash_table_t * table, void * key, size_t key_len) -{ +int hash_table_has_key(omg_hash_table_t *table, void *key, size_t key_len) { size_t hash = HASH(key, key_len); //LOG("Searching for key with hash -> %d", (int)hash); @@ -365,11 +357,10 @@ int hash_table_has_key(omg_hash_table_t * table, void * key, size_t key_len) * @param keys a void** pointer where keys are filled in (memory allocated internally and must be freed) * @return total number of keys filled in keys */ -size_t hash_table_get_keys(omg_hash_table_t * table, void ** keys) -{ +size_t hash_table_get_keys(omg_hash_table_t *table, void **keys) { size_t i = 0; size_t count = 0; - keys = calloc(table->key_count, sizeof(void *)); + keys = calloc(table->key_count, sizeof(void *)*HASH_LEN); for(i=0; i<HASH_LEN; i++) { if (table->store_house[i]) { @@ -403,8 +394,7 @@ size_t hash_table_get_keys(omg_hash_table_t * table, void ** keys) * @returns 1 when no memory * @returns count of elements */ -size_t hash_table_get_elements(omg_hash_table_t * table, hash_table_element_t *** elements) -{ +size_t hash_table_get_elements(omg_hash_table_t *table, hash_table_element_t *** elements) { size_t i = 0; size_t count = 0; (*elements) = (hash_table_element_t **) calloc(table->key_count, sizeof(hash_table_element_t *)); @@ -446,8 +436,7 @@ size_t hash_table_get_elements(omg_hash_table_t * table, hash_table_element_t ** * @param max_key max value of the hash to be returned by the function * @returns hash value belonging to [0, max_key) */ -uint16_t hash_table_do_hash(void * key, size_t key_len, uint16_t max_key) -{ +uint16_t hash_table_do_hash(void *key, size_t key_len, uint16_t max_key) { uint16_t *ptr = (uint16_t *) key; uint16_t hash = 0xbabe; // WHY NOT size_t i = 0; @@ -469,10 +458,9 @@ uint16_t hash_table_do_hash(void * key, size_t key_len, uint16_t max_key) * @returns -2 when no emmory for new store house * @returns 0 when sucess */ -int hash_table_resize(omg_hash_table_t *table, size_t len) -{ +int hash_table_resize(omg_hash_table_t *table, size_t len) { //LOG("resizing hash table from %d to %d", table->key_num, len); - hash_table_element_t ** elements; + hash_table_element_t **elements; size_t count; // FIXME traversing the elements twice, change it some time soon count = hash_table_get_elements(table, &elements); @@ -483,7 +471,7 @@ int hash_table_resize(omg_hash_table_t *table, size_t len) } // keep the current store house in case we dont get more memory - hash_table_element_t ** temp = table->store_house; + hash_table_element_t **temp = table->store_house; table->store_house = calloc(len, sizeof(hash_table_element_t *)); if (!table->store_house) { diff --git a/openair2/UTIL/OTG/main.c b/openair2/UTIL/OTG/main.c index 1ee9b0edd7600df62ccd4acb8d9c1a2cc6194ecc..023033c45fbc603820b7890bddac690000fc275d 100644 --- a/openair2/UTIL/OTG/main.c +++ b/openair2/UTIL/OTG/main.c @@ -53,9 +53,7 @@ int simu_time=0, duration=0, seed=0, simu_mode=0; // init OTG with config parameters -void init_config_otg(char *protocol, char *ip_version) -{ - +void init_config_otg(char *protocol, char *ip_version) { int i, j, k; if (simu_time>0) @@ -70,25 +68,19 @@ void init_config_otg(char *protocol, char *ip_version) printf("duration %d, seeds %d \n", duration, g_otg->seed); - for (i=0; i<(NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX); i++) { - - - if (duration>0) g_otg->duration[i]=duration; else g_otg->duration[i]=10000; - g_otg->dst_port[i]=DST_PORT; - g_otg->dst_ip[i]=(char*)malloc(100*sizeof(char*)); + g_otg->dst_ip[i]=(char *)malloc(100*sizeof(char *)); g_otg->dst_ip[i]=DST_IP; g_otg->dst_ip[i]=DST_IP; //config ip version - if (ip_version !=NULL) { if ((strcmp(ip_version,"IP4")==0) ||(strcmp(ip_version,"ip4")==0)) g_otg->ip_v[i]=IPV4; @@ -97,7 +89,6 @@ void init_config_otg(char *protocol, char *ip_version) } else g_otg->ip_v[i]=IPV4; - //config transport protocol version if (protocol!=NULL) { if ((strcmp(protocol,"TCP")==0) ||(strcmp(protocol,"tcp")==0)) @@ -123,20 +114,13 @@ void init_config_otg(char *protocol, char *ip_version) g_otg->size_std_dev[i][j][k]=PKTS_SIZE_STD_DEV; g_otg->size_lambda[i][j][k]=PKTS_SIZE_LAMBDA; } - } - - } - - - } -int main_below_ip() -{ +int main_below_ip() { int i, j, k, l, rtt_owd ,rx_otg=0, simu_time=0, ctime=0, nb_round=0; float p; char *packet; @@ -145,25 +129,17 @@ int main_below_ip() printf(" max enb %d, max ue %d \n", NUMBER_OF_eNB_MAX, NUMBER_OF_UE_MAX); do { - nb_round=nb_round+1; // for (stime=0; stime < SIMU_TIME; stime++) // discrete event generation : tick, stime generate the ctime for (i=0; i<(NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX); i++) { - for (j=0; j<(NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX); j++) { - for (k=0; k<MAX_NUM_TRAFFIC_STATE; k++) { LOG_I(OTG,"OTG emulation src=%d, dst=%d, state=%d \n", i, j, k); - - - ctime=0; // set the ctime to 0 do { - if (simu_time> SIMU_TIME) { - otg_info->ctime=SIMU_TIME; return(0); } @@ -172,21 +148,16 @@ int main_below_ip() char *packet=NULL; /*packet=packet_gen(i, j, k, ctime);*/ packet=packet_gen(i, j, ctime, &pkt_size); - - if (packet!=NULL) { if ((ceil(g_otg->duration[i]*uniform_rng()))==ctime) { - printf("DROP PACKET (i=%d,j=%d) seq num=%d\n",i, j, otg_info->seq_num[i][j]); - + printf("DROP PACKET (i=%d,j=%d) seq num=%d\n",i, j, (int)otg_info->seq_num[i][j]); } else { - printf("SEND PACKET (i=%d,j=%d) seq num=%d\n",i, j, otg_info->seq_num[i][j]); - + printf("SEND PACKET (i=%d,j=%d) seq num=%d\n",i, j, (int)otg_info->seq_num[i][j]); rtt_owd=ceil(uniform_rng()*8.56); LOG_I(OTG,"one way delay= %d , (src=%d, dst=%d, state=%d)\n", rtt_owd, i, j, k); ctime+=rtt_owd; otg_info->rx_pkt_owd[i][j]=rtt_owd; simu_time+=rtt_owd; - //rx_packet_out=check_packet(i, j, ctime, packet); rx_packet_out=otg_rx_pkt(i,j, ctime, packet, pkt_size); //if (rx_packet_out==NULL) @@ -196,18 +167,15 @@ int main_below_ip() // rx_packet_out=NULL; free(packet); // } - //} - //Do not increase the ctime and simu_time with the one way delay. ctime-=rtt_owd; simu_time-=rtt_owd; - - - LOG_I(OTG,"PKTS INFO:: (src=%d, dst=%d, state=%d),NB PKTS=%d ,sequence NB=%d, RTT (one way)ms= %d \n ",i, j, k, otg_info->tx_num_pkt[i][j], otg_info->seq_num[i][j], otg_info->rx_pkt_owd[i][j]); + LOG_I(OTG,"PKTS INFO:: (src=%d, dst=%d, state=%d),NB PKTS=%d ,sequence NB=%d, RTT (one way)ms= %d \n ", + i, j, k, (int)otg_info->tx_num_pkt[i][j], (int)otg_info->seq_num[i][j], (int)otg_info->rx_pkt_owd[i][j]); } } else - printf("Node (i=%d,j=%d) seq num=%d, ctime %d, prb %lf\n",i, j, otg_info->seq_num[i][j], ctime,(ceil(g_otg->duration[i]*uniform_rng()))); + printf("Node (i=%d,j=%d) seq num=%d, ctime %d, prb %lf\n",i, j, (int)otg_info->seq_num[i][j], ctime,(ceil(g_otg->duration[i]*uniform_rng()))); LOG_I(OTG,"Time:: ctime=%d, duration=%d, simu_time=%d, max=%d, (src=%d, dst=%d, state=%d) \n", ctime, g_otg->duration[i],simu_time, SIMU_TIME, i, j,k); ctime+=1; @@ -215,27 +183,19 @@ int main_below_ip() } while (ctime<=g_otg->duration[i]) ; } - - if (otg_info->tx_num_pkt[i][j]>otg_info->rx_num_pkt[i][j]) - LOG_I(OTG,"STAT: (LOSS):: (src=%d, dst=%d) NB packet TX= %d, NB packet RX = %d, seq NUM=%d\n ",i, j, otg_info->tx_num_pkt[i][j], otg_info->rx_num_pkt[i][j],otg_info->seq_num[i][j] ); + LOG_I(OTG,"STAT: (LOSS):: (src=%d, dst=%d) NB packet TX= %d, NB packet RX = %d, seq NUM=%d\n ", + i, j, (int)otg_info->tx_num_pkt[i][j], (int)otg_info->rx_num_pkt[i][j],(int)otg_info->seq_num[i][j] ); else - LOG_I(OTG,"STAT: :: (src=%d, dst=%d) NB packet TX= %d, NB packet RX= %d, seq NUM=%d \n ",i, j, otg_info->tx_num_pkt[i][j], otg_info->rx_num_pkt[i][j], otg_info->seq_num[i][j]); - - - + LOG_I(OTG,"STAT: :: (src=%d, dst=%d) NB packet TX= %d, NB packet RX= %d, seq NUM=%d \n ", + i, j, (int)otg_info->tx_num_pkt[i][j], (int)otg_info->rx_num_pkt[i][j], (int)otg_info->seq_num[i][j]); } } - - - } while (simu_time<=SIMU_TIME); - } -int main_above_ip() -{ +int main_above_ip() { int i, j, k, simu_time=0, ctime=0, nb_round=0; char *packet=NULL; printf(" max enb %d, max ue %d \n", NUMBER_OF_eNB_MAX, NUMBER_OF_UE_MAX); @@ -244,9 +204,7 @@ int main_above_ip() nb_round=nb_round+1; for (i=0; i<(NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX); i++) { - for (j=0; j<(NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX); j++) { - for (k=0; k<MAX_NUM_TRAFFIC_STATE; k++) { LOG_I(OTG,"SOCKET:: OTG emulation src=%d, dst=%d, state=%d \n", i, j, k); ctime=0; @@ -255,57 +213,44 @@ int main_above_ip() } } - ctime+=1; simu_time+=1; } while (simu_time<=SIMU_TIME); - } -void config_traffic_type(char *traffic) -{ +void config_traffic_type(char *traffic) { Application application; int i,j; if (strcmp(traffic, "SCBR")==0) application=SCBR; - else if (strcmp(traffic, "OPENARENA")==0) application=OPENARENA; - else if (strcmp(traffic, "BICYCLE_RACE")==0) application=BICYCLE_RACE; - else if (strcmp(traffic, "AUTO_PILOT")==0) application=AUTO_PILOT; - else if (strcmp(traffic, "TEAM_FORTRESS")==0) application=TEAM_FORTRESS; - else application=NO_PREDEFINED_TRAFFIC; printf("Config Application: %d \n", application); for (i=0; i<(NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX); i++) { - for (j=0; j<(NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX); j++) { - g_otg->application_type[i][j] =application; - } } - } -cunstom_config(simu_time, duration) -{ +cunstom_config(simu_time, duration) { int i; //--config introduced Global simulation time for each node @@ -321,37 +266,23 @@ cunstom_config(simu_time, duration) -int main (int argc, char **argv) -{ - - +int main (int argc, char **argv) { int i,j, tx; - char *protocol=NULL; char *ip_version=NULL; char *traffic=NULL; - - - - init_all_otg(); otg_info->ctime=0; LOG_I(OTG,"Emulation time %d \n ", otg_info->ctime); g_otg->num_nodes=NUMBER_OF_eNB_MAX + NUMBER_OF_UE_MAX; LOG_I(OTG,"OTG emulation number of nodes= %d \n", g_otg->num_nodes); - - for (i = 1; i <argc ; i ++) { if ('-' == argv[i][0]) { - if(('h' == argv[i][1]) || ('H' == argv[i][1])) { printf("Help OTG: \n./otg [-M [s (socket mode)] [b (Below IP)]] [-T (Simu Time)] [-d (duration per node)] [-s (seed)] [-P (protocol: TCP or UDP)] [-I (ip version: IP4 or IP6)] -A [(application: CBR, AUTO_PILOT, BICYCLE_RACE, OPENARENA, TEAM_FORTRESS)]\n"); return(0); - - } - - else if ('M' == argv[i][1]) { + } else if ('M' == argv[i][1]) { if (strcmp("s",argv[i+1])==0) { printf("Above IP: SOCKET MODE \n"); simu_mode=1; @@ -359,89 +290,53 @@ int main (int argc, char **argv) printf("Below IP: IPC/RPC MODE\n"); simu_mode=0; } - - } - - else if ('T' == argv[i][1]) { + } else if ('T' == argv[i][1]) { simu_time=atoi(argv[i+1]); printf("simu_time=%d\n", simu_time); - } - - - else if ('d' == argv[i][1]) { + } else if ('d' == argv[i][1]) { duration=atoi(argv[i+1]); printf("duration node=%d\n", duration); - } - - else if ('s' == argv[i][1]) { + } else if ('s' == argv[i][1]) { seed=atoi(argv[i+1]); printf("seed val =%d\n", seed); - } - - - else if ('P' == argv[i][1]) { + } else if ('P' == argv[i][1]) { protocol=argv[i+1]; if ((strcmp(argv[i+1],"TCP")==0) || (strcmp(argv[i+1],"UDP")==0) || (strcmp(argv[i+1],"tcp")==0) || (strcmp(argv[i+1],"udp")==0)) { protocol=argv[i+1]; printf("Protocol=%s\n", protocol); } - } - - else if ('I' == argv[i][1]) { + } else if ('I' == argv[i][1]) { if ((strcmp(argv[i+1],"IP4")==0) || (strcmp(argv[i+1],"IP6")==0) || (strcmp(argv[i+1],"ip4")==0) || (strcmp(argv[i+1],"ip6")==0)) { ip_version=argv[i+1]; printf("IP version=%s\n", ip_version); } - - - } - - else if ('A' == argv[i][1]) { + } else if ('A' == argv[i][1]) { if ((strcmp(argv[i+1],"CBR")==0) || (strcmp(argv[i+1],"AUTO_PILOT")==0) || (strcmp(argv[i+1],"BICYCLE_RACE")==0) || (strcmp(argv[i+1],"OPENARENA")==0) || (strcmp(argv[i+1],"TEAM_FORTRESS")==0)) traffic=argv[i+1]; config_traffic_type(traffic); - } - - } - - - } - - if (traffic!=NULL) init_predef_traffic(); else init_config_otg(protocol, ip_version); - init_seeds(g_otg->seed); cunstom_config(simu_time, duration); - - if (simu_mode==0) tx=main_below_ip(); - else if (simu_mode==1) tx=main_above_ip(); - - // Compute KPI after the end of the simu kpi_gen(); - free_otg(); - - - return 0; - } diff --git a/openair2/UTIL/OTG/otg_form.c b/openair2/UTIL/OTG/otg_form.c index 6994e658961b9ec76795320b24c66f8b908ea631..aea5d3888277edf14c94aa2bfcd25217b453c001 100644 --- a/openair2/UTIL/OTG/otg_form.c +++ b/openair2/UTIL/OTG/otg_form.c @@ -38,31 +38,25 @@ extern unsigned char NB_eNB_INST; extern unsigned char NB_UE_INST; -FD_otg * form_dl, *form_ul; +FD_otg *form_dl, *form_ul; FL_FORM *fclock; unsigned int clear_cmpt_ul=0; unsigned int clear_cmpt_dl=0; -FD_otg *create_form_otg(void) -{ +FD_otg *create_form_otg(void) { FL_OBJECT *obj; FD_otg *fdui = (FD_otg *) fl_calloc(1, sizeof(*fdui)); - fdui->otg = fl_bgn_form(FL_NO_BOX, 550, 550); obj = fl_add_box(FL_UP_BOX,0,0,900,700,""); fdui->owd = fl_add_xyplot(FL_NORMAL_XYPLOT,50,30,450,190,"Delay(ms)"); fl_set_object_color(fdui->owd,FL_BLACK,FL_YELLOW); fdui->throughput = fl_add_xyplot(FL_NORMAL_XYPLOT,50,300,450,190,"Throughput(Kbit/s)"); fl_set_object_color(fdui->throughput,FL_BLACK,FL_YELLOW); - - obj = fl_add_button(FL_NORMAL_BUTTON,250,510,50,30,"Exit"); fl_set_object_callback(obj, exit_cb, 0); fdui->loss_ratio=fl_add_text(FL_NORMAL_TEXT,5,510,220,20,"NB Loss pkts"); fdui->simu_time=fl_add_text(FL_NORMAL_TEXT,370,510,250,30,"Simulation Time"); - - fl_end_form(); fdui->otg->fdui = fdui; return fdui; @@ -70,18 +64,15 @@ FD_otg *create_form_otg(void) //For more details about object parameters, refer to: http://xforms-toolkit.org/doc/xforms_25.html -void show_otg_form() -{ +void show_otg_form() { int eNB_id; char title[255]; char *tArgv[] = { "OTG", "OTG" }; int tArgc = 2; - int major_owd = 6; int minor_owd = 3; int major_thr = 5; int minor_thr = 2; - fl_initialize(&tArgc,tArgv,"OTG",0,0); for (eNB_id = 0; eNB_id < NB_eNB_INST; eNB_id++) { //NB_eNB_INST @@ -98,9 +89,6 @@ void show_otg_form() fl_set_xyplot_ytics(form_dl->throughput,major_thr, minor_thr); fl_set_xyplot_ybounds(form_dl->throughput,0,1000); - - - form_ul= create_form_otg (); sprintf (title, "LTE UE->eNB (UL)"); fl_show_form (form_ul->otg, FL_PLACE_HOTSPOT, FL_FULLBORDER, title); @@ -116,20 +104,15 @@ void show_otg_form() //fl_set_xyplot_xgrid (form_ul->throughput, FL_GRID_MAJOR); fl_set_xyplot_ytics(form_ul->throughput,major_thr, minor_thr); fl_set_xyplot_ybounds(form_ul->throughput,0,1000); - - } //create_form_clock(); //fl_show_form(fclock, FL_PLACE_CENTER,FL_TRANSIENT,"clocks"); //fl_do_forms(); - fl_check_forms(); } -void add_tab_metric(int src, int dst, float owd, float throughput, int ctime) -{ - +void add_tab_metric(int src, int dst, float owd, float throughput, int ctime) { if (otg_forms_info->init_forms==0) { show_otg_form(); otg_forms_info->init_forms=1; @@ -158,9 +141,7 @@ void add_tab_metric(int src, int dst, float owd, float throughput, int ctime) } -void plot_graphes_ul(int src, int dst, int ctime) //UE -->eNB -{ - +void plot_graphes_ul(int src, int dst, int ctime) { //UE -->eNB int i, src_idx=1, curve_id=1; char loss_rate[100]; char simu_time[100]; @@ -169,12 +150,8 @@ void plot_graphes_ul(int src, int dst, int ctime) //UE -->eNB int y_key_position=75; if (otg_forms_info->idx_ul[src][dst]==MAX_SAMPLES-1) { - fl_update_display(1); //the function flushes the X buffer so the drawing requests are on their way to the server - - - if (otg_forms_info->is_data_plot_ul == -1) otg_forms_info->is_data_plot_ul=src; @@ -184,17 +161,13 @@ void plot_graphes_ul(int src, int dst, int ctime) //UE -->eNB sprintf(curve_label, "%d%s%d", src,"-->", dst); fl_set_xyplot_key(form_ul->owd, 0, curve_label); fl_set_xyplot_key_position(form_ul->owd, x_key_position,y_key_position, FL_ALIGN_BOTTOM_LEFT); - fl_set_xyplot_data (form_ul->throughput, otg_forms_info->data_ctime_ul[src][dst], otg_forms_info->data_throughput_ul[src][dst], otg_forms_info->idx_ul[src][dst], "", "time", "kbit/s"); fl_set_xyplot_key(form_ul->throughput, 0, curve_label); fl_set_xyplot_key_font(form_ul->throughput, FL_BOLD_STYLE, FL_HUGE_SIZE); fl_set_xyplot_key_position(form_ul->throughput, x_key_position,y_key_position , FL_ALIGN_BOTTOM_LEFT); - - - otg_kpi_nb_loss_pkts(); - sprintf(loss_rate, "%s%d","NB Loss pkts UL=", otg_info->total_loss_ul); + sprintf(loss_rate, "%s%u","NB Loss pkts UL=", otg_info->total_loss_ul); fl_set_object_label(form_ul->loss_ratio, loss_rate); sprintf(simu_time, "%s%d","Simulation Time(ms)=", ctime); fl_set_object_label(form_ul->simu_time, simu_time); @@ -204,20 +177,16 @@ void plot_graphes_ul(int src, int dst, int ctime) //UE -->eNB sprintf(curve_label, "%d%s%d", otg_forms_info->is_data_plot_ul,"-->", dst); fl_set_xyplot_key(form_ul->owd, 0, curve_label); fl_set_xyplot_key_position(form_ul->owd, x_key_position,y_key_position, FL_ALIGN_BOTTOM_LEFT); - - fl_set_xyplot_data (form_ul->throughput, otg_forms_info->data_ctime_ul[otg_forms_info->is_data_plot_ul][dst], otg_forms_info->data_throughput_ul[otg_forms_info->is_data_plot_ul][dst], otg_forms_info->idx_ul[otg_forms_info->is_data_plot_ul][dst], "", "time", "kbit/s"); sprintf(curve_label, "%d%s%d", otg_forms_info->is_data_plot_ul,"-->", dst); fl_set_xyplot_key(form_ul->throughput, 0, curve_label); fl_set_xyplot_key_position(form_ul->throughput, x_key_position,y_key_position , FL_ALIGN_BOTTOM_LEFT); - otg_kpi_nb_loss_pkts(); - sprintf(loss_rate, "%s%d","NB Loss pkts UL=",otg_info->total_loss_ul); + sprintf(loss_rate, "%s%u","NB Loss pkts UL=",otg_info->total_loss_ul); fl_set_object_label(form_ul->loss_ratio, loss_rate); sprintf(simu_time, "%s%d","Simulation Time(ms)=", ctime); fl_set_object_label(form_ul->simu_time, simu_time); - } for (src_idx=1; src_idx<=NB_UE_INST; src_idx++) { @@ -229,9 +198,6 @@ void plot_graphes_ul(int src, int dst, int ctime) //UE -->eNB sprintf(curve_label, "%d%s%d", src_idx,"-->", dst); fl_set_xyplot_key(form_ul->owd, curve_id-1, curve_label); fl_set_xyplot_key_position(form_ul->owd, x_key_position,y_key_position, FL_ALIGN_BOTTOM_LEFT); - - - fl_add_xyplot_overlay(form_ul->throughput,curve_id++, otg_forms_info->data_ctime_ul[src_idx][dst], otg_forms_info->data_throughput_ul[src_idx][dst], @@ -242,7 +208,6 @@ void plot_graphes_ul(int src, int dst, int ctime) //UE -->eNB } } - for (i=0; i<otg_forms_info->idx_ul[src][dst]; i++) { otg_forms_info->data_ctime_ul[src][dst][otg_forms_info->idx_ul[src][dst]]=i; otg_forms_info->data_owd_ul[src][dst][i]= otg_forms_info->data_owd_ul[src][dst][i+1]; @@ -253,14 +218,11 @@ void plot_graphes_ul(int src, int dst, int ctime) //UE -->eNB } fl_check_forms(); - } -void plot_graphes_dl(int src, int dst, int ctime) //eNB -->UE -{ - +void plot_graphes_dl(int src, int dst, int ctime) { //eNB -->UE int i, dst_idx=1, curve_id=1; char loss_rate[100]; char curve_label[100]; @@ -269,11 +231,8 @@ void plot_graphes_dl(int src, int dst, int ctime) //eNB -->UE int y_key_position=75; if (otg_forms_info->idx_dl[src][dst]==MAX_SAMPLES-1) { - fl_update_display(1); //the function flushes the X buffer so the drawing requests are on their way to the server - - if (otg_forms_info->is_data_plot_dl == -1) otg_forms_info->is_data_plot_dl=dst; @@ -289,12 +248,10 @@ void plot_graphes_dl(int src, int dst, int ctime) //eNB -->UE fl_set_xyplot_key(form_dl->throughput, 0, curve_label); fl_set_xyplot_key_position(form_dl->throughput, x_key_position,y_key_position, FL_ALIGN_BOTTOM_LEFT); otg_kpi_nb_loss_pkts(); - sprintf(loss_rate, "%s%d","NB Loss pkts DL=",otg_info->total_loss_dl); + sprintf(loss_rate, "%s%u","NB Loss pkts DL=",otg_info->total_loss_dl); fl_set_object_label(form_dl->loss_ratio, loss_rate); - sprintf(simu_time, "%s%d","Simulation Time(ms)=", ctime); fl_set_object_label(form_dl->simu_time, simu_time); - } else { fl_set_xyplot_data (form_dl->owd, otg_forms_info->data_ctime_dl[src][otg_forms_info->is_data_plot_dl], otg_forms_info->data_owd_dl[src][otg_forms_info->is_data_plot_dl], otg_forms_info->idx_dl[src][otg_forms_info->is_data_plot_dl], "", "time", "ms"); @@ -306,9 +263,8 @@ void plot_graphes_dl(int src, int dst, int ctime) //eNB -->UE sprintf(curve_label, "%d%s%d", src,"-->",otg_forms_info->is_data_plot_dl); fl_set_xyplot_key(form_dl->throughput, 0, curve_label); fl_set_xyplot_key_position(form_dl->throughput,x_key_position,y_key_position, FL_ALIGN_BOTTOM_LEFT); - otg_kpi_nb_loss_pkts(); - sprintf(loss_rate, "%s%d","NB Loss pkts DL=",otg_info->total_loss_dl); + sprintf(loss_rate, "%s%u","NB Loss pkts DL=",otg_info->total_loss_dl); fl_set_object_label(form_dl->loss_ratio, loss_rate); sprintf(simu_time, "%s%d","Simulation Time(ms)=", ctime); fl_set_object_label(form_dl->simu_time, simu_time); @@ -323,7 +279,6 @@ void plot_graphes_dl(int src, int dst, int ctime) //eNB -->UE sprintf(curve_label, "%d%s%d", src,"-->", dst_idx); fl_set_xyplot_key(form_dl->owd, curve_id-1, curve_label); fl_set_xyplot_key_position(form_dl->owd, x_key_position,y_key_position, FL_ALIGN_BOTTOM_LEFT); - fl_add_xyplot_overlay(form_dl->throughput,curve_id++, otg_forms_info->data_ctime_dl[src][dst_idx], otg_forms_info->data_throughput_dl[src][dst_idx], @@ -331,8 +286,6 @@ void plot_graphes_dl(int src, int dst, int ctime) //eNB -->UE sprintf(curve_label, "%d%s%d", src,"-->", dst_idx); fl_set_xyplot_key(form_dl->throughput, curve_id-1, curve_label); fl_set_xyplot_key_position(form_dl->throughput, x_key_position,y_key_position, FL_ALIGN_BOTTOM_LEFT); - - } } @@ -346,7 +299,6 @@ void plot_graphes_dl(int src, int dst, int ctime) //eNB -->UE } fl_check_forms(); - } @@ -354,14 +306,12 @@ void plot_graphes_dl(int src, int dst, int ctime) //eNB -->UE -void exit_cb(FL_OBJECT *ob, long q) -{ +void exit_cb(FL_OBJECT *ob, long q) { fl_finish(); exit(0); } -void create_form_clock(void) -{ +void create_form_clock(void) { FL_OBJECT *obj; if (fclock) @@ -369,22 +319,18 @@ void create_form_clock(void) fclock = fl_bgn_form(FL_NO_BOX,500,350); obj = fl_add_box(FL_UP_BOX,0,0,500,350,""); - obj = fl_add_clock(FL_DIGITAL_CLOCK,185,20,150,35,""); fl_set_object_boxtype(obj,FL_ROUNDED_BOX); fl_set_object_color(obj,FL_COL1,FL_BLACK); fl_set_object_lsize(obj,FL_MEDIUM_SIZE); fl_set_object_lstyle(obj,FL_BOLD_STYLE); - obj = fl_add_clock(FL_ANALOG_CLOCK,30,70,220,200,""); fl_set_object_boxtype(obj,FL_UP_BOX); - obj = fl_add_clock(FL_ANALOG_CLOCK,260,70,220,200,""); fl_set_object_boxtype(obj,FL_OVAL3D_UPBOX); obj = fl_add_button(FL_NORMAL_BUTTON,375,300,110,35,"Exit"); fl_set_object_callback(obj, exit_cb, 0); fl_end_form(); - fl_scale_form(fclock, 0.7, 0.7); } diff --git a/openair2/UTIL/OTG/otg_kpi.c b/openair2/UTIL/OTG/otg_kpi.c index 94a0a53d5c54025b6e7c340cfa2a3dbe8af69010..3af84adc8b303275048733b9255a6f3c92be52c9 100644 --- a/openair2/UTIL/OTG/otg_kpi.c +++ b/openair2/UTIL/OTG/otg_kpi.c @@ -43,23 +43,22 @@ unsigned int start_log_jitter=0; extern unsigned char NB_eNB_INST; extern unsigned char NB_UE_INST; -void tx_throughput(int src, int dst, int application) -{ - +void tx_throughput(int src, int dst, int application) { if (otg_info->tx_num_bytes[src][dst][application]>0) { // otg_info->tx_throughput[src][dst][application]=((double)otg_info->tx_num_bytes[src][dst][application] *1000*8)/ (get_ctime()*1024); // unit Kbit/sec, if ctime in ms if ((g_otg->flow_start[src][dst][application]+g_otg->flow_duration[src][dst][application]) < get_ctime() ) - otg_info->tx_throughput[src][dst][application]=((double)otg_info->tx_num_bytes[src][dst][application] *1000*8)/ ((g_otg->flow_start[src][dst][application]+g_otg->flow_duration[src][dst][application])*1024); // unit Kbit/sec, if ctime in ms + otg_info->tx_throughput[src][dst][application]=((double)otg_info->tx_num_bytes[src][dst][application] *1000*8)/ ((g_otg->flow_start[src][dst][application]+g_otg->flow_duration[src][dst][application]) + *1024); // unit Kbit/sec, if ctime in ms else if (g_otg->flow_start[src][dst][application] < get_ctime() ) otg_info->tx_throughput[src][dst][application]=((double)otg_info->tx_num_bytes[src][dst][application] *1000*8)/ ((get_ctime() - g_otg->flow_start[src][dst][application])*1024); - else + else LOG_W(OTG, "[src %d][dst %d][app %d] flow start time less than the simu time (start %d, duration %d, ctime %d)\n", - src, dst, application, - g_otg->flow_start[src][dst][application], - g_otg->flow_duration[src][dst][application], - get_ctime()); + src, dst, application, + g_otg->flow_start[src][dst][application], + g_otg->flow_duration[src][dst][application], + get_ctime()); } - + if (otg_info->tx_num_bytes_background[src][dst]>0) otg_info->tx_throughput_background[src][dst]=((double)otg_info->tx_num_bytes_background[src][dst]*1000*8)/ (get_ctime()*1024); // unit Kbit/sec, if ctime in ms @@ -71,26 +70,24 @@ void tx_throughput(int src, int dst, int application) // LOG_I(OTG,"DUY, get_ctime() [i=%d,j=%d,k=%d] = %.d\n", src,dst,application,get_ctime()); LOG_I(OTG,"otg_multicast_info->tx_num_bytes[i=%d,j=%d,k=%d] = %.d\n", src,dst,application,otg_multicast_info->tx_num_bytes[src][dst][application]); } - } -void rx_goodput(int src, int dst, int application) -{ - +void rx_goodput(int src, int dst, int application) { if (otg_info->rx_num_bytes[src][dst][application]>0) { // otg_info->rx_goodput[src][dst][application]=((double)otg_info->rx_num_bytes[src][dst][application]*1000*8)/(get_ctime()*1024); // unit kB/sec, if ctime in ms -if ((g_otg->flow_start[src][dst][application]+g_otg->flow_duration[src][dst][application]) < get_ctime() ) - otg_info->rx_goodput[src][dst][application]=((double)otg_info->rx_num_bytes[src][dst][application] *1000*8)/ ((g_otg->flow_start[src][dst][application]+g_otg->flow_duration[src][dst][application])*1024); // unit Kbit/sec, if ctime in ms + if ((g_otg->flow_start[src][dst][application]+g_otg->flow_duration[src][dst][application]) < get_ctime() ) + otg_info->rx_goodput[src][dst][application]=((double)otg_info->rx_num_bytes[src][dst][application] *1000*8)/ ((g_otg->flow_start[src][dst][application]+g_otg->flow_duration[src][dst][application]) + *1024); // unit Kbit/sec, if ctime in ms else if (g_otg->flow_start[src][dst][application] < get_ctime() ) otg_info->rx_goodput[src][dst][application]=((double)otg_info->rx_num_bytes[src][dst][application] *1000*8)/ ((get_ctime() - g_otg->flow_start[src][dst][application])*1024); - else + else LOG_W(OTG, "[src %d][dst %d][app %d] flow start time less than the simu time (start %d, duration %d, ctime %d)\n", - src, dst, application, - g_otg->flow_start[src][dst][application], - g_otg->flow_duration[src][dst][application], - get_ctime()); + src, dst, application, + g_otg->flow_start[src][dst][application], + g_otg->flow_duration[src][dst][application], + get_ctime()); } if (otg_info->rx_num_bytes_background[src][dst]>0) @@ -105,9 +102,7 @@ if ((g_otg->flow_start[src][dst][application]+g_otg->flow_duration[src][dst][app -void rx_loss_rate_pkts(int src, int dst, int application) -{ - +void rx_loss_rate_pkts(int src, int dst, int application) { if (otg_info->rx_num_pkt[src][dst][application]<otg_info->tx_num_pkt[src][dst][application]) otg_info->rx_loss_rate[src][dst][application]= 1 - ((double)otg_info->rx_num_pkt[src][dst][application]/otg_info->tx_num_pkt[src][dst][application]); else @@ -127,26 +122,20 @@ void rx_loss_rate_pkts(int src, int dst, int application) otg_multicast_info->rx_loss_rate[src][dst]= 1 - ((double)otg_multicast_info->rx_num_pkt[src][dst][application]/otg_multicast_info->tx_num_pkt[src][dst][0]); else otg_multicast_info->rx_loss_rate[src][dst]=0; - } -void rx_loss_rate_bytes(int src, int dst, int application) -{ - +void rx_loss_rate_bytes(int src, int dst, int application) { if (otg_info->rx_num_pkt[src][dst][application]<otg_info->tx_num_pkt[src][dst][application]) otg_info->rx_loss_rate[src][dst][application]= 1 - ((double)otg_info->rx_num_bytes[src][dst][application]/otg_info->tx_num_bytes[src][dst][application]); else otg_info->rx_loss_rate[src][dst][application]=0; LOG_I(OTG, "loss rate (src=%d, dst=%d, appli %d ):: = %lf(bytes) \n",src, dst, application, otg_info->rx_loss_rate[src][dst][application]); - } -void otg_kpi_nb_loss_pkts(void) -{ +void otg_kpi_nb_loss_pkts(void) { unsigned int i,j,k; - otg_info->total_loss_dl=0; otg_info->total_loss_ul=0; @@ -162,9 +151,7 @@ void otg_kpi_nb_loss_pkts(void) } } -void average_pkt_jitter(int src, int dst, int application) -{ - +void average_pkt_jitter(int src, int dst, int application) { if (otg_info->rx_jitter_sample[src][dst][application] > 0 ) { otg_info->rx_jitter_avg[src][dst][application]/= otg_info->rx_jitter_sample[src][dst][application]; otg_info->rx_jitter_avg_e2e[src][dst][application]/= otg_info->rx_jitter_sample[src][dst][application]; @@ -189,13 +176,10 @@ void average_pkt_jitter(int src, int dst, int application) LOG_T(OTG,"average_jitter_dl %lf average_jitter_ul %lf \n",otg_info->average_jitter_dl_e2e,otg_info->average_jitter_ul_e2e); } - } -void average_total_jitter(void) -{ +void average_total_jitter(void) { unsigned int i,j,k; - otg_info->average_jitter_dl=0; otg_info->average_jitter_ul=0; otg_info->average_jitter_dl_e2e=0; @@ -207,7 +191,6 @@ void average_total_jitter(void) if (i<NB_eNB_INST) { otg_info->average_jitter_dl+=otg_info->rx_jitter_avg[i][j][k]; otg_info->average_jitter_dl_e2e+=otg_info->rx_jitter_avg_e2e[i][j][k]; - } else { otg_info->average_jitter_ul+=otg_info->rx_jitter_avg[i][j][k]; otg_info->average_jitter_ul_e2e+=otg_info->rx_jitter_avg_e2e[i][j][k]; @@ -221,10 +204,8 @@ void average_total_jitter(void) // otg_info->average_jitter_ul/= (float)NB_UE_INST; } -void kpi_gen() -{ +void kpi_gen() { int i, j,k; - int tx_total_bytes_dl=0; int tx_total_pkts_dl=0; int rx_total_bytes_dl=0; @@ -233,13 +214,10 @@ void kpi_gen() int tx_total_pkts_ul=0; int rx_total_bytes_ul=0; int rx_total_pkts_ul=0; - float min_owd_dl=0; float max_owd_dl=0; - float min_owd_dl_e2e=0; float max_owd_dl_e2e=0; - int tx_total_bytes_dl_background=0; int tx_total_pkts_dl_background=0; int rx_total_bytes_dl_background=0; @@ -248,27 +226,18 @@ void kpi_gen() int tx_total_pkts_ul_background=0; int rx_total_bytes_ul_background=0; int rx_total_pkts_ul_background=0; - float min_owd_ul=0; float max_owd_ul=0; float min_owd_ul_e2e=0; float max_owd_ul_e2e=0; - - int tx_total_bytes_dl_multicast=0; int tx_total_pkts_dl_multicast=0; int rx_total_bytes_dl_multicast=0; int rx_total_pkts_dl_multicast=0; - - int num_active_source=0; - - int dl_ok=1,ul_ok=1; - char traffic_type[12]; char traffic[30]; - #ifdef STANDALONE FILE *file; file = fopen("log_OTG.txt", "w"); @@ -281,11 +250,8 @@ void kpi_gen() #endif - - for (i=0; i<(NB_eNB_INST + NB_UE_INST); i++) { for (j=0; j<(NB_eNB_INST + NB_UE_INST); j++) { - /*background stats*/ if (i<NB_eNB_INST) { tx_total_bytes_dl_background+=otg_info->tx_num_bytes_background[i][j]; @@ -300,7 +266,6 @@ void kpi_gen() } for (k=0; k<MAX_NUM_APPLICATION; k++) { - tx_throughput(i,j,k); rx_goodput(i,j,k); rx_loss_rate_pkts(i,j,k); @@ -319,7 +284,6 @@ void kpi_gen() tx_total_pkts_dl_multicast+=otg_multicast_info->tx_num_pkt[i][j][k]; rx_total_bytes_dl_multicast+=otg_multicast_info->rx_num_bytes[i][j][k]; rx_total_pkts_dl_multicast+=otg_multicast_info->rx_num_pkt[i][j][k]; - #ifdef STANDALONE LOG_I(OTG,"No stats for multicast "); // do nothing #else @@ -329,21 +293,17 @@ void kpi_gen() if (otg_multicast_info->tx_num_bytes[i][j][k]>0) { LOG_I(OTG,"----------------------------------------------------------\n"); LOG_I(OTG,"Total Time (multicast) (ms)= %d \n", otg_info->ctime+1); - // LOG_I(OTG,"[%s] Multicast [eNB:%d -> UE:%d] \n",traffic_type, i, j); - LOG_I(OTG,"[MULTICAST] Total packets(TX)= %d \n", otg_multicast_info->tx_num_pkt[i][j][k]); LOG_I(OTG,"[MULTICAST] Total bytes(TX)= %d \n", otg_multicast_info->tx_num_bytes[i][j][k]); LOG_I(OTG,"[MULTICAST] Total packets(RX)= %d \n", otg_multicast_info->rx_num_pkt[i][j][k]); LOG_I(OTG,"[MULTICAST] Total bytes(RX)= %d \n", otg_multicast_info->rx_num_bytes[i][j][k]); - LOG_I(OTG,"[MULTICAST] TX throughput = %.7f (Kbit/s) \n", otg_multicast_info->tx_throughput[i][j]); LOG_I(OTG,"[MULTICAST] RX goodput = %.7f (Kbit/s) \n", otg_multicast_info->rx_goodput[i][j]); // if (otg_multicast_info->rx_loss_rate[i][j]>0){ // LOG_I(OTG,"[MULTICAST] Loss rate = %lf \n", (otg_multicast_info->rx_loss_rate[i][j])); // LOG_I(OTG,"[MULTICAST] NB Lost packets=%d \n", (otg_multicast_info->tx_num_pkt[i][j][k]-otg_multicast_info->rx_num_pkt[i][j][k])); //} - // if ((g_otg->background_stats==1)&&(otg_info->tx_num_bytes_background[i][j]>0)){ LOG_F(OTG,"----------------------------------------------------------\n"); LOG_F(OTG,"Total Time (multicast) (ms)= %d \n", otg_info->ctime+1); @@ -363,12 +323,9 @@ void kpi_gen() } #endif - }// end for multicast - if ((otg_info->tx_throughput[i][j][k]>0)||((otg_info->tx_throughput_background[i][j]>0) && (otg_info->tx_num_bytes[i][j][k]>0))) { - num_active_source+=1; if (i<NB_eNB_INST) { // DL @@ -392,7 +349,6 @@ void kpi_gen() if ((max_owd_dl_e2e<otg_info->rx_owd_max_e2e[i][j][k]) || (max_owd_dl_e2e==0)) max_owd_dl_e2e=otg_info->rx_owd_max_e2e[i][j][k]; - } else { // UL tx_total_bytes_ul+=otg_info->tx_num_bytes[i][j][k]; tx_total_pkts_ul+=otg_info->tx_num_pkt[i][j][k]; @@ -414,7 +370,6 @@ void kpi_gen() if ((max_owd_ul_e2e<otg_info->rx_owd_max_e2e[i][j][k]) || (max_owd_ul_e2e==0)) max_owd_ul_e2e=otg_info->rx_owd_max_e2e[i][j][k]; - } //LOG_D(OTG,"KPI: (src=%d, dst=%d, appli %d) NB packet TX= %d, NB packet RX= %d\n ",i, j, otg_info->tx_num_pkt[i][j][k], otg_info->rx_num_pkt[i][j][k]); @@ -432,9 +387,7 @@ void kpi_gen() traffic[sizeof(traffic) - 1] = 0; // terminate string } - #ifdef STANDALONE - fprintf(file,"----------------------------------------------------------\n"); fprintf(file,"Total Time (ms)= %d \n", otg_info->ctime+1); @@ -467,8 +420,6 @@ void kpi_gen() } } */ - - #else LOG_I(OTG,"----------------------------------------------------------\n"); LOG_I(OTG,"Total Time (ms)= %d \n", otg_info->ctime+1); @@ -555,15 +506,11 @@ void kpi_gen() } */ #endif - } // if ((otg_multicast_info->tx_throughput[i][j]>0) && (otg_info->tx_num_bytes[i][j][k]>0)) { - }// end loop of k - - #ifdef STANDALONE if ((g_otg->background_stats==1)&&(otg_info->tx_num_bytes_background[i][j]>0)) { @@ -629,14 +576,10 @@ void kpi_gen() } #endif - - }// end loop of j }// end loop of i - // average_total_jitter(); - #ifdef STANDALONE fprintf (file,"**************** TOTAL DL RESULTS ******************\n"); fprintf(file,"Total Time= %d \n", otg_info->ctime+1); @@ -723,7 +666,6 @@ void kpi_gen() LOG_I(OTG,"[MULTICAST] RX throughput = %.7f(Kbit/s) \n", ((double)rx_total_bytes_dl_multicast*1000*8)/(otg_info->ctime*1024)); } - LOG_F(OTG,"**************** TOTAL DL RESULTS ******************\n"); LOG_F(OTG,"Total Time (ms)= %d \n", otg_info->ctime+1); LOG_F(OTG,"[DATA] Total packets(TX)= %d \n", tx_total_pkts_dl); @@ -762,8 +704,6 @@ void kpi_gen() LOG_F(OTG,"[MULTICAST] RX throughput = %.7f(Kbit/s) \n", ((double)rx_total_bytes_dl_multicast*1000*8)/(otg_info->ctime*1024)); } - - LOG_I(OTG,"**************** TOTAL UL RESULTS ******************\n"); LOG_I(OTG,"Total Time (ms)= %d \n", otg_info->ctime+1); LOG_I(OTG,"[DATA] Total packets(TX)= %d \n", tx_total_pkts_ul); @@ -795,7 +735,6 @@ void kpi_gen() LOG_I(OTG,"[BACKGROUND] Total bytes(RX)= %d \n", rx_total_bytes_ul_background); LOG_I(OTG,"[BACKGROUND] TX throughput = %.7f(Kbit/s) \n", ((double)tx_total_bytes_ul_background*1000*8)/(otg_info->ctime*1024)); LOG_I(OTG,"[BACKGROUND] RX throughput = %.7f(Kbit/s) \n", ((double)rx_total_bytes_ul_background*1000*8)/(otg_info->ctime*1024)); - } LOG_F(OTG,"**************** TOTAL UL RESULTS ******************\n"); @@ -825,7 +764,6 @@ void kpi_gen() LOG_F(OTG,"[BACKGROUND] Total bytes(RX)= %d \n", rx_total_bytes_ul_background); LOG_F(OTG,"[BACKGROUND] TX throughput = %.7f(Kbit/s) \n", ((double)tx_total_bytes_ul_background*1000*8)/(otg_info->ctime*1024)); LOG_F(OTG,"[BACKGROUND] RX throughput = %.7f(Kbit/s) \n", ((double)rx_total_bytes_ul_background*1000*8)/(otg_info->ctime*1024)); - } if ((dl_ok == 1 ) && (ul_ok ==1)) @@ -837,8 +775,7 @@ void kpi_gen() } -void add_log_metric(int src, int dst, int ctime, double metric, unsigned int label) -{ +void add_log_metric(int src, int dst, int ctime, double metric, unsigned int label) { unsigned int i; unsigned int j; unsigned int node_actif=0; @@ -846,28 +783,27 @@ void add_log_metric(int src, int dst, int ctime, double metric, unsigned int lab //LOG_I(OTG,"[%d][%d] LOGG_ADDED ctime=%d, metric=%.2f \n", src, dst, ctime, metric); switch (label) { - case OTG_LATENCY: - add_log_label(label, &start_log_latency); - break; - - case OTG_LATENCY_BG: - add_log_label(label, &start_log_latency_bg); - break; - - case OTG_GP: - add_log_label(label, &start_log_GP); - break; - - case OTG_GP_BG: - add_log_label(label, &start_log_GP_bg); - break; - - case OTG_JITTER: - add_log_label(label, &start_log_GP_bg); - break; - - default: - LOG_E(OTG, "File label unknown %d \n", label); + case OTG_LATENCY: + add_log_label(label, &start_log_latency); + break; + + case OTG_LATENCY_BG: + add_log_label(label, &start_log_latency_bg); + break; + + case OTG_GP: + add_log_label(label, &start_log_GP); + break; + + case OTG_GP_BG: + add_log_label(label, &start_log_GP_bg); + break; + + case OTG_JITTER: + add_log_label(label, &start_log_GP_bg); + break; + default: + LOG_E(OTG, "File label unknown %u \n", label); } LOG_F(label,"%d ", ctime); @@ -892,8 +828,7 @@ void add_log_metric(int src, int dst, int ctime, double metric, unsigned int lab -void add_log_label(unsigned int label, unsigned int * start_log_metric) -{ +void add_log_label(unsigned int label, unsigned int *start_log_metric) { unsigned int i; unsigned int j; unsigned int node_actif=0; @@ -910,7 +845,7 @@ void add_log_label(unsigned int label, unsigned int * start_log_metric) node_actif++; if (node_actif>0) - LOG_F(label,"%d->%d ", i, j); + LOG_F(label,"%u->%u ", i, j); } } diff --git a/openair2/UTIL/OTG/otg_rx.c b/openair2/UTIL/OTG/otg_rx.c index 46cad30cb8b78a5d16b5264e8e8d0826b76da9a4..a8b18e23b7aa5f6f84b84ae7d5f2fe449ca93d69 100644 --- a/openair2/UTIL/OTG/otg_rx.c +++ b/openair2/UTIL/OTG/otg_rx.c @@ -38,9 +38,9 @@ #include "otg_kpi.h" #ifdef ENABLE_DB_STATS -#include <mysql.h> -#include <m_ctype.h> -#include <sql_common.h> + #include <mysql.h> + #include <m_ctype.h> + #include <sql_common.h> #endif extern unsigned char NB_eNB_INST; @@ -54,12 +54,10 @@ extern unsigned char NB_UE_INST; #define MIN(x,y) ((x)<(y)?(x):(y)) // Check if the packet is well received or not and extract data -int otg_rx_pkt(const int dst_instanceP, const int ctime, const char * const buffer_tx, const unsigned int size) -{ - +int otg_rx_pkt(const int dst_instanceP, const int ctime, const char *const buffer_tx, const unsigned int size) { int bytes_read = 0; - otg_hdr_info_t * otg_hdr_info_rx; - otg_hdr_t * otg_hdr_rx; + otg_hdr_info_t *otg_hdr_info_rx; + otg_hdr_t *otg_hdr_rx; int is_size_ok = 0; unsigned int seq_num_rx; unsigned int nb_loss_pkts; @@ -70,26 +68,22 @@ int otg_rx_pkt(const int dst_instanceP, const int ctime, const char * const buff if (buffer_tx!=NULL) { otg_hdr_info_rx = (otg_hdr_info_t *) (&buffer_tx[bytes_read]); bytes_read += sizeof (otg_hdr_info_t); - - LOG_D(OTG,"otg_rx_pkt functions: destination %d, size %d, otg_hdr_info_rx->flag %.4x, otg_hdr_info_rx->size %d \n", + LOG_D(OTG,"otg_rx_pkt functions: destination %d, size %u, otg_hdr_info_rx->flag %.4x, otg_hdr_info_rx->size %u \n", dst_instanceP, size, otg_hdr_info_rx->flag, otg_hdr_info_rx->size); - if (((otg_hdr_info_rx->flag == 0xffff) || (otg_hdr_info_rx->flag == 0xbbbb) || (otg_hdr_info_rx->flag == 0x1000)) && (otg_hdr_info_rx->size == size )) { //data traffic - LOG_I(OTG,"MAX_RX_INFO %d %d \n",NB_eNB_INST, NB_UE_INST); - /*is_size_ok= 0; if (( otg_hdr_info_rx->size ) == size ) {*/ is_size_ok= 1; otg_hdr_rx = (otg_hdr_t *) (&buffer_tx[bytes_read]); - LOG_I(OTG,"[SRC %d][DST %d] [FLOW_idx %d][APP TYPE %d] RX INFO pkt at time %d: flag 0x %x, seq number %d, tx time %d, size (hdr %d, pdcp %d) \n", + LOG_I(OTG,"[SRC %u][DST %u] [FLOW_idx %u][APP TYPE %u] RX INFO pkt at time %d: flag 0x %x, seq number %u, tx time %u, size (hdr %u, pdcp %u) \n", otg_hdr_rx->src_instance, otg_hdr_rx->dst_instance, otg_hdr_rx->flow_id, @@ -99,14 +93,12 @@ int otg_rx_pkt(const int dst_instanceP, const int ctime, const char * const buff otg_hdr_rx->seq_num, otg_hdr_rx->time, otg_hdr_info_rx->size, size); - bytes_read += sizeof (otg_hdr_t); - src_instance = otg_hdr_rx->src_instance; dst_instance = otg_hdr_rx->dst_instance; if (dst_instance != dst_instanceP) { -//#warning "LG: TODO think about multicast traffic" + //#warning "LG: TODO think about multicast traffic" /* TODO: fix this LOG, a lot of missing parameters, replaced by a simple basic version */ /*LOG_W(OTG,"[SRC %d][DST %d] [FLOW_idx %d][APP TYPE %d] RX INFO pkt at time %d: flag 0x %x, seq number %d, tx time %d, size (hdr %d, pdcp %d) not for dest instance %u\n", dst_instanceP);*/ @@ -114,7 +106,7 @@ int otg_rx_pkt(const int dst_instanceP, const int ctime, const char * const buff } if(otg_hdr_rx->traffic_type > MAX_NUM_APPLICATION) { - LOG_W(OTG,"RX packet: application type out of range %d for the pair of (src %d, dst %d) \n", + LOG_W(OTG,"RX packet: application type out of range %u for the pair of (src %u, dst %u) \n", otg_hdr_rx->traffic_type, src_instance, dst_instance); otg_hdr_rx->traffic_type=0; } @@ -135,7 +127,7 @@ int otg_rx_pkt(const int dst_instanceP, const int ctime, const char * const buff // rx_check_loss(src_instance, dst_instance, otg_hdr_info_rx->flag, otg_hdr_rx->seq_num, &seq_num_rx, &nb_loss_pkts); // otg_multicast_info->loss_rate[src_instance][dst_instance][otg_hdr_rx->traffic_type]=nb_loss_pkts; //otg_multicast_info->rx_sn[src_instance][dst_instance][otg_hdr_rx->traffic_type]=seq_num_rx; - LOG_I(OTG,"received a multicast packet with size %d sn %d ran owd %d loss rate %d\n", + LOG_I(OTG,"received a multicast packet with size %u sn %u ran owd %u loss rate %u\n", otg_hdr_info_rx->size, seq_num_rx, ctime- otg_hdr_rx->time, nb_loss_pkts); //return 0; } /** background traffic **/ @@ -148,10 +140,8 @@ int otg_rx_pkt(const int dst_instanceP, const int ctime, const char * const buff nb_loss_pkts=otg_info->nb_loss_pkts_background_ul[src_instance][dst_instance]; } - - LOG_D(OTG,"[%d][%d] AGGREGATION LEVEL (RX) %d \n", src_instance, dst_instance, otg_hdr_rx->aggregation_level); + LOG_D(OTG,"[%u][%u] AGGREGATION LEVEL (RX) %u \n", src_instance, dst_instance, otg_hdr_rx->aggregation_level); otg_info->aggregation_level[src_instance][dst_instance]=otg_hdr_rx->aggregation_level; - /* Loss and out of sequence data management */ lost_packet= rx_check_loss( src_instance, @@ -161,11 +151,9 @@ int otg_rx_pkt(const int dst_instanceP, const int ctime, const char * const buff &seq_num_rx, &nb_loss_pkts); - if (otg_info->owd_const[src_instance][dst_instance][otg_hdr_rx->flow_id]==0) owd_const_gen(src_instance,dst_instance,otg_hdr_rx->flow_id, otg_hdr_rx->traffic_type); - /******/ /* float owd_const_capillary_v=owd_const_capillary()/2; @@ -185,7 +173,7 @@ int otg_rx_pkt(const int dst_instanceP, const int ctime, const char * const buff otg_info->radio_access_delay[src_instance][dst_instance]=(float) (ctime- otg_hdr_rx->time); otg_multicast_info->radio_access_delay[src_instance][dst_instance]=(float) (ctime- otg_hdr_rx->time); } else { - LOG_I(OTG,"received packet has tx time %d greater than the current time %d\n",otg_hdr_rx->time,ctime ); + LOG_I(OTG,"received packet has tx time %u greater than the current time %d\n",otg_hdr_rx->time,ctime ); otg_info->radio_access_delay[src_instance][dst_instance] = 0; otg_multicast_info->radio_access_delay[src_instance][dst_instance]=0; } @@ -196,8 +184,7 @@ int otg_rx_pkt(const int dst_instanceP, const int ctime, const char * const buff otg_info->rx_pkt_owd_e2e[src_instance][dst_instance]= otg_info->owd_const[src_instance][dst_instance][otg_hdr_rx->flow_id] + otg_info->radio_access_delay[src_instance][dst_instance]; otg_multicast_info->rx_pkt_owd[src_instance][dst_instance]=otg_multicast_info->radio_access_delay[src_instance][dst_instance]; - - LOG_D(OTG, "[src %d][dst %d] ctime %d tx time %d: OWD %lf E2E OWD %lf \n", + LOG_D(OTG, "[src %u][dst %u] ctime %d tx time %u: OWD %lf E2E OWD %lf \n", src_instance, dst_instance, ctime, @@ -217,7 +204,7 @@ int otg_rx_pkt(const int dst_instanceP, const int ctime, const char * const buff otg_info->rx_pkt_jitter[src_instance][dst_instance]= abs(otg_info->rx_pkt_owd_history[src_instance][dst_instance][0] - otg_info->rx_pkt_owd_history[src_instance][dst_instance][1]); - LOG_D(OTG,"The packet jitter for the pair (src %d, dst %d)) at %d is %lf (current %lf, previous %lf) \n", + LOG_D(OTG,"The packet jitter for the pair (src %u, dst %u)) at %d is %lf (current %lf, previous %lf) \n", src_instance, dst_instance, ctime, otg_info->rx_pkt_jitter[src_instance][dst_instance], otg_info->rx_pkt_owd_history[src_instance][dst_instance][0], otg_info->rx_pkt_owd_history[src_instance][dst_instance][1]); // e2e @@ -230,26 +217,24 @@ int otg_rx_pkt(const int dst_instanceP, const int ctime, const char * const buff otg_info->rx_pkt_jitter_e2e[src_instance][dst_instance]= abs(otg_info->rx_pkt_owd_history_e2e[src_instance][dst_instance][0] - otg_info->rx_pkt_owd_history_e2e[src_instance][dst_instance][1]); - LOG_D(OTG,"The packet jitter for the pair (src %d, dst %d)) at %d is %lf (current %lf, previous %lf) \n", + LOG_D(OTG,"The packet jitter for the pair (src %u, dst %u)) at %d is %lf (current %lf, previous %lf) \n", src_instance, dst_instance, ctime, otg_info->rx_pkt_jitter_e2e[src_instance][dst_instance], otg_info->rx_pkt_owd_history_e2e[src_instance][dst_instance][0], otg_info->rx_pkt_owd_history_e2e[src_instance][dst_instance][1]); - } if (otg_hdr_info_rx->flag == 0x1000) { - LOG_I(OTG,"[SRC%d -> DST %d] Received a multicast packet at time %d with size %d, seq num %d, ran owd %d number loss packet %d\n", + LOG_I(OTG,"[SRC%u -> DST %u] Received a multicast packet at time %d with size %u, seq num %u, ran owd %u number loss packet %u\n", src_instance, dst_instance, ctime,otg_hdr_info_rx->size, otg_hdr_rx->seq_num, ctime - otg_hdr_rx->time, nb_loss_pkts); - - LOG_I(OTG,"INFO LATENCY :: [SRC %d][DST %d] radio access %.2f (tx time %d, ctime %d), OWD:%d (ms):\n", + LOG_I(OTG,"INFO LATENCY :: [SRC %u][DST %u] radio access %.2f (tx time %u, ctime %d), OWD:%d (ms):\n", src_instance, dst_instance, otg_multicast_info->radio_access_delay[src_instance][dst_instance], @@ -286,8 +271,7 @@ int otg_rx_pkt(const int dst_instanceP, const int ctime, const char * const buff otg_multicast_info->rx_total_bytes_dl+=otg_hdr_info_rx->size; } else { - - LOG_I(OTG,"[SRC %d][DST %d] Stats :: radio access latency %.2f (tx time %d, ctime %d) jitter %.2f, Estimated E2E OWD:%.2f (ms):\n", + LOG_I(OTG,"[SRC %u][DST %u] Stats :: radio access latency %.2f (tx time %u, ctime %d) jitter %.2f, Estimated E2E OWD:%.2f (ms):\n", src_instance, dst_instance, otg_info->radio_access_delay[src_instance][dst_instance], @@ -296,7 +280,6 @@ int otg_rx_pkt(const int dst_instanceP, const int ctime, const char * const buff otg_info->rx_pkt_owd_e2e[src_instance][dst_instance]); if (otg_hdr_info_rx->flag == 0xffff) { - if (otg_info->rx_owd_max[src_instance][dst_instance][otg_hdr_rx->traffic_type]==0) { otg_info->rx_owd_max[src_instance][dst_instance][otg_hdr_rx->traffic_type]=otg_info->rx_pkt_owd[src_instance][dst_instance]; otg_info->rx_owd_min[src_instance][dst_instance][otg_hdr_rx->traffic_type]=otg_info->rx_pkt_owd[src_instance][dst_instance]; @@ -332,7 +315,6 @@ int otg_rx_pkt(const int dst_instanceP, const int ctime, const char * const buff otg_info->rx_jitter_avg_e2e[src_instance][dst_instance][otg_hdr_rx->traffic_type] += otg_info->rx_pkt_jitter_e2e[src_instance][dst_instance]; otg_info->rx_jitter_sample[src_instance][dst_instance][otg_hdr_rx->traffic_type] +=1; } - } if (g_otg->curve==1) { @@ -355,15 +337,12 @@ int otg_rx_pkt(const int dst_instanceP, const int ctime, const char * const buff otg_info->rx_total_bytes_dl+=otg_hdr_info_rx->size; else otg_info->rx_total_bytes_ul+=otg_hdr_info_rx->size; - } //LOG_I(OTG,"RX INFO :: RTT MIN(one way) ms: %.2f, RTT MAX(one way) ms: %.2f \n", otg_info->rx_owd_min[src][dst], otg_info->rx_owd_max[src][dst]); - /* xforms part: add metrics */ - //printf("payload_size %d, header_size %d \n", otg_hdr_rx->pkts_size, otg_hdr_rx->hdr_type); - LOG_I(OTG,"[RX] OTG packet, PACKET SIZE [SRC %d][DST %d]: Flag (0x%x), Traffic %d, time(%d), Seq num (%d), Total size (%d)\n", + LOG_I(OTG,"[RX] OTG packet, PACKET SIZE [SRC %u][DST %u]: Flag (0x%x), Traffic %u, time(%d), Seq num (%u), Total size (%u)\n", src_instance, dst_instance, otg_hdr_info_rx->flag, @@ -372,7 +351,6 @@ int otg_rx_pkt(const int dst_instanceP, const int ctime, const char * const buff otg_hdr_rx->seq_num, size); /*LOG_I(OTG,"details::RX [SRC %d][DST %d]: Flag (0x%x), time(%d), Seq num (%d), Total size (%d), header(%d), payload (%d) \n", src, dst, otg_hdr_info_rx->flag, ctime, otg_hdr_rx->seq_num, size, strlen(packet_rx->header), strlen(packet_rx->payload));*/ - if (otg_hdr_info_rx->flag == 0xffff) { otg_info->rx_num_pkt[src_instance][dst_instance][otg_hdr_rx->traffic_type]+=1; otg_info->rx_num_bytes[src_instance][dst_instance][otg_hdr_rx->traffic_type]+=otg_hdr_info_rx->size; @@ -402,7 +380,6 @@ int otg_rx_pkt(const int dst_instanceP, const int ctime, const char * const buff otg_hdr_rx->time, ((otg_hdr_info_rx->size*1000*8)/(otg_info->rx_pkt_owd[src_instance][dst_instance]*1024 )), OTG_GP); /* compute the throughput in Kbit/s */ - } else if (otg_hdr_info_rx->flag == 0x1000) { otg_multicast_info->rx_num_pkt[src_instance][dst_instance][otg_hdr_rx->traffic_type]+=1; otg_multicast_info->rx_num_bytes[src_instance][dst_instance][otg_hdr_rx->traffic_type]+=otg_hdr_info_rx->size; @@ -446,18 +423,17 @@ int otg_rx_pkt(const int dst_instanceP, const int ctime, const char * const buff if (is_size_ok == 0) { otg_hdr_rx = (otg_hdr_t *) (&buffer_tx[bytes_read]); - LOG_W(OTG,"[SRC %d][DST %d] RX pkt: seq number %d size mis-matche (hdr %d, pdcp %d) \n", + LOG_W(OTG,"[SRC %u][DST %u] RX pkt: seq number %u size mis-matche (hdr %u, pdcp %u) \n", src_instance, dst_instance, otg_hdr_rx->seq_num, otg_hdr_info_rx->size, size); otg_info->nb_loss_pkts_otg[src_instance][dst_instance]++; } return(0); } else { - LOG_W(OTG,"RX: Not an OTG pkt, forward to upper layer (flag %x, size %d, pdcp_size %d) FIX ME \n", + LOG_W(OTG,"RX: Not an OTG pkt, forward to upper layer (flag %x, size %u, pdcp_size %u) FIX ME \n", otg_hdr_info_rx->flag, otg_hdr_info_rx->size, size); return(1); //to be fixed on the real case to one } - } return(0); @@ -471,10 +447,8 @@ int rx_check_loss( const int dst, const unsigned int flag, const int seq_num, - unsigned int * const seq_num_rx, - unsigned int * const nb_loss_pkts) -{ - + unsigned int *const seq_num_rx, + unsigned int *const nb_loss_pkts) { /* Loss and out of sequence data management, we have 3 case : */ /* (1) Receieved packet corresponds to the expected one, in terms of the sequence number*/ int lost_packet=0; @@ -509,8 +483,7 @@ void owd_const_gen( const int src, const int dst, const int flow_id, - const unsigned int flag) -{ + const unsigned int flag) { otg_info->owd_const[src][dst][flow_id]=(owd_const_mobile_core()+owd_const_IP_backbone()+owd_const_application())/2; if ((flag==M2M)||(flag==M2M_TRAFFIC)||(flag==AUTO_PILOT_L)||(flag==AUTO_PILOT_M)||(flag==AUTO_PILOT_H)||(flag==VIRTUAL_GAME_L)||(flag==VIRTUAL_GAME_M)|| (flag==VIRTUAL_GAME_H)||(flag==VIRTUAL_GAME_F) @@ -523,8 +496,7 @@ void owd_const_gen( -float owd_const_capillary(void) -{ +float owd_const_capillary(void) { /*return (uniform_dist(MIN_APPLICATION_PROCESSING_GATEWAY_DELAY, MAX_APPLICATION_PROCESSING_GATEWAY_DELAY) + uniform_dist(MIN_FORMATING_TRANSFERRING_DELAY, MAX_FORMATING_TRANSFERRING_DELAY) + uniform_dist(MIN_ACCESS_DELAY, MAX_ACCESS_DELAY) + @@ -534,8 +506,7 @@ float owd_const_capillary(void) } -float owd_const_mobile_core(void) -{ +float owd_const_mobile_core(void) { /*double delay; // this is a delay model for a loaded GGSN according to //"M. Laner, P. Svoboda and M. Rupp, Latency Analysis of 3G Network Components, EW'12, Poznan, Poland, 2012", table 2, page 6. @@ -559,15 +530,12 @@ float owd_const_mobile_core(void) return ((double)MIN_U_PLANE_CORE_IP_ACCESS_DELAY+ (double)MAX_U_PLANE_CORE_IP_ACCESS_DELAY + (double)MIN_FW_PROXY_DELAY + (double)MAX_FW_PROXY_DELAY)/2; } -float owd_const_IP_backbone(void) -{ +float owd_const_IP_backbone(void) { /*return uniform_dist(MIN_NETWORK_ACCESS_DELAY,MAX_NETWORK_ACCESS_DELAY);*/ return ((double)MIN_NETWORK_ACCESS_DELAY+(double)MAX_NETWORK_ACCESS_DELAY)/2; - } -float owd_const_application(void) -{ +float owd_const_application(void) { /*return uniform_dist(MIN_APPLICATION_ACESS_DELAY, MAX_APPLICATION_ACESS_DELAY);*/ return ((double)MIN_APPLICATION_ACESS_DELAY+(double)MAX_APPLICATION_ACESS_DELAY)/2; } diff --git a/openair2/UTIL/OTG/otg_tx.c b/openair2/UTIL/OTG/otg_tx.c index ac3ffd0fb29b0bfdf7666c13e7122b9d7b76d6b8..2459bb7338860747e488f1edfc98d98ca407cbfa 100644 --- a/openair2/UTIL/OTG/otg_tx.c +++ b/openair2/UTIL/OTG/otg_tx.c @@ -305,10 +305,10 @@ unsigned char *packet_gen( otg_info->tx_num_pkt[src_instance][dst_instance][otg_info->traffic_type[src_instance][dst_instance]]+=1; if (size!=strlen(payload)) - LOG_E(OTG,"[%d][%d] [0x %x] The expected packet size does not match the payload size : size %d, strlen %zu, seq_num %d packet: |%s|%s| \n", + LOG_E(OTG,"[%d][%d] [0x %x] The expected packet size does not match the payload size : size %u, strlen %zu, seq_num %u packet: |%s|%s| \n", src_instance, dst_instance, flag, size, strlen(payload), seq_num, header, payload); else - LOG_D(OTG,"[%d][%d] 0x %x][m2m Aggre %d][Flow %d][Type %d/%s] TX INFO pkt at time %d Size= [payload %d] [Total %zu] with seq num %d, state=%d : |%s|%s| \n", + LOG_D(OTG,"[%d][%d] 0x %x][m2m Aggre %u][Flow %u][Type %u/%s] TX INFO pkt at time %d Size= [payload %u] [Total %zu] with seq num %u, state=%u : |%s|%s| \n", src_instance, dst_instance, flag, otg_info->m2m_aggregation[src_instance][dst_instance], otg_info->flow_id[src_instance][dst_instance], @@ -316,7 +316,7 @@ unsigned char *packet_gen( map_int_to_str(otg_app_type_names,otg_info->traffic_type[src_instance][dst_instance]), ctime, size, header_size+strlen(payload), seq_num,state, header, payload); - LOG_D(OTG, "[%d]MY_SEQ %d \n", otg_info->traffic_type[src_instance][dst_instance], otg_info->seq_num[src_instance][dst_instance][otg_info->traffic_type[src_instance][dst_instance]] ); + LOG_D(OTG, "[%u]MY_SEQ %d \n", otg_info->traffic_type[src_instance][dst_instance], otg_info->seq_num[src_instance][dst_instance][otg_info->traffic_type[src_instance][dst_instance]] ); } else { if ((g_otg->aggregation_level[src_instance][dst_instance][application]*otg_info->size_background[src_instance][dst_instance])<=PAYLOAD_MAX) otg_info->size_background[src_instance][dst_instance]=g_otg->aggregation_level[src_instance][dst_instance][application]*otg_info->size_background[src_instance][dst_instance]; @@ -335,7 +335,7 @@ unsigned char *packet_gen( otg_info->seq_num_background[src_instance][dst_instance]+=1; if (otg_info->size_background[src_instance][dst_instance]!=strlen(payload)) - LOG_E(OTG,"[%d][%d] [0x %x] The expected packet size does not match the payload size : size %d, strlen %zu, seq num %d, packet |%s|%s| \n", + LOG_E(OTG,"[%d][%d] [0x %x] The expected packet size does not match the payload size : size %d, strlen %zu, seq num %u, packet |%s|%s| \n", src_instance, dst_instance, flag, @@ -345,7 +345,7 @@ unsigned char *packet_gen( header, payload); else - LOG_D(OTG,"[%d][%d][0x %x][%d] TX INFO pkt at time %s size is %d with seq num %d, state=%d : |%s|%s| \n", + LOG_D(OTG,"[%d][%d][0x %x][%d] TX INFO pkt at time %s size is %d with seq num %u, state=%u : |%s|%s| \n", src_instance, dst_instance, flag, @@ -367,7 +367,7 @@ unsigned char *packet_gen( otg_info->tx_total_bytes_ul+=buffer_size; if (otg_info->traffic_type[src_instance][dst_instance] > MAX_NUM_APPLICATION) { - LOG_W(OTG,"application type out of range %d for the pair of (src %d, dst %d) \n", + LOG_W(OTG,"application type out of range %u for the pair of (src %d, dst %d) \n", otg_info->traffic_type[src_instance][dst_instance], src_instance, dst_instance); otg_info->traffic_type[src_instance][dst_instance]=0; } @@ -425,7 +425,7 @@ unsigned char *packet_gen_multicast( g_otg_multicast->idt_max[src_instance][dst_instance][app])); size = ceil(uniform_dist(g_otg_multicast->size_min[src_instance][dst_instance][app], g_otg_multicast->size_max[src_instance][dst_instance][app])); - LOG_D(OTG, "ptime %d, ctime %d idt %d (min %d, max %d) size %d (min %d, max %d)\n", + LOG_D(OTG, "ptime %d, ctime %d idt %d (min %d, max %d) size %u (min %d, max %d)\n", otg_multicast_info->ptime[src_instance][dst_instance][application], ctime, otg_multicast_info->idt[src_instance][dst_instance][app], @@ -459,10 +459,10 @@ unsigned char *packet_gen_multicast( otg_multicast_info->tx_num_bytes[src_instance][dst_instance][app]); if (size!=strlen(payload)) - LOG_E(OTG,"[src %d][dst %d] The expected packet size does not match the payload size : size %d, strlen %zu \n", + LOG_E(OTG,"[src %d][dst %d] The expected packet size does not match the payload size : size %u, strlen %zu \n", src_instance, dst_instance, size, strlen(payload)); else { - LOG_I(OTG,"[src %d][dst %d]TX INFO pkt at time %d Size= [payload %d] [Total %zu] with seq num %d: |%s|%s| \n", + LOG_I(OTG,"[src %d][dst %d]TX INFO pkt at time %d Size= [payload %u] [Total %zu] with seq num %d: |%s|%s| \n", src_instance, dst_instance, ctime, @@ -557,7 +557,7 @@ int check_data_transmit( // for (application=0; application<g_otg->application_idx[src_instance][dst_instance]; application++){ otg_info->gen_pkts=0; - LOG_T(OTG,"FLOW_INFO [src %d][dst %d] [IDX %d] [APPLICATION TYPE %d] MAX %d [M2M %d ]\n", + LOG_T(OTG,"FLOW_INFO [src %d][dst %d] [IDX %d] [APPLICATION TYPE %d] MAX %u [M2M %u ]\n", src_instance, dst_instance, app, g_otg->application_type[src_instance][dst_instance][app], g_otg->application_idx[src_instance][dst_instance], @@ -605,7 +605,7 @@ int check_data_transmit( if (((state==PU_STATE)||(state==ED_STATE))|| (otg_info->idt[src_instance][dst_instance][app]==0) || (( (ctime-otg_info->ptime[src_instance][dst_instance][app]) >= otg_info->idt[src_instance][dst_instance][app] ) )) { - LOG_D(OTG,"[TX] OTG packet: Time To Transmit::OK (Source= %d, Destination= %d, Application %d, State= %d) , (IDT= %d ,ctime= %d, ptime= %d) \n", + LOG_D(OTG,"[TX] OTG packet: Time To Transmit::OK (Source= %d, Destination= %d, Application %d, State= %u) , (IDT= %d ,ctime= %d, ptime= %d) \n", src_instance, dst_instance , app, @@ -654,7 +654,7 @@ int check_data_transmit( if (g_otg->m2m[src_instance][dst_instance][app]==M2M) otg_info->traffic_type[src_instance][dst_instance]=app;//g_otg->application_idx[src_instance][dst_instance];//M2M; - LOG_D(OTG,"[BACKGROUND=%d] Time To Transmit [SRC %d][DST %d][APPLI %d] \n", otg_info->traffic_type_background[src_instance][dst_instance], src_instance, dst_instance, app); + LOG_D(OTG,"[BACKGROUND=%u] Time To Transmit [SRC %d][DST %d][APPLI %d] \n", otg_info->traffic_type_background[src_instance][dst_instance], src_instance, dst_instance, app); } } @@ -720,7 +720,7 @@ void header_size_gen( if ((g_otg->application_type[src_instance][dst_instance][application]==VOIP_G711)||(g_otg->application_type[src_instance][dst_instance][application]==VOIP_G729)) size_header+=RTP_HEADER; - LOG_D(OTG,"Header size is %d [IP V=%d][PROTO=%d]\n", size_header, g_otg->ip_v[src_instance][dst_instance][application],g_otg->trans_proto[src_instance][dst_instance][application]); + LOG_D(OTG,"Header size is %u [IP V=%d][PROTO=%d]\n", size_header, g_otg->ip_v[src_instance][dst_instance][application],g_otg->trans_proto[src_instance][dst_instance][application]); otg_info->header_size_app[src_instance][dst_instance][application]=size_header; } } @@ -889,7 +889,7 @@ unsigned char * serialize_buffer( otg_hdr_p->traffic_type=traffic_type; byte_tx_count += sizeof(otg_hdr_t); - LOG_I(OTG,"traffic type %d\n",otg_hdr_p->traffic_type); + LOG_I(OTG,"traffic type %u\n",otg_hdr_p->traffic_type); // copy the header first memcpy(&tx_buffer[byte_tx_count], header, strlen(header)); byte_tx_count += strlen(header); @@ -1953,7 +1953,7 @@ int header_size_gen_background( otg_info->header_size_background[src_instance][dst_instance]=size_header; } - LOG_D(OTG," [SRC %d][DST %d] BACKGROUND TRAFFIC:: size header %d \n", src_instance, dst_instance, otg_info->header_size_background[src_instance][dst_instance]); + LOG_D(OTG," [SRC %d][DST %d] BACKGROUND TRAFFIC:: size header %u \n", src_instance, dst_instance, otg_info->header_size_background[src_instance][dst_instance]); return otg_info->header_size_background[src_instance][dst_instance]; } @@ -1987,7 +1987,7 @@ void state_management( if (ctime>otg_info->start_holding_time_off[src_instance][dst_instance][application]) { otg_info->c_holding_time_off[src_instance][dst_instance][application]= ctime - otg_info->start_holding_time_off[src_instance][dst_instance][application]; - LOG_D(OTG,"[%d][%d][Appli id %d][Agg Level=%d] STATE:: OFF Holding Time %d (%d, %d)\n", src_instance, dst_instance,application , g_otg->aggregation_level[src_instance][dst_instance][application], + LOG_D(OTG,"[%d][%d][Appli id %d][Agg Level=%u] STATE:: OFF Holding Time %u (%d, %u)\n", src_instance, dst_instance,application , g_otg->aggregation_level[src_instance][dst_instance][application], otg_info->c_holding_time_off[src_instance][dst_instance][application], ctime, otg_info->start_holding_time_off[src_instance][dst_instance][application]); } @@ -1997,7 +1997,7 @@ void state_management( +g_otg->prob_off_pe[src_instance][dst_instance][application]))) && (otg_info->c_holding_time_off[src_instance][dst_instance][application]>=g_otg->holding_time_off_pu[src_instance][dst_instance][application])) { otg_info->state[src_instance][dst_instance][application]=PU_STATE; - LOG_I(OTG,"[%d][%d][Appli id %d][Agg Level=%d] NEW STATE:: OFF-->PU %d (ctime %d, start %d )\n", src_instance, dst_instance,application, + LOG_I(OTG,"[%d][%d][Appli id %d][Agg Level=%u] NEW STATE:: OFF-->PU %u (ctime %d, start %u )\n", src_instance, dst_instance,application, g_otg->aggregation_level[src_instance][dst_instance][application], otg_info->c_holding_time_off[src_instance][dst_instance][application], ctime, otg_info->start_holding_time_off[src_instance][dst_instance][application]); otg_info->state_transition_prob[src_instance][dst_instance][application]=uniform_dist(0,1); @@ -2007,7 +2007,7 @@ void state_management( && (otg_info->state_transition_prob[src_instance][dst_instance][application]< 1-g_otg->prob_off_pe[src_instance][dst_instance][application])) && (otg_info->c_holding_time_off[src_instance][dst_instance][application]>=g_otg->holding_time_off_ed[src_instance][dst_instance][application])) { otg_info->state[src_instance][dst_instance][application]=ED_STATE; - LOG_D(OTG,"[%d][%d][Appli id %d][Agg Level=%d] NEW STATE:: OFF-->ED \n", src_instance, dst_instance,application, g_otg->aggregation_level[src_instance][dst_instance][application]); + LOG_D(OTG,"[%d][%d][Appli id %d][Agg Level=%u] NEW STATE:: OFF-->ED \n", src_instance, dst_instance,application, g_otg->aggregation_level[src_instance][dst_instance][application]); otg_info->state_transition_prob[src_instance][dst_instance][application]=uniform_dist(0,1); } @@ -2015,13 +2015,13 @@ void state_management( && (otg_info->state_transition_prob[src_instance][dst_instance][application]<=1)) && (otg_info->c_holding_time_off[src_instance][dst_instance]>=g_otg->holding_time_off_pe[src_instance][dst_instance])) { otg_info->state[src_instance][dst_instance][application]=PE_STATE; - LOG_I(OTG,"[%d][%d][Appli id %d][Agg Level=%d] NEW STATE:: OFF-->PE \n", src_instance, dst_instance,application, g_otg->aggregation_level[src_instance][dst_instance][application]); + LOG_I(OTG,"[%d][%d][Appli id %d][Agg Level=%u] NEW STATE:: OFF-->PE \n", src_instance, dst_instance,application, g_otg->aggregation_level[src_instance][dst_instance][application]); otg_info->state_transition_prob[src_instance][dst_instance][application]=uniform_dist(0,1); } else { otg_info->c_holding_time_off[src_instance][dst_instance][application]= ctime - otg_info->start_holding_time_off[src_instance][dst_instance][application]; otg_info->state_transition_prob[src_instance][dst_instance][application]=uniform_dist(0,1); - LOG_D(OTG,"[%d][%d][Appli id %d][Agg Level=%d] STATE:: OFF\n", src_instance, dst_instance,application, g_otg->aggregation_level[src_instance][dst_instance][application]); + LOG_D(OTG,"[%d][%d][Appli id %d][Agg Level=%u] STATE:: OFF\n", src_instance, dst_instance,application, g_otg->aggregation_level[src_instance][dst_instance][application]); } break; @@ -2033,20 +2033,20 @@ void state_management( otg_info->state[src_instance][dst_instance][application]=OFF_STATE; otg_info->start_holding_time_off[src_instance][dst_instance][application]=ctime; otg_info->c_holding_time_off[src_instance][dst_instance][application]=0; - LOG_D(OTG,"[%d][%d][Appli id %d][Agg Level=%d] NEW STATE:: PU-->OFF \n", src_instance, dst_instance,application, g_otg->aggregation_level[src_instance][dst_instance][application]); + LOG_D(OTG,"[%d][%d][Appli id %d][Agg Level=%u] NEW STATE:: PU-->OFF \n", src_instance, dst_instance,application, g_otg->aggregation_level[src_instance][dst_instance][application]); otg_info->state_transition_prob[src_instance][dst_instance][application]=uniform_dist(0,1); } else if ((otg_info->state_transition_prob[src_instance][dst_instance][application]<=1-g_otg->prob_pu_pe[src_instance][dst_instance][application]) && (otg_info->state_transition_prob[src_instance][dst_instance][application]>1-(g_otg->prob_pu_ed[src_instance][dst_instance][application] +g_otg->prob_pu_pe[src_instance][dst_instance][application]))) { //otg_info->state[src_instance][dst_instance]=ON_STATE; otg_info->state[src_instance][dst_instance][application]=ED_STATE; - LOG_I(OTG,"[%d][%d][Appli id %d][Agg Level=%d] NEW STATE:: PU-->ED \n", src_instance, dst_instance,application, g_otg->aggregation_level[src_instance][dst_instance][application]); + LOG_I(OTG,"[%d][%d][Appli id %d][Agg Level=%u] NEW STATE:: PU-->ED \n", src_instance, dst_instance,application, g_otg->aggregation_level[src_instance][dst_instance][application]); otg_info->state_transition_prob[src_instance][dst_instance][application]=uniform_dist(0,1); } else { /*if (otg_info->state_transition_prob[src_instance][dst_instance]>=g_otg->prob_pu_ed)*/ //otg_info->state[src_instance][dst_instance]=ON_STATE; otg_info->state[src_instance][dst_instance][application]=PE_STATE; otg_info->start_holding_time_pe_off[src_instance][dst_instance][application]=ctime; - LOG_D(OTG,"[%d][%d][Appli id %d][Agg Level=%d] NEW STATE:: PU-->PE \n", src_instance, dst_instance,application, g_otg->aggregation_level[src_instance][dst_instance][application]); + LOG_D(OTG,"[%d][%d][Appli id %d][Agg Level=%u] NEW STATE:: PU-->PE \n", src_instance, dst_instance,application, g_otg->aggregation_level[src_instance][dst_instance][application]); otg_info->state_transition_prob[src_instance][dst_instance][application]=uniform_dist(0,1); } @@ -2059,20 +2059,20 @@ void state_management( otg_info->state[src_instance][dst_instance][application]=OFF_STATE; otg_info->start_holding_time_off[src_instance][dst_instance][application]=ctime; otg_info->c_holding_time_off[src_instance][dst_instance][application]=0; - LOG_D(OTG,"[%d][%d][Appli id %d][Agg Level=%d] NEW STATE:: ED-->OFF \n", src_instance, dst_instance,application, g_otg->aggregation_level[src_instance][dst_instance][application]); + LOG_D(OTG,"[%d][%d][Appli id %d][Agg Level=%u] NEW STATE:: ED-->OFF \n", src_instance, dst_instance,application, g_otg->aggregation_level[src_instance][dst_instance][application]); otg_info->state_transition_prob[src_instance][dst_instance][application]=uniform_dist(0,1); } else if ((otg_info->state_transition_prob[src_instance][dst_instance][application]>=1-(g_otg->prob_ed_pu[src_instance][dst_instance][application] + g_otg->prob_ed_pe[src_instance][dst_instance][application] )) && (otg_info->state_transition_prob[src_instance][dst_instance][application]<1-g_otg->prob_ed_pe[src_instance][dst_instance][application])) { //otg_info->state[src_instance][dst_instance]=ON_STATE; otg_info->state[src_instance][dst_instance][application]=PE_STATE; - LOG_D(OTG,"[%d][%d][Appli id %d][Agg Level=%d] NEW STATE:: ED-->PU \n", src_instance, dst_instance,application, g_otg->aggregation_level[src_instance][dst_instance][application]); + LOG_D(OTG,"[%d][%d][Appli id %d][Agg Level=%u] NEW STATE:: ED-->PU \n", src_instance, dst_instance,application, g_otg->aggregation_level[src_instance][dst_instance][application]); otg_info->state_transition_prob[src_instance][dst_instance][application]=uniform_dist(0,1); } else { /*if ((otg_info->state_transition_prob[src_instance][dst_instance]>=1-g_otg->prob_ed_pe)&&(otg_info->state_transition_prob[src_instance][dst_instance]<=1)) */ //otg_info->state[src_instance][dst_instance]=ON_STATE; otg_info->state[src_instance][dst_instance][application]=PE_STATE; otg_info->start_holding_time_pe_off[src_instance][dst_instance][application]=ctime; - LOG_D(OTG,"[%d][%d][Appli id %d][Agg Level=%d] NEW STATE:: ED-->PE \n", src_instance, dst_instance,application, g_otg->aggregation_level[src_instance][dst_instance][application]); + LOG_D(OTG,"[%d][%d][Appli id %d][Agg Level=%u] NEW STATE:: ED-->PE \n", src_instance, dst_instance,application, g_otg->aggregation_level[src_instance][dst_instance][application]); otg_info->state_transition_prob[src_instance][dst_instance][application]=uniform_dist(0,1); } @@ -2082,7 +2082,7 @@ void state_management( if (g_otg->holding_time_pe_off[src_instance][dst_instance][application]<=otg_info->c_holding_time_pe_off[src_instance][dst_instance][application]) { //otg_info->state[src_instance][dst_instance]=OFF_STATE; otg_info->state[src_instance][dst_instance][application]=OFF_STATE; - LOG_D(OTG,"[%d][%d][Appli id %d][Agg Level=%d] NEW STATE:: PE->OFF\n", src_instance, dst_instance,application, g_otg->aggregation_level[src_instance][dst_instance][application]); + LOG_D(OTG,"[%d][%d][Appli id %d][Agg Level=%u] NEW STATE:: PE->OFF\n", src_instance, dst_instance,application, g_otg->aggregation_level[src_instance][dst_instance][application]); otg_info->c_holding_time_pe_off[src_instance][dst_instance][application]=0; otg_info->state_transition_prob[src_instance][dst_instance][application]=uniform_dist(0,1); otg_info->start_holding_time_off[src_instance][dst_instance][application]=ctime; @@ -2097,7 +2097,7 @@ void state_management( break; default: - LOG_W(OTG,"Unknown state(%d) \n", otg_info->state[src_instance][dst_instance][application]); + LOG_W(OTG,"Unknown state(%u) \n", otg_info->state[src_instance][dst_instance][application]); otg_info->state[src_instance][dst_instance][application]= OFF_STATE; // switch to default state break; @@ -2145,13 +2145,13 @@ void voip_traffic( if (ctime>otg_info->start_voip_silence[src_instance][dst_instance][application]) otg_info->c_holding_time_silence[src_instance][dst_instance][application]= ctime - otg_info->start_voip_silence[src_instance][dst_instance][application]; - LOG_D(OTG,"[%d][%d][Appli id %d] VOIP STATE:: SILENCE %d (ctime=%d, start=%d)\n", src_instance, dst_instance,application, + LOG_D(OTG,"[%d][%d][Appli id %d] VOIP STATE:: SILENCE %u (ctime=%d, start=%u)\n", src_instance, dst_instance,application, otg_info->c_holding_time_silence[src_instance][dst_instance][application], ctime, otg_info->start_voip_silence[src_instance][dst_instance][application]); } if (otg_info->c_holding_time_silence[src_instance][dst_instance][application]>=otg_info->silence_time[src_instance][dst_instance][application]) { otg_info->voip_state[src_instance][dst_instance][application]=SIMPLE_TALK; - LOG_I(OTG,"[%d][%d][Appli id %d] NEW VOIP STATE :: SILENCE-->TALK %d (ctime=%d, start=%d )\n", src_instance, dst_instance,application , + LOG_I(OTG,"[%d][%d][Appli id %d] NEW VOIP STATE :: SILENCE-->TALK %u (ctime=%d, start=%u )\n", src_instance, dst_instance,application , otg_info->c_holding_time_silence[src_instance][dst_instance][application], ctime, otg_info->start_voip_silence[src_instance][dst_instance][application]); otg_info->start_voip_talk[src_instance][dst_instance][application]=ctime; otg_info->c_holding_time_talk[src_instance][dst_instance][application]=0; @@ -2160,7 +2160,7 @@ void voip_traffic( if (ctime>otg_info->start_voip_silence[src_instance][dst_instance][application]) otg_info->c_holding_time_silence[src_instance][dst_instance][application]= ctime - otg_info->start_voip_silence[src_instance][dst_instance][application]; - LOG_I(OTG,"[%d][%d][Appli id %d] STATE:: SILENCE [timer:%d] \n", src_instance, dst_instance,application, otg_info->c_holding_time_silence[src_instance][dst_instance][application]); + LOG_I(OTG,"[%d][%d][Appli id %d] STATE:: SILENCE [timer:%u] \n", src_instance, dst_instance,application, otg_info->c_holding_time_silence[src_instance][dst_instance][application]); } break; @@ -2168,7 +2168,7 @@ void voip_traffic( case SIMPLE_TALK: if (otg_info->c_holding_time_talk[src_instance][dst_instance][application]>=otg_info->simple_talk_time[src_instance][dst_instance][application]) { otg_info->voip_state[src_instance][dst_instance][application]=SILENCE; - LOG_I(OTG,"[%d][%d][Appli id %d] NEW VOIP STATE:: TALK-->SILENCE %d (ctime=%d, start=%d )\n", src_instance, dst_instance,application , + LOG_I(OTG,"[%d][%d][Appli id %d] NEW VOIP STATE:: TALK-->SILENCE %u (ctime=%d, start=%u )\n", src_instance, dst_instance,application , otg_info->c_holding_time_talk[src_instance][dst_instance][application], ctime, otg_info->start_voip_talk[src_instance][dst_instance][application]); otg_info->start_voip_silence[src_instance][dst_instance][application]=ctime; otg_info->c_holding_time_silence[src_instance][dst_instance][application]=0; @@ -2177,15 +2177,15 @@ void voip_traffic( if (ctime>otg_info->start_voip_talk[src_instance][dst_instance][application]) otg_info->c_holding_time_talk[src_instance][dst_instance][application]= ctime - otg_info->start_voip_talk[src_instance][dst_instance][application]; - LOG_I(OTG,"[%d][%d][Appli id %d] VOIP STATE:: TALK [timer:%d]\n", src_instance, dst_instance,application, otg_info->c_holding_time_talk[src_instance][dst_instance][application]); - LOG_I(OTG, "test_talk [ctime %d] [start talk %d] [%d] \n",ctime, otg_info->start_voip_talk[src_instance][dst_instance][application], + LOG_I(OTG,"[%d][%d][Appli id %d] VOIP STATE:: TALK [timer:%u]\n", src_instance, dst_instance,application, otg_info->c_holding_time_talk[src_instance][dst_instance][application]); + LOG_I(OTG, "test_talk [ctime %d] [start talk %u] [%u] \n",ctime, otg_info->start_voip_talk[src_instance][dst_instance][application], otg_info->c_holding_time_talk[src_instance][dst_instance][application] ); } break; default: - LOG_W(OTG,"Unknown VOIP state(%d) \n", otg_info->voip_state[src_instance][dst_instance][application]); + LOG_W(OTG,"Unknown VOIP state(%u) \n", otg_info->voip_state[src_instance][dst_instance][application]); otg_info->voip_state[src_instance][dst_instance][application]= SILENCE; // switch to default state break; diff --git a/openair2/UTIL/OTG/otg_tx_socket.c b/openair2/UTIL/OTG/otg_tx_socket.c index 026dc3e8b836344ea81099aa7b59a4df829acf3b..83b8476e9f7baeddca6a57e0ead3c8e8e27ff906 100644 --- a/openair2/UTIL/OTG/otg_tx_socket.c +++ b/openair2/UTIL/OTG/otg_tx_socket.c @@ -36,28 +36,28 @@ #ifdef WIN32 /* si vous êtes sous Windows */ -#include <winsock2.h> + #include <winsock2.h> #elif defined (linux) /* si vous êtes sous Linux */ -#include <sys/types.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <arpa/inet.h> -#include <unistd.h> /* close */ -#include <netdb.h> /* gethostbyname */ -#include <errno.h> - -#define INVALID_SOCKET -1 -#define SOCKET_ERROR -1 -#define closesocket(s) close(s) -typedef int SOCKET; -typedef struct sockaddr_in SOCKADDR_IN; -typedef struct sockaddr SOCKADDR; -typedef struct in_addr IN_ADDR; + #include <sys/types.h> + #include <sys/socket.h> + #include <netinet/in.h> + #include <arpa/inet.h> + #include <unistd.h> /* close */ + #include <netdb.h> /* gethostbyname */ + #include <errno.h> + + #define INVALID_SOCKET -1 + #define SOCKET_ERROR -1 + #define closesocket(s) close(s) + typedef int SOCKET; + typedef struct sockaddr_in SOCKADDR_IN; + typedef struct sockaddr SOCKADDR; + typedef struct in_addr IN_ADDR; #else /* sinon vous êtes sur une plateforme non supportée */ -#error not defined for this platform + #error not defined for this platform #endif @@ -67,11 +67,8 @@ control_hdr_t *control_hdr; -void socket_packet_send(int src, int dst, int state,int ctime) -{ - +void socket_packet_send(int src, int dst, int state,int ctime) { init_control_header(); - LOG_I(OTG,"SOCKET:: IP version %d, Transport Protocol %d \n", g_otg->ip_v[src], g_otg->trans_proto[src]); if ((g_otg->ip_v[src]==1) && (g_otg->trans_proto[src]==2)) @@ -85,29 +82,20 @@ void socket_packet_send(int src, int dst, int state,int ctime) if ((g_otg->ip_v[src]==2) && (g_otg->trans_proto[src]==1)) client_socket_udp_ip6(src, dst, state, ctime); - - - } -void client_socket_tcp_ip4(int src, int dst, int state, int ctime) -{ - +void client_socket_tcp_ip4(int src, int dst, int state, int ctime) { #define PORT 7777 - - LOG_I(OTG,"SOCKET:: TCP-IP4 :: src= %d , dst= %d , state= %d \n", src, dst, state); - #if defined (WIN32) WSADATA WSAData; int erreur = WSAStartup(MAKEWORD(2,2), &WSAData); #else int erreur = 0; #endif - SOCKET sock; SOCKADDR_IN sin; int sock_err; @@ -118,94 +106,69 @@ void client_socket_tcp_ip4(int src, int dst, int state, int ctime) if(!erreur) { /* Create socket */ sock = socket(AF_INET, SOCK_STREAM, 0); - /* Configure the connection */ sin.sin_addr.s_addr = inet_addr(g_otg->dst_ip[src]); sin.sin_family = AF_INET; sin.sin_port = htons(PORT); - /* connection is ok */ - printf("SOCKET:: TCP-IP4 :: \n"); - if(connect(sock, (SOCKADDR*)&sin, sizeof(sin)) != SOCKET_ERROR) { + if(connect(sock, (SOCKADDR *)&sin, sizeof(sin)) != SOCKET_ERROR) { LOG_I(OTG,"SOCKET:: TCP-IP4 :: Create socket %s with dst port %d\n", inet_ntoa(sin.sin_addr), htons(sin.sin_port)); ctime=0; LOG_I(OTG,"SOCKET:: TCP-IP4 :: ctime=%d, duration=%d \n", ctime, g_otg->duration[src]); - init_control_header(); - do { //payload=NULL; //payload=packet_gen_socket(src, dst, state, ctime); //payload="CCCCC"; - char *payload_rest; payload_rest=packet_gen_socket(src, dst, state, ctime); if (payload_rest!=NULL) { - - - payload_t *payload; payload= malloc(sizeof(payload_t)); // Data serialization char *tx_buffer; tx_buffer= (char *)malloc(PAYLOAD_MAX); - payload->control_hdr=otg_info_hdr_gen(src, dst, TCP, IPV4); - payload->payload_rest=payload_rest; memcpy(tx_buffer, payload->control_hdr, sizeof (control_hdr_t)); memcpy(tx_buffer+ sizeof (control_hdr_t), payload->payload_rest, strlen(payload_rest)); - - int total_size=sizeof(control_hdr_t) + strlen(payload_rest); - if((sock_err = send(sock, tx_buffer, total_size, 0)) != SOCKET_ERROR) LOG_I(OTG,"SOCKET:: TCP-IP4 :: Payload to send size :: %d \n",sock_err); else LOG_I(OTG,"SOCKET:: TCP-IP4 :: Transmission Error\n"); - + free(payload); + free(tx_buffer); } ctime+=1; - - } while (ctime<=g_otg->duration[src]) ; - - } /* connection is not possible..." */ else LOG_I(OTG,"SOCKET:: TCP-IP4 :: connection is not possible to connect \n"); - /* close the socket */ closesocket(sock); - } } -void client_socket_udp_ip4(int src, int dst, int state,int ctime) -{ - +void client_socket_udp_ip4(int src, int dst, int state,int ctime) { char *payload_rest; signed int udp_send; - - - int sockfd, ok, addr_in_size; u_short portnum = 12345; struct sockaddr_in *to; struct hostent *toinfo; char *htoname = "127.0.0.1"; u_long toaddr; - LOG_I(OTG,"SOCKET:: UDP-IP4 :: src= %d , dst= %d , state= %d \n", src, dst, state); to = (struct sockaddr_in *)malloc(sizeof(struct sockaddr_in)); @@ -226,7 +189,6 @@ void client_socket_udp_ip4(int src, int dst, int state,int ctime) to->sin_port = portnum; - // /* @@ -238,8 +200,6 @@ void client_socket_udp_ip4(int src, int dst, int state,int ctime) memset(control_hdr, 0, sizeof(control_hdr_t)); */ // - - if((sockfd = socket (PF_INET, SOCK_DGRAM, 0)) == -1) { LOG_W(OTG,"SOCKET:: UDP-IP4 :: Error %d in socket: %s\n",errno,sys_errlist[errno]); exit(errno); @@ -249,21 +209,20 @@ void client_socket_udp_ip4(int src, int dst, int state,int ctime) payload_rest=packet_gen_socket(src, dst, state, ctime); if (payload_rest!=NULL) { - payload_t *payload; payload= malloc(sizeof(payload_t)); // Data serialization char *tx_buffer; tx_buffer= (char *)malloc(PAYLOAD_MAX); - - + if (tx_buffer == NULL || payload == NULL) { + LOG_E(OTG,"Memory allocation failed\n"); + return; + } payload->control_hdr=otg_info_hdr_gen(src, dst, UDP, IPV4); payload->payload_rest=payload_rest; memcpy(tx_buffer, payload->control_hdr, sizeof (control_hdr_t)); memcpy(tx_buffer+ sizeof (control_hdr_t), payload->payload_rest, strlen(payload_rest)); int total_size=sizeof(control_hdr_t) + strlen(payload_rest); - - udp_send=sendto(sockfd, tx_buffer,total_size ,0,(struct sockaddr *)to,addr_in_size); LOG_I(OTG,"SOCKET:: UDP-IP4 :: Payload to send :: data sent:%d \n", udp_send); // Update TX OTG info @@ -271,69 +230,42 @@ void client_socket_udp_ip4(int src, int dst, int state,int ctime) //otg_info->rx_num_bytes[src][dst]+= udp_send + (HDR_IP_v4 + HDR_UDP); // - if (NULL != payload) { - payload=NULL; - free(payload); - } - - if (NULL != tx_buffer) { - tx_buffer=NULL; - free(tx_buffer); - } - - - + free(payload); + free(tx_buffer); } if(udp_send == -1) { LOG_I(OTG,"SOCKET:: UDP-IP4 :: Transmission Error\n"); exit(errno); - } - - else + } else LOG_I(OTG,"SOCKET:: UDP-IP4 :: No data to transmit\n"); ctime+=1; - - } while (ctime<=g_otg->duration[src]) ; closesocket(sockfd); - } -void client_socket_tcp_ip6(int src, int dst, int state,int ctime) -{ +void client_socket_tcp_ip6(int src, int dst, int state,int ctime) { printf("client TCP IPv6\n"); - } -void client_socket_udp_ip6(int src, int dst, int state,int ctime) -{ +void client_socket_udp_ip6(int src, int dst, int state,int ctime) { printf("client UDP IPv6\n"); - } -char* packet_gen_socket(int src, int dst, int state, int ctime) -{ - +char *packet_gen_socket(int src, int dst, int state, int ctime) { int size; char *payload=NULL; - - set_ctime(ctime); LOG_I(OTG,"SOCKET :: num_nodes_tx:: %d , seed:: %d \n", g_otg->num_nodes, g_otg->seed); - LOG_I(OTG,"SOCKET :: NODE_INFO (Source= %d, Destination= %d,State= %d) ctime %d \n", src, dst, state, otg_info->ctime); - - LOG_I(OTG,"SOCKET :: INFO_SIM (src=%d, dst=%d, state=%d) application=%d, idt dist =%d, pkts dist= %d\n", src, dst, state, g_otg->application_type[src][dst], g_otg->idt_dist[src][dst][state], g_otg->size_dist[src][dst][state]); - LOG_I(OTG,"SOCKET :: Transmission info: idt=%d, simulation time=%d \n", otg_info->idt[src][dst], ctime); // do not generate packet for this pair of src, dst : no app type and/or idt are defined @@ -352,7 +284,6 @@ char* packet_gen_socket(int src, int dst, int state, int ctime) //end pre-config if ((otg_info->idt[src][dst]==(ctime-otg_info->ptime[src][dst][state])) || (otg_info->idt[src][dst]==0)) { - LOG_I(OTG,"SOCKET :: Time To Transmit (Source= %d, Destination= %d,State= %d) , (IDT= %d ,simu time= %d, previous packet time= %d) \n", src, dst, state ,otg_info->idt[src][dst], ctime, otg_info->ptime[src][dst][state]); otg_info->ptime[src][dst][state]=ctime; @@ -362,8 +293,6 @@ char* packet_gen_socket(int src, int dst, int state, int ctime) return 0; // do not generate the packet, and keep the idt } - - size=size_dist(src, dst, state); LOG_I(OTG,"SOCKET :: Generate Packet for (Source= %d, Destination= %d,State= %d) , pkt size dist= %d, simu time= %d ,packet size=%d \n", src, dst, state, g_otg->size_dist[src][dst][state], otg_info->ctime, size); @@ -374,15 +303,12 @@ char* packet_gen_socket(int src, int dst, int state, int ctime) size=(5* sizeof(int))+10; payload=payload_pkts(size); - return(payload); - } -control_hdr_t *otg_info_hdr_gen(int src, int dst, int trans_proto, int ip_v) -{ +control_hdr_t *otg_info_hdr_gen(int src, int dst, int trans_proto, int ip_v) { control_hdr->src=src; control_hdr->dst=dst; control_hdr->trans_proto=trans_proto; @@ -391,15 +317,11 @@ control_hdr_t *otg_info_hdr_gen(int src, int dst, int trans_proto, int ip_v) LOG_I(OTG,"SOCKET :: control header src %d\n",control_hdr->dst); LOG_I(OTG,"SOCKET :: control header src %d\n",control_hdr->trans_proto); LOG_I(OTG,"SOCKET :: control header src %d\n",control_hdr->ip_v); - - return control_hdr; - } -void init_control_header() -{ +void init_control_header() { //set otg header to 0 control_hdr = calloc(1, sizeof(control_hdr_t)); diff --git a/openair2/X2AP/x2ap_eNB.c b/openair2/X2AP/x2ap_eNB.c index 13f6989f1cbe9749f3c5b727e3f20ecb4acc0409..db29f32d7ba839fb8f5d98627b815feb902c9a8e 100644 --- a/openair2/X2AP/x2ap_eNB.c +++ b/openair2/X2AP/x2ap_eNB.c @@ -19,6 +19,13 @@ * contact@openairinterface.org */ +/*! \file x2ap_eNB.c + * \brief x2ap tasks for eNB + * \author Konstantinos Alexandris <Konstantinos.Alexandris@eurecom.fr>, Cedric Roux <Cedric.Roux@eurecom.fr>, Navid Nikaein <Navid.Nikaein@eurecom.fr> + * \date 2018 + * \version 1.0 + */ + #include <pthread.h> #include <stdio.h> #include <stdlib.h> @@ -64,6 +71,13 @@ void x2ap_eNB_register_eNB(x2ap_eNB_instance_t *instance_p, uint32_t enb_port_for_X2C, int multi_sd); +static +void x2ap_eNB_handle_handover_req(instance_t instance, + x2ap_handover_req_t *x2ap_handover_req); + +static +void x2ap_eNB_handle_handover_req_ack(instance_t instance, + x2ap_handover_req_ack_t *x2ap_handover_req_ack); static void x2ap_eNB_handle_sctp_data_ind(instance_t instance, sctp_data_ind_t *sctp_data_ind) { @@ -353,6 +367,62 @@ void x2ap_eNB_handle_sctp_init_msg_multi_cnf( } } +static +void x2ap_eNB_handle_handover_req(instance_t instance, + x2ap_handover_req_t *x2ap_handover_req) +{ + /* TODO: remove this hack (the goal is to find the correct + * eNodeB structure for the target) - we need a proper way for RRC + * and X2AP to identify eNodeBs + * RRC knows about mod_id and X2AP knows about eNB_id (eNB_ID in + * the configuration file) + * as far as I understand.. CROUX + */ + x2ap_eNB_instance_t *instance_p; + x2ap_eNB_data_t *target; + + int target_enb_id = x2ap_handover_req->target_physCellId; + + instance_p = x2ap_eNB_pci_get_instance(target_enb_id); + DevAssert(instance_p != NULL); + + //instance_p = x2ap_eNB_get_instance(instance); + //DevAssert(instance_p != NULL); + + target = x2ap_is_eNB_id_in_list(instance_p->eNB_id); + DevAssert(target != NULL); + + /* store rnti at index 0 */ + //x2id_to_source_rnti[0] = x2ap_handover_req->source_rnti; + x2ap_eNB_generate_x2_handover_request(target, x2ap_handover_req); +} + +static +void x2ap_eNB_handle_handover_req_ack(instance_t instance, + x2ap_handover_req_ack_t *x2ap_handover_req_ack) +{ + /* TODO: remove this hack (the goal is to find the correct + * eNodeB structure for the other end) - we need a proper way for RRC + * and X2AP to identify eNodeBs + * RRC knows about mod_id and X2AP knows about eNB_id (eNB_ID in + * the configuration file) + * as far as I understand.. CROUX + */ + x2ap_eNB_instance_t *instance_p; + x2ap_eNB_data_t *target; + int target_enb_id = x2ap_handover_req_ack->target_mod_id; + + instance_p = x2ap_eNB_get_instance(instance); + DevAssert(instance_p != NULL); + + target = x2ap_is_eNB_id_in_list(target_enb_id); + DevAssert(target != NULL); + + x2ap_eNB_generate_x2_handover_request_ack(target, x2ap_handover_req_ack); + //x2ap_eNB_generate_x2_handover_req_ack(instance_p, target, x2ap_handover_req_ack->source_x2id, + //x2ap_handover_req_ack->rrc_buffer, x2ap_handover_req_ack->rrc_buffer_size); +} + void *x2ap_task(void *arg) { MessageDef *received_msg = NULL; int result; @@ -374,6 +444,16 @@ void *x2ap_task(void *arg) { &X2AP_REGISTER_ENB_REQ(received_msg)); break; + case X2AP_HANDOVER_REQ: + x2ap_eNB_handle_handover_req(ITTI_MESSAGE_GET_INSTANCE(received_msg), + &X2AP_HANDOVER_REQ(received_msg)); + break; + + case X2AP_HANDOVER_REQ_ACK: + x2ap_eNB_handle_handover_req_ack(ITTI_MESSAGE_GET_INSTANCE(received_msg), + &X2AP_HANDOVER_REQ_ACK(received_msg)); + break; + case SCTP_INIT_MSG_MULTI_CNF: x2ap_eNB_handle_sctp_init_msg_multi_cnf(ITTI_MESSAGE_GET_INSTANCE(received_msg), &received_msg->ittiMsg.sctp_init_msg_multi_cnf); diff --git a/openair2/X2AP/x2ap_eNB.h b/openair2/X2AP/x2ap_eNB.h index 1a19416122d0918fa20896b6f580c858758db90e..5433a890883c94d750594fd4a99e848ef449c343 100644 --- a/openair2/X2AP/x2ap_eNB.h +++ b/openair2/X2AP/x2ap_eNB.h @@ -19,6 +19,13 @@ * contact@openairinterface.org */ +/*! \file x2ap_eNB.h + * \brief x2ap tasks for eNB + * \author Konstantinos Alexandris <Konstantinos.Alexandris@eurecom.fr>, Cedric Roux <Cedric.Roux@eurecom.fr>, Navid Nikaein <Navid.Nikaein@eurecom.fr> + * \date 2018 + * \version 1.0 + */ + #include <stdio.h> #include <stdint.h> diff --git a/openair2/X2AP/x2ap_eNB_decoder.c b/openair2/X2AP/x2ap_eNB_decoder.c index f156d96d175beab05523d01625cd34324bc1e1a5..553cf8e559c1d38b3969e33a2e21384c6401a326 100644 --- a/openair2/X2AP/x2ap_eNB_decoder.c +++ b/openair2/X2AP/x2ap_eNB_decoder.c @@ -19,6 +19,13 @@ * contact@openairinterface.org */ +/*! \file x2ap_eNB_decoder.c + * \brief x2ap decoder procedures for eNB + * \author Konstantinos Alexandris <Konstantinos.Alexandris@eurecom.fr>, Cedric Roux <Cedric.Roux@eurecom.fr>, Navid Nikaein <Navid.Nikaein@eurecom.fr> + * \date 2018 + * \version 1.0 + */ + #include <stdio.h> #include "assertions.h" @@ -33,7 +40,12 @@ static int x2ap_eNB_decode_initiating_message(X2AP_X2AP_PDU_t *pdu) switch(pdu->choice.initiatingMessage.procedureCode) { case X2AP_ProcedureCode_id_x2Setup: - asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_X2AP_X2AP_PDU, pdu); + //asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_X2AP_X2AP_PDU, pdu); + X2AP_INFO("x2ap_eNB_decode_initiating_message!\n"); + break; + + case X2AP_ProcedureCode_id_handoverPreparation: + //asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_X2AP_X2AP_PDU, pdu); X2AP_INFO("x2ap_eNB_decode_initiating_message!\n"); break; @@ -54,7 +66,12 @@ static int x2ap_eNB_decode_successful_outcome(X2AP_X2AP_PDU_t *pdu) switch(pdu->choice.successfulOutcome.procedureCode) { case X2AP_ProcedureCode_id_x2Setup: - asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_X2AP_X2AP_PDU, pdu); + //asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_X2AP_X2AP_PDU, pdu); + X2AP_INFO("x2ap_eNB_decode_successfuloutcome_message!\n"); + break; + + case X2AP_ProcedureCode_id_handoverPreparation: + //asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_X2AP_X2AP_PDU, pdu); X2AP_INFO("x2ap_eNB_decode_successfuloutcome_message!\n"); break; @@ -73,7 +90,7 @@ static int x2ap_eNB_decode_unsuccessful_outcome(X2AP_X2AP_PDU_t *pdu) switch(pdu->choice.unsuccessfulOutcome.procedureCode) { case X2AP_ProcedureCode_id_x2Setup: - asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_X2AP_X2AP_PDU, pdu); + //asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_X2AP_X2AP_PDU, pdu); X2AP_INFO("x2ap_eNB_decode_unsuccessfuloutcome_message!\n"); break; @@ -99,8 +116,9 @@ int x2ap_eNB_decode_pdu(X2AP_X2AP_PDU_t *pdu, const uint8_t *const buffer, uint3 length, 0, 0); - - xer_fprint(stdout, &asn_DEF_X2AP_X2AP_PDU, pdu); + if (asn1_xer_print) { + xer_fprint(stdout, &asn_DEF_X2AP_X2AP_PDU, pdu); + } if (dec_ret.code != RC_OK) { X2AP_ERROR("Failed to decode pdu\n"); diff --git a/openair2/X2AP/x2ap_eNB_decoder.h b/openair2/X2AP/x2ap_eNB_decoder.h index 9ce9ea3d40ef039a9c36c45163bdeb2969b0b9fb..7919c785554aef8eeaa5c156225c9cdac5d155b4 100644 --- a/openair2/X2AP/x2ap_eNB_decoder.h +++ b/openair2/X2AP/x2ap_eNB_decoder.h @@ -19,6 +19,13 @@ * contact@openairinterface.org */ +/*! \file x2ap_eNB_decoder.h + * \brief x2ap decoder procedures for eNB + * \author Konstantinos Alexandris <Konstantinos.Alexandris@eurecom.fr>, Cedric Roux <Cedric.Roux@eurecom.fr>, Navid Nikaein <Navid.Nikaein@eurecom.fr> + * \date 2018 + * \version 1.0 + */ + #ifndef X2AP_ENB_DECODER_H_ #define X2AP_ENB_DECODER_H_ diff --git a/openair2/X2AP/x2ap_eNB_defs.h b/openair2/X2AP/x2ap_eNB_defs.h index 3014290206913e516b046bfc5dbab94fa64397b1..a5558c42a5307d7f55c64be8eca6cf788e37b3c8 100644 --- a/openair2/X2AP/x2ap_eNB_defs.h +++ b/openair2/X2AP/x2ap_eNB_defs.h @@ -19,6 +19,13 @@ * contact@openairinterface.org */ +/*! \file x2ap_eNB_defs.h + * \brief x2ap struct definitions for eNB + * \author Konstantinos Alexandris <Konstantinos.Alexandris@eurecom.fr>, Cedric Roux <Cedric.Roux@eurecom.fr>, Navid Nikaein <Navid.Nikaein@eurecom.fr> + * \date 2018 + * \version 1.0 + */ + #include <stdint.h> #include "queue.h" @@ -156,6 +163,7 @@ typedef struct x2ap_eNB_instance_s { uint32_t downlink_frequency[MAX_NUM_CCs]; int32_t uplink_frequency_offset[MAX_NUM_CCs]; uint32_t Nid_cell[MAX_NUM_CCs]; + uint32_t Nid_target_cell[MAX_NUM_CCs]; int16_t N_RB_DL[MAX_NUM_CCs]; lte_frame_type_t frame_type[MAX_NUM_CCs]; uint32_t fdd_earfcn_DL[MAX_NUM_CCs]; diff --git a/openair2/X2AP/x2ap_eNB_encoder.c b/openair2/X2AP/x2ap_eNB_encoder.c index 1eb617a7f1ddec817a88648fe25ddbef2ac9ad7c..8b1c030d35d0b14d588475cf317d450f2fa3e686 100644 --- a/openair2/X2AP/x2ap_eNB_encoder.c +++ b/openair2/X2AP/x2ap_eNB_encoder.c @@ -19,6 +19,13 @@ * contact@openairinterface.org */ +/*! \file x2ap_eNB_encoder.c + * \brief x2ap encoder procedures for eNB + * \author Konstantinos Alexandris <Konstantinos.Alexandris@eurecom.fr>, Cedric Roux <Cedric.Roux@eurecom.fr>, Navid Nikaein <Navid.Nikaein@eurecom.fr> + * \date 2018 + * \version 1.0 + */ + #include <stdio.h> #include <string.h> #include <stdint.h> diff --git a/openair2/X2AP/x2ap_eNB_encoder.h b/openair2/X2AP/x2ap_eNB_encoder.h index 04c77583b4f27c05fcc723100784bf418bf26c3a..f451a3fb2626e6119b7a0158d4f4394a8f0cb9d1 100644 --- a/openair2/X2AP/x2ap_eNB_encoder.h +++ b/openair2/X2AP/x2ap_eNB_encoder.h @@ -19,6 +19,13 @@ * contact@openairinterface.org */ +/*! \file x2ap_eNB_encoder.h + * \brief x2ap encoder procedures for eNB + * \author Konstantinos Alexandris <Konstantinos.Alexandris@eurecom.fr>, Cedric Roux <Cedric.Roux@eurecom.fr>, Navid Nikaein <Navid.Nikaein@eurecom.fr> + * \date 2018 + * \version 1.0 + */ + #ifndef X2AP_ENB_ENCODER_H_ #define X2AP_ENB_ENCODER_H_ diff --git a/openair2/X2AP/x2ap_eNB_generate_messages.c b/openair2/X2AP/x2ap_eNB_generate_messages.c index 9c5a281506730409d8cf9b7048e4d68b90e826a7..b9a2dae04ce18069c79dbad880ba19fe1f2ffaf1 100644 --- a/openair2/X2AP/x2ap_eNB_generate_messages.c +++ b/openair2/X2AP/x2ap_eNB_generate_messages.c @@ -19,12 +19,22 @@ * contact@openairinterface.org */ +/*! \file x2ap_eNB_generate_messages.c + * \brief x2ap procedures for eNB + * \author Konstantinos Alexandris <Konstantinos.Alexandris@eurecom.fr>, Cedric Roux <Cedric.Roux@eurecom.fr>, Navid Nikaein <Navid.Nikaein@eurecom.fr> + * \date 2018 + * \version 1.0 + */ + #include "intertask_interface.h" +#include "X2AP_LastVisitedCell-Item.h" + #include "x2ap_common.h" #include "x2ap_eNB.h" #include "x2ap_eNB_generate_messages.h" #include "x2ap_eNB_encoder.h" +#include "x2ap_eNB_decoder.h" #include "x2ap_eNB_itti_messaging.h" @@ -403,3 +413,314 @@ int x2ap_eNB_set_cause (X2AP_Cause_t * cause_p, return 0; } + +int x2ap_eNB_generate_x2_handover_request (x2ap_eNB_data_t *x2ap_eNB_data_p, + x2ap_handover_req_t *x2ap_handover_req) +{ + + X2AP_X2AP_PDU_t pdu; + X2AP_HandoverRequest_t *out; + X2AP_HandoverRequest_IEs_t *ie; + X2AP_E_RABs_ToBeSetup_ItemIEs_t *e_RABS_ToBeSetup_ItemIEs; + X2AP_E_RABs_ToBeSetup_Item_t *e_RABs_ToBeSetup_Item; + X2AP_LastVisitedCell_Item_t *lastVisitedCell_Item; + + x2ap_eNB_instance_t *instance_p; + + uint8_t *buffer; + uint32_t len; + int ret = 0; + + DevAssert(x2ap_eNB_data_p != NULL); + + /* get the eNB instance */ + instance_p = x2ap_eNB_data_p->x2ap_eNB_instance; + + DevAssert(instance_p != NULL); + + + /* Prepare the X2AP handover message to encode */ + memset(&pdu, 0, sizeof(pdu)); + pdu.present = X2AP_X2AP_PDU_PR_initiatingMessage; + pdu.choice.initiatingMessage.procedureCode = X2AP_ProcedureCode_id_handoverPreparation; + pdu.choice.initiatingMessage.criticality = X2AP_Criticality_reject; + pdu.choice.initiatingMessage.value.present = X2AP_InitiatingMessage__value_PR_HandoverRequest; + out = &pdu.choice.initiatingMessage.value.choice.HandoverRequest; + + /* mandatory */ + ie = (X2AP_HandoverRequest_IEs_t *)calloc(1, sizeof(X2AP_HandoverRequest_IEs_t)); + ie->id = X2AP_ProtocolIE_ID_id_Old_eNB_UE_X2AP_ID; + ie->criticality = X2AP_Criticality_reject; + ie->value.present = X2AP_HandoverRequest_IEs__value_PR_UE_X2AP_ID; + ie->value.choice.UE_X2AP_ID = x2ap_handover_req->old_eNB_ue_x2ap_id; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + + /* mandatory */ + ie = (X2AP_HandoverRequest_IEs_t *)calloc(1, sizeof(X2AP_HandoverRequest_IEs_t)); + ie->id = X2AP_ProtocolIE_ID_id_Cause; + ie->criticality = X2AP_Criticality_ignore; + ie->value.present = X2AP_HandoverRequest_IEs__value_PR_Cause; + ie->value.choice.Cause.present = X2AP_Cause_PR_radioNetwork; + ie->value.choice.Cause.choice.radioNetwork = X2AP_CauseRadioNetwork_handover_desirable_for_radio_reasons; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + + /* mandatory */ + ie = (X2AP_HandoverRequest_IEs_t *)calloc(1, sizeof(X2AP_HandoverRequest_IEs_t)); + ie->id = X2AP_ProtocolIE_ID_id_TargetCell_ID; + ie->criticality = X2AP_Criticality_reject; + ie->value.present = X2AP_HandoverRequest_IEs__value_PR_ECGI; + MCC_MNC_TO_PLMNID(instance_p->mcc, instance_p->mnc, instance_p->mnc_digit_length, + &ie->value.choice.ECGI.pLMN_Identity); + MACRO_ENB_ID_TO_CELL_IDENTITY(instance_p->eNB_id, 0, &ie->value.choice.ECGI.eUTRANcellIdentifier); + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + + /* mandatory */ + ie = (X2AP_HandoverRequest_IEs_t *)calloc(1, sizeof(X2AP_HandoverRequest_IEs_t)); + ie->id = X2AP_ProtocolIE_ID_id_GUMMEI_ID; + ie->criticality = X2AP_Criticality_reject; + ie->value.present = X2AP_HandoverRequest_IEs__value_PR_GUMMEI; + MCC_MNC_TO_PLMNID(instance_p->mcc, instance_p->mnc, instance_p->mnc_digit_length, + &ie->value.choice.GUMMEI.gU_Group_ID.pLMN_Identity); + //@TODO: consider to update these values + INT16_TO_OCTET_STRING(x2ap_handover_req->ue_gummei.mme_group_id, &ie->value.choice.GUMMEI.gU_Group_ID.mME_Group_ID); + MME_CODE_TO_OCTET_STRING(x2ap_handover_req->ue_gummei.mme_code, &ie->value.choice.GUMMEI.mME_Code); + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + + /* mandatory */ + ie = (X2AP_HandoverRequest_IEs_t *)calloc(1, sizeof(X2AP_HandoverRequest_IEs_t)); + ie->id = X2AP_ProtocolIE_ID_id_UE_ContextInformation; + ie->criticality = X2AP_Criticality_reject; + ie->value.present = X2AP_HandoverRequest_IEs__value_PR_UE_ContextInformation; + //@TODO: consider to update this value + ie->value.choice.UE_ContextInformation.mME_UE_S1AP_ID = x2ap_handover_req->mme_ue_s1ap_id; + + KENB_STAR_TO_BIT_STRING(x2ap_handover_req->kenb,&ie->value.choice.UE_ContextInformation.aS_SecurityInformation.key_eNodeB_star); + + if (x2ap_handover_req->kenb_ncc >=0) { // Check this condition + ie->value.choice.UE_ContextInformation.aS_SecurityInformation.nextHopChainingCount = x2ap_handover_req->kenb_ncc; + } + else { + ie->value.choice.UE_ContextInformation.aS_SecurityInformation.nextHopChainingCount = 1; + } + + ENCRALG_TO_BIT_STRING(x2ap_handover_req->security_capabilities.encryption_algorithms, + &ie->value.choice.UE_ContextInformation.uESecurityCapabilities.encryptionAlgorithms); + + INTPROTALG_TO_BIT_STRING(x2ap_handover_req->security_capabilities.integrity_algorithms, + &ie->value.choice.UE_ContextInformation.uESecurityCapabilities.integrityProtectionAlgorithms); + + //@TODO: update with proper UEAMPR + UEAGMAXBITRTD_TO_ASN_PRIMITIVES(3L,&ie->value.choice.UE_ContextInformation.uEaggregateMaximumBitRate.uEaggregateMaximumBitRateDownlink); + UEAGMAXBITRTU_TO_ASN_PRIMITIVES(6L,&ie->value.choice.UE_ContextInformation.uEaggregateMaximumBitRate.uEaggregateMaximumBitRateUplink); + { + for (int i=0;i<x2ap_handover_req->nb_e_rabs_tobesetup;i++) { + e_RABS_ToBeSetup_ItemIEs = (X2AP_E_RABs_ToBeSetup_ItemIEs_t *)calloc(1,sizeof(X2AP_E_RABs_ToBeSetup_ItemIEs_t)); + e_RABS_ToBeSetup_ItemIEs->id = X2AP_ProtocolIE_ID_id_E_RABs_ToBeSetup_Item; + e_RABS_ToBeSetup_ItemIEs->criticality = X2AP_Criticality_ignore; + e_RABS_ToBeSetup_ItemIEs->value.present = X2AP_E_RABs_ToBeSetup_ItemIEs__value_PR_E_RABs_ToBeSetup_Item; + e_RABs_ToBeSetup_Item = &e_RABS_ToBeSetup_ItemIEs->value.choice.E_RABs_ToBeSetup_Item; + { + e_RABs_ToBeSetup_Item->e_RAB_ID = x2ap_handover_req->e_rabs_tobesetup[i].e_rab_id; + e_RABs_ToBeSetup_Item->e_RAB_Level_QoS_Parameters.qCI = x2ap_handover_req->e_rab_param[i].qos.qci; + e_RABs_ToBeSetup_Item->e_RAB_Level_QoS_Parameters.allocationAndRetentionPriority.priorityLevel = x2ap_handover_req->e_rab_param[i].qos.allocation_retention_priority.priority_level; + e_RABs_ToBeSetup_Item->e_RAB_Level_QoS_Parameters.allocationAndRetentionPriority.pre_emptionCapability = x2ap_handover_req->e_rab_param[i].qos.allocation_retention_priority.pre_emp_capability; + e_RABs_ToBeSetup_Item->e_RAB_Level_QoS_Parameters.allocationAndRetentionPriority.pre_emptionVulnerability = x2ap_handover_req->e_rab_param[i].qos.allocation_retention_priority.pre_emp_vulnerability; + e_RABs_ToBeSetup_Item->uL_GTPtunnelEndpoint.transportLayerAddress.size = (uint8_t)(x2ap_handover_req->e_rabs_tobesetup[i].eNB_addr.length/8); + e_RABs_ToBeSetup_Item->uL_GTPtunnelEndpoint.transportLayerAddress.bits_unused = x2ap_handover_req->e_rabs_tobesetup[i].eNB_addr.length%8; + e_RABs_ToBeSetup_Item->uL_GTPtunnelEndpoint.transportLayerAddress.buf = + calloc(1,e_RABs_ToBeSetup_Item->uL_GTPtunnelEndpoint.transportLayerAddress.size); + + memcpy (e_RABs_ToBeSetup_Item->uL_GTPtunnelEndpoint.transportLayerAddress.buf, + x2ap_handover_req->e_rabs_tobesetup[i].eNB_addr.buffer, + e_RABs_ToBeSetup_Item->uL_GTPtunnelEndpoint.transportLayerAddress.size); + + INT32_TO_OCTET_STRING(x2ap_handover_req->e_rabs_tobesetup[i].gtp_teid,&e_RABs_ToBeSetup_Item->uL_GTPtunnelEndpoint.gTP_TEID); + } + ASN_SEQUENCE_ADD(&ie->value.choice.UE_ContextInformation.e_RABs_ToBeSetup_List.list, e_RABS_ToBeSetup_ItemIEs); + } + } + + OCTET_STRING_fromBuf(&ie->value.choice.UE_ContextInformation.rRC_Context, (char*) x2ap_handover_req->rrc_buffer, x2ap_handover_req->rrc_buffer_size); + + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + + /* mandatory */ + ie = (X2AP_HandoverRequest_IEs_t *)calloc(1, sizeof(X2AP_HandoverRequest_IEs_t)); + ie->id = X2AP_ProtocolIE_ID_id_UE_HistoryInformation; + ie->criticality = X2AP_Criticality_ignore; + ie->value.present = X2AP_HandoverRequest_IEs__value_PR_UE_HistoryInformation; + //@TODO: consider to update this value + { + lastVisitedCell_Item = (X2AP_LastVisitedCell_Item_t *)calloc(1, sizeof(X2AP_LastVisitedCell_Item_t)); + lastVisitedCell_Item->present = X2AP_LastVisitedCell_Item_PR_e_UTRAN_Cell; + MCC_MNC_TO_PLMNID(instance_p->mcc, instance_p->mnc, instance_p->mnc_digit_length, + &lastVisitedCell_Item->choice.e_UTRAN_Cell.global_Cell_ID.pLMN_Identity); + MACRO_ENB_ID_TO_CELL_IDENTITY(0, 0, &lastVisitedCell_Item->choice.e_UTRAN_Cell.global_Cell_ID.eUTRANcellIdentifier); + lastVisitedCell_Item->choice.e_UTRAN_Cell.cellType.cell_Size = X2AP_Cell_Size_small; + lastVisitedCell_Item->choice.e_UTRAN_Cell.time_UE_StayedInCell = 2; + ASN_SEQUENCE_ADD(&ie->value.choice.UE_HistoryInformation.list, lastVisitedCell_Item); + } + + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + + if (x2ap_eNB_encode_pdu(&pdu, &buffer, &len) < 0) { + X2AP_ERROR("Failed to encode X2 handover request\n"); + abort(); + return -1; + } + + MSC_LOG_TX_MESSAGE (MSC_X2AP_SRC_ENB, MSC_X2AP_TARGET_ENB, NULL, 0, "0 X2Handover/initiatingMessage assoc_id %u", x2ap_eNB_data_p->assoc_id); + + x2ap_eNB_itti_send_sctp_data_req(instance_p->instance, x2ap_eNB_data_p->assoc_id, buffer, len, 1); + + return ret; +} + +int x2ap_eNB_generate_x2_handover_request_ack (x2ap_eNB_data_t *x2ap_eNB_data_p, + x2ap_handover_req_ack_t *x2ap_handover_req_ack) +{ + + X2AP_X2AP_PDU_t pdu; + X2AP_HandoverRequestAcknowledge_t *out; + X2AP_HandoverRequestAcknowledge_IEs_t *ie; + X2AP_E_RABs_Admitted_ItemIEs_t *e_RABS_Admitted_ItemIEs; + X2AP_E_RABs_Admitted_Item_t *e_RABs_Admitted_Item; + + x2ap_eNB_instance_t *instance_p; + + uint8_t *buffer; + uint32_t len; + int ret = 0; + + DevAssert(x2ap_eNB_data_p != NULL); + + /* get the eNB instance */ + instance_p = x2ap_eNB_data_p->x2ap_eNB_instance; + + DevAssert(instance_p != NULL); + + /* Prepare the X2AP handover message to encode */ + memset(&pdu, 0, sizeof(pdu)); + pdu.present = X2AP_X2AP_PDU_PR_successfulOutcome; + pdu.choice.successfulOutcome.procedureCode = X2AP_ProcedureCode_id_handoverPreparation; + pdu.choice.successfulOutcome.criticality = X2AP_Criticality_reject; + pdu.choice.successfulOutcome.value.present = X2AP_SuccessfulOutcome__value_PR_HandoverRequestAcknowledge; + out = &pdu.choice.successfulOutcome.value.choice.HandoverRequestAcknowledge; + + /* mandatory */ + ie = (X2AP_HandoverRequestAcknowledge_IEs_t *)calloc(1, sizeof(X2AP_HandoverRequestAcknowledge_IEs_t)); + ie->id = X2AP_ProtocolIE_ID_id_Old_eNB_UE_X2AP_ID; + ie->criticality = X2AP_Criticality_ignore; + ie->value.present = X2AP_HandoverRequestAcknowledge_IEs__value_PR_UE_X2AP_ID; + ie->value.choice.UE_X2AP_ID = 0; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + + /* mandatory */ + ie = (X2AP_HandoverRequestAcknowledge_IEs_t *)calloc(1, sizeof(X2AP_HandoverRequestAcknowledge_IEs_t)); + ie->id = X2AP_ProtocolIE_ID_id_New_eNB_UE_X2AP_ID; + ie->criticality = X2AP_Criticality_ignore; + ie->value.present = X2AP_HandoverRequestAcknowledge_IEs__value_PR_UE_X2AP_ID_1; + ie->value.choice.UE_X2AP_ID = 0; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + + /* mandatory */ + ie = (X2AP_HandoverRequestAcknowledge_IEs_t *)calloc(1, sizeof(X2AP_HandoverRequestAcknowledge_IEs_t)); + ie->id = X2AP_ProtocolIE_ID_id_E_RABs_Admitted_List; + ie->criticality = X2AP_Criticality_ignore; + ie->value.present = X2AP_HandoverRequestAcknowledge_IEs__value_PR_E_RABs_Admitted_List; + + { + for (int i=0;i<x2ap_handover_req_ack->nb_e_rabs_tobesetup;i++) { + e_RABS_Admitted_ItemIEs = (X2AP_E_RABs_Admitted_ItemIEs_t *)calloc(1,sizeof(X2AP_E_RABs_Admitted_ItemIEs_t)); + e_RABS_Admitted_ItemIEs->id = X2AP_ProtocolIE_ID_id_E_RABs_Admitted_Item; + e_RABS_Admitted_ItemIEs->criticality = X2AP_Criticality_ignore; + e_RABS_Admitted_ItemIEs->value.present = X2AP_E_RABs_Admitted_ItemIEs__value_PR_E_RABs_Admitted_Item; + e_RABs_Admitted_Item = &e_RABS_Admitted_ItemIEs->value.choice.E_RABs_Admitted_Item; + { + e_RABs_Admitted_Item->e_RAB_ID = x2ap_handover_req_ack->e_rabs_tobesetup[i].e_rab_id; + } + ASN_SEQUENCE_ADD(&ie->value.choice.E_RABs_Admitted_List.list, e_RABS_Admitted_ItemIEs); + } + } + + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + + /* mandatory */ + ie = (X2AP_HandoverRequestAcknowledge_IEs_t *)calloc(1, sizeof(X2AP_HandoverRequestAcknowledge_IEs_t)); + ie->id = X2AP_ProtocolIE_ID_id_TargeteNBtoSource_eNBTransparentContainer; + ie->criticality = X2AP_Criticality_ignore; + ie->value.present = X2AP_HandoverRequestAcknowledge_IEs__value_PR_TargeteNBtoSource_eNBTransparentContainer; + + OCTET_STRING_fromBuf(&ie->value.choice.TargeteNBtoSource_eNBTransparentContainer, (char*) x2ap_handover_req_ack->rrc_buffer, x2ap_handover_req_ack->rrc_buffer_size); + + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + + if (x2ap_eNB_encode_pdu(&pdu, &buffer, &len) < 0) { + X2AP_ERROR("Failed to encode X2 handover response\n"); + abort(); + return -1; + } + + MSC_LOG_TX_MESSAGE (MSC_X2AP_SRC_ENB, MSC_X2AP_TARGET_ENB, NULL, 0, "0 X2Handover/successfulOutcome assoc_id %u", x2ap_eNB_data_p->assoc_id); + + x2ap_eNB_itti_send_sctp_data_req(instance_p->instance, x2ap_eNB_data_p->assoc_id, buffer, len, 1); + + return ret; +} + +int x2ap_eNB_generate_x2_ue_context_release (x2ap_eNB_data_t *x2ap_eNB_data_p) +{ + + X2AP_X2AP_PDU_t pdu; + X2AP_UEContextRelease_t *out; + X2AP_UEContextRelease_IEs_t *ie; + + x2ap_eNB_instance_t *instance_p; + + uint8_t *buffer; + uint32_t len; + int ret = 0; + + DevAssert(x2ap_eNB_data_p != NULL); + + /* get the eNB instance */ + instance_p = x2ap_eNB_data_p->x2ap_eNB_instance; + + DevAssert(instance_p != NULL); + + /* Prepare the X2AP ue context relase message to encode */ + memset(&pdu, 0, sizeof(pdu)); + pdu.present = X2AP_X2AP_PDU_PR_initiatingMessage; + pdu.choice.initiatingMessage.procedureCode = X2AP_ProcedureCode_id_uEContextRelease; + pdu.choice.initiatingMessage.criticality = X2AP_Criticality_ignore; + pdu.choice.initiatingMessage.value.present = X2AP_InitiatingMessage__value_PR_UEContextRelease; + out = &pdu.choice.initiatingMessage.value.choice.UEContextRelease; + + /* mandatory */ + ie = (X2AP_UEContextRelease_IEs_t *)calloc(1, sizeof(X2AP_UEContextRelease_IEs_t)); + ie->id = X2AP_ProtocolIE_ID_id_Old_eNB_UE_X2AP_ID; + ie->criticality = X2AP_Criticality_reject; + ie->value.present = X2AP_UEContextRelease_IEs__value_PR_UE_X2AP_ID; + ie->value.choice.UE_X2AP_ID = 0; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + + /* mandatory */ + ie = (X2AP_UEContextRelease_IEs_t *)calloc(1, sizeof(X2AP_UEContextRelease_IEs_t)); + ie->id = X2AP_ProtocolIE_ID_id_New_eNB_UE_X2AP_ID; + ie->criticality = X2AP_Criticality_reject; + ie->value.present = X2AP_UEContextRelease_IEs__value_PR_UE_X2AP_ID_1; + ie->value.choice.UE_X2AP_ID = 0; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + + if (x2ap_eNB_encode_pdu(&pdu, &buffer, &len) < 0) { + X2AP_ERROR("Failed to encode X2 UE Context Release\n"); + abort(); + return -1; + } + + MSC_LOG_TX_MESSAGE (MSC_X2AP_SRC_ENB, MSC_X2AP_TARGET_ENB, NULL, 0, "0 X2UEContextRelease/initiatingMessage assoc_id %u", x2ap_eNB_data_p->assoc_id); + + x2ap_eNB_itti_send_sctp_data_req(instance_p->instance, x2ap_eNB_data_p->assoc_id, buffer, len, 1); + + return ret; +} diff --git a/openair2/X2AP/x2ap_eNB_generate_messages.h b/openair2/X2AP/x2ap_eNB_generate_messages.h index a72b37e743da4ff24bdd8cd827ec0ffaeec47713..9028d8cd054e9d78388e7cf17967d6b00bdbee7f 100644 --- a/openair2/X2AP/x2ap_eNB_generate_messages.h +++ b/openair2/X2AP/x2ap_eNB_generate_messages.h @@ -19,6 +19,13 @@ * contact@openairinterface.org */ +/*! \file x2ap_eNB_generate_messages.h + * \brief x2ap procedures for eNB + * \author Konstantinos Alexandris <Konstantinos.Alexandris@eurecom.fr>, Cedric Roux <Cedric.Roux@eurecom.fr>, Navid Nikaein <Navid.Nikaein@eurecom.fr> + * \date 2018 + * \version 1.0 + */ + #ifndef X2AP_ENB_GENERATE_MESSAGES_H_ #define X2AP_ENB_GENERATE_MESSAGES_H_ @@ -26,9 +33,9 @@ #include "x2ap_common.h" int x2ap_eNB_generate_x2_setup_request(x2ap_eNB_instance_t *instance_p, - x2ap_eNB_data_t *x2ap_enb_data_p); + x2ap_eNB_data_t *x2ap_eNB_data_p); -int x2ap_eNB_generate_x2_setup_response(x2ap_eNB_data_t *x2ap_enb_data_p); +int x2ap_eNB_generate_x2_setup_response(x2ap_eNB_data_t *x2ap_eNB_data_p); int x2ap_eNB_generate_x2_setup_failure(instance_t instance, uint32_t assoc_id, @@ -40,5 +47,12 @@ int x2ap_eNB_set_cause (X2AP_Cause_t * cause_p, X2AP_Cause_PR cause_type, long cause_value); +int x2ap_eNB_generate_x2_handover_request (x2ap_eNB_data_t *x2ap_eNB_data_p, + x2ap_handover_req_t *x2ap_handover_req); + +int x2ap_eNB_generate_x2_handover_request_ack (x2ap_eNB_data_t *x2ap_eNB_data_p, + x2ap_handover_req_ack_t *x2ap_handover_req_ack); + +int x2ap_eNB_generate_x2_ue_context_release (x2ap_eNB_data_t *x2ap_eNB_data_p); #endif /* X2AP_ENB_GENERATE_MESSAGES_H_ */ diff --git a/openair2/X2AP/x2ap_eNB_handler.c b/openair2/X2AP/x2ap_eNB_handler.c index a16a3da5a8ac9d3b5fd998875fed3e61cd8cc5fc..52b14f1d236510804626c9ee889383f19f306e78 100644 --- a/openair2/X2AP/x2ap_eNB_handler.c +++ b/openair2/X2AP/x2ap_eNB_handler.c @@ -18,6 +18,14 @@ * For more information about the OpenAirInterface (OAI) Software Alliance: * contact@openairinterface.org */ + +/*! \file x2ap_eNB_handler.c + * \brief x2ap handler procedures for eNB + * \author Konstantinos Alexandris <Konstantinos.Alexandris@eurecom.fr>, Cedric Roux <Cedric.Roux@eurecom.fr>, Navid Nikaein <Navid.Nikaein@eurecom.fr> + * \date 2018 + * \version 1.0 + */ + #include <stdint.h> #include "intertask_interface.h" @@ -52,9 +60,20 @@ int x2ap_eNB_handle_x2_setup_failure (instance_t instance, uint32_t stream, X2AP_X2AP_PDU_t *pdu); +static +int x2ap_eNB_handle_handover_preparation (instance_t instance, + uint32_t assoc_id, + uint32_t stream, + X2AP_X2AP_PDU_t *pdu); +static +int x2ap_eNB_handle_handover_response (instance_t instance, + uint32_t assoc_id, + uint32_t stream, + X2AP_X2AP_PDU_t *pdu); + /* Handlers matrix. Only eNB related procedure present here */ x2ap_message_decoded_callback x2ap_messages_callback[][3] = { - { 0, 0, 0 }, /* handoverPreparation */ + { x2ap_eNB_handle_handover_preparation, x2ap_eNB_handle_handover_response, 0 }, /* handoverPreparation */ { 0, 0, 0 }, /* handoverCancel */ { 0, 0, 0 }, /* loadIndication */ { 0, 0, 0 }, /* errorIndication */ @@ -143,41 +162,105 @@ int x2ap_eNB_handle_message(instance_t instance, uint32_t assoc_id, int32_t stre const uint8_t *const data, const uint32_t data_length) { X2AP_X2AP_PDU_t pdu; - int ret; + int ret = 0; DevAssert(data != NULL); memset(&pdu, 0, sizeof(pdu)); + //printf("Data length received: %d\n", data_length); + if (x2ap_eNB_decode_pdu(&pdu, data, data_length) < 0) { X2AP_ERROR("Failed to decode PDU\n"); return -1; } - /* Checking procedure Code and direction of message */ - if (pdu.choice.initiatingMessage.procedureCode > sizeof(x2ap_messages_callback) / (3 * sizeof( - x2ap_message_decoded_callback)) - || (pdu.present > X2AP_X2AP_PDU_PR_unsuccessfulOutcome)) { - X2AP_ERROR("[SCTP %d] Either procedureCode %ld or direction %d exceed expected\n", - assoc_id, pdu.choice.initiatingMessage.procedureCode, pdu.present); - ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_X2AP_X2AP_PDU, &pdu); - return -1; - } + switch (pdu.present) { - /* No handler present. - * This can mean not implemented or no procedure for eNB (wrong direction). - */ - if (x2ap_messages_callback[pdu.choice.initiatingMessage.procedureCode][pdu.present - 1] == NULL) { - X2AP_ERROR("[SCTP %d] No handler for procedureCode %ld in %s\n", - assoc_id, pdu.choice.initiatingMessage.procedureCode, - x2ap_direction2String(pdu.present - 1)); - ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_X2AP_X2AP_PDU, &pdu); - return -1; - } + case X2AP_X2AP_PDU_PR_initiatingMessage: + /* Checking procedure Code and direction of message */ + if (pdu.choice.initiatingMessage.procedureCode > sizeof(x2ap_messages_callback) / (3 * sizeof( + x2ap_message_decoded_callback))) { + //|| (pdu.present > X2AP_X2AP_PDU_PR_unsuccessfulOutcome)) { + X2AP_ERROR("[SCTP %d] Either procedureCode %ld exceed expected\n", + assoc_id, pdu.choice.initiatingMessage.procedureCode); + ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_X2AP_X2AP_PDU, &pdu); + return -1; + } - /* Calling the right handler */ - ret = (*x2ap_messages_callback[pdu.choice.initiatingMessage.procedureCode][pdu.present - 1]) + /* No handler present. + * This can mean not implemented or no procedure for eNB (wrong direction). + */ + if (x2ap_messages_callback[pdu.choice.initiatingMessage.procedureCode][pdu.present - 1] == NULL) { + X2AP_ERROR("[SCTP %d] No handler for procedureCode %ld in %s\n", + assoc_id, pdu.choice.initiatingMessage.procedureCode, + x2ap_direction2String(pdu.present - 1)); + ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_X2AP_X2AP_PDU, &pdu); + return -1; + } + /* Calling the right handler */ + ret = (*x2ap_messages_callback[pdu.choice.initiatingMessage.procedureCode][pdu.present - 1]) + (instance, assoc_id, stream, &pdu); + break; + + case X2AP_X2AP_PDU_PR_successfulOutcome: + /* Checking procedure Code and direction of message */ + if (pdu.choice.successfulOutcome.procedureCode > sizeof(x2ap_messages_callback) / (3 * sizeof( + x2ap_message_decoded_callback))) { + //|| (pdu.present > X2AP_X2AP_PDU_PR_unsuccessfulOutcome)) { + X2AP_ERROR("[SCTP %d] Either procedureCode %ld exceed expected\n", + assoc_id, pdu.choice.successfulOutcome.procedureCode); + ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_X2AP_X2AP_PDU, &pdu); + return -1; + } + + /* No handler present. + * This can mean not implemented or no procedure for eNB (wrong direction). + */ + if (x2ap_messages_callback[pdu.choice.successfulOutcome.procedureCode][pdu.present - 1] == NULL) { + X2AP_ERROR("[SCTP %d] No handler for procedureCode %ld in %s\n", + assoc_id, pdu.choice.successfulOutcome.procedureCode, + x2ap_direction2String(pdu.present - 1)); + ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_X2AP_X2AP_PDU, &pdu); + return -1; + } + /* Calling the right handler */ + ret = (*x2ap_messages_callback[pdu.choice.successfulOutcome.procedureCode][pdu.present - 1]) (instance, assoc_id, stream, &pdu); + break; + + case X2AP_X2AP_PDU_PR_unsuccessfulOutcome: + /* Checking procedure Code and direction of message */ + if (pdu.choice.unsuccessfulOutcome.procedureCode > sizeof(x2ap_messages_callback) / (3 * sizeof( + x2ap_message_decoded_callback))) { + //|| (pdu.present > X2AP_X2AP_PDU_PR_unsuccessfulOutcome)) { + X2AP_ERROR("[SCTP %d] Either procedureCode %ld exceed expected\n", + assoc_id, pdu.choice.unsuccessfulOutcome.procedureCode); + ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_X2AP_X2AP_PDU, &pdu); + return -1; + } + + /* No handler present. + * This can mean not implemented or no procedure for eNB (wrong direction). + */ + if (x2ap_messages_callback[pdu.choice.unsuccessfulOutcome.procedureCode][pdu.present - 1] == NULL) { + X2AP_ERROR("[SCTP %d] No handler for procedureCode %ld in %s\n", + assoc_id, pdu.choice.unsuccessfulOutcome.procedureCode, + x2ap_direction2String(pdu.present - 1)); + ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_X2AP_X2AP_PDU, &pdu); + return -1; + } + /* Calling the right handler */ + ret = (*x2ap_messages_callback[pdu.choice.unsuccessfulOutcome.procedureCode][pdu.present - 1]) + (instance, assoc_id, stream, &pdu); + break; + + default: + X2AP_ERROR("[SCTP %d] Direction %d exceed expected\n", + assoc_id, pdu.present); + break; + } + ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_X2AP_X2AP_PDU, &pdu); return ret; } @@ -191,6 +274,7 @@ x2ap_eNB_handle_x2_setup_request(instance_t instance, X2AP_X2SetupRequest_t *x2SetupRequest; X2AP_X2SetupRequest_IEs_t *ie; + ServedCells__Member *servedCellMember; x2ap_eNB_data_t *x2ap_eNB_data; uint32_t eNB_id = 0; @@ -219,27 +303,31 @@ x2ap_eNB_handle_x2_setup_request(instance_t instance, X2AP_FIND_PROTOCOLIE_BY_ID(X2AP_X2SetupRequest_IEs_t, ie, x2SetupRequest, X2AP_ProtocolIE_ID_id_GlobalENB_ID, true); - - if (ie->value.choice.GlobalENB_ID.eNB_ID.present == X2AP_ENB_ID_PR_home_eNB_ID) { + if (ie == NULL ) { + X2AP_ERROR("%s %d: ie is a NULL pointer \n",__FILE__,__LINE__); + return -1; + } else { + if (ie->value.choice.GlobalENB_ID.eNB_ID.present == X2AP_ENB_ID_PR_home_eNB_ID) { // Home eNB ID = 28 bits - uint8_t *eNB_id_buf = ie->value.choice.GlobalENB_ID.eNB_ID.choice.home_eNB_ID.buf; + uint8_t *eNB_id_buf = ie->value.choice.GlobalENB_ID.eNB_ID.choice.home_eNB_ID.buf; - if (ie->value.choice.GlobalENB_ID.eNB_ID.choice.macro_eNB_ID.size != 28) { + if (ie->value.choice.GlobalENB_ID.eNB_ID.choice.macro_eNB_ID.size != 28) { //TODO: handle case were size != 28 -> notify ? reject ? - } + } - eNB_id = (eNB_id_buf[0] << 20) + (eNB_id_buf[1] << 12) + (eNB_id_buf[2] << 4) + ((eNB_id_buf[3] & 0xf0) >> 4); - X2AP_DEBUG("Home eNB id: %07x\n", eNB_id); - } else { + eNB_id = (eNB_id_buf[0] << 20) + (eNB_id_buf[1] << 12) + (eNB_id_buf[2] << 4) + ((eNB_id_buf[3] & 0xf0) >> 4); + X2AP_DEBUG("Home eNB id: %07x\n", eNB_id); + } else { // Macro eNB = 20 bits - uint8_t *eNB_id_buf = ie->value.choice.GlobalENB_ID.eNB_ID.choice.macro_eNB_ID.buf; + uint8_t *eNB_id_buf = ie->value.choice.GlobalENB_ID.eNB_ID.choice.macro_eNB_ID.buf; - if (ie->value.choice.GlobalENB_ID.eNB_ID.choice.macro_eNB_ID.size != 20) { + if (ie->value.choice.GlobalENB_ID.eNB_ID.choice.macro_eNB_ID.size != 20) { //TODO: handle case were size != 20 -> notify ? reject ? - } + } - eNB_id = (eNB_id_buf[0] << 12) + (eNB_id_buf[1] << 4) + ((eNB_id_buf[2] & 0xf0) >> 4); - X2AP_DEBUG("macro eNB id: %05x\n", eNB_id); + eNB_id = (eNB_id_buf[0] << 12) + (eNB_id_buf[1] << 4) + ((eNB_id_buf[2] & 0xf0) >> 4); + X2AP_DEBUG("macro eNB id: %05x\n", eNB_id); + } } X2AP_DEBUG("Adding eNB to the list of associated eNBs\n"); @@ -283,6 +371,21 @@ x2ap_eNB_handle_x2_setup_request(instance_t instance, */ } + /* Set proper pci */ + X2AP_FIND_PROTOCOLIE_BY_ID(X2AP_X2SetupRequest_IEs_t, ie, x2SetupRequest, + X2AP_ProtocolIE_ID_id_ServedCells, true); + + if (ie == NULL ) { + X2AP_ERROR("%s %d: ie is a NULL pointer \n",__FILE__,__LINE__); + return -1; + } else if (ie->value.choice.ServedCells.list.count > 0) { + x2ap_eNB_data->x2ap_eNB_instance->num_cc = ie->value.choice.ServedCells.list.count; + for (int i=0; i<ie->value.choice.ServedCells.list.count;i++) { + servedCellMember = (ServedCells__Member *)ie->value.choice.ServedCells.list.array[i]; + x2ap_eNB_data->x2ap_eNB_instance->Nid_target_cell[i] = servedCellMember->servedCellInfo.pCI; + } + } + return x2ap_eNB_generate_x2_setup_response(x2ap_eNB_data); } @@ -295,6 +398,7 @@ int x2ap_eNB_handle_x2_setup_response(instance_t instance, X2AP_X2SetupResponse_t *x2SetupResponse; X2AP_X2SetupResponse_IEs_t *ie; + ServedCells__Member *servedCellMember; x2ap_eNB_data_t *x2ap_eNB_data; uint32_t eNB_id = 0; @@ -322,6 +426,10 @@ int x2ap_eNB_handle_x2_setup_response(instance_t instance, X2AP_FIND_PROTOCOLIE_BY_ID(X2AP_X2SetupResponse_IEs_t, ie, x2SetupResponse, X2AP_ProtocolIE_ID_id_GlobalENB_ID, true); + if (ie == NULL ) { + X2AP_ERROR("%s %d: ie is a NULL pointer \n",__FILE__,__LINE__); + return -1; + } if (ie->value.choice.GlobalENB_ID.eNB_ID.present == X2AP_ENB_ID_PR_home_eNB_ID) { // Home eNB ID = 28 bits uint8_t *eNB_id_buf = ie->value.choice.GlobalENB_ID.eNB_ID.choice.home_eNB_ID.buf; @@ -367,6 +475,21 @@ int x2ap_eNB_handle_x2_setup_response(instance_t instance, */ } + /* Set proper pci */ + X2AP_FIND_PROTOCOLIE_BY_ID(X2AP_X2SetupResponse_IEs_t, ie, x2SetupResponse, + X2AP_ProtocolIE_ID_id_ServedCells, true); + + if (ie == NULL ) { + X2AP_ERROR("%s %d: ie is a NULL pointer \n",__FILE__,__LINE__); + return -1; + } else if (ie->value.choice.ServedCells.list.count > 0) { + x2ap_eNB_data->x2ap_eNB_instance->num_cc = ie->value.choice.ServedCells.list.count; + for (int i=0; i<ie->value.choice.ServedCells.list.count;i++) { + servedCellMember = (ServedCells__Member *)ie->value.choice.ServedCells.list.array[i]; + x2ap_eNB_data->x2ap_eNB_instance->Nid_target_cell[i] = servedCellMember->servedCellInfo.pCI; + } + } + /* Optionaly set the target eNB name */ /* The association is now ready as source and target eNBs know parameters of each other. @@ -416,7 +539,10 @@ int x2ap_eNB_handle_x2_setup_failure(instance_t instance, X2AP_FIND_PROTOCOLIE_BY_ID(X2AP_X2SetupFailure_IEs_t, ie, x2SetupFailure, X2AP_ProtocolIE_ID_id_Cause, true); - + if (ie == NULL ) { + X2AP_ERROR("%s %d: ie is a NULL pointer \n",__FILE__,__LINE__); + return -1; + } // need a FSM to handle all cases if ((ie->value.choice.Cause.present == X2AP_Cause_PR_misc) && (ie->value.choice.Cause.choice.misc == X2AP_CauseMisc_unspecified)) { @@ -430,3 +556,173 @@ int x2ap_eNB_handle_x2_setup_failure(instance_t instance, return 0; } + +static +int x2ap_eNB_handle_handover_preparation (instance_t instance, + uint32_t assoc_id, + uint32_t stream, + X2AP_X2AP_PDU_t *pdu) +{ + + X2AP_HandoverRequest_t *x2HandoverRequest; + X2AP_HandoverRequest_IEs_t *ie; + + X2AP_E_RABs_ToBeSetup_ItemIEs_t *e_RABS_ToBeSetup_ItemIEs; + X2AP_E_RABs_ToBeSetup_Item_t *e_RABs_ToBeSetup_Item; + + x2ap_eNB_data_t *x2ap_eNB_data; + MessageDef *msg; + + DevAssert (pdu != NULL); + x2HandoverRequest = &pdu->choice.initiatingMessage.value.choice.HandoverRequest; + + if (stream == 0) { + X2AP_ERROR ("Received new x2 handover request on stream == 0\n"); + /* TODO: send a x2 failure response */ + return 0; + } + + X2AP_DEBUG ("Received a new X2 handover request\n"); + + x2ap_eNB_data = x2ap_get_eNB(NULL, assoc_id, 0); + DevAssert(x2ap_eNB_data != NULL); + + msg = itti_alloc_new_message(TASK_X2AP, X2AP_HANDOVER_REQ); + + X2AP_FIND_PROTOCOLIE_BY_ID(X2AP_HandoverRequest_IEs_t, ie, x2HandoverRequest, + X2AP_ProtocolIE_ID_id_Old_eNB_UE_X2AP_ID, true); + //X2AP_HANDOVER_REQ(msg).source_rnti = ctxt_pP->rnti; + //X2AP_HANDOVER_REQ(m).source_x2id = x2HandoverRequest->old_eNB_UE_X2AP_ID; + if (ie == NULL ) { + X2AP_ERROR("%s %d: ie is a NULL pointer \n",__FILE__,__LINE__); + return -1; + } else { + X2AP_HANDOVER_REQ(msg).old_eNB_ue_x2ap_id = ie->value.choice.UE_X2AP_ID; + } + + //X2AP_HANDOVER_REQ(msg).target_physCellId = measResults2->measResultNeighCells->choice. + //measResultListEUTRA.list.array[ncell_index]->physCellId; + X2AP_FIND_PROTOCOLIE_BY_ID(X2AP_HandoverRequest_IEs_t, ie, x2HandoverRequest, + X2AP_ProtocolIE_ID_id_GUMMEI_ID, true); + + TBCD_TO_MCC_MNC(&ie->value.choice.ECGI.pLMN_Identity, X2AP_HANDOVER_REQ(msg).ue_gummei.mcc, + X2AP_HANDOVER_REQ(msg).ue_gummei.mnc, X2AP_HANDOVER_REQ(msg).ue_gummei.mnc_len); + OCTET_STRING_TO_INT8(&ie->value.choice.GUMMEI.mME_Code, X2AP_HANDOVER_REQ(msg).ue_gummei.mme_code); + OCTET_STRING_TO_INT16(&ie->value.choice.GUMMEI.gU_Group_ID.mME_Group_ID, X2AP_HANDOVER_REQ(msg).ue_gummei.mme_group_id); + + X2AP_FIND_PROTOCOLIE_BY_ID(X2AP_HandoverRequest_IEs_t, ie, x2HandoverRequest, + X2AP_ProtocolIE_ID_id_UE_ContextInformation, true); + + if (ie == NULL ) { + X2AP_ERROR("%s %d: ie is a NULL pointer \n",__FILE__,__LINE__); + return -1; + } + + X2AP_HANDOVER_REQ(msg).mme_ue_s1ap_id = ie->value.choice.UE_ContextInformation.mME_UE_S1AP_ID; + X2AP_HANDOVER_REQ(msg).target_mod_id = x2ap_eNB_data->x2ap_eNB_instance->eNB_id; + X2AP_HANDOVER_REQ(msg).security_capabilities.encryption_algorithms = + BIT_STRING_to_uint16(&ie->value.choice.UE_ContextInformation.uESecurityCapabilities.encryptionAlgorithms); + X2AP_HANDOVER_REQ(msg).security_capabilities.integrity_algorithms = + BIT_STRING_to_uint16(&ie->value.choice.UE_ContextInformation.uESecurityCapabilities.integrityProtectionAlgorithms); + + //X2AP_HANDOVER_REQ(msg).ue_ambr=ue_context_pP->ue_context.ue_ambr; + + if ((ie->value.choice.UE_ContextInformation.aS_SecurityInformation.key_eNodeB_star.buf) && + (ie->value.choice.UE_ContextInformation.aS_SecurityInformation.key_eNodeB_star.size == 32)) { + memcpy(X2AP_HANDOVER_REQ(msg).kenb, ie->value.choice.UE_ContextInformation.aS_SecurityInformation.key_eNodeB_star.buf, 32); + X2AP_HANDOVER_REQ(msg).kenb_ncc = ie->value.choice.UE_ContextInformation.aS_SecurityInformation.nextHopChainingCount; + } else { + X2AP_WARN ("Size of eNB key star does not match the expected value\n"); + } + + if (ie->value.choice.UE_ContextInformation.e_RABs_ToBeSetup_List.list.count > 0) { + + X2AP_HANDOVER_REQ(msg).nb_e_rabs_tobesetup = ie->value.choice.UE_ContextInformation.e_RABs_ToBeSetup_List.list.count; + + for (int i=0;i<ie->value.choice.UE_ContextInformation.e_RABs_ToBeSetup_List.list.count;i++) { + e_RABS_ToBeSetup_ItemIEs = (X2AP_E_RABs_ToBeSetup_ItemIEs_t *) ie->value.choice.UE_ContextInformation.e_RABs_ToBeSetup_List.list.array[i]; + e_RABs_ToBeSetup_Item = &e_RABS_ToBeSetup_ItemIEs->value.choice.E_RABs_ToBeSetup_Item; + + X2AP_HANDOVER_REQ(msg).e_rabs_tobesetup[i].e_rab_id = e_RABs_ToBeSetup_Item->e_RAB_ID ; + + memcpy(X2AP_HANDOVER_REQ(msg).e_rabs_tobesetup[i].eNB_addr.buffer, + e_RABs_ToBeSetup_Item->uL_GTPtunnelEndpoint.transportLayerAddress.buf, + e_RABs_ToBeSetup_Item->uL_GTPtunnelEndpoint.transportLayerAddress.size); + + X2AP_HANDOVER_REQ(msg).e_rabs_tobesetup[i].eNB_addr.length = + e_RABs_ToBeSetup_Item->uL_GTPtunnelEndpoint.transportLayerAddress.size * 8 - e_RABs_ToBeSetup_Item->uL_GTPtunnelEndpoint.transportLayerAddress.bits_unused; + + OCTET_STRING_TO_INT32(&e_RABs_ToBeSetup_Item->uL_GTPtunnelEndpoint.gTP_TEID, + X2AP_HANDOVER_REQ(msg).e_rabs_tobesetup[i].gtp_teid); + + X2AP_HANDOVER_REQ(msg).e_rab_param[i].qos.qci = e_RABs_ToBeSetup_Item->e_RAB_Level_QoS_Parameters.qCI; + X2AP_HANDOVER_REQ(msg).e_rab_param[i].qos.allocation_retention_priority.priority_level = e_RABs_ToBeSetup_Item->e_RAB_Level_QoS_Parameters.allocationAndRetentionPriority.priorityLevel; + X2AP_HANDOVER_REQ(msg).e_rab_param[i].qos.allocation_retention_priority.pre_emp_capability = e_RABs_ToBeSetup_Item->e_RAB_Level_QoS_Parameters.allocationAndRetentionPriority.pre_emptionCapability; + X2AP_HANDOVER_REQ(msg).e_rab_param[i].qos.allocation_retention_priority.pre_emp_vulnerability = e_RABs_ToBeSetup_Item->e_RAB_Level_QoS_Parameters.allocationAndRetentionPriority.pre_emptionVulnerability; + } + + } + else { + X2AP_ERROR ("Can't decode the e_RABs_ToBeSetup_List \n"); + } + + X2AP_RRC_Context_t *c = &ie->value.choice.UE_ContextInformation.rRC_Context; + + if (c->size > 1024 /* TODO: this is the size of rrc_buffer in struct x2ap_handover_req_ack_s*/) + { printf("%s:%d: fatal: buffer too big\n", __FILE__, __LINE__); abort(); } + + memcpy(X2AP_HANDOVER_REQ_ACK(msg).rrc_buffer, c->buf, c->size); + X2AP_HANDOVER_REQ_ACK(msg).rrc_buffer_size = c->size; + + itti_send_msg_to_task(TASK_RRC_ENB, x2ap_eNB_data->x2ap_eNB_instance->instance, msg); + + return 0; +} + +static +int x2ap_eNB_handle_handover_response (instance_t instance, + uint32_t assoc_id, + uint32_t stream, + X2AP_X2AP_PDU_t *pdu) +{ + X2AP_HandoverRequestAcknowledge_t *x2HandoverRequestAck; + X2AP_HandoverRequestAcknowledge_IEs_t *ie; + + x2ap_eNB_data_t *x2ap_eNB_data; + MessageDef *msg; + + DevAssert (pdu != NULL); + x2HandoverRequestAck = &pdu->choice.successfulOutcome.value.choice.HandoverRequestAcknowledge; + + if (stream == 0) { + X2AP_ERROR ("Received new x2 handover response on stream == 0\n"); + /* TODO: send a x2 failure response */ + return 0; + } + + X2AP_DEBUG ("Received a new X2 handover response\n"); + + x2ap_eNB_data = x2ap_get_eNB(NULL, assoc_id, 0); + DevAssert(x2ap_eNB_data != NULL); + + + msg = itti_alloc_new_message(TASK_X2AP, X2AP_HANDOVER_REQ_ACK); + /* TODO: fill the message */ + //extern int x2id_to_source_rnti[1]; + //X2AP_HANDOVER_REQ_ACK(m).source_x2id = x2HandoverRequestAck->old_eNB_UE_X2AP_ID; + //X2AP_HANDOVER_REQ_ACK(m).source_rnti = x2id_to_source_rnti[x2HandoverRequestAck->old_eNB_UE_X2AP_ID]; + + X2AP_FIND_PROTOCOLIE_BY_ID(X2AP_HandoverRequestAcknowledge_IEs_t, ie, x2HandoverRequestAck, + X2AP_ProtocolIE_ID_id_TargeteNBtoSource_eNBTransparentContainer, true); + + X2AP_TargeteNBtoSource_eNBTransparentContainer_t *c = &ie->value.choice.TargeteNBtoSource_eNBTransparentContainer; + + if (c->size > 1024 /* TODO: this is the size of rrc_buffer in struct x2ap_handover_req_ack_s*/) + { printf("%s:%d: fatal: buffer too big\n", __FILE__, __LINE__); abort(); } + + memcpy(X2AP_HANDOVER_REQ_ACK(msg).rrc_buffer, c->buf, c->size); + X2AP_HANDOVER_REQ_ACK(msg).rrc_buffer_size = c->size; + + itti_send_msg_to_task(TASK_RRC_ENB, x2ap_eNB_data->x2ap_eNB_instance->instance, msg); + return 0; +} diff --git a/openair2/X2AP/x2ap_eNB_handler.h b/openair2/X2AP/x2ap_eNB_handler.h index 0f93859a84213e273c3a19eac0dd158d1616212e..e4dac14e8e637078880ac10dd25b442a81cce51f 100644 --- a/openair2/X2AP/x2ap_eNB_handler.h +++ b/openair2/X2AP/x2ap_eNB_handler.h @@ -19,6 +19,13 @@ * contact@openairinterface.org */ +/*! \file x2ap_eNB_handler.h + * \brief x2ap handler procedures for eNB + * \author Konstantinos Alexandris <Konstantinos.Alexandris@eurecom.fr>, Cedric Roux <Cedric.Roux@eurecom.fr>, Navid Nikaein <Navid.Nikaein@eurecom.fr> + * \date 2018 + * \version 1.0 + */ + #ifndef X2AP_ENB_HANDLERS_H_ #define X2AP_ENB_HANDLERS_H_ diff --git a/openair2/X2AP/x2ap_eNB_itti_messaging.c b/openair2/X2AP/x2ap_eNB_itti_messaging.c index d8e1e19afeeae608e1d44b18784ca1ec0aa293a6..1896e3949c6adf86c9ae91a4f606b1a1b69583f8 100644 --- a/openair2/X2AP/x2ap_eNB_itti_messaging.c +++ b/openair2/X2AP/x2ap_eNB_itti_messaging.c @@ -19,6 +19,13 @@ * contact@openairinterface.org */ +/*! \file x2ap_eNB_itti_messaging.c + * \brief x2ap tasks for eNB + * \author Konstantinos Alexandris <Konstantinos.Alexandris@eurecom.fr>, Cedric Roux <Cedric.Roux@eurecom.fr>, Navid Nikaein <Navid.Nikaein@eurecom.fr> + * \date 2018 + * \version 1.0 + */ + #include "intertask_interface.h" #include "x2ap_eNB_itti_messaging.h" diff --git a/openair2/X2AP/x2ap_eNB_itti_messaging.h b/openair2/X2AP/x2ap_eNB_itti_messaging.h index 55bf58b6605260c85c70b4d5887f768c42f3e49f..ee946880ac3c3b69ca51b58ee0c327260ea3ed6d 100644 --- a/openair2/X2AP/x2ap_eNB_itti_messaging.h +++ b/openair2/X2AP/x2ap_eNB_itti_messaging.h @@ -19,6 +19,13 @@ * contact@openairinterface.org */ +/*! \file x2ap_eNB_itti_messaging.h + * \brief x2ap tasks for eNB + * \author Konstantinos Alexandris <Konstantinos.Alexandris@eurecom.fr>, Cedric Roux <Cedric.Roux@eurecom.fr>, Navid Nikaein <Navid.Nikaein@eurecom.fr> + * \date 2018 + * \version 1.0 + */ + #ifndef X2AP_ENB_ITTI_MESSAGING_H_ #define X2AP_ENB_ITTI_MESSAGING_H_ diff --git a/openair2/X2AP/x2ap_eNB_management_procedures.c b/openair2/X2AP/x2ap_eNB_management_procedures.c index c2b128ffd312c4c042dc397b992dd62ff6641bc2..670581406b9e2190ac0233bd9b5b797fc66ef521 100644 --- a/openair2/X2AP/x2ap_eNB_management_procedures.c +++ b/openair2/X2AP/x2ap_eNB_management_procedures.c @@ -19,6 +19,13 @@ * contact@openairinterface.org */ +/*! \file x2ap_eNB_management_procedures.c + * \brief x2ap tasks for eNB + * \author Konstantinos Alexandris <Konstantinos.Alexandris@eurecom.fr>, Cedric Roux <Cedric.Roux@eurecom.fr>, Navid Nikaein <Navid.Nikaein@eurecom.fr> + * \date 2018 + * \version 1.0 + */ + #include <stdio.h> #include <stdlib.h> #include <stdint.h> @@ -162,6 +169,22 @@ x2ap_eNB_instance_t *x2ap_eNB_get_instance(instance_t instance) return NULL; } +x2ap_eNB_instance_t *x2ap_eNB_pci_get_instance(uint32_t pci) +{ + x2ap_eNB_instance_t *temp = NULL; + + STAILQ_FOREACH(temp, &x2ap_eNB_internal_data.x2ap_eNB_instances_head, + x2ap_eNB_entries) { + for (int i=0; i<temp->num_cc;i++) { + if (temp->Nid_target_cell[i] == pci) { + /* Matching occurence */ + return temp; + } + } + } + + return NULL; +} /// utility functions diff --git a/openair2/X2AP/x2ap_eNB_management_procedures.h b/openair2/X2AP/x2ap_eNB_management_procedures.h index b66a6d10356536508f5dad4d44a960da61a7f094..80234159515f401f439b47ed0695b9223963cc69 100644 --- a/openair2/X2AP/x2ap_eNB_management_procedures.h +++ b/openair2/X2AP/x2ap_eNB_management_procedures.h @@ -19,6 +19,13 @@ * contact@openairinterface.org */ +/*! \file x2ap_eNB_management_procedures.h + * \brief x2ap tasks for eNB + * \author Konstantinos Alexandris <Konstantinos.Alexandris@eurecom.fr>, Cedric Roux <Cedric.Roux@eurecom.fr>, Navid Nikaein <Navid.Nikaein@eurecom.fr> + * \date 2018 + * \version 1.0 + */ + #ifndef X2AP_ENB_MANAGEMENT_PROCEDURES_H_ #define X2AP_ENB_MANAGEMENT_PROCEDURES_H @@ -30,6 +37,8 @@ void x2ap_eNB_insert_new_instance(x2ap_eNB_instance_t *new_instance_p); x2ap_eNB_instance_t *x2ap_eNB_get_instance(uint8_t mod_id); +x2ap_eNB_instance_t *x2ap_eNB_pci_get_instance(uint32_t pci); + uint16_t x2ap_eNB_fetch_add_global_cnx_id(void); void x2ap_eNB_prepare_internal_data(void); diff --git a/openair3/GTPV1-U/gtpv1u_eNB.c b/openair3/GTPV1-U/gtpv1u_eNB.c index c8bfd1255c0ebd600d02bc0803186a0c4be6b5eb..d904e90f228238971ab64917480dda48868f9aab 100644 --- a/openair3/GTPV1-U/gtpv1u_eNB.c +++ b/openair3/GTPV1-U/gtpv1u_eNB.c @@ -61,8 +61,7 @@ extern RAN_CONTEXT_t RC; static int gtpv1u_dump_socket_g; //----------------------------------------------------------------------------- -int gtpv1u_eNB_create_dump_socket(void) -{ +int gtpv1u_eNB_create_dump_socket(void) { struct ifreq ifr; int hdrincl=1; @@ -92,8 +91,7 @@ int gtpv1u_eNB_create_dump_socket(void) } //----------------------------------------------------------------------------- -static void gtpv1u_eNB_write_dump_socket(uint8_t *buffer_pP, uint32_t buffer_lengthP) -{ +static void gtpv1u_eNB_write_dump_socket(uint8_t *buffer_pP, uint32_t buffer_lengthP) { struct sockaddr_in sin; memset(&sin, 0, sizeof(sin)); sin.sin_family = AF_INET; @@ -108,12 +106,10 @@ static void gtpv1u_eNB_write_dump_socket(uint8_t *buffer_pP, uint32_t buffer_len #endif //----------------------------------------------------------------------------- -static int gtpv1u_eNB_send_init_udp(const Gtpv1uS1Req * req) -{ +static int gtpv1u_eNB_send_init_udp(const Gtpv1uS1Req *req) { // Create and alloc new message MessageDef *message_p; - struct in_addr addr={0}; - + struct in_addr addr= {0}; message_p = itti_alloc_new_message(TASK_GTPV1_U, UDP_INIT); if (message_p == NULL) { @@ -124,21 +120,20 @@ static int gtpv1u_eNB_send_init_udp(const Gtpv1uS1Req * req) addr.s_addr = req->enb_ip_address_for_S1u_S12_S4_up; UDP_INIT(message_p).address = inet_ntoa(addr); LOG_I(GTPU, "Tx UDP_INIT IP addr %s (%x)\n", UDP_INIT(message_p).address,UDP_INIT(message_p).port); - MSC_LOG_EVENT( - MSC_GTPU_ENB, - "0 UDP bind %s:%u", - UDP_INIT(message_p).address, - UDP_INIT(message_p).port); + MSC_GTPU_ENB, + "0 UDP bind %s:%u", + UDP_INIT(message_p).address, + UDP_INIT(message_p).port); return itti_send_msg_to_task(TASK_UDP, INSTANCE_DEFAULT, message_p); } static int gtpv1u_s1_req( const instance_t instanceP, - const Gtpv1uS1Req * const req) { + const Gtpv1uS1Req *const req) { memcpy(&RC.gtpv1u_data_g->enb_ip_address_for_S1u_S12_S4_up, - &req->enb_ip_address_for_S1u_S12_S4_up, - sizeof (req->enb_ip_address_for_S1u_S12_S4_up)); + &req->enb_ip_address_for_S1u_S12_S4_up, + sizeof (req->enb_ip_address_for_S1u_S12_S4_up)); gtpv1u_eNB_send_init_udp(req); return 0; } @@ -148,8 +143,7 @@ NwGtpv1uRcT gtpv1u_eNB_log_request(NwGtpv1uLogMgrHandleT hLogMgr, uint32_t logLevel, NwCharT *file, uint32_t line, - NwCharT *logStr) -{ + NwCharT *logStr) { LOG_D(GTPU, "%s\n", logStr); return NW_GTPV1U_OK; } @@ -161,12 +155,10 @@ NwGtpv1uRcT gtpv1u_eNB_send_udp_msg( uint32_t buffer_len, uint32_t buffer_offset, uint32_t peerIpAddr, - uint16_t peerPort) -{ + uint16_t peerPort) { // Create and alloc new message MessageDef *message_p = NULL; udp_data_req_t *udp_data_req_p = NULL; - message_p = itti_alloc_new_message(TASK_GTPV1_U, UDP_DATA_REQ); if (message_p) { @@ -190,8 +182,7 @@ NwGtpv1uRcT gtpv1u_eNB_send_udp_msg( /* Callback called when a gtpv1u message arrived on UDP interface */ NwGtpv1uRcT gtpv1u_eNB_process_stack_req( NwGtpv1uUlpHandleT hUlp, - NwGtpv1uUlpApiT *pUlpApi) -{ + NwGtpv1uUlpApiT *pUlpApi) { boolean_t result = FALSE; teid_t teid = 0; hashtable_rc_t hash_rc = HASH_TABLE_KEY_NOT_EXISTS; @@ -204,94 +195,88 @@ NwGtpv1uRcT gtpv1u_eNB_process_stack_req( * - T-PDU * - END-MARKER */ - case NW_GTPV1U_ULP_API_RECV_TPDU: { - uint8_t buffer[4096]; - uint32_t buffer_len; - /* Nw-gptv1u stack has processed a PDU. we can schedule it to PDCP - * for transmission. - */ - teid = pUlpApi->apiInfo.recvMsgInfo.teid; - - if (NW_GTPV1U_OK != nwGtpv1uMsgGetTpdu(pUlpApi->apiInfo.recvMsgInfo.hMsg, - buffer, &buffer_len)) { - LOG_E(GTPU, "Error while retrieving T-PDU"); - } + case NW_GTPV1U_ULP_API_RECV_TPDU: { + uint8_t buffer[4096]; + uint32_t buffer_len; + /* Nw-gptv1u stack has processed a PDU. we can schedule it to PDCP + * for transmission. + */ + teid = pUlpApi->apiInfo.recvMsgInfo.teid; + + if (NW_GTPV1U_OK != nwGtpv1uMsgGetTpdu(pUlpApi->apiInfo.recvMsgInfo.hMsg, + buffer, &buffer_len)) { + LOG_E(GTPU, "Error while retrieving T-PDU"); + } - itti_free(TASK_UDP, ((NwGtpv1uMsgT*)pUlpApi->apiInfo.recvMsgInfo.hMsg)->msgBuf); + itti_free(TASK_UDP, ((NwGtpv1uMsgT *)pUlpApi->apiInfo.recvMsgInfo.hMsg)->msgBuf); #if defined(GTP_DUMP_SOCKET) && GTP_DUMP_SOCKET > 0 - gtpv1u_eNB_write_dump_socket(buffer,buffer_len); + gtpv1u_eNB_write_dump_socket(buffer,buffer_len); #endif + rc = nwGtpv1uMsgDelete(RC.gtpv1u_data_g->gtpv1u_stack, + pUlpApi->apiInfo.recvMsgInfo.hMsg); - rc = nwGtpv1uMsgDelete(RC.gtpv1u_data_g->gtpv1u_stack, - pUlpApi->apiInfo.recvMsgInfo.hMsg); - if (rc != NW_GTPV1U_OK) { - LOG_E(GTPU, "nwGtpv1uMsgDelete failed: 0x%x\n", rc); - } + if (rc != NW_GTPV1U_OK) { + LOG_E(GTPU, "nwGtpv1uMsgDelete failed: 0x%x\n", rc); + } - //----------------------- - // GTPV1U->PDCP mapping - //----------------------- - hash_rc = hashtable_get(RC.gtpv1u_data_g->teid_mapping, teid, (void**)>pv1u_teid_data_p); + //----------------------- + // GTPV1U->PDCP mapping + //----------------------- + hash_rc = hashtable_get(RC.gtpv1u_data_g->teid_mapping, teid, (void **)>pv1u_teid_data_p); - if (hash_rc == HASH_TABLE_OK) { + if (hash_rc == HASH_TABLE_OK) { #if defined(LOG_GTPU) && LOG_GTPU > 0 - LOG_D(GTPU, "Received T-PDU from gtpv1u stack teid %u size %d -> enb module id %u ue module id %u rab id %u\n", - teid, - buffer_len, - gtpv1u_teid_data_p->enb_id, - gtpv1u_teid_data_p->ue_id, - gtpv1u_teid_data_p->eps_bearer_id); + LOG_D(GTPU, "Received T-PDU from gtpv1u stack teid %u size %d -> enb module id %u ue module id %u rab id %u\n", + teid, + buffer_len, + gtpv1u_teid_data_p->enb_id, + gtpv1u_teid_data_p->ue_id, + gtpv1u_teid_data_p->eps_bearer_id); #endif - -//#warning "LG eps bearer mapping to DRB id to do (offset -4)" - PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, gtpv1u_teid_data_p->enb_id, ENB_FLAG_YES, gtpv1u_teid_data_p->ue_id, 0, 0,gtpv1u_teid_data_p->enb_id); - MSC_LOG_TX_MESSAGE( - MSC_GTPU_ENB, - MSC_PDCP_ENB, - NULL,0, - MSC_AS_TIME_FMT" DATA-REQ rb %u size %u", - 0,0, - (gtpv1u_teid_data_p->eps_bearer_id) ? gtpv1u_teid_data_p->eps_bearer_id - 4: 5-4, - buffer_len); - - result = pdcp_data_req( - &ctxt, - SRB_FLAG_NO, - (gtpv1u_teid_data_p->eps_bearer_id) ? gtpv1u_teid_data_p->eps_bearer_id - 4: 5-4, - 0, // mui - SDU_CONFIRM_NO, // confirm - buffer_len, - buffer, - PDCP_TRANSMISSION_MODE_DATA + //#warning "LG eps bearer mapping to DRB id to do (offset -4)" + PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, gtpv1u_teid_data_p->enb_id, ENB_FLAG_YES, gtpv1u_teid_data_p->ue_id, 0, 0,gtpv1u_teid_data_p->enb_id); + MSC_LOG_TX_MESSAGE( + MSC_GTPU_ENB, + MSC_PDCP_ENB, + NULL,0, + MSC_AS_TIME_FMT" DATA-REQ rb %u size %u", + 0,0, + (gtpv1u_teid_data_p->eps_bearer_id) ? gtpv1u_teid_data_p->eps_bearer_id - 4: 5-4, + buffer_len); + result = pdcp_data_req( + &ctxt, + SRB_FLAG_NO, + (gtpv1u_teid_data_p->eps_bearer_id) ? gtpv1u_teid_data_p->eps_bearer_id - 4: 5-4, + 0, // mui + SDU_CONFIRM_NO, // confirm + buffer_len, + buffer, + PDCP_TRANSMISSION_MODE_DATA #if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0)) - ,NULL, NULL + ,NULL, NULL #endif - ); - - - if ( result == FALSE ) { - - if (ctxt.configured == FALSE ) - LOG_W(GTPU, "PDCP data request failed, cause: RB is not configured!\n") ; - else - LOG_W(GTPU, "PDCP data request failed\n"); - - return NW_GTPV1U_FAILURE; + ); + + if ( result == FALSE ) { + if (ctxt.configured == FALSE ) + LOG_W(GTPU, "PDCP data request failed, cause: RB is not configured!\n") ; + else + LOG_W(GTPU, "PDCP data request failed\n"); + + return NW_GTPV1U_FAILURE; + } + } else { + LOG_W(GTPU, "Received T-PDU from gtpv1u stack teid %u unknown size %u", teid, buffer_len); } - - } else { - LOG_W(GTPU, "Received T-PDU from gtpv1u stack teid %u unknown size %u", teid, buffer_len); } - } break; - - default: { - LOG_E(GTPU, "Received undefined UlpApi (%02x) from gtpv1u stack!\n", - pUlpApi->apiType); - } - - } // end of switch - + + default: { + LOG_E(GTPU, "Received undefined UlpApi (%02x) from gtpv1u stack!\n", + pUlpApi->apiType); + } + } // end of switch + return NW_GTPV1U_OK; } @@ -301,8 +286,7 @@ int data_recv_callback(uint16_t portP, uint32_t address, uint8_t *buffer, uint32_t length, - void *arg_p) -{ + void *arg_p) { gtpv1u_data_t *gtpv1u_data_p; if (arg_p == NULL) { @@ -310,7 +294,6 @@ int data_recv_callback(uint16_t portP, } gtpv1u_data_p = (gtpv1u_data_t *)arg_p; - return nwGtpv1uProcessUdpReq(gtpv1u_data_p->gtpv1u_stack, buffer, length, @@ -421,9 +404,7 @@ static NwGtpv1uRcT gtpv1u_start_timer_wrapper( uint32_t timeoutUsec, uint32_t tmrType, void *timeoutArg, - NwGtpv1uTimerHandleT *hTmr) -{ - + NwGtpv1uTimerHandleT *hTmr) { NwGtpv1uRcT rc = NW_GTPV1U_OK; long timer_id; @@ -453,11 +434,8 @@ static NwGtpv1uRcT gtpv1u_start_timer_wrapper( static NwGtpv1uRcT gtpv1u_stop_timer_wrapper( NwGtpv1uTimerMgrHandleT tmrMgrHandle, - NwGtpv1uTimerHandleT hTmr) -{ - + NwGtpv1uTimerHandleT hTmr) { NwGtpv1uRcT rc = NW_GTPV1U_OK; - return rc; } @@ -468,18 +446,14 @@ gtpv1u_initial_req( gtpv1u_data_t *gtpv1u_data_pP, teid_t teidP, tcp_udp_port_t portP, - uint32_t address) -{ + uint32_t address) { NwGtpv1uUlpApiT ulp_req; NwGtpv1uRcT rc = NW_GTPV1U_FAILURE; - memset(&ulp_req, 0, sizeof(NwGtpv1uUlpApiT)); - ulp_req.apiType = NW_GTPV1U_ULP_API_INITIAL_REQ; ulp_req.apiInfo.initialReqInfo.teid = teidP; ulp_req.apiInfo.initialReqInfo.peerPort = portP; ulp_req.apiInfo.initialReqInfo.peerIp = address; - rc = nwGtpv1uProcessUlpReq(gtpv1u_data_pP->gtpv1u_stack, &ulp_req); if (rc == NW_GTPV1U_OK) { @@ -500,9 +474,7 @@ gtpv1u_new_data_req( uint8_t *buffer_pP, uint32_t buf_lenP, uint32_t buf_offsetP -) -{ - +) { NwGtpv1uUlpApiT stack_req; NwGtpv1uRcT rc = NW_GTPV1U_FAILURE; struct gtpv1u_ue_data_s ue; @@ -510,17 +482,14 @@ gtpv1u_new_data_req( struct gtpv1u_bearer_s *bearer_p = NULL; hashtable_rc_t hash_rc = HASH_TABLE_KEY_NOT_EXISTS;; gtpv1u_data_t *gtpv1u_data_p = NULL; - memset(&ue, 0, sizeof(struct gtpv1u_ue_data_s)); ue.ue_id = ue_rntiP; - AssertFatal(enb_module_idP >=0, "Bad parameter enb module id %u\n", enb_module_idP); AssertFatal((rab_idP - GTPV1U_BEARER_OFFSET)< GTPV1U_MAX_BEARERS_ID, "Bad parameter rab id %u\n", rab_idP); AssertFatal((rab_idP - GTPV1U_BEARER_OFFSET) >= 0 , "Bad parameter rab id %u\n", rab_idP); - gtpv1u_data_p = RC.gtpv1u_data_g; /* Check that UE context is present in ue map. */ - hash_rc = hashtable_get(gtpv1u_data_p->ue_mapping, (uint64_t)ue_rntiP, (void**)&ue_inst_p); + hash_rc = hashtable_get(gtpv1u_data_p->ue_mapping, (uint64_t)ue_rntiP, (void **)&ue_inst_p); if (hash_rc == HASH_TABLE_KEY_NOT_EXISTS ) { LOG_E(GTPU, "[UE %d] Trying to send data on non-existing UE context\n", ue_rntiP); @@ -536,18 +505,16 @@ gtpv1u_new_data_req( if (bearer_p->state != BEARER_UP) { LOG_W(GTPU, "Trying to send data over bearer with state(%u) != BEARER_UP\n", bearer_p->state); -//#warning LG: HACK WHILE WAITING FOR NAS, normally return -1 + //#warning LG: HACK WHILE WAITING FOR NAS, normally return -1 if (bearer_p->state != BEARER_IN_CONFIG) return -1; } memset(&stack_req, 0, sizeof(NwGtpv1uUlpApiT)); - stack_req.apiType = NW_GTPV1U_ULP_API_SEND_TPDU; stack_req.apiInfo.sendtoInfo.teid = bearer_p->teid_sgw; stack_req.apiInfo.sendtoInfo.ipAddr = bearer_p->sgw_ip_addr; - LOG_D(GTPU, "TX TO TEID %u addr 0x%x\n",bearer_p->teid_sgw, bearer_p->sgw_ip_addr); rc = nwGtpv1uGpduMsgNew(gtpv1u_data_p->gtpv1u_stack, bearer_p->teid_sgw, @@ -587,10 +554,9 @@ gtpv1u_new_data_req( int gtpv1u_create_s1u_tunnel( const instance_t instanceP, - const gtpv1u_enb_create_tunnel_req_t * const create_tunnel_req_pP, - gtpv1u_enb_create_tunnel_resp_t * const create_tunnel_resp_pP - ) -{ + const gtpv1u_enb_create_tunnel_req_t *const create_tunnel_req_pP, + gtpv1u_enb_create_tunnel_resp_t *const create_tunnel_resp_pP +) { /* Create a new nw-gtpv1-u stack req using API */ NwGtpv1uUlpApiT stack_req; NwGtpv1uRcT rc = NW_GTPV1U_FAILURE; @@ -606,17 +572,14 @@ gtpv1u_create_s1u_tunnel( int ip_offset = 0; in_addr_t in_addr; int addrs_length_in_bytes= 0; - - MSC_LOG_RX_MESSAGE( - MSC_GTPU_ENB, - MSC_RRC_ENB, - NULL,0, - MSC_AS_TIME_FMT" CREATE_TUNNEL_REQ RNTI %"PRIx16" inst %u ntuns %u ebid %u sgw-s1u teid %u", - 0,0,create_tunnel_req_pP->rnti, instanceP, - create_tunnel_req_pP->num_tunnels, create_tunnel_req_pP->eps_bearer_id[0], - create_tunnel_req_pP->sgw_S1u_teid[0]); - + MSC_GTPU_ENB, + MSC_RRC_ENB, + NULL,0, + MSC_AS_TIME_FMT" CREATE_TUNNEL_REQ RNTI %"PRIx16" inst %u ntuns %u ebid %u sgw-s1u teid %u", + 0,0,create_tunnel_req_pP->rnti, instanceP, + create_tunnel_req_pP->num_tunnels, create_tunnel_req_pP->eps_bearer_id[0], + create_tunnel_req_pP->sgw_S1u_teid[0]); create_tunnel_resp_pP->rnti = create_tunnel_req_pP->rnti; create_tunnel_resp_pP->status = 0; create_tunnel_resp_pP->num_tunnels = 0; @@ -627,7 +590,6 @@ gtpv1u_create_s1u_tunnel( LOG_D(GTPU, "Rx GTPV1U_ENB_CREATE_TUNNEL_REQ ue rnti %x eps bearer id %u\n", create_tunnel_req_pP->rnti, eps_bearer_id); memset(&stack_req, 0, sizeof(NwGtpv1uUlpApiT)); - stack_req.apiType = NW_GTPV1U_ULP_API_CREATE_TUNNEL_ENDPOINT; do { @@ -636,7 +598,6 @@ gtpv1u_create_s1u_tunnel( stack_req.apiInfo.createTunnelEndPointInfo.teid = s1u_teid; stack_req.apiInfo.createTunnelEndPointInfo.hUlpSession = 0; stack_req.apiInfo.createTunnelEndPointInfo.hStackSession = 0; - rc = nwGtpv1uProcessUlpReq(RC.gtpv1u_data_g->gtpv1u_stack, &stack_req); LOG_D(GTPU, ".\n"); } while (rc != NW_GTPV1U_OK); @@ -647,7 +608,6 @@ gtpv1u_create_s1u_tunnel( hash_rc = hashtable_get(RC.gtpv1u_data_g->ue_mapping, create_tunnel_req_pP->rnti, (void **)>pv1u_ue_data_p); if ((hash_rc == HASH_TABLE_KEY_NOT_EXISTS) || (hash_rc == HASH_TABLE_OK)) { - if (hash_rc == HASH_TABLE_KEY_NOT_EXISTS) { gtpv1u_ue_data_p = calloc (1, sizeof(gtpv1u_ue_data_t)); hash_rc = hashtable_insert(RC.gtpv1u_data_g->ue_mapping, create_tunnel_req_pP->rnti, gtpv1u_ue_data_p); @@ -660,7 +620,6 @@ gtpv1u_create_s1u_tunnel( &RC.gtpv1u_data_g->enb_ip_address_for_S1u_S12_S4_up, sizeof (in_addr_t)); create_tunnel_resp_pP->enb_addr.length = sizeof (in_addr_t); - addrs_length_in_bytes = create_tunnel_req_pP->sgw_addr[i].length / 8; AssertFatal((addrs_length_in_bytes == 4) || (addrs_length_in_bytes == 16) || @@ -670,7 +629,7 @@ gtpv1u_create_s1u_tunnel( if ((addrs_length_in_bytes == 4) || (addrs_length_in_bytes == 20)) { - in_addr = *((in_addr_t*)create_tunnel_req_pP->sgw_addr[i].buffer); + in_addr = *((in_addr_t *)create_tunnel_req_pP->sgw_addr[i].buffer); ip_offset = 4; gtpv1u_ue_data_p->bearers[eps_bearer_id - GTPV1U_BEARER_OFFSET].sgw_ip_addr = in_addr; } @@ -688,7 +647,6 @@ gtpv1u_create_s1u_tunnel( gtpv1u_ue_data_p->bearers[eps_bearer_id - GTPV1U_BEARER_OFFSET].teid_sgw = create_tunnel_req_pP->sgw_S1u_teid[i]; gtpv1u_ue_data_p->num_bearers++; create_tunnel_resp_pP->enb_S1u_teid[i] = s1u_teid; - } else { create_tunnel_resp_pP->enb_S1u_teid[i] = 0; create_tunnel_resp_pP->status = 0xFF; @@ -696,11 +654,10 @@ gtpv1u_create_s1u_tunnel( create_tunnel_resp_pP->eps_bearer_id[i] = eps_bearer_id; create_tunnel_resp_pP->num_tunnels += 1; - //----------------------- // GTPV1U->PDCP mapping //----------------------- - hash_rc = hashtable_get(RC.gtpv1u_data_g->teid_mapping, s1u_teid, (void**)>pv1u_teid_data_p); + hash_rc = hashtable_get(RC.gtpv1u_data_g->teid_mapping, s1u_teid, (void **)>pv1u_teid_data_p); if (hash_rc == HASH_TABLE_KEY_NOT_EXISTS) { gtpv1u_teid_data_p = calloc (1, sizeof(gtpv1u_teid_data_t)); @@ -714,14 +671,14 @@ gtpv1u_create_s1u_tunnel( create_tunnel_resp_pP->status = 0xFF; } } - MSC_LOG_TX_MESSAGE( - MSC_GTPU_ENB, - MSC_RRC_ENB, - NULL,0, - "0 GTPV1U_ENB_CREATE_TUNNEL_RESP rnti %x teid %x", - create_tunnel_resp_pP->rnti, - s1u_teid); + MSC_LOG_TX_MESSAGE( + MSC_GTPU_ENB, + MSC_RRC_ENB, + NULL,0, + "0 GTPV1U_ENB_CREATE_TUNNEL_RESP rnti %x teid %x", + create_tunnel_resp_pP->rnti, + s1u_teid); LOG_D(GTPU, "Tx GTPV1U_ENB_CREATE_TUNNEL_RESP ue rnti %x status %d\n", create_tunnel_req_pP->rnti, create_tunnel_resp_pP->status); @@ -729,12 +686,10 @@ gtpv1u_create_s1u_tunnel( } int gtpv1u_update_s1u_tunnel( - const instance_t instanceP, - const gtpv1u_enb_create_tunnel_req_t * const create_tunnel_req_pP, - const rnti_t prior_rnti - ) -{ - + const instance_t instanceP, + const gtpv1u_enb_create_tunnel_req_t *const create_tunnel_req_pP, + const rnti_t prior_rnti +) { /* Local tunnel end-point identifier */ teid_t s1u_teid = 0; gtpv1u_teid_data_t *gtpv1u_teid_data_p = NULL; @@ -744,12 +699,12 @@ int gtpv1u_update_s1u_tunnel( hashtable_rc_t hash_rc = HASH_TABLE_KEY_NOT_EXISTS; int i,j; uint8_t bearers_num = 0,bearers_total = 0; - //----------------------- // PDCP->GTPV1U mapping //----------------------- hash_rc = hashtable_get(RC.gtpv1u_data_g->ue_mapping, prior_rnti, (void **)>pv1u_ue_data_p); - if(hash_rc != HASH_TABLE_OK){ + + if(hash_rc != HASH_TABLE_OK) { LOG_E(GTPU,"Error get ue_mapping(rnti=%x) from GTPV1U hashtable error\n", prior_rnti); return -1; } @@ -757,65 +712,66 @@ int gtpv1u_update_s1u_tunnel( gtpv1u_ue_data_new_p = calloc (1, sizeof(gtpv1u_ue_data_t)); memcpy(gtpv1u_ue_data_new_p,gtpv1u_ue_data_p,sizeof(gtpv1u_ue_data_t)); gtpv1u_ue_data_new_p->ue_id = create_tunnel_req_pP->rnti; - hash_rc = hashtable_insert(RC.gtpv1u_data_g->ue_mapping, create_tunnel_req_pP->rnti, gtpv1u_ue_data_new_p); AssertFatal(hash_rc == HASH_TABLE_OK, "Error inserting ue_mapping in GTPV1U hashtable"); LOG_I(GTPU, "inserting ue_mapping(rnti=%x) in GTPV1U hashtable\n", - create_tunnel_req_pP->rnti); - + create_tunnel_req_pP->rnti); hash_rc = hashtable_remove(RC.gtpv1u_data_g->ue_mapping, prior_rnti); LOG_I(GTPU, "hashtable_remove ue_mapping(rnti=%x) in GTPV1U hashtable\n", - prior_rnti); + prior_rnti); //----------------------- // GTPV1U->PDCP mapping //----------------------- bearers_total =gtpv1u_ue_data_new_p->num_bearers; - for(j = 0;j<GTPV1U_MAX_BEARERS_ID;j++){ + for(j = 0; j<GTPV1U_MAX_BEARERS_ID; j++) { if(gtpv1u_ue_data_new_p->bearers[j].state != BEARER_IN_CONFIG) continue; bearers_num++; + for (i = 0; i < create_tunnel_req_pP->num_tunnels; i++) { if(j == (create_tunnel_req_pP->eps_bearer_id[i]-GTPV1U_BEARER_OFFSET)) break; } - if(i < create_tunnel_req_pP->num_tunnels){ + + if(i < create_tunnel_req_pP->num_tunnels) { s1u_teid = gtpv1u_ue_data_new_p->bearers[j].teid_eNB; - hash_rc = hashtable_get(RC.gtpv1u_data_g->teid_mapping, s1u_teid, (void**)>pv1u_teid_data_p); + hash_rc = hashtable_get(RC.gtpv1u_data_g->teid_mapping, s1u_teid, (void **)>pv1u_teid_data_p); + if (hash_rc == HASH_TABLE_OK) { gtpv1u_teid_data_p->ue_id = create_tunnel_req_pP->rnti; gtpv1u_teid_data_p->eps_bearer_id = create_tunnel_req_pP->eps_bearer_id[i]; - LOG_I(GTPU, "updata teid_mapping te_id %u (prior_rnti %x rnti %x) in GTPV1U hashtable\n", s1u_teid,prior_rnti,create_tunnel_req_pP->rnti); - }else{ + } else { LOG_W(GTPU, "Error get teid mapping(s1u_teid=%u) from GTPV1U hashtable", s1u_teid); } - }else{ + } else { s1u_teid = gtpv1u_ue_data_new_p->bearers[j].teid_eNB; hash_rc = hashtable_remove(RC.gtpv1u_data_g->teid_mapping, s1u_teid); if (hash_rc != HASH_TABLE_OK) { LOG_D(GTPU, "Removed user rnti %x , enb S1U teid %u not found\n", prior_rnti, s1u_teid); } + gtpv1u_ue_data_new_p->bearers[j].state = BEARER_DOWN; gtpv1u_ue_data_new_p->num_bearers--; LOG_I(GTPU, "delete teid_mapping te_id %u (rnti%x) bearer_id %d in GTPV1U hashtable\n", s1u_teid,prior_rnti,j+GTPV1U_BEARER_OFFSET);; } + if(bearers_num > bearers_total) break; } - return 0; + return 0; } //----------------------------------------------------------------------------- -static int gtpv1u_delete_s1u_tunnel( +int gtpv1u_delete_s1u_tunnel( const instance_t instanceP, - const gtpv1u_enb_delete_tunnel_req_t * const req_pP) -{ + const gtpv1u_enb_delete_tunnel_req_t *const req_pP) { NwGtpv1uUlpApiT stack_req; NwGtpv1uRcT rc = NW_GTPV1U_FAILURE; MessageDef *message_p = NULL; @@ -823,22 +779,16 @@ static int gtpv1u_delete_s1u_tunnel( hashtable_rc_t hash_rc = HASH_TABLE_KEY_NOT_EXISTS; teid_t teid_eNB = 0; int erab_index = 0; - message_p = itti_alloc_new_message(TASK_GTPV1_U, GTPV1U_ENB_DELETE_TUNNEL_RESP); - GTPV1U_ENB_DELETE_TUNNEL_RESP(message_p).rnti = req_pP->rnti; GTPV1U_ENB_DELETE_TUNNEL_RESP(message_p).status = 0; - - - hash_rc = hashtable_get(RC.gtpv1u_data_g->ue_mapping, req_pP->rnti, (void**)>pv1u_ue_data_p); + hash_rc = hashtable_get(RC.gtpv1u_data_g->ue_mapping, req_pP->rnti, (void **)>pv1u_ue_data_p); if (hash_rc == HASH_TABLE_OK) { - for (erab_index = 0; erab_index < req_pP->num_erab; erab_index++) { teid_eNB = gtpv1u_ue_data_p->bearers[req_pP->eps_bearer_id[erab_index] - GTPV1U_BEARER_OFFSET].teid_eNB; LOG_D(GTPU, "Rx GTPV1U_ENB_DELETE_TUNNEL user rnti %x eNB S1U teid %u eps bearer id %u\n", req_pP->rnti, teid_eNB, req_pP->eps_bearer_id[erab_index]); - { memset(&stack_req, 0, sizeof(NwGtpv1uUlpApiT)); stack_req.apiType = NW_GTPV1U_ULP_API_DESTROY_TUNNEL_ENDPOINT; @@ -846,7 +796,6 @@ static int gtpv1u_delete_s1u_tunnel( req_pP->eps_bearer_id[erab_index], teid_eNB); stack_req.apiInfo.destroyTunnelEndPointInfo.hStackSessionHandle = gtpv1u_ue_data_p->bearers[req_pP->eps_bearer_id[erab_index] - GTPV1U_BEARER_OFFSET].teid_eNB_stack_session; - rc = nwGtpv1uProcessUlpReq(RC.gtpv1u_data_g->gtpv1u_stack, &stack_req); LOG_D(GTPU, ".\n"); } @@ -881,36 +830,30 @@ static int gtpv1u_delete_s1u_tunnel( } }// else silently do nothing - LOG_D(GTPU, "Tx GTPV1U_ENB_DELETE_TUNNEL_RESP user rnti %x eNB S1U teid %u status %u\n", GTPV1U_ENB_DELETE_TUNNEL_RESP(message_p).rnti, GTPV1U_ENB_DELETE_TUNNEL_RESP(message_p).enb_S1u_teid, GTPV1U_ENB_DELETE_TUNNEL_RESP(message_p).status); - MSC_LOG_TX_MESSAGE( - MSC_GTPU_ENB, - MSC_RRC_ENB, - NULL,0, - "0 GTPV1U_ENB_DELETE_TUNNEL_RESP rnti %x teid %x", - GTPV1U_ENB_DELETE_TUNNEL_RESP(message_p).rnti, - teid_eNB); - + MSC_GTPU_ENB, + MSC_RRC_ENB, + NULL,0, + "0 GTPV1U_ENB_DELETE_TUNNEL_RESP rnti %x teid %x", + GTPV1U_ENB_DELETE_TUNNEL_RESP(message_p).rnti, + teid_eNB); return itti_send_msg_to_task(TASK_RRC_ENB, instanceP, message_p); } //----------------------------------------------------------------------------- -int gtpv1u_eNB_init(void) -{ +int gtpv1u_eNB_init(void) { NwGtpv1uRcT rc = NW_GTPV1U_FAILURE; NwGtpv1uUlpEntityT ulp; NwGtpv1uUdpEntityT udp; NwGtpv1uLogMgrEntityT log; NwGtpv1uTimerMgrEntityT tmr; - // enb_properties_p = enb_config_get()->properties[0]; - RC.gtpv1u_data_g = (gtpv1u_data_t*)calloc(sizeof(gtpv1u_data_t),1); - + RC.gtpv1u_data_g = (gtpv1u_data_t *)calloc(sizeof(gtpv1u_data_t),1); LOG_I(GTPU, "Initializing GTPU stack %p\n",&RC.gtpv1u_data_g); //gtpv1u_data_g.gtpv1u_stack; /* Initialize UE hashtable */ @@ -918,8 +861,7 @@ int gtpv1u_eNB_init(void) AssertFatal(RC.gtpv1u_data_g->ue_mapping != NULL, " ERROR Initializing TASK_GTPV1_U task interface: in hashtable_create returned %p\n", RC.gtpv1u_data_g->ue_mapping); RC.gtpv1u_data_g->teid_mapping = hashtable_create (256, NULL, NULL); AssertFatal(RC.gtpv1u_data_g->teid_mapping != NULL, " ERROR Initializing TASK_GTPV1_U task interface: in hashtable_create\n"); -// RC.gtpv1u_data_g.enb_ip_address_for_S1u_S12_S4_up = enb_properties_p->enb_ipv4_address_for_S1U; - + // RC.gtpv1u_data_g.enb_ip_address_for_S1u_S12_S4_up = enb_properties_p->enb_ipv4_address_for_S1U; //gtpv1u_data_g.udp_data; RC.gtpv1u_data_g->seq_num = 0; RC.gtpv1u_data_g->restart_counter = 0; @@ -936,7 +878,6 @@ int gtpv1u_eNB_init(void) return -1; } - /* Set the ULP API callback. Called once message have been processed by the * nw-gtpv1u stack. */ @@ -983,30 +924,26 @@ int gtpv1u_eNB_init(void) } #endif - LOG_D(GTPU, "Initializing GTPV1U interface for eNB: DONE\n"); return 0; } //----------------------------------------------------------------------------- void *gtpv1u_eNB_process_itti_msg(void *notUsed) { - /* Trying to fetch a message from the message queue. - * If the queue is empty, this function will block till a - * message is sent to the task. - */ - instance_t instance; - MessageDef *received_message_p = NULL; - int rc = 0; - - itti_receive_msg(TASK_GTPV1_U, &received_message_p); - VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_GTPV1U_ENB_TASK, VCD_FUNCTION_IN); - DevAssert(received_message_p != NULL); - - instance = ITTI_MSG_INSTANCE(received_message_p); - //msg_name_p = ITTI_MSG_NAME(received_message_p); - - switch (ITTI_MSG_ID(received_message_p)) { - + /* Trying to fetch a message from the message queue. + * If the queue is empty, this function will block till a + * message is sent to the task. + */ + instance_t instance; + MessageDef *received_message_p = NULL; + int rc = 0; + itti_receive_msg(TASK_GTPV1_U, &received_message_p); + VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_GTPV1U_ENB_TASK, VCD_FUNCTION_IN); + DevAssert(received_message_p != NULL); + instance = ITTI_MSG_INSTANCE(received_message_p); + //msg_name_p = ITTI_MSG_NAME(received_message_p); + + switch (ITTI_MSG_ID(received_message_p)) { case GTPV1U_ENB_S1_REQ: gtpv1u_s1_req(instance, &received_message_p->ittiMsg.gtpv1uS1Req); @@ -1037,17 +974,14 @@ void *gtpv1u_eNB_process_itti_msg(void *notUsed) { gtpv1u_ue_data_t *gtpv1u_ue_data_p = NULL; teid_t enb_s1u_teid = 0; teid_t sgw_s1u_teid = 0; - VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_GTPV1U_PROCESS_TUNNEL_DATA_REQ, VCD_FUNCTION_IN); data_req_p = >PV1U_ENB_TUNNEL_DATA_REQ(received_message_p); //ipv4_send_data(ipv4_data_p->sd, data_ind_p->buffer, data_ind_p->length); - #if defined(GTP_DUMP_SOCKET) && GTP_DUMP_SOCKET > 0 gtpv1u_eNB_write_dump_socket(&data_req_p->buffer[data_req_p->offset],data_req_p->length); #endif memset(&stack_req, 0, sizeof(NwGtpv1uUlpApiT)); - - hash_rc = hashtable_get(RC.gtpv1u_data_g->ue_mapping, (uint64_t)data_req_p->rnti, (void**)>pv1u_ue_data_p); + hash_rc = hashtable_get(RC.gtpv1u_data_g->ue_mapping, (uint64_t)data_req_p->rnti, (void **)>pv1u_ue_data_p); if (hash_rc == HASH_TABLE_KEY_NOT_EXISTS) { LOG_E(GTPU, "nwGtpv1uProcessUlpReq failed: while getting ue rnti %x in hashtable ue_mapping\n", data_req_p->rnti); @@ -1058,7 +992,6 @@ void *gtpv1u_eNB_process_itti_msg(void *notUsed) { stack_req.apiType = NW_GTPV1U_ULP_API_SEND_TPDU; stack_req.apiInfo.sendtoInfo.teid = sgw_s1u_teid; stack_req.apiInfo.sendtoInfo.ipAddr = gtpv1u_ue_data_p->bearers[data_req_p->rab_id - GTPV1U_BEARER_OFFSET].sgw_ip_addr; - rc = nwGtpv1uGpduMsgNew( RC.gtpv1u_data_g->gtpv1u_stack, sgw_s1u_teid, @@ -1072,7 +1005,7 @@ void *gtpv1u_eNB_process_itti_msg(void *notUsed) { if (rc != NW_GTPV1U_OK) { LOG_E(GTPU, "nwGtpv1uGpduMsgNew failed: 0x%x\n", rc); MSC_LOG_EVENT(MSC_GTPU_ENB,"0 Failed send G-PDU ltid %u rtid %u size %u", - enb_s1u_teid,sgw_s1u_teid,data_req_p->length); + enb_s1u_teid,sgw_s1u_teid,data_req_p->length); (void)enb_s1u_teid; /* avoid gcc warning "set but not used" */ } else { rc = nwGtpv1uProcessUlpReq(RC.gtpv1u_data_g->gtpv1u_stack, &stack_req); @@ -1080,19 +1013,18 @@ void *gtpv1u_eNB_process_itti_msg(void *notUsed) { if (rc != NW_GTPV1U_OK) { LOG_E(GTPU, "nwGtpv1uProcessUlpReq failed: 0x%x\n", rc); MSC_LOG_EVENT(MSC_GTPU_ENB,"0 Failed send G-PDU ltid %u rtid %u size %u", - enb_s1u_teid,sgw_s1u_teid,data_req_p->length); + enb_s1u_teid,sgw_s1u_teid,data_req_p->length); } else { - MSC_LOG_TX_MESSAGE( - MSC_GTPU_ENB, - MSC_GTPU_SGW, - NULL, - 0, - MSC_AS_TIME_FMT" G-PDU ltid %u rtid %u size %u", - 0,0, - enb_s1u_teid, - sgw_s1u_teid, - data_req_p->length); - + MSC_LOG_TX_MESSAGE( + MSC_GTPU_ENB, + MSC_GTPU_SGW, + NULL, + 0, + MSC_AS_TIME_FMT" G-PDU ltid %u rtid %u size %u", + 0,0, + enb_s1u_teid, + sgw_s1u_teid, + data_req_p->length); } rc = nwGtpv1uMsgDelete(RC.gtpv1u_data_g->gtpv1u_stack, @@ -1113,11 +1045,11 @@ void *gtpv1u_eNB_process_itti_msg(void *notUsed) { case TERMINATE_MESSAGE: { if (RC.gtpv1u_data_g->ue_mapping != NULL) { - hashtable_destroy (RC.gtpv1u_data_g->ue_mapping); + hashtable_destroy (&(RC.gtpv1u_data_g->ue_mapping)); } if (RC.gtpv1u_data_g->teid_mapping != NULL) { - hashtable_destroy (RC.gtpv1u_data_g->teid_mapping); + hashtable_destroy (&(RC.gtpv1u_data_g->teid_mapping)); } LOG_W(GTPU, " *** Exiting GTPU thread\n"); @@ -1135,21 +1067,18 @@ void *gtpv1u_eNB_process_itti_msg(void *notUsed) { ITTI_MSG_NAME(received_message_p)); } break; - } - - rc = itti_free(ITTI_MSG_ORIGIN_ID(received_message_p), received_message_p); - AssertFatal(rc == EXIT_SUCCESS, "Failed to free memory (%d)!\n", rc); - received_message_p = NULL; - VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_GTPV1U_ENB_TASK, VCD_FUNCTION_OUT); + } - return NULL; + rc = itti_free(ITTI_MSG_ORIGIN_ID(received_message_p), received_message_p); + AssertFatal(rc == EXIT_SUCCESS, "Failed to free memory (%d)!\n", rc); + received_message_p = NULL; + VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_GTPV1U_ENB_TASK, VCD_FUNCTION_OUT); + return NULL; } //----------------------------------------------------------------------------- -void *gtpv1u_eNB_task(void *args) -{ +void *gtpv1u_eNB_task(void *args) { int rc = 0; - rc = gtpv1u_eNB_init(); AssertFatal(rc == 0, "gtpv1u_eNB_init Failed"); itti_mark_task_ready(TASK_GTPV1_U); diff --git a/openair3/GTPV1-U/gtpv1u_task.c b/openair3/GTPV1-U/gtpv1u_task.c index e821885ab5198055484b183f12eef1411b243b9a..1339839cf971edd203f2e9100a769a7b4df9ac26 100644 --- a/openair3/GTPV1-U/gtpv1u_task.c +++ b/openair3/GTPV1-U/gtpv1u_task.c @@ -95,7 +95,7 @@ void gtpu_print_hex_octets(unsigned char* dataP, unsigned long sizeP) h = tv.tv_sec/3600/24; m = (tv.tv_sec / 60) % 60; s = tv.tv_sec % 60; - snprintf(timeofday, 64, "%02d:%02d:%02d.%06d", h,m,s,tv.tv_usec); + snprintf(timeofday, 64, "%02u:%02u:%02u.%06d", h,m,s,tv.tv_usec); GTPU_DEBUG("%s------+-------------------------------------------------|\n",timeofday); GTPU_DEBUG("%s | 0 1 2 3 4 5 6 7 8 9 a b c d e f |\n",timeofday); @@ -116,7 +116,7 @@ void gtpu_print_hex_octets(unsigned char* dataP, unsigned long sizeP) buffer_marker = 0; } - buffer_marker+=snprintf(>pu_2_print_buffer[buffer_marker], GTPU_2_PRINT_BUFFER_LEN - buffer_marker, " %04ld |", octet_index); + buffer_marker+=snprintf(>pu_2_print_buffer[buffer_marker], GTPU_2_PRINT_BUFFER_LEN - buffer_marker, " %04lu |", octet_index); } /* diff --git a/openair3/GTPV1-U/nw-gtpv1u/src/NwGtpv1u.c b/openair3/GTPV1-U/nw-gtpv1u/src/NwGtpv1u.c index eb27189a6133b6785b43c5539e11d09573d57ed8..3e8da5d015faa56051c35f48185908137d81afeb 100644 --- a/openair3/GTPV1-U/nw-gtpv1u/src/NwGtpv1u.c +++ b/openair3/GTPV1-U/nw-gtpv1u/src/NwGtpv1u.c @@ -689,9 +689,9 @@ nwGtpv1uInitialize( NW_INOUT NwGtpv1uStackHandleT *hGtpuStackHandle, uint32_t st NwGtpv1uStackT *thiz; thiz = (NwGtpv1uStackT *) malloc( sizeof(NwGtpv1uStackT)); - memset(thiz, 0, sizeof(NwGtpv1uStackT)); if(thiz) { + memset(thiz, 0, sizeof(NwGtpv1uStackT)); thiz->id = (NwPtrT)thiz; thiz->stackType = stackType; thiz->seq = (uint16_t) ((uintptr_t)thiz) ; // FIXME interesting casts... don't know what this is good for... @@ -892,6 +892,11 @@ nwGtpv1uProcessUdpReq( NW_IN NwGtpv1uStackHandleT hGtpuStackHandle, ret = nwGtpv1uProcessGpdu(thiz, udpData, udpDataLen, peerIp); break; + case NW_GTP_END_MARKER: + GTPU_DEBUG("NW_GTP_END_MARKER\n"); + ret = NW_GTPV1U_OK; + break; + default: ret = NW_GTPV1U_FAILURE; NW_ASSERT(0); diff --git a/openair3/GTPV1-U/nw-gtpv1u/test-app/nw-helloworld/NwMiniLogMgrEntity.h b/openair3/GTPV1-U/nw-gtpv1u/test-app/nw-helloworld/NwMiniLogMgrEntity.h index ffa9c0c85e7814932729a92baf2727472d804896..8f2908e52aa182f11d8067d4c005addf4f01f778 100644 --- a/openair3/GTPV1-U/nw-gtpv1u/test-app/nw-helloworld/NwMiniLogMgrEntity.h +++ b/openair3/GTPV1-U/nw-gtpv1u/test-app/nw-helloworld/NwMiniLogMgrEntity.h @@ -32,7 +32,7 @@ extern uint32_t g_log_level; { \ char _logStr[1024]; \ snprintf(_logStr, 1024, __VA_ARGS__); \ - printf("NWGTPv2U-APP %s - %s <%s,%u>\n", gLogLevelStr[_logLevel], _logStr, basename(__FILE__), __LINE__);\ + printf("NWGTPv2U-APP %s - %s <%s,%d>\n", gLogLevelStr[_logLevel], _logStr, basename(__FILE__), __LINE__);\ } \ } while(0) diff --git a/openair3/GTPV1-U/nw-gtpv1u/test-app/nw-helloworld/NwMiniTmrMgrEntity.c b/openair3/GTPV1-U/nw-gtpv1u/test-app/nw-helloworld/NwMiniTmrMgrEntity.c index f6102d52508057c7e9f24de0c3bc63bb2beba1d8..63ad59b23f82b5cd731305a8c1258b48efe5cd37 100644 --- a/openair3/GTPV1-U/nw-gtpv1u/test-app/nw-helloworld/NwMiniTmrMgrEntity.c +++ b/openair3/GTPV1-U/nw-gtpv1u/test-app/nw-helloworld/NwMiniTmrMgrEntity.c @@ -64,8 +64,8 @@ NwGtpv1uRcT nwTimerStart( NwGtpv1uTimerMgrHandleT tmrMgrHandle, struct timeval tv; NW_LOG(NW_LOG_LEVEL_INFO, - "Received start timer request from stack with timer type %u, arg %x, for %u sec and %u usec", - tmrType, timeoutArg, timeoutSec, timeoutUsec); + "Received start timer request from stack with timer type %d , arg %x, for %d sec and %d usec", + tmrType, (unsigned int)timeoutArg, timeoutSec, timeoutUsec); pTmr = (NwMiniTmrMgrEntityT *) malloc (sizeof(NwMiniTmrMgrEntityT)); @@ -90,7 +90,7 @@ NwGtpv1uRcT nwTimerStop( NwGtpv1uTimerMgrHandleT tmrMgrHandle, NwGtpv1uTimerHandleT hTmr) { NW_LOG(NW_LOG_LEVEL_INFO, - "Received stop timer request from stack for timer handle %u", hTmr); + "Received stop timer request from stack for timer handle %d", hTmr); evtimer_del(&(((NwMiniTmrMgrEntityT *)hTmr)->ev)); free((void *)hTmr); return NW_GTPV1U_OK; diff --git a/openair3/NAS/COMMON/UTIL/tst/timer.c b/openair3/NAS/COMMON/UTIL/tst/timer.c index 701c878f4de3f5cd728109d20c9d928de44e31c7..2215bcee2d1ff2241f50be34712072be4afecdee 100644 --- a/openair3/NAS/COMMON/UTIL/tst/timer.c +++ b/openair3/NAS/COMMON/UTIL/tst/timer.c @@ -96,7 +96,7 @@ int main (int argc, const char* argv[]) /* Start NB_TIMERS_MAX timers to expire at time interval of 1s */ for (int i=0; i < NB_TIMERS_MAX; i++) { if (_start(&timer[i], i) != RETURNok) { - printf("ERROR: timer_start(i=%u) failed\n", i); + printf("ERROR: timer_start(i=%d) failed\n", i); } } diff --git a/openair3/NAS/TEST/NETWORK/network_simulator.c b/openair3/NAS/TEST/NETWORK/network_simulator.c index 294241a3845fbf6d663daad85365a16d707d6c34..461f701f95181d08a1c8cd2cb4a6a6de7dc33f8e 100644 --- a/openair3/NAS/TEST/NETWORK/network_simulator.c +++ b/openair3/NAS/TEST/NETWORK/network_simulator.c @@ -319,7 +319,7 @@ int main (int argc, const char* argv[]) _network_simulator_msg_sent += 1; } - printf("\nINFO\t: %d messages received, %d messages sent\n", + printf("\nINFO\t: %u messages received, %u messages sent\n", _network_simulator_msg_recv, _network_simulator_msg_sent); } diff --git a/openair3/NAS/TEST/USER/user_simulator.c b/openair3/NAS/TEST/USER/user_simulator.c index fa015df30af33599815c5341059ba2a831716964..1c429c3b8508c1b766d0c27a0d1289d3d2edb8a7 100644 --- a/openair3/NAS/TEST/USER/user_simulator.c +++ b/openair3/NAS/TEST/USER/user_simulator.c @@ -143,7 +143,7 @@ int main (int argc, const char* argv[]) } printf("INFO\t: The User Simulator is now connected to %s (%d)\n", - devpath, USER_GETFD()); + devpath, (int)USER_GETFD()); } else { /* Initialize network socket handlers */ _user_simulator_id.open = socket_udp_open; @@ -163,7 +163,7 @@ int main (int argc, const char* argv[]) } printf("INFO\t: The User Simulator is now connected to %s/%s (%d)\n", - host, port, USER_GETFD()); + host, port, (int)USER_GETFD()); } @@ -231,7 +231,7 @@ int main (int argc, const char* argv[]) /* * Termination cleanup */ - printf("INFO\t: Closing user endpoint descriptor %d\n", USER_GETFD()); + printf("INFO\t: Closing user endpoint descriptor %d\n", (int)USER_GETFD()); USER_CLOSE(); printf("INFO\t: User simulator exited\n"); @@ -282,7 +282,7 @@ static int _set_signal_handler(int signal, void (handler)(int)) static void _signal_handler(int signal_number) { printf("\nWARNING\t: Signal %d received\n", signal_number); - printf("INFO\t: Closing user socket %d\n", USER_GETFD()); + printf("INFO\t: Closing user socket %d\n", (int)USER_GETFD()); USER_CLOSE(); printf("INFO\t: User simulator exited\n"); exit(EXIT_SUCCESS); diff --git a/openair3/NAS/UE/API/USER/at_response.c b/openair3/NAS/UE/API/USER/at_response.c index a488aa78d9f7c949564c3553150e040b36981fa8..859db90d7e0d5393045771260e30b35f968e7484 100644 --- a/openair3/NAS/UE/API/USER/at_response.c +++ b/openair3/NAS/UE/API/USER/at_response.c @@ -88,41 +88,41 @@ static int _at_response_encode_cgev (char* buffer, const at_response_t* data); typedef int (*_at_response_encode_function_t) (char* buffer, const at_response_t*); static _at_response_encode_function_t _at_response_encode_function[AT_RESPONSE_ID_MAX] = { - NULL, - _at_response_encode_cgsn, /* CGSN */ - _at_response_encode_cgmi, /* CGMI */ - _at_response_encode_cgmm, /* CGMM */ - _at_response_encode_cgmr, /* CGMR */ - _at_response_encode_cimi, /* CIMI */ - _at_response_encode_cfun, /* CFUN */ - _at_response_encode_cpin, /* CPIN */ - _at_response_encode_csq, /* CSQ */ - _at_response_encode_cesq, /* CESQ */ - _at_response_encode_clac, /* CLAC */ - _at_response_encode_cmee, /* CMEE */ - _at_response_encode_cnum, /* CNUM */ - _at_response_encode_clck, /* CLCK */ - _at_response_encode_cops, /* COPS */ - _at_response_encode_creg, /* CREG */ - _at_response_encode_cgatt, /* CGATT */ - _at_response_encode_cgreg, /* CGREG */ - _at_response_encode_cereg, /* CEREG */ - _at_response_encode_cgdcont, /* CGDCONT */ - _at_response_encode_cgact, /* CGACT */ - _at_response_encode_cgpaddr, /* CGPADDR */ - _at_response_encode_cgev, /* CGEV: unsolicited result */ + NULL, + _at_response_encode_cgsn, /* CGSN */ + _at_response_encode_cgmi, /* CGMI */ + _at_response_encode_cgmm, /* CGMM */ + _at_response_encode_cgmr, /* CGMR */ + _at_response_encode_cimi, /* CIMI */ + _at_response_encode_cfun, /* CFUN */ + _at_response_encode_cpin, /* CPIN */ + _at_response_encode_csq, /* CSQ */ + _at_response_encode_cesq, /* CESQ */ + _at_response_encode_clac, /* CLAC */ + _at_response_encode_cmee, /* CMEE */ + _at_response_encode_cnum, /* CNUM */ + _at_response_encode_clck, /* CLCK */ + _at_response_encode_cops, /* COPS */ + _at_response_encode_creg, /* CREG */ + _at_response_encode_cgatt, /* CGATT */ + _at_response_encode_cgreg, /* CGREG */ + _at_response_encode_cereg, /* CEREG */ + _at_response_encode_cgdcont, /* CGDCONT */ + _at_response_encode_cgact, /* CGACT */ + _at_response_encode_cgpaddr, /* CGPADDR */ + _at_response_encode_cgev, /* CGEV: unsolicited result */ }; /* String representation of Packet Domain events (cf. network_pdn_state_t) */ static const char* _at_response_event_str[] = { - "UNKNOWN EVENT", - "ME PDN ACT", - "NW PDN DEACT", - "ME PDN DEACT", - "NW ACT", - "ME ACT", - "NW DEACT", - "ME DEACT", + "UNKNOWN EVENT", + "ME PDN ACT", + "NW PDN DEACT", + "ME PDN DEACT", + "NW ACT", + "ME ACT", + "NW DEACT", + "ME DEACT", }; /****************************************************************************/ @@ -147,24 +147,24 @@ static const char* _at_response_event_str[] = { ***************************************************************************/ int at_response_encode(char* buffer, const at_response_t* at_response) { - LOG_FUNC_IN; + LOG_FUNC_IN; - int bytes = RETURNerror; - _at_response_encode_function_t encode; + int bytes = RETURNerror; + _at_response_encode_function_t encode; - if (at_response->id < AT_RESPONSE_ID_MAX) { - /* Call encoding function applicable to the AT command response */ - encode = _at_response_encode_function[at_response->id]; + if (at_response->id < AT_RESPONSE_ID_MAX) { + /* Call encoding function applicable to the AT command response */ + encode = _at_response_encode_function[at_response->id]; - if (encode != NULL) { - bytes = (*encode)(buffer, at_response); - } else { - /* Generic encoding: OK, ERROR */ - bytes = 0; + if (encode != NULL) { + bytes = (*encode)(buffer, at_response); + } else { + /* Generic encoding: OK, ERROR */ + bytes = 0; + } } - } - LOG_FUNC_RETURN (bytes); + LOG_FUNC_RETURN (bytes); } /****************************************************************************/ @@ -188,21 +188,21 @@ int at_response_encode(char* buffer, const at_response_t* at_response) ***************************************************************************/ static int _at_response_encode_cgsn(char* buffer, const at_response_t* data) { - LOG_FUNC_IN; + LOG_FUNC_IN; - int offset = 0; + int offset = 0; - if (data->type == AT_COMMAND_ACT) { - const at_cgsn_resp_t * cgsn = &(data->response.cgsn); + if (data->type == AT_COMMAND_ACT) { + const at_cgsn_resp_t * cgsn = &(data->response.cgsn); - if (at_response_format_v1) { - offset += sprintf(buffer, "\r\n"); - } + if (at_response_format_v1) { + offset += sprintf(buffer, "\r\n"); + } - offset += sprintf(buffer+offset, "+CGSN: %s\r\n", cgsn->sn); - } + offset += sprintf(buffer+offset, "+CGSN: %s\r\n", cgsn->sn); + } - LOG_FUNC_RETURN (offset); + LOG_FUNC_RETURN (offset); } /**************************************************************************** @@ -222,21 +222,21 @@ static int _at_response_encode_cgsn(char* buffer, const at_response_t* data) ***************************************************************************/ static int _at_response_encode_cgmi(char* buffer, const at_response_t* data) { - LOG_FUNC_IN; + LOG_FUNC_IN; - int offset = 0; + int offset = 0; - if (data->type == AT_COMMAND_ACT) { - const at_cgmi_resp_t * cgmi = &(data->response.cgmi); + if (data->type == AT_COMMAND_ACT) { + const at_cgmi_resp_t * cgmi = &(data->response.cgmi); - if (at_response_format_v1) { - offset += sprintf(buffer, "\r\n"); - } + if (at_response_format_v1) { + offset += sprintf(buffer, "\r\n"); + } - offset += sprintf(buffer+offset, "+CGMI: %s\r\n", cgmi->manufacturer); - } + offset += sprintf(buffer+offset, "+CGMI: %s\r\n", cgmi->manufacturer); + } - LOG_FUNC_RETURN (offset); + LOG_FUNC_RETURN (offset); } /**************************************************************************** @@ -256,21 +256,21 @@ static int _at_response_encode_cgmi(char* buffer, const at_response_t* data) ***************************************************************************/ static int _at_response_encode_cgmm(char* buffer, const at_response_t* data) { - LOG_FUNC_IN; + LOG_FUNC_IN; - int offset = 0; + int offset = 0; - if (data->type == AT_COMMAND_ACT) { - const at_cgmm_resp_t * cgmm = &(data->response.cgmm); + if (data->type == AT_COMMAND_ACT) { + const at_cgmm_resp_t * cgmm = &(data->response.cgmm); - if (at_response_format_v1) { - offset += sprintf(buffer, "\r\n"); - } + if (at_response_format_v1) { + offset += sprintf(buffer, "\r\n"); + } - offset += sprintf(buffer+offset, "+CGMM: %s\r\n", cgmm->model); - } + offset += sprintf(buffer+offset, "+CGMM: %s\r\n", cgmm->model); + } - LOG_FUNC_RETURN (offset); + LOG_FUNC_RETURN (offset); } /**************************************************************************** @@ -290,21 +290,21 @@ static int _at_response_encode_cgmm(char* buffer, const at_response_t* data) ***************************************************************************/ static int _at_response_encode_cgmr(char* buffer, const at_response_t* data) { - LOG_FUNC_IN; + LOG_FUNC_IN; - int offset = 0; + int offset = 0; - if (data->type == AT_COMMAND_ACT) { - const at_cgmr_resp_t * cgmr = &(data->response.cgmr); + if (data->type == AT_COMMAND_ACT) { + const at_cgmr_resp_t * cgmr = &(data->response.cgmr); - if (at_response_format_v1) { - offset += sprintf(buffer, "\r\n"); - } + if (at_response_format_v1) { + offset += sprintf(buffer, "\r\n"); + } - offset += sprintf(buffer+offset, "+CGMR: %s\r\n", cgmr->revision); - } + offset += sprintf(buffer+offset, "+CGMR: %s\r\n", cgmr->revision); + } - LOG_FUNC_RETURN (offset); + LOG_FUNC_RETURN (offset); } /**************************************************************************** @@ -324,21 +324,21 @@ static int _at_response_encode_cgmr(char* buffer, const at_response_t* data) ***************************************************************************/ static int _at_response_encode_cimi(char* buffer, const at_response_t* data) { - LOG_FUNC_IN; + LOG_FUNC_IN; - int offset = 0; + int offset = 0; - if (data->type == AT_COMMAND_ACT) { - const at_cimi_resp_t * cimi = &(data->response.cimi); + if (data->type == AT_COMMAND_ACT) { + const at_cimi_resp_t * cimi = &(data->response.cimi); - if (at_response_format_v1) { - offset += sprintf(buffer, "\r\n"); - } + if (at_response_format_v1) { + offset += sprintf(buffer, "\r\n"); + } - offset += sprintf(buffer+offset, "+CIMI: %s\r\n", cimi->IMSI); - } + offset += sprintf(buffer+offset, "+CIMI: %s\r\n", cimi->IMSI); + } - LOG_FUNC_RETURN (offset); + LOG_FUNC_RETURN (offset); } /**************************************************************************** @@ -358,27 +358,27 @@ static int _at_response_encode_cimi(char* buffer, const at_response_t* data) ***************************************************************************/ static int _at_response_encode_cfun(char* buffer, const at_response_t* data) { - LOG_FUNC_IN; + LOG_FUNC_IN; - const at_cfun_resp_t * cfun = &(data->response.cfun); - int offset = 0; + const at_cfun_resp_t * cfun = &(data->response.cfun); + int offset = 0; - if (data->type == AT_COMMAND_GET) { - if (at_response_format_v1) { - offset += sprintf(buffer, "\r\n"); - } + if (data->type == AT_COMMAND_GET) { + if (at_response_format_v1) { + offset += sprintf(buffer, "\r\n"); + } - offset += sprintf(buffer+offset, "+CFUN: %d\r\n", cfun->fun); - } else if (data->type == AT_COMMAND_TST) { - if (at_response_format_v1) { - offset += sprintf(buffer, "\r\n"); - } + offset += sprintf(buffer+offset, "+CFUN: %d\r\n", cfun->fun); + } else if (data->type == AT_COMMAND_TST) { + if (at_response_format_v1) { + offset += sprintf(buffer, "\r\n"); + } - offset += sprintf(buffer+offset, "+CFUN: (%d-%d),(%d,%d)\r\n", - AT_CFUN_MIN, AT_CFUN_MAX, AT_CFUN_NORST, AT_CFUN_RST); - } + offset += sprintf(buffer+offset, "+CFUN: (%d-%d),(%d,%d)\r\n", + AT_CFUN_MIN, AT_CFUN_MAX, AT_CFUN_NORST, AT_CFUN_RST); + } - LOG_FUNC_RETURN (offset); + LOG_FUNC_RETURN (offset); } /**************************************************************************** @@ -398,21 +398,21 @@ static int _at_response_encode_cfun(char* buffer, const at_response_t* data) ***************************************************************************/ static int _at_response_encode_cpin(char* buffer, const at_response_t* data) { - LOG_FUNC_IN; + LOG_FUNC_IN; - int offset = 0; + int offset = 0; - if (data->type == AT_COMMAND_GET) { - const at_cpin_resp_t * cpin = &(data->response.cpin); + if (data->type == AT_COMMAND_GET) { + const at_cpin_resp_t * cpin = &(data->response.cpin); - if (at_response_format_v1) { - offset += sprintf(buffer, "\r\n"); - } + if (at_response_format_v1) { + offset += sprintf(buffer, "\r\n"); + } - offset += sprintf(buffer+offset, "+CPIN: %s\r\n", cpin->code); - } + offset += sprintf(buffer+offset, "+CPIN: %s\r\n", cpin->code); + } - LOG_FUNC_RETURN (offset); + LOG_FUNC_RETURN (offset); } /**************************************************************************** @@ -432,29 +432,29 @@ static int _at_response_encode_cpin(char* buffer, const at_response_t* data) ***************************************************************************/ static int _at_response_encode_csq(char* buffer, const at_response_t* data) { - LOG_FUNC_IN; - - const at_csq_resp_t * csq = &(data->response.csq); - int offset = 0; - - if (data->type == AT_COMMAND_ACT) { - if (at_response_format_v1) { - offset += sprintf(buffer, "\r\n"); + LOG_FUNC_IN; + + const at_csq_resp_t * csq = &(data->response.csq); + int offset = 0; + + if (data->type == AT_COMMAND_ACT) { + if (at_response_format_v1) { + offset += sprintf(buffer, "\r\n"); + } + + offset += sprintf(buffer+offset, "+CSQ: %d,%d\r\n", + csq->rssi, csq->ber); + } else if (data->type == AT_COMMAND_TST) { + if (at_response_format_v1) { + offset += sprintf(buffer, "\r\n"); + } + + offset += sprintf(buffer+offset, "+CSQ: (%d-%d),(%d-%d)\r\n", + AT_CSQ_RSSI_0, AT_CSQ_RSSI_31, + AT_CSQ_BER_0, AT_CSQ_BER_7); } - offset += sprintf(buffer+offset, "+CSQ: %d,%d\r\n", - csq->rssi, csq->ber); - } else if (data->type == AT_COMMAND_TST) { - if (at_response_format_v1) { - offset += sprintf(buffer, "\r\n"); - } - - offset += sprintf(buffer+offset, "+CSQ: (%d-%d),(%d-%d)\r\n", - AT_CSQ_RSSI_0, AT_CSQ_RSSI_31, - AT_CSQ_BER_0, AT_CSQ_BER_7); - } - - LOG_FUNC_RETURN (offset); + LOG_FUNC_RETURN (offset); } /**************************************************************************** @@ -474,35 +474,35 @@ static int _at_response_encode_csq(char* buffer, const at_response_t* data) ***************************************************************************/ static int _at_response_encode_cesq(char* buffer, const at_response_t* data) { - LOG_FUNC_IN; - - const at_cesq_resp_t * cesq = &(data->response.cesq); - int offset = 0; - - if (data->type == AT_COMMAND_ACT) { - if (at_response_format_v1) { - offset += sprintf(buffer, "\r\n"); + LOG_FUNC_IN; + + const at_cesq_resp_t * cesq = &(data->response.cesq); + int offset = 0; + + if (data->type == AT_COMMAND_ACT) { + if (at_response_format_v1) { + offset += sprintf(buffer, "\r\n"); + } + + offset += sprintf(buffer+offset, "+CESQ: %d,%d,%d,%d,%d,%d\r\n", + cesq->rssi, cesq->ber, cesq->rscp, + cesq->ecno, cesq->rsrq, cesq->rsrp); + } else if (data->type == AT_COMMAND_TST) { + if (at_response_format_v1) { + offset += sprintf(buffer, "\r\n"); + } + + offset += sprintf(buffer+offset, "+CESQ: (%d-%d),(%d-%d),(%d-%d)," + "(%d-%d),(%d-%d),(%d-%d)\r\n", + AT_CESQ_RSSI_0, AT_CESQ_RSSI_31, + AT_CESQ_BER_0, AT_CESQ_BER_7, + AT_CESQ_RSCP_0, AT_CESQ_RSCP_96, + AT_CESQ_ECNO_0, AT_CESQ_ECNO_49, + AT_CESQ_RSRQ_0, AT_CESQ_RSRQ_34, + AT_CESQ_RSRP_0, AT_CESQ_RSRP_97); } - offset += sprintf(buffer+offset, "+CESQ: %d,%d,%d,%d,%d,%d\r\n", - cesq->rssi, cesq->ber, cesq->rscp, - cesq->ecno, cesq->rsrq, cesq->rsrp); - } else if (data->type == AT_COMMAND_TST) { - if (at_response_format_v1) { - offset += sprintf(buffer, "\r\n"); - } - - offset += sprintf(buffer+offset, "+CESQ: (%d-%d),(%d-%d),(%d-%d)," - "(%d-%d),(%d-%d),(%d-%d)\r\n", - AT_CESQ_RSSI_0, AT_CESQ_RSSI_31, - AT_CESQ_BER_0, AT_CESQ_BER_7, - AT_CESQ_RSCP_0, AT_CESQ_RSCP_96, - AT_CESQ_ECNO_0, AT_CESQ_ECNO_49, - AT_CESQ_RSRQ_0, AT_CESQ_RSRQ_34, - AT_CESQ_RSRP_0, AT_CESQ_RSRP_97); - } - - LOG_FUNC_RETURN (offset); + LOG_FUNC_RETURN (offset); } /**************************************************************************** @@ -522,27 +522,27 @@ static int _at_response_encode_cesq(char* buffer, const at_response_t* data) ***************************************************************************/ static int _at_response_encode_clac(char* buffer, const at_response_t* data) { - LOG_FUNC_IN; + LOG_FUNC_IN; - const at_clac_resp_t * clac = &(data->response.clac); - int offset = 0; - int i; + const at_clac_resp_t * clac = &(data->response.clac); + int offset = 0; + int i; - if (data->type == AT_COMMAND_ACT) { - if (clac->n_acs > 0) { - if (at_response_format_v1) { - offset += sprintf(buffer, "\r\n"); - } + if (data->type == AT_COMMAND_ACT) { + if (clac->n_acs > 0) { + if (at_response_format_v1) { + offset += sprintf(buffer, "\r\n"); + } - offset += sprintf(buffer+offset, "%s", clac->ac[0]); + offset += sprintf(buffer+offset, "%s", clac->ac[0]); - for (i = 1; i < clac->n_acs; i++) { - offset += sprintf(buffer+offset, "\r\n%s", clac->ac[i]); - } + for (i = 1; i < clac->n_acs; i++) { + offset += sprintf(buffer+offset, "\r\n%s", clac->ac[i]); + } + } } - } - LOG_FUNC_RETURN (offset); + LOG_FUNC_RETURN (offset); } /**************************************************************************** @@ -562,22 +562,22 @@ static int _at_response_encode_clac(char* buffer, const at_response_t* data) ***************************************************************************/ static int _at_response_encode_cnum(char* buffer, const at_response_t* data) { - LOG_FUNC_IN; + LOG_FUNC_IN; - int offset = 0; + int offset = 0; - if (data->type == AT_COMMAND_ACT) { - const at_cnum_resp_t * cnum = &(data->response.cnum); + if (data->type == AT_COMMAND_ACT) { + const at_cnum_resp_t * cnum = &(data->response.cnum); - if (at_response_format_v1) { - offset += sprintf(buffer, "\r\n"); - } + if (at_response_format_v1) { + offset += sprintf(buffer, "\r\n"); + } - offset += sprintf(buffer+offset, "+CNUM: ,%s,%u\r\n", - cnum->number, cnum->type); - } + offset += sprintf(buffer+offset, "+CNUM: ,%s,%u\r\n", + cnum->number, (unsigned int)cnum->type); + } - LOG_FUNC_RETURN (offset); + LOG_FUNC_RETURN (offset); } /**************************************************************************** @@ -597,26 +597,26 @@ static int _at_response_encode_cnum(char* buffer, const at_response_t* data) ***************************************************************************/ static int _at_response_encode_clck(char* buffer, const at_response_t* data) { - LOG_FUNC_IN; + LOG_FUNC_IN; - const at_clck_resp_t * clck = &(data->response.clck); - int offset = 0; + const at_clck_resp_t * clck = &(data->response.clck); + int offset = 0; - if (data->type == AT_COMMAND_SET) { - if (at_response_format_v1) { - offset += sprintf(buffer, "\r\n"); - } + if (data->type == AT_COMMAND_SET) { + if (at_response_format_v1) { + offset += sprintf(buffer, "\r\n"); + } - offset += sprintf(buffer+offset, "+CLCK: %d\r\n", clck->status); - } else if (data->type == AT_COMMAND_TST) { - if (at_response_format_v1) { - offset += sprintf(buffer, "\r\n"); - } + offset += sprintf(buffer+offset, "+CLCK: %d\r\n", clck->status); + } else if (data->type == AT_COMMAND_TST) { + if (at_response_format_v1) { + offset += sprintf(buffer, "\r\n"); + } - offset += sprintf(buffer+offset, "+CLCK: %s\r\n", AT_CLCK_SC); - } + offset += sprintf(buffer+offset, "+CLCK: %s\r\n", AT_CLCK_SC); + } - LOG_FUNC_RETURN (offset); + LOG_FUNC_RETURN (offset); } /**************************************************************************** @@ -636,63 +636,63 @@ static int _at_response_encode_clck(char* buffer, const at_response_t* data) ***************************************************************************/ static int _at_response_encode_cops(char* buffer, const at_response_t* data) { - LOG_FUNC_IN; - - int offset = 0; - - if (data->type == AT_COMMAND_GET) { - const at_cops_get_t * cops = &(data->response.cops.get); - - if (at_response_format_v1) { - offset += sprintf(buffer, "\r\n"); - } - - offset += sprintf(buffer+offset, "+COPS: %d", cops->mode); - - if (data->mask & AT_COPS_RESP_OPER_MASK) { - /* If <oper> is present <format> must be given */ - assert(data->mask & AT_COPS_RESP_FORMAT_MASK); - offset += sprintf(buffer+offset, ",%d", cops->format); - - if (cops->format == AT_COPS_LONG) { - offset += sprintf(buffer+offset, ",%s", - (char*)cops->plmn.id.alpha_long); - } else if (cops->format == AT_COPS_SHORT) { - offset += sprintf(buffer+offset, ",%s", - (char*)cops->plmn.id.alpha_short); - } else if (cops->format == AT_COPS_NUM) { - offset += sprintf(buffer+offset, ",%s", - (char*)cops->plmn.id.num); - } + LOG_FUNC_IN; + + int offset = 0; + + if (data->type == AT_COMMAND_GET) { + const at_cops_get_t * cops = &(data->response.cops.get); + + if (at_response_format_v1) { + offset += sprintf(buffer, "\r\n"); + } + + offset += sprintf(buffer+offset, "+COPS: %d", cops->mode); + + if (data->mask & AT_COPS_RESP_OPER_MASK) { + /* If <oper> is present <format> must be given */ + assert(data->mask & AT_COPS_RESP_FORMAT_MASK); + offset += sprintf(buffer+offset, ",%d", cops->format); + + if (cops->format == AT_COPS_LONG) { + offset += sprintf(buffer+offset, ",%s", + (char*)cops->plmn.id.alpha_long); + } else if (cops->format == AT_COPS_SHORT) { + offset += sprintf(buffer+offset, ",%s", + (char*)cops->plmn.id.alpha_short); + } else if (cops->format == AT_COPS_NUM) { + offset += sprintf(buffer+offset, ",%s", + (char*)cops->plmn.id.num); + } + } + + if (data->mask & AT_COPS_RESP_ACT_MASK) { + offset += sprintf(buffer+offset, ",%d", cops->AcT); + } + + offset += sprintf(buffer+offset, "\r\n"); + } else if (data->type == AT_COMMAND_TST) { + const at_cops_tst_t * cops = &(data->response.cops.tst); + + if (at_response_format_v1) { + offset += sprintf(buffer, "\r\n"); + } + + offset += sprintf(buffer+offset, "+COPS: "); + + /* Display the list of operators present in the network */ + strncpy(buffer+offset, cops->data, cops->size); + offset += cops->size; + + /* Display the list of supported network registration modes and + * supported representation formats of network operators */ + //offset += sprintf(buffer+offset, ",,(%d-%d),(%d,%d,%d)", + // AT_COPS_AUTO, AT_COPS_MANAUTO, + // AT_COPS_LONG, AT_COPS_SHORT, AT_COPS_NUM); + offset += sprintf(buffer+offset, "\r\n"); } - if (data->mask & AT_COPS_RESP_ACT_MASK) { - offset += sprintf(buffer+offset, ",%d", cops->AcT); - } - - offset += sprintf(buffer+offset, "\r\n"); - } else if (data->type == AT_COMMAND_TST) { - const at_cops_tst_t * cops = &(data->response.cops.tst); - - if (at_response_format_v1) { - offset += sprintf(buffer, "\r\n"); - } - - offset += sprintf(buffer+offset, "+COPS: "); - - /* Display the list of operators present in the network */ - strncpy(buffer+offset, cops->data, cops->size); - offset += cops->size; - - /* Display the list of supported network registration modes and - * supported representation formats of network operators */ - //offset += sprintf(buffer+offset, ",,(%d-%d),(%d,%d,%d)", - // AT_COPS_AUTO, AT_COPS_MANAUTO, - // AT_COPS_LONG, AT_COPS_SHORT, AT_COPS_NUM); - offset += sprintf(buffer+offset, "\r\n"); - } - - LOG_FUNC_RETURN (offset); + LOG_FUNC_RETURN (offset); } /**************************************************************************** @@ -712,28 +712,28 @@ static int _at_response_encode_cops(char* buffer, const at_response_t* data) ***************************************************************************/ static int _at_response_encode_cgatt(char* buffer, const at_response_t* data) { - LOG_FUNC_IN; + LOG_FUNC_IN; - int offset = 0; + int offset = 0; - if (data->type == AT_COMMAND_GET) { - const at_cgatt_resp_t * cgatt = &(data->response.cgatt); + if (data->type == AT_COMMAND_GET) { + const at_cgatt_resp_t * cgatt = &(data->response.cgatt); - if (at_response_format_v1) { - offset += sprintf(buffer, "\r\n"); - } + if (at_response_format_v1) { + offset += sprintf(buffer, "\r\n"); + } - offset += sprintf(buffer+offset, "+CGATT: %d\r\n", cgatt->state); - } else if (data->type == AT_COMMAND_TST) { - if (at_response_format_v1) { - offset += sprintf(buffer, "\r\n"); - } + offset += sprintf(buffer+offset, "+CGATT: %d\r\n", cgatt->state); + } else if (data->type == AT_COMMAND_TST) { + if (at_response_format_v1) { + offset += sprintf(buffer, "\r\n"); + } - offset += sprintf(buffer+offset, "+CGATT: (%d,%d)\r\n", - AT_CGATT_STATE_MIN, AT_CGATT_STATE_MAX); - } + offset += sprintf(buffer+offset, "+CGATT: (%d,%d)\r\n", + AT_CGATT_STATE_MIN, AT_CGATT_STATE_MAX); + } - LOG_FUNC_RETURN (offset); + LOG_FUNC_RETURN (offset); } /**************************************************************************** @@ -753,43 +753,43 @@ static int _at_response_encode_cgatt(char* buffer, const at_response_t* data) ***************************************************************************/ static int _at_response_encode_creg(char* buffer, const at_response_t* data) { - LOG_FUNC_IN; + LOG_FUNC_IN; - int offset = 0; + int offset = 0; - if (data->type == AT_COMMAND_GET) { - const at_creg_resp_t * creg = &(data->response.creg); + if (data->type == AT_COMMAND_GET) { + const at_creg_resp_t * creg = &(data->response.creg); - if (at_response_format_v1) { - offset += sprintf(buffer, "\r\n"); - } + if (at_response_format_v1) { + offset += sprintf(buffer, "\r\n"); + } - offset += sprintf(buffer+offset, "+CREG: %d,%d", - creg->n, creg->stat); + offset += sprintf(buffer+offset, "+CREG: %d,%d", + creg->n, creg->stat); - if (data->mask & AT_CREG_RESP_LAC_MASK) { - offset += sprintf(buffer+offset, ",%s", creg->lac); - } + if (data->mask & AT_CREG_RESP_LAC_MASK) { + offset += sprintf(buffer+offset, ",%s", creg->lac); + } - if (data->mask & AT_CREG_RESP_CI_MASK) { - offset += sprintf(buffer+offset, ",%s", creg->ci); - } + if (data->mask & AT_CREG_RESP_CI_MASK) { + offset += sprintf(buffer+offset, ",%s", creg->ci); + } - if (data->mask & AT_CREG_RESP_ACT_MASK) { - offset += sprintf(buffer+offset, ",%d", creg->AcT); - } + if (data->mask & AT_CREG_RESP_ACT_MASK) { + offset += sprintf(buffer+offset, ",%d", creg->AcT); + } - offset += sprintf(buffer+offset, "\r\n"); - } else if (data->type == AT_COMMAND_TST) { - if (at_response_format_v1) { - offset += sprintf(buffer, "\r\n"); - } + offset += sprintf(buffer+offset, "\r\n"); + } else if (data->type == AT_COMMAND_TST) { + if (at_response_format_v1) { + offset += sprintf(buffer, "\r\n"); + } - offset += sprintf(buffer+offset, "+CREG: (%d-%d)\r\n", - AT_CREG_N_MIN, AT_CREG_N_MAX); - } + offset += sprintf(buffer+offset, "+CREG: (%d-%d)\r\n", + AT_CREG_N_MIN, AT_CREG_N_MAX); + } - LOG_FUNC_RETURN (offset); + LOG_FUNC_RETURN (offset); } /**************************************************************************** @@ -809,47 +809,47 @@ static int _at_response_encode_creg(char* buffer, const at_response_t* data) ***************************************************************************/ static int _at_response_encode_cgreg(char* buffer, const at_response_t* data) { - LOG_FUNC_IN; + LOG_FUNC_IN; - int offset = 0; + int offset = 0; - if (data->type == AT_COMMAND_GET) { - const at_cgreg_resp_t * cgreg = &(data->response.cgreg); + if (data->type == AT_COMMAND_GET) { + const at_cgreg_resp_t * cgreg = &(data->response.cgreg); - if (at_response_format_v1) { - offset += sprintf(buffer, "\r\n"); - } + if (at_response_format_v1) { + offset += sprintf(buffer, "\r\n"); + } - offset += sprintf(buffer+offset, "+CGREG: %d,%d", - cgreg->n, cgreg->stat); + offset += sprintf(buffer+offset, "+CGREG: %d,%d", + cgreg->n, cgreg->stat); - if (data->mask & AT_CGREG_RESP_LAC_MASK) { - offset += sprintf(buffer+offset, ",%s", cgreg->lac); - } + if (data->mask & AT_CGREG_RESP_LAC_MASK) { + offset += sprintf(buffer+offset, ",%s", cgreg->lac); + } - if (data->mask & AT_CGREG_RESP_CI_MASK) { - offset += sprintf(buffer+offset, ",%s", cgreg->ci); - } + if (data->mask & AT_CGREG_RESP_CI_MASK) { + offset += sprintf(buffer+offset, ",%s", cgreg->ci); + } - if (data->mask & AT_CGREG_RESP_ACT_MASK) { - offset += sprintf(buffer+offset, ",%d", cgreg->AcT); - } + if (data->mask & AT_CGREG_RESP_ACT_MASK) { + offset += sprintf(buffer+offset, ",%d", cgreg->AcT); + } - if (data->mask & AT_CGREG_RESP_RAC_MASK) { - offset += sprintf(buffer+offset, ",%s", cgreg->rac); - } + if (data->mask & AT_CGREG_RESP_RAC_MASK) { + offset += sprintf(buffer+offset, ",%s", cgreg->rac); + } - offset += sprintf(buffer+offset, "\r\n"); - } else if (data->type == AT_COMMAND_TST) { - if (at_response_format_v1) { - offset += sprintf(buffer, "\r\n"); - } + offset += sprintf(buffer+offset, "\r\n"); + } else if (data->type == AT_COMMAND_TST) { + if (at_response_format_v1) { + offset += sprintf(buffer, "\r\n"); + } - offset += sprintf(buffer+offset, "+CGREG: (%d-%d)\r\n", - AT_CGREG_N_MIN, AT_CGREG_N_MAX); - } + offset += sprintf(buffer+offset, "+CGREG: (%d-%d)\r\n", + AT_CGREG_N_MIN, AT_CGREG_N_MAX); + } - LOG_FUNC_RETURN (offset); + LOG_FUNC_RETURN (offset); } /**************************************************************************** @@ -869,43 +869,43 @@ static int _at_response_encode_cgreg(char* buffer, const at_response_t* data) ***************************************************************************/ static int _at_response_encode_cereg(char* buffer, const at_response_t* data) { - LOG_FUNC_IN; + LOG_FUNC_IN; - int offset = 0; + int offset = 0; - if (data->type == AT_COMMAND_GET) { - const at_cereg_resp_t * cereg = &(data->response.cereg); + if (data->type == AT_COMMAND_GET) { + const at_cereg_resp_t * cereg = &(data->response.cereg); - if (at_response_format_v1) { - offset += sprintf(buffer, "\r\n"); - } + if (at_response_format_v1) { + offset += sprintf(buffer, "\r\n"); + } - offset += sprintf(buffer+offset, "+CEREG: %d,%d", - cereg->n, cereg->stat); + offset += sprintf(buffer+offset, "+CEREG: %d,%d", + cereg->n, cereg->stat); - if (data->mask & AT_CEREG_RESP_TAC_MASK) { - offset += sprintf(buffer+offset, ",%s", cereg->tac); - } + if (data->mask & AT_CEREG_RESP_TAC_MASK) { + offset += sprintf(buffer+offset, ",%s", cereg->tac); + } - if (data->mask & AT_CEREG_RESP_CI_MASK) { - offset += sprintf(buffer+offset, ",%s", cereg->ci); - } + if (data->mask & AT_CEREG_RESP_CI_MASK) { + offset += sprintf(buffer+offset, ",%s", cereg->ci); + } - if (data->mask & AT_CEREG_RESP_ACT_MASK) { - offset += sprintf(buffer+offset, ",%d", cereg->AcT); - } + if (data->mask & AT_CEREG_RESP_ACT_MASK) { + offset += sprintf(buffer+offset, ",%d", cereg->AcT); + } - offset += sprintf(buffer+offset, "\r\n"); - } else if (data->type == AT_COMMAND_TST) { - if (at_response_format_v1) { - offset += sprintf(buffer, "\r\n"); - } + offset += sprintf(buffer+offset, "\r\n"); + } else if (data->type == AT_COMMAND_TST) { + if (at_response_format_v1) { + offset += sprintf(buffer, "\r\n"); + } - offset += sprintf(buffer+offset, "+CEREG: (%d-%d)\r\n", - AT_CEREG_N_MIN, AT_CEREG_N_MAX); - } + offset += sprintf(buffer+offset, "+CEREG: (%d-%d)\r\n", + AT_CEREG_N_MIN, AT_CEREG_N_MAX); + } - LOG_FUNC_RETURN (offset); + LOG_FUNC_RETURN (offset); } /**************************************************************************** @@ -925,65 +925,65 @@ static int _at_response_encode_cereg(char* buffer, const at_response_t* data) ***************************************************************************/ static int _at_response_encode_cgdcont(char* buffer, const at_response_t* data) { - LOG_FUNC_IN; - - int offset = 0; - int i; - - if (data->type == AT_COMMAND_GET) { - const at_cgdcont_get_t * cgdcont = &(data->response.cgdcont.get); - - if (at_response_format_v1) { - offset += sprintf(buffer, "\r\n"); + LOG_FUNC_IN; + + int offset = 0; + int i; + + if (data->type == AT_COMMAND_GET) { + const at_cgdcont_get_t * cgdcont = &(data->response.cgdcont.get); + + if (at_response_format_v1) { + offset += sprintf(buffer, "\r\n"); + } + + /* Display the list of defined PDN contexts */ + for (i = 0; i < cgdcont->n_pdns; i++) { + offset += sprintf(buffer+offset, "+CGDCONT: %u", (unsigned int)cgdcont->cid[i]); + + if (cgdcont->PDP_type[i] == NET_PDN_TYPE_IPV4) { + offset += sprintf(buffer+offset, ",IP"); + } else if (cgdcont->PDP_type[i] == NET_PDN_TYPE_IPV6) { + offset += sprintf(buffer+offset, ",IPV6"); + } else if (cgdcont->PDP_type[i] == NET_PDN_TYPE_IPV4V6) { + offset += sprintf(buffer+offset, ",IPV4V6"); + } + + offset += sprintf(buffer+offset, ",%s", cgdcont->APN[i]); + /* No data/header compression */ + offset += sprintf(buffer+offset, ",%u,%u\r\n", + (unsigned int)(AT_CGDCONT_D_COMP_OFF), (unsigned int)(AT_CGDCONT_H_COMP_OFF)); + } + } else if (data->type == AT_COMMAND_TST) { + const at_cgdcont_tst_t * cgdcont = &(data->response.cgdcont.tst); + + if (at_response_format_v1) { + offset += sprintf(buffer, "\r\n"); + } + + /* IPv4 PDN type */ + offset += sprintf(buffer+offset, "+CGDCONT: "); + offset += sprintf(buffer+offset, "(1-%d),IP,,,(%d-%d),(%d-%d)", + cgdcont->n_cid, + AT_CGDCONT_D_COMP_MIN, AT_CGDCONT_D_COMP_MAX, + AT_CGDCONT_H_COMP_MIN, AT_CGDCONT_H_COMP_MAX); + /* IPv6 PDN type */ + offset += sprintf(buffer+offset, "\r\n+CGDCONT: "); + offset += sprintf(buffer+offset, "(1-%d),IPV6,,,(%d-%d),(%d-%d)", + cgdcont->n_cid, + AT_CGDCONT_D_COMP_MIN, AT_CGDCONT_D_COMP_MAX, + AT_CGDCONT_H_COMP_MIN, AT_CGDCONT_H_COMP_MAX); + /* IPv4v6 PDN type */ + offset += sprintf(buffer+offset, "\r\n+CGDCONT: "); + offset += sprintf(buffer+offset, "(1-%d),IPV4V6,,,(%d-%d),(%d-%d)", + cgdcont->n_cid, + AT_CGDCONT_D_COMP_MIN, AT_CGDCONT_D_COMP_MAX, + AT_CGDCONT_H_COMP_MIN, AT_CGDCONT_H_COMP_MAX); + + offset += sprintf(buffer+offset, "\r\n"); } - /* Display the list of defined PDN contexts */ - for (i = 0; i < cgdcont->n_pdns; i++) { - offset += sprintf(buffer+offset, "+CGDCONT: %u", cgdcont->cid[i]); - - if (cgdcont->PDP_type[i] == NET_PDN_TYPE_IPV4) { - offset += sprintf(buffer+offset, ",IP"); - } else if (cgdcont->PDP_type[i] == NET_PDN_TYPE_IPV6) { - offset += sprintf(buffer+offset, ",IPV6"); - } else if (cgdcont->PDP_type[i] == NET_PDN_TYPE_IPV4V6) { - offset += sprintf(buffer+offset, ",IPV4V6"); - } - - offset += sprintf(buffer+offset, ",%s", cgdcont->APN[i]); - /* No data/header compression */ - offset += sprintf(buffer+offset, ",%u,%u\r\n", - AT_CGDCONT_D_COMP_OFF, AT_CGDCONT_H_COMP_OFF); - } - } else if (data->type == AT_COMMAND_TST) { - const at_cgdcont_tst_t * cgdcont = &(data->response.cgdcont.tst); - - if (at_response_format_v1) { - offset += sprintf(buffer, "\r\n"); - } - - /* IPv4 PDN type */ - offset += sprintf(buffer+offset, "+CGDCONT: "); - offset += sprintf(buffer+offset, "(1-%u),IP,,,(%u-%u),(%u-%u)", - cgdcont->n_cid, - AT_CGDCONT_D_COMP_MIN, AT_CGDCONT_D_COMP_MAX, - AT_CGDCONT_H_COMP_MIN, AT_CGDCONT_H_COMP_MAX); - /* IPv6 PDN type */ - offset += sprintf(buffer+offset, "\r\n+CGDCONT: "); - offset += sprintf(buffer+offset, "(1-%u),IPV6,,,(%u-%u),(%u-%u)", - cgdcont->n_cid, - AT_CGDCONT_D_COMP_MIN, AT_CGDCONT_D_COMP_MAX, - AT_CGDCONT_H_COMP_MIN, AT_CGDCONT_H_COMP_MAX); - /* IPv4v6 PDN type */ - offset += sprintf(buffer+offset, "\r\n+CGDCONT: "); - offset += sprintf(buffer+offset, "(1-%u),IPV4V6,,,(%u-%u),(%u-%u)", - cgdcont->n_cid, - AT_CGDCONT_D_COMP_MIN, AT_CGDCONT_D_COMP_MAX, - AT_CGDCONT_H_COMP_MIN, AT_CGDCONT_H_COMP_MAX); - - offset += sprintf(buffer+offset, "\r\n"); - } - - LOG_FUNC_RETURN (offset); + LOG_FUNC_RETURN (offset); } /**************************************************************************** @@ -1003,33 +1003,33 @@ static int _at_response_encode_cgdcont(char* buffer, const at_response_t* data) ***************************************************************************/ static int _at_response_encode_cgact(char* buffer, const at_response_t* data) { - LOG_FUNC_IN; - - int offset = 0; - int i; - - if (data->type == AT_COMMAND_GET) { - const at_cgact_resp_t * cgact = &(data->response.cgact); - - if (at_response_format_v1) { - offset += sprintf(buffer, "\r\n"); + LOG_FUNC_IN; + + int offset = 0; + int i; + + if (data->type == AT_COMMAND_GET) { + const at_cgact_resp_t * cgact = &(data->response.cgact); + + if (at_response_format_v1) { + offset += sprintf(buffer, "\r\n"); + } + + /* Display the list of defined PDN status */ + for (i = 0; i < cgact->n_pdns; i++) { + offset += sprintf(buffer+offset, "+CGACT: %u,%u\r\n", + (unsigned int)cgact->cid[i], (unsigned int)cgact->state[i]); + } + } else if (data->type == AT_COMMAND_TST) { + if (at_response_format_v1) { + offset += sprintf(buffer, "\r\n"); + } + + offset += sprintf(buffer+offset, "+CGACT: (%d,%d)\r\n", + AT_CGACT_STATE_MIN, AT_CGACT_STATE_MAX); } - /* Display the list of defined PDN status */ - for (i = 0; i < cgact->n_pdns; i++) { - offset += sprintf(buffer+offset, "+CGACT: %u,%u\r\n", - cgact->cid[i], cgact->state[i]); - } - } else if (data->type == AT_COMMAND_TST) { - if (at_response_format_v1) { - offset += sprintf(buffer, "\r\n"); - } - - offset += sprintf(buffer+offset, "+CGACT: (%d,%d)\r\n", - AT_CGACT_STATE_MIN, AT_CGACT_STATE_MAX); - } - - LOG_FUNC_RETURN (offset); + LOG_FUNC_RETURN (offset); } /**************************************************************************** @@ -1049,69 +1049,72 @@ static int _at_response_encode_cgact(char* buffer, const at_response_t* data) ***************************************************************************/ static int _at_response_encode_cgpaddr(char* buffer, const at_response_t* data) { - LOG_FUNC_IN; - - int offset = 0; - const at_cgpaddr_resp_t * cgpaddr = &(data->response.cgpaddr); - int i; - - if (data->type == AT_COMMAND_SET) { - if (at_response_format_v1) { - offset += sprintf(buffer, "\r\n"); - } - - /* Display the list of IP addresses assigned to each defined PDN - * connections */ - for (i = 0; i < cgpaddr->n_pdns; i++) { - offset += sprintf(buffer+offset, "+CGPADDR: %u", cgpaddr->cid[i]); - - if (cgpaddr->PDP_addr_1[i] != NULL) { - /* IPv4 address */ - offset += sprintf(buffer+offset, ",%hhu.%hhu.%hhu.%hhu", - cgpaddr->PDP_addr_1[i][0], - cgpaddr->PDP_addr_1[i][1], - cgpaddr->PDP_addr_1[i][2], - cgpaddr->PDP_addr_1[i][3]); - } - - if (cgpaddr->PDP_addr_2[i] != NULL) { - /* IPv6 Link-local address prefixe */ - offset += sprintf(buffer+offset, - ",%hhu.%hhu.%hhu.%hhu.%hhu.%hhu.%hhu.%hhu", - 0xfe, 0x80, 0, 0, 0, 0, 0, 0); - /* IPv6 Link-local address */ - offset += sprintf(buffer+offset, - ".%hhu.%hhu.%hhu.%hhu.%hhu.%hhu.%hhu.%hhu", - cgpaddr->PDP_addr_2[i][0], - cgpaddr->PDP_addr_2[i][1], - cgpaddr->PDP_addr_2[i][2], - cgpaddr->PDP_addr_2[i][3], - cgpaddr->PDP_addr_2[i][4], - cgpaddr->PDP_addr_2[i][5], - cgpaddr->PDP_addr_2[i][6], - cgpaddr->PDP_addr_2[i][7]); - } - - offset += sprintf(buffer+offset, "\r\n"); + LOG_FUNC_IN; + + int offset = 0; + const at_cgpaddr_resp_t * cgpaddr = &(data->response.cgpaddr); + int i; + + if (data->type == AT_COMMAND_SET) { + if (at_response_format_v1) { + offset += sprintf(buffer, "\r\n"); + } + + /* Display the list of IP addresses assigned to each defined PDN + * connections */ + for (i = 0; i < cgpaddr->n_pdns; i++) { + offset += sprintf(buffer+offset, "+CGPADDR: %u", (unsigned int)cgpaddr->cid[i]); + + if (cgpaddr->PDP_addr_1[i] != NULL) { + /* IPv4 address */ + offset += sprintf(buffer+offset, ",%hhu.%hhu.%hhu.%hhu", + (unsigned int)cgpaddr->PDP_addr_1[i][0], + (unsigned int)cgpaddr->PDP_addr_1[i][1], + (unsigned int)cgpaddr->PDP_addr_1[i][2], + (unsigned int)cgpaddr->PDP_addr_1[i][3]); + } + + if (cgpaddr->PDP_addr_2[i] != NULL) { + /* IPv6 Link-local address prefixe */ + offset += sprintf(buffer+offset, + ",%hhu.%hhu.%hhu.%hhu.%hhu.%hhu.%hhu.%hhu", + (unsigned int)0xfe, (unsigned int)0x80, + (unsigned int)0, (unsigned int)0, + (unsigned int)0, (unsigned int)0, + (unsigned int)0, (unsigned int)0); + /* IPv6 Link-local address */ + offset += sprintf(buffer+offset, + ".%hhu.%hhu.%hhu.%hhu.%hhu.%hhu.%hhu.%hhu", + (unsigned int)cgpaddr->PDP_addr_2[i][0], + (unsigned int)cgpaddr->PDP_addr_2[i][1], + (unsigned int)cgpaddr->PDP_addr_2[i][2], + (unsigned int)cgpaddr->PDP_addr_2[i][3], + (unsigned int)cgpaddr->PDP_addr_2[i][4], + (unsigned int)cgpaddr->PDP_addr_2[i][5], + (unsigned int)cgpaddr->PDP_addr_2[i][6], + (unsigned int)cgpaddr->PDP_addr_2[i][7]); + } + + offset += sprintf(buffer+offset, "\r\n"); + } + } else if (data->type == AT_COMMAND_TST) { + /* Display the list of defined PDN contexts */ + if (cgpaddr->n_pdns > 0) { + if (at_response_format_v1) { + offset += sprintf(buffer, "\r\n"); + } + + offset += sprintf(buffer+offset, "+CGPADDR: %u", (unsigned int)cgpaddr->cid[0]); + + for (i = 1; i < cgpaddr->n_pdns; i++) { + offset += sprintf(buffer+offset, ",%u", (unsigned int)cgpaddr->cid[i]); + } + + offset += sprintf(buffer+offset, "\r\n"); + } } - } else if (data->type == AT_COMMAND_TST) { - /* Display the list of defined PDN contexts */ - if (cgpaddr->n_pdns > 0) { - if (at_response_format_v1) { - offset += sprintf(buffer, "\r\n"); - } - offset += sprintf(buffer+offset, "+CGPADDR: %u", cgpaddr->cid[0]); - - for (i = 1; i < cgpaddr->n_pdns; i++) { - offset += sprintf(buffer+offset, ",%u", cgpaddr->cid[i]); - } - - offset += sprintf(buffer+offset, "\r\n"); - } - } - - LOG_FUNC_RETURN (offset); + LOG_FUNC_RETURN (offset); } /**************************************************************************** @@ -1131,28 +1134,28 @@ static int _at_response_encode_cgpaddr(char* buffer, const at_response_t* data) ***************************************************************************/ static int _at_response_encode_cmee(char* buffer, const at_response_t* data) { - LOG_FUNC_IN; + LOG_FUNC_IN; - int offset = 0; + int offset = 0; - if (data->type == AT_COMMAND_GET) { - const at_cmee_resp_t * cmee = &(data->response.cmee); + if (data->type == AT_COMMAND_GET) { + const at_cmee_resp_t * cmee = &(data->response.cmee); - if (at_response_format_v1) { - offset += sprintf(buffer, "\r\n"); - } + if (at_response_format_v1) { + offset += sprintf(buffer, "\r\n"); + } - offset += sprintf(buffer+offset, "+CMEE: %d\r\n", cmee->n); - } else if (data->type == AT_COMMAND_TST) { - if (at_response_format_v1) { - offset += sprintf(buffer, "\r\n"); - } + offset += sprintf(buffer+offset, "+CMEE: %d\r\n", cmee->n); + } else if (data->type == AT_COMMAND_TST) { + if (at_response_format_v1) { + offset += sprintf(buffer, "\r\n"); + } - offset += sprintf(buffer+offset, "+CMEE: (%d,%d)\r\n", - AT_CMEE_N_MIN, AT_CMEE_N_MAX); - } + offset += sprintf(buffer+offset, "+CMEE: (%d,%d)\r\n", + AT_CMEE_N_MIN, AT_CMEE_N_MAX); + } - LOG_FUNC_RETURN (offset); + LOG_FUNC_RETURN (offset); } /**************************************************************************** @@ -1172,16 +1175,16 @@ static int _at_response_encode_cmee(char* buffer, const at_response_t* data) ***************************************************************************/ static int _at_response_encode_cgev(char* buffer, const at_response_t* data) { - LOG_FUNC_IN; + LOG_FUNC_IN; - int offset = 0; + int offset = 0; - if (data->type == AT_COMMAND_GET) { - const at_cgev_resp_t * cgev = &(data->response.cgev); - offset += sprintf(buffer+offset, "+CGEV: %s %u\r\n", - _at_response_event_str[cgev->code], cgev->cid); - } + if (data->type == AT_COMMAND_GET) { + const at_cgev_resp_t * cgev = &(data->response.cgev); + offset += sprintf(buffer+offset, "+CGEV: %s %u\r\n", + _at_response_event_str[cgev->code], (unsigned int)cgev->cid); + } - LOG_FUNC_RETURN (offset); + LOG_FUNC_RETURN (offset); } diff --git a/openair3/NAS/UE/ESM/PdnConnectivity.c b/openair3/NAS/UE/ESM/PdnConnectivity.c index f0f4efa769f5180dc5b73f5c31ea04ada5e71a49..48730f2ca9d2f68e981f8268362d89b8af8bde1b 100644 --- a/openair3/NAS/UE/ESM/PdnConnectivity.c +++ b/openair3/NAS/UE/ESM/PdnConnectivity.c @@ -138,119 +138,119 @@ int esm_proc_pdn_connectivity(nas_user_t *user, int cid, int is_to_define, const OctetString *apn, int is_emergency, unsigned int *pti) { - LOG_FUNC_IN; + LOG_FUNC_IN; - int rc = RETURNerror; - int pid = cid - 1; - esm_data_t *esm_data = user-> esm_data; - esm_pt_data_t *esm_pt_data = user-> esm_pt_data; + int rc = RETURNerror; + int pid = cid - 1; + esm_data_t *esm_data = user-> esm_data; + esm_pt_data_t *esm_pt_data = user-> esm_pt_data; - if (!is_to_define) { - LOG_TRACE(INFO, "ESM-PROC - Undefine PDN connection (cid=%d)", cid); - /* Delete the PDN connection entry */ - int pti = _pdn_connectivity_delete(esm_data, pid); + if (!is_to_define) { + LOG_TRACE(INFO, "ESM-PROC - Undefine PDN connection (cid=%d)", cid); + /* Delete the PDN connection entry */ + int pti = _pdn_connectivity_delete(esm_data, pid); - if (pti != ESM_PT_UNASSIGNED) { - /* Release the procedure transaction data */ - rc = esm_pt_release(esm_pt_data, pti); - } + if (pti != ESM_PT_UNASSIGNED) { + /* Release the procedure transaction data */ + rc = esm_pt_release(esm_pt_data, pti); + } - LOG_FUNC_RETURN(rc); - } else if (pti != NULL) { - LOG_TRACE(INFO, "ESM-PROC - Assign new procedure transaction identity " - "(cid=%d)", cid); - /* Assign new procedure transaction identity */ - *pti = esm_pt_assign(esm_pt_data); - - if (*pti == ESM_PT_UNASSIGNED) { - LOG_TRACE(WARNING, "ESM-PROC - Failed to assign new procedure " - "transaction identity"); - LOG_FUNC_RETURN (RETURNerror); - } + LOG_FUNC_RETURN(rc); + } else if (pti != NULL) { + LOG_TRACE(INFO, "ESM-PROC - Assign new procedure transaction identity " + "(cid=%d)", cid); + /* Assign new procedure transaction identity */ + *pti = esm_pt_assign(esm_pt_data); + + if (*pti == ESM_PT_UNASSIGNED) { + LOG_TRACE(WARNING, "ESM-PROC - Failed to assign new procedure " + "transaction identity"); + LOG_FUNC_RETURN (RETURNerror); + } - /* Update the PDN connection data */ - rc = _pdn_connectivity_set_pti(esm_data, pid, *pti); + /* Update the PDN connection data */ + rc = _pdn_connectivity_set_pti(esm_data, pid, *pti); - if (rc != RETURNok) { - LOG_TRACE(WARNING, "ESM-PROC - Failed to update PDN connection"); - } + if (rc != RETURNok) { + LOG_TRACE(WARNING, "ESM-PROC - Failed to update PDN connection"); + } - LOG_FUNC_RETURN (rc); - } - - LOG_TRACE(INFO,"ESM-PROC - Define new %s PDN connection to APN %s (cid=%d)", - (pdn_type == ESM_PDN_TYPE_IPV4)? "IPv4" : - (pdn_type == ESM_PDN_TYPE_IPV6)? "IPv6" : "IPv4v6", - apn->value, cid); - - if (is_emergency && esm_data->emergency) { - /* The UE shall not request additional PDN connection for - * emergency bearer services */ - LOG_TRACE(WARNING, "ESM-PROC - PDN connection for emergency bearer " - "services is already active"); - LOG_FUNC_RETURN (RETURNerror); - } else if (pid < ESM_DATA_PDN_MAX) { - if ((pid == esm_data->pdn[pid].pid) && (esm_data->pdn[pid].is_active)) { - /* PDN connection with the specified identifier is active */ - LOG_TRACE(WARNING, "ESM-PROC - PDN connection is active"); - LOG_FUNC_RETURN (RETURNerror); + LOG_FUNC_RETURN (rc); } - } else { - LOG_TRACE(WARNING, "ESM-PROC - PDN connection identifier is not valid"); - LOG_FUNC_RETURN (RETURNerror); - } - - if (apn && apn->length > 0) { - /* The UE requested subsequent connectivity to additionnal PDNs */ - int pid = _pdn_connectivity_find_apn(esm_data, apn); - - if ( (pid >= 0) && esm_data->pdn[pid].is_active ) { - /* An active PDN connection to this APN already exists */ - if ( (esm_data->pdn[pid].data->type != ESM_PDN_TYPE_IPV4V6) && - (esm_data->pdn[pid].data->type != pdn_type) ) { - /* The UE is requesting PDN connection for other IP version - * than the one already activated */ - if (!esm_data->pdn[pid].data->addr_realloc) { - /* The network does not allow PDN connectivity using - * IPv4 and IPv6 address versions to the same APN */ - if (pdn_type != ESM_PDN_TYPE_IPV4V6) { - LOG_TRACE(WARNING, "ESM-PROC - %s PDN connectivity to " - "%s is not allowed by the network", - (pdn_type != ESM_PDN_TYPE_IPV4)? "IPv6" : - "IPv4", apn->value); - } else { - LOG_TRACE(WARNING, "ESM-PROC - %s PDN connection to %s " - "already exists", - (esm_data->pdn[pid].data->type != - ESM_PDN_TYPE_IPV4)? "IPv6" : "IPv4", - apn->value); - } - - LOG_FUNC_RETURN (RETURNerror); + + LOG_TRACE(INFO,"ESM-PROC - Define new %s PDN connection to APN %s (cid=%d)", + (pdn_type == ESM_PDN_TYPE_IPV4)? "IPv4" : + (pdn_type == ESM_PDN_TYPE_IPV6)? "IPv6" : "IPv4v6", + (apn!=NULL)?apn->value:0, cid); + + if (is_emergency && esm_data->emergency) { + /* The UE shall not request additional PDN connection for + * emergency bearer services */ + LOG_TRACE(WARNING, "ESM-PROC - PDN connection for emergency bearer " + "services is already active"); + LOG_FUNC_RETURN (RETURNerror); + } else if (pid < ESM_DATA_PDN_MAX) { + if ((pid == esm_data->pdn[pid].pid) && (esm_data->pdn[pid].is_active)) { + /* PDN connection with the specified identifier is active */ + LOG_TRACE(WARNING, "ESM-PROC - PDN connection is active"); + LOG_FUNC_RETURN (RETURNerror); } - } else { - /* The UE is requesting PDN connection to this APN using the - * same IP version than the one already activated */ - LOG_TRACE(WARNING, "ESM-PROC - %s PDN connection to %s " - "already exists", - (esm_data->pdn[pid].data->type != ESM_PDN_TYPE_IPV4)? - (esm_data->pdn[pid].data->type != ESM_PDN_TYPE_IPV6)? - "IPv4v6" : "IPv6" : "IPv4", apn->value); + } else { + LOG_TRACE(WARNING, "ESM-PROC - PDN connection identifier is not valid"); LOG_FUNC_RETURN (RETURNerror); - } } - } - - /* - * New PDN context has to be defined to allow connectivity to an APN: - * The UE may attempt to attach to the network using the default APN, - * or request PDN connectivity to emergency bearer services. The UE - * may also subsequently request connectivity to additional PDNs if - * not already established, or may have been allowed to request PDN - * connectivity for other IP version than the one already activated - */ - rc = _pdn_connectivity_create(esm_data, pid, apn, pdn_type, is_emergency); - LOG_FUNC_RETURN(rc); + + if (apn && apn->length > 0) { + /* The UE requested subsequent connectivity to additionnal PDNs */ + int pid = _pdn_connectivity_find_apn(esm_data, apn); + + if ( (pid >= 0) && esm_data->pdn[pid].is_active ) { + /* An active PDN connection to this APN already exists */ + if ( (esm_data->pdn[pid].data->type != ESM_PDN_TYPE_IPV4V6) && + (esm_data->pdn[pid].data->type != pdn_type) ) { + /* The UE is requesting PDN connection for other IP version + * than the one already activated */ + if (!esm_data->pdn[pid].data->addr_realloc) { + /* The network does not allow PDN connectivity using + * IPv4 and IPv6 address versions to the same APN */ + if (pdn_type != ESM_PDN_TYPE_IPV4V6) { + LOG_TRACE(WARNING, "ESM-PROC - %s PDN connectivity to " + "%s is not allowed by the network", + (pdn_type != ESM_PDN_TYPE_IPV4)? "IPv6" : + "IPv4", apn->value); + } else { + LOG_TRACE(WARNING, "ESM-PROC - %s PDN connection to %s " + "already exists", + (esm_data->pdn[pid].data->type != + ESM_PDN_TYPE_IPV4)? "IPv6" : "IPv4", + apn->value); + } + + LOG_FUNC_RETURN (RETURNerror); + } + } else { + /* The UE is requesting PDN connection to this APN using the + * same IP version than the one already activated */ + LOG_TRACE(WARNING, "ESM-PROC - %s PDN connection to %s " + "already exists", + (esm_data->pdn[pid].data->type != ESM_PDN_TYPE_IPV4)? + (esm_data->pdn[pid].data->type != ESM_PDN_TYPE_IPV6)? + "IPv4v6" : "IPv6" : "IPv4", apn->value); + LOG_FUNC_RETURN (RETURNerror); + } + } + } + + /* + * New PDN context has to be defined to allow connectivity to an APN: + * The UE may attempt to attach to the network using the default APN, + * or request PDN connectivity to emergency bearer services. The UE + * may also subsequently request connectivity to additional PDNs if + * not already established, or may have been allowed to request PDN + * connectivity for other IP version than the one already activated + */ + rc = _pdn_connectivity_create(esm_data, pid, apn, pdn_type, is_emergency); + LOG_FUNC_RETURN(rc); } /**************************************************************************** @@ -283,42 +283,42 @@ int esm_proc_pdn_connectivity(nas_user_t *user, int cid, int is_to_define, int esm_proc_pdn_connectivity_request(nas_user_t *user, int is_standalone, int pti, OctetString *msg, int sent_by_ue) { - LOG_FUNC_IN; - esm_pt_data_t *esm_pt_data = user->esm_pt_data; - int rc = RETURNok; - - LOG_TRACE(INFO, "ESM-PROC - Initiate PDN connectivity (pti=%d)", pti); - - if (is_standalone) { - emm_sap_t emm_sap; - emm_esm_data_t *emm_esm = &emm_sap.u.emm_esm.u.data; - /* - * Notity EMM that ESM PDU has to be forwarded to lower layers - */ - emm_sap.primitive = EMMESM_UNITDATA_REQ; - emm_sap.u.emm_esm.ueid = user->ueid; - emm_esm->msg.length = msg->length; - emm_esm->msg.value = msg->value; - rc = emm_sap_send(user, &emm_sap); - - if (rc != RETURNerror) { - /* Start T3482 retransmission timer */ - rc = esm_pt_start_timer(user, pti, msg, T3482_DEFAULT_VALUE, - _pdn_connectivity_t3482_handler); + LOG_FUNC_IN; + esm_pt_data_t *esm_pt_data = user->esm_pt_data; + int rc = RETURNok; + + LOG_TRACE(INFO, "ESM-PROC - Initiate PDN connectivity (pti=%d)", pti); + + if (is_standalone) { + emm_sap_t emm_sap; + emm_esm_data_t *emm_esm = &emm_sap.u.emm_esm.u.data; + /* + * Notity EMM that ESM PDU has to be forwarded to lower layers + */ + emm_sap.primitive = EMMESM_UNITDATA_REQ; + emm_sap.u.emm_esm.ueid = user->ueid; + emm_esm->msg.length = msg->length; + emm_esm->msg.value = msg->value; + rc = emm_sap_send(user, &emm_sap); + + if (rc != RETURNerror) { + /* Start T3482 retransmission timer */ + rc = esm_pt_start_timer(user, pti, msg, T3482_DEFAULT_VALUE, + _pdn_connectivity_t3482_handler); + } } - } - if (rc != RETURNerror) { - /* Set the procedure transaction state to PENDING */ - rc = esm_pt_set_status(esm_pt_data, pti, ESM_PT_PENDING); + if (rc != RETURNerror) { + /* Set the procedure transaction state to PENDING */ + rc = esm_pt_set_status(esm_pt_data, pti, ESM_PT_PENDING); - if (rc != RETURNok) { - /* The procedure transaction was already in PENDING state */ - LOG_TRACE(WARNING, "ESM-PROC - PTI %d was already PENDING", pti); + if (rc != RETURNok) { + /* The procedure transaction was already in PENDING state */ + LOG_TRACE(WARNING, "ESM-PROC - PTI %d was already PENDING", pti); + } } - } - LOG_FUNC_RETURN(rc); + LOG_FUNC_RETURN(rc); } /**************************************************************************** @@ -351,73 +351,73 @@ int esm_proc_pdn_connectivity_accept(nas_user_t *user, int pti, esm_proc_pdn_typ const OctetString *pdn_addr, const OctetString *apn, int *esm_cause) { - LOG_FUNC_IN; - esm_data_t *esm_data = user->esm_data; - esm_pt_data_t *esm_pt_data = user->esm_pt_data; - int rc; - int pid = RETURNerror; - char apn_first_char[4]; - - LOG_VAR(char, str[128]); - - if (isprint(apn->value[0])) { - apn_first_char[0] = '\0'; - } else { - sprintf (apn_first_char, "%02X", apn->value[0]); - } - - LOG_TRACE(INFO, "ESM-PROC - PDN connectivity accepted by the network " - "(pti=%d) APN = %s\"%s\", IP address = %s", pti, apn_first_char, isprint(apn->value[0]) ? &apn->value[0] : &apn->value[1], - (pdn_type == ESM_PDN_TYPE_IPV4)? esm_data_get_ipv4_addr(pdn_addr, str) : - (pdn_type == ESM_PDN_TYPE_IPV6)? esm_data_get_ipv6_addr(pdn_addr, str) : - esm_data_get_ipv4v6_addr(pdn_addr, str)); - - /* Stop T3482 timer if running */ - esm_pt_stop_timer(esm_pt_data, pti); - /* Set the procedure transaction state to INACTIVE */ - rc = esm_pt_set_status(esm_pt_data, pti, ESM_PT_INACTIVE); - - if (rc != RETURNok) { - /* The procedure transaction was already in INACTIVE state - * as the request may have already been accepted; consider - * this request message with same PTI as a network re- - * transmission */ - LOG_TRACE(WARNING, "ESM-PROC - PTI %d network retransmission", pti); - *esm_cause = ESM_CAUSE_PTI_ALREADY_IN_USE; - } else { - /* XXX - 3GPP TS 24.301, section 6.5.1.3 and 7.3.1 - * The UE should ensure that the procedure transaction identity - * (PTI) assigned to this procedure is not released immediately. - * While the PTI value is not released, the UE regards any received - * ACTIVATE DEFAULT EPS BEARER CONTEXT REQUEST message with the same - * PTI value as a network retransmission. - * The way to achieve this is implementation dependent. - */ + LOG_FUNC_IN; + esm_data_t *esm_data = user->esm_data; + esm_pt_data_t *esm_pt_data = user->esm_pt_data; + int rc; + int pid = RETURNerror; + char apn_first_char[4]; - /* Check whether a PDN connection exists to this APN */ - pid = _pdn_connectivity_find_pdn(esm_data, apn, pdn_type); + LOG_VAR(char, str[128]); - if (pid < 0) { - /* No any PDN connection has been defined to establish connectivity - * to this APN */ - LOG_TRACE(WARNING, "ESM-PROC - PDN connection entry for " - "APN \"%s\" (type=%d) not found", apn->value, pdn_type); - *esm_cause = ESM_CAUSE_UNKNOWN_ACCESS_POINT_NAME; - LOG_FUNC_RETURN(RETURNerror); + if (isprint(apn->value[0])) { + apn_first_char[0] = '\0'; + } else { + sprintf (apn_first_char, "%02X", apn->value[0]); } - /* Update the PDN connection */ - rc = _pdn_connectivity_update(esm_data, pid, apn, pdn_type, pdn_addr, *esm_cause); + LOG_TRACE(INFO, "ESM-PROC - PDN connectivity accepted by the network " + "(pti=%d) APN = %s\"%s\", IP address = %s", pti, apn_first_char, isprint(apn->value[0]) ? &apn->value[0] : &apn->value[1], + (pdn_type == ESM_PDN_TYPE_IPV4)? esm_data_get_ipv4_addr(pdn_addr, str) : + (pdn_type == ESM_PDN_TYPE_IPV6)? esm_data_get_ipv6_addr(pdn_addr, str) : + esm_data_get_ipv4v6_addr(pdn_addr, str)); + + /* Stop T3482 timer if running */ + esm_pt_stop_timer(esm_pt_data, pti); + /* Set the procedure transaction state to INACTIVE */ + rc = esm_pt_set_status(esm_pt_data, pti, ESM_PT_INACTIVE); if (rc != RETURNok) { - LOG_TRACE(WARNING, "ESM-PROC - Failed to update PDN connection " - "(pid=%d)", pid); - *esm_cause = ESM_CAUSE_REQUEST_REJECTED_UNSPECIFIED; - LOG_FUNC_RETURN(RETURNerror); + /* The procedure transaction was already in INACTIVE state + * as the request may have already been accepted; consider + * this request message with same PTI as a network re- + * transmission */ + LOG_TRACE(WARNING, "ESM-PROC - PTI %d network retransmission", pti); + *esm_cause = ESM_CAUSE_PTI_ALREADY_IN_USE; + } else { + /* XXX - 3GPP TS 24.301, section 6.5.1.3 and 7.3.1 + * The UE should ensure that the procedure transaction identity + * (PTI) assigned to this procedure is not released immediately. + * While the PTI value is not released, the UE regards any received + * ACTIVATE DEFAULT EPS BEARER CONTEXT REQUEST message with the same + * PTI value as a network retransmission. + * The way to achieve this is implementation dependent. + */ + + /* Check whether a PDN connection exists to this APN */ + pid = _pdn_connectivity_find_pdn(esm_data, apn, pdn_type); + + if (pid < 0) { + /* No any PDN connection has been defined to establish connectivity + * to this APN */ + LOG_TRACE(WARNING, "ESM-PROC - PDN connection entry for " + "APN \"%s\" (type=%d) not found", apn->value, pdn_type); + *esm_cause = ESM_CAUSE_UNKNOWN_ACCESS_POINT_NAME; + LOG_FUNC_RETURN(RETURNerror); + } + + /* Update the PDN connection */ + rc = _pdn_connectivity_update(esm_data, pid, apn, pdn_type, pdn_addr, *esm_cause); + + if (rc != RETURNok) { + LOG_TRACE(WARNING, "ESM-PROC - Failed to update PDN connection " + "(pid=%d)", pid); + *esm_cause = ESM_CAUSE_REQUEST_REJECTED_UNSPECIFIED; + LOG_FUNC_RETURN(RETURNerror); + } } - } - LOG_FUNC_RETURN (pid); + LOG_FUNC_RETURN (pid); } /**************************************************************************** @@ -444,33 +444,33 @@ int esm_proc_pdn_connectivity_accept(nas_user_t *user, int pti, esm_proc_pdn_typ ***************************************************************************/ int esm_proc_pdn_connectivity_reject(nas_user_t *user, int pti, int *esm_cause) { - LOG_FUNC_IN; - esm_pt_data_t *esm_pt_data = user->esm_pt_data; - int rc; - - LOG_TRACE(WARNING, "ESM-PROC - PDN connectivity rejected by " - "the network (pti=%d), ESM cause = %d", pti, *esm_cause); - - /* Stop T3482 timer if running */ - (void) esm_pt_stop_timer(esm_pt_data, pti); - /* Set the procedure transaction state to INACTIVE */ - rc = esm_pt_set_status(esm_pt_data, pti, ESM_PT_INACTIVE); - - if (rc != RETURNok) { - /* The procedure transaction was already in INACTIVE state */ - LOG_TRACE(WARNING, "ESM-PROC - PTI %d was already INACTIVE", pti); - *esm_cause = ESM_CAUSE_MESSAGE_TYPE_NOT_COMPATIBLE; - } else { - /* Release the procedure transaction identity */ - rc = esm_pt_release(user->esm_pt_data, pti); + LOG_FUNC_IN; + esm_pt_data_t *esm_pt_data = user->esm_pt_data; + int rc; + + LOG_TRACE(WARNING, "ESM-PROC - PDN connectivity rejected by " + "the network (pti=%d), ESM cause = %d", pti, *esm_cause); + + /* Stop T3482 timer if running */ + (void) esm_pt_stop_timer(esm_pt_data, pti); + /* Set the procedure transaction state to INACTIVE */ + rc = esm_pt_set_status(esm_pt_data, pti, ESM_PT_INACTIVE); if (rc != RETURNok) { - LOG_TRACE(WARNING, "ESM-PROC - Failed to release PTI %d", pti); - *esm_cause = ESM_CAUSE_REQUEST_REJECTED_UNSPECIFIED; + /* The procedure transaction was already in INACTIVE state */ + LOG_TRACE(WARNING, "ESM-PROC - PTI %d was already INACTIVE", pti); + *esm_cause = ESM_CAUSE_MESSAGE_TYPE_NOT_COMPATIBLE; + } else { + /* Release the procedure transaction identity */ + rc = esm_pt_release(user->esm_pt_data, pti); + + if (rc != RETURNok) { + LOG_TRACE(WARNING, "ESM-PROC - Failed to release PTI %d", pti); + *esm_cause = ESM_CAUSE_REQUEST_REJECTED_UNSPECIFIED; + } } - } - LOG_FUNC_RETURN(rc); + LOG_FUNC_RETURN(rc); } /**************************************************************************** @@ -495,22 +495,22 @@ int esm_proc_pdn_connectivity_reject(nas_user_t *user, int pti, int *esm_cause) ***************************************************************************/ int esm_proc_pdn_connectivity_complete(nas_user_t *user) { - LOG_FUNC_IN; - esm_pt_data_t *esm_pt_data = user->esm_pt_data; - int rc = RETURNerror; + LOG_FUNC_IN; + esm_pt_data_t *esm_pt_data = user->esm_pt_data; + int rc = RETURNerror; - LOG_TRACE(INFO, "ESM-PROC - PDN connectivity complete"); + LOG_TRACE(INFO, "ESM-PROC - PDN connectivity complete"); - /* Get the procedure transaction identity assigned to the PDN connection - * entry which is still pending in the inactive state */ - int pti = esm_pt_get_pending_pti(esm_pt_data, ESM_PT_INACTIVE); + /* Get the procedure transaction identity assigned to the PDN connection + * entry which is still pending in the inactive state */ + int pti = esm_pt_get_pending_pti(esm_pt_data, ESM_PT_INACTIVE); - if (pti != ESM_PT_UNASSIGNED) { - /* Release the procedure transaction identity */ - rc = esm_pt_release(esm_pt_data, pti); - } + if (pti != ESM_PT_UNASSIGNED) { + /* Release the procedure transaction identity */ + rc = esm_pt_release(esm_pt_data, pti); + } - LOG_FUNC_RETURN(rc); + LOG_FUNC_RETURN(rc); } /**************************************************************************** @@ -536,40 +536,40 @@ int esm_proc_pdn_connectivity_complete(nas_user_t *user) ***************************************************************************/ int esm_proc_pdn_connectivity_failure(nas_user_t *user, int is_pending) { - LOG_FUNC_IN; - esm_pt_data_t *esm_pt_data = user->esm_pt_data; - int rc; - int pti; - - LOG_TRACE(WARNING, "ESM-PROC - PDN connectivity failure in state %s", - (is_pending)? "PENDING" : "INACTIVE"); - - if (is_pending) { - /* Get the procedure transaction identity assigned to the pending PDN - * connection entry */ - pti = esm_pt_get_pending_pti(esm_pt_data, ESM_PT_PENDING); - - if (pti == ESM_PT_UNASSIGNED) { - LOG_TRACE(ERROR, "ESM-PROC - No procedure transaction is PENDING"); - return (RETURNerror); - } + LOG_FUNC_IN; + esm_pt_data_t *esm_pt_data = user->esm_pt_data; + int rc; + int pti; + + LOG_TRACE(WARNING, "ESM-PROC - PDN connectivity failure in state %s", + (is_pending)? "PENDING" : "INACTIVE"); + + if (is_pending) { + /* Get the procedure transaction identity assigned to the pending PDN + * connection entry */ + pti = esm_pt_get_pending_pti(esm_pt_data, ESM_PT_PENDING); + + if (pti == ESM_PT_UNASSIGNED) { + LOG_TRACE(ERROR, "ESM-PROC - No procedure transaction is PENDING"); + return (RETURNerror); + } - /* Set the procedure transaction state to INACTIVE */ - (void) esm_pt_set_status(esm_pt_data, pti, ESM_PT_INACTIVE); - } else { - /* Get the procedure transaction identity assigned to the PDN - * connection entry which is still pending in the inactive state */ - pti = esm_pt_get_pending_pti(esm_pt_data, ESM_PT_INACTIVE); - } + /* Set the procedure transaction state to INACTIVE */ + (void) esm_pt_set_status(esm_pt_data, pti, ESM_PT_INACTIVE); + } else { + /* Get the procedure transaction identity assigned to the PDN + * connection entry which is still pending in the inactive state */ + pti = esm_pt_get_pending_pti(esm_pt_data, ESM_PT_INACTIVE); + } - /* Release the procedure transaction identity */ - rc = esm_pt_release(esm_pt_data, pti); + /* Release the procedure transaction identity */ + rc = esm_pt_release(esm_pt_data, pti); - if (rc != RETURNok) { - LOG_TRACE(WARNING, "ESM-PROC - Failed to release PTI %d", pti); - } + if (rc != RETURNok) { + LOG_TRACE(WARNING, "ESM-PROC - Failed to release PTI %d", pti); + } - LOG_FUNC_RETURN(rc); + LOG_FUNC_RETURN(rc); } @@ -607,62 +607,62 @@ int esm_proc_pdn_connectivity_failure(nas_user_t *user, int is_pending) ** Others: None ** ** ** ***************************************************************************/ -// FIXME +// FIXME static void *_pdn_connectivity_t3482_handler(void *args) { - LOG_FUNC_IN; - - int rc; - - /* Get retransmission timer parameters data */ - esm_pt_timer_data_t *data = args; - nas_user_t *user = data->user; - esm_pt_data_t *esm_pt_data = user->esm_pt_data; - - /* Increment the retransmission counter */ - data->count += 1; - - LOG_TRACE(WARNING, "ESM-PROC - T3482 timer expired (pti=%d), " - "retransmission counter = %d", data->pti, data->count); - - if (data->count < ESM_PDN_CONNECTIVITY_COUNTER_MAX) { - emm_sap_t emm_sap; - emm_esm_data_t *emm_esm = &emm_sap.u.emm_esm.u.data; - /* - * Notify EMM that the PDN connectivity request message - * has to be sent again - */ - emm_sap.primitive = EMMESM_UNITDATA_REQ; - emm_sap.u.emm_esm.ueid = user->ueid; - emm_esm->msg.length = data->msg.length; - emm_esm->msg.value = data->msg.value; - rc = emm_sap_send(user, &emm_sap); - - if (rc != RETURNerror) { - /* Restart the timer T3482 */ - rc = esm_pt_start_timer(user, data->pti, &data->msg, T3482_DEFAULT_VALUE, - _pdn_connectivity_t3482_handler); - } - } else { - /* Set the procedure transaction state to INACTIVE */ - rc = esm_pt_set_status(esm_pt_data, data->pti, ESM_PT_INACTIVE); - - if (rc != RETURNok) { - /* The procedure transaction was already in INACTIVE state */ - LOG_TRACE(WARNING, "ESM-PROC - PTI %d was already INACTIVE", - data->pti); + LOG_FUNC_IN; + + int rc; + + /* Get retransmission timer parameters data */ + esm_pt_timer_data_t *data = args; + nas_user_t *user = data->user; + esm_pt_data_t *esm_pt_data = user->esm_pt_data; + + /* Increment the retransmission counter */ + data->count += 1; + + LOG_TRACE(WARNING, "ESM-PROC - T3482 timer expired (pti=%d), " + "retransmission counter = %d", data->pti, data->count); + + if (data->count < ESM_PDN_CONNECTIVITY_COUNTER_MAX) { + emm_sap_t emm_sap; + emm_esm_data_t *emm_esm = &emm_sap.u.emm_esm.u.data; + /* + * Notify EMM that the PDN connectivity request message + * has to be sent again + */ + emm_sap.primitive = EMMESM_UNITDATA_REQ; + emm_sap.u.emm_esm.ueid = user->ueid; + emm_esm->msg.length = data->msg.length; + emm_esm->msg.value = data->msg.value; + rc = emm_sap_send(user, &emm_sap); + + if (rc != RETURNerror) { + /* Restart the timer T3482 */ + rc = esm_pt_start_timer(user, data->pti, &data->msg, T3482_DEFAULT_VALUE, + _pdn_connectivity_t3482_handler); + } } else { - /* Release the transaction identity assigned to this procedure */ - rc = esm_pt_release(esm_pt_data, data->pti); - - if (rc != RETURNok) { - LOG_TRACE(WARNING, "ESM-PROC - Failed to release PTI %d", - data->pti); - } + /* Set the procedure transaction state to INACTIVE */ + rc = esm_pt_set_status(esm_pt_data, data->pti, ESM_PT_INACTIVE); + + if (rc != RETURNok) { + /* The procedure transaction was already in INACTIVE state */ + LOG_TRACE(WARNING, "ESM-PROC - PTI %d was already INACTIVE", + data->pti); + } else { + /* Release the transaction identity assigned to this procedure */ + rc = esm_pt_release(esm_pt_data, data->pti); + + if (rc != RETURNok) { + LOG_TRACE(WARNING, "ESM-PROC - Failed to release PTI %d", + data->pti); + } + } } - } - LOG_FUNC_RETURN(NULL); + LOG_FUNC_RETURN(NULL); } /* @@ -692,63 +692,63 @@ static int _pdn_connectivity_create(esm_data_t *esm_data, int pid, const OctetSt esm_proc_pdn_type_t pdn_type, int is_emergency) { - esm_pdn_t *pdn = NULL; + esm_pdn_t *pdn = NULL; - LOG_TRACE(INFO, "ESM-PROC - Create new PDN connection (pid=%d)", pid); + LOG_TRACE(INFO, "ESM-PROC - Create new PDN connection (pid=%d)", pid); - if (pid >= ESM_DATA_PDN_MAX) { - return (RETURNerror); - } else if (esm_data->pdn[pid].is_active) { - LOG_TRACE(ERROR, "ESM-PROC - PDN connection is active"); - return (RETURNerror); - } - - if (esm_data->pdn[pid].data != NULL) { - /* Update existing non-active PDN connection */ - pdn = esm_data->pdn[pid].data; - } else { - /* Create new PDN connection */ - pdn = (esm_pdn_t *)malloc(sizeof(esm_pdn_t)); - - if (pdn == NULL) { - LOG_TRACE(WARNING, "ESM-PROC - " - "Failed to create new PDN connection"); - return (RETURNerror); + if (pid >= ESM_DATA_PDN_MAX) { + return (RETURNerror); + } else if (esm_data->pdn[pid].is_active) { + LOG_TRACE(ERROR, "ESM-PROC - PDN connection is active"); + return (RETURNerror); } - memset(pdn, 0, sizeof(esm_pdn_t)); - /* Increment the number of PDN connections */ - esm_data->n_pdns += 1; - /* Set the PDN connection identifier */ - esm_data->pdn[pid].pid = pid; - /* Reset the PDN connection active indicator */ - esm_data->pdn[pid].is_active = FALSE; - /* Setup the PDN connection data */ - esm_data->pdn[pid].data = pdn; - } - - /* Update the PDN connection data */ - pdn->is_emergency = is_emergency; - - if ( apn && (apn->length > 0) ) { - if (pdn->apn.length > 0) { - free(pdn->apn.value); - pdn->apn.length = 0; + if (esm_data->pdn[pid].data != NULL) { + /* Update existing non-active PDN connection */ + pdn = esm_data->pdn[pid].data; + } else { + /* Create new PDN connection */ + pdn = (esm_pdn_t *)malloc(sizeof(esm_pdn_t)); + + if (pdn == NULL) { + LOG_TRACE(WARNING, "ESM-PROC - " + "Failed to create new PDN connection"); + return (RETURNerror); + } + + memset(pdn, 0, sizeof(esm_pdn_t)); + /* Increment the number of PDN connections */ + esm_data->n_pdns += 1; + /* Set the PDN connection identifier */ + esm_data->pdn[pid].pid = pid; + /* Reset the PDN connection active indicator */ + esm_data->pdn[pid].is_active = FALSE; + /* Setup the PDN connection data */ + esm_data->pdn[pid].data = pdn; } - pdn->apn.value = (uint8_t *)malloc(apn->length + 1); + /* Update the PDN connection data */ + pdn->is_emergency = is_emergency; + + if ( apn && (apn->length > 0) ) { + if (pdn->apn.length > 0) { + free(pdn->apn.value); + pdn->apn.length = 0; + } + + pdn->apn.value = (uint8_t *)malloc(apn->length + 1); - if (pdn->apn.value) { - pdn->apn.length = apn->length; - memcpy(pdn->apn.value, apn->value, apn->length); - pdn->apn.value[pdn->apn.length] = '\0'; + if (pdn->apn.value) { + pdn->apn.length = apn->length; + memcpy(pdn->apn.value, apn->value, apn->length); + pdn->apn.value[pdn->apn.length] = '\0'; + } } - } - pdn->type = pdn_type; - pdn->addr_realloc = FALSE; + pdn->type = pdn_type; + pdn->addr_realloc = FALSE; - return (RETURNok); + return (RETURNok); } /**************************************************************************** @@ -772,75 +772,75 @@ static int _pdn_connectivity_update(esm_data_t *esm_data, int pid, const OctetSt const OctetString *pdn_addr, int esm_cause) { - LOG_TRACE(INFO, "ESM-PROC - Update PDN connection (pid=%d)", pid); + LOG_TRACE(INFO, "ESM-PROC - Update PDN connection (pid=%d)", pid); - if (pid >= ESM_DATA_PDN_MAX) { - return (RETURNerror); - } else if (pid != esm_data->pdn[pid].pid) { - LOG_TRACE(ERROR, "ESM-PROC - PDN connection identifier is not valid"); - return (RETURNerror); - } else if (esm_data->pdn[pid].data == NULL) { - LOG_TRACE(ERROR, "ESM-PROC - PDN connection has not been allocated"); - return (RETURNerror); - } else if (esm_data->pdn[pid].is_active) { - LOG_TRACE(WARNING, "ESM-PROC - Active %s PDN connection to %s already " - "exists", (esm_data->pdn[pid].data->type != ESM_PDN_TYPE_IPV4)? - "IPv6" : "IPv4", esm_data->pdn[pid].data->apn.value); - return (RETURNerror); - } + if (pid >= ESM_DATA_PDN_MAX) { + return (RETURNerror); + } else if (pid != esm_data->pdn[pid].pid) { + LOG_TRACE(ERROR, "ESM-PROC - PDN connection identifier is not valid"); + return (RETURNerror); + } else if (esm_data->pdn[pid].data == NULL) { + LOG_TRACE(ERROR, "ESM-PROC - PDN connection has not been allocated"); + return (RETURNerror); + } else if (esm_data->pdn[pid].is_active) { + LOG_TRACE(WARNING, "ESM-PROC - Active %s PDN connection to %s already " + "exists", (esm_data->pdn[pid].data->type != ESM_PDN_TYPE_IPV4)? + "IPv6" : "IPv4", esm_data->pdn[pid].data->apn.value); + return (RETURNerror); + } - /* Get the PDN connection */ - esm_pdn_t *pdn = esm_data->pdn[pid].data; + /* Get the PDN connection */ + esm_pdn_t *pdn = esm_data->pdn[pid].data; - /* Setup the Access Point Name value */ - if ( apn && (apn->length > 0) ) { - if (pdn->apn.length > 0) { - free(pdn->apn.value); - pdn->apn.length = 0; - } + /* Setup the Access Point Name value */ + if ( apn && (apn->length > 0) ) { + if (pdn->apn.length > 0) { + free(pdn->apn.value); + pdn->apn.length = 0; + } - pdn->apn.value = (uint8_t *)malloc(apn->length + 1); + pdn->apn.value = (uint8_t *)malloc(apn->length + 1); - if (pdn->apn.value) { - pdn->apn.length = apn->length; - memcpy(pdn->apn.value, apn->value, apn->length); - pdn->apn.value[pdn->apn.length] = '\0'; + if (pdn->apn.value) { + pdn->apn.length = apn->length; + memcpy(pdn->apn.value, apn->value, apn->length); + pdn->apn.value[pdn->apn.length] = '\0'; + } } - } - /* Setup the IP address allocated by the network */ - if ( pdn_addr && (pdn_addr->length > 0) ) { - int length = ((pdn_addr->length < ESM_DATA_IP_ADDRESS_SIZE) ? - pdn_addr->length : ESM_DATA_IP_ADDRESS_SIZE); - memcpy(pdn->ip_addr, pdn_addr->value, length); - pdn->type = pdn_type; - } - - /* - * 3GPP TS 24.301, section 6.2.2 - * Update the address re-allocation indicator - */ - if (esm_cause == ESM_CAUSE_SINGLE_ADDRESS_BEARERS_ONLY_ALLOWED) { - /* The UE requested IPv4 or IPv6 address and the network allows - * single addressing per bearer: - * The UE should subsequently request another PDN connection for - * the other IP version using the UE requested PDN connectivity - * procedure to the same APN with a single address PDN type - * (IPv4 or IPv6) other than the one already activated */ - pdn->addr_realloc = TRUE; - } else if ( (esm_cause == ESM_CAUSE_PDN_TYPE_IPV4_ONLY_ALLOWED) || - (esm_cause == ESM_CAUSE_PDN_TYPE_IPV6_ONLY_ALLOWED) ) { - /* The UE requested IPv4 or IPv6 address and the network allows - * IPv4 or IPv6 PDN address only: - * The UE shall not subsequently initiate another UE requested - * PDN connectivity procedure to the same APN to obtain a PDN - * type different from the one allowed by the network */ - pdn->addr_realloc = FALSE; - } else if (pdn_type != ESM_PDN_TYPE_IPV4V6) { - pdn->addr_realloc = TRUE; - } + /* Setup the IP address allocated by the network */ + if ( pdn_addr && (pdn_addr->length > 0) ) { + int length = ((pdn_addr->length < ESM_DATA_IP_ADDRESS_SIZE) ? + pdn_addr->length : ESM_DATA_IP_ADDRESS_SIZE); + memcpy(pdn->ip_addr, pdn_addr->value, length); + pdn->type = pdn_type; + } + + /* + * 3GPP TS 24.301, section 6.2.2 + * Update the address re-allocation indicator + */ + if (esm_cause == ESM_CAUSE_SINGLE_ADDRESS_BEARERS_ONLY_ALLOWED) { + /* The UE requested IPv4 or IPv6 address and the network allows + * single addressing per bearer: + * The UE should subsequently request another PDN connection for + * the other IP version using the UE requested PDN connectivity + * procedure to the same APN with a single address PDN type + * (IPv4 or IPv6) other than the one already activated */ + pdn->addr_realloc = TRUE; + } else if ( (esm_cause == ESM_CAUSE_PDN_TYPE_IPV4_ONLY_ALLOWED) || + (esm_cause == ESM_CAUSE_PDN_TYPE_IPV6_ONLY_ALLOWED) ) { + /* The UE requested IPv4 or IPv6 address and the network allows + * IPv4 or IPv6 PDN address only: + * The UE shall not subsequently initiate another UE requested + * PDN connectivity procedure to the same APN to obtain a PDN + * type different from the one allowed by the network */ + pdn->addr_realloc = FALSE; + } else if (pdn_type != ESM_PDN_TYPE_IPV4V6) { + pdn->addr_realloc = TRUE; + } - return (RETURNok); + return (RETURNok); } /**************************************************************************** @@ -861,42 +861,42 @@ static int _pdn_connectivity_update(esm_data_t *esm_data, int pid, const OctetSt ***************************************************************************/ static int _pdn_connectivity_delete(esm_data_t *esm_data, int pid) { - int pti = ESM_PT_UNASSIGNED; - - if (pid < ESM_DATA_PDN_MAX) { - if (pid != esm_data->pdn[pid].pid) { - LOG_TRACE(ERROR, - "ESM-PROC - PDN connection identifier is not valid"); - } else if (esm_data->pdn[pid].data == NULL) { - LOG_TRACE(ERROR, - "ESM-PROC - PDN connection has not been allocated"); - } else if (esm_data->pdn[pid].is_active) { - LOG_TRACE(ERROR, "ESM-PROC - PDN connection is active"); - } else { - /* Get the identity of the procedure transaction that created - * the PDN connection */ - pti = esm_data->pdn[pid].data->pti; + int pti = ESM_PT_UNASSIGNED; + + if (pid < ESM_DATA_PDN_MAX) { + if (pid != esm_data->pdn[pid].pid) { + LOG_TRACE(ERROR, + "ESM-PROC - PDN connection identifier is not valid"); + } else if (esm_data->pdn[pid].data == NULL) { + LOG_TRACE(ERROR, + "ESM-PROC - PDN connection has not been allocated"); + } else if (esm_data->pdn[pid].is_active) { + LOG_TRACE(ERROR, "ESM-PROC - PDN connection is active"); + } else { + /* Get the identity of the procedure transaction that created + * the PDN connection */ + pti = esm_data->pdn[pid].data->pti; + } } - } - if (pti != ESM_PT_UNASSIGNED) { - /* Decrement the number of PDN connections */ - esm_data->n_pdns -= 1; - /* Set the PDN connection as available */ - esm_data->pdn[pid].pid = -1; + if (pti != ESM_PT_UNASSIGNED) { + /* Decrement the number of PDN connections */ + esm_data->n_pdns -= 1; + /* Set the PDN connection as available */ + esm_data->pdn[pid].pid = -1; + + /* Release allocated PDN connection data */ + if (esm_data->pdn[pid].data->apn.length > 0) { + free(esm_data->pdn[pid].data->apn.value); + } - /* Release allocated PDN connection data */ - if (esm_data->pdn[pid].data->apn.length > 0) { - free(esm_data->pdn[pid].data->apn.value); + free(esm_data->pdn[pid].data); + esm_data->pdn[pid].data = NULL; + LOG_TRACE(WARNING, "ESM-PROC - PDN connection %d released", pid); } - free(esm_data->pdn[pid].data); - esm_data->pdn[pid].data = NULL; - LOG_TRACE(WARNING, "ESM-PROC - PDN connection %d released", pid); - } - - /* Return the procedure transaction identity */ - return (pti); + /* Return the procedure transaction identity */ + return (pti); } /**************************************************************************** @@ -916,24 +916,24 @@ static int _pdn_connectivity_delete(esm_data_t *esm_data, int pid) ***************************************************************************/ static int _pdn_connectivity_set_pti(esm_data_t *esm_data, int pid, int pti) { - if (pid < ESM_DATA_PDN_MAX) { - if (pid != esm_data->pdn[pid].pid) { - LOG_TRACE(ERROR, - "ESM-PROC - PDN connection identifier is not valid"); - } else if (esm_data->pdn[pid].data == NULL) { - LOG_TRACE(ERROR, - "ESM-PROC - PDN connection has not been allocated"); - } else if (esm_data->pdn[pid].is_active) { - LOG_TRACE(ERROR, "ESM-PROC - PDN connection is active"); - } else { - /* Update the identity of the procedure transaction assigned to - * the PDN connection */ - esm_data->pdn[pid].data->pti = pti; - return (RETURNok); + if (pid < ESM_DATA_PDN_MAX) { + if (pid != esm_data->pdn[pid].pid) { + LOG_TRACE(ERROR, + "ESM-PROC - PDN connection identifier is not valid"); + } else if (esm_data->pdn[pid].data == NULL) { + LOG_TRACE(ERROR, + "ESM-PROC - PDN connection has not been allocated"); + } else if (esm_data->pdn[pid].is_active) { + LOG_TRACE(ERROR, "ESM-PROC - PDN connection is active"); + } else { + /* Update the identity of the procedure transaction assigned to + * the PDN connection */ + esm_data->pdn[pid].data->pti = pti; + return (RETURNok); + } } - } - return (RETURNerror); + return (RETURNerror); } /**************************************************************************** @@ -953,26 +953,26 @@ static int _pdn_connectivity_set_pti(esm_data_t *esm_data, int pid, int pti) ***************************************************************************/ static int _pdn_connectivity_find_apn(esm_data_t *esm_data, const OctetString *apn) { - int i; + int i; - for (i = 0; i < ESM_DATA_PDN_MAX; i++) { - if ( (esm_data->pdn[i].pid != -1) && esm_data->pdn[i].data ) { - if (esm_data->pdn[i].data->apn.length != apn->length) { - continue; - } + for (i = 0; i < ESM_DATA_PDN_MAX; i++) { + if ( (esm_data->pdn[i].pid != -1) && esm_data->pdn[i].data ) { + if (esm_data->pdn[i].data->apn.length != apn->length) { + continue; + } - if (memcmp(esm_data->pdn[i].data->apn.value, - apn->value, apn->length) != 0) { - continue; - } + if (memcmp(esm_data->pdn[i].data->apn.value, + apn->value, apn->length) != 0) { + continue; + } - /* PDN entry found */ - break; + /* PDN entry found */ + break; + } } - } - /* Return the identifier of the PDN connection */ - return (esm_data->pdn[i].pid); + /* Return the identifier of the PDN connection */ + return (esm_data->pdn[i].pid); } /**************************************************************************** @@ -994,35 +994,35 @@ static int _pdn_connectivity_find_apn(esm_data_t *esm_data, const OctetString *a static int _pdn_connectivity_find_pdn(esm_data_t *esm_data, const OctetString *apn, const esm_proc_pdn_type_t pdn_type) { - int i; - - for (i = 0; i < ESM_DATA_PDN_MAX; i++) { - if ( (esm_data->pdn[i].pid != -1) && esm_data->pdn[i].data ) { - /* PDN connection established during initial network attachment */ - if (esm_data->pdn[i].data->apn.length == 0) { - break; - } - - /* Subsequent PDN connection established for the specified APN */ - if (esm_data->pdn[i].data->apn.length != apn->length) { - continue; - } - - if (memcmp(esm_data->pdn[i].data->apn.value, - apn->value, apn->length) != 0) { - continue; - } - - if (esm_data->pdn[i].data->type == ESM_PDN_TYPE_IPV4V6) { - break; - } - - if (esm_data->pdn[i].data->type == pdn_type) { - break; - } + int i; + + for (i = 0; i < ESM_DATA_PDN_MAX; i++) { + if ( (esm_data->pdn[i].pid != -1) && esm_data->pdn[i].data ) { + /* PDN connection established during initial network attachment */ + if (esm_data->pdn[i].data->apn.length == 0) { + break; + } + + /* Subsequent PDN connection established for the specified APN */ + if (esm_data->pdn[i].data->apn.length != apn->length) { + continue; + } + + if (memcmp(esm_data->pdn[i].data->apn.value, + apn->value, apn->length) != 0) { + continue; + } + + if (esm_data->pdn[i].data->type == ESM_PDN_TYPE_IPV4V6) { + break; + } + + if (esm_data->pdn[i].data->type == pdn_type) { + break; + } + } } - } - /* Return the identifier of the PDN connection */ - return (esm_data->pdn[i].pid); + /* Return the identifier of the PDN connection */ + return (esm_data->pdn[i].pid); } diff --git a/openair3/S1AP/s1ap_common.h b/openair3/S1AP/s1ap_common.h index 94b3e43bc65b8789e330f25179381e0d2de4ba47..fc872564c57d51a34936523c86833b107ef20996 100644 --- a/openair3/S1AP/s1ap_common.h +++ b/openair3/S1AP/s1ap_common.h @@ -90,6 +90,7 @@ extern int asn1_xer_print; # define S1AP_DEBUG(x, args...) do { fprintf(stdout, "[S1AP][D]"x, ##args); } while(0) #endif + #define S1AP_FIND_PROTOCOLIE_BY_ID(IE_TYPE, ie, container, IE_ID, mandatory) \ do {\ IE_TYPE **ptr; \ @@ -102,15 +103,17 @@ extern int asn1_xer_print; break; \ } \ } \ - if (mandatory) DevAssert(ie != NULL); \ + if (ie == NULL ) { \ + S1AP_ERROR("S1AP_FIND_PROTOCOLIE_BY_ID: %s %d: ie is NULL\n",__FILE__,__LINE__);\ + if (mandatory) _Assert_Exit_ \ + } \ } while(0) - /** \brief Function callback prototype. **/ typedef int (*s1ap_message_decoded_callback)( - uint32_t assoc_id, - uint32_t stream, - S1AP_S1AP_PDU_t *pdu + uint32_t assoc_id, + uint32_t stream, + S1AP_S1AP_PDU_t *pdu ); /** \brief Handle criticality diff --git a/openair3/S1AP/s1ap_eNB.c b/openair3/S1AP/s1ap_eNB.c index 9eab896d8314ae6e6b9ccb804d64d887cb548265..282e7b5f60354cff5c80bfb2e6de7970be5e65dc 100644 --- a/openair3/S1AP/s1ap_eNB.c +++ b/openair3/S1AP/s1ap_eNB.c @@ -349,6 +349,12 @@ void *s1ap_eNB_process_itti_msg(void *notUsed) { } break; + case S1AP_PATH_SWITCH_REQ: { + s1ap_eNB_path_switch_req(ITTI_MESSAGE_GET_INSTANCE(received_msg), + &S1AP_PATH_SWITCH_REQ(received_msg)); + } + break; + case S1AP_UE_CONTEXT_RELEASE_COMPLETE: { s1ap_ue_context_release_complete(ITTI_MESSAGE_GET_INSTANCE(received_msg), &S1AP_UE_CONTEXT_RELEASE_COMPLETE(received_msg)); diff --git a/openair3/S1AP/s1ap_eNB_decoder.c b/openair3/S1AP/s1ap_eNB_decoder.c index dd1dfadc23fecb583509b5275f4db15f36d06617..3eb182b159db73c3d981cd9078deebdf528f92e0 100644 --- a/openair3/S1AP/s1ap_eNB_decoder.c +++ b/openair3/S1AP/s1ap_eNB_decoder.c @@ -107,6 +107,11 @@ static int s1ap_eNB_decode_successful_outcome(S1AP_S1AP_PDU_t *pdu) { free(res.buffer); break; + case S1AP_ProcedureCode_id_PathSwitchRequest: + res = asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_S1AP_S1AP_PDU, pdu); + free(res.buffer); + break; + default: S1AP_ERROR("Unknown procedure ID (%d) for successfull outcome message\n", (int)pdu->choice.successfulOutcome.procedureCode); @@ -125,6 +130,10 @@ static int s1ap_eNB_decode_unsuccessful_outcome(S1AP_S1AP_PDU_t *pdu) { res = asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_S1AP_S1AP_PDU, pdu); free(res.buffer); break; + case S1AP_ProcedureCode_id_PathSwitchRequest: + res = asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_S1AP_S1AP_PDU, pdu); + free(res.buffer); + break; default: S1AP_ERROR("Unknown procedure ID (%d) for unsuccessfull outcome message\n", diff --git a/openair3/S1AP/s1ap_eNB_encoder.c b/openair3/S1AP/s1ap_eNB_encoder.c index e282d1dd78227f3104b92fd95a89d0d5128060c3..0cd46214fc050997b06144af12deb77e4a2d3c39 100644 --- a/openair3/S1AP/s1ap_eNB_encoder.c +++ b/openair3/S1AP/s1ap_eNB_encoder.c @@ -113,6 +113,11 @@ int s1ap_eNB_encode_initiating(S1AP_S1AP_PDU_t *pdu, free(res.buffer); break; + case S1AP_ProcedureCode_id_PathSwitchRequest: + res = asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_S1AP_S1AP_PDU, pdu); + free(res.buffer); + break; + default: S1AP_DEBUG("Unknown procedure ID (%d) for initiating message\n", (int)pdu->choice.initiatingMessage.procedureCode); diff --git a/openair3/S1AP/s1ap_eNB_handlers.c b/openair3/S1AP/s1ap_eNB_handlers.c index 0f7afb68f76d03d2ae832a2ce49f848db6c64504..98bdbeb54db898d154703c102d668975d2bb2c62 100644 --- a/openair3/S1AP/s1ap_eNB_handlers.c +++ b/openair3/S1AP/s1ap_eNB_handlers.c @@ -94,12 +94,22 @@ int s1ap_eNB_handle_e_rab_release_command(uint32_t assoc_id, uint32_t stream, S1AP_S1AP_PDU_t *pdu); +static +int s1ap_eNB_handle_s1_path_switch_request_ack(uint32_t assoc_id, + uint32_t stream, + S1AP_S1AP_PDU_t *pdu); + +static +int s1ap_eNB_handle_s1_path_switch_request_failure(uint32_t assoc_id, + uint32_t stream, + S1AP_S1AP_PDU_t *pdu); + /* Handlers matrix. Only eNB related procedure present here */ s1ap_message_decoded_callback messages_callback[][3] = { { 0, 0, 0 }, /* HandoverPreparation */ { 0, 0, 0 }, /* HandoverResourceAllocation */ { 0, 0, 0 }, /* HandoverNotification */ - { 0, 0, 0 }, /* PathSwitchRequest */ + { 0, s1ap_eNB_handle_s1_path_switch_request_ack, s1ap_eNB_handle_s1_path_switch_request_failure }, /* PathSwitchRequest */ { 0, 0, 0 }, /* HandoverCancel */ { s1ap_eNB_handle_e_rab_setup_request, 0, 0 }, /* E_RABSetup */ { s1ap_eNB_handle_e_rab_modify_request, 0, 0 }, /* E_RABModify */ @@ -260,13 +270,17 @@ int s1ap_eNB_handle_s1_setup_failure(uint32_t assoc_id, } S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_S1SetupFailureIEs_t, ie, container, - S1AP_ProtocolIE_ID_id_Cause, true); + S1AP_ProtocolIE_ID_id_Cause,true); - if ((ie->value.choice.Cause.present == S1AP_Cause_PR_misc) && - (ie->value.choice.Cause.choice.misc == S1AP_CauseMisc_unspecified)) { - S1AP_WARN("Received s1 setup failure for MME... MME is not ready\n"); + if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */ + if ((ie->value.choice.Cause.present == S1AP_Cause_PR_misc) && + (ie->value.choice.Cause.choice.misc == S1AP_CauseMisc_unspecified)) { + S1AP_WARN("Received s1 setup failure for MME... MME is not ready\n"); + } else { + S1AP_ERROR("Received s1 setup failure for MME... please check your parameters\n"); + } } else { - S1AP_ERROR("Received s1 setup failure for MME... please check your parameters\n"); + return -1; } mme_desc_p->state = S1AP_ENB_STATE_WAITING; @@ -300,62 +314,73 @@ int s1ap_eNB_handle_s1_setup_response(uint32_t assoc_id, S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_S1SetupResponseIEs_t, ie, container, S1AP_ProtocolIE_ID_id_ServedGUMMEIs, true); + /* The list of served gummei can contain at most 8 elements. * LTE related gummei is the first element in the list, i.e with an id of 0. */ - S1AP_DEBUG("servedGUMMEIs.list.count %d\n", ie->value.choice.ServedGUMMEIs.list.count); - DevAssert(ie->value.choice.ServedGUMMEIs.list.count > 0); - DevAssert(ie->value.choice.ServedGUMMEIs.list.count <= S1AP_maxnoofRATs); - - for (i = 0; i < ie->value.choice.ServedGUMMEIs.list.count; i++) { - S1AP_ServedGUMMEIsItem_t *gummei_item_p; - struct served_gummei_s *new_gummei_p; - int j; - gummei_item_p = ie->value.choice.ServedGUMMEIs.list.array[i]; - new_gummei_p = calloc(1, sizeof(struct served_gummei_s)); - STAILQ_INIT(&new_gummei_p->served_plmns); - STAILQ_INIT(&new_gummei_p->served_group_ids); - STAILQ_INIT(&new_gummei_p->mme_codes); - S1AP_DEBUG("servedPLMNs.list.count %d\n", gummei_item_p->servedPLMNs.list.count); - - for (j = 0; j < gummei_item_p->servedPLMNs.list.count; j++) { - S1AP_PLMNidentity_t *plmn_identity_p; - struct plmn_identity_s *new_plmn_identity_p; - plmn_identity_p = gummei_item_p->servedPLMNs.list.array[j]; - new_plmn_identity_p = calloc(1, sizeof(struct plmn_identity_s)); - TBCD_TO_MCC_MNC(plmn_identity_p, new_plmn_identity_p->mcc, - new_plmn_identity_p->mnc, new_plmn_identity_p->mnc_digit_length); - STAILQ_INSERT_TAIL(&new_gummei_p->served_plmns, new_plmn_identity_p, next); - new_gummei_p->nb_served_plmns++; - } + if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */ + S1AP_DEBUG("servedGUMMEIs.list.count %d\n", ie->value.choice.ServedGUMMEIs.list.count); + DevAssert(ie->value.choice.ServedGUMMEIs.list.count > 0); + DevAssert(ie->value.choice.ServedGUMMEIs.list.count <= S1AP_maxnoofRATs); + + for (i = 0; i < ie->value.choice.ServedGUMMEIs.list.count; i++) { + S1AP_ServedGUMMEIsItem_t *gummei_item_p; + struct served_gummei_s *new_gummei_p; + int j; + gummei_item_p = ie->value.choice.ServedGUMMEIs.list.array[i]; + new_gummei_p = calloc(1, sizeof(struct served_gummei_s)); + STAILQ_INIT(&new_gummei_p->served_plmns); + STAILQ_INIT(&new_gummei_p->served_group_ids); + STAILQ_INIT(&new_gummei_p->mme_codes); + S1AP_DEBUG("servedPLMNs.list.count %d\n", gummei_item_p->servedPLMNs.list.count); + + for (j = 0; j < gummei_item_p->servedPLMNs.list.count; j++) { + S1AP_PLMNidentity_t *plmn_identity_p; + struct plmn_identity_s *new_plmn_identity_p; + plmn_identity_p = gummei_item_p->servedPLMNs.list.array[j]; + new_plmn_identity_p = calloc(1, sizeof(struct plmn_identity_s)); + TBCD_TO_MCC_MNC(plmn_identity_p, new_plmn_identity_p->mcc, + new_plmn_identity_p->mnc, new_plmn_identity_p->mnc_digit_length); + STAILQ_INSERT_TAIL(&new_gummei_p->served_plmns, new_plmn_identity_p, next); + new_gummei_p->nb_served_plmns++; + } - for (j = 0; j < gummei_item_p->servedGroupIDs.list.count; j++) { - S1AP_MME_Group_ID_t *mme_group_id_p; - struct served_group_id_s *new_group_id_p; - mme_group_id_p = gummei_item_p->servedGroupIDs.list.array[j]; - new_group_id_p = calloc(1, sizeof(struct served_group_id_s)); - OCTET_STRING_TO_INT16(mme_group_id_p, new_group_id_p->mme_group_id); - STAILQ_INSERT_TAIL(&new_gummei_p->served_group_ids, new_group_id_p, next); - new_gummei_p->nb_group_id++; - } + for (j = 0; j < gummei_item_p->servedGroupIDs.list.count; j++) { + S1AP_MME_Group_ID_t *mme_group_id_p; + struct served_group_id_s *new_group_id_p; + mme_group_id_p = gummei_item_p->servedGroupIDs.list.array[j]; + new_group_id_p = calloc(1, sizeof(struct served_group_id_s)); + OCTET_STRING_TO_INT16(mme_group_id_p, new_group_id_p->mme_group_id); + STAILQ_INSERT_TAIL(&new_gummei_p->served_group_ids, new_group_id_p, next); + new_gummei_p->nb_group_id++; + } - for (j = 0; j < gummei_item_p->servedMMECs.list.count; j++) { - S1AP_MME_Code_t *mme_code_p; - struct mme_code_s *new_mme_code_p; - mme_code_p = gummei_item_p->servedMMECs.list.array[j]; - new_mme_code_p = calloc(1, sizeof(struct mme_code_s)); - OCTET_STRING_TO_INT8(mme_code_p, new_mme_code_p->mme_code); - STAILQ_INSERT_TAIL(&new_gummei_p->mme_codes, new_mme_code_p, next); - new_gummei_p->nb_mme_code++; - } + for (j = 0; j < gummei_item_p->servedMMECs.list.count; j++) { + S1AP_MME_Code_t *mme_code_p; + struct mme_code_s *new_mme_code_p; + mme_code_p = gummei_item_p->servedMMECs.list.array[j]; + new_mme_code_p = calloc(1, sizeof(struct mme_code_s)); + OCTET_STRING_TO_INT8(mme_code_p, new_mme_code_p->mme_code); + STAILQ_INSERT_TAIL(&new_gummei_p->mme_codes, new_mme_code_p, next); + new_gummei_p->nb_mme_code++; + } - STAILQ_INSERT_TAIL(&mme_desc_p->served_gummei, new_gummei_p, next); + STAILQ_INSERT_TAIL(&mme_desc_p->served_gummei, new_gummei_p, next); + } + } else { + return -1; } /* Set the capacity of this MME */ S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_S1SetupResponseIEs_t, ie, container, S1AP_ProtocolIE_ID_id_RelativeMMECapacity, true); - mme_desc_p->relative_mme_capacity = ie->value.choice.RelativeMMECapacity; + + if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */ + mme_desc_p->relative_mme_capacity = ie->value.choice.RelativeMMECapacity; + } else { + return -1; + } + /* Optionaly set the mme name */ S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_S1SetupResponseIEs_t, ie, container, S1AP_ProtocolIE_ID_id_MMEname, false); @@ -404,7 +429,7 @@ int s1ap_eNB_handle_error_indication(uint32_t assoc_id, S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID, false); /* optional */ - if (!ie) { + if (ie != NULL) { S1AP_WARN("Received S1 Error indication MME UE S1AP ID 0x%lx\n", ie->value.choice.MME_UE_S1AP_ID); } @@ -412,7 +437,7 @@ int s1ap_eNB_handle_error_indication(uint32_t assoc_id, S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID, false); /* optional */ - if (!ie) { + if (ie != NULL) { S1AP_WARN("Received S1 Error indication eNB UE S1AP ID 0x%lx\n", ie->value.choice.ENB_UE_S1AP_ID); } @@ -744,17 +769,28 @@ int s1ap_eNB_handle_initial_context_request(uint32_t assoc_id, /* id-MME-UE-S1AP-ID */ S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_InitialContextSetupRequestIEs_t, ie, container, S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID, true); - mme_ue_s1ap_id = ie->value.choice.MME_UE_S1AP_ID; + + if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */ + mme_ue_s1ap_id = ie->value.choice.MME_UE_S1AP_ID; + } else { + return -1; + } + /* id-eNB-UE-S1AP-ID */ S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_InitialContextSetupRequestIEs_t, ie, container, S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID, true); - enb_ue_s1ap_id = ie->value.choice.ENB_UE_S1AP_ID; - if ((ue_desc_p = s1ap_eNB_get_ue_context(mme_desc_p->s1ap_eNB_instance, - enb_ue_s1ap_id)) == NULL) { - S1AP_ERROR("[SCTP %d] Received initial context setup request for non " - "existing UE context 0x%06lx\n", assoc_id, - enb_ue_s1ap_id); + if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */ + enb_ue_s1ap_id = ie->value.choice.ENB_UE_S1AP_ID; + + if ((ue_desc_p = s1ap_eNB_get_ue_context(mme_desc_p->s1ap_eNB_instance, + enb_ue_s1ap_id)) == NULL) { + S1AP_ERROR("[SCTP %d] Received initial context setup request for non " + "existing UE context 0x%06lx\n", assoc_id, + enb_ue_s1ap_id); + return -1; + } + } else { return -1; } @@ -771,67 +807,91 @@ int s1ap_eNB_handle_initial_context_request(uint32_t assoc_id, S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).ue_initial_id = ue_desc_p->ue_initial_id; ue_desc_p->ue_initial_id = 0; S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).eNB_ue_s1ap_id = ue_desc_p->eNB_ue_s1ap_id; + S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).mme_ue_s1ap_id = ue_desc_p->mme_ue_s1ap_id; /* id-uEaggregateMaximumBitrate */ S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_InitialContextSetupRequestIEs_t, ie, container, S1AP_ProtocolIE_ID_id_uEaggregateMaximumBitrate, true); - asn_INTEGER2ulong(&(ie->value.choice.UEAggregateMaximumBitrate.uEaggregateMaximumBitRateUL), - &(S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).ue_ambr.br_ul)); - asn_INTEGER2ulong(&(ie->value.choice.UEAggregateMaximumBitrate.uEaggregateMaximumBitRateDL), - &(S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).ue_ambr.br_dl)); - /* id-E-RABToBeSetupListCtxtSUReq */ + + if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */ + asn_INTEGER2ulong(&(ie->value.choice.UEAggregateMaximumBitrate.uEaggregateMaximumBitRateUL), + &(S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).ue_ambr.br_ul)); + asn_INTEGER2ulong(&(ie->value.choice.UEAggregateMaximumBitrate.uEaggregateMaximumBitRateDL), + &(S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).ue_ambr.br_dl)); + /* id-E-RABToBeSetupListCtxtSUReq */ + } else { + return -1; + } + S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_InitialContextSetupRequestIEs_t, ie, container, S1AP_ProtocolIE_ID_id_E_RABToBeSetupListCtxtSUReq, true); - S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).nb_of_e_rabs = - ie->value.choice.E_RABToBeSetupListCtxtSUReq.list.count; - - for (i = 0; i < ie->value.choice.E_RABToBeSetupListCtxtSUReq.list.count; i++) { - S1AP_E_RABToBeSetupItemCtxtSUReq_t *item_p; - item_p = &(((S1AP_E_RABToBeSetupItemCtxtSUReqIEs_t *)ie->value.choice.E_RABToBeSetupListCtxtSUReq.list.array[i])->value.choice.E_RABToBeSetupItemCtxtSUReq); - S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].e_rab_id = item_p->e_RAB_ID; - - if (item_p->nAS_PDU != NULL) { - /* Only copy NAS pdu if present */ - S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].nas_pdu.length = item_p->nAS_PDU->size; - S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].nas_pdu.buffer = - malloc(sizeof(uint8_t) * item_p->nAS_PDU->size); - memcpy(S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].nas_pdu.buffer, - item_p->nAS_PDU->buf, item_p->nAS_PDU->size); - S1AP_DEBUG("Received NAS message with the E_RAB setup procedure\n"); - } else { - S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].nas_pdu.length = 0; - S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].nas_pdu.buffer = NULL; - } - /* Set the transport layer address */ - memcpy(S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].sgw_addr.buffer, - item_p->transportLayerAddress.buf, item_p->transportLayerAddress.size); - S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].sgw_addr.length = - item_p->transportLayerAddress.size * 8 - item_p->transportLayerAddress.bits_unused; - /* GTP tunnel endpoint ID */ - OCTET_STRING_TO_INT32(&item_p->gTP_TEID, S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].gtp_teid); - /* Set the QOS informations */ - S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].qos.qci = item_p->e_RABlevelQoSParameters.qCI; - S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].qos.allocation_retention_priority.priority_level = - item_p->e_RABlevelQoSParameters.allocationRetentionPriority.priorityLevel; - S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].qos.allocation_retention_priority.pre_emp_capability = - item_p->e_RABlevelQoSParameters.allocationRetentionPriority.pre_emptionCapability; - S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].qos.allocation_retention_priority.pre_emp_vulnerability = - item_p->e_RABlevelQoSParameters.allocationRetentionPriority.pre_emptionVulnerability; + if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */ + S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).nb_of_e_rabs = + ie->value.choice.E_RABToBeSetupListCtxtSUReq.list.count; + + for (i = 0; i < ie->value.choice.E_RABToBeSetupListCtxtSUReq.list.count; i++) { + S1AP_E_RABToBeSetupItemCtxtSUReq_t *item_p; + item_p = &(((S1AP_E_RABToBeSetupItemCtxtSUReqIEs_t *)ie->value.choice.E_RABToBeSetupListCtxtSUReq.list.array[i])->value.choice.E_RABToBeSetupItemCtxtSUReq); + S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].e_rab_id = item_p->e_RAB_ID; + + if (item_p->nAS_PDU != NULL) { + /* Only copy NAS pdu if present */ + S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].nas_pdu.length = item_p->nAS_PDU->size; + S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].nas_pdu.buffer = + malloc(sizeof(uint8_t) * item_p->nAS_PDU->size); + memcpy(S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].nas_pdu.buffer, + item_p->nAS_PDU->buf, item_p->nAS_PDU->size); + S1AP_DEBUG("Received NAS message with the E_RAB setup procedure\n"); + } else { + S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].nas_pdu.length = 0; + S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].nas_pdu.buffer = NULL; + } + + /* Set the transport layer address */ + memcpy(S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].sgw_addr.buffer, + item_p->transportLayerAddress.buf, item_p->transportLayerAddress.size); + S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].sgw_addr.length = + item_p->transportLayerAddress.size * 8 - item_p->transportLayerAddress.bits_unused; + /* GTP tunnel endpoint ID */ + OCTET_STRING_TO_INT32(&item_p->gTP_TEID, S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].gtp_teid); + /* Set the QOS informations */ + S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].qos.qci = item_p->e_RABlevelQoSParameters.qCI; + S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].qos.allocation_retention_priority.priority_level = + item_p->e_RABlevelQoSParameters.allocationRetentionPriority.priorityLevel; + S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].qos.allocation_retention_priority.pre_emp_capability = + item_p->e_RABlevelQoSParameters.allocationRetentionPriority.pre_emptionCapability; + S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).e_rab_param[i].qos.allocation_retention_priority.pre_emp_vulnerability = + item_p->e_RABlevelQoSParameters.allocationRetentionPriority.pre_emptionVulnerability; + } /* for i... */ + } else {/* ie != NULL */ + return -1; } /* id-UESecurityCapabilities */ S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_InitialContextSetupRequestIEs_t, ie, container, S1AP_ProtocolIE_ID_id_UESecurityCapabilities, true); - S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).security_capabilities.encryption_algorithms = - BIT_STRING_to_uint16(&ie->value.choice.UESecurityCapabilities.encryptionAlgorithms); - S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).security_capabilities.integrity_algorithms = - BIT_STRING_to_uint16(&ie->value.choice.UESecurityCapabilities.integrityProtectionAlgorithms); - /* id-SecurityKey : Copy the security key */ + + if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */ + S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).security_capabilities.encryption_algorithms = + BIT_STRING_to_uint16(&ie->value.choice.UESecurityCapabilities.encryptionAlgorithms); + S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).security_capabilities.integrity_algorithms = + BIT_STRING_to_uint16(&ie->value.choice.UESecurityCapabilities.integrityProtectionAlgorithms); + /* id-SecurityKey : Copy the security key */ + } else {/* ie != NULL */ + return -1; + } + S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_InitialContextSetupRequestIEs_t, ie, container, S1AP_ProtocolIE_ID_id_SecurityKey, true); - memcpy(&S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).security_key, - ie->value.choice.SecurityKey.buf, ie->value.choice.SecurityKey.size); - itti_send_msg_to_task(TASK_RRC_ENB, ue_desc_p->eNB_instance->instance, message_p); + + if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */ + memcpy(&S1AP_INITIAL_CONTEXT_SETUP_REQ(message_p).security_key, + ie->value.choice.SecurityKey.buf, ie->value.choice.SecurityKey.size); + itti_send_msg_to_task(TASK_RRC_ENB, ue_desc_p->eNB_instance->instance, message_p); + } else {/* ie != NULL */ + return -1; + } + return 0; } @@ -859,57 +919,61 @@ int s1ap_eNB_handle_ue_context_release_command(uint32_t assoc_id, S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_UEContextReleaseCommand_IEs_t, ie, container, S1AP_ProtocolIE_ID_id_UE_S1AP_IDs, true); - switch (ie->value.choice.UE_S1AP_IDs.present) { - case S1AP_UE_S1AP_IDs_PR_uE_S1AP_ID_pair: - enb_ue_s1ap_id = ie->value.choice.UE_S1AP_IDs.choice.uE_S1AP_ID_pair.eNB_UE_S1AP_ID; - mme_ue_s1ap_id = ie->value.choice.UE_S1AP_IDs.choice.uE_S1AP_ID_pair.mME_UE_S1AP_ID; - MSC_LOG_RX_MESSAGE( - MSC_S1AP_ENB, - MSC_S1AP_MME, - NULL,0, - "0 UEContextRelease/%s eNB_ue_s1ap_id "S1AP_UE_ID_FMT" mme_ue_s1ap_id "S1AP_UE_ID_FMT" len %u", - s1ap_direction2String(pdu->present - 1), - enb_ue_s1ap_id, - mme_ue_s1ap_id); - - if ((ue_desc_p = s1ap_eNB_get_ue_context(mme_desc_p->s1ap_eNB_instance, - enb_ue_s1ap_id)) == NULL) { - S1AP_ERROR("[SCTP %d] Received UE context release command for non " - "existing UE context 0x%06lx\n", - assoc_id, - enb_ue_s1ap_id); - return -1; - } else { - MSC_LOG_TX_MESSAGE( + if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */ + switch (ie->value.choice.UE_S1AP_IDs.present) { + case S1AP_UE_S1AP_IDs_PR_uE_S1AP_ID_pair: + enb_ue_s1ap_id = ie->value.choice.UE_S1AP_IDs.choice.uE_S1AP_ID_pair.eNB_UE_S1AP_ID; + mme_ue_s1ap_id = ie->value.choice.UE_S1AP_IDs.choice.uE_S1AP_ID_pair.mME_UE_S1AP_ID; + MSC_LOG_RX_MESSAGE( MSC_S1AP_ENB, - MSC_RRC_ENB, + MSC_S1AP_MME, NULL,0, - "0 S1AP_UE_CONTEXT_RELEASE_COMMAND/%d eNB_ue_s1ap_id "S1AP_UE_ID_FMT" ", - enb_ue_s1ap_id); - message_p = itti_alloc_new_message(TASK_S1AP, S1AP_UE_CONTEXT_RELEASE_COMMAND); - - if (ue_desc_p->mme_ue_s1ap_id == 0) { // case of Detach Request and switch off from RRC_IDLE mode - ue_desc_p->mme_ue_s1ap_id = mme_ue_s1ap_id; + "0 UEContextRelease/%s eNB_ue_s1ap_id "S1AP_UE_ID_FMT" mme_ue_s1ap_id "S1AP_UE_ID_FMT" len %u", + s1ap_direction2String(pdu->present - 1), + enb_ue_s1ap_id, + mme_ue_s1ap_id); + + if ((ue_desc_p = s1ap_eNB_get_ue_context(mme_desc_p->s1ap_eNB_instance, + enb_ue_s1ap_id)) == NULL) { + S1AP_ERROR("[SCTP %d] Received UE context release command for non " + "existing UE context 0x%06lx\n", + assoc_id, + enb_ue_s1ap_id); + return -1; + } else { + MSC_LOG_TX_MESSAGE( + MSC_S1AP_ENB, + MSC_RRC_ENB, + NULL,0, + "0 S1AP_UE_CONTEXT_RELEASE_COMMAND/%d eNB_ue_s1ap_id "S1AP_UE_ID_FMT" ", + enb_ue_s1ap_id); + message_p = itti_alloc_new_message(TASK_S1AP, S1AP_UE_CONTEXT_RELEASE_COMMAND); + + if (ue_desc_p->mme_ue_s1ap_id == 0) { // case of Detach Request and switch off from RRC_IDLE mode + ue_desc_p->mme_ue_s1ap_id = mme_ue_s1ap_id; + } + + S1AP_UE_CONTEXT_RELEASE_COMMAND(message_p).eNB_ue_s1ap_id = enb_ue_s1ap_id; + itti_send_msg_to_task(TASK_RRC_ENB, ue_desc_p->eNB_instance->instance, message_p); + return 0; } - S1AP_UE_CONTEXT_RELEASE_COMMAND(message_p).eNB_ue_s1ap_id = enb_ue_s1ap_id; - itti_send_msg_to_task(TASK_RRC_ENB, ue_desc_p->eNB_instance->instance, message_p); - return 0; - } - - break; + break; - //#warning "TODO mapping mme_ue_s1ap_id enb_ue_s1ap_id?" + //#warning "TODO mapping mme_ue_s1ap_id enb_ue_s1ap_id?" - case S1AP_UE_S1AP_IDs_PR_mME_UE_S1AP_ID: - mme_ue_s1ap_id = ie->value.choice.UE_S1AP_IDs.choice.uE_S1AP_ID_pair.mME_UE_S1AP_ID; - S1AP_ERROR("TO DO mapping mme_ue_s1ap_id enb_ue_s1ap_id"); - (void)mme_ue_s1ap_id; /* TODO: remove - it's to remove gcc warning about unused var */ + case S1AP_UE_S1AP_IDs_PR_mME_UE_S1AP_ID: + mme_ue_s1ap_id = ie->value.choice.UE_S1AP_IDs.choice.uE_S1AP_ID_pair.mME_UE_S1AP_ID; + S1AP_ERROR("TO DO mapping mme_ue_s1ap_id enb_ue_s1ap_id"); + (void)mme_ue_s1ap_id; /* TODO: remove - it's to remove gcc warning about unused var */ - case S1AP_UE_S1AP_IDs_PR_NOTHING: - default: - S1AP_ERROR("S1AP_UE_CONTEXT_RELEASE_COMMAND not processed, missing info elements"); - return -1; + case S1AP_UE_S1AP_IDs_PR_NOTHING: + default: + S1AP_ERROR("S1AP_UE_CONTEXT_RELEASE_COMMAND not processed, missing info elements"); + return -1; + } + } else { + return -1; } S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_UEContextReleaseCommand_IEs_t, ie, container, @@ -941,11 +1005,22 @@ int s1ap_eNB_handle_e_rab_setup_request(uint32_t assoc_id, /* id-MME-UE-S1AP-ID */ S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_E_RABSetupRequestIEs_t, ie, container, S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID, true); - mme_ue_s1ap_id = ie->value.choice.MME_UE_S1AP_ID; + + if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */ + mme_ue_s1ap_id = ie->value.choice.MME_UE_S1AP_ID; + } else { + return -1; + } + /* id-eNB-UE-S1AP-ID */ S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_E_RABSetupRequestIEs_t, ie, container, S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID, true); - enb_ue_s1ap_id = ie->value.choice.ENB_UE_S1AP_ID; + + if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */ + enb_ue_s1ap_id = ie->value.choice.ENB_UE_S1AP_ID; + } else { + return -1; + } if ((ue_desc_p = s1ap_eNB_get_ue_context(mme_desc_p->s1ap_eNB_instance, enb_ue_s1ap_id)) == NULL) { @@ -975,51 +1050,56 @@ int s1ap_eNB_handle_e_rab_setup_request(uint32_t assoc_id, S1AP_E_RAB_SETUP_REQ(message_p).eNB_ue_s1ap_id = enb_ue_s1ap_id; S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_E_RABSetupRequestIEs_t, ie, container, S1AP_ProtocolIE_ID_id_E_RABToBeSetupListBearerSUReq, true); - S1AP_E_RAB_SETUP_REQ(message_p).nb_e_rabs_tosetup = - ie->value.choice.E_RABToBeSetupListBearerSUReq.list.count; - - for (i = 0; i < ie->value.choice.E_RABToBeSetupListBearerSUReq.list.count; i++) { - S1AP_E_RABToBeSetupItemBearerSUReq_t *item_p; - item_p = &(((S1AP_E_RABToBeSetupItemBearerSUReqIEs_t *)ie->value.choice.E_RABToBeSetupListBearerSUReq.list.array[i])->value.choice.E_RABToBeSetupItemBearerSUReq); - S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].e_rab_id = item_p->e_RAB_ID; - - // check for the NAS PDU - if (item_p->nAS_PDU.size > 0 ) { - S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].nas_pdu.length = item_p->nAS_PDU.size; - S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].nas_pdu.buffer = malloc(sizeof(uint8_t) * item_p->nAS_PDU.size); - memcpy(S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].nas_pdu.buffer, - item_p->nAS_PDU.buf, item_p->nAS_PDU.size); - // S1AP_INFO("received a NAS PDU with size %d (%02x.%02x)\n",S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].nas_pdu.length, item_p->nAS_PDU.buf[0], item_p->nAS_PDU.buf[1]); - } else { - S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].nas_pdu.length = 0; - S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].nas_pdu.buffer = NULL; - S1AP_WARN("NAS PDU is not provided, generate a E_RAB_SETUP Failure (TBD) back to MME \n"); - // return -1; - } - /* Set the transport layer address */ - memcpy(S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].sgw_addr.buffer, - item_p->transportLayerAddress.buf, item_p->transportLayerAddress.size); - S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].sgw_addr.length = - item_p->transportLayerAddress.size * 8 - item_p->transportLayerAddress.bits_unused; - /* S1AP_INFO("sgw addr %s len: %d (size %d, index %d)\n", - S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].sgw_addr.buffer, - S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].sgw_addr.length, - item_p->transportLayerAddress.size, i); - */ - /* GTP tunnel endpoint ID */ - OCTET_STRING_TO_INT32(&item_p->gTP_TEID, S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].gtp_teid); - /* Set the QOS informations */ - S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].qos.qci = item_p->e_RABlevelQoSParameters.qCI; - S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].qos.allocation_retention_priority.priority_level = - item_p->e_RABlevelQoSParameters.allocationRetentionPriority.priorityLevel; - S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].qos.allocation_retention_priority.pre_emp_capability = - item_p->e_RABlevelQoSParameters.allocationRetentionPriority.pre_emptionCapability; - S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].qos.allocation_retention_priority.pre_emp_vulnerability = - item_p->e_RABlevelQoSParameters.allocationRetentionPriority.pre_emptionVulnerability; + if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */ + S1AP_E_RAB_SETUP_REQ(message_p).nb_e_rabs_tosetup = + ie->value.choice.E_RABToBeSetupListBearerSUReq.list.count; + + for (i = 0; i < ie->value.choice.E_RABToBeSetupListBearerSUReq.list.count; i++) { + S1AP_E_RABToBeSetupItemBearerSUReq_t *item_p; + item_p = &(((S1AP_E_RABToBeSetupItemBearerSUReqIEs_t *)ie->value.choice.E_RABToBeSetupListBearerSUReq.list.array[i])->value.choice.E_RABToBeSetupItemBearerSUReq); + S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].e_rab_id = item_p->e_RAB_ID; + + // check for the NAS PDU + if (item_p->nAS_PDU.size > 0 ) { + S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].nas_pdu.length = item_p->nAS_PDU.size; + S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].nas_pdu.buffer = malloc(sizeof(uint8_t) * item_p->nAS_PDU.size); + memcpy(S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].nas_pdu.buffer, + item_p->nAS_PDU.buf, item_p->nAS_PDU.size); + // S1AP_INFO("received a NAS PDU with size %d (%02x.%02x)\n",S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].nas_pdu.length, item_p->nAS_PDU.buf[0], item_p->nAS_PDU.buf[1]); + } else { + S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].nas_pdu.length = 0; + S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].nas_pdu.buffer = NULL; + S1AP_WARN("NAS PDU is not provided, generate a E_RAB_SETUP Failure (TBD) back to MME \n"); + } + + /* Set the transport layer address */ + memcpy(S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].sgw_addr.buffer, + item_p->transportLayerAddress.buf, item_p->transportLayerAddress.size); + S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].sgw_addr.length = + item_p->transportLayerAddress.size * 8 - item_p->transportLayerAddress.bits_unused; + /* S1AP_INFO("sgw addr %s len: %d (size %d, index %d)\n", + S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].sgw_addr.buffer, + S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].sgw_addr.length, + item_p->transportLayerAddress.size, i); + */ + /* GTP tunnel endpoint ID */ + OCTET_STRING_TO_INT32(&item_p->gTP_TEID, S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].gtp_teid); + /* Set the QOS informations */ + S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].qos.qci = item_p->e_RABlevelQoSParameters.qCI; + S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].qos.allocation_retention_priority.priority_level = + item_p->e_RABlevelQoSParameters.allocationRetentionPriority.priorityLevel; + S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].qos.allocation_retention_priority.pre_emp_capability = + item_p->e_RABlevelQoSParameters.allocationRetentionPriority.pre_emptionCapability; + S1AP_E_RAB_SETUP_REQ(message_p).e_rab_setup_params[i].qos.allocation_retention_priority.pre_emp_vulnerability = + item_p->e_RABlevelQoSParameters.allocationRetentionPriority.pre_emptionVulnerability; + } /* for i... */ + + itti_send_msg_to_task(TASK_RRC_ENB, ue_desc_p->eNB_instance->instance, message_p); + } else { + return -1; } - itti_send_msg_to_task(TASK_RRC_ENB, ue_desc_p->eNB_instance->instance, message_p); return 0; } @@ -1063,49 +1143,59 @@ int s1ap_eNB_handle_paging(uint32_t assoc_id, /* id-UEIdentityIndexValue : convert UE Identity Index value */ S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_PagingIEs_t, ie, container, S1AP_ProtocolIE_ID_id_UEIdentityIndexValue, true); - S1AP_PAGING_IND(message_p).ue_index_value = BIT_STRING_to_uint32(&ie->value.choice.UEIdentityIndexValue); - S1AP_DEBUG("[SCTP %d] Received Paging ue_index_value (%d)\n", - assoc_id,(uint32_t)S1AP_PAGING_IND(message_p).ue_index_value); - S1AP_PAGING_IND(message_p).ue_paging_identity.choice.s_tmsi.mme_code = 0; - S1AP_PAGING_IND(message_p).ue_paging_identity.choice.s_tmsi.m_tmsi = 0; + + if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */ + S1AP_PAGING_IND(message_p).ue_index_value = BIT_STRING_to_uint32(&ie->value.choice.UEIdentityIndexValue); + S1AP_DEBUG("[SCTP %d] Received Paging ue_index_value (%d)\n", + assoc_id,(uint32_t)S1AP_PAGING_IND(message_p).ue_index_value); + S1AP_PAGING_IND(message_p).ue_paging_identity.choice.s_tmsi.mme_code = 0; + S1AP_PAGING_IND(message_p).ue_paging_identity.choice.s_tmsi.m_tmsi = 0; + } else { + return -1; + } + /* id-UEPagingID */ S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_PagingIEs_t, ie, container, S1AP_ProtocolIE_ID_id_UEPagingID, true); - /* convert UE Paging Identity */ - if (ie->value.choice.UEPagingID.present == S1AP_UEPagingID_PR_s_TMSI) { - S1AP_PAGING_IND(message_p).ue_paging_identity.presenceMask = UE_PAGING_IDENTITY_s_tmsi; - OCTET_STRING_TO_INT8(&ie->value.choice.UEPagingID.choice.s_TMSI.mMEC, S1AP_PAGING_IND(message_p).ue_paging_identity.choice.s_tmsi.mme_code); - OCTET_STRING_TO_INT32(&ie->value.choice.UEPagingID.choice.s_TMSI.m_TMSI, S1AP_PAGING_IND(message_p).ue_paging_identity.choice.s_tmsi.m_tmsi); - } else if (ie->value.choice.UEPagingID.present == S1AP_UEPagingID_PR_iMSI) { - S1AP_PAGING_IND(message_p).ue_paging_identity.presenceMask = UE_PAGING_IDENTITY_imsi; - S1AP_PAGING_IND(message_p).ue_paging_identity.choice.imsi.length = 0; - - for (int i = 0; i < ie->value.choice.UEPagingID.choice.iMSI.size; i++) { - S1AP_PAGING_IND(message_p).ue_paging_identity.choice.imsi.buffer[2*i] = (uint8_t)(ie->value.choice.UEPagingID.choice.iMSI.buf[i] & 0x0F ); - S1AP_PAGING_IND(message_p).ue_paging_identity.choice.imsi.length++; - S1AP_PAGING_IND(message_p).ue_paging_identity.choice.imsi.buffer[2*i+1] = (uint8_t)((ie->value.choice.UEPagingID.choice.iMSI.buf[i]>>4) & 0x0F); - LOG_D(S1AP,"paging : i %d %d imsi %d %d \n",2*i,2*i+1,S1AP_PAGING_IND(message_p).ue_paging_identity.choice.imsi.buffer[2*i], S1AP_PAGING_IND(message_p).ue_paging_identity.choice.imsi.buffer[2*i+1]); - - if (S1AP_PAGING_IND(message_p).ue_paging_identity.choice.imsi.buffer[2*i+1] == 0x0F) { - if(i != ie->value.choice.UEPagingID.choice.iMSI.size - 1) { - /* invalid paging_p->uePagingID.choise.iMSI.buffer */ - S1AP_ERROR("[SCTP %d] Received Paging : uePagingID.choise.iMSI error(i %d 0x0F)\n", assoc_id,i); - return -1; - } - } else { + if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */ + /* convert UE Paging Identity */ + if (ie->value.choice.UEPagingID.present == S1AP_UEPagingID_PR_s_TMSI) { + S1AP_PAGING_IND(message_p).ue_paging_identity.presenceMask = UE_PAGING_IDENTITY_s_tmsi; + OCTET_STRING_TO_INT8(&ie->value.choice.UEPagingID.choice.s_TMSI.mMEC, S1AP_PAGING_IND(message_p).ue_paging_identity.choice.s_tmsi.mme_code); + OCTET_STRING_TO_INT32(&ie->value.choice.UEPagingID.choice.s_TMSI.m_TMSI, S1AP_PAGING_IND(message_p).ue_paging_identity.choice.s_tmsi.m_tmsi); + } else if (ie->value.choice.UEPagingID.present == S1AP_UEPagingID_PR_iMSI) { + S1AP_PAGING_IND(message_p).ue_paging_identity.presenceMask = UE_PAGING_IDENTITY_imsi; + S1AP_PAGING_IND(message_p).ue_paging_identity.choice.imsi.length = 0; + + for (int i = 0; i < ie->value.choice.UEPagingID.choice.iMSI.size; i++) { + S1AP_PAGING_IND(message_p).ue_paging_identity.choice.imsi.buffer[2*i] = (uint8_t)(ie->value.choice.UEPagingID.choice.iMSI.buf[i] & 0x0F ); S1AP_PAGING_IND(message_p).ue_paging_identity.choice.imsi.length++; - } - } + S1AP_PAGING_IND(message_p).ue_paging_identity.choice.imsi.buffer[2*i+1] = (uint8_t)((ie->value.choice.UEPagingID.choice.iMSI.buf[i]>>4) & 0x0F); + LOG_D(S1AP,"paging : i %d %d imsi %d %d \n",2*i,2*i+1,S1AP_PAGING_IND(message_p).ue_paging_identity.choice.imsi.buffer[2*i], S1AP_PAGING_IND(message_p).ue_paging_identity.choice.imsi.buffer[2*i+1]); + + if (S1AP_PAGING_IND(message_p).ue_paging_identity.choice.imsi.buffer[2*i+1] == 0x0F) { + if(i != ie->value.choice.UEPagingID.choice.iMSI.size - 1) { + /* invalid paging_p->uePagingID.choise.iMSI.buffer */ + S1AP_ERROR("[SCTP %d] Received Paging : uePagingID.choise.iMSI error(i %d 0x0F)\n", assoc_id,i); + return -1; + } + } else { + S1AP_PAGING_IND(message_p).ue_paging_identity.choice.imsi.length++; + } + } /* for i... */ - if (S1AP_PAGING_IND(message_p).ue_paging_identity.choice.imsi.length >= S1AP_IMSI_LENGTH) { - /* invalid paging_p->uePagingID.choise.iMSI.size */ - S1AP_ERROR("[SCTP %d] Received Paging : uePagingID.choise.iMSI.size(%d) is over IMSI length(%d)\n", assoc_id, S1AP_PAGING_IND(message_p).ue_paging_identity.choice.imsi.length, S1AP_IMSI_LENGTH); + if (S1AP_PAGING_IND(message_p).ue_paging_identity.choice.imsi.length >= S1AP_IMSI_LENGTH) { + /* invalid paging_p->uePagingID.choise.iMSI.size */ + S1AP_ERROR("[SCTP %d] Received Paging : uePagingID.choise.iMSI.size(%d) is over IMSI length(%d)\n", assoc_id, S1AP_PAGING_IND(message_p).ue_paging_identity.choice.imsi.length, S1AP_IMSI_LENGTH); + return -1; + } + } else { /* of if (ie->value.choice.UEPagingID.present == S1AP_UEPagingID_PR_iMSI) */ + /* invalid paging_p->uePagingID.present */ + S1AP_ERROR("[SCTP %d] Received Paging : uePagingID.present(%d) is unknown\n", assoc_id, ie->value.choice.UEPagingID.present); return -1; } - } else { - /* invalid paging_p->uePagingID.present */ - S1AP_ERROR("[SCTP %d] Received Paging : uePagingID.present(%d) is unknown\n", assoc_id, ie->value.choice.UEPagingID.present); + } else { /* of ie != NULL */ return -1; } @@ -1125,14 +1215,18 @@ int s1ap_eNB_handle_paging(uint32_t assoc_id, S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_PagingIEs_t, ie, container, S1AP_ProtocolIE_ID_id_CNDomain, true); - /* id-CNDomain : convert cnDomain */ - if (ie->value.choice.CNDomain == S1AP_CNDomain_ps) { - S1AP_PAGING_IND(message_p).cn_domain = CN_DOMAIN_PS; - } else if (ie->value.choice.CNDomain == S1AP_CNDomain_cs) { - S1AP_PAGING_IND(message_p).cn_domain = CN_DOMAIN_CS; + if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */ + /* id-CNDomain : convert cnDomain */ + if (ie->value.choice.CNDomain == S1AP_CNDomain_ps) { + S1AP_PAGING_IND(message_p).cn_domain = CN_DOMAIN_PS; + } else if (ie->value.choice.CNDomain == S1AP_CNDomain_cs) { + S1AP_PAGING_IND(message_p).cn_domain = CN_DOMAIN_CS; + } else { + /* invalid paging_p->cnDomain */ + S1AP_ERROR("[SCTP %d] Received Paging : cnDomain(%ld) is unknown\n", assoc_id, ie->value.choice.CNDomain); + return -1; + } } else { - /* invalid paging_p->cnDomain */ - S1AP_ERROR("[SCTP %d] Received Paging : cnDomain(%ld) is unknown\n", assoc_id, ie->value.choice.CNDomain); return -1; } @@ -1142,20 +1236,25 @@ int s1ap_eNB_handle_paging(uint32_t assoc_id, /* id-TAIList */ S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_PagingIEs_t, ie, container, S1AP_ProtocolIE_ID_id_TAIList, true); - S1AP_INFO("[SCTP %d] Received Paging taiList: count %d\n", assoc_id, ie->value.choice.TAIList.list.count); - - for (int i = 0; i < ie->value.choice.TAIList.list.count; i++) { - S1AP_TAIItem_t *item_p; - item_p = &(((S1AP_TAIItemIEs_t *)ie->value.choice.TAIList.list.array[i])->value.choice.TAIItem); - TBCD_TO_MCC_MNC(&(item_p->tAI.pLMNidentity), S1AP_PAGING_IND(message_p).plmn_identity[i].mcc, - S1AP_PAGING_IND(message_p).plmn_identity[i].mnc, - S1AP_PAGING_IND(message_p).plmn_identity[i].mnc_digit_length); - OCTET_STRING_TO_INT16(&(item_p->tAI.tAC), S1AP_PAGING_IND(message_p).tac[i]); - S1AP_PAGING_IND(message_p).tai_size++; - S1AP_DEBUG("[SCTP %d] Received Paging: MCC %d, MNC %d, TAC %d\n", assoc_id, - S1AP_PAGING_IND(message_p).plmn_identity[i].mcc, - S1AP_PAGING_IND(message_p).plmn_identity[i].mnc, - S1AP_PAGING_IND(message_p).tac[i]); + + if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */ + S1AP_INFO("[SCTP %d] Received Paging taiList: count %d\n", assoc_id, ie->value.choice.TAIList.list.count); + + for (int i = 0; i < ie->value.choice.TAIList.list.count; i++) { + S1AP_TAIItem_t *item_p; + item_p = &(((S1AP_TAIItemIEs_t *)ie->value.choice.TAIList.list.array[i])->value.choice.TAIItem); + TBCD_TO_MCC_MNC(&(item_p->tAI.pLMNidentity), S1AP_PAGING_IND(message_p).plmn_identity[i].mcc, + S1AP_PAGING_IND(message_p).plmn_identity[i].mnc, + S1AP_PAGING_IND(message_p).plmn_identity[i].mnc_digit_length); + OCTET_STRING_TO_INT16(&(item_p->tAI.tAC), S1AP_PAGING_IND(message_p).tac[i]); + S1AP_PAGING_IND(message_p).tai_size++; + S1AP_DEBUG("[SCTP %d] Received Paging: MCC %d, MNC %d, TAC %d\n", assoc_id, + S1AP_PAGING_IND(message_p).plmn_identity[i].mcc, + S1AP_PAGING_IND(message_p).plmn_identity[i].mnc, + S1AP_PAGING_IND(message_p).tac[i]); + } + } else { + return -1; } //paging parameter values @@ -1197,11 +1296,22 @@ int s1ap_eNB_handle_e_rab_modify_request(uint32_t assoc_id, /* id-MME-UE-S1AP-ID */ S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_E_RABModifyRequestIEs_t, ie, container, S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID, true); - mme_ue_s1ap_id = ie->value.choice.MME_UE_S1AP_ID; + + if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */ + mme_ue_s1ap_id = ie->value.choice.MME_UE_S1AP_ID; + } else { + return -1; + } + /* id-eNB-UE-S1AP-ID */ S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_E_RABModifyRequestIEs_t, ie, container, S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID, true); - enb_ue_s1ap_id = ie->value.choice.ENB_UE_S1AP_ID; + + if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */ + enb_ue_s1ap_id = ie->value.choice.ENB_UE_S1AP_ID; + } else { + return -1; + } if ((ue_desc_p = s1ap_eNB_get_ue_context(mme_desc_p->s1ap_eNB_instance, enb_ue_s1ap_id)) == NULL) { @@ -1228,13 +1338,17 @@ int s1ap_eNB_handle_e_rab_modify_request(uint32_t assoc_id, S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_E_RABModifyRequestIEs_t, ie, container, S1AP_ProtocolIE_ID_id_E_RABToBeModifiedListBearerModReq, true); - for(nb_of_e_rabs_failed = 0; nb_of_e_rabs_failed < ie->value.choice.E_RABToBeModifiedListBearerModReq.list.count; nb_of_e_rabs_failed++) { - S1AP_E_RABToBeModifiedItemBearerModReq_t *item_p; - item_p = &(((S1AP_E_RABToBeModifiedItemBearerModReqIEs_t *) - ie->value.choice.E_RABToBeModifiedListBearerModReq.list.array[nb_of_e_rabs_failed])->value.choice.E_RABToBeModifiedItemBearerModReq); - S1AP_E_RAB_MODIFY_RESP(message_p).e_rabs_failed[nb_of_e_rabs_failed].e_rab_id = item_p->e_RAB_ID; - S1AP_E_RAB_MODIFY_RESP(message_p).e_rabs_failed[nb_of_e_rabs_failed].cause = S1AP_Cause_PR_radioNetwork; - S1AP_E_RAB_MODIFY_RESP(message_p).e_rabs_failed[nb_of_e_rabs_failed].cause_value = S1AP_CauseRadioNetwork_unknown_mme_ue_s1ap_id; + if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */ + for(nb_of_e_rabs_failed = 0; nb_of_e_rabs_failed < ie->value.choice.E_RABToBeModifiedListBearerModReq.list.count; nb_of_e_rabs_failed++) { + S1AP_E_RABToBeModifiedItemBearerModReq_t *item_p; + item_p = &(((S1AP_E_RABToBeModifiedItemBearerModReqIEs_t *) + ie->value.choice.E_RABToBeModifiedListBearerModReq.list.array[nb_of_e_rabs_failed])->value.choice.E_RABToBeModifiedItemBearerModReq); + S1AP_E_RAB_MODIFY_RESP(message_p).e_rabs_failed[nb_of_e_rabs_failed].e_rab_id = item_p->e_RAB_ID; + S1AP_E_RAB_MODIFY_RESP(message_p).e_rabs_failed[nb_of_e_rabs_failed].cause = S1AP_Cause_PR_radioNetwork; + S1AP_E_RAB_MODIFY_RESP(message_p).e_rabs_failed[nb_of_e_rabs_failed].cause_value = S1AP_CauseRadioNetwork_unknown_mme_ue_s1ap_id; + } + } else { + return -1; } S1AP_E_RAB_MODIFY_RESP(message_p).nb_of_e_rabs_failed = nb_of_e_rabs_failed; @@ -1251,37 +1365,43 @@ int s1ap_eNB_handle_e_rab_modify_request(uint32_t assoc_id, /* id-E-RABToBeModifiedListBearerModReq */ S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_E_RABModifyRequestIEs_t, ie, container, S1AP_ProtocolIE_ID_id_E_RABToBeModifiedListBearerModReq, true); - S1AP_E_RAB_MODIFY_REQ(message_p).nb_e_rabs_tomodify = - ie->value.choice.E_RABToBeModifiedListBearerModReq.list.count; - - for (i = 0; i < ie->value.choice.E_RABToBeModifiedListBearerModReq.list.count; i++) { - S1AP_E_RABToBeModifiedItemBearerModReq_t *item_p; - item_p = &(((S1AP_E_RABToBeModifiedItemBearerModReqIEs_t *)ie->value.choice.E_RABToBeModifiedListBearerModReq.list.array[i])->value.choice.E_RABToBeModifiedItemBearerModReq); - S1AP_E_RAB_MODIFY_REQ(message_p).e_rab_modify_params[i].e_rab_id = item_p->e_RAB_ID; - - // check for the NAS PDU - if (item_p->nAS_PDU.size > 0 ) { - S1AP_E_RAB_MODIFY_REQ(message_p).e_rab_modify_params[i].nas_pdu.length = item_p->nAS_PDU.size; - S1AP_E_RAB_MODIFY_REQ(message_p).e_rab_modify_params[i].nas_pdu.buffer = malloc(sizeof(uint8_t) * item_p->nAS_PDU.size); - memcpy(S1AP_E_RAB_MODIFY_REQ(message_p).e_rab_modify_params[i].nas_pdu.buffer, - item_p->nAS_PDU.buf, item_p->nAS_PDU.size); - } else { - S1AP_E_RAB_MODIFY_REQ(message_p).e_rab_modify_params[i].nas_pdu.length = 0; - S1AP_E_RAB_MODIFY_REQ(message_p).e_rab_modify_params[i].nas_pdu.buffer = NULL; - continue; + + if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */ + S1AP_E_RAB_MODIFY_REQ(message_p).nb_e_rabs_tomodify = + ie->value.choice.E_RABToBeModifiedListBearerModReq.list.count; + + for (i = 0; i < ie->value.choice.E_RABToBeModifiedListBearerModReq.list.count; i++) { + S1AP_E_RABToBeModifiedItemBearerModReq_t *item_p; + item_p = &(((S1AP_E_RABToBeModifiedItemBearerModReqIEs_t *)ie->value.choice.E_RABToBeModifiedListBearerModReq.list.array[i])->value.choice.E_RABToBeModifiedItemBearerModReq); + S1AP_E_RAB_MODIFY_REQ(message_p).e_rab_modify_params[i].e_rab_id = item_p->e_RAB_ID; + + // check for the NAS PDU + if (item_p->nAS_PDU.size > 0 ) { + S1AP_E_RAB_MODIFY_REQ(message_p).e_rab_modify_params[i].nas_pdu.length = item_p->nAS_PDU.size; + S1AP_E_RAB_MODIFY_REQ(message_p).e_rab_modify_params[i].nas_pdu.buffer = malloc(sizeof(uint8_t) * item_p->nAS_PDU.size); + memcpy(S1AP_E_RAB_MODIFY_REQ(message_p).e_rab_modify_params[i].nas_pdu.buffer, + item_p->nAS_PDU.buf, item_p->nAS_PDU.size); + } else { + S1AP_E_RAB_MODIFY_REQ(message_p).e_rab_modify_params[i].nas_pdu.length = 0; + S1AP_E_RAB_MODIFY_REQ(message_p).e_rab_modify_params[i].nas_pdu.buffer = NULL; + continue; + } + + /* Set the QOS informations */ + S1AP_E_RAB_MODIFY_REQ(message_p).e_rab_modify_params[i].qos.qci = item_p->e_RABLevelQoSParameters.qCI; + S1AP_E_RAB_MODIFY_REQ(message_p).e_rab_modify_params[i].qos.allocation_retention_priority.priority_level = + item_p->e_RABLevelQoSParameters.allocationRetentionPriority.priorityLevel; + S1AP_E_RAB_MODIFY_REQ(message_p).e_rab_modify_params[i].qos.allocation_retention_priority.pre_emp_capability = + item_p->e_RABLevelQoSParameters.allocationRetentionPriority.pre_emptionCapability; + S1AP_E_RAB_MODIFY_REQ(message_p).e_rab_modify_params[i].qos.allocation_retention_priority.pre_emp_vulnerability = + item_p->e_RABLevelQoSParameters.allocationRetentionPriority.pre_emptionVulnerability; } - /* Set the QOS informations */ - S1AP_E_RAB_MODIFY_REQ(message_p).e_rab_modify_params[i].qos.qci = item_p->e_RABLevelQoSParameters.qCI; - S1AP_E_RAB_MODIFY_REQ(message_p).e_rab_modify_params[i].qos.allocation_retention_priority.priority_level = - item_p->e_RABLevelQoSParameters.allocationRetentionPriority.priorityLevel; - S1AP_E_RAB_MODIFY_REQ(message_p).e_rab_modify_params[i].qos.allocation_retention_priority.pre_emp_capability = - item_p->e_RABLevelQoSParameters.allocationRetentionPriority.pre_emptionCapability; - S1AP_E_RAB_MODIFY_REQ(message_p).e_rab_modify_params[i].qos.allocation_retention_priority.pre_emp_vulnerability = - item_p->e_RABLevelQoSParameters.allocationRetentionPriority.pre_emptionVulnerability; + itti_send_msg_to_task(TASK_RRC_ENB, ue_desc_p->eNB_instance->instance, message_p); + } else { /* of if (ie != NULL)*/ + return -1; } - itti_send_msg_to_task(TASK_RRC_ENB, ue_desc_p->eNB_instance->instance, message_p); return 0; } // handle e-rab release command and send it to rrc_end @@ -1308,11 +1428,22 @@ int s1ap_eNB_handle_e_rab_release_command(uint32_t assoc_id, /* id-MME-UE-S1AP-ID */ S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_E_RABReleaseCommandIEs_t, ie, container, S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID, true); - mme_ue_s1ap_id = ie->value.choice.MME_UE_S1AP_ID; + + if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */ + mme_ue_s1ap_id = ie->value.choice.MME_UE_S1AP_ID; + } else { + return -1; + } + /* id-eNB-UE-S1AP-ID */ S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_E_RABReleaseCommandIEs_t, ie, container, S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID, true); - enb_ue_s1ap_id = ie->value.choice.ENB_UE_S1AP_ID; + + if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */ + enb_ue_s1ap_id = ie->value.choice.ENB_UE_S1AP_ID; + } else { + return -1; + } if ((ue_desc_p = s1ap_eNB_get_ue_context(mme_desc_p->s1ap_eNB_instance, enb_ue_s1ap_id)) == NULL) { @@ -1359,15 +1490,251 @@ int s1ap_eNB_handle_e_rab_release_command(uint32_t assoc_id, /* id-E-RABToBeReleasedList */ S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_E_RABReleaseCommandIEs_t, ie, container, S1AP_ProtocolIE_ID_id_E_RABToBeReleasedList, true); - S1AP_E_RAB_RELEASE_COMMAND(message_p).nb_e_rabs_torelease = ie->value.choice.E_RABList.list.count; - for (i = 0; i < ie->value.choice.E_RABList.list.count; i++) { - S1AP_E_RABItem_t *item_p; - item_p = &(((S1AP_E_RABItemIEs_t *)ie->value.choice.E_RABList.list.array[i])->value.choice.E_RABItem); - S1AP_E_RAB_RELEASE_COMMAND(message_p).e_rab_release_params[i].e_rab_id = item_p->e_RAB_ID; - S1AP_DEBUG("[SCTP] Received E-RAB release command for e-rab id %ld\n", item_p->e_RAB_ID); + if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */ + S1AP_E_RAB_RELEASE_COMMAND(message_p).nb_e_rabs_torelease = ie->value.choice.E_RABList.list.count; + + for (i = 0; i < ie->value.choice.E_RABList.list.count; i++) { + S1AP_E_RABItem_t *item_p; + item_p = &(((S1AP_E_RABItemIEs_t *)ie->value.choice.E_RABList.list.array[i])->value.choice.E_RABItem); + S1AP_E_RAB_RELEASE_COMMAND(message_p).e_rab_release_params[i].e_rab_id = item_p->e_RAB_ID; + S1AP_DEBUG("[SCTP] Received E-RAB release command for e-rab id %ld\n", item_p->e_RAB_ID); + } + } else { + return -1; + } + + itti_send_msg_to_task(TASK_RRC_ENB, ue_desc_p->eNB_instance->instance, message_p); + return 0; +} + +static +int s1ap_eNB_handle_s1_path_switch_request_ack(uint32_t assoc_id, + uint32_t stream, + S1AP_S1AP_PDU_t *pdu) { + s1ap_eNB_mme_data_t *mme_desc_p = NULL; + s1ap_eNB_ue_context_t *ue_desc_p = NULL; + MessageDef *message_p = NULL; + S1AP_PathSwitchRequestAcknowledge_t *pathSwitchRequestAcknowledge; + S1AP_PathSwitchRequestAcknowledgeIEs_t *ie; + S1AP_E_RABToBeSwitchedULItemIEs_t *s1ap_E_RABToBeSwitchedULItemIEs; + S1AP_E_RABToBeSwitchedULItem_t *s1ap_E_RABToBeSwitchedULItem; + S1AP_E_RABItemIEs_t *e_RABItemIEs; + S1AP_E_RABItem_t *e_RABItem; + DevAssert(pdu != NULL); + pathSwitchRequestAcknowledge = &pdu->choice.successfulOutcome.value.choice.PathSwitchRequestAcknowledge; + + /* Path Switch request == UE-related procedure -> stream !=0 */ + if (stream == 0) { + S1AP_ERROR("[SCTP %d] Received s1 path switch request ack on stream (%d)\n", + assoc_id, stream); + return -1; + } + + if ((mme_desc_p = s1ap_eNB_get_MME(NULL, assoc_id, 0)) == NULL) { + S1AP_ERROR("[SCTP %d] Received S1 path switch request ack for non existing " + "MME context\n", assoc_id); + return -1; + } + + // send a message to RRC + message_p = itti_alloc_new_message(TASK_S1AP, S1AP_PATH_SWITCH_REQ_ACK); + /* mandatory */ + S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_PathSwitchRequestAcknowledgeIEs_t, ie, pathSwitchRequestAcknowledge, + S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID, true); + if (ie == NULL) { + S1AP_ERROR("[SCTP %d] Received path switch request ack for non " + "ie context is NULL\n", assoc_id); + return -1; + } + + S1AP_PATH_SWITCH_REQ_ACK(message_p).eNB_ue_s1ap_id = ie->value.choice.ENB_UE_S1AP_ID; + + if ((ue_desc_p = s1ap_eNB_get_ue_context(mme_desc_p->s1ap_eNB_instance, + ie->value.choice.ENB_UE_S1AP_ID)) == NULL) { + S1AP_ERROR("[SCTP %d] Received path switch request ack for non " + "existing UE context 0x%06lx\n", assoc_id, + ie->value.choice.ENB_UE_S1AP_ID); + return -1; + } + + S1AP_PATH_SWITCH_REQ_ACK(message_p).ue_initial_id = ue_desc_p->ue_initial_id; + /* mandatory */ + S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_PathSwitchRequestAcknowledgeIEs_t, ie, pathSwitchRequestAcknowledge, + S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID, true); + + if (ie == NULL) { + S1AP_ERROR("[SCTP %d] Received path switch request ack for non " + "ie context is NULL\n", assoc_id); + return -1; + } + + S1AP_PATH_SWITCH_REQ_ACK(message_p).mme_ue_s1ap_id = ie->value.choice.MME_UE_S1AP_ID; + + if ( ue_desc_p->mme_ue_s1ap_id != ie->value.choice.MME_UE_S1AP_ID) { + S1AP_WARN("UE context mme_ue_s1ap_id is different form that of the message (%d != %ld)", + ue_desc_p->mme_ue_s1ap_id, ie->value.choice.MME_UE_S1AP_ID); + } + + /* mandatory */ + S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_PathSwitchRequestAcknowledgeIEs_t, ie, pathSwitchRequestAcknowledge, + S1AP_ProtocolIE_ID_id_SecurityContext, true); + + if (ie == NULL) { + S1AP_ERROR("[SCTP %d] Received path switch request ack for non " + "ie context is NULL\n", assoc_id); + return -1; + } + + S1AP_PATH_SWITCH_REQ_ACK(message_p).next_hop_chain_count = + ie->value.choice.SecurityContext.nextHopChainingCount; + memcpy(&S1AP_PATH_SWITCH_REQ_ACK(message_p).next_security_key, + ie->value.choice.SecurityContext.nextHopParameter.buf, + ie->value.choice.SecurityContext.nextHopParameter.size); + /* optional */ + S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_PathSwitchRequestAcknowledgeIEs_t, ie, pathSwitchRequestAcknowledge, + S1AP_ProtocolIE_ID_id_uEaggregateMaximumBitrate, false); + + if (ie) { + OCTET_STRING_TO_INT32 ( + &ie->value.choice.UEAggregateMaximumBitrate.uEaggregateMaximumBitRateUL, + S1AP_PATH_SWITCH_REQ_ACK(message_p).ue_ambr.br_ul + ); + OCTET_STRING_TO_INT32 ( + &ie->value.choice.UEAggregateMaximumBitrate.uEaggregateMaximumBitRateDL, + S1AP_PATH_SWITCH_REQ_ACK(message_p).ue_ambr.br_dl + ); + } else { + S1AP_WARN("UEAggregateMaximumBitrate not supported\n"); + S1AP_PATH_SWITCH_REQ_ACK(message_p).ue_ambr.br_ul = 0; + S1AP_PATH_SWITCH_REQ_ACK(message_p).ue_ambr.br_dl = 0; + } + + /* optional */ + S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_PathSwitchRequestAcknowledgeIEs_t, ie, pathSwitchRequestAcknowledge, + S1AP_ProtocolIE_ID_id_E_RABToBeSwitchedULList, false); + + if (ie) { + S1AP_PATH_SWITCH_REQ_ACK(message_p).nb_e_rabs_tobeswitched = ie->value.choice.E_RABToBeSwitchedULList.list.count; + + for (int i = 0; i < ie->value.choice.E_RABToBeSwitchedULList.list.count; i++) { + s1ap_E_RABToBeSwitchedULItemIEs = (S1AP_E_RABToBeSwitchedULItemIEs_t *)ie->value.choice.E_RABToBeSwitchedULList.list.array[i]; + s1ap_E_RABToBeSwitchedULItem = &s1ap_E_RABToBeSwitchedULItemIEs->value.choice.E_RABToBeSwitchedULItem; + S1AP_PATH_SWITCH_REQ_ACK (message_p).e_rabs_tobeswitched[i].e_rab_id = s1ap_E_RABToBeSwitchedULItem->e_RAB_ID; + memcpy(S1AP_PATH_SWITCH_REQ_ACK (message_p).e_rabs_tobeswitched[i].sgw_addr.buffer, + s1ap_E_RABToBeSwitchedULItem->transportLayerAddress.buf, s1ap_E_RABToBeSwitchedULItem->transportLayerAddress.size); + S1AP_PATH_SWITCH_REQ_ACK (message_p).e_rabs_tobeswitched[i].sgw_addr.length = + s1ap_E_RABToBeSwitchedULItem->transportLayerAddress.size * 8 - s1ap_E_RABToBeSwitchedULItem->transportLayerAddress.bits_unused; + OCTET_STRING_TO_INT32(&s1ap_E_RABToBeSwitchedULItem->gTP_TEID, + S1AP_PATH_SWITCH_REQ_ACK (message_p).e_rabs_tobeswitched[i].gtp_teid); + } + } else { + S1AP_WARN("E_RABToBeSwitchedULList not supported\n"); + S1AP_PATH_SWITCH_REQ_ACK(message_p).nb_e_rabs_tobeswitched = 0; + } + + /* optional */ + S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_PathSwitchRequestAcknowledgeIEs_t, ie, pathSwitchRequestAcknowledge, + S1AP_ProtocolIE_ID_id_E_RABToBeReleasedList, false); + + if (ie) { + S1AP_PATH_SWITCH_REQ_ACK(message_p).nb_e_rabs_tobereleased = ie->value.choice.E_RABList.list.count; + + for (int i = 0; i < ie->value.choice.E_RABList.list.count; i++) { + e_RABItemIEs = (S1AP_E_RABItemIEs_t *)ie->value.choice.E_RABList.list.array[i]; + e_RABItem = &e_RABItemIEs->value.choice.E_RABItem; + S1AP_PATH_SWITCH_REQ_ACK (message_p).e_rabs_tobereleased[i].e_rab_id = e_RABItem->e_RAB_ID; + } + } else { + S1AP_WARN("E_RABToBeReleasedList not supported\n"); + S1AP_PATH_SWITCH_REQ_ACK(message_p).nb_e_rabs_tobereleased = 0; + } + + /* optional */ + S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_PathSwitchRequestAcknowledgeIEs_t, ie, pathSwitchRequestAcknowledge, + S1AP_ProtocolIE_ID_id_CriticalityDiagnostics, false); + + if(!ie) { + S1AP_WARN("Critical Diagnostic not supported\n"); } + /* optional */ + S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_PathSwitchRequestAcknowledgeIEs_t, ie, pathSwitchRequestAcknowledge, + S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID_2, false); + + if(!ie) { + S1AP_WARN("MME_UE_S1AP_ID_2 flag not supported\n"); + } + + // TODO continue itti_send_msg_to_task(TASK_RRC_ENB, ue_desc_p->eNB_instance->instance, message_p); return 0; } + +static +int s1ap_eNB_handle_s1_path_switch_request_failure(uint32_t assoc_id, + uint32_t stream, + S1AP_S1AP_PDU_t *pdu) { + s1ap_eNB_mme_data_t *mme_desc_p = NULL; + S1AP_PathSwitchRequestFailure_t *pathSwitchRequestFailure; + S1AP_PathSwitchRequestFailureIEs_t *ie; + DevAssert(pdu != NULL); + pathSwitchRequestFailure = &pdu->choice.unsuccessfulOutcome.value.choice.PathSwitchRequestFailure; + + if (stream != 0) { + S1AP_ERROR("[SCTP %d] Received s1 path switch request failure on stream != 0 (%d)\n", + assoc_id, stream); + return -1; + } + + if ((mme_desc_p = s1ap_eNB_get_MME(NULL, assoc_id, 0)) == NULL) { + S1AP_ERROR("[SCTP %d] Received S1 path switch request failure for non existing " + "MME context\n", assoc_id); + return -1; + } + + S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_PathSwitchRequestFailureIEs_t, ie, pathSwitchRequestFailure, + S1AP_ProtocolIE_ID_id_Cause, true); + + if (ie == NULL) { + S1AP_ERROR("[SCTP %d] Received S1 path switch request failure for non existing " + "ie context is NULL\n", assoc_id); + return -1; + } + + switch(ie->value.choice.Cause.present) { + case S1AP_Cause_PR_NOTHING: + S1AP_WARN("Received S1 Error indication cause NOTHING\n"); + break; + + case S1AP_Cause_PR_radioNetwork: + S1AP_WARN("Radio Network Layer Cause Failure\n"); + break; + + case S1AP_Cause_PR_transport: + S1AP_WARN("Transport Layer Cause Failure\n"); + break; + + case S1AP_Cause_PR_nas: + S1AP_WARN("NAS Cause Failure\n"); + break; + + case S1AP_Cause_PR_misc: + S1AP_WARN("Miscelaneous Cause Failure\n"); + break; + + default: + S1AP_WARN("Received an unknown S1 Error indication cause\n"); + break; + } + + S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_PathSwitchRequestFailureIEs_t, ie, pathSwitchRequestFailure, + S1AP_ProtocolIE_ID_id_CriticalityDiagnostics, false); + + if(!ie) { + S1AP_WARN("Critical Diagnostic not supported\n"); + } + + // TODO continue + return 0; +} diff --git a/openair3/S1AP/s1ap_eNB_nas_procedures.c b/openair3/S1AP/s1ap_eNB_nas_procedures.c index 2189140dad0213e506d46b86ab26fcb488fd0714..6652ca0447b10ea8a0f573e1cacd5e68beacc34f 100644 --- a/openair3/S1AP/s1ap_eNB_nas_procedures.c +++ b/openair3/S1AP/s1ap_eNB_nas_procedures.c @@ -50,376 +50,376 @@ //------------------------------------------------------------------------------ int s1ap_eNB_handle_nas_first_req( - instance_t instance, s1ap_nas_first_req_t *s1ap_nas_first_req_p) + instance_t instance, s1ap_nas_first_req_t *s1ap_nas_first_req_p) //------------------------------------------------------------------------------ { - s1ap_eNB_instance_t *instance_p = NULL; - struct s1ap_eNB_mme_data_s *mme_desc_p = NULL; - struct s1ap_eNB_ue_context_s *ue_desc_p = NULL; - S1AP_S1AP_PDU_t pdu; - S1AP_InitialUEMessage_t *out; - S1AP_InitialUEMessage_IEs_t *ie; - uint8_t *buffer = NULL; - uint32_t length = 0; - DevAssert(s1ap_nas_first_req_p != NULL); - /* Retrieve the S1AP eNB instance associated with Mod_id */ - instance_p = s1ap_eNB_get_instance(instance); - DevAssert(instance_p != NULL); - memset(&pdu, 0, sizeof(pdu)); - pdu.present = S1AP_S1AP_PDU_PR_initiatingMessage; - pdu.choice.initiatingMessage.procedureCode = S1AP_ProcedureCode_id_initialUEMessage; - pdu.choice.initiatingMessage.criticality = S1AP_Criticality_ignore; - pdu.choice.initiatingMessage.value.present = S1AP_InitiatingMessage__value_PR_InitialUEMessage; - out = &pdu.choice.initiatingMessage.value.choice.InitialUEMessage; - - /* Select the MME corresponding to the provided GUMMEI. */ - if (s1ap_nas_first_req_p->ue_identity.presenceMask & UE_IDENTITIES_gummei) { - mme_desc_p = s1ap_eNB_nnsf_select_mme_by_gummei( - instance_p, - s1ap_nas_first_req_p->establishment_cause, - s1ap_nas_first_req_p->ue_identity.gummei); - - if (mme_desc_p) { - S1AP_INFO("[eNB %d] Chose MME '%s' (assoc_id %d) through GUMMEI MCC %d MNC %d MMEGI %d MMEC %d\n", - instance, - mme_desc_p->mme_name, - mme_desc_p->assoc_id, - s1ap_nas_first_req_p->ue_identity.gummei.mcc, - s1ap_nas_first_req_p->ue_identity.gummei.mnc, - s1ap_nas_first_req_p->ue_identity.gummei.mme_group_id, - s1ap_nas_first_req_p->ue_identity.gummei.mme_code); + s1ap_eNB_instance_t *instance_p = NULL; + struct s1ap_eNB_mme_data_s *mme_desc_p = NULL; + struct s1ap_eNB_ue_context_s *ue_desc_p = NULL; + S1AP_S1AP_PDU_t pdu; + S1AP_InitialUEMessage_t *out; + S1AP_InitialUEMessage_IEs_t *ie; + uint8_t *buffer = NULL; + uint32_t length = 0; + DevAssert(s1ap_nas_first_req_p != NULL); + /* Retrieve the S1AP eNB instance associated with Mod_id */ + instance_p = s1ap_eNB_get_instance(instance); + DevAssert(instance_p != NULL); + memset(&pdu, 0, sizeof(pdu)); + pdu.present = S1AP_S1AP_PDU_PR_initiatingMessage; + pdu.choice.initiatingMessage.procedureCode = S1AP_ProcedureCode_id_initialUEMessage; + pdu.choice.initiatingMessage.criticality = S1AP_Criticality_ignore; + pdu.choice.initiatingMessage.value.present = S1AP_InitiatingMessage__value_PR_InitialUEMessage; + out = &pdu.choice.initiatingMessage.value.choice.InitialUEMessage; + + /* Select the MME corresponding to the provided GUMMEI. */ + if (s1ap_nas_first_req_p->ue_identity.presenceMask & UE_IDENTITIES_gummei) { + mme_desc_p = s1ap_eNB_nnsf_select_mme_by_gummei( + instance_p, + s1ap_nas_first_req_p->establishment_cause, + s1ap_nas_first_req_p->ue_identity.gummei); + + if (mme_desc_p) { + S1AP_INFO("[eNB %d] Chose MME '%s' (assoc_id %d) through GUMMEI MCC %d MNC %d MMEGI %d MMEC %d\n", + instance, + mme_desc_p->mme_name, + mme_desc_p->assoc_id, + s1ap_nas_first_req_p->ue_identity.gummei.mcc, + s1ap_nas_first_req_p->ue_identity.gummei.mnc, + s1ap_nas_first_req_p->ue_identity.gummei.mme_group_id, + s1ap_nas_first_req_p->ue_identity.gummei.mme_code); + } } - } - if (mme_desc_p == NULL) { - /* Select the MME corresponding to the provided s-TMSI. */ - if (s1ap_nas_first_req_p->ue_identity.presenceMask & UE_IDENTITIES_s_tmsi) { - mme_desc_p = s1ap_eNB_nnsf_select_mme_by_mme_code( - instance_p, - s1ap_nas_first_req_p->establishment_cause, - s1ap_nas_first_req_p->selected_plmn_identity, - s1ap_nas_first_req_p->ue_identity.s_tmsi.mme_code); - - if (mme_desc_p) { - S1AP_INFO("[eNB %d] Chose MME '%s' (assoc_id %d) through S-TMSI MMEC %d and selected PLMN Identity index %d MCC %d MNC %d\n", - instance, - mme_desc_p->mme_name, - mme_desc_p->assoc_id, - s1ap_nas_first_req_p->ue_identity.s_tmsi.mme_code, - s1ap_nas_first_req_p->selected_plmn_identity, - instance_p->mcc[s1ap_nas_first_req_p->selected_plmn_identity], - instance_p->mnc[s1ap_nas_first_req_p->selected_plmn_identity]); - } + if (mme_desc_p == NULL) { + /* Select the MME corresponding to the provided s-TMSI. */ + if (s1ap_nas_first_req_p->ue_identity.presenceMask & UE_IDENTITIES_s_tmsi) { + mme_desc_p = s1ap_eNB_nnsf_select_mme_by_mme_code( + instance_p, + s1ap_nas_first_req_p->establishment_cause, + s1ap_nas_first_req_p->selected_plmn_identity, + s1ap_nas_first_req_p->ue_identity.s_tmsi.mme_code); + + if (mme_desc_p) { + S1AP_INFO("[eNB %d] Chose MME '%s' (assoc_id %d) through S-TMSI MMEC %d and selected PLMN Identity index %d MCC %d MNC %d\n", + instance, + mme_desc_p->mme_name, + mme_desc_p->assoc_id, + s1ap_nas_first_req_p->ue_identity.s_tmsi.mme_code, + s1ap_nas_first_req_p->selected_plmn_identity, + instance_p->mcc[s1ap_nas_first_req_p->selected_plmn_identity], + instance_p->mnc[s1ap_nas_first_req_p->selected_plmn_identity]); + } + } } - } - if (mme_desc_p == NULL) { - /* Select MME based on the selected PLMN identity, received through RRC - * Connection Setup Complete */ - mme_desc_p = s1ap_eNB_nnsf_select_mme_by_plmn_id( - instance_p, - s1ap_nas_first_req_p->establishment_cause, - s1ap_nas_first_req_p->selected_plmn_identity); - - if (mme_desc_p) { - S1AP_INFO("[eNB %d] Chose MME '%s' (assoc_id %d) through selected PLMN Identity index %d MCC %d MNC %d\n", - instance, - mme_desc_p->mme_name, - mme_desc_p->assoc_id, - s1ap_nas_first_req_p->selected_plmn_identity, - instance_p->mcc[s1ap_nas_first_req_p->selected_plmn_identity], - instance_p->mnc[s1ap_nas_first_req_p->selected_plmn_identity]); + if (mme_desc_p == NULL) { + /* Select MME based on the selected PLMN identity, received through RRC + * Connection Setup Complete */ + mme_desc_p = s1ap_eNB_nnsf_select_mme_by_plmn_id( + instance_p, + s1ap_nas_first_req_p->establishment_cause, + s1ap_nas_first_req_p->selected_plmn_identity); + + if (mme_desc_p) { + S1AP_INFO("[eNB %d] Chose MME '%s' (assoc_id %d) through selected PLMN Identity index %d MCC %d MNC %d\n", + instance, + mme_desc_p->mme_name, + mme_desc_p->assoc_id, + s1ap_nas_first_req_p->selected_plmn_identity, + instance_p->mcc[s1ap_nas_first_req_p->selected_plmn_identity], + instance_p->mnc[s1ap_nas_first_req_p->selected_plmn_identity]); + } } - } - if (mme_desc_p == NULL) { - /* - * If no MME corresponds to the GUMMEI, the s-TMSI, or the selected PLMN - * identity, selects the MME with the highest capacity. - */ - mme_desc_p = s1ap_eNB_nnsf_select_mme( - instance_p, - s1ap_nas_first_req_p->establishment_cause); + if (mme_desc_p == NULL) { + /* + * If no MME corresponds to the GUMMEI, the s-TMSI, or the selected PLMN + * identity, selects the MME with the highest capacity. + */ + mme_desc_p = s1ap_eNB_nnsf_select_mme( + instance_p, + s1ap_nas_first_req_p->establishment_cause); + + if (mme_desc_p) { + S1AP_INFO("[eNB %d] Chose MME '%s' (assoc_id %d) through highest relative capacity\n", + instance, + mme_desc_p->mme_name, + mme_desc_p->assoc_id); + } + } - if (mme_desc_p) { - S1AP_INFO("[eNB %d] Chose MME '%s' (assoc_id %d) through highest relative capacity\n", - instance, - mme_desc_p->mme_name, - mme_desc_p->assoc_id); + if (mme_desc_p == NULL) { + /* + * In case eNB has no MME associated, the eNB should inform RRC and discard + * this request. + */ + S1AP_WARN("No MME is associated to the eNB\n"); + // TODO: Inform RRC + return -1; } - } - if (mme_desc_p == NULL) { - /* - * In case eNB has no MME associated, the eNB should inform RRC and discard - * this request. + /* The eNB should allocate a unique eNB UE S1AP ID for this UE. The value + * will be used for the duration of the connectivity. */ - S1AP_WARN("No MME is associated to the eNB\n"); - // TODO: Inform RRC - return -1; - } - - /* The eNB should allocate a unique eNB UE S1AP ID for this UE. The value - * will be used for the duration of the connectivity. - */ - ue_desc_p = s1ap_eNB_allocate_new_UE_context(); - DevAssert(ue_desc_p != NULL); - /* Keep a reference to the selected MME */ - ue_desc_p->mme_ref = mme_desc_p; - ue_desc_p->ue_initial_id = s1ap_nas_first_req_p->ue_initial_id; - ue_desc_p->eNB_instance = instance_p; - ue_desc_p->selected_plmn_identity = s1ap_nas_first_req_p->selected_plmn_identity; - - do { - struct s1ap_eNB_ue_context_s *collision_p; - /* Peek a random value for the eNB_ue_s1ap_id */ - ue_desc_p->eNB_ue_s1ap_id = (random() + random()) & 0x00ffffff; - - if ((collision_p = RB_INSERT(s1ap_ue_map, &instance_p->s1ap_ue_head, ue_desc_p)) - == NULL) { - S1AP_DEBUG("Found usable eNB_ue_s1ap_id: 0x%06x %d(10)\n", - ue_desc_p->eNB_ue_s1ap_id, - ue_desc_p->eNB_ue_s1ap_id); - /* Break the loop as the id is not already used by another UE */ - break; - } - } while(1); + ue_desc_p = s1ap_eNB_allocate_new_UE_context(); + DevAssert(ue_desc_p != NULL); + /* Keep a reference to the selected MME */ + ue_desc_p->mme_ref = mme_desc_p; + ue_desc_p->ue_initial_id = s1ap_nas_first_req_p->ue_initial_id; + ue_desc_p->eNB_instance = instance_p; + ue_desc_p->selected_plmn_identity = s1ap_nas_first_req_p->selected_plmn_identity; + + do { + struct s1ap_eNB_ue_context_s *collision_p; + /* Peek a random value for the eNB_ue_s1ap_id */ + ue_desc_p->eNB_ue_s1ap_id = (random() + random()) & 0x00ffffff; + + if ((collision_p = RB_INSERT(s1ap_ue_map, &instance_p->s1ap_ue_head, ue_desc_p)) + == NULL) { + S1AP_DEBUG("Found usable eNB_ue_s1ap_id: 0x%06x %u(10)\n", + ue_desc_p->eNB_ue_s1ap_id, + ue_desc_p->eNB_ue_s1ap_id); + /* Break the loop as the id is not already used by another UE */ + break; + } + } while(1); - /* mandatory */ - ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID; - ie->criticality = S1AP_Criticality_reject; - ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_ENB_UE_S1AP_ID; - ie->value.choice.ENB_UE_S1AP_ID = ue_desc_p->eNB_ue_s1ap_id; - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - /* mandatory */ - ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_NAS_PDU; - ie->criticality = S1AP_Criticality_reject; - ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_NAS_PDU; + /* mandatory */ + ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID; + ie->criticality = S1AP_Criticality_reject; + ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_ENB_UE_S1AP_ID; + ie->value.choice.ENB_UE_S1AP_ID = ue_desc_p->eNB_ue_s1ap_id; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + /* mandatory */ + ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_NAS_PDU; + ie->criticality = S1AP_Criticality_reject; + ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_NAS_PDU; #if 1 - ie->value.choice.NAS_PDU.buf = s1ap_nas_first_req_p->nas_pdu.buffer; + ie->value.choice.NAS_PDU.buf = s1ap_nas_first_req_p->nas_pdu.buffer; #else - ie->value.choice.NAS_PDU.buf = malloc(s1ap_nas_first_req_p->nas_pdu.length); - memcpy(ie->value.choice.NAS_PDU.buf, - s1ap_nas_first_req_p->nas_pdu.buffer, - s1ap_nas_first_req_p->nas_pdu.length); + ie->value.choice.NAS_PDU.buf = malloc(s1ap_nas_first_req_p->nas_pdu.length); + memcpy(ie->value.choice.NAS_PDU.buf, + s1ap_nas_first_req_p->nas_pdu.buffer, + s1ap_nas_first_req_p->nas_pdu.length); #endif - ie->value.choice.NAS_PDU.size = s1ap_nas_first_req_p->nas_pdu.length; - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - /* mandatory */ - ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_TAI; - ie->criticality = S1AP_Criticality_reject; - ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_TAI; - /* Assuming TAI is the TAI from the cell */ - INT16_TO_OCTET_STRING(instance_p->tac, &ie->value.choice.TAI.tAC); - MCC_MNC_TO_PLMNID(instance_p->mcc[ue_desc_p->selected_plmn_identity], - instance_p->mnc[ue_desc_p->selected_plmn_identity], - instance_p->mnc_digit_length[ue_desc_p->selected_plmn_identity], - &ie->value.choice.TAI.pLMNidentity); - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - /* mandatory */ - ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_EUTRAN_CGI; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_EUTRAN_CGI; - /* Set the EUTRAN CGI - * The cell identity is defined on 28 bits but as we use macro enb id, - * we have to pad. - */ - //#warning "TODO get cell id from RRC" - MACRO_ENB_ID_TO_CELL_IDENTITY(instance_p->eNB_id, - 0, // Cell ID - &ie->value.choice.EUTRAN_CGI.cell_ID); - MCC_MNC_TO_TBCD(instance_p->mcc[ue_desc_p->selected_plmn_identity], - instance_p->mnc[ue_desc_p->selected_plmn_identity], - instance_p->mnc_digit_length[ue_desc_p->selected_plmn_identity], - &ie->value.choice.EUTRAN_CGI.pLMNidentity); - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - /* Set the establishment cause according to those provided by RRC */ - DevCheck(s1ap_nas_first_req_p->establishment_cause < RRC_CAUSE_LAST, - s1ap_nas_first_req_p->establishment_cause, RRC_CAUSE_LAST, 0); - /* mandatory */ - ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_RRC_Establishment_Cause; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_RRC_Establishment_Cause; - ie->value.choice.RRC_Establishment_Cause = s1ap_nas_first_req_p->establishment_cause; - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - - /* optional */ - if (s1ap_nas_first_req_p->ue_identity.presenceMask & UE_IDENTITIES_s_tmsi) { - S1AP_DEBUG("S_TMSI_PRESENT\n"); + ie->value.choice.NAS_PDU.size = s1ap_nas_first_req_p->nas_pdu.length; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + /* mandatory */ ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_S_TMSI; + ie->id = S1AP_ProtocolIE_ID_id_TAI; ie->criticality = S1AP_Criticality_reject; - ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_S_TMSI; - MME_CODE_TO_OCTET_STRING(s1ap_nas_first_req_p->ue_identity.s_tmsi.mme_code, - &ie->value.choice.S_TMSI.mMEC); - M_TMSI_TO_OCTET_STRING(s1ap_nas_first_req_p->ue_identity.s_tmsi.m_tmsi, - &ie->value.choice.S_TMSI.m_TMSI); + ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_TAI; + /* Assuming TAI is the TAI from the cell */ + INT16_TO_OCTET_STRING(instance_p->tac, &ie->value.choice.TAI.tAC); + MCC_MNC_TO_PLMNID(instance_p->mcc[ue_desc_p->selected_plmn_identity], + instance_p->mnc[ue_desc_p->selected_plmn_identity], + instance_p->mnc_digit_length[ue_desc_p->selected_plmn_identity], + &ie->value.choice.TAI.pLMNidentity); ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - } - - /* optional */ - if (0) { + /* mandatory */ ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_CSG_Id; - ie->criticality = S1AP_Criticality_reject; - ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_CSG_Id; - // ie->value.choice.CSG_Id = ; + ie->id = S1AP_ProtocolIE_ID_id_EUTRAN_CGI; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_EUTRAN_CGI; + /* Set the EUTRAN CGI + * The cell identity is defined on 28 bits but as we use macro enb id, + * we have to pad. + */ + //#warning "TODO get cell id from RRC" + MACRO_ENB_ID_TO_CELL_IDENTITY(instance_p->eNB_id, + 0, // Cell ID + &ie->value.choice.EUTRAN_CGI.cell_ID); + MCC_MNC_TO_TBCD(instance_p->mcc[ue_desc_p->selected_plmn_identity], + instance_p->mnc[ue_desc_p->selected_plmn_identity], + instance_p->mnc_digit_length[ue_desc_p->selected_plmn_identity], + &ie->value.choice.EUTRAN_CGI.pLMNidentity); ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - } - - /* optional */ - if (s1ap_nas_first_req_p->ue_identity.presenceMask & UE_IDENTITIES_gummei) { - S1AP_DEBUG("GUMMEI_ID_PRESENT\n"); + /* Set the establishment cause according to those provided by RRC */ + DevCheck(s1ap_nas_first_req_p->establishment_cause < RRC_CAUSE_LAST, + s1ap_nas_first_req_p->establishment_cause, RRC_CAUSE_LAST, 0); + /* mandatory */ ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_GUMMEI_ID; - ie->criticality = S1AP_Criticality_reject; - ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_GUMMEI; - MCC_MNC_TO_PLMNID( - s1ap_nas_first_req_p->ue_identity.gummei.mcc, - s1ap_nas_first_req_p->ue_identity.gummei.mnc, - s1ap_nas_first_req_p->ue_identity.gummei.mnc_len, - &ie->value.choice.GUMMEI.pLMN_Identity); - MME_GID_TO_OCTET_STRING(s1ap_nas_first_req_p->ue_identity.gummei.mme_group_id, - &ie->value.choice.GUMMEI.mME_Group_ID); - MME_CODE_TO_OCTET_STRING(s1ap_nas_first_req_p->ue_identity.gummei.mme_code, - &ie->value.choice.GUMMEI.mME_Code); + ie->id = S1AP_ProtocolIE_ID_id_RRC_Establishment_Cause; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_RRC_Establishment_Cause; + ie->value.choice.RRC_Establishment_Cause = s1ap_nas_first_req_p->establishment_cause; ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - } - /* optional */ + /* optional */ + if (s1ap_nas_first_req_p->ue_identity.presenceMask & UE_IDENTITIES_s_tmsi) { + S1AP_DEBUG("S_TMSI_PRESENT\n"); + ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_S_TMSI; + ie->criticality = S1AP_Criticality_reject; + ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_S_TMSI; + MME_CODE_TO_OCTET_STRING(s1ap_nas_first_req_p->ue_identity.s_tmsi.mme_code, + &ie->value.choice.S_TMSI.mMEC); + M_TMSI_TO_OCTET_STRING(s1ap_nas_first_req_p->ue_identity.s_tmsi.m_tmsi, + &ie->value.choice.S_TMSI.m_TMSI); + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + } + + /* optional */ + if (0) { + ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_CSG_Id; + ie->criticality = S1AP_Criticality_reject; + ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_CSG_Id; + // ie->value.choice.CSG_Id = ; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + } + + /* optional */ + if (s1ap_nas_first_req_p->ue_identity.presenceMask & UE_IDENTITIES_gummei) { + S1AP_DEBUG("GUMMEI_ID_PRESENT\n"); + ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_GUMMEI_ID; + ie->criticality = S1AP_Criticality_reject; + ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_GUMMEI; + MCC_MNC_TO_PLMNID( + s1ap_nas_first_req_p->ue_identity.gummei.mcc, + s1ap_nas_first_req_p->ue_identity.gummei.mnc, + s1ap_nas_first_req_p->ue_identity.gummei.mnc_len, + &ie->value.choice.GUMMEI.pLMN_Identity); + MME_GID_TO_OCTET_STRING(s1ap_nas_first_req_p->ue_identity.gummei.mme_group_id, + &ie->value.choice.GUMMEI.mME_Group_ID); + MME_CODE_TO_OCTET_STRING(s1ap_nas_first_req_p->ue_identity.gummei.mme_code, + &ie->value.choice.GUMMEI.mME_Code); + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + } + + /* optional */ #if (S1AP_VERSION >= MAKE_VERSION(9, 0, 0)) - if (0) { - ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_CellAccessMode; - ie->criticality = S1AP_Criticality_reject; - ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_CellAccessMode; - // ie->value.choice.CellAccessMode = ; - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - } + if (0) { + ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_CellAccessMode; + ie->criticality = S1AP_Criticality_reject; + ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_CellAccessMode; + // ie->value.choice.CellAccessMode = ; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + } - /* optional */ + /* optional */ #if (S1AP_VERSION >= MAKE_VERSION(10, 0, 0)) - if (0) { - ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_GW_TransportLayerAddress; - ie->criticality = S1AP_Criticality_reject; - ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_TransportLayerAddress; - // ie->value.choice.TransportLayerAddress =; - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - } + if (0) { + ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_GW_TransportLayerAddress; + ie->criticality = S1AP_Criticality_reject; + ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_TransportLayerAddress; + // ie->value.choice.TransportLayerAddress =; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + } - /* optional */ - if (0) { - ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_RelayNode_Indicator; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_RelayNode_Indicator; - // ie->value.choice.RelayNode_Indicator =; - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - } + /* optional */ + if (0) { + ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_RelayNode_Indicator; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_RelayNode_Indicator; + // ie->value.choice.RelayNode_Indicator =; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + } #if (S1AP_VERSION >= MAKE_VERSION(11, 0, 0)) - /* optional */ - if (0) { - ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_GUMMEIType; - ie->criticality = S1AP_Criticality_reject; - ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_GUMMEIType; - // ie->value.choice.GUMMEIType =; - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - } + /* optional */ + if (0) { + ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_GUMMEIType; + ie->criticality = S1AP_Criticality_reject; + ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_GUMMEIType; + // ie->value.choice.GUMMEIType =; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + } - /* optional */ /* release 11 */ - if (0) { - ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_Tunnel_Information_for_BBF; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_TunnelInformation; - // ie->value.choice.TunnelInformation =; - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - } + /* optional */ /* release 11 */ + if (0) { + ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_Tunnel_Information_for_BBF; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_TunnelInformation; + // ie->value.choice.TunnelInformation =; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + } - /* optional */ - if (0) { - ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_SIPTO_L_GW_TransportLayerAddress; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_TransportLayerAddress; - // ie->value.choice.TransportLayerAddress = ; - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - } + /* optional */ + if (0) { + ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_SIPTO_L_GW_TransportLayerAddress; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_TransportLayerAddress; + // ie->value.choice.TransportLayerAddress = ; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + } - /* optional */ - if (0) { - ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_LHN_ID; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_LHN_ID; - // ie->value.choice.LHN_ID = ue_release_req_p->eNB_ue_s1ap_id; - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - } + /* optional */ + if (0) { + ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_LHN_ID; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_LHN_ID; + // ie->value.choice.LHN_ID = ue_release_req_p->eNB_ue_s1ap_id; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + } #if (S1AP_VERSION >= MAKE_VERSION(13, 0, 0)) - /* optional */ - if (0) { - ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_MME_Group_ID; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_MME_Group_ID; - // ie->value.choice.MME_Group_ID =; - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - } + /* optional */ + if (0) { + ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_MME_Group_ID; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_MME_Group_ID; + // ie->value.choice.MME_Group_ID =; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + } - /* optional */ - if (0) { - ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_UE_Usage_Type; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_UE_Usage_Type; - // ie->value.choice.UE_Usage_Type =; - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - } + /* optional */ + if (0) { + ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_UE_Usage_Type; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_UE_Usage_Type; + // ie->value.choice.UE_Usage_Type =; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + } - /* optional */ - if (0) { - ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_CE_mode_B_SupportIndicator; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_CE_mode_B_SupportIndicator; - // ie->value.choice.CE_mode_B_SupportIndicator = ; - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - } + /* optional */ + if (0) { + ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_CE_mode_B_SupportIndicator; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_CE_mode_B_SupportIndicator; + // ie->value.choice.CE_mode_B_SupportIndicator = ; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + } #if (S1AP_VERSION >= MAKE_VERSION(14, 0, 0)) - /* optional */ - if (0) { - ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_DCN_ID; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_DCN_ID; - // ie->value.choice.DCN_ID = ; - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - } + /* optional */ + if (0) { + ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_DCN_ID; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_DCN_ID; + // ie->value.choice.DCN_ID = ; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + } - /* optional */ - if (0) { - ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_Coverage_Level; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_Coverage_Level; - // ie->value.choice.Coverage_Level = ue_release_req_p->eNB_ue_s1ap_id; - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - } + /* optional */ + if (0) { + ie = (S1AP_InitialUEMessage_IEs_t *)calloc(1, sizeof(S1AP_InitialUEMessage_IEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_Coverage_Level; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_InitialUEMessage_IEs__value_PR_Coverage_Level; + // ie->value.choice.Coverage_Level = ue_release_req_p->eNB_ue_s1ap_id; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + } #endif /* #if (S1AP_VERSION >= MAKE_VERSION(14, 0, 0)) */ #endif /* #if (S1AP_VERSION >= MAKE_VERSION(13, 0, 0)) */ @@ -427,44 +427,44 @@ int s1ap_eNB_handle_nas_first_req( #endif /* #if (S1AP_VERSION >= MAKE_VERSION(10, 0, 0)) */ #endif /* #if (S1AP_VERSION >= MAKE_VERSION(9, 0, 0)) */ - if (s1ap_eNB_encode_pdu(&pdu, &buffer, &length) < 0) { - /* Failed to encode message */ - DevMessage("Failed to encode initial UE message\n"); - } + if (s1ap_eNB_encode_pdu(&pdu, &buffer, &length) < 0) { + /* Failed to encode message */ + DevMessage("Failed to encode initial UE message\n"); + } - /* Update the current S1AP UE state */ - ue_desc_p->ue_state = S1AP_UE_WAITING_CSR; - /* Assign a stream for this UE : - * From 3GPP 36.412 7)Transport layers: - * Within the SCTP association established between one MME and eNB pair: - * - a single pair of stream identifiers shall be reserved for the sole use - * of S1AP elementary procedures that utilize non UE-associated signalling. - * - At least one pair of stream identifiers shall be reserved for the sole use - * of S1AP elementary procedures that utilize UE-associated signallings. - * However a few pairs (i.e. more than one) should be reserved. - * - A single UE-associated signalling shall use one SCTP stream and - * the stream should not be changed during the communication of the - * UE-associated signalling. - */ - mme_desc_p->nextstream = (mme_desc_p->nextstream + 1) % mme_desc_p->out_streams; + /* Update the current S1AP UE state */ + ue_desc_p->ue_state = S1AP_UE_WAITING_CSR; + /* Assign a stream for this UE : + * From 3GPP 36.412 7)Transport layers: + * Within the SCTP association established between one MME and eNB pair: + * - a single pair of stream identifiers shall be reserved for the sole use + * of S1AP elementary procedures that utilize non UE-associated signalling. + * - At least one pair of stream identifiers shall be reserved for the sole use + * of S1AP elementary procedures that utilize UE-associated signallings. + * However a few pairs (i.e. more than one) should be reserved. + * - A single UE-associated signalling shall use one SCTP stream and + * the stream should not be changed during the communication of the + * UE-associated signalling. + */ + mme_desc_p->nextstream = (mme_desc_p->nextstream + 1) % mme_desc_p->out_streams; - if ((mme_desc_p->nextstream == 0) && (mme_desc_p->out_streams > 1)) { - mme_desc_p->nextstream += 1; - } + if ((mme_desc_p->nextstream == 0) && (mme_desc_p->out_streams > 1)) { + mme_desc_p->nextstream += 1; + } - ue_desc_p->tx_stream = mme_desc_p->nextstream; - MSC_LOG_TX_MESSAGE( - MSC_S1AP_ENB, - MSC_S1AP_MME, - (const char *)NULL, - 0, - MSC_AS_TIME_FMT" initialUEMessage initiatingMessage eNB_ue_s1ap_id %u", - 0,0,//MSC_AS_TIME_ARGS(ctxt_pP), - ue_desc_p->eNB_ue_s1ap_id); - /* Send encoded message over sctp */ - s1ap_eNB_itti_send_sctp_data_req(instance_p->instance, mme_desc_p->assoc_id, - buffer, length, ue_desc_p->tx_stream); - return 0; + ue_desc_p->tx_stream = mme_desc_p->nextstream; + MSC_LOG_TX_MESSAGE( + MSC_S1AP_ENB, + MSC_S1AP_MME, + (const char *)NULL, + 0, + MSC_AS_TIME_FMT" initialUEMessage initiatingMessage eNB_ue_s1ap_id %u", + 0,0,//MSC_AS_TIME_ARGS(ctxt_pP), + ue_desc_p->eNB_ue_s1ap_id); + /* Send encoded message over sctp */ + s1ap_eNB_itti_send_sctp_data_req(instance_p->instance, mme_desc_p->assoc_id, + buffer, length, ue_desc_p->tx_stream); + return 0; } //------------------------------------------------------------------------------ @@ -473,246 +473,258 @@ int s1ap_eNB_handle_nas_downlink(uint32_t assoc_id, S1AP_S1AP_PDU_t *pdu) //------------------------------------------------------------------------------ { - s1ap_eNB_mme_data_t *mme_desc_p = NULL; - s1ap_eNB_ue_context_t *ue_desc_p = NULL; - s1ap_eNB_instance_t *s1ap_eNB_instance = NULL; - S1AP_DownlinkNASTransport_t *container; - S1AP_DownlinkNASTransport_IEs_t *ie; - S1AP_ENB_UE_S1AP_ID_t enb_ue_s1ap_id; - S1AP_MME_UE_S1AP_ID_t mme_ue_s1ap_id; - DevAssert(pdu != NULL); - - /* UE-related procedure -> stream != 0 */ - if (stream == 0) { - S1AP_ERROR("[SCTP %d] Received UE-related procedure on stream == 0\n", - assoc_id); - return -1; - } + s1ap_eNB_mme_data_t *mme_desc_p = NULL; + s1ap_eNB_ue_context_t *ue_desc_p = NULL; + s1ap_eNB_instance_t *s1ap_eNB_instance = NULL; + S1AP_DownlinkNASTransport_t *container; + S1AP_DownlinkNASTransport_IEs_t *ie; + S1AP_ENB_UE_S1AP_ID_t enb_ue_s1ap_id; + S1AP_MME_UE_S1AP_ID_t mme_ue_s1ap_id; + DevAssert(pdu != NULL); + + /* UE-related procedure -> stream != 0 */ + if (stream == 0) { + S1AP_ERROR("[SCTP %d] Received UE-related procedure on stream == 0\n", + assoc_id); + return -1; + } - if ((mme_desc_p = s1ap_eNB_get_MME(NULL, assoc_id, 0)) == NULL) { - S1AP_ERROR( - "[SCTP %d] Received NAS downlink message for non existing MME context\n", - assoc_id); - return -1; - } + if ((mme_desc_p = s1ap_eNB_get_MME(NULL, assoc_id, 0)) == NULL) { + S1AP_ERROR( + "[SCTP %d] Received NAS downlink message for non existing MME context\n", + assoc_id); + return -1; + } - s1ap_eNB_instance = mme_desc_p->s1ap_eNB_instance; - /* Prepare the S1AP message to encode */ - container = &pdu->choice.initiatingMessage.value.choice.DownlinkNASTransport; - S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_DownlinkNASTransport_IEs_t, ie, container, - S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID, true); - mme_ue_s1ap_id = ie->value.choice.MME_UE_S1AP_ID; - S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_DownlinkNASTransport_IEs_t, ie, container, - S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID, true); - enb_ue_s1ap_id = ie->value.choice.ENB_UE_S1AP_ID; - - if ((ue_desc_p = s1ap_eNB_get_ue_context(s1ap_eNB_instance, - enb_ue_s1ap_id)) == NULL) { - MSC_LOG_RX_DISCARDED_MESSAGE( - MSC_S1AP_ENB, - MSC_S1AP_MME, - NULL, - 0, - MSC_AS_TIME_FMT" downlinkNASTransport eNB_ue_s1ap_id %u mme_ue_s1ap_id %u", - enb_ue_s1ap_id, - mme_ue_s1ap_id); - S1AP_ERROR("[SCTP %d] Received NAS downlink message for non existing UE context eNB_UE_S1AP_ID: 0x%lx\n", - assoc_id, - enb_ue_s1ap_id); - return -1; - } + s1ap_eNB_instance = mme_desc_p->s1ap_eNB_instance; + /* Prepare the S1AP message to encode */ + container = &pdu->choice.initiatingMessage.value.choice.DownlinkNASTransport; + S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_DownlinkNASTransport_IEs_t, ie, container, + S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID, true); + if (ie == NULL) { /* checked by macro, but cppcheck doesn't see it */ + return -1; + } else { + mme_ue_s1ap_id = ie->value.choice.MME_UE_S1AP_ID; + } + S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_DownlinkNASTransport_IEs_t, ie, container, + S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID, true); + if (ie == NULL) { /* checked by macro, but cppcheck doesn't see it */ + return -1; + } else { + enb_ue_s1ap_id = ie->value.choice.ENB_UE_S1AP_ID; + } + if ((ue_desc_p = s1ap_eNB_get_ue_context(s1ap_eNB_instance, + enb_ue_s1ap_id)) == NULL) { + MSC_LOG_RX_DISCARDED_MESSAGE( + MSC_S1AP_ENB, + MSC_S1AP_MME, + NULL, + 0, + MSC_AS_TIME_FMT" downlinkNASTransport eNB_ue_s1ap_id %u mme_ue_s1ap_id %u", + enb_ue_s1ap_id, + mme_ue_s1ap_id); + S1AP_ERROR("[SCTP %d] Received NAS downlink message for non existing UE context eNB_UE_S1AP_ID: 0x%lx\n", + assoc_id, + enb_ue_s1ap_id); + return -1; + } - if (0 == ue_desc_p->rx_stream) { - ue_desc_p->rx_stream = stream; - } else if (stream != ue_desc_p->rx_stream) { - S1AP_ERROR("[SCTP %d] Received UE-related procedure on stream %u, expecting %u\n", - assoc_id, stream, ue_desc_p->rx_stream); - return -1; - } + if (0 == ue_desc_p->rx_stream) { + ue_desc_p->rx_stream = stream; + } else if (stream != ue_desc_p->rx_stream) { + S1AP_ERROR("[SCTP %d] Received UE-related procedure on stream %u, expecting %u\n", + assoc_id, stream, ue_desc_p->rx_stream); + return -1; + } - /* Is it the first outcome of the MME for this UE ? If so store the mme - * UE s1ap id. - */ - if (ue_desc_p->mme_ue_s1ap_id == 0) { - ue_desc_p->mme_ue_s1ap_id = mme_ue_s1ap_id; - } else { - /* We already have a mme ue s1ap id check the received is the same */ - if (ue_desc_p->mme_ue_s1ap_id != mme_ue_s1ap_id) { - S1AP_ERROR("[SCTP %d] Mismatch in MME UE S1AP ID (0x%lx != 0x%"PRIx32"\n", - assoc_id, - mme_ue_s1ap_id, - ue_desc_p->mme_ue_s1ap_id - ); - return -1; + /* Is it the first outcome of the MME for this UE ? If so store the mme + * UE s1ap id. + */ + if (ue_desc_p->mme_ue_s1ap_id == 0) { + ue_desc_p->mme_ue_s1ap_id = mme_ue_s1ap_id; + } else { + /* We already have a mme ue s1ap id check the received is the same */ + if (ue_desc_p->mme_ue_s1ap_id != mme_ue_s1ap_id) { + S1AP_ERROR("[SCTP %d] Mismatch in MME UE S1AP ID (0x%lx != 0x%"PRIx32"\n", + assoc_id, + mme_ue_s1ap_id, + ue_desc_p->mme_ue_s1ap_id + ); + return -1; + } } - } - MSC_LOG_RX_MESSAGE( - MSC_S1AP_ENB, - MSC_S1AP_MME, - NULL, - 0, - MSC_AS_TIME_FMT" downlinkNASTransport eNB_ue_s1ap_id %u mme_ue_s1ap_id %u", - assoc_id, - mme_ue_s1ap_id); - S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_DownlinkNASTransport_IEs_t, ie, container, - S1AP_ProtocolIE_ID_id_NAS_PDU, true); - /* Forward the NAS PDU to RRC */ - s1ap_eNB_itti_send_nas_downlink_ind(s1ap_eNB_instance->instance, - ue_desc_p->ue_initial_id, - ue_desc_p->eNB_ue_s1ap_id, - ie->value.choice.NAS_PDU.buf, - ie->value.choice.NAS_PDU.size); - return 0; + MSC_LOG_RX_MESSAGE( + MSC_S1AP_ENB, + MSC_S1AP_MME, + NULL, + 0, + MSC_AS_TIME_FMT" downlinkNASTransport eNB_ue_s1ap_id %u mme_ue_s1ap_id %u", + assoc_id, + mme_ue_s1ap_id); + + S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_DownlinkNASTransport_IEs_t, ie, container, + S1AP_ProtocolIE_ID_id_NAS_PDU, true); + /* Forward the NAS PDU to RRC */ + if (ie != NULL) { /* checked by macro, but cppcheck doesn't see it */ + s1ap_eNB_itti_send_nas_downlink_ind(s1ap_eNB_instance->instance, + ue_desc_p->ue_initial_id, + ue_desc_p->eNB_ue_s1ap_id, + ie->value.choice.NAS_PDU.buf, + ie->value.choice.NAS_PDU.size); + } else { + return -1; + } + return 0; } //------------------------------------------------------------------------------ int s1ap_eNB_nas_uplink(instance_t instance, s1ap_uplink_nas_t *s1ap_uplink_nas_p) //------------------------------------------------------------------------------ { - struct s1ap_eNB_ue_context_s *ue_context_p; - s1ap_eNB_instance_t *s1ap_eNB_instance_p; - S1AP_S1AP_PDU_t pdu; - S1AP_UplinkNASTransport_t *out; - S1AP_UplinkNASTransport_IEs_t *ie; - uint8_t *buffer; - uint32_t length; - DevAssert(s1ap_uplink_nas_p != NULL); - /* Retrieve the S1AP eNB instance associated with Mod_id */ - s1ap_eNB_instance_p = s1ap_eNB_get_instance(instance); - DevAssert(s1ap_eNB_instance_p != NULL); - - if ((ue_context_p = s1ap_eNB_get_ue_context(s1ap_eNB_instance_p, s1ap_uplink_nas_p->eNB_ue_s1ap_id)) == NULL) { - /* The context for this eNB ue s1ap id doesn't exist in the map of eNB UEs */ - S1AP_WARN("Failed to find ue context associated with eNB ue s1ap id: %06x\n", - s1ap_uplink_nas_p->eNB_ue_s1ap_id); - return -1; - } - - /* Uplink NAS transport can occur either during an s1ap connected state - * or during initial attach (for example: NAS authentication). - */ - if (!(ue_context_p->ue_state == S1AP_UE_CONNECTED || - ue_context_p->ue_state == S1AP_UE_WAITING_CSR)) { - S1AP_WARN("You are attempting to send NAS data over non-connected " - "eNB ue s1ap id: %u, current state: %d\n", - s1ap_uplink_nas_p->eNB_ue_s1ap_id, ue_context_p->ue_state); - return -1; - } + struct s1ap_eNB_ue_context_s *ue_context_p; + s1ap_eNB_instance_t *s1ap_eNB_instance_p; + S1AP_S1AP_PDU_t pdu; + S1AP_UplinkNASTransport_t *out; + S1AP_UplinkNASTransport_IEs_t *ie; + uint8_t *buffer; + uint32_t length; + DevAssert(s1ap_uplink_nas_p != NULL); + /* Retrieve the S1AP eNB instance associated with Mod_id */ + s1ap_eNB_instance_p = s1ap_eNB_get_instance(instance); + DevAssert(s1ap_eNB_instance_p != NULL); + + if ((ue_context_p = s1ap_eNB_get_ue_context(s1ap_eNB_instance_p, s1ap_uplink_nas_p->eNB_ue_s1ap_id)) == NULL) { + /* The context for this eNB ue s1ap id doesn't exist in the map of eNB UEs */ + S1AP_WARN("Failed to find ue context associated with eNB ue s1ap id: %06x\n", + s1ap_uplink_nas_p->eNB_ue_s1ap_id); + return -1; + } - /* Prepare the S1AP message to encode */ - memset(&pdu, 0, sizeof(pdu)); - pdu.present = S1AP_S1AP_PDU_PR_initiatingMessage; - pdu.choice.initiatingMessage.procedureCode = S1AP_ProcedureCode_id_uplinkNASTransport; - pdu.choice.initiatingMessage.criticality = S1AP_Criticality_ignore; - pdu.choice.initiatingMessage.value.present = S1AP_InitiatingMessage__value_PR_UplinkNASTransport; - out = &pdu.choice.initiatingMessage.value.choice.UplinkNASTransport; - /* mandatory */ - ie = (S1AP_UplinkNASTransport_IEs_t *)calloc(1, sizeof(S1AP_UplinkNASTransport_IEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID; - ie->criticality = S1AP_Criticality_reject; - ie->value.present = S1AP_UplinkNASTransport_IEs__value_PR_MME_UE_S1AP_ID; - ie->value.choice.MME_UE_S1AP_ID = ue_context_p->mme_ue_s1ap_id; - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - /* mandatory */ - ie = (S1AP_UplinkNASTransport_IEs_t *)calloc(1, sizeof(S1AP_UplinkNASTransport_IEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID; - ie->criticality = S1AP_Criticality_reject; - ie->value.present = S1AP_UplinkNASTransport_IEs__value_PR_ENB_UE_S1AP_ID; - ie->value.choice.ENB_UE_S1AP_ID = ue_context_p->eNB_ue_s1ap_id; - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - /* mandatory */ - ie = (S1AP_UplinkNASTransport_IEs_t *)calloc(1, sizeof(S1AP_UplinkNASTransport_IEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_NAS_PDU; - ie->criticality = S1AP_Criticality_reject; - ie->value.present = S1AP_UplinkNASTransport_IEs__value_PR_NAS_PDU; - ie->value.choice.NAS_PDU.buf = s1ap_uplink_nas_p->nas_pdu.buffer; - ie->value.choice.NAS_PDU.size = s1ap_uplink_nas_p->nas_pdu.length; - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - /* mandatory */ - ie = (S1AP_UplinkNASTransport_IEs_t *)calloc(1, sizeof(S1AP_UplinkNASTransport_IEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_EUTRAN_CGI; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_UplinkNASTransport_IEs__value_PR_EUTRAN_CGI; - MCC_MNC_TO_PLMNID( - s1ap_eNB_instance_p->mcc[ue_context_p->selected_plmn_identity], - s1ap_eNB_instance_p->mnc[ue_context_p->selected_plmn_identity], - s1ap_eNB_instance_p->mnc_digit_length[ue_context_p->selected_plmn_identity], - &ie->value.choice.EUTRAN_CGI.pLMNidentity); - //#warning "TODO get cell id from RRC" - MACRO_ENB_ID_TO_CELL_IDENTITY(s1ap_eNB_instance_p->eNB_id, - 0, - &ie->value.choice.EUTRAN_CGI.cell_ID); - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - /* mandatory */ - ie = (S1AP_UplinkNASTransport_IEs_t *)calloc(1, sizeof(S1AP_UplinkNASTransport_IEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_TAI; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_UplinkNASTransport_IEs__value_PR_TAI; - MCC_MNC_TO_PLMNID( - s1ap_eNB_instance_p->mcc[ue_context_p->selected_plmn_identity], - s1ap_eNB_instance_p->mnc[ue_context_p->selected_plmn_identity], - s1ap_eNB_instance_p->mnc_digit_length[ue_context_p->selected_plmn_identity], - &ie->value.choice.TAI.pLMNidentity); - TAC_TO_ASN1(s1ap_eNB_instance_p->tac, &ie->value.choice.TAI.tAC); - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - /* optional */ -#if (S1AP_VERSION >= MAKE_VERSION(10, 0, 0)) + /* Uplink NAS transport can occur either during an s1ap connected state + * or during initial attach (for example: NAS authentication). + */ + if (!(ue_context_p->ue_state == S1AP_UE_CONNECTED || + ue_context_p->ue_state == S1AP_UE_WAITING_CSR)) { + S1AP_WARN("You are attempting to send NAS data over non-connected " + "eNB ue s1ap id: %u, current state: %d\n", + s1ap_uplink_nas_p->eNB_ue_s1ap_id, ue_context_p->ue_state); + return -1; + } - if (0) { + /* Prepare the S1AP message to encode */ + memset(&pdu, 0, sizeof(pdu)); + pdu.present = S1AP_S1AP_PDU_PR_initiatingMessage; + pdu.choice.initiatingMessage.procedureCode = S1AP_ProcedureCode_id_uplinkNASTransport; + pdu.choice.initiatingMessage.criticality = S1AP_Criticality_ignore; + pdu.choice.initiatingMessage.value.present = S1AP_InitiatingMessage__value_PR_UplinkNASTransport; + out = &pdu.choice.initiatingMessage.value.choice.UplinkNASTransport; + /* mandatory */ ie = (S1AP_UplinkNASTransport_IEs_t *)calloc(1, sizeof(S1AP_UplinkNASTransport_IEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_GW_TransportLayerAddress; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_UplinkNASTransport_IEs__value_PR_TransportLayerAddress; - // ie->value.choice.TransportLayerAddress = ; + ie->id = S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID; + ie->criticality = S1AP_Criticality_reject; + ie->value.present = S1AP_UplinkNASTransport_IEs__value_PR_MME_UE_S1AP_ID; + ie->value.choice.MME_UE_S1AP_ID = ue_context_p->mme_ue_s1ap_id; ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - } - - /* optional */ -#if (S1AP_VERSION >= MAKE_VERSION(14, 0, 0)) - - if (0) { + /* mandatory */ + ie = (S1AP_UplinkNASTransport_IEs_t *)calloc(1, sizeof(S1AP_UplinkNASTransport_IEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID; + ie->criticality = S1AP_Criticality_reject; + ie->value.present = S1AP_UplinkNASTransport_IEs__value_PR_ENB_UE_S1AP_ID; + ie->value.choice.ENB_UE_S1AP_ID = ue_context_p->eNB_ue_s1ap_id; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + /* mandatory */ + ie = (S1AP_UplinkNASTransport_IEs_t *)calloc(1, sizeof(S1AP_UplinkNASTransport_IEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_NAS_PDU; + ie->criticality = S1AP_Criticality_reject; + ie->value.present = S1AP_UplinkNASTransport_IEs__value_PR_NAS_PDU; + ie->value.choice.NAS_PDU.buf = s1ap_uplink_nas_p->nas_pdu.buffer; + ie->value.choice.NAS_PDU.size = s1ap_uplink_nas_p->nas_pdu.length; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + /* mandatory */ ie = (S1AP_UplinkNASTransport_IEs_t *)calloc(1, sizeof(S1AP_UplinkNASTransport_IEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_SIPTO_L_GW_TransportLayerAddress; + ie->id = S1AP_ProtocolIE_ID_id_EUTRAN_CGI; ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_UplinkNASTransport_IEs__value_PR_TransportLayerAddress; - // ie->value.choice.TransportLayerAddress = ; + ie->value.present = S1AP_UplinkNASTransport_IEs__value_PR_EUTRAN_CGI; + MCC_MNC_TO_PLMNID( + s1ap_eNB_instance_p->mcc[ue_context_p->selected_plmn_identity], + s1ap_eNB_instance_p->mnc[ue_context_p->selected_plmn_identity], + s1ap_eNB_instance_p->mnc_digit_length[ue_context_p->selected_plmn_identity], + &ie->value.choice.EUTRAN_CGI.pLMNidentity); + //#warning "TODO get cell id from RRC" + MACRO_ENB_ID_TO_CELL_IDENTITY(s1ap_eNB_instance_p->eNB_id, + 0, + &ie->value.choice.EUTRAN_CGI.cell_ID); ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - } - - /* optional */ - if (0) { + /* mandatory */ ie = (S1AP_UplinkNASTransport_IEs_t *)calloc(1, sizeof(S1AP_UplinkNASTransport_IEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_LHN_ID; + ie->id = S1AP_ProtocolIE_ID_id_TAI; ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_UplinkNASTransport_IEs__value_PR_LHN_ID; - // ie->value.choice.LHN_ID =; + ie->value.present = S1AP_UplinkNASTransport_IEs__value_PR_TAI; + MCC_MNC_TO_PLMNID( + s1ap_eNB_instance_p->mcc[ue_context_p->selected_plmn_identity], + s1ap_eNB_instance_p->mnc[ue_context_p->selected_plmn_identity], + s1ap_eNB_instance_p->mnc_digit_length[ue_context_p->selected_plmn_identity], + &ie->value.choice.TAI.pLMNidentity); + TAC_TO_ASN1(s1ap_eNB_instance_p->tac, &ie->value.choice.TAI.tAC); ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - } + /* optional */ +#if (S1AP_VERSION >= MAKE_VERSION(10, 0, 0)) + + if (0) { + ie = (S1AP_UplinkNASTransport_IEs_t *)calloc(1, sizeof(S1AP_UplinkNASTransport_IEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_GW_TransportLayerAddress; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_UplinkNASTransport_IEs__value_PR_TransportLayerAddress; + // ie->value.choice.TransportLayerAddress = ; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + } + + /* optional */ +#if (S1AP_VERSION >= MAKE_VERSION(14, 0, 0)) + + if (0) { + ie = (S1AP_UplinkNASTransport_IEs_t *)calloc(1, sizeof(S1AP_UplinkNASTransport_IEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_SIPTO_L_GW_TransportLayerAddress; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_UplinkNASTransport_IEs__value_PR_TransportLayerAddress; + // ie->value.choice.TransportLayerAddress = ; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + } + + /* optional */ + if (0) { + ie = (S1AP_UplinkNASTransport_IEs_t *)calloc(1, sizeof(S1AP_UplinkNASTransport_IEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_LHN_ID; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_UplinkNASTransport_IEs__value_PR_LHN_ID; + // ie->value.choice.LHN_ID =; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + } #endif /* #if (S1AP_VERSION >= MAKE_VERSION(14, 0, 0)) */ #endif /* #if (S1AP_VERSION >= MAKE_VERSION(10, 0, 0)) */ - if (s1ap_eNB_encode_pdu(&pdu, &buffer, &length) < 0) { - S1AP_ERROR("Failed to encode uplink NAS transport\n"); - /* Encode procedure has failed... */ - return -1; - } + if (s1ap_eNB_encode_pdu(&pdu, &buffer, &length) < 0) { + S1AP_ERROR("Failed to encode uplink NAS transport\n"); + /* Encode procedure has failed... */ + return -1; + } - MSC_LOG_TX_MESSAGE( - MSC_S1AP_ENB, - MSC_S1AP_MME, - (const char *)NULL, - 0, - MSC_AS_TIME_FMT" uplinkNASTransport initiatingMessage eNB_ue_s1ap_id %u mme_ue_s1ap_id %u", - 0,0,//MSC_AS_TIME_ARGS(ctxt_pP), - ue_context_p->eNB_ue_s1ap_id, - ue_context_p->mme_ue_s1ap_id); - /* UE associated signalling -> use the allocated stream */ - s1ap_eNB_itti_send_sctp_data_req(s1ap_eNB_instance_p->instance, - ue_context_p->mme_ref->assoc_id, buffer, - length, ue_context_p->tx_stream); - return 0; + MSC_LOG_TX_MESSAGE( + MSC_S1AP_ENB, + MSC_S1AP_MME, + (const char *)NULL, + 0, + MSC_AS_TIME_FMT" uplinkNASTransport initiatingMessage eNB_ue_s1ap_id %u mme_ue_s1ap_id %u", + 0,0,//MSC_AS_TIME_ARGS(ctxt_pP), + ue_context_p->eNB_ue_s1ap_id, + ue_context_p->mme_ue_s1ap_id); + /* UE associated signalling -> use the allocated stream */ + s1ap_eNB_itti_send_sctp_data_req(s1ap_eNB_instance_p->instance, + ue_context_p->mme_ref->assoc_id, buffer, + length, ue_context_p->tx_stream); + return 0; } @@ -721,549 +733,549 @@ int s1ap_eNB_nas_non_delivery_ind(instance_t instance, s1ap_nas_non_delivery_ind_t *s1ap_nas_non_delivery_ind) //------------------------------------------------------------------------------ { - struct s1ap_eNB_ue_context_s *ue_context_p; - s1ap_eNB_instance_t *s1ap_eNB_instance_p; - S1AP_S1AP_PDU_t pdu; - S1AP_NASNonDeliveryIndication_t *out; - S1AP_NASNonDeliveryIndication_IEs_t *ie; - uint8_t *buffer; - uint32_t length; - DevAssert(s1ap_nas_non_delivery_ind != NULL); - /* Retrieve the S1AP eNB instance associated with Mod_id */ - s1ap_eNB_instance_p = s1ap_eNB_get_instance(instance); - DevAssert(s1ap_eNB_instance_p != NULL); - - if ((ue_context_p = s1ap_eNB_get_ue_context(s1ap_eNB_instance_p, s1ap_nas_non_delivery_ind->eNB_ue_s1ap_id)) == NULL) { - /* The context for this eNB ue s1ap id doesn't exist in the map of eNB UEs */ - S1AP_WARN("Failed to find ue context associated with eNB ue s1ap id: %06x\n", - s1ap_nas_non_delivery_ind->eNB_ue_s1ap_id); - MSC_LOG_EVENT( - MSC_S1AP_ENB, - MSC_AS_TIME_FMT" Sent of NAS_NON_DELIVERY_IND to MME failed, no context for eNB_ue_s1ap_id %06x", - s1ap_nas_non_delivery_ind->eNB_ue_s1ap_id); - return -1; - } + struct s1ap_eNB_ue_context_s *ue_context_p; + s1ap_eNB_instance_t *s1ap_eNB_instance_p; + S1AP_S1AP_PDU_t pdu; + S1AP_NASNonDeliveryIndication_t *out; + S1AP_NASNonDeliveryIndication_IEs_t *ie; + uint8_t *buffer; + uint32_t length; + DevAssert(s1ap_nas_non_delivery_ind != NULL); + /* Retrieve the S1AP eNB instance associated with Mod_id */ + s1ap_eNB_instance_p = s1ap_eNB_get_instance(instance); + DevAssert(s1ap_eNB_instance_p != NULL); + + if ((ue_context_p = s1ap_eNB_get_ue_context(s1ap_eNB_instance_p, s1ap_nas_non_delivery_ind->eNB_ue_s1ap_id)) == NULL) { + /* The context for this eNB ue s1ap id doesn't exist in the map of eNB UEs */ + S1AP_WARN("Failed to find ue context associated with eNB ue s1ap id: %06x\n", + s1ap_nas_non_delivery_ind->eNB_ue_s1ap_id); + MSC_LOG_EVENT( + MSC_S1AP_ENB, + MSC_AS_TIME_FMT" Sent of NAS_NON_DELIVERY_IND to MME failed, no context for eNB_ue_s1ap_id %06x", + s1ap_nas_non_delivery_ind->eNB_ue_s1ap_id); + return -1; + } - /* Prepare the S1AP message to encode */ - memset(&pdu, 0, sizeof(pdu)); - pdu.present = S1AP_S1AP_PDU_PR_initiatingMessage; - pdu.choice.initiatingMessage.procedureCode = S1AP_ProcedureCode_id_NASNonDeliveryIndication; - pdu.choice.initiatingMessage.criticality = S1AP_Criticality_ignore; - pdu.choice.initiatingMessage.value.present = S1AP_InitiatingMessage__value_PR_NASNonDeliveryIndication; - out = &pdu.choice.initiatingMessage.value.choice.NASNonDeliveryIndication; - /* mandatory */ - ie = (S1AP_NASNonDeliveryIndication_IEs_t *)calloc(1, sizeof(S1AP_NASNonDeliveryIndication_IEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID; - ie->criticality = S1AP_Criticality_reject; - ie->value.present = S1AP_NASNonDeliveryIndication_IEs__value_PR_MME_UE_S1AP_ID; - ie->value.choice.MME_UE_S1AP_ID = ue_context_p->mme_ue_s1ap_id; - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - /* mandatory */ - ie = (S1AP_NASNonDeliveryIndication_IEs_t *)calloc(1, sizeof(S1AP_NASNonDeliveryIndication_IEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID; - ie->criticality = S1AP_Criticality_reject; - ie->value.present = S1AP_NASNonDeliveryIndication_IEs__value_PR_ENB_UE_S1AP_ID; - ie->value.choice.ENB_UE_S1AP_ID = ue_context_p->eNB_ue_s1ap_id; - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - /* mandatory */ - ie = (S1AP_NASNonDeliveryIndication_IEs_t *)calloc(1, sizeof(S1AP_NASNonDeliveryIndication_IEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_NAS_PDU; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_NASNonDeliveryIndication_IEs__value_PR_NAS_PDU; - ie->value.choice.NAS_PDU.buf = s1ap_nas_non_delivery_ind->nas_pdu.buffer; - ie->value.choice.NAS_PDU.size = s1ap_nas_non_delivery_ind->nas_pdu.length; - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - /* mandatory */ - ie = (S1AP_NASNonDeliveryIndication_IEs_t *)calloc(1, sizeof(S1AP_NASNonDeliveryIndication_IEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_Cause; - ie->criticality = S1AP_Criticality_ignore; - /* Send a dummy cause */ - ie->value.present = S1AP_NASNonDeliveryIndication_IEs__value_PR_Cause; - ie->value.choice.Cause.present = S1AP_Cause_PR_radioNetwork; - ie->value.choice.Cause.choice.radioNetwork = S1AP_CauseRadioNetwork_radio_connection_with_ue_lost; - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + /* Prepare the S1AP message to encode */ + memset(&pdu, 0, sizeof(pdu)); + pdu.present = S1AP_S1AP_PDU_PR_initiatingMessage; + pdu.choice.initiatingMessage.procedureCode = S1AP_ProcedureCode_id_NASNonDeliveryIndication; + pdu.choice.initiatingMessage.criticality = S1AP_Criticality_ignore; + pdu.choice.initiatingMessage.value.present = S1AP_InitiatingMessage__value_PR_NASNonDeliveryIndication; + out = &pdu.choice.initiatingMessage.value.choice.NASNonDeliveryIndication; + /* mandatory */ + ie = (S1AP_NASNonDeliveryIndication_IEs_t *)calloc(1, sizeof(S1AP_NASNonDeliveryIndication_IEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID; + ie->criticality = S1AP_Criticality_reject; + ie->value.present = S1AP_NASNonDeliveryIndication_IEs__value_PR_MME_UE_S1AP_ID; + ie->value.choice.MME_UE_S1AP_ID = ue_context_p->mme_ue_s1ap_id; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + /* mandatory */ + ie = (S1AP_NASNonDeliveryIndication_IEs_t *)calloc(1, sizeof(S1AP_NASNonDeliveryIndication_IEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID; + ie->criticality = S1AP_Criticality_reject; + ie->value.present = S1AP_NASNonDeliveryIndication_IEs__value_PR_ENB_UE_S1AP_ID; + ie->value.choice.ENB_UE_S1AP_ID = ue_context_p->eNB_ue_s1ap_id; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + /* mandatory */ + ie = (S1AP_NASNonDeliveryIndication_IEs_t *)calloc(1, sizeof(S1AP_NASNonDeliveryIndication_IEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_NAS_PDU; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_NASNonDeliveryIndication_IEs__value_PR_NAS_PDU; + ie->value.choice.NAS_PDU.buf = s1ap_nas_non_delivery_ind->nas_pdu.buffer; + ie->value.choice.NAS_PDU.size = s1ap_nas_non_delivery_ind->nas_pdu.length; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + /* mandatory */ + ie = (S1AP_NASNonDeliveryIndication_IEs_t *)calloc(1, sizeof(S1AP_NASNonDeliveryIndication_IEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_Cause; + ie->criticality = S1AP_Criticality_ignore; + /* Send a dummy cause */ + ie->value.present = S1AP_NASNonDeliveryIndication_IEs__value_PR_Cause; + ie->value.choice.Cause.present = S1AP_Cause_PR_radioNetwork; + ie->value.choice.Cause.choice.radioNetwork = S1AP_CauseRadioNetwork_radio_connection_with_ue_lost; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - if (s1ap_eNB_encode_pdu(&pdu, &buffer, &length) < 0) { - S1AP_ERROR("Failed to encode NAS NON delivery indication\n"); - /* Encode procedure has failed... */ - MSC_LOG_EVENT( - MSC_S1AP_ENB, - MSC_AS_TIME_FMT" Sent of NAS_NON_DELIVERY_IND to MME failed (encoding)"); - return -1; - } + if (s1ap_eNB_encode_pdu(&pdu, &buffer, &length) < 0) { + S1AP_ERROR("Failed to encode NAS NON delivery indication\n"); + /* Encode procedure has failed... */ + MSC_LOG_EVENT( + MSC_S1AP_ENB, + MSC_AS_TIME_FMT" Sent of NAS_NON_DELIVERY_IND to MME failed (encoding)"); + return -1; + } - MSC_LOG_TX_MESSAGE( - MSC_S1AP_ENB, - MSC_S1AP_MME, - (const char *)buffer, - length, - MSC_AS_TIME_FMT" NASNonDeliveryIndication initiatingMessage eNB_ue_s1ap_id %u mme_ue_s1ap_id %u", - 0,0,//MSC_AS_TIME_ARGS(ctxt_pP), - ue_context_p->eNB_ue_s1ap_id, - ue_context_p->mme_ue_s1ap_id); - /* UE associated signalling -> use the allocated stream */ - s1ap_eNB_itti_send_sctp_data_req(s1ap_eNB_instance_p->instance, - ue_context_p->mme_ref->assoc_id, buffer, - length, ue_context_p->tx_stream); - return 0; + MSC_LOG_TX_MESSAGE( + MSC_S1AP_ENB, + MSC_S1AP_MME, + (const char *)buffer, + length, + MSC_AS_TIME_FMT" NASNonDeliveryIndication initiatingMessage eNB_ue_s1ap_id %u mme_ue_s1ap_id %u", + 0,0,//MSC_AS_TIME_ARGS(ctxt_pP), + ue_context_p->eNB_ue_s1ap_id, + ue_context_p->mme_ue_s1ap_id); + /* UE associated signalling -> use the allocated stream */ + s1ap_eNB_itti_send_sctp_data_req(s1ap_eNB_instance_p->instance, + ue_context_p->mme_ref->assoc_id, buffer, + length, ue_context_p->tx_stream); + return 0; } //------------------------------------------------------------------------------ int s1ap_eNB_initial_ctxt_resp( - instance_t instance, s1ap_initial_context_setup_resp_t *initial_ctxt_resp_p) + instance_t instance, s1ap_initial_context_setup_resp_t *initial_ctxt_resp_p) //------------------------------------------------------------------------------ { - s1ap_eNB_instance_t *s1ap_eNB_instance_p = NULL; - struct s1ap_eNB_ue_context_s *ue_context_p = NULL; - S1AP_S1AP_PDU_t pdu; - S1AP_InitialContextSetupResponse_t *out; - S1AP_InitialContextSetupResponseIEs_t *ie; - uint8_t *buffer = NULL; - uint32_t length; - int i; - /* Retrieve the S1AP eNB instance associated with Mod_id */ - s1ap_eNB_instance_p = s1ap_eNB_get_instance(instance); - DevAssert(initial_ctxt_resp_p != NULL); - DevAssert(s1ap_eNB_instance_p != NULL); - - if ((ue_context_p = s1ap_eNB_get_ue_context(s1ap_eNB_instance_p, - initial_ctxt_resp_p->eNB_ue_s1ap_id)) == NULL) { - /* The context for this eNB ue s1ap id doesn't exist in the map of eNB UEs */ - S1AP_WARN("Failed to find ue context associated with eNB ue s1ap id: 0x%06x\n", - initial_ctxt_resp_p->eNB_ue_s1ap_id); - return -1; - } - - /* Uplink NAS transport can occur either during an s1ap connected state - * or during initial attach (for example: NAS authentication). - */ - if (!(ue_context_p->ue_state == S1AP_UE_CONNECTED || - ue_context_p->ue_state == S1AP_UE_WAITING_CSR)) { - S1AP_WARN("You are attempting to send NAS data over non-connected " - "eNB ue s1ap id: %06x, current state: %d\n", - initial_ctxt_resp_p->eNB_ue_s1ap_id, ue_context_p->ue_state); - return -1; - } + s1ap_eNB_instance_t *s1ap_eNB_instance_p = NULL; + struct s1ap_eNB_ue_context_s *ue_context_p = NULL; + S1AP_S1AP_PDU_t pdu; + S1AP_InitialContextSetupResponse_t *out; + S1AP_InitialContextSetupResponseIEs_t *ie; + uint8_t *buffer = NULL; + uint32_t length; + int i; + /* Retrieve the S1AP eNB instance associated with Mod_id */ + s1ap_eNB_instance_p = s1ap_eNB_get_instance(instance); + DevAssert(initial_ctxt_resp_p != NULL); + DevAssert(s1ap_eNB_instance_p != NULL); + + if ((ue_context_p = s1ap_eNB_get_ue_context(s1ap_eNB_instance_p, + initial_ctxt_resp_p->eNB_ue_s1ap_id)) == NULL) { + /* The context for this eNB ue s1ap id doesn't exist in the map of eNB UEs */ + S1AP_WARN("Failed to find ue context associated with eNB ue s1ap id: 0x%06x\n", + initial_ctxt_resp_p->eNB_ue_s1ap_id); + return -1; + } - /* Prepare the S1AP message to encode */ - memset(&pdu, 0, sizeof(pdu)); - pdu.present = S1AP_S1AP_PDU_PR_successfulOutcome; - pdu.choice.successfulOutcome.procedureCode = S1AP_ProcedureCode_id_InitialContextSetup; - pdu.choice.successfulOutcome.criticality = S1AP_Criticality_reject; - pdu.choice.successfulOutcome.value.present = S1AP_SuccessfulOutcome__value_PR_InitialContextSetupResponse; - out = &pdu.choice.successfulOutcome.value.choice.InitialContextSetupResponse; - /* mandatory */ - ie = (S1AP_InitialContextSetupResponseIEs_t *)calloc(1, sizeof(S1AP_InitialContextSetupResponseIEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_InitialContextSetupResponseIEs__value_PR_MME_UE_S1AP_ID; - ie->value.choice.MME_UE_S1AP_ID = ue_context_p->mme_ue_s1ap_id; - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - /* mandatory */ - ie = (S1AP_InitialContextSetupResponseIEs_t *)calloc(1, sizeof(S1AP_InitialContextSetupResponseIEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_InitialContextSetupResponseIEs__value_PR_ENB_UE_S1AP_ID; - ie->value.choice.ENB_UE_S1AP_ID = initial_ctxt_resp_p->eNB_ue_s1ap_id; - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - /* mandatory */ - ie = (S1AP_InitialContextSetupResponseIEs_t *)calloc(1, sizeof(S1AP_InitialContextSetupResponseIEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_E_RABSetupListCtxtSURes; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_InitialContextSetupResponseIEs__value_PR_E_RABSetupListCtxtSURes; + /* Uplink NAS transport can occur either during an s1ap connected state + * or during initial attach (for example: NAS authentication). + */ + if (!(ue_context_p->ue_state == S1AP_UE_CONNECTED || + ue_context_p->ue_state == S1AP_UE_WAITING_CSR)) { + S1AP_WARN("You are attempting to send NAS data over non-connected " + "eNB ue s1ap id: %06x, current state: %d\n", + initial_ctxt_resp_p->eNB_ue_s1ap_id, ue_context_p->ue_state); + return -1; + } - for (i = 0; i < initial_ctxt_resp_p->nb_of_e_rabs; i++) { - S1AP_E_RABSetupItemCtxtSUResIEs_t *item; + /* Prepare the S1AP message to encode */ + memset(&pdu, 0, sizeof(pdu)); + pdu.present = S1AP_S1AP_PDU_PR_successfulOutcome; + pdu.choice.successfulOutcome.procedureCode = S1AP_ProcedureCode_id_InitialContextSetup; + pdu.choice.successfulOutcome.criticality = S1AP_Criticality_reject; + pdu.choice.successfulOutcome.value.present = S1AP_SuccessfulOutcome__value_PR_InitialContextSetupResponse; + out = &pdu.choice.successfulOutcome.value.choice.InitialContextSetupResponse; /* mandatory */ - item = (S1AP_E_RABSetupItemCtxtSUResIEs_t *)calloc(1, sizeof(S1AP_E_RABSetupItemCtxtSUResIEs_t)); - item->id = S1AP_ProtocolIE_ID_id_E_RABSetupItemCtxtSURes; - item->criticality = S1AP_Criticality_ignore; - item->value.present = S1AP_E_RABSetupItemCtxtSUResIEs__value_PR_E_RABSetupItemCtxtSURes; - item->value.choice.E_RABSetupItemCtxtSURes.e_RAB_ID = initial_ctxt_resp_p->e_rabs[i].e_rab_id; - GTP_TEID_TO_ASN1(initial_ctxt_resp_p->e_rabs[i].gtp_teid, &item->value.choice.E_RABSetupItemCtxtSURes.gTP_TEID); - item->value.choice.E_RABSetupItemCtxtSURes.transportLayerAddress.buf = malloc(initial_ctxt_resp_p->e_rabs[i].eNB_addr.length); - memcpy(item->value.choice.E_RABSetupItemCtxtSURes.transportLayerAddress.buf, - initial_ctxt_resp_p->e_rabs[i].eNB_addr.buffer, - initial_ctxt_resp_p->e_rabs[i].eNB_addr.length); - item->value.choice.E_RABSetupItemCtxtSURes.transportLayerAddress.size = initial_ctxt_resp_p->e_rabs[i].eNB_addr.length; - item->value.choice.E_RABSetupItemCtxtSURes.transportLayerAddress.bits_unused = 0; - S1AP_DEBUG("initial_ctxt_resp_p: e_rab ID %ld, enb_addr %d.%d.%d.%d, SIZE %ld \n", - item->value.choice.E_RABSetupItemCtxtSURes.e_RAB_ID, - item->value.choice.E_RABSetupItemCtxtSURes.transportLayerAddress.buf[0], - item->value.choice.E_RABSetupItemCtxtSURes.transportLayerAddress.buf[1], - item->value.choice.E_RABSetupItemCtxtSURes.transportLayerAddress.buf[2], - item->value.choice.E_RABSetupItemCtxtSURes.transportLayerAddress.buf[3], - item->value.choice.E_RABSetupItemCtxtSURes.transportLayerAddress.size); - ASN_SEQUENCE_ADD(&ie->value.choice.E_RABSetupListCtxtSURes.list, item); - } - - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - - /* optional */ - if (initial_ctxt_resp_p->nb_of_e_rabs_failed) { ie = (S1AP_InitialContextSetupResponseIEs_t *)calloc(1, sizeof(S1AP_InitialContextSetupResponseIEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_E_RABFailedToSetupListCtxtSURes; + ie->id = S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID; ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_InitialContextSetupResponseIEs__value_PR_E_RABList; - - for (i = 0; i < initial_ctxt_resp_p->nb_of_e_rabs_failed; i++) { - S1AP_E_RABItemIEs_t *item; - /* mandatory */ - item = (S1AP_E_RABItemIEs_t *)calloc(1, sizeof(S1AP_E_RABItemIEs_t)); - item->id = S1AP_ProtocolIE_ID_id_E_RABItem; - item->criticality = S1AP_Criticality_ignore; - item->value.present = S1AP_E_RABItemIEs__value_PR_E_RABItem; - item->value.choice.E_RABItem.e_RAB_ID = initial_ctxt_resp_p->e_rabs_failed[i].e_rab_id; - item->value.choice.E_RABItem.cause.present = initial_ctxt_resp_p->e_rabs_failed[i].cause; - - switch(item->value.choice.E_RABItem.cause.present) { - case S1AP_Cause_PR_radioNetwork: - item->value.choice.E_RABItem.cause.choice.radioNetwork = initial_ctxt_resp_p->e_rabs_failed[i].cause_value; - break; - - case S1AP_Cause_PR_transport: - item->value.choice.E_RABItem.cause.choice.transport = initial_ctxt_resp_p->e_rabs_failed[i].cause_value; - break; - - case S1AP_Cause_PR_nas: - item->value.choice.E_RABItem.cause.choice.nas = initial_ctxt_resp_p->e_rabs_failed[i].cause_value; - break; - - case S1AP_Cause_PR_protocol: - item->value.choice.E_RABItem.cause.choice.protocol = initial_ctxt_resp_p->e_rabs_failed[i].cause_value; - break; - - case S1AP_Cause_PR_misc: - item->value.choice.E_RABItem.cause.choice.misc = initial_ctxt_resp_p->e_rabs_failed[i].cause_value; - break; - - case S1AP_Cause_PR_NOTHING: - default: - break; - } - - S1AP_DEBUG("initial context setup response: failed e_rab ID %ld\n", item->value.choice.E_RABItem.e_RAB_ID); - ASN_SEQUENCE_ADD(&ie->value.choice.E_RABList.list, item); - } - + ie->value.present = S1AP_InitialContextSetupResponseIEs__value_PR_MME_UE_S1AP_ID; + ie->value.choice.MME_UE_S1AP_ID = ue_context_p->mme_ue_s1ap_id; ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - } - - /* optional */ - if (0) { + /* mandatory */ ie = (S1AP_InitialContextSetupResponseIEs_t *)calloc(1, sizeof(S1AP_InitialContextSetupResponseIEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_CriticalityDiagnostics; + ie->id = S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID; ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_InitialContextSetupResponseIEs__value_PR_CriticalityDiagnostics; - // ie->value.choice.CriticalityDiagnostics =; + ie->value.present = S1AP_InitialContextSetupResponseIEs__value_PR_ENB_UE_S1AP_ID; + ie->value.choice.ENB_UE_S1AP_ID = initial_ctxt_resp_p->eNB_ue_s1ap_id; ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - } - - if (s1ap_eNB_encode_pdu(&pdu, &buffer, &length) < 0) { - S1AP_ERROR("Failed to encode uplink NAS transport\n"); - /* Encode procedure has failed... */ - return -1; - } - - MSC_LOG_TX_MESSAGE( - MSC_S1AP_ENB, - MSC_S1AP_MME, - (const char *)buffer, - length, - MSC_AS_TIME_FMT" InitialContextSetup successfulOutcome eNB_ue_s1ap_id %u mme_ue_s1ap_id %u", - 0,0,//MSC_AS_TIME_ARGS(ctxt_pP), - initial_ctxt_resp_p->eNB_ue_s1ap_id, - ue_context_p->mme_ue_s1ap_id); - /* UE associated signalling -> use the allocated stream */ - s1ap_eNB_itti_send_sctp_data_req(s1ap_eNB_instance_p->instance, - ue_context_p->mme_ref->assoc_id, buffer, - length, ue_context_p->tx_stream); - return 0; -} - -//------------------------------------------------------------------------------ -int s1ap_eNB_ue_capabilities(instance_t instance, - s1ap_ue_cap_info_ind_t *ue_cap_info_ind_p) -//------------------------------------------------------------------------------ -{ - s1ap_eNB_instance_t *s1ap_eNB_instance_p; - struct s1ap_eNB_ue_context_s *ue_context_p; - S1AP_S1AP_PDU_t pdu; - S1AP_UECapabilityInfoIndication_t *out; - S1AP_UECapabilityInfoIndicationIEs_t *ie; - uint8_t *buffer; - uint32_t length; - /* Retrieve the S1AP eNB instance associated with Mod_id */ - s1ap_eNB_instance_p = s1ap_eNB_get_instance(instance); - DevAssert(ue_cap_info_ind_p != NULL); - DevAssert(s1ap_eNB_instance_p != NULL); - - if ((ue_context_p = s1ap_eNB_get_ue_context(s1ap_eNB_instance_p, - ue_cap_info_ind_p->eNB_ue_s1ap_id)) == NULL) { - /* The context for this eNB ue s1ap id doesn't exist in the map of eNB UEs */ - S1AP_WARN("Failed to find ue context associated with eNB ue s1ap id: %u\n", - ue_cap_info_ind_p->eNB_ue_s1ap_id); - return -1; - } - - /* UE capabilities message can occur either during an s1ap connected state - * or during initial attach (for example: NAS authentication). - */ - if (!(ue_context_p->ue_state == S1AP_UE_CONNECTED || - ue_context_p->ue_state == S1AP_UE_WAITING_CSR)) { - S1AP_WARN("You are attempting to send NAS data over non-connected " - "eNB ue s1ap id: %u, current state: %d\n", - ue_cap_info_ind_p->eNB_ue_s1ap_id, ue_context_p->ue_state); - return -1; - } - - /* Prepare the S1AP message to encode */ - memset(&pdu, 0, sizeof(pdu)); - pdu.present = S1AP_S1AP_PDU_PR_initiatingMessage; - pdu.choice.initiatingMessage.procedureCode = S1AP_ProcedureCode_id_UECapabilityInfoIndication; - pdu.choice.initiatingMessage.criticality = S1AP_Criticality_ignore; - pdu.choice.initiatingMessage.value.present = S1AP_InitiatingMessage__value_PR_UECapabilityInfoIndication; - out = &pdu.choice.initiatingMessage.value.choice.UECapabilityInfoIndication; - /* mandatory */ - ie = (S1AP_UECapabilityInfoIndicationIEs_t *)calloc(1, sizeof(S1AP_UECapabilityInfoIndicationIEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID; - ie->criticality = S1AP_Criticality_reject; - ie->value.present = S1AP_UECapabilityInfoIndicationIEs__value_PR_MME_UE_S1AP_ID; - ie->value.choice.MME_UE_S1AP_ID = ue_context_p->mme_ue_s1ap_id; - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - /* mandatory */ - ie = (S1AP_UECapabilityInfoIndicationIEs_t *)calloc(1, sizeof(S1AP_UECapabilityInfoIndicationIEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID; - ie->criticality = S1AP_Criticality_reject; - ie->value.present = S1AP_UECapabilityInfoIndicationIEs__value_PR_ENB_UE_S1AP_ID; - ie->value.choice.ENB_UE_S1AP_ID = ue_cap_info_ind_p->eNB_ue_s1ap_id; - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - /* mandatory */ - ie = (S1AP_UECapabilityInfoIndicationIEs_t *)calloc(1, sizeof(S1AP_UECapabilityInfoIndicationIEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_UERadioCapability; - ie->criticality = S1AP_Criticality_reject; - ie->value.present = S1AP_UECapabilityInfoIndicationIEs__value_PR_UERadioCapability; - ie->value.choice.UERadioCapability.buf = ue_cap_info_ind_p->ue_radio_cap.buffer; - ie->value.choice.UERadioCapability.size = ue_cap_info_ind_p->ue_radio_cap.length; - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - /* optional */ -#if (S1AP_VERSION >= MAKE_VERSION(12, 0, 0)) - - if (0) { - ie = (S1AP_UECapabilityInfoIndicationIEs_t *)calloc(1, sizeof(S1AP_UECapabilityInfoIndicationIEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_UERadioCapabilityForPaging; + /* mandatory */ + ie = (S1AP_InitialContextSetupResponseIEs_t *)calloc(1, sizeof(S1AP_InitialContextSetupResponseIEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_E_RABSetupListCtxtSURes; ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_UECapabilityInfoIndicationIEs__value_PR_UERadioCapabilityForPaging; - // ie->value.choice.UERadioCapabilityForPaging = ; + ie->value.present = S1AP_InitialContextSetupResponseIEs__value_PR_E_RABSetupListCtxtSURes; + + for (i = 0; i < initial_ctxt_resp_p->nb_of_e_rabs; i++) { + S1AP_E_RABSetupItemCtxtSUResIEs_t *item; + /* mandatory */ + item = (S1AP_E_RABSetupItemCtxtSUResIEs_t *)calloc(1, sizeof(S1AP_E_RABSetupItemCtxtSUResIEs_t)); + item->id = S1AP_ProtocolIE_ID_id_E_RABSetupItemCtxtSURes; + item->criticality = S1AP_Criticality_ignore; + item->value.present = S1AP_E_RABSetupItemCtxtSUResIEs__value_PR_E_RABSetupItemCtxtSURes; + item->value.choice.E_RABSetupItemCtxtSURes.e_RAB_ID = initial_ctxt_resp_p->e_rabs[i].e_rab_id; + GTP_TEID_TO_ASN1(initial_ctxt_resp_p->e_rabs[i].gtp_teid, &item->value.choice.E_RABSetupItemCtxtSURes.gTP_TEID); + item->value.choice.E_RABSetupItemCtxtSURes.transportLayerAddress.buf = malloc(initial_ctxt_resp_p->e_rabs[i].eNB_addr.length); + memcpy(item->value.choice.E_RABSetupItemCtxtSURes.transportLayerAddress.buf, + initial_ctxt_resp_p->e_rabs[i].eNB_addr.buffer, + initial_ctxt_resp_p->e_rabs[i].eNB_addr.length); + item->value.choice.E_RABSetupItemCtxtSURes.transportLayerAddress.size = initial_ctxt_resp_p->e_rabs[i].eNB_addr.length; + item->value.choice.E_RABSetupItemCtxtSURes.transportLayerAddress.bits_unused = 0; + S1AP_DEBUG("initial_ctxt_resp_p: e_rab ID %ld, enb_addr %d.%d.%d.%d, SIZE %ld \n", + item->value.choice.E_RABSetupItemCtxtSURes.e_RAB_ID, + item->value.choice.E_RABSetupItemCtxtSURes.transportLayerAddress.buf[0], + item->value.choice.E_RABSetupItemCtxtSURes.transportLayerAddress.buf[1], + item->value.choice.E_RABSetupItemCtxtSURes.transportLayerAddress.buf[2], + item->value.choice.E_RABSetupItemCtxtSURes.transportLayerAddress.buf[3], + item->value.choice.E_RABSetupItemCtxtSURes.transportLayerAddress.size); + ASN_SEQUENCE_ADD(&ie->value.choice.E_RABSetupListCtxtSURes.list, item); + } + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - } -#endif /* #if (S1AP_VERSION >= MAKE_VERSION(14, 0, 0)) */ + /* optional */ + if (initial_ctxt_resp_p->nb_of_e_rabs_failed) { + ie = (S1AP_InitialContextSetupResponseIEs_t *)calloc(1, sizeof(S1AP_InitialContextSetupResponseIEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_E_RABFailedToSetupListCtxtSURes; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_InitialContextSetupResponseIEs__value_PR_E_RABList; + + for (i = 0; i < initial_ctxt_resp_p->nb_of_e_rabs_failed; i++) { + S1AP_E_RABItemIEs_t *item; + /* mandatory */ + item = (S1AP_E_RABItemIEs_t *)calloc(1, sizeof(S1AP_E_RABItemIEs_t)); + item->id = S1AP_ProtocolIE_ID_id_E_RABItem; + item->criticality = S1AP_Criticality_ignore; + item->value.present = S1AP_E_RABItemIEs__value_PR_E_RABItem; + item->value.choice.E_RABItem.e_RAB_ID = initial_ctxt_resp_p->e_rabs_failed[i].e_rab_id; + item->value.choice.E_RABItem.cause.present = initial_ctxt_resp_p->e_rabs_failed[i].cause; + + switch(item->value.choice.E_RABItem.cause.present) { + case S1AP_Cause_PR_radioNetwork: + item->value.choice.E_RABItem.cause.choice.radioNetwork = initial_ctxt_resp_p->e_rabs_failed[i].cause_value; + break; + + case S1AP_Cause_PR_transport: + item->value.choice.E_RABItem.cause.choice.transport = initial_ctxt_resp_p->e_rabs_failed[i].cause_value; + break; + + case S1AP_Cause_PR_nas: + item->value.choice.E_RABItem.cause.choice.nas = initial_ctxt_resp_p->e_rabs_failed[i].cause_value; + break; + + case S1AP_Cause_PR_protocol: + item->value.choice.E_RABItem.cause.choice.protocol = initial_ctxt_resp_p->e_rabs_failed[i].cause_value; + break; + + case S1AP_Cause_PR_misc: + item->value.choice.E_RABItem.cause.choice.misc = initial_ctxt_resp_p->e_rabs_failed[i].cause_value; + break; + + case S1AP_Cause_PR_NOTHING: + default: + break; + } + + S1AP_DEBUG("initial context setup response: failed e_rab ID %ld\n", item->value.choice.E_RABItem.e_RAB_ID); + ASN_SEQUENCE_ADD(&ie->value.choice.E_RABList.list, item); + } + + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + } - if (s1ap_eNB_encode_pdu(&pdu, &buffer, &length) < 0) { - /* Encode procedure has failed... */ - S1AP_ERROR("Failed to encode UE capabilities indication\n"); - return -1; - } + /* optional */ + if (0) { + ie = (S1AP_InitialContextSetupResponseIEs_t *)calloc(1, sizeof(S1AP_InitialContextSetupResponseIEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_CriticalityDiagnostics; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_InitialContextSetupResponseIEs__value_PR_CriticalityDiagnostics; + // ie->value.choice.CriticalityDiagnostics =; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + } - MSC_LOG_TX_MESSAGE( - MSC_S1AP_ENB, - MSC_S1AP_MME, - (const char *)buffer, - length, - MSC_AS_TIME_FMT" UECapabilityInfoIndication initiatingMessage eNB_ue_s1ap_id %u mme_ue_s1ap_id %u", - 0,0,//MSC_AS_TIME_ARGS(ctxt_pP), - ue_cap_info_ind_p->eNB_ue_s1ap_id, - ue_context_p->mme_ue_s1ap_id); - /* UE associated signalling -> use the allocated stream */ - s1ap_eNB_itti_send_sctp_data_req(s1ap_eNB_instance_p->instance, - ue_context_p->mme_ref->assoc_id, buffer, - length, ue_context_p->tx_stream); - return 0; + if (s1ap_eNB_encode_pdu(&pdu, &buffer, &length) < 0) { + S1AP_ERROR("Failed to encode uplink NAS transport\n"); + /* Encode procedure has failed... */ + return -1; + } + + MSC_LOG_TX_MESSAGE( + MSC_S1AP_ENB, + MSC_S1AP_MME, + (const char *)buffer, + length, + MSC_AS_TIME_FMT" InitialContextSetup successfulOutcome eNB_ue_s1ap_id %u mme_ue_s1ap_id %u", + 0,0,//MSC_AS_TIME_ARGS(ctxt_pP), + initial_ctxt_resp_p->eNB_ue_s1ap_id, + ue_context_p->mme_ue_s1ap_id); + /* UE associated signalling -> use the allocated stream */ + s1ap_eNB_itti_send_sctp_data_req(s1ap_eNB_instance_p->instance, + ue_context_p->mme_ref->assoc_id, buffer, + length, ue_context_p->tx_stream); + return 0; } //------------------------------------------------------------------------------ -int s1ap_eNB_e_rab_setup_resp(instance_t instance, - s1ap_e_rab_setup_resp_t *e_rab_setup_resp_p) +int s1ap_eNB_ue_capabilities(instance_t instance, + s1ap_ue_cap_info_ind_t *ue_cap_info_ind_p) //------------------------------------------------------------------------------ { - s1ap_eNB_instance_t *s1ap_eNB_instance_p = NULL; - struct s1ap_eNB_ue_context_s *ue_context_p = NULL; - S1AP_S1AP_PDU_t pdu; - S1AP_E_RABSetupResponse_t *out; - S1AP_E_RABSetupResponseIEs_t *ie; - uint8_t *buffer = NULL; - uint32_t length; - int i; - /* Retrieve the S1AP eNB instance associated with Mod_id */ - s1ap_eNB_instance_p = s1ap_eNB_get_instance(instance); - DevAssert(e_rab_setup_resp_p != NULL); - DevAssert(s1ap_eNB_instance_p != NULL); - - if ((ue_context_p = s1ap_eNB_get_ue_context(s1ap_eNB_instance_p, - e_rab_setup_resp_p->eNB_ue_s1ap_id)) == NULL) { - /* The context for this eNB ue s1ap id doesn't exist in the map of eNB UEs */ - S1AP_WARN("Failed to find ue context associated with eNB ue s1ap id: 0x%06x\n", - e_rab_setup_resp_p->eNB_ue_s1ap_id); - return -1; - } - - /* Uplink NAS transport can occur either during an s1ap connected state - * or during initial attach (for example: NAS authentication). - */ - if (!(ue_context_p->ue_state == S1AP_UE_CONNECTED || - ue_context_p->ue_state == S1AP_UE_WAITING_CSR)) { - S1AP_WARN("You are attempting to send NAS data over non-connected " - "eNB ue s1ap id: %06x, current state: %d\n", - e_rab_setup_resp_p->eNB_ue_s1ap_id, ue_context_p->ue_state); - return -1; - } - - /* Prepare the S1AP message to encode */ - memset(&pdu, 0, sizeof(pdu)); - pdu.present = S1AP_S1AP_PDU_PR_successfulOutcome; - pdu.choice.successfulOutcome.procedureCode = S1AP_ProcedureCode_id_E_RABModify; - pdu.choice.successfulOutcome.criticality = S1AP_Criticality_reject; - pdu.choice.successfulOutcome.value.present = S1AP_SuccessfulOutcome__value_PR_E_RABSetupResponse; - out = &pdu.choice.successfulOutcome.value.choice.E_RABSetupResponse; - /* mandatory */ - ie = (S1AP_E_RABSetupResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABSetupResponseIEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_E_RABSetupResponseIEs__value_PR_MME_UE_S1AP_ID; - ie->value.choice.MME_UE_S1AP_ID = ue_context_p->mme_ue_s1ap_id; - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - /* mandatory */ - ie = (S1AP_E_RABSetupResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABSetupResponseIEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_E_RABSetupResponseIEs__value_PR_ENB_UE_S1AP_ID; - ie->value.choice.ENB_UE_S1AP_ID = e_rab_setup_resp_p->eNB_ue_s1ap_id; - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - - /* optional */ - if (e_rab_setup_resp_p->nb_of_e_rabs > 0) { - ie = (S1AP_E_RABSetupResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABSetupResponseIEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_E_RABSetupListBearerSURes; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_E_RABSetupResponseIEs__value_PR_E_RABSetupListBearerSURes; - - for (i = 0; i < e_rab_setup_resp_p->nb_of_e_rabs; i++) { - S1AP_E_RABSetupItemBearerSUResIEs_t *item; - /* mandatory */ - item = (S1AP_E_RABSetupItemBearerSUResIEs_t *)calloc(1, sizeof(S1AP_E_RABSetupItemBearerSUResIEs_t)); - item->id = S1AP_ProtocolIE_ID_id_E_RABSetupItemBearerSURes; - item->criticality = S1AP_Criticality_ignore; - item->value.present = S1AP_E_RABSetupItemBearerSUResIEs__value_PR_E_RABSetupItemBearerSURes; - item->value.choice.E_RABSetupItemBearerSURes.e_RAB_ID = e_rab_setup_resp_p->e_rabs[i].e_rab_id; - GTP_TEID_TO_ASN1(e_rab_setup_resp_p->e_rabs[i].gtp_teid, &item->value.choice.E_RABSetupItemBearerSURes.gTP_TEID); - item->value.choice.E_RABSetupItemBearerSURes.transportLayerAddress.buf = malloc(e_rab_setup_resp_p->e_rabs[i].eNB_addr.length); - memcpy(item->value.choice.E_RABSetupItemBearerSURes.transportLayerAddress.buf, - e_rab_setup_resp_p->e_rabs[i].eNB_addr.buffer, - e_rab_setup_resp_p->e_rabs[i].eNB_addr.length); - item->value.choice.E_RABSetupItemBearerSURes.transportLayerAddress.size = e_rab_setup_resp_p->e_rabs[i].eNB_addr.length; - item->value.choice.E_RABSetupItemBearerSURes.transportLayerAddress.bits_unused = 0; - S1AP_DEBUG("e_rab_setup_resp: e_rab ID %ld, teid %u, enb_addr %d.%d.%d.%d, SIZE %ld\n", - item->value.choice.E_RABSetupItemBearerSURes.e_RAB_ID, - e_rab_setup_resp_p->e_rabs[i].gtp_teid, - item->value.choice.E_RABSetupItemBearerSURes.transportLayerAddress.buf[0], - item->value.choice.E_RABSetupItemBearerSURes.transportLayerAddress.buf[1], - item->value.choice.E_RABSetupItemBearerSURes.transportLayerAddress.buf[2], - item->value.choice.E_RABSetupItemBearerSURes.transportLayerAddress.buf[3], - item->value.choice.E_RABSetupItemBearerSURes.transportLayerAddress.size); - ASN_SEQUENCE_ADD(&ie->value.choice.E_RABSetupListBearerSURes.list, item); + s1ap_eNB_instance_t *s1ap_eNB_instance_p; + struct s1ap_eNB_ue_context_s *ue_context_p; + S1AP_S1AP_PDU_t pdu; + S1AP_UECapabilityInfoIndication_t *out; + S1AP_UECapabilityInfoIndicationIEs_t *ie; + uint8_t *buffer; + uint32_t length; + /* Retrieve the S1AP eNB instance associated with Mod_id */ + s1ap_eNB_instance_p = s1ap_eNB_get_instance(instance); + DevAssert(ue_cap_info_ind_p != NULL); + DevAssert(s1ap_eNB_instance_p != NULL); + + if ((ue_context_p = s1ap_eNB_get_ue_context(s1ap_eNB_instance_p, + ue_cap_info_ind_p->eNB_ue_s1ap_id)) == NULL) { + /* The context for this eNB ue s1ap id doesn't exist in the map of eNB UEs */ + S1AP_WARN("Failed to find ue context associated with eNB ue s1ap id: %u\n", + ue_cap_info_ind_p->eNB_ue_s1ap_id); + return -1; } - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - } - - /* optional */ - if (e_rab_setup_resp_p->nb_of_e_rabs_failed > 0) { - ie = (S1AP_E_RABSetupResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABSetupResponseIEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_E_RABFailedToSetupListBearerSURes; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_E_RABSetupResponseIEs__value_PR_E_RABList; - - for (i = 0; i < e_rab_setup_resp_p->nb_of_e_rabs_failed; i++) { - S1AP_E_RABItemIEs_t *item; - item = (S1AP_E_RABItemIEs_t *)calloc(1, sizeof(S1AP_E_RABItemIEs_t)); - item->id = S1AP_ProtocolIE_ID_id_E_RABItem; - item->criticality = S1AP_Criticality_ignore; - item->value.present = S1AP_E_RABItemIEs__value_PR_E_RABItem; - item->value.choice.E_RABItem.e_RAB_ID = e_rab_setup_resp_p->e_rabs_failed[i].e_rab_id; - item->value.choice.E_RABItem.cause.present = e_rab_setup_resp_p->e_rabs_failed[i].cause; + /* UE capabilities message can occur either during an s1ap connected state + * or during initial attach (for example: NAS authentication). + */ + if (!(ue_context_p->ue_state == S1AP_UE_CONNECTED || + ue_context_p->ue_state == S1AP_UE_WAITING_CSR)) { + S1AP_WARN("You are attempting to send NAS data over non-connected " + "eNB ue s1ap id: %u, current state: %d\n", + ue_cap_info_ind_p->eNB_ue_s1ap_id, ue_context_p->ue_state); + return -1; + } - switch(item->value.choice.E_RABItem.cause.present) { - case S1AP_Cause_PR_radioNetwork: - item->value.choice.E_RABItem.cause.choice.radioNetwork = e_rab_setup_resp_p->e_rabs_failed[i].cause_value; - break; + /* Prepare the S1AP message to encode */ + memset(&pdu, 0, sizeof(pdu)); + pdu.present = S1AP_S1AP_PDU_PR_initiatingMessage; + pdu.choice.initiatingMessage.procedureCode = S1AP_ProcedureCode_id_UECapabilityInfoIndication; + pdu.choice.initiatingMessage.criticality = S1AP_Criticality_ignore; + pdu.choice.initiatingMessage.value.present = S1AP_InitiatingMessage__value_PR_UECapabilityInfoIndication; + out = &pdu.choice.initiatingMessage.value.choice.UECapabilityInfoIndication; + /* mandatory */ + ie = (S1AP_UECapabilityInfoIndicationIEs_t *)calloc(1, sizeof(S1AP_UECapabilityInfoIndicationIEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID; + ie->criticality = S1AP_Criticality_reject; + ie->value.present = S1AP_UECapabilityInfoIndicationIEs__value_PR_MME_UE_S1AP_ID; + ie->value.choice.MME_UE_S1AP_ID = ue_context_p->mme_ue_s1ap_id; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + /* mandatory */ + ie = (S1AP_UECapabilityInfoIndicationIEs_t *)calloc(1, sizeof(S1AP_UECapabilityInfoIndicationIEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID; + ie->criticality = S1AP_Criticality_reject; + ie->value.present = S1AP_UECapabilityInfoIndicationIEs__value_PR_ENB_UE_S1AP_ID; + ie->value.choice.ENB_UE_S1AP_ID = ue_cap_info_ind_p->eNB_ue_s1ap_id; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + /* mandatory */ + ie = (S1AP_UECapabilityInfoIndicationIEs_t *)calloc(1, sizeof(S1AP_UECapabilityInfoIndicationIEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_UERadioCapability; + ie->criticality = S1AP_Criticality_reject; + ie->value.present = S1AP_UECapabilityInfoIndicationIEs__value_PR_UERadioCapability; + ie->value.choice.UERadioCapability.buf = ue_cap_info_ind_p->ue_radio_cap.buffer; + ie->value.choice.UERadioCapability.size = ue_cap_info_ind_p->ue_radio_cap.length; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + /* optional */ +#if (S1AP_VERSION >= MAKE_VERSION(12, 0, 0)) - case S1AP_Cause_PR_transport: - item->value.choice.E_RABItem.cause.choice.transport = e_rab_setup_resp_p->e_rabs_failed[i].cause_value; - break; + if (0) { + ie = (S1AP_UECapabilityInfoIndicationIEs_t *)calloc(1, sizeof(S1AP_UECapabilityInfoIndicationIEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_UERadioCapabilityForPaging; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_UECapabilityInfoIndicationIEs__value_PR_UERadioCapabilityForPaging; + // ie->value.choice.UERadioCapabilityForPaging = ; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + } - case S1AP_Cause_PR_nas: - item->value.choice.E_RABItem.cause.choice.nas = e_rab_setup_resp_p->e_rabs_failed[i].cause_value; - break; +#endif /* #if (S1AP_VERSION >= MAKE_VERSION(14, 0, 0)) */ - case S1AP_Cause_PR_protocol: - item->value.choice.E_RABItem.cause.choice.protocol = e_rab_setup_resp_p->e_rabs_failed[i].cause_value; - break; + if (s1ap_eNB_encode_pdu(&pdu, &buffer, &length) < 0) { + /* Encode procedure has failed... */ + S1AP_ERROR("Failed to encode UE capabilities indication\n"); + return -1; + } - case S1AP_Cause_PR_misc: - item->value.choice.E_RABItem.cause.choice.misc = e_rab_setup_resp_p->e_rabs_failed[i].cause_value; - break; + MSC_LOG_TX_MESSAGE( + MSC_S1AP_ENB, + MSC_S1AP_MME, + (const char *)buffer, + length, + MSC_AS_TIME_FMT" UECapabilityInfoIndication initiatingMessage eNB_ue_s1ap_id %u mme_ue_s1ap_id %u", + 0,0,//MSC_AS_TIME_ARGS(ctxt_pP), + ue_cap_info_ind_p->eNB_ue_s1ap_id, + ue_context_p->mme_ue_s1ap_id); + /* UE associated signalling -> use the allocated stream */ + s1ap_eNB_itti_send_sctp_data_req(s1ap_eNB_instance_p->instance, + ue_context_p->mme_ref->assoc_id, buffer, + length, ue_context_p->tx_stream); + return 0; +} - case S1AP_Cause_PR_NOTHING: - default: - break; - } +//------------------------------------------------------------------------------ +int s1ap_eNB_e_rab_setup_resp(instance_t instance, + s1ap_e_rab_setup_resp_t *e_rab_setup_resp_p) +//------------------------------------------------------------------------------ +{ + s1ap_eNB_instance_t *s1ap_eNB_instance_p = NULL; + struct s1ap_eNB_ue_context_s *ue_context_p = NULL; + S1AP_S1AP_PDU_t pdu; + S1AP_E_RABSetupResponse_t *out; + S1AP_E_RABSetupResponseIEs_t *ie; + uint8_t *buffer = NULL; + uint32_t length; + int i; + /* Retrieve the S1AP eNB instance associated with Mod_id */ + s1ap_eNB_instance_p = s1ap_eNB_get_instance(instance); + DevAssert(e_rab_setup_resp_p != NULL); + DevAssert(s1ap_eNB_instance_p != NULL); + + if ((ue_context_p = s1ap_eNB_get_ue_context(s1ap_eNB_instance_p, + e_rab_setup_resp_p->eNB_ue_s1ap_id)) == NULL) { + /* The context for this eNB ue s1ap id doesn't exist in the map of eNB UEs */ + S1AP_WARN("Failed to find ue context associated with eNB ue s1ap id: 0x%06x\n", + e_rab_setup_resp_p->eNB_ue_s1ap_id); + return -1; + } - S1AP_DEBUG("e_rab_modify_resp: failed e_rab ID %ld\n", item->value.choice.E_RABItem.e_RAB_ID); - ASN_SEQUENCE_ADD(&ie->value.choice.E_RABList.list, item); + /* Uplink NAS transport can occur either during an s1ap connected state + * or during initial attach (for example: NAS authentication). + */ + if (!(ue_context_p->ue_state == S1AP_UE_CONNECTED || + ue_context_p->ue_state == S1AP_UE_WAITING_CSR)) { + S1AP_WARN("You are attempting to send NAS data over non-connected " + "eNB ue s1ap id: %06x, current state: %d\n", + e_rab_setup_resp_p->eNB_ue_s1ap_id, ue_context_p->ue_state); + return -1; } + /* Prepare the S1AP message to encode */ + memset(&pdu, 0, sizeof(pdu)); + pdu.present = S1AP_S1AP_PDU_PR_successfulOutcome; + pdu.choice.successfulOutcome.procedureCode = S1AP_ProcedureCode_id_E_RABModify; + pdu.choice.successfulOutcome.criticality = S1AP_Criticality_reject; + pdu.choice.successfulOutcome.value.present = S1AP_SuccessfulOutcome__value_PR_E_RABSetupResponse; + out = &pdu.choice.successfulOutcome.value.choice.E_RABSetupResponse; + /* mandatory */ + ie = (S1AP_E_RABSetupResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABSetupResponseIEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_E_RABSetupResponseIEs__value_PR_MME_UE_S1AP_ID; + ie->value.choice.MME_UE_S1AP_ID = ue_context_p->mme_ue_s1ap_id; ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - } - - /* optional */ - if (0) { + /* mandatory */ ie = (S1AP_E_RABSetupResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABSetupResponseIEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_CriticalityDiagnostics; + ie->id = S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID; ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_E_RABSetupResponseIEs__value_PR_CriticalityDiagnostics; - // ie->value.choice.CriticalityDiagnostics = ; + ie->value.present = S1AP_E_RABSetupResponseIEs__value_PR_ENB_UE_S1AP_ID; + ie->value.choice.ENB_UE_S1AP_ID = e_rab_setup_resp_p->eNB_ue_s1ap_id; ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - } - /* S1AP_E_RABSetupListBearerSURes_t e_RABSetupListBearerSURes; - memset(&e_RABSetupListBearerSURes, 0, sizeof(S1AP_E_RABSetupListBearerSURes_t)); - if (s1ap_encode_s1ap_e_rabsetuplistbearersures(&e_RABSetupListBearerSURes, &initial_ies_p->e_RABSetupListBearerSURes.s1ap_E_RABSetupItemBearerSURes) < 0 ) - return -1; - ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_S1AP_E_RABSetupListBearerSURes, &e_RABSetupListBearerSURes); - */ - fprintf(stderr, "start encode\n"); + /* optional */ + if (e_rab_setup_resp_p->nb_of_e_rabs > 0) { + ie = (S1AP_E_RABSetupResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABSetupResponseIEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_E_RABSetupListBearerSURes; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_E_RABSetupResponseIEs__value_PR_E_RABSetupListBearerSURes; + + for (i = 0; i < e_rab_setup_resp_p->nb_of_e_rabs; i++) { + S1AP_E_RABSetupItemBearerSUResIEs_t *item; + /* mandatory */ + item = (S1AP_E_RABSetupItemBearerSUResIEs_t *)calloc(1, sizeof(S1AP_E_RABSetupItemBearerSUResIEs_t)); + item->id = S1AP_ProtocolIE_ID_id_E_RABSetupItemBearerSURes; + item->criticality = S1AP_Criticality_ignore; + item->value.present = S1AP_E_RABSetupItemBearerSUResIEs__value_PR_E_RABSetupItemBearerSURes; + item->value.choice.E_RABSetupItemBearerSURes.e_RAB_ID = e_rab_setup_resp_p->e_rabs[i].e_rab_id; + GTP_TEID_TO_ASN1(e_rab_setup_resp_p->e_rabs[i].gtp_teid, &item->value.choice.E_RABSetupItemBearerSURes.gTP_TEID); + item->value.choice.E_RABSetupItemBearerSURes.transportLayerAddress.buf = malloc(e_rab_setup_resp_p->e_rabs[i].eNB_addr.length); + memcpy(item->value.choice.E_RABSetupItemBearerSURes.transportLayerAddress.buf, + e_rab_setup_resp_p->e_rabs[i].eNB_addr.buffer, + e_rab_setup_resp_p->e_rabs[i].eNB_addr.length); + item->value.choice.E_RABSetupItemBearerSURes.transportLayerAddress.size = e_rab_setup_resp_p->e_rabs[i].eNB_addr.length; + item->value.choice.E_RABSetupItemBearerSURes.transportLayerAddress.bits_unused = 0; + S1AP_DEBUG("e_rab_setup_resp: e_rab ID %ld, teid %u, enb_addr %d.%d.%d.%d, SIZE %ld\n", + item->value.choice.E_RABSetupItemBearerSURes.e_RAB_ID, + e_rab_setup_resp_p->e_rabs[i].gtp_teid, + item->value.choice.E_RABSetupItemBearerSURes.transportLayerAddress.buf[0], + item->value.choice.E_RABSetupItemBearerSURes.transportLayerAddress.buf[1], + item->value.choice.E_RABSetupItemBearerSURes.transportLayerAddress.buf[2], + item->value.choice.E_RABSetupItemBearerSURes.transportLayerAddress.buf[3], + item->value.choice.E_RABSetupItemBearerSURes.transportLayerAddress.size); + ASN_SEQUENCE_ADD(&ie->value.choice.E_RABSetupListBearerSURes.list, item); + } + + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + } - if (s1ap_eNB_encode_pdu(&pdu, &buffer, &length) < 0) { - S1AP_ERROR("Failed to encode uplink transport\n"); - /* Encode procedure has failed... */ - return -1; - } + /* optional */ + if (e_rab_setup_resp_p->nb_of_e_rabs_failed > 0) { + ie = (S1AP_E_RABSetupResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABSetupResponseIEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_E_RABFailedToSetupListBearerSURes; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_E_RABSetupResponseIEs__value_PR_E_RABList; + + for (i = 0; i < e_rab_setup_resp_p->nb_of_e_rabs_failed; i++) { + S1AP_E_RABItemIEs_t *item; + item = (S1AP_E_RABItemIEs_t *)calloc(1, sizeof(S1AP_E_RABItemIEs_t)); + item->id = S1AP_ProtocolIE_ID_id_E_RABItem; + item->criticality = S1AP_Criticality_ignore; + item->value.present = S1AP_E_RABItemIEs__value_PR_E_RABItem; + item->value.choice.E_RABItem.e_RAB_ID = e_rab_setup_resp_p->e_rabs_failed[i].e_rab_id; + item->value.choice.E_RABItem.cause.present = e_rab_setup_resp_p->e_rabs_failed[i].cause; + + switch(item->value.choice.E_RABItem.cause.present) { + case S1AP_Cause_PR_radioNetwork: + item->value.choice.E_RABItem.cause.choice.radioNetwork = e_rab_setup_resp_p->e_rabs_failed[i].cause_value; + break; + + case S1AP_Cause_PR_transport: + item->value.choice.E_RABItem.cause.choice.transport = e_rab_setup_resp_p->e_rabs_failed[i].cause_value; + break; + + case S1AP_Cause_PR_nas: + item->value.choice.E_RABItem.cause.choice.nas = e_rab_setup_resp_p->e_rabs_failed[i].cause_value; + break; + + case S1AP_Cause_PR_protocol: + item->value.choice.E_RABItem.cause.choice.protocol = e_rab_setup_resp_p->e_rabs_failed[i].cause_value; + break; + + case S1AP_Cause_PR_misc: + item->value.choice.E_RABItem.cause.choice.misc = e_rab_setup_resp_p->e_rabs_failed[i].cause_value; + break; + + case S1AP_Cause_PR_NOTHING: + default: + break; + } + + S1AP_DEBUG("e_rab_modify_resp: failed e_rab ID %ld\n", item->value.choice.E_RABItem.e_RAB_ID); + ASN_SEQUENCE_ADD(&ie->value.choice.E_RABList.list, item); + } + + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + } - MSC_LOG_TX_MESSAGE( - MSC_S1AP_ENB, - MSC_S1AP_MME, - (const char *)buffer, - length, - MSC_AS_TIME_FMT" E_RAN Setup successfulOutcome eNB_ue_s1ap_id %u mme_ue_s1ap_id %u", - 0,0,//MSC_AS_TIME_ARGS(ctxt_pP), - e_rab_setup_resp_p->eNB_ue_s1ap_id, - ue_context_p->mme_ue_s1ap_id); - /* UE associated signalling -> use the allocated stream */ - s1ap_eNB_itti_send_sctp_data_req(s1ap_eNB_instance_p->instance, - ue_context_p->mme_ref->assoc_id, buffer, - length, ue_context_p->tx_stream); - return 0; + /* optional */ + if (0) { + ie = (S1AP_E_RABSetupResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABSetupResponseIEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_CriticalityDiagnostics; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_E_RABSetupResponseIEs__value_PR_CriticalityDiagnostics; + // ie->value.choice.CriticalityDiagnostics = ; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + } + + /* S1AP_E_RABSetupListBearerSURes_t e_RABSetupListBearerSURes; + memset(&e_RABSetupListBearerSURes, 0, sizeof(S1AP_E_RABSetupListBearerSURes_t)); + if (s1ap_encode_s1ap_e_rabsetuplistbearersures(&e_RABSetupListBearerSURes, &initial_ies_p->e_RABSetupListBearerSURes.s1ap_E_RABSetupItemBearerSURes) < 0 ) + return -1; + ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_S1AP_E_RABSetupListBearerSURes, &e_RABSetupListBearerSURes); + */ + fprintf(stderr, "start encode\n"); + + if (s1ap_eNB_encode_pdu(&pdu, &buffer, &length) < 0) { + S1AP_ERROR("Failed to encode uplink transport\n"); + /* Encode procedure has failed... */ + return -1; + } + + MSC_LOG_TX_MESSAGE( + MSC_S1AP_ENB, + MSC_S1AP_MME, + (const char *)buffer, + length, + MSC_AS_TIME_FMT" E_RAN Setup successfulOutcome eNB_ue_s1ap_id %u mme_ue_s1ap_id %u", + 0,0,//MSC_AS_TIME_ARGS(ctxt_pP), + e_rab_setup_resp_p->eNB_ue_s1ap_id, + ue_context_p->mme_ue_s1ap_id); + /* UE associated signalling -> use the allocated stream */ + s1ap_eNB_itti_send_sctp_data_req(s1ap_eNB_instance_p->instance, + ue_context_p->mme_ref->assoc_id, buffer, + length, ue_context_p->tx_stream); + return 0; } //------------------------------------------------------------------------------ @@ -1271,325 +1283,562 @@ int s1ap_eNB_e_rab_modify_resp(instance_t instance, s1ap_e_rab_modify_resp_t *e_rab_modify_resp_p) //------------------------------------------------------------------------------ { - s1ap_eNB_instance_t *s1ap_eNB_instance_p = NULL; - struct s1ap_eNB_ue_context_s *ue_context_p = NULL; - S1AP_S1AP_PDU_t pdu; - S1AP_E_RABModifyResponse_t *out; - S1AP_E_RABModifyResponseIEs_t *ie; - uint8_t *buffer = NULL; - uint32_t length; - int i; - /* Retrieve the S1AP eNB instance associated with Mod_id */ - s1ap_eNB_instance_p = s1ap_eNB_get_instance(instance); - DevAssert(e_rab_modify_resp_p != NULL); - DevAssert(s1ap_eNB_instance_p != NULL); - - if ((ue_context_p = s1ap_eNB_get_ue_context(s1ap_eNB_instance_p, - e_rab_modify_resp_p->eNB_ue_s1ap_id)) == NULL) { - /* The context for this eNB ue s1ap id doesn't exist in the map of eNB UEs */ - S1AP_WARN("Failed to find ue context associated with eNB ue s1ap id: 0x%06x\n", - e_rab_modify_resp_p->eNB_ue_s1ap_id); - return -1; - } - - /* Uplink NAS transport can occur either during an s1ap connected state - * or during initial attach (for example: NAS authentication). - */ - if (!(ue_context_p->ue_state == S1AP_UE_CONNECTED || - ue_context_p->ue_state == S1AP_UE_WAITING_CSR)) { - S1AP_WARN("You are attempting to send NAS data over non-connected " - "eNB ue s1ap id: %06x, current state: %d\n", - e_rab_modify_resp_p->eNB_ue_s1ap_id, ue_context_p->ue_state); - return -1; - } + s1ap_eNB_instance_t *s1ap_eNB_instance_p = NULL; + struct s1ap_eNB_ue_context_s *ue_context_p = NULL; + S1AP_S1AP_PDU_t pdu; + S1AP_E_RABModifyResponse_t *out; + S1AP_E_RABModifyResponseIEs_t *ie; + uint8_t *buffer = NULL; + uint32_t length; + int i; + /* Retrieve the S1AP eNB instance associated with Mod_id */ + s1ap_eNB_instance_p = s1ap_eNB_get_instance(instance); + DevAssert(e_rab_modify_resp_p != NULL); + DevAssert(s1ap_eNB_instance_p != NULL); + + if ((ue_context_p = s1ap_eNB_get_ue_context(s1ap_eNB_instance_p, + e_rab_modify_resp_p->eNB_ue_s1ap_id)) == NULL) { + /* The context for this eNB ue s1ap id doesn't exist in the map of eNB UEs */ + S1AP_WARN("Failed to find ue context associated with eNB ue s1ap id: 0x%06x\n", + e_rab_modify_resp_p->eNB_ue_s1ap_id); + return -1; + } - /* Prepare the S1AP message to encode */ - memset(&pdu, 0, sizeof(pdu)); - pdu.present = S1AP_S1AP_PDU_PR_successfulOutcome; - pdu.choice.successfulOutcome.procedureCode = S1AP_ProcedureCode_id_E_RABModify; - pdu.choice.successfulOutcome.criticality = S1AP_Criticality_reject; - pdu.choice.successfulOutcome.value.present = S1AP_SuccessfulOutcome__value_PR_E_RABModifyResponse; - out = &pdu.choice.successfulOutcome.value.choice.E_RABModifyResponse; - /* mandatory */ - ie = (S1AP_E_RABModifyResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABModifyResponseIEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_E_RABModifyResponseIEs__value_PR_MME_UE_S1AP_ID; - ie->value.choice.MME_UE_S1AP_ID = ue_context_p->mme_ue_s1ap_id; - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - /* mandatory */ - ie = (S1AP_E_RABModifyResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABModifyResponseIEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_E_RABModifyResponseIEs__value_PR_ENB_UE_S1AP_ID; - ie->value.choice.ENB_UE_S1AP_ID = e_rab_modify_resp_p->eNB_ue_s1ap_id; - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + /* Uplink NAS transport can occur either during an s1ap connected state + * or during initial attach (for example: NAS authentication). + */ + if (!(ue_context_p->ue_state == S1AP_UE_CONNECTED || + ue_context_p->ue_state == S1AP_UE_WAITING_CSR)) { + S1AP_WARN("You are attempting to send NAS data over non-connected " + "eNB ue s1ap id: %06x, current state: %d\n", + e_rab_modify_resp_p->eNB_ue_s1ap_id, ue_context_p->ue_state); + return -1; + } - /* optional */ - if (e_rab_modify_resp_p->nb_of_e_rabs > 0) { + /* Prepare the S1AP message to encode */ + memset(&pdu, 0, sizeof(pdu)); + pdu.present = S1AP_S1AP_PDU_PR_successfulOutcome; + pdu.choice.successfulOutcome.procedureCode = S1AP_ProcedureCode_id_E_RABModify; + pdu.choice.successfulOutcome.criticality = S1AP_Criticality_reject; + pdu.choice.successfulOutcome.value.present = S1AP_SuccessfulOutcome__value_PR_E_RABModifyResponse; + out = &pdu.choice.successfulOutcome.value.choice.E_RABModifyResponse; + /* mandatory */ ie = (S1AP_E_RABModifyResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABModifyResponseIEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_E_RABModifyListBearerModRes; + ie->id = S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID; ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_E_RABModifyResponseIEs__value_PR_E_RABModifyListBearerModRes; - - for (i = 0; i < e_rab_modify_resp_p->nb_of_e_rabs; i++) { - S1AP_E_RABModifyItemBearerModResIEs_t *item; - item = (S1AP_E_RABModifyItemBearerModResIEs_t *)calloc(1, sizeof(S1AP_E_RABModifyItemBearerModResIEs_t)); - item->id = S1AP_ProtocolIE_ID_id_E_RABModifyItemBearerModRes; - item->criticality = S1AP_Criticality_ignore; - item->value.present = S1AP_E_RABModifyItemBearerModResIEs__value_PR_E_RABModifyItemBearerModRes; - item->value.choice.E_RABModifyItemBearerModRes.e_RAB_ID = e_rab_modify_resp_p->e_rabs[i].e_rab_id; - S1AP_DEBUG("e_rab_modify_resp: modified e_rab ID %ld\n", item->value.choice.E_RABModifyItemBearerModRes.e_RAB_ID); - ASN_SEQUENCE_ADD(&ie->value.choice.E_RABModifyListBearerModRes.list, item); - } - + ie->value.present = S1AP_E_RABModifyResponseIEs__value_PR_MME_UE_S1AP_ID; + ie->value.choice.MME_UE_S1AP_ID = ue_context_p->mme_ue_s1ap_id; ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - } - - /* optional */ - if (e_rab_modify_resp_p->nb_of_e_rabs_failed > 0) { + /* mandatory */ ie = (S1AP_E_RABModifyResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABModifyResponseIEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_E_RABFailedToModifyList; + ie->id = S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID; ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_E_RABModifyResponseIEs__value_PR_E_RABList; - - for (i = 0; i < e_rab_modify_resp_p->nb_of_e_rabs_failed; i++) { - S1AP_E_RABItemIEs_t *item; - item = (S1AP_E_RABItemIEs_t *)calloc(1, sizeof(S1AP_E_RABItemIEs_t)); - item->id = S1AP_ProtocolIE_ID_id_E_RABItem; - item->criticality = S1AP_Criticality_ignore; - item->value.present = S1AP_E_RABItemIEs__value_PR_E_RABItem; - item->value.choice.E_RABItem.e_RAB_ID = e_rab_modify_resp_p->e_rabs_failed[i].e_rab_id; - item->value.choice.E_RABItem.cause.present = e_rab_modify_resp_p->e_rabs_failed[i].cause; - - switch(item->value.choice.E_RABItem.cause.present) { - case S1AP_Cause_PR_radioNetwork: - item->value.choice.E_RABItem.cause.choice.radioNetwork = e_rab_modify_resp_p->e_rabs_failed[i].cause_value; - break; + ie->value.present = S1AP_E_RABModifyResponseIEs__value_PR_ENB_UE_S1AP_ID; + ie->value.choice.ENB_UE_S1AP_ID = e_rab_modify_resp_p->eNB_ue_s1ap_id; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - case S1AP_Cause_PR_transport: - item->value.choice.E_RABItem.cause.choice.transport = e_rab_modify_resp_p->e_rabs_failed[i].cause_value; - break; + /* optional */ + if (e_rab_modify_resp_p->nb_of_e_rabs > 0) { + ie = (S1AP_E_RABModifyResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABModifyResponseIEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_E_RABModifyListBearerModRes; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_E_RABModifyResponseIEs__value_PR_E_RABModifyListBearerModRes; + + for (i = 0; i < e_rab_modify_resp_p->nb_of_e_rabs; i++) { + S1AP_E_RABModifyItemBearerModResIEs_t *item; + item = (S1AP_E_RABModifyItemBearerModResIEs_t *)calloc(1, sizeof(S1AP_E_RABModifyItemBearerModResIEs_t)); + item->id = S1AP_ProtocolIE_ID_id_E_RABModifyItemBearerModRes; + item->criticality = S1AP_Criticality_ignore; + item->value.present = S1AP_E_RABModifyItemBearerModResIEs__value_PR_E_RABModifyItemBearerModRes; + item->value.choice.E_RABModifyItemBearerModRes.e_RAB_ID = e_rab_modify_resp_p->e_rabs[i].e_rab_id; + S1AP_DEBUG("e_rab_modify_resp: modified e_rab ID %ld\n", item->value.choice.E_RABModifyItemBearerModRes.e_RAB_ID); + ASN_SEQUENCE_ADD(&ie->value.choice.E_RABModifyListBearerModRes.list, item); + } + + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + } - case S1AP_Cause_PR_nas: - item->value.choice.E_RABItem.cause.choice.nas = e_rab_modify_resp_p->e_rabs_failed[i].cause_value; - break; + /* optional */ + if (e_rab_modify_resp_p->nb_of_e_rabs_failed > 0) { + ie = (S1AP_E_RABModifyResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABModifyResponseIEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_E_RABFailedToModifyList; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_E_RABModifyResponseIEs__value_PR_E_RABList; + + for (i = 0; i < e_rab_modify_resp_p->nb_of_e_rabs_failed; i++) { + S1AP_E_RABItemIEs_t *item; + item = (S1AP_E_RABItemIEs_t *)calloc(1, sizeof(S1AP_E_RABItemIEs_t)); + item->id = S1AP_ProtocolIE_ID_id_E_RABItem; + item->criticality = S1AP_Criticality_ignore; + item->value.present = S1AP_E_RABItemIEs__value_PR_E_RABItem; + item->value.choice.E_RABItem.e_RAB_ID = e_rab_modify_resp_p->e_rabs_failed[i].e_rab_id; + item->value.choice.E_RABItem.cause.present = e_rab_modify_resp_p->e_rabs_failed[i].cause; + + switch(item->value.choice.E_RABItem.cause.present) { + case S1AP_Cause_PR_radioNetwork: + item->value.choice.E_RABItem.cause.choice.radioNetwork = e_rab_modify_resp_p->e_rabs_failed[i].cause_value; + break; + + case S1AP_Cause_PR_transport: + item->value.choice.E_RABItem.cause.choice.transport = e_rab_modify_resp_p->e_rabs_failed[i].cause_value; + break; + + case S1AP_Cause_PR_nas: + item->value.choice.E_RABItem.cause.choice.nas = e_rab_modify_resp_p->e_rabs_failed[i].cause_value; + break; + + case S1AP_Cause_PR_protocol: + item->value.choice.E_RABItem.cause.choice.protocol = e_rab_modify_resp_p->e_rabs_failed[i].cause_value; + break; + + case S1AP_Cause_PR_misc: + item->value.choice.E_RABItem.cause.choice.misc = e_rab_modify_resp_p->e_rabs_failed[i].cause_value; + break; + + case S1AP_Cause_PR_NOTHING: + default: + break; + } + + S1AP_DEBUG("e_rab_modify_resp: failed e_rab ID %ld\n", item->value.choice.E_RABItem.e_RAB_ID); + ASN_SEQUENCE_ADD(&ie->value.choice.E_RABList.list, item); + } + + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + } - case S1AP_Cause_PR_protocol: - item->value.choice.E_RABItem.cause.choice.protocol = e_rab_modify_resp_p->e_rabs_failed[i].cause_value; - break; + /* optional */ + if (0) { + ie = (S1AP_E_RABModifyResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABModifyResponseIEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_CriticalityDiagnostics; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_E_RABModifyResponseIEs__value_PR_CriticalityDiagnostics; + // ie->value.choice.CriticalityDiagnostics = ; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + } - case S1AP_Cause_PR_misc: - item->value.choice.E_RABItem.cause.choice.misc = e_rab_modify_resp_p->e_rabs_failed[i].cause_value; - break; + fprintf(stderr, "start encode\n"); - case S1AP_Cause_PR_NOTHING: - default: - break; - } + if (s1ap_eNB_encode_pdu(&pdu, &buffer, &length) < 0) { + S1AP_ERROR("Failed to encode uplink transport\n"); + /* Encode procedure has failed... */ + return -1; + } - S1AP_DEBUG("e_rab_modify_resp: failed e_rab ID %ld\n", item->value.choice.E_RABItem.e_RAB_ID); - ASN_SEQUENCE_ADD(&ie->value.choice.E_RABList.list, item); + MSC_LOG_TX_MESSAGE( + MSC_S1AP_ENB, + MSC_S1AP_MME, + (const char *)buffer, + length, + MSC_AS_TIME_FMT" E_RAN Modify successful Outcome eNB_ue_s1ap_id %u mme_ue_s1ap_id %u", + 0,0,//MSC_AS_TIME_ARGS(ctxt_pP), + e_rab_modify_resp_p->eNB_ue_s1ap_id, + ue_context_p->mme_ue_s1ap_id); + /* UE associated signalling -> use the allocated stream */ + s1ap_eNB_itti_send_sctp_data_req(s1ap_eNB_instance_p->instance, + ue_context_p->mme_ref->assoc_id, buffer, + length, ue_context_p->tx_stream); + return 0; +} +//------------------------------------------------------------------------------ +int s1ap_eNB_e_rab_release_resp(instance_t instance, + s1ap_e_rab_release_resp_t *e_rab_release_resp_p) +//------------------------------------------------------------------------------ +{ + s1ap_eNB_instance_t *s1ap_eNB_instance_p = NULL; + struct s1ap_eNB_ue_context_s *ue_context_p = NULL; + S1AP_S1AP_PDU_t pdu; + S1AP_E_RABReleaseResponse_t *out; + S1AP_E_RABReleaseResponseIEs_t *ie; + uint8_t *buffer = NULL; + uint32_t length; + int i; + /* Retrieve the S1AP eNB instance associated with Mod_id */ + s1ap_eNB_instance_p = s1ap_eNB_get_instance(instance); + DevAssert(e_rab_release_resp_p != NULL); + DevAssert(s1ap_eNB_instance_p != NULL); + + if ((ue_context_p = s1ap_eNB_get_ue_context(s1ap_eNB_instance_p, + e_rab_release_resp_p->eNB_ue_s1ap_id)) == NULL) { + /* The context for this eNB ue s1ap id doesn't exist in the map of eNB UEs */ + S1AP_WARN("Failed to find ue context associated with eNB ue s1ap id: %u\n", + e_rab_release_resp_p->eNB_ue_s1ap_id); + return -1; } + /* Prepare the S1AP message to encode */ + memset(&pdu, 0, sizeof(pdu)); + pdu.present = S1AP_S1AP_PDU_PR_successfulOutcome; + pdu.choice.successfulOutcome.procedureCode = S1AP_ProcedureCode_id_E_RABRelease; + pdu.choice.successfulOutcome.criticality = S1AP_Criticality_reject; + pdu.choice.successfulOutcome.value.present = S1AP_SuccessfulOutcome__value_PR_E_RABReleaseResponse; + out = &pdu.choice.successfulOutcome.value.choice.E_RABReleaseResponse; + /* mandatory */ + ie = (S1AP_E_RABReleaseResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABReleaseResponseIEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_E_RABReleaseResponseIEs__value_PR_MME_UE_S1AP_ID; + ie->value.choice.MME_UE_S1AP_ID = ue_context_p->mme_ue_s1ap_id; ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - } - - /* optional */ - if (0) { - ie = (S1AP_E_RABModifyResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABModifyResponseIEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_CriticalityDiagnostics; + /* mandatory */ + ie = (S1AP_E_RABReleaseResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABReleaseResponseIEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID; ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_E_RABModifyResponseIEs__value_PR_CriticalityDiagnostics; - // ie->value.choice.CriticalityDiagnostics = ; + ie->value.present = S1AP_E_RABReleaseResponseIEs__value_PR_ENB_UE_S1AP_ID; + ie->value.choice.ENB_UE_S1AP_ID = e_rab_release_resp_p->eNB_ue_s1ap_id; ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - } - fprintf(stderr, "start encode\n"); + /* optional */ + if (e_rab_release_resp_p->nb_of_e_rabs_released > 0) { + ie = (S1AP_E_RABReleaseResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABReleaseResponseIEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_E_RABReleaseListBearerRelComp; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_E_RABReleaseResponseIEs__value_PR_E_RABReleaseListBearerRelComp; + + for (i = 0; i < e_rab_release_resp_p->nb_of_e_rabs_released; i++) { + S1AP_E_RABReleaseItemBearerRelCompIEs_t *item; + item = (S1AP_E_RABReleaseItemBearerRelCompIEs_t *)calloc(1, sizeof(S1AP_E_RABReleaseItemBearerRelCompIEs_t)); + item->id = S1AP_ProtocolIE_ID_id_E_RABReleaseItemBearerRelComp; + item->criticality = S1AP_Criticality_ignore; + item->value.present = S1AP_E_RABReleaseItemBearerRelCompIEs__value_PR_E_RABReleaseItemBearerRelComp; + item->value.choice.E_RABReleaseItemBearerRelComp.e_RAB_ID = e_rab_release_resp_p->e_rab_release[i].e_rab_id; + S1AP_DEBUG("e_rab_release_resp: e_rab ID %ld\n", item->value.choice.E_RABReleaseItemBearerRelComp.e_RAB_ID); + ASN_SEQUENCE_ADD(&ie->value.choice.E_RABReleaseListBearerRelComp.list, item); + } + + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + } - if (s1ap_eNB_encode_pdu(&pdu, &buffer, &length) < 0) { - S1AP_ERROR("Failed to encode uplink transport\n"); - /* Encode procedure has failed... */ - return -1; - } + /* optional */ + if (e_rab_release_resp_p->nb_of_e_rabs_failed > 0) { + ie = (S1AP_E_RABReleaseResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABReleaseResponseIEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_E_RABFailedToReleaseList; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_E_RABReleaseResponseIEs__value_PR_E_RABList; + + for (i = 0; i < e_rab_release_resp_p->nb_of_e_rabs_failed; i++) { + S1AP_E_RABItemIEs_t *item; + item = (S1AP_E_RABItemIEs_t *)calloc(1, sizeof(S1AP_E_RABItemIEs_t)); + item->id = S1AP_ProtocolIE_ID_id_E_RABItem; + item->criticality = S1AP_Criticality_ignore; + item->value.present = S1AP_E_RABItemIEs__value_PR_E_RABItem; + item->value.choice.E_RABItem.e_RAB_ID = e_rab_release_resp_p->e_rabs_failed[i].e_rab_id; + item->value.choice.E_RABItem.cause.present = e_rab_release_resp_p->e_rabs_failed[i].cause; + + switch(item->value.choice.E_RABItem.cause.present) { + case S1AP_Cause_PR_radioNetwork: + item->value.choice.E_RABItem.cause.choice.radioNetwork = e_rab_release_resp_p->e_rabs_failed[i].cause_value; + break; + + case S1AP_Cause_PR_transport: + item->value.choice.E_RABItem.cause.choice.transport = e_rab_release_resp_p->e_rabs_failed[i].cause_value; + break; + + case S1AP_Cause_PR_nas: + item->value.choice.E_RABItem.cause.choice.nas = e_rab_release_resp_p->e_rabs_failed[i].cause_value; + break; + + case S1AP_Cause_PR_protocol: + item->value.choice.E_RABItem.cause.choice.protocol = e_rab_release_resp_p->e_rabs_failed[i].cause_value; + break; + + case S1AP_Cause_PR_misc: + item->value.choice.E_RABItem.cause.choice.misc = e_rab_release_resp_p->e_rabs_failed[i].cause_value; + break; + + case S1AP_Cause_PR_NOTHING: + default: + break; + } + + ASN_SEQUENCE_ADD(&ie->value.choice.E_RABList.list, item); + } + + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + } - MSC_LOG_TX_MESSAGE( - MSC_S1AP_ENB, - MSC_S1AP_MME, - (const char *)buffer, - length, - MSC_AS_TIME_FMT" E_RAN Modify successful Outcome eNB_ue_s1ap_id %u mme_ue_s1ap_id %u", - 0,0,//MSC_AS_TIME_ARGS(ctxt_pP), - e_rab_modify_resp_p->eNB_ue_s1ap_id, - ue_context_p->mme_ue_s1ap_id); - /* UE associated signalling -> use the allocated stream */ - s1ap_eNB_itti_send_sctp_data_req(s1ap_eNB_instance_p->instance, - ue_context_p->mme_ref->assoc_id, buffer, - length, ue_context_p->tx_stream); - return 0; + /* optional */ + if (0) { + ie = (S1AP_E_RABReleaseResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABReleaseResponseIEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_CriticalityDiagnostics; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_E_RABReleaseResponseIEs__value_PR_CriticalityDiagnostics; + // ie->value.choice.CriticalityDiagnostics = ; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + } + + /* optional */ +#if (S1AP_VERSION >= MAKE_VERSION(12, 0, 0)) + + if(0) { + ie = (S1AP_E_RABReleaseResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABReleaseResponseIEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_UserLocationInformation; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_E_RABReleaseResponseIEs__value_PR_UserLocationInformation; + // ie->value.choice.UserLocationInformation = ; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + } + +#endif /* #if (S1AP_VERSION >= MAKE_VERSION(14, 0, 0)) */ + fprintf(stderr, "start encode\n"); + + if (s1ap_eNB_encode_pdu(&pdu, &buffer, &length) < 0) { + S1AP_ERROR("Failed to encode release response\n"); + /* Encode procedure has failed... */ + return -1; + } + + MSC_LOG_TX_MESSAGE( + MSC_S1AP_ENB, + MSC_S1AP_MME, + (const char *)buffer, + length, + MSC_AS_TIME_FMT" E_RAN Release successfulOutcome eNB_ue_s1ap_id %u mme_ue_s1ap_id %u", + 0,0,//MSC_AS_TIME_ARGS(ctxt_pP), + e_rab_release_resp_p->eNB_ue_s1ap_id, + ue_context_p->mme_ue_s1ap_id); + /* UE associated signalling -> use the allocated stream */ + s1ap_eNB_itti_send_sctp_data_req(s1ap_eNB_instance_p->instance, + ue_context_p->mme_ref->assoc_id, buffer, + length, ue_context_p->tx_stream); + S1AP_INFO("e_rab_release_response sended eNB_UE_S1AP_ID %d mme_ue_s1ap_id %d nb_of_e_rabs_released %d nb_of_e_rabs_failed %d\n", + e_rab_release_resp_p->eNB_ue_s1ap_id, ue_context_p->mme_ue_s1ap_id,e_rab_release_resp_p->nb_of_e_rabs_released,e_rab_release_resp_p->nb_of_e_rabs_failed); + return 0; } -//------------------------------------------------------------------------------ -int s1ap_eNB_e_rab_release_resp(instance_t instance, - s1ap_e_rab_release_resp_t *e_rab_release_resp_p) + +int s1ap_eNB_path_switch_req(instance_t instance, + s1ap_path_switch_req_t *path_switch_req_p) //------------------------------------------------------------------------------ { - s1ap_eNB_instance_t *s1ap_eNB_instance_p = NULL; - struct s1ap_eNB_ue_context_s *ue_context_p = NULL; + s1ap_eNB_instance_t *s1ap_eNB_instance_p = NULL; + struct s1ap_eNB_ue_context_s *ue_context_p = NULL; + struct s1ap_eNB_mme_data_s *mme_desc_p = NULL; + S1AP_S1AP_PDU_t pdu; - S1AP_E_RABReleaseResponse_t *out; - S1AP_E_RABReleaseResponseIEs_t *ie; - uint8_t *buffer = NULL; + S1AP_PathSwitchRequest_t *out; + S1AP_PathSwitchRequestIEs_t *ie; + + S1AP_E_RABToBeSwitchedDLItemIEs_t *e_RABToBeSwitchedDLItemIEs; + S1AP_E_RABToBeSwitchedDLItem_t *e_RABToBeSwitchedDLItem; + + uint8_t *buffer = NULL; uint32_t length; - int i; + int ret = 0;//-1; + /* Retrieve the S1AP eNB instance associated with Mod_id */ s1ap_eNB_instance_p = s1ap_eNB_get_instance(instance); - DevAssert(e_rab_release_resp_p != NULL); + + DevAssert(path_switch_req_p != NULL); DevAssert(s1ap_eNB_instance_p != NULL); - if ((ue_context_p = s1ap_eNB_get_ue_context(s1ap_eNB_instance_p, - e_rab_release_resp_p->eNB_ue_s1ap_id)) == NULL) { + //if ((ue_context_p = s1ap_eNB_get_ue_context(s1ap_eNB_instance_p, + // path_switch_req_p->eNB_ue_s1ap_id)) == NULL) { /* The context for this eNB ue s1ap id doesn't exist in the map of eNB UEs */ - S1AP_WARN("Failed to find ue context associated with eNB ue s1ap id: %u\n", - e_rab_release_resp_p->eNB_ue_s1ap_id); + //S1AP_WARN("Failed to find ue context associated with eNB ue s1ap id: 0x%06x\n", + // path_switch_req_p->eNB_ue_s1ap_id); + //return -1; + //} + + /* Uplink NAS transport can occur either during an s1ap connected state + * or during initial attach (for example: NAS authentication). + */ + //if (!(ue_context_p->ue_state == S1AP_UE_CONNECTED || + // ue_context_p->ue_state == S1AP_UE_WAITING_CSR)) { + //S1AP_WARN("You are attempting to send NAS data over non-connected " + // "eNB ue s1ap id: %06x, current state: %d\n", + // path_switch_req_p->eNB_ue_s1ap_id, ue_context_p->ue_state); + //return -1; + //} + + /* Select the MME corresponding to the provided GUMMEI. */ + mme_desc_p = s1ap_eNB_nnsf_select_mme_by_gummei_no_cause(s1ap_eNB_instance_p, path_switch_req_p->ue_gummei); + + if (mme_desc_p == NULL) { + /* + * In case eNB has no MME associated, the eNB should inform RRC and discard + * this request. + */ + + S1AP_WARN("No MME is associated to the eNB\n"); + // TODO: Inform RRC return -1; } - /* Prepare the S1AP message to encode */ - memset(&pdu, 0, sizeof(pdu)); - pdu.present = S1AP_S1AP_PDU_PR_successfulOutcome; - pdu.choice.successfulOutcome.procedureCode = S1AP_ProcedureCode_id_E_RABRelease; - pdu.choice.successfulOutcome.criticality = S1AP_Criticality_reject; - pdu.choice.successfulOutcome.value.present = S1AP_SuccessfulOutcome__value_PR_E_RABReleaseResponse; - out = &pdu.choice.successfulOutcome.value.choice.E_RABReleaseResponse; - /* mandatory */ - ie = (S1AP_E_RABReleaseResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABReleaseResponseIEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_E_RABReleaseResponseIEs__value_PR_MME_UE_S1AP_ID; - ie->value.choice.MME_UE_S1AP_ID = ue_context_p->mme_ue_s1ap_id; - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - /* mandatory */ - ie = (S1AP_E_RABReleaseResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABReleaseResponseIEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_E_RABReleaseResponseIEs__value_PR_ENB_UE_S1AP_ID; - ie->value.choice.ENB_UE_S1AP_ID = e_rab_release_resp_p->eNB_ue_s1ap_id; - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + /* The eNB should allocate a unique eNB UE S1AP ID for this UE. The value + * will be used for the duration of the connectivity. + */ + ue_context_p = s1ap_eNB_allocate_new_UE_context(); + DevAssert(ue_context_p != NULL); - /* optional */ - if (e_rab_release_resp_p->nb_of_e_rabs_released > 0) { - ie = (S1AP_E_RABReleaseResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABReleaseResponseIEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_E_RABReleaseListBearerRelComp; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_E_RABReleaseResponseIEs__value_PR_E_RABReleaseListBearerRelComp; + /* Keep a reference to the selected MME */ + ue_context_p->mme_ref = mme_desc_p; + ue_context_p->ue_initial_id = path_switch_req_p->ue_initial_id; + ue_context_p->eNB_instance = s1ap_eNB_instance_p; + + do { + struct s1ap_eNB_ue_context_s *collision_p; - for (i = 0; i < e_rab_release_resp_p->nb_of_e_rabs_released; i++) { - S1AP_E_RABReleaseItemBearerRelCompIEs_t *item; - item = (S1AP_E_RABReleaseItemBearerRelCompIEs_t *)calloc(1, sizeof(S1AP_E_RABReleaseItemBearerRelCompIEs_t)); - item->id = S1AP_ProtocolIE_ID_id_E_RABReleaseItemBearerRelComp; - item->criticality = S1AP_Criticality_ignore; - item->value.present = S1AP_E_RABReleaseItemBearerRelCompIEs__value_PR_E_RABReleaseItemBearerRelComp; - item->value.choice.E_RABReleaseItemBearerRelComp.e_RAB_ID = e_rab_release_resp_p->e_rab_release[i].e_rab_id; - S1AP_DEBUG("e_rab_release_resp: e_rab ID %ld\n", item->value.choice.E_RABReleaseItemBearerRelComp.e_RAB_ID); - ASN_SEQUENCE_ADD(&ie->value.choice.E_RABReleaseListBearerRelComp.list, item); + /* Peek a random value for the eNB_ue_s1ap_id */ + ue_context_p->eNB_ue_s1ap_id = (random() + random()) & 0x00ffffff; + + if ((collision_p = RB_INSERT(s1ap_ue_map, &s1ap_eNB_instance_p->s1ap_ue_head, ue_context_p)) + == NULL) { + S1AP_DEBUG("Found usable eNB_ue_s1ap_id: 0x%06x %u(10)\n", + ue_context_p->eNB_ue_s1ap_id, + ue_context_p->eNB_ue_s1ap_id); + /* Break the loop as the id is not already used by another UE */ + break; } + } while(1); - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - } + ue_context_p->mme_ue_s1ap_id = path_switch_req_p->mme_ue_s1ap_id; - /* optional */ - if (e_rab_release_resp_p->nb_of_e_rabs_failed > 0) { - ie = (S1AP_E_RABReleaseResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABReleaseResponseIEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_E_RABFailedToReleaseList; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_E_RABReleaseResponseIEs__value_PR_E_RABList; + /* Prepare the S1AP message to encode */ + memset(&pdu, 0, sizeof(pdu)); + pdu.present = S1AP_S1AP_PDU_PR_initiatingMessage; + pdu.choice.initiatingMessage.procedureCode = S1AP_ProcedureCode_id_PathSwitchRequest; + pdu.choice.initiatingMessage.criticality = S1AP_Criticality_reject; + pdu.choice.initiatingMessage.value.present = S1AP_InitiatingMessage__value_PR_PathSwitchRequest; + out = &pdu.choice.initiatingMessage.value.choice.PathSwitchRequest; + + /* mandatory */ + ie = (S1AP_PathSwitchRequestIEs_t *)calloc(1, sizeof(S1AP_PathSwitchRequestIEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID; + ie->criticality = S1AP_Criticality_reject; + ie->value.present = S1AP_PathSwitchRequestIEs__value_PR_ENB_UE_S1AP_ID; + ie->value.choice.ENB_UE_S1AP_ID = ue_context_p->eNB_ue_s1ap_id; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - for (i = 0; i < e_rab_release_resp_p->nb_of_e_rabs_failed; i++) { - S1AP_E_RABItemIEs_t *item; - item = (S1AP_E_RABItemIEs_t *)calloc(1, sizeof(S1AP_E_RABItemIEs_t)); - item->id = S1AP_ProtocolIE_ID_id_E_RABItem; - item->criticality = S1AP_Criticality_ignore; - item->value.present = S1AP_E_RABItemIEs__value_PR_E_RABItem; - item->value.choice.E_RABItem.e_RAB_ID = e_rab_release_resp_p->e_rabs_failed[i].e_rab_id; - item->value.choice.E_RABItem.cause.present = e_rab_release_resp_p->e_rabs_failed[i].cause; + /* mandatory */ + if (path_switch_req_p->nb_of_e_rabs > 0) { + ie = (S1AP_PathSwitchRequestIEs_t *)calloc(1, sizeof(S1AP_PathSwitchRequestIEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_E_RABToBeSwitchedDLList; + ie->criticality = S1AP_Criticality_reject; + ie->value.present = S1AP_PathSwitchRequestIEs__value_PR_E_RABToBeSwitchedDLList; - switch(item->value.choice.E_RABItem.cause.present) { - case S1AP_Cause_PR_radioNetwork: - item->value.choice.E_RABItem.cause.choice.radioNetwork = e_rab_release_resp_p->e_rabs_failed[i].cause_value; - break; + for (int i = 0; i < path_switch_req_p->nb_of_e_rabs; i++) { + e_RABToBeSwitchedDLItemIEs = (S1AP_E_RABToBeSwitchedDLItemIEs_t *)calloc(1, sizeof(S1AP_E_RABToBeSwitchedDLItemIEs_t)); + e_RABToBeSwitchedDLItemIEs->id = S1AP_ProtocolIE_ID_id_E_RABToBeSwitchedDLItem; + e_RABToBeSwitchedDLItemIEs->criticality = S1AP_Criticality_reject; + e_RABToBeSwitchedDLItemIEs->value.present = S1AP_E_RABToBeSwitchedDLItemIEs__value_PR_E_RABToBeSwitchedDLItem; - case S1AP_Cause_PR_transport: - item->value.choice.E_RABItem.cause.choice.transport = e_rab_release_resp_p->e_rabs_failed[i].cause_value; - break; + e_RABToBeSwitchedDLItem = &e_RABToBeSwitchedDLItemIEs->value.choice.E_RABToBeSwitchedDLItem; + e_RABToBeSwitchedDLItem->e_RAB_ID = path_switch_req_p->e_rabs_tobeswitched[i].e_rab_id; + INT32_TO_OCTET_STRING(path_switch_req_p->e_rabs_tobeswitched[i].gtp_teid, &e_RABToBeSwitchedDLItem->gTP_TEID); - case S1AP_Cause_PR_nas: - item->value.choice.E_RABItem.cause.choice.nas = e_rab_release_resp_p->e_rabs_failed[i].cause_value; - break; + e_RABToBeSwitchedDLItem->transportLayerAddress.size = path_switch_req_p->e_rabs_tobeswitched[i].eNB_addr.length; + e_RABToBeSwitchedDLItem->transportLayerAddress.bits_unused = 0; - case S1AP_Cause_PR_protocol: - item->value.choice.E_RABItem.cause.choice.protocol = e_rab_release_resp_p->e_rabs_failed[i].cause_value; - break; + e_RABToBeSwitchedDLItem->transportLayerAddress.buf = calloc(1,e_RABToBeSwitchedDLItem->transportLayerAddress.size); - case S1AP_Cause_PR_misc: - item->value.choice.E_RABItem.cause.choice.misc = e_rab_release_resp_p->e_rabs_failed[i].cause_value; - break; + memcpy (e_RABToBeSwitchedDLItem->transportLayerAddress.buf, + path_switch_req_p->e_rabs_tobeswitched[i].eNB_addr.buffer, + path_switch_req_p->e_rabs_tobeswitched[i].eNB_addr.length); - case S1AP_Cause_PR_NOTHING: - default: - break; - } + S1AP_DEBUG("path_switch_req: e_rab ID %ld, teid %u, enb_addr %d.%d.%d.%d, SIZE %zu\n", + e_RABToBeSwitchedDLItem->e_RAB_ID, + path_switch_req_p->e_rabs_tobeswitched[i].gtp_teid, + e_RABToBeSwitchedDLItem->transportLayerAddress.buf[0], + e_RABToBeSwitchedDLItem->transportLayerAddress.buf[1], + e_RABToBeSwitchedDLItem->transportLayerAddress.buf[2], + e_RABToBeSwitchedDLItem->transportLayerAddress.buf[3], + e_RABToBeSwitchedDLItem->transportLayerAddress.size); - ASN_SEQUENCE_ADD(&ie->value.choice.E_RABList.list, item); + ASN_SEQUENCE_ADD(&ie->value.choice.E_RABToBeSwitchedDLList.list, e_RABToBeSwitchedDLItemIEs); } ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); } - /* optional */ - if (0) { - ie = (S1AP_E_RABReleaseResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABReleaseResponseIEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_CriticalityDiagnostics; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_E_RABReleaseResponseIEs__value_PR_CriticalityDiagnostics; - // ie->value.choice.CriticalityDiagnostics = ; - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - } + /* mandatory */ + ie = (S1AP_PathSwitchRequestIEs_t *)calloc(1, sizeof(S1AP_PathSwitchRequestIEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_SourceMME_UE_S1AP_ID; + ie->criticality = S1AP_Criticality_reject; + ie->value.present = S1AP_PathSwitchRequestIEs__value_PR_MME_UE_S1AP_ID; + ie->value.choice.MME_UE_S1AP_ID = path_switch_req_p->mme_ue_s1ap_id; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - /* optional */ -#if (S1AP_VERSION >= MAKE_VERSION(12, 0, 0)) + /* mandatory */ + ie = (S1AP_PathSwitchRequestIEs_t *)calloc(1, sizeof(S1AP_PathSwitchRequestIEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_EUTRAN_CGI; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_PathSwitchRequestIEs__value_PR_EUTRAN_CGI; + MACRO_ENB_ID_TO_CELL_IDENTITY(s1ap_eNB_instance_p->eNB_id, + 0, + &ie->value.choice.EUTRAN_CGI.cell_ID); + MCC_MNC_TO_TBCD(s1ap_eNB_instance_p->mcc[0], + s1ap_eNB_instance_p->mnc[0], + s1ap_eNB_instance_p->mnc_digit_length[0], + &ie->value.choice.EUTRAN_CGI.pLMNidentity); + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - if(0) { - ie = (S1AP_E_RABReleaseResponseIEs_t *)calloc(1, sizeof(S1AP_E_RABReleaseResponseIEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_UserLocationInformation; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_E_RABReleaseResponseIEs__value_PR_UserLocationInformation; - // ie->value.choice.UserLocationInformation = ; - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - } + /* mandatory */ + ie = (S1AP_PathSwitchRequestIEs_t *)calloc(1, sizeof(S1AP_PathSwitchRequestIEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_TAI; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_PathSwitchRequestIEs__value_PR_TAI; + /* Assuming TAI is the TAI from the cell */ + INT16_TO_OCTET_STRING(s1ap_eNB_instance_p->tac, &ie->value.choice.TAI.tAC); + MCC_MNC_TO_PLMNID(s1ap_eNB_instance_p->mcc[0], + s1ap_eNB_instance_p->mnc[0], + s1ap_eNB_instance_p->mnc_digit_length[0], + &ie->value.choice.TAI.pLMNidentity); + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); -#endif /* #if (S1AP_VERSION >= MAKE_VERSION(14, 0, 0)) */ - fprintf(stderr, "start encode\n"); + /* mandatory */ + ie = (S1AP_PathSwitchRequestIEs_t *)calloc(1, sizeof(S1AP_PathSwitchRequestIEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_UESecurityCapabilities; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_PathSwitchRequestIEs__value_PR_UESecurityCapabilities; + ENCRALG_TO_BIT_STRING(path_switch_req_p->security_capabilities.encryption_algorithms, + &ie->value.choice.UESecurityCapabilities.encryptionAlgorithms); + INTPROTALG_TO_BIT_STRING(path_switch_req_p->security_capabilities.integrity_algorithms, + &ie->value.choice.UESecurityCapabilities.integrityProtectionAlgorithms); + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); if (s1ap_eNB_encode_pdu(&pdu, &buffer, &length) < 0) { - S1AP_ERROR("Failed to encode release response\n"); + S1AP_ERROR("Failed to encode Path Switch Req \n"); /* Encode procedure has failed... */ return -1; } + /* Update the current S1AP UE state */ + ue_context_p->ue_state = S1AP_UE_WAITING_CSR; + + /* Assign a stream for this UE : + * From 3GPP 36.412 7)Transport layers: + * Within the SCTP association established between one MME and eNB pair: + * - a single pair of stream identifiers shall be reserved for the sole use + * of S1AP elementary procedures that utilize non UE-associated signalling. + * - At least one pair of stream identifiers shall be reserved for the sole use + * of S1AP elementary procedures that utilize UE-associated signallings. + * However a few pairs (i.e. more than one) should be reserved. + * - A single UE-associated signalling shall use one SCTP stream and + * the stream should not be changed during the communication of the + * UE-associated signalling. + */ + mme_desc_p->nextstream = (mme_desc_p->nextstream + 1) % mme_desc_p->out_streams; + + if ((mme_desc_p->nextstream == 0) && (mme_desc_p->out_streams > 1)) { + mme_desc_p->nextstream += 1; + } + + ue_context_p->tx_stream = mme_desc_p->nextstream; + MSC_LOG_TX_MESSAGE( MSC_S1AP_ENB, MSC_S1AP_MME, (const char *)buffer, length, - MSC_AS_TIME_FMT" E_RAN Release successfulOutcome eNB_ue_s1ap_id %u mme_ue_s1ap_id %u", + MSC_AS_TIME_FMT" E_RAN Setup successfulOutcome eNB_ue_s1ap_id %u mme_ue_s1ap_id %u", 0,0,//MSC_AS_TIME_ARGS(ctxt_pP), - e_rab_release_resp_p->eNB_ue_s1ap_id, - ue_context_p->mme_ue_s1ap_id); + ue_context_p->eNB_ue_s1ap_id, + path_switch_req_p->mme_ue_s1ap_id); + /* UE associated signalling -> use the allocated stream */ s1ap_eNB_itti_send_sctp_data_req(s1ap_eNB_instance_p->instance, - ue_context_p->mme_ref->assoc_id, buffer, + mme_desc_p->assoc_id, buffer, length, ue_context_p->tx_stream); - S1AP_INFO("e_rab_release_response sended eNB_UE_S1AP_ID %d mme_ue_s1ap_id %d nb_of_e_rabs_released %d nb_of_e_rabs_failed %d\n", - e_rab_release_resp_p->eNB_ue_s1ap_id, ue_context_p->mme_ue_s1ap_id,e_rab_release_resp_p->nb_of_e_rabs_released,e_rab_release_resp_p->nb_of_e_rabs_failed); - return 0; + + return ret; } diff --git a/openair3/S1AP/s1ap_eNB_nas_procedures.h b/openair3/S1AP/s1ap_eNB_nas_procedures.h index a7f144c0ca3653ab0a2665f8d1be619a1fe9d1a5..c4257198727a042cfacd7eeafac65e1dfc36a232 100644 --- a/openair3/S1AP/s1ap_eNB_nas_procedures.h +++ b/openair3/S1AP/s1ap_eNB_nas_procedures.h @@ -49,4 +49,7 @@ int s1ap_eNB_e_rab_modify_resp(instance_t instance, int s1ap_eNB_e_rab_release_resp(instance_t instance, s1ap_e_rab_release_resp_t *e_rab_release_resp_p); + +int s1ap_eNB_path_switch_req(instance_t instance, + s1ap_path_switch_req_t *path_switch_req_p); #endif /* S1AP_ENB_NAS_PROCEDURES_H_ */ diff --git a/openair3/S1AP/s1ap_eNB_nnsf.c b/openair3/S1AP/s1ap_eNB_nnsf.c index 63dc92b5e260e33c82a3dd076788b4761b1d763c..6319f6e054d878fb19087e0c3f3fa8e946a6d602 100644 --- a/openair3/S1AP/s1ap_eNB_nnsf.c +++ b/openair3/S1AP/s1ap_eNB_nnsf.c @@ -321,3 +321,79 @@ s1ap_eNB_nnsf_select_mme_by_gummei(s1ap_eNB_instance_t *instance_p, * connectivity. */ return NULL; } + + +struct s1ap_eNB_mme_data_s * +s1ap_eNB_nnsf_select_mme_by_gummei_no_cause(s1ap_eNB_instance_t *instance_p, + s1ap_gummei_t gummei) +{ + struct s1ap_eNB_mme_data_s *mme_data_p = NULL; + struct s1ap_eNB_mme_data_s *mme_highest_capacity_p = NULL; + uint8_t current_capacity = 0; + + RB_FOREACH(mme_data_p, s1ap_mme_map, &instance_p->s1ap_mme_head) { + struct served_gummei_s *gummei_p = NULL; + + if (mme_data_p->state != S1AP_ENB_STATE_CONNECTED) { + /* The association between MME and eNB is not ready for the moment, + * go to the next known MME. + */ + if (mme_data_p->state == S1AP_ENB_OVERLOAD) { + /* MME is overloaded. We have to check the RRC establishment + * cause and take decision to the select this MME depending on + * the overload state. + */ + } else { + /* The MME is not overloaded, association is simply not ready. */ + continue; + } + } + + if (current_capacity < mme_data_p->relative_mme_capacity) { + /* We find a better MME, keep a reference to it */ + current_capacity = mme_data_p->relative_mme_capacity; + mme_highest_capacity_p = mme_data_p; + } + + /* Looking for MME gummei matching the one provided by NAS */ + STAILQ_FOREACH(gummei_p, &mme_data_p->served_gummei, next) { + struct served_group_id_s *group_id_p = NULL; + struct mme_code_s *mme_code_p = NULL; + struct plmn_identity_s *served_plmn_p = NULL; + + STAILQ_FOREACH(served_plmn_p, &gummei_p->served_plmns, next) { + if ((served_plmn_p->mcc == gummei.mcc) && + (served_plmn_p->mnc == gummei.mnc)) { + break; + } + } + STAILQ_FOREACH(mme_code_p, &gummei_p->mme_codes, next) { + if (mme_code_p->mme_code == gummei.mme_code) { + break; + } + } + STAILQ_FOREACH(group_id_p, &gummei_p->served_group_ids, next) { + if (group_id_p->mme_group_id == gummei.mme_group_id) { + break; + } + } + + /* The MME matches the parameters provided by the NAS layer -> + * the MME is knwown and the association is ready. + * Return the reference to the MME to use it for this UE. + */ + if ((group_id_p != NULL) && + (mme_code_p != NULL) && + (served_plmn_p != NULL)) { + return mme_data_p; + } + } + } + + /* At this point no MME matches the provided GUMMEI. Select the one with the + * highest relative capacity. + * In case the list of known MME is empty, simply return NULL, that way the RRC + * layer should know about it and reject RRC connectivity. + */ + return mme_highest_capacity_p; +} diff --git a/openair3/S1AP/s1ap_eNB_nnsf.h b/openair3/S1AP/s1ap_eNB_nnsf.h index 706f3ada6ff8380bf7e94d6a541817eb83064e07..d5f080649b0e6563ea138420fb35b7481cba2727 100644 --- a/openair3/S1AP/s1ap_eNB_nnsf.h +++ b/openair3/S1AP/s1ap_eNB_nnsf.h @@ -42,4 +42,8 @@ s1ap_eNB_nnsf_select_mme_by_gummei(s1ap_eNB_instance_t *instance_p, rrc_establishment_cause_t cause, s1ap_gummei_t gummei); +struct s1ap_eNB_mme_data_s* +s1ap_eNB_nnsf_select_mme_by_gummei_no_cause(s1ap_eNB_instance_t *instance_p, + s1ap_gummei_t gummei); + #endif /* S1AP_ENB_NNSF_H_ */ diff --git a/openair3/S1AP/s1ap_eNB_overload.c b/openair3/S1AP/s1ap_eNB_overload.c index cf208fc16e3e47dfaa2d63d64842bed52caa9397..9358ae62bdb6286873240f3194af9e609921172f 100644 --- a/openair3/S1AP/s1ap_eNB_overload.c +++ b/openair3/S1AP/s1ap_eNB_overload.c @@ -47,60 +47,60 @@ int s1ap_eNB_handle_overload_start(uint32_t assoc_id, uint32_t stream, S1AP_S1AP_PDU_t *pdu) { - s1ap_eNB_mme_data_t *mme_desc_p; - S1AP_OverloadStart_t *container; - S1AP_OverloadStartIEs_t *ie; - - DevAssert(pdu != NULL); - - container = &pdu->choice.initiatingMessage.value.choice.OverloadStart; - - S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_OverloadStartIEs_t, ie, container, - S1AP_ProtocolIE_ID_id_OverloadResponse, true); - - DevCheck(ie->value.choice.OverloadResponse.present == - S1AP_OverloadResponse_PR_overloadAction, - S1AP_OverloadResponse_PR_overloadAction, 0, 0); - - /* Non UE-associated signalling -> stream 0 */ - DevCheck(stream == 0, stream, 0, 0); - - if ((mme_desc_p = s1ap_eNB_get_MME(NULL, assoc_id, 0)) == NULL) { - /* No MME context associated */ - return -1; - } - - /* Mark the MME as overloaded and set the overload state according to - * the value received. - */ - mme_desc_p->state = S1AP_ENB_OVERLOAD; - mme_desc_p->overload_state = - ie->value.choice.OverloadResponse.choice.overloadAction; - - return 0; + s1ap_eNB_mme_data_t *mme_desc_p; + S1AP_OverloadStart_t *container; + S1AP_OverloadStartIEs_t *ie; + + DevAssert(pdu != NULL); + + container = &pdu->choice.initiatingMessage.value.choice.OverloadStart; + + S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_OverloadStartIEs_t, ie, container, + S1AP_ProtocolIE_ID_id_OverloadResponse, true); + if (ie != NULL) { + DevCheck(ie->value.choice.OverloadResponse.present == + S1AP_OverloadResponse_PR_overloadAction, + S1AP_OverloadResponse_PR_overloadAction, 0, 0); + } + /* Non UE-associated signalling -> stream 0 */ + DevCheck(stream == 0, stream, 0, 0); + + if ((mme_desc_p = s1ap_eNB_get_MME(NULL, assoc_id, 0)) == NULL) { + /* No MME context associated */ + return -1; + } + + /* Mark the MME as overloaded and set the overload state according to + * the value received. + */ + mme_desc_p->state = S1AP_ENB_OVERLOAD; + mme_desc_p->overload_state = + ie->value.choice.OverloadResponse.choice.overloadAction; + + return 0; } int s1ap_eNB_handle_overload_stop(uint32_t assoc_id, uint32_t stream, S1AP_S1AP_PDU_t *pdu) { - /* We received Overload stop message, meaning that the MME is no more - * overloaded. This is an empty message, with only message header and no - * Information Element. - */ - DevAssert(pdu != NULL); + /* We received Overload stop message, meaning that the MME is no more + * overloaded. This is an empty message, with only message header and no + * Information Element. + */ + DevAssert(pdu != NULL); - s1ap_eNB_mme_data_t *mme_desc_p; + s1ap_eNB_mme_data_t *mme_desc_p; - /* Non UE-associated signalling -> stream 0 */ - DevCheck(stream == 0, stream, 0, 0); + /* Non UE-associated signalling -> stream 0 */ + DevCheck(stream == 0, stream, 0, 0); - if ((mme_desc_p = s1ap_eNB_get_MME(NULL, assoc_id, 0)) == NULL) { - /* No MME context associated */ - return -1; - } + if ((mme_desc_p = s1ap_eNB_get_MME(NULL, assoc_id, 0)) == NULL) { + /* No MME context associated */ + return -1; + } - mme_desc_p->state = S1AP_ENB_STATE_CONNECTED; - mme_desc_p->overload_state = S1AP_NO_OVERLOAD; - return 0; + mme_desc_p->state = S1AP_ENB_STATE_CONNECTED; + mme_desc_p->overload_state = S1AP_NO_OVERLOAD; + return 0; } diff --git a/openair3/S1AP/s1ap_eNB_trace.c b/openair3/S1AP/s1ap_eNB_trace.c index 653aa98ccdd1390c965e11c018cc9d9b7db18616..03c0ea4fb2c077d2b5d06110eff9e6d917c06377 100644 --- a/openair3/S1AP/s1ap_eNB_trace.c +++ b/openair3/S1AP/s1ap_eNB_trace.c @@ -42,107 +42,109 @@ void s1ap_eNB_generate_trace_failure(struct s1ap_eNB_ue_context_s *ue_desc_p, S1AP_E_UTRAN_Trace_ID_t *trace_id, S1AP_Cause_t *cause_p) { - S1AP_S1AP_PDU_t pdu; - S1AP_TraceFailureIndication_t *out; - S1AP_TraceFailureIndicationIEs_t *ie; - uint8_t *buffer = NULL; - uint32_t length; - - DevAssert(ue_desc_p != NULL); - DevAssert(trace_id != NULL); - DevAssert(cause_p != NULL); - - /* Prepare the S1AP message to encode */ - memset(&pdu, 0, sizeof(pdu)); - pdu.present = S1AP_S1AP_PDU_PR_initiatingMessage; - pdu.choice.initiatingMessage.procedureCode = S1AP_ProcedureCode_id_TraceFailureIndication; - pdu.choice.initiatingMessage.criticality = S1AP_Criticality_ignore; - pdu.choice.initiatingMessage.value.present = S1AP_InitiatingMessage__value_PR_TraceFailureIndication; - out = &pdu.choice.initiatingMessage.value.choice.TraceFailureIndication; - - /* mandatory */ - ie = (S1AP_TraceFailureIndicationIEs_t *)calloc(1, sizeof(S1AP_TraceFailureIndicationIEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID; - ie->criticality = S1AP_Criticality_reject; - ie->value.present = S1AP_TraceFailureIndicationIEs__value_PR_MME_UE_S1AP_ID; - ie->value.choice.MME_UE_S1AP_ID = ue_desc_p->mme_ue_s1ap_id; - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - - /* mandatory */ - ie = (S1AP_TraceFailureIndicationIEs_t *)calloc(1, sizeof(S1AP_TraceFailureIndicationIEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID; - ie->criticality = S1AP_Criticality_reject; - ie->value.present = S1AP_TraceFailureIndicationIEs__value_PR_ENB_UE_S1AP_ID; - ie->value.choice.ENB_UE_S1AP_ID = ue_desc_p->eNB_ue_s1ap_id; - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - - /* mandatory */ - ie = (S1AP_TraceFailureIndicationIEs_t *)calloc(1, sizeof(S1AP_TraceFailureIndicationIEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_E_UTRAN_Trace_ID; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_TraceFailureIndicationIEs__value_PR_E_UTRAN_Trace_ID; - memcpy(&ie->value.choice.E_UTRAN_Trace_ID, trace_id, sizeof(S1AP_E_UTRAN_Trace_ID_t)); - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - - /* mandatory */ - ie = (S1AP_TraceFailureIndicationIEs_t *)calloc(1, sizeof(S1AP_TraceFailureIndicationIEs_t)); - ie->id = S1AP_ProtocolIE_ID_id_Cause; - ie->criticality = S1AP_Criticality_ignore; - ie->value.present = S1AP_TraceFailureIndicationIEs__value_PR_Cause; - memcpy(&ie->value.choice.Cause, cause_p, sizeof(S1AP_Cause_t)); - ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); - - if (s1ap_eNB_encode_pdu(&pdu, &buffer, &length) < 0) { - return; - } - - s1ap_eNB_itti_send_sctp_data_req(ue_desc_p->mme_ref->s1ap_eNB_instance->instance, - ue_desc_p->mme_ref->assoc_id, buffer, - length, ue_desc_p->tx_stream); + S1AP_S1AP_PDU_t pdu; + S1AP_TraceFailureIndication_t *out; + S1AP_TraceFailureIndicationIEs_t *ie; + uint8_t *buffer = NULL; + uint32_t length; + + DevAssert(ue_desc_p != NULL); + DevAssert(trace_id != NULL); + DevAssert(cause_p != NULL); + + /* Prepare the S1AP message to encode */ + memset(&pdu, 0, sizeof(pdu)); + pdu.present = S1AP_S1AP_PDU_PR_initiatingMessage; + pdu.choice.initiatingMessage.procedureCode = S1AP_ProcedureCode_id_TraceFailureIndication; + pdu.choice.initiatingMessage.criticality = S1AP_Criticality_ignore; + pdu.choice.initiatingMessage.value.present = S1AP_InitiatingMessage__value_PR_TraceFailureIndication; + out = &pdu.choice.initiatingMessage.value.choice.TraceFailureIndication; + + /* mandatory */ + ie = (S1AP_TraceFailureIndicationIEs_t *)calloc(1, sizeof(S1AP_TraceFailureIndicationIEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_MME_UE_S1AP_ID; + ie->criticality = S1AP_Criticality_reject; + ie->value.present = S1AP_TraceFailureIndicationIEs__value_PR_MME_UE_S1AP_ID; + ie->value.choice.MME_UE_S1AP_ID = ue_desc_p->mme_ue_s1ap_id; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + + /* mandatory */ + ie = (S1AP_TraceFailureIndicationIEs_t *)calloc(1, sizeof(S1AP_TraceFailureIndicationIEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID; + ie->criticality = S1AP_Criticality_reject; + ie->value.present = S1AP_TraceFailureIndicationIEs__value_PR_ENB_UE_S1AP_ID; + ie->value.choice.ENB_UE_S1AP_ID = ue_desc_p->eNB_ue_s1ap_id; + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + + /* mandatory */ + ie = (S1AP_TraceFailureIndicationIEs_t *)calloc(1, sizeof(S1AP_TraceFailureIndicationIEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_E_UTRAN_Trace_ID; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_TraceFailureIndicationIEs__value_PR_E_UTRAN_Trace_ID; + memcpy(&ie->value.choice.E_UTRAN_Trace_ID, trace_id, sizeof(S1AP_E_UTRAN_Trace_ID_t)); + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + + /* mandatory */ + ie = (S1AP_TraceFailureIndicationIEs_t *)calloc(1, sizeof(S1AP_TraceFailureIndicationIEs_t)); + ie->id = S1AP_ProtocolIE_ID_id_Cause; + ie->criticality = S1AP_Criticality_ignore; + ie->value.present = S1AP_TraceFailureIndicationIEs__value_PR_Cause; + memcpy(&ie->value.choice.Cause, cause_p, sizeof(S1AP_Cause_t)); + ASN_SEQUENCE_ADD(&out->protocolIEs.list, ie); + + if (s1ap_eNB_encode_pdu(&pdu, &buffer, &length) < 0) { + return; + } + + s1ap_eNB_itti_send_sctp_data_req(ue_desc_p->mme_ref->s1ap_eNB_instance->instance, + ue_desc_p->mme_ref->assoc_id, buffer, + length, ue_desc_p->tx_stream); } int s1ap_eNB_handle_trace_start(uint32_t assoc_id, uint32_t stream, S1AP_S1AP_PDU_t *pdu) { - S1AP_TraceStart_t *container; - S1AP_TraceStartIEs_t *ie; - struct s1ap_eNB_ue_context_s *ue_desc_p; - struct s1ap_eNB_mme_data_s *mme_ref_p; - - DevAssert(pdu != NULL); - - container = &pdu->choice.initiatingMessage.value.choice.TraceStart; - - S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_TraceStartIEs_t, ie, container, - S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID, TRUE); - mme_ref_p = s1ap_eNB_get_MME(NULL, assoc_id, 0); - DevAssert(mme_ref_p != NULL); - - if ((ue_desc_p = s1ap_eNB_get_ue_context(mme_ref_p->s1ap_eNB_instance, - ie->value.choice.ENB_UE_S1AP_ID)) == NULL) { - /* Could not find context associated with this eNB_ue_s1ap_id -> generate - * trace failure indication. - */ - S1AP_E_UTRAN_Trace_ID_t trace_id; - S1AP_Cause_t cause; - memset(&trace_id, 0, sizeof(S1AP_E_UTRAN_Trace_ID_t)); - memset(&cause, 0, sizeof(S1AP_Cause_t)); - cause.present = S1AP_Cause_PR_radioNetwork; - cause.choice.radioNetwork = S1AP_CauseRadioNetwork_unknown_pair_ue_s1ap_id; - s1ap_eNB_generate_trace_failure(ue_desc_p, &trace_id, &cause); - } - - return 0; + S1AP_TraceStart_t *container; + S1AP_TraceStartIEs_t *ie; + struct s1ap_eNB_ue_context_s *ue_desc_p; + struct s1ap_eNB_mme_data_s *mme_ref_p; + + DevAssert(pdu != NULL); + + container = &pdu->choice.initiatingMessage.value.choice.TraceStart; + + S1AP_FIND_PROTOCOLIE_BY_ID(S1AP_TraceStartIEs_t, ie, container, + S1AP_ProtocolIE_ID_id_eNB_UE_S1AP_ID, TRUE); + mme_ref_p = s1ap_eNB_get_MME(NULL, assoc_id, 0); + DevAssert(mme_ref_p != NULL); + if (ie != NULL) { + ue_desc_p = s1ap_eNB_get_ue_context(mme_ref_p->s1ap_eNB_instance, + ie->value.choice.ENB_UE_S1AP_ID); + } + if (ue_desc_p == NULL) { + /* Could not find context associated with this eNB_ue_s1ap_id -> generate + * trace failure indication. + */ + S1AP_E_UTRAN_Trace_ID_t trace_id; + S1AP_Cause_t cause; + memset(&trace_id, 0, sizeof(S1AP_E_UTRAN_Trace_ID_t)); + memset(&cause, 0, sizeof(S1AP_Cause_t)); + cause.present = S1AP_Cause_PR_radioNetwork; + cause.choice.radioNetwork = S1AP_CauseRadioNetwork_unknown_pair_ue_s1ap_id; + s1ap_eNB_generate_trace_failure(NULL, &trace_id, &cause); + } + + return 0; } int s1ap_eNB_handle_deactivate_trace(uint32_t assoc_id, uint32_t stream, S1AP_S1AP_PDU_t *message_p) { - // S1AP_DeactivateTraceIEs_t *deactivate_trace_p; - // - // deactivate_trace_p = &message_p->msg.deactivateTraceIEs; + // S1AP_DeactivateTraceIEs_t *deactivate_trace_p; + // + // deactivate_trace_p = &message_p->msg.deactivateTraceIEs; - return 0; + return 0; } diff --git a/openair3/SCTP/sctp_eNB_task.c b/openair3/SCTP/sctp_eNB_task.c index e7265d66d6485c25e74f5cf128e0a89e932001f8..b0c18c36923b1e9a65e3c548258d8de1de024cb7 100644 --- a/openair3/SCTP/sctp_eNB_task.c +++ b/openair3/SCTP/sctp_eNB_task.c @@ -59,33 +59,33 @@ enum sctp_connection_type_e { - SCTP_TYPE_CLIENT, - SCTP_TYPE_SERVER, - SCTP_TYPE_MULTI_SERVER, - SCTP_TYPE_MAX + SCTP_TYPE_CLIENT, + SCTP_TYPE_SERVER, + SCTP_TYPE_MULTI_SERVER, + SCTP_TYPE_MAX }; typedef struct sctp_cnx_list_elm_s { - STAILQ_ENTRY(sctp_cnx_list_elm_s) entries; - - /* Type of this association - */ - enum sctp_connection_type_e connection_type; - - int sd; ///< Socket descriptor of connection */ - uint16_t local_port; - uint16_t in_streams; ///< Number of input streams negociated for this connection - uint16_t out_streams; ///< Number of output streams negotiated for this connection - uint16_t ppid; ///< Payload protocol Identifier - int32_t assoc_id; ///< SCTP association id for the connection (note4debug host byte order) - uint32_t messages_recv; ///< Number of messages received on this connection - uint32_t messages_sent; ///< Number of messages sent on this connection - task_id_t task_id; ///< Task id of the task who asked for this connection - instance_t instance; ///< Instance - uint16_t cnx_id; ///< Upper layer identifier - - struct sockaddr *peer_addresses;///< A list of peer addresses for server socket - int nb_peer_addresses; ///< For server socket + STAILQ_ENTRY(sctp_cnx_list_elm_s) entries; + + /* Type of this association + */ + enum sctp_connection_type_e connection_type; + + int sd; ///< Socket descriptor of connection */ + uint16_t local_port; + uint16_t in_streams; ///< Number of input streams negociated for this connection + uint16_t out_streams; ///< Number of output streams negotiated for this connection + uint16_t ppid; ///< Payload protocol Identifier + int32_t assoc_id; ///< SCTP association id for the connection (note4debug host byte order) + uint32_t messages_recv; ///< Number of messages received on this connection + uint32_t messages_sent; ///< Number of messages sent on this connection + task_id_t task_id; ///< Task id of the task who asked for this connection + instance_t instance; ///< Instance + uint16_t cnx_id; ///< Upper layer identifier + + struct sockaddr *peer_addresses;///< A list of peer addresses for server socket + int nb_peer_addresses; ///< For server socket } sctp_cnx_list_elm_t; @@ -95,962 +95,965 @@ static uint16_t sctp_nb_cnx = 0; //------------------------------------------------------------------------------ struct sctp_cnx_list_elm_s *sctp_get_cnx(int32_t assoc_id, int sd) { - struct sctp_cnx_list_elm_s *elm; + struct sctp_cnx_list_elm_s *elm; - STAILQ_FOREACH(elm, &sctp_cnx_list, entries) { - if (assoc_id != -1) { - if (elm->assoc_id == assoc_id) { - return elm; - } - } else { - if (elm->sd == sd) { - return elm; - } + STAILQ_FOREACH(elm, &sctp_cnx_list, entries) { + if (assoc_id != -1) { + if (elm->assoc_id == assoc_id) { + return elm; + } + } else { + if (elm->sd == sd) { + return elm; + } + } } - } - return NULL; + return NULL; } //------------------------------------------------------------------------------ static inline void sctp_eNB_accept_associations_multi( - struct sctp_cnx_list_elm_s *sctp_cnx) + struct sctp_cnx_list_elm_s *sctp_cnx) { - int ns; - int n; - int flags = 0; - socklen_t from_len; - struct sctp_sndrcvinfo sinfo; + int ns; + int n; + int flags = 0; + socklen_t from_len; + struct sctp_sndrcvinfo sinfo; - struct sockaddr_in addr; - uint8_t buffer[SCTP_RECV_BUFFER_SIZE]; + struct sockaddr_in addr; + uint8_t buffer[SCTP_RECV_BUFFER_SIZE]; - DevAssert(sctp_cnx != NULL); + DevAssert(sctp_cnx != NULL); - memset((void *)&addr, 0, sizeof(struct sockaddr_in)); - from_len = (socklen_t)sizeof(struct sockaddr_in); - memset((void *)&sinfo, 0, sizeof(struct sctp_sndrcvinfo)); + memset((void *)&addr, 0, sizeof(struct sockaddr_in)); + from_len = (socklen_t)sizeof(struct sockaddr_in); + memset((void *)&sinfo, 0, sizeof(struct sctp_sndrcvinfo)); - n = sctp_recvmsg(sctp_cnx->sd, (void *)buffer, SCTP_RECV_BUFFER_SIZE, - (struct sockaddr *)&addr, &from_len, - &sinfo, &flags); + n = sctp_recvmsg(sctp_cnx->sd, (void *)buffer, SCTP_RECV_BUFFER_SIZE, + (struct sockaddr *)&addr, &from_len, + &sinfo, &flags); - if (n < 0) { - if (errno == ENOTCONN) { - SCTP_DEBUG("Received not connected for sd %d\n", sctp_cnx->sd); - close(sctp_cnx->sd); - } else { - SCTP_DEBUG("An error occured during read\n"); - SCTP_ERROR("sctp_recvmsg (fd %d, len %d ): %s:%d\n", sctp_cnx->sd, n, strerror(errno), errno); + if (n < 0) { + if (errno == ENOTCONN) { + SCTP_DEBUG("Received not connected for sd %d\n", sctp_cnx->sd); + close(sctp_cnx->sd); + } else { + SCTP_DEBUG("An error occured during read\n"); + SCTP_ERROR("sctp_recvmsg (fd %d, len %d ): %s:%d\n", sctp_cnx->sd, n, strerror(errno), errno); + } + return; } - return; - } - if (flags & MSG_NOTIFICATION) { - union sctp_notification *snp; - snp = (union sctp_notification *)buffer; + if (flags & MSG_NOTIFICATION) { + union sctp_notification *snp; + snp = (union sctp_notification *)buffer; - SCTP_DEBUG("Received notification for sd %d, type %u\n", - sctp_cnx->sd, snp->sn_header.sn_type); + SCTP_DEBUG("Received notification for sd %d, type %u\n", + sctp_cnx->sd, snp->sn_header.sn_type); - /* Association has changed. */ - if (SCTP_ASSOC_CHANGE == snp->sn_header.sn_type) { - struct sctp_assoc_change *sctp_assoc_changed; - sctp_assoc_changed = &snp->sn_assoc_change; + /* Association has changed. */ + if (SCTP_ASSOC_CHANGE == snp->sn_header.sn_type) { + struct sctp_assoc_change *sctp_assoc_changed; + sctp_assoc_changed = &snp->sn_assoc_change; - SCTP_DEBUG("Client association changed: %d\n", sctp_assoc_changed->sac_state); + SCTP_DEBUG("Client association changed: %d\n", sctp_assoc_changed->sac_state); - /* New physical association requested by a peer */ - switch (sctp_assoc_changed->sac_state) { - case SCTP_COMM_UP: { - SCTP_DEBUG("Comm up notified for sd %d, assigned assoc_id %d\n", - sctp_cnx->sd, sctp_assoc_changed->sac_assoc_id); - struct sctp_cnx_list_elm_s *new_cnx; + /* New physical association requested by a peer */ + switch (sctp_assoc_changed->sac_state) { + case SCTP_COMM_UP: { + SCTP_DEBUG("Comm up notified for sd %d, assigned assoc_id %d\n", + sctp_cnx->sd, sctp_assoc_changed->sac_assoc_id); + struct sctp_cnx_list_elm_s *new_cnx; - new_cnx = calloc(1, sizeof(*sctp_cnx)); + new_cnx = calloc(1, sizeof(*sctp_cnx)); - DevAssert(new_cnx != NULL); + DevAssert(new_cnx != NULL); - new_cnx->connection_type = SCTP_TYPE_CLIENT; + new_cnx->connection_type = SCTP_TYPE_CLIENT; - ns = sctp_peeloff(sctp_cnx->sd, sctp_assoc_changed->sac_assoc_id); + ns = sctp_peeloff(sctp_cnx->sd, sctp_assoc_changed->sac_assoc_id); - new_cnx->sd = ns; - new_cnx->task_id = sctp_cnx->task_id; - new_cnx->cnx_id = 0; - new_cnx->ppid = sctp_cnx->ppid; - new_cnx->instance = sctp_cnx->instance; - new_cnx->local_port = sctp_cnx->local_port; - new_cnx->assoc_id = sctp_assoc_changed->sac_assoc_id; + new_cnx->sd = ns; + new_cnx->task_id = sctp_cnx->task_id; + new_cnx->cnx_id = 0; + new_cnx->ppid = sctp_cnx->ppid; + new_cnx->instance = sctp_cnx->instance; + new_cnx->local_port = sctp_cnx->local_port; + new_cnx->assoc_id = sctp_assoc_changed->sac_assoc_id; - if (sctp_get_sockinfo(ns, &new_cnx->in_streams, &new_cnx->out_streams, - &new_cnx->assoc_id) != 0) { - SCTP_ERROR("sctp_get_sockinfo failed\n"); - close(ns); - free(new_cnx); - return; - } + if (sctp_get_sockinfo(ns, &new_cnx->in_streams, &new_cnx->out_streams, + &new_cnx->assoc_id) != 0) { + SCTP_ERROR("sctp_get_sockinfo failed\n"); + close(ns); + free(new_cnx); + return; + } - /* Insert new element at end of list */ - STAILQ_INSERT_TAIL(&sctp_cnx_list, new_cnx, entries); - sctp_nb_cnx++; + /* Insert new element at end of list */ + STAILQ_INSERT_TAIL(&sctp_cnx_list, new_cnx, entries); + sctp_nb_cnx++; - /* Add the socket to list of fd monitored by ITTI */ - itti_subscribe_event_fd(TASK_SCTP, ns); + /* Add the socket to list of fd monitored by ITTI */ + itti_subscribe_event_fd(TASK_SCTP, ns); - sctp_itti_send_association_ind(new_cnx->task_id, new_cnx->instance, - new_cnx->assoc_id, new_cnx->local_port, - new_cnx->out_streams, new_cnx->in_streams); - } - break; + sctp_itti_send_association_ind(new_cnx->task_id, new_cnx->instance, + new_cnx->assoc_id, new_cnx->local_port, + new_cnx->out_streams, new_cnx->in_streams); + } + break; - default: - break; - } + default: + break; + } + } + } else { + SCTP_DEBUG("No notification from SCTP\n"); } - } else { - SCTP_DEBUG("No notification from SCTP\n"); - } } //------------------------------------------------------------------------------ void sctp_handle_new_association_req_multi( - const instance_t instance, - const task_id_t requestor, - const sctp_new_association_req_multi_t * const sctp_new_association_req_p) + const instance_t instance, + const task_id_t requestor, + const sctp_new_association_req_multi_t * const sctp_new_association_req_p) { - int ns; - int sd; + int ns; + int sd; - int32_t assoc_id = 0; + int32_t assoc_id = 0; - struct sctp_cnx_list_elm_s *sctp_cnx = NULL; - enum sctp_connection_type_e connection_type = SCTP_TYPE_CLIENT; + struct sctp_cnx_list_elm_s *sctp_cnx = NULL; + enum sctp_connection_type_e connection_type = SCTP_TYPE_CLIENT; - /* Prepare a new SCTP association as requested by upper layer and try to connect - * to remote host. - */ - DevAssert(sctp_new_association_req_p != NULL); + /* Prepare a new SCTP association as requested by upper layer and try to connect + * to remote host. + */ + DevAssert(sctp_new_association_req_p != NULL); - sd = sctp_new_association_req_p->multi_sd; + sd = sctp_new_association_req_p->multi_sd; - /* Create new socket with IPv6 affinity */ + /* Create new socket with IPv6 affinity */ //#warning "SCTP may Force IPv4 only, here" - /* Mark the socket as non-blocking */ - //if (fcntl(sd, F_SETFL, O_NONBLOCK) < 0) { + /* Mark the socket as non-blocking */ + //if (fcntl(sd, F_SETFL, O_NONBLOCK) < 0) { //SCTP_ERROR("fcntl F_SETFL O_NONBLOCK failed: %s\n", - // strerror(errno)); + // strerror(errno)); //close(sd); //return; - //} - - /* SOCK_STREAM socket type requires an explicit connect to the remote host - * address and port. - * Only use IPv4 for the first connection attempt - */ - if ((sctp_new_association_req_p->remote_address.ipv6 != 0) || - (sctp_new_association_req_p->remote_address.ipv4 != 0)) { - uint8_t address_index = 0; - uint8_t used_address = sctp_new_association_req_p->remote_address.ipv6 + - sctp_new_association_req_p->remote_address.ipv4; - struct sockaddr_in addr[used_address]; - - memset(addr, 0, used_address * sizeof(struct sockaddr_in)); - - if (sctp_new_association_req_p->remote_address.ipv6 == 1) { - if (inet_pton(AF_INET6, sctp_new_association_req_p->remote_address.ipv6_address, - &addr[address_index].sin_addr.s_addr) != 1) { - SCTP_ERROR("Failed to convert ipv6 address %*s to network type\n", - (int)strlen(sctp_new_association_req_p->remote_address.ipv6_address), - sctp_new_association_req_p->remote_address.ipv6_address); - //close(sd); - //return; - exit(1); - } - - SCTP_DEBUG("Converted ipv6 address %*s to network type\n", - (int)strlen(sctp_new_association_req_p->remote_address.ipv6_address), - sctp_new_association_req_p->remote_address.ipv6_address); - - addr[address_index].sin_family = AF_INET6; - addr[address_index].sin_port = htons(sctp_new_association_req_p->port); - address_index++; - } + //} - if (sctp_new_association_req_p->remote_address.ipv4 == 1) { - if (inet_pton(AF_INET, sctp_new_association_req_p->remote_address.ipv4_address, - &addr[address_index].sin_addr.s_addr) != 1) { - SCTP_ERROR("Failed to convert ipv4 address %*s to network type\n", - (int)strlen(sctp_new_association_req_p->remote_address.ipv4_address), - sctp_new_association_req_p->remote_address.ipv4_address); - //close(sd); - //return; - exit(1); - } - - SCTP_DEBUG("Converted ipv4 address %*s to network type\n", - (int)strlen(sctp_new_association_req_p->remote_address.ipv4_address), - sctp_new_association_req_p->remote_address.ipv4_address); - - addr[address_index].sin_family = AF_INET; - addr[address_index].sin_port = htons(sctp_new_association_req_p->port); - address_index++; - } + /* SOCK_STREAM socket type requires an explicit connect to the remote host + * address and port. + * Only use IPv4 for the first connection attempt + */ + if ((sctp_new_association_req_p->remote_address.ipv6 != 0) || + (sctp_new_association_req_p->remote_address.ipv4 != 0)) { + uint8_t address_index = 0; + uint8_t used_address = sctp_new_association_req_p->remote_address.ipv6 + + sctp_new_association_req_p->remote_address.ipv4; + struct sockaddr_in addr[used_address]; + + memset(addr, 0, used_address * sizeof(struct sockaddr_in)); + + if (sctp_new_association_req_p->remote_address.ipv6 == 1) { + if (inet_pton(AF_INET6, sctp_new_association_req_p->remote_address.ipv6_address, + &addr[address_index].sin_addr.s_addr) != 1) { + SCTP_ERROR("Failed to convert ipv6 address %*s to network type\n", + (int)strlen(sctp_new_association_req_p->remote_address.ipv6_address), + sctp_new_association_req_p->remote_address.ipv6_address); + //close(sd); + //return; + exit(1); + } + + SCTP_DEBUG("Converted ipv6 address %*s to network type\n", + (int)strlen(sctp_new_association_req_p->remote_address.ipv6_address), + sctp_new_association_req_p->remote_address.ipv6_address); + + addr[address_index].sin_family = AF_INET6; + addr[address_index].sin_port = htons(sctp_new_association_req_p->port); + address_index++; + } - /* Connect to remote host and port */ - if (sctp_connectx(sd, (struct sockaddr *)addr, 1, &assoc_id) < 0) { - /* sctp_connectx on non-blocking socket return EINPROGRESS */ - if (errno != EINPROGRESS) { - SCTP_ERROR("Connect failed: %s\n", strerror(errno)); - sctp_itti_send_association_resp( - requestor, instance, -1, sctp_new_association_req_p->ulp_cnx_id, - SCTP_STATE_UNREACHABLE, 0, 0); - /* Add the socket to list of fd monitored by ITTI */ - //itti_unsubscribe_event_fd(TASK_SCTP, sd); - //close(sd); - return; - } else { - SCTP_DEBUG("connectx assoc_id %d in progress..., used %d addresses\n", - assoc_id, used_address); - } - } else { - SCTP_DEBUG("sctp_connectx SUCCESS, used %d addresses assoc_id %d\n", - used_address, - assoc_id); + if (sctp_new_association_req_p->remote_address.ipv4 == 1) { + if (inet_pton(AF_INET, sctp_new_association_req_p->remote_address.ipv4_address, + &addr[address_index].sin_addr.s_addr) != 1) { + SCTP_ERROR("Failed to convert ipv4 address %*s to network type\n", + (int)strlen(sctp_new_association_req_p->remote_address.ipv4_address), + sctp_new_association_req_p->remote_address.ipv4_address); + //close(sd); + //return; + exit(1); + } + + SCTP_DEBUG("Converted ipv4 address %*s to network type\n", + (int)strlen(sctp_new_association_req_p->remote_address.ipv4_address), + sctp_new_association_req_p->remote_address.ipv4_address); + + addr[address_index].sin_family = AF_INET; + addr[address_index].sin_port = htons(sctp_new_association_req_p->port); + address_index++; + } + + /* Connect to remote host and port */ + if (sctp_connectx(sd, (struct sockaddr *)addr, 1, &assoc_id) < 0) { + /* sctp_connectx on non-blocking socket return EINPROGRESS */ + if (errno != EINPROGRESS) { + SCTP_ERROR("Connect failed: %s\n", strerror(errno)); + sctp_itti_send_association_resp( + requestor, instance, -1, sctp_new_association_req_p->ulp_cnx_id, + SCTP_STATE_UNREACHABLE, 0, 0); + /* Add the socket to list of fd monitored by ITTI */ + //itti_unsubscribe_event_fd(TASK_SCTP, sd); + //close(sd); + return; + } else { + SCTP_DEBUG("connectx assoc_id %d in progress..., used %d addresses\n", + assoc_id, used_address); + } + } else { + SCTP_DEBUG("sctp_connectx SUCCESS, used %d addresses assoc_id %d\n", + used_address, + assoc_id); + } } - } - ns = sctp_peeloff(sd,assoc_id); + ns = sctp_peeloff(sd,assoc_id); - sctp_cnx = calloc(1, sizeof(*sctp_cnx)); + sctp_cnx = calloc(1, sizeof(*sctp_cnx)); - sctp_cnx->connection_type = connection_type; + sctp_cnx->connection_type = connection_type; - sctp_cnx->sd = ns; - sctp_cnx->task_id = requestor; - sctp_cnx->cnx_id = sctp_new_association_req_p->ulp_cnx_id; - sctp_cnx->ppid = sctp_new_association_req_p->ppid; - sctp_cnx->instance = instance; - sctp_cnx->assoc_id = assoc_id; + sctp_cnx->sd = ns; + sctp_cnx->task_id = requestor; + sctp_cnx->cnx_id = sctp_new_association_req_p->ulp_cnx_id; + sctp_cnx->ppid = sctp_new_association_req_p->ppid; + sctp_cnx->instance = instance; + sctp_cnx->assoc_id = assoc_id; - /* Add the socket to list of fd monitored by ITTI */ - itti_subscribe_event_fd(TASK_SCTP, ns); + /* Add the socket to list of fd monitored by ITTI */ + itti_subscribe_event_fd(TASK_SCTP, ns); - /* Insert new element at end of list */ - STAILQ_INSERT_TAIL(&sctp_cnx_list, sctp_cnx, entries); - sctp_nb_cnx++; + /* Insert new element at end of list */ + STAILQ_INSERT_TAIL(&sctp_cnx_list, sctp_cnx, entries); + sctp_nb_cnx++; - SCTP_DEBUG("Inserted new descriptor for sd %d in list, nb elements %u, assoc_id %d\n", - ns, sctp_nb_cnx, assoc_id); + SCTP_DEBUG("Inserted new descriptor for sd %d in list, nb elements %u, assoc_id %d\n", + ns, sctp_nb_cnx, assoc_id); } //------------------------------------------------------------------------------ void sctp_handle_new_association_req( - const instance_t instance, - const task_id_t requestor, - const sctp_new_association_req_t * const sctp_new_association_req_p) + const instance_t instance, + const task_id_t requestor, + const sctp_new_association_req_t * const sctp_new_association_req_p) { - int sd = 0; - int32_t assoc_id = 0; - - struct sctp_event_subscribe events; - - struct sctp_cnx_list_elm_s *sctp_cnx = NULL; - enum sctp_connection_type_e connection_type = SCTP_TYPE_CLIENT; - - struct ifreq ifr; - struct ifaddrs *ifaddr = NULL; - struct ifaddrs *ifa = NULL; - int family = 0; - int s = 0; - struct in_addr in; - struct in6_addr in6; - /* Prepare a new SCTP association as requested by upper layer and try to connect - * to remote host. - */ - DevAssert(sctp_new_association_req_p != NULL); - - /* Create new socket with IPv6 affinity */ + int sd = 0; + int32_t assoc_id = 0; + + struct sctp_event_subscribe events; + + struct sctp_cnx_list_elm_s *sctp_cnx = NULL; + enum sctp_connection_type_e connection_type = SCTP_TYPE_CLIENT; + + struct ifreq ifr; + struct ifaddrs *ifaddr = NULL; + struct ifaddrs *ifa = NULL; + int family = 0; + int s = 0; + struct in_addr in; + struct in6_addr in6; + /* Prepare a new SCTP association as requested by upper layer and try to connect + * to remote host. + */ + DevAssert(sctp_new_association_req_p != NULL); + + /* Create new socket with IPv6 affinity */ //#warning "SCTP may Force IPv4 only, here" #ifdef NO_VIRTUAL_MACHINE - // in init chunk appears a list of host addresses, IPv4 and IPv4 in an arbitrary (unsorted) order - // SCTP hearbeats starts with first ipv4 addresses then stop triyng with other ipv4 addresses - // if it encounters an IPv6 address in list, so we can force the building of IPv4 addresses only - // with AF_INET (the working IPv4 address can be the last in the list...) - if ((sd = socket(AF_INET6, SOCK_STREAM, IPPROTO_SCTP)) < 0) { + // in init chunk appears a list of host addresses, IPv4 and IPv4 in an arbitrary (unsorted) order + // SCTP hearbeats starts with first ipv4 addresses then stop triyng with other ipv4 addresses + // if it encounters an IPv6 address in list, so we can force the building of IPv4 addresses only + // with AF_INET (the working IPv4 address can be the last in the list...) + if ((sd = socket(AF_INET6, SOCK_STREAM, IPPROTO_SCTP)) < 0) { #else - if ((sd = socket(AF_INET, SOCK_STREAM, IPPROTO_SCTP)) < 0) { + if ((sd = socket(AF_INET, SOCK_STREAM, IPPROTO_SCTP)) < 0) { #endif - SCTP_ERROR("Socket creation failed: %s\n", strerror(errno)); - return; - } - - /* Add the socket to list of fd monitored by ITTI */ - itti_subscribe_event_fd(TASK_SCTP, sd); - - if (sctp_set_init_opt(sd, - sctp_new_association_req_p->in_streams, - sctp_new_association_req_p->out_streams, - SCTP_MAX_ATTEMPTS, SCTP_TIMEOUT) != 0) { - SCTP_ERROR("Setsockopt IPPROTO_SCTP_INITMSG failed: %s\n", - strerror(errno)); - itti_unsubscribe_event_fd(TASK_SCTP, sd); - close(sd); - return; - } - - /* Subscribe to all events */ - memset((void *)&events, 1, sizeof(struct sctp_event_subscribe)); - - if (setsockopt(sd, IPPROTO_SCTP, SCTP_EVENTS, &events, - sizeof(struct sctp_event_subscribe)) < 0) { - SCTP_ERROR("Setsockopt IPPROTO_SCTP_EVENTS failed: %s\n", - strerror(errno)); - close(sd); - return; - } - - // Bind to device ... or we could bind to address also - if (getifaddrs(&ifaddr) == -1) { - SCTP_ERROR("getifaddrs failed: %s\n", strerror(errno)); - close(sd); - } - - /* Walk through linked list, maintaining head pointer so we - can free list later */ - for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) { - if (ifa->ifa_addr == NULL) - continue; - - family = ifa->ifa_addr->sa_family; - - /* For an AF_INET* interface address, display the address */ - if (sctp_new_association_req_p->local_address.ipv4 && family == AF_INET) { - // compare address - s = inet_aton(sctp_new_association_req_p->local_address.ipv4_address, - &in); - - if (s > 0 ) { - if (((struct sockaddr_in*)ifa->ifa_addr)->sin_addr.s_addr == in.s_addr) { - struct sockaddr_in locaddr; - locaddr.sin_family = AF_INET; - locaddr.sin_port = htons(sctp_new_association_req_p->port); - locaddr.sin_addr.s_addr = in.s_addr; - - if (sctp_bindx(sd, (struct sockaddr*)&locaddr, 1, SCTP_BINDX_ADD_ADDR) < 0) { - SCTP_ERROR("sctp_bindx SCTP_BINDX_ADD_ADDR failed: %s\n", - strerror(errno)); - } else { - SCTP_DEBUG("sctp_bindx SCTP_BINDX_ADD_ADDR socket bound to : %s\n", - inet_ntoa(locaddr.sin_addr)); - } - break; - - } - } - } else if (sctp_new_association_req_p->local_address.ipv6 && family == AF_INET6) { - // compare address - s = inet_pton(AF_INET6, - sctp_new_association_req_p->local_address.ipv6_address, - &in6); - - if (s == 1 ) { - if (memcmp(&((struct sockaddr_in6*)ifa->ifa_addr)->sin6_addr, - &in6, sizeof(in6)) == 0) { - memset(&ifr, 0, sizeof(ifr)); - snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "%s", ifa->ifa_name); - - if (setsockopt(sd, SOL_SOCKET, SO_BINDTODEVICE, (void *)&ifr, sizeof(ifr)) < 0) { - SCTP_ERROR("Setsockopt SOL_SOCKET failed: %s\n", - strerror(errno)); - } else { - SCTP_DEBUG("Setsockopt SOL_SOCKET socket bound to : %s\n", - ifa->ifa_name); - } - - break; - } - } + SCTP_ERROR("Socket creation failed: %s\n", strerror(errno)); + return; } - } - - freeifaddrs(ifaddr); - - /* Mark the socket as non-blocking */ - if (fcntl(sd, F_SETFL, O_NONBLOCK) < 0) { - SCTP_ERROR("fcntl F_SETFL O_NONBLOCK failed: %s\n", - strerror(errno)); - close(sd); - return; - } - - /* SOCK_STREAM socket type requires an explicit connect to the remote host - * address and port. - * Only use IPv4 for the first connection attempt - */ - if ((sctp_new_association_req_p->remote_address.ipv6 != 0) || - (sctp_new_association_req_p->remote_address.ipv4 != 0)) { - uint8_t address_index = 0; - uint8_t used_address = sctp_new_association_req_p->remote_address.ipv6 + - sctp_new_association_req_p->remote_address.ipv4; - struct sockaddr_in addr[used_address]; - - memset(addr, 0, used_address * sizeof(struct sockaddr_in)); - - if (sctp_new_association_req_p->remote_address.ipv6 == 1) { - if (inet_pton(AF_INET6, sctp_new_association_req_p->remote_address.ipv6_address, - &addr[address_index].sin_addr.s_addr) != 1) { - SCTP_ERROR("Failed to convert ipv6 address %*s to network type\n", - (int)strlen(sctp_new_association_req_p->remote_address.ipv6_address), - sctp_new_association_req_p->remote_address.ipv6_address); + + /* Add the socket to list of fd monitored by ITTI */ + itti_subscribe_event_fd(TASK_SCTP, sd); + + if (sctp_set_init_opt(sd, + sctp_new_association_req_p->in_streams, + sctp_new_association_req_p->out_streams, + SCTP_MAX_ATTEMPTS, SCTP_TIMEOUT) != 0) { + SCTP_ERROR("Setsockopt IPPROTO_SCTP_INITMSG failed: %s\n", + strerror(errno)); + itti_unsubscribe_event_fd(TASK_SCTP, sd); close(sd); return; - } - - SCTP_DEBUG("Converted ipv6 address %*s to network type\n", - (int)strlen(sctp_new_association_req_p->remote_address.ipv6_address), - sctp_new_association_req_p->remote_address.ipv6_address); - - addr[address_index].sin_family = AF_INET6; - addr[address_index].sin_port = htons(sctp_new_association_req_p->port); - address_index++; } - if (sctp_new_association_req_p->remote_address.ipv4 == 1) { - if (inet_pton(AF_INET, sctp_new_association_req_p->remote_address.ipv4_address, - &addr[address_index].sin_addr.s_addr) != 1) { - SCTP_ERROR("Failed to convert ipv4 address %*s to network type\n", - (int)strlen(sctp_new_association_req_p->remote_address.ipv4_address), - sctp_new_association_req_p->remote_address.ipv4_address); + /* Subscribe to all events */ + memset((void *)&events, 1, sizeof(struct sctp_event_subscribe)); + + if (setsockopt(sd, IPPROTO_SCTP, SCTP_EVENTS, &events, + sizeof(struct sctp_event_subscribe)) < 0) { + SCTP_ERROR("Setsockopt IPPROTO_SCTP_EVENTS failed: %s\n", + strerror(errno)); close(sd); return; - } + } - SCTP_DEBUG("Converted ipv4 address %*s to network type\n", - (int)strlen(sctp_new_association_req_p->remote_address.ipv4_address), - sctp_new_association_req_p->remote_address.ipv4_address); + // Bind to device ... or we could bind to address also + if (getifaddrs(&ifaddr) == -1) { + SCTP_ERROR("getifaddrs failed: %s\n", strerror(errno)); + close(sd); + } - addr[address_index].sin_family = AF_INET; - addr[address_index].sin_port = htons(sctp_new_association_req_p->port); - address_index++; + /* Walk through linked list, maintaining head pointer so we + can free list later */ + for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) { + if (ifa->ifa_addr == NULL) + continue; + + family = ifa->ifa_addr->sa_family; + + /* For an AF_INET* interface address, display the address */ + if (sctp_new_association_req_p->local_address.ipv4 && family == AF_INET) { + // compare address + s = inet_aton(sctp_new_association_req_p->local_address.ipv4_address, + &in); + + if (s > 0 ) { + if (((struct sockaddr_in*)ifa->ifa_addr)->sin_addr.s_addr == in.s_addr) { + struct sockaddr_in locaddr; + locaddr.sin_family = AF_INET; + locaddr.sin_port = htons(sctp_new_association_req_p->port); + locaddr.sin_addr.s_addr = in.s_addr; + + if (sctp_bindx(sd, (struct sockaddr*)&locaddr, 1, SCTP_BINDX_ADD_ADDR) < 0) { + SCTP_ERROR("sctp_bindx SCTP_BINDX_ADD_ADDR failed: %s\n", + strerror(errno)); + } else { + SCTP_DEBUG("sctp_bindx SCTP_BINDX_ADD_ADDR socket bound to : %s\n", + inet_ntoa(locaddr.sin_addr)); + } + break; + + } + } + } else if (sctp_new_association_req_p->local_address.ipv6 && family == AF_INET6) { + // compare address + s = inet_pton(AF_INET6, + sctp_new_association_req_p->local_address.ipv6_address, + &in6); + + if (s == 1 ) { + if (memcmp(&((struct sockaddr_in6*)ifa->ifa_addr)->sin6_addr, + &in6, sizeof(in6)) == 0) { + memset(&ifr, 0, sizeof(ifr)); + snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "%s", ifa->ifa_name); + + if (setsockopt(sd, SOL_SOCKET, SO_BINDTODEVICE, (void *)&ifr, sizeof(ifr)) < 0) { + SCTP_ERROR("Setsockopt SOL_SOCKET failed: %s\n", + strerror(errno)); + } else { + SCTP_DEBUG("Setsockopt SOL_SOCKET socket bound to : %s\n", + ifa->ifa_name); + } + + break; + } + } + } } - /* Connect to remote host and port */ - if (sctp_connectx(sd, (struct sockaddr *)addr, 1, &assoc_id) < 0) { - /* sctp_connectx on non-blocking socket return EINPROGRESS */ - if (errno != EINPROGRESS) { - SCTP_ERROR("Connect failed: %s\n", strerror(errno)); - sctp_itti_send_association_resp( - requestor, instance, -1, sctp_new_association_req_p->ulp_cnx_id, - SCTP_STATE_UNREACHABLE, 0, 0); - /* Add the socket to list of fd monitored by ITTI */ - itti_unsubscribe_event_fd(TASK_SCTP, sd); + freeifaddrs(ifaddr); + + /* Mark the socket as non-blocking */ + if (fcntl(sd, F_SETFL, O_NONBLOCK) < 0) { + SCTP_ERROR("fcntl F_SETFL O_NONBLOCK failed: %s\n", + strerror(errno)); close(sd); return; - } else { - SCTP_DEBUG("connectx assoc_id %d in progress..., used %d addresses\n", - assoc_id, used_address); - } - } else { - SCTP_DEBUG("sctp_connectx SUCCESS, used %d addresses assoc_id %d\n", - used_address, - assoc_id); } - } else { - /* No remote address provided -> only bind the socket for now. - * Connection will be accepted in the main event loop + + /* SOCK_STREAM socket type requires an explicit connect to the remote host + * address and port. + * Only use IPv4 for the first connection attempt */ - struct sockaddr_in6 addr6; + if ((sctp_new_association_req_p->remote_address.ipv6 != 0) || + (sctp_new_association_req_p->remote_address.ipv4 != 0)) { + uint8_t address_index = 0; + uint8_t used_address = sctp_new_association_req_p->remote_address.ipv6 + + sctp_new_association_req_p->remote_address.ipv4; + struct sockaddr_in addr[used_address]; + + memset(addr, 0, used_address * sizeof(struct sockaddr_in)); + + if (sctp_new_association_req_p->remote_address.ipv6 == 1) { + if (inet_pton(AF_INET6, sctp_new_association_req_p->remote_address.ipv6_address, + &addr[address_index].sin_addr.s_addr) != 1) { + SCTP_ERROR("Failed to convert ipv6 address %*s to network type\n", + (int)strlen(sctp_new_association_req_p->remote_address.ipv6_address), + sctp_new_association_req_p->remote_address.ipv6_address); + close(sd); + return; + } + + SCTP_DEBUG("Converted ipv6 address %*s to network type\n", + (int)strlen(sctp_new_association_req_p->remote_address.ipv6_address), + sctp_new_association_req_p->remote_address.ipv6_address); + + addr[address_index].sin_family = AF_INET6; + addr[address_index].sin_port = htons(sctp_new_association_req_p->port); + address_index++; + } - connection_type = SCTP_TYPE_SERVER; + if (sctp_new_association_req_p->remote_address.ipv4 == 1) { + if (inet_pton(AF_INET, sctp_new_association_req_p->remote_address.ipv4_address, + &addr[address_index].sin_addr.s_addr) != 1) { + SCTP_ERROR("Failed to convert ipv4 address %*s to network type\n", + (int)strlen(sctp_new_association_req_p->remote_address.ipv4_address), + sctp_new_association_req_p->remote_address.ipv4_address); + close(sd); + return; + } + + SCTP_DEBUG("Converted ipv4 address %*s to network type\n", + (int)strlen(sctp_new_association_req_p->remote_address.ipv4_address), + sctp_new_association_req_p->remote_address.ipv4_address); + + addr[address_index].sin_family = AF_INET; + addr[address_index].sin_port = htons(sctp_new_association_req_p->port); + address_index++; + } - /* For now bind to any interface */ - addr6.sin6_family = AF_INET6; - addr6.sin6_addr = in6addr_any; - addr6.sin6_port = htons(sctp_new_association_req_p->port); + /* Connect to remote host and port */ + if (sctp_connectx(sd, (struct sockaddr *)addr, 1, &assoc_id) < 0) { + /* sctp_connectx on non-blocking socket return EINPROGRESS */ + if (errno != EINPROGRESS) { + SCTP_ERROR("Connect failed: %s\n", strerror(errno)); + sctp_itti_send_association_resp( + requestor, instance, -1, sctp_new_association_req_p->ulp_cnx_id, + SCTP_STATE_UNREACHABLE, 0, 0); + /* Add the socket to list of fd monitored by ITTI */ + itti_unsubscribe_event_fd(TASK_SCTP, sd); + close(sd); + return; + } else { + SCTP_DEBUG("connectx assoc_id %d in progress..., used %d addresses\n", + assoc_id, used_address); + } + } else { + SCTP_DEBUG("sctp_connectx SUCCESS, used %d addresses assoc_id %d\n", + used_address, + assoc_id); + } + } else { + /* No remote address provided -> only bind the socket for now. + * Connection will be accepted in the main event loop + */ + struct sockaddr_in6 addr6; - if (bind(sd, (struct sockaddr*)&addr6, sizeof(addr6)) < 0) { - SCTP_ERROR("Failed to bind the socket to address any (v4/v6): %s\n", - strerror(errno)); - close(sd); - return; + connection_type = SCTP_TYPE_SERVER; + + /* For now bind to any interface */ + addr6.sin6_family = AF_INET6; + addr6.sin6_addr = in6addr_any; + addr6.sin6_port = htons(sctp_new_association_req_p->port); + + if (bind(sd, (struct sockaddr*)&addr6, sizeof(addr6)) < 0) { + SCTP_ERROR("Failed to bind the socket to address any (v4/v6): %s\n", + strerror(errno)); + close(sd); + return; + } } - } - sctp_cnx = calloc(1, sizeof(*sctp_cnx)); + sctp_cnx = calloc(1, sizeof(*sctp_cnx)); - sctp_cnx->connection_type = connection_type; + sctp_cnx->connection_type = connection_type; - sctp_cnx->sd = sd; - sctp_cnx->task_id = requestor; - sctp_cnx->cnx_id = sctp_new_association_req_p->ulp_cnx_id; - sctp_cnx->ppid = sctp_new_association_req_p->ppid; - sctp_cnx->instance = instance; - sctp_cnx->assoc_id = assoc_id; + sctp_cnx->sd = sd; + sctp_cnx->task_id = requestor; + sctp_cnx->cnx_id = sctp_new_association_req_p->ulp_cnx_id; + sctp_cnx->ppid = sctp_new_association_req_p->ppid; + sctp_cnx->instance = instance; + sctp_cnx->assoc_id = assoc_id; - /* Insert new element at end of list */ - STAILQ_INSERT_TAIL(&sctp_cnx_list, sctp_cnx, entries); - sctp_nb_cnx++; + /* Insert new element at end of list */ + STAILQ_INSERT_TAIL(&sctp_cnx_list, sctp_cnx, entries); + sctp_nb_cnx++; - SCTP_DEBUG("Inserted new descriptor for sd %d in list, nb elements %u, assoc_id %d\n", - sd, sctp_nb_cnx, assoc_id); + SCTP_DEBUG("Inserted new descriptor for sd %d in list, nb elements %u, assoc_id %d\n", + sd, sctp_nb_cnx, assoc_id); } - //------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ void sctp_send_data( - instance_t instance, - task_id_t task_id, - sctp_data_req_t *sctp_data_req_p) + instance_t instance, + task_id_t task_id, + sctp_data_req_t *sctp_data_req_p) { - struct sctp_cnx_list_elm_s *sctp_cnx = NULL; - - DevAssert(sctp_data_req_p != NULL); - DevAssert(sctp_data_req_p->buffer != NULL); - DevAssert(sctp_data_req_p->buffer_length > 0); - - sctp_cnx = sctp_get_cnx(sctp_data_req_p->assoc_id, 0); - - if (sctp_cnx == NULL) { - SCTP_ERROR("Failed to find SCTP description for assoc_id %d\n", - sctp_data_req_p->assoc_id); - /* TODO: notify upper layer */ - return; - } - - if (sctp_data_req_p->stream >= sctp_cnx->out_streams) { - SCTP_ERROR("Requested stream (%"PRIu16") >= nb out streams (%"PRIu16")\n", - sctp_data_req_p->stream, sctp_cnx->out_streams); - return; - } - - /* Send message on specified stream of the sd association - * NOTE: PPID should be defined in network order - */ - if (sctp_sendmsg(sctp_cnx->sd, sctp_data_req_p->buffer, - sctp_data_req_p->buffer_length, NULL, 0, - htonl(sctp_cnx->ppid), 0, sctp_data_req_p->stream, 0, 0) < 0) { - SCTP_ERROR("Sctp_sendmsg failed: %s\n", strerror(errno)); - /* TODO: notify upper layer */ - return; - } - - SCTP_DEBUG("Successfully sent %u bytes on stream %d for assoc_id %u\n", - sctp_data_req_p->buffer_length, sctp_data_req_p->stream, - sctp_cnx->assoc_id); + struct sctp_cnx_list_elm_s *sctp_cnx = NULL; + + DevAssert(sctp_data_req_p != NULL); + DevAssert(sctp_data_req_p->buffer != NULL); + DevAssert(sctp_data_req_p->buffer_length > 0); + + sctp_cnx = sctp_get_cnx(sctp_data_req_p->assoc_id, 0); + + if (sctp_cnx == NULL) { + SCTP_ERROR("Failed to find SCTP description for assoc_id %d\n", + sctp_data_req_p->assoc_id); + /* TODO: notify upper layer */ + return; + } + + if (sctp_data_req_p->stream >= sctp_cnx->out_streams) { + SCTP_ERROR("Requested stream (%"PRIu16") >= nb out streams (%"PRIu16")\n", + sctp_data_req_p->stream, sctp_cnx->out_streams); + return; + } + + /* Send message on specified stream of the sd association + * NOTE: PPID should be defined in network order + */ + if (sctp_sendmsg(sctp_cnx->sd, sctp_data_req_p->buffer, + sctp_data_req_p->buffer_length, NULL, 0, + htonl(sctp_cnx->ppid), 0, sctp_data_req_p->stream, 0, 0) < 0) { + SCTP_ERROR("Sctp_sendmsg failed: %s\n", strerror(errno)); + /* TODO: notify upper layer */ + return; + } + + SCTP_DEBUG("Successfully sent %u bytes on stream %d for assoc_id %u\n", + sctp_data_req_p->buffer_length, sctp_data_req_p->stream, + sctp_cnx->assoc_id); } //------------------------------------------------------------------------------ static int sctp_close_association( - const instance_t instance, - const task_id_t requestor, - sctp_close_association_t *close_association_p) + const instance_t instance, + const task_id_t requestor, + sctp_close_association_t *close_association_p) { - struct sctp_cnx_list_elm_s *sctp_cnx = NULL; + struct sctp_cnx_list_elm_s *sctp_cnx = NULL; - DevAssert(close_association_p != NULL); - sctp_cnx = sctp_get_cnx(close_association_p->assoc_id, 0); + DevAssert(close_association_p != NULL); + sctp_cnx = sctp_get_cnx(close_association_p->assoc_id, 0); - if (sctp_cnx == NULL) { - SCTP_ERROR("Failed to find SCTP description for assoc_id %d\n", - close_association_p->assoc_id); - /* TODO: notify upper layer */ - return -1; - } else { - close(sctp_cnx->sd); - STAILQ_REMOVE(&sctp_cnx_list, sctp_cnx, sctp_cnx_list_elm_s, entries); - SCTP_DEBUG("Removed assoc_id %u (closed socket %u)\n", - sctp_cnx->assoc_id, sctp_cnx->sd); - } - - return 0; + if (sctp_cnx == NULL) { + SCTP_ERROR("Failed to find SCTP description for assoc_id %d\n", + close_association_p->assoc_id); + /* TODO: notify upper layer */ + return -1; + } else { + close(sctp_cnx->sd); + STAILQ_REMOVE(&sctp_cnx_list, sctp_cnx, sctp_cnx_list_elm_s, entries); + SCTP_DEBUG("Removed assoc_id %u (closed socket %u)\n", + sctp_cnx->assoc_id, (unsigned int)sctp_cnx->sd); + } + + return 0; } //------------------------------------------------------------------------------ static int sctp_create_new_listener( - const instance_t instance, - const task_id_t requestor, - sctp_init_t *init_p, - int server_type) + const instance_t instance, + const task_id_t requestor, + sctp_init_t *init_p, + int server_type) { - struct sctp_event_subscribe event; - struct sockaddr *addr = NULL; - struct sctp_cnx_list_elm_s *sctp_cnx = NULL; - uint16_t i = 0, j = 0; - int sd = 0; - int used_addresses = 0; - - DevAssert(init_p != NULL); - - if (init_p->ipv4 == 0 && init_p->ipv6 == 0) { - SCTP_ERROR("Illegal IP configuration upper layer should request at" - "least ipv4 and/or ipv6 config\n"); - return -1; - } + struct sctp_event_subscribe event; + struct sockaddr *addr = NULL; + struct sctp_cnx_list_elm_s *sctp_cnx = NULL; + uint16_t i = 0, j = 0; + int sd = 0; + int used_addresses = 0; + + DevAssert(init_p != NULL); + + if (init_p->ipv4 == 0 && init_p->ipv6 == 0) { + SCTP_ERROR("Illegal IP configuration upper layer should request at" + "least ipv4 and/or ipv6 config\n"); + return -1; + } - if ((used_addresses = init_p->nb_ipv4_addr + init_p->nb_ipv6_addr) == 0) { - SCTP_WARN("No address provided...\n"); - return -1; - } + if ((used_addresses = init_p->nb_ipv4_addr + init_p->nb_ipv6_addr) == 0) { + SCTP_WARN("No address provided...\n"); + return -1; + } - addr = calloc(used_addresses, sizeof(struct sockaddr)); + addr = calloc(used_addresses, sizeof(struct sockaddr)); - SCTP_DEBUG("Creating new listen socket on port %u with\n", init_p->port); + SCTP_DEBUG("Creating new listen socket on port %u with\n", init_p->port); - if (init_p->ipv4 == 1) { - struct sockaddr_in *ip4_addr; + if (init_p->ipv4 == 1) { + struct sockaddr_in *ip4_addr; - SCTP_DEBUG("ipv4 addresses:\n"); + SCTP_DEBUG("ipv4 addresses:\n"); - for (i = 0; i < init_p->nb_ipv4_addr; i++) { - SCTP_DEBUG("\t- "IPV4_ADDR"\n", - IPV4_ADDR_FORMAT(init_p->ipv4_address[i])); - ip4_addr = (struct sockaddr_in *)&addr[i]; - ip4_addr->sin_family = AF_INET; - ip4_addr->sin_port = htons(init_p->port); - ip4_addr->sin_addr.s_addr = init_p->ipv4_address[i]; + for (i = 0; i < init_p->nb_ipv4_addr; i++) { + SCTP_DEBUG("\t- "IPV4_ADDR"\n", + IPV4_ADDR_FORMAT(init_p->ipv4_address[i])); + ip4_addr = (struct sockaddr_in *)&addr[i]; + ip4_addr->sin_family = AF_INET; + ip4_addr->sin_port = htons(init_p->port); + ip4_addr->sin_addr.s_addr = init_p->ipv4_address[i]; + } } - } - if (init_p->ipv6 == 1) { - struct sockaddr_in6 *ip6_addr; + if (init_p->ipv6 == 1) { + struct sockaddr_in6 *ip6_addr; - SCTP_DEBUG("ipv6 addresses:\n"); + SCTP_DEBUG("ipv6 addresses:\n"); - for (j = 0; j < init_p->nb_ipv6_addr; j++) { - SCTP_DEBUG("\t- %s\n", init_p->ipv6_address[j]); - ip6_addr = (struct sockaddr_in6 *)&addr[i + j]; - ip6_addr->sin6_family = AF_INET6; - ip6_addr->sin6_port = htons(init_p->port); + for (j = 0; j < init_p->nb_ipv6_addr; j++) { + SCTP_DEBUG("\t- %s\n", init_p->ipv6_address[j]); + ip6_addr = (struct sockaddr_in6 *)&addr[i + j]; + ip6_addr->sin6_family = AF_INET6; + ip6_addr->sin6_port = htons(init_p->port); - if (inet_pton(AF_INET6, init_p->ipv6_address[j], - ip6_addr->sin6_addr.s6_addr) <= 0) { - SCTP_WARN("Provided ipv6 address %s is not valid\n", - init_p->ipv6_address[j]); - } + if (inet_pton(AF_INET6, init_p->ipv6_address[j], + ip6_addr->sin6_addr.s6_addr) <= 0) { + SCTP_WARN("Provided ipv6 address %s is not valid\n", + init_p->ipv6_address[j]); + } + } } - } - if (server_type) { - if ((sd = socket(PF_INET, SOCK_SEQPACKET, IPPROTO_SCTP)) < 0) { - SCTP_ERROR("socket: %s:%d\n", strerror(errno), errno); - return -1; + if (server_type) { + if ((sd = socket(PF_INET, SOCK_SEQPACKET, IPPROTO_SCTP)) < 0) { + SCTP_ERROR("socket: %s:%d\n", strerror(errno), errno); + free(addr); + return -1; + } } - } - else { - if ((sd = socket(AF_INET6, SOCK_STREAM, IPPROTO_SCTP)) < 0) { - SCTP_ERROR("socket: %s:%d\n", strerror(errno), errno); - return -1; + else { + if ((sd = socket(AF_INET6, SOCK_STREAM, IPPROTO_SCTP)) < 0) { + SCTP_ERROR("socket: %s:%d\n", strerror(errno), errno); + free(addr); + return -1; + } } - } - memset((void *)&event, 1, sizeof(struct sctp_event_subscribe)); + memset((void *)&event, 1, sizeof(struct sctp_event_subscribe)); - if (setsockopt(sd, IPPROTO_SCTP, SCTP_EVENTS, &event, - sizeof(struct sctp_event_subscribe)) < 0) { - SCTP_ERROR("setsockopt: %s:%d\n", strerror(errno), errno); - return -1; - } - - sctp_cnx = calloc(1, sizeof(*sctp_cnx)); - - if (server_type) { - sctp_cnx->connection_type = SCTP_TYPE_MULTI_SERVER; - } - else { - sctp_cnx->connection_type = SCTP_TYPE_SERVER; - } - - sctp_cnx->sd = sd; - sctp_cnx->local_port = init_p->port; - sctp_cnx->in_streams = 32; - sctp_cnx->out_streams = 32; - sctp_cnx->ppid = init_p->ppid; - sctp_cnx->task_id = requestor; - sctp_cnx->instance = instance; - - /* Some pre-bind socket configuration */ - if (sctp_set_init_opt(sd, - sctp_cnx->in_streams, - sctp_cnx->out_streams, - 0, - 0) < 0) { - goto err; - } - - if (sctp_bindx(sd, addr, used_addresses, SCTP_BINDX_ADD_ADDR) != 0) { - SCTP_ERROR("sctp_bindx: %s:%d\n", strerror(errno), errno); - return -1; - } + if (setsockopt(sd, IPPROTO_SCTP, SCTP_EVENTS, &event, + sizeof(struct sctp_event_subscribe)) < 0) { + SCTP_ERROR("setsockopt: %s:%d\n", strerror(errno), errno); + free(addr); + return -1; + } - if (listen(sd, 5) < 0) { - SCTP_ERROR("listen: %s:%d\n", strerror(errno), errno); - return -1; - } + sctp_cnx = calloc(1, sizeof(*sctp_cnx)); - /* Insert new element at end of list */ - STAILQ_INSERT_TAIL(&sctp_cnx_list, sctp_cnx, entries); - sctp_nb_cnx++; + if (server_type) { + sctp_cnx->connection_type = SCTP_TYPE_MULTI_SERVER; + } + else { + sctp_cnx->connection_type = SCTP_TYPE_SERVER; + } + + sctp_cnx->sd = sd; + sctp_cnx->local_port = init_p->port; + sctp_cnx->in_streams = 32; + sctp_cnx->out_streams = 32; + sctp_cnx->ppid = init_p->ppid; + sctp_cnx->task_id = requestor; + sctp_cnx->instance = instance; + + /* Some pre-bind socket configuration */ + if (sctp_set_init_opt(sd, + sctp_cnx->in_streams, + sctp_cnx->out_streams, + 0, + 0) < 0) { + goto err; + } - /* Add the socket to list of fd monitored by ITTI */ - itti_subscribe_event_fd(TASK_SCTP, sd); + if (sctp_bindx(sd, addr, used_addresses, SCTP_BINDX_ADD_ADDR) != 0) { + SCTP_ERROR("sctp_bindx: %s:%d\n", strerror(errno), errno); + return -1; + } + + if (listen(sd, 5) < 0) { + SCTP_ERROR("listen: %s:%d\n", strerror(errno), errno); + return -1; + } + + /* Insert new element at end of list */ + STAILQ_INSERT_TAIL(&sctp_cnx_list, sctp_cnx, entries); + sctp_nb_cnx++; + + /* Add the socket to list of fd monitored by ITTI */ + itti_subscribe_event_fd(TASK_SCTP, sd); - return sd; + return sd; err: - if (sd != -1) { - close(sd); - sd = -1; - } + if (sd != -1) { + close(sd); + sd = -1; + } - return -1; + return -1; } //------------------------------------------------------------------------------ static inline void sctp_eNB_accept_associations( - struct sctp_cnx_list_elm_s *sctp_cnx) + struct sctp_cnx_list_elm_s *sctp_cnx) { - int client_sd; - struct sockaddr saddr; - socklen_t saddr_size; - - DevAssert(sctp_cnx != NULL); - - saddr_size = sizeof(saddr); - - /* There is a new client connecting. Accept it... - */ - if ((client_sd = accept(sctp_cnx->sd, &saddr, &saddr_size)) < 0) { - SCTP_ERROR("[%d] accept failed: %s:%d\n", sctp_cnx->sd, strerror(errno), errno); - } else { - struct sctp_cnx_list_elm_s *new_cnx; - uint16_t port; - - /* This is an ipv6 socket */ - port = ((struct sockaddr_in6*)&saddr)->sin6_port; - - /* Contrary to BSD, client socket does not inherit O_NONBLOCK option */ - if (fcntl(client_sd, F_SETFL, O_NONBLOCK) < 0) { - SCTP_ERROR("fcntl F_SETFL O_NONBLOCK failed: %s\n", - strerror(errno)); - close(client_sd); - return; - } + int client_sd; + struct sockaddr saddr; + socklen_t saddr_size; - new_cnx = calloc(1, sizeof(*sctp_cnx)); + DevAssert(sctp_cnx != NULL); - DevAssert(new_cnx != NULL); + saddr_size = sizeof(saddr); - new_cnx->connection_type = SCTP_TYPE_CLIENT; + /* There is a new client connecting. Accept it... + */ + if ((client_sd = accept(sctp_cnx->sd, &saddr, &saddr_size)) < 0) { + SCTP_ERROR("[%d] accept failed: %s:%d\n", sctp_cnx->sd, strerror(errno), errno); + } else { + struct sctp_cnx_list_elm_s *new_cnx; + uint16_t port; - new_cnx->sd = client_sd; - new_cnx->task_id = sctp_cnx->task_id; - new_cnx->cnx_id = 0; - new_cnx->ppid = sctp_cnx->ppid; - new_cnx->instance = sctp_cnx->instance; - new_cnx->local_port = sctp_cnx->local_port; + /* This is an ipv6 socket */ + port = ((struct sockaddr_in6*)&saddr)->sin6_port; - if (sctp_get_sockinfo(client_sd, &new_cnx->in_streams, &new_cnx->out_streams, - &new_cnx->assoc_id) != 0) { - SCTP_ERROR("sctp_get_sockinfo failed\n"); - close(client_sd); - free(new_cnx); - return; - } + /* Contrary to BSD, client socket does not inherit O_NONBLOCK option */ + if (fcntl(client_sd, F_SETFL, O_NONBLOCK) < 0) { + SCTP_ERROR("fcntl F_SETFL O_NONBLOCK failed: %s\n", + strerror(errno)); + close(client_sd); + return; + } - /* Insert new element at end of list */ - STAILQ_INSERT_TAIL(&sctp_cnx_list, new_cnx, entries); - sctp_nb_cnx++; + new_cnx = calloc(1, sizeof(*sctp_cnx)); - /* Add the socket to list of fd monitored by ITTI */ - itti_subscribe_event_fd(TASK_SCTP, client_sd); + DevAssert(new_cnx != NULL); + + new_cnx->connection_type = SCTP_TYPE_CLIENT; + + new_cnx->sd = client_sd; + new_cnx->task_id = sctp_cnx->task_id; + new_cnx->cnx_id = 0; + new_cnx->ppid = sctp_cnx->ppid; + new_cnx->instance = sctp_cnx->instance; + new_cnx->local_port = sctp_cnx->local_port; + + if (sctp_get_sockinfo(client_sd, &new_cnx->in_streams, &new_cnx->out_streams, + &new_cnx->assoc_id) != 0) { + SCTP_ERROR("sctp_get_sockinfo failed\n"); + close(client_sd); + free(new_cnx); + return; + } + + /* Insert new element at end of list */ + STAILQ_INSERT_TAIL(&sctp_cnx_list, new_cnx, entries); + sctp_nb_cnx++; + + /* Add the socket to list of fd monitored by ITTI */ + itti_subscribe_event_fd(TASK_SCTP, client_sd); - sctp_itti_send_association_ind(new_cnx->task_id, new_cnx->instance, - new_cnx->assoc_id, port, - new_cnx->out_streams, new_cnx->in_streams); - } + sctp_itti_send_association_ind(new_cnx->task_id, new_cnx->instance, + new_cnx->assoc_id, port, + new_cnx->out_streams, new_cnx->in_streams); + } } //------------------------------------------------------------------------------ static inline void sctp_eNB_read_from_socket( - struct sctp_cnx_list_elm_s *sctp_cnx) + struct sctp_cnx_list_elm_s *sctp_cnx) { - int flags = 0, n; - socklen_t from_len; - struct sctp_sndrcvinfo sinfo; + int flags = 0, n; + socklen_t from_len; + struct sctp_sndrcvinfo sinfo; - struct sockaddr_in addr; - uint8_t buffer[SCTP_RECV_BUFFER_SIZE]; + struct sockaddr_in addr; + uint8_t buffer[SCTP_RECV_BUFFER_SIZE]; - DevAssert(sctp_cnx != NULL); + DevAssert(sctp_cnx != NULL); - memset((void *)&addr, 0, sizeof(struct sockaddr_in)); - from_len = (socklen_t)sizeof(struct sockaddr_in); - memset((void *)&sinfo, 0, sizeof(struct sctp_sndrcvinfo)); + memset((void *)&addr, 0, sizeof(struct sockaddr_in)); + from_len = (socklen_t)sizeof(struct sockaddr_in); + memset((void *)&sinfo, 0, sizeof(struct sctp_sndrcvinfo)); - n = sctp_recvmsg(sctp_cnx->sd, (void *)buffer, SCTP_RECV_BUFFER_SIZE, - (struct sockaddr *)&addr, &from_len, - &sinfo, &flags); + n = sctp_recvmsg(sctp_cnx->sd, (void *)buffer, SCTP_RECV_BUFFER_SIZE, + (struct sockaddr *)&addr, &from_len, + &sinfo, &flags); - if (n < 0) { - if (errno == ENOTCONN) { - itti_unsubscribe_event_fd(TASK_SCTP, sctp_cnx->sd); + if (n < 0) { + if (errno == ENOTCONN) { + itti_unsubscribe_event_fd(TASK_SCTP, sctp_cnx->sd); - SCTP_DEBUG("Received not connected for sd %d\n", sctp_cnx->sd); + SCTP_DEBUG("Received not connected for sd %d\n", sctp_cnx->sd); - sctp_itti_send_association_resp( - sctp_cnx->task_id, sctp_cnx->instance, -1, - sctp_cnx->cnx_id, SCTP_STATE_UNREACHABLE, 0, 0); + sctp_itti_send_association_resp( + sctp_cnx->task_id, sctp_cnx->instance, -1, + sctp_cnx->cnx_id, SCTP_STATE_UNREACHABLE, 0, 0); - close(sctp_cnx->sd); - STAILQ_REMOVE(&sctp_cnx_list, sctp_cnx, sctp_cnx_list_elm_s, entries); - sctp_nb_cnx--; - free(sctp_cnx); - } else { - SCTP_DEBUG("An error occured during read\n"); - SCTP_ERROR("sctp_recvmsg (fd %d, len %d ): %s:%d\n", sctp_cnx->sd, n, strerror(errno), errno); - } + close(sctp_cnx->sd); + STAILQ_REMOVE(&sctp_cnx_list, sctp_cnx, sctp_cnx_list_elm_s, entries); + sctp_nb_cnx--; + free(sctp_cnx); + } else { + SCTP_DEBUG("An error occured during read\n"); + SCTP_ERROR("sctp_recvmsg (fd %d, len %d ): %s:%d\n", sctp_cnx->sd, n, strerror(errno), errno); + } - return; - } else if (n == 0) { - SCTP_DEBUG("return of sctp_recvmsg is 0...\n"); - return; - } + return; + } else if (n == 0) { + SCTP_DEBUG("return of sctp_recvmsg is 0...\n"); + return; + } - if (flags & MSG_NOTIFICATION) { - union sctp_notification *snp; - snp = (union sctp_notification *)buffer; + if (flags & MSG_NOTIFICATION) { + union sctp_notification *snp; + snp = (union sctp_notification *)buffer; - SCTP_DEBUG("Received notification for sd %d, type %u\n", - sctp_cnx->sd, snp->sn_header.sn_type); + SCTP_DEBUG("Received notification for sd %d, type %u\n", + sctp_cnx->sd, snp->sn_header.sn_type); - /* Client deconnection */ - if (SCTP_SHUTDOWN_EVENT == snp->sn_header.sn_type) { - itti_unsubscribe_event_fd(TASK_SCTP, sctp_cnx->sd); + /* Client deconnection */ + if (SCTP_SHUTDOWN_EVENT == snp->sn_header.sn_type) { + itti_unsubscribe_event_fd(TASK_SCTP, sctp_cnx->sd); - close(sctp_cnx->sd); + close(sctp_cnx->sd); - sctp_itti_send_association_resp( - sctp_cnx->task_id, sctp_cnx->instance, sctp_cnx->assoc_id, - sctp_cnx->cnx_id, SCTP_STATE_SHUTDOWN, - 0, 0); + sctp_itti_send_association_resp( + sctp_cnx->task_id, sctp_cnx->instance, sctp_cnx->assoc_id, + sctp_cnx->cnx_id, SCTP_STATE_SHUTDOWN, + 0, 0); - STAILQ_REMOVE(&sctp_cnx_list, sctp_cnx, sctp_cnx_list_elm_s, entries); - sctp_nb_cnx--; + STAILQ_REMOVE(&sctp_cnx_list, sctp_cnx, sctp_cnx_list_elm_s, entries); + sctp_nb_cnx--; - free(sctp_cnx); - } - /* Association has changed. */ - else if (SCTP_ASSOC_CHANGE == snp->sn_header.sn_type) { - struct sctp_assoc_change *sctp_assoc_changed; - sctp_assoc_changed = &snp->sn_assoc_change; - - SCTP_DEBUG("Client association changed: %d\n", sctp_assoc_changed->sac_state); - - /* New physical association requested by a peer */ - switch (sctp_assoc_changed->sac_state) { - case SCTP_COMM_UP: { - if (sctp_get_peeraddresses(sctp_cnx->sd, NULL, NULL) != 0) { - /* TODO Failure -> notify upper layer */ - } else { - sctp_get_sockinfo(sctp_cnx->sd, &sctp_cnx->in_streams, - &sctp_cnx->out_streams, &sctp_cnx->assoc_id); + free(sctp_cnx); + } + /* Association has changed. */ + else if (SCTP_ASSOC_CHANGE == snp->sn_header.sn_type) { + struct sctp_assoc_change *sctp_assoc_changed; + sctp_assoc_changed = &snp->sn_assoc_change; + + SCTP_DEBUG("Client association changed: %d\n", sctp_assoc_changed->sac_state); + + /* New physical association requested by a peer */ + switch (sctp_assoc_changed->sac_state) { + case SCTP_COMM_UP: { + if (sctp_get_peeraddresses(sctp_cnx->sd, NULL, NULL) != 0) { + /* TODO Failure -> notify upper layer */ + } else { + sctp_get_sockinfo(sctp_cnx->sd, &sctp_cnx->in_streams, + &sctp_cnx->out_streams, &sctp_cnx->assoc_id); + } + + SCTP_DEBUG("Comm up notified for sd %d, assigned assoc_id %d\n", + sctp_cnx->sd, sctp_cnx->assoc_id); + + sctp_itti_send_association_resp( + sctp_cnx->task_id, sctp_cnx->instance, sctp_cnx->assoc_id, + sctp_cnx->cnx_id, SCTP_STATE_ESTABLISHED, + sctp_cnx->out_streams, sctp_cnx->in_streams); + + } + break; + + default: + SCTP_WARN("unhandled: SCTP_ASSOC_CHANGE to %d\n", sctp_assoc_changed->sac_state); + break; + } + } + } else { + sctp_cnx->messages_recv++; + + if (ntohl(sinfo.sinfo_ppid) != sctp_cnx->ppid) { + /* Mismatch in Payload Protocol Identifier, + * may be we received unsollicited traffic from stack other than S1AP. + */ + SCTP_ERROR("Received data from peer with unsollicited PPID %d, expecting %d\n", + ntohl(sinfo.sinfo_ppid), + sctp_cnx->ppid); } - SCTP_DEBUG("Comm up notified for sd %d, assigned assoc_id %d\n", - sctp_cnx->sd, sctp_cnx->assoc_id); - - sctp_itti_send_association_resp( - sctp_cnx->task_id, sctp_cnx->instance, sctp_cnx->assoc_id, - sctp_cnx->cnx_id, SCTP_STATE_ESTABLISHED, - sctp_cnx->out_streams, sctp_cnx->in_streams); - - } - break; + SCTP_DEBUG("[%d][%d] Msg of length %d received from port %u, on stream %d, PPID %d\n", + sinfo.sinfo_assoc_id, sctp_cnx->sd, n, ntohs(addr.sin_port), + sinfo.sinfo_stream, ntohl(sinfo.sinfo_ppid)); - default: - SCTP_WARN("unhandled: SCTP_ASSOC_CHANGE to %d\n", sctp_assoc_changed->sac_state); - break; - } - } - } else { - sctp_cnx->messages_recv++; - - if (ntohl(sinfo.sinfo_ppid) != sctp_cnx->ppid) { - /* Mismatch in Payload Protocol Identifier, - * may be we received unsollicited traffic from stack other than S1AP. - */ - SCTP_ERROR("Received data from peer with unsollicited PPID %d, expecting %d\n", - ntohl(sinfo.sinfo_ppid), - sctp_cnx->ppid); + sctp_itti_send_new_message_ind(sctp_cnx->task_id, + sinfo.sinfo_assoc_id, + buffer, n, sinfo.sinfo_stream); } - - SCTP_DEBUG("[%d][%d] Msg of length %d received from port %u, on stream %d, PPID %d\n", - sinfo.sinfo_assoc_id, sctp_cnx->sd, n, ntohs(addr.sin_port), - sinfo.sinfo_stream, ntohl(sinfo.sinfo_ppid)); - - sctp_itti_send_new_message_ind(sctp_cnx->task_id, - sinfo.sinfo_assoc_id, - buffer, n, sinfo.sinfo_stream); - } } //------------------------------------------------------------------------------ void sctp_eNB_flush_sockets( - struct epoll_event *events, int nb_events) + struct epoll_event *events, int nb_events) { - int i; - struct sctp_cnx_list_elm_s *sctp_cnx = NULL; + int i; + struct sctp_cnx_list_elm_s *sctp_cnx = NULL; - if (events == NULL) { - return; - } + if (events == NULL) { + return; + } - for (i = 0; i < nb_events; i++) { - sctp_cnx = sctp_get_cnx(-1, events[i].data.fd); + for (i = 0; i < nb_events; i++) { + sctp_cnx = sctp_get_cnx(-1, events[i].data.fd); - if (sctp_cnx == NULL) { - continue; - } + if (sctp_cnx == NULL) { + continue; + } - SCTP_DEBUG("Found data for descriptor %d\n", events[i].data.fd); + SCTP_DEBUG("Found data for descriptor %d\n", events[i].data.fd); - if (sctp_cnx->connection_type == SCTP_TYPE_CLIENT) { - sctp_eNB_read_from_socket(sctp_cnx); - } - else if (sctp_cnx->connection_type == SCTP_TYPE_MULTI_SERVER) { - sctp_eNB_accept_associations_multi(sctp_cnx); - } - else { - sctp_eNB_accept_associations(sctp_cnx); + if (sctp_cnx->connection_type == SCTP_TYPE_CLIENT) { + sctp_eNB_read_from_socket(sctp_cnx); + } + else if (sctp_cnx->connection_type == SCTP_TYPE_MULTI_SERVER) { + sctp_eNB_accept_associations_multi(sctp_cnx); + } + else { + sctp_eNB_accept_associations(sctp_cnx); + } } - } } //------------------------------------------------------------------------------ void sctp_eNB_init(void) { - SCTP_DEBUG("Starting SCTP layer\n"); + SCTP_DEBUG("Starting SCTP layer\n"); - STAILQ_INIT(&sctp_cnx_list); + STAILQ_INIT(&sctp_cnx_list); - itti_mark_task_ready(TASK_SCTP); - MSC_START_USE(); + itti_mark_task_ready(TASK_SCTP); + MSC_START_USE(); } - + //------------------------------------------------------------------------------ void *sctp_eNB_process_itti_msg(void *notUsed) { @@ -1058,88 +1061,88 @@ void *sctp_eNB_process_itti_msg(void *notUsed) struct epoll_event *events; MessageDef *received_msg = NULL; int result; - + itti_receive_msg(TASK_SCTP, &received_msg); /* Check if there is a packet to handle */ if (received_msg != NULL) { - switch (ITTI_MSG_ID(received_msg)) { - case SCTP_INIT_MSG: { - SCTP_DEBUG("Received SCTP_INIT_MSG\n"); - - /* We received a new connection request */ - if (sctp_create_new_listener( - ITTI_MESSAGE_GET_INSTANCE(received_msg), - ITTI_MSG_ORIGIN_ID(received_msg), - &received_msg->ittiMsg.sctp_init,0) < 0) { - /* SCTP socket creation or bind failed... */ - SCTP_ERROR("Failed to create new SCTP listener\n"); + switch (ITTI_MSG_ID(received_msg)) { + case SCTP_INIT_MSG: { + SCTP_DEBUG("Received SCTP_INIT_MSG\n"); + + /* We received a new connection request */ + if (sctp_create_new_listener( + ITTI_MESSAGE_GET_INSTANCE(received_msg), + ITTI_MSG_ORIGIN_ID(received_msg), + &received_msg->ittiMsg.sctp_init,0) < 0) { + /* SCTP socket creation or bind failed... */ + SCTP_ERROR("Failed to create new SCTP listener\n"); + } } - } - break; - - case SCTP_INIT_MSG_MULTI_REQ: { - int multi_sd; - - SCTP_DEBUG("Received SCTP_INIT_MSG_MULTI_REQ\n"); - - multi_sd = sctp_create_new_listener( - ITTI_MESSAGE_GET_INSTANCE(received_msg), - ITTI_MSG_ORIGIN_ID(received_msg), - &received_msg->ittiMsg.sctp_init_multi,1); - /* We received a new connection request */ - if (multi_sd < 0) { - /* SCTP socket creation or bind failed... */ - SCTP_ERROR("Failed to create new SCTP listener\n"); - } - sctp_itti_send_init_msg_multi_cnf( + break; + + case SCTP_INIT_MSG_MULTI_REQ: { + int multi_sd; + + SCTP_DEBUG("Received SCTP_INIT_MSG_MULTI_REQ\n"); + + multi_sd = sctp_create_new_listener( + ITTI_MESSAGE_GET_INSTANCE(received_msg), + ITTI_MSG_ORIGIN_ID(received_msg), + &received_msg->ittiMsg.sctp_init_multi,1); + /* We received a new connection request */ + if (multi_sd < 0) { + /* SCTP socket creation or bind failed... */ + SCTP_ERROR("Failed to create new SCTP listener\n"); + } + sctp_itti_send_init_msg_multi_cnf( ITTI_MSG_ORIGIN_ID(received_msg), ITTI_MESSAGE_GET_INSTANCE(received_msg), multi_sd); - } - break; - - case SCTP_NEW_ASSOCIATION_REQ: { - sctp_handle_new_association_req(ITTI_MESSAGE_GET_INSTANCE(received_msg), - ITTI_MSG_ORIGIN_ID(received_msg), - &received_msg->ittiMsg.sctp_new_association_req); - } - break; - - case SCTP_NEW_ASSOCIATION_REQ_MULTI: { - sctp_handle_new_association_req_multi(ITTI_MESSAGE_GET_INSTANCE(received_msg), - ITTI_MSG_ORIGIN_ID(received_msg), - &received_msg->ittiMsg.sctp_new_association_req_multi); - } - break; - - case SCTP_CLOSE_ASSOCIATION: - sctp_close_association(ITTI_MESSAGE_GET_INSTANCE(received_msg), - ITTI_MSG_ORIGIN_ID(received_msg), - &received_msg->ittiMsg.sctp_close_association); + } break; - case TERMINATE_MESSAGE: - SCTP_WARN("*** Exiting SCTP thread\n"); - itti_exit_task(); + case SCTP_NEW_ASSOCIATION_REQ: { + sctp_handle_new_association_req(ITTI_MESSAGE_GET_INSTANCE(received_msg), + ITTI_MSG_ORIGIN_ID(received_msg), + &received_msg->ittiMsg.sctp_new_association_req); + } break; - case SCTP_DATA_REQ: { - sctp_send_data(ITTI_MESSAGE_GET_INSTANCE(received_msg), - ITTI_MSG_ORIGIN_ID(received_msg), - &received_msg->ittiMsg.sctp_data_req); - } - break; + case SCTP_NEW_ASSOCIATION_REQ_MULTI: { + sctp_handle_new_association_req_multi(ITTI_MESSAGE_GET_INSTANCE(received_msg), + ITTI_MSG_ORIGIN_ID(received_msg), + &received_msg->ittiMsg.sctp_new_association_req_multi); + } + break; - default: - SCTP_ERROR("Received unhandled message %d:%s\n", - ITTI_MSG_ID(received_msg), ITTI_MSG_NAME(received_msg)); + case SCTP_CLOSE_ASSOCIATION: + sctp_close_association(ITTI_MESSAGE_GET_INSTANCE(received_msg), + ITTI_MSG_ORIGIN_ID(received_msg), + &received_msg->ittiMsg.sctp_close_association); + break; + + case TERMINATE_MESSAGE: + SCTP_WARN("*** Exiting SCTP thread\n"); + itti_exit_task(); + break; + + case SCTP_DATA_REQ: { + sctp_send_data(ITTI_MESSAGE_GET_INSTANCE(received_msg), + ITTI_MSG_ORIGIN_ID(received_msg), + &received_msg->ittiMsg.sctp_data_req); + } break; - } - result = itti_free(ITTI_MSG_ORIGIN_ID(received_msg), received_msg); - AssertFatal (result == EXIT_SUCCESS, "Failed to free memory (%d)!\n", result); - received_msg = NULL; + default: + SCTP_ERROR("Received unhandled message %d:%s\n", + ITTI_MSG_ID(received_msg), ITTI_MSG_NAME(received_msg)); + break; + } + + result = itti_free(ITTI_MSG_ORIGIN_ID(received_msg), received_msg); + AssertFatal (result == EXIT_SUCCESS, "Failed to free memory (%d)!\n", result); + received_msg = NULL; } nb_events = itti_get_events(TASK_SCTP, &events); @@ -1148,15 +1151,15 @@ void *sctp_eNB_process_itti_msg(void *notUsed) return NULL; } - + //------------------------------------------------------------------------------ void *sctp_eNB_task(void *arg) { - sctp_eNB_init(); + sctp_eNB_init(); - while (1) { - (void) sctp_eNB_process_itti_msg(NULL); - } + while (1) { + (void) sctp_eNB_process_itti_msg(NULL); + } - return NULL; + return NULL; } diff --git a/openair3/TEST/EPC_TEST/play_scenario.c b/openair3/TEST/EPC_TEST/play_scenario.c index 546878e57692061c502ac17d56f08fd7a5f336d1..5928ab017f5f2370cd671fd9347c40a580a596e2 100644 --- a/openair3/TEST/EPC_TEST/play_scenario.c +++ b/openair3/TEST/EPC_TEST/play_scenario.c @@ -249,7 +249,7 @@ int et_hex2data(unsigned char * const data, const unsigned char * const hexstrin char *endptr = NULL; size_t count = 0; - fprintf(stdout, "%s(%s,%d)\n", __FUNCTION__, hexstring, len); + fprintf(stdout, "%s(%s,%u)\n", __FUNCTION__, hexstring, len); if ((len > 1) && (strlen((const char*)hexstring) % 2)) { //or hexstring has an odd length @@ -1103,7 +1103,7 @@ et_config_parse_opt_line ( fprintf(stderr, "Please provide a valid -D/--delay-on-exit argument, %s is not a valid value\n", delay_on_exit); exit(1); } - printf("Delay on exit is %d\n", delay_on_exit); + printf("Delay on exit is %u\n", delay_on_exit); } break; diff --git a/openair3/TEST/EPC_TEST/play_scenario.h b/openair3/TEST/EPC_TEST/play_scenario.h index f9601fe9044aca63d522b3e4085220bec52b8d18..db399a23f1010604a647326123859cc8238b687b 100644 --- a/openair3/TEST/EPC_TEST/play_scenario.h +++ b/openair3/TEST/EPC_TEST/play_scenario.h @@ -398,7 +398,7 @@ typedef struct et_event_s { } u; } et_event_t; -inline void et_free_pointer(void *p) {if (NULL != p) {free(p); p=NULL;}}; +inline void et_free_pointer(void *p) {if (NULL != p) {free(p);}}; //------------------------- void et_free_packet(et_packet_t* packet); diff --git a/openair3/TEST/EPC_TEST/play_scenario_display.c b/openair3/TEST/EPC_TEST/play_scenario_display.c index e10cbdf9bf1b285d6965dcb77c3f4db80b284c84..dd5b6edbd3c679d03a71e4222f3f98040f809271 100644 --- a/openair3/TEST/EPC_TEST/play_scenario_display.c +++ b/openair3/TEST/EPC_TEST/play_scenario_display.c @@ -54,7 +54,7 @@ void et_print_hex_octets(const unsigned char * const byte_stream, const unsigned fprintf(stdout, " |\n"); } - fprintf(stdout, " %04ld |", octet_index); + fprintf(stdout, " %04lu |", octet_index); } /* diff --git a/openair3/TEST/EPC_TEST/play_scenario_parse.c b/openair3/TEST/EPC_TEST/play_scenario_parse.c index 040db30398495f51f3faf25b5bf6fb2a18604806..d24fddddec342acc284a01f5233e16ed4b4a3560 100644 --- a/openair3/TEST/EPC_TEST/play_scenario_parse.c +++ b/openair3/TEST/EPC_TEST/play_scenario_parse.c @@ -94,7 +94,7 @@ void et_parse_s1ap(xmlDocPtr doc, const xmlNode const *s1ap_node, et_s1ap_t * co xml_char = xmlGetProp((xmlNode *)cur_node, (const xmlChar *)"value"); if (NULL != xml_char) { xml_char2 = xmlGetProp((xmlNode *)cur_node, (const xmlChar *)"name"); - fprintf(stdout, "s1ap %p field name %s size %d value %s\n",s1ap, xml_char2, size, xml_char); + fprintf(stdout, "s1ap %p field name %s size %u value %s\n",s1ap, xml_char2, size, xml_char); xmlFree(xml_char2); // if success to get value, do not parse children //AssertFatal ((xmlStrlen(xml_char) == size), "ERROR %s() mismatch in size %d and strlen %d\n", __FUNCTION__, size, xmlStrlen(xml_char)); diff --git a/openair3/UTILS/conversions.h b/openair3/UTILS/conversions.h index 00287341b2a19f06af32ae4a136d329b73d694b2..f1f1d2550a146a18b1ae8dbd53dfb5dbcfc4d39f 100644 --- a/openair3/UTILS/conversions.h +++ b/openair3/UTILS/conversions.h @@ -131,6 +131,54 @@ do { \ #define M_TMSI_TO_OCTET_STRING INT32_TO_OCTET_STRING #define MME_GID_TO_OCTET_STRING INT16_TO_OCTET_STRING +#define ENCRALG_TO_BIT_STRING(encralg, bitstring) \ + do { \ + (bitstring)->size=2; \ + (bitstring)->bits_unused=0; \ + (bitstring)->buf=calloc (1, sizeof (uint8_t)); \ + (bitstring)->buf[0] = (encralg) >> 8; \ + (bitstring)->buf[1] = (encralg); \ + }while(0) + +#define INTPROTALG_TO_BIT_STRING(intprotalg, bitstring) \ +do { \ + (bitstring)->size=2; \ + (bitstring)->bits_unused=0; \ + (bitstring)->buf=calloc (2, sizeof (uint8_t)); \ + (bitstring)->buf[0] = (intprotalg) >> 8; \ + (bitstring)->buf[1] = (intprotalg); \ +}while(0) + +#define KENB_STAR_TO_BIT_STRING(kenbstar, bitstring) \ +do { \ + (bitstring)->size=32; \ + (bitstring)->bits_unused=0; \ + (bitstring)->buf= calloc (32, sizeof (uint8_t));\ + memcpy((bitstring)->buf, kenbstar, 32*sizeof(uint8_t)); \ +}while(0) + +#define UEAGMAXBITRTD_TO_ASN_PRIMITIVES(uegmaxbitrtd, asnprimitives) \ +do { \ + (asnprimitives)->size=5; \ + (asnprimitives)->buf=calloc (5, sizeof (uint8_t)); \ + (asnprimitives)->buf[0] = (uegmaxbitrtd) >> 32; \ + (asnprimitives)->buf[1] = (uegmaxbitrtd) >> 24; \ + (asnprimitives)->buf[2] = (uegmaxbitrtd) >> 16; \ + (asnprimitives)->buf[3] = (uegmaxbitrtd) >> 8; \ + (asnprimitives)->buf[4] = (uegmaxbitrtd); \ + }while(0) + +#define UEAGMAXBITRTU_TO_ASN_PRIMITIVES(uegmaxbitrtu, asnprimitives) \ +do { \ + (asnprimitives)->size=5; \ + (asnprimitives)->buf=calloc (5, sizeof (uint8_t)); \ + (asnprimitives)->buf[0] = (uegmaxbitrtu) >> 32; \ + (asnprimitives)->buf[1] = (uegmaxbitrtu) >> 24; \ + (asnprimitives)->buf[2] = (uegmaxbitrtu) >> 16; \ + (asnprimitives)->buf[3] = (uegmaxbitrtu) >> 8; \ + (asnprimitives)->buf[4] = (uegmaxbitrtu); \ + }while(0) + #define OCTET_STRING_TO_INT8(aSN, x) \ do { \ DevCheck((aSN)->size == 1, (aSN)->size, 0, 0); \ diff --git a/targets/ARCH/BLADERF/USERSPACE/LIB/bladerf_lib.c b/targets/ARCH/BLADERF/USERSPACE/LIB/bladerf_lib.c index e5966af267047b0285583bab64d2e75370b65385..3ced5ca833a972d1e8f021733dbf1c2ab71cdb16 100644 --- a/targets/ARCH/BLADERF/USERSPACE/LIB/bladerf_lib.c +++ b/targets/ARCH/BLADERF/USERSPACE/LIB/bladerf_lib.c @@ -35,18 +35,18 @@ * @{ */ -//! Number of BladeRF devices +//! Number of BladeRF devices #ifdef __SSE4_1__ # include <smmintrin.h> #endif - + #ifdef __AVX2__ # include <immintrin.h> #endif int num_devices=0; -/*These items configure the underlying asynch stream used by the the sync interface. +/*These items configure the underlying asynch stream used by the the sync interface. */ /*! \brief BladeRF Init function (not used at the moment) @@ -54,119 +54,119 @@ int num_devices=0; * \returns 0 on success */ int trx_brf_init(openair0_device *device) { - return 0; + return 0; } /*! \brief get current timestamp - *\param device the hardware to use + *\param device the hardware to use *\param module the bladeRf module *\returns timestamp of BladeRF */ - + openair0_timestamp trx_get_timestamp(openair0_device *device, bladerf_module module) { - int status; - struct bladerf_metadata meta; - brf_state_t *brf = (brf_state_t*)device->priv; - memset(&meta, 0, sizeof(meta)); - - if ((status=bladerf_get_timestamp(brf->dev, module, &meta.timestamp)) != 0) { - fprintf(stderr,"Failed to get current %s timestamp: %s\n",(module == BLADERF_MODULE_RX ) ? "RX" : "TX", bladerf_strerror(status)); - return -1; - } // else {printf("Current RX timestampe 0x%016"PRIx64"\n", meta.timestamp); } - - return meta.timestamp; + int status; + struct bladerf_metadata meta; + brf_state_t *brf = (brf_state_t*)device->priv; + memset(&meta, 0, sizeof(meta)); + + if ((status=bladerf_get_timestamp(brf->dev, module, &meta.timestamp)) != 0) { + fprintf(stderr,"Failed to get current %s timestamp: %s\n",(module == BLADERF_MODULE_RX ) ? "RX" : "TX", bladerf_strerror(status)); + return -1; + } // else {printf("Current RX timestampe 0x%016"PRIx64"\n", meta.timestamp); } + + return meta.timestamp; } /*! \brief Start BladeRF - * \param device the hardware to use + * \param device the hardware to use * \returns 0 on success */ int trx_brf_start(openair0_device *device) { - brf_state_t *brf = (brf_state_t*)device->priv; - int status; - - brf->meta_tx.flags = 0; - - if ((status = bladerf_sync_config(brf->dev, - BLADERF_MODULE_TX, - BLADERF_FORMAT_SC16_Q11_META, - brf->num_buffers, - brf->buffer_size, - brf->num_transfers, - 100/*brf->tx_timeout_ms*/)) != 0 ) { - fprintf(stderr,"Failed to configure TX sync interface: %s\n", bladerf_strerror(status)); - abort(); - } - if ((status = bladerf_sync_config(brf->dev, - BLADERF_MODULE_RX, - BLADERF_FORMAT_SC16_Q11_META, - brf->num_buffers, - brf->buffer_size, - brf->num_transfers, - 100/*brf->rx_timeout_ms*/)) != 0 ) { - fprintf(stderr,"Failed to configure RX sync interface: %s\n", bladerf_strerror(status)); - abort(); - } - if ((status=bladerf_enable_module(brf->dev, BLADERF_MODULE_TX, true)) != 0) { - fprintf(stderr,"Failed to enable TX module: %s\n", bladerf_strerror(status)); - abort(); - } - if ((status=bladerf_enable_module(brf->dev, BLADERF_MODULE_RX, true)) != 0) { - fprintf(stderr,"Failed to enable RX module: %s\n", bladerf_strerror(status)); - abort(); - } - - return 0; + brf_state_t *brf = (brf_state_t*)device->priv; + int status; + + brf->meta_tx.flags = 0; + + if ((status = bladerf_sync_config(brf->dev, + BLADERF_MODULE_TX, + BLADERF_FORMAT_SC16_Q11_META, + brf->num_buffers, + brf->buffer_size, + brf->num_transfers, + 100/*brf->tx_timeout_ms*/)) != 0 ) { + fprintf(stderr,"Failed to configure TX sync interface: %s\n", bladerf_strerror(status)); + abort(); + } + if ((status = bladerf_sync_config(brf->dev, + BLADERF_MODULE_RX, + BLADERF_FORMAT_SC16_Q11_META, + brf->num_buffers, + brf->buffer_size, + brf->num_transfers, + 100/*brf->rx_timeout_ms*/)) != 0 ) { + fprintf(stderr,"Failed to configure RX sync interface: %s\n", bladerf_strerror(status)); + abort(); + } + if ((status=bladerf_enable_module(brf->dev, BLADERF_MODULE_TX, true)) != 0) { + fprintf(stderr,"Failed to enable TX module: %s\n", bladerf_strerror(status)); + abort(); + } + if ((status=bladerf_enable_module(brf->dev, BLADERF_MODULE_RX, true)) != 0) { + fprintf(stderr,"Failed to enable RX module: %s\n", bladerf_strerror(status)); + abort(); + } + + return 0; } /*! \brief Called to send samples to the BladeRF RF target \param device pointer to the device structure specific to the RF hardware target - \param timestamp The timestamp at whicch the first sample MUST be sent + \param timestamp The timestamp at whicch the first sample MUST be sent \param buff Buffer which holds the samples \param nsamps number of samples to be sent \param cc index of the component carrier \param flags Ignored for the moment \returns 0 on success -*/ +*/ static int trx_brf_write(openair0_device *device,openair0_timestamp ptimestamp, void **buff, int nsamps, int cc, int flags) { - - int status; - brf_state_t *brf = (brf_state_t*)device->priv; - /* BRF has only 1 rx/tx chaine : is it correct? */ - int16_t *samples = (int16_t*)buff[0]; - - //memset(&brf->meta_tx, 0, sizeof(brf->meta_tx)); - // When BLADERF_META_FLAG_TX_NOW is used the timestamp is not used, so one can't schedule a tx - if (brf->meta_tx.flags == 0 ) - brf->meta_tx.flags = (BLADERF_META_FLAG_TX_BURST_START);// | BLADERF_META_FLAG_TX_BURST_END);// | BLADERF_META_FLAG_TX_NOW); - - - brf->meta_tx.timestamp= (uint64_t) (ptimestamp); - status = bladerf_sync_tx(brf->dev, samples, (unsigned int) nsamps, &brf->meta_tx, 2*brf->tx_timeout_ms); - - if (brf->meta_tx.flags == BLADERF_META_FLAG_TX_BURST_START) - brf->meta_tx.flags = BLADERF_META_FLAG_TX_UPDATE_TIMESTAMP; - - - if (status != 0) { - //fprintf(stderr,"Failed to TX sample: %s\n", bladerf_strerror(status)); - brf->num_tx_errors++; - brf_error(status); - } else if (brf->meta_tx.status & BLADERF_META_STATUS_UNDERRUN){ - /* libbladeRF does not report this status. It is here for future use. */ - fprintf(stderr, "TX Underrun detected. %u valid samples were read.\n", brf->meta_tx.actual_count); - brf->num_underflows++; - } - //printf("Provided TX timestampe %u, meta timestame %u\n", ptimestamp,brf->meta_tx.timestamp); - - // printf("tx status %d \n",brf->meta_tx.status); - brf->tx_current_ts=brf->meta_tx.timestamp; - brf->tx_actual_nsamps+=brf->meta_tx.actual_count; - brf->tx_nsamps+=nsamps; - brf->tx_count++; - - - return nsamps; //brf->meta_tx.actual_count; + + int status; + brf_state_t *brf = (brf_state_t*)device->priv; + /* BRF has only 1 rx/tx chaine : is it correct? */ + int16_t *samples = (int16_t*)buff[0]; + + //memset(&brf->meta_tx, 0, sizeof(brf->meta_tx)); + // When BLADERF_META_FLAG_TX_NOW is used the timestamp is not used, so one can't schedule a tx + if (brf->meta_tx.flags == 0 ) + brf->meta_tx.flags = (BLADERF_META_FLAG_TX_BURST_START);// | BLADERF_META_FLAG_TX_BURST_END);// | BLADERF_META_FLAG_TX_NOW); + + + brf->meta_tx.timestamp= (uint64_t) (ptimestamp); + status = bladerf_sync_tx(brf->dev, samples, (unsigned int) nsamps, &brf->meta_tx, 2*brf->tx_timeout_ms); + + if (brf->meta_tx.flags == BLADERF_META_FLAG_TX_BURST_START) + brf->meta_tx.flags = BLADERF_META_FLAG_TX_UPDATE_TIMESTAMP; + + + if (status != 0) { + //fprintf(stderr,"Failed to TX sample: %s\n", bladerf_strerror(status)); + brf->num_tx_errors++; + brf_error(status); + } else if (brf->meta_tx.status & BLADERF_META_STATUS_UNDERRUN) { + /* libbladeRF does not report this status. It is here for future use. */ + fprintf(stderr, "TX Underrun detected. %u valid samples were read.\n", brf->meta_tx.actual_count); + brf->num_underflows++; + } + //printf("Provided TX timestampe %u, meta timestame %u\n", ptimestamp,brf->meta_tx.timestamp); + + // printf("tx status %d \n",brf->meta_tx.status); + brf->tx_current_ts=brf->meta_tx.timestamp; + brf->tx_actual_nsamps+=brf->meta_tx.actual_count; + brf->tx_nsamps+=nsamps; + brf->tx_count++; + + + return nsamps; //brf->meta_tx.actual_count; } /*! \brief Receive samples from hardware. @@ -182,90 +182,90 @@ static int trx_brf_write(openair0_device *device,openair0_timestamp ptimestamp, */ static int trx_brf_read(openair0_device *device, openair0_timestamp *ptimestamp, void **buff, int nsamps, int cc) { - int status=0; - brf_state_t *brf = (brf_state_t*)device->priv; - - // BRF has only one rx/tx chain - int16_t *samples = (int16_t*)buff[0]; - - brf->meta_rx.actual_count = 0; - brf->meta_rx.flags = BLADERF_META_FLAG_RX_NOW; - status = bladerf_sync_rx(brf->dev, samples, (unsigned int) nsamps, &brf->meta_rx, 2*brf->rx_timeout_ms); - - // printf("Current RX timestampe %u, nsamps %u, actual %u, cc %d\n", brf->meta_rx.timestamp, nsamps, brf->meta_rx.actual_count, cc); - - if (status != 0) { - fprintf(stderr, "RX failed: %s\n", bladerf_strerror(status)); - // printf("RX failed: %s\n", bladerf_strerror(status)); - brf->num_rx_errors++; - } else if ( brf->meta_rx.status & BLADERF_META_STATUS_OVERRUN) { - brf->num_overflows++; - printf("RX overrun (%d) is detected. t=" "%" PRIu64 "Got %u samples. nsymps %d\n", - brf->num_overflows,brf->meta_rx.timestamp, brf->meta_rx.actual_count, nsamps); - } - - if (brf->meta_rx.actual_count != nsamps) { - printf("RX bad samples count, wanted %d, got %d\n", nsamps, brf->meta_rx.actual_count); - } - - //printf("Current RX timestampe %u\n", brf->meta_rx.timestamp); - //printf("[BRF] (buff %p) ts=0x%"PRIu64" %s\n",samples, brf->meta_rx.timestamp,bladerf_strerror(status)); - brf->rx_current_ts=brf->meta_rx.timestamp; - brf->rx_actual_nsamps+=brf->meta_rx.actual_count; - brf->rx_nsamps+=nsamps; - brf->rx_count++; - - - *ptimestamp = brf->meta_rx.timestamp; - - return nsamps; //brf->meta_rx.actual_count; + int status=0; + brf_state_t *brf = (brf_state_t*)device->priv; + + // BRF has only one rx/tx chain + int16_t *samples = (int16_t*)buff[0]; + + brf->meta_rx.actual_count = 0; + brf->meta_rx.flags = BLADERF_META_FLAG_RX_NOW; + status = bladerf_sync_rx(brf->dev, samples, (unsigned int) nsamps, &brf->meta_rx, 2*brf->rx_timeout_ms); + + // printf("Current RX timestampe %u, nsamps %u, actual %u, cc %d\n", brf->meta_rx.timestamp, nsamps, brf->meta_rx.actual_count, cc); + + if (status != 0) { + fprintf(stderr, "RX failed: %s\n", bladerf_strerror(status)); + // printf("RX failed: %s\n", bladerf_strerror(status)); + brf->num_rx_errors++; + } else if ( brf->meta_rx.status & BLADERF_META_STATUS_OVERRUN) { + brf->num_overflows++; + printf("RX overrun (%d) is detected. t=" "%" PRIu64 "Got %u samples. nsymps %d\n", + brf->num_overflows,brf->meta_rx.timestamp, brf->meta_rx.actual_count, nsamps); + } + + if (brf->meta_rx.actual_count != nsamps) { + printf("RX bad samples count, wanted %d, got %d\n", nsamps, brf->meta_rx.actual_count); + } + + //printf("Current RX timestampe %u\n", brf->meta_rx.timestamp); + //printf("[BRF] (buff %p) ts=0x%"PRIu64" %s\n",samples, brf->meta_rx.timestamp,bladerf_strerror(status)); + brf->rx_current_ts=brf->meta_rx.timestamp; + brf->rx_actual_nsamps+=brf->meta_rx.actual_count; + brf->rx_nsamps+=nsamps; + brf->rx_count++; + + + *ptimestamp = brf->meta_rx.timestamp; + + return nsamps; //brf->meta_rx.actual_count; } -/*! \brief Terminate operation of the BladeRF transceiver -- free all associated resources +/*! \brief Terminate operation of the BladeRF transceiver -- free all associated resources * \param device the hardware to use */ void trx_brf_end(openair0_device *device) { - int status; - brf_state_t *brf = (brf_state_t*)device->priv; - // Disable RX module, shutting down our underlying RX stream - if ((status=bladerf_enable_module(brf->dev, BLADERF_MODULE_RX, false)) != 0) { - fprintf(stderr, "Failed to disable RX module: %s\n", bladerf_strerror(status)); - } - if ((status=bladerf_enable_module(brf->dev, BLADERF_MODULE_TX, false)) != 0) { - fprintf(stderr, "Failed to disable TX module: %s\n", bladerf_strerror(status)); - } - bladerf_close(brf->dev); - exit(1); + int status; + brf_state_t *brf = (brf_state_t*)device->priv; + // Disable RX module, shutting down our underlying RX stream + if ((status=bladerf_enable_module(brf->dev, BLADERF_MODULE_RX, false)) != 0) { + fprintf(stderr, "Failed to disable RX module: %s\n", bladerf_strerror(status)); + } + if ((status=bladerf_enable_module(brf->dev, BLADERF_MODULE_TX, false)) != 0) { + fprintf(stderr, "Failed to disable TX module: %s\n", bladerf_strerror(status)); + } + bladerf_close(brf->dev); + exit(1); } -/*! \brief print the BladeRF statistics +/*! \brief print the BladeRF statistics * \param device the hardware to use * \returns 0 on success */ int trx_brf_get_stats(openair0_device* device) { - return(0); + return(0); } -/*! \brief Reset the BladeRF statistics +/*! \brief Reset the BladeRF statistics * \param device the hardware to use * \returns 0 on success */ int trx_brf_reset_stats(openair0_device* device) { - return(0); + return(0); } /*! \brief Stop BladeRF * \param card the hardware to use - * \returns 0 in success + * \returns 0 in success */ int trx_brf_stop(openair0_device* device) { - return(0); + return(0); } @@ -273,39 +273,39 @@ int trx_brf_stop(openair0_device* device) { * \param device the hardware to use * \param openair0_cfg1 openair0 Config structure (ignored. It is there to comply with RF common API) * \param exmimo_dump_config (ignored) - * \returns 0 in success + * \returns 0 in success */ int trx_brf_set_freq(openair0_device* device, openair0_config_t *openair0_cfg1,int exmimo_dump_config) { - int status; - brf_state_t *brf = (brf_state_t *)device->priv; - openair0_config_t *openair0_cfg = (openair0_config_t *)device->openair0_cfg; + int status; + brf_state_t *brf = (brf_state_t *)device->priv; + openair0_config_t *openair0_cfg = (openair0_config_t *)device->openair0_cfg; - if ((status=bladerf_set_frequency(brf->dev, BLADERF_MODULE_TX, (unsigned int) openair0_cfg->tx_freq[0])) != 0){ - fprintf(stderr,"Failed to set TX frequency: %s\n",bladerf_strerror(status)); - brf_error(status); - }else - printf("[BRF] set TX Frequency to %u\n", (unsigned int) openair0_cfg->tx_freq[0]); + if ((status=bladerf_set_frequency(brf->dev, BLADERF_MODULE_TX, (unsigned int) openair0_cfg->tx_freq[0])) != 0) { + fprintf(stderr,"Failed to set TX frequency: %s\n",bladerf_strerror(status)); + brf_error(status); + } else + printf("[BRF] set TX Frequency to %u\n", (unsigned int) openair0_cfg->tx_freq[0]); - if ((status=bladerf_set_frequency(brf->dev, BLADERF_MODULE_RX, (unsigned int) openair0_cfg->rx_freq[0])) != 0){ - fprintf(stderr,"Failed to set RX frequency: %s\n",bladerf_strerror(status)); - brf_error(status); - } else - printf("[BRF] set RX frequency to %u\n",(unsigned int)openair0_cfg->rx_freq[0]); + if ((status=bladerf_set_frequency(brf->dev, BLADERF_MODULE_RX, (unsigned int) openair0_cfg->rx_freq[0])) != 0) { + fprintf(stderr,"Failed to set RX frequency: %s\n",bladerf_strerror(status)); + brf_error(status); + } else + printf("[BRF] set RX frequency to %u\n",(unsigned int)openair0_cfg->rx_freq[0]); - return(0); + return(0); } /*! \brief Set Gains (TX/RX) * \param device the hardware to use * \param openair0_cfg openair0 Config structure - * \returns 0 in success + * \returns 0 in success */ int trx_brf_set_gains(openair0_device* device, openair0_config_t *openair0_cfg) { - return(0); + return(0); } @@ -317,10 +317,11 @@ int16_t cos_3fsover8[8] = {2047, -1448, 0, 1447, -2047, 1447, 0, /*! \brief calibration table for BladeRF */ rx_gain_calib_table_t calib_table_fx4[] = { - {2300000000.0,53.5}, - {1880000000.0,57.0}, - {816000000.0,73.0}, - {-1,0}}; + {2300000000.0,53.5}, + {1880000000.0,57.0}, + {816000000.0,73.0}, + {-1,0} +}; /*! \brief set RX gain offset from calibration table * \param openair0_cfg RF frontend parameters set by application @@ -328,822 +329,822 @@ rx_gain_calib_table_t calib_table_fx4[] = { */ void set_rx_gain_offset(openair0_config_t *openair0_cfg, int chain_index) { - int i=0; - // loop through calibration table to find best adjustment factor for RX frequency - double min_diff = 6e9,diff; - - while (openair0_cfg->rx_gain_calib_table[i].freq>0) { - diff = fabs(openair0_cfg->rx_freq[chain_index] - openair0_cfg->rx_gain_calib_table[i].freq); - printf("cal %d: freq %f, offset %f, diff %f\n", - i, - openair0_cfg->rx_gain_calib_table[i].freq, - openair0_cfg->rx_gain_calib_table[i].offset,diff); - if (min_diff > diff) { - min_diff = diff; - openair0_cfg->rx_gain_offset[chain_index] = openair0_cfg->rx_gain_calib_table[i].offset; + int i=0; + // loop through calibration table to find best adjustment factor for RX frequency + double min_diff = 6e9,diff; + + while (openair0_cfg->rx_gain_calib_table[i].freq>0) { + diff = fabs(openair0_cfg->rx_freq[chain_index] - openair0_cfg->rx_gain_calib_table[i].freq); + printf("cal %d: freq %f, offset %f, diff %f\n", + i, + openair0_cfg->rx_gain_calib_table[i].freq, + openair0_cfg->rx_gain_calib_table[i].offset,diff); + if (min_diff > diff) { + min_diff = diff; + openair0_cfg->rx_gain_offset[chain_index] = openair0_cfg->rx_gain_calib_table[i].offset; + } + i++; } - i++; - } - + } -/*! \brief Calibrate LMSSDR RF +/*! \brief Calibrate LMSSDR RF * \param device the hardware to use */ void calibrate_rf(openair0_device *device) { - /* TODO: this function does not seem to work. Disabled until fixed. */ - return; - - brf_state_t *brf = (brf_state_t *)device->priv; - openair0_timestamp ptimestamp; - int16_t *calib_buffp,*calib_tx_buffp; - int16_t calib_buff[2*RXDCLENGTH]; - int16_t calib_tx_buff[2*RXDCLENGTH]; - int i,j,offI,offQ,offIold,offQold,offInew,offQnew,offphase,offphaseold,offphasenew,offgain,offgainold,offgainnew; - int32_t meanI,meanQ,meanIold,meanQold; - int cnt=0,loop; - - // put TX on a far-away frequency to avoid interference in RX band - bladerf_set_frequency(brf->dev,BLADERF_MODULE_TX, (unsigned int) device->openair0_cfg->rx_freq[0] + 200e6); - // Set gains to close to max - bladerf_set_gain(brf->dev, BLADERF_MODULE_RX, 60); - bladerf_set_gain(brf->dev, BLADERF_MODULE_TX, 60); - - // fill TX buffer with fs/8 complex sinusoid - j=0; - for (i=0;i<RXDCLENGTH;i++) { - calib_tx_buff[j++] = cos_fsover8[i&7]; - calib_tx_buff[j++] = cos_fsover8[(i+6)&7]; // sin - } - calib_buffp = &calib_buff[0]; - calib_tx_buffp = &calib_tx_buff[0]; - // Calibrate RX DC offset - - offIold=offQold=2048; - bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_LMS_DCOFF_I,offIold); - bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_LMS_DCOFF_Q,offQold); - for (i=0;i<10;i++) - trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); - - for (meanIold=meanQold=i=j=0;i<RXDCLENGTH;i++) { - meanIold+=calib_buff[j++]; - meanQold+=calib_buff[j++]; - } - meanIold/=RXDCLENGTH; - meanQold/=RXDCLENGTH; - printf("[BRF] RX DC: (%d,%d) => (%d,%d)\n",offIold,offQold,meanIold,meanQold); - - offI=offQ=-2048; - bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_LMS_DCOFF_I,offI); - bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_LMS_DCOFF_Q,offQ); - for (i=0;i<10;i++) - trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); - - for (meanI=meanQ=i=j=0;i<RXDCLENGTH;i++) { - meanI+=calib_buff[j++]; - meanQ+=calib_buff[j++]; - } - meanI/=RXDCLENGTH; - meanQ/=RXDCLENGTH; - // printf("[BRF] RX DC: (%d,%d) => (%d,%d)\n",offI,offQ,meanI,meanQ); - - while (cnt++ < 12) { - - offInew=(offIold+offI)>>1; - offQnew=(offQold+offQ)>>1; - - if (meanI*meanI < meanIold*meanIold) { - meanIold = meanI; - offIold = offI; - printf("[BRF] *** RX DC: offI %d => %d\n",offIold,meanI); + /* TODO: this function does not seem to work. Disabled until fixed. */ + return; + + brf_state_t *brf = (brf_state_t *)device->priv; + openair0_timestamp ptimestamp; + int16_t *calib_buffp,*calib_tx_buffp; + int16_t calib_buff[2*RXDCLENGTH]; + int16_t calib_tx_buff[2*RXDCLENGTH]; + int i,j,offI,offQ,offIold,offQold,offInew,offQnew,offphase,offphaseold,offphasenew,offgain,offgainold,offgainnew; + int32_t meanI,meanQ,meanIold,meanQold; + int cnt=0,loop; + + // put TX on a far-away frequency to avoid interference in RX band + bladerf_set_frequency(brf->dev,BLADERF_MODULE_TX, (unsigned int) device->openair0_cfg->rx_freq[0] + 200e6); + // Set gains to close to max + bladerf_set_gain(brf->dev, BLADERF_MODULE_RX, 60); + bladerf_set_gain(brf->dev, BLADERF_MODULE_TX, 60); + + // fill TX buffer with fs/8 complex sinusoid + j=0; + for (i=0; i<RXDCLENGTH; i++) { + calib_tx_buff[j++] = cos_fsover8[i&7]; + calib_tx_buff[j++] = cos_fsover8[(i+6)&7]; // sin } - if (meanQ*meanQ < meanQold*meanQold) { - meanQold = meanQ; - offQold = offQ; - printf("[BRF] *** RX DC: offQ %d => %d\n",offQold,meanQ); + calib_buffp = &calib_buff[0]; + calib_tx_buffp = &calib_tx_buff[0]; + // Calibrate RX DC offset + + offIold=offQold=2048; + bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_LMS_DCOFF_I,offIold); + bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_LMS_DCOFF_Q,offQold); + for (i=0; i<10; i++) + trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); + + for (meanIold=meanQold=i=j=0; i<RXDCLENGTH; i++) { + meanIold+=calib_buff[j++]; + meanQold+=calib_buff[j++]; } - offI = offInew; - offQ = offQnew; + meanIold/=RXDCLENGTH; + meanQold/=RXDCLENGTH; + printf("[BRF] RX DC: (%d,%d) => (%d,%d)\n",offIold,offQold,meanIold,meanQold); + + offI=offQ=-2048; bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_LMS_DCOFF_I,offI); bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_LMS_DCOFF_Q,offQ); + for (i=0; i<10; i++) + trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); - for (i=0;i<10;i++) - trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); - - for (meanI=meanQ=i=j=0;i<RXDCLENGTH;i++) { - meanI+=calib_buff[j++]; - meanQ+=calib_buff[j++]; + for (meanI=meanQ=i=j=0; i<RXDCLENGTH; i++) { + meanI+=calib_buff[j++]; + meanQ+=calib_buff[j++]; } meanI/=RXDCLENGTH; meanQ/=RXDCLENGTH; - printf("[BRF] RX DC: (%d,%d) => (%d,%d)\n",offI,offQ,meanI,meanQ); - } - - printf("[BRF] RX DC: (%d,%d) => (%d,%d)\n",offIold,offQold,meanIold,meanQold); - bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_LMS_DCOFF_I,offIold); - bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_LMS_DCOFF_Q,offQold); - - // TX DC offset - // PUT TX as f_RX + fs/4 - // loop back BLADERF_LB_RF_LNA1 - bladerf_set_frequency(brf->dev,BLADERF_MODULE_TX, (unsigned int) device->openair0_cfg->rx_freq[0] + (unsigned int) device->openair0_cfg->sample_rate/4); - bladerf_set_loopback (brf->dev,BLADERF_LB_RF_LNA1); - - offIold=2048; - bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_LMS_DCOFF_I,offIold); - for (i=0;i<10;i++) { - trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); - trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0); - } - for (meanIold=meanQold=i=j=0;i<RXDCLENGTH;i++) { - switch (i&3) { - case 0: - meanIold+=calib_buff[j++]; - break; - case 1: - meanQold+=calib_buff[j++]; - break; - case 2: - meanIold-=calib_buff[j++]; - break; - case 3: - meanQold-=calib_buff[j++]; - break; + // printf("[BRF] RX DC: (%d,%d) => (%d,%d)\n",offI,offQ,meanI,meanQ); + + while (cnt++ < 12) { + + offInew=(offIold+offI)>>1; + offQnew=(offQold+offQ)>>1; + + if (meanI*meanI < meanIold*meanIold) { + meanIold = meanI; + offIold = offI; + printf("[BRF] *** RX DC: offI %d => %d\n",offIold,meanI); + } + if (meanQ*meanQ < meanQold*meanQold) { + meanQold = meanQ; + offQold = offQ; + printf("[BRF] *** RX DC: offQ %d => %d\n",offQold,meanQ); + } + offI = offInew; + offQ = offQnew; + bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_LMS_DCOFF_I,offI); + bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_LMS_DCOFF_Q,offQ); + + for (i=0; i<10; i++) + trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); + + for (meanI=meanQ=i=j=0; i<RXDCLENGTH; i++) { + meanI+=calib_buff[j++]; + meanQ+=calib_buff[j++]; + } + meanI/=RXDCLENGTH; + meanQ/=RXDCLENGTH; + printf("[BRF] RX DC: (%d,%d) => (%d,%d)\n",offI,offQ,meanI,meanQ); } - } - // meanIold/=RXDCLENGTH; - // meanQold/=RXDCLENGTH; - printf("[BRF] TX DC (offI): %d => (%d,%d)\n",offIold,meanIold,meanQold); - - offI=-2048; - bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_LMS_DCOFF_I,offI); - for (i=0;i<10;i++) { - trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); - trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0); - } - for (meanI=meanQ=i=j=0;i<RXDCLENGTH;i++) { - switch (i&3) { - case 0: - meanI+=calib_buff[j++]; - break; - case 1: - meanQ+=calib_buff[j++]; - break; - case 2: - meanI-=calib_buff[j++]; - break; - case 3: - meanQ-=calib_buff[j++]; - break; + + printf("[BRF] RX DC: (%d,%d) => (%d,%d)\n",offIold,offQold,meanIold,meanQold); + bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_LMS_DCOFF_I,offIold); + bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_LMS_DCOFF_Q,offQold); + + // TX DC offset + // PUT TX as f_RX + fs/4 + // loop back BLADERF_LB_RF_LNA1 + bladerf_set_frequency(brf->dev,BLADERF_MODULE_TX, (unsigned int) device->openair0_cfg->rx_freq[0] + (unsigned int) device->openair0_cfg->sample_rate/4); + bladerf_set_loopback (brf->dev,BLADERF_LB_RF_LNA1); + + offIold=2048; + bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_LMS_DCOFF_I,offIold); + for (i=0; i<10; i++) { + trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); + trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0); } - } - // meanI/=RXDCLENGTH; - // meanQ/=RXDCLENGTH; - printf("[BRF] TX DC (offI): %d => (%d,%d)\n",offI,meanI,meanQ); - cnt = 0; - while (cnt++ < 12) { - - offInew=(offIold+offI)>>1; - if (meanI*meanI+meanQ*meanQ < meanIold*meanIold +meanQold*meanQold) { - printf("[BRF] TX DC (offI): ([%d,%d]) => %d : %d\n",offIold,offI,offInew,meanI*meanI+meanQ*meanQ); - meanIold = meanI; - meanQold = meanQ; - offIold = offI; + for (meanIold=meanQold=i=j=0; i<RXDCLENGTH; i++) { + switch (i&3) { + case 0: + meanIold+=calib_buff[j++]; + break; + case 1: + meanQold+=calib_buff[j++]; + break; + case 2: + meanIold-=calib_buff[j++]; + break; + case 3: + meanQold-=calib_buff[j++]; + break; + } } - offI = offInew; - bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_LMS_DCOFF_I,offI); + // meanIold/=RXDCLENGTH; + // meanQold/=RXDCLENGTH; + printf("[BRF] TX DC (offI): %d => (%d,%d)\n",offIold,meanIold,meanQold); - for (i=0;i<10;i++) { - trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); - trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0); - } - for (meanI=meanQ=i=j=0;i<RXDCLENGTH;i++) { - switch (i&3) { - case 0: - meanI+=calib_buff[j++]; - break; - case 1: - meanQ+=calib_buff[j++]; - break; - case 2: - meanI-=calib_buff[j++]; - break; - case 3: - meanQ-=calib_buff[j++]; - break; - } + offI=-2048; + bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_LMS_DCOFF_I,offI); + for (i=0; i<10; i++) { + trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); + trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0); } - // meanI/=RXDCLENGTH; - // meanQ/=RXDCLENGTH; - // printf("[BRF] TX DC (offI): %d => (%d,%d)\n",offI,meanI,meanQ); - } - - bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_LMS_DCOFF_I,offIold); - - offQold=2048; - bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_LMS_DCOFF_Q,offQold); - for (i=0;i<10;i++) { - trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); - trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0); - } - // project on fs/4 - for (meanIold=meanQold=i=j=0;i<RXDCLENGTH;i++) { - switch (i&3) { - case 0: - meanIold+=calib_buff[j++]; - break; - case 1: - meanQold+=calib_buff[j++]; - break; - case 2: - meanIold-=calib_buff[j++]; - break; - case 3: - meanQold-=calib_buff[j++]; - break; + for (meanI=meanQ=i=j=0; i<RXDCLENGTH; i++) { + switch (i&3) { + case 0: + meanI+=calib_buff[j++]; + break; + case 1: + meanQ+=calib_buff[j++]; + break; + case 2: + meanI-=calib_buff[j++]; + break; + case 3: + meanQ-=calib_buff[j++]; + break; + } } - } - // meanIold/=RXDCLENGTH; - // meanQold/=RXDCLENGTH; - printf("[BRF] TX DC (offQ): %d => (%d,%d)\n",offQold,meanIold,meanQold); - - offQ=-2048; - bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_LMS_DCOFF_Q,offQ); - for (i=0;i<10;i++) { - trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); - trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0); - } - for (meanI=meanQ=i=j=0;i<RXDCLENGTH;i++) { - switch (i&3) { - case 0: - meanI+=calib_buff[j++]; - break; - case 1: - meanQ+=calib_buff[j++]; - break; - case 2: - meanI-=calib_buff[j++]; - break; - case 3: - meanQ-=calib_buff[j++]; - break; + // meanI/=RXDCLENGTH; + // meanQ/=RXDCLENGTH; + printf("[BRF] TX DC (offI): %d => (%d,%d)\n",offI,meanI,meanQ); + cnt = 0; + while (cnt++ < 12) { + + offInew=(offIold+offI)>>1; + if (meanI*meanI+meanQ*meanQ < meanIold*meanIold +meanQold*meanQold) { + printf("[BRF] TX DC (offI): ([%d,%d]) => %d : %d\n",offIold,offI,offInew,meanI*meanI+meanQ*meanQ); + meanIold = meanI; + meanQold = meanQ; + offIold = offI; + } + offI = offInew; + bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_LMS_DCOFF_I,offI); + + for (i=0; i<10; i++) { + trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); + trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0); + } + for (meanI=meanQ=i=j=0; i<RXDCLENGTH; i++) { + switch (i&3) { + case 0: + meanI+=calib_buff[j++]; + break; + case 1: + meanQ+=calib_buff[j++]; + break; + case 2: + meanI-=calib_buff[j++]; + break; + case 3: + meanQ-=calib_buff[j++]; + break; + } + } + // meanI/=RXDCLENGTH; + // meanQ/=RXDCLENGTH; + // printf("[BRF] TX DC (offI): %d => (%d,%d)\n",offI,meanI,meanQ); } - } - // meanI/=RXDCLENGTH; - // meanQ/=RXDCLENGTH; - printf("[BRF] TX DC (offQ): %d => (%d,%d)\n",offQ,meanI,meanQ); - - cnt=0; - while (cnt++ < 12) { - - offQnew=(offQold+offQ)>>1; - if (meanI*meanI+meanQ*meanQ < meanIold*meanIold +meanQold*meanQold) { - printf("[BRF] TX DC (offQ): ([%d,%d]) => %d : %d\n",offQold,offQ,offQnew,meanI*meanI+meanQ*meanQ); - meanIold = meanI; - meanQold = meanQ; - offQold = offQ; - } - offQ = offQnew; - bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_LMS_DCOFF_Q,offQ); + bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_LMS_DCOFF_I,offIold); - for (i=0;i<10;i++) { - trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); - trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0); - } - for (meanI=meanQ=i=j=0;i<RXDCLENGTH;i++) { - switch (i&3) { - case 0: - meanI+=calib_buff[j++]; - break; - case 1: - meanQ+=calib_buff[j++]; - break; - case 2: - meanI-=calib_buff[j++]; - break; - case 3: - meanQ-=calib_buff[j++]; - break; - } + offQold=2048; + bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_LMS_DCOFF_Q,offQold); + for (i=0; i<10; i++) { + trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); + trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0); } - // meanI/=RXDCLENGTH; - // meanQ/=RXDCLENGTH; - // printf("[BRF] TX DC (offQ): %d => (%d,%d)\n",offQ,meanI,meanQ); - } - - printf("[BRF] TX DC: (%d,%d) => (%d,%d)\n",offIold,offQold,meanIold,meanQold); - - bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_LMS_DCOFF_Q,offQold); - - // TX IQ imbalance - for (loop=0;loop<2;loop++) { - offphaseold=4096; - bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_FPGA_PHASE,offphaseold); - for (i=0;i<10;i++) { - trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); - trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0); + // project on fs/4 + for (meanIold=meanQold=i=j=0; i<RXDCLENGTH; i++) { + switch (i&3) { + case 0: + meanIold+=calib_buff[j++]; + break; + case 1: + meanQold+=calib_buff[j++]; + break; + case 2: + meanIold-=calib_buff[j++]; + break; + case 3: + meanQold-=calib_buff[j++]; + break; + } } - // project on fs/8 (Image of TX signal in +ve frequencies) - for (meanIold=meanQold=i=j=0;i<RXDCLENGTH;i++) { - meanIold+= (calib_buff[j]*cos_fsover8[i&7] - calib_buff[j+1]*cos_fsover8[(i+2)&7])>>11; - meanQold+= (calib_buff[j]*cos_fsover8[(i+2)&7] + calib_buff[j+1]*cos_fsover8[i&7])>>11; - j+=2; - } - - meanIold/=RXDCLENGTH; - meanQold/=RXDCLENGTH; - printf("[BRF] TX IQ (offphase): %d => (%d,%d)\n",offphaseold,meanIold,meanQold); - - offphase=-4096; - bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_FPGA_PHASE,offphase); - for (i=0;i<10;i++) { - trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); - trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0); - } - // project on fs/8 (Image of TX signal in +ve frequencies) - for (meanI=meanQ=i=j=0;i<RXDCLENGTH;i++) { - meanI+= (calib_buff[j]*cos_fsover8[i&7] - calib_buff[j+1]*cos_fsover8[(i+2)&7])>>11; - meanQ+= (calib_buff[j]*cos_fsover8[(i+2)&7] + calib_buff[j+1]*cos_fsover8[i&7])>>11; - j+=2; - } - - meanI/=RXDCLENGTH; - meanQ/=RXDCLENGTH; - printf("[BRF] TX IQ (offphase): %d => (%d,%d)\n",offphase,meanI,meanQ); - - cnt=0; - while (cnt++ < 13) { - - offphasenew=(offphaseold+offphase)>>1; - printf("[BRF] TX IQ (offphase): ([%d,%d]) => %d : %d\n",offphaseold,offphase,offphasenew,meanI*meanI+meanQ*meanQ); - if (meanI*meanI+meanQ*meanQ < meanIold*meanIold +meanQold*meanQold) { - - - meanIold = meanI; - meanQold = meanQ; - offphaseold = offphase; - } - offphase = offphasenew; - bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_FPGA_PHASE,offphase); - - for (i=0;i<10;i++) { - trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); - trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0); - } - // project on fs/8 (Image of TX signal in +ve frequencies) - for (meanI=meanQ=i=j=0;i<RXDCLENGTH;i++) { - meanI+= (calib_buff[j]*cos_fsover8[i&7] - calib_buff[j+1]*cos_fsover8[(i+2)&7])>>11; - meanQ+= (calib_buff[j]*cos_fsover8[(i+2)&7] + calib_buff[j+1]*cos_fsover8[i&7])>>11; - j+=2; - } - meanI/=RXDCLENGTH; - meanQ/=RXDCLENGTH; - - // printf("[BRF] TX DC (offQ): %d => (%d,%d)\n",offQ,meanI,meanQ); - } - - printf("[BRF] TX IQ offphase: %d => (%d,%d)\n",offphaseold,meanIold,meanQold); - - bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_FPGA_PHASE,offphaseold); - - offgainold=4096; - bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_FPGA_GAIN,offgainold); - for (i=0;i<10;i++) { - trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); - trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0); - } - // project on fs/8 (Image of TX signal in +ve frequencies) - for (meanIold=meanQold=i=j=0;i<RXDCLENGTH;i++) { - meanIold+= (calib_buff[j]*cos_fsover8[i&7] - calib_buff[j+1]*cos_fsover8[(i+2)&7])>>11; - meanQold+= (calib_buff[j]*cos_fsover8[(i+2)&7] + calib_buff[j+1]*cos_fsover8[i&7])>>11; - j+=2; - } - - meanIold/=RXDCLENGTH; - meanQold/=RXDCLENGTH; - printf("[BRF] TX IQ (offgain): %d => (%d,%d)\n",offgainold,meanIold,meanQold); - - offgain=-4096; - bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_FPGA_GAIN,offgain); - for (i=0;i<10;i++) { - trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); - trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0); - } - // project on fs/8 (Image of TX signal in +ve frequencies) - for (meanI=meanQ=i=j=0;i<RXDCLENGTH;i++) { - meanI+= (calib_buff[j]*cos_fsover8[i&7] - calib_buff[j+1]*cos_fsover8[(i+2)&7])>>11; - meanQ+= (calib_buff[j]*cos_fsover8[(i+2)&7] + calib_buff[j+1]*cos_fsover8[i&7])>>11; - j+=2; - } - - meanI/=RXDCLENGTH; - meanQ/=RXDCLENGTH; - printf("[BRF] TX IQ (offgain): %d => (%d,%d)\n",offgain,meanI,meanQ); - - cnt=0; - while (cnt++ < 13) { - - offgainnew=(offgainold+offgain)>>1; - if (meanI*meanI+meanQ*meanQ < meanIold*meanIold +meanQold*meanQold) { - printf("[BRF] TX IQ (offgain): ([%d,%d]) => %d : %d\n",offgainold,offgain,offgainnew,meanI*meanI+meanQ*meanQ); - - meanIold = meanI; - meanQold = meanQ; - offgainold = offgain; - } - offgain = offgainnew; - bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_FPGA_GAIN,offgain); - - for (i=0;i<10;i++) { - trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); - trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0); - } - // project on fs/8 (Image of TX signal in +ve frequencies) - for (meanI=meanQ=i=j=0;i<RXDCLENGTH;i++) { - meanI+= (calib_buff[j]*cos_fsover8[i&7] - calib_buff[j+1]*cos_fsover8[(i+2)&7])>>11; - meanQ+= (calib_buff[j]*cos_fsover8[(i+2)&7] + calib_buff[j+1]*cos_fsover8[i&7])>>11; - j+=2; - } - meanI/=RXDCLENGTH; - meanQ/=RXDCLENGTH; - - // printf("[BRF] TX DC (offQ): %d => (%d,%d)\n",offQ,meanI,meanQ); - } - - printf("[BRF] TX IQ offgain: %d => (%d,%d)\n",offgainold,meanIold,meanQold); - - bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_FPGA_GAIN,offgainold); - } - - // RX IQ imbalance - for (loop=0;loop<2;loop++) { - offphaseold=4096; - bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_FPGA_PHASE,offphaseold); - for (i=0;i<10;i++) { - trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); - trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0); - } - // project on -3fs/8 (Image of TX signal in -ve frequencies) - for (meanIold=meanQold=i=j=0;i<RXDCLENGTH;i++) { - meanIold+= (calib_buff[j]*cos_3fsover8[i&7] - calib_buff[j+1]*cos_3fsover8[(i+2)&7])>>11; - meanQold+= (calib_buff[j]*cos_3fsover8[(i+2)&7] + calib_buff[j+1]*cos_3fsover8[i&7])>>11; - j+=2; - } - - meanIold/=RXDCLENGTH; - meanQold/=RXDCLENGTH; - printf("[BRF] RX IQ (offphase): %d => (%d,%d)\n",offphaseold,meanIold,meanQold); - - offphase=-4096; - bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_FPGA_PHASE,offphase); - for (i=0;i<10;i++) { - trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); - trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0); + // meanIold/=RXDCLENGTH; + // meanQold/=RXDCLENGTH; + printf("[BRF] TX DC (offQ): %d => (%d,%d)\n",offQold,meanIold,meanQold); + + offQ=-2048; + bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_LMS_DCOFF_Q,offQ); + for (i=0; i<10; i++) { + trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); + trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0); } - // project on -3fs/8 (Image of TX signal in -ve frequencies) - for (meanI=meanQ=i=j=0;i<RXDCLENGTH;i++) { - meanI+= (calib_buff[j]*cos_3fsover8[i&7] - calib_buff[j+1]*cos_3fsover8[(i+2)&7])>>11; - meanQ+= (calib_buff[j]*cos_3fsover8[(i+2)&7] + calib_buff[j+1]*cos_3fsover8[i&7])>>11; - j+=2; + for (meanI=meanQ=i=j=0; i<RXDCLENGTH; i++) { + switch (i&3) { + case 0: + meanI+=calib_buff[j++]; + break; + case 1: + meanQ+=calib_buff[j++]; + break; + case 2: + meanI-=calib_buff[j++]; + break; + case 3: + meanQ-=calib_buff[j++]; + break; + } } - - meanI/=RXDCLENGTH; - meanQ/=RXDCLENGTH; - printf("[BRF] RX IQ (offphase): %d => (%d,%d)\n",offphase,meanI,meanQ); - + // meanI/=RXDCLENGTH; + // meanQ/=RXDCLENGTH; + printf("[BRF] TX DC (offQ): %d => (%d,%d)\n",offQ,meanI,meanQ); + cnt=0; - while (cnt++ < 13) { - - offphasenew=(offphaseold+offphase)>>1; - printf("[BRF] RX IQ (offphase): ([%d,%d]) => %d : %d\n",offphaseold,offphase,offphasenew,meanI*meanI+meanQ*meanQ); - if (meanI*meanI+meanQ*meanQ < meanIold*meanIold +meanQold*meanQold) { - - - meanIold = meanI; - meanQold = meanQ; - offphaseold = offphase; - } - offphase = offphasenew; - bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_FPGA_PHASE,offphase); - - for (i=0;i<10;i++) { - trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); - trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0); - } - // project on -3fs/8 (Image of TX signal in -ve frequencies) - for (meanI=meanQ=i=j=0;i<RXDCLENGTH;i++) { - meanI+= (calib_buff[j]*cos_3fsover8[i&7] - calib_buff[j+1]*cos_3fsover8[(i+2)&7])>>11; - meanQ+= (calib_buff[j]*cos_3fsover8[(i+2)&7] + calib_buff[j+1]*cos_3fsover8[i&7])>>11; - j+=2; - } - meanI/=RXDCLENGTH; - meanQ/=RXDCLENGTH; - - // printf("[BRF] TX DC (offQ): %d => (%d,%d)\n",offQ,meanI,meanQ); + while (cnt++ < 12) { + + offQnew=(offQold+offQ)>>1; + if (meanI*meanI+meanQ*meanQ < meanIold*meanIold +meanQold*meanQold) { + printf("[BRF] TX DC (offQ): ([%d,%d]) => %d : %d\n",offQold,offQ,offQnew,meanI*meanI+meanQ*meanQ); + + meanIold = meanI; + meanQold = meanQ; + offQold = offQ; + } + offQ = offQnew; + bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_LMS_DCOFF_Q,offQ); + + for (i=0; i<10; i++) { + trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); + trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0); + } + for (meanI=meanQ=i=j=0; i<RXDCLENGTH; i++) { + switch (i&3) { + case 0: + meanI+=calib_buff[j++]; + break; + case 1: + meanQ+=calib_buff[j++]; + break; + case 2: + meanI-=calib_buff[j++]; + break; + case 3: + meanQ-=calib_buff[j++]; + break; + } + } + // meanI/=RXDCLENGTH; + // meanQ/=RXDCLENGTH; + // printf("[BRF] TX DC (offQ): %d => (%d,%d)\n",offQ,meanI,meanQ); } - - printf("[BRF] RX IQ offphase: %d => (%d,%d)\n",offphaseold,meanIold,meanQold); - - bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_FPGA_PHASE,offphaseold); - - offgainold=4096; - bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_FPGA_GAIN,offgainold); - for (i=0;i<10;i++) { - trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); - trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0,0); - } - // project on -3fs/8 (Image of TX signal in +ve frequencies) - for (meanIold=meanQold=i=j=0;i<RXDCLENGTH;i++) { - meanIold+= (calib_buff[j]*cos_3fsover8[i&7] - calib_buff[j+1]*cos_3fsover8[(i+2)&7])>>11; - meanQold+= (calib_buff[j]*cos_3fsover8[(i+2)&7] + calib_buff[j+1]*cos_3fsover8[i&7])>>11; - j+=2; - } - - meanIold/=RXDCLENGTH; - meanQold/=RXDCLENGTH; - printf("[BRF] RX IQ (offgain): %d => (%d,%d)\n",offgainold,meanIold,meanQold); - - offgain=-4096; - bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_FPGA_GAIN,offgain); - for (i=0;i<10;i++) { - trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); - trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0); - } - // project on 3fs/8 (Image of TX signal in -ve frequencies) - for (meanI=meanQ=i=j=0;i<RXDCLENGTH;i++) { - meanI+= (calib_buff[j]*cos_3fsover8[i&7] - calib_buff[j+1]*cos_3fsover8[(i+2)&7])>>11; - meanQ+= (calib_buff[j]*cos_3fsover8[(i+2)&7] + calib_buff[j+1]*cos_3fsover8[i&7])>>11; - j+=2; + + printf("[BRF] TX DC: (%d,%d) => (%d,%d)\n",offIold,offQold,meanIold,meanQold); + + bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_LMS_DCOFF_Q,offQold); + + // TX IQ imbalance + for (loop=0; loop<2; loop++) { + offphaseold=4096; + bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_FPGA_PHASE,offphaseold); + for (i=0; i<10; i++) { + trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); + trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0); + } + // project on fs/8 (Image of TX signal in +ve frequencies) + for (meanIold=meanQold=i=j=0; i<RXDCLENGTH; i++) { + meanIold+= (calib_buff[j]*cos_fsover8[i&7] - calib_buff[j+1]*cos_fsover8[(i+2)&7])>>11; + meanQold+= (calib_buff[j]*cos_fsover8[(i+2)&7] + calib_buff[j+1]*cos_fsover8[i&7])>>11; + j+=2; + } + + meanIold/=RXDCLENGTH; + meanQold/=RXDCLENGTH; + printf("[BRF] TX IQ (offphase): %d => (%d,%d)\n",offphaseold,meanIold,meanQold); + + offphase=-4096; + bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_FPGA_PHASE,offphase); + for (i=0; i<10; i++) { + trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); + trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0); + } + // project on fs/8 (Image of TX signal in +ve frequencies) + for (meanI=meanQ=i=j=0; i<RXDCLENGTH; i++) { + meanI+= (calib_buff[j]*cos_fsover8[i&7] - calib_buff[j+1]*cos_fsover8[(i+2)&7])>>11; + meanQ+= (calib_buff[j]*cos_fsover8[(i+2)&7] + calib_buff[j+1]*cos_fsover8[i&7])>>11; + j+=2; + } + + meanI/=RXDCLENGTH; + meanQ/=RXDCLENGTH; + printf("[BRF] TX IQ (offphase): %d => (%d,%d)\n",offphase,meanI,meanQ); + + cnt=0; + while (cnt++ < 13) { + + offphasenew=(offphaseold+offphase)>>1; + printf("[BRF] TX IQ (offphase): ([%d,%d]) => %d : %d\n",offphaseold,offphase,offphasenew,meanI*meanI+meanQ*meanQ); + if (meanI*meanI+meanQ*meanQ < meanIold*meanIold +meanQold*meanQold) { + + + meanIold = meanI; + meanQold = meanQ; + offphaseold = offphase; + } + offphase = offphasenew; + bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_FPGA_PHASE,offphase); + + for (i=0; i<10; i++) { + trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); + trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0); + } + // project on fs/8 (Image of TX signal in +ve frequencies) + for (meanI=meanQ=i=j=0; i<RXDCLENGTH; i++) { + meanI+= (calib_buff[j]*cos_fsover8[i&7] - calib_buff[j+1]*cos_fsover8[(i+2)&7])>>11; + meanQ+= (calib_buff[j]*cos_fsover8[(i+2)&7] + calib_buff[j+1]*cos_fsover8[i&7])>>11; + j+=2; + } + meanI/=RXDCLENGTH; + meanQ/=RXDCLENGTH; + + // printf("[BRF] TX DC (offQ): %d => (%d,%d)\n",offQ,meanI,meanQ); + } + + printf("[BRF] TX IQ offphase: %d => (%d,%d)\n",offphaseold,meanIold,meanQold); + + bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_FPGA_PHASE,offphaseold); + + offgainold=4096; + bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_FPGA_GAIN,offgainold); + for (i=0; i<10; i++) { + trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); + trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0); + } + // project on fs/8 (Image of TX signal in +ve frequencies) + for (meanIold=meanQold=i=j=0; i<RXDCLENGTH; i++) { + meanIold+= (calib_buff[j]*cos_fsover8[i&7] - calib_buff[j+1]*cos_fsover8[(i+2)&7])>>11; + meanQold+= (calib_buff[j]*cos_fsover8[(i+2)&7] + calib_buff[j+1]*cos_fsover8[i&7])>>11; + j+=2; + } + + meanIold/=RXDCLENGTH; + meanQold/=RXDCLENGTH; + printf("[BRF] TX IQ (offgain): %d => (%d,%d)\n",offgainold,meanIold,meanQold); + + offgain=-4096; + bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_FPGA_GAIN,offgain); + for (i=0; i<10; i++) { + trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); + trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0); + } + // project on fs/8 (Image of TX signal in +ve frequencies) + for (meanI=meanQ=i=j=0; i<RXDCLENGTH; i++) { + meanI+= (calib_buff[j]*cos_fsover8[i&7] - calib_buff[j+1]*cos_fsover8[(i+2)&7])>>11; + meanQ+= (calib_buff[j]*cos_fsover8[(i+2)&7] + calib_buff[j+1]*cos_fsover8[i&7])>>11; + j+=2; + } + + meanI/=RXDCLENGTH; + meanQ/=RXDCLENGTH; + printf("[BRF] TX IQ (offgain): %d => (%d,%d)\n",offgain,meanI,meanQ); + + cnt=0; + while (cnt++ < 13) { + + offgainnew=(offgainold+offgain)>>1; + if (meanI*meanI+meanQ*meanQ < meanIold*meanIold +meanQold*meanQold) { + printf("[BRF] TX IQ (offgain): ([%d,%d]) => %d : %d\n",offgainold,offgain,offgainnew,meanI*meanI+meanQ*meanQ); + + meanIold = meanI; + meanQold = meanQ; + offgainold = offgain; + } + offgain = offgainnew; + bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_FPGA_GAIN,offgain); + + for (i=0; i<10; i++) { + trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); + trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0); + } + // project on fs/8 (Image of TX signal in +ve frequencies) + for (meanI=meanQ=i=j=0; i<RXDCLENGTH; i++) { + meanI+= (calib_buff[j]*cos_fsover8[i&7] - calib_buff[j+1]*cos_fsover8[(i+2)&7])>>11; + meanQ+= (calib_buff[j]*cos_fsover8[(i+2)&7] + calib_buff[j+1]*cos_fsover8[i&7])>>11; + j+=2; + } + meanI/=RXDCLENGTH; + meanQ/=RXDCLENGTH; + + // printf("[BRF] TX DC (offQ): %d => (%d,%d)\n",offQ,meanI,meanQ); + } + + printf("[BRF] TX IQ offgain: %d => (%d,%d)\n",offgainold,meanIold,meanQold); + + bladerf_set_correction(brf->dev,BLADERF_MODULE_TX,BLADERF_CORR_FPGA_GAIN,offgainold); } - - meanI/=RXDCLENGTH; - meanQ/=RXDCLENGTH; - printf("[BRF] RX IQ (offgain): %d => (%d,%d)\n",offgain,meanI,meanQ); - - cnt=0; - while (cnt++ < 13) { - - offgainnew=(offgainold+offgain)>>1; - if (meanI*meanI+meanQ*meanQ < meanIold*meanIold +meanQold*meanQold) { - printf("[BRF] RX IQ (offgain): ([%d,%d]) => %d : %d\n",offgainold,offgain,offgainnew,meanI*meanI+meanQ*meanQ); - - meanIold = meanI; - meanQold = meanQ; - offgainold = offgain; - } - offgain = offgainnew; - bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_FPGA_GAIN,offgain); - - for (i=0;i<10;i++) { - trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); - trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0); - } - // project on -3fs/8 (Image of TX signal in -ve frequencies) - for (meanI=meanQ=i=j=0;i<RXDCLENGTH;i++) { - meanI+= (calib_buff[j]*cos_3fsover8[i&7] - calib_buff[j+1]*cos_3fsover8[(i+2)&7])>>11; - meanQ+= (calib_buff[j]*cos_3fsover8[(i+2)&7] + calib_buff[j+1]*cos_3fsover8[i&7])>>11; - j+=2; - } - meanI/=RXDCLENGTH; - meanQ/=RXDCLENGTH; - - // printf("[BRF] TX DC (offQ): %d => (%d,%d)\n",offQ,meanI,meanQ); + + // RX IQ imbalance + for (loop=0; loop<2; loop++) { + offphaseold=4096; + bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_FPGA_PHASE,offphaseold); + for (i=0; i<10; i++) { + trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); + trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0); + } + // project on -3fs/8 (Image of TX signal in -ve frequencies) + for (meanIold=meanQold=i=j=0; i<RXDCLENGTH; i++) { + meanIold+= (calib_buff[j]*cos_3fsover8[i&7] - calib_buff[j+1]*cos_3fsover8[(i+2)&7])>>11; + meanQold+= (calib_buff[j]*cos_3fsover8[(i+2)&7] + calib_buff[j+1]*cos_3fsover8[i&7])>>11; + j+=2; + } + + meanIold/=RXDCLENGTH; + meanQold/=RXDCLENGTH; + printf("[BRF] RX IQ (offphase): %d => (%d,%d)\n",offphaseold,meanIold,meanQold); + + offphase=-4096; + bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_FPGA_PHASE,offphase); + for (i=0; i<10; i++) { + trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); + trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0); + } + // project on -3fs/8 (Image of TX signal in -ve frequencies) + for (meanI=meanQ=i=j=0; i<RXDCLENGTH; i++) { + meanI+= (calib_buff[j]*cos_3fsover8[i&7] - calib_buff[j+1]*cos_3fsover8[(i+2)&7])>>11; + meanQ+= (calib_buff[j]*cos_3fsover8[(i+2)&7] + calib_buff[j+1]*cos_3fsover8[i&7])>>11; + j+=2; + } + + meanI/=RXDCLENGTH; + meanQ/=RXDCLENGTH; + printf("[BRF] RX IQ (offphase): %d => (%d,%d)\n",offphase,meanI,meanQ); + + cnt=0; + while (cnt++ < 13) { + + offphasenew=(offphaseold+offphase)>>1; + printf("[BRF] RX IQ (offphase): ([%d,%d]) => %d : %d\n",offphaseold,offphase,offphasenew,meanI*meanI+meanQ*meanQ); + if (meanI*meanI+meanQ*meanQ < meanIold*meanIold +meanQold*meanQold) { + + + meanIold = meanI; + meanQold = meanQ; + offphaseold = offphase; + } + offphase = offphasenew; + bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_FPGA_PHASE,offphase); + + for (i=0; i<10; i++) { + trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); + trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0); + } + // project on -3fs/8 (Image of TX signal in -ve frequencies) + for (meanI=meanQ=i=j=0; i<RXDCLENGTH; i++) { + meanI+= (calib_buff[j]*cos_3fsover8[i&7] - calib_buff[j+1]*cos_3fsover8[(i+2)&7])>>11; + meanQ+= (calib_buff[j]*cos_3fsover8[(i+2)&7] + calib_buff[j+1]*cos_3fsover8[i&7])>>11; + j+=2; + } + meanI/=RXDCLENGTH; + meanQ/=RXDCLENGTH; + + // printf("[BRF] TX DC (offQ): %d => (%d,%d)\n",offQ,meanI,meanQ); + } + + printf("[BRF] RX IQ offphase: %d => (%d,%d)\n",offphaseold,meanIold,meanQold); + + bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_FPGA_PHASE,offphaseold); + + offgainold=4096; + bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_FPGA_GAIN,offgainold); + for (i=0; i<10; i++) { + trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); + trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0,0); + } + // project on -3fs/8 (Image of TX signal in +ve frequencies) + for (meanIold=meanQold=i=j=0; i<RXDCLENGTH; i++) { + meanIold+= (calib_buff[j]*cos_3fsover8[i&7] - calib_buff[j+1]*cos_3fsover8[(i+2)&7])>>11; + meanQold+= (calib_buff[j]*cos_3fsover8[(i+2)&7] + calib_buff[j+1]*cos_3fsover8[i&7])>>11; + j+=2; + } + + meanIold/=RXDCLENGTH; + meanQold/=RXDCLENGTH; + printf("[BRF] RX IQ (offgain): %d => (%d,%d)\n",offgainold,meanIold,meanQold); + + offgain=-4096; + bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_FPGA_GAIN,offgain); + for (i=0; i<10; i++) { + trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); + trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0); + } + // project on 3fs/8 (Image of TX signal in -ve frequencies) + for (meanI=meanQ=i=j=0; i<RXDCLENGTH; i++) { + meanI+= (calib_buff[j]*cos_3fsover8[i&7] - calib_buff[j+1]*cos_3fsover8[(i+2)&7])>>11; + meanQ+= (calib_buff[j]*cos_3fsover8[(i+2)&7] + calib_buff[j+1]*cos_3fsover8[i&7])>>11; + j+=2; + } + + meanI/=RXDCLENGTH; + meanQ/=RXDCLENGTH; + printf("[BRF] RX IQ (offgain): %d => (%d,%d)\n",offgain,meanI,meanQ); + + cnt=0; + while (cnt++ < 13) { + + offgainnew=(offgainold+offgain)>>1; + if (meanI*meanI+meanQ*meanQ < meanIold*meanIold +meanQold*meanQold) { + printf("[BRF] RX IQ (offgain): ([%d,%d]) => %d : %d\n",offgainold,offgain,offgainnew,meanI*meanI+meanQ*meanQ); + + meanIold = meanI; + meanQold = meanQ; + offgainold = offgain; + } + offgain = offgainnew; + bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_FPGA_GAIN,offgain); + + for (i=0; i<10; i++) { + trx_brf_read(device, &ptimestamp, (void **)&calib_buffp, RXDCLENGTH, 0); + trx_brf_write(device,ptimestamp+5*RXDCLENGTH, (void **)&calib_tx_buffp, RXDCLENGTH, 0, 0); + } + // project on -3fs/8 (Image of TX signal in -ve frequencies) + for (meanI=meanQ=i=j=0; i<RXDCLENGTH; i++) { + meanI+= (calib_buff[j]*cos_3fsover8[i&7] - calib_buff[j+1]*cos_3fsover8[(i+2)&7])>>11; + meanQ+= (calib_buff[j]*cos_3fsover8[(i+2)&7] + calib_buff[j+1]*cos_3fsover8[i&7])>>11; + j+=2; + } + meanI/=RXDCLENGTH; + meanQ/=RXDCLENGTH; + + // printf("[BRF] TX DC (offQ): %d => (%d,%d)\n",offQ,meanI,meanQ); + } + + printf("[BRF] RX IQ offgain: %d => (%d,%d)\n",offgainold,meanIold,meanQold); + + bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_FPGA_GAIN,offgainold); } - - printf("[BRF] RX IQ offgain: %d => (%d,%d)\n",offgainold,meanIold,meanQold); - - bladerf_set_correction(brf->dev,BLADERF_MODULE_RX,BLADERF_CORR_FPGA_GAIN,offgainold); - } - - bladerf_set_frequency(brf->dev,BLADERF_MODULE_TX, (unsigned int) device->openair0_cfg->tx_freq[0]); - bladerf_set_loopback(brf->dev,BLADERF_LB_NONE); - bladerf_set_gain(brf->dev, BLADERF_MODULE_RX, (unsigned int) device->openair0_cfg->rx_gain[0]-device->openair0_cfg[0].rx_gain_offset[0]); - bladerf_set_gain(brf->dev, BLADERF_MODULE_TX, (unsigned int) device->openair0_cfg->tx_gain[0]); - // LOG_M("blade_rf_test.m","rxs",calib_buff,RXDCLENGTH,1,1); + + bladerf_set_frequency(brf->dev,BLADERF_MODULE_TX, (unsigned int) device->openair0_cfg->tx_freq[0]); + bladerf_set_loopback(brf->dev,BLADERF_LB_NONE); + bladerf_set_gain(brf->dev, BLADERF_MODULE_RX, (unsigned int) device->openair0_cfg->rx_gain[0]-device->openair0_cfg[0].rx_gain_offset[0]); + bladerf_set_gain(brf->dev, BLADERF_MODULE_TX, (unsigned int) device->openair0_cfg->tx_gain[0]); + // LOG_M("blade_rf_test.m","rxs",calib_buff,RXDCLENGTH,1,1); } -/*! \brief Initialize Openair BLADERF target. It returns 0 if OK +/*! \brief Initialize Openair BLADERF target. It returns 0 if OK * \param device the hardware to use * \param openair0_cfg RF frontend parameters set by application * \returns 0 on success */ int device_init(openair0_device *device, openair0_config_t *openair0_cfg) { - int status; - brf_state_t *brf = (brf_state_t*)malloc(sizeof(brf_state_t)); - memset(brf, 0, sizeof(brf_state_t)); - /* device specific */ - //openair0_cfg->txlaunch_wait = 1;//manage when TX processing is triggered - //openair0_cfg->txlaunch_wait_slotcount = 1; //manage when TX processing is triggered - openair0_cfg->iq_txshift = 0;// shift - openair0_cfg->iq_rxrescale = 15;//rescale iqs - - // init required params - switch ((int)openair0_cfg->sample_rate) { - case 30720000: - openair0_cfg->samples_per_packet = 2048; - openair0_cfg->tx_sample_advance = 0; - break; - case 15360000: - openair0_cfg->samples_per_packet = 2048; - openair0_cfg->tx_sample_advance = 0; - break; - case 7680000: - openair0_cfg->samples_per_packet = 1024; - openair0_cfg->tx_sample_advance = 0; - break; - case 1920000: - openair0_cfg->samples_per_packet = 256; - openair0_cfg->tx_sample_advance = 50; - break; - default: - printf("Error: unknown sampling rate %f\n",openair0_cfg->sample_rate); - exit(-1); - break; - } - openair0_cfg->iq_txshift= 0; - openair0_cfg->iq_rxrescale = 15; /*not sure*/ - openair0_cfg->rx_gain_calib_table = calib_table_fx4; - - // The number of buffers to use in the underlying data stream - brf->num_buffers = 128; - // the size of the underlying stream buffers, in samples - brf->buffer_size = (unsigned int) openair0_cfg->samples_per_packet;//*sizeof(int32_t); // buffer size = 4096 for sample_len of 1024 - brf->num_transfers = 16; - brf->rx_timeout_ms = 0; - brf->tx_timeout_ms = 0; - brf->sample_rate=(unsigned int)openair0_cfg->sample_rate; - - memset(&brf->meta_rx, 0, sizeof(brf->meta_rx)); - memset(&brf->meta_tx, 0, sizeof(brf->meta_tx)); - - printf("\n[BRF] sampling_rate %d, num_buffers %d, buffer_size %d, num transfer %d, timeout_ms (rx %d, tx %d)\n", - brf->sample_rate, brf->num_buffers, brf->buffer_size,brf->num_transfers, brf->rx_timeout_ms, brf->tx_timeout_ms); - - if ((status=bladerf_open(&brf->dev, "")) != 0 ) { - fprintf(stderr,"Failed to open brf device: %s\n",bladerf_strerror(status)); - brf_error(status); - } - printf("[BRF] init dev %p\n", brf->dev); - switch(bladerf_device_speed(brf->dev)){ - case BLADERF_DEVICE_SPEED_SUPER: - printf("[BRF] Device operates at max speed\n"); - break; - default: - printf("[BRF] Device does not operates at max speed, change the USB port\n"); - brf_error(BLADERF_ERR_UNSUPPORTED); - } - // RX - // Example of CLI output: RX Frequency: 2539999999Hz - - - if ((status=bladerf_set_gain_mode(brf->dev, BLADERF_MODULE_RX, BLADERF_GAIN_MGC))) { - fprintf(stderr, "[BRF] Failed to disable AGC\n"); - brf_error(status); - } - - if ((status=bladerf_set_frequency(brf->dev, BLADERF_MODULE_RX, (unsigned int) openair0_cfg->rx_freq[0])) != 0){ - fprintf(stderr,"Failed to set RX frequency: %s\n",bladerf_strerror(status)); - brf_error(status); - } else - printf("[BRF] set RX frequency to %u\n",(unsigned int)openair0_cfg->rx_freq[0]); - - - - unsigned int actual_value=0; - if ((status=bladerf_set_sample_rate(brf->dev, BLADERF_MODULE_RX, (unsigned int) openair0_cfg->sample_rate, &actual_value)) != 0){ - fprintf(stderr,"Failed to set RX sample rate: %s\n", bladerf_strerror(status)); - brf_error(status); - }else - printf("[BRF] set RX sample rate to %u, %u\n", (unsigned int) openair0_cfg->sample_rate, actual_value); - - - if ((status=bladerf_set_bandwidth(brf->dev, BLADERF_MODULE_RX, (unsigned int) openair0_cfg->rx_bw*2, &actual_value)) != 0){ - fprintf(stderr,"Failed to set RX bandwidth: %s\n", bladerf_strerror(status)); - brf_error(status); - }else - printf("[BRF] set RX bandwidth to %u, %u\n",(unsigned int)openair0_cfg->rx_bw*2, actual_value); - - set_rx_gain_offset(&openair0_cfg[0],0); - if ((status=bladerf_set_gain(brf->dev, BLADERF_MODULE_RX, (int) openair0_cfg->rx_gain[0]-openair0_cfg[0].rx_gain_offset[0])) != 0) { - fprintf(stderr,"Failed to set RX gain: %s\n",bladerf_strerror(status)); - brf_error(status); - } else - printf("[BRF] set RX gain to %d (%d)\n",(int)(openair0_cfg->rx_gain[0]-openair0_cfg[0].rx_gain_offset[0]),(int)openair0_cfg[0].rx_gain_offset[0]); - - // TX - - if ((status=bladerf_set_frequency(brf->dev, BLADERF_MODULE_TX, (unsigned int) openair0_cfg->tx_freq[0])) != 0){ - fprintf(stderr,"Failed to set TX frequency: %s\n",bladerf_strerror(status)); - brf_error(status); - }else - printf("[BRF] set TX Frequency to %u\n", (unsigned int) openair0_cfg->tx_freq[0]); - - if ((status=bladerf_set_sample_rate(brf->dev, BLADERF_MODULE_TX, (unsigned int) openair0_cfg->sample_rate, NULL)) != 0){ - fprintf(stderr,"Failed to set TX sample rate: %s\n", bladerf_strerror(status)); - brf_error(status); - }else - printf("[BRF] set TX sampling rate to %u \n", (unsigned int) openair0_cfg->sample_rate); - - if ((status=bladerf_set_bandwidth(brf->dev, BLADERF_MODULE_TX,(unsigned int)openair0_cfg->tx_bw*2, NULL)) != 0){ - fprintf(stderr, "Failed to set TX bandwidth: %s\n", bladerf_strerror(status)); - brf_error(status); - }else - printf("[BRF] set TX bandwidth to %u \n", (unsigned int) openair0_cfg->tx_bw*2); - - if ((status=bladerf_set_gain(brf->dev, BLADERF_MODULE_TX, (int) openair0_cfg->tx_gain[0])) != 0) { - fprintf(stderr,"Failed to set TX gain: %s\n",bladerf_strerror(status)); - brf_error(status); - }else - printf("[BRF] set the TX gain to %d\n", (int)openair0_cfg->tx_gain[0]); - - - /* Configure the device's TX module for use with the sync interface. - * SC16 Q11 samples *with* metadata are used. */ - if ((status=bladerf_sync_config(brf->dev, BLADERF_MODULE_TX,BLADERF_FORMAT_SC16_Q11_META,brf->num_buffers,brf->buffer_size,brf->num_transfers,brf->tx_timeout_ms)) != 0 ) { - fprintf(stderr,"Failed to configure TX sync interface: %s\n", bladerf_strerror(status)); - brf_error(status); - }else - printf("[BRF] configured TX sync interface \n"); - -/* Configure the device's RX module for use with the sync interface. - * SC16 Q11 samples *with* metadata are used. */ - if ((status=bladerf_sync_config(brf->dev, BLADERF_MODULE_RX, BLADERF_FORMAT_SC16_Q11_META,brf->num_buffers,brf->buffer_size,brf->num_transfers,brf->rx_timeout_ms)) != 0 ) { - fprintf(stderr,"Failed to configure RX sync interface: %s\n", bladerf_strerror(status)); - brf_error(status); - }else - printf("[BRF] configured Rx sync interface \n"); - - - /* We must always enable the TX module after calling bladerf_sync_config(), and - * before attempting to TX samples via bladerf_sync_tx(). */ - if ((status=bladerf_enable_module(brf->dev, BLADERF_MODULE_TX, true)) != 0) { - fprintf(stderr,"Failed to enable TX module: %s\n", bladerf_strerror(status)); - brf_error(status); - } else - printf("[BRF] TX module enabled \n"); - - /* We must always enable the RX module after calling bladerf_sync_config(), and - * before attempting to RX samples via bladerf_sync_rx(). */ - if ((status=bladerf_enable_module(brf->dev, BLADERF_MODULE_RX, true)) != 0) { - fprintf(stderr,"Failed to enable RX module: %s\n", bladerf_strerror(status)); - brf_error(status); - }else - printf("[BRF] RX module enabled \n"); - - // calibrate - - if ((status=bladerf_calibrate_dc(brf->dev, BLADERF_DC_CAL_LPF_TUNING)) != 0 || - (status=bladerf_calibrate_dc(brf->dev, BLADERF_DC_CAL_TX_LPF)) != 0 || - (status=bladerf_calibrate_dc(brf->dev, BLADERF_DC_CAL_RX_LPF)) != 0 || - (status=bladerf_calibrate_dc(brf->dev, BLADERF_DC_CAL_RXVGA2)) != 0) { - fprintf(stderr, "[BRF] error calibrating\n"); - brf_error(status); - } else - printf("[BRF] calibration OK\n"); - - bladerf_log_set_verbosity(get_brf_log_level(openair0_cfg->log_level)); - - printf("BLADERF: Initializing openair0_device\n"); - device->Mod_id = num_devices++; - device->type = BLADERF_DEV; - device->trx_start_func = trx_brf_start; - device->trx_end_func = trx_brf_end; - device->trx_read_func = trx_brf_read; - device->trx_write_func = trx_brf_write; - device->trx_get_stats_func = trx_brf_get_stats; - device->trx_reset_stats_func = trx_brf_reset_stats; - device->trx_stop_func = trx_brf_stop; - device->trx_set_freq_func = trx_brf_set_freq; - device->trx_set_gains_func = trx_brf_set_gains; - device->openair0_cfg = openair0_cfg; - device->priv = (void *)brf; - - calibrate_rf(device); - - // memcpy((void*)&device->openair0_cfg,(void*)&openair0_cfg[0],sizeof(openair0_config_t)); - - if ((status=bladerf_enable_module(brf->dev, BLADERF_MODULE_TX, false)) != 0) { - fprintf(stderr,"Failed to enable TX module: %s\n", bladerf_strerror(status)); - abort(); - } - if ((status=bladerf_enable_module(brf->dev, BLADERF_MODULE_RX, false)) != 0) { - fprintf(stderr,"Failed to enable RX module: %s\n", bladerf_strerror(status)); - abort(); - } - - return 0; + int status; + brf_state_t *brf = (brf_state_t*)malloc(sizeof(brf_state_t)); + memset(brf, 0, sizeof(brf_state_t)); + /* device specific */ + //openair0_cfg->txlaunch_wait = 1;//manage when TX processing is triggered + //openair0_cfg->txlaunch_wait_slotcount = 1; //manage when TX processing is triggered + openair0_cfg->iq_txshift = 0;// shift + openair0_cfg->iq_rxrescale = 15;//rescale iqs + + // init required params + switch ((int)openair0_cfg->sample_rate) { + case 30720000: + openair0_cfg->samples_per_packet = 2048; + openair0_cfg->tx_sample_advance = 0; + break; + case 15360000: + openair0_cfg->samples_per_packet = 2048; + openair0_cfg->tx_sample_advance = 0; + break; + case 7680000: + openair0_cfg->samples_per_packet = 1024; + openair0_cfg->tx_sample_advance = 0; + break; + case 1920000: + openair0_cfg->samples_per_packet = 256; + openair0_cfg->tx_sample_advance = 50; + break; + default: + printf("Error: unknown sampling rate %f\n",openair0_cfg->sample_rate); + exit(-1); + break; + } + openair0_cfg->iq_txshift= 0; + openair0_cfg->iq_rxrescale = 15; /*not sure*/ + openair0_cfg->rx_gain_calib_table = calib_table_fx4; + + // The number of buffers to use in the underlying data stream + brf->num_buffers = 128; + // the size of the underlying stream buffers, in samples + brf->buffer_size = (unsigned int) openair0_cfg->samples_per_packet;//*sizeof(int32_t); // buffer size = 4096 for sample_len of 1024 + brf->num_transfers = 16; + brf->rx_timeout_ms = 0; + brf->tx_timeout_ms = 0; + brf->sample_rate=(unsigned int)openair0_cfg->sample_rate; + + memset(&brf->meta_rx, 0, sizeof(brf->meta_rx)); + memset(&brf->meta_tx, 0, sizeof(brf->meta_tx)); + + printf("\n[BRF] sampling_rate %u, num_buffers %u, buffer_size %u, num transfer %u, timeout_ms (rx %u, tx %u)\n", + brf->sample_rate, brf->num_buffers, brf->buffer_size,brf->num_transfers, brf->rx_timeout_ms, brf->tx_timeout_ms); + + if ((status=bladerf_open(&brf->dev, "")) != 0 ) { + fprintf(stderr,"Failed to open brf device: %s\n",bladerf_strerror(status)); + brf_error(status); + } + printf("[BRF] init dev %p\n", brf->dev); + switch(bladerf_device_speed(brf->dev)) { + case BLADERF_DEVICE_SPEED_SUPER: + printf("[BRF] Device operates at max speed\n"); + break; + default: + printf("[BRF] Device does not operates at max speed, change the USB port\n"); + brf_error(BLADERF_ERR_UNSUPPORTED); + } + // RX + // Example of CLI output: RX Frequency: 2539999999Hz + + + if ((status=bladerf_set_gain_mode(brf->dev, BLADERF_MODULE_RX, BLADERF_GAIN_MGC))) { + fprintf(stderr, "[BRF] Failed to disable AGC\n"); + brf_error(status); + } + + if ((status=bladerf_set_frequency(brf->dev, BLADERF_MODULE_RX, (unsigned int) openair0_cfg->rx_freq[0])) != 0) { + fprintf(stderr,"Failed to set RX frequency: %s\n",bladerf_strerror(status)); + brf_error(status); + } else + printf("[BRF] set RX frequency to %u\n",(unsigned int)openair0_cfg->rx_freq[0]); + + + + unsigned int actual_value=0; + if ((status=bladerf_set_sample_rate(brf->dev, BLADERF_MODULE_RX, (unsigned int) openair0_cfg->sample_rate, &actual_value)) != 0) { + fprintf(stderr,"Failed to set RX sample rate: %s\n", bladerf_strerror(status)); + brf_error(status); + } else + printf("[BRF] set RX sample rate to %u, %u\n", (unsigned int) openair0_cfg->sample_rate, actual_value); + + + if ((status=bladerf_set_bandwidth(brf->dev, BLADERF_MODULE_RX, (unsigned int) openair0_cfg->rx_bw*2, &actual_value)) != 0) { + fprintf(stderr,"Failed to set RX bandwidth: %s\n", bladerf_strerror(status)); + brf_error(status); + } else + printf("[BRF] set RX bandwidth to %u, %u\n",(unsigned int)openair0_cfg->rx_bw*2, actual_value); + + set_rx_gain_offset(&openair0_cfg[0],0); + if ((status=bladerf_set_gain(brf->dev, BLADERF_MODULE_RX, (int) openair0_cfg->rx_gain[0]-openair0_cfg[0].rx_gain_offset[0])) != 0) { + fprintf(stderr,"Failed to set RX gain: %s\n",bladerf_strerror(status)); + brf_error(status); + } else + printf("[BRF] set RX gain to %d (%d)\n",(int)(openair0_cfg->rx_gain[0]-openair0_cfg[0].rx_gain_offset[0]),(int)openair0_cfg[0].rx_gain_offset[0]); + + // TX + + if ((status=bladerf_set_frequency(brf->dev, BLADERF_MODULE_TX, (unsigned int) openair0_cfg->tx_freq[0])) != 0) { + fprintf(stderr,"Failed to set TX frequency: %s\n",bladerf_strerror(status)); + brf_error(status); + } else + printf("[BRF] set TX Frequency to %u\n", (unsigned int) openair0_cfg->tx_freq[0]); + + if ((status=bladerf_set_sample_rate(brf->dev, BLADERF_MODULE_TX, (unsigned int) openair0_cfg->sample_rate, NULL)) != 0) { + fprintf(stderr,"Failed to set TX sample rate: %s\n", bladerf_strerror(status)); + brf_error(status); + } else + printf("[BRF] set TX sampling rate to %u \n", (unsigned int) openair0_cfg->sample_rate); + + if ((status=bladerf_set_bandwidth(brf->dev, BLADERF_MODULE_TX,(unsigned int)openair0_cfg->tx_bw*2, NULL)) != 0) { + fprintf(stderr, "Failed to set TX bandwidth: %s\n", bladerf_strerror(status)); + brf_error(status); + } else + printf("[BRF] set TX bandwidth to %u \n", (unsigned int) openair0_cfg->tx_bw*2); + + if ((status=bladerf_set_gain(brf->dev, BLADERF_MODULE_TX, (int) openair0_cfg->tx_gain[0])) != 0) { + fprintf(stderr,"Failed to set TX gain: %s\n",bladerf_strerror(status)); + brf_error(status); + } else + printf("[BRF] set the TX gain to %d\n", (int)openair0_cfg->tx_gain[0]); + + + /* Configure the device's TX module for use with the sync interface. + * SC16 Q11 samples *with* metadata are used. */ + if ((status=bladerf_sync_config(brf->dev, BLADERF_MODULE_TX,BLADERF_FORMAT_SC16_Q11_META,brf->num_buffers,brf->buffer_size,brf->num_transfers,brf->tx_timeout_ms)) != 0 ) { + fprintf(stderr,"Failed to configure TX sync interface: %s\n", bladerf_strerror(status)); + brf_error(status); + } else + printf("[BRF] configured TX sync interface \n"); + + /* Configure the device's RX module for use with the sync interface. + * SC16 Q11 samples *with* metadata are used. */ + if ((status=bladerf_sync_config(brf->dev, BLADERF_MODULE_RX, BLADERF_FORMAT_SC16_Q11_META,brf->num_buffers,brf->buffer_size,brf->num_transfers,brf->rx_timeout_ms)) != 0 ) { + fprintf(stderr,"Failed to configure RX sync interface: %s\n", bladerf_strerror(status)); + brf_error(status); + } else + printf("[BRF] configured Rx sync interface \n"); + + + /* We must always enable the TX module after calling bladerf_sync_config(), and + * before attempting to TX samples via bladerf_sync_tx(). */ + if ((status=bladerf_enable_module(brf->dev, BLADERF_MODULE_TX, true)) != 0) { + fprintf(stderr,"Failed to enable TX module: %s\n", bladerf_strerror(status)); + brf_error(status); + } else + printf("[BRF] TX module enabled \n"); + + /* We must always enable the RX module after calling bladerf_sync_config(), and + * before attempting to RX samples via bladerf_sync_rx(). */ + if ((status=bladerf_enable_module(brf->dev, BLADERF_MODULE_RX, true)) != 0) { + fprintf(stderr,"Failed to enable RX module: %s\n", bladerf_strerror(status)); + brf_error(status); + } else + printf("[BRF] RX module enabled \n"); + + // calibrate + + if ((status=bladerf_calibrate_dc(brf->dev, BLADERF_DC_CAL_LPF_TUNING)) != 0 || + (status=bladerf_calibrate_dc(brf->dev, BLADERF_DC_CAL_TX_LPF)) != 0 || + (status=bladerf_calibrate_dc(brf->dev, BLADERF_DC_CAL_RX_LPF)) != 0 || + (status=bladerf_calibrate_dc(brf->dev, BLADERF_DC_CAL_RXVGA2)) != 0) { + fprintf(stderr, "[BRF] error calibrating\n"); + brf_error(status); + } else + printf("[BRF] calibration OK\n"); + + bladerf_log_set_verbosity(get_brf_log_level(openair0_cfg->log_level)); + + printf("BLADERF: Initializing openair0_device\n"); + device->Mod_id = num_devices++; + device->type = BLADERF_DEV; + device->trx_start_func = trx_brf_start; + device->trx_end_func = trx_brf_end; + device->trx_read_func = trx_brf_read; + device->trx_write_func = trx_brf_write; + device->trx_get_stats_func = trx_brf_get_stats; + device->trx_reset_stats_func = trx_brf_reset_stats; + device->trx_stop_func = trx_brf_stop; + device->trx_set_freq_func = trx_brf_set_freq; + device->trx_set_gains_func = trx_brf_set_gains; + device->openair0_cfg = openair0_cfg; + device->priv = (void *)brf; + + calibrate_rf(device); + + // memcpy((void*)&device->openair0_cfg,(void*)&openair0_cfg[0],sizeof(openair0_config_t)); + + if ((status=bladerf_enable_module(brf->dev, BLADERF_MODULE_TX, false)) != 0) { + fprintf(stderr,"Failed to enable TX module: %s\n", bladerf_strerror(status)); + abort(); + } + if ((status=bladerf_enable_module(brf->dev, BLADERF_MODULE_RX, false)) != 0) { + fprintf(stderr,"Failed to enable RX module: %s\n", bladerf_strerror(status)); + abort(); + } + + return 0; } -/*! \brief bladeRF error report - * \param status +/*! \brief bladeRF error report + * \param status * \returns 0 on success */ int brf_error(int status) { - fprintf(stderr, "[BRF] brf_error: %s\n", bladerf_strerror(status)); - exit(-1); - return status; // or status error code + fprintf(stderr, "[BRF] brf_error: %s\n", bladerf_strerror(status)); + exit(-1); + return status; // or status error code } @@ -1153,61 +1154,61 @@ int brf_error(int status) { */ struct bladerf * open_bladerf_from_serial(const char *serial) { - int status; - struct bladerf *dev; - struct bladerf_devinfo info; - /* Initialize all fields to "don't care" wildcard values. - * - * Immediately passing this to bladerf_open_with_devinfo() would cause - * libbladeRF to open any device on any available backend. */ - bladerf_init_devinfo(&info); - /* Specify the desired device's serial number, while leaving all other - * fields in the info structure wildcard values */ - strncpy(info.serial, serial, BLADERF_SERIAL_LENGTH - 1); - info.serial[BLADERF_SERIAL_LENGTH - 1] = '\0'; - status = bladerf_open_with_devinfo(&dev, &info); - - if (status == BLADERF_ERR_NODEV) { - printf("No devices available with serial=%s\n", serial); - return NULL; - } else if (status != 0) { - fprintf(stderr, "Failed to open device with serial=%s (%s)\n", serial, bladerf_strerror(status)); - return NULL; - } else { - return dev; - } + int status; + struct bladerf *dev; + struct bladerf_devinfo info; + /* Initialize all fields to "don't care" wildcard values. + * + * Immediately passing this to bladerf_open_with_devinfo() would cause + * libbladeRF to open any device on any available backend. */ + bladerf_init_devinfo(&info); + /* Specify the desired device's serial number, while leaving all other + * fields in the info structure wildcard values */ + strncpy(info.serial, serial, BLADERF_SERIAL_LENGTH - 1); + info.serial[BLADERF_SERIAL_LENGTH - 1] = '\0'; + status = bladerf_open_with_devinfo(&dev, &info); + + if (status == BLADERF_ERR_NODEV) { + printf("No devices available with serial=%s\n", serial); + return NULL; + } else if (status != 0) { + fprintf(stderr, "Failed to open device with serial=%s (%s)\n", serial, bladerf_strerror(status)); + return NULL; + } else { + return dev; + } } /*! \brief Get BladeRF log level * \param log_level log level * \returns log level of BLADERF device */ -int get_brf_log_level(int log_level){ - - int level=BLADERF_LOG_LEVEL_INFO; - return BLADERF_LOG_LEVEL_INFO; - switch(log_level) { - case LOG_DEBUG: - level=BLADERF_LOG_LEVEL_DEBUG; - break; - case LOG_INFO: - level= BLADERF_LOG_LEVEL_INFO; - break; - case LOG_WARNING: - level=BLADERF_LOG_LEVEL_WARNING; - break; - case LOG_ERR: - level=BLADERF_LOG_LEVEL_ERROR; - break; - case LOG_CRIT: - level=BLADERF_LOG_LEVEL_CRITICAL; - break; - case LOG_EMERG: - level = BLADERF_LOG_LEVEL_SILENT; - break; - default: - break; - } - return level; +int get_brf_log_level(int log_level) { + + int level=BLADERF_LOG_LEVEL_INFO; + return BLADERF_LOG_LEVEL_INFO; + switch(log_level) { + case LOG_DEBUG: + level=BLADERF_LOG_LEVEL_DEBUG; + break; + case LOG_INFO: + level= BLADERF_LOG_LEVEL_INFO; + break; + case LOG_WARNING: + level=BLADERF_LOG_LEVEL_WARNING; + break; + case LOG_ERR: + level=BLADERF_LOG_LEVEL_ERROR; + break; + case LOG_CRIT: + level=BLADERF_LOG_LEVEL_CRITICAL; + break; + case LOG_EMERG: + level = BLADERF_LOG_LEVEL_SILENT; + break; + default: + break; + } + return level; } /*@}*/ diff --git a/targets/ARCH/ETHERNET/USERSPACE/LIB/ethernet_lib.c b/targets/ARCH/ETHERNET/USERSPACE/LIB/ethernet_lib.c index 108c4ca069e07ee71c7b3625cb5b5b8f5c9740ad..392cad2ee7af364e0a4189d8c473c75d814fac37 100644 --- a/targets/ARCH/ETHERNET/USERSPACE/LIB/ethernet_lib.c +++ b/targets/ARCH/ETHERNET/USERSPACE/LIB/ethernet_lib.c @@ -19,7 +19,7 @@ * contact@openairinterface.org */ -/*! \file ethernet_lib.c +/*! \file ethernet_lib.c * \brief API to stream I/Q samples over standard ethernet * \author add alcatel Katerina Trilyraki, Navid Nikaein, Pedro Dinis, Lucio Ferreira, Raymond Knopp * \date 2015 @@ -55,113 +55,113 @@ int dest_addr_len[MAX_INST]; int trx_eth_start(openair0_device *device) { - eth_state_t *eth = (eth_state_t*)device->priv; - - /* initialize socket */ - if (eth->flags == ETH_RAW_MODE) { - printf("Setting ETHERNET to ETH_RAW_IF5_MODE\n"); - if (eth_socket_init_raw(device)!=0) return -1; - /* RRU gets device configuration - RAU sets device configuration*/ + eth_state_t *eth = (eth_state_t*)device->priv; - printf("Setting Timenout to 999999 usecs\n"); - if(ethernet_tune (device,RCV_TIMEOUT,999999)!=0) return -1; + /* initialize socket */ + if (eth->flags == ETH_RAW_MODE) { + printf("Setting ETHERNET to ETH_RAW_IF5_MODE\n"); + if (eth_socket_init_raw(device)!=0) return -1; + /* RRU gets device configuration - RAU sets device configuration*/ - /* - if (device->host_type == RAU_HOST) { - if(eth_set_dev_conf_raw(device)!=0) return -1; - } else { - if(eth_get_dev_conf_raw(device)!=0) return -1; - }*/ + printf("Setting Timenout to 999999 usecs\n"); + if(ethernet_tune (device,RCV_TIMEOUT,999999)!=0) return -1; - /* adjust MTU wrt number of samples per packet */ - if(eth->compression == ALAW_COMPRESS) { - if(ethernet_tune (device,MTU_SIZE,RAW_PACKET_SIZE_BYTES_ALAW(device->openair0_cfg->samples_per_packet))!=0) return -1; - } else { - if(ethernet_tune (device,MTU_SIZE,RAW_PACKET_SIZE_BYTES(device->openair0_cfg->samples_per_packet))!=0) return -1; - } - if(ethernet_tune (device,RCV_TIMEOUT,999999)!=0) return -1; - } else if (eth->flags == ETH_RAW_IF4p5_MODE) { + /* + if (device->host_type == RAU_HOST) { + if(eth_set_dev_conf_raw(device)!=0) return -1; + } else { + if(eth_get_dev_conf_raw(device)!=0) return -1; + }*/ - printf("Setting ETHERNET to ETH_RAW_IF4p5_MODE\n"); - if (eth_socket_init_raw(device)!=0) return -1; + /* adjust MTU wrt number of samples per packet */ + if(eth->compression == ALAW_COMPRESS) { + if(ethernet_tune (device,MTU_SIZE,RAW_PACKET_SIZE_BYTES_ALAW(device->openair0_cfg->samples_per_packet))!=0) return -1; + } else { + if(ethernet_tune (device,MTU_SIZE,RAW_PACKET_SIZE_BYTES(device->openair0_cfg->samples_per_packet))!=0) return -1; + } + if(ethernet_tune (device,RCV_TIMEOUT,999999)!=0) return -1; + } else if (eth->flags == ETH_RAW_IF4p5_MODE) { - printf("Setting Timenout to 999999 usecs\n"); - if(ethernet_tune (device,RCV_TIMEOUT,999999)!=0) return -1; + printf("Setting ETHERNET to ETH_RAW_IF4p5_MODE\n"); + if (eth_socket_init_raw(device)!=0) return -1; - /* - if (device->host_type == RAU_HOST) { - if(eth_set_dev_conf_raw_IF4p5(device)!=0) return -1; - } else { - if(eth_get_dev_conf_raw_IF4p5(device)!=0) return -1; - } - */ + printf("Setting Timenout to 999999 usecs\n"); + if(ethernet_tune (device,RCV_TIMEOUT,999999)!=0) return -1; - /* adjust MTU wrt number of samples per packet */ - if(ethernet_tune (device,MTU_SIZE,RAW_IF4p5_PRACH_SIZE_BYTES)!=0) return -1; + /* + if (device->host_type == RAU_HOST) { + if(eth_set_dev_conf_raw_IF4p5(device)!=0) return -1; + } else { + if(eth_get_dev_conf_raw_IF4p5(device)!=0) return -1; + } + */ - if(ethernet_tune (device,RCV_TIMEOUT,999999)!=0) return -1; - } else if (eth->flags == ETH_UDP_IF4p5_MODE) { - printf("Setting ETHERNET to UDP_IF4p5_MODE\n"); - if (eth_socket_init_udp(device)!=0) return -1; + /* adjust MTU wrt number of samples per packet */ + if(ethernet_tune (device,MTU_SIZE,RAW_IF4p5_PRACH_SIZE_BYTES)!=0) return -1; - printf("Setting Timeout to 999999 usecs\n"); - if(ethernet_tune (device,RCV_TIMEOUT,999999)!=0) return -1; + if(ethernet_tune (device,RCV_TIMEOUT,999999)!=0) return -1; + } else if (eth->flags == ETH_UDP_IF4p5_MODE) { + printf("Setting ETHERNET to UDP_IF4p5_MODE\n"); + if (eth_socket_init_udp(device)!=0) return -1; - /* - if (device->host_type == RAU_HOST) { - if(eth_set_dev_conf_udp(device)!=0) return -1; - } else { - if(eth_get_dev_conf_udp(device)!=0) return -1; - } - */ + printf("Setting Timeout to 999999 usecs\n"); + if(ethernet_tune (device,RCV_TIMEOUT,999999)!=0) return -1; - /* adjust MTU wrt number of samples per packet */ - if(ethernet_tune (device,MTU_SIZE,UDP_IF4p5_PRACH_SIZE_BYTES)!=0) return -1; - + /* + if (device->host_type == RAU_HOST) { + if(eth_set_dev_conf_udp(device)!=0) return -1; + } else { + if(eth_get_dev_conf_udp(device)!=0) return -1; + } + */ + /* adjust MTU wrt number of samples per packet */ + if(ethernet_tune (device,MTU_SIZE,UDP_IF4p5_PRACH_SIZE_BYTES)!=0) return -1; - - } else if (eth->flags == ETH_RAW_IF5_MOBIPASS) { - printf("Setting ETHERNET to RAW_IF5_MODE\n"); - if (eth_socket_init_raw(device)!=0) return -1; - if(ethernet_tune (device,RCV_TIMEOUT,999999)!=0) return -1; - } else { - printf("Setting ETHERNET to UDP_IF5_MODE\n"); - if (eth_socket_init_udp(device)!=0) return -1; - /* - if (device->host_type == RAU_HOST) { - if(eth_set_dev_conf_udp(device)!=0) return -1; + + } else if (eth->flags == ETH_RAW_IF5_MOBIPASS) { + printf("Setting ETHERNET to RAW_IF5_MODE\n"); + if (eth_socket_init_raw(device)!=0) return -1; + if(ethernet_tune (device,RCV_TIMEOUT,999999)!=0) return -1; + } else { - if(eth_get_dev_conf_udp(device)!=0) return -1; - }*/ + printf("Setting ETHERNET to UDP_IF5_MODE\n"); + if (eth_socket_init_udp(device)!=0) return -1; + + /* + if (device->host_type == RAU_HOST) { + if(eth_set_dev_conf_udp(device)!=0) return -1; + } else { + if(eth_get_dev_conf_udp(device)!=0) return -1; + }*/ + + /* adjust MTU wrt number of samples per packet */ + if(ethernet_tune (device,MTU_SIZE,UDP_IF4p5_PRACH_SIZE_BYTES)!=0) return -1; + + if(ethernet_tune (device,RCV_TIMEOUT,999999)!=0) return -1; + } + /* apply additional configuration */ + if(ethernet_tune (device, SND_BUF_SIZE,2000000000)!=0) return -1; + if(ethernet_tune (device, RCV_BUF_SIZE,2000000000)!=0) return -1; + if(ethernet_tune (device, KERNEL_SND_BUF_MAX_SIZE, 200000000)!=0) return -1; + if(ethernet_tune (device, KERNEL_RCV_BUF_MAX_SIZE, 200000000)!=0) return -1; - /* adjust MTU wrt number of samples per packet */ - if(ethernet_tune (device,MTU_SIZE,UDP_IF4p5_PRACH_SIZE_BYTES)!=0) return -1; - - if(ethernet_tune (device,RCV_TIMEOUT,999999)!=0) return -1; - } - /* apply additional configuration */ - if(ethernet_tune (device, SND_BUF_SIZE,2000000000)!=0) return -1; - if(ethernet_tune (device, RCV_BUF_SIZE,2000000000)!=0) return -1; - if(ethernet_tune (device, KERNEL_SND_BUF_MAX_SIZE, 200000000)!=0) return -1; - if(ethernet_tune (device, KERNEL_RCV_BUF_MAX_SIZE, 200000000)!=0) return -1; - - return 0; + return 0; } void trx_eth_end(openair0_device *device) { - eth_state_t *eth = (eth_state_t*)device->priv; - /* destroys socket only for the processes that call the eth_end fuction-- shutdown() for beaking the pipe */ - if ( close(eth->sockfdd) <0 ) { - perror("ETHERNET: Failed to close socket"); - exit(0); - } else { - printf("[%s] socket has been successfully closed.\n",(device->host_type == RAU_HOST)? "RAU":"RRU"); - } + eth_state_t *eth = (eth_state_t*)device->priv; + /* destroys socket only for the processes that call the eth_end fuction-- shutdown() for beaking the pipe */ + if ( close(eth->sockfdd) <0 ) { + perror("ETHERNET: Failed to close socket"); + exit(0); + } else { + printf("[%s] socket has been successfully closed.\n",(device->host_type == RAU_HOST)? "RAU":"RRU"); + } } @@ -187,282 +187,282 @@ int trx_eth_reset_stats(openair0_device* device) { int ethernet_tune(openair0_device *device, unsigned int option, int value) { - - eth_state_t *eth = (eth_state_t*)device->priv; - struct timeval timeout; - struct ifreq ifr; - char system_cmd[256]; - int rname[] = { CTL_NET, NET_CORE, NET_CORE_RMEM_MAX }; - int wname[] = { CTL_NET, NET_CORE, NET_CORE_WMEM_MAX }; - int namelen=3; - int newval[1]; - int newlen=sizeof(newval); - int ret=0; - // int i=0; - - /****************** socket level options ************************/ - switch(option) { - case SND_BUF_SIZE: /* transmit socket buffer size */ - if (setsockopt(eth->sockfdd, - SOL_SOCKET, - SO_SNDBUF, - &value,sizeof(value))) { - perror("[ETHERNET] setsockopt()"); - } else { - printf("send buffer size= %d bytes\n",value); - } - break; - - case RCV_BUF_SIZE: /* receive socket buffer size */ - if (setsockopt(eth->sockfdd, - SOL_SOCKET, - SO_RCVBUF, - &value,sizeof(value))) { - perror("[ETHERNET] setsockopt()"); - } else { - printf("receive bufffer size= %d bytes\n",value); - } - break; - - case RCV_TIMEOUT: - timeout.tv_sec = value/1000000; - timeout.tv_usec = value%1000000;//less than rt_period? - if (setsockopt(eth->sockfdc, - SOL_SOCKET, - SO_RCVTIMEO, - (char *)&timeout,sizeof(timeout))) { - perror("[ETHERNET] setsockopt()"); - } else { - printf( "receive timeout= %u usec\n",(unsigned int)timeout.tv_usec); - } - if (setsockopt(eth->sockfdd, - SOL_SOCKET, - SO_RCVTIMEO, - (char *)&timeout,sizeof(timeout))) { - perror("[ETHERNET] setsockopt()"); - } else { - printf( "receive timeout= %u usec\n",(unsigned int)timeout.tv_usec); - } - break; - - case SND_TIMEOUT: - timeout.tv_sec = value/1000000000; - timeout.tv_usec = value%1000000000;//less than rt_period? - if (setsockopt(eth->sockfdc, - SOL_SOCKET, - SO_SNDTIMEO, - (char *)&timeout,sizeof(timeout))) { - perror("[ETHERNET] setsockopt()"); - } else { - printf( "send timeout= %d,%d sec\n",(int)timeout.tv_sec,(int)timeout.tv_usec); - } - if (setsockopt(eth->sockfdd, - SOL_SOCKET, - SO_SNDTIMEO, - (char *)&timeout,sizeof(timeout))) { - perror("[ETHERNET] setsockopt()"); - } else { - printf( "send timeout= %d,%d sec\n",(int)timeout.tv_sec,(int)timeout.tv_usec); - } - break; - - + + eth_state_t *eth = (eth_state_t*)device->priv; + struct timeval timeout; + struct ifreq ifr; + char system_cmd[256]; + int rname[] = { CTL_NET, NET_CORE, NET_CORE_RMEM_MAX }; + int wname[] = { CTL_NET, NET_CORE, NET_CORE_WMEM_MAX }; + int namelen=3; + int newval[1]; + int newlen=sizeof(newval); + int ret=0; + // int i=0; + + /****************** socket level options ************************/ + switch(option) { + case SND_BUF_SIZE: /* transmit socket buffer size */ + if (setsockopt(eth->sockfdd, + SOL_SOCKET, + SO_SNDBUF, + &value,sizeof(value))) { + perror("[ETHERNET] setsockopt()"); + } else { + printf("send buffer size= %d bytes\n",value); + } + break; + + case RCV_BUF_SIZE: /* receive socket buffer size */ + if (setsockopt(eth->sockfdd, + SOL_SOCKET, + SO_RCVBUF, + &value,sizeof(value))) { + perror("[ETHERNET] setsockopt()"); + } else { + printf("receive bufffer size= %d bytes\n",value); + } + break; + + case RCV_TIMEOUT: + timeout.tv_sec = value/1000000; + timeout.tv_usec = value%1000000;//less than rt_period? + if (setsockopt(eth->sockfdc, + SOL_SOCKET, + SO_RCVTIMEO, + (char *)&timeout,sizeof(timeout))) { + perror("[ETHERNET] setsockopt()"); + } else { + printf( "receive timeout= %u usec\n",(unsigned int)timeout.tv_usec); + } + if (setsockopt(eth->sockfdd, + SOL_SOCKET, + SO_RCVTIMEO, + (char *)&timeout,sizeof(timeout))) { + perror("[ETHERNET] setsockopt()"); + } else { + printf( "receive timeout= %u usec\n",(unsigned int)timeout.tv_usec); + } + break; + + case SND_TIMEOUT: + timeout.tv_sec = value/1000000000; + timeout.tv_usec = value%1000000000;//less than rt_period? + if (setsockopt(eth->sockfdc, + SOL_SOCKET, + SO_SNDTIMEO, + (char *)&timeout,sizeof(timeout))) { + perror("[ETHERNET] setsockopt()"); + } else { + printf( "send timeout= %d,%d sec\n",(int)timeout.tv_sec,(int)timeout.tv_usec); + } + if (setsockopt(eth->sockfdd, + SOL_SOCKET, + SO_SNDTIMEO, + (char *)&timeout,sizeof(timeout))) { + perror("[ETHERNET] setsockopt()"); + } else { + printf( "send timeout= %d,%d sec\n",(int)timeout.tv_sec,(int)timeout.tv_usec); + } + break; + + /******************* interface level options *************************/ - case MTU_SIZE: /* change MTU of the eth interface */ - ifr.ifr_addr.sa_family = AF_INET; - strncpy(ifr.ifr_name,eth->if_name, sizeof(ifr.ifr_name)); - ifr.ifr_mtu =value; - if (ioctl(eth->sockfdd,SIOCSIFMTU,(caddr_t)&ifr) < 0 ) - perror ("[ETHERNET] Can't set the MTU"); - else - printf("[ETHERNET] %s MTU size has changed to %d\n",eth->if_name,ifr.ifr_mtu); - break; - - case TX_Q_LEN: /* change TX queue length of eth interface */ - ifr.ifr_addr.sa_family = AF_INET; - strncpy(ifr.ifr_name,eth->if_name, sizeof(ifr.ifr_name)); - ifr.ifr_qlen =value; - if (ioctl(eth->sockfdd,SIOCSIFTXQLEN,(caddr_t)&ifr) < 0 ) - perror ("[ETHERNET] Can't set the txqueuelen"); - else - printf("[ETHERNET] %s txqueuelen size has changed to %d\n",eth->if_name,ifr.ifr_qlen); - break; - + case MTU_SIZE: /* change MTU of the eth interface */ + ifr.ifr_addr.sa_family = AF_INET; + strncpy(ifr.ifr_name,eth->if_name, sizeof(ifr.ifr_name)); + ifr.ifr_mtu =value; + if (ioctl(eth->sockfdd,SIOCSIFMTU,(caddr_t)&ifr) < 0 ) + perror ("[ETHERNET] Can't set the MTU"); + else + printf("[ETHERNET] %s MTU size has changed to %d\n",eth->if_name,ifr.ifr_mtu); + break; + + case TX_Q_LEN: /* change TX queue length of eth interface */ + ifr.ifr_addr.sa_family = AF_INET; + strncpy(ifr.ifr_name,eth->if_name, sizeof(ifr.ifr_name)); + ifr.ifr_qlen =value; + if (ioctl(eth->sockfdd,SIOCSIFTXQLEN,(caddr_t)&ifr) < 0 ) + perror ("[ETHERNET] Can't set the txqueuelen"); + else + printf("[ETHERNET] %s txqueuelen size has changed to %d\n",eth->if_name,ifr.ifr_qlen); + break; + /******************* device level options *************************/ - case COALESCE_PAR: - ret=snprintf(system_cmd,sizeof(system_cmd),"ethtool -C %s rx-usecs %d",eth->if_name,value); - if (ret > 0) { - ret=system(system_cmd); - if (ret == -1) { - fprintf (stderr,"[ETHERNET] Can't start shell to execute %s %s",system_cmd, strerror(errno)); - } else { - printf ("[ETHERNET] status of %s is %d\n", system_cmd, WEXITSTATUS(ret)); - } - printf("[ETHERNET] Coalesce parameters %s\n",system_cmd); - } else { - perror("[ETHERNET] Can't set coalesce parameters\n"); + case COALESCE_PAR: + ret=snprintf(system_cmd,sizeof(system_cmd),"ethtool -C %s rx-usecs %d",eth->if_name,value); + if (ret > 0) { + ret=system(system_cmd); + if (ret == -1) { + fprintf (stderr,"[ETHERNET] Can't start shell to execute %s %s",system_cmd, strerror(errno)); + } else { + printf ("[ETHERNET] status of %s is %d\n", system_cmd, WEXITSTATUS(ret)); + } + printf("[ETHERNET] Coalesce parameters %s\n",system_cmd); + } else { + perror("[ETHERNET] Can't set coalesce parameters\n"); + } + break; + + case PAUSE_PAR: + if (value==1) ret=snprintf(system_cmd,sizeof(system_cmd),"ethtool -A %s autoneg off rx off tx off",eth->if_name); + else if (value==0) ret=snprintf(system_cmd,sizeof(system_cmd),"ethtool -A %s autoneg on rx on tx on",eth->if_name); + else break; + if (ret > 0) { + ret=system(system_cmd); + if (ret == -1) { + fprintf (stderr,"[ETHERNET] Can't start shell to execute %s %s",system_cmd, strerror(errno)); + } else { + printf ("[ETHERNET] status of %s is %d\n", system_cmd, WEXITSTATUS(ret)); + } + printf("[ETHERNET] Pause parameters %s\n",system_cmd); + } else { + perror("[ETHERNET] Can't set pause parameters\n"); + } + break; + + case RING_PAR: + ret=snprintf(system_cmd,sizeof(system_cmd),"ethtool -G %s val %d",eth->if_name,value); + if (ret > 0) { + ret=system(system_cmd); + if (ret == -1) { + fprintf (stderr,"[ETHERNET] Can't start shell to execute %s %s",system_cmd, strerror(errno)); + } else { + printf ("[ETHERNET] status of %s is %d\n", system_cmd, WEXITSTATUS(ret)); + } + printf("[ETHERNET] Ring parameters %s\n",system_cmd); + } else { + perror("[ETHERNET] Can't set ring parameters\n"); + } + break; + case KERNEL_RCV_BUF_MAX_SIZE: + newval[0] = value; + ret=sysctl(rname, namelen, NULL, 0, newval, newlen); + if (ret) { + fprintf(stderr,"[ETHERNET] Error using sysctl():%s\n",strerror(errno)); + } else { + printf("[ETHERNET] Kernel network receive buffer max size is set to %u\n",(unsigned int)newval[0]); + } + break; + case KERNEL_SND_BUF_MAX_SIZE: + newval[0] = value; + ret=sysctl(wname, namelen, NULL, 0, newval, newlen); + if (ret) { + fprintf(stderr,"[ETHERNET] Error using sysctl():%s\n",strerror(errno)); + } else { + printf("[ETHERNET] Kernel network send buffer max size is set to %u\n",(unsigned int)newval[0]); + } + break; + + default: + break; } - break; - - case PAUSE_PAR: - if (value==1) ret=snprintf(system_cmd,sizeof(system_cmd),"ethtool -A %s autoneg off rx off tx off",eth->if_name); - else if (value==0) ret=snprintf(system_cmd,sizeof(system_cmd),"ethtool -A %s autoneg on rx on tx on",eth->if_name); - else break; - if (ret > 0) { - ret=system(system_cmd); - if (ret == -1) { - fprintf (stderr,"[ETHERNET] Can't start shell to execute %s %s",system_cmd, strerror(errno)); - } else { - printf ("[ETHERNET] status of %s is %d\n", system_cmd, WEXITSTATUS(ret)); - } - printf("[ETHERNET] Pause parameters %s\n",system_cmd); + + return 0; +} + + +int transport_init(openair0_device *device, openair0_config_t *openair0_cfg, eth_params_t * eth_params ) { + + eth_state_t *eth = (eth_state_t*)malloc(sizeof(eth_state_t)); + memset(eth, 0, sizeof(eth_state_t)); + + if (eth_params->transp_preference == 1) { + eth->flags = ETH_RAW_MODE; + } else if (eth_params->transp_preference == 0) { + eth->flags = ETH_UDP_MODE; + } else if (eth_params->transp_preference == 3) { + eth->flags = ETH_RAW_IF4p5_MODE; + } else if (eth_params->transp_preference == 2) { + eth->flags = ETH_UDP_IF4p5_MODE; + } else if (eth_params->transp_preference == 4) { + eth->flags = ETH_RAW_IF5_MOBIPASS; } else { - perror("[ETHERNET] Can't set pause parameters\n"); + printf("transport_init: Unknown transport preference %d - default to RAW", eth_params->transp_preference); + eth->flags = ETH_RAW_MODE; } - break; - - case RING_PAR: - ret=snprintf(system_cmd,sizeof(system_cmd),"ethtool -G %s val %d",eth->if_name,value); - if (ret > 0) { - ret=system(system_cmd); - if (ret == -1) { - fprintf (stderr,"[ETHERNET] Can't start shell to execute %s %s",system_cmd, strerror(errno)); - } else { - printf ("[ETHERNET] status of %s is %d\n", system_cmd, WEXITSTATUS(ret)); - } - printf("[ETHERNET] Ring parameters %s\n",system_cmd); + + if (eth_params->if_compress == 0) { + eth->compression = NO_COMPRESS; + } else if (eth_params->if_compress == 1) { + eth->compression = ALAW_COMPRESS; } else { - perror("[ETHERNET] Can't set ring parameters\n"); - } - break; - case KERNEL_RCV_BUF_MAX_SIZE: - newval[0] = value; - ret=sysctl(rname, namelen, NULL, 0, newval, newlen); - if (ret) { - fprintf(stderr,"[ETHERNET] Error using sysctl():%s\n",strerror(errno)); - } else{ - printf("[ETHERNET] Kernel network receive buffer max size is set to %u\n",newval[0]); + printf("transport_init: Unknown compression scheme %d - default to ALAW", eth_params->if_compress); + eth->compression = ALAW_COMPRESS; } - break; - case KERNEL_SND_BUF_MAX_SIZE: - newval[0] = value; - ret=sysctl(wname, namelen, NULL, 0, newval, newlen); - if (ret) { - fprintf(stderr,"[ETHERNET] Error using sysctl():%s\n",strerror(errno)); - } else{ - printf("[ETHERNET] Kernel network send buffer max size is set to %u\n",newval[0]); + + printf("[ETHERNET]: Initializing openair0_device for %s ...\n", ((device->host_type == RAU_HOST) ? "RAU": "RRU")); + device->Mod_id = 0;//num_devices_eth++; + device->transp_type = ETHERNET_TP; + device->trx_start_func = trx_eth_start; + device->trx_get_stats_func = trx_eth_get_stats; + device->trx_reset_stats_func = trx_eth_reset_stats; + device->trx_end_func = trx_eth_end; + device->trx_stop_func = trx_eth_stop; + device->trx_set_freq_func = trx_eth_set_freq; + device->trx_set_gains_func = trx_eth_set_gains; + + if (eth->flags == ETH_RAW_MODE) { + device->trx_write_func = trx_eth_write_raw; + device->trx_read_func = trx_eth_read_raw; + } else if (eth->flags == ETH_UDP_MODE) { + device->trx_write_func = trx_eth_write_udp; + device->trx_read_func = trx_eth_read_udp; + device->trx_ctlsend_func = trx_eth_ctlsend_udp; + device->trx_ctlrecv_func = trx_eth_ctlrecv_udp; + } else if (eth->flags == ETH_RAW_IF4p5_MODE) { + device->trx_write_func = trx_eth_write_raw_IF4p5; + device->trx_read_func = trx_eth_read_raw_IF4p5; + } else if (eth->flags == ETH_UDP_IF4p5_MODE) { + device->trx_write_func = trx_eth_write_udp_IF4p5; + device->trx_read_func = trx_eth_read_udp_IF4p5; + device->trx_ctlsend_func = trx_eth_ctlsend_udp; + device->trx_ctlrecv_func = trx_eth_ctlrecv_udp; + } else if (eth->flags == ETH_RAW_IF5_MOBIPASS) { + device->trx_write_func = trx_eth_write_raw_IF4p5; + device->trx_read_func = trx_eth_read_raw_IF5_mobipass; + } else { + //device->trx_write_func = trx_eth_write_udp_IF4p5; + //device->trx_read_func = trx_eth_read_udp_IF4p5; } - break; - - default: - break; - } - - return 0; -} + eth->if_name = eth_params->local_if_name; + device->priv = eth; -int transport_init(openair0_device *device, openair0_config_t *openair0_cfg, eth_params_t * eth_params ) { + /* device specific */ + // openair0_cfg[0].iq_rxrescale = 15;//rescale iqs + // openair0_cfg[0].iq_txshift = eth_params->iq_txshift;// shift + // openair0_cfg[0].tx_sample_advance = eth_params->tx_sample_advance; - eth_state_t *eth = (eth_state_t*)malloc(sizeof(eth_state_t)); - memset(eth, 0, sizeof(eth_state_t)); - - if (eth_params->transp_preference == 1) { - eth->flags = ETH_RAW_MODE; - } else if (eth_params->transp_preference == 0) { - eth->flags = ETH_UDP_MODE; - } else if (eth_params->transp_preference == 3) { - eth->flags = ETH_RAW_IF4p5_MODE; - } else if (eth_params->transp_preference == 2) { - eth->flags = ETH_UDP_IF4p5_MODE; - } else if (eth_params->transp_preference == 4) { - eth->flags = ETH_RAW_IF5_MOBIPASS; - } else { - printf("transport_init: Unknown transport preference %d - default to RAW", eth_params->transp_preference); - eth->flags = ETH_RAW_MODE; - } - - if (eth_params->if_compress == 0) { - eth->compression = NO_COMPRESS; - } else if (eth_params->if_compress == 1) { - eth->compression = ALAW_COMPRESS; - } else { - printf("transport_init: Unknown compression scheme %d - default to ALAW", eth_params->if_compress); - eth->compression = ALAW_COMPRESS; - } - - printf("[ETHERNET]: Initializing openair0_device for %s ...\n", ((device->host_type == RAU_HOST) ? "RAU": "RRU")); - device->Mod_id = 0;//num_devices_eth++; - device->transp_type = ETHERNET_TP; - device->trx_start_func = trx_eth_start; - device->trx_get_stats_func = trx_eth_get_stats; - device->trx_reset_stats_func = trx_eth_reset_stats; - device->trx_end_func = trx_eth_end; - device->trx_stop_func = trx_eth_stop; - device->trx_set_freq_func = trx_eth_set_freq; - device->trx_set_gains_func = trx_eth_set_gains; - - if (eth->flags == ETH_RAW_MODE) { - device->trx_write_func = trx_eth_write_raw; - device->trx_read_func = trx_eth_read_raw; - } else if (eth->flags == ETH_UDP_MODE) { - device->trx_write_func = trx_eth_write_udp; - device->trx_read_func = trx_eth_read_udp; - device->trx_ctlsend_func = trx_eth_ctlsend_udp; - device->trx_ctlrecv_func = trx_eth_ctlrecv_udp; - } else if (eth->flags == ETH_RAW_IF4p5_MODE) { - device->trx_write_func = trx_eth_write_raw_IF4p5; - device->trx_read_func = trx_eth_read_raw_IF4p5; - } else if (eth->flags == ETH_UDP_IF4p5_MODE) { - device->trx_write_func = trx_eth_write_udp_IF4p5; - device->trx_read_func = trx_eth_read_udp_IF4p5; - device->trx_ctlsend_func = trx_eth_ctlsend_udp; - device->trx_ctlrecv_func = trx_eth_ctlrecv_udp; - } else if (eth->flags == ETH_RAW_IF5_MOBIPASS) { - device->trx_write_func = trx_eth_write_raw_IF4p5; - device->trx_read_func = trx_eth_read_raw_IF5_mobipass; - } else { - //device->trx_write_func = trx_eth_write_udp_IF4p5; - //device->trx_read_func = trx_eth_read_udp_IF4p5; - } - - eth->if_name = eth_params->local_if_name; - device->priv = eth; - - /* device specific */ - // openair0_cfg[0].iq_rxrescale = 15;//rescale iqs - // openair0_cfg[0].iq_txshift = eth_params->iq_txshift;// shift - // openair0_cfg[0].tx_sample_advance = eth_params->tx_sample_advance; - - /* RRU does not have any information to make this configuration atm */ - /* - if (device->host_type == RAU_HOST) { - - switch ((int)openair0_cfg[0].sample_rate) { - case 30720000: - openair0_cfg[0].samples_per_packet = 3840; - break; - case 23040000: - openair0_cfg[0].samples_per_packet = 2880; - break; - case 15360000: - openair0_cfg[0].samples_per_packet = 1920; - break; - case 7680000: - openair0_cfg[0].samples_per_packet = 960; - break; - case 1920000: - openair0_cfg[0].samples_per_packet = 240; - break; - default: - printf("Error: unknown sampling rate %f\n",openair0_cfg[0].sample_rate); - exit(-1); - break; - } - }*/ + /* RRU does not have any information to make this configuration atm */ + /* + if (device->host_type == RAU_HOST) { + + switch ((int)openair0_cfg[0].sample_rate) { + case 30720000: + openair0_cfg[0].samples_per_packet = 3840; + break; + case 23040000: + openair0_cfg[0].samples_per_packet = 2880; + break; + case 15360000: + openair0_cfg[0].samples_per_packet = 1920; + break; + case 7680000: + openair0_cfg[0].samples_per_packet = 960; + break; + case 1920000: + openair0_cfg[0].samples_per_packet = 240; + break; + default: + printf("Error: unknown sampling rate %f\n",openair0_cfg[0].sample_rate); + exit(-1); + break; + } + }*/ - device->openair0_cfg=&openair0_cfg[0]; - return 0; + device->openair0_cfg=&openair0_cfg[0]; + return 0; } diff --git a/targets/ARCH/EXMIMO/USERSPACE/LIB/openair0_lib.c b/targets/ARCH/EXMIMO/USERSPACE/LIB/openair0_lib.c index 7d23cdeb8929391659e668f60c4edf118cd01891..f12af629b7f08924e818de904c3b88346e5452ee 100644 --- a/targets/ARCH/EXMIMO/USERSPACE/LIB/openair0_lib.c +++ b/targets/ARCH/EXMIMO/USERSPACE/LIB/openair0_lib.c @@ -444,7 +444,7 @@ static void *watchdog_thread(void *arg) { (diff > 16)&& (first_acquisition==0)) {// we're too late so exit exm->watchdog_exit = 1; - printf("exiting, too late to keep up - diff = %d\n", diff); + printf("exiting, too late to keep up - diff = %u\n", diff); } first_acquisition=0; @@ -625,7 +625,7 @@ int trx_exmimo_read(openair0_device *device, openair0_timestamp *ptimestamp, voi if (cfg->mmapped_dma == 0) { // if buff is not the dma buffer, do a memcpy, otherwise do nothing for (i=0;i<cc;i++) { #ifdef DEBUG_EXMIMO - printf("copying to %p (%lu), from %llu\n",buff[i]+(ntot*sizeof(int)),ntot*sizeof(int),(exm->last_ts_rx % exm->samples_per_frame)); + printf("copying to %p (%zu), from %llu\n",buff[i]+(ntot*sizeof(int)),ntot*sizeof(int),(exm->last_ts_rx % exm->samples_per_frame)); #endif if ((n+(exm->last_ts_rx%exm->samples_per_frame))<exm->samples_per_frame) { memcpy(buff[i]+(ntot*sizeof(int)), @@ -733,7 +733,7 @@ int device_init(openair0_device *device, openair0_config_t *openair0_cfg) { if (ret == -3) printf("Error mapping RX or TX buffer"); - + free(exm); return(ret); } @@ -752,6 +752,7 @@ int device_init(openair0_device *device, openair0_config_t *openair0_cfg) { // check if the software matches firmware if (p_exmimo_id->board_swrev!=BOARD_SWREV_CNTL2) { printf("Software revision %d and firmware revision %d do not match. Please update either the firmware or the software!\n",BOARD_SWREV_CNTL2,p_exmimo_id->board_swrev); + free(exm); return(-1); } } @@ -905,7 +906,7 @@ int openair0_config(openair0_config_t *openair0_cfg, int UE_flag) p_exmimo_config->rf.rx_gain[ant][0] = 30 - (rxg_max[ant] - (int)openair0_cfg[card].rx_gain[ant]); //was measured at rxgain=30; } else { - printf("openair0: RX RF gain too high, reduce by %d dB\n", (int)openair0_cfg[card].rx_gain[ant]-rxg_max[ant]); + printf("openair0: RX RF gain too high, reduce by %u dB\n", (int)openair0_cfg[card].rx_gain[ant]-rxg_max[ant]); exit(-1); } break; @@ -916,7 +917,7 @@ int openair0_config(openair0_config_t *openair0_cfg, int UE_flag) p_exmimo_config->rf.rx_gain[ant][0] = 30 - (rxg_med[ant] - (int)openair0_cfg[card].rx_gain[ant]); //was measured at rxgain=30; } else { - printf("openair0: RX RF gain too high, reduce by %d dB\n", (int)openair0_cfg[card].rx_gain[ant]-rxg_med[ant]); + printf("openair0: RX RF gain too high, reduce by %u dB\n", (int)openair0_cfg[card].rx_gain[ant]-rxg_med[ant]); exit(-1); } break; @@ -927,7 +928,7 @@ int openair0_config(openair0_config_t *openair0_cfg, int UE_flag) p_exmimo_config->rf.rx_gain[ant][0] = 30 - (rxg_byp[ant] - (int)openair0_cfg[card].rx_gain[ant]); //was measured at rxgain=30; } else { - printf("openair0: RX RF gain too high, reduce by %d dB\n", (int)openair0_cfg[card].rx_gain[ant]-rxg_byp[ant]); + printf("openair0: RX RF gain too high, reduce by %u dB\n", (int)openair0_cfg[card].rx_gain[ant]-rxg_byp[ant]); exit(-1); } break; diff --git a/targets/ARCH/EXMIMO/USERSPACE/OAI_FW_INIT/updatefw.c b/targets/ARCH/EXMIMO/USERSPACE/OAI_FW_INIT/updatefw.c index 1b2445fa72e512cb290a12ab3ebf80c97c3ab138..be049e255e3929dd6a5ffb88aab096d158b4ec1a 100644 --- a/targets/ARCH/EXMIMO/USERSPACE/OAI_FW_INIT/updatefw.c +++ b/targets/ARCH/EXMIMO/USERSPACE/OAI_FW_INIT/updatefw.c @@ -211,22 +211,25 @@ void find_and_transfer_section(char* section_name, unsigned int verboselevel) { int nbread; unsigned int secnb = 0; + if(p_elfimage == NULL) { + fprintf(stderr, "%s %d:Error, firmware file not opened\n",__FILE__,__LINE__); + } for (secnb = 0 ; secnb < elf_Ehdr.e_shnum; secnb++) { get_elf_section_header(&elf_Shdr, p_elfimage, secnb); if (!strcmp(SecNameStnTable + elf_Shdr.sh_name, section_name)) { if (verboselevel >= VERBOSE_LEVEL_SECTION_DETAILS) - printf("Info: ok, found section %s (as section nb. %d)\n", SecNameStnTable + elf_Shdr.sh_name, secnb); + printf("Info: ok, found section %s (as section nb. %u)\n", SecNameStnTable + elf_Shdr.sh_name, secnb); /* Check that section size is a multiple of 4 bytes. */ if (elf_Shdr.sh_size % 4) { - fprintf(stderr, "Error: section %s has a non-multiple-of-4-bytes size (%d).\n", - SecNameStnTable + elf_Shdr.sh_name, elf_Shdr.sh_size); + fprintf(stderr, "Error: section %s has a non-multiple-of-4-bytes size (%lu).\n", + SecNameStnTable + elf_Shdr.sh_name, (unsigned long)elf_Shdr.sh_size); fclose(p_elfimage); exit(-1); } else if (verboselevel >= VERBOSE_LEVEL_SECTION_DETAILS) { - printf("Info: ok, section %s has size %d bytes (multiple of 4 bytes).\n", - SecNameStnTable + elf_Shdr.sh_name, elf_Shdr.sh_size); + printf("Info: ok, section %s has size %lu bytes (multiple of 4 bytes).\n", + SecNameStnTable + elf_Shdr.sh_name, (unsigned long)elf_Shdr.sh_size); } /* Dynamically allocate a chunk of memory to store the section into. */ @@ -245,13 +248,13 @@ void find_and_transfer_section(char* section_name, unsigned int verboselevel) { } if (!section_content) { - fprintf(stderr, "Error: could not dynamically allocate %d bytes for section %s.\n", - elf_Shdr.sh_size, SecNameStnTable + elf_Shdr.sh_name); + fprintf(stderr, "Error: could not dynamically allocate %lu bytes for section %s.\n", + (unsigned long)elf_Shdr.sh_size, (SecNameStnTable + elf_Shdr.sh_name)); fclose(p_elfimage); exit(-1); } else if (verboselevel >= VERBOSE_LEVEL_IOCTL) { - printf("Info: ok, dynamically allocated a %d bytes buffer for section %s.\n", - elf_Shdr.sh_size, SecNameStnTable + elf_Shdr.sh_name); + printf("Info: ok, dynamically allocated a %lu bytes buffer for section %s.\n", + (unsigned long)elf_Shdr.sh_size, SecNameStnTable + elf_Shdr.sh_name); } /* Position the file cursor at the begining of proper section. */ @@ -260,13 +263,13 @@ void find_and_transfer_section(char* section_name, unsigned int verboselevel) { nbread = fread(section_content, elf_Shdr.sh_size, 1, p_elfimage); if (nbread != 1) { - fprintf(stderr, "Error: could not read %d bytes from ELF file into dynamic buffer.\n", elf_Shdr.sh_size); + fprintf(stderr, "Error: could not read %lu bytes from ELF file into dynamic buffer.\n", (unsigned long)elf_Shdr.sh_size); free(section_content); fclose(p_elfimage); exit(-1); } else if (verboselevel >= VERBOSE_LEVEL_IOCTL) { - printf("Info: ok, copied content of section %s into dynamic buffer (%d bytes copied).\n", - SecNameStnTable + elf_Shdr.sh_name, elf_Shdr.sh_size); + printf("Info: ok, copied content of section %s into dynamic buffer (%lu bytes copied).\n", + SecNameStnTable + elf_Shdr.sh_name, (unsigned long)elf_Shdr.sh_size); } /* Open the special device file. */ @@ -324,12 +327,15 @@ void find_and_clear_section_bss(unsigned int verboselevel) { int ifile; unsigned int secnb = 0; + if(p_elfimage == NULL) { + fprintf(stderr, "%s %d:Error, firmware file not opened\n",__FILE__,__LINE__); + } for (secnb = 0 ; secnb < elf_Ehdr.e_shnum; secnb++) { get_elf_section_header(&elf_Shdr, p_elfimage, secnb); if (!strcmp(SecNameStnTable + elf_Shdr.sh_name, ".bss")) { if (verboselevel >= VERBOSE_LEVEL_SECTION_DETAILS) - printf("Info: ok, found section %s (as section nb. %d)\n", SecNameStnTable + elf_Shdr.sh_name, secnb); + printf("Info: ok, found section %s (as section nb. %u)\n", SecNameStnTable + elf_Shdr.sh_name, secnb); /* Open the special device file. */ if (!pflag) { @@ -491,6 +497,10 @@ int main(int argc, char** argv) { /* Open firmware file in READ_ONLY mode. */ filename = p_str_fwn; + if (filename == NULL) { + fprintf(stderr, "%s %d: No filename specified\n", __FILE__, __LINE__); + exit(-1); + } p_elfimage = fopen(filename, READ_FILE_MODE); if (p_elfimage == NULL) { @@ -505,6 +515,7 @@ int main(int argc, char** argv) { /* Get informations from header file */ if (!(get_elf_header(&elf_Ehdr, p_elfimage))) { fprintf(stderr, "Error : file doesn't match expected format.\n"); + fclose(p_elfimage); exit(-1); } @@ -522,9 +533,10 @@ int main(int argc, char** argv) { /* copy the string table into global variable */ if (StringSec_size > MAX_SIZE_STRING_TABLE) { - fprintf(stderr, "Error: section name string table too big (%d > %d);" + fprintf(stderr, "Error: section name string table too big (%ld > %d);" " increase max. allowed value in source code and recompile\n", StringSec_size, MAX_SIZE_STRING_TABLE); + fclose(p_elfimage); exit(-1); } @@ -626,7 +638,7 @@ int main(int argc, char** argv) { if (verboselevel >= VERBOSE_LEVEL_MAIN_STEPS) printf("Info: entering action #5 (Jump to firmware/set stack-pointer).\n"); if (verboselevel >= VERBOSE_LEVEL_SECTION_DETAILS) - printf("Info: Firmware entry point = 0x%08x, setting stack pointer = 0x%08x.\n", elf_Ehdr.e_entry, stackpointer); + printf("Info: Firmware entry point = 0x%08x, setting stack pointer = 0x%08x.\n", (unsigned int)elf_Ehdr.e_entry, stackpointer); /* Open the special device file. */ if (!pflag) { @@ -665,7 +677,7 @@ int main(int argc, char** argv) { } /* pflag */ if (verboselevel >= VERBOSE_LEVEL_MAIN_STEPS) printf("Info: action #5 done.\n"); - + fclose(p_elfimage); /* Did we pretend ? */ diff --git a/targets/ARCH/EXMIMO/USERSPACE/OCTAVE/oarf_send_frame.cc b/targets/ARCH/EXMIMO/USERSPACE/OCTAVE/oarf_send_frame.cc index 1ebe3aeb4e306784f25d5d5f9430f2a495d9628c..8874b22c5ee4d57509c8213da293359d92d485eb 100644 --- a/targets/ARCH/EXMIMO/USERSPACE/OCTAVE/oarf_send_frame.cc +++ b/targets/ARCH/EXMIMO/USERSPACE/OCTAVE/oarf_send_frame.cc @@ -116,7 +116,7 @@ DEFUN_DLD (oarf_send_frame, args, nargout,"Send frame") for (i=0;i<4;i++) { resampling_factor[i] = (openair0_exmimo_pci[card].exmimo_config_ptr)->framing.resampling_factor[i]; - printf("card %d, ant %d, resampling %d\n",card,i,resampling_factor[i]); + printf("card %d, ant %d, resampling %u\n",card,i,resampling_factor[i]); } for (i=0;i<numcols;i++){ diff --git a/targets/ARCH/IRIS/USERSPACE/LIB/iris_lib.cpp b/targets/ARCH/IRIS/USERSPACE/LIB/iris_lib.cpp index 7abdf65498acf4c4eff9064481b2961f4ec07fe1..34a694a4d556a03cf56e18d4a7a527cfcf28d98b 100644 --- a/targets/ARCH/IRIS/USERSPACE/LIB/iris_lib.cpp +++ b/targets/ARCH/IRIS/USERSPACE/LIB/iris_lib.cpp @@ -35,7 +35,8 @@ #define SAMPLE_RATE_DOWN 1 /*! \brief Iris Configuration */ -typedef struct { +extern "C" { + typedef struct { // -------------------------------- // variables for Iris configuration @@ -78,8 +79,8 @@ typedef struct { //! timestamp of RX packet openair0_timestamp rx_timestamp; -} iris_state_t; - + } iris_state_t; +} /*! \brief Called to start the Iris lime transceiver. Return 0 if OK, < 0 if error @param device pointer to the device structure specific to the RF hardware target */ @@ -151,13 +152,15 @@ trx_iris_write(openair0_device *device, openair0_timestamp timestamp, void **buf iris_state_t *s = (iris_state_t *) device->priv; int nsamps2; // aligned to upper 32 or 16 byte boundary #if defined(__x86_64) || defined(__i386__) -#ifdef __AVX2__ + #ifdef __AVX2__ nsamps2 = (nsamps+7)>>3; __m256i buff_tx[2][nsamps2]; -#else + #else nsamps2 = (nsamps+3)>>2; __m128i buff_tx[2][nsamps2]; -#endif + #endif +#else + #error unsupported CPU architecture, iris device cannot be built #endif // bring RX data into 12 LSBs for softmodem RX @@ -705,7 +708,7 @@ int device_init(openair0_device *device, openair0_config_t *openair0_cfg) { for (i = 0; i < s->tx_num_channels; i++) { if (i < s->iris[r]->getNumChannels(SOAPY_SDR_TX)) { s->iris[r]->setBandwidth(SOAPY_SDR_TX, i, tx_filt_bw); - printf("Setting tx bandwidth on channel %lu/%lu: BW %f (readback %f)\n", i, + printf("Setting tx bandwidth on channel %zu/%lu: BW %f (readback %f)\n", i, s->iris[r]->getNumChannels(SOAPY_SDR_TX), tx_filt_bw / 1e6, s->iris[r]->getBandwidth(SOAPY_SDR_TX, i) / 1e6); } @@ -713,7 +716,7 @@ int device_init(openair0_device *device, openair0_config_t *openair0_cfg) { for (i = 0; i < s->rx_num_channels; i++) { if (i < s->iris[r]->getNumChannels(SOAPY_SDR_RX)) { s->iris[r]->setBandwidth(SOAPY_SDR_RX, i, rx_filt_bw); - printf("Setting rx bandwidth on channel %lu/%lu : BW %f (readback %f)\n", i, + printf("Setting rx bandwidth on channel %zu/%lu : BW %f (readback %f)\n", i, s->iris[r]->getNumChannels(SOAPY_SDR_RX), rx_filt_bw / 1e6, s->iris[r]->getBandwidth(SOAPY_SDR_RX, i) / 1e6); } @@ -776,7 +779,7 @@ int device_init(openair0_device *device, openair0_config_t *openair0_cfg) { std::cout << "Front end detected: " << s->iris[r]->getHardwareInfo()["frontend"] << "\n"; for (i = 0; i < s->rx_num_channels; i++) { if (i < s->iris[r]->getNumChannels(SOAPY_SDR_RX)) { - printf("RX Channel %lu\n", i); + printf("RX Channel %zu\n", i); printf("Actual RX sample rate: %fMSps...\n", (s->iris[r]->getSampleRate(SOAPY_SDR_RX, i) / 1e6)); printf("Actual RX frequency: %fGHz...\n", (s->iris[r]->getFrequency(SOAPY_SDR_RX, i) / 1e9)); printf("Actual RX gain: %f...\n", (s->iris[r]->getGain(SOAPY_SDR_RX, i))); @@ -794,7 +797,7 @@ int device_init(openair0_device *device, openair0_config_t *openair0_cfg) { for (i = 0; i < s->tx_num_channels; i++) { if (i < s->iris[r]->getNumChannels(SOAPY_SDR_TX)) { - printf("TX Channel %lu\n", i); + printf("TX Channel %zu\n", i); printf("Actual TX sample rate: %fMSps...\n", (s->iris[r]->getSampleRate(SOAPY_SDR_TX, i) / 1e6)); printf("Actual TX frequency: %fGHz...\n", (s->iris[r]->getFrequency(SOAPY_SDR_TX, i) / 1e9)); printf("Actual TX gain: %f...\n", (s->iris[r]->getGain(SOAPY_SDR_TX, i))); diff --git a/targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp b/targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp index 563e3755b78d712729a37bcd3787046400aadd72..f3094a4baaa78c32942a1450098c60443c2a194b 100644 --- a/targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp +++ b/targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp @@ -438,16 +438,18 @@ static int trx_usrp_write(openair0_device *device, openair0_timestamp timestamp, int nsamps2; // aligned to upper 32 or 16 byte boundary #if defined(__x86_64) || defined(__i386__) -#ifdef __AVX2__ - nsamps2 = (nsamps+7)>>3; - __m256i buff_tx[2][nsamps2]; -#else + #ifdef __AVX2__ + nsamps2 = (nsamps+7)>>3; + __m256i buff_tx[2][nsamps2]; + #else nsamps2 = (nsamps+3)>>2; __m128i buff_tx[2][nsamps2]; -#endif + #endif #elif defined(__arm__) nsamps2 = (nsamps+3)>>2; int16x8_t buff_tx[2][nsamps2]; +#else + #error Unsupported CPU architecture, USRP device cannot be built #endif // bring RX data into 12 LSBs for softmodem RX diff --git a/targets/RT/USER/lte-enb.c b/targets/RT/USER/lte-enb.c index 9db1684bd27b7c351d7459d0319d6ab649f3608d..8584fd1d1cbc1ab565c75982e1076a39beba79ee 100644 --- a/targets/RT/USER/lte-enb.c +++ b/targets/RT/USER/lte-enb.c @@ -167,7 +167,10 @@ static inline int rxtx(PHY_VARS_eNB *eNB,L1_rxtx_proc_t *proc, char *thread_name #if defined(PRE_SCD_THREAD) RU_t *ru = RC.ru[0]; #endif - + if (eNB ==NULL) { + LOG_D(PHY,"%s:%d: rxtx invalid argument, eNB pointer is NULL",__FILE__,__LINE__); + return -1; + } if (nfapi_mode == 1) { // I am a PNF and I need to let nFAPI know that we have a (sub)frame tick uint16_t frame = proc->frame_rx; @@ -206,7 +209,7 @@ static inline int rxtx(PHY_VARS_eNB *eNB,L1_rxtx_proc_t *proc, char *thread_name T(T_ENB_PHY_DL_TICK, T_INT(eNB->Mod_id), T_INT(proc->frame_tx), T_INT(proc->subframe_tx)); // if this is IF5 or 3GPP_eNB - if (eNB && eNB->RU_list && eNB->RU_list[0] && eNB->RU_list[0]->function < NGFI_RAU_IF4p5) { + if (eNB->RU_list && eNB->RU_list[0] && eNB->RU_list[0]->function < NGFI_RAU_IF4p5) { wakeup_prach_eNB(eNB,NULL,proc->frame_rx,proc->subframe_rx); #if (LTE_RRC_VERSION >= MAKE_VERSION(14, 0, 0)) wakeup_prach_eNB_br(eNB,NULL,proc->frame_rx,proc->subframe_rx); diff --git a/targets/RT/USER/lte-ru.c b/targets/RT/USER/lte-ru.c index 0583c689e66c85ab1e48ce0fe9cb2c6184e46eac..ce978d8b1affc2392d1aaf9639dbafb117e9c1a9 100644 --- a/targets/RT/USER/lte-ru.c +++ b/targets/RT/USER/lte-ru.c @@ -1456,7 +1456,7 @@ int setup_RU_buffers(RU_t *ru) { frame_parms = &ru->frame_parms; printf("setup_RU_buffers: frame_parms = %p\n",frame_parms); } else { - printf("RU[%d] not initialized\n", ru->idx); + printf("RU not initialized (NULL pointer)\n"); return(-1); } @@ -2469,8 +2469,8 @@ void configure_ru(int idx, if (capabilities->FH_fmt < MAX_FH_FMTs) LOG_I(PHY, "RU FH options %s\n",rru_format_options[capabilities->FH_fmt]); - - AssertFatal((ret=check_capabilities(ru,capabilities)) == 0, + ret=check_capabilities(ru,capabilities); + AssertFatal((ret == 0), "Cannot configure RRU %d, check_capabilities returned %d\n", idx,ret); // take antenna capabilities of RRU ru->nb_tx = capabilities->nb_tx[0]; diff --git a/targets/RT/USER/lte-ue.c b/targets/RT/USER/lte-ue.c index 1fe1d4c06b1feeec523976666c80c5f58dad5cb7..f67dbeca7efd0c17557f3e0d35d53028b312d46c 100644 --- a/targets/RT/USER/lte-ue.c +++ b/targets/RT/USER/lte-ue.c @@ -971,6 +971,10 @@ static void *UE_phy_stub_single_thread_rxn_txnp4(void *arg) { //int init_ra_UE = -1; // This counter is used to initiate the RA of each UE in different SFrames static __thread int UE_thread_rxtx_retval; struct rx_tx_thread_data *rtd = arg; + if (rtd == NULL) { + LOG_E( MAC, "[SCHED][UE] rx_tx_thread_data *rtd: NULL pointer\n" ); + exit_fun("nothing to add"); + } UE_rxtx_proc_t *proc = rtd->proc; // settings for nfapi-L2-emulator mode @@ -984,9 +988,8 @@ static void *UE_phy_stub_single_thread_rxn_txnp4(void *arg) { proc = &PHY_vars_UE_g[0][0]->proc.proc_rxtx[0]; phy_stub_ticking->num_single_thread[ue_thread_id] = -1; - if (rtd != NULL) { - UE = rtd->UE; - } + UE = rtd->UE; + if(ue_thread_id == 0){ phy_stub_ticking->ticking_var = -1; diff --git a/targets/RT/USER/lte-uesoftmodem.c b/targets/RT/USER/lte-uesoftmodem.c index a3aa0036628cdda51be0b0014de6fa5aedee89fa..13cc859414314ccc8d2162c2962c35111571bd3a 100644 --- a/targets/RT/USER/lte-uesoftmodem.c +++ b/targets/RT/USER/lte-uesoftmodem.c @@ -693,9 +693,13 @@ int main( int argc, char **argv ) { #if defined (XFORMS) int ret; #endif + configmodule_interface_t *config_mod; + start_background_system(); - if ( load_configmodule(argc,argv,CONFIG_ENABLECMDLINEONLY) == NULL) { + config_mod = load_configmodule(argc, argv, CONFIG_ENABLECMDLINEONLY); + + if (config_mod == NULL) { exit_fun("[SOFTMODEM] Error, configuration module init failed\n"); } @@ -811,8 +815,6 @@ int main( int argc, char **argv ) { } else init_openair0(frame_parms[0],(int)rx_gain[0][0]); if (simL1flag==1) { - AssertFatal(NULL!=load_configmodule(argc,argv,CONFIG_ENABLECMDLINEONLY), - "[SOFTMODEM] Error, configuration module init failed\n"); RCConfig_sim(); } diff --git a/targets/RT/USER/rt_wrapper.c b/targets/RT/USER/rt_wrapper.c index 443d183068e634ab97e751d7ed5f448edd820732..b55bafed1b00727416d7b94a30cbebd91ef084ef 100644 --- a/targets/RT/USER/rt_wrapper.c +++ b/targets/RT/USER/rt_wrapper.c @@ -125,7 +125,7 @@ void check_clock(void) if (clock_getres(clock_id, &res)) { printf("clock_getres failed"); } else { - printf("reported resolution = %llu ns\n", (long long int) ((int) 1e9 * res.tv_sec) + (long long int) res.tv_nsec); + printf("reported resolution = %lld ns\n", (long long int) ((int) 1e9 * res.tv_sec) + (long long int) res.tv_nsec); } } diff --git a/targets/TEST/PACKET_TRACER/pt.c b/targets/TEST/PACKET_TRACER/pt.c index 030b63ab907319283059e4b8bdd74a2ceb4814cc..510865d33e5ab3a802544522ecdd36fbe444e564 100644 --- a/targets/TEST/PACKET_TRACER/pt.c +++ b/targets/TEST/PACKET_TRACER/pt.c @@ -166,7 +166,8 @@ int input_text(char *file,char *sdu) printf("byte %d: %x (%s%s)\n",b_ind,byte,binary_table[byte>>4],binary_table[byte&0xf]); b_ind++; } - + if (fd) + fclose(fd); return(b_ind); } @@ -220,14 +221,14 @@ int parse_args(int argc, char** argv, args_t* args) case 'I': strcpy(args->input1_file,optarg); args->input1_sdu_len = input_text(args->input1_file,args->input1_sdu); - printf("Got sdu1 of length %d bytes\n",args->input1_sdu_len); + printf("Got sdu1 of length %u bytes\n",args->input1_sdu_len); args->input1_sdu_flag=1; break; case 'J': strcpy(args->input2_file,optarg); args->input2_sdu_len = input_text(args->input2_file,args->input2_sdu); - printf("Got sdu2 of length %d bytes\n",args->input2_sdu_len); + printf("Got sdu2 of length %u bytes\n",args->input2_sdu_len); args->input2_sdu_flag=1; break; @@ -530,7 +531,8 @@ int main (int argc, char **argv) if (args.input_sib == 0) { openair_rrc_lite_eNB_init(0); } else { - printf("Got SI from files (%d,%d,%d,%d,%d)\n",args.input_sib,args.input1_sdu_flag,args.input2_sdu_flag); + printf("Got SI from files (%d,%d,%d)\n", + args.input_sib,args.input1_sdu_flag,args.input2_sdu_flag); } openair_rrc_on(0,0); diff --git a/targets/TEST/PDCP/test_pdcp.c b/targets/TEST/PDCP/test_pdcp.c index a999bb254dfcbd80184740ebb694ad907b0fcd85..b62edf1215410921f3c9e27fbe7d4c55b9400fd3 100644 --- a/targets/TEST/PDCP/test_pdcp.c +++ b/targets/TEST/PDCP/test_pdcp.c @@ -249,7 +249,7 @@ BOOL test_pdcp_data_req(void) * information if we pass mem_block_ts via a linked list? */ - if (pdcp_test_pdu_buffer_size == 0 || pdcp_test_pdu_buffer == NULL) { + if (pdcp_test_pdu_buffer_size == 0 ) { msg("[TEST] PDU created by pdcp_data_req() is invalid!\n"); return FALSE; } diff --git a/targets/TEST/PDCP/with_rlc/test_pdcp_rlc.c b/targets/TEST/PDCP/with_rlc/test_pdcp_rlc.c index d3efbe139f1293b330383249a81c8890fcecdd86..9f28fd7c78a6c3182fec9f763676e2e68ecd6dac 100644 --- a/targets/TEST/PDCP/with_rlc/test_pdcp_rlc.c +++ b/targets/TEST/PDCP/with_rlc/test_pdcp_rlc.c @@ -125,7 +125,7 @@ void pdcp_rlc_test_mac_rlc_loop (struct mac_data_ind *data_indP, struct mac_dat if (tb_src != NULL) { tb_size = ((struct mac_tb_req *) (tb_src->data))->tb_size_in_bits >> 3; - printf("[RLC-LOOP] FOUND TB SIZE IN BITS %d IN BYTES %d sizeof (mac_rlc_max_rx_header_size_t) %d\n", + printf("[RLC-LOOP] FOUND TB SIZE IN BITS %d IN BYTES %u sizeof (mac_rlc_max_rx_header_size_t) %d\n", ((struct mac_tb_req *) (tb_src->data))->tb_size_in_bits, tb_size, sizeof (mac_rlc_max_rx_header_size_t));