Merge tag 'media/v6.12-1' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab...
[linux-2.6-block.git] / net / wireless / ocb.c
CommitLineData
d2912cb1 1// SPDX-License-Identifier: GPL-2.0-only
6e0bd6c3
RL
2/*
3 * OCB mode implementation
4 *
5 * Copyright: (c) 2014 Czech Technical University in Prague
6 * (c) 2014 Volkswagen Group Research
076fc877 7 * Copyright (C) 2022-2023 Intel Corporation
6e0bd6c3
RL
8 * Author: Rostislav Lisovy <rostislav.lisovy@fel.cvut.cz>
9 * Funded by: Volkswagen Group Research
6e0bd6c3
RL
10 */
11
12#include <linux/ieee80211.h>
13#include <net/cfg80211.h>
14#include "nl80211.h"
15#include "core.h"
16#include "rdev-ops.h"
17
076fc877
JB
18int cfg80211_join_ocb(struct cfg80211_registered_device *rdev,
19 struct net_device *dev,
20 struct ocb_setup *setup)
6e0bd6c3
RL
21{
22 struct wireless_dev *wdev = dev->ieee80211_ptr;
23 int err;
24
076fc877 25 lockdep_assert_wiphy(wdev->wiphy);
6e0bd6c3
RL
26
27 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB)
28 return -EOPNOTSUPP;
29
1b9df2d2
OO
30 if (!rdev->ops->join_ocb)
31 return -EOPNOTSUPP;
32
6e0bd6c3
RL
33 if (WARN_ON(!setup->chandef.chan))
34 return -EINVAL;
35
36 err = rdev_join_ocb(rdev, dev, setup);
37 if (!err)
7b0a0e3c 38 wdev->u.ocb.chandef = setup->chandef;
6e0bd6c3
RL
39
40 return err;
41}
42
076fc877
JB
43int cfg80211_leave_ocb(struct cfg80211_registered_device *rdev,
44 struct net_device *dev)
6e0bd6c3
RL
45{
46 struct wireless_dev *wdev = dev->ieee80211_ptr;
47 int err;
48
076fc877 49 lockdep_assert_wiphy(wdev->wiphy);
6e0bd6c3
RL
50
51 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB)
52 return -EOPNOTSUPP;
53
54 if (!rdev->ops->leave_ocb)
55 return -EOPNOTSUPP;
56
abc76cf5
JB
57 if (!wdev->u.ocb.chandef.chan)
58 return -ENOTCONN;
59
6e0bd6c3
RL
60 err = rdev_leave_ocb(rdev, dev);
61 if (!err)
7b0a0e3c 62 memset(&wdev->u.ocb.chandef, 0, sizeof(wdev->u.ocb.chandef));
6e0bd6c3
RL
63
64 return err;
65}