1 /* $OpenBSD: if_urtwn.c,v 1.16 2011/02/10 17:26:40 jakemsr Exp $ */ 2 3 /*- 4 * Copyright (c) 2010 Damien Bergamini <damien.bergamini@free.fr> 5 * Copyright (c) 2014 Kevin Lo <kevlo@FreeBSD.org> 6 * Copyright (c) 2015-2016 Andriy Voskoboinyk <avos@FreeBSD.org> 7 * 8 * Permission to use, copy, modify, and distribute this software for any 9 * purpose with or without fee is hereby granted, provided that the above 10 * copyright notice and this permission notice appear in all copies. 11 * 12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 13 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 14 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 15 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 16 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 17 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 18 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 19 * 20 * $FreeBSD$ 21 */ 22 23 #ifndef IF_RTWN_RIDX_H 24 #define IF_RTWN_RIDX_H 25 26 /* HW rate indices. */ 27 #define RTWN_RIDX_CCK1 0 28 #define RTWN_RIDX_CCK2 1 29 #define RTWN_RIDX_CCK55 2 30 #define RTWN_RIDX_CCK11 3 31 #define RTWN_RIDX_OFDM6 4 32 #define RTWN_RIDX_OFDM9 5 33 #define RTWN_RIDX_OFDM12 6 34 #define RTWN_RIDX_OFDM18 7 35 #define RTWN_RIDX_OFDM24 8 36 #define RTWN_RIDX_OFDM36 9 37 #define RTWN_RIDX_OFDM48 10 38 #define RTWN_RIDX_OFDM54 11 39 40 #define RTWN_RIDX_HT_MCS_SHIFT 12 41 #define RTWN_RIDX_HT_MCS(i) (RTWN_RIDX_HT_MCS_SHIFT + (i)) 42 43 #define RTWN_RIDX_COUNT 28 44 #define RTWN_RIDX_UNKNOWN (uint8_t)-1 45 46 #define RTWN_RATE_IS_CCK(rate) ((rate) <= RTWN_RIDX_CCK11) 47 #define RTWN_RATE_IS_OFDM(rate) \ 48 ((rate) >= RTWN_RIDX_OFDM6 && (rate) != RTWN_RIDX_UNKNOWN) 49 50 51 static const uint8_t ridx2rate[] = 52 { 2, 4, 11, 22, 12, 18, 24, 36, 48, 72, 96, 108 }; 53 54 static __inline uint8_t 55 rate2ridx(uint8_t rate) 56 { 57 if (rate & IEEE80211_RATE_MCS) { 58 return ((rate & 0xf) + RTWN_RIDX_HT_MCS_SHIFT); 59 } 60 switch (rate) { 61 /* 11g */ 62 case 12: return 4; 63 case 18: return 5; 64 case 24: return 6; 65 case 36: return 7; 66 case 48: return 8; 67 case 72: return 9; 68 case 96: return 10; 69 case 108: return 11; 70 /* 11b */ 71 case 2: return 0; 72 case 4: return 1; 73 case 11: return 2; 74 case 22: return 3; 75 default: return RTWN_RIDX_UNKNOWN; 76 } 77 } 78 79 /* XXX move to net80211 */ 80 static __inline__ uint8_t 81 rtwn_ctl_mcsrate(const struct ieee80211_rate_table *rt, uint8_t ridx) 82 { 83 uint8_t cix, rate; 84 85 /* Check if we are using MCS rate. */ 86 KASSERT(ridx >= RTWN_RIDX_HT_MCS(0) && ridx != RTWN_RIDX_UNKNOWN, 87 ("bad mcs rate index %d", ridx)); 88 89 rate = (ridx - RTWN_RIDX_HT_MCS(0)) | IEEE80211_RATE_MCS; 90 cix = rt->info[rt->rateCodeToIndex[rate]].ctlRateIndex; 91 KASSERT(cix != (uint8_t)-1, ("rate %d (%d) has no info", rate, ridx)); 92 return rt->info[cix].dot11Rate; 93 } 94 95 #endif /* IF_RTWN_RIDX_H */ 96