Compare commits
No commits in common. "dev" and "master" have entirely different histories.
8 changed files with 65 additions and 371 deletions
4
Makefile
4
Makefile
|
|
@ -1,4 +0,0 @@
|
||||||
all: sentinel
|
|
||||||
|
|
||||||
sentinel: main.c
|
|
||||||
gcc -lncurses -lcurl -lrtlsdr -lm main.c -o sentinel
|
|
||||||
|
|
@ -10,12 +10,9 @@ mostly by scrapping API endpoints, gathering RSS feeds and getting readings from
|
||||||
but of course! if you wish to add support for your SDR or generally help me make this idea become true - go ahead! you can contact me at [hornet@lainlounge.xyz](mailto:hornet@lainlounge.xyz) via email or XMPP
|
but of course! if you wish to add support for your SDR or generally help me make this idea become true - go ahead! you can contact me at [hornet@lainlounge.xyz](mailto:hornet@lainlounge.xyz) via email or XMPP
|
||||||
|
|
||||||
## installation
|
## installation
|
||||||
```
|
WIP
|
||||||
git clone https://git.lainlounge.xyz/hornet/sentinel
|
|
||||||
cd sentinel
|
this is a C program, so everything here will be around compiling stuff with gcc, or maybe i'll learn how to use make properly
|
||||||
make
|
|
||||||
./sentinel
|
|
||||||
```
|
|
||||||
|
|
||||||
## roadmap
|
## roadmap
|
||||||
|
|
||||||
|
|
|
||||||
25
ascii/level1
25
ascii/level1
|
|
@ -1,25 +0,0 @@
|
||||||
MWMMMWWWWMWMWWMMMMMMWWMWWNMMWWMMMMMMMWMMMM
|
|
||||||
MWWWWWMMWMMWWWWWN0XNXNNNNKXKXWMMMWMMMMMMWW
|
|
||||||
MMMMMWMMMWMWKN0Kxccloxddlckxkk0XWMWMMWWWWM
|
|
||||||
WMMWMWMMMWWOcl,:. . .' 'dO0XWWMMWWW
|
|
||||||
MMMWMMMWWNO' .. .,dOKNMMMW
|
|
||||||
WWWWMWMMWd. ' .'kWWMW
|
|
||||||
WWMMWMWW0. . , .kWWW
|
|
||||||
MMMMMMMW: ; .. . . .KWM
|
|
||||||
MMMWMMWK' ;.:'d '. . cWM
|
|
||||||
MMMMMMM0. .:ol,'.;o0ko. . dx:'....xM
|
|
||||||
MWWMMMMW, ; . .'K.;lKNWWWN: . NWNXOdcllW
|
|
||||||
MWMMWMMMN;.c'; .'K:KXWWWMWo' ..kOWWWKoocM
|
|
||||||
WMMWMMMMMWcl:,': .O;llOKOkl,.:,dxlodlcol:M
|
|
||||||
MWWWMMMMMWW,kc.x.,OlO'locod..k'0kococlxldM
|
|
||||||
MWMMMMMMWWMoN,.d.;X:x0'xd.. ;l.xl:,.dkOOXW
|
|
||||||
MMWMMMMMMWWdO;.c.'d.lNdoK; .; l,..'XNWWWM
|
|
||||||
MMMMMMWWMMMdK. ,..; .XlxNO;..:.:;',oWMMWMM
|
|
||||||
MWWMWMWWMWMoO. '. oolOc',;,cc;'':WMMMWM
|
|
||||||
MWMWWWMWWWWlWc . .';,..',o,.. ;MMWWWW
|
|
||||||
MMWMWMMMMMXlN;; 'c:.. ...'..'0MMMWMM
|
|
||||||
MMWMMMMMWXd.ddx lok;.,..:klxOWMMWMWW
|
|
||||||
WMWMMWNNxl.'Ndl . .. .. . .d;xxKXXWWWM
|
|
||||||
NXXX0kkk. 'O,, :d. . . . ....:kxk0k0
|
|
||||||
dxc;. .. . . oxkl . . ...'':
|
|
||||||
' . . :0K' . .. ..
|
|
||||||
23
ascii/level2
23
ascii/level2
|
|
@ -1,23 +0,0 @@
|
||||||
|
|
||||||
................
|
|
||||||
.... .'.
|
|
||||||
'' ...
|
|
||||||
;. .,
|
|
||||||
.. .;
|
|
||||||
: ;
|
|
||||||
.; ;
|
|
||||||
'. .,
|
|
||||||
'. .,;;. c
|
|
||||||
: kNdWd 0K00 .;
|
|
||||||
.. ' ... .,,. :
|
|
||||||
,. , .; ''
|
|
||||||
., : l' ,c.
|
|
||||||
: .: :,;.. . . .;l.
|
|
||||||
; ., ::;;,,.. .cc:.
|
|
||||||
; .' .;:c;''','.,.;l:;
|
|
||||||
: .'..,;:;;,,;,;c'.,
|
|
||||||
:. '......,'...;
|
|
||||||
;. .....;...
|
|
||||||
..;; .'........
|
|
||||||
..... ...
|
|
||||||
|
|
||||||
23
ascii/level3
23
ascii/level3
|
|
@ -1,23 +0,0 @@
|
||||||
|
|
||||||
..............
|
|
||||||
..... ..'.
|
|
||||||
,' ........... .''
|
|
||||||
: .. ',
|
|
||||||
,. ........ .;
|
|
||||||
: ..... ;.
|
|
||||||
,. '. .. .. .,;
|
|
||||||
; '. .. ''
|
|
||||||
; c:,,,,,,,;kcllo:,;c'''..c,;;,:x
|
|
||||||
.',' .d''kNNo.,x..,xddNk .O;
|
|
||||||
:. .d;'.....o; .d;',. .0:
|
|
||||||
:. ..,o ....... ,;'';;,:l.
|
|
||||||
,. 'x. .. .: ..k.
|
|
||||||
: .k; .;. . .;, ..o,
|
|
||||||
; ,Oc .' ,;:;,,;.. 'c,
|
|
||||||
: co: .' XNWWWXXWO..o.
|
|
||||||
,. .'ok. KMMMMMMW;.x:
|
|
||||||
: lol. .0MMMNk':k,
|
|
||||||
.: ,. :dol..:l:'.oo.
|
|
||||||
...;. ., ,;cx':,ll'........
|
|
||||||
... .. .
|
|
||||||
...
|
|
||||||
27
ascii/level4
27
ascii/level4
|
|
@ -1,27 +0,0 @@
|
||||||
|
|
||||||
.:lcccccccl:;.
|
|
||||||
.'''. .''.
|
|
||||||
;'. .''
|
|
||||||
., ',.
|
|
||||||
c .;
|
|
||||||
o ......... .. .,
|
|
||||||
.. ...... .. c
|
|
||||||
c ..... ...... .:
|
|
||||||
l ....... ..... ..
|
|
||||||
: . ' c
|
|
||||||
: .d'XXx'. '.ld: '
|
|
||||||
' .'ool'. .;.O0c o
|
|
||||||
. , ..
|
|
||||||
. c '; '
|
|
||||||
. c .. :. .
|
|
||||||
; o c. .. ..c .
|
|
||||||
; .: . .
|
|
||||||
: , ', '........ ,
|
|
||||||
.; ' .,' .. .
|
|
||||||
c ,,
|
|
||||||
:. .. '''.. .
|
|
||||||
.:. :. ....l.
|
|
||||||
.'':; ., . '.......''..
|
|
||||||
.... .. ..
|
|
||||||
. .
|
|
||||||
|
|
||||||
23
ascii/level5
23
ascii/level5
|
|
@ -1,23 +0,0 @@
|
||||||
|
|
||||||
.,;cloodddoolc:;'...
|
|
||||||
.coxMMMMNOOO000000WMMMMMMWNKOd.
|
|
||||||
OMXo'.. ..,'.cMl
|
|
||||||
:Mc 'MW
|
|
||||||
NM. .. . ,MM.
|
|
||||||
.MM. ;:'. . . ...,o ;
|
|
||||||
...Md ;0XWMNKx;.. .'cd0XWW0d'. '
|
|
||||||
.. ; ..; ,:x:cl;.....'c;lox0;,.. ..
|
|
||||||
.: ...... , .. c. ...., ;
|
|
||||||
, .. ' ,........ '
|
|
||||||
' ' .. ..
|
|
||||||
' , ' '
|
|
||||||
.. .......' '
|
|
||||||
.. . ..
|
|
||||||
' .. ............ .. ,
|
|
||||||
' .:............,, '
|
|
||||||
.. . .. ... ..'
|
|
||||||
' ........ ..
|
|
||||||
... .. .. ..
|
|
||||||
.. ...
|
|
||||||
.......
|
|
||||||
|
|
||||||
302
main.c
302
main.c
|
|
@ -3,10 +3,8 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <ctype.h>
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/ioctl.h>
|
|
||||||
#include <ncurses.h>
|
#include <ncurses.h>
|
||||||
#include <rtl-sdr.h>
|
#include <rtl-sdr.h>
|
||||||
#include <curl/curl.h>
|
#include <curl/curl.h>
|
||||||
|
|
@ -36,18 +34,6 @@
|
||||||
|
|
||||||
#define M_PI 3.14159265358979323846
|
#define M_PI 3.14159265358979323846
|
||||||
|
|
||||||
/*define DEFCON level stuff */
|
|
||||||
#define DEFCON_URL "https://defconwarningsystem.com/code.dat"
|
|
||||||
unsigned int level;
|
|
||||||
unsigned int cooldown = 1800;
|
|
||||||
unsigned int cooldown_timer = 0;
|
|
||||||
bool cooldown_reset = false;
|
|
||||||
|
|
||||||
size_t write_data(void *ptr1, size_t size, size_t nmemb, FILE *stream) {
|
|
||||||
size_t written = fwrite(ptr1, size, nmemb, stream);
|
|
||||||
return written;
|
|
||||||
};
|
|
||||||
|
|
||||||
/* declare global variables */
|
/* declare global variables */
|
||||||
|
|
||||||
rtlsdr_dev_t *dev = NULL;
|
rtlsdr_dev_t *dev = NULL;
|
||||||
|
|
@ -60,38 +46,9 @@ bool SDR_PRESENT = false;
|
||||||
bool RSS_LIST_PRESENT = false;
|
bool RSS_LIST_PRESENT = false;
|
||||||
bool COMMS_AVAILABLE = false;
|
bool COMMS_AVAILABLE = false;
|
||||||
bool CURL_AVAILABLE = false;
|
bool CURL_AVAILABLE = false;
|
||||||
int term_rows, term_cols;
|
|
||||||
|
|
||||||
/* declare ncurses windows */
|
|
||||||
|
|
||||||
WINDOW * sdr;
|
|
||||||
WINDOW * rss;
|
|
||||||
WINDOW * defcon;
|
|
||||||
|
|
||||||
/* startup screen! :3 */
|
|
||||||
|
|
||||||
void startup_screen() {
|
|
||||||
printf("\n\n");
|
|
||||||
printf(CYAN" █████ ███ ████ \n");
|
|
||||||
printf(" ░░███ ░░░ ░░███ \n");
|
|
||||||
printf(" █████ ██████ ████████ ███████ ████ ████████ ██████ ░███ \n");
|
|
||||||
printf(" ███░░ ███░░███░░███░░███ ░░░███░ ░░███ ░░███░░███ ███░░███ ░███ \n");
|
|
||||||
printf("░░█████ ░███████ ░███ ░███ ░███ ░███ ░███ ░███ ░███████ ░███ \n");
|
|
||||||
printf(" ░░░░███░███░░░ ░███ ░███ ░███ ███ ░███ ░███ ░███ ░███░░░ ░███ \n");
|
|
||||||
printf(" ██████ ░░██████ ████ █████ ░░█████ █████ ████ █████░░██████ █████\n");
|
|
||||||
printf("░░░░░░ ░░░░░░ ░░░░ ░░░░░ ░░░░░ ░░░░░ ░░░░ ░░░░░ ░░░░░░ ░░░░░ \n\n");
|
|
||||||
printf(" v0.0.1\n" RESET);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* declare reusable functions */
|
/* declare reusable functions */
|
||||||
|
|
||||||
void get_terminal_size(int *rows, int *cols) {
|
|
||||||
struct winsize w;
|
|
||||||
ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
|
|
||||||
*rows = w.ws_row;
|
|
||||||
*cols = w.ws_col;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* read out shell command output */
|
/* read out shell command output */
|
||||||
char* readout(const char* command, char* buffer, size_t size) {
|
char* readout(const char* command, char* buffer, size_t size) {
|
||||||
FILE *fp = popen(command, "r");
|
FILE *fp = popen(command, "r");
|
||||||
|
|
@ -110,6 +67,19 @@ char* readout(const char* command, char* buffer, size_t size) {
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void startup_screen() {
|
||||||
|
printf("\n\n");
|
||||||
|
printf(CYAN" █████ ███ ████ \n");
|
||||||
|
printf(" ░░███ ░░░ ░░███ \n");
|
||||||
|
printf(" █████ ██████ ████████ ███████ ████ ████████ ██████ ░███ \n");
|
||||||
|
printf(" ███░░ ███░░███░░███░░███ ░░░███░ ░░███ ░░███░░███ ███░░███ ░███ \n");
|
||||||
|
printf("░░█████ ░███████ ░███ ░███ ░███ ░███ ░███ ░███ ░███████ ░███ \n");
|
||||||
|
printf(" ░░░░███░███░░░ ░███ ░███ ░███ ███ ░███ ░███ ░███ ░███░░░ ░███ \n");
|
||||||
|
printf(" ██████ ░░██████ ████ █████ ░░█████ █████ ████ █████░░██████ █████\n");
|
||||||
|
printf("░░░░░░ ░░░░░░ ░░░░ ░░░░░ ░░░░░ ░░░░░ ░░░░ ░░░░░ ░░░░░░ ░░░░░ \n\n");
|
||||||
|
printf(" v0.0.1\n" RESET);
|
||||||
|
}
|
||||||
|
|
||||||
/* declare functions for startup checks */
|
/* declare functions for startup checks */
|
||||||
void util_check() {
|
void util_check() {
|
||||||
printf("curl: ");
|
printf("curl: ");
|
||||||
|
|
@ -157,8 +127,8 @@ void defcon_level_check() {
|
||||||
fputc(5, fp);
|
fputc(5, fp);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
} else {
|
} else {
|
||||||
int last_known_startup = fgetc(fp);
|
int last_known = fgetc(fp);
|
||||||
printf("DEFCON level cache file found! last known level: %d\n", last_known_startup);
|
printf("DEFCON level cache file found! last known level: %d\n", last_known);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -194,7 +164,6 @@ void rss_sources_check() {
|
||||||
|
|
||||||
|
|
||||||
/* making sure program has everything it needs to run, more checks will be introduced as capabilities are added */
|
/* making sure program has everything it needs to run, more checks will be introduced as capabilities are added */
|
||||||
|
|
||||||
void startup_checks() {
|
void startup_checks() {
|
||||||
printf("######################################################################\n");
|
printf("######################################################################\n");
|
||||||
printf(MAGENTA"STARTUP CHECKS\n"RESET);
|
printf(MAGENTA"STARTUP CHECKS\n"RESET);
|
||||||
|
|
@ -211,13 +180,9 @@ void startup_checks() {
|
||||||
} else {
|
} else {
|
||||||
printf("internet connectivity status: ");
|
printf("internet connectivity status: ");
|
||||||
printf(RED"offline\n"RESET);
|
printf(RED"offline\n"RESET);
|
||||||
printf(RED"internet-dependent capabilities will be unavailable!\n"RESET);
|
printf(RED"internet-dependent capabilities will be unavailable!"RESET);
|
||||||
COMMS_AVAILABLE = false;
|
COMMS_AVAILABLE = false;
|
||||||
}
|
}
|
||||||
/* get terminal size */
|
|
||||||
get_terminal_size(&term_rows, &term_cols);
|
|
||||||
printf("terminal size: ");
|
|
||||||
printf(YELLOW"%dx%d\n"RESET, term_rows, term_cols);
|
|
||||||
printf("----------------------------------------------------------------------\n");
|
printf("----------------------------------------------------------------------\n");
|
||||||
/* utilities presence check */
|
/* utilities presence check */
|
||||||
printf(MAGENTA"UTILITIES\n\n"RESET);
|
printf(MAGENTA"UTILITIES\n\n"RESET);
|
||||||
|
|
@ -235,7 +200,7 @@ void startup_checks() {
|
||||||
printf(MAGENTA"all checks finished!\n"RESET);
|
printf(MAGENTA"all checks finished!\n"RESET);
|
||||||
printf("######################################################################\n");
|
printf("######################################################################\n");
|
||||||
printf(BLUE"initializing in 5 seconds...\n\n"RESET);
|
printf(BLUE"initializing in 5 seconds...\n\n"RESET);
|
||||||
//usleep(5000000);
|
usleep(5000000);
|
||||||
if (SDR_PRESENT == true)
|
if (SDR_PRESENT == true)
|
||||||
{
|
{
|
||||||
printf(GREEN"initializing RTL-SDR...\n"RESET);
|
printf(GREEN"initializing RTL-SDR...\n"RESET);
|
||||||
|
|
@ -244,38 +209,9 @@ void startup_checks() {
|
||||||
if (RSS_LIST_PRESENT == true && COMMS_AVAILABLE == true && CURL_AVAILABLE == true) {
|
if (RSS_LIST_PRESENT == true && COMMS_AVAILABLE == true && CURL_AVAILABLE == true) {
|
||||||
printf(GREEN"initializing RSS aggregator...\n"RESET);
|
printf(GREEN"initializing RSS aggregator...\n"RESET);
|
||||||
}
|
}
|
||||||
if (COMMS_AVAILABLE == true && CURL_AVAILABLE == true) {
|
|
||||||
printf(GREEN"initializing DEFCON level parser...\n"RESET);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* define functions for dashboard - WIP */
|
|
||||||
|
|
||||||
void init_colors() {
|
|
||||||
start_color();
|
|
||||||
init_pair(1, COLOR_RED, COLOR_BLACK);
|
|
||||||
init_pair(2, COLOR_GREEN, COLOR_BLACK);
|
|
||||||
init_pair(3, COLOR_YELLOW, COLOR_BLACK);
|
|
||||||
init_pair(4, COLOR_BLUE, COLOR_BLACK);
|
|
||||||
init_pair(5, COLOR_MAGENTA, COLOR_BLACK);
|
|
||||||
init_pair(6, COLOR_CYAN, COLOR_BLACK);
|
|
||||||
init_pair(7, COLOR_WHITE, COLOR_BLACK);
|
|
||||||
init_pair(8, COLOR_WHITE, COLOR_RED);
|
|
||||||
init_pair(9, COLOR_WHITE, COLOR_GREEN);
|
|
||||||
}
|
|
||||||
|
|
||||||
void print_centered(WINDOW *win, const char *text) {
|
|
||||||
int width = getmaxx(win);
|
|
||||||
int height = getmaxy(win)/2;
|
|
||||||
int length = strlen(text);
|
|
||||||
int start_col = (width - length) / 2;
|
|
||||||
mvwprintw(win, height, start_col, "%s", text);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* define rtl-sdr specific functions and general SDR workflow - WIP */
|
|
||||||
|
|
||||||
/* signal analysis function */
|
/* signal analysis function */
|
||||||
void fourier_transform(unsigned char *buf, double *out, int n) {
|
void fourier_transform(unsigned char *buf, double *out, int n) {
|
||||||
for (int k = 0; k < n; k++) {
|
for (int k = 0; k < n; k++) {
|
||||||
|
|
@ -290,12 +226,25 @@ void fourier_transform(unsigned char *buf, double *out, int n) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* define functions for dashboard - WIP */
|
||||||
|
|
||||||
|
void init_colors() {
|
||||||
|
start_color();
|
||||||
|
init_pair(1, COLOR_RED, COLOR_BLACK);
|
||||||
|
init_pair(2, COLOR_GREEN, COLOR_BLACK);
|
||||||
|
init_pair(3, COLOR_YELLOW, COLOR_BLACK);
|
||||||
|
init_pair(4, COLOR_BLUE, COLOR_BLACK);
|
||||||
|
init_pair(5, COLOR_MAGENTA, COLOR_BLACK);
|
||||||
|
init_pair(6, COLOR_CYAN, COLOR_BLACK);
|
||||||
|
init_pair(7, COLOR_WHITE, COLOR_BLACK);
|
||||||
|
}
|
||||||
|
|
||||||
void draw_bar_graph(double *data, int size) {
|
void draw_bar_graph(double *data, int size) {
|
||||||
wclear(sdr);
|
clear();
|
||||||
double max_value = 0.0;
|
double max_value = 0.0;
|
||||||
wattron(sdr, COLOR_PAIR(6));
|
attron(COLOR_PAIR(6));
|
||||||
wprintw(sdr, "center frequency: %.3f MHz gain: %d bandwidth: %.3f MHz", center_freq / (double)MHz, rtlsdr_get_tuner_gain(dev), bandwidth / (double)MHz);
|
printw("center frequency: %.3f MHz gain: %d bandwidth: %.3f MHz", center_freq / (double)MHz, rtlsdr_get_tuner_gain(dev), bandwidth / (double)MHz);
|
||||||
wattroff(sdr, COLOR_PAIR(6));
|
attroff(COLOR_PAIR(6));
|
||||||
double bottom = center_freq - bandwidth / 2.0;
|
double bottom = center_freq - bandwidth / 2.0;
|
||||||
double step = bandwidth / (double)size;
|
double step = bandwidth / (double)size;
|
||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
|
|
@ -303,17 +252,20 @@ void draw_bar_graph(double *data, int size) {
|
||||||
max_value = data[i];
|
max_value = data[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
wattron(sdr, COLOR_PAIR(4));
|
attron(COLOR_PAIR(4));
|
||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
mvwprintw(sdr, i + 1, 0, "%.3f MHz: ", bottom / (double)MHz + i * step / (double)MHz);
|
mvprintw(i + 1, 0, "%.3f MHz: ", bottom / (double)MHz + i * step / (double)MHz);
|
||||||
for (int j = 0; j < data[i] * 50 / max_value; j++) {
|
for (int j = 0; j < data[i] * 50 / max_value; j++) {
|
||||||
wprintw(sdr, ">");
|
printw(">");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
wattroff(sdr, COLOR_PAIR(4));
|
attroff(COLOR_PAIR(4));
|
||||||
wrefresh(sdr);
|
refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* define rtl-sdr specific functions and general SDR workflow - WIP */
|
||||||
|
|
||||||
void rtl_sdr_processing(unsigned char *buf, int buffer_length) {
|
void rtl_sdr_processing(unsigned char *buf, int buffer_length) {
|
||||||
int n = buffer_length;
|
int n = buffer_length;
|
||||||
double *out = (double *)malloc(n * sizeof(double));
|
double *out = (double *)malloc(n * sizeof(double));
|
||||||
|
|
@ -329,7 +281,7 @@ void rtl_sdr_processing(unsigned char *buf, int buffer_length) {
|
||||||
void rtl_sdr_waterfall() {
|
void rtl_sdr_waterfall() {
|
||||||
bandwidth = 10*MHz;
|
bandwidth = 10*MHz;
|
||||||
rtlsdr_set_tuner_bandwidth(dev, bandwidth);
|
rtlsdr_set_tuner_bandwidth(dev, bandwidth);
|
||||||
uint32_t buffer_length = getmaxy(sdr)-2, n_read = 10; // example buffer length
|
uint32_t buffer_length = 40, n_read = 10; // example buffer length
|
||||||
unsigned char *buffer = (unsigned char *)malloc(buffer_length);
|
unsigned char *buffer = (unsigned char *)malloc(buffer_length);
|
||||||
rtlsdr_set_center_freq(dev, 104*MHz); //104MHz for testing purposes
|
rtlsdr_set_center_freq(dev, 104*MHz); //104MHz for testing purposes
|
||||||
center_freq = rtlsdr_get_center_freq(dev);
|
center_freq = rtlsdr_get_center_freq(dev);
|
||||||
|
|
@ -338,77 +290,17 @@ void rtl_sdr_waterfall() {
|
||||||
usleep(500000);
|
usleep(500000);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* RSS feed functions & workflow - WIP */
|
void sdr_not_available() {
|
||||||
|
clear();
|
||||||
|
attron(COLOR_PAIR(1));
|
||||||
|
printw("SDR NOT AVAILABLE");
|
||||||
|
attroff(COLOR_PAIR(1));
|
||||||
|
refresh();
|
||||||
|
usleep(5000000);
|
||||||
|
}
|
||||||
|
|
||||||
/* DEFCON level functions */
|
/* DEFCON level functions */
|
||||||
|
|
||||||
char fetch_defcon_level() {
|
|
||||||
CURL *curl;
|
|
||||||
CURLcode res;
|
|
||||||
FILE *fp;
|
|
||||||
unsigned int current_level = 5; //nothing ever happens
|
|
||||||
unsigned int last_known;
|
|
||||||
cooldown_timer++;
|
|
||||||
|
|
||||||
if(cooldown_timer > cooldown_reset){
|
|
||||||
cooldown_reset = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cooldown_reset = true) {
|
|
||||||
|
|
||||||
curl = curl_easy_init();
|
|
||||||
if (curl) {
|
|
||||||
fp = fopen(".last_known_defcon", "w");
|
|
||||||
if (fp == NULL) {
|
|
||||||
perror("fopen");
|
|
||||||
return current_level;
|
|
||||||
}
|
|
||||||
|
|
||||||
curl_easy_setopt(curl, CURLOPT_URL, DEFCON_URL);
|
|
||||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
|
|
||||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
|
|
||||||
|
|
||||||
res = curl_easy_perform(curl);
|
|
||||||
if (res != CURLE_OK) {
|
|
||||||
fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
|
|
||||||
} else {
|
|
||||||
fseek(fp, 0, SEEK_SET);
|
|
||||||
int ch = fgetc(fp);
|
|
||||||
if (isdigit(ch)){
|
|
||||||
current_level = ch - '0'; // read the DEFCON level from the file
|
|
||||||
last_known = current_level;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fclose(fp);
|
|
||||||
curl_easy_cleanup(curl);
|
|
||||||
} else {
|
|
||||||
print_centered(defcon, "HTTP request failed :(");
|
|
||||||
}
|
|
||||||
|
|
||||||
return current_level;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
current_level = last_known;
|
|
||||||
return current_level;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void print_file_lines_ncurses(const char *filename, WINDOW *win) {
|
|
||||||
FILE *file = fopen(filename, "r");
|
|
||||||
if (file == NULL) {
|
|
||||||
perror("fopen");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
char line[256];
|
|
||||||
int y = 1;
|
|
||||||
while (fgets(line, sizeof(line), file) != NULL) {
|
|
||||||
mvwprintw(win, y++, 1, "%s", line);
|
|
||||||
wrefresh(win);
|
|
||||||
}
|
|
||||||
fclose(file);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* main dashboard function */
|
/* main dashboard function */
|
||||||
|
|
||||||
|
|
@ -417,91 +309,21 @@ void start_dashboard() {
|
||||||
cbreak();
|
cbreak();
|
||||||
noecho();
|
noecho();
|
||||||
init_colors();
|
init_colors();
|
||||||
refresh();
|
if (SDR_PRESENT == true) {
|
||||||
WINDOW * sdr = newwin(term_rows/2-2, term_cols/2, 1, 1);
|
do{
|
||||||
WINDOW * rss = newwin(term_rows-2, term_cols/2-2, 1, term_cols/2+2);
|
|
||||||
WINDOW * defcon = newwin(term_rows/2, term_cols/2, term_rows/2, 1);
|
|
||||||
box(sdr, 0, 0);
|
|
||||||
box(rss, 0, 0);
|
|
||||||
box(defcon, 0, 0);
|
|
||||||
wrefresh(sdr);
|
|
||||||
wrefresh(rss);
|
|
||||||
wrefresh(defcon);
|
|
||||||
|
|
||||||
while(true) {
|
|
||||||
/* SDR window */
|
|
||||||
if (SDR_PRESENT == true) {
|
|
||||||
rtl_sdr_waterfall();
|
rtl_sdr_waterfall();
|
||||||
}
|
} while (true);
|
||||||
else {
|
|
||||||
wbkgd(sdr, COLOR_PAIR(8));
|
|
||||||
print_centered(sdr, "SDR NOT AVAILABLE");
|
|
||||||
wrefresh(sdr);
|
|
||||||
usleep(1000000);
|
|
||||||
}
|
|
||||||
/* RSS window */
|
|
||||||
if (COMMS_AVAILABLE == true && CURL_AVAILABLE == true) {
|
|
||||||
wbkgd(rss, COLOR_PAIR(9));
|
|
||||||
print_centered(rss, "RSS FEED AVAILABLE");
|
|
||||||
wrefresh(rss);
|
|
||||||
usleep(1000000);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
wbkgd(rss, COLOR_PAIR(8));
|
|
||||||
print_centered(rss, "RSS FEEED NOT AVAILABLE");
|
|
||||||
wrefresh(rss);
|
|
||||||
usleep(1000000);
|
|
||||||
}
|
|
||||||
/* DEFCON window */
|
|
||||||
if (COMMS_AVAILABLE == true && CURL_AVAILABLE == true) {
|
|
||||||
level = fetch_defcon_level();
|
|
||||||
switch(level) {
|
|
||||||
case 5:
|
|
||||||
wbkgd(defcon, COLOR_PAIR(4));
|
|
||||||
print_file_lines_ncurses("./ascii/level5", defcon);
|
|
||||||
wprintw(defcon, " DEFCON 5 - NOTHING EVER HAPPENS");
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
wbkgd(defcon, COLOR_PAIR(2));
|
|
||||||
print_file_lines_ncurses("./ascii/level4", defcon);
|
|
||||||
wprintw(defcon, " DEFCON 4 - UNLIKELY TO HAPPEN");
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
wbkgd(defcon, COLOR_PAIR(5));
|
|
||||||
print_file_lines_ncurses("./ascii/level3", defcon);
|
|
||||||
wprintw(defcon, " DEFCON 3 - MAYBE IT WILL HAPPEN");
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
wbkgd(defcon, COLOR_PAIR(3));
|
|
||||||
print_file_lines_ncurses("./ascii/level2", defcon);
|
|
||||||
wprintw(defcon, " DEFCON 2 - SOMETHING WILL HAPPEN");
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
wbkgd(defcon, COLOR_PAIR(1));
|
|
||||||
print_file_lines_ncurses("./ascii/level1", defcon);
|
|
||||||
wprintw(defcon, " DEFCON 1 - IT IS HAPPENING");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
wbkgd(defcon, COLOR_PAIR(4));
|
|
||||||
print_file_lines_ncurses("./ascii/level5", defcon);
|
|
||||||
wprintw(defcon, " DEFCON 5 - NOTHING EVER HAPPENS"); //because nothing ever happens
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
wrefresh(defcon);
|
|
||||||
usleep(1000000);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
wbkgd(defcon, COLOR_PAIR(8));
|
|
||||||
print_centered(defcon, "DEFCON CHECK NOT AVAILABLE");
|
|
||||||
wrefresh(defcon);
|
|
||||||
usleep(1000000);
|
|
||||||
}
|
|
||||||
|
|
||||||
rtlsdr_close(dev);
|
|
||||||
endwin();
|
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
do{
|
||||||
|
sdr_not_available();
|
||||||
|
} while (true);
|
||||||
|
}
|
||||||
|
rtlsdr_close(dev);
|
||||||
|
endwin();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
startup_screen();
|
startup_screen();
|
||||||
startup_checks();
|
startup_checks();
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue