util.h 1.8 KB

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