Blame view
net/batman-adv/bitarray.h
1.88 KB
0046b0402
|
1 |
/* Copyright (C) 2006-2016 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 24 |
#include "main.h" #include <linux/bitops.h> #include <linux/compiler.h> #include <linux/types.h> |
62fe710f6
|
25 |
/** |
7afcbbef6
|
26 27 28 29 30 |
* 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
|
31 32 |
* * Return: 1 if the corresponding bit in the given seq_bits indicates true |
dbd6b11e1
|
33 |
* and curr_seqno is within range of last_seqno. Otherwise returns 0. |
9cfc7bd60
|
34 |
*/ |
9b4a1159d
|
35 |
static inline int batadv_test_bit(const unsigned long *seq_bits, |
6b5e971a2
|
36 |
u32 last_seqno, u32 curr_seqno) |
0079d2cef
|
37 |
{ |
6b5e971a2
|
38 |
s32 diff; |
0079d2cef
|
39 40 |
diff = last_seqno - curr_seqno; |
42d0b044b
|
41 |
if (diff < 0 || diff >= BATADV_TQ_LOCAL_WINDOW_SIZE) |
0079d2cef
|
42 |
return 0; |
24820df14
|
43 |
return test_bit(diff, seq_bits) != 0; |
0079d2cef
|
44 |
} |
c6c8fea29
|
45 46 |
/* turn corresponding bit on, so we can remember that we got the packet */ |
6b5e971a2
|
47 |
static inline void batadv_set_bit(unsigned long *seq_bits, s32 n) |
0079d2cef
|
48 49 |
{ /* if too old, just drop it */ |
42d0b044b
|
50 |
if (n < 0 || n >= BATADV_TQ_LOCAL_WINDOW_SIZE) |
0079d2cef
|
51 |
return; |
c6c8fea29
|
52 |
|
0079d2cef
|
53 54 |
set_bit(n, seq_bits); /* turn the position on */ } |
c6c8fea29
|
55 |
|
6b5e971a2
|
56 57 |
int batadv_bit_get_packet(void *priv, unsigned long *seq_bits, s32 seq_num_diff, int set_mark); |
c6c8fea29
|
58 |
|
c6c8fea29
|
59 |
#endif /* _NET_BATMAN_ADV_BITARRAY_H_ */ |