34 Commits

Author SHA1 Message Date
lwvmobile
f6cd915f4d Misc Tweaks; Multi BP; More CapMax FLCO; XPT; 2023-02-23 21:59:08 -05:00
lwvmobile
1dfd59801e Literature Update; 2023-02-22 20:00:24 -05:00
lwvmobile
c4513fab7a NXDN Tweaks and SACCH/FACCH CRC Fixes; 2023-02-22 19:46:06 -05:00
lwvmobile
a3b8839897 Minor Cap+ and XPT Fix; 2023-02-21 13:55:15 -05:00
lwvmobile
9e009867ff Disable/Tweak some setmod_bw defaults; 2023-02-20 17:59:53 -05:00
lwvmobile
e95e2218d9 Cap+ NL; Hytera XPT Trunk Support (experimental) 2023-02-20 12:47:30 -05:00
lwvmobile
a9742043b8 General DMR Tweaks; 64-bit IV from 32-bit MI; 2023-02-20 12:43:16 -05:00
lwvmobile
05eef039c9 DMR - LRRP tweaks; Add LOCN PDU. 2023-02-20 12:41:20 -05:00
lwvmobile
818e952b7b DMR - dheader rewrite; UDT/USBD fix; block tweaks; 2023-02-20 12:40:42 -05:00
lwvmobile
38b962aacf P25 Dibit, Block and PDU Payload Tweaks; 2023-02-20 12:35:44 -05:00
lwvmobile
0217202801 DMR - Fix Cap+ CSBK; Various Minor Fixes; 2023-02-05 16:47:58 -05:00
lwvmobile
ef07b48540 DMR Minor Code Fixes; 2023-02-04 20:10:38 -05:00
lwvmobile
db67a8b227 NCurses Compiler Warning and Call Alert Fix; 2023-02-04 04:35:06 -05:00
lwvmobile
4e2c4577d5 DMR Cap+ CSBK Improvements; 2023-02-03 22:15:13 -05:00
lwvmobile
e581c96560 DMR FLCO Tweaks; P25 Site/RFSS Display; 2023-02-02 20:03:52 -05:00
lwvmobile
f3505269d0 DMR Conf Data CRC9; Message CRC32; Tweaks; 2023-02-01 05:35:21 -05:00
lwvmobile
20ccdbbced DMR FLC Tweaks; CSBK Cleaning; 2023-02-01 05:31:40 -05:00
lwvmobile
fc2fb99502 P25P2 OSS Bugfix; 2023-01-29 18:41:03 -05:00
lwvmobile
143c560958 DMR FLCO - Check PF First; 2023-01-29 16:09:47 -05:00
lwvmobile
d122d7e935 DMR Unknown FLCO Tweaks; PI Tweaks; 2023-01-28 21:00:13 -05:00
lwvmobile
d0f9bb4bad Fix DMR FEC/CRC/RAS Implementation Issues; 2023-01-21 05:43:42 -05:00
lwvmobile
ac752029bd Tweak RAS/CRC; Other Misc Tweaks; 2023-01-19 09:42:42 -05:00
lwvmobile
5b994f5129 NXDN Multi-Key CSV Import; Example Updt; 2023-01-18 12:18:56 -05:00
lwvmobile
ec7d7c24a5 DMR SB/RC Additions; Cap+ LC/CSBK; RAS; 2023-01-17 23:58:52 -05:00
lwvmobile
1d49481f2d Fix/Restore MBEout Files; 'DSP' CACH; Tweaks; 2023-01-17 02:25:53 -05:00
lwvmobile
7ca8cb421c Cap+ FLC/CSBK Tweaks; 2023-01-17 02:08:25 -05:00
lwvmobile
4eb44b3c67 'DSP' File Output for OKDMR - Initial Commit; 2023-01-15 22:04:04 -05:00
lwvmobile
e16e4b61fc Cap+ Things; 2023-01-15 21:22:28 -05:00
lwvmobile
fbd04fa869 Allow Standard BP Key on MBE File Playback; 2023-01-15 18:13:48 -05:00
lwvmobile
7f9b852f36 Fix Audio Gain/Device Out on MBE File Playback; 2023-01-15 18:12:15 -05:00
lwvmobile
f5a7ab2b77 P25 P2 ISCH Var Fix; 2023-01-15 18:09:47 -05:00
lwvmobile
ffe6098fb8 DMR Cap+ Rest Channel FLCO/SLCO Fix; 2023-01-09 19:39:05 -05:00
lwvmobile
157ca8c043 RTL Input Tuning Fix (UDP); Minor Tweaks; 2023-01-09 14:13:00 -05:00
lwvmobile
b722e43a3a dPMR Scrambler Key Support; 2023-01-07 18:41:44 -05:00
42 changed files with 4213 additions and 2574 deletions

2
.gitignore vendored
View File

@@ -5,3 +5,5 @@ build
*.sh *.sh
*.csv *.csv
examples examples
*.bin
*.ans

View File

@@ -2,29 +2,6 @@
This branch is for modifications to make a Windows 32-bit binary to be precompiled, please DO NOT use this branch if you are a Linux User, or copy any contents out of here to modify your existing setup! This branch is for modifications to make a Windows 32-bit binary to be precompiled, please DO NOT use this branch if you are a Linux User, or copy any contents out of here to modify your existing setup!
# Digital Speech Decoder - Florida Man Edition
DSD-FME is an evolution of the original DSD project from 'DSD Author' using the base code of [szechyjs](https://github.com/szechyjs/dsd "szechyjs"), some code and ideas from [LouisErigHerve](https://github.com/LouisErigHerve/dsd "LouisErigHerve"), [Boatbod OP25](https://github.com/boatbod/op25 "Boatbod OP25") and
[Osmocom OP25](https://gitea.osmocom.org/op25/op25 "Osmocom OP25"), along with other snippets of code, information, and inspirations from other projects including [DSDcc](https://github.com/f4exb/dsdcc "DSDcc"), [SDTRunk](https://github.com/DSheirer/sdrtrunk "SDRTrunk"), [MMDVMHost](https://github.com/g4klx/MMDVMHost "MMDVMHost"), [LFSR](https://github.com/mattames/LFSR "LFSR"), [OK-DMRlib](https://github.com/OK-DMR/ok-dmrlib "OK-DMRlib"), and [EZPWD-Reed-Solomon](https://github.com/pjkundert/ezpwd-reed-solomon "EZPWD"), Eric Cottrell, SP5WWP and others. Finally, this is all brought together with original code to extend the fuctionality and add new features including NCurses Terminal and Menu system, Pulse Audio, TCP Direct Link Audio, RIGCTL, Trunking Features, LRRP/GPS Mapping, P25 Phase 2, EDACS, OP25 Capture Bin compatability, etc. DSD-FME is primarily focused with Linux Desktop users, so please understand that this version may not compile, compile easily, or run correctly in other environments.
This project wouldn't be possible without a few good people providing me plenty of sample audio files to run over and over again. Special thanks to jurek1111, KrisMar, noamlivne, racingfan360, iScottyBotty, LimaZulu and others for the many hours of wav samples submitted by them. Most importantly, HRH17, whose insight, information, samples, and willingness to let me remote into a computer half-way across the globe in order to test trunking features are what make DSD-FME what it has become. Thank you everybody.
Click image below for video of current DMR/P25 trunking capabilities.
[![DSD-FME](https://github.com/lwvmobile/dsd-fme/blob/main/dsd-fme.png)](https://www.youtube.com/watch?v=hGIijBbbUxg "DSD-FME Trunking Demo")
![DSD-FME](https://github.com/lwvmobile/dsd-fme/blob/main/dsd-fme2.png)
![DSD-FME](https://github.com/lwvmobile/dsd-fme/blob/main/dsd-fme3.png)
## Information
See the [examples](https://github.com/lwvmobile/dsd-fme/tree/main/examples "examples") folder for information on [cloning and installing](https://github.com/lwvmobile/dsd-fme/blob/main/examples/Install_Notes.md "cloning and installing"), [example usage](https://github.com/lwvmobile/dsd-fme/blob/main/examples/Example_Usage.md "example usage"), and [trunking examples](https://github.com/lwvmobile/dsd-fme/blob/main/examples/trunking.sh "trunking examples").
## Notice
The pulseaudio branch has been deleted in favor of the new main branch which also uses Pulse Audio. Users moving to the main branch should review the help file and example usage files for changes in syntax. Users can download the last pulse audio branch version from the release link if they prefer the older version. Any pre-compiled windows versions found in the release link will be considered legacy as well, and do not feature trunking support and have older handling for some other modes. Users are free to use those, but keep in mind the use case syntax may and will be different between versions. Furthermore, any wiki articles with 'auto intstall scripts' made for windows users may contain outdated information for building the deleted pulseaudio branch, please adjust any information found in those accordingly.
## License ## License
Copyright (C) 2010 DSD Author Copyright (C) 2010 DSD Author
GPG Key ID: 0x3F1D7FD0 (74EF 430D F7F2 0A48 FCE6 F630 FAA2 635D 3F1D 7FD0) GPG Key ID: 0x3F1D7FD0 (74EF 430D F7F2 0A48 FCE6 F630 FAA2 635D 3F1D 7FD0)

View File

@@ -1,162 +0,0 @@
## Notice
These examples will need to be modified to run on the 'lite' branch, or any precompiled Windows binaries released. (i.e. dsd-fme to dsd-fme-lite.exe, -i pulse -o pulse, etc)
### Example Usage and Notes!
`dsd-fme` is all you need to run for pulse input, pulse output, and auto detect for DMR BS/MS, and P25 (1 and 2) . To use other decoding methods which cannot be auto detected, please use the following command line switches. Make sure to route audio into and out of DSD-FME using pavucontrol and virtual sinks as needed.
```
-ft XDMA decoder class (P25 1 and 2, and DMR Stereo)
-fs DMR Stereo, also may need to use -xr if inverted DMR
-fa Legacy Auto (not recommended)
-fi NXDN48
-fn NXDN96
-fp ProVoice
-fm dPMR, also may need to use -xd if inverted dPMR.
-fr DMR Mono, also may need to use -xr if inverted DMR.
-f1 P25P1
-f2 P25P2 (will need to specify wacn/sys/nac manually)
-fx X2-TDMA
```
## Trunking Examples
Please see trunking.sh for sample start up scripts or scroll down to the bottom for more explanation.
## Example Usage - Default Decoder, Ncurses Terminal, Pulse Input/Output, and Log Console to file
`dsd-fme -N 2> voice.log`
and in a second terminal tab, same folder, run
`tail -n 40 -f voice.log`
Then you can open up your pavucontrol "Pulse Audio Volume Control" or "Volume Control" application and route input into DSD-FME from any application and DSD-FME output to the left and right speakers respectively. (unlock the channel in the application stream and adjust left and right independently)
### Input ###
--TCP Direct Audio Link with SDR++
`dsd-fme -i tcp` Currently defaults to localhost:7355 (SDR++ defaults)
`dsd-fme -i tcp:192.168.7.5:7356` (remote host and custom port)
--48000/9600 Mono Wav File Input
`dsd-fme -i filename.wav` 48k/1 Audio (SDR++, GQRX wav recordings)
`dsd-fme -i filename.wav -s 96000` 96k/1 (DSDPlus Raw Signal Wav Files)
Wav File Input Note: Due to 96000 rate audio requiring me to double the symbol rate and center, be sure to use the -s 96000 at the very end of the startup command. Also, some NXDN48/96 may have difficulties decoding properly with wav file input.
## Example Usage - RTL2832 Dongle Input
`dsd-fme -ft -i rtl:0:154.9875M:26:-2:8:0:6020 `
```
RTL-SDR options:
WARNING! Old CLI Switch Handling has been depreciated in favor of rtl:<parms>
Usage: rtl:dev:freq:gain:ppm:bw:sq:udp
dev <num> RTL-SDR Device Index Number
freq <num> RTL-SDR Frequency (851800000 or 851.8M)
gain <num> RTL-SDR Device Gain (0-49) (default = 26)(0 = Hardware AGC, not recommended)
ppm <num> RTL-SDR PPM Error (default = 0)
bw <num> RTL-SDR VFO Bandwidth kHz (default = 12)(6, 8, 12, 24)
sq <num> RTL-SDR Squelch Level (0 - Open, 25 - Little, 50 - Higher)
udp <num> RTL-SDR UDP Remote Port (default = 6020)
Example: dsd-fme -fp -i rtl:0:851.375M:22:-2:12:0:6021
```
## Example Usage - Extra Payload/PDU Logging
`dsd-fme -Z -N 2>> log.ans`
and in a second terminal tab, same folder, run
`tail -n 40 -f log.ans`
### EDACS/P25/NXDN/DMR Simple/Single VFO Trunking ###
EDACS Trunking (w/ channel map import)
--EDACS/PV Trunking using RIGCTL and TCP Direct Link Audio inside of SDR++ (Tested and Working on EDACS/EDACS-EA with Provoice only, no analog voice monitoring)
`dsd-fme -i tcp -fp -C channel_map.csv -G group.csv -T -U 4532 -N 2> log.ans`
--NXDN48 Trunking (standard band plan) with SDR++ (untested for frequency accuracy)
`dsd-fme -fi -i tcp -T -U 4532 -N 2> log.ans`
--NXDN48 Trunking (w/ channel map import) with SDR++ (put control channel frequency at channel 0 in channel_map.csv)
`dsd-fme -fi -i tcp -T -U 4532 -C channel_map.csv -N 2> log.ans`
--DMR Trunking (w/ channel map import) with SDR++ (put control channel frequency at channel 0 (TIII and Con+) in channel_map.csv)
`dsd-fme -fs -i tcp -T -U 4532 -C channel_map.csv -N 2> log.ans`
--P25 Trunking P1 and P2 (C4FM) with SDR++
`dsd-fme -i tcp -T -U 4532 -N 2> log.ans`
--P25 Trunking (CQPSK) with P1 Control Channel (Should switch symbol rate and center on Phase 2 audio channels)
`dsd-fme -i tcp -T -U 4532 -N -mq 2> log.ans`
--P25 Trunking Phase 2 TDMA Control Channel systems with CQPSK (non Phase 1 systems)
`dsd-fme -i tcp -T -U 4532 -N -f2 -m2 2> log.ans`
Trunking Note1: All samples above can also be run with the RTL input method and setting of RTL UDP remote port. In terms of performance, however, SDR++ will do a much better job on weaker/marginal signal compared to the RTL input. RTL input should only be used on strong signal.
`dsd-fme -fp -i rtl:0:851.8M:22:-2:24:0:6020 -T -C channel_map.csv -G group.csv -N 2> log.ans`
Trunking Note2: CQPSK Phase 1 and Phase 2 Systems are subceptible to LSM distortion issues, but seem to do okay, but require really good signal. Some CRC issues still occur with Phase 2 TDMA LCCH Mac Signal that can affect reliability, I believe this issue is ultimately caused by the PSK demodulation inside of FME. I also don't believe this will work on 8-level PSK, but I cannot determine that at the moment. Update: I have improved the LCCH Mac Signal decoding my increasing the QPSK decision point buffers to their maximum values.
Trunking Note3: DMR Trunking has been coded, and some testing and tweaks have been carried out. Cap+, Con+, and TIII systems seem to do well with trunking now. Placing the frequency for the control channel at channel map 0 in your channel_map.csv file is not required now if using RIGCTL or the RTL Input, both can poll the VFO for the current frequency if it believes its on a control channel, but setting a fake channel number (i.e. 999) first with the CC frequency will result in finding the CC faster on startup if desired. If you need to map out your channels for TIII, you can observe the console output and look for channel numbers. For conveniece I have included the DSDPlus channel numbering (as best as I can figure it, but they seem consistent) into the console print so it will make it easier for users from DSDPlus to map frequencies into the channel_map.csv file. Make sure your channel numbers are the Cd (channel decimal) values from the log, and not the C+ (dsdplus) values. Notice: TIII Site ID value needs work to determine proper DMRLA values for system area and sub area.
```
Talkgroup Voice Channel Grant (TV_GRANT) - Logical
Ch [036] Cd [0054] C+ [0110] - TS [1] - Target [01900500] - Source [01900505]
```
Use channel 54 in your import file, which would correspond to dsdplus channels 109 and 110 (109 = TS0 / 110 = TS1).
For Connect Plus, enumerate your list from 1 to the last channel and add the frequency. For Capacity Plus, Rest Channels 1 and 2 will share the same frequency, 3 and 4 will share, 5 and 6 will share, and 7-8 will share, as Capacity Plus counts each RF frequency as two seperate channels, one for each time slot. Capacity Plus Quirk: DSD-FME makes its best effort to follow the rest channel in the event that the sync is lost for longer than the hangtime, but occassionally, DSD-FME will lose the rest channel and will have to hunt through all frequencies to find it again.
Currently uncoded/unknown DMR trunking systems include Hytera XPT.
Trunking Note4: NXDN Trunking may also require a channel map file, depending on the system. If it uses a custom range (above 800), then channels will need to be mapped. If channels do not require mapping (have channels below 800) but you are not tuning properly, then please use a channel_map and please report the issue in the issues along with the channels you are tuning and the actual rf frequency so corrections can be made.
Channel Map and Group CSV Note: Leave the top line of the channel_map.csv and group.csv as the label, do not delete the line, if no line is there, dsd_import skips the first line so it will not import the first channel or first group in those files if there is something there that isn't a label.
## NCurses Keyboard Shortcuts ##
Some Keyboard Shortcuts have been implemented for testing to see how users like them. Just hope nobody pushes a key on accident and doesn't know which one it was or what it does. The current list of keyboard shortcuts include:
```
esc or arrow keys - ncurses menu
q - quit
c - toggle compact mode
h - toggle call history
z - toggle console payloads
a - toggle call alert beep
4 - force dmr privacy key assertion over fid and svc bits
i - toggle signal inversion on types that can't auto detect (dmr, dpmr)
m - toggle c4fm/qpsk 10/4 (everything but phase 2 signal)
M - toggle c4fm/qpsk 8/3 (phase 2 tdma control channel)
R - start capturing symbol capture bin (date/time name file)
r - stop capturing symbol capture bin
spacebar - replay last symbol capture bin (captures must be stopped first)
s - stop playing symbol capture bin or wav input file
P - start per call decoded wav files
p - stop per call decoded wav files
t - toggle trunking (needs either rtl input, or rigctl connection)
1 - Lockout Tuning/Playback of TG in Slot 1 or Conventional (Current Session Only)
2 - Lockout Tuning/Playback of TG in Slot 2 (Current Session Only)
0 - Toggle Audio Smoothing - May produce crackling if enabled on RTL/TCP or wav/bin files
w - Toggle Trunking/Playback White List (Allow A Groups Only) / Black List (Block B or DE groups only) Mode
g - Toggle Trunking Tuning to Group Calls (DMR T3, Con+, Cap+, P25)
u - Toggle Trunking Tuning to Private Calls (DMR T3, P25)
d - Toggle Trunking Tuning to Data Calls (DMR T3)
```

View File

@@ -1,131 +0,0 @@
## Notice
These should not be followed for the 'lite' branch
## How to clone and build this branch
### Ubuntu 22.04/20.04/LM20/Debian Bullseye or Newer:
Using the included download-and-install.sh should make for a simple and painless clone, build, and install on newer Debian/Ubuntu/Mint/Pi systems. Simply acquire or copy the script, and run it. Update: Ubuntu 22.04 and RPi Bullseye 64-bit has been tested working with the installer script and functions appropriately.
If you need all dependencies build and installed first (only on Debian/Ubuntu/Mint/Pi), run:
```
wget https://raw.githubusercontent.com/lwvmobile/dsd-fme/main/download-and-install.sh
chmod +x download-and-install.sh
./download-and-install.sh
```
If you have dependencies already installed (i.e. need a fresh clean install on a system with DSD-FME already or using system other than Debian/Ubuntu, etc), please run this instead:
```
wget https://raw.githubusercontent.com/lwvmobile/dsd-fme/main/download-and-install-nodeps.sh
chmod +x download-and-install-nodeps.sh
./download-and-install-nodeps.sh
```
### Ubuntu 18.04/LM19/Buster Note:
The above install.sh should now function on older system types. You can elect to manually follow the steps down below. Do NOT Manually build and install ITPP 4.3.1 on older systems, it is currently not wanting to build on Ubuntu 18.04 and Linux Mint 19. Install it from the repository instead.
## Manual Install
First, install dependency packages. This guide will assume you are using Debian/Ubuntu based distros. Check your package manager for equivalent packages if different.
```
sudo apt update
sudo apt install libpulse-dev pavucontrol libsndfile1-dev libfftw3-dev liblapack-dev socat libusb-1.0-0-dev libncurses5 libncurses5-dev rtl-sdr librtlsdr-dev libusb-1.0-0-dev cmake git wget make build-essential libitpp-dev libncursesw5-dev
```
## Headless
If running headless, swap out pavucontrol for pulsemixer, and also install pulseaudio as well. Attempting to install pavucontrol in a headless environment may attempt to install a minimal desktop environment. Note: Default behavior of pulseaudio in a headless environment may be to be muted, so check by opening pulsemixer and unmuting and routing audio appropriately.
```
sudo apt install libpulse-dev libsndfile1-dev libfftw3-dev liblapack-dev socat libusb-1.0-0-dev libncurses5 libncurses5-dev rtl-sdr librtlsdr-dev libusb-1.0-0-dev cmake git wget make build-essential libitpp-dev libncursesw5-dev pulsemixer pulseaudio
```
### Build and Install ITPP - ONLY IF NOT IN REPO!!
```
wget -O itpp-latest.tar.bz2 http://sourceforge.net/projects/itpp/files/latest/download?source=files
tar xjf itpp*
#if you can't cd into this folder, double check folder name first
cd itpp-4.3.1
mkdir build
cd build
cmake ..
make -j `nproc`
sudo make install
sudo ldconfig
cd ..
cd ..
```
MBELib is considered a requirement in this build. You must read this notice prior to continuing. [MBElib Patent Notice](https://github.com/lwvmobile/mbelib#readme "MBElib Patent Notice") This version of MBELib is 1.3.2 and prints to STDERR, using the stock 1.3.0 MBElib may cause problems with print alignments if paired with this version of DSD-FME, or cause future compatibility issues.
```
git clone https://github.com/lwvmobile/mbelib
cd mbelib
mkdir build
cd build
cmake ..
make -j `nproc`
sudo make install
sudo ldconfig
cd ..
cd ..
```
Note: Some environment/distro users (Cygwin, Arch, and others) may need to manually copy any libmbe files found in the build folder to the /usr/lib folder on root.
`sudo cp libmbe* /usr/lib`
Finish by running these steps to clone and build DSD-FME.
```
git clone https://github.com/lwvmobile/dsd-fme
cd dsd-fme
sudo cp tone8.wav /usr/share/
sudo cp tone24.wav /usr/share/
sudo cp tone48.wav /usr/share/
sudo chmod 777 /usr/share/tone8.wav
sudo chmod 777 /usr/share/tone24.wav
sudo chmod 777 /usr/share/tone48.wav
mkdir build
cd build
cmake ..
make -j `nproc`
sudo make install
sudo ldconfig
```
Optional 'Virtual Sinks' for routing audio from SDR++ or GQRX, Media Players, etc. into DSD-FME
You may wish to direct sound into DSD-FME via Virtual Sinks. You may set up a Virtual Sink or two on your machine for routing audio in and out of applications to other applications using the following command, and opening up pavucontrol "PulseAudio Volume Control" in the menu (or `pulsemixer` in headless mode) to change line out of application to virtual sink, and line in of DSD-FME to monitor of virtual sink. This command will not persist past a reboot, so you will need to invoke them each time you reboot, or search for how to add this to your conf files for persistency if desired.
```
pacmd load-module module-null-sink sink_name=virtual_sink sink_properties=device.description=Virtual_Sink
pacmd load-module module-null-sink sink_name=virtual_sink2 sink_properties=device.description=Virtual_Sink2
```
Already have this branch, and just want to pull the latest build? You can run the rebuild.sh file in the dsd-fme folder, or manually do the pull with the commands:
```
##Open your clone folder##
git pull
##cd into your build folder##
cd build
cmake ..
make -j `nproc`
sudo make install
sudo ldconfig
```
If the call alert wav files aren't playing, then make sure to run the following in the dsd-fme folder to copy the wav files to the /usr/share/ folder and give them adequate permission to be accessed.
```
sudo cp tone8.wav /usr/share/
sudo cp tone24.wav /usr/share/
sudo cp tone48.wav /usr/share/
sudo chmod 777 /usr/share/tone8.wav
sudo chmod 777 /usr/share/tone24.wav
sudo chmod 777 /usr/share/tone48.wav
```

View File

@@ -1,10 +0,0 @@
ChannelNumber(dec),frequency(Hz) (do not delete this line or won't import properly)
1,858606250
2,858606250
3,859606250
4,859606250
5,860606250
6,860606250
7,861606250
8,861606250
1 ChannelNumber(dec) frequency(Hz) (do not delete this line or won't import properly)
2 1 858606250
3 2 858606250
4 3 859606250
5 4 859606250
6 5 860606250
7 6 860606250
8 7 861606250
9 8 861606250

View File

@@ -1,19 +0,0 @@
ChannelNumber(dec),frequency(Hz) (do not delete this line or won't import properly)
999,862093750,default cc (come here first), optional use non-existent channel as first entry
1,863093750
2,862093750
3,861093750
4,860093750
5,859093750
6,863593750
7,862593750
8,861593750
9,860593750
10,859593750
11,863393750
12,862393750
13,861393750
14,860393750
15,859393750
1 ChannelNumber(dec),frequency(Hz) (do not delete this line or won't import properly)
2 999,862093750,default cc (come here first), optional use non-existent channel as first entry
3 1,863093750
4 2,862093750
5 3,861093750
6 4,860093750
7 5,859093750
8 6,863593750
9 7,862593750
10 8,861593750
11 9,860593750
12 10,859593750
13 11,863393750
14 12,862393750
15 13,861393750
16 14,860393750
17 15,859393750

View File

@@ -1,8 +0,0 @@
ChannelNumber(dec),frequency(Hz) (do not delete this line or won't import properly)
999,456318750,default cc (come here first), optional use non-existent channel as first entry
36,455756250
54,455981250
81,456318750
1 ChannelNumber(dec),frequency(Hz) (do not delete this line or won't import properly)
2 999,456318750,default cc (come here first), optional use non-existent channel as first entry
3 36,455756250
4 54,455981250
5 81,456318750

View File

@@ -1,6 +0,0 @@
ChannelNumber(dec),frequency(Hz) (do not delete this line or won't import properly)
1,851375000
2,851800000
3,855987500
4,858487500
5,852312500
1 ChannelNumber(dec) frequency(Hz) (do not delete this line or won't import properly)
2 1 851375000
3 2 851800000
4 3 855987500
5 4 858487500
6 5 852312500

View File

@@ -1,5 +0,0 @@
DEC,Mode(A- Allow, B - Block, DE - Digital Enc),Name of Group,Tag (do not delete this line or won't import properly)
100,B,Example Name,Tag
1449,A,Fire Dispatch,Fire
929,A,Fire Tac,Fire
22033,DE,Law Dispatch,Law
1 DEC,Mode(A- Allow, B - Block, DE - Digital Enc),Name of Group,Tag (do not delete this line or won't import properly)
2 100,B,Example Name,Tag
3 1449,A,Fire Dispatch,Fire
4 929,A,Fire Tac,Fire
5 22033,DE,Law Dispatch,Law

View File

@@ -1,40 +0,0 @@
#example trunking sh scripts (SDR++ and RTL Input) -T = trunking
#make sure to put a # in front of all lines except the one you wish to use
#P25 P1 FDMA CC with C4FM
#dsd-fme -i tcp -U 4532 -T -N 2> log.ans
#dsd-fme -i rtl:0:850M:26:-2:8:0:6020 -T -N 2> log.ans
#P25 P1 FDMA CC with QPSK (Simulcast)
#dsd-fme -i tcp:192.168.7.8:7355 -U 4532 -T -mq -N 2> log.ans
#dsd-fme -i rtl:0:855.625M:26:-2:12:0:6020 -T -mq -N 2> log.ans
#P25 P2 TDMA CC with QPSK (Simulcast)
#dsd-fme -i tcp:192.168.7.8:7355 -U 4532 -T -f2 -m2 -N 2> log.ans
#dsd-fme -i rtl:0:855.625M:26:-2:12:0:6020 -T -f2 -m2 -N 2> log.ans
#DMR TIII, Con+, Cap+
dsd-fme -fs -i tcp -U 4532 -T -C dmr_t3_chan.csv -G group.csv -N 2> log.ans
#dsd-fme -fs -i rtl:0:450M:26:-2:8:0:6020 -T -C connect_plus_chan.csv -G group.csv -N 2> log.ans
#EDACS/EDACS-EA Digital Only
#dsd-fme -fp -i tcp:192.168.7.5:7355 -U 4532 -T -C edacs_channel_map.csv -G group.csv -N 2> log.ans
#dsd-fme -fp -i rtl:0:850M:26:-2:24:0:6020 -T -C edacs_channel_map.csv -G group.csv -N 2> log.ans
#NXDN48 Trunking with Standard Band Plan (Channels 0-800)
#dsd-fme -fi -i tcp -T -U 4532 -N 2> log.ans
#dsd-fme -fi -i rtl:0:450M:26:-2:8:75:6020 -T -G group.csv -N 2> log.ans
#NXDN48 Trunking with Channel Map (Custom Channels > 800)
#dsd-fme -fi -i tcp -T -U 4532 -C channel_map.csv -N 2> log.ans
#dsd-fme -fi -i rtl:0:450M:26:-2:8:75:6020 -T -G group.csv -C channel_map.csv -N 2> log.ans
#Notes: parameters after -i tcp can be omitted if using localhost as the default hostname to connect
#and 7355 as the default port number. -U is the port number for RIGCTL and will mirror the tcp hostname
#running under the assumption that the user will be connnecting the VFO to the same instance of SDR++
#You can also specify an ip address to connect to a remote SDR++ instance, make sure that the settings
#inside of SDR++ match, i.e., change in SDR++ from 'localhost' to an IP to bind to (machine's IP address)
#Note2: RTL input should only be used on strong signal, the SDR++ VFO will perform much better on marginal signal
#Having a -G group.csv is purely optional, but useful if you want to block groups, or give groups names

View File

@@ -203,8 +203,10 @@ typedef struct
int playoffsetR; int playoffsetR;
char mbe_out_dir[1024]; char mbe_out_dir[1024];
char mbe_out_file[1024]; char mbe_out_file[1024];
char mbe_out_fileR[1024]; //second slot on a TDMA system
char mbe_out_path[2048]; //1024 char mbe_out_path[2048]; //1024
FILE *mbe_out_f; FILE *mbe_out_f;
FILE *mbe_out_fR; //second slot on a TDMA system
FILE *symbol_out_f; FILE *symbol_out_f;
float audio_gain; float audio_gain;
float audio_gainR; float audio_gainR;
@@ -218,6 +220,7 @@ typedef struct
char szNumbers[1024]; //**tera 10/32/64 char str char szNumbers[1024]; //**tera 10/32/64 char str
short int symbol_out; short int symbol_out;
short int mbe_out; //flag for mbe out, don't attempt fclose more than once short int mbe_out; //flag for mbe out, don't attempt fclose more than once
short int mbe_outR; //flag for mbe out, don't attempt fclose more than once
SNDFILE *wav_out_f; SNDFILE *wav_out_f;
SNDFILE *wav_out_fR; SNDFILE *wav_out_fR;
SNDFILE *wav_out_raw; SNDFILE *wav_out_raw;
@@ -328,6 +331,7 @@ typedef struct
char group_in_file[1024]; char group_in_file[1024];
char lcn_in_file[1024]; char lcn_in_file[1024];
char chan_in_file[1024]; char chan_in_file[1024];
char key_in_file[1024];
//end import filenames //end import filenames
//reverse mute //reverse mute
@@ -355,6 +359,10 @@ typedef struct
//OSS audio - slot preference //OSS audio - slot preference
uint8_t slot_preference; uint8_t slot_preference;
//'DSP' Format Output
uint8_t use_dsp_output;
char dsp_out_file[2048];
} dsd_opts; } dsd_opts;
typedef struct typedef struct
@@ -508,27 +516,32 @@ typedef struct
unsigned int dmr_fid; unsigned int dmr_fid;
unsigned int dmr_so; unsigned int dmr_so;
unsigned int dmr_flco;
unsigned int dmr_fidR; unsigned int dmr_fidR;
unsigned int dmr_soR; unsigned int dmr_soR;
unsigned int dmr_flcoR;
char slot1light[8]; char slot1light[8];
char slot2light[8]; char slot2light[8];
int directmode; int directmode;
int dmr_stereo_payload[144]; //load up 144 dibit buffer for every single DMR TDMA frame int dmr_stereo_payload[144]; //load up 144 dibit buffer for every single DMR TDMA frame
uint8_t data_header_blocks[2]; //collect number of blocks to follow from data header per slot int data_header_blocks[2]; //collect number of blocks to follow from data header per slot
int data_block_counter[2]; //counter for number of data blocks collected
uint8_t data_header_valid[2]; //flag for verifying the data header if still valid (in case of tact/burst fec errs)
uint8_t data_header_padding[2]; //collect number of padding octets in last block per slot uint8_t data_header_padding[2]; //collect number of padding octets in last block per slot
uint8_t data_header_format[2]; //collect format of data header (conf or unconf) per slot uint8_t data_header_format[2]; //collect format of data header (conf or unconf) per slot
uint8_t data_header_sap[2]; //collect sap info per slot uint8_t data_header_sap[2]; //collect sap info per slot
uint8_t data_block_counter[2]; //counter for number of data blocks collected
uint8_t data_p_head[2]; //flag for dmr proprietary header to follow uint8_t data_p_head[2]; //flag for dmr proprietary header to follow
//new stuff below here //new stuff below here
uint8_t data_conf_data[2]; //flag for confirmed data blocks per slot uint8_t data_conf_data[2]; //flag for confirmed data blocks per slot
uint8_t dmr_pdu_sf[2][288]; //unified pdu 'superframe' //[slot][byte] uint8_t dmr_pdu_sf[2][288]; //unified pdu 'superframe' //[slot][byte]
uint8_t cap_plus_csbk_bits[12*8*8]; //CSBK Cap+ FL initial and appended block bit storage
uint8_t cap_plus_block_num; //received block number storage
uint8_t data_block_crc_valid[2][25]; //flag each individual block as good crc on confirmed data uint8_t data_block_crc_valid[2][25]; //flag each individual block as good crc on confirmed data
char dmr_embedded_signalling[2][6][48]; //embedded signalling 2 slots by 6 vc by 48 bits (replacing TS1SuperFrame.TimeSlotRawVoiceFrame.Sync structure) char dmr_embedded_signalling[2][7][48]; //embedded signalling 2 slots by 6 vc by 48 bits (replacing TS1SuperFrame.TimeSlotRawVoiceFrame.Sync structure)
char dmr_cach_fragment[4][17]; //unsure of size, will need to check/verify char dmr_cach_fragment[4][17]; //unsure of size, will need to check/verify
int dmr_cach_counter; //counter for dmr_cach_fragments 0-3; not sure if needed yet. int dmr_cach_counter; //counter for dmr_cach_fragments 0-3; not sure if needed yet.
@@ -545,8 +558,9 @@ typedef struct
dPMRVoiceFS2Frame_t dPMRVoiceFS2Frame; dPMRVoiceFS2Frame_t dPMRVoiceFS2Frame;
unsigned char * dpmr_caller_id; char dpmr_caller_id[20];
unsigned char * dpmr_target_id; char dpmr_target_id[20];
int dpmr_color_code; int dpmr_color_code;
short int dmr_stereo; //need state variable for upsample function short int dmr_stereo; //need state variable for upsample function
@@ -571,6 +585,8 @@ typedef struct
unsigned long long int p2_wacn; unsigned long long int p2_wacn;
unsigned long long int p2_sysid; unsigned long long int p2_sysid;
unsigned long long int p2_cc; //p1 NAC unsigned long long int p2_cc; //p1 NAC
unsigned long long int p2_siteid;
unsigned long long int p2_rfssid;
int p2_hardset; //flag for checking whether or not P2 wacn and sysid are hard set by user int p2_hardset; //flag for checking whether or not P2 wacn and sysid are hard set by user
int p2_scramble_offset; //offset counter for scrambling application int p2_scramble_offset; //offset counter for scrambling application
int p2_vch_chan_num; //vch channel number (0 or 1, not the 0-11 TS) int p2_vch_chan_num; //vch channel number (0 or 1, not the 0-11 TS)
@@ -640,12 +656,15 @@ typedef struct
uint32_t nxdn_location_sys_code; uint32_t nxdn_location_sys_code;
uint16_t nxdn_location_site_code; uint16_t nxdn_location_site_code;
//multi-key array
unsigned long long int rkey_array[0xFFFF];
//dmr late entry mi //dmr late entry mi
uint64_t late_entry_mi_fragment[2][7][3]; uint64_t late_entry_mi_fragment[2][7][3];
//dmr manufacturer branding and sub_branding (i.e., Motorola and Con+) //dmr manufacturer branding and sub_branding (i.e., Motorola and Con+)
char dmr_branding[99]; char dmr_branding[20];
char dmr_branding_sub[99]; char dmr_branding_sub[80];
//Remus DMR End Call Alert Beep //Remus DMR End Call Alert Beep
int dmr_end_alert[2]; //dmr TLC end call alert beep has already played once flag int dmr_end_alert[2]; //dmr TLC end call alert beep has already played once flag
@@ -749,13 +768,16 @@ int get_dibit_and_analog_signal (dsd_opts * opts, dsd_state * state, int * out_a
void skipDibit (dsd_opts * opts, dsd_state * state, int count); void skipDibit (dsd_opts * opts, dsd_state * state, int count);
void saveImbe4400Data (dsd_opts * opts, dsd_state * state, char *imbe_d); void saveImbe4400Data (dsd_opts * opts, dsd_state * state, char *imbe_d);
void saveAmbe2450Data (dsd_opts * opts, dsd_state * state, char *ambe_d); void saveAmbe2450Data (dsd_opts * opts, dsd_state * state, char *ambe_d);
void saveAmbe2450DataR (dsd_opts * opts, dsd_state * state, char *ambe_d); //tdma slot 2
void PrintAMBEData (dsd_opts * opts, dsd_state * state, char *ambe_d); void PrintAMBEData (dsd_opts * opts, dsd_state * state, char *ambe_d);
void PrintIMBEData (dsd_opts * opts, dsd_state * state, char *imbe_d); void PrintIMBEData (dsd_opts * opts, dsd_state * state, char *imbe_d);
int readImbe4400Data (dsd_opts * opts, dsd_state * state, char *imbe_d); int readImbe4400Data (dsd_opts * opts, dsd_state * state, char *imbe_d);
int readAmbe2450Data (dsd_opts * opts, dsd_state * state, char *ambe_d); int readAmbe2450Data (dsd_opts * opts, dsd_state * state, char *ambe_d);
void openMbeInFile (dsd_opts * opts, dsd_state * state); void openMbeInFile (dsd_opts * opts, dsd_state * state);
void closeMbeOutFile (dsd_opts * opts, dsd_state * state); void closeMbeOutFile (dsd_opts * opts, dsd_state * state);
void closeMbeOutFileR (dsd_opts * opts, dsd_state * state); //tdma slot 2
void openMbeOutFile (dsd_opts * opts, dsd_state * state); void openMbeOutFile (dsd_opts * opts, dsd_state * state);
void openMbeOutFileR (dsd_opts * opts, dsd_state * state); //tdma slot 2
void openWavOutFile (dsd_opts * opts, dsd_state * state); void openWavOutFile (dsd_opts * opts, dsd_state * state);
void openWavOutFileL (dsd_opts * opts, dsd_state * state); void openWavOutFileL (dsd_opts * opts, dsd_state * state);
void openWavOutFileR (dsd_opts * opts, dsd_state * state); void openWavOutFileR (dsd_opts * opts, dsd_state * state);
@@ -868,7 +890,7 @@ int32_t GetdPmrColorCode(uint8_t ChannelCodeBit[24]);
void BPTCDeInterleaveDMRData(uint8_t * Input, uint8_t * Output); void BPTCDeInterleaveDMRData(uint8_t * Input, uint8_t * Output);
uint32_t BPTC_196x96_Extract_Data(uint8_t InputDeInteleavedData[196], uint8_t DMRDataExtracted[96], uint8_t R[3]); uint32_t BPTC_196x96_Extract_Data(uint8_t InputDeInteleavedData[196], uint8_t DMRDataExtracted[96], uint8_t R[3]);
uint32_t BPTC_128x77_Extract_Data(uint8_t InputDataMatrix[8][16], uint8_t DMRDataExtracted[77]); uint32_t BPTC_128x77_Extract_Data(uint8_t InputDataMatrix[8][16], uint8_t DMRDataExtracted[77]);
uint32_t BPTC_16x2_Extract_Data(uint8_t InputInterleavedData[32], uint8_t DMRDataExtracted[32]); uint32_t BPTC_16x2_Extract_Data(uint8_t InputInterleavedData[32], uint8_t DMRDataExtracted[32], uint32_t ParityCheckTypeOdd);
//Reed Solomon (12,9) functions //Reed Solomon (12,9) functions
void rs_12_9_calc_syndrome(rs_12_9_codeword_t *codeword, rs_12_9_poly_t *syndrome); void rs_12_9_calc_syndrome(rs_12_9_codeword_t *codeword, rs_12_9_poly_t *syndrome);
@@ -881,6 +903,8 @@ uint16_t ComputeCrcCCITT(uint8_t * DMRData);
uint16_t ComputeCrcCCITT16d(const uint8_t buf[], uint8_t len); uint16_t ComputeCrcCCITT16d(const uint8_t buf[], uint8_t len);
uint32_t ComputeAndCorrectFullLinkControlCrc(uint8_t * FullLinkControlDataBytes, uint32_t * CRCComputed, uint32_t CRCMask); uint32_t ComputeAndCorrectFullLinkControlCrc(uint8_t * FullLinkControlDataBytes, uint32_t * CRCComputed, uint32_t CRCMask);
uint8_t ComputeCrc5Bit(uint8_t * DMRData); uint8_t ComputeCrc5Bit(uint8_t * DMRData);
uint16_t ComputeCrc9Bit(uint8_t * DMRData, uint32_t NbData);
uint32_t ComputeCrc32Bit(uint8_t * DMRData, uint32_t NbData);
//new simplified dmr functions //new simplified dmr functions
void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196], uint8_t databurst); void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196], uint8_t databurst);
@@ -904,11 +928,12 @@ void dmrMSData (dsd_opts * opts, dsd_state * state);
void dmrMSBootstrap (dsd_opts * opts, dsd_state * state); void dmrMSBootstrap (dsd_opts * opts, dsd_state * state);
//dmr data header and multi block types (header, 1/2, 3/4, 1, Unified) //dmr data header and multi block types (header, 1/2, 3/4, 1, Unified)
void dmr_dheader (dsd_opts * opts, dsd_state * state, uint8_t dheader[], uint32_t CRCCorrect, uint32_t IrrecoverableErrors); void dmr_dheader (dsd_opts * opts, dsd_state * state, uint8_t dheader[], uint8_t dheader_bits[], uint32_t CRCCorrect, uint32_t IrrecoverableErrors);
void dmr_block_assembler (dsd_opts * opts, dsd_state * state, uint8_t block_bytes[], uint8_t block_len, uint8_t databurst, uint8_t type); void dmr_block_assembler (dsd_opts * opts, dsd_state * state, uint8_t block_bytes[], uint8_t block_len, uint8_t databurst, uint8_t type);
void dmr_pdu (dsd_opts * opts, dsd_state * state, uint8_t block_len, uint8_t DMR_PDU[]); void dmr_pdu (dsd_opts * opts, dsd_state * state, uint8_t block_len, uint8_t DMR_PDU[]);
void dmr_reset_blocks (dsd_opts * opts, dsd_state * state); void dmr_reset_blocks (dsd_opts * opts, dsd_state * state);
uint8_t dmr_lrrp (dsd_opts * opts, dsd_state * state, uint8_t block_len, uint8_t DMR_PDU[]); void dmr_lrrp (dsd_opts * opts, dsd_state * state, uint8_t block_len, uint8_t DMR_PDU[]);
void dmr_locn (dsd_opts * opts, dsd_state * state, uint8_t block_len, uint8_t DMR_PDU[]);
//dmr alg stuff //dmr alg stuff
void dmr_alg_reset (dsd_opts * opts, dsd_state * state); void dmr_alg_reset (dsd_opts * opts, dsd_state * state);
@@ -916,14 +941,19 @@ void dmr_alg_refresh (dsd_opts * opts, dsd_state * state);
void dmr_late_entry_mi_fragment (dsd_opts * opts, dsd_state * state, uint8_t vc, char ambe_fr[4][24], char ambe_fr2[4][24], char ambe_fr3[4][24]); void dmr_late_entry_mi_fragment (dsd_opts * opts, dsd_state * state, uint8_t vc, char ambe_fr[4][24], char ambe_fr2[4][24], char ambe_fr3[4][24]);
void dmr_late_entry_mi (dsd_opts * opts, dsd_state * state); void dmr_late_entry_mi (dsd_opts * opts, dsd_state * state);
//handle Single Burst (Voice Burst F) or Reverse Channel Signalling
void dmr_sbrc (dsd_opts * opts, dsd_state * state, uint8_t power);
//DMR FEC/CRC from Boatbod - OP25 //DMR FEC/CRC from Boatbod - OP25
bool Hamming17123(uint8_t* d); bool Hamming17123(uint8_t* d);
uint8_t crc8(uint8_t bits[], unsigned int len); uint8_t crc8(uint8_t bits[], unsigned int len);
bool crc8_ok(uint8_t bits[], unsigned int len); bool crc8_ok(uint8_t bits[], unsigned int len);
uint8_t crc7(uint8_t bits[], unsigned int len);
//LFSR code courtesy of https://github.com/mattames/LFSR/ //LFSR code courtesy of https://github.com/mattames/LFSR/
void LFSR(dsd_state * state); void LFSR(dsd_state * state);
void LFSRN (char * BufferIn, char * BufferOut, dsd_state * state); void LFSRN (char * BufferIn, char * BufferOut, dsd_state * state);
void LFSR64(dsd_state * state);
void Hamming_7_4_init(); void Hamming_7_4_init();
void Hamming_7_4_encode(unsigned char *origBits, unsigned char *encodedBits); void Hamming_7_4_encode(unsigned char *origBits, unsigned char *encodedBits);
@@ -1008,6 +1038,7 @@ unsigned long long int edacs_bch (unsigned long long int message);
int csvGroupImport(dsd_opts * opts, dsd_state * state); int csvGroupImport(dsd_opts * opts, dsd_state * state);
int csvLCNImport(dsd_opts * opts, dsd_state * state); int csvLCNImport(dsd_opts * opts, dsd_state * state);
int csvChanImport(dsd_opts * opts, dsd_state * state); int csvChanImport(dsd_opts * opts, dsd_state * state);
int csvKeyImport(dsd_opts * opts, dsd_state * state);
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@@ -1033,7 +1064,7 @@ bool CDMRTrellisDecode(const unsigned char* data, unsigned char* payload);
int ez_rs28_ess (int payload[96], int parity[168]); //ezpwd bridge for FME int ez_rs28_ess (int payload[96], int parity[168]); //ezpwd bridge for FME
int ez_rs28_facch (int payload[156], int parity[114]); //ezpwd bridge for FME int ez_rs28_facch (int payload[156], int parity[114]); //ezpwd bridge for FME
int ez_rs28_sacch (int payload[180], int parity[132]); //ezpwd bridge for FME int ez_rs28_sacch (int payload[180], int parity[132]); //ezpwd bridge for FME
unsigned long long int isch_lookup (unsigned long long int isch); //isch map lookup int isch_lookup (unsigned long long int isch); //isch map lookup
int bd_bridge (int payload[196], uint8_t decoded[12]); //bridge to Michael Ossmann Block De-interleaver and 1/2 rate trellis decoder int bd_bridge (int payload[196], uint8_t decoded[12]); //bridge to Michael Ossmann Block De-interleaver and 1/2 rate trellis decoder
int crc16_lb_bridge (int payload[190], int len); int crc16_lb_bridge (int payload[190], int len);
int crc12_xb_bridge (int payload[190], int len); int crc12_xb_bridge (int payload[190], int len);

View File

@@ -134,6 +134,13 @@ const uint8_t DeInterleaveReverseChannelBptc[32] =
24, 9, 26, 11, 28, 13, 30, 15 24, 9, 26, 11, 28, 13, 30, 15
}; };
const uint8_t DeInterleaveReverseChannelBptcPlacement[32] =
{
0, 16, 1, 17, 2, 18, 3, 19,
4, 20, 5, 21, 6, 22, 7, 23,
8, 24, 9, 25, 10, 26, 11, 27,
12, 28, 13, 29, 14, 30, 15, 31
};
/* Functions ----------------------------------------------------------------*/ /* Functions ----------------------------------------------------------------*/
@@ -192,18 +199,10 @@ uint32_t BPTC_196x96_Extract_Data(uint8_t InputDeInteleavedData[196], uint8_t DM
} }
} }
/* R(0) to R(2) may be used to transport some
* Restricted Access System (RAS) information,
* So save these three bytes before reset all of them
* See patent US 2013/0288643 A1 */
R[0] = DataMatrix[0][2]; /* Save R(0) */
R[1] = DataMatrix[0][1]; /* Save R(1) */
R[2] = DataMatrix[0][0]; /* Save R(2) */
/* Set to 0 R(0) to R(2) - See DMR standard chapter B1.1 BPTC (196,96) */ /* Set to 0 R(0) to R(2) - See DMR standard chapter B1.1 BPTC (196,96) */
DataMatrix[0][0] = 0; /* R(2) */ // DataMatrix[0][0] = 0; /* R(2) */
DataMatrix[0][1] = 0; /* R(1) */ // DataMatrix[0][1] = 0; /* R(1) */
DataMatrix[0][2] = 0; /* R(0) */ // DataMatrix[0][2] = 0; /* R(0) */
/* Init the Hamming (15,11,3) library /* Init the Hamming (15,11,3) library
* Not needed because it has already been done * Not needed because it has already been done
@@ -356,6 +355,14 @@ uint32_t BPTC_196x96_Extract_Data(uint8_t InputDeInteleavedData[196], uint8_t DM
} }
} }
/* R(0) to R(2) may be used to transport some
* Restricted Access System (RAS) information,
* So save these three bits after hamming correction
* See patent US 2013/0288643 A1 */
R[0] = DataMatrix[0][2]; /* Save R(0) */
R[1] = DataMatrix[0][1]; /* Save R(1) */
R[2] = DataMatrix[0][0]; /* Save R(2) */
/* Return the number of irrecoverable Hamming errors */ /* Return the number of irrecoverable Hamming errors */
return HammingIrrecoverableErrorNb; return HammingIrrecoverableErrorNb;
} /* End BPTC_196x96_Extract_Data() */ } /* End BPTC_196x96_Extract_Data() */
@@ -498,33 +505,38 @@ uint32_t BPTC_128x77_Extract_Data(uint8_t InputDataMatrix[8][16], uint8_t DMRDat
* DMRDataExtracted[11..15] = Hamming data * DMRDataExtracted[11..15] = Hamming data
* DMRDataExtracted[16..31] = 16 bits of odd parity (to be checked) * DMRDataExtracted[16..31] = 16 bits of odd parity (to be checked)
* *
* @param ParityCheckTypeOdd : 0 = Parity to check is even (used in Non-Reverse Channel Single Burst BPTC)
* 1 = Parity to check is odd (used in Reverse Channel Single Burst BPTC)
*
* @return 0 = All is OK * @return 0 = All is OK
* Other = Error - Irrecoverable Hamming parity check error number * Other = Error - Irrecoverable Hamming parity check error number
*/ */
uint32_t BPTC_16x2_Extract_Data(uint8_t InputInterleavedData[32], uint8_t DMRDataExtracted[32]) uint32_t BPTC_16x2_Extract_Data(uint8_t InputInterleavedData[32], uint8_t DMRDataExtracted[32], uint32_t ParityCheckTypeOdd)
{ {
uint32_t i; uint32_t i;
uint8_t DataMatrix[32]; uint8_t DataMatrix[32];
uint8_t LineUncorrected[16]; uint8_t LineUncorrected[16];
uint8_t LineCorrected[11]; uint8_t LineCorrected[11];
uint32_t HammingIrrecoverableErrorNb = 0; uint32_t HammingIrrecoverableErrorNb = 0;
uint32_t ParityCheckErrorNb = 0; uint32_t ParityCheckOddErrorNb = 0;
uint32_t ParityCheckEvenErrorNb = 0;
//TODO: make this so we can load either rc interleave, or single burst interleave
for(i = 0; i < 32; i++) for(i = 0; i < 32; i++)
{ {
DataMatrix[DeInterleaveReverseChannelBptc[i]] = InputInterleavedData[i] & 1; DataMatrix[DeInterleaveReverseChannelBptcPlacement[DeInterleaveReverseChannelBptc[i]]] = InputInterleavedData[i] & 1;
} }
/* Copy the entire input buffer to the output buffer */ /* Copy the entire input buffer to the output buffer */
for(i = 0; i < 32; i++) for(i = 0; i < 32; i++)
{ {
DMRDataExtracted[i] = DataMatrix[i]; DMRDataExtracted[i] = DataMatrix[i] & 1;
} }
/* Prepare the line to be corrected */ /* Prepare the line to be corrected */
for(i = 0; i < 16; i++) for(i = 0; i < 16; i++)
{ {
LineUncorrected[i] = DataMatrix[i]; LineUncorrected[i] = DataMatrix[i] & 1;
} }
/* Apply Hamming (16,11,4) code correction */ /* Apply Hamming (16,11,4) code correction */
@@ -536,7 +548,7 @@ uint32_t BPTC_16x2_Extract_Data(uint8_t InputInterleavedData[32], uint8_t DMRDat
/* Copy the corrected content to the output buffer */ /* Copy the corrected content to the output buffer */
for(i = 0; i < 11; i++) for(i = 0; i < 11; i++)
{ {
DMRDataExtracted[i] = LineCorrected[i]; DMRDataExtracted[i] = LineCorrected[i] & 1;
} }
/* Check Parity bits */ /* Check Parity bits */
@@ -544,14 +556,24 @@ uint32_t BPTC_16x2_Extract_Data(uint8_t InputInterleavedData[32], uint8_t DMRDat
{ {
/* Odd parity ==> If data = 1 then parity = 0 /* Odd parity ==> If data = 1 then parity = 0
* If data = 0 then parity = 1 */ * If data = 0 then parity = 1 */
if(DMRDataExtracted[i] == DMRDataExtracted[i + 16]) ParityCheckErrorNb++; if((DMRDataExtracted[i] & 1) == (DMRDataExtracted[i + 16] & 1)) ParityCheckOddErrorNb++;
if((DMRDataExtracted[i] & 1) != (DMRDataExtracted[i + 16] & 1)) ParityCheckEvenErrorNb++;
} }
//fprintf(stderr, "Hamming ERR=%u ; Parity ERR=%u", HammingIrrecoverableErrorNb, ParityCheckErrorNb); //fprintf(stderr, "Hamming ERR=%u ; Parity odd ERR=%u, Parity even ERR=%u, ", HammingIrrecoverableErrorNb, ParityCheckOddErrorNb, ParityCheckEvenErrorNb);
//fprintf(stderr, "Content =\n");
//for(i = 0; i < 32; i++)
//{
// fprintf(stderr, "%u", DMRDataExtracted[i] & 1);
// if((i == 15) || (i == 31)) fprintf(stderr, "\n");
// else fprintf(stderr, "-");
//}
/* Return the number of irrecoverable Hamming errors + /* Return the number of irrecoverable Hamming errors +
* the number of parity check error */ * the number of parity check error */
return (HammingIrrecoverableErrorNb + ParityCheckErrorNb); if(ParityCheckTypeOdd) return (HammingIrrecoverableErrorNb + ParityCheckOddErrorNb);
else return (HammingIrrecoverableErrorNb + ParityCheckEvenErrorNb);
} /* End BPTC_16x2_Extract_Data() */ } /* End BPTC_16x2_Extract_Data() */

View File

@@ -8,250 +8,362 @@
#include "dsd.h" #include "dsd.h"
void dmr_dheader (dsd_opts * opts, dsd_state * state, uint8_t dheader[], uint32_t CRCCorrect, uint32_t IrrecoverableErrors) //hopefully a more simplified (or logical) version...once you get past all the variables
void dmr_dheader (dsd_opts * opts, dsd_state * state, uint8_t dheader[], uint8_t dheader_bits[], uint32_t CRCCorrect, uint32_t IrrecoverableErrors)
{ {
uint32_t i, j, k; uint32_t i, j, k;
uint8_t slot = state->currentslot; uint8_t slot = state->currentslot;
//clear out unified pdu 'superframe' slot //clear out unified pdu 'superframe' slot
for (short int i = 0; i < 288; i++) for (short int i = 0; i < 288; i++) state->dmr_pdu_sf[slot][i] = 0;
{
state->dmr_pdu_sf[slot][i] = 0;
}
//TODO: ONLY RUN ON GOOD CRC? //reset block counter to 1
state->data_block_counter[slot] = 1;
//collect relevant data header info, figure out format, and grab appropriate info from it if (IrrecoverableErrors == 0 && CRCCorrect == 1) //&&CRCCorrect == 1
if (state->data_p_head[slot] == 0)
{ {
uint8_t gi = dheader_bits[0]; //group or individual data
uint8_t a = dheader_bits[1]; //response requested flag
uint8_t ab = (uint8_t)ConvertBitIntoBytes(&dheader_bits[2], 2); //appended blocks
uint8_t dpf = (uint8_t)ConvertBitIntoBytes(&dheader_bits[4], 4); //data packet format
uint8_t sap = (uint8_t)ConvertBitIntoBytes(&dheader_bits[8], 4); //service access point
uint8_t poc = (uint8_t)ConvertBitIntoBytes(&dheader_bits[8], 4); //padding octets
uint32_t target = (uint32_t)ConvertBitIntoBytes(&dheader_bits[16], 24); //destination llid
uint32_t source = (uint32_t)ConvertBitIntoBytes(&dheader_bits[40], 24); //source llid
//store source for dmr pdu packet handling (lrrp) when not available in completed message
if (dpf != 15) state->dmr_lrrp_source[slot] = source;
//set dpf to storage for later use (UDT, SD, etc)
state->data_header_format[slot] = dpf;
//Type Strings
char sap_string[20];
char mfid_string[20];
char udtf_string[20];
char sddd_string[20];
sprintf (sap_string, "%s", "");
sprintf (mfid_string, "%s", "");
sprintf (udtf_string, "%s", "");
sprintf (sddd_string, "%s", "");
//see 9.3 - ETSI TS 102 361-1 V2.5.1 (2017-10) for more info
uint8_t f = dheader_bits[64]; //F -- Full message flag (F)
uint8_t bf = (uint8_t)ConvertBitIntoBytes(&dheader_bits[65], 7); //Blocks to Follow (BF)
//confirmed data header
uint8_t s = dheader_bits[72]; //S -- Re-Synchronize Flag
uint8_t ns = (uint8_t)ConvertBitIntoBytes(&dheader_bits[73], 3); //N(S) -- send sequence number
uint8_t fsn = (uint8_t)ConvertBitIntoBytes(&dheader_bits[76], 4); //Fragment Sequence Number (FSN)
//response header
uint8_t r_class = (uint8_t)ConvertBitIntoBytes(&dheader_bits[72], 2);
uint8_t r_type = (uint8_t)ConvertBitIntoBytes(&dheader_bits[74], 3);
uint8_t r_status = (uint8_t)ConvertBitIntoBytes(&dheader_bits[77], 3);
//short data - status/precoded
uint8_t s_ab_msb = (uint8_t)ConvertBitIntoBytes(&dheader_bits[2], 2); //appended block, msb
uint8_t s_ab_lsb = (uint8_t)ConvertBitIntoBytes(&dheader_bits[12], 4);//appended block, lsb
uint8_t s_ab_fin = (s_ab_msb << 2) | s_ab_lsb; //appended blocks, final value
uint8_t s_source_port = (uint8_t)ConvertBitIntoBytes(&dheader_bits[64], 3);
uint8_t s_dest_port = (uint8_t)ConvertBitIntoBytes(&dheader_bits[67], 3);
uint8_t s_status_precoded = (uint8_t)ConvertBitIntoBytes(&dheader_bits[70], 10);
//short data - raw
uint8_t sd_sarq = dheader_bits[70]; //Selective Automatic Repeat reQuest
uint8_t sd_f = dheader_bits[71]; //full message flag
uint8_t sd_bp = (uint8_t)ConvertBitIntoBytes(&dheader_bits[72], 8); //bit padding
//short data - defined
uint8_t dd_format = (uint8_t)ConvertBitIntoBytes(&dheader_bits[64], 6);
//Unified Data Transport (UDT)
uint8_t udt_format = (uint8_t)ConvertBitIntoBytes(&dheader_bits[12], 4);
uint8_t udt_padnib = (uint8_t)ConvertBitIntoBytes(&dheader_bits[64], 5);
uint8_t udt_uab = (uint8_t)ConvertBitIntoBytes(&dheader_bits[70], 2); //udt appended blocks
uint8_t udt_sf = dheader_bits[72];
uint8_t udt_pf = dheader_bits[73];
uint8_t udt_op = (uint8_t)ConvertBitIntoBytes(&dheader_bits[74], 6);
//p_head
uint8_t p_sap = (uint8_t)ConvertBitIntoBytes(&dheader_bits[0], 4);
uint8_t p_mfid = (uint8_t)ConvertBitIntoBytes(&dheader_bits[8], 8);
uint8_t p_pot = (uint8_t)ConvertBitIntoBytes(&dheader_bits[3], 5); //looking for LRRP pot_report
fprintf (stderr, "%s ", KGRN); fprintf (stderr, "%s ", KGRN);
state->data_block_counter[slot] = 1; //reset block counter to 1 fprintf (stderr, "\n");
state->data_header_format[slot] = dheader[0]; //collect the entire byte, we can check group or individual, response requested as well on this fprintf (stderr, " Slot %d Data Header - ", slot+1);
state->data_header_sap[slot] = (dheader[1] & 0xF0) >> 4;
if ( (state->data_header_format[slot] & 0xF) == 0x2) if (gi == 1 && dpf != 15) fprintf(stderr, "GROUP - ");
if (gi == 0 && dpf != 15) fprintf(stderr, "INDIV - ");
if (dpf == 0) fprintf (stderr, "Unified Data Transport (UDT) ");
else if (dpf == 1) fprintf (stderr, "Response Packet ");
else if (dpf == 2) fprintf (stderr, "Unconfirmed Delivery ");
else if (dpf == 3) fprintf (stderr, "Confirmed Delivery ");
else if (dpf == 13) fprintf (stderr, "Short Data: Defined ");
else if (dpf == 14) fprintf (stderr, "Short Data: Raw or S/P ");
else if (dpf == 15) fprintf (stderr, "Proprietary Packet Data");
else fprintf (stderr, "Reserved/Unknown DPF %X ", dpf);
if (a == 1 && dpf != 15) fprintf(stderr, "- Response Requested ");
if (dpf != 15) fprintf (stderr, "- Source: %d Target: %d ", source, target);
//sap string handling
if (dpf == 15) sap = p_sap;
if (sap == 0) sprintf (sap_string, "%s", "UDT Data"); //apparently, both dpf and sap for UDT is 0
else if (sap == 2) sprintf (sap_string, "%s", "TCP Comp"); //TCP/IP header compression
else if (sap == 3) sprintf (sap_string, "%s", "UDP Comp"); //UDP/IP header compression
else if (sap == 4) sprintf (sap_string, "%s", "IP Based"); //IP based Packet Data
else if (sap == 5) sprintf (sap_string, "%s", "ARP Prot"); //Address Resoution Protocol (ARP)
else if (sap == 9) sprintf (sap_string, "%s", "Prop PDU"); //Proprietary Packet Data
else if (sap == 10) sprintf (sap_string, "%s", "Short DT"); //Short Data
else sprintf (sap_string, "%s", "Reserved"); //reserved, or err/unk
//mfid string handling
if (dpf == 15)
{ {
state->data_conf_data[slot] = 0; //flag as unconfirmed data, no need for additional CRC/Serial checks if (p_mfid == 0x10) sprintf (mfid_string, "%s", "Motorola");
state->data_header_padding[slot] = dheader[1] & 0xF; //number of padding octets on last block else if (p_mfid == 0x58) sprintf (mfid_string, "%s", "Tait ");
state->data_header_blocks[slot] = dheader[8] & 0x7F; //number of blocks to follow, most useful for when to poll the super array for data else if (p_mfid == 0x68) sprintf (mfid_string, "%s", "Hytera ");
fprintf (stderr, "\n Unconfirmed Data Header: DPF %01X - SAP %02X - Block Count %02X - Padding Octets %02X", else if (p_mfid == 0x08) sprintf (mfid_string, "%s", "Hytera ");
state->data_header_format[slot] & 0xF, state->data_header_sap[slot], else if (p_mfid == 0x06) sprintf (mfid_string, "%s", "Trid/Mot");
state->data_header_blocks[slot], state->data_header_padding[slot] ); else if (p_mfid == 0x00) sprintf (mfid_string, "%s", "Standard");
else sprintf (mfid_string, "%s", "Other ");
} }
if ( (state->data_header_format[slot] & 0xF) == 0x3) //udt format string handling
if (dpf == 0)
{ {
state->data_conf_data[slot] = 1; //set flag to indicate the following blocks are confirmed data so we know to run additional CRC etc on it. if (udt_format == 0x00) sprintf (udtf_string, "%s", "Binary");
state->data_header_padding[slot] = dheader[1] & 0xF; //number of padding octets on last block else if (udt_format == 0x01) sprintf (udtf_string, "%s", "MS/TG Adr");
state->data_header_blocks[slot] = dheader[8] & 0x7F; //number of blocks to follow, most useful for when to poll the super array for data else if (udt_format == 0x02) sprintf (udtf_string, "%s", "4-bit BCD");
fprintf (stderr, "\n Confirmed Data Header: DPF %01X - SAP %02X - Block Count %02X - Padding Octets %02X", else if (udt_format == 0x03) sprintf (udtf_string, "%s", "ISO7 Char");
state->data_header_format[slot] & 0xF, state->data_header_sap[slot], else if (udt_format == 0x04) sprintf (udtf_string, "%s", "ISO8 Char");
state->data_header_blocks[slot], state->data_header_padding[slot] ); else if (udt_format == 0x05) sprintf (udtf_string, "%s", "NMEA LOCN");
else if (udt_format == 0x06) sprintf (udtf_string, "%s", "IP Addr");
else if (udt_format == 0x07) sprintf (udtf_string, "%s", "UTF-16"); //16-bit Unicode Chars
else if (udt_format == 0x08) sprintf (udtf_string, "%s", "Manu Spec"); //Manufacturer Specific
else if (udt_format == 0x09) sprintf (udtf_string, "%s", "Manu Spec"); //Manufacturer Specific
else if (udt_format == 0x0A) sprintf (udtf_string, "%s", "Mixed UTF"); //Appended block contains addr and 16-bit UTF-16BE
else sprintf (udtf_string, "%s", "Reserved");
} }
if ( (state->data_header_format[slot] & 0xF) == 0xD) //DD_HEAD //short data dd_head format string
if (dpf == 13)
{ {
if (dd_format == 0x00) sprintf (sddd_string, "%s", "Binary");
else if (dd_format == 0x01) sprintf (sddd_string, "%s", "BCD ");
else if (dd_format == 0x02) sprintf (sddd_string, "%s", "7-bit Char");
else if (dd_format == 0x03) sprintf (sddd_string, "%s", "IEC 8859-1");
else if (dd_format == 0x04) sprintf (sddd_string, "%s", "IEC 8859-2");
else if (dd_format == 0x05) sprintf (sddd_string, "%s", "IEC 8859-3");
else if (dd_format == 0x06) sprintf (sddd_string, "%s", "IEC 8859-4");
else if (dd_format == 0x07) sprintf (sddd_string, "%s", "IEC 8859-5");
else if (dd_format == 0x08) sprintf (sddd_string, "%s", "IEC 8859-6");
else if (dd_format == 0x09) sprintf (sddd_string, "%s", "IEC 8859-7");
else if (dd_format == 0x0A) sprintf (sddd_string, "%s", "IEC 8859-8");
else if (dd_format == 0x0B) sprintf (sddd_string, "%s", "IEC 8859-9");
else if (dd_format == 0x0C) sprintf (sddd_string, "%s", "IEC 8859-10");
else if (dd_format == 0x0D) sprintf (sddd_string, "%s", "IEC 8859-11");
else if (dd_format == 0x0E) sprintf (sddd_string, "%s", "IEC 8859-13"); //there is no 8059-12
else if (dd_format == 0x0F) sprintf (sddd_string, "%s", "IEC 8859-14");
else if (dd_format == 0x10) sprintf (sddd_string, "%s", "IEC 8859-15");
else if (dd_format == 0x11) sprintf (sddd_string, "%s", "IEC 8859-16");
else if (dd_format == 0x12) sprintf (sddd_string, "%s", "UTF-8 ");
else if (dd_format == 0x13) sprintf (sddd_string, "%s", "UTF-16 ");
else if (dd_format == 0x14) sprintf (sddd_string, "%s", "UTF-16BE");
else if (dd_format == 0x15) sprintf (sddd_string, "%s", "UTF-16LE");
else if (dd_format == 0x16) sprintf (sddd_string, "%s", "UTF-32 ");
else if (dd_format == 0x17) sprintf (sddd_string, "%s", "UTF-32BE");
else if (dd_format == 0x18) sprintf (sddd_string, "%s", "UTF-32LE");
else sprintf (sddd_string, "%s", "Reserved");
}
if (dpf == 0) //UDT
{
//UDT packet info -- samples needed for testing
//NOTE: This format's completed message has a CRC16 - like MBC - but has number of blocks (appended blocks) like R 1/2, etc.
fprintf (stderr, "\n SAP %02X [%s] - FMT %d [%s] - PDn %d - BLOCKS %d SF %d - PF %d OP %02X", sap, sap_string, udt_format, udtf_string, udt_padnib, udt_uab, udt_sf, udt_pf, udt_op);
//set number of blocks to follow (appended blocks) for block assembler
state->data_header_blocks[slot] = udt_uab;
//set data header to valid
state->data_header_valid[slot] = 1;
//send to assembler as type 3, rearrange into CSBK type PDU (to verify), and send to dmr_cspdu
dmr_block_assembler (opts, state, dheader, 12, 0x0B, 3);
}
if (dpf == 1) //response data packet header
{
//mostly fleshed out response packet info
fprintf (stderr, "\n SAP %02X [%s] - Class %d - Type %0d - ", sap, sap_string, r_class, r_type);
if (r_class == 0 && r_type == 1) fprintf (stderr, "ACK - Success");
if (r_class == 1)
{
fprintf (stderr, "NACK - ");
if (r_type == 0) fprintf (stderr, "Illegal Format");
if (r_type == 1) fprintf (stderr, "Illegal Format");
if (r_type == 2) fprintf (stderr, "Packet CRC ERR");
if (r_type == 3) fprintf (stderr, "Memory Full");
if (r_type == 4) fprintf (stderr, "FSN Out of Seq");
if (r_type == 5) fprintf (stderr, "Undeliverable");
if (r_type == 6) fprintf (stderr, "PKT Out of Seq");
if (r_type == 7) fprintf (stderr, "Invalid User");
}
if (r_class == 2) fprintf (stderr, "SACK - Retry");
if (r_status) fprintf (stderr, " - %d", r_status); //the object/value of the ack/nack/sack
}
//Confirmed or Unconfirmed Data Packets Header
if (dpf == 2 || dpf == 3)
{
if (dpf == 2) fprintf (stderr, "\n SAP %02X [%s] - FMF %d - BLOCKS %02d - PAD %02d - FSN %d", sap, sap_string, f, bf, poc, fsn);
if (dpf == 3) fprintf (stderr, "\n SAP %02X [%s] - FMF %d - BLOCKS %02d - PAD %02d - S %d - NS %d - FSN %d", sap, sap_string, f, bf, poc, s, ns, fsn);
state->data_header_blocks[slot] = bf;
if (dpf == 3) state->data_conf_data[slot] = 1; //set confirmed data delivery flag for additional CRC checks, block assembly, etc.
}
//Short Data DD_Head (13), and R_Head or SP_Head (14)
if (dpf == 13 || dpf == 14)
{
//only set if not all zeroes
if (s_ab_fin) state->data_header_blocks[slot] = s_ab_fin;
//Short Data: Defined
if (dpf == 13) fprintf (stderr, "\n SD:D [DD_HEAD] - SAP %02d [%s] - BLOCKS %02d - DD %02X - PADb %d - FMT %02X [%s]", sap, sap_string, s_ab_fin, dd_format, sd_bp, dd_format, sddd_string);
//Short Data: Raw or S/P
if (dpf == 14)
{
//S/P has all appended block bits set to zero -- any other way to tell difference?
if (s_ab_fin == 0) fprintf (stderr, "\n SD:S/P [SP_HEAD] - SAP %02d [%s] - SP %02d - DP %02d - S/P %02X", sap, sap_string, s_source_port, s_dest_port, s_status_precoded);
//Raw
else fprintf (stderr, "\n SD:RAW [R_HEAD] - SAP %02d [%s] - BLOCKS %02d - SP %02d - DP %02d - SARQ %d - FMF %d - PDb %d", sap, sap_string, s_ab_fin, s_source_port, s_dest_port, sd_sarq, sd_f, sd_bp);
}
//6.2.2 The Response Requested (A) information element of the header shall be set to 0
//for unconfirmed data and shall be set to 1 for confirmed data. DD_HEAD, R_HEAD, or SP_HEAD (double check)
if (a == 1)
{
state->data_conf_data[slot] = 1;
fprintf (stderr, " - Confirmed Data");
}
}
//Proprietary Data Header
if (dpf == 15)
{
fprintf (stderr, " - P_SAP %02d [%s] - MFID %02X [%s]", p_sap, sap_string, p_mfid, mfid_string);
//look for LRRP potential report 0x1F (may be others as well)
//this could just be a sap == 1, which is 'reserved', unsure (or maybe no actual correlation?)
if (p_sap != 1) state->data_header_blocks[slot]--; //decrement the blocks to follow count in order to pass CRC32 and properly assemble blocks
else //add block to start of the dmr_pdu_sf since it probably contains vital LRRP data (0x1F report) -- won't pass CRC32 either way
{
int blocks = state->data_header_blocks[slot]-1;
if (blocks < 1) blocks = 4; //safety value
if (blocks > 9) blocks = 9;
for(i = 0; i < 12; i++) state->dmr_pdu_sf[slot][i+(blocks*12)] = dheader[i];
state->data_block_counter[slot]++;
//no matter how you assemble this, with or without the p_head block(s), there is ALWAYS a CRC32 Failure
//even when it continues to pass on other SAP values, SAP 1 must have a different checksum?
//Users trying to get this will want to enable -F to bypass the CRC32 failure
//a recent discovery on a few systems and samples show the existence of multiple Prop Head Packets (how does that work)
}
}
//block storage sanity
if (state->data_header_blocks[slot] > 9) state->data_header_blocks[slot] = 9;
//assuming we didn't receive the initial data header block on a p_head and then decremented it
//3 or 4 seems to be the average safe value
if (state->data_header_blocks[slot] < 1) state->data_header_blocks[slot] = 4;
//set data header validity unless its a p_head (should be set prior, if received)
if (dpf != 15) state->data_header_valid[slot] = 1;
//REMUS! Uncomment these lines if desired
if (dpf != 15 && dpf != 1)
{
sprintf (state->dmr_lrrp_gps[slot], "Data Call - %s SRC [%d] DST [%d] ", sap_string, source, target);
if (a == 1) strcat (state->dmr_lrrp_gps[slot], "- RSP REQ ");
}
//REMUS! Uncomment these lines if desired -- if the data request data header is missing, though, this may keep accumulating
// if (dpf == 1)
// {
// strcat (state->dmr_lrrp_gps[slot], "- RSP ");
// if (r_class == 0) strcat (state->dmr_lrrp_gps[slot], "ACK - RX OK");
// if (r_class == 1) strcat (state->dmr_lrrp_gps[slot], "NACK - RX ERR");
// if (r_class == 2) strcat (state->dmr_lrrp_gps[slot], "SACK - RETRY");
// }
//End REMUS Data string
//store SAP value
state->data_header_sap[slot] = sap;
} //End Irrecoverable Errors
if (IrrecoverableErrors != 0)
{
state->data_header_valid[slot] = 0;
sprintf (state->dmr_lrrp_gps[slot], "%s", "");
state->data_p_head[slot] = 0;
state->data_conf_data[slot] = 0; state->data_conf_data[slot] = 0;
state->data_header_padding[slot] = dheader[7] & 0xF; state->data_block_counter[slot] = 1;
state->data_header_blocks[slot] = ( (dheader[0] & 0x30) | ((dheader[1] & 0xF) >> 0) ); //what a pain MSB | LSB state->data_header_blocks[slot] = 1;
fprintf (stderr, "\n Short Data - Defined: DPF %01X - SAP %02X - Appended Blocks %02X - Padding Bits %02X",
state->data_header_format[slot] & 0xF, state->data_header_sap[slot],
state->data_header_blocks[slot], state->data_header_padding[slot] );
}
if ( (state->data_header_format[slot] & 0xF) == 0xE) //SP_HEAD or R_HEAD
{
state->data_conf_data[slot] = 0;
state->data_header_padding[slot] = dheader[7] & 0xF;
state->data_header_blocks[slot] = ( (dheader[0] & 0x30) | ((dheader[1] & 0xF) >> 0) );
fprintf (stderr, "\n Short Data - Raw or Precoded: DPF %01X - SAP %02X - Appended Blocks %02X - Padding Bits %02X",
state->data_header_format[slot] & 0xF, state->data_header_sap[slot],
state->data_header_blocks[slot], state->data_header_padding[slot] );
}
}
//do we still need this? since we have ample PDU storage
if (state->data_header_blocks[slot] > 7)
{
state->data_header_blocks[slot] = 7;
} }
fprintf (stderr, "%s", KNRM); fprintf (stderr, "%s", KNRM);
//end collecting data header info
fprintf (stderr, "%s ", KYEL);
if (state->data_header_sap[slot] == 0x4 && state->data_p_head[slot] == 0)
{
fprintf (stderr, "\n IP Data - Source: ");
fprintf (stderr, "[%d]", (dheader[5] <<16 ) + (dheader[6] << 8) + dheader[7] );
fprintf (stderr, " Destination: ");
fprintf (stderr, "[%d]", (dheader[2] <<16 ) + (dheader[3] <<8 ) + dheader[4] );
state->dmr_lrrp_source[slot] = (dheader[5] <<16 ) + (dheader[6] << 8) + dheader[7];
//Remus! Uncomment these line
// if ( (state->data_header_format[slot] & 0xF ) != 0x1 && state->data_p_head[slot] == 0)
// sprintf (state->dmr_lrrp_gps[slot], "IP DATA SRC [%d] DST [%d] ", (dheader[5] <<16 ) + (dheader[6] << 8) + dheader[7], (dheader[2] <<16 ) + (dheader[3] <<8 ) + dheader[4]);
} }
if (state->data_header_sap[slot] == 0x0 && state->data_p_head[slot] == 0) //convert UDT to a CSBK friendly PDU format
void dmr_udt_cspdu_converter (dsd_opts * opts, dsd_state * state, uint8_t block_bytes[], uint8_t block_bits[], uint32_t CRCCorrect, uint32_t IrrecoverableErrors)
{ {
fprintf (stderr, "\n Unified Data Transport - Source: "); int i, j;
fprintf (stderr, "[%d]", (dheader[5] <<16 ) + (dheader[6] << 8) + dheader[7] );
fprintf (stderr, " Destination: ");
fprintf (stderr, "[%d]", (dheader[2] <<16 ) + (dheader[3] <<8 ) + dheader[4] );
state->dmr_lrrp_source[slot] = (dheader[5] <<16 ) + (dheader[6] << 8) + dheader[7]; //rearrange UDT data to a CSBK message format
uint8_t cs_byte[48]; //12 x 4, 2 bit AB should mean only 3 total appended blocks, so 4 all together (minus rearrangement)
memset (cs_byte, 0, sizeof (cs_byte));
uint8_t cs_bits[48*8];
memset (cs_bits, 0, sizeof (cs_bits));
//Remus! Uncomment these line cs_byte[0] = (uint8_t)ConvertBitIntoBytes(&block_bits[73], 7); //lb, pf and opcode byte
// if ( (state->data_header_format[slot] & 0xF ) != 0x1 && state->data_p_head[slot] == 0) uint8_t udt_opcode = (uint8_t)ConvertBitIntoBytes(&block_bits[74], 6); //for observation testing
// sprintf (state->dmr_lrrp_gps[slot], "UDT SRC [%d] DST [%d] ", (dheader[5] <<16 ) + (dheader[6] << 8) + dheader[7], (dheader[2] <<16 ) + (dheader[3] <<8 ) + dheader[4]); cs_byte[1] = 0; //set mfid to zero for now (may use custom value if needed later)
uint8_t udt_mfid = 0; //setting to zero
//should be 34 total (maximum) after removing tailing CRC16 (initial and last block)
for (i = 0; i < 34; i++) cs_byte[2+i] = block_bytes[12+i];
//bytes to bits
for(i = 0, j = 0; i < 36; i++, j+=8) //4 blocks max?
{
cs_bits[j + 0] = (cs_byte[i] >> 7) & 0x01;
cs_bits[j + 1] = (cs_byte[i] >> 6) & 0x01;
cs_bits[j + 2] = (cs_byte[i] >> 5) & 0x01;
cs_bits[j + 3] = (cs_byte[i] >> 4) & 0x01;
cs_bits[j + 4] = (cs_byte[i] >> 3) & 0x01;
cs_bits[j + 5] = (cs_byte[i] >> 2) & 0x01;
cs_bits[j + 6] = (cs_byte[i] >> 1) & 0x01;
cs_bits[j + 7] = (cs_byte[i] >> 0) & 0x01;
} }
if (state->data_header_sap[slot] == 0x9 && state->data_p_head[slot] == 0) dmr_cspdu (opts, state, cs_bits, cs_byte, CRCCorrect, IrrecoverableErrors);
{
fprintf (stderr, "\n Proprietary Packet Data - Source: ");
fprintf (stderr, "[%d]", (dheader[5] <<16 ) + (dheader[6] << 8) + dheader[7] );
fprintf (stderr, " Destination: ");
fprintf (stderr, "[%d]", (dheader[2] <<16 ) + (dheader[3] <<8 ) + dheader[4] );
state->dmr_lrrp_source[slot] = (dheader[5] <<16 ) + (dheader[6] << 8) + dheader[7];
//Remus! Uncomment this line
// sprintf (state->dmr_lrrp_gps[slot], "P_HEAD SRC [%d] DST [%d] ", (dheader[5] <<16 ) + (dheader[6] << 8) + dheader[7], (dheader[2] <<16 ) + (dheader[3] <<8 ) + dheader[4]);
}
if (state->data_header_sap[slot] == 0x2 && state->data_p_head[slot] == 0)
{
fprintf (stderr, "\n TCP/IP Header Compression Data - Source: ");
fprintf (stderr, "[%d]", dheader[3]);
fprintf (stderr, " Destination: ");
fprintf (stderr, "[%d]", dheader[2]);
state->dmr_lrrp_source[slot] = dheader[3];
//Remus! Uncomment these line
// if ( (state->data_header_format[slot] & 0xF ) != 0x1 && state->data_p_head[slot] == 0)
// sprintf (state->dmr_lrrp_gps[slot], "IPC SRC [%d] DST [%d] ", dheader[3], dheader[2]);
}
if (state->data_header_sap[slot] == 0x3 && state->data_p_head[slot] == 0)
{
fprintf (stderr, "\n UDP/IP Header Compression Data - Source: ");
fprintf (stderr, "[%d]", dheader[3]);
fprintf (stderr, " Destination: ");
fprintf (stderr, "[%d]", dheader[2]);
state->dmr_lrrp_source[slot] = dheader[3];
//Remus! Uncomment these line
// if ( (state->data_header_format[slot] & 0xF ) != 0x1 && state->data_p_head[slot] == 0)
// sprintf (state->dmr_lrrp_gps[slot], "UDP SRC [%d] DST [%d] ", dheader[3], dheader[2]);
}
if (state->data_header_sap[slot] == 0x5 && state->data_p_head[slot] == 0)
{
fprintf (stderr, "\n ARP - Address Resolution Protocol ");
}
if ( (state->data_header_format[slot] & 0xF ) == 0xD && state->data_p_head[slot] == 0)
{
fprintf (stderr, "\n Short Data - Defined - Source: ");
fprintf (stderr, "[%d]", (dheader[5] <<16 ) + (dheader[6] << 8) + dheader[7] );
fprintf (stderr, " Destination: ");
fprintf (stderr, "[%d]", (dheader[2] <<16 ) + (dheader[3] <<8 ) + dheader[4] );
//Remus! Uncomment this line
// sprintf (state->dmr_lrrp_gps[slot], "SD-D SRC [%d] DST [%d] ", (dheader[5] <<16 ) + (dheader[6] << 8) + dheader[7], (dheader[2] <<16 ) + (dheader[3] <<8 ) + dheader[4]);
}
if ( (state->data_header_format[slot] & 0xF) == 0xE && state->data_p_head[slot] == 0)
{
fprintf (stderr, "\n Short Data - Raw or Status/Precoded - Source: ");
fprintf (stderr, "[%d]", (dheader[5] <<16 ) + (dheader[6] << 8) + dheader[7] );
fprintf (stderr, " Destination: ");
fprintf (stderr, "[%d]", (dheader[2] <<16 ) + (dheader[3] <<8 ) + dheader[4] );
//Remus! Uncomment this line
// sprintf (state->dmr_lrrp_gps[slot], "SD-R/P SRC [%d] DST [%d] ", (dheader[5] <<16 ) + (dheader[6] << 8) + dheader[7], (dheader[2] <<16 ) + (dheader[3] <<8 ) + dheader[4]);
}
if ( (state->data_header_format[slot] & 0xF ) == 0x1 && state->data_p_head[slot] == 0)
{
fprintf (stderr, "\n Response Packet - Source: ");
fprintf (stderr, "[%d]", (dheader[5] <<16 ) + (dheader[6] << 8) + dheader[7] );
fprintf (stderr, " Destination: ");
fprintf (stderr, "[%d]", (dheader[2] <<16 ) + (dheader[3] <<8 ) + dheader[4] );
//Remus! Uncomment these lines
// char rsp[90];
// sprintf (rsp, " - RSP SRC [%d] DST [%d] ", (dheader[5] <<16 ) + (dheader[6] << 8) + dheader[7], (dheader[2] <<16 ) + (dheader[3] <<8 ) + dheader[4]);
// strcat (state->dmr_lrrp_gps[slot], rsp);
}
//Removed Dup UDT Message
if ( (state->data_header_format[slot] & 0x40) == 0x40 && state->data_p_head[slot] == 0) //check response req bit
{
fprintf (stderr, "\n Response Requested - ");
fprintf (stderr, " Source:");
fprintf (stderr, " [%d]", (dheader[2] <<16 ) + (dheader[3] << 8) + dheader[4] );
fprintf (stderr, " Destination:");
fprintf (stderr, " [%d]", (dheader[5] <<16 ) + (dheader[6] <<8 ) + dheader[7] );
//Remus! Uncomment these lines
// char rsp[90];
// sprintf (rsp, "- RSP REQ ");
// strcat (state->dmr_lrrp_gps[slot], rsp);
}
//if proprietary header was flagged by the last data header, then process data differently
if (state->data_p_head[slot] == 1)
{
fprintf (stderr, "\n Proprietary Data Header: SAP %01X - Format %01X - MFID %02X",
(dheader[0] & 0xF0) >> 4, dheader[0] & 0xF, dheader[1] );
//state->data_p_head[slot] = 0; //disabling this, we can flag it off after processing pdu instead
state->data_header_sap[slot] = 0; //reset this to zero so we don't trip the condition below
state->data_block_counter[slot]++; //increment the counter since this counts against the data blocks
//set overarching manufacturer in use when non-standard feature id set is up
//if (dheader[1] != 0) state->dmr_mfid = dheader[1]; //diable, will only set in link control or csbk for now (random manufacturers getting set, bad decode? or random feature?)
//assign prop header pdu to 'superframe'
uint8_t blocks = state->data_header_blocks[slot] - 1;
for(i = 0; i < 12; i++)
{
state->dmr_pdu_sf[slot][i+(blocks*12)] = dheader[i];
}
}
//only set this flag after everything else is processed
if (state->data_header_sap[slot] == 0x9 && state->data_p_head[slot] == 0)
{
fprintf (stderr, "\n Proprietary Packet Data Incoming ");
state->data_p_head[slot] = 1; //flag that next data header will be a proprietary data header
}
fprintf (stderr, "%s ", KNRM);
//let user know the data header may have errors
fprintf (stderr, "%s", KRED);
if (CRCCorrect == 1) ; //CRCCorrect 1 is good, else is bad CRC; no print on good
else if(IrrecoverableErrors == 0) fprintf(stderr, " (FEC OK)");
else fprintf(stderr, " (FEC/CRC ERR)");
fprintf (stderr, "%s", KNRM);
} }
@@ -261,24 +373,18 @@ void dmr_block_assembler (dsd_opts * opts, dsd_state * state, uint8_t block_byte
int i, j, k; int i, j, k;
uint8_t lb = 0; //mbc last block uint8_t lb = 0; //mbc last block
uint8_t pf = 0; //mbc protect flag uint8_t pf = 0; //mbc protect flag
uint8_t is_conf_data = 0; //internal flag to see if type 1 blocks contain confirmed data crcs and serials
uint8_t slot = state->currentslot; uint8_t slot = state->currentslot;
int blocks; int blocks;
uint8_t blockcounter = state->data_block_counter[slot]; uint8_t blockcounter = state->data_block_counter[slot];
uint8_t block_num = state->data_header_blocks[slot];
//crc specific variables
uint8_t len = 24; //len of completed message needing crc32 number of blocks*block_len - 12?
uint8_t crclen = 32; //len of the crc32 (obviously)
uint8_t start = 12; //starting position (+12 offset loaded up data header)
uint8_t n = 12; //number of bytes per block
//TODO: CRC check on Header, Blocks and full frames as appropriate
uint32_t CRCCorrect = 0; uint32_t CRCCorrect = 0;
uint32_t CRCComputed = 0; uint32_t CRCComputed = 0;
uint32_t CRCExtracted = 0; uint32_t CRCExtracted = 0;
uint32_t IrrecoverableErrors = 0; uint32_t IrrecoverableErrors = 0;
uint8_t dmr_pdu_sf_bits[18*8*8]; //8 blocks at 18 bytes at 8 bits //just a large value to have plenty storage space uint8_t dmr_pdu_sf_bits[8*8*50]; //give plenty of space so we don't go oob
//MBC Header and Block CRC //MBC Header and Block CRC
uint8_t mbc_crc_good[2]; //header and blocks crc pass/fail local storage uint8_t mbc_crc_good[2]; //header and blocks crc pass/fail local storage
@@ -287,19 +393,27 @@ void dmr_block_assembler (dsd_opts * opts, dsd_state * state, uint8_t block_byte
if (type == 1) blocks = state->data_header_blocks[slot] - 1; if (type == 1) blocks = state->data_header_blocks[slot] - 1;
if (type == 2) blocks = state->data_block_counter[slot]; if (type == 2) blocks = state->data_block_counter[slot];
//UDT Header and Block Check
uint8_t is_udt = 0;
if (type == 3)
{
blocks = state->data_block_counter[slot];
is_udt = 1;
type = 2;
}
//sanity check, setting block_len and block values to sane numbers in case of missing header, else could overload array (crash) or print out //sanity check, setting block_len and block values to sane numbers in case of missing header, else could overload array (crash) or print out
if (blocks < 1) blocks = 1; //changed blocks from uint8_t to int if (blocks < 1) blocks = 1; //changed blocks from uint8_t to int
if (blocks > 8) blocks = 8; if (blocks > 9) blocks = 9;
if (block_len == 0) block_len = 18; if (block_len == 0) block_len = 18;
if (block_len > 24) block_len = 24; if (block_len > 24) block_len = 24;
//TODO: add CRC/FEC validation to each data header and each confirmed data block as well - type 1
if (type == 1) if (type == 1)
{ {
//type 1 data block, shuffle method //type 1 data block, shuffle method
for (j = 0; j < blocks; j++) //6 for (j = 0; j < blocks; j++)
{ {
for (i = 0; i < block_len; i++) //block_len for (i = 0; i < block_len; i++)
{ {
state->dmr_pdu_sf[slot][i+block_len*j] = state->dmr_pdu_sf[slot][i+block_len*(j+1)]; state->dmr_pdu_sf[slot][i+block_len*j] = state->dmr_pdu_sf[slot][i+block_len*(j+1)];
} }
@@ -309,20 +423,141 @@ void dmr_block_assembler (dsd_opts * opts, dsd_state * state, uint8_t block_byte
{ {
state->dmr_pdu_sf[slot][i+(blocks*block_len)] = block_bytes[i]; state->dmr_pdu_sf[slot][i+(blocks*block_len)] = block_bytes[i];
} }
//time to send the completed 'superframe' to the DMR PDU message handler //time to send the completed 'superframe' to the DMR PDU message handler
if (state->data_block_counter[slot] == state->data_header_blocks[slot]) if (state->data_block_counter[slot] == state->data_header_blocks[slot] && state->data_header_valid[slot] == 1)
{ {
//TODO: CRC32 on completed messages //CRC32 on completed messages
for(i = 0, j = 0; i < (block_num * block_len); i++, j+=8)
{
dmr_pdu_sf_bits[j + 0] = (state->dmr_pdu_sf[slot][i] >> 7) & 0x01;
dmr_pdu_sf_bits[j + 1] = (state->dmr_pdu_sf[slot][i] >> 6) & 0x01;
dmr_pdu_sf_bits[j + 2] = (state->dmr_pdu_sf[slot][i] >> 5) & 0x01;
dmr_pdu_sf_bits[j + 3] = (state->dmr_pdu_sf[slot][i] >> 4) & 0x01;
dmr_pdu_sf_bits[j + 4] = (state->dmr_pdu_sf[slot][i] >> 3) & 0x01;
dmr_pdu_sf_bits[j + 5] = (state->dmr_pdu_sf[slot][i] >> 2) & 0x01;
dmr_pdu_sf_bits[j + 6] = (state->dmr_pdu_sf[slot][i] >> 1) & 0x01;
dmr_pdu_sf_bits[j + 7] = (state->dmr_pdu_sf[slot][i] >> 0) & 0x01;
}
//sanity check to prevent a negative or zero block_num or sending a negative value into the bit array
if (block_num < 1 || block_num == 0) block_num = 1;
CRCExtracted = 0;
//extract crc from last block, apply to completed 'superframe' minus header
for(i = 0; i < 32; i++)
{
CRCExtracted = CRCExtracted << 1;
CRCExtracted = CRCExtracted | (uint32_t)(dmr_pdu_sf_bits[i + (block_len * 8) * block_num - 32] & 1); //96
}
//rearrage for ridiculously stupid CRC32 LSO/MSO ordering
for(i = 0, j = 0; i < (block_num * block_len); i+=2, j+=16)
{
dmr_pdu_sf_bits[j + 0] = (state->dmr_pdu_sf[slot][i+1] >> 7) & 0x01;
dmr_pdu_sf_bits[j + 1] = (state->dmr_pdu_sf[slot][i+1] >> 6) & 0x01;
dmr_pdu_sf_bits[j + 2] = (state->dmr_pdu_sf[slot][i+1] >> 5) & 0x01;
dmr_pdu_sf_bits[j + 3] = (state->dmr_pdu_sf[slot][i+1] >> 4) & 0x01;
dmr_pdu_sf_bits[j + 4] = (state->dmr_pdu_sf[slot][i+1] >> 3) & 0x01;
dmr_pdu_sf_bits[j + 5] = (state->dmr_pdu_sf[slot][i+1] >> 2) & 0x01;
dmr_pdu_sf_bits[j + 6] = (state->dmr_pdu_sf[slot][i+1] >> 1) & 0x01;
dmr_pdu_sf_bits[j + 7] = (state->dmr_pdu_sf[slot][i+1] >> 0) & 0x01;
dmr_pdu_sf_bits[j + 8] = (state->dmr_pdu_sf[slot][i] >> 7) & 0x01;
dmr_pdu_sf_bits[j + 9] = (state->dmr_pdu_sf[slot][i] >> 6) & 0x01;
dmr_pdu_sf_bits[j + 10] = (state->dmr_pdu_sf[slot][i] >> 5) & 0x01;
dmr_pdu_sf_bits[j + 11] = (state->dmr_pdu_sf[slot][i] >> 4) & 0x01;
dmr_pdu_sf_bits[j + 12] = (state->dmr_pdu_sf[slot][i] >> 3) & 0x01;
dmr_pdu_sf_bits[j + 13] = (state->dmr_pdu_sf[slot][i] >> 2) & 0x01;
dmr_pdu_sf_bits[j + 14] = (state->dmr_pdu_sf[slot][i] >> 1) & 0x01;
dmr_pdu_sf_bits[j + 15] = (state->dmr_pdu_sf[slot][i] >> 0) & 0x01;
//increment extra 2 bytes on each nth byte (depends on data type 1/2, 3/4, 1) if conf data
if ( i == (block_len - 1) )
{
if (state->data_conf_data[slot] == 0) i+=2;
}
}
//confirmed working now!
CRCComputed = (uint32_t)ComputeCrc32Bit(dmr_pdu_sf_bits, ( block_num * block_len * 8) - 32);
//if the CRC32 is correct, I think its fair to assume we don't need to worry about if the
//individual CRC9s are correct on confirmed data blocks (but we can confirm now that they are all good)
if (CRCComputed == CRCExtracted) CRCCorrect = 1;
//only run on good CRC or CRC/RAS bypass (aggressive_framesync == 0)
if (CRCCorrect || opts->aggressive_framesync == 0)
dmr_pdu (opts, state, block_len, state->dmr_pdu_sf[slot]); dmr_pdu (opts, state, block_len, state->dmr_pdu_sf[slot]);
if (CRCCorrect) ; //print nothing
else
{
fprintf (stderr, "%s", KRED);
fprintf (stderr, "\n Slot %d - Multi Block PDU Message CRC32 ERR", slot+1);
//debug print
// fprintf (stderr, " %X - %X", CRCExtracted, CRCComputed);
fprintf (stderr, "%s", KNRM);
}
//Full Super Frame Type 1 - Payload Output
if (opts->payload == 1)
{
fprintf (stderr, "%s", KGRN);
fprintf (stderr, "\n Slot %d - Multi Block PDU Message\n ", slot+1);
for (i = 0; i < ((blocks+1)*block_len); i++)
{
fprintf (stderr, "[%02X]", state->dmr_pdu_sf[slot][i]);
if (i == 11 || i == 23 || i == 35 || i == 47 || i == 59 || i == 71 || i == 83 || i == 95)
{
fprintf (stderr, "\n ");
} }
} }
//debug print
// fprintf (stderr, " CRC - EXT %X CMP %X", CRCExtracted, CRCComputed);
//type 2 - MBC header and MBC continuation blocks if (state->data_header_format[slot] == 13 || state->data_header_format[slot] == 14 || state->data_header_sap[slot] == 10)
{
fprintf (stderr, "%s", KCYN);
fprintf (stderr, "\n Short Data: ASCII \n" );
for (i = 0; i < ((blocks+1)*block_len); i++)
{
if (state->dmr_pdu_sf[slot][i] <= 0x7E && state->dmr_pdu_sf[slot][i] >=0x20)
{
fprintf (stderr, "%c", state->dmr_pdu_sf[slot][i]);
}
else fprintf (stderr, " ");
if (i == 47 || i == 95) fprintf (stderr, "\n ");
}
}
fprintf (stderr, "%s ", KNRM);
}
//reset data header format storage
state->data_header_format[slot] = 7;
//flag off data header validity
state->data_header_valid[slot] = 0;
//flag off conf data flag
state->data_conf_data[slot] = 0;
} //end completed sf
} //end type 1 blocks
//type 2 - MBC and UDT header, MBC and UDT continuation blocks
if (type == 2) if (type == 2)
{ {
//sanity check (marginal signal, bad decodes, etc) //sanity check (marginal signal, bad decodes, etc) -- may go a little lower (find out max number of MBC blocks supported)
if (state->data_block_counter[slot] > 8) state->data_block_counter[slot] = 8; if (state->data_block_counter[slot] > 4) state->data_block_counter[slot] = 4;
//Type 2 data block, additive method //Type 2 data block, additive method
for (i = 0; i < block_len; i++) for (i = 0; i < block_len; i++)
@@ -335,9 +570,17 @@ void dmr_block_assembler (dsd_opts * opts, dsd_state * state, uint8_t block_byte
lb = block_bytes[0] >> 7; //last block flag lb = block_bytes[0] >> 7; //last block flag
pf = (block_bytes[0] >> 6) & 1; pf = (block_bytes[0] >> 6) & 1;
if (lb == 1) //last block arrived, time to send to cspdu decoder if (is_udt)
{ {
for(i = 0, j = 0; i < 12*4; i++, j+=8) // blocks = state->data_header_blocks[slot];
if (blocks == blockcounter) lb = 1; //double check
pf = 0; //flag off is set from bit in error
}
//last block arrived and we have a valid data header, time to send to cspdu decoder
if (lb == 1 && state->data_header_valid[slot] == 1)
{
for(i = 0, j = 0; i < 12*4; i++, j+=8) //4 blocks max?
{ {
dmr_pdu_sf_bits[j + 0] = (state->dmr_pdu_sf[slot][i] >> 7) & 0x01; dmr_pdu_sf_bits[j + 0] = (state->dmr_pdu_sf[slot][i] >> 7) & 0x01;
dmr_pdu_sf_bits[j + 1] = (state->dmr_pdu_sf[slot][i] >> 6) & 0x01; dmr_pdu_sf_bits[j + 1] = (state->dmr_pdu_sf[slot][i] >> 6) & 0x01;
@@ -349,10 +592,13 @@ void dmr_block_assembler (dsd_opts * opts, dsd_state * state, uint8_t block_byte
dmr_pdu_sf_bits[j + 7] = (state->dmr_pdu_sf[slot][i] >> 0) & 0x01; dmr_pdu_sf_bits[j + 7] = (state->dmr_pdu_sf[slot][i] >> 0) & 0x01;
} }
//check UDT PF
if (is_udt) pf = dmr_pdu_sf_bits[73];
//CRC check on Header and full frames as appropriate (header crc already stored) //CRC check on Header and full frames as appropriate (header crc already stored)
//The 16 bit CRC in the header shall include the data carried by the header. //The 16 bit CRC in the header shall include the data carried by the header.
//The 16 bit CRC in the last block shall be performed on //The 16 bit CRC in the last block shall be performed on
//all MBC blocks (conmbined) except the header block. <-- misleading statement, just like half the dmr manual //all MBC blocks (conmbined) except the header block.
mbc_crc_good[0] = state->data_block_crc_valid[slot][0]; mbc_crc_good[0] = state->data_block_crc_valid[slot][0];
@@ -367,15 +613,13 @@ void dmr_block_assembler (dsd_opts * opts, dsd_state * state, uint8_t block_byte
uint8_t mbc_block_bits[12*8*3]; uint8_t mbc_block_bits[12*8*3];
memset (mbc_block_bits, 0, sizeof(mbc_block_bits)); memset (mbc_block_bits, 0, sizeof(mbc_block_bits));
//shift continuation blocks and last block into seperate array for crc check //shift continuation blocks and last block into seperate array for crc check
for (i = 0; i < 12*8*3; i++) for (i = 0; i < 12*8*3; i++) //only doing 3 blocks (4 minus the header)
{ {
mbc_block_bits[i] = dmr_pdu_sf_bits[i+96]; //skip mbc header mbc_block_bits[i] = dmr_pdu_sf_bits[i+96]; //skip mbc header
} }
CRCComputed = ComputeCrcCCITT16d (mbc_block_bits, ((blocks+0)*96)-16 ); CRCComputed = ComputeCrcCCITT16d (mbc_block_bits, ((blocks+0)*96)-16 );
// fprintf (stderr, " \n CRC EXT %X CRC CMP %X", CRCExtracted, CRCComputed);
if (CRCComputed == CRCExtracted) mbc_crc_good[1] = 1; if (CRCComputed == CRCExtracted) mbc_crc_good[1] = 1;
CRCCorrect = 0; CRCCorrect = 0;
@@ -387,34 +631,28 @@ void dmr_block_assembler (dsd_opts * opts, dsd_state * state, uint8_t block_byte
CRCCorrect = 1; CRCCorrect = 1;
IrrecoverableErrors = 0; IrrecoverableErrors = 0;
} }
else
//cspdu will only act on any fid/opcodes if good CRC to prevent falsing on control signalling
dmr_cspdu (opts, state, dmr_pdu_sf_bits, state->dmr_pdu_sf[slot], CRCCorrect, IrrecoverableErrors);
}
}
//Full Super Frame Type 1 - Debug Output
if (opts->payload == 1 && type == 1 && state->data_block_counter[slot] == state->data_header_blocks[slot])
{ {
fprintf (stderr, "%s", KGRN); fprintf (stderr, "%s", KRED);
fprintf (stderr, "\n Multi Block PDU Superframe - Slot [%d]\n ", slot+1); fprintf (stderr, "\n Slot %d - Multi Block Control Message CRC16 ERR", slot+1);
for (i = 0; i < ((blocks+1)*block_len); i++)
{ //debug print
fprintf (stderr, "[%02X]", state->dmr_pdu_sf[slot][i]); fprintf (stderr, " %X - %X", CRCExtracted, CRCComputed);
if (i == 11 || i == 23 || i == 35 || i == 47 || i == 59 || i == 71 || i == 83 || i == 95)
{
fprintf (stderr, "\n ");
}
}
fprintf (stderr, "%s", KNRM); fprintf (stderr, "%s", KNRM);
} }
//Full Super Frame MBC - Debug Output //cspdu will only act on any fid/opcodes if good CRC to prevent falsing on control signalling
if (opts->payload == 1 && type == 2 && lb == 1) if (!is_udt && !pf) dmr_cspdu (opts, state, dmr_pdu_sf_bits, state->dmr_pdu_sf[slot], CRCCorrect, IrrecoverableErrors);
//will need to reassemble partially before sending to dmr_pdu or dmr_cspdu for handling -- needs testing
if (is_udt && !pf) dmr_udt_cspdu_converter (opts, state, state->dmr_pdu_sf[slot], dmr_pdu_sf_bits, CRCCorrect, IrrecoverableErrors);
//Full Super Frame MBC/UDT - Debug Output
if (opts->payload == 1)
{ {
fprintf (stderr, "%s", KGRN); fprintf (stderr, "%s", KGRN);
fprintf (stderr, "\n MBC Multi Block PDU Superframe - Slot [%d]\n ", slot+1); fprintf (stderr, "\n Slot %d - Multi Block Control Message\n ", slot+1);
for (i = 0; i < ((blocks+1)*block_len); i++) for (i = 0; i < ((blocks+1)*block_len); i++)
{ {
fprintf (stderr, "[%02X]", state->dmr_pdu_sf[slot][i]); fprintf (stderr, "[%02X]", state->dmr_pdu_sf[slot][i]);
@@ -424,16 +662,23 @@ void dmr_block_assembler (dsd_opts * opts, dsd_state * state, uint8_t block_byte
} }
} }
fprintf (stderr, "%s", KRED); fprintf (stderr, "%s", KRED);
if (mbc_crc_good[0] == 0) fprintf (stderr, "MBC Header CRC ERR "); if (mbc_crc_good[0] == 0) fprintf (stderr, "MBC/UDT Header CRC ERR ");
if (mbc_crc_good[1] == 0) fprintf (stderr, "MBC Blocks CRC ERR "); if (mbc_crc_good[1] == 0) fprintf (stderr, "MBC/UDT Blocks CRC ERR ");
if (pf) fprintf (stderr, "MBC/UDT Header/Blocks Protected ");
fprintf (stderr, "%s ", KNRM); fprintf (stderr, "%s ", KNRM);
} }
state->data_block_counter[slot]++; //increment block counter } //end last block flag on MBC
if (type == 2 && lb == 1) } //end type 2 (MBC Header and Continuation)
//leave this seperate so we can reset/zero stuff in case the data header isn't valid, etc
//switched to an if-elseif-else so we could get the block counter increment on the end
//without having it in an akward position
//if the end of normal data header and blocks
if (type == 1 && state->data_block_counter[slot] == state->data_header_blocks[slot])
{ {
state->data_block_counter[slot] = 0; //reset the block counter (MBCs)
//clear out unified pdu 'superframe' slot //clear out unified pdu 'superframe' slot
for (short int i = 0; i < 288; i++) for (short int i = 0; i < 288; i++)
@@ -441,22 +686,65 @@ void dmr_block_assembler (dsd_opts * opts, dsd_state * state, uint8_t block_byte
state->dmr_pdu_sf[slot][i] = 0; state->dmr_pdu_sf[slot][i] = 0;
} }
state->data_block_crc_valid[slot][0] = 0; //Zero Out MBC Header Block CRC Valid //Zero Out MBC Header Block CRC Valid
state->data_block_crc_valid[slot][0] = 0;
//reset the block counter (data blocks)
state->data_block_counter[slot] = 1;
//reset data header format storage
state->data_header_format[slot] = 7;
//flag off data header validity
state->data_header_valid[slot] = 0;
//flag off conf data flag
state->data_conf_data[slot] = 0;
} }
//else if the end of MBC Header and Blocks
else if (type == 2 && lb == 1)
{
//clear out unified pdu 'superframe' slot
for (short int i = 0; i < 288; i++)
{
state->dmr_pdu_sf[slot][i] = 0;
} }
//failsafe to clear old data header, block info, cach, in case of tact/emb/slottype failures and we //Zero Out MBC Header Block CRC Valid
//can no longer verify accurate data block reporting state->data_block_crc_valid[slot][0] = 0;
//reset the block counter (data blocks)
state->data_block_counter[slot] = 1;
//reset data header format storage
state->data_header_format[slot] = 7;
//flag off data header validity
state->data_header_valid[slot] = 0;
//flag off conf data flag
state->data_conf_data[slot] = 0;
}
//else increment block counter after sorting/shuffling blocks
else state->data_block_counter[slot]++;
}
//failsafe to clear old data header, block info, cach, in case of tact/emb/slottype failures
//or tuning away and we can no longer verify accurate data block reporting
void dmr_reset_blocks (dsd_opts * opts, dsd_state * state) void dmr_reset_blocks (dsd_opts * opts, dsd_state * state)
{ {
memset (state->data_p_head, 0, sizeof(state->data_p_head)); memset (state->data_p_head, 0, sizeof(state->data_p_head));
memset (state->data_conf_data, 0, sizeof(state->data_conf_data)); memset (state->data_conf_data, 0, sizeof(state->data_conf_data));
memset (state->dmr_pdu_sf, 0, sizeof(state->dmr_pdu_sf)); memset (state->dmr_pdu_sf, 0, sizeof(state->dmr_pdu_sf));
memset (state->data_block_counter, 0, sizeof(state->data_block_counter)); memset (state->data_block_counter, 1, sizeof(state->data_block_counter));
memset (state->data_header_blocks, 0, sizeof(state->data_header_blocks)); memset (state->data_header_blocks, 1, sizeof(state->data_header_blocks));
memset (state->data_block_crc_valid, 0, sizeof(state->data_block_crc_valid)); memset (state->data_block_crc_valid, 0, sizeof(state->data_block_crc_valid));
memset (state->dmr_lrrp_source, 0, sizeof(state->dmr_lrrp_source)); memset (state->dmr_lrrp_source, 0, sizeof(state->dmr_lrrp_source));
memset (state->dmr_cach_fragment, 1, sizeof (state->dmr_cach_fragment)); memset (state->dmr_cach_fragment, 1, sizeof (state->dmr_cach_fragment));
memset (state->cap_plus_csbk_bits, 0, sizeof(state->cap_plus_csbk_bits));
memset (state->data_header_valid, 0, sizeof(state->data_header_valid));
memset (state->data_header_format, 7, sizeof(state->data_header_format));
//reset some strings
sprintf (state->call_string[0], "%s", " "); //21 spaces
sprintf (state->call_string[1], "%s", " "); //21 spaces
sprintf (state->dmr_lrrp_gps[0], "%s", "");
sprintf (state->dmr_lrrp_gps[1], "%s", "");
} }

View File

@@ -42,6 +42,11 @@ void dmrBS (dsd_opts * opts, dsd_state * state)
uint8_t vc1; uint8_t vc1;
uint8_t vc2; uint8_t vc2;
//assign as nonsensical numbers
uint8_t cc = 25;
uint8_t power = 9; //power and pre-emption indicator
uint8_t lcss = 9;
//would be ideal to grab all dibits and break them into bits to pass to new data handler? //would be ideal to grab all dibits and break them into bits to pass to new data handler?
uint8_t dummy_bits[196]; uint8_t dummy_bits[196];
memset (dummy_bits, 0, sizeof(dummy_bits)); memset (dummy_bits, 0, sizeof(dummy_bits));
@@ -109,13 +114,8 @@ void dmrBS (dsd_opts * opts, dsd_state * state)
//disabled for dmr_cach testing //disabled for dmr_cach testing
tact_okay = 0; tact_okay = 0;
if ( Hamming_7_4_decode (tact_bits) ) tact_okay = 1; if ( Hamming_7_4_decode (tact_bits) ) tact_okay = 1;
if (tact_okay != 1) if (tact_okay != 1) goto END;
{
if (opts->aggressive_framesync == 1)
{
goto END;
}
}
internalslot = state->currentslot = tact_bits[1]; internalslot = state->currentslot = tact_bits[1];
@@ -189,13 +189,13 @@ void dmrBS (dsd_opts * opts, dsd_state * state)
syncdata[(2*i)+1] = (1 & dibit); // bit 0 syncdata[(2*i)+1] = (1 & dibit); // bit 0
//embedded link control //embedded link control
if(internalslot == 0 && vc1 > 1 && vc1 < 6) //grab on vc1 values 2-5 B C D and E if(internalslot == 0 && vc1 > 1 && vc1 < 7) //grab on vc1 values 2-5 B C D and E
{ {
state->dmr_embedded_signalling[internalslot][vc1-1][i*2] = (1 & (dibit >> 1)); // bit 1 state->dmr_embedded_signalling[internalslot][vc1-1][i*2] = (1 & (dibit >> 1)); // bit 1
state->dmr_embedded_signalling[internalslot][vc1-1][i*2+1] = (1 & dibit); // bit 0 state->dmr_embedded_signalling[internalslot][vc1-1][i*2+1] = (1 & dibit); // bit 0
} }
if(internalslot == 1 && vc2 > 1 && vc2 < 6) //grab on vc2 values 2-5 B C D and E if(internalslot == 1 && vc2 > 1 && vc2 < 7) //grab on vc2 values 2-5 B C D and E
{ {
state->dmr_embedded_signalling[internalslot][vc2-1][i*2] = (1 & (dibit >> 1)); // bit 1 state->dmr_embedded_signalling[internalslot][vc2-1][i*2] = (1 & (dibit >> 1)); // bit 1
state->dmr_embedded_signalling[internalslot][vc2-1][i*2+1] = (1 & dibit); // bit 0 state->dmr_embedded_signalling[internalslot][vc2-1][i*2+1] = (1 & dibit); // bit 0
@@ -265,6 +265,9 @@ void dmrBS (dsd_opts * opts, dsd_state * state)
else fprintf (stderr,"Sync: -DMR "); else fprintf (stderr,"Sync: -DMR ");
vc1 = 1; vc1 = 1;
//close MBEout file - slot 1
if (opts->mbe_out_f != NULL) closeMbeOutFile (opts, state);
} }
if (internalslot == 1) if (internalslot == 1)
{ {
@@ -276,6 +279,9 @@ void dmrBS (dsd_opts * opts, dsd_state * state)
vc2 = 1; vc2 = 1;
//close MBEout file - slot 2
if (opts->mbe_out_fR != NULL) closeMbeOutFileR (opts, state);
} }
dmr_data_sync (opts, state); dmr_data_sync (opts, state);
skipcount++; skipcount++;
@@ -294,9 +300,9 @@ void dmrBS (dsd_opts * opts, dsd_state * state)
if ( (strcmp (sync, DMR_BS_VOICE_SYNC) != 0) && emb_ok == 0) goto END; //fprintf (stderr, "EMB BAD? "); if ( (strcmp (sync, DMR_BS_VOICE_SYNC) != 0) && emb_ok == 0) goto END; //fprintf (stderr, "EMB BAD? ");
else if (emb_ok == 1) else if (emb_ok == 1)
{ {
uint8_t cc = ((EmbeddedSignalling[0] << 3) + (EmbeddedSignalling[1] << 2) + (EmbeddedSignalling[2] << 1) + EmbeddedSignalling[3]); cc = ((EmbeddedSignalling[0] << 3) + (EmbeddedSignalling[1] << 2) + (EmbeddedSignalling[2] << 1) + EmbeddedSignalling[3]);
uint8_t power = EmbeddedSignalling[4]; power = EmbeddedSignalling[4];
uint8_t lcss = ((EmbeddedSignalling[5] << 1) + EmbeddedSignalling[6]); lcss = ((EmbeddedSignalling[5] << 1) + EmbeddedSignalling[6]);
} }
@@ -312,12 +318,16 @@ void dmrBS (dsd_opts * opts, dsd_state * state)
state->dmrburstL = 16; state->dmrburstL = 16;
vc = vc1; vc = vc1;
sprintf (light, "%s", " [SLOT1] slot2 "); sprintf (light, "%s", " [SLOT1] slot2 ");
//open MBEout file - slot 1
if ((opts->mbe_out_dir[0] != 0) && (opts->mbe_out_f == NULL)) openMbeOutFile (opts, state);
} }
else else
{ {
state->dmrburstR = 16; state->dmrburstR = 16;
vc = vc2; vc = vc2;
sprintf (light, "%s", " slot1 [SLOT2] "); sprintf (light, "%s", " slot1 [SLOT2] ");
//open MBEout file - slot 2
if ((opts->mbe_out_dir[0] != 0) && (opts->mbe_out_fR == NULL)) openMbeOutFileR (opts, state);
} }
if (opts->inverted_dmr == 0) sprintf (polarity, "%s", "+"); if (opts->inverted_dmr == 0) sprintf (polarity, "%s", "+");
else sprintf (polarity, "%s", "-"); else sprintf (polarity, "%s", "-");
@@ -329,6 +339,8 @@ void dmrBS (dsd_opts * opts, dsd_state * state)
//process embedded link control //process embedded link control
fprintf (stderr, "\n"); fprintf (stderr, "\n");
dmr_data_burst_handler(opts, state, (uint8_t *)dummy_bits, 0xEB); dmr_data_burst_handler(opts, state, (uint8_t *)dummy_bits, 0xEB);
//check the single burst/reverse channel opportunity
dmr_sbrc (opts, state, power);
} }
if (internalslot == 1 && vc2 == 6) if (internalslot == 1 && vc2 == 6)
@@ -336,6 +348,8 @@ void dmrBS (dsd_opts * opts, dsd_state * state)
//process embedded link control //process embedded link control
fprintf (stderr, "\n"); fprintf (stderr, "\n");
dmr_data_burst_handler(opts, state, (uint8_t *)dummy_bits, 0xEB); dmr_data_burst_handler(opts, state, (uint8_t *)dummy_bits, 0xEB);
//check the single burst/reverse channel opportunity
dmr_sbrc (opts, state, power);
} }
if (opts->payload == 1) fprintf (stderr, "\n"); //extra line break necessary here if (opts->payload == 1) fprintf (stderr, "\n"); //extra line break necessary here
@@ -384,11 +398,36 @@ void dmrBS (dsd_opts * opts, dsd_state * state)
state->last_cc_sync_time = time(NULL); state->last_cc_sync_time = time(NULL);
} }
//'DSP' output to file
if (opts->use_dsp_output == 1)
{
FILE * pFile; //file pointer
pFile = fopen (opts->dsp_out_file, "a");
fprintf (pFile, "\n%d 98 ", internalslot+1); //'98' is CACH designation value
for (i = 0; i < 6; i++) //3 byte CACH
{
int cach_byte = (state->dmr_stereo_payload[i*2] << 2) | state->dmr_stereo_payload[i*2 + 1];
fprintf (pFile, "%X", cach_byte);
}
fprintf (pFile, "\n%d 10 ", internalslot+1); //0x10 for voice burst
for (i = 6; i < 72; i++) //33 bytes, no CACH
{
int dsp_byte = (state->dmr_stereo_payload[i*2] << 2) | state->dmr_stereo_payload[i*2 + 1];
fprintf (pFile, "%X", dsp_byte);
}
fclose (pFile);
}
//reset err checks //reset err checks
cach_err = 1; cach_err = 1;
tact_okay = 0; tact_okay = 0;
emb_ok = 0; emb_ok = 0;
//reset emb components
cc = 25;
power = 9;
lcss = 9;
//Extra safeguards to break loop //Extra safeguards to break loop
// if ( (vc1 > 7 && vc2 > 7) ) goto END; // if ( (vc1 > 7 && vc2 > 7) ) goto END;
if ( (vc1 > 14 || vc2 > 14) ) goto END; if ( (vc1 > 14 || vc2 > 14) ) goto END;
@@ -420,6 +459,10 @@ void dmrBS (dsd_opts * opts, dsd_state * state)
state->errs2R = 0; state->errs2R = 0;
state->errs2 = 0; state->errs2 = 0;
//close any open MBEout files
if (opts->mbe_out_f != NULL) closeMbeOutFile (opts, state);
if (opts->mbe_out_fR != NULL) closeMbeOutFileR (opts, state);
//if we have a tact or emb err, then produce sync pattern/err message //if we have a tact or emb err, then produce sync pattern/err message
if (tact_okay != 1 || emb_ok != 1) if (tact_okay != 1 || emb_ok != 1)
{ {
@@ -430,18 +473,16 @@ void dmrBS (dsd_opts * opts, dsd_state * state)
fprintf (stderr, "| VOICE CACH/EMB ERR"); fprintf (stderr, "| VOICE CACH/EMB ERR");
fprintf (stderr, "%s", KNRM); fprintf (stderr, "%s", KNRM);
fprintf (stderr, "\n"); fprintf (stderr, "\n");
//run LFSR if either slot had an active MI in it. //run refresh if either slot had an active MI in it.
if (state->payload_algid >= 0x21) if (state->payload_algid >= 0x21)
{ {
state->currentslot = 0; state->currentslot = 0;
LFSR(state); dmr_alg_refresh (opts, state);
fprintf (stderr, "\n");
} }
if (state->payload_algidR >= 0x21) if (state->payload_algidR >= 0x21)
{ {
state->currentslot = 1; state->currentslot = 1;
LFSR(state); dmr_alg_refresh (opts, state);
fprintf (stderr, "\n");
} }
//failsafe to reset all data header and blocks when bad tact or emb //failsafe to reset all data header and blocks when bad tact or emb
@@ -471,6 +512,7 @@ void dmrBSBootstrap (dsd_opts * opts, dsd_state * state)
uint8_t cach_err = 0; uint8_t cach_err = 0;
uint8_t sync_okay = 1; uint8_t sync_okay = 1;
uint8_t internalslot;
char cachdata[25]; char cachdata[25];
int cachInterleave[24] = int cachInterleave[24] =
@@ -503,10 +545,7 @@ void dmrBSBootstrap (dsd_opts * opts, dsd_state * state)
{ {
dibit = *dibit_p; dibit = *dibit_p;
dibit_p++; dibit_p++;
if(opts->inverted_dmr == 1) if(opts->inverted_dmr == 1) dibit = (dibit ^ 2) & 3;
{
dibit = (dibit ^ 2);
}
state->dmr_stereo_payload[i] = dibit; state->dmr_stereo_payload[i] = dibit;
} }
@@ -526,15 +565,9 @@ void dmrBSBootstrap (dsd_opts * opts, dsd_state * state)
//decode and correct tact and compare //decode and correct tact and compare
if ( Hamming_7_4_decode (tact_bits) ) tact_okay = 1; if ( Hamming_7_4_decode (tact_bits) ) tact_okay = 1;
if (tact_okay != 1) if (tact_okay != 1) goto END;
{
if (opts->aggressive_framesync == 1)
{
goto END;
}
}
state->currentslot = tact_bits[1]; internalslot = state->currentslot = tact_bits[1];
//Setup for first AMBE Frame //Setup for first AMBE Frame
@@ -589,18 +622,16 @@ void dmrBSBootstrap (dsd_opts * opts, dsd_state * state)
sync[24] = 0; sync[24] = 0;
if ( strcmp (sync, DMR_BS_VOICE_SYNC) != 0) if ( strcmp (sync, DMR_BS_VOICE_SYNC) != 0)
{
if (opts->aggressive_framesync == 1)
{ {
sync_okay = 0; sync_okay = 0;
goto END; goto END;
} }
}
//Continue Second AMBE Frame, 18 after Sync or EmbeddedSignalling //Continue Second AMBE Frame, 18 after Sync or EmbeddedSignalling
for(i = 0; i < 18; i++) for(i = 0; i < 18; i++)
{ {
dibit = getDibit(opts, state); dibit = getDibit(opts, state);
state->dmr_stereo_payload[i+90] = dibit;
ambe_fr2[*w][*x] = (1 & (dibit >> 1)); // bit 1 ambe_fr2[*w][*x] = (1 & (dibit >> 1)); // bit 1
ambe_fr2[*y][*z] = (1 & dibit); // bit 0 ambe_fr2[*y][*z] = (1 & dibit); // bit 0
@@ -623,6 +654,7 @@ void dmrBSBootstrap (dsd_opts * opts, dsd_state * state)
for(i = 0; i < 36; i++) for(i = 0; i < 36; i++)
{ {
dibit = getDibit(opts, state); dibit = getDibit(opts, state);
state->dmr_stereo_payload[i+108] = dibit;
ambe_fr3[*w][*x] = (1 & (dibit >> 1)); // bit 1 ambe_fr3[*w][*x] = (1 & (dibit >> 1)); // bit 1
ambe_fr3[*y][*z] = (1 & dibit); // bit 0 ambe_fr3[*y][*z] = (1 & dibit); // bit 0
@@ -633,6 +665,26 @@ void dmrBSBootstrap (dsd_opts * opts, dsd_state * state)
} }
//'DSP' output to file
if (opts->use_dsp_output == 1)
{
FILE * pFile; //file pointer
pFile = fopen (opts->dsp_out_file, "a");
fprintf (pFile, "\n%d 98 ", internalslot+1); //'98' is CACH designation value
for (i = 0; i < 6; i++) //3 byte CACH
{
int cach_byte = (state->dmr_stereo_payload[i*2] << 2) | state->dmr_stereo_payload[i*2 + 1];
fprintf (pFile, "%X", cach_byte);
}
fprintf (pFile, "\n%d 10 ", internalslot+1); //0x10 for "voice burst"
for (i = 6; i < 72; i++) //33 bytes, no CACH
{
int dsp_byte = (state->dmr_stereo_payload[i*2] << 2) | state->dmr_stereo_payload[i*2 + 1];
fprintf (pFile, "%X", dsp_byte);
}
fclose (pFile);
}
fprintf (stderr,"%s ", getTime()); fprintf (stderr,"%s ", getTime());
char polarity[3]; char polarity[3];
char light[18]; char light[18];
@@ -640,10 +692,14 @@ void dmrBSBootstrap (dsd_opts * opts, dsd_state * state)
if (state->currentslot == 0) if (state->currentslot == 0)
{ {
sprintf (light, "%s", " [SLOT1] slot2 "); sprintf (light, "%s", " [SLOT1] slot2 ");
//open MBEout file - slot 1
if ((opts->mbe_out_dir[0] != 0) && (opts->mbe_out_f == NULL)) openMbeOutFile (opts, state);
} }
else else
{ {
sprintf (light, "%s", " slot1 [SLOT2] "); sprintf (light, "%s", " slot1 [SLOT2] ");
//open MBEout file - slot 2
if ((opts->mbe_out_dir[0] != 0) && (opts->mbe_out_fR == NULL)) openMbeOutFileR (opts, state);
} }
if (opts->inverted_dmr == 0) sprintf (polarity, "%s", "+"); if (opts->inverted_dmr == 0) sprintf (polarity, "%s", "+");
else sprintf (polarity, "%s", "-"); else sprintf (polarity, "%s", "-");
@@ -665,7 +721,7 @@ void dmrBSBootstrap (dsd_opts * opts, dsd_state * state)
processMbeFrame (opts, state, NULL, ambe_fr3, NULL); processMbeFrame (opts, state, NULL, ambe_fr3, NULL);
//collect the mi fragment //collect the mi fragment
dmr_late_entry_mi_fragment (opts, state, 1, ambe_fr, ambe_fr2, ambe_fr3); dmr_late_entry_mi_fragment (opts, state, 1, m1, m2, m3);
cach_err = dmr_cach (opts, state, cachdata); cach_err = dmr_cach (opts, state, cachdata);
fprintf (stderr, "\n"); fprintf (stderr, "\n");
@@ -683,18 +739,17 @@ void dmrBSBootstrap (dsd_opts * opts, dsd_state * state)
fprintf (stderr, "%s", KRED); fprintf (stderr, "%s", KRED);
fprintf (stderr, "| VOICE CACH/SYNC ERR"); fprintf (stderr, "| VOICE CACH/SYNC ERR");
fprintf (stderr, "%s", KNRM); fprintf (stderr, "%s", KNRM);
//run LFSR if either slot had an active MI in it. fprintf (stderr, "\n");
//run refresh if either slot had an active MI in it.
if (state->payload_algid >= 0x21) if (state->payload_algid >= 0x21)
{ {
state->currentslot = 0; state->currentslot = 0;
LFSR(state); dmr_alg_refresh (opts, state);
fprintf (stderr, "\n");
} }
if (state->payload_algidR >= 0x21) if (state->payload_algidR >= 0x21)
{ {
state->currentslot = 1; state->currentslot = 1;
LFSR(state); dmr_alg_refresh (opts, state);
fprintf (stderr, "\n");
} }
//failsafe to reset all data header and blocks when bad tact or emb //failsafe to reset all data header and blocks when bad tact or emb

View File

@@ -22,31 +22,33 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8
int csbk_pf = 0; int csbk_pf = 0;
int csbk_o = 0; int csbk_o = 0;
int csbk_fid = 0; int csbk_fid = 0;
uint64_t csbk_data = 0;
int csbk = 0;
long int ccfreq = 0; long int ccfreq = 0;
if(IrrecoverableErrors == 0 && CRCCorrect == 1)
{
csbk_lb = ( (cs_pdu[0] & 0x80) >> 7 ); csbk_lb = ( (cs_pdu[0] & 0x80) >> 7 );
csbk_pf = ( (cs_pdu[0] & 0x40) >> 6 ); csbk_pf = ( (cs_pdu[0] & 0x40) >> 6 );
csbk_o = cs_pdu[0] & 0x3F; csbk_o = cs_pdu[0] & 0x3F;
csbk_fid = cs_pdu[1]; //feature set id csbk_fid = cs_pdu[1]; //feature set id
csbk_pf = ( (cs_pdu[1] & 0x80) >> 7);
csbk = ((cs_pdu[0] & 0x3F) << 8) | cs_pdu[1]; //opcode and fid combo set
//update time to prevent random 'Control Channel Signal Lost' hopping
//in the middle of voice call on current Control Channel (con+ and t3)
state->last_cc_sync_time = time(NULL);
//check, regardless of CRC err
if (IrrecoverableErrors == 0)
{
//Hytera XPT CSBK Check -- if bits 0 and 1 are used as lcss, gi, ts, then this bit may be set on
if ( csbk_fid == 0x68 && (csbk_o == 0x0A || csbk_o == 0x0B) ) csbk_pf = 0;
if (csbk_pf == 1) //check the protect flag, don't run if set if (csbk_pf == 1) //check the protect flag, don't run if set
{ {
fprintf (stderr, "%s", KRED); fprintf (stderr, "%s", KRED);
fprintf (stderr, "\n Protected Control Signalling Block(s)"); fprintf (stderr, "\n Protected Control Signalling Block(s)");
fprintf (stderr, "%s", KNRM); fprintf (stderr, "%s", KNRM);
} }
}
if(IrrecoverableErrors == 0 && CRCCorrect == 1)
{
//update time to prevent random 'Control Channel Signal Lost' hopping
//in the middle of voice call on current Control Channel (con+ and t3)
state->last_cc_sync_time = time(NULL);
if (csbk_pf == 0) //okay to run if (csbk_pf == 0) //okay to run
{ {
@@ -209,6 +211,7 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8
SetFreq(opts->rigctl_sockfd, freq); SetFreq(opts->rigctl_sockfd, freq);
state->p25_vc_freq[0] = state->p25_vc_freq[1] = freq; state->p25_vc_freq[0] = state->p25_vc_freq[1] = freq;
opts->p25_is_tuned = 1; //set to 1 to set as currently tuned so we don't keep tuning nonstop opts->p25_is_tuned = 1; //set to 1 to set as currently tuned so we don't keep tuning nonstop
dmr_reset_blocks (opts, state); //reset all block gathering since we are tuning away
} }
//rtl_udp //rtl_udp
@@ -217,6 +220,7 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8
rtl_udp_tune (opts, state, freq); rtl_udp_tune (opts, state, freq);
state->p25_vc_freq[0] = state->p25_vc_freq[1] = freq; state->p25_vc_freq[0] = state->p25_vc_freq[1] = freq;
opts->p25_is_tuned = 1; opts->p25_is_tuned = 1;
dmr_reset_blocks (opts, state); //reset all block gathering since we are tuning away
} }
} }
@@ -234,7 +238,7 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8
{ {
//initial line break //initial line break
fprintf (stderr, "\n"); fprintf (stderr, "\n");
fprintf (stderr, " Move (C_MOVE) (TODO)"); fprintf (stderr, " Move (C_MOVE) ");
} }
//Aloha //Aloha
@@ -372,10 +376,10 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8
{ {
//initial line break //initial line break
fprintf (stderr, "\n"); fprintf (stderr, "\n");
fprintf (stderr, " Clear (P_CLEAR) (TODO)"); fprintf (stderr, " Clear (P_CLEAR) ");
} }
//(P_PROTECT) - Could be a useful way of determining who is on the current timeslot p_kind 2 //(P_PROTECT)
if (csbk_o == 47) if (csbk_o == 47)
{ {
//initial line break //initial line break
@@ -395,27 +399,6 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8
fprintf (stderr, "\n"); fprintf (stderr, "\n");
fprintf (stderr, " Target [%08d] - Source [%08d]", target, source); fprintf (stderr, " Target [%08d] - Source [%08d]", target, source);
//Illegally Parked is another way to say a private call is outbound on this channel
//so, we can use this as a form of 'link control'
if (p_kind == 2)
{
//don't set this if operating out of dmr mono or using call alert beep
if (opts->dmr_mono == 0 && opts->call_alert == 0)
{
if (state->currentslot == 0)
{
state->lasttg = target;
state->lastsrc = source;
}
else
{
state->lasttgR = target;
state->lastsrcR = source;
}
}
}
} }
if (csbk_o == 40) //0x28 //check to see if these are fid 0 only, or also in other manufacturer fids if (csbk_o == 40) //0x28 //check to see if these are fid 0 only, or also in other manufacturer fids
@@ -545,28 +528,28 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8
{ {
//initial line break //initial line break
fprintf (stderr, "\n"); fprintf (stderr, "\n");
fprintf (stderr, " C_AHOY (TODO) "); fprintf (stderr, " C_AHOY ");
} }
if (csbk_o == 42) if (csbk_o == 42)
{ {
//initial line break //initial line break
fprintf (stderr, "\n"); fprintf (stderr, "\n");
fprintf (stderr, " P_MAINT (TODO) "); fprintf (stderr, " P_MAINT ");
} }
if (csbk_o == 30) if (csbk_o == 30)
{ {
//initial line break //initial line break
fprintf (stderr, "\n"); fprintf (stderr, "\n");
fprintf (stderr, " C_ACKVIT (TODO) "); fprintf (stderr, " C_ACKVIT ");
} }
if (csbk_o == 31) if (csbk_o == 31)
{ {
//initial line break //initial line break
fprintf (stderr, "\n"); fprintf (stderr, "\n");
fprintf (stderr, " C_RAND (TODO) "); fprintf (stderr, " C_RAND ");
} }
//tier 2 csbks //tier 2 csbks
@@ -641,39 +624,116 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8
} }
//Capacity+ Section //Reworked Cap+ for Multi Block FL PDU and Private/Data Calls
//experimental, but seems to be working well
if (csbk_fid == 0x10) if (csbk_fid == 0x10)
{ {
//not quite sure how these tuning rules will go over
//if they don't work so well, may just fall back to //Cap+ Something
//a 'follow rest channel on no sync' only approach if (csbk_o == 0x3A)
{
//initial line break
fprintf (stderr, "\n");
fprintf (stderr, "%s", KYEL);
fprintf (stderr, " Capacity Plus CSBK 0x3A ");
// 01:15:08 Sync: +DMR slot1 [slot2] | Color Code=03 | CSBK
// Capacity Plus Channel Status - FL: 3 TS: 1 RS: 0 - Rest Channel 1 - Single Block
// Ch1: Rest Ch2: Idle Ch3: Idle Ch4: Idle
// Ch5: Idle Ch6: Idle Ch7: Idle Ch8: Idle
// DMR PDU Payload [BE][10][E1][00][00][00][00][00][00][00][4E][15]
// 01:15:08 Sync: +DMR [slot1] slot2 | Color Code=03 | CSBK
//FL, TS, and Rest Channel seem to be in same location as the Channel Status CSBK
//other values are currently unknown
// DMR PDU Payload [BA][10][C1][3B][61][11][51][00][00][00][3D][D6]
// 01:15:08 Sync: +DMR slot1 [slot2] | Color Code=03 | CSBK
// DMR PDU Payload [BA][10][E1][3B][61][11][51][00][00][00][46][BE]
}
//Cap+ Neighbors
if (csbk_o == 0x3B)
{
//initial line break
fprintf (stderr, "\n");
fprintf (stderr, "%s", KYEL);
fprintf (stderr, " Capacity Plus Neighbor List ");
uint8_t nl[6]; //neighbors numerical value
uint8_t nr[6]; //neighbors current rest channel
memset (nl, 0, sizeof (nl));
memset (nr, 0, sizeof (nr));
for (int i = 0; i < 6; i++)
{
nl[i] = (uint8_t)ConvertBitIntoBytes(&cs_pdu_bits[32+(i*8)], 4);
nr[i] = (uint8_t)ConvertBitIntoBytes(&cs_pdu_bits[36+(i*8)], 4);
if (nl[i]) fprintf (stderr, "S: %d R(%d) ", nl[i], nr[i]);
}
}
//Cap+ Channel Status
if (csbk_o == 0x3E) if (csbk_o == 0x3E)
{ {
//initial line break //initial line break
fprintf (stderr, "\n"); fprintf (stderr, "\n");
fprintf (stderr, "%s", KYEL); fprintf (stderr, "%s", KYEL);
uint8_t fl = (uint8_t)ConvertBitIntoBytes(&cs_pdu_bits[16], 2); uint8_t fl = (uint8_t)ConvertBitIntoBytes(&cs_pdu_bits[16], 2);
uint8_t slot = cs_pdu_bits[18]; uint8_t ts = cs_pdu_bits[18]; //timeslot this PDU occurs in
uint8_t rest_channel = cs_pdu[2] & 0xF; //0xF, or 0x1F? uint8_t res = cs_pdu_bits[19]; //unknown, always seems to be 0 -- could be used in larger Cap+? like a bank switch?
uint8_t rest_channel = (uint8_t)ConvertBitIntoBytes(&cs_pdu_bits[20], 4);
uint8_t group_tally = 0; //set this to the number of active group channels tallied
uint8_t block_num = state->cap_plus_block_num;
//sanity check
if (block_num > 6)
{
state->cap_plus_block_num = 6;
block_num = 6;
}
uint8_t ch[8]; //one bit per channel uint8_t ch[8]; //one bit per channel
uint8_t pch[8]; //private or data call channel bits
uint8_t tg = 0; uint8_t tg = 0;
uint32_t tghex = 0; //combined all tgs for debug
int i, j, k; int i, j, k;
//tg and channel info for trunking purposes //tg and channel info for trunking purposes
uint8_t t_tg[9]; uint8_t t_tg[9];
memset (t_tg, 0, sizeof(t_tg)); memset (t_tg, 0, sizeof(t_tg));
k = 0; //initialize group ch and private/data channel bit arrays
for (i = 0; i < 8; i++)
{
ch[i] = 0;
pch[i] = 0;
}
//treating FL as a form of LCSS
if (fl == 2 || fl == 3) //initial or single block (fl2 or fl3)
{
memset (state->cap_plus_csbk_bits, 0, sizeof(state->cap_plus_csbk_bits));
for (i = 0; i < 10*8; i++) state->cap_plus_csbk_bits[i] = cs_pdu_bits[i];
state->cap_plus_block_num = 0;
}
else //appended block (fl0) or final block (fl1)
{
for (i = 0; i < 7*8; i++) state->cap_plus_csbk_bits[i+80+(7*8*block_num)] = cs_pdu_bits[i+24];
block_num++;
state->cap_plus_block_num++;
}
if (rest_channel != state->dmr_rest_channel) if (rest_channel != state->dmr_rest_channel)
{ {
state->dmr_rest_channel = rest_channel; state->dmr_rest_channel = rest_channel;
} }
for (int i = 0; i < 8; i++)
{
ch[i] = cs_pdu_bits[i+24];
}
//assign to cc freq to follow during no sync //assign to cc freq to follow during no sync
if (state->trunk_chan_map[rest_channel] != 0) if (state->trunk_chan_map[rest_channel] != 0)
@@ -683,28 +743,82 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8
opts->p25_is_tuned = 1; opts->p25_is_tuned = 1;
} }
fprintf (stderr, " Capacity Plus Channel Status - Rest Channel %d", rest_channel); fprintf (stderr, " Capacity Plus Channel Status - FL: %d TS: %d RS: %d - Rest Channel %d", fl, ts, res, rest_channel);
if (fl == 0) fprintf (stderr, " - Appended Block"); //have not yet observed a system use this fl value
if (fl == 1) fprintf (stderr, " - Final Block");
if (fl == 2) fprintf (stderr, " - Initial Block");
if (fl == 3) fprintf (stderr, " - Single Block"); //still considering a single, and not a final
//look at each group channel bit -- run this PRIOR to checking private or data calls
//or else we will overwrite the ch bits we set below for private calls with zeroes
//these also seem to indicate data calls -- can't find a distinction of which is which
for (int i = 0; i < 8; i++)
{
ch[i] = state->cap_plus_csbk_bits[i+24];
if (ch[i] == 1) group_tally++; //figure out where to start looking in the byte stream for the 0x80 flag
}
//check for private/data calls -- user will neeed to enable 'data' call tuning in order to tune them
uint8_t pdflag = (uint8_t)ConvertBitIntoBytes(&state->cap_plus_csbk_bits[40+(group_tally*8)], 8); //seems to be 0x80 (last block flag?) on samples I have
uint16_t private_target = 0;
//first, check to see if we have a completed PDU
if (fl == 1 || fl == 3)
{
//then check to see if this byte has a value, should be 0x80
//this bytes location seems to shift depending on level of activity
if (pdflag == 0x80) //now looking to see if any appended data was added
{
k = 0; //= 0
fprintf (stderr, "\n"); fprintf (stderr, "\n");
fprintf (stderr, " F%X Private or Data Call", pdflag);
for (int i = 0; i < 8; i++)
{
pch[i] = state->cap_plus_csbk_bits[i+48+(group_tally*8)];
if (pch[i] == 1)
{
fprintf (stderr, " Ch%d:", i+1);
private_target = (uint16_t)ConvertBitIntoBytes(&state->cap_plus_csbk_bits[56+(k*16)+(group_tally*8)], 16);
fprintf (stderr, " TGT %d;", private_target);
if (opts->trunk_tune_data_calls == 1) t_tg[i] = private_target; //set here for tuning allow/block
k++;
}
}
}
}
//end private/data call check
// if (fl != 2)
if (fl == 1 || fl == 3)
{
fprintf (stderr, "\n ");
k = 0;
for (i = 0; i < 8; i++) for (i = 0; i < 8; i++)
{ {
fprintf (stderr, "Ch%d: ", i+1); fprintf (stderr, "Ch%d: ", i+1);
if (ch[i] != 0) if (ch[i] == 1) //group voice channels
{ {
tg = (uint8_t)ConvertBitIntoBytes(&cs_pdu_bits[k*8+32], 8); tg = (uint8_t)ConvertBitIntoBytes(&state->cap_plus_csbk_bits[k*8+32], 8);
fprintf (stderr, " %03d ", tg); if (tg != 0) fprintf (stderr, " %03d ", tg);
else fprintf (stderr, "Actv ");
//add values to trunking tg/channel potentials //add values to trunking tg/channel potentials
t_tg[i] = tg; t_tg[i] = tg;
k++; if (tg != 0) k++;
} }
else if (pch[i] == 1) //private or data channels
{
fprintf (stderr, "P||D ");
//flag as available for tuning if enabled
if (opts->trunk_tune_data_calls == 1) ch[i] = 1;
}
else if (i+1 == rest_channel) fprintf (stderr, "Rest "); else if (i+1 == rest_channel) fprintf (stderr, "Rest ");
else fprintf (stderr, "Idle "); else fprintf (stderr, "Idle ");
if (i == 3) fprintf (stderr, "\n "); if (i == 3) fprintf (stderr, "\n ");
} }
tghex = (uint32_t)ConvertBitIntoBytes(&cs_pdu_bits[32], 24);
//fprintf (stderr, "\n TG Hex = 0x%06X", tghex);
state->dmr_mfid = 0x10; state->dmr_mfid = 0x10;
sprintf (state->dmr_branding, "%s", "Motorola"); sprintf (state->dmr_branding, "%s", "Motorola");
sprintf (state->dmr_branding_sub, "%s", "Cap+ "); sprintf (state->dmr_branding_sub, "%s", "Cap+ ");
@@ -717,7 +831,7 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8
//Skip tuning group calls if group calls are disabled //Skip tuning group calls if group calls are disabled
if (opts->trunk_tune_group_calls == 0) goto SKIPCAP; if (opts->trunk_tune_group_calls == 0) goto SKIPCAP;
//don't tune if currently a vc on the current channel //don't tune if vc on the current channel
if ( (time(NULL) - state->last_vc_sync_time > 2) ) if ( (time(NULL) - state->last_vc_sync_time > 2) )
{ {
for (j = 0; j < 8; j++) //go through the channels stored looking for active ones to tune to for (j = 0; j < 8; j++) //go through the channels stored looking for active ones to tune to
@@ -737,7 +851,6 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8
} }
} }
//no more 0 reporting, that was some bad code that caused that issue
//without priority, this will tune the first one it finds (if group isn't blocked) //without priority, this will tune the first one it finds (if group isn't blocked)
if (t_tg[j] != 0 && state->p25_cc_freq != 0 && opts->p25_trunk == 1 && (strcmp(mode, "B") != 0) && (strcmp(mode, "DE") != 0)) if (t_tg[j] != 0 && state->p25_cc_freq != 0 && opts->p25_trunk == 1 && (strcmp(mode, "B") != 0) && (strcmp(mode, "DE") != 0))
{ {
@@ -750,6 +863,7 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8
SetFreq(opts->rigctl_sockfd, state->trunk_chan_map[j+1]); SetFreq(opts->rigctl_sockfd, state->trunk_chan_map[j+1]);
state->p25_vc_freq[0] = state->p25_vc_freq[1] = state->trunk_chan_map[j+1]; state->p25_vc_freq[0] = state->p25_vc_freq[1] = state->trunk_chan_map[j+1];
opts->p25_is_tuned = 1; //set to 1 to set as currently tuned so we don't keep tuning nonstop opts->p25_is_tuned = 1; //set to 1 to set as currently tuned so we don't keep tuning nonstop
dmr_reset_blocks (opts, state); //reset all block gathering since we are tuning away
j = 11; //break loop j = 11; //break loop
} }
@@ -759,6 +873,7 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8
rtl_udp_tune (opts, state, state->trunk_chan_map[j+1]); rtl_udp_tune (opts, state, state->trunk_chan_map[j+1]);
state->p25_vc_freq[0] = state->p25_vc_freq[1] = state->trunk_chan_map[j+1]; state->p25_vc_freq[0] = state->p25_vc_freq[1] = state->trunk_chan_map[j+1];
opts->p25_is_tuned = 1; opts->p25_is_tuned = 1;
dmr_reset_blocks (opts, state); //reset all block gathering since we are tuning away
j = 11; //break loop j = 11; //break loop
} }
@@ -766,11 +881,29 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8
} }
} }
} } //end tuning
SKIPCAP: ;
//debug print
if (fl == 1 && opts->payload == 1)
{
fprintf (stderr, "%s\n", KYEL);
fprintf (stderr, " CAP+ Multi Block PDU \n ");
uint8_t fl_bytes = 0;
for (i = 0; i < (10+(block_num*7)); i++)
{
fl_bytes = (uint8_t)ConvertBitIntoBytes(&state->cap_plus_csbk_bits[i*8], 8);
fprintf (stderr, "[%02X]", fl_bytes);
if (i == 17 || i == 35) fprintf (stderr, "\n ");
} }
SKIPCAP: ; //do nothing fprintf (stderr, "%s", KNRM);
} }
memset (state->cap_plus_csbk_bits, 0, sizeof(state->cap_plus_csbk_bits));
state->cap_plus_block_num = 0;
} //if (fl == 1 || fl == 3)
} //opcode == 0x3E
} //fid == 0x10
//Connect+ Section //Connect+ Section
if (csbk_fid == 0x06) if (csbk_fid == 0x06)
@@ -778,13 +911,14 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8
if (csbk_o == 0x01) if (csbk_o == 0x01)
{ {
//initial line break
fprintf (stderr, "\n");
uint8_t nb1 = cs_pdu[2] & 0x3F; uint8_t nb1 = cs_pdu[2] & 0x3F;
uint8_t nb2 = cs_pdu[3] & 0x3F; uint8_t nb2 = cs_pdu[3] & 0x3F;
uint8_t nb3 = cs_pdu[4] & 0x3F; uint8_t nb3 = cs_pdu[4] & 0x3F;
uint8_t nb4 = cs_pdu[5] & 0x3F; uint8_t nb4 = cs_pdu[5] & 0x3F;
uint8_t nb5 = cs_pdu[6] & 0x3F; uint8_t nb5 = cs_pdu[6] & 0x3F;
//initial line break
fprintf (stderr, "\n");
fprintf (stderr, "%s", KYEL); fprintf (stderr, "%s", KYEL);
fprintf (stderr, " Connect Plus Neighbors\n"); fprintf (stderr, " Connect Plus Neighbors\n");
fprintf (stderr, " NB1(%02d), NB2(%02d), NB3(%02d), NB4(%02d), NB5(%02d)", nb1, nb2, nb3, nb4, nb5); fprintf (stderr, " NB1(%02d), NB2(%02d), NB3(%02d), NB4(%02d), NB5(%02d)", nb1, nb2, nb3, nb4, nb5);
@@ -868,6 +1002,7 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8
opts->p25_is_tuned = 1; //set to 1 to set as currently tuned so we don't keep tuning nonstop opts->p25_is_tuned = 1; //set to 1 to set as currently tuned so we don't keep tuning nonstop
state->is_con_plus = 1; //flag on state->is_con_plus = 1; //flag on
state->last_vc_sync_time = time(NULL); //bugfix: set sync here so we don't immediately tune back to CC constantly. state->last_vc_sync_time = time(NULL); //bugfix: set sync here so we don't immediately tune back to CC constantly.
dmr_reset_blocks (opts, state); //reset all block gathering since we are tuning away
} }
//rtl_udp //rtl_udp
@@ -878,6 +1013,7 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8
opts->p25_is_tuned = 1; opts->p25_is_tuned = 1;
state->is_con_plus = 1; //flag on state->is_con_plus = 1; //flag on
state->last_vc_sync_time = time(NULL); //bugfix: set sync here so we don't immediately tune back to CC constantly. state->last_vc_sync_time = time(NULL); //bugfix: set sync here so we don't immediately tune back to CC constantly.
dmr_reset_blocks (opts, state); //reset all block gathering since we are tuning away
} }
} }
@@ -888,71 +1024,209 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8
} }
//upon further examination, opcodes 6 and C (12) do not appear to be a channel grants or tlcs,
//it is present in Connect+, but its purpose isn't entirely clear
//DSDPlus only regards it as a 'CSBK [LB=1 CSBKO=6 (?) FID=06 v1=115213 v2=10488576 v3=0]
//unsure of what the v1 v2 v3 fields specify
// if (csbk_o == 0x06 || csbk_o == 0x0C)
if (csbk_o != 0x01 && csbk_o != 0x03)
{
uint32_t v1 = ( (cs_pdu[2] << 16) + (cs_pdu[3] << 8) + cs_pdu[4] );
uint32_t v2 = ( (cs_pdu[5] << 16) + (cs_pdu[6] << 8) + cs_pdu[7] );
uint32_t v3 = ( (cs_pdu[7] << 16) + (cs_pdu[8] << 8) + cs_pdu[9] );
// debug print
// initial line break
// fprintf (stderr, "\n");
// fprintf (stderr, "%s", KYEL);
// fprintf (stderr, " Connect Plus CSBK 0x%X\n", csbk_o);
// fprintf (stderr, " v1(%d), v2(%d), v3(%d)",v1, v2, v3);
// state->dmr_mfid = 0x06;
// sprintf (state->dmr_branding, "%s", "Motorola");
// sprintf(state->dmr_branding_sub, "Con+ ");
}
//the validity of these last three csbk opcodes cannot be confirmed
//I recall making these based on observation and speculation long ago,
//but cannot verify the accuracy of them now, so they will remain disabled
//they offer no particular interest to trunking/listening
// if (csbk_o == 0x11)
// {
// //initial line break
// fprintf (stderr, "\n");
// fprintf (stderr, "%s", KYEL);
// fprintf (stderr, " Connect Plus Registration Request");
// state->dmr_mfid = 0x06;
// sprintf (state->dmr_branding, "%s", "Motorola");
// sprintf(state->dmr_branding_sub, "Con+ ");
// }
// if (csbk_o == 0x12)
// {
// //initial line break
// fprintf (stderr, "\n");
// fprintf (stderr, "%s", KYEL);
// fprintf (stderr, " Connect Plus Registration Response");
// state->dmr_mfid = 0x06;
// sprintf (state->dmr_branding, "%s", "Motorola");
// sprintf(state->dmr_branding_sub, "Con+ ");
// }
// if (csbk_o == 0x18)
// {
// //initial line break
// fprintf (stderr, "\n");
// fprintf (stderr, "%s", KYEL);
// fprintf (stderr, " Connect Plus Talkgroup Affiliation");
// state->dmr_mfid = 0x06;
// sprintf (state->dmr_branding, "%s", "Motorola");
// sprintf(state->dmr_branding_sub, "Con+ ");
// }
fprintf (stderr, "%s", KNRM); fprintf (stderr, "%s", KNRM);
} //end Connect+
//Hytera XPT
if (csbk_fid == 0x68)
{
//XPT Site Status -- Very Very Experimental, WIP, Don't be surprised by bad decodes or broken trunking
if (csbk_o == 0x0A)
{
//initial line break
fprintf (stderr, "\n");
fprintf (stderr, "%s", KYEL);
uint8_t xpt_ch[6]; //one tg/call per timeslot
uint16_t tg = 0; //8-bit TG value or hash
int i, j;
//tg and channel info for trunking purposes
uint8_t t_tg[24];
memset (t_tg, 0, sizeof(t_tg));
uint8_t xpt_seq = (uint8_t)ConvertBitIntoBytes(&cs_pdu_bits[0], 2); //this replaces the CSBK lb and pf
uint8_t xpt_free = (uint8_t)ConvertBitIntoBytes(&cs_pdu_bits[16], 4); //free repeater channel
uint8_t xpt_bank = 0;
if (xpt_seq) xpt_bank = xpt_seq*6;
//get 2-bit status values for each 6 channels (timeslots)
for (i = 0; i < 6; i++) xpt_ch[i] = (uint8_t)ConvertBitIntoBytes(&cs_pdu_bits[20+(i*2)], 2);
fprintf (stderr, " Hytera XPT Site Status - Free RPT: %d SN: %d\n ", xpt_free+1, xpt_seq);
//Print List of Channels and Activity
for (i = 0; i < 6; i++)
{
fprintf (stderr, "Ch%02d: ", i+xpt_bank+1); //(xpt_seq*6)
tg = (uint8_t)ConvertBitIntoBytes(&cs_pdu_bits[i*8+32], 8);
fprintf (stderr, "ST-%X", xpt_ch[i]); //status bits value 0,1,2, or 3
if (tg != 0) fprintf (stderr, " %03d ", tg);
else
{
if (xpt_ch[i] == 3) fprintf (stderr, " Null "); //offline?, free? but also group call if the TG value is populated? Wut? Null should cover both cases...maybe
else if (xpt_ch[i] == 2) fprintf (stderr, " Priv "); //This seems to be used on both private data and private calls, but one or the other has a 0 TG value?
else if (xpt_ch[i] == 1) fprintf (stderr, " Unk "); //the 01 value has not been observed as of yet, group data?
else if (xpt_ch[i] == 0) fprintf (stderr, " Idle "); //Idle appears to always be a 0, or could indicate Group Data (including status CSBK and VLC/TLC)
} }
if (i == 2) fprintf (stderr, "\n ");
//add values to trunking tg/channel potentials
if (tg != 0) t_tg[i+(xpt_seq*6)] = tg;
}
//add string for ncurses terminal display
sprintf (state->dmr_site_parms, "Free RPT - %d ", xpt_free+1);
//assign to cc freq to follow during no sync
//current theory is that user should set channel 0 as the 'home repeater' frequency
//this can change if this is ever tested by anybody properly
if (state->trunk_chan_map[0] != 0)
{
state->p25_cc_freq = state->trunk_chan_map[0];
//set to always tuned
opts->p25_is_tuned = 1;
}
//Skip tuning calls if group calls are disabled
if (opts->trunk_tune_group_calls == 0) goto SKIPXPT;
//don't tune if vc on the current channel
if ( (time(NULL) - state->last_vc_sync_time > 2) )
{
for (j = 0; j < 6; j++) //go through the channels stored looking for active ones to tune to
{
char mode[8]; //allow, block, digital, enc, etc
//if we are using allow/whitelist mode, then write 'B' to mode for block
//comparison below will look for an 'A' to write to mode if it is allowed
if (opts->trunk_use_allow_list == 1) sprintf (mode, "%s", "B");
//this won't work properly on hashed TGT values
//unless users load a TGT hash in a csv file
//and hope it doesn't clash with other normal TG values
for (int i = 0; i < state->group_tally; i++)
{
if (state->group_array[i].groupNumber == t_tg[j+(xpt_seq*6)])
{
fprintf (stderr, " [%s]", state->group_array[i].groupName);
strcpy (mode, state->group_array[i].groupMode);
}
}
//without priority, this will tune the first one it finds (if group isn't blocked)
if (t_tg[j+(xpt_seq*6)+1] != 0 && state->p25_cc_freq != 0 && opts->p25_trunk == 1 && (strcmp(mode, "B") != 0) && (strcmp(mode, "DE") != 0))
{
if (state->trunk_chan_map[j+(xpt_seq*6)+1] != 0) //if we have a valid frequency
{
//RIGCTL
if (opts->use_rigctl == 1)
{
if (opts->setmod_bw != 0 ) SetModulation(opts->rigctl_sockfd, opts->setmod_bw);
SetFreq(opts->rigctl_sockfd, state->trunk_chan_map[j+(xpt_seq*6)+1]);
state->p25_vc_freq[0] = state->p25_vc_freq[1] = state->trunk_chan_map[j+(xpt_seq*6)+1];
opts->p25_is_tuned = 1; //set to 1 to set as currently tuned so we don't keep tuning nonstop
dmr_reset_blocks (opts, state); //reset all block gathering since we are tuning away
j = 11; //break loop
}
//rtl_udp
else if (opts->audio_in_type == 3)
{
rtl_udp_tune (opts, state, state->trunk_chan_map[j+(xpt_seq*6)+1]);
state->p25_vc_freq[0] = state->p25_vc_freq[1] = state->trunk_chan_map[j+(xpt_seq*6)+1];
opts->p25_is_tuned = 1;
dmr_reset_blocks (opts, state); //reset all block gathering since we are tuning away
j = 11; //break loop
}
}
}
}
} //end tuning
SKIPXPT: ;
sprintf (state->dmr_branding_sub, "XPT ");
//Trunking Note: My understanding is that XPT calls always start on the 'home' repeater, and then expand
//outward to the free repeaters, so its probably easiest for a user to load the frequencies in a csv file
//and let FME scan through them as opposed to actively trunking, it will spend most of the time on the home repeater
//and if calls occur on the home repeater, it'll be too busy with those to go to the free repeater
//DSD-FME doesn't have any sort of TG priority, so its first come first served, just block or allow
} //end 0x0A
//XPT Site Information - Adj Site Info??
if (csbk_o == 0x0B)
{
//initial line break
fprintf (stderr, "\n");
fprintf (stderr, "%s", KYEL);
fprintf (stderr, " Hytera XPT CSBK 0x0B ");
//wraithe's theory -- seems pretty good to me
//still only a theory though until can be verified
//by having a system with precisely known variables
//new samples show this doesn't always quite work, there seems to be
//more than one data set transmitted in this CSBK
//one set works, the other doesn't fit the pattern
// Site ID [5 bits]
// Unknown_3 [3 bits]
// Free Repeater on site [4 bits]
// Unknown_4 [4 bits]
// 11:44:58 Sync: +DMR slot1 [slot2] | Color Code=01 | CSBK
// Hytera XPT CSBK 0x0B
// DMR PDU Payload [0B][68][10][20][18][10][20][10][28][20][EF][DA]
// repeat x3 (for total of 4 sites)
// int i;
// uint8_t xpt_site_id[4];
// uint8_t xpt_site_rp[4];
// uint8_t xpt_site_u1[4];
// uint8_t xpt_site_u2[4];
// for (i = 0; i < 4; i++)
// {
// xpt_site_id[i] = (uint8_t)ConvertBitIntoBytes(&cs_pdu_bits[16+(i*16)], 5);
// xpt_site_u1[i] = (uint8_t)ConvertBitIntoBytes(&cs_pdu_bits[21+(i*16)], 3);
// xpt_site_rp[i] = (uint8_t)ConvertBitIntoBytes(&cs_pdu_bits[24+(i*16)], 4);
// xpt_site_u2[i] = (uint8_t)ConvertBitIntoBytes(&cs_pdu_bits[28+(i*16)], 4);
// }
// fprintf (stderr, " Hytera XPT Site Id: %d - Free RPT: %d", xpt_site_id[0], xpt_site_rp[0]);
// // fprintf (stderr, " RS1: %d RS2: %d", xpt_site_u1[0], xpt_site_u2[1]); //debug
// fprintf (stderr, "\n");
// fprintf (stderr, " XPT Adj Site(s): ");
// for (i = 1; i < 4; i++)
// {
// if (xpt_site_id[i] != 0)
// {
// fprintf (stderr, "%d (%d) ", xpt_site_id[i], xpt_site_rp[i]);
// // fprintf (stderr, "RS1: %d RS2: %d - ", xpt_site_u1[i], xpt_site_u2[i]); //debug
// }
// }
sprintf (state->dmr_branding_sub, "XPT ");
} //end 0x0B
} //end Hytera XPT section
} }
END: END:
fprintf (stderr, "%s", KNRM); fprintf (stderr, "%s", KNRM);

View File

@@ -56,6 +56,7 @@ dmr_data_sync (dsd_opts * opts, dsd_state * state)
{ {
dibit = (int)state->dmr_stereo_payload[i]; dibit = (int)state->dmr_stereo_payload[i];
} }
else state->dmr_stereo_payload[i] = dibit;
cachdata[cachInterleave[(i*2)]] = (1 & (dibit >> 1)); // bit 1 cachdata[cachInterleave[(i*2)]] = (1 & (dibit >> 1)); // bit 1
cachdata[cachInterleave[(i*2)+1]] = (1 & dibit); // bit 0 cachdata[cachInterleave[(i*2)+1]] = (1 & dibit); // bit 0
@@ -75,12 +76,9 @@ dmr_data_sync (dsd_opts * opts, dsd_state * state)
else else
{ {
cach_okay = -1; cach_okay = -1;
if (opts->aggressive_framesync == 1)
{
SlotTypeOk = 0; SlotTypeOk = 0;
goto END; goto END;
} }
}
state->currentslot = tact_bits[1]; state->currentslot = tact_bits[1];
@@ -103,6 +101,7 @@ dmr_data_sync (dsd_opts * opts, dsd_state * state)
{ {
dibit = (int)state->dmr_stereo_payload[i+12]; dibit = (int)state->dmr_stereo_payload[i+12];
} }
else state->dmr_stereo_payload[i+12] = dibit;
info[2*i] = (1 & (dibit >> 1)); // bit 1 info[2*i] = (1 & (dibit >> 1)); // bit 1
info[(2*i)+1] = (1 & dibit); // bit 0 info[(2*i)+1] = (1 & dibit); // bit 0
} }
@@ -118,6 +117,7 @@ dmr_data_sync (dsd_opts * opts, dsd_state * state)
{ {
dibit = (int)state->dmr_stereo_payload[61]; dibit = (int)state->dmr_stereo_payload[61];
} }
else state->dmr_stereo_payload[61] = dibit;
SlotType[0] = (1 & (dibit >> 1)); // bit 1 SlotType[0] = (1 & (dibit >> 1)); // bit 1
SlotType[1] = (1 & dibit); // bit 0 SlotType[1] = (1 & dibit); // bit 0
@@ -132,6 +132,7 @@ dmr_data_sync (dsd_opts * opts, dsd_state * state)
{ {
dibit = (int)state->dmr_stereo_payload[62]; dibit = (int)state->dmr_stereo_payload[62];
} }
else state->dmr_stereo_payload[62] = dibit;
SlotType[2] = (1 & (dibit >> 1)); // bit 1 SlotType[2] = (1 & (dibit >> 1)); // bit 1
SlotType[3] = (1 & dibit); // bit 0 SlotType[3] = (1 & dibit); // bit 0
@@ -146,6 +147,7 @@ dmr_data_sync (dsd_opts * opts, dsd_state * state)
{ {
dibit = (int)state->dmr_stereo_payload[63]; dibit = (int)state->dmr_stereo_payload[63];
} }
else state->dmr_stereo_payload[63] = dibit;
SlotType[4] = (1 & (dibit >> 1)); // bit 1 SlotType[4] = (1 & (dibit >> 1)); // bit 1
SlotType[5] = (1 & dibit); // bit 0 SlotType[5] = (1 & dibit); // bit 0
@@ -160,6 +162,7 @@ dmr_data_sync (dsd_opts * opts, dsd_state * state)
{ {
dibit = (int)state->dmr_stereo_payload[64]; dibit = (int)state->dmr_stereo_payload[64];
} }
else state->dmr_stereo_payload[64] = dibit;
SlotType[6] = (1 & (dibit >> 1)); // bit 1 SlotType[6] = (1 & (dibit >> 1)); // bit 1
SlotType[7] = (1 & dibit); // bit 0 SlotType[7] = (1 & dibit); // bit 0
@@ -175,6 +178,7 @@ dmr_data_sync (dsd_opts * opts, dsd_state * state)
{ {
dibit = (int)state->dmr_stereo_payload[65]; dibit = (int)state->dmr_stereo_payload[65];
} }
else state->dmr_stereo_payload[65] = dibit;
SlotType[8] = (1 & (dibit >> 1)); // bit 1 SlotType[8] = (1 & (dibit >> 1)); // bit 1
SlotType[9] = (1 & dibit); // bit 0 SlotType[9] = (1 & dibit); // bit 0
@@ -191,6 +195,8 @@ dmr_data_sync (dsd_opts * opts, dsd_state * state)
{ {
dibit = (int)state->dmr_stereo_payload[i+66]; dibit = (int)state->dmr_stereo_payload[i+66];
} }
else state->dmr_stereo_payload[i+66] = dibit;
syncdata[2*i] = (1 & (dibit >> 1)); // bit 1 syncdata[2*i] = (1 & (dibit >> 1)); // bit 1
syncdata[(2*i)+1] = (1 & dibit); // bit 0 syncdata[(2*i)+1] = (1 & dibit); // bit 0
sync[i] = (dibit | 1) + 48; sync[i] = (dibit | 1) + 48;
@@ -236,6 +242,7 @@ dmr_data_sync (dsd_opts * opts, dsd_state * state)
if (state->dmr_stereo == 0) if (state->dmr_stereo == 0)
{ {
dibit = getDibit(opts, state); dibit = getDibit(opts, state);
state->dmr_stereo_payload[i+90] = dibit;
} }
if (state->dmr_stereo == 1) if (state->dmr_stereo == 1)
{ {
@@ -252,12 +259,9 @@ dmr_data_sync (dsd_opts * opts, dsd_state * state)
else else
{ {
SlotTypeOk = -1; SlotTypeOk = -1;
if (opts->aggressive_framesync == 1)
{
SlotTypeOk = 0; SlotTypeOk = 0;
goto END; goto END;
} }
}
state->color_code = (SlotType[0] << 3) + (SlotType[1] << 2) +(SlotType[2] << 1) + (SlotType[3] << 0); state->color_code = (SlotType[0] << 3) + (SlotType[1] << 2) +(SlotType[2] << 1) + (SlotType[3] << 0);
state->color_code_ok = SlotTypeOk; state->color_code_ok = SlotTypeOk;
@@ -277,6 +281,7 @@ dmr_data_sync (dsd_opts * opts, dsd_state * state)
if (state->dmr_stereo == 0) if (state->dmr_stereo == 0)
{ {
dibit = getDibit(opts, state); dibit = getDibit(opts, state);
state->dmr_stereo_payload[i+95] = dibit;
} }
if (state->dmr_stereo == 1) if (state->dmr_stereo == 1)
@@ -288,10 +293,11 @@ dmr_data_sync (dsd_opts * opts, dsd_state * state)
info[(2*i) + 99] = (1 & dibit); // bit 0 info[(2*i) + 99] = (1 & dibit); // bit 0
} }
dmr_data_burst_handler(opts, state, (uint8_t *)info, burst); //don't run on MS Reverse Channel Data
if (state->dmr_ms_rc == 0) dmr_data_burst_handler(opts, state, (uint8_t *)info, burst);
//don't run cach on simplex or mono //don't run cach on simplex or mono
if (state->dmr_ms_mode == 0 || opts->dmr_mono == 0) if (state->dmr_ms_mode == 0 && opts->dmr_mono == 0)
{ {
cach_err = dmr_cach (opts, state, cachdata); cach_err = dmr_cach (opts, state, cachdata);
} }

View File

@@ -9,9 +9,11 @@
* 2022-12 DSD-FME Florida Man Edition * 2022-12 DSD-FME Florida Man Edition
*-----------------------------------------------------------------------------*/ *-----------------------------------------------------------------------------*/
//TODO: CRC9 on confirmed data blocks; CRC32 on completed data sf; //WIP: Unified Single Block Data - USBD -- TODO: USBD LIP Protocol Handling
//TODO: Reverse Channel Signalling - RC single burst BPTC/7-bit CRC //WIP: UDT Header and Blocks (coded - need samples)
//TODO: Single Burst Embedded LC - Non-RC single burst LC - Look for Late Entry Alg/Key //WIP: CRC9/CRC32 on Rate 1 Data (need samples)
//WIP: Reverse Channel Signalling - RC single burst BPTC/7-bit CRC (rc interleave) and when to run RC and not SB
//WIP: Single Burst Embedded LC - Non-RC single burst LC - Look for Late Entry Alg/Key
#include "dsd.h" #include "dsd.h"
@@ -26,6 +28,12 @@ void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196
uint8_t slot = state->currentslot; uint8_t slot = state->currentslot;
uint8_t block = state->data_block_counter[slot]; uint8_t block = state->data_block_counter[slot];
//confirmed data
uint8_t dbsn = 0; //data block serial number for confirmed data blocks
uint8_t blockcounter = 0; //local block count
uint8_t confdatabits[250]; //array to reshuffle conf data block bits into sequence for crc9 check
memset (confdatabits, 0, sizeof(confdatabits));
//BPTC 196x96 Specific //BPTC 196x96 Specific
uint8_t BPTCDeInteleavedData[196]; uint8_t BPTCDeInteleavedData[196];
uint8_t BPTCDmrDataBit[96]; uint8_t BPTCDmrDataBit[96];
@@ -37,14 +45,16 @@ void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196
uint8_t LC_DataBytes[10]; uint8_t LC_DataBytes[10];
int Burst = -1; int Burst = -1;
//Unified PDU (is this the best nomenclature) Bytes //PDU Bytes and Bits
uint8_t DMR_PDU[25]; //using 25 bytes as the max for now uint8_t DMR_PDU[25];
uint8_t DMR_PDU_bits[196]; //bitwise version of unified payload, will probably be a lot easier to use this w/ manual uint8_t DMR_PDU_bits[196];
memset (DMR_PDU, 0, sizeof (DMR_PDU)); memset (DMR_PDU, 0, sizeof (DMR_PDU));
memset (DMR_PDU_bits, 0, sizeof (DMR_PDU_bits)); memset (DMR_PDU_bits, 0, sizeof (DMR_PDU_bits));
uint8_t R[3]; uint8_t R[3];
uint8_t BPTCReservedBits = 0; uint8_t BPTCReservedBits = 0;
uint8_t is_ras = 0;
uint8_t crc_original_validity = 0;
uint32_t crcmask = 0; uint32_t crcmask = 0;
uint8_t crclen = 0; uint8_t crclen = 0;
@@ -54,9 +64,12 @@ void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196
uint8_t is_emb = 0; uint8_t is_emb = 0;
uint8_t is_lc = 0; uint8_t is_lc = 0;
uint8_t is_full = 0; uint8_t is_full = 0;
uint8_t is_udt = 0;
uint8_t pdu_len = 0; uint8_t pdu_len = 0;
uint8_t pdu_start = 0; //starting value of pdu (0 normal, 2 for confirmed) uint8_t pdu_start = 0; //starting value of pdu (0 normal, 2 for confirmed)
uint8_t usbd_st = 0; //usbd service type
switch(databurst){ switch(databurst){
case 0x00: //PI case 0x00: //PI
is_bptc = 1; is_bptc = 1;
@@ -108,32 +121,36 @@ void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196
pdu_len = 12; //12 bytes pdu_len = 12; //12 bytes
sprintf(state->fsubtype, " DATA"); sprintf(state->fsubtype, " DATA");
break; break;
//TODO - 1/2 0x0F0 - 3/4 0x1FF - Rate 1 0x10F
//going to set crclen and mask according to confirmed data here,
//use block assmebler to carry out completed message crc
case 0x07: //1/2 Rate Data case 0x07: //1/2 Rate Data
is_bptc = 1; is_bptc = 1;
crclen = 9; //confirmed data only crclen = 9; //confirmed data only
crcmask = 0x0F0; crcmask = 0x0F0;
pdu_len = 12; //12 bytes unconfirmed pdu_len = 12; //12 bytes unconfirmed
sprintf(state->fsubtype, " R12U ");
if (state->data_conf_data[slot] == 1) if (state->data_conf_data[slot] == 1)
{ {
pdu_len = 10; pdu_len = 10;
pdu_start = 2; //start at plus two when assembling pdu_start = 2; //start at plus two when assembling
sprintf(state->fsubtype, " R12C ");
}
if (state->data_header_format[slot] == 0) //UDT 1/2 Encoded Blocks
{
is_udt = 1;
sprintf(state->fsubtype, " UDTC ");
} }
sprintf(state->fsubtype, " R12D ");
break; break;
case 0x08: //3/4 Rate Data case 0x08: //3/4 Rate Data
is_trellis = 1; is_trellis = 1;
crclen = 9; //confirmed data only crclen = 9; //confirmed data only
crcmask = 0x1FF; crcmask = 0x1FF;
pdu_len = 18; //18 bytes unconfirmed pdu_len = 18; //18 bytes unconfirmed
sprintf(state->fsubtype, " R34U ");
if (state->data_conf_data[slot] == 1) if (state->data_conf_data[slot] == 1)
{ {
pdu_len = 16; pdu_len = 16;
pdu_start = 2; //start at plus two when assembling pdu_start = 2; //start at plus two when assembling
sprintf(state->fsubtype, " R34C ");
} }
sprintf(state->fsubtype, " R34D ");
break; break;
case 0x09: //Idle case 0x09: //Idle
//pseudo-random data fill, no need to do anything with this //pseudo-random data fill, no need to do anything with this
@@ -141,33 +158,70 @@ void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196
break; break;
case 0x0A: //1 Rate Data case 0x0A: //1 Rate Data
crclen = 9; //confirmed data only crclen = 9; //confirmed data only
crcmask = 0x1FF; crcmask = 0x10F;
is_full = 1; is_full = 1;
pdu_len = 25; //196 bits - 24.5 bytes pdu_len = 25; //196 bits - 24.5 bytes
sprintf(state->fsubtype, " R_1D "); sprintf(state->fsubtype, " R_1U ");
if (state->data_conf_data[slot] == 1)
{
pdu_len = 23;
pdu_start = 2; //start at plus two when assembling
sprintf(state->fsubtype, " R_1C ");
}
break; break;
case 0x0B: //Unified Data case 0x0B: //Unified Single Block Data USBD
is_bptc = 1; is_bptc = 1;
crclen = 16; crclen = 16;
crcmask = 0x3333; crcmask = 0x3333;
pdu_len = 12; //12 bytes pdu_len = 12; //12 bytes
sprintf(state->fsubtype, " UDAT "); sprintf(state->fsubtype, " USBD ");
break; break;
//special types (not real data 'sync' bursts) //special types (not real data 'sync' bursts)
case 0xEB: //Embedded Signalling case 0xEB: //Embedded Signalling
crclen = 5;
is_emb = 1; is_emb = 1;
pdu_len = 9; pdu_len = 9;
break; break;
default: default:
//Slot Type FEC should catch this so we never see it,
//but if it doesn't, then we can still dump the entire 'packet'
//treat like rate 1 unconfirmed data
is_full = 1;
pdu_len = 25; //196 bits - 24.5 bytes
sprintf(state->fsubtype, " _UNK ");
break; break;
} }
//flag off prop head when not looking at data blocks
if (databurst != 0x6 && databurst != 0x7 && databurst != 0x8 && databurst != 0xA && databurst != 0xB) state->data_p_head[slot] = 0;
if (databurst != 0xEB) if (databurst != 0xEB)
{ {
if (state->dmr_ms_mode == 0) fprintf(stderr, "| Color Code=%02d ", state->dmr_color_code); if (state->dmr_ms_mode == 0) fprintf(stderr, "| Color Code=%02d ", state->dmr_color_code);
fprintf(stderr, "|%s", state->fsubtype); fprintf(stderr, "|%s", state->fsubtype);
//'DSP' output to file
if (opts->use_dsp_output == 1)
{
FILE * pFile; //file pointer
pFile = fopen (opts->dsp_out_file, "a");
fprintf (pFile, "\n%d 98 ", slot+1); //'98' is CACH designation value
for (i = 0; i < 6; i++) //3 byte CACH
{
int cach_byte = (state->dmr_stereo_payload[i*2] << 2) | state->dmr_stereo_payload[i*2 + 1];
fprintf (pFile, "%X", cach_byte); //nibble, not a byte, next time I look at this and wonder why its not %02X
}
fprintf (pFile, "\n%d %02X ", slot+1, databurst); //use hex value of current data burst type
for (i = 6; i < 72; i++) //33 bytes, no CACH
{
int dsp_byte = (state->dmr_stereo_payload[i*2] << 2) | state->dmr_stereo_payload[i*2 + 1];
fprintf (pFile, "%X", dsp_byte);
}
fclose (pFile);
}
} }
//Most Data Sync Burst types will use the bptc 196x96 //Most Data Sync Burst types will use the bptc 196x96
@@ -184,7 +238,10 @@ void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196
IrrecoverableErrors = BPTC_196x96_Extract_Data(BPTCDeInteleavedData, BPTCDmrDataBit, R); IrrecoverableErrors = BPTC_196x96_Extract_Data(BPTCDeInteleavedData, BPTCDmrDataBit, R);
/* Fill the reserved bit (R(0)-R(2) of the BPTC(196,96) block) */ /* Fill the reserved bit (R(0)-R(2) of the BPTC(196,96) block) */
BPTCReservedBits = (R[0] & 0x01) | ((R[1] << 1) & 0x02) | ((R[2] << 2) & 0x08); BPTCReservedBits = (R[0] & 0x01) | ((R[1] << 1) & 0x02) | ((R[2] << 2) & 0x04);
//debug print
//fprintf (stderr, " RAS? %X - %d %d %d", BPTCReservedBits, R[0], R[1], R[2]);
/* Convert the 96 bits BPTC data into 12 bytes */ /* Convert the 96 bits BPTC data into 12 bytes */
k = 0; k = 0;
@@ -213,20 +270,59 @@ void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196
/* Check/correct the BPTC data and compute the Reed-Solomon (12,9) CRC */ /* Check/correct the BPTC data and compute the Reed-Solomon (12,9) CRC */
if (is_lc) CRCCorrect = ComputeAndCorrectFullLinkControlCrc(BPTCDmrDataByte, &CRCComputed, crcmask); if (is_lc) CRCCorrect = ComputeAndCorrectFullLinkControlCrc(BPTCDmrDataByte, &CRCComputed, crcmask);
//TODO: run CRC9 on confirmed 1/2 data blocks //set CRC to correct on unconfirmed 1/2 data blocks (for reporting due to no CRC available on these)
else if (state->data_conf_data[slot] == 1) else if (state->data_conf_data[slot] == 0 && databurst == 0x7)
{ {
//run CRC on individual blocks according to type and validate each individual block CRCComputed = 0;
CRCExtracted = 0;
CRCCorrect = 1;
}
//run CRC9 on intermediate and last 1/2 confirmed data blocks
else if (state->data_conf_data[slot] == 1 && databurst == 0x7)
{
blockcounter = state->data_block_counter[slot]; //current block number according to the counter
dbsn = (uint32_t)ConvertBitIntoBytes(&BPTCDmrDataBit[0], 7) + 1; //recover data block serial number
CRCExtracted = (uint32_t)ConvertBitIntoBytes(&BPTCDmrDataBit[7], 9); //extract CRC from data
CRCExtracted = CRCExtracted ^ crcmask;
//reorganize the BPTCDmrDataBit array into confdatabits, just for CRC9 check
//need to find a sample to confirm this
for(i = 0; i < 80; i++) confdatabits[i] = BPTCDmrDataBit[i + 16];
for(i = 0; i < 7; i++) confdatabits[i + 80] = BPTCDmrDataBit[i];
CRCComputed = ComputeCrc9Bit(confdatabits, 87);
if (CRCExtracted == CRCComputed)
{
CRCCorrect = 1;
state->data_block_crc_valid[slot][blockcounter] = 1;
}
else state->data_block_crc_valid[slot][blockcounter] = 0;
} }
//run CCITT on other data forms //run CCITT on other data forms
else //will still run on unconfirmed data (shouldn't matter other than a possible bogus warning message) else
{ {
CRCComputed = ComputeCrcCCITT(BPTCDmrDataBit); CRCComputed = ComputeCrcCCITT(BPTCDmrDataBit);
if (CRCComputed == CRCExtracted) CRCCorrect = 1; if (CRCComputed == CRCExtracted) CRCCorrect = 1;
else CRCCorrect = 0; else CRCCorrect = 0;
} }
//set the 'RAS Flag', if no irrecoverable errors but bad crc, only when enabled by user (to prevent a lot of bad data CSBKs)
if (opts->aggressive_framesync == 0 && CRCCorrect == 0 && IrrecoverableErrors == 0 && BPTCReservedBits == 4) is_ras = 1;
//make sure the system type isn't Hytera, but could just be bad decodes on bad sample
if (BPTCDmrDataByte[1] == 0x68) is_ras = 0;
//if this is a RAS system, set the CRC to okay if irrecoverable errors are okay
//if we don't do this, then we can't view some data (CSBKs on RAS enabled systems)
if (is_ras == 1)
{
crc_original_validity = CRCCorrect;
CRCCorrect = 1;
}
if (databurst == 0x04 || databurst == 0x06) //MBC Header, Data Header if (databurst == 0x04 || databurst == 0x06) //MBC Header, Data Header
{ {
if (CRCCorrect) if (CRCCorrect)
@@ -249,7 +345,7 @@ void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196
BPTCDmrDataBit[j + 7] = (BPTCDmrDataByte[i+pdu_start] >> 0) & 0x01; BPTCDmrDataBit[j + 7] = (BPTCDmrDataByte[i+pdu_start] >> 0) & 0x01;
} }
//convert to unified DMR_PDU and DMR_PDU_bits //convert to DMR_PDU and DMR_PDU_bits
for (i = 0; i < pdu_len; i++) for (i = 0; i < pdu_len; i++)
{ {
DMR_PDU[i] = BPTCDmrDataByte[i+pdu_start]; DMR_PDU[i] = BPTCDmrDataByte[i+pdu_start];
@@ -295,11 +391,7 @@ void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196
IrrecoverableErrors = BPTC_128x77_Extract_Data(BptcDataMatrix, LC_DataBit); IrrecoverableErrors = BPTC_128x77_Extract_Data(BptcDataMatrix, LC_DataBit);
/* Reconstitute the 5 bit CRC */ /* Reconstitute the 5 bit CRC */
CRCExtracted = (LC_DataBit[72] & 1) << 4; CRCExtracted = (uint32_t)ConvertBitIntoBytes(&LC_DataBit[72], 5);
CRCExtracted |= (LC_DataBit[73] & 1) << 3;
CRCExtracted |= (LC_DataBit[74] & 1) << 2;
CRCExtracted |= (LC_DataBit[75] & 1) << 1;
CRCExtracted |= (LC_DataBit[76] & 1) << 0;
/* Compute the 5 bit CRC */ /* Compute the 5 bit CRC */
CRCComputed = ComputeCrc5Bit(LC_DataBit); CRCComputed = ComputeCrc5Bit(LC_DataBit);
@@ -348,6 +440,50 @@ void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196
DMR_PDU[i] = (uint8_t)TrellisReturn[i+pdu_start]; DMR_PDU[i] = (uint8_t)TrellisReturn[i+pdu_start];
} }
for(i = 0, j = 0; i < 18; i++, j+=8)
{
DMR_PDU_bits[j + 0] = (TrellisReturn[i] >> 7) & 0x01;
DMR_PDU_bits[j + 1] = (TrellisReturn[i] >> 6) & 0x01;
DMR_PDU_bits[j + 2] = (TrellisReturn[i] >> 5) & 0x01;
DMR_PDU_bits[j + 3] = (TrellisReturn[i] >> 4) & 0x01;
DMR_PDU_bits[j + 4] = (TrellisReturn[i] >> 3) & 0x01;
DMR_PDU_bits[j + 5] = (TrellisReturn[i] >> 2) & 0x01;
DMR_PDU_bits[j + 6] = (TrellisReturn[i] >> 1) & 0x01;
DMR_PDU_bits[j + 7] = (TrellisReturn[i] >> 0) & 0x01;
}
//set CRC to correct on unconfirmed 3/4 data blocks (for reporting due to no CRC available on these)
if (state->data_conf_data[slot] == 0) CRCCorrect = 1;
//run CRC9 on intermediate and last 3/4 data blocks
else if (state->data_conf_data[slot] == 1)
{
blockcounter = state->data_block_counter[slot]; //current block number according to the counter
dbsn = (uint32_t)ConvertBitIntoBytes(&DMR_PDU_bits[0], 7) + 1; //recover data block serial number
CRCExtracted = (uint32_t)ConvertBitIntoBytes(&DMR_PDU_bits[7], 9); //extract CRC from data
CRCExtracted = CRCExtracted ^ crcmask;
//reorganize the DMR_PDU_bits array into confdatabits, just for CRC9 check
//confirmed working now!
for(i = 0; i < 128; i++) confdatabits[i] = DMR_PDU_bits[i + 16];
for(i = 0; i < 7; i++) confdatabits[i + 128] = DMR_PDU_bits[i];
CRCComputed = ComputeCrc9Bit(confdatabits, 135);
if (CRCExtracted == CRCComputed)
{
CRCCorrect = 1;
state->data_block_crc_valid[slot][blockcounter] = 1;
}
else
{
// IrrecoverableErrors = 9; //set as a shim since the trellis decoder is a pain to fix
state->data_block_crc_valid[slot][blockcounter] = 0;
}
}
//reorganize the DMR_PDU_bits into PDU friendly format (minus the dbsn and crc9)
memset (DMR_PDU_bits, 0, sizeof(DMR_PDU_bits));
for(i = 0, j = 0; i < pdu_len; i++, j+=8) for(i = 0, j = 0; i < pdu_len; i++, j+=8)
{ {
DMR_PDU_bits[j + 0] = (TrellisReturn[i+pdu_start] >> 7) & 0x01; DMR_PDU_bits[j + 0] = (TrellisReturn[i+pdu_start] >> 7) & 0x01;
@@ -360,17 +496,13 @@ void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196
DMR_PDU_bits[j + 7] = (TrellisReturn[i+pdu_start] >> 0) & 0x01; DMR_PDU_bits[j + 7] = (TrellisReturn[i+pdu_start] >> 0) & 0x01;
} }
//TODO: run CRC9 on confirmed 3/4 data blocks
} }
if (is_full) //Rate 1 Data if (is_full) //Rate 1 Data
{ {
CRCExtracted = 0; CRCExtracted = 0;
CRCComputed = 0; CRCComputed = 0;
IrrecoverableErrors = 0; IrrecoverableErrors = 0; //implicit, since there is no encoding
//TODO: run CRC9 on confirmed data
for (i = 0; i < 24; i++) for (i = 0; i < 24; i++)
{ {
@@ -381,6 +513,32 @@ void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196
DMR_PDU[25] = (uint8_t)ConvertBitIntoBytes(&info[192], 4); DMR_PDU[25] = (uint8_t)ConvertBitIntoBytes(&info[192], 4);
DMR_PDU[25] = DMR_PDU[25] << 4; DMR_PDU[25] = DMR_PDU[25] << 4;
//set CRC to correct on unconfirmed 1 rate data blocks (for reporting due to no CRC available on these)
if (state->data_conf_data[slot] == 0) CRCCorrect = 1;
//run CRC9 on intermediate and last 1 rate data blocks
else if (state->data_conf_data[slot] == 1)
{
blockcounter = state->data_block_counter[slot]; //current block number according to the counter
dbsn = (uint32_t)ConvertBitIntoBytes(&info[0], 7) + 1; //recover data block serial number
CRCExtracted = (uint32_t)ConvertBitIntoBytes(&info[7], 9); //extract CRC from data
CRCExtracted = CRCExtracted ^ crcmask;
//reorganize the info bit array into confdatabits, just for CRC9 check
//unconfirmed, haven't seen any samples with rate 1 data
for(i = 0; i < 176; i++) confdatabits[i] = info[i + 16];
for(i = 0; i < 7; i++) confdatabits[i + 176] = info[i];
CRCComputed = ComputeCrc9Bit(confdatabits, 183);
if (CRCExtracted == CRCComputed)
{
CRCCorrect = 1;
state->data_block_crc_valid[slot][blockcounter] = 1;
}
else state->data_block_crc_valid[slot][blockcounter] = 0;
}
//copy info to dmr_pdu_bits //copy info to dmr_pdu_bits
memcpy(DMR_PDU_bits, info, sizeof(DMR_PDU_bits)); memcpy(DMR_PDU_bits, info, sizeof(DMR_PDU_bits));
@@ -395,27 +553,75 @@ void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196
if (databurst == 0x02) dmr_flco (opts, state, DMR_PDU_bits, CRCCorrect, IrrecoverableErrors, 2); //TLC if (databurst == 0x02) dmr_flco (opts, state, DMR_PDU_bits, CRCCorrect, IrrecoverableErrors, 2); //TLC
if (databurst == 0xEB) dmr_flco (opts, state, DMR_PDU_bits, CRCCorrect, IrrecoverableErrors, 3); //EMB if (databurst == 0xEB) dmr_flco (opts, state, DMR_PDU_bits, CRCCorrect, IrrecoverableErrors, 3); //EMB
//dmr data header and multi block types (header, 1/2, 3/4, 1, Unified) - type 1 //dmr data header and multi block types (header, 1/2, 3/4, 1, UDT) - type 1
if (databurst == 0x06) dmr_dheader (opts, state, DMR_PDU, CRCCorrect, IrrecoverableErrors); if (databurst == 0x06) dmr_dheader (opts, state, DMR_PDU, DMR_PDU_bits, CRCCorrect, IrrecoverableErrors);
if (databurst == 0x07) dmr_block_assembler (opts, state, DMR_PDU, pdu_len, databurst, 1); //1/2 Rate Data
if (databurst == 0x08) dmr_block_assembler (opts, state, DMR_PDU, pdu_len, databurst, 1); //3/4 Rate Data if (databurst == 0x08) dmr_block_assembler (opts, state, DMR_PDU, pdu_len, databurst, 1); //3/4 Rate Data
//if (databurst == 0x0A) dmr_block_assembler (opts, state, DMR_PDU, pdu_len, databurst, 1); //Full Rate Data - Disabled until further testing can be done if (databurst == 0x0A) dmr_block_assembler (opts, state, DMR_PDU, pdu_len, databurst, 1); //Full Rate Data
if (databurst == 0x07 && is_udt == 0) dmr_block_assembler (opts, state, DMR_PDU, pdu_len, databurst, 1); //1/2 Rate Data
if (databurst == 0x07 && is_udt == 1) dmr_block_assembler (opts, state, DMR_PDU, pdu_len, databurst, 3); //UDT with 1/2 Rate Encoding
//is unified data handled like normal data, or control signalling data? //control signalling types (CSBK, MBC)
if (databurst == 0x0B) dmr_block_assembler (opts, state, DMR_PDU, pdu_len, databurst, 1); //Unified Data
//if (databurst == 0x0B) dmr_cspdu (opts, state, DMR_PDU_bits, DMR_PDU, CRCCorrect, IrrecoverableErrors);
//control signalling types (CSBK, MBC, UDT)
if (databurst == 0x03) dmr_cspdu (opts, state, DMR_PDU_bits, DMR_PDU, CRCCorrect, IrrecoverableErrors); if (databurst == 0x03) dmr_cspdu (opts, state, DMR_PDU_bits, DMR_PDU, CRCCorrect, IrrecoverableErrors);
//both MBC header and MBC continuation will go to the block_assembler - type 2, and then to dmr_cspdu //both MBC header and MBC continuation will go to the block_assembler - type 2, and then to dmr_cspdu
if (databurst == 0x04) if (databurst == 0x04)
{ {
state->data_block_counter[slot] = 0; //zero block counter before running header state->data_block_counter[slot] = 0; //zero block counter before running header
state->data_header_valid[slot] = 1; //set valid header since we received one
dmr_block_assembler (opts, state, DMR_PDU, pdu_len, databurst, 2); dmr_block_assembler (opts, state, DMR_PDU, pdu_len, databurst, 2);
} }
if (databurst == 0x05) dmr_block_assembler (opts, state, DMR_PDU, pdu_len, databurst, 2); if (databurst == 0x05) dmr_block_assembler (opts, state, DMR_PDU, pdu_len, databurst, 2);
//Unified Single Data Block (USBD) -- Not to be confused with Unified Data Transport (UDT)
if (databurst == 0x0B)
{
//TODO: provide more robust handling at a later date -- ETSI TS 102 361-4 V1.11.1 (2021-01) 6.6.11.3
usbd_st = (uint8_t)ConvertBitIntoBytes(&DMR_PDU_bits[0], 4);
fprintf (stderr, "%s\n", KYEL);
fprintf (stderr, " Unified Single Block Data - ");
if (usbd_st == 0) fprintf (stderr, "Location Information Protocol");
else if (usbd_st > 8) fprintf (stderr, "Manufacturer Specific Service %d ", usbd_st);
else fprintf (stderr, "Reserved %d ", usbd_st);
}
//set the original CRCCorrect back to its original value if the RAS flag was tripped
if (is_ras == 1) CRCCorrect = crc_original_validity;
//start printing relevant fec/crc/ras messages, don't print on idle or MBC continuation blocks (handled in dmr_block.c)
if (IrrecoverableErrors == 0 && CRCCorrect == 1 && databurst != 0x09 && databurst != 0x05) ; //fprintf(stderr, "(CRC OK)");
// if (IrrecoverableErrors == 0 && CRCCorrect == 0 && databurst != 0x09 && databurst != 0x05)
// {
// fprintf (stderr, "%s", KYEL);
// fprintf(stderr, " (FEC OK)");
// fprintf (stderr, "%s", KNRM);
// }
if (IrrecoverableErrors != 0 && databurst != 0x09) //&& databurst != 0x05
{
fprintf (stderr, "%s", KRED);
fprintf(stderr, " (FEC ERR)");
fprintf (stderr, "%s", KNRM);
}
//print whether or not the 'RAS Field' bits are set to indicate RAS enabled (to be verified)
if (is_ras == 1)
{
fprintf (stderr, "%s", KRED);
fprintf (stderr, " -RAS ");
//the value of this field seems to always, or usually, be 4, or just R[2] bit is set
if (opts->payload == 1) fprintf (stderr, "%X ", BPTCReservedBits);
fprintf (stderr, "%s", KNRM);
}
if (IrrecoverableErrors == 0 && CRCCorrect == 0 && is_ras == 0 && databurst != 0x09 && databurst != 0x05)
{
fprintf (stderr, "%s", KRED);
fprintf (stderr, " (CRC ERR) ");
fprintf (stderr, "%s", KNRM);
}
//print the unified PDU format here, if not slot idle //print the unified PDU format here, if not slot idle
if (opts->payload == 1 && databurst != 0x09) if (opts->payload == 1 && databurst != 0x09)
{ {
@@ -427,20 +633,12 @@ void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196
fprintf (stderr, "[%02X]", DMR_PDU[i]); fprintf (stderr, "[%02X]", DMR_PDU[i]);
} }
fprintf (stderr, "%s", KNRM); //debug print
// if (dbsn) fprintf (stderr, " SN %X", dbsn);
// fprintf (stderr, "%s", KCYN); // fprintf (stderr, " CRC - EXT %X CMP %X", CRCExtracted, CRCComputed);
// fprintf (stderr, "\n Hex to Ascii - ");
// for (i = 0; i < 12; i++)
// {
// if (DMR_PDU[i] <= 0x7E && DMR_PDU[i] >=0x20)
// {
// fprintf (stderr, "%c", DMR_PDU[i]);
// }
// else fprintf (stderr, ".");
// }
fprintf (stderr, "%s", KNRM); fprintf (stderr, "%s", KNRM);
} }
} }

View File

@@ -25,73 +25,280 @@ void dmr_flco (dsd_opts * opts, dsd_state * state, uint8_t lc_bits[], uint32_t C
uint8_t so = 0; uint8_t so = 0;
uint32_t target = 0; uint32_t target = 0;
uint32_t source = 0; uint32_t source = 0;
uint8_t capsite = 0;
int restchannel = -1; int restchannel = -1;
int is_cap_plus = 0; int is_cap_plus = 0;
int is_alias = 0; int is_alias = 0;
int is_gps = 0; int is_gps = 0;
//XPT 'Things'
int is_xpt = 0;
uint8_t xpt_hand = 0; //handshake
uint8_t xpt_free = 0; //free repeater
uint8_t xpt_int = 0; //xpt channel to interrupt (channel/repeater call should occur on?)
uint8_t xpt_res_a = 0; //unknown values of other bits of the XPT LC
uint8_t xpt_res_b = 0; //unknown values of other bits of the XPT LC
uint8_t xpt_res_c = 0; //unknown values of other bits of the XPT LC
uint8_t target_hash[24]; //for XPT (and others if desired, get the hash and compare against SLC or XPT Status CSBKs)
uint8_t tg_hash = 0; //value of the hashed TG
uint8_t slot = state->currentslot; uint8_t slot = state->currentslot;
uint8_t unk = 0; //flag for unknown FLCO + FID combo
pf = (uint8_t)(lc_bits[0]); //Protect Flag -- Hytera XPT uses this to signify which TS the PDU is on
pf = (uint8_t)(lc_bits[0]); //Protect Flag reserved = (uint8_t)(lc_bits[1]); //Reserved -- Hytera XPT G/I bit; 0 - Individual; 1 - Group;
reserved = (uint8_t)(lc_bits[1]); //Reserved
flco = (uint8_t)ConvertBitIntoBytes(&lc_bits[2], 6); //Full Link Control Opcode flco = (uint8_t)ConvertBitIntoBytes(&lc_bits[2], 6); //Full Link Control Opcode
fid = (uint8_t)ConvertBitIntoBytes(&lc_bits[8], 8); //Feature set ID (FID) fid = (uint8_t)ConvertBitIntoBytes(&lc_bits[8], 8); //Feature set ID (FID)
so = (uint8_t)ConvertBitIntoBytes(&lc_bits[16], 8); //Service Options so = (uint8_t)ConvertBitIntoBytes(&lc_bits[16], 8); //Service Options
target = (uint32_t)ConvertBitIntoBytes(&lc_bits[24], 24); //Target or Talk Group target = (uint32_t)ConvertBitIntoBytes(&lc_bits[24], 24); //Target or Talk Group
source = (uint32_t)ConvertBitIntoBytes(&lc_bits[48], 24); source = (uint32_t)ConvertBitIntoBytes(&lc_bits[48], 24);
//look for Cap+ on VLC header, then set source and/or rest channel appropriately //read ahead a little to get this for the xpt flag
if (type == 1 && fid == 0x10 && flco == 0x04) if (IrrecoverableErrors == 0 && flco == 0x09 && fid == 0x68)
{ {
is_cap_plus = 1; sprintf (state->dmr_branding, "%s", " Hytera");
restchannel = (int)ConvertBitIntoBytes(&lc_bits[48], 8); sprintf (state->dmr_branding_sub, "XPT ");
source = (uint32_t)ConvertBitIntoBytes(&lc_bits[56], 16);
sprintf (state->dmr_branding, "%s", "Motorola");
sprintf (state->dmr_branding_sub, "%s", "Cap+ ");
} }
//look at the dmr_branding_sub for the XPT string
//branding sub is set at CSBK(68-3A and 3B), SLCO 8, and here on 0x09
if (strcmp (state->dmr_branding_sub, "XPT ") == 0) is_xpt = 1;
//hytera XPT -- disable the pf flag, is used for TS value in some Hytera XPT PDUs
if (is_xpt) pf = 0;
//check protect flag
if (pf == 1)
{
if (type == 1) fprintf (stderr, "%s \n", KRED);
if (type == 2) fprintf (stderr, "%s \n", KRED);
if (type == 3) fprintf (stderr, "%s", KRED);
fprintf (stderr, " SLOT %d", state->currentslot+1);
fprintf (stderr, " Protected LC ");
goto END_FLCO;
}
if (IrrecoverableErrors == 0) if (IrrecoverableErrors == 0)
{ {
if (slot == 0) state->dmr_flco = flco;
else state->dmr_flcoR = flco;
//Embedded Talker Alias Header Only (format and len storage) //Embedded Talker Alias Header Only (format and len storage)
if (type == 3 && flco == 0x04) if ( (fid == 0 || fid == 0x68) && type == 3 && flco == 0x04)
{ {
dmr_embedded_alias_header(opts, state, lc_bits); dmr_embedded_alias_header(opts, state, lc_bits);
} }
//Embedded Talker Alias Header (continuation) and Blocks //Embedded Talker Alias Header (continuation) and Blocks
if (type == 3 && flco > 0x3 && flco < 0x08) if ( (fid == 0 || fid == 0x68) && type == 3 && flco > 0x03 && flco < 0x08)
{ {
is_alias = 1; is_alias = 1;
dmr_embedded_alias_blocks(opts, state, lc_bits); dmr_embedded_alias_blocks(opts, state, lc_bits);
} }
//Embedded GPS //Embedded GPS
if (type == 3 && flco == 0x08) if ( (fid == 0 || fid == 0x68) && fid == 0 && type == 3 && flco == 0x08)
{ {
is_gps = 1; is_gps = 1;
if (fid == 0) dmr_embedded_gps(opts, state, lc_bits); //issues with fid 0x10 and flco 0x08 dmr_embedded_gps(opts, state, lc_bits);
//NOTE: fid 0x10 and flco 0x08 produces a lot of 'zero' lat or lon values, I don't believe this is embedded gps
//this has been observed to happen often on CapMax systems, so I believe it could be some CapMax 'thing'
//Unknown Link Control - FLCO=0x08 FID=0x10 SVC=0xC1 or FLCO=0x08 FID=0x10 SVC=0xC0 <-- have the enc bit set on svc, but these calls aren't enc?
//is this an encrypted embedded link control?
else
{
fprintf (stderr, "%s", KGRN);
fprintf (stderr, " Slot %d Unknown EMB LC - FLCO=0x%02X FID=0x%02X SVC=0x%02X ", slot+1, flco, fid, so);
fprintf (stderr, "%s", KNRM);
} }
//look for Cap+ on VLC header, then set source and/or rest channel appropriately
if (type == 1 && fid == 0x10 && (flco == 0x04 || flco == 0x07) ) //0x07 appears to be a cap+ txi private call
{
is_cap_plus = 1;
capsite = (uint8_t)ConvertBitIntoBytes(&lc_bits[48], 4); //don't believe so
restchannel = (int)ConvertBitIntoBytes(&lc_bits[52], 4); //
source = (uint32_t)ConvertBitIntoBytes(&lc_bits[56], 16);
}
//Unknown CapMax/Moto Things -- 0x14, 0x15, 0x16 are new ones on emb
if (fid == 0x10 && (flco == 0x08 || flco == 0x28 || flco == 0x14 || flco == 0x15 || flco == 0x16))
{
//NOTE: fid 0x10 and flco 0x08 (emb) produces a lot of 'zero' bytes
//this has been observed to happen often on CapMax systems, so I believe it could be some CapMax 'thing'
//Unknown Link Control - FLCO=0x08 FID=0x10 SVC=0xC1 or FLCO=0x08 FID=0x10 SVC=0xC0 <- probably no SVC bits in the lc
//flco 0x28 has also been observed lately but the tg and src values don't match
//another flco 0x10 does seem to match, so is probably capmax group call flco
if (type == 1) fprintf (stderr, "%s \n", KCYN);
if (type == 2) fprintf (stderr, "%s \n", KCYN);
if (type == 3) fprintf (stderr, "%s", KCYN);
fprintf (stderr, " SLOT %d", state->currentslot+1);
fprintf (stderr, " Motorola");
unk = 1;
goto END_FLCO;
}
//7.1.1.1 Terminator Data Link Control PDU - ETSI TS 102 361-3 V1.2.1 (2013-07)
if (type == 2 && flco == 0x30)
{
fprintf (stderr, "%s \n", KRED);
fprintf (stderr, " SLOT %d", state->currentslot+1);
fprintf (stderr, " Data Terminator (TD_LC) ");
fprintf (stderr, "%s", KNRM);
//reset data header format storage
state->data_header_format[slot] = 7;
//flag off data header validity
state->data_header_valid[slot] = 0;
//flag off conf data flag
state->data_conf_data[slot] = 0;
goto END_FLCO;
}
//Unknown Tait Things
if (fid == 0x58)
{
//NOTE: fid 0x58 (tait) had a single flco 0x06 emb observed, but without the other blocks (4,5,7) for an alias
//will need to observe this one, or just remove it from the list, going to isolate tait lc for now
if (type == 1) fprintf (stderr, "%s \n", KCYN);
if (type == 2) fprintf (stderr, "%s \n", KCYN);
if (type == 3) fprintf (stderr, "%s", KCYN);
fprintf (stderr, " SLOT %d", state->currentslot+1);
fprintf (stderr, " Tait");
unk = 1;
goto END_FLCO;
}
//look for any Hytera XPT system, adjust TG to 16-bit allocation
//Groups use only 8 out of 16, but 16 always seems to be allocated
//private calls use 16-bit target values hased to 8-bit in the site status csbk
//the TLC preceeds the VLC for a 'handshake' call setup in XPT
//truncate if XPT is set
if (is_xpt == 1)
{
target = (uint32_t)ConvertBitIntoBytes(&lc_bits[32], 16); //16-bit allocation
source = (uint32_t)ConvertBitIntoBytes(&lc_bits[56], 16); //16-bit allocation
//the crc8 hash is the value represented in the CSBK when dealing with private calls
for (int i = 0; i < 16; i++) target_hash[i] = lc_bits[32+i];
tg_hash = crc8 (target_hash, 16);
}
//XPT Call 'Grant' Setup Occurs in TLC (TermLC Handshake) with a flco 0x09
if (fid == 0x68 && flco == 0x09)
{
//The CSBK always uses an 8-bit TG; The White Papers (user manuals) say 8-bit TG and 16-bit SRC addressing
//It seems that private calls and indiv data calls use a hash of their 8 bit tgt values in the CSBK
xpt_free = (uint8_t)ConvertBitIntoBytes(&lc_bits[24], 4); //24 and 4 on 0x09
xpt_hand = (uint8_t)ConvertBitIntoBytes(&lc_bits[28], 4); //handshake kind: 0 - ordinary; 1-2 Interrupts; 3-15 reserved;
target = (uint32_t)ConvertBitIntoBytes(&lc_bits[32], 16); //16-bit allocation
source = (uint32_t)ConvertBitIntoBytes(&lc_bits[56], 16); //16-bit allocation
//the bits that are left behind
xpt_res_a = (uint8_t)ConvertBitIntoBytes(&lc_bits[16], 8); //Where the SVC bits would usually be
xpt_res_b = (uint8_t)ConvertBitIntoBytes(&lc_bits[48], 8); //where the first 8 bits of the SRC would be
xpt_res_c = (uint8_t)ConvertBitIntoBytes(&lc_bits[72], 8); //some unknown 8 bit value after the SRC
//speculation: 16,4 may be the current repeater channel this call will occur on? or the channel to interrupt?, could also be 8 bits?
xpt_int = (uint8_t)ConvertBitIntoBytes(&lc_bits[16], 4);
//the crc8 hash is the value represented in the CSBK when dealing with private calls
for (int i = 0; i < 16; i++) target_hash[i] = lc_bits[32+i];
tg_hash = crc8 (target_hash, 16); //This is a different poly, but using as placeholder
fprintf (stderr, "%s \n", KGRN);
fprintf (stderr, " SLOT %d ", state->currentslot+1);
fprintf(stderr, "TGT=%u SRC=%u ", target, source);
// Here are some of the RIDs with hash address seen in that sample:
// 930 = 88
// 9317 = 198
// 10002 = 187
if (opts->payload == 1) fprintf(stderr, "HASH=%d ", tg_hash);
// if (opts->payload == 1) fprintf(stderr, "HSK [%X] ", xpt_hand);
if (opts->payload == 1) fprintf(stderr, "CH=%X ", xpt_int+1); //repeater channel to 'interrupt' with this call?
if (opts->payload == 1) fprintf(stderr, "FLCO=0x%02X FID=0x%02X ", flco, fid);
// if (opts->payload == 1) fprintf(stderr, "RS [%02X][%02X][%02X] ", xpt_res_a, xpt_res_b, xpt_res_c);
fprintf (stderr, "Hytera XPT ");
if (reserved == 1) fprintf (stderr, "Group "); //according to observation
else fprintf (stderr, "Private "); //according to observation
fprintf (stderr, "Call Protect ");
fprintf (stderr, "%s", KYEL);
fprintf (stderr, "F-Rpt %d", xpt_free+1);
fprintf (stderr, "%s ", KNRM);
//add string for ncurses terminal display
sprintf (state->dmr_site_parms, "Free RPT - %d ", xpt_free+1);
is_xpt = 1;
goto END_FLCO;
}
//XPT 'Handshake' -- not observed as of yet on any samples
if ( fid == 0x68 && (flco == 0x2E || flco == 0x2F) )
{
//all below is according to the patent, but never observed on any samples I have
target = (uint32_t)ConvertBitIntoBytes(&lc_bits[24], 24); //24-bit values according to patent
source = (uint32_t)ConvertBitIntoBytes(&lc_bits[56], 24); //24-bit values according to patent
xpt_free = (uint8_t)ConvertBitIntoBytes(&lc_bits[16], 4); //16 and 4 on 2E and 2F
xpt_hand = (uint8_t)ConvertBitIntoBytes(&lc_bits[20], 4); //handshake kind: 0 - ordinary; 1-2 Interrupts; 3-15 reserved;
xpt_int = (uint8_t)ConvertBitIntoBytes(&lc_bits[24], 8); //Interrupt Designated Channel (No idea?)
fprintf (stderr, "%s \n", KGRN);
fprintf (stderr, " SLOT %d ", state->currentslot+1);
fprintf(stderr, "TGT=%u SRC=%u ", target, source);
if (opts->payload == 1) fprintf(stderr, "HASH=%d ", tg_hash);
// if (opts->payload == 1) fprintf(stderr, "HSK=[%X] ", xpt_hand);
if (opts->payload == 1) fprintf(stderr, "FLCO=0x%02X FID=0x%02X ", flco, fid);
fprintf (stderr, "Hytera XPT ");
if (reserved == 1) fprintf (stderr, "Group ");
else fprintf (stderr, "Private ");
fprintf (stderr, "Call ");
if (flco == 0x2E) fprintf (stderr, "Request ");
if (flco == 0x2F) fprintf (stderr, "Response ");
fprintf (stderr, "%s ", KNRM);
is_xpt = 1;
goto END_FLCO;
}
//Hytera XPT "something" -- seen on Embedded
if (fid == 0x68 && flco == 0x13)
{
if (type == 1) fprintf (stderr, "%s \n", KCYN);
if (type == 2) fprintf (stderr, "%s \n", KCYN);
if (type == 3) fprintf (stderr, "%s", KCYN);
fprintf (stderr, " SLOT %d", state->currentslot+1);
fprintf (stderr, " Hytera ");
unk = 1;
goto END_FLCO;
}
//unknown other manufacturer or OTA ENC, etc.
//removed tait from the list, added hytera 0x08
if (fid != 0 && fid != 0x68 && fid != 0x10 && fid != 0x08)
{
if (type == 1) fprintf (stderr, "%s \n", KYEL);
if (type == 2) fprintf (stderr, "%s \n", KYEL);
if (type == 3) fprintf (stderr, "%s", KYEL);
fprintf (stderr, " SLOT %d", state->currentslot+1);
fprintf (stderr, " Unknown LC ");
unk = 1;
goto END_FLCO;
} }
} }
//will want to continue to observe for different flco and fid combinations to find out their meaning //will want to continue to observe for different flco and fid combinations to find out their meaning
//Standard Addressing/Cap+ Addressing (trying to avoid embedded alias and gps, etc)
if(IrrecoverableErrors == 0 && is_alias == 0 && is_gps == 0) if(IrrecoverableErrors == 0 && is_alias == 0 && is_gps == 0)
{ {
//set overarching manufacturer in use when non-standard feature id set is up //set overarching manufacturer in use when non-standard feature id set is up
//may not want to set moto 0x10 here either, lots of radios use that set as well
if (fid != 0) state->dmr_mfid = fid; if (fid != 0) state->dmr_mfid = fid;
if (type != 2) //VLC and EMB, set our target, source, so, and fid per channel if (type != 2) //VLC and EMB, set our target, source, so, and fid per channel
@@ -131,6 +338,7 @@ void dmr_flco (dsd_opts * opts, dsd_state * state, uint8_t lc_bits[], uint32_t C
// state->lastsrc = 0; // state->lastsrc = 0;
state->payload_algid = 0; state->payload_algid = 0;
state->payload_mi = 0; state->payload_mi = 0;
state->payload_keyid = 0;
} }
if (state->currentslot == 1) if (state->currentslot == 1)
{ {
@@ -140,6 +348,7 @@ void dmr_flco (dsd_opts * opts, dsd_state * state, uint8_t lc_bits[], uint32_t C
// state->lastsrcR = 0; // state->lastsrcR = 0;
state->payload_algidR = 0; state->payload_algidR = 0;
state->payload_miR = 0; state->payload_miR = 0;
state->payload_keyidR = 0;
} }
} }
@@ -160,14 +369,38 @@ void dmr_flco (dsd_opts * opts, dsd_state * state, uint8_t lc_bits[], uint32_t C
fprintf (stderr, " SLOT %d ", state->currentslot+1); fprintf (stderr, " SLOT %d ", state->currentslot+1);
fprintf(stderr, "TGT=%u SRC=%u ", target, source); fprintf(stderr, "TGT=%u SRC=%u ", target, source);
if (opts->payload == 1 && is_xpt == 1) fprintf(stderr, "HASH=%d ", tg_hash);
if (opts->payload == 1) fprintf(stderr, "FLCO=0x%02X FID=0x%02X SVC=0x%02X ", flco, fid, so); if (opts->payload == 1) fprintf(stderr, "FLCO=0x%02X FID=0x%02X SVC=0x%02X ", flco, fid, so);
if (flco == 3) //UU_V_Ch_Usr //0x04 and 0x05 on a TLC seem to indicate a Cap + Private Call Terminator (perhaps one for each MS)
//0x07 on a VLC seems to indicate a Cap+ Private Call Header
//0x23 on the Embedded Voice Burst Sync seems to indicate a Cap+ or Cap+ TXI Private Call in progress
//0x20 on the Embedded Voice Burst Sync seems to indicate a Moto (non-specific) Group Call in progress
//its possible that both EMB FID 0x10 FLCO 0x20 and 0x23 are just Moto but non-specific (observed 0x20 on Tier 2)
if (fid == 0x68) sprintf (state->call_string[slot], " Hytera ");
else if (flco == 0x4 || flco == 0x5 || flco == 0x7 || flco == 0x23) //Cap+ Things
{
sprintf (state->call_string[slot], " Cap+");
fprintf (stderr, "Cap+ ");
if (flco == 0x4)
{
strcat (state->call_string[slot], " Grp");
fprintf (stderr, "Group ");
}
else
{
strcat (state->call_string[slot], " Pri");
fprintf (stderr, "Private ");
}
}
else if (flco == 0x3) //UU_V_Ch_Usr -- still valid on hytera VLC
{ {
sprintf (state->call_string[slot], " Private "); sprintf (state->call_string[slot], " Private ");
fprintf (stderr, "Private "); fprintf (stderr, "Private ");
} }
else //Grp_V_Ch_Usr else //Grp_V_Ch_Usr -- still valid on hytera VLC
{ {
sprintf (state->call_string[slot], " Group "); sprintf (state->call_string[slot], " Group ");
fprintf (stderr, "Group "); fprintf (stderr, "Group ");
@@ -191,6 +424,9 @@ void dmr_flco (dsd_opts * opts, dsd_state * state, uint8_t lc_bits[], uint32_t C
//REMUS! Uncomment Line Below if desired //REMUS! Uncomment Line Below if desired
// else strcat (state->call_string[slot], " "); // else strcat (state->call_string[slot], " ");
//Motorola FID 0x10 Only
if (fid == 0x10)
{
/* Check the "Service Option" bits */ /* Check the "Service Option" bits */
if(so & 0x30) if(so & 0x30)
{ {
@@ -206,7 +442,7 @@ void dmr_flco (dsd_opts * opts, dsd_state * state, uint8_t lc_bits[], uint32_t C
{ {
//REMUS! Uncomment Line Below if desired //REMUS! Uncomment Line Below if desired
// strcat (state->call_string[slot], " RES"); // strcat (state->call_string[slot], " RES");
fprintf(stderr, "Reserved=%d ", (so & 0x30) >> 4); fprintf(stderr, "RS%d ", (so & 0x30) >> 4);
} }
} }
if(so & 0x08) if(so & 0x08)
@@ -248,13 +484,16 @@ void dmr_flco (dsd_opts * opts, dsd_state * state, uint8_t lc_bits[], uint32_t C
fprintf(stderr, "No Priority "); fprintf(stderr, "No Priority ");
} }
} }
}
//should rework this back into the upper portion
if (fid == 0x68) fprintf (stderr, "Hytera ");
if (is_xpt) fprintf (stderr, "XPT ");
if (fid == 0x68 && flco == 0x00) fprintf (stderr, "Group ");
if (fid == 0x68 && flco == 0x03) fprintf (stderr, "Private ");
fprintf(stderr, "Call "); fprintf(stderr, "Call ");
fprintf (stderr, "%s", KRED);
if (CRCCorrect == 1) ; //CRCCorrect 1 is good, else is bad CRC; no print on good
else if(IrrecoverableErrors == 0) fprintf(stderr, "(FEC/RAS)");
else fprintf(stderr, "(FEC/CRC ERR)");
//check Cap+ rest channel info if available and good fec //check Cap+ rest channel info if available and good fec
if (is_cap_plus == 1) if (is_cap_plus == 1)
@@ -299,6 +538,23 @@ void dmr_flco (dsd_opts * opts, dsd_state * state, uint8_t lc_bits[], uint32_t C
} }
END_FLCO:
if (unk == 1 || pf == 1)
{
fprintf(stderr, " FLCO=0x%02X FID=0x%02X SVC=0x%02X ", flco, fid, so);
fprintf (stderr, "%s", KNRM);
}
if(IrrecoverableErrors != 0)
{
if (type != 3) fprintf (stderr, "\n");
fprintf (stderr, "%s", KRED);
fprintf (stderr, " SLOT %d", state->currentslot+1);
fprintf (stderr, " FLCO FEC ERR ");
fprintf (stderr, "%s", KNRM);
}
} }
//externalized dmr cach - tact and slco fragment handling //externalized dmr cach - tact and slco fragment handling
@@ -552,8 +808,17 @@ void dmr_slco (dsd_opts * opts, dsd_state * state, uint8_t slco_bits[])
//Con+ //Con+
uint8_t con_netid = (uint8_t)ConvertBitIntoBytes(&slco_bits[8], 8); uint8_t con_netid = (uint8_t)ConvertBitIntoBytes(&slco_bits[8], 8);
uint8_t con_siteid = (uint8_t)ConvertBitIntoBytes(&slco_bits[16], 8); uint8_t con_siteid = (uint8_t)ConvertBitIntoBytes(&slco_bits[16], 8);
//Cap+ //Cap+
uint8_t restchannel = (uint8_t)ConvertBitIntoBytes(&slco_bits[12], 8); uint8_t capsite = (uint8_t)ConvertBitIntoBytes(&slco_bits[22], 3); //Seems more consistent
uint8_t restchannel = (uint8_t)ConvertBitIntoBytes(&slco_bits[16], 4);
uint8_t cap_reserved = (uint8_t)ConvertBitIntoBytes(&slco_bits[20], 2); //significant value?
//Hytera XPT
uint8_t xpt_free = (uint8_t)ConvertBitIntoBytes(&slco_bits[12], 4); //free repeater
//the next two per SDRTrunk, but only 0 values ever observed here
uint8_t xpt_pri = (uint8_t)ConvertBitIntoBytes(&slco_bits[16], 4); //priority repeater
uint8_t xpt_hash = (uint8_t)ConvertBitIntoBytes(&slco_bits[20], 8); //priority TG hash
//initial line break //initial line break
fprintf (stderr, "\n"); fprintf (stderr, "\n");
@@ -602,18 +867,12 @@ void dmr_slco (dsd_opts * opts, dsd_state * state, uint8_t slco_bits[])
fprintf (stderr, " SLCO Activity Update TS1: %X Hash: %02X TS2: %X Hash: %02X", ts1_act, ts1_hash, ts2_act, ts2_hash); //102 361-2 7.1.3.2 fprintf (stderr, " SLCO Activity Update TS1: %X Hash: %02X TS2: %X Hash: %02X", ts1_act, ts1_hash, ts2_act, ts2_hash); //102 361-2 7.1.3.2
else if (slco == 0x9) else if (slco == 0x9)
{ {
state->dmr_mfid = 0x10;
sprintf (state->dmr_branding, "%s", "Motorola");
sprintf (state->dmr_branding_sub, "%s", "Con+ ");
fprintf (stderr, " SLCO Connect Plus Voice Channel - Net ID: %d Site ID: %d", con_netid, con_siteid); fprintf (stderr, " SLCO Connect Plus Voice Channel - Net ID: %d Site ID: %d", con_netid, con_siteid);
sprintf (state->dmr_site_parms, "%d-%d ", con_netid, con_siteid); sprintf (state->dmr_site_parms, "%d-%d ", con_netid, con_siteid);
} }
else if (slco == 0xA) else if (slco == 0xA)
{ {
state->dmr_mfid = 0x10;
sprintf (state->dmr_branding, "%s", "Motorola");
sprintf (state->dmr_branding_sub, "%s", "Con+ ");
fprintf (stderr, " SLCO Connect Plus Control Channel - Net ID: %d Site ID: %d", con_netid, con_siteid); fprintf (stderr, " SLCO Connect Plus Control Channel - Net ID: %d Site ID: %d", con_netid, con_siteid);
sprintf (state->dmr_site_parms, "%d-%d ", con_netid, con_siteid); sprintf (state->dmr_site_parms, "%d-%d ", con_netid, con_siteid);
@@ -627,19 +886,24 @@ void dmr_slco (dsd_opts * opts, dsd_state * state, uint8_t slco_bits[])
else if (slco == 0xF) else if (slco == 0xF)
{ {
state->dmr_mfid = 0x10; fprintf (stderr, " SLCO Capacity Plus Site: %d - Rest Channel %d - RS: %02X", capsite, restchannel, cap_reserved);
sprintf (state->dmr_branding, "%s", "Motorola");
sprintf (state->dmr_branding_sub, "%s", "Cap+ ");
fprintf (stderr, " SLCO Capacity Plus Rest Channel %d", restchannel);
state->dmr_rest_channel = restchannel;
//assign to cc freq if available //assign to cc freq if available
if (state->trunk_chan_map[restchannel] != 0) if (state->trunk_chan_map[restchannel] != 0)
{ {
state->p25_cc_freq = state->trunk_chan_map[restchannel]; state->p25_cc_freq = state->trunk_chan_map[restchannel];
} }
//nullify any previous TIII data (bugfix for bad assignments or system type switching) }
sprintf(state->dmr_site_parms, "%s", ""); else if (slco == 0x08)
{
//The Priority Repeater and Priority Hash values stem from SDRTrunk, but I've never seen these values not be zeroes
// fprintf (stderr, " SLCO Hytera XPT - Free RPT %d - PRI RPT %d - PRI HASH: %02X", xpt_free, xpt_pri, xpt_hash);
//NOTE: on really busy systems, this free repeater assignment can lag due to the 4 TS requirment to get SLC
fprintf (stderr, " SLCO Hytera XPT - Free RPT %d ", xpt_free+1);
sprintf (state->dmr_branding_sub, "XPT ");
//add string for ncurses terminal display
sprintf (state->dmr_site_parms, "Free RPT - %d ", xpt_free+1);
} }
else fprintf (stderr, " SLCO Unknown - %d ", slco); else fprintf (stderr, " SLCO Unknown - %d ", slco);

View File

@@ -77,6 +77,12 @@ void dmr_late_entry_mi (dsd_opts * opts, dsd_state * state)
state->payload_mi = mi_final; state->payload_mi = mi_final;
fprintf (stderr, "%s", KNRM); fprintf (stderr, "%s", KNRM);
} }
//run afterwards, or le verification won't match up properly
if (state->payload_algid != 0x21)
{
LFSR64 (state);
fprintf (stderr, "\n");
}
} }
if (slot == 1 && state->payload_algidR != 0) if (slot == 1 && state->payload_algidR != 0)
{ {
@@ -87,6 +93,12 @@ void dmr_late_entry_mi (dsd_opts * opts, dsd_state * state)
state->payload_miR = mi_final; state->payload_miR = mi_final;
fprintf (stderr, "%s", KNRM); fprintf (stderr, "%s", KNRM);
} }
//run afterwards, or le verification won't match up properly
if (state->payload_algidR != 0x21)
{
LFSR64 (state);
fprintf (stderr, "\n");
}
} }
} }
@@ -104,11 +116,13 @@ void dmr_alg_refresh (dsd_opts * opts, dsd_state * state)
state->DMRvcL = 0; state->DMRvcL = 0;
} }
if (state->payload_algid >= 0x21) if (state->payload_algid == 0x21)
{ {
LFSR (state); LFSR (state);
fprintf (stderr, "\n"); fprintf (stderr, "\n");
} }
//LFSR64 carried out after LE verification in order to keep it from constantly resetting the MI to the previous value
} }
if (state->currentslot == 1) if (state->currentslot == 1)
{ {
@@ -119,11 +133,13 @@ void dmr_alg_refresh (dsd_opts * opts, dsd_state * state)
state->DMRvcR = 0; state->DMRvcR = 0;
} }
if (state->payload_algidR >= 0x21) if (state->payload_algidR == 0x21)
{ {
LFSR (state); LFSR (state);
fprintf (stderr, "\n"); fprintf (stderr, "\n");
} }
//LFSR64 carried out after LE verification in order to keep it from constantly resetting the MI to the previous value
} }
} }
@@ -135,5 +151,166 @@ void dmr_alg_reset (dsd_opts * opts, dsd_state * state)
state->DMRvcL = 0; state->DMRvcL = 0;
state->DMRvcR = 0; state->DMRvcR = 0;
state->payload_miP = 0; state->payload_miP = 0;
state->payload_miN = 0;
}
//handle Single Burst (Voice Burst F) or Reverse Channel Signalling
void dmr_sbrc (dsd_opts * opts, dsd_state * state, uint8_t power)
{
int i;
uint8_t slot = state->currentslot;
uint8_t sbrc_interleaved[32];
uint8_t sbrc_return[32];
memset (sbrc_interleaved, 0, sizeof(sbrc_interleaved));
memset (sbrc_return, 0, sizeof(sbrc_return));
uint32_t irr_err = 0;
uint32_t sbrc_hex = 0;
uint16_t crc_extracted = 7777;
uint16_t crc_computed = 9999;
uint8_t crc_okay = 0;
// 9.3.2 Pre-emption and power control Indicator (PI)
// 0 - The embedded signalling carries information associated to the same logical channel or the Null embedded message
// 1 - The embedded signalling carries RC information associated to the other logical channel
for(i = 0; i < 32; i++) sbrc_interleaved[i] = state->dmr_embedded_signalling[slot][5][i + 8];
//power == 0 should be single burst
if (power == 0) irr_err = BPTC_16x2_Extract_Data(sbrc_interleaved, sbrc_return, 0);
//power == 1 should be reverse channel -- still need to check the interleave inside of BPTC
if (power == 1) irr_err = BPTC_16x2_Extract_Data(sbrc_interleaved, sbrc_return, 1);
//bad emb burst, never set a valid power indicator value (probably 9)
if (power > 1) goto SBRC_END;
//RC Channel CRC 7 Mask = 0x7A; CRC bits are used as privacy indicators on
//Single Voice Burst F (see below), other moto values seem to exist there as well
//unknown what the other values are (see Cap+ 0x313 and 0x643)
if (power == 1) //RC
{
crc_extracted = 0;
for (i = 0; i < 7; i++)
{
crc_extracted = crc_extracted << 1;
crc_extracted = crc_extracted | sbrc_return[i+4];
}
crc_extracted = crc_extracted ^ 0x7A;
crc_computed = crc7((uint8_t *) sbrc_return, 11);
if (crc_extracted == crc_computed) crc_okay = 1;
}
else crc_okay = 1; //SB
if (opts->payload == 1) //hide the sb/rc behind the payload printer, won't be useful to most people right now
{
fprintf (stderr, "\n %s", KCYN);
if (power == 0) fprintf (stderr, " SB: ");
if (power == 1) fprintf (stderr, " RC: ");
for(i = 0; i < 11; i++)
{
sbrc_hex = sbrc_hex << 1;
sbrc_hex |= sbrc_return[i] & 1; //sbrc_return
fprintf (stderr, "%d", sbrc_return[i]);
}
fprintf (stderr, " - %03X", sbrc_hex);
fprintf (stderr, "%s", KNRM);
if (crc_okay == 0)
{
fprintf (stderr, "%s", KRED);
fprintf (stderr, " (CRC ERR)");
fprintf (stderr, "%s", KNRM);
if (opts->payload == 1) fprintf (stderr, " CRC EXT %02X, CRC CMP %02X", crc_extracted, crc_computed);
}
}
//Disabling the lower portion until this can be completely ironed out
//sbrc_hex value of 0x313 seems to be some Cap+ Thing,
//also observed 0x643 on another cap+ system (site id, status? something?)
// uint8_t sbrc_opcode = sbrc_hex;
// uint8_t alg = sbrc_hex & 0x7;
// uint8_t key = (sbrc_hex >> 3) & 0xFF;
//this pattern seems to fit the multiple cap+ systems I've observed
//test on site '7' to make sure (works on 1 and 4)
// uint8_t cap_site = (sbrc_hex >> 4) & 0x7;
// if (opts->payload == 1)
// {
// if (irr_err != 0) fprintf (stderr, "%s (FEC ERR) %d %s", KRED, irr_err, KNRM);
// if (irr_err == 0)
// {
// if (sbrc_hex == 0) ; //NULL
// else if (sbrc_hex == 0x313) //sbrc_hex == 0x313 and 0x643 (cap+ things)
// {
// //Cap+ Site ID seems to fit here on samples I've seen with the alternate SB signalling
// fprintf (stderr, "%s ", KYEL);
// fprintf (stderr, "\n ");
// fprintf (stderr, " Capacity Plus Site %d", cap_site);
// fprintf (stderr, "%s ", KNRM);
// }
// else
// {
// if (slot == 0)
// {
// //key and alg only present SOME times, not all,
// //also, intermixed with other signalling
// //needs more study first!
// if (state->dmr_so & 0x40 && key != 0 && state->payload_keyid == 0)
// {
// if (opts->payload == 1)
// {
// fprintf (stderr, "%s ", KYEL);
// fprintf (stderr, "\n Slot 1");
// fprintf (stderr, " DMR LE SB ALG ID: %X KEY ID: %0X", alg + 0x20, key);
// fprintf (stderr, "%s ", KNRM);
// }
// //needs more study before assignment
// // state->payload_keyid = key;
// // state->payload_algid = alg + 0x20; //assuming DMRA approved alg values (moto patent)
// }
// }
// if (slot == 1)
// {
// if (state->dmr_soR & 0x40 && key != 0 && state->payload_keyidR == 0)
// {
// if (opts->payload == 1)
// {
// fprintf (stderr, "%s ", KYEL);
// fprintf (stderr, "\n Slot 2");
// fprintf (stderr, " DMR LE SB ALG ID: %X KEY ID: %0X", alg + 0x20, key);
// fprintf (stderr, "%s ", KNRM);
// }
// //needs more study before assignment
// // state->payload_keyidR = key;
// // state->payload_algidR = alg + 0x20; //assuming DMRA approved alg values (moto patent)
// }
// }
// }
// }
// }
SBRC_END:
//'DSP' output to file -- only RC, or RC and SB?
if (power == 1 && opts->use_dsp_output == 1 && sbrc_hex != 0) //if not NULL
{
FILE * pFile; //file pointer
pFile = fopen (opts->dsp_out_file, "a");
fprintf (pFile, "\n%d 99 ", slot+1); //'99' is RC designation value
int k = 0;
for (i = 0; i < 24; i++) //12 bytes, SB or RC
{
//check to see if k++ starts at zero, or at 1
int sbrc_nib = (state->dmr_embedded_signalling[slot][5][k++] << 3) | (state->dmr_embedded_signalling[slot][5][k++] << 2) | (state->dmr_embedded_signalling[slot][5][k++] << 1) | (state->dmr_embedded_signalling[slot][5][k++] << 0);
fprintf (pFile, "%X", sbrc_nib);
}
fclose (pFile);
}
} }

View File

@@ -50,6 +50,11 @@ void dmrMS (dsd_opts * opts, dsd_state * state)
uint8_t internalslot; uint8_t internalslot;
uint8_t vc; uint8_t vc;
//assign as nonsensical numbers
uint8_t cc = 25;
uint8_t power = 9; //power and pre-emption indicator
uint8_t lcss = 9;
//dummy bits to pass to dburst for link control //dummy bits to pass to dburst for link control
uint8_t dummy_bits[196]; uint8_t dummy_bits[196];
memset (dummy_bits, 0, sizeof (dummy_bits)); memset (dummy_bits, 0, sizeof (dummy_bits));
@@ -87,7 +92,7 @@ void dmrMS (dsd_opts * opts, dsd_state * state)
for(i = 0; i < 12; i++) for(i = 0; i < 12; i++)
{ {
dibit = getDibit(opts, state); dibit = getDibit(opts, state);
if(opts->inverted_dmr == 1) dibit = (dibit ^ 2); if(opts->inverted_dmr == 1) dibit = (dibit ^ 2) & 3;
cachdata[i] = dibit; cachdata[i] = dibit;
state->dmr_stereo_payload[i] = dibit; state->dmr_stereo_payload[i] = dibit;
@@ -119,7 +124,7 @@ void dmrMS (dsd_opts * opts, dsd_state * state)
for(i = 0; i < 36; i++) for(i = 0; i < 36; i++)
{ {
dibit = getDibit(opts, state); dibit = getDibit(opts, state);
if(opts->inverted_dmr == 1) dibit = (dibit ^ 2); if(opts->inverted_dmr == 1) dibit = (dibit ^ 2) & 3;
state->dmr_stereo_payload[i+12] = dibit; state->dmr_stereo_payload[i+12] = dibit;
@@ -144,7 +149,7 @@ void dmrMS (dsd_opts * opts, dsd_state * state)
for(i = 0; i < 18; i++) for(i = 0; i < 18; i++)
{ {
dibit = getDibit(opts, state); dibit = getDibit(opts, state);
if(opts->inverted_dmr == 1) dibit = (dibit ^ 2); if(opts->inverted_dmr == 1) dibit = (dibit ^ 2) & 3;
state->dmr_stereo_payload[i+48] = dibit; state->dmr_stereo_payload[i+48] = dibit;
ambe_fr2[*w][*x] = (1 & (dibit >> 1)); // bit 1 ambe_fr2[*w][*x] = (1 & (dibit >> 1)); // bit 1
@@ -171,7 +176,7 @@ void dmrMS (dsd_opts * opts, dsd_state * state)
sync[i] = (dibit | 1) + 48; sync[i] = (dibit | 1) + 48;
// load the superframe to do embedded signal processing // load the superframe to do embedded signal processing
if(vc > 1 && vc < 6) //grab on vc1 values 2-5 B C D and E if(vc > 1) //grab on vc1 values 2-5 B C D and E
{ {
state->dmr_embedded_signalling[internalslot][vc-1][i*2] = (1 & (dibit >> 1)); // bit 1 state->dmr_embedded_signalling[internalslot][vc-1][i*2] = (1 & (dibit >> 1)); // bit 1
state->dmr_embedded_signalling[internalslot][vc-1][i*2+1] = (1 & dibit); // bit 0 state->dmr_embedded_signalling[internalslot][vc-1][i*2+1] = (1 & dibit); // bit 0
@@ -180,17 +185,41 @@ void dmrMS (dsd_opts * opts, dsd_state * state)
} }
sync[24] = 0; sync[24] = 0;
//test for RC sync pattern in MS sourced audio
if ( strcmp (sync, DMR_RC_DATA_SYNC) == 0)
{
state->dmr_ms_rc = 1;
fprintf (stderr, "%s ", getTime());
if (opts->inverted_dmr == 0)
{
fprintf (stderr,"Sync: +DMR MS/DM MODE/MONO ");
}
else fprintf (stderr,"Sync: -DMR MS/DM MODE/MONO ");
fprintf (stderr, "| RC ");
fprintf (stderr, "\n");
}
for(i = 0; i < 8; i++) EmbeddedSignalling[i] = syncdata[i];
for(i = 0; i < 8; i++) EmbeddedSignalling[i + 8] = syncdata[i + 40];
EmbeddedSignallingOk = -1; EmbeddedSignallingOk = -1;
if(QR_16_7_6_decode(EmbeddedSignalling)) if(QR_16_7_6_decode(EmbeddedSignalling))
{ {
EmbeddedSignallingOk = 1; EmbeddedSignallingOk = 1;
cc = ((EmbeddedSignalling[0] << 3) + (EmbeddedSignalling[1] << 2) + (EmbeddedSignalling[2] << 1) + EmbeddedSignalling[3]);
power = EmbeddedSignalling[4];
lcss = ((EmbeddedSignalling[5] << 1) + EmbeddedSignalling[6]);
} }
//Continue Second AMBE Frame, 18 after Sync or EmbeddedSignalling //Continue Second AMBE Frame, 18 after Sync or EmbeddedSignalling
for(i = 0; i < 18; i++) for(i = 0; i < 18; i++)
{ {
dibit = getDibit(opts, state); dibit = getDibit(opts, state);
if(opts->inverted_dmr == 1) dibit = (dibit ^ 2); if(opts->inverted_dmr == 1) dibit = (dibit ^ 2) & 3;
state->dmr_stereo_payload[i+90] = dibit; state->dmr_stereo_payload[i+90] = dibit;
ambe_fr2[*w][*x] = (1 & (dibit >> 1)); // bit 1 ambe_fr2[*w][*x] = (1 & (dibit >> 1)); // bit 1
@@ -214,7 +243,7 @@ void dmrMS (dsd_opts * opts, dsd_state * state)
for(i = 0; i < 36; i++) for(i = 0; i < 36; i++)
{ {
dibit = getDibit(opts, state); dibit = getDibit(opts, state);
if(opts->inverted_dmr == 1) dibit = (dibit ^ 2); if(opts->inverted_dmr == 1) dibit = (dibit ^ 2) & 3;
state->dmr_stereo_payload[i+108] = dibit; state->dmr_stereo_payload[i+108] = dibit;
ambe_fr3[*w][*x] = (1 & (dibit >> 1)); // bit 1 ambe_fr3[*w][*x] = (1 & (dibit >> 1)); // bit 1
@@ -227,6 +256,20 @@ void dmrMS (dsd_opts * opts, dsd_state * state)
} }
//'DSP' output to file
if (opts->use_dsp_output == 1)
{
FILE * pFile; //file pointer
pFile = fopen (opts->dsp_out_file, "a");
fprintf (pFile, "\n%d 10 ", state->currentslot+1); //0x10 for "voice burst", forced to slot 1
for (i = 6; i < 72; i++) //33 bytes, no CACH
{
int dsp_byte = (state->dmr_stereo_payload[i*2] << 2) | state->dmr_stereo_payload[i*2 + 1];
fprintf (pFile, "%X", dsp_byte);
}
fclose (pFile);
}
state->dmr_ms_mode = 1; state->dmr_ms_mode = 1;
memcpy (ambe_fr4, ambe_fr2, sizeof(ambe_fr2)); memcpy (ambe_fr4, ambe_fr2, sizeof(ambe_fr2));
@@ -238,6 +281,8 @@ void dmrMS (dsd_opts * opts, dsd_state * state)
memcpy (m2, ambe_fr2, sizeof(m2)); memcpy (m2, ambe_fr2, sizeof(m2));
memcpy (m3, ambe_fr3, sizeof(m3)); memcpy (m3, ambe_fr3, sizeof(m3));
if (state->dmr_ms_rc == 0)
{
if (state->directmode == 0) if (state->directmode == 0)
{ {
processMbeFrame (opts, state, NULL, ambe_fr, NULL); processMbeFrame (opts, state, NULL, ambe_fr, NULL);
@@ -250,10 +295,14 @@ void dmrMS (dsd_opts * opts, dsd_state * state)
processMbeFrame (opts, state, NULL, ambe_fr2, NULL); processMbeFrame (opts, state, NULL, ambe_fr2, NULL);
processMbeFrame (opts, state, NULL, ambe_fr3, NULL); processMbeFrame (opts, state, NULL, ambe_fr3, NULL);
} }
}
if (vc == 6) if (vc == 6)
{ {
dmr_data_burst_handler(opts, state, (uint8_t *)dummy_bits, 0xEB); dmr_data_burst_handler(opts, state, (uint8_t *)dummy_bits, 0xEB);
//check the single burst/reverse channel opportunity
dmr_sbrc (opts, state, power);
fprintf (stderr, "\n"); fprintf (stderr, "\n");
dmr_alg_refresh (opts, state); dmr_alg_refresh (opts, state);
} }
@@ -268,6 +317,12 @@ void dmrMS (dsd_opts * opts, dsd_state * state)
state->last_vc_sync_time = time(NULL); state->last_vc_sync_time = time(NULL);
vc++; vc++;
//reset emb components
cc = 25;
power = 9; //power and pre-emption indicator
lcss = 9;
//this is necessary because we need to skip and collect dibits, not just skip them //this is necessary because we need to skip and collect dibits, not just skip them
if (vc > 6) goto END; if (vc > 6) goto END;
@@ -292,7 +347,7 @@ void dmrMS (dsd_opts * opts, dsd_state * state)
dibit = getDibit(opts, state); dibit = getDibit(opts, state);
if (opts->inverted_dmr == 1) if (opts->inverted_dmr == 1)
{ {
dibit = (dibit ^ 2); dibit = (dibit ^ 2) & 3;
} }
state->dmr_stereo_payload[i] = dibit; state->dmr_stereo_payload[i] = dibit;
@@ -379,7 +434,7 @@ void dmrMSBootstrap (dsd_opts * opts, dsd_state * state)
dibit = state->dmr_stereo_payload[i]; dibit = state->dmr_stereo_payload[i];
if(opts->inverted_dmr == 1) if(opts->inverted_dmr == 1)
{ {
dibit = (dibit ^ 2); dibit = (dibit ^ 2) & 3;
} }
cachdata[i] = dibit; cachdata[i] = dibit;
} }
@@ -398,7 +453,7 @@ void dmrMSBootstrap (dsd_opts * opts, dsd_state * state)
dibit = state->dmr_stereo_payload[i+12]; dibit = state->dmr_stereo_payload[i+12];
if(opts->inverted_dmr == 1) if(opts->inverted_dmr == 1)
{ {
dibit = (dibit ^ 2); dibit = (dibit ^ 2) & 3;
} }
state->dmr_stereo_payload[i+12] = dibit; state->dmr_stereo_payload[i+12] = dibit;
ambe_fr[*w][*x] = (1 & (dibit >> 1)); // bit 1 ambe_fr[*w][*x] = (1 & (dibit >> 1)); // bit 1
@@ -425,7 +480,7 @@ void dmrMSBootstrap (dsd_opts * opts, dsd_state * state)
dibit = state->dmr_stereo_payload[i+48]; dibit = state->dmr_stereo_payload[i+48];
if(opts->inverted_dmr == 1) if(opts->inverted_dmr == 1)
{ {
dibit = (dibit ^ 2); dibit = (dibit ^ 2) & 3;
} }
ambe_fr2[*w][*x] = (1 & (dibit >> 1)); // bit 1 ambe_fr2[*w][*x] = (1 & (dibit >> 1)); // bit 1
ambe_fr2[*y][*z] = (1 & dibit); // bit 0 ambe_fr2[*y][*z] = (1 & dibit); // bit 0
@@ -443,8 +498,9 @@ void dmrMSBootstrap (dsd_opts * opts, dsd_state * state)
dibit = getDibit(opts, state); dibit = getDibit(opts, state);
if(opts->inverted_dmr == 1) if(opts->inverted_dmr == 1)
{ {
dibit = (dibit ^ 2); dibit = (dibit ^ 2) & 3;
} }
state->dmr_stereo_payload[i+90] = dibit;
ambe_fr2[*w][*x] = (1 & (dibit >> 1)); // bit 1 ambe_fr2[*w][*x] = (1 & (dibit >> 1)); // bit 1
ambe_fr2[*y][*z] = (1 & dibit); // bit 0 ambe_fr2[*y][*z] = (1 & dibit); // bit 0
@@ -469,8 +525,9 @@ void dmrMSBootstrap (dsd_opts * opts, dsd_state * state)
dibit = getDibit(opts, state); dibit = getDibit(opts, state);
if(opts->inverted_dmr == 1) if(opts->inverted_dmr == 1)
{ {
dibit = (dibit ^ 2); dibit = (dibit ^ 2) & 3;
} }
state->dmr_stereo_payload[i+108] = dibit;
ambe_fr3[*w][*x] = (1 & (dibit >> 1)); // bit 1 ambe_fr3[*w][*x] = (1 & (dibit >> 1)); // bit 1
ambe_fr3[*y][*z] = (1 & dibit); // bit 0 ambe_fr3[*y][*z] = (1 & dibit); // bit 0
@@ -481,6 +538,20 @@ void dmrMSBootstrap (dsd_opts * opts, dsd_state * state)
} }
//'DSP' output to file
if (opts->use_dsp_output == 1)
{
FILE * pFile; //file pointer
pFile = fopen (opts->dsp_out_file, "a");
fprintf (pFile, "\n%d 10 ", state->currentslot+1); //0x10 for "voice burst", force to slot 1
for (i = 6; i < 72; i++) //33 bytes, no CACH
{
int dsp_byte = (state->dmr_stereo_payload[i*2] << 2) | state->dmr_stereo_payload[i*2 + 1];
fprintf (pFile, "%X", dsp_byte);
}
fclose (pFile);
}
fprintf (stderr, "%s ", getTime()); fprintf (stderr, "%s ", getTime());
if (opts->inverted_dmr == 0) if (opts->inverted_dmr == 0)
{ {
@@ -517,7 +588,7 @@ void dmrMSBootstrap (dsd_opts * opts, dsd_state * state)
} }
//collect the mi fragment //collect the mi fragment
dmr_late_entry_mi_fragment (opts, state, 1, ambe_fr, ambe_fr2, ambe_fr3); dmr_late_entry_mi_fragment (opts, state, 1, m1, m2, m3);
//errors due to skipping other slot //errors due to skipping other slot
// cach_err = dmr_cach (opts, state, cachdata); // cach_err = dmr_cach (opts, state, cachdata);
@@ -558,7 +629,7 @@ void dmrMSData (dsd_opts * opts, dsd_state * state)
{ {
dibit = *dibit_p; dibit = *dibit_p;
dibit_p++; dibit_p++;
if(opts->inverted_dmr == 1) dibit = (dibit ^ 2); if(opts->inverted_dmr == 1) dibit = (dibit ^ 2) & 3;
state->dmr_stereo_payload[i] = dibit; state->dmr_stereo_payload[i] = dibit;
} }
@@ -566,7 +637,7 @@ void dmrMSData (dsd_opts * opts, dsd_state * state)
for (i = 0; i < 54; i++) for (i = 0; i < 54; i++)
{ {
dibit = getDibit(opts, state); dibit = getDibit(opts, state);
if(opts->inverted_dmr == 1) dibit = (dibit ^ 2); if(opts->inverted_dmr == 1) dibit = (dibit ^ 2) & 3;
state->dmr_stereo_payload[i+90] = dibit; state->dmr_stereo_payload[i+90] = dibit;
} }

View File

@@ -44,9 +44,9 @@ void dmr_pdu (dsd_opts * opts, dsd_state * state, uint8_t block_len, uint8_t DMR
uint8_t padding = state->data_header_padding[slot]; uint8_t padding = state->data_header_padding[slot];
uint8_t lrrp_conf = 0; uint8_t lrrp_conf = 0;
//consider disabling on prop_head data blocks if bad/false decodes //check for more available flag info, etc on these prior to running
//if (state->data_p_head[slot] == 0) if (DMR_PDU[0] == 0x01) dmr_locn (opts, state, block_len, DMR_PDU);
lrrp_conf = dmr_lrrp (opts, state, block_len, DMR_PDU); else dmr_lrrp (opts, state, block_len, DMR_PDU);
//maybe one day we will have more things to do here //maybe one day we will have more things to do here
state->data_conf_data[slot] = 0; //flag off confirmed data after processing it state->data_conf_data[slot] = 0; //flag off confirmed data after processing it
@@ -57,7 +57,7 @@ void dmr_pdu (dsd_opts * opts, dsd_state * state, uint8_t block_len, uint8_t DMR
//The contents of this function are mostly my reversed engineered efforts by observing DSDPlus output and matching data bytes //The contents of this function are mostly my reversed engineered efforts by observing DSDPlus output and matching data bytes
//combined with a few external sources such as OK-DMR for some token values and extra data values (rad and alt) //combined with a few external sources such as OK-DMR for some token values and extra data values (rad and alt)
//this is by no means an extensive LRRP list and is prone to error (unless somebody has the manual or something) //this is by no means an extensive LRRP list and is prone to error (unless somebody has the manual or something)
uint8_t dmr_lrrp (dsd_opts * opts, dsd_state * state, uint8_t block_len, uint8_t DMR_PDU[]) void dmr_lrrp (dsd_opts * opts, dsd_state * state, uint8_t block_len, uint8_t DMR_PDU[])
{ {
int i, j; int i, j;
uint16_t message_len = 0; uint16_t message_len = 0;
@@ -82,12 +82,15 @@ uint8_t dmr_lrrp (dsd_opts * opts, dsd_state * state, uint8_t block_len, uint8_t
//lat-long-radius-alt //lat-long-radius-alt
uint32_t lat = 0; uint32_t lat = 0;
uint8_t lat_sign = 0;
uint32_t lon = 0; uint32_t lon = 0;
uint16_t rad = 0; uint16_t rad = 0; //or Azimuth in Circle 3D?
uint8_t alt = 0; uint8_t alt = 0;
double lat_unit = (double)180/(double)4294967295; double lat_unit = (double)180/(double)4294967295;
double lon_unit = (double)360/(double)4294967295; double lon_unit = (double)360/(double)4294967295;
double lat_fin = 0.0; //calculated values
double lon_fin = 0.0; //calculated values
int lat_sign = 1; //positive 1, or negative 1
int lon_sign = 1; //positive 1, or negative 1
//speed/velocity //speed/velocity
uint16_t vel = 0; uint16_t vel = 0;
@@ -98,26 +101,17 @@ uint8_t dmr_lrrp (dsd_opts * opts, dsd_state * state, uint8_t block_len, uint8_t
uint8_t degrees = 0; uint8_t degrees = 0;
uint8_t deg_set = 0; uint8_t deg_set = 0;
char deg_glyph[4];
sprintf (deg_glyph, "%s", "°");
// sprintf (deg_glyph, "%s", "d");
//triggered information report //triggered information report
uint8_t report = 0; uint8_t report = 0;
uint8_t pot_report = 0; //potential report by finding 0x0D and backtracking a few bytes uint8_t pot_report = 0; //potential report by finding 0x0D and backtracking a few bytes
uint8_t is_p_head = 0;
//shim for getting LRRP out of some prop head data blocks
if (state->data_p_head[slot] == 1)
{
if (DMR_PDU[1] != 0x10) goto LRRP_END; //check to see if FID is 0x10
i = 0;
message_len = blocks * block_len;
source = state->dmr_lrrp_source[state->currentslot];
is_p_head = 1;
}
else i = 12;
//start looking for tokens (using my best understanding of the ok-dmr library xml and python files) //start looking for tokens (using my best understanding of the ok-dmr library xml and python files)
for (i; i < ( (blocks*block_len) - (padding+4) ); i++) for (i = 0; i < ( (blocks*block_len) - (padding+4) ); i++)
{ {
switch(DMR_PDU[i]){ switch(DMR_PDU[i]){
@@ -174,20 +168,22 @@ uint8_t dmr_lrrp (dsd_opts * opts, dsd_state * state, uint8_t block_len, uint8_t
} }
break; break;
//RESULT TOKEN or Request ID! //RESULT TOKEN or Request ID!
case 0x22: //same comment as below, observed followed the message len
case 0x23: //this value has been seen after the 0x0D message len, appears to be a 2-byte value, was tripping a false on time stamp case 0x23: //this value has been seen after the 0x0D message len, appears to be a 2-byte value, was tripping a false on time stamp
i += 2; i += 2;
break; break;
//answer and report tokens //answer and report tokens
case 0x51: //circle-2d case 0x51: //circle-2d
case 0x54: //circle-3d case 0x54: //circle-3d
case 0x55: //circle-3d <- false positives on one sample, so either an earlier token occurred (that we don't have) or just random data? case 0x55: //circle-3d
if (message_len > 0 && lat == 0) if (message_len > 0 && lat == 0)
{ {
if (DMR_PDU[i+1] & 0x80) lat_sign = 1; // lat = ( ( ((DMR_PDU[i+1] & 0x7F ) << 24 ) + (DMR_PDU[i+2] << 16) + (DMR_PDU[i+3] << 8) + DMR_PDU[i+4]) * 1 );
lat = ( ( ((DMR_PDU[i+1] & 0x7F ) << 24 ) + (DMR_PDU[i+2] << 16) + (DMR_PDU[i+3] << 8) + DMR_PDU[i+4]) * 1 ); // lon = ( ( ((DMR_PDU[i+5] & 0x7F ) << 24 ) + (DMR_PDU[i+6] << 16) + (DMR_PDU[i+7] << 8) + DMR_PDU[i+8]) * 1 );
lat = ( ( (DMR_PDU[i+1] << 24 ) + (DMR_PDU[i+2] << 16) + (DMR_PDU[i+3] << 8) + DMR_PDU[i+4]) * 1 );
lon = ( ( (DMR_PDU[i+5] << 24 ) + (DMR_PDU[i+6] << 16) + (DMR_PDU[i+7] << 8) + DMR_PDU[i+8]) * 1 ); lon = ( ( (DMR_PDU[i+5] << 24 ) + (DMR_PDU[i+6] << 16) + (DMR_PDU[i+7] << 8) + DMR_PDU[i+8]) * 1 );
rad = (DMR_PDU[i+9] << 8) + DMR_PDU[i+10]; rad = (DMR_PDU[i+9] << 8) + DMR_PDU[i+10];
i += 10; //double check i += 10;
if (lat > 0 && lon > 0) lrrp_confidence++; //would be better to set by absolute boundary (180 and 90?) if (lat > 0 && lon > 0) lrrp_confidence++; //would be better to set by absolute boundary (180 and 90?)
else lat = 0; else lat = 0;
} }
@@ -213,10 +209,11 @@ uint8_t dmr_lrrp (dsd_opts * opts, dsd_state * state, uint8_t block_len, uint8_t
case 0x66: //point-2d case 0x66: //point-2d
if (message_len > 0 && lat == 0) if (message_len > 0 && lat == 0)
{ {
if (DMR_PDU[i+1] & 0x80) lat_sign = 1; // lat = ( ( ((DMR_PDU[i+1] & 0x7F ) << 24 ) + (DMR_PDU[i+2] << 16) + (DMR_PDU[i+3] << 8) + DMR_PDU[i+4]) * 1 );
lat = ( ( ((DMR_PDU[i+1] & 0x7F ) << 24 ) + (DMR_PDU[i+2] << 16) + (DMR_PDU[i+3] << 8) + DMR_PDU[i+4]) * 1 ); // lon = ( ( ((DMR_PDU[i+5] & 0x7F ) << 24 ) + (DMR_PDU[i+6] << 16) + (DMR_PDU[i+7] << 8) + DMR_PDU[i+8]) * 1 );
lat = ( ( (DMR_PDU[i+1] << 24 ) + (DMR_PDU[i+2] << 16) + (DMR_PDU[i+3] << 8) + DMR_PDU[i+4]) * 1 );
lon = ( ( (DMR_PDU[i+5] << 24 ) + (DMR_PDU[i+6] << 16) + (DMR_PDU[i+7] << 8) + DMR_PDU[i+8]) * 1 ); lon = ( ( (DMR_PDU[i+5] << 24 ) + (DMR_PDU[i+6] << 16) + (DMR_PDU[i+7] << 8) + DMR_PDU[i+8]) * 1 );
i += 8; //check i += 8;
lrrp_confidence++; lrrp_confidence++;
} }
break; break;
@@ -224,12 +221,13 @@ uint8_t dmr_lrrp (dsd_opts * opts, dsd_state * state, uint8_t block_len, uint8_t
case 0x6A: //point-3d case 0x6A: //point-3d
if (message_len > 0 && lat == 0) if (message_len > 0 && lat == 0)
{ {
if (DMR_PDU[i+1] & 0x80) lat_sign = 1; // lat = ( ( ((DMR_PDU[i+1] & 0x7F ) << 24 ) + (DMR_PDU[i+2] << 16) + (DMR_PDU[i+3] << 8) + DMR_PDU[i+4]) * 1 );
lat = ( ( ((DMR_PDU[i+1] & 0x7F ) << 24 ) + (DMR_PDU[i+2] << 16) + (DMR_PDU[i+3] << 8) + DMR_PDU[i+4]) * 1 ); // lon = ( ( ((DMR_PDU[i+5] & 0x7F ) << 24 ) + (DMR_PDU[i+6] << 16) + (DMR_PDU[i+7] << 8) + DMR_PDU[i+8]) * 1 );
lat = ( ( (DMR_PDU[i+1] << 24 ) + (DMR_PDU[i+2] << 16) + (DMR_PDU[i+3] << 8) + DMR_PDU[i+4]) * 1 );
lon = ( ( (DMR_PDU[i+5] << 24 ) + (DMR_PDU[i+6] << 16) + (DMR_PDU[i+7] << 8) + DMR_PDU[i+8]) * 1 ); lon = ( ( (DMR_PDU[i+5] << 24 ) + (DMR_PDU[i+6] << 16) + (DMR_PDU[i+7] << 8) + DMR_PDU[i+8]) * 1 );
alt = DMR_PDU[i+9]; alt = DMR_PDU[i+9];
i += 9; //check i += 9;
if (lat > 0 && lon > 0) lrrp_confidence++; //would be better to set by absolute boundary (180 and 90?) if (lat > 0 && lon > 0) lrrp_confidence++;
else lat = 0; else lat = 0;
} }
break; break;
@@ -273,7 +271,7 @@ uint8_t dmr_lrrp (dsd_opts * opts, dsd_state * state, uint8_t block_len, uint8_t
{ {
fprintf (stderr, "%s", KYEL); fprintf (stderr, "%s", KYEL);
fprintf (stderr, "\n LRRP Confidence: %d - Message Len: %d Octets", lrrp_confidence, message_len); fprintf (stderr, "\n LRRP Confidence: %d - Message Len: %d Octets", lrrp_confidence, message_len);
if (lrrp_confidence >= 4) //find the sweet magical number if (lrrp_confidence >= 3) //find the sweet magical number
{ {
//now we can open our lrrp file and write to it as well //now we can open our lrrp file and write to it as well
FILE * pFile; //file pointer FILE * pFile; //file pointer
@@ -285,9 +283,10 @@ uint8_t dmr_lrrp (dsd_opts * opts, dsd_state * state, uint8_t block_len, uint8_t
if (!year) fprintf (pFile, "%s\t", getDateL() ); //current date, only add this IF no included timestamp in LRRP data? if (!year) fprintf (pFile, "%s\t", getDateL() ); //current date, only add this IF no included timestamp in LRRP data?
if (!year) fprintf (pFile, "%s\t", getTimeL() ); //current timestamp, only add this IF no included timestamp in LRRP data? if (!year) fprintf (pFile, "%s\t", getTimeL() ); //current timestamp, only add this IF no included timestamp in LRRP data?
if (year) fprintf (pFile, "%04d/%02d/%02d\t%02d:%02d:%02d\t", year, month, day, hour, minute, second); //add timestamp from decoded audio if available if (year) fprintf (pFile, "%04d/%02d/%02d\t%02d:%02d:%02d\t", year, month, day, hour, minute, second); //add timestamp from decoded audio if available
//write data header source (or destination?) if not available in lrrp data //write data header source if not available in lrrp data
if (!source) fprintf (pFile, "%08lld\t", state->dmr_lrrp_source[state->currentslot]); //source address from data header if (!source) fprintf (pFile, "%08lld\t", state->dmr_lrrp_source[state->currentslot]); //source address from data header
if (source) fprintf (pFile, "%08d\t", source); //add source form decoded audio if available, else its from the header if (source) fprintf (pFile, "%08d\t", source); //add source form decoded audio if available, else its from the header
} }
if (pot_report) if (pot_report)
@@ -327,31 +326,45 @@ uint8_t dmr_lrrp (dsd_opts * opts, dsd_state * state, uint8_t block_len, uint8_t
if (lat) if (lat)
{ {
fprintf (stderr, "\n"); fprintf (stderr, "\n");
if (lat_sign) //print a '-' in front of the value //need to check these new calcs for accuracy accross the globe, both lat and lon
fprintf (stderr, " LRRP - Lat: -%.5lf", (double)lat * lat_unit);
else fprintf (stderr, " LRRP - Lat: %.5lf", (double)lat * lat_unit); //two's compliment-ish testing on these bytes
fprintf (stderr, " Lon: %.5lf", (double)lon * lon_unit); if (lat & 0x80000000) //8
if (lat_sign) {
fprintf (stderr, " (-%.5lf, %.5lf)", (double)lat * lat_unit , (double)lon * lon_unit); lat = lat & 0x7FFFFFFF;
else fprintf (stderr, " (%.5lf, %.5lf)", (double)lat * lat_unit , (double)lon * lon_unit); lat_sign = -1;
// lat = 0x80000000 - lat; //not sure why this doesn't work here like it does on lon, extra bit?
}
if (lon & 0x80000000)
{
lon = lon & 0x7FFFFFFF;
lon_sign = -1;
lon = 0x80000000 - lon;
}
lat_fin = (double)lat * lat_unit * lat_sign;
lon_fin = (double)lon * lon_unit * lon_sign;
fprintf (stderr, " LRRP - Lat: %.5lf", lat_fin);
fprintf (stderr, " Lon: %.5lf", lon_fin);
fprintf (stderr, " (%.5lf, %.5lf)", lat_fin , lon_fin);
if (opts->lrrp_file_output == 1) if (opts->lrrp_file_output == 1)
{ {
if (lat_sign) fprintf (pFile, "-"); fprintf (pFile, "%.5lf\t", lat_fin);
fprintf (pFile, "%.5lf\t", (double)lat * lat_unit); fprintf (pFile, "%.5lf\t", lon_fin);
fprintf (pFile, "%.5lf\t", (double)lon * lon_unit);
} }
} }
if (rad) if (rad)
{ {
fprintf (stderr, "\n"); fprintf (stderr, "\n");
fprintf (stderr, " LRRP - Radius: %d", rad); //unsure of 'units' or calculation for radius (meters?) fprintf (stderr, " LRRP - Radius: %dm", rad); //unsure of 'units' or calculation for radius (meters?)
} }
if (alt) if (alt)
{ {
fprintf (stderr, "\n"); fprintf (stderr, "\n");
fprintf (stderr, " LRRP - Altitude: %d", alt); //unsure of 'units' or calculation for alt (meters?) fprintf (stderr, " LRRP - Altitude: %dm", alt); //unsure of 'units' or calculation for alt (meters?)
} }
if (vel_set) if (vel_set)
{ {
@@ -362,7 +375,7 @@ uint8_t dmr_lrrp (dsd_opts * opts, dsd_state * state, uint8_t block_len, uint8_t
if (deg_set) if (deg_set)
{ {
fprintf (stderr, "\n"); fprintf (stderr, "\n");
fprintf (stderr, " LRRP - Track: %d Degrees", degrees); fprintf (stderr, " LRRP - Track: %d%s", degrees, deg_glyph);
if (opts->lrrp_file_output == 1) fprintf (pFile, "%d\t",degrees); if (opts->lrrp_file_output == 1) fprintf (pFile, "%d\t",degrees);
} }
@@ -373,20 +386,17 @@ uint8_t dmr_lrrp (dsd_opts * opts, dsd_state * state, uint8_t block_len, uint8_t
fclose (pFile); fclose (pFile);
} }
//save to array for ncurses //save to string for ncurses
if (!source) source = state->dmr_lrrp_source[state->currentslot]; if (!source) source = state->dmr_lrrp_source[state->currentslot];
char sign[8];
char velstr[20]; char velstr[20];
char degstr[20]; char degstr[20];
char lrrpstr[100]; char lrrpstr[100];
sprintf (lrrpstr, "%s", ""); sprintf (lrrpstr, "%s", "");
sprintf (velstr, "%s", ""); sprintf (velstr, "%s", "");
sprintf (degstr, "%s", ""); sprintf (degstr, "%s", "");
if (lat_sign) sprintf (sign, "%s", "-"); if (lat) sprintf (lrrpstr, "LRRP %0d (%lf, %lf)", source, lat_fin, lon_fin);
else sprintf (sign, "%s", "");
if (lat) sprintf (lrrpstr, "LRRP %0d (%s%lf, %lf)", source, sign, (double)lat * lat_unit, (double)lon * lon_unit);
if (vel_set) sprintf (velstr, " %.4lf km/h", velocity * 3.6); if (vel_set) sprintf (velstr, " %.4lf km/h", velocity * 3.6);
if (deg_set) sprintf (degstr, " %d deg", degrees); if (deg_set) sprintf (degstr, " %d%s ", degrees, deg_glyph);
sprintf (state->dmr_lrrp_gps[slot], "%s%s%s", lrrpstr, velstr, degstr); sprintf (state->dmr_lrrp_gps[slot], "%s%s%s", lrrpstr, velstr, degstr);
} }
@@ -399,16 +409,126 @@ uint8_t dmr_lrrp (dsd_opts * opts, dsd_state * state, uint8_t block_len, uint8_t
fprintf (stderr, " Potential ARRP/LRRP Report (Debug): 0x%02X", report); fprintf (stderr, " Potential ARRP/LRRP Report (Debug): 0x%02X", report);
} }
// else //debug only, disabled
// {
// fprintf (stderr, "\n");
// fprintf (stderr, "\n LRRP Confidence: %d - Message Len: %d Octets", lrrp_confidence, message_len);
// }
LRRP_END: LRRP_END:
fprintf (stderr, "%s", KNRM); fprintf (stderr, "%s", KNRM);
}
return (lrrp_confidence);
void dmr_locn (dsd_opts * opts, dsd_state * state, uint8_t block_len, uint8_t DMR_PDU[])
{
int i, j;
uint8_t slot = state->currentslot;
uint8_t blocks = state->data_header_blocks[slot];
uint8_t padding = state->data_header_padding[slot];
uint8_t source = state->dmr_lrrp_source[slot];
//flags if certain data type is present
uint8_t time = 0;
uint8_t lat = 0;
uint8_t lon = 0;
//date-time variables
uint8_t hour = 0;
uint8_t minute = 0;
uint8_t second = 0;
uint8_t year = 0;
uint8_t month = 0;
uint8_t day = 0;
//need to experiment best way to do this portion
uint8_t lat_deg = 0;
uint8_t lat_min = 0;
uint16_t lat_sec = 0;
uint8_t lon_deg = 0;
uint8_t lon_min = 0;
uint16_t lon_sec = 0;
char lat_ord[2];
char lon_ord[2];
sprintf (lat_ord, "%s", "N");
sprintf (lon_ord, "%s", "E");
char deg_glyph[4];
sprintf (deg_glyph, "%s", "°");
// sprintf (deg_glyph, "%s", "d");
//more strings...
char locnstr[50];
char latstr[75];
char lonstr[75];
sprintf (locnstr, "%s", " ");
sprintf (latstr, "%s", " ");
sprintf (lonstr, "%s", " ");
//TODO: conversion to decimal format
//DD = d + (min/60) + (sec/3600)
//N is positive, E is positive?? Assuming its like a 2D plane
int lat_sign = 1; //positive 1 or negative 1
int lon_sign = 1; //positive 1 or negative 1
double lat_fin = 0;
double lon_fin = 0;
//start looking for specific bytes corresponding to 'letters' A (time), NSEW (ordinal directions), etc
for (i = 0; i < ( (blocks*block_len) - (padding+4) ); i++)
{
switch(DMR_PDU[i]){
case 0x41: //A -- time and date
time = 1;
hour = ((DMR_PDU[i+1] - 0x30) << 4) | (DMR_PDU[i+2] - 0x30);
minute = ((DMR_PDU[i+3] - 0x30) << 4) | (DMR_PDU[i+4] - 0x30);
second = ((DMR_PDU[i+5] - 0x30) << 4) | (DMR_PDU[i+6] - 0x30);
//think this is in day, mon, year format
day = ((DMR_PDU[i+7] - 0x30) << 4) | (DMR_PDU[i+8] - 0x30);
month = ((DMR_PDU[i+9] - 0x30) << 4) | (DMR_PDU[i+10] - 0x30);
year = ((DMR_PDU[i+11] - 0x30) << 4) | (DMR_PDU[i+12] - 0x30);
i += 12;
break;
case 0x53: //S -- South
sprintf (lat_ord, "%s", "S");
lat_sign = -1;
case 0x4E: //N -- North
lat = 1;
lat_deg = ((DMR_PDU[i+1] - 0x30) << 4) | (DMR_PDU[i+2] - 0x30);
lat_min = ((DMR_PDU[i+3] - 0x30) << 4) | (DMR_PDU[i+4] - 0x30);
lat_sec = ((DMR_PDU[i+6] - 0x30) << 12) | ((DMR_PDU[i+7] - 0x30) << 8) | ((DMR_PDU[i+8] - 0x30) << 4) | ((DMR_PDU[i+9] - 0x30) << 0);
i += 8;
break;
case 0x57: //W -- West
sprintf (lon_ord, "%s", "W");
lon_sign = -1;
case 0x45: //E -- East
lon = 1;
lon_deg = ((DMR_PDU[i+1] - 0x30) << 8) | ((DMR_PDU[i+2] - 0x30) << 4) | ((DMR_PDU[i+3] - 0x30) << 0);
lon_min = ((DMR_PDU[i+4] - 0x30) << 4) | (DMR_PDU[i+5] - 0x30);
lon_sec = ((DMR_PDU[i+7] - 0x30) << 12) | ((DMR_PDU[i+8] - 0x30) << 8) | ((DMR_PDU[i+9] - 0x30) << 4) | ((DMR_PDU[i+10] - 0x30) << 0);
i += 8;
break;
default:
//do nothing
break;
} //end switch
} //for i
if (lat && lon)
{
fprintf (stderr, "%s", KYEL);
fprintf (stderr, "\n LOCN Report - Source: [%d]\n", source);
if (time) fprintf (stderr, " 20%02X/%02X/%02X %02X:%02X:%02X ", year, month, day, hour, minute, second);
fprintf (stderr, "Lat: %s %02X%s%02X\"%04X' Lon: %s %02X%s%02X\"%04X' ", lat_ord, lat_deg, deg_glyph, lat_min, lat_sec, lon_ord, lon_deg, deg_glyph, lon_min, lon_sec);
//string manip for ncurses terminal display
sprintf (locnstr, "LOCN %d ", source);
sprintf (latstr, "%s %02X%s%02X\"%04X' ", lat_ord, lat_deg, deg_glyph, lat_min, lat_sec);
sprintf (lonstr, "%s %02X%s%02X\"%04X' ", lon_ord, lon_deg, deg_glyph, lon_min, lon_sec);
sprintf (state->dmr_lrrp_gps[slot], "%s%s%s", locnstr, latstr, lonstr);
}
} }

View File

@@ -14,80 +14,63 @@ void dmr_pi (dsd_opts * opts, dsd_state * state, uint8_t PI_BYTE[], uint32_t CRC
{ {
if((IrrecoverableErrors == 0)) if((IrrecoverableErrors == 0))
{
if (state->currentslot == 0)
{ {
if (0 == 0) if (state->currentslot == 0)
{ {
state->payload_algid = PI_BYTE[0]; state->payload_algid = PI_BYTE[0];
state->payload_keyid = PI_BYTE[2]; state->payload_keyid = PI_BYTE[2];
}
state->payload_mi = ( ((PI_BYTE[3]) << 24) + ((PI_BYTE[4]) << 16) + ((PI_BYTE[5]) << 8) + (PI_BYTE[6]) ); state->payload_mi = ( ((PI_BYTE[3]) << 24) + ((PI_BYTE[4]) << 16) + ((PI_BYTE[5]) << 8) + (PI_BYTE[6]) );
if (state->payload_algid < 0x26) if (state->payload_algid < 0x26)
{ {
fprintf (stderr, "%s ", KYEL); fprintf (stderr, "%s ", KYEL);
fprintf (stderr, "\n Slot 1"); fprintf (stderr, "\n Slot 1");
fprintf (stderr, " DMR PI Header ALG ID: 0x%02X KEY ID: 0x%02X MI: 0x%08X", state->payload_algid, state->payload_keyid, state->payload_mi); fprintf (stderr, " DMR PI H- ALG ID: 0x%02X KEY ID: 0x%02X MI: 0x%08X", state->payload_algid, state->payload_keyid, state->payload_mi);
fprintf (stderr, "%s ", KNRM); fprintf (stderr, "%s ", KNRM);
if (state->payload_algid != 0x21)
{
fprintf (stderr, "\n");
LFSR64 (state);
}
} }
if (state->payload_algid >= 0x26) if (state->payload_algid >= 0x26)
{
if (0 == 0)
{ {
state->payload_algid = 0; state->payload_algid = 0;
state->payload_keyid = 0; state->payload_keyid = 0;
state->payload_mi = 0; state->payload_mi = 0;
} }
} }
}
if (state->currentslot == 1) if (state->currentslot == 1)
{ {
if (0 == 0)
{
state->payload_algidR = PI_BYTE[0]; state->payload_algidR = PI_BYTE[0];
state->payload_keyidR = PI_BYTE[2]; state->payload_keyidR = PI_BYTE[2];
}
state->payload_miR = ( ((PI_BYTE[3]) << 24) + ((PI_BYTE[4]) << 16) + ((PI_BYTE[5]) << 8) + (PI_BYTE[6]) ); state->payload_miR = ( ((PI_BYTE[3]) << 24) + ((PI_BYTE[4]) << 16) + ((PI_BYTE[5]) << 8) + (PI_BYTE[6]) );
if (state->payload_algidR < 0x26) if (state->payload_algidR < 0x26)
{ {
fprintf (stderr, "%s ", KYEL); fprintf (stderr, "%s ", KYEL);
fprintf (stderr, "\n Slot 2"); fprintf (stderr, "\n Slot 2");
fprintf (stderr, " DMR PI Header ALG ID: 0x%02X KEY ID: 0x%02X MI: 0x%08X", state->payload_algidR, state->payload_keyidR, state->payload_miR); fprintf (stderr, " DMR PI H- ALG ID: 0x%02X KEY ID: 0x%02X MI: 0x%08X", state->payload_algidR, state->payload_keyidR, state->payload_miR);
fprintf (stderr, "%s ", KNRM); fprintf (stderr, "%s ", KNRM);
if (state->payload_algidR != 0x21)
{
fprintf (stderr, "\n");
LFSR64 (state);
}
} }
if (state->payload_algidR >= 0x26) if (state->payload_algidR >= 0x26)
{
if (0== 0)
{ {
state->payload_algidR = 0; state->payload_algidR = 0;
state->payload_keyidR = 0; state->payload_keyidR = 0;
state->payload_miR = 0; state->payload_miR = 0;
} }
}
}
} }
if((IrrecoverableErrors == 0) && CRCCorrect)
{
//fprintf (stderr, " (PI CRC Okay)");
} }
else if((IrrecoverableErrors == 0))
{
//fprintf (stderr, " (PI FEC Okay)");
}
else {
fprintf (stderr, "%s", KRED);
fprintf (stderr, (" (PI FEC ERR)"));
fprintf (stderr, "%s ", KNRM);
}
} }
void LFSR(dsd_state * state) void LFSR(dsd_state * state)
@@ -109,28 +92,68 @@ void LFSR(dsd_state * state)
} }
if (state->currentslot == 0) if (state->currentslot == 0)
{
if (1 == 1)
{ {
fprintf (stderr, "%s", KYEL); fprintf (stderr, "%s", KYEL);
fprintf (stderr, " Slot 1"); fprintf (stderr, " Slot 1");
fprintf (stderr, " DMR PI Continuation ALG ID: 0x%02X KEY ID: 0x%02X", state->payload_algid, state->payload_keyid); fprintf (stderr, " DMR PI C- ALG ID: 0x%02X KEY ID: 0x%02X", state->payload_algid, state->payload_keyid);
fprintf(stderr, " Next MI: 0x%08X", lfsr); fprintf(stderr, " MI: 0x%08X", lfsr);
fprintf (stderr, "%s", KNRM); fprintf (stderr, "%s", KNRM);
}
state->payload_mi = lfsr; state->payload_mi = lfsr;
} }
if (state->currentslot == 1) if (state->currentslot == 1)
{ {
if (1 == 1)
{
fprintf (stderr, "%s", KYEL); fprintf (stderr, "%s", KYEL);
fprintf (stderr, " Slot 2"); fprintf (stderr, " Slot 2");
fprintf (stderr, " DMR PI Continuation ALG ID: 0x%02X KEY ID: 0x%02X", state->payload_algidR, state->payload_keyidR); fprintf (stderr, " DMR PI C- ALG ID: 0x%02X KEY ID: 0x%02X", state->payload_algidR, state->payload_keyidR);
fprintf(stderr, " Next MI: 0x%08X", lfsr); fprintf(stderr, " MI: 0x%08X", lfsr);
fprintf (stderr, "%s", KNRM); fprintf (stderr, "%s", KNRM);
}
state->payload_miR = lfsr; state->payload_miR = lfsr;
} }
} }
void LFSR64(dsd_state * state)
{
{
uint64_t lfsr = 0;
if (state->currentslot == 0)
{
lfsr = (uint64_t) state->payload_mi;
}
else lfsr = (uint64_t) state->payload_miR;
uint8_t cnt = 0;
for(cnt=0;cnt<32;cnt++)
{
uint64_t bit = ( (lfsr >> 31) ^ (lfsr >> 21) ^ (lfsr >> 1) ^ (lfsr >> 0) ) & 0x1;
lfsr = (lfsr << 1) | bit;
}
// if (state->currentslot == 0) state->payload_miP = lfsr;
// else state->payload_miN = lfsr;
if (state->currentslot == 0)
{
fprintf (stderr, "%s", KYEL);
fprintf (stderr, " Slot 1");
fprintf (stderr, " DMR PI C- ALG ID: 0x%02X KEY ID: 0x%02X", state->payload_algid, state->payload_keyid);
fprintf (stderr, " MI: 0x%016lX", lfsr);
fprintf (stderr, "%s", KNRM);
state->payload_mi = lfsr & 0xFFFFFFFF; //truncate for next repitition and le verification
}
if (state->currentslot == 1)
{
fprintf (stderr, "%s", KYEL);
fprintf (stderr, " Slot 2");
fprintf (stderr, " DMR PI C- ALG ID: 0x%02X KEY ID: 0x%02X", state->payload_algidR, state->payload_keyidR);
fprintf (stderr, " MI: 0x%016lX", lfsr);
fprintf (stderr, "%s", KNRM);
state->payload_miR = lfsr & 0xFFFFFFFF; //truncate for next repitition and le verification
}
}
}

View File

@@ -4,7 +4,7 @@
//Original Source - https://github.com/LouisErigHerve/dsd //Original Source - https://github.com/LouisErigHerve/dsd
//Additional Functions //Additional Functions
//Hamming17123, crc8, crc8ok functions //Hamming17123, crc7, crc8, crc8ok functions
//Original Souce - https://github.com/boatbod/op25 //Original Souce - https://github.com/boatbod/op25
#include "dsd.h" #include "dsd.h"
@@ -121,6 +121,31 @@ bool crc8_ok(uint8_t bits[], unsigned int len)
return (crc == crc8(bits,len)); return (crc == crc8(bits,len));
} }
uint8_t crc7(uint8_t bits[], unsigned int len)
{
uint8_t crc=0;
unsigned int K = 7;
//G7(x) = x7 + x5 + x2 + x + 1 check poly below for correct (dmr rc crc7)
uint8_t poly[8] = {1,0,1,0,0,1,1,1}; // crc7 poly
uint8_t buf[256];
if (len+K > sizeof(buf)) {
// fprintf (stderr, "crc8: buffer length %u exceeds maximum %lu\n", len+K, sizeof(buf));
return 0;
}
memset (buf, 0, sizeof(buf));
for (unsigned int i=0; i<len; i++){
buf[i] = bits[i];
}
for (unsigned int i=0; i<len; i++)
if (buf[i])
for (unsigned int j=0; j<K+1; j++)
buf[i+j] ^= poly[j];
for (unsigned int i=0; i<K; i++){
crc = (crc << 1) + buf[len + i];
}
return crc;
}
/* /*
* @brief : This function compute the CRC-CCITT of the DMR data * @brief : This function compute the CRC-CCITT of the DMR data
* by using the polynomial x^16 + x^12 + x^5 + 1 * by using the polynomial x^16 + x^12 + x^5 + 1
@@ -330,3 +355,86 @@ uint32_t ConvertBitIntoBytes(uint8_t * BufferIn, uint32_t BitLength)
* *
* @return The 9 bit CRC * @return The 9 bit CRC
*/ */
uint16_t ComputeCrc9Bit(uint8_t * DMRData, uint32_t NbData)
{
uint32_t i;
uint16_t CRC = 0x0000; /* Initialization value = 0x0000 */
/* Polynomial x^9 + x^6 + x^4 + x^3 + 1
* Normal = 0x059
* Reciprocal = 0x134
* Reversed reciprocal = 0x12C */
uint16_t Polynome = 0x059;
for(i = 0; i < NbData; i++)
{
if(((CRC >> 8) & 1) ^ (DMRData[i] & 1))
{
CRC = (CRC << 1) ^ Polynome;
}
else
{
CRC <<= 1;
}
}
/* Conserve only the 9 LSBs */
CRC &= 0x01FF;
/* Invert the CRC */
CRC ^= 0x01FF;
/* Return the CRC */
return CRC;
} /* End ComputeCrc9Bit() */
/*
* @brief : This function compute the CRC-32 of the DMR data
* by using the polynomial x^32 + x^26 + x^23 + x^22 + x^16 + x^12 + x^11 + x^10 + x^8 + x^7 + x^5 + x^4 + x^2 + x + 1
*
* @param Input : A buffer pointer of the DMR data (80 bytes)
* Rate 1/2 coded confirmed (10 data octets): 80 bit sequence (80 bytes)
* Rate 3/4 coded confirmed (16 data octets): 128 bit sequence (120 bytes)
* Rate 1 coded confirmed (22 data octets): 176 bit sequence (176 bytes)
*
* @param NbData : The number of bit to compute
* Rate 1/2 coded confirmed (10 data octets): 80 bit sequence (80 bytes)
* Rate 3/4 coded confirmed (16 data octets): 128 bit sequence (120 bytes)
* Rate 1 coded confirmed (22 data octets): 176 bit sequence (176 bytes)
*
* @return The 32 bit CRC
*/
uint32_t ComputeCrc32Bit(uint8_t * DMRData, uint32_t NbData)
{
uint32_t i;
uint32_t CRC = 0x00000000; /* Initialization value = 0x00000000 */
/* Polynomial x^32 + x^26 + x^23 + x^22 + x^16 + x^12 + x^11 + x^10 + x^8 + x^7 + x^5 + x^4 + x^2 + x + 1
* Normal = 0x04C11DB7
* Reversed = 0xEDB88320
* Reciprocal = 0xDB710641
* Reversed reciprocal = 0x82608EDB */
uint32_t Polynome = 0x04C11DB7;
for(i = 0; i < NbData; i++)
{
if(((CRC >> 31) & 1) ^ (DMRData[i] & 1))
{
CRC = (CRC << 1) ^ Polynome;
}
else
{
CRC <<= 1;
}
}
//for whatever reason, we get the CRC returned in a reversed byte order (MSO LSO b***s***)
uint32_t a, b, c, d;
a = b = c = d = 0;
a = (CRC & 0xFF) << 24;
b = (CRC & 0xFF00) >> 8;
b = b << 16;
c = (CRC & 0xFF0000) >> 16;
c = c << 8;
d = (CRC & 0xFF000000) >> 24;
CRC = a + b + c + d;
/* Return the CRC */
return CRC;
} /* End ComputeCrc32Bit() */

View File

@@ -24,11 +24,18 @@ void processdPMRvoice (dsd_opts * opts, dsd_state * state)
uint8_t CCH[NB_OF_DPMR_VOICE_FRAME_TO_DECODE][72] = {0}; uint8_t CCH[NB_OF_DPMR_VOICE_FRAME_TO_DECODE][72] = {0};
uint8_t CCHDescrambled[NB_OF_DPMR_VOICE_FRAME_TO_DECODE][72] = {0}; uint8_t CCHDescrambled[NB_OF_DPMR_VOICE_FRAME_TO_DECODE][72] = {0};
uint8_t CCHDeInterleaved[NB_OF_DPMR_VOICE_FRAME_TO_DECODE][72] = {0}; uint8_t CCHDeInterleaved[NB_OF_DPMR_VOICE_FRAME_TO_DECODE][72] = {0};
uint8_t CCHDataHammingCorrected[NB_OF_DPMR_VOICE_FRAME_TO_DECODE][48] = {0}; uint8_t CCHDataHammingCorrected[NB_OF_DPMR_VOICE_FRAME_TO_DECODE][48];
uint8_t CCHDataCRC[NB_OF_DPMR_VOICE_FRAME_TO_DECODE] = {0}; uint8_t CCHDataCRC[NB_OF_DPMR_VOICE_FRAME_TO_DECODE];
uint8_t CCHDataCRCComputed[NB_OF_DPMR_VOICE_FRAME_TO_DECODE] = {0};
memset (CCHDataHammingCorrected, 1, sizeof(CCHDataHammingCorrected));
memset (CCHDataCRC, 1, sizeof(CCHDataCRC));
uint8_t CCHDataCRCComputed[NB_OF_DPMR_VOICE_FRAME_TO_DECODE];
memset (CCHDataCRCComputed, 0, sizeof(CCHDataCRCComputed));
uint8_t CC[NB_OF_DPMR_VOICE_FRAME_TO_DECODE / 2][24] = {0}; uint8_t CC[NB_OF_DPMR_VOICE_FRAME_TO_DECODE / 2][24] = {0};
char ambe_fr[NB_OF_DPMR_VOICE_FRAME_TO_DECODE * 4][4][24] = {0}; char ambe_fr[NB_OF_DPMR_VOICE_FRAME_TO_DECODE * 4][4][24];
memset (ambe_fr, 0, sizeof (ambe_fr));
const int *w, *x, *y, *z; const int *w, *x, *y, *z;
uint32_t ScramblerLFSR = 0; uint32_t ScramblerLFSR = 0;
bool correctable = true; bool correctable = true;
@@ -56,11 +63,6 @@ void processdPMRvoice (dsd_opts * opts, dsd_state * state)
uint8_t CalledID[8] = {0}; uint8_t CalledID[8] = {0};
uint8_t CallingID[8] = {0}; uint8_t CallingID[8] = {0};
if (opts->errorbars == 1)
{
//fprintf(stderr, "VOICE e:");
}
/* First CCH (Control CHannel) - 72 bit */ /* First CCH (Control CHannel) - 72 bit */
k = 0; k = 0;
@@ -76,7 +78,6 @@ void processdPMRvoice (dsd_opts * opts, dsd_state * state)
CCH[0][(i * 2)] = (1 & (dibit >> 1)); // bit 1 CCH[0][(i * 2)] = (1 & (dibit >> 1)); // bit 1
CCH[0][(i * 2) + 1] = (1 & dibit); // bit 0 CCH[0][(i * 2) + 1] = (1 & dibit); // bit 0
} }
/* 4 TCH (Traffic CHannel) = 4 x 72 bit voice playload */ /* 4 TCH (Traffic CHannel) = 4 x 72 bit voice playload */
@@ -148,9 +149,6 @@ void processdPMRvoice (dsd_opts * opts, dsd_state * state)
/* 4 TCH (Traffic CHannel) = 4 x 72 bit voice playload */ /* 4 TCH (Traffic CHannel) = 4 x 72 bit voice playload */
//Sync issues occur when FS2 occurs immediatly after the 4th rep, so cutting of 4 early to gain constant resync
//probably can't resync fast enough when the next sync starts immediately after the 4th rep of 36 dibits
//consider writing a method that will loop this entire process based on the frame numbering found inside the CCH info, is that possible?
k = 0; k = 0;
for (j = 0; j < 4; j++) for (j = 0; j < 4; j++)
{ {
@@ -177,15 +175,9 @@ void processdPMRvoice (dsd_opts * opts, dsd_state * state)
x++; x++;
y++; y++;
z++; z++;
//should be fixed now with the frame_sync t_max setup
//no more early breaking required
}
}
/* Initialize the Hamming (12,8) error code detection }
* Not needed because it has already been done }
* in the "InitAllFecFunction()" function */
//Hamming_12_8_init();
/* Decoding all CCH (Control CHannel) */ /* Decoding all CCH (Control CHannel) */
for(i = 0; i < NB_OF_DPMR_VOICE_FRAME_TO_DECODE; i++) for(i = 0; i < NB_OF_DPMR_VOICE_FRAME_TO_DECODE; i++)
@@ -207,22 +199,8 @@ void processdPMRvoice (dsd_opts * opts, dsd_state * state)
if(HammingCorrectable[i][j] == false) correctable = false; if(HammingCorrectable[i][j] == false) correctable = false;
} }
if(correctable) if(correctable) HammingOk[i] = 1;
{ else HammingOk[i] = 0;
//fprintf(stderr, "CCH data corrected successfully\n");
HammingOk[i] = 1;
}
else
{
//fprintf(stderr, "ERROR !!! CCH data contains uncorrectable bit\n");
HammingOk[i] = 0;
}
/* Reconstitute the 7 bit CRC */ /* Reconstitute the 7 bit CRC */
CCHDataCRC[i] = 0; CCHDataCRC[i] = 0;
@@ -237,24 +215,8 @@ void processdPMRvoice (dsd_opts * opts, dsd_state * state)
/* Compute the 7 bit CRC */ /* Compute the 7 bit CRC */
CCHDataCRCComputed[i] = CRC7BitdPMR(CCHDataHammingCorrected[i], 41); CCHDataCRCComputed[i] = CRC7BitdPMR(CCHDataHammingCorrected[i], 41);
if(CCHDataCRC[i] == CCHDataCRCComputed[i]) if(CCHDataCRC[i] == CCHDataCRCComputed[i]) CrcOk[i] = 1;
{ else CrcOk[i] = 0;
//fprintf(stderr, "Good CCH CRCs ! CRC received = 0x%02X, CRC computed = 0x%02X\n",
// CCHDataCRC[i], CCHDataCRCComputed[i]);
CrcOk[i] = 1;
}
else
{
//fprintf(stderr, "ERROR !!! CCH CRCs are different ! CRC received = 0x%02X, CRC computed = 0x%02X\n",
// CCHDataCRC[i], CCHDataCRCComputed[i]);
CrcOk[i] = 0;
}
/* Fill the frame number */ /* Fill the frame number */
CCH_FrameNumber[i] = ConvertBitIntoBytes(&CCHDataHammingCorrected[i][0], 2); CCH_FrameNumber[i] = ConvertBitIntoBytes(&CCHDataHammingCorrected[i][0], 2);
@@ -300,45 +262,18 @@ void processdPMRvoice (dsd_opts * opts, dsd_state * state)
CallingID[7] = '\0'; CallingID[7] = '\0';
/* Print Hamming debug info */
//fprintf(stderr, " | ");
for(i = 0; i < NB_OF_DPMR_VOICE_FRAME_TO_DECODE; i++)
{
//fprintf(stderr, "Hamming[%u]=", i);
for(j = 0; j < 6; j++)
{
//if(HammingCorrectable[i][j]) fprintf(stderr, "1");
//else fprintf(stderr, "0");
}
//fprintf(stderr, " HammingOk[%u]=%u", i, HammingOk[i]);
//fprintf(stderr, " CrcOk[%u]=%u", i, CrcOk[i]);
//fprintf(stderr, " Bit[%u]=", i);
//for(j = 0; j < 7; j++)
//{
// if(CCHDataHammingCorrected[i][j + 41]) fprintf(stderr, "1");
// else fprintf(stderr, "0");
//}
//fprintf(stderr, " CRCrec=0x%02X CRCcomp=0x%02X", CCHDataCRC[i], CCHDataCRCComputed[i]);
//if(i < (NB_OF_DPMR_VOICE_FRAME_TO_DECODE - 1)) fprintf(stderr, " - ");
}
#if (NB_OF_DPMR_VOICE_FRAME_TO_DECODE == 2)
/* To determine the part of the payload frame, we need to check the /* To determine the part of the payload frame, we need to check the
* Hamming code result, the CRC and the frame number */ * Hamming code result, the CRC and the frame number */
// if( (HammingOk[0] && CrcOk[0] && (CCH_FrameNumber[0] == 0)) || // if( (HammingOk[0] && CrcOk[0] && (CCH_FrameNumber[0] == 0)) ||
// (HammingOk[1] && CrcOk[1] && (CCH_FrameNumber[1] == 1))) // (HammingOk[1] && CrcOk[1] && (CCH_FrameNumber[1] == 1)))
if(((CrcOk[0] || HammingCorrectable[0][0]) && (CCH_FrameNumber[0] == 0)) || if(((CrcOk[0] || HammingCorrectable[0][0]) && (CCH_FrameNumber[0] == 0)) ||
((CrcOk[1] || HammingCorrectable[1][0]) && (CCH_FrameNumber[1] == 1))) ((CrcOk[1] || HammingCorrectable[1][0]) && (CCH_FrameNumber[1] == 1)))
{ {
/* First part of the super frame */ /* First part of the super frame */
PartOfSuperFrame = 1; PartOfSuperFrame = 1;
//fprintf(stderr, "\nFirst part of the Super Frame");
/* The next part will normally be the second part */ /* The next part will normally be the second part */
opts->dPMR_next_part_of_superframe = 2; opts->dPMR_next_part_of_superframe = 2;
@@ -366,20 +301,19 @@ void processdPMRvoice (dsd_opts * opts, dsd_state * state)
/* BUGFIX : Copy in all case the TG ID */ /* BUGFIX : Copy in all case the TG ID */
strcpy((char *)state->dPMRVoiceFS2Frame.CalledID, (char *)CalledID); strcpy((char *)state->dPMRVoiceFS2Frame.CalledID, (char *)CalledID);
} }
/* To determine the part of the payload frame, we need to check the /* To determine the part of the payload frame, we need to check the
* Hamming code result, the CRC and the frame number */ * Hamming code result, the CRC and the frame number */
// else if( (HammingOk[0] && CrcOk[0] && (CCH_FrameNumber[0] == 2)) || // else if( (HammingOk[0] && CrcOk[0] && (CCH_FrameNumber[0] == 2)) ||
// (HammingOk[1] && CrcOk[1] && (CCH_FrameNumber[1] == 3))) // (HammingOk[1] && CrcOk[1] && (CCH_FrameNumber[1] == 3)))
else if(((CrcOk[0] || HammingCorrectable[0][0]) && (CCH_FrameNumber[0] == 2)) || else if(((CrcOk[0] || HammingCorrectable[0][0]) && (CCH_FrameNumber[0] == 2)) ||
((CrcOk[1] || HammingCorrectable[1][0]) && (CCH_FrameNumber[1] == 3))) ((CrcOk[1] || HammingCorrectable[1][0]) && (CCH_FrameNumber[1] == 3)))
{ {
/* Second part of the super frame */ /* Second part of the super frame */
PartOfSuperFrame = 2; PartOfSuperFrame = 2;
//fprintf(stderr, "\nSecond part of the Super Frame");
/* The next part will normally be the first part */ /* The next part will normally be the first part */
opts->dPMR_next_part_of_superframe = 1; opts->dPMR_next_part_of_superframe = 1;
@@ -392,7 +326,9 @@ void processdPMRvoice (dsd_opts * opts, dsd_state * state)
CallingID[7] = '\0'; CallingID[7] = '\0';
/* Determine if the calling SRC ID is correct */ /* Determine if the calling SRC ID is correct */
//if(HammingOk[0] && CrcOk[0] && HammingOk[1] && CrcOk[1]) //if(HammingOk[0] && CrcOk[0] && HammingOk[1] && CrcOk[1])
if((CrcOk[0] || (HammingCorrectable[0][0] && HammingCorrectable[0][1])) && if((CrcOk[0] || (HammingCorrectable[0][0] && HammingCorrectable[0][1])) &&
(CrcOk[1] || (HammingCorrectable[1][0] && HammingCorrectable[1][1]))) (CrcOk[1] || (HammingCorrectable[1][0] && HammingCorrectable[1][1])))
{ {
@@ -420,133 +356,144 @@ void processdPMRvoice (dsd_opts * opts, dsd_state * state)
/* Set the next part of the superframe to receive */ /* Set the next part of the superframe to receive */
if(opts->dPMR_next_part_of_superframe == 1) if(opts->dPMR_next_part_of_superframe == 1)
{ {
//fprintf(stderr, "Supposed first part of the Super Frame\n");
/* Set the next part as the second part */ /* Set the next part as the second part */
opts->dPMR_next_part_of_superframe = 2; opts->dPMR_next_part_of_superframe = 2;
} }
else if(opts->dPMR_next_part_of_superframe == 2) else if(opts->dPMR_next_part_of_superframe == 2)
{ {
//fprintf(stderr, "Supposed second part of the Super Frame\n");
/* Set the next part as the first part */ /* Set the next part as the first part */
opts->dPMR_next_part_of_superframe = 1; opts->dPMR_next_part_of_superframe = 1;
} }
else else
{ {
//fprintf(stderr, "Unknown part of the Super Frame\n");
/* Unknown current part, set to 0 */ /* Unknown current part, set to 0 */
opts->dPMR_next_part_of_superframe = 0; opts->dPMR_next_part_of_superframe = 0;
} }
} }
if(state->dPMRVoiceFS2Frame.ColorCode[0] != (unsigned int)(-1))
{
//only print the CC and src/tg info if CRC is good
/* Display the color code */
//fprintf(stderr, " | Color Code=%02d ", (int)state->dPMRVoiceFS2Frame.ColorCode[0]);
}
else
{
/* Unknown color code, display "??" */
//fprintf(stderr, " | Color Code=?? ");
}
/* Display the destination ID (talk group - TG) */ /* Display the destination ID (talk group - TG) */
//fprintf(stderr, "| TG=%s", CalledID); fprintf (stderr, "\n");
if(state->dPMRVoiceFS2Frame.CalledIDOk) if(state->dPMRVoiceFS2Frame.CalledIDOk)
{ {
fprintf (stderr, "%s", KGRN); fprintf (stderr, "%s", KGRN);
fprintf(stderr, "\n| TG=%s", CalledID); fprintf(stderr, " TG=%s", CalledID);
fprintf (stderr, "%s", KNRM); fprintf (stderr, "%s", KNRM);
//strcpy (state->dpmr_target_id, CalledID); //HERE HERE
state->dpmr_target_id = CalledID;
//fprintf(stderr, " (CRC OK) ");
if(state->dPMRVoiceFS2Frame.ColorCode[0] != (unsigned int)(-1))
{
fprintf (stderr, "%s", KGRN);
fprintf(stderr, " | Color Code=%02d ", (int)state->dPMRVoiceFS2Frame.ColorCode[0]);
fprintf (stderr, "%s", KNRM);
state->dpmr_color_code = (int)state->dPMRVoiceFS2Frame.ColorCode[0];
} //check other as well before assigning
if(state->dPMRVoiceFS2Frame.CallingIDOk) sprintf (state->dpmr_target_id, "%s", CalledID);
} }
else else
{
//fprintf(stderr, " (CRC ERR) ");
}
/* Display the source ID */
//fprintf(stderr, "| Src=%s", CallingID);
if(state->dPMRVoiceFS2Frame.CallingIDOk)
{
fprintf (stderr, "%s", KGRN);
fprintf(stderr, "| Src=%s", CallingID);
fprintf (stderr, "%s", KNRM);
//strcpy (state->dpmr_caller_id, CallingID);
state->dpmr_caller_id = CallingID;
//fprintf(stderr, " (CRC OK) \n");
}
else
{ {
fprintf (stderr, "%s", KRED); fprintf (stderr, "%s", KRED);
fprintf(stderr, " (CRC ERR) \n"); fprintf(stderr, " TG=(CRC ERR)");
fprintf (stderr, "%s", KNRM); fprintf (stderr, "%s", KNRM);
} }
#endif /* (NB_OF_DPMR_VOICE_FRAME_TO_DECODE == 2) */ /* Display the source ID */
if(state->dPMRVoiceFS2Frame.CallingIDOk)
{
fprintf (stderr, "%s", KGRN);
fprintf(stderr, " Src=%s", CallingID);
fprintf (stderr, "%s", KNRM);
//check other as well before assigning
if(state->dPMRVoiceFS2Frame.CalledIDOk) sprintf (state->dpmr_caller_id, "%s", CallingID);
//stashed channel code in here, more likely to be correct, but no guarantee
if(state->dPMRVoiceFS2Frame.ColorCode[0] != (unsigned int)(-1))
{
fprintf (stderr, "%s", KGRN);
fprintf(stderr, " Channel Code=%02d", (int)state->dPMRVoiceFS2Frame.ColorCode[0]);
fprintf (stderr, "%s", KNRM);
//check other as well before assigning
if(state->dPMRVoiceFS2Frame.CalledIDOk) state->dpmr_color_code = (int)state->dPMRVoiceFS2Frame.ColorCode[0];
}
}
else
{
fprintf (stderr, "%s", KRED);
fprintf(stderr, " Src=(CRC ERR) Channel Code =(CRC ERR)");
fprintf (stderr, "%s", KNRM);
}
if (state->dPMRVoiceFS2Frame.Version[0] == 3)
{
fprintf (stderr, "%s", KRED);
fprintf (stderr, " Scrambler");
fprintf (stderr, "%s", KNRM);
if (state->R != 0)
{
fprintf (stderr, "%s", KYEL);
fprintf (stderr, " Key %05lld ", state->R );
fprintf (stderr, "%s", KNRM);
}
}
//Play only voice frames by first looking to see if there is a TCH voice in CommunicationMode, //Play only voice frames by first looking to see if there is a TCH voice in CommunicationMode,
//then sending it to be processed by processMbeFrame, its much cleaner this way
short start = 0; short start = 0;
short end = 4; short end = 4;
//not really even sure why I made this loop
//I probably should actually read the manual again
for (short o = 0; o < 2; o++) for (short o = 0; o < 2; o++)
{ {
//reset scrambler key seed on frame 0
if (state->dPMRVoiceFS2Frame.FrameNumbering[o] == 0) state->payload_miN = 0;
//depending on first or second TCH, set start and end variables appropriately //depending on first or second TCH, set start and end variables appropriately
if (o == 1) if (o == 1)
{ {
start = 4; start = 4;
end = 8; end = 8;
//add extra line break on second repitition only when dumping payload to console
if (opts->payload == 1)
{
fprintf(stderr, "\n");
}
} }
//this is used so we can simply pass the voice here to the
//nxdn scrambler by telling mbe these are nxdn frames and to
//apply the same descramble method to them if necessary
int realsynctype = state->synctype;
// fprintf (stderr, "\nCommunication Mode: %d\n", state->dPMRVoiceFS2Frame.CommunicationMode[o]); // fprintf (stderr, "\nCommunication Mode: %d\n", state->dPMRVoiceFS2Frame.CommunicationMode[o]);
//fprintf (stderr, "Encryption Mode: %d\n", state->dPMRVoiceFS2Frame.Version[o]); // fprintf (stderr, "Encryption Mode: %d\n", state->dPMRVoiceFS2Frame.Version[o]); //shows as 3 (manufacturer specific, 5.16) on the dPMR scrambler values received
//fprintf (stderr, "Superframe Number: %d", state->dPMRVoiceFS2Frame.FrameNumbering[o]); //should be 1-4, but may be same number on TCH 1 or TCH 2 // fprintf (stderr, "Superframe Number: %d", state->dPMRVoiceFS2Frame.FrameNumbering[o]);
if((state->dPMRVoiceFS2Frame.CommunicationMode[o] == 0) || if((state->dPMRVoiceFS2Frame.CommunicationMode[o] == 0) ||
(state->dPMRVoiceFS2Frame.CommunicationMode[o] == 1) || (state->dPMRVoiceFS2Frame.CommunicationMode[o] == 1) ||
(state->dPMRVoiceFS2Frame.CommunicationMode[o] == 5)) (state->dPMRVoiceFS2Frame.CommunicationMode[o] == 5))
{ {
//There are 4 AMBE voice samples per TCH //check to see if we are using scrambler
if (state->dPMRVoiceFS2Frame.Version[o] == 3) //!= 0
{
state->synctype = 28; //fake it as nxdn
state->nxdn_cipher_type = 0x01; //turn on nxdn scrambler cipher
state->dmr_encL = 1; //flag on enc bit here so we can mute if no key provided
}
//flag back off if key is provided
if (state->R != 0) state->dmr_encL = 0;
//There are 4 AMBE voice frames per TCH
for(i = start; i < end; i++) for(i = start; i < end; i++)
{ {
processMbeFrame (opts, state, NULL, ambe_fr[i], NULL); processMbeFrame (opts, state, NULL, ambe_fr[i], NULL);
} //End for(i = start; i < end); i++)
} //if comms and not encrypted
}//End for TCH for o loop
if (opts->errorbars == 1)
{
fprintf(stderr, "\n");
} }
//set the correct sync type again and flag off the cipher
state->synctype = realsynctype;
state->nxdn_cipher_type = 0;
}
}
fprintf(stderr, "\n");
//keep code below, could be handy cheat sheet for other info //keep code below, could be handy cheat sheet for other info
#ifdef dPMR_PRINT_DEBUG_INFO #ifdef dPMR_PRINT_DEBUG_INFO
//Display the CCH content //Display the CCH content

View File

@@ -283,9 +283,8 @@ static int digitize (dsd_opts* opts, dsd_state* state, int symbol)
valid = 0; valid = 0;
//only run estimate_symbol when we aren't trunking, otherwise noise/gain levels on other rf channels may impact performance severely //disabling again, causing issues with trunking P25
//honestly can't say I've seen any improvement when using heuristics, but is detrimental to playing back multiple p25 samples if (state->synctype == 1 && opts->p25_trunk == 1)
if (state->synctype == 1 && opts->p25_trunk == 0)
{ {
// Use the P25 heuristics if available // Use the P25 heuristics if available
// valid = estimate_symbol(state->rf_mod, &(state->inv_p25_heuristics), state->last_dibit, symbol, &dibit); // valid = estimate_symbol(state->rf_mod, &(state->inv_p25_heuristics), state->last_dibit, symbol, &dibit);
@@ -348,9 +347,8 @@ static int digitize (dsd_opts* opts, dsd_state* state, int symbol)
valid = 0; valid = 0;
//only run estimate_symbol when we aren't trunking, otherwise noise/gain levels on other rf channels may impact performance severely //disabling again, causing issues with trunking P25
//honestly can't say I've seen any improvement when using heuristics, but is detrimental to playing back multiple p25 samples if (state->synctype == 0 && opts->p25_trunk == 1)
if (state->synctype == 0 && opts->p25_trunk == 0)
{ {
// Use the P25 heuristics if available // Use the P25 heuristics if available
// valid = estimate_symbol(state->rf_mod, &(state->p25_heuristics), state->last_dibit, symbol, &dibit); // valid = estimate_symbol(state->rf_mod, &(state->p25_heuristics), state->last_dibit, symbol, &dibit);

View File

@@ -34,7 +34,7 @@ char * getTimeF(void) //get pretty hh:mm:ss timestamp
} }
char * getDateF(void) { char * getDateF(void) {
char datename[120]; //bug in 32-bit Ubuntu when using date in filename, date is garbage text char datename[80]; //32-bit needs this to be 80
char * curr2; char * curr2;
struct tm * to; struct tm * to;
time_t t; time_t t;
@@ -45,8 +45,7 @@ char * getDateF(void) {
return curr2; return curr2;
} }
void void saveImbe4400Data (dsd_opts * opts, dsd_state * state, char *imbe_d)
saveImbe4400Data (dsd_opts * opts, dsd_state * state, char *imbe_d)
{ {
int i, j, k; int i, j, k;
unsigned char b; unsigned char b;
@@ -56,11 +55,6 @@ saveImbe4400Data (dsd_opts * opts, dsd_state * state, char *imbe_d)
fputc (err, opts->mbe_out_f); fputc (err, opts->mbe_out_f);
k = 0; k = 0;
if (opts->payload == 1) //make opt variable later on to toggle this
{
//fprintf(stderr, "\n IMBE ");
}
for (i = 0; i < 11; i++) for (i = 0; i < 11; i++)
{ {
b = 0; b = 0;
@@ -71,21 +65,12 @@ saveImbe4400Data (dsd_opts * opts, dsd_state * state, char *imbe_d)
b = b + imbe_d[k]; b = b + imbe_d[k];
k++; k++;
} }
if (opts->payload == 1) //make opt variable later on to toggle this
{
//fprintf (stderr, "%02X", b);
}
fputc (b, opts->mbe_out_f); fputc (b, opts->mbe_out_f);
} }
if (opts->payload == 1)
{
//fprintf(stderr, " err = [%X] [%X] ", state->errs, state->errs2);
}
fflush (opts->mbe_out_f); fflush (opts->mbe_out_f);
} }
void void saveAmbe2450Data (dsd_opts * opts, dsd_state * state, char *ambe_d)
saveAmbe2450Data (dsd_opts * opts, dsd_state * state, char *ambe_d)
{ {
int i, j, k; int i, j, k;
unsigned char b; unsigned char b;
@@ -95,12 +80,7 @@ saveAmbe2450Data (dsd_opts * opts, dsd_state * state, char *ambe_d)
fputc (err, opts->mbe_out_f); fputc (err, opts->mbe_out_f);
k = 0; k = 0;
if (opts->payload == 1) //make opt variable later on to toggle this for (i = 0; i < 6; i++)
{
//fprintf(stderr, "\n AMBE ");
}
//for (i = 0; i < 6; i++)
for (i = 0; i < 6; i++) //using 7 seems to break older amb files where it was 6, need to test 7 on 7 some more
{ {
b = 0; b = 0;
for (j = 0; j < 8; j++) for (j = 0; j < 8; j++)
@@ -109,28 +89,40 @@ saveAmbe2450Data (dsd_opts * opts, dsd_state * state, char *ambe_d)
b = b + ambe_d[k]; b = b + ambe_d[k];
k++; k++;
} }
if (opts->payload == 1 && i < 6) //make opt variable later on to toggle this
{
//fprintf (stderr, "%02X", b);
}
if (opts->payload == 1 && i == 6) //7th octet should only contain 1 bit? value will be either 0x00 or 0x80?
{
//fprintf (stderr, "%02X", b & 0x80); //7th octet should only contain 1 bit?
}
fputc (b, opts->mbe_out_f); fputc (b, opts->mbe_out_f);
} }
if (opts->payload == 1)
{
//fprintf(stderr, " err = [%X] [%X] ", state->errs, state->errs2);
}
b = ambe_d[48]; b = ambe_d[48];
fputc (b, opts->mbe_out_f); fputc (b, opts->mbe_out_f);
fflush (opts->mbe_out_f); fflush (opts->mbe_out_f);
} }
void void saveAmbe2450DataR (dsd_opts * opts, dsd_state * state, char *ambe_d)
PrintIMBEData (dsd_opts * opts, dsd_state * state, char *imbe_d) //for P25P1 and ProVoice {
int i, j, k;
unsigned char b;
unsigned char err;
err = (unsigned char) state->errs2R;
fputc (err, opts->mbe_out_fR);
k = 0;
for (i = 0; i < 6; i++)
{
b = 0;
for (j = 0; j < 8; j++)
{
b = b << 1;
b = b + ambe_d[k];
k++;
}
fputc (b, opts->mbe_out_fR);
}
b = ambe_d[48];
fputc (b, opts->mbe_out_fR);
fflush (opts->mbe_out_fR);
}
void PrintIMBEData (dsd_opts * opts, dsd_state * state, char *imbe_d) //for P25P1 and ProVoice
{ {
int i, j, k; int i, j, k;
unsigned char b; unsigned char b;
@@ -165,8 +157,7 @@ PrintIMBEData (dsd_opts * opts, dsd_state * state, char *imbe_d) //for P25P1 and
//fprintf (stderr, "\n"); //fprintf (stderr, "\n");
} }
void void PrintAMBEData (dsd_opts * opts, dsd_state * state, char *ambe_d)
PrintAMBEData (dsd_opts * opts, dsd_state * state, char *ambe_d)
{ {
int i, j, k; int i, j, k;
unsigned char b; unsigned char b;
@@ -333,14 +324,21 @@ openMbeInFile (dsd_opts * opts, dsd_state * state)
cookie[2] = fgetc (opts->mbe_in_f); cookie[2] = fgetc (opts->mbe_in_f);
cookie[3] = fgetc (opts->mbe_in_f); cookie[3] = fgetc (opts->mbe_in_f);
cookie[4] = 0; cookie[4] = 0;
//ambe+2
if (strstr (cookie, ".amb") != NULL) if (strstr (cookie, ".amb") != NULL)
{ {
state->mbe_file_type = 1; state->mbe_file_type = 1;
} }
//p1 and pv
else if (strstr (cookie, ".imb") != NULL) else if (strstr (cookie, ".imb") != NULL)
{ {
state->mbe_file_type = 0; state->mbe_file_type = 0;
} }
//d-star ambe
else if (strstr (cookie, ".dmb") != NULL)
{
state->mbe_file_type = 2;
}
else else
{ {
state->mbe_file_type = -1; state->mbe_file_type = -1;
@@ -349,7 +347,7 @@ openMbeInFile (dsd_opts * opts, dsd_state * state)
} }
//much simpler version //slot 1
void closeMbeOutFile (dsd_opts * opts, dsd_state * state) void closeMbeOutFile (dsd_opts * opts, dsd_state * state)
{ {
if (opts->mbe_out == 1) if (opts->mbe_out == 1)
@@ -360,28 +358,47 @@ void closeMbeOutFile (dsd_opts * opts, dsd_state * state)
fclose (opts->mbe_out_f); fclose (opts->mbe_out_f);
opts->mbe_out_f = NULL; opts->mbe_out_f = NULL;
opts->mbe_out = 0; opts->mbe_out = 0;
fprintf (stderr, "\nClosing MBE out file."); fprintf (stderr, "\nClosing MBE out file 1.\n");
} }
} }
} }
void //slot 2
openMbeOutFile (dsd_opts * opts, dsd_state * state) void closeMbeOutFileR (dsd_opts * opts, dsd_state * state)
{
if (opts->mbe_outR == 1)
{
if (opts->mbe_out_fR != NULL)
{
fflush (opts->mbe_out_fR);
fclose (opts->mbe_out_fR);
opts->mbe_out_fR = NULL;
opts->mbe_outR = 0;
fprintf (stderr, "\nClosing MBE out file 2.\n");
}
}
}
void openMbeOutFile (dsd_opts * opts, dsd_state * state)
{ {
int i, j; int i, j;
char ext[5]; char ext[5];
//phase 1 and provoice
if ( (state->synctype == 0) || (state->synctype == 1) || (state->synctype == 14) || (state->synctype == 15) ) if ( (state->synctype == 0) || (state->synctype == 1) || (state->synctype == 14) || (state->synctype == 15) )
{ {
sprintf (ext, ".imb"); sprintf (ext, ".imb");
} }
else //d-star
else if ( (state->synctype == 6) || (state->synctype == 7) || (state->synctype == 18) || (state->synctype == 19) )
{ {
sprintf (ext, ".amb"); sprintf (ext, ".dmb"); //new dstar file extension to make it read in and process properly
} }
//dmr, nxdn, phase 2, x2-tdma
else sprintf (ext, ".amb");
//reset talkgroup id buffer //reset talkgroup id buffer
for (i = 0; i < 12; i++) for (i = 0; i < 12; i++)
@@ -394,14 +411,14 @@ openMbeOutFile (dsd_opts * opts, dsd_state * state)
state->tgcount = 0; state->tgcount = 0;
sprintf (opts->mbe_out_file, "%s %s%s", getDateF(), getTimeF(), ext); sprintf (opts->mbe_out_file, "%s %s S1%s", getDateF(), getTimeF(), ext);
sprintf (opts->mbe_out_path, "%s%s", opts->mbe_out_dir, opts->mbe_out_file); sprintf (opts->mbe_out_path, "%s%s", opts->mbe_out_dir, opts->mbe_out_file);
opts->mbe_out_f = fopen (opts->mbe_out_path, "w"); opts->mbe_out_f = fopen (opts->mbe_out_path, "w");
if (opts->mbe_out_f == NULL) if (opts->mbe_out_f == NULL)
{ {
fprintf (stderr,"Error, couldn't open %s\n", opts->mbe_out_path); fprintf (stderr,"\nError, couldn't open %s for slot 1\n", opts->mbe_out_path);
} }
else opts->mbe_out = 1; else opts->mbe_out = 1;
@@ -411,8 +428,54 @@ openMbeOutFile (dsd_opts * opts, dsd_state * state)
fflush (opts->mbe_out_f); fflush (opts->mbe_out_f);
} }
void void openMbeOutFileR (dsd_opts * opts, dsd_state * state)
openWavOutFile (dsd_opts * opts, dsd_state * state) {
int i, j;
char ext[5];
//phase 1 and provoice
if ( (state->synctype == 0) || (state->synctype == 1) || (state->synctype == 14) || (state->synctype == 15) )
{
sprintf (ext, ".imb");
}
//d-star
else if ( (state->synctype == 6) || (state->synctype == 7) || (state->synctype == 18) || (state->synctype == 19) )
{
sprintf (ext, ".dmb"); //new dstar file extension to make it read in and process properly
}
//dmr, nxdn, phase 2, x2-tdma
else sprintf (ext, ".amb");
//reset talkgroup id buffer
for (i = 0; i < 12; i++)
{
for (j = 0; j < 25; j++)
{
state->tg[j][i] = 0;
}
}
state->tgcount = 0;
sprintf (opts->mbe_out_fileR, "%s %s S2%s", getDateF(), getTimeF(), ext);
sprintf (opts->mbe_out_path, "%s%s", opts->mbe_out_dir, opts->mbe_out_fileR);
opts->mbe_out_fR = fopen (opts->mbe_out_path, "w");
if (opts->mbe_out_fR == NULL)
{
fprintf (stderr,"\nError, couldn't open %s for slot 2\n", opts->mbe_out_path);
}
else opts->mbe_outR = 1;
//
fprintf (opts->mbe_out_fR, "%s", ext);
fflush (opts->mbe_out_fR);
}
void openWavOutFile (dsd_opts * opts, dsd_state * state)
{ {
SF_INFO info; SF_INFO info;

View File

@@ -87,8 +87,8 @@ processFrame (dsd_opts * opts, dsd_state * state)
//NXDN FSW //NXDN FSW
if ((state->synctype == 28) || (state->synctype == 29)) if ((state->synctype == 28) || (state->synctype == 29))
{ {
//MBEout restored, is not handled internally by nxdn_frame.c
nxdn_frame (opts, state); nxdn_frame (opts, state);
//no MBEout...use symbol capture bin instead!
return; return;
} }
else if ((state->synctype == 6) || (state->synctype == 7)) else if ((state->synctype == 6) || (state->synctype == 7))
@@ -107,7 +107,7 @@ processFrame (dsd_opts * opts, dsd_state * state)
state->nac = 0; state->nac = 0;
if ((opts->mbe_out_dir[0] != 0) && (opts->mbe_out_f == NULL)) if ((opts->mbe_out_dir[0] != 0) && (opts->mbe_out_f == NULL))
{ {
openMbeOutFile (opts, state); openMbeOutFile (opts, state); //dstar ambe files are read back incorrectly, need to change file extension to differentiate when doing a playback
} }
sprintf (state->fsubtype, " VOICE "); sprintf (state->fsubtype, " VOICE ");
processDSTAR (opts, state); processDSTAR (opts, state);
@@ -129,7 +129,7 @@ processFrame (dsd_opts * opts, dsd_state * state)
state->nac = 0; state->nac = 0;
if ((opts->mbe_out_dir[0] != 0) && (opts->mbe_out_f == NULL)) if ((opts->mbe_out_dir[0] != 0) && (opts->mbe_out_f == NULL))
{ {
openMbeOutFile (opts, state); openMbeOutFile (opts, state); //dstar ambe files are read back incorrectly, need to change file extension to differentiate when doing a playback
} }
sprintf (state->fsubtype, " DATA "); sprintf (state->fsubtype, " DATA ");
processDSTAR_HD (opts, state); processDSTAR_HD (opts, state);
@@ -164,10 +164,7 @@ processFrame (dsd_opts * opts, dsd_state * state)
//disable so radio id doesn't blink in and out during ncurses and aggressive_framesync //disable so radio id doesn't blink in and out during ncurses and aggressive_framesync
state->nac = 0; state->nac = 0;
//state->lastsrc = 0;
//state->lasttg = 0;
//state->lastsrcR = 0;
//state->lasttgR = 0;
if (opts->errorbars == 1) if (opts->errorbars == 1)
{ {
if (opts->verbose > 0) if (opts->verbose > 0)
@@ -178,22 +175,20 @@ processFrame (dsd_opts * opts, dsd_state * state)
} }
if ( (state->synctype == 11) || (state->synctype == 12) || (state->synctype == 32) ) //DMR Voice Modes if ( (state->synctype == 11) || (state->synctype == 12) || (state->synctype == 32) ) //DMR Voice Modes
{ {
if ((opts->mbe_out_dir[0] != 0) && (opts->mbe_out_f == NULL) && opts->dmr_stereo == 0)
{
openMbeOutFile (opts, state);
}
sprintf (state->fsubtype, " VOICE "); sprintf (state->fsubtype, " VOICE ");
if (opts->dmr_stereo == 0 && state->synctype < 32) // -T option for DMR (TDMA) stereo if (opts->dmr_stereo == 0 && state->synctype < 32) // -T option for DMR (TDMA) stereo
{ {
sprintf (state->slot1light, " slot1 "); sprintf (state->slot1light, " slot1 ");
sprintf (state->slot2light, " slot2 "); sprintf (state->slot2light, " slot2 ");
//we can safely open MBE on any MS or mono handling
if ((opts->mbe_out_dir[0] != 0) && (opts->mbe_out_f == NULL)) openMbeOutFile (opts, state);
dmrMSBootstrap (opts, state); dmrMSBootstrap (opts, state);
} }
if (opts->dmr_mono == 1 && state->synctype == 32) if (opts->dmr_mono == 1 && state->synctype == 32)
{ {
// fprintf (stderr, "%s", KRED); //we can safely open MBE on any MS or mono handling
// fprintf (stderr, "Please use XDMA or DMR Stereo to decode MS/Simplex \n"); if ((opts->mbe_out_dir[0] != 0) && (opts->mbe_out_f == NULL)) openMbeOutFile (opts, state);
// fprintf (stderr, "%s", KNRM);
dmrMSBootstrap (opts, state); dmrMSBootstrap (opts, state);
} }
if (opts->dmr_stereo == 1) //opts->dmr_stereo == 1 if (opts->dmr_stereo == 1) //opts->dmr_stereo == 1
@@ -201,6 +196,8 @@ processFrame (dsd_opts * opts, dsd_state * state)
state->dmr_stereo = 1; //set the state to 1 when handling pure voice frames state->dmr_stereo = 1; //set the state to 1 when handling pure voice frames
if (state->synctype > 31 ) if (state->synctype > 31 )
{ {
//we can safely open MBE on any MS or mono handling
if ((opts->mbe_out_dir[0] != 0) && (opts->mbe_out_f == NULL)) openMbeOutFile (opts, state);
dmrMSBootstrap (opts, state); //bootstrap into MS Bootstrap (voice only) dmrMSBootstrap (opts, state); //bootstrap into MS Bootstrap (voice only)
} }
else dmrBSBootstrap (opts, state); //bootstrap into BS Bootstrap else dmrBSBootstrap (opts, state); //bootstrap into BS Bootstrap
@@ -208,26 +205,17 @@ processFrame (dsd_opts * opts, dsd_state * state)
} }
else if ( (state->synctype == 33) || (state->synctype == 34) ) //MS Data and RC data else if ( (state->synctype == 33) || (state->synctype == 34) ) //MS Data and RC data
{ {
if (opts->mbe_out_f != NULL) closeMbeOutFile (opts, state);
if (opts->mbe_out_fR != NULL) closeMbeOutFileR (opts, state);
dmrMSData (opts, state); dmrMSData (opts, state);
// if (opts->dmr_stereo == 0)
// {
// closeMbeOutFile (opts, state);
// state->err_str[0] = 0;
// fprintf (stderr, "%s", KRED);
// fprintf (stderr, "Please use XDMA or DMR Stereo to decode MS/Simplex \n");
// fprintf (stderr, "%s", KNRM);
// }
// if (opts->dmr_stereo == 1)
// {
// dmrMSData (opts, state);
// }
} }
else else
{ {
if (opts->dmr_stereo == 0) if (opts->dmr_stereo == 0)
{ {
closeMbeOutFile (opts, state); if (opts->mbe_out_f != NULL) closeMbeOutFile (opts, state);
if (opts->mbe_out_fR != NULL) closeMbeOutFileR (opts, state);
state->err_str[0] = 0; state->err_str[0] = 0;
sprintf (state->slot1light, " slot1 "); sprintf (state->slot1light, " slot1 ");
sprintf (state->slot2light, " slot2 "); sprintf (state->slot2light, " slot2 ");
@@ -237,6 +225,9 @@ processFrame (dsd_opts * opts, dsd_state * state)
//switch dmr_stereo to 0 when handling BS data frame syncs with processDMRdata //switch dmr_stereo to 0 when handling BS data frame syncs with processDMRdata
if (opts->dmr_stereo == 1) if (opts->dmr_stereo == 1)
{ {
if (opts->mbe_out_f != NULL) closeMbeOutFile (opts, state);
if (opts->mbe_out_fR != NULL) closeMbeOutFileR (opts, state);
state->dmr_stereo = 0; //set the state to zero for handling pure data frames state->dmr_stereo = 0; //set the state to zero for handling pure data frames
sprintf (state->slot1light, " slot1 "); sprintf (state->slot1light, " slot1 ");
sprintf (state->slot2light, " slot2 "); sprintf (state->slot2light, " slot2 ");
@@ -246,6 +237,7 @@ processFrame (dsd_opts * opts, dsd_state * state)
} }
return; return;
} }
//X2-TDMA
else if ((state->synctype >= 2) && (state->synctype <= 5)) else if ((state->synctype >= 2) && (state->synctype <= 5))
{ {
state->nac = 0; state->nac = 0;
@@ -264,7 +256,7 @@ processFrame (dsd_opts * opts, dsd_state * state)
} }
else else
{ {
closeMbeOutFile (opts, state); if (opts->mbe_out_f != NULL) closeMbeOutFile (opts, state);
state->err_str[0] = 0; state->err_str[0] = 0;
processX2TDMAdata (opts, state); processX2TDMAdata (opts, state);
} }
@@ -272,9 +264,6 @@ processFrame (dsd_opts * opts, dsd_state * state)
} }
else if ((state->synctype == 14) || (state->synctype == 15)) else if ((state->synctype == 14) || (state->synctype == 15))
{ {
//state->nac = 0;
//state->lastsrc = 0;
//state->lasttg = 0;
if (opts->errorbars == 1) if (opts->errorbars == 1)
{ {
if (opts->verbose > 0) if (opts->verbose > 0)
@@ -294,6 +283,7 @@ processFrame (dsd_opts * opts, dsd_state * state)
//edacs //edacs
else if ((state->synctype == 37) || (state->synctype == 38)) else if ((state->synctype == 37) || (state->synctype == 38))
{ {
if (opts->mbe_out_f != NULL) closeMbeOutFile (opts, state);
edacs (opts, state); edacs (opts, state);
return; return;
} }
@@ -313,13 +303,7 @@ processFrame (dsd_opts * opts, dsd_state * state)
//P25 P2 //P25 P2
else if ((state->synctype == 35) || (state->synctype == 36)) else if ((state->synctype == 35) || (state->synctype == 36))
{ {
//Do stuff //relocate MBEout to inside frame handling
//fprintf(stderr, "YSF Sync! \n");
if ((opts->mbe_out_dir[0] != 0) && (opts->mbe_out_f == NULL))
{
//openMbeOutFile (opts, state);
}
//sprintf(state->fsubtype, " VOICE ");
processP2(opts, state); processP2(opts, state);
return; return;
} }
@@ -328,6 +312,7 @@ processFrame (dsd_opts * opts, dsd_state * state)
{ {
/* dPMR Frame Sync 1 */ /* dPMR Frame Sync 1 */
fprintf(stderr, "dPMR Frame Sync 1 "); fprintf(stderr, "dPMR Frame Sync 1 ");
if (opts->mbe_out_f != NULL) closeMbeOutFile (opts, state);
} }
else if ((state->synctype == 21) || (state->synctype == 25)) else if ((state->synctype == 21) || (state->synctype == 25))
{ {
@@ -360,11 +345,13 @@ processFrame (dsd_opts * opts, dsd_state * state)
{ {
/* dPMR Frame Sync 3 */ /* dPMR Frame Sync 3 */
fprintf(stderr, "dPMR Frame Sync 3 "); fprintf(stderr, "dPMR Frame Sync 3 ");
if (opts->mbe_out_f != NULL) closeMbeOutFile (opts, state);
} }
else if ((state->synctype == 23) || (state->synctype == 27)) else if ((state->synctype == 23) || (state->synctype == 27))
{ {
/* dPMR Frame Sync 4 */ /* dPMR Frame Sync 4 */
fprintf(stderr, "dPMR Frame Sync 4 "); fprintf(stderr, "dPMR Frame Sync 4 ");
if (opts->mbe_out_f != NULL) closeMbeOutFile (opts, state);
} }
//dPMR //dPMR
else //P25 else //P25
@@ -469,8 +456,8 @@ processFrame (dsd_opts * opts, dsd_state * state)
} }
if (opts->mbe_out_dir[0] != 0) if (opts->mbe_out_dir[0] != 0)
{ {
closeMbeOutFile (opts, state); if (opts->mbe_out_f != NULL) closeMbeOutFile (opts, state);
openMbeOutFile (opts, state); if (opts->mbe_out_f == NULL) openMbeOutFile (opts, state);
} }
mbe_initMbeParms (state->cur_mp, state->prev_mp, state->prev_mp_enhanced); mbe_initMbeParms (state->cur_mp, state->prev_mp, state->prev_mp_enhanced);
state->lastp25type = 2; state->lastp25type = 2;
@@ -552,7 +539,7 @@ processFrame (dsd_opts * opts, dsd_state * state)
} }
if (opts->mbe_out_dir[0] != 0) if (opts->mbe_out_dir[0] != 0)
{ {
closeMbeOutFile (opts, state); if (opts->mbe_out_f != NULL) closeMbeOutFile (opts, state);
} }
mbe_initMbeParms (state->cur_mp, state->prev_mp, state->prev_mp_enhanced); mbe_initMbeParms (state->cur_mp, state->prev_mp, state->prev_mp_enhanced);
state->lasttg = 0; state->lasttg = 0;
@@ -579,7 +566,7 @@ processFrame (dsd_opts * opts, dsd_state * state)
} }
if (opts->mbe_out_dir[0] != 0) if (opts->mbe_out_dir[0] != 0)
{ {
closeMbeOutFile (opts, state); if (opts->mbe_out_f != NULL) closeMbeOutFile (opts, state);
} }
mbe_initMbeParms (state->cur_mp, state->prev_mp, state->prev_mp_enhanced); mbe_initMbeParms (state->cur_mp, state->prev_mp, state->prev_mp_enhanced);
state->lasttg = 0; state->lasttg = 0;
@@ -598,6 +585,11 @@ processFrame (dsd_opts * opts, dsd_state * state)
printFrameInfo (opts, state); printFrameInfo (opts, state);
fprintf (stderr," TSBK"); fprintf (stderr," TSBK");
} }
if (opts->mbe_out_dir[0] != 0)
{
if (opts->mbe_out_f != NULL) closeMbeOutFile (opts, state);
if (opts->mbe_out_fR != NULL) closeMbeOutFileR (opts, state);
}
if (opts->resume > 0) if (opts->resume > 0)
{ {
resumeScan (opts, state); resumeScan (opts, state);
@@ -607,7 +599,6 @@ processFrame (dsd_opts * opts, dsd_state * state)
state->lastp25type = 3; state->lastp25type = 3;
sprintf (state->fsubtype, " TSBK "); sprintf (state->fsubtype, " TSBK ");
// Now processing NID
processTSBK(opts, state); processTSBK(opts, state);
} }
@@ -616,89 +607,91 @@ processFrame (dsd_opts * opts, dsd_state * state)
if (opts->errorbars == 1) if (opts->errorbars == 1)
{ {
printFrameInfo (opts, state); printFrameInfo (opts, state);
fprintf (stderr," PDU\n"); fprintf (stderr," PDU\n"); //multi block/packet PDU
}
if (opts->mbe_out_dir[0] != 0)
{
if (opts->mbe_out_f != NULL) closeMbeOutFile (opts, state);
if (opts->mbe_out_fR != NULL) closeMbeOutFileR (opts, state);
} }
if (opts->resume > 0) if (opts->resume > 0)
{ {
resumeScan (opts, state); resumeScan (opts, state);
} }
if (opts->mbe_out_dir[0] != 0)
{
if (opts->mbe_out_f == NULL)
{
openMbeOutFile (opts, state);
}
}
state->lastp25type = 4; state->lastp25type = 4;
sprintf (state->fsubtype, " PDU "); sprintf (state->fsubtype, " PDU ");
} }
// try to guess based on previous frame if unknown type
else if (state->lastp25type == 1)
{
if (opts->errorbars == 1)
{
printFrameInfo (opts, state);
fprintf (stderr,"(LDU2) ");
}
if (opts->mbe_out_dir[0] != 0)
{
if (opts->mbe_out_f == NULL)
{
openMbeOutFile (opts, state);
}
}
//state->lastp25type = 0;
// Guess that the state is LDU2
state->lastp25type = 2;
sprintf (state->fsubtype, "(LDU2) ");
state->numtdulc = 0;
processLDU2 (opts, state);
}
else if (state->lastp25type == 2)
{
if (opts->errorbars == 1)
{
printFrameInfo (opts, state);
fprintf (stderr,"(LDU1) ");
}
if (opts->mbe_out_dir[0] != 0)
{
if (opts->mbe_out_f == NULL)
{
openMbeOutFile (opts, state);
}
}
//state->lastp25type = 0;
// Guess that the state is LDU1
state->lastp25type = 1;
sprintf (state->fsubtype, "(LDU1) ");
state->numtdulc = 0;
processLDU1 (opts, state);
}
else if (state->lastp25type == 3)
{
if (opts->errorbars == 1)
{
printFrameInfo (opts, state);
fprintf (stderr," (TSBK)\n");
}
//state->lastp25type = 0;
// Guess that the state is TSBK
state->lastp25type = 3;
sprintf (state->fsubtype, "(TSBK) ");
// Now processing NID // try to guess based on previous frame if unknown type
skipDibit (opts, state, 328-25); // disabling the guessing game on P1
}
else if (state->lastp25type == 4) // else if (state->lastp25type == 1)
{ // {
if (opts->errorbars == 1) // if (opts->errorbars == 1)
{ // {
printFrameInfo (opts, state); // printFrameInfo (opts, state);
fprintf (stderr," (PDU)\n"); // fprintf (stderr,"(LDU2) ");
} // }
state->lastp25type = 0; // // if (opts->mbe_out_dir[0] != 0)
} // // {
// // if (opts->mbe_out_f == NULL)
// // {
// // openMbeOutFile (opts, state);
// // }
// // }
// //state->lastp25type = 0;
// // Guess that the state is LDU2
// state->lastp25type = 2;
// sprintf (state->fsubtype, "(LDU2) ");
// state->numtdulc = 0;
// processLDU2 (opts, state);
// }
// else if (state->lastp25type == 2)
// {
// if (opts->errorbars == 1)
// {
// printFrameInfo (opts, state);
// fprintf (stderr,"(LDU1) ");
// }
// if (opts->mbe_out_dir[0] != 0)
// {
// if (opts->mbe_out_f == NULL)
// {
// openMbeOutFile (opts, state);
// }
// }
// //state->lastp25type = 0;
// // Guess that the state is LDU1
// state->lastp25type = 1;
// sprintf (state->fsubtype, "(LDU1) ");
// state->numtdulc = 0;
// processLDU1 (opts, state);
// }
// else if (state->lastp25type == 3)
// {
// if (opts->errorbars == 1)
// {
// printFrameInfo (opts, state);
// fprintf (stderr," (TSBK)\n");
// }
// //state->lastp25type = 0;
// // Guess that the state is TSBK
// state->lastp25type = 3;
// sprintf (state->fsubtype, "(TSBK) ");
// // Now processing NID
// skipDibit (opts, state, 328-25);
// }
// else if (state->lastp25type == 4)
// {
// if (opts->errorbars == 1)
// {
// printFrameInfo (opts, state);
// fprintf (stderr," (PDU)\n");
// }
// state->lastp25type = 0;
// }
else else
{ {
state->lastp25type = 0; state->lastp25type = 0;

View File

@@ -145,3 +145,68 @@ int csvChanImport(dsd_opts * opts, dsd_state * state) //channel map import
fclose(fp); fclose(fp);
return 0; return 0;
} }
int csvKeyImport(dsd_opts * opts, dsd_state * state) //multi-key support
{
char filename[1024] = "filename.csv";
sprintf (filename, "%s", opts->key_in_file);
char buffer[BSIZE];
FILE * fp;
fp = fopen(filename, "r");
if (fp == NULL) {
printf("Unable to open file '%s'\n", filename);
exit(1);
}
int row_count = 0;
int field_count = 0;
unsigned long long int keynumber = 0;
unsigned long long int keyvalue = 0;
uint16_t hash = 0;
uint8_t hash_bits[24];
memset (hash_bits, 0, sizeof(hash_bits));
while (fgets(buffer, BSIZE, fp)) {
field_count = 0;
row_count++;
if (row_count == 1)
continue; //don't want labels
char * field = strtok(buffer, ","); //seperate by comma
while (field) {
if (field_count == 0)
{
sscanf (field, "%lld", &keynumber);
if (keynumber > 0xFFFF) //if larger than 16-bits, get its hash instead
{
keynumber = keynumber & 0xFFFFFF; //truncate to 24-bits (max allowed)
for (int i = 0; i < 24; i++)
{
hash_bits[i] = ((keynumber << i) & 0x800000) >> 23; //load into array for CRC16
}
hash = ComputeCrcCCITT16d (hash_bits, 24);
keynumber = hash & 0xFFFF; //make sure its no larger than 16-bits
fprintf (stderr, "Hashed ");
}
}
if (field_count == 1)
{
sscanf (field, "%lld", &keyvalue);
state->rkey_array[keynumber] = keyvalue & 0xFFFFFFFFFF; //doesn't exceed 40-bit value
}
field = strtok(NULL, ",");
field_count++;
}
fprintf (stderr, "Key [%03lld] [%05lld]", keynumber, state->rkey_array[keynumber]);
fprintf (stderr, "\n");
hash = 0;
}
fclose(fp);
return 0;
}

View File

@@ -52,11 +52,10 @@ char * FM_banner[9] = {
" ██║ ██║ ╚═══██╗██║ ██║   ██╔══╝ ██║╚██╔╝██║██╔══╝ ", " ██║ ██║ ╚═══██╗██║ ██║   ██╔══╝ ██║╚██╔╝██║██╔══╝ ",
" ██████╔╝██████╔╝██████╔╝   ██║ ██║ ╚═╝ ██║███████╗", " ██████╔╝██████╔╝██████╔╝   ██║ ██║ ╚═╝ ██║███████╗",
" ╚═════╝ ╚═════╝ ╚═════╝    ╚═╝ ╚═╝ ╚═╝╚══════╝", " ╚═════╝ ╚═════╝ ╚═════╝    ╚═╝ ╚═╝ ╚═╝╚══════╝",
" Lite Edition v2.0.0-6-gc44e039 Windows 32-bit RC1 " " 'Lite' Edition v2.0.0-40-gc999c97 Windows 32-bit RC4 "
}; };
int int comp (const void *a, const void *b)
comp (const void *a, const void *b)
{ {
if (*((const int *) a) == *((const int *) b)) if (*((const int *) a) == *((const int *) b))
return 0; return 0;
@@ -69,6 +68,7 @@ comp (const void *a, const void *b)
//struct for checking existence of directory to write to //struct for checking existence of directory to write to
struct stat st = {0}; struct stat st = {0};
char wav_file_directory[1024] = {0}; char wav_file_directory[1024] = {0};
char dsp_filename[1024] = {0};
unsigned long long int p2vars = 0; unsigned long long int p2vars = 0;
char * pEnd; //bugfix char * pEnd; //bugfix
@@ -135,10 +135,11 @@ noCarrier (dsd_opts * opts, dsd_state * state)
state->dmr_payload_p = state->dibit_buf + 200; state->dmr_payload_p = state->dibit_buf + 200;
memset (state->dmr_payload_buf, 0, sizeof (int) * 200); memset (state->dmr_payload_buf, 0, sizeof (int) * 200);
//dmr buffer end //dmr buffer end
if (opts->mbe_out_f != NULL)
{ //close MBE out files
closeMbeOutFile (opts, state); if (opts->mbe_out_f != NULL) closeMbeOutFile (opts, state);
} if (opts->mbe_out_fR != NULL) closeMbeOutFileR (opts, state);
state->jitter = -1; state->jitter = -1;
state->lastsynctype = -1; state->lastsynctype = -1;
state->carrier = 0; state->carrier = 0;
@@ -253,12 +254,12 @@ noCarrier (dsd_opts * opts, dsd_state * state)
state->data_header_blocks[1] = 1; //when trying to fill the superframe and 0-1 blocks give us an overflow state->data_header_blocks[1] = 1; //when trying to fill the superframe and 0-1 blocks give us an overflow
state->data_header_padding[0] = 0; state->data_header_padding[0] = 0;
state->data_header_padding[1] = 0; state->data_header_padding[1] = 0;
state->data_header_format[0] = 0; state->data_header_format[0] = 7;
state->data_header_format[1] = 0; state->data_header_format[1] = 7;
state->data_header_sap[0] = 0; state->data_header_sap[0] = 0;
state->data_header_sap[1] = 0; state->data_header_sap[1] = 0;
state->data_block_counter[0] = 0; state->data_block_counter[0] = 1;
state->data_block_counter[1] = 0; state->data_block_counter[1] = 1;
state->data_p_head[0] = 0; state->data_p_head[0] = 0;
state->data_p_head[1] = 0; state->data_p_head[1] = 0;
@@ -287,7 +288,7 @@ noCarrier (dsd_opts * opts, dsd_state * state)
state->nxdn_sf = 0; state->nxdn_sf = 0;
memset (state->nxdn_sacch_frame_segcrc, 1, sizeof(state->nxdn_sacch_frame_segcrc)); //init on 1, bad CRC all memset (state->nxdn_sacch_frame_segcrc, 1, sizeof(state->nxdn_sacch_frame_segcrc)); //init on 1, bad CRC all
state->nxdn_sacch_non_superframe = TRUE; state->nxdn_sacch_non_superframe = TRUE;
memset (state->nxdn_sacch_frame_segment, 0, sizeof(state->nxdn_sacch_frame_segment)); memset (state->nxdn_sacch_frame_segment, 1, sizeof(state->nxdn_sacch_frame_segment));
state->nxdn_alias_block_number = 0; state->nxdn_alias_block_number = 0;
memset (state->nxdn_alias_block_segment, 0, sizeof(state->nxdn_alias_block_segment)); memset (state->nxdn_alias_block_segment, 0, sizeof(state->nxdn_alias_block_segment));
sprintf (state->nxdn_call_type, "%s", ""); sprintf (state->nxdn_call_type, "%s", "");
@@ -301,6 +302,11 @@ noCarrier (dsd_opts * opts, dsd_state * state)
//initialize unified dmr pdu 'superframe' //initialize unified dmr pdu 'superframe'
memset (state->dmr_pdu_sf, 0, sizeof (state->dmr_pdu_sf)); memset (state->dmr_pdu_sf, 0, sizeof (state->dmr_pdu_sf));
memset (state->data_header_valid, 0, sizeof(state->data_header_valid));
//initialize cap+ bits and block num storage
memset (state->cap_plus_csbk_bits, 0, sizeof(state->cap_plus_csbk_bits));
state->cap_plus_block_num = 0;
//init confirmed data individual block crc as invalid //init confirmed data individual block crc as invalid
memset (state->data_block_crc_valid, 0, sizeof(state->data_block_crc_valid)); memset (state->data_block_crc_valid, 0, sizeof(state->data_block_crc_valid));
@@ -319,8 +325,8 @@ noCarrier (dsd_opts * opts, dsd_state * state)
memset(state->dmr_lrrp_gps, 0, sizeof(state->dmr_lrrp_gps)); memset(state->dmr_lrrp_gps, 0, sizeof(state->dmr_lrrp_gps));
//REMUS! multi-purpose call_string //REMUS! multi-purpose call_string
sprintf (state->call_string[0], "%s", " "); //20 spaces sprintf (state->call_string[0], "%s", " "); //21 spaces
sprintf (state->call_string[1], "%s", " "); //20 spaces sprintf (state->call_string[1], "%s", " "); //21 spaces
if (time(NULL) - state->last_cc_sync_time > 30) //thirty seconds of no carrier if (time(NULL) - state->last_cc_sync_time > 30) //thirty seconds of no carrier
{ {
@@ -334,6 +340,17 @@ noCarrier (dsd_opts * opts, dsd_state * state)
opts->p25_is_tuned = 0; opts->p25_is_tuned = 0;
} }
opts->dPMR_next_part_of_superframe = 0;
state->dPMRVoiceFS2Frame.CalledIDOk = 0;
state->dPMRVoiceFS2Frame.CallingIDOk = 0;
memset(state->dPMRVoiceFS2Frame.CalledID, 0, 8);
memset(state->dPMRVoiceFS2Frame.CallingID, 0, 8);
memset(state->dPMRVoiceFS2Frame.Version, 0, 8);
sprintf (state->dpmr_caller_id, "%s", " ");
sprintf (state->dpmr_target_id, "%s", " ");
} //nocarrier } //nocarrier
void void
@@ -364,8 +381,10 @@ initOpts (dsd_opts * opts)
opts->playoffsetR = 0; opts->playoffsetR = 0;
opts->mbe_out_dir[0] = 0; opts->mbe_out_dir[0] = 0;
opts->mbe_out_file[0] = 0; opts->mbe_out_file[0] = 0;
opts->mbe_out_fileR[0] = 0; //second slot on a TDMA system
opts->mbe_out_path[0] = 0; opts->mbe_out_path[0] = 0;
opts->mbe_out_f = NULL; opts->mbe_out_f = NULL;
opts->mbe_out_fR = NULL; //second slot on a TDMA system
opts->audio_gain = 0; //0 opts->audio_gain = 0; //0
opts->audio_gainR = 0; //0 opts->audio_gainR = 0; //0
opts->audio_out = 1; opts->audio_out = 1;
@@ -378,11 +397,13 @@ initOpts (dsd_opts * opts)
opts->group_in_file[0] = 0; opts->group_in_file[0] = 0;
opts->lcn_in_file[0] = 0; opts->lcn_in_file[0] = 0;
opts->chan_in_file[0] = 0; opts->chan_in_file[0] = 0;
opts->key_in_file[0] = 0;
//end import filenames //end import filenames
opts->szNumbers[0] = 0; opts->szNumbers[0] = 0;
opts->symbol_out_f = NULL; opts->symbol_out_f = NULL;
opts->symbol_out = 0; opts->symbol_out = 0;
opts->mbe_out = 0; opts->mbe_out = 0;
opts->mbe_outR = 0; //second slot on a TDMA system
opts->wav_out_f = NULL; opts->wav_out_f = NULL;
opts->wav_out_fR = NULL; opts->wav_out_fR = NULL;
opts->wav_out_raw = NULL; opts->wav_out_raw = NULL;
@@ -504,12 +525,18 @@ initOpts (dsd_opts * opts)
//Trunking - Tune Data Calls //Trunking - Tune Data Calls
opts->trunk_tune_data_calls = 0; //disabled by default opts->trunk_tune_data_calls = 0; //disabled by default
opts->dPMR_next_part_of_superframe = 0;
//OSS audio - Slot Preference //OSS audio - Slot Preference
//slot preference is used during OSS audio playback to //slot preference is used during OSS audio playback to
//prefer one tdma voice slot over another when both are playing back //prefer one tdma voice slot over another when both are playing back
//this is a fix to cygwin stuttering when both slots have voice //this is a fix to cygwin stuttering when both slots have voice
opts->slot_preference = 0; //default prefer slot 1 -- state->currentslot = 0; opts->slot_preference = 0; //default prefer slot 1 -- state->currentslot = 0;
//dsp structured file
opts->dsp_out_file[0] = 0;
opts->use_dsp_output = 0;
} //initopts } //initopts
void void
@@ -649,8 +676,6 @@ initState (dsd_state * state)
state->payload_miN = 0; state->payload_miN = 0;
state->dpmr_color_code = -1; state->dpmr_color_code = -1;
state->dpmr_caller_id = 0;
state->dpmr_target_id = 0;
state->payload_mi = 0; state->payload_mi = 0;
state->payload_miR = 0; state->payload_miR = 0;
@@ -687,6 +712,8 @@ initState (dsd_state * state)
state->dmr_soR = 0; state->dmr_soR = 0;
state->dmr_fid = 0; state->dmr_fid = 0;
state->dmr_fidR = 0; state->dmr_fidR = 0;
state->dmr_flco = 0;
state->dmr_flcoR = 0;
state->dmr_ms_mode = 0; state->dmr_ms_mode = 0;
state->HYTL = 0; state->HYTL = 0;
@@ -712,12 +739,12 @@ initState (dsd_state * state)
state->data_header_blocks[1] = 1; //when trying to fill the superframe and 0-1 blocks give us an overflow state->data_header_blocks[1] = 1; //when trying to fill the superframe and 0-1 blocks give us an overflow
state->data_header_padding[0] = 0; state->data_header_padding[0] = 0;
state->data_header_padding[1] = 0; state->data_header_padding[1] = 0;
state->data_header_format[0] = 0; state->data_header_format[0] = 7;
state->data_header_format[1] = 0; state->data_header_format[1] = 7;
state->data_header_sap[0] = 0; state->data_header_sap[0] = 0;
state->data_header_sap[1] = 0; state->data_header_sap[1] = 0;
state->data_block_counter[0] = 0; state->data_block_counter[0] = 1;
state->data_block_counter[1] = 0; state->data_block_counter[1] = 1;
state->data_p_head[0] = 0; state->data_p_head[0] = 0;
state->data_p_head[1] = 0; state->data_p_head[1] = 0;
@@ -730,6 +757,8 @@ initState (dsd_state * state)
state->p2_wacn = 0; state->p2_wacn = 0;
state->p2_sysid = 0; state->p2_sysid = 0;
state->p2_cc = 0; state->p2_cc = 0;
state->p2_siteid = 0;
state->p2_rfssid = 0;
state->p2_hardset = 0; state->p2_hardset = 0;
state->p2_is_lcch = 0; state->p2_is_lcch = 0;
state->p25_cc_is_tdma = 2; //init on 2, TSBK NET_STS will set 0, TDMA NET_STS will set 1. //used to determine if we need to change symbol rate when cc hunting state->p25_cc_is_tdma = 2; //init on 2, TSBK NET_STS will set 0, TDMA NET_STS will set 1. //used to determine if we need to change symbol rate when cc hunting
@@ -779,9 +808,6 @@ initState (dsd_state * state)
//dmr trunking/ncurses stuff //dmr trunking/ncurses stuff
state->dmr_rest_channel = -1; //init on -1 state->dmr_rest_channel = -1; //init on -1
state->dmr_mfid = -1; // state->dmr_mfid = -1; //
state->dmr_tuned_lcn = -1; //logical slot, lcn * ts?
state->dmr_vc_lcn = -1; //
state->dmr_vc_lsn = -1;
//new nxdn stuff //new nxdn stuff
state->nxdn_part_of_frame = 0; state->nxdn_part_of_frame = 0;
@@ -789,7 +815,7 @@ initState (dsd_state * state)
state->nxdn_sf = 0; state->nxdn_sf = 0;
memset (state->nxdn_sacch_frame_segcrc, 1, sizeof(state->nxdn_sacch_frame_segcrc)); //init on 1, bad CRC all memset (state->nxdn_sacch_frame_segcrc, 1, sizeof(state->nxdn_sacch_frame_segcrc)); //init on 1, bad CRC all
state->nxdn_sacch_non_superframe = TRUE; state->nxdn_sacch_non_superframe = TRUE;
memset (state->nxdn_sacch_frame_segment, 0, sizeof(state->nxdn_sacch_frame_segment)); memset (state->nxdn_sacch_frame_segment, 1, sizeof(state->nxdn_sacch_frame_segment));
state->nxdn_alias_block_number = 0; state->nxdn_alias_block_number = 0;
memset (state->nxdn_alias_block_segment, 0, sizeof(state->nxdn_alias_block_segment)); memset (state->nxdn_alias_block_segment, 0, sizeof(state->nxdn_alias_block_segment));
//site/srv/cch info //site/srv/cch info
@@ -797,6 +823,9 @@ initState (dsd_state * state)
state->nxdn_location_sys_code = 0; state->nxdn_location_sys_code = 0;
sprintf (state->nxdn_location_category, "%s", " "); sprintf (state->nxdn_location_category, "%s", " ");
//multi-key array
memset (state->rkey_array, 0, sizeof(state->rkey_array));
//Remus DMR End Call Alert Beep //Remus DMR End Call Alert Beep
state->dmr_end_alert[0] = 0; state->dmr_end_alert[0] = 0;
state->dmr_end_alert[1] = 0; state->dmr_end_alert[1] = 0;
@@ -807,6 +836,11 @@ initState (dsd_state * state)
//initialize unified dmr pdu 'superframe' //initialize unified dmr pdu 'superframe'
memset (state->dmr_pdu_sf, 0, sizeof (state->dmr_pdu_sf)); memset (state->dmr_pdu_sf, 0, sizeof (state->dmr_pdu_sf));
memset (state->data_header_valid, 0, sizeof(state->data_header_valid));
//initialize cap+ bits and block num storage
memset (state->cap_plus_csbk_bits, 0, sizeof(state->cap_plus_csbk_bits));
state->cap_plus_block_num = 0;
//init confirmed data individual block crc as invalid //init confirmed data individual block crc as invalid
memset (state->data_block_crc_valid, 0, sizeof(state->data_block_crc_valid)); memset (state->data_block_crc_valid, 0, sizeof(state->data_block_crc_valid));
@@ -826,14 +860,23 @@ initState (dsd_state * state)
memset(state->dmr_lrrp_gps, 0, sizeof(state->dmr_lrrp_gps)); memset(state->dmr_lrrp_gps, 0, sizeof(state->dmr_lrrp_gps));
//REMUS! multi-purpose call_string //REMUS! multi-purpose call_string
sprintf (state->call_string[0], "%s", " "); //20 spaces sprintf (state->call_string[0], "%s", " "); //21 spaces
sprintf (state->call_string[1], "%s", " "); //20 spaces sprintf (state->call_string[1], "%s", " "); //21 spaces
//late entry mi fragments //late entry mi fragments
memset (state->late_entry_mi_fragment, 0, sizeof (state->late_entry_mi_fragment)); memset (state->late_entry_mi_fragment, 0, sizeof (state->late_entry_mi_fragment));
initialize_p25_heuristics(&state->p25_heuristics); initialize_p25_heuristics(&state->p25_heuristics);
state->dPMRVoiceFS2Frame.CalledIDOk = 0;
state->dPMRVoiceFS2Frame.CallingIDOk = 0;
memset(state->dPMRVoiceFS2Frame.CalledID, 0, 8);
memset(state->dPMRVoiceFS2Frame.CallingID, 0, 8);
memset(state->dPMRVoiceFS2Frame.Version, 0, 8);
sprintf (state->dpmr_caller_id, "%s", " ");
sprintf (state->dpmr_target_id, "%s", " ");
} //init_state } //init_state
void void
@@ -865,7 +908,7 @@ usage ()
printf (" -o <device> Audio output device (default is /dev/dsp)\n"); printf (" -o <device> Audio output device (default is /dev/dsp)\n");
printf (" null for no audio output\n"); printf (" null for no audio output\n");
printf (" pulse for pulse audio \n"); printf (" pulse for pulse audio \n");
printf (" -d <dir> Create mbe data files, use this directory\n"); printf (" -d <dir> Create mbe data files, use this directory (TDMA version is experimental)\n");
printf (" -r <files> Read/Play saved mbe data from file(s)\n"); printf (" -r <files> Read/Play saved mbe data from file(s)\n");
printf (" -g <num> Audio output gain (default = 0 = auto, disable = -1)\n"); printf (" -g <num> Audio output gain (default = 0 = auto, disable = -1)\n");
printf (" -w <file> Output synthesized speech to a .wav file, legacy auto modes only.\n"); printf (" -w <file> Output synthesized speech to a .wav file, legacy auto modes only.\n");
@@ -875,6 +918,7 @@ usage ()
printf (" -a Enable Call Alert Beep (NCurses Terminal Only)\n"); printf (" -a Enable Call Alert Beep (NCurses Terminal Only)\n");
printf (" (Warning! Might be annoying.)\n"); printf (" (Warning! Might be annoying.)\n");
printf (" -L <file> Specify Filename for LRRP Data Output.\n"); printf (" -L <file> Specify Filename for LRRP Data Output.\n");
printf (" -Q <file> Specify Filename for DSP Structured File Output. (placed in DSP folder)\n");
printf (" -c <file> Output symbol capture to .bin file\n"); printf (" -c <file> Output symbol capture to .bin file\n");
printf (" -q Reverse Mute - Mute Unencrypted Voice and Unmute Encrypted Voice\n"); printf (" -q Reverse Mute - Mute Unencrypted Voice and Unmute Encrypted Voice\n");
printf (" -V Enable Audio Smoothing on Upsampled 48k/1 or 24k/2 Audio (Capital V)\n"); printf (" -V Enable Audio Smoothing on Upsampled 48k/1 or 24k/2 Audio (Capital V)\n");
@@ -894,9 +938,9 @@ usage ()
printf (" Example: dsd-fme-lite -fp -i rtl:0:851.375M:22:-2:12:0:6021\n"); printf (" Example: dsd-fme-lite -fp -i rtl:0:851.375M:22:-2:12:0:6021\n");
printf ("\n"); printf ("\n");
printf ("Decoder options:\n"); printf ("Decoder options:\n");
printf (" -fa Legacy Auto Detection 8k/1 (old methods default)\n"); printf (" -fa Legacy Auto Detection (old methods default)\n");
printf (" -ft XDMA P25 and DMR BS/MS frame types (new default)\n"); printf (" -ft XDMA P25 and DMR BS/MS frame types (new default)\n");
printf (" -fs DMR Stereo BS and MS Simplex only\n"); printf (" -fs DMR Stereo BS and MS Simplex\n");
printf (" -f1 Decode only P25 Phase 1\n"); printf (" -f1 Decode only P25 Phase 1\n");
printf (" -fd Decode only D-STAR\n"); printf (" -fd Decode only D-STAR\n");
printf (" -fr Decode only DMR Mono - Single Slot Voice\n"); printf (" -fr Decode only DMR Mono - Single Slot Voice\n");
@@ -905,7 +949,7 @@ usage ()
printf (" -fn Decode only NXDN96* (12.5 kHz)\n"); printf (" -fn Decode only NXDN96* (12.5 kHz)\n");
printf (" -fp Decode only EDACS/ProVoice*\n"); printf (" -fp Decode only EDACS/ProVoice*\n");
printf (" -fm Decode only dPMR*\n"); printf (" -fm Decode only dPMR*\n");
printf (" -l Disable DMR and NXDN input filtering\n"); printf (" -l Disable DMR, dPMR, and NXDN input filtering\n");
printf (" -u <num> Unvoiced speech quality (default=3)\n"); printf (" -u <num> Unvoiced speech quality (default=3)\n");
printf (" -xx Expect non-inverted X2-TDMA signal\n"); printf (" -xx Expect non-inverted X2-TDMA signal\n");
printf (" -xr Expect inverted DMR signal\n"); printf (" -xr Expect inverted DMR signal\n");
@@ -933,9 +977,8 @@ usage ()
//printf (" (4 Level, not 8 Level LSM) (this is honestly unknown since I can't verify what local systems are using)\n"); //printf (" (4 Level, not 8 Level LSM) (this is honestly unknown since I can't verify what local systems are using)\n");
printf (" -F Relax P25 Phase 2 MAC_SIGNAL CRC Checksum Pass/Fail\n"); printf (" -F Relax P25 Phase 2 MAC_SIGNAL CRC Checksum Pass/Fail\n");
printf (" Use this feature to allow MAC_SIGNAL even if CRC errors.\n"); printf (" Use this feature to allow MAC_SIGNAL even if CRC errors.\n");
printf (" -F Relax DMR CACH/Burst FEC Pass/Fail - Passive Frame Sync\n"); printf (" -F Relax DMR RAS/CRC CSBK/DATA Pass/Fail\n");
printf (" Use if skipping occurs, but may cause wonky audio due to loss of good sync\n"); printf (" Enabling on some systems could lead to bad voice/data decoding if bad or marginal signal\n");
printf ("\n"); printf ("\n");
printf (" -K <dec> Manually Enter Basic Privacy Key (Decimal Value of Key Number)\n"); printf (" -K <dec> Manually Enter Basic Privacy Key (Decimal Value of Key Number)\n");
printf ("\n"); printf ("\n");
@@ -945,7 +988,11 @@ usage ()
printf (" -H '736B9A9C5645288B 243AD5CB8701EF8A' \n"); printf (" -H '736B9A9C5645288B 243AD5CB8701EF8A' \n");
printf (" -H '20029736A5D91042 C923EB0697484433 005EFC58A1905195 E28E9C7836AA2DB8' \n"); printf (" -H '20029736A5D91042 C923EB0697484433 005EFC58A1905195 E28E9C7836AA2DB8' \n");
printf ("\n"); printf ("\n");
printf (" -R <dec> Manually Enter NXDN 4800/9600 EHR Scrambler Key Value (Decimal Value)\n"); printf (" -R <dec> Manually Enter dPMR or NXDN EHR Scrambler Key Value (Decimal Value)\n");
printf (" \n");
printf (" -k <file> Import Key List from csv file.\n");
printf (" Only supports NXDN, DMR Basic Privacy and **tera 10-Char (decimal value) only. \n");
printf (" (dPMR and **tera 32/64 char not supported, DMR uses TG value as key id -- EXPERIMENTAL!!). \n");
printf (" \n"); printf (" \n");
printf (" -4 Force Privacy Key over FID and SVC bits \n"); printf (" -4 Force Privacy Key over FID and SVC bits \n");
printf ("\n"); printf ("\n");
@@ -1027,6 +1074,7 @@ if (opts->audio_in_type == 0)
if (opts->audio_out_type == 0) if (opts->audio_out_type == 0)
{ {
// openPulseInput(opts); //test to see if we still randomly hang up in ncurses and tcp input if we open this and leave it opened
openPulseOutput(opts); openPulseOutput(opts);
} }
@@ -1096,10 +1144,10 @@ cleanupAndExit (dsd_opts * opts, dsd_state * state)
{ {
closeSymbolOutFile (opts, state); closeSymbolOutFile (opts, state);
} }
if (opts->mbe_out_f != NULL)
{ //close MBE out files
closeMbeOutFile (opts, state); if (opts->mbe_out_f != NULL) closeMbeOutFile (opts, state);
} if (opts->mbe_out_fR != NULL) closeMbeOutFileR (opts, state);
fprintf (stderr,"\n"); fprintf (stderr,"\n");
fprintf (stderr,"Total audio errors: %i\n", state->debug_audio_errors); fprintf (stderr,"Total audio errors: %i\n", state->debug_audio_errors);
@@ -1109,22 +1157,6 @@ cleanupAndExit (dsd_opts * opts, dsd_state * state)
exit (0); exit (0);
} }
// void
// sigfun (int sig) //not convinced this is truly required, maybe some environments require it?
// {
// exitflag = 1;
// #ifdef USE_RTLSDR
// // if (opts->audio_in_type == 3)
// //rtlsdr_sighandler();
// #endif
// signal (SIGINT, SIG_DFL);
// ncursesClose ();
// // #ifdef USE_RTLSDR
// // if (opts->audio_in_type == 3) rtlsdr_sighandler();
// // #endif
// }
double atofs(char *s) double atofs(char *s)
{ {
char last; char last;
@@ -1179,9 +1211,8 @@ main (int argc, char **argv)
InitAllFecFunction(); InitAllFecFunction();
exitflag = 0; exitflag = 0;
// signal (SIGINT, sigfun);
while ((c = getopt (argc, argv, "haepPqs:t:v:z:i:o:d:c:g:nw:B:C:R:f:m:u:x:A:S:M:G:D:L:VU:Y:K:H:X:NQWrlZTF01:2:345:6:7:89:E")) != -1) while ((c = getopt (argc, argv, "haepPqs:t:v:z:i:o:d:c:g:nw:B:C:R:f:m:u:x:A:S:M:G:D:L:VU:Y:K:H:X:NQ:WrlZTF01:2:345:6:7:89:Ek:")) != -1)
{ {
opterr = 0; opterr = 0;
switch (c) switch (c)
@@ -1197,7 +1228,29 @@ main (int argc, char **argv)
//make sure to put a colon : after each if they need an argument //make sure to put a colon : after each if they need an argument
//or remove colon if no argument required //or remove colon if no argument required
//Disabled the Serial Port Dev and Baud Rate, etc, If somebody uses that function, sorry...
case 'k': //NXDN multi-key loader
strncpy(opts.key_in_file, optarg, 1023);
opts.key_in_file[1023] = '\0';
csvKeyImport(&opts, &state);
break;
case 'Q': //'DSP' Structured Output file for OKDMRlib
sprintf (wav_file_directory, "./DSP");
wav_file_directory[1023] = '\0';
if (stat(wav_file_directory, &st) == -1)
{
fprintf (stderr, "-Q %s DSP file directory does not exist\n", wav_file_directory);
fprintf (stderr, "Creating directory %s to save DSP Structured files\n", wav_file_directory);
mkdir(wav_file_directory, 0700); //user read write execute, needs execute for some reason or segfault
}
//read in filename
//sprintf (opts.wav_out_file, "./WAV/DSD-FME-X1.wav");
strncpy(dsp_filename, optarg, 1023);
sprintf(opts.dsp_out_file, "%s/%s", wav_file_directory, dsp_filename);
fprintf (stderr, "Saving DSP Structured files to %s\n", opts.dsp_out_file);
opts.use_dsp_output = 1;
break;
case 'z': case 'z':
sscanf (optarg, "%d", &opts.slot_preference); sscanf (optarg, "%d", &opts.slot_preference);
@@ -1287,41 +1340,6 @@ main (int argc, char **argv)
if (opts.setmod_bw > 25000) opts.setmod_bw = 25000; //not too high if (opts.setmod_bw > 25000) opts.setmod_bw = 25000; //not too high
break; break;
// case 'e':
// opts.errorbars = 1;
// opts.datascope = 0;
// break;
// case 'p':
// if (optarg[0] == 'e')
// {
// opts.p25enc = 1;
// }
// else if (optarg[0] == 'l')
// {
// opts.p25lc = 1;
// }
// else if (optarg[0] == 's')
// {
// opts.p25status = 1;
// }
// else if (optarg[0] == 't')
// {
// opts.p25tg = 1;
// }
// else if (optarg[0] == 'u')
// {
// opts.unmute_encrypted_p25 = 1;
// fprintf(stderr, "P25 Encrypted Audio Unmuted\n");
// }
// break;
// case 'P':
// sscanf (optarg, "%d", &opts.rtlsdr_ppm_error);
// break;
// case 'q':
// opts.errorbars = 0;
// opts.verbose = 0;
// break;
case 's': case 's':
sscanf (optarg, "%d", &opts.wav_sample_rate); sscanf (optarg, "%d", &opts.wav_sample_rate);
opts.wav_interpolator = opts.wav_sample_rate / opts.wav_decimator; opts.wav_interpolator = opts.wav_sample_rate / opts.wav_decimator;
@@ -1329,12 +1347,6 @@ main (int argc, char **argv)
state.symbolCenter = state.symbolCenter * opts.wav_interpolator; state.symbolCenter = state.symbolCenter * opts.wav_interpolator;
break; break;
// case 't':
// opts.symboltiming = 1;
// opts.errorbars = 1;
// opts.datascope = 0;
// break;
case 'v': case 'v':
sscanf (optarg, "%d", &opts.verbose); sscanf (optarg, "%d", &opts.verbose);
break; break;
@@ -1413,30 +1425,6 @@ main (int argc, char **argv)
} }
break; break;
// case 'G': //Set rtl device gain
// sscanf (optarg, "%d", &opts.rtl_gain_value); //multiple value by ten to make it consitent with the way rtl_fm really works
// break;
// case 'L': //Set rtl squelch level
// sscanf (optarg, "%d", &opts.rtl_squelch_level); //set squelch by user to prevent false positives on NXDN and others
// break;
// case 'V': //Set rtl voltage level
// sscanf (optarg, "%d", &opts.rtl_volume_multiplier); //set 'volume' multiplier for rtl-sdr samples
// break;
// case 'U': //Set rtl udp remote port
// sscanf (optarg, "%d", &opts.rtl_udp_port); //set udp port number for RTL remote
// break;
// case 'D': //Set rtl device index number
// sscanf (optarg, "%d", &opts.rtl_dev_index);
// break;
// case 'Y': //Set rtl VFO bandwidth --recommend 6, 12, 24, 36, 48, default 48? or 12?
// sscanf (optarg, "%d", &opts.rtl_bandwidth);
// break;
case 'N': case 'N':
opts.use_ncurses_terminal = 1; opts.use_ncurses_terminal = 1;
fprintf (stderr,"Enabling NCurses Terminal.\n"); fprintf (stderr,"Enabling NCurses Terminal.\n");
@@ -1459,7 +1447,7 @@ main (int argc, char **argv)
wav_file_directory[1023] = '\0'; wav_file_directory[1023] = '\0';
if (stat(wav_file_directory, &st) == -1) if (stat(wav_file_directory, &st) == -1)
{ {
fprintf (stderr, "-T %s WAV file directory does not exist\n", wav_file_directory); fprintf (stderr, "-P %s WAV file directory does not exist\n", wav_file_directory);
fprintf (stderr, "Creating directory %s to save decoded wav files\n", wav_file_directory); fprintf (stderr, "Creating directory %s to save decoded wav files\n", wav_file_directory);
mkdir(wav_file_directory, 0700); //user read write execute, needs execute for some reason or segfault mkdir(wav_file_directory, 0700); //user read write execute, needs execute for some reason or segfault
} }
@@ -1476,22 +1464,10 @@ main (int argc, char **argv)
fprintf (stderr, "%s", KYEL); fprintf (stderr, "%s", KYEL);
//fprintf (stderr,"DMR Stereo Aggressive Resync Disabled!\n"); //fprintf (stderr,"DMR Stereo Aggressive Resync Disabled!\n");
fprintf (stderr, "Relax P25 Phase 2 MAC_SIGNAL CRC Checksum Pass/Fail\n"); fprintf (stderr, "Relax P25 Phase 2 MAC_SIGNAL CRC Checksum Pass/Fail\n");
fprintf (stderr, "Relax DMR CACH/Burst FEC Pass/Fail\n"); fprintf (stderr, "Relax DMR RAS/CRC CSBK/DATA Pass/Fail\n");
fprintf (stderr, "%s", KNRM); fprintf (stderr, "%s", KNRM);
break; break;
// case 'z':
// sscanf (optarg, "%d", &opts.scoperate);
// opts.errorbars = 0;
// opts.p25enc = 0;
// opts.p25lc = 0;
// opts.p25status = 0;
// opts.p25tg = 0;
// opts.datascope = 1;
// opts.symboltiming = 0;
// fprintf (stderr,"Setting datascope frame rate to %i frame per second.\n", opts.scoperate);
// break;
case 'i': case 'i':
strncpy(opts.audio_in_dev, optarg, 2047); strncpy(opts.audio_in_dev, optarg, 2047);
opts.audio_in_dev[2047] = '\0'; opts.audio_in_dev[2047] = '\0';
@@ -1513,11 +1489,6 @@ main (int argc, char **argv)
// fprintf (stderr,"Writing mbe data temporarily disabled!\n"); // fprintf (stderr,"Writing mbe data temporarily disabled!\n");
break; break;
// case 'c':
// opts.rtlsdr_center_freq = (uint32_t)atofs(optarg);
// fprintf (stderr,"Tuning to frequency: %i Hz\n", opts.rtlsdr_center_freq);
// break;
case 'c': //now is symbol capture bin output like FME Lite case 'c': //now is symbol capture bin output like FME Lite
strncpy(opts.symbol_out_file, optarg, 1023); strncpy(opts.symbol_out_file, optarg, 1023);
opts.symbol_out_file[1023] = '\0'; opts.symbol_out_file[1023] = '\0';
@@ -1556,15 +1527,6 @@ main (int argc, char **argv)
openWavOutFile (&opts, &state); openWavOutFile (&opts, &state);
break; break;
// case 'B':
// sscanf (optarg, "%d", &opts.serial_baud);
// break;
// case 'C':
// strncpy(opts.serial_dev, optarg, 1023);
// opts.serial_dev[1023] = '\0';
// break;
case 'f': case 'f':
if (optarg[0] == 'a') if (optarg[0] == 'a')
{ {
@@ -1578,12 +1540,12 @@ main (int argc, char **argv)
opts.frame_dpmr = 0; opts.frame_dpmr = 0;
opts.frame_provoice = 0; opts.frame_provoice = 0;
opts.frame_ysf = 0; opts.frame_ysf = 0;
opts.pulse_digi_rate_out = 8000; //doesn't matter for /dev/dsp anyways opts.pulse_digi_rate_out = 48000; // /dev/dsp does need this set to 48000 to properly process the upsampling
opts.pulse_digi_out_channels = 1; opts.pulse_digi_out_channels = 1;
opts.dmr_stereo = 0; opts.dmr_stereo = 1; //switching in 'stereo' for 'mono'
opts.dmr_mono = 1; opts.dmr_mono = 0;
state.dmr_stereo = 0; state.dmr_stereo = 0;
opts.setmod_bw = 7000; //opts.setmod_bw = 7000;
sprintf (opts.output_name, "Legacy Auto"); sprintf (opts.output_name, "Legacy Auto");
} }
else if (optarg[0] == 'd') else if (optarg[0] == 'd')
@@ -1677,7 +1639,7 @@ main (int argc, char **argv)
opts.dmr_mono = 0; opts.dmr_mono = 0;
opts.pulse_digi_rate_out = 48000; opts.pulse_digi_rate_out = 48000;
opts.pulse_digi_out_channels = 1; opts.pulse_digi_out_channels = 1;
opts.setmod_bw = 7000; opts.setmod_bw = 12000;
sprintf (opts.output_name, "P25P1"); sprintf (opts.output_name, "P25P1");
fprintf (stderr,"Decoding only P25 Phase 1 frames.\n"); fprintf (stderr,"Decoding only P25 Phase 1 frames.\n");
} }
@@ -1704,7 +1666,7 @@ main (int argc, char **argv)
opts.dmr_stereo = 0; opts.dmr_stereo = 0;
state.dmr_stereo = 0; state.dmr_stereo = 0;
opts.dmr_mono = 0; opts.dmr_mono = 0;
opts.setmod_bw = 4000; // opts.setmod_bw = 4000; //causing issues
sprintf (opts.output_name, "NXDN48"); sprintf (opts.output_name, "NXDN48");
fprintf (stderr,"Setting symbol rate to 2400 / second\n"); fprintf (stderr,"Setting symbol rate to 2400 / second\n");
fprintf (stderr,"Decoding only NXDN 4800 baud frames.\n"); fprintf (stderr,"Decoding only NXDN 4800 baud frames.\n");
@@ -1758,7 +1720,7 @@ main (int argc, char **argv)
opts.dmr_stereo = 1; opts.dmr_stereo = 1;
state.dmr_stereo = 0; state.dmr_stereo = 0;
opts.dmr_mono = 0; opts.dmr_mono = 0;
opts.setmod_bw = 7000; opts.setmod_bw = 12000;
sprintf (opts.output_name, "P25P2"); sprintf (opts.output_name, "P25P2");
fprintf (stderr,"Decoding P25-P2 frames C4FM or OP25 Symbol Captures!\n"); fprintf (stderr,"Decoding P25-P2 frames C4FM or OP25 Symbol Captures!\n");
} }
@@ -1809,7 +1771,7 @@ main (int argc, char **argv)
state.rf_mod = 0; state.rf_mod = 0;
opts.dmr_stereo = 1; opts.dmr_stereo = 1;
opts.dmr_mono = 0; opts.dmr_mono = 0;
opts.setmod_bw = 7000; opts.setmod_bw = 12000; //safe default on both DMR and P25
opts.pulse_digi_rate_out = 24000; opts.pulse_digi_rate_out = 24000;
opts.pulse_digi_out_channels = 2; opts.pulse_digi_out_channels = 2;
sprintf (opts.output_name, "XDMA"); sprintf (opts.output_name, "XDMA");
@@ -1836,7 +1798,7 @@ main (int argc, char **argv)
opts.dmr_stereo = 0; opts.dmr_stereo = 0;
opts.dmr_mono = 0; opts.dmr_mono = 0;
state.dmr_stereo = 0; state.dmr_stereo = 0;
opts.setmod_bw = 7000; // opts.setmod_bw = 7000; //causing issues
sprintf (opts.output_name, "NXDN96"); sprintf (opts.output_name, "NXDN96");
fprintf (stderr,"Decoding only NXDN 9600 baud frames.\n"); fprintf (stderr,"Decoding only NXDN 9600 baud frames.\n");
} }
@@ -1863,30 +1825,9 @@ main (int argc, char **argv)
state.dmr_stereo = 0; //0 state.dmr_stereo = 0; //0
opts.setmod_bw = 7000; opts.setmod_bw = 7000;
sprintf (opts.output_name, "DMR Mono"); sprintf (opts.output_name, "DMR Mono");
//fprintf(stderr, "Notice: DMR cannot autodetect polarity. \n Use -xr option if Inverted Signal expected.\n"); fprintf(stderr, "Notice: DMR cannot autodetect polarity. \n Use -xr option if Inverted Signal expected.\n");
fprintf (stderr,"Decoding only DMR Mono. \nUsing DMR Stereo or XDMA is highly encouraged.\n"); fprintf (stderr,"Decoding only DMR Mono. \nUsing DMR Stereo '-fs' or XDMA '-ft' is highly encouraged.\n");
//dmr stereo below
// opts.frame_dstar = 0;
// opts.frame_x2tdma = 0;
// opts.frame_p25p1 = 0;
// opts.frame_p25p2 = 0;
// opts.inverted_p2 = 0;
// opts.frame_nxdn48 = 0;
// opts.frame_nxdn96 = 0;
// opts.frame_dmr = 1;
// opts.frame_dpmr = 0;
// opts.frame_provoice = 0;
// opts.frame_ysf = 0;
// opts.mod_c4fm = 1;
// opts.mod_qpsk = 0;
// opts.mod_gfsk = 0;
// state.rf_mod = 0;
// opts.dmr_stereo = 1;
// state.dmr_stereo = 0;
// opts.pulse_digi_rate_out = 24000;
// opts.pulse_digi_out_channels = 2;
// sprintf (opts.output_name, "DMR Stereo");
// fprintf (stderr,"Decoding DMR Stereo BS/MS Simplex\n");
} }
else if (optarg[0] == 'm') else if (optarg[0] == 'm')
{ {
@@ -1916,14 +1857,14 @@ main (int argc, char **argv)
fprintf(stderr, "Decoding only dPMR frames.\n"); fprintf(stderr, "Decoding only dPMR frames.\n");
} }
break; break;
//don't mess with the modulations, doesn't really do anything meaningful anyways //don't mess with the modulations unless you really need to
case 'm': case 'm':
if (optarg[0] == 'a') if (optarg[0] == 'a')
{ {
// opts.mod_c4fm = 1; opts.mod_c4fm = 1;
// opts.mod_qpsk = 1; opts.mod_qpsk = 1;
// opts.mod_gfsk = 1; opts.mod_gfsk = 1;
// state.rf_mod = 0; state.rf_mod = 0;
fprintf (stderr,"Don't use the -ma switch.\n"); fprintf (stderr,"Don't use the -ma switch.\n");
} }
else if (optarg[0] == 'c') else if (optarg[0] == 'c')
@@ -1962,6 +1903,29 @@ main (int argc, char **argv)
opts.setmod_bw = 12000; opts.setmod_bw = 12000;
fprintf (stderr,"Enabling 6000 sps P25p2 CQPSK.\n"); fprintf (stderr,"Enabling 6000 sps P25p2 CQPSK.\n");
} }
//test
else if (optarg[0] == '3')
{
opts.mod_c4fm = 1;
opts.mod_qpsk = 0;
opts.mod_gfsk = 0;
state.rf_mod = 0;
state.samplesPerSymbol = 10;
state.symbolCenter = 4;
opts.setmod_bw = 12000;
fprintf (stderr,"Enabling 6000 sps P25p2 C4FM.\n");
}
else if (optarg[0] == '4')
{
opts.mod_c4fm = 1;
opts.mod_qpsk = 1;
opts.mod_gfsk = 1;
state.rf_mod = 0;
state.samplesPerSymbol = 8;
state.symbolCenter = 3;
opts.setmod_bw = 12000;
fprintf (stderr,"Enabling 6000 sps P25p2 all optimizations.\n");
}
break; break;
case 'u': case 'u':
sscanf (optarg, "%i", &opts.uvquality); sscanf (optarg, "%i", &opts.uvquality);
@@ -2321,10 +2285,10 @@ main (int argc, char **argv)
{ {
openWavOutFile (&opts, &state); openWavOutFile (&opts, &state);
} }
else opts.pulse_digi_rate_out = 48000;
{ opts.pulse_digi_out_channels = 1;
openAudioOutDevice (&opts, SAMPLE_RATE_OUT); if (opts.audio_out_type == 0) openPulseOutput(&opts); //need to open it up for output?
} if (opts.audio_out_type == 5) openAudioOutDevice (&opts, SAMPLE_RATE_OUT);
} }
else if (strcmp (opts.audio_in_dev, opts.audio_out_dev) != 0) else if (strcmp (opts.audio_in_dev, opts.audio_out_dev) != 0)
@@ -2359,10 +2323,7 @@ main (int argc, char **argv)
if (opts.playfiles == 1) if (opts.playfiles == 1)
{ {
opts.pulse_digi_rate_out = 48000; state.aout_gain = 25; //BUGFIX: No audio output when playing back .amb/.imb files
opts.pulse_digi_out_channels = 1;
// openPulseOutput(&opts); //need to open it up for output?
openAudioInDevice (&opts); //needs to be tested, not sure if required
playMbeFiles (&opts, &state, argc, argv); playMbeFiles (&opts, &state, argc, argv);
} }

View File

@@ -17,72 +17,6 @@
#include "dsd.h" #include "dsd.h"
void
playMbeFiles (dsd_opts * opts, dsd_state * state, int argc, char **argv)
{
int i;
char imbe_d[88];
char ambe_d[49];
for (i = state->optind; i < argc; i++)
{
sprintf (opts->mbe_in_file, "%s", argv[i]);
openMbeInFile (opts, state);
mbe_initMbeParms (state->cur_mp, state->prev_mp, state->prev_mp_enhanced);
fprintf (stderr, "playing %s\n", opts->mbe_in_file);
while (feof (opts->mbe_in_f) == 0)
{
if (state->mbe_file_type == 0)
{
readImbe4400Data (opts, state, imbe_d);
mbe_processImbe4400Dataf (state->audio_out_temp_buf, &state->errs, &state->errs2, state->err_str, imbe_d, state->cur_mp, state->prev_mp, state->prev_mp_enhanced, opts->uvquality);
if (opts->audio_out == 1)
{
processAudio(opts, state);
}
if (opts->wav_out_f != NULL)
{
writeSynthesizedVoice (opts, state);
}
if (opts->audio_out == 1)
{
playSynthesizedVoice (opts, state);
}
}
else if (state->mbe_file_type == 1)
{
readAmbe2450Data (opts, state, ambe_d);
mbe_processAmbe2450Dataf (state->audio_out_temp_buf, &state->errs, &state->errs2, state->err_str, ambe_d, state->cur_mp, state->prev_mp, state->prev_mp_enhanced, opts->uvquality);
if (opts->audio_out == 1)
{
processAudio(opts, state);
}
if (opts->wav_out_f != NULL)
{
writeSynthesizedVoice (opts, state);
}
if (opts->audio_out == 1)
{
playSynthesizedVoice (opts, state);
}
}
if (exitflag == 1)
{
cleanupAndExit (opts, state);
}
}
}
}
void
processMbeFrame (dsd_opts * opts, dsd_state * state, char imbe_fr[8][23], char ambe_fr[4][24], char imbe7100_fr[7][24])
{
//
int Pr[256] = { int Pr[256] = {
0x0000, 0x1F00, 0xE300, 0xFC00, 0x2503, 0x3A03, 0xC603, 0xD903, 0x0000, 0x1F00, 0xE300, 0xFC00, 0x2503, 0x3A03, 0xC603, 0xD903,
0x4A05, 0x5505, 0xA905, 0xB605, 0x6F06, 0x7006, 0x8C06, 0x9306, 0x4A05, 0x5505, 0xA905, 0xB605, 0x6F06, 0x7006, 0x8C06, 0x9306,
@@ -117,7 +51,87 @@ processMbeFrame (dsd_opts * opts, dsd_state * state, char imbe_fr[8][23], char a
0x0BF0, 0x14F0, 0xE8F0, 0xF7F0, 0x2EF3, 0x31F3, 0xCDF3, 0xD2F3, 0x0BF0, 0x14F0, 0xE8F0, 0xF7F0, 0x2EF3, 0x31F3, 0xCDF3, 0xD2F3,
0x41F5, 0x5EF5, 0xA2F5, 0xBDF5, 0x64F6, 0x7BF6, 0x87F6, 0x98F6 //255 0x41F5, 0x5EF5, 0xA2F5, 0xBDF5, 0x64F6, 0x7BF6, 0x87F6, 0x98F6 //255
}; };
//
void playMbeFiles (dsd_opts * opts, dsd_state * state, int argc, char **argv)
{
int i;
char imbe_d[88];
char ambe_d[49];
for (i = state->optind; i < argc; i++)
{
sprintf (opts->mbe_in_file, "%s", argv[i]);
openMbeInFile (opts, state);
mbe_initMbeParms (state->cur_mp, state->prev_mp, state->prev_mp_enhanced);
fprintf (stderr, "playing %s\n", opts->mbe_in_file);
while (feof (opts->mbe_in_f) == 0)
{
if (state->mbe_file_type == 0)
{
readImbe4400Data (opts, state, imbe_d);
mbe_processImbe4400Dataf (state->audio_out_temp_buf, &state->errs, &state->errs2, state->err_str, imbe_d, state->cur_mp, state->prev_mp, state->prev_mp_enhanced, opts->uvquality);
if (opts->audio_out == 1)
{
processAudio(opts, state);
}
if (opts->wav_out_f != NULL)
{
writeSynthesizedVoice (opts, state);
}
if (opts->audio_out == 1)
{
playSynthesizedVoice (opts, state);
}
}
else if (state->mbe_file_type > 0) //ambe files
{
readAmbe2450Data (opts, state, ambe_d);
int j, x;
unsigned long long int k;
if (state->K != 0) //apply Pr key
{
k = Pr[state->K];
k = ( ((k & 0xFF0F) << 32 ) + (k << 16) + k );
for (short int j = 0; j < 48; j++) //49
{
x = ( ((k << j) & 0x800000000000) >> 47 );
ambe_d[j] ^= x;
}
}
//ambe+2
if (state->mbe_file_type == 1) mbe_processAmbe2450Dataf (state->audio_out_temp_buf, &state->errs, &state->errs2, state->err_str, ambe_d, state->cur_mp, state->prev_mp, state->prev_mp_enhanced, opts->uvquality);
//dstar ambe
if (state->mbe_file_type == 2) mbe_processAmbe2400Dataf (state->audio_out_temp_buf, &state->errs, &state->errs2, state->err_str, ambe_d, state->cur_mp, state->prev_mp, state->prev_mp_enhanced, opts->uvquality);
if (opts->audio_out == 1)
{
processAudio(opts, state);
}
if (opts->wav_out_f != NULL)
{
writeSynthesizedVoice (opts, state);
}
if (opts->audio_out == 1)
{
playSynthesizedVoice (opts, state);
}
}
if (exitflag == 1)
{
cleanupAndExit (opts, state);
}
}
}
}
void
processMbeFrame (dsd_opts * opts, dsd_state * state, char imbe_fr[8][23], char ambe_fr[4][24], char imbe7100_fr[7][24])
{
int i; int i;
char imbe_d[88]; char imbe_d[88];
@@ -126,6 +140,11 @@ processMbeFrame (dsd_opts * opts, dsd_state * state, char imbe_fr[8][23], char a
unsigned long long int k; unsigned long long int k;
int x; int x;
//24-bit TG to 16-bit hash
uint16_t hash = 0;
uint8_t hash_bits[24];
memset (hash_bits, 0, sizeof(hash_bits));
int preempt = 0; //TDMA dual voice slot preemption(when using OSS output) int preempt = 0; //TDMA dual voice slot preemption(when using OSS output)
@@ -279,6 +298,31 @@ processMbeFrame (dsd_opts * opts, dsd_state * state, char imbe_fr[8][23], char a
mbe_demodulateAmbe3600x2450Data (ambe_fr); mbe_demodulateAmbe3600x2450Data (ambe_fr);
state->errs2 = mbe_eccAmbe3600x2450Data (ambe_fr, ambe_d); state->errs2 = mbe_eccAmbe3600x2450Data (ambe_fr, ambe_d);
//EXPERIMENTAL!!
//load basic privacy key number from array by the tg value (if not forced)
//currently only Moto BP and Hytera 10 Char BP (converted to decimal)
if (state->M == 0)
{
//see if we need to hash a value larger than 16-bits
hash = state->lasttg & 0xFFFFFF;
if (hash > 0xFFFF) //if greater than 16-bits
{
for (int i = 0; i < 24; i++)
{
hash_bits[i] = ((hash << i) & 0x800000) >> 23; //load into array for CRC16
}
hash = ComputeCrcCCITT16d (hash_bits, 24);
hash = hash & 0xFFFF; //make sure its no larger than 16-bits
}
if (state->rkey_array[hash] != 0)
{
state->K = state->rkey_array[hash] & 0xFF; //doesn't exceed 255
state->K1 = state->rkey_array[hash] & 0xFFFFFFFFFF; //doesn't exceed 40-bit limit
opts->dmr_mute_encL = 0;
}
// else opts->dmr_mute_encL = 1; //may cause issues for manual key entry (non-csv)
}
if ( (state->K > 0 && state->dmr_so & 0x40 && state->payload_keyid == 0 && state->dmr_fid == 0x10) || if ( (state->K > 0 && state->dmr_so & 0x40 && state->payload_keyid == 0 && state->dmr_fid == 0x10) ||
(state->K > 0 && state->M == 1) ) (state->K > 0 && state->M == 1) )
{ {
@@ -364,6 +408,13 @@ processMbeFrame (dsd_opts * opts, dsd_state * state, char imbe_fr[8][23], char a
{ {
PrintAMBEData (opts, state, ambe_d); PrintAMBEData (opts, state, ambe_d);
} }
//restore MBE file save, slot 1 -- consider saving even if enc
if (opts->mbe_out_f != NULL && (state->dmr_encL == 0 || opts->dmr_mute_encL == 0) )
{
saveAmbe2450Data (opts, state, ambe_d);
}
} }
//stereo slots and slot 1 (right slot) //stereo slots and slot 1 (right slot)
if (state->currentslot == 1) //&& opts->dmr_stereo == 1 if (state->currentslot == 1) //&& opts->dmr_stereo == 1
@@ -374,6 +425,31 @@ processMbeFrame (dsd_opts * opts, dsd_state * state, char imbe_fr[8][23], char a
mbe_demodulateAmbe3600x2450Data (ambe_fr); mbe_demodulateAmbe3600x2450Data (ambe_fr);
state->errs2R = mbe_eccAmbe3600x2450Data (ambe_fr, ambe_d); state->errs2R = mbe_eccAmbe3600x2450Data (ambe_fr, ambe_d);
//EXPERIMENTAL!!
//load basic privacy key number from array by the tg value (if not forced)
//currently only Moto BP and Hytera 10 Char BP (converted to decimal)
if (state->M == 0)
{
//see if we need to hash a value larger than 16-bits
hash = state->lasttgR & 0xFFFFFF;
if (hash > 0xFFFF) //if greater than 16-bits
{
for (int i = 0; i < 24; i++)
{
hash_bits[i] = ((hash << i) & 0x800000) >> 23; //load into array for CRC16
}
hash = ComputeCrcCCITT16d (hash_bits, 24);
hash = hash & 0xFFFF; //make sure its no larger than 16-bits
}
if (state->rkey_array[hash] != 0)
{
state->K = state->rkey_array[hash] & 0xFF; //doesn't exceed 255
state->K1 = state->rkey_array[hash] & 0xFFFFFFFFFF; //doesn't exceed 40-bit limit
opts->dmr_mute_encR = 0;
}
// else opts->dmr_mute_encR = 1; //may cause issues for manual key entry (non-csv)
}
if ( (state->K > 0 && state->dmr_soR & 0x40 && state->payload_keyidR == 0 && state->dmr_fidR == 0x10) || if ( (state->K > 0 && state->dmr_soR & 0x40 && state->payload_keyidR == 0 && state->dmr_fidR == 0x10) ||
(state->K > 0 && state->M == 1) ) (state->K > 0 && state->M == 1) )
{ {
@@ -458,6 +534,12 @@ processMbeFrame (dsd_opts * opts, dsd_state * state, char imbe_fr[8][23], char a
{ {
PrintAMBEData (opts, state, ambe_d); PrintAMBEData (opts, state, ambe_d);
} }
//restore MBE file save, slot 2 -- consider saving even if enc
if (opts->mbe_out_fR != NULL && (state->dmr_encR == 0 || opts->dmr_mute_encR == 0) )
{
saveAmbe2450DataR (opts, state, ambe_d);
}
} }
//X2-TDMA? Not sure what still makes it this far to run under Framef //X2-TDMA? Not sure what still makes it this far to run under Framef

View File

@@ -840,9 +840,14 @@ void ncursesMenu (dsd_opts * opts, dsd_state * state)
if(opts->tcp_file_in == NULL) if(opts->tcp_file_in == NULL)
{ {
fprintf(stderr, "Error, couldn't open TCP with libsndfile: %s\n", sf_strerror(NULL)); fprintf(stderr, "Error, couldn't open TCP with libsndfile: %s\n", sf_strerror(NULL));
if (opts->audio_out_type == 0)
{
sprintf (opts->audio_in_dev, "%s", "pulse"); sprintf (opts->audio_in_dev, "%s", "pulse");
opts->audio_in_type = 0; opts->audio_in_type = 0;
} }
else opts->audio_in_type = 5;
}
state->audio_smoothing = 0; //disable smoothing to prevent random crackling/buzzing state->audio_smoothing = 0; //disable smoothing to prevent random crackling/buzzing
@@ -971,7 +976,8 @@ void ncursesMenu (dsd_opts * opts, dsd_state * state)
} }
} }
opts->audio_in_type = 0; //set after closing to prevent above crash condition if (opts->audio_out_type == 0) opts->audio_in_type = 0; //set after closing to prevent above crash condition
else (opts->audio_in_type = 5);
choicec = 18; //exit choicec = 18; //exit
} }
@@ -1045,7 +1051,7 @@ void ncursesMenu (dsd_opts * opts, dsd_state * state)
mvwprintw(entry_win, 3, 2, " "); mvwprintw(entry_win, 3, 2, " ");
mvwprintw(entry_win, 4, 2, "1 - Basic Privacy "); mvwprintw(entry_win, 4, 2, "1 - Basic Privacy ");
mvwprintw(entry_win, 5, 2, "2 - **tera Privacy "); mvwprintw(entry_win, 5, 2, "2 - **tera Privacy ");
mvwprintw(entry_win, 6, 2, "3 - NXDN Scrambler "); mvwprintw(entry_win, 6, 2, "3 - NXDN/dPMR Scrambler ");
mvwprintw(entry_win, 7, 2, "4 - Force Key Priority "); mvwprintw(entry_win, 7, 2, "4 - Force Key Priority ");
mvwprintw(entry_win, 8, 3, " "); mvwprintw(entry_win, 8, 3, " ");
echo(); echo();
@@ -1125,7 +1131,7 @@ void ncursesMenu (dsd_opts * opts, dsd_state * state)
state->R = 0; state->R = 0;
entry_win = newwin(6, WIDTH+6, starty+10, startx+10); entry_win = newwin(6, WIDTH+6, starty+10, startx+10);
box (entry_win, 0, 0); box (entry_win, 0, 0);
mvwprintw(entry_win, 2, 2, "NXDN Scrambler Key Value (DEC):"); mvwprintw(entry_win, 2, 2, "NXDN/dPMR Scrambler Key Value (DEC):");
mvwprintw(entry_win, 3, 3, " "); mvwprintw(entry_win, 3, 3, " ");
echo(); echo();
refresh(); refresh();
@@ -1684,35 +1690,21 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state)
if (opts->audio_in_type != 1) //can't run getch/menu when using STDIN - if (opts->audio_in_type != 1) //can't run getch/menu when using STDIN -
{ {
timeout(0); timeout(0); //
c = getch(); c = getch(); //
} }
//testing sending UDP commands to the socket inside of rtl_sdr_fm.cpp //use rtl_udp_tune
//this works, but we will want to make an init func open one time, and have sendto here
#ifdef USE_RTLSDR #ifdef USE_RTLSDR
if (temp_freq == opts->rtlsdr_center_freq) if (temp_freq == opts->rtlsdr_center_freq)
{ {
handle = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); rtl_udp_tune (opts, state, temp_freq);
memset((char * ) & address, 0, sizeof(address));
address.sin_family = AF_INET;
address.sin_addr.s_addr = inet_addr(SRV_IP); //address of host
address.sin_port = htons(udp_port);
sendto(handle, data, UDP_BUFLEN, 0, (const struct sockaddr * ) & address, sizeof(struct sockaddr_in));
temp_freq = -1; temp_freq = -1;
} }
#endif #endif
//Variable reset/set section //Variable reset/set section
//carrier reset
// if (state->carrier == 0) //reset these to 0 when no carrier
// {
// sprintf(state->dmr_branding, "%s", "");
// }
//set lls sync types //set lls sync types
if (state->synctype >= 0 && state->synctype < 39) if (state->synctype >= 0 && state->synctype < 39)
{ {
@@ -1908,7 +1900,7 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state)
openWavOutFileL (opts, state); //testing for now, will want to move to per call later openWavOutFileL (opts, state); //testing for now, will want to move to per call later
} }
if (opts->call_alert == 1) if (opts->call_alert == 1 && rd != 0 && tg != 0)
{ {
//fprintf (stderr, "BEEP 0 MS LEFT\n"); //fprintf (stderr, "BEEP 0 MS LEFT\n");
beeper (opts, state, 0); beeper (opts, state, 0);
@@ -1951,7 +1943,7 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state)
openWavOutFileL (opts, state); //testing for now, will want to move to per call later openWavOutFileL (opts, state); //testing for now, will want to move to per call later
} }
if (opts->call_alert == 1) if (opts->call_alert == 1 && rd != 0 && tg != 0)
{ {
//fprintf (stderr, "BEEP 0 BS LEFT\n"); //fprintf (stderr, "BEEP 0 BS LEFT\n");
beeper (opts, state, 0); beeper (opts, state, 0);
@@ -1993,7 +1985,7 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state)
openWavOutFileR (opts, state); //testing for now, will want to move to per call later openWavOutFileR (opts, state); //testing for now, will want to move to per call later
} }
if (opts->call_alert == 1) if (opts->call_alert == 1 && rdR != 0 && tgR != 0)
{ {
//fprintf (stderr, "BEEP 1 BS RIGHT\n"); //fprintf (stderr, "BEEP 1 BS RIGHT\n");
beeper (opts, state, 1); beeper (opts, state, 1);
@@ -2048,11 +2040,19 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state)
// { // {
// beeper (opts, state, 0); // beeper (opts, state, 0);
// state->dmr_end_alert[0] = 1; //don't play again until new voice frames // state->dmr_end_alert[0] = 1; //don't play again until new voice frames
// state->lasttg = 0;
// state->lastsrc = 0;
// rd = 0;
// tg = 0;
// } // }
// if (state->dmrburstR == 2 && state->dmr_end_alert[1] == 0) //if TLC and flag not tripped // if (state->dmrburstR == 2 && state->dmr_end_alert[1] == 0) //if TLC and flag not tripped
// { // {
// beeper (opts, state, 1); // beeper (opts, state, 1);
// state->dmr_end_alert[1] = 1; //don't play again until new voice frames // state->dmr_end_alert[1] = 1; //don't play again until new voice frames
// state->lasttgR = 0;
// state->lastsrcR = 0;
// rdR = 0;
// tgR = 0;
// } // }
// } // }
@@ -2061,7 +2061,7 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state)
if (opts->ncurses_compact == 1) if (opts->ncurses_compact == 1)
{ {
printw ("------------------------------------------------------------------------------\n"); printw ("------------------------------------------------------------------------------\n");
printw ("| Digital Speech Decoder: Florida Man Edition - Win32 %s \n", "v2.0.0-6-gc44e039 RC1"); printw ("| Digital Speech Decoder: Florida Man Edition - Win32 %s \n", "v2.0.0-40-gc999c97 RC4");
} }
if (opts->ncurses_compact == 0) if (opts->ncurses_compact == 0)
{ {
@@ -2072,8 +2072,8 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state)
if (i == 1) printw (" ESC to Menu"); if (i == 1) printw (" ESC to Menu");
if (i == 2) printw (" 'q' to Quit "); if (i == 2) printw (" 'q' to Quit ");
if (i == 4) printw (" MBElib %s", versionstr); if (i == 4) printw (" MBElib %s", versionstr);
if (i == 5) printw (" %s ", "Win32 RC1"); //printw (" %s \n", GIT_TAG); if (i == 5) printw (" %s ", "Win32 RC4"); //printw (" %s \n", GIT_TAG);
if (i == 6) printw (" %s \n", "v2.0.0-6-gc44e039"); //printw (" %s \n", GIT_TAG); if (i == 6) printw (" %s \n", "v2.0.0-40-gc999c97"); //printw (" %s \n", GIT_TAG);
else printw ("\n"); else printw ("\n");
} }
attroff(COLOR_PAIR(6)); //6 attroff(COLOR_PAIR(6)); //6
@@ -2178,6 +2178,7 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state)
{ {
printw ("| Reverse Mute - Muting Unencrypted Voice\n"); printw ("| Reverse Mute - Muting Unencrypted Voice\n");
} }
if (opts->aggressive_framesync == 0) printw ("| Selective CRC ERR Bypass Enabled (RAS) \n");
printw ("------------------------------------------------------------------------------\n"); printw ("------------------------------------------------------------------------------\n");
attroff(COLOR_PAIR(4)); attroff(COLOR_PAIR(4));
@@ -2372,7 +2373,7 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state)
} }
else if (lls == 0 || lls == 1) //P1 else if (lls == 0 || lls == 1) //P1
{ {
printw ("P25 P1 - WACN: [%05llX] SYS: [%03llX] NAC: [%03llX] ", state->p2_wacn, state->p2_sysid, state->p2_cc); printw ("P25 P1 - [%05llX][%03llX][%03llX] RFSS: [%lld] SITE: [%lld] ", state->p2_wacn, state->p2_sysid, state->p2_cc, state->p2_rfssid, state->p2_siteid);
if (state->p25_cc_freq != 0) if (state->p25_cc_freq != 0)
{ {
printw ("Freq: [%.06lf] MHz", (double)state->p25_cc_freq/1000000); printw ("Freq: [%.06lf] MHz", (double)state->p25_cc_freq/1000000);
@@ -2380,7 +2381,7 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state)
} }
else if (lls == 35 || lls == 36) //P2 else if (lls == 35 || lls == 36) //P2
{ {
printw ("P25 P2 - WACN: [%05llX] SYS: [%03llX] NAC: [%03llX] ", state->p2_wacn, state->p2_sysid, state->p2_cc); printw ("P25 P2 - [%05llX][%03llX][%03llX] RFSS: [%lld] SITE: [%lld] ", state->p2_wacn, state->p2_sysid, state->p2_cc, state->p2_rfssid, state->p2_siteid);
if (state->p2_wacn == 0 || state->p2_sysid == 0 || state->p2_cc == 0) if (state->p2_wacn == 0 || state->p2_sysid == 0 || state->p2_cc == 0)
{ {
attron(COLOR_PAIR(2)); attron(COLOR_PAIR(2));
@@ -2492,7 +2493,7 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state)
printw("AES-128"); printw("AES-128");
attron(COLOR_PAIR(3)); attron(COLOR_PAIR(3));
} }
if (state->payload_algid == 0x84 || state->payload_algid == 0x25) if (state->payload_algid == 0x84 || state->payload_algid == 0x25 || state->payload_algid == 0x05)
{ {
attron(COLOR_PAIR(1)); attron(COLOR_PAIR(1));
printw("AES-256"); printw("AES-256");
@@ -2533,17 +2534,6 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state)
attron(COLOR_PAIR(4)); attron(COLOR_PAIR(4));
//Frequency Display
if (state->p25_vc_freq[0] != 0)
{
attron(COLOR_PAIR(5));
printw ("Frequency: [%.06lf] MHz ", (double)state->p25_vc_freq[0]/1000000);
if (state->carrier == 1)
{
attron(COLOR_PAIR(3));
}
}
if(state->dmrburstL == 16) //only during call if(state->dmrburstL == 16) //only during call
{ {
@@ -2569,7 +2559,7 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state)
} }
//LRRP //LRRP
if(state->dmrburstL != 16 && opts->p25_trunk == 0) //only during data and no trunking if(state->dmrburstL != 16) //only during data and no trunking //&& opts->p25_trunk == 0
{ {
attron(COLOR_PAIR(4)); attron(COLOR_PAIR(4));
printw ("%s", state->dmr_lrrp_gps[0]); printw ("%s", state->dmr_lrrp_gps[0]);
@@ -2598,8 +2588,9 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state)
printw ("\n"); printw ("\n");
//Slot 2 [1] //Slot 2 [1] //Don't print on MS mode
if (lls < 30 || lls == 35 || lls == 36){ //Don't print on MS mode if (lls < 30 || lls == 35 || lls == 36)
{
printw ("| SLOT 2 - "); printw ("| SLOT 2 - ");
if (state->dmrburstR < 16 && state->carrier == 1 && state->lasttgR > 0 && state->lastsrcR > 0) if (state->dmrburstR < 16 && state->carrier == 1 && state->lasttgR > 0 && state->lastsrcR > 0)
{ {
@@ -2684,7 +2675,7 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state)
printw("AES-128"); printw("AES-128");
attron(COLOR_PAIR(3)); attron(COLOR_PAIR(3));
} }
if (state->payload_algidR == 0x84 || state->payload_algidR == 0x25) if (state->payload_algidR == 0x84 || state->payload_algidR == 0x25 || state->payload_algidR == 0x05)
{ {
attron(COLOR_PAIR(1)); attron(COLOR_PAIR(1));
printw("AES-256"); printw("AES-256");
@@ -2725,17 +2716,6 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state)
attron(COLOR_PAIR(4)); attron(COLOR_PAIR(4));
//Frequency Display
if (state->p25_vc_freq[1] != 0)
{
attron(COLOR_PAIR(5));
printw ("Frequency: [%.06lf] MHz ", (double)state->p25_vc_freq[1]/1000000);
if (state->carrier == 1)
{
attron(COLOR_PAIR(3));
}
}
if(state->dmrburstR == 16) //only during call if(state->dmrburstR == 16) //only during call
{ {
@@ -2761,7 +2741,7 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state)
} }
//LRRP //LRRP
if(state->dmrburstR != 16 && opts->p25_trunk == 0) //only during data and no trunking if(state->dmrburstR != 16) //only during data and no trunking //&& opts->p25_trunk == 0
{ {
attron(COLOR_PAIR(4)); attron(COLOR_PAIR(4));
printw ("%s", state->dmr_lrrp_gps[1]); printw ("%s", state->dmr_lrrp_gps[1]);
@@ -2789,6 +2769,22 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state)
else attroff(COLOR_PAIR(4)); else attroff(COLOR_PAIR(4));
printw ("\n"); printw ("\n");
if (1 == 1) //opts->p25_trunk == 1
{
printw ("| T INFO | ");
// Tuned Frequency Display
if (state->p25_vc_freq[0] != 0)
{
attron(COLOR_PAIR(4));
printw ("Frequency: [%.06lf] MHz ", (double)state->p25_vc_freq[0]/1000000);
}
if (state->carrier == 1) attron(COLOR_PAIR(3));
else attroff(COLOR_PAIR(4));
printw ("\n");
}
} // end if not MS } // end if not MS
} //end DMR BS Types } //end DMR BS Types
@@ -2796,7 +2792,23 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state)
if (lls == 20 || lls == 21 || lls == 22 || lls == 23 ||lls == 24 || lls == 25 || lls == 26 || lls == 27) if (lls == 20 || lls == 21 || lls == 22 || lls == 23 ||lls == 24 || lls == 25 || lls == 26 || lls == 27)
{ {
printw ("| DCC: [%i] ", state->dpmr_color_code); printw ("| DCC: [%i] ", state->dpmr_color_code);
printw ("TID: [%s] RID: [%s] \n", state->dpmr_target_id, state->dpmr_caller_id); printw ("TGT: [%s] SRC: [%s] ", state->dpmr_target_id, state->dpmr_caller_id);
printw ("\n| ");
if (state->dPMRVoiceFS2Frame.Version[0] == 3)
{
attron(COLOR_PAIR(2));
printw ("Scrambler ");
attroff(COLOR_PAIR(2));
attron(COLOR_PAIR(3));
if (state->R != 0)
{
attron(COLOR_PAIR(1));
printw ("KEY VALUE: [%05lld] ", state->R );
//printw ("SEED: [%04llX]", state->payload_miN);
attron(COLOR_PAIR(3));
}
}
printw ("\n");
} }
//EDACS and ProVoice //EDACS and ProVoice
@@ -2904,8 +2916,8 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state)
printw ("--Call History----------------------------------------------------------------\n"); printw ("--Call History----------------------------------------------------------------\n");
for (short int j = 0; j < 10; j++) for (short int j = 0; j < 10; j++)
{ {
//only print if a valid time was assigned to the matrix, and not EDACS/PV //only print if a valid time was assigned to the matrix, and not EDACS/PV, and source is not zero
if ( ((time(NULL) - call_matrix[9-j][5]) < 999999) && call_matrix[9-j][0] != 14 && call_matrix[9-j][0] != 15 && call_matrix[9-j][0] != 37 && call_matrix[9-j][0] != 38 ) if ( ((time(NULL) - call_matrix[9-j][5]) < 999999) && call_matrix[9-j][0] != 14 && call_matrix[9-j][0] != 15 && call_matrix[9-j][0] != 37 && call_matrix[9-j][0] != 38 && call_matrix[9-j][2] != 0) //
{ {
printw ("| %s ", SyncTypes[call_matrix[9-j][0]]); printw ("| %s ", SyncTypes[call_matrix[9-j][0]]);
if (lls == 28 || lls == 29) if (lls == 28 || lls == 29)
@@ -3106,21 +3118,24 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state)
} }
} }
if (c == 32) //'space bar' replay last bin file (rework to do wav files too?) //
{ // if (c == 32) //'space bar' replay last bin file (rework to do wav files too?)
struct stat stat_buf; // {
if (stat(opts->audio_in_dev, &stat_buf) != 0) // struct stat stat_buf;
{ // if (stat(opts->audio_in_dev, &stat_buf) != 0)
fprintf (stderr,"Error, couldn't open %s\n", opts->audio_in_dev); // {
goto SKIPR; // fprintf (stderr,"Error, couldn't open %s\n", opts->audio_in_dev);
} // goto SKIPR;
if (S_ISREG(stat_buf.st_mode)) // }
{ // if (S_ISREG(stat_buf.st_mode))
opts->symbolfile = fopen(opts->audio_in_dev, "r"); // {
opts->audio_in_type = 4; //symbol capture bin files // opts->symbolfile = fopen(opts->audio_in_dev, "r");
} // opts->audio_in_type = 4; //symbol capture bin files
SKIPR: ; //do nothing // }
} // SKIPR: ; //do nothing
// }
//
if (c == 80) //'P' key - start per call wav files if (c == 80) //'P' key - start per call wav files
{ {
@@ -3153,28 +3168,34 @@ if (c == 112) //'p' key - stop all per call wav files
opts->dmr_stereo_wav = 0; opts->dmr_stereo_wav = 0;
} }
//
// if (c == 115) //'s' key, stop playing wav or symbol in files
// {
// if (opts->symbolfile != NULL)
// {
// if (opts->audio_in_type == 4)
// {
// fclose(opts->symbolfile);
// }
// }
if (c == 115) //'s' key, stop playing wav or symbol in files // if (opts->audio_in_type == 2) //wav input file
{ // {
if (opts->symbolfile != NULL) // sf_close(opts->audio_in_file);
{ // }
if (opts->audio_in_type == 4)
{
fclose(opts->symbolfile);
}
}
if (opts->audio_in_type == 2) //wav input file // if (opts->audio_out_type == 0)
{ // {
sf_close(opts->audio_in_file); // opts->audio_in_type = 0;
} // openPulseInput(opts);
// }
// else opts->audio_in_type = 5;//cleanupAndExit(opts, state);
opts->audio_in_type = 0; // }
openPulseInput(opts); //
}
//Lockout bug in EDACS prevents any group from tuning when using this, not sure why yet // //Lockout bug in EDACS prevents any group from tuning when using this, not sure why yet
//WARNING! USE THESE WITH CAUTION! IF BREAKING ISSUES OBSERVED, THEN RESTART AND DON'T USE THEM!! // //WARNING! USE THESE WITH CAUTION! IF BREAKING ISSUES OBSERVED, THEN RESTART AND DON'T USE THEM!!
if (opts->frame_provoice != 1 && c == 49) //'1' key, lockout slot 1 or conventional tg from tuning/playback during session if (opts->frame_provoice != 1 && c == 49) //'1' key, lockout slot 1 or conventional tg from tuning/playback during session
{ {
state->group_array[state->group_tally].groupNumber = state->lasttg; state->group_array[state->group_tally].groupNumber = state->lasttg;
@@ -3237,6 +3258,38 @@ if (opts->p25_trunk == 1 && c == 103) //'g' key, toggle tune group calls
else opts->trunk_tune_group_calls = 1; else opts->trunk_tune_group_calls = 1;
} }
if (c == 70) //'F' key - toggle agressive sync/crc failure/ras
{
if (opts->aggressive_framesync == 0) opts->aggressive_framesync = 1;
else opts->aggressive_framesync = 0;
}
if (c == 68) //'D' key - Reset DMR Site Parms/Call Strings, etc.
{
//dmr trunking/ncurses stuff
state->dmr_rest_channel = -1; //init on -1
state->dmr_mfid = -1; //
//dmr mfid branding and site parms
sprintf(state->dmr_branding_sub, "%s", "");
sprintf(state->dmr_branding, "%s", "");
sprintf (state->dmr_site_parms, "%s", "");
//DMR Location Area - DMRLA B***S***
opts->dmr_dmrla_is_set = 0;
opts->dmr_dmrla_n = 0;
}
//Debug/Troubleshooting Option
if (c == 90) //'Z' key - Simulate NoCarrier/No VC/CC sync to zero out more stuff (capital Z)
{
// opts->p25_is_tuned = 0;
state->last_cc_sync_time = 0;
state->last_vc_sync_time = 0;
noCarrier(opts, state);
}
//anything with an entry box will need the inputs and outputs stopped first //anything with an entry box will need the inputs and outputs stopped first
//so probably just write a function to handle c input, and when c = certain values //so probably just write a function to handle c input, and when c = certain values
//needing an entry box, then stop all of those //needing an entry box, then stop all of those

View File

@@ -273,4 +273,9 @@ void rtl_udp_tune(dsd_opts * opts, dsd_state * state, long int frequency)
address.sin_addr.s_addr = inet_addr("127.0.0.1"); //make user configurable later address.sin_addr.s_addr = inet_addr("127.0.0.1"); //make user configurable later
address.sin_port = htons(udp_port); address.sin_port = htons(udp_port);
sendto(handle, data, 5, 0, (const struct sockaddr * ) & address, sizeof(struct sockaddr_in)); sendto(handle, data, 5, 0, (const struct sockaddr * ) & address, sizeof(struct sockaddr_in));
//BUGFIX: This was causing an indefinite number of UDP sockets to stay open on each tune request
//we open a new socket with each request, so we need to close the socket after writing to it
//this would cause the tuning to stop after x number of tune attempts (few hours? on a busy system)
close (handle); //close socket after sending.
} }

View File

@@ -312,11 +312,11 @@ void map_isch()
isch_map["fb063f092"] = 127; isch_map["fb063f092"] = 127;
} }
unsigned long long int isch_lookup (unsigned long long int isch) int isch_lookup (unsigned long long int isch)
{ {
map_isch(); //initialize the lookup map map_isch(); //initialize the lookup map
char s[64]; char s[64];
unsigned long long int decoded = -2; //initialize lookup to an invalid number int decoded = -2; //initialize lookup to an invalid number
sprintf(s, "%llx", isch); sprintf(s, "%llx", isch);
decoded = isch_map[s]; decoded = isch_map[s];
return(decoded); return(decoded);

View File

@@ -111,15 +111,13 @@ void nxdn_deperm_facch(dsd_opts * opts, dsd_state * state, uint8_t bits[144])
trellis_buf[(i*8)+7] = (m_data[i] >> 0) & 1; trellis_buf[(i*8)+7] = (m_data[i] >> 0) & 1;
} }
//load tail 16 bits into check variable to compare vs computed crc value crc = crc12f (trellis_buf, 84); //80
for (int i = 0; i < 12; i++) for (int i = 0; i < 12; i++)
{ {
check = check << 1; check = check << 1;
check = check + trellis_buf[80+i]; check = check | trellis_buf[84+i]; //80
} }
crc = crc12f (trellis_buf, 80);
if (crc == check) NXDN_Elements_Content_decode(opts, state, 1, trellis_buf); if (crc == check) NXDN_Elements_Content_decode(opts, state, 1, trellis_buf);
// else if (opts->payload == 1) NXDN_Elements_Content_decode(opts, state, 0, trellis_buf); // else if (opts->payload == 1) NXDN_Elements_Content_decode(opts, state, 0, trellis_buf);
@@ -131,7 +129,7 @@ void nxdn_deperm_facch(dsd_opts * opts, dsd_state * state, uint8_t bits[144])
{ {
fprintf (stderr, "[%02X]", m_data[i]); fprintf (stderr, "[%02X]", m_data[i]);
} }
fprintf (stderr, " - %03X %03X", crc, check); fprintf (stderr, " - %03X %03X", check, crc);
} }
} }
@@ -211,11 +209,11 @@ void nxdn_deperm_sacch(dsd_opts * opts, dsd_state * state, uint8_t bits[60])
trellis_buf[(i*8)+7] = (m_data[i] >> 0) & 1; trellis_buf[(i*8)+7] = (m_data[i] >> 0) & 1;
} }
crc = crc6(trellis_buf, 32); crc = crc6(trellis_buf, 26); //32
for (int i = 0; i < 6; i++) for (int i = 0; i < 6; i++)
{ {
check = check << 1; check = check << 1;
check = check + trellis_buf[i+26]; check = check | trellis_buf[i+26];
} }
//FIRST! If part of a non_superframe, and CRC is good, send directly to NXDN_Elements_Content_decode //FIRST! If part of a non_superframe, and CRC is good, send directly to NXDN_Elements_Content_decode
@@ -231,16 +229,16 @@ void nxdn_deperm_sacch(dsd_opts * opts, dsd_state * state, uint8_t bits[60])
nsf_sacch[i] = trellis_buf[i+8]; nsf_sacch[i] = trellis_buf[i+8];
} }
if (crc == 0) NXDN_Elements_Content_decode(opts, state, 1, nsf_sacch); if (crc == check) NXDN_Elements_Content_decode(opts, state, 1, nsf_sacch);
if (opts->payload == 1) if (opts->payload == 1)
{ {
fprintf (stderr, "\n SACCH NSF "); fprintf (stderr, "\n SACCH NSF ");
for (int i = 0; i < 5; i++) for (int i = 0; i < 4; i++)
{ {
fprintf (stderr, "[%02X]", m_data[i]); fprintf (stderr, "[%02X]", m_data[i]);
} }
if (crc != 0) fprintf (stderr, " CRC ERR - %02X %02X", crc, check); if (crc != check) fprintf (stderr, " CRC ERR - %02X %02X", check, crc);
} }
} }
@@ -266,7 +264,7 @@ void nxdn_deperm_sacch(dsd_opts * opts, dsd_state * state, uint8_t bits[60])
//reset scrambler seed to key value on new superframe //reset scrambler seed to key value on new superframe
if (part_of_frame == 0 && state->nxdn_cipher_type == 0x1) state->payload_miN = 0; if (part_of_frame == 0 && state->nxdn_cipher_type == 0x1) state->payload_miN = 0;
if (crc == 0) if (crc == check)
{ {
state->nxdn_ran = state->nxdn_last_ran = ran; state->nxdn_ran = state->nxdn_last_ran = ran;
state->nxdn_sf = sf; state->nxdn_sf = sf;
@@ -294,11 +292,11 @@ void nxdn_deperm_sacch(dsd_opts * opts, dsd_state * state, uint8_t bits[60])
{ {
fprintf (stderr, "\n"); fprintf (stderr, "\n");
fprintf (stderr, " SACCH SF Segment #%d ", part_of_frame+1); fprintf (stderr, " SACCH SF Segment #%d ", part_of_frame+1);
for (int i = 0; i < 5; i++) for (int i = 0; i < 4; i++)
{ {
fprintf (stderr, "[%02X]", m_data[i]); fprintf (stderr, "[%02X]", m_data[i]);
} }
if (crc != 0) fprintf (stderr, " CRC ERR - %02X %02X", crc, check); if (crc != check) fprintf (stderr, " CRC ERR - %02X %02X", crc, check);
} }
} }
@@ -312,6 +310,7 @@ void nxdn_deperm_facch2_udch(dsd_opts * opts, dsd_state * state, uint8_t bits[34
uint8_t trellis_buf[199]; uint8_t trellis_buf[199];
int id = 0; int id = 0;
uint16_t crc = 0; uint16_t crc = 0;
uint16_t check = 0;
for (int i=0; i<348; i++) { for (int i=0; i<348; i++) {
deperm[PERM_12_29[i]] = bits[i]; deperm[PERM_12_29[i]] = bits[i];
@@ -377,6 +376,11 @@ void nxdn_deperm_facch2_udch(dsd_opts * opts, dsd_state * state, uint8_t bits[34
} }
crc = crc15(trellis_buf, 199); crc = crc15(trellis_buf, 199);
for (int i = 0; i < 15; i++)
{
check = check << 1;
check = check | trellis_buf[i+184];
}
uint8_t f2u_message_buffer[199]; uint8_t f2u_message_buffer[199];
memset (f2u_message_buffer, 0, sizeof(f2u_message_buffer)); memset (f2u_message_buffer, 0, sizeof(f2u_message_buffer));
@@ -388,7 +392,7 @@ void nxdn_deperm_facch2_udch(dsd_opts * opts, dsd_state * state, uint8_t bits[34
f2u_message_buffer[i] = trellis_buf[i+8]; f2u_message_buffer[i] = trellis_buf[i+8];
} }
if (crc == 0) if (crc == check)
{ {
fprintf (stderr, " F2/U "); fprintf (stderr, " F2/U ");
//NXDN_Elements_Content_decode(opts, state, 1, trellis_buf); //NXDN_Elements_Content_decode(opts, state, 1, trellis_buf);
@@ -404,7 +408,7 @@ void nxdn_deperm_facch2_udch(dsd_opts * opts, dsd_state * state, uint8_t bits[34
fprintf (stderr, "[%02X]", m_data[i]); fprintf (stderr, "[%02X]", m_data[i]);
if (i == 12) fprintf (stderr, "\n "); if (i == 12) fprintf (stderr, "\n ");
} }
if (crc != 0) fprintf (stderr, " CRC ERR "); if (crc != check) fprintf (stderr, " CRC ERR ");
} }
} }
@@ -452,11 +456,6 @@ void nxdn_deperm_cac(dsd_opts * opts, dsd_state * state, uint8_t bits[300])
temp[i] = depunc[i] << 1; temp[i] = depunc[i] << 1;
} }
for (int i = 0; i < 8; i++)
{
temp[i+350] = 0;
}
CNXDNConvolution_start(); CNXDNConvolution_start();
for (int i = 0U; i < 179U; i++) for (int i = 0U; i < 179U; i++)
{ {
@@ -482,20 +481,11 @@ void nxdn_deperm_cac(dsd_opts * opts, dsd_state * state, uint8_t bits[300])
crc = crc16cac(trellis_buf, 171); crc = crc16cac(trellis_buf, 171);
//message type will probably be neccesary beforehand on single/dual meessage runs
//run message, check len, load into a seperate buffer, send to element, do same with other piece?
uint8_t MessageType = 0;
for (int i = 0; i < 6; i++)
{
MessageType = MessageType << 1;
MessageType = MessageType + trellis_buf[i+2]; //double check this on CAC
}
uint8_t cac_message_buffer[171]; uint8_t cac_message_buffer[171];
memset (cac_message_buffer, 0, sizeof(cac_message_buffer)); memset (cac_message_buffer, 0, sizeof(cac_message_buffer));
//shift the cac_message into the appropriate byte arrangement for element_decoder //shift the cac_message into the appropriate byte arrangement for element_decoder -- skip SR field
for (int i = 0; i < 160; i++) //in future, we can use this to send multiple messages to decoder, if present for (int i = 0; i < 160; i++)
{ {
cac_message_buffer[i] = trellis_buf[i+8]; cac_message_buffer[i] = trellis_buf[i+8];
} }
@@ -564,7 +554,7 @@ void nxdn_message_type (dsd_opts * opts, dsd_state * state, uint8_t MessageType)
state->nxdn_last_tg = 0; state->nxdn_last_tg = 0;
state->nxdn_cipher_type = 0; state->nxdn_cipher_type = 0;
memset (state->nxdn_sacch_frame_segcrc, 1, sizeof(state->nxdn_sacch_frame_segcrc)); memset (state->nxdn_sacch_frame_segcrc, 1, sizeof(state->nxdn_sacch_frame_segcrc));
memset (state->nxdn_sacch_frame_segment, 0, sizeof(state->nxdn_sacch_frame_segment)); memset (state->nxdn_sacch_frame_segment, 1, sizeof(state->nxdn_sacch_frame_segment));
sprintf (state->nxdn_call_type, "%s", ""); sprintf (state->nxdn_call_type, "%s", "");
} }
} }
@@ -669,12 +659,12 @@ static uint16_t crc15(const uint8_t buf[], int len)
static uint16_t crc16cac(const uint8_t buf[], int len) static uint16_t crc16cac(const uint8_t buf[], int len)
{ {
int crc = 0xc3ee; uint32_t crc = 0xc3ee; //not sure why this though
int poly = (1<<12) + (1<<5) + 1; uint32_t poly = (1<<12) + (1<<5) + 1; //poly is fine
for (int i=0;i<len;i++) { for (int i=0;i<len;i++)
{
crc = ((crc << 1) | buf[i]) & 0x1ffff; crc = ((crc << 1) | buf[i]) & 0x1ffff;
if(crc & 0x10000) if(crc & 0x10000) crc = (crc & 0xffff) ^ poly;
crc = (crc & 0xffff) ^ poly;
} }
crc = crc ^ 0xffff; crc = crc ^ 0xffff;
return crc & 0xffff; return crc & 0xffff;

View File

@@ -233,6 +233,11 @@ void NXDN_decode_VCALL_ASSGN(dsd_opts * opts, dsd_state * state, uint8_t * Messa
long int freq = 0; long int freq = 0;
freq = nxdn_channel_to_frequency(opts, state, Channel); freq = nxdn_channel_to_frequency(opts, state, Channel);
//check the rkey array for a scrambler key value
//TGT ID and Key ID could clash though if csv or system has both with different keys
if (state->rkey_array[DestinationID] != 0) state->R = state->rkey_array[DestinationID];
if (state->M == 1) state->nxdn_cipher_type = 0x1;
//check for control channel frequency in the channel map if not available //check for control channel frequency in the channel map if not available
if (opts->p25_trunk == 1 && state->p25_cc_freq == 0) if (opts->p25_trunk == 1 && state->p25_cc_freq == 0)
{ {
@@ -287,23 +292,46 @@ void NXDN_decode_VCALL_ASSGN(dsd_opts * opts, dsd_state * state, uint8_t * Messa
//rigctl //rigctl
if (opts->use_rigctl == 1) if (opts->use_rigctl == 1)
{ {
//extra safeguards due to sync issues with NXDN
memset (state->nxdn_sacch_frame_segment, 1, sizeof(state->nxdn_sacch_frame_segment));
memset (state->nxdn_sacch_frame_segcrc, 1, sizeof(state->nxdn_sacch_frame_segcrc));
state->lastsynctype = -1;
state->last_cc_sync_time = time(NULL);
state->last_vc_sync_time = time(NULL); //useful?
//
if (opts->setmod_bw != 0 ) SetModulation(opts->rigctl_sockfd, opts->setmod_bw); if (opts->setmod_bw != 0 ) SetModulation(opts->rigctl_sockfd, opts->setmod_bw);
SetFreq(opts->rigctl_sockfd, freq); SetFreq(opts->rigctl_sockfd, freq);
state->p25_vc_freq[0] = state->p25_vc_freq[1] = freq; state->p25_vc_freq[0] = state->p25_vc_freq[1] = freq;
opts->p25_is_tuned = 1; //set to 1 to set as currently tuned so we don't keep tuning nonstop opts->p25_is_tuned = 1; //set to 1 to set as currently tuned so we don't keep tuning nonstop
}
//rtl_udp
else if (opts->audio_in_type == 3)
{
rtl_udp_tune (opts, state, freq);
state->p25_vc_freq[0] = state->p25_vc_freq[1] = freq;
opts->p25_is_tuned = 1;
}
//set rid and tg when we actually tune to it //set rid and tg when we actually tune to it
state->nxdn_last_rid = SourceUnitID & 0xFFFF; state->nxdn_last_rid = SourceUnitID & 0xFFFF;
state->nxdn_last_tg = (DestinationID & 0xFFFF); state->nxdn_last_tg = (DestinationID & 0xFFFF);
sprintf (state->nxdn_call_type, "%s", NXDN_Call_Type_To_Str(CallType)); sprintf (state->nxdn_call_type, "%s", NXDN_Call_Type_To_Str(CallType));
} }
//rtl_udp
else if (opts->audio_in_type == 3)
{
//extra safeguards due to sync issues with NXDN
memset (state->nxdn_sacch_frame_segment, 1, sizeof(state->nxdn_sacch_frame_segment));
memset (state->nxdn_sacch_frame_segcrc, 1, sizeof(state->nxdn_sacch_frame_segcrc));
state->lastsynctype = -1;
state->last_cc_sync_time = time(NULL);
state->last_vc_sync_time = time(NULL);
//
rtl_udp_tune (opts, state, freq);
state->p25_vc_freq[0] = state->p25_vc_freq[1] = freq;
opts->p25_is_tuned = 1;
//set rid and tg when we actually tune to it
state->nxdn_last_rid = SourceUnitID & 0xFFFF;
state->nxdn_last_tg = (DestinationID & 0xFFFF);
sprintf (state->nxdn_call_type, "%s", NXDN_Call_Type_To_Str(CallType));
}
}
} }
fprintf (stderr, "%s", KNRM); fprintf (stderr, "%s", KNRM);
@@ -639,6 +667,18 @@ void NXDN_decode_VCALL(dsd_opts * opts, dsd_state * state, uint8_t * Message)
fprintf(stderr, "Src=%u - Dst/TG=%u ", SourceUnitID & 0xFFFF, DestinationID & 0xFFFF); fprintf(stderr, "Src=%u - Dst/TG=%u ", SourceUnitID & 0xFFFF, DestinationID & 0xFFFF);
fprintf (stderr, "%s", KNRM); fprintf (stderr, "%s", KNRM);
//check the rkey array for a scrambler key value
//check by keyid first, then by tgt id
//TGT ID and Key ID could clash though if csv or system has both with different keys
// if (state->rkey_array[KeyID] != 0) state->R = state->rkey_array[KeyID];
if (state->rkey_array[DestinationID] != 0) state->R = state->rkey_array[DestinationID];
if (state->M == 1)
{
state->nxdn_cipher_type = 0x1;
CipherType = 0x1;
}
/* Print the "Cipher Type" */ /* Print the "Cipher Type" */
if(CipherType != 0) if(CipherType != 0)
{ {
@@ -653,6 +693,7 @@ void NXDN_decode_VCALL(dsd_opts * opts, dsd_state * state, uint8_t * Message)
fprintf (stderr, "%s", KNRM); fprintf (stderr, "%s", KNRM);
} }
if (state->nxdn_cipher_type == 0x01 && state->R > 0) //scrambler key value if (state->nxdn_cipher_type == 0x01 && state->R > 0) //scrambler key value
{ {
fprintf (stderr, "%s", KYEL); fprintf (stderr, "%s", KYEL);
@@ -663,7 +704,7 @@ void NXDN_decode_VCALL(dsd_opts * opts, dsd_state * state, uint8_t * Message)
//only grab if CRC is okay //only grab if CRC is okay
if(state->NxdnElementsContent.VCallCrcIsGood) if(state->NxdnElementsContent.VCallCrcIsGood)
{ {
if ( (SourceUnitID & 0xFFFF) > 0 ) if ( (SourceUnitID & 0xFFFF) > 0 ) //
{ {
state->nxdn_last_rid = SourceUnitID & 0xFFFF; state->nxdn_last_rid = SourceUnitID & 0xFFFF;
state->nxdn_last_tg = (DestinationID & 0xFFFF); state->nxdn_last_tg = (DestinationID & 0xFFFF);

View File

@@ -86,6 +86,15 @@ void nxdn_frame (dsd_opts * opts, dsd_state * state)
facch2 = 0; facch2 = 0;
sacch = 0; sacch = 0;
cac = 0; cac = 0;
//test for inbound direction lich when trunking (false positive) and skip
//all inbound lich are even value (lsb is set to 0 for inbound direction)
if (lich % 2 == 0 && opts->p25_trunk == 1)
{
if (opts->payload == 1) fprintf(stderr, " Simplex/Inbound NXDN lich on trunking system - type 0x%02X\n", lich);
goto END;
}
switch(lich) { //cases without breaks continue to flow downwards until they hit the break switch(lich) { //cases without breaks continue to flow downwards until they hit the break
case 0x01: // CAC types case 0x01: // CAC types
case 0x05: case 0x05:
@@ -151,7 +160,7 @@ void nxdn_frame (dsd_opts * opts, dsd_state * state)
default: default:
if (opts->payload == 1) fprintf(stderr, " false sync or unsupported NXDN lich type 0x%02X\n", lich); if (opts->payload == 1) fprintf(stderr, " false sync or unsupported NXDN lich type 0x%02X\n", lich);
//reset the sacch field, we probably got a false sync and need to wipe or give a bad crc //reset the sacch field, we probably got a false sync and need to wipe or give a bad crc
memset (state->nxdn_sacch_frame_segment, 0, sizeof(state->nxdn_sacch_frame_segment)); memset (state->nxdn_sacch_frame_segment, 1, sizeof(state->nxdn_sacch_frame_segment));
memset (state->nxdn_sacch_frame_segcrc, 1, sizeof(state->nxdn_sacch_frame_segcrc)); memset (state->nxdn_sacch_frame_segcrc, 1, sizeof(state->nxdn_sacch_frame_segcrc));
state->lastsynctype = -1; //set to -1 so we don't jump back here too quickly state->lastsynctype = -1; //set to -1 so we don't jump back here too quickly
voice = 0; voice = 0;
@@ -241,13 +250,38 @@ void nxdn_frame (dsd_opts * opts, dsd_state * state)
} }
state->nxdn_sacch_non_superframe = (lich == 0x20 || lich == 0x21 || lich == 0x61 || lich == 0x40 || lich == 0x41) ? true : false; if (lich == 0x20 || lich == 0x21 || lich == 0x61 || lich == 0x40 || lich == 0x41) state->nxdn_sacch_non_superframe = TRUE;
else state->nxdn_sacch_non_superframe = FALSE;
if (sacch)nxdn_deperm_sacch(opts, state, sacch_bits); if (sacch)nxdn_deperm_sacch(opts, state, sacch_bits);
if (cac) nxdn_deperm_cac(opts, state, cac_bits); if (cac) nxdn_deperm_cac(opts, state, cac_bits);
if (facch2) nxdn_deperm_facch2_udch(opts, state, facch2_bits); if (facch2) nxdn_deperm_facch2_udch(opts, state, facch2_bits);
if (facch & 1) nxdn_deperm_facch(opts, state, facch_bits_a); if (facch & 1) nxdn_deperm_facch(opts, state, facch_bits_a);
if (facch & 2) nxdn_deperm_facch(opts, state, facch_bits_b); if (facch & 2) nxdn_deperm_facch(opts, state, facch_bits_b);
if (voice) nxdn_voice (opts, state, voice, dbuf); if (voice)
{
//restore MBE file open here
if ((opts->mbe_out_dir[0] != 0) && (opts->mbe_out_f == NULL)) openMbeOutFile (opts, state);
//update last voice sync time
state->last_vc_sync_time = time(NULL);
//process voice frame
nxdn_voice (opts, state, voice, dbuf);
}
//close MBE file if no voice and its open
if (!voice)
{
if (opts->mbe_out_f != NULL)
{
if (opts->frame_nxdn96 == 1) //nxdn96 has voice and data mixed together, so we will need to do a time check first
{
if ( (time(NULL) - state->last_vc_sync_time) > 1) //test for optimal time, 1 sec should be okay
{
closeMbeOutFile (opts, state);
}
}
if (opts->frame_nxdn48 == 1) closeMbeOutFile (opts, state); //okay to close right away if nxdn48, no data/voice mixing
}
}
fprintf (stderr, "\n"); fprintf (stderr, "\n");
END: ; //do nothing END: ; //do nothing

View File

@@ -40,7 +40,8 @@ static int find_min(uint8_t list[], int len) {
index = i; index = i;
unique = 1; unique = 1;
} else if (list[i] == min) { } else if (list[i] == min) {
unique = 0; //unique = 0;
; //do nothing, still can be correct and pass CRC
} }
} }
/* return -1 if a minimum can't be found */ /* return -1 if a minimum can't be found */

View File

@@ -7,6 +7,73 @@
*-----------------------------------------------------------------------------*/ *-----------------------------------------------------------------------------*/
#include "dsd.h" #include "dsd.h"
int block_convolution (int payload[196], uint8_t decoded[12])
{
int ec = -1; //initialize error value
uint8_t deinterleaved_bits[196];
uint8_t trellis_bytes[12];
uint8_t m_data[14];
uint8_t temp[210]; //temp bit position buffer for convolution
//initialize our deinterleaved bits and bytes with zeroes
for (int i = 0; i < 196; i++) deinterleaved_bits[i] = 0;
for (int i = 0; i < 210; i++) temp[i] = 0;
for (int i = 0; i < 12; i++) trellis_bytes[i] = 0;
for (int i = 0; i < 14; i++) m_data[i] = 0;
//convolution decoder
uint8_t s0;
uint8_t s1;
//initialize our decoded byte buffer with zeroes
for (int i = 0; i < 12; i++) decoded[i] = 0;
static const uint16_t deinterleave_tsbk[] = {
0, 1, 2, 3, 52, 53, 54, 55, 100,101,102,103, 148,149,150,151,
4, 5, 6, 7, 56, 57, 58, 59, 104,105,106,107, 152,153,154,155,
8, 9, 10, 11, 60, 61, 62, 63, 108,109,110,111, 156,157,158,159,
12, 13, 14, 15, 64, 65, 66, 67, 112,113,114,115, 160,161,162,163,
16, 17, 18, 19, 68, 69, 70, 71, 116,117,118,119, 164,165,166,167,
20, 21, 22, 23, 72, 73, 74, 75, 120,121,122,123, 168,169,170,171,
24, 25, 26, 27, 76, 77, 78, 79, 124,125,126,127, 172,173,174,175,
28, 29, 30, 31, 80, 81, 82, 83, 128,129,130,131, 176,177,178,179,
32, 33, 34, 35, 84, 85, 86, 87, 132,133,134,135, 180,181,182,183,
36, 37, 38, 39, 88, 89, 90, 91, 136,137,138,139, 184,185,186,187,
40, 41, 42, 43, 92, 93, 94, 95, 140,141,142,143, 188,189,190,191,
44, 45, 46, 47, 96, 97, 98, 99, 144,145,146,147, 192,193,194,195,
48, 49, 50, 51 };
//get the deinterleaved bits
for (int i = 0; i < 196; i++) deinterleaved_bits[deinterleave_tsbk[i]] = payload[i];
//shift into proper position for the convolutional decoder
for (int i = 0; i < 196; i++) temp[i] = deinterleaved_bits[i] << 1;
CNXDNConvolution_start();
for (int i = 0U; i < 98U; i++) //102U
{
s0 = temp[(2*i)];
s1 = temp[(2*i)+1];
CNXDNConvolution_decode(s0, s1);
}
CNXDNConvolution_chainback(m_data, 96U); //98U
//debug print
fprintf (stderr, "\n Convolution Chainback - ");
for (int i = 0; i < 14; i++) fprintf (stderr, "[%02X]", m_data[i]);
//transfer m_data to decoded bytes -- when sorted out, can probably send decoded straight to chainback, and save the code
// for (int i = 0; i < 12; i++) decoded[i] = m_data[i];
ec = 0; //unknown if a method exists to returns errors from the convolutional decoder, just rely on CRC check for now
return ec;
}
void processTSBK(dsd_opts * opts, dsd_state * state) void processTSBK(dsd_opts * opts, dsd_state * state)
{ {
@@ -54,6 +121,9 @@ void processTSBK(dsd_opts * opts, dsd_state * state)
} }
//test with the nxdn convolutional decoder
// ec = block_convolution (tsbkbit, tsbk_byte);
//send tsbkbit to block_deinterleave and return tsbk_byte //send tsbkbit to block_deinterleave and return tsbk_byte
ec = bd_bridge(tsbkbit, tsbk_byte); ec = bd_bridge(tsbkbit, tsbk_byte);
@@ -84,7 +154,7 @@ void processTSBK(dsd_opts * opts, dsd_state * state)
tsbk_byte[i] = byte; tsbk_byte[i] = byte;
} }
//convert tsbk_byte to PDU and send to vPDU handler //convert tsbk_byte to vPDU and send to vPDU handler
//...may or may not be entirely compatible, //...may or may not be entirely compatible,
MFID = tsbk_byte[1]; MFID = tsbk_byte[1];
PDU[0] = 0x07; //P25p1 TSBK Duid 0x07 PDU[0] = 0x07; //P25p1 TSBK Duid 0x07
@@ -106,8 +176,9 @@ void processTSBK(dsd_opts * opts, dsd_state * state)
protectbit = (tsbk_byte[0] >> 6) & 0x1; protectbit = (tsbk_byte[0] >> 6) & 0x1;
//Don't run NET_STS out of this, or will set wrong NAC/CC //&& PDU[1] != 0x49 && PDU[1] != 0x45 //Don't run NET_STS out of this, or will set wrong NAC/CC //&& PDU[1] != 0x49 && PDU[1] != 0x45
//0x49 is telephone grant, 0x46 Unit to Unit Channel Answer Request (seems bogus) //0x49 is telephone grant, 0x46 Unit to Unit Channel Answer Request (seems bogus) (mfid 90)
if (MFID < 0x2 && protectbit == 0 && err == 0 && ec == 0 && PDU[1] != 0x7B ) // if (MFID < 0x2 && protectbit == 0 && err == 0 && ec == 0 && PDU[1] != 0x7B )
if ( (MFID < 0x2 || MFID == 0xA4 || MFID == 0x90) && protectbit == 0 && err == 0 && ec == 0 && PDU[1] != 0x7B )
{ {
fprintf (stderr, "%s",KYEL); fprintf (stderr, "%s",KYEL);
process_MAC_VPDU(opts, state, 0, PDU); process_MAC_VPDU(opts, state, 0, PDU);
@@ -115,7 +186,7 @@ void processTSBK(dsd_opts * opts, dsd_state * state)
} }
//set our WACN and SYSID here now that we have valid ec and crc/checksum //set our WACN and SYSID here now that we have valid ec and crc/checksum
if (protectbit == 0 && err == 0 && ec == 0 && (tsbk_byte[0] & 0x3F) == 0x3B) else if (protectbit == 0 && err == 0 && ec == 0 && (tsbk_byte[0] & 0x3F) == 0x3B)
{ {
long int wacn = (tsbk_byte[3] << 12) | (tsbk_byte[4] << 4) | (tsbk_byte[5] >> 4);; long int wacn = (tsbk_byte[3] << 12) | (tsbk_byte[4] << 4) | (tsbk_byte[5] >> 4);;
int sysid = ((tsbk_byte[5] & 0xF) << 8) | tsbk_byte[6]; int sysid = ((tsbk_byte[5] & 0xF) << 8) | tsbk_byte[6];
@@ -143,16 +214,43 @@ void processTSBK(dsd_opts * opts, dsd_state * state)
if (opts->payload == 1) if (opts->payload == 1)
{ {
fprintf (stderr, "%s",KCYN); fprintf (stderr, "%s",KCYN);
fprintf (stderr, "\n P25 PDU Payload "); fprintf (stderr, "\n P25 PDU Payload #%d ", j);
for (i = 0; i < 12; i++) for (i = 0; i < 12; i++)
{ {
fprintf (stderr, "[%02X]", tsbk_byte[i]); fprintf (stderr, "[%02X]", tsbk_byte[i]);
} }
} }
fprintf (stderr, "%s ", KNRM); fprintf (stderr, "%s ", KNRM);
} }
else
{
if (opts->payload == 1)
{
fprintf (stderr, "%s",KCYN);
fprintf (stderr, "\n P25 PDU Payload #%d ", j+1);
for (i = 0; i < 12; i++)
{
fprintf (stderr, "[%02X]", tsbk_byte[i]);
}
fprintf (stderr, "\n MFID %02X Protected: %d Last Block: %d", MFID, protectbit, (tsbk_byte[0] >> 7) );
if (ec != 0)
{
fprintf (stderr, "%s",KRED);
fprintf (stderr, " (FEC ERR)");
}
else if (err != 0)
{
fprintf (stderr, "%s",KRED);
fprintf (stderr, " (CRC ERR)");
}
fprintf (stderr, "%s ", KNRM);
}
}
//reset for next rep //reset for next rep
ec = -2; ec = -2;
err = -2; err = -2;
@@ -165,5 +263,7 @@ void processTSBK(dsd_opts * opts, dsd_state * state)
j = 4; //set j to break the loop early j = 4; //set j to break the loop early
} }
} }
fprintf (stderr, "%s ", KNRM);
fprintf (stderr, "\n"); fprintf (stderr, "\n");
} }

View File

@@ -76,7 +76,7 @@ int vc_counter = 0;
int framing_counter = 0; int framing_counter = 0;
unsigned long long int isch = 0; unsigned long long int isch = 0;
unsigned long long int isch_decoded = 0; int isch_decoded = -1;
int p2_duid[8] = {0}; int p2_duid[8] = {0};
int16_t duid_decoded = 0; int16_t duid_decoded = 0;
@@ -369,7 +369,7 @@ void process_ISCH (dsd_opts * opts, dsd_state * state)
{ {
isch_decoded = isch_lookup(isch); isch_decoded = isch_lookup(isch);
if (isch_decoded > 0) if (isch_decoded > -1)
{ {
int uf_count = isch_decoded & 0x3; int uf_count = isch_decoded & 0x3;
int free = (isch_decoded >> 2) & 0x1; int free = (isch_decoded >> 2) & 0x1;
@@ -411,6 +411,7 @@ void process_ISCH (dsd_opts * opts, dsd_state * state)
} }
isch_decoded = -1; //reset to bad value after running
} }
@@ -693,10 +694,20 @@ void process_P2_DUID (dsd_opts * opts, dsd_state * state)
if (state->currentslot == 0 && duid_decoded != 3 && duid_decoded != 12) if (state->currentslot == 0 && duid_decoded != 3 && duid_decoded != 12)
{ {
fprintf (stderr, "VCH 0 "); fprintf (stderr, "VCH 0 ");
//open MBEout file - slot 1 - USE WITH CAUTION on Phase 2! Consider using a symbol capture bin instead!
if (duid_decoded == 0 || duid_decoded == 6) //4V or 2V (voice)
{
if ((opts->mbe_out_dir[0] != 0) && (opts->mbe_out_f == NULL)) openMbeOutFile (opts, state);
}
} }
else if (state->currentslot == 1 && duid_decoded != 3 && duid_decoded != 12) else if (state->currentslot == 1 && duid_decoded != 3 && duid_decoded != 12)
{ {
fprintf (stderr, "VCH 1 "); fprintf (stderr, "VCH 1 ");
//open MBEout file - slot 2 - USE WITH CAUTION on Phase 2! Consider using a symbol capture bin instead!
if (duid_decoded == 0 || duid_decoded == 6) //4V or 2V (voice)
{
if ((opts->mbe_out_dir[0] != 0) && (opts->mbe_out_fR == NULL)) openMbeOutFileR (opts, state);
}
} }
else fprintf (stderr, "VCH S "); else fprintf (stderr, "VCH S ");
@@ -836,5 +847,15 @@ void processP2 (dsd_opts * opts, dsd_state * state)
process_P2_DUID (opts, state); process_P2_DUID (opts, state);
state->dmr_stereo = 0; state->dmr_stereo = 0;
state->p2_is_lcch = 0; state->p2_is_lcch = 0;
//bugfix for OSS dmrbust 16 shim, reset both to 0 upon exit
//in case or marginal signal and both get stuck on 16, indefinitely muting the non-preferred slot
//but...this can also cause at least one 4v/2v to get through on the other slot if the sync lines up that way
if (opts->audio_out_type == 5)
{
//set both to blank value
state->dmrburstL = 17;
state->dmrburstR = 17;
}
fprintf (stderr, "\n"); fprintf (stderr, "\n");
} }

View File

@@ -915,6 +915,9 @@ void process_MAC_VPDU(dsd_opts * opts, dsd_state * state, int type, unsigned lon
fprintf (stderr, "\n RFSS Status Broadcast - Implicit \n"); fprintf (stderr, "\n RFSS Status Broadcast - Implicit \n");
fprintf (stderr, " LRA [%02X] SYSID [%03X] RFSS ID [%02X] SITE ID [%02X] CHAN [%04X] SSC [%02X] ", lra, lsysid, rfssid, siteid, channel, sysclass); fprintf (stderr, " LRA [%02X] SYSID [%03X] RFSS ID [%02X] SITE ID [%02X] CHAN [%04X] SSC [%02X] ", lra, lsysid, rfssid, siteid, channel, sysclass);
process_channel_to_freq (opts, state, channel); process_channel_to_freq (opts, state, channel);
state->p2_siteid = siteid;
state->p2_rfssid = rfssid;
} }
//RFSS Status Broadcast - Explicit //RFSS Status Broadcast - Explicit
@@ -931,10 +934,13 @@ void process_MAC_VPDU(dsd_opts * opts, dsd_state * state, int type, unsigned lon
fprintf (stderr, " LRA [%02X] SYSID [%03X] RFSS ID [%02X] SITE ID [%02X]\n CHAN-T [%04X] CHAN-R [%02X] SSC [%02X] ", lra, lsysid, rfssid, siteid, channelt, channelr, sysclass); fprintf (stderr, " LRA [%02X] SYSID [%03X] RFSS ID [%02X] SITE ID [%02X]\n CHAN-T [%04X] CHAN-R [%02X] SSC [%02X] ", lra, lsysid, rfssid, siteid, channelt, channelr, sysclass);
process_channel_to_freq (opts, state, channelt); process_channel_to_freq (opts, state, channelt);
process_channel_to_freq (opts, state, channelr); process_channel_to_freq (opts, state, channelr);
state->p2_siteid = siteid;
state->p2_rfssid = rfssid;
} }
//Unit-to-Unit Answer Request (UU_ANS_REQ) //Unit-to-Unit Answer Request (UU_ANS_REQ)
if (MAC[1+len_a] == 0x45) if (MAC[1+len_a] == 0x45 && MAC[2+len_a] != 0x90)
{ {
int svc = MAC[2+len_a]; int svc = MAC[2+len_a];
int answer = MAC[3+len_a]; int answer = MAC[3+len_a];
@@ -946,17 +952,17 @@ void process_MAC_VPDU(dsd_opts * opts, dsd_state * state, int type, unsigned lon
} }
//Telephone Interconnect Voice Channel Grant (TELE_INT_CH_GRANT) //Telephone Interconnect Voice Channel Grant (TELE_INT_CH_GRANT) //look at PDU for this, see if this is tunable
if (MAC[1+len_a] == 0x48) // if (MAC[1+len_a] == 0x48 && MAC[2+len_a] != 0x90)
{ // {
fprintf (stderr, "\n Telephone Interconnect Voice Channel Grant "); // fprintf (stderr, "\n Telephone Interconnect Voice Channel Grant ");
} // }
//Telephone Interconnect Voice Channel Grant Update (TELE_INT_CH_GRANT_UPDT) // //Telephone Interconnect Voice Channel Grant Update (TELE_INT_CH_GRANT_UPDT)
if (MAC[1+len_a] == 0x49) // if (MAC[1+len_a] == 0x49 && MAC[2+len_a] != 0x90)
{ // {
fprintf (stderr, "\n Telephone Interconnect Voice Channel Grant Update "); // fprintf (stderr, "\n Telephone Interconnect Voice Channel Grant Update ");
} // }
//Synchronization Broadcast (SYNC_BCST) //Synchronization Broadcast (SYNC_BCST)
if (MAC[1+len_a] == 0x70) if (MAC[1+len_a] == 0x70)
@@ -980,12 +986,12 @@ void process_MAC_VPDU(dsd_opts * opts, dsd_state * state, int type, unsigned lon
else offhour = ( (ltoff & 0b11111 ) / 2); else offhour = ( (ltoff & 0b11111 ) / 2);
int seconds = slots / 135; //very rough estimation, but may be close enough for grins int seconds = slots / 135; //very rough estimation, but may be close enough for grins
if (seconds > 60) seconds = 60; //sanity check for rounding error if (seconds > 59) seconds = 59; //sanity check for rounding error
fprintf (stderr, " Date: 20%02d.%02d.%02d Time: %02d:%02d:%02d UTC\n", fprintf (stderr, " Date: 20%02d.%02d.%02d Time: %02d:%02d:%02d UTC\n",
year, month, day, hour, min, seconds); year, month, day, hour, min, seconds);
fprintf (stderr, " Local Time Offset: %.01f Hours;", offhour); fprintf (stderr, " Local Time Offset: %.01f Hours;", offhour);
//if ist bit is set, then time on system may be considered invalid (i.e., no external time sync) //if ist bit is set, then time on system may be considered invalid (i.e., no external time sync)
if (ist % 1) if (ist == 1)
{ {
fprintf (stderr, " Invalid System Time "); fprintf (stderr, " Invalid System Time ");
} }
@@ -1079,6 +1085,9 @@ void process_MAC_VPDU(dsd_opts * opts, dsd_state * state, int type, unsigned lon
process_channel_to_freq (opts, state, channelr); process_channel_to_freq (opts, state, channelr);
} }
state->p2_siteid = siteid;
state->p2_rfssid = rfssid;
} }
//Secondary Control Channel Broadcast, Implicit //Secondary Control Channel Broadcast, Implicit
@@ -1110,6 +1119,9 @@ void process_MAC_VPDU(dsd_opts * opts, dsd_state * state, int type, unsigned lon
state->lcn_freq_count = 3; //increment to three state->lcn_freq_count = 3; //increment to three
} }
state->p2_siteid = siteid;
state->p2_rfssid = rfssid;
} }
//MFID90 Group Regroup Voice Channel User - Abbreviated //MFID90 Group Regroup Voice Channel User - Abbreviated

View File

@@ -202,6 +202,10 @@ void process_SACCH_MAC_PDU (dsd_opts * opts, dsd_state * state, int payload[180]
//print it and then zero out //print it and then zero out
state->lastsrc = 0; state->lastsrc = 0;
state->lasttg = 0; state->lasttg = 0;
//close any open MBEout files
if (opts->mbe_out_f != NULL) closeMbeOutFile (opts, state);
} }
if (state->currentslot == 0) if (state->currentslot == 0)
{ {
@@ -218,6 +222,9 @@ void process_SACCH_MAC_PDU (dsd_opts * opts, dsd_state * state, int payload[180]
//print it and then zero out //print it and then zero out
state->lastsrcR = 0; state->lastsrcR = 0;
state->lasttgR = 0; state->lasttgR = 0;
//close any open MBEout files
if (opts->mbe_out_fR != NULL) closeMbeOutFileR (opts, state);
} }
fprintf (stderr, "%s", KNRM); fprintf (stderr, "%s", KNRM);
} }
@@ -232,8 +239,9 @@ void process_SACCH_MAC_PDU (dsd_opts * opts, dsd_state * state, int payload[180]
} }
if (opcode == 0x4 && err == 0) if (opcode == 0x4 && err == 0)
{ {
if (state->currentslot == 1) state->dmrburstL = 21; //disable to prevent blinking in ncurses terminal due to OSS preemption shim
else state->dmrburstR = 21; //if (state->currentslot == 1) state->dmrburstL = 21;
//else state->dmrburstR = 21;
fprintf (stderr, " MAC_ACTIVE "); fprintf (stderr, " MAC_ACTIVE ");
fprintf (stderr, "%s", KYEL); fprintf (stderr, "%s", KYEL);
process_MAC_VPDU(opts, state, 1, SMAC); process_MAC_VPDU(opts, state, 1, SMAC);
@@ -241,8 +249,18 @@ void process_SACCH_MAC_PDU (dsd_opts * opts, dsd_state * state, int payload[180]
} }
if (opcode == 0x6 && err == 0) if (opcode == 0x6 && err == 0)
{ {
if (state->currentslot == 1) state->dmrburstL = 22; if (state->currentslot == 1)
else state->dmrburstR = 22; {
state->dmrburstL = 21;
//close any open MBEout files
if (opts->mbe_out_f != NULL) closeMbeOutFile (opts, state);
}
else
{
state->dmrburstR = 21;
//close any open MBEout files
if (opts->mbe_out_fR != NULL) closeMbeOutFileR (opts, state);
}
fprintf (stderr, " MAC_HANGTIME "); fprintf (stderr, " MAC_HANGTIME ");
fprintf (stderr, "%s", KYEL); fprintf (stderr, "%s", KYEL);
process_MAC_VPDU(opts, state, 1, SMAC); process_MAC_VPDU(opts, state, 1, SMAC);
@@ -412,6 +430,10 @@ void process_FACCH_MAC_PDU (dsd_opts * opts, dsd_state * state, int payload[156]
//print it and then zero out //print it and then zero out
state->lastsrc = 0; state->lastsrc = 0;
state->lasttg = 0; state->lasttg = 0;
//close any open MBEout files
if (opts->mbe_out_f != NULL) closeMbeOutFile (opts, state);
} }
if (state->currentslot == 1) if (state->currentslot == 1)
{ {
@@ -428,6 +450,9 @@ void process_FACCH_MAC_PDU (dsd_opts * opts, dsd_state * state, int payload[156]
//print it and then zero out //print it and then zero out
state->lastsrcR = 0; state->lastsrcR = 0;
state->lasttgR = 0; state->lasttgR = 0;
//close any open MBEout files
if (opts->mbe_out_fR != NULL) closeMbeOutFileR (opts, state);
} }
fprintf (stderr, "%s", KNRM); fprintf (stderr, "%s", KNRM);
} }
@@ -462,8 +487,9 @@ void process_FACCH_MAC_PDU (dsd_opts * opts, dsd_state * state, int payload[156]
} }
if (opcode == 0x4 && err == 0) if (opcode == 0x4 && err == 0)
{ {
if (state->currentslot == 0) state->dmrburstL = 21; //disable to prevent blinking in ncurses terminal due to OSS preemption shim
else state->dmrburstR = 21; //if (state->currentslot == 0) state->dmrburstL = 21;
//else state->dmrburstR = 21;
fprintf (stderr, " MAC_ACTIVE "); fprintf (stderr, " MAC_ACTIVE ");
fprintf (stderr, "%s", KYEL); fprintf (stderr, "%s", KYEL);
process_MAC_VPDU(opts, state, 0, FMAC); process_MAC_VPDU(opts, state, 0, FMAC);
@@ -471,8 +497,18 @@ void process_FACCH_MAC_PDU (dsd_opts * opts, dsd_state * state, int payload[156]
} }
if (opcode == 0x6 && err == 0) if (opcode == 0x6 && err == 0)
{ {
if (state->currentslot == 0) state->dmrburstL = 22; if (state->currentslot == 0)
else state->dmrburstR = 22; {
state->dmrburstL = 22;
//close any open MBEout files
if (opts->mbe_out_f != NULL) closeMbeOutFile (opts, state);
}
else
{
state->dmrburstR = 22;
//close any open MBEout files
if (opts->mbe_out_fR != NULL) closeMbeOutFileR (opts, state);
}
fprintf (stderr, " MAC_HANGTIME "); fprintf (stderr, " MAC_HANGTIME ");
fprintf (stderr, "%s", KYEL); fprintf (stderr, "%s", KYEL);
process_MAC_VPDU(opts, state, 0, FMAC); process_MAC_VPDU(opts, state, 0, FMAC);

View File

@@ -33,11 +33,11 @@ processProVoice (dsd_opts * opts, dsd_state * state)
#ifdef PROVOICE_DUMP #ifdef PROVOICE_DUMP
fprintf (stderr," "); fprintf (stderr," ");
#endif #endif
//init Bits (64)...MI? //iNitial 64 bits
if (opts->payload == 1) if (opts->payload == 1)
{ {
k = 0; k = 0;
//fprintf (stderr, "\nInit 64 "); fprintf (stderr, "\n N64: ");
for(i = 0; i < 8; i++) for(i = 0; i < 8; i++)
{ {
initbyte[i] = 0; initbyte[i] = 0;
@@ -47,9 +47,10 @@ processProVoice (dsd_opts * opts, dsd_state * state)
initbyte[i] = initbyte[i] | init[k]; initbyte[i] = initbyte[i] | init[k];
k++; k++;
} }
//fprintf (stderr, "%02X", initbyte[i]); fprintf (stderr, "%02X", initbyte[i]);
if (i == 3) fprintf (stderr, "-");
} }
//fprintf (stderr, "\n"); fprintf (stderr, "\n");
} }
// lid // lid
for (i = 0; i < 16; i++) for (i = 0; i < 16; i++)
@@ -79,7 +80,7 @@ processProVoice (dsd_opts * opts, dsd_state * state)
if (opts->payload == 1) if (opts->payload == 1)
{ {
k = 0; k = 0;
//fprintf (stderr, "LID "); fprintf (stderr, " LID: ");
for(i = 0; i < 10; i++) for(i = 0; i < 10; i++)
{ {
lidbyte[i] = 0; lidbyte[i] = 0;
@@ -89,7 +90,8 @@ processProVoice (dsd_opts * opts, dsd_state * state)
lidbyte[i] = lidbyte[i] | lid[k]; lidbyte[i] = lidbyte[i] | lid[k];
k++; k++;
} }
//fprintf (stderr, "%02X", lidbyte[i]); fprintf (stderr, "%02X", lidbyte[i]);
if (i == 3 || i == 7) fprintf (stderr, "-");
} }
// fprintf (stderr, "\n"); // fprintf (stderr, "\n");
} }
@@ -337,7 +339,7 @@ processProVoice (dsd_opts * opts, dsd_state * state)
if (opts->payload == 1) if (opts->payload == 1)
{ {
k = 0; k = 0;
//fprintf (stderr, "16 bits? "); fprintf (stderr, "\n 16B: ");
for(i = 0; i < 2; i++) for(i = 0; i < 2; i++)
{ {
initbyte[i] = 0; initbyte[i] = 0;
@@ -347,7 +349,7 @@ if (opts->payload == 1)
initbyte[i] = initbyte[i] | init[k]; initbyte[i] = initbyte[i] | init[k];
k++; k++;
} }
//fprintf (stderr, "%02X", initbyte[i]); fprintf (stderr, "%02X", initbyte[i]);
} }
// fprintf (stderr, "\n"); // fprintf (stderr, "\n");
} }