Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /* Copyright (C) B.A.T.M.A.N. contributors:
0003  *
0004  * Simon Wunderlich, Marek Lindner
0005  */
0006 
0007 #ifndef _NET_BATMAN_ADV_BITARRAY_H_
0008 #define _NET_BATMAN_ADV_BITARRAY_H_
0009 
0010 #include "main.h"
0011 
0012 #include <linux/bitops.h>
0013 #include <linux/compiler.h>
0014 #include <linux/stddef.h>
0015 #include <linux/types.h>
0016 
0017 /**
0018  * batadv_test_bit() - check if bit is set in the current window
0019  *
0020  * @seq_bits: pointer to the sequence number receive packet
0021  * @last_seqno: latest sequence number in seq_bits
0022  * @curr_seqno: sequence number to test for
0023  *
0024  * Return: true if the corresponding bit in the given seq_bits indicates true
0025  * and curr_seqno is within range of last_seqno. Otherwise returns false.
0026  */
0027 static inline bool batadv_test_bit(const unsigned long *seq_bits,
0028                    u32 last_seqno, u32 curr_seqno)
0029 {
0030     s32 diff;
0031 
0032     diff = last_seqno - curr_seqno;
0033     if (diff < 0 || diff >= BATADV_TQ_LOCAL_WINDOW_SIZE)
0034         return false;
0035     return test_bit(diff, seq_bits) != 0;
0036 }
0037 
0038 /**
0039  * batadv_set_bit() - Turn corresponding bit on, so we can remember that we got
0040  *  the packet
0041  * @seq_bits: bitmap of the packet receive window
0042  * @n: relative sequence number of newly received packet
0043  */
0044 static inline void batadv_set_bit(unsigned long *seq_bits, s32 n)
0045 {
0046     /* if too old, just drop it */
0047     if (n < 0 || n >= BATADV_TQ_LOCAL_WINDOW_SIZE)
0048         return;
0049 
0050     set_bit(n, seq_bits); /* turn the position on */
0051 }
0052 
0053 bool batadv_bit_get_packet(void *priv, unsigned long *seq_bits,
0054                s32 seq_num_diff, int set_mark);
0055 
0056 #endif /* _NET_BATMAN_ADV_BITARRAY_H_ */