18a1b9b6aSSam Leffler /*- 2*fe267a55SPedro F. Giffuni * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 3*fe267a55SPedro F. Giffuni * 4b032f27cSSam Leffler * Copyright (c) 2002-2008 Sam Leffler, Errno Consulting 58a1b9b6aSSam Leffler * All rights reserved. 68a1b9b6aSSam Leffler * 78a1b9b6aSSam Leffler * Redistribution and use in source and binary forms, with or without 88a1b9b6aSSam Leffler * modification, are permitted provided that the following conditions 98a1b9b6aSSam Leffler * are met: 108a1b9b6aSSam Leffler * 1. Redistributions of source code must retain the above copyright 118a1b9b6aSSam Leffler * notice, this list of conditions and the following disclaimer. 128a1b9b6aSSam Leffler * 2. Redistributions in binary form must reproduce the above copyright 138a1b9b6aSSam Leffler * notice, this list of conditions and the following disclaimer in the 148a1b9b6aSSam Leffler * documentation and/or other materials provided with the distribution. 158a1b9b6aSSam Leffler * 168a1b9b6aSSam Leffler * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 178a1b9b6aSSam Leffler * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 188a1b9b6aSSam Leffler * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 198a1b9b6aSSam Leffler * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 208a1b9b6aSSam Leffler * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 218a1b9b6aSSam Leffler * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 228a1b9b6aSSam Leffler * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 238a1b9b6aSSam Leffler * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 248a1b9b6aSSam Leffler * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 258a1b9b6aSSam Leffler * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 268a1b9b6aSSam Leffler */ 278a1b9b6aSSam Leffler 288a1b9b6aSSam Leffler #include <sys/cdefs.h> 298a1b9b6aSSam Leffler __FBSDID("$FreeBSD$"); 308a1b9b6aSSam Leffler 318a1b9b6aSSam Leffler /* 328a1b9b6aSSam Leffler * IEEE 802.11 NULL crypto support. 338a1b9b6aSSam Leffler */ 34b032f27cSSam Leffler #include "opt_wlan.h" 35b032f27cSSam Leffler 368a1b9b6aSSam Leffler #include <sys/param.h> 3781c04d11SGleb Smirnoff #include <sys/kernel.h> 388ec07310SGleb Smirnoff #include <sys/malloc.h> 396fe391f4SGleb Smirnoff #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 51b032f27cSSam Leffler static void *none_attach(struct ieee80211vap *, struct ieee80211_key *); 528a1b9b6aSSam Leffler static void none_detach(struct ieee80211_key *); 538a1b9b6aSSam Leffler static int none_setkey(struct ieee80211_key *); 54c0cb9349SAdrian Chadd static void none_setiv(struct ieee80211_key *, uint8_t *); 55ef0d8f63SAdrian Chadd static int none_encap(struct ieee80211_key *, struct mbuf *); 562cc12adeSSam Leffler static int none_decap(struct ieee80211_key *, struct mbuf *, int); 5796d88463SSam Leffler static int none_enmic(struct ieee80211_key *, struct mbuf *, int); 5896d88463SSam Leffler static int none_demic(struct ieee80211_key *, struct mbuf *, int); 598a1b9b6aSSam Leffler 608a1b9b6aSSam Leffler const struct ieee80211_cipher ieee80211_cipher_none = { 618a1b9b6aSSam Leffler .ic_name = "NONE", 628a1b9b6aSSam Leffler .ic_cipher = IEEE80211_CIPHER_NONE, 638a1b9b6aSSam Leffler .ic_header = 0, 648a1b9b6aSSam Leffler .ic_trailer = 0, 658a1b9b6aSSam Leffler .ic_miclen = 0, 668a1b9b6aSSam Leffler .ic_attach = none_attach, 678a1b9b6aSSam Leffler .ic_detach = none_detach, 688a1b9b6aSSam Leffler .ic_setkey = none_setkey, 69c0cb9349SAdrian Chadd .ic_setiv = none_setiv, 708a1b9b6aSSam Leffler .ic_encap = none_encap, 718a1b9b6aSSam Leffler .ic_decap = none_decap, 728a1b9b6aSSam Leffler .ic_enmic = none_enmic, 738a1b9b6aSSam Leffler .ic_demic = none_demic, 748a1b9b6aSSam Leffler }; 758a1b9b6aSSam Leffler 768a1b9b6aSSam Leffler static void * 77b032f27cSSam Leffler none_attach(struct ieee80211vap *vap, struct ieee80211_key *k) 788a1b9b6aSSam Leffler { 79b032f27cSSam Leffler return vap; /* for diagnostics+stats */ 808a1b9b6aSSam Leffler } 818a1b9b6aSSam Leffler 828a1b9b6aSSam Leffler static void 838a1b9b6aSSam Leffler none_detach(struct ieee80211_key *k) 848a1b9b6aSSam Leffler { 858a1b9b6aSSam Leffler (void) k; 868a1b9b6aSSam Leffler } 878a1b9b6aSSam Leffler 888a1b9b6aSSam Leffler static int 898a1b9b6aSSam Leffler none_setkey(struct ieee80211_key *k) 908a1b9b6aSSam Leffler { 918a1b9b6aSSam Leffler (void) k; 928a1b9b6aSSam Leffler return 1; 938a1b9b6aSSam Leffler } 948a1b9b6aSSam Leffler 95c0cb9349SAdrian Chadd static void 96c0cb9349SAdrian Chadd none_setiv(struct ieee80211_key *k, uint8_t *ivp) 97c0cb9349SAdrian Chadd { 98c0cb9349SAdrian Chadd } 99c0cb9349SAdrian Chadd 1008a1b9b6aSSam Leffler static int 101ef0d8f63SAdrian Chadd none_encap(struct ieee80211_key *k, struct mbuf *m) 1028a1b9b6aSSam Leffler { 103b032f27cSSam Leffler struct ieee80211vap *vap = k->wk_private; 1048a1b9b6aSSam Leffler #ifdef IEEE80211_DEBUG 1058a1b9b6aSSam Leffler struct ieee80211_frame *wh = mtod(m, struct ieee80211_frame *); 106ef0d8f63SAdrian Chadd uint8_t keyid; 107ef0d8f63SAdrian Chadd 108ef0d8f63SAdrian Chadd keyid = ieee80211_crypto_get_keyid(vap, k); 1098a1b9b6aSSam Leffler 1108a1b9b6aSSam Leffler /* 1118a1b9b6aSSam Leffler * The specified key is not setup; this can 1128a1b9b6aSSam Leffler * happen, at least, when changing keys. 1138a1b9b6aSSam Leffler */ 114b032f27cSSam Leffler IEEE80211_NOTE_MAC(vap, IEEE80211_MSG_CRYPTO, wh->i_addr1, 115ef0d8f63SAdrian Chadd "key id %u is not set (encap)", keyid); 1166dbbec93SAndriy Voskoboinyk #endif 117b032f27cSSam Leffler vap->iv_stats.is_tx_badcipher++; 1188a1b9b6aSSam Leffler return 0; 1198a1b9b6aSSam Leffler } 1208a1b9b6aSSam Leffler 1218a1b9b6aSSam Leffler static int 1222cc12adeSSam Leffler none_decap(struct ieee80211_key *k, struct mbuf *m, int hdrlen) 1238a1b9b6aSSam Leffler { 124b032f27cSSam Leffler struct ieee80211vap *vap = k->wk_private; 1258a1b9b6aSSam Leffler #ifdef IEEE80211_DEBUG 1268a1b9b6aSSam Leffler struct ieee80211_frame *wh = mtod(m, struct ieee80211_frame *); 12768e8e04eSSam Leffler const uint8_t *ivp = (const uint8_t *)&wh[1]; 1288a1b9b6aSSam Leffler #endif 1298a1b9b6aSSam Leffler 1308a1b9b6aSSam Leffler /* 1318a1b9b6aSSam Leffler * The specified key is not setup; this can 1328a1b9b6aSSam Leffler * happen, at least, when changing keys. 1338a1b9b6aSSam Leffler */ 1348a1b9b6aSSam Leffler /* XXX useful to know dst too */ 135b032f27cSSam Leffler IEEE80211_NOTE_MAC(vap, IEEE80211_MSG_CRYPTO, wh->i_addr2, 136b032f27cSSam Leffler "key id %u is not set (decap)", ivp[IEEE80211_WEP_IVLEN] >> 6); 137b032f27cSSam Leffler vap->iv_stats.is_rx_badkeyid++; 1388a1b9b6aSSam Leffler return 0; 1398a1b9b6aSSam Leffler } 1408a1b9b6aSSam Leffler 1418a1b9b6aSSam Leffler static int 14296d88463SSam Leffler none_enmic(struct ieee80211_key *k, struct mbuf *m, int force) 1438a1b9b6aSSam Leffler { 144b032f27cSSam Leffler struct ieee80211vap *vap = k->wk_private; 1458a1b9b6aSSam Leffler 146b032f27cSSam Leffler vap->iv_stats.is_tx_badcipher++; 1478a1b9b6aSSam Leffler return 0; 1488a1b9b6aSSam Leffler } 1498a1b9b6aSSam Leffler 1508a1b9b6aSSam Leffler static int 15196d88463SSam Leffler none_demic(struct ieee80211_key *k, struct mbuf *m, int force) 1528a1b9b6aSSam Leffler { 153b032f27cSSam Leffler struct ieee80211vap *vap = k->wk_private; 1548a1b9b6aSSam Leffler 155b032f27cSSam Leffler vap->iv_stats.is_rx_badkeyid++; 1568a1b9b6aSSam Leffler return 0; 1578a1b9b6aSSam Leffler } 158