ptrkrysik | 82bd117 | 2015-01-15 09:35:03 +0100 | [diff] [blame] | 1 | /* -*- c++ -*- */ |
| 2 | /* @file |
| 3 | * @author Piotr Krysik <ptrkrysik@gmail.com> |
| 4 | * @section LICENSE |
| 5 | * |
| 6 | * Gr-gsm is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 3, or (at your option) |
| 9 | * any later version. |
| 10 | * |
| 11 | * Gr-gsm is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with gr-gsm; see the file COPYING. If not, write to |
| 18 | * the Free Software Foundation, Inc., 51 Franklin Street, |
| 19 | * Boston, MA 02110-1301, USA. |
| 20 | * |
| 21 | */ |
| 22 | |
| 23 | #ifdef HAVE_CONFIG_H |
| 24 | #include "config.h" |
| 25 | #endif |
| 26 | |
| 27 | #include <gnuradio/io_signature.h> |
| 28 | #include "tmsi_dumper_impl.h" |
ptrkrysik | 258bbb8 | 2015-01-15 11:31:47 +0100 | [diff] [blame] | 29 | #include "grgsm/gsmtap.h" |
| 30 | #include <stdio.h> |
banjaxbanjo | 27ca869 | 2015-01-16 09:01:49 +0000 | [diff] [blame] | 31 | #include <ctime> |
| 32 | FILE* tmsiFile; |
ptrkrysik | 82bd117 | 2015-01-15 09:35:03 +0100 | [diff] [blame] | 33 | |
| 34 | namespace gr { |
| 35 | namespace gsm { |
ptrkrysik | 258bbb8 | 2015-01-15 11:31:47 +0100 | [diff] [blame] | 36 | |
| 37 | void tmsi_dumper_impl::dump_tmsi(pmt::pmt_t msg) |
| 38 | { |
banjaxbanjo | 27ca869 | 2015-01-16 09:01:49 +0000 | [diff] [blame] | 39 | time_t now = time(0); |
| 40 | tm *ltm = localtime(&now); |
ptrkrysik | 258bbb8 | 2015-01-15 11:31:47 +0100 | [diff] [blame] | 41 | pmt::pmt_t message_plus_header_blob = pmt::cdr(msg); |
| 42 | uint8_t * message_plus_header = (uint8_t *)pmt::blob_data(message_plus_header_blob); |
| 43 | size_t message_plus_header_len=pmt::blob_length(message_plus_header_blob); |
| 44 | |
| 45 | gsmtap_hdr * header = (gsmtap_hdr *)message_plus_header; |
banjaxbanjo | 27ca869 | 2015-01-16 09:01:49 +0000 | [diff] [blame] | 46 | int ii=sizeof(gsmtap_hdr); |
| 47 | |
| 48 | switch(message_plus_header[ii]){ |
| 49 | case 37: |
| 50 | //1 tmsi 6-9 |
| 51 | |
| 52 | if((unsigned char)message_plus_header[ii+1] == 6 && (unsigned char)message_plus_header[ii+2] == 33) |
| 53 | { |
| 54 | if((unsigned char)message_plus_header[ii+6] != 43 && (unsigned char)message_plus_header[ii+6] != 43) |
| 55 | { |
| 56 | //printf("INSIDE 37\n"); |
| 57 | tmsiFile = fopen("tmsicount.txt", "a+"); |
| 58 | fprintf(tmsiFile,"%02.2x%02.2x%02.2x%02.2x-%02i%02i%02i%02i%02i%02i-%i\n", |
| 59 | (unsigned char)message_plus_header[ii+6], |
| 60 | (unsigned char)message_plus_header[ii+7], |
| 61 | (unsigned char)message_plus_header[ii+8], |
| 62 | (unsigned char)message_plus_header[ii+9], |
| 63 | 1900 + ltm->tm_year-2000, |
| 64 | 1+ltm->tm_mon, |
| 65 | ltm->tm_mday, |
| 66 | ltm->tm_hour, |
| 67 | ltm->tm_min, |
| 68 | ltm->tm_sec, |
| 69 | 0); |
| 70 | fclose(tmsiFile); |
| 71 | } |
| 72 | } |
| 73 | break; |
| 74 | case 49: |
| 75 | if(message_plus_header[ii+2] == 33)//21 hex |
| 76 | { |
| 77 | //printf("INSIDE 49\n"); |
| 78 | //1 imsi 5-12 33 |
| 79 | tmsiFile = fopen("tmsicount.txt", "a"); |
| 80 | fprintf(tmsiFile,"%i-%02i%02i%02i%02i%02i%02i-%02.2x%02.2x%02.2x%02.2x%02.2x%02.2x%02.2x%02.2x\n",0, |
| 81 | 1900 + ltm->tm_year-2000, |
| 82 | 1+ltm->tm_mon, |
| 83 | ltm->tm_mday, |
| 84 | ltm->tm_hour, |
| 85 | ltm->tm_min, |
| 86 | ltm->tm_sec, |
| 87 | |
| 88 | (unsigned char)message_plus_header[ii+5], |
| 89 | (unsigned char)message_plus_header[ii+6], |
| 90 | (unsigned char)message_plus_header[ii+7], |
| 91 | (unsigned char)message_plus_header[ii+8], |
| 92 | (unsigned char)message_plus_header[ii+9], |
| 93 | (unsigned char)message_plus_header[ii+10], |
| 94 | (unsigned char)message_plus_header[ii+11], |
| 95 | (unsigned char)message_plus_header[ii+12]); |
| 96 | fclose(tmsiFile); |
| 97 | } |
| 98 | break; |
| 99 | case 65: |
banjaxbanjo | 6f27bcf | 2015-01-16 11:16:08 +0000 | [diff] [blame] | 100 | //printf("INSIDE 65\n"); (41 hex) (65 int) 6-8 13-16 |
| 101 | if(message_plus_header[ii+2] == 33)//21 hex |
| 102 | { |
| 103 | tmsiFile = fopen("tmsicount.txt", "a+"); |
| 104 | fprintf(tmsiFile,"%02.2x%02.2x%02.2x%02.2x-%02d%02d%02d%02d%02d%02d-%i\n%02.2x%02.2x%02.2x%02.2x-%02d%02d%02d%02d%02d%02d-%i\n", |
| 105 | (unsigned char)message_plus_header[ii+6], |
| 106 | (unsigned char)message_plus_header[ii+7], |
| 107 | (unsigned char)message_plus_header[ii+8], |
| 108 | (unsigned char)message_plus_header[ii+9], |
| 109 | 1900 + ltm->tm_year-2000, |
| 110 | 1+ltm->tm_mon, |
| 111 | ltm->tm_mday, |
| 112 | ltm->tm_hour, |
| 113 | ltm->tm_min, |
| 114 | ltm->tm_sec,0, |
| 115 | |
| 116 | (unsigned char)message_plus_header[ii+13], |
| 117 | (unsigned char)message_plus_header[ii+14], |
| 118 | (unsigned char)message_plus_header[ii+15], |
| 119 | (unsigned char)message_plus_header[ii+16], |
| 120 | 1900 + ltm->tm_year-2000, |
| 121 | 1+ltm->tm_mon, |
| 122 | ltm->tm_mday, |
| 123 | ltm->tm_hour, |
| 124 | ltm->tm_min, |
| 125 | ltm->tm_sec,0); |
| 126 | fclose(tmsiFile); |
| 127 | } |
banjaxbanjo | 27ca869 | 2015-01-16 09:01:49 +0000 | [diff] [blame] | 128 | break; |
| 129 | case 73: |
| 130 | //printf("INSIDE 73\n"); |
| 131 | //3 tmsi 4-7 8-11 15-18 |
| 132 | if(message_plus_header[ii+2] == 34) |
| 133 | { |
| 134 | tmsiFile = fopen("tmsicount.txt", "a+"); |
| 135 | fprintf(tmsiFile,"%02.2x%02.2x%02.2x%02.2x-%02d%02d%02d%02d%02d%02d-%i\n%02.2x%02.2x%02.2x%02.2x-%02d%02d%02d%02d%02d%02d-%i\n%02.2x%02.2x%02.2x%02.2x-%02d%02d%02d%02d%02d%02d-%i\n", |
| 136 | (unsigned char)message_plus_header[ii+4], |
| 137 | (unsigned char)message_plus_header[ii+5], |
| 138 | (unsigned char)message_plus_header[ii+6], |
| 139 | (unsigned char)message_plus_header[ii+7], |
| 140 | 1900 + ltm->tm_year-2000, |
| 141 | 1+ltm->tm_mon, |
| 142 | ltm->tm_mday, |
| 143 | ltm->tm_hour, |
| 144 | ltm->tm_min, |
| 145 | ltm->tm_sec,0, |
| 146 | |
| 147 | (unsigned char)message_plus_header[ii+8], |
| 148 | (unsigned char)message_plus_header[ii+9], |
| 149 | (unsigned char)message_plus_header[ii+10], |
| 150 | (unsigned char)message_plus_header[ii+11], |
| 151 | 1900 + ltm->tm_year-2000, |
| 152 | 1+ltm->tm_mon, |
| 153 | ltm->tm_mday, |
| 154 | ltm->tm_hour, |
| 155 | ltm->tm_min, |
| 156 | ltm->tm_sec,0, |
| 157 | |
| 158 | (unsigned char)message_plus_header[ii+15], |
| 159 | (unsigned char)message_plus_header[ii+16], |
| 160 | (unsigned char)message_plus_header[ii+17], |
| 161 | (unsigned char)message_plus_header[ii+18], |
| 162 | 1900 + ltm->tm_year-2000, |
| 163 | 1+ltm->tm_mon, |
| 164 | ltm->tm_mday, |
| 165 | ltm->tm_hour, |
| 166 | ltm->tm_min, |
| 167 | ltm->tm_sec,0); |
| 168 | fclose(tmsiFile); |
| 169 | } |
| 170 | break; |
| 171 | case 77: |
| 172 | if(message_plus_header[ii+2] == 33 && message_plus_header[ii+4] == 8) |
| 173 | { |
| 174 | //1 imsi 1 tmsi 5-12 16-19 |
| 175 | //printf("INSIDE 77 + 33 + 8\n"); |
| 176 | tmsiFile = fopen("tmsicount.txt", "a+"); |
| 177 | fprintf(tmsiFile,"%02.2x%02.2x%02.2x%02.2x-%02d%02d%02d%02d%02d%02d-%02.2x%02.2x%02.2x%02.2x%02.2x%02.2x%02.2x%02.2x\n", |
| 178 | (unsigned char)message_plus_header[ii+16], |
| 179 | (unsigned char)message_plus_header[ii+17], |
| 180 | (unsigned char)message_plus_header[ii+18], |
| 181 | (unsigned char)message_plus_header[ii+19], |
| 182 | 1900 + ltm->tm_year-2000, |
| 183 | 1+ltm->tm_mon, |
| 184 | ltm->tm_mday, |
| 185 | ltm->tm_hour, |
| 186 | ltm->tm_min, |
| 187 | ltm->tm_sec, |
| 188 | |
| 189 | (unsigned char)message_plus_header[ii+5], |
| 190 | (unsigned char)message_plus_header[ii+6], |
| 191 | (unsigned char)message_plus_header[ii+7], |
| 192 | (unsigned char)message_plus_header[ii+8], |
| 193 | (unsigned char)message_plus_header[ii+9], |
| 194 | (unsigned char)message_plus_header[ii+10], |
| 195 | (unsigned char)message_plus_header[ii+11], |
| 196 | (unsigned char)message_plus_header[ii+12]); |
| 197 | fclose(tmsiFile); |
| 198 | } |
| 199 | else if(message_plus_header[ii+2] == 33 && message_plus_header[ii+4] == 5) |
| 200 | { |
| 201 | //1 tmsi 1 imsi 6-9 12-19 |
| 202 | //printf("INSIDE 77 + 33 + 5\n"); |
| 203 | tmsiFile = fopen("tmsicount.txt", "a+"); |
| 204 | fprintf(tmsiFile,"%02.2x%02.2x%02.2x%02.2x-%02d%02d%02d%02d%02d%02d-%02.2x%02.2x%02.2x%02.2x%02.2x%02.2x%02.2x%02.2x\n", |
| 205 | (unsigned char)message_plus_header[ii+6], |
| 206 | (unsigned char)message_plus_header[ii+7], |
| 207 | (unsigned char)message_plus_header[ii+8], |
| 208 | (unsigned char)message_plus_header[ii+9], |
| 209 | 1900 + ltm->tm_year-2000, |
| 210 | 1+ltm->tm_mon, |
| 211 | ltm->tm_mday, |
| 212 | ltm->tm_hour, |
| 213 | ltm->tm_min, |
| 214 | ltm->tm_sec, |
| 215 | |
| 216 | (unsigned char)message_plus_header[ii+12], |
| 217 | (unsigned char)message_plus_header[ii+13], |
| 218 | (unsigned char)message_plus_header[ii+14], |
| 219 | (unsigned char)message_plus_header[ii+15], |
| 220 | (unsigned char)message_plus_header[ii+16], |
| 221 | (unsigned char)message_plus_header[ii+17], |
| 222 | (unsigned char)message_plus_header[ii+18], |
| 223 | (unsigned char)message_plus_header[ii+19]); |
| 224 | fclose(tmsiFile); |
| 225 | } |
| 226 | else if(message_plus_header[ii+2] == 34) |
| 227 | { |
| 228 | //printf("INSIDE 77 + 34\n"); |
| 229 | tmsiFile = fopen("tmsicount.txt", "a+"); |
| 230 | fprintf(tmsiFile,"%02.2x%02.2x%02.2x%02.2x-%02d%02d%02d%02d%02d%02d-%i\n%02.2x%02.2x%02.2x%02.2x-%02d%02d%02d%02d%02d%02d-%i\n%02.2x%02.2x%02.2x%02.2x-%02d%02d%02d%02d%02d%02d-%i\n", |
| 231 | (unsigned char)message_plus_header[ii+4], |
| 232 | (unsigned char)message_plus_header[ii+5], |
| 233 | (unsigned char)message_plus_header[ii+6], |
| 234 | (unsigned char)message_plus_header[ii+7], |
| 235 | 1900 + ltm->tm_year-2000, |
| 236 | 1+ltm->tm_mon, |
| 237 | ltm->tm_mday, |
| 238 | ltm->tm_hour, |
| 239 | ltm->tm_min, |
| 240 | ltm->tm_sec,0, |
| 241 | |
| 242 | (unsigned char)message_plus_header[ii+8], |
| 243 | (unsigned char)message_plus_header[ii+9], |
| 244 | (unsigned char)message_plus_header[ii+10], |
| 245 | (unsigned char)message_plus_header[ii+11], |
| 246 | 1900 + ltm->tm_year-2000, |
| 247 | 1+ltm->tm_mon, |
| 248 | ltm->tm_mday, |
| 249 | ltm->tm_hour, |
| 250 | ltm->tm_min, |
| 251 | ltm->tm_sec,0, |
| 252 | |
| 253 | (unsigned char)message_plus_header[ii+15], |
| 254 | (unsigned char)message_plus_header[ii+16], |
| 255 | (unsigned char)message_plus_header[ii+17], |
| 256 | (unsigned char)message_plus_header[ii+18], |
| 257 | 1900 + ltm->tm_year-2000, |
| 258 | 1+ltm->tm_mon, |
| 259 | ltm->tm_mday, |
| 260 | ltm->tm_hour, |
| 261 | ltm->tm_min, |
| 262 | ltm->tm_sec,0); |
| 263 | fclose(tmsiFile); |
| 264 | } |
| 265 | else if(message_plus_header[ii+2] == 36) |
| 266 | { |
| 267 | //printf("INSIDE 77 + 36\n"); |
| 268 | tmsiFile = fopen("tmsicount.txt", "a+"); |
| 269 | fprintf(tmsiFile,"%02.2x%02.2x%02.2x%02.2x-%02d%02d%02d%02d%02d%02d-%i\n%02.2x%02.2x%02.2x%02.2x-%02d%02d%02d%02d%02d%02d-%i\n%02.2x%02.2x%02.2x%02.2x-%02d%02d%02d%02d%02d%02d-%i\n%02.2x%02.2x%02.2x%02.2x-%02d%02d%02d%02d%02d%02d-%i\n", |
| 270 | (unsigned char)message_plus_header[ii+4], |
| 271 | (unsigned char)message_plus_header[ii+5], |
| 272 | (unsigned char)message_plus_header[ii+6], |
| 273 | (unsigned char)message_plus_header[ii+7], |
| 274 | 1900 + ltm->tm_year-2000, |
| 275 | 1+ltm->tm_mon, |
| 276 | ltm->tm_mday, |
| 277 | ltm->tm_hour, |
| 278 | ltm->tm_min, |
| 279 | ltm->tm_sec,0, |
| 280 | |
| 281 | (unsigned char)message_plus_header[ii+8], |
| 282 | (unsigned char)message_plus_header[ii+9], |
| 283 | (unsigned char)message_plus_header[ii+10], |
| 284 | (unsigned char)message_plus_header[ii+11], |
| 285 | 1900 + ltm->tm_year-2000, |
| 286 | 1+ltm->tm_mon, |
| 287 | ltm->tm_mday, |
| 288 | ltm->tm_hour, |
| 289 | ltm->tm_min, |
| 290 | ltm->tm_sec,0, |
| 291 | |
| 292 | (unsigned char)message_plus_header[ii+12], |
| 293 | (unsigned char)message_plus_header[ii+13], |
| 294 | (unsigned char)message_plus_header[ii+14], |
| 295 | (unsigned char)message_plus_header[ii+15], |
| 296 | 1900 + ltm->tm_year-2000, |
| 297 | 1+ltm->tm_mon, |
| 298 | ltm->tm_mday, |
| 299 | ltm->tm_hour, |
| 300 | ltm->tm_min, |
| 301 | ltm->tm_sec,0, |
| 302 | |
| 303 | (unsigned char)message_plus_header[ii+16], |
| 304 | (unsigned char)message_plus_header[ii+17], |
| 305 | (unsigned char)message_plus_header[ii+18], |
| 306 | (unsigned char)message_plus_header[ii+19], |
| 307 | 1900 + ltm->tm_year-2000, |
| 308 | 1+ltm->tm_mon, |
| 309 | ltm->tm_mday, |
| 310 | ltm->tm_hour, |
| 311 | ltm->tm_min, |
| 312 | ltm->tm_sec,0); |
| 313 | fclose(tmsiFile); |
| 314 | } |
| 315 | break; |
| 316 | case 85: |
| 317 | if(message_plus_header[ii+2] == 34)//hex 22 |
| 318 | { |
| 319 | //printf("INSIDE 85\n");// hex is 55 |
| 320 | tmsiFile = fopen("tmsicount.txt", "a+"); |
| 321 | fprintf(tmsiFile,"%02.2x%02.2x%02.2x%02.2x-%02d%02d%02d%02d%02d%02d-%i\n%02.2x%02.2x%02.2x%02.2x-%02d%02d%02d%02d%02d%02d-%i\n", |
| 322 | (unsigned char)message_plus_header[ii+4], |
| 323 | (unsigned char)message_plus_header[ii+5], |
| 324 | (unsigned char)message_plus_header[ii+6], |
| 325 | (unsigned char)message_plus_header[ii+7], |
| 326 | 1900 + ltm->tm_year-2000, |
| 327 | 1+ltm->tm_mon, |
| 328 | ltm->tm_mday, |
| 329 | ltm->tm_hour, |
| 330 | ltm->tm_min, |
| 331 | ltm->tm_sec,0, |
| 332 | |
| 333 | (unsigned char)message_plus_header[ii+8], |
| 334 | (unsigned char)message_plus_header[ii+9], |
| 335 | (unsigned char)message_plus_header[ii+10], |
| 336 | (unsigned char)message_plus_header[ii+11], |
| 337 | 1900 + ltm->tm_year-2000, |
| 338 | 1+ltm->tm_mon, |
| 339 | ltm->tm_mday, |
| 340 | ltm->tm_hour, |
| 341 | ltm->tm_min, |
| 342 | ltm->tm_sec,0); |
| 343 | fclose(tmsiFile); |
| 344 | } |
| 345 | break; |
| 346 | |
| 347 | } |
| 348 | |
ptrkrysik | 258bbb8 | 2015-01-15 11:31:47 +0100 | [diff] [blame] | 349 | std::cout << std::endl; |
| 350 | } |
| 351 | |
ptrkrysik | 82bd117 | 2015-01-15 09:35:03 +0100 | [diff] [blame] | 352 | tmsi_dumper::sptr |
| 353 | tmsi_dumper::make() |
| 354 | { |
| 355 | return gnuradio::get_initial_sptr |
| 356 | (new tmsi_dumper_impl()); |
| 357 | } |
| 358 | |
| 359 | /* |
| 360 | * The private constructor |
| 361 | */ |
| 362 | tmsi_dumper_impl::tmsi_dumper_impl() |
| 363 | : gr::block("tmsi_dumper", |
ptrkrysik | 9162922 | 2015-01-15 10:28:14 +0100 | [diff] [blame] | 364 | gr::io_signature::make(0, 0, 0), |
| 365 | gr::io_signature::make(0, 0, 0)) |
ptrkrysik | 258bbb8 | 2015-01-15 11:31:47 +0100 | [diff] [blame] | 366 | { |
| 367 | message_port_register_in(pmt::mp("msgs")); |
| 368 | set_msg_handler(pmt::mp("msgs"), boost::bind(&tmsi_dumper_impl::dump_tmsi, this, _1)); |
| 369 | } |
ptrkrysik | 82bd117 | 2015-01-15 09:35:03 +0100 | [diff] [blame] | 370 | |
| 371 | /* |
| 372 | * Our virtual destructor. |
| 373 | */ |
| 374 | tmsi_dumper_impl::~tmsi_dumper_impl() |
| 375 | { |
| 376 | } |
ptrkrysik | 82bd117 | 2015-01-15 09:35:03 +0100 | [diff] [blame] | 377 | } /* namespace gsm */ |
| 378 | } /* namespace gr */ |
| 379 | |