From 94926167c26cf281f01fe3ba83f82ef95bbbd13f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20DEL=20NERO?= Date: Sun, 4 Dec 2022 01:02:16 +0100 Subject: [PATCH] improvements and fixes. DFS event emulation. --- src/rf_jammer/rf_jammer.c | 221 ++++++++++++++++++++++++-------------- 1 file changed, 138 insertions(+), 83 deletions(-) diff --git a/src/rf_jammer/rf_jammer.c b/src/rf_jammer/rf_jammer.c index 2e8caaf..4033c61 100644 --- a/src/rf_jammer/rf_jammer.c +++ b/src/rf_jammer/rf_jammer.c @@ -50,7 +50,6 @@ } while (0) #define IQ_SAMPLE_RATE (10000000UL) -#define SUBCARRIERS_SAMPLE_RATE (10000000UL) #define IF_FREQ 0 @@ -121,51 +120,64 @@ void printhelp(char* argv[]) { printf("Options:\n"); printf(" -stdout\t\t\t: IQ stream send to stdout\n"); - printf(" -freq_bw:[Hz] \t\t: bandwith (Hz)\n"); + printf(" -iq_rate\t\t\t: IQ rate (default : 10000000)\n"); + printf(" -freq_bw:[Hz]\t\t\t: bandwith (Hz)\n"); printf(" -ping_pong_freq:[centi Hz]\t: ping pong freq (per step of 0.01 Hz)\n"); - printf(" -jam_mode:[Mode id]\t\t: Mode. 0=ping pong, 1=random, 3=full iq random\n"); - printf(" -jam_interval:[ms]\t\t: Interval (ms)\n"); - printf(" -jam_duration:[ms]\t\t: pulses duration (ms)\n"); + printf(" -jam_mode:[Mode id]\t\t: Mode. 0=ping pong, 1=random, 2=fixed frequency, 3=full iq random\n"); + printf(" -jam_interval:[uS]\t\t: Interval (uS)\n"); + printf(" -jam_duration:[uS]\t\t: pulses duration (uS)\n"); + printf(" -jam_long_interval:[uS]\t\t: pulses long interval (uS)\n"); + printf(" -jam_group_pulses:[cnt]\t\t: pulses group count\n"); printf(" -rand_interval\t\t: random interval mode\n"); printf(" -rand_duration\t\t: random duration mode\n"); printf(" -generate\t\t\t: Generate the IQ stream\n"); printf(" -help\t\t\t\t: This help\n"); + printf("\n Examples :\n"); + printf(" ./rf_jammer -generate -stdout -iq_rate:10000000 -freq_bw:50000 -jam_mode:1 -jam_interval:625 -jam_duration:10 | hackrf_transfer -f 5500000000 -t - -x 47 -a 1 -s 10000000\n"); + printf(" ./rf_jammer -generate -stdout -iq_rate:2000000 -jam_mode:2 -jam_interval:613 -jam_duration:12 -jam_long_interval:250000 -jam_group_pulses:15 | hackrf_transfer -f 5500000000 -t - -x 47 -a 1 -s 2000000\n"); printf("\n"); } #define BUFFER_SAMPLES_SIZE (2048*8) +int us2ticks(int samplerate, int us) +{ + return (us * (samplerate / 1000000)); +} + int main(int argc, char* argv[]) { char temp_str[512]; wave_io * wave1,*wave2; - uint16_t iq_wavebuf[ BUFFER_SAMPLES_SIZE * (IQ_SAMPLE_RATE/SUBCARRIERS_SAMPLE_RATE)]; + uint16_t iq_wavebuf[ BUFFER_SAMPLES_SIZE ]; int16_t wavebuf_dbg[BUFFER_SAMPLES_SIZE]; double wavebuf_dbg2[BUFFER_SAMPLES_SIZE]; - unsigned int i,j,k; + unsigned int i,j; int freq_bw; + int pulses_cnt; int ping_pong_freq; int jam_mode; int pulses_interval, pulses_interval_cnt; + int pulses_long_interval,pulses_short_interval; int pulses_duration, pulses_duration_cnt; + int pulses_group_nb; + int rand_interval,rand_duration; - double audio_sample_final; + double ping_pong_sample; double fm_mod; - double old_freq,interpolation_step; - uint32_t randdword; rand_gen_state randgen; iq_wave_gen iqgen; - wave_gen audio_l_gen; + wave_gen ping_pong_gen; verbose=0; stdoutmode = 0; @@ -178,6 +190,7 @@ int main(int argc, char* argv[]) pulses_interval_cnt = 0; rand_interval = 0; rand_duration = 0; + pulses_cnt = 0; if(isOption(argc,argv,"stdout",NULL)>0) { @@ -186,7 +199,7 @@ int main(int argc, char* argv[]) if(!stdoutmode) { - printf("rf_jammer v0.0.0.1\n"); + printf("rf_jammer v0.0.0.2\n"); printf("Copyright (C) 2022 Jean-Francois DEL NERO\n"); printf("This program comes with ABSOLUTELY NO WARRANTY\n"); printf("This is free software, and you are welcome to redistribute it\n"); @@ -207,6 +220,8 @@ int main(int argc, char* argv[]) } pulses_interval = 0; + pulses_short_interval = 0; + pulses_long_interval = 0; pulses_duration = 2000000; if(isOption(argc,argv,"freq_bw",(char*)&temp_str)>0) @@ -224,14 +239,32 @@ int main(int argc, char* argv[]) jam_mode = atoi(temp_str) ; } + iqgen.sample_rate = IQ_SAMPLE_RATE; + if(isOption(argc,argv,"iq_rate",(char*)&temp_str)>0) + { + iqgen.sample_rate = atoi(temp_str); + } + if(isOption(argc,argv,"jam_interval",(char*)&temp_str)>0) { - pulses_interval = atoi(temp_str) * (IQ_SAMPLE_RATE / 1000); + pulses_interval = us2ticks(iqgen.sample_rate, atoi(temp_str)); + pulses_short_interval = pulses_interval; } if(isOption(argc,argv,"jam_duration",(char*)&temp_str)>0) { - pulses_duration = atoi(temp_str) * (IQ_SAMPLE_RATE / 1000); + pulses_duration = us2ticks(iqgen.sample_rate, atoi(temp_str)); + } + + if(isOption(argc,argv,"jam_long_interval",(char*)&temp_str)>0) + { + pulses_long_interval = us2ticks(iqgen.sample_rate, atoi(temp_str)); + } + + pulses_group_nb = 0; + if(isOption(argc,argv,"jam_group_pulses",(char*)&temp_str)>0) + { + pulses_group_nb = atoi(temp_str); } if(isOption(argc,argv,"rand_interval",NULL)>0) @@ -246,21 +279,22 @@ int main(int argc, char* argv[]) if(isOption(argc,argv,"generate",0)>0) { + memset(iq_wavebuf, 0, BUFFER_SAMPLES_SIZE * sizeof(uint16_t) ); + rand_gen_init(&randgen, 0xC279DCEF ); // Init oscillators - // Left and Right audio freq (used if no .mod music file) - audio_l_gen.phase = 0; - audio_l_gen.Frequency = ((double)ping_pong_freq) / 100.0; - audio_l_gen.Amplitude = 100; - audio_l_gen.sample_rate = SUBCARRIERS_SAMPLE_RATE; + // ping pong freq + ping_pong_gen.phase = 0; + ping_pong_gen.Frequency = ((double)ping_pong_freq) / 100.0; + ping_pong_gen.Amplitude = 100; + ping_pong_gen.sample_rate = iqgen.sample_rate; // IQ Modulator iqgen.phase = 0; iqgen.Frequency = IF_FREQ; iqgen.Amplitude = 127; - iqgen.sample_rate = IQ_SAMPLE_RATE; if(stdoutmode) { @@ -272,96 +306,99 @@ int main(int argc, char* argv[]) { // file mode : create iq + wav files wave1 = create_wave("test.iq",iqgen.sample_rate,WAVE_FILE_FORMAT_RAW_8BITS_IQ); - wave2 = create_wave("test.wav",SUBCARRIERS_SAMPLE_RATE,WAVE_FILE_FORMAT_WAV_16BITS_MONO); + wave2 = create_wave("test.wav",iqgen.sample_rate,WAVE_FILE_FORMAT_WAV_16BITS_MONO); } if(wave1) { - old_freq = IF_FREQ; - // Main loop... for(i=0;(i<8) || stdoutmode ;i++) { - switch( jam_mode ) - { - case 0: // freq ping pong - for(j=0;j= pulses_group_nb) + { + pulses_interval = pulses_long_interval; + pulses_cnt = 0; + } + else + { + pulses_interval = pulses_short_interval; + } } else { - pulses_duration_cnt = 0; - pulses_interval_cnt = 0; - - if(rand_interval) - pulses_interval = (rand_gen_get_next_word(&randgen) & 0x7F) * (IQ_SAMPLE_RATE / 1000); - - if(rand_duration) - pulses_duration = (rand_gen_get_next_word(&randgen) & 0x7F) * (IQ_SAMPLE_RATE / 1000); + pulses_interval = pulses_short_interval; } + + if(rand_interval) + pulses_interval = (rand_gen_get_next_word(&randgen) & 0x7F) * (iqgen.sample_rate / 1000000); + + if(rand_duration) + pulses_duration = (rand_gen_get_next_word(&randgen) & 0x7F) * (iqgen.sample_rate / 1000000); } - - iq_wavebuf[(j*(IQ_SAMPLE_RATE/SUBCARRIERS_SAMPLE_RATE))+k] = get_next_iq(&iqgen);//iq_sample; } - - old_freq = wavebuf_dbg2[j]; } } else { - for(j=0;j= pulses_group_nb) + { + pulses_interval = pulses_long_interval; + pulses_cnt = 0; + } + else + { + pulses_interval = pulses_short_interval; + } + } + else + { + pulses_interval = pulses_short_interval; + } if(rand_interval) - pulses_interval = (rand_gen_get_next_word(&randgen) & 0x7F) * (IQ_SAMPLE_RATE / 1000); + pulses_interval = (rand_gen_get_next_word(&randgen) & 0x7F) * (iqgen.sample_rate / 1000000); if(rand_duration) - pulses_duration = (rand_gen_get_next_word(&randgen) & 0x7F) * (IQ_SAMPLE_RATE / 1000); + pulses_duration = (rand_gen_get_next_word(&randgen) & 0x7F) * (iqgen.sample_rate / 1000000); } } } } - write_wave(wave1, &iq_wavebuf,BUFFER_SAMPLES_SIZE*(IQ_SAMPLE_RATE/SUBCARRIERS_SAMPLE_RATE)); + write_wave(wave1, &iq_wavebuf,BUFFER_SAMPLES_SIZE); write_wave(wave2, &wavebuf_dbg,BUFFER_SAMPLES_SIZE); } close_wave(wave1);