-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsniffing_task.c
123 lines (79 loc) · 3.07 KB
/
sniffing_task.c
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
/*
* radio_task.c
*
* Created on: 7. 2. 2024
* Author: vojtechlukas
*/
// === INCLUDES =================================================================================================
#include "ti_drivers_config.h"
#include "ti_radio_config.h"
#include <stdio.h>
#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Task.h>
#include <ti/sysbios/knl/Semaphore.h>
#include <stdint.h>
#include <source/queue/radio_queue.h>
#include <source/utils/stv.h>
#include <source/ethernet/Ethernet.h>
#include <source/ethernet/EthernetUdp.h>
#include <source/utils/restart.h>
#include <sniffing_task.h>
#include <source/radio_proc/radio_proc.h>
#include <source/oled_gui/gui.h>
#include <source/utils/log.h>
//===============================================================================================================
// === GLOBAL VARIABLES =========================================================================================
extern uint32_t nRxBufFull;
EthernetUDP ethernetUdp;
extern rfc_bleGenericRxOutput_t bleStats;
extern rfc_ieeeRxOutput_t ieeeStats;
// === MAIN TASK FUNCTION =======================================================================================
/*
* === Sniffing_Main
* This task ensures core functionality of the device. Firstly, it initializes
* the RF Core and if Startup Vectors are configured that way, it starts sniffing.
* Then it falls into infinite loop, where it periodically checks for new frames in
* RF queue. If it founds one, it creates a UDP packet and fills it with appropriate
* data.
*
* Parameters:
* a0 - Not used
* a1 - Not used
* Returns:
* N/A
*/
void Sniffing_Main(UArg a0, UArg a1)
{
const uint8_t accessAddress[] = {0xD6, 0xBE, 0x89, 0x8E};
const uint8_t rxChannel = STV_ReadFromAddress(STVW_RF_CHANNEL);
const RF_Protocol_t proto = STV_ReadFromAddress(STVW_RF_PROTOCOL) == STV_RF_PROTO_BLE ? BluetoothLowEnergy : IEEE_802_15_4;
IPAddress *targetIp = (IPAddress *)STVW_TARGET_IP_ADDRESS;
RadioQueue_init();
RadioQueue_reset();
EthernetUDP_begin_init(ðernetUdp);
EthernetUDP_begin(ðernetUdp, 2014);
if (STV_ReadFromAddress(STVW_RUNNING_STATUS) == 0x52)
{
Radio_SetUpAndBeginRx(proto, rxChannel);
GUI_ChangeRx(1);
}
for (;;)
{
if (RadioQueue_hasPacket())
{
uint8_t buffer[2047];
uint16_t packetLen = RadioQueue_takePacket(buffer, 2047);
EthernetUDP_beginPacket_ip(ðernetUdp, *targetIp, 2014);
EthernetUDP_write_byte(ðernetUdp, (uint8_t)Radio_GetCurrentProtocol());
if (Radio_GetCurrentProtocol() == BluetoothLowEnergy)
{
EthernetUDP_write(ðernetUdp, (uint8_t *)accessAddress, 4);
}
EthernetUDP_write(ðernetUdp, (uint8_t *)buffer, packetLen);
EthernetUDP_endPacket(ðernetUdp);
}
Log_print("BLE RX CMD", &RFCMD_bleGenericRX, CmdStatus);
Log_print("IEEE RX CMD", &RFCMD_ieeeRX, CmdStatus);
Task_sleep(10);
}
}