9c2d6f61f1949ee4a9a332843043bbbb1479ae5d
[deliverable/linux.git] / net / mac802154 / mac_cmd.c
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 *
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>
23 #include <linux/ieee802154.h>
24
25 #include <net/ieee802154_netdev.h>
26 #include <net/cfg802154.h>
27 #include <net/mac802154.h>
28 #include <net/nl802154.h>
29
30 #include "ieee802154_i.h"
31 #include "driver-ops.h"
32
33 static int mac802154_mlme_start_req(struct net_device *dev,
34 struct ieee802154_addr *addr,
35 u8 channel, u8 page,
36 u8 bcn_ord, u8 sf_ord,
37 u8 pan_coord, u8 blx,
38 u8 coord_realign)
39 {
40 struct ieee802154_mlme_ops *ops = ieee802154_mlme_ops(dev);
41 int rc = 0;
42
43 BUG_ON(addr->mode != IEEE802154_ADDR_SHORT);
44
45 mac802154_dev_set_pan_id(dev, addr->pan_id);
46 mac802154_dev_set_short_addr(dev, addr->short_addr);
47 mac802154_dev_set_page_channel(dev, page, channel);
48
49 if (ops->llsec) {
50 struct ieee802154_llsec_params params;
51 int changed = 0;
52
53 params.coord_shortaddr = addr->short_addr;
54 changed |= IEEE802154_LLSEC_PARAM_COORD_SHORTADDR;
55
56 params.pan_id = addr->pan_id;
57 changed |= IEEE802154_LLSEC_PARAM_PAN_ID;
58
59 params.hwaddr = ieee802154_devaddr_from_raw(dev->dev_addr);
60 changed |= IEEE802154_LLSEC_PARAM_HWADDR;
61
62 params.coord_hwaddr = params.hwaddr;
63 changed |= IEEE802154_LLSEC_PARAM_COORD_HWADDR;
64
65 rc = ops->llsec->set_params(dev, &params, changed);
66 }
67
68 /* FIXME: add validation for unused parameters to be sane
69 * for SoftMAC
70 */
71 ieee802154_nl_start_confirm(dev, IEEE802154_SUCCESS);
72
73 return rc;
74 }
75
76 static struct wpan_phy *mac802154_get_phy(const struct net_device *dev)
77 {
78 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
79
80 BUG_ON(dev->type != ARPHRD_IEEE802154);
81
82 return to_phy(get_device(&sdata->local->phy->dev));
83 }
84
85 static int mac802154_set_mac_params(struct net_device *dev,
86 const struct ieee802154_mac_params *params)
87 {
88 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
89 struct ieee802154_local *local = sdata->local;
90 int ret;
91
92 mutex_lock(&sdata->local->iflist_mtx);
93 sdata->mac_params = *params;
94 mutex_unlock(&sdata->local->iflist_mtx);
95
96 if (local->hw.flags & IEEE802154_HW_TXPOWER) {
97 ret = drv_set_tx_power(local, params->transmit_power);
98 if (ret < 0)
99 return ret;
100 }
101
102 if (local->hw.flags & IEEE802154_HW_CCA_MODE) {
103 ret = drv_set_cca_mode(local, params->cca_mode);
104 if (ret < 0)
105 return ret;
106 }
107
108 if (local->hw.flags & IEEE802154_HW_CCA_ED_LEVEL) {
109 ret = drv_set_cca_ed_level(local, params->cca_ed_level);
110 if (ret < 0)
111 return ret;
112 }
113
114 return 0;
115 }
116
117 static void mac802154_get_mac_params(struct net_device *dev,
118 struct ieee802154_mac_params *params)
119 {
120 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
121
122 mutex_lock(&sdata->local->iflist_mtx);
123 *params = sdata->mac_params;
124 mutex_unlock(&sdata->local->iflist_mtx);
125 }
126
127 static struct ieee802154_llsec_ops mac802154_llsec_ops = {
128 .get_params = mac802154_get_params,
129 .set_params = mac802154_set_params,
130 .add_key = mac802154_add_key,
131 .del_key = mac802154_del_key,
132 .add_dev = mac802154_add_dev,
133 .del_dev = mac802154_del_dev,
134 .add_devkey = mac802154_add_devkey,
135 .del_devkey = mac802154_del_devkey,
136 .add_seclevel = mac802154_add_seclevel,
137 .del_seclevel = mac802154_del_seclevel,
138 .lock_table = mac802154_lock_table,
139 .get_table = mac802154_get_table,
140 .unlock_table = mac802154_unlock_table,
141 };
142
143 struct ieee802154_reduced_mlme_ops mac802154_mlme_reduced = {
144 .get_phy = mac802154_get_phy,
145 };
146
147 struct ieee802154_mlme_ops mac802154_mlme_wpan = {
148 .get_phy = mac802154_get_phy,
149 .start_req = mac802154_mlme_start_req,
150 .get_pan_id = mac802154_dev_get_pan_id,
151 .get_short_addr = mac802154_dev_get_short_addr,
152 .get_dsn = mac802154_dev_get_dsn,
153
154 .llsec = &mac802154_llsec_ops,
155
156 .set_mac_params = mac802154_set_mac_params,
157 .get_mac_params = mac802154_get_mac_params,
158 };
This page took 0.044423 seconds and 4 git commands to generate.