Deleted Added
full compact
ieee80211.c (182742) ieee80211.c (184273)
1/*-
2 * Copyright (c) 2001 Atsushi Onoe
3 * Copyright (c) 2002-2008 Sam Leffler, Errno Consulting
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 11 unchanged lines hidden (view full) ---

20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2001 Atsushi Onoe
3 * Copyright (c) 2002-2008 Sam Leffler, Errno Consulting
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 11 unchanged lines hidden (view full) ---

20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
28__FBSDID("$FreeBSD: head/sys/net80211/ieee80211.c 182742 2008-09-03 20:33:11Z brooks $");
28__FBSDID("$FreeBSD: head/sys/net80211/ieee80211.c 184273 2008-10-25 23:31:20Z sam $");
29
30/*
31 * IEEE 802.11 generic handler
32 */
33#include "opt_wlan.h"
34
35#include <sys/param.h>
36#include <sys/systm.h>

--- 1023 unchanged lines hidden (view full) ---

1060 , c->ic_maxregpower
1061 , c->ic_minpower / 2, c->ic_minpower & 1 ? 5 : 0
1062 , c->ic_maxpower / 2, c->ic_maxpower & 1 ? 5 : 0
1063 );
1064 }
1065}
1066
1067static int
29
30/*
31 * IEEE 802.11 generic handler
32 */
33#include "opt_wlan.h"
34
35#include <sys/param.h>
36#include <sys/systm.h>

--- 1023 unchanged lines hidden (view full) ---

1060 , c->ic_maxregpower
1061 , c->ic_minpower / 2, c->ic_minpower & 1 ? 5 : 0
1062 , c->ic_maxpower / 2, c->ic_maxpower & 1 ? 5 : 0
1063 );
1064 }
1065}
1066
1067static int
1068media2mode(const struct ieee80211com *ic,
1069 const struct ifmedia_entry *ime, enum ieee80211_phymode *mode)
1068media2mode(const struct ifmedia_entry *ime, uint32_t flags, uint16_t *mode)
1070{
1071 switch (IFM_MODE(ime->ifm_media)) {
1072 case IFM_IEEE80211_11A:
1073 *mode = IEEE80211_MODE_11A;
1074 break;
1075 case IFM_IEEE80211_11B:
1076 *mode = IEEE80211_MODE_11B;
1077 break;

--- 16 unchanged lines hidden (view full) ---

1094 return 0;
1095 }
1096 /*
1097 * Turbo mode is an ``option''.
1098 * XXX does not apply to AUTO
1099 */
1100 if (ime->ifm_media & IFM_IEEE80211_TURBO) {
1101 if (*mode == IEEE80211_MODE_11A) {
1069{
1070 switch (IFM_MODE(ime->ifm_media)) {
1071 case IFM_IEEE80211_11A:
1072 *mode = IEEE80211_MODE_11A;
1073 break;
1074 case IFM_IEEE80211_11B:
1075 *mode = IEEE80211_MODE_11B;
1076 break;

--- 16 unchanged lines hidden (view full) ---

1093 return 0;
1094 }
1095 /*
1096 * Turbo mode is an ``option''.
1097 * XXX does not apply to AUTO
1098 */
1099 if (ime->ifm_media & IFM_IEEE80211_TURBO) {
1100 if (*mode == IEEE80211_MODE_11A) {
1102 if (ic->ic_flags & IEEE80211_F_TURBOP)
1101 if (flags & IEEE80211_F_TURBOP)
1103 *mode = IEEE80211_MODE_TURBO_A;
1104 else
1105 *mode = IEEE80211_MODE_STURBO_A;
1106 } else if (*mode == IEEE80211_MODE_11G)
1107 *mode = IEEE80211_MODE_TURBO_G;
1108 else
1109 return 0;
1110 }
1111 /* XXX HT40 +/- */
1112 return 1;
1113}
1114
1115/*
1102 *mode = IEEE80211_MODE_TURBO_A;
1103 else
1104 *mode = IEEE80211_MODE_STURBO_A;
1105 } else if (*mode == IEEE80211_MODE_11G)
1106 *mode = IEEE80211_MODE_TURBO_G;
1107 else
1108 return 0;
1109 }
1110 /* XXX HT40 +/- */
1111 return 1;
1112}
1113
1114/*
1116 * Handle a media change request on the underlying
1117 * interface; we accept mode changes only.
1115 * Handle a media change request on the underlying interface.
1118 */
1119int
1120ieee80211com_media_change(struct ifnet *ifp)
1121{
1116 */
1117int
1118ieee80211com_media_change(struct ifnet *ifp)
1119{
1122 struct ieee80211com *ic = ifp->if_l2com;
1123 struct ifmedia_entry *ime = ic->ic_media.ifm_cur;
1124 enum ieee80211_phymode newphymode;
1125 int error = 0;
1126
1127 /*
1128 * First, identify the phy mode.
1129 */
1130 if (!media2mode(ic, ime, &newphymode))
1131 return EINVAL;
1132 /* NB: mode must be supported, no need to check */
1133
1134 /*
1135 * Handle phy mode change.
1136 */
1137 IEEE80211_LOCK(ic);
1138 if (ic->ic_curmode != newphymode) { /* change phy mode */
1139 struct ieee80211vap *vap;
1140
1141 (void) ieee80211_setmode(ic, newphymode);
1142 /*
1143 * Propagate new state to each vap.
1144 */
1145 TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) {
1146 }
1147 }
1148 IEEE80211_UNLOCK(ic);
1149 return error;
1120 return EINVAL;
1150}
1151
1121}
1122
1152static int
1153findrate(const struct ieee80211com *ic, enum ieee80211_phymode m, int r)
1154{
1155 int i, nrates;
1156
1157 for (i = 0, nrates = ic->ic_sup_rates[m].rs_nrates; i < nrates; i++)
1158 if ((ic->ic_sup_rates[m].rs_rates[i] & IEEE80211_RATE_VAL) == r)
1159 return i;
1160 return -1;
1161}
1162
1163/*
1164 * Handle a media change request on the vap interface.
1165 */
1166int
1167ieee80211_media_change(struct ifnet *ifp)
1168{
1169 struct ieee80211vap *vap = ifp->if_softc;
1170 struct ifmedia_entry *ime = vap->iv_media.ifm_cur;
1123/*
1124 * Handle a media change request on the vap interface.
1125 */
1126int
1127ieee80211_media_change(struct ifnet *ifp)
1128{
1129 struct ieee80211vap *vap = ifp->if_softc;
1130 struct ifmedia_entry *ime = vap->iv_media.ifm_cur;
1171 struct ieee80211com *ic = vap->iv_ic;
1172 int newrate;
1131 uint16_t newmode;
1173
1132
1174 /* XXX this won't work unless ic_curmode is != IEEE80211_MODE_AUTO */
1175 if (ic->ic_curmode == IEEE80211_MODE_AUTO)
1133 if (!media2mode(ime, vap->iv_flags, &newmode))
1176 return EINVAL;
1134 return EINVAL;
1177 if (IFM_SUBTYPE(ime->ifm_media) != IFM_AUTO) {
1178 /*
1179 * NB: this can only be used to specify a legacy rate.
1180 */
1181 newrate = ieee80211_media2rate(ime->ifm_media);
1182 if (newrate == 0)
1183 return EINVAL;
1184 if (findrate(ic, ic->ic_curmode, newrate) == -1)
1185 return EINVAL;
1186 } else {
1187 newrate = IEEE80211_FIXED_RATE_NONE;
1188 }
1189 if (newrate != vap->iv_txparms[ic->ic_curmode].ucastrate) {
1190 vap->iv_txparms[ic->ic_curmode].ucastrate = newrate;
1135 if (vap->iv_des_mode != newmode) {
1136 vap->iv_des_mode = newmode;
1191 return ENETRESET;
1192 }
1193 return 0;
1194}
1195
1196/*
1197 * Common code to calculate the media status word
1198 * from the operating mode and channel state.

--- 324 unchanged lines hidden ---
1137 return ENETRESET;
1138 }
1139 return 0;
1140}
1141
1142/*
1143 * Common code to calculate the media status word
1144 * from the operating mode and channel state.

--- 324 unchanged lines hidden ---