| 1 |
|
| 2 | |
| 3 | * Utilities for cfg80211 unit testing
|
| 4 | *
|
| 5 | * Copyright (C) 2023 Intel Corporation
|
| 6 |
|
| 7 | #ifndef __CFG80211_UTILS_H
|
| 8 | #define __CFG80211_UTILS_H
|
| 9 |
|
| 10 | #define CHAN2G(_freq) { \
|
| 11 | .band = NL80211_BAND_2GHZ, \
|
| 12 | .center_freq = (_freq), \
|
| 13 | .hw_value = (_freq), \
|
| 14 | }
|
| 15 |
|
| 16 | static const struct ieee80211_channel channels_2ghz[] = {
|
| 17 | CHAN2G(2412),
|
| 18 | CHAN2G(2417),
|
| 19 | CHAN2G(2422),
|
| 20 | CHAN2G(2427),
|
| 21 | CHAN2G(2432),
|
| 22 | CHAN2G(2437),
|
| 23 | CHAN2G(2442),
|
| 24 | CHAN2G(2447),
|
| 25 | CHAN2G(2452),
|
| 26 | CHAN2G(2457),
|
| 27 | CHAN2G(2462),
|
| 28 | CHAN2G(2467),
|
| 29 | CHAN2G(2472),
|
| 30 | CHAN2G(2484),
|
| 31 | };
|
| 32 |
|
| 33 | struct t_wiphy_priv {
|
| 34 | struct kunit *test;
|
| 35 | struct cfg80211_ops *ops;
|
| 36 |
|
| 37 | void *ctx;
|
| 38 |
|
| 39 | struct ieee80211_supported_band band_2ghz;
|
| 40 | struct ieee80211_channel channels_2ghz[ARRAY_SIZE(channels_2ghz)];
|
| 41 | };
|
| 42 |
|
| 43 | #define T_WIPHY(test, ctx) ({ \
|
| 44 | struct wiphy *__wiphy = \
|
| 45 | kunit_alloc_resource(test, t_wiphy_init, \
|
| 46 | t_wiphy_exit, \
|
| 47 | GFP_KERNEL, &(ctx)); \
|
| 48 | \
|
| 49 | KUNIT_ASSERT_NOT_NULL(test, __wiphy); \
|
| 50 | __wiphy; \
|
| 51 | })
|
| 52 | #define t_wiphy_ctx(wiphy) (((struct t_wiphy_priv *)wiphy_priv(wiphy))->ctx)
|
| 53 |
|
| 54 | int t_wiphy_init(struct kunit_resource *resource, void *data);
|
| 55 | void t_wiphy_exit(struct kunit_resource *resource);
|
| 56 |
|
| 57 | #define t_skb_remove_member(skb, type, member) do { \
|
| 58 | memmove((skb)->data + (skb)->len - sizeof(type) + \
|
| 59 | offsetof(type, member), \
|
| 60 | (skb)->data + (skb)->len - sizeof(type) + \
|
| 61 | offsetofend(type, member), \
|
| 62 | offsetofend(type, member)); \
|
| 63 | skb_trim(skb, (skb)->len - sizeof_field(type, member)); \
|
| 64 | } while (0)
|
| 65 |
|
| 66 | #endif
|