1138568Ssam/*- 2178354Ssam * Copyright (c) 2002-2008 Sam Leffler, Errno Consulting 3138568Ssam * All rights reserved. 4138568Ssam * 5138568Ssam * Redistribution and use in source and binary forms, with or without 6138568Ssam * modification, are permitted provided that the following conditions 7138568Ssam * are met: 8138568Ssam * 1. Redistributions of source code must retain the above copyright 9138568Ssam * notice, this list of conditions and the following disclaimer. 10138568Ssam * 2. Redistributions in binary form must reproduce the above copyright 11138568Ssam * notice, this list of conditions and the following disclaimer in the 12138568Ssam * documentation and/or other materials provided with the distribution. 13138568Ssam * 14138568Ssam * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 15138568Ssam * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16138568Ssam * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17138568Ssam * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18138568Ssam * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19138568Ssam * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20138568Ssam * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21138568Ssam * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22138568Ssam * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23138568Ssam * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24138568Ssam */ 25138568Ssam 26138568Ssam#include <sys/cdefs.h> 27138568Ssam__FBSDID("$FreeBSD$"); 28138568Ssam 29138568Ssam/* 30138568Ssam * IEEE 802.11 NULL crypto support. 31138568Ssam */ 32178354Ssam#include "opt_wlan.h" 33178354Ssam 34138568Ssam#include <sys/param.h> 35178354Ssam#include <sys/kernel.h> 36138568Ssam#include <sys/systm.h> 37138568Ssam#include <sys/mbuf.h> 38138568Ssam#include <sys/module.h> 39138568Ssam 40138568Ssam#include <sys/socket.h> 41138568Ssam 42138568Ssam#include <net/if.h> 43138568Ssam#include <net/if_media.h> 44138568Ssam#include <net/ethernet.h> 45138568Ssam 46138568Ssam#include <net80211/ieee80211_var.h> 47138568Ssam 48178354Ssamstatic void *none_attach(struct ieee80211vap *, struct ieee80211_key *); 49138568Ssamstatic void none_detach(struct ieee80211_key *); 50138568Ssamstatic int none_setkey(struct ieee80211_key *); 51170530Ssamstatic int none_encap(struct ieee80211_key *, struct mbuf *, uint8_t); 52147252Ssamstatic int none_decap(struct ieee80211_key *, struct mbuf *, int); 53147045Ssamstatic int none_enmic(struct ieee80211_key *, struct mbuf *, int); 54147045Ssamstatic int none_demic(struct ieee80211_key *, struct mbuf *, int); 55138568Ssam 56138568Ssamconst struct ieee80211_cipher ieee80211_cipher_none = { 57138568Ssam .ic_name = "NONE", 58138568Ssam .ic_cipher = IEEE80211_CIPHER_NONE, 59138568Ssam .ic_header = 0, 60138568Ssam .ic_trailer = 0, 61138568Ssam .ic_miclen = 0, 62138568Ssam .ic_attach = none_attach, 63138568Ssam .ic_detach = none_detach, 64138568Ssam .ic_setkey = none_setkey, 65138568Ssam .ic_encap = none_encap, 66138568Ssam .ic_decap = none_decap, 67138568Ssam .ic_enmic = none_enmic, 68138568Ssam .ic_demic = none_demic, 69138568Ssam}; 70138568Ssam 71138568Ssamstatic void * 72178354Ssamnone_attach(struct ieee80211vap *vap, struct ieee80211_key *k) 73138568Ssam{ 74178354Ssam return vap; /* for diagnostics+stats */ 75138568Ssam} 76138568Ssam 77138568Ssamstatic void 78138568Ssamnone_detach(struct ieee80211_key *k) 79138568Ssam{ 80138568Ssam (void) k; 81138568Ssam} 82138568Ssam 83138568Ssamstatic int 84138568Ssamnone_setkey(struct ieee80211_key *k) 85138568Ssam{ 86138568Ssam (void) k; 87138568Ssam return 1; 88138568Ssam} 89138568Ssam 90138568Ssamstatic int 91170530Ssamnone_encap(struct ieee80211_key *k, struct mbuf *m, uint8_t keyid) 92138568Ssam{ 93178354Ssam struct ieee80211vap *vap = k->wk_private; 94138568Ssam#ifdef IEEE80211_DEBUG 95138568Ssam struct ieee80211_frame *wh = mtod(m, struct ieee80211_frame *); 96138568Ssam#endif 97138568Ssam 98138568Ssam /* 99138568Ssam * The specified key is not setup; this can 100138568Ssam * happen, at least, when changing keys. 101138568Ssam */ 102178354Ssam IEEE80211_NOTE_MAC(vap, IEEE80211_MSG_CRYPTO, wh->i_addr1, 103178354Ssam "key id %u is not set (encap)", keyid>>6); 104178354Ssam vap->iv_stats.is_tx_badcipher++; 105138568Ssam return 0; 106138568Ssam} 107138568Ssam 108138568Ssamstatic int 109147252Ssamnone_decap(struct ieee80211_key *k, struct mbuf *m, int hdrlen) 110138568Ssam{ 111178354Ssam struct ieee80211vap *vap = k->wk_private; 112138568Ssam#ifdef IEEE80211_DEBUG 113138568Ssam struct ieee80211_frame *wh = mtod(m, struct ieee80211_frame *); 114170530Ssam const uint8_t *ivp = (const uint8_t *)&wh[1]; 115138568Ssam#endif 116138568Ssam 117138568Ssam /* 118138568Ssam * The specified key is not setup; this can 119138568Ssam * happen, at least, when changing keys. 120138568Ssam */ 121138568Ssam /* XXX useful to know dst too */ 122178354Ssam IEEE80211_NOTE_MAC(vap, IEEE80211_MSG_CRYPTO, wh->i_addr2, 123178354Ssam "key id %u is not set (decap)", ivp[IEEE80211_WEP_IVLEN] >> 6); 124178354Ssam vap->iv_stats.is_rx_badkeyid++; 125138568Ssam return 0; 126138568Ssam} 127138568Ssam 128138568Ssamstatic int 129147045Ssamnone_enmic(struct ieee80211_key *k, struct mbuf *m, int force) 130138568Ssam{ 131178354Ssam struct ieee80211vap *vap = k->wk_private; 132138568Ssam 133178354Ssam vap->iv_stats.is_tx_badcipher++; 134138568Ssam return 0; 135138568Ssam} 136138568Ssam 137138568Ssamstatic int 138147045Ssamnone_demic(struct ieee80211_key *k, struct mbuf *m, int force) 139138568Ssam{ 140178354Ssam struct ieee80211vap *vap = k->wk_private; 141138568Ssam 142178354Ssam vap->iv_stats.is_rx_badkeyid++; 143138568Ssam return 0; 144138568Ssam} 145