18a1b9b6aSSam Leffler /*- 21f1d7810SSam Leffler * Copyright (c) 2002-2005 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 * 3. The name of the author may not be used to endorse or promote products 148a1b9b6aSSam Leffler * derived from this software without specific prior written permission. 158a1b9b6aSSam Leffler * 168a1b9b6aSSam Leffler * Alternatively, this software may be distributed under the terms of the 178a1b9b6aSSam Leffler * GNU General Public License ("GPL") version 2 as published by the Free 188a1b9b6aSSam Leffler * Software Foundation. 198a1b9b6aSSam Leffler * 208a1b9b6aSSam Leffler * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 218a1b9b6aSSam Leffler * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 228a1b9b6aSSam Leffler * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 238a1b9b6aSSam Leffler * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 248a1b9b6aSSam Leffler * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 258a1b9b6aSSam Leffler * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 268a1b9b6aSSam Leffler * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 278a1b9b6aSSam Leffler * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 288a1b9b6aSSam Leffler * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 298a1b9b6aSSam Leffler * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 308a1b9b6aSSam Leffler */ 318a1b9b6aSSam Leffler 328a1b9b6aSSam Leffler #include <sys/cdefs.h> 338a1b9b6aSSam Leffler __FBSDID("$FreeBSD$"); 348a1b9b6aSSam Leffler 358a1b9b6aSSam Leffler /* 368a1b9b6aSSam Leffler * IEEE 802.11 NULL crypto support. 378a1b9b6aSSam Leffler */ 388a1b9b6aSSam Leffler #include <sys/param.h> 398a1b9b6aSSam Leffler #include <sys/systm.h> 408a1b9b6aSSam Leffler #include <sys/mbuf.h> 418a1b9b6aSSam Leffler #include <sys/module.h> 428a1b9b6aSSam Leffler 438a1b9b6aSSam Leffler #include <sys/socket.h> 448a1b9b6aSSam Leffler 458a1b9b6aSSam Leffler #include <net/if.h> 468a1b9b6aSSam Leffler #include <net/if_media.h> 478a1b9b6aSSam Leffler #include <net/ethernet.h> 488a1b9b6aSSam Leffler 498a1b9b6aSSam Leffler #include <net80211/ieee80211_var.h> 508a1b9b6aSSam Leffler 518a1b9b6aSSam Leffler static void *none_attach(struct ieee80211com *, struct ieee80211_key *); 528a1b9b6aSSam Leffler static void none_detach(struct ieee80211_key *); 538a1b9b6aSSam Leffler static int none_setkey(struct ieee80211_key *); 548a1b9b6aSSam Leffler static int none_encap(struct ieee80211_key *, struct mbuf *, u_int8_t); 558a1b9b6aSSam Leffler static int none_decap(struct ieee80211_key *, struct mbuf *); 5696d88463SSam Leffler static int none_enmic(struct ieee80211_key *, struct mbuf *, int); 5796d88463SSam Leffler static int none_demic(struct ieee80211_key *, struct mbuf *, int); 588a1b9b6aSSam Leffler 598a1b9b6aSSam Leffler const struct ieee80211_cipher ieee80211_cipher_none = { 608a1b9b6aSSam Leffler .ic_name = "NONE", 618a1b9b6aSSam Leffler .ic_cipher = IEEE80211_CIPHER_NONE, 628a1b9b6aSSam Leffler .ic_header = 0, 638a1b9b6aSSam Leffler .ic_trailer = 0, 648a1b9b6aSSam Leffler .ic_miclen = 0, 658a1b9b6aSSam Leffler .ic_attach = none_attach, 668a1b9b6aSSam Leffler .ic_detach = none_detach, 678a1b9b6aSSam Leffler .ic_setkey = none_setkey, 688a1b9b6aSSam Leffler .ic_encap = none_encap, 698a1b9b6aSSam Leffler .ic_decap = none_decap, 708a1b9b6aSSam Leffler .ic_enmic = none_enmic, 718a1b9b6aSSam Leffler .ic_demic = none_demic, 728a1b9b6aSSam Leffler }; 738a1b9b6aSSam Leffler 748a1b9b6aSSam Leffler static void * 758a1b9b6aSSam Leffler none_attach(struct ieee80211com *ic, struct ieee80211_key *k) 768a1b9b6aSSam Leffler { 778a1b9b6aSSam Leffler return ic; /* for diagnostics+stats */ 788a1b9b6aSSam Leffler } 798a1b9b6aSSam Leffler 808a1b9b6aSSam Leffler static void 818a1b9b6aSSam Leffler none_detach(struct ieee80211_key *k) 828a1b9b6aSSam Leffler { 838a1b9b6aSSam Leffler (void) k; 848a1b9b6aSSam Leffler } 858a1b9b6aSSam Leffler 868a1b9b6aSSam Leffler static int 878a1b9b6aSSam Leffler none_setkey(struct ieee80211_key *k) 888a1b9b6aSSam Leffler { 898a1b9b6aSSam Leffler (void) k; 908a1b9b6aSSam Leffler return 1; 918a1b9b6aSSam Leffler } 928a1b9b6aSSam Leffler 938a1b9b6aSSam Leffler static int 948a1b9b6aSSam Leffler none_encap(struct ieee80211_key *k, struct mbuf *m, u_int8_t keyid) 958a1b9b6aSSam Leffler { 968a1b9b6aSSam Leffler struct ieee80211com *ic = k->wk_private; 978a1b9b6aSSam Leffler #ifdef IEEE80211_DEBUG 988a1b9b6aSSam Leffler struct ieee80211_frame *wh = mtod(m, struct ieee80211_frame *); 998a1b9b6aSSam Leffler #endif 1008a1b9b6aSSam Leffler 1018a1b9b6aSSam Leffler /* 1028a1b9b6aSSam Leffler * The specified key is not setup; this can 1038a1b9b6aSSam Leffler * happen, at least, when changing keys. 1048a1b9b6aSSam Leffler */ 1058a1b9b6aSSam Leffler IEEE80211_DPRINTF(ic, IEEE80211_MSG_CRYPTO, 106f287c95bSSam Leffler "[%s] key id %u is not set (encap)\n", 1078a1b9b6aSSam Leffler ether_sprintf(wh->i_addr1), keyid>>6); 1088a1b9b6aSSam Leffler ic->ic_stats.is_tx_badcipher++; 1098a1b9b6aSSam Leffler return 0; 1108a1b9b6aSSam Leffler } 1118a1b9b6aSSam Leffler 1128a1b9b6aSSam Leffler static int 1138a1b9b6aSSam Leffler none_decap(struct ieee80211_key *k, struct mbuf *m) 1148a1b9b6aSSam Leffler { 1158a1b9b6aSSam Leffler struct ieee80211com *ic = k->wk_private; 1168a1b9b6aSSam Leffler #ifdef IEEE80211_DEBUG 1178a1b9b6aSSam Leffler struct ieee80211_frame *wh = mtod(m, struct ieee80211_frame *); 1188a1b9b6aSSam Leffler const u_int8_t *ivp = (const u_int8_t *)&wh[1]; 1198a1b9b6aSSam Leffler #endif 1208a1b9b6aSSam Leffler 1218a1b9b6aSSam Leffler /* 1228a1b9b6aSSam Leffler * The specified key is not setup; this can 1238a1b9b6aSSam Leffler * happen, at least, when changing keys. 1248a1b9b6aSSam Leffler */ 1258a1b9b6aSSam Leffler /* XXX useful to know dst too */ 1268a1b9b6aSSam Leffler IEEE80211_DPRINTF(ic, IEEE80211_MSG_CRYPTO, 127f287c95bSSam Leffler "[%s] key id %u is not set (decap)\n", 1288a1b9b6aSSam Leffler ether_sprintf(wh->i_addr2), ivp[IEEE80211_WEP_IVLEN] >> 6); 1298a1b9b6aSSam Leffler ic->ic_stats.is_rx_badkeyid++; 1308a1b9b6aSSam Leffler return 0; 1318a1b9b6aSSam Leffler } 1328a1b9b6aSSam Leffler 1338a1b9b6aSSam Leffler static int 13496d88463SSam Leffler none_enmic(struct ieee80211_key *k, struct mbuf *m, int force) 1358a1b9b6aSSam Leffler { 1368a1b9b6aSSam Leffler struct ieee80211com *ic = k->wk_private; 1378a1b9b6aSSam Leffler 1388a1b9b6aSSam Leffler ic->ic_stats.is_tx_badcipher++; 1398a1b9b6aSSam Leffler return 0; 1408a1b9b6aSSam Leffler } 1418a1b9b6aSSam Leffler 1428a1b9b6aSSam Leffler static int 14396d88463SSam Leffler none_demic(struct ieee80211_key *k, struct mbuf *m, int force) 1448a1b9b6aSSam Leffler { 1458a1b9b6aSSam Leffler struct ieee80211com *ic = k->wk_private; 1468a1b9b6aSSam Leffler 1478a1b9b6aSSam Leffler ic->ic_stats.is_rx_badkeyid++; 1488a1b9b6aSSam Leffler return 0; 1498a1b9b6aSSam Leffler } 150