mirror of
https://github.com/lwvmobile/dsd-fme.git
synced 2026-11-13 17:27:21 -05:00
Compare commits
987 Commits
win32-rc5
...
audio_work
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
34753963b8 | ||
|
|
544d576551 | ||
|
|
72f8c1aff7 | ||
|
|
bfa4891965 | ||
|
|
daa47069bf | ||
|
|
587181f4de | ||
|
|
eb8048f1d9 | ||
|
|
d8f9bd190b | ||
|
|
6880087afe | ||
|
|
6106a608e3 | ||
|
|
1aae6d34c9 | ||
|
|
be57b5149b | ||
|
|
3e221f29f5 | ||
|
|
4754f6a59b | ||
|
|
7027b145b8 | ||
|
|
f38b5976f3 | ||
|
|
5244c85774 | ||
|
|
4005c9b313 | ||
|
|
72b3e5efe4 | ||
|
|
a3a6fb999a | ||
|
|
37855b817b | ||
|
|
4fe32db7f5 | ||
|
|
6819f9010e | ||
|
|
719d9709e6 | ||
|
|
26e4a619f6 | ||
|
|
0838a7f7ba | ||
|
|
a6ea60b345 | ||
|
|
9232d66fcb | ||
|
|
15515158b5 | ||
|
|
fa4a332582 | ||
|
|
4139b19bfe | ||
|
|
cd5f0f4a8e | ||
|
|
fb3dc75c47 | ||
|
|
f2254f413a | ||
|
|
c97400a704 | ||
|
|
cc6711fe4d | ||
|
|
198f0eacb5 | ||
|
|
5e5c3c4555 | ||
|
|
272f17bfa3 | ||
|
|
69d31151dd | ||
|
|
6fd7176659 | ||
|
|
c960f9932c | ||
|
|
e877e7b9de | ||
|
|
43d63b20dc | ||
|
|
e6d2dd7934 | ||
|
|
8c3ae61b1a | ||
|
|
f443063d3b | ||
|
|
ed1d1d630c | ||
|
|
56f6f6d78e | ||
|
|
a6bdfa913f | ||
|
|
ad77f266c4 | ||
|
|
f72eb31b30 | ||
|
|
441ba31d1b | ||
|
|
7d94abd76a | ||
|
|
7b89174bb1 | ||
|
|
f6f5f80361 | ||
|
|
b7cd501cc1 | ||
|
|
9f03ad123d | ||
|
|
d3303aea28 | ||
|
|
615f67536f | ||
|
|
12012a9eee | ||
|
|
53a256bee8 | ||
|
|
d7ce5e4cae | ||
|
|
5af38d3563 | ||
|
|
034855069a | ||
|
|
3ee5acef0a | ||
|
|
b5bd9a7238 | ||
|
|
56b491ed3e | ||
|
|
a26a680fd6 | ||
|
|
4ec2387140 | ||
|
|
385a9a1747 | ||
|
|
2267f5d007 | ||
|
|
99f422898a | ||
|
|
4924bd249a | ||
|
|
a5e000a14c | ||
|
|
53eaccc892 | ||
|
|
e95cd4dd3a | ||
|
|
48b0c4025b | ||
|
|
2171df515d | ||
|
|
83d7460a0b | ||
|
|
38ad11dbef | ||
|
|
eddd6cb8b1 | ||
|
|
abf28593b1 | ||
|
|
bc4aeff164 | ||
|
|
632041a44a | ||
|
|
f1cd83e924 | ||
|
|
50bf004427 | ||
|
|
85a6372c2e | ||
|
|
eb76ea2039 | ||
|
|
14edf325bc | ||
|
|
e11ed353b8 | ||
|
|
f8521fda99 | ||
|
|
fa47d0321b | ||
|
|
095d982b62 | ||
|
|
0060378321 | ||
|
|
8ea6415424 | ||
|
|
eb24239c51 | ||
|
|
ac1c658870 | ||
|
|
cf032ab955 | ||
|
|
2d04878506 | ||
|
|
748bb5b191 | ||
|
|
f3b89f1c51 | ||
|
|
b2d388a210 | ||
|
|
c883e2bf0b | ||
|
|
f8ca0a8e08 | ||
|
|
99b1fd2fe2 | ||
|
|
b0a46a541d | ||
|
|
3aabd85604 | ||
|
|
9acd8c981e | ||
|
|
9353c489aa | ||
|
|
bc95dc1a1d | ||
|
|
1ecd32e017 | ||
|
|
6ef823347b | ||
|
|
bd75c1ab83 | ||
|
|
b3b943d330 | ||
|
|
a5151686ec | ||
|
|
24c1dd97df | ||
|
|
6f171620dc | ||
|
|
7428a87d80 | ||
|
|
79084f26c6 | ||
|
|
d5cd4b4273 | ||
|
|
bafd74b225 | ||
|
|
8df8ce85f2 | ||
|
|
a5b9984d78 | ||
|
|
4dd68f2221 | ||
|
|
21c02acd8c | ||
|
|
c7b25c60af | ||
|
|
41865f3af7 | ||
|
|
8f092e293f | ||
|
|
c888dfc1d6 | ||
|
|
6ebe3eff58 | ||
|
|
2ca3f0a356 | ||
|
|
698a991262 | ||
|
|
352bb98bc6 | ||
|
|
8c34313720 | ||
|
|
ce805a7860 | ||
|
|
86b8900b3d | ||
|
|
eb1bcee301 | ||
|
|
fd3b4b6a66 | ||
|
|
b09de5f112 | ||
|
|
8d1c92c490 | ||
|
|
bd98e3befb | ||
|
|
1aa71811b0 | ||
|
|
4e1b1ac98e | ||
|
|
ccbaef8541 | ||
|
|
8a30115398 | ||
|
|
3a1d393a0f | ||
|
|
66844b1d4c | ||
|
|
722d7b77fb | ||
|
|
5a2575c9a0 | ||
|
|
daad012466 | ||
|
|
f2cc686189 | ||
|
|
175ccff7e9 | ||
|
|
4a1e6f1540 | ||
|
|
d285865de5 | ||
|
|
4bcc9f8aec | ||
|
|
c6b2320cbd | ||
|
|
87be5aa72e | ||
|
|
3f0f675fd5 | ||
|
|
7c56fb836b | ||
|
|
2891d7314b | ||
|
|
ed13bb34d8 | ||
|
|
b9097d9462 | ||
|
|
59fcfdae81 | ||
|
|
f85304471f | ||
|
|
3fc67a5694 | ||
|
|
2314900829 | ||
|
|
680b792b19 | ||
|
|
0d734b753f | ||
|
|
fae33ca0a1 | ||
|
|
dc7ff1136e | ||
|
|
67ab05da63 | ||
|
|
54ba3b6513 | ||
|
|
13739b18aa | ||
|
|
7a198e62f9 | ||
|
|
e37955448e | ||
|
|
2dc9db17ab | ||
|
|
a3eb6dd552 | ||
|
|
35b782a10f | ||
|
|
8c4dc6ed36 | ||
|
|
1532fdcc8e | ||
|
|
68d959cb7a | ||
|
|
c364117fc0 | ||
|
|
d376fcc227 | ||
|
|
93b297c2d5 | ||
|
|
d158db618d | ||
|
|
934b95cde8 | ||
|
|
3563399126 | ||
|
|
6364009e45 | ||
|
|
1739017303 | ||
|
|
27d416f38b | ||
|
|
f9dac1c226 | ||
|
|
d1334038df | ||
|
|
4ebc6ab6c9 | ||
|
|
76905b095b | ||
|
|
daf014df6a | ||
|
|
ff4dd03379 | ||
|
|
114e305e25 | ||
|
|
4e04d99780 | ||
|
|
a9a88c5b13 | ||
|
|
71d4d30f3a | ||
|
|
8cbfb96141 | ||
|
|
919100daad | ||
|
|
d2f4c1ddd9 | ||
|
|
cb89fb69c1 | ||
|
|
51727b815d | ||
|
|
8bfdeeebd0 | ||
|
|
b963b08469 | ||
|
|
177551e081 | ||
|
|
7ab5ec8b40 | ||
|
|
8fd9c64c0c | ||
|
|
a9af3b9380 | ||
|
|
fc21063652 | ||
|
|
19864225f6 | ||
|
|
3312e14422 | ||
|
|
425d477168 | ||
|
|
b351b6a20d | ||
|
|
4b75211ad0 | ||
|
|
88c76c4a6c | ||
|
|
cfbd859d9e | ||
|
|
5851abbce8 | ||
|
|
d35bed4348 | ||
|
|
4e77bb05b9 | ||
|
|
fdbc2ef0e2 | ||
|
|
237cb3ffa5 | ||
|
|
7ed1a79b5b | ||
|
|
e36672f54c | ||
|
|
eac360571e | ||
|
|
9f59729fb1 | ||
|
|
9f063cb4da | ||
|
|
f593453328 | ||
|
|
871bdf5a82 | ||
|
|
fbf40335aa | ||
|
|
0c8a11c607 | ||
|
|
c13ffbc9b2 | ||
|
|
31f9edefa5 | ||
|
|
fe0195ad10 | ||
|
|
e3e2fff6e5 | ||
|
|
3b67ff52d5 | ||
|
|
17789f03f9 | ||
|
|
6fb464f57d | ||
|
|
6c277da869 | ||
|
|
4d5af32ce7 | ||
|
|
16a84b8d3e | ||
|
|
eebb251d2f | ||
|
|
4255a2f9ba | ||
|
|
5fcfb141a6 | ||
|
|
304baca7c5 | ||
|
|
fb2de46d88 | ||
|
|
f551952bf6 | ||
|
|
ec8d74fabd | ||
|
|
f732ad9639 | ||
|
|
31bfd6a235 | ||
|
|
a44c81a6bb | ||
|
|
df56d421f8 | ||
|
|
f5fad8d5e0 | ||
|
|
f92c64c4d3 | ||
|
|
2ca15d8b53 | ||
|
|
bc18db2bc2 | ||
|
|
a006074459 | ||
|
|
141eac9bc3 | ||
|
|
69dd1d167b | ||
|
|
f6aba4a5a4 | ||
|
|
f0b5f2737f | ||
|
|
5c177d671c | ||
|
|
1d112a21cc | ||
|
|
13bbf08e6c | ||
|
|
7c180113cd | ||
|
|
2ba4641796 | ||
|
|
d11de2cbac | ||
|
|
1725e45793 | ||
|
|
035df461e1 | ||
|
|
f6f5380df4 | ||
|
|
d8df5ceab5 | ||
|
|
dfe744ef13 | ||
|
|
2fbdf46fd6 | ||
|
|
2c100dd121 | ||
|
|
42cb14b9d9 | ||
|
|
c5cded87b1 | ||
|
|
b2ee4e1df0 | ||
|
|
db73166da7 | ||
|
|
8d21574a93 | ||
|
|
35bd5ccc55 | ||
|
|
6dd1410faf | ||
|
|
0cbf42e4e6 | ||
|
|
f0657ee5a8 | ||
|
|
29ee3a5f3a | ||
|
|
8cfaced4b4 | ||
|
|
61673222db | ||
|
|
f59f0cbb7f | ||
|
|
20af28597d | ||
|
|
942d83f54d | ||
|
|
0c6f132520 | ||
|
|
6319508937 | ||
|
|
ae6525e986 | ||
|
|
51d1690edc | ||
|
|
14d00f9228 | ||
|
|
5ad9f4107c | ||
|
|
6afa4ed327 | ||
|
|
bc140ec081 | ||
|
|
d904289060 | ||
|
|
e13bd4f323 | ||
|
|
5752f1b84a | ||
|
|
5e516ed6d1 | ||
|
|
2ceeeb82af | ||
|
|
2883e44a9d | ||
|
|
20747db2cc | ||
|
|
c2f22ac399 | ||
|
|
b8beede921 | ||
|
|
cd32158a73 | ||
|
|
a8ec6dbe37 | ||
|
|
f22af7c5fc | ||
|
|
a4b53f88a1 | ||
|
|
4567e2f4a4 | ||
|
|
8a3fd87784 | ||
|
|
c428ce32b2 | ||
|
|
2ae9c50d47 | ||
|
|
dfcc8d513d | ||
|
|
7c9d032c99 | ||
|
|
f6fc91a051 | ||
|
|
8b76daa35f | ||
|
|
8b883f556f | ||
|
|
beefaae0fa | ||
|
|
13e778b123 | ||
|
|
7f7c13a72a | ||
|
|
f2312e63eb | ||
|
|
d6adaa87c7 | ||
|
|
20e35a00ba | ||
|
|
8610ee8956 | ||
|
|
92fbdabbe5 | ||
|
|
25659ba920 | ||
|
|
b2ce60b843 | ||
|
|
c87ad08371 | ||
|
|
94688fddd4 | ||
|
|
e29eba9943 | ||
|
|
920dce96fe | ||
|
|
e2747525a6 | ||
|
|
a5989486ae | ||
|
|
9c58273832 | ||
|
|
9a9fa0c182 | ||
|
|
319d0b9866 | ||
|
|
5dbccaadf6 | ||
|
|
28a6777d83 | ||
|
|
21afa4ba97 | ||
|
|
d60dfa7ff3 | ||
|
|
5d3b2ec56f | ||
|
|
2c55a9caab | ||
|
|
6daedf198f | ||
|
|
8d52ce2ac9 | ||
|
|
63e484cc91 | ||
|
|
e3ecace5db | ||
|
|
f9add0b997 | ||
|
|
d3c942d475 | ||
|
|
3d1e28fb3a | ||
|
|
c07fa3a0bc | ||
|
|
ef94b311fa | ||
|
|
79d5b795e3 | ||
|
|
d0c20be7f3 | ||
|
|
6833275960 | ||
|
|
601a1ad2d1 | ||
|
|
db036f4dfc | ||
|
|
7bcd29abec | ||
|
|
c5b36af672 | ||
|
|
9da8544408 | ||
|
|
ab9a9ddab3 | ||
|
|
ceb695af01 | ||
|
|
1ffddf823f | ||
|
|
499134bc2d | ||
|
|
7a9763c6c7 | ||
|
|
db7bc75739 | ||
|
|
bd1dcd2a7f | ||
|
|
bc205cfe00 | ||
|
|
0f3dcf47ea | ||
|
|
3f165571d2 | ||
|
|
b2450b1924 | ||
|
|
061703db7b | ||
|
|
50f4327306 | ||
|
|
90206eac92 | ||
|
|
f1a5d6f870 | ||
|
|
ca506672a8 | ||
|
|
3041713eb3 | ||
|
|
dbc645e7b0 | ||
|
|
5d205800aa | ||
|
|
e5d11c81f3 | ||
|
|
d86c520509 | ||
|
|
854b421235 | ||
|
|
8206a5f3f4 | ||
|
|
0568475d59 | ||
|
|
b5a43031f9 | ||
|
|
ba41ba57f6 | ||
|
|
d84136dc92 | ||
|
|
ad78373b43 | ||
|
|
8980207fd6 | ||
|
|
33d8ee70d9 | ||
|
|
b86cd1bc3c | ||
|
|
57c22b484d | ||
|
|
834bd57ea6 | ||
|
|
7e26b7b902 | ||
|
|
4eb2e770c8 | ||
|
|
0208f6240c | ||
|
|
db88bfff8d | ||
|
|
a78b88cb90 | ||
|
|
a42dd9db83 | ||
|
|
a7d7cf1c2e | ||
|
|
1ec8bb5c8b | ||
|
|
d8e672f796 | ||
|
|
b577397d22 | ||
|
|
832afa6c5a | ||
|
|
b667d25f2a | ||
|
|
e237b5541b | ||
|
|
bf62106953 | ||
|
|
09b181449f | ||
|
|
c073bc49c1 | ||
|
|
7b2a2031a2 | ||
|
|
a90a2dadd4 | ||
|
|
c21aa98034 | ||
|
|
c967e1500c | ||
|
|
99212cc139 | ||
|
|
caab348a39 | ||
|
|
f799374183 | ||
|
|
1f8a129137 | ||
|
|
ba11725087 | ||
|
|
79f8503c09 | ||
|
|
5c7f285b9d | ||
|
|
b7415e1855 | ||
|
|
3def1f59e5 | ||
|
|
7b8a79b8ea | ||
|
|
9695438fcd | ||
|
|
49cd974dcb | ||
|
|
739d373204 | ||
|
|
896cb83eb2 | ||
|
|
22f1261efa | ||
|
|
4648b9c8eb | ||
|
|
e77770f608 | ||
|
|
bfa2ae8bc4 | ||
|
|
9c13d21f69 | ||
|
|
16ce501582 | ||
|
|
61617db239 | ||
|
|
ac74a9c80e | ||
|
|
c8812db585 | ||
|
|
95aaa8fc2e | ||
|
|
deb9dbed61 | ||
|
|
0feb8dc73c | ||
|
|
6bfbdbd9df | ||
|
|
2160b369bb | ||
|
|
de91defc20 | ||
|
|
3fbff95b2b | ||
|
|
6facababd7 | ||
|
|
dc3dc80d8f | ||
|
|
202fbf3dbc | ||
|
|
f6283f4807 | ||
|
|
1f7ddbecdf | ||
|
|
129af0ba9e | ||
|
|
eed267ed3f | ||
|
|
e195770181 | ||
|
|
cbddea701a | ||
|
|
3eefa3365f | ||
|
|
d22f9ddfe3 | ||
|
|
5c9416313a | ||
|
|
4b063aaf97 | ||
|
|
bbfd4967cf | ||
|
|
c5742350d1 | ||
|
|
753286cdf6 | ||
|
|
22028b37ed | ||
|
|
3483c736ba | ||
|
|
20989c31c8 | ||
|
|
cee797017b | ||
|
|
bceac916fe | ||
|
|
7d8a081e3f | ||
|
|
4bd36ece9a | ||
|
|
b95644d5e5 | ||
|
|
791cc17b27 | ||
|
|
40b1b67b29 | ||
|
|
b8cb4ad521 | ||
|
|
6b50ca034b | ||
|
|
43df9c3ff5 | ||
|
|
dff48692ca | ||
|
|
44a8085463 | ||
|
|
934eb8264e | ||
|
|
dc1bb6a55e | ||
|
|
fe9b5b51e8 | ||
|
|
f35aa046c1 | ||
|
|
a708fa5f6e | ||
|
|
bb78b1bf27 | ||
|
|
931fae62c6 | ||
|
|
c1e657a5e3 | ||
|
|
1e2d42ce23 | ||
|
|
5d367a5c27 | ||
|
|
1d03f7efbf | ||
|
|
5125fd4d6c | ||
|
|
d079035adf | ||
|
|
06bfcdacc2 | ||
|
|
ab844202bc | ||
|
|
f05ddf8fcd | ||
|
|
f36df3ea09 | ||
|
|
df28ebe573 | ||
|
|
3a44affc63 | ||
|
|
19be1db46c | ||
|
|
7101c3588a | ||
|
|
5573244583 | ||
|
|
ad1db34c86 | ||
|
|
379cc25099 | ||
|
|
df6a6ce066 | ||
|
|
27735ccc01 | ||
|
|
d614eb088e | ||
|
|
f1088e9471 | ||
|
|
f6b8cc71cc | ||
|
|
d35144e0e9 | ||
|
|
f7fe1e066c | ||
|
|
18366dd294 | ||
|
|
106d717157 | ||
|
|
296775d231 | ||
|
|
114d8d7dfc | ||
|
|
2392f57d62 | ||
|
|
a0b199d208 | ||
|
|
6c4584a00a | ||
|
|
5d565c55a7 | ||
|
|
fbc902d16e | ||
|
|
051a65f0bb | ||
|
|
ffc311e0e9 | ||
|
|
d738eee5d9 | ||
|
|
58a00106d3 | ||
|
|
d0617714ca | ||
|
|
6ae3316cd1 | ||
|
|
c1577905cd | ||
|
|
d12f6a1191 | ||
|
|
0f5612fdd4 | ||
|
|
a77fa83c80 | ||
|
|
75bc2b7b35 | ||
|
|
ac6284819a | ||
|
|
2e09e5fdfa | ||
|
|
5c09130782 | ||
|
|
677b064e97 | ||
|
|
a30512f4e4 | ||
|
|
e20229208f | ||
|
|
f67bb81de2 | ||
|
|
f98cdfeb0f | ||
|
|
ba264c1557 | ||
|
|
11a08298ff | ||
|
|
72ac2f628b | ||
|
|
dd87bf77f8 | ||
|
|
d730ca2c25 | ||
|
|
0d09baee3c | ||
|
|
7ea26b68e7 | ||
|
|
e7334a6c4f | ||
|
|
404dc772d4 | ||
|
|
7754123e30 | ||
|
|
16b950d5a0 | ||
|
|
0ba3fee968 | ||
|
|
a2113fcdcc | ||
|
|
ec7fbeeb22 | ||
|
|
5f969bf4aa | ||
|
|
8a197aea45 | ||
|
|
c6bc10f1ba | ||
|
|
5830dfa991 | ||
|
|
fc44edb0fc | ||
|
|
cb02c0328c | ||
|
|
71d79ff45b | ||
|
|
c4e2730ced | ||
|
|
65fdd7c5b4 | ||
|
|
42fee3bd3e | ||
|
|
b4d45af268 | ||
|
|
7125f2fa5e | ||
|
|
4993ed00a2 | ||
|
|
a2b622a343 | ||
|
|
c401035209 | ||
|
|
4324afc593 | ||
|
|
de5b99dbb9 | ||
|
|
374999df1f | ||
|
|
ba7455c99e | ||
|
|
ad592cdc59 | ||
|
|
78b2dac71c | ||
|
|
5d5f224f66 | ||
|
|
c70762fbee | ||
|
|
166bbbbc72 | ||
|
|
8bdcaa047a | ||
|
|
ee557cc552 | ||
|
|
d7b99be51f | ||
|
|
ed85d508ed | ||
|
|
ffa8b053d7 | ||
|
|
c39ddbc7a7 | ||
|
|
fa7fd116a7 | ||
|
|
199913ce53 | ||
|
|
1ac2d84dc0 | ||
|
|
c55128fc21 | ||
|
|
a6cb8b6989 | ||
|
|
676c5f0f09 | ||
|
|
9acc014274 | ||
|
|
2237d16696 | ||
|
|
180fd1bfb0 | ||
|
|
77bcff0dcc | ||
|
|
b43e566f98 | ||
|
|
f4e0412368 | ||
|
|
18ec24f0e8 | ||
|
|
bf10289223 | ||
|
|
e3c3d15dce | ||
|
|
b726cc8faf | ||
|
|
133746d3a3 | ||
|
|
56adbfe6fd | ||
|
|
c2e5b919d6 | ||
|
|
b675a8fbcd | ||
|
|
d5d84d598e | ||
|
|
aac17ca47d | ||
|
|
ead9bb77ec | ||
|
|
91aac9b61a | ||
|
|
d0aa9e66ca | ||
|
|
b8f92e9661 | ||
|
|
78cb583a4d | ||
|
|
69f6710898 | ||
|
|
ca3c648e3a | ||
|
|
cc581637c5 | ||
|
|
5a05011992 | ||
|
|
daa200d655 | ||
|
|
34b0040b04 | ||
|
|
24c08dfbbd | ||
|
|
390c7939f9 | ||
|
|
fa6fe06068 | ||
|
|
7193bca136 | ||
|
|
67b7272b05 | ||
|
|
88c9959e8e | ||
|
|
e4dcad7873 | ||
|
|
bd1f6881ce | ||
|
|
4b7b5d5a29 | ||
|
|
42c5bd16cd | ||
|
|
501e7c762c | ||
|
|
a01a01b533 | ||
|
|
6d56db17f4 | ||
|
|
d0040fd2a1 | ||
|
|
e5dd5eed5d | ||
|
|
dda84e74bc | ||
|
|
19712bf401 | ||
|
|
76b6aa46bd | ||
|
|
20ca710523 | ||
|
|
f98bad18b9 | ||
|
|
0ecc9765dd | ||
|
|
5d26333676 | ||
|
|
2d2af754c5 | ||
|
|
3939a5b1cf | ||
|
|
fc99153c80 | ||
|
|
076c7d669b | ||
|
|
c8020c76ae | ||
|
|
696c9663dd | ||
|
|
92144ee482 | ||
|
|
bd0b3f2856 | ||
|
|
529148ee18 | ||
|
|
810aa04eb0 | ||
|
|
20abfd4b8e | ||
|
|
bb76449560 | ||
|
|
fc6b35c7f5 | ||
|
|
e6da485117 | ||
|
|
d6160f7b7a | ||
|
|
2aedef7e77 | ||
|
|
11fd605d6b | ||
|
|
7b87ecca87 | ||
|
|
ea996f6442 | ||
|
|
e0182068b2 | ||
|
|
cd01902023 | ||
|
|
5e386e90e0 | ||
|
|
e28121f5b3 | ||
|
|
7a25e5d998 | ||
|
|
c6488a4a26 | ||
|
|
f32d18a5a3 | ||
|
|
3297bd1e9e | ||
|
|
6f9ce1f7ad | ||
|
|
a21d0ac05e | ||
|
|
584ca9e17a | ||
|
|
fb1abfbd26 | ||
|
|
e6dd71f338 | ||
|
|
46bf41fe15 | ||
|
|
01b6eccf4c | ||
|
|
e1924db1ff | ||
|
|
76309399b0 | ||
|
|
9cbb4ec36b | ||
|
|
973af860cf | ||
|
|
bc90ade337 | ||
|
|
ab54b2f6f8 | ||
|
|
72626546c5 | ||
|
|
c08dcb064c | ||
|
|
7525735df1 | ||
|
|
f28559ae6b | ||
|
|
e8957aa90f | ||
|
|
4fdc302809 | ||
|
|
c32b2bd7aa | ||
|
|
a121f33be8 | ||
|
|
f65e65fb47 | ||
|
|
a4ddcd4220 | ||
|
|
481dd0adb5 | ||
|
|
001d28aaf8 | ||
|
|
86e0a3ad77 | ||
|
|
a6a300e7c5 | ||
|
|
55a1d5a9f3 | ||
|
|
81f9cd6ee6 | ||
|
|
459151b4bf | ||
|
|
fcad1789dc | ||
|
|
1c3204e5d7 | ||
|
|
84df9bbca7 | ||
|
|
d073e7cae8 | ||
|
|
3c2ce0bb18 | ||
|
|
9aee34a501 | ||
|
|
cc5248e958 | ||
|
|
d880d05ea5 | ||
|
|
d882962b9c | ||
|
|
241cc05f80 | ||
|
|
cdcdc106ef | ||
|
|
a6bb5ed28d | ||
|
|
e1348b838b | ||
|
|
677ad50f79 | ||
|
|
6903d230fa | ||
|
|
b2cc2d4c11 | ||
|
|
763d28981c | ||
|
|
f274f74f44 | ||
|
|
9dfbcc886f | ||
|
|
5e0f64a7c2 | ||
|
|
18f24215e5 | ||
|
|
23e1c23789 | ||
|
|
a46523ee84 | ||
|
|
dc9aa270e5 | ||
|
|
ae528f844f | ||
|
|
d52c2b6426 | ||
|
|
29cd61fdcd | ||
|
|
daecac1612 | ||
|
|
abbf153785 | ||
|
|
1667019662 | ||
|
|
e2fbece993 | ||
|
|
d157dee956 | ||
|
|
9506bd5f77 | ||
|
|
2222d86e02 | ||
|
|
2161c3d762 | ||
|
|
eb5de342ba | ||
|
|
2ca9117783 | ||
|
|
b1809e9403 | ||
|
|
d1b11bc53c | ||
|
|
c61d2dd35d | ||
|
|
d8958662d9 | ||
|
|
801cdead80 | ||
|
|
5098cdb445 | ||
|
|
f229f0d648 | ||
|
|
cbaed9337b | ||
|
|
66ff2551e9 | ||
|
|
0a7e86a8fa | ||
|
|
e3c96f2d5d | ||
|
|
24741ed420 | ||
|
|
1f6f8f194b | ||
|
|
102966482b | ||
|
|
eb7929e758 | ||
|
|
8bbfdf2671 | ||
|
|
958400eaf6 | ||
|
|
20e862a6a0 | ||
|
|
8cbb30b036 | ||
|
|
9696042156 | ||
|
|
56b27dd055 | ||
|
|
a388e9ad85 | ||
|
|
2e93cca73a | ||
|
|
6a694444c5 | ||
|
|
8227b49b59 | ||
|
|
dd483c3300 | ||
|
|
f217f17c52 | ||
|
|
be3f69a2d0 | ||
|
|
bf96b96fdf | ||
|
|
c7537cca96 | ||
|
|
14a87465ce | ||
|
|
8c8df5b1b4 | ||
|
|
a56c736c06 | ||
|
|
7ff3e3e79b | ||
|
|
c5713c52da | ||
|
|
5bea494193 | ||
|
|
e48b715f4f | ||
|
|
12ac9460b9 | ||
|
|
c8c72eadab | ||
|
|
cd476bb463 | ||
|
|
53617bd366 | ||
|
|
99f2606d4d | ||
|
|
2aebdf79f3 | ||
|
|
c840544d25 | ||
|
|
927df66e9a | ||
|
|
7f4443c77f | ||
|
|
1600e6c0d4 | ||
|
|
0c86ba29fc | ||
|
|
b2f6b158e3 | ||
|
|
6ab2f69111 | ||
|
|
0097942732 | ||
|
|
3686e7fdd2 | ||
|
|
0e8f3362b9 | ||
|
|
078142bd3f | ||
|
|
304817b68e | ||
|
|
e48c05a0ab | ||
|
|
4cdcefb980 | ||
|
|
dcc818e9c3 | ||
|
|
0037064958 | ||
|
|
c0ccbf73d0 | ||
|
|
500d0387fd | ||
|
|
0f077832cf | ||
|
|
449468f566 | ||
|
|
fd2444f2cd | ||
|
|
d6968dffdd | ||
|
|
b50119e0bc | ||
|
|
58e90298eb | ||
|
|
224dc1e68c | ||
|
|
e9262f18db | ||
|
|
14b4af8b33 | ||
|
|
af271f62f3 | ||
|
|
6f9fba9fbf | ||
|
|
afa329b5e4 | ||
|
|
d8395fff59 | ||
|
|
81abd65da1 | ||
|
|
a48c197ecc | ||
|
|
85d53896de | ||
|
|
8b844aa6e3 | ||
|
|
578117d82a | ||
|
|
363c99ceca | ||
|
|
a93177eb61 | ||
|
|
d6181e2dcd | ||
|
|
f9b74cf7e2 | ||
|
|
d4740550e4 | ||
|
|
d91c44f6f3 | ||
|
|
e59b46448a | ||
|
|
d826391d16 | ||
|
|
5406960f26 | ||
|
|
8f1d1e4934 | ||
|
|
54b6fd67e7 | ||
|
|
1568ee6176 | ||
|
|
6978ac9cd3 | ||
|
|
1961eb832a | ||
|
|
c38423c251 | ||
|
|
ecd3ec1c61 | ||
|
|
66e8bcd86a | ||
|
|
23b1036c6b | ||
|
|
0d4ab17d0a | ||
|
|
b38a692fc5 | ||
|
|
2ff96a6b91 | ||
|
|
9089d6568a | ||
|
|
73c43b030e | ||
|
|
42fa737844 | ||
|
|
e4f61115c6 | ||
|
|
3bb9994589 | ||
|
|
23f6c75257 | ||
|
|
3bac7ba99b | ||
|
|
56a5df86a0 | ||
|
|
50d707a8e3 | ||
|
|
aa49e5869b | ||
|
|
d982a2b91e | ||
|
|
a92736bb3a | ||
|
|
54386285cc | ||
|
|
676027a56f | ||
|
|
cdc0d9e012 | ||
|
|
32d4c0ed72 | ||
|
|
16959cac7a | ||
|
|
f2f20f8f94 | ||
|
|
1a8efd5835 | ||
|
|
5a01c7a4db | ||
|
|
1b18139e41 | ||
|
|
263b3bbeda | ||
|
|
cba01aaa59 | ||
|
|
d4599b05a0 | ||
|
|
200287316d | ||
|
|
1d05f3d851 | ||
|
|
8e8d987686 | ||
|
|
343512e9bf | ||
|
|
af612c058b | ||
|
|
d81e8be3cf | ||
|
|
fb93289538 | ||
|
|
92a2217e80 | ||
|
|
b6d41260e7 | ||
|
|
bb6b54990f | ||
|
|
016d27e22d | ||
|
|
17a336e27d | ||
|
|
c3f3573a99 | ||
|
|
81dab2f0b6 | ||
|
|
a80e534179 | ||
|
|
8310f87504 | ||
|
|
f27057c790 | ||
|
|
649d267fa5 | ||
|
|
d8a7e5d366 | ||
|
|
8ccc241743 | ||
|
|
af922d209d | ||
|
|
958d0debbb | ||
|
|
2016891bd5 | ||
|
|
412cb26c0f | ||
|
|
3fc983f273 | ||
|
|
b5d24f9c00 | ||
|
|
a432173cd6 | ||
|
|
5440161ff9 | ||
|
|
bb542c475c | ||
|
|
aef834e914 | ||
|
|
fd44120874 | ||
|
|
0e9b2b245d | ||
|
|
eacbd21c50 | ||
|
|
deca8e74a8 | ||
|
|
9eefbb26d8 | ||
|
|
b637462ee8 | ||
|
|
7fc513e09e | ||
|
|
802e1c96bd | ||
|
|
0bc75f6f78 | ||
|
|
32a3ba535b | ||
|
|
2e898d997b | ||
|
|
817b335349 | ||
|
|
e9d551f4cb | ||
|
|
33933e914e | ||
|
|
8e230a08b5 | ||
|
|
dfc4f6f304 | ||
|
|
5a3061f942 | ||
|
|
b40281fda3 | ||
|
|
966fbf8c6a | ||
|
|
ca65f1b209 | ||
|
|
a5d73f06d2 | ||
|
|
56b0e8440e | ||
|
|
b6a12b6ceb | ||
|
|
15a12acfd3 | ||
|
|
c534e0f1fe | ||
|
|
5e68580fa6 | ||
|
|
e6d83e7305 | ||
|
|
d56cf106b4 | ||
|
|
4279ccf292 | ||
|
|
846b202192 | ||
|
|
330ebe2bf3 | ||
|
|
79b4a5e720 | ||
|
|
8186b62a91 | ||
|
|
20f0c852aa | ||
|
|
9e4ae23c0b | ||
|
|
585f6f2fa5 | ||
|
|
a4fba3b19c | ||
|
|
a2180eb5d3 | ||
|
|
514161fefa | ||
|
|
bba059f35f | ||
|
|
5977f865e3 | ||
|
|
ade7c0477f | ||
|
|
a2fded8340 | ||
|
|
005e15c45f | ||
|
|
e9962a8923 | ||
|
|
c6611eae9c | ||
|
|
261193959c | ||
|
|
e7a71eabb6 | ||
|
|
afba84e584 | ||
|
|
96faff7711 | ||
|
|
94166b493c | ||
|
|
6a0b1b2dcf | ||
|
|
5c8e3d95a7 | ||
|
|
4c91588af6 | ||
|
|
35c05654a5 | ||
|
|
fbc9b5fab8 | ||
|
|
1126ab6578 | ||
|
|
0842613b24 | ||
|
|
bf4a4b574c | ||
|
|
380657679e | ||
|
|
0a214af29b | ||
|
|
b008122149 | ||
|
|
7b6feb9e4f | ||
|
|
e4861bf94c | ||
|
|
587a3f01a2 | ||
|
|
8d5c82356e | ||
|
|
df039ab1c1 | ||
|
|
f5e3c6eddd | ||
|
|
fc01712132 | ||
|
|
7ec0bf83b4 | ||
|
|
504476c5db | ||
|
|
f78dbd57bc | ||
|
|
d2b27fdf25 | ||
|
|
3aa20f82b9 | ||
|
|
402b2f0264 | ||
|
|
4dd2328e10 | ||
|
|
98bcdd203e | ||
|
|
741ed51d08 | ||
|
|
5d8e07228e | ||
|
|
4a43a48b2e | ||
|
|
0ef3b4ab4b | ||
|
|
00e0f00974 | ||
|
|
91181f9e93 | ||
|
|
5c42c50a40 | ||
|
|
36399386c5 | ||
|
|
8eee4cd699 | ||
|
|
1410e8bd81 | ||
|
|
915375fb1c | ||
|
|
52fff28dc4 | ||
|
|
bd035622b8 | ||
|
|
44163710f9 | ||
|
|
44b1ccdeae | ||
|
|
34113cb782 | ||
|
|
2a336a9275 | ||
|
|
5c08a9193c | ||
|
|
2cae7f9c18 | ||
|
|
e056c97d9d | ||
|
|
dc49e0d08b | ||
|
|
b639f6af28 | ||
|
|
6b45c4ba9b | ||
|
|
2062502a59 | ||
|
|
a490d9ead2 | ||
|
|
c73832ac2c |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -7,3 +7,6 @@ build
|
|||||||
examples
|
examples
|
||||||
*.bin
|
*.bin
|
||||||
*.ans
|
*.ans
|
||||||
|
*.patch
|
||||||
|
*.zip
|
||||||
|
result
|
||||||
135
CMakeLists.txt
135
CMakeLists.txt
@@ -1,23 +1,120 @@
|
|||||||
project(dsd-fme-aero)
|
#Ubuntu 20.04 uses 3.16.3
|
||||||
cmake_minimum_required(VERSION 2.8.11)
|
#Ubuntu 22.04 uses 3.22.1
|
||||||
|
#Arch currently on 3.26.3
|
||||||
|
#Cygwin currently using 3.23.2 (or newer)
|
||||||
|
cmake_minimum_required(VERSION 3.10.2)
|
||||||
|
project(dsd-fme)
|
||||||
|
|
||||||
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake/")
|
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake/")
|
||||||
#Set curses to ncurses, and wide true for ascii
|
#Set curses to ncurses, and wide true for ascii
|
||||||
set(CURSES_NEED_NCURSES TRUE)
|
set(CURSES_NEED_NCURSES TRUE)
|
||||||
set(CURSES_NEED_WIDE TRUE)
|
set(CURSES_NEED_WIDE TRUE)
|
||||||
|
|
||||||
|
#use cmake option -DCOLORS=OFF to disable color output (ncurses)
|
||||||
|
option(COLORS
|
||||||
|
"Build with Colors Enabled" ON)
|
||||||
|
if (COLORS)
|
||||||
|
add_definitions(-DPRETTY_COLORS)
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
#use cmake option -DCOLORSLOGS=OFF to disable color output (terminal/logs)
|
||||||
|
option(COLORSLOGS
|
||||||
|
"Build with Colors Enabled" ON)
|
||||||
|
if (COLORSLOGS)
|
||||||
|
add_definitions(-DPRETTY_COLORS_LOGS)
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
#use cmake option -DPVC=ON to enable Provoice Conventional Frame Sync
|
||||||
|
option(PVC
|
||||||
|
"Build with Provoice Conventional Frame Sync Enabled" OFF)
|
||||||
|
if (PVC)
|
||||||
|
add_definitions(-DPVCONVENTIONAL)
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
|
||||||
|
#use cmake option -DLZ=ON to enable LimaZulu Requested NXDN Tweaks
|
||||||
|
option(LZ
|
||||||
|
"Build with new LimaZulu Requested NXDN Tweaks Enabled" OFF)
|
||||||
|
if (LZ)
|
||||||
|
add_definitions(-DLIMAZULUTWEAKS)
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
#use cmake option -DASCII=ON to enable ASCII only Alias Support in NXDN
|
||||||
|
option(ASCII
|
||||||
|
"Build with ASCII only Alias Support in NXDN Enabled" ON)
|
||||||
|
if (ASCII)
|
||||||
|
add_definitions(-DASCII_DECODE)
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
#use cmake option -DASCII=OFF -DBIG5=ON to enable ASCII and BIG5 Alias Support in NXDN
|
||||||
|
option(BIG5
|
||||||
|
"Build with BIG5 and ASCII Alias Support in NXDN Enabled" OFF)
|
||||||
|
if (BIG5)
|
||||||
|
add_definitions(-DBIG5_DECODE)
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
#use cmake option -DASCII=OFF -DSJIS=ON to enable ASCII and SJIS Alias Support in NXDN
|
||||||
|
option(SJIS
|
||||||
|
"Build with SJIS and ASCII Alias Support in NXDN Enabled" OFF)
|
||||||
|
if (SJIS)
|
||||||
|
add_definitions(-DSJIS_DECODE)
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
#use cmake option -DASCII=OFF -DUTF16=ON to enable ASCII and UTF16BE Alias Support in NXDN
|
||||||
|
option(UTF16
|
||||||
|
"Build with UTF16BE and ASCII Alias Support in NXDN Enabled" OFF)
|
||||||
|
if (UTF16)
|
||||||
|
add_definitions(-DUTF16_DECODE)
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
#use cmake option -DTYPEC=OFF to disable NXDN Type-C and Conventional Decoding (enabled by default)
|
||||||
|
option(TYPEC
|
||||||
|
"Build with NXDN Type-C and Conventional Decoding Enabled" ON)
|
||||||
|
if (TYPEC)
|
||||||
|
add_definitions(-DTYPE_C_DECODE)
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
#use cmake option -DTYPED=OFF to disable NXDN Type-D / IDAS Decoding (enabled by default)
|
||||||
|
option(TYPED
|
||||||
|
"Build with NXDN Type-D / IDAS Decoding Enabled" ON)
|
||||||
|
if (TYPED)
|
||||||
|
add_definitions(-DTYPE_D_DECODE)
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
#use cmake option -DDCR=OFF to disable Japanese DCR (NXDN Variant) Decoding (enabled by default)
|
||||||
|
option(DCR
|
||||||
|
"Build with Japanese DCR (NXDN Variant) Decoding Enabled" ON)
|
||||||
|
if (DCR)
|
||||||
|
add_definitions(-DJPNDCR_DECODE)
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
#use cmake option -DNOS=ON to enable older NXDN sync w/ pos and inv polarity, disable newer seperated (disabled by default)
|
||||||
|
option(NOS
|
||||||
|
"Build with Old NXDN Sync (pos and inv polarity) Enabled" OFF)
|
||||||
|
if (NOS)
|
||||||
|
add_definitions(-DNXDN_OLD_SYNC)
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
#use cmake option -DSID=ON to enable P25p1 Soft ID decoding -- Experimental
|
||||||
|
option(SID
|
||||||
|
"Build with P25p1 LSD/Soft ID Enabled" OFF)
|
||||||
|
if (SID)
|
||||||
|
add_definitions(-DSOFTID)
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
|
||||||
include(git_revision)
|
include(git_revision)
|
||||||
git_describe(GIT_TAG)
|
git_describe(GIT_TAG)
|
||||||
|
|
||||||
find_package(LibSndFile REQUIRED)
|
find_package(LibSndFile REQUIRED)
|
||||||
find_package(MBE REQUIRED)
|
find_package(MBE REQUIRED)
|
||||||
find_package(ITPP REQUIRED)
|
|
||||||
find_package(RTLSDR)
|
find_package(RTLSDR)
|
||||||
find_package(Curses REQUIRED)
|
find_package(Curses REQUIRED)
|
||||||
find_package(PULSEAUDIO REQUIRED)
|
find_package(PulseAudio REQUIRED)
|
||||||
|
find_package(CODEC2)
|
||||||
|
|
||||||
include_directories(SYSTEM ${LIBSNDFILE_INCLUDE_DIR} ${MBE_INCLUDE_DIR} ${ITPP_INCLUDE_DIR} ${PULSEAUDIO_INCLUDE_DIRS} ${CURSES_INCLUDE_DIR})
|
include_directories(SYSTEM ${LIBSNDFILE_INCLUDE_DIR} ${MBE_INCLUDE_DIR} ${PULSEAUDIO_INCLUDE_DIRS} ${CURSES_INCLUDE_DIRS})
|
||||||
set(LIBS ${MBE_LIBRARY} ${LIBSNDFILE_LIBRARY} ${ITPP_LIBRARY} ${PULSEAUDIO_SIMPLE_LIBRARY} ${CURSES_LIBRARY})
|
set(LIBS ${MBE_LIBRARY} ${LIBSNDFILE_LIBRARY} ${PULSEAUDIO_SIMPLE_LIBRARY} ${PULSEAUDIO_LIBRARY} ${CURSES_LIBRARIES})
|
||||||
|
|
||||||
if(RTLSDR_FOUND)
|
if(RTLSDR_FOUND)
|
||||||
find_package(Threads)
|
find_package(Threads)
|
||||||
@@ -26,11 +123,18 @@ if(RTLSDR_FOUND)
|
|||||||
add_definitions(-DUSE_RTLSDR)
|
add_definitions(-DUSE_RTLSDR)
|
||||||
endif(RTLSDR_FOUND)
|
endif(RTLSDR_FOUND)
|
||||||
|
|
||||||
|
if(CODEC2_FOUND)
|
||||||
|
include_directories(SYSTEM ${CODEC2_INCLUDE_DIRS})
|
||||||
|
list(APPEND LIBS ${CODEC2_LIBRARIES})
|
||||||
|
add_definitions(-DUSE_CODEC2)
|
||||||
|
endif(CODEC2_FOUND)
|
||||||
|
|
||||||
FILE(GLOB SRCS src/*.c src/*.cpp)
|
FILE(GLOB SRCS src/*.c src/*.cpp)
|
||||||
FILE(GLOB HEADERS include/*.h include/*.hpp)
|
FILE(GLOB HEADERS include/*.h include/*.hpp)
|
||||||
|
|
||||||
if(NOT RTLSDR_FOUND)
|
if(NOT RTLSDR_FOUND)
|
||||||
list(REMOVE_ITEM SRCS ${CMAKE_CURRENT_SOURCE_DIR}/src/rtl_sdr_fm.cpp)
|
list(REMOVE_ITEM SRCS ${CMAKE_CURRENT_SOURCE_DIR}/src/rtl_sdr_fm.cpp)
|
||||||
|
list(REMOVE_ITEM SRCS ${CMAKE_CURRENT_SOURCE_DIR}/src/rtl_sdr_tcp.c)
|
||||||
endif(NOT RTLSDR_FOUND)
|
endif(NOT RTLSDR_FOUND)
|
||||||
|
|
||||||
configure_file("src/git_ver.c.in" "${CMAKE_CURRENT_BINARY_DIR}/git_ver.c" @ONLY)
|
configure_file("src/git_ver.c.in" "${CMAKE_CURRENT_BINARY_DIR}/git_ver.c" @ONLY)
|
||||||
@@ -38,24 +142,29 @@ list(APPEND SRCS "${CMAKE_CURRENT_BINARY_DIR}/git_ver.c")
|
|||||||
|
|
||||||
include_directories("${PROJECT_SOURCE_DIR}/include")
|
include_directories("${PROJECT_SOURCE_DIR}/include")
|
||||||
|
|
||||||
ADD_EXECUTABLE(dsd-fme-aero ${SRCS} ${HEADERS})
|
ADD_EXECUTABLE(dsd-fme ${SRCS} ${HEADERS})
|
||||||
TARGET_LINK_LIBRARIES(dsd-fme-aero ${LIBS})
|
TARGET_LINK_LIBRARIES(dsd-fme ${LIBS})
|
||||||
|
|
||||||
|
target_compile_options(dsd-fme PRIVATE -Wunused-but-set-variable -Wunused-variable -Wunused-parameter
|
||||||
|
-Wempty-body -Wunused-label $<$<COMPILE_LANGUAGE:C>:-Wpointer-sign>
|
||||||
|
-Wmisleading-indentation -Wparentheses -Wunused-value -Wreturn-type
|
||||||
|
-Wtautological-compare)
|
||||||
|
|
||||||
include(GNUInstallDirs)
|
include(GNUInstallDirs)
|
||||||
install(TARGETS dsd-fme-aero DESTINATION ${CMAKE_INSTALL_BINDIR})
|
install(TARGETS dsd-fme DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||||
|
|
||||||
# man page
|
# man page
|
||||||
find_program(HELP2MAN_FOUND help2man)
|
find_program(HELP2MAN_FOUND help2man)
|
||||||
if (HELP2MAN_FOUND)
|
if (HELP2MAN_FOUND)
|
||||||
add_custom_command(TARGET dsd-fme-aero POST_BUILD
|
add_custom_command(TARGET dsd-fme POST_BUILD
|
||||||
COMMAND help2man
|
COMMAND help2man
|
||||||
ARGS -n "Digital Speech Decoder"
|
ARGS -n "Digital Speech Decoder"
|
||||||
--version-string=${GIT_TAG}
|
--version-string=${GIT_TAG}
|
||||||
-o ${CMAKE_CURRENT_BINARY_DIR}/dsd-fme-aero.1
|
-o ${CMAKE_CURRENT_BINARY_DIR}/dsd-fme.1
|
||||||
--no-info
|
--no-info
|
||||||
$<TARGET_FILE:dsd-fme-aero>
|
$<TARGET_FILE:dsd-fme>
|
||||||
)
|
)
|
||||||
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/dsd-fme-aero.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1)
|
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/dsd-fme.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# uninstall target
|
# uninstall target
|
||||||
|
|||||||
15
README.md
15
README.md
@@ -1,6 +1,17 @@
|
|||||||
## Notice
|
|
||||||
|
|
||||||
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"), [SDRTRunk](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, ilyacodes, Phillipw1084 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, YSF, M17, OP25 Capture Bin compatability, etc. DSD-FME is primarily focused with Linux Desktop users in mind, 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, Forts, thewraithe2008, RayAir, Cretu, and others for the many hours of wav samples and information provided 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. I'd also like to thank mrscanner2008 for providing an additional remote where additional NXDN Type-C, 'Idas' Type-D, and XPT decoding and trunking could be sorted out. Thanks to volo-zyko for cleaning up a lot of code. Thank you everybody.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## Information
|
||||||
|
|
||||||
|
See the [examples](https://github.com/lwvmobile/dsd-fme/tree/audio_work/examples "examples") folder for information on [cloning and installing](https://github.com/lwvmobile/dsd-fme/blob/audio_work/examples/Install_Notes.md "cloning and installing"), [example usage](https://github.com/lwvmobile/dsd-fme/blob/audio_work/examples/Example_Usage.md "example usage"), and [trunking examples](https://github.com/lwvmobile/dsd-fme/blob/audio_work/examples/trunking.sh "trunking examples").
|
||||||
|
|
||||||
## License
|
## License
|
||||||
Copyright (C) 2010 DSD Author
|
Copyright (C) 2010 DSD Author
|
||||||
|
|||||||
31
cmake/FindCODEC2.cmake
Normal file
31
cmake/FindCODEC2.cmake
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
# - Try to find CODEC2
|
||||||
|
# Once done this will define
|
||||||
|
|
||||||
|
#Seems to work on Cygwin as well now -- more testing for may be required
|
||||||
|
# Not sure what causes the 'Package 'codec2', required by 'virtual:world', not found' message, but seems to work anyways
|
||||||
|
# -- Checking for module 'codec2'
|
||||||
|
# -- Package 'codec2', required by 'virtual:world', not found
|
||||||
|
# -- Found CODEC2: /usr/local/lib/libcodec2.dll.a
|
||||||
|
|
||||||
|
if (NOT CODEC2_FOUND)
|
||||||
|
|
||||||
|
find_package(PkgConfig)
|
||||||
|
pkg_check_modules(CODEC2_PKG codec2)
|
||||||
|
set(CODEC2_DEFINITIONS ${PC_CODEC2_CFLAGS_OTHER})
|
||||||
|
|
||||||
|
find_path(CODEC2_INCLUDE_DIR
|
||||||
|
NAMES codec2/codec2.h codec2.h
|
||||||
|
HINTS ${CODEC2_PKG_INCLUDE_DIRS})
|
||||||
|
|
||||||
|
find_library(CODEC2_LIBRARY
|
||||||
|
NAMES codec2/codec2 codec2
|
||||||
|
HINTS ${CODEC2_PKG_LIBRARY_DIRS})
|
||||||
|
|
||||||
|
set(CODEC2_LIBRARIES ${CODEC2_LIBRARY})
|
||||||
|
set(CODEC2_INCLUDE_DIRS ${CODEC2_INCLUDE_DIR})
|
||||||
|
|
||||||
|
include(FindPackageHandleStandardArgs)
|
||||||
|
find_package_handle_standard_args(CODEC2 DEFAULT_MSG CODEC2_LIBRARY CODEC2_INCLUDE_DIR)
|
||||||
|
mark_as_advanced(CODEC2_INCLUDE_DIR CODEC2_LIBRARY)
|
||||||
|
|
||||||
|
endif (NOT CODEC2_FOUND)
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
# - Try to find ITPP
|
|
||||||
# Once done this will define
|
|
||||||
#
|
|
||||||
# ITPP_FOUND - System has ITPP
|
|
||||||
# ITPP_INCLUDE_DIR - The ITPP include directory
|
|
||||||
# ITPP_LIBRARY - The library needed to use ITPP
|
|
||||||
#
|
|
||||||
|
|
||||||
find_path(ITPP_INCLUDE_DIR itpp/itcomm.h)
|
|
||||||
|
|
||||||
set(ITPP_NAMES ${ITPP_NAMES} itpp libitpp libitpp.dll)
|
|
||||||
FIND_LIBRARY(ITPP_LIBRARY NAMES ${ITPP_NAMES})
|
|
||||||
|
|
||||||
include(FindPackageHandleStandardArgs)
|
|
||||||
find_package_handle_standard_args(ITPP DEFAULT_MSG ITPP_LIBRARY ITPP_INCLUDE_DIR)
|
|
||||||
244
cyg_portable.sh
Normal file
244
cyg_portable.sh
Normal file
@@ -0,0 +1,244 @@
|
|||||||
|
#! /bin/bash
|
||||||
|
#
|
||||||
|
cdir=$(pwd)
|
||||||
|
clear
|
||||||
|
printf "DSD-FME Digital Speech Decoder - Florida Man Edition Portable Cygwin Creator\n"
|
||||||
|
printf "Only use this in a Cygwin64 Environment. Will not work in a Linux Environment!\n"
|
||||||
|
read -p "Do you want to make a portable copy? y/N " RELEASE
|
||||||
|
RELEASE=$(printf "$RELEASE"|tr '[:upper:]' '[:lower:]')
|
||||||
|
if [ "$RELEASE" = "y" ]; then
|
||||||
|
|
||||||
|
printf "Copying files to dsd-fme-portable folder and making zip file. Please wait!\n"
|
||||||
|
cd ~
|
||||||
|
|
||||||
|
#create a dsd-fme-portable folder and copy all the needed items for a portable release version
|
||||||
|
mkdir dsd-fme-portable
|
||||||
|
cd dsd-fme-portable
|
||||||
|
#all of these folders may not be necessary
|
||||||
|
mkdir sourcecode
|
||||||
|
mkdir bin
|
||||||
|
mkdir dev
|
||||||
|
cd dev
|
||||||
|
mkdir shm
|
||||||
|
cd ..
|
||||||
|
mkdir dsd-fme
|
||||||
|
mkdir logs
|
||||||
|
mkdir WAV
|
||||||
|
mkdir etc
|
||||||
|
mkdir home
|
||||||
|
mkdir lib
|
||||||
|
mkdir tmp
|
||||||
|
mkdir usr
|
||||||
|
cd usr
|
||||||
|
mkdir share
|
||||||
|
cd share
|
||||||
|
mkdir terminfo
|
||||||
|
cd ~
|
||||||
|
|
||||||
|
#start copying things
|
||||||
|
|
||||||
|
#terminfo is needed for ncurses
|
||||||
|
cp -r /usr/share/terminfo/* dsd-fme-portable/usr/share/terminfo
|
||||||
|
|
||||||
|
#copy required items from the root bin folder to release bin folder
|
||||||
|
cp /bin/ls.exe dsd-fme-portable/bin/
|
||||||
|
cp /bin/bash.exe dsd-fme-portable/bin/
|
||||||
|
cp /bin/ncurses6-config dsd-fme-portable/bin/
|
||||||
|
cp /bin/ncursesw6-config dsd-fme-portable/bin/
|
||||||
|
cp /bin/pacat.exe dsd-fme-portable/bin/
|
||||||
|
cp /bin/pactl.exe dsd-fme-portable/bin/
|
||||||
|
cp /bin/padsp dsd-fme-portable/bin/
|
||||||
|
cp /bin/pamon dsd-fme-portable/bin/
|
||||||
|
cp /bin/paplay dsd-fme-portable/bin/
|
||||||
|
cp /bin/parec dsd-fme-portable/bin/
|
||||||
|
cp /bin/parecord dsd-fme-portable/bin/
|
||||||
|
cp /bin/pulseaudio.exe dsd-fme-portable/bin/
|
||||||
|
cp /bin/tty.exe dsd-fme-portable/bin/
|
||||||
|
|
||||||
|
#start copying things from the etc folder
|
||||||
|
cp -r /etc/pulse/ dsd-fme-portable/etc/
|
||||||
|
|
||||||
|
#start copying things to the lib folder
|
||||||
|
cp -r /lib/pulseaudio/ dsd-fme-portable/lib/
|
||||||
|
|
||||||
|
#start copying things into the dsd-fme folder
|
||||||
|
cp dsd-fme/build/dsd-fme.exe dsd-fme-portable/dsd-fme/
|
||||||
|
cp -r dsd-fme/examples dsd-fme-portable/dsd-fme/
|
||||||
|
cp .bash_profile dsd-fme-portable/dsd-fme/
|
||||||
|
cp .bashrc dsd-fme-portable/dsd-fme/
|
||||||
|
cp .inputrc dsd-fme-portable/dsd-fme/
|
||||||
|
cp .profile dsd-fme-portable/dsd-fme/
|
||||||
|
|
||||||
|
#move (cut) the bat files to the portable folder root and delete the other ones so users won't get confused
|
||||||
|
mv dsd-fme-portable/dsd-fme/examples/cygwin_bat/*.bat dsd-fme-portable/
|
||||||
|
mv dsd-fme-portable/dsd-fme/examples/cygwin_bat/example_options.txt dsd-fme-portable/
|
||||||
|
mv dsd-fme-portable/dsd-fme/examples/cygwin_bat/complete_usage_options.txt dsd-fme-portable/
|
||||||
|
rm -rf dsd-fme-portable/dsd-fme/examples/cygwin_bat
|
||||||
|
|
||||||
|
#change .bat files permissions to be read/write/executable by all users (for some reason, this is not preserved)
|
||||||
|
chmod 777 dsd-fme-portable/*.bat
|
||||||
|
|
||||||
|
#copy the license, copyright, source code, and things that should be included in all portable releases
|
||||||
|
cp dsd-fme/COPYRIGHT dsd-fme-portable/sourcecode/
|
||||||
|
cp dsd-fme/DSD_Author.pgp dsd-fme-portable/sourcecode/
|
||||||
|
cp dsd-fme/dsd-fme-qgis-map.qgz dsd-fme-portable/sourcecode/
|
||||||
|
cp dsd-fme/README.md dsd-fme-portable/sourcecode/
|
||||||
|
cp dsd-fme/dsd-fme2.png dsd-fme-portable/sourcecode/
|
||||||
|
cp dsd-fme/dsd-fme3.png dsd-fme-portable/sourcecode/
|
||||||
|
|
||||||
|
cp dsd-fme/CMakeLists.txt dsd-fme-portable/sourcecode/
|
||||||
|
cp -r dsd-fme/src dsd-fme-portable/sourcecode/
|
||||||
|
cp -r dsd-fme/include dsd-fme-portable/sourcecode/
|
||||||
|
cp -r dsd-fme/cmake dsd-fme-portable/sourcecode/
|
||||||
|
cp -r dsd-fme/patch dsd-fme-portable/sourcecode/
|
||||||
|
|
||||||
|
#compiled items into release dsd-fme folder
|
||||||
|
cp codec2/build/src/cygcodec2* dsd-fme-portable/dsd-fme/
|
||||||
|
cp rtl-sdr/build/src/cyg* dsd-fme-portable/dsd-fme/
|
||||||
|
cp mbelib/build/cygmbe* dsd-fme-portable/dsd-fme/
|
||||||
|
|
||||||
|
#bin items into release dsd-fme folder (uisng * where version numbering may exist, those may be upgraded if hard coded)
|
||||||
|
cp /bin/bash.exe dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cut.exe dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygao* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygarchive* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygargp* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygassuan* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygasyncns* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygatomic* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygattr* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygavahi-client* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygavahi-common* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygavahi-wrap* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygblkid* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygbrotlicommon* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygbrotlidec* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygbz2* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygcares* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygcheck.exe dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygcli.dll dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygcom_err* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygcrypt* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygcrypto* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygcurl* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygdb_cxx* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygdb_sql* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygdb* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygdbus* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygedit* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygexpat* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygfdisk* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygffi* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygfftw3_threads* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygfftw3* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygfftw3f_threads* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygfftw3f* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygfftw3l_threads* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygfftw3l* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygfido2* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygFLAC* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygformw* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cyggc* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cyggdbm_compat* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cyggdbm*.dll dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cyggio* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygglib* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cyggmodule* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cyggmp* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cyggnutls* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cyggobject* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cyggomp* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cyggpg-error* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cyggpgme* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cyggsm* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cyggssapi_krb5* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cyggthread* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygguile* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cyghistory* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cyghogweed* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygICE* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygiconv* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygid3tag* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygidn* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygintl* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygisl* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygjsoncpp* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygk5crypto* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygkrb5* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cyglber* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygldap* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygltdl* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cyglz* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygma* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygmenuw* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygmeta* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygmp* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygncurses* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygnettle* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygnghttp* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygobjc* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygogg* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygopus* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygorc* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygp11* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygpanel* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygpath.exe dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygpcre* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygperl* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygpipe* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygpkg* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygpng* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygpopt* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygprotocol* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygpsl* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygpulse* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygquadmath* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygreadline* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygrhash* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygrunsrv.exe dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygsamplerate* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygsasl* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygserver* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygSM* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygsmart* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygsndfile* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygsox* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygspeex* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygsqlite* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygssh* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygssl* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygstart.exe dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygstdc* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygtasn* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygtdb* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygticw* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygtwo* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygunistring* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygusb* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cyguuid* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cyguv* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygvorbis* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygwavpack* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygwin1.dll dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygwrap* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygX* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygx* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/cygz* dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/grep.exe dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/ls.exe dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/mintty.exe dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/pacat.exe dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/pacmd.exe dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/pactl.exe dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/padsp dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/pamon dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/paplay dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/parec dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/pulseaudio.exe dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/tail.exe dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/touch.exe dsd-fme-portable/dsd-fme/
|
||||||
|
cp /bin/tty.exe dsd-fme-portable/dsd-fme/
|
||||||
|
|
||||||
|
zip -r dsd-fme-x86-64-cygwin-portable.zip dsd-fme-portable
|
||||||
|
|
||||||
|
fi
|
||||||
14
cyg_rebuild.sh
Normal file
14
cyg_rebuild.sh
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
#! /bin/bash
|
||||||
|
#
|
||||||
|
clear
|
||||||
|
printf "DSD-FME Digital Speech Decoder - Florida Man Edition
|
||||||
|
Automatic Git Pull and Rebuild for Cygwin\n\n"
|
||||||
|
sleep 1
|
||||||
|
##Open your clone folder##
|
||||||
|
git pull
|
||||||
|
sleep 2
|
||||||
|
##cd into your build folder##
|
||||||
|
cd build
|
||||||
|
cmake ..
|
||||||
|
make -j $(nproc)
|
||||||
|
make install
|
||||||
47
download-and-install-Arch.sh
Normal file
47
download-and-install-Arch.sh
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
#! /bin/bash
|
||||||
|
#
|
||||||
|
cdir=$(pwd)
|
||||||
|
clear
|
||||||
|
printf "Digital Speech Decoder: Florida Man Edition - Auto Installer For Arch Linux\n
|
||||||
|
This will install the required packages, clone, build, and install DSD-FME only.
|
||||||
|
This has been tested on Arch 2023.08.01 and Manjaro XFCE 22.1.3 Minimal.\n
|
||||||
|
MBELib is considered a requirement on this build.
|
||||||
|
You must view the Patent Notice prior to continuing.
|
||||||
|
The Patent Notice can be found at the site below.
|
||||||
|
https://github.com/lwvmobile/mbelib#readme
|
||||||
|
Please confirm that you have viewed the patent notice by entering y below.\n\n"
|
||||||
|
read -p "Have you viewed the patent notice? y/N " ANSWER
|
||||||
|
ANSWER=$(printf "$ANSWER"|tr '[:upper:]' '[:lower:]')
|
||||||
|
if [ "$ANSWER" = "y" ]; then
|
||||||
|
|
||||||
|
sudo pacman -Syu #always run a full update first, partial upgrades aren't supported in Arch -- including downloading dependencies, that may require an updated dependency, and breaks same dependency on another package, a.k.a, dependency hell
|
||||||
|
sudo pacman -S libpulse cmake ncurses lapack perl fftw rtl-sdr codec2 base-devel libsndfile git wget
|
||||||
|
|
||||||
|
git clone https://github.com/lwvmobile/mbelib
|
||||||
|
cd mbelib
|
||||||
|
git checkout ambe_tones
|
||||||
|
mkdir build
|
||||||
|
cd build
|
||||||
|
cmake ..
|
||||||
|
make -j $(nproc)
|
||||||
|
sudo make install
|
||||||
|
sudo ldconfig
|
||||||
|
sudo cp /usr/local/lib/libmbe.so /usr/lib/libmbe.so
|
||||||
|
cd $cdir
|
||||||
|
|
||||||
|
git clone https://github.com/lwvmobile/dsd-fme
|
||||||
|
### For branch audio_work - git clone --branch audio_work https://github.com/lwvmobile/dsd-fme
|
||||||
|
cd dsd-fme
|
||||||
|
#git checkout audio_work
|
||||||
|
mkdir build
|
||||||
|
cd build
|
||||||
|
cmake ..
|
||||||
|
make -j $(nproc)
|
||||||
|
sudo make install
|
||||||
|
sudo ldconfig
|
||||||
|
|
||||||
|
printf "Any issues, Please report to either:\nhttps://github.com/lwvmobile/dsd-fme/issues or\nhttps://forums.radioreference.com/threads/dsd-fme.438137/\n\n"
|
||||||
|
|
||||||
|
else
|
||||||
|
printf "Sorry, you cannot build DSD-FME without acknowledging the Patent Notice.\n\n"
|
||||||
|
fi
|
||||||
77
download-and-install-cygwin.sh
Normal file
77
download-and-install-cygwin.sh
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
#! /bin/bash
|
||||||
|
#
|
||||||
|
cdir=$(pwd)
|
||||||
|
clear
|
||||||
|
printf "Digital Speech Decoder: Florida Man Edition - Auto Installer For Cygwin\n
|
||||||
|
This will install the required packages, clone, build, and install DSD-FME only.
|
||||||
|
This has been tested on Cygwin x86-64 as of 20250211. This may take a while!\n
|
||||||
|
MBELib is considered a requirement on this build.
|
||||||
|
You must view the Patent Notice prior to continuing.
|
||||||
|
The Patent Notice can be found at the site below.
|
||||||
|
https://github.com/lwvmobile/mbelib#readme
|
||||||
|
Please confirm that you have viewed the patent notice by entering y below.\n\n"
|
||||||
|
read -p "Have you viewed the patent notice? y/N " ANSWER
|
||||||
|
ANSWER=$(printf "$ANSWER"|tr '[:upper:]' '[:lower:]')
|
||||||
|
if [ "$ANSWER" = "y" ]; then
|
||||||
|
|
||||||
|
#is this needed?
|
||||||
|
LD_LIBRARY_PATH=/usr/local/lib
|
||||||
|
export LD_LIBRARY_PATH
|
||||||
|
echo $LD_LIBRARY_PATH
|
||||||
|
|
||||||
|
#MBELIB
|
||||||
|
cd $cdir
|
||||||
|
printf "Installing mbelib\n Please wait!\n"
|
||||||
|
git clone https://github.com/lwvmobile/mbelib.git
|
||||||
|
cd mbelib
|
||||||
|
git checkout ambe_tones
|
||||||
|
mkdir build
|
||||||
|
cd build
|
||||||
|
cmake ..
|
||||||
|
make -j $(nproc)
|
||||||
|
make install
|
||||||
|
cp cygmbe-1.dll /bin
|
||||||
|
|
||||||
|
#CODEC2
|
||||||
|
cd $cdir
|
||||||
|
printf "Installing codec2\n Please wait!\n"
|
||||||
|
git clone https://github.com/drowe67/codec2.git
|
||||||
|
cd codec2
|
||||||
|
mkdir build
|
||||||
|
cd build
|
||||||
|
cmake ..
|
||||||
|
make -j $(nproc)
|
||||||
|
make install
|
||||||
|
|
||||||
|
#RTL-SDR
|
||||||
|
cd $cdir
|
||||||
|
printf "Installing RTL-SDR\n Please wait!\n"
|
||||||
|
git clone https://github.com/lwvmobile/rtl-sdr.git
|
||||||
|
cd rtl-sdr
|
||||||
|
mkdir build
|
||||||
|
cd build
|
||||||
|
cmake ..
|
||||||
|
make -j $(nproc)
|
||||||
|
make install
|
||||||
|
|
||||||
|
#DSD-FME
|
||||||
|
cd $cdir
|
||||||
|
printf "Installing DSD-FME\n Please wait!\n"
|
||||||
|
git clone https://github.com/lwvmobile/dsd-fme.git
|
||||||
|
cd dsd-fme
|
||||||
|
#git checkout aw_dev
|
||||||
|
mkdir build
|
||||||
|
cd build
|
||||||
|
cmake -DCOLORSLOGS=OFF ..
|
||||||
|
make -j $(nproc)
|
||||||
|
make install
|
||||||
|
cd $cdir
|
||||||
|
|
||||||
|
#call the cyg_portable script
|
||||||
|
sh dsd-fme/cyg_portable.sh
|
||||||
|
|
||||||
|
printf "Any issues, Please report to either:\nhttps://github.com/lwvmobile/dsd-fme/issues or\nhttps://forums.radioreference.com/threads/dsd-fme.438137/\n\n"
|
||||||
|
|
||||||
|
else
|
||||||
|
printf "Sorry, you cannot build DSD-FME without acknowledging the Patent Notice.\n\n"
|
||||||
|
fi
|
||||||
17
download-and-install-nodeps.sh
Normal file
17
download-and-install-nodeps.sh
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
#! /bin/bash
|
||||||
|
clear
|
||||||
|
printf "\nDigital Speech Decoder: Florida Man Edition - Auto Installer\n
|
||||||
|
This will clone, build, and install DSD-FME only.
|
||||||
|
If DSD-FME has never been installed on this machine,
|
||||||
|
then you will need to install the dependencies first!
|
||||||
|
Please run download-and-install.sh instead.\n\n"
|
||||||
|
read -p "Press Enter to continue..." x
|
||||||
|
git clone https://github.com/lwvmobile/dsd-fme
|
||||||
|
cd dsd-fme
|
||||||
|
#git checkout audio_work
|
||||||
|
mkdir build
|
||||||
|
cd build
|
||||||
|
cmake ..
|
||||||
|
make -j $(nproc)
|
||||||
|
sudo make install
|
||||||
|
sudo ldconfig
|
||||||
38
download-and-install-ubuntu2404lts.sh
Normal file
38
download-and-install-ubuntu2404lts.sh
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
#! /bin/bash
|
||||||
|
#
|
||||||
|
cdir=$(pwd)
|
||||||
|
clear
|
||||||
|
printf "Digital Speech Decoder: Florida Man Edition - Auto Installer\n
|
||||||
|
MBELib is considered a requirement on this build.
|
||||||
|
You must view the Patent Notice prior to continuing.
|
||||||
|
The Patent Notice can be found at the site below.
|
||||||
|
https://github.com/lwvmobile/mbelib#readme
|
||||||
|
Please confirm that you have viewed the patent notice by entering y below:\n\n"
|
||||||
|
read -p "Have you viewed the patent notice? y/N " ANSWER
|
||||||
|
ANSWER=$(printf "$ANSWER"|tr '[:upper:]' '[:lower:]')
|
||||||
|
if [ "$ANSWER" = "y" ]; then
|
||||||
|
sudo apt update
|
||||||
|
sudo apt install libpulse-dev libsndfile1-dev libfftw3-dev liblapack-dev socat libusb-1.0-0-dev rtl-sdr librtlsdr-dev libusb-1.0-0-dev cmake git wget make build-essential libncurses-dev libncurses6 libcodec2-dev
|
||||||
|
git clone https://github.com/lwvmobile/mbelib
|
||||||
|
cd mbelib
|
||||||
|
git checkout ambe_tones
|
||||||
|
mkdir build
|
||||||
|
cd build
|
||||||
|
cmake ..
|
||||||
|
make -j $(nproc)
|
||||||
|
sudo make install
|
||||||
|
sudo ldconfig
|
||||||
|
cd $cdir
|
||||||
|
git clone https://github.com/lwvmobile/dsd-fme
|
||||||
|
cd dsd-fme
|
||||||
|
#git checkout audio_work
|
||||||
|
mkdir build
|
||||||
|
cd build
|
||||||
|
cmake ..
|
||||||
|
make -j $(nproc)
|
||||||
|
sudo make install
|
||||||
|
sudo ldconfig
|
||||||
|
else
|
||||||
|
printf "\nSorry, you cannot build DSD-FME without acknowledging the Patent Notice.\nExiting...\n\n"
|
||||||
|
exit 2
|
||||||
|
fi
|
||||||
38
download-and-install.sh
Normal file
38
download-and-install.sh
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
#! /bin/bash
|
||||||
|
#
|
||||||
|
cdir=$(pwd)
|
||||||
|
clear
|
||||||
|
printf "Digital Speech Decoder: Florida Man Edition - Auto Installer\n
|
||||||
|
MBELib is considered a requirement on this build.
|
||||||
|
You must view the Patent Notice prior to continuing.
|
||||||
|
The Patent Notice can be found at the site below.
|
||||||
|
https://github.com/lwvmobile/mbelib#readme
|
||||||
|
Please confirm that you have viewed the patent notice by entering y below:\n\n"
|
||||||
|
read -p "Have you viewed the patent notice? y/N " ANSWER
|
||||||
|
ANSWER=$(printf "$ANSWER"|tr '[:upper:]' '[:lower:]')
|
||||||
|
if [ "$ANSWER" = "y" ]; then
|
||||||
|
sudo apt update
|
||||||
|
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 libncursesw5-dev libcodec2-dev
|
||||||
|
git clone https://github.com/lwvmobile/mbelib
|
||||||
|
cd mbelib
|
||||||
|
git checkout ambe_tones
|
||||||
|
mkdir build
|
||||||
|
cd build
|
||||||
|
cmake ..
|
||||||
|
make -j $(nproc)
|
||||||
|
sudo make install
|
||||||
|
sudo ldconfig
|
||||||
|
cd $cdir
|
||||||
|
git clone https://github.com/lwvmobile/dsd-fme
|
||||||
|
cd dsd-fme
|
||||||
|
#git checkout audio_work
|
||||||
|
mkdir build
|
||||||
|
cd build
|
||||||
|
cmake ..
|
||||||
|
make -j $(nproc)
|
||||||
|
sudo make install
|
||||||
|
sudo ldconfig
|
||||||
|
else
|
||||||
|
printf "\nSorry, you cannot build DSD-FME without acknowledging the Patent Notice.\nExiting...\n\n"
|
||||||
|
exit 2
|
||||||
|
fi
|
||||||
BIN
dsd-fme2.png
Normal file
BIN
dsd-fme2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 725 KiB |
BIN
dsd-fme3.png
Normal file
BIN
dsd-fme3.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 109 KiB |
74
examples/Audio_Plumbing.md
Normal file
74
examples/Audio_Plumbing.md
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
|
||||||
|
|
||||||
|
## Audio Plumbing
|
||||||
|
|
||||||
|
While using DSD-FME to demodulate and decode RF Audio, you will find it necessary to properly plumb (or route) audio from each input source and output sink properly. This mini tutorial aims to help you do such when using Pulse Audio.
|
||||||
|
|
||||||
|
You will first want to locate and run the virtualsink.sh script file via `sh virtualsink.sh` command. This will create two null-sink, or 'virtual sinks' for us to plumb audio from point A to point B.
|
||||||
|
|
||||||
|
Here are screenshots of a proper setup using pavucontrol, or "Pulse Audio Volume Control", having voice input from the encoder listening to your microphone, the RF Output going into the "Virtual_Sink" null-sink, and on the playback side, playing back voice to our speakers, with RF modulated audio being monitored on "Virtual-Sink" null-sink.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
The general idea is that we want to route RF modulated audio into our Virtual_Sink and have our decoder listen to the same sink. Voice Output should always be to Audio Hardware (speakers, headphones, etc).
|
||||||
|
|
||||||
|
Note, that using the virtualsink.sh will create these sinks for us for the duration of your computers boot. If you reboot, they will not persist. Configuration files can be modified to always have these sinks available, or the `virtualsink.sh` script can be executed on login, but you must do so at your own risk and own research, it is out of the scope of this tutorial to create persistent sinks.
|
||||||
|
|
||||||
|
In case of the usage of a headless environment and pavucontrol is not viable, you may use alternatives such as pulsemixer which is similar in functionality, just as a CLI tool and not a GUI tool.
|
||||||
|
|
||||||
|
Users can now use the `-O` CLI argument to list out all pulse audio input sources and output sinks and pass an optional argument alongside `pulse`, appending the name or index number to select the device each time. This method will work in both Linux environments as well as Cygwin builds (making sure to start the pulseaudio.exe server in the back first with the specified .bat file or command, see below).
|
||||||
|
|
||||||
|
For Example:
|
||||||
|
|
||||||
|
The Output (truncated) of `dsd-fme -O`
|
||||||
|
|
||||||
|
```
|
||||||
|
=======[ Output Device #1 ]=======
|
||||||
|
Description: Family 17h (Models 00h-0fh) HD Audio Controller Analog Stereo
|
||||||
|
Name: alsa_output.pci-0000_0d_00.3.analog-stereo
|
||||||
|
Index: 1
|
||||||
|
|
||||||
|
=======[ Output Device #4 ]=======
|
||||||
|
Description: Virtual_Sink1
|
||||||
|
Name: virtual_sink1
|
||||||
|
Index: 4
|
||||||
|
|
||||||
|
=======[ Output Device #5 ]=======
|
||||||
|
Description: Virtual_Sink2
|
||||||
|
Name: virtual_sink2
|
||||||
|
Index: 5
|
||||||
|
|
||||||
|
=======[ Input Device #2 ]=======
|
||||||
|
Description: Family 17h (Models 00h-0fh) HD Audio Controller Analog Stereo
|
||||||
|
Name: alsa_input.pci-0000_0d_00.3.analog-stereo
|
||||||
|
Index: 2
|
||||||
|
|
||||||
|
=======[ Input Device #5 ]=======
|
||||||
|
Description: Monitor of Virtual_Sink1
|
||||||
|
Name: virtual_sink1.monitor
|
||||||
|
Index: 5
|
||||||
|
|
||||||
|
=======[ Input Device #6 ]=======
|
||||||
|
Description: Monitor of Virtual_Sink2
|
||||||
|
Name: virtual_sink2.monitor
|
||||||
|
Index: 6
|
||||||
|
```
|
||||||
|
|
||||||
|
You might use any of the following for input and output options:
|
||||||
|
|
||||||
|
```
|
||||||
|
-i pulse
|
||||||
|
-i pulse:6
|
||||||
|
-i pulse:virtual_sink2.monitor
|
||||||
|
|
||||||
|
-o pulse
|
||||||
|
-o pulse:1
|
||||||
|
-o pulse:alsa_output.pci-0000_0d_00.3.analog-stereo
|
||||||
|
```
|
||||||
|
|
||||||
|
Something to keep in mind is that often times, you only need to set these values once, as a pulse audio server (or plugin) can often times remember these settings, even across reboots, as long as the same hardware is present for future use (real or null-sink).
|
||||||
|
|
||||||
|
<!-- TODO: Add This later -->
|
||||||
|
<!-- Cygwin Note: Running the supplied `0p - start-pulse-audio-backend.bat` file will not only start up the pulse audio server for you, but also setup your null-sinks, and enumerate all devices for you to use, making it an easy selection for your start up .bat files. See any notes in the precomplied .zip file for more information. -->
|
||||||
319
examples/Example_Usage.md
Normal file
319
examples/Example_Usage.md
Normal file
@@ -0,0 +1,319 @@
|
|||||||
|
### 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. To use other decoding methods which cannot be auto detected, please use the following command line switches.
|
||||||
|
|
||||||
|
```
|
||||||
|
-ft XDMA decoder class (P25p1 and p2, YSF, 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
|
||||||
|
-fh EDACS Standard / Network
|
||||||
|
-fH EDACS Standard / Network with ESK
|
||||||
|
-fe EDACS Extended Addresssing
|
||||||
|
-fE EDACS Extended Addressing with ESK
|
||||||
|
-fm dPMR, also may need to use -xd if inverted dPMR.
|
||||||
|
-f1 P25P1
|
||||||
|
-f2 P25P2 (may need to specify wacn/sys/nac manually if traffic channel)
|
||||||
|
-fx X2-TDMA
|
||||||
|
-fy YSF
|
||||||
|
-fz M17 Stream
|
||||||
|
```
|
||||||
|
|
||||||
|
## Conventional Frequency Scanner
|
||||||
|
This feature is used to allow DSD-FME to use RIGCTL or RTL input and cycle through frequencies to attain a frame sync.
|
||||||
|
|
||||||
|
This works almost identically to how the trunkng methods work, but instead of locking onto a control channel and tuning based on its decoding, it tunes through all loaded frequencies in a CSV file and stops when it finds a frame sync. This method is meant for loading a bunch of conventional non-trunking frequencies that signal only when voice or short data bursts are present (DMR T2, Conventional P25 P1, Conventional NXDN, etc) and decode them until the frame sync stops and then resume its scan. This method uses SDR++ RIGCTL, or RTL internal handling to go through signal. -Y is the scan switch. Note: This method will NOT perform at a level similar to a real hardware scanner, SDR tuning is not nearly as fast or reliable at locking onto signal.
|
||||||
|
|
||||||
|
To scan through a mixture of DMR and P25 Conventional, use:
|
||||||
|
`dsd-fme -i tcp -C channel_map.csv -G group.csv -Y -U 4532 -N 2> log.ans`
|
||||||
|
|
||||||
|
To scan through NXDN48 only conventional, use:
|
||||||
|
`dsd-fme -fi -i tcp -C channel_map.csv -Y -U 4532 -N 2> log.ans`
|
||||||
|
|
||||||
|
To scan through NXDN96 only conventional, use:
|
||||||
|
`dsd-fme -fn -i tcp -C channel_map.csv -Y -U 4532 -N 2> log.ans`
|
||||||
|
|
||||||
|
The Channel Map setup will be identical to any of the channel maps found for trunking systems, channel numbers do not matter and can be arbitrarily organized, and frequencies can be duplicated to be 'scanned' more frequently in larger CSV files. Scan speed by default is 1 second, and is most stable at that speed. This can be adjusted by using the `-t 2` option, for example, to specify 2 seconds of hang time per frequency. ~~If activity occurs on a frequency, an additional 2 seconds of 'hangtime' will occur on that frequency for any follow up voice activity.~~ Using `-t 0` will forego the one second wait time, and this can work in some situations, but is not advised as it may skip during the middle of transmissions, or skip over them entirely without a framesync.
|
||||||
|
|
||||||
|
Please Note: DMR Simplex may not behave well on scan, I have not been able to test it as such, but given the nature of the on-off timeslot signalling on DMR Simplex, missed frame syncs and skipping/resuming scan may occur.
|
||||||
|
|
||||||
|
## 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`
|
||||||
|
|
||||||
|
### Audio Plumbing
|
||||||
|
|
||||||
|
Please see [Audio Plumbing](https://github.com/lwvmobile/dsd-fme/blob/aw_dev/examples/Audio_Plumbing.md "Audio Plumbing") for general help with audio plumbing (routing from A to B).
|
||||||
|
|
||||||
|
### 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
|
||||||
|
Short Setup (all default values):
|
||||||
|
|
||||||
|
`dsd-fme -i rtl`
|
||||||
|
|
||||||
|
Detailed Setup:
|
||||||
|
|
||||||
|
`dsd-fme -ft -i rtl:0:154.9875M:26:-2:8:0:6020 `
|
||||||
|
|
||||||
|
```
|
||||||
|
RTL-SDR options:
|
||||||
|
Usage: rtl:dev:freq:gain:ppm:bw:sq:vol
|
||||||
|
NOTE: all arguments after rtl are optional now for trunking, but user configuration is recommended
|
||||||
|
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 = 0; Hardware AGC recommended)
|
||||||
|
ppm <num> RTL-SDR PPM Error (default = 0)
|
||||||
|
bw <num> RTL-SDR Bandwidth kHz (default = 12)(8, 12, 16, 24)
|
||||||
|
sq <num> RTL-SDR Squelch Level vs RMS Value (Optional)
|
||||||
|
vol <num> RTL-SDR Sample 'Volume' Multiplier (default = 2)(1,2,3)
|
||||||
|
Example: dsd-fme -fs -i rtl -C cap_plus_channel.csv -T
|
||||||
|
Example: dsd-fme -fp -i rtl:0:851.375M:22:-2:24:0:2
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
## 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++ (see switches above for STD/NET, EA, and ESK modes)
|
||||||
|
|
||||||
|
`dsd-fme -i tcp -fE -C channel_map.csv -G group.csv -T -U 4532 -N 2> log.ans`
|
||||||
|
|
||||||
|
--NXDN48 Trunking (Direct Frequency Assignment) 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 (QPSK) 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 QPSK (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: QPSK Phase 1 and Phase 2 Systems may be 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 style LSN-esque numbering 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 lpcn (12-bit logical physical channel number - decimal format) values from the log, and not the LPCN+TS (13-bit DSDPlus LSN) values. Notice: TIII Site ID value needs work to determine proper DMRLA values for system area and sub area.
|
||||||
|
|
||||||
|
```
|
||||||
|
00:43:00 Sync: +DMR [slot1] slot2 | Color Code=00 | CSBK
|
||||||
|
Talkgroup Voice Channel Grant (TV_GRANT) - Logical
|
||||||
|
LPCN: 0075; TS: 2; LPCN+TS: 0152; Target: 16518173 - Source: 16533625
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
Use channel 75 in your import file, which would correspond to dsdplus channels 151 and 152 (151 = TS1 / 152 = TS2).
|
||||||
|
|
||||||
|
For Connect Plus, enumerate your list from 1 to the last channel and add the frequency. For Capacity Plus, LSN 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 'channel' as two seperate channels (LSN), 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 may lose the rest channel and will have to hunt through all frequencies to find it again.
|
||||||
|
|
||||||
|
Trunking Note4: NXDN Trunking v1 will require a channel map. Please see the example folder for an appropriate channel map. NOTICE: NXDN trunking has been fixed on the RTL (rtl_fm) input method and works correctly now using a soft squelch value to determine when to look for frame sync. Tests show this works very well, but squelch adjustments may be required to differentiate the noise floor from the signal.
|
||||||
|
|
||||||
|
NXDN Trunking Update: NXDN DFA (Direct Frequency Assignment) has been coded from the v2 documents, so using a channel map may not be required, as long as the DFA is configured with standard values, and not 'system definable' values. This will only work on trunking systems that use DFA (newer systems) in accordance to the v2 CAI document NXDN TS 1-A Version 2.0 September 2016. If the system uses 'system definable' values, then make sure to put the channels in a channel map csv file as as the 16-bit OFN values for proper tuning.
|
||||||
|
|
||||||
|
NXDN Type-D/IDAS Update: Type-D or IDAS decoding/trunking has been coded now and tested on a small two channel system. Set up a channel map much like Type-C trunking. If preferred, insert channel 31 at the top of your channel map for the 'home repeater' or go to channel of choice during a TX_REL or DISC message. Extensive testing of Type-D has not been conducted. Some cavaets may currently include iffy per call wav file saving and potentially shifting SRC and TGT ID values due to how SCCH messages are handled and how Busy Repeater Messages are handled. Private calls will need to be enabled by enabling 'data calls', if desired. During testing, only data calls came on private calls, so this was set to disabled by default, but can be enabled with data calls enabled. Also, note that some home repeater channels may or may not carry calls from all systems.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
Hytera XPT: Code has been added for XPT system slco/flco/csbk decoding and trunking. The setup will be similar to Capacity Plus trunking in the csv file, listing each LSN channel to a frequency (see examples/hytera_xpt_chan.csv). Currently, this set up is working with smaller XPT systems that I have been able to test with.
|
||||||
|
|
||||||
|
## 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 - cycle event history short, long, or off
|
||||||
|
z - toggle console payloads
|
||||||
|
a - toggle call alert beep
|
||||||
|
4 - force privacy/scrambler key assertion over enc identifiers (dmr and nxdn)
|
||||||
|
6 - force rc4 key assertion over missing pi header/le enc identifiers (dmr)
|
||||||
|
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 (lower s)
|
||||||
|
P - start per call decoded wav files (Capital P)
|
||||||
|
p - stop per call decoded wav files (lower p)
|
||||||
|
t - toggle trunking (needs either rtl input, or rigctl connection)
|
||||||
|
y - toggle scanner (needs either rtl input, or rigctl connection)
|
||||||
|
1 - Toggle Voice Synthesis in TDMA Slot 1 or FDMA Conventional Voice
|
||||||
|
2 - Toggle Voice Synthesis in TDMA Slot 2
|
||||||
|
w - Toggle Trunking/Playback White List (Allow A Groups Only) / Black List (Block B or DE groups only) Mode
|
||||||
|
T - Toggle Trunking Tuning to Group Calls (DMR T3, Con+, Cap+, P25, NXDN)
|
||||||
|
u - Toggle Trunking Tuning to Private Calls (DMR T3, Cap+, P25)
|
||||||
|
d - Toggle Trunking Tuning to Data Calls (DMR T3, NXDN)
|
||||||
|
e - Toggle Trunking Tuning to Encrypted Calls (P25)
|
||||||
|
8 - Connect to SDR++ TCP Audio Sink with Defaults/Retry Sink Connection on Disconnect
|
||||||
|
9 - Connect to SDR++ RIGCTL Server with Defaults/Retry RIGCTL Connection
|
||||||
|
D - Reset DMR Site Parms/Call Strings, etc.
|
||||||
|
Z - Simulate NoCarrier/No VC/CC sync (capital Z)
|
||||||
|
|
||||||
|
! - Lockout Tuning/Playback of TG in Slot 1 or Conventional -- Current Session Only if no group.csv file specified
|
||||||
|
@ - Lockout Tuning/Playback of TG in Slot 2 -- Current Session Only if no group.csv file specified
|
||||||
|
|
||||||
|
k - Hold TG in Slot 1 or Conventional, or clear current hold
|
||||||
|
l - Hold TG in Slot 2 on TDMA Systems, or clear current hold
|
||||||
|
|
||||||
|
C - Drop Call and Return to CC during trunking operation
|
||||||
|
L - Manual Cycle Forward Channel Tuned when RIGCTL or using RTL input and channel csv loaded
|
||||||
|
|
||||||
|
S - Toggle between EDACS Standard/Network and Extended Addressing mode (Capital S)
|
||||||
|
A - Toggle EDACS ESK Mask (none vs A0)
|
||||||
|
|
||||||
|
H - Toggle High Pass Filter on Digital Sythesized Voice
|
||||||
|
V - Toggle Low Pass Filter on Analog Voice or Raw Signal Monitoring
|
||||||
|
B - Toggle High Pass Filter on Analog Voice or Raw Signal Monitoring
|
||||||
|
N - Toggle Passband Filter on Analog Voice or Raw Signal Monitoring
|
||||||
|
|
||||||
|
[ - Scroll backwards through Event History
|
||||||
|
] - Scroll forwards through Event History
|
||||||
|
\ - Switch between Slot 1 and Slot 2 Event History
|
||||||
|
|
||||||
|
v - Cycle RTL Input Volume Multiplier 1X, 2X, 3X (lower v)
|
||||||
|
|
||||||
|
g - Manually decrease RTL gain
|
||||||
|
G - Manually increase RTL gain
|
||||||
|
|
||||||
|
{ - Manually decrease PPM
|
||||||
|
} - Manually increase PPM
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
## Sending Audio to a Icecast 2 Server via FFmpeg (Windows)
|
||||||
|
|
||||||
|
Make sure to enable "Stereo Mix" from Volume Control Panel and then disable Windows Sounds.
|
||||||
|
|
||||||
|
```
|
||||||
|
ffmpeg -f dshow -i audio="Stereo Mix (Realtek High Definition Audio)" -c:a aac -b:a 64k -content_type 'audio/aac' -vn -f adts icecast://source:password@192.168.5.251:8844/DSDFME
|
||||||
|
```
|
||||||
|
|
||||||
|
## Sending Audio to a Icecast 2 Server via FFmpeg (Linux w/ Pulse Audio)
|
||||||
|
|
||||||
|
`pactl list short sources`
|
||||||
|
|
||||||
|
Choose Desired Device to Cast:
|
||||||
|
|
||||||
|
```
|
||||||
|
0 auto_null.monitor module-null-sink.c s16le 2ch 48000Hz IDLE
|
||||||
|
1 alsa_output.pci-0000_0d_00.3.analog-stereo.monitor module-alsa-card.c s16le 2ch 44100Hz RUNNING
|
||||||
|
2 alsa_input.pci-0000_0d_00.3.analog-stereo module-alsa-card.c s16le 2ch 44100Hz RUNNING
|
||||||
|
3 virtual_sink.monitor module-null-sink.c s16le 2ch 44100Hz RUNNING
|
||||||
|
4 virtual_sink2.monitor module-null-sink.c s16le 2ch 44100Hz RUNNING
|
||||||
|
7 alsa_output.pci-0000_0b_00.1.hdmi-stereo-extra1.monitor module-alsa-card.c s16le 2ch 44100Hz RUNNING
|
||||||
|
```
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
```
|
||||||
|
francis@12cores:~$ pactl list short sources
|
||||||
|
0 auto_null.monitor module-null-sink.c s16le 2ch 48000Hz IDLE
|
||||||
|
francis@12coresx:~$ ffmpeg -f pulse -i 0 -c:a libmp3lame -ab 64k -f mp3 icecast://source:password@XXXXXXXXX:8000
|
||||||
|
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
Note: Do not run this command for ffmpeg/icecast piped to the main dsd-fme command, make sure these are running in seperate terminals.
|
||||||
|
|
||||||
|
## Sending Audio to UDP Target/Port
|
||||||
|
|
||||||
|
Audio can be sent to a target address on your local area network with the UDP blaster using the `-o udp:targetaddress:port` option.
|
||||||
|
Note: Any analog audio monitoring will not function properly over UDP port (rate difference issues)
|
||||||
|
|
||||||
|
Example (Short 8k/2):
|
||||||
|
`dsd-fme -fs -o udp:192.168.7.8:23470`
|
||||||
|
|
||||||
|
Receiving End (Short 8k/2):
|
||||||
|
`socat stdio udp-listen:23470 | play --buffer 640 -q -b 16 -r 8000 -c2 -t s16 -`
|
||||||
|
|
||||||
|
Example (Short 8k/1):
|
||||||
|
`dsd-fme -f1 -o udp:192.168.7.8:23469`
|
||||||
|
|
||||||
|
Receiving End (Short 8k/1):
|
||||||
|
`socat stdio udp-listen:23469 | play --buffer 320 -q -b 16 -r 8000 -c1 -t s16 -`
|
||||||
|
|
||||||
|
Example (Float 8k/2):
|
||||||
|
`dsd-fme -ft -y -o udp:192.168.7.8:23468`
|
||||||
|
|
||||||
|
Receiving End (Float 8k/2):
|
||||||
|
`socat stdio udp-listen:23468 | play --buffer 1280 -q -b 16 -r 8000 -c2 -t f32 -`
|
||||||
|
|
||||||
|
Example (Float 8k/1):
|
||||||
|
`dsd-fme -fi -y -o udp:192.168.7.8:23467`
|
||||||
|
|
||||||
|
Receiving End (Float 8k/1):
|
||||||
|
`socat stdio udp-listen:23467 | play --buffer 640 -q -b 16 -r 8000 -c1 -t f32 -`
|
||||||
|
|
||||||
|
Note: --buffer option in play is calculated by (channels * samples * sizeof(samples)),
|
||||||
|
where samples is 160 for mono, 320 for stereo, and short samples are 2 and float samples are 4.
|
||||||
|
This is vital to prevent 'lag' or cut-off audio when the UDP audio doesn't fill the default buffer size.
|
||||||
|
|
||||||
|
Note2: Be sure to start the receiving end AFTER starting DSD-FME. If DSD-FME is restarted, make sure to restart the receiving end as well, as socat/UDP closes the UDP port listening when DSD-FME closes the UDP socket.
|
||||||
|
|
||||||
|
Note3: socat version 1.8 may have a `E xioopen_ipdgram_listen(): unknown address family 0` problem, downgrading to 1.7.4 is recommended if this occurs. `sudo downgrade socat`.
|
||||||
|
|
||||||
|
## Record 48k/1 audio with rtl_fm
|
||||||
|
|
||||||
|
You can record suitable audio to feed as input to dsd-fme with `-i` using rtl_fm:
|
||||||
|
|
||||||
|
`rtl_fm -M nfm -f [FREQ] -s 48k -g 42 -l 20 > input.wav`
|
||||||
|
|
||||||
|
You can also combine that with `socat` to send the audio to a remote dsd-fme instance in real time while keeping a local copy on the host where the RTL-SDR dongle is:
|
||||||
|
|
||||||
|
`rtl_fm -M fm -f [FREQ] -s 48k -g 42 -l 20 | tee input.wav | socat -u - TCP-LISTEN:1234,forever,reuseaddr`
|
||||||
|
|
||||||
|
On the remote side where dsd-fme is, use the TCP input:
|
||||||
|
|
||||||
|
`dsd-fme -i tcp:192.168.7.8:1234 -N`
|
||||||
|
|
||||||
|
Note: As always, when using rtl_fm, play with `-l` and `-g` to find a good squelch and gain values for your environment - you will know if the squelch is the right value when `input.wav` does not increase in size in the absence of useful signal on the monitored frequency.
|
||||||
225
examples/Install_Notes.md
Normal file
225
examples/Install_Notes.md
Normal file
@@ -0,0 +1,225 @@
|
|||||||
|
## How to clone and build this branch
|
||||||
|
|
||||||
|
### Ubuntu 22.04/20.04/LM20/Debian Bullseye:
|
||||||
|
|
||||||
|
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 23.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/audio_work/download-and-install.sh
|
||||||
|
sh download-and-install.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
### Debian 12 (SID) / Ubuntu 24.04 LTS (Updated Ncurses Dependencies)
|
||||||
|
|
||||||
|
```
|
||||||
|
wget https://raw.githubusercontent.com/lwvmobile/dsd-fme/audio_work/download-and-install-ubuntu2404lts.sh
|
||||||
|
sh download-and-install-ubuntu2404lts.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
### Arch Based Distros:
|
||||||
|
|
||||||
|
```
|
||||||
|
wget https://raw.githubusercontent.com/lwvmobile/dsd-fme/audio_work/download-and-install-Arch.sh
|
||||||
|
sh download-and-install-Arch.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
### Other:
|
||||||
|
|
||||||
|
If you have dependencies already installed, please run this instead:
|
||||||
|
|
||||||
|
```
|
||||||
|
wget https://raw.githubusercontent.com/lwvmobile/dsd-fme/audio_work/download-and-install-nodeps.sh
|
||||||
|
sh download-and-install-nodeps.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
## 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.
|
||||||
|
|
||||||
|
Debian/Mint/Ubuntu/Pi
|
||||||
|
|
||||||
|
```
|
||||||
|
sudo apt update
|
||||||
|
#Ubuntu 22.04 lts / Debian 11 and lower
|
||||||
|
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 libcodec2-dev
|
||||||
|
#Ubuntu 24.04 lts / Debian 12
|
||||||
|
#sudo apt install libpulse-dev pavucontrol libsndfile1-dev libfftw3-dev liblapack-dev socat libusb-1.0-0-dev rtl-sdr librtlsdr-dev libusb-1.0-0-dev cmake git wget make build-essential libncurses-dev libncurses6 libcodec2-dev
|
||||||
|
```
|
||||||
|
|
||||||
|
Fedora 36/37 -- from https://github.com/lwvmobile/dsd-fme/issues/99
|
||||||
|
|
||||||
|
```
|
||||||
|
sudo dnf update
|
||||||
|
sudo dnf install libsndfile-devel fftw-devel lapack-devel rtl-sdr-devel pulseaudio-libs-devel libusb-devel cmake git ncurses ncurses-devel gcc wget pavucontrol gcc-c++ codec2-devel
|
||||||
|
```
|
||||||
|
|
||||||
|
Arch -- https://github.com/lwvmobile/dsd-fme/issues/153 and https://github.com/lwvmobile/dsd-fme/issues/153
|
||||||
|
|
||||||
|
```
|
||||||
|
sudo pacman -Syu
|
||||||
|
sudo pacman -S libpulse cmake ncurses lapack perl fftw rtl-sdr codec2 base-devel libsndfile git wget rtl-sdr
|
||||||
|
```
|
||||||
|
|
||||||
|
## Headless Ubuntu Server/Pi
|
||||||
|
|
||||||
|
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 libncursesw5-dev pulsemixer pulseaudio libcodec2-dev
|
||||||
|
```
|
||||||
|
|
||||||
|
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")
|
||||||
|
|
||||||
|
```
|
||||||
|
git clone https://github.com/lwvmobile/mbelib
|
||||||
|
git checkout ambe_tones
|
||||||
|
cd mbelib
|
||||||
|
mkdir build
|
||||||
|
cd build
|
||||||
|
cmake ..
|
||||||
|
make -j `nproc`
|
||||||
|
sudo make install
|
||||||
|
sudo ldconfig
|
||||||
|
cd ..
|
||||||
|
cd ..
|
||||||
|
```
|
||||||
|
|
||||||
|
Finish by running these steps to clone and build DSD-FME.
|
||||||
|
|
||||||
|
```
|
||||||
|
git clone https://github.com/lwvmobile/dsd-fme
|
||||||
|
cd dsd-fme
|
||||||
|
mkdir build
|
||||||
|
cd build
|
||||||
|
cmake ..
|
||||||
|
make -j `nproc`
|
||||||
|
sudo make install
|
||||||
|
sudo ldconfig
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
### LD_PATH
|
||||||
|
|
||||||
|
Some environments may require an LD path to be set to /usr/local/lib, similar to:
|
||||||
|
```
|
||||||
|
LD_LIBRARY_PATH=/usr/local/lib
|
||||||
|
export LD_LIBRARY_PATH
|
||||||
|
```
|
||||||
|
|
||||||
|
### macOS Builds (Homebrew)
|
||||||
|
|
||||||
|
Building on macOS (Apple Silicon) using [Homebrew](https://brew.sh "Homebrew") for dependencies has been tested working, but keep in mind this project is primarily focused on Linux, so macOS support should be considered experimental. Unlike the Linux steps above, macOS has no `ldconfig`, so simply skip that step wherever it appears below.
|
||||||
|
|
||||||
|
Install dependencies first:
|
||||||
|
|
||||||
|
```
|
||||||
|
brew install cmake git libsndfile pulseaudio rtl-sdr codec2 ncurses pkg-config
|
||||||
|
```
|
||||||
|
|
||||||
|
Note: Homebrew's ncurses is keg-only (not symlinked into /opt/homebrew), so we will pass an extra CMake flag when configuring DSD-FME below so it can be found.
|
||||||
|
|
||||||
|
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")
|
||||||
|
|
||||||
|
```
|
||||||
|
git clone https://github.com/lwvmobile/mbelib
|
||||||
|
cd mbelib
|
||||||
|
git checkout ambe_tones
|
||||||
|
mkdir build
|
||||||
|
cd build
|
||||||
|
cmake ..
|
||||||
|
make -j `sysctl -n hw.ncpu`
|
||||||
|
sudo make install
|
||||||
|
cd ../..
|
||||||
|
```
|
||||||
|
|
||||||
|
Finish by cloning and building DSD-FME (note the added -DCMAKE_PREFIX_PATH flag for keg-only ncurses):
|
||||||
|
|
||||||
|
```
|
||||||
|
git clone https://github.com/lwvmobile/dsd-fme
|
||||||
|
cd dsd-fme
|
||||||
|
mkdir build
|
||||||
|
cd build
|
||||||
|
cmake .. -DCMAKE_PREFIX_PATH=$(brew --prefix ncurses)
|
||||||
|
make -j `sysctl -n hw.ncpu`
|
||||||
|
sudo make install
|
||||||
|
```
|
||||||
|
|
||||||
|
Pulse Audio is still the default input/output in DSD-FME, so start the Homebrew Pulse Audio daemon before running dsd-fme (it will also restart at login): `brew services start pulseaudio`. To confirm your RTL-SDR dongle is detected, run `rtl_test` (ships with Homebrew's rtl-sdr package); unlike Linux, there is no driver blacklist to deal with on macOS.
|
||||||
|
|
||||||
|
### Windows Cygwin Builds
|
||||||
|
|
||||||
|
Cygwin builds now have an experimental semi-automatic installer, to run, follow steps below:
|
||||||
|
|
||||||
|
Open Windows PowerShell (not Command Prompt) and copy and paste all of this in all at once.
|
||||||
|
|
||||||
|
```
|
||||||
|
Invoke-WebRequest https://cygwin.com/setup-x86_64.exe -OutFile setup-x86_64.exe
|
||||||
|
.\setup-x86_64.exe --packages nano,libpulse-devel,libpulse-mainloop-glib0,libpulse-simple0,libpulse0,pulseaudio,pulseaudio-debuginfo,pulseaudio-equalizer,pulseaudio-module-x11,pulseaudio-module-zeroconf,pulseaudio-utils,sox-fmt-pulseaudio,libusb0,libusb1.0,libusb1.0-debuginfo,libusb1.0-devel,libncurses++w10,libncurses-devel,libncursesw10,ncurses,cmake,gcc-core,gcc-debuginfo,gcc-objc,git,make,socat,sox,sox-fmt-ao,zip,unzip,wget,gcc-g++,libsndfile-devel
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
Pick a Mirror. http://www.gtlib.gatech.edu mirror seems relatively fast. Nurse the Cygwin installer by clicking next and waiting for it to finish. Ignore the warning popup telling you to install libusb from sourceforge. Install the [Zadig](https://zadig.akeo.ie/ "Zadig") driver instead, if you haven't already and have an RTL Dongle. After Cygwin finishes installing, the installer sh script will download and run, be patient, it may also take a little while.
|
||||||
|
|
||||||
|
Then:
|
||||||
|
|
||||||
|
```
|
||||||
|
C:\cygwin64\bin\mintty.exe /bin/bash -l -c "wget https://raw.githubusercontent.com/lwvmobile/dsd-fme/refs/heads/audio_work/download-and-install-cygwin.sh; sh download-and-install-cygwin.sh; dsd-fme;"
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
After the sh script finishes, dsd-fme should open. If not, then double click on the Cygwin Terminal desktop shortcut, and try running `dsd-fme`. If you chose to create a portable version, you will find the folder and zip file in the `C:\cygwin64\home\username` directory if using the default cygwin64 folder location.
|
||||||
|
|
||||||
|
You can also update your versions by using the cyg_rebuild.sh script `sh cyg_rebuild.sh`.
|
||||||
|
|
||||||
|
### Virtual Sinks
|
||||||
|
|
||||||
|
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. Note: This setup is completely optional if using TCP Network Sink Audio and/or RTL Input. You may need to manually install either of these programs manually, if desired, or find suitable alternatives for pipewire-pulse such as pwvucontrol, or similar.
|
||||||
|
|
||||||
|
```
|
||||||
|
pactl load-module module-null-sink sink_name=virtual_sink sink_properties=device.description=Virtual_Sink
|
||||||
|
pactl 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
|
||||||
|
```
|
||||||
|
|
||||||
|
### Applying Patches -- Recommended For Advanced Users Only
|
||||||
|
|
||||||
|
More experimental or potentially functionality changing or temperamental features may be included as seperate .patch files inside of the patch folder, and are not included in the source code by default.
|
||||||
|
If users wish to try or use these patches, then they can apply patches and build/rebuild with the following procedure. Make sure you have changed to the dsd-fme directory first, either by the top
|
||||||
|
command, or by otherwise opening the terminal to the clone folder.
|
||||||
|
|
||||||
|
```
|
||||||
|
cd dsd-fme
|
||||||
|
git apply patch/patchname.patch
|
||||||
|
cd build
|
||||||
|
make
|
||||||
|
sudo make install
|
||||||
|
```
|
||||||
|
|
||||||
|
If you later wish to update to the latest version via `git pull`, you may first need to reset any patches, perform the `git pull`, and then reapply patches.
|
||||||
|
A procedure for this is similar to, but not limited to:
|
||||||
|
|
||||||
|
```
|
||||||
|
cd dsd-fme
|
||||||
|
git reset --hard
|
||||||
|
git pull
|
||||||
|
git apply patch/xyz.patch
|
||||||
|
cd build
|
||||||
|
make
|
||||||
|
sudo make install
|
||||||
|
```
|
||||||
|
|
||||||
|
NOTE: Patches can potential break over time with further changes to code, requiring merge resolution or other manual intervention to re-apply patches.
|
||||||
10
examples/capacity_plus_chan.csv
Normal file
10
examples/capacity_plus_chan.csv
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
LSN(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
|
||||||
|
|
||||||
|
19
examples/connect_plus_chan.csv
Normal file
19
examples/connect_plus_chan.csv
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
14
examples/cygwin_bat/9pa-close-pulse-audio-server.bat.old
Normal file
14
examples/cygwin_bat/9pa-close-pulse-audio-server.bat.old
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
@REM Shutdown pulseaudio and clean out any remenants in /dev/shm if left behind
|
||||||
|
|
||||||
|
cd dsd-fme
|
||||||
|
pactl.exe exit
|
||||||
|
|
||||||
|
@REM now navigate to the /dev/shm folder and automatically remove any
|
||||||
|
@REM remnants from other times pulse wasn't shut down properly
|
||||||
|
|
||||||
|
cd ..
|
||||||
|
cd dev
|
||||||
|
cd shm
|
||||||
|
del pulse*
|
||||||
|
|
||||||
|
PAUSE
|
||||||
34
examples/cygwin_bat/9pa-start-pulse-audio-server.bat.old
Normal file
34
examples/cygwin_bat/9pa-start-pulse-audio-server.bat.old
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
@REM Set the console / terminal to 90 columns, 50 lines
|
||||||
|
@REM mode con: cols=90 lines=50
|
||||||
|
|
||||||
|
@ECHO OFF
|
||||||
|
|
||||||
|
@REM change directory into the dsd-fme folder
|
||||||
|
cd dsd-fme
|
||||||
|
|
||||||
|
@REM Start the Pulse Audio backend with a 10 minute time out
|
||||||
|
@REM start pulse audio server with 600 second idle time and no CPU limit (prevent closing while idle in menu)
|
||||||
|
|
||||||
|
@REM output from pulse server routed to NUL to supress "capabilities dropped, nag messages, etc" messages
|
||||||
|
pulseaudio.exe --start --no-cpu-limit=TRUE --exit-idle-time=600 2> NUL
|
||||||
|
|
||||||
|
@REM End pulse start up
|
||||||
|
|
||||||
|
ECHO The Pulse Audio Server should now be active!
|
||||||
|
|
||||||
|
@REM Setup Some null-sinks (if desired, remove @REM below)
|
||||||
|
|
||||||
|
@REM pactl load-module module-null-sink sink_name=virtual_sink1 sink_properties=device.description=Virtual_Sink1
|
||||||
|
@REM pactl load-module module-null-sink sink_name=virtual_sink2 sink_properties=device.description=Virtual_Sink2
|
||||||
|
|
||||||
|
@REM Setup Default Sink to device 0 (output)
|
||||||
|
|
||||||
|
pactl set-default-sink 0
|
||||||
|
|
||||||
|
@REM List Avaiable Pulse Audio Sinks and Sources
|
||||||
|
|
||||||
|
@ECHO ON
|
||||||
|
|
||||||
|
dsd-fme -O
|
||||||
|
|
||||||
|
PAUSE
|
||||||
258
examples/cygwin_bat/complete_usage_options.txt
Normal file
258
examples/cygwin_bat/complete_usage_options.txt
Normal file
@@ -0,0 +1,258 @@
|
|||||||
|
Build Version: AW 2026-47-ga6ea60b
|
||||||
|
MBElib Version: 1.3.4
|
||||||
|
CODEC2 Support Enabled
|
||||||
|
|
||||||
|
Usage: dsd-fme [options] Decoder/Trunking Mode
|
||||||
|
or: dsd-fme [options] -r <files> Read/Play saved mbe data from file(s)
|
||||||
|
or: dsd-fme -h Show help
|
||||||
|
|
||||||
|
Display Options:
|
||||||
|
-N Use NCurses Terminal
|
||||||
|
dsd-fme -N 2> console_log.txt
|
||||||
|
-Z Log MBE/PDU Payloads to console
|
||||||
|
|
||||||
|
Device Options:
|
||||||
|
-O List All Pulse Audio Input Sources and Output Sinks (devices).
|
||||||
|
|
||||||
|
Input/Output options:
|
||||||
|
-i <device> Audio input device (default is pulse)
|
||||||
|
/dev/dsp for OSS audio (Depreciated: Will require padsp wrapper in Linux)
|
||||||
|
pulse for pulse audio signal input
|
||||||
|
pulse:6 or pulse:virtual_sink2.monitor for pulse audio signal input on virtual_sink2 (see -O)
|
||||||
|
rtl for rtl dongle (Default Values -- see below)
|
||||||
|
rtl:dev:freq:gain:ppm:bw:sq:vol for rtl dongle (see below)
|
||||||
|
rtltcp:host:port:freq:gain:ppm:bw:sq:vol for rtl dongle on an rtl_tcp server (see below)
|
||||||
|
tcp for tcp client SDR++/GNURadio Companion/Other (Port 7355)
|
||||||
|
tcp:192.168.7.5:7355 for custom address and port
|
||||||
|
filename.bin for OP25/FME capture bin files
|
||||||
|
filename.wav for 48K/1 wav files (SDR++, GQRX)
|
||||||
|
filename.wav -s 96000 for 96K/1 wav files (DSDPlus)
|
||||||
|
(Use single quotes '/directory/audio file.wav' when directories/spaces are present)
|
||||||
|
-s <rate> Sample Rate of wav input files (48000 or 96000) Mono only!
|
||||||
|
-o <device> Audio output device (default is pulse)
|
||||||
|
/dev/dsp for OSS audio (Depreciated: Will require padsp wrapper in Linux)
|
||||||
|
pulse for pulse audio decoded voice or analog output
|
||||||
|
pulse:1 or pulse:alsa_output.pci-0000_0d_00.3.analog-stereo for pulse audio decoded voice or analog output on device (see -O)
|
||||||
|
null for no audio output
|
||||||
|
udp for UDP socket blaster output (default host 127.0.0.1; default port 23456)
|
||||||
|
udp:192.168.7.8:23470 for UDP socket blaster output (Target Address and Port
|
||||||
|
-d <dir> Create mbe data files, use this directory (TDMA version is experimental)
|
||||||
|
-r <files> Read/Play saved mbe data from file(s)
|
||||||
|
-g <float> Audio Digital Output Gain (Default: 0 = Auto; )
|
||||||
|
(Manual: 1 = 2%; 50 = 100%)
|
||||||
|
-n <float> Audio Analog Output Gain (Default: 0 = Auto; 0-100% )
|
||||||
|
-6 <file> Output raw audio .wav file (48K/1). (WARNING! Large File Sizes 1 Hour ~= 360 MB)
|
||||||
|
-7 <dir> Create/Use Custom directory for Per Call decoded .wav file saving.
|
||||||
|
(Use ./folder for Nested Directory!)
|
||||||
|
(Use /path/to/folder for hard coded directory!)
|
||||||
|
(Use Before the -P option!)
|
||||||
|
-8 Enable Source Audio Monitor
|
||||||
|
(Set Squelch in RTL, SDR++ or GQRX, etc, if monitoring mixed analog/digital)
|
||||||
|
-w <file> Output synthesized speech to a single static .wav file. (Do not use with -P Per Call Switch)
|
||||||
|
-P Enable Per Call WAV file saving. (Do not use with -w filename.wav single wav file switch)
|
||||||
|
(Per Call works with everything now and doesn't require ncurses terminal!)
|
||||||
|
-j <string> Custom Tag(s), colon delimited, to append to Per Call decoded .wav files.
|
||||||
|
-j TGT_LAPD:TAG_FIRE:FREQ_851987500 (Total 3 Tags, Maximum Letter Length = 100)
|
||||||
|
-a Enable Call Alert Beep
|
||||||
|
(Warning! Might be annoying.)
|
||||||
|
-J <file> Specify Filename for Event Log Output.
|
||||||
|
-L <file> Specify Filename for LRRP Data Output.
|
||||||
|
-Q <file> Specify Filename for OK-DMRlib Structured File Output. (placed in DSP folder)
|
||||||
|
-Q <file> Specify Filename for M17 Float Stream Output. (placed in DSP folder)
|
||||||
|
-c <file> Output symbol capture to .bin file
|
||||||
|
-q Reverse Mute - Mute Unencrypted Voice and Unmute Encrypted Voice
|
||||||
|
-V <num> Enable TDMA Voice Synthesis on Slot 1 (1), Slot 2 (2), or Both (3); Default is 3;
|
||||||
|
-z Set TDMA Voice Slot Preference when using /dev/dsp audio output (prevent lag and stuttering)
|
||||||
|
-v <hex> Set Filtering Bitmap Options (Advanced Option)
|
||||||
|
1 1 1 1 (0xF): PBF/LPF/HPF/HPFD on
|
||||||
|
|
||||||
|
RTL-SDR options:
|
||||||
|
Usage: rtl:dev:freq:gain:ppm:bw:sq:vol
|
||||||
|
NOTE: all arguments after rtl are optional now for trunking, but user configuration is recommended
|
||||||
|
dev <num> RTL-SDR Device Index Number or 8 Digit Serial Number, no strings! (default 0)
|
||||||
|
freq <num> RTL-SDR Frequency (851800000 or 851.8M)
|
||||||
|
gain <num> RTL-SDR Device Gain (0-49)(default = 0; Hardware AGC recommended)
|
||||||
|
ppm <num> RTL-SDR PPM Error (default = 0)
|
||||||
|
bw <num> RTL-SDR Bandwidth kHz (default = 12)(4, 6, 8, 12, 16, 24)
|
||||||
|
sq <num> RTL-SDR Squelch Level vs RMS Value (Optional)
|
||||||
|
vol <num> RTL-SDR Sample 'Volume' Multiplier (default = 2)(1,2,3)
|
||||||
|
Example: dsd-fme -fs -i rtl -C cap_plus_channel.csv -T
|
||||||
|
Example: dsd-fme -fp -i rtl:0:851.375M:22:-2:24:0:2
|
||||||
|
Usage: rtltcp:host:port:freq:gain:ppm:bw:sq:vol
|
||||||
|
host <name> rtl_tcp Server Hostname or IP Address (default = localhost)
|
||||||
|
port <num> rtl_tcp Server Port (default = 1234)
|
||||||
|
freq, gain, ppm, bw, sq, vol as above
|
||||||
|
Example: dsd-fme -fs -i rtltcp:192.168.1.10:1234:450M:26:-2:8 -C connect_plus_chan.csv -T
|
||||||
|
|
||||||
|
Decoder options:
|
||||||
|
-fa Auto Detection
|
||||||
|
-fA Passive Analog Audio Monitor
|
||||||
|
-ft TDMA Trunking P25p1 Control and Voice, P25p2 Trunked Channels, and DMR
|
||||||
|
-fs DMR TDMA BS and MS Simplex
|
||||||
|
-f1 Decode only P25 Phase 1
|
||||||
|
-f2 Decode only P25 Phase 2 (6000 sps) **
|
||||||
|
-fd Decode only DSTAR
|
||||||
|
-fx Decode only X2-TDMA
|
||||||
|
-fy Decode only YSF
|
||||||
|
-fz Decode only M17*
|
||||||
|
-fi Decode only NXDN48* (6.25 kHz) / IDAS*
|
||||||
|
-fn Decode only NXDN96* (12.5 kHz)
|
||||||
|
-fp Decode only ProVoice*
|
||||||
|
-fh Decode only EDACS Standard/ProVoice*
|
||||||
|
-fH Decode only EDACS Standard/ProVoice with ESK 0xA0*
|
||||||
|
-fh344 Decode only EDACS Standard/ProVoice and set AFS to 344 or similar custom 11-bit scheme*
|
||||||
|
-fH434 Decode only EDACS Standard/ProVoice and set AFS to custom 11-bit scheme with ESK 0xA0*
|
||||||
|
-fe Decode only EDACS EA/ProVoice*
|
||||||
|
-fE Decode only EDACS EA/ProVoice with ESK 0xA0*
|
||||||
|
-fm Decode only dPMR*
|
||||||
|
-l Disable DMR, dPMR, NXDN, M17 input filtering
|
||||||
|
-xx Expect non-inverted X2-TDMA signal
|
||||||
|
-xr Expect inverted DMR signal
|
||||||
|
-xd Expect inverted ICOM dPMR signal
|
||||||
|
-xn Expect inverted NXDN/DCR/IDAS signal
|
||||||
|
|
||||||
|
* denotes frame types that cannot be auto-detected.
|
||||||
|
** Phase 2 Single Frequency may require user to manually set WACN/SYSID/CC parameters if MAC_SIGNAL not present.
|
||||||
|
|
||||||
|
Advanced Decoder options:
|
||||||
|
-X <hex> Manually Set P2 Parameters (WACN, SYSID, CC/NAC)
|
||||||
|
(-X BEE00ABC123)
|
||||||
|
-_ <dec> Manually Set NXDN PN95 Dibit Scrambler Seed (1-511)
|
||||||
|
(-* 261)
|
||||||
|
-D <dec> Manually Set TIII DMR Location Area n bit len (0-10)(10 max)
|
||||||
|
(Value defaults to max n bit value for site model size)
|
||||||
|
(Setting 0 will show full Site ID, no area/subarea)
|
||||||
|
|
||||||
|
-ma Auto-select modulation optimizations
|
||||||
|
-mc Use only C4FM modulation optimizations (default)
|
||||||
|
-mg Use only GFSK modulation optimizations
|
||||||
|
-mq Use only QPSK modulation optimizations
|
||||||
|
-m2 Use P25p2 6000 sps QPSK modulation optimizations
|
||||||
|
-F Relax P25 Phase 2 MAC_SIGNAL CRC Checksum Pass/Fail
|
||||||
|
Use this feature to allow MAC_SIGNAL even if CRC errors.
|
||||||
|
-F Relax DMR RAS/CRC CSBK/DATA Pass/Fail
|
||||||
|
Enabling on some systems could lead to bad channel assignments/site data decoding if bad or marginal signal
|
||||||
|
|
||||||
|
-b <dec> Manually Enter Basic Privacy Key (Decimal Value of Key Number)
|
||||||
|
(NOTE: This used to be the 'K' option!)
|
||||||
|
|
||||||
|
-H <hex> Manually Enter Hytera 10/32/64 Char Basic Privacy Hex Key (see example below)
|
||||||
|
Encapulate in Single Quotation Marks; Space every 16 chars.
|
||||||
|
-H 0B57935150
|
||||||
|
-H '736B9A9C5645288B 243AD5CB8701EF8A'
|
||||||
|
-H '20029736A5D91042 C923EB0697484433 005EFC58A1905195 E28E9C7836AA2DB8'
|
||||||
|
|
||||||
|
-H <hex> Manually Enter AES-128, AES-256, or Kirisun 128 or 256 Hex Key (see example below)
|
||||||
|
Encapulate in Single Quotation Marks; Space every 16 chars.
|
||||||
|
-H '736B9A9C5645288B 243AD5CB8701EF8A'
|
||||||
|
-H '20029736A5D91042 C923EB0697484433 005EFC58A1905195 E28E9C7836AA2DB8'
|
||||||
|
|
||||||
|
-H <hex> Manually Enter Caltta 10/32/64 Char Basic Privacy Hex Key (see example below)
|
||||||
|
-H C:40:1234567890
|
||||||
|
-H C:128:736B9A9C5645288B243AD5CB8701EF8A'
|
||||||
|
-H C:256:20029736A5D91042C923EB0697484433005EFC58A1905195E28E9C7836AA2DB8'
|
||||||
|
|
||||||
|
-H <hex> Manually Enter Hytera OTA Encryption 32 Char Hex Key (see example below)
|
||||||
|
-H O:0:0 no keystream application, but check for Hytera OTA Encryption and DMRA EP Late Entry IV.
|
||||||
|
-H O:128:17bfe59b29a06136fb7d3811fd1a4904 for 128-bit RC4 OTA Key Setup
|
||||||
|
|
||||||
|
-R <dec> Manually Enter dPMR or NXDN EHR Scrambler Key Value (Decimal Value)
|
||||||
|
|
||||||
|
-1 <hex> Manually Enter RC4 or DES Key Value (DMR, P25, NXDN) (Hex Value)
|
||||||
|
|
||||||
|
-2 <hex> Manually Enter and Enforce TYT 16-bit BP Key Value (DMR) (Hex Value)
|
||||||
|
|
||||||
|
-! <hex> Manually Enter and Enforce TYT Advanced Privacy (PC4) 128 or 256 bit AP Hex Key (see example below)
|
||||||
|
Encapulate in Single Quotation Marks; Space every 16 chars.
|
||||||
|
-! '736B9A9C5645288B 243AD5CB8701EF8A'
|
||||||
|
-! '1111111111111111 1111111111111111 1111111111111111 1111111111111111'
|
||||||
|
|
||||||
|
-@ <hex> Manually Enter and Enforce Retevis Advanced Privacy (RC2) 128 or 256 bit AP Hex Key (see example below)
|
||||||
|
Encapulate in Single Quotation Marks; Space every 16 chars.
|
||||||
|
-@ '736B9A9C5645288B 243AD5CB8701EF8A'
|
||||||
|
-@ '1122334455667788 99AABBCCDDEEFF11 1122334455667788 99AABBCCDDEEFF11'
|
||||||
|
|
||||||
|
-5 <hex> Manually Enter and Enforce TYT Enhanced Privacy (AES-128) EP Hex Key (see example below)
|
||||||
|
Encapulate in Single Quotation Marks; Space every 16 chars.
|
||||||
|
-5 '736B9A9C5645288B 243AD5CB8701EF8A'
|
||||||
|
|
||||||
|
-+ <hex> Manually Enter and Enforce Baofeng Advanced Privacy (PC5-128 or PC5-256) AP Hex Key (see example below)
|
||||||
|
Encapulate in Single Quotation Marks; Space every 16 chars.
|
||||||
|
-+ 'ABCDABCDABCDABCD ABDCDABCDABCDABC'
|
||||||
|
-+ 'ABCDABCDABCDABCD ABDCDABCDABCDABC EF01EF01EF01EF01 EF01EF01EF01EF01'
|
||||||
|
|
||||||
|
-^ <hex> Manually Enter and Enforce Connect Systems 72-bit (9-byte) Extended Encryption Hex Key (see example below)
|
||||||
|
-^ 3BBE782C0430008271
|
||||||
|
|
||||||
|
-9 <dec> Manually Enter and Enforce Kenwood 15-bit Scrambler Key Value (DMR) (Dec Value)
|
||||||
|
|
||||||
|
-A <hex> Manually Enter and Enforce Anytone 16-bit BP Key Value (DMR) (Hex Value)
|
||||||
|
|
||||||
|
-$ <string> Enter RAS Password 6-24 Char Key Value (DMR) (a-z A-Z, 0-9, $ # _ -)
|
||||||
|
-$ Password123
|
||||||
|
|
||||||
|
Special Use Cases involving # and $, use parenthesis and put \ in front of all $ signs
|
||||||
|
-$ "######"
|
||||||
|
-$ "\$\$\$\$\$\$"
|
||||||
|
|
||||||
|
-y <hex> Enter RAS 56-bit Effective Key Value (DMR) (14 Char Hex Value)
|
||||||
|
-y 6DF241BC4AE2EC
|
||||||
|
|
||||||
|
-, <string> Manually Enter and Enforce Auctus A6 (GoComm) 8 Char Key Value (DMR) (String Value)
|
||||||
|
-, Secure04
|
||||||
|
|
||||||
|
-u <string> Manually Enter Vertex Standard 10 or 64 Char Hex Key
|
||||||
|
-u 10:1234567891 or 64:AAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBCCCCCCCCCCCCCCCCDDDDDDDDDDDDDDDD
|
||||||
|
-u 0:0 no KS application, but apply the inversion to the interleave (clear errors on 256)
|
||||||
|
|
||||||
|
-S <str> Manually Enter and Enforce Generic Static Keystream -> Length and BYTE PACKED / ALIGNED String for AMBE (up to 882 bits)
|
||||||
|
For Example, enter 16-bit Keystream 0909 as:
|
||||||
|
-S 16:0909
|
||||||
|
For Example, enter 49-bit Keystream as:
|
||||||
|
-S 49:123456789ABC80
|
||||||
|
For Example, enter 49-bit Keystream (MBP 70) as:
|
||||||
|
-S 49:ED0AED4AED4AED4A
|
||||||
|
For Example, Baofeng 49-bit Keystream for 56-bit Custom Encryption as:
|
||||||
|
-S 49:11AA22BB33CC44
|
||||||
|
For Example, Caltta 40-bit Keystream w/ optional 7-bit discard as:
|
||||||
|
-S 40:1234567890:7
|
||||||
|
|
||||||
|
-k <file> Import Key List from csv file (Decimal Format) -- Lower Case 'k'.
|
||||||
|
Only supports NXDN, DMR Basic Privacy (decimal value).
|
||||||
|
(dPMR and Hytera 32/64 char not supported, DMR uses TG value as key id -- EXPERIMENTAL!!).
|
||||||
|
|
||||||
|
-K <file> Import Key List from csv file (Hexidecimal Format) -- Capital 'K'.
|
||||||
|
Use for Hex Value Hytera 10-char BP keys, RC4 10-char, DES 16-char Hex Keys, and AES128/256 32/64-char keys.
|
||||||
|
|
||||||
|
-4 Force Privacy Key over Encryption Identifiers (DMR MBP/HBP and NXDN Scrambler)
|
||||||
|
|
||||||
|
-0 Force RC4 Key over Missing PI header/LE Encryption Identifiers (DMR)
|
||||||
|
|
||||||
|
-M <hex> Force Entered Alg ID Value over Missing PI header/LE Encryption Identifiers (DMR)
|
||||||
|
|
||||||
|
-3 Disable DMR Late Entry Encryption Identifiers (VC6 Single Burst)
|
||||||
|
Note: Disable this if false positives on Voice ENC occur.
|
||||||
|
|
||||||
|
Trunking Options:
|
||||||
|
-C <file> Import Channel to Frequency Map (channum, freq) from csv file. (Capital C)
|
||||||
|
(See channel_map.csv for example)
|
||||||
|
-G <file> Import Group List Allow/Block and Label from csv file.
|
||||||
|
(See group.csv for example)
|
||||||
|
-T Enable Trunking Features (NXDN/P25/EDACS/DMR) with RIGCTL/TCP or RTL Input
|
||||||
|
-Y Enable Scanning Mode with RIGCTL/TCP or RTL Input
|
||||||
|
Experimental -- Can only scan for sync with enabled decoders, don't mix NXDN and DMR/P25!
|
||||||
|
This is not a Trunking Feature, just scans through conventional frequencies fast!
|
||||||
|
-W Use Imported Group List as a Trunking Allow/White List -- Only Tune with Mode A
|
||||||
|
-p Disable Tune to Private Calls (DMR TIII, P25, NXDN Type-C and Type-D)
|
||||||
|
-E Disable Tune to Group Calls (DMR TIII, Con+, Cap+, P25, NXDN Type-C, and Type-D)
|
||||||
|
-e Enable Tune to Data Calls (DMR TIII, Cap+, NXDN Type-C)
|
||||||
|
(NOTE: No Clear Distinction between Cap+ Private Voice Calls and Data Calls -- Both enabled with Data Calls)
|
||||||
|
-I <dec> Specify TG to Hold During Trunking (DMR, P25, NXDN Type-C Trunking)
|
||||||
|
-U <port> Enable RIGCTL/TCP; Set TCP Port for RIGCTL. (4532 on SDR++)
|
||||||
|
-B <Hertz> Set RIGCTL Setmod Bandwidth in Hertz (0 - default - OFF)
|
||||||
|
P25 - 12000; NXDN48 - 7000; NXDN96: 12000; DMR - 7000-12000; EDACS/PV - 12000-24000;
|
||||||
|
May vary based on system stregnth, etc.
|
||||||
|
-t <secs> Set Trunking or Scan Speed VC/sync loss hangtime in seconds. (default = 1 second)
|
||||||
|
|
||||||
|
Trunking Example TCP: dsd-fme -fs -i tcp -U 4532 -T -C dmr_t3_chan.csv -G group.csv -N 2> log.txt
|
||||||
|
Trunking Example RTL: dsd-fme -fs -i rtl:0:450M:26:-2:8 -T -C connect_plus_chan.csv -G group.csv -N 2> log.txt
|
||||||
97
examples/cygwin_bat/example_options.txt
Normal file
97
examples/cygwin_bat/example_options.txt
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
This example options contains numerous options put into the start-dsd-fme.bat file in the option string
|
||||||
|
feel free to experiment and mix and match example options for your bat files option string.
|
||||||
|
|
||||||
|
Trunking Option Examples:
|
||||||
|
|
||||||
|
P25 (Phase 1 Control) Trunking with SDR++ Network Sink input, RIGCTL, /dev/dsp output,
|
||||||
|
per call wav files, ncurses terminal
|
||||||
|
-ft -i tcp:127.0.0.1:7355 -U 4532 -T -P -N
|
||||||
|
|
||||||
|
P25 (Phase 2 Control) Trunking with SDR++ Network Sink input, RIGCTL, /dev/dsp output,
|
||||||
|
per call wav files, ncurses terminal
|
||||||
|
-f2 -i tcp:127.0.0.1:7355 -U 4532 -T -P -N
|
||||||
|
|
||||||
|
DMR Trunking with RTL input, /dev/dsp output, channel map import,
|
||||||
|
per call wav files, ncurses terminal, payload dump to console
|
||||||
|
-fs -i rtl:0:450M:0:-2:12 -T -C examples\dmr_t3_chan.csv -P -N -Z
|
||||||
|
|
||||||
|
DMR Trunking with SDR++ input, RIGCTL, /dev/dsp output, RAS enabled CSBK (-F),
|
||||||
|
channel map import, per call wav files, ncurses terminal, payload dump to console
|
||||||
|
-fs -F -i tcp -U 4532 -T -C examples\capacity_plus_chan.csv -P -N -Z
|
||||||
|
|
||||||
|
NXDN48 v2.0 DFA (Direct Frequency Assignment) Trunking with SDR++ input, RIGCTL, /dev/dsp output,
|
||||||
|
scrambler key import (decimal), per call wav files, ncurses terminal, payload dump to console
|
||||||
|
-fi -i tcp -U 4532 -T -P -N -Z -k examples\nxdn_sc_key.csv
|
||||||
|
|
||||||
|
NXDN96 Trunking with SDR++ input, RIGCTL, /dev/dsp output,
|
||||||
|
channel map import, per call wav files, ncurses terminal, payload dump to console
|
||||||
|
-fn -i tcp -U 4532 -T -C examples\nxdn_chan_map.csv -P -N -Z
|
||||||
|
|
||||||
|
EDACS Standard Network Analog and Digital
|
||||||
|
-fh -i tcp -U 4532 -T -C edacs_channel_map.csv -G group.csv -N
|
||||||
|
-fh -i rtl:0:850M:44:-2:24 -T -C edacs_channel_map.csv -G group.csv -N
|
||||||
|
|
||||||
|
EDACS Extended Address Analog and Digital (with ESK)
|
||||||
|
-fE -i tcp:192.168.7.5:7355 -U 4532 -T -C edacs_channel_map.csv -G group.csv -N
|
||||||
|
-fE -i rtl:0:850M:44:-2:24 -T -C edacs_channel_map.csv -G group.csv -N
|
||||||
|
|
||||||
|
Scanning Option Examples:
|
||||||
|
|
||||||
|
Scanning will not perform quickly like a real scanner, but can be used with any
|
||||||
|
supported decoding type and analog as well, and will require a channel_map to scan frequencies
|
||||||
|
channel numbers do not matter, but use unique ones for each frequeny
|
||||||
|
-t 0 will scan as fast as possible, but may miss frame sync, -t 1 is stable, but needs 1 second between tuning
|
||||||
|
|
||||||
|
P25/DMR/Analog Scanning with RTL input, /dev/dsp output, channel map import,
|
||||||
|
per call wav files, ncurses terminal, payload dump to console, raw audio signal monitoring
|
||||||
|
-ft -i rtl:0:450M:0:-2:12 -Y -t 1 -C examples\dmr_t3_chan.csv -P -8 -N -Z
|
||||||
|
|
||||||
|
P25/DMR/Analog Scanning with SDR++ input (use squelch), RIGCTL, /dev/dsp output, channel map import,
|
||||||
|
per call wav files, ncurses terminal, payload dump to console, raw audio signal monitoring
|
||||||
|
-ft -i tcp:127.0.0.1:7355 -U 4532 -Y -t 1 -C examples\dmr_t3_chan.csv -P -8 -N -Z
|
||||||
|
|
||||||
|
NXDN48/Analog Scanning with SDR++ input (use squelch), RIGCTL, /dev/dsp output, channel map import,
|
||||||
|
per call wav files, ncurses terminal, payload dump to console, raw audio signal monitoring
|
||||||
|
-fi -i tcp:127.0.0.1:7355 -U 4532 -Y -t 1-C examples\nxdn_chan_map.csv -P -8 -N -Z
|
||||||
|
|
||||||
|
Analog Scanning with SDR++ input (use squelch), RIGCTL, /dev/dsp output, channel map import
|
||||||
|
-fA -i tcp:127.0.0.1:7355 -U 4532 -Y -t 0 -C examples\nxdn_chan_map.csv -8
|
||||||
|
|
||||||
|
Encryption Option Examples:
|
||||||
|
|
||||||
|
DMR with default /dev/dsp input and output, use basic privacy key 70
|
||||||
|
-fs -b 70
|
||||||
|
|
||||||
|
DMR with default /dev/dsp input and output, load .csv file with decimal basic privacy keys loaded by TG value,
|
||||||
|
-fs -k examples\multi_key.csv
|
||||||
|
|
||||||
|
DMR with default /dev/dsp input and output, use Hytera basic privacy key (10, 32, and 64 hex char versions)
|
||||||
|
-fs -H 1111111111
|
||||||
|
-fs -H '2222222222222222 3333333333333333'
|
||||||
|
-fs -H '2222222222222222 3333333333333333 4444444444444444 5555555555555555'
|
||||||
|
|
||||||
|
DMR with default /dev/dsp input and output, use RC4 key 0x7777777777
|
||||||
|
-fs -1 7777777777
|
||||||
|
|
||||||
|
DMR with default /dev/dsp input and output, use RC4 key 0x7777777777,
|
||||||
|
Force RC4 Key over Missing PI header/LE Encryption Identifiers (-0)
|
||||||
|
Disable Late Entry Encryption Signalling Identifiers (-3)
|
||||||
|
-fs -0 -3 -1 7777777777
|
||||||
|
|
||||||
|
DMR with default /dev/dsp input and output, load RC4 and 10-char HBP keys from .csv file (hexidecimal format)
|
||||||
|
-fs -K dsd-fme\examples\multi_key_hex.csv
|
||||||
|
|
||||||
|
P25 with default /dev/dsp input and output, use RC4 key 0x7777777777
|
||||||
|
-ft -1 7777777777
|
||||||
|
|
||||||
|
NXDN48 with default /dev/dsp input and output, use Scrambler key 32767
|
||||||
|
-fi -R 32767
|
||||||
|
|
||||||
|
NXDN96 with default /dev/dsp input and output, use Scrambler key 15000
|
||||||
|
-fn -R 15000
|
||||||
|
|
||||||
|
dPMR with default /dev/dsp input and output, use Scrambler key 32767
|
||||||
|
-fm -R 32767
|
||||||
|
|
||||||
|
NXDN48 with default /dev/dsp input and output, load scrambler keys from .csv file (decimal format)
|
||||||
|
-fi -k dsd-fme\examples\nxdn_sc_key.csv
|
||||||
1
examples/cygwin_bat/readme_cygwin_bat.txt
Normal file
1
examples/cygwin_bat/readme_cygwin_bat.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
These .bat files are ONLY for use on the portable cygwin builds, do not use these in any other build environments!
|
||||||
67
examples/cygwin_bat/start-dsd-fme.bat
Normal file
67
examples/cygwin_bat/start-dsd-fme.bat
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
@REM Digital Speech Decoder: Florida Man Edition
|
||||||
|
@REM DSD-FME Cygwin Windows Portable Builds
|
||||||
|
@REM
|
||||||
|
@REM The source code of this software can be downloaded here:
|
||||||
|
@REM https://github.com/lwvmobile/dsd-fme
|
||||||
|
@REM
|
||||||
|
@REM If you paid for, or were otherwise fleeced for this software, DEMAND YOUR MONEY BACK!
|
||||||
|
@REM
|
||||||
|
@REM This software is designed to be used with an SDR receiver (like SDR++ or SDR#) with TCP input,
|
||||||
|
@REM RTL Input, media file playback over virtual cables or null-sinks, or a Discriminator Tap input
|
||||||
|
@REM
|
||||||
|
@REM The complete options list can be seen by viewing complete_usage_options.txt
|
||||||
|
@REM Many examples can be found in example_options.txt
|
||||||
|
@REM
|
||||||
|
@REM Enjoy!
|
||||||
|
|
||||||
|
@REM Regarding the options string (or any string in .bat files)
|
||||||
|
@REM If your string may contain spaces, set the first '"' before options, and then an ending '"'
|
||||||
|
@REM Incorrect: set options="-fs -N -Z"
|
||||||
|
@REM Correct: set "options=-fs -N -Z"
|
||||||
|
|
||||||
|
@REM set options to pass to dsd-fme
|
||||||
|
set "options= -N -Z "
|
||||||
|
|
||||||
|
@REM Create Folder and Set Date Time for logs
|
||||||
|
@echo off
|
||||||
|
mkdir logs
|
||||||
|
@REM Locale-independent date/time for log filenames (yyyyMMdd_HHmmss)
|
||||||
|
@REM Works on older Windows without wmic or PowerShell
|
||||||
|
for /f "tokens=1-6 delims=/: " %%a in ('robocopy "|" . /njh ^| find ":"') do (
|
||||||
|
set "YYYY=%%a"
|
||||||
|
set "MM=%%b"
|
||||||
|
set "DD=%%c"
|
||||||
|
set "HH=%%d"
|
||||||
|
set "Min=%%e"
|
||||||
|
set "Sec=%%f"
|
||||||
|
)
|
||||||
|
set "datetimestr=%YYYY%%MM%%DD%_%HH%%Min%%Sec%"
|
||||||
|
|
||||||
|
@REM random number is used so that two log files don't share the same name
|
||||||
|
set rnd=%RANDOM%
|
||||||
|
|
||||||
|
@REM set log file relative filepath
|
||||||
|
set "clog=.\logs\console_log_%datetimestr%_%rnd%.txt"
|
||||||
|
set "elog=.\logs\event_log_%datetimestr%_%rnd%.txt"
|
||||||
|
|
||||||
|
@REM create the log file now with touch
|
||||||
|
.\dsd-fme\touch.exe %clog%
|
||||||
|
.\dsd-fme\touch.exe %elog%
|
||||||
|
|
||||||
|
@REM Launch Tail to display the console log and event log in a seperate console windows
|
||||||
|
start .\dsd-fme\tail.exe -n 40 -f %clog%
|
||||||
|
start .\dsd-fme\tail.exe -n 40 -f %elog%
|
||||||
|
|
||||||
|
@REM start dsd-fme with options and logs
|
||||||
|
.\dsd-fme\dsd-fme.exe %options% -J %elog% 2> %clog%
|
||||||
|
|
||||||
|
echo ----------------------------------------------------------------------------------
|
||||||
|
echo ----------------------------------------------------------------------------------
|
||||||
|
echo For any errors, see: %clog%
|
||||||
|
echo Forward %clog% and Options: "%options%"
|
||||||
|
echo to developer on Github or Radio Reference for troubleshooting.
|
||||||
|
echo ----------------------------------------------------------------------------------
|
||||||
|
echo ----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@REM Set pause to diplay above message
|
||||||
|
PAUSE
|
||||||
8
examples/dmr_t3_chan.csv
Normal file
8
examples/dmr_t3_chan.csv
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
6
examples/edacs_channel_map.csv
Normal file
6
examples/edacs_channel_map.csv
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
LSN(dec),frequency(Hz) (do not delete this line or won't import properly)
|
||||||
|
1,851375000
|
||||||
|
2,851800000
|
||||||
|
3,855987500
|
||||||
|
4,858487500
|
||||||
|
5,852312500
|
||||||
|
7
examples/example_aes_keys.csv
Normal file
7
examples/example_aes_keys.csv
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
keyid(hex), keyvalue(hex)
|
||||||
|
0001,0000000000000000,0000000000000000,0000000000000000,0000002823d87923
|
||||||
|
0003,0101010101010101,0101010101010101
|
||||||
|
0004,0101010101010101,0101010101010101,0101010101010101,0101010101010101
|
||||||
|
C197,A753BC945DE5E0F1,EC1970F8565154E6,D9DF2FAC6278FA93,B531D2CC046E93A2
|
||||||
|
0067,0000000000000000,0000000000000000,0000000000000000,DEADBEEFBAADF00D
|
||||||
|
0000,0000000000000000,0000000000000000,0000000000000000,0000000000000001
|
||||||
|
5
examples/group.csv
Normal file
5
examples/group.csv
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
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
|
||||||
|
10
examples/hytera_xpt_chan.csv
Normal file
10
examples/hytera_xpt_chan.csv
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
LSN(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
|
||||||
|
|
||||||
|
6
examples/multi_key.csv
Normal file
6
examples/multi_key.csv
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
key id or tg id (dec), key number or value (dec) //NXDN Scrambler, BP, 10-char Hytera BP only
|
||||||
|
2,70
|
||||||
|
1,123
|
||||||
|
100,70
|
||||||
|
12,48713912656
|
||||||
|
672560,254
|
||||||
|
5
examples/multi_key_hex.csv
Normal file
5
examples/multi_key_hex.csv
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
key id(hex), key value (hex) //10-char Hytera BP, RC4
|
||||||
|
1,1234567890
|
||||||
|
2,ABCDEF1234
|
||||||
|
C,0B57935150
|
||||||
|
64,0B57935150
|
||||||
|
8
examples/nxdn_chan_map.csv
Normal file
8
examples/nxdn_chan_map.csv
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
channel(dec), freq(Hz)
|
||||||
|
141,423862500
|
||||||
|
142,424337500
|
||||||
|
143,424912500
|
||||||
|
203,424100000
|
||||||
|
204,424625000
|
||||||
|
271,422650000
|
||||||
|
302,423287500
|
||||||
|
5
examples/nxdn_sc_key.csv
Normal file
5
examples/nxdn_sc_key.csv
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
key(dec) or tg(dec), value(dec), load any single keys as key 0
|
||||||
|
0,23466
|
||||||
|
1,12345
|
||||||
|
2,32700
|
||||||
|
63,32767
|
||||||
|
BIN
examples/pavucontrol_plumbing1.png
Normal file
BIN
examples/pavucontrol_plumbing1.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 26 KiB |
BIN
examples/pavucontrol_plumbing2.png
Normal file
BIN
examples/pavucontrol_plumbing2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 68 KiB |
112
examples/start-dsd-fme-linux-terminal.sh
Normal file
112
examples/start-dsd-fme-linux-terminal.sh
Normal file
@@ -0,0 +1,112 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# Force bash for better compatibility (I think)
|
||||||
|
#
|
||||||
|
# Digital Speech Decoder: Florida Man Edition
|
||||||
|
#
|
||||||
|
# The source code of this software can be downloaded here:
|
||||||
|
# https://github.com/lwvmobile/dsd-fme
|
||||||
|
#
|
||||||
|
# If you paid for, or were otherwise fleeced for this software, DEMAND YOUR MONEY BACK!
|
||||||
|
#
|
||||||
|
# This software is designed to be used with an SDR receiver (like SDR++ or SDR#) with TCP input,
|
||||||
|
# RTL Input, media file playback over virtual cables or null-sinks, or a Discriminator Tap input
|
||||||
|
#
|
||||||
|
# The complete options list can be seen by viewing complete_usage_options.ans
|
||||||
|
# Many examples can be found in example_options.ans
|
||||||
|
#
|
||||||
|
# Enjoy!
|
||||||
|
###
|
||||||
|
#### IMPORTANT! Set your dsd-fme options here! ####
|
||||||
|
# Example : opts=' -ft -i rtl:0:460.350M:0:-1:8 -N -Z '
|
||||||
|
####
|
||||||
|
# set options to pass to dsd-fme
|
||||||
|
opts=' -N -Z '
|
||||||
|
####
|
||||||
|
# Initialize variables
|
||||||
|
xe="0"
|
||||||
|
gt="0"
|
||||||
|
xt="0"
|
||||||
|
ko="0"
|
||||||
|
# Functions to check for available terminals
|
||||||
|
chk_xe(){
|
||||||
|
# Check if x-terminal-emulator is installed
|
||||||
|
xe=$(which x-terminal-emulator 2>/dev/null)
|
||||||
|
if [ -z $xe ];then xe="0";else xe="1";fi
|
||||||
|
}
|
||||||
|
chk_gt(){
|
||||||
|
# Check if gnome-terminal is installed
|
||||||
|
gt=$(which gnome-terminal 2>/dev/null)
|
||||||
|
if [ -z $gt ];then gt="0";else gt="1";fi
|
||||||
|
}
|
||||||
|
chk_ko(){
|
||||||
|
# Check if Konsole is installed
|
||||||
|
ko=$(which konsole 2>/dev/null)
|
||||||
|
if [ -z $ko ];then ko="0";else ko="1";fi
|
||||||
|
}
|
||||||
|
chk_xt(){
|
||||||
|
# Check if xterm is installed
|
||||||
|
xt=$(which xterm 2>/dev/null)
|
||||||
|
if [ -z $xt ];then xt="0";else xt="1";fi
|
||||||
|
}
|
||||||
|
# Check for and set terminal
|
||||||
|
chk_xe
|
||||||
|
if [ $xe = "1" ];then
|
||||||
|
term=$(which x-terminal-emulator 2>/dev/null)
|
||||||
|
printf "Using X-Terminal-Emulator!\n"
|
||||||
|
else
|
||||||
|
chk_gt
|
||||||
|
fi
|
||||||
|
if [ $gt = "1" ];then
|
||||||
|
term=$(which gnome-terminal 2>/dev/null)
|
||||||
|
printf "Using Gnome-Terminal!\n"
|
||||||
|
elif [ $xe = "0" ]&&[ $gt = "0" ];then
|
||||||
|
chk_xt
|
||||||
|
fi
|
||||||
|
if [ $xt = "1" ];then
|
||||||
|
term=$(which xterm 2>/dev/null)
|
||||||
|
printf "Using XTerm!\n"
|
||||||
|
elif [ $xe = "0" ]&&[ $gt = "0" ]&&[ $xt = "0" ];then
|
||||||
|
chk_ko
|
||||||
|
fi
|
||||||
|
if [ $ko = "1" ];then
|
||||||
|
term=$(which konsole 2>/dev/null)
|
||||||
|
printf "Using Konsole!\n"
|
||||||
|
fi
|
||||||
|
# Bail if no terminal found
|
||||||
|
if [ "$ko" -eq "0" ]&&[ "$gt" -eq "0" ]&&[ "$xt" -eq "0" ]&&[ "$xe" -eq "0" ];then printf "No known terminals available!\n";exit 1;fi
|
||||||
|
# Get current directory
|
||||||
|
wd=$(pwd)
|
||||||
|
# Set date/time
|
||||||
|
# dt=$(date +%F_%H%M-%S-%N) #with hyphens
|
||||||
|
dt=$(date +%Y%m%d_%H%M%S) #just an underscore between date and time
|
||||||
|
if [ ! -d "logs" ]; then
|
||||||
|
mkdir logs
|
||||||
|
fi
|
||||||
|
# set log file relative filepath
|
||||||
|
clog="$wd/logs/console_log_$dt.txt"
|
||||||
|
elog="$wd/logs/event_log_$dt.txt"
|
||||||
|
# create the log file now with touch
|
||||||
|
touch $clog
|
||||||
|
touch $elog
|
||||||
|
# open new terminal windows to watch live log files
|
||||||
|
if [ "$term" == "$(which konsole)" ]||[ "$term" == "$(which xterm)" ];then
|
||||||
|
$term -e "tail -n 40 -f $clog" 2>/dev/null
|
||||||
|
$term -e "tail -n 40 -f $elog" 2>/dev/null
|
||||||
|
else
|
||||||
|
$term --window -e "tail -n 40 -f $clog" 2>/dev/null
|
||||||
|
$term --window -e "tail -n 40 -f $elog" 2>/dev/null
|
||||||
|
fi
|
||||||
|
# start dsd-fme with options and log files
|
||||||
|
dsd-fme $opts -J $elog 2> $clog
|
||||||
|
echo -------------------------------------------------------------------------------
|
||||||
|
echo -------------------------------------------------------------------------------
|
||||||
|
echo For any errors, see: $clog
|
||||||
|
echo Forward $clog and
|
||||||
|
echo Options: \" $opts \"
|
||||||
|
echo to developer on Github or Radio Reference for troubleshooting.
|
||||||
|
echo -------------------------------------------------------------------------------
|
||||||
|
echo -------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
# Set pause to diplay above message
|
||||||
|
read -p "Press ENTER to continue... " x
|
||||||
|
|
||||||
57
examples/trunking.sh
Normal file
57
examples/trunking.sh
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
#example trunking sh scripts (SDR++ with RIGCTL and RTL Input)
|
||||||
|
#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:0:-2:12 -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:0:-2:12 -T -mq -N 2> log.ans
|
||||||
|
|
||||||
|
#P25 P2 TDMA CC with C4FM
|
||||||
|
#dsd-fme -i tcp:192.168.7.8:7355 -U 4532 -T -f2 -N 2> log.ans
|
||||||
|
#dsd-fme -i rtl:0:855.625M:0:-2:12 -T -f2 -m2 -N 2> log.ans
|
||||||
|
|
||||||
|
#DMR TIII, Con+, Cap+, XPT
|
||||||
|
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:44:-2:8 -T -C connect_plus_chan.csv -G group.csv -N 2> log.ans
|
||||||
|
|
||||||
|
#EDACS Standard Network Analog and Digital
|
||||||
|
#dsd-fme -fh -i tcp:192.168.7.5:7355 -U 4532 -T -C edacs_channel_map.csv -G group.csv -N 2> log.ans
|
||||||
|
#dsd-fme -fh -i rtl:0:850M:44:-2:24 -T -C edacs_channel_map.csv -G group.csv -N 2> log.ans
|
||||||
|
|
||||||
|
#EDACS Standard Network Analog and Digital (with ESK)
|
||||||
|
#dsd-fme -fH -i tcp:192.168.7.5:7355 -U 4532 -T -C edacs_channel_map.csv -G group.csv -N 2> log.ans
|
||||||
|
#dsd-fme -fH -i rtl:0:850M:44:-2:24 -T -C edacs_channel_map.csv -G group.csv -N 2> log.ans
|
||||||
|
|
||||||
|
#EDACS Extended Address Analog and Digital
|
||||||
|
#dsd-fme -fe -i tcp:192.168.7.5:7355 -U 4532 -T -C edacs_channel_map.csv -G group.csv -N 2> log.ans
|
||||||
|
#dsd-fme -fe -i rtl:0:850M:44:-2:24 -T -C edacs_channel_map.csv -G group.csv -N 2> log.ans
|
||||||
|
|
||||||
|
#EDACS Extended Address Analog and Digital (with ESK)
|
||||||
|
#dsd-fme -fE -i tcp:192.168.7.5:7355 -U 4532 -T -C edacs_channel_map.csv -G group.csv -N 2> log.ans
|
||||||
|
#dsd-fme -fE -i rtl:0:850M:44:-2:24 -T -C edacs_channel_map.csv -G group.csv -N 2> log.ans
|
||||||
|
|
||||||
|
#NXDN48 Type-C or Type-D Trunking with Channel Map
|
||||||
|
#dsd-fme -fi -i tcp -T -U 4532 -C nxdn_channel_map.csv -N 2> log.ans
|
||||||
|
#dsd-fme -fi -i rtl:0:855.625M:0:-2:12:100 -T -C nxdn_channel_map.csv -N 2> log.ans
|
||||||
|
|
||||||
|
#NXDN48 Type-C Trunking with DFA
|
||||||
|
#dsd-fme -fi -i tcp -T -U 4532 -N 2> log.ans
|
||||||
|
#dsd-fme -fi -i rtl:0:855.625M:0:-2:12:100 -T -N 2> log.ans
|
||||||
|
|
||||||
|
#NXDN96 Trunking with Channel Map
|
||||||
|
#dsd-fme -fn -i tcp -T -U 4532 -C nxdn_channel_map.csv -N 2> log.ans
|
||||||
|
#dsd-fme -fn -i rtl -T -C nxdn_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
|
||||||
|
#paramters after -i rtl can also be omitted now if using the default configurations
|
||||||
|
|
||||||
|
#Having a -G group.csv is purely optional, but useful if you want to block groups, or give groups names
|
||||||
64
flake.lock
generated
Normal file
64
flake.lock
generated
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
{
|
||||||
|
"nodes": {
|
||||||
|
"flake-parts": {
|
||||||
|
"inputs": {
|
||||||
|
"nixpkgs-lib": "nixpkgs-lib"
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1709336216,
|
||||||
|
"narHash": "sha256-Dt/wOWeW6Sqm11Yh+2+t0dfEWxoMxGBvv3JpIocFl9E=",
|
||||||
|
"owner": "hercules-ci",
|
||||||
|
"repo": "flake-parts",
|
||||||
|
"rev": "f7b3c975cf067e56e7cda6cb098ebe3fb4d74ca2",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "hercules-ci",
|
||||||
|
"repo": "flake-parts",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nixpkgs": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1711163522,
|
||||||
|
"narHash": "sha256-YN/Ciidm+A0fmJPWlHBGvVkcarYWSC+s3NTPk/P+q3c=",
|
||||||
|
"owner": "NixOS",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"rev": "44d0940ea560dee511026a53f0e2e2cde489b4d4",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "NixOS",
|
||||||
|
"ref": "nixos-unstable",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nixpkgs-lib": {
|
||||||
|
"locked": {
|
||||||
|
"dir": "lib",
|
||||||
|
"lastModified": 1709237383,
|
||||||
|
"narHash": "sha256-cy6ArO4k5qTx+l5o+0mL9f5fa86tYUX3ozE1S+Txlds=",
|
||||||
|
"owner": "NixOS",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"rev": "1536926ef5621b09bba54035ae2bb6d806d72ac8",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"dir": "lib",
|
||||||
|
"owner": "NixOS",
|
||||||
|
"ref": "nixos-unstable",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": {
|
||||||
|
"inputs": {
|
||||||
|
"flake-parts": "flake-parts",
|
||||||
|
"nixpkgs": "nixpkgs"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": "root",
|
||||||
|
"version": 7
|
||||||
|
}
|
||||||
18
flake.nix
Normal file
18
flake.nix
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
{
|
||||||
|
description = "Digital Speech Decoder - Florida Man Edition ";
|
||||||
|
|
||||||
|
inputs = {
|
||||||
|
flake-parts.url = "github:hercules-ci/flake-parts";
|
||||||
|
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||||
|
};
|
||||||
|
|
||||||
|
outputs = inputs@{ flake-parts, ... }:
|
||||||
|
flake-parts.lib.mkFlake { inherit inputs; } {
|
||||||
|
systems = [ "x86_64-linux" "aarch64-linux" "aarch64-darwin" "x86_64-darwin" ];
|
||||||
|
perSystem = { config, pkgs, ... }: {
|
||||||
|
packages.default = config.packages.dsd-fme;
|
||||||
|
|
||||||
|
packages.dsd-fme = pkgs.callPackage ./package.nix { };
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -7,8 +7,6 @@
|
|||||||
*
|
*
|
||||||
* Code adapted from http://www.aqdi.com/golay.htm
|
* Code adapted from http://www.aqdi.com/golay.htm
|
||||||
*
|
*
|
||||||
* Tried before with the implementation from ITPP library but couldn't make it produce the same outputs
|
|
||||||
* expected from the P25 transmissions that I have tested. This implementation does work.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|||||||
@@ -5,9 +5,6 @@
|
|||||||
/**
|
/**
|
||||||
* Code taken and adapted from www.eccpage.com/rs.c
|
* Code taken and adapted from www.eccpage.com/rs.c
|
||||||
* Credit goes to Mr Simon Rockliff.
|
* Credit goes to Mr Simon Rockliff.
|
||||||
*
|
|
||||||
* Tried before with the implementation from ITPP library but couldn't make it produce the same outputs
|
|
||||||
* expected from the P25 transmissions that I have tested. This implementation does work.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* This program is an encoder/decoder for Reed-Solomon codes. Encoding is in
|
/* This program is an encoder/decoder for Reed-Solomon codes. Encoding is in
|
||||||
|
|||||||
71
include/bp.h
Normal file
71
include/bp.h
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
#ifndef BP_H
|
||||||
|
#define BP_H
|
||||||
|
|
||||||
|
static const uint16_t BPK[256] = {
|
||||||
|
//000
|
||||||
|
0x0000, 0x1F00, 0xE300, 0xFC00, 0x2503, 0x3A03, 0xC603, 0xD903,
|
||||||
|
//008
|
||||||
|
0x4A05, 0x5505, 0xA905, 0xB605, 0x6F06, 0x7006, 0x8C06, 0x9306,
|
||||||
|
//016
|
||||||
|
0x2618, 0x3918, 0xC518, 0xDA18, 0x031B, 0x1C1B, 0xE01B, 0xFF1B,
|
||||||
|
//024
|
||||||
|
0x6C1D, 0x731D, 0x8F1D, 0x901D, 0x491E, 0x561E, 0xAA1E, 0xB51E,
|
||||||
|
//032
|
||||||
|
0x4B28, 0x5428, 0xA828, 0xB728, 0x6E2B, 0x712B, 0x8D2B, 0x922B,
|
||||||
|
//040
|
||||||
|
0x012D, 0x1E2D, 0xE22D, 0xFD2D, 0x242E, 0x3B2E, 0xC72E, 0xD82E,
|
||||||
|
//048
|
||||||
|
0x6D30, 0x7230, 0x8E30, 0x9130, 0x4833, 0x5733, 0xAB33, 0xB433,
|
||||||
|
//056
|
||||||
|
0x2735, 0x3835, 0xC435, 0xDB35, 0x0236, 0x1D36, 0xE136, 0xFE36,
|
||||||
|
//064
|
||||||
|
0x2B49, 0x3449, 0xC849, 0xD749, 0x0E4A, 0x114A, 0xED4A, 0xF24A,
|
||||||
|
//072
|
||||||
|
0x614C, 0x7E4C, 0x824C, 0x9D4C, 0x444F, 0x5B4F, 0xA74F, 0xB84F,
|
||||||
|
//080
|
||||||
|
0x0D51, 0x1251, 0xEE51, 0xF151, 0x2852, 0x3752, 0xCB52, 0xD452,
|
||||||
|
//088
|
||||||
|
0x4754, 0x5854, 0xA454, 0xBB54, 0x6257, 0x7D57, 0x8157, 0x9E57,
|
||||||
|
//096
|
||||||
|
0x6061, 0x7F61, 0x8361, 0x9C61, 0x4562, 0x5A62, 0xA662, 0xB962,
|
||||||
|
//104
|
||||||
|
0x2A64, 0x3564, 0xC964, 0xD664, 0x0F67, 0x1067, 0xEC67, 0xF367,
|
||||||
|
//112
|
||||||
|
0x4679, 0x5979, 0xA579, 0xBA79, 0x637A, 0x7C7A, 0x807A, 0x9F7A,
|
||||||
|
//120
|
||||||
|
0x0C7C, 0x137C, 0xEF7C, 0xF07C, 0x297F, 0x367F, 0xCA7F, 0xD57F,
|
||||||
|
//128
|
||||||
|
0x4D89, 0x5289, 0xAE89, 0xB189, 0x688A, 0x778A, 0x8B8A, 0x948A,
|
||||||
|
//136
|
||||||
|
0x078C, 0x188C, 0xE48C, 0xFB8C, 0x228F, 0x3D8F, 0xC18F, 0xDE8F,
|
||||||
|
//144
|
||||||
|
0x6B91, 0x7491, 0x8891, 0x9791, 0x4E92, 0x5192, 0xAD92, 0xB292,
|
||||||
|
//152
|
||||||
|
0x2194, 0x3E94, 0xC294, 0xDD94, 0x0497, 0x1B97, 0xE797, 0xF897,
|
||||||
|
//160
|
||||||
|
0x06A1, 0x19A1, 0xE5A1, 0xFAA1, 0x23A2, 0x3CA2, 0xC0A2, 0xDFA2,
|
||||||
|
//168
|
||||||
|
0x4CA4, 0x53A4, 0xAFA4, 0xB0A4, 0x69A7, 0x76A7, 0x8AA7, 0x95A7,
|
||||||
|
//176
|
||||||
|
0x20B9, 0x3FB9, 0xC3B9, 0xDCB9, 0x05BA, 0x1ABA, 0xE6BA, 0xF9BA,
|
||||||
|
//184
|
||||||
|
0x6ABC, 0x75BC, 0x89BC, 0x96BC, 0x4FBF, 0x50BF, 0xACBF, 0xB3BF,
|
||||||
|
//192
|
||||||
|
0x66C0, 0x79C0, 0x85C0, 0x9AC0, 0x43C3, 0x5CC3, 0xA0C3, 0xBFC3,
|
||||||
|
//200
|
||||||
|
0x2CC5, 0x33C5, 0xCFC5, 0xD0C5, 0x09C6, 0x16C6, 0xEAC6, 0xF5C6,
|
||||||
|
//208
|
||||||
|
0x84D0, 0x85DF, 0x8AD3, 0x8BDC, 0xB6D5, 0xB7DA, 0xB8D6, 0xB9D9,
|
||||||
|
//216
|
||||||
|
0xD0DA, 0xD1D5, 0xDED9, 0xDFD6, 0xE2DF, 0xE3D0, 0xECDC, 0xEDD3,
|
||||||
|
//224
|
||||||
|
0x2DE8, 0x32E8, 0xCEE8, 0xD1E8, 0x08EB, 0x17EB, 0xEBEB, 0xF4EB,
|
||||||
|
//232
|
||||||
|
0x67ED, 0x78ED, 0x84ED, 0x9BED, 0x42EE, 0x5DEE, 0xA1EE, 0xBEEE,
|
||||||
|
//240
|
||||||
|
0x0BF0, 0x14F0, 0xE8F0, 0xF7F0, 0x2EF3, 0x31F3, 0xCDF3, 0xD2F3,
|
||||||
|
//248
|
||||||
|
0x41F5, 0x5EF5, 0xA2F5, 0xBDF5, 0x64F6, 0x7BF6, 0x87F6, 0x98F6
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -52,7 +52,7 @@ int traceBack (int * out, int * m_pathMemory0, int * m_pathMemory1, int * m_path
|
|||||||
state = S2; // lower path
|
state = S2; // lower path
|
||||||
} else {
|
} else {
|
||||||
state = S0; // upper path
|
state = S0; // upper path
|
||||||
}; // end else - if
|
} // end else - if
|
||||||
out[loop]=0;
|
out[loop]=0;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -61,7 +61,7 @@ int traceBack (int * out, int * m_pathMemory0, int * m_pathMemory1, int * m_path
|
|||||||
state = S2; // lower path
|
state = S2; // lower path
|
||||||
} else {
|
} else {
|
||||||
state = S0; // upper path
|
state = S0; // upper path
|
||||||
}; // end else - if
|
} // end else - if
|
||||||
out[loop]=1;
|
out[loop]=1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -70,7 +70,7 @@ int traceBack (int * out, int * m_pathMemory0, int * m_pathMemory1, int * m_path
|
|||||||
state = S3; // lower path
|
state = S3; // lower path
|
||||||
} else {
|
} else {
|
||||||
state = S1; // upper path
|
state = S1; // upper path
|
||||||
}; // end else - if
|
} // end else - if
|
||||||
out[loop]=0;
|
out[loop]=0;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -79,12 +79,12 @@ int traceBack (int * out, int * m_pathMemory0, int * m_pathMemory1, int * m_path
|
|||||||
state = S3; // lower path
|
state = S3; // lower path
|
||||||
} else {
|
} else {
|
||||||
state = S1; // upper path
|
state = S1; // upper path
|
||||||
}; // end else - if
|
} // end else - if
|
||||||
out[loop]=1;
|
out[loop]=1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}; // end switch
|
} // end switch
|
||||||
}; // end for
|
} // end for
|
||||||
|
|
||||||
return(length);
|
return(length);
|
||||||
}; // end function
|
}; // end function
|
||||||
|
|||||||
891
include/dsd.h
891
include/dsd.h
File diff suppressed because it is too large
Load Diff
@@ -75,7 +75,7 @@ for (loop=0; loop < size; loop++) {
|
|||||||
|
|
||||||
m_crc = (m_crc >> 8) ^ ccittTab[tmp];
|
m_crc = (m_crc >> 8) ^ ccittTab[tmp];
|
||||||
|
|
||||||
}; // end for
|
} // end for
|
||||||
|
|
||||||
// calculate and save crc-value in fields 54 and 55 of dvframe
|
// calculate and save crc-value in fields 54 and 55 of dvframe
|
||||||
m_crc = ~m_crc;
|
m_crc = ~m_crc;
|
||||||
|
|||||||
1448
include/fec.h
1448
include/fec.h
File diff suppressed because it is too large
Load Diff
@@ -16,7 +16,7 @@
|
|||||||
// Software Foundation, Inc., 51 Franklin Street, Boston, MA
|
// Software Foundation, Inc., 51 Franklin Street, Boston, MA
|
||||||
// 02110-1301, USA.
|
// 02110-1301, USA.
|
||||||
|
|
||||||
static const uint8_t PERM_12_5[] = {
|
static const uint16_t PERM_12_5[] = {
|
||||||
0,12,24,36,48,
|
0,12,24,36,48,
|
||||||
1,13,25,37,49,
|
1,13,25,37,49,
|
||||||
2,14,26,38,50,
|
2,14,26,38,50,
|
||||||
@@ -31,7 +31,7 @@ static const uint8_t PERM_12_5[] = {
|
|||||||
11,23,35,47,59
|
11,23,35,47,59
|
||||||
};
|
};
|
||||||
|
|
||||||
static const uint8_t PERM_16_9[] = {
|
static const uint16_t PERM_16_9[] = {
|
||||||
0, 16, 32, 48, 64, 80, 96, 112, 128,
|
0, 16, 32, 48, 64, 80, 96, 112, 128,
|
||||||
1, 17, 33, 49, 65, 81, 97, 113, 129,
|
1, 17, 33, 49, 65, 81, 97, 113, 129,
|
||||||
2, 18, 34, 50, 66, 82, 98, 114, 130,
|
2, 18, 34, 50, 66, 82, 98, 114, 130,
|
||||||
|
|||||||
@@ -1,26 +0,0 @@
|
|||||||
|
|
||||||
#ifndef P25P1_CHECK_NID_H_3af071e917ea43fdb51326e2cbfbde0a
|
|
||||||
#define P25P1_CHECK_NID_H_3af071e917ea43fdb51326e2cbfbde0a
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks a NID value, returns the fixed NAC, DUID and also an indication if it failed to decode the NID.
|
|
||||||
* \param bch_code Input. An array to the 63 bytes, each containing one bit of the NID. This includes the
|
|
||||||
* NAC (12 bits), DUID (4 bits) and 47 bits of BCH parity.
|
|
||||||
* \param new_nac Output. An address where to store the calculated NAC value after error correction. Should
|
|
||||||
* be large enough to accommodate for an integer.
|
|
||||||
* \param new_duid Output. An address where to store the calculated DUID value after error correction. Should
|
|
||||||
* be able to accommodate 3 chars.
|
|
||||||
* \param parity Input. The parity value read.
|
|
||||||
* \return 0 if there were errors processing the NID.
|
|
||||||
*/
|
|
||||||
int check_NID(char* bch_code, int* new_nac, char* new_duid, unsigned char parity);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // P25P1_CHECK_NID_H_3af071e917ea43fdb51326e2cbfbde0a
|
|
||||||
95
include/pc4.h
Normal file
95
include/pc4.h
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
#include <stdint.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
#ifndef TYT_AP
|
||||||
|
#define TYT_AP
|
||||||
|
|
||||||
|
#define nbround 254
|
||||||
|
#define n1 264
|
||||||
|
|
||||||
|
#define UNUSEDPC4(x) ((void)x)
|
||||||
|
|
||||||
|
/* Structure holding all PC4 state variables */
|
||||||
|
typedef struct {
|
||||||
|
short bits[49], temp[49];
|
||||||
|
uint8_t ptconvert;
|
||||||
|
uint8_t convert[7];
|
||||||
|
uint8_t perm[16][256];
|
||||||
|
uint8_t new1[256];
|
||||||
|
uint8_t array[49];
|
||||||
|
uint8_t array2[49];
|
||||||
|
uint8_t decal[nbround];
|
||||||
|
uint8_t rngxor[nbround][3];
|
||||||
|
uint8_t rngxor2[nbround][3];
|
||||||
|
uint8_t rounds;
|
||||||
|
uint8_t tab[256];
|
||||||
|
uint8_t inv[256];
|
||||||
|
uint8_t permut[3][3];
|
||||||
|
uint64_t bb;
|
||||||
|
uint64_t x;
|
||||||
|
uint8_t tot[3];
|
||||||
|
uint8_t l[2][3], r[2][3];
|
||||||
|
uint8_t y, totb;
|
||||||
|
uint32_t result;
|
||||||
|
uint8_t xyz, count;
|
||||||
|
uint8_t keys[16];
|
||||||
|
unsigned char array_arc4[256];
|
||||||
|
int i_arc4, j_arc4;
|
||||||
|
int x1, x2, i;
|
||||||
|
unsigned char h2[n1];
|
||||||
|
unsigned char h1[n1*3];
|
||||||
|
} PC4Context;
|
||||||
|
|
||||||
|
/* Global context accessible from all .c files */
|
||||||
|
extern PC4Context ctx;
|
||||||
|
|
||||||
|
/* Public API */
|
||||||
|
void create_keys(PC4Context *ctx, unsigned char key1[], size_t size1);
|
||||||
|
void pc4encrypt(PC4Context *ctx);
|
||||||
|
void pc4decrypt(PC4Context *ctx);
|
||||||
|
void binhex(PC4Context *ctx, short *z, int length);
|
||||||
|
void hexbin(PC4Context *ctx, short *q, uint8_t w, uint8_t hex);
|
||||||
|
static void u64_to_bytes_be(uint64_t val, unsigned char *out);
|
||||||
|
|
||||||
|
/* Encrypt a 49-bit frame (original flow) */
|
||||||
|
static void encrypt_frame_49(short frame_bits_in[49]) {
|
||||||
|
for (int i = 0; i < 49; i++) ctx.bits[i] = frame_bits_in[i];
|
||||||
|
for (int i = 0; i < 49; i++) ctx.temp[i] = ctx.bits[ctx.array[i]];
|
||||||
|
for (int i = 0; i < 49; i++) ctx.bits[i] = ctx.temp[i];
|
||||||
|
ctx.ptconvert = 0;
|
||||||
|
binhex(&ctx, ctx.bits, 48);
|
||||||
|
pc4encrypt(&ctx);
|
||||||
|
for (int q = 0; q < 6; q++) {
|
||||||
|
uint8_t w = (uint8_t)(q * 8);
|
||||||
|
hexbin(&ctx, ctx.bits, w, ctx.convert[q]);
|
||||||
|
}
|
||||||
|
ctx.bits[48] = (short)(ctx.bits[48] ^ ctx.totb);
|
||||||
|
for (int i = 0; i < 49; i++) ctx.temp[ctx.array2[i]] = ctx.bits[i];
|
||||||
|
for (int i = 0; i < 49; i++) ctx.bits[i] = ctx.temp[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Decrypt a 49-bit frame (original flow) */
|
||||||
|
static void decrypt_frame_49(short frame_bits_in[49]) {
|
||||||
|
for (int i = 0; i < 49; i++) ctx.bits[i] = frame_bits_in[i];
|
||||||
|
for (int i = 0; i < 49; i++) ctx.temp[i] = ctx.bits[ctx.array2[i]];
|
||||||
|
for (int i = 0; i < 49; i++) ctx.bits[i] = ctx.temp[i];
|
||||||
|
ctx.ptconvert = 0;
|
||||||
|
binhex(&ctx, ctx.bits, 48);
|
||||||
|
pc4decrypt(&ctx);
|
||||||
|
for (int q = 0; q < 6; q++) {
|
||||||
|
uint8_t w = (uint8_t)(q * 8);
|
||||||
|
hexbin(&ctx, ctx.bits, w, ctx.convert[q]);
|
||||||
|
}
|
||||||
|
ctx.bits[48] = (short)(ctx.bits[48] ^ ctx.totb);
|
||||||
|
for (int i = 0; i < 49; i++) ctx.temp[ctx.array[i]] = ctx.bits[i];
|
||||||
|
for (int i = 0; i < 49; i++) ctx.bits[i] = ctx.temp[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Convert 64-bit integer to bytes (big-endian) */
|
||||||
|
static void u64_to_bytes_be(uint64_t val, unsigned char *out) {
|
||||||
|
for (int i = 0; i < 8; i++) {
|
||||||
|
out[i] = (unsigned char)((val >> (56 - 8 * i)) & 0xFF);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
147
include/pc5.h
Normal file
147
include/pc5.h
Normal file
@@ -0,0 +1,147 @@
|
|||||||
|
#include <stdint.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
#ifndef BAOFENG_AP
|
||||||
|
#define BAOFENG_AP
|
||||||
|
|
||||||
|
#define nbround 254
|
||||||
|
#define n1 264
|
||||||
|
|
||||||
|
#define UNUSEDPC5(x) ((void)x)
|
||||||
|
|
||||||
|
/* Structure holding all PC5 state variables */
|
||||||
|
typedef struct {
|
||||||
|
short bits[49], temp[49];
|
||||||
|
uint8_t ptconvert;
|
||||||
|
uint8_t convert[7];
|
||||||
|
uint8_t perm[16][256];
|
||||||
|
uint8_t new1[256];
|
||||||
|
uint8_t array[49];
|
||||||
|
uint8_t array2[49];
|
||||||
|
uint8_t decal[nbround];
|
||||||
|
uint8_t rngxor[nbround][3];
|
||||||
|
uint8_t rngxor2[nbround][3];
|
||||||
|
uint8_t rounds;
|
||||||
|
uint8_t tab[256];
|
||||||
|
uint8_t inv[256];
|
||||||
|
uint8_t permut[3][3];
|
||||||
|
uint64_t bb;
|
||||||
|
uint64_t x;
|
||||||
|
uint8_t tot[3];
|
||||||
|
uint8_t l[2][3], r[2][3];
|
||||||
|
uint8_t y, totb;
|
||||||
|
uint32_t result;
|
||||||
|
uint8_t xyz, count;
|
||||||
|
uint8_t keys[16];
|
||||||
|
unsigned char array_arc4[256];
|
||||||
|
int i_arc4, j_arc4;
|
||||||
|
int x1, x2, i;
|
||||||
|
unsigned char h2[n1];
|
||||||
|
unsigned char h1[n1*3];
|
||||||
|
uint8_t numbers[25];
|
||||||
|
} PC5Context;
|
||||||
|
|
||||||
|
/* Global context accessible from all .c files */
|
||||||
|
extern PC5Context ctxpc5;
|
||||||
|
|
||||||
|
/* Public API */
|
||||||
|
void create_keys_pc5(PC5Context *ctxpc5, unsigned char key1[], size_t size1);
|
||||||
|
void pc5encrypt(PC5Context *ctxpc5);
|
||||||
|
void pc5decrypt(PC5Context *ctxpc5);
|
||||||
|
void binhexpc5(PC5Context *ctxpc5, short *z, int length);
|
||||||
|
void hexbinpc5(PC5Context *ctxpc5, short *q, uint8_t w, uint8_t hex);
|
||||||
|
static void u64_to_bytes_be_pc5(uint64_t val, unsigned char *out);
|
||||||
|
|
||||||
|
/* Encrypt a 49-bit frame using PC5 algorithm (original flow) */
|
||||||
|
static void encrypt_frame_49_pc5(short frame_bits_in[49]) {
|
||||||
|
// Only process first 24 bits for encryption, rest are XORed
|
||||||
|
ctxpc5.ptconvert = 0;
|
||||||
|
binhexpc5(&ctxpc5, frame_bits_in, 24);
|
||||||
|
|
||||||
|
uint8_t convert[6];
|
||||||
|
|
||||||
|
// Store first 3 bytes in convert
|
||||||
|
for (int i = 0; i < 3; i++) convert[i] = ctxpc5.convert[i];
|
||||||
|
|
||||||
|
// Split each byte into two 4-bit nibbles
|
||||||
|
ctxpc5.convert[0] = convert[0] >> 4;
|
||||||
|
ctxpc5.convert[1] = convert[0] & 0xF;
|
||||||
|
ctxpc5.convert[2] = convert[1] >> 4;
|
||||||
|
ctxpc5.convert[3] = convert[1] & 0xF;
|
||||||
|
ctxpc5.convert[4] = convert[2] >> 4;
|
||||||
|
ctxpc5.convert[5] = convert[2] & 0xF;
|
||||||
|
|
||||||
|
pc5encrypt(&ctxpc5);
|
||||||
|
|
||||||
|
// Store encrypted nibbles back in convert
|
||||||
|
for (int i = 0; i < 6; i++) convert[i] = ctxpc5.convert[i];
|
||||||
|
|
||||||
|
// Recombine nibbles into bytes
|
||||||
|
ctxpc5.convert[0] = (convert[0] << 4) + convert[1];
|
||||||
|
ctxpc5.convert[1] = (convert[2] << 4) + convert[3];
|
||||||
|
ctxpc5.convert[2] = (convert[4] << 4) + convert[5];
|
||||||
|
|
||||||
|
// Convert back to bits for first 24 bits
|
||||||
|
for (int q = 0; q < 3; q++) {
|
||||||
|
uint8_t w = (uint8_t)(q * 8);
|
||||||
|
hexbinpc5(&ctxpc5, frame_bits_in, w, ctxpc5.convert[q]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// XOR the remaining bits (positions 24 to 48)
|
||||||
|
for (int i = 24; i < 49; i++) {
|
||||||
|
frame_bits_in[i] = (short)(frame_bits_in[i] ^ ctxpc5.numbers[i - 24]);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < 49; i++) ctxpc5.bits[i] = frame_bits_in[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Decrypt a 49-bit frame using PC5 algorithm (original flow) */
|
||||||
|
static void decrypt_frame_49_pc5(short frame_bits_in[49]) {
|
||||||
|
// XOR the remaining bits (positions 24 to 48) first
|
||||||
|
for (int i = 24; i < 49; i++) {
|
||||||
|
frame_bits_in[i] = (short)(frame_bits_in[i] ^ ctxpc5.numbers[i - 24]);
|
||||||
|
}
|
||||||
|
|
||||||
|
ctxpc5.ptconvert = 0;
|
||||||
|
binhexpc5(&ctxpc5, frame_bits_in, 24);
|
||||||
|
|
||||||
|
uint8_t convert[6];
|
||||||
|
|
||||||
|
// Store first 3 bytes in convert
|
||||||
|
for (int i = 0; i < 3; i++) convert[i] = ctxpc5.convert[i];
|
||||||
|
|
||||||
|
// Split each byte into two 4-bit nibbles
|
||||||
|
ctxpc5.convert[0] = convert[0] >> 4;
|
||||||
|
ctxpc5.convert[1] = convert[0] & 0xF;
|
||||||
|
ctxpc5.convert[2] = convert[1] >> 4;
|
||||||
|
ctxpc5.convert[3] = convert[1] & 0xF;
|
||||||
|
ctxpc5.convert[4] = convert[2] >> 4;
|
||||||
|
ctxpc5.convert[5] = convert[2] & 0xF;
|
||||||
|
|
||||||
|
pc5decrypt(&ctxpc5);
|
||||||
|
|
||||||
|
// Store decrypted nibbles back in convert
|
||||||
|
for (int i = 0; i < 6; i++) convert[i] = ctxpc5.convert[i];
|
||||||
|
|
||||||
|
// Recombine nibbles into bytes
|
||||||
|
ctxpc5.convert[0] = (convert[0] << 4) + convert[1];
|
||||||
|
ctxpc5.convert[1] = (convert[2] << 4) + convert[3];
|
||||||
|
ctxpc5.convert[2] = (convert[4] << 4) + convert[5];
|
||||||
|
|
||||||
|
// Convert back to bits for first 24 bits
|
||||||
|
for (int q = 0; q < 3; q++) {
|
||||||
|
uint8_t w = (uint8_t)(q * 8);
|
||||||
|
hexbinpc5(&ctxpc5, frame_bits_in, w, ctxpc5.convert[q]);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < 49; i++) ctxpc5.bits[i] = frame_bits_in[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Convert 64-bit integer to bytes (big-endian) */
|
||||||
|
static void u64_to_bytes_be_pc5(uint64_t val, unsigned char *out) {
|
||||||
|
for (int i = 0; i < 8; i++) {
|
||||||
|
out[i] = (unsigned char)((val >> (56 - 8 * i)) & 0xFF);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
43
include/rc2.h
Normal file
43
include/rc2.h
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
#ifndef RETEVIS_AP
|
||||||
|
#define RETEVIS_AP
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include "dsd.h"
|
||||||
|
|
||||||
|
#define n1 264
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint8_t array_rc4[256];
|
||||||
|
int i_rc4, j_rc4;
|
||||||
|
uint64_t x;
|
||||||
|
uint8_t xyz, count;
|
||||||
|
uint64_t bb;
|
||||||
|
} RC4State;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int x1, x2;
|
||||||
|
unsigned char h2[n1];
|
||||||
|
unsigned char h1[n1 * 3];
|
||||||
|
} MD2State;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint16_t xkey[64];
|
||||||
|
uint8_t plain[8];
|
||||||
|
uint8_t cipher[8];
|
||||||
|
} RC2State;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
RC4State rc4;
|
||||||
|
MD2State md2;
|
||||||
|
RC2State rc2;
|
||||||
|
uint64_t internal_state;
|
||||||
|
uint64_t internal_zero;
|
||||||
|
uint8_t keys[16];
|
||||||
|
} CryptoContext;
|
||||||
|
|
||||||
|
/* Public API */
|
||||||
|
void create_keys_rc2(CryptoContext* ctx, unsigned char key1[], size_t size1);
|
||||||
|
void encryption_rc2(CryptoContext* ctx, uint8_t s1[49]);
|
||||||
|
void decrypt_rc2(CryptoContext* ctx, uint8_t bits[49]);
|
||||||
|
|
||||||
|
#endif
|
||||||
48
include/synctype.h
Normal file
48
include/synctype.h
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
#ifndef SYNCTYPE_H
|
||||||
|
#define SYNCTYPE_H
|
||||||
|
|
||||||
|
static const char * SyncTypes[44] = {
|
||||||
|
"P25p1",
|
||||||
|
"P25p1",
|
||||||
|
"X2TDMA DATA",
|
||||||
|
"X2TDMA DATA",
|
||||||
|
"X2TDMA VOICE",
|
||||||
|
"X2TDMA VOICE",
|
||||||
|
"DSTAR", //voice
|
||||||
|
"DSTAR", //voice
|
||||||
|
"M17",
|
||||||
|
"M17",
|
||||||
|
"DMR", //10
|
||||||
|
"DMR",
|
||||||
|
"DMR",
|
||||||
|
"DMR",
|
||||||
|
"EDACS/PV",
|
||||||
|
"EDACS/PV",
|
||||||
|
"M17", //M17 Voice Stream
|
||||||
|
"M17", //M17 Voice Stream
|
||||||
|
"DSTAR", //header
|
||||||
|
"DSTAR", //header
|
||||||
|
"dPMR", //20
|
||||||
|
"dPMR",
|
||||||
|
"dPMR",
|
||||||
|
"dPMR",
|
||||||
|
"dPMR",
|
||||||
|
"dPMR",
|
||||||
|
"dPMR",
|
||||||
|
"dPMR",
|
||||||
|
"NXDN",
|
||||||
|
"NXDN",
|
||||||
|
"YSF", //30
|
||||||
|
"YSF", //31
|
||||||
|
"DMR",
|
||||||
|
"DMR",
|
||||||
|
"DMR",
|
||||||
|
"P25p2",
|
||||||
|
"P25p2",
|
||||||
|
"EDACS/PV", //37
|
||||||
|
"EDACS/PV", //38
|
||||||
|
"ANALOG", //39 Generic Sync Types
|
||||||
|
"DIGITAL" //40 Generic Sync Types
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
10
install.sh
10
install.sh
@@ -1,12 +1,8 @@
|
|||||||
sudo cp tone8.wav /usr/share/
|
#!/bin/bash
|
||||||
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
|
mkdir build
|
||||||
cd build
|
cd build
|
||||||
cmake ..
|
cmake ..
|
||||||
make -j `nproc`
|
make -j $(nproc)
|
||||||
sudo make install
|
sudo make install
|
||||||
sudo ldconfig
|
sudo ldconfig
|
||||||
44
package.nix
Normal file
44
package.nix
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
{ lib
|
||||||
|
, stdenv
|
||||||
|
, cmake
|
||||||
|
, mbelib
|
||||||
|
, libsndfile
|
||||||
|
, ncurses
|
||||||
|
, pulseaudio
|
||||||
|
, rtl-sdr
|
||||||
|
, codec2
|
||||||
|
, portaudioSupport ? true
|
||||||
|
, portaudio ? null
|
||||||
|
}:
|
||||||
|
|
||||||
|
assert portaudioSupport -> portaudio != null;
|
||||||
|
|
||||||
|
stdenv.mkDerivation {
|
||||||
|
name = "dsd-fme";
|
||||||
|
|
||||||
|
src = ./.;
|
||||||
|
|
||||||
|
nativeBuildInputs = [ cmake ];
|
||||||
|
buildInputs = [
|
||||||
|
mbelib
|
||||||
|
libsndfile
|
||||||
|
rtl-sdr
|
||||||
|
ncurses.dev
|
||||||
|
pulseaudio.dev
|
||||||
|
codec2
|
||||||
|
] ++ lib.optionals portaudioSupport [ portaudio ];
|
||||||
|
|
||||||
|
doCheck = true;
|
||||||
|
|
||||||
|
meta = with lib; {
|
||||||
|
description = "Digital Speech Decoder - Florida Man Edition";
|
||||||
|
longDescription = ''
|
||||||
|
DSD is able to decode several digital voice formats from discriminator
|
||||||
|
tap audio and synthesize the decoded speech. Speech synthesis requires
|
||||||
|
mbelib, which is a separate package.
|
||||||
|
'';
|
||||||
|
homepage = "https://github.com/lwvmobile/dsd-fme";
|
||||||
|
license = licenses.mit;
|
||||||
|
platforms = platforms.unix;
|
||||||
|
};
|
||||||
|
}
|
||||||
330
patch/extra/ghost_box_wip3_awd.patch
Normal file
330
patch/extra/ghost_box_wip3_awd.patch
Normal file
@@ -0,0 +1,330 @@
|
|||||||
|
diff --git a/include/dsd.h b/include/dsd.h
|
||||||
|
index 4a75702..3cf085e 100644
|
||||||
|
--- a/include/dsd.h
|
||||||
|
+++ b/include/dsd.h
|
||||||
|
@@ -317,6 +317,7 @@ typedef struct
|
||||||
|
long int rtl_rms;
|
||||||
|
int monitor_input_audio;
|
||||||
|
int analog_only;
|
||||||
|
+ int ghosts_only;
|
||||||
|
int pulse_raw_rate_in;
|
||||||
|
int pulse_raw_rate_out;
|
||||||
|
int pulse_digi_rate_in;
|
||||||
|
@@ -1342,6 +1343,8 @@ void rtl_udp_tune(dsd_opts * opts, dsd_state * state, long int frequency);
|
||||||
|
long int GetCurrentFreq(int sockfd);
|
||||||
|
bool SetFreq(int sockfd, long int freq);
|
||||||
|
bool SetModulation(int sockfd, int bandwidth);
|
||||||
|
+bool SetModulationWFM(int sockfd, int bandwidth);
|
||||||
|
+void death (dsd_opts * opts, dsd_state * state);
|
||||||
|
//commands below unique to GQRX only, not usable on SDR++
|
||||||
|
bool GetSignalLevel(int sockfd, double *dBFS);
|
||||||
|
bool GetSquelchLevel(int sockfd, double *dBFS);
|
||||||
|
diff --git a/src/3.c b/src/3.c
|
||||||
|
index e104993..b9033bd 100644
|
||||||
|
--- a/src/3.c
|
||||||
|
+++ b/src/3.c
|
||||||
|
@@ -591,4 +591,176 @@ long int raw_rms(int16_t *samples, int len, int step) //use samplespersymbol as
|
||||||
|
rms = (long int)sqrt((p-err) / len);
|
||||||
|
if (rms < 0) rms = 150;
|
||||||
|
return rms;
|
||||||
|
-}
|
||||||
|
\ No newline at end of file
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+
|
||||||
|
+//Ghosts
|
||||||
|
+void death (dsd_opts * opts, dsd_state * state)
|
||||||
|
+{
|
||||||
|
+ int i, x, result = 0;
|
||||||
|
+ short ghosts[960];
|
||||||
|
+ short spooks[960];
|
||||||
|
+ short demons[960];
|
||||||
|
+ short sample = 0;
|
||||||
|
+
|
||||||
|
+ memset (ghosts, 0, 960*sizeof(short));
|
||||||
|
+ memset (spooks, 0, 960*sizeof(short));
|
||||||
|
+ memset (demons, 0, 960*sizeof(short));
|
||||||
|
+
|
||||||
|
+ while (!exitflag) //while the software is running
|
||||||
|
+ {
|
||||||
|
+ //death on speaks at 48k/1 short output
|
||||||
|
+ if (opts->audio_in_type == 0)
|
||||||
|
+ {
|
||||||
|
+ for (i = 0; i < 960; i++)
|
||||||
|
+ {
|
||||||
|
+ pa_simple_read(opts->pulse_digi_dev_in, &sample, 2, NULL );
|
||||||
|
+ ghosts[i] = sample;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ for (i = 0; i < 960; i++)
|
||||||
|
+ {
|
||||||
|
+ pa_simple_read(opts->pulse_digi_dev_in, &sample, 2, NULL );
|
||||||
|
+ spooks[i] = sample;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ for (i = 0; i < 960; i++)
|
||||||
|
+ {
|
||||||
|
+ pa_simple_read(opts->pulse_digi_dev_in, &sample, 2, NULL );
|
||||||
|
+ demons[i] = sample;
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ if (opts->audio_in_type == 8)
|
||||||
|
+ {
|
||||||
|
+ for (i = 0; i < 960; i++)
|
||||||
|
+ {
|
||||||
|
+ result = sf_read_short(opts->tcp_file_in, &sample, 1);
|
||||||
|
+ if (result == 0)
|
||||||
|
+ {
|
||||||
|
+ sf_close(opts->tcp_file_in);
|
||||||
|
+ fprintf (stderr, "Connection to the Underworld Severed.\n");
|
||||||
|
+ fprintf (stderr, "Closing Death Speech Decoder.\n");
|
||||||
|
+ cleanupAndExit(opts, state);
|
||||||
|
+ }
|
||||||
|
+ ghosts[i] = sample;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ for (i = 0; i < 960; i++)
|
||||||
|
+ {
|
||||||
|
+ result = sf_read_short(opts->tcp_file_in, &sample, 1);
|
||||||
|
+ if (result == 0)
|
||||||
|
+ {
|
||||||
|
+ sf_close(opts->tcp_file_in);
|
||||||
|
+ fprintf (stderr, "Connection to the Underworld Severed.\n");
|
||||||
|
+ fprintf (stderr, "Closing Death Speech Decoder.\n");
|
||||||
|
+ cleanupAndExit(opts, state);
|
||||||
|
+ }
|
||||||
|
+ spooks[i] = sample;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ for (i = 0; i < 960; i++)
|
||||||
|
+ {
|
||||||
|
+ result = sf_read_short(opts->tcp_file_in, &sample, 1);
|
||||||
|
+ if (result == 0)
|
||||||
|
+ {
|
||||||
|
+ sf_close(opts->tcp_file_in);
|
||||||
|
+ fprintf (stderr, "Connection to the Underworld Severed.\n");
|
||||||
|
+ fprintf (stderr, "Closing Death Speech Decoder.\n");
|
||||||
|
+ cleanupAndExit(opts, state);
|
||||||
|
+ }
|
||||||
|
+ demons[i] = sample;
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ //RTL Input
|
||||||
|
+ #ifdef USE_RTLSDR
|
||||||
|
+ if (opts->audio_in_type == 3)
|
||||||
|
+ {
|
||||||
|
+ for (i = 0; i < 960; i++)
|
||||||
|
+ {
|
||||||
|
+ get_rtlsdr_sample(&sample, opts, state);
|
||||||
|
+ ghosts[i] = sample;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ for (i = 0; i < 960; i++)
|
||||||
|
+ {
|
||||||
|
+ get_rtlsdr_sample(&sample, opts, state);
|
||||||
|
+ spooks[i] = sample;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ for (i = 0; i < 960; i++)
|
||||||
|
+ {
|
||||||
|
+ get_rtlsdr_sample(&sample, opts, state);
|
||||||
|
+ demons[i] = sample;
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+ #endif
|
||||||
|
+
|
||||||
|
+ //The Dead Don't Like OSS input yet
|
||||||
|
+
|
||||||
|
+ //Listen to the Howls of the Deceased
|
||||||
|
+ if (opts->audio_out_type == 0 && opts->slot1_on == 1)
|
||||||
|
+ {
|
||||||
|
+ pa_simple_write(opts->pulse_raw_dev_out, ghosts, 960*2, NULL);
|
||||||
|
+ pa_simple_write(opts->pulse_raw_dev_out, spooks, 960*2, NULL);
|
||||||
|
+ pa_simple_write(opts->pulse_raw_dev_out, demons, 960*2, NULL);
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ if (opts->audio_out_type == 8) //UDP Audio
|
||||||
|
+ {
|
||||||
|
+ udp_socket_blasterA (opts, state, 960*2, ghosts);
|
||||||
|
+ udp_socket_blasterA (opts, state, 960*2, spooks);
|
||||||
|
+ udp_socket_blasterA (opts, state, 960*2, demons);
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ //added a condition check so that if OSS output and 8K, switches to 48K when opening OSS
|
||||||
|
+ if (opts->audio_out_type == 5 && opts->floating_point == 0 && opts->slot1_on == 1)
|
||||||
|
+ {
|
||||||
|
+ write (opts->audio_out_fd, ghosts, 960*2);
|
||||||
|
+ write (opts->audio_out_fd, spooks, 960*2);
|
||||||
|
+ write (opts->audio_out_fd, demons, 960*2);
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ //STDOUT -- I don't see the harm of adding this here, will be fine for analog only or digital only (non-mixed analog and digital)
|
||||||
|
+ if (opts->audio_out_type == 1 && opts->floating_point == 0 && opts->slot1_on == 1)
|
||||||
|
+ {
|
||||||
|
+ write (opts->audio_out_fd, ghosts, 960*2);
|
||||||
|
+ write (opts->audio_out_fd, spooks, 960*2);
|
||||||
|
+ write (opts->audio_out_fd, demons, 960*2);
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ //Undulate the Crystal Ball
|
||||||
|
+ if (x >= opts->trunk_hangtime)
|
||||||
|
+ {
|
||||||
|
+ long int spook_channel = state->trunk_lcn_freq[0];
|
||||||
|
+
|
||||||
|
+ //rigctl
|
||||||
|
+ if (opts->use_rigctl == 1)
|
||||||
|
+ {
|
||||||
|
+ if (opts->setmod_bw != 0 ) SetModulationWFM(opts->rigctl_sockfd, opts->setmod_bw);
|
||||||
|
+ SetFreq(opts->rigctl_sockfd, spook_channel);
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ //rtl
|
||||||
|
+ if (opts->audio_in_type == 3)
|
||||||
|
+ {
|
||||||
|
+ #ifdef USE_RTLSDR
|
||||||
|
+ rtl_dev_tune(opts, spook_channel);
|
||||||
|
+ #endif
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ //
|
||||||
|
+ state->trunk_lcn_freq[0] += 200000;
|
||||||
|
+
|
||||||
|
+ if (state->trunk_lcn_freq[0] > 106100000)
|
||||||
|
+ state->trunk_lcn_freq[0] = 87900000;
|
||||||
|
+
|
||||||
|
+ x = 0;
|
||||||
|
+
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ x++;
|
||||||
|
+
|
||||||
|
+ } //end while loop
|
||||||
|
+} //end ghosts
|
||||||
|
\ No newline at end of file
|
||||||
|
diff --git a/src/dsd_main.c b/src/dsd_main.c
|
||||||
|
index ca878e9..f14995d 100644
|
||||||
|
--- a/src/dsd_main.c
|
||||||
|
+++ b/src/dsd_main.c
|
||||||
|
@@ -696,6 +696,7 @@ initOpts (dsd_opts * opts)
|
||||||
|
|
||||||
|
opts->monitor_input_audio = 0; //enable with -8
|
||||||
|
opts->analog_only = 0; //only turned on with -fA
|
||||||
|
+ opts->ghosts_only = 0; //ghostbox mode with -fG
|
||||||
|
|
||||||
|
opts->inverted_p2 = 0;
|
||||||
|
opts->p2counter = 0;
|
||||||
|
@@ -1358,6 +1359,7 @@ usage ()
|
||||||
|
printf ("Decoder options:\n");
|
||||||
|
printf (" -fa Auto Detection\n");
|
||||||
|
printf (" -fA Passive Analog Audio Monitor\n");
|
||||||
|
+ printf (" -fG Ghosts, Demons, Specters, Ghouls, and Skeletons (Ghost Box)\n");
|
||||||
|
printf (" -ft TDMA Trunking P25p1 Control and Voice, P25p2 Trunked Channels, and DMR\n");
|
||||||
|
printf (" -fs DMR TDMA BS and MS Simplex\n");
|
||||||
|
printf (" -f1 Decode only P25 Phase 1\n");
|
||||||
|
@@ -2172,6 +2174,35 @@ main (int argc, char **argv)
|
||||||
|
sprintf (opts.output_name, "Analog Monitor");
|
||||||
|
fprintf (stderr,"Only Monitoring Passive Analog Signal\n");
|
||||||
|
}
|
||||||
|
+ else if (optarg[0] == 'G') //listen to spooky scary skeletons
|
||||||
|
+ {
|
||||||
|
+ opts.frame_dstar = 0;
|
||||||
|
+ opts.frame_x2tdma = 0;
|
||||||
|
+ opts.frame_p25p1 = 0;
|
||||||
|
+ opts.frame_p25p2 = 0;
|
||||||
|
+ opts.frame_nxdn48 = 0;
|
||||||
|
+ opts.frame_nxdn96 = 0;
|
||||||
|
+ opts.frame_dmr = 0;
|
||||||
|
+ opts.frame_dpmr = 0;
|
||||||
|
+ opts.frame_provoice = 0;
|
||||||
|
+ opts.frame_ysf = 0;
|
||||||
|
+ opts.frame_m17 = 0;
|
||||||
|
+ opts.pulse_digi_rate_out = 8000;
|
||||||
|
+ opts.pulse_digi_out_channels = 1;
|
||||||
|
+ opts.dmr_stereo = 0;
|
||||||
|
+ state.dmr_stereo = 0;
|
||||||
|
+ opts.dmr_mono = 0;
|
||||||
|
+ state.rf_mod = 0;
|
||||||
|
+ opts.monitor_input_audio = 1;
|
||||||
|
+ opts.ghosts_only = 1;
|
||||||
|
+ state.trunk_lcn_freq[0] = 87900000; //everybody knows ghosts live on the Broadcast FM band
|
||||||
|
+ opts.setmod_bw = 150000; //Ghosts annunciate clearly with about 150,000 PB
|
||||||
|
+ opts.trunk_hangtime = 0;
|
||||||
|
+ opts.rtlsdr_center_freq = 850000000;
|
||||||
|
+ opts.rtl_bandwidth = 48;
|
||||||
|
+ sprintf (opts.output_name, "Ghost Box");
|
||||||
|
+ fprintf (stderr,"Sounds of the Dead.\n");
|
||||||
|
+ }
|
||||||
|
else if (optarg[0] == 'd')
|
||||||
|
{
|
||||||
|
opts.frame_dstar = 1;
|
||||||
|
@@ -3462,6 +3493,22 @@ main (int argc, char **argv)
|
||||||
|
processM17IPF(&opts, &state);
|
||||||
|
}
|
||||||
|
|
||||||
|
+ else if (opts.ghosts_only == 1)
|
||||||
|
+ {
|
||||||
|
+ #ifdef USE_RTLSDR
|
||||||
|
+ if(opts.audio_in_type == 3)
|
||||||
|
+ open_rtlsdr_stream(&opts);
|
||||||
|
+ #endif
|
||||||
|
+
|
||||||
|
+ if (opts.audio_in_type == 0)
|
||||||
|
+ openPulseInput(&opts);
|
||||||
|
+
|
||||||
|
+ if (opts.audio_out_type == 0)
|
||||||
|
+ openPulseOutput(&opts);
|
||||||
|
+
|
||||||
|
+ death(&opts, &state);
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
diff --git a/src/dsd_rigctl.c b/src/dsd_rigctl.c
|
||||||
|
index 820ac7e..f12bacc 100644
|
||||||
|
--- a/src/dsd_rigctl.c
|
||||||
|
+++ b/src/dsd_rigctl.c
|
||||||
|
@@ -163,6 +163,28 @@ bool SetModulation(int sockfd, int bandwidth)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
+bool SetModulationWFM(int sockfd, int bandwidth)
|
||||||
|
+{
|
||||||
|
+ char buf[BUFSIZE];
|
||||||
|
+ //the bandwidth is now a user/system based configurable variable
|
||||||
|
+ sprintf (buf, "M WFM %d\n", bandwidth); //SDR++ has changed the token from FM to NFM, even if Ryzerth fixes it later, users may still have an older version
|
||||||
|
+ Send(sockfd, buf);
|
||||||
|
+ Recv(sockfd, buf);
|
||||||
|
+
|
||||||
|
+ //if it fails the first time, send the other token instead
|
||||||
|
+ if (strcmp(buf, "RPRT 1\n") == 0 ) //sdr++ has a linebreak here, is that in all versions of the protocol?
|
||||||
|
+ {
|
||||||
|
+ sprintf (buf, "M WFM %d\n", bandwidth); //anything not SDR++
|
||||||
|
+ Send(sockfd, buf);
|
||||||
|
+ Recv(sockfd, buf);
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ if (strcmp(buf, "RPRT 1\n") == 0 )
|
||||||
|
+ return false;
|
||||||
|
+
|
||||||
|
+ return true;
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
bool GetSignalLevel(int sockfd, double *dBFS)
|
||||||
|
{
|
||||||
|
char buf[BUFSIZE];
|
||||||
|
diff --git a/src/rtl_sdr_fm.cpp b/src/rtl_sdr_fm.cpp
|
||||||
|
index ad04667..dd6566c 100644
|
||||||
|
--- a/src/rtl_sdr_fm.cpp
|
||||||
|
+++ b/src/rtl_sdr_fm.cpp
|
||||||
|
@@ -1034,7 +1034,7 @@ void open_rtlsdr_stream(dsd_opts *opts)
|
||||||
|
//init with low pass if decoding P25 or EDACS/Provoice
|
||||||
|
if (opts->frame_p25p1 == 1 || opts->frame_p25p2 == 1 || opts->frame_provoice == 1)
|
||||||
|
demod_init_ro2(&demod);
|
||||||
|
- else if (opts->analog_only == 1 || opts->m17encoder == 1)
|
||||||
|
+ else if (opts->analog_only == 1 || opts->m17encoder == 1 || opts->ghosts_only == 1)
|
||||||
|
demod_init_analog(&demod);
|
||||||
|
else demod_init(&demod);
|
||||||
|
output_init(&output);
|
||||||
257
patch/moto_type2_starter_pack.patch
Normal file
257
patch/moto_type2_starter_pack.patch
Normal file
@@ -0,0 +1,257 @@
|
|||||||
|
diff --git a/include/dsd.h b/include/dsd.h
|
||||||
|
index 4a75702..355837f 100644
|
||||||
|
--- a/include/dsd.h
|
||||||
|
+++ b/include/dsd.h
|
||||||
|
@@ -357,6 +357,8 @@ typedef struct
|
||||||
|
int frame_m17;
|
||||||
|
int inverted_m17;
|
||||||
|
|
||||||
|
+ int frame_typeii;
|
||||||
|
+
|
||||||
|
FILE *symbolfile;
|
||||||
|
int call_alert;
|
||||||
|
|
||||||
|
@@ -989,6 +991,10 @@ typedef struct
|
||||||
|
#define INV_DPMR_FRAME_SYNC_3 "311313111133"
|
||||||
|
#define INV_DPMR_FRAME_SYNC_4 "111333331133131131111313"
|
||||||
|
|
||||||
|
+//Motorola Type II Sync Pattern 0xAC binary 1010 1100
|
||||||
|
+#define TYPE_II_SYNC "13131133" //baesd on what getDibit returns
|
||||||
|
+#define TYPE_II_SINV "31313311" //baesd on what getDibit returns
|
||||||
|
+
|
||||||
|
/*
|
||||||
|
* function prototypes
|
||||||
|
*/
|
||||||
|
@@ -1357,6 +1363,9 @@ void edacs(dsd_opts * opts, dsd_state * state);
|
||||||
|
unsigned long long int edacs_bch (unsigned long long int message);
|
||||||
|
void eot_cc(dsd_opts * opts, dsd_state * state); //end of TX return to CC
|
||||||
|
|
||||||
|
+//Type II
|
||||||
|
+void type_ii(dsd_opts * opts, dsd_state * state);
|
||||||
|
+
|
||||||
|
//Generic Tuning Functions
|
||||||
|
void return_to_cc (dsd_opts * opts, dsd_state * state);
|
||||||
|
|
||||||
|
diff --git a/src/dsd_dibit.c b/src/dsd_dibit.c
|
||||||
|
index 5424f7a..9b403cf 100644
|
||||||
|
--- a/src/dsd_dibit.c
|
||||||
|
+++ b/src/dsd_dibit.c
|
||||||
|
@@ -222,13 +222,14 @@ invert_dibit(int dibit)
|
||||||
|
int digitize (dsd_opts* opts, dsd_state* state, int symbol)
|
||||||
|
{
|
||||||
|
// determine dibit state
|
||||||
|
- if ((state->synctype == 6) || (state->synctype == 14)|| (state->synctype == 18) || (state->synctype == 37))
|
||||||
|
+ if ((state->synctype == 6) || (state->synctype == 14)|| (state->synctype == 18) || (state->synctype == 37) || (state->synctype == 40))
|
||||||
|
|
||||||
|
{
|
||||||
|
// 6 +D-STAR
|
||||||
|
// 14 +ProVoice
|
||||||
|
// 18 +D-STAR_HD
|
||||||
|
// 37 +EDACS
|
||||||
|
+ // 41 +TypeII
|
||||||
|
|
||||||
|
if (symbol > state->center)
|
||||||
|
{
|
||||||
|
@@ -243,12 +244,13 @@ int digitize (dsd_opts* opts, dsd_state* state, int symbol)
|
||||||
|
return (1); // +3
|
||||||
|
}
|
||||||
|
}
|
||||||
|
- else if ((state->synctype == 7) || (state->synctype == 15)|| (state->synctype == 19) || (state->synctype == 38))
|
||||||
|
+ else if ((state->synctype == 7) || (state->synctype == 15)|| (state->synctype == 19) || (state->synctype == 38) || (state->synctype == 41))
|
||||||
|
{
|
||||||
|
// 7 -D-STAR
|
||||||
|
// 15 -ProVoice
|
||||||
|
// 19 -D-STAR_HD
|
||||||
|
// 38 -EDACS
|
||||||
|
+ // 41 -TypeII
|
||||||
|
|
||||||
|
if (symbol > state->center)
|
||||||
|
{
|
||||||
|
diff --git a/src/dsd_frame.c b/src/dsd_frame.c
|
||||||
|
index 577169c..58fa07c 100644
|
||||||
|
--- a/src/dsd_frame.c
|
||||||
|
+++ b/src/dsd_frame.c
|
||||||
|
@@ -269,6 +269,12 @@ processFrame (dsd_opts * opts, dsd_state * state)
|
||||||
|
processYSF(opts, state);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
+ //TypeII
|
||||||
|
+ else if (state->synctype == 40 || state->synctype == 41)
|
||||||
|
+ {
|
||||||
|
+ type_ii(opts, state);
|
||||||
|
+ return;
|
||||||
|
+ }
|
||||||
|
//M17
|
||||||
|
else if ((state->synctype == 16) || (state->synctype == 9) || (state->synctype == 17) || (state->synctype == 8) ||
|
||||||
|
(state->synctype == 76) || (state->synctype == 77) || (state->synctype == 86) || (state->synctype == 87) ||
|
||||||
|
diff --git a/src/dsd_frame_sync.c b/src/dsd_frame_sync.c
|
||||||
|
index e10f3cc..7f5fbf5 100644
|
||||||
|
--- a/src/dsd_frame_sync.c
|
||||||
|
+++ b/src/dsd_frame_sync.c
|
||||||
|
@@ -117,6 +117,8 @@ getFrameSync (dsd_opts * opts, dsd_state * state)
|
||||||
|
* 36 = -P25 P2
|
||||||
|
* 37 = +EDACS
|
||||||
|
* 38 = -EDACS
|
||||||
|
+ * 40 = +Type2
|
||||||
|
+ * 41 = -Type2
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
@@ -205,7 +207,7 @@ getFrameSync (dsd_opts * opts, dsd_state * state)
|
||||||
|
{
|
||||||
|
t_max = 12; //based on Frame_Sync_2 pattern
|
||||||
|
}
|
||||||
|
- else if (opts->frame_m17 == 1)
|
||||||
|
+ else if (opts->frame_m17 == 1 || opts->frame_typeii == 1)
|
||||||
|
{
|
||||||
|
t_max = 8;
|
||||||
|
}
|
||||||
|
@@ -581,6 +583,40 @@ getFrameSync (dsd_opts * opts, dsd_state * state)
|
||||||
|
}
|
||||||
|
//end YSF sync
|
||||||
|
|
||||||
|
+ //Motorola Type II
|
||||||
|
+ strncpy(synctest8, (synctest_p - 7), 8);
|
||||||
|
+ if (opts->frame_typeii == 1)
|
||||||
|
+ {
|
||||||
|
+ if (strcmp(synctest8, TYPE_II_SYNC) == 0)
|
||||||
|
+ {
|
||||||
|
+ if (state->lastsynctype == 40)
|
||||||
|
+ {
|
||||||
|
+ printFrameSync (opts, state, "+Type II", synctest_pos + 1, modulation);
|
||||||
|
+ state->carrier = 1;
|
||||||
|
+ state->offset = synctest_pos;
|
||||||
|
+ state->max = ((state->max) + lmax) / 2;
|
||||||
|
+ state->min = ((state->min) + lmin) / 2;
|
||||||
|
+ state->lastsynctype = 40;
|
||||||
|
+ return (40);
|
||||||
|
+ }
|
||||||
|
+ else state->lastsynctype = 40;
|
||||||
|
+ }
|
||||||
|
+ else if (strcmp(synctest8, TYPE_II_SINV) == 0)
|
||||||
|
+ {
|
||||||
|
+ if (state->lastsynctype == 41)
|
||||||
|
+ {
|
||||||
|
+ printFrameSync (opts, state, "-Type II", synctest_pos + 1, modulation);
|
||||||
|
+ state->carrier = 1;
|
||||||
|
+ state->offset = synctest_pos;
|
||||||
|
+ state->max = ((state->max) + lmax) / 2;
|
||||||
|
+ state->min = ((state->min) + lmin) / 2;
|
||||||
|
+ state->lastsynctype = 41;
|
||||||
|
+ return (41);
|
||||||
|
+ }
|
||||||
|
+ else state->lastsynctype = 41;
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
//M17 Sync -- Just STR and LSF for now
|
||||||
|
strncpy(synctest16, (synctest_p - 15), 16);
|
||||||
|
strncpy(synctest8, (synctest_p - 7), 8);
|
||||||
|
diff --git a/src/dsd_main.c b/src/dsd_main.c
|
||||||
|
index ca878e9..c5a3e95 100644
|
||||||
|
--- a/src/dsd_main.c
|
||||||
|
+++ b/src/dsd_main.c
|
||||||
|
@@ -622,6 +622,7 @@ initOpts (dsd_opts * opts)
|
||||||
|
opts->frame_provoice = 0;
|
||||||
|
opts->frame_ysf = 1;
|
||||||
|
opts->frame_m17 = 0;
|
||||||
|
+ opts->frame_typeii = 0;
|
||||||
|
opts->mod_c4fm = 1;
|
||||||
|
opts->mod_qpsk = 0;
|
||||||
|
opts->mod_gfsk = 0;
|
||||||
|
@@ -1377,6 +1378,7 @@ usage ()
|
||||||
|
printf (" -fe Decode only EDACS EA/ProVoice*\n");
|
||||||
|
printf (" -fE Decode only EDACS EA/ProVoice with ESK 0xA0*\n");
|
||||||
|
printf (" -fm Decode only dPMR*\n");
|
||||||
|
+ printf (" -fT Decode only Type II (Smartnet/Smartzone)*\n");
|
||||||
|
printf (" -l Disable DMR, dPMR, NXDN, M17 input filtering\n");
|
||||||
|
printf (" -u <num> Unvoiced speech quality (default=3)\n");
|
||||||
|
printf (" -xx Expect non-inverted X2-TDMA signal\n");
|
||||||
|
@@ -2431,6 +2433,39 @@ main (int argc, char **argv)
|
||||||
|
opts.rtl_bandwidth = 24;
|
||||||
|
// opts.rtl_gain_value = 36;
|
||||||
|
}
|
||||||
|
+ else if (optarg[0] == 'T') //Motorola Type II
|
||||||
|
+ {
|
||||||
|
+ opts.frame_dstar = 0;
|
||||||
|
+ opts.frame_x2tdma = 0;
|
||||||
|
+ opts.frame_p25p1 = 0;
|
||||||
|
+ opts.frame_p25p2 = 0;
|
||||||
|
+ opts.frame_nxdn48 = 0;
|
||||||
|
+ opts.frame_nxdn96 = 0;
|
||||||
|
+ opts.frame_dmr = 0;
|
||||||
|
+ opts.frame_dpmr = 0;
|
||||||
|
+ opts.frame_provoice = 0;
|
||||||
|
+ opts.frame_ysf = 0;
|
||||||
|
+ opts.frame_m17 = 0;
|
||||||
|
+ opts.frame_typeii = 1;
|
||||||
|
+ ////to maintain 10/4 sample per symbol rate, we need to run at 36000
|
||||||
|
+ //to hit TypeII's 3600 bps rating. BW values in rtl_fm are also modified
|
||||||
|
+ //similarly, but testing will need to be done, this MAY NOT be viable in DSD-FME.
|
||||||
|
+ opts.pulse_digi_rate_in = 36000;
|
||||||
|
+ opts.wav_sample_rate = 36000;
|
||||||
|
+ opts.mod_c4fm = 1;
|
||||||
|
+ opts.mod_qpsk = 0;
|
||||||
|
+ opts.mod_gfsk = 0; //might still be better as gfsk
|
||||||
|
+ state.rf_mod = 2;
|
||||||
|
+ opts.pulse_digi_rate_out = 8000;
|
||||||
|
+ opts.pulse_digi_out_channels = 1;
|
||||||
|
+ opts.dmr_stereo = 0;
|
||||||
|
+ opts.dmr_mono = 0;
|
||||||
|
+ state.dmr_stereo = 0;
|
||||||
|
+ // opts.setmod_bw = 12500;
|
||||||
|
+ sprintf (opts.output_name, "Type II");
|
||||||
|
+ // fprintf (stderr,"Setting symbol rate to 4800 / second\n");
|
||||||
|
+ fprintf (stderr,"Decoding Motorola Type II frames.\n");
|
||||||
|
+ }
|
||||||
|
else if (optarg[0] == '1')
|
||||||
|
{
|
||||||
|
opts.frame_dstar = 0;
|
||||||
|
diff --git a/src/rtl_sdr_fm.cpp b/src/rtl_sdr_fm.cpp
|
||||||
|
index ad04667..954c6dc 100644
|
||||||
|
--- a/src/rtl_sdr_fm.cpp
|
||||||
|
+++ b/src/rtl_sdr_fm.cpp
|
||||||
|
@@ -1025,6 +1025,7 @@ void rtlsdr_sighandler()
|
||||||
|
void open_rtlsdr_stream(dsd_opts *opts)
|
||||||
|
{
|
||||||
|
int r;
|
||||||
|
+ if (opts->frame_typeii == 1) bandwidth_divisor = 36000;
|
||||||
|
rtl_bandwidth = opts->rtl_bandwidth * 1000; //reverted back to straight value
|
||||||
|
bandwidth_multiplier = (bandwidth_divisor / rtl_bandwidth);
|
||||||
|
volume_multiplier = 1; //moved to external handling to be more dynamic
|
||||||
|
diff --git a/src/typeII.c b/src/typeII.c
|
||||||
|
new file mode 100644
|
||||||
|
index 0000000..eb0cd56
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/src/typeII.c
|
||||||
|
@@ -0,0 +1,29 @@
|
||||||
|
+/*-------------------------------------------------------------------------------
|
||||||
|
+ * typeII.c
|
||||||
|
+ * Motorola Type II Decoder (WIP)
|
||||||
|
+ *
|
||||||
|
+ *
|
||||||
|
+ *
|
||||||
|
+ *
|
||||||
|
+ * LWVMOBILE
|
||||||
|
+ * 2024-03 DSD-FME Florida Man Edition
|
||||||
|
+ *-----------------------------------------------------------------------------*/
|
||||||
|
+
|
||||||
|
+#include "dsd.h"
|
||||||
|
+
|
||||||
|
+//Type II
|
||||||
|
+void type_ii(dsd_opts * opts, dsd_state * state)
|
||||||
|
+{
|
||||||
|
+ int i;
|
||||||
|
+ uint8_t t2[80]; memset(t2, 0, sizeof(t2));
|
||||||
|
+
|
||||||
|
+ for (i = 0; i < 76; i++)
|
||||||
|
+ t2[i] = getDibit(opts, state);
|
||||||
|
+
|
||||||
|
+ //debug dump collected bits
|
||||||
|
+ fprintf (stderr, "Frame:");
|
||||||
|
+ for (i = 0; i < 10; i++)
|
||||||
|
+ fprintf (stderr, " %02X", (uint8_t)ConvertBitIntoBytes(&t2[i*8], 8));
|
||||||
|
+
|
||||||
|
+ fprintf (stderr, "\n");
|
||||||
|
+}
|
||||||
|
\ No newline at end of file
|
||||||
15
rebuild.sh
Normal file
15
rebuild.sh
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
#! /bin/bash
|
||||||
|
#
|
||||||
|
clear
|
||||||
|
printf "DSD-FME Digital Speech Decoder - Florida Man Edition
|
||||||
|
Automatic Git Pull and Rebuild\n\n"
|
||||||
|
sleep 1
|
||||||
|
##Open your clone folder##
|
||||||
|
git pull
|
||||||
|
sleep 2
|
||||||
|
##cd into your build folder##
|
||||||
|
cd build
|
||||||
|
cmake ..
|
||||||
|
make -j $(nproc)
|
||||||
|
sudo make install
|
||||||
|
sudo ldconfig
|
||||||
671
src/bptc.c
671
src/bptc.c
@@ -167,223 +167,295 @@ void BPTCDeInterleaveDMRData(uint8_t * Input, uint8_t * Output)
|
|||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @brief : This function extract the 96 bits of a deinteleaved 196 bits
|
* BPTC (196,96) extract — ETSI TS 102 361-1 B.1.1
|
||||||
* buffer using BPTC (196,96)
|
* Two-pass row Hamming(15,11) + column Hamming(13,9).
|
||||||
*
|
* Debug: define BPTC_196x96_DEBUG 1 for row/col correction chatter.
|
||||||
* @param InputDeInteleavedData : Pointer of DMR input data deinterleaved (196 bytes)
|
|
||||||
*
|
|
||||||
* @param DMRDataExtracted : Pointer where the DMR data will be written (96 bytes)
|
|
||||||
*
|
|
||||||
* @return The total number of irrecoverable Hamming check errors
|
|
||||||
*/
|
*/
|
||||||
uint32_t BPTC_196x96_Extract_Data(uint8_t InputDeInteleavedData[196], uint8_t DMRDataExtracted[96], uint8_t R[3])
|
|
||||||
|
// #define BPTC_196x96_DEBUG 1
|
||||||
|
|
||||||
|
uint32_t BPTC_196x96_Extract_Data(uint8_t InputDeInteleavedData[196],
|
||||||
|
uint8_t DMRDataExtracted[96],
|
||||||
|
uint8_t R[3],
|
||||||
|
uint8_t * is_ras)
|
||||||
{
|
{
|
||||||
uint32_t i, j, k;
|
uint32_t i, j, k;
|
||||||
uint8_t DataMatrix[13][15];
|
uint8_t DataMatrix[13][15];
|
||||||
uint8_t LineUncorrected[15];
|
uint8_t LineUncorrected[15];
|
||||||
|
uint8_t LineBefore[15];
|
||||||
uint8_t LineCorrected[11];
|
uint8_t LineCorrected[11];
|
||||||
uint8_t ColumnUncorrected[13];
|
uint8_t ColumnUncorrected[13];
|
||||||
|
uint8_t ColumnBefore[13];
|
||||||
uint8_t ColumnCorrected[9];
|
uint8_t ColumnCorrected[9];
|
||||||
uint32_t HammingIrrecoverableErrorNb = 0;
|
uint32_t HammingIrrecoverableErrorNb = 0;
|
||||||
|
uint32_t row_corr_p1 = 0, col_corr_p1 = 0;
|
||||||
|
uint32_t row_fail_p1 = 0, col_fail_p1 = 0;
|
||||||
|
uint32_t row_corr_p2 = 0, col_corr_p2 = 0;
|
||||||
|
uint32_t row_fail_p2 = 0, col_fail_p2 = 0;
|
||||||
|
|
||||||
/* First step : Reconstitute the BPTC 15x11 matrix
|
UNUSED(row_corr_p1); UNUSED(col_corr_p1);
|
||||||
* Note : Input data shall be deinterleaved */
|
UNUSED(row_fail_p1); UNUSED(col_fail_p1);
|
||||||
k = 1; /* Discard R(3) bit - See DMR standard chapter B1.1 BPTC (196,96) */
|
UNUSED(row_corr_p2); UNUSED(col_corr_p2);
|
||||||
for(i = 0; i < 13; i++)
|
UNUSED(row_fail_p2); UNUSED(col_fail_p2);
|
||||||
|
|
||||||
|
#if BPTC_196x96_DEBUG
|
||||||
|
fprintf (stderr, "\n");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Rebuild 13×15 matrix; discard R(3) at index 0 — DMR B.1.1 */
|
||||||
|
k = 1;
|
||||||
|
for (i = 0; i < 13; i++)
|
||||||
{
|
{
|
||||||
for(j = 0; j < 15; j++)
|
for (j = 0; j < 15; j++)
|
||||||
{
|
{
|
||||||
/* Only the LSBit of the byte is stored */
|
|
||||||
DataMatrix[i][j] = (InputDeInteleavedData[k] & 1);
|
DataMatrix[i][j] = (InputDeInteleavedData[k] & 1);
|
||||||
k++;
|
k++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set to 0 R(0) to R(2) - See DMR standard chapter B1.1 BPTC (196,96) */
|
/* ========== Pass 1: row Hamming(15,11) on rows 0..8 ========== */
|
||||||
// DataMatrix[0][0] = 0; /* R(2) */
|
for (i = 0; i < 9; i++)
|
||||||
// DataMatrix[0][1] = 0; /* R(1) */
|
|
||||||
// DataMatrix[0][2] = 0; /* R(0) */
|
|
||||||
|
|
||||||
/* Init the Hamming (15,11,3) library
|
|
||||||
* Not needed because it has already been done
|
|
||||||
* in the "InitAllFecFunction()" function */
|
|
||||||
//Hamming_15_11_init();
|
|
||||||
|
|
||||||
/* Init the Hamming (13,9,3) library
|
|
||||||
* Not needed because it has already been done
|
|
||||||
* in the "InitAllFecFunction()" function */
|
|
||||||
//Hamming_13_9_init();
|
|
||||||
|
|
||||||
/* Init the Hamming error counter */
|
|
||||||
HammingIrrecoverableErrorNb = 0;
|
|
||||||
|
|
||||||
/* Process the the Hamming (15,11,3) code
|
|
||||||
* check on each line (first time).
|
|
||||||
* Do not check the 4th last lines */
|
|
||||||
for(i = 0; i < 9; i++)
|
|
||||||
{
|
{
|
||||||
/* Get a full line */
|
for (j = 0; j < 15; j++)
|
||||||
for(j = 0; j < 15; j++)
|
|
||||||
{
|
{
|
||||||
LineUncorrected[j] = DataMatrix[i][j];
|
LineUncorrected[j] = DataMatrix[i][j];
|
||||||
|
LineBefore[j] = LineUncorrected[j];
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Apply Hamming (15,11,3) code correction */
|
if (Hamming_15_11_decode(LineUncorrected, LineCorrected, 1) == false)
|
||||||
if(Hamming_15_11_decode(LineUncorrected, LineCorrected, 1) == false)
|
|
||||||
{
|
{
|
||||||
HammingIrrecoverableErrorNb++;
|
HammingIrrecoverableErrorNb++;
|
||||||
}
|
row_fail_p1++;
|
||||||
|
#if BPTC_196x96_DEBUG
|
||||||
/* Re-inject the line in the matrix (only the util data [11 bit],
|
fprintf(stderr, " BPTC196 P1 ROW FAIL row=%u rx=", (unsigned)i);
|
||||||
* not the Hamming part [4 bit]) */
|
for (j = 0; j < 15; j++)
|
||||||
for(j = 0; j < 11; j++)
|
fprintf(stderr, "%u", LineBefore[j] & 1);
|
||||||
{
|
fprintf(stderr, "\n");
|
||||||
DataMatrix[i][j] = LineCorrected[j];
|
#endif
|
||||||
}
|
/* Keep original data bits on failure */
|
||||||
}
|
for (j = 0; j < 11; j++)
|
||||||
|
DataMatrix[i][j] = LineBefore[j];
|
||||||
|
|
||||||
/* Process the the Hamming (15,11,3) code
|
|
||||||
* check on each column/row (first time) */
|
|
||||||
for(i = 0; i < 15; i++)
|
|
||||||
{
|
|
||||||
/* Get a full column */
|
|
||||||
for(j = 0; j < 13; j++)
|
|
||||||
{
|
|
||||||
ColumnUncorrected[j] = DataMatrix[j][i];
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Apply Hamming (15,11,3) code correction */
|
|
||||||
if(Hamming_13_9_decode(ColumnUncorrected, ColumnCorrected, 1) == false)
|
|
||||||
{
|
|
||||||
HammingIrrecoverableErrorNb++;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Re-inject the column in the matrix (only the util data [11 bit],
|
|
||||||
* not the Hamming part [4 bit]) */
|
|
||||||
for(j = 0; j < 9; j++)
|
|
||||||
{
|
|
||||||
DataMatrix[j][i] = ColumnCorrected[j];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* The first Hamming code check has maybe corrected bit
|
|
||||||
* witch can be use to correct other bit, so make the
|
|
||||||
* same operation twice */
|
|
||||||
|
|
||||||
/* Reset the number of irrecoverable errors */
|
|
||||||
HammingIrrecoverableErrorNb = 0;
|
|
||||||
|
|
||||||
|
|
||||||
/* Process the the Hamming (15,11,3) code
|
|
||||||
* check on each line (second time).
|
|
||||||
* Do not check the 4th last lines */
|
|
||||||
for(i = 0; i < 9; i++)
|
|
||||||
{
|
|
||||||
/* Get a full line */
|
|
||||||
for(j = 0; j < 15; j++)
|
|
||||||
{
|
|
||||||
LineUncorrected[j] = DataMatrix[i][j];
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Apply Hamming (15,11,3) code correction */
|
|
||||||
if(Hamming_15_11_decode(LineUncorrected, LineCorrected, 1) == false)
|
|
||||||
{
|
|
||||||
/* Row/Line contains irrecoverable errors */
|
|
||||||
HammingIrrecoverableErrorNb++;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Row/Line contains correct data */
|
/* rxBits were corrected in place; note any flip */
|
||||||
}
|
for (j = 0; j < 15; j++)
|
||||||
|
{
|
||||||
/* Re-inject the line in the matrix (only the util data [11 bit],
|
if ((LineBefore[j] & 1) != (LineUncorrected[j] & 1))
|
||||||
* not the Hamming part [4 bit]) */
|
{
|
||||||
for(j = 0; j < 11; j++)
|
row_corr_p1++;
|
||||||
{
|
#if BPTC_196x96_DEBUG
|
||||||
DataMatrix[i][j] = LineCorrected[j];
|
fprintf(stderr,
|
||||||
|
" BPTC196 P1 ROW CORRECTED row=%u bit=%u %u->%u\n",
|
||||||
|
(unsigned)i, (unsigned)j,
|
||||||
|
(unsigned)(LineBefore[j] & 1),
|
||||||
|
(unsigned)(LineUncorrected[j] & 1));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (j = 0; j < 11; j++)
|
||||||
|
DataMatrix[i][j] = LineCorrected[j];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#if BPTC_196x96_DEBUG
|
||||||
|
if (row_fail_p1 || row_corr_p1)
|
||||||
|
fprintf(stderr, " BPTC196 P1 ROW summary: fail=%u corrected_bits=%u\n",
|
||||||
|
(unsigned)row_fail_p1, (unsigned)row_corr_p1);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* ========== Pass 1: column Hamming(13,9) on cols 0..14 ========== */
|
||||||
/* Process the the Hamming (15,11,3) code
|
for (i = 0; i < 15; i++)
|
||||||
* check on each column/row (second time) */
|
|
||||||
for(i = 0; i < 15; i++)
|
|
||||||
{
|
{
|
||||||
/* Get a full column */
|
for (j = 0; j < 13; j++)
|
||||||
for(j = 0; j < 13; j++)
|
|
||||||
{
|
{
|
||||||
ColumnUncorrected[j] = DataMatrix[j][i];
|
ColumnUncorrected[j] = DataMatrix[j][i];
|
||||||
|
ColumnBefore[j] = ColumnUncorrected[j];
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Apply Hamming (15,11,3) code correction */
|
if (Hamming_13_9_decode(ColumnUncorrected, ColumnCorrected, 1) == false)
|
||||||
if(Hamming_13_9_decode(ColumnUncorrected, ColumnCorrected, 1) == false)
|
|
||||||
{
|
{
|
||||||
/* Row/Line contains irrecoverable errors */
|
|
||||||
HammingIrrecoverableErrorNb++;
|
HammingIrrecoverableErrorNb++;
|
||||||
|
col_fail_p1++;
|
||||||
|
#if BPTC_196x96_DEBUG
|
||||||
|
fprintf(stderr, " BPTC196 P1 COL FAIL col=%u rx=", (unsigned)i);
|
||||||
|
for (j = 0; j < 13; j++)
|
||||||
|
fprintf(stderr, "%u", ColumnBefore[j] & 1);
|
||||||
|
fprintf(stderr, "\n");
|
||||||
|
#endif
|
||||||
|
for (j = 0; j < 9; j++)
|
||||||
|
DataMatrix[j][i] = ColumnBefore[j];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Row/Line contains correct data */
|
for (j = 0; j < 13; j++)
|
||||||
}
|
{
|
||||||
|
if ((ColumnBefore[j] & 1) != (ColumnUncorrected[j] & 1))
|
||||||
/* Re-inject the column in the matrix (only the util data [11 bit],
|
{
|
||||||
* not the Hamming part [4 bit]) */
|
col_corr_p1++;
|
||||||
for(j = 0; j < 9; j++)
|
#if BPTC_196x96_DEBUG
|
||||||
{
|
fprintf(stderr,
|
||||||
DataMatrix[j][i] = ColumnCorrected[j];
|
" BPTC196 P1 COL CORRECTED col=%u bit=%u %u->%u\n",
|
||||||
|
(unsigned)i, (unsigned)j,
|
||||||
|
(unsigned)(ColumnBefore[j] & 1),
|
||||||
|
(unsigned)(ColumnUncorrected[j] & 1));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (j = 0; j < 9; j++)
|
||||||
|
DataMatrix[j][i] = ColumnCorrected[j];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#if BPTC_196x96_DEBUG
|
||||||
|
if (col_fail_p1 || col_corr_p1)
|
||||||
|
fprintf(stderr, " BPTC196 P1 COL summary: fail=%u corrected_bits=%u\n",
|
||||||
|
(unsigned)col_fail_p1, (unsigned)col_corr_p1);
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Extract the DMR data (96 bit) from the matrix */
|
/* Second pass can fix more after the first cascade */
|
||||||
/* First line : Do not take R(2), R(1) and R(0) */
|
HammingIrrecoverableErrorNb = 0;
|
||||||
|
|
||||||
|
/* ========== Pass 2: rows ========== */
|
||||||
|
for (i = 0; i < 9; i++)
|
||||||
|
{
|
||||||
|
for (j = 0; j < 15; j++)
|
||||||
|
{
|
||||||
|
LineUncorrected[j] = DataMatrix[i][j];
|
||||||
|
LineBefore[j] = LineUncorrected[j];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Hamming_15_11_decode(LineUncorrected, LineCorrected, 1) == false)
|
||||||
|
{
|
||||||
|
HammingIrrecoverableErrorNb++;
|
||||||
|
row_fail_p2++;
|
||||||
|
#if BPTC_196x96_DEBUG
|
||||||
|
fprintf(stderr, " BPTC196 P2 ROW FAIL row=%u rx=", (unsigned)i);
|
||||||
|
for (j = 0; j < 15; j++)
|
||||||
|
fprintf(stderr, "%u", LineBefore[j] & 1);
|
||||||
|
fprintf(stderr, "\n");
|
||||||
|
#endif
|
||||||
|
for (j = 0; j < 11; j++)
|
||||||
|
DataMatrix[i][j] = LineBefore[j];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (j = 0; j < 15; j++)
|
||||||
|
{
|
||||||
|
if ((LineBefore[j] & 1) != (LineUncorrected[j] & 1))
|
||||||
|
{
|
||||||
|
row_corr_p2++;
|
||||||
|
#if BPTC_196x96_DEBUG
|
||||||
|
fprintf(stderr,
|
||||||
|
" BPTC196 P2 ROW CORRECTED row=%u bit=%u %u->%u\n",
|
||||||
|
(unsigned)i, (unsigned)j,
|
||||||
|
(unsigned)(LineBefore[j] & 1),
|
||||||
|
(unsigned)(LineUncorrected[j] & 1));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (j = 0; j < 11; j++)
|
||||||
|
DataMatrix[i][j] = LineCorrected[j];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#if BPTC_196x96_DEBUG
|
||||||
|
if (row_fail_p2 || row_corr_p2)
|
||||||
|
fprintf(stderr, " BPTC196 P2 ROW summary: fail=%u corrected_bits=%u\n",
|
||||||
|
(unsigned)row_fail_p2, (unsigned)row_corr_p2);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* ========== Pass 2: columns ========== */
|
||||||
|
for (i = 0; i < 15; i++)
|
||||||
|
{
|
||||||
|
for (j = 0; j < 13; j++)
|
||||||
|
{
|
||||||
|
ColumnUncorrected[j] = DataMatrix[j][i];
|
||||||
|
ColumnBefore[j] = ColumnUncorrected[j];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Hamming_13_9_decode(ColumnUncorrected, ColumnCorrected, 1) == false)
|
||||||
|
{
|
||||||
|
HammingIrrecoverableErrorNb++;
|
||||||
|
col_fail_p2++;
|
||||||
|
#if BPTC_196x96_DEBUG
|
||||||
|
fprintf(stderr, " BPTC196 P2 COL FAIL col=%u rx=", (unsigned)i);
|
||||||
|
for (j = 0; j < 13; j++)
|
||||||
|
fprintf(stderr, "%u", ColumnBefore[j] & 1);
|
||||||
|
fprintf(stderr, "\n");
|
||||||
|
#endif
|
||||||
|
for (j = 0; j < 9; j++)
|
||||||
|
DataMatrix[j][i] = ColumnBefore[j];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (j = 0; j < 13; j++)
|
||||||
|
{
|
||||||
|
if ((ColumnBefore[j] & 1) != (ColumnUncorrected[j] & 1))
|
||||||
|
{
|
||||||
|
col_corr_p2++;
|
||||||
|
#if BPTC_196x96_DEBUG
|
||||||
|
fprintf(stderr,
|
||||||
|
" BPTC196 P2 COL CORRECTED col=%u bit=%u %u->%u\n",
|
||||||
|
(unsigned)i, (unsigned)j,
|
||||||
|
(unsigned)(ColumnBefore[j] & 1),
|
||||||
|
(unsigned)(ColumnUncorrected[j] & 1));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (j = 0; j < 9; j++)
|
||||||
|
DataMatrix[j][i] = ColumnCorrected[j];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#if BPTC_196x96_DEBUG
|
||||||
|
if (col_fail_p2 || col_corr_p2)
|
||||||
|
fprintf(stderr, " BPTC196 P2 COL summary: fail=%u corrected_bits=%u\n",
|
||||||
|
(unsigned)col_fail_p2, (unsigned)col_corr_p2);
|
||||||
|
fprintf(stderr,
|
||||||
|
" BPTC196 FINAL irrecoverable=%u P1(row_f=%u col_f=%u row_c=%u col_c=%u) "
|
||||||
|
"P2(row_f=%u col_f=%u row_c=%u col_c=%u)\n",
|
||||||
|
(unsigned)HammingIrrecoverableErrorNb,
|
||||||
|
(unsigned)row_fail_p1, (unsigned)col_fail_p1,
|
||||||
|
(unsigned)row_corr_p1, (unsigned)col_corr_p1,
|
||||||
|
(unsigned)row_fail_p2, (unsigned)col_fail_p2,
|
||||||
|
(unsigned)row_corr_p2, (unsigned)col_corr_p2);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Extract 96 data bits */
|
||||||
k = 0;
|
k = 0;
|
||||||
|
for (i = 3; i < 11; i++)
|
||||||
for(i = 3; i < 11; i++)
|
|
||||||
{
|
{
|
||||||
DMRDataExtracted[k] = DataMatrix[0][i];
|
DMRDataExtracted[k++] = DataMatrix[0][i];
|
||||||
k++;
|
}
|
||||||
|
for (i = 1; i < 9; i++)
|
||||||
|
{
|
||||||
|
for (j = 0; j < 11; j++)
|
||||||
|
DMRDataExtracted[k++] = DataMatrix[i][j];
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Next lines */
|
if (HammingIrrecoverableErrorNb == 0)
|
||||||
for(i = 1; i < 9; i++)
|
|
||||||
{
|
{
|
||||||
for(j = 0; j < 11; j++)
|
R[0] = DataMatrix[0][2]; /* R(0) */
|
||||||
{
|
R[1] = DataMatrix[0][1]; /* R(1) */
|
||||||
DMRDataExtracted[k] = DataMatrix[i][j];
|
R[2] = DataMatrix[0][0]; /* R(2) */
|
||||||
k++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* R(0) to R(2) may be used to transport some
|
if (R[0] == 0 && R[1] == 0 && R[2] == 1)
|
||||||
* Restricted Access System (RAS) information,
|
*is_ras = 1;
|
||||||
* So save these three bits after hamming correction
|
else
|
||||||
* See patent US 2013/0288643 A1 */
|
*is_ras = 0;
|
||||||
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 HammingIrrecoverableErrorNb;
|
return HammingIrrecoverableErrorNb;
|
||||||
} /* End BPTC_196x96_Extract_Data() */
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @brief : This function extract the 77 bits of a deinteleaved 128 bits
|
* BPTC (128,77) extract with iterative Hamming + parity-guided repair
|
||||||
* buffer using BPTC (128,77).
|
* and diagnostic logging.
|
||||||
|
* See ETSI TS 102 361-1 B.2.1
|
||||||
*
|
*
|
||||||
* @note : See DMR standard ETSI TS 102 361-1 chapter B.2.1 for details
|
* Enable/disable chatter with BPTC_128x77_DEBUG (1 = on).
|
||||||
*
|
|
||||||
* @param InputDeInteleavedData : Pointer of DMR input data deinterleaved (128 bytes
|
|
||||||
act as a 16 x 8 byte data matrix)
|
|
||||||
*
|
|
||||||
* @param DMRDataExtracted : Pointer where the DMR data will be written (77 bytes)
|
|
||||||
* DMRDataExtracted[0..71] = Util data (hamming corrected)
|
|
||||||
* DMRDataExtracted[72..76] = 5 bit of CRC extracted (to be checked)
|
|
||||||
*
|
|
||||||
* @return 0 = All is OK
|
|
||||||
* Other = Error - Irrecoverable Hamming parity check error number
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// #define BPTC_128x77_DEBUG 1
|
||||||
|
|
||||||
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 i, j, k;
|
uint32_t i, j, k;
|
||||||
@@ -394,102 +466,193 @@ uint32_t BPTC_128x77_Extract_Data(uint8_t InputDataMatrix[8][16], uint8_t DMRDat
|
|||||||
uint32_t ParityCheckErrorNb = 0;
|
uint32_t ParityCheckErrorNb = 0;
|
||||||
uint32_t NbOfOne;
|
uint32_t NbOfOne;
|
||||||
|
|
||||||
/* First step : Reconstitute the BPTC 16x8 matrix */
|
uint8_t row_bad[7];
|
||||||
for(i = 0; i < 8; i++)
|
uint8_t col_bad[16];
|
||||||
|
|
||||||
|
#if BPTC_128x77_DEBUG
|
||||||
|
fprintf (stderr, "\n");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
for (i = 0; i < 8; i++)
|
||||||
{
|
{
|
||||||
for(j = 0; j < 16; j++)
|
for (j = 0; j < 16; j++)
|
||||||
{
|
|
||||||
/* Only the LSBit of the byte is stored */
|
|
||||||
DataMatrix[i][j] = (InputDataMatrix[i][j] & 1);
|
DataMatrix[i][j] = (InputDataMatrix[i][j] & 1);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Init the Hamming (16,11,4) library
|
/* ---------- Pass 1: Hamming (16,11,4) on rows 0..6 ---------- */
|
||||||
* Not needed because it has already been done
|
memset(row_bad, 0, sizeof(row_bad));
|
||||||
* in the "InitAllFecFunction()" function */
|
for (i = 0; i < 7; i++)
|
||||||
//Hamming_16_11_4_init();
|
|
||||||
|
|
||||||
/* Process the the Hamming (16,11,4) code
|
|
||||||
* check on each line.
|
|
||||||
* Do not check the last line (line nb 8) */
|
|
||||||
for(i = 0; i < 7; i++)
|
|
||||||
{
|
{
|
||||||
/* Get a full line */
|
for (j = 0; j < 16; j++)
|
||||||
for(j = 0; j < 16; j++)
|
|
||||||
{
|
|
||||||
LineUncorrected[j] = DataMatrix[i][j];
|
LineUncorrected[j] = DataMatrix[i][j];
|
||||||
}
|
|
||||||
|
|
||||||
/* Apply Hamming (16,11,4) code correction */
|
if (Hamming_16_11_4_decode(LineUncorrected, LineCorrected, 1) == false)
|
||||||
if(Hamming_16_11_4_decode(LineUncorrected, LineCorrected, 1) == false)
|
|
||||||
{
|
{
|
||||||
HammingIrrecoverableErrorNb++;
|
HammingIrrecoverableErrorNb++;
|
||||||
|
row_bad[i] = 1;
|
||||||
|
#if BPTC_128x77_DEBUG
|
||||||
|
fprintf(stderr, " BPTC128 P1 Hamming FAIL row=%u rx=", (unsigned)i);
|
||||||
|
for (j = 0; j < 16; j++)
|
||||||
|
fprintf(stderr, "%u", LineUncorrected[j] & 1);
|
||||||
|
fprintf(stderr, "\n");
|
||||||
|
#endif
|
||||||
|
for (j = 0; j < 11; j++)
|
||||||
|
DataMatrix[i][j] = LineUncorrected[j];
|
||||||
}
|
}
|
||||||
|
else
|
||||||
/* Re-inject the line in the matrix (only the util data [11 bit],
|
|
||||||
* not the Hamming part [4 bit]) */
|
|
||||||
for(j = 0; j < 11; j++)
|
|
||||||
{
|
{
|
||||||
DataMatrix[i][j] = LineCorrected[j];
|
for (j = 0; j < 11; j++)
|
||||||
|
DataMatrix[i][j] = LineCorrected[j];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#if BPTC_128x77_DEBUG
|
||||||
|
if (HammingIrrecoverableErrorNb)
|
||||||
|
fprintf(stderr, " BPTC128 P1 Hamming irrecoverable rows=%u\n",
|
||||||
|
(unsigned)HammingIrrecoverableErrorNb);
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Extract the DMR data (77 bit) from the matrix */
|
/* ---------- Column even-parity check (row 7) ---------- */
|
||||||
k = 0;
|
memset(col_bad, 0, sizeof(col_bad));
|
||||||
|
|
||||||
/* 2 first lines */
|
|
||||||
for(i = 0; i < 2; i++)
|
|
||||||
{
|
|
||||||
for(j = 0; j < 11; j++)
|
|
||||||
{
|
|
||||||
DMRDataExtracted[k] = DataMatrix[i][j];
|
|
||||||
k++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 5 Next lines */
|
|
||||||
for(i = 2; i < 7; i++)
|
|
||||||
{
|
|
||||||
for(j = 0; j < 10; j++)
|
|
||||||
{
|
|
||||||
DMRDataExtracted[k] = DataMatrix[i][j];
|
|
||||||
k++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* 5 bit of CRC */
|
|
||||||
for(i = 2; i < 7; i++)
|
|
||||||
{
|
|
||||||
DMRDataExtracted[k] = DataMatrix[i][10];
|
|
||||||
k++;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Verify the data integrity by checking
|
|
||||||
* all column parity bit */
|
|
||||||
ParityCheckErrorNb = 0;
|
ParityCheckErrorNb = 0;
|
||||||
for(i = 0; i < 16; i++)
|
for (i = 0; i < 16; i++)
|
||||||
{
|
{
|
||||||
NbOfOne = 0;
|
NbOfOne = 0;
|
||||||
|
for (j = 0; j < 7; j++)
|
||||||
/* Get a full column */
|
|
||||||
for(j = 0; j < 7; j++)
|
|
||||||
{
|
|
||||||
NbOfOne += DataMatrix[j][i];
|
NbOfOne += DataMatrix[j][i];
|
||||||
}
|
|
||||||
|
|
||||||
/* Check the parity bit (number of "1"
|
if ((NbOfOne % 2) != DataMatrix[7][i])
|
||||||
* must be even) */
|
|
||||||
if((NbOfOne % 2) != DataMatrix[7][i])
|
|
||||||
{
|
{
|
||||||
ParityCheckErrorNb++;
|
ParityCheckErrorNb++;
|
||||||
|
col_bad[i] = 1;
|
||||||
|
#if BPTC_128x77_DEBUG
|
||||||
|
fprintf(stderr,
|
||||||
|
" BPTC128 P1 parity FAIL col=%u sum7=%u parity_bit=%u (expect even)\n",
|
||||||
|
(unsigned)i, (unsigned)NbOfOne, (unsigned)DataMatrix[7][i]);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#if BPTC_128x77_DEBUG
|
||||||
|
if (ParityCheckErrorNb)
|
||||||
|
fprintf(stderr, " BPTC128 P1 parity bad columns=%u\n",
|
||||||
|
(unsigned)ParityCheckErrorNb);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* ---------- Parity-guided single-bit repair ---------- */
|
||||||
|
{
|
||||||
|
uint32_t n_bad_rows = 0, n_bad_cols = 0;
|
||||||
|
uint32_t br = 0, bc = 0;
|
||||||
|
|
||||||
|
for (i = 0; i < 7; i++)
|
||||||
|
if (row_bad[i]) { n_bad_rows++; br = i; }
|
||||||
|
for (i = 0; i < 16; i++)
|
||||||
|
if (col_bad[i]) { n_bad_cols++; bc = i; }
|
||||||
|
|
||||||
|
#if BPTC_128x77_DEBUG
|
||||||
|
fprintf(stderr,
|
||||||
|
" BPTC128 repair candidates: bad_rows=%u bad_cols=%u",
|
||||||
|
(unsigned)n_bad_rows, (unsigned)n_bad_cols);
|
||||||
|
if (n_bad_rows == 1)
|
||||||
|
fprintf(stderr, " row=%u", (unsigned)br);
|
||||||
|
if (n_bad_cols == 1)
|
||||||
|
fprintf(stderr, " col=%u", (unsigned)bc);
|
||||||
|
fprintf(stderr, "\n");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (n_bad_rows == 1 && n_bad_cols == 1 && bc < 11)
|
||||||
|
{
|
||||||
|
DataMatrix[br][bc] ^= 1;
|
||||||
|
row_bad[br] = 0;
|
||||||
|
#if BPTC_128x77_DEBUG
|
||||||
|
fprintf(stderr,
|
||||||
|
" BPTC128 parity-guided FLIP at row=%u col=%u -> %u\n",
|
||||||
|
(unsigned)br, (unsigned)bc, (unsigned)DataMatrix[br][bc]);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
#if BPTC_128x77_DEBUG
|
||||||
|
else if (n_bad_rows || n_bad_cols)
|
||||||
|
{
|
||||||
|
fprintf(stderr,
|
||||||
|
" BPTC128 no single-intersection flip "
|
||||||
|
"(need exactly 1 bad row and 1 data col)\n");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ---------- Pass 2: Hamming (16,11,4) again ---------- */
|
||||||
|
HammingIrrecoverableErrorNb = 0;
|
||||||
|
for (i = 0; i < 7; i++)
|
||||||
|
{
|
||||||
|
for (j = 0; j < 16; j++)
|
||||||
|
LineUncorrected[j] = DataMatrix[i][j];
|
||||||
|
|
||||||
|
if (Hamming_16_11_4_decode(LineUncorrected, LineCorrected, 1) == false)
|
||||||
|
{
|
||||||
|
HammingIrrecoverableErrorNb++;
|
||||||
|
#if BPTC_128x77_DEBUG
|
||||||
|
fprintf(stderr, " BPTC128 P2 Hamming FAIL row=%u rx=", (unsigned)i);
|
||||||
|
for (j = 0; j < 16; j++)
|
||||||
|
fprintf(stderr, "%u", LineUncorrected[j] & 1);
|
||||||
|
fprintf(stderr, "\n");
|
||||||
|
#endif
|
||||||
|
for (j = 0; j < 11; j++)
|
||||||
|
DataMatrix[i][j] = LineUncorrected[j];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (j = 0; j < 11; j++)
|
||||||
|
DataMatrix[i][j] = LineCorrected[j];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#if BPTC_128x77_DEBUG
|
||||||
|
if (HammingIrrecoverableErrorNb)
|
||||||
|
fprintf(stderr, " BPTC128 P2 Hamming irrecoverable rows=%u\n",
|
||||||
|
(unsigned)HammingIrrecoverableErrorNb);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* ---------- Final column parity recount ---------- */
|
||||||
|
ParityCheckErrorNb = 0;
|
||||||
|
for (i = 0; i < 16; i++)
|
||||||
|
{
|
||||||
|
NbOfOne = 0;
|
||||||
|
for (j = 0; j < 7; j++)
|
||||||
|
NbOfOne += DataMatrix[j][i];
|
||||||
|
|
||||||
|
if ((NbOfOne % 2) != DataMatrix[7][i])
|
||||||
|
{
|
||||||
|
ParityCheckErrorNb++;
|
||||||
|
#if BPTC_128x77_DEBUG
|
||||||
|
fprintf(stderr,
|
||||||
|
" BPTC128 P2 parity FAIL col=%u sum7=%u parity_bit=%u\n",
|
||||||
|
(unsigned)i, (unsigned)NbOfOne, (unsigned)DataMatrix[7][i]);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return the number of irrecoverable Hamming errors +
|
#if BPTC_128x77_DEBUG
|
||||||
* the number of parity check error */
|
fprintf(stderr,
|
||||||
return (HammingIrrecoverableErrorNb + ParityCheckErrorNb);
|
" BPTC128 result: Hamming_err=%u parity_err=%u total=%u\n",
|
||||||
} /* End BPTC_128x77_Extract_Data() */
|
(unsigned)HammingIrrecoverableErrorNb,
|
||||||
|
(unsigned)ParityCheckErrorNb,
|
||||||
|
(unsigned)(HammingIrrecoverableErrorNb + ParityCheckErrorNb));
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* ---------- Extract 77 bits ---------- */
|
||||||
|
k = 0;
|
||||||
|
for (i = 0; i < 2; i++)
|
||||||
|
{
|
||||||
|
for (j = 0; j < 11; j++)
|
||||||
|
DMRDataExtracted[k++] = DataMatrix[i][j];
|
||||||
|
}
|
||||||
|
for (i = 2; i < 7; i++)
|
||||||
|
{
|
||||||
|
for (j = 0; j < 10; j++)
|
||||||
|
DMRDataExtracted[k++] = DataMatrix[i][j];
|
||||||
|
}
|
||||||
|
for (i = 2; i < 7; i++)
|
||||||
|
DMRDataExtracted[k++] = DataMatrix[i][10];
|
||||||
|
|
||||||
|
return (HammingIrrecoverableErrorNb + ParityCheckErrorNb);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @brief : This function extract the 32 bits of a deinteleaved 32 bits
|
* @brief : This function extract the 32 bits of a deinteleaved 32 bits
|
||||||
@@ -577,6 +740,52 @@ uint32_t BPTC_16x2_Extract_Data(uint8_t InputInterleavedData[32], uint8_t DMRDat
|
|||||||
|
|
||||||
} /* End BPTC_16x2_Extract_Data() */
|
} /* End BPTC_16x2_Extract_Data() */
|
||||||
|
|
||||||
|
uint32_t BPTC_128x77_Check_Errors(uint8_t InputDataMatrix[8][16])
|
||||||
|
{
|
||||||
|
uint32_t i, j;
|
||||||
|
uint32_t ham_bad = 0, ham_fix = 0, par_err = 0;
|
||||||
|
uint8_t line[16], before[16], decoded[11];
|
||||||
|
uint32_t ones;
|
||||||
|
int changed;
|
||||||
|
|
||||||
|
for (i = 0; i < 7; i++)
|
||||||
|
{
|
||||||
|
for (j = 0; j < 16; j++)
|
||||||
|
{
|
||||||
|
before[j] = (InputDataMatrix[i][j] & 1);
|
||||||
|
line[j] = before[j];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Hamming_16_11_4_decode(line, decoded, 1) == false)
|
||||||
|
{
|
||||||
|
ham_bad++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
changed = 0;
|
||||||
|
for (j = 0; j < 16; j++)
|
||||||
|
{
|
||||||
|
if (line[j] != before[j])
|
||||||
|
{
|
||||||
|
changed = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (changed)
|
||||||
|
ham_fix++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < 16; i++)
|
||||||
|
{
|
||||||
|
ones = 0;
|
||||||
|
for (j = 0; j < 7; j++)
|
||||||
|
ones += (InputDataMatrix[j][i] & 1);
|
||||||
|
if ((ones % 2) != (InputDataMatrix[7][i] & 1))
|
||||||
|
par_err++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ham_bad + ham_fix + par_err;
|
||||||
|
}
|
||||||
|
|
||||||
/* End of file */
|
/* End of file */
|
||||||
|
|||||||
974
src/crypt-aes.c
Normal file
974
src/crypt-aes.c
Normal file
@@ -0,0 +1,974 @@
|
|||||||
|
/*-------------------------------------------------------------------------------
|
||||||
|
* aes.c Tinier AES
|
||||||
|
* Easy To Use (and configurable) AES Output and Utility Bit/Byte Functions
|
||||||
|
*
|
||||||
|
* Modified Tiny AES code for more variable nk/nr/nb values, all in one file
|
||||||
|
* https://github.com/kokke/tiny-AES-c
|
||||||
|
*-----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
This is free and unencumbered software released into the public domain.
|
||||||
|
|
||||||
|
Anyone is free to copy, modify, publish, use, compile, sell, or
|
||||||
|
distribute this software, either in source code form or as a compiled
|
||||||
|
binary, for any purpose, commercial or non-commercial, and by any
|
||||||
|
means.
|
||||||
|
|
||||||
|
In jurisdictions that recognize copyright laws, the author or authors
|
||||||
|
of this software dedicate any and all copyright interest in the
|
||||||
|
software to the public domain. We make this dedication for the benefit
|
||||||
|
of the public at large and to the detriment of our heirs and
|
||||||
|
successors. We intend this dedication to be an overt act of
|
||||||
|
relinquishment in perpetuity of all present and future rights to this
|
||||||
|
software under copyright law.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||||
|
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||||
|
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||||
|
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||||
|
OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
|
For more information, please refer to <http://unlicense.org/>
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include "dsd.h"
|
||||||
|
#include "bp.h"
|
||||||
|
|
||||||
|
#define AES_BLOCKLEN 16
|
||||||
|
unsigned Nb = 4;
|
||||||
|
unsigned Nk = 8;
|
||||||
|
unsigned Nr = 14;
|
||||||
|
|
||||||
|
struct AES_ctx
|
||||||
|
{
|
||||||
|
uint8_t RoundKey[240];
|
||||||
|
uint8_t Iv[16];
|
||||||
|
};
|
||||||
|
|
||||||
|
//internal function prototypes
|
||||||
|
void AES_init_ctx(struct AES_ctx* ctx, const uint8_t* key);
|
||||||
|
void AES_init_ctx_iv(struct AES_ctx* ctx, const uint8_t* key, const uint8_t* iv);
|
||||||
|
void AES_ctx_set_iv(struct AES_ctx* ctx, const uint8_t* iv);
|
||||||
|
void AES_ECB_encrypt(const struct AES_ctx* ctx, uint8_t* buf);
|
||||||
|
void AES_ECB_decrypt(const struct AES_ctx* ctx, uint8_t* buf);
|
||||||
|
void AES_CBC_encrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, size_t length);
|
||||||
|
void AES_CBC_decrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, size_t length);
|
||||||
|
void AES_CTR_xcrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, size_t length);
|
||||||
|
|
||||||
|
typedef uint8_t state_t[4][4];
|
||||||
|
|
||||||
|
static const uint8_t sbox[256] = {
|
||||||
|
//0 1 2 3 4 5 6 7 8 9 A B C D E F
|
||||||
|
0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76,
|
||||||
|
0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0,
|
||||||
|
0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
|
||||||
|
0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75,
|
||||||
|
0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84,
|
||||||
|
0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
|
||||||
|
0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8,
|
||||||
|
0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2,
|
||||||
|
0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
|
||||||
|
0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb,
|
||||||
|
0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c, 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79,
|
||||||
|
0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
|
||||||
|
0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a,
|
||||||
|
0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e,
|
||||||
|
0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
|
||||||
|
0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16 };
|
||||||
|
|
||||||
|
static const uint8_t rsbox[256] = {
|
||||||
|
0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e, 0x81, 0xf3, 0xd7, 0xfb,
|
||||||
|
0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87, 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb,
|
||||||
|
0x54, 0x7b, 0x94, 0x32, 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
|
||||||
|
0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49, 0x6d, 0x8b, 0xd1, 0x25,
|
||||||
|
0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16, 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92,
|
||||||
|
0x6c, 0x70, 0x48, 0x50, 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
|
||||||
|
0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05, 0xb8, 0xb3, 0x45, 0x06,
|
||||||
|
0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02, 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b,
|
||||||
|
0x3a, 0x91, 0x11, 0x41, 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
|
||||||
|
0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8, 0x1c, 0x75, 0xdf, 0x6e,
|
||||||
|
0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89, 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b,
|
||||||
|
0xfc, 0x56, 0x3e, 0x4b, 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
|
||||||
|
0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xec, 0x5f,
|
||||||
|
0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d, 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef,
|
||||||
|
0xa0, 0xe0, 0x3b, 0x4d, 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
|
||||||
|
0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0c, 0x7d };
|
||||||
|
|
||||||
|
static const uint8_t Rcon[11] = {
|
||||||
|
0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36 };
|
||||||
|
|
||||||
|
#define getSBoxValue(num) (sbox[(num)])
|
||||||
|
|
||||||
|
static void KeyExpansion(uint8_t* RoundKey, const uint8_t* Key)
|
||||||
|
{
|
||||||
|
unsigned i, j, k;
|
||||||
|
uint8_t tempa[4]; // Used for the column/row operations
|
||||||
|
|
||||||
|
// The first round key is the key itself.
|
||||||
|
for (i = 0; i < Nk; ++i)
|
||||||
|
{
|
||||||
|
RoundKey[(i * 4) + 0] = Key[(i * 4) + 0];
|
||||||
|
RoundKey[(i * 4) + 1] = Key[(i * 4) + 1];
|
||||||
|
RoundKey[(i * 4) + 2] = Key[(i * 4) + 2];
|
||||||
|
RoundKey[(i * 4) + 3] = Key[(i * 4) + 3];
|
||||||
|
}
|
||||||
|
|
||||||
|
// All other round keys are found from the previous round keys.
|
||||||
|
for (i = Nk; i < Nb * (Nr + 1); ++i)
|
||||||
|
{
|
||||||
|
{
|
||||||
|
k = (i - 1) * 4;
|
||||||
|
tempa[0]=RoundKey[k + 0];
|
||||||
|
tempa[1]=RoundKey[k + 1];
|
||||||
|
tempa[2]=RoundKey[k + 2];
|
||||||
|
tempa[3]=RoundKey[k + 3];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i % Nk == 0)
|
||||||
|
{
|
||||||
|
// This function shifts the 4 bytes in a word to the left once.
|
||||||
|
// [a0,a1,a2,a3] becomes [a1,a2,a3,a0]
|
||||||
|
|
||||||
|
// Function RotWord()
|
||||||
|
{
|
||||||
|
const uint8_t u8tmp = tempa[0];
|
||||||
|
tempa[0] = tempa[1];
|
||||||
|
tempa[1] = tempa[2];
|
||||||
|
tempa[2] = tempa[3];
|
||||||
|
tempa[3] = u8tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
// SubWord() is a function that takes a four-byte input word and
|
||||||
|
// applies the S-box to each of the four bytes to produce an output word.
|
||||||
|
|
||||||
|
// Function Subword()
|
||||||
|
{
|
||||||
|
tempa[0] = getSBoxValue(tempa[0]);
|
||||||
|
tempa[1] = getSBoxValue(tempa[1]);
|
||||||
|
tempa[2] = getSBoxValue(tempa[2]);
|
||||||
|
tempa[3] = getSBoxValue(tempa[3]);
|
||||||
|
}
|
||||||
|
|
||||||
|
tempa[0] = tempa[0] ^ Rcon[i/Nk];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Nk == 8) //only run if using AES256 (Nk == 8)
|
||||||
|
{
|
||||||
|
if (i % Nk == 4)
|
||||||
|
{
|
||||||
|
// Function Subword()
|
||||||
|
{
|
||||||
|
tempa[0] = getSBoxValue(tempa[0]);
|
||||||
|
tempa[1] = getSBoxValue(tempa[1]);
|
||||||
|
tempa[2] = getSBoxValue(tempa[2]);
|
||||||
|
tempa[3] = getSBoxValue(tempa[3]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
j = i * 4; k=(i - Nk) * 4;
|
||||||
|
RoundKey[j + 0] = RoundKey[k + 0] ^ tempa[0];
|
||||||
|
RoundKey[j + 1] = RoundKey[k + 1] ^ tempa[1];
|
||||||
|
RoundKey[j + 2] = RoundKey[k + 2] ^ tempa[2];
|
||||||
|
RoundKey[j + 3] = RoundKey[k + 3] ^ tempa[3];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//input bit array, return output as up to a 64-bit value
|
||||||
|
uint64_t convert_bits_into_output_ta(uint8_t * input, int len)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
uint64_t output = 0;
|
||||||
|
for(i = 0; i < len; i++)
|
||||||
|
{
|
||||||
|
output <<= 1;
|
||||||
|
output |= (uint64_t)(input[i] & 1);
|
||||||
|
}
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
//take x amount of bits and pack into len amount of bytes (symmetrical)
|
||||||
|
void pack_bit_array_into_byte_array_ta (uint8_t * input, uint8_t * output, int len)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < len; i++)
|
||||||
|
output[i] = (uint8_t)convert_bits_into_output_ta(&input[i*8], 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
//take len amount of bytes and unpack back into a bit array
|
||||||
|
void unpack_byte_array_into_bit_array_ta (uint8_t * input, uint8_t * output, int len)
|
||||||
|
{
|
||||||
|
int i = 0, k = 0;
|
||||||
|
for (i = 0; i < len; i++)
|
||||||
|
{
|
||||||
|
output[k++] = (input[i] >> 7) & 1;
|
||||||
|
output[k++] = (input[i] >> 6) & 1;
|
||||||
|
output[k++] = (input[i] >> 5) & 1;
|
||||||
|
output[k++] = (input[i] >> 4) & 1;
|
||||||
|
output[k++] = (input[i] >> 3) & 1;
|
||||||
|
output[k++] = (input[i] >> 2) & 1;
|
||||||
|
output[k++] = (input[i] >> 1) & 1;
|
||||||
|
output[k++] = (input[i] >> 0) & 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void AES_init_ctx(struct AES_ctx* ctx, const uint8_t* key)
|
||||||
|
{
|
||||||
|
KeyExpansion(ctx->RoundKey, key);
|
||||||
|
}
|
||||||
|
void AES_init_ctx_iv(struct AES_ctx* ctx, const uint8_t* key, const uint8_t* iv)
|
||||||
|
{
|
||||||
|
KeyExpansion(ctx->RoundKey, key);
|
||||||
|
memcpy (ctx->Iv, iv, AES_BLOCKLEN);
|
||||||
|
}
|
||||||
|
void AES_ctx_set_iv(struct AES_ctx* ctx, const uint8_t* iv)
|
||||||
|
{
|
||||||
|
memcpy (ctx->Iv, iv, AES_BLOCKLEN);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void AddRoundKey(uint8_t round, state_t* state, const uint8_t* RoundKey)
|
||||||
|
{
|
||||||
|
uint8_t i,j;
|
||||||
|
for (i = 0; i < 4; ++i)
|
||||||
|
{
|
||||||
|
for (j = 0; j < 4; ++j)
|
||||||
|
{
|
||||||
|
(*state)[i][j] ^= RoundKey[(round * Nb * 4) + (i * Nb) + j];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void SubBytes(state_t* state)
|
||||||
|
{
|
||||||
|
uint8_t i, j;
|
||||||
|
for (i = 0; i < 4; ++i)
|
||||||
|
{
|
||||||
|
for (j = 0; j < 4; ++j)
|
||||||
|
{
|
||||||
|
(*state)[j][i] = getSBoxValue((*state)[j][i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ShiftRows(state_t* state)
|
||||||
|
{
|
||||||
|
uint8_t temp;
|
||||||
|
|
||||||
|
// Rotate first row 1 columns to left
|
||||||
|
temp = (*state)[0][1];
|
||||||
|
(*state)[0][1] = (*state)[1][1];
|
||||||
|
(*state)[1][1] = (*state)[2][1];
|
||||||
|
(*state)[2][1] = (*state)[3][1];
|
||||||
|
(*state)[3][1] = temp;
|
||||||
|
|
||||||
|
// Rotate second row 2 columns to left
|
||||||
|
temp = (*state)[0][2];
|
||||||
|
(*state)[0][2] = (*state)[2][2];
|
||||||
|
(*state)[2][2] = temp;
|
||||||
|
|
||||||
|
temp = (*state)[1][2];
|
||||||
|
(*state)[1][2] = (*state)[3][2];
|
||||||
|
(*state)[3][2] = temp;
|
||||||
|
|
||||||
|
// Rotate third row 3 columns to left
|
||||||
|
temp = (*state)[0][3];
|
||||||
|
(*state)[0][3] = (*state)[3][3];
|
||||||
|
(*state)[3][3] = (*state)[2][3];
|
||||||
|
(*state)[2][3] = (*state)[1][3];
|
||||||
|
(*state)[1][3] = temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
static uint8_t xtime(uint8_t x)
|
||||||
|
{
|
||||||
|
return ((x<<1) ^ (((x>>7) & 1) * 0x1b));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void MixColumns(state_t* state)
|
||||||
|
{
|
||||||
|
uint8_t i;
|
||||||
|
uint8_t Tmp, Tm, t;
|
||||||
|
for (i = 0; i < 4; ++i)
|
||||||
|
{
|
||||||
|
t = (*state)[i][0];
|
||||||
|
Tmp = (*state)[i][0] ^ (*state)[i][1] ^ (*state)[i][2] ^ (*state)[i][3] ;
|
||||||
|
Tm = (*state)[i][0] ^ (*state)[i][1] ; Tm = xtime(Tm); (*state)[i][0] ^= Tm ^ Tmp ;
|
||||||
|
Tm = (*state)[i][1] ^ (*state)[i][2] ; Tm = xtime(Tm); (*state)[i][1] ^= Tm ^ Tmp ;
|
||||||
|
Tm = (*state)[i][2] ^ (*state)[i][3] ; Tm = xtime(Tm); (*state)[i][2] ^= Tm ^ Tmp ;
|
||||||
|
Tm = (*state)[i][3] ^ t ; Tm = xtime(Tm); (*state)[i][3] ^= Tm ^ Tmp ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#define Multiply(x, y) \
|
||||||
|
( ((y & 1) * x) ^ \
|
||||||
|
((y>>1 & 1) * xtime(x)) ^ \
|
||||||
|
((y>>2 & 1) * xtime(xtime(x))) ^ \
|
||||||
|
((y>>3 & 1) * xtime(xtime(xtime(x)))) ^ \
|
||||||
|
((y>>4 & 1) * xtime(xtime(xtime(xtime(x)))))) \
|
||||||
|
|
||||||
|
|
||||||
|
#define getSBoxInvert(num) (rsbox[(num)])
|
||||||
|
|
||||||
|
static void InvMixColumns(state_t* state)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
uint8_t a, b, c, d;
|
||||||
|
for (i = 0; i < 4; ++i)
|
||||||
|
{
|
||||||
|
a = (*state)[i][0];
|
||||||
|
b = (*state)[i][1];
|
||||||
|
c = (*state)[i][2];
|
||||||
|
d = (*state)[i][3];
|
||||||
|
|
||||||
|
(*state)[i][0] = Multiply(a, 0x0e) ^ Multiply(b, 0x0b) ^ Multiply(c, 0x0d) ^ Multiply(d, 0x09);
|
||||||
|
(*state)[i][1] = Multiply(a, 0x09) ^ Multiply(b, 0x0e) ^ Multiply(c, 0x0b) ^ Multiply(d, 0x0d);
|
||||||
|
(*state)[i][2] = Multiply(a, 0x0d) ^ Multiply(b, 0x09) ^ Multiply(c, 0x0e) ^ Multiply(d, 0x0b);
|
||||||
|
(*state)[i][3] = Multiply(a, 0x0b) ^ Multiply(b, 0x0d) ^ Multiply(c, 0x09) ^ Multiply(d, 0x0e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void InvSubBytes(state_t* state)
|
||||||
|
{
|
||||||
|
uint8_t i, j;
|
||||||
|
for (i = 0; i < 4; ++i)
|
||||||
|
{
|
||||||
|
for (j = 0; j < 4; ++j)
|
||||||
|
{
|
||||||
|
(*state)[j][i] = getSBoxInvert((*state)[j][i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void InvShiftRows(state_t* state)
|
||||||
|
{
|
||||||
|
uint8_t temp;
|
||||||
|
|
||||||
|
// Rotate first row 1 columns to right
|
||||||
|
temp = (*state)[3][1];
|
||||||
|
(*state)[3][1] = (*state)[2][1];
|
||||||
|
(*state)[2][1] = (*state)[1][1];
|
||||||
|
(*state)[1][1] = (*state)[0][1];
|
||||||
|
(*state)[0][1] = temp;
|
||||||
|
|
||||||
|
// Rotate second row 2 columns to right
|
||||||
|
temp = (*state)[0][2];
|
||||||
|
(*state)[0][2] = (*state)[2][2];
|
||||||
|
(*state)[2][2] = temp;
|
||||||
|
|
||||||
|
temp = (*state)[1][2];
|
||||||
|
(*state)[1][2] = (*state)[3][2];
|
||||||
|
(*state)[3][2] = temp;
|
||||||
|
|
||||||
|
// Rotate third row 3 columns to right
|
||||||
|
temp = (*state)[0][3];
|
||||||
|
(*state)[0][3] = (*state)[1][3];
|
||||||
|
(*state)[1][3] = (*state)[2][3];
|
||||||
|
(*state)[2][3] = (*state)[3][3];
|
||||||
|
(*state)[3][3] = temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cipher is the main function that encrypts the PlainText,
|
||||||
|
// or produces a keystream, depending on application.
|
||||||
|
static void Cipher(state_t* state, const uint8_t* RoundKey)
|
||||||
|
{
|
||||||
|
uint8_t round = 0;
|
||||||
|
|
||||||
|
// Add the First round key to the state before starting the rounds.
|
||||||
|
AddRoundKey(0, state, RoundKey);
|
||||||
|
|
||||||
|
// There will be Nr rounds.
|
||||||
|
// The first Nr-1 rounds are identical.
|
||||||
|
// These Nr rounds are executed in the loop below.
|
||||||
|
// Last one without MixColumns()
|
||||||
|
for (round = 1; ; ++round)
|
||||||
|
{
|
||||||
|
SubBytes(state);
|
||||||
|
ShiftRows(state);
|
||||||
|
if (round == Nr) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
MixColumns(state);
|
||||||
|
AddRoundKey(round, state, RoundKey);
|
||||||
|
}
|
||||||
|
// Add round key to last round
|
||||||
|
AddRoundKey(Nr, state, RoundKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void InvCipher(state_t* state, const uint8_t* RoundKey)
|
||||||
|
{
|
||||||
|
uint8_t round = 0;
|
||||||
|
|
||||||
|
// Add the First round key to the state before starting the rounds.
|
||||||
|
AddRoundKey(Nr, state, RoundKey);
|
||||||
|
|
||||||
|
// There will be Nr rounds.
|
||||||
|
// The first Nr-1 rounds are identical.
|
||||||
|
// These Nr rounds are executed in the loop below.
|
||||||
|
// Last one without InvMixColumn()
|
||||||
|
for (round = (Nr - 1); ; --round)
|
||||||
|
{
|
||||||
|
InvShiftRows(state);
|
||||||
|
InvSubBytes(state);
|
||||||
|
AddRoundKey(round, state, RoundKey);
|
||||||
|
if (round == 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
InvMixColumns(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void AES_ECB_encrypt(const struct AES_ctx* ctx, uint8_t* buf)
|
||||||
|
{
|
||||||
|
// The next function call encrypts the PlainText with the Key using AES algorithm.
|
||||||
|
Cipher((state_t*)buf, ctx->RoundKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AES_ECB_decrypt(const struct AES_ctx* ctx, uint8_t* buf)
|
||||||
|
{
|
||||||
|
// The next function call decrypts the PlainText with the Key using AES algorithm.
|
||||||
|
InvCipher((state_t*)buf, ctx->RoundKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void XorWithIv(uint8_t* buf, const uint8_t* Iv)
|
||||||
|
{
|
||||||
|
uint8_t i;
|
||||||
|
for (i = 0; i < AES_BLOCKLEN; ++i)
|
||||||
|
{
|
||||||
|
buf[i] ^= Iv[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void AES_CBC_encrypt_buffer(struct AES_ctx *ctx, uint8_t* buf, size_t length)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
uint8_t *Iv = ctx->Iv;
|
||||||
|
for (i = 0; i < length; i += AES_BLOCKLEN)
|
||||||
|
{
|
||||||
|
XorWithIv(buf, Iv);
|
||||||
|
Cipher((state_t*)buf, ctx->RoundKey);
|
||||||
|
Iv = buf;
|
||||||
|
buf += AES_BLOCKLEN;
|
||||||
|
}
|
||||||
|
/* store Iv in ctx for next call */
|
||||||
|
memcpy(ctx->Iv, Iv, AES_BLOCKLEN);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AES_CBC_decrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, size_t length)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
uint8_t storeNextIv[AES_BLOCKLEN];
|
||||||
|
for (i = 0; i < length; i += AES_BLOCKLEN)
|
||||||
|
{
|
||||||
|
memcpy(storeNextIv, buf, AES_BLOCKLEN);
|
||||||
|
InvCipher((state_t*)buf, ctx->RoundKey);
|
||||||
|
XorWithIv(buf, ctx->Iv);
|
||||||
|
memcpy(ctx->Iv, storeNextIv, AES_BLOCKLEN);
|
||||||
|
buf += AES_BLOCKLEN;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Symmetrical operation: same function for encrypting as for decrypting. Note any IV/nonce should never be reused with the same key */
|
||||||
|
void AES_CTR_xcrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, size_t length)
|
||||||
|
{
|
||||||
|
uint8_t buffer[AES_BLOCKLEN];
|
||||||
|
|
||||||
|
size_t i;
|
||||||
|
int bi;
|
||||||
|
for (i = 0, bi = AES_BLOCKLEN; i < length; ++i, ++bi)
|
||||||
|
{
|
||||||
|
if (bi == AES_BLOCKLEN) /* we need to regen xor compliment in buffer */
|
||||||
|
{
|
||||||
|
|
||||||
|
memcpy(buffer, ctx->Iv, AES_BLOCKLEN);
|
||||||
|
Cipher((state_t*)buffer,ctx->RoundKey);
|
||||||
|
|
||||||
|
/* Increment Iv and handle overflow */
|
||||||
|
for (bi = (AES_BLOCKLEN - 1); bi >= 0; --bi)
|
||||||
|
{
|
||||||
|
/* inc will overflow */
|
||||||
|
if (ctx->Iv[bi] == 255)
|
||||||
|
{
|
||||||
|
ctx->Iv[bi] = 0;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
ctx->Iv[bi] += 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
bi = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
buf[i] = (buf[i] ^ buffer[bi]);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//Vertex Standard "AES" Encryption - convert AES key into a round key at 256 Nb,Nk,Nr values
|
||||||
|
//then select entries from the BP table to invert and convert to a keystream
|
||||||
|
void vertex_256_keystream_creation(dsd_state * state, char * key_string)
|
||||||
|
{
|
||||||
|
|
||||||
|
Nb = 4;
|
||||||
|
Nk = 8;
|
||||||
|
Nr = 14;
|
||||||
|
|
||||||
|
uint8_t key[32];
|
||||||
|
memset (key, 0, sizeof(key));
|
||||||
|
|
||||||
|
parse_raw_user_string(key_string, key);
|
||||||
|
|
||||||
|
struct AES_ctx ctx;
|
||||||
|
KeyExpansion(ctx.RoundKey, key);
|
||||||
|
|
||||||
|
uint64_t vtx_key = 0;
|
||||||
|
|
||||||
|
//use the bytes from round key output to select 4 BP key 16-bit words
|
||||||
|
for (int i = 224; i < 228; i++)
|
||||||
|
{
|
||||||
|
vtx_key <<= 16;
|
||||||
|
vtx_key |= BPK[ctx.RoundKey[i]];
|
||||||
|
}
|
||||||
|
|
||||||
|
//invert value
|
||||||
|
vtx_key = ~vtx_key;
|
||||||
|
|
||||||
|
fprintf (stderr,"Vertex Round Key Bytes: ");
|
||||||
|
for (uint16_t i = 224; i < 228; i++)
|
||||||
|
fprintf (stderr, "%02X ", ctx.RoundKey[i]);
|
||||||
|
fprintf (stderr, "Vertex Keystream: %016llX;", (unsigned long long int)vtx_key);
|
||||||
|
fprintf (stderr, "\n");
|
||||||
|
|
||||||
|
uint8_t vtx_bytes[8];
|
||||||
|
memset (vtx_bytes, 0, sizeof(vtx_bytes));
|
||||||
|
|
||||||
|
for (int i = 0; i < 8; i++)
|
||||||
|
vtx_bytes[i] = (vtx_key >> (56-(i*8))) & 0xFF;
|
||||||
|
|
||||||
|
unpack_byte_array_into_bit_array(vtx_bytes, state->static_ks_bits[0], 8);
|
||||||
|
unpack_byte_array_into_bit_array(vtx_bytes, state->static_ks_bits[1], 8);
|
||||||
|
|
||||||
|
//hex representation of the effective keystream value
|
||||||
|
state->vtx256_ekey = convert_bits_into_output(state->static_ks_bits[0], 64);
|
||||||
|
|
||||||
|
state->vtx_key_loaded = 1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//byte-wise output of AES OFB Keystream
|
||||||
|
//input iv is a 16-byte uint8_t array of initialization vector
|
||||||
|
//input key is up to 32-byte uint8_t array of key value
|
||||||
|
//input type is the type/key len of AES required (0-128, 1-192, 2-256)
|
||||||
|
//input nblocks is the number of rounds of 16-byte keystream output blocks requried
|
||||||
|
//output is a uint8_t bytewise array, each round filled with 16-bytes from aes keystream output
|
||||||
|
void aes_ofb_keystream_output (uint8_t * iv, uint8_t * key, uint8_t * output, int type, int nblocks)
|
||||||
|
{
|
||||||
|
|
||||||
|
int i;
|
||||||
|
uint8_t input_register[16]; //OFB Input Register
|
||||||
|
memset (input_register, 0, sizeof(input_register));
|
||||||
|
|
||||||
|
//Set values specific to type (128/192/256)
|
||||||
|
if (type == 0) //128
|
||||||
|
{
|
||||||
|
Nb = 4;
|
||||||
|
Nk = 4;
|
||||||
|
Nr = 10;
|
||||||
|
}
|
||||||
|
else if (type == 1) //192
|
||||||
|
{
|
||||||
|
Nb = 4;
|
||||||
|
Nk = 6;
|
||||||
|
Nr = 12;
|
||||||
|
}
|
||||||
|
else //if (type == 2) //256
|
||||||
|
{
|
||||||
|
Nb = 4;
|
||||||
|
Nk = 8;
|
||||||
|
Nr = 14;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct AES_ctx ctx;
|
||||||
|
|
||||||
|
//load first round of input_register with received IV (OFB First Input Register)
|
||||||
|
memcpy (input_register, iv, 16*sizeof(uint8_t) );
|
||||||
|
|
||||||
|
//initialize the key variable for the Cipher function
|
||||||
|
memset (ctx.RoundKey, 0, 240*sizeof(uint8_t));
|
||||||
|
KeyExpansion(ctx.RoundKey, key);
|
||||||
|
|
||||||
|
//execute the cipher function, and copy ciphered input_register to output for required number of rounds
|
||||||
|
for (i = 0; i < nblocks; i++)
|
||||||
|
{
|
||||||
|
Cipher((state_t*)input_register, ctx.RoundKey); //input_register is returned as output, and is put back in as object feedback
|
||||||
|
memcpy (output+(i*16), input_register, 16*sizeof(uint8_t) ); //copy ciphered input_register to output
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//byte-wise AES CFB (Cipher Feedback) Payload operating in 128-bit block mode
|
||||||
|
//input in is a uint8_t bytewise array,is the input to be ciphered (encrypted or decrypted)
|
||||||
|
//input iv is a 16-byte uint8_t array of initialization vector
|
||||||
|
//input key is up to 32-byte uint8_t array of key value
|
||||||
|
//input type is the type/key len of AES required (0-128, 1-192, 2-256)
|
||||||
|
//input nblocks is the number of rounds of 16-byte payload blocks requried (last block will need padding if not flush)
|
||||||
|
//output out is a uint8_t bytewise array, each round filled with 16-bytes of cfb ciphered output (encrypted or decrypted)
|
||||||
|
//de is a bit-flag signalling to run Cipher (encrypt) on 1, or InvCipher (decrypt) on 0
|
||||||
|
void aes_cfb_bytewise_payload_crypt (uint8_t * iv, uint8_t * key, uint8_t * in, uint8_t * out, int type, int nblocks, int de)
|
||||||
|
{
|
||||||
|
|
||||||
|
int i, j;
|
||||||
|
uint8_t input_register[16]; //Input Register
|
||||||
|
memset (input_register, 0, sizeof(input_register));
|
||||||
|
|
||||||
|
//Set values specific to type (128/192/256)
|
||||||
|
if (type == 0) //128
|
||||||
|
{
|
||||||
|
Nb = 4;
|
||||||
|
Nk = 4;
|
||||||
|
Nr = 10;
|
||||||
|
}
|
||||||
|
else if (type == 1) //192
|
||||||
|
{
|
||||||
|
Nb = 4;
|
||||||
|
Nk = 6;
|
||||||
|
Nr = 12;
|
||||||
|
}
|
||||||
|
else //if (type == 2) //256
|
||||||
|
{
|
||||||
|
Nb = 4;
|
||||||
|
Nk = 8;
|
||||||
|
Nr = 14;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct AES_ctx ctx;
|
||||||
|
|
||||||
|
//load first round of input_register with received IV (CFB First Input Register)
|
||||||
|
memcpy (input_register, iv, 16*sizeof(uint8_t) );
|
||||||
|
|
||||||
|
//initialize the key variable for the Cipher function
|
||||||
|
memset (ctx.RoundKey, 0, 240*sizeof(uint8_t));
|
||||||
|
KeyExpansion(ctx.RoundKey, key);
|
||||||
|
|
||||||
|
//execute the cipher function, and copy ciphered input_register to output for required number of rounds
|
||||||
|
for (i = 0; i < nblocks; i++)
|
||||||
|
{
|
||||||
|
|
||||||
|
//the cipher is always run in the foward, or encryption mode
|
||||||
|
Cipher((state_t*)input_register, ctx.RoundKey);
|
||||||
|
|
||||||
|
//xor the current input 'in' to the current state of the input_register for cipher feedback
|
||||||
|
for (j = 0; j < 16; j++)
|
||||||
|
input_register[j] ^= in[j+(i*16)];
|
||||||
|
|
||||||
|
//copy ciphered/xor'd input_register to output 'out'
|
||||||
|
memcpy (out+(i*16), input_register, 16*sizeof(uint8_t) );
|
||||||
|
|
||||||
|
//if running in decryption mode, we feed in the next round of input
|
||||||
|
if (!de)
|
||||||
|
memcpy(input_register, in+(i*16), 16*sizeof(uint8_t));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//byte-wise AES CBC (Cipher Block Chaining) //Yeah, I know this already exists, but wanted a custom convenience wrapper version
|
||||||
|
//input in is a uint8_t bytewise array,is the input to be ciphered (encrypted or decrypted)
|
||||||
|
//input iv is a 16-byte uint8_t array of initialization vector
|
||||||
|
//input key is up to 32-byte uint8_t array of key value
|
||||||
|
//input type is the type/key len of AES required (0-128, 1-192, 2-256)
|
||||||
|
//input nblocks is the number of rounds of 16-byte payload blocks requried (last block will need padding if not flush)
|
||||||
|
//output out is a uint8_t bytewise array, each round filled with 16-bytes of cfb ciphered output (encrypted or decrypted)
|
||||||
|
//de is a bit-flag signalling to run Cipher (encrypt) on 1, or InvCipher (decrypt) on 0
|
||||||
|
void aes_cbc_bytewise_payload_crypt (uint8_t * iv, uint8_t * key, uint8_t * in, uint8_t * out, int type, int nblocks, int de)
|
||||||
|
{
|
||||||
|
|
||||||
|
int i, j;
|
||||||
|
uint8_t input_register[16]; //Input Register
|
||||||
|
memset (input_register, 0, sizeof(input_register));
|
||||||
|
|
||||||
|
//Set values specific to type (128/192/256)
|
||||||
|
if (type == 0) //128
|
||||||
|
{
|
||||||
|
Nb = 4;
|
||||||
|
Nk = 4;
|
||||||
|
Nr = 10;
|
||||||
|
}
|
||||||
|
else if (type == 1) //192
|
||||||
|
{
|
||||||
|
Nb = 4;
|
||||||
|
Nk = 6;
|
||||||
|
Nr = 12;
|
||||||
|
}
|
||||||
|
else //if (type == 2) //256
|
||||||
|
{
|
||||||
|
Nb = 4;
|
||||||
|
Nk = 8;
|
||||||
|
Nr = 14;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct AES_ctx ctx;
|
||||||
|
|
||||||
|
//load first round of input_register accordingly
|
||||||
|
if (de)
|
||||||
|
memcpy (input_register, iv, 16*sizeof(uint8_t) );
|
||||||
|
else memcpy (input_register, in, 16*sizeof(uint8_t) );
|
||||||
|
|
||||||
|
//initialize the key variable for the Cipher function
|
||||||
|
memset (ctx.RoundKey, 0, 240*sizeof(uint8_t));
|
||||||
|
KeyExpansion(ctx.RoundKey, key);
|
||||||
|
|
||||||
|
//
|
||||||
|
for (i = 0; i < nblocks; i++)
|
||||||
|
{
|
||||||
|
|
||||||
|
//run encryption or decryption depending on de value
|
||||||
|
if (de) //encrypt
|
||||||
|
{
|
||||||
|
|
||||||
|
//xor the current input 'in' pt to the current state of the input_register for cbc feedback
|
||||||
|
for (j = 0; j < 16; j++)
|
||||||
|
input_register[j] ^= in[j+(i*16)];
|
||||||
|
|
||||||
|
Cipher((state_t*)input_register, ctx.RoundKey);
|
||||||
|
|
||||||
|
//copy ciphered input_register to output 'out'
|
||||||
|
memcpy (out+(i*16), input_register, 16*sizeof(uint8_t) );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
else //decrypt
|
||||||
|
{
|
||||||
|
|
||||||
|
InvCipher((state_t*)input_register, ctx.RoundKey);
|
||||||
|
|
||||||
|
//copy ciphered input_register to output 'out'
|
||||||
|
memcpy (out+(i*16), input_register, 16*sizeof(uint8_t) );
|
||||||
|
|
||||||
|
//xor the current output by IV, or by last received CT
|
||||||
|
if (i == 0)
|
||||||
|
{
|
||||||
|
for (j = 0; j < 16; j++)
|
||||||
|
out[j] ^= iv[j];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (j = 0; j < 16; j++)
|
||||||
|
out[j+(i*16)] ^= in[j+((i-1)*16)];
|
||||||
|
}
|
||||||
|
|
||||||
|
//copy in next segment for input_register (if not last)
|
||||||
|
if (i < nblocks)
|
||||||
|
memcpy(input_register, in+((i+1)*16), 16*sizeof(uint8_t) );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//byte-wise AES CBC_MAC (Cipher Block Chaining Message Authentication) //This is slightly different than above, no IV is present,
|
||||||
|
//but if iv is desireable, it will need to be pre-XOR'd with the first plaintext input block by the calling function
|
||||||
|
//input in is a uint8_t bytewise array, is the input to be ciphered.
|
||||||
|
//input key is up to 32-byte uint8_t array of key value
|
||||||
|
//input type is the type/key len of AES required (0-128, 1-192, 2-256)
|
||||||
|
//input nblocks is the number of rounds of 16-byte payload blocks requried (last block will need padding if not flush)
|
||||||
|
//output out is a uint8_t bytewise array, with only the final round output as the MAC octets
|
||||||
|
//NOTE: When doing a cbc_mac, you should only run it in the forward (encryption) mode to get the mac bytes
|
||||||
|
void aes_cbc_mac_generator (uint8_t * key, uint8_t * in, uint8_t * out, int type, int nblocks)
|
||||||
|
{
|
||||||
|
|
||||||
|
int i, j;
|
||||||
|
uint8_t input_register[16]; //Input Register
|
||||||
|
memset (input_register, 0, sizeof(input_register));
|
||||||
|
|
||||||
|
//Set values specific to type (128/192/256)
|
||||||
|
if (type == 0) //128
|
||||||
|
{
|
||||||
|
Nb = 4;
|
||||||
|
Nk = 4;
|
||||||
|
Nr = 10;
|
||||||
|
}
|
||||||
|
else if (type == 1) //192
|
||||||
|
{
|
||||||
|
Nb = 4;
|
||||||
|
Nk = 6;
|
||||||
|
Nr = 12;
|
||||||
|
}
|
||||||
|
else //if (type == 2) //256
|
||||||
|
{
|
||||||
|
Nb = 4;
|
||||||
|
Nk = 8;
|
||||||
|
Nr = 14;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct AES_ctx ctx;
|
||||||
|
|
||||||
|
//initialize the key variable for the Cipher function
|
||||||
|
memset (ctx.RoundKey, 0, 240*sizeof(uint8_t));
|
||||||
|
KeyExpansion(ctx.RoundKey, key);
|
||||||
|
|
||||||
|
//
|
||||||
|
for (i = 0; i < nblocks; i++)
|
||||||
|
{
|
||||||
|
|
||||||
|
//xor the current input 'in' pt to the current state of the input_register for cbc feedback
|
||||||
|
//if this is the first iteration, this will load the first round plain text instead
|
||||||
|
for (j = 0; j < 16; j++)
|
||||||
|
input_register[j] ^= in[j+((i+0)*16)];
|
||||||
|
|
||||||
|
Cipher((state_t*)input_register, ctx.RoundKey);
|
||||||
|
|
||||||
|
//debug, load out all intermediate output register values
|
||||||
|
// memcpy (out+(i*16), input_register, 16*sizeof(uint8_t) );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//copy final ciphered input_register to output 'out', user will determine how many bytes of output they want for MAC
|
||||||
|
memcpy (out, input_register, 16*sizeof(uint8_t) );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//byte-wise output of AES ECB Ciphering/Deciphering
|
||||||
|
//input is uint8_t byte-wise (16-bytes) data to be ciphered or deciphered
|
||||||
|
//input key is up to 32-byte uint8_t array of key value
|
||||||
|
//input type is the type/len of AES required (0-128, 1-192, 2-256)
|
||||||
|
//output is a uint8_t bytewise array of ciphered or deciphered input
|
||||||
|
//de is a bit-flag signalling to run Cipher (encrypt) on 1, or InvCipher (decrypt) on 0
|
||||||
|
void aes_ecb_bytewise_payload_crypt (uint8_t * input, uint8_t * key, uint8_t * output, int type, int de)
|
||||||
|
{
|
||||||
|
|
||||||
|
uint8_t input_register[16]; //ECB Input Register
|
||||||
|
memset (input_register, 0, sizeof(input_register));
|
||||||
|
|
||||||
|
//Set values specific to type (128/192/256)
|
||||||
|
if (type == 0) //128
|
||||||
|
{
|
||||||
|
Nb = 4;
|
||||||
|
Nk = 4;
|
||||||
|
Nr = 10;
|
||||||
|
}
|
||||||
|
else if (type == 1) //192
|
||||||
|
{
|
||||||
|
Nb = 4;
|
||||||
|
Nk = 6;
|
||||||
|
Nr = 12;
|
||||||
|
}
|
||||||
|
else //if (type == 2) //256
|
||||||
|
{
|
||||||
|
Nb = 4;
|
||||||
|
Nk = 8;
|
||||||
|
Nr = 14;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct AES_ctx ctx;
|
||||||
|
|
||||||
|
//load input_register with received input (ECB Payload)
|
||||||
|
memcpy (input_register, input, 16*sizeof(uint8_t) );
|
||||||
|
|
||||||
|
//initialize the key variable for the Cipher function
|
||||||
|
memset (ctx.RoundKey, 0, 240*sizeof(uint8_t));
|
||||||
|
KeyExpansion(ctx.RoundKey, key);
|
||||||
|
|
||||||
|
//run encryption or decryption depending on de value
|
||||||
|
if (de) //encrypt
|
||||||
|
Cipher((state_t*)input_register, ctx.RoundKey);
|
||||||
|
else //decrypt
|
||||||
|
InvCipher((state_t*)input_register, ctx.RoundKey);
|
||||||
|
|
||||||
|
//copy ciphered/deciphered input_register to output
|
||||||
|
memcpy (output, input_register, 16*sizeof(uint8_t) );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//symmetrical ctr mode payload encryption and decryption
|
||||||
|
void aes_ctr_bitwise_payload_crypt (uint8_t * iv, uint8_t * key, uint8_t * payload, int type)
|
||||||
|
{
|
||||||
|
|
||||||
|
//Set values specific to type (128/192/256)
|
||||||
|
if (type == 0) //128
|
||||||
|
{
|
||||||
|
Nb = 4;
|
||||||
|
Nk = 4;
|
||||||
|
Nr = 10;
|
||||||
|
}
|
||||||
|
else if (type == 1) //192
|
||||||
|
{
|
||||||
|
Nb = 4;
|
||||||
|
Nk = 6;
|
||||||
|
Nr = 12;
|
||||||
|
}
|
||||||
|
else //if (type == 2) //256
|
||||||
|
{
|
||||||
|
Nb = 4;
|
||||||
|
Nk = 8;
|
||||||
|
Nr = 14;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct AES_ctx ctx;
|
||||||
|
|
||||||
|
//init and set the iv and key variables
|
||||||
|
memset (ctx.RoundKey, 0, 240*sizeof(uint8_t));
|
||||||
|
memset (ctx.Iv, 0, 16*sizeof(uint8_t));
|
||||||
|
|
||||||
|
KeyExpansion(ctx.RoundKey, key);
|
||||||
|
memcpy (ctx.Iv, iv, AES_BLOCKLEN);
|
||||||
|
|
||||||
|
//pack input bit-wise payload to byte array
|
||||||
|
uint8_t payload_bytes[16];
|
||||||
|
memset (payload_bytes, 0, sizeof(payload_bytes));
|
||||||
|
pack_bit_array_into_byte_array_ta (payload, payload_bytes, 16);
|
||||||
|
|
||||||
|
//pass to internal CTR handler for payload
|
||||||
|
AES_CTR_xcrypt_buffer(&ctx, payload_bytes, 16);
|
||||||
|
|
||||||
|
//unpack output bytes back to bits
|
||||||
|
unpack_byte_array_into_bit_array_ta(payload_bytes, payload, 16);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//symmetrical ctr mode payload encryption and decryption
|
||||||
|
void aes_ctr_bytewise_payload_crypt (uint8_t * iv, uint8_t * key, uint8_t * payload, int type)
|
||||||
|
{
|
||||||
|
|
||||||
|
//Set values specific to type (128/192/256)
|
||||||
|
if (type == 0) //128
|
||||||
|
{
|
||||||
|
Nb = 4;
|
||||||
|
Nk = 4;
|
||||||
|
Nr = 10;
|
||||||
|
}
|
||||||
|
else if (type == 1) //192
|
||||||
|
{
|
||||||
|
Nb = 4;
|
||||||
|
Nk = 6;
|
||||||
|
Nr = 12;
|
||||||
|
}
|
||||||
|
else //if (type == 2) //256
|
||||||
|
{
|
||||||
|
Nb = 4;
|
||||||
|
Nk = 8;
|
||||||
|
Nr = 14;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct AES_ctx ctx;
|
||||||
|
|
||||||
|
//init and set the iv and key variables
|
||||||
|
memset (ctx.RoundKey, 0, 240*sizeof(uint8_t));
|
||||||
|
memset (ctx.Iv, 0, 16*sizeof(uint8_t));
|
||||||
|
|
||||||
|
KeyExpansion(ctx.RoundKey, key);
|
||||||
|
memcpy (ctx.Iv, iv, AES_BLOCKLEN);
|
||||||
|
|
||||||
|
//pass to internal CTR handler for payload
|
||||||
|
AES_CTR_xcrypt_buffer(&ctx, payload, 16);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
927
src/crypt-des.c
Normal file
927
src/crypt-des.c
Normal file
@@ -0,0 +1,927 @@
|
|||||||
|
/*-------------------------------------------------------------------------------
|
||||||
|
* des.c Crypthings
|
||||||
|
* DES Alg
|
||||||
|
*-----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "dsd.h"
|
||||||
|
|
||||||
|
//NOTE: The SLUT boxes are S boxes with additional calculations so we don't have
|
||||||
|
//to manually sort out row and column values and can cut down on operations
|
||||||
|
|
||||||
|
uint8_t SLUT1[64] = {
|
||||||
|
0xE0,0x00,0x40,0xF0,0xD0,0x70,0x10,0x40,
|
||||||
|
0x20,0xE0,0xF0,0x20,0xB0,0xD0,0x80,0x10,
|
||||||
|
0x30,0xA0,0xA0,0x60,0x60,0xC0,0xC0,0xB0,
|
||||||
|
0x50,0x90,0x90,0x50,0x00,0x30,0x70,0x80,
|
||||||
|
0x40,0xF0,0x10,0xC0,0xE0,0x80,0x80,0x20,
|
||||||
|
0xD0,0x40,0x60,0x90,0x20,0x10,0xB0,0x70,
|
||||||
|
0xF0,0x50,0xC0,0xB0,0x90,0x30,0x70,0xE0,
|
||||||
|
0x30,0xA0,0xA0,0x00,0x50,0x60,0x00,0xD0
|
||||||
|
};
|
||||||
|
|
||||||
|
uint8_t SLUT2[64] = {
|
||||||
|
0x0F,0x03,0x01,0x0D,0x08,0x04,0x0E,0x07,
|
||||||
|
0x06,0x0F,0x0B,0x02,0x03,0x08,0x04,0x0E,
|
||||||
|
0x09,0x0C,0x07,0x00,0x02,0x01,0x0D,0x0A,
|
||||||
|
0x0C,0x06,0x00,0x09,0x05,0x0B,0x0A,0x05,
|
||||||
|
0x00,0x0D,0x0E,0x08,0x07,0x0A,0x0B,0x01,
|
||||||
|
0x0A,0x03,0x04,0x0F,0x0D,0x04,0x01,0x02,
|
||||||
|
0x05,0x0B,0x08,0x06,0x0C,0x07,0x06,0x0C,
|
||||||
|
0x09,0x00,0x03,0x05,0x02,0x0E,0x0F,0x09
|
||||||
|
};
|
||||||
|
|
||||||
|
uint8_t SLUT3[64] = {
|
||||||
|
0xA0,0xD0,0x00,0x70,0x90,0x00,0xE0,0x90,
|
||||||
|
0x60,0x30,0x30,0x40,0xF0,0x60,0x50,0xA0,
|
||||||
|
0x10,0x20,0xD0,0x80,0xC0,0x50,0x70,0xE0,
|
||||||
|
0xB0,0xC0,0x40,0xB0,0x20,0xF0,0x80,0x10,
|
||||||
|
0xD0,0x10,0x60,0xA0,0x40,0xD0,0x90,0x00,
|
||||||
|
0x80,0x60,0xF0,0x90,0x30,0x80,0x00,0x70,
|
||||||
|
0xB0,0x40,0x10,0xF0,0x20,0xE0,0xC0,0x30,
|
||||||
|
0x50,0xB0,0xA0,0x50,0xE0,0x20,0x70,0xC0
|
||||||
|
};
|
||||||
|
|
||||||
|
uint8_t SLUT4[64] = {
|
||||||
|
0x07,0x0D,0x0D,0x08,0x0E,0x0B,0x03,0x05,
|
||||||
|
0x00,0x06,0x06,0x0F,0x09,0x00,0x0A,0x03,
|
||||||
|
0x01,0x04,0x02,0x07,0x08,0x02,0x05,0x0C,
|
||||||
|
0x0B,0x01,0x0C,0x0A,0x04,0x0E,0x0F,0x09,
|
||||||
|
0x0A,0x03,0x06,0x0F,0x09,0x00,0x00,0x06,
|
||||||
|
0x0C,0x0A,0x0B,0x01,0x07,0x0D,0x0D,0x08,
|
||||||
|
0x0F,0x09,0x01,0x04,0x03,0x05,0x0E,0x0B,
|
||||||
|
0x05,0x0C,0x02,0x07,0x08,0x02,0x04,0x0E
|
||||||
|
};
|
||||||
|
|
||||||
|
uint8_t SLUT5[64] = {
|
||||||
|
0x20,0xE0,0xC0,0xB0,0x40,0x20,0x10,0xC0,
|
||||||
|
0x70,0x40,0xA0,0x70,0xB0,0xD0,0x60,0x10,
|
||||||
|
0x80,0x50,0x50,0x00,0x30,0xF0,0xF0,0xA0,
|
||||||
|
0xD0,0x30,0x00,0x90,0xE0,0x80,0x90,0x60,
|
||||||
|
0x40,0xB0,0x20,0x80,0x10,0xC0,0xB0,0x70,
|
||||||
|
0xA0,0x10,0xD0,0xE0,0x70,0x20,0x80,0xD0,
|
||||||
|
0xF0,0x60,0x90,0xF0,0xC0,0x00,0x50,0x90,
|
||||||
|
0x60,0xA0,0x30,0x40,0x00,0x50,0xE0,0x30
|
||||||
|
};
|
||||||
|
|
||||||
|
uint8_t SLUT6[64] = {
|
||||||
|
0x0C,0x0A,0x01,0x0F,0x0A,0x04,0x0F,0x02,
|
||||||
|
0x09,0x07,0x02,0x0C,0x06,0x09,0x08,0x05,
|
||||||
|
0x00,0x06,0x0D,0x01,0x03,0x0D,0x04,0x0E,
|
||||||
|
0x0E,0x00,0x07,0x0B,0x05,0x03,0x0B,0x08,
|
||||||
|
0x09,0x04,0x0E,0x03,0x0F,0x02,0x05,0x0C,
|
||||||
|
0x02,0x09,0x08,0x05,0x0C,0x0F,0x03,0x0A,
|
||||||
|
0x07,0x0B,0x00,0x0E,0x04,0x01,0x0A,0x07,
|
||||||
|
0x01,0x06,0x0D,0x00,0x0B,0x08,0x06,0x0D
|
||||||
|
};
|
||||||
|
|
||||||
|
uint8_t SLUT7[64] = {
|
||||||
|
0x40,0xD0,0xB0,0x00,0x20,0xB0,0xE0,0x70,
|
||||||
|
0xF0,0x40,0x00,0x90,0x80,0x10,0xD0,0xA0,
|
||||||
|
0x30,0xE0,0xC0,0x30,0x90,0x50,0x70,0xC0,
|
||||||
|
0x50,0x20,0xA0,0xF0,0x60,0x80,0x10,0x60,
|
||||||
|
0x10,0x60,0x40,0xB0,0xB0,0xD0,0xD0,0x80,
|
||||||
|
0xC0,0x10,0x30,0x40,0x70,0xA0,0xE0,0x70,
|
||||||
|
0xA0,0x90,0xF0,0x50,0x60,0x00,0x80,0xF0,
|
||||||
|
0x00,0xE0,0x50,0x20,0x90,0x30,0x20,0xC0
|
||||||
|
};
|
||||||
|
|
||||||
|
uint8_t SLUT8[64] = {
|
||||||
|
0x0D,0x01,0x02,0x0F,0x08,0x0D,0x04,0x08,
|
||||||
|
0x06,0x0A,0x0F,0x03,0x0B,0x07,0x01,0x04,
|
||||||
|
0x0A,0x0C,0x09,0x05,0x03,0x06,0x0E,0x0B,
|
||||||
|
0x05,0x00,0x00,0x0E,0x0C,0x09,0x07,0x02,
|
||||||
|
0x07,0x02,0x0B,0x01,0x04,0x0E,0x01,0x07,
|
||||||
|
0x09,0x04,0x0C,0x0A,0x0E,0x08,0x02,0x0D,
|
||||||
|
0x00,0x0F,0x06,0x0C,0x0A,0x09,0x0D,0x00,
|
||||||
|
0x0F,0x03,0x03,0x05,0x05,0x06,0x08,0x0B
|
||||||
|
};
|
||||||
|
|
||||||
|
//initial permutation IP (on input)
|
||||||
|
uint8_t initial_register_permutation[64] = {
|
||||||
|
58, 50, 42, 34, 26, 18, 10, 2,
|
||||||
|
60, 52, 44, 36, 28, 20, 12, 4,
|
||||||
|
62, 54, 46, 38, 30, 22, 14, 6,
|
||||||
|
64, 56, 48, 40, 32, 24, 16, 8,
|
||||||
|
57, 49, 41, 33, 25, 17, 9, 1,
|
||||||
|
59, 51, 43, 35, 27, 19, 11, 3,
|
||||||
|
61, 53, 45, 37, 29, 21, 13, 5,
|
||||||
|
63, 55, 47, 39, 31, 23, 15, 7};
|
||||||
|
|
||||||
|
//D-Box Expansion (sometimes noted as E BIT-SELECTION TABLE)
|
||||||
|
uint8_t message_expansion[48] = {
|
||||||
|
32, 1, 2, 3, 4, 5,
|
||||||
|
4, 5, 6, 7, 8, 9,
|
||||||
|
8, 9, 10, 11, 12, 13,
|
||||||
|
12, 13, 14, 15, 16, 17,
|
||||||
|
16, 17, 18, 19, 20, 21,
|
||||||
|
20, 21, 22, 23, 24, 25,
|
||||||
|
24, 25, 26, 27, 28, 29,
|
||||||
|
28, 29, 30, 31, 32, 1};
|
||||||
|
|
||||||
|
// (sometimes noted as simply 'P')
|
||||||
|
uint8_t right_half_permutation[32] = {
|
||||||
|
16, 7, 20, 21,
|
||||||
|
29, 12, 28, 17,
|
||||||
|
1, 15, 23, 26,
|
||||||
|
5, 18, 31, 10,
|
||||||
|
2, 8, 24, 14,
|
||||||
|
32, 27, 3, 9,
|
||||||
|
19, 13, 30, 6,
|
||||||
|
22, 11, 4, 25};
|
||||||
|
|
||||||
|
//inverse initial PI, a.k.a. final permutation (on output)
|
||||||
|
uint8_t final_register_permutation[64] = {
|
||||||
|
40, 8, 48, 16, 56, 24, 64, 32,
|
||||||
|
39, 7, 47, 15, 55, 23, 63, 31,
|
||||||
|
38, 6, 46, 14, 54, 22, 62, 30,
|
||||||
|
37, 5, 45, 13, 53, 21, 61, 29,
|
||||||
|
36, 4, 44, 12, 52, 20, 60, 28,
|
||||||
|
35, 3, 43, 11, 51, 19, 59, 27,
|
||||||
|
34, 2, 42, 10, 50, 18, 58, 26,
|
||||||
|
33, 1, 41, 9, 49, 17, 57, 25};
|
||||||
|
|
||||||
|
//initial key permutation
|
||||||
|
uint8_t pc1_key_permutation[56] = {
|
||||||
|
57, 49, 41, 33, 25, 17, 9,
|
||||||
|
1, 58, 50, 42, 34, 26, 18,
|
||||||
|
10, 2, 59, 51, 43, 35, 27,
|
||||||
|
19, 11, 3, 60, 52, 44, 36,
|
||||||
|
63, 55, 47, 39, 31, 23, 15,
|
||||||
|
7, 62, 54, 46, 38, 30, 22,
|
||||||
|
14, 6, 61, 53, 45, 37, 29,
|
||||||
|
21, 13, 5, 28, 20, 12, 4};
|
||||||
|
|
||||||
|
//sub c and d key permutation
|
||||||
|
uint8_t pc2_key_permutation[48] = {
|
||||||
|
//c bits
|
||||||
|
14,17,11,24,1,5,
|
||||||
|
3,28,15,6,21,10,
|
||||||
|
23,19,12,4,26,8,
|
||||||
|
16,7,27,20,13,2,
|
||||||
|
//d bits (with -28 offset to simply/only have one permute function)
|
||||||
|
13,24,3,9,19,27,
|
||||||
|
2,12,23,17,5,20,
|
||||||
|
16,21,11,28,6,25,
|
||||||
|
18,14,22,8,1,4
|
||||||
|
};
|
||||||
|
|
||||||
|
uint8_t key_shift_sizes[17] = {
|
||||||
|
1,
|
||||||
|
1, 1, 2, 2,
|
||||||
|
2, 2, 2, 2,
|
||||||
|
1, 2, 2, 2,
|
||||||
|
2, 2, 2, 1};
|
||||||
|
|
||||||
|
uint8_t key_shift_bytes[17] = {
|
||||||
|
0x80,
|
||||||
|
0x80, 0x80, 0xC0, 0xC0,
|
||||||
|
0xC0, 0xC0, 0xC0, 0xC0,
|
||||||
|
0x80, 0xC0, 0xC0, 0xC0,
|
||||||
|
0xC0, 0xC0, 0xC0, 0x80};
|
||||||
|
|
||||||
|
uint8_t key_shift_x[4] = {8,8,8,4};
|
||||||
|
|
||||||
|
uint8_t key_shift_y[4] = {1,2,3,0};
|
||||||
|
|
||||||
|
//input is byte-wise array, output is byte-wise array
|
||||||
|
void permute(uint8_t * input, uint8_t * output, uint8_t * table, uint8_t start, uint8_t end)
|
||||||
|
{
|
||||||
|
|
||||||
|
for (uint8_t i = start; i < end; i++)
|
||||||
|
{
|
||||||
|
uint8_t tdiv = (table[i] - 1) / 8;
|
||||||
|
uint8_t tmod = (table[i] - 1) % 8;
|
||||||
|
uint8_t idiv = i/8;
|
||||||
|
uint8_t imod = i%8;
|
||||||
|
|
||||||
|
//need a way to simplify or get rid of all these shifts
|
||||||
|
uint8_t bit = (((input[tdiv] & (0x80 >> tmod)) << tmod) >> imod);
|
||||||
|
output[idiv] |= bit;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void rotate_sub_keys(uint8_t * Kc, uint8_t * Kd, uint8_t shift_size, uint8_t shift_byte)
|
||||||
|
{
|
||||||
|
|
||||||
|
uint8_t sb1[4]; memset(sb1, 0, sizeof(sb1));
|
||||||
|
uint8_t sb2[4]; memset(sb2, 0, sizeof(sb2));
|
||||||
|
|
||||||
|
for (uint8_t i = 0; i < 4; i++)
|
||||||
|
{
|
||||||
|
sb1[i] = shift_byte & Kc[i];
|
||||||
|
sb2[i] = shift_byte & Kd[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
for (uint8_t i = 0; i < 4; i++)
|
||||||
|
{
|
||||||
|
|
||||||
|
uint8_t x = key_shift_x[i];
|
||||||
|
uint8_t y = key_shift_y[i];
|
||||||
|
|
||||||
|
Kc[i] <<= shift_size;
|
||||||
|
Kd[i] <<= shift_size;
|
||||||
|
|
||||||
|
Kc[i] |= (sb1[y] >> (x - shift_size));
|
||||||
|
Kd[i] |= (sb2[y] >> (x - shift_size));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void des_cipher (uint8_t * main_key, uint8_t * input_register, uint8_t * output_register, uint8_t de)
|
||||||
|
{
|
||||||
|
|
||||||
|
//starting and ending permutations
|
||||||
|
uint8_t initial_permutation[8]; memset(initial_permutation, 0, sizeof(initial_permutation));
|
||||||
|
uint8_t pre_end_permutation[8]; memset(pre_end_permutation, 0, sizeof(pre_end_permutation));
|
||||||
|
|
||||||
|
//intermediate left, right, and expansion/selection arrays
|
||||||
|
uint8_t left[4]; memset(left, 0, sizeof(left));
|
||||||
|
uint8_t right[4]; memset(right, 0, sizeof(right));
|
||||||
|
uint8_t rperm[4]; memset(rperm, 0, sizeof(rperm));
|
||||||
|
uint8_t exp[6]; memset(exp, 0, sizeof(exp));
|
||||||
|
uint8_t sel[4]; memset(sel, 0, sizeof(sel));
|
||||||
|
|
||||||
|
//key sets
|
||||||
|
uint8_t Ks[16][7]; memset(Ks, 0, sizeof(Ks));
|
||||||
|
uint8_t Kc[4]; memset(Kc, 0, sizeof(Kc));
|
||||||
|
uint8_t Kd[4]; memset(Kd, 0, sizeof(Kd));
|
||||||
|
|
||||||
|
//initial Ks permutation and shuffle to Kc and Kd
|
||||||
|
permute (main_key, Ks[0], pc1_key_permutation, 0, 56);
|
||||||
|
for (uint8_t i = 0; i < 3; i++)
|
||||||
|
{
|
||||||
|
Kc[i] = Ks[0][i];
|
||||||
|
}
|
||||||
|
Kc[3] = Ks[0][3] & 0xF0;
|
||||||
|
for (uint8_t i = 0; i < 3; i++)
|
||||||
|
{
|
||||||
|
Kd[i] = (Ks[0][i+3] & 0x0F) << 4;
|
||||||
|
Kd[i] |= (Ks[0][i+4] & 0xF0) >> 4;
|
||||||
|
}
|
||||||
|
Kd[3] = (Ks[0][6] & 0x0F) << 4;
|
||||||
|
|
||||||
|
//reset Ks
|
||||||
|
memset(Ks, 0, sizeof(Ks));
|
||||||
|
|
||||||
|
//create the 16 Ks rounds
|
||||||
|
for (uint8_t i = 0; i < 16; i++)
|
||||||
|
{
|
||||||
|
uint8_t shift_size = key_shift_sizes[i+1];
|
||||||
|
uint8_t shift_byte = key_shift_bytes[i+1];
|
||||||
|
rotate_sub_keys(Kc, Kd, shift_size, shift_byte);
|
||||||
|
permute (Kc, Ks[i], pc2_key_permutation, 0, 24);
|
||||||
|
permute (Kd, Ks[i], pc2_key_permutation, 24, 48);
|
||||||
|
}
|
||||||
|
|
||||||
|
//permute the input_register with the ip (initial_register_permutation) table
|
||||||
|
permute (input_register, initial_permutation, initial_register_permutation, 0, 64);
|
||||||
|
|
||||||
|
//copy the initial permutation to left and right half arrays
|
||||||
|
memcpy (left, initial_permutation+0, sizeof(left));
|
||||||
|
memcpy (right, initial_permutation+4, sizeof(right));
|
||||||
|
|
||||||
|
//16 feistel rounds
|
||||||
|
for (uint8_t f = 0; f < 16; f++)
|
||||||
|
{
|
||||||
|
|
||||||
|
//reset rperm and exp arrays
|
||||||
|
memset(rperm, 0, sizeof(rperm));
|
||||||
|
memset(exp, 0, sizeof(exp));
|
||||||
|
|
||||||
|
//expand right half from 32-bit to 48-bit
|
||||||
|
permute (right, exp, message_expansion, 0, 48);
|
||||||
|
|
||||||
|
//apply current iteration keyset to the expanded array (encryption cycles Ks forward, decryption goes in reverse)
|
||||||
|
if (de == 1)
|
||||||
|
{
|
||||||
|
for (uint8_t i = 0; i < 6; i++)
|
||||||
|
exp[i] ^= Ks[f][i];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (uint8_t i = 0; i < 6; i++)
|
||||||
|
exp[i] ^= Ks[15-f][i];
|
||||||
|
}
|
||||||
|
|
||||||
|
//extract 6 bits for each sbox swap from the expanded array
|
||||||
|
uint8_t e1 = exp[0] >> 2;
|
||||||
|
uint8_t e2 = ((exp[0] & 0x3) << 4) | (exp[1] >> 4);
|
||||||
|
uint8_t e3 = ((exp[1] & 0xF) << 2) | (exp[2] >> 6);
|
||||||
|
uint8_t e4 = exp[2] & 0x3F;
|
||||||
|
|
||||||
|
uint8_t e5 = exp[3] >> 2;
|
||||||
|
uint8_t e6 = ((exp[3] & 0x3) << 4) | (exp[4] >> 4);
|
||||||
|
uint8_t e7 = ((exp[4] & 0xF) << 2) | (exp[5] >> 6);
|
||||||
|
uint8_t e8 = exp[5] & 0x3F;
|
||||||
|
|
||||||
|
//select 32-bits of each 48-bit expansion via modified S Box Look Up Tables
|
||||||
|
//swap the 6 bits for 4 bits via SLUT tables and OR them together into a selection array
|
||||||
|
sel[0] = SLUT1[e1] | SLUT2[e2];
|
||||||
|
sel[1] = SLUT3[e3] | SLUT4[e4];
|
||||||
|
sel[2] = SLUT5[e5] | SLUT6[e6];
|
||||||
|
sel[3] = SLUT7[e7] | SLUT8[e8];
|
||||||
|
|
||||||
|
//permute the selected 32-bits into a new right half
|
||||||
|
permute (sel, rperm, right_half_permutation, 0, 32);
|
||||||
|
|
||||||
|
//xor new right half against left half
|
||||||
|
for (uint8_t i = 0; i < 4; i++)
|
||||||
|
rperm[i] ^= left[i];
|
||||||
|
|
||||||
|
//swap old right half to left, set new right half to rperm
|
||||||
|
memcpy (left, right, sizeof(left));
|
||||||
|
memcpy (right, rperm, sizeof(right));
|
||||||
|
|
||||||
|
} //end feistel rounds f
|
||||||
|
|
||||||
|
//combine right and left into the pre_end_permutation array
|
||||||
|
memcpy (pre_end_permutation+0, right, sizeof(right));
|
||||||
|
memcpy (pre_end_permutation+4, left, sizeof(left));
|
||||||
|
|
||||||
|
//carry out the final permuation to get the completed output_register for this cipher iteration
|
||||||
|
permute (pre_end_permutation, output_register, final_register_permutation, 0, 64);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//kirisun variation on this cipher w/ preconfigured unique key schedule
|
||||||
|
void ksun_des_cipher (uint8_t * key, uint8_t * input_register, uint8_t * output_register, uint8_t de)
|
||||||
|
{
|
||||||
|
|
||||||
|
//starting and ending permutations
|
||||||
|
uint8_t initial_permutation[8]; memset(initial_permutation, 0, sizeof(initial_permutation));
|
||||||
|
uint8_t pre_end_permutation[8]; memset(pre_end_permutation, 0, sizeof(pre_end_permutation));
|
||||||
|
|
||||||
|
//intermediate left, right, and expansion/selection arrays
|
||||||
|
uint8_t left[4]; memset(left, 0, sizeof(left));
|
||||||
|
uint8_t right[4]; memset(right, 0, sizeof(right));
|
||||||
|
uint8_t rperm[4]; memset(rperm, 0, sizeof(rperm));
|
||||||
|
uint8_t exp[6]; memset(exp, 0, sizeof(exp));
|
||||||
|
uint8_t sel[4]; memset(sel, 0, sizeof(sel));
|
||||||
|
|
||||||
|
//key sets
|
||||||
|
uint8_t Ks[16][6]; memset(Ks, 0, sizeof(Ks));
|
||||||
|
|
||||||
|
//file the key into the keysets
|
||||||
|
for (int i = 0; i < 16; i++)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < 6; j++)
|
||||||
|
Ks[i][j] = key[(i*6) + j];
|
||||||
|
}
|
||||||
|
|
||||||
|
//permute the input_register with the ip (initial_register_permutation) table
|
||||||
|
permute (input_register, initial_permutation, initial_register_permutation, 0, 64);
|
||||||
|
|
||||||
|
//copy the initial permutation to left and right half arrays
|
||||||
|
memcpy (left, initial_permutation+0, sizeof(left));
|
||||||
|
memcpy (right, initial_permutation+4, sizeof(right));
|
||||||
|
|
||||||
|
//16 feistel rounds
|
||||||
|
for (uint8_t f = 0; f < 16; f++)
|
||||||
|
{
|
||||||
|
|
||||||
|
//reset rperm and exp arrays
|
||||||
|
memset(rperm, 0, sizeof(rperm));
|
||||||
|
memset(exp, 0, sizeof(exp));
|
||||||
|
|
||||||
|
//expand right half from 32-bit to 48-bit
|
||||||
|
permute (right, exp, message_expansion, 0, 48);
|
||||||
|
|
||||||
|
//apply current iteration keyset to the expanded array (encryption cycles Ks forward, decryption goes in reverse)
|
||||||
|
if (de == 1)
|
||||||
|
{
|
||||||
|
for (uint8_t i = 0; i < 6; i++)
|
||||||
|
exp[i] ^= Ks[f][i];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (uint8_t i = 0; i < 6; i++)
|
||||||
|
exp[i] ^= Ks[15-f][i];
|
||||||
|
}
|
||||||
|
|
||||||
|
//extract 6 bits for each sbox swap from the expanded array
|
||||||
|
uint8_t e1 = exp[0] >> 2;
|
||||||
|
uint8_t e2 = ((exp[0] & 0x3) << 4) | (exp[1] >> 4);
|
||||||
|
uint8_t e3 = ((exp[1] & 0xF) << 2) | (exp[2] >> 6);
|
||||||
|
uint8_t e4 = exp[2] & 0x3F;
|
||||||
|
|
||||||
|
uint8_t e5 = exp[3] >> 2;
|
||||||
|
uint8_t e6 = ((exp[3] & 0x3) << 4) | (exp[4] >> 4);
|
||||||
|
uint8_t e7 = ((exp[4] & 0xF) << 2) | (exp[5] >> 6);
|
||||||
|
uint8_t e8 = exp[5] & 0x3F;
|
||||||
|
|
||||||
|
//select 32-bits of each 48-bit expansion via modified S Box Look Up Tables
|
||||||
|
//swap the 6 bits for 4 bits via SLUT tables and OR them together into a selection array
|
||||||
|
sel[0] = SLUT1[e1] | SLUT2[e2];
|
||||||
|
sel[1] = SLUT3[e3] | SLUT4[e4];
|
||||||
|
sel[2] = SLUT5[e5] | SLUT6[e6];
|
||||||
|
sel[3] = SLUT7[e7] | SLUT8[e8];
|
||||||
|
|
||||||
|
//permute the selected 32-bits into a new right half
|
||||||
|
permute (sel, rperm, right_half_permutation, 0, 32);
|
||||||
|
|
||||||
|
//xor new right half against left half
|
||||||
|
for (uint8_t i = 0; i < 4; i++)
|
||||||
|
rperm[i] ^= left[i];
|
||||||
|
|
||||||
|
//swap old right half to left, set new right half to rperm
|
||||||
|
memcpy (left, right, sizeof(left));
|
||||||
|
memcpy (right, rperm, sizeof(right));
|
||||||
|
|
||||||
|
} //end feistel rounds f
|
||||||
|
|
||||||
|
//combine right and left into the pre_end_permutation array
|
||||||
|
memcpy (pre_end_permutation+0, right, sizeof(right));
|
||||||
|
memcpy (pre_end_permutation+4, left, sizeof(left));
|
||||||
|
|
||||||
|
//carry out the final permuation to get the completed output_register for this cipher iteration
|
||||||
|
permute (pre_end_permutation, output_register, final_register_permutation, 0, 64);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void des56_ofb_keystream_output (uint8_t * main_key, uint8_t * iv, uint8_t * ks_bytes, uint8_t de, int16_t nblocks)
|
||||||
|
{
|
||||||
|
|
||||||
|
//cipher input and output
|
||||||
|
uint8_t input_register[8]; memset(input_register, 0, sizeof(input_register));
|
||||||
|
uint8_t output_register[8]; memset(output_register, 0, sizeof(output_register));
|
||||||
|
|
||||||
|
//copy the IV to the input_register (make copy so we don't manipulate the calling functions copy)
|
||||||
|
memcpy(input_register, iv, sizeof(input_register));
|
||||||
|
|
||||||
|
//execute the des_cipher in output feedback mode
|
||||||
|
for (int16_t i = 0; i < nblocks; i++)
|
||||||
|
{
|
||||||
|
//de should be 1 here for encryption mode
|
||||||
|
des_cipher(main_key, input_register, output_register, de);
|
||||||
|
memcpy(input_register, output_register, sizeof(output_register)); //recycle output_register back into input register
|
||||||
|
memcpy(ks_bytes+(i*8), output_register, sizeof(output_register)); //copy output_register to ks_bytes + iteration offset of times 8
|
||||||
|
memset(output_register, 0, sizeof(output_register)); //reset output register
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//the des_cipher function is already ECB mode, this convenience wrapper is just available as a reminder to illustrate that point
|
||||||
|
void des56_ecb_payload_crypt (uint8_t * main_key, uint8_t * input_register, uint8_t * output_register, uint8_t de)
|
||||||
|
{
|
||||||
|
//de 1 for encryption mode, 0 for decryption mode
|
||||||
|
des_cipher(main_key, input_register, output_register, de);
|
||||||
|
}
|
||||||
|
|
||||||
|
//TDEA, or triple data encryption algorithm, or triple DES, in electronic codebook mode
|
||||||
|
void tdea_ecb_payload_crypt (uint8_t * K1, uint8_t * K2, uint8_t * K3, uint8_t * input, uint8_t * output, uint8_t de)
|
||||||
|
{
|
||||||
|
|
||||||
|
//cipher input and output
|
||||||
|
uint8_t input_register[8]; memset(input_register, 0, sizeof(input_register));
|
||||||
|
uint8_t output_register[8]; memset(output_register, 0, sizeof(output_register));
|
||||||
|
|
||||||
|
//copy the input to the input_register (make copy so we don't manipulate the calling functions copy)
|
||||||
|
memcpy(input_register, input, sizeof(input_register));
|
||||||
|
|
||||||
|
//For TDEA, the cipher alternates between encryption and decryption to the payload
|
||||||
|
//so, for example, K1 is run as de=1, K2 is run as de=0, and K3 is run as de=1,
|
||||||
|
//K1 and K3 will always use the same mode and K2 will be the opposite
|
||||||
|
|
||||||
|
//NOTE: If running ECB mode in decryption, make sure to send the keys in reverse order
|
||||||
|
//so that its K3, K2, and K1 for decryption, and K1, K2, K3 for encryption
|
||||||
|
|
||||||
|
//K1
|
||||||
|
des_cipher(K1, input_register, output_register, de);
|
||||||
|
memcpy(input_register, output_register, sizeof(output_register)); //recycle output_register back into input_register
|
||||||
|
memset(output_register, 0, sizeof(output_register)); //reset output register
|
||||||
|
|
||||||
|
//K2
|
||||||
|
de = (de ^ 1) & 1; //flip the de bit
|
||||||
|
des_cipher(K2, input_register, output_register, de);
|
||||||
|
memcpy(input_register, output_register, sizeof(output_register)); //recycle output_register back into input_register
|
||||||
|
memset(output_register, 0, sizeof(output_register)); //reset output register
|
||||||
|
|
||||||
|
//K3
|
||||||
|
de = (de ^ 1) & 1; //flip the de bit back
|
||||||
|
des_cipher(K3, input_register, output_register, de);
|
||||||
|
|
||||||
|
//copy payload out
|
||||||
|
memcpy(output, output_register, sizeof(output_register)); //copy output_register to output
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//TDEA, or triple data encryption algorithm, or triple DES, in cipher block chain mode (64-bit)
|
||||||
|
//same as usual inputs (byte wise), also, if needing DES56, just feed the same key into K1, K2, and K3
|
||||||
|
//if running in decryption mode, this will reverse the key bundle order from (K1, K2, K3) to (K3, K2, K1) on this end
|
||||||
|
void tdea_cbc_payload_crypt (uint8_t * K1, uint8_t * K2, uint8_t * K3, uint8_t * iv, uint8_t * in, uint8_t * out, int16_t nblocks, uint8_t de)
|
||||||
|
{
|
||||||
|
|
||||||
|
int16_t i, j;
|
||||||
|
|
||||||
|
//cipher input and output
|
||||||
|
uint8_t input_register[8]; memset(input_register, 0, sizeof(input_register));
|
||||||
|
uint8_t output_register[8]; memset(output_register, 0, sizeof(output_register));
|
||||||
|
|
||||||
|
//load first round of input_register accordingly
|
||||||
|
if (de)
|
||||||
|
memcpy (input_register, iv, sizeof(input_register)); //load the IV as first input_register if encrypting
|
||||||
|
else memcpy (input_register, in, sizeof(input_register)); //load first cipher text as input_register is decrypting
|
||||||
|
|
||||||
|
//run payload for number of payload nblocks required
|
||||||
|
for (i = 0; i < nblocks; i++)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (de)
|
||||||
|
{
|
||||||
|
|
||||||
|
//xor the current input 'in' pt to the current state of the input_register for cbc feedback
|
||||||
|
for (j = 0; j < 8; j++)
|
||||||
|
input_register[j] ^= in[j+(i*8)];
|
||||||
|
|
||||||
|
//K1
|
||||||
|
des_cipher(K1, input_register, output_register, de);
|
||||||
|
memcpy(input_register, output_register, sizeof(output_register)); //recycle output_register back into input_register
|
||||||
|
memset(output_register, 0, sizeof(output_register)); //reset output register
|
||||||
|
|
||||||
|
//K2
|
||||||
|
de = (de ^ 1) & 1; //flip the de bit
|
||||||
|
des_cipher(K2, input_register, output_register, de);
|
||||||
|
memcpy(input_register, output_register, sizeof(output_register)); //recycle output_register back into input_register
|
||||||
|
memset(output_register, 0, sizeof(output_register)); //reset output register
|
||||||
|
|
||||||
|
//K3
|
||||||
|
de = (de ^ 1) & 1; //flip the de bit back
|
||||||
|
des_cipher(K3, input_register, output_register, de);
|
||||||
|
memcpy (input_register, output_register, sizeof(output_register)); //recycle output_register back into input_register
|
||||||
|
|
||||||
|
//copy ciphered output_register to output 'out'
|
||||||
|
memcpy (out+(i*8), output_register, sizeof(output_register));
|
||||||
|
memset(output_register, 0, sizeof(output_register)); //reset output register
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
//K3
|
||||||
|
des_cipher(K3, input_register, output_register, de);
|
||||||
|
memcpy(input_register, output_register, sizeof(output_register)); //recycle output_register back into input_register
|
||||||
|
memset(output_register, 0, sizeof(output_register)); //reset output register
|
||||||
|
|
||||||
|
//K2
|
||||||
|
de = (de ^ 1) & 1; //flip the de bit
|
||||||
|
des_cipher(K2, input_register, output_register, de);
|
||||||
|
memcpy(input_register, output_register, sizeof(output_register)); //recycle output_register back into input_register
|
||||||
|
memset(output_register, 0, sizeof(output_register)); //reset output register
|
||||||
|
|
||||||
|
//K1
|
||||||
|
de = (de ^ 1) & 1; //flip the de bit back
|
||||||
|
des_cipher(K1, input_register, output_register, de);
|
||||||
|
memcpy (input_register, output_register, sizeof(output_register)); //recycle output_register back into input_register
|
||||||
|
|
||||||
|
//copy ciphered input_register to output 'out'
|
||||||
|
memcpy (out+(i*8), output_register, sizeof(output_register));
|
||||||
|
|
||||||
|
//xor the current output by IV, or by last received CT, depending on round
|
||||||
|
if (i == 0)
|
||||||
|
{
|
||||||
|
for (j = 0; j < 8; j++)
|
||||||
|
out[j] ^= iv[j];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (j = 0; j < 8; j++)
|
||||||
|
out[j+(i*8)] ^= in[j+((i-1)*8)];
|
||||||
|
}
|
||||||
|
|
||||||
|
//copy in next segment for input_register (if not last)
|
||||||
|
if (i < nblocks)
|
||||||
|
memcpy(input_register, in+((i+1)*8), sizeof(input_register));
|
||||||
|
|
||||||
|
memset(output_register, 0, sizeof(output_register)); //reset output register
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//TDEA, or triple data encryption algorithm, or triple DES, in cipher block chain mode (64-bit)
|
||||||
|
//same as usual inputs (byte wise), also, if needing DES56, just feed the same key into K1, K2, and K3
|
||||||
|
//only the last output_register is returned for the variable len MAC bytes, always run in encryption mode
|
||||||
|
//but if iv is desireable, it will need to be pre-XOR'd with the first plaintext input block by the calling function
|
||||||
|
void tdea_cbc_mac_generator (uint8_t * K1, uint8_t * K2, uint8_t * K3, uint8_t * in, uint8_t * out, int16_t nblocks)
|
||||||
|
{
|
||||||
|
|
||||||
|
int16_t i, j;
|
||||||
|
|
||||||
|
//cipher input and output
|
||||||
|
uint8_t input_register[8]; memset(input_register, 0, sizeof(input_register));
|
||||||
|
uint8_t output_register[8]; memset(output_register, 0, sizeof(output_register));
|
||||||
|
|
||||||
|
//run payload for number of payload nblocks required
|
||||||
|
for (i = 0; i < nblocks; i++)
|
||||||
|
{
|
||||||
|
|
||||||
|
//the cipher is always run in the foward, or encryption mode (1,0,1)
|
||||||
|
|
||||||
|
//xor the current input 'in' pt to the current state of the input_register for cbc feedback
|
||||||
|
for (j = 0; j < 8; j++)
|
||||||
|
input_register[j] ^= in[j+(i*8)];
|
||||||
|
|
||||||
|
//K1
|
||||||
|
des_cipher(K1, input_register, output_register, 1);
|
||||||
|
memcpy(input_register, output_register, sizeof(output_register)); //recycle output_register back into input_register
|
||||||
|
memset(output_register, 0, sizeof(output_register)); //reset output register
|
||||||
|
|
||||||
|
//K2
|
||||||
|
des_cipher(K2, input_register, output_register, 0);
|
||||||
|
memcpy(input_register, output_register, sizeof(output_register)); //recycle output_register back into input_register
|
||||||
|
memset(output_register, 0, sizeof(output_register)); //reset output register
|
||||||
|
|
||||||
|
//K3
|
||||||
|
des_cipher(K3, input_register, output_register, 1);
|
||||||
|
memcpy (input_register, output_register, sizeof(output_register));
|
||||||
|
|
||||||
|
//copy ciphered output_register to output 'out'
|
||||||
|
//Since we only want the last output_register,
|
||||||
|
//this will overwrite the out until completion
|
||||||
|
memcpy (out, output_register, sizeof(output_register));
|
||||||
|
|
||||||
|
memset(output_register, 0, sizeof(output_register)); //reset output register
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//TDEA, or triple data encryption algorithm, or triple DES, in cihper feedback mode (64-bit)
|
||||||
|
//same as usual inputs (byte wise), also, if needing DES56, just feed the same key into K1, K2, and K3
|
||||||
|
void tdea_cfb_payload_crypt (uint8_t * K1, uint8_t * K2, uint8_t * K3, uint8_t * iv, uint8_t * in, uint8_t * out, int16_t nblocks, uint8_t de)
|
||||||
|
{
|
||||||
|
|
||||||
|
int16_t i, j;
|
||||||
|
|
||||||
|
//cipher input and output
|
||||||
|
uint8_t input_register[8]; memset(input_register, 0, sizeof(input_register));
|
||||||
|
uint8_t output_register[8]; memset(output_register, 0, sizeof(output_register));
|
||||||
|
|
||||||
|
//copy the IV to the input_register (make copy so we don't manipulate the calling functions copy)
|
||||||
|
memcpy(input_register, iv, sizeof(input_register));
|
||||||
|
|
||||||
|
//execute the des_cipher in output feedback mode 3 times using each key and transferring output to input each time
|
||||||
|
for (i = 0; i < nblocks; i++)
|
||||||
|
{
|
||||||
|
|
||||||
|
//the cipher is always run in the foward, or encryption mode (1,0,1)
|
||||||
|
|
||||||
|
//K1
|
||||||
|
des_cipher(K1, input_register, output_register, 1);
|
||||||
|
memcpy(input_register, output_register, sizeof(output_register)); //recycle output_register back into input_register
|
||||||
|
memset(output_register, 0, sizeof(output_register)); //reset output register
|
||||||
|
|
||||||
|
//K2
|
||||||
|
des_cipher(K2, input_register, output_register, 0);
|
||||||
|
memcpy(input_register, output_register, sizeof(output_register)); //recycle output_register back into input_register
|
||||||
|
memset(output_register, 0, sizeof(output_register)); //reset output register
|
||||||
|
|
||||||
|
//K3
|
||||||
|
des_cipher(K3, input_register, output_register, 1);
|
||||||
|
|
||||||
|
//xor the current input 'in' to the current state of the input_register for cipher feedback
|
||||||
|
for (j = 0; j < 8; j++)
|
||||||
|
output_register[j] ^= in[j+(i*8)];
|
||||||
|
|
||||||
|
memcpy(input_register, output_register, sizeof(output_register)); //recycle output_register back into input_register
|
||||||
|
|
||||||
|
//copy keystream out and reset
|
||||||
|
memcpy(out+(i*8), output_register, sizeof(output_register)); //copy output_register to ks_bytes + iteration offset of times 8
|
||||||
|
memset(output_register, 0, sizeof(output_register)); //reset output register
|
||||||
|
|
||||||
|
//if running in decryption mode, we feed in the next round of input
|
||||||
|
if (!de)
|
||||||
|
memcpy(input_register, in+(i*8), sizeof(input_register));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//TDEA, or triple data encryption algorithm, or triple DES, in IV counter mode (tested, working)
|
||||||
|
void tdea_ctr_payload_crypt (uint8_t * K1, uint8_t * K2, uint8_t * K3, uint8_t * iv, uint8_t * input, uint8_t * output, int16_t nblocks)
|
||||||
|
{
|
||||||
|
|
||||||
|
int16_t i, j;
|
||||||
|
|
||||||
|
//cipher input and output
|
||||||
|
uint8_t input_register[8]; memset(input_register, 0, sizeof(input_register));
|
||||||
|
uint8_t output_register[8]; memset(output_register, 0, sizeof(output_register));
|
||||||
|
|
||||||
|
//copy the IV to the input_register (ctr mode will manipulate the IV, since it needs to keep a rolling counter
|
||||||
|
memcpy(input_register, iv, sizeof(input_register));
|
||||||
|
|
||||||
|
//execute the des_cipher in counter mode 3 times using each key and transferring output to input each time
|
||||||
|
//then the IV is iterated and fed back into the input_register to start the next nblocks loop
|
||||||
|
for (i = 0; i < nblocks; i++)
|
||||||
|
{
|
||||||
|
|
||||||
|
//CTR mode cipher should always run in the forward (encryption) mode
|
||||||
|
|
||||||
|
//K1
|
||||||
|
des_cipher(K1, input_register, output_register, 1);
|
||||||
|
memcpy(input_register, output_register, sizeof(output_register)); //recycle output_register back into input_register
|
||||||
|
memset(output_register, 0, sizeof(output_register)); //reset output register
|
||||||
|
|
||||||
|
//K2
|
||||||
|
des_cipher(K2, input_register, output_register, 0);
|
||||||
|
memcpy(input_register, output_register, sizeof(output_register)); //recycle output_register back into input_register
|
||||||
|
memset(output_register, 0, sizeof(output_register)); //reset output register
|
||||||
|
|
||||||
|
//K3
|
||||||
|
des_cipher(K3, input_register, output_register, 1);
|
||||||
|
|
||||||
|
//set output at current pointer to the xor of input current pointer and the output_register
|
||||||
|
for (j = 0; j < 8; j++)
|
||||||
|
output[j+(i*8)] = input[j+(i*8)] ^ output_register[j];
|
||||||
|
|
||||||
|
memset(output_register, 0, sizeof(output_register)); //reset output register
|
||||||
|
|
||||||
|
//increment the IV, and handle roll over (uint8_t will rollover to 0 after 0xFF)
|
||||||
|
for (j = 7; j >= 0; j--)
|
||||||
|
{
|
||||||
|
iv[j]++;
|
||||||
|
if (iv[j] == 0)
|
||||||
|
continue;
|
||||||
|
else break;
|
||||||
|
}
|
||||||
|
|
||||||
|
//debug IV iteration
|
||||||
|
// fprintf (stderr, "\n IV: ");
|
||||||
|
// for (j = 0; j < 8; j++)
|
||||||
|
// fprintf (stderr, "%02X", iv[j]);
|
||||||
|
|
||||||
|
//feed the new IV into the input register
|
||||||
|
memcpy (input_register, iv, sizeof(input_register));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//TDEA, or triple data encryption algorithm, or triple DES, in output feedback mode
|
||||||
|
void tdea_tofb_keystream_output (uint8_t * K1, uint8_t * K2, uint8_t * K3, uint8_t * iv, uint8_t * ks_bytes, uint8_t de, int16_t nblocks)
|
||||||
|
{
|
||||||
|
|
||||||
|
//cipher input and output
|
||||||
|
uint8_t input_register[8]; memset(input_register, 0, sizeof(input_register));
|
||||||
|
uint8_t output_register[8]; memset(output_register, 0, sizeof(output_register));
|
||||||
|
|
||||||
|
//copy the IV to the input_register (make copy so we don't manipulate the calling functions copy)
|
||||||
|
memcpy(input_register, iv, sizeof(input_register));
|
||||||
|
|
||||||
|
//execute the des_cipher in output feedback mode 3 times using each key and transferring output to input each time
|
||||||
|
for (int16_t i = 0; i < nblocks; i++)
|
||||||
|
{
|
||||||
|
//K1
|
||||||
|
des_cipher(K1, input_register, output_register, de);
|
||||||
|
memcpy(input_register, output_register, sizeof(output_register)); //recycle output_register back into input_register
|
||||||
|
memset(output_register, 0, sizeof(output_register)); //reset output register
|
||||||
|
|
||||||
|
//K2
|
||||||
|
de = (de ^ 1) & 1; //flip the de bit
|
||||||
|
des_cipher(K2, input_register, output_register, de);
|
||||||
|
memcpy(input_register, output_register, sizeof(output_register)); //recycle output_register back into input_register
|
||||||
|
memset(output_register, 0, sizeof(output_register)); //reset output register
|
||||||
|
|
||||||
|
//K3
|
||||||
|
de = (de ^ 1) & 1; //flip the de bit back
|
||||||
|
des_cipher(K3, input_register, output_register, de);
|
||||||
|
memcpy(input_register, output_register, sizeof(output_register)); //recycle output_register back into input_register
|
||||||
|
|
||||||
|
//copy keystream out and reset
|
||||||
|
memcpy(ks_bytes+(i*8), output_register, sizeof(output_register)); //copy output_register to ks_bytes + iteration offset of times 8
|
||||||
|
memset(output_register, 0, sizeof(output_register)); //reset output register
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//a linear feedback shift register with maximal taps on 64-bit values that can be run to any specified len,
|
||||||
|
//its input is a byte array of up to 8 bytes, and its output is same array packed with new LFSR value in it.
|
||||||
|
uint64_t lfsr_64_to_len_ca(uint8_t * iv, int16_t len)
|
||||||
|
{
|
||||||
|
|
||||||
|
uint64_t lfsr = 0, bit = 0;
|
||||||
|
|
||||||
|
lfsr = ((uint64_t)iv[0] << 56ULL) + ((uint64_t)iv[1] << 48ULL) + ((uint64_t)iv[2] << 40ULL) + ((uint64_t)iv[3] << 32ULL) +
|
||||||
|
((uint64_t)iv[4] << 24ULL) + ((uint64_t)iv[5] << 16ULL) + ((uint64_t)iv[6] << 8ULL) + ((uint64_t)iv[7] << 0ULL);
|
||||||
|
|
||||||
|
memset (iv, 0, 8*sizeof(uint8_t));
|
||||||
|
|
||||||
|
for(int16_t cnt = 0; cnt < len; cnt++)
|
||||||
|
{
|
||||||
|
//63,61,45,37,27,14
|
||||||
|
// Polynomial is C(x) = x^64 + x^62 + x^46 + x^38 + x^27 + x^15 + 1
|
||||||
|
bit = ((lfsr >> 63) ^ (lfsr >> 61) ^ (lfsr >> 45) ^ (lfsr >> 37) ^ (lfsr >> 26) ^ (lfsr >> 14)) & 0x1;
|
||||||
|
lfsr = (lfsr << 1) | bit;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int16_t i = 0; i < 8; i++)
|
||||||
|
iv[i] = (lfsr >> (56-(i*8))) & 0xFF;
|
||||||
|
|
||||||
|
// fprintf (stderr, "\n IV(%02d): ", len);
|
||||||
|
// for (int16_t i = 0; i < 8; i++)
|
||||||
|
// fprintf (stderr, "%02X", iv[i]);
|
||||||
|
|
||||||
|
return bit;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void des56_ca_keystream_output (uint8_t * main_key, uint8_t * iv, uint8_t * ks_bytes, uint8_t de, int16_t ff, int16_t nbits)
|
||||||
|
{
|
||||||
|
|
||||||
|
//cipher input and output
|
||||||
|
uint8_t input_register[8]; memset(input_register, 0, sizeof(input_register));
|
||||||
|
uint8_t output_register[8]; memset(output_register, 0, sizeof(output_register));
|
||||||
|
|
||||||
|
//copy the IV to the input_register (make copy so we don't manipulate the calling functions copy)
|
||||||
|
memcpy(input_register, iv, sizeof(input_register));
|
||||||
|
|
||||||
|
//fast forward the current input_register state
|
||||||
|
lfsr_64_to_len_ca(input_register, ff);
|
||||||
|
|
||||||
|
//execute the des_cipher in (CA) mode with 1-bit output
|
||||||
|
for (int16_t i = 0; i < nbits; i++)
|
||||||
|
{
|
||||||
|
|
||||||
|
//de should be 1 here for encryption mode
|
||||||
|
des_cipher(main_key, input_register, output_register, de);
|
||||||
|
|
||||||
|
//keystream accumulation, shift current byte and append
|
||||||
|
//single bit from current output register's most significant bit
|
||||||
|
ks_bytes[i/8] <<= 1;
|
||||||
|
ks_bytes[i/8] |= ((output_register[0] >> 7) & 1);
|
||||||
|
|
||||||
|
//advance the input_register with the lfsr 1 time
|
||||||
|
lfsr_64_to_len_ca(input_register, 1);
|
||||||
|
|
||||||
|
//reset output register
|
||||||
|
memset(output_register, 0, sizeof(output_register));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// fprintf (stderr, "\n IR: ");
|
||||||
|
// for (int16_t i = 0; i < 8; i++)
|
||||||
|
// fprintf (stderr, "%02X", input_register[i]);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//transitional function mainly to load key and iv into an array
|
||||||
|
void des_multi_keystream_output (unsigned long long int mi, unsigned long long int key_ulli, uint8_t * output, int type, int len)
|
||||||
|
{
|
||||||
|
int i = 0;
|
||||||
|
uint8_t iv[8]; memset (iv, 0, sizeof(iv));
|
||||||
|
uint8_t key[8]; memset(key, 0, sizeof(key));
|
||||||
|
|
||||||
|
//convert unsinged long long int values into array values
|
||||||
|
for (i = 7; i >= 0; i--)
|
||||||
|
iv[7-i] = (mi >> (8*i)) & 0xFF;
|
||||||
|
|
||||||
|
for (i = 7; i >= 0; i--)
|
||||||
|
key[7-i] = (key_ulli >> (8*i)) & 0xFF;
|
||||||
|
|
||||||
|
//debug
|
||||||
|
// fprintf (stderr, "\n IV: ");
|
||||||
|
// for (i = 0; i < 8; i++)
|
||||||
|
// fprintf (stderr, "%02X", iv[i]);
|
||||||
|
// fprintf (stderr, "\n Key: ");
|
||||||
|
// for (i = 0; i < 8; i++)
|
||||||
|
// fprintf (stderr, "%02X", key[i]);
|
||||||
|
|
||||||
|
//types: 1 = DES56 OFB; 2 = DES56 CA (XL)
|
||||||
|
if (type == 2)
|
||||||
|
{
|
||||||
|
if (len == 0)
|
||||||
|
des56_ca_keystream_output(key, iv, output, 1, 110+696, 1704);
|
||||||
|
else des56_ca_keystream_output(key, iv, output, 1, 110+000, 1704);
|
||||||
|
}
|
||||||
|
else des56_ofb_keystream_output(key, iv, output, 1, len);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//transitional function mainly to load iv into an array
|
||||||
|
void tdea_multi_keystream_output (unsigned long long int mi, uint8_t * key, uint8_t * output, int type, int len)
|
||||||
|
{
|
||||||
|
int i = 0;
|
||||||
|
uint8_t iv[8]; memset (iv, 0, sizeof(iv));
|
||||||
|
|
||||||
|
//convert unsinged long long int values into array values
|
||||||
|
for (i = 7; i >= 0; i--)
|
||||||
|
iv[7-i] = (mi >> (8*i)) & 0xFF;
|
||||||
|
|
||||||
|
//debug
|
||||||
|
// fprintf (stderr, "\n IV: ");
|
||||||
|
// for (i = 0; i < 8; i++)
|
||||||
|
// fprintf (stderr, "%02X", iv[i]);
|
||||||
|
|
||||||
|
//type 1 = TDEA TOFB //TODO: Add more types like 2DES?
|
||||||
|
if (type == 1)
|
||||||
|
tdea_tofb_keystream_output(key, key+8, key+16, iv, output, 1, len);
|
||||||
|
else tdea_tofb_keystream_output(key, key+8, key+16, iv, output, 1, len);
|
||||||
|
|
||||||
|
}
|
||||||
354
src/crypt-etc.c
Normal file
354
src/crypt-etc.c
Normal file
@@ -0,0 +1,354 @@
|
|||||||
|
#include "dsd.h"
|
||||||
|
#include "dmr_const.h"
|
||||||
|
|
||||||
|
void ken_dmr_scrambler_keystream_creation(dsd_state * state, char * input)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
SLOT 1 Protected LC FLCO=0x00 FID=0x20 <--this link appears to indicate scrambler usage from Kenwood on DMR
|
||||||
|
DMR PDU Payload [80][20][40][00][00][01][00][00][01] SB: 00000000000 - 000;
|
||||||
|
|
||||||
|
SLOT 1 TGT=1 SRC=1 FLCO=0x00 FID=0x00 SVC=0x00 Group Call <--different call, no scrambler from same Kenwood Radio
|
||||||
|
DMR PDU Payload [00][00][00][00][00][01][00][00][01]
|
||||||
|
|
||||||
|
For This, we could possible transition this to not be enforced
|
||||||
|
since we may have a positive indicator in link control,
|
||||||
|
but needs further samples and validation
|
||||||
|
*/
|
||||||
|
|
||||||
|
int lfsr = 0, bit = 0;
|
||||||
|
sscanf (input, "%d", &lfsr);
|
||||||
|
fprintf (stderr,"DMR Kenwood 15-bit Scrambler Key %05d with Forced Application\n", lfsr);
|
||||||
|
|
||||||
|
for (int i = 0; i < 882; i++)
|
||||||
|
{
|
||||||
|
state->static_ks_bits[0][i] = lfsr & 0x1;
|
||||||
|
state->static_ks_bits[1][i] = lfsr & 0x1;
|
||||||
|
bit = ( (lfsr >> 1) ^ (lfsr >> 0) ) & 1;
|
||||||
|
lfsr = ( (lfsr >> 1 ) | (bit << 14) );
|
||||||
|
}
|
||||||
|
|
||||||
|
state->ken_sc = 1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void anytone_bp_keystream_creation(dsd_state * state, char * input)
|
||||||
|
{
|
||||||
|
uint16_t key = 0;
|
||||||
|
uint16_t kperm = 0;
|
||||||
|
|
||||||
|
sscanf (input, "%hX", &key);
|
||||||
|
key &= 0xFFFF; //truncate to 16-bits
|
||||||
|
|
||||||
|
//calculate key permutation using simple operations
|
||||||
|
uint8_t nib1, nib2, nib3, nib4;
|
||||||
|
|
||||||
|
//nib 1 and 3 are simple inversions
|
||||||
|
nib1 = ~(key >> 12) & 0xF;
|
||||||
|
nib3 = ~(key >> 4) & 0xF;
|
||||||
|
|
||||||
|
//nib 2 and 4 are +8 and mod 16 (& 0xF)
|
||||||
|
nib2 = (((key >> 8) & 0xF) + 8) % 16;
|
||||||
|
nib4 = (((key >> 0) & 0xF) + 8) % 16;
|
||||||
|
|
||||||
|
//debug
|
||||||
|
// fprintf (stderr, "{%01X, %01X, %01X, %01X}", nib1, nib2, nib3, nib4);
|
||||||
|
|
||||||
|
kperm = nib1;
|
||||||
|
kperm <<= 4;
|
||||||
|
kperm |= nib2;
|
||||||
|
kperm <<= 4;
|
||||||
|
kperm |= nib3;
|
||||||
|
kperm <<= 4;
|
||||||
|
kperm |= nib4;
|
||||||
|
|
||||||
|
//load bits into static keystream
|
||||||
|
for (int i = 0; i < 16; i++)
|
||||||
|
{
|
||||||
|
state->static_ks_bits[0][i] = (kperm >> (15-i)) & 1;
|
||||||
|
state->static_ks_bits[1][i] = (kperm >> (15-i)) & 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf (stderr,"DMR Anytone Basic 16-bit Key 0x%04X with Forced Application\n", key);
|
||||||
|
state->any_bp = 1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void straight_mod_xor_keystream_creation(dsd_state * state, char * input)
|
||||||
|
{
|
||||||
|
uint16_t len = 0;
|
||||||
|
char * curr;
|
||||||
|
curr = strtok(input, ":"); //should be len (mod) of key (decimal)
|
||||||
|
if (curr != NULL)
|
||||||
|
sscanf (curr, "%hd", &len);
|
||||||
|
else goto END_KS;
|
||||||
|
|
||||||
|
//len sanity check, can't be greater than 882
|
||||||
|
if (len > 882)
|
||||||
|
len = 882;
|
||||||
|
|
||||||
|
curr = strtok(NULL, ":"); //should be key in hex
|
||||||
|
if (curr != NULL)
|
||||||
|
{
|
||||||
|
//continue
|
||||||
|
}
|
||||||
|
else goto END_KS;
|
||||||
|
|
||||||
|
//debug
|
||||||
|
// fprintf (stderr, "\ncurr: %s\n", curr);
|
||||||
|
|
||||||
|
uint8_t ks_bytes[112];
|
||||||
|
memset (ks_bytes, 0, sizeof(ks_bytes));
|
||||||
|
parse_raw_user_string(curr, ks_bytes);
|
||||||
|
|
||||||
|
uint8_t ks_bits[896];
|
||||||
|
memset(ks_bits, 0, sizeof(ks_bits));
|
||||||
|
|
||||||
|
uint16_t unpack_len = len / 8;
|
||||||
|
if (len % 8)
|
||||||
|
unpack_len++;
|
||||||
|
unpack_byte_array_into_bit_array(ks_bytes, ks_bits, unpack_len);
|
||||||
|
|
||||||
|
for (uint16_t i = 0; i < len; i++)
|
||||||
|
{
|
||||||
|
state->static_ks_bits[0][i] = ks_bits[i];
|
||||||
|
state->static_ks_bits[1][i] = ks_bits[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf (stderr,"AMBE Straight XOR %d-bit Keystream: ", len);
|
||||||
|
for (uint16_t i = 0; i < unpack_len; i++)
|
||||||
|
fprintf (stderr, "%02X", ks_bytes[i]);
|
||||||
|
fprintf (stderr, " with Forced Application \n");
|
||||||
|
|
||||||
|
state->straight_ks = 1;
|
||||||
|
state->straight_mod = (int)len;
|
||||||
|
|
||||||
|
END_KS:
|
||||||
|
|
||||||
|
if (curr == NULL)
|
||||||
|
fprintf (stderr, "Straight KS String Malformed! No KS Created!\n");
|
||||||
|
else
|
||||||
|
{
|
||||||
|
curr = strtok(NULL, ":"); //optional discard value
|
||||||
|
if (curr != NULL)
|
||||||
|
{
|
||||||
|
len = 0;
|
||||||
|
sscanf (curr, "%hd", &len);
|
||||||
|
if (len != 0 && len < 8)
|
||||||
|
{
|
||||||
|
state->straight_discard = (int)len;
|
||||||
|
fprintf (stderr, "Optional Straight XOR Keystream Discard: %d; \n", len);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void caltta_bp_keystream_creation(dsd_state * state, char * input)
|
||||||
|
{
|
||||||
|
uint16_t len = 0;
|
||||||
|
char * curr;
|
||||||
|
curr = strtok(input, ":"); //should be len (mod) of key (decimal)
|
||||||
|
if (curr != NULL)
|
||||||
|
sscanf (curr, "%hd", &len);
|
||||||
|
else goto END_KS;
|
||||||
|
|
||||||
|
//len sanity check, can't be greater than 882
|
||||||
|
if (len > 256)
|
||||||
|
len = 256;
|
||||||
|
|
||||||
|
curr = strtok(NULL, ":"); //should be key in hex
|
||||||
|
if (curr != NULL)
|
||||||
|
{
|
||||||
|
//continue
|
||||||
|
}
|
||||||
|
else goto END_KS;
|
||||||
|
|
||||||
|
uint8_t ks_bytes[112];
|
||||||
|
memset (ks_bytes, 0, sizeof(ks_bytes));
|
||||||
|
parse_raw_user_string(curr, ks_bytes);
|
||||||
|
|
||||||
|
uint8_t ks_bits[896];
|
||||||
|
memset(ks_bits, 0, sizeof(ks_bits));
|
||||||
|
|
||||||
|
uint16_t unpack_len = len / 8;
|
||||||
|
if (len % 8)
|
||||||
|
unpack_len++;
|
||||||
|
unpack_byte_array_into_bit_array(ks_bytes, ks_bits, unpack_len);
|
||||||
|
|
||||||
|
for (uint16_t i = 0; i < len; i++)
|
||||||
|
{
|
||||||
|
state->static_ks_bits[0][i] = ks_bits[i];
|
||||||
|
state->static_ks_bits[1][i] = ks_bits[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf (stderr,"Caltta BP %d-bit Keystream: ", len);
|
||||||
|
for (uint16_t i = 0; i < unpack_len; i++)
|
||||||
|
fprintf (stderr, "%02X", ks_bytes[i]);
|
||||||
|
fprintf (stderr, "\n");
|
||||||
|
|
||||||
|
state->straight_ks = 0x26;
|
||||||
|
state->straight_mod = (int)len;
|
||||||
|
|
||||||
|
END_KS:
|
||||||
|
|
||||||
|
if (curr == NULL)
|
||||||
|
fprintf (stderr, "Caltta BP KS String Malformed! No KS Created!\n");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void hytera_bp_keystream_creation(dsd_state * state, char * input)
|
||||||
|
{
|
||||||
|
uint16_t len = 0;
|
||||||
|
char * curr;
|
||||||
|
curr = strtok(input, ":"); //should be len (mod) of key (decimal)
|
||||||
|
if (curr != NULL)
|
||||||
|
sscanf (curr, "%hd", &len);
|
||||||
|
else goto END_KS;
|
||||||
|
|
||||||
|
//len sanity check, can't be greater than 882
|
||||||
|
if (len > 256)
|
||||||
|
len = 256;
|
||||||
|
|
||||||
|
curr = strtok(NULL, ":"); //should be key in hex
|
||||||
|
if (curr != NULL)
|
||||||
|
{
|
||||||
|
//continue
|
||||||
|
}
|
||||||
|
else goto END_KS;
|
||||||
|
|
||||||
|
uint8_t ks_bytes[112];
|
||||||
|
memset (ks_bytes, 0, sizeof(ks_bytes));
|
||||||
|
parse_raw_user_string(curr, ks_bytes);
|
||||||
|
|
||||||
|
uint8_t ks_bits[896];
|
||||||
|
memset(ks_bits, 0, sizeof(ks_bits));
|
||||||
|
|
||||||
|
uint16_t unpack_len = len / 8;
|
||||||
|
if (len % 8)
|
||||||
|
unpack_len++;
|
||||||
|
unpack_byte_array_into_bit_array(ks_bytes, ks_bits, unpack_len);
|
||||||
|
|
||||||
|
for (uint16_t i = 0; i < len; i++)
|
||||||
|
{
|
||||||
|
state->static_ks_bits[0][i] = ks_bits[i];
|
||||||
|
state->static_ks_bits[1][i] = ks_bits[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf (stderr,"Hytera BP %d-bit Keystream: ", len);
|
||||||
|
for (uint16_t i = 0; i < unpack_len; i++)
|
||||||
|
fprintf (stderr, "%02X", ks_bytes[i]);
|
||||||
|
|
||||||
|
state->straight_ks = 0x68;
|
||||||
|
state->straight_mod = (int)len;
|
||||||
|
|
||||||
|
END_KS:
|
||||||
|
|
||||||
|
if (curr == NULL)
|
||||||
|
fprintf (stderr, "Hytera BP KS String Malformed! No KS Created!\n");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//connect systems 72-bit (9-byte) Extended Encryption //TODO: Move this later
|
||||||
|
void csi72_ambe2_codeword_keystream(dsd_state * state, char ambe_fr[4][24])
|
||||||
|
{
|
||||||
|
|
||||||
|
char interleaved[72];
|
||||||
|
memset (interleaved, 0, sizeof(interleaved));
|
||||||
|
|
||||||
|
//interleave the frame
|
||||||
|
const int *w, *x, *y, *z;
|
||||||
|
w = rW; x = rX; y = rY; z = rZ;
|
||||||
|
|
||||||
|
for (int8_t i = 0; i < 36; i++)
|
||||||
|
{
|
||||||
|
interleaved[(i*2)+0] = ambe_fr[*w][*x];
|
||||||
|
interleaved[(i*2)+1] = ambe_fr[*y][*z];
|
||||||
|
|
||||||
|
w++;
|
||||||
|
x++;
|
||||||
|
y++;
|
||||||
|
z++;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t ks_bytes[9]; memset(ks_bytes, 0, sizeof(ks_bytes));
|
||||||
|
uint8_t ks[72]; memset(ks, 0, sizeof(ks));
|
||||||
|
|
||||||
|
//keys are loaded in reverse byte order, stored in state->static_ks_bits[0]
|
||||||
|
for (int i = 0; i < 9; i++)
|
||||||
|
ks_bytes[i] = state->static_ks_bits[0][8-i];
|
||||||
|
|
||||||
|
//convert byte array into a bit array
|
||||||
|
unpack_byte_array_into_bit_array(ks_bytes, ks, 9);
|
||||||
|
|
||||||
|
//apply keystream to interleave
|
||||||
|
for (int8_t i = 0; i < 72; i++)
|
||||||
|
interleaved[i] ^= ks[71-i];
|
||||||
|
|
||||||
|
//deinterleave back into ambe_fr frame
|
||||||
|
w = rW; x = rX; y = rY; z = rZ;
|
||||||
|
int k = 0;
|
||||||
|
for (int8_t i = 0; i < 36; i++)
|
||||||
|
{
|
||||||
|
ambe_fr[*w][*x] = interleaved[k++];
|
||||||
|
ambe_fr[*y][*z] = interleaved[k++];
|
||||||
|
|
||||||
|
w++;
|
||||||
|
x++;
|
||||||
|
y++;
|
||||||
|
z++;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void vtx256_ambe2_interleave_inversion(char ambe_fr[4][24])
|
||||||
|
{
|
||||||
|
|
||||||
|
uint32_t silence_check = 0;
|
||||||
|
for (int i = 0; i < 20; i++)
|
||||||
|
{
|
||||||
|
silence_check <<= 1;
|
||||||
|
silence_check |= (uint8_t)ambe_fr[0][23-i];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (silence_check == 0xF8014)
|
||||||
|
goto END_INV;
|
||||||
|
|
||||||
|
char interleaved[72];
|
||||||
|
memset (interleaved, 0, sizeof(interleaved));
|
||||||
|
|
||||||
|
//interleave the frame
|
||||||
|
const int *w, *x, *y, *z;
|
||||||
|
w = rW; x = rX; y = rY; z = rZ;
|
||||||
|
|
||||||
|
for (int8_t i = 0; i < 36; i++)
|
||||||
|
{
|
||||||
|
interleaved[(i*2)+0] = ambe_fr[*w][*x];
|
||||||
|
interleaved[(i*2)+1] = ambe_fr[*y][*z];
|
||||||
|
|
||||||
|
w++;
|
||||||
|
x++;
|
||||||
|
y++;
|
||||||
|
z++;
|
||||||
|
}
|
||||||
|
|
||||||
|
//invert the bits in the 49 to 71 position
|
||||||
|
for (int8_t i = 49; i < 72; i++)
|
||||||
|
interleaved[i] ^= 1;
|
||||||
|
|
||||||
|
//deinterleave back into ambe_fr frame
|
||||||
|
w = rW; x = rX; y = rY; z = rZ;
|
||||||
|
int k = 0;
|
||||||
|
for (int8_t i = 0; i < 36; i++)
|
||||||
|
{
|
||||||
|
ambe_fr[*w][*x] = interleaved[k++];
|
||||||
|
ambe_fr[*y][*z] = interleaved[k++];
|
||||||
|
|
||||||
|
w++;
|
||||||
|
x++;
|
||||||
|
y++;
|
||||||
|
z++;
|
||||||
|
}
|
||||||
|
|
||||||
|
END_INV: ; //do nothing
|
||||||
|
|
||||||
|
}
|
||||||
1242
src/crypt-kir.c
Normal file
1242
src/crypt-kir.c
Normal file
File diff suppressed because it is too large
Load Diff
458
src/crypt-md5.c
Normal file
458
src/crypt-md5.c
Normal file
@@ -0,0 +1,458 @@
|
|||||||
|
//MD5 Code Originally Sourced From: https://github.com/Zunawe/md5-c
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Derived from the RSA Data Security, Inc. MD5 Message-Digest Algorithm
|
||||||
|
* and modified slightly to be functionally identical but condensed into control structures.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "dsd.h"
|
||||||
|
|
||||||
|
typedef struct{
|
||||||
|
uint64_t size; // Size of input in bytes
|
||||||
|
uint32_t buffer[4]; // Current accumulation of hash
|
||||||
|
uint8_t input[64]; // Input to be used in the next step
|
||||||
|
uint8_t digest[16]; // Result of algorithm
|
||||||
|
}MD5Context;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Constants defined by the MD5 algorithm
|
||||||
|
*/
|
||||||
|
#define A 0x67452301
|
||||||
|
#define B 0xefcdab89
|
||||||
|
#define C 0x98badcfe
|
||||||
|
#define D 0x10325476
|
||||||
|
|
||||||
|
static uint32_t S[] = {7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22,
|
||||||
|
5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20,
|
||||||
|
4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23,
|
||||||
|
6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21};
|
||||||
|
|
||||||
|
static uint32_t K[] = {0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee,
|
||||||
|
0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501,
|
||||||
|
0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be,
|
||||||
|
0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821,
|
||||||
|
0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa,
|
||||||
|
0xd62f105d, 0x02441453, 0xd8a1e681, 0xe7d3fbc8,
|
||||||
|
0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed,
|
||||||
|
0xa9e3e905, 0xfcefa3f8, 0x676f02d9, 0x8d2a4c8a,
|
||||||
|
0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c,
|
||||||
|
0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70,
|
||||||
|
0x289b7ec6, 0xeaa127fa, 0xd4ef3085, 0x04881d05,
|
||||||
|
0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665,
|
||||||
|
0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039,
|
||||||
|
0x655b59c3, 0x8f0ccc92, 0xffeff47d, 0x85845dd1,
|
||||||
|
0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1,
|
||||||
|
0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Padding used to make the size (in bits) of the input congruent to 448 mod 512
|
||||||
|
*/
|
||||||
|
static uint8_t PADDING[] = {0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Bit-manipulation functions defined by the MD5 algorithm
|
||||||
|
*/
|
||||||
|
#define F(X, Y, Z) ((X & Y) | (~X & Z))
|
||||||
|
#define G(X, Y, Z) ((X & Z) | (Y & ~Z))
|
||||||
|
#define H(X, Y, Z) (X ^ Y ^ Z)
|
||||||
|
#define I(X, Y, Z) (Y ^ (X | ~Z))
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Rotates a 32-bit word left by n bits
|
||||||
|
*/
|
||||||
|
uint32_t rotateLeft(uint32_t x, uint32_t n){
|
||||||
|
return (x << n) | (x >> (32 - n));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Initialize a context
|
||||||
|
*/
|
||||||
|
void md5Init(MD5Context *ctx){
|
||||||
|
ctx->size = (uint64_t)0;
|
||||||
|
|
||||||
|
ctx->buffer[0] = (uint32_t)A;
|
||||||
|
ctx->buffer[1] = (uint32_t)B;
|
||||||
|
ctx->buffer[2] = (uint32_t)C;
|
||||||
|
ctx->buffer[3] = (uint32_t)D;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Step on 512 bits of input with the main MD5 algorithm.
|
||||||
|
*/
|
||||||
|
void md5Step(uint32_t *buffer, uint32_t *input){
|
||||||
|
uint32_t AA = buffer[0];
|
||||||
|
uint32_t BB = buffer[1];
|
||||||
|
uint32_t CC = buffer[2];
|
||||||
|
uint32_t DD = buffer[3];
|
||||||
|
|
||||||
|
uint32_t E;
|
||||||
|
|
||||||
|
unsigned int j;
|
||||||
|
|
||||||
|
for(unsigned int i = 0; i < 64; ++i){
|
||||||
|
switch(i / 16){
|
||||||
|
case 0:
|
||||||
|
E = F(BB, CC, DD);
|
||||||
|
j = i;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
E = G(BB, CC, DD);
|
||||||
|
j = ((i * 5) + 1) % 16;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
E = H(BB, CC, DD);
|
||||||
|
j = ((i * 3) + 5) % 16;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
E = I(BB, CC, DD);
|
||||||
|
j = (i * 7) % 16;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t temp = DD;
|
||||||
|
DD = CC;
|
||||||
|
CC = BB;
|
||||||
|
BB = BB + rotateLeft(AA + E + K[i] + input[j], S[i]);
|
||||||
|
AA = temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
buffer[0] += AA;
|
||||||
|
buffer[1] += BB;
|
||||||
|
buffer[2] += CC;
|
||||||
|
buffer[3] += DD;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Add some amount of input to the context
|
||||||
|
*
|
||||||
|
* If the input fills out a block of 512 bits, apply the algorithm (md5Step)
|
||||||
|
* and save the result in the buffer. Also updates the overall size.
|
||||||
|
*/
|
||||||
|
void md5Update(MD5Context *ctx, uint8_t *input_buffer, size_t input_len){
|
||||||
|
uint32_t input[16];
|
||||||
|
unsigned int offset = ctx->size % 64;
|
||||||
|
ctx->size += (uint64_t)input_len;
|
||||||
|
|
||||||
|
// Copy each byte in input_buffer into the next space in our context input
|
||||||
|
for(unsigned int i = 0; i < input_len; ++i){
|
||||||
|
ctx->input[offset++] = (uint8_t)*(input_buffer + i);
|
||||||
|
|
||||||
|
// If we've filled our context input, copy it into our local array input
|
||||||
|
// then reset the offset to 0 and fill in a new buffer.
|
||||||
|
// Every time we fill out a chunk, we run it through the algorithm
|
||||||
|
// to enable some back and forth between cpu and i/o
|
||||||
|
if(offset % 64 == 0){
|
||||||
|
for(unsigned int j = 0; j < 16; ++j){
|
||||||
|
// Convert to little-endian
|
||||||
|
// The local variable `input` our 512-bit chunk separated into 32-bit words
|
||||||
|
// we can use in calculations
|
||||||
|
input[j] = (uint32_t)(ctx->input[(j * 4) + 3]) << 24 |
|
||||||
|
(uint32_t)(ctx->input[(j * 4) + 2]) << 16 |
|
||||||
|
(uint32_t)(ctx->input[(j * 4) + 1]) << 8 |
|
||||||
|
(uint32_t)(ctx->input[(j * 4)]);
|
||||||
|
}
|
||||||
|
md5Step(ctx->buffer, input);
|
||||||
|
offset = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Pad the current input to get to 448 bytes, append the size in bits to the very end,
|
||||||
|
* and save the result of the final iteration into digest.
|
||||||
|
*/
|
||||||
|
void md5Finalize(MD5Context *ctx){
|
||||||
|
uint32_t input[16];
|
||||||
|
unsigned int offset = ctx->size % 64;
|
||||||
|
unsigned int padding_length = offset < 56 ? 56 - offset : (56 + 64) - offset;
|
||||||
|
|
||||||
|
// Fill in the padding and undo the changes to size that resulted from the update
|
||||||
|
md5Update(ctx, PADDING, padding_length);
|
||||||
|
ctx->size -= (uint64_t)padding_length;
|
||||||
|
|
||||||
|
// Do a final update (internal to this function)
|
||||||
|
// Last two 32-bit words are the two halves of the size (converted from bytes to bits)
|
||||||
|
for(unsigned int j = 0; j < 14; ++j){
|
||||||
|
input[j] = (uint32_t)(ctx->input[(j * 4) + 3]) << 24 |
|
||||||
|
(uint32_t)(ctx->input[(j * 4) + 2]) << 16 |
|
||||||
|
(uint32_t)(ctx->input[(j * 4) + 1]) << 8 |
|
||||||
|
(uint32_t)(ctx->input[(j * 4)]);
|
||||||
|
}
|
||||||
|
input[14] = (uint32_t)(ctx->size * 8);
|
||||||
|
input[15] = (uint32_t)((ctx->size * 8) >> 32);
|
||||||
|
|
||||||
|
md5Step(ctx->buffer, input);
|
||||||
|
|
||||||
|
// Move the result into digest (convert from little-endian)
|
||||||
|
for(unsigned int i = 0; i < 4; ++i){
|
||||||
|
ctx->digest[(i * 4) + 0] = (uint8_t)((ctx->buffer[i] & 0x000000FF));
|
||||||
|
ctx->digest[(i * 4) + 1] = (uint8_t)((ctx->buffer[i] & 0x0000FF00) >> 8);
|
||||||
|
ctx->digest[(i * 4) + 2] = (uint8_t)((ctx->buffer[i] & 0x00FF0000) >> 16);
|
||||||
|
ctx->digest[(i * 4) + 3] = (uint8_t)((ctx->buffer[i] & 0xFF000000) >> 24);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Functions that run the algorithm on the provided input and put the digest into result.
|
||||||
|
* result should be able to store 16 bytes.
|
||||||
|
*/
|
||||||
|
void md5String(char *input, uint8_t *result){
|
||||||
|
MD5Context ctx;
|
||||||
|
md5Init(&ctx);
|
||||||
|
md5Update(&ctx, (uint8_t *)input, strlen(input));
|
||||||
|
md5Finalize(&ctx);
|
||||||
|
|
||||||
|
memcpy(result, ctx.digest, 16);
|
||||||
|
}
|
||||||
|
|
||||||
|
void md5File(FILE *file, uint8_t *result){
|
||||||
|
char *input_buffer = malloc(1024);
|
||||||
|
size_t input_size = 0;
|
||||||
|
|
||||||
|
MD5Context ctx;
|
||||||
|
md5Init(&ctx);
|
||||||
|
|
||||||
|
while((input_size = fread(input_buffer, 1, 1024, file)) > 0){
|
||||||
|
md5Update(&ctx, (uint8_t *)input_buffer, input_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
md5Finalize(&ctx);
|
||||||
|
|
||||||
|
free(input_buffer);
|
||||||
|
|
||||||
|
memcpy(result, ctx.digest, 16);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* RAS 104-bit permutation
|
||||||
|
*
|
||||||
|
* Generates a permutation of bit positions 0..103 using the 32-bit seed
|
||||||
|
* (the last four active key bytes interpreted as a big-endian uint32).
|
||||||
|
*
|
||||||
|
* Algorithm:
|
||||||
|
* - Maintain a circular list of the still-available positions.
|
||||||
|
* - Repeatedly select (seed % remaining_count) steps from the current
|
||||||
|
* position, record that index, remove it, and continue from its successor.
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* seed - 32-bit seed (e.g. 0x92604BD5)
|
||||||
|
* order - output array of 104 integers. order[i] = source bit position
|
||||||
|
* that should be placed at output bit i.
|
||||||
|
*/
|
||||||
|
void ras_permute_order(uint32_t seed, int * order)
|
||||||
|
{
|
||||||
|
int remaining[104];
|
||||||
|
int count = 104;
|
||||||
|
int pos = 0; /* current index inside the remaining[] array */
|
||||||
|
|
||||||
|
for (int i = 0; i < 104; i++)
|
||||||
|
remaining[i] = i;
|
||||||
|
|
||||||
|
for (int i = 0; i < 104; i++)
|
||||||
|
{
|
||||||
|
unsigned idx = seed % (unsigned)count;
|
||||||
|
int actual = (pos + (int)idx) % count;
|
||||||
|
|
||||||
|
order[i] = remaining[actual];
|
||||||
|
|
||||||
|
#ifdef DEBUG_RAS
|
||||||
|
//debug
|
||||||
|
// fprintf (stderr, "\n I: %d; C: %d; P: %d; IDX: %u; ACT: %d; ORD: %d; ", i, count, pos, idx, actual, order[i]);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* remove the chosen entry */
|
||||||
|
for (int j = actual; j < count - 1; j++)
|
||||||
|
remaining[j] = remaining[j + 1];
|
||||||
|
count--;
|
||||||
|
|
||||||
|
/* continue from the successor of the removed element */
|
||||||
|
if (count > 0)
|
||||||
|
pos = actual % count;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef DEBUG_RAS
|
||||||
|
//debug
|
||||||
|
// fprintf(stderr, "\n Order: ");
|
||||||
|
// for (int i = 0; i < 104; i++)
|
||||||
|
// fprintf (stderr, "%03d,", order[i]);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void apply_ras_permutation(const uint8_t * src, uint8_t * dst, const int * order)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 104; i++)
|
||||||
|
{
|
||||||
|
int src_bit = order[i];
|
||||||
|
int src_byte = src_bit / 8;
|
||||||
|
int src_off = 7 - (src_bit % 8); /* MSB of byte is lowest bit index */
|
||||||
|
|
||||||
|
int bit = (src[src_byte] >> src_off) & 1;
|
||||||
|
|
||||||
|
int dst_byte = i / 8;
|
||||||
|
int dst_off = 7 - (i % 8);
|
||||||
|
|
||||||
|
if (bit)
|
||||||
|
dst[dst_byte] |= (uint8_t)(1u << dst_off);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Full RAS workflow, return value is the the calculated MAC attachment
|
||||||
|
//input is a pointer to byte-wise payload from dburst of RAS enabled payloads
|
||||||
|
uint32_t ras_mac_calculator(dsd_state * state, uint8_t * input, int input_len, int type)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (state->ras_effective_key == 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
uint32_t mac = 0;
|
||||||
|
uint8_t ras_input[13];
|
||||||
|
memset (ras_input, 0, sizeof(ras_input));
|
||||||
|
|
||||||
|
for (int i = 0; i < input_len; i++)
|
||||||
|
ras_input[i] = input[i];
|
||||||
|
|
||||||
|
int shift = 48;
|
||||||
|
for (int i = input_len; i < 13; i++)
|
||||||
|
{
|
||||||
|
ras_input[i] = (state->ras_effective_key >> shift) & 0xFF;
|
||||||
|
shift -= 8;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef DEBUG_RAS
|
||||||
|
//debug input value
|
||||||
|
if (type != 2)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "\n RAS Input: ");
|
||||||
|
for (int i = 0; i < 13; i++)
|
||||||
|
fprintf (stderr, "%02X", ras_input[i]);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
uint8_t ras_output[16]; memset(ras_output, 0, sizeof(ras_output));
|
||||||
|
|
||||||
|
if (type != 2)
|
||||||
|
{
|
||||||
|
apply_ras_permutation(ras_input, ras_output, state->ras_permutation_order);
|
||||||
|
|
||||||
|
#ifdef DEBUG_RAS
|
||||||
|
//debug output value
|
||||||
|
fprintf (stderr, "\n RAS Output: ");
|
||||||
|
for (int i = 0; i < 13; i++)
|
||||||
|
fprintf (stderr, "%02X", ras_output[i]);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
//Run Appropriate CRC or RS calculation on Permuted Output
|
||||||
|
uint8_t output_bits[104]; memset(output_bits, 0, sizeof(output_bits));
|
||||||
|
unpack_byte_array_into_bit_array(ras_output, output_bits, 13);
|
||||||
|
|
||||||
|
if (type == 0)
|
||||||
|
mac = ComputeCrcCCITT16d(output_bits, 13*8);
|
||||||
|
else if (type == 1)
|
||||||
|
{
|
||||||
|
rs_16_13_encode(ras_output);
|
||||||
|
for (int i = 0; i < 3; i++)
|
||||||
|
{
|
||||||
|
mac <<= 8;
|
||||||
|
mac |= ras_output[i+13];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (type == 2)
|
||||||
|
{
|
||||||
|
mac = ComputeCrc5Bit(input);
|
||||||
|
mac += state->ras_effective_key & 0x1F;
|
||||||
|
mac %= 31;
|
||||||
|
}
|
||||||
|
|
||||||
|
return mac;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void ras_effective_key_creation(dsd_state * state, char * input)
|
||||||
|
{
|
||||||
|
|
||||||
|
uint8_t md5_key[30];
|
||||||
|
memset (md5_key, 0, sizeof(md5_key));
|
||||||
|
|
||||||
|
uint16_t len = strlen((const char*)input);
|
||||||
|
|
||||||
|
//sanity check on provided char len
|
||||||
|
if (len > 24)
|
||||||
|
len = 24;
|
||||||
|
|
||||||
|
//load chars as uint8_t into key array
|
||||||
|
for (int i = 0; i < len; i++)
|
||||||
|
md5_key[i] = (uint8_t)input[i];
|
||||||
|
|
||||||
|
//debug
|
||||||
|
fprintf (stderr, "RAS Key String: %s; LEN: %d; HEX: ", input, len);
|
||||||
|
for (int i = 0; i < len; i++)
|
||||||
|
fprintf (stderr, "%02X ", md5_key[i]);
|
||||||
|
fprintf (stderr, "\n");
|
||||||
|
|
||||||
|
MD5Context ctx;
|
||||||
|
md5Init(&ctx);
|
||||||
|
md5Update(&ctx, md5_key, len);
|
||||||
|
md5Finalize(&ctx);
|
||||||
|
|
||||||
|
//debug dump the digest
|
||||||
|
fprintf (stderr, "MD5: ");
|
||||||
|
for (int i = 0; i < 16; i++)
|
||||||
|
fprintf (stderr, "%02X ", ctx.digest[i]);
|
||||||
|
fprintf (stderr, "\n");
|
||||||
|
|
||||||
|
//collect 7 bytes of the MD5 Hash to create the flat key value
|
||||||
|
unsigned long long int flat_key = 0;
|
||||||
|
for (int i = 0; i < 7; i++)
|
||||||
|
{
|
||||||
|
flat_key <<= 8;
|
||||||
|
flat_key |= ctx.digest[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
//On real world testing, it was discovered that by selecting a password (VluByDZhkPenguinkeeper) which has
|
||||||
|
//an MD5 partial hash of FFFFFFFFFEDFFF, the value actually placed into the radio was FFFFFFFFFEE001
|
||||||
|
//this indicates the entire value will roll-over, and not just a byte rollvoer (mod)
|
||||||
|
|
||||||
|
//The known rule is that the last 5 bits of the flat key value (prior to reverse)
|
||||||
|
//is that it cannot equal 0x1F (all 1 bits), if so, a correction of +2 is
|
||||||
|
//performaed onto a flat value, which increments the entire value appropriately
|
||||||
|
|
||||||
|
//Below patent also suggest all bytes cannot equal zero
|
||||||
|
//and if so, the next portion of MD5 may be used,
|
||||||
|
//or some other method may be utilized to prevent fringe cases
|
||||||
|
//https://patents.google.com/patent/US20130288643A1
|
||||||
|
|
||||||
|
if ((flat_key & 0x1F) == 0x1F)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "Flat Correction: %014llX -> %014llX;\n", flat_key, flat_key+2);
|
||||||
|
flat_key += 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
//byte-reverse the flat_key into the effective_key
|
||||||
|
unsigned long long int effective_key = 0;
|
||||||
|
for (int i = 0; i < 7; i++)
|
||||||
|
{
|
||||||
|
effective_key <<= 8;
|
||||||
|
effective_key |= (flat_key >> (i*8)) & 0xFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t ras_seed = effective_key & 0xFFFFFFFF;
|
||||||
|
|
||||||
|
ras_permute_order(ras_seed, state->ras_permutation_order);
|
||||||
|
|
||||||
|
//debug
|
||||||
|
fprintf (stderr, "RAS Effective Key Value: %014llX;", effective_key);
|
||||||
|
|
||||||
|
state->ras_effective_key = effective_key;
|
||||||
|
|
||||||
|
fprintf (stderr, "\n");
|
||||||
|
|
||||||
|
}
|
||||||
392
src/crypt-pc4.c
Normal file
392
src/crypt-pc4.c
Normal file
@@ -0,0 +1,392 @@
|
|||||||
|
#include "pc4.h"
|
||||||
|
|
||||||
|
/* Global PC4 context instance */
|
||||||
|
PC4Context ctx;
|
||||||
|
|
||||||
|
/* ---------------------------------
|
||||||
|
Internal utility functions
|
||||||
|
----------------------------------- */
|
||||||
|
|
||||||
|
/* Rotate right */
|
||||||
|
static uint32_t ror(uint32_t x, int shift, int bits) {
|
||||||
|
uint32_t m0 = (1u << (bits - shift)) - 1u;
|
||||||
|
uint32_t m1 = (1u << shift) - 1u;
|
||||||
|
return ((x >> shift) & m0) | ((x & m1) << (bits - shift));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Rotate left */
|
||||||
|
static uint32_t rol(uint32_t x, int shift, int bits) {
|
||||||
|
uint32_t m0 = (1u << (bits - shift)) - 1u;
|
||||||
|
uint32_t m1 = (1u << shift) - 1u;
|
||||||
|
return ((x & m0) << shift) | ((x >> (bits - shift)) & m1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* SplitMix64 random number generator */
|
||||||
|
static uint64_t next_rng(PC4Context *ctx) {
|
||||||
|
uint64_t z = (ctx->x += 0x9e3779b97f4a7c15ULL);
|
||||||
|
z = (z ^ (z >> 30)) * 0xbf58476d1ce4e5b9ULL;
|
||||||
|
z = (z ^ (z >> 27)) * 0x94d049bb133111ebULL;
|
||||||
|
return z ^ (z >> 31);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ARC4 initialization */
|
||||||
|
static void arc4_init(PC4Context *ctx, unsigned char key[]) {
|
||||||
|
int tmp;
|
||||||
|
for (ctx->i_arc4 = 0; ctx->i_arc4 < 256; ctx->i_arc4++)
|
||||||
|
ctx->array_arc4[ctx->i_arc4] = (unsigned char)ctx->i_arc4;
|
||||||
|
|
||||||
|
ctx->j_arc4 = 0;
|
||||||
|
for (ctx->i_arc4 = 0; ctx->i_arc4 < 256; ctx->i_arc4++) {
|
||||||
|
ctx->j_arc4 = (ctx->j_arc4 + ctx->array_arc4[ctx->i_arc4] + key[ctx->i_arc4 % 256]) % 256;
|
||||||
|
tmp = ctx->array_arc4[ctx->i_arc4];
|
||||||
|
ctx->array_arc4[ctx->i_arc4] = ctx->array_arc4[ctx->j_arc4];
|
||||||
|
ctx->array_arc4[ctx->j_arc4] = tmp;
|
||||||
|
}
|
||||||
|
ctx->i_arc4 = 0;
|
||||||
|
ctx->j_arc4 = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ARC4 output combined with SplitMix64 stream */
|
||||||
|
static unsigned char arc4_output(PC4Context *ctx) {
|
||||||
|
uint8_t rndbyte, decal;
|
||||||
|
int tmp, t;
|
||||||
|
|
||||||
|
ctx->i_arc4 = (ctx->i_arc4 + 1) % 256;
|
||||||
|
ctx->j_arc4 = (ctx->j_arc4 + ctx->array_arc4[ctx->i_arc4]) % 256;
|
||||||
|
tmp = ctx->array_arc4[ctx->i_arc4];
|
||||||
|
ctx->array_arc4[ctx->i_arc4] = ctx->array_arc4[ctx->j_arc4];
|
||||||
|
ctx->array_arc4[ctx->j_arc4] = tmp;
|
||||||
|
t = (ctx->array_arc4[ctx->i_arc4] + ctx->array_arc4[ctx->j_arc4]) % 256;
|
||||||
|
|
||||||
|
if (ctx->xyz == 0) ctx->bb = next_rng(ctx);
|
||||||
|
decal = (uint8_t)(56 - (8 * ctx->xyz));
|
||||||
|
rndbyte = (uint8_t)((ctx->bb >> decal) & 0xffu);
|
||||||
|
ctx->xyz++;
|
||||||
|
if (ctx->xyz == 8) ctx->xyz = 0;
|
||||||
|
|
||||||
|
if (ctx->count == 0) {
|
||||||
|
rndbyte = (uint8_t)(rndbyte ^ ctx->array_arc4[t]);
|
||||||
|
ctx->count = 1;
|
||||||
|
} else {
|
||||||
|
rndbyte = (uint8_t)(rndbyte + ctx->array_arc4[t]);
|
||||||
|
ctx->count = 0;
|
||||||
|
}
|
||||||
|
return rndbyte;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Initialize MD2-II state */
|
||||||
|
static void md2_init(PC4Context *ctx) {
|
||||||
|
ctx->x1 = 0;
|
||||||
|
ctx->x2 = 0;
|
||||||
|
for (ctx->i = 0; ctx->i < n1; ctx->i++) ctx->h2[ctx->i] = 0;
|
||||||
|
for (ctx->i = 0; ctx->i < n1; ctx->i++) ctx->h1[ctx->i] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* MD2-II hashing */
|
||||||
|
static void md2_hashing(PC4Context *ctx, unsigned char t1[], size_t b6) {
|
||||||
|
static const unsigned char s4[256] = {
|
||||||
|
13,199,11,67,237,193,164,77,115,184,141,222,73,38,147,36,150,87,21,104,12,61,156,101,111,145,
|
||||||
|
119,22,207,35,198,37,171,167,80,30,219,28,213,121,86,29,214,242,6,4,89,162,110,175,19,157,3,
|
||||||
|
88,234,94,144,118,159,239,100,17,182,173,238,68,16,79,132,54,163,52,9,58,57,55,229,192,170,226,
|
||||||
|
56,231,187,158,70,224,233,245,26,47,32,44,247,8,251,20,197,185,109,153,204,218,93,178,212,137,84,
|
||||||
|
174,24,120,130,149,72,180,181,208,255,189,152,18,143,176,60,249,27,227,128,139,243,253,59,123,172,
|
||||||
|
108,211,96,138,10,215,42,225,40,81,65,90,25,98,126,154,64,124,116,122,5,1,168,83,190,131,191,244,
|
||||||
|
240,235,177,155,228,125,66,43,201,248,220,129,188,230,62,75,71,78,34,31,216,254,136,91,114,106,46,
|
||||||
|
217,196,92,151,209,133,51,236,33,252,127,179,69,7,183,105,146,97,39,15,205,112,200,166,223,45,48,
|
||||||
|
246,186,41,148,140,107,76,85,95,194,142,50,49,134,23,135,169,221,210,203,63,165,82,161,202,53,14,
|
||||||
|
206,232,103,102,195,117,250,99,0,74,160,241,2,113};
|
||||||
|
|
||||||
|
int b1, b2, b3, b4, b5;
|
||||||
|
b4 = 0;
|
||||||
|
while (b6) {
|
||||||
|
for (; b6 && ctx->x2 < n1; b6--, ctx->x2++) {
|
||||||
|
b5 = t1[b4++];
|
||||||
|
ctx->h1[ctx->x2 + n1] = (unsigned char)b5;
|
||||||
|
ctx->h1[ctx->x2 + (n1 * 2)] = (unsigned char)(b5 ^ ctx->h1[ctx->x2]);
|
||||||
|
ctx->x1 = ctx->h2[ctx->x2] ^= s4[b5 ^ ctx->x1];
|
||||||
|
}
|
||||||
|
if (ctx->x2 == n1) {
|
||||||
|
b2 = 0;
|
||||||
|
ctx->x2 = 0;
|
||||||
|
for (b3 = 0; b3 < (n1 + 2); b3++) {
|
||||||
|
for (b1 = 0; b1 < (n1 * 3); b1++)
|
||||||
|
b2 = ctx->h1[b1] ^= s4[b2];
|
||||||
|
b2 = (b2 + b3) % 256;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Finalize MD2-II */
|
||||||
|
static void md2_end(PC4Context *ctx, unsigned char h4[n1]) {
|
||||||
|
unsigned char h3[n1];
|
||||||
|
int i, n4 = n1 - ctx->x2;
|
||||||
|
for (i = 0; i < n4; i++) h3[i] = (unsigned char)n4;
|
||||||
|
md2_hashing(ctx, h3, (size_t)n4);
|
||||||
|
md2_hashing(ctx, ctx->h2, sizeof(ctx->h2));
|
||||||
|
for (i = 0; i < n1; i++) h4[i] = ctx->h1[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Generate a random index */
|
||||||
|
static int mixy(PC4Context *ctx, int nn2) {
|
||||||
|
return arc4_output(ctx) % nn2;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Fisher-Yates shuffle */
|
||||||
|
static void mixer(PC4Context *ctx, uint8_t *mixu, int nn) {
|
||||||
|
int ii, jj, tmmp;
|
||||||
|
for (ii = nn - 1; ii > 0; ii--) {
|
||||||
|
jj = mixy(ctx, ii + 1);
|
||||||
|
tmmp = mixu[jj];
|
||||||
|
mixu[jj] = mixu[ii];
|
||||||
|
mixu[ii] = (uint8_t)tmmp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Key schedule and S-box generation */
|
||||||
|
void create_keys(PC4Context *ctx, unsigned char key1[], size_t size1) {
|
||||||
|
int i, w, k;
|
||||||
|
unsigned char h4[n1];
|
||||||
|
|
||||||
|
md2_init(ctx);
|
||||||
|
md2_hashing(ctx, key1, size1);
|
||||||
|
md2_end(ctx, h4);
|
||||||
|
|
||||||
|
for (i = 0; i < 16; i++) ctx->keys[i] = h4[i];
|
||||||
|
arc4_init(ctx, h4);
|
||||||
|
|
||||||
|
ctx->x = 0;
|
||||||
|
for (i = 0; i < 8; i++) ctx->x = (ctx->x << 8) + (uint64_t)(h4[256 + i] & 0xffu);
|
||||||
|
|
||||||
|
ctx->xyz = 0;
|
||||||
|
ctx->count = 0;
|
||||||
|
|
||||||
|
for (i = 0; i < 20000; i++) (void)arc4_output(ctx);
|
||||||
|
|
||||||
|
uint8_t numbers[256];
|
||||||
|
|
||||||
|
for (w = 0; w < 16; w++) {
|
||||||
|
k = arc4_output(ctx) + 256;
|
||||||
|
for (i = 0; i < k; i++) (void)arc4_output(ctx);
|
||||||
|
for (i = 0; i < 256; i++) numbers[i] = (uint8_t)i;
|
||||||
|
mixer(ctx, numbers, 256);
|
||||||
|
for (i = 0; i < 256; i++) ctx->perm[w][i] = numbers[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
k = arc4_output(ctx) + 256;
|
||||||
|
for (i = 0; i < k; i++) (void)arc4_output(ctx);
|
||||||
|
for (i = 0; i < 256; i++) numbers[i] = (uint8_t)i;
|
||||||
|
mixer(ctx, numbers, 256);
|
||||||
|
for (i = 0; i < 256; i++) ctx->new1[i] = numbers[i];
|
||||||
|
|
||||||
|
k = arc4_output(ctx) + 256;
|
||||||
|
for (i = 0; i < k; i++) (void)arc4_output(ctx);
|
||||||
|
for (i = 0; i < 49; i++) numbers[i] = (uint8_t)i;
|
||||||
|
mixer(ctx, numbers, 49);
|
||||||
|
for (i = 0; i < 49; i++) ctx->array[i] = numbers[i];
|
||||||
|
|
||||||
|
k = arc4_output(ctx) + 256;
|
||||||
|
for (i = 0; i < k; i++) (void)arc4_output(ctx);
|
||||||
|
for (i = 0; i < nbround; i++) ctx->decal[i] = (uint8_t)((arc4_output(ctx) % 23) + 1);
|
||||||
|
|
||||||
|
k = arc4_output(ctx) + 256;
|
||||||
|
for (i = 0; i < k; i++) (void)arc4_output(ctx);
|
||||||
|
for (w = 0; w < 3; w++)
|
||||||
|
for (i = 0; i < nbround; i++)
|
||||||
|
ctx->rngxor[i][w] = arc4_output(ctx);
|
||||||
|
|
||||||
|
k = arc4_output(ctx) + 256;
|
||||||
|
for (i = 0; i < k; i++) (void)arc4_output(ctx);
|
||||||
|
for (i = 0; i < 49; i++) numbers[i] = (uint8_t)i;
|
||||||
|
mixer(ctx, numbers, 49);
|
||||||
|
for (i = 0; i < 49; i++) ctx->array2[i] = numbers[i];
|
||||||
|
|
||||||
|
k = arc4_output(ctx) + 256;
|
||||||
|
for (i = 0; i < k; i++) (void)arc4_output(ctx);
|
||||||
|
for (i = 0; i < 256; i++) numbers[i] = (uint8_t)i;
|
||||||
|
mixer(ctx, numbers, 256);
|
||||||
|
for (i = 0; i < 256; i++) {
|
||||||
|
ctx->tab[i] = numbers[i];
|
||||||
|
ctx->inv[ctx->tab[i]] = (unsigned char)i;
|
||||||
|
}
|
||||||
|
|
||||||
|
k = arc4_output(ctx) + 256;
|
||||||
|
for (i = 0; i < k; i++) (void)arc4_output(ctx);
|
||||||
|
for (w = 0; w < 3; w++) {
|
||||||
|
k = arc4_output(ctx) + 256;
|
||||||
|
for (i = 0; i < k; i++) (void)arc4_output(ctx);
|
||||||
|
for (i = 0; i < 3; i++) numbers[i] = (uint8_t)i;
|
||||||
|
mixer(ctx, numbers, 3);
|
||||||
|
for (i = 0; i < 3; i++) ctx->permut[w][i] = numbers[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
k = arc4_output(ctx) + 256;
|
||||||
|
for (i = 0; i < k; i++) (void)arc4_output(ctx);
|
||||||
|
for (w = 0; w < 3; w++)
|
||||||
|
for (i = 0; i < nbround; i++)
|
||||||
|
ctx->rngxor2[i][w] = arc4_output(ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Compute round transformation */
|
||||||
|
static void compute(PC4Context *ctx, uint8_t *tab1, uint8_t round) {
|
||||||
|
ctx->tot[0] = (uint8_t)((ctx->perm[round][tab1[ctx->permut[0][0]]] +
|
||||||
|
ctx->perm[round][tab1[ctx->permut[0][1]]]) ^
|
||||||
|
ctx->perm[round][tab1[ctx->permut[0][2]]]);
|
||||||
|
ctx->tot[0] = (uint8_t)(ctx->tot[0] + ctx->new1[ctx->tot[0]]);
|
||||||
|
ctx->tot[1] = (uint8_t)((ctx->perm[round][tab1[ctx->permut[1][0]]] +
|
||||||
|
ctx->perm[round][tab1[ctx->permut[1][1]]]) ^
|
||||||
|
ctx->perm[round][tab1[ctx->permut[1][2]]]);
|
||||||
|
ctx->tot[1] = (uint8_t)(ctx->tot[1] + ctx->new1[ctx->tot[1]]);
|
||||||
|
ctx->tot[2] = (uint8_t)((ctx->perm[round][tab1[ctx->permut[2][0]]] +
|
||||||
|
ctx->perm[round][tab1[ctx->permut[2][1]]]) ^
|
||||||
|
ctx->perm[round][tab1[ctx->permut[2][2]]]);
|
||||||
|
ctx->tot[2] = (uint8_t)(ctx->tot[2] + ctx->new1[ctx->tot[2]]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Convert bits to bytes */
|
||||||
|
void binhex(PC4Context *ctx, short *z, int length) {
|
||||||
|
short *b = (short *)z;
|
||||||
|
uint8_t i, j;
|
||||||
|
for (i = 0; i < length; i = j) {
|
||||||
|
uint8_t a = 0;
|
||||||
|
for (j = i; j < i + 8; ++j) {
|
||||||
|
a |= (uint8_t)(b[((short)(7 - (j % 8)) + j) - (j % 8)] << (j - i));
|
||||||
|
}
|
||||||
|
ctx->convert[ctx->ptconvert] = a;
|
||||||
|
ctx->ptconvert++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Convert byte to bits */
|
||||||
|
void hexbin(PC4Context *ctx, short *q, uint8_t w, uint8_t hex) { // warning: unused parameter ‘ctx’ [-Wunused-parameter]
|
||||||
|
short *bits = (short *)q;
|
||||||
|
for (uint8_t i = 0; i < 8; ++i) {
|
||||||
|
bits[(short)(7 + w) - i] = (short)((hex >> i) & 1u);
|
||||||
|
}
|
||||||
|
|
||||||
|
UNUSEDPC4(ctx); //fix above warning
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Encrypt one block */
|
||||||
|
void pc4encrypt(PC4Context *ctx) {
|
||||||
|
int i;
|
||||||
|
ctx->totb = 0;
|
||||||
|
|
||||||
|
for (i = 0; i < 3; i++) {
|
||||||
|
ctx->l[0][i] = ctx->convert[i];
|
||||||
|
ctx->r[0][i] = ctx->convert[i + 3];
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 1; i <= ctx->rounds; i++) {
|
||||||
|
ctx->totb ^= ctx->r[(i - 1) % 2][0];
|
||||||
|
ctx->totb ^= ctx->r[(i - 1) % 2][1];
|
||||||
|
ctx->totb ^= ctx->r[(i - 1) % 2][2];
|
||||||
|
|
||||||
|
ctx->r[(i - 1) % 2][0] += (uint8_t)(~ctx->rngxor2[ctx->rounds - i][0]);
|
||||||
|
ctx->r[(i - 1) % 2][1] ^= (uint8_t)(~ctx->rngxor2[ctx->rounds - i][1]);
|
||||||
|
ctx->r[(i - 1) % 2][2] += (uint8_t)(~ctx->rngxor2[ctx->rounds - i][2]);
|
||||||
|
|
||||||
|
ctx->result = 0;
|
||||||
|
ctx->result += ((uint32_t)ctx->r[(i - 1) % 2][0] << 16);
|
||||||
|
ctx->result += ((uint32_t)ctx->r[(i - 1) % 2][1] << 8);
|
||||||
|
ctx->result += ctx->r[(i - 1) % 2][2];
|
||||||
|
|
||||||
|
ctx->result = rol(ctx->result, ctx->decal[i - 1], 24);
|
||||||
|
|
||||||
|
ctx->r[(i - 1) % 2][0] = (uint8_t)(ctx->result >> 16);
|
||||||
|
ctx->r[(i - 1) % 2][1] = (uint8_t)((ctx->result >> 8) & 0xffu);
|
||||||
|
ctx->r[(i - 1) % 2][2] = (uint8_t)(ctx->result & 0xffu);
|
||||||
|
|
||||||
|
ctx->r[(i - 1) % 2][0] = ctx->tab[ctx->r[(i - 1) % 2][0]];
|
||||||
|
ctx->r[(i - 1) % 2][0] ^= ctx->rngxor[i - 1][0];
|
||||||
|
|
||||||
|
ctx->r[(i - 1) % 2][1] = ctx->inv[ctx->r[(i - 1) % 2][1]];
|
||||||
|
ctx->r[(i - 1) % 2][1] -= ctx->rngxor[i - 1][1];
|
||||||
|
|
||||||
|
ctx->r[(i - 1) % 2][2] = ctx->tab[ctx->r[(i - 1) % 2][2]];
|
||||||
|
ctx->r[(i - 1) % 2][2] ^= ctx->rngxor[i - 1][2];
|
||||||
|
|
||||||
|
compute(ctx, ctx->r[(i - 1) % 2], (uint8_t)((i - 1) % 16));
|
||||||
|
|
||||||
|
ctx->l[i % 2][0] = ctx->r[(i - 1) % 2][0];
|
||||||
|
ctx->r[i % 2][0] = ctx->l[(i - 1) % 2][0] - ctx->tot[0];
|
||||||
|
|
||||||
|
ctx->l[i % 2][1] = ctx->r[(i - 1) % 2][1];
|
||||||
|
ctx->r[i % 2][1] = ctx->l[(i - 1) % 2][1] ^ ctx->tot[1];
|
||||||
|
|
||||||
|
ctx->l[i % 2][2] = ctx->r[(i - 1) % 2][2];
|
||||||
|
ctx->r[i % 2][2] = ctx->l[(i - 1) % 2][2] - ctx->tot[2];
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < 3; i++) {
|
||||||
|
ctx->convert[i + 3] = ctx->l[(ctx->rounds - 1) % 2][i];
|
||||||
|
ctx->convert[i] = ctx->r[(ctx->rounds - 1) % 2][i];
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx->totb %= 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Decrypt one block */
|
||||||
|
void pc4decrypt(PC4Context *ctx) {
|
||||||
|
int i;
|
||||||
|
ctx->totb = 0;
|
||||||
|
|
||||||
|
for (i = 0; i < 3; i++) {
|
||||||
|
ctx->l[0][i] = ctx->convert[i];
|
||||||
|
ctx->r[0][i] = ctx->convert[i + 3];
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx->y = (uint8_t)((ctx->rounds - 1) % 16);
|
||||||
|
if (ctx->y == 0) ctx->y = 16;
|
||||||
|
|
||||||
|
for (i = 1; i <= ctx->rounds; i++) {
|
||||||
|
ctx->y--;
|
||||||
|
compute(ctx, ctx->r[(i - 1) % 2], ctx->y);
|
||||||
|
if (ctx->y == 0) ctx->y = 16;
|
||||||
|
|
||||||
|
ctx->result = 0;
|
||||||
|
|
||||||
|
ctx->l[(i - 1) % 2][0] ^= ctx->rngxor[ctx->rounds - i][0];
|
||||||
|
ctx->l[(i - 1) % 2][0] = ctx->inv[ctx->l[(i - 1) % 2][0]];
|
||||||
|
|
||||||
|
ctx->l[(i - 1) % 2][1] += ctx->rngxor[ctx->rounds - i][1];
|
||||||
|
ctx->l[(i - 1) % 2][1] = ctx->tab[ctx->l[(i - 1) % 2][1]];
|
||||||
|
|
||||||
|
ctx->l[(i - 1) % 2][2] ^= ctx->rngxor[ctx->rounds - i][2];
|
||||||
|
ctx->l[(i - 1) % 2][2] = ctx->inv[ctx->l[(i - 1) % 2][2]];
|
||||||
|
|
||||||
|
ctx->result += ((uint32_t)ctx->l[(i - 1) % 2][0] << 16);
|
||||||
|
ctx->result += ((uint32_t)ctx->l[(i - 1) % 2][1] << 8);
|
||||||
|
ctx->result += ctx->l[(i - 1) % 2][2];
|
||||||
|
|
||||||
|
ctx->result = ror(ctx->result, ctx->decal[ctx->rounds - i], 24);
|
||||||
|
|
||||||
|
ctx->l[(i - 1) % 2][0] = (uint8_t)(ctx->result >> 16);
|
||||||
|
ctx->l[(i - 1) % 2][1] = (uint8_t)((ctx->result >> 8) & 0xffu);
|
||||||
|
ctx->l[(i - 1) % 2][2] = (uint8_t)(ctx->result & 0xffu);
|
||||||
|
|
||||||
|
ctx->l[(i - 1) % 2][0] -= (uint8_t)(~ctx->rngxor2[i - 1][0]);
|
||||||
|
ctx->l[(i - 1) % 2][1] ^= (uint8_t)(~ctx->rngxor2[i - 1][1]);
|
||||||
|
ctx->l[(i - 1) % 2][2] -= (uint8_t)(~ctx->rngxor2[i - 1][2]);
|
||||||
|
|
||||||
|
ctx->totb ^= ctx->l[(i - 1) % 2][0];
|
||||||
|
ctx->totb ^= ctx->l[(i - 1) % 2][1];
|
||||||
|
ctx->totb ^= ctx->l[(i - 1) % 2][2];
|
||||||
|
|
||||||
|
ctx->l[i % 2][0] = ctx->r[(i - 1) % 2][0];
|
||||||
|
ctx->r[i % 2][0] = ctx->l[(i - 1) % 2][0] + ctx->tot[0];
|
||||||
|
|
||||||
|
ctx->l[i % 2][1] = ctx->r[(i - 1) % 2][1];
|
||||||
|
ctx->r[i % 2][1] = ctx->l[(i - 1) % 2][1] ^ ctx->tot[1];
|
||||||
|
|
||||||
|
ctx->l[i % 2][2] = ctx->r[(i - 1) % 2][2];
|
||||||
|
ctx->r[i % 2][2] = ctx->l[(i - 1) % 2][2] + ctx->tot[2];
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < 3; i++) {
|
||||||
|
ctx->convert[i + 3] = ctx->l[(ctx->rounds - 1) % 2][i];
|
||||||
|
ctx->convert[i] = ctx->r[(ctx->rounds - 1) % 2][i];
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx->totb %= 2;
|
||||||
|
}
|
||||||
468
src/crypt-pc5.c
Normal file
468
src/crypt-pc5.c
Normal file
@@ -0,0 +1,468 @@
|
|||||||
|
#include "pc5.h"
|
||||||
|
#include "dsd.h"
|
||||||
|
|
||||||
|
#include <ctype.h>
|
||||||
|
|
||||||
|
/* Global PC5 context instance */
|
||||||
|
PC5Context ctxpc5;
|
||||||
|
|
||||||
|
/* ---------------------------------
|
||||||
|
Internal utility functions
|
||||||
|
----------------------------------- */
|
||||||
|
|
||||||
|
/* Rotate right */
|
||||||
|
static uint32_t ror(uint32_t x, int shift, int bits) {
|
||||||
|
uint32_t m0 = (1u << (bits - shift)) - 1u;
|
||||||
|
uint32_t m1 = (1u << shift) - 1u;
|
||||||
|
return ((x >> shift) & m0) | ((x & m1) << (bits - shift));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Rotate left */
|
||||||
|
static uint32_t rol(uint32_t x, int shift, int bits) {
|
||||||
|
uint32_t m0 = (1u << (bits - shift)) - 1u;
|
||||||
|
uint32_t m1 = (1u << shift) - 1u;
|
||||||
|
return ((x & m0) << shift) | ((x >> (bits - shift)) & m1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* SplitMix64 random number generator */
|
||||||
|
static uint64_t next_rng(PC5Context *ctxpc5) {
|
||||||
|
uint64_t z = (ctxpc5->x += 0x9e3779b97f4a7c15ULL);
|
||||||
|
z = (z ^ (z >> 30)) * 0xbf58476d1ce4e5b9ULL;
|
||||||
|
z = (z ^ (z >> 27)) * 0x94d049bb133111ebULL;
|
||||||
|
return z ^ (z >> 31);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ARC4 initialization */
|
||||||
|
static void arc4_init(PC5Context *ctxpc5, unsigned char key[]) {
|
||||||
|
int tmp;
|
||||||
|
for (ctxpc5->i_arc4 = 0; ctxpc5->i_arc4 < 256; ctxpc5->i_arc4++)
|
||||||
|
ctxpc5->array_arc4[ctxpc5->i_arc4] = (unsigned char)ctxpc5->i_arc4;
|
||||||
|
|
||||||
|
ctxpc5->j_arc4 = 0;
|
||||||
|
for (ctxpc5->i_arc4 = 0; ctxpc5->i_arc4 < 256; ctxpc5->i_arc4++) {
|
||||||
|
ctxpc5->j_arc4 = (ctxpc5->j_arc4 + ctxpc5->array_arc4[ctxpc5->i_arc4] + key[ctxpc5->i_arc4 % 256]) % 256;
|
||||||
|
tmp = ctxpc5->array_arc4[ctxpc5->i_arc4];
|
||||||
|
ctxpc5->array_arc4[ctxpc5->i_arc4] = ctxpc5->array_arc4[ctxpc5->j_arc4];
|
||||||
|
ctxpc5->array_arc4[ctxpc5->j_arc4] = tmp;
|
||||||
|
}
|
||||||
|
ctxpc5->i_arc4 = 0;
|
||||||
|
ctxpc5->j_arc4 = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ARC4 output combined with SplitMix64 stream */
|
||||||
|
static unsigned char arc4_output(PC5Context *ctxpc5) {
|
||||||
|
uint8_t rndbyte, decal;
|
||||||
|
int tmp, t;
|
||||||
|
|
||||||
|
ctxpc5->i_arc4 = (ctxpc5->i_arc4 + 1) % 256;
|
||||||
|
ctxpc5->j_arc4 = (ctxpc5->j_arc4 + ctxpc5->array_arc4[ctxpc5->i_arc4]) % 256;
|
||||||
|
tmp = ctxpc5->array_arc4[ctxpc5->i_arc4];
|
||||||
|
ctxpc5->array_arc4[ctxpc5->i_arc4] = ctxpc5->array_arc4[ctxpc5->j_arc4];
|
||||||
|
ctxpc5->array_arc4[ctxpc5->j_arc4] = tmp;
|
||||||
|
t = (ctxpc5->array_arc4[ctxpc5->i_arc4] + ctxpc5->array_arc4[ctxpc5->j_arc4]) % 256;
|
||||||
|
|
||||||
|
if (ctxpc5->xyz == 0) ctxpc5->bb = next_rng(ctxpc5);
|
||||||
|
decal = (uint8_t)(56 - (8 * ctxpc5->xyz));
|
||||||
|
rndbyte = (uint8_t)((ctxpc5->bb >> decal) & 0xffu);
|
||||||
|
ctxpc5->xyz++;
|
||||||
|
if (ctxpc5->xyz == 8) ctxpc5->xyz = 0;
|
||||||
|
|
||||||
|
if (ctxpc5->count == 0) {
|
||||||
|
rndbyte = (uint8_t)(rndbyte ^ ctxpc5->array_arc4[t]);
|
||||||
|
ctxpc5->count = 1;
|
||||||
|
} else {
|
||||||
|
rndbyte = (uint8_t)(rndbyte + ctxpc5->array_arc4[t]);
|
||||||
|
ctxpc5->count = 0;
|
||||||
|
}
|
||||||
|
return rndbyte;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Initialize MD2-II state */
|
||||||
|
static void md2_init(PC5Context *ctxpc5) {
|
||||||
|
ctxpc5->x1 = 0;
|
||||||
|
ctxpc5->x2 = 0;
|
||||||
|
for (ctxpc5->i = 0; ctxpc5->i < n1; ctxpc5->i++) ctxpc5->h2[ctxpc5->i] = 0;
|
||||||
|
for (ctxpc5->i = 0; ctxpc5->i < n1; ctxpc5->i++) ctxpc5->h1[ctxpc5->i] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* MD2-II hashing */
|
||||||
|
static void md2_hashing(PC5Context *ctxpc5, unsigned char t1[], size_t b6) {
|
||||||
|
static const unsigned char s4[256] = {
|
||||||
|
13,199,11,67,237,193,164,77,115,184,141,222,73,38,147,36,150,87,21,104,12,61,156,101,111,145,
|
||||||
|
119,22,207,35,198,37,171,167,80,30,219,28,213,121,86,29,214,242,6,4,89,162,110,175,19,157,3,
|
||||||
|
88,234,94,144,118,159,239,100,17,182,173,238,68,16,79,132,54,163,52,9,58,57,55,229,192,170,226,
|
||||||
|
56,231,187,158,70,224,233,245,26,47,32,44,247,8,251,20,197,185,109,153,204,218,93,178,212,137,84,
|
||||||
|
174,24,120,130,149,72,180,181,208,255,189,152,18,143,176,60,249,27,227,128,139,243,253,59,123,172,
|
||||||
|
108,211,96,138,10,215,42,225,40,81,65,90,25,98,126,154,64,124,116,122,5,1,168,83,190,131,191,244,
|
||||||
|
240,235,177,155,228,125,66,43,201,248,220,129,188,230,62,75,71,78,34,31,216,254,136,91,114,106,46,
|
||||||
|
217,196,92,151,209,133,51,236,33,252,127,179,69,7,183,105,146,97,39,15,205,112,200,166,223,45,48,
|
||||||
|
246,186,41,148,140,107,76,85,95,194,142,50,49,134,23,135,169,221,210,203,63,165,82,161,202,53,14,
|
||||||
|
206,232,103,102,195,117,250,99,0,74,160,241,2,113};
|
||||||
|
|
||||||
|
int b1, b2, b3, b4, b5;
|
||||||
|
b4 = 0;
|
||||||
|
while (b6) {
|
||||||
|
for (; b6 && ctxpc5->x2 < n1; b6--, ctxpc5->x2++) {
|
||||||
|
b5 = t1[b4++];
|
||||||
|
ctxpc5->h1[ctxpc5->x2 + n1] = (unsigned char)b5;
|
||||||
|
ctxpc5->h1[ctxpc5->x2 + (n1 * 2)] = (unsigned char)(b5 ^ ctxpc5->h1[ctxpc5->x2]);
|
||||||
|
ctxpc5->x1 = ctxpc5->h2[ctxpc5->x2] ^= s4[b5 ^ ctxpc5->x1];
|
||||||
|
}
|
||||||
|
if (ctxpc5->x2 == n1) {
|
||||||
|
b2 = 0;
|
||||||
|
ctxpc5->x2 = 0;
|
||||||
|
for (b3 = 0; b3 < (n1 + 2); b3++) {
|
||||||
|
for (b1 = 0; b1 < (n1 * 3); b1++)
|
||||||
|
b2 = ctxpc5->h1[b1] ^= s4[b2];
|
||||||
|
b2 = (b2 + b3) % 256;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Finalize MD2-II */
|
||||||
|
static void md2_end(PC5Context *ctxpc5, unsigned char h4[n1]) {
|
||||||
|
unsigned char h3[n1];
|
||||||
|
int i, n4 = n1 - ctxpc5->x2;
|
||||||
|
for (i = 0; i < n4; i++) h3[i] = (unsigned char)n4;
|
||||||
|
md2_hashing(ctxpc5, h3, (size_t)n4);
|
||||||
|
md2_hashing(ctxpc5, ctxpc5->h2, sizeof(ctxpc5->h2));
|
||||||
|
for (i = 0; i < n1; i++) h4[i] = ctxpc5->h1[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Generate a random index */
|
||||||
|
static int mixy(PC5Context *ctxpc5, int nn2) {
|
||||||
|
return arc4_output(ctxpc5) % nn2;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Fisher-Yates shuffle */
|
||||||
|
static void mixer(PC5Context *ctxpc5, uint8_t *mixu, int nn) {
|
||||||
|
int ii, jj, tmmp;
|
||||||
|
for (ii = nn - 1; ii > 0; ii--) {
|
||||||
|
jj = mixy(ctxpc5, ii + 1);
|
||||||
|
tmmp = mixu[jj];
|
||||||
|
mixu[jj] = mixu[ii];
|
||||||
|
mixu[ii] = (uint8_t)tmmp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Key schedule and S-box generation */
|
||||||
|
void create_keys_pc5(PC5Context *ctxpc5, unsigned char key1[], size_t size1) {
|
||||||
|
int i, w, k;
|
||||||
|
unsigned char h4[n1];
|
||||||
|
|
||||||
|
md2_init(ctxpc5);
|
||||||
|
md2_hashing(ctxpc5, key1, size1);
|
||||||
|
md2_end(ctxpc5, h4);
|
||||||
|
|
||||||
|
for (i = 0; i < 16; i++) ctxpc5->keys[i] = h4[i];
|
||||||
|
arc4_init(ctxpc5, h4);
|
||||||
|
|
||||||
|
ctxpc5->x = 0;
|
||||||
|
for (i = 0; i < 8; i++) ctxpc5->x = (ctxpc5->x << 8) + (uint64_t)(h4[256 + i] & 0xffu);
|
||||||
|
|
||||||
|
ctxpc5->xyz = 0;
|
||||||
|
ctxpc5->count = 0;
|
||||||
|
|
||||||
|
for (i = 0; i < 23000; i++) (void)arc4_output(ctxpc5);
|
||||||
|
|
||||||
|
uint8_t numbers[256];
|
||||||
|
|
||||||
|
for (w = 0; w < 253; w++) {
|
||||||
|
k = arc4_output(ctxpc5) + 256;
|
||||||
|
for (i = 0; i < k; i++) (void)arc4_output(ctxpc5);
|
||||||
|
for (i = 0; i < 16; i++) numbers[i] = (uint8_t)i;
|
||||||
|
mixer(ctxpc5, numbers, 16);
|
||||||
|
for (i = 0; i < 16; i++) ctxpc5->perm[i][w] = numbers[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
k = arc4_output(ctxpc5) + 256;
|
||||||
|
for (i = 0; i < k; i++) (void)arc4_output(ctxpc5);
|
||||||
|
for (i = 0; i < 16; i++) numbers[i] = (uint8_t)i;
|
||||||
|
mixer(ctxpc5, numbers, 16);
|
||||||
|
for (i = 0; i < 16; i++) ctxpc5->new1[i] = numbers[i];
|
||||||
|
|
||||||
|
k = arc4_output(ctxpc5) + 256;
|
||||||
|
for (i = 0; i < k; i++) (void)arc4_output(ctxpc5);
|
||||||
|
for (i = 0; i < nbround; i++) ctxpc5->decal[i] = (uint8_t)((arc4_output(ctxpc5) % 11) + 1);
|
||||||
|
|
||||||
|
k = arc4_output(ctxpc5) + 256;
|
||||||
|
for (i = 0; i < k; i++) (void)arc4_output(ctxpc5);
|
||||||
|
for (w = 0; w < 3; w++)
|
||||||
|
for (i = 0; i < nbround; i++)
|
||||||
|
ctxpc5->rngxor[i][w] = arc4_output(ctxpc5) % 16;
|
||||||
|
|
||||||
|
k = arc4_output(ctxpc5) + 256;
|
||||||
|
for (i = 0; i < k; i++) (void)arc4_output(ctxpc5);
|
||||||
|
for (i = 0; i < 16; i++) numbers[i] = (uint8_t)i;
|
||||||
|
mixer(ctxpc5, numbers, 16);
|
||||||
|
for (i = 0; i < 16; i++) {
|
||||||
|
ctxpc5->tab[i] = numbers[i];
|
||||||
|
ctxpc5->inv[ctxpc5->tab[i]] = (unsigned char)i;
|
||||||
|
}
|
||||||
|
|
||||||
|
k = arc4_output(ctxpc5) + 256;
|
||||||
|
for (i = 0; i < k; i++) (void)arc4_output(ctxpc5);
|
||||||
|
for (w = 0; w < 3; w++) {
|
||||||
|
k = arc4_output(ctxpc5) + 256;
|
||||||
|
for (i = 0; i < k; i++) (void)arc4_output(ctxpc5);
|
||||||
|
for (i = 0; i < 3; i++) numbers[i] = (uint8_t)i;
|
||||||
|
mixer(ctxpc5, numbers, 3);
|
||||||
|
for (i = 0; i < 3; i++) ctxpc5->permut[w][i] = numbers[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
k = arc4_output(ctxpc5) + 256;
|
||||||
|
for (i = 0; i < k; i++) (void)arc4_output(ctxpc5);
|
||||||
|
for (w = 0; w < 3; w++)
|
||||||
|
for (i = 0; i < nbround; i++)
|
||||||
|
ctxpc5->rngxor2[i][w] = arc4_output(ctxpc5) % 16;
|
||||||
|
|
||||||
|
k = arc4_output(ctxpc5) + 256;
|
||||||
|
|
||||||
|
for (w = 0; w < 25; w++) ctxpc5->numbers[w]=arc4_output(ctxpc5) % 2;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static void compute_pc5(PC5Context *ctxpc5, uint8_t *tab1, uint8_t round) {
|
||||||
|
ctxpc5->tot[0] = (uint8_t)((ctxpc5->perm[tab1[ctxpc5->permut[0][0]]][round] +
|
||||||
|
ctxpc5->perm[tab1[ctxpc5->permut[0][1]]][round]) ^
|
||||||
|
ctxpc5->perm[tab1[ctxpc5->permut[0][2]]][round]);
|
||||||
|
ctxpc5->tot[0] = (uint8_t)((ctxpc5->tot[0] + ctxpc5->new1[ctxpc5->tot[0]]) % 16);
|
||||||
|
ctxpc5->tot[1] = (uint8_t)((ctxpc5->perm[tab1[ctxpc5->permut[1][0]]][round] +
|
||||||
|
ctxpc5->perm[tab1[ctxpc5->permut[1][1]]][round]) ^
|
||||||
|
ctxpc5->perm[tab1[ctxpc5->permut[1][2]]][round]);
|
||||||
|
ctxpc5->tot[1] = (uint8_t)((ctxpc5->tot[1] + ctxpc5->new1[ctxpc5->tot[1]]) % 16);
|
||||||
|
ctxpc5->tot[2] = (uint8_t)((ctxpc5->perm[tab1[ctxpc5->permut[2][0]]][round] +
|
||||||
|
ctxpc5->perm[tab1[ctxpc5->permut[2][1]]][round]) ^
|
||||||
|
ctxpc5->perm[tab1[ctxpc5->permut[2][2]]][round]);
|
||||||
|
ctxpc5->tot[2] = (uint8_t)((ctxpc5->tot[2] + ctxpc5->new1[ctxpc5->tot[2]]) % 16);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Convert bits to bytes */
|
||||||
|
void binhexpc5(PC5Context *ctxpc5, short *z, int length) {
|
||||||
|
short *b = (short *)z;
|
||||||
|
uint8_t i, j;
|
||||||
|
for (i = 0; i < length; i = j) {
|
||||||
|
uint8_t a = 0;
|
||||||
|
for (j = i; j < i + 8; ++j) {
|
||||||
|
a |= (uint8_t)(b[((short)(7 - (j % 8)) + j) - (j % 8)] << (j - i));
|
||||||
|
}
|
||||||
|
ctxpc5->convert[ctxpc5->ptconvert] = a;
|
||||||
|
ctxpc5->ptconvert++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Convert byte to bits */
|
||||||
|
void hexbinpc5(PC5Context *ctxpc5, short *q, uint8_t w, uint8_t hex) { // warning: unused parameter ‘ctxpc5’ [-Wunused-parameter]
|
||||||
|
UNUSED(ctxpc5);
|
||||||
|
short *bits = (short *)q;
|
||||||
|
for (uint8_t i = 0; i < 8; ++i) {
|
||||||
|
bits[(short)(7 + w) - i] = (short)((hex >> i) & 1u);
|
||||||
|
}
|
||||||
|
|
||||||
|
// UNUSEDPC4(ctxpc5); //fix above warning
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Encrypt one block */
|
||||||
|
void pc5encrypt(PC5Context *ctxpc5) {
|
||||||
|
int i;
|
||||||
|
int g;
|
||||||
|
|
||||||
|
for (i = 0; i < 3; i++) {
|
||||||
|
ctxpc5->l[0][i] = ctxpc5->convert[i];
|
||||||
|
ctxpc5->r[0][i] = ctxpc5->convert[i + 3];
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 1; i <= ctxpc5->rounds; i++) {
|
||||||
|
ctxpc5->r[(i - 1) % 2][0] = (ctxpc5->r[(i - 1) % 2][0] + ((uint8_t)~ctxpc5->rngxor2[ctxpc5->rounds - i][0])) % 16;
|
||||||
|
ctxpc5->r[(i - 1) % 2][1] = (ctxpc5->r[(i - 1) % 2][1] ^ ((uint8_t)~ctxpc5->rngxor2[ctxpc5->rounds - i][1])) % 16;
|
||||||
|
ctxpc5->r[(i - 1) % 2][2] = (ctxpc5->r[(i - 1) % 2][2] + ((uint8_t)~ctxpc5->rngxor2[ctxpc5->rounds - i][2])) % 16;
|
||||||
|
|
||||||
|
ctxpc5->result = 0;
|
||||||
|
ctxpc5->result += ((uint32_t)ctxpc5->r[(i - 1) % 2][0] << 8);
|
||||||
|
ctxpc5->result += ((uint32_t)ctxpc5->r[(i - 1) % 2][1] << 4);
|
||||||
|
ctxpc5->result += ctxpc5->r[(i - 1) % 2][2];
|
||||||
|
|
||||||
|
ctxpc5->result = rol(ctxpc5->result, ctxpc5->decal[i - 1], 12);
|
||||||
|
|
||||||
|
ctxpc5->r[(i - 1) % 2][0] = (uint8_t)(ctxpc5->result >> 8);
|
||||||
|
ctxpc5->r[(i - 1) % 2][1] = (uint8_t)((ctxpc5->result >> 4) & 0xfu);
|
||||||
|
ctxpc5->r[(i - 1) % 2][2] = (uint8_t)(ctxpc5->result & 0xfu);
|
||||||
|
|
||||||
|
ctxpc5->r[(i - 1) % 2][0] = ctxpc5->tab[ctxpc5->r[(i - 1) % 2][0]];
|
||||||
|
ctxpc5->r[(i - 1) % 2][0] = (ctxpc5->r[(i - 1) % 2][0] ^ ctxpc5->rngxor[i - 1][0]) % 16;
|
||||||
|
|
||||||
|
ctxpc5->r[(i - 1) % 2][1] = ctxpc5->inv[ctxpc5->r[(i - 1) % 2][1]];
|
||||||
|
|
||||||
|
if ((ctxpc5->r[(i - 1) % 2][1] - ctxpc5->rngxor[i - 1][1]) < 0) {
|
||||||
|
g = (ctxpc5->r[(i - 1) % 2][1] - ctxpc5->rngxor[i - 1][1]) + 16;
|
||||||
|
} else {
|
||||||
|
g = (ctxpc5->r[(i - 1) % 2][1] - ctxpc5->rngxor[i - 1][1]) % 16;
|
||||||
|
}
|
||||||
|
ctxpc5->r[(i - 1) % 2][1] = g;
|
||||||
|
|
||||||
|
ctxpc5->r[(i - 1) % 2][2] = ctxpc5->tab[ctxpc5->r[(i - 1) % 2][2]];
|
||||||
|
ctxpc5->r[(i - 1) % 2][2] = (ctxpc5->r[(i - 1) % 2][2] ^ ctxpc5->rngxor[i - 1][2]) % 16;
|
||||||
|
|
||||||
|
compute_pc5(ctxpc5, ctxpc5->r[(i - 1) % 2], (uint8_t)((i - 1) % 253));
|
||||||
|
|
||||||
|
ctxpc5->l[i % 2][0] = ctxpc5->r[(i - 1) % 2][0];
|
||||||
|
|
||||||
|
if ((ctxpc5->l[(i - 1) % 2][0] - ctxpc5->tot[0]) < 0) {
|
||||||
|
g = (ctxpc5->l[(i - 1) % 2][0] - ctxpc5->tot[0]) + 16;
|
||||||
|
} else {
|
||||||
|
g = ctxpc5->l[(i - 1) % 2][0] - ctxpc5->tot[0];
|
||||||
|
}
|
||||||
|
ctxpc5->r[i % 2][0] = g;
|
||||||
|
|
||||||
|
ctxpc5->l[i % 2][1] = ctxpc5->r[(i - 1) % 2][1];
|
||||||
|
ctxpc5->r[i % 2][1] = (ctxpc5->l[(i - 1) % 2][1] ^ ctxpc5->tot[1]) % 16;
|
||||||
|
|
||||||
|
ctxpc5->l[i % 2][2] = ctxpc5->r[(i - 1) % 2][2];
|
||||||
|
|
||||||
|
if ((ctxpc5->l[(i - 1) % 2][2] - ctxpc5->tot[2]) < 0) {
|
||||||
|
g = (ctxpc5->l[(i - 1) % 2][2] - ctxpc5->tot[2]) + 16;
|
||||||
|
} else {
|
||||||
|
g = ctxpc5->l[(i - 1) % 2][2] - ctxpc5->tot[2];
|
||||||
|
}
|
||||||
|
ctxpc5->r[i % 2][2] = g;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < 3; i++) {
|
||||||
|
ctxpc5->convert[i + 3] = ctxpc5->l[(ctxpc5->rounds - 1) % 2][i];
|
||||||
|
ctxpc5->convert[i] = ctxpc5->r[(ctxpc5->rounds - 1) % 2][i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Decrypt one block */
|
||||||
|
void pc5decrypt(PC5Context *ctxpc5) {
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; i < 3; i++) {
|
||||||
|
ctxpc5->l[0][i] = ctxpc5->convert[i];
|
||||||
|
ctxpc5->r[0][i] = ctxpc5->convert[i + 3];
|
||||||
|
}
|
||||||
|
|
||||||
|
ctxpc5->y = (uint8_t)((ctxpc5->rounds - 1) % 253);
|
||||||
|
if (ctxpc5->y == 0) ctxpc5->y = 253;
|
||||||
|
|
||||||
|
for (i = 1; i <= ctxpc5->rounds; i++) {
|
||||||
|
ctxpc5->y--;
|
||||||
|
compute_pc5(ctxpc5, ctxpc5->r[(i - 1) % 2], ctxpc5->y);
|
||||||
|
if (ctxpc5->y == 0) ctxpc5->y = 253;
|
||||||
|
|
||||||
|
ctxpc5->result = 0;
|
||||||
|
|
||||||
|
ctxpc5->l[(i - 1) % 2][0] ^= ctxpc5->rngxor[ctxpc5->rounds - i][0];
|
||||||
|
ctxpc5->l[(i - 1) % 2][0] %= 16;
|
||||||
|
ctxpc5->l[(i - 1) % 2][0] = ctxpc5->inv[ctxpc5->l[(i - 1) % 2][0]];
|
||||||
|
|
||||||
|
ctxpc5->l[(i - 1) % 2][1] += ctxpc5->rngxor[ctxpc5->rounds - i][1];
|
||||||
|
ctxpc5->l[(i - 1) % 2][1] %= 16;
|
||||||
|
ctxpc5->l[(i - 1) % 2][1] = ctxpc5->tab[ctxpc5->l[(i - 1) % 2][1]];
|
||||||
|
|
||||||
|
ctxpc5->l[(i - 1) % 2][2] ^= ctxpc5->rngxor[ctxpc5->rounds - i][2];
|
||||||
|
ctxpc5->l[(i - 1) % 2][2] %= 16;
|
||||||
|
ctxpc5->l[(i - 1) % 2][2] = ctxpc5->inv[ctxpc5->l[(i - 1) % 2][2]];
|
||||||
|
|
||||||
|
ctxpc5->result += ((uint32_t)ctxpc5->l[(i - 1) % 2][0] << 8);
|
||||||
|
ctxpc5->result += ((uint32_t)ctxpc5->l[(i - 1) % 2][1] << 4);
|
||||||
|
ctxpc5->result += ctxpc5->l[(i - 1) % 2][2];
|
||||||
|
|
||||||
|
ctxpc5->result = ror(ctxpc5->result, ctxpc5->decal[ctxpc5->rounds - i], 12);
|
||||||
|
|
||||||
|
ctxpc5->l[(i - 1) % 2][0] = (uint8_t)(ctxpc5->result >> 8);
|
||||||
|
ctxpc5->l[(i - 1) % 2][1] = (uint8_t)((ctxpc5->result >> 4) & 0xfu);
|
||||||
|
ctxpc5->l[(i - 1) % 2][2] = (uint8_t)(ctxpc5->result & 0xfu);
|
||||||
|
|
||||||
|
int temp;
|
||||||
|
|
||||||
|
temp = ctxpc5->l[(i - 1) % 2][0] - ((uint8_t)(~ctxpc5->rngxor2[i - 1][0]) % 16);
|
||||||
|
if (temp < 0) temp += 16;
|
||||||
|
ctxpc5->l[(i - 1) % 2][0] = temp % 16;
|
||||||
|
|
||||||
|
ctxpc5->l[(i - 1) % 2][1] ^= (uint8_t)(~ctxpc5->rngxor2[i - 1][1]) % 16;
|
||||||
|
ctxpc5->l[(i - 1) % 2][1] %= 16;
|
||||||
|
|
||||||
|
temp = ctxpc5->l[(i - 1) % 2][2] - ((uint8_t)(~ctxpc5->rngxor2[i - 1][2]) % 16);
|
||||||
|
if (temp < 0) temp += 16;
|
||||||
|
ctxpc5->l[(i - 1) % 2][2] = temp % 16;
|
||||||
|
|
||||||
|
ctxpc5->l[i % 2][0] = ctxpc5->r[(i - 1) % 2][0];
|
||||||
|
ctxpc5->r[i % 2][0] = (ctxpc5->l[(i - 1) % 2][0] + ctxpc5->tot[0]) % 16;
|
||||||
|
|
||||||
|
ctxpc5->l[i % 2][1] = ctxpc5->r[(i - 1) % 2][1];
|
||||||
|
ctxpc5->r[i % 2][1] = (ctxpc5->l[(i - 1) % 2][1] ^ ctxpc5->tot[1]) % 16;
|
||||||
|
|
||||||
|
ctxpc5->l[i % 2][2] = ctxpc5->r[(i - 1) % 2][2];
|
||||||
|
ctxpc5->r[i % 2][2] = (ctxpc5->l[(i - 1) % 2][2] + ctxpc5->tot[2]) % 16;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < 3; i++) {
|
||||||
|
ctxpc5->convert[i + 3] = ctxpc5->l[(ctxpc5->rounds - 1) % 2][i];
|
||||||
|
ctxpc5->convert[i] = ctxpc5->r[(ctxpc5->rounds - 1) % 2][i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Key creation for BAOFENG AP */
|
||||||
|
void baofeng_ap_pc5_keystream_creation(dsd_state *state, char *input) {
|
||||||
|
|
||||||
|
char buf[1024];
|
||||||
|
strncpy(buf, input, sizeof(buf) - 1);
|
||||||
|
buf[sizeof(buf) - 1] = '\0';
|
||||||
|
|
||||||
|
// Count hexadecimal characters (without spaces)
|
||||||
|
int hex_char_count = 0;
|
||||||
|
for (int i = 0; buf[i] != '\0'; i++) {
|
||||||
|
if (isxdigit(buf[i])) {
|
||||||
|
hex_char_count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hex_char_count == 32) { // 128 bits (32 hex characters)
|
||||||
|
unsigned char key1[16] = {0};
|
||||||
|
unsigned char key2[16] = {0};
|
||||||
|
|
||||||
|
char *pEnd;
|
||||||
|
uint64_t K1 = strtoull(buf, &pEnd, 16);
|
||||||
|
uint64_t K2 = strtoull(pEnd, &pEnd, 16);
|
||||||
|
|
||||||
|
u64_to_bytes_be_pc5(K1, &key1[0]);
|
||||||
|
u64_to_bytes_be_pc5(K2, &key1[8]);
|
||||||
|
|
||||||
|
// Reverse key for PC5 (only for 128-bit)
|
||||||
|
for (int i=0;i<16;i++) key2[i] = key1[15-i];
|
||||||
|
|
||||||
|
/* Create key schedule */
|
||||||
|
create_keys_pc5(&ctxpc5, key2, sizeof(key2));
|
||||||
|
ctxpc5.rounds = nbround;
|
||||||
|
|
||||||
|
fprintf(stderr, "DMR BAOFENG AP (PC5) 128-bit Key %016llX%016llX with Forced Application\n",
|
||||||
|
(unsigned long long)K1, (unsigned long long)K2);
|
||||||
|
state->baofeng_ap = 1;
|
||||||
|
|
||||||
|
} else if (hex_char_count == 64) { // 256 bits (64 hex characters)
|
||||||
|
// Remove spaces and store as ASCII string (64 bytes)
|
||||||
|
char ascii_key[65] = {0}; // 64 characters + null terminator
|
||||||
|
int j = 0;
|
||||||
|
for (int i = 0; buf[i] != '\0' && j < 64; i++) {
|
||||||
|
if (isxdigit(buf[i])) {
|
||||||
|
ascii_key[j++] = buf[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ascii_key[64] = '\0';
|
||||||
|
|
||||||
|
/* Create key schedule */
|
||||||
|
create_keys_pc5(&ctxpc5, (unsigned char*)ascii_key, 64);
|
||||||
|
ctxpc5.rounds = nbround;
|
||||||
|
|
||||||
|
fprintf(stderr, "DMR BAOFENG AP (PC5) 256-bit Key: %s with Forced Application\n", ascii_key);
|
||||||
|
state->baofeng_ap = 1;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
fprintf(stderr, "ERROR: Invalid key length. Expected 32 chars (128-bit) or 64 chars (256-bit), got %d hex chars\n", hex_char_count);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
404
src/crypt-rc2.c
Normal file
404
src/crypt-rc2.c
Normal file
@@ -0,0 +1,404 @@
|
|||||||
|
#include "rc2.h"
|
||||||
|
#include "dsd.h"
|
||||||
|
|
||||||
|
static inline uint64_t rol64(uint64_t x, int n) {
|
||||||
|
return ((x << n) | (x >> (63 - n) >> 1)) & 0xffffffffffffffff;
|
||||||
|
}
|
||||||
|
|
||||||
|
void swapbit(uint64_t* internalstate, uint8_t bit) {
|
||||||
|
unsigned char bitB = bit & 1;
|
||||||
|
if (bitB)
|
||||||
|
*internalstate |= bitB;
|
||||||
|
else
|
||||||
|
*internalstate &= (~bitB ^ 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// MD2 functions
|
||||||
|
void md2_init(MD2State* state) {
|
||||||
|
state->x1 = 0;
|
||||||
|
state->x2 = 0;
|
||||||
|
memset(state->h2, 0, n1);
|
||||||
|
memset(state->h1, 0, n1 * 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
void md2_hashing(MD2State* state, unsigned char t1[], size_t b6) {
|
||||||
|
static unsigned char s4[256] = {
|
||||||
|
13,199,11,67,237,193,164,77,115,184,141,222,73,
|
||||||
|
38,147,36,150,87,21,104,12,61,156,101,111,145,
|
||||||
|
119,22,207,35,198,37,171,167,80,30,219,28,213,
|
||||||
|
121,86,29,214,242,6,4,89,162,110,175,19,157,
|
||||||
|
3,88,234,94,144,118,159,239,100,17,182,173,238,
|
||||||
|
68,16,79,132,54,163,52,9,58,57,55,229,192,
|
||||||
|
170,226,56,231,187,158,70,224,233,245,26,47,32,
|
||||||
|
44,247,8,251,20,197,185,109,153,204,218,93,178,
|
||||||
|
212,137,84,174,24,120,130,149,72,180,181,208,255,
|
||||||
|
189,152,18,143,176,60,249,27,227,128,139,243,253,
|
||||||
|
59,123,172,108,211,96,138,10,215,42,225,40,81,
|
||||||
|
65,90,25,98,126,154,64,124,116,122,5,1,168,
|
||||||
|
83,190,131,191,244,240,235,177,155,228,125,66,43,
|
||||||
|
201,248,220,129,188,230,62,75,71,78,34,31,216,
|
||||||
|
254,136,91,114,106,46,217,196,92,151,209,133,51,
|
||||||
|
236,33,252,127,179,69,7,183,105,146,97,39,15,
|
||||||
|
205,112,200,166,223,45,48,246,186,41,148,140,107,
|
||||||
|
76,85,95,194,142,50,49,134,23,135,169,221,210,
|
||||||
|
203,63,165,82,161,202,53,14,206,232,103,102,195,
|
||||||
|
117,250,99,0,74,160,241,2,113
|
||||||
|
};
|
||||||
|
|
||||||
|
int b4 = 0;
|
||||||
|
|
||||||
|
while (b6) {
|
||||||
|
for (; b6 && state->x2 < n1; b6--, state->x2++) {
|
||||||
|
int b5 = t1[b4++];
|
||||||
|
state->h1[state->x2 + n1] = b5;
|
||||||
|
state->h1[state->x2 + (n1 * 2)] = b5 ^ state->h1[state->x2];
|
||||||
|
state->x1 = state->h2[state->x2] ^= s4[b5 ^ state->x1];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state->x2 == n1) {
|
||||||
|
int b2 = 0;
|
||||||
|
state->x2 = 0;
|
||||||
|
|
||||||
|
for (int b3 = 0; b3 < (n1 + 2); b3++) {
|
||||||
|
for (int b1 = 0; b1 < (n1 * 3); b1++)
|
||||||
|
b2 = state->h1[b1] ^= s4[b2];
|
||||||
|
b2 = (b2 + b3) % 256;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void md2_end(MD2State* state, unsigned char h4[n1]) {
|
||||||
|
unsigned char h3[n1];
|
||||||
|
int n4 = n1 - state->x2;
|
||||||
|
for (int i = 0; i < n4; i++) h3[i] = n4;
|
||||||
|
md2_hashing(state, h3, n4);
|
||||||
|
md2_hashing(state, state->h2, sizeof(state->h2));
|
||||||
|
for (int i = 0; i < n1; i++) h4[i] = state->h1[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
// RC4 functions
|
||||||
|
uint64_t next(RC4State* state) {
|
||||||
|
uint64_t z = (state->x += 0x9e3779b97f4a7c15);
|
||||||
|
z = (z ^ (z >> 30)) * 0xbf58476d1ce4e5b9;
|
||||||
|
z = (z ^ (z >> 27)) * 0x94d049bb133111eb;
|
||||||
|
return z ^ (z >> 31);
|
||||||
|
}
|
||||||
|
|
||||||
|
void rc4_init(RC4State* state, unsigned char key[]) {
|
||||||
|
int tmp;
|
||||||
|
|
||||||
|
for (state->i_rc4 = 0; state->i_rc4 < 256; state->i_rc4++) {
|
||||||
|
state->array_rc4[state->i_rc4] = state->i_rc4;
|
||||||
|
}
|
||||||
|
|
||||||
|
state->j_rc4 = 0;
|
||||||
|
for (state->i_rc4 = 0; state->i_rc4 < 256; state->i_rc4++) {
|
||||||
|
state->j_rc4 = (state->j_rc4 + state->array_rc4[state->i_rc4] + key[state->i_rc4 % 256]) % 256;
|
||||||
|
tmp = state->array_rc4[state->i_rc4];
|
||||||
|
state->array_rc4[state->i_rc4] = state->array_rc4[state->j_rc4];
|
||||||
|
state->array_rc4[state->j_rc4] = tmp;
|
||||||
|
}
|
||||||
|
state->i_rc4 = 0;
|
||||||
|
state->j_rc4 = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned char rc4_output(RC4State* state) {
|
||||||
|
uint8_t rndbyte, decal;
|
||||||
|
int tmp, t;
|
||||||
|
|
||||||
|
state->i_rc4 = (state->i_rc4 + 1) % 256;
|
||||||
|
state->j_rc4 = (state->j_rc4 + state->array_rc4[state->i_rc4]) % 256;
|
||||||
|
tmp = state->array_rc4[state->i_rc4];
|
||||||
|
state->array_rc4[state->i_rc4] = state->array_rc4[state->j_rc4];
|
||||||
|
state->array_rc4[state->j_rc4] = tmp;
|
||||||
|
t = (state->array_rc4[state->i_rc4] + state->array_rc4[state->j_rc4]) % 256;
|
||||||
|
|
||||||
|
|
||||||
|
if (state->xyz == 0) state->bb = next(state);
|
||||||
|
decal = 56 - (8 * state->xyz);
|
||||||
|
rndbyte = (state->bb >> decal) & 0xff;
|
||||||
|
state->xyz++;
|
||||||
|
if (state->xyz == 8) state->xyz = 0;
|
||||||
|
|
||||||
|
if (state->count == 0) {
|
||||||
|
rndbyte = rndbyte ^ state->array_rc4[t];
|
||||||
|
state->count = 1;
|
||||||
|
} else {
|
||||||
|
rndbyte = rndbyte + state->array_rc4[t];
|
||||||
|
state->count = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return rndbyte;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Convert 64-bit integer to bytes (big-endian) */
|
||||||
|
static void u64_to_bytes_be(uint64_t val, unsigned char *out) {
|
||||||
|
for (int i = 0; i < 8; i++) {
|
||||||
|
out[i] = (unsigned char)((val >> (56 - 8 * i)) & 0xFF);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// RC2 functions
|
||||||
|
void rc2_keyschedule(RC2State* state) {
|
||||||
|
unsigned i;
|
||||||
|
// Phase 3 - copy to xkey in little-endian order
|
||||||
|
i = 63;
|
||||||
|
do {
|
||||||
|
state->xkey[i] = ((unsigned char *)state->xkey)[2 * i] +
|
||||||
|
(((unsigned char *)state->xkey)[2 * i + 1] << 8);
|
||||||
|
} while (i--);
|
||||||
|
}
|
||||||
|
|
||||||
|
void rc2_encrypt(RC2State* state) {
|
||||||
|
uint16_t x76, x54, x32, x10, i;
|
||||||
|
|
||||||
|
x76 = (state->plain[7] << 8) + state->plain[6];
|
||||||
|
x54 = (state->plain[5] << 8) + state->plain[4];
|
||||||
|
x32 = (state->plain[3] << 8) + state->plain[2];
|
||||||
|
x10 = (state->plain[1] << 8) + state->plain[0];
|
||||||
|
|
||||||
|
for (i = 0; i < 16; i++) {
|
||||||
|
x10 += (x32 & ~x76) + (x54 & x76) + state->xkey[4 * i + 0];
|
||||||
|
x10 = (x10 << 1) + (x10 >> 15 & 1);
|
||||||
|
|
||||||
|
x32 += (x54 & ~x10) + (x76 & x10) + state->xkey[4 * i + 1];
|
||||||
|
x32 = (x32 << 2) + (x32 >> 14 & 3);
|
||||||
|
|
||||||
|
x54 += (x76 & ~x32) + (x10 & x32) + state->xkey[4 * i + 2];
|
||||||
|
x54 = (x54 << 3) + (x54 >> 13 & 7);
|
||||||
|
|
||||||
|
x76 += (x10 & ~x54) + (x32 & x54) + state->xkey[4 * i + 3];
|
||||||
|
x76 = (x76 << 5) + (x76 >> 11 & 31);
|
||||||
|
|
||||||
|
if (i == 4 || i == 10) {
|
||||||
|
x10 += state->xkey[x76 & 63];
|
||||||
|
x32 += state->xkey[x10 & 63];
|
||||||
|
x54 += state->xkey[x32 & 63];
|
||||||
|
x76 += state->xkey[x54 & 63];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
state->cipher[0] = (unsigned char)x10;
|
||||||
|
state->cipher[1] = (unsigned char)(x10 >> 8);
|
||||||
|
state->cipher[2] = (unsigned char)x32;
|
||||||
|
state->cipher[3] = (unsigned char)(x32 >> 8);
|
||||||
|
state->cipher[4] = (unsigned char)x54;
|
||||||
|
state->cipher[5] = (unsigned char)(x54 >> 8);
|
||||||
|
state->cipher[6] = (unsigned char)x76;
|
||||||
|
state->cipher[7] = (unsigned char)(x76 >> 8);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Main cryptographic functions
|
||||||
|
void create_keys_rc2(CryptoContext* ctx, unsigned char key1[], size_t size1) {
|
||||||
|
unsigned char h4[n1];
|
||||||
|
|
||||||
|
// Initialize MD2 and hash the key
|
||||||
|
md2_init(&ctx->md2);
|
||||||
|
md2_hashing(&ctx->md2, key1, size1);
|
||||||
|
md2_end(&ctx->md2, h4);
|
||||||
|
|
||||||
|
// Copy first 16 bytes to keys
|
||||||
|
for (int i = 0; i < 16; i++) ctx->keys[i] = h4[i];
|
||||||
|
|
||||||
|
// Initialize RC4 with hashed key
|
||||||
|
rc4_init(&ctx->rc4, h4);
|
||||||
|
|
||||||
|
// Initialize RC4 state variables
|
||||||
|
ctx->rc4.x = 0;
|
||||||
|
for (int i = 0; i < 8; i++) ctx->rc4.x = (ctx->rc4.x << 8) + (h4[256 + i] & 0xff);
|
||||||
|
|
||||||
|
ctx->rc4.xyz = 0;
|
||||||
|
ctx->rc4.count = 0;
|
||||||
|
|
||||||
|
// Warm-up RC4
|
||||||
|
for (int i = 0; i < 22000; i++) rc4_output(&ctx->rc4);
|
||||||
|
|
||||||
|
// Generate RC2 keys
|
||||||
|
int k = rc4_output(&ctx->rc4) + 256;
|
||||||
|
for (int i = 0; i < k; i++) rc4_output(&ctx->rc4);
|
||||||
|
|
||||||
|
for (int i = 0; i < 64; i++) {
|
||||||
|
ctx->rc2.xkey[i] = (rc4_output(&ctx->rc4) << 8) + rc4_output(&ctx->rc4);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generate internal zero value
|
||||||
|
k = rc4_output(&ctx->rc4) + 256;
|
||||||
|
for (int i = 0; i < k; i++) rc4_output(&ctx->rc4);
|
||||||
|
|
||||||
|
ctx->internal_zero = 0;
|
||||||
|
for (int i = 0; i < 8; i++) {
|
||||||
|
ctx->internal_zero = (ctx->internal_zero << 8) + rc4_output(&ctx->rc4);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generate RC2 key schedule
|
||||||
|
rc2_keyschedule(&ctx->rc2);
|
||||||
|
}
|
||||||
|
|
||||||
|
void encryption_rc2(CryptoContext* ctx, uint8_t bits[49]) {
|
||||||
|
ctx->internal_state = ctx->internal_zero;
|
||||||
|
|
||||||
|
for (int sso = 0; sso < 49; sso++) {
|
||||||
|
// Prepare plaintext from internal state
|
||||||
|
ctx->rc2.plain[0] = (ctx->internal_state >> 56) & 0xff;
|
||||||
|
ctx->rc2.plain[1] = (ctx->internal_state >> 48) & 0xff;
|
||||||
|
ctx->rc2.plain[2] = (ctx->internal_state >> 40) & 0xff;
|
||||||
|
ctx->rc2.plain[3] = (ctx->internal_state >> 32) & 0xff;
|
||||||
|
ctx->rc2.plain[4] = (ctx->internal_state >> 24) & 0xff;
|
||||||
|
ctx->rc2.plain[5] = (ctx->internal_state >> 16) & 0xff;
|
||||||
|
ctx->rc2.plain[6] = (ctx->internal_state >> 8) & 0xff;
|
||||||
|
ctx->rc2.plain[7] = ctx->internal_state & 0xff;
|
||||||
|
|
||||||
|
// Encrypt with RC2
|
||||||
|
rc2_encrypt(&ctx->rc2);
|
||||||
|
|
||||||
|
// Reconstruct internal state from ciphertext
|
||||||
|
ctx->internal_state = 0;
|
||||||
|
for (int i = 0; i < 8; i++) {
|
||||||
|
ctx->internal_state = (ctx->internal_state << 8) + (ctx->rc2.cipher[i] & 0xff);
|
||||||
|
}
|
||||||
|
|
||||||
|
// XOR the bit and update internal state
|
||||||
|
bits[48 - sso] = bits[48 - sso] ^ (ctx->internal_state & 1);
|
||||||
|
ctx->internal_state = rol64(ctx->internal_state, 1);
|
||||||
|
swapbit(&ctx->internal_state, bits[48 - sso]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void decrypt_rc2(CryptoContext* ctx, uint8_t bits[49]) {
|
||||||
|
uint8_t tempy;
|
||||||
|
ctx->internal_state = ctx->internal_zero;
|
||||||
|
|
||||||
|
|
||||||
|
for (int sso = 0; sso < 49; sso++) {
|
||||||
|
// Prepare plaintext from internal state
|
||||||
|
ctx->rc2.plain[0] = (ctx->internal_state >> 56) & 0xff;
|
||||||
|
ctx->rc2.plain[1] = (ctx->internal_state >> 48) & 0xff;
|
||||||
|
ctx->rc2.plain[2] = (ctx->internal_state >> 40) & 0xff;
|
||||||
|
ctx->rc2.plain[3] = (ctx->internal_state >> 32) & 0xff;
|
||||||
|
ctx->rc2.plain[4] = (ctx->internal_state >> 24) & 0xff;
|
||||||
|
ctx->rc2.plain[5] = (ctx->internal_state >> 16) & 0xff;
|
||||||
|
ctx->rc2.plain[6] = (ctx->internal_state >> 8) & 0xff;
|
||||||
|
ctx->rc2.plain[7] = ctx->internal_state & 0xff;
|
||||||
|
|
||||||
|
// Encrypt with RC2
|
||||||
|
rc2_encrypt(&ctx->rc2);
|
||||||
|
|
||||||
|
// Reconstruct internal state from ciphertext
|
||||||
|
ctx->internal_state = 0;
|
||||||
|
for (int i = 0; i < 8; i++) {
|
||||||
|
ctx->internal_state = (ctx->internal_state << 8) + (ctx->rc2.cipher[i] & 0xff);
|
||||||
|
}
|
||||||
|
|
||||||
|
// XOR the bit and update internal state
|
||||||
|
tempy = bits[48 - sso];
|
||||||
|
bits[48 - sso] = bits[48 - sso] ^ (ctx->internal_state & 1);
|
||||||
|
ctx->internal_state = rol64(ctx->internal_state, 1);
|
||||||
|
swapbit(&ctx->internal_state, tempy);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Key creation for Retevis AP */
|
||||||
|
void retevis_rc2_keystream_creation(dsd_state *state, char *input) {
|
||||||
|
|
||||||
|
unsigned char key1[64]; memset(key1, 0, sizeof(key1));
|
||||||
|
unsigned char key2[64]; memset(key2, 0, sizeof(key2));
|
||||||
|
|
||||||
|
char buf[1024];
|
||||||
|
strncpy(buf, input, sizeof(buf) - 1);
|
||||||
|
buf[sizeof(buf) - 1] = '\0';
|
||||||
|
|
||||||
|
char *pEnd;
|
||||||
|
uint64_t K1 = strtoull(buf, &pEnd, 16);
|
||||||
|
uint64_t K2 = strtoull(pEnd, &pEnd, 16);
|
||||||
|
uint64_t K3 = strtoull(pEnd, &pEnd, 16);
|
||||||
|
uint64_t K4 = strtoull(pEnd, &pEnd, 16);
|
||||||
|
|
||||||
|
if (K3 != 0 || K4 != 0) //256-bit keys loaded as ASCII characters
|
||||||
|
{
|
||||||
|
//start loading K1, K2, K3, and K4 as ASCII to fill 64 bytes of key1
|
||||||
|
int k = 0; uint8_t x = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < 16; i++)
|
||||||
|
{
|
||||||
|
x = ((K1 >> (60-(i*4))) & 0xF);
|
||||||
|
if (x >= 0 && x <= 9) //numbers 0-9
|
||||||
|
x += 0x30; //ASCII representation of numbers is 0x30, 0x31....0x39
|
||||||
|
else x += 0x37; //Upper ASCII A,B,C,D,E,F is 0x41, 0x42...0x46
|
||||||
|
key1[k++] = x;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < 16; i++)
|
||||||
|
{
|
||||||
|
x = ((K2 >> (60-(i*4))) & 0xF);
|
||||||
|
if (x >= 0 && x <= 9) //numbers 0-9
|
||||||
|
x += 0x30; //ASCII representation of numbers is 0x30, 0x31....0x39
|
||||||
|
else x += 0x37; //Upper ASCII A,B,C,D,E,F is 0x41, 0x42...0x46
|
||||||
|
key1[k++] = x;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < 16; i++)
|
||||||
|
{
|
||||||
|
x = ((K3 >> (60-(i*4))) & 0xF);
|
||||||
|
if (x >= 0 && x <= 9) //numbers 0-9
|
||||||
|
x += 0x30; //ASCII representation of numbers is 0x30, 0x31....0x39
|
||||||
|
else x += 0x37; //Upper ASCII A,B,C,D,E,F is 0x41, 0x42...0x46
|
||||||
|
key1[k++] = x;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < 16; i++)
|
||||||
|
{
|
||||||
|
x = ((K4 >> (60-(i*4))) & 0xF);
|
||||||
|
if (x >= 0 && x <= 9) //numbers 0-9
|
||||||
|
x += 0x30; //ASCII representation of numbers is 0x30, 0x31....0x39
|
||||||
|
else x += 0x37; //Upper ASCII A,B,C,D,E,F is 0x41, 0x42...0x46
|
||||||
|
key1[k++] = x;
|
||||||
|
}
|
||||||
|
|
||||||
|
//debug
|
||||||
|
// fprintf (stderr, "ASCII: ");
|
||||||
|
// for (int i = 0; i < 64; i++)
|
||||||
|
// fprintf (stderr, " %02X", key1[i]);
|
||||||
|
// fprintf (stderr, "\n");
|
||||||
|
|
||||||
|
// Initialize RC2 context
|
||||||
|
static CryptoContext rc2_ctx;
|
||||||
|
create_keys_rc2(&rc2_ctx, key1, 64);
|
||||||
|
|
||||||
|
// Store context in DSD state
|
||||||
|
state->rc2_context = malloc(sizeof(CryptoContext));
|
||||||
|
memcpy(state->rc2_context, &rc2_ctx, sizeof(CryptoContext));
|
||||||
|
|
||||||
|
fprintf(stderr, "DMR RETEVIS AP (RC2) 256-bit Key %016llX%016llX%016llX%016llX with Forced Application\n",
|
||||||
|
(unsigned long long)K1, (unsigned long long)K2, (unsigned long long)K3, (unsigned long long)K4);
|
||||||
|
|
||||||
|
state->retevis_ap = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
else //128-bit loaded as reverse bytes
|
||||||
|
{
|
||||||
|
|
||||||
|
u64_to_bytes_be(K1, &key1[0]);
|
||||||
|
u64_to_bytes_be(K2, &key1[8]);
|
||||||
|
|
||||||
|
// reverse load the key bytes into key2
|
||||||
|
for (int i=0;i<16;i++)
|
||||||
|
key2[i] = key1[15-i];
|
||||||
|
|
||||||
|
// Initialize RC2 context
|
||||||
|
static CryptoContext rc2_ctx;
|
||||||
|
create_keys_rc2(&rc2_ctx, key2, 16);
|
||||||
|
|
||||||
|
// Store context in DSD state
|
||||||
|
state->rc2_context = malloc(sizeof(CryptoContext));
|
||||||
|
memcpy(state->rc2_context, &rc2_ctx, sizeof(CryptoContext));
|
||||||
|
|
||||||
|
fprintf(stderr, "DMR RETEVIS AP (RC2) 128-bit Key %016llX%016llX with Forced Application\n",
|
||||||
|
(unsigned long long)K1, (unsigned long long)K2);
|
||||||
|
|
||||||
|
state->retevis_ap = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
1506
src/crypt-rc4.c
Normal file
1506
src/crypt-rc4.c
Normal file
File diff suppressed because it is too large
Load Diff
309
src/crypt-tyt.c
Normal file
309
src/crypt-tyt.c
Normal file
@@ -0,0 +1,309 @@
|
|||||||
|
#include "dsd.h"
|
||||||
|
#include "dmr_const.h"
|
||||||
|
#include "pc4.h"
|
||||||
|
|
||||||
|
//interleaved code words for AMBE+2 (as it arrives over the air)
|
||||||
|
void ambe2_codeword_print_i (dsd_opts * opts, char ambe_fr[4][24])
|
||||||
|
{
|
||||||
|
uint8_t interleaved[72];
|
||||||
|
memset (interleaved, 0, sizeof(interleaved));
|
||||||
|
|
||||||
|
//reinterleave the frame
|
||||||
|
const int *w, *x, *y, *z;
|
||||||
|
w = rW; x = rX; y = rY; z = rZ;
|
||||||
|
|
||||||
|
for (int8_t i = 0; i < 36; i++)
|
||||||
|
{
|
||||||
|
interleaved[(i*2)+0] = (uint8_t)ambe_fr[*w][*x];
|
||||||
|
interleaved[(i*2)+1] = (uint8_t)ambe_fr[*y][*z];
|
||||||
|
|
||||||
|
w++;
|
||||||
|
x++;
|
||||||
|
y++;
|
||||||
|
z++;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t bytes[9]; memset(bytes, 0, sizeof(bytes));
|
||||||
|
|
||||||
|
//pack
|
||||||
|
pack_bit_array_into_byte_array(interleaved, bytes, 9);
|
||||||
|
|
||||||
|
if (opts->payload == 1)
|
||||||
|
{
|
||||||
|
fprintf (stderr, " AMBE HEX(72) INT: ");
|
||||||
|
for (int8_t i = 0; i < 9; i++)
|
||||||
|
fprintf (stderr, "%02X", bytes[i]);
|
||||||
|
fprintf (stderr, "\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//de-interleaved code words for AMBE+2
|
||||||
|
void ambe2_codeword_print_b (dsd_opts * opts, char ambe_fr[4][24])
|
||||||
|
{
|
||||||
|
uint8_t fr_reverse[4][24]; memset(fr_reverse, 0, sizeof(fr_reverse));
|
||||||
|
for (int i = 0; i < 24; i++)
|
||||||
|
fr_reverse[0][i] = ambe_fr[0][23-i];
|
||||||
|
for (int i = 0; i < 23; i++)
|
||||||
|
fr_reverse[1][i] = ambe_fr[1][22-i];
|
||||||
|
for (int i = 0; i < 11; i++)
|
||||||
|
fr_reverse[2][i] = ambe_fr[2][10-i];
|
||||||
|
for (int i = 0; i < 14; i++)
|
||||||
|
fr_reverse[3][i] = ambe_fr[3][13-i];
|
||||||
|
|
||||||
|
uint32_t v0 = (uint32_t)convert_bits_into_output((uint8_t *)fr_reverse[0], 24); //24
|
||||||
|
uint32_t v1 = (uint32_t)convert_bits_into_output((uint8_t *)fr_reverse[1], 23); //23
|
||||||
|
uint32_t v2 = (uint32_t)convert_bits_into_output((uint8_t *)fr_reverse[2], 11); //11
|
||||||
|
uint32_t v3 = (uint32_t)convert_bits_into_output((uint8_t *)fr_reverse[3], 14); //14
|
||||||
|
|
||||||
|
uint32_t c0 = (uint32_t)convert_bits_into_output((uint8_t *)fr_reverse[0], 12);
|
||||||
|
uint32_t c1 = (uint32_t)convert_bits_into_output((uint8_t *)fr_reverse[1], 12);
|
||||||
|
|
||||||
|
//72 bit version
|
||||||
|
unsigned long long int hex1 = ((unsigned long long int)v0 << 40ULL) + ((unsigned long long int)v1 << 17ULL) + ((unsigned long long int)v2 << 6ULL) + (v3 >> 8);
|
||||||
|
unsigned long long int hex2 = v3 & 0xFF;
|
||||||
|
|
||||||
|
//49 bit version prior to golay correction and c1 demodulation pN
|
||||||
|
unsigned long long int hex49 = ((unsigned long long int)c0 << 37ULL) + ((unsigned long long int)c1 << 25ULL) + ((unsigned long long int)v2 << 14ULL) + v3;
|
||||||
|
|
||||||
|
UNUSED(opts);
|
||||||
|
|
||||||
|
if (opts->payload == 1)
|
||||||
|
{
|
||||||
|
fprintf (stderr, " AMBE HEX(72): %016llX%02llX \n", hex1, hex2);
|
||||||
|
fprintf (stderr, " AMBE HEX(49): %014llX\n", hex49 << 7);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//de-interleaved code words for AMBE+2
|
||||||
|
void ambe2_codeword_print_f (dsd_opts * opts, char ambe_fr[4][24])
|
||||||
|
{
|
||||||
|
uint32_t v0 = (uint32_t)convert_bits_into_output((uint8_t *)ambe_fr[0], 24); //24
|
||||||
|
uint32_t v1 = (uint32_t)convert_bits_into_output((uint8_t *)ambe_fr[1], 23); //23
|
||||||
|
uint32_t v2 = (uint32_t)convert_bits_into_output((uint8_t *)ambe_fr[2], 11); //11
|
||||||
|
uint32_t v3 = (uint32_t)convert_bits_into_output((uint8_t *)ambe_fr[3], 14); //14
|
||||||
|
|
||||||
|
// if (opts->payload == 1)
|
||||||
|
// fprintf (stderr, " AMBE V0: %06X; V1: %06X; V2: %03X; V3: %04X; \n", v0, v1, v2, v3);
|
||||||
|
|
||||||
|
unsigned long long int hex1 = ((unsigned long long int)v0 << 40ULL) + ((unsigned long long int)v1 << 17ULL) + ((unsigned long long int)v2 << 6ULL) + (v3 >> 8);
|
||||||
|
unsigned long long int hex2 = v3 & 0xFF;
|
||||||
|
|
||||||
|
if (opts->payload == 1)
|
||||||
|
fprintf (stderr, " AMBE HEX(72): %016llX%02llX \n", hex1, hex2);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//NOTE: This mode DOES NOT work over a repeater, simplex only
|
||||||
|
//repeaters may or will attempt to correct the frame errors
|
||||||
|
void tyt16_ambe2_codeword_keystream(dsd_state * state, char ambe_fr[4][24], int fnum)
|
||||||
|
{
|
||||||
|
|
||||||
|
char interleaved[72];
|
||||||
|
memset (interleaved, 0, sizeof(interleaved));
|
||||||
|
|
||||||
|
//interleave the frame
|
||||||
|
const int *w, *x, *y, *z;
|
||||||
|
w = rW; x = rX; y = rY; z = rZ;
|
||||||
|
|
||||||
|
for (int8_t i = 0; i < 36; i++)
|
||||||
|
{
|
||||||
|
interleaved[(i*2)+0] = ambe_fr[*w][*x];
|
||||||
|
interleaved[(i*2)+1] = ambe_fr[*y][*z];
|
||||||
|
|
||||||
|
w++;
|
||||||
|
x++;
|
||||||
|
y++;
|
||||||
|
z++;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t ks_bytes[10]; memset(ks_bytes, 0, sizeof(ks_bytes));
|
||||||
|
uint8_t ks[80]; memset(ks, 0, sizeof(ks));
|
||||||
|
|
||||||
|
ks_bytes[0] = (state->H >> 8) & 0xFF;
|
||||||
|
ks_bytes[1] = (state->H >> 0) & 0xFF;
|
||||||
|
|
||||||
|
//copy same bytes into rest of byte array
|
||||||
|
for (int16_t i = 2; i < 10; i++)
|
||||||
|
ks_bytes[i] = ks_bytes[i%2];
|
||||||
|
|
||||||
|
//convert byte array into a bit array
|
||||||
|
unpack_byte_array_into_bit_array(ks_bytes, ks, 10);
|
||||||
|
|
||||||
|
//set ks idx position (-1)
|
||||||
|
int idx = 0;
|
||||||
|
if (fnum == 0)
|
||||||
|
idx = 79;
|
||||||
|
else idx = 71;
|
||||||
|
|
||||||
|
//apply keystream to interleave
|
||||||
|
for (int8_t i = 0; i < 72; i++)
|
||||||
|
interleaved[i] ^= ks[idx--];
|
||||||
|
|
||||||
|
//deinterleave back into ambe_fr frame
|
||||||
|
w = rW; x = rX; y = rY; z = rZ;
|
||||||
|
int k = 0;
|
||||||
|
for (int8_t i = 0; i < 36; i++)
|
||||||
|
{
|
||||||
|
ambe_fr[*w][*x] = interleaved[k++];
|
||||||
|
ambe_fr[*y][*z] = interleaved[k++];
|
||||||
|
|
||||||
|
w++;
|
||||||
|
x++;
|
||||||
|
y++;
|
||||||
|
z++;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void tyt_ap_pc4_keystream_creation(dsd_state * state, char * input)
|
||||||
|
{
|
||||||
|
unsigned char key1[64]; memset(key1, 0, sizeof(key1));
|
||||||
|
unsigned char key2[64]; memset(key2, 0, sizeof(key2));
|
||||||
|
|
||||||
|
char buf[1024];
|
||||||
|
strncpy(buf, input, sizeof(buf) - 1);
|
||||||
|
buf[sizeof(buf) - 1] = '\0';
|
||||||
|
|
||||||
|
char *pEnd;
|
||||||
|
uint64_t K1 = strtoull(buf, &pEnd, 16);
|
||||||
|
uint64_t K2 = strtoull(pEnd, &pEnd, 16);
|
||||||
|
uint64_t K3 = strtoull(pEnd, &pEnd, 16);
|
||||||
|
uint64_t K4 = strtoull(pEnd, &pEnd, 16);
|
||||||
|
|
||||||
|
if (K3 != 0 || K4 != 0) //256-bit keys loaded as ASCII characters
|
||||||
|
{
|
||||||
|
//start loading K1, K2, K3, and K4 as ASCII to fill 64 bytes of key1
|
||||||
|
int k = 0; uint8_t x = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < 16; i++)
|
||||||
|
{
|
||||||
|
x = ((K1 >> (60-(i*4))) & 0xF);
|
||||||
|
if (x >= 0 && x <= 9) //numbers 0-9
|
||||||
|
x += 0x30; //ASCII representation of numbers is 0x30, 0x31....0x39
|
||||||
|
else x += 0x37; //Upper ASCII A,B,C,D,E,F is 0x41, 0x42...0x46
|
||||||
|
key1[k++] = x;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < 16; i++)
|
||||||
|
{
|
||||||
|
x = ((K2 >> (60-(i*4))) & 0xF);
|
||||||
|
if (x >= 0 && x <= 9) //numbers 0-9
|
||||||
|
x += 0x30; //ASCII representation of numbers is 0x30, 0x31....0x39
|
||||||
|
else x += 0x37; //Upper ASCII A,B,C,D,E,F is 0x41, 0x42...0x46
|
||||||
|
key1[k++] = x;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < 16; i++)
|
||||||
|
{
|
||||||
|
x = ((K3 >> (60-(i*4))) & 0xF);
|
||||||
|
if (x >= 0 && x <= 9) //numbers 0-9
|
||||||
|
x += 0x30; //ASCII representation of numbers is 0x30, 0x31....0x39
|
||||||
|
else x += 0x37; //Upper ASCII A,B,C,D,E,F is 0x41, 0x42...0x46
|
||||||
|
key1[k++] = x;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < 16; i++)
|
||||||
|
{
|
||||||
|
x = ((K4 >> (60-(i*4))) & 0xF);
|
||||||
|
if (x >= 0 && x <= 9) //numbers 0-9
|
||||||
|
x += 0x30; //ASCII representation of numbers is 0x30, 0x31....0x39
|
||||||
|
else x += 0x37; //Upper ASCII A,B,C,D,E,F is 0x41, 0x42...0x46
|
||||||
|
key1[k++] = x;
|
||||||
|
}
|
||||||
|
|
||||||
|
//debug
|
||||||
|
// fprintf (stderr, "ASCII: ");
|
||||||
|
// for (int i = 0; i < 64; i++)
|
||||||
|
// fprintf (stderr, " %02X", key1[i]);
|
||||||
|
// fprintf (stderr, "\n");
|
||||||
|
|
||||||
|
/* Create key schedule */
|
||||||
|
create_keys(&ctx, key1, 64);
|
||||||
|
ctx.rounds = nbround;
|
||||||
|
|
||||||
|
fprintf(stderr, "DMR TYT AP (PC4) 256-bit Key %016llX%016llX%016llX%016llX with Forced Application\n",
|
||||||
|
(unsigned long long)K1, (unsigned long long)K2, (unsigned long long)K3, (unsigned long long)K4);
|
||||||
|
|
||||||
|
state->tyt_ap = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
else //128-bit loaded as reverse bytes
|
||||||
|
{
|
||||||
|
|
||||||
|
u64_to_bytes_be(K1, &key1[0]);
|
||||||
|
u64_to_bytes_be(K2, &key1[8]);
|
||||||
|
|
||||||
|
// reverse load the key bytes into key2
|
||||||
|
for (int i=0;i<16;i++)
|
||||||
|
key2[i] = key1[15-i];
|
||||||
|
|
||||||
|
/* Create key schedule */
|
||||||
|
create_keys(&ctx, key2, 16);
|
||||||
|
ctx.rounds = nbround;
|
||||||
|
|
||||||
|
fprintf (stderr,"DMR TYT AP (PC4) 128-bit Key %016llX%016llX with Forced Application\n",
|
||||||
|
(unsigned long long int)K1, (unsigned long long int)K2);
|
||||||
|
|
||||||
|
state->tyt_ap = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void tyt_ep_aes_keystream_creation(dsd_state * state, char * input)
|
||||||
|
{
|
||||||
|
char buf[1024];
|
||||||
|
strncpy(buf, input, 1023);
|
||||||
|
buf[1023] = '\0';
|
||||||
|
|
||||||
|
char *pEnd;
|
||||||
|
unsigned long long int K1 = strtoull (buf, &pEnd, 16);
|
||||||
|
unsigned long long int K2 = strtoull (pEnd, &pEnd, 16);
|
||||||
|
|
||||||
|
//
|
||||||
|
uint8_t static_key[32];
|
||||||
|
memset(static_key, 0, sizeof(static_key));
|
||||||
|
|
||||||
|
//static key value
|
||||||
|
static_key[0]=0x6e; static_key[1]=0x02; static_key[2]=0x8d; static_key[3]=0x8a;
|
||||||
|
static_key[4]=0xca; static_key[5]=0xeb; static_key[6]=0x9b; static_key[7]=0xbe;
|
||||||
|
static_key[8]=0x42; static_key[9]=0x72; static_key[10]=0xfb; static_key[11]=0x82;
|
||||||
|
static_key[12]=0x64; static_key[13]=0x56; static_key[14]=0x31; static_key[15]=0xfa;
|
||||||
|
|
||||||
|
//the key value provided by user
|
||||||
|
uint8_t user_key[16];
|
||||||
|
memset(user_key, 0, sizeof(user_key));
|
||||||
|
|
||||||
|
//Load user key into array to manipulate
|
||||||
|
for (int i = 0; i < 8; i++)
|
||||||
|
{
|
||||||
|
user_key[i+0] = (K1 >> (56-(i*8))) & 0xFF;
|
||||||
|
user_key[i+8] = (K2 >> (56-(i*8))) & 0xFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t input_register[16];
|
||||||
|
memset(input_register, 0, sizeof(input_register));
|
||||||
|
|
||||||
|
//manipulate user provided key by loading bytes in reverse order into the input_register
|
||||||
|
for (int i = 0; i < 16; i++)
|
||||||
|
input_register[15-i] = user_key[i];
|
||||||
|
|
||||||
|
uint8_t ks_bytes[16];
|
||||||
|
memset(ks_bytes, 0, sizeof(ks_bytes));
|
||||||
|
|
||||||
|
//create keystream
|
||||||
|
aes_ofb_keystream_output(input_register, static_key, ks_bytes, 0, 1);
|
||||||
|
uint8_t ks_bits[128];
|
||||||
|
memset(ks_bits, 0, sizeof(ks_bits));
|
||||||
|
unpack_byte_array_into_bit_array(ks_bytes, ks_bits, 16);
|
||||||
|
|
||||||
|
//load static keystream into ctx.bits since that isn't ever zeroed out
|
||||||
|
for (int i = 0; i < 49; i++)
|
||||||
|
ctx.bits[i] = ks_bits[i];
|
||||||
|
|
||||||
|
fprintf (stderr,"DMR TYT EP (AES-128) Key %016llX%016llX with Forced Application\n", K1, K2);
|
||||||
|
state->tyt_ep = 1;
|
||||||
|
|
||||||
|
}
|
||||||
354
src/dmr_34.c
Normal file
354
src/dmr_34.c
Normal file
@@ -0,0 +1,354 @@
|
|||||||
|
/*-------------------------------------------------------------------------------
|
||||||
|
* dmr_34.c
|
||||||
|
* DMR (and P25) 3/4 Rate Viterbi Trellis Decoder (Improved)
|
||||||
|
*
|
||||||
|
* Code Sourced From: Unknown
|
||||||
|
* No License Provided
|
||||||
|
*
|
||||||
|
* LWVMOBILE
|
||||||
|
* 2026-02 DSD-FME Florida Man Edition
|
||||||
|
*-----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#define INRANGE 8 // Serial input is grouped in 3 bits, each input value ranges 0~7
|
||||||
|
#define INSTATIC 8 // Number of possible states in the state machine, range 0~7
|
||||||
|
#define INDATA 49 // Input 144 bits, grouped into 3-bit units → outputs 48 values (0~15) + one final 0 to determine end state
|
||||||
|
#define INSYMBOL 49 // Number of input symbols
|
||||||
|
#define PATH 64 // For the i-th (48≥i≥2) input, there are 64 branch metrics → 64 possible paths
|
||||||
|
#define SELECTPATH 8 // Among the 64 paths, select the 8 with smallest metrics, then choose the smallest one as final output
|
||||||
|
#define BITELEN 9 //
|
||||||
|
|
||||||
|
/******************************************************************************
|
||||||
|
* Header file includes
|
||||||
|
*******************************************************************************/
|
||||||
|
#include "dsd.h"
|
||||||
|
#include <time.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
/******************************************************************************
|
||||||
|
* Global variable definitions
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
uint8_t interleave[98] = {
|
||||||
|
0, 1, 8, 9, 16, 17, 24, 25, 32, 33, 40, 41, 48, 49, 56, 57, 64, 65, 72, 73, 80, 81, 88, 89, 96, 97,
|
||||||
|
2, 3, 10, 11, 18, 19, 26, 27, 34, 35, 42, 43, 50, 51, 58, 59, 66, 67, 74, 75, 82, 83, 90, 91,
|
||||||
|
4, 5, 12, 13, 20, 21, 28, 29, 36, 37, 44, 45, 52, 53, 60, 61, 68, 69, 76, 77, 84, 85, 92, 93,
|
||||||
|
6, 7, 14, 15, 22, 23, 30, 31, 38, 39, 46, 47, 54, 55, 62, 63, 70, 71, 78, 79, 86, 87, 94, 95};
|
||||||
|
|
||||||
|
static int16_t staticX[INSTATIC][INRANGE] =
|
||||||
|
{
|
||||||
|
{ 1,-3,-3,1,3,-1,-1,3 },
|
||||||
|
{ -3,1,3,-1,-1,3,1,-3 },
|
||||||
|
{ -1,3,3,-1,-3,1,1,-3 },
|
||||||
|
{ 3,-1,-3,1,1,-3,-1,3 },
|
||||||
|
{ -3,1,1,-3,-1,3,3,-1 },
|
||||||
|
{ 1,-3,-1,3,3,-1,-3,1 },
|
||||||
|
{ 3,-1,-1,3,1,-3,-3,1 },
|
||||||
|
{ -1,3,1,-3,-3,1,3,-1 }
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
static int16_t staticY[INSTATIC][INRANGE] =
|
||||||
|
{
|
||||||
|
{ -1,3,-1,3,-3,1,-3,1 },
|
||||||
|
{ -1,3,-3,1,-3,1,-1,3 },
|
||||||
|
{ -1,3,-1,3,-3,1,-3,1 },
|
||||||
|
{ -1,3,-3,1,-3,1,-1,3 },
|
||||||
|
{ -3,1,-3,1,-1,3,-1,3 },
|
||||||
|
{ -3,1,-1,3,-1,3,-3,1 },
|
||||||
|
{ -3,1,-3,1,-1,3,-1,3 },
|
||||||
|
{ -3,1,-1,3,-1,3,-3,1 }
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Convert 0~7 symbols into 3-bit (0/1) bitstream
|
||||||
|
*
|
||||||
|
* @Param [in] psymbol Input decimal symbol values
|
||||||
|
* @Param [in] num Number of input symbols
|
||||||
|
* @Param [out] pbit Output 3-bit stream
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void TriBit(uint16_t *psymbol, uint16_t num, uint16_t *pbit)
|
||||||
|
{
|
||||||
|
int16_t temp, i;
|
||||||
|
for (i = 0; i < num; i++)
|
||||||
|
{
|
||||||
|
temp = psymbol[i];
|
||||||
|
*pbit++ = (temp >> 2) & 0x01;
|
||||||
|
*pbit++ = (temp >> 1) & 0x01;
|
||||||
|
*pbit++ = temp & 0x01;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Organize the decoded 3-bit stream into 16-bit word format for output
|
||||||
|
*
|
||||||
|
* @Param [in] ptriBitDecRslt Input 3-bit decoded bitstream
|
||||||
|
* @Param [out] poutdata Output packed 16-bit words
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void TriBitToShort(uint16_t *ptriBitDecRslt, uint16_t *poutdata)
|
||||||
|
{
|
||||||
|
int16_t i, j, k = 0;
|
||||||
|
uint16_t bitArray[144] = { 0 };
|
||||||
|
memset(poutdata, 0, sizeof(uint16_t) * 9);
|
||||||
|
|
||||||
|
TriBit(ptriBitDecRslt, 48, bitArray);
|
||||||
|
for (i = 0; i < 9; i++)
|
||||||
|
{
|
||||||
|
for (j = 15; j >= 0; j--)
|
||||||
|
{
|
||||||
|
poutdata[i] += bitArray[k++] << j;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Among 8 paths, select the one with the smallest metric and return its index
|
||||||
|
*
|
||||||
|
* @Param [in] pdata Array of 8 path metrics
|
||||||
|
* @return Index of the path with minimum metric
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
uint16_t MinPath(uint16_t *pdata)
|
||||||
|
{
|
||||||
|
uint16_t i, j = 0;
|
||||||
|
uint16_t min = pdata[0]; // Take first value as initial minimum
|
||||||
|
|
||||||
|
for (i = 0; i < SELECTPATH; i++)
|
||||||
|
{
|
||||||
|
if (pdata[i] < min) // If current value is smaller
|
||||||
|
{
|
||||||
|
min = pdata[i]; // Update minimum
|
||||||
|
j = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return j; // Return index of minimum path
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief From 64 paths, select the 8 paths with smallest metrics,
|
||||||
|
* and output corresponding state and input values
|
||||||
|
*
|
||||||
|
* @Param [in] parrary Array of 64 branch metrics
|
||||||
|
* @Param [out] pipath_ed Sorted 8 smallest path metrics
|
||||||
|
* @Param [out] pstate States corresponding to the 8 best paths
|
||||||
|
* @Param [out] pdata Input values corresponding to the 8 best paths
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void PathFunc(uint16_t *parrary, uint16_t *pipath_ed, uint16_t *pstate, uint16_t *pdata)
|
||||||
|
{
|
||||||
|
int16_t i, j, locT = 0, ValT = 0;
|
||||||
|
uint16_t dataT[PATH] = { 0 };
|
||||||
|
|
||||||
|
memcpy(dataT, parrary, sizeof(uint16_t)*PATH);
|
||||||
|
|
||||||
|
for (i = 0; i < INRANGE; i++)
|
||||||
|
{
|
||||||
|
ValT = dataT[0];
|
||||||
|
locT = 0;
|
||||||
|
for (j = 1; j < PATH; j++)
|
||||||
|
{
|
||||||
|
if (dataT[j] < ValT)
|
||||||
|
{
|
||||||
|
ValT = dataT[j];
|
||||||
|
locT = j;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dataT[locT] = 10000;
|
||||||
|
pipath_ed[i] = ValT;
|
||||||
|
pstate[i] = locT / 8; // quotient → state
|
||||||
|
pdata[i] = locT % 8; // remainder → input symbol
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Calculate path metric (Manhattan distance)
|
||||||
|
*
|
||||||
|
* @Param [in] dataAX X-coordinate of received constellation point A
|
||||||
|
* @Param [in] dataBX X-coordinate of reference constellation point B
|
||||||
|
* @Param [in] dataAY Y-coordinate of received constellation point A
|
||||||
|
* @Param [in] dataBY Y-coordinate of reference constellation point B
|
||||||
|
* @return Path metric result
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
uint16_t DistanceCal(int16_t dataAX, int16_t dataBX, int16_t dataAY, int16_t dataBY)
|
||||||
|
{
|
||||||
|
uint16_t DistanceRslt = 0;
|
||||||
|
DistanceRslt = abs(dataAX - dataBX) + abs(dataAY - dataBY);
|
||||||
|
//DistanceRslt = sqrt((dataAX - dataBX)*(dataAX - dataBX) + (dataAY - dataBY)*(dataAY - dataBY));
|
||||||
|
return DistanceRslt;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Convert 2-bit value to constellation symbol (±1, ±3)
|
||||||
|
*
|
||||||
|
* @Param [in] InBit Input 2-bit value (0~3)
|
||||||
|
* @return Constellation symbol value
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
int16_t BitToSymbol(int16_t InBit)
|
||||||
|
{
|
||||||
|
switch (InBit)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
return 1;
|
||||||
|
case 1:
|
||||||
|
return 3;
|
||||||
|
case 2:
|
||||||
|
return -1;
|
||||||
|
case 3:
|
||||||
|
return -3;
|
||||||
|
default:
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Map input symbols (0~15) to constellation points (±1, ±3) in I/Q
|
||||||
|
*
|
||||||
|
* @Param [in] pinstar Input symbol array (0~15)
|
||||||
|
* @Param [in] num Number of symbols
|
||||||
|
* @Param [out] pdataX Output I-channel (X) coordinates
|
||||||
|
* @Param [out] pdataY Output Q-channel (Y) coordinates
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void MapStar(uint16_t *pinstar, uint16_t num, int16_t *pdataX, int16_t *pdataY)
|
||||||
|
{
|
||||||
|
int16_t i, itemp;
|
||||||
|
|
||||||
|
for (i = 0; i < num; i++)
|
||||||
|
{
|
||||||
|
itemp = (pinstar[i] >> 2) & 0x03;
|
||||||
|
*pdataX++ = BitToSymbol(itemp);
|
||||||
|
itemp = pinstar[i] & 0x03;
|
||||||
|
*pdataY++ = BitToSymbol(itemp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Viterbi decoding function — selects the most likely sequence
|
||||||
|
*
|
||||||
|
* @Param [in] pindata Input symbol sequence (values 0~15)
|
||||||
|
* @Param [out] outdata Decoded output (packed 16-bit words)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void Virterbi(uint16_t *pindata, uint16_t outdata[])
|
||||||
|
{
|
||||||
|
int16_t i, p, j = 1;
|
||||||
|
uint16_t lastDistnc[INRANGE] = { 0 }; // Branch metrics for final input (8 values)
|
||||||
|
uint16_t crntDistnc[64] = { 0 }; // All 64 possible branch metrics for current step
|
||||||
|
uint16_t DecodeOut[INDATA][INRANGE] = { {0 }}; // Possible input sequences up to current step (8 survivors)
|
||||||
|
uint16_t DecodeOutEnd[INDATA][INRANGE] = { {0 }}; // Temporary buffer for path history
|
||||||
|
uint16_t exInDistnc[INRANGE] = { 0 }; // 8 survivor path metrics
|
||||||
|
uint16_t triBitDecRslt[INDATA] = { 0 }; // Final decoded 3-bit symbols
|
||||||
|
int16_t starX[INDATA] = { 0 }, starY[INDATA] = { 0 }; // Constellation point coordinates (I/Q)
|
||||||
|
|
||||||
|
uint16_t minDistnc = 0;
|
||||||
|
uint16_t ConstelPData[INRANGE] = { 0 }; // Input symbols leading to next states
|
||||||
|
uint16_t ConstelPState[INSTATIC] = { 0 }; // Survivor states
|
||||||
|
|
||||||
|
MapStar(pindata, INDATA, starX, starY); // Map input symbols to constellation points
|
||||||
|
|
||||||
|
// Branch metrics for the first input symbol (starting from state 0)
|
||||||
|
for (i = 0; i < INRANGE; i++)
|
||||||
|
{
|
||||||
|
ConstelPData[i] = i; // Next state value
|
||||||
|
DecodeOut[0][i] = i; // Possible input symbols from state 0
|
||||||
|
exInDistnc[i] = DistanceCal(starX[0], staticX[0][i], starY[0], staticY[0][i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Compute branch metrics for each subsequent input symbol
|
||||||
|
for (j = 1; j < INDATA - 1; j++) // for each input symbol
|
||||||
|
{
|
||||||
|
for (p = 0; p < INSTATIC; p++) // for each current survivor state
|
||||||
|
{
|
||||||
|
for (i = 0; i < INRANGE; i++) // for each possible input
|
||||||
|
{
|
||||||
|
crntDistnc[p * 8 + i] = DistanceCal(starX[j], staticX[ConstelPData[p]][i], starY[j], staticY[ConstelPData[p]][i]) + exInDistnc[p];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
PathFunc(crntDistnc, exInDistnc, ConstelPState, ConstelPData); // Select 8 best paths
|
||||||
|
|
||||||
|
for (p = 0; p <= j; p++)
|
||||||
|
{
|
||||||
|
for (i = 0; i < INRANGE; i++)
|
||||||
|
{
|
||||||
|
if (p < j)
|
||||||
|
{
|
||||||
|
DecodeOutEnd[p][i] = DecodeOut[p][ConstelPState[i]];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
DecodeOut[p][i] = ConstelPData[i];
|
||||||
|
DecodeOutEnd[p][i] = DecodeOut[p][i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
memcpy(DecodeOut, DecodeOutEnd, j * 8 * sizeof(int16_t));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Final step — force ending in state 0
|
||||||
|
for (i = 0; i < INRANGE; i++)
|
||||||
|
{
|
||||||
|
lastDistnc[i] = DistanceCal(starX[INDATA - 1], staticX[DecodeOut[INDATA - 2][i]][0], starY[INDATA - 1], staticY[DecodeOut[INDATA - 2][i]][0]) + exInDistnc[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
minDistnc = MinPath(lastDistnc); // Find best final path
|
||||||
|
|
||||||
|
for (i = 0; i < INDATA - 1; i++)
|
||||||
|
{
|
||||||
|
triBitDecRslt[i] = DecodeOutEnd[i][minDistnc];
|
||||||
|
}
|
||||||
|
|
||||||
|
TriBitToShort(triBitDecRslt, outdata);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t viterbi_r34 (uint8_t * input, uint8_t * output)
|
||||||
|
{
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
uint32_t irr_err = 0; //irrecoverable errors
|
||||||
|
|
||||||
|
uint8_t deinterleaved_dibits[98];
|
||||||
|
memset (deinterleaved_dibits, 0, sizeof(deinterleaved_dibits));
|
||||||
|
|
||||||
|
//deinterleave our input dibits
|
||||||
|
for (i = 0; i < 98; i++)
|
||||||
|
deinterleaved_dibits[interleave[i]] = input[i];
|
||||||
|
|
||||||
|
//pack the input into nibbles (dibit pairs)
|
||||||
|
uint8_t nibs[49];
|
||||||
|
memset (nibs, 0, sizeof(nibs));
|
||||||
|
|
||||||
|
for (i = 0; i < 49; i++)
|
||||||
|
nibs[i] = (deinterleaved_dibits[i*2+0] << 2) | (deinterleaved_dibits[i*2+1] << 0);
|
||||||
|
|
||||||
|
uint16_t pindata[49]; memset (pindata, 0, sizeof(pindata));
|
||||||
|
uint16_t outdata[18]; memset (outdata, 0, sizeof(outdata));
|
||||||
|
|
||||||
|
for (int i = 0; i < 49; i++)
|
||||||
|
pindata[i] = (uint16_t)nibs[i];
|
||||||
|
|
||||||
|
Virterbi(pindata, outdata);
|
||||||
|
|
||||||
|
int k = 0;
|
||||||
|
for (int i = 0; i < 9; i++)
|
||||||
|
{
|
||||||
|
output[k++] = (outdata[i] >> 8) & 0xFF;
|
||||||
|
output[k++] = (outdata[i] >> 0) & 0xFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
return irr_err; //TODO: Need to pull viterbi metrics from upper functions
|
||||||
|
}
|
||||||
1284
src/dmr_block.c
1284
src/dmr_block.c
File diff suppressed because it is too large
Load Diff
575
src/dmr_bs.c
575
src/dmr_bs.c
@@ -9,13 +9,15 @@
|
|||||||
#include "dsd.h"
|
#include "dsd.h"
|
||||||
#include "dmr_const.h"
|
#include "dmr_const.h"
|
||||||
|
|
||||||
|
// #define PRINT_AMBE72 //enable to view 72-bit AMBE codewords
|
||||||
|
|
||||||
//A subroutine for processing each TDMA frame individually to allow for
|
//A subroutine for processing each TDMA frame individually to allow for
|
||||||
//processing voice and/or data on both BS slots (channels) simultaneously
|
//processing voice and/or data on both BS slots (channels) simultaneously
|
||||||
void dmrBS (dsd_opts * opts, dsd_state * state)
|
void dmrBS (dsd_opts * opts, dsd_state * state)
|
||||||
{
|
{
|
||||||
int i, j, k, l, dibit;
|
char * timestr = NULL;
|
||||||
int *dibit_p;
|
|
||||||
|
|
||||||
|
int i, dibit;
|
||||||
char ambe_fr[4][24];
|
char ambe_fr[4][24];
|
||||||
char ambe_fr2[4][24];
|
char ambe_fr2[4][24];
|
||||||
char ambe_fr3[4][24];
|
char ambe_fr3[4][24];
|
||||||
@@ -25,18 +27,22 @@ void dmrBS (dsd_opts * opts, dsd_state * state)
|
|||||||
char redundancyB[36];
|
char redundancyB[36];
|
||||||
|
|
||||||
//memcpy of ambe_fr for late entry
|
//memcpy of ambe_fr for late entry
|
||||||
char m1[4][24];
|
uint8_t m1[4][24];
|
||||||
char m2[4][24];
|
uint8_t m2[4][24];
|
||||||
char m3[4][24];
|
uint8_t m3[4][24];
|
||||||
|
|
||||||
const int *w, *x, *y, *z;
|
const int *w, *x, *y, *z;
|
||||||
char sync[25];
|
char sync[25];
|
||||||
char syncdata[48];
|
uint8_t syncdata[48];
|
||||||
char EmbeddedSignalling[16];
|
memset (syncdata, 0, sizeof(syncdata));
|
||||||
|
|
||||||
|
uint8_t emb_pdu[16];
|
||||||
|
memset (emb_pdu, 0, sizeof(emb_pdu));
|
||||||
|
|
||||||
uint8_t emb_ok = 0;
|
uint8_t emb_ok = 0;
|
||||||
uint8_t tact_okay = 0;
|
uint8_t tact_okay = 0;
|
||||||
uint8_t cach_err = 0;
|
uint8_t cach_err = 0;
|
||||||
|
UNUSED(cach_err);
|
||||||
|
|
||||||
uint8_t internalslot;
|
uint8_t internalslot;
|
||||||
uint8_t vc1;
|
uint8_t vc1;
|
||||||
@@ -46,28 +52,12 @@ void dmrBS (dsd_opts * opts, dsd_state * state)
|
|||||||
uint8_t cc = 25;
|
uint8_t cc = 25;
|
||||||
uint8_t power = 9; //power and pre-emption indicator
|
uint8_t power = 9; //power and pre-emption indicator
|
||||||
uint8_t lcss = 9;
|
uint8_t lcss = 9;
|
||||||
|
UNUSED2(cc, lcss);
|
||||||
|
|
||||||
//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));
|
||||||
|
|
||||||
//add time to mirror printFrameSync
|
|
||||||
time_t now;
|
|
||||||
char * getTime(void) //get pretty hh:mm:ss timestamp
|
|
||||||
{
|
|
||||||
time_t t = time(NULL);
|
|
||||||
|
|
||||||
char * curr;
|
|
||||||
char * stamp = asctime(localtime( & t));
|
|
||||||
|
|
||||||
curr = strtok(stamp, " ");
|
|
||||||
curr = strtok(NULL, " ");
|
|
||||||
curr = strtok(NULL, " ");
|
|
||||||
curr = strtok(NULL, " ");
|
|
||||||
|
|
||||||
return curr;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Init slot lights
|
//Init slot lights
|
||||||
sprintf (state->slot1light, " slot1 ");
|
sprintf (state->slot1light, " slot1 ");
|
||||||
sprintf (state->slot2light, " slot2 ");
|
sprintf (state->slot2light, " slot2 ");
|
||||||
@@ -75,14 +65,24 @@ void dmrBS (dsd_opts * opts, dsd_state * state)
|
|||||||
//Init the color code status
|
//Init the color code status
|
||||||
state->color_code_ok = 0;
|
state->color_code_ok = 0;
|
||||||
|
|
||||||
vc1 = 2;
|
//if coming from the bootsrap, then the slot will still be assigned the last value
|
||||||
vc2 = 2;
|
//we want to set only that vc value to 2, the other to 7
|
||||||
|
if (state->currentslot == 0)
|
||||||
|
{
|
||||||
|
vc1 = 2;
|
||||||
|
vc2 = 7;
|
||||||
|
}
|
||||||
|
if (state->currentslot == 1)
|
||||||
|
{
|
||||||
|
vc1 = 7;
|
||||||
|
vc2 = 2;
|
||||||
|
}
|
||||||
|
|
||||||
short int loop = 1;
|
short int loop = 1;
|
||||||
short int skipcount = 0;
|
short int skipcount = 0;
|
||||||
|
|
||||||
//cach
|
//cach
|
||||||
char cachdata[25];
|
uint8_t cachdata[25];
|
||||||
int cachInterleave[24] =
|
int cachInterleave[24] =
|
||||||
{0, 7, 8, 9, 1, 10,
|
{0, 7, 8, 9, 1, 10,
|
||||||
11, 12, 2, 13, 14,
|
11, 12, 2, 13, 14,
|
||||||
@@ -96,6 +96,19 @@ void dmrBS (dsd_opts * opts, dsd_state * state)
|
|||||||
//Run Loop while the getting is good
|
//Run Loop while the getting is good
|
||||||
while (loop == 1) {
|
while (loop == 1) {
|
||||||
|
|
||||||
|
if (exitflag == 1)
|
||||||
|
{
|
||||||
|
cleanupAndExit (opts, state);
|
||||||
|
}
|
||||||
|
|
||||||
|
timestr = getTimeC();
|
||||||
|
|
||||||
|
memset (ambe_fr, 0, sizeof(ambe_fr));
|
||||||
|
memset (ambe_fr2, 0, sizeof(ambe_fr2));
|
||||||
|
memset (ambe_fr3, 0, sizeof(ambe_fr3));
|
||||||
|
memset (emb_pdu, 0, sizeof(emb_pdu));
|
||||||
|
memset (syncdata, 0, sizeof(syncdata));
|
||||||
|
|
||||||
internalslot = -1; //reset here so we know if this value is being set properly
|
internalslot = -1; //reset here so we know if this value is being set properly
|
||||||
for(i = 0; i < 12; i++)
|
for(i = 0; i < 12; i++)
|
||||||
{
|
{
|
||||||
@@ -183,19 +196,19 @@ void dmrBS (dsd_opts * opts, dsd_state * state)
|
|||||||
{
|
{
|
||||||
dibit = getDibit(opts, state);
|
dibit = getDibit(opts, state);
|
||||||
state->dmr_stereo_payload[i+66] = dibit;
|
state->dmr_stereo_payload[i+66] = dibit;
|
||||||
sync[i] = (dibit | 1) + 48; //how does this work again?
|
sync[i] = (dibit | 1) + 48; //Sync Burst String as ones and threes
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
//embedded link control
|
//embedded link control
|
||||||
if(internalslot == 0 && vc1 > 1 && vc1 < 7) //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 E, and F
|
||||||
{
|
{
|
||||||
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 < 7) //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 E, and F
|
||||||
{
|
{
|
||||||
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
|
||||||
@@ -204,8 +217,8 @@ void dmrBS (dsd_opts * opts, dsd_state * state)
|
|||||||
}
|
}
|
||||||
sync[24] = 0;
|
sync[24] = 0;
|
||||||
|
|
||||||
for(i = 0; i < 8; i++) EmbeddedSignalling[i] = syncdata[i];
|
for(i = 0; i < 8; i++) emb_pdu[i + 0] = syncdata[i];
|
||||||
for(i = 0; i < 8; i++) EmbeddedSignalling[i + 8] = syncdata[i + 40];
|
for(i = 0; i < 8; i++) emb_pdu[i + 8] = syncdata[i + 40];
|
||||||
|
|
||||||
//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++)
|
||||||
@@ -255,7 +268,7 @@ void dmrBS (dsd_opts * opts, dsd_state * state)
|
|||||||
if ( strcmp (sync, DMR_BS_DATA_SYNC) == 0 )
|
if ( strcmp (sync, DMR_BS_DATA_SYNC) == 0 )
|
||||||
{
|
{
|
||||||
|
|
||||||
fprintf (stderr,"%s ", getTime());
|
fprintf (stderr,"%s ", timestr);
|
||||||
if (internalslot == 0)
|
if (internalslot == 0)
|
||||||
{
|
{
|
||||||
if (opts->inverted_dmr == 0)
|
if (opts->inverted_dmr == 0)
|
||||||
@@ -264,7 +277,7 @@ void dmrBS (dsd_opts * opts, dsd_state * state)
|
|||||||
}
|
}
|
||||||
else fprintf (stderr,"Sync: -DMR ");
|
else fprintf (stderr,"Sync: -DMR ");
|
||||||
|
|
||||||
vc1 = 1;
|
vc1 = 7; //set to 7 so we can see that we should not be on a VC unless a framesync comes in for it first
|
||||||
|
|
||||||
//close MBEout file - slot 1
|
//close MBEout file - slot 1
|
||||||
if (opts->mbe_out_f != NULL) closeMbeOutFile (opts, state);
|
if (opts->mbe_out_f != NULL) closeMbeOutFile (opts, state);
|
||||||
@@ -277,7 +290,7 @@ void dmrBS (dsd_opts * opts, dsd_state * state)
|
|||||||
}
|
}
|
||||||
else fprintf (stderr,"Sync: -DMR ");
|
else fprintf (stderr,"Sync: -DMR ");
|
||||||
|
|
||||||
vc2 = 1;
|
vc2 = 7; //set to 7 so we can see that we should not be on a VC unless a framesync comes in for it first
|
||||||
|
|
||||||
//close MBEout file - slot 2
|
//close MBEout file - slot 2
|
||||||
if (opts->mbe_out_fR != NULL) closeMbeOutFileR (opts, state);
|
if (opts->mbe_out_fR != NULL) closeMbeOutFileR (opts, state);
|
||||||
@@ -288,26 +301,138 @@ void dmrBS (dsd_opts * opts, dsd_state * state)
|
|||||||
goto SKIP;
|
goto SKIP;
|
||||||
}
|
}
|
||||||
|
|
||||||
//only play voice on no data sync
|
//ETSI TS 102 361-1 V2.6.1 Table E.2 and E.4
|
||||||
|
//check for a rc burst with bptc or 34 rate data in it (testing only)
|
||||||
|
// #define RC_TESTING //disable if not in use
|
||||||
|
#ifdef RC_TESTING
|
||||||
|
|
||||||
|
//skip the vc counter, just look at the QR and P/Pi if not voice or data sync pattern
|
||||||
|
if ( (strcmp (sync, DMR_BS_DATA_SYNC) != 0) && (strcmp (sync, DMR_BS_VOICE_SYNC) != 0) )
|
||||||
|
{
|
||||||
|
|
||||||
|
//Golay_20_8_decode FEC for the burst type (SlotType)
|
||||||
|
unsigned char SlotType[20];
|
||||||
|
memset (SlotType, 0, sizeof(SlotType));
|
||||||
|
uint8_t k = 61;
|
||||||
|
for (uint8_t i = 0; i < 5; i++)
|
||||||
|
{
|
||||||
|
SlotType[(i*2)+0] = (state->dmr_stereo_payload[k+0] >> 1) & 1;
|
||||||
|
SlotType[(i*2)+1] = (state->dmr_stereo_payload[k++] >> 0) & 1;
|
||||||
|
}
|
||||||
|
k = 90;
|
||||||
|
for (uint8_t i = 0; i < 5; i++)
|
||||||
|
{
|
||||||
|
SlotType[(i*2)+10] = (state->dmr_stereo_payload[k+0] >> 1) & 1;
|
||||||
|
SlotType[(i*2)+11] = (state->dmr_stereo_payload[k++] >> 0) & 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//if the QR FEC is good, tact/cach FEC is good, and slot type burst FEC is good, and the P/PI bit is on for RC
|
||||||
|
//NOTE: This can still trigger on bad signal when it should be a data sync pattern but signal drops out or
|
||||||
|
//occassionally on p_clear with trunking tuner logic active and partial stale dibits in the buffer
|
||||||
|
if (QR_16_7_6_decode(emb_pdu) && emb_pdu[4] && tact_okay == 1) //during voice test
|
||||||
|
{
|
||||||
|
|
||||||
|
if (Golay_20_8_decode(SlotType))
|
||||||
|
{
|
||||||
|
fprintf (stderr,"%s ", timestr);
|
||||||
|
if (opts->inverted_dmr == 0)
|
||||||
|
fprintf (stderr,"Sync: +RC ");
|
||||||
|
else fprintf (stderr,"Sync: -RC ");
|
||||||
|
|
||||||
|
dmr_data_sync (opts, state);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < 48; i++)
|
||||||
|
state->dmr_embedded_signalling[internalslot][5][i] = syncdata[i];
|
||||||
|
|
||||||
|
dmr_sbrc (opts, state, emb_pdu[4]);
|
||||||
|
|
||||||
|
emb_ok = 1;
|
||||||
|
|
||||||
|
//give an audio cue when this happens (low, high)
|
||||||
|
beeper (opts, state, internalslot, 40, 86, 3);
|
||||||
|
beeper (opts, state, internalslot, 80, 86, 3);
|
||||||
|
|
||||||
|
//put into Event History
|
||||||
|
state->event_history_s[0].Event_History_Items[internalslot].color_pair = 4;
|
||||||
|
watchdog_event_datacall (opts, state, 0, 0, "DMR Reverse Channel P/PI Indicator On (FEC Okay);", internalslot);
|
||||||
|
push_event_history (&state->event_history_s[internalslot]);
|
||||||
|
init_event_history (&state->event_history_s[internalslot], 0, 1);
|
||||||
|
|
||||||
|
if (Golay_20_8_decode(SlotType))
|
||||||
|
{
|
||||||
|
skipcount++;
|
||||||
|
goto SKIP;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
#endif //RC_TESTING
|
||||||
|
|
||||||
|
//check to see if we are expecting a VC at this point vc > 7
|
||||||
|
if (strcmp (sync, DMR_BS_DATA_SYNC) != 0 && internalslot == 0 && vc1 > 6)
|
||||||
|
{
|
||||||
|
fprintf (stderr,"%s ", timestr);
|
||||||
|
|
||||||
|
//simplifying things
|
||||||
|
// char polarity[3];
|
||||||
|
char light[18];
|
||||||
|
|
||||||
|
sprintf (light, "%s", " [SLOT1] slot2 ");
|
||||||
|
fprintf (stderr,"Sync: DMR %s", light);
|
||||||
|
fprintf (stderr, "%s", KCYN);
|
||||||
|
fprintf (stderr, "| Frame Sync Err: %d", vc1);
|
||||||
|
fprintf (stderr, "%s", KNRM);
|
||||||
|
fprintf (stderr, "\n");
|
||||||
|
vc1++;
|
||||||
|
//this should give it enough time to find the next frame sync pattern, if it exists, if not, then trigger a resync
|
||||||
|
if ( vc1 > 13 ) goto END;
|
||||||
|
else goto SKIP;
|
||||||
|
}
|
||||||
|
|
||||||
|
//check to see if we are expecting a VC at this point vc > 7
|
||||||
|
if (strcmp (sync, DMR_BS_DATA_SYNC) != 0 && internalslot == 1 && vc2 > 6)
|
||||||
|
{
|
||||||
|
fprintf (stderr,"%s ", timestr);
|
||||||
|
|
||||||
|
//simplifying things
|
||||||
|
// char polarity[3];
|
||||||
|
char light[18];
|
||||||
|
|
||||||
|
sprintf (light, "%s", " slot1 [SLOT2] ");
|
||||||
|
fprintf (stderr,"Sync: DMR %s", light);
|
||||||
|
fprintf (stderr, "%s", KCYN);
|
||||||
|
fprintf (stderr, "| Frame Sync Err: %d", vc2);
|
||||||
|
fprintf (stderr, "%s", KNRM);
|
||||||
|
fprintf (stderr, "\n");
|
||||||
|
vc2++;
|
||||||
|
//this should give it enough time to find the next frame sync pattern, if it exists, if not, then trigger a resync
|
||||||
|
if ( vc2 > 13 ) goto END;
|
||||||
|
else goto SKIP;
|
||||||
|
}
|
||||||
|
|
||||||
|
//only play voice on no data sync, and VC values are within expected values 1-6
|
||||||
if (strcmp (sync, DMR_BS_DATA_SYNC) != 0) //we already have a tact ecc check, so we won't get here without that, see if there is any other eccs we can run just to make sure
|
if (strcmp (sync, DMR_BS_DATA_SYNC) != 0) //we already have a tact ecc check, so we won't get here without that, see if there is any other eccs we can run just to make sure
|
||||||
{
|
{
|
||||||
|
|
||||||
//check the embedded signalling, if bad at this point, we probably aren't quite in sync
|
//check the embedded signalling, if bad at this point, we probably aren't quite in sync
|
||||||
if(QR_16_7_6_decode(EmbeddedSignalling)) emb_ok = 1;
|
if(QR_16_7_6_decode(emb_pdu)) emb_ok = 1;
|
||||||
else emb_ok = 0;
|
else emb_ok = 0;
|
||||||
|
|
||||||
//disable the goto END; if this causes more problems than fixing on late entry dual voices i.e., lots of forced resyncs
|
//disable the goto END; if this causes more problems than fixing on late entry dual voices i.e., lots of forced resyncs
|
||||||
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)
|
||||||
{
|
{
|
||||||
cc = ((EmbeddedSignalling[0] << 3) + (EmbeddedSignalling[1] << 2) + (EmbeddedSignalling[2] << 1) + EmbeddedSignalling[3]);
|
cc = ((emb_pdu[0] << 3) + (emb_pdu[1] << 2) + (emb_pdu[2] << 1) + emb_pdu[3]);
|
||||||
power = EmbeddedSignalling[4];
|
power = emb_pdu[4];
|
||||||
lcss = ((EmbeddedSignalling[5] << 1) + EmbeddedSignalling[6]);
|
lcss = ((emb_pdu[5] << 1) + emb_pdu[6]);
|
||||||
|
state->dmr_color_code = state->color_code = cc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
skipcount = 0; //reset skip count if processing voice frames
|
skipcount = 0; //reset skip count if processing voice frames
|
||||||
fprintf (stderr,"%s ", getTime());
|
fprintf (stderr,"%s ", timestr);
|
||||||
|
|
||||||
//simplifying things
|
//simplifying things
|
||||||
char polarity[3];
|
char polarity[3];
|
||||||
@@ -331,25 +456,46 @@ void dmrBS (dsd_opts * opts, dsd_state * 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", "-");
|
||||||
|
if (state->dmr_color_code != 16)
|
||||||
fprintf (stderr,"Sync: %sDMR %s| Color Code=%02d | VC%d ", polarity, light, state->dmr_color_code, vc);
|
fprintf (stderr,"Sync: %sDMR %s| Color Code=%02d | VC%d ", polarity, light, state->dmr_color_code, vc);
|
||||||
|
else fprintf (stderr,"Sync: %sDMR %s| Color Code=XX | VC%d ", polarity, light, vc);
|
||||||
|
|
||||||
if (internalslot == 0 && vc1 == 6)
|
if (internalslot == 0 && vc1 == 6)
|
||||||
{
|
{
|
||||||
|
if (state->hota_enc_check && state->forced_alg_id > 1)
|
||||||
|
{
|
||||||
|
state->dmr_so = 0x40;
|
||||||
|
state->payload_algid = state->forced_alg_id;
|
||||||
|
state->payload_keyid = 0xFF;
|
||||||
|
}
|
||||||
|
//this needs to run prior to embedded link control
|
||||||
|
if (state->payload_algid == 0x02)
|
||||||
|
hytera_enhanced_alg_refresh(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
|
//check the single burst/reverse channel opportunity -- moved
|
||||||
dmr_sbrc (opts, state, power);
|
// dmr_sbrc (opts, state, power);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (internalslot == 1 && vc2 == 6)
|
if (internalslot == 1 && vc2 == 6)
|
||||||
{
|
{
|
||||||
|
if (state->hota_enc_check && state->forced_alg_id > 1)
|
||||||
|
{
|
||||||
|
state->dmr_soR = 0x40;
|
||||||
|
state->payload_algidR = state->forced_alg_id;
|
||||||
|
state->payload_keyidR = 0xFF;
|
||||||
|
}
|
||||||
|
//this needs to run prior to embedded link control
|
||||||
|
if (state->payload_algidR == 0x02)
|
||||||
|
hytera_enhanced_alg_refresh(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
|
//check the single burst/reverse channel opportunity -- moved
|
||||||
dmr_sbrc (opts, state, power);
|
// 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
|
||||||
@@ -361,44 +507,81 @@ void dmrBS (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 ( opts->audio_in_type == 5 && internalslot == 0 && state->dmrburstR != 16 ) //(OSS shim)
|
if (state->tyt_bp == 1)
|
||||||
// {
|
|
||||||
// processMbeFrame (opts, state, NULL, ambe_fr, NULL);
|
|
||||||
// processMbeFrame (opts, state, NULL, ambe_fr2, NULL);
|
|
||||||
// processMbeFrame (opts, state, NULL, ambe_fr3, NULL);
|
|
||||||
// }
|
|
||||||
// if ( opts->audio_in_type == 5 && internalslot == 1 && state->dmrburstL != 16 ) //(OSS shim)
|
|
||||||
// {
|
|
||||||
// processMbeFrame (opts, state, NULL, ambe_fr, NULL);
|
|
||||||
// processMbeFrame (opts, state, NULL, ambe_fr2, NULL);
|
|
||||||
// processMbeFrame (opts, state, NULL, ambe_fr3, NULL);
|
|
||||||
// }
|
|
||||||
|
|
||||||
processMbeFrame (opts, state, NULL, ambe_fr, NULL);
|
|
||||||
processMbeFrame (opts, state, NULL, ambe_fr2, NULL);
|
|
||||||
processMbeFrame (opts, state, NULL, ambe_fr3, NULL);
|
|
||||||
|
|
||||||
cach_err = dmr_cach (opts, state, cachdata);
|
|
||||||
fprintf (stderr, "\n");
|
|
||||||
|
|
||||||
// run alg refresh after vc6 ambe processing
|
|
||||||
if (internalslot == 0 && vc1 == 6) dmr_alg_refresh (opts, state);
|
|
||||||
if (internalslot == 1 && vc2 == 6) dmr_alg_refresh (opts, state);
|
|
||||||
|
|
||||||
dmr_late_entry_mi_fragment (opts, state, vc, m1, m2, m3);
|
|
||||||
|
|
||||||
//increment the vc counters
|
|
||||||
if (internalslot == 0) vc1++;
|
|
||||||
if (internalslot == 1) vc2++;
|
|
||||||
|
|
||||||
//update cc amd vc sync time for trunking purposes (particularly Con+)
|
|
||||||
if (opts->p25_is_tuned == 1)
|
|
||||||
{
|
{
|
||||||
state->last_vc_sync_time = time(NULL);
|
tyt16_ambe2_codeword_keystream(state, ambe_fr, 0);
|
||||||
state->last_cc_sync_time = time(NULL);
|
tyt16_ambe2_codeword_keystream(state, ambe_fr2, 1);
|
||||||
|
tyt16_ambe2_codeword_keystream(state, ambe_fr3, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
//'DSP' output to file
|
if (state->csi_ee == 1)
|
||||||
|
{
|
||||||
|
csi72_ambe2_codeword_keystream(state, ambe_fr);
|
||||||
|
csi72_ambe2_codeword_keystream(state, ambe_fr2);
|
||||||
|
csi72_ambe2_codeword_keystream(state, ambe_fr3);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state->vtx256_ekey != 0)
|
||||||
|
{
|
||||||
|
vtx256_ambe2_interleave_inversion(ambe_fr);
|
||||||
|
vtx256_ambe2_interleave_inversion(ambe_fr2);
|
||||||
|
vtx256_ambe2_interleave_inversion(ambe_fr3);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef PRINT_AMBE72
|
||||||
|
ambe2_codeword_print_i(opts, ambe_fr);
|
||||||
|
ambe2_codeword_print_i(opts, ambe_fr2);
|
||||||
|
ambe2_codeword_print_i(opts, ambe_fr3);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
processMbeFrame (opts, state, NULL, ambe_fr, NULL);
|
||||||
|
if(internalslot == 0)
|
||||||
|
{
|
||||||
|
memcpy(state->f_l4[0], state->audio_out_temp_buf, sizeof(state->audio_out_temp_buf));
|
||||||
|
memcpy(state->s_l4[0], state->s_l, sizeof(state->s_l));
|
||||||
|
memcpy(state->s_l4u[0], state->s_lu, sizeof(state->s_lu));
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
memcpy(state->f_r4[0], state->audio_out_temp_bufR, sizeof(state->audio_out_temp_bufR));
|
||||||
|
memcpy(state->s_r4[0], state->s_r, sizeof(state->s_r));
|
||||||
|
memcpy(state->s_r4u[0], state->s_ru, sizeof(state->s_ru));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
processMbeFrame (opts, state, NULL, ambe_fr2, NULL);
|
||||||
|
if(internalslot == 0)
|
||||||
|
{
|
||||||
|
memcpy(state->f_l4[1], state->audio_out_temp_buf, sizeof(state->audio_out_temp_buf));
|
||||||
|
memcpy(state->s_l4[1], state->s_l, sizeof(state->s_l));
|
||||||
|
memcpy(state->s_l4u[1], state->s_lu, sizeof(state->s_lu));
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
memcpy(state->f_r4[1], state->audio_out_temp_bufR, sizeof(state->audio_out_temp_bufR));
|
||||||
|
memcpy(state->s_r4[1], state->s_r, sizeof(state->s_r));
|
||||||
|
memcpy(state->s_r4u[1], state->s_ru, sizeof(state->s_ru));
|
||||||
|
}
|
||||||
|
|
||||||
|
processMbeFrame (opts, state, NULL, ambe_fr3, NULL);
|
||||||
|
if(internalslot == 0)
|
||||||
|
{
|
||||||
|
memcpy(state->f_l4[2], state->audio_out_temp_buf, sizeof(state->audio_out_temp_buf));
|
||||||
|
memcpy(state->s_l4[2], state->s_l, sizeof(state->s_l));
|
||||||
|
memcpy(state->s_l4u[2], state->s_lu, sizeof(state->s_lu));
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
memcpy(state->f_r4[2], state->audio_out_temp_bufR, sizeof(state->audio_out_temp_bufR));
|
||||||
|
memcpy(state->s_r4[2], state->s_r, sizeof(state->s_r));
|
||||||
|
memcpy(state->s_r4u[2], state->s_ru, sizeof(state->s_ru));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//'DSP' output to file -- run before sbrc
|
||||||
if (opts->use_dsp_output == 1)
|
if (opts->use_dsp_output == 1)
|
||||||
{
|
{
|
||||||
FILE * pFile; //file pointer
|
FILE * pFile; //file pointer
|
||||||
@@ -418,6 +601,34 @@ void dmrBS (dsd_opts * opts, dsd_state * state)
|
|||||||
fclose (pFile);
|
fclose (pFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//run sbrc here to look for the late entry key and alg after we observe potential errors in VC6
|
||||||
|
if (internalslot == 0 && vc1 == 6) dmr_sbrc (opts, state, power);
|
||||||
|
if (internalslot == 1 && vc2 == 6) dmr_sbrc (opts, state, power);
|
||||||
|
|
||||||
|
cach_err = dmr_cach (opts, state, cachdata);
|
||||||
|
if (opts->payload == 0) fprintf (stderr, "\n");
|
||||||
|
|
||||||
|
// run alg refresh after vc6 ambe processing
|
||||||
|
if (internalslot == 0 && vc1 == 6) dmr_alg_refresh (opts, state);
|
||||||
|
if (internalslot == 1 && vc2 == 6) dmr_alg_refresh (opts, state);
|
||||||
|
|
||||||
|
if (internalslot == 0 && vc1 == 6) state->static_ks_counter[0] = 0;
|
||||||
|
if (internalslot == 1 && vc2 == 6) state->static_ks_counter[1] = 0;
|
||||||
|
|
||||||
|
if (opts->dmr_le != 2) //if not Hytera Enhanced
|
||||||
|
dmr_late_entry_mi_fragment (opts, state, vc%7, m1, m2, m3);
|
||||||
|
|
||||||
|
//increment the vc counters
|
||||||
|
if (internalslot == 0) vc1++;
|
||||||
|
if (internalslot == 1) vc2++;
|
||||||
|
|
||||||
|
//update cc amd vc sync time for trunking purposes (particularly Con+)
|
||||||
|
if (opts->p25_is_tuned == 1)
|
||||||
|
{
|
||||||
|
state->last_vc_sync_time = time(NULL);
|
||||||
|
state->last_cc_sync_time = time(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
//reset err checks
|
//reset err checks
|
||||||
cach_err = 1;
|
cach_err = 1;
|
||||||
tact_okay = 0;
|
tact_okay = 0;
|
||||||
@@ -435,7 +646,15 @@ void dmrBS (dsd_opts * opts, dsd_state * state)
|
|||||||
}
|
}
|
||||||
|
|
||||||
SKIP:
|
SKIP:
|
||||||
if (skipcount > 2) //after 2 consecutive data frames, drop back to getFrameSync and process with dmr_data_sync
|
|
||||||
|
//both working now, will need support added for ENC audio and no key
|
||||||
|
//NOTE: We want this to play regardless of whether the slot is voice or data, to play silence in one slot and voice in the second, or voices in both
|
||||||
|
if (internalslot == 1 && opts->floating_point == 1 && opts->pulse_digi_rate_out == 8000)
|
||||||
|
playSynthesizedVoiceFS3 (opts, state); //Float Stereo Mix 3v2
|
||||||
|
if (internalslot == 1 && opts->floating_point == 0 && opts->pulse_digi_rate_out == 8000)
|
||||||
|
playSynthesizedVoiceSS3 (opts, state); //Short Stereo Mix 3v2
|
||||||
|
|
||||||
|
if (skipcount > 3) //after 3 onsecutive data frames, drop back to getFrameSync and process with dmr_data_sync (need one more in order to push last voice on slot 2 only voice)
|
||||||
{
|
{
|
||||||
//set tests to all good so we don't get a bogus/redundant voice error
|
//set tests to all good so we don't get a bogus/redundant voice error
|
||||||
cach_err = 0;
|
cach_err = 0;
|
||||||
@@ -450,6 +669,21 @@ void dmrBS (dsd_opts * opts, dsd_state * state)
|
|||||||
ncursesPrinter(opts, state);
|
ncursesPrinter(opts, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//slot 1
|
||||||
|
watchdog_event_history(opts, state, 0);
|
||||||
|
watchdog_event_current(opts, state, 0);
|
||||||
|
|
||||||
|
//slot 2 for TDMA systems
|
||||||
|
watchdog_event_history(opts, state, 1);
|
||||||
|
watchdog_event_current(opts, state, 1);
|
||||||
|
|
||||||
|
//
|
||||||
|
if (timestr != NULL)
|
||||||
|
{
|
||||||
|
free (timestr);
|
||||||
|
timestr = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
} // while loop
|
} // while loop
|
||||||
|
|
||||||
END:
|
END:
|
||||||
@@ -463,11 +697,17 @@ void dmrBS (dsd_opts * opts, dsd_state * state)
|
|||||||
if (opts->mbe_out_f != NULL) closeMbeOutFile (opts, state);
|
if (opts->mbe_out_f != NULL) closeMbeOutFile (opts, state);
|
||||||
if (opts->mbe_out_fR != NULL) closeMbeOutFileR (opts, state);
|
if (opts->mbe_out_fR != NULL) closeMbeOutFileR (opts, state);
|
||||||
|
|
||||||
|
//clear out any stale audio storage buffers
|
||||||
|
memset (state->f_l4, 0.0f, sizeof(state->f_l4));
|
||||||
|
memset (state->f_r4, 0.0f, sizeof(state->f_r4));
|
||||||
|
memset (state->s_l4, 0, sizeof(state->s_l4));
|
||||||
|
memset (state->s_r4, 0, sizeof(state->s_r4));
|
||||||
|
|
||||||
//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)
|
||||||
{
|
{
|
||||||
|
|
||||||
fprintf (stderr,"%s ", getTime());
|
fprintf (stderr,"%s ", timestr);
|
||||||
fprintf (stderr,"Sync: DMR ");
|
fprintf (stderr,"Sync: DMR ");
|
||||||
fprintf (stderr, "%s", KRED);
|
fprintf (stderr, "%s", KRED);
|
||||||
fprintf (stderr, "| VOICE CACH/EMB ERR");
|
fprintf (stderr, "| VOICE CACH/EMB ERR");
|
||||||
@@ -479,64 +719,78 @@ void dmrBS (dsd_opts * opts, dsd_state * state)
|
|||||||
state->currentslot = 0;
|
state->currentslot = 0;
|
||||||
dmr_alg_refresh (opts, state);
|
dmr_alg_refresh (opts, state);
|
||||||
}
|
}
|
||||||
|
else if (state->payload_algid == 0x02)
|
||||||
|
{
|
||||||
|
state->currentslot = 0;
|
||||||
|
hytera_enhanced_alg_refresh(state);
|
||||||
|
dmr_alg_refresh (opts, state);
|
||||||
|
}
|
||||||
if (state->payload_algidR >= 0x21)
|
if (state->payload_algidR >= 0x21)
|
||||||
{
|
{
|
||||||
state->currentslot = 1;
|
state->currentslot = 1;
|
||||||
dmr_alg_refresh (opts, state);
|
dmr_alg_refresh (opts, state);
|
||||||
}
|
}
|
||||||
|
else if (state->payload_algidR == 0x02)
|
||||||
|
{
|
||||||
|
state->currentslot = 1;
|
||||||
|
hytera_enhanced_alg_refresh(state);
|
||||||
|
dmr_alg_refresh (opts, state);
|
||||||
|
}
|
||||||
|
|
||||||
//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
|
||||||
dmr_reset_blocks (opts, state);
|
dmr_reset_blocks (opts, state);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
if (timestr != NULL)
|
||||||
|
{
|
||||||
|
free (timestr);
|
||||||
|
timestr = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
//reset static ks counter
|
||||||
|
state->static_ks_counter[0] = 0;
|
||||||
|
state->static_ks_counter[1] = 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Process buffered half frame and 2nd half and then jump to full BS decoding
|
//Process buffered half frame and 2nd half and then jump to full BS decoding
|
||||||
void dmrBSBootstrap (dsd_opts * opts, dsd_state * state)
|
void dmrBSBootstrap (dsd_opts * opts, dsd_state * state)
|
||||||
{
|
{
|
||||||
int i, j, k, l, dibit;
|
int i, dibit;
|
||||||
int *dibit_p;
|
int *dibit_p;
|
||||||
char ambe_fr[4][24];
|
char ambe_fr[4][24];
|
||||||
char ambe_fr2[4][24];
|
char ambe_fr2[4][24];
|
||||||
char ambe_fr3[4][24];
|
char ambe_fr3[4][24];
|
||||||
|
|
||||||
|
memset (ambe_fr, 0, sizeof(ambe_fr));
|
||||||
|
memset (ambe_fr2, 0, sizeof(ambe_fr2));
|
||||||
|
memset (ambe_fr3, 0, sizeof(ambe_fr3));
|
||||||
|
|
||||||
//memcpy of ambe_fr for late entry
|
//memcpy of ambe_fr for late entry
|
||||||
char m1[4][24];
|
uint8_t m1[4][24];
|
||||||
char m2[4][24];
|
uint8_t m2[4][24];
|
||||||
char m3[4][24];
|
uint8_t m3[4][24];
|
||||||
|
|
||||||
const int *w, *x, *y, *z;
|
const int *w, *x, *y, *z;
|
||||||
char sync[25];
|
char sync[25];
|
||||||
uint8_t tact_okay = 0;
|
uint8_t tact_okay = 0;
|
||||||
uint8_t cach_err = 0;
|
uint8_t cach_err = 0;
|
||||||
uint8_t sync_okay = 1;
|
uint8_t sync_okay = 1;
|
||||||
|
UNUSED(cach_err);
|
||||||
|
|
||||||
uint8_t internalslot;
|
uint8_t internalslot;
|
||||||
|
|
||||||
char cachdata[25];
|
uint8_t cachdata[25];
|
||||||
int cachInterleave[24] =
|
int cachInterleave[24] =
|
||||||
{0, 7, 8, 9, 1, 10,
|
{0, 7, 8, 9, 1, 10,
|
||||||
11, 12, 2, 13, 14,
|
11, 12, 2, 13, 14,
|
||||||
15, 3, 16, 4, 17, 18,
|
15, 3, 16, 4, 17, 18,
|
||||||
19, 5, 20, 21, 22, 6, 23
|
19, 5, 20, 21, 22, 6, 23
|
||||||
};
|
};
|
||||||
//add time to mirror printFrameSync
|
|
||||||
time_t now;
|
|
||||||
char * getTime(void) //get pretty hh:mm:ss timestamp
|
|
||||||
{
|
|
||||||
time_t t = time(NULL);
|
|
||||||
|
|
||||||
char * curr;
|
char * timestr = getTimeC();
|
||||||
char * stamp = asctime(localtime( & t));
|
|
||||||
|
|
||||||
curr = strtok(stamp, " ");
|
|
||||||
curr = strtok(NULL, " ");
|
|
||||||
curr = strtok(NULL, " ");
|
|
||||||
curr = strtok(NULL, " ");
|
|
||||||
|
|
||||||
return curr;
|
|
||||||
}
|
|
||||||
|
|
||||||
//payload buffer
|
//payload buffer
|
||||||
//CACH + First Half Payload + Sync = 12 + 54 + 24
|
//CACH + First Half Payload + Sync = 12 + 54 + 24
|
||||||
@@ -569,6 +823,9 @@ void dmrBSBootstrap (dsd_opts * opts, dsd_state * state)
|
|||||||
|
|
||||||
internalslot = state->currentslot = tact_bits[1];
|
internalslot = state->currentslot = tact_bits[1];
|
||||||
|
|
||||||
|
//reset static ks counter
|
||||||
|
state->static_ks_counter[internalslot] = 0;
|
||||||
|
|
||||||
//Setup for first AMBE Frame
|
//Setup for first AMBE Frame
|
||||||
|
|
||||||
//Interleave Schedule
|
//Interleave Schedule
|
||||||
@@ -685,7 +942,7 @@ void dmrBSBootstrap (dsd_opts * opts, dsd_state * state)
|
|||||||
fclose (pFile);
|
fclose (pFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf (stderr,"%s ", getTime());
|
fprintf (stderr,"%s ", timestr);
|
||||||
char polarity[3];
|
char polarity[3];
|
||||||
char light[18];
|
char light[18];
|
||||||
|
|
||||||
@@ -703,8 +960,9 @@ void dmrBSBootstrap (dsd_opts * opts, dsd_state * 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", "-");
|
||||||
|
if (state->dmr_color_code != 16)
|
||||||
fprintf (stderr,"Sync: %sDMR %s| Color Code=%02d | VC1*", polarity, light, state->dmr_color_code);
|
fprintf (stderr,"Sync: %sDMR %s| Color Code=%02d | VC1*", polarity, light, state->dmr_color_code);
|
||||||
|
else fprintf (stderr,"Sync: %sDMR %s| Color Code=XX | VC1*", polarity, light);
|
||||||
|
|
||||||
dmr_alg_reset (opts, state);
|
dmr_alg_reset (opts, state);
|
||||||
|
|
||||||
@@ -715,26 +973,106 @@ void dmrBSBootstrap (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->tyt_bp == 1)
|
||||||
|
{
|
||||||
|
tyt16_ambe2_codeword_keystream(state, ambe_fr, 0);
|
||||||
|
tyt16_ambe2_codeword_keystream(state, ambe_fr2, 1);
|
||||||
|
tyt16_ambe2_codeword_keystream(state, ambe_fr3, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state->csi_ee == 1)
|
||||||
|
{
|
||||||
|
csi72_ambe2_codeword_keystream(state, ambe_fr);
|
||||||
|
csi72_ambe2_codeword_keystream(state, ambe_fr2);
|
||||||
|
csi72_ambe2_codeword_keystream(state, ambe_fr3);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state->vtx256_ekey != 0)
|
||||||
|
{
|
||||||
|
vtx256_ambe2_interleave_inversion(ambe_fr);
|
||||||
|
vtx256_ambe2_interleave_inversion(ambe_fr2);
|
||||||
|
vtx256_ambe2_interleave_inversion(ambe_fr3);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef PRINT_AMBE72
|
||||||
|
ambe2_codeword_print_i(opts, ambe_fr);
|
||||||
|
ambe2_codeword_print_i(opts, ambe_fr2);
|
||||||
|
ambe2_codeword_print_i(opts, ambe_fr3);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (opts->payload == 1) fprintf (stderr, "\n"); //extra line break necessary here
|
if (opts->payload == 1) fprintf (stderr, "\n"); //extra line break necessary here
|
||||||
|
// processMbeFrame (opts, state, NULL, ambe_fr, NULL);
|
||||||
|
// processMbeFrame (opts, state, NULL, ambe_fr2, NULL);
|
||||||
|
// processMbeFrame (opts, state, NULL, ambe_fr3, NULL);
|
||||||
|
|
||||||
processMbeFrame (opts, state, NULL, ambe_fr, NULL);
|
processMbeFrame (opts, state, NULL, ambe_fr, NULL);
|
||||||
|
if(internalslot == 0)
|
||||||
|
{
|
||||||
|
memcpy(state->f_l4[0], state->audio_out_temp_buf, sizeof(state->audio_out_temp_buf));
|
||||||
|
memcpy(state->s_l4[0], state->s_l, sizeof(state->s_l));
|
||||||
|
memcpy(state->s_l4u[0], state->s_lu, sizeof(state->s_lu));
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
memcpy(state->f_r4[0], state->audio_out_temp_bufR, sizeof(state->audio_out_temp_bufR));
|
||||||
|
memcpy(state->s_r4[0], state->s_r, sizeof(state->s_r));
|
||||||
|
memcpy(state->s_r4u[0], state->s_ru, sizeof(state->s_ru));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
processMbeFrame (opts, state, NULL, ambe_fr2, NULL);
|
processMbeFrame (opts, state, NULL, ambe_fr2, NULL);
|
||||||
|
if(internalslot == 0)
|
||||||
|
{
|
||||||
|
memcpy(state->f_l4[1], state->audio_out_temp_buf, sizeof(state->audio_out_temp_buf));
|
||||||
|
memcpy(state->s_l4[1], state->s_l, sizeof(state->s_l));
|
||||||
|
memcpy(state->s_l4u[1], state->s_lu, sizeof(state->s_lu));
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
memcpy(state->f_r4[1], state->audio_out_temp_bufR, sizeof(state->audio_out_temp_bufR));
|
||||||
|
memcpy(state->s_r4[1], state->s_r, sizeof(state->s_r));
|
||||||
|
memcpy(state->s_r4u[1], state->s_ru, sizeof(state->s_ru));
|
||||||
|
}
|
||||||
|
|
||||||
processMbeFrame (opts, state, NULL, ambe_fr3, NULL);
|
processMbeFrame (opts, state, NULL, ambe_fr3, NULL);
|
||||||
|
if(internalslot == 0)
|
||||||
|
{
|
||||||
|
memcpy(state->f_l4[2], state->audio_out_temp_buf, sizeof(state->audio_out_temp_buf));
|
||||||
|
memcpy(state->s_l4[2], state->s_l, sizeof(state->s_l));
|
||||||
|
memcpy(state->s_l4u[2], state->s_lu, sizeof(state->s_lu));
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
memcpy(state->f_r4[2], state->audio_out_temp_bufR, sizeof(state->audio_out_temp_bufR));
|
||||||
|
memcpy(state->s_r4[2], state->s_r, sizeof(state->s_r));
|
||||||
|
memcpy(state->s_r4u[2], state->s_ru, sizeof(state->s_ru));
|
||||||
|
}
|
||||||
|
|
||||||
//collect the mi fragment
|
//collect the mi fragment
|
||||||
dmr_late_entry_mi_fragment (opts, state, 1, m1, m2, m3);
|
if (opts->dmr_le != 2) //if not Hytera Enhanced
|
||||||
|
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");
|
if (opts->payload == 0) fprintf (stderr, "\n");
|
||||||
|
|
||||||
//update voice sync time for trunking purposes (particularly Con+)
|
//update voice sync time for trunking purposes (particularly Con+)
|
||||||
if (opts->p25_is_tuned == 1) state->last_vc_sync_time = time(NULL);
|
if (opts->p25_is_tuned == 1) state->last_vc_sync_time = time(NULL);
|
||||||
|
|
||||||
|
//NOTE: Only play on slot 1, if slot 0, then it'll play after the next TDMA frame in the BS loop instead
|
||||||
|
if (internalslot == 1 && opts->floating_point == 1 && opts->pulse_digi_rate_out == 8000)
|
||||||
|
playSynthesizedVoiceFS3 (opts, state); //Float Stereo Mix 3v2
|
||||||
|
if (internalslot == 1 && opts->floating_point == 0 && opts->pulse_digi_rate_out == 8000)
|
||||||
|
playSynthesizedVoiceSS3 (opts, state); //Short Stereo Mix 3v2
|
||||||
|
|
||||||
dmrBS (opts, state); //bootstrap into full TDMA frame for BS mode
|
dmrBS (opts, state); //bootstrap into full TDMA frame for BS mode
|
||||||
END:
|
END:
|
||||||
//if we have a tact err, then produce sync pattern/err message
|
//if we have a tact err, then produce sync pattern/err message
|
||||||
if (tact_okay != 1 || sync_okay != 1)
|
if (tact_okay != 1 || sync_okay != 1)
|
||||||
{
|
{
|
||||||
fprintf (stderr,"%s ", getTime());
|
fprintf (stderr,"%s ", timestr);
|
||||||
fprintf (stderr,"Sync: DMR ");
|
fprintf (stderr,"Sync: DMR ");
|
||||||
fprintf (stderr, "%s", KRED);
|
fprintf (stderr, "%s", KRED);
|
||||||
fprintf (stderr, "| VOICE CACH/SYNC ERR");
|
fprintf (stderr, "| VOICE CACH/SYNC ERR");
|
||||||
@@ -746,15 +1084,32 @@ void dmrBSBootstrap (dsd_opts * opts, dsd_state * state)
|
|||||||
state->currentslot = 0;
|
state->currentslot = 0;
|
||||||
dmr_alg_refresh (opts, state);
|
dmr_alg_refresh (opts, state);
|
||||||
}
|
}
|
||||||
|
else if (state->payload_algid == 0x02)
|
||||||
|
{
|
||||||
|
state->currentslot = 0;
|
||||||
|
hytera_enhanced_alg_refresh(state);
|
||||||
|
dmr_alg_refresh (opts, state);
|
||||||
|
}
|
||||||
if (state->payload_algidR >= 0x21)
|
if (state->payload_algidR >= 0x21)
|
||||||
{
|
{
|
||||||
state->currentslot = 1;
|
state->currentslot = 1;
|
||||||
dmr_alg_refresh (opts, state);
|
dmr_alg_refresh (opts, state);
|
||||||
}
|
}
|
||||||
|
else if (state->payload_algidR == 0x02)
|
||||||
|
{
|
||||||
|
state->currentslot = 1;
|
||||||
|
hytera_enhanced_alg_refresh(state);
|
||||||
|
dmr_alg_refresh (opts, state);
|
||||||
|
}
|
||||||
|
|
||||||
//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
|
||||||
dmr_reset_blocks (opts, state);
|
dmr_reset_blocks (opts, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (timestr != NULL)
|
||||||
|
{
|
||||||
|
free (timestr);
|
||||||
|
timestr = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
2179
src/dmr_csbk.c
2179
src/dmr_csbk.c
File diff suppressed because it is too large
Load Diff
@@ -25,14 +25,15 @@ dmr_data_sync (dsd_opts * opts, dsd_state * state)
|
|||||||
int *dibit_p;
|
int *dibit_p;
|
||||||
char sync[25];
|
char sync[25];
|
||||||
char syncdata[48];
|
char syncdata[48];
|
||||||
char cachdata[25];
|
uint8_t cachdata[25];
|
||||||
|
UNUSED(syncdata);
|
||||||
|
|
||||||
char bursttype[5];
|
|
||||||
uint8_t burst;
|
uint8_t burst;
|
||||||
char info[196];
|
char info[196];
|
||||||
unsigned char SlotType[20];
|
unsigned char SlotType[20];
|
||||||
unsigned int SlotTypeOk;
|
unsigned int SlotTypeOk;
|
||||||
uint8_t cach_err = 0;
|
uint8_t cach_err = 0;
|
||||||
|
UNUSED(cach_err);
|
||||||
|
|
||||||
int cachInterleave[24] =
|
int cachInterleave[24] =
|
||||||
{0, 7, 8, 9, 1, 10,
|
{0, 7, 8, 9, 1, 10,
|
||||||
@@ -258,7 +259,6 @@ dmr_data_sync (dsd_opts * opts, dsd_state * state)
|
|||||||
if( Golay_20_8_decode(SlotType) ) SlotTypeOk = 1;
|
if( Golay_20_8_decode(SlotType) ) SlotTypeOk = 1;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SlotTypeOk = -1;
|
|
||||||
SlotTypeOk = 0;
|
SlotTypeOk = 0;
|
||||||
goto END;
|
goto END;
|
||||||
}
|
}
|
||||||
@@ -293,8 +293,8 @@ 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
|
||||||
}
|
}
|
||||||
|
|
||||||
//don't run on MS Reverse Channel Data
|
//
|
||||||
if (state->dmr_ms_rc == 0) dmr_data_burst_handler(opts, state, (uint8_t *)info, burst);
|
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)
|
||||||
@@ -321,31 +321,25 @@ dmr_data_sync (dsd_opts * opts, dsd_state * state)
|
|||||||
skipDibit (opts, state, 12 + 49 + 5);
|
skipDibit (opts, state, 12 + 49 + 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
//if using con+ trunking and last voice observed more than x seconds ago, snap back to con+ cc
|
#define CON_TUNEAWAY //disable if any unlock issues noted on the logic
|
||||||
//con+ voice channels can have extremely long idle periods without properly tearing down
|
|
||||||
|
#ifdef CON_TUNEAWAY
|
||||||
|
//simplified, if IDLE condition, drop cc and vc sync time so when RF channel tears down, we go back much quicker
|
||||||
|
//NOTE: This was adopted, because going back to the CC early and then to be sent back to the channel grant,
|
||||||
|
//only for it to tear down and being sent back to the CC again isn't very efficient for trunk tracking
|
||||||
|
//NOTE: This will still leave the tuner in the 'locked' state when tuning a voice channel grant on the CC,
|
||||||
|
//and will remain locked until a new voice channel grant is received, but its just asthetic, trying to fix it
|
||||||
|
//is too much of a hassle and causes other issues like CC hunting, etc.
|
||||||
if (opts->p25_trunk == 1 && opts->p25_is_tuned == 1 && state->is_con_plus == 1)
|
if (opts->p25_trunk == 1 && opts->p25_is_tuned == 1 && state->is_con_plus == 1)
|
||||||
{
|
{
|
||||||
//bug fixed that caused hopping from CC to VC; decreased to 2 seconds.
|
int clear = 0;
|
||||||
if ( (time(NULL) - state->last_vc_sync_time > 2) )
|
//IF both slots currently signalling IDLE
|
||||||
|
if (state->dmrburstL == 9 && state->dmrburstR == 9) clear = 1;
|
||||||
|
if (clear == 1)
|
||||||
{
|
{
|
||||||
if (opts->use_rigctl == 1) //rigctl tuning
|
state->last_cc_sync_time = 0;
|
||||||
{
|
state->last_vc_sync_time = 0;
|
||||||
if (opts->setmod_bw != 0) SetModulation(opts->rigctl_sockfd, opts->setmod_bw);
|
|
||||||
SetFreq(opts->rigctl_sockfd, state->p25_cc_freq);
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (opts->audio_in_type == 3) //rtl_fm tuning
|
|
||||||
{
|
|
||||||
//UDP command to tune the RTL dongle
|
|
||||||
rtl_udp_tune(opts, state, state->p25_cc_freq);
|
|
||||||
}
|
|
||||||
opts->p25_is_tuned = 0;
|
|
||||||
//zero out vc frequencies
|
|
||||||
state->p25_vc_freq[0] = 0;
|
|
||||||
state->p25_vc_freq[1] = 0;
|
|
||||||
state->last_cc_sync_time = time(NULL);
|
|
||||||
state->is_con_plus = 0; //con+ flag off
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
320
src/dmr_dburst.c
320
src/dmr_dburst.c
@@ -6,14 +6,11 @@
|
|||||||
* Source: https://github.com/LouisErigHerve/dsd/blob/master/src/dmr_sync.c
|
* Source: https://github.com/LouisErigHerve/dsd/blob/master/src/dmr_sync.c
|
||||||
*
|
*
|
||||||
* LWVMOBILE
|
* LWVMOBILE
|
||||||
* 2022-12 DSD-FME Florida Man Edition
|
* 2026-09 DSD-FME Florida Man Edition
|
||||||
*-----------------------------------------------------------------------------*/
|
*-----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
//WIP: Unified Single Block Data - USBD -- TODO: USBD LIP Protocol Handling
|
//TODO: Test USBD LIP Decoder with Real World Samples (if/when available)
|
||||||
//WIP: UDT Header and Blocks (coded - need samples)
|
//TODO: Test UDT NMEA and LIP Decoders with Real World Samples (if/when available)
|
||||||
//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,13 +23,13 @@ void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196
|
|||||||
uint32_t CRCCorrect = 0;
|
uint32_t CRCCorrect = 0;
|
||||||
uint32_t IrrecoverableErrors = 0;
|
uint32_t IrrecoverableErrors = 0;
|
||||||
uint8_t slot = state->currentslot;
|
uint8_t slot = state->currentslot;
|
||||||
uint8_t block = state->data_block_counter[slot];
|
|
||||||
|
|
||||||
//confirmed data
|
//confirmed data
|
||||||
uint8_t dbsn = 0; //data block serial number for confirmed data blocks
|
uint8_t dbsn = 0; //data block serial number for confirmed data blocks
|
||||||
uint8_t blockcounter = 0; //local block count
|
uint8_t blockcounter = 0; //local block count
|
||||||
uint8_t confdatabits[250]; //array to reshuffle conf data block bits into sequence for crc9 check
|
uint8_t confdatabits[250]; //array to reshuffle conf data block bits into sequence for crc9 check
|
||||||
memset (confdatabits, 0, sizeof(confdatabits));
|
memset (confdatabits, 0, sizeof(confdatabits));
|
||||||
|
UNUSED(dbsn);
|
||||||
|
|
||||||
//BPTC 196x96 Specific
|
//BPTC 196x96 Specific
|
||||||
uint8_t BPTCDeInteleavedData[196];
|
uint8_t BPTCDeInteleavedData[196];
|
||||||
@@ -45,16 +42,24 @@ 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;
|
||||||
|
|
||||||
|
memset (BPTCDeInteleavedData, 0, sizeof(BPTCDeInteleavedData));
|
||||||
|
memset (BPTCDmrDataBit, 0, sizeof(BPTCDmrDataBit));
|
||||||
|
memset (BPTCDmrDataByte, 0, sizeof(BPTCDmrDataByte));
|
||||||
|
memset (BptcDataMatrix, 0, sizeof(BptcDataMatrix));
|
||||||
|
memset (LC_DataBit, 0, sizeof(LC_DataBit));
|
||||||
|
memset (LC_DataBytes, 0, sizeof(LC_DataBytes));
|
||||||
|
|
||||||
//PDU Bytes and Bits
|
//PDU Bytes and Bits
|
||||||
uint8_t DMR_PDU[25];
|
uint8_t DMR_PDU[25];
|
||||||
uint8_t DMR_PDU_bits[196];
|
uint8_t DMR_PDU_bits[200];
|
||||||
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 hota_enc = 0;
|
||||||
uint8_t BPTCReservedBits = 0;
|
uint8_t is_ras = 0;
|
||||||
uint8_t is_ras = 0;
|
uint8_t bptc_res_bits[3];
|
||||||
uint8_t crc_original_validity = 0;
|
memset (bptc_res_bits, 0, sizeof(bptc_res_bits));
|
||||||
|
uint8_t crc_original_validity = 0;
|
||||||
|
|
||||||
uint32_t crcmask = 0;
|
uint32_t crcmask = 0;
|
||||||
uint8_t crclen = 0;
|
uint8_t crclen = 0;
|
||||||
@@ -72,6 +77,7 @@ void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196
|
|||||||
|
|
||||||
switch(databurst){
|
switch(databurst){
|
||||||
case 0x00: //PI
|
case 0x00: //PI
|
||||||
|
hota_enc = 1;
|
||||||
is_bptc = 1;
|
is_bptc = 1;
|
||||||
crclen = 16;
|
crclen = 16;
|
||||||
crcmask = 0x6969; //insert pi and 69 jokes here
|
crcmask = 0x6969; //insert pi and 69 jokes here
|
||||||
@@ -79,6 +85,7 @@ void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196
|
|||||||
sprintf(state->fsubtype, " PI ");
|
sprintf(state->fsubtype, " PI ");
|
||||||
break;
|
break;
|
||||||
case 0x01: //VLC
|
case 0x01: //VLC
|
||||||
|
hota_enc = 1;
|
||||||
is_bptc = 1;
|
is_bptc = 1;
|
||||||
is_lc = 1;
|
is_lc = 1;
|
||||||
crclen = 24;
|
crclen = 24;
|
||||||
@@ -87,6 +94,7 @@ void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196
|
|||||||
sprintf(state->fsubtype, " VLC ");
|
sprintf(state->fsubtype, " VLC ");
|
||||||
break;
|
break;
|
||||||
case 0x02: //TLC
|
case 0x02: //TLC
|
||||||
|
hota_enc = 1;
|
||||||
is_bptc = 1;
|
is_bptc = 1;
|
||||||
is_lc = 1;
|
is_lc = 1;
|
||||||
crcmask = 0x999999;
|
crcmask = 0x999999;
|
||||||
@@ -95,6 +103,7 @@ void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196
|
|||||||
sprintf(state->fsubtype, " TLC ");
|
sprintf(state->fsubtype, " TLC ");
|
||||||
break;
|
break;
|
||||||
case 0x03: //CSBK
|
case 0x03: //CSBK
|
||||||
|
hota_enc = 1;
|
||||||
is_bptc = 1;
|
is_bptc = 1;
|
||||||
crclen = 16;
|
crclen = 16;
|
||||||
crcmask = 0xA5A5;
|
crcmask = 0xA5A5;
|
||||||
@@ -102,6 +111,7 @@ void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196
|
|||||||
sprintf(state->fsubtype, " CSBK");
|
sprintf(state->fsubtype, " CSBK");
|
||||||
break;
|
break;
|
||||||
case 0x04: //MBC Header
|
case 0x04: //MBC Header
|
||||||
|
hota_enc = 1;
|
||||||
is_bptc = 1;
|
is_bptc = 1;
|
||||||
crclen = 16;
|
crclen = 16;
|
||||||
crcmask = 0xAAAA;
|
crcmask = 0xAAAA;
|
||||||
@@ -115,6 +125,7 @@ void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196
|
|||||||
sprintf(state->fsubtype, " MBCC");
|
sprintf(state->fsubtype, " MBCC");
|
||||||
break;
|
break;
|
||||||
case 0x06: //Data Header
|
case 0x06: //Data Header
|
||||||
|
hota_enc = 1;
|
||||||
is_bptc = 1;
|
is_bptc = 1;
|
||||||
crclen = 16;
|
crclen = 16;
|
||||||
crcmask = 0xCCCC;
|
crcmask = 0xCCCC;
|
||||||
@@ -136,7 +147,9 @@ void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196
|
|||||||
if (state->data_header_format[slot] == 0) //UDT 1/2 Encoded Blocks
|
if (state->data_header_format[slot] == 0) //UDT 1/2 Encoded Blocks
|
||||||
{
|
{
|
||||||
is_udt = 1;
|
is_udt = 1;
|
||||||
sprintf(state->fsubtype, " UDTC ");
|
if (state->data_conf_data[slot] == 1)
|
||||||
|
sprintf(state->fsubtype, " UDTC "); //confirmed data
|
||||||
|
else sprintf(state->fsubtype, " UDTU "); //unconfirmed data
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 0x08: //3/4 Rate Data
|
case 0x08: //3/4 Rate Data
|
||||||
@@ -160,16 +173,17 @@ void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196
|
|||||||
crclen = 9; //confirmed data only
|
crclen = 9; //confirmed data only
|
||||||
crcmask = 0x10F;
|
crcmask = 0x10F;
|
||||||
is_full = 1;
|
is_full = 1;
|
||||||
pdu_len = 25; //196 bits - 24.5 bytes
|
pdu_len = 24; //192 bits 24 bytes + 4 pad bits
|
||||||
sprintf(state->fsubtype, " R_1U ");
|
sprintf(state->fsubtype, " R_1U ");
|
||||||
if (state->data_conf_data[slot] == 1)
|
if (state->data_conf_data[slot] == 1)
|
||||||
{
|
{
|
||||||
pdu_len = 23;
|
pdu_len = 22; //start at plus two when assembling
|
||||||
pdu_start = 2; //start at plus two when assembling
|
pdu_start = 2; //start at plus two when assembling
|
||||||
sprintf(state->fsubtype, " R_1C ");
|
sprintf(state->fsubtype, " R_1C ");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 0x0B: //Unified Single Block Data USBD
|
case 0x0B: //Unified Single Block Data USBD
|
||||||
|
hota_enc = 1;
|
||||||
is_bptc = 1;
|
is_bptc = 1;
|
||||||
crclen = 16;
|
crclen = 16;
|
||||||
crcmask = 0x3333;
|
crcmask = 0x3333;
|
||||||
@@ -179,6 +193,7 @@ void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196
|
|||||||
|
|
||||||
//special types (not real data 'sync' bursts)
|
//special types (not real data 'sync' bursts)
|
||||||
case 0xEB: //Embedded Signalling
|
case 0xEB: //Embedded Signalling
|
||||||
|
hota_enc = 1;
|
||||||
crclen = 5;
|
crclen = 5;
|
||||||
is_emb = 1;
|
is_emb = 1;
|
||||||
pdu_len = 9;
|
pdu_len = 9;
|
||||||
@@ -200,7 +215,12 @@ void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196
|
|||||||
|
|
||||||
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)
|
||||||
|
{
|
||||||
|
if (state->dmr_color_code != 16)
|
||||||
|
fprintf(stderr, "| Color Code=%02d ", state->dmr_color_code);
|
||||||
|
else fprintf(stderr, "| Color Code=XX ");
|
||||||
|
}
|
||||||
fprintf(stderr, "|%s", state->fsubtype);
|
fprintf(stderr, "|%s", state->fsubtype);
|
||||||
|
|
||||||
//'DSP' output to file
|
//'DSP' output to file
|
||||||
@@ -235,28 +255,41 @@ void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196
|
|||||||
BPTCDeInterleaveDMRData(info, BPTCDeInteleavedData);
|
BPTCDeInterleaveDMRData(info, BPTCDeInteleavedData);
|
||||||
|
|
||||||
/* Extract the BPTC 196,96 DMR data */
|
/* Extract the BPTC 196,96 DMR data */
|
||||||
IrrecoverableErrors = BPTC_196x96_Extract_Data(BPTCDeInteleavedData, BPTCDmrDataBit, R);
|
IrrecoverableErrors = BPTC_196x96_Extract_Data(BPTCDeInteleavedData, BPTCDmrDataBit, bptc_res_bits, &is_ras);
|
||||||
|
|
||||||
/* 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) & 0x04);
|
|
||||||
|
|
||||||
|
#ifdef DEBUG_RAS
|
||||||
//debug print
|
//debug print
|
||||||
//fprintf (stderr, " RAS? %X - %d %d %d", BPTCReservedBits, R[0], R[1], R[2]);
|
if (bptc_res_bits[0] != 0 || bptc_res_bits[1] != 0 || bptc_res_bits[2] != 0)
|
||||||
|
fprintf (stderr, " BPTC R BITS: %d %d %d", bptc_res_bits[0], bptc_res_bits[1], bptc_res_bits[2]);
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Convert the 96 bits BPTC data into 12 bytes */
|
//TODO: Checkdown no irrecoverable errors prior to OTA Decryption?
|
||||||
k = 0;
|
|
||||||
for(i = 0; i < 12; i++)
|
//Hytera OTA Encryption
|
||||||
|
if (state->hota_key_loaded && hota_enc)
|
||||||
|
hytera_ota_decrypt_bptc_96(state, BPTCDmrDataBit, databurst);
|
||||||
|
|
||||||
|
//Hytera Data Block Level Decryption
|
||||||
|
if (databurst == 0x7) //Rate 1_2 Data Only
|
||||||
{
|
{
|
||||||
BPTCDmrDataByte[i] = 0;
|
uint8_t bytes[12];
|
||||||
for(j = 0; j < 8; j++)
|
memset(bytes, 0, sizeof(bytes));
|
||||||
{
|
pack_bit_array_into_byte_array(BPTCDmrDataBit, bytes, 12);
|
||||||
BPTCDmrDataByte[i] = BPTCDmrDataByte[i] << 1;
|
hytera_bp_data_decrypt(state, bytes, 12);
|
||||||
BPTCDmrDataByte[i] = BPTCDmrDataByte[i] | (BPTCDmrDataBit[k] & 0x01);
|
hytera_ep_data_decrypt(opts, state, bytes, 12);
|
||||||
k++;
|
unpack_byte_array_into_bit_array(bytes, BPTCDmrDataBit, 12);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Fill the CRC extracted (before Reed-Solomon (12,9) FEC correction) */
|
/* Convert the 96 bits BPTC data into 12 bytes */
|
||||||
|
pack_bit_array_into_byte_array(BPTCDmrDataBit, BPTCDmrDataByte, 12);
|
||||||
|
|
||||||
|
//make sure the system type isn't Hytera, but could just be bad decodes on bad sample
|
||||||
|
if (IrrecoverableErrors == 0 && BPTCDmrDataByte[1] == 0x68) is_ras = 0;
|
||||||
|
|
||||||
|
//make sure if this is a PI header, the FID is set to 0x10
|
||||||
|
if (IrrecoverableErrors == 0 && databurst == 0x00 && BPTCDmrDataByte[1] != 0x10) is_ras = 0;
|
||||||
|
|
||||||
|
/* Fill the CRC extracted */
|
||||||
CRCExtracted = 0;
|
CRCExtracted = 0;
|
||||||
for(i = 0; i < crclen; i++)
|
for(i = 0; i < crclen; i++)
|
||||||
{
|
{
|
||||||
@@ -268,7 +301,24 @@ void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196
|
|||||||
CRCExtracted = CRCExtracted ^ crcmask;
|
CRCExtracted = CRCExtracted ^ crcmask;
|
||||||
|
|
||||||
/* 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)
|
||||||
|
{
|
||||||
|
if (is_ras)
|
||||||
|
{
|
||||||
|
CRCComputed = ras_mac_calculator(state, BPTCDmrDataByte, 9, 1);
|
||||||
|
if (CRCComputed == CRCExtracted)
|
||||||
|
CRCCorrect = 1;
|
||||||
|
|
||||||
|
#ifdef DEBUG_RAS
|
||||||
|
fprintf (stderr, " EXT: %06X; MAC: %06X;", CRCExtracted, CRCComputed);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
else CRCCorrect = ComputeAndCorrectFullLinkControlCrc(BPTCDmrDataByte, &CRCComputed, crcmask);
|
||||||
|
|
||||||
|
//Hytera OTA Encryption LC Context Creation for VLC Header
|
||||||
|
if (state->hota_key_loaded && CRCCorrect && databurst == 0x01)
|
||||||
|
hytera_create_lc_ctx(state, BPTCDmrDataBit);
|
||||||
|
}
|
||||||
|
|
||||||
//set CRC to correct on unconfirmed 1/2 data blocks (for reporting due to no CRC available on these)
|
//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] == 0 && databurst == 0x7)
|
else if (state->data_conf_data[slot] == 0 && databurst == 0x7)
|
||||||
@@ -304,20 +354,23 @@ void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196
|
|||||||
//run CCITT on other data forms
|
//run CCITT on other data forms
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
CRCComputed = ComputeCrcCCITT(BPTCDmrDataBit);
|
if (is_ras == 1)
|
||||||
|
{
|
||||||
|
CRCComputed = ras_mac_calculator(state, BPTCDmrDataByte, 10, 0);
|
||||||
|
|
||||||
|
#ifdef DEBUG_RAS
|
||||||
|
fprintf (stderr, " EXT: %04X; MAC: %04X;", CRCExtracted, CRCComputed);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
else 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 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 we don't do this, then we can't view some data (CSBKs on RAS enabled systems)
|
||||||
if (is_ras == 1)
|
if (is_ras == 1 && state->ras_effective_key == 0)
|
||||||
{
|
{
|
||||||
crc_original_validity = CRCCorrect;
|
crc_original_validity = CRCCorrect;
|
||||||
CRCCorrect = 1;
|
CRCCorrect = 1;
|
||||||
@@ -333,17 +386,7 @@ void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Convert corrected x bytes into x*8 bits */
|
/* Convert corrected x bytes into x*8 bits */
|
||||||
for(i = 0, j = 0; i < pdu_len; i++, j+=8)
|
unpack_byte_array_into_bit_array(BPTCDmrDataByte, BPTCDmrDataBit, pdu_len);
|
||||||
{
|
|
||||||
BPTCDmrDataBit[j + 0] = (BPTCDmrDataByte[i+pdu_start] >> 7) & 0x01;
|
|
||||||
BPTCDmrDataBit[j + 1] = (BPTCDmrDataByte[i+pdu_start] >> 6) & 0x01;
|
|
||||||
BPTCDmrDataBit[j + 2] = (BPTCDmrDataByte[i+pdu_start] >> 5) & 0x01;
|
|
||||||
BPTCDmrDataBit[j + 3] = (BPTCDmrDataByte[i+pdu_start] >> 4) & 0x01;
|
|
||||||
BPTCDmrDataBit[j + 4] = (BPTCDmrDataByte[i+pdu_start] >> 3) & 0x01;
|
|
||||||
BPTCDmrDataBit[j + 5] = (BPTCDmrDataByte[i+pdu_start] >> 2) & 0x01;
|
|
||||||
BPTCDmrDataBit[j + 6] = (BPTCDmrDataByte[i+pdu_start] >> 1) & 0x01;
|
|
||||||
BPTCDmrDataBit[j + 7] = (BPTCDmrDataByte[i+pdu_start] >> 0) & 0x01;
|
|
||||||
}
|
|
||||||
|
|
||||||
//convert to 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++)
|
||||||
@@ -387,8 +430,42 @@ void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196
|
|||||||
} /* End for(j = 0; j < 8; j++) */
|
} /* End for(j = 0; j < 8; j++) */
|
||||||
} /* End for(i = 0; i < 16; i++) */
|
} /* End for(i = 0; i < 16; i++) */
|
||||||
|
|
||||||
|
//Hytera OTA Encryption
|
||||||
|
// if (state->hota_key_loaded && state->hota_ctx_ok[slot] == 0)
|
||||||
|
// hytera_ota_search_emb_lc(state, BptcDataMatrix); //only run as a debug option
|
||||||
|
if (state->hota_key_loaded && state->hota_ctx_ok[slot] == 1)
|
||||||
|
hytera_ota_decrypt_emb_lc(state, BptcDataMatrix);
|
||||||
|
|
||||||
/* Extract the 72 LC bit (+ 5 CRC bit) of the matrix */
|
/* Extract the 72 LC bit (+ 5 CRC bit) of the matrix */
|
||||||
IrrecoverableErrors = BPTC_128x77_Extract_Data(BptcDataMatrix, LC_DataBit);
|
if (state->hota_key_loaded && state->hota_ctx_ok[slot] == 0)
|
||||||
|
{
|
||||||
|
//just fill with all ones, would be garbage from FEC anyways
|
||||||
|
memset(LC_DataBit, 1, sizeof(LC_DataBit));
|
||||||
|
IrrecoverableErrors = 1;
|
||||||
|
|
||||||
|
//TODO: columns instead of rows to match application of keystream
|
||||||
|
#ifdef DEBUG_HOTA
|
||||||
|
fprintf(stderr, "\n BPTC 128: ");
|
||||||
|
for (int i = 0; i < 8; i++)
|
||||||
|
fprintf (stderr, "%04X", (uint16_t)convert_bits_into_output(BptcDataMatrix[i], 16));
|
||||||
|
fprintf (stderr, "\n");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
else if (state->hota_enc_check == 1)
|
||||||
|
{
|
||||||
|
//just fill with all ones, would be garbage from FEC anyways
|
||||||
|
memset(LC_DataBit, 1, sizeof(LC_DataBit));
|
||||||
|
IrrecoverableErrors = 1;
|
||||||
|
|
||||||
|
//TODO: columns instead of rows to match application of keystream
|
||||||
|
#ifdef DEBUG_HOTA
|
||||||
|
fprintf(stderr, "\n BPTC 128: ");
|
||||||
|
for (int i = 0; i < 8; i++)
|
||||||
|
fprintf (stderr, "%04X", (uint16_t)convert_bits_into_output(BptcDataMatrix[i], 16));
|
||||||
|
fprintf (stderr, "\n");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
else IrrecoverableErrors = BPTC_128x77_Extract_Data(BptcDataMatrix, LC_DataBit);
|
||||||
|
|
||||||
/* Reconstitute the 5 bit CRC */
|
/* Reconstitute the 5 bit CRC */
|
||||||
CRCExtracted = (uint32_t)ConvertBitIntoBytes(&LC_DataBit[72], 5);
|
CRCExtracted = (uint32_t)ConvertBitIntoBytes(&LC_DataBit[72], 5);
|
||||||
@@ -396,6 +473,16 @@ void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196
|
|||||||
/* Compute the 5 bit CRC */
|
/* Compute the 5 bit CRC */
|
||||||
CRCComputed = ComputeCrc5Bit(LC_DataBit);
|
CRCComputed = ComputeCrc5Bit(LC_DataBit);
|
||||||
|
|
||||||
|
//read ahead first two bytes, look for 1X10 or 2X10 pattern
|
||||||
|
uint16_t ras_test = (uint16_t)(ConvertBitIntoBytes(&LC_DataBit[0], 16) & 0x30FF);
|
||||||
|
if ((IrrecoverableErrors == 0) && (ras_test == 0x2010 || ras_test == 0x1010))
|
||||||
|
{
|
||||||
|
is_ras = 1;
|
||||||
|
if (state->ras_effective_key != 0)
|
||||||
|
CRCComputed = ras_mac_calculator(state, LC_DataBit, 9, 2);
|
||||||
|
}
|
||||||
|
else is_ras = 0;
|
||||||
|
|
||||||
if(CRCExtracted == CRCComputed) CRCCorrect = 1;
|
if(CRCExtracted == CRCComputed) CRCCorrect = 1;
|
||||||
else CRCCorrect = 0;
|
else CRCCorrect = 0;
|
||||||
|
|
||||||
@@ -411,34 +498,33 @@ void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//the ugly one
|
//the sexy one
|
||||||
if (is_trellis)
|
if (is_trellis)
|
||||||
{
|
{
|
||||||
CRCExtracted = 0;
|
CRCExtracted = 0;
|
||||||
CRCComputed = 0;
|
CRCComputed = 0;
|
||||||
IrrecoverableErrors = 1;
|
IrrecoverableErrors = 1;
|
||||||
bool trellis_good = TRUE;
|
|
||||||
|
|
||||||
uint8_t tdibits[98];
|
uint8_t tdibits[98];
|
||||||
memset (tdibits, 0, sizeof(tdibits));
|
memset (tdibits, 0, sizeof(tdibits));
|
||||||
|
|
||||||
//reconstitute info bits into reverse ordered dibits for the trellis decoder
|
//reconstitute info bits into dibits for the trellis decoder
|
||||||
for (i = 0; i < 98; i++)
|
for (i = 0; i < 98; i++)
|
||||||
{
|
tdibits[i] = (info[i*2] << 1) | info[i*2+1];
|
||||||
tdibits[97-i] = (info[i*2] << 1) | info[i*2+1];
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned char TrellisReturn[18];
|
uint8_t TrellisReturn[18];
|
||||||
memset (TrellisReturn, 0, sizeof(TrellisReturn));
|
memset (TrellisReturn, 0, sizeof(TrellisReturn));
|
||||||
|
IrrecoverableErrors = viterbi_r34(tdibits, TrellisReturn);
|
||||||
|
|
||||||
trellis_good = CDMRTrellisDecode(tdibits, TrellisReturn);
|
//Hytera Data Block Level Decryption
|
||||||
if (trellis_good == TRUE) IrrecoverableErrors = 0;
|
hytera_bp_data_decrypt(state, TrellisReturn, 18);
|
||||||
// else (fprintf (stderr, " Trellis Failure")); //debug print
|
hytera_ep_data_decrypt(opts, state, TrellisReturn, 18);
|
||||||
|
|
||||||
for (i = 0; i < pdu_len; i++) //18
|
//NOTE: IrrecoverableErrors in this context are a tally of errors from trellis
|
||||||
{
|
//they may have been successfully corrected, the CRC will reveal as much
|
||||||
DMR_PDU[i] = (uint8_t)TrellisReturn[i+pdu_start];
|
|
||||||
}
|
for (i = 0; i < pdu_len; i++)
|
||||||
|
DMR_PDU[i] = TrellisReturn[i+pdu_start];
|
||||||
|
|
||||||
for(i = 0, j = 0; i < 18; i++, j+=8)
|
for(i = 0, j = 0; i < 18; i++, j+=8)
|
||||||
{
|
{
|
||||||
@@ -464,7 +550,6 @@ void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196
|
|||||||
CRCExtracted = CRCExtracted ^ crcmask;
|
CRCExtracted = CRCExtracted ^ crcmask;
|
||||||
|
|
||||||
//reorganize the DMR_PDU_bits array into confdatabits, just for CRC9 check
|
//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 < 128; i++) confdatabits[i] = DMR_PDU_bits[i + 16];
|
||||||
for(i = 0; i < 7; i++) confdatabits[i + 128] = DMR_PDU_bits[i];
|
for(i = 0; i < 7; i++) confdatabits[i + 128] = DMR_PDU_bits[i];
|
||||||
|
|
||||||
@@ -475,10 +560,8 @@ void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196
|
|||||||
state->data_block_crc_valid[slot][blockcounter] = 1;
|
state->data_block_crc_valid[slot][blockcounter] = 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
|
||||||
// IrrecoverableErrors = 9; //set as a shim since the trellis decoder is a pain to fix
|
|
||||||
state->data_block_crc_valid[slot][blockcounter] = 0;
|
state->data_block_crc_valid[slot][blockcounter] = 0;
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -500,18 +583,24 @@ void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196
|
|||||||
|
|
||||||
if (is_full) //Rate 1 Data
|
if (is_full) //Rate 1 Data
|
||||||
{
|
{
|
||||||
|
//assembly (w/ confirmed data) on a working Tier III Tait System
|
||||||
|
|
||||||
CRCExtracted = 0;
|
CRCExtracted = 0;
|
||||||
CRCComputed = 0;
|
CRCComputed = 0;
|
||||||
IrrecoverableErrors = 0; //implicit, since there is no encoding
|
IrrecoverableErrors = 0; //implicit, since there is no encoding
|
||||||
|
|
||||||
for (i = 0; i < 24; i++)
|
//pack rate 1 data for a total of up to 24 bytes, (22 if Confirmed Data)
|
||||||
{
|
//skipping the 4 padding bits located at 96,97,98,99 using the ptr values
|
||||||
DMR_PDU[i] = (uint8_t)ConvertBitIntoBytes(&info[i*8], 8);
|
//as offsets for confirmed data, len, and continue points for packing
|
||||||
}
|
int bit_ptr = pdu_start * 8;
|
||||||
//leftover 4 bits, manual doesn't say which 4 so assuming last 4
|
int byte_ptr = 0;
|
||||||
//pushing last 4 to 25 and shifting it
|
pack_bit_array_into_byte_array (info+bit_ptr, DMR_PDU+byte_ptr, 12-pdu_start);
|
||||||
DMR_PDU[25] = (uint8_t)ConvertBitIntoBytes(&info[192], 4);
|
bit_ptr = 100; byte_ptr = 12-pdu_start;
|
||||||
DMR_PDU[25] = DMR_PDU[25] << 4;
|
pack_bit_array_into_byte_array (info+bit_ptr, DMR_PDU+byte_ptr, 12);
|
||||||
|
|
||||||
|
//Hytera Data Block Level Decryption
|
||||||
|
hytera_bp_data_decrypt(state, DMR_PDU, 24);
|
||||||
|
hytera_ep_data_decrypt(opts, state, DMR_PDU, 24);
|
||||||
|
|
||||||
//set CRC to correct on unconfirmed 1 rate data blocks (for reporting due to no CRC available on these)
|
//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;
|
if (state->data_conf_data[slot] == 0) CRCCorrect = 1;
|
||||||
@@ -525,11 +614,12 @@ void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196
|
|||||||
CRCExtracted = CRCExtracted ^ crcmask;
|
CRCExtracted = CRCExtracted ^ crcmask;
|
||||||
|
|
||||||
//reorganize the info bit array into confdatabits, just for CRC9 check
|
//reorganize the info bit array into confdatabits, just for CRC9 check
|
||||||
//unconfirmed, haven't seen any samples with rate 1 data
|
int k = 0;
|
||||||
for(i = 0; i < 176; i++) confdatabits[i] = info[i + 16];
|
for (i = 16; i < 96; i++) confdatabits[k++] = info[i]; //first half
|
||||||
for(i = 0; i < 7; i++) confdatabits[i + 176] = info[i];
|
for (i = 100; i < 196; i++) confdatabits[k++] = info[i]; //second half
|
||||||
|
for (i = 0; i < 7; i++) confdatabits[k++] = info[i]; //DBSN
|
||||||
|
CRCComputed = ComputeCrc9Bit(confdatabits, k);
|
||||||
|
|
||||||
CRCComputed = ComputeCrc9Bit(confdatabits, 183);
|
|
||||||
if (CRCExtracted == CRCComputed)
|
if (CRCExtracted == CRCComputed)
|
||||||
{
|
{
|
||||||
CRCCorrect = 1;
|
CRCCorrect = 1;
|
||||||
@@ -537,6 +627,9 @@ void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196
|
|||||||
}
|
}
|
||||||
else state->data_block_crc_valid[slot][blockcounter] = 0;
|
else state->data_block_crc_valid[slot][blockcounter] = 0;
|
||||||
|
|
||||||
|
//debug confirmed data values (working now)
|
||||||
|
// fprintf (stderr, " K: %d; DSBN: %d; CRC: %03X / %03X;", k, dbsn, CRCComputed, CRCExtracted);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//copy info to dmr_pdu_bits
|
//copy info to dmr_pdu_bits
|
||||||
@@ -549,9 +642,9 @@ void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196
|
|||||||
if (databurst == 0x00) dmr_pi (opts, state, DMR_PDU, CRCCorrect, IrrecoverableErrors);
|
if (databurst == 0x00) dmr_pi (opts, state, DMR_PDU, CRCCorrect, IrrecoverableErrors);
|
||||||
|
|
||||||
//full link control
|
//full link control
|
||||||
if (databurst == 0x01) dmr_flco (opts, state, DMR_PDU_bits, CRCCorrect, IrrecoverableErrors, 1); //VLC
|
if (databurst == 0x01) dmr_flco (opts, state, DMR_PDU_bits, CRCCorrect, &IrrecoverableErrors, 1); //VLC
|
||||||
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, UDT) - 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, DMR_PDU_bits, CRCCorrect, IrrecoverableErrors);
|
if (databurst == 0x06) dmr_dheader (opts, state, DMR_PDU, DMR_PDU_bits, CRCCorrect, IrrecoverableErrors);
|
||||||
@@ -578,43 +671,41 @@ void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196
|
|||||||
//TODO: provide more robust handling at a later date -- ETSI TS 102 361-4 V1.11.1 (2021-01) 6.6.11.3
|
//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);
|
usbd_st = (uint8_t)ConvertBitIntoBytes(&DMR_PDU_bits[0], 4);
|
||||||
fprintf (stderr, "%s\n", KYEL);
|
fprintf (stderr, "%s\n", KYEL);
|
||||||
fprintf (stderr, " Unified Single Block Data - ");
|
fprintf (stderr, " USBD - ");
|
||||||
if (usbd_st == 0) fprintf (stderr, "Location Information Protocol");
|
if (usbd_st == 0) lip_protocol_decoder (opts, state, DMR_PDU_bits);
|
||||||
else if (usbd_st > 8) fprintf (stderr, "Manufacturer Specific Service %d ", usbd_st);
|
else if (usbd_st > 8) fprintf (stderr, "Manufacturer Specific Service %d ", usbd_st);
|
||||||
else fprintf (stderr, "Reserved %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
|
//set the original CRCCorrect back to its original value if the RAS flag was tripped (if no key value present)
|
||||||
if (is_ras == 1) CRCCorrect = crc_original_validity;
|
if (is_ras == 1 && state->ras_effective_key == 0) 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 && databurst != 0x08 && databurst != 0x09) //&& databurst != 0x05
|
||||||
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, "%s", KRED);
|
||||||
fprintf(stderr, " (FEC ERR)");
|
fprintf(stderr, " (FEC ERR)");
|
||||||
fprintf (stderr, "%s", KNRM);
|
fprintf (stderr, "%s", KNRM);
|
||||||
}
|
}
|
||||||
|
|
||||||
//print whether or not the 'RAS Field' bits are set to indicate RAS enabled (to be verified)
|
//print whether or not the 'RAS Field' bit is set to indicate RAS
|
||||||
if (is_ras == 1)
|
//detected for RAS enabled burst types and disposition if key available
|
||||||
|
if (IrrecoverableErrors == 0 && is_ras == 1 && (is_bptc || is_emb) && databurst != 0x05 && databurst != 0x07)
|
||||||
{
|
{
|
||||||
fprintf (stderr, "%s", KRED);
|
fprintf (stderr, "%s", KRED);
|
||||||
fprintf (stderr, " -RAS ");
|
fprintf (stderr, " {RAS ");
|
||||||
//the value of this field seems to always, or usually, be 4, or just R[2] bit is set
|
if (state->ras_effective_key != 0 && CRCComputed != CRCExtracted)
|
||||||
if (opts->payload == 1) fprintf (stderr, "%X ", BPTCReservedBits);
|
fprintf (stderr, "Fail} ");
|
||||||
|
else if (state->ras_effective_key != 0 && CRCComputed == CRCExtracted)
|
||||||
|
fprintf (stderr, "Okay} ");
|
||||||
|
else if (state->ras_effective_key == 0)
|
||||||
|
fprintf (stderr, "Skip} ");
|
||||||
fprintf (stderr, "%s", KNRM);
|
fprintf (stderr, "%s", KNRM);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//might flicker the terminal on partially enabled systems, may need to find a better placement
|
||||||
|
if (IrrecoverableErrors == 0 && (is_bptc || is_emb) && databurst != 0x05 && databurst != 0x07 && databurst != 0x09)
|
||||||
|
state->dmr_is_ras = is_ras;
|
||||||
|
|
||||||
if (IrrecoverableErrors == 0 && CRCCorrect == 0 && is_ras == 0 && databurst != 0x09 && databurst != 0x05)
|
if (IrrecoverableErrors == 0 && CRCCorrect == 0 && is_ras == 0 && databurst != 0x09 && databurst != 0x05)
|
||||||
{
|
{
|
||||||
fprintf (stderr, "%s", KRED);
|
fprintf (stderr, "%s", KRED);
|
||||||
@@ -630,9 +721,24 @@ void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196
|
|||||||
fprintf (stderr, " DMR PDU Payload ");
|
fprintf (stderr, " DMR PDU Payload ");
|
||||||
for (i = 0; i < pdu_len; i++)
|
for (i = 0; i < pdu_len; i++)
|
||||||
{
|
{
|
||||||
|
#ifdef DEBUG_RAS
|
||||||
|
fprintf (stderr, "%02X", DMR_PDU[i]);
|
||||||
|
#else
|
||||||
fprintf (stderr, "[%02X]", DMR_PDU[i]);
|
fprintf (stderr, "[%02X]", DMR_PDU[i]);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//RAS 5-bit - always same differential
|
||||||
|
//calculation should be 5-bit portion of RAS Effective Key's Last byte & 0x1F
|
||||||
|
//5-bit + CRCComputed % 31 = CRCExtracted
|
||||||
|
#ifdef DEBUG_RAS
|
||||||
|
if (opts->payload == 1 && is_emb && is_ras)
|
||||||
|
{
|
||||||
|
int32_t diff = ((int32_t)CRCExtracted - (int32_t)CRCComputed + 31) % 31;
|
||||||
|
fprintf (stderr, " CRC CMP: %02X EXT: %02X DIFF: %02X", CRCComputed, CRCExtracted, diff);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
//debug print
|
//debug print
|
||||||
// if (dbsn) fprintf (stderr, " SN %X", dbsn);
|
// if (dbsn) fprintf (stderr, " SN %X", dbsn);
|
||||||
// fprintf (stderr, " CRC - EXT %X CMP %X", CRCExtracted, CRCComputed);
|
// fprintf (stderr, " CRC - EXT %X CMP %X", CRCExtracted, CRCComputed);
|
||||||
|
|||||||
1002
src/dmr_flco.c
1002
src/dmr_flco.c
File diff suppressed because it is too large
Load Diff
712
src/dmr_le.c
712
src/dmr_le.c
@@ -8,8 +8,11 @@
|
|||||||
|
|
||||||
#include "dsd.h"
|
#include "dsd.h"
|
||||||
|
|
||||||
|
static unsigned long long int next_iv_32[2] = {0,0};
|
||||||
|
static unsigned long long int next_iv_64[2] = {0,0};
|
||||||
|
|
||||||
//gather ambe_fr mi fragments for processing
|
//gather ambe_fr mi fragments for processing
|
||||||
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, uint8_t ambe_fr[4][24], uint8_t ambe_fr2[4][24], uint8_t ambe_fr3[4][24])
|
||||||
{
|
{
|
||||||
|
|
||||||
uint8_t slot = state->currentslot;
|
uint8_t slot = state->currentslot;
|
||||||
@@ -25,6 +28,8 @@ void dmr_late_entry_mi_fragment (dsd_opts * opts, dsd_state * state, uint8_t vc,
|
|||||||
|
|
||||||
void dmr_late_entry_mi (dsd_opts * opts, dsd_state * state)
|
void dmr_late_entry_mi (dsd_opts * opts, dsd_state * state)
|
||||||
{
|
{
|
||||||
|
UNUSED(opts);
|
||||||
|
|
||||||
uint8_t slot = state->currentslot;
|
uint8_t slot = state->currentslot;
|
||||||
int i, j;
|
int i, j;
|
||||||
int g[3];
|
int g[3];
|
||||||
@@ -35,6 +40,12 @@ void dmr_late_entry_mi (dsd_opts * opts, dsd_state * state)
|
|||||||
uint64_t mi_corrected = 0;
|
uint64_t mi_corrected = 0;
|
||||||
uint64_t go_corrected = 0;
|
uint64_t go_corrected = 0;
|
||||||
|
|
||||||
|
uint8_t mi_bits[36];
|
||||||
|
memset (mi_bits, 0, sizeof(mi_bits));
|
||||||
|
uint8_t mi_crc_cmp = 0;
|
||||||
|
uint8_t mi_crc_ext = 1;
|
||||||
|
uint8_t mi_crc_ok = 0;
|
||||||
|
|
||||||
mi_test = (state->late_entry_mi_fragment[slot][1][0] << 32L) | (state->late_entry_mi_fragment[slot][2][0] << 28) | (state->late_entry_mi_fragment[slot][3][0] << 24) |
|
mi_test = (state->late_entry_mi_fragment[slot][1][0] << 32L) | (state->late_entry_mi_fragment[slot][2][0] << 28) | (state->late_entry_mi_fragment[slot][3][0] << 24) |
|
||||||
(state->late_entry_mi_fragment[slot][1][1] << 20) | (state->late_entry_mi_fragment[slot][2][1] << 16) | (state->late_entry_mi_fragment[slot][3][1] << 12) |
|
(state->late_entry_mi_fragment[slot][1][1] << 20) | (state->late_entry_mi_fragment[slot][2][1] << 16) | (state->late_entry_mi_fragment[slot][3][1] << 12) |
|
||||||
(state->late_entry_mi_fragment[slot][1][2] << 8) | (state->late_entry_mi_fragment[slot][2][2] << 4) | (state->late_entry_mi_fragment[slot][3][2] << 0);
|
(state->late_entry_mi_fragment[slot][1][2] << 8) | (state->late_entry_mi_fragment[slot][2][2] << 4) | (state->late_entry_mi_fragment[slot][3][2] << 0);
|
||||||
@@ -60,53 +71,217 @@ void dmr_late_entry_mi (dsd_opts * opts, dsd_state * state)
|
|||||||
mi_corrected |= mi_go_bits[i];
|
mi_corrected |= mi_go_bits[i];
|
||||||
go_corrected = go_corrected << 1;
|
go_corrected = go_corrected << 1;
|
||||||
go_corrected |= mi_go_bits[i+12];
|
go_corrected |= mi_go_bits[i+12];
|
||||||
|
//manipulate for crc check
|
||||||
|
mi_bits[i+(j*12)] = mi_go_bits[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int mi_final = 0;
|
unsigned long long int mi_final = 0;
|
||||||
mi_final = (mi_corrected >> 4) & 0xFFFFFFFF;
|
mi_final = (mi_corrected >> 4) & 0xFFFFFFFF;
|
||||||
|
|
||||||
|
mi_crc_ext = (uint8_t)ConvertBitIntoBytes(&mi_bits[32], 4);
|
||||||
|
mi_crc_cmp = crc4(mi_bits, 32);
|
||||||
|
if (mi_crc_ext == mi_crc_cmp)
|
||||||
|
mi_crc_ok = 1;
|
||||||
|
|
||||||
|
//debug -- working now
|
||||||
|
// fprintf (stderr, " LE MI: %09llX; CRC EXT: %X; CRC CMP: %X; \n", mi_corrected, mi_crc_ext, mi_crc_cmp);
|
||||||
|
|
||||||
if (g[0] && g[1] && g[2])
|
if (g[0] && g[1] && g[2])
|
||||||
{
|
{
|
||||||
if (slot == 0 && state->payload_algid != 0)
|
|
||||||
|
if (mi_crc_ok == 1 && state->hota_enc_check == 1)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "%s", KCYN);
|
||||||
|
fprintf (stderr, " Slot %d DMRA EP Potential;", slot+1);
|
||||||
|
|
||||||
|
unsigned long long int temp_iv = mi_final;
|
||||||
|
|
||||||
|
//Reverse Potential IV for both 32-bit and 128-bit to show the IV
|
||||||
|
//that may have been carried by the PI header or last superframe
|
||||||
|
uint8_t iv_a[16]; memset(iv_a, 0, sizeof(iv_a));
|
||||||
|
uint8_t iv_d[16]; memset(iv_d, 0, sizeof(iv_d));
|
||||||
|
for (int i = 0; i < 4; i++)
|
||||||
|
{
|
||||||
|
iv_a[i] = (mi_final >> (24-(i*8))) & 0xFF;
|
||||||
|
iv_d[i] = (mi_final >> (24-(i*8))) & 0xFF;
|
||||||
|
}
|
||||||
|
fprintf (stderr, "\n ");
|
||||||
|
reverse_lfsr_32a_to_len(iv_a, 32);
|
||||||
|
fprintf (stderr, " ");
|
||||||
|
reverse_lfsr_32d_to_len(iv_d, 32);
|
||||||
|
fprintf (stderr, "\n");
|
||||||
|
|
||||||
|
if (next_iv_64[slot] != 0 && mi_final == next_iv_64[slot])
|
||||||
|
{
|
||||||
|
//probably safe to assume AES-256 if its DMRA specific
|
||||||
|
fprintf (stderr, " DMRA AES 128-bit IV detected;");
|
||||||
|
state->forced_alg_id = 0x25;
|
||||||
|
if (slot == 0 && state->payload_mi == 0)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "\n");
|
||||||
|
state->payload_mi = mi_final;
|
||||||
|
state->dmr_so = 0x40;
|
||||||
|
LFSR128d(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (slot == 1 && state->payload_miR == 0)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "\n");
|
||||||
|
state->payload_miR = mi_final;
|
||||||
|
state->dmr_soR = 0x40;
|
||||||
|
LFSR128d(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
if (next_iv_32[slot] != 0 && mi_final == next_iv_32[slot])
|
||||||
|
{
|
||||||
|
//only DMRA RC4 uses this tap configuration
|
||||||
|
fprintf (stderr, " DMRA RC4 32-bit IV detected;");
|
||||||
|
state->forced_alg_id = 0x21;
|
||||||
|
if (slot == 0 && state->payload_mi == 0)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "\n");
|
||||||
|
state->payload_mi = mi_final;
|
||||||
|
state->dmr_so = 0x40;
|
||||||
|
LFSR(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (slot == 1 && state->payload_miR == 0)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "\n");
|
||||||
|
state->payload_miR = mi_final;
|
||||||
|
state->dmr_soR = 0x40;
|
||||||
|
LFSR(state);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//AES taps to next embedded value
|
||||||
|
for(int cnt = 0; cnt < 32; cnt++)
|
||||||
|
{
|
||||||
|
unsigned long long int bit = ( (temp_iv >> 31) ^ (temp_iv >> 21) ^ (temp_iv >> 1) ^ (temp_iv >> 0) ) & 0x1;
|
||||||
|
temp_iv = (temp_iv << 1) | bit;
|
||||||
|
}
|
||||||
|
next_iv_64[slot] = temp_iv & 0xFFFFFFFF;
|
||||||
|
|
||||||
|
//RC4 taps to next embedded value
|
||||||
|
temp_iv = mi_final;
|
||||||
|
for(int cnt = 0; cnt < 32; cnt++)
|
||||||
|
{
|
||||||
|
unsigned long long int bit = ( (temp_iv >> 31) ^ (temp_iv >> 3) ^ (temp_iv >> 1) ) & 0x1;
|
||||||
|
temp_iv = (temp_iv << 1) | bit;
|
||||||
|
}
|
||||||
|
next_iv_32[slot] = temp_iv & 0xFFFFFFFF;
|
||||||
|
|
||||||
|
fprintf (stderr, "\n");
|
||||||
|
fprintf (stderr, "%s", KNRM);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (slot == 0 && state->payload_algid != 0 && state->payload_algid != 0x26)
|
||||||
{
|
{
|
||||||
if (state->payload_mi != mi_final)
|
if (state->payload_mi != mi_final)
|
||||||
{
|
{
|
||||||
fprintf (stderr, "%s", KCYN);
|
fprintf (stderr, "%s", KCYN);
|
||||||
fprintf (stderr, " Slot 1 PI/LFSR and Late Entry MI Mismatch - %08X : %08X \n", state->payload_mi, mi_final);
|
fprintf (stderr, " Slot 1 PI/LFSR and Late Entry MI Mismatch - %08llX : %08llX ", state->payload_mi, mi_final);
|
||||||
state->payload_mi = mi_final;
|
if (mi_crc_ok == 1) state->payload_mi = mi_final;
|
||||||
|
if (mi_crc_ok == 1) fprintf (stderr, "(CRC OK)");
|
||||||
|
else fprintf (stderr, "(CRC ERR)");
|
||||||
|
fprintf (stderr, "\n");
|
||||||
fprintf (stderr, "%s", KNRM);
|
fprintf (stderr, "%s", KNRM);
|
||||||
}
|
}
|
||||||
//run afterwards, or le verification won't match up properly
|
|
||||||
if (state->payload_algid != 0x21)
|
//run expansions afterwards, or le verification won't match up properly
|
||||||
|
|
||||||
|
//DES1
|
||||||
|
if (state->payload_algid == 0x22)
|
||||||
{
|
{
|
||||||
LFSR64 (state);
|
LFSR64 (state);
|
||||||
fprintf (stderr, "\n");
|
fprintf (stderr, "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//AES-128 or AES-256
|
||||||
|
if (state->payload_algid == 0x24 || state->payload_algid == 0x25)
|
||||||
|
{
|
||||||
|
LFSR128d (state);
|
||||||
|
fprintf (stderr, "\n");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
if (slot == 1 && state->payload_algidR != 0)
|
if (slot == 1 && state->payload_algidR != 0 && state->payload_algidR != 0x26)
|
||||||
{
|
{
|
||||||
if (state->payload_miR != mi_final)
|
if (state->payload_miR != mi_final)
|
||||||
{
|
{
|
||||||
fprintf (stderr, "%s", KCYN);
|
fprintf (stderr, "%s", KCYN);
|
||||||
fprintf (stderr, " Slot 2 PI/LFSR and Late Entry MI Mismatch - %08X : %08X \n", state->payload_miR, mi_final);
|
fprintf (stderr, " Slot 2 PI/LFSR and Late Entry MI Mismatch - %08llX : %08llX ", state->payload_miR, mi_final);
|
||||||
state->payload_miR = mi_final;
|
if (mi_crc_ok == 1) state->payload_miR = mi_final;
|
||||||
|
if (mi_crc_ok == 1) fprintf (stderr, "(CRC OK)");
|
||||||
|
else fprintf (stderr, "(CRC ERR)");
|
||||||
|
fprintf (stderr, "\n");
|
||||||
fprintf (stderr, "%s", KNRM);
|
fprintf (stderr, "%s", KNRM);
|
||||||
}
|
}
|
||||||
//run afterwards, or le verification won't match up properly
|
|
||||||
if (state->payload_algidR != 0x21)
|
//run expansions afterwards, or le verification won't match up properly
|
||||||
|
|
||||||
|
//DES1
|
||||||
|
if (state->payload_algidR == 0x22)
|
||||||
{
|
{
|
||||||
LFSR64 (state);
|
LFSR64 (state);
|
||||||
fprintf (stderr, "\n");
|
fprintf (stderr, "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//AES-128 or AES-256
|
||||||
|
if (state->payload_algidR == 0x24 || state->payload_algidR == 0x25)
|
||||||
|
{
|
||||||
|
LFSR128d (state);
|
||||||
|
fprintf (stderr, "\n");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//run LFSR even if golay fails
|
||||||
|
else if (slot == 0 && state->payload_algid != 0)
|
||||||
|
{
|
||||||
|
//DES1
|
||||||
|
if (state->payload_algid == 0x22)
|
||||||
|
{
|
||||||
|
LFSR64 (state);
|
||||||
|
fprintf (stderr, "\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
//AES-128 or AES-256
|
||||||
|
if (state->payload_algid == 0x24 || state->payload_algid == 0x25)
|
||||||
|
{
|
||||||
|
LFSR128d (state);
|
||||||
|
fprintf (stderr, "\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (slot == 1 && state->payload_algidR != 0)
|
||||||
|
{
|
||||||
|
//DES1
|
||||||
|
if (state->payload_algidR == 0x22)
|
||||||
|
{
|
||||||
|
LFSR64 (state);
|
||||||
|
fprintf (stderr, "\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
//AES-128 or AES-256
|
||||||
|
if (state->payload_algidR == 0x24 || state->payload_algidR == 0x25)
|
||||||
|
{
|
||||||
|
LFSR128d (state);
|
||||||
|
fprintf (stderr, "\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void dmr_alg_refresh (dsd_opts * opts, dsd_state * state)
|
void dmr_alg_refresh (dsd_opts * opts, dsd_state * state)
|
||||||
{
|
{
|
||||||
|
UNUSED(opts);
|
||||||
|
|
||||||
if (state->currentslot == 0)
|
if (state->currentslot == 0)
|
||||||
{
|
{
|
||||||
state->dropL = 256;
|
state->dropL = 256;
|
||||||
@@ -121,7 +296,54 @@ void dmr_alg_refresh (dsd_opts * opts, dsd_state * state)
|
|||||||
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
|
|
||||||
|
//LFSR64/128 carried out after LE verification in order to keep it from constantly resetting the MI to the previous value
|
||||||
|
|
||||||
|
if (state->payload_algid == 0x02)
|
||||||
|
{
|
||||||
|
state->DMRvcL = 0;
|
||||||
|
//LFSR already calculated, just dump it now
|
||||||
|
fprintf (stderr, "%s", KYEL);
|
||||||
|
fprintf (stderr, " Slot 1");
|
||||||
|
fprintf (stderr, " DMR PI C- ALG ID: %02X; KEY ID: %02X;", state->payload_algid, state->payload_keyid);
|
||||||
|
fprintf (stderr, " MI(40): %010llX;", state->payload_mi);
|
||||||
|
fprintf (stderr, " Hytera Enhanced;");
|
||||||
|
fprintf (stderr, "%s\n", KNRM);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((state->payload_algid & 0xF0) == 0x30) //any kirisun 0x3X alg
|
||||||
|
{
|
||||||
|
uint8_t alg = state->payload_algid;
|
||||||
|
state->DMRvcL = 0;
|
||||||
|
state->payload_mi = kirisun_lfsr(state->payload_mi);
|
||||||
|
fprintf (stderr, "%s", KYEL);
|
||||||
|
fprintf (stderr, " Slot 1");
|
||||||
|
fprintf (stderr, " DMR PI C- ALG ID: %02X; KEY ID: %02X;", alg, state->payload_keyid);
|
||||||
|
fprintf (stderr, " MI(32): %08llX;", state->payload_mi);
|
||||||
|
fprintf (stderr, " Kirisun ");
|
||||||
|
if (alg == 0x31)
|
||||||
|
fprintf (stderr, "Reinforced ");
|
||||||
|
else if (alg == 0x32)
|
||||||
|
fprintf (stderr, "Low ");
|
||||||
|
else if (alg == 0x33)
|
||||||
|
fprintf (stderr, "Middle ");
|
||||||
|
else if (alg == 0x34)
|
||||||
|
fprintf (stderr, "High ");
|
||||||
|
else if (alg == 0x35)
|
||||||
|
fprintf (stderr, "Enhanced ");
|
||||||
|
else if (alg == 0x36)
|
||||||
|
fprintf (stderr, "Advanced ");
|
||||||
|
else if (alg == 0x37)
|
||||||
|
fprintf (stderr, "Universal ");
|
||||||
|
else if (alg == 0x38)
|
||||||
|
fprintf (stderr, "Strengthened ");
|
||||||
|
else if (alg == 0x39)
|
||||||
|
fprintf (stderr, "Top ");
|
||||||
|
else if (alg == 0x3A)
|
||||||
|
fprintf (stderr, "Ultra ");
|
||||||
|
fprintf (stderr, "Encryption;");
|
||||||
|
fprintf (stderr, "%s\n", KNRM);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
if (state->currentslot == 1)
|
if (state->currentslot == 1)
|
||||||
@@ -138,7 +360,54 @@ void dmr_alg_refresh (dsd_opts * opts, dsd_state * state)
|
|||||||
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
|
|
||||||
|
//LFSR64/128 carried out after LE verification in order to keep it from constantly resetting the MI to the previous value
|
||||||
|
|
||||||
|
if (state->payload_algidR == 0x02)
|
||||||
|
{
|
||||||
|
state->DMRvcR = 0;
|
||||||
|
//LFSR already calculated, just dump it now
|
||||||
|
fprintf (stderr, "%s", KYEL);
|
||||||
|
fprintf (stderr, " Slot 2");
|
||||||
|
fprintf (stderr, " DMR PI C- ALG ID: %02X; KEY ID: %02X;", state->payload_algidR, state->payload_keyidR);
|
||||||
|
fprintf (stderr, " MI(40): %010llX;", state->payload_miR);
|
||||||
|
fprintf (stderr, " Hytera Enhanced;");
|
||||||
|
fprintf (stderr, "%s\n", KNRM);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((state->payload_algidR & 0xF0) == 0x30) //any 0x3X alg
|
||||||
|
{
|
||||||
|
uint8_t alg = state->payload_algidR;
|
||||||
|
state->DMRvcR = 0;
|
||||||
|
state->payload_miR = kirisun_lfsr(state->payload_miR);
|
||||||
|
fprintf (stderr, "%s", KYEL);
|
||||||
|
fprintf (stderr, " Slot 2");
|
||||||
|
fprintf (stderr, " DMR PI C- ALG ID: %02X; KEY ID: %02X;", alg, state->payload_keyidR);
|
||||||
|
fprintf (stderr, " MI(32): %08llX;", state->payload_miR);
|
||||||
|
fprintf (stderr, " Kirisun ");
|
||||||
|
if (alg == 0x31)
|
||||||
|
fprintf (stderr, "Reinforced ");
|
||||||
|
else if (alg == 0x32)
|
||||||
|
fprintf (stderr, "Low ");
|
||||||
|
else if (alg == 0x33)
|
||||||
|
fprintf (stderr, "Middle ");
|
||||||
|
else if (alg == 0x34)
|
||||||
|
fprintf (stderr, "High ");
|
||||||
|
else if (alg == 0x35)
|
||||||
|
fprintf (stderr, "Enhanced ");
|
||||||
|
else if (alg == 0x36)
|
||||||
|
fprintf (stderr, "Advanced ");
|
||||||
|
else if (alg == 0x37)
|
||||||
|
fprintf (stderr, "Universal ");
|
||||||
|
else if (alg == 0x38)
|
||||||
|
fprintf (stderr, "Strengthened ");
|
||||||
|
else if (alg == 0x39)
|
||||||
|
fprintf (stderr, "Top ");
|
||||||
|
else if (alg == 0x3A)
|
||||||
|
fprintf (stderr, "Ultra ");
|
||||||
|
fprintf (stderr, "Encryption;");
|
||||||
|
fprintf (stderr, "%s\n", KNRM);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,12 +415,14 @@ void dmr_alg_refresh (dsd_opts * opts, dsd_state * state)
|
|||||||
|
|
||||||
void dmr_alg_reset (dsd_opts * opts, dsd_state * state)
|
void dmr_alg_reset (dsd_opts * opts, dsd_state * state)
|
||||||
{
|
{
|
||||||
|
UNUSED(opts);
|
||||||
|
|
||||||
state->dropL = 256;
|
state->dropL = 256;
|
||||||
state->dropR = 256;
|
state->dropR = 256;
|
||||||
state->DMRvcL = 0;
|
state->DMRvcL = 0;
|
||||||
state->DMRvcR = 0;
|
state->DMRvcR = 0;
|
||||||
state->payload_miP = 0;
|
// state->payload_miP = 0; //running these clears out before we can create a new keystream
|
||||||
state->payload_miN = 0;
|
// state->payload_miN = 0; //running these clears out before we can create a new keystream
|
||||||
}
|
}
|
||||||
|
|
||||||
//handle Single Burst (Voice Burst F) or Reverse Channel Signalling
|
//handle Single Burst (Voice Burst F) or Reverse Channel Signalling
|
||||||
@@ -161,19 +432,38 @@ void dmr_sbrc (dsd_opts * opts, dsd_state * state, uint8_t power)
|
|||||||
uint8_t slot = state->currentslot;
|
uint8_t slot = state->currentslot;
|
||||||
uint8_t sbrc_interleaved[32];
|
uint8_t sbrc_interleaved[32];
|
||||||
uint8_t sbrc_return[32];
|
uint8_t sbrc_return[32];
|
||||||
|
uint8_t sbrc_retcrc[32]; //crc significant bits of the return for SB
|
||||||
memset (sbrc_interleaved, 0, sizeof(sbrc_interleaved));
|
memset (sbrc_interleaved, 0, sizeof(sbrc_interleaved));
|
||||||
memset (sbrc_return, 0, sizeof(sbrc_return));
|
memset (sbrc_return, 0, sizeof(sbrc_return));
|
||||||
|
memset (sbrc_retcrc, 0, sizeof(sbrc_retcrc));
|
||||||
uint32_t irr_err = 0;
|
uint32_t irr_err = 0;
|
||||||
uint32_t sbrc_hex = 0;
|
uint32_t sbrc_hex = 0;
|
||||||
uint16_t crc_extracted = 7777;
|
uint16_t crc_extracted = 7777;
|
||||||
uint16_t crc_computed = 9999;
|
uint16_t crc_computed = 9999;
|
||||||
uint8_t crc_okay = 0;
|
uint8_t crc7_okay = 0; //RC
|
||||||
|
uint8_t crc3_okay = 0; //TXI
|
||||||
|
uint8_t txi = 0; //SEE: https://patents.google.com/patent/US8271009B2
|
||||||
|
UNUSED(txi);
|
||||||
|
|
||||||
|
//NOTE: Any previous mentions to Cap+ in this area may have been in error,
|
||||||
|
//The signalling observed here was actually TXI information, not Cap+ Specifically
|
||||||
|
|
||||||
|
//check to see if this a TXI system
|
||||||
|
if (slot == 0 && state->dmr_so & 0x20) txi = 1;
|
||||||
|
if (slot == 1 && state->dmr_soR & 0x20) txi = 1;
|
||||||
|
|
||||||
// 9.3.2 Pre-emption and power control Indicator (PI)
|
// 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
|
// 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
|
// 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];
|
for(i = 0; i < 32; i++) sbrc_interleaved[i] = state->dmr_embedded_signalling[slot][5][i + 8];
|
||||||
|
|
||||||
|
//decrypt for Hytera OTA Encryption w/ loaded key
|
||||||
|
if (state->hota_key_loaded && state->hota_sbrc_idx1[state->currentslot] == -1)
|
||||||
|
hytera_ota_search_sb_rc(state, sbrc_interleaved, power);
|
||||||
|
if (state->hota_key_loaded)
|
||||||
|
hytera_ota_decrypt_sb_rc(state, sbrc_interleaved);
|
||||||
|
|
||||||
//power == 0 should be single burst
|
//power == 0 should be single burst
|
||||||
if (power == 0) irr_err = BPTC_16x2_Extract_Data(sbrc_interleaved, sbrc_return, 0);
|
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
|
//power == 1 should be reverse channel -- still need to check the interleave inside of BPTC
|
||||||
@@ -181,9 +471,41 @@ void dmr_sbrc (dsd_opts * opts, dsd_state * state, uint8_t power)
|
|||||||
//bad emb burst, never set a valid power indicator value (probably 9)
|
//bad emb burst, never set a valid power indicator value (probably 9)
|
||||||
if (power > 1) goto SBRC_END;
|
if (power > 1) goto SBRC_END;
|
||||||
|
|
||||||
|
//Hytera OTA
|
||||||
|
if (irr_err && state->hota_key_loaded && state->hota_sbrc_idx2[state->currentslot] == -1)
|
||||||
|
{
|
||||||
|
state->hota_sbrc_idx1[state->currentslot] = -1;
|
||||||
|
state->hota_sbrc_idx2[state->currentslot] = -1;
|
||||||
|
fprintf (stderr, "%s \n", KRED);
|
||||||
|
fprintf (stderr, " SLOT %d ", slot+1);
|
||||||
|
fprintf (stderr, "SB_RC Missing IDX; Encrypted;");
|
||||||
|
fprintf (stderr, "%s\n", KNRM);
|
||||||
|
goto SBRC_END;
|
||||||
|
}
|
||||||
|
else if (irr_err && state->hota_key_loaded && state->hota_sbrc_idx2[state->currentslot] != -1)
|
||||||
|
{
|
||||||
|
state->hota_sbrc_idx1[state->currentslot] = -1;
|
||||||
|
state->hota_sbrc_idx2[state->currentslot] = -1;
|
||||||
|
fprintf (stderr, "%s \n", KRED);
|
||||||
|
fprintf (stderr, " SLOT %d ", slot+1);
|
||||||
|
fprintf (stderr, "SB_RC Incorrect IDX or FEC Errors; Encrypted;");
|
||||||
|
fprintf (stderr, "%s\n", KNRM);
|
||||||
|
goto SBRC_END;
|
||||||
|
}
|
||||||
|
else if (state->hota_enc_check)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "%s \n", KRED);
|
||||||
|
fprintf (stderr, " SLOT %d ", slot+1);
|
||||||
|
fprintf (stderr, "SB_RC Encrypted;");
|
||||||
|
fprintf (stderr, "%s\n", KNRM);
|
||||||
|
goto SBRC_END;
|
||||||
|
}
|
||||||
|
|
||||||
|
//arrange the return for proper order for the crc3 check
|
||||||
|
for (i = 0; i < 8; i++) sbrc_retcrc[i] = sbrc_return[i+3];
|
||||||
|
|
||||||
//RC Channel CRC 7 Mask = 0x7A; CRC bits are used as privacy indicators on
|
//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
|
//Single Voice Burst F (see below), other moto values seem to exist there as well -- See TXI patent
|
||||||
//unknown what the other values are (see Cap+ 0x313 and 0x643)
|
|
||||||
if (power == 1) //RC
|
if (power == 1) //RC
|
||||||
{
|
{
|
||||||
crc_extracted = 0;
|
crc_extracted = 0;
|
||||||
@@ -193,120 +515,253 @@ void dmr_sbrc (dsd_opts * opts, dsd_state * state, uint8_t power)
|
|||||||
crc_extracted = crc_extracted | sbrc_return[i+4];
|
crc_extracted = crc_extracted | sbrc_return[i+4];
|
||||||
}
|
}
|
||||||
crc_extracted = crc_extracted ^ 0x7A;
|
crc_extracted = crc_extracted ^ 0x7A;
|
||||||
crc_computed = crc7((uint8_t *) sbrc_return, 11);
|
crc_computed = crc7((uint8_t *) sbrc_return, 4); //#187 fix
|
||||||
if (crc_extracted == crc_computed) crc_okay = 1;
|
if (crc_extracted == crc_computed) crc7_okay = 1;
|
||||||
}
|
}
|
||||||
else crc_okay = 1; //SB
|
else //if (txi == 1) //if TXI -- but TXI systems also carry the non-crc protected ENC identifiers
|
||||||
|
|
||||||
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);
|
crc_extracted = 0;
|
||||||
|
for (i = 0; i < 3; i++)
|
||||||
|
{
|
||||||
|
crc_extracted = crc_extracted << 1;
|
||||||
|
crc_extracted = crc_extracted | sbrc_return[i]; //first 3 most significant bits
|
||||||
|
}
|
||||||
|
crc_computed = crc3((uint8_t *) sbrc_retcrc, 8); //working now seems consistent as well
|
||||||
|
if (crc_extracted == crc_computed) crc3_okay = 1;
|
||||||
|
// fprintf (stderr, " CRC EXT %02X, CRC CMP %02X", crc_extracted, crc_computed);
|
||||||
|
}
|
||||||
|
// else //crc_okay = 0; //CRC invalid / not available when is ENC Identifiers (I really hate that)
|
||||||
|
|
||||||
|
for(i = 0; i < 11; i++)
|
||||||
|
{
|
||||||
|
sbrc_hex = sbrc_hex << 1;
|
||||||
|
sbrc_hex |= sbrc_return[i] & 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (opts->payload == 1) //hide the sb/rc behind the payload printer, won't be useful to most people
|
||||||
|
{
|
||||||
|
fprintf (stderr, "%s", KCYN);
|
||||||
if (power == 0) fprintf (stderr, " SB: ");
|
if (power == 0) fprintf (stderr, " SB: ");
|
||||||
if (power == 1) fprintf (stderr, " RC: ");
|
if (power == 1) fprintf (stderr, " RC: ");
|
||||||
for(i = 0; i < 11; i++)
|
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, "%d", sbrc_return[i]);
|
||||||
}
|
fprintf (stderr, " - %03X; ", sbrc_hex);
|
||||||
fprintf (stderr, " - %03X", sbrc_hex);
|
|
||||||
fprintf (stderr, "%s", KNRM);
|
fprintf (stderr, "%s", KNRM);
|
||||||
|
|
||||||
if (crc_okay == 0)
|
// if (crc_okay == 0) //forego this since the crc can vary or not be used at all
|
||||||
|
// {
|
||||||
|
// fprintf (stderr, "%s", KRED);
|
||||||
|
// fprintf (stderr, " (CRC ERR)");
|
||||||
|
// fprintf (stderr, "%s", KNRM);
|
||||||
|
// fprintf (stderr, " CRC EXT %02X, CRC CMP %02X", crc_extracted, crc_computed);
|
||||||
|
// }
|
||||||
|
|
||||||
|
fprintf (stderr, "\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t sbrc_opcode = sbrc_hex & 0x7; //opcode and alg the same bits, but the alg is present when CRC is bad (I know they are limited on bits, but I hate that idea)
|
||||||
|
uint8_t alg = sbrc_hex & 0x7; //SEE: https://patents.google.com/patent/EP2347540B1/en
|
||||||
|
uint8_t key = (sbrc_hex >> 3) & 0xFF;
|
||||||
|
uint8_t txi_delay = (sbrc_hex >> 3) & 0x1F; //middle five are the 'delay' value on a TXI system
|
||||||
|
|
||||||
|
//Note: AES-256 Key 1 will pass a CRC3 due to its bit arrangement vs the CRC poly 1101
|
||||||
|
// if (irr_err == 0 && sbrc_hex = 0xD) crc3_okay = 0; //SB: 00000001101
|
||||||
|
|
||||||
|
//NOTE: on above, I belive that we need to check by opcode as well, as a CRC3 can have multiple collisions
|
||||||
|
//so we need to exclude op/alg 0 and 3 from the check (does algID 0x03/0x23 even exist?)
|
||||||
|
|
||||||
|
//Kirisun
|
||||||
|
if (opts->dmr_le == 3)
|
||||||
|
{
|
||||||
|
if (irr_err != 0)
|
||||||
{
|
{
|
||||||
fprintf (stderr, "%s", KRED);
|
uint32_t sbrcpl = 0;
|
||||||
fprintf (stderr, " (CRC ERR)");
|
for(i = 0; i < 32; i++)
|
||||||
fprintf (stderr, "%s", KNRM);
|
{
|
||||||
if (opts->payload == 1) fprintf (stderr, " CRC EXT %02X, CRC CMP %02X", crc_extracted, crc_computed);
|
sbrcpl = sbrcpl << 1;
|
||||||
|
sbrcpl |= sbrc_interleaved[i] & 1;
|
||||||
|
}
|
||||||
|
if (opts->payload == 0) fprintf (stderr, "\n");
|
||||||
|
fprintf (stderr, "%s SLOT %d SB/RC (FEC ERR) E:%d; I:%08X D:%03X; %s ", KRED, slot+1, irr_err, sbrcpl, sbrc_hex, KNRM);
|
||||||
|
if (opts->payload == 1) fprintf (stderr, "\n");
|
||||||
|
}
|
||||||
|
else if (irr_err == 0 && sbrc_hex != 0) //older firmware had sbrc_hex 0x5F1, and 0x5E1 instead
|
||||||
|
{
|
||||||
|
fprintf (stderr, "\n");
|
||||||
|
fprintf (stderr, "%s", KCYN);
|
||||||
|
fprintf (stderr, " Slot %d", state->currentslot+1);
|
||||||
|
fprintf (stderr, " DMR LE SB Kirisun");
|
||||||
|
|
||||||
|
//Newer Samples and/or updated firmware seem to do this with actual key values
|
||||||
|
uint8_t alg = sbrc_hex >> 7;
|
||||||
|
|
||||||
|
if (alg != 0xB)
|
||||||
|
{
|
||||||
|
fprintf (stderr, " ALG: %02X;", alg+0x30);
|
||||||
|
uint8_t kid = (sbrc_hex >> 3) & 0xF;
|
||||||
|
fprintf (stderr, " KID: %02X;", kid);
|
||||||
|
uint8_t unk = sbrc_hex & 0x7;
|
||||||
|
fprintf (stderr, " LOW3: %X;", unk);
|
||||||
|
|
||||||
|
if (state->currentslot == 0)
|
||||||
|
{
|
||||||
|
if (state->payload_algid == 0 && state->dmr_so & 0x40)
|
||||||
|
state->payload_algid = alg+0x30;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (state->payload_algidR == 0 && state->dmr_soR & 0x40)
|
||||||
|
state->payload_algidR = alg+0x30;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf (stderr, "%s ", KNRM);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Disabling the lower portion until this can be completely ironed out
|
if (opts->dmr_le == 1)
|
||||||
|
{
|
||||||
|
if (irr_err != 0)
|
||||||
|
{
|
||||||
|
uint32_t sbrcpl = 0;
|
||||||
|
for(i = 0; i < 32; i++)
|
||||||
|
{
|
||||||
|
sbrcpl = sbrcpl << 1;
|
||||||
|
sbrcpl |= sbrc_interleaved[i] & 1;
|
||||||
|
}
|
||||||
|
if (opts->payload == 0) fprintf (stderr, "\n");
|
||||||
|
fprintf (stderr, "%s SLOT %d SB/RC (FEC ERR) E:%d; I:%08X D:%03X; %s ", KRED, slot+1, irr_err, sbrcpl, sbrc_hex, KNRM);
|
||||||
|
if (opts->payload == 1) fprintf (stderr, "\n");
|
||||||
|
}
|
||||||
|
if (irr_err == 0)
|
||||||
|
{
|
||||||
|
if (sbrc_hex == 0 && crc7_okay == 0) ; //NULL Single Burst, do nothing (changed to allow the 0 value of RC below to trigger)
|
||||||
|
|
||||||
//sbrc_hex value of 0x313 seems to be some Cap+ Thing,
|
//else if (placeholder for future conditions)
|
||||||
//also observed 0x643 on another cap+ system (site id, status? something?)
|
// {
|
||||||
// uint8_t sbrc_opcode = sbrc_hex;
|
// placeholder for future conditions
|
||||||
// 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
|
else if (crc7_okay == 1)
|
||||||
//test on site '7' to make sure (works on 1 and 4)
|
{
|
||||||
// uint8_t cap_site = (sbrc_hex >> 4) & 0x7;
|
//decode the reverse channel information ETSI TS 102 361-4 V1.12.1 (2023-07) p 103 Table 6.32: MS Reverse Channel (RC) Command Information Elements
|
||||||
|
if (opts->payload == 0) fprintf (stderr, "\n");
|
||||||
|
fprintf (stderr, "%s", KCYN);
|
||||||
|
sbrc_hex = sbrc_hex >> 7; //set value to its 4-bit form
|
||||||
|
if (sbrc_hex == 0) fprintf (stderr, " RC: Increase Power By One Step;");
|
||||||
|
else if (sbrc_hex == 1) fprintf (stderr, " RC: Decrease Power By One Step;");
|
||||||
|
else if (sbrc_hex == 2) fprintf (stderr, " RC: Set Power To Highest;");
|
||||||
|
else if (sbrc_hex == 3) fprintf (stderr, " RC: Set Power To Lowest;");
|
||||||
|
else if (sbrc_hex == 4) fprintf (stderr, " RC: Cease Transmission Command;");
|
||||||
|
else if (sbrc_hex == 5) fprintf (stderr, " RC: Cease Transmission Request;");
|
||||||
|
else fprintf (stderr, " RC: Reserved %02X;", sbrc_hex);
|
||||||
|
fprintf (stderr, "%s", KNRM);
|
||||||
|
// if (opts->payload == 1)
|
||||||
|
fprintf (stderr, "\n");
|
||||||
|
}
|
||||||
|
|
||||||
// if (opts->payload == 1)
|
//if the call is interruptable (TXI) and the crc3 is okay and TXI Opcode
|
||||||
// {
|
else if (crc3_okay == 1 && (sbrc_opcode == 0 || sbrc_opcode == 3) )
|
||||||
// if (irr_err != 0) fprintf (stderr, "%s (FEC ERR) %d %s", KRED, irr_err, KNRM);
|
{
|
||||||
// if (irr_err == 0)
|
//opcodes -- 0 (NULL), BR Delay (3)
|
||||||
// {
|
if (opts->payload == 0) fprintf (stderr, "\n");
|
||||||
// if (sbrc_hex == 0) ; //NULL
|
fprintf (stderr, "%s", KCYN);
|
||||||
// else if (sbrc_hex == 0x313) //sbrc_hex == 0x313 and 0x643 (cap+ things)
|
fprintf (stderr, " TXI Op: %X -", sbrc_opcode);
|
||||||
// {
|
if (sbrc_opcode == 0) fprintf (stderr, " Null; ");
|
||||||
// //Cap+ Site ID seems to fit here on samples I've seen with the alternate SB signalling
|
else if (sbrc_opcode == 3)
|
||||||
// fprintf (stderr, "%s ", KYEL);
|
{
|
||||||
// fprintf (stderr, "\n ");
|
if (txi_delay != 0)
|
||||||
// fprintf (stderr, " Capacity Plus Site %d", cap_site);
|
fprintf (stderr, " BR Delay: %d - %d ms;", txi_delay, txi_delay * 30); //could also indicate number of superframes until next VC6 pre-emption
|
||||||
// fprintf (stderr, "%s ", KNRM);
|
else fprintf (stderr, "BR Delay: Irrelevant / Send at any time;");
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
|
|
||||||
// if (slot == 0)
|
//alignment of inbound backwards channel and outbound burst
|
||||||
// {
|
if (txi_delay == 2) fprintf (stderr, " SF3, Burst E;"); //E is inbound
|
||||||
// //key and alg only present SOME times, not all,
|
if (txi_delay == 4) fprintf (stderr, " SF3, Burst D;"); //D is inbound
|
||||||
// //also, intermixed with other signalling
|
if (txi_delay == 6) fprintf (stderr, " SF3, Burst C;"); //C is inbound
|
||||||
// //needs more study first!
|
if (txi_delay == 8) fprintf (stderr, " SF3, Burst B;"); //B is inbound
|
||||||
// if (state->dmr_so & 0x40 && key != 0 && state->payload_keyid == 0)
|
}
|
||||||
// {
|
else fprintf (stderr, " Unk; ");
|
||||||
// if (opts->payload == 1)
|
fprintf (stderr, "%s", KNRM);
|
||||||
// {
|
|
||||||
// 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
|
if (opts->payload == 1) fprintf (stderr, "\n"); //only during payload
|
||||||
// // 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
|
else if (sbrc_opcode != 0 && sbrc_opcode != 3) //all that should be left in this field is the potential ENC identifiers
|
||||||
// // state->payload_keyidR = key;
|
{
|
||||||
// // state->payload_algidR = alg + 0x20; //assuming DMRA approved alg values (moto patent)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// }
|
if (slot == 0) //may not need the state->errs anymore //&& state->errs < 3
|
||||||
|
{
|
||||||
|
if (state->dmr_so & 0x40 && key != 0 && alg != 0)
|
||||||
|
{
|
||||||
|
//if we aren't forcing a particular alg or privacy key set
|
||||||
|
if (state->forced_alg_id == 0)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "\n");
|
||||||
|
fprintf (stderr, "%s", KCYN);
|
||||||
|
fprintf (stderr, " Slot 1");
|
||||||
|
fprintf (stderr, " DMR LE SB ALG ID: %02X; KEY ID: %02X;", alg + 0x20, key);
|
||||||
|
if (alg == 1) fprintf (stderr, " RC4;");
|
||||||
|
if (alg == 2) fprintf (stderr, " DES;");
|
||||||
|
if (alg == 4) fprintf (stderr, " AES128;");
|
||||||
|
if (alg == 5) fprintf (stderr, " AES256;");
|
||||||
|
if (alg == 6) fprintf (stderr, " Caltta BP");
|
||||||
|
fprintf (stderr, "%s ", KNRM);
|
||||||
|
if (opts->payload == 1) fprintf (stderr, "\n");
|
||||||
|
if (state->payload_keyid != key)
|
||||||
|
state->payload_keyid = key;
|
||||||
|
if (state->payload_algid != alg)
|
||||||
|
state->payload_algid = alg + 0x20; //assuming DMRA approved alg values (moto patent)
|
||||||
|
}
|
||||||
|
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
|
||||||
|
if (slot == 1) //may not need the state->errs anymore //&& state->errsR < 3
|
||||||
|
{
|
||||||
|
if (state->dmr_soR & 0x40 && key != 0 && alg != 0)
|
||||||
|
{
|
||||||
|
//if we aren't forcing a particular alg or privacy key set
|
||||||
|
if (state->forced_alg_id == 0)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "\n");
|
||||||
|
fprintf (stderr, "%s", KCYN);
|
||||||
|
fprintf (stderr, " Slot 2");
|
||||||
|
fprintf (stderr, " DMR LE SB ALG ID: %02X; KEY ID: %02X;", alg + 0x20, key);
|
||||||
|
if (alg == 1) fprintf (stderr, " RC4;");
|
||||||
|
if (alg == 2) fprintf (stderr, " DES;");
|
||||||
|
if (alg == 4) fprintf (stderr, " AES128;");
|
||||||
|
if (alg == 5) fprintf (stderr, " AES256;");
|
||||||
|
if (alg == 6) fprintf (stderr, " Caltta BP");
|
||||||
|
fprintf (stderr, "%s ", KNRM);
|
||||||
|
if (opts->payload == 1) fprintf (stderr, "\n");
|
||||||
|
if (state->payload_keyidR != key)
|
||||||
|
state->payload_keyidR = key;
|
||||||
|
if (state->payload_algidR != alg)
|
||||||
|
state->payload_algidR = alg + 0x20; //assuming DMRA approved alg values (moto patent)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
SBRC_END:
|
SBRC_END:
|
||||||
|
|
||||||
//'DSP' output to file -- only RC, or RC and SB?
|
//'DSP' output to file -- SB and RC
|
||||||
if (power == 1 && opts->use_dsp_output == 1 && sbrc_hex != 0) //if not NULL
|
if (opts->use_dsp_output == 1)
|
||||||
{
|
{
|
||||||
FILE * pFile; //file pointer
|
FILE * pFile; //file pointer
|
||||||
pFile = fopen (opts->dsp_out_file, "a");
|
pFile = fopen (opts->dsp_out_file, "a");
|
||||||
fprintf (pFile, "\n%d 99 ", slot+1); //'99' is RC designation value
|
fprintf (pFile, "\n%d 99 ", slot+1); //'99' is SB and RC designation value
|
||||||
int k = 0;
|
for (i = 0; i < 12; i++) //48 bits (includes CC, PPI, LCSS, and QR)
|
||||||
for (i = 0; i < 24; i++) //12 bytes, SB or RC
|
// for (i = 2; i < 10; i++) //32 bits (only SB/RC Data and its PC/H)
|
||||||
{
|
{
|
||||||
//check to see if k++ starts at zero, or at 1
|
uint8_t sbrc_nib = (state->dmr_embedded_signalling[slot][5][(i*4)+0] << 3) | (state->dmr_embedded_signalling[slot][5][(i*4)+1] << 2) | (state->dmr_embedded_signalling[slot][5][(i*4)+2] << 1) | (state->dmr_embedded_signalling[slot][5][(i*4)+3] << 0);
|
||||||
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);
|
fprintf (pFile, "%X", sbrc_nib);
|
||||||
}
|
}
|
||||||
fclose (pFile);
|
fclose (pFile);
|
||||||
@@ -314,3 +769,50 @@ void dmr_sbrc (dsd_opts * opts, dsd_state * state, uint8_t power)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint8_t crc3(uint8_t bits[], unsigned int len)
|
||||||
|
{
|
||||||
|
uint8_t crc=0;
|
||||||
|
unsigned int K = 3;
|
||||||
|
//x^3+x+1
|
||||||
|
uint8_t poly[4] = {1,1,0,1};
|
||||||
|
uint8_t buf[256];
|
||||||
|
if (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;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t crc4(uint8_t bits[], unsigned int len)
|
||||||
|
{
|
||||||
|
uint8_t crc=0;
|
||||||
|
unsigned int K = 4;
|
||||||
|
//x^4+x+1
|
||||||
|
uint8_t poly[5] = {1,0,0,1,1};
|
||||||
|
uint8_t buf[256];
|
||||||
|
if (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 ^ 0xF; //invert
|
||||||
|
}
|
||||||
|
|||||||
353
src/dmr_ms.c
353
src/dmr_ms.c
@@ -9,43 +9,42 @@
|
|||||||
#include "dsd.h"
|
#include "dsd.h"
|
||||||
#include "dmr_const.h"
|
#include "dmr_const.h"
|
||||||
|
|
||||||
|
// #define PRINT_AMBE72 //enable to view 72-bit AMBE codewords
|
||||||
|
|
||||||
//A subroutine for processing MS voice
|
//A subroutine for processing MS voice
|
||||||
void dmrMS (dsd_opts * opts, dsd_state * state)
|
void dmrMS (dsd_opts * opts, dsd_state * state)
|
||||||
{
|
{
|
||||||
|
|
||||||
int i, j, k, l, dibit;
|
char * timestr = getTimeC();
|
||||||
int *dibit_p;
|
|
||||||
|
int i, j, dibit;
|
||||||
char ambe_fr[4][24];
|
char ambe_fr[4][24];
|
||||||
char ambe_fr2[4][24];
|
char ambe_fr2[4][24];
|
||||||
char ambe_fr3[4][24];
|
char ambe_fr3[4][24];
|
||||||
char ambe_fr4[4][24];
|
char ambe_fr4[4][24];
|
||||||
|
|
||||||
//memcpy of ambe_fr for late entry
|
//memcpy of ambe_fr for late entry
|
||||||
char m1[4][24];
|
uint8_t m1[4][24];
|
||||||
char m2[4][24];
|
uint8_t m2[4][24];
|
||||||
char m3[4][24];
|
uint8_t m3[4][24];
|
||||||
|
|
||||||
const int *w, *x, *y, *z;
|
const int *w, *x, *y, *z;
|
||||||
char sync[25];
|
|
||||||
char syncdata[48];
|
uint8_t syncdata[48];
|
||||||
char EmbeddedSignalling[16];
|
memset (syncdata, 0, sizeof(syncdata));
|
||||||
|
|
||||||
|
uint8_t emb_pdu[16];
|
||||||
|
memset (emb_pdu, 0, sizeof(emb_pdu));
|
||||||
|
|
||||||
//cach
|
//cach
|
||||||
char cachdata[25];
|
char cachdata[25];
|
||||||
int cachInterleave[24] =
|
|
||||||
{0, 7, 8, 9, 1, 10,
|
|
||||||
11, 12, 2, 13, 14,
|
|
||||||
15, 3, 16, 4, 17, 18,
|
|
||||||
19, 5, 20, 21, 22, 6, 23
|
|
||||||
};
|
|
||||||
|
|
||||||
//cach tact bits
|
//cach tact bits
|
||||||
uint8_t tact_bits[7];
|
uint8_t tact_bits[7];
|
||||||
|
|
||||||
uint8_t emb_ok = 0;
|
|
||||||
uint8_t tact_okay = 0;
|
uint8_t tact_okay = 0;
|
||||||
uint8_t cach_err = 0;
|
uint8_t emb_ok = 0;
|
||||||
uint8_t EmbeddedSignallingOk = 0;
|
UNUSED(emb_ok);
|
||||||
|
|
||||||
uint8_t internalslot;
|
uint8_t internalslot;
|
||||||
uint8_t vc;
|
uint8_t vc;
|
||||||
@@ -54,32 +53,14 @@ void dmrMS (dsd_opts * opts, dsd_state * state)
|
|||||||
uint8_t cc = 25;
|
uint8_t cc = 25;
|
||||||
uint8_t power = 9; //power and pre-emption indicator
|
uint8_t power = 9; //power and pre-emption indicator
|
||||||
uint8_t lcss = 9;
|
uint8_t lcss = 9;
|
||||||
|
UNUSED2(cc, lcss);
|
||||||
|
|
||||||
//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));
|
||||||
|
|
||||||
//add time to mirror printFrameSync
|
|
||||||
time_t now;
|
|
||||||
char * getTime(void) //get pretty hh:mm:ss timestamp
|
|
||||||
{
|
|
||||||
time_t t = time(NULL);
|
|
||||||
|
|
||||||
char * curr;
|
|
||||||
char * stamp = asctime(localtime( & t));
|
|
||||||
|
|
||||||
curr = strtok(stamp, " ");
|
|
||||||
curr = strtok(NULL, " ");
|
|
||||||
curr = strtok(NULL, " ");
|
|
||||||
curr = strtok(NULL, " ");
|
|
||||||
|
|
||||||
return curr;
|
|
||||||
}
|
|
||||||
|
|
||||||
vc = 2;
|
vc = 2;
|
||||||
|
|
||||||
short int skipcount = 0;
|
|
||||||
|
|
||||||
//Hardset variables for MS/Mono
|
//Hardset variables for MS/Mono
|
||||||
state->currentslot = 0; //0
|
state->currentslot = 0; //0
|
||||||
|
|
||||||
@@ -89,6 +70,10 @@ void dmrMS (dsd_opts * opts, dsd_state * state)
|
|||||||
for (j = 0; j < 6; j++) {
|
for (j = 0; j < 6; j++) {
|
||||||
state->dmrburstL = 16;
|
state->dmrburstL = 16;
|
||||||
|
|
||||||
|
memset (ambe_fr, 0, sizeof(ambe_fr));
|
||||||
|
memset (ambe_fr2, 0, sizeof(ambe_fr2));
|
||||||
|
memset (ambe_fr3, 0, sizeof(ambe_fr3));
|
||||||
|
|
||||||
for(i = 0; i < 12; i++)
|
for(i = 0; i < 12; i++)
|
||||||
{
|
{
|
||||||
dibit = getDibit(opts, state);
|
dibit = getDibit(opts, state);
|
||||||
@@ -173,10 +158,8 @@ void dmrMS (dsd_opts * opts, dsd_state * state)
|
|||||||
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;
|
|
||||||
|
|
||||||
// load the superframe to do embedded signal processing
|
// load the superframe to do embedded signal processing
|
||||||
if(vc > 1) //grab on vc1 values 2-5 B C D and E
|
if(vc > 1) //grab on vc2 values 2-5 B C D E, and F
|
||||||
{
|
{
|
||||||
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
|
||||||
@@ -184,35 +167,17 @@ void dmrMS (dsd_opts * opts, dsd_state * state)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sync[24] = 0;
|
for(i = 0; i < 8; i++) emb_pdu[i + 0] = syncdata[i];
|
||||||
|
for(i = 0; i < 8; i++) emb_pdu[i + 8] = syncdata[i + 40];
|
||||||
|
|
||||||
//test for RC sync pattern in MS sourced audio
|
emb_ok = -1;
|
||||||
if ( strcmp (sync, DMR_RC_DATA_SYNC) == 0)
|
if(QR_16_7_6_decode(emb_pdu))
|
||||||
{
|
{
|
||||||
state->dmr_ms_rc = 1;
|
emb_ok = 1;
|
||||||
fprintf (stderr, "%s ", getTime());
|
cc = ((emb_pdu[0] << 3) + (emb_pdu[1] << 2) + (emb_pdu[2] << 1) + emb_pdu[3]);
|
||||||
if (opts->inverted_dmr == 0)
|
power = emb_pdu[4];
|
||||||
{
|
lcss = ((emb_pdu[5] << 1) + emb_pdu[6]);
|
||||||
fprintf (stderr,"Sync: +DMR MS/DM MODE/MONO ");
|
state->dmr_color_code = state->color_code = cc;
|
||||||
}
|
|
||||||
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;
|
|
||||||
if(QR_16_7_6_decode(EmbeddedSignalling))
|
|
||||||
{
|
|
||||||
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
|
||||||
@@ -281,24 +246,67 @@ 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->tyt_bp == 1)
|
||||||
{
|
{
|
||||||
if (state->directmode == 0)
|
tyt16_ambe2_codeword_keystream(state, ambe_fr, 0);
|
||||||
{
|
tyt16_ambe2_codeword_keystream(state, ambe_fr2, 1);
|
||||||
processMbeFrame (opts, state, NULL, ambe_fr, NULL);
|
tyt16_ambe2_codeword_keystream(state, ambe_fr3, 0);
|
||||||
processMbeFrame (opts, state, NULL, ambe_fr2, NULL);
|
}
|
||||||
processMbeFrame (opts, state, NULL, ambe_fr3, NULL);
|
|
||||||
}
|
if (state->csi_ee == 1)
|
||||||
else
|
{
|
||||||
{
|
csi72_ambe2_codeword_keystream(state, ambe_fr);
|
||||||
processMbeFrame (opts, state, NULL, ambe_fr4, NULL); //play duplicate of 2 here to smooth audio on tdma direct
|
csi72_ambe2_codeword_keystream(state, ambe_fr2);
|
||||||
processMbeFrame (opts, state, NULL, ambe_fr2, NULL);
|
csi72_ambe2_codeword_keystream(state, ambe_fr3);
|
||||||
processMbeFrame (opts, state, NULL, ambe_fr3, NULL);
|
}
|
||||||
}
|
|
||||||
|
if (state->vtx256_ekey != 0)
|
||||||
|
{
|
||||||
|
vtx256_ambe2_interleave_inversion(ambe_fr);
|
||||||
|
vtx256_ambe2_interleave_inversion(ambe_fr2);
|
||||||
|
vtx256_ambe2_interleave_inversion(ambe_fr3);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef PRINT_AMBE72
|
||||||
|
ambe2_codeword_print_i(opts, ambe_fr);
|
||||||
|
ambe2_codeword_print_i(opts, ambe_fr2);
|
||||||
|
ambe2_codeword_print_i(opts, ambe_fr3);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
processMbeFrame (opts, state, NULL, ambe_fr, NULL);
|
||||||
|
memcpy(state->f_l4[0], state->audio_out_temp_buf, sizeof(state->audio_out_temp_buf));
|
||||||
|
memcpy(state->s_l4[0], state->s_l, sizeof(state->s_l));
|
||||||
|
memcpy(state->s_l4u[0], state->s_lu, sizeof(state->s_lu));
|
||||||
|
processMbeFrame (opts, state, NULL, ambe_fr2, NULL);
|
||||||
|
memcpy(state->f_l4[1], state->audio_out_temp_buf, sizeof(state->audio_out_temp_buf));
|
||||||
|
memcpy(state->s_l4[1], state->s_l, sizeof(state->s_l));
|
||||||
|
memcpy(state->s_l4u[1], state->s_lu, sizeof(state->s_lu));
|
||||||
|
processMbeFrame (opts, state, NULL, ambe_fr3, NULL);
|
||||||
|
memcpy(state->f_l4[2], state->audio_out_temp_buf, sizeof(state->audio_out_temp_buf));
|
||||||
|
memcpy(state->s_l4[2], state->s_l, sizeof(state->s_l));
|
||||||
|
memcpy(state->s_l4u[2], state->s_lu, sizeof(state->s_lu));
|
||||||
|
|
||||||
|
//TODO: Consider copying f_l to f_r for left and right channel saturation on MS mode
|
||||||
|
if (opts->floating_point == 0)
|
||||||
|
{
|
||||||
|
// memcpy (state->s_r4, state->s_l4, sizeof(state->s_l4));
|
||||||
|
if(opts->pulse_digi_out_channels == 2)
|
||||||
|
playSynthesizedVoiceSS3(opts, state);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (opts->floating_point == 1)
|
||||||
|
{
|
||||||
|
// memcpy (state->f_r4, state->f_l4, sizeof(state->f_l4));
|
||||||
|
if(opts->pulse_digi_out_channels == 2)
|
||||||
|
playSynthesizedVoiceFS3(opts, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vc == 6)
|
if (vc == 6)
|
||||||
{
|
{
|
||||||
|
//this needs to run prior to embedded link control
|
||||||
|
if (state->payload_algid == 0x02)
|
||||||
|
hytera_enhanced_alg_refresh(state);
|
||||||
|
|
||||||
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
|
//check the single burst/reverse channel opportunity
|
||||||
dmr_sbrc (opts, state, power);
|
dmr_sbrc (opts, state, power);
|
||||||
@@ -308,7 +316,8 @@ void dmrMS (dsd_opts * opts, dsd_state * state)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//collect the mi fragment
|
//collect the mi fragment
|
||||||
dmr_late_entry_mi_fragment (opts, state, vc, m1, m2, m3);
|
if (opts->dmr_le != 2) //if not Hytera Enhanced
|
||||||
|
dmr_late_entry_mi_fragment (opts, state, vc, m1, m2, m3);
|
||||||
|
|
||||||
//errors in ms/mono since we skip the other slot
|
//errors in ms/mono since we skip the other slot
|
||||||
// cach_err = dmr_cach (opts, state, cachdata);
|
// cach_err = dmr_cach (opts, state, cachdata);
|
||||||
@@ -327,7 +336,6 @@ void dmrMS (dsd_opts * opts, dsd_state * state)
|
|||||||
if (vc > 6) goto END;
|
if (vc > 6) goto END;
|
||||||
|
|
||||||
skipDibit (opts, state, 144); //skip to next tdma channel
|
skipDibit (opts, state, 144); //skip to next tdma channel
|
||||||
state->dmr_ms_rc = 0;
|
|
||||||
|
|
||||||
//since we are in a loop, run ncursesPrinter here
|
//since we are in a loop, run ncursesPrinter here
|
||||||
if (opts->use_ncurses_terminal == 1)
|
if (opts->use_ncurses_terminal == 1)
|
||||||
@@ -335,6 +343,10 @@ void dmrMS (dsd_opts * opts, dsd_state * state)
|
|||||||
ncursesPrinter(opts, state);
|
ncursesPrinter(opts, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//slot 1
|
||||||
|
watchdog_event_history(opts, state, 0);
|
||||||
|
watchdog_event_current(opts, state, 0);
|
||||||
|
|
||||||
} // end loop
|
} // end loop
|
||||||
|
|
||||||
END:
|
END:
|
||||||
@@ -355,67 +367,50 @@ void dmrMS (dsd_opts * opts, dsd_state * state)
|
|||||||
|
|
||||||
state->dmr_stereo = 0;
|
state->dmr_stereo = 0;
|
||||||
state->dmr_ms_mode = 0;
|
state->dmr_ms_mode = 0;
|
||||||
state->dmr_ms_rc = 0;
|
|
||||||
state->directmode = 0; //flag off
|
state->directmode = 0; //flag off
|
||||||
|
|
||||||
|
if (timestr != NULL)
|
||||||
|
{
|
||||||
|
free (timestr);
|
||||||
|
timestr = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
//reset static ks counter
|
||||||
|
state->static_ks_counter[0] = 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//collect buffered 1st half and get 2nd half voice payload and then jump to full MS Voice decoding.
|
//collect buffered 1st half and get 2nd half voice payload and then jump to full MS Voice decoding.
|
||||||
void dmrMSBootstrap (dsd_opts * opts, dsd_state * state)
|
void dmrMSBootstrap (dsd_opts * opts, dsd_state * state)
|
||||||
{
|
{
|
||||||
int i, j, k, l, dibit;
|
|
||||||
|
char * timestr = getTimeC();
|
||||||
|
|
||||||
|
//reset static ks counter
|
||||||
|
state->static_ks_counter[0] = 0;
|
||||||
|
|
||||||
|
int i, dibit;
|
||||||
int *dibit_p;
|
int *dibit_p;
|
||||||
|
|
||||||
char ambe_fr[4][24];
|
char ambe_fr[4][24];
|
||||||
char ambe_fr2[4][24];
|
char ambe_fr2[4][24];
|
||||||
char ambe_fr3[4][24];
|
char ambe_fr3[4][24];
|
||||||
char ambe_fr4[4][24]; //shim for crappy tdma direct, need more samples to see if this is really a necessary shim or not
|
char ambe_fr4[4][24];
|
||||||
|
|
||||||
|
memset (ambe_fr, 0, sizeof(ambe_fr));
|
||||||
|
memset (ambe_fr2, 0, sizeof(ambe_fr2));
|
||||||
|
memset (ambe_fr3, 0, sizeof(ambe_fr3));
|
||||||
|
|
||||||
//memcpy of ambe_fr for late entry
|
//memcpy of ambe_fr for late entry
|
||||||
char m1[4][24];
|
uint8_t m1[4][24];
|
||||||
char m2[4][24];
|
uint8_t m2[4][24];
|
||||||
char m3[4][24];
|
uint8_t m3[4][24];
|
||||||
|
|
||||||
const int *w, *x, *y, *z;
|
const int *w, *x, *y, *z;
|
||||||
char sync[25];
|
|
||||||
char syncdata[48];
|
|
||||||
|
|
||||||
//cach
|
//cach
|
||||||
char cachdata[25];
|
char cachdata[25];
|
||||||
int cachInterleave[24] =
|
UNUSED(cachdata);
|
||||||
{0, 7, 8, 9, 1, 10,
|
|
||||||
11, 12, 2, 13, 14,
|
|
||||||
15, 3, 16, 4, 17, 18,
|
|
||||||
19, 5, 20, 21, 22, 6, 23
|
|
||||||
};
|
|
||||||
|
|
||||||
int mutecurrentslot;
|
|
||||||
int msMode;
|
|
||||||
char cc[4];
|
|
||||||
char EmbeddedSignalling[16];
|
|
||||||
|
|
||||||
uint8_t emb_ok = 0;
|
|
||||||
uint8_t tact_okay = 0;
|
|
||||||
uint8_t cach_err = 0;
|
|
||||||
uint8_t EmbeddedSignallingOk = 0;
|
|
||||||
|
|
||||||
//add time to mirror sync
|
|
||||||
time_t now;
|
|
||||||
char * getTime(void) //get pretty hh:mm:ss timestamp
|
|
||||||
{
|
|
||||||
time_t t = time(NULL);
|
|
||||||
|
|
||||||
char * curr;
|
|
||||||
char * stamp = asctime(localtime( & t));
|
|
||||||
|
|
||||||
curr = strtok(stamp, " ");
|
|
||||||
curr = strtok(NULL, " ");
|
|
||||||
curr = strtok(NULL, " ");
|
|
||||||
curr = strtok(NULL, " ");
|
|
||||||
|
|
||||||
return curr;
|
|
||||||
}
|
|
||||||
|
|
||||||
state->dmrburstL = 16;
|
state->dmrburstL = 16;
|
||||||
state->currentslot = 0; //force to slot 0
|
state->currentslot = 0; //force to slot 0
|
||||||
@@ -552,13 +547,15 @@ void dmrMSBootstrap (dsd_opts * opts, dsd_state * state)
|
|||||||
fclose (pFile);
|
fclose (pFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf (stderr, "%s ", getTime());
|
fprintf (stderr, "%s ", timestr);
|
||||||
if (opts->inverted_dmr == 0)
|
if (opts->inverted_dmr == 0)
|
||||||
{
|
{
|
||||||
fprintf (stderr,"Sync: +DMR MS/DM MODE/MONO ");
|
fprintf (stderr,"Sync: +DMR MS/DM MODE/MONO ");
|
||||||
}
|
}
|
||||||
else fprintf (stderr,"Sync: -DMR MS/DM MODE/MONO ");
|
else fprintf (stderr,"Sync: -DMR MS/DM MODE/MONO ");
|
||||||
|
if (state->dmr_color_code != 16)
|
||||||
|
fprintf (stderr, "| Color Code=%02d ", state->dmr_color_code);
|
||||||
|
else fprintf (stderr, "| Color Code=XX ");
|
||||||
fprintf (stderr, "| VC* ");
|
fprintf (stderr, "| VC* ");
|
||||||
fprintf (stderr, "\n");
|
fprintf (stderr, "\n");
|
||||||
|
|
||||||
@@ -574,24 +571,72 @@ void dmrMSBootstrap (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->directmode == 0)
|
if (state->tyt_bp == 1)
|
||||||
{
|
{
|
||||||
processMbeFrame (opts, state, NULL, ambe_fr, NULL);
|
tyt16_ambe2_codeword_keystream(state, ambe_fr, 0);
|
||||||
processMbeFrame (opts, state, NULL, ambe_fr2, NULL);
|
tyt16_ambe2_codeword_keystream(state, ambe_fr2, 1);
|
||||||
processMbeFrame (opts, state, NULL, ambe_fr3, NULL);
|
tyt16_ambe2_codeword_keystream(state, ambe_fr3, 0);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
if (state->csi_ee == 1)
|
||||||
{
|
{
|
||||||
processMbeFrame (opts, state, NULL, ambe_fr4, NULL); //play duplicate of 2 here to smooth audio
|
csi72_ambe2_codeword_keystream(state, ambe_fr);
|
||||||
processMbeFrame (opts, state, NULL, ambe_fr2, NULL);
|
csi72_ambe2_codeword_keystream(state, ambe_fr2);
|
||||||
processMbeFrame (opts, state, NULL, ambe_fr3, NULL);
|
csi72_ambe2_codeword_keystream(state, ambe_fr3);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state->vtx256_ekey != 0)
|
||||||
|
{
|
||||||
|
vtx256_ambe2_interleave_inversion(ambe_fr);
|
||||||
|
vtx256_ambe2_interleave_inversion(ambe_fr2);
|
||||||
|
vtx256_ambe2_interleave_inversion(ambe_fr3);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef PRINT_AMBE72
|
||||||
|
ambe2_codeword_print_i(opts, ambe_fr);
|
||||||
|
ambe2_codeword_print_i(opts, ambe_fr2);
|
||||||
|
ambe2_codeword_print_i(opts, ambe_fr3);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
processMbeFrame (opts, state, NULL, ambe_fr, NULL);
|
||||||
|
memcpy(state->f_l4[0], state->audio_out_temp_buf, sizeof(state->audio_out_temp_buf));
|
||||||
|
memcpy(state->s_l4[0], state->s_l, sizeof(state->s_l));
|
||||||
|
memcpy(state->s_l4u[0], state->s_lu, sizeof(state->s_lu));
|
||||||
|
processMbeFrame (opts, state, NULL, ambe_fr2, NULL);
|
||||||
|
memcpy(state->f_l4[1], state->audio_out_temp_buf, sizeof(state->audio_out_temp_buf));
|
||||||
|
memcpy(state->s_l4[1], state->s_l, sizeof(state->s_l));
|
||||||
|
memcpy(state->s_l4u[1], state->s_lu, sizeof(state->s_lu));
|
||||||
|
processMbeFrame (opts, state, NULL, ambe_fr3, NULL);
|
||||||
|
memcpy(state->f_l4[2], state->audio_out_temp_buf, sizeof(state->audio_out_temp_buf));
|
||||||
|
memcpy(state->s_l4[2], state->s_l, sizeof(state->s_l));
|
||||||
|
memcpy(state->s_l4u[2], state->s_lu, sizeof(state->s_lu));
|
||||||
|
|
||||||
|
//TODO: Consider copying f_l to f_r for left and right channel saturation on MS mode
|
||||||
|
if (opts->floating_point == 0)
|
||||||
|
{
|
||||||
|
// memcpy (state->s_r4, state->s_l4, sizeof(state->s_l4));
|
||||||
|
if(opts->pulse_digi_out_channels == 2)
|
||||||
|
playSynthesizedVoiceSS3(opts, state);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (opts->floating_point == 1)
|
||||||
|
{
|
||||||
|
// memcpy (state->f_r4, state->f_l4, sizeof(state->f_l4));
|
||||||
|
if(opts->pulse_digi_out_channels == 2)
|
||||||
|
playSynthesizedVoiceFS3(opts, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
//collect the mi fragment
|
//collect the mi fragment
|
||||||
dmr_late_entry_mi_fragment (opts, state, 1, m1, m2, m3);
|
if (opts->dmr_le != 2) //if not Hytera Enhanced
|
||||||
|
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);
|
||||||
|
if (timestr != NULL)
|
||||||
|
{
|
||||||
|
free (timestr);
|
||||||
|
timestr = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
skipDibit (opts, state, 144); //skip to next TDMA slot
|
skipDibit (opts, state, 144); //skip to next TDMA slot
|
||||||
dmrMS (opts, state); //bootstrap into full TDMA frame
|
dmrMS (opts, state); //bootstrap into full TDMA frame
|
||||||
@@ -601,28 +646,13 @@ void dmrMSBootstrap (dsd_opts * opts, dsd_state * state)
|
|||||||
//simplied to a simple data collector, and then passed on to dmr_data_sync for the usual processing
|
//simplied to a simple data collector, and then passed on to dmr_data_sync for the usual processing
|
||||||
void dmrMSData (dsd_opts * opts, dsd_state * state)
|
void dmrMSData (dsd_opts * opts, dsd_state * state)
|
||||||
{
|
{
|
||||||
int i, b, c;
|
|
||||||
|
char * timestr = getTimeC();
|
||||||
|
|
||||||
|
int i;
|
||||||
int dibit;
|
int dibit;
|
||||||
int *dibit_p;
|
int *dibit_p;
|
||||||
|
|
||||||
//add time to mirror sync
|
|
||||||
time_t now;
|
|
||||||
char * getTime(void) //get pretty hh:mm:ss timestamp
|
|
||||||
{
|
|
||||||
time_t t = time(NULL);
|
|
||||||
|
|
||||||
char * curr;
|
|
||||||
char * stamp = asctime(localtime( & t));
|
|
||||||
|
|
||||||
curr = strtok(stamp, " ");
|
|
||||||
curr = strtok(NULL, " ");
|
|
||||||
curr = strtok(NULL, " ");
|
|
||||||
curr = strtok(NULL, " ");
|
|
||||||
|
|
||||||
return curr;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//CACH + First Half Payload + Sync = 12 + 54 + 24
|
//CACH + First Half Payload + Sync = 12 + 54 + 24
|
||||||
dibit_p = state->dmr_payload_p - 90;
|
dibit_p = state->dmr_payload_p - 90;
|
||||||
for (i = 0; i < 90; i++) //90
|
for (i = 0; i < 90; i++) //90
|
||||||
@@ -631,7 +661,6 @@ void dmrMSData (dsd_opts * opts, dsd_state * state)
|
|||||||
dibit_p++;
|
dibit_p++;
|
||||||
if(opts->inverted_dmr == 1) dibit = (dibit ^ 2) & 3;
|
if(opts->inverted_dmr == 1) dibit = (dibit ^ 2) & 3;
|
||||||
state->dmr_stereo_payload[i] = dibit;
|
state->dmr_stereo_payload[i] = dibit;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < 54; i++)
|
for (i = 0; i < 54; i++)
|
||||||
@@ -639,16 +668,17 @@ void dmrMSData (dsd_opts * opts, dsd_state * state)
|
|||||||
dibit = getDibit(opts, state);
|
dibit = getDibit(opts, state);
|
||||||
if(opts->inverted_dmr == 1) dibit = (dibit ^ 2) & 3;
|
if(opts->inverted_dmr == 1) dibit = (dibit ^ 2) & 3;
|
||||||
state->dmr_stereo_payload[i+90] = dibit;
|
state->dmr_stereo_payload[i+90] = dibit;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf (stderr, "%s ", getTime());
|
fprintf (stderr, "%s ", timestr);
|
||||||
if (opts->inverted_dmr == 0)
|
if (opts->inverted_dmr == 0)
|
||||||
{
|
{
|
||||||
fprintf (stderr,"Sync: +DMR MS/DM MODE/MONO ");
|
fprintf (stderr,"Sync: +DMR MS/DM MODE/MONO ");
|
||||||
}
|
}
|
||||||
else fprintf (stderr,"Sync: -DMR MS/DM MODE/MONO ");
|
else fprintf (stderr,"Sync: -DMR MS/DM MODE/MONO ");
|
||||||
|
if (state->dmr_color_code != 16)
|
||||||
|
fprintf (stderr, "| Color Code=%02d ", state->dmr_color_code);
|
||||||
|
else fprintf (stderr, "| Color Code=XX ");
|
||||||
|
|
||||||
sprintf(state->slot1light, "%s", "");
|
sprintf(state->slot1light, "%s", "");
|
||||||
sprintf(state->slot2light, "%s", "");
|
sprintf(state->slot2light, "%s", "");
|
||||||
@@ -664,16 +694,23 @@ void dmrMSData (dsd_opts * opts, dsd_state * state)
|
|||||||
state->directmode = 0; //flag off
|
state->directmode = 0; //flag off
|
||||||
|
|
||||||
//should just be loaded in the dmr_payload_buffer instead now
|
//should just be loaded in the dmr_payload_buffer instead now
|
||||||
|
//but we want to run getDibit so the buffer has actual good values in it
|
||||||
for (i = 0; i < 144; i++) //66
|
for (i = 0; i < 144; i++) //66
|
||||||
{
|
{
|
||||||
dibit = getDibit(opts, state);
|
dibit = getDibit(opts, state);
|
||||||
state->dmr_stereo_payload[i] = dibit;
|
state->dmr_stereo_payload[i] = 1; //set to one so first frame will fail intentionally instead of zero fill
|
||||||
}
|
}
|
||||||
//CACH + First Half Payload = 12 + 54
|
//CACH + First Half Payload = 12 + 54
|
||||||
for (i = 0; i < 66; i++) //66
|
for (i = 0; i < 66; i++) //66
|
||||||
{
|
{
|
||||||
dibit = getDibit(opts, state);
|
dibit = getDibit(opts, state);
|
||||||
state->dmr_stereo_payload[i] = dibit;
|
state->dmr_stereo_payload[i+66] = 1; ////set to one so first frame will fail intentionally instead of zero fill
|
||||||
|
}
|
||||||
|
|
||||||
|
if (timestr != NULL)
|
||||||
|
{
|
||||||
|
free (timestr);
|
||||||
|
timestr = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
965
src/dmr_pdu.c
965
src/dmr_pdu.c
File diff suppressed because it is too large
Load Diff
599
src/dmr_pi.c
599
src/dmr_pi.c
@@ -13,69 +13,307 @@
|
|||||||
void dmr_pi (dsd_opts * opts, dsd_state * state, uint8_t PI_BYTE[], uint32_t CRCCorrect, uint32_t IrrecoverableErrors)
|
void dmr_pi (dsd_opts * opts, dsd_state * state, uint8_t PI_BYTE[], uint32_t CRCCorrect, uint32_t IrrecoverableErrors)
|
||||||
{
|
{
|
||||||
|
|
||||||
if((IrrecoverableErrors == 0))
|
uint8_t MFID = PI_BYTE[1];
|
||||||
|
|
||||||
|
if(IrrecoverableErrors == 0)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (state->currentslot == 0)
|
//update cc amd vc sync time for trunking purposes (particularly Con+)
|
||||||
|
if (opts->p25_is_tuned == 1)
|
||||||
{
|
{
|
||||||
state->payload_algid = PI_BYTE[0];
|
state->last_vc_sync_time = time(NULL);
|
||||||
state->payload_keyid = PI_BYTE[2];
|
state->last_cc_sync_time = time(NULL);
|
||||||
state->payload_mi = ( ((PI_BYTE[3]) << 24) + ((PI_BYTE[4]) << 16) + ((PI_BYTE[5]) << 8) + (PI_BYTE[6]) );
|
}
|
||||||
if (state->payload_algid < 0x26)
|
|
||||||
|
if (MFID == 0x0A && CRCCorrect == 1) //Kirisun
|
||||||
|
{
|
||||||
|
//NOTE: Some Kirisun Radios seem to use byte 2 as the SVC_OPT, others seem to use it like a KID value
|
||||||
|
// uint8_t so = PI_BYTE[2]; //in VLC and PI, this byte is 0x40, so thinking this could be SVC_OPT
|
||||||
|
uint8_t alg = PI_BYTE[0]; //observed 0x36 and 0x37 for Kirisun Advanced and Universal Privacy
|
||||||
|
//NOTE: Original samples had this as 0x40 no matter which "key" was selected, new samples from different radio show a KID value
|
||||||
|
uint8_t kid = PI_BYTE[2]; //user info conveyed there is only 16 allotments for Key, and keys are channel specific, so no key id value on older FW
|
||||||
|
uint32_t target = ((unsigned long long int)PI_BYTE[7] << 16) | ((unsigned long long int)PI_BYTE[8] << 8) | ((unsigned long long int)PI_BYTE[9] << 0);
|
||||||
|
|
||||||
|
//TODO: Use ALG and TGT value here to produce a key id via hashing it
|
||||||
|
uint8_t hash = alg * target % 256; //more complex hash later (honestly, probably not)
|
||||||
|
|
||||||
|
//Only set real KID if the byte value isn't 0x40
|
||||||
|
if (kid == 0x40)
|
||||||
|
kid = hash;
|
||||||
|
|
||||||
|
//MI only appears to be 32-bit
|
||||||
|
uint32_t mi = ((uint32_t)PI_BYTE[3] << 24) | ((uint32_t)PI_BYTE[4] << 16) |
|
||||||
|
((uint32_t)PI_BYTE[5] << 8) | ((uint32_t)PI_BYTE[6] << 0);
|
||||||
|
|
||||||
|
if (state->currentslot == 0)
|
||||||
{
|
{
|
||||||
fprintf (stderr, "%s ", KYEL);
|
state->dmr_so = 0x40;
|
||||||
fprintf (stderr, "\n Slot 1");
|
state->payload_algid = alg;
|
||||||
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);
|
state->payload_keyid = kid;
|
||||||
fprintf (stderr, "%s ", KNRM);
|
state->payload_mi = mi;
|
||||||
if (state->payload_algid != 0x21)
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
state->dmr_soR = 0x40;
|
||||||
|
state->payload_algidR = alg;
|
||||||
|
state->payload_keyidR = kid;
|
||||||
|
state->payload_miR = mi;
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf (stderr, "%s ", KYEL);
|
||||||
|
fprintf (stderr, "\n Slot %d", state->currentslot+1);
|
||||||
|
fprintf (stderr, " DMR PI H- ALG ID: %02X; TGT: %d; KEY ID: %02X; MI(32): %08X;", alg, target, kid, mi);
|
||||||
|
|
||||||
|
fprintf (stderr, " Kirisun ");
|
||||||
|
if (alg == 0x31)
|
||||||
|
fprintf (stderr, "Reinforced ");
|
||||||
|
else if (alg == 0x32)
|
||||||
|
fprintf (stderr, "Low ");
|
||||||
|
else if (alg == 0x33)
|
||||||
|
fprintf (stderr, "Middle ");
|
||||||
|
else if (alg == 0x34)
|
||||||
|
fprintf (stderr, "High ");
|
||||||
|
else if (alg == 0x35)
|
||||||
|
fprintf (stderr, "Enhanced ");
|
||||||
|
else if (alg == 0x36)
|
||||||
|
fprintf (stderr, "Advanced ");
|
||||||
|
else if (alg == 0x37)
|
||||||
|
fprintf (stderr, "Universal ");
|
||||||
|
else if (alg == 0x38)
|
||||||
|
fprintf (stderr, "Strengthened ");
|
||||||
|
else if (alg == 0x39)
|
||||||
|
fprintf (stderr, "Top ");
|
||||||
|
else if (alg == 0x3A)
|
||||||
|
fprintf (stderr, "Ultra ");
|
||||||
|
fprintf (stderr, "Encryption;");
|
||||||
|
fprintf (stderr, "%s", KNRM);
|
||||||
|
|
||||||
|
//flag late entry SB for Kirisun
|
||||||
|
opts->dmr_le = 3;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (MFID == 0x68) //Hytera Enhanced
|
||||||
|
{
|
||||||
|
if (state->currentslot == 0)
|
||||||
|
{
|
||||||
|
state->dmr_so |= 0x40; //OR the enc bit onto the SO
|
||||||
|
state->payload_algid = PI_BYTE[0];
|
||||||
|
state->payload_keyid = PI_BYTE[2];
|
||||||
|
state->payload_mi = ((unsigned long long int)PI_BYTE[3] << 32ULL) | ((unsigned long long int)PI_BYTE[4] << 24) |
|
||||||
|
((unsigned long long int)PI_BYTE[5] << 16) | ((unsigned long long int)PI_BYTE[6] << 8) | ((unsigned long long int)PI_BYTE[7] << 0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
state->dmr_soR |= 0x40; //OR the enc bit onto the SO
|
||||||
|
state->payload_algidR = PI_BYTE[0];
|
||||||
|
state->payload_keyidR = PI_BYTE[2];
|
||||||
|
state->payload_miR = ((unsigned long long int)PI_BYTE[3] << 32ULL) | ((unsigned long long int)PI_BYTE[4] << 24) |
|
||||||
|
((unsigned long long int)PI_BYTE[5] << 16) | ((unsigned long long int)PI_BYTE[6] << 8) | ((unsigned long long int)PI_BYTE[7] << 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf (stderr, "%s ", KYEL);
|
||||||
|
fprintf (stderr, "\n Slot %d", state->currentslot+1);
|
||||||
|
fprintf (stderr, " DMR PI H- ALG ID: %02X; KEY ID: %02X; MI(40): %02X%02X%02X%02X%02X;",
|
||||||
|
PI_BYTE[0], PI_BYTE[2], PI_BYTE[3], PI_BYTE[4], PI_BYTE[5], PI_BYTE[6], PI_BYTE[7]);
|
||||||
|
|
||||||
|
//PI_BYTE[9] is a checksum of the other bytes combined
|
||||||
|
uint8_t checksum = 0;
|
||||||
|
for (int i = 0; i < 9; i++)
|
||||||
|
{
|
||||||
|
checksum += PI_BYTE[i];
|
||||||
|
checksum &= 0xFF;
|
||||||
|
}
|
||||||
|
checksum = ~checksum & 0xFF;
|
||||||
|
checksum++;
|
||||||
|
|
||||||
|
//debug
|
||||||
|
// fprintf (stderr, " CHK: %02X / %02X;", checksum, PI_BYTE[9]);
|
||||||
|
|
||||||
|
if (checksum == PI_BYTE[9])
|
||||||
|
{
|
||||||
|
fprintf (stderr, " Hytera Enhanced; ");
|
||||||
|
|
||||||
|
if (state->currentslot == 0 && state->R != 0)
|
||||||
|
fprintf (stderr, "Key: %010llX; ", state->R);
|
||||||
|
|
||||||
|
if (state->currentslot == 1 && state->RR != 0)
|
||||||
|
fprintf (stderr, "Key: %010llX; ", state->RR);
|
||||||
|
|
||||||
|
//disable late entry for DMRA (hopefully, there aren't any systems running both DMRA and Hytera Enhanced mixed together)
|
||||||
|
opts->dmr_le = 2;
|
||||||
|
|
||||||
|
// fprintf (stderr, " (Checksum Okay);");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fprintf (stderr, "%s", KRED);
|
||||||
|
fprintf (stderr, " (Checksum Err);");
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf (stderr, "%s", KNRM);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (MFID == 0x10) //DMRA
|
||||||
|
{
|
||||||
|
|
||||||
|
if (state->currentslot == 0)
|
||||||
|
{
|
||||||
|
state->payload_algid = PI_BYTE[0];
|
||||||
|
state->payload_keyid = PI_BYTE[2];
|
||||||
|
state->payload_mi = ((unsigned long long int)PI_BYTE[3] << 24ULL) | ((unsigned long long int)PI_BYTE[4] << 16ULL) | ((unsigned long long int)PI_BYTE[5] << 8ULL) | ((unsigned long long int)PI_BYTE[6] << 0ULL);
|
||||||
|
if (state->payload_algid < 0x28)
|
||||||
{
|
{
|
||||||
fprintf (stderr, "\n");
|
fprintf (stderr, "%s ", KYEL);
|
||||||
LFSR64 (state);
|
fprintf (stderr, "\n Slot 1");
|
||||||
|
fprintf (stderr, " DMR PI H- ALG ID: %02X; KEY ID: %02X; MI(32): %08llX;", state->payload_algid, state->payload_keyid, state->payload_mi);
|
||||||
|
|
||||||
|
//check for any values that aren't 0x2X but just 0x0X
|
||||||
|
//going to be very generic here to avoid any particular vendors using 0x2X and not 0x0X
|
||||||
|
if (state->payload_algid & 0x20)
|
||||||
|
fprintf (stderr, " DMRA");
|
||||||
|
else fprintf (stderr, " DMRA Compatible");
|
||||||
|
|
||||||
|
if ((state->payload_algid & 0x07) == 0x01)
|
||||||
|
{
|
||||||
|
fprintf (stderr, " RC4;");
|
||||||
|
state->payload_algid = 0x21;
|
||||||
|
}
|
||||||
|
|
||||||
|
else if ((state->payload_algid & 0x07) == 0x02)
|
||||||
|
{
|
||||||
|
fprintf (stderr, " DES;");
|
||||||
|
state->payload_algid = 0x22;
|
||||||
|
}
|
||||||
|
|
||||||
|
else if ((state->payload_algid & 0x07) == 0x04)
|
||||||
|
{
|
||||||
|
fprintf (stderr, " AES-128;");
|
||||||
|
state->payload_algid = 0x24;
|
||||||
|
}
|
||||||
|
|
||||||
|
else if ((state->payload_algid & 0x07) == 0x05)
|
||||||
|
{
|
||||||
|
fprintf (stderr, " AES-256;");
|
||||||
|
state->payload_algid = 0x25;
|
||||||
|
}
|
||||||
|
|
||||||
|
else if ((state->payload_algid & 0x07) == 0x06)
|
||||||
|
{
|
||||||
|
fprintf (stderr, " Caltta BP;");
|
||||||
|
state->payload_algid = 0x26;
|
||||||
|
state->payload_mi = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf (stderr, "%s ", KNRM);
|
||||||
|
|
||||||
|
//expand the 32-bit MI to a 64-bit DES IV
|
||||||
|
if (state->payload_algid == 0x22)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "\n");
|
||||||
|
LFSR64 (state);
|
||||||
|
}
|
||||||
|
|
||||||
|
//expand the 32-bit MI to a 128-bit AES IV
|
||||||
|
if (state->payload_algid == 0x24 || state->payload_algid == 0x25)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "\n");
|
||||||
|
LFSR128d (state);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state->payload_algid >= 0x28)
|
||||||
|
{
|
||||||
|
state->payload_algid = 0;
|
||||||
|
state->payload_keyid = 0;
|
||||||
|
state->payload_mi = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state->payload_algid >= 0x26)
|
if (state->currentslot == 1)
|
||||||
{
|
{
|
||||||
state->payload_algid = 0;
|
|
||||||
state->payload_keyid = 0;
|
|
||||||
state->payload_mi = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (state->currentslot == 1)
|
state->payload_algidR = PI_BYTE[0];
|
||||||
{
|
state->payload_keyidR = PI_BYTE[2];
|
||||||
|
state->payload_miR = ((unsigned long long int)PI_BYTE[3] << 24ULL) | ((unsigned long long int)PI_BYTE[4] << 16ULL) | ((unsigned long long int)PI_BYTE[5] << 8ULL) | ((unsigned long long int)PI_BYTE[6] << 0ULL);
|
||||||
state->payload_algidR = PI_BYTE[0];
|
if (state->payload_algidR < 0x26)
|
||||||
state->payload_keyidR = PI_BYTE[2];
|
|
||||||
state->payload_miR = ( ((PI_BYTE[3]) << 24) + ((PI_BYTE[4]) << 16) + ((PI_BYTE[5]) << 8) + (PI_BYTE[6]) );
|
|
||||||
if (state->payload_algidR < 0x26)
|
|
||||||
{
|
|
||||||
fprintf (stderr, "%s ", KYEL);
|
|
||||||
fprintf (stderr, "\n Slot 2");
|
|
||||||
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);
|
|
||||||
if (state->payload_algidR != 0x21)
|
|
||||||
{
|
{
|
||||||
fprintf (stderr, "\n");
|
fprintf (stderr, "%s ", KYEL);
|
||||||
LFSR64 (state);
|
fprintf (stderr, "\n Slot 2");
|
||||||
|
fprintf (stderr, " DMR PI H- ALG ID: %02X; KEY ID: %02X; MI(32): %08llX;", state->payload_algidR, state->payload_keyidR, state->payload_miR);
|
||||||
|
|
||||||
|
//check for any values that aren't 0x2X but just 0x0X
|
||||||
|
//going to be very generic here to avoid any particular vendors using 0x2X and not 0x0X
|
||||||
|
if (state->payload_algidR & 0x20)
|
||||||
|
fprintf (stderr, " DMRA");
|
||||||
|
else fprintf (stderr, " DMRA Compatible");
|
||||||
|
|
||||||
|
if ((state->payload_algidR & 0x07) == 0x01)
|
||||||
|
{
|
||||||
|
fprintf (stderr, " RC4;");
|
||||||
|
state->payload_algidR = 0x21;
|
||||||
|
}
|
||||||
|
|
||||||
|
else if ((state->payload_algidR & 0x07) == 0x02)
|
||||||
|
{
|
||||||
|
fprintf (stderr, " DES;");
|
||||||
|
state->payload_algidR = 0x22;
|
||||||
|
}
|
||||||
|
|
||||||
|
else if ((state->payload_algidR & 0x07) == 0x04)
|
||||||
|
{
|
||||||
|
fprintf (stderr, " AES-128;");
|
||||||
|
state->payload_algidR = 0x24;
|
||||||
|
}
|
||||||
|
|
||||||
|
else if ((state->payload_algidR & 0x07) == 0x05)
|
||||||
|
{
|
||||||
|
fprintf (stderr, " AES-256;");
|
||||||
|
state->payload_algidR = 0x25;
|
||||||
|
}
|
||||||
|
|
||||||
|
else if ((state->payload_algidR & 0x07) == 0x06)
|
||||||
|
{
|
||||||
|
fprintf (stderr, " Caltta BP;");
|
||||||
|
state->payload_algidR = 0x26;
|
||||||
|
state->payload_miR = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf (stderr, "%s ", KNRM);
|
||||||
|
|
||||||
|
//expand the 32-bit MI to a 64-bit DES IV
|
||||||
|
if (state->payload_algidR == 0x22)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "\n");
|
||||||
|
LFSR64 (state);
|
||||||
|
}
|
||||||
|
|
||||||
|
//expand the 32-bit MI to a 128-bit AES IV
|
||||||
|
if (state->payload_algidR == 0x24 || state->payload_algidR == 0x25)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "\n");
|
||||||
|
LFSR128d (state);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (state->payload_algidR >= 0x28)
|
||||||
|
{
|
||||||
|
state->payload_algidR = 0;
|
||||||
|
state->payload_keyidR = 0;
|
||||||
|
state->payload_miR = 0;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state->payload_algidR >= 0x26)
|
} //end DMRA
|
||||||
{
|
|
||||||
state->payload_algidR = 0;
|
|
||||||
state->payload_keyidR = 0;
|
|
||||||
state->payload_miR = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LFSR(dsd_state * state)
|
void LFSR(dsd_state * state)
|
||||||
{
|
{
|
||||||
int lfsr = 0;
|
unsigned long long int lfsr = 0;
|
||||||
if (state->currentslot == 0)
|
if (state->currentslot == 0)
|
||||||
{
|
{
|
||||||
lfsr = state->payload_mi;
|
lfsr = state->payload_mi;
|
||||||
@@ -87,16 +325,19 @@ void LFSR(dsd_state * state)
|
|||||||
for(cnt=0;cnt<32;cnt++)
|
for(cnt=0;cnt<32;cnt++)
|
||||||
{
|
{
|
||||||
// Polynomial is C(x) = x^32 + x^4 + x^2 + 1
|
// Polynomial is C(x) = x^32 + x^4 + x^2 + 1
|
||||||
int bit = ((lfsr >> 31) ^ (lfsr >> 3) ^ (lfsr >> 1)) & 0x1;
|
unsigned long long int bit = ((lfsr >> 31) ^ (lfsr >> 3) ^ (lfsr >> 1)) & 0x1;
|
||||||
lfsr = (lfsr << 1) | (bit);
|
lfsr = (lfsr << 1) | bit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lfsr &= 0xFFFFFFFF;
|
||||||
|
|
||||||
if (state->currentslot == 0)
|
if (state->currentslot == 0)
|
||||||
{
|
{
|
||||||
fprintf (stderr, "%s", KYEL);
|
fprintf (stderr, "%s", KYEL);
|
||||||
fprintf (stderr, " Slot 1");
|
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, " DMR PI C- ALG ID: %02X; KEY ID: %02X;", state->payload_algid, state->payload_keyid);
|
||||||
fprintf(stderr, " MI: 0x%08X", lfsr);
|
fprintf (stderr, " MI(32): %08llX;", lfsr);
|
||||||
|
fprintf (stderr, " RC4;");
|
||||||
fprintf (stderr, "%s", KNRM);
|
fprintf (stderr, "%s", KNRM);
|
||||||
state->payload_mi = lfsr;
|
state->payload_mi = lfsr;
|
||||||
}
|
}
|
||||||
@@ -106,54 +347,268 @@ void LFSR(dsd_state * state)
|
|||||||
|
|
||||||
fprintf (stderr, "%s", KYEL);
|
fprintf (stderr, "%s", KYEL);
|
||||||
fprintf (stderr, " Slot 2");
|
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, " DMR PI C- ALG ID: %02X; KEY ID: %02X;", state->payload_algidR, state->payload_keyidR);
|
||||||
fprintf(stderr, " MI: 0x%08X", lfsr);
|
fprintf(stderr, " MI(32): %08llX;", lfsr);
|
||||||
|
fprintf (stderr, " RC4;");
|
||||||
fprintf (stderr, "%s", KNRM);
|
fprintf (stderr, "%s", KNRM);
|
||||||
state->payload_miR = lfsr;
|
state->payload_miR = lfsr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Expand a 32-bit MI into a 64-bit IV for DES
|
||||||
void LFSR64(dsd_state * state)
|
void LFSR64(dsd_state * state)
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
uint64_t lfsr = 0;
|
unsigned long long int lfsr = 0;
|
||||||
|
|
||||||
if (state->currentslot == 0)
|
if (state->currentslot == 0)
|
||||||
{
|
{
|
||||||
lfsr = (uint64_t) state->payload_mi;
|
lfsr = (uint64_t) state->payload_mi;
|
||||||
}
|
}
|
||||||
else lfsr = (uint64_t) state->payload_miR;
|
else lfsr = (uint64_t) state->payload_miR;
|
||||||
|
|
||||||
uint8_t cnt = 0;
|
uint8_t cnt = 0;
|
||||||
|
|
||||||
for(cnt=0;cnt<32;cnt++)
|
for(cnt=0;cnt<32;cnt++)
|
||||||
{
|
{
|
||||||
uint64_t bit = ( (lfsr >> 31) ^ (lfsr >> 21) ^ (lfsr >> 1) ^ (lfsr >> 0) ) & 0x1;
|
unsigned long long int bit = ( (lfsr >> 31) ^ (lfsr >> 21) ^ (lfsr >> 1) ^ (lfsr >> 0) ) & 0x1;
|
||||||
lfsr = (lfsr << 1) | bit;
|
lfsr = (lfsr << 1) | bit;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (state->currentslot == 0) state->payload_miP = lfsr;
|
if (state->currentslot == 0)
|
||||||
// else state->payload_miN = lfsr;
|
{
|
||||||
|
|
||||||
if (state->currentslot == 0)
|
|
||||||
{
|
|
||||||
fprintf (stderr, "%s", KYEL);
|
fprintf (stderr, "%s", KYEL);
|
||||||
fprintf (stderr, " Slot 1");
|
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, " DMR PI C- ALG ID: %02X; KEY ID: %02X;", state->payload_algid, state->payload_keyid);
|
||||||
fprintf (stderr, " MI: 0x%016lX", lfsr);
|
fprintf (stderr, " MI(64): %016llX;", lfsr);
|
||||||
|
fprintf (stderr, " DES;");
|
||||||
fprintf (stderr, "%s", KNRM);
|
fprintf (stderr, "%s", KNRM);
|
||||||
state->payload_mi = lfsr & 0xFFFFFFFF; //truncate for next repitition and le verification
|
state->payload_mi = lfsr & 0xFFFFFFFF; //truncate for next repitition and le verification
|
||||||
}
|
state->payload_miP = lfsr;
|
||||||
|
state->DMRvcL = 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (state->currentslot == 1)
|
if (state->currentslot == 1)
|
||||||
{
|
{
|
||||||
fprintf (stderr, "%s", KYEL);
|
fprintf (stderr, "%s", KYEL);
|
||||||
fprintf (stderr, " Slot 2");
|
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, " DMR PI C- ALG ID: %02X; KEY ID: %02X;", state->payload_algidR, state->payload_keyidR);
|
||||||
fprintf (stderr, " MI: 0x%016lX", lfsr);
|
fprintf (stderr, " MI(64): %016llX;", lfsr);
|
||||||
|
fprintf (stderr, " DES;");
|
||||||
fprintf (stderr, "%s", KNRM);
|
fprintf (stderr, "%s", KNRM);
|
||||||
state->payload_miR = lfsr & 0xFFFFFFFF; //truncate for next repitition and le verification
|
state->payload_miR = lfsr & 0xFFFFFFFF; //truncate for next repitition and le verification
|
||||||
}
|
state->payload_miN = lfsr;
|
||||||
|
state->DMRvcR = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//if supplied IV is only 32-bit in value, then expand it to a 128-bit IV using these LFSR taps (packed array)
|
||||||
|
void lfsr_32_to_128(uint8_t * iv)
|
||||||
|
{
|
||||||
|
uint64_t lfsr = 0, bit = 0;
|
||||||
|
|
||||||
|
lfsr = ((uint64_t)iv[0] << 24ULL) + ((uint64_t)iv[1] << 16ULL) + ((uint64_t)iv[2] << 8ULL) + ((uint64_t)iv[3] << 0ULL);
|
||||||
|
|
||||||
|
uint8_t cnt = 0, x = 32;
|
||||||
|
|
||||||
|
for(cnt = 0;cnt < 96; cnt++)
|
||||||
|
{
|
||||||
|
//32,22,2,1 (per Xilinx XAPP 052) Table 3: Taps for Maximum-Length LFSR Counters
|
||||||
|
bit = ( (lfsr >> 31) ^ (lfsr >> 21) ^ (lfsr >> 1) ^ (lfsr >> 0) ) & 0x1;
|
||||||
|
lfsr = (lfsr << 1) | bit;
|
||||||
|
|
||||||
|
//continue packing iv
|
||||||
|
iv[x/8] = (iv[x/8] << 1) + bit;
|
||||||
|
|
||||||
|
x++;
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf (stderr, "\n IV(128): ");
|
||||||
|
for (x = 0; x < 16; x++)
|
||||||
|
fprintf (stderr, "%02X", iv[x]);
|
||||||
|
fprintf (stderr, "\n");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//Expand a 32-bit MI into a 128-bit IV for AES
|
||||||
|
void LFSR128d(dsd_state * state)
|
||||||
|
{
|
||||||
|
unsigned long long int lfsr = 0;
|
||||||
|
|
||||||
|
if (state->currentslot == 0)
|
||||||
|
lfsr = state->payload_mi;
|
||||||
|
else lfsr = state->payload_miR;
|
||||||
|
|
||||||
|
unsigned long long int next_mi;
|
||||||
|
|
||||||
|
//start packing aes_iv
|
||||||
|
if (state->currentslot == 0)
|
||||||
|
{
|
||||||
|
state->aes_iv[0] = (lfsr >> 24) & 0xFF;
|
||||||
|
state->aes_iv[1] = (lfsr >> 16) & 0xFF;
|
||||||
|
state->aes_iv[2] = (lfsr >> 8 ) & 0xFF;
|
||||||
|
state->aes_iv[3] = (lfsr >> 0 ) & 0xFF;
|
||||||
|
}
|
||||||
|
else if (state->currentslot == 1)
|
||||||
|
{
|
||||||
|
state->aes_ivR[0] = (lfsr >> 24) & 0xFF;
|
||||||
|
state->aes_ivR[1] = (lfsr >> 16) & 0xFF;
|
||||||
|
state->aes_ivR[2] = (lfsr >> 8 ) & 0xFF;
|
||||||
|
state->aes_ivR[3] = (lfsr >> 0 ) & 0xFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
int cnt = 0; int x = 32;
|
||||||
|
unsigned long long int bit;
|
||||||
|
for(cnt=0;cnt<96;cnt++)
|
||||||
|
{
|
||||||
|
//32,22,2,1
|
||||||
|
bit = ( (lfsr >> 31) ^ (lfsr >> 21) ^ (lfsr >> 1) ^ (lfsr >> 0) ) & 0x1;
|
||||||
|
lfsr = (lfsr << 1) | bit;
|
||||||
|
|
||||||
|
//continue packing aes_iv
|
||||||
|
if (state->currentslot == 0)
|
||||||
|
state->aes_iv[x/8] = (state->aes_iv[x/8] << 1) + bit;
|
||||||
|
else if (state->currentslot == 1)
|
||||||
|
state->aes_ivR[x/8] = (state->aes_ivR[x/8] << 1) + bit;
|
||||||
|
x++;
|
||||||
|
}
|
||||||
|
|
||||||
|
//assign the next 32-bit short MI from 4,5,6,7 so it'll match up with OTA late entry
|
||||||
|
if (state->currentslot == 0)
|
||||||
|
next_mi = ((unsigned long long int)state->aes_iv[4] << 24) | ((unsigned long long int)state->aes_iv[5] << 16) |
|
||||||
|
((unsigned long long int)state->aes_iv[6] << 8) | ((unsigned long long int)state->aes_iv[7] << 0);
|
||||||
|
if (state->currentslot == 1)
|
||||||
|
next_mi = ((unsigned long long int)state->aes_ivR[4] << 24) | ((unsigned long long int)state->aes_ivR[5] << 16) |
|
||||||
|
((unsigned long long int)state->aes_ivR[6] << 8) | ((unsigned long long int)state->aes_ivR[7] << 0);
|
||||||
|
|
||||||
|
if (state->currentslot == 0)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "%s", KYEL);
|
||||||
|
fprintf (stderr, " Slot 1");
|
||||||
|
fprintf (stderr, " DMR PI C- ALG ID: %02X; KEY ID: %02X; MI(128): ", state->payload_algid, state->payload_keyid);
|
||||||
|
for (x = 0; x < 16; x++)
|
||||||
|
fprintf (stderr, "%02X", state->aes_iv[x]);
|
||||||
|
fprintf (stderr, "%s", KNRM);
|
||||||
|
fprintf (stderr, ";");
|
||||||
|
|
||||||
|
if (state->payload_algid == 0x24)
|
||||||
|
fprintf (stderr, " AES-128;");
|
||||||
|
else fprintf (stderr, " AES-256;");
|
||||||
|
|
||||||
|
state->payload_mi = next_mi;
|
||||||
|
state->DMRvcL = 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state->currentslot == 1)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "%s", KYEL);
|
||||||
|
fprintf (stderr, " Slot 2");
|
||||||
|
fprintf (stderr, " DMR PI C- ALG ID: %02X; KEY ID: %02X; MI(128): ", state->payload_algidR, state->payload_keyidR);
|
||||||
|
for (x = 0; x < 16; x++)
|
||||||
|
fprintf (stderr, "%02X", state->aes_ivR[x]);
|
||||||
|
fprintf (stderr, "%s", KNRM);
|
||||||
|
fprintf (stderr, ";");
|
||||||
|
|
||||||
|
if (state->payload_algidR == 0x24)
|
||||||
|
fprintf (stderr, " AES-128;");
|
||||||
|
else fprintf (stderr, " AES-256;");
|
||||||
|
|
||||||
|
state->payload_miR = next_mi;
|
||||||
|
state->DMRvcR = 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned long long int hytera_lfsr(uint8_t * mi, uint8_t * taps, uint8_t len)
|
||||||
|
{
|
||||||
|
|
||||||
|
for (uint8_t i = 0; i < len; i++)
|
||||||
|
{
|
||||||
|
uint8_t bit = (mi[i] >> 7) & 1;
|
||||||
|
mi[i] <<= 1;
|
||||||
|
if (bit) mi[i] ^= taps[i%len];
|
||||||
|
mi[i] |= bit;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned long long int mi_value = 0;
|
||||||
|
for (uint8_t i = 0; i < len; i++)
|
||||||
|
{
|
||||||
|
mi_value <<= 8;
|
||||||
|
mi_value |= mi[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
//debug
|
||||||
|
// fprintf (stderr, " Next MI: %010llX \n", mi_value);
|
||||||
|
|
||||||
|
return mi_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
void hytera_enhanced_alg_refresh(dsd_state * state)
|
||||||
|
{
|
||||||
|
uint8_t mi[5]; memset (mi, 0, sizeof(mi));
|
||||||
|
unsigned long long int mi_value = 0;
|
||||||
|
if (state->currentslot == 0)
|
||||||
|
mi_value = state->payload_mi;
|
||||||
|
else mi_value = state->payload_miR;
|
||||||
|
|
||||||
|
//load mi_value into mi array
|
||||||
|
mi[0] = ((mi_value & 0xFF00000000) >> 32UL);
|
||||||
|
mi[1] = ((mi_value & 0xFF000000) >> 24);
|
||||||
|
mi[2] = ((mi_value & 0xFF0000) >> 16);
|
||||||
|
mi[3] = ((mi_value & 0xFF00) >> 8);
|
||||||
|
mi[4] = ((mi_value & 0xFF) >> 0);
|
||||||
|
|
||||||
|
//calculate the next MI value
|
||||||
|
uint8_t taps[5]; memset(taps, 0, sizeof(taps));
|
||||||
|
|
||||||
|
//the tap values
|
||||||
|
taps[0] = 0x12;
|
||||||
|
taps[1] = 0x24;
|
||||||
|
taps[2] = 0x48;
|
||||||
|
taps[3] = 0x22;
|
||||||
|
taps[4] = 0x14;
|
||||||
|
mi_value = hytera_lfsr(mi, taps, 5);
|
||||||
|
|
||||||
|
if (state->currentslot == 0)
|
||||||
|
state->payload_mi = mi_value;
|
||||||
|
else state->payload_miR = mi_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t kirisun_lfsr(unsigned long long int mi)
|
||||||
|
{
|
||||||
|
|
||||||
|
uint32_t taps = 0xD459C4F1;
|
||||||
|
uint32_t lfsr = (uint32_t)mi;
|
||||||
|
uint32_t new_mi = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < 4; i++)
|
||||||
|
{
|
||||||
|
|
||||||
|
uint8_t byte = 0;
|
||||||
|
|
||||||
|
for (int j = 0; j < 8; j++)
|
||||||
|
{
|
||||||
|
uint32_t temp = (lfsr << 1);
|
||||||
|
uint8_t msb = (lfsr >> 31) & 1;
|
||||||
|
|
||||||
|
if (msb)
|
||||||
|
{
|
||||||
|
byte |= (1 << j);
|
||||||
|
lfsr = temp ^ taps;
|
||||||
|
}
|
||||||
|
else lfsr = temp; //was previously temp ^ 1, but that isn't a primitive
|
||||||
|
}
|
||||||
|
|
||||||
|
new_mi <<=8;
|
||||||
|
new_mi |= byte;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return new_mi;
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -10,7 +10,7 @@
|
|||||||
#include "dsd.h"
|
#include "dsd.h"
|
||||||
|
|
||||||
//modified to accept variable payload size and len
|
//modified to accept variable payload size and len
|
||||||
uint16_t ComputeCrcCCITT16d(const uint8_t buf[], uint8_t len)
|
uint16_t ComputeCrcCCITT16d(const uint8_t * buf, uint32_t len)
|
||||||
{
|
{
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
uint16_t CRC = 0x0000; /* Initialization value = 0x0000 */
|
uint16_t CRC = 0x0000; /* Initialization value = 0x0000 */
|
||||||
@@ -325,15 +325,15 @@ uint8_t ComputeCrc5Bit(uint8_t * DMRData)
|
|||||||
return CRC;
|
return CRC;
|
||||||
} /* End ComputeCrc5Bit() */
|
} /* End ComputeCrc5Bit() */
|
||||||
|
|
||||||
uint32_t ConvertBitIntoBytes(uint8_t * BufferIn, uint32_t BitLength)
|
uint64_t ConvertBitIntoBytes(uint8_t * BufferIn, uint32_t BitLength)
|
||||||
{
|
{
|
||||||
uint32_t Output = 0;
|
uint64_t Output = 0;
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
|
|
||||||
for(i = 0; i < BitLength; i++)
|
for(i = 0; i < BitLength; i++)
|
||||||
{
|
{
|
||||||
Output <<= 1;
|
Output <<= 1;
|
||||||
Output |= (uint32_t)(BufferIn[i] & 1);
|
Output |= (uint64_t)(BufferIn[i] & 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Output;
|
return Output;
|
||||||
@@ -438,3 +438,43 @@ uint32_t ComputeCrc32Bit(uint8_t * DMRData, uint32_t NbData)
|
|||||||
/* Return the CRC */
|
/* Return the CRC */
|
||||||
return CRC;
|
return CRC;
|
||||||
} /* End ComputeCrc32Bit() */
|
} /* End ComputeCrc32Bit() */
|
||||||
|
|
||||||
|
uint32_t ComputeCrc32BitV(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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Alternate Return Configuration for Vertex
|
||||||
|
//Encrypted PDUs that have already been reordered once before
|
||||||
|
//CRC32 CMP: 1622377A EXT: 377A1622
|
||||||
|
uint32_t a, b, c, d;
|
||||||
|
a = b = c = d = 0;
|
||||||
|
|
||||||
|
a = ((CRC >> 0) & 0xFF) << 16;
|
||||||
|
b = ((CRC >> 8) & 0xFF) << 24;
|
||||||
|
c = ((CRC >> 16) & 0xFF) << 0;
|
||||||
|
d = ((CRC >> 24) & 0xFF) << 8;
|
||||||
|
|
||||||
|
CRC = a + b + c + d;
|
||||||
|
|
||||||
|
/* Return the CRC */
|
||||||
|
return CRC;
|
||||||
|
} /* End ComputeCrc32BitV() */
|
||||||
|
|
||||||
|
|||||||
@@ -53,15 +53,10 @@ void processdPMRvoice (dsd_opts * opts, dsd_state * state)
|
|||||||
uint32_t CCH_EmergencyPriority[NB_OF_DPMR_VOICE_FRAME_TO_DECODE];
|
uint32_t CCH_EmergencyPriority[NB_OF_DPMR_VOICE_FRAME_TO_DECODE];
|
||||||
uint32_t CCH_Reserved[NB_OF_DPMR_VOICE_FRAME_TO_DECODE];
|
uint32_t CCH_Reserved[NB_OF_DPMR_VOICE_FRAME_TO_DECODE];
|
||||||
uint32_t CCH_SlowData[NB_OF_DPMR_VOICE_FRAME_TO_DECODE];
|
uint32_t CCH_SlowData[NB_OF_DPMR_VOICE_FRAME_TO_DECODE];
|
||||||
uint32_t *errs;
|
|
||||||
uint32_t *errs2;
|
|
||||||
uint8_t AmbeBitDescrambled[49] = {0};
|
|
||||||
uint32_t ScramblerKey = 0;
|
|
||||||
uint32_t PartOfSuperFrame = 0;
|
uint32_t PartOfSuperFrame = 0;
|
||||||
uint32_t VoiceFrameFlag = 1; /* We consider the current frame as a voice frame */
|
|
||||||
uint32_t AttachedDataFlag = 0;
|
|
||||||
uint8_t CalledID[8] = {0};
|
uint8_t CalledID[8] = {0};
|
||||||
uint8_t CallingID[8] = {0};
|
uint8_t CallingID[8] = {0};
|
||||||
|
UNUSED(PartOfSuperFrame);
|
||||||
|
|
||||||
/* First CCH (Control CHannel) - 72 bit */
|
/* First CCH (Control CHannel) - 72 bit */
|
||||||
k = 0;
|
k = 0;
|
||||||
@@ -381,7 +376,7 @@ void processdPMRvoice (dsd_opts * opts, dsd_state * state)
|
|||||||
fprintf (stderr, "%s", KNRM);
|
fprintf (stderr, "%s", KNRM);
|
||||||
|
|
||||||
//check other as well before assigning
|
//check other as well before assigning
|
||||||
if(state->dPMRVoiceFS2Frame.CallingIDOk) sprintf (state->dpmr_target_id, "%s", CalledID);
|
if(state->dPMRVoiceFS2Frame.CalledIDOk) sprintf (state->dpmr_target_id, "%s", CalledID);
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -478,10 +473,18 @@ void processdPMRvoice (dsd_opts * opts, dsd_state * state)
|
|||||||
//flag back off if key is provided
|
//flag back off if key is provided
|
||||||
if (state->R != 0) state->dmr_encL = 0;
|
if (state->R != 0) state->dmr_encL = 0;
|
||||||
|
|
||||||
|
//print Current Frame Number if payload verbosity enabled
|
||||||
|
if (opts->payload == 1)
|
||||||
|
fprintf (stderr, "\n FN %d/4", state->dPMRVoiceFS2Frame.FrameNumbering[o]+1);
|
||||||
|
|
||||||
//There are 4 AMBE voice frames per TCH
|
//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);
|
||||||
|
if (opts->floating_point == 0)
|
||||||
|
playSynthesizedVoiceMS(opts, state);
|
||||||
|
if (opts->floating_point == 1)
|
||||||
|
playSynthesizedVoiceFM(opts, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
//set the correct sync type again and flag off the cipher
|
//set the correct sync type again and flag off the cipher
|
||||||
|
|||||||
829
src/dsd_alias.c
Normal file
829
src/dsd_alias.c
Normal file
@@ -0,0 +1,829 @@
|
|||||||
|
/*-------------------------------------------------------------------------------
|
||||||
|
* dsd_alias.c
|
||||||
|
* Talker Alias Handling for Various Protocols and Vendors
|
||||||
|
*
|
||||||
|
* LWVMOBILE
|
||||||
|
* 2025-02 DSD-FME Florida Man Edition
|
||||||
|
*-----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#include "dsd.h"
|
||||||
|
|
||||||
|
//Motorola P25 OTA Alias Decoding ripped/demystified from Ilya Smirnov's SDRTrunk Voodoo Code
|
||||||
|
uint8_t moto_alias_lut[256] = {
|
||||||
|
0xD2, 0xF6, 0xD4, 0x2B, 0x63, 0x49, 0x94, 0x5E, 0xA7, 0x5C, 0x70, 0x69, 0xF7, 0x08, 0xB1, 0x7D,
|
||||||
|
0x38, 0xCF, 0xCC, 0xD8, 0x51, 0x8F, 0xD5, 0x93, 0x6A, 0xF3, 0xEF, 0x7E, 0xFB, 0x64, 0xF4, 0x35,
|
||||||
|
0x27, 0x07, 0x31, 0x14, 0x87, 0x98, 0x76, 0x34, 0xCA, 0x92, 0x33, 0x1B, 0x4F, 0x8C, 0x09, 0x40,
|
||||||
|
0x32, 0x36, 0x77, 0x12, 0xD3, 0xC3, 0x01, 0xAB, 0x72, 0x81, 0x95, 0xC9, 0xC0, 0xE9, 0x65, 0x52,
|
||||||
|
0x24, 0x30, 0x1C, 0xDB, 0x88, 0xE8, 0x97, 0x9D, 0x58, 0x26, 0x04, 0x39, 0xAC, 0x2A, 0x9E, 0xAA,
|
||||||
|
0x25, 0xD7, 0xCE, 0xEB, 0x96, 0xF5, 0x0E, 0x8D, 0xDC, 0xA9, 0x2F, 0xDD, 0x1F, 0xEA, 0x91, 0xB7,
|
||||||
|
0xD6, 0x89, 0x8B, 0xD1, 0xB0, 0x99, 0x13, 0x7A, 0xE7, 0x9A, 0xB5, 0x86, 0xFF, 0x46, 0x85, 0xB2,
|
||||||
|
0x73, 0xDA, 0xBF, 0xD0, 0x71, 0xCB, 0x4D, 0x80, 0x15, 0x67, 0x16, 0x1A, 0x20, 0x8E, 0x45, 0x3E,
|
||||||
|
0xF2, 0x2E, 0x66, 0x90, 0x74, 0x8A, 0x6F, 0x78, 0xBB, 0x53, 0x03, 0x11, 0x68, 0xCD, 0x44, 0x17,
|
||||||
|
0x28, 0x5F, 0x1E, 0x84, 0x75, 0x79, 0x6E, 0x9B, 0x2C, 0xBE, 0x62, 0x2D, 0xF1, 0x7C, 0xB8, 0x83,
|
||||||
|
0xD9, 0x4E, 0x6D, 0x02, 0x61, 0x3D, 0xA8, 0x06, 0xB9, 0xF8, 0x9C, 0x37, 0x3A, 0x23, 0xC1, 0x50,
|
||||||
|
0xED, 0x9F, 0xAF, 0x3B, 0xBD, 0x82, 0xBA, 0xA0, 0xDF, 0xC2, 0x47, 0x22, 0xF0, 0xEE, 0xA1, 0xFE,
|
||||||
|
0xA2, 0x10, 0x5B, 0x48, 0x57, 0xA3, 0x05, 0x60, 0x7B, 0x0D, 0xF9, 0x6C, 0xB3, 0x56, 0x4C, 0xBC,
|
||||||
|
0x29, 0xA4, 0x0F, 0xEC, 0xB6, 0xA5, 0xA6, 0x3C, 0x7F, 0x6B, 0xB4, 0x21, 0xAD, 0xAE, 0xC4, 0xC8,
|
||||||
|
0xC5, 0x5D, 0xDE, 0xE0, 0x1D, 0x19, 0x4B, 0xC6, 0x0C, 0x3F, 0x5A, 0xC7, 0xE1, 0x59, 0x55, 0x54,
|
||||||
|
0x4A, 0x43, 0x42, 0xE2, 0xE3, 0xFA, 0x00, 0xE4, 0xE5, 0x18, 0x41, 0x0B, 0x0A, 0xE6, 0xFC, 0xFD
|
||||||
|
};
|
||||||
|
|
||||||
|
void apx_embedded_alias_test_phase1 (dsd_opts * opts, dsd_state * state)
|
||||||
|
{
|
||||||
|
|
||||||
|
uint64_t temp_a = 0x15902D2806010005; uint64_t temp_b = 0xDE; //72 bits, so break into segments
|
||||||
|
uint8_t lcw[72]; memset (lcw, 0, sizeof(lcw));
|
||||||
|
for (uint64_t i = 0; i < 64; i++)
|
||||||
|
lcw[i] = (temp_a >> (63-i)) & 1;
|
||||||
|
for (uint64_t i = 0; i < 8; i++)
|
||||||
|
lcw[i+64] = (temp_b >> (7-i)) & 1;
|
||||||
|
p25_lcw(opts, state, lcw, 0);
|
||||||
|
|
||||||
|
temp_a = 0x1790010BEE0740F0; temp_b = 0x4E;
|
||||||
|
memset (lcw, 0, sizeof(lcw));
|
||||||
|
for (uint64_t i = 0; i < 64; i++)
|
||||||
|
lcw[i] = (temp_a >> (63-i)) & 1;
|
||||||
|
for (uint64_t i = 0; i < 8; i++)
|
||||||
|
lcw[i+64] = (temp_b >> (7-i)) & 1;
|
||||||
|
p25_lcw(opts, state, lcw, 0);
|
||||||
|
|
||||||
|
temp_a = 0x17900200DD2D2168; temp_b = 0x1A;
|
||||||
|
memset (lcw, 0, sizeof(lcw));
|
||||||
|
for (uint64_t i = 0; i < 64; i++)
|
||||||
|
lcw[i] = (temp_a >> (63-i)) & 1;
|
||||||
|
for (uint64_t i = 0; i < 8; i++)
|
||||||
|
lcw[i+64] = (temp_b >> (7-i)) & 1;
|
||||||
|
p25_lcw(opts, state, lcw, 0);
|
||||||
|
|
||||||
|
temp_a = 0x17900301B52FFBFB; temp_b = 0xFE;
|
||||||
|
memset (lcw, 0, sizeof(lcw));
|
||||||
|
for (uint64_t i = 0; i < 64; i++)
|
||||||
|
lcw[i] = (temp_a >> (63-i)) & 1;
|
||||||
|
for (uint64_t i = 0; i < 8; i++)
|
||||||
|
lcw[i+64] = (temp_b >> (7-i)) & 1;
|
||||||
|
p25_lcw(opts, state, lcw, 0);
|
||||||
|
|
||||||
|
temp_a = 0x1790040E53FE86BE; temp_b = 0xF7;
|
||||||
|
memset (lcw, 0, sizeof(lcw));
|
||||||
|
for (uint64_t i = 0; i < 64; i++)
|
||||||
|
lcw[i] = (temp_a >> (63-i)) & 1;
|
||||||
|
for (uint64_t i = 0; i < 8; i++)
|
||||||
|
lcw[i+64] = (temp_b >> (7-i)) & 1;
|
||||||
|
p25_lcw(opts, state, lcw, 0);
|
||||||
|
|
||||||
|
temp_a = 0x17900508FD5AB910; temp_b = 0xB2;
|
||||||
|
memset (lcw, 0, sizeof(lcw));
|
||||||
|
for (uint64_t i = 0; i < 64; i++)
|
||||||
|
lcw[i] = (temp_a >> (63-i)) & 1;
|
||||||
|
for (uint64_t i = 0; i < 8; i++)
|
||||||
|
lcw[i+64] = (temp_b >> (7-i)) & 1;
|
||||||
|
p25_lcw(opts, state, lcw, 0);
|
||||||
|
|
||||||
|
temp_a = 0x1790060376F9D800; temp_b = 0x00;
|
||||||
|
memset (lcw, 0, sizeof(lcw));
|
||||||
|
for (uint64_t i = 0; i < 64; i++)
|
||||||
|
lcw[i] = (temp_a >> (63-i)) & 1;
|
||||||
|
for (uint64_t i = 0; i < 8; i++)
|
||||||
|
lcw[i+64] = (temp_b >> (7-i)) & 1;
|
||||||
|
p25_lcw(opts, state, lcw, 0);
|
||||||
|
|
||||||
|
//Harris Phase 1 GPS
|
||||||
|
state->lastsrc = 1000;
|
||||||
|
temp_a = 0x2AA41D4C24262328; temp_b = 0xAF;
|
||||||
|
memset (lcw, 0, sizeof(lcw));
|
||||||
|
for (uint64_t i = 0; i < 64; i++)
|
||||||
|
lcw[i] = (temp_a >> (63-i)) & 1;
|
||||||
|
for (uint64_t i = 0; i < 8; i++)
|
||||||
|
lcw[i+64] = (temp_b >> (7-i)) & 1;
|
||||||
|
p25_lcw(opts, state, lcw, 0);
|
||||||
|
|
||||||
|
temp_a = 0x2BA44E0DB2660108; temp_b = 0x14;
|
||||||
|
memset (lcw, 0, sizeof(lcw));
|
||||||
|
for (uint64_t i = 0; i < 64; i++)
|
||||||
|
lcw[i] = (temp_a >> (63-i)) & 1;
|
||||||
|
for (uint64_t i = 0; i < 8; i++)
|
||||||
|
lcw[i+64] = (temp_b >> (7-i)) & 1;
|
||||||
|
p25_lcw(opts, state, lcw, 0);
|
||||||
|
state->lastsrc = 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void apx_embedded_alias_header_phase1 (dsd_opts * opts, dsd_state * state, uint8_t slot, uint8_t * lc_bits)
|
||||||
|
{
|
||||||
|
|
||||||
|
UNUSED(opts);
|
||||||
|
uint8_t ta_len = (uint8_t)ConvertBitIntoBytes(&lc_bits[32], 8); //len in blocks of associated talker alias
|
||||||
|
uint8_t sn = (uint8_t)ConvertBitIntoBytes(&lc_bits[56], 4);
|
||||||
|
fprintf (stderr, " SN: %X;", sn);
|
||||||
|
fprintf (stderr, " BN: 0/%d;", ta_len);
|
||||||
|
|
||||||
|
//use dmr_pdu_sf for storage, store entire header (will be used to verify complete reception of full alias)
|
||||||
|
memset (state->dmr_pdu_sf[slot], 0, sizeof (state->dmr_pdu_sf[slot])); //reset storage for header and blocks
|
||||||
|
memcpy (state->dmr_pdu_sf[slot], lc_bits, 72*sizeof(uint8_t));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void apx_embedded_alias_blocks_phase1 (dsd_opts * opts, dsd_state * state, uint8_t slot, uint8_t * lc_bits)
|
||||||
|
{
|
||||||
|
|
||||||
|
UNUSED(opts);
|
||||||
|
uint8_t bn = (uint8_t)ConvertBitIntoBytes(&lc_bits[16], 8); //current block number
|
||||||
|
uint8_t sn = (uint8_t)ConvertBitIntoBytes(&lc_bits[24], 4); //is a static value on all block sequences
|
||||||
|
uint8_t ta_len = (uint8_t)ConvertBitIntoBytes(&state->dmr_pdu_sf[slot][32], 8); //len in blocks pulled from stored header
|
||||||
|
uint16_t header = (uint16_t)ConvertBitIntoBytes(&state->dmr_pdu_sf[slot][0], 16); //header check, should be 0x1590
|
||||||
|
|
||||||
|
if (ta_len == 0 || header != 0x1590) //checkdown, make sure we have an up to date header for this with a good len value
|
||||||
|
{
|
||||||
|
fprintf (stderr, " Missing Header");
|
||||||
|
fprintf (stderr, " BN: %d/??;", bn);
|
||||||
|
fprintf (stderr, " SN: %X;", sn);
|
||||||
|
fprintf (stderr, " Partial: ");
|
||||||
|
for (uint8_t i = 7; i < 18; i++)
|
||||||
|
fprintf (stderr, "%0X", (uint8_t)ConvertBitIntoBytes(&lc_bits[0+(i*4)], 4));
|
||||||
|
|
||||||
|
//clear out now stale storage
|
||||||
|
memset (state->dmr_pdu_sf[slot], 0, sizeof (state->dmr_pdu_sf[slot]));
|
||||||
|
}
|
||||||
|
|
||||||
|
else //good len and header stored
|
||||||
|
{
|
||||||
|
|
||||||
|
//sanity check, bn cannot equal zero (this shouldn't happen, but bad decode could occur)
|
||||||
|
if (bn == 0) bn = 1;
|
||||||
|
|
||||||
|
fprintf (stderr, " SN: %X;", sn);
|
||||||
|
fprintf (stderr, " BN: %d/%d;", bn, ta_len);
|
||||||
|
|
||||||
|
//use dmr_pdu_sf for storage, store data relevant portion at ptr of (bn-1) * 44 + 72 offset for header
|
||||||
|
memcpy(state->dmr_pdu_sf[slot]+(((bn-1)*44)+72), lc_bits+28, 44*sizeof(uint8_t));
|
||||||
|
|
||||||
|
if (ta_len == bn) //this is the last block, proceed to decoding
|
||||||
|
{
|
||||||
|
|
||||||
|
//Calculate variable len bits determined by non-zero octets
|
||||||
|
int16_t num_bits = 56; //starting value is the static bit count on the fqsuid
|
||||||
|
|
||||||
|
// //evaluate the storage and determine how many octets/bits are present at this point (fall back to this if needed)
|
||||||
|
// for (int16_t i = 0; i < 368; i++) //(3072-128)/8
|
||||||
|
// {
|
||||||
|
// uint8_t byte = (uint8_t)ConvertBitIntoBytes(&state->dmr_pdu_sf[slot][72+56+(i*8)], 8);
|
||||||
|
// if (byte == 0)
|
||||||
|
// break;
|
||||||
|
// else
|
||||||
|
// num_bits += 8;
|
||||||
|
// }
|
||||||
|
|
||||||
|
//evaluate the storage and determine how many octets/bits are present at this point (expanded to two octets each, CRC with a 00xx pattern failed this)
|
||||||
|
for (int16_t i = 0; i < 184; i++) //(3072-128)/16
|
||||||
|
{
|
||||||
|
uint16_t bytes = (uint16_t)ConvertBitIntoBytes(&state->dmr_pdu_sf[slot][72+56+(i*16)], 16);
|
||||||
|
if (bytes == 0)
|
||||||
|
break;
|
||||||
|
else
|
||||||
|
num_bits += 16;
|
||||||
|
}
|
||||||
|
|
||||||
|
//pass to alias decoder
|
||||||
|
apx_embedded_alias_decode (opts, state, slot, num_bits, state->dmr_pdu_sf[slot]);
|
||||||
|
|
||||||
|
//clear out now stale storage
|
||||||
|
memset (state->dmr_pdu_sf[slot], 0, sizeof(state->dmr_pdu_sf[slot]));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void apx_embedded_alias_header_phase2 (dsd_opts * opts, dsd_state * state, uint8_t slot, uint8_t * lc_bits)
|
||||||
|
{
|
||||||
|
|
||||||
|
UNUSED(opts);
|
||||||
|
uint8_t ta_len = (uint8_t)ConvertBitIntoBytes(&lc_bits[40], 8);
|
||||||
|
uint8_t sn = (uint8_t)ConvertBitIntoBytes(&lc_bits[64], 4);
|
||||||
|
uint8_t bn = (uint8_t)ConvertBitIntoBytes(&lc_bits[56], 8);
|
||||||
|
fprintf (stderr, " SN: %X;", sn); //NOTE: vPDU header is also a partial block, and has a block num and SN value in it
|
||||||
|
fprintf (stderr, " BN: %d/%d;", bn, ta_len);
|
||||||
|
|
||||||
|
//bit array to rearrange input lc_bits from phase 2 input to match the phase 1 header and block handling
|
||||||
|
uint8_t bits[136]; memset(bits, 0, sizeof(bits));
|
||||||
|
memcpy (bits, lc_bits, 2*8*sizeof(uint8_t)); //header 0x9190
|
||||||
|
memcpy (bits+16, lc_bits+24, 4*8*sizeof(uint8_t)); //BN, SN, etc
|
||||||
|
memcpy (bits+56, lc_bits+56, 10*8*sizeof(uint8_t)); //adding 8 bits of extra padding here
|
||||||
|
|
||||||
|
int16_t alias_st = 136; //start of the encoded alias (the copied size of this header, basically)
|
||||||
|
|
||||||
|
//debug, dump header arranged at this end
|
||||||
|
// fprintf (stderr, " Header: ");
|
||||||
|
// for (int16_t i = 0; i < alias_st/8; i++) //double check and adjust
|
||||||
|
// fprintf (stderr, "%02X", (uint8_t)ConvertBitIntoBytes(&bits[0+(i*8)], 8));
|
||||||
|
|
||||||
|
//use dmr_pdu_sf for storage, store entire header (will be used to verify complete reception of full alias)
|
||||||
|
memset (state->dmr_pdu_sf[slot], 0, sizeof (state->dmr_pdu_sf[slot])); //reset storage for header and blocks
|
||||||
|
memcpy (state->dmr_pdu_sf[slot], bits, alias_st*sizeof(uint8_t)); //this header block has 128 bits of relevant data (through the fqsuid)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void apx_embedded_alias_blocks_phase2 (dsd_opts * opts, dsd_state * state, uint8_t slot, uint8_t * lc_bits)
|
||||||
|
{
|
||||||
|
|
||||||
|
UNUSED(opts);
|
||||||
|
int16_t rel_bits = 100; //number of relevant bits in each block
|
||||||
|
int16_t rel_st = 36; //start of relevant bits in this block
|
||||||
|
int16_t alias_st = 136; //start of the encoded alias
|
||||||
|
uint8_t bn = (uint8_t)ConvertBitIntoBytes(&lc_bits[24], 8); //current block number
|
||||||
|
uint8_t sn = (uint8_t)ConvertBitIntoBytes(&lc_bits[32], 4); //is a static value on all block sequences
|
||||||
|
uint8_t ta_len = (uint8_t)ConvertBitIntoBytes(&state->dmr_pdu_sf[slot][32], 8); //len in blocks pulled from stored header
|
||||||
|
uint16_t header = (uint16_t)ConvertBitIntoBytes(&state->dmr_pdu_sf[slot][0], 16); //header check, should be 0x9190
|
||||||
|
|
||||||
|
if (ta_len == 0 || header != 0x9190)
|
||||||
|
{
|
||||||
|
fprintf (stderr, " Missing Header");
|
||||||
|
fprintf (stderr, " BN: %d/??;", bn);
|
||||||
|
fprintf (stderr, " SN: %X;", sn);
|
||||||
|
fprintf (stderr, " Partial: ");
|
||||||
|
for (uint8_t i = 9; i < 32; i++) //double check and adjust
|
||||||
|
fprintf (stderr, "%0X", (uint8_t)ConvertBitIntoBytes(&lc_bits[0+(i*4)], 4));
|
||||||
|
|
||||||
|
//clear out now stale storage
|
||||||
|
memset (state->dmr_pdu_sf[slot], 0, sizeof(state->dmr_pdu_sf[slot]));
|
||||||
|
}
|
||||||
|
|
||||||
|
else //good len and header stored
|
||||||
|
{
|
||||||
|
|
||||||
|
//sanity check, bn cannot equal zero (this shouldn't happen, but bad decode could occur)
|
||||||
|
if (bn == 0) bn = 1;
|
||||||
|
|
||||||
|
fprintf (stderr, " SN: %X;", sn);
|
||||||
|
fprintf (stderr, " BN: %d/%d;", bn, ta_len);
|
||||||
|
|
||||||
|
//use dmr_pdu_sf for storage, store data relevant portion at ptr calculated below
|
||||||
|
memcpy(state->dmr_pdu_sf[slot]+(alias_st+((bn-1)*rel_bits)), lc_bits+rel_st, rel_bits*sizeof(uint8_t)); //Fix this value when samples arrive
|
||||||
|
|
||||||
|
//debug, dump accumulated data at this end
|
||||||
|
// fprintf (stderr, " Accumulated: ");
|
||||||
|
// for (int16_t i = 0; i < (alias_st+(rel_bits*bn))/8; i++) //double check and adjust
|
||||||
|
// fprintf (stderr, "%02X", (uint8_t)ConvertBitIntoBytes(&state->dmr_pdu_sf[slot][0+(i*8)], 8));
|
||||||
|
|
||||||
|
if (ta_len == bn) //this is the last block, proceed to decoding
|
||||||
|
{
|
||||||
|
|
||||||
|
//Calculate variable len bits determined by non-zero octets
|
||||||
|
int16_t num_bits = 56; //starting value is the static bit count on the fqsuid
|
||||||
|
|
||||||
|
// //evaluate the storage and determine how many octets/bits are present at this point (fall back to this if needed)
|
||||||
|
// for (int16_t i = 0; i < 368; i++) //(3072-128)/8
|
||||||
|
// {
|
||||||
|
// uint8_t byte = (uint8_t)ConvertBitIntoBytes(&state->dmr_pdu_sf[slot][72+56+(i*8)], 8);
|
||||||
|
// if (byte == 0)
|
||||||
|
// break;
|
||||||
|
// else
|
||||||
|
// num_bits += 8;
|
||||||
|
// }
|
||||||
|
|
||||||
|
//evaluate the storage and determine how many octets/bits are present at this point (expanded to two octets each, CRC with a 00xx pattern failed this)
|
||||||
|
for (int16_t i = 0; i < 184; i++) //(3072-128)/16
|
||||||
|
{
|
||||||
|
uint16_t bytes = (uint16_t)ConvertBitIntoBytes(&state->dmr_pdu_sf[slot][72+56+(i*16)], 16);
|
||||||
|
if (bytes == 0)
|
||||||
|
break;
|
||||||
|
else
|
||||||
|
num_bits += 16;
|
||||||
|
}
|
||||||
|
|
||||||
|
//pass to alias decoder
|
||||||
|
apx_embedded_alias_decode (opts, state, slot, num_bits, state->dmr_pdu_sf[slot]);
|
||||||
|
|
||||||
|
//clear out now stale storage
|
||||||
|
memset (state->dmr_pdu_sf[slot], 0, sizeof (state->dmr_pdu_sf[slot]));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void apx_embedded_alias_decode (dsd_opts * opts, dsd_state * state, uint8_t slot, int16_t num_bits, uint8_t * input)
|
||||||
|
{
|
||||||
|
|
||||||
|
UNUSED(opts);
|
||||||
|
UNUSED(state);
|
||||||
|
UNUSED(slot);
|
||||||
|
|
||||||
|
//debug, dump completed data set
|
||||||
|
// fprintf (stderr, "\n Full: ");
|
||||||
|
// for (int16_t i = 0; i < (72+num_bits)/4; i++)
|
||||||
|
// fprintf (stderr, "%X", (uint8_t)ConvertBitIntoBytes(&input[0+(i*4)], 4));
|
||||||
|
|
||||||
|
//extract CRC
|
||||||
|
uint16_t crc_ext = (uint16_t)ConvertBitIntoBytes(&input[(72+num_bits-16)], 16);
|
||||||
|
|
||||||
|
//compute CRC
|
||||||
|
uint16_t crc_cmp = ComputeCrcCCITT16d(&input[72], num_bits-16);
|
||||||
|
|
||||||
|
//print comparison
|
||||||
|
// fprintf (stderr, " CRC EXT: %04X CMP: %04X;", crc_ext, crc_cmp);
|
||||||
|
if (crc_ext != crc_cmp)
|
||||||
|
fprintf (stderr, " Alias CRC Error;");
|
||||||
|
// else fprintf (stderr, " Alias Okay;");
|
||||||
|
|
||||||
|
//start decoding the alias
|
||||||
|
if (crc_ext == crc_cmp)
|
||||||
|
{
|
||||||
|
|
||||||
|
//extract fully qualified SUID
|
||||||
|
uint32_t wacn = (uint32_t)ConvertBitIntoBytes(&input[72], 20);
|
||||||
|
uint32_t sys = (uint32_t)ConvertBitIntoBytes(&input[92], 12);
|
||||||
|
uint32_t rid = (uint32_t)ConvertBitIntoBytes(&input[104], 24);
|
||||||
|
|
||||||
|
//print fully qualified SUID
|
||||||
|
fprintf (stderr, "\n FQ-SUID: %05X.%03X.%06X (%d);", wacn, sys, rid, rid);
|
||||||
|
|
||||||
|
//WIP: Working, needs more samples to verify various num_bits values
|
||||||
|
uint16_t ptr = 128; //starting point of encoded alias
|
||||||
|
uint8_t encoded[200]; memset(encoded, 0, sizeof(encoded));
|
||||||
|
uint8_t decoded[200]; memset(decoded, 0, sizeof(decoded));
|
||||||
|
uint16_t num_bytes = (num_bits / 8) - 9; //subtract 2 CRC and 7 FQSUID
|
||||||
|
|
||||||
|
//sanity check
|
||||||
|
if (num_bytes <= 0) num_bytes = 1;
|
||||||
|
|
||||||
|
for (int16_t i = 0; i < num_bytes; i++)
|
||||||
|
{
|
||||||
|
encoded[i] = (uint8_t)ConvertBitIntoBytes(&input[ptr], 8);
|
||||||
|
ptr += 8;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t accumulator = num_bytes;
|
||||||
|
|
||||||
|
//Ilya's Voodoo Code
|
||||||
|
for (uint16_t i = 0; i < num_bytes; i++)
|
||||||
|
{
|
||||||
|
// Multiplication step 1
|
||||||
|
uint16_t accum_mult = accumulator * 293 + 0x72E9;
|
||||||
|
|
||||||
|
// Lookup table step
|
||||||
|
uint8_t lut = moto_alias_lut[encoded[i]];
|
||||||
|
uint8_t mult1 = lut - (accum_mult >> 8);
|
||||||
|
|
||||||
|
// Incrementing step
|
||||||
|
uint8_t mult2 = 1;
|
||||||
|
uint8_t shortstop = accum_mult | 0x1;
|
||||||
|
uint8_t increment = shortstop << 1;
|
||||||
|
|
||||||
|
//clang warning -- warning: result of comparison of constant -1 with expression of type 'uint8_t' (aka 'unsigned char') is always true [-Wtautological-constant-out-of-range-compare]
|
||||||
|
// while(mult2 != -1 && shortstop != 1) //clang warning can't be -1 if uint8_t (set to 255 instead?)
|
||||||
|
while(shortstop != 1) //this one tests out okay, so may use it instead
|
||||||
|
{
|
||||||
|
shortstop += increment;
|
||||||
|
mult2 += 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Multiplication step 2
|
||||||
|
decoded[i] = mult1 * mult2;
|
||||||
|
|
||||||
|
// Update the accumulator
|
||||||
|
accumulator += encoded[i] + 1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// //debug, dump just the encoded alias portion
|
||||||
|
// fprintf (stderr, "\n Encoded: ");
|
||||||
|
// for (int16_t i = 0; i < num_bytes; i++)
|
||||||
|
// fprintf (stderr, "%02X", encoded[i]);
|
||||||
|
|
||||||
|
// //debug, dump the decoded payload as hex octets
|
||||||
|
// fprintf (stderr, "\n Decoded: ");
|
||||||
|
// for (int16_t i = 0; i < num_bytes; i++)
|
||||||
|
// fprintf (stderr, "%02X", decoded[i]);
|
||||||
|
|
||||||
|
//dump the decoded payload as long chars
|
||||||
|
// fprintf (stderr, "\n");
|
||||||
|
fprintf (stderr, " Alias: ");
|
||||||
|
for (int16_t i = 0; i < num_bytes/2; i++)
|
||||||
|
fprintf (stderr, "%lc", ((decoded[(i*2)+0])<<8) | ((decoded[(i*2)+1])<<0) );
|
||||||
|
|
||||||
|
apx_embedded_alias_dump (opts, state, slot, num_bytes, input, decoded);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void apx_embedded_alias_dump (dsd_opts * opts, dsd_state * state, uint8_t slot, uint16_t num_bytes, uint8_t * input, uint8_t * decoded)
|
||||||
|
{
|
||||||
|
|
||||||
|
char str[50]; memset(str, 0, sizeof(str));
|
||||||
|
char fqs[50]; memset(fqs, 0, sizeof(fqs));
|
||||||
|
|
||||||
|
//check num_bytes, if greter than 100, then set to 100
|
||||||
|
if (num_bytes >= 98) num_bytes = 98;
|
||||||
|
|
||||||
|
for (int16_t i = 0; i < num_bytes/2; i++)
|
||||||
|
{
|
||||||
|
if (decoded[(i*2)+1] == 0x2C) //remove a comma if it exists, change it to a 0x2E dot
|
||||||
|
str[i] = 0x2E;
|
||||||
|
else if (decoded[(i*2)+1] > 0x1F && decoded[(i*2)+1] < 0x7F) //may not need or use this restriction
|
||||||
|
str[i] = decoded[(i*2)+1];
|
||||||
|
else str[i] = 0x20; //space
|
||||||
|
}
|
||||||
|
|
||||||
|
//flag to indicate this already exists in import or group struct
|
||||||
|
uint8_t wr = 0;
|
||||||
|
|
||||||
|
//fully qualified SUID
|
||||||
|
uint32_t wacn = (uint32_t)ConvertBitIntoBytes(&input[72], 20);
|
||||||
|
uint32_t sys = (uint32_t)ConvertBitIntoBytes(&input[92], 12);
|
||||||
|
uint32_t rid = (uint32_t)ConvertBitIntoBytes(&input[104], 24);
|
||||||
|
|
||||||
|
sprintf (fqs, " FQ-SUID: %05X:%03X.%06X (%d);", wacn, sys, rid, rid);
|
||||||
|
if (rid != 0 && state->event_history_s[slot].Event_History_Items[0].source_id == rid)
|
||||||
|
{
|
||||||
|
sprintf (state->event_history_s[slot].Event_History_Items[0].alias, "%s; ", str);
|
||||||
|
strcat (state->event_history_s[slot].Event_History_Items[0].alias, fqs);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int16_t i = 0; i < state->group_tally; i++)
|
||||||
|
{
|
||||||
|
if (state->group_array[i].groupNumber == rid)
|
||||||
|
{
|
||||||
|
wr = 1; //already in there, so no need to assign it
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (wr == 0) //not already in there, so save it there now
|
||||||
|
{
|
||||||
|
state->group_array[state->group_tally].groupNumber = rid;
|
||||||
|
sprintf (state->group_array[state->group_tally].groupMode, "%s", "D");
|
||||||
|
sprintf (state->group_array[state->group_tally].groupName, "%s", str);
|
||||||
|
state->group_tally++;
|
||||||
|
|
||||||
|
//if we have an opened group file, let's write what info we found into it
|
||||||
|
if (opts->group_in_file[0] != 0) //file is available
|
||||||
|
{
|
||||||
|
FILE * pFile; //file pointer
|
||||||
|
//open file by name that is supplied in the ncurses terminal, or cli
|
||||||
|
pFile = fopen (opts->group_in_file, "a");
|
||||||
|
fprintf (pFile, "%d,D,", rid); //may want to not use this one
|
||||||
|
fprintf (pFile, "%s", str);
|
||||||
|
fprintf (pFile, ",FQS:%05X.%03X.%06X(%d),Moto\n", wacn, sys, rid, rid);
|
||||||
|
fclose (pFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//end Motorola P25 OTA Alias Decoding
|
||||||
|
|
||||||
|
//TODO: Migrate Other OTA Alias functions here
|
||||||
|
|
||||||
|
void l3h_embedded_alias_blocks_phase1 (dsd_opts * opts, dsd_state * state, uint8_t slot, uint8_t * lc_bits)
|
||||||
|
{
|
||||||
|
|
||||||
|
uint8_t op = (uint8_t)ConvertBitIntoBytes(&lc_bits[0], 8);
|
||||||
|
uint8_t ptr = op-0x32;
|
||||||
|
uint8_t bytes[7]; memset(bytes, 0, sizeof(bytes));
|
||||||
|
for (uint8_t i = 0; i < 7; i++)
|
||||||
|
bytes[i] = (uint8_t)ConvertBitIntoBytes(&lc_bits[16+(i*8)], 8);
|
||||||
|
|
||||||
|
//use +4 offset to match the MAC vPDU since that was already worked out long ago
|
||||||
|
memcpy(state->dmr_pdu_sf[slot]+4+(ptr*7), bytes, sizeof(bytes));
|
||||||
|
|
||||||
|
//to be tested
|
||||||
|
if (ptr == 4) //is there always 4 blocks, or is it a variable amount?
|
||||||
|
l3h_embedded_alias_decode(opts, state, slot, 4+28, state->dmr_pdu_sf[slot]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void l3h_embedded_alias_decode (dsd_opts * opts, dsd_state * state, uint8_t slot, int16_t len, uint8_t * input)
|
||||||
|
{
|
||||||
|
|
||||||
|
//storage info for storing to groupName, if not available
|
||||||
|
char str[40]; memset (str, 0, sizeof(str));
|
||||||
|
char ttemp[40]; memset (ttemp, 0, sizeof(ttemp));
|
||||||
|
uint8_t wr = 0;
|
||||||
|
uint32_t tsrc = 0, ttg = 0;
|
||||||
|
if (slot == 0 && state->lastsrc != 0) tsrc = state->lastsrc;
|
||||||
|
if (slot == 1 && state->lastsrcR != 0) tsrc = state->lastsrcR;
|
||||||
|
if (slot == 0 && state->lasttg != 0) ttg = state->lasttg;
|
||||||
|
if (slot == 1 && state->lasttgR != 0) ttg = state->lasttgR;
|
||||||
|
|
||||||
|
int8_t ptr = 0;
|
||||||
|
if (tsrc != 0)
|
||||||
|
fprintf (stderr, " TG: %d; SRC: %d; Talker Alias: ", ttg, tsrc);
|
||||||
|
else fprintf (stderr, " TG: UNK; SRC: UNK; Talker Alias: ");
|
||||||
|
for (int8_t i = 4; i <= len; i++)
|
||||||
|
{
|
||||||
|
if ( (input[i] > 0x19) && (input[i] < 0x7F) )
|
||||||
|
fprintf (stderr, "%c", (char)input[i]);
|
||||||
|
else fprintf (stderr, " ");
|
||||||
|
|
||||||
|
if (input[i] == 0x2C) //remove a comma if it exists, change it to a 0x2E dot
|
||||||
|
ttemp[ptr] = 0x2E;
|
||||||
|
else if ( (input[i] > 0x19) && (input[i] < 0x7F) )
|
||||||
|
ttemp[ptr] = input[i];
|
||||||
|
else if (input[i] != 0)
|
||||||
|
ttemp[ptr] = 0x20; //space
|
||||||
|
|
||||||
|
ptr++;
|
||||||
|
}
|
||||||
|
|
||||||
|
//assign completed talker to a more useful string instead
|
||||||
|
snprintf (str, ptr+1, "%s", ttemp);
|
||||||
|
|
||||||
|
if (state->event_history_s[slot].Event_History_Items[0].source_id == tsrc && tsrc != 0)
|
||||||
|
sprintf (state->event_history_s[slot].Event_History_Items[0].alias, "%s", str);
|
||||||
|
|
||||||
|
//The Duke Energy system may relay two src values, may be a good idea to pick one and stick with it
|
||||||
|
if (tsrc != 0)
|
||||||
|
{
|
||||||
|
for (int16_t i = 0; i < state->group_tally; i++)
|
||||||
|
{
|
||||||
|
if (state->group_array[i].groupNumber == tsrc)
|
||||||
|
{
|
||||||
|
wr = 1; //already in there, so no need to assign it
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (wr == 0) //not already in there, so save it there now
|
||||||
|
{
|
||||||
|
state->group_array[state->group_tally].groupNumber = tsrc;
|
||||||
|
sprintf (state->group_array[state->group_tally].groupMode, "%s", "D");
|
||||||
|
sprintf (state->group_array[state->group_tally].groupName, "%s", str);
|
||||||
|
state->group_tally++;
|
||||||
|
|
||||||
|
//if we have an opened group file, let's write what info we found into it
|
||||||
|
if (opts->group_in_file[0] != 0) //file is available
|
||||||
|
{
|
||||||
|
FILE * pFile; //file pointer
|
||||||
|
//open file by name that is supplied in the ncurses terminal, or cli
|
||||||
|
pFile = fopen (opts->group_in_file, "a");
|
||||||
|
fprintf (pFile, "%d,D,", tsrc);
|
||||||
|
fprintf (pFile, "%s", str);
|
||||||
|
fprintf (pFile, ",TG:%d,SYS:%03llX,RFSS:%lld,SITE:%lld,Harris\n", ttg, state->p2_sysid, state->p2_rfssid, state->p2_siteid);
|
||||||
|
fclose (pFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//debug
|
||||||
|
// fprintf (stderr, "\n WR: %d TG: %d SRC: %d Res: %d Len: %d STR: %s", wr, ttg, tsrc, res, len, str);
|
||||||
|
|
||||||
|
//reset storage
|
||||||
|
memset (state->dmr_pdu_sf[slot], 0, sizeof (state->dmr_pdu_sf[slot]));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void tait_iso7_embedded_alias_decode (dsd_opts * opts, dsd_state * state, uint8_t slot, int16_t len, uint8_t * input)
|
||||||
|
{
|
||||||
|
|
||||||
|
UNUSED(slot);
|
||||||
|
uint8_t alias[24]; memset(alias, 0, sizeof(alias));
|
||||||
|
for (uint8_t i = 0; i < len; i++)
|
||||||
|
{
|
||||||
|
alias[i] = (uint8_t)ConvertBitIntoBytes(&input[16+(i*7)], 7);
|
||||||
|
|
||||||
|
// fprintf (stderr, "%X,", alias[i]); //debug
|
||||||
|
|
||||||
|
if (alias[i] == 0x2C) //change a comma to a dot
|
||||||
|
alias[i] = 0x2E;
|
||||||
|
else if (alias[i] < 0x20) //change any garble / control chars to a space
|
||||||
|
alias[i] = 0x20;
|
||||||
|
|
||||||
|
fprintf (stderr, "%c", alias[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
//flag to indicate this already exists in import or group struct
|
||||||
|
uint8_t wr = 0;
|
||||||
|
uint32_t rid = state->lastsrc;
|
||||||
|
uint16_t nac = state->nac;
|
||||||
|
|
||||||
|
if (state->event_history_s[slot].Event_History_Items[0].source_id == rid)
|
||||||
|
sprintf (state->event_history_s[slot].Event_History_Items[0].alias, "%s", alias);
|
||||||
|
|
||||||
|
if (rid != 0)
|
||||||
|
{
|
||||||
|
for (int16_t i = 0; i < state->group_tally; i++)
|
||||||
|
{
|
||||||
|
if (state->group_array[i].groupNumber == rid)
|
||||||
|
{
|
||||||
|
wr = 1; //already in there, so no need to assign it
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (wr == 0) //not already in there, so save it there now
|
||||||
|
{
|
||||||
|
state->group_array[state->group_tally].groupNumber = rid;
|
||||||
|
sprintf (state->group_array[state->group_tally].groupMode, "%s", "D");
|
||||||
|
sprintf (state->group_array[state->group_tally].groupName, "%s", alias);
|
||||||
|
state->group_tally++;
|
||||||
|
|
||||||
|
//if we have an opened group file, let's write what info we found into it
|
||||||
|
if (opts->group_in_file[0] != 0) //file is available
|
||||||
|
{
|
||||||
|
FILE * pFile; //file pointer
|
||||||
|
//open file by name that is supplied in the ncurses terminal, or cli
|
||||||
|
pFile = fopen (opts->group_in_file, "a");
|
||||||
|
fprintf (pFile, "%d,D,", rid); //may want to not use this one
|
||||||
|
fprintf (pFile, "%s,", alias);
|
||||||
|
fprintf (pFile, "%03X,", nac); //if we find this on a trunking system, may want to add the site and rfss id
|
||||||
|
fprintf (pFile, "%s", ",Tait\n");
|
||||||
|
fclose (pFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void dmr_talker_alias_lc_header (dsd_opts * opts, dsd_state * state, uint8_t slot, uint8_t * lc_bits)
|
||||||
|
{
|
||||||
|
uint8_t format = (uint8_t)ConvertBitIntoBytes(&lc_bits[16], 2);
|
||||||
|
uint8_t block_len = (uint8_t)ConvertBitIntoBytes(&lc_bits[18], 5);
|
||||||
|
uint8_t char_size = 0;
|
||||||
|
|
||||||
|
if (format == 0) char_size = 7;
|
||||||
|
else if (format == 1 || format == 2) char_size = 8;
|
||||||
|
else char_size = 16;
|
||||||
|
|
||||||
|
state->dmr_alias_format[slot] = format;
|
||||||
|
state->dmr_alias_block_len[slot] = block_len; //data len, see below
|
||||||
|
state->dmr_alias_char_size[slot] = char_size;
|
||||||
|
|
||||||
|
//load into dmr_pdu_sf as bit wise values for this since iso7 has 49 bits in this header, otherwise, load with 48?
|
||||||
|
if (char_size == 7)
|
||||||
|
memcpy(state->dmr_pdu_sf[slot], lc_bits+23, 49*sizeof(uint8_t));
|
||||||
|
else if (char_size == 8)
|
||||||
|
memcpy(state->dmr_pdu_sf[slot], lc_bits+24, 48*sizeof(uint8_t));
|
||||||
|
else if (char_size == 16)
|
||||||
|
memcpy(state->dmr_pdu_sf[slot], lc_bits+24, 48*sizeof(uint8_t));
|
||||||
|
|
||||||
|
//TEST: The Block Len (Data Lan) value is, according to my interpretation, the number of encoded
|
||||||
|
//character units in the alias, test to verify, but fall back to the ptr index if necessary
|
||||||
|
//this is referenced in 5.4.3 ETSI TS 102 361-2 V2.5.1 (2023-05) 7.2.19 Talker Alias Data Length
|
||||||
|
|
||||||
|
fprintf (stderr, " Slot %d - Talker Alias LC Header; Format %d; Char Len: %d; Char Size: %d;", slot, format, block_len, char_size);
|
||||||
|
|
||||||
|
//Decode the header's alias portion
|
||||||
|
fprintf (stderr, "\n");
|
||||||
|
dmr_talker_alias_lc_decode(opts, state, slot, 0, char_size, block_len);
|
||||||
|
}
|
||||||
|
|
||||||
|
void dmr_talker_alias_lc_blocks (dsd_opts * opts, dsd_state * state, uint8_t slot, uint8_t block_num, uint8_t * lc_bits)
|
||||||
|
{
|
||||||
|
UNUSED(opts); //delete if we don't use this, but may want it if we dump alias to a file later on
|
||||||
|
uint8_t block_len = state->dmr_alias_block_len[slot];
|
||||||
|
uint8_t char_size = state->dmr_alias_char_size[slot];
|
||||||
|
uint16_t ptr = 0;
|
||||||
|
uint16_t end = block_len;
|
||||||
|
|
||||||
|
//Note: The Joann sample only carries block 5, and no header on block 4
|
||||||
|
//another radio on that ham setup also has a broken alias similar, but
|
||||||
|
//the other talkers have the 04 and the sample has a good decode otherwise
|
||||||
|
//debug broken aliasing on ham radio
|
||||||
|
|
||||||
|
// if (char_size == 0) //Enable this is you need to check alias even with missing header (set 7, 8, or 16)
|
||||||
|
// char_size = 8;
|
||||||
|
|
||||||
|
/*
|
||||||
|
22:54:51 Sync: +DMR slot1 [SLOT2] | Color Code=01 | VC6
|
||||||
|
Slot 1 - Talker Alias Block Num: 1; Valid Block; Talker Alias: Joann
|
||||||
|
DMR PDU Payload [05][00][4A][6F][61][6E][6E][00][FF]
|
||||||
|
*/
|
||||||
|
|
||||||
|
//set the pointer to the current index of the dmr_pdu_sf
|
||||||
|
if (char_size == 16)
|
||||||
|
ptr = 48 + (block_num * 56);
|
||||||
|
else if (char_size == 8)
|
||||||
|
ptr = 48 + (block_num * 56);
|
||||||
|
else if (char_size == 7)
|
||||||
|
ptr = 49 + (block_num * 56);
|
||||||
|
|
||||||
|
if (char_size == 0) //unset, no header received
|
||||||
|
fprintf (stderr, " Slot %d - Talker Alias Block Num: %d; Invalid Header;", slot, block_num+1);
|
||||||
|
|
||||||
|
else if (block_num > 3) //invalid block (data error)
|
||||||
|
fprintf (stderr, " Slot %d - Talker Alias Block Num: %d; Invalid Block;", slot, block_num+1);
|
||||||
|
|
||||||
|
else //valid header present, continue
|
||||||
|
{
|
||||||
|
if (char_size == 7)
|
||||||
|
{
|
||||||
|
memcpy(state->dmr_pdu_sf[slot]+ptr, lc_bits+16, 56*sizeof(uint8_t));
|
||||||
|
ptr += 56;
|
||||||
|
if (block_len == 0)
|
||||||
|
end = ptr / 7;
|
||||||
|
else end = block_len;
|
||||||
|
}
|
||||||
|
else if (char_size == 8)
|
||||||
|
{
|
||||||
|
memcpy(state->dmr_pdu_sf[slot]+ptr, lc_bits+16, 56*sizeof(uint8_t));
|
||||||
|
ptr += 56;
|
||||||
|
if (block_len == 0)
|
||||||
|
end = ptr / 8;
|
||||||
|
else end = block_len;
|
||||||
|
}
|
||||||
|
else if (char_size == 16)
|
||||||
|
{
|
||||||
|
memcpy(state->dmr_pdu_sf[slot]+ptr, lc_bits+16, 56*sizeof(uint8_t));
|
||||||
|
ptr += 56;
|
||||||
|
if (block_len == 0)
|
||||||
|
end = ptr / 16;
|
||||||
|
else end = block_len;
|
||||||
|
}
|
||||||
|
|
||||||
|
dmr_talker_alias_lc_decode (opts, state, slot, block_num+1, char_size, end);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Decode partial or completed alias
|
||||||
|
void dmr_talker_alias_lc_decode (dsd_opts * opts, dsd_state * state, uint8_t slot, uint8_t block_num, uint8_t char_size, uint16_t end)
|
||||||
|
{
|
||||||
|
UNUSED(opts);
|
||||||
|
uint16_t i = 0;
|
||||||
|
fprintf (stderr, " Slot %d - Talker Alias Block Num: %d; Valid Block;", slot, block_num+1);
|
||||||
|
fprintf (stderr, " Talker Alias: ");
|
||||||
|
|
||||||
|
char alias_string[500]; memset (alias_string, 0, sizeof(alias_string));
|
||||||
|
sprintf (alias_string, "%s", "");
|
||||||
|
|
||||||
|
if (char_size == 7)
|
||||||
|
{
|
||||||
|
for (i = 0; i < end; i++)
|
||||||
|
{
|
||||||
|
uint8_t character = (uint8_t)ConvertBitIntoBytes(&state->dmr_pdu_sf[slot][(i*7)], 7);
|
||||||
|
char ch[2]; ch[0] = character; ch[1] = 0;
|
||||||
|
if (character >= 0x20 && character <= 0x7E) //Standard ASCII Set
|
||||||
|
{
|
||||||
|
fprintf (stderr, "%c", character);
|
||||||
|
strcat (alias_string, ch);
|
||||||
|
}
|
||||||
|
// else if (character == 0)
|
||||||
|
// {
|
||||||
|
// strcat (alias_string, " ");
|
||||||
|
// fprintf (stderr, " ");
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
else
|
||||||
|
{
|
||||||
|
strcat (alias_string, " ");
|
||||||
|
fprintf (stderr, " ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (char_size == 8)
|
||||||
|
{
|
||||||
|
for (i = 0; i < end; i++)
|
||||||
|
{
|
||||||
|
uint8_t character = (uint8_t)ConvertBitIntoBytes(&state->dmr_pdu_sf[slot][(i*8)], 8);
|
||||||
|
char ch[2]; ch[0] = character; ch[1] = 0;
|
||||||
|
// if (character >= 0x20 && character <= 0x7E) //Standard ASCII Set
|
||||||
|
if (character >= 0x20 && character != 0x7F) //allow some extended UTF diacritical characters as well
|
||||||
|
{
|
||||||
|
fprintf (stderr, "%c", character);
|
||||||
|
strcat (alias_string, ch);
|
||||||
|
}
|
||||||
|
// else if (character == 0)
|
||||||
|
// {
|
||||||
|
// strcat (alias_string, " ");
|
||||||
|
// fprintf (stderr, " ");
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
else
|
||||||
|
{
|
||||||
|
strcat (alias_string, " ");
|
||||||
|
fprintf (stderr, " ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (char_size == 16)
|
||||||
|
{
|
||||||
|
int ptr = 0;
|
||||||
|
setlocale(LC_ALL, ""); //needed when encoded alias contains Chinese (or probably any non-roman charset that isn't default on users terminal)
|
||||||
|
for (i = 0; i < end; i++)
|
||||||
|
{
|
||||||
|
uint16_t character = (uint16_t)ConvertBitIntoBytes(&state->dmr_pdu_sf[slot][(i*16)], 16);
|
||||||
|
|
||||||
|
if (character >= 0x20 && character != 0x7F)
|
||||||
|
fprintf (stderr, "%lc", character);
|
||||||
|
else fprintf (stderr, " ");
|
||||||
|
|
||||||
|
//Encode to UTF-8
|
||||||
|
ptr += utf8_encode(character, alias_string+ptr);
|
||||||
|
|
||||||
|
//debug
|
||||||
|
// fprintf (stderr, " [%04X], ", character);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//assign to string for event history and ncurses display
|
||||||
|
uint32_t source = 0;
|
||||||
|
if (slot == 0)
|
||||||
|
source = state->lastsrc;
|
||||||
|
else source = state->lastsrcR;
|
||||||
|
|
||||||
|
if (state->event_history_s[slot].Event_History_Items[0].source_id == source)
|
||||||
|
sprintf (state->event_history_s[slot].Event_History_Items[0].alias, "%s; ", alias_string);
|
||||||
|
sprintf (state->generic_talker_alias[slot], "Talker Alias: %s; ", alias_string);
|
||||||
|
|
||||||
|
}
|
||||||
490
src/dsd_audio.c
490
src/dsd_audio.c
@@ -21,14 +21,16 @@ pa_sample_spec ss;
|
|||||||
pa_sample_spec tt;
|
pa_sample_spec tt;
|
||||||
pa_sample_spec zz;
|
pa_sample_spec zz;
|
||||||
pa_sample_spec cc;
|
pa_sample_spec cc;
|
||||||
|
pa_sample_spec ff; //float
|
||||||
|
|
||||||
|
//pulse audio buffer attributes (input latency)
|
||||||
|
pa_buffer_attr lt;
|
||||||
|
|
||||||
void closePulseOutput (dsd_opts * opts)
|
void closePulseOutput (dsd_opts * opts)
|
||||||
{
|
{
|
||||||
pa_simple_free (opts->pulse_digi_dev_out);
|
pa_simple_free (opts->pulse_digi_dev_out);
|
||||||
if (opts->dmr_stereo == 1)
|
if (opts->frame_provoice == 1 || opts->monitor_input_audio == 1) //EDACS analog calls and/or monitoring source analog audio
|
||||||
{
|
pa_simple_free (opts->pulse_raw_dev_out);
|
||||||
pa_simple_free (opts->pulse_digi_dev_outR);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void closePulseInput (dsd_opts * opts)
|
void closePulseInput (dsd_opts * opts)
|
||||||
@@ -39,33 +41,66 @@ void closePulseInput (dsd_opts * opts)
|
|||||||
void openPulseOutput(dsd_opts * opts)
|
void openPulseOutput(dsd_opts * opts)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
char * dev = NULL;
|
||||||
|
if (opts->pa_output_idx[0] != 0)
|
||||||
|
dev = opts->pa_output_idx;
|
||||||
|
|
||||||
|
int err = 0;
|
||||||
|
|
||||||
ss.format = PA_SAMPLE_S16NE;
|
ss.format = PA_SAMPLE_S16NE;
|
||||||
ss.channels = opts->pulse_raw_out_channels; //doing tests with 2 channels at 22050 for 44100 audio default in pulse
|
ss.channels = opts->pulse_raw_out_channels;
|
||||||
ss.rate = opts->pulse_raw_rate_out; //48000
|
ss.rate = opts->pulse_raw_rate_out;
|
||||||
|
|
||||||
tt.format = PA_SAMPLE_S16NE;
|
tt.format = PA_SAMPLE_S16NE;
|
||||||
tt.channels = opts->pulse_digi_out_channels; //doing tests with 2 channels at 22050 for 44100 audio default in pulse
|
tt.channels = opts->pulse_digi_out_channels;
|
||||||
tt.rate = opts->pulse_digi_rate_out; //48000, switches to 8000 when using RTL dongle
|
tt.rate = opts->pulse_digi_rate_out;
|
||||||
|
|
||||||
if (opts->monitor_input_audio == 1)
|
ff.format = PA_SAMPLE_FLOAT32NE;
|
||||||
|
ff.channels = opts->pulse_digi_out_channels;
|
||||||
|
ff.rate = opts->pulse_digi_rate_out;
|
||||||
|
|
||||||
|
//reconfigured to open when using edacs or raw analog monitor so we can have a analog audio out that runs at 48k1 and not 8k1 float/short
|
||||||
|
if (opts->frame_provoice == 1 || opts->monitor_input_audio == 1)
|
||||||
|
opts->pulse_raw_dev_out = pa_simple_new(NULL, "DSD-FME3", PA_STREAM_PLAYBACK, dev, "Analog", &ss, 0, NULL, &err);
|
||||||
|
|
||||||
|
if (err != 0)
|
||||||
{
|
{
|
||||||
opts->pulse_raw_dev_out = pa_simple_new(NULL, "DSD-FME3", PA_STREAM_PLAYBACK, NULL, "Raw Audio Out", &ss, NULL, NULL, NULL);
|
fprintf (stderr, "Err: %d; %s; ", err, pa_strerror(err));
|
||||||
|
#ifdef __CYGWIN__
|
||||||
|
fprintf (stderr, "Please make sure the Pulse Audio Server Backend is running first.");
|
||||||
|
#endif
|
||||||
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
//tt
|
pa_channel_map* fl = 0; //NULL and 0 are same in this context
|
||||||
pa_channel_map* left = 0; //NULL and 0 are same in this context
|
pa_channel_map* ss = 0; //NULL and 0 are same in this context
|
||||||
pa_channel_map* right = 0; //NULL and 0 are same in this context
|
|
||||||
|
|
||||||
if (opts->dmr_stereo == 0)
|
if (opts->floating_point == 0 && opts->analog_only == 0)
|
||||||
{
|
{
|
||||||
opts->pulse_digi_dev_out = pa_simple_new(NULL, "DSD-FME", PA_STREAM_PLAYBACK, NULL, opts->output_name, &tt, left, NULL, NULL);
|
opts->pulse_digi_dev_out = pa_simple_new(NULL, "DSD-FME", PA_STREAM_PLAYBACK, dev, opts->output_name, &tt, ss, NULL, &err);
|
||||||
|
|
||||||
|
if (err != 0)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "Err: %d; %s; ", err, pa_strerror(err));
|
||||||
|
#ifdef __CYGWIN__
|
||||||
|
fprintf (stderr, "Please make sure the Pulse Audio Server Backend is running first.");
|
||||||
|
#endif
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opts->dmr_stereo == 1)
|
if (opts->floating_point == 1 && opts->analog_only == 0)
|
||||||
{
|
{
|
||||||
opts->pulse_digi_dev_out = pa_simple_new(NULL, "DSD-FME1", PA_STREAM_PLAYBACK, NULL, "XDMA SLOT 1", &tt, left, NULL, NULL);
|
opts->pulse_digi_dev_out = pa_simple_new(NULL, "DSD-FME", PA_STREAM_PLAYBACK, dev, opts->output_name, &ff, fl, NULL, &err);
|
||||||
opts->pulse_digi_dev_outR = pa_simple_new(NULL, "DSD-FME2", PA_STREAM_PLAYBACK, NULL, "XDMA SLOT 2", &tt, right, NULL, NULL);
|
|
||||||
|
if (err != 0)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "Err: %d; %s; ", err, pa_strerror(err));
|
||||||
|
#ifdef __CYGWIN__
|
||||||
|
fprintf (stderr, "Please make sure the Pulse Audio Server Backend is running first.");
|
||||||
|
#endif
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -73,14 +108,212 @@ void openPulseOutput(dsd_opts * opts)
|
|||||||
void openPulseInput(dsd_opts * opts)
|
void openPulseInput(dsd_opts * opts)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
char * dev = NULL;
|
||||||
|
if (opts->pa_input_idx[0] != 0)
|
||||||
|
dev = opts->pa_input_idx;
|
||||||
|
|
||||||
|
int err = 0;
|
||||||
|
|
||||||
cc.format = PA_SAMPLE_S16NE;
|
cc.format = PA_SAMPLE_S16NE;
|
||||||
cc.channels = opts->pulse_digi_in_channels;
|
cc.channels = opts->pulse_digi_in_channels;
|
||||||
cc.rate = opts->pulse_digi_rate_in; //48000
|
cc.rate = opts->pulse_digi_rate_in; //48000
|
||||||
|
|
||||||
opts->pulse_digi_dev_in = pa_simple_new(NULL, "DSD-FME", PA_STREAM_RECORD, NULL, opts->output_name, &cc, NULL, NULL, NULL);
|
//adjust input latency settings (defaults are all -1 to let server set these automatically, but without pavucontrol open, this is approx 2s)
|
||||||
|
//setting fragsize to 960 for 48000 input seems to do the trick to allow a much faster latency without underrun, may need adjusting if
|
||||||
|
//modifying the input rate (will only apply IF using pulse audio input, and not any other input method)
|
||||||
|
|
||||||
|
//TODO: set fragsize vs expected input rate if required in the future
|
||||||
|
//NOTE: If users report any underrun conditions, then either change 960 back to -1, or pass NULL instead of <
|
||||||
|
|
||||||
|
//https://freedesktop.org/software/pulseaudio/doxygen/structpa__buffer__attr.html
|
||||||
|
|
||||||
|
//for now, only going to modify the fragsize if using the encoder, else, let the pa server set it automatically
|
||||||
|
// if (opts->m17encoder == 1)
|
||||||
|
// lt.fragsize = 960*5;
|
||||||
|
// else lt.fragsize = -1;
|
||||||
|
|
||||||
|
//test doing it universally, fall back to above if needed
|
||||||
|
lt.fragsize = 960*5;
|
||||||
|
lt.maxlength = -1;
|
||||||
|
lt.prebuf = -1;
|
||||||
|
lt.tlength = -1;
|
||||||
|
// if (opts->m17encoder == 1)
|
||||||
|
// opts->pulse_digi_dev_in = pa_simple_new(NULL, "DSD-FME4", PA_STREAM_RECORD, dev, "M17 Voice Input", &cc, NULL, <, &err);
|
||||||
|
// else opts->pulse_digi_dev_in = pa_simple_new(NULL, "DSD-FME", PA_STREAM_RECORD, dev, opts->output_name, &cc, NULL, <, &err);
|
||||||
|
|
||||||
|
opts->pulse_digi_dev_in = pa_simple_new(NULL, "DSD-FME", PA_STREAM_RECORD, dev, opts->output_name, &cc, NULL, <, &err);
|
||||||
|
|
||||||
|
if (err != 0)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "Err: %d; %s; ", err, pa_strerror(err));
|
||||||
|
#ifdef __CYGWIN__
|
||||||
|
fprintf (stderr, "Please make sure the Pulse Audio Server Backend is running first.");
|
||||||
|
#endif
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
//debug
|
||||||
|
// if (opts->m17encoder == 1)
|
||||||
|
// {
|
||||||
|
// unsigned long long int latency = pa_simple_get_latency (opts->pulse_digi_dev_in, NULL);
|
||||||
|
// fprintf (stderr, "Pulse Audio Input Latency: %05lld;", latency);
|
||||||
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void parse_pulse_input_string (dsd_opts * opts, char * input)
|
||||||
|
{
|
||||||
|
char * curr;
|
||||||
|
curr = strtok(input, ":");
|
||||||
|
if (curr != NULL)
|
||||||
|
{
|
||||||
|
strncpy (opts->pa_input_idx, curr, 99);
|
||||||
|
opts->pa_input_idx[99] = 0;
|
||||||
|
fprintf (stderr, "\n");
|
||||||
|
fprintf (stderr, "Pulse Input Device: %s; ", opts->pa_input_idx);
|
||||||
|
fprintf (stderr, "\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void parse_pulse_output_string (dsd_opts * opts, char * input)
|
||||||
|
{
|
||||||
|
char * curr;
|
||||||
|
curr = strtok(input, ":");
|
||||||
|
if (curr != NULL)
|
||||||
|
{
|
||||||
|
strncpy (opts->pa_output_idx, curr, 99);
|
||||||
|
opts->pa_output_idx[99] = 0;
|
||||||
|
fprintf (stderr, "\n");
|
||||||
|
fprintf (stderr, "Pulse Output Device: %s; ", opts->pa_output_idx);
|
||||||
|
fprintf (stderr, "\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
|
// macOS does not support OSS (/dev/dsp).
|
||||||
|
// Provide a stub so callers can link while using Pulse/CoreAudio backends.
|
||||||
|
void openOSSOutput(dsd_opts *opts)
|
||||||
|
{
|
||||||
|
(void)opts;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
void openOSSOutput (dsd_opts * opts)
|
||||||
|
{
|
||||||
|
int fmt;
|
||||||
|
int speed = 48000;
|
||||||
|
if (opts->audio_in_type == 5) //if((strncmp(opts->audio_in_dev, "/dev/dsp", 8) == 0)) or 'split' == 0
|
||||||
|
{
|
||||||
|
|
||||||
|
if((strncmp(opts->audio_out_dev, "/dev/dsp", 8) == 0))
|
||||||
|
{
|
||||||
|
fprintf (stderr, "OSS Output %s.\n", opts->audio_out_dev);
|
||||||
|
opts->audio_out_fd = open (opts->audio_out_dev, O_RDWR);
|
||||||
|
if (opts->audio_out_fd == -1)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "Error, couldn't open #1 %s\n", opts->audio_out_dev);
|
||||||
|
opts->audio_out = 0;
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fmt = 0;
|
||||||
|
if (ioctl (opts->audio_out_fd, SNDCTL_DSP_RESET) < 0)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "ioctl reset error \n");
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt = speed;
|
||||||
|
if (ioctl (opts->audio_out_fd, SNDCTL_DSP_SPEED, &fmt) < 0)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "ioctl speed error \n");
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt = 0; //this seems okay to be 1 or 0, not sure what the difference really is (works in stereo on 0)
|
||||||
|
if (ioctl (opts->audio_out_fd, SNDCTL_DSP_STEREO, &fmt) < 0)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "ioctl stereo error \n");
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt = AFMT_S16_LE;
|
||||||
|
if (ioctl (opts->audio_out_fd, SNDCTL_DSP_SETFMT, &fmt) < 0)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "ioctl setfmt error \n");
|
||||||
|
}
|
||||||
|
|
||||||
|
opts->audio_out_type = 5; //5 for 1 channel - 48k OSS 16-bit short output (matching with input)
|
||||||
|
opts->pulse_digi_rate_out = 48000; //this is used to force to upsample and also allow source audio monitor conditional check
|
||||||
|
opts->pulse_digi_out_channels = 1; //this is used to allow source audio monitor conditional check
|
||||||
|
opts->audio_gain = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (opts->audio_in_type != 5 || opts->split == 1) //split == 1
|
||||||
|
{
|
||||||
|
|
||||||
|
if((strncmp(opts->audio_out_dev, "/dev/dsp", 8) == 0))
|
||||||
|
{
|
||||||
|
fprintf (stderr, "OSS Output %s.\n", opts->audio_out_dev);
|
||||||
|
opts->audio_out_fd = open (opts->audio_out_dev, O_WRONLY);
|
||||||
|
if (opts->audio_out_fd == -1)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "Error, couldn't open %s\n", opts->audio_out_dev);
|
||||||
|
opts->audio_out = 0;
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Setup the device. Note that it's important to set the sample format, number of channels and sample rate exactly in this order. Some devices depend on the order.
|
||||||
|
|
||||||
|
fmt = 0;
|
||||||
|
if (ioctl (opts->audio_out_fd, SNDCTL_DSP_RESET) < 0)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "ioctl reset error \n");
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt = AFMT_S16_LE; //Sample Format
|
||||||
|
if (ioctl (opts->audio_out_fd, SNDCTL_DSP_SETFMT, &fmt) < 0)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "ioctl setfmt error \n");
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt = opts->pulse_digi_out_channels; //number of channels //was 2
|
||||||
|
if (ioctl (opts->audio_out_fd, SNDCTL_DSP_CHANNELS, &fmt) < 0)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "ioctl channel error \n");
|
||||||
|
}
|
||||||
|
|
||||||
|
//if using split with OSS output, and using EDACS w/ Analog, we have to use 48k
|
||||||
|
if (opts->frame_provoice == 1)
|
||||||
|
opts->pulse_digi_rate_out = 48000;
|
||||||
|
|
||||||
|
speed = opts->pulse_digi_rate_out; //since we have split input/output, we want to mirror pulse rate out
|
||||||
|
fmt = speed; //output rate
|
||||||
|
if (ioctl (opts->audio_out_fd, SNDCTL_DSP_SPEED, &fmt) < 0)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "ioctl speed error \n");
|
||||||
|
}
|
||||||
|
if (opts->pulse_digi_out_channels == 2)
|
||||||
|
fmt = 1;
|
||||||
|
else fmt = 0;
|
||||||
|
|
||||||
|
if (ioctl (opts->audio_out_fd, SNDCTL_DSP_STEREO, &fmt) < 0)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "ioctl stereo error \n");
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO: Multiple output returns based on 8k/1, 8k/2, or maybe 48k/1? (2,3,5)??
|
||||||
|
if (opts->pulse_digi_out_channels == 2)
|
||||||
|
opts->audio_out_type = 2; //2 for 2 channel 8k OSS 16-bit short output
|
||||||
|
else if (opts->frame_m17 == 1)
|
||||||
|
opts->audio_out_type = 2;
|
||||||
|
else opts->audio_out_type = 5;
|
||||||
|
|
||||||
|
//debug
|
||||||
|
fprintf (stderr, "Using OSS Output with %dk/%d channel configuration.\n", opts->pulse_digi_rate_out, opts->pulse_digi_out_channels);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void
|
void
|
||||||
processAudio (dsd_opts * opts, dsd_state * state)
|
processAudio (dsd_opts * opts, dsd_state * state)
|
||||||
{
|
{
|
||||||
@@ -172,8 +405,7 @@ processAudio (dsd_opts * opts, dsd_state * state)
|
|||||||
|
|
||||||
// copy audio data to output buffer and upsample if necessary
|
// copy audio data to output buffer and upsample if necessary
|
||||||
state->audio_out_temp_buf_p = state->audio_out_temp_buf;
|
state->audio_out_temp_buf_p = state->audio_out_temp_buf;
|
||||||
//we only want to upsample when using sample rates greater than 8k for output,
|
//we only want to upsample when using sample rates greater than 8k for output
|
||||||
//hard set to 8k for RTL mono and MBE playback, otherwise crackling may occur.
|
|
||||||
if (opts->pulse_digi_rate_out > 8000)
|
if (opts->pulse_digi_rate_out > 8000)
|
||||||
{
|
{
|
||||||
for (n = 0; n < 160; n++)
|
for (n = 0; n < 160; n++)
|
||||||
@@ -197,6 +429,8 @@ processAudio (dsd_opts * opts, dsd_state * state)
|
|||||||
*state->audio_out_float_buf_p = -32768.0F;
|
*state->audio_out_float_buf_p = -32768.0F;
|
||||||
}
|
}
|
||||||
*state->audio_out_buf_p = (short) *state->audio_out_float_buf_p;
|
*state->audio_out_buf_p = (short) *state->audio_out_float_buf_p;
|
||||||
|
//tap the pointer here and store the short upsample buffer samples
|
||||||
|
state->s_lu[n] = (short) *state->audio_out_float_buf_p;
|
||||||
state->audio_out_buf_p++;
|
state->audio_out_buf_p++;
|
||||||
state->audio_out_float_buf_p++;
|
state->audio_out_float_buf_p++;
|
||||||
}
|
}
|
||||||
@@ -215,6 +449,10 @@ processAudio (dsd_opts * opts, dsd_state * state)
|
|||||||
*state->audio_out_temp_buf_p = -32768.0F;
|
*state->audio_out_temp_buf_p = -32768.0F;
|
||||||
}
|
}
|
||||||
*state->audio_out_buf_p = (short) *state->audio_out_temp_buf_p;
|
*state->audio_out_buf_p = (short) *state->audio_out_temp_buf_p;
|
||||||
|
//tap the pointer here and store the short buffer samples
|
||||||
|
state->s_l[n] = (short) *state->audio_out_temp_buf_p;
|
||||||
|
//debug
|
||||||
|
// fprintf (stderr, " %d", state->s_l[n]);
|
||||||
state->audio_out_buf_p++;
|
state->audio_out_buf_p++;
|
||||||
state->audio_out_temp_buf_p++;
|
state->audio_out_temp_buf_p++;
|
||||||
state->audio_out_idx++;
|
state->audio_out_idx++;
|
||||||
@@ -315,7 +553,6 @@ processAudioR (dsd_opts * opts, dsd_state * state)
|
|||||||
// copy audio data to output buffer and upsample if necessary
|
// copy audio data to output buffer and upsample if necessary
|
||||||
state->audio_out_temp_buf_pR = state->audio_out_temp_bufR;
|
state->audio_out_temp_buf_pR = state->audio_out_temp_bufR;
|
||||||
//we only want to upsample when using sample rates greater than 8k for output,
|
//we only want to upsample when using sample rates greater than 8k for output,
|
||||||
//hard set to 8k for RTL mono and MBE playback, otherwise crackling may occur.
|
|
||||||
if (opts->pulse_digi_rate_out > 8000)
|
if (opts->pulse_digi_rate_out > 8000)
|
||||||
{
|
{
|
||||||
for (n = 0; n < 160; n++)
|
for (n = 0; n < 160; n++)
|
||||||
@@ -339,6 +576,8 @@ processAudioR (dsd_opts * opts, dsd_state * state)
|
|||||||
*state->audio_out_float_buf_pR = -32768.0F;
|
*state->audio_out_float_buf_pR = -32768.0F;
|
||||||
}
|
}
|
||||||
*state->audio_out_buf_pR = (short) *state->audio_out_float_buf_pR;
|
*state->audio_out_buf_pR = (short) *state->audio_out_float_buf_pR;
|
||||||
|
//tap the pointer here and store the short upsample buffer samples
|
||||||
|
state->s_ru[n] = (short) *state->audio_out_float_buf_pR;
|
||||||
state->audio_out_buf_pR++;
|
state->audio_out_buf_pR++;
|
||||||
state->audio_out_float_buf_pR++;
|
state->audio_out_float_buf_pR++;
|
||||||
}
|
}
|
||||||
@@ -357,6 +596,8 @@ processAudioR (dsd_opts * opts, dsd_state * state)
|
|||||||
*state->audio_out_temp_buf_pR = -32768.0F;
|
*state->audio_out_temp_buf_pR = -32768.0F;
|
||||||
}
|
}
|
||||||
*state->audio_out_buf_pR = (short) *state->audio_out_temp_buf_pR;
|
*state->audio_out_buf_pR = (short) *state->audio_out_temp_buf_pR;
|
||||||
|
//tap the pointer here and store the short buffer samples
|
||||||
|
state->s_r[n] = (short) *state->audio_out_temp_buf_pR;
|
||||||
state->audio_out_buf_pR++;
|
state->audio_out_buf_pR++;
|
||||||
state->audio_out_temp_buf_pR++;
|
state->audio_out_temp_buf_pR++;
|
||||||
state->audio_out_idxR++;
|
state->audio_out_idxR++;
|
||||||
@@ -421,12 +662,47 @@ void writeSynthesizedVoiceR (dsd_opts * opts, dsd_state * state)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void writeRawSample (dsd_opts * opts, dsd_state * state, short sample)
|
//short Mono to Stereo version for new static .wav files in stereo format for TDMA
|
||||||
|
void writeSynthesizedVoiceMS (dsd_opts * opts, dsd_state * state)
|
||||||
{
|
{
|
||||||
int n;
|
int n;
|
||||||
short aout_buf[160];
|
short aout_buf[160];
|
||||||
short *aout_buf_p;
|
short *aout_buf_p;
|
||||||
|
|
||||||
|
aout_buf_p = aout_buf;
|
||||||
|
state->audio_out_temp_buf_p = state->audio_out_temp_buf;
|
||||||
|
|
||||||
|
for (n = 0; n < 160; n++)
|
||||||
|
{
|
||||||
|
if (*state->audio_out_temp_buf_p > (float) 32767)
|
||||||
|
{
|
||||||
|
*state->audio_out_temp_buf_p = (float) 32767;
|
||||||
|
}
|
||||||
|
else if (*state->audio_out_temp_buf_p < (float) -32768)
|
||||||
|
{
|
||||||
|
*state->audio_out_temp_buf_p = (float) -32768;
|
||||||
|
}
|
||||||
|
*aout_buf_p = (short) *state->audio_out_temp_buf_p;
|
||||||
|
aout_buf_p++;
|
||||||
|
state->audio_out_temp_buf_p++;
|
||||||
|
}
|
||||||
|
|
||||||
|
short ss[320];
|
||||||
|
for (n = 0; n < 160; n++)
|
||||||
|
{
|
||||||
|
ss[(n*2)+0] = aout_buf[n];
|
||||||
|
ss[(n*2)+1] = aout_buf[n];
|
||||||
|
}
|
||||||
|
|
||||||
|
sf_write_short(opts->wav_out_f, ss, 320);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void writeRawSample (dsd_opts * opts, dsd_state * state, short sample)
|
||||||
|
{
|
||||||
|
UNUSED(state);
|
||||||
|
|
||||||
|
//short aout_buf[160];
|
||||||
//sf_write_short(opts->wav_out_raw, aout_buf, 160);
|
//sf_write_short(opts->wav_out_raw, aout_buf, 160);
|
||||||
|
|
||||||
//only write if actual audio, truncate silence
|
//only write if actual audio, truncate silence
|
||||||
@@ -441,12 +717,26 @@ void
|
|||||||
playSynthesizedVoice (dsd_opts * opts, dsd_state * state)
|
playSynthesizedVoice (dsd_opts * opts, dsd_state * state)
|
||||||
{
|
{
|
||||||
ssize_t result;
|
ssize_t result;
|
||||||
|
UNUSED(result);
|
||||||
|
|
||||||
|
//don't synthesize voice if slot is turned off
|
||||||
|
if (opts->slot1_on == 0)
|
||||||
|
{
|
||||||
|
//clear any previously buffered audio
|
||||||
|
state->audio_out_float_buf_p = state->audio_out_float_buf + 100;
|
||||||
|
state->audio_out_buf_p = state->audio_out_buf + 100;
|
||||||
|
memset (state->audio_out_float_buf, 0, 100 * sizeof (float));
|
||||||
|
memset (state->audio_out_buf, 0, 100 * sizeof (short));
|
||||||
|
state->audio_out_idx2 = 0;
|
||||||
|
state->audio_out_idx = 0;
|
||||||
|
goto end_psv;
|
||||||
|
}
|
||||||
|
|
||||||
if (state->audio_out_idx > opts->delay)
|
if (state->audio_out_idx > opts->delay)
|
||||||
{
|
{
|
||||||
if (opts->audio_out_type == 5) //OSS
|
if (opts->audio_out_type == 5 || opts->audio_out_type == 1) //OSS
|
||||||
{
|
{
|
||||||
//OSS
|
//OSS 48k/1
|
||||||
result = write (opts->audio_out_fd, (state->audio_out_buf_p - state->audio_out_idx), (state->audio_out_idx * 2));
|
result = write (opts->audio_out_fd, (state->audio_out_buf_p - state->audio_out_idx), (state->audio_out_idx * 2));
|
||||||
state->audio_out_idx = 0;
|
state->audio_out_idx = 0;
|
||||||
}
|
}
|
||||||
@@ -455,11 +745,18 @@ playSynthesizedVoice (dsd_opts * opts, dsd_state * state)
|
|||||||
pa_simple_write(opts->pulse_digi_dev_out, (state->audio_out_buf_p - state->audio_out_idx), (state->audio_out_idx * 2), NULL);
|
pa_simple_write(opts->pulse_digi_dev_out, (state->audio_out_buf_p - state->audio_out_idx), (state->audio_out_idx * 2), NULL);
|
||||||
state->audio_out_idx = 0;
|
state->audio_out_idx = 0;
|
||||||
}
|
}
|
||||||
|
else if (opts->audio_out_type == 8) //UDP Audio Out -- Forgot some things still use this for now
|
||||||
|
{
|
||||||
|
udp_socket_blaster (opts, state, (state->audio_out_idx * 2), (state->audio_out_buf_p - state->audio_out_idx));
|
||||||
|
state->audio_out_idx = 0;
|
||||||
|
}
|
||||||
else state->audio_out_idx = 0; //failsafe for audio_out == 0
|
else state->audio_out_idx = 0; //failsafe for audio_out == 0
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
end_psv:
|
||||||
|
|
||||||
if (state->audio_out_idx2 >= 800000)
|
if (state->audio_out_idx2 >= 800000)
|
||||||
{
|
{
|
||||||
state->audio_out_float_buf_p = state->audio_out_float_buf + 100;
|
state->audio_out_float_buf_p = state->audio_out_float_buf + 100;
|
||||||
@@ -475,14 +772,15 @@ void
|
|||||||
playSynthesizedVoiceR (dsd_opts * opts, dsd_state * state)
|
playSynthesizedVoiceR (dsd_opts * opts, dsd_state * state)
|
||||||
{
|
{
|
||||||
ssize_t result;
|
ssize_t result;
|
||||||
|
UNUSED(result);
|
||||||
|
|
||||||
if (state->audio_out_idxR > opts->delay)
|
if (state->audio_out_idxR > opts->delay)
|
||||||
{
|
{
|
||||||
// output synthesized speech to sound card
|
// output synthesized speech to sound card
|
||||||
if (opts->audio_out_type == 5) //OSS
|
if (opts->audio_out_type == 5) //OSS
|
||||||
{
|
{
|
||||||
//OSS
|
//OSS 48k/1
|
||||||
result = write (opts->audio_out_fdR, (state->audio_out_buf_pR - state->audio_out_idxR), (state->audio_out_idxR * 2));
|
result = write (opts->audio_out_fd, (state->audio_out_buf_pR - state->audio_out_idxR), (state->audio_out_idxR * 2));
|
||||||
state->audio_out_idxR = 0;
|
state->audio_out_idxR = 0;
|
||||||
}
|
}
|
||||||
else if (opts->audio_out_type == 0)
|
else if (opts->audio_out_type == 0)
|
||||||
@@ -490,6 +788,11 @@ playSynthesizedVoiceR (dsd_opts * opts, dsd_state * state)
|
|||||||
pa_simple_write(opts->pulse_digi_dev_outR, (state->audio_out_buf_pR - state->audio_out_idxR), (state->audio_out_idxR * 2), NULL);
|
pa_simple_write(opts->pulse_digi_dev_outR, (state->audio_out_buf_pR - state->audio_out_idxR), (state->audio_out_idxR * 2), NULL);
|
||||||
state->audio_out_idxR = 0;
|
state->audio_out_idxR = 0;
|
||||||
}
|
}
|
||||||
|
else if (opts->audio_out_type == 8) //UDP Audio Out -- Not sure how this would handle, but R never gets called anymore, so just here for symmetry
|
||||||
|
{
|
||||||
|
udp_socket_blaster (opts, state, (state->audio_out_idxR * 2), (state->audio_out_buf_pR - state->audio_out_idxR));
|
||||||
|
state->audio_out_idxR = 0;
|
||||||
|
}
|
||||||
else state->audio_out_idxR = 0; //failsafe for audio_out == 0
|
else state->audio_out_idxR = 0; //failsafe for audio_out == 0
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -507,6 +810,8 @@ playSynthesizedVoiceR (dsd_opts * opts, dsd_state * state)
|
|||||||
void
|
void
|
||||||
openAudioOutDevice (dsd_opts * opts, int speed)
|
openAudioOutDevice (dsd_opts * opts, int speed)
|
||||||
{
|
{
|
||||||
|
UNUSED(speed);
|
||||||
|
|
||||||
//converted to handle any calls to use portaudio
|
//converted to handle any calls to use portaudio
|
||||||
if(strncmp(opts->audio_out_dev, "pa:", 3) == 0)
|
if(strncmp(opts->audio_out_dev, "pa:", 3) == 0)
|
||||||
{
|
{
|
||||||
@@ -521,7 +826,7 @@ openAudioOutDevice (dsd_opts * opts, int speed)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
struct stat stat_buf;
|
// struct stat stat_buf;
|
||||||
// if(stat(opts->audio_out_dev, &stat_buf) != 0 && strncmp(opts->audio_out_dev, "pulse", 5 != 0)) //HERE
|
// if(stat(opts->audio_out_dev, &stat_buf) != 0 && strncmp(opts->audio_out_dev, "pulse", 5 != 0)) //HERE
|
||||||
// {
|
// {
|
||||||
// fprintf (stderr,"Error, couldn't open %s\n", opts->audio_out_dev);
|
// fprintf (stderr,"Error, couldn't open %s\n", opts->audio_out_dev);
|
||||||
@@ -545,6 +850,9 @@ openAudioInDevice (dsd_opts * opts)
|
|||||||
const char ch = '.';
|
const char ch = '.';
|
||||||
extension = strrchr(opts->audio_in_dev, ch); //return extension if this is a .wav or .bin file
|
extension = strrchr(opts->audio_in_dev, ch); //return extension if this is a .wav or .bin file
|
||||||
|
|
||||||
|
//if no extension set, give default of .wav -- bugfix for github issue #105
|
||||||
|
// if (extension == NULL) extension = ".wav";
|
||||||
|
|
||||||
// get info of device/file
|
// get info of device/file
|
||||||
if (strncmp(opts->audio_in_dev, "-", 1) == 0)
|
if (strncmp(opts->audio_in_dev, "-", 1) == 0)
|
||||||
{
|
{
|
||||||
@@ -563,6 +871,11 @@ openAudioInDevice (dsd_opts * opts)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
else if (strncmp(opts->audio_in_dev, "m17udp", 6) == 0)
|
||||||
|
{
|
||||||
|
opts->audio_in_type = 9; //NULL audio device
|
||||||
|
}
|
||||||
|
|
||||||
else if (strncmp(opts->audio_in_dev, "tcp", 3) == 0)
|
else if (strncmp(opts->audio_in_dev, "tcp", 3) == 0)
|
||||||
{
|
{
|
||||||
opts->audio_in_type = 8;
|
opts->audio_in_type = 8;
|
||||||
@@ -579,25 +892,34 @@ openAudioInDevice (dsd_opts * opts)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (strncmp(opts->audio_in_dev, "udp", 3) == 0)
|
// else if (strncmp(opts->audio_in_dev, "udp", 3) == 0)
|
||||||
{
|
// {
|
||||||
opts->audio_in_type = 6;
|
// opts->audio_in_type = 6;
|
||||||
opts->audio_in_file_info = calloc(1, sizeof(SF_INFO));
|
// opts->audio_in_file_info = calloc(1, sizeof(SF_INFO));
|
||||||
opts->audio_in_file_info->samplerate=opts->wav_sample_rate;
|
// opts->audio_in_file_info->samplerate=opts->wav_sample_rate;
|
||||||
opts->audio_in_file_info->channels=1;
|
// opts->audio_in_file_info->channels=1;
|
||||||
opts->audio_in_file_info->seekable=0;
|
// opts->audio_in_file_info->seekable=0;
|
||||||
opts->audio_in_file_info->format=SF_FORMAT_RAW|SF_FORMAT_PCM_16|SF_ENDIAN_LITTLE;
|
// opts->audio_in_file_info->format=SF_FORMAT_RAW|SF_FORMAT_PCM_16|SF_ENDIAN_LITTLE;
|
||||||
opts->udp_file_in = sf_open_fd(opts->udp_sockfd, SFM_READ, opts->audio_in_file_info, 0);
|
// opts->udp_file_in = sf_open_fd(opts->udp_sockfd, SFM_READ, opts->audio_in_file_info, 0);
|
||||||
|
|
||||||
|
// if(opts->udp_file_in == NULL)
|
||||||
|
// {
|
||||||
|
// fprintf(stderr, "Error, couldn't open UDP with libsndfile: %s\n", sf_strerror(NULL));
|
||||||
|
// exit(1);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
if(opts->udp_file_in == NULL)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "Error, couldn't open UDP with libsndfile: %s\n", sf_strerror(NULL));
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if(strncmp(opts->audio_in_dev, "rtl", 3) == 0)
|
else if(strncmp(opts->audio_in_dev, "rtl", 3) == 0)
|
||||||
{
|
{
|
||||||
|
#ifdef USE_RTLSDR
|
||||||
opts->audio_in_type = 3;
|
opts->audio_in_type = 3;
|
||||||
|
#elif AERO_BUILD
|
||||||
|
opts->audio_in_type = 5;
|
||||||
|
sprintf (opts->audio_in_dev, "/dev/dsp");
|
||||||
|
#else
|
||||||
|
opts->audio_in_type = 0;
|
||||||
|
sprintf (opts->audio_in_dev, "pulse");
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
else if(strncmp(opts->audio_in_dev, "pulse", 5) == 0)
|
else if(strncmp(opts->audio_in_dev, "pulse", 5) == 0)
|
||||||
{
|
{
|
||||||
@@ -607,7 +929,87 @@ openAudioInDevice (dsd_opts * opts)
|
|||||||
{
|
{
|
||||||
opts->audio_in_type = 5;
|
opts->audio_in_type = 5;
|
||||||
}
|
}
|
||||||
else if (strncmp(extension, ".bin", 3) == 0)
|
|
||||||
|
//if no extension set, treat as named pipe or extensionless wav file -- bugfix for github issue #105
|
||||||
|
else if (extension == NULL)
|
||||||
|
{
|
||||||
|
opts->audio_in_type = 2;
|
||||||
|
opts->audio_in_file_info = calloc(1, sizeof(SF_INFO));
|
||||||
|
opts->audio_in_file_info->samplerate = opts->wav_sample_rate;
|
||||||
|
opts->audio_in_file_info->channels = 1;
|
||||||
|
opts->audio_in_file_info->seekable = 0;
|
||||||
|
opts->audio_in_file_info->format = SF_FORMAT_RAW | SF_FORMAT_PCM_16 | SF_ENDIAN_LITTLE;
|
||||||
|
opts->audio_in_file = sf_open(opts->audio_in_dev, SFM_READ, opts->audio_in_file_info);
|
||||||
|
|
||||||
|
if (opts->audio_in_file == NULL)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Error, couldn't open file/pipe with libsndfile: %s\n", sf_strerror(NULL));
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//test .rrc files with hardset wav file settings
|
||||||
|
else if (strncmp(extension, ".rrc", 4) == 0)
|
||||||
|
{
|
||||||
|
//debug
|
||||||
|
fprintf (stderr, "Opening M17 .rrc headless wav file\n");
|
||||||
|
|
||||||
|
opts->audio_in_type = 2;
|
||||||
|
opts->audio_in_file_info = calloc(1, sizeof(SF_INFO));
|
||||||
|
opts->audio_in_file_info->samplerate = 48000;
|
||||||
|
opts->audio_in_file_info->channels = 1;
|
||||||
|
opts->audio_in_file_info->seekable = 0;
|
||||||
|
opts->audio_in_file_info->format = SF_FORMAT_RAW | SF_FORMAT_PCM_16 | SF_ENDIAN_LITTLE;
|
||||||
|
opts->audio_in_file = sf_open(opts->audio_in_dev, SFM_READ, opts->audio_in_file_info);
|
||||||
|
|
||||||
|
if(opts->audio_in_file == NULL)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Error, couldn't open %s with libsndfile: %s\n", opts->audio_in_dev, sf_strerror(NULL));
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Open .raw files as a float input type
|
||||||
|
else if (strncmp(extension, ".raw", 4) == 0)
|
||||||
|
{
|
||||||
|
struct stat stat_buf;
|
||||||
|
if (stat(opts->audio_in_dev, &stat_buf) != 0)
|
||||||
|
{
|
||||||
|
fprintf (stderr,"Error, couldn't open raw (float) file %s\n", opts->audio_in_dev);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
if (S_ISREG(stat_buf.st_mode))
|
||||||
|
{
|
||||||
|
opts->symbolfile = fopen(opts->audio_in_dev, "r");
|
||||||
|
opts->audio_in_type = 44; //float symbol input
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
opts->audio_in_type = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Open .raw files as a float input type
|
||||||
|
else if (strncmp(extension, ".sym", 4) == 0)
|
||||||
|
{
|
||||||
|
struct stat stat_buf;
|
||||||
|
if (stat(opts->audio_in_dev, &stat_buf) != 0)
|
||||||
|
{
|
||||||
|
fprintf (stderr,"Error, couldn't open sym (float) file %s\n", opts->audio_in_dev);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
if (S_ISREG(stat_buf.st_mode))
|
||||||
|
{
|
||||||
|
opts->symbolfile = fopen(opts->audio_in_dev, "r");
|
||||||
|
opts->audio_in_type = 44; //float symbol input
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
opts->audio_in_type = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (strncmp(extension, ".bin", 4) == 0)
|
||||||
{
|
{
|
||||||
struct stat stat_buf;
|
struct stat stat_buf;
|
||||||
if (stat(opts->audio_in_dev, &stat_buf) != 0)
|
if (stat(opts->audio_in_dev, &stat_buf) != 0)
|
||||||
|
|||||||
2427
src/dsd_audio2.c
Normal file
2427
src/dsd_audio2.c
Normal file
File diff suppressed because it is too large
Load Diff
@@ -16,6 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <limits.h>
|
||||||
|
|
||||||
#include "dsd.h"
|
#include "dsd.h"
|
||||||
|
|
||||||
@@ -118,23 +119,49 @@ print_datascope(dsd_opts* opts, dsd_state* state, int* sbuf2)
|
|||||||
static void
|
static void
|
||||||
use_symbol (dsd_opts* opts, dsd_state* state, int symbol)
|
use_symbol (dsd_opts* opts, dsd_state* state, int symbol)
|
||||||
{
|
{
|
||||||
int i;
|
UNUSED(symbol);
|
||||||
int sbuf2[128];
|
|
||||||
int lmin, lmax, lsum;
|
|
||||||
|
|
||||||
|
int i;
|
||||||
|
int lmin, lmax, lsum;
|
||||||
|
int lmn[2] = {INT_MAX, INT_MAX};
|
||||||
|
int lmx[2] = {INT_MIN, INT_MIN};
|
||||||
|
|
||||||
|
// single-pass tracking of the 2 smallest and 2 largest values in the symbol window
|
||||||
for (i = 0; i < opts->ssize; i++)
|
for (i = 0; i < opts->ssize; i++)
|
||||||
{
|
{
|
||||||
sbuf2[i] = state->sbuf[i];
|
int x = state->sbuf[i];
|
||||||
|
if (x < lmn[1])
|
||||||
|
{
|
||||||
|
if (x < lmn[0])
|
||||||
|
{
|
||||||
|
lmn[1] = lmn[0];
|
||||||
|
lmn[0] = x;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
lmn[1] = x;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (x > lmx[1])
|
||||||
|
{
|
||||||
|
if (x > lmx[0])
|
||||||
|
{
|
||||||
|
lmx[1] = lmx[0];
|
||||||
|
lmx[0] = x;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
lmx[1] = x;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
qsort (sbuf2, opts->ssize, sizeof (int), comp);
|
|
||||||
|
|
||||||
// continuous update of min/max in rf_mod=1 (QPSK) mode
|
// continuous update of min/max in rf_mod=1 (QPSK) mode
|
||||||
// in c4fm min/max must only be updated during sync
|
// in c4fm min/max must only be updated during sync
|
||||||
if (state->rf_mod == 1)
|
if (state->rf_mod == 1)
|
||||||
{
|
{
|
||||||
lmin = (sbuf2[0] + sbuf2[1]) / 2;
|
lmin = (lmn[0] + lmn[1]) / 2;
|
||||||
lmax = (sbuf2[(opts->ssize - 1)] + sbuf2[(opts->ssize - 2)]) / 2;
|
lmax = (lmx[1] + lmx[0]) / 2;
|
||||||
state->minbuf[state->midx] = lmin;
|
state->minbuf[state->midx] = lmin;
|
||||||
state->maxbuf[state->midx] = lmax;
|
state->maxbuf[state->midx] = lmax;
|
||||||
if (state->midx == (opts->msize - 1))
|
if (state->midx == (opts->msize - 1))
|
||||||
@@ -176,7 +203,7 @@ use_symbol (dsd_opts* opts, dsd_state* state, int symbol)
|
|||||||
|
|
||||||
if (opts->datascope == 1)
|
if (opts->datascope == 1)
|
||||||
{
|
{
|
||||||
print_datascope(opts, state, sbuf2);
|
print_datascope(opts, state, state->sbuf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -217,8 +244,7 @@ invert_dibit(int dibit)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int digitize (dsd_opts* opts, dsd_state* state, int symbol)
|
int digitize (dsd_opts* opts, dsd_state* state, int symbol)
|
||||||
//int digitize (dsd_opts* opts, dsd_state* state, int symbol)
|
|
||||||
{
|
{
|
||||||
// determine dibit state
|
// determine dibit state
|
||||||
if ((state->synctype == 6) || (state->synctype == 14)|| (state->synctype == 18) || (state->synctype == 37))
|
if ((state->synctype == 6) || (state->synctype == 14)|| (state->synctype == 18) || (state->synctype == 37))
|
||||||
@@ -265,30 +291,39 @@ static int digitize (dsd_opts* opts, dsd_state* state, int symbol)
|
|||||||
|
|
||||||
else if ((state->synctype == 1) || (state->synctype == 3) || (state->synctype == 5) ||
|
else if ((state->synctype == 1) || (state->synctype == 3) || (state->synctype == 5) ||
|
||||||
(state->synctype == 9) || (state->synctype == 11) || (state->synctype == 13) ||
|
(state->synctype == 9) || (state->synctype == 11) || (state->synctype == 13) ||
|
||||||
(state->synctype == 17) || (state->synctype == 29) || (state->synctype == 36) )
|
(state->synctype == 17) || (state->synctype == 29) || (state->synctype == 31) ||
|
||||||
|
(state->synctype == 77) || (state->synctype == 87) ||(state->synctype == 36) ||
|
||||||
|
(state->synctype == 99) )
|
||||||
|
|
||||||
{
|
{
|
||||||
// 1 -P25p1
|
// 1 -P25p1
|
||||||
// 3 -X2-TDMA (inverted signal voice frame)
|
// 3 -X2-TDMA (inverted signal voice frame)
|
||||||
// 5 -X2-TDMA (inverted signal data frame)
|
// 5 -X2-TDMA (inverted signal data frame)
|
||||||
// 9 -NXDN (inverted voice frame)
|
// 9 -M17 LSR
|
||||||
// 11 -DMR (inverted signal voice frame)
|
// 11 -DMR (inverted signal voice frame)
|
||||||
// 13 -DMR (inverted signal data frame)
|
// 13 -DMR (inverted signal data frame)
|
||||||
// 17 -NXDN (inverted data frame)
|
// 17 -M17 STR
|
||||||
// 29 -NXDN (inverted FSW)
|
// 29 -NXDN (inverted FSW)
|
||||||
|
// 31 -YSF
|
||||||
// 36 -P25p2
|
// 36 -P25p2
|
||||||
|
// 77 -M17 BRT
|
||||||
|
// 87 -M17 PKT
|
||||||
|
// 99 -M17 Preamble
|
||||||
|
|
||||||
int valid;
|
int valid;
|
||||||
int dibit;
|
int dibit;
|
||||||
|
|
||||||
valid = 0;
|
valid = 0;
|
||||||
|
|
||||||
//disabling again, causing issues with trunking P25
|
UNUSED(opts);
|
||||||
if (state->synctype == 1 && opts->p25_trunk == 1)
|
|
||||||
{
|
//testing again, either on Voice channels only (when tuned) or with trunk disabled
|
||||||
// Use the P25 heuristics if available
|
// if (state->synctype == 1 && (opts->p25_is_tuned == 1 || opts->p25_trunk == 0) && opts->use_heuristics == 1)
|
||||||
// valid = estimate_symbol(state->rf_mod, &(state->inv_p25_heuristics), state->last_dibit, symbol, &dibit);
|
if (state->synctype == 1 && opts->use_heuristics == 1)
|
||||||
}
|
{
|
||||||
|
// Use the P25p1 heuristics if available
|
||||||
|
valid = estimate_symbol(state->rf_mod, &(state->inv_p25_heuristics), state->last_dibit, symbol, &dibit);
|
||||||
|
}
|
||||||
|
|
||||||
if (valid == 0)
|
if (valid == 0)
|
||||||
{
|
{
|
||||||
@@ -335,24 +370,29 @@ static int digitize (dsd_opts* opts, dsd_state* state, int symbol)
|
|||||||
// 0 +P25p1
|
// 0 +P25p1
|
||||||
// 2 +X2-TDMA (non inverted signal data frame)
|
// 2 +X2-TDMA (non inverted signal data frame)
|
||||||
// 4 +X2-TDMA (non inverted signal voice frame)
|
// 4 +X2-TDMA (non inverted signal voice frame)
|
||||||
// 8 +NXDN (non inverted voice frame)
|
// 8 +M17 LSF
|
||||||
// 10 +DMR (non inverted signal data frame)
|
// 10 +DMR (non inverted signal data frame)
|
||||||
// 12 +DMR (non inverted signal voice frame)
|
// 12 +DMR (non inverted signal voice frame)
|
||||||
// 16 +NXDN (non inverted data frame)
|
// 16 +M17 STR
|
||||||
// 28 +NXND (FSW)
|
// 28 +NXND (FSW)
|
||||||
|
// 30 +YSF
|
||||||
// 35 +p25p2
|
// 35 +p25p2
|
||||||
|
// 76 +M17 BRT
|
||||||
|
// 86 +M17 PKT
|
||||||
|
// 98 +M17 Preamble
|
||||||
|
|
||||||
int valid;
|
int valid;
|
||||||
int dibit;
|
int dibit;
|
||||||
|
|
||||||
valid = 0;
|
valid = 0;
|
||||||
|
|
||||||
//disabling again, causing issues with trunking P25
|
//testing again, either on Voice channels only (when tuned) or with trunk disabled
|
||||||
if (state->synctype == 0 && opts->p25_trunk == 1)
|
// if (state->synctype == 0 && (opts->p25_is_tuned == 1 || opts->p25_trunk == 0) && opts->use_heuristics == 1)
|
||||||
{
|
if (state->synctype == 0 && opts->use_heuristics == 1)
|
||||||
// Use the P25 heuristics if available
|
{
|
||||||
// valid = estimate_symbol(state->rf_mod, &(state->p25_heuristics), state->last_dibit, symbol, &dibit);
|
// Use the P25p1 heuristics if available
|
||||||
}
|
valid = estimate_symbol(state->rf_mod, &(state->p25_heuristics), state->last_dibit, symbol, &dibit);
|
||||||
|
}
|
||||||
|
|
||||||
if (valid == 0)
|
if (valid == 0)
|
||||||
{
|
{
|
||||||
@@ -445,7 +485,7 @@ get_dibit_and_analog_signal (dsd_opts* opts, dsd_state* state, int* out_analog_s
|
|||||||
}
|
}
|
||||||
|
|
||||||
//symbol/dibit file capture/writing
|
//symbol/dibit file capture/writing
|
||||||
if (opts->symbol_out == 1)
|
if (opts->symbol_out_f)
|
||||||
{
|
{
|
||||||
//fprintf (stderr, "%d", dibit);
|
//fprintf (stderr, "%d", dibit);
|
||||||
fputc (dibit, opts->symbol_out_f);
|
fputc (dibit, opts->symbol_out_f);
|
||||||
@@ -482,6 +522,7 @@ skipDibit (dsd_opts * opts, dsd_state * state, int count)
|
|||||||
|
|
||||||
short sample;
|
short sample;
|
||||||
int i;
|
int i;
|
||||||
|
UNUSED(sample);
|
||||||
|
|
||||||
for (i = 0; i < (count); i++)
|
for (i = 0; i < (count); i++)
|
||||||
{
|
{
|
||||||
|
|||||||
870
src/dsd_events.c
Normal file
870
src/dsd_events.c
Normal file
@@ -0,0 +1,870 @@
|
|||||||
|
/*-------------------------------------------------------------------------------
|
||||||
|
* dsd_events.c
|
||||||
|
* DSD-FME event history init, watchdog, push, and related functions
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* LWVMOBILE
|
||||||
|
* 2025-05 DSD-FME Florida Man Edition
|
||||||
|
*-----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#include "dsd.h"
|
||||||
|
#include "git_ver.h"
|
||||||
|
#include "synctype.h"
|
||||||
|
|
||||||
|
//init each event history struct passed into here
|
||||||
|
void init_event_history (Event_History_I * event_struct, uint8_t start, uint8_t stop)
|
||||||
|
{
|
||||||
|
for (uint8_t i = start; i < stop; i++)
|
||||||
|
{
|
||||||
|
event_struct->Event_History_Items[i].write = 0;
|
||||||
|
event_struct->Event_History_Items[i].color_pair = 4;
|
||||||
|
event_struct->Event_History_Items[i].systype = -1;
|
||||||
|
event_struct->Event_History_Items[i].subtype = -1;
|
||||||
|
event_struct->Event_History_Items[i].sys_id1 = 0;
|
||||||
|
event_struct->Event_History_Items[i].sys_id2 = 0;
|
||||||
|
event_struct->Event_History_Items[i].sys_id3 = 0;
|
||||||
|
event_struct->Event_History_Items[i].sys_id4 = 0;
|
||||||
|
event_struct->Event_History_Items[i].sys_id5 = 0;
|
||||||
|
event_struct->Event_History_Items[i].gi = 0;
|
||||||
|
event_struct->Event_History_Items[i].enc = 0;
|
||||||
|
event_struct->Event_History_Items[i].enc_alg = 0;
|
||||||
|
event_struct->Event_History_Items[i].enc_key = 0;
|
||||||
|
event_struct->Event_History_Items[i].mi = 0;
|
||||||
|
event_struct->Event_History_Items[i].svc = 0;
|
||||||
|
event_struct->Event_History_Items[i].source_id = 0;
|
||||||
|
event_struct->Event_History_Items[i].target_id = 0;
|
||||||
|
sprintf (event_struct->Event_History_Items[i].src_str, "%s", "BUMBLEBEETUNA");
|
||||||
|
sprintf (event_struct->Event_History_Items[i].tgt_str, "%s", "BUMBLEBEETUNA");
|
||||||
|
sprintf (event_struct->Event_History_Items[i].t_name, "%s", "BUMBLEBEETUNA");
|
||||||
|
sprintf (event_struct->Event_History_Items[i].s_name, "%s", "BUMBLEBEETUNA");
|
||||||
|
sprintf (event_struct->Event_History_Items[i].t_mode, "%s", "BUMBLEBEETUNA");
|
||||||
|
sprintf (event_struct->Event_History_Items[i].s_mode, "%s", "BUMBLEBEETUNA");
|
||||||
|
event_struct->Event_History_Items[i].channel = 0;
|
||||||
|
event_struct->Event_History_Items[i].event_time = 0;
|
||||||
|
|
||||||
|
memset (event_struct->Event_History_Items[i].pdu, 0, sizeof(event_struct->Event_History_Items[0].pdu));
|
||||||
|
sprintf (event_struct->Event_History_Items[i].sysid_string, "%s", "");
|
||||||
|
sprintf (event_struct->Event_History_Items[i].alias, "%s", "BUMBLEBEETUNA");
|
||||||
|
sprintf (event_struct->Event_History_Items[i].gps_s, "%s", "BUMBLEBEETUNA");
|
||||||
|
sprintf (event_struct->Event_History_Items[i].text_message, "%s", "BUMBLEBEETUNA");
|
||||||
|
sprintf (event_struct->Event_History_Items[i].event_string, "%s", "BUMBLEBEETUNA");
|
||||||
|
sprintf (event_struct->Event_History_Items[i].internal_str, "%s", "BUMBLEBEETUNA");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void push_event_history (Event_History_I * event_struct)
|
||||||
|
{
|
||||||
|
|
||||||
|
//Fixed, had it going in the wrong direction first time
|
||||||
|
for (uint8_t i = 254; i >= 1; i--)
|
||||||
|
{
|
||||||
|
event_struct->Event_History_Items[i].write = event_struct->Event_History_Items[i-1].write;
|
||||||
|
event_struct->Event_History_Items[i].color_pair = event_struct->Event_History_Items[i-1].color_pair;
|
||||||
|
event_struct->Event_History_Items[i].systype = event_struct->Event_History_Items[i-1].systype;
|
||||||
|
event_struct->Event_History_Items[i].subtype = event_struct->Event_History_Items[i-1].subtype;
|
||||||
|
event_struct->Event_History_Items[i].sys_id1 = event_struct->Event_History_Items[i-1].sys_id1;
|
||||||
|
event_struct->Event_History_Items[i].sys_id2 = event_struct->Event_History_Items[i-1].sys_id2;
|
||||||
|
event_struct->Event_History_Items[i].sys_id3 = event_struct->Event_History_Items[i-1].sys_id3;
|
||||||
|
event_struct->Event_History_Items[i].sys_id4 = event_struct->Event_History_Items[i-1].sys_id4;
|
||||||
|
event_struct->Event_History_Items[i].sys_id5 = event_struct->Event_History_Items[i-1].sys_id5;
|
||||||
|
event_struct->Event_History_Items[i].gi = event_struct->Event_History_Items[i-1].gi;
|
||||||
|
event_struct->Event_History_Items[i].enc = event_struct->Event_History_Items[i-1].enc;
|
||||||
|
event_struct->Event_History_Items[i].enc_alg = event_struct->Event_History_Items[i-1].enc_alg;
|
||||||
|
event_struct->Event_History_Items[i].enc_key = event_struct->Event_History_Items[i-1].enc_key;
|
||||||
|
event_struct->Event_History_Items[i].mi = event_struct->Event_History_Items[i-1].mi;
|
||||||
|
event_struct->Event_History_Items[i].svc = event_struct->Event_History_Items[i-1].svc;
|
||||||
|
event_struct->Event_History_Items[i].source_id = event_struct->Event_History_Items[i-1].source_id;
|
||||||
|
event_struct->Event_History_Items[i].target_id = event_struct->Event_History_Items[i-1].target_id;
|
||||||
|
sprintf (event_struct->Event_History_Items[i].src_str, "%s", event_struct->Event_History_Items[i-1].src_str);
|
||||||
|
sprintf (event_struct->Event_History_Items[i].tgt_str, "%s", event_struct->Event_History_Items[i-1].tgt_str);
|
||||||
|
sprintf (event_struct->Event_History_Items[i].t_name, "%s", event_struct->Event_History_Items[i-1].t_name);
|
||||||
|
sprintf (event_struct->Event_History_Items[i].s_name, "%s", event_struct->Event_History_Items[i-1].s_name);
|
||||||
|
sprintf (event_struct->Event_History_Items[i].t_mode, "%s", event_struct->Event_History_Items[i-1].t_mode);
|
||||||
|
sprintf (event_struct->Event_History_Items[i].s_mode, "%s", event_struct->Event_History_Items[i-1].s_mode);
|
||||||
|
event_struct->Event_History_Items[i].channel = event_struct->Event_History_Items[i-1].channel;
|
||||||
|
event_struct->Event_History_Items[i].event_time = event_struct->Event_History_Items[i+1].event_time;
|
||||||
|
|
||||||
|
memcpy (event_struct->Event_History_Items[i].pdu, event_struct->Event_History_Items[i-1].pdu, sizeof(event_struct->Event_History_Items[0].pdu));
|
||||||
|
sprintf (event_struct->Event_History_Items[i].sysid_string, "%s", event_struct->Event_History_Items[i-1].sysid_string);
|
||||||
|
sprintf (event_struct->Event_History_Items[i].alias, "%s", event_struct->Event_History_Items[i-1].alias);
|
||||||
|
sprintf (event_struct->Event_History_Items[i].gps_s, "%s", event_struct->Event_History_Items[i-1].gps_s);
|
||||||
|
sprintf (event_struct->Event_History_Items[i].text_message, "%s", event_struct->Event_History_Items[i-1].text_message);
|
||||||
|
sprintf (event_struct->Event_History_Items[i].event_string, "%s", event_struct->Event_History_Items[i-1].event_string);
|
||||||
|
sprintf (event_struct->Event_History_Items[i].internal_str, "%s", event_struct->Event_History_Items[i-1].internal_str);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void write_event_to_log_file (dsd_opts * opts, dsd_state * state, uint8_t slot, uint8_t swrite, char * event_string) //pass completed event string here that is in the struct
|
||||||
|
{
|
||||||
|
|
||||||
|
//open log file
|
||||||
|
FILE * event_log_file;
|
||||||
|
event_log_file = fopen(opts->event_out_file, "a");
|
||||||
|
|
||||||
|
fprintf (event_log_file, "%s ", event_string);
|
||||||
|
if (swrite == 1)
|
||||||
|
fprintf (event_log_file, "Slot %d; ", slot+1);
|
||||||
|
fprintf (event_log_file,"\n");
|
||||||
|
|
||||||
|
char text_string[2000]; sprintf (text_string, "%s", "BUMBLEBEETUNA");
|
||||||
|
if (strncmp(text_string, state->event_history_s[slot].Event_History_Items[0].text_message, 13) != 0)
|
||||||
|
fprintf (event_log_file, "%s \n", state->event_history_s[slot].Event_History_Items[0].text_message);
|
||||||
|
if (strncmp(text_string, state->event_history_s[slot].Event_History_Items[0].alias, 13) != 0)
|
||||||
|
fprintf (event_log_file, " Talker Alias: %s \n", state->event_history_s[slot].Event_History_Items[0].alias);
|
||||||
|
if (strncmp(text_string, state->event_history_s[slot].Event_History_Items[0].gps_s, 13) != 0)
|
||||||
|
fprintf (event_log_file, " GPS: %s \n", state->event_history_s[slot].Event_History_Items[0].gps_s);
|
||||||
|
if (strncmp(text_string, state->event_history_s[slot].Event_History_Items[0].internal_str, 13) != 0)
|
||||||
|
fprintf (event_log_file, " DSD-FME: %s \n", state->event_history_s[slot].Event_History_Items[0].internal_str);
|
||||||
|
|
||||||
|
//flush and close log file
|
||||||
|
fflush (event_log_file);
|
||||||
|
fclose (event_log_file);
|
||||||
|
}
|
||||||
|
|
||||||
|
// run once per loop to check for and push and update event history
|
||||||
|
void watchdog_event_history (dsd_opts * opts, dsd_state * state, uint8_t slot)
|
||||||
|
{
|
||||||
|
|
||||||
|
//create a pointer to the current slot event history
|
||||||
|
Event_History_I * event_struct = &state->event_history_s[slot];
|
||||||
|
|
||||||
|
//is this a TDMA slot (append Slot value to end of written event history)
|
||||||
|
uint8_t swrite = 0;
|
||||||
|
|
||||||
|
//who is currently talking
|
||||||
|
uint32_t source_id = 0;
|
||||||
|
|
||||||
|
//last values pulled from the event history
|
||||||
|
uint32_t last_source_id = event_struct->Event_History_Items[0].source_id;
|
||||||
|
|
||||||
|
if (slot == 0)
|
||||||
|
source_id = state->lastsrc;
|
||||||
|
else
|
||||||
|
source_id = state->lastsrcR;
|
||||||
|
|
||||||
|
//if DMR BS or P25P2, then flag the swrite, so write can append slot value to event history log //|| state->lastsynctype == 32 || state->lastsynctype == 33 || state->lastsynctype == 34 MS
|
||||||
|
if (state->lastsynctype == 10 || state->lastsynctype == 11 || state->lastsynctype == 12 || state->lastsynctype == 13)
|
||||||
|
swrite = 1;
|
||||||
|
|
||||||
|
else if (state->lastsynctype == 35 || state->lastsynctype == 36)
|
||||||
|
swrite = 1;
|
||||||
|
|
||||||
|
if (slot == 0) //BUGFIX: generic catch on FDMA systems so that we don't write duplicate data to slot 2 event history
|
||||||
|
{
|
||||||
|
//NXDN RID (TODO: Changeover to lastsrc later on)
|
||||||
|
if (state->lastsynctype == 28 || state->lastsynctype == 29)
|
||||||
|
source_id = state->nxdn_last_rid;
|
||||||
|
|
||||||
|
if (state->lastsynctype == 30 || state->lastsynctype == 31) //YSF Fusion
|
||||||
|
{
|
||||||
|
source_id = 0;
|
||||||
|
if (strncmp(state->ysf_src, " ", 10) != 0) //if this field does not have ten spaces in it
|
||||||
|
{
|
||||||
|
for (uint8_t i = 0; i < 11; i++)
|
||||||
|
source_id += state->ysf_src[i]; //convert to sum value to make a distinct enough src value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state->lastsynctype == 8 || state->lastsynctype == 9 || state->lastsynctype == 16 || state->lastsynctype == 17) //M17 STR
|
||||||
|
{
|
||||||
|
source_id = (uint32_t)state->m17_src;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state->lastsynctype == 6 || state->lastsynctype == 7 || state->lastsynctype == 18 || state->lastsynctype == 19) //DSTAR
|
||||||
|
{
|
||||||
|
source_id = 0;
|
||||||
|
for (uint8_t i = 0; i < 12; i++)
|
||||||
|
source_id += state->dstar_src[i]; //convert to sum value to make a distinct enough src value
|
||||||
|
|
||||||
|
//need a strncmp here for 8 spaces in this field first so we don't blip a blank into the event history
|
||||||
|
if (strncmp(state->dstar_src, " ", 8) == 0)
|
||||||
|
source_id = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state->lastsynctype == 20 || state->lastsynctype == 24 || state->lastsynctype == 21 || state->lastsynctype == 25 || state->lastsynctype == 22 || state->lastsynctype == 26 || state->lastsynctype == 23 || state->lastsynctype == 27) //dPMR
|
||||||
|
{
|
||||||
|
source_id = 0;
|
||||||
|
for (uint8_t i = 0; i < 20; i++)
|
||||||
|
source_id += state->dpmr_caller_id[i]; //convert to sum value to make a distinct enough src value
|
||||||
|
|
||||||
|
//need a strncmp here for 8 spaces in this field first so we don't blip a blank into the event history
|
||||||
|
if (strncmp(state->dpmr_caller_id, " ", 6) == 0)
|
||||||
|
source_id = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state->lastsynctype == 14 || state->lastsynctype == 15 || state->lastsynctype == 37 || state->lastsynctype == 38) //EDACS Calls
|
||||||
|
{
|
||||||
|
source_id = 0;
|
||||||
|
if (opts->p25_is_tuned == 1)
|
||||||
|
source_id = state->lastsrc;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//call alert beep when new call detected
|
||||||
|
if (last_source_id == 0 && source_id != 0 && opts->call_alert == 1)
|
||||||
|
beeper (opts, state, slot, 40, 86, 3);
|
||||||
|
|
||||||
|
if (source_id != last_source_id && last_source_id != 0)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (opts->event_out_file[0] != 0)
|
||||||
|
write_event_to_log_file(opts, state, slot, swrite, event_struct->Event_History_Items[0].event_string);
|
||||||
|
|
||||||
|
event_struct->Event_History_Items[0].write = 1; //written, or pushed at this point
|
||||||
|
|
||||||
|
if (opts->static_wav_file == 0)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (slot == 0 && opts->wav_out_f != NULL)
|
||||||
|
{
|
||||||
|
opts->wav_out_f = close_and_rename_wav_file(opts->wav_out_f, opts->wav_out_file, opts->wav_out_dir, opts->wav_custom_tag, event_struct);
|
||||||
|
opts->wav_out_f = open_wav_file(opts->wav_out_dir, opts->wav_out_file, 8000, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (slot == 1 && opts->wav_out_fR != NULL)
|
||||||
|
{
|
||||||
|
opts->wav_out_fR = close_and_rename_wav_file(opts->wav_out_fR, opts->wav_out_fileR, opts->wav_out_dir, opts->wav_custom_tag, event_struct);
|
||||||
|
opts->wav_out_fR = open_wav_file(opts->wav_out_dir, opts->wav_out_fileR, 8000, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
push_event_history (event_struct);
|
||||||
|
init_event_history (event_struct, 0, 1);
|
||||||
|
|
||||||
|
//clear out some strings and things
|
||||||
|
memset(state->ysf_txt, 0, sizeof(state->ysf_txt));
|
||||||
|
memset(state->dstar_gps, 0, sizeof(state->dstar_gps));
|
||||||
|
memset(state->dstar_txt, 0, sizeof(state->dstar_txt));
|
||||||
|
state->gi[slot] = -1; //return to an unset value
|
||||||
|
|
||||||
|
//end of voice call alert
|
||||||
|
if (opts->call_alert == 1)
|
||||||
|
beeper (opts, state, slot, 40, 86, 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//similar to above, but constantly testing and checking the most recent event only
|
||||||
|
//this will hopefully be more useful when dealing with an ongoing event with
|
||||||
|
//features that update over time with embedded signalling, etc
|
||||||
|
void watchdog_event_current (dsd_opts * opts, dsd_state * state, uint8_t slot)
|
||||||
|
{
|
||||||
|
|
||||||
|
//create a pointer to the current slot event history
|
||||||
|
Event_History_I * event_struct = &state->event_history_s[slot];
|
||||||
|
|
||||||
|
//ncurses color pairs
|
||||||
|
uint8_t color_pair = 4; //default voice color (unknown gi)
|
||||||
|
if (state->gi[slot] == 1)
|
||||||
|
color_pair = 4; //default private voice color
|
||||||
|
else if (state->gi[slot] == 0)
|
||||||
|
color_pair = 4; //default group voice color
|
||||||
|
|
||||||
|
//TODO: Flesh out more later on.
|
||||||
|
uint32_t source_id = 0;
|
||||||
|
uint32_t target_id = 0;
|
||||||
|
char src_str[200]; memset (src_str, 0, sizeof(src_str));
|
||||||
|
sprintf (src_str, "%s", "BUMBLEBEETUNA");
|
||||||
|
char tgt_str[200]; memset (tgt_str, 0, sizeof(tgt_str));
|
||||||
|
sprintf (tgt_str, "%s", "BUMBLEBEETUNA");
|
||||||
|
|
||||||
|
//group import items
|
||||||
|
char t_name[200]; memset (t_name, 0, sizeof(t_name));
|
||||||
|
sprintf (t_name, "%s", "BUMBLEBEETUNA");
|
||||||
|
char s_name[200]; memset (s_name, 0, sizeof(s_name));
|
||||||
|
sprintf (s_name, "%s", "BUMBLEBEETUNA");
|
||||||
|
char t_mode[200]; memset (t_mode, 0, sizeof(t_mode));
|
||||||
|
sprintf (t_mode, "%s", "BUMBLEBEETUNA");
|
||||||
|
char s_mode[200]; memset (s_mode, 0, sizeof(s_mode));
|
||||||
|
sprintf (s_mode, "%s", "BUMBLEBEETUNA");
|
||||||
|
|
||||||
|
uint16_t svc_opts = 0;
|
||||||
|
uint8_t subtype = 0;
|
||||||
|
uint8_t mfid = 0;
|
||||||
|
uint32_t sys_id1 = 0;
|
||||||
|
uint32_t sys_id2 = 0;
|
||||||
|
uint32_t sys_id3 = 0;
|
||||||
|
uint32_t sys_id4 = 0;
|
||||||
|
uint32_t sys_id5 = 0;
|
||||||
|
|
||||||
|
uint32_t channel = 0;
|
||||||
|
|
||||||
|
uint8_t enc = 0;
|
||||||
|
uint8_t alg_id = 0;
|
||||||
|
uint16_t key_id = 0;
|
||||||
|
unsigned long long int mi;
|
||||||
|
|
||||||
|
char sysid_string[200]; memset(sysid_string, 0, sizeof(sysid_string));
|
||||||
|
sprintf (sysid_string, "%s", "");
|
||||||
|
|
||||||
|
if (slot == 0)
|
||||||
|
{
|
||||||
|
source_id = state->lastsrc;
|
||||||
|
target_id = state->lasttg;
|
||||||
|
|
||||||
|
subtype = state->dmrburstL;
|
||||||
|
mfid = state->dmr_fid;
|
||||||
|
|
||||||
|
svc_opts = state->dmr_so;
|
||||||
|
enc = (svc_opts >> 6) & 1;
|
||||||
|
alg_id = state->payload_algid;
|
||||||
|
key_id = (uint16_t)state->payload_keyid;
|
||||||
|
|
||||||
|
mi = state->payload_mi;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
source_id = state->lastsrcR;
|
||||||
|
target_id = state->lasttgR;
|
||||||
|
|
||||||
|
subtype = state->dmrburstR;
|
||||||
|
mfid = state->dmr_fidR;
|
||||||
|
|
||||||
|
svc_opts = state->dmr_soR;
|
||||||
|
enc = (svc_opts >> 6) & 1;
|
||||||
|
|
||||||
|
alg_id = state->payload_algidR;
|
||||||
|
key_id = (uint16_t)state->payload_keyidR;
|
||||||
|
mi = state->payload_miR;
|
||||||
|
}
|
||||||
|
|
||||||
|
//if P25 (if not P25, then these will all be zero anyways)
|
||||||
|
sys_id1 = state->p2_wacn;
|
||||||
|
sys_id2 = state->p2_sysid;
|
||||||
|
if (state->nac != 0)
|
||||||
|
sys_id3 = state->nac; //same as state->p2_cc, but zeroes out when no signal or error
|
||||||
|
else sys_id3 = state->p2_cc;
|
||||||
|
sys_id4 = state->p2_rfssid;
|
||||||
|
sys_id5 = state->p2_siteid;
|
||||||
|
|
||||||
|
if (sys_id1)
|
||||||
|
sprintf (sysid_string, "P25_%05X%03X%03X_%d_%d", sys_id1, sys_id2, sys_id3, sys_id4, sys_id5);
|
||||||
|
else sprintf (sysid_string, "P25_%03X", sys_id3);
|
||||||
|
|
||||||
|
if (state->lastsynctype == 10 || state->lastsynctype == 11 || state->lastsynctype == 12 || state->lastsynctype == 13 ||
|
||||||
|
state->lastsynctype == 32 || state->lastsynctype == 33 || state->lastsynctype == 34 )
|
||||||
|
{
|
||||||
|
sys_id1 = state->dmr_t3_syscode;
|
||||||
|
sys_id2 = state->dmr_color_code;
|
||||||
|
|
||||||
|
if (sys_id1)
|
||||||
|
sprintf (sysid_string, "DMR_%X_CC_%d", sys_id1, sys_id2);
|
||||||
|
else sprintf (sysid_string, "DMR_CC_%d", sys_id2);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (slot == 0) //BUGFIX: generic catch on FDMA systems so that we don't write duplicate data to slot 2 event history
|
||||||
|
{
|
||||||
|
//NXDN RID (TODO: Changeover to lastsrc and lasttg later on)
|
||||||
|
if (state->lastsynctype == 28 || state->lastsynctype == 29)
|
||||||
|
{
|
||||||
|
source_id = state->nxdn_last_rid;
|
||||||
|
target_id = state->nxdn_last_tg;
|
||||||
|
if (state->nxdn_cipher_type != 0)
|
||||||
|
enc = 1;
|
||||||
|
alg_id = state->nxdn_cipher_type;
|
||||||
|
key_id = state->nxdn_key;
|
||||||
|
|
||||||
|
sys_id1 = state->nxdn_location_site_code;
|
||||||
|
sys_id2 = state->nxdn_location_sys_code;
|
||||||
|
sys_id3 = state->nxdn_last_ran; //might be an issue on conventional systems that have a different RAN on the tx_rel or idle data bursts
|
||||||
|
|
||||||
|
if (sys_id1)
|
||||||
|
sprintf (sysid_string, "NXDN_%d_%d_RAN_%d", sys_id2, sys_id1, sys_id3);
|
||||||
|
else sprintf (sysid_string, "NXDN_RAN_%d", sys_id3);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state->lastsynctype == 30 || state->lastsynctype == 31) //YSF Fusion
|
||||||
|
{
|
||||||
|
source_id = 0;
|
||||||
|
if (strncmp(state->ysf_src, " ", 10) != 0) //if this field does not have ten spaces in it
|
||||||
|
{
|
||||||
|
for (uint8_t i = 0; i < 11; i++)
|
||||||
|
source_id += state->ysf_src[i]; //convert to sum value to make a distinct enough src value
|
||||||
|
}
|
||||||
|
|
||||||
|
//WIP: If Text, compile it here (still having issues with an empty txt string making a line break)
|
||||||
|
uint8_t k = 0; char ysf_emp[21][21]; memset(ysf_emp, 0, sizeof(ysf_emp));
|
||||||
|
if (memcmp(ysf_emp, state->ysf_txt, sizeof(state->ysf_txt)) != 0)
|
||||||
|
{
|
||||||
|
for (uint8_t i = 4; i < 8; i++)
|
||||||
|
{
|
||||||
|
for (uint8_t j = 0; j < 20; j++)
|
||||||
|
{
|
||||||
|
if (state->ysf_txt[i][j] != 0x2A)
|
||||||
|
event_struct->Event_History_Items[0].text_message[k++] = state->ysf_txt[i][j];
|
||||||
|
else event_struct->Event_History_Items[0].text_message[k++] = 0x20; //space
|
||||||
|
|
||||||
|
}
|
||||||
|
event_struct->Event_History_Items[0].text_message[k] = 0; //terminate
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else sprintf (event_struct->Event_History_Items[0].text_message, "%s", "BUMBLEBEETUNA");
|
||||||
|
|
||||||
|
sprintf (sysid_string, "%s", "YSF");
|
||||||
|
|
||||||
|
char temp_str[20];
|
||||||
|
memset(temp_str, 0, sizeof(temp_str));
|
||||||
|
|
||||||
|
//set src string as a non-spaced non-garbo char string
|
||||||
|
for (uint8_t i = 0; i < 10; i++)
|
||||||
|
{
|
||||||
|
if (state->ysf_src[i] == 0x20) //spaces to underscore
|
||||||
|
temp_str[i] = 0x5F;
|
||||||
|
else if (state->ysf_src[i] > 0x20 && state->ysf_src[i] < 0x7F) //copy normal ascii range characters
|
||||||
|
temp_str[i] = state->ysf_src[i];
|
||||||
|
else if (state->ysf_src[i] == 0) break; //hit the terminator, so stop
|
||||||
|
else temp_str[i] = 0x5F; //unknown to underscore
|
||||||
|
}
|
||||||
|
sprintf (src_str, "%s", temp_str);
|
||||||
|
|
||||||
|
//same for tgt str
|
||||||
|
memset(temp_str, 0, sizeof(temp_str));
|
||||||
|
for (uint8_t i = 0; i < 10; i++)
|
||||||
|
{
|
||||||
|
if (state->ysf_tgt[i] == 0x20) //spaces to underscore
|
||||||
|
temp_str[i] = 0x5F;
|
||||||
|
else if (state->ysf_tgt[i] > 0x20 && state->ysf_tgt[i] < 0x7F) //copy normal ascii range characters
|
||||||
|
temp_str[i] = state->ysf_tgt[i];
|
||||||
|
else if (state->ysf_tgt[i] == 0) break; //hit the terminator, so stop
|
||||||
|
else temp_str[i] = 0x5F; //unknown to underscore
|
||||||
|
}
|
||||||
|
sprintf (tgt_str, "%s", temp_str);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state->lastsynctype == 8 || state->lastsynctype == 9 || state->lastsynctype == 16 || state->lastsynctype == 17) //M17 STR
|
||||||
|
{
|
||||||
|
target_id = (uint32_t)state->m17_dst;
|
||||||
|
source_id = (uint32_t)state->m17_src;
|
||||||
|
sys_id1 = state->m17_can;
|
||||||
|
sprintf (sysid_string, "M17_CAN_%d", sys_id1);
|
||||||
|
sprintf (src_str, "%s", state->m17_src_csd);
|
||||||
|
sprintf (tgt_str, "%s", state->m17_dst_csd);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state->lastsynctype == 6 || state->lastsynctype == 7 || state->lastsynctype == 18 || state->lastsynctype == 19) //DSTAR
|
||||||
|
{
|
||||||
|
source_id = 0;
|
||||||
|
for (uint8_t i = 0; i < 12; i++)
|
||||||
|
source_id += state->dstar_src[i]; //convert to sum value to make a distinct enough src value
|
||||||
|
|
||||||
|
//need a strncmp here for 8 spaces in this field first so we don't blip a blank into the event history
|
||||||
|
if (strncmp(state->dstar_src, " ", 8) == 0)
|
||||||
|
source_id = 0;
|
||||||
|
|
||||||
|
sprintf (sysid_string, "%s", "DSTAR");
|
||||||
|
|
||||||
|
char temp_str[20];
|
||||||
|
memset(temp_str, 0, sizeof(temp_str));
|
||||||
|
|
||||||
|
//set src string as a non-spaced non-garbo char string
|
||||||
|
for (uint8_t i = 0; i < 12; i++)
|
||||||
|
{
|
||||||
|
if (state->dstar_src[i] == 0x20) //spaces to underscore
|
||||||
|
temp_str[i] = 0x5F;
|
||||||
|
else if (state->dstar_src[i] > 0x20 && state->dstar_src[i] < 0x7F) //copy normal ascii range characters
|
||||||
|
temp_str[i] = state->dstar_src[i];
|
||||||
|
else if (state->dstar_src[i] == 0) break; //hit the terminator, so stop
|
||||||
|
else temp_str[i] = 0x5F; //unknown to underscore
|
||||||
|
}
|
||||||
|
sprintf (src_str, "%s", temp_str);
|
||||||
|
|
||||||
|
//same for tgt str
|
||||||
|
memset(temp_str, 0, sizeof(temp_str));
|
||||||
|
for (uint8_t i = 0; i < 8; i++)
|
||||||
|
{
|
||||||
|
if (state->dstar_dst[i] == 0x20) //spaces to underscore
|
||||||
|
temp_str[i] = 0x5F;
|
||||||
|
else if (state->dstar_dst[i] > 0x20 && state->dstar_dst[i] < 0x7F) //copy normal ascii range characters
|
||||||
|
temp_str[i] = state->dstar_dst[i];
|
||||||
|
else if (state->dstar_dst[i] == 0) break; //hit the terminator, so stop
|
||||||
|
else temp_str[i] = 0x5F; //unknown to underscore
|
||||||
|
}
|
||||||
|
sprintf (tgt_str, "%s", temp_str);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state->lastsynctype == 20 || state->lastsynctype == 24 || state->lastsynctype == 21 || state->lastsynctype == 25 || state->lastsynctype == 22 || state->lastsynctype == 26 || state->lastsynctype == 23 || state->lastsynctype == 27) //dPMR
|
||||||
|
{
|
||||||
|
source_id = 0;
|
||||||
|
for (uint8_t i = 0; i < 20; i++)
|
||||||
|
source_id += state->dpmr_caller_id[i]; //convert to sum value to make a distinct enough src value
|
||||||
|
|
||||||
|
//need a strncmp here for 8 spaces in this field first so we don't blip a blank into the event history
|
||||||
|
if (strncmp(state->dpmr_caller_id, " ", 6) == 0)
|
||||||
|
source_id = 0;
|
||||||
|
|
||||||
|
sprintf (sysid_string, "DPMR_CC_%d", state->dpmr_color_code);
|
||||||
|
|
||||||
|
sprintf (src_str, "%s", state->dpmr_caller_id);
|
||||||
|
sprintf (tgt_str, "%s", state->dpmr_target_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state->lastsynctype == 14 || state->lastsynctype == 15 || state->lastsynctype == 37 || state->lastsynctype == 38) //EDACS Calls
|
||||||
|
{
|
||||||
|
source_id = 0;
|
||||||
|
if (opts->p25_is_tuned == 1)
|
||||||
|
{
|
||||||
|
source_id = state->lastsrc;
|
||||||
|
channel = state->edacs_tuned_lcn;
|
||||||
|
}
|
||||||
|
|
||||||
|
sys_id1 = state->edacs_site_id;
|
||||||
|
sys_id2 = state->edacs_area_code;
|
||||||
|
sys_id3 = state->edacs_sys_id;
|
||||||
|
svc_opts = state->edacs_vc_call_type;
|
||||||
|
char sup_str[200]; memset (sup_str, 0, sizeof(sup_str));
|
||||||
|
sprintf (sup_str, "%s", "_");
|
||||||
|
if (svc_opts & 0x02)
|
||||||
|
strcat (sup_str, "Digital_");
|
||||||
|
else strcat (sup_str, "Analog_");
|
||||||
|
if (svc_opts & 0x04)
|
||||||
|
strcat (sup_str, "Emergency_");
|
||||||
|
if (svc_opts & 0x08)
|
||||||
|
strcat (sup_str, "Group_");
|
||||||
|
if (svc_opts & 0x10)
|
||||||
|
strcat (sup_str, "I_");
|
||||||
|
if (svc_opts & 0x20)
|
||||||
|
strcat (sup_str, "ALL_");
|
||||||
|
if (svc_opts & 0x40)
|
||||||
|
strcat (sup_str, "INTER_");
|
||||||
|
if (svc_opts & 0x80)
|
||||||
|
strcat (sup_str, "TEST_");
|
||||||
|
if (svc_opts & 0x100)
|
||||||
|
strcat (sup_str, "AGENCY_");
|
||||||
|
if (svc_opts & 0x200)
|
||||||
|
strcat (sup_str, "FLEET_");
|
||||||
|
if (svc_opts & 0x01)
|
||||||
|
strcat (sup_str, "Voice_");
|
||||||
|
strcat (sup_str, "Call");
|
||||||
|
|
||||||
|
sprintf (sysid_string, "EDACS_SITE_%03d", sys_id1);
|
||||||
|
strcat (sysid_string, sup_str);
|
||||||
|
|
||||||
|
if (state->ea_mode == 0)
|
||||||
|
{
|
||||||
|
int afs = state->lasttg;
|
||||||
|
sprintf(src_str, "%s", ""); sprintf(tgt_str, "%s", "");
|
||||||
|
int a = (afs >> state->edacs_a_shift) & state->edacs_a_mask;
|
||||||
|
int f = (afs >> state->edacs_f_shift) & state->edacs_f_mask;
|
||||||
|
int s = afs & state->edacs_s_mask;
|
||||||
|
sprintf (tgt_str, "%03d_AFS_%02d_%02d%01d", afs, a, f, s);
|
||||||
|
if (state->lastsrc != 0x800 && state->lastsrc != 0)
|
||||||
|
sprintf (src_str, "LID_%d", state->lastsrc);
|
||||||
|
else sprintf (src_str, "LID_UNK");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//if we have a group_array import, search and load it here
|
||||||
|
//will search and load both target values, and src values if available
|
||||||
|
uint8_t t_name_loaded = 0;
|
||||||
|
uint8_t s_name_loaded = 0;
|
||||||
|
if (target_id != 0)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < state->group_tally; i++)
|
||||||
|
{
|
||||||
|
if (state->group_array[i].groupNumber == target_id)
|
||||||
|
{
|
||||||
|
sprintf (t_name, "%s", state->group_array[i].groupName);
|
||||||
|
sprintf (t_mode, "%s", state->group_array[i].groupMode);
|
||||||
|
t_name_loaded = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (source_id != 0) //&& state->gi[slot] == 1
|
||||||
|
{
|
||||||
|
for (int i = 0; i < state->group_tally; i++)
|
||||||
|
{
|
||||||
|
if (state->group_array[i].groupNumber == source_id)
|
||||||
|
{
|
||||||
|
sprintf (s_name, "%s", state->group_array[i].groupName);
|
||||||
|
sprintf (s_mode, "%s", state->group_array[i].groupMode);
|
||||||
|
s_name_loaded = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//system type string (P25, DMR, etc)
|
||||||
|
const char * sys_string = "Digital";
|
||||||
|
if (state->lastsynctype != -1)
|
||||||
|
sys_string = SyncTypes[state->lastsynctype];
|
||||||
|
|
||||||
|
//date and time strings
|
||||||
|
char * timestr = getTimeN(time(NULL));
|
||||||
|
char * datestr = getDateN(time(NULL));
|
||||||
|
|
||||||
|
if (source_id != 0)
|
||||||
|
{
|
||||||
|
event_struct->Event_History_Items[0].write = 0;
|
||||||
|
state->event_history_s[slot].Event_History_Items[0].color_pair = color_pair;
|
||||||
|
if (state->lastsynctype != -1)
|
||||||
|
event_struct->Event_History_Items[0].systype = state->lastsynctype;
|
||||||
|
else event_struct->Event_History_Items[0].systype = 39; //generic digital call
|
||||||
|
event_struct->Event_History_Items[0].subtype = subtype; //voice
|
||||||
|
event_struct->Event_History_Items[0].gi = state->gi[slot]; //need this add this to link control messages
|
||||||
|
event_struct->Event_History_Items[0].sys_id1 = sys_id1;
|
||||||
|
event_struct->Event_History_Items[0].sys_id2 = sys_id2;
|
||||||
|
event_struct->Event_History_Items[0].sys_id3 = sys_id3;
|
||||||
|
event_struct->Event_History_Items[0].sys_id4 = sys_id4;
|
||||||
|
event_struct->Event_History_Items[0].sys_id5 = sys_id5;
|
||||||
|
event_struct->Event_History_Items[0].enc = enc;
|
||||||
|
event_struct->Event_History_Items[0].enc_alg = alg_id;
|
||||||
|
event_struct->Event_History_Items[0].enc_key = key_id;
|
||||||
|
event_struct->Event_History_Items[0].mi = mi;
|
||||||
|
event_struct->Event_History_Items[0].svc = svc_opts;
|
||||||
|
event_struct->Event_History_Items[0].source_id = source_id;
|
||||||
|
event_struct->Event_History_Items[0].target_id = target_id;
|
||||||
|
event_struct->Event_History_Items[0].channel = channel; //need to add this to trunking messages, if tuned from call grant
|
||||||
|
if (opts->playfiles == 0) //if playing back .mbe files with a time in it, don't set this
|
||||||
|
event_struct->Event_History_Items[0].event_time = time(NULL);
|
||||||
|
sprintf (event_struct->Event_History_Items[0].sysid_string, "%s", sysid_string);
|
||||||
|
sprintf (event_struct->Event_History_Items[0].src_str, "%s", src_str);
|
||||||
|
sprintf (event_struct->Event_History_Items[0].tgt_str, "%s", tgt_str);
|
||||||
|
|
||||||
|
sprintf (event_struct->Event_History_Items[0].t_name, "%s", t_name);
|
||||||
|
sprintf (event_struct->Event_History_Items[0].s_name, "%s", s_name);
|
||||||
|
sprintf (event_struct->Event_History_Items[0].t_mode, "%s", t_mode);
|
||||||
|
sprintf (event_struct->Event_History_Items[0].s_mode, "%s", s_mode);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//Craft an event string for ncurses event history, and a more complex string for logging
|
||||||
|
char event_string[2000]; memset(event_string, 0, sizeof(event_string));
|
||||||
|
|
||||||
|
//WIP: Seperate Voice Call Event Strings when SRC/TGT values are numerical,
|
||||||
|
//and a seperate one for when they are string values (M17, YSF, DSTAR, and dPMR, or use special formatting)
|
||||||
|
if (state->lastsynctype == 30 || state->lastsynctype == 31) //YSF Fusion //TODO: Data calls dumping a lot of events as VOICE
|
||||||
|
{
|
||||||
|
//TODO: See if we can add some decoded data as well in the future to an event string
|
||||||
|
sprintf (event_string, "%s %s %s TGT: %s SRC: %s ", datestr, timestr, sys_string, state->ysf_tgt, state->ysf_src);
|
||||||
|
}
|
||||||
|
else if (state->lastsynctype == 16 || state->lastsynctype == 17) //M17
|
||||||
|
{
|
||||||
|
//TODO: See if we can add some decoded data as well in the future to an event string
|
||||||
|
if (state->m17_dst == 0xFFFFFFFFFFFF)
|
||||||
|
sprintf (event_string, "%s %s %s TGT: %s SRC: %s CAN: %02d;", datestr, timestr, sys_string, "BROADCAST", state->m17_src_str, state->m17_can);
|
||||||
|
else
|
||||||
|
sprintf (event_string, "%s %s %s TGT: %s SRC: %s CAN: %02d;", datestr, timestr, sys_string, state->m17_dst_str, state->m17_src_str, state->m17_can);
|
||||||
|
}
|
||||||
|
else if (state->lastsynctype == 6 || state->lastsynctype == 7 || state->lastsynctype == 18 || state->lastsynctype == 19) //DSTAR
|
||||||
|
{
|
||||||
|
//TODO: See if we can add some decoded data as well in the future to an event string
|
||||||
|
sprintf (event_string, "%s %s %s TGT: %s SRC: %s ", datestr, timestr, sys_string, state->dstar_dst, state->dstar_src);
|
||||||
|
}
|
||||||
|
else if (state->lastsynctype == 20 || state->lastsynctype == 24 || state->lastsynctype == 21 || state->lastsynctype == 25 || state->lastsynctype == 22 || state->lastsynctype == 26 || state->lastsynctype == 23 || state->lastsynctype == 27) //dPMR
|
||||||
|
{
|
||||||
|
//TODO: See if we can add some decoded data as well in the future to an event string
|
||||||
|
sprintf (event_string, "%s %s %s CC: %02d; TGT: %s; SRC: %s; ", datestr, timestr, sys_string, state->dpmr_color_code, state->dpmr_target_id, state->dpmr_caller_id);
|
||||||
|
if (state->dPMRVoiceFS2Frame.Version[0] == 3)
|
||||||
|
strcat (event_string, "Scrambler Enc; ");
|
||||||
|
}
|
||||||
|
else if (state->lastsynctype == 14 || state->lastsynctype == 15 || state->lastsynctype == 37 || state->lastsynctype == 38) //EDACS Calls
|
||||||
|
{
|
||||||
|
svc_opts = state->edacs_vc_call_type;
|
||||||
|
char sup_str[200]; memset (sup_str, 0, sizeof(sup_str));
|
||||||
|
sprintf (sup_str, "%s", "");
|
||||||
|
if (svc_opts & 0x02)
|
||||||
|
strcat (sup_str, "Digital ");
|
||||||
|
else strcat (sup_str, "Analog ");
|
||||||
|
if (svc_opts & 0x04)
|
||||||
|
strcat (sup_str, "Emergency ");
|
||||||
|
if (svc_opts & 0x08)
|
||||||
|
strcat (sup_str, "Group ");
|
||||||
|
if (svc_opts & 0x10)
|
||||||
|
strcat (sup_str, "I ");
|
||||||
|
if (svc_opts & 0x20)
|
||||||
|
strcat (sup_str, "ALL ");
|
||||||
|
if (svc_opts & 0x40)
|
||||||
|
strcat (sup_str, "INTER ");
|
||||||
|
if (svc_opts & 0x80)
|
||||||
|
strcat (sup_str, "TEST ");
|
||||||
|
if (svc_opts & 0x100)
|
||||||
|
strcat (sup_str, "AGENCY ");
|
||||||
|
if (svc_opts & 0x200)
|
||||||
|
strcat (sup_str, "FLEET ");
|
||||||
|
if (svc_opts & 0x01)
|
||||||
|
strcat (sup_str, "Voice ");
|
||||||
|
strcat (sup_str, "Call");
|
||||||
|
|
||||||
|
if (state->ea_mode == 1)
|
||||||
|
{
|
||||||
|
sprintf (event_string, "%s %s %s TGT: %07d; SRC: %07d; LCN: %02d; SITE: %d:%d.%04X; %s; ", datestr, timestr, sys_string, target_id, source_id, channel, sys_id1, sys_id2, sys_id3, sup_str);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int afs = state->lasttg;
|
||||||
|
int a = (afs >> state->edacs_a_shift) & state->edacs_a_mask;
|
||||||
|
int f = (afs >> state->edacs_f_shift) & state->edacs_f_mask;
|
||||||
|
int s = afs & state->edacs_s_mask;
|
||||||
|
char afs_str[8];
|
||||||
|
getAfsString(state, afs_str, a, f, s);
|
||||||
|
char lid_str[20]; memset(lid_str, 0, sizeof(lid_str));
|
||||||
|
sprintf(lid_str, "%s", "");
|
||||||
|
if (state->lastsrc != 0 && state->lastsrc != 0x800)
|
||||||
|
sprintf (lid_str, "LID: %05d;", state->lastsrc);
|
||||||
|
else sprintf (lid_str, "LID: __UNK;");
|
||||||
|
|
||||||
|
sprintf (event_string, "%s %s %s AFS: %s (%04d); %s LCN: %02d; Site: %d; %s; ", datestr, timestr, sys_string, afs_str, afs, lid_str, channel, sys_id1, sup_str);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (state->lastsynctype == 10 || state->lastsynctype == 11 || state->lastsynctype == 12 || state->lastsynctype == 13 ||
|
||||||
|
state->lastsynctype == 32 || state->lastsynctype == 33 || state->lastsynctype == 34 ) //DMR
|
||||||
|
{
|
||||||
|
if (sys_id1)
|
||||||
|
sprintf (event_string, "%s %s %s TGT: %08d; SRC: %08d; CC: %02d; SYS: %X; ", datestr, timestr, sys_string, target_id, source_id, sys_id2, sys_id1);
|
||||||
|
else
|
||||||
|
sprintf (event_string, "%s %s %s TGT: %08d; SRC: %08d; CC: %02d; ", datestr, timestr, sys_string, target_id, source_id, sys_id2);
|
||||||
|
if (enc)
|
||||||
|
strcat(event_string, "ENC; ");
|
||||||
|
if (alg_id != 0)
|
||||||
|
{
|
||||||
|
char ess_str[30];
|
||||||
|
sprintf (ess_str, "ALG: %02X; KID: %02X; ", alg_id, key_id);
|
||||||
|
strcat(event_string, ess_str);
|
||||||
|
}
|
||||||
|
|
||||||
|
//monitor for misc link control that may set a SO without having SO inside of it,
|
||||||
|
//those could cause misc issues here, will need to observe and make adjustments
|
||||||
|
if (svc_opts & 0x80)
|
||||||
|
strcat (event_string, "Emergency; ");
|
||||||
|
|
||||||
|
if (svc_opts & 0x08)
|
||||||
|
strcat (event_string, "Broadcast; ");
|
||||||
|
|
||||||
|
if (svc_opts & 0x04)
|
||||||
|
strcat (event_string, "OVCM; ");
|
||||||
|
|
||||||
|
if (state->gi[slot] == 0)
|
||||||
|
strcat (event_string, "Group; ");
|
||||||
|
else if (state->gi[slot] == 1)
|
||||||
|
strcat (event_string, "Private; ");
|
||||||
|
|
||||||
|
if (mfid == 0x10)
|
||||||
|
{
|
||||||
|
if (svc_opts & 0x20)
|
||||||
|
strcat (event_string, "TXI; ");
|
||||||
|
else if (svc_opts & 0x10)
|
||||||
|
strcat (event_string, "TXI; "); //this is the svc opt bit that tells you when the next VC6 will be pre-empted, but not helpful here
|
||||||
|
|
||||||
|
if (svc_opts & 0x03)
|
||||||
|
strcat (event_string, "PRIORITY; "); //need to break this apart into each one, but need to double check the decoded value is accurate
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else if (state->lastsynctype == 0 || state->lastsynctype == 1 || state->lastsynctype == 35 || state->lastsynctype == 36)
|
||||||
|
{
|
||||||
|
if (sys_id1)
|
||||||
|
sprintf (event_string, "%s %s %s TGT: %08d; SRC: %08d; NAC: %03X; NET_STS: %05X:%03X:%d.%d; ", datestr, timestr, sys_string, target_id, source_id, sys_id3, sys_id1, sys_id2, sys_id4, sys_id5);
|
||||||
|
else
|
||||||
|
sprintf (event_string, "%s %s %s TGT: %08d; SRC: %08d; NAC: %03X; ", datestr, timestr, sys_string, target_id, source_id, sys_id3);
|
||||||
|
if (alg_id != 0 && alg_id != 0x80)
|
||||||
|
{
|
||||||
|
char ess_str[30];
|
||||||
|
sprintf (ess_str, "ENC; ALG: %02X; KID: %04X; ", alg_id, key_id);
|
||||||
|
strcat(event_string, ess_str);
|
||||||
|
}
|
||||||
|
if (svc_opts & 0x80)
|
||||||
|
strcat (event_string, "Emergency; ");
|
||||||
|
if (state->gi[slot] == 0)
|
||||||
|
strcat (event_string, "Group; ");
|
||||||
|
else if (state->gi[slot] == 1)
|
||||||
|
strcat (event_string, "Private; ");
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (state->lastsynctype == 28 || state->lastsynctype == 29)
|
||||||
|
{
|
||||||
|
if (sys_id1)
|
||||||
|
sprintf (event_string, "%s %s %s TGT: %08d; SRC: %08d; RAN: %02d; SYS: %d.%d; ", datestr, timestr, sys_string, target_id, source_id, sys_id3, sys_id2, sys_id1);
|
||||||
|
else
|
||||||
|
sprintf (event_string, "%s %s %s TGT: %08d; SRC: %08d; RAN: %02d; ", datestr, timestr, sys_string, target_id, source_id, sys_id3);
|
||||||
|
if (enc)
|
||||||
|
strcat(event_string, "ENC; ");
|
||||||
|
if (alg_id != 0)
|
||||||
|
{
|
||||||
|
char ess_str[30];
|
||||||
|
sprintf (ess_str, "ALG: %d; KID: %02X; ", alg_id, key_id);
|
||||||
|
strcat(event_string, ess_str);
|
||||||
|
}
|
||||||
|
if (state->gi[slot] == 0)
|
||||||
|
strcat (event_string, "Group; ");
|
||||||
|
else if (state->gi[slot] == 1)
|
||||||
|
strcat (event_string, "Private; ");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (t_name_loaded)
|
||||||
|
{
|
||||||
|
char group[420];
|
||||||
|
sprintf (group, "TName: %s; Mode: %s; ", t_name, t_mode);
|
||||||
|
strcat (event_string, group);
|
||||||
|
}
|
||||||
|
if (s_name_loaded)
|
||||||
|
{
|
||||||
|
char private[420];
|
||||||
|
sprintf (private, "SName: %s; Mode: %s; ", s_name, s_mode);
|
||||||
|
strcat (event_string, private);
|
||||||
|
}
|
||||||
|
|
||||||
|
sprintf (event_struct->Event_History_Items[0].event_string, "%s", event_string);
|
||||||
|
|
||||||
|
if (timestr != NULL)
|
||||||
|
{
|
||||||
|
free (timestr);
|
||||||
|
timestr = NULL;
|
||||||
|
}
|
||||||
|
if (datestr != NULL)
|
||||||
|
{
|
||||||
|
free (datestr);
|
||||||
|
datestr = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void watchdog_event_datacall (dsd_opts * opts, dsd_state * state, uint32_t src, uint32_t dst, char * data_string, uint8_t slot)
|
||||||
|
{
|
||||||
|
UNUSED(opts);
|
||||||
|
state->event_history_s[slot].Event_History_Items[0].write = 0;
|
||||||
|
if (state->event_history_s[slot].Event_History_Items[0].color_pair == 4) //if not set previously by specific decoder //don't touch this one
|
||||||
|
state->event_history_s[slot].Event_History_Items[0].color_pair = 4; //default data color //you can change this one
|
||||||
|
state->event_history_s[slot].Event_History_Items[0].systype = state->lastsynctype;
|
||||||
|
state->event_history_s[slot].Event_History_Items[0].subtype = 6; //data
|
||||||
|
state->event_history_s[slot].Event_History_Items[0].gi = state->gi[slot];
|
||||||
|
state->event_history_s[slot].Event_History_Items[0].enc = 0;
|
||||||
|
state->event_history_s[slot].Event_History_Items[0].enc_alg = 0;
|
||||||
|
state->event_history_s[slot].Event_History_Items[0].enc_key = 0;
|
||||||
|
state->event_history_s[slot].Event_History_Items[0].mi = 0;
|
||||||
|
state->event_history_s[slot].Event_History_Items[0].svc = 0;
|
||||||
|
state->event_history_s[slot].Event_History_Items[0].source_id = src;
|
||||||
|
state->event_history_s[slot].Event_History_Items[0].target_id = dst;
|
||||||
|
state->event_history_s[slot].Event_History_Items[0].channel = 0;
|
||||||
|
state->event_history_s[slot].Event_History_Items[0].event_time = time(NULL);
|
||||||
|
|
||||||
|
//date and time strings //getTimeN(time(NULL)); //getDateN(time(NULL));
|
||||||
|
char * timestr = getTimeN(time(NULL));
|
||||||
|
char * datestr = getDateN(time(NULL));
|
||||||
|
|
||||||
|
char event_string[2000]; memset (event_string, 0, sizeof(event_string));
|
||||||
|
sprintf (event_string, "%s %s ", datestr, timestr);
|
||||||
|
strcat (event_string, data_string); //may need to check for potential overflow of this
|
||||||
|
sprintf (state->event_history_s[slot].Event_History_Items[0].event_string, "%s", event_string); //could change this to a strncpy to prevent potential overflow
|
||||||
|
|
||||||
|
if (timestr != NULL)
|
||||||
|
{
|
||||||
|
free (timestr);
|
||||||
|
timestr = NULL;
|
||||||
|
}
|
||||||
|
if (datestr != NULL)
|
||||||
|
{
|
||||||
|
free (datestr);
|
||||||
|
datestr = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
//call alert on data calls
|
||||||
|
if (opts->call_alert)
|
||||||
|
beeper (opts, state, slot, 80, 20, 3);
|
||||||
|
}
|
||||||
1901
src/dsd_file.c
1901
src/dsd_file.c
File diff suppressed because it is too large
Load Diff
@@ -1,8 +1,48 @@
|
|||||||
|
#include "dsd.h"
|
||||||
|
|
||||||
|
//M17 Filter -- RRC Alpha = 0.5 S/s 48000 with 81 taps
|
||||||
|
#define M17ZEROS 80
|
||||||
|
float m17gain = 3.16227766f; //sqrt of 10.0f
|
||||||
|
static float m17xv[81];
|
||||||
|
|
||||||
|
//sample RRC filter for 48kHz sample rate
|
||||||
|
//alpha=0.5, span=8, sps=10, gain=sqrt(sps)
|
||||||
|
float m17coeffs[81] = //replaced old ones with ones from libm17
|
||||||
|
{
|
||||||
|
-0.003195702904062073f, -0.002930279157647190f, -0.001940667871554463f,
|
||||||
|
-0.000356087678023658f, 0.001547011339077758f, 0.003389554791179751f,
|
||||||
|
0.004761898604225673f, 0.005310860846138910f, 0.004824746306020221f,
|
||||||
|
0.003297923526848786f, 0.000958710871218619f, -0.001749908029791816f,
|
||||||
|
-0.004238694106631223f, -0.005881783042101693f, -0.006150256456781309f,
|
||||||
|
-0.004745376707651645f, -0.001704189656473565f, 0.002547854551539951f,
|
||||||
|
0.007215575568844704f, 0.011231038205363532f, 0.013421952197060707f,
|
||||||
|
0.012730475385624438f, 0.008449554307303753f, 0.000436744366018287f,
|
||||||
|
-0.010735380379191660f, -0.023726883538258272f, -0.036498030780605324f,
|
||||||
|
-0.046500883189991064f, -0.050979050575999614f, -0.047340680079891187f,
|
||||||
|
-0.033554880492651755f, -0.008513823955725943f, 0.027696543159614194f,
|
||||||
|
0.073664520037517042f, 0.126689053778116234f, 0.182990955139333916f,
|
||||||
|
0.238080025892859704f, 0.287235637987091563f, 0.326040247765297220f,
|
||||||
|
0.350895727088112619f, 0.359452932027607974f, 0.350895727088112619f,
|
||||||
|
0.326040247765297220f, 0.287235637987091563f, 0.238080025892859704f,
|
||||||
|
0.182990955139333916f, 0.126689053778116234f, 0.073664520037517042f,
|
||||||
|
0.027696543159614194f, -0.008513823955725943f, -0.033554880492651755f,
|
||||||
|
-0.047340680079891187f, -0.050979050575999614f, -0.046500883189991064f,
|
||||||
|
-0.036498030780605324f, -0.023726883538258272f, -0.010735380379191660f,
|
||||||
|
0.000436744366018287f, 0.008449554307303753f, 0.012730475385624438f,
|
||||||
|
0.013421952197060707f, 0.011231038205363532f, 0.007215575568844704f,
|
||||||
|
0.002547854551539951f, -0.001704189656473565f, -0.004745376707651645f,
|
||||||
|
-0.006150256456781309f, -0.005881783042101693f, -0.004238694106631223f,
|
||||||
|
-0.001749908029791816f, 0.000958710871218619f, 0.003297923526848786f,
|
||||||
|
0.004824746306020221f, 0.005310860846138910f, 0.004761898604225673f,
|
||||||
|
0.003389554791179751f, 0.001547011339077758f, -0.000356087678023658f,
|
||||||
|
-0.001940667871554463f, -0.002930279157647190f, -0.003195702904062073f
|
||||||
|
};
|
||||||
|
|
||||||
// Original DMR filter
|
// Original DMR filter
|
||||||
#define NZEROS 60
|
#define NZEROS 60
|
||||||
float ngain = 7.423339364f;
|
float ngain = 7.423339364f;
|
||||||
static float xv[NZEROS+1];
|
static float xv[NZEROS+1];
|
||||||
float xcoeffs[] =
|
float xcoeffs[61] =
|
||||||
{ -0.0083649323f, -0.0265444850f, -0.0428141462f, -0.0537571943f,
|
{ -0.0083649323f, -0.0265444850f, -0.0428141462f, -0.0537571943f,
|
||||||
-0.0564141052f, -0.0489161045f, -0.0310068662f, -0.0043393881f,
|
-0.0564141052f, -0.0489161045f, -0.0310068662f, -0.0043393881f,
|
||||||
+0.0275375106f, +0.0595423283f, +0.0857543325f, +0.1003565948f,
|
+0.0275375106f, +0.0595423283f, +0.0857543325f, +0.1003565948f,
|
||||||
@@ -27,7 +67,7 @@ float xcoeffs[] =
|
|||||||
float nxgain = 15.95930463f;
|
float nxgain = 15.95930463f;
|
||||||
static float nxv[NXZEROS+1];
|
static float nxv[NXZEROS+1];
|
||||||
|
|
||||||
float nxcoeffs[] =
|
float nxcoeffs[135] =
|
||||||
{ +0.031462429f, +0.031747267f, +0.030401148f, +0.027362877f,
|
{ +0.031462429f, +0.031747267f, +0.030401148f, +0.027362877f,
|
||||||
+0.022653298f, +0.016379869f, +0.008737200f, +0.000003302f,
|
+0.022653298f, +0.016379869f, +0.008737200f, +0.000003302f,
|
||||||
-0.009468531f, -0.019262057f, -0.028914291f, -0.037935027f,
|
-0.009468531f, -0.019262057f, -0.028914291f, -0.037935027f,
|
||||||
@@ -74,7 +114,7 @@ const float dmrgain = 6.82973073748f;
|
|||||||
static float dxv[DMRNZEROS+1];
|
static float dxv[DMRNZEROS+1];
|
||||||
|
|
||||||
// DMR filter F4EXB - root raised cosine alpha=0.7 Ts = 6650 S/s Fc = 48kHz
|
// DMR filter F4EXB - root raised cosine alpha=0.7 Ts = 6650 S/s Fc = 48kHz
|
||||||
const float dmrcoeffs[] =
|
const float dmrcoeffs[61] =
|
||||||
{0.0301506278, 0.0269200615, 0.0159662432, -0.0013114705, -0.0216605133,
|
{0.0301506278, 0.0269200615, 0.0159662432, -0.0013114705, -0.0216605133,
|
||||||
-0.0404938748, -0.0528141756, -0.0543747957, -0.0428325003, -0.0186176083,
|
-0.0404938748, -0.0528141756, -0.0543747957, -0.0428325003, -0.0186176083,
|
||||||
0.0147202645, 0.0508418571, 0.0816392577, 0.0988113688, 0.0957187780,
|
0.0147202645, 0.0508418571, 0.0816392577, 0.0988113688, 0.0957187780,
|
||||||
@@ -98,7 +138,7 @@ static float dpmrxv[NXZEROS+1];
|
|||||||
const float dpmrgain = 14.6083498224f;
|
const float dpmrgain = 14.6083498224f;
|
||||||
|
|
||||||
// dPMR filter - root raised cosine alpha=0.2 Ts = 3325 S/s Fc = 48 kHz - zero at boundaries appears to be slightly better
|
// dPMR filter - root raised cosine alpha=0.2 Ts = 3325 S/s Fc = 48 kHz - zero at boundaries appears to be slightly better
|
||||||
const float dpmrcoeffs[] =
|
const float dpmrcoeffs[135] =
|
||||||
{-0.0000983004, 0.0058388841, 0.0119748846, 0.0179185547, 0.0232592816,
|
{-0.0000983004, 0.0058388841, 0.0119748846, 0.0179185547, 0.0232592816,
|
||||||
0.0275919612, 0.0305433586, 0.0317982965, 0.0311240307,
|
0.0275919612, 0.0305433586, 0.0317982965, 0.0311240307,
|
||||||
0.0283911865, 0.0235897433, 0.0168387650, 0.0083888763,
|
0.0283911865, 0.0235897433, 0.0168387650, 0.0083888763,
|
||||||
@@ -156,6 +196,11 @@ dpmr_filter(short sample)
|
|||||||
return dsd_input_filter(sample, 4);
|
return dsd_input_filter(sample, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
short m17_filter (short sample)
|
||||||
|
{
|
||||||
|
return dsd_input_filter(sample, 5);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
short
|
short
|
||||||
dsd_input_filter(short sample, int mode)
|
dsd_input_filter(short sample, int mode)
|
||||||
@@ -189,6 +234,14 @@ dsd_input_filter(short sample, int mode)
|
|||||||
coeffs = (float *)dpmrcoeffs;
|
coeffs = (float *)dpmrcoeffs;
|
||||||
zeros = DPMRNZEROS;
|
zeros = DPMRNZEROS;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 5:
|
||||||
|
gain = m17gain;
|
||||||
|
v = m17xv;
|
||||||
|
coeffs = (float *)m17coeffs;
|
||||||
|
zeros = M17ZEROS;
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return sample;
|
return sample;
|
||||||
}
|
}
|
||||||
@@ -204,3 +257,12 @@ dsd_input_filter(short sample, int mode)
|
|||||||
|
|
||||||
return (short)(sum / gain); // filtered sample out
|
return (short)(sum / gain); // filtered sample out
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void init_rrc_filter_memory()
|
||||||
|
{
|
||||||
|
memset (m17xv, 0, 81*sizeof(float));
|
||||||
|
memset (xv, 0, 61*sizeof(float));
|
||||||
|
memset (dxv, 0, 61*sizeof(float));
|
||||||
|
memset (nxv, 0, 135*sizeof(float));
|
||||||
|
memset (dpmrxv, 0, 135*sizeof(float));
|
||||||
|
}
|
||||||
131
src/dsd_frame.c
131
src/dsd_frame.c
@@ -20,35 +20,27 @@
|
|||||||
#define NULL 0
|
#define NULL 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "p25p1_check_nid.h"
|
|
||||||
|
|
||||||
void
|
void
|
||||||
printFrameInfo (dsd_opts * opts, dsd_state * state)
|
printFrameInfo (dsd_opts * opts, dsd_state * state)
|
||||||
{
|
{
|
||||||
|
|
||||||
int level;
|
UNUSED(opts);
|
||||||
|
|
||||||
level = (int) state->max / 164;
|
fprintf (stderr, "%s", KCYN);
|
||||||
if (opts->verbose > 0)
|
if (state->p2_wacn != 0)
|
||||||
{
|
fprintf (stderr, "WACN: %05llX; ", state->p2_wacn);
|
||||||
//fprintf (stderr,"inlvl: %2i%% ", level);
|
if (state->p2_sysid != 0)
|
||||||
}
|
fprintf (stderr, "SYS: %03llX; ", state->p2_sysid);
|
||||||
if (state->nac != 0)
|
if (state->p2_cc != 0)
|
||||||
{
|
fprintf (stderr, "NAC/CC: %03llX; ", state->p2_cc);
|
||||||
fprintf (stderr, "%s", KCYN);
|
else fprintf (stderr, "NAC: %03X; ", state->nac);
|
||||||
fprintf (stderr,"nac: [%4X] ", state->nac);
|
|
||||||
fprintf (stderr, "%s", KNRM);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (opts->verbose > 1)
|
if (state->p2_rfssid != 0)
|
||||||
{
|
fprintf (stderr, "RFSS: %03lld; ", state->p2_rfssid);
|
||||||
fprintf (stderr, "%s", KGRN);
|
if (state->p2_siteid != 0)
|
||||||
fprintf (stderr,"src: [%8i] ", state->lastsrc);
|
fprintf (stderr, "Site: %03lld; ", state->p2_siteid);
|
||||||
fprintf (stderr, "%s", KNRM);
|
|
||||||
}
|
|
||||||
fprintf (stderr, "%s", KGRN);
|
|
||||||
fprintf (stderr,"tg: [%5i] ", state->lasttg);
|
|
||||||
fprintf (stderr, "%s", KNRM);
|
fprintf (stderr, "%s", KNRM);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -59,8 +51,10 @@ processFrame (dsd_opts * opts, dsd_state * state)
|
|||||||
char duid[3];
|
char duid[3];
|
||||||
char nac[13];
|
char nac[13];
|
||||||
int level;
|
int level;
|
||||||
|
UNUSED2(nac, level);
|
||||||
|
|
||||||
char status_0;
|
char status_0;
|
||||||
|
UNUSED(status_0);
|
||||||
char bch_code[63];
|
char bch_code[63];
|
||||||
int index_bch_code;
|
int index_bch_code;
|
||||||
unsigned char parity;
|
unsigned char parity;
|
||||||
@@ -91,52 +85,26 @@ processFrame (dsd_opts * opts, dsd_state * state)
|
|||||||
nxdn_frame (opts, state);
|
nxdn_frame (opts, state);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//DSTAR
|
||||||
else if ((state->synctype == 6) || (state->synctype == 7))
|
else if ((state->synctype == 6) || (state->synctype == 7))
|
||||||
{
|
{
|
||||||
state->nac = 0;
|
if ((opts->mbe_out_dir[0] != 0) && (opts->mbe_out_f == NULL))
|
||||||
state->lastsrc = 0;
|
openMbeOutFile (opts, state);
|
||||||
state->lasttg = 0;
|
sprintf (state->fsubtype, " VOICE ");
|
||||||
if (opts->errorbars == 1)
|
processDSTAR (opts, state);
|
||||||
{
|
return;
|
||||||
if (opts->verbose > 0)
|
}
|
||||||
{
|
|
||||||
level = (int) state->max / 164;
|
|
||||||
//fprintf (stderr,"inlvl: %2i%% ", level);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
state->nac = 0;
|
|
||||||
if ((opts->mbe_out_dir[0] != 0) && (opts->mbe_out_f == NULL))
|
|
||||||
{
|
|
||||||
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 ");
|
|
||||||
processDSTAR (opts, state);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else if ((state->synctype == 18) || (state->synctype == 19))
|
else if ((state->synctype == 18) || (state->synctype == 19))
|
||||||
{
|
{
|
||||||
state->nac = 0;
|
if ((opts->mbe_out_dir[0] != 0) && (opts->mbe_out_f == NULL))
|
||||||
state->lastsrc = 0;
|
openMbeOutFile (opts, state);
|
||||||
state->lasttg = 0;
|
sprintf (state->fsubtype, " DATA ");
|
||||||
if (opts->errorbars == 1)
|
processDSTAR_HD (opts, state);
|
||||||
{
|
return;
|
||||||
if (opts->verbose > 0)
|
}
|
||||||
{
|
|
||||||
level = (int) state->max / 164;
|
|
||||||
//fprintf (stderr,"inlvl: %2i%% ", level);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
state->nac = 0;
|
|
||||||
if ((opts->mbe_out_dir[0] != 0) && (opts->mbe_out_f == NULL))
|
|
||||||
{
|
|
||||||
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 ");
|
|
||||||
processDSTAR_HD (opts, state);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
//Start DMR Types
|
//Start DMR Types
|
||||||
else if ((state->synctype >= 10) && (state->synctype <= 13) || (state->synctype == 32) || (state->synctype == 33) || (state->synctype == 34) ) //32-34 DMR MS and RC
|
else if ((state->synctype >= 10 && state->synctype <= 13) || (state->synctype == 32) || (state->synctype == 33) || (state->synctype == 34) ) //32-34 DMR MS and RC
|
||||||
{
|
{
|
||||||
|
|
||||||
//print manufacturer strings to branding, disabled 0x10 moto other systems can use that fid set
|
//print manufacturer strings to branding, disabled 0x10 moto other systems can use that fid set
|
||||||
@@ -177,19 +145,19 @@ processFrame (dsd_opts * opts, dsd_state * 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)
|
||||||
{
|
{
|
||||||
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
|
//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);
|
if ((opts->mbe_out_dir[0] != 0) && (opts->mbe_out_f == NULL)) openMbeOutFile (opts, state);
|
||||||
dmrMSBootstrap (opts, state);
|
if (opts->p25_trunk == 0) dmrMSBootstrap (opts, state);
|
||||||
}
|
}
|
||||||
if (opts->dmr_mono == 1 && state->synctype == 32)
|
if (opts->dmr_mono == 1 && state->synctype == 32)
|
||||||
{
|
{
|
||||||
//we can safely open MBE on any MS or mono handling
|
//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);
|
if ((opts->mbe_out_dir[0] != 0) && (opts->mbe_out_f == NULL)) openMbeOutFile (opts, state);
|
||||||
dmrMSBootstrap (opts, state);
|
if (opts->p25_trunk == 0) dmrMSBootstrap (opts, state);
|
||||||
}
|
}
|
||||||
if (opts->dmr_stereo == 1) //opts->dmr_stereo == 1
|
if (opts->dmr_stereo == 1) //opts->dmr_stereo == 1
|
||||||
{
|
{
|
||||||
@@ -198,7 +166,7 @@ processFrame (dsd_opts * opts, dsd_state * state)
|
|||||||
{
|
{
|
||||||
//we can safely open MBE on any MS or mono handling
|
//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);
|
if ((opts->mbe_out_dir[0] != 0) && (opts->mbe_out_f == NULL)) openMbeOutFile (opts, state);
|
||||||
dmrMSBootstrap (opts, state); //bootstrap into MS Bootstrap (voice only)
|
if (opts->p25_trunk == 0) 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
|
||||||
}
|
}
|
||||||
@@ -207,7 +175,7 @@ processFrame (dsd_opts * opts, dsd_state * state)
|
|||||||
{
|
{
|
||||||
if (opts->mbe_out_f != NULL) closeMbeOutFile (opts, state);
|
if (opts->mbe_out_f != NULL) closeMbeOutFile (opts, state);
|
||||||
if (opts->mbe_out_fR != NULL) closeMbeOutFileR (opts, state);
|
if (opts->mbe_out_fR != NULL) closeMbeOutFileR (opts, state);
|
||||||
dmrMSData (opts, state);
|
if (opts->p25_trunk == 0) dmrMSData (opts, state);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -219,7 +187,6 @@ processFrame (dsd_opts * opts, dsd_state * 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 ");
|
||||||
state->payload_miP = 0; //zero out when switching back to data sync
|
|
||||||
dmr_data_sync (opts, state);
|
dmr_data_sync (opts, 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
|
||||||
@@ -231,7 +198,6 @@ processFrame (dsd_opts * opts, dsd_state * 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 ");
|
||||||
state->payload_miP = 0; //zero out when switching back to data sync
|
|
||||||
dmr_data_sync (opts, state);
|
dmr_data_sync (opts, state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -290,16 +256,16 @@ processFrame (dsd_opts * opts, dsd_state * state)
|
|||||||
//ysf
|
//ysf
|
||||||
else if ((state->synctype == 30) || (state->synctype == 31))
|
else if ((state->synctype == 30) || (state->synctype == 31))
|
||||||
{
|
{
|
||||||
//Do stuff
|
//relocate MBEout to inside frame handling -- Not Working Currently for YSF
|
||||||
//fprintf(stderr, "YSF Sync! \n");
|
|
||||||
if ((opts->mbe_out_dir[0] != 0) && (opts->mbe_out_f == NULL))
|
|
||||||
{
|
|
||||||
//openMbeOutFile (opts, state);
|
|
||||||
}
|
|
||||||
//sprintf(state->fsubtype, " VOICE ");
|
|
||||||
processYSF(opts, state);
|
processYSF(opts, state);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
//M17 STR
|
||||||
|
else if (state->synctype == 16)
|
||||||
|
{
|
||||||
|
processM17STR(opts, state);
|
||||||
|
return;
|
||||||
|
}
|
||||||
//P25 P2
|
//P25 P2
|
||||||
else if ((state->synctype == 35) || (state->synctype == 36))
|
else if ((state->synctype == 35) || (state->synctype == 36))
|
||||||
{
|
{
|
||||||
@@ -424,7 +390,8 @@ processFrame (dsd_opts * opts, dsd_state * state)
|
|||||||
if (new_nac != state->nac) {
|
if (new_nac != state->nac) {
|
||||||
// NAC fixed by error correction
|
// NAC fixed by error correction
|
||||||
state->nac = new_nac;
|
state->nac = new_nac;
|
||||||
if (state->p2_hardset == 0 && new_nac != 0)
|
//apparently, both 0 and 0xFFF can the BCH code on signal drop
|
||||||
|
if (state->p2_hardset == 0 && new_nac != 0 && new_nac != 0xFFF)
|
||||||
{
|
{
|
||||||
state->p2_cc = new_nac;
|
state->p2_cc = new_nac;
|
||||||
}
|
}
|
||||||
@@ -604,7 +571,7 @@ processFrame (dsd_opts * opts, dsd_state * state)
|
|||||||
if (opts->errorbars == 1)
|
if (opts->errorbars == 1)
|
||||||
{
|
{
|
||||||
printFrameInfo (opts, state);
|
printFrameInfo (opts, state);
|
||||||
fprintf (stderr," MBF\n"); //multi block format PDU
|
fprintf (stderr," MPDU\n"); //multi block format PDU
|
||||||
}
|
}
|
||||||
if (opts->mbe_out_dir[0] != 0)
|
if (opts->mbe_out_dir[0] != 0)
|
||||||
{
|
{
|
||||||
@@ -616,7 +583,7 @@ processFrame (dsd_opts * opts, dsd_state * state)
|
|||||||
resumeScan (opts, state);
|
resumeScan (opts, state);
|
||||||
}
|
}
|
||||||
state->lastp25type = 4;
|
state->lastp25type = 4;
|
||||||
sprintf (state->fsubtype, " MBF ");
|
sprintf (state->fsubtype, " MPDU ");
|
||||||
|
|
||||||
processMPDU(opts, state);
|
processMPDU(opts, state);
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
958
src/dsd_gps.c
Normal file
958
src/dsd_gps.c
Normal file
@@ -0,0 +1,958 @@
|
|||||||
|
/*-------------------------------------------------------------------------------
|
||||||
|
* dsd_gps.c
|
||||||
|
* GPS Handling Functions for Various Protocols
|
||||||
|
*
|
||||||
|
* LWVMOBILE
|
||||||
|
* 2023-12 DSD-FME Florida Man Edition
|
||||||
|
*-----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#include "dsd.h"
|
||||||
|
|
||||||
|
void lip_protocol_decoder (dsd_opts * opts, dsd_state * state, uint8_t * input)
|
||||||
|
{
|
||||||
|
//NOTE: This is defined in ETSI TS 102 361-4 V1.12.1 (2023-07) p208
|
||||||
|
//6.6.11.3.2 USBD Polling Service Poll Response PDU for LIP (That's a mouthful)
|
||||||
|
|
||||||
|
int slot = state->currentslot;
|
||||||
|
|
||||||
|
//May need to set this in the UDT header, or pass it into this function to be sure
|
||||||
|
// uint32_t src = 0;
|
||||||
|
// if (slot == 0)
|
||||||
|
// src = state->lastsrc;
|
||||||
|
// else src = state->lastsrcR;
|
||||||
|
|
||||||
|
//NOTE: This format is pretty much the same as DMR EMB GPS, but has a few extra elements,
|
||||||
|
//so I got lazy and just lifted most of the code from there, also assuming same lat/lon calcs
|
||||||
|
//since those have been tested to work in DMR EMB GPS and units are same in LIP
|
||||||
|
|
||||||
|
fprintf (stderr, "Location Information Protocol; ");
|
||||||
|
|
||||||
|
// uint8_t service_type = (uint8_t)ConvertBitIntoBytes(&input[0], 4); //checked before arrival here
|
||||||
|
uint8_t time_elapsed = (uint8_t)ConvertBitIntoBytes(&input[6], 2);
|
||||||
|
uint8_t lon_sign = input[8];
|
||||||
|
uint32_t lon = (uint32_t)ConvertBitIntoBytes(&input[9], 24); //8, 25
|
||||||
|
uint8_t lat_sign = input[33];
|
||||||
|
uint32_t lat = (uint32_t)ConvertBitIntoBytes(&input[34], 23); //33, 24
|
||||||
|
uint8_t pos_err = (uint8_t)ConvertBitIntoBytes(&input[57], 2);
|
||||||
|
uint8_t hor_vel = (uint8_t)ConvertBitIntoBytes(&input[59], 7);
|
||||||
|
uint8_t dir_tra = (uint8_t)ConvertBitIntoBytes(&input[66], 4);
|
||||||
|
uint8_t reason = (uint8_t)ConvertBitIntoBytes(&input[70], 3);
|
||||||
|
uint8_t add_hash = (uint8_t)ConvertBitIntoBytes(&input[73], 8); //MS Source Address Hash
|
||||||
|
|
||||||
|
//NOTE: May need to use double instead of float to avoid rounding errors
|
||||||
|
double latitude, longitude = 0.0f;
|
||||||
|
double lat_unit = (double)180/ pow (2.0, 24); //180 divided by 2^24 -- 6.3.30
|
||||||
|
double lon_unit = (double)360/ pow (2.0, 25); //360 divided by 2^25 -- 6.3.50
|
||||||
|
double lon_sf = 1.0f; //float value we can multiple longitude with
|
||||||
|
double lat_sf = 1.0f; //float value we can multiple latitude with
|
||||||
|
|
||||||
|
char latstr[3];
|
||||||
|
char lonstr[3];
|
||||||
|
sprintf (latstr, "%s", "N");
|
||||||
|
sprintf (lonstr, "%s", "E");
|
||||||
|
|
||||||
|
char deg_glyph[4];
|
||||||
|
sprintf (deg_glyph, "%s", "°");
|
||||||
|
|
||||||
|
//lat and lon calculations
|
||||||
|
if (lat_sign)
|
||||||
|
{
|
||||||
|
lat = 0x800001 - lat;
|
||||||
|
sprintf (latstr, "%s", "S");
|
||||||
|
lat_sf = -1.0f;
|
||||||
|
}
|
||||||
|
latitude = ((double)lat * lat_unit);
|
||||||
|
|
||||||
|
if (lon_sign)
|
||||||
|
{
|
||||||
|
lon = 0x1000001 - lon;
|
||||||
|
sprintf (lonstr, "%s", "W");
|
||||||
|
lon_sf = -1.0f;
|
||||||
|
}
|
||||||
|
longitude = ((double)lon * lon_unit);
|
||||||
|
|
||||||
|
//6.3.63 Position Error
|
||||||
|
//6.3.17 Horizontal velocity
|
||||||
|
/*
|
||||||
|
Horizontal velocity shall be encoded for speeds 0 km/h to 28 km/h in 1 km/h steps and
|
||||||
|
from 28 km/h onwards using equation: v = C × (1 + x)^(K-A) + B where:
|
||||||
|
*/
|
||||||
|
float v = 0.0f;
|
||||||
|
float C = 16.0f;
|
||||||
|
float x = 0.038f;
|
||||||
|
float A = 13.0f;
|
||||||
|
float K = (float)hor_vel;
|
||||||
|
float B = 0.0f;
|
||||||
|
|
||||||
|
if (hor_vel > 28)
|
||||||
|
v = C * (pow(1+x, K-A)) + B; //I think this pow function is set up correctly
|
||||||
|
else v = (float)hor_vel;
|
||||||
|
|
||||||
|
float dir = (((float)dir_tra + 11.25f)/22.5f); //page 68, Table 6.45
|
||||||
|
|
||||||
|
//truncated and rounded forms
|
||||||
|
int vt = (int)v;
|
||||||
|
int dt = (int)dir;
|
||||||
|
|
||||||
|
//sanity check
|
||||||
|
if (fabs (latitude) < 90 && fabs(longitude) < 180)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "Src(Hash); %03d; Lat: %.5lf%s%s Lon: %.5lf%s%s (%.5lf, %.5lf); Spd: %d km/h; Dir: %d%s",add_hash, latitude, deg_glyph, latstr, longitude, deg_glyph, lonstr, lat_sf * latitude, lon_sf * longitude, vt, dt, deg_glyph);
|
||||||
|
|
||||||
|
//6.3.63 Position Error
|
||||||
|
uint16_t position_error = 2 * pow(10, pos_err); //2 * 10^pos_err
|
||||||
|
if (pos_err == 0x7 ) fprintf (stderr, "\n Position Error: Unknown or Invalid;");
|
||||||
|
else fprintf (stderr, "\n Position Error: Less than %dm;", position_error);
|
||||||
|
|
||||||
|
//Reason For Sending 6.6.11.3.3 Table 6.80
|
||||||
|
if (reason) fprintf (stderr, " Reserved: %d;", reason);
|
||||||
|
else fprintf (stderr, " Request Response; ");
|
||||||
|
|
||||||
|
//6.3.78 Time elapsed
|
||||||
|
if (time_elapsed == 0) fprintf (stderr, " TE: < 5s;");
|
||||||
|
if (time_elapsed == 1) fprintf (stderr, " TE: < 5m;");
|
||||||
|
if (time_elapsed == 2) fprintf (stderr, " TE: < 30m;");
|
||||||
|
if (time_elapsed == 3) fprintf (stderr, " TE: NA or UNK;"); //not applicable or unknown
|
||||||
|
|
||||||
|
//save to array for ncurses
|
||||||
|
if (pos_err != 0x7)
|
||||||
|
{
|
||||||
|
sprintf (state->dmr_embedded_gps[slot], "%03d; LIP: %.5lf%s%s %.5lf%s%s; Err: %dm; Spd: %d km/h; Dir: %d%s", add_hash, latitude, deg_glyph, latstr, longitude, deg_glyph, lonstr, position_error, vt, dt, deg_glyph);
|
||||||
|
}
|
||||||
|
else sprintf (state->dmr_embedded_gps[slot], "%03d; LIP: %.5lf%s%s %.5lf%s%s Unknown Pos Err; Spd: %d km/h; Dir %d%s", add_hash, latitude, deg_glyph, latstr, longitude, deg_glyph, lonstr, vt, dt, deg_glyph);
|
||||||
|
|
||||||
|
//save to event history string
|
||||||
|
sprintf (state->event_history_s[slot].Event_History_Items[0].gps_s, "%s", state->dmr_embedded_gps[slot]);
|
||||||
|
|
||||||
|
//save to LRRP report for mapping/logging
|
||||||
|
FILE * pFile; //file pointer
|
||||||
|
if (opts->lrrp_file_output == 1)
|
||||||
|
{
|
||||||
|
|
||||||
|
char * datestr = getDateS();
|
||||||
|
char * timestr = getTimeC();
|
||||||
|
|
||||||
|
//open file by name that is supplied in the ncurses terminal, or cli
|
||||||
|
pFile = fopen (opts->lrrp_out_file, "a");
|
||||||
|
fprintf (pFile, "%s\t", datestr );
|
||||||
|
fprintf (pFile, "%s\t", timestr );
|
||||||
|
fprintf (pFile, "%08d\t", add_hash);
|
||||||
|
fprintf (pFile, "%.5lf\t", latitude);
|
||||||
|
fprintf (pFile, "%.5lf\t", longitude);
|
||||||
|
fprintf (pFile, "%d\t", vt); //speed in km/h
|
||||||
|
fprintf (pFile, "%d\t", dt); //direction of travel
|
||||||
|
fprintf (pFile, "\n");
|
||||||
|
fclose (pFile);
|
||||||
|
|
||||||
|
if (timestr != NULL)
|
||||||
|
{
|
||||||
|
free (timestr);
|
||||||
|
timestr = NULL;
|
||||||
|
}
|
||||||
|
if (datestr != NULL)
|
||||||
|
{
|
||||||
|
free (datestr);
|
||||||
|
datestr = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else fprintf (stderr, " Position Calculation Error;");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void nmea_iec_61162_1 (dsd_opts * opts, dsd_state * state, uint8_t * input, uint32_t src, int type)
|
||||||
|
{
|
||||||
|
int slot = state->currentslot;
|
||||||
|
|
||||||
|
//NOTE: The Only difference between Short (type == 1) and Long Format (type == 2)
|
||||||
|
//is the utc_ss3 on short vs utc_ss6 and inclusion of COG value on long
|
||||||
|
|
||||||
|
//NOTE: MFID Specific Formats are not handled here, unknown, could be added if worked out
|
||||||
|
//they could share most of the same elements and use the large spare bits in block 2 for extra
|
||||||
|
// uint8_t mfid = (uint8_t)ConvertBitIntoBytes(&input[88], 8); //on type 3, last octet of first block carries MFID
|
||||||
|
|
||||||
|
// uint8_t nmea_c = input[0]; //encrypted -- checked before we get here
|
||||||
|
uint8_t nmea_ns = input[1]; //north/south (lat sign)
|
||||||
|
uint8_t nmea_ew = input[2]; //east/west (lon sign)
|
||||||
|
uint8_t nmea_q = input[3]; //Quality Indicator (no fix or fix valid)
|
||||||
|
uint8_t nmea_speed = (uint8_t)ConvertBitIntoBytes(&input[4], 7); //speed in knots (127 = greater than 126 knots)
|
||||||
|
|
||||||
|
//Latitude Bits
|
||||||
|
uint8_t nmea_ndeg = (uint8_t)ConvertBitIntoBytes(&input[11], 7); //Latitude Degrees
|
||||||
|
uint8_t nmea_nmin = (uint8_t)ConvertBitIntoBytes(&input[18], 6); //Latitude Minutes
|
||||||
|
uint16_t nmea_nminf = (uint16_t)ConvertBitIntoBytes(&input[24], 14); //Latitude Fractions of Minutes
|
||||||
|
|
||||||
|
//Longitude Bits
|
||||||
|
uint8_t nmea_edeg = (uint8_t)ConvertBitIntoBytes(&input[38], 8); //Longitude Degrees
|
||||||
|
uint8_t nmea_emin = (uint8_t)ConvertBitIntoBytes(&input[46], 6); //Longitude Minutes
|
||||||
|
uint16_t nmea_eminf = (uint16_t)ConvertBitIntoBytes(&input[52], 14); //Longitude Fractions of Minutes
|
||||||
|
|
||||||
|
//UTC Time and COG
|
||||||
|
uint8_t nmea_utc_hh = (uint8_t)ConvertBitIntoBytes(&input[66], 5);
|
||||||
|
uint8_t nmea_utc_mm = (uint8_t)ConvertBitIntoBytes(&input[71], 6);
|
||||||
|
//seconds and the addition of COG is the difference between short and long formats
|
||||||
|
uint8_t nmea_utc_ss3 = (uint8_t)ConvertBitIntoBytes(&input[77], 3) * 10; //seconds in 10s
|
||||||
|
uint8_t nmea_utc_ss6 = (uint8_t)ConvertBitIntoBytes(&input[77], 6); //seconds in 1s
|
||||||
|
uint16_t nmea_cog = (uint16_t)ConvertBitIntoBytes(&input[103], 9); //course over ground in degrees
|
||||||
|
|
||||||
|
//lat and lon conversion
|
||||||
|
char deg_glyph[4];
|
||||||
|
sprintf (deg_glyph, "%s", "°");
|
||||||
|
float latitude = 0.0f;
|
||||||
|
float longitude = 0.0f;
|
||||||
|
// float m_unit = 1.0f / 60.0f; //unit to convert min into decimal value - (1/60)*60 minutes = 1 degree
|
||||||
|
// float mm_unit = 1.0f / 10000.0f; //unit to convert minf into decimal value - (0000 - 9999) 0.0001×9999 = .9999 minutes, so its sub 1 minute decimal
|
||||||
|
|
||||||
|
//testing w/ Harris NMEA like values (ran tests over there with this code, this seems to work on those values)
|
||||||
|
float m_unit = 1.0f / 60.0f; //unit to convert min into decimal value - (1/60)*60 minutes = 1 degree
|
||||||
|
float mm_unit = 1.0f / 600000.0f; //unit to convert minf into decimal value - (0000 - 9999) 0.0001×9999 = .9999 minutes, so its sub 1 minute decimal
|
||||||
|
|
||||||
|
//speed conversion
|
||||||
|
float fmps, fmph, fkph = 0.0f; //conversion of knots to mps, kph, and mph values
|
||||||
|
fmps = (float)nmea_speed * 0.514444; UNUSED(fmps);
|
||||||
|
fmph = (float)nmea_speed * 1.15078f; UNUSED(fmph);
|
||||||
|
fkph = (float)nmea_speed * 1.852f;
|
||||||
|
|
||||||
|
//calculate decimal representation of latidude and longitude (need some samples to test)
|
||||||
|
latitude = ( (float)nmea_ndeg + ((float)nmea_nmin*m_unit) + ((float)nmea_nminf*mm_unit) );
|
||||||
|
longitude = ( (float)nmea_edeg + ((float)nmea_emin*m_unit) + ((float)nmea_eminf*mm_unit) );
|
||||||
|
|
||||||
|
if (!nmea_ns) latitude *= -1.0f; //0 is South, 1 is North
|
||||||
|
if (!nmea_ew) longitude *= -1.0f; //0 is West, 1 is East
|
||||||
|
|
||||||
|
fprintf (stderr, " GPS: %f%s, %f%s;", latitude, deg_glyph, longitude, deg_glyph);
|
||||||
|
|
||||||
|
//Speed in Knots
|
||||||
|
if (nmea_speed > 126)
|
||||||
|
fprintf (stderr, " SPD > 126 knots or %f kph;", fkph);
|
||||||
|
else
|
||||||
|
fprintf (stderr, " SPD: %d knots; %f kph;", nmea_speed, fkph);
|
||||||
|
|
||||||
|
//Print UTC Time and COG according to Format Type
|
||||||
|
if (type == 1)
|
||||||
|
fprintf (stderr, " FIX: %d; %02d:%02d:%02d UTC; Short Format;", nmea_q, nmea_utc_hh, nmea_utc_mm, nmea_utc_ss3);
|
||||||
|
if (type == 2)
|
||||||
|
fprintf (stderr, " FIX: %d; %02d:%02d:%02d UTC; COG: %d%s; Long Format;", nmea_q, nmea_utc_hh, nmea_utc_mm, nmea_utc_ss6, nmea_cog, deg_glyph);
|
||||||
|
|
||||||
|
//save to ncurses string
|
||||||
|
sprintf (state->dmr_embedded_gps[slot], "GPS: (%f%s, %f%s)", latitude, deg_glyph, longitude, deg_glyph);
|
||||||
|
|
||||||
|
//save to event history string
|
||||||
|
sprintf (state->event_history_s[slot].Event_History_Items[0].gps_s, "(%f%s, %f%s)", latitude, deg_glyph, longitude, deg_glyph);
|
||||||
|
|
||||||
|
//save to LRRP report for mapping/logging
|
||||||
|
FILE * pFile; //file pointer
|
||||||
|
if (opts->lrrp_file_output == 1)
|
||||||
|
{
|
||||||
|
|
||||||
|
char * datestr = getDateS();
|
||||||
|
char * timestr = getTimeC();
|
||||||
|
|
||||||
|
int s = (int)fkph; //rounded interger format for the log report
|
||||||
|
int a = 0;
|
||||||
|
if (type == 2)
|
||||||
|
a = nmea_cog; //long format only
|
||||||
|
//open file by name that is supplied in the ncurses terminal, or cli
|
||||||
|
pFile = fopen (opts->lrrp_out_file, "a");
|
||||||
|
fprintf (pFile, "%s\t", datestr );
|
||||||
|
fprintf (pFile, "%s\t", timestr ); //could switch to UTC time if desired, but would require local user offset
|
||||||
|
fprintf (pFile, "%08d\t", src);
|
||||||
|
fprintf (pFile, "%.6lf\t", latitude);
|
||||||
|
fprintf (pFile, "%.6lf\t", longitude);
|
||||||
|
fprintf (pFile, "%d\t ", s);
|
||||||
|
fprintf (pFile, "%d\t ", a);
|
||||||
|
fprintf (pFile, "\n");
|
||||||
|
fclose (pFile);
|
||||||
|
|
||||||
|
if (timestr != NULL)
|
||||||
|
{
|
||||||
|
free (timestr);
|
||||||
|
timestr = NULL;
|
||||||
|
}
|
||||||
|
if (datestr != NULL)
|
||||||
|
{
|
||||||
|
free (datestr);
|
||||||
|
datestr = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//harris location on PTT (MAC) 3.100
|
||||||
|
void harris_lptt (dsd_opts * opts, dsd_state * state, uint8_t * input, uint32_t src, int slot, int phase)
|
||||||
|
{
|
||||||
|
|
||||||
|
//I really wonder about the engineers who laid out this message
|
||||||
|
|
||||||
|
//NOTE: I have only seen the MAC variation of this message description, I cannot 100% confirm
|
||||||
|
//the two block LCW format is identical, but it does carry the same amount of relevant bytes
|
||||||
|
//observation shows the GPS coordinates are accurate on LCW format, but I cannot
|
||||||
|
//vouch for the COG,SPEED,TIME, EMG and GPS Quality elements when in LCW format.
|
||||||
|
|
||||||
|
//starting at relevant information, bytes 0,1,2,3
|
||||||
|
uint16_t lat_min_dec = (uint16_t)ConvertBitIntoBytes(input+0, 16);
|
||||||
|
uint16_t lat_ns = input[16]; //0 == N, 1 == S
|
||||||
|
uint16_t lat_min_int = (uint16_t)ConvertBitIntoBytes(input+17, 7);
|
||||||
|
uint16_t lat_deg_int = (uint16_t)ConvertBitIntoBytes(input+24, 8);
|
||||||
|
|
||||||
|
//starting at relevant information, bytes 4,5,6,7
|
||||||
|
uint16_t lon_min_dec = (uint16_t)ConvertBitIntoBytes(input+32, 16);
|
||||||
|
uint16_t lon_ew = input[48]; //0 == N, 1 == S
|
||||||
|
uint16_t lon_min_int = (uint16_t)ConvertBitIntoBytes(input+49, 7);
|
||||||
|
uint16_t lon_deg_int = (uint16_t)ConvertBitIntoBytes(input+56, 8);
|
||||||
|
|
||||||
|
//starting at relevant information, bytes 8,9
|
||||||
|
uint32_t time_secs_low = (uint32_t)ConvertBitIntoBytes(input+64, 16);
|
||||||
|
|
||||||
|
//starting at relevant information, bytes 10,11,12,13
|
||||||
|
uint16_t course_low = (uint16_t)ConvertBitIntoBytes(input+80, 8);
|
||||||
|
uint16_t speed_low = (uint16_t)ConvertBitIntoBytes(input+88, 8);
|
||||||
|
uint16_t course_high = (uint16_t)ConvertBitIntoBytes(input+96+4, 4); //says 3,2,1,0,
|
||||||
|
uint16_t speed_high = (uint16_t)ConvertBitIntoBytes(input+96+0, 4); //says 7,6,5,4
|
||||||
|
|
||||||
|
//starting at relevant information, byte 14
|
||||||
|
uint32_t time_secs_high = input[104];
|
||||||
|
uint8_t status_emergency = input[105];
|
||||||
|
uint8_t gps_quality = (uint16_t)ConvertBitIntoBytes(input+106, 2);
|
||||||
|
uint8_t gps_sat_num = (uint16_t)ConvertBitIntoBytes(input+108, 4);
|
||||||
|
|
||||||
|
//start calculating things
|
||||||
|
float lat_DDMMmm = (float)lat_deg_int + ((float)lat_min_int / 60.0f) + ((float)lat_min_dec / 600000.0f);
|
||||||
|
float lon_DDMMmm = (float)lon_deg_int + ((float)lon_min_int / 60.0f) + ((float)lon_min_dec / 600000.0f);
|
||||||
|
|
||||||
|
if (lat_ns)
|
||||||
|
lat_DDMMmm *= -1.0f;
|
||||||
|
if (lon_ew)
|
||||||
|
lon_DDMMmm *= -1.0f;
|
||||||
|
|
||||||
|
//course conversion
|
||||||
|
uint32_t course = (course_high << 4) | course_low; //tenths of degrees
|
||||||
|
float course_deg = (float)course / 10.0f; //actual value
|
||||||
|
|
||||||
|
//speed conversion
|
||||||
|
uint32_t speed_knots = (speed_high << 4) | speed_low; //tenths of degrees
|
||||||
|
float fmps, fmph, fkph = 0.0f; //conversion of knots to mps, kph, and mph values
|
||||||
|
fmps = ((float)speed_knots / 10.0f) * 0.514444; UNUSED(fmps);
|
||||||
|
fmph = ((float)speed_knots / 10.0f) * 1.15078f; UNUSED(fmph);
|
||||||
|
fkph = ((float)speed_knots / 10.0f) * 1.852f; UNUSED(fkph);
|
||||||
|
|
||||||
|
//seconds since midnight as a 17-bit representation and calculation to HHMMSS format
|
||||||
|
uint32_t sec_m = (time_secs_high << 16) | time_secs_low;
|
||||||
|
uint32_t thour = sec_m / 3600;
|
||||||
|
uint32_t tmin = (sec_m % 3600) / 60;
|
||||||
|
uint32_t tsec = (sec_m % 3600) % 60;
|
||||||
|
|
||||||
|
char deg_glyph[4];
|
||||||
|
sprintf (deg_glyph, "%s", "°");
|
||||||
|
|
||||||
|
//print results
|
||||||
|
fprintf (stderr, "\n");
|
||||||
|
if (phase == 2)
|
||||||
|
{
|
||||||
|
fprintf (stderr, " LCH: %d;", slot);
|
||||||
|
if (src != 0)
|
||||||
|
fprintf (stderr, " SRC: %08d;", src);
|
||||||
|
else
|
||||||
|
fprintf (stderr, " SRC: UNK;");
|
||||||
|
|
||||||
|
if (gps_quality < 3) //GPS hardware present
|
||||||
|
{
|
||||||
|
fprintf (stderr, " GPS: %f%s, %f%s;", lat_DDMMmm, deg_glyph, lon_DDMMmm, deg_glyph);
|
||||||
|
if (gps_quality == 0)
|
||||||
|
fprintf (stderr, " Last Fix;"); //No fix still holds last values
|
||||||
|
else if (gps_quality == 1)
|
||||||
|
fprintf (stderr, " Curr Fix;");
|
||||||
|
else if (gps_quality == 2)
|
||||||
|
fprintf (stderr, " Diff Fix;"); //presumably either lat or lon only changed, not both?
|
||||||
|
|
||||||
|
fprintf (stderr, " #Sats: %d;", gps_sat_num);
|
||||||
|
}
|
||||||
|
else if (gps_quality == 3)
|
||||||
|
fprintf (stderr, " GPS: Not Enabled / No Hardware Present;");
|
||||||
|
|
||||||
|
fprintf (stderr, " COG: %f%s;", course_deg, deg_glyph);
|
||||||
|
fprintf (stderr, " SPD: %f k/h;", fkph);
|
||||||
|
|
||||||
|
if (sec_m != 0x1FFFF) // && sec_m != 0 (so says the doc, but midnight is a valid time)
|
||||||
|
fprintf (stderr, " T: %02d:%02d:%02d;", thour, tmin, tsec);
|
||||||
|
|
||||||
|
if (status_emergency)
|
||||||
|
fprintf (stderr, " Emergency;");
|
||||||
|
}
|
||||||
|
else if (phase == 1)
|
||||||
|
{
|
||||||
|
if (src != 0)
|
||||||
|
fprintf (stderr, " SRC: %08d;", src);
|
||||||
|
else
|
||||||
|
fprintf (stderr, " SRC: UNK;");
|
||||||
|
fprintf (stderr, " GPS: %f%s, %f%s;", lat_DDMMmm, deg_glyph, lon_DDMMmm, deg_glyph);
|
||||||
|
|
||||||
|
//again, can't vouch 100%, so just going to dump the GPS Coordinates and zero out other values for LRRP file
|
||||||
|
fkph = 0.0f;
|
||||||
|
course_deg = 0.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
//save to ncurses string
|
||||||
|
sprintf (state->dmr_embedded_gps[slot], "(%f%s, %f%s)", lat_DDMMmm, deg_glyph, lon_DDMMmm, deg_glyph);
|
||||||
|
|
||||||
|
//save to event history string
|
||||||
|
if (state->event_history_s[slot].Event_History_Items[0].source_id == src && src != 0)
|
||||||
|
sprintf (state->event_history_s[slot].Event_History_Items[0].gps_s, "%s", state->dmr_embedded_gps[slot]);
|
||||||
|
|
||||||
|
//save to LRRP report for mapping/logging
|
||||||
|
if (opts->lrrp_file_output == 1 && src != 0 && gps_quality != 3)
|
||||||
|
{
|
||||||
|
|
||||||
|
char * datestr = getDateS();
|
||||||
|
char * timestr = getTimeC();
|
||||||
|
|
||||||
|
//rounded interger formats for the log report
|
||||||
|
int s = (int)fkph;
|
||||||
|
int a = (int)course_deg;
|
||||||
|
|
||||||
|
//open file by name that is supplied in the ncurses terminal, or cli
|
||||||
|
FILE * pFile; //file pointer
|
||||||
|
pFile = fopen (opts->lrrp_out_file, "a");
|
||||||
|
fprintf (pFile, "%s\t", datestr );
|
||||||
|
fprintf (pFile, "%s\t", timestr );
|
||||||
|
fprintf (pFile, "%08d\t", src);
|
||||||
|
fprintf (pFile, "%.6lf\t", lat_DDMMmm);
|
||||||
|
fprintf (pFile, "%.6lf\t", lon_DDMMmm);
|
||||||
|
fprintf (pFile, "%d\t ", s);
|
||||||
|
fprintf (pFile, "%d\t ", a);
|
||||||
|
fprintf (pFile, "\n");
|
||||||
|
fclose (pFile);
|
||||||
|
|
||||||
|
if (timestr != NULL)
|
||||||
|
{
|
||||||
|
free (timestr);
|
||||||
|
timestr = NULL;
|
||||||
|
}
|
||||||
|
if (datestr != NULL)
|
||||||
|
{
|
||||||
|
free (datestr);
|
||||||
|
datestr = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//debugging dump of this message
|
||||||
|
// if (opts->payload == 1)
|
||||||
|
// {
|
||||||
|
// fprintf (stderr, "\n ");
|
||||||
|
// for (int i = 0; i < 14; i++)
|
||||||
|
// fprintf (stderr, "%02X ", (uint8_t)ConvertBitIntoBytes(input+(i*8), 8));
|
||||||
|
// }
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//externalize embedded GPS - Confirmed working now on NE, NW, SE, and SW coordinates
|
||||||
|
void dmr_embedded_gps (dsd_opts * opts, dsd_state * state, uint8_t lc_bits[])
|
||||||
|
{
|
||||||
|
UNUSED(opts);
|
||||||
|
|
||||||
|
fprintf (stderr, "%s", KYEL);
|
||||||
|
fprintf (stderr, " Embedded GPS:");
|
||||||
|
uint8_t slot = state->currentslot;
|
||||||
|
uint8_t pf = lc_bits[0];
|
||||||
|
uint8_t res_a = lc_bits[1];
|
||||||
|
uint8_t res_b = (uint8_t)ConvertBitIntoBytes(&lc_bits[16], 4);
|
||||||
|
uint8_t pos_err = (uint8_t)ConvertBitIntoBytes(&lc_bits[20], 3);
|
||||||
|
UNUSED2(res_a, res_b);
|
||||||
|
|
||||||
|
char deg_glyph[4];
|
||||||
|
sprintf (deg_glyph, "%s", "°");
|
||||||
|
|
||||||
|
uint32_t lon_sign = lc_bits[23];
|
||||||
|
uint32_t lon = (uint32_t)ConvertBitIntoBytes(&lc_bits[24], 24);
|
||||||
|
uint32_t lat_sign = lc_bits[48];
|
||||||
|
uint32_t lat = (uint32_t)ConvertBitIntoBytes(&lc_bits[49], 23);
|
||||||
|
double lon_sf = 1.0f; //float value we can multiple longitude with
|
||||||
|
double lat_sf = 1.0f; //float value we can multiple latitude with
|
||||||
|
|
||||||
|
double lat_unit = (double)180/ pow (2.0, 24); //180 divided by 2^24
|
||||||
|
double lon_unit = (double)360/ pow (2.0, 25); //360 divided by 2^25
|
||||||
|
|
||||||
|
char latstr[3];
|
||||||
|
char lonstr[3];
|
||||||
|
sprintf (latstr, "%s", "N");
|
||||||
|
sprintf (lonstr, "%s", "E");
|
||||||
|
|
||||||
|
//run calculations and print
|
||||||
|
//7.2.16 and 7.2.17 (two's compliment)
|
||||||
|
|
||||||
|
double latitude = 0;
|
||||||
|
double longitude = 0;
|
||||||
|
|
||||||
|
if (pf) fprintf (stderr, " Protected");
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (lat_sign)
|
||||||
|
{
|
||||||
|
lat = 0x800001 - lat;
|
||||||
|
sprintf (latstr, "%s", "S");
|
||||||
|
lat_sf = -1.0f;
|
||||||
|
}
|
||||||
|
latitude = ((double)lat * lat_unit);
|
||||||
|
|
||||||
|
if (lon_sign)
|
||||||
|
{
|
||||||
|
lon = 0x1000001 - lon;
|
||||||
|
sprintf (lonstr, "%s", "W");
|
||||||
|
lon_sf = -1.0f;
|
||||||
|
}
|
||||||
|
longitude = ((double)lon * lon_unit);
|
||||||
|
|
||||||
|
//sanity check
|
||||||
|
if (fabs(latitude) < 90 && fabs(longitude) < 180)
|
||||||
|
{
|
||||||
|
fprintf (stderr, " Lat: %.5lf%s%s Lon: %.5lf%s%s (%.5lf, %.5lf)", latitude, deg_glyph, latstr, longitude, deg_glyph, lonstr, lat_sf * latitude, lon_sf * longitude);
|
||||||
|
|
||||||
|
//7.2.15 Position Error
|
||||||
|
uint16_t position_error = 2 * pow(10, pos_err); //2 * 10^pos_err
|
||||||
|
if (pos_err == 0x7 ) fprintf (stderr, "\n Position Error: Unknown or Invalid");
|
||||||
|
else fprintf (stderr, "\n Position Error: Less than %dm", position_error);
|
||||||
|
|
||||||
|
//save to array for ncurses
|
||||||
|
if (pos_err != 0x7)
|
||||||
|
{
|
||||||
|
sprintf (state->dmr_embedded_gps[slot], "GPS: %.5lf%s%s %.5lf%s%s Err: %dm", latitude, deg_glyph, latstr, longitude, deg_glyph, lonstr, position_error);
|
||||||
|
}
|
||||||
|
else sprintf (state->dmr_embedded_gps[slot], "GPS: %.5lf%s%s %.5lf%s%s Unknown Pos Err", latitude, deg_glyph, latstr, longitude, deg_glyph, lonstr);
|
||||||
|
|
||||||
|
uint32_t src = 0;
|
||||||
|
if (slot == 0) src = state->lasttg;
|
||||||
|
if (slot == 1) src = state->lasttgR;
|
||||||
|
|
||||||
|
//save to event history string
|
||||||
|
// if (state->event_history_s[slot].Event_History_Items[0].source_id == src)
|
||||||
|
sprintf (state->event_history_s[slot].Event_History_Items[0].gps_s, "%s", state->dmr_embedded_gps[slot]);
|
||||||
|
|
||||||
|
//save to LRRP report for mapping/logging
|
||||||
|
FILE * pFile; //file pointer
|
||||||
|
if (opts->lrrp_file_output == 1)
|
||||||
|
{
|
||||||
|
|
||||||
|
char * datestr = getDateS();
|
||||||
|
char * timestr = getTimeC();
|
||||||
|
|
||||||
|
//open file by name that is supplied in the ncurses terminal, or cli
|
||||||
|
pFile = fopen (opts->lrrp_out_file, "a");
|
||||||
|
fprintf (pFile, "%s\t", datestr );
|
||||||
|
fprintf (pFile, "%s\t", timestr );
|
||||||
|
fprintf (pFile, "%08d\t", src);
|
||||||
|
fprintf (pFile, "%.5lf\t", latitude);
|
||||||
|
fprintf (pFile, "%.5lf\t", longitude);
|
||||||
|
fprintf (pFile, "0\t " ); //zero for velocity
|
||||||
|
fprintf (pFile, "0\t " ); //zero for azimuth
|
||||||
|
fprintf (pFile, "\n");
|
||||||
|
fclose (pFile);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf (stderr, "%s", KNRM);
|
||||||
|
}
|
||||||
|
|
||||||
|
//This Function needs testing, is tested working for NW and NE lat and
|
||||||
|
//long coordinates, but not for SE and SW coordinates
|
||||||
|
void apx_embedded_gps (dsd_opts * opts, dsd_state * state, uint8_t lc_bits[])
|
||||||
|
{
|
||||||
|
|
||||||
|
fprintf (stderr, "%s", KYEL);
|
||||||
|
fprintf (stderr, " GPS:");
|
||||||
|
uint8_t slot = state->currentslot;
|
||||||
|
uint8_t pf = lc_bits[0];
|
||||||
|
uint8_t res_a = lc_bits[1];
|
||||||
|
uint8_t res_b = (uint8_t)ConvertBitIntoBytes(&lc_bits[16], 7);
|
||||||
|
uint8_t expired = lc_bits[23]; //this bit seems to indicate that the GPS coordinates are out of date or fresh
|
||||||
|
|
||||||
|
char deg_glyph[4];
|
||||||
|
sprintf (deg_glyph, "%s", "°");
|
||||||
|
|
||||||
|
uint32_t lon_sign = lc_bits[48];
|
||||||
|
uint32_t lon = (uint32_t)ConvertBitIntoBytes(&lc_bits[49], 23);
|
||||||
|
uint32_t lat_sign = lc_bits[24];
|
||||||
|
uint32_t lat = (uint32_t)ConvertBitIntoBytes(&lc_bits[25], 23);
|
||||||
|
|
||||||
|
double lat_unit = 90.0f / 0x7FFFFF;
|
||||||
|
double lon_unit = 180.0f / 0x7FFFFF;
|
||||||
|
|
||||||
|
char latstr[3];
|
||||||
|
char lonstr[3];
|
||||||
|
char valid[12];
|
||||||
|
sprintf (latstr, "%s", "N");
|
||||||
|
sprintf (lonstr, "%s", "E");
|
||||||
|
sprintf (valid, "%s", "Current Fix");
|
||||||
|
|
||||||
|
double latitude = 0;
|
||||||
|
double longitude = 0;
|
||||||
|
|
||||||
|
if (pf) fprintf (stderr, " Protected");
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
latitude = ((double)lat * lat_unit);
|
||||||
|
if (lat_sign)
|
||||||
|
{
|
||||||
|
latitude -= 90.0f;
|
||||||
|
sprintf (latstr, "%s", "S");
|
||||||
|
}
|
||||||
|
|
||||||
|
longitude = ((double)lon * lon_unit);
|
||||||
|
if (lon_sign)
|
||||||
|
{
|
||||||
|
longitude -= 180.0f;
|
||||||
|
sprintf (lonstr, "%s", "W");
|
||||||
|
}
|
||||||
|
|
||||||
|
//sanity check
|
||||||
|
if (fabs ((float)latitude) < 90 && fabs((float)longitude) < 180)
|
||||||
|
{
|
||||||
|
fprintf (stderr, " Lat: %.5lf%s%s Lon: %.5lf%s%s (%.5lf, %.5lf) ", latitude, deg_glyph, latstr, longitude, deg_glyph, lonstr, latitude, longitude);
|
||||||
|
|
||||||
|
if (expired)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "Last Fix; ");
|
||||||
|
sprintf (valid, "%s", "Last Fix");
|
||||||
|
}
|
||||||
|
else if (!expired)
|
||||||
|
fprintf (stderr, "Current Fix; ");
|
||||||
|
|
||||||
|
if (res_a)
|
||||||
|
fprintf (stderr, "RES_A: %d; ", res_a);
|
||||||
|
|
||||||
|
if (res_b)
|
||||||
|
fprintf (stderr, "RES_B: %02X; ", res_b);
|
||||||
|
|
||||||
|
uint32_t src = 0;
|
||||||
|
if (slot == 0) src = state->lastsrc;
|
||||||
|
if (slot == 1) src = state->lastsrcR;
|
||||||
|
|
||||||
|
//save to array for ncurses
|
||||||
|
sprintf (state->dmr_embedded_gps[slot], "GPS: %lf%s%s %lf%s%s (%lf, %lf) %s", latitude, deg_glyph, latstr, longitude, deg_glyph, lonstr, latitude, longitude, valid);
|
||||||
|
|
||||||
|
//save to event history string
|
||||||
|
if (state->event_history_s[slot].Event_History_Items[0].source_id == src)
|
||||||
|
sprintf (state->event_history_s[slot].Event_History_Items[0].gps_s, "%s", state->dmr_embedded_gps[slot]);
|
||||||
|
|
||||||
|
//save to LRRP report for mapping/logging
|
||||||
|
FILE * pFile; //file pointer
|
||||||
|
if (opts->lrrp_file_output == 1)
|
||||||
|
{
|
||||||
|
|
||||||
|
char * datestr = getDateS();
|
||||||
|
char * timestr = getTimeC();
|
||||||
|
|
||||||
|
//open file by name that is supplied in the ncurses terminal, or cli
|
||||||
|
pFile = fopen (opts->lrrp_out_file, "a");
|
||||||
|
fprintf (pFile, "%s\t", datestr );
|
||||||
|
fprintf (pFile, "%s\t", timestr );
|
||||||
|
fprintf (pFile, "%08d\t", src);
|
||||||
|
fprintf (pFile, "%.5lf\t", latitude);
|
||||||
|
fprintf (pFile, "%.5lf\t", longitude);
|
||||||
|
fprintf (pFile, "0\t " ); //zero for velocity
|
||||||
|
fprintf (pFile, "0\t " ); //zero for azimuth
|
||||||
|
fprintf (pFile, "\n");
|
||||||
|
fclose (pFile);
|
||||||
|
|
||||||
|
if (timestr != NULL)
|
||||||
|
{
|
||||||
|
free (timestr);
|
||||||
|
timestr = NULL;
|
||||||
|
}
|
||||||
|
if (datestr != NULL)
|
||||||
|
{
|
||||||
|
free (datestr);
|
||||||
|
datestr = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf (stderr, "%s", KNRM);
|
||||||
|
}
|
||||||
|
|
||||||
|
void decode_cellocator(dsd_opts * opts, dsd_state * state, uint8_t * input, int len)
|
||||||
|
{
|
||||||
|
//TODO: This
|
||||||
|
UNUSED(opts);
|
||||||
|
UNUSED(state);
|
||||||
|
UNUSED(input);
|
||||||
|
UNUSED(len);
|
||||||
|
|
||||||
|
//UTF8 Text: MCGP (0x4D434750) followed by data values
|
||||||
|
//(0417D1050000F45FD1DD00010000000097BDD56C81000009AAAABF12864C)
|
||||||
|
utf8_to_text(state, 0, 4, input);
|
||||||
|
|
||||||
|
fprintf (stderr, " Cellocator:");
|
||||||
|
|
||||||
|
uint8_t type = input[4];
|
||||||
|
if (type == 1) fprintf (stderr, " Platform Manifest Data;");
|
||||||
|
else if (type == 2) fprintf (stderr, " CAN Data;");
|
||||||
|
else if (type == 3) fprintf (stderr, " CAN Trigger Data;");
|
||||||
|
else if (type == 4) fprintf (stderr, " Time and Location Data;");
|
||||||
|
else if (type == 5) fprintf (stderr, " Accelerometer Data;");
|
||||||
|
else if (type == 6) fprintf (stderr, " PSP Alarm System Data;");
|
||||||
|
else if (type == 7) fprintf (stderr, " Usage Counter Data;");
|
||||||
|
else if (type == 8) fprintf (stderr, " Command Authentication Table Data;");
|
||||||
|
else if (type == 9) fprintf (stderr, " GSM Neighbor List Data;");
|
||||||
|
else if (type == 10) fprintf (stderr, " Maintenance Server Platform Manifest Data;");
|
||||||
|
else fprintf (stderr, " Unknown Data;");
|
||||||
|
|
||||||
|
//Data afterwards appears to be an arbitrary len so has variable reporting data
|
||||||
|
//will need to establish a len value for data and contents
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void decode_ars(dsd_opts * opts, dsd_state * state, uint8_t * input, int len)
|
||||||
|
{
|
||||||
|
//TODO: This
|
||||||
|
UNUSED(opts);
|
||||||
|
UNUSED(state);
|
||||||
|
UNUSED(input);
|
||||||
|
UNUSED(len);
|
||||||
|
}
|
||||||
|
|
||||||
|
//WIP: Based on Denny's always brilliant reverse-engineering of GPS reports
|
||||||
|
void nxdn_gps_report(dsd_opts * opts, dsd_state * state, uint8_t * input, uint32_t src)
|
||||||
|
{
|
||||||
|
|
||||||
|
//Elevation
|
||||||
|
int16_t elevation = (int16_t)convert_bits_into_output(input+56, 16);
|
||||||
|
|
||||||
|
//Speed & Heading (in tenths)
|
||||||
|
uint16_t speed_raw = (uint16_t)convert_bits_into_output(input+74, 14);
|
||||||
|
uint16_t heading_raw = (uint16_t)convert_bits_into_output(input+92, 12);
|
||||||
|
double speed = speed_raw / 10.0; //knots or k/h
|
||||||
|
double heading = heading_raw / 10.0;
|
||||||
|
|
||||||
|
//Date
|
||||||
|
uint16_t year = (uint16_t)(convert_bits_into_output(input+136,7) + 2000);
|
||||||
|
uint8_t month = (uint8_t) convert_bits_into_output(input+143,4);
|
||||||
|
uint8_t day = (uint8_t)(convert_bits_into_output(input+147,5) + 1);
|
||||||
|
|
||||||
|
//Longitude (DDMM.mmmm format)
|
||||||
|
uint16_t lon_degmin = (uint16_t)convert_bits_into_output(input+152, 16);
|
||||||
|
uint16_t lon_frac = (uint16_t)convert_bits_into_output(input+16, 15);
|
||||||
|
uint8_t lon_hem = (uint8_t) convert_bits_into_output(input+183, 1);
|
||||||
|
double lon_minutes = (lon_degmin % 100) + (lon_frac / 10000.0);
|
||||||
|
double lon_decimal = (lon_degmin / 100) + (lon_minutes / 60.0);
|
||||||
|
double longitude = (lon_hem == 0) ? lon_decimal : -lon_decimal;
|
||||||
|
|
||||||
|
//Latitude (DDMM.mmmm format)
|
||||||
|
uint16_t lat_degmin = (uint16_t)convert_bits_into_output(input+184,16);
|
||||||
|
uint16_t lat_frac = (uint16_t)convert_bits_into_output(input+200,15);
|
||||||
|
uint8_t lat_hem = (uint8_t) convert_bits_into_output(input+215,1);
|
||||||
|
double lat_minutes = (lat_degmin % 100) + (lat_frac / 10000.0);
|
||||||
|
double lat_decimal = (lat_degmin / 100) + (lat_minutes / 60.0);
|
||||||
|
double latitude = (lat_hem == 0) ? lat_decimal : -lat_decimal;
|
||||||
|
|
||||||
|
//Time
|
||||||
|
uint8_t hour = (uint8_t) convert_bits_into_output(input+247,5);
|
||||||
|
uint8_t minute = (uint8_t) convert_bits_into_output(input+252,6);
|
||||||
|
|
||||||
|
char deg_glyph[4];
|
||||||
|
sprintf (deg_glyph, "%s", "°");
|
||||||
|
|
||||||
|
//Report
|
||||||
|
fprintf (stderr, "\n GPS: (%f%s, %f%s) ", latitude, deg_glyph, longitude, deg_glyph);
|
||||||
|
fprintf (stderr, "Speed: %lf k/h; ", speed);
|
||||||
|
fprintf (stderr, "COG: %lf; ", heading);
|
||||||
|
fprintf (stderr, "Elevation: %i; ", elevation);
|
||||||
|
fprintf (stderr, "Date: %04d/%02d/%02d ", year, month, day);
|
||||||
|
fprintf (stderr, "Time: %02d:%02d ", hour, minute);
|
||||||
|
|
||||||
|
//dump to event history
|
||||||
|
sprintf (state->event_history_s[0].Event_History_Items[0].gps_s, "(%f%s, %f%s)", latitude, deg_glyph, longitude, deg_glyph);
|
||||||
|
uint32_t source = state->dmr_lrrp_source[0];
|
||||||
|
uint32_t target = state->dmr_lrrp_target[0];
|
||||||
|
char comp_string[500]; memset (comp_string, 0, sizeof(comp_string));
|
||||||
|
sprintf (comp_string, "GPS SRC: %d; TGT: %d;", source, target);
|
||||||
|
watchdog_event_datacall (opts, state, source, target, comp_string, 0);
|
||||||
|
|
||||||
|
//save to LRRP report for mapping/logging
|
||||||
|
if (opts->lrrp_file_output == 1 && src != 0)
|
||||||
|
{
|
||||||
|
|
||||||
|
char * datestr = getDateS();
|
||||||
|
char * timestr = getTimeC();
|
||||||
|
|
||||||
|
//rounded interger formats for the log report
|
||||||
|
int s = (int)speed;
|
||||||
|
int a = (int)heading;
|
||||||
|
|
||||||
|
//open file by name that is supplied in the ncurses terminal, or cli
|
||||||
|
FILE * pFile; //file pointer
|
||||||
|
pFile = fopen (opts->lrrp_out_file, "a");
|
||||||
|
fprintf (pFile, "%s\t", datestr );
|
||||||
|
fprintf (pFile, "%s\t", timestr );
|
||||||
|
fprintf (pFile, "%08d\t", src);
|
||||||
|
fprintf (pFile, "%.6lf\t", latitude);
|
||||||
|
fprintf (pFile, "%.6lf\t", longitude);
|
||||||
|
fprintf (pFile, "%d\t ", s);
|
||||||
|
fprintf (pFile, "%d\t ", a);
|
||||||
|
fprintf (pFile, "\n");
|
||||||
|
fclose (pFile);
|
||||||
|
|
||||||
|
if (timestr != NULL)
|
||||||
|
{
|
||||||
|
free (timestr);
|
||||||
|
timestr = NULL;
|
||||||
|
}
|
||||||
|
if (datestr != NULL)
|
||||||
|
{
|
||||||
|
free (datestr);
|
||||||
|
datestr = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//reset source and target from PDU storage
|
||||||
|
state->dmr_lrrp_source[0] = 0;
|
||||||
|
state->dmr_lrrp_target[0] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t nmea_sentence_checker(dsd_opts * opts, dsd_state * state, uint8_t * input, uint8_t slot, int len)
|
||||||
|
{
|
||||||
|
|
||||||
|
//Check Start and End, and Validity w/ Checksum
|
||||||
|
int i;
|
||||||
|
uint8_t start_value = (uint8_t)ConvertBitIntoBytes(input, 8);
|
||||||
|
uint8_t end_value = 0;
|
||||||
|
uint8_t checksum_calc = 0;
|
||||||
|
uint8_t checksum_ext = 0;
|
||||||
|
char checksum_str[3];
|
||||||
|
memset(checksum_str, 0, sizeof(checksum_str));
|
||||||
|
uint8_t valid = 0;
|
||||||
|
|
||||||
|
if (start_value == '$' || start_value == '!')
|
||||||
|
{
|
||||||
|
//debug
|
||||||
|
// fprintf (stderr, "Start Okay! ");
|
||||||
|
|
||||||
|
for (i = 1; i < len; i++)
|
||||||
|
{
|
||||||
|
uint8_t value = (uint8_t)ConvertBitIntoBytes(input+(i*8), 8);
|
||||||
|
if (value == '*')
|
||||||
|
{
|
||||||
|
end_value = value;
|
||||||
|
checksum_str[0] = (uint8_t)ConvertBitIntoBytes(input+(i*8)+8, 8);
|
||||||
|
checksum_str[1] = (uint8_t)ConvertBitIntoBytes(input+(i*8)+16, 8);
|
||||||
|
checksum_str[2] = 0;
|
||||||
|
sscanf (checksum_str, "%hhX", &checksum_ext);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if (value >= 0x20 && value < 0x7F)
|
||||||
|
{
|
||||||
|
checksum_calc ^= value;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else break; //anything else that isn't ascii range values
|
||||||
|
}
|
||||||
|
|
||||||
|
//debug
|
||||||
|
// if (end_value == '*')
|
||||||
|
// fprintf (stderr, "Checksum Present! ");
|
||||||
|
|
||||||
|
if (checksum_ext == checksum_calc)
|
||||||
|
{
|
||||||
|
// fprintf (stderr, "Checksum Okay! (%02X / %02X)", checksum_calc, checksum_ext);
|
||||||
|
valid = 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// fprintf (stderr, "Checksum Err! (%02X / %02X) ", checksum_calc, checksum_ext);
|
||||||
|
valid = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//dump, if valid
|
||||||
|
memset(state->event_history_s[slot].Event_History_Items[0].text_message, 0, sizeof(state->event_history_s[slot].Event_History_Items[0].text_message));
|
||||||
|
if (valid)
|
||||||
|
{
|
||||||
|
uint8_t ascii = 0;
|
||||||
|
uint16_t crlf = 0;
|
||||||
|
for (i = 0; i < len; i++)
|
||||||
|
{
|
||||||
|
ascii = (uint8_t)ConvertBitIntoBytes(input+(i*8), 8);
|
||||||
|
crlf = (uint16_t)ConvertBitIntoBytes(input+(i*8), 16);
|
||||||
|
if (ascii >= 0x20 && ascii < 0x7F)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "%c", ascii);
|
||||||
|
state->event_history_s[slot].Event_History_Items[0].text_message[i] = ascii;
|
||||||
|
}
|
||||||
|
else if (crlf == 0x0D0A) //NMEA Sentences end with 0x0D 0x0A (CR/LF)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "%s", " ");
|
||||||
|
state->event_history_s[slot].Event_History_Items[0].text_message[i+0] = 0x20; //Space
|
||||||
|
state->event_history_s[slot].Event_History_Items[0].text_message[i+1] = 0x20; //Space
|
||||||
|
i+=2;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else break; //anything else that isn't ascii range values
|
||||||
|
}
|
||||||
|
|
||||||
|
//check for supplimentary string i.e., $PP25
|
||||||
|
ascii = (uint8_t)ConvertBitIntoBytes(input+(i*8), 8);
|
||||||
|
if (crlf == 0x0D0A && ascii == '$')
|
||||||
|
{
|
||||||
|
for (i = i; i < len; i++)
|
||||||
|
{
|
||||||
|
ascii = (uint8_t)ConvertBitIntoBytes(input+(i*8), 8);
|
||||||
|
crlf = (uint16_t)ConvertBitIntoBytes(input+(i*8), 16);
|
||||||
|
|
||||||
|
if (ascii >= 0x20 && ascii < 0x7F)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "%c", ascii);
|
||||||
|
state->event_history_s[slot].Event_History_Items[0].text_message[i] = ascii;
|
||||||
|
}
|
||||||
|
else if (crlf == 0x0D0A) //Supplimentary Sentences end with 0x0D 0x0A (CR/LF)
|
||||||
|
{
|
||||||
|
state->event_history_s[slot].Event_History_Items[0].text_message[i] = 0x20;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else break; //anything else that isn't ascii range values
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//debug
|
||||||
|
// fprintf(stderr, "\n %s", state->event_history_s[slot].Event_History_Items[0].text_message);
|
||||||
|
|
||||||
|
//dump to event history
|
||||||
|
state->event_history_s[slot].Event_History_Items[0].text_message[i] = '\0';
|
||||||
|
uint32_t source = state->dmr_lrrp_source[slot];
|
||||||
|
uint32_t target = state->dmr_lrrp_target[slot];
|
||||||
|
char comp_string[500]; memset (comp_string, 0, sizeof(comp_string));
|
||||||
|
sprintf (comp_string, "NMEA SRC: %d; TGT: %d;", source, target);
|
||||||
|
watchdog_event_datacall (opts, state, source, target, comp_string, slot);
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (start_value != '$' && start_value != '!')
|
||||||
|
fprintf (stderr, " Not an NMEA Sentence Structure;");
|
||||||
|
else if ( (start_value == '$' || start_value == '!') && end_value != '*')
|
||||||
|
fprintf (stderr, " Possible NMEA Sentence, Missing Ending *;");
|
||||||
|
else if ( start_value != '$' && start_value != '!' && end_value == '*')
|
||||||
|
fprintf (stderr, " Possible NMEA Sentence, Missing Starting $ or !;");
|
||||||
|
else if (checksum_calc != checksum_ext)
|
||||||
|
fprintf (stderr, " NMEA Checksum Error (%02X / %02X);", checksum_calc, checksum_ext);
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO: Convert to LRRP data and report / GPS on Event History
|
||||||
|
|
||||||
|
state->dmr_lrrp_source[slot] = 0;
|
||||||
|
state->dmr_lrrp_target[slot] = 0;
|
||||||
|
|
||||||
|
return valid;
|
||||||
|
}
|
||||||
110
src/dsd_import.c
110
src/dsd_import.c
@@ -7,25 +7,31 @@ int csvGroupImport(dsd_opts * opts, dsd_state * state)
|
|||||||
{
|
{
|
||||||
char filename[1024] = "filename.csv";
|
char filename[1024] = "filename.csv";
|
||||||
sprintf (filename, "%s", opts->group_in_file);
|
sprintf (filename, "%s", opts->group_in_file);
|
||||||
//filename[1023] = '\0'; //necessary?
|
|
||||||
char buffer[BSIZE];
|
char buffer[BSIZE];
|
||||||
FILE * fp;
|
FILE * fp;
|
||||||
fp = fopen(filename, "r");
|
fp = fopen(filename, "r");
|
||||||
if (fp == NULL) {
|
|
||||||
|
if (fp == NULL)
|
||||||
|
{
|
||||||
printf("Unable to open group file '%s'\n", filename);
|
printf("Unable to open group file '%s'\n", filename);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int row_count = 0;
|
int row_count = 0;
|
||||||
int field_count = 0;
|
int field_count = 0;
|
||||||
long int group_number = 0; //local group number for array index value
|
|
||||||
int i = 0;
|
unsigned int i = 0;
|
||||||
while (fgets(buffer, BSIZE, fp)) {
|
while (fgets(buffer, BSIZE, fp))
|
||||||
|
{
|
||||||
|
|
||||||
field_count = 0;
|
field_count = 0;
|
||||||
row_count++;
|
row_count++;
|
||||||
if (row_count == 1)
|
if (row_count == 1)
|
||||||
continue; //don't want labels
|
continue; //don't want labels
|
||||||
char * field = strtok(buffer, ","); //seperate by comma
|
char * field = strtok(buffer, ","); //seperate by comma
|
||||||
while (field) {
|
while (field)
|
||||||
|
{
|
||||||
|
|
||||||
if (field_count == 0)
|
if (field_count == 0)
|
||||||
{
|
{
|
||||||
@@ -33,23 +39,38 @@ int csvGroupImport(dsd_opts * opts, dsd_state * state)
|
|||||||
state->group_array[i].groupNumber = atol(field);
|
state->group_array[i].groupNumber = atol(field);
|
||||||
fprintf (stderr, "%ld, ", state->group_array[i].groupNumber);
|
fprintf (stderr, "%ld, ", state->group_array[i].groupNumber);
|
||||||
}
|
}
|
||||||
if (field_count == 1)
|
else if (field_count == 1)
|
||||||
{
|
{
|
||||||
strcpy(state->group_array[i].groupMode, field);
|
// strcpy(state->group_array[i].groupMode, field);
|
||||||
|
strncpy(state->group_array[i].groupMode, field, 2); //only copy two letters max A, B, D, DE
|
||||||
fprintf (stderr, "%s, ", state->group_array[i].groupMode);
|
fprintf (stderr, "%s, ", state->group_array[i].groupMode);
|
||||||
}
|
}
|
||||||
if (field_count == 2)
|
else if (field_count == 2)
|
||||||
{
|
{
|
||||||
strcpy(state->group_array[i].groupName, field);
|
// strcpy(state->group_array[i].groupName, field);
|
||||||
|
strncpy(state->group_array[i].groupName, field, 98); //this should also fix potential issues observed in past when there is no comma after the name
|
||||||
|
|
||||||
|
uint16_t len = strlen((const char*)state->group_array[i].groupName);
|
||||||
|
|
||||||
|
//remove any potential linebreaks at this point
|
||||||
|
if (state->group_array[i].groupName[len-1] == '\n')
|
||||||
|
{
|
||||||
|
// fprintf(stderr, " ** LEN: %d; ** ", len); //debug
|
||||||
|
state->group_array[i].groupName[len-1] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
fprintf (stderr, "%s ", state->group_array[i].groupName);
|
fprintf (stderr, "%s ", state->group_array[i].groupName);
|
||||||
}
|
}
|
||||||
|
|
||||||
field = strtok(NULL, ",");
|
field = strtok(NULL, ",");
|
||||||
field_count++;
|
field_count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf (stderr, "\n");
|
fprintf (stderr, "\n");
|
||||||
|
|
||||||
i++;
|
i++;
|
||||||
state->group_tally++;
|
state->group_tally++;
|
||||||
|
|
||||||
}
|
}
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
return 0;
|
return 0;
|
||||||
@@ -146,7 +167,8 @@ int csvChanImport(dsd_opts * opts, dsd_state * state) //channel map import
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int csvKeyImport(dsd_opts * opts, dsd_state * state) //multi-key support
|
//Decimal Variant of Key Import
|
||||||
|
int csvKeyImportDec(dsd_opts * opts, dsd_state * state) //multi-key support
|
||||||
{
|
{
|
||||||
char filename[1024] = "filename.csv";
|
char filename[1024] = "filename.csv";
|
||||||
sprintf (filename, "%s", opts->key_in_file);
|
sprintf (filename, "%s", opts->key_in_file);
|
||||||
@@ -210,3 +232,69 @@ int csvKeyImport(dsd_opts * opts, dsd_state * state) //multi-key support
|
|||||||
fclose(fp);
|
fclose(fp);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Hex Variant of Key Import
|
||||||
|
int csvKeyImportHex(dsd_opts * opts, dsd_state * state) //key import for hex keys
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
|
||||||
|
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, "%llX", &keynumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (field_count == 1)
|
||||||
|
{
|
||||||
|
sscanf (field, "%llX", &state->rkey_array[keynumber]);
|
||||||
|
}
|
||||||
|
|
||||||
|
//this could also theoretically nuke other keys that are at the same offset
|
||||||
|
if (field_count == 2)
|
||||||
|
{
|
||||||
|
sscanf (field, "%llX", &state->rkey_array[keynumber+0x101]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (field_count == 3)
|
||||||
|
{
|
||||||
|
sscanf (field, "%llX", &state->rkey_array[keynumber+0x201]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (field_count == 4)
|
||||||
|
{
|
||||||
|
sscanf (field, "%llX", &state->rkey_array[keynumber+0x301]);
|
||||||
|
}
|
||||||
|
|
||||||
|
field = strtok(NULL, ",");
|
||||||
|
field_count++;
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf (stderr, "Key [%04llX] [%016llX]", keynumber, state->rkey_array[keynumber]);
|
||||||
|
|
||||||
|
//if longer key is loaded (or clash with the 0x101, 0x201, 0x301 offset, then print the full key listing)
|
||||||
|
if ( (state->rkey_array[keynumber+0x101] != 0) || (state->rkey_array[keynumber+0x201] != 0) || (state->rkey_array[keynumber+0x301] != 0) )
|
||||||
|
fprintf (stderr, " [%016llX] [%016llX] [%016llX]", state->rkey_array[keynumber+0x101], state->rkey_array[keynumber+0x201], state->rkey_array[keynumber+0x301]);
|
||||||
|
fprintf (stderr, "\n");
|
||||||
|
|
||||||
|
}
|
||||||
|
fclose(fp);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|||||||
7
src/dsd_ks.c
Normal file
7
src/dsd_ks.c
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
/*-------------------------------------------------------------------------------
|
||||||
|
* dsd_ks.c
|
||||||
|
* Placeholder File 6 -- This file is for temporary code storage
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*-----------------------------------------------------------------------------*/
|
||||||
5888
src/dsd_main.c
5888
src/dsd_main.c
File diff suppressed because it is too large
Load Diff
1993
src/dsd_mbe.c
1993
src/dsd_mbe.c
File diff suppressed because it is too large
Load Diff
179
src/dsd_mbe2.c
Normal file
179
src/dsd_mbe2.c
Normal file
@@ -0,0 +1,179 @@
|
|||||||
|
/*-------------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* TODO: Fill me in'
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* LWVMOBILE
|
||||||
|
* 2023-07 DSD-FME Florida Man Edition
|
||||||
|
*-----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
//new and simplified/organized ambe and imbe handling
|
||||||
|
//moving all audio handling and decryption to seperate files for simplicity (eventually)
|
||||||
|
|
||||||
|
#include "dsd.h"
|
||||||
|
|
||||||
|
//the initial functions will ONLY return demodulated ambe or imbe frames, THAT'S IT!
|
||||||
|
//decryption and audio handling etc will be handled at a different area
|
||||||
|
|
||||||
|
//using soft_demod will also allow for not compiling mbelib and also using a DVstick in the future
|
||||||
|
|
||||||
|
//P25p1 IMBE 7200 or AMBE+2 EFR
|
||||||
|
void soft_demod_imbe7200 (dsd_state * state, char imbe_fr7200[8][23], char imbe_d[88])
|
||||||
|
{
|
||||||
|
state->errs = mbe_eccImbe7200x4400C0 (imbe_fr7200);
|
||||||
|
state->errs2 = state->errs;
|
||||||
|
mbe_demodulateImbe7200x4400Data (imbe_fr7200);
|
||||||
|
state->errs2 += mbe_eccImbe7200x4400Data (imbe_fr7200, imbe_d);
|
||||||
|
state->debug_audio_errors += state->errs2;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//ProVoice IMBE 7100
|
||||||
|
void soft_demod_imbe7100 (dsd_state * state, char imbe_fr7100[7][24], char imbe_d[88])
|
||||||
|
{
|
||||||
|
state->errs = mbe_eccImbe7100x4400C0 (imbe_fr7100);
|
||||||
|
state->errs2 = state->errs;
|
||||||
|
mbe_demodulateImbe7100x4400Data (imbe_fr7100);
|
||||||
|
state->errs2 += mbe_eccImbe7100x4400Data (imbe_fr7100, imbe_d);
|
||||||
|
state->debug_audio_errors += state->errs2;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//AMBE+2 EHR
|
||||||
|
void soft_demod_ambe2_ehr(dsd_state * state, char ambe2_ehr[4][24], char ambe_d[49])
|
||||||
|
{
|
||||||
|
state->errs = mbe_eccAmbe3600x2450C0 (ambe2_ehr);
|
||||||
|
state->errs2 = state->errs;
|
||||||
|
mbe_demodulateAmbe3600x2450Data (ambe2_ehr);
|
||||||
|
state->errs2 += mbe_eccAmbe3600x2450Data (ambe2_ehr, ambe_d);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//AMBE One Shot (DSTAR)
|
||||||
|
void soft_demod_ambe_dstar(dsd_opts * opts, dsd_state * state, char ambe_fr[4][24], char ambe_d[49])
|
||||||
|
{
|
||||||
|
mbe_processAmbe3600x2400Framef (state->audio_out_temp_buf, &state->errs, &state->errs2,
|
||||||
|
state->err_str, ambe_fr, ambe_d, state->cur_mp, state->prev_mp, state->prev_mp_enhanced, opts->uvquality);
|
||||||
|
if (opts->floating_point == 1)
|
||||||
|
memcpy (state->f_l, state->audio_out_temp_buf, sizeof(state->f_l));
|
||||||
|
else processAudio(opts, state);
|
||||||
|
}
|
||||||
|
|
||||||
|
//AMBE+2 One Shot (X2-TDMA)
|
||||||
|
void soft_demod_ambe_x2(dsd_opts * opts, dsd_state * state, char ambe_fr[4][24], char ambe_d[49])
|
||||||
|
{
|
||||||
|
mbe_processAmbe3600x2450Framef (state->audio_out_temp_buf, &state->errs, &state->errs2,
|
||||||
|
state->err_str, ambe_fr, ambe_d, state->cur_mp, state->prev_mp, state->prev_mp_enhanced, opts->uvquality);
|
||||||
|
if (opts->floating_point == 1)
|
||||||
|
memcpy (state->f_l, state->audio_out_temp_buf, sizeof(state->f_l));
|
||||||
|
else processAudio(opts, state);
|
||||||
|
}
|
||||||
|
|
||||||
|
void soft_mbe (dsd_opts * opts, dsd_state * state, char imbe_fr[8][23], char ambe_fr[4][24], char imbe7100_fr[7][24])
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
char ambe_d[49];
|
||||||
|
char imbe_d[88];
|
||||||
|
int slot = state->currentslot;
|
||||||
|
memset (ambe_d, 0, sizeof(ambe_d));
|
||||||
|
memset (imbe_d, 0, sizeof(imbe_d));
|
||||||
|
|
||||||
|
UNUSED(i);
|
||||||
|
|
||||||
|
//P25p1, YSF FR, NXDN EFR
|
||||||
|
if (state->synctype == 0 || state->synctype == 1)
|
||||||
|
{
|
||||||
|
soft_demod_imbe7200(state, imbe_fr, imbe_d);
|
||||||
|
//handle decryption here
|
||||||
|
//print IMBE frame
|
||||||
|
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);
|
||||||
|
//send to playback here
|
||||||
|
}
|
||||||
|
|
||||||
|
//ProVoice
|
||||||
|
else if (state->synctype == 14 || state->synctype == 15)
|
||||||
|
{
|
||||||
|
soft_demod_imbe7100(state, imbe7100_fr, imbe_d);
|
||||||
|
//nothing to do
|
||||||
|
|
||||||
|
//convert to 7200
|
||||||
|
mbe_convertImbe7100to7200(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);
|
||||||
|
//send to playback here
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//D-STAR AMBE
|
||||||
|
else if (state->synctype == 6 || state->synctype == 7)
|
||||||
|
{
|
||||||
|
soft_demod_ambe_dstar(opts, state, ambe_fr, ambe_d);
|
||||||
|
if(opts->payload == 1)
|
||||||
|
PrintAMBEData (opts, state, ambe_d);
|
||||||
|
|
||||||
|
if (opts->floating_point == 0 && opts->pulse_digi_out_channels == 1)
|
||||||
|
playSynthesizedVoiceMS(opts, state);
|
||||||
|
if (opts->floating_point == 1 && opts->pulse_digi_out_channels == 1)
|
||||||
|
playSynthesizedVoiceFM(opts, state);
|
||||||
|
if (opts->floating_point == 0 && opts->pulse_digi_out_channels == 2)
|
||||||
|
playSynthesizedVoiceSS(opts, state);
|
||||||
|
if (opts->floating_point == 1 && opts->pulse_digi_out_channels == 2)
|
||||||
|
playSynthesizedVoiceFS(opts, state);
|
||||||
|
|
||||||
|
if (opts->wav_out_f != NULL && opts->dmr_stereo_wav == 1)
|
||||||
|
writeSynthesizedVoice (opts, state);
|
||||||
|
|
||||||
|
//single wav file handled by playSynthesizedVoiceMS
|
||||||
|
|
||||||
|
if (opts->mbe_out_f != NULL)
|
||||||
|
saveAmbe2450Data (opts, state, ambe_d);
|
||||||
|
}
|
||||||
|
|
||||||
|
//X2-TDMA AMBE
|
||||||
|
else if (state->synctype >= 2 && state->synctype <= 5)
|
||||||
|
{
|
||||||
|
soft_demod_ambe_x2(opts, state, ambe_fr, ambe_d);
|
||||||
|
if(opts->payload == 1)
|
||||||
|
PrintAMBEData (opts, state, ambe_d);
|
||||||
|
|
||||||
|
if (opts->floating_point == 0 && opts->pulse_digi_out_channels == 1)
|
||||||
|
playSynthesizedVoiceMS(opts, state);
|
||||||
|
if (opts->floating_point == 1 && opts->pulse_digi_out_channels == 1)
|
||||||
|
playSynthesizedVoiceFM(opts, state);
|
||||||
|
if (opts->floating_point == 0 && opts->pulse_digi_out_channels == 2)
|
||||||
|
playSynthesizedVoiceSS(opts, state);
|
||||||
|
if (opts->floating_point == 1 && opts->pulse_digi_out_channels == 2)
|
||||||
|
playSynthesizedVoiceFS(opts, state);
|
||||||
|
|
||||||
|
if (opts->wav_out_f != NULL)
|
||||||
|
writeSynthesizedVoice (opts, state);
|
||||||
|
|
||||||
|
if (opts->mbe_out_f != NULL)
|
||||||
|
saveAmbe2450Data (opts, state, ambe_d);
|
||||||
|
}
|
||||||
|
|
||||||
|
//AMBE+2 EHR (NXDN, DMR, P25p2, YSF VD/1)
|
||||||
|
else
|
||||||
|
{
|
||||||
|
soft_demod_ambe2_ehr (state, ambe_fr, ambe_d);
|
||||||
|
//decrypt here
|
||||||
|
if(opts->payload == 1)
|
||||||
|
PrintAMBEData (opts, state, ambe_d);
|
||||||
|
//make left or right channel decision
|
||||||
|
if (slot == 0)
|
||||||
|
{
|
||||||
|
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 (slot == 1)
|
||||||
|
{
|
||||||
|
mbe_processAmbe2450Dataf (state->audio_out_temp_bufR, &state->errsR, &state->errs2R, state->err_strR,
|
||||||
|
ambe_d, state->cur_mp2, state->prev_mp2, state->prev_mp_enhanced2, opts->uvquality);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
275
src/dsd_misc.c
Normal file
275
src/dsd_misc.c
Normal file
@@ -0,0 +1,275 @@
|
|||||||
|
/*-------------------------------------------------------------------------------
|
||||||
|
* dsd_misc.c
|
||||||
|
* Misc Code that needs to be reorganized and sorted out
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*-----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#include "dsd.h"
|
||||||
|
|
||||||
|
//audio filter stuff sourced from: https://github.com/NedSimao/FilteringLibrary
|
||||||
|
//no license / information provided in source code
|
||||||
|
#define PI 3.141592653
|
||||||
|
|
||||||
|
//do we need this for test input sthit?
|
||||||
|
// #define PLOT_POINTS 100
|
||||||
|
// #define SAMPLE_TIME_S 0.001
|
||||||
|
// #define CUTOFFFREQ_HZ 50
|
||||||
|
// #define sine_freq 40
|
||||||
|
// #define sine_freq_1 500
|
||||||
|
// #define HFC 50
|
||||||
|
// #define LFC 100
|
||||||
|
|
||||||
|
void LPFilter_Init(LPFilter *filter, float cutoffFreqHz, float sampleTimeS)
|
||||||
|
{
|
||||||
|
|
||||||
|
float RC=0.0;
|
||||||
|
RC=1.0/(2*PI*cutoffFreqHz);
|
||||||
|
filter->coef[0]=sampleTimeS/(sampleTimeS+RC);
|
||||||
|
filter->coef[1]=RC/(sampleTimeS+RC);
|
||||||
|
|
||||||
|
filter->v_out[0]=0.0;
|
||||||
|
filter->v_out[1]=0.0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
float LPFilter_Update(LPFilter *filter, float v_in)
|
||||||
|
{
|
||||||
|
|
||||||
|
filter->v_out[1]=filter->v_out[0];
|
||||||
|
filter->v_out[0]=(filter->coef[0]*v_in) + (filter->coef[1]*filter->v_out[1]);
|
||||||
|
|
||||||
|
return (filter->v_out[0]);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/********************************************************************************************************
|
||||||
|
* HIGH PASS FILTER
|
||||||
|
********************************************************************************************************/
|
||||||
|
void HPFilter_Init(HPFilter *filter, float cutoffFreqHz, float sampleTimeS)
|
||||||
|
{
|
||||||
|
|
||||||
|
float RC=0.0;
|
||||||
|
RC=1.0/(2*PI*cutoffFreqHz);
|
||||||
|
|
||||||
|
filter->coef=RC/(sampleTimeS+RC);
|
||||||
|
|
||||||
|
filter->v_in[0]=0.0;
|
||||||
|
filter->v_in[1]=0.0;
|
||||||
|
|
||||||
|
filter->v_out[0]=0.0;
|
||||||
|
filter->v_out[1]=0.0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
float HPFilter_Update(HPFilter *filter, float v_in)
|
||||||
|
{
|
||||||
|
|
||||||
|
filter->v_in[1]=filter->v_in[0];
|
||||||
|
filter->v_in[0]=v_in;
|
||||||
|
|
||||||
|
filter->v_out[1]=filter->v_out[0];
|
||||||
|
filter->v_out[0]=filter->coef * (filter->v_in[0] - filter->v_in[1]+filter->v_out[1]);
|
||||||
|
|
||||||
|
return (filter->v_out[0]);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/********************************************************************************************************
|
||||||
|
* BAND PASS FILTER
|
||||||
|
********************************************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
void PBFilter_Init(PBFilter *filter, float HPF_cutoffFreqHz, float LPF_cutoffFreqHz, float sampleTimeS)
|
||||||
|
{
|
||||||
|
|
||||||
|
LPFilter_Init(&filter->lpf, LPF_cutoffFreqHz, sampleTimeS);
|
||||||
|
HPFilter_Init(&filter->hpf, HPF_cutoffFreqHz, sampleTimeS);
|
||||||
|
|
||||||
|
filter->out_in=0.0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
float PBFilter_Update(PBFilter *filter, float v_in)
|
||||||
|
{
|
||||||
|
|
||||||
|
filter->out_in=HPFilter_Update(&filter->hpf, v_in);
|
||||||
|
|
||||||
|
filter->out_in=LPFilter_Update(&filter->lpf, filter->out_in);
|
||||||
|
|
||||||
|
return (filter->out_in);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/********************************************************************************************************
|
||||||
|
* NOTCH FILTER
|
||||||
|
********************************************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
void NOTCHFilter_Init(NOTCHFilter *filter, float centerFreqHz, float notchWidthHz, float sampleTimeS)
|
||||||
|
{
|
||||||
|
|
||||||
|
//filter frequency to angular (rad/s)
|
||||||
|
float w0_rps=2.0 * PI *centerFreqHz;
|
||||||
|
float ww_rps=2.0 * PI *notchWidthHz;
|
||||||
|
|
||||||
|
//pre warp center frequency
|
||||||
|
float w0_pw_rps=(2.0/sampleTimeS) * tanf(0.5 * w0_rps * sampleTimeS);
|
||||||
|
|
||||||
|
//computing filter coefficients
|
||||||
|
|
||||||
|
filter->alpha=4.0 + w0_rps*w0_pw_rps*sampleTimeS*sampleTimeS;
|
||||||
|
filter->beta=2.0*ww_rps*sampleTimeS;
|
||||||
|
|
||||||
|
//clearing input and output buffers
|
||||||
|
|
||||||
|
for (uint8_t n=0; n<3; n++)
|
||||||
|
{
|
||||||
|
filter->vin[n]=0;
|
||||||
|
filter->vout[n]=0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
float NOTCHFilter_Update(NOTCHFilter *filter, float vin)
|
||||||
|
{
|
||||||
|
|
||||||
|
//shifting samples
|
||||||
|
filter->vin[2]=filter->vin[1];
|
||||||
|
filter->vin[1]=filter->vin[0];
|
||||||
|
|
||||||
|
filter->vout[2]=filter->vout[1];
|
||||||
|
filter->vout[1]=filter->vout[0];
|
||||||
|
|
||||||
|
filter->vin[0]=vin;
|
||||||
|
|
||||||
|
//compute new output
|
||||||
|
filter->vout[0]=(filter->alpha*filter->vin[0] + 2.0 *(filter->alpha -8.0)*filter->vin[1] + filter->alpha*filter->vin[2]
|
||||||
|
-(2.0f*(filter->alpha-8.0)*filter->vout[1]+(filter->alpha-filter->beta)*filter->vout[2]))/(filter->alpha+filter->beta);
|
||||||
|
|
||||||
|
|
||||||
|
return (filter->vout[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void init_audio_filters (dsd_state * state)
|
||||||
|
{
|
||||||
|
//still not sure if this is even correct or not, but 48k sounds good now
|
||||||
|
LPFilter_Init(&state->RCFilter, 960, (float)1/(float)48000);
|
||||||
|
HPFilter_Init(&state->HRCFilter, 960, (float)1/(float)48000);
|
||||||
|
|
||||||
|
//left and right variants for stereo output testing on digital voice samples
|
||||||
|
LPFilter_Init(&state->RCFilterL, 960, (float)1/(float)16000);
|
||||||
|
HPFilter_Init(&state->HRCFilterL, 960, (float)1/(float)16000);
|
||||||
|
LPFilter_Init(&state->RCFilterR, 960, (float)1/(float)16000);
|
||||||
|
HPFilter_Init(&state->HRCFilterR, 960, (float)1/(float)16000);
|
||||||
|
|
||||||
|
//PBFilter_Init(PBFilter *filter, float HPF_cutoffFreqHz, float LPF_cutoffFreqHz, float sampleTimeS);
|
||||||
|
//NOTCHFilter_Init(NOTCHFilter *filter, float centerFreqHz, float notchWidthHz, float sampleTimeS);
|
||||||
|
|
||||||
|
//NOTE: PBFilter_init also inits a LPF and HPF, but on another set of filters, might be worth
|
||||||
|
//testing just using the PBFilter by itself and see how it does without the hpf used
|
||||||
|
|
||||||
|
//passband filter working (seems to be), notch filter unsure which values to use, doesn't have any appreciable affect when used as is
|
||||||
|
PBFilter_Init(&state->PBF, 8000, 12000, (float)1/(float)1536000); //RTL Sampling at 1536000 S/s.
|
||||||
|
NOTCHFilter_Init(&state->NF, 1000, 4000, (float)1/(float)1536000);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//FUNCTIONS for handing use of above filters
|
||||||
|
|
||||||
|
//lpf
|
||||||
|
void lpf(dsd_state * state, short * input, int len)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < len; i++)
|
||||||
|
{
|
||||||
|
// fprintf (stderr, "\n in: %05d", input[i]);
|
||||||
|
input[i] = LPFilter_Update(&state->RCFilter, input[i]);
|
||||||
|
// fprintf (stderr, "\n out: %05d", input[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//hpf
|
||||||
|
void hpf(dsd_state * state, short * input, int len)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < len; i++)
|
||||||
|
{
|
||||||
|
// fprintf (stderr, "\n in: %05d", input[i]);
|
||||||
|
input[i] = HPFilter_Update(&state->HRCFilter, input[i]);
|
||||||
|
// fprintf (stderr, "\n out: %05d", input[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//hpf digital left
|
||||||
|
void hpf_dL(dsd_state * state, short * input, int len)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < len; i++)
|
||||||
|
{
|
||||||
|
// fprintf (stderr, "\n in: %05d", input[i]);
|
||||||
|
input[i] = HPFilter_Update(&state->HRCFilterL, input[i]);
|
||||||
|
// fprintf (stderr, "\n out: %05d", input[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//hpf digital right
|
||||||
|
void hpf_dR(dsd_state * state, short * input, int len)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < len; i++)
|
||||||
|
{
|
||||||
|
// fprintf (stderr, "\n in: %05d", input[i]);
|
||||||
|
input[i] = HPFilter_Update(&state->HRCFilterR, input[i]);
|
||||||
|
// fprintf (stderr, "\n out: %05d", input[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//nf
|
||||||
|
void nf(dsd_state * state, short * input, int len)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < len; i++)
|
||||||
|
{
|
||||||
|
// fprintf (stderr, "\n in: %05d", input[i]);
|
||||||
|
input[i] = NOTCHFilter_Update(&state->NF, input[i]);
|
||||||
|
// fprintf (stderr, "\n out: %05d", input[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//pbf
|
||||||
|
void pbf(dsd_state * state, short * input, int len)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < len; i++)
|
||||||
|
{
|
||||||
|
// fprintf (stderr, "\n in: %05d", input[i]);
|
||||||
|
input[i] = PBFilter_Update(&state->PBF, input[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Generic RMS function derived from RTL_FM (RTL_SDR) RMS code (doesnt' really work correctly outside of RTL)
|
||||||
|
long int raw_rms(int16_t *samples, int len, int step) //use samplespersymbol as len
|
||||||
|
{
|
||||||
|
|
||||||
|
int i;
|
||||||
|
long int rms;
|
||||||
|
long p, t, s;
|
||||||
|
double dc, err;
|
||||||
|
|
||||||
|
p = t = 0L;
|
||||||
|
for (i=0; i<len; i+=step) {
|
||||||
|
s = (long)samples[i];
|
||||||
|
t += s;
|
||||||
|
p += s * s;
|
||||||
|
}
|
||||||
|
/* correct for dc offset in squares */
|
||||||
|
dc = (double)(t*step) / (double)len;
|
||||||
|
err = t * 2 * dc - dc * dc * len;
|
||||||
|
|
||||||
|
rms = (long int)sqrt((p-err) / len);
|
||||||
|
if (rms < 0) rms = 150;
|
||||||
|
return rms;
|
||||||
|
}
|
||||||
3371
src/dsd_ncurses.c
3371
src/dsd_ncurses.c
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user