ieee80211_action.c revision 195618
1181344Sdfr/*- 2181344Sdfr * Copyright (c) 2009 Sam Leffler, Errno Consulting 3208291Suqs * All rights reserved. 4181344Sdfr * 5181344Sdfr * Redistribution and use in source and binary forms, with or without 6181344Sdfr * modification, are permitted provided that the following conditions 7181344Sdfr * are met: 8181344Sdfr * 1. Redistributions of source code must retain the above copyright 9181344Sdfr * notice, this list of conditions and the following disclaimer. 10181344Sdfr * 2. Redistributions in binary form must reproduce the above copyright 11181344Sdfr * notice, this list of conditions and the following disclaimer in the 12181344Sdfr * documentation and/or other materials provided with the distribution. 13181344Sdfr * 14181344Sdfr * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 15181344Sdfr * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16181344Sdfr * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17181344Sdfr * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18181344Sdfr * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19181344Sdfr * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20181344Sdfr * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21181344Sdfr * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22181344Sdfr * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23181344Sdfr * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24181344Sdfr */ 25181344Sdfr 26181344Sdfr#include <sys/cdefs.h> 27203026Sgavin#ifdef __FreeBSD__ 28181344Sdfr__FBSDID("$FreeBSD: head/sys/net80211/ieee80211_action.c 195618 2009-07-11 15:02:45Z rpaulo $"); 29181344Sdfr#endif 30181344Sdfr 31181344Sdfr/* 32181344Sdfr * IEEE 802.11 send/recv action frame support. 33181344Sdfr */ 34181344Sdfr 35181344Sdfr#include "opt_inet.h" 36181344Sdfr#include "opt_wlan.h" 37181344Sdfr 38181344Sdfr#include <sys/param.h> 39181344Sdfr#include <sys/kernel.h> 40181344Sdfr#include <sys/systm.h> 41181344Sdfr 42181344Sdfr#include <sys/socket.h> 43181344Sdfr 44181344Sdfr#include <net/if.h> 45181344Sdfr#include <net/if_media.h> 46181344Sdfr#include <net/ethernet.h> 47181344Sdfr 48181344Sdfr#include <net80211/ieee80211_var.h> 49236668Sjoel#include <net80211/ieee80211_action.h> 50181344Sdfr#include <net80211/ieee80211_mesh.h> 51181344Sdfr 52181344Sdfrstatic int 53181344Sdfrsend_inval(struct ieee80211_node *ni, int cat, int act, void *sa) 54181344Sdfr{ 55181344Sdfr return EINVAL; 56181344Sdfr} 57181344Sdfr 58181344Sdfrstatic ieee80211_send_action_func *ba_send_action[8] = { 59181344Sdfr send_inval, send_inval, send_inval, send_inval, 60181344Sdfr send_inval, send_inval, send_inval, send_inval, 61181344Sdfr}; 62181344Sdfrstatic ieee80211_send_action_func *ht_send_action[8] = { 63181344Sdfr send_inval, send_inval, send_inval, send_inval, 64181344Sdfr send_inval, send_inval, send_inval, send_inval, 65181344Sdfr}; 66181344Sdfrstatic ieee80211_send_action_func *meshpl_send_action[8] = { 67181344Sdfr send_inval, send_inval, send_inval, send_inval, 68181344Sdfr send_inval, send_inval, send_inval, send_inval, 69181344Sdfr}; 70181344Sdfrstatic ieee80211_send_action_func *meshlm_send_action[4] = { 71181344Sdfr send_inval, send_inval, send_inval, send_inval, 72181344Sdfr}; 73181344Sdfrstatic ieee80211_send_action_func *hwmp_send_action[8] = { 74181344Sdfr send_inval, send_inval, send_inval, send_inval, 75181344Sdfr send_inval, send_inval, send_inval, send_inval, 76181344Sdfr}; 77203025Sgavinstatic ieee80211_send_action_func *vendor_send_action[8] = { 78181344Sdfr send_inval, send_inval, send_inval, send_inval, 79181344Sdfr send_inval, send_inval, send_inval, send_inval, 80181344Sdfr}; 81181344Sdfr 82181344Sdfrint 83ieee80211_send_action_register(int cat, int act, ieee80211_send_action_func *f) 84{ 85#define N(a) (sizeof(a) / sizeof(a[0])) 86 switch (cat) { 87 case IEEE80211_ACTION_CAT_BA: 88 if (act >= N(ba_send_action)) 89 break; 90 ba_send_action[act] = f; 91 return 0; 92 case IEEE80211_ACTION_CAT_HT: 93 if (act >= N(ht_send_action)) 94 break; 95 ht_send_action[act] = f; 96 return 0; 97 case IEEE80211_ACTION_CAT_MESHPEERING: 98 if (act >= N(meshpl_send_action)) 99 break; 100 meshpl_send_action[act] = f; 101 return 0; 102 case IEEE80211_ACTION_CAT_MESHLMETRIC: 103 if (act >= N(meshlm_send_action)) 104 break; 105 meshlm_send_action[act] = f; 106 return 0; 107 case IEEE80211_ACTION_CAT_MESHPATH: 108 if (act > N(hwmp_send_action)) 109 break; 110 hwmp_send_action[act] = f; 111 return 0; 112 case IEEE80211_ACTION_CAT_VENDOR: 113 if (act >= N(vendor_send_action)) 114 break; 115 vendor_send_action[act] = f; 116 return 0; 117 } 118 return EINVAL; 119#undef N 120} 121 122void 123ieee80211_send_action_unregister(int cat, int act) 124{ 125 ieee80211_send_action_register(cat, act, send_inval); 126} 127 128int 129ieee80211_send_action(struct ieee80211_node *ni, int cat, int act, void *sa) 130{ 131#define N(a) (sizeof(a) / sizeof(a[0])) 132 ieee80211_send_action_func *f = send_inval; 133 134 switch (cat) { 135 case IEEE80211_ACTION_CAT_BA: 136 if (act < N(ba_send_action)) 137 f = ba_send_action[act]; 138 break; 139 case IEEE80211_ACTION_CAT_HT: 140 if (act < N(ht_send_action)) 141 f = ht_send_action[act]; 142 break; 143 case IEEE80211_ACTION_CAT_MESHPEERING: 144 if (act < N(meshpl_send_action)) 145 f = meshpl_send_action[act]; 146 break; 147 case IEEE80211_ACTION_CAT_MESHLMETRIC: 148 if (act < N(meshlm_send_action)) 149 f = meshlm_send_action[act]; 150 break; 151 case IEEE80211_ACTION_CAT_MESHPATH: 152 if (act < N(hwmp_send_action)) 153 f = hwmp_send_action[act]; 154 break; 155 case IEEE80211_ACTION_CAT_VENDOR: 156 if (act < N(vendor_send_action)) 157 f = vendor_send_action[act]; 158 break; 159 } 160 return f(ni, cat, act, sa); 161#undef N 162} 163 164static int 165recv_inval(struct ieee80211_node *ni, const struct ieee80211_frame *wh, 166 const uint8_t *frm, const uint8_t *efrm) 167{ 168 return EINVAL; 169} 170 171static ieee80211_recv_action_func *ba_recv_action[8] = { 172 recv_inval, recv_inval, recv_inval, recv_inval, 173 recv_inval, recv_inval, recv_inval, recv_inval, 174}; 175static ieee80211_recv_action_func *ht_recv_action[8] = { 176 recv_inval, recv_inval, recv_inval, recv_inval, 177 recv_inval, recv_inval, recv_inval, recv_inval, 178}; 179static ieee80211_recv_action_func *meshpl_recv_action[8] = { 180 recv_inval, recv_inval, recv_inval, recv_inval, 181 recv_inval, recv_inval, recv_inval, recv_inval, 182}; 183static ieee80211_recv_action_func *meshlm_recv_action[4] = { 184 recv_inval, recv_inval, recv_inval, recv_inval, 185}; 186static ieee80211_recv_action_func *hwmp_recv_action[8] = { 187 recv_inval, recv_inval, recv_inval, recv_inval, 188 recv_inval, recv_inval, recv_inval, recv_inval, 189}; 190static ieee80211_recv_action_func *vendor_recv_action[8] = { 191 recv_inval, recv_inval, recv_inval, recv_inval, 192 recv_inval, recv_inval, recv_inval, recv_inval, 193}; 194 195int 196ieee80211_recv_action_register(int cat, int act, ieee80211_recv_action_func *f) 197{ 198#define N(a) (sizeof(a) / sizeof(a[0])) 199 switch (cat) { 200 case IEEE80211_ACTION_CAT_BA: 201 if (act >= N(ba_recv_action)) 202 break; 203 ba_recv_action[act] = f; 204 return 0; 205 case IEEE80211_ACTION_CAT_HT: 206 if (act >= N(ht_recv_action)) 207 break; 208 ht_recv_action[act] = f; 209 return 0; 210 case IEEE80211_ACTION_CAT_MESHPEERING: 211 if (act >= N(meshpl_recv_action)) 212 break; 213 meshpl_recv_action[act] = f; 214 return 0; 215 case IEEE80211_ACTION_CAT_MESHLMETRIC: 216 if (act >= N(meshlm_recv_action)) 217 break; 218 meshlm_recv_action[act] = f; 219 return 0; 220 case IEEE80211_ACTION_CAT_MESHPATH: 221 if (act >= N(hwmp_recv_action)) 222 break; 223 hwmp_recv_action[act] = f; 224 return 0; 225 case IEEE80211_ACTION_CAT_VENDOR: 226 if (act >= N(vendor_recv_action)) 227 break; 228 vendor_recv_action[act] = f; 229 return 0; 230 } 231 return EINVAL; 232#undef N 233} 234 235void 236ieee80211_recv_action_unregister(int cat, int act) 237{ 238 ieee80211_recv_action_register(cat, act, recv_inval); 239} 240 241int 242ieee80211_recv_action(struct ieee80211_node *ni, 243 const struct ieee80211_frame *wh, 244 const uint8_t *frm, const uint8_t *efrm) 245{ 246#define N(a) (sizeof(a) / sizeof(a[0])) 247 ieee80211_recv_action_func *f = recv_inval; 248 const struct ieee80211_action *ia = 249 (const struct ieee80211_action *) frm; 250 251 switch (ia->ia_category) { 252 case IEEE80211_ACTION_CAT_BA: 253 if (ia->ia_action < N(ba_recv_action)) 254 f = ba_recv_action[ia->ia_action]; 255 break; 256 case IEEE80211_ACTION_CAT_HT: 257 if (ia->ia_action < N(ht_recv_action)) 258 f = ht_recv_action[ia->ia_action]; 259 break; 260 case IEEE80211_ACTION_CAT_MESHPEERING: 261 if (ia->ia_action < N(meshpl_recv_action)) 262 f = meshpl_recv_action[ia->ia_action]; 263 break; 264 case IEEE80211_ACTION_CAT_MESHLMETRIC: 265 if (ia->ia_action < N(meshlm_recv_action)) 266 f = meshlm_recv_action[ia->ia_action]; 267 break; 268 case IEEE80211_ACTION_CAT_MESHPATH: 269 if (ia->ia_action < N(hwmp_recv_action)) 270 f = hwmp_recv_action[ia->ia_action]; 271 break; 272 case IEEE80211_ACTION_CAT_VENDOR: 273 if (ia->ia_action < N(vendor_recv_action)) 274 f = vendor_recv_action[ia->ia_action]; 275 break; 276 } 277 return f(ni, wh, frm, efrm); 278#undef N 279} 280