summaryrefslogtreecommitdiffstats
path: root/net/wireless/tests/util.h
blob: 6de712e0d4320c6861fa7e285fe8199bb496cbf4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/* SPDX-License-Identifier: GPL-2.0-only */
/*
 * Utilities for cfg80211 unit testing
 *
 * Copyright (C) 2023 Intel Corporation
 */
#ifndef __CFG80211_UTILS_H
#define __CFG80211_UTILS_H

#define CHAN2G(_freq)  { \
	.band = NL80211_BAND_2GHZ, \
	.center_freq = (_freq), \
	.hw_value = (_freq), \
}

static const struct ieee80211_channel channels_2ghz[] = {
	CHAN2G(2412), /* Channel 1 */
	CHAN2G(2417), /* Channel 2 */
	CHAN2G(2422), /* Channel 3 */
	CHAN2G(2427), /* Channel 4 */
	CHAN2G(2432), /* Channel 5 */
	CHAN2G(2437), /* Channel 6 */
	CHAN2G(2442), /* Channel 7 */
	CHAN2G(2447), /* Channel 8 */
	CHAN2G(2452), /* Channel 9 */
	CHAN2G(2457), /* Channel 10 */
	CHAN2G(2462), /* Channel 11 */
	CHAN2G(2467), /* Channel 12 */
	CHAN2G(2472), /* Channel 13 */
	CHAN2G(2484), /* Channel 14 */
};

struct t_wiphy_priv {
	struct kunit *test;
	struct cfg80211_ops *ops;

	void *ctx;

	struct ieee80211_supported_band band_2ghz;
	struct ieee80211_channel channels_2ghz[ARRAY_SIZE(channels_2ghz)];
};

#define T_WIPHY(test, ctx) ({						\
		struct wiphy *__wiphy =					\
			kunit_alloc_resource(test, t_wiphy_init,	\
					     t_wiphy_exit,		\
					     GFP_KERNEL, &(ctx));	\
									\
		KUNIT_ASSERT_NOT_NULL(test, __wiphy);			\
		__wiphy;						\
	})
#define t_wiphy_ctx(wiphy) (((struct t_wiphy_priv *)wiphy_priv(wiphy))->ctx)

int t_wiphy_init(struct kunit_resource *resource, void *data);
void t_wiphy_exit(struct kunit_resource *resource);

#define t_skb_remove_member(skb, type, member)	do {				\
		memmove((skb)->data + (skb)->len - sizeof(type) +		\
			offsetof(type, member),					\
			(skb)->data + (skb)->len - sizeof(type) +		\
			offsetofend(type, member),				\
			offsetofend(type, member));				\
		skb_trim(skb, (skb)->len - sizeof_field(type, member));		\
	} while (0)

#endif /* __CFG80211_UTILS_H */