blob: 00b2b214770eb3b7e37ba0b6179ec7054e88df33 [file] [log] [blame]
alex.bluesman.smirnov@gmail.com6e2128d2012-05-15 20:50:25 +00001/*
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 *
alex.bluesman.smirnov@gmail.com6e2128d2012-05-15 20:50:25 +000015 * 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>
Alexander Aring4ca24ac2014-10-25 09:41:04 +020023#include <linux/ieee802154.h>
alex.bluesman.smirnov@gmail.com6e2128d2012-05-15 20:50:25 +000024
25#include <net/ieee802154_netdev.h>
Alexander Aring5ad60d32014-10-25 09:41:02 +020026#include <net/cfg802154.h>
alex.bluesman.smirnov@gmail.com6e2128d2012-05-15 20:50:25 +000027#include <net/mac802154.h>
28
Alexander Aring0f1556b2014-10-25 09:41:00 +020029#include "ieee802154_i.h"
Alexander Aringf59f4192014-11-02 04:18:44 +010030#include "driver-ops.h"
alex.bluesman.smirnov@gmail.com6e2128d2012-05-15 20:50:25 +000031
alex.bluesman.smirnov@gmail.com5265f462012-06-25 23:24:52 +000032static int mac802154_mlme_start_req(struct net_device *dev,
Phoebe Buckheisterae531b92014-03-14 21:24:02 +010033 struct ieee802154_addr *addr,
alex.bluesman.smirnov@gmail.com5265f462012-06-25 23:24:52 +000034 u8 channel, u8 page,
35 u8 bcn_ord, u8 sf_ord,
36 u8 pan_coord, u8 blx,
37 u8 coord_realign)
38{
Phoebe Buckheister9b0bb4a2014-05-16 17:46:43 +020039 struct ieee802154_mlme_ops *ops = ieee802154_mlme_ops(dev);
40 int rc = 0;
41
Phoebe Buckheisterae531b92014-03-14 21:24:02 +010042 BUG_ON(addr->mode != IEEE802154_ADDR_SHORT);
alex.bluesman.smirnov@gmail.com5265f462012-06-25 23:24:52 +000043
Phoebe Buckheisterae531b92014-03-14 21:24:02 +010044 mac802154_dev_set_pan_id(dev, addr->pan_id);
45 mac802154_dev_set_short_addr(dev, addr->short_addr);
alex.bluesman.smirnov@gmail.com5265f462012-06-25 23:24:52 +000046 mac802154_dev_set_page_channel(dev, page, channel);
47
Phoebe Buckheister9b0bb4a2014-05-16 17:46:43 +020048 if (ops->llsec) {
49 struct ieee802154_llsec_params params;
50 int changed = 0;
51
52 params.coord_shortaddr = addr->short_addr;
53 changed |= IEEE802154_LLSEC_PARAM_COORD_SHORTADDR;
54
55 params.pan_id = addr->pan_id;
56 changed |= IEEE802154_LLSEC_PARAM_PAN_ID;
57
58 params.hwaddr = ieee802154_devaddr_from_raw(dev->dev_addr);
59 changed |= IEEE802154_LLSEC_PARAM_HWADDR;
60
61 params.coord_hwaddr = params.hwaddr;
62 changed |= IEEE802154_LLSEC_PARAM_COORD_HWADDR;
63
64 rc = ops->llsec->set_params(dev, &params, changed);
65 }
66
Phoebe Buckheister9b0bb4a2014-05-16 17:46:43 +020067 return rc;
alex.bluesman.smirnov@gmail.com5265f462012-06-25 23:24:52 +000068}
69
Alexander Aringc7420c32014-10-28 18:21:30 +010070static int mac802154_set_mac_params(struct net_device *dev,
71 const struct ieee802154_mac_params *params)
72{
73 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
Alexander Aringf59f4192014-11-02 04:18:44 +010074 struct ieee802154_local *local = sdata->local;
75 int ret;
Alexander Aringc7420c32014-10-28 18:21:30 +010076
77 mutex_lock(&sdata->local->iflist_mtx);
78 sdata->mac_params = *params;
79 mutex_unlock(&sdata->local->iflist_mtx);
80
Alexander Aringf59f4192014-11-02 04:18:44 +010081 if (local->hw.flags & IEEE802154_HW_TXPOWER) {
82 ret = drv_set_tx_power(local, params->transmit_power);
83 if (ret < 0)
84 return ret;
85 }
86
87 if (local->hw.flags & IEEE802154_HW_CCA_MODE) {
88 ret = drv_set_cca_mode(local, params->cca_mode);
89 if (ret < 0)
90 return ret;
91 }
92
93 if (local->hw.flags & IEEE802154_HW_CCA_ED_LEVEL) {
94 ret = drv_set_cca_ed_level(local, params->cca_ed_level);
95 if (ret < 0)
96 return ret;
97 }
98
Alexander Aringc7420c32014-10-28 18:21:30 +010099 return 0;
100}
101
102static void mac802154_get_mac_params(struct net_device *dev,
103 struct ieee802154_mac_params *params)
104{
105 struct ieee802154_sub_if_data *sdata = IEEE802154_DEV_TO_SUB_IF(dev);
106
107 mutex_lock(&sdata->local->iflist_mtx);
108 *params = sdata->mac_params;
109 mutex_unlock(&sdata->local->iflist_mtx);
110}
111
Phoebe Buckheister29e02372014-05-16 17:46:42 +0200112static struct ieee802154_llsec_ops mac802154_llsec_ops = {
113 .get_params = mac802154_get_params,
114 .set_params = mac802154_set_params,
115 .add_key = mac802154_add_key,
116 .del_key = mac802154_del_key,
117 .add_dev = mac802154_add_dev,
118 .del_dev = mac802154_del_dev,
119 .add_devkey = mac802154_add_devkey,
120 .del_devkey = mac802154_del_devkey,
121 .add_seclevel = mac802154_add_seclevel,
122 .del_seclevel = mac802154_del_seclevel,
123 .lock_table = mac802154_lock_table,
124 .get_table = mac802154_get_table,
125 .unlock_table = mac802154_unlock_table,
126};
127
alex.bluesman.smirnov@gmail.com32bad7e2012-06-25 23:24:48 +0000128struct ieee802154_mlme_ops mac802154_mlme_wpan = {
alex.bluesman.smirnov@gmail.com5265f462012-06-25 23:24:52 +0000129 .start_req = mac802154_mlme_start_req,
alex.bluesman.smirnov@gmail.come885a472012-07-10 21:22:44 +0000130 .get_pan_id = mac802154_dev_get_pan_id,
131 .get_short_addr = mac802154_dev_get_short_addr,
Tony Cheneau04835462013-03-25 17:59:29 +0000132 .get_dsn = mac802154_dev_get_dsn,
Phoebe Buckheistere462ded2014-03-31 21:37:46 +0200133
Phoebe Buckheister29e02372014-05-16 17:46:42 +0200134 .llsec = &mac802154_llsec_ops,
135
Phoebe Buckheistere462ded2014-03-31 21:37:46 +0200136 .set_mac_params = mac802154_set_mac_params,
137 .get_mac_params = mac802154_get_mac_params,
alex.bluesman.smirnov@gmail.com32bad7e2012-06-25 23:24:48 +0000138};