Path: blob/main/sys/net80211/ieee80211_crypto_none.c
39475 views
/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2002-2008 Sam Leffler, Errno Consulting4* All rights reserved.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11* 2. Redistributions in binary form must reproduce the above copyright12* notice, this list of conditions and the following disclaimer in the13* documentation and/or other materials provided with the distribution.14*15* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR16* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES17* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.18* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,19* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT20* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,21* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY22* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT23* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF24* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.25*/2627#include <sys/cdefs.h>28/*29* IEEE 802.11 NULL crypto support.30*/31#include "opt_wlan.h"3233#include <sys/param.h>34#include <sys/kernel.h>35#include <sys/malloc.h>36#include <sys/systm.h>37#include <sys/mbuf.h>38#include <sys/module.h>3940#include <sys/socket.h>4142#include <net/if.h>43#include <net/if_media.h>44#include <net/ethernet.h>4546#include <net80211/ieee80211_var.h>4748static void *none_attach(struct ieee80211vap *, struct ieee80211_key *);49static void none_detach(struct ieee80211_key *);50static int none_setkey(struct ieee80211_key *);51static void none_setiv(struct ieee80211_key *, uint8_t *);52static int none_encap(struct ieee80211_key *, struct mbuf *);53static int none_decap(struct ieee80211_key *, struct mbuf *, int);54static int none_enmic(struct ieee80211_key *, struct mbuf *, int);55static int none_demic(struct ieee80211_key *, struct mbuf *, int);5657const struct ieee80211_cipher ieee80211_cipher_none = {58.ic_name = "NONE",59.ic_cipher = IEEE80211_CIPHER_NONE,60.ic_header = 0,61.ic_trailer = 0,62.ic_miclen = 0,63.ic_attach = none_attach,64.ic_detach = none_detach,65.ic_setkey = none_setkey,66.ic_setiv = none_setiv,67.ic_encap = none_encap,68.ic_decap = none_decap,69.ic_enmic = none_enmic,70.ic_demic = none_demic,71};7273static void *74none_attach(struct ieee80211vap *vap, struct ieee80211_key *k)75{76return vap; /* for diagnostics+stats */77}7879static void80none_detach(struct ieee80211_key *k)81{82(void) k;83}8485static int86none_setkey(struct ieee80211_key *k)87{88(void) k;89return 1;90}9192static void93none_setiv(struct ieee80211_key *k, uint8_t *ivp)94{95}9697static int98none_encap(struct ieee80211_key *k, struct mbuf *m)99{100struct ieee80211vap *vap = k->wk_private;101#ifdef IEEE80211_DEBUG102struct ieee80211_frame *wh = mtod(m, struct ieee80211_frame *);103uint8_t keyid;104105keyid = ieee80211_crypto_get_keyid(vap, k);106107/*108* The specified key is not setup; this can109* happen, at least, when changing keys.110*/111IEEE80211_NOTE_MAC(vap, IEEE80211_MSG_CRYPTO, wh->i_addr1,112"key id %u is not set (encap)", keyid);113#endif114vap->iv_stats.is_tx_badcipher++;115return 0;116}117118static int119none_decap(struct ieee80211_key *k, struct mbuf *m, int hdrlen)120{121struct ieee80211vap *vap = k->wk_private;122#ifdef IEEE80211_DEBUG123struct ieee80211_frame *wh = mtod(m, struct ieee80211_frame *);124const uint8_t *ivp = (const uint8_t *)&wh[1];125#endif126127/*128* The specified key is not setup; this can129* happen, at least, when changing keys.130*/131/* XXX useful to know dst too */132IEEE80211_NOTE_MAC(vap, IEEE80211_MSG_CRYPTO, wh->i_addr2,133"key id %u is not set (decap)", ivp[IEEE80211_WEP_IVLEN] >> 6);134vap->iv_stats.is_rx_badkeyid++;135return 0;136}137138static int139none_enmic(struct ieee80211_key *k, struct mbuf *m, int force)140{141struct ieee80211vap *vap = k->wk_private;142143vap->iv_stats.is_tx_badcipher++;144return 0;145}146147static int148none_demic(struct ieee80211_key *k, struct mbuf *m, int force)149{150struct ieee80211vap *vap = k->wk_private;151152vap->iv_stats.is_rx_badkeyid++;153return 0;154}155156157