1 /*- 2 * Copyright (c) 2002-2008 Sam Leffler, Errno Consulting 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 * 25 * $FreeBSD: head/sys/net80211/ieee80211_crypto_none.c 178354 2008-04-20 20:35:46Z sam $ 26 * $DragonFly$ 27 */ 28 29 /* 30 * IEEE 802.11 NULL crypto support. 31 */ 32 #include "opt_wlan.h" 33 34 #include <sys/param.h> 35 #include <sys/kernel.h> 36 #include <sys/systm.h> 37 #include <sys/mbuf.h> 38 #include <sys/module.h> 39 40 #include <sys/socket.h> 41 42 #include <net/if.h> 43 #include <net/if_media.h> 44 #include <net/ethernet.h> 45 #include <net/route.h> 46 47 #include <netproto/802_11/ieee80211_var.h> 48 49 static void *none_attach(struct ieee80211vap *, struct ieee80211_key *); 50 static void none_detach(struct ieee80211_key *); 51 static int none_setkey(struct ieee80211_key *); 52 static int none_encap(struct ieee80211_key *, struct mbuf *, uint8_t); 53 static int none_decap(struct ieee80211_key *, struct mbuf *, int); 54 static int none_enmic(struct ieee80211_key *, struct mbuf *, int); 55 static int none_demic(struct ieee80211_key *, struct mbuf *, int); 56 57 const 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_encap = none_encap, 67 .ic_decap = none_decap, 68 .ic_enmic = none_enmic, 69 .ic_demic = none_demic, 70 }; 71 72 static void * 73 none_attach(struct ieee80211vap *vap, struct ieee80211_key *k) 74 { 75 return vap; /* for diagnostics+stats */ 76 } 77 78 static void 79 none_detach(struct ieee80211_key *k) 80 { 81 (void) k; 82 } 83 84 static int 85 none_setkey(struct ieee80211_key *k) 86 { 87 (void) k; 88 return 1; 89 } 90 91 static int 92 none_encap(struct ieee80211_key *k, struct mbuf *m, uint8_t keyid) 93 { 94 struct ieee80211vap *vap = k->wk_private; 95 #ifdef IEEE80211_DEBUG 96 struct ieee80211_frame *wh = mtod(m, struct ieee80211_frame *); 97 #endif 98 99 /* 100 * The specified key is not setup; this can 101 * happen, at least, when changing keys. 102 */ 103 IEEE80211_NOTE_MAC(vap, IEEE80211_MSG_CRYPTO, wh->i_addr1, 104 "key id %u is not set (encap)", keyid>>6); 105 vap->iv_stats.is_tx_badcipher++; 106 return 0; 107 } 108 109 static int 110 none_decap(struct ieee80211_key *k, struct mbuf *m, int hdrlen) 111 { 112 struct ieee80211vap *vap = k->wk_private; 113 #ifdef IEEE80211_DEBUG 114 struct ieee80211_frame *wh = mtod(m, struct ieee80211_frame *); 115 const uint8_t *ivp = (const uint8_t *)&wh[1]; 116 #endif 117 118 /* 119 * The specified key is not setup; this can 120 * happen, at least, when changing keys. 121 */ 122 /* XXX useful to know dst too */ 123 IEEE80211_NOTE_MAC(vap, IEEE80211_MSG_CRYPTO, wh->i_addr2, 124 "key id %u is not set (decap)", ivp[IEEE80211_WEP_IVLEN] >> 6); 125 vap->iv_stats.is_rx_badkeyid++; 126 return 0; 127 } 128 129 static int 130 none_enmic(struct ieee80211_key *k, struct mbuf *m, int force) 131 { 132 struct ieee80211vap *vap = k->wk_private; 133 134 vap->iv_stats.is_tx_badcipher++; 135 return 0; 136 } 137 138 static int 139 none_demic(struct ieee80211_key *k, struct mbuf *m, int force) 140 { 141 struct ieee80211vap *vap = k->wk_private; 142 143 vap->iv_stats.is_rx_badkeyid++; 144 return 0; 145 } 146