]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - net/mac802154/mac_cmd.c
KVM: SVM: Move spec control call after restore of GS
[mirror_ubuntu-artful-kernel.git] / net / mac802154 / mac_cmd.c
CommitLineData
6e2128d4 1/*
2 * MAC commands interface
3 *
4 * Copyright 2007-2012 Siemens AG
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2
8 * as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
6e2128d4 15 * Written by:
16 * Sergey Lapin <slapin@ossfans.org>
17 * Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
18 * Alexander Smirnov <alex.bluesman.smirnov@gmail.com>
19 */
20
21#include <linux/skbuff.h>
22#include <linux/if_arp.h>
4ca24aca 23#include <linux/ieee802154.h>
6e2128d4 24
25#include <net/ieee802154_netdev.h>
5ad60d36 26#include <net/cfg802154.h>
6e2128d4 27#include <net/mac802154.h>
28
0f1556bc 29#include "ieee802154_i.h"
f59f419d 30#include "driver-ops.h"
6e2128d4 31
5265f467 32static int mac802154_mlme_start_req(struct net_device *dev,
ae531b94 33 struct ieee802154_addr *addr,
5265f467 34 u8 channel, u8 page,
35 u8 bcn_ord, u8 sf_ord,
36 u8 pan_coord, u8 blx,
37 u8 coord_realign)
38{
641459ca
LB
39 struct ieee802154_llsec_params params;
40 int changed = 0;
9b0bb4a8 41
7bea1ea7
AA
42 ASSERT_RTNL();
43
ae531b94 44 BUG_ON(addr->mode != IEEE802154_ADDR_SHORT);
5265f467 45
c947f7e1
AA
46 dev->ieee802154_ptr->pan_id = addr->pan_id;
47 dev->ieee802154_ptr->short_addr = addr->short_addr;
5265f467 48 mac802154_dev_set_page_channel(dev, page, channel);
49
641459ca
LB
50 params.pan_id = addr->pan_id;
51 changed |= IEEE802154_LLSEC_PARAM_PAN_ID;
9b0bb4a8 52
641459ca
LB
53 params.hwaddr = ieee802154_devaddr_from_raw(dev->dev_addr);
54 changed |= IEEE802154_LLSEC_PARAM_HWADDR;
9b0bb4a8 55
641459ca
LB
56 params.coord_hwaddr = params.hwaddr;
57 changed |= IEEE802154_LLSEC_PARAM_COORD_HWADDR;
9b0bb4a8 58
641459ca
LB
59 params.coord_shortaddr = addr->short_addr;
60 changed |= IEEE802154_LLSEC_PARAM_COORD_SHORTADDR;
9b0bb4a8 61
641459ca 62 return mac802154_set_params(dev, &params, changed);
5265f467 63}
64
c7420c36
AA
65static int mac802154_set_mac_params(struct net_device *dev,
66 const struct ieee802154_mac_params *params)
67{
68 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
f59f419d 69 struct ieee802154_local *local = sdata->local;
5fb3f026 70 struct wpan_dev *wpan_dev = &sdata->wpan_dev;
f59f419d 71 int ret;
c7420c36 72
7bea1ea7
AA
73 ASSERT_RTNL();
74
5fb3f026
AA
75 /* PHY */
76 wpan_dev->wpan_phy->transmit_power = params->transmit_power;
7fe9a388 77 wpan_dev->wpan_phy->cca = params->cca;
5fb3f026
AA
78 wpan_dev->wpan_phy->cca_ed_level = params->cca_ed_level;
79
80 /* MAC */
81 wpan_dev->min_be = params->min_be;
82 wpan_dev->max_be = params->max_be;
83 wpan_dev->csma_retries = params->csma_retries;
84 wpan_dev->frame_retries = params->frame_retries;
85 wpan_dev->lbt = params->lbt;
c7420c36 86
edea8f7c 87 if (local->hw.phy->flags & WPAN_PHY_FLAG_TXPOWER) {
f59f419d
AA
88 ret = drv_set_tx_power(local, params->transmit_power);
89 if (ret < 0)
90 return ret;
91 }
92
edea8f7c 93 if (local->hw.phy->flags & WPAN_PHY_FLAG_CCA_MODE) {
7fe9a388 94 ret = drv_set_cca_mode(local, &params->cca);
f59f419d
AA
95 if (ret < 0)
96 return ret;
97 }
98
edea8f7c 99 if (local->hw.phy->flags & WPAN_PHY_FLAG_CCA_ED_LEVEL) {
f59f419d
AA
100 ret = drv_set_cca_ed_level(local, params->cca_ed_level);
101 if (ret < 0)
102 return ret;
103 }
104
c7420c36
AA
105 return 0;
106}
107
108static void mac802154_get_mac_params(struct net_device *dev,
109 struct ieee802154_mac_params *params)
110{
111 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
5fb3f026 112 struct wpan_dev *wpan_dev = &sdata->wpan_dev;
c7420c36 113
7bea1ea7
AA
114 ASSERT_RTNL();
115
5fb3f026
AA
116 /* PHY */
117 params->transmit_power = wpan_dev->wpan_phy->transmit_power;
7fe9a388 118 params->cca = wpan_dev->wpan_phy->cca;
5fb3f026
AA
119 params->cca_ed_level = wpan_dev->wpan_phy->cca_ed_level;
120
121 /* MAC */
122 params->min_be = wpan_dev->min_be;
123 params->max_be = wpan_dev->max_be;
124 params->csma_retries = wpan_dev->csma_retries;
125 params->frame_retries = wpan_dev->frame_retries;
126 params->lbt = wpan_dev->lbt;
c7420c36
AA
127}
128
29663b0c 129static const struct ieee802154_llsec_ops mac802154_llsec_ops = {
29e02374
PB
130 .get_params = mac802154_get_params,
131 .set_params = mac802154_set_params,
132 .add_key = mac802154_add_key,
133 .del_key = mac802154_del_key,
134 .add_dev = mac802154_add_dev,
135 .del_dev = mac802154_del_dev,
136 .add_devkey = mac802154_add_devkey,
137 .del_devkey = mac802154_del_devkey,
138 .add_seclevel = mac802154_add_seclevel,
139 .del_seclevel = mac802154_del_seclevel,
140 .lock_table = mac802154_lock_table,
141 .get_table = mac802154_get_table,
142 .unlock_table = mac802154_unlock_table,
143};
144
32bad7e3 145struct ieee802154_mlme_ops mac802154_mlme_wpan = {
5265f467 146 .start_req = mac802154_mlme_start_req,
e462ded6 147
29e02374
PB
148 .llsec = &mac802154_llsec_ops,
149
e462ded6
PB
150 .set_mac_params = mac802154_set_mac_params,
151 .get_mac_params = mac802154_get_mac_params,
32bad7e3 152};