Blame view
net/batman-adv/bitarray.h
1.92 KB
ac79cbb96
|
1 |
/* Copyright (C) 2006-2017 B.A.T.M.A.N. contributors: |
c6c8fea29
|
2 3 4 5 6 7 8 9 10 11 12 13 14 |
* * Simon Wunderlich, Marek Lindner * * This program is free software; you can redistribute it and/or * modify it under the terms of version 2 of the GNU General Public * License as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License |
ebf38fb7a
|
15 |
* along with this program; if not, see <http://www.gnu.org/licenses/>. |
c6c8fea29
|
16 17 18 19 |
*/ #ifndef _NET_BATMAN_ADV_BITARRAY_H_ #define _NET_BATMAN_ADV_BITARRAY_H_ |
1e2c2a4fe
|
20 21 22 23 |
#include "main.h" #include <linux/bitops.h> #include <linux/compiler.h> |
4b426b108
|
24 |
#include <linux/stddef.h> |
1e2c2a4fe
|
25 |
#include <linux/types.h> |
62fe710f6
|
26 |
/** |
7afcbbef6
|
27 28 29 30 31 |
* batadv_test_bit - check if bit is set in the current window * * @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
|
32 |
* |
4b426b108
|
33 34 |
* 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
|
35 |
*/ |
4b426b108
|
36 37 |
static inline bool batadv_test_bit(const unsigned long *seq_bits, u32 last_seqno, u32 curr_seqno) |
0079d2cef
|
38 |
{ |
6b5e971a2
|
39 |
s32 diff; |
0079d2cef
|
40 41 |
diff = last_seqno - curr_seqno; |
42d0b044b
|
42 |
if (diff < 0 || diff >= BATADV_TQ_LOCAL_WINDOW_SIZE) |
4b426b108
|
43 |
return false; |
24820df14
|
44 |
return test_bit(diff, seq_bits) != 0; |
0079d2cef
|
45 |
} |
c6c8fea29
|
46 47 |
/* turn corresponding bit on, so we can remember that we got the packet */ |
6b5e971a2
|
48 |
static inline void batadv_set_bit(unsigned long *seq_bits, s32 n) |
0079d2cef
|
49 50 |
{ /* if too old, just drop it */ |
42d0b044b
|
51 |
if (n < 0 || n >= BATADV_TQ_LOCAL_WINDOW_SIZE) |
0079d2cef
|
52 |
return; |
c6c8fea29
|
53 |
|
0079d2cef
|
54 55 |
set_bit(n, seq_bits); /* turn the position on */ } |
c6c8fea29
|
56 |
|
4b426b108
|
57 58 |
bool batadv_bit_get_packet(void *priv, unsigned long *seq_bits, s32 seq_num_diff, int set_mark); |
c6c8fea29
|
59 |
|
c6c8fea29
|
60 |
#endif /* _NET_BATMAN_ADV_BITARRAY_H_ */ |