/* SPDX-License-Identifier: GPL-2.0 */1/* Copyright (C) B.A.T.M.A.N. contributors:2*3* Simon Wunderlich, Marek Lindner4*/56#ifndef _NET_BATMAN_ADV_BITARRAY_H_7#define _NET_BATMAN_ADV_BITARRAY_H_89#include "main.h"1011#include <linux/bitops.h>12#include <linux/compiler.h>13#include <linux/stddef.h>14#include <linux/types.h>1516/**17* batadv_test_bit() - check if bit is set in the current window18*19* @seq_bits: pointer to the sequence number receive packet20* @last_seqno: latest sequence number in seq_bits21* @curr_seqno: sequence number to test for22*23* Return: true if the corresponding bit in the given seq_bits indicates true24* and curr_seqno is within range of last_seqno. Otherwise returns false.25*/26static inline bool batadv_test_bit(const unsigned long *seq_bits,27u32 last_seqno, u32 curr_seqno)28{29s32 diff;3031diff = last_seqno - curr_seqno;32if (diff < 0 || diff >= BATADV_TQ_LOCAL_WINDOW_SIZE)33return false;34return test_bit(diff, seq_bits) != 0;35}3637/**38* batadv_set_bit() - Turn corresponding bit on, so we can remember that we got39* the packet40* @seq_bits: bitmap of the packet receive window41* @n: relative sequence number of newly received packet42*/43static inline void batadv_set_bit(unsigned long *seq_bits, s32 n)44{45/* if too old, just drop it */46if (n < 0 || n >= BATADV_TQ_LOCAL_WINDOW_SIZE)47return;4849set_bit(n, seq_bits); /* turn the position on */50}5152bool batadv_bit_get_packet(void *priv, unsigned long *seq_bits,53s32 seq_num_diff, int set_mark);5455#endif /* _NET_BATMAN_ADV_BITARRAY_H_ */565758