-
Notifications
You must be signed in to change notification settings - Fork 240
/
DMRNetworkConfigurationMonitor.java
436 lines (389 loc) · 16.1 KB
/
DMRNetworkConfigurationMonitor.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
/*
* *****************************************************************************
* Copyright (C) 2014-2024 Dennis Sheirer
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
* ****************************************************************************
*/
package io.github.dsheirer.module.decode.dmr;
import io.github.dsheirer.controller.channel.Channel;
import io.github.dsheirer.identifier.site.SiteIdentifier;
import io.github.dsheirer.module.decode.dmr.channel.DMRChannel;
import io.github.dsheirer.module.decode.dmr.identifier.DMRNetwork;
import io.github.dsheirer.module.decode.dmr.identifier.DMRSite;
import io.github.dsheirer.module.decode.dmr.message.DMRMessage;
import io.github.dsheirer.module.decode.dmr.message.data.DataMessage;
import io.github.dsheirer.module.decode.dmr.message.data.csbk.CSBKMessage;
import io.github.dsheirer.module.decode.dmr.message.data.csbk.hytera.HyteraAdjacentSiteInformation;
import io.github.dsheirer.module.decode.dmr.message.data.csbk.hytera.HyteraAnnouncement;
import io.github.dsheirer.module.decode.dmr.message.data.csbk.motorola.CapacityMaxAloha;
import io.github.dsheirer.module.decode.dmr.message.data.csbk.motorola.ConnectPlusNeighborReport;
import io.github.dsheirer.module.decode.dmr.message.data.csbk.motorola.ConnectPlusVoiceChannelUser;
import io.github.dsheirer.module.decode.dmr.message.data.csbk.standard.Aloha;
import io.github.dsheirer.module.decode.dmr.message.data.csbk.standard.announcement.AdjacentSiteInformation;
import io.github.dsheirer.module.decode.dmr.message.data.lc.LCMessage;
import io.github.dsheirer.module.decode.dmr.message.data.lc.shorty.ConnectPlusControlChannel;
import io.github.dsheirer.module.decode.dmr.message.data.lc.shorty.ConnectPlusTrafficChannel;
import io.github.dsheirer.module.decode.dmr.message.data.lc.shorty.ControlChannelSystemParameters;
import io.github.dsheirer.module.decode.dmr.message.data.lc.shorty.TrafficChannelSystemParameters;
import io.github.dsheirer.module.decode.dmr.message.type.Model;
import io.github.dsheirer.module.decode.dmr.message.type.SystemIdentityCode;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Tracks the network configuration details of a DMR network from the broadcast messages
*/
public class DMRNetworkConfigurationMonitor
{
private final static Logger mLog = LoggerFactory.getLogger(DMRNetworkConfigurationMonitor.class);
private static final String BRAND_HYTERA = "Hytera";
private static final String BRAND_MOTOROLA_CAPACITY_PLUS = "Motorola Capacity+";
private static final String BRAND_MOTOROLA_CONNECT_PLUS = "Motorola Connect+";
private static final String BRAND_STANDARD = "Standard";
private static final String BRAND_TIER_3_TRUNKING = "Tier III Trunking";
private static final String BRAND_MOTOROLA_CAPACITY_MAX_TIER_3_TRUNKING = "Capacity Max Tier III Trunking";
private static final String BRAND_HYTERA_TIER_3_TRUNKING = "Hytera Tier III Trunking";
private static final String MODE_CAPACITY_MAX_OPEN_SYSTEM = "Open System";
private static final String MODE_CAPACITY_MAX_ADVANTAGE = "Advantage";
private static final String CHANNEL_TYPE_CONTROL = "Control";
private static final String CHANNEL_TYPE_TRAFFIC = "Traffic";
private static final String UNKNOWN = "Unknown";
private List<SiteIdentifier> mNeighborSites = new ArrayList<>();
private Map<Integer,AdjacentSiteInformation> mTier3NeighborSites = new HashMap<>();
private Map<Integer,DMRChannel> mObservedChannelMap = new HashMap<>();
private DMRNetwork mDMRNetwork;
private DMRSite mDMRSite;
private Model mTier3Model;
private String mBrand;
private String mMode;
private String mChannelType;
private Integer mColorCodeTS1;
private Integer mColorCodeTS2;
private DMRChannel mCurrentChannel;
private Channel mChannel;
/**
* Constructs an instance
* @param channel configuration
*/
public DMRNetworkConfigurationMonitor(Channel channel)
{
mChannel = channel;
}
/**
* Sets the current channel
*/
public void setCurrentChannel(DMRChannel channel)
{
mCurrentChannel = channel;
}
/**
* Process a DMR message
* @param message to process that has already been checked for isValid()
*/
public void process(DMRMessage message)
{
if(message instanceof CSBKMessage csbk)
{
process(csbk);
}
else if(message instanceof LCMessage lc)
{
process(lc);
}
if(message instanceof DataMessage dm)
{
process(dm);
}
}
/**
* Processes data messages to capture the color code for each timeslot.
* @param dm data message
*/
public void process(DataMessage dm)
{
if(dm.getTimeslot() == 1)
{
mColorCodeTS1 = dm.getSlotType().getColorCode();
}
else if(dm.getTimeslot() == 2)
{
mColorCodeTS2 = dm.getSlotType().getColorCode();
}
}
/**
* Processes link control messages
*/
public void process(LCMessage linkControl)
{
switch(linkControl.getOpcode())
{
case FULL_CAPACITY_MAX_GROUP_VOICE_CHANNEL_USER:
case FULL_CAPACITY_MAX_TALKER_ALIAS:
case FULL_CAPACITY_MAX_TALKER_ALIAS_CONTINUATION:
mBrand = BRAND_MOTOROLA_CAPACITY_MAX_TIER_3_TRUNKING;
break;
case SHORT_CONNECT_PLUS_CONTROL_CHANNEL:
if(linkControl instanceof ConnectPlusControlChannel cpcc)
{
mDMRNetwork = cpcc.getNetwork();
mDMRSite = cpcc.getSite();
mChannelType = CHANNEL_TYPE_CONTROL;
mBrand = BRAND_MOTOROLA_CONNECT_PLUS;
}
break;
case SHORT_CONNECT_PLUS_TRAFFIC_CHANNEL:
if(linkControl instanceof ConnectPlusTrafficChannel cptc)
{
mDMRNetwork = cptc.getNetwork();
mDMRSite = cptc.getSite();
mChannelType = CHANNEL_TYPE_TRAFFIC;
mBrand = BRAND_MOTOROLA_CONNECT_PLUS;
}
break;
case SHORT_STANDARD_CONTROL_CHANNEL_SYSTEM_PARAMETERS:
if(linkControl instanceof ControlChannelSystemParameters cc)
{
SystemIdentityCode sic = cc.getSystemIdentityCode();
mTier3Model = sic.getModel();
mDMRNetwork = sic.getNetwork();
mDMRSite = sic.getSite();
mChannelType = CHANNEL_TYPE_CONTROL;
if(mBrand == null)
{
mBrand = BRAND_TIER_3_TRUNKING;
}
}
break;
case SHORT_STANDARD_TRAFFIC_CHANNEL_SYSTEM_PARAMETERS:
if(linkControl instanceof TrafficChannelSystemParameters tc)
{
SystemIdentityCode sic = tc.getSystemIdentityCode();
mTier3Model = sic.getModel();
mDMRNetwork = sic.getNetwork();
mDMRSite = sic.getSite();
mChannelType = CHANNEL_TYPE_TRAFFIC;
}
if(mBrand == null)
{
mBrand = BRAND_TIER_3_TRUNKING;
}
}
}
/**
* Processes Control Signalling Blocks (CSBK)
*/
public void process(CSBKMessage csbk)
{
switch(csbk.getOpcode())
{
case STANDARD_ALOHA:
if(csbk instanceof Aloha)
{
if(mDMRNetwork == null || mDMRSite == null)
{
SystemIdentityCode sic = ((Aloha)csbk).getSystemIdentityCode();
if(mDMRNetwork == null)
{
mDMRNetwork = sic.getNetwork();
}
if(mDMRSite == null)
{
mDMRSite = sic.getSite();
}
if(mTier3Model == null)
{
mTier3Model = sic.getModel();
}
}
if(mBrand == null)
{
mBrand = BRAND_TIER_3_TRUNKING;
}
}
break;
case STANDARD_ANNOUNCEMENT:
if(csbk instanceof AdjacentSiteInformation neighbor)
{
mTier3NeighborSites.put(neighbor.getNeighborSystemIdentityCode().getSite().getValue(), neighbor);
}
break;
case HYTERA_08_ANNOUNCEMENT:
case HYTERA_68_ANNOUNCEMENT:
if(csbk instanceof HyteraAnnouncement)
{
HyteraAnnouncement ha = (HyteraAnnouncement)csbk;
if(mBrand == null)
{
mBrand = BRAND_HYTERA_TIER_3_TRUNKING;
}
if(mDMRNetwork == null)
{
mDMRNetwork = ha.getSystemIdentityCode().getNetwork();
}
if(mDMRSite == null)
{
mDMRSite = ha.getSystemIdentityCode().getSite();
}
if(mTier3Model == null)
{
mTier3Model = ha.getSystemIdentityCode().getModel();
}
mBrand = BRAND_HYTERA_TIER_3_TRUNKING;
}
if(csbk instanceof HyteraAdjacentSiteInformation)
{
HyteraAdjacentSiteInformation hasi = (HyteraAdjacentSiteInformation)csbk;
int site = hasi.getNeighborSystemIdentityCode().getSite().getValue();
if(!mTier3NeighborSites.containsKey(site))
{
mTier3NeighborSites.put(site, hasi);
}
}
break;
case MOTOROLA_CAPMAX_ALOHA:
if(csbk instanceof CapacityMaxAloha)
{
if(mDMRNetwork == null || mDMRSite == null)
{
SystemIdentityCode sic = ((CapacityMaxAloha)csbk).getSystemIdentityCode();
if(mDMRNetwork == null)
{
mDMRNetwork = sic.getNetwork();
}
if(mDMRSite == null)
{
mDMRSite = sic.getSite();
}
if(mTier3Model == null)
{
mTier3Model = sic.getModel();
}
}
mChannelType = CHANNEL_TYPE_CONTROL;
mBrand = BRAND_MOTOROLA_CAPACITY_MAX_TIER_3_TRUNKING;
}
break;
case MOTOROLA_CAPMAX_CHANNEL_UPDATE_ADVANTAGE_MODE:
mBrand = BRAND_MOTOROLA_CAPACITY_MAX_TIER_3_TRUNKING;
mMode = MODE_CAPACITY_MAX_ADVANTAGE;
break;
case MOTOROLA_CAPMAX_CHANNEL_UPDATE_OPEN_MODE:
mBrand = BRAND_MOTOROLA_CAPACITY_MAX_TIER_3_TRUNKING;
mMode = MODE_CAPACITY_MAX_OPEN_SYSTEM;
break;
case MOTOROLA_CONPLUS_NEIGHBOR_REPORT:
if(mNeighborSites.isEmpty() && csbk instanceof ConnectPlusNeighborReport)
{
ConnectPlusNeighborReport cpnr = (ConnectPlusNeighborReport)csbk;
mNeighborSites.addAll(cpnr.getNeighbors());
}
mBrand = BRAND_MOTOROLA_CONNECT_PLUS;
break;
case MOTOROLA_CONPLUS_VOICE_CHANNEL_USER:
if(csbk instanceof ConnectPlusVoiceChannelUser)
{
DMRChannel channel = ((ConnectPlusVoiceChannelUser)csbk).getChannel();
addDmrChannel(channel);
}
mBrand = BRAND_MOTOROLA_CONNECT_PLUS;
break;
}
}
/**
* Adds the DMR channel to the observed channel map
*/
private void addDmrChannel(DMRChannel dmrChannel)
{
mObservedChannelMap.put(dmrChannel.getValue(), dmrChannel);
}
public String getActivitySummary()
{
StringBuilder sb = new StringBuilder();
sb.append("Activity Summary - Decoder: DMR ");
sb.append("\n\nBrand: ").append((mBrand == null ? BRAND_STANDARD : mBrand));
if(mMode != null)
{
sb.append("\nConfigured Mode: ").append(mMode);
}
sb.append("\nChannel Type: ").append((mChannelType != null) ? mChannelType : UNKNOWN);
sb.append("\nColor Code Timeslot 1: ").append(mColorCodeTS1 != null ? mColorCodeTS1 : UNKNOWN);
sb.append("\nColor Code Timeslot 2: ").append(mColorCodeTS2 != null ? mColorCodeTS2 : UNKNOWN);
if(mDMRNetwork != null)
{
sb.append("\nNetwork: ").append(mDMRNetwork);
}
if(mDMRSite != null)
{
sb.append("\nSite: ").append(mDMRSite);
}
if(mTier3Model != null)
{
sb.append("\nNetwork Model: ").append(mTier3Model);
}
//Observed DMR Channels
if(!mObservedChannelMap.isEmpty())
{
sb.append("\nObserved Logical Slot Numbers (LSN):");
List<Integer> lsns = new ArrayList<>(mObservedChannelMap.keySet());
Collections.sort(lsns);
for(Integer lsn: lsns)
{
DMRChannel channel = mObservedChannelMap.get(lsn);
if(channel != null)
{
sb.append("\n\t").append(channel);
double frequency = channel.getDownlinkFrequency();
if(frequency != 0)
{
frequency /= 1E6d;
}
sb.append(" ").append(frequency).append(" MHz");
}
}
}
if(!mNeighborSites.isEmpty())
{
sb.append("\nNeighbor Sites\n");
for(SiteIdentifier neighbor: mNeighborSites)
{
sb.append("\tNeighbor: ").append(neighbor).append("\n");
}
}
if(!mTier3NeighborSites.isEmpty())
{
sb.append("\nTier III Neighbor Sites\n");
for(Map.Entry<Integer,AdjacentSiteInformation> neighbor: mTier3NeighborSites.entrySet())
{
AdjacentSiteInformation site = neighbor.getValue();
sb.append("\tNeighbor: ").append("Network:").append(site.getNeighborSystemIdentityCode().getNetwork());
sb.append(" Site:").append(site.getNeighborSystemIdentityCode().getSite());
sb.append(" ").append(site.getNeighborSystemIdentityCode().getModel());
DMRChannel channel = site.getNeighborChannel();
sb.append(" ").append(channel);
if(channel.getDownlinkFrequency() > 0)
{
sb.append(" ").append(channel.getDownlinkFrequency());
}
sb.append("\n");
}
}
sb.append("\n\n");
return sb.toString();
}
}