ocb.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * OCB mode implementation
  4. *
  5. * Copyright: (c) 2014 Czech Technical University in Prague
  6. * (c) 2014 Volkswagen Group Research
  7. * Copyright (C) 2022-2023 Intel Corporation
  8. * Author: Rostislav Lisovy <rostislav.lisovy@fel.cvut.cz>
  9. * Funded by: Volkswagen Group Research
  10. */
  11. #include <linux/ieee80211.h>
  12. #include <net/cfg80211.h>
  13. #include "nl80211.h"
  14. #include "core.h"
  15. #include "rdev-ops.h"
  16. int cfg80211_join_ocb(struct cfg80211_registered_device *rdev,
  17. struct net_device *dev,
  18. struct ocb_setup *setup)
  19. {
  20. struct wireless_dev *wdev = dev->ieee80211_ptr;
  21. int err;
  22. lockdep_assert_wiphy(wdev->wiphy);
  23. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB)
  24. return -EOPNOTSUPP;
  25. if (!rdev->ops->join_ocb)
  26. return -EOPNOTSUPP;
  27. if (WARN_ON(!setup->chandef.chan))
  28. return -EINVAL;
  29. err = rdev_join_ocb(rdev, dev, setup);
  30. if (!err)
  31. wdev->u.ocb.chandef = setup->chandef;
  32. return err;
  33. }
  34. int cfg80211_leave_ocb(struct cfg80211_registered_device *rdev,
  35. struct net_device *dev)
  36. {
  37. struct wireless_dev *wdev = dev->ieee80211_ptr;
  38. int err;
  39. lockdep_assert_wiphy(wdev->wiphy);
  40. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB)
  41. return -EOPNOTSUPP;
  42. if (!rdev->ops->leave_ocb)
  43. return -EOPNOTSUPP;
  44. if (!wdev->u.ocb.chandef.chan)
  45. return -ENOTCONN;
  46. err = rdev_leave_ocb(rdev, dev);
  47. if (!err)
  48. memset(&wdev->u.ocb.chandef, 0, sizeof(wdev->u.ocb.chandef));
  49. return err;
  50. }