Blame view
net/batman-adv/bitarray.h
1.52 KB
7db7d9f36
|
1 |
/* SPDX-License-Identifier: GPL-2.0 */ |
7a79d717e
|
2 |
/* Copyright (C) 2006-2019 B.A.T.M.A.N. contributors: |
c6c8fea29
|
3 4 |
* * Simon Wunderlich, Marek Lindner |
c6c8fea29
|
5 6 7 8 |
*/ #ifndef _NET_BATMAN_ADV_BITARRAY_H_ #define _NET_BATMAN_ADV_BITARRAY_H_ |
1e2c2a4fe
|
9 10 11 12 |
#include "main.h" #include <linux/bitops.h> #include <linux/compiler.h> |
4b426b108
|
13 |
#include <linux/stddef.h> |
1e2c2a4fe
|
14 |
#include <linux/types.h> |
62fe710f6
|
15 |
/** |
7e9a8c2ce
|
16 |
* batadv_test_bit() - check if bit is set in the current window |
7afcbbef6
|
17 18 19 20 |
* * @seq_bits: pointer to the sequence number receive packet * @last_seqno: latest sequence number in seq_bits * @curr_seqno: sequence number to test for |
62fe710f6
|
21 |
* |
4b426b108
|
22 23 |
* Return: true if the corresponding bit in the given seq_bits indicates true * and curr_seqno is within range of last_seqno. Otherwise returns false. |
9cfc7bd60
|
24 |
*/ |
4b426b108
|
25 26 |
static inline bool batadv_test_bit(const unsigned long *seq_bits, u32 last_seqno, u32 curr_seqno) |
0079d2cef
|
27 |
{ |
6b5e971a2
|
28 |
s32 diff; |
0079d2cef
|
29 30 |
diff = last_seqno - curr_seqno; |
42d0b044b
|
31 |
if (diff < 0 || diff >= BATADV_TQ_LOCAL_WINDOW_SIZE) |
4b426b108
|
32 |
return false; |
24820df14
|
33 |
return test_bit(diff, seq_bits) != 0; |
0079d2cef
|
34 |
} |
c6c8fea29
|
35 |
|
e57acf8e9
|
36 37 38 39 40 41 |
/** * batadv_set_bit() - Turn corresponding bit on, so we can remember that we got * the packet * @seq_bits: bitmap of the packet receive window * @n: relative sequence number of newly received packet */ |
6b5e971a2
|
42 |
static inline void batadv_set_bit(unsigned long *seq_bits, s32 n) |
0079d2cef
|
43 44 |
{ /* if too old, just drop it */ |
42d0b044b
|
45 |
if (n < 0 || n >= BATADV_TQ_LOCAL_WINDOW_SIZE) |
0079d2cef
|
46 |
return; |
c6c8fea29
|
47 |
|
0079d2cef
|
48 49 |
set_bit(n, seq_bits); /* turn the position on */ } |
c6c8fea29
|
50 |
|
4b426b108
|
51 52 |
bool batadv_bit_get_packet(void *priv, unsigned long *seq_bits, s32 seq_num_diff, int set_mark); |
c6c8fea29
|
53 |
|
c6c8fea29
|
54 |
#endif /* _NET_BATMAN_ADV_BITARRAY_H_ */ |