-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPEM_final_Ebpf_main.py
More file actions
347 lines (236 loc) · 10.3 KB
/
PEM_final_Ebpf_main.py
File metadata and controls
347 lines (236 loc) · 10.3 KB
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
#!/usr/bin/python
#
# iwlstrength.py iwl wifi stregth as audio
# For Linux, uses BCC, eBPF. Embedded C.
#
# Tone generation from: https://gist.github.com/nekozing/5774628
#
# 29-Apr-2019 Brendan Gregg Created this.
from __future__ import print_function
from bcc import BPF
from bcc.utils import printb
import time
# import numpy
# BPF
b = BPF(text="""
#include <uapi/linux/ptrace.h>
#include <bcc/proto.h>
#include <net/mac80211.h>
#include "/home/siotlab1/Desktop/linux-5.8/net/mac80211/ieee80211_i.h"
#include <uapi/linux/ptrace.h>
#include <linux/dma-mapping.h>
#include "/home/siotlab1/Desktop/linux-5.8/drivers/net/wireless/ath/ath9k/ath9k.h"
#include </home/siotlab1/Desktop/linux-5.8/include/linux/ieee80211.h>
#include </home/siotlab1/Desktop/linux-5.8/include/uapi/linux/time.h>
struct prio_sched_data {
int bands;
struct tcf_proto __rcu *filter_list;
struct tcf_block *block;
u8 prio2band[TC_PRIO_MAX+1];
struct Qdisc *queues[TCQ_PRIO_BANDS];
};
int kprobe____ieee80211_beacon_add_tim(struct pt_regs *ctx,struct ieee80211_sub_if_data *sdata,
struct ps_data *ps, struct sk_buff *skb,
bool is_template) {
u64 ts = bpf_ktime_get_ns();
u64 tim;
bpf_probe_read(&tim, sizeof(tim), &ps->tim);
bpf_trace_printk("[2021][ath10k_wmi_event_host_swba] [1] bitmap: %x\\n", tim);
return 0;
}
int kprobe__ath_tx_process_buffer(struct pt_regs *ctx, struct ath_softc *sc, struct ath_txq *txq,
struct ath_tx_status *ts, struct ath_buf *bf,
struct list_head *bf_head)
{
struct ieee80211_hdr * hdr = (struct ieee80211_hdr *)bf->bf_mpdu->data;
u8 addr1[6],addr2[6];
bpf_probe_read(&addr1, sizeof(addr1), &hdr->addr1);
bpf_probe_read(&addr2, sizeof(addr2), &hdr->addr2);
struct ieee80211_hw *hw = (struct ieee80211_hw *)sc->hw;
u8 match_addr1[6];
match_addr1[0] = 0xa4;
match_addr1[1] = 0x08;
match_addr1[2] = 0xea;
if( (match_addr1[0] == addr1[0] && match_addr1[1] == addr1[1] && match_addr1[1] == addr1[1]))
{
bpf_trace_printk("[2021][ath_tx_process_bufffer][mac80211_qnum] ... %d\\n", txq->mac80211_qnum);
bpf_trace_printk("[2021][ath_tx_process_bufffer][axq_qnum] ... %d\\n", txq->axq_qnum);
bpf_trace_printk("[2021][ath_tx_process_bufffer][axq_depth] ... %d\\n", txq->axq_depth);
bpf_trace_printk("[2021][ath_tx_process_bufffer][axq_ampdu_depth] ... %d\\n", txq->axq_ampdu_depth);
bpf_trace_printk("[2021][ath_tx_process_bufffer][txq_tailidx] ... %d\\n", txq->txq_tailidx);
bpf_trace_printk("[2021][ath_tx_process_bufffer][pending_frames] ... %d\\n", txq->pending_frames);
bpf_trace_printk("[2021][ath_tx_process_buffer]::7::peerd[1] %x:%x:%x\\n", addr1[0], addr1[1], addr1[2]);
bpf_trace_printk("[2021][ath_tx_process_buffer]::7::peerd[2] %x:%x:%x\\n", addr1[3], addr1[4], addr1[5]);
}
return 0;
}
int kprobe__br_handle_frame_finish(struct pt_regs *ctx,struct net *net, struct sock *sk, struct sk_buff *skb)
{
struct iphdr *ip_header = (struct iphdr *) (skb->head + skb->network_header);
struct ethhdr *mh = (struct ethhdr *) ( skb->head + skb->mac_header);
if (skb->mac_len ==14)
{
if (ip_header->daddr == 0xf1e0100a)
{
bpf_trace_printk("\\n");
bpf_trace_printk("[2021][br_handle_frame_finish]Source IP[1]=%x\\n",ip_header->daddr);
bpf_trace_printk("[2021][br_handle_frame_finish]Source MAC[1]=%x:%x:%x\\n",mh->h_dest[0],mh->h_dest[1],mh->h_dest[2]);
}
}
return 0;
}
int kprobe__dev_hard_start_xmit(struct pt_regs *ctx,struct sk_buff *first, struct net_device *dev,
struct netdev_queue *txq, int *ret)
{
struct iphdr *ip_header = (struct iphdr *) (first->head + first->network_header);
struct ethhdr *mh = (struct ethhdr *) ( first->head + first->mac_header);
if (first->mac_len ==14)
{
if (ip_header->daddr == 0xf1e0100a)
{
bpf_trace_printk("[2021][dev_hard_start_xmit]Source IP[1]=%x\\n",ip_header->daddr);
bpf_trace_printk("[2021][dev_hard_start_xmit]Source MAC[1]=%x:%x:%x\\n",mh->h_dest[0],mh->h_dest[1],mh->h_dest[2]);
}
}
return 0;
}
int kprobe__ieee80211_tx_pending(struct pt_regs *ctx)
{
bpf_trace_printk("[2021][ieee80211_tx_pending]\\n");
return 0;
}
int kprobe__ieee80211_queue_skb(struct pt_regs *ctx,struct ieee80211_local *local,
struct ieee80211_sub_if_data *sdata,
struct sta_info *sta,
struct sk_buff *skb)
{
return 0;
}
int kprobe__ieee80211_xmit(struct pt_regs *ctx, struct ieee80211_sub_if_data *sdata,
struct sta_info *sta, struct sk_buff *skb)
{
struct ieee80211_hdr * hdr = (struct ieee80211_hdr *)skb->data;
u8 addr1[6],addr2[6];
bpf_probe_read(&addr1, sizeof(addr1), &hdr->addr1);
bpf_probe_read(&addr2, sizeof(addr2), &hdr->addr2);
u8 match_addr1[6];
match_addr1[0] = 0xa4;
match_addr1[1] = 0x8;
match_addr1[2] = 0xea;
if( (match_addr1[0] == addr1[0] && match_addr1[1] == addr1[1] && match_addr1[1] == addr1[1]))
{
bpf_trace_printk("[2021][ieee80211_xmit]::7::peerd[1] %x:%x:%x\\n", addr1[0], addr1[1], addr1[2]);
bpf_trace_printk("[2021][ieee80211_xmit]::7::peerd[2] %x:%x:%x\\n", addr1[3], addr1[4], addr1[5]);
}
return 0;
}
int kprobe__ath_tx_txqaddbuf(struct pt_regs *ctx,struct ath_softc *sc, struct ath_txq *txq,
struct list_head *head, bool internal)
{
struct ath_buf *bf = (struct ath_buf *) head->prev;
struct ieee80211_hdr * hdr = (struct ieee80211_hdr *)bf->bf_mpdu->data;
u8 addr1[6],addr2[6];
bpf_probe_read(&addr1, sizeof(addr1), &hdr->addr1);
bpf_probe_read(&addr2, sizeof(addr2), &hdr->addr2);
u8 match_addr1[6];
match_addr1[0] = 0xa4;
match_addr1[1] = 0x08;
match_addr1[2] = 0xea;
if( (match_addr1[0] == addr1[0] && match_addr1[1] == addr1[1] && match_addr1[1] == addr1[1]))
{
bpf_trace_printk("[2021][ath_tx_txqaddbuf]::7::peerd[1] %x:%x:%x\\n", addr1[0], addr1[1], addr1[2]);
bpf_trace_printk("[2021][ath_tx_txqaddbuf]::7::peerd[2] %x:%x:%x\\n", addr1[3], addr1[4], addr1[5]);
}
return 0;
}
int kprobe____sta_info_recalc_tim(struct pt_regs *ctx, struct sta_info *sta)
{
u8 addr1[6];
bpf_probe_read(&addr1, sizeof(addr1), &sta->sta.addr);
u8 match_addr1[6];
match_addr1[0] = 0xa4;
match_addr1[1] = 0x08;
match_addr1[2] = 0xea;
if( (match_addr1[0] == addr1[0] && match_addr1[1] == addr1[1] && match_addr1[1] == addr1[1]))
{
bpf_trace_printk("[2021][__sta_info_recalc_tim]::7::peerd[1] %x:%x:%x\\n", addr1[0], addr1[1], addr1[2]);
bpf_trace_printk("[2021][__sta_info_recalc_tim]::7::peerd[2] %x:%x:%x\\n", addr1[3], addr1[4], addr1[5]);
bpf_trace_printk("[2021][__sta_info_recalc_tim]::7::peerd[3] aid %d: PS buffer for AC %d \\n", sta->sta.aid, sta->sta.aid);
}
return 0;
}
int kprobe__ath_tx_complete_buf(struct pt_regs *ctx,struct ath_softc *sc, struct ath_buf *bf)
{
struct ieee80211_hdr * hdr = (struct ieee80211_hdr *)bf->bf_mpdu->data;
u8 addr1[6],addr2[6];
bpf_probe_read(&addr1, sizeof(addr1), &hdr->addr1);
bpf_probe_read(&addr2, sizeof(addr2), &hdr->addr2);
u8 match_addr1[6];
match_addr1[0] = 0xa4;
match_addr1[1] = 0x08;
match_addr1[2] = 0xea;
if( (match_addr1[0] == addr1[0] && match_addr1[1] == addr1[1] && match_addr1[1] == addr1[1]))
{
bpf_trace_printk("[2021][ath_tx_complete_buf]::7::peerd[1] %x:%x:%x\\n", addr1[0], addr1[1], addr1[2]);
bpf_trace_printk("[2021][ath_tx_complete_buf]::7::peerd[2] %x:%x:%x\\n", addr1[3], addr1[4], addr1[5]);
}
return 0;
}
int kprobe__ieee80211_rx_napi(struct pt_regs *ctx,struct ieee80211_hw *hw, struct ieee80211_sta *pubsta,
struct sk_buff *skb, struct napi_struct *napi)
{
struct ieee80211_hdr * hdr = (struct ieee80211_hdr *)skb->data;
struct ieee80211_hdr * hdr1 = (struct ieee80211_hdr *)skb->data;
u8 addr1[6];
u8 addr2[6];
u8 match_addr1[6];
u8 match_addr2[6];
bpf_probe_read(&addr1, sizeof(addr1), &hdr->addr1);
bpf_probe_read(&addr2, sizeof(addr2), &hdr->addr2);
match_addr1[0] = 0xa4;
match_addr1[1] = 0x08;
match_addr1[2] = 0xea;
if( (match_addr1[0] == addr1[0] && match_addr1[1] == addr1[1] && match_addr1[1] == addr1[1]))
{
bpf_trace_printk("[2021][ath10k_process_rx]RECEIVED a [data] packet::2::::7::peerd[1] %x:%x:%x\\n", addr2[0], addr2[1], addr2[2]);
bpf_trace_printk("[2021][ath10k_process_rx]RECEIVED a [data] packet::2::::7::peerd[2] %x:%x:%x\\n", addr2[3], addr2[4], addr2[5]);
u16 fc;
bpf_probe_read(&fc, sizeof(fc), &hdr->frame_control);
bpf_trace_printk("[2021][ath10k_process_rx]RECEIVED a [data] packet::2::::7::peerd[3] 3::ftype %x ::4::stype %x ::5::PM %x \\n",
fc & IEEE80211_FCTL_FTYPE, fc & IEEE80211_FCTL_STYPE, fc & IEEE80211_FCTL_PM);
}
if( (match_addr1[0] == addr2[0] && match_addr1[1] == addr2[1] && match_addr1[1] == addr2[1]))
{
bpf_trace_printk("[2021][ath10k_process_rx]RECEIVED a [data] packet::2::::7::peerd[1] %x:%x:%x\\n", addr2[0], addr2[1], addr2[2]);
bpf_trace_printk("[2021][ath10k_process_rx]RECEIVED a [data] packet::2::::7::peerd[2] %x:%x:%x\\n", addr2[3], addr2[4], addr2[5]);
u16 fc;
bpf_probe_read(&fc, sizeof(fc), &hdr->frame_control);
bpf_trace_printk("[2021][ath10k_process_rx]RECEIVED a [data] packet::2::::7::peerd[3] 3::ftype %x ::4::stype %x ::5::PM %x \\n",
fc & IEEE80211_FCTL_FTYPE, fc & IEEE80211_FCTL_STYPE, fc & IEEE80211_FCTL_PM);
}
return 0;
}
""")
last=0
print((time.time() * 1000))
while 1:
try:
(task, pid, cpu, flags, ts, msg) = b.trace_fields()
# (val0, fmt) = msg.split(' ', 1)
# if (fmt == "Rssi %d, TSF %llu"):
# signal = int(val0);
# for c in range(0, (100 + signal) / 2):
# print("*")
# print((time.time()))
printb(b"%-18.9f %-18.9f %s" % (time.time(), ts, msg))
# print("")
# if (last != signal):
# sound.stop()
# sound = pygame.sndarray.make_sound(note[signal])
# sound.play(-1)
# last = signal
except KeyboardInterrupt:
exit()
except ValueError:
next
sound.stop()