18a1b9b6aSSam Leffler /*- 2b032f27cSSam Leffler * Copyright (c) 2002-2008 Sam Leffler, Errno Consulting 38a1b9b6aSSam Leffler * All rights reserved. 48a1b9b6aSSam Leffler * 58a1b9b6aSSam Leffler * Redistribution and use in source and binary forms, with or without 68a1b9b6aSSam Leffler * modification, are permitted provided that the following conditions 78a1b9b6aSSam Leffler * are met: 88a1b9b6aSSam Leffler * 1. Redistributions of source code must retain the above copyright 98a1b9b6aSSam Leffler * notice, this list of conditions and the following disclaimer. 108a1b9b6aSSam Leffler * 2. Redistributions in binary form must reproduce the above copyright 118a1b9b6aSSam Leffler * notice, this list of conditions and the following disclaimer in the 128a1b9b6aSSam Leffler * documentation and/or other materials provided with the distribution. 138a1b9b6aSSam Leffler * 148a1b9b6aSSam Leffler * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 158a1b9b6aSSam Leffler * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 168a1b9b6aSSam Leffler * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 178a1b9b6aSSam Leffler * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 188a1b9b6aSSam Leffler * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 198a1b9b6aSSam Leffler * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 208a1b9b6aSSam Leffler * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 218a1b9b6aSSam Leffler * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 228a1b9b6aSSam Leffler * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 238a1b9b6aSSam Leffler * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 248a1b9b6aSSam Leffler */ 258a1b9b6aSSam Leffler 268a1b9b6aSSam Leffler #include <sys/cdefs.h> 278a1b9b6aSSam Leffler __FBSDID("$FreeBSD$"); 288a1b9b6aSSam Leffler 298a1b9b6aSSam Leffler /* 308a1b9b6aSSam Leffler * IEEE 802.11 NULL crypto support. 318a1b9b6aSSam Leffler */ 32b032f27cSSam Leffler #include "opt_wlan.h" 33b032f27cSSam Leffler 348a1b9b6aSSam Leffler #include <sys/param.h> 3581c04d11SGleb Smirnoff #include <sys/kernel.h> 366fe391f4SGleb Smirnoff #include <sys/systm.h> 378a1b9b6aSSam Leffler #include <sys/mbuf.h> 388a1b9b6aSSam Leffler #include <sys/module.h> 398a1b9b6aSSam Leffler 408a1b9b6aSSam Leffler #include <sys/socket.h> 418a1b9b6aSSam Leffler 428a1b9b6aSSam Leffler #include <net/if.h> 438a1b9b6aSSam Leffler #include <net/if_media.h> 448a1b9b6aSSam Leffler #include <net/ethernet.h> 458a1b9b6aSSam Leffler 468a1b9b6aSSam Leffler #include <net80211/ieee80211_var.h> 478a1b9b6aSSam Leffler 48b032f27cSSam Leffler static void *none_attach(struct ieee80211vap *, struct ieee80211_key *); 498a1b9b6aSSam Leffler static void none_detach(struct ieee80211_key *); 508a1b9b6aSSam Leffler static int none_setkey(struct ieee80211_key *); 51*c0cb9349SAdrian Chadd static void none_setiv(struct ieee80211_key *, uint8_t *); 52ef0d8f63SAdrian Chadd static int none_encap(struct ieee80211_key *, struct mbuf *); 532cc12adeSSam Leffler static int none_decap(struct ieee80211_key *, struct mbuf *, int); 5496d88463SSam Leffler static int none_enmic(struct ieee80211_key *, struct mbuf *, int); 5596d88463SSam Leffler static int none_demic(struct ieee80211_key *, struct mbuf *, int); 568a1b9b6aSSam Leffler 578a1b9b6aSSam Leffler const struct ieee80211_cipher ieee80211_cipher_none = { 588a1b9b6aSSam Leffler .ic_name = "NONE", 598a1b9b6aSSam Leffler .ic_cipher = IEEE80211_CIPHER_NONE, 608a1b9b6aSSam Leffler .ic_header = 0, 618a1b9b6aSSam Leffler .ic_trailer = 0, 628a1b9b6aSSam Leffler .ic_miclen = 0, 638a1b9b6aSSam Leffler .ic_attach = none_attach, 648a1b9b6aSSam Leffler .ic_detach = none_detach, 658a1b9b6aSSam Leffler .ic_setkey = none_setkey, 66*c0cb9349SAdrian Chadd .ic_setiv = none_setiv, 678a1b9b6aSSam Leffler .ic_encap = none_encap, 688a1b9b6aSSam Leffler .ic_decap = none_decap, 698a1b9b6aSSam Leffler .ic_enmic = none_enmic, 708a1b9b6aSSam Leffler .ic_demic = none_demic, 718a1b9b6aSSam Leffler }; 728a1b9b6aSSam Leffler 738a1b9b6aSSam Leffler static void * 74b032f27cSSam Leffler none_attach(struct ieee80211vap *vap, struct ieee80211_key *k) 758a1b9b6aSSam Leffler { 76b032f27cSSam Leffler return vap; /* for diagnostics+stats */ 778a1b9b6aSSam Leffler } 788a1b9b6aSSam Leffler 798a1b9b6aSSam Leffler static void 808a1b9b6aSSam Leffler none_detach(struct ieee80211_key *k) 818a1b9b6aSSam Leffler { 828a1b9b6aSSam Leffler (void) k; 838a1b9b6aSSam Leffler } 848a1b9b6aSSam Leffler 858a1b9b6aSSam Leffler static int 868a1b9b6aSSam Leffler none_setkey(struct ieee80211_key *k) 878a1b9b6aSSam Leffler { 888a1b9b6aSSam Leffler (void) k; 898a1b9b6aSSam Leffler return 1; 908a1b9b6aSSam Leffler } 918a1b9b6aSSam Leffler 92*c0cb9349SAdrian Chadd static void 93*c0cb9349SAdrian Chadd none_setiv(struct ieee80211_key *k, uint8_t *ivp) 94*c0cb9349SAdrian Chadd { 95*c0cb9349SAdrian Chadd } 96*c0cb9349SAdrian Chadd 978a1b9b6aSSam Leffler static int 98ef0d8f63SAdrian Chadd none_encap(struct ieee80211_key *k, struct mbuf *m) 998a1b9b6aSSam Leffler { 100b032f27cSSam Leffler struct ieee80211vap *vap = k->wk_private; 1018a1b9b6aSSam Leffler #ifdef IEEE80211_DEBUG 1028a1b9b6aSSam Leffler struct ieee80211_frame *wh = mtod(m, struct ieee80211_frame *); 1038a1b9b6aSSam Leffler #endif 104ef0d8f63SAdrian Chadd uint8_t keyid; 105ef0d8f63SAdrian Chadd 106ef0d8f63SAdrian Chadd keyid = ieee80211_crypto_get_keyid(vap, k); 1078a1b9b6aSSam Leffler 1088a1b9b6aSSam Leffler /* 1098a1b9b6aSSam Leffler * The specified key is not setup; this can 1108a1b9b6aSSam Leffler * happen, at least, when changing keys. 1118a1b9b6aSSam Leffler */ 112b032f27cSSam Leffler IEEE80211_NOTE_MAC(vap, IEEE80211_MSG_CRYPTO, wh->i_addr1, 113ef0d8f63SAdrian Chadd "key id %u is not set (encap)", keyid); 114b032f27cSSam Leffler vap->iv_stats.is_tx_badcipher++; 1158a1b9b6aSSam Leffler return 0; 1168a1b9b6aSSam Leffler } 1178a1b9b6aSSam Leffler 1188a1b9b6aSSam Leffler static int 1192cc12adeSSam Leffler none_decap(struct ieee80211_key *k, struct mbuf *m, int hdrlen) 1208a1b9b6aSSam Leffler { 121b032f27cSSam Leffler struct ieee80211vap *vap = k->wk_private; 1228a1b9b6aSSam Leffler #ifdef IEEE80211_DEBUG 1238a1b9b6aSSam Leffler struct ieee80211_frame *wh = mtod(m, struct ieee80211_frame *); 12468e8e04eSSam Leffler const uint8_t *ivp = (const uint8_t *)&wh[1]; 1258a1b9b6aSSam Leffler #endif 1268a1b9b6aSSam Leffler 1278a1b9b6aSSam Leffler /* 1288a1b9b6aSSam Leffler * The specified key is not setup; this can 1298a1b9b6aSSam Leffler * happen, at least, when changing keys. 1308a1b9b6aSSam Leffler */ 1318a1b9b6aSSam Leffler /* XXX useful to know dst too */ 132b032f27cSSam Leffler IEEE80211_NOTE_MAC(vap, IEEE80211_MSG_CRYPTO, wh->i_addr2, 133b032f27cSSam Leffler "key id %u is not set (decap)", ivp[IEEE80211_WEP_IVLEN] >> 6); 134b032f27cSSam Leffler vap->iv_stats.is_rx_badkeyid++; 1358a1b9b6aSSam Leffler return 0; 1368a1b9b6aSSam Leffler } 1378a1b9b6aSSam Leffler 1388a1b9b6aSSam Leffler static int 13996d88463SSam Leffler none_enmic(struct ieee80211_key *k, struct mbuf *m, int force) 1408a1b9b6aSSam Leffler { 141b032f27cSSam Leffler struct ieee80211vap *vap = k->wk_private; 1428a1b9b6aSSam Leffler 143b032f27cSSam Leffler vap->iv_stats.is_tx_badcipher++; 1448a1b9b6aSSam Leffler return 0; 1458a1b9b6aSSam Leffler } 1468a1b9b6aSSam Leffler 1478a1b9b6aSSam Leffler static int 14896d88463SSam Leffler none_demic(struct ieee80211_key *k, struct mbuf *m, int force) 1498a1b9b6aSSam Leffler { 150b032f27cSSam Leffler struct ieee80211vap *vap = k->wk_private; 1518a1b9b6aSSam Leffler 152b032f27cSSam Leffler vap->iv_stats.is_rx_badkeyid++; 1538a1b9b6aSSam Leffler return 0; 1548a1b9b6aSSam Leffler } 155