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> 36*8ec07310SGleb Smirnoff #include <sys/malloc.h> 376fe391f4SGleb Smirnoff #include <sys/systm.h> 388a1b9b6aSSam Leffler #include <sys/mbuf.h> 398a1b9b6aSSam Leffler #include <sys/module.h> 408a1b9b6aSSam Leffler 418a1b9b6aSSam Leffler #include <sys/socket.h> 428a1b9b6aSSam Leffler 438a1b9b6aSSam Leffler #include <net/if.h> 448a1b9b6aSSam Leffler #include <net/if_media.h> 458a1b9b6aSSam Leffler #include <net/ethernet.h> 468a1b9b6aSSam Leffler 478a1b9b6aSSam Leffler #include <net80211/ieee80211_var.h> 488a1b9b6aSSam Leffler 49b032f27cSSam Leffler static void *none_attach(struct ieee80211vap *, struct ieee80211_key *); 508a1b9b6aSSam Leffler static void none_detach(struct ieee80211_key *); 518a1b9b6aSSam Leffler static int none_setkey(struct ieee80211_key *); 52c0cb9349SAdrian Chadd static void none_setiv(struct ieee80211_key *, uint8_t *); 53ef0d8f63SAdrian Chadd static int none_encap(struct ieee80211_key *, struct mbuf *); 542cc12adeSSam Leffler static int none_decap(struct ieee80211_key *, struct mbuf *, int); 5596d88463SSam Leffler static int none_enmic(struct ieee80211_key *, struct mbuf *, int); 5696d88463SSam Leffler static int none_demic(struct ieee80211_key *, struct mbuf *, int); 578a1b9b6aSSam Leffler 588a1b9b6aSSam Leffler const struct ieee80211_cipher ieee80211_cipher_none = { 598a1b9b6aSSam Leffler .ic_name = "NONE", 608a1b9b6aSSam Leffler .ic_cipher = IEEE80211_CIPHER_NONE, 618a1b9b6aSSam Leffler .ic_header = 0, 628a1b9b6aSSam Leffler .ic_trailer = 0, 638a1b9b6aSSam Leffler .ic_miclen = 0, 648a1b9b6aSSam Leffler .ic_attach = none_attach, 658a1b9b6aSSam Leffler .ic_detach = none_detach, 668a1b9b6aSSam Leffler .ic_setkey = none_setkey, 67c0cb9349SAdrian Chadd .ic_setiv = none_setiv, 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 * 75b032f27cSSam Leffler none_attach(struct ieee80211vap *vap, struct ieee80211_key *k) 768a1b9b6aSSam Leffler { 77b032f27cSSam Leffler return vap; /* 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 93c0cb9349SAdrian Chadd static void 94c0cb9349SAdrian Chadd none_setiv(struct ieee80211_key *k, uint8_t *ivp) 95c0cb9349SAdrian Chadd { 96c0cb9349SAdrian Chadd } 97c0cb9349SAdrian Chadd 988a1b9b6aSSam Leffler static int 99ef0d8f63SAdrian Chadd none_encap(struct ieee80211_key *k, struct mbuf *m) 1008a1b9b6aSSam Leffler { 101b032f27cSSam Leffler struct ieee80211vap *vap = k->wk_private; 1028a1b9b6aSSam Leffler #ifdef IEEE80211_DEBUG 1038a1b9b6aSSam Leffler struct ieee80211_frame *wh = mtod(m, struct ieee80211_frame *); 1048a1b9b6aSSam Leffler #endif 105ef0d8f63SAdrian Chadd uint8_t keyid; 106ef0d8f63SAdrian Chadd 107ef0d8f63SAdrian Chadd keyid = ieee80211_crypto_get_keyid(vap, k); 1088a1b9b6aSSam Leffler 1098a1b9b6aSSam Leffler /* 1108a1b9b6aSSam Leffler * The specified key is not setup; this can 1118a1b9b6aSSam Leffler * happen, at least, when changing keys. 1128a1b9b6aSSam Leffler */ 113b032f27cSSam Leffler IEEE80211_NOTE_MAC(vap, IEEE80211_MSG_CRYPTO, wh->i_addr1, 114ef0d8f63SAdrian Chadd "key id %u is not set (encap)", keyid); 115b032f27cSSam Leffler vap->iv_stats.is_tx_badcipher++; 1168a1b9b6aSSam Leffler return 0; 1178a1b9b6aSSam Leffler } 1188a1b9b6aSSam Leffler 1198a1b9b6aSSam Leffler static int 1202cc12adeSSam Leffler none_decap(struct ieee80211_key *k, struct mbuf *m, int hdrlen) 1218a1b9b6aSSam Leffler { 122b032f27cSSam Leffler struct ieee80211vap *vap = k->wk_private; 1238a1b9b6aSSam Leffler #ifdef IEEE80211_DEBUG 1248a1b9b6aSSam Leffler struct ieee80211_frame *wh = mtod(m, struct ieee80211_frame *); 12568e8e04eSSam Leffler const uint8_t *ivp = (const uint8_t *)&wh[1]; 1268a1b9b6aSSam Leffler #endif 1278a1b9b6aSSam Leffler 1288a1b9b6aSSam Leffler /* 1298a1b9b6aSSam Leffler * The specified key is not setup; this can 1308a1b9b6aSSam Leffler * happen, at least, when changing keys. 1318a1b9b6aSSam Leffler */ 1328a1b9b6aSSam Leffler /* XXX useful to know dst too */ 133b032f27cSSam Leffler IEEE80211_NOTE_MAC(vap, IEEE80211_MSG_CRYPTO, wh->i_addr2, 134b032f27cSSam Leffler "key id %u is not set (decap)", ivp[IEEE80211_WEP_IVLEN] >> 6); 135b032f27cSSam Leffler vap->iv_stats.is_rx_badkeyid++; 1368a1b9b6aSSam Leffler return 0; 1378a1b9b6aSSam Leffler } 1388a1b9b6aSSam Leffler 1398a1b9b6aSSam Leffler static int 14096d88463SSam Leffler none_enmic(struct ieee80211_key *k, struct mbuf *m, int force) 1418a1b9b6aSSam Leffler { 142b032f27cSSam Leffler struct ieee80211vap *vap = k->wk_private; 1438a1b9b6aSSam Leffler 144b032f27cSSam Leffler vap->iv_stats.is_tx_badcipher++; 1458a1b9b6aSSam Leffler return 0; 1468a1b9b6aSSam Leffler } 1478a1b9b6aSSam Leffler 1488a1b9b6aSSam Leffler static int 14996d88463SSam Leffler none_demic(struct ieee80211_key *k, struct mbuf *m, int force) 1508a1b9b6aSSam Leffler { 151b032f27cSSam Leffler struct ieee80211vap *vap = k->wk_private; 1528a1b9b6aSSam Leffler 153b032f27cSSam Leffler vap->iv_stats.is_rx_badkeyid++; 1548a1b9b6aSSam Leffler return 0; 1558a1b9b6aSSam Leffler } 156