orinoco: add hermes_ops
[orinoco_usb.git] / drivers / net / wireless / orinoco / cfg.c
blob8225e84ce75988d6d71ecb9ed0f603306dc6a6c0
1 /* cfg80211 support
3 * See copyright notice in main.c
4 */
5 #include <linux/ieee80211.h>
6 #include <net/cfg80211.h>
7 #include "hw.h"
8 #include "main.h"
9 #include "orinoco.h"
11 #include "cfg.h"
13 /* Supported bitrates. Must agree with hw.c */
14 static struct ieee80211_rate orinoco_rates[] = {
15 { .bitrate = 10 },
16 { .bitrate = 20 },
17 { .bitrate = 55 },
18 { .bitrate = 110 },
21 static const void * const orinoco_wiphy_privid = &orinoco_wiphy_privid;
23 /* Called after orinoco_private is allocated. */
24 void orinoco_wiphy_init(struct wiphy *wiphy)
26 struct orinoco_private *priv = wiphy_priv(wiphy);
28 wiphy->privid = orinoco_wiphy_privid;
30 set_wiphy_dev(wiphy, priv->dev);
33 /* Called after firmware is initialised */
34 int orinoco_wiphy_register(struct wiphy *wiphy)
36 struct orinoco_private *priv = wiphy_priv(wiphy);
37 int i, channels = 0;
39 if (priv->firmware_type == FIRMWARE_TYPE_AGERE)
40 wiphy->max_scan_ssids = 1;
41 else
42 wiphy->max_scan_ssids = 0;
44 wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION);
46 /* TODO: should we set if we only have demo ad-hoc?
47 * (priv->has_port3)
49 if (priv->has_ibss)
50 wiphy->interface_modes |= BIT(NL80211_IFTYPE_ADHOC);
52 if (!priv->broken_monitor || force_monitor)
53 wiphy->interface_modes |= BIT(NL80211_IFTYPE_MONITOR);
55 priv->band.bitrates = orinoco_rates;
56 priv->band.n_bitrates = ARRAY_SIZE(orinoco_rates);
58 /* Only support channels allowed by the card EEPROM */
59 for (i = 0; i < NUM_CHANNELS; i++) {
60 if (priv->channel_mask & (1 << i)) {
61 priv->channels[i].center_freq =
62 ieee80211_dsss_chan_to_freq(i+1);
63 channels++;
66 priv->band.channels = priv->channels;
67 priv->band.n_channels = channels;
69 wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->band;
70 wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
72 i = 0;
73 if (priv->has_wep) {
74 priv->cipher_suites[i] = WLAN_CIPHER_SUITE_WEP40;
75 i++;
77 if (priv->has_big_wep) {
78 priv->cipher_suites[i] = WLAN_CIPHER_SUITE_WEP104;
79 i++;
82 if (priv->has_wpa) {
83 priv->cipher_suites[i] = WLAN_CIPHER_SUITE_TKIP;
84 i++;
86 wiphy->cipher_suites = priv->cipher_suites;
87 wiphy->n_cipher_suites = i;
89 wiphy->rts_threshold = priv->rts_thresh;
90 if (!priv->has_mwo)
91 wiphy->frag_threshold = priv->frag_thresh;
93 return wiphy_register(wiphy);
96 static int orinoco_change_vif(struct wiphy *wiphy, struct net_device *dev,
97 enum nl80211_iftype type, u32 *flags,
98 struct vif_params *params)
100 struct orinoco_private *priv = wiphy_priv(wiphy);
101 int err = 0;
102 unsigned long lock;
104 if (orinoco_lock(priv, &lock) != 0)
105 return -EBUSY;
107 switch (type) {
108 case NL80211_IFTYPE_ADHOC:
109 if (!priv->has_ibss && !priv->has_port3)
110 err = -EINVAL;
111 break;
113 case NL80211_IFTYPE_STATION:
114 break;
116 case NL80211_IFTYPE_MONITOR:
117 if (priv->broken_monitor && !force_monitor) {
118 printk(KERN_WARNING "%s: Monitor mode support is "
119 "buggy in this firmware, not enabling\n",
120 wiphy_name(wiphy));
121 err = -EINVAL;
123 break;
125 default:
126 err = -EINVAL;
129 if (!err) {
130 priv->iw_mode = type;
131 set_port_type(priv);
132 err = orinoco_commit(priv);
135 orinoco_unlock(priv, &lock);
137 return err;
140 static int orinoco_scan(struct wiphy *wiphy, struct net_device *dev,
141 struct cfg80211_scan_request *request)
143 struct orinoco_private *priv = wiphy_priv(wiphy);
144 int err;
146 if (!request)
147 return -EINVAL;
149 if (priv->scan_request && priv->scan_request != request)
150 return -EBUSY;
152 priv->scan_request = request;
154 err = orinoco_hw_trigger_scan(priv, request->ssids);
156 return err;
159 static int orinoco_set_channel(struct wiphy *wiphy,
160 struct ieee80211_channel *chan,
161 enum nl80211_channel_type channel_type)
163 struct orinoco_private *priv = wiphy_priv(wiphy);
164 int err = 0;
165 unsigned long flags;
166 int channel;
168 if (!chan)
169 return -EINVAL;
171 if (channel_type != NL80211_CHAN_NO_HT)
172 return -EINVAL;
174 if (chan->band != IEEE80211_BAND_2GHZ)
175 return -EINVAL;
177 channel = ieee80211_freq_to_dsss_chan(chan->center_freq);
179 if ((channel < 1) || (channel > NUM_CHANNELS) ||
180 !(priv->channel_mask & (1 << (channel-1))))
181 return -EINVAL;
183 if (orinoco_lock(priv, &flags) != 0)
184 return -EBUSY;
186 priv->channel = channel;
187 if (priv->iw_mode == NL80211_IFTYPE_MONITOR) {
188 /* Fast channel change - no commit if successful */
189 hermes_t *hw = &priv->hw;
190 err = hw->ops->cmd_wait(hw, HERMES_CMD_TEST |
191 HERMES_TEST_SET_CHANNEL,
192 channel, NULL);
194 orinoco_unlock(priv, &flags);
196 return err;
199 const struct cfg80211_ops orinoco_cfg_ops = {
200 .change_virtual_intf = orinoco_change_vif,
201 .set_channel = orinoco_set_channel,
202 .scan = orinoco_scan,