blob: 3bc0db3165ff72d7d02dedfadc8faf37f6c025a5 [file] [log] [blame]
Roman Khassraf2b1ebf12015-08-29 17:43:43 +02001#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3# @file
Piotr Krysika6268a52017-08-23 16:02:19 +02004# @author (C) 2015 by Roman Khassraf <rkhassraf@gmail.com>
Roman Khassraf2b1ebf12015-08-29 17:43:43 +02005# @section LICENSE
6#
7# Gr-gsm is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation; either version 3, or (at your option)
10# any later version.
11#
12# Gr-gsm is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with gr-gsm; see the file COPYING. If not, write to
19# the Free Software Foundation, Inc., 51 Franklin Street,
20# Boston, MA 02110-1301, USA.
21#
22#
23
24from gnuradio import blocks
25from gnuradio import eng_notation
26from gnuradio import gr
27from gnuradio.eng_option import eng_option
28from optparse import OptionParser, OptionGroup
29import collections
30import grgsm
Roman Khassraf262b53d2015-09-13 12:14:26 +020031import pmt
Roman Khassraf2b1ebf12015-08-29 17:43:43 +020032import socket
33
34
Piotr Krysik3e192c42016-02-13 07:31:51 +010035class grgsm_decoder(gr.top_block):
Roman Khassraf2b1ebf12015-08-29 17:43:43 +020036
37 def __init__(self, timeslot=0, subslot=None, chan_mode='BCCH',
38 burst_file=None,
Piotr Krysik231aca72016-07-17 10:44:43 +020039 cfile=None, fc=None, samp_rate=2e6,
Roman Khassraf2b1ebf12015-08-29 17:43:43 +020040 a5=1, a5_kc=None,
Roman Khassraf262b53d2015-09-13 12:14:26 +020041 speech_file=None, speech_codec=None,
Roman Khassrafc0addfb2016-09-27 20:11:42 +020042 enable_voice_boundary_detection=False,
Vasil Velichkov7f259fd2018-05-06 02:13:36 +030043 tch_h_channel=0,
44 multi_rate=0,
Piotr Krysik0679ceb2016-04-29 11:16:22 +020045 verbose=False,
Piotr Krysik231aca72016-07-17 10:44:43 +020046 print_bursts=False, ppm=0):
Roman Khassraf2b1ebf12015-08-29 17:43:43 +020047
Piotr Krysik3e192c42016-02-13 07:31:51 +010048 gr.top_block.__init__(self, "Gr-gsm Decode")
Roman Khassraf2b1ebf12015-08-29 17:43:43 +020049
50 ##################################################
51 # Parameters
52 ##################################################
53 self.timeslot = timeslot
54 self.subslot = subslot
55 self.chan_mode = chan_mode
56 self.burst_file = burst_file
57 self.cfile = cfile
58 self.fc = fc
59 self.samp_rate = samp_rate
Roman Khassraf2b1ebf12015-08-29 17:43:43 +020060 self.a5 = a5
61 self.kc = a5_kc
62 if len(a5_kc) < 8:
63 self.kc = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
64 self.speech_file = speech_file
65 self.speech_codec = speech_codec
Roman Khassraf262b53d2015-09-13 12:14:26 +020066 self.verbose = verbose
Piotr Krysik0679ceb2016-04-29 11:16:22 +020067 self.print_bursts = print_bursts
Roman Khassrafc0addfb2016-09-27 20:11:42 +020068 self.enable_voice_boundary_detection = enable_voice_boundary_detection
Roman Khassraf2b1ebf12015-08-29 17:43:43 +020069
70 ##################################################
71 # Blocks
72 ##################################################
73
74 if self.burst_file:
75 self.burst_file_source = grgsm.burst_file_source(burst_file)
76 elif self.cfile:
77 self.file_source = blocks.file_source(gr.sizeof_gr_complex*1, self.cfile, False)
78 self.receiver = grgsm.receiver(4, ([0]), ([]))
Piotr Krysik8040e012016-03-08 21:42:11 +010079 if self.fc is not None:
Piotr Krysik231aca72016-07-17 10:44:43 +020080 self.input_adapter = grgsm.gsm_input(ppm=ppm, osr=4, fc=self.fc, samp_rate_in=samp_rate)
Piotr Krysik388bc0d2016-07-15 14:17:05 +020081 self.offset_control = grgsm.clock_offset_control(self.fc, self.samp_rate)
Piotr Krysik8040e012016-03-08 21:42:11 +010082 else:
Piotr Krysik231aca72016-07-17 10:44:43 +020083 self.input_adapter = grgsm.gsm_input(ppm=ppm, osr=4, samp_rate_in=samp_rate)
Roman Khassraf2b1ebf12015-08-29 17:43:43 +020084
85 self.dummy_burst_filter = grgsm.dummy_burst_filter()
86 self.timeslot_filter = grgsm.burst_timeslot_filter(self.timeslot)
87
88 self.subslot_filter = None
89 if self.chan_mode == 'BCCH_SDCCH4' and self.subslot is not None:
90 self.subslot_filter = grgsm.burst_sdcch_subslot_filter(grgsm.SS_FILTER_SDCCH4, self.subslot)
91 elif self.chan_mode == 'SDCCH8' and self.subslot is not None:
92 self.subslot_filter = grgsm.burst_sdcch_subslot_filter(grgsm.SS_FILTER_SDCCH8, self.subslot)
93
94 if self.chan_mode == 'BCCH':
Piotr Krysik773a1942016-05-20 12:45:54 +020095 self.bcch_demapper = grgsm.gsm_bcch_ccch_demapper(self.timeslot)
Roman Khassraf2b1ebf12015-08-29 17:43:43 +020096 elif self.chan_mode == 'BCCH_SDCCH4':
Piotr Krysik773a1942016-05-20 12:45:54 +020097 self.bcch_sdcch4_demapper = grgsm.gsm_bcch_ccch_sdcch4_demapper(self.timeslot)
Roman Khassraf2b1ebf12015-08-29 17:43:43 +020098 elif self.chan_mode == 'SDCCH8':
Piotr Krysik773a1942016-05-20 12:45:54 +020099 self.sdcch8_demapper = grgsm.gsm_sdcch8_demapper(self.timeslot)
Roman Khassraf2b1ebf12015-08-29 17:43:43 +0200100 elif self.chan_mode == 'TCHF':
101 self.tch_f_demapper = grgsm.tch_f_chans_demapper(self.timeslot)
Roman Khassrafc0addfb2016-09-27 20:11:42 +0200102 self.tch_f_decoder = grgsm.tch_f_decoder(speech_codec, enable_voice_boundary_detection)
Piotr Krysik27791722016-07-20 08:12:23 +0200103 self.tch_f_pdu_to_tagged_stream = blocks.pdu_to_tagged_stream(blocks.byte_t, "packet_len")
104 self.tch_f_file_sink = blocks.file_sink(gr.sizeof_char*1, speech_file, False)
Vasil Velichkov7f259fd2018-05-06 02:13:36 +0300105 elif self.chan_mode == 'TCHH':
106 self.tch_h_demapper = grgsm.tch_h_chans_demapper(self.timeslot, tch_h_channel)
107 self.tch_h_decoder = grgsm.tch_h_decoder(tch_h_channel, multi_rate, enable_voice_boundary_detection)
108 self.tch_f_pdu_to_tagged_stream = blocks.pdu_to_tagged_stream(blocks.byte_t, "packet_len")
109 self.tch_f_file_sink = blocks.file_sink(gr.sizeof_char*1, speech_file, False)
Roman Khassraf2b1ebf12015-08-29 17:43:43 +0200110
111 if self.kc != [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]:
112 self.decryption = grgsm.decryption(self.kc, self.a5)
113 self.cch_decoder_decrypted = grgsm.control_channels_decoder()
Vasil Velichkov7f259fd2018-05-06 02:13:36 +0300114 if self.chan_mode in ('TCHF', 'TCHH'):
Roman Khassraf2b1ebf12015-08-29 17:43:43 +0200115 self.decryption_tch_sacch = grgsm.decryption(self.kc, self.a5)
116
117 self.cch_decoder = grgsm.control_channels_decoder()
118
Piotr Krysikbeb36f42016-06-09 13:58:52 +0200119 self.socket_pdu_server = blocks.socket_pdu("UDP_SERVER", "127.0.0.1", "4729", 10000) #added in order to avoid generating ICMP messages
Piotr Krysik72a16172016-02-22 14:30:02 +0100120 self.socket_pdu = blocks.socket_pdu("UDP_CLIENT", "127.0.0.1", "4729", 10000)
Piotr Krysikbeb36f42016-06-09 13:58:52 +0200121
Roman Khassraf262b53d2015-09-13 12:14:26 +0200122 if self.verbose:
123 self.message_printer = grgsm.message_printer(pmt.intern(""), True, True, False)
124
Piotr Krysik0679ceb2016-04-29 11:16:22 +0200125 if self.print_bursts:
Piotr Krysik7685bc02016-04-29 12:09:01 +0200126 self.bursts_printer = grgsm.bursts_printer(pmt.intern(""), True, True, True, True)
Piotr Krysik0679ceb2016-04-29 11:16:22 +0200127
128
Roman Khassraf2b1ebf12015-08-29 17:43:43 +0200129
130 ##################################################
131 # Asynch Message Connections
132 ##################################################
133
134 if self.burst_file:
135 self.msg_connect(self.burst_file_source, "out", self.dummy_burst_filter, "in")
136 elif self.cfile:
137 self.connect((self.file_source, 0), (self.input_adapter, 0))
138 self.connect((self.input_adapter, 0), (self.receiver, 0))
Piotr Krysik8040e012016-03-08 21:42:11 +0100139 if self.fc is not None:
Piotr Krysik6577ec22016-07-15 13:21:09 +0200140 self.msg_connect(self.offset_control, "ctrl", self.input_adapter, "ctrl_in")
Piotr Krysik8040e012016-03-08 21:42:11 +0100141 self.msg_connect(self.receiver, "measurements", self.offset_control, "measurements")
Roman Khassraf2b1ebf12015-08-29 17:43:43 +0200142 self.msg_connect(self.receiver, "C0", self.dummy_burst_filter, "in")
143
144 self.msg_connect(self.dummy_burst_filter, "out", self.timeslot_filter, "in")
Piotr Krysik0679ceb2016-04-29 11:16:22 +0200145 if self.print_bursts:
146 self.msg_connect(self.timeslot_filter, "out", self.bursts_printer, 'bursts')
Roman Khassraf2b1ebf12015-08-29 17:43:43 +0200147
148 if (self.chan_mode == 'BCCH_SDCCH4' or self.chan_mode == 'SDCCH8') and self.subslot_filter is not None:
149 self.msg_connect(self.timeslot_filter, "out", self.subslot_filter, "in")
150
151 if self.chan_mode == 'BCCH':
152 if self.subslot_filter is not None:
153 self.msg_connect(self.subslot_filter, "out", self.bcch_demapper, "bursts")
154 else:
155 self.msg_connect(self.timeslot_filter, "out", self.bcch_demapper, "bursts")
156
157 self.msg_connect(self.bcch_demapper, "bursts", self.cch_decoder, "bursts")
158 self.msg_connect(self.cch_decoder, "msgs", self.socket_pdu, "pdus")
Roman Khassraf262b53d2015-09-13 12:14:26 +0200159 if self.verbose:
160 self.msg_connect(self.cch_decoder, "msgs", self.message_printer, "msgs")
Roman Khassraf2b1ebf12015-08-29 17:43:43 +0200161
162 elif self.chan_mode == 'BCCH_SDCCH4':
163 if self.subslot_filter is not None:
164 self.msg_connect(self.subslot_filter, "out", self.bcch_sdcch4_demapper, "bursts")
165 else:
166 self.msg_connect(self.timeslot_filter, "out", self.bcch_sdcch4_demapper, "bursts")
167
168 if self.kc != [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]:
169 self.msg_connect(self.bcch_sdcch4_demapper, "bursts", self.decryption, "bursts")
170 self.msg_connect(self.decryption, "bursts", self.cch_decoder_decrypted, "bursts")
171 self.msg_connect(self.cch_decoder_decrypted, "msgs", self.socket_pdu, "pdus")
Roman Khassraf262b53d2015-09-13 12:14:26 +0200172 if self.verbose:
173 self.msg_connect(self.cch_decoder_decrypted, "msgs", self.message_printer, "msgs")
Roman Khassraf2b1ebf12015-08-29 17:43:43 +0200174
175 self.msg_connect(self.bcch_sdcch4_demapper, "bursts", self.cch_decoder, "bursts")
176 self.msg_connect(self.cch_decoder, "msgs", self.socket_pdu, "pdus")
Roman Khassraf262b53d2015-09-13 12:14:26 +0200177 if self.verbose:
178 self.msg_connect(self.cch_decoder, "msgs", self.message_printer, "msgs")
Roman Khassraf2b1ebf12015-08-29 17:43:43 +0200179
180 elif self.chan_mode == 'SDCCH8':
181 if self.subslot_filter is not None:
182 self.msg_connect(self.subslot_filter, "out", self.sdcch8_demapper, "bursts")
183 else:
184 self.msg_connect(self.timeslot_filter, "out", self.sdcch8_demapper, "bursts")
185
186 if self.kc != [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]:
187 self.msg_connect(self.sdcch8_demapper, "bursts", self.decryption, "bursts")
188 self.msg_connect(self.decryption, "bursts", self.cch_decoder_decrypted, "bursts")
189 self.msg_connect(self.cch_decoder_decrypted, "msgs", self.socket_pdu, "pdus")
Roman Khassraf262b53d2015-09-13 12:14:26 +0200190 if self.verbose:
191 self.msg_connect(self.cch_decoder_decrypted, "msgs", self.message_printer, "msgs")
Roman Khassraf2b1ebf12015-08-29 17:43:43 +0200192
193 self.msg_connect(self.sdcch8_demapper, "bursts", self.cch_decoder, "bursts")
194 self.msg_connect(self.cch_decoder, "msgs", self.socket_pdu, "pdus")
Roman Khassraf262b53d2015-09-13 12:14:26 +0200195 if self.verbose:
196 self.msg_connect(self.cch_decoder, "msgs", self.message_printer, "msgs")
Roman Khassraf2b1ebf12015-08-29 17:43:43 +0200197
198 elif self.chan_mode == 'TCHF':
199 self.msg_connect(self.timeslot_filter, "out", self.tch_f_demapper, "bursts")
200 if self.kc != [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]:
201 self.msg_connect(self.tch_f_demapper, "acch_bursts", self.decryption_tch_sacch, "bursts")
202 self.msg_connect(self.tch_f_demapper, "tch_bursts", self.decryption, "bursts")
203
204 self.msg_connect(self.decryption_tch_sacch, "bursts", self.cch_decoder, "bursts")
205 self.msg_connect(self.decryption, "bursts", self.tch_f_decoder, "bursts")
206 else:
207 self.msg_connect(self.tch_f_demapper, "acch_bursts", self.cch_decoder, "bursts")
208 self.msg_connect(self.tch_f_demapper, "tch_bursts", self.tch_f_decoder, "bursts")
209
210 self.msg_connect(self.tch_f_decoder, "msgs", self.socket_pdu, "pdus")
211 self.msg_connect(self.cch_decoder, "msgs", self.socket_pdu, "pdus")
Piotr Krysik27791722016-07-20 08:12:23 +0200212 self.msg_connect(self.tch_f_decoder, "voice", self.tch_f_pdu_to_tagged_stream, "pdus")
213 self.connect((self.tch_f_pdu_to_tagged_stream, 0), (self.tch_f_file_sink, 0))
214
215
Roman Khassraf262b53d2015-09-13 12:14:26 +0200216 if self.verbose:
217 self.msg_connect(self.tch_f_decoder, "msgs", self.message_printer, "msgs")
218 self.msg_connect(self.cch_decoder, "msgs", self.message_printer, "msgs")
Vasil Velichkov7f259fd2018-05-06 02:13:36 +0300219
220 elif self.chan_mode == 'TCHH':
221 self.msg_connect(self.timeslot_filter, "out", self.tch_h_demapper, "bursts")
222 if self.kc != [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]:
223 self.msg_connect(self.tch_h_demapper, "acch_bursts", self.decryption_tch_sacch, "bursts")
224 self.msg_connect(self.tch_h_demapper, "tch_bursts", self.decryption, "bursts")
225
226 self.msg_connect(self.decryption_tch_sacch, "bursts", self.cch_decoder, "bursts")
227 self.msg_connect(self.decryption, "bursts", self.tch_h_decoder, "bursts")
228 else:
229 self.msg_connect(self.tch_h_demapper, "acch_bursts", self.cch_decoder, "bursts")
230 self.msg_connect(self.tch_h_demapper, "tch_bursts", self.tch_h_decoder, "bursts")
231
232 self.msg_connect(self.tch_h_decoder, "msgs", self.socket_pdu, "pdus")
233 self.msg_connect(self.cch_decoder, "msgs", self.socket_pdu, "pdus")
234 self.msg_connect(self.tch_h_decoder, "voice", self.tch_f_pdu_to_tagged_stream, "pdus")
235 self.connect((self.tch_f_pdu_to_tagged_stream, 0), (self.tch_f_file_sink, 0))
236
237 if self.verbose:
238 self.msg_connect(self.tch_h_decoder, "msgs", self.message_printer, "msgs")
239 self.msg_connect(self.cch_decoder, "msgs", self.message_printer, "msgs")
Roman Khassraf2b1ebf12015-08-29 17:43:43 +0200240
241if __name__ == '__main__':
242
243 # List of channel configurations
Vasil Velichkov7f259fd2018-05-06 02:13:36 +0300244 channel_modes = ['BCCH', 'BCCH_SDCCH4', 'SDCCH8', 'TCHF', 'TCHH']
Roman Khassraf2b1ebf12015-08-29 17:43:43 +0200245
246 # mapping options to grgsm's enums
247 tch_codecs = collections.OrderedDict([
248 ('FR', grgsm.TCH_FS),
249 ('EFR', grgsm.TCH_EFR),
250 ('AMR12.2', grgsm.TCH_AFS12_2),
251 ('AMR10.2', grgsm.TCH_AFS10_2),
252 ('AMR7.95', grgsm.TCH_AFS7_95),
253 ('AMR7.4', grgsm.TCH_AFS7_4),
254 ('AMR6.7', grgsm.TCH_AFS6_7),
255 ('AMR5.9', grgsm.TCH_AFS5_9),
256 ('AMR5.15', grgsm.TCH_AFS5_15),
257 ('AMR4.75', grgsm.TCH_AFS4_75)
258 ])
259
260 kc = []
261
262 parser = OptionParser(option_class=eng_option, usage="%prog: [options]")
263
264 def kc_callback(option, opt_str, value, parser):
265
266 """ Callback function that parses Kc """
267
268 # format 0x12,0x34,0x56,0x78,0x90,0xAB,0xCD,0xEF
269 if ',' in value:
270 value_str = value.split(',')
271
272 for s in value_str:
273 val = int(s, 16)
274 if val < 0 or val > 255:
275 parser.error("Invalid Kc % s\n" % s)
276 kc.append(val)
277 if len(kc) != 8:
278 parser.error("Invalid Kc length")
279 # format: 1234567890ABCDEF
280 elif len(value) == 16:
281 for i in range(8):
282 s = value[2*i: 2*i + 2]
283 val = int(s, 16)
284 if val < 0 or val > 255:
285 parser.error("Invalid Kc % s\n" % s)
286 kc.append(val)
287 else:
288 parser.error("Invalid Kc format")
289
290 # define options
291 parser.add_option("-m", "--mode", dest="chan_mode", default='BCCH',
292 type='choice', choices=channel_modes,
293 help="Channel mode. Valid options are 'BCCH' (Non-combined C0), "
294 "'BCCH_SDCCH4'(Combined C0), 'SDCCH8' (Stand-alone control channel) "
Vasil Velichkov7f259fd2018-05-06 02:13:36 +0300295 "'TCHF' (Traffic Channel, Full rate), 'TCHH' (Traffic Channel, Half rate) ")
Roman Khassraf2b1ebf12015-08-29 17:43:43 +0200296 parser.add_option("-t", "--timeslot", dest="timeslot", type="intx", default=0,
297 help="Timeslot to decode [default=%default]")
298 parser.add_option("-u", "--subslot", dest="subslot", type="intx",
299 help="Subslot to decode. Use in combination with channel type BCCH_SDCCH4 and SDCCH8")
300 parser.add_option("-b", "--burst-file", dest="burst_file", help="Input file (bursts)")
301 parser.add_option("-c", "--cfile", dest="cfile", help="Input file (cfile)")
Roman Khassraf262b53d2015-09-13 12:14:26 +0200302 parser.add_option("-v", "--verbose", action="store_true",
303 help="If set, the decoded messages (with frame number and count) are printed to stdout")
Piotr Krysik0679ceb2016-04-29 11:16:22 +0200304 parser.add_option("-p", "--print-bursts", action="store_true",
305 help="If set, the raw bursts (with frame number and count) are printed to stdout")
Roman Khassraf2b1ebf12015-08-29 17:43:43 +0200306
307 # group cfile options together
308 cfile_options = OptionGroup(
309 parser, 'Cfile Options', 'Options for decoding cfile input.',
310 )
311 cfile_options.add_option("-f", "--fc", dest="fc", type="eng_float",
Piotr Krysik231aca72016-07-17 10:44:43 +0200312 help="Frequency of cfile capture")
Roman Khassraf2b1ebf12015-08-29 17:43:43 +0200313 cfile_options.add_option("-a", "--arfcn", dest="arfcn", type="intx",
Piotr Krysikfcb45b02017-09-11 10:07:25 +0200314 help="Set ARFCN instead of frequency (for PCS1900 add 0x8000 (2**15) to the ARFCN number).")
Roman Khassraf2b1ebf12015-08-29 17:43:43 +0200315 cfile_options.add_option("-s", "--samp-rate", dest="samp_rate", type="eng_float",
Piotr Krysik13d9e7a2016-04-24 15:23:15 +0200316 default=eng_notation.num_to_str(1e6),
Roman Khassraf2b1ebf12015-08-29 17:43:43 +0200317 help="Sample rate of cfile capture [default=%default]")
Piotr Krysik231aca72016-07-17 10:44:43 +0200318 cfile_options.add_option("--ppm", dest="ppm", type="float", default=0,
319 help="Set frequency offset correction [default=%default]")
320
Roman Khassraf2b1ebf12015-08-29 17:43:43 +0200321 parser.add_option_group(cfile_options)
322
323 # group decryption options
324 decryption_options = OptionGroup(
325 parser, 'Decryption Options', 'Options for setting the A5 decryption parameters.',
326 )
327 decryption_options.add_option("-e", "--a5", dest="a5", type="intx", default=1,
328 help="A5 version [default=%default]. A5 versions 1 - 3 supported")
329 decryption_options.add_option("-k", "--kc", action="callback", callback=kc_callback, type="string",
330 help="A5 session key Kc. Valid formats are "
331 "'0x12,0x34,0x56,0x78,0x90,0xAB,0xCD,0xEF' and '1234567890ABCDEF'")
332 parser.add_option_group(decryption_options)
333
334 # group TCH options
335 tch_options = OptionGroup(
336 parser, 'TCH Options', 'Options for setting Traffic channel decoding parameters.',
337 )
338 tch_options.add_option("-d", "--speech-codec", dest="speech_codec", default='FR',
339 type='choice', choices=tch_codecs.keys(),
340 help="TCH-F speech codec [default=%default]. "
341 "Valid options are " + ", ".join(tch_codecs.keys()))
342 tch_options.add_option("-o", "--output-tch", dest="speech_output_file", default="/tmp/speech.au.gsm",
Vasil Velichkov7f259fd2018-05-06 02:13:36 +0300343 help="tch/f speech output file [default=%default].")
344 tch_options.add_option("--sub-channel", dest="tch_h_channel", default="0", type='intx',
345 help="TCH/H sub-channel. [default=0]")
346 tch_options.add_option("--multi-rate", dest="multi_rate", default="", type='string',
347 help="The MultiRrate configuration element from the Assignment Command message. "
348 "Example: 28111a40. See 3GPP TS 44.018 - 10.5.2.21aa MultiRate configuration")
Piotr Krysik2770fc42017-07-23 22:05:10 +0200349 tch_options.add_option("--voice-boundary", dest="enable_voice_boundary_detection", action="store_true", default=False,
Roman Khassrafc0addfb2016-09-27 20:11:42 +0200350 help="Enable voice boundary detection for traffic channels. This can help reduce noice in the output.")
Roman Khassraf2b1ebf12015-08-29 17:43:43 +0200351 parser.add_option_group(tch_options)
352
353 # parse
354 (options, args) = parser.parse_args()
355
356 # some verifications
357 if (options.cfile is None and options.burst_file is None) or \
358 (options.cfile is not None and options.burst_file is not None):
359 parser.error("Please provide a cfile or a burst file (but not both) as input\n")
360
361 if options.timeslot < 0 or options.timeslot > 7:
362 parser.error("Invalid timeslot. Must be a in range 0-7\n")
363
364 if options.subslot is not None and (options.subslot < 0 or options.subslot > 7):
365 parser.error("Invalid subslot. Must be a in range 0-7\n")
366
367 if options.a5 < 0 or options.a5 > 3:
368 parser.error("Invalid A5 version\n")
369
Piotr Krysik231aca72016-07-17 10:44:43 +0200370 if options.cfile and (options.fc is None and options.arfcn is None):
Piotr Krysik8040e012016-03-08 21:42:11 +0100371 print("You haven't provided a frequency or an ARFCN - working without automatic frequency offset correction.\n")
Roman Khassraf2b1ebf12015-08-29 17:43:43 +0200372
373 # handle frequency / arfcn input
Piotr Krysik231aca72016-07-17 10:44:43 +0200374 arfcn = None
375 fc = None
Roman Khassraf2b1ebf12015-08-29 17:43:43 +0200376 if options.arfcn:
Piotr Krysikfcb45b02017-09-11 10:07:25 +0200377 if not grgsm.arfcn.is_valid_arfcn(options.arfcn):
378 parser.error("ARFCN is not valid\n")
Roman Khassraf2b1ebf12015-08-29 17:43:43 +0200379 else:
380 arfcn = options.arfcn
Piotr Krysikfcb45b02017-09-11 10:07:25 +0200381 fc = grgsm.arfcn.arfcn2downlink(arfcn)
Roman Khassraf2b1ebf12015-08-29 17:43:43 +0200382 elif options.fc:
383 fc = options.fc
Piotr Krysikfcb45b02017-09-11 10:07:25 +0200384 arfcn = grgsm.arfcn.downlink2arfcn(options.fc)
Roman Khassraf2b1ebf12015-08-29 17:43:43 +0200385
Roman Khassraf2b1ebf12015-08-29 17:43:43 +0200386 # instanciate decoder
Piotr Krysik3e192c42016-02-13 07:31:51 +0100387 tb = grgsm_decoder(timeslot=options.timeslot, subslot=options.subslot, chan_mode=options.chan_mode,
Roman Khassraf2b1ebf12015-08-29 17:43:43 +0200388 burst_file=options.burst_file,
Piotr Krysik8040e012016-03-08 21:42:11 +0100389 cfile=options.cfile, fc=fc, samp_rate=options.samp_rate,
Roman Khassraf2b1ebf12015-08-29 17:43:43 +0200390 a5=options.a5, a5_kc=kc,
Roman Khassraf262b53d2015-09-13 12:14:26 +0200391 speech_file=options.speech_output_file, speech_codec=tch_codecs.get(options.speech_codec),
Roman Khassrafc0addfb2016-09-27 20:11:42 +0200392 enable_voice_boundary_detection=options.enable_voice_boundary_detection,
Vasil Velichkov7f259fd2018-05-06 02:13:36 +0300393 tch_h_channel=options.tch_h_channel,
394 multi_rate=options.multi_rate,
Piotr Krysik0679ceb2016-04-29 11:16:22 +0200395 verbose=options.verbose,
Piotr Krysik196982b2016-07-17 10:43:00 +0200396 print_bursts=options.print_bursts, ppm=options.ppm)
Roman Khassraf2b1ebf12015-08-29 17:43:43 +0200397
398 # run
399 tb.start()
400 tb.wait()