Blame view
net/batman-adv/bitarray.h
1.68 KB
e19f9759e
|
1 |
/* Copyright (C) 2006-2014 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_ |
dbd6b11e1
|
20 21 |
/* Returns 1 if the corresponding bit in the given seq_bits indicates true * and curr_seqno is within range of last_seqno. Otherwise returns 0. |
9cfc7bd60
|
22 |
*/ |
9b4a1159d
|
23 24 |
static inline int batadv_test_bit(const unsigned long *seq_bits, uint32_t last_seqno, uint32_t curr_seqno) |
0079d2cef
|
25 26 27 28 |
{ int32_t diff; diff = last_seqno - curr_seqno; |
42d0b044b
|
29 |
if (diff < 0 || diff >= BATADV_TQ_LOCAL_WINDOW_SIZE) |
0079d2cef
|
30 31 |
return 0; else |
dbd6b11e1
|
32 |
return test_bit(diff, seq_bits) != 0; |
0079d2cef
|
33 |
} |
c6c8fea29
|
34 35 |
/* turn corresponding bit on, so we can remember that we got the packet */ |
9b4a1159d
|
36 |
static inline void batadv_set_bit(unsigned long *seq_bits, int32_t n) |
0079d2cef
|
37 38 |
{ /* if too old, just drop it */ |
42d0b044b
|
39 |
if (n < 0 || n >= BATADV_TQ_LOCAL_WINDOW_SIZE) |
0079d2cef
|
40 |
return; |
c6c8fea29
|
41 |
|
0079d2cef
|
42 43 |
set_bit(n, seq_bits); /* turn the position on */ } |
c6c8fea29
|
44 45 |
/* receive and process one packet, returns 1 if received seq_num is considered |
9cfc7bd60
|
46 47 |
* new, 0 if old */ |
0f5f93226
|
48 49 |
int batadv_bit_get_packet(void *priv, unsigned long *seq_bits, int32_t seq_num_diff, int set_mark); |
c6c8fea29
|
50 |
|
c6c8fea29
|
51 |
#endif /* _NET_BATMAN_ADV_BITARRAY_H_ */ |