1 /* 2 * Copyright (c) 2002-2005 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 * 3. The name of the author may not be used to endorse or promote products 14 * derived from this software without specific prior written permission. 15 * 16 * Alternatively, this software may be distributed under the terms of the 17 * GNU General Public License ("GPL") version 2 as published by the Free 18 * Software Foundation. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 * 31 * $FreeBSD: src/sys/net80211/ieee80211_crypto_none.c,v 1.5 2005/06/10 16:11:24 sam Exp $ 32 * $DragonFly: src/sys/netproto/802_11/wlan/ieee80211_crypto_none.c,v 1.3 2007/05/07 14:12:16 sephe Exp $ 33 */ 34 35 /* 36 * IEEE 802.11 NULL crypto support. 37 */ 38 #include <sys/param.h> 39 #include <sys/systm.h> 40 #include <sys/mbuf.h> 41 #include <sys/module.h> 42 43 #include <sys/socket.h> 44 45 #include <net/if.h> 46 #include <net/if_arp.h> 47 #include <net/if_media.h> 48 #include <net/ethernet.h> 49 50 #include <netproto/802_11/ieee80211_var.h> 51 52 static void *none_crypto_attach(struct ieee80211com *, struct ieee80211_key *); 53 static void none_crypto_detach(struct ieee80211_key *); 54 static int none_crypto_setkey(struct ieee80211_key *); 55 static int none_crypto_encap(struct ieee80211_key *, struct mbuf *, uint8_t); 56 static int none_crypto_decap(struct ieee80211_key *, struct mbuf *, int); 57 static int none_crypto_enmic(struct ieee80211_key *, struct mbuf *, int); 58 static int none_crypto_demic(struct ieee80211_key *, struct mbuf *, int); 59 static int none_crypto_getiv(struct ieee80211_key *, 60 struct ieee80211_crypto_iv *, uint8_t); 61 static int none_crypto_update(struct ieee80211_key *, 62 const struct ieee80211_crypto_iv *, 63 const struct ieee80211_frame *); 64 65 const struct ieee80211_cipher ieee80211_cipher_none = { 66 .ic_name = "NONE", 67 .ic_cipher = IEEE80211_CIPHER_NONE, 68 .ic_header = 0, 69 .ic_trailer = 0, 70 .ic_miclen = 0, 71 .ic_attach = none_crypto_attach, 72 .ic_detach = none_crypto_detach, 73 .ic_setkey = none_crypto_setkey, 74 .ic_encap = none_crypto_encap, 75 .ic_decap = none_crypto_decap, 76 .ic_enmic = none_crypto_enmic, 77 .ic_demic = none_crypto_demic, 78 .ic_getiv = none_crypto_getiv, 79 .ic_update = none_crypto_update 80 }; 81 82 static void * 83 none_crypto_attach(struct ieee80211com *ic, struct ieee80211_key *k) 84 { 85 return ic; /* for diagnostics+stats */ 86 } 87 88 static void 89 none_crypto_detach(struct ieee80211_key *k) 90 { 91 (void) k; 92 } 93 94 static int 95 none_crypto_setkey(struct ieee80211_key *k) 96 { 97 (void) k; 98 return 1; 99 } 100 101 static int 102 none_crypto_encap(struct ieee80211_key *k, struct mbuf *m, uint8_t keyid) 103 { 104 struct ieee80211com *ic = k->wk_private; 105 #ifdef IEEE80211_DEBUG 106 struct ieee80211_frame *wh = mtod(m, struct ieee80211_frame *); 107 #endif 108 109 /* 110 * The specified key is not setup; this can 111 * happen, at least, when changing keys. 112 */ 113 IEEE80211_DPRINTF(ic, IEEE80211_MSG_CRYPTO, 114 "[%6D] key id %u is not set (encap)\n", 115 wh->i_addr1, ":", keyid>>6); 116 ic->ic_stats.is_tx_badcipher++; 117 return 0; 118 } 119 120 static int 121 none_crypto_decap(struct ieee80211_key *k, struct mbuf *m, int hdrlen) 122 { 123 struct ieee80211com *ic = k->wk_private; 124 #ifdef IEEE80211_DEBUG 125 struct ieee80211_frame *wh = mtod(m, struct ieee80211_frame *); 126 const uint8_t *ivp = (const uint8_t *)&wh[1]; 127 #endif 128 129 /* 130 * The specified key is not setup; this can 131 * happen, at least, when changing keys. 132 */ 133 /* XXX useful to know dst too */ 134 IEEE80211_DPRINTF(ic, IEEE80211_MSG_CRYPTO, 135 "[%6D] key id %u is not set (decap)\n", 136 wh->i_addr2, ":", ivp[IEEE80211_WEP_IVLEN] >> 6); 137 ic->ic_stats.is_rx_badkeyid++; 138 return 0; 139 } 140 141 static int 142 none_crypto_update(struct ieee80211_key *k, 143 const struct ieee80211_crypto_iv *iv, 144 const struct ieee80211_frame *wh) 145 { 146 struct ieee80211com *ic = k->wk_private; 147 const uint8_t *ivp = (const uint8_t *)iv; 148 149 /* 150 * The specified key is not setup; this can 151 * happen, at least, when changing keys. 152 */ 153 IEEE80211_DPRINTF(ic, IEEE80211_MSG_CRYPTO, 154 "[%6D] key id %u is not set (update)\n", 155 wh->i_addr2, ":", ivp[IEEE80211_WEP_IVLEN] >> 6); 156 ic->ic_stats.is_rx_badkeyid++; 157 return 0; 158 } 159 160 static int 161 none_crypto_enmic(struct ieee80211_key *k, struct mbuf *m, int force) 162 { 163 struct ieee80211com *ic = k->wk_private; 164 165 ic->ic_stats.is_tx_badcipher++; 166 return 0; 167 } 168 169 static int 170 none_crypto_demic(struct ieee80211_key *k, struct mbuf *m, int force) 171 { 172 struct ieee80211com *ic = k->wk_private; 173 174 ic->ic_stats.is_rx_badkeyid++; 175 return 0; 176 } 177 178 static int 179 none_crypto_getiv(struct ieee80211_key *k, struct ieee80211_crypto_iv *iv, 180 uint8_t keyid) 181 { 182 struct ieee80211com *ic = k->wk_private; 183 184 /* 185 * The specified key is not setup; this can 186 * happen, at least, when changing keys. 187 */ 188 IEEE80211_DPRINTF(ic, IEEE80211_MSG_CRYPTO, 189 "key id %u is not set (getiv)\n", keyid>>6); 190 ic->ic_stats.is_tx_badcipher++; 191 return 0; 192 } 193