From f8585ccc04cad8f4876bbcb4f58d4377ce61363b Mon Sep 17 00:00:00 2001 From: Doug McLain Date: Sat, 6 Nov 2021 00:43:54 -0400 Subject: [PATCH] Fix MMDVM modem buffer overrun on receive for YSF and DMR --- DroidStar.pro.user | 487 --------------------------------------------- dmrcodec.cpp | 4 +- main.qml | 6 - serialmodem.cpp | 27 ++- ysfcodec.cpp | 4 +- 5 files changed, 28 insertions(+), 500 deletions(-) delete mode 100644 DroidStar.pro.user diff --git a/DroidStar.pro.user b/DroidStar.pro.user deleted file mode 100644 index e33ca9f..0000000 --- a/DroidStar.pro.user +++ /dev/null @@ -1,487 +0,0 @@ - - - - - - EnvironmentId - {1b40929c-f363-44e6-ae48-8bc2eb02f152} - - - ProjectExplorer.Project.ActiveTarget - 0 - - - ProjectExplorer.Project.EditorSettings - - true - false - true - - Cpp - - CppGlobal - - - - QmlJS - - QmlJSGlobal - - - 2 - UTF-8 - false - 4 - false - 80 - true - true - 1 - false - true - false - 0 - true - true - 0 - 8 - true - false - 1 - true - true - true - *.md, *.MD, Makefile - false - true - - - - ProjectExplorer.Project.PluginSettings - - - true - false - true - true - true - true - - - 0 - true - - true - Builtin.BuildSystem - - true - true - Builtin.DefaultTidyAndClazy - 12 - - - - true - - - - - ProjectExplorer.Project.Target.0 - - Android.Device.Type - Android Qt 5.15.2 Clang Multi-Abi - Android Qt 5.15.2 Clang Multi-Abi - {955eaf34-57a0-4cce-b8ac-8097bc82fcb9} - 1 - 0 - 0 - - 0 - /mnt/data/src/qt-projects/build-DroidStar-Android_Qt_5_15_2_Clang_Multi_Abi-Debug - /mnt/data/src/qt-projects/build-DroidStar-Android_Qt_5_15_2_Clang_Multi_Abi-Debug - - - true - QtProjectManager.QMakeBuildStep - false - - armeabi-v7a - - - - true - Qt4ProjectManager.MakeStep - - - true - Copy application data - Qt4ProjectManager.AndroidPackageInstallationStep - - - android-31 - - true - Build Android APK - QmakeProjectManager.AndroidBuildApkStep - false - - 4 - Build - Build - ProjectExplorer.BuildSteps.Build - - - - true - Qt4ProjectManager.MakeStep - clean - - 1 - Clean - Clean - ProjectExplorer.BuildSteps.Clean - - 2 - false - - - Debug - Qt4ProjectManager.Qt4BuildConfiguration - 2 - - - /mnt/data/src/qt-projects/build-DroidStar-Android_Qt_5_15_2_Clang_Multi_Abi-Release - /mnt/data/src/qt-projects/build-DroidStar-Android_Qt_5_15_2_Clang_Multi_Abi-Release - - - true - QtProjectManager.QMakeBuildStep - false - - armeabi-v7a - arm64-v8a - - - - true - Qt4ProjectManager.MakeStep - - - true - Copy application data - Qt4ProjectManager.AndroidPackageInstallationStep - - - android-29 - - true - Build Android APK - QmakeProjectManager.AndroidBuildApkStep - false - - 4 - Build - Build - ProjectExplorer.BuildSteps.Build - - - - true - Qt4ProjectManager.MakeStep - clean - - 1 - Clean - Clean - ProjectExplorer.BuildSteps.Clean - - 2 - false - - - Release - Qt4ProjectManager.Qt4BuildConfiguration - 0 - 0 - - - 0 - /mnt/data/src/qt-projects/build-DroidStar-Android_Qt_5_15_2_Clang_Multi_Abi-Profile - /mnt/data/src/qt-projects/build-DroidStar-Android_Qt_5_15_2_Clang_Multi_Abi-Profile - - - true - QtProjectManager.QMakeBuildStep - false - - - - true - Qt4ProjectManager.MakeStep - - - true - Copy application data - Qt4ProjectManager.AndroidPackageInstallationStep - - - android-31 - - true - Build Android APK - QmakeProjectManager.AndroidBuildApkStep - false - - 4 - Build - Build - ProjectExplorer.BuildSteps.Build - - - - true - Qt4ProjectManager.MakeStep - clean - - 1 - Clean - Clean - ProjectExplorer.BuildSteps.Clean - - 2 - false - - - Profile - Qt4ProjectManager.Qt4BuildConfiguration - 0 - 0 - 0 - - 3 - - - - true - Qt4ProjectManager.AndroidDeployQtStep - - 1 - Deploy - Deploy - ProjectExplorer.BuildSteps.Deploy - - 1 - - false - Qt4ProjectManager.AndroidDeployConfiguration2 - - 1 - - - arm64-v8a - armeabi-v7a - armeabi - - 192.168.1.69:55555 - 30 - - - true - true - 2 - true - - - - - - - - 0 - - DroidStar - Qt4ProjectManager.AndroidRunConfiguration:/mnt/data/src/qt-projects/DroidStar/DroidStar.pro - /mnt/data/src/qt-projects/DroidStar/DroidStar.pro - false - true - false - true - - 1 - - - - ProjectExplorer.Project.Target.1 - - Desktop - Desktop Qt 5.15.2 GCC 64bit - Desktop Qt 5.15.2 GCC 64bit - qt.qt5.5152.gcc_64_kit - 0 - 0 - 0 - - 0 - /mnt/data/src/qt-projects/build-DroidStar-Desktop_Qt_5_15_2_GCC_64bit-Debug - /mnt/data/src/qt-projects/build-DroidStar-Desktop_Qt_5_15_2_GCC_64bit-Debug - - - true - QtProjectManager.QMakeBuildStep - false - - - - true - Qt4ProjectManager.MakeStep - - 2 - Build - Build - ProjectExplorer.BuildSteps.Build - - - - true - Qt4ProjectManager.MakeStep - clean - - 1 - Clean - Clean - ProjectExplorer.BuildSteps.Clean - - 2 - false - - - Debug - Qt4ProjectManager.Qt4BuildConfiguration - 2 - - - /mnt/data/src/qt-projects/build-DroidStar-Desktop_Qt_5_15_2_GCC_64bit-Release - /mnt/data/src/qt-projects/build-DroidStar-Desktop_Qt_5_15_2_GCC_64bit-Release - - - true - QtProjectManager.QMakeBuildStep - false - - - - true - Qt4ProjectManager.MakeStep - - 2 - Build - Build - ProjectExplorer.BuildSteps.Build - - - - true - Qt4ProjectManager.MakeStep - clean - - 1 - Clean - Clean - ProjectExplorer.BuildSteps.Clean - - 2 - false - - - Release - Qt4ProjectManager.Qt4BuildConfiguration - 0 - 0 - - - 0 - /mnt/data/src/qt-projects/build-DroidStar-Desktop_Qt_5_15_2_GCC_64bit-Profile - /mnt/data/src/qt-projects/build-DroidStar-Desktop_Qt_5_15_2_GCC_64bit-Profile - - - true - QtProjectManager.QMakeBuildStep - false - - - - true - Qt4ProjectManager.MakeStep - - 2 - Build - Build - ProjectExplorer.BuildSteps.Build - - - - true - Qt4ProjectManager.MakeStep - clean - - 1 - Clean - Clean - ProjectExplorer.BuildSteps.Clean - - 2 - false - - - Profile - Qt4ProjectManager.Qt4BuildConfiguration - 0 - 0 - 0 - - 3 - - - 0 - Deploy - Deploy - ProjectExplorer.BuildSteps.Deploy - - 1 - - false - ProjectExplorer.DefaultDeployConfiguration - - 1 - - true - true - 2 - true - - 2 - - Qt4ProjectManager.Qt4RunConfiguration:/mnt/data/src/qt-projects/DroidStar/DroidStar.pro - /mnt/data/src/qt-projects/DroidStar/DroidStar.pro - false - true - true - false - true - - 1 - - - - ProjectExplorer.Project.TargetCount - 2 - - - ProjectExplorer.Project.Updater.FileVersion - 22 - - - Version - 22 - - diff --git a/dmrcodec.cpp b/dmrcodec.cpp index d3024f7..c5de0a1 100755 --- a/dmrcodec.cpp +++ b/dmrcodec.cpp @@ -925,6 +925,7 @@ void DMRCodec::process_rx_data() { int16_t pcm[160]; uint8_t ambe[9]; + static uint8_t cnt = 0; if(m_rxwatchdog++ > 100){ qDebug() << "DMR RX stream timeout "; @@ -935,7 +936,7 @@ void DMRCodec::process_rx_data() m_modeinfo.streamid = 0; } - if(m_rxmodemq.size() > 2){ + if((m_rxmodemq.size() > 2) && (++cnt >= 3)){ QByteArray out; int s = m_rxmodemq[1]; if((m_rxmodemq[0] == 0xe0) && (m_rxmodemq.size() >= s)){ @@ -944,6 +945,7 @@ void DMRCodec::process_rx_data() } m_modem->write(out); } + cnt = 0; } if((!m_tx) && (m_rxcodecq.size() > 8) ){ diff --git a/main.qml b/main.qml index 43c65b0..9965073 100644 --- a/main.qml +++ b/main.qml @@ -448,12 +448,6 @@ ApplicationWindow { if(mainTab.comboMode.currentText != "REF"){ mainTab.comboModule.enabled = false; } - if( (mainTab.comboMode.currentText == "REF") || - (mainTab.comboMode.currentText == "DCS") || - (mainTab.comboMode.currentText == "XRF")) - { - disclaimerDialog.open(); - } if(mainTab.comboMode.currentText === "YSF"){ settingsTab.m171600.checked = true; } diff --git a/serialmodem.cpp b/serialmodem.cpp index b19cb3d..3d2bce9 100644 --- a/serialmodem.cpp +++ b/serialmodem.cpp @@ -20,7 +20,7 @@ #include #include "serialmodem.h" -//#define DEBUGHW +#define DEBUGHW #define ENDLINE "\n" const unsigned char MODE_IDLE = 0U; @@ -278,18 +278,35 @@ void SerialModem::process_modem() const uint8_t r = (uint8_t)m_serialdata[2]; const uint8_t s = (uint8_t)m_serialdata[1]; - if(m_serialdata.size() >= m_serialdata[1]){ + if(r == MMDVM_NAK){ + qDebug() << "Received MMDVM_NAK"; for(int i = 0; i < s; ++i){ - out.append(m_serialdata.dequeue()); + m_serialdata.dequeue(); } - emit modem_data_ready(out); } - if(r == MMDVM_GET_VERSION){ + else if(r == MMDVM_ACK){ + qDebug() << "Received MMDVM_ACK"; + for(int i = 0; i < s; ++i){ + m_serialdata.dequeue(); + } + } + + else if(r == MMDVM_GET_VERSION){ QThread::msleep(100); set_freq(); QThread::msleep(100); set_config(); + for(int i = 0; i < s; ++i){ + m_serialdata.dequeue(); + } + } + + else if(m_serialdata.size() >= m_serialdata[1]){ + for(int i = 0; i < s; ++i){ + out.append(m_serialdata.dequeue()); + } + emit modem_data_ready(out); } } } diff --git a/ysfcodec.cpp b/ysfcodec.cpp index 0195b62..dfac2f0 100755 --- a/ysfcodec.cpp +++ b/ysfcodec.cpp @@ -1276,6 +1276,7 @@ void YSFCodec::process_rx_data() int16_t pcm[160]; uint8_t ambe[7]; uint8_t imbe[11]; + static uint8_t cnt = 0; if(m_rxwatchdog++ > 20){ qDebug() << "YSF RX stream timeout "; @@ -1284,7 +1285,7 @@ void YSFCodec::process_rx_data() emit update(m_modeinfo); } - if(m_rxmodemq.size() > 2){ + if((m_rxmodemq.size() > 2) && (++cnt >= 5)){ QByteArray out; int s = m_rxmodemq[1]; if((m_rxmodemq[0] == 0xe0) && (m_rxmodemq.size() >= s)){ @@ -1293,6 +1294,7 @@ void YSFCodec::process_rx_data() } m_modem->write(out); } + cnt = 0; } if(m_modeinfo.type == 3){