-
Notifications
You must be signed in to change notification settings - Fork 61
/
nxdnmessage.cpp
315 lines (287 loc) · 9.77 KB
/
nxdnmessage.cpp
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
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2016 Edouard Griffiths, F4EXB. //
// //
// 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 as version 3 of the License, or //
// //
// 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 V3 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/>. //
///////////////////////////////////////////////////////////////////////////////////
#include <string.h>
#include "nxdnmessage.h"
namespace DSDcc
{
const unsigned char Message::NXDN_MESSAGE_TYPE_VCALL = 0x01U;
const unsigned char Message::NXDN_MESSAGE_TYPE_VCALL_IV = 0x03U;
const unsigned char Message::NXDN_MESSAGE_TYPE_DCALL_HDR = 0x09U;
const unsigned char Message::NXDN_MESSAGE_TYPE_DCALL_DATA = 0x0BU;
const unsigned char Message::NXDN_MESSAGE_TYPE_DCALL_ACK = 0x0CU;
const unsigned char Message::NXDN_MESSAGE_TYPE_TX_REL = 0x08U;
const unsigned char Message::NXDN_MESSAGE_TYPE_HEAD_DLY = 0x0FU;
const unsigned char Message::NXDN_MESSAGE_TYPE_SDCALL_REQ_HDR = 0x38U;
const unsigned char Message::NXDN_MESSAGE_TYPE_SDCALL_REQ_DATA = 0x39U;
const unsigned char Message::NXDN_MESSAGE_TYPE_SDCALL_RESP = 0x3BU;
const unsigned char Message::NXDN_MESSAGE_TYPE_SDCALL_IV = 0x3AU;
const unsigned char Message::NXDN_MESSAGE_TYPE_STAT_INQ_REQ = 0x30U;
const unsigned char Message::NXDN_MESSAGE_TYPE_STAT_INQ_RESP = 0x31U;
const unsigned char Message::NXDN_MESSAGE_TYPE_STAT_REQ = 0x32U;
const unsigned char Message::NXDN_MESSAGE_TYPE_STAT_RESP = 0x33U;
const unsigned char Message::NXDN_MESSAGE_TYPE_REM_CON_REQ = 0x34U;
const unsigned char Message::NXDN_MESSAGE_TYPE_REM_CON_RESP = 0x35U;
const unsigned char Message::NXDN_MESSAGE_TYPE_IDLE = 0x10U;
const unsigned char Message::NXDN_MESSAGE_TYPE_AUTH_INQ_REQ = 0x28U;
const unsigned char Message::NXDN_MESSAGE_TYPE_AUTH_INQ_RESP = 0x29U;
const unsigned char Message::NXDN_MESSAGE_TYPE_PROP_FORM = 0x3FU;
const unsigned char Message::NXDN_MESSAGE_TYPE_VCALL_ASSGN = 0x04U;
const unsigned char Message::NXDN_MESSAGE_TYPE_SRV_INFO = 0x19U;
const unsigned char Message::NXDN_MESSAGE_TYPE_SITE_INFO = 0x18U;
const unsigned char Message::NXDN_MESSAGE_TYPE_ADJ_SITE_INFO = 0x1BU;
const unsigned char Message::NXDN_MESSAGE_TYPE_GRP_REG_REQ_RESP= 0x24U;
const unsigned char Message::NXDN_MESSAGE_TYPE_VCALL_REQ = 0x01U;
const unsigned char Message::NXDN_MESSAGE_TYPE_VCALL_RESP = 0x01U;
const unsigned char Message::NXDN_MESSAGE_TYPE_VCALL_REC_REQ = 0X02U;
const unsigned char Message::NXDN_MESSAGE_TYPE_VCALL_REC_RESP = 0X02U;
const unsigned char Message::NXDN_MESSAGE_TYPE_VCALL_CONN_REQ = 0X03U;
const unsigned char Message::NXDN_MESSAGE_TYPE_VCALL_CONN_RESP = 0X03U;
const unsigned char Message::NXDN_MESSAGE_TYPE_VCALL_ASSGN_DUP = 0X05U;
void Message::reset()
{
memset(m_data, 0, 22);
}
void Message::setMessageIndex(unsigned int index)
{
if (index < 2) {
m_shift = index*9;
}
}
void Message::setFromSACCH(int index, const unsigned char *data)
{
if (index == 0)
{
m_data[0] = data[0];
m_data[1] = data[1];
m_data[2] = data[2];
}
else if (index == 1)
{
m_data[2] = (m_data[2] & 0xC0) + (data[0]>>2);
m_data[3] = ((data[0]&0x03)<<6) + (data[1]>>2);
m_data[4] = ((data[1]&0x03)<<6) + (data[2]>>2);
}
else if (index == 2)
{
m_data[4] = (m_data[4] & 0xF0) + (data[0]>>4);
m_data[5] = ((data[0]&0x0F)<<4) + (data[1]>>4);
m_data[6] = ((data[1]&0x0F)<<4) + (data[2]>>4);
}
else if (index == 3)
{
m_data[6] = (m_data[6] & 0xFC) + (data[0]>>6);
m_data[7] = ((data[0]&0x3F)<<2) + (data[1]>>6);
m_data[8] = ((data[1]&0x3F)<<2) + (data[2]>>6);
}
m_shift = 0; // reset dual index
}
void Message::setFromFACCH1(const unsigned char *data)
{
memcpy(m_data, data, 10);
m_shift = 0; // reset dual index
}
void Message::setFromFACCH2(const unsigned char *data)
{
memcpy(m_data, data, 22);
m_shift = 0; // reset dual index
}
void Message::setFromCAC(const unsigned char *data)
{
memcpy(m_data, data, 18);
m_shift = 0; // reset dual index
}
void Message::setFromCACShort(const unsigned char *data)
{
memcpy(m_data, data, 12);
m_shift = 0; // reset dual index
}
void Message::setFromCACLong(const unsigned char *data)
{
memcpy(m_data, data, 16);
m_shift = 0; // reset dual index
}
bool Message::hasCallDetails() const
{
bool ret;
switch(getMessageType())
{
case NXDN_MESSAGE_TYPE_VCALL:
case NXDN_MESSAGE_TYPE_DCALL_HDR:
case NXDN_MESSAGE_TYPE_DCALL_ACK:
case NXDN_MESSAGE_TYPE_TX_REL:
case NXDN_MESSAGE_TYPE_HEAD_DLY:
case NXDN_MESSAGE_TYPE_SDCALL_REQ_HDR:
case NXDN_MESSAGE_TYPE_SDCALL_RESP:
case NXDN_MESSAGE_TYPE_STAT_INQ_REQ:
case NXDN_MESSAGE_TYPE_STAT_INQ_RESP:
case NXDN_MESSAGE_TYPE_STAT_REQ:
case NXDN_MESSAGE_TYPE_STAT_RESP:
case NXDN_MESSAGE_TYPE_REM_CON_REQ:
case NXDN_MESSAGE_TYPE_REM_CON_RESP:
case NXDN_MESSAGE_TYPE_AUTH_INQ_REQ: // group indicator missing
case NXDN_MESSAGE_TYPE_AUTH_INQ_RESP: // group indicator missing
ret = true;
break;
default:
ret = false;
break;
}
return ret;
}
bool Message::hasGroupCallInfo() const
{
bool ret;
switch(getMessageType())
{
case NXDN_MESSAGE_TYPE_VCALL:
case NXDN_MESSAGE_TYPE_DCALL_HDR:
case NXDN_MESSAGE_TYPE_DCALL_ACK:
case NXDN_MESSAGE_TYPE_TX_REL:
case NXDN_MESSAGE_TYPE_HEAD_DLY:
case NXDN_MESSAGE_TYPE_SDCALL_REQ_HDR:
case NXDN_MESSAGE_TYPE_SDCALL_RESP:
case NXDN_MESSAGE_TYPE_STAT_INQ_REQ:
case NXDN_MESSAGE_TYPE_STAT_INQ_RESP:
case NXDN_MESSAGE_TYPE_STAT_REQ:
case NXDN_MESSAGE_TYPE_STAT_RESP:
case NXDN_MESSAGE_TYPE_REM_CON_REQ:
case NXDN_MESSAGE_TYPE_REM_CON_RESP:
ret = true;
break;
default:
ret = false;
break;
}
return ret;
}
unsigned char Message::getMessageType() const
{
return m_data[0U+m_shift] & 0x3FU;
}
bool Message::getSourceUnitId(unsigned short& id) const
{
if (hasCallDetails())
{
id = (m_data[3U+m_shift] << 8) | m_data[4U+m_shift];
return true;
}
else
{
return false;
}
}
bool Message::getDestinationGroupId(unsigned short& id) const
{
if (hasCallDetails())
{
id = (m_data[5U+m_shift] << 8) | m_data[6U+m_shift];
return true;
}
else
{
return false;
}
}
bool Message::isGroupCall(bool& sw) const
{
if (hasGroupCallInfo())
{
sw = (m_data[2U+m_shift] & 0x80U) != 0x80U;
return true;
}
else
{
return false;
}
}
bool Message::getLocationId(unsigned int& id) const
{
bool ret;
switch(getMessageType())
{
case NXDN_MESSAGE_TYPE_SITE_INFO:
id = (m_data[1U+m_shift]<<16) | (m_data[2U+m_shift]<<8) | m_data[3U+m_shift];
ret = true;
break;
case NXDN_MESSAGE_TYPE_SRV_INFO:
id = (m_data[1U+m_shift]<<16) | (m_data[2U+m_shift]<<8) | m_data[3U+m_shift];
ret = true;
break;
default:
ret = false;
break;
}
return ret;
}
bool Message::getServiceInformation(unsigned short& sibits) const
{
bool ret;
switch(getMessageType())
{
case NXDN_MESSAGE_TYPE_SITE_INFO:
sibits = (m_data[6U+m_shift]<<8) | m_data[7U+m_shift];
ret = true;
break;
case NXDN_MESSAGE_TYPE_SRV_INFO:
sibits = (m_data[4U+m_shift]<<8) | m_data[5U+m_shift];
ret = true;
break;
default:
ret = false;
break;
}
return ret;
}
bool Message::getAdjacentSitesInformation(AdjacentSiteInformation *adjacentSites, int nbSitesToGet) const
{
if (getMessageType() == NXDN_MESSAGE_TYPE_ADJ_SITE_INFO)
{
for (int i=0; i<nbSitesToGet; i++)
{
unsigned int siteIndex = (m_data[4U+m_shift+5*i]>>2) & 0xF;
adjacentSites[siteIndex].m_siteNumber = siteIndex;
adjacentSites[siteIndex].m_channelNumber = m_data[5U+m_shift+5*i] + ((m_data[4U+m_shift+5*i]&0x3)<<8);
adjacentSites[siteIndex].m_locationId = (m_data[1U+m_shift+5*i]<<16) + (m_data[2U+m_shift+5*i]<<8) + m_data[3U+m_shift+5*i];
}
return true;
} else{
return false;
}
}
bool Message::isFullRate(bool& fullRate) const
{
bool ret;
switch(getMessageType())
{
case NXDN_MESSAGE_TYPE_VCALL:
// case NXDN_MESSAGE_TYPE_VCALL_REQ: same value as above
// case NXDN_MESSAGE_TYPE_VCALL_RESP: same value as above
case NXDN_MESSAGE_TYPE_VCALL_REC_REQ:
// case NXDN_MESSAGE_TYPE_VCALL_REC_RESP: same value as above
case NXDN_MESSAGE_TYPE_VCALL_CONN_REQ:
// case NXDN_MESSAGE_TYPE_VCALL_CONN_RESP: same value as above
case NXDN_MESSAGE_TYPE_VCALL_ASSGN:
case NXDN_MESSAGE_TYPE_VCALL_ASSGN_DUP:
fullRate = m_data[2U+m_shift] & 1;
ret = true;
break;
default:
ret = false;
break;
}
return ret;
}
} // namespace