ocb.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 Intel Corporation
  8. * Author: Rostislav Lisovy <[email protected]>
  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. ASSERT_WDEV_LOCK(wdev);
  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_join_ocb(struct cfg80211_registered_device *rdev,
  35. struct net_device *dev,
  36. struct ocb_setup *setup)
  37. {
  38. struct wireless_dev *wdev = dev->ieee80211_ptr;
  39. int err;
  40. wdev_lock(wdev);
  41. err = __cfg80211_join_ocb(rdev, dev, setup);
  42. wdev_unlock(wdev);
  43. return err;
  44. }
  45. int __cfg80211_leave_ocb(struct cfg80211_registered_device *rdev,
  46. struct net_device *dev)
  47. {
  48. struct wireless_dev *wdev = dev->ieee80211_ptr;
  49. int err;
  50. ASSERT_WDEV_LOCK(wdev);
  51. if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB)
  52. return -EOPNOTSUPP;
  53. if (!rdev->ops->leave_ocb)
  54. return -EOPNOTSUPP;
  55. if (!wdev->u.ocb.chandef.chan)
  56. return -ENOTCONN;
  57. err = rdev_leave_ocb(rdev, dev);
  58. if (!err)
  59. memset(&wdev->u.ocb.chandef, 0, sizeof(wdev->u.ocb.chandef));
  60. return err;
  61. }
  62. int cfg80211_leave_ocb(struct cfg80211_registered_device *rdev,
  63. struct net_device *dev)
  64. {
  65. struct wireless_dev *wdev = dev->ieee80211_ptr;
  66. int err;
  67. wdev_lock(wdev);
  68. err = __cfg80211_leave_ocb(rdev, dev);
  69. wdev_unlock(wdev);
  70. return err;
  71. }