/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Copyright (c) 2001 Atsushi Onoe
* Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* Alternatively, this software may be distributed under the terms of the
* GNU General Public License ("GPL") version 2 as published by the Free
* Software Foundation.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* IEEE 802.11 generic crypto support
*/
#include "net80211_impl.h"
extern const struct ieee80211_cipher wep;
extern const struct ieee80211_cipher tkip;
extern const struct ieee80211_cipher ccmp;
/*
* Table of registered cipher modules.
*/
static const char *cipher_modnames[] = {
"wlan_wep", /* IEEE80211_CIPHER_WEP */
"wlan_tkip", /* IEEE80211_CIPHER_TKIP */
"wlan_aes_ocb", /* IEEE80211_CIPHER_AES_OCB */
"wlan_ccmp", /* IEEE80211_CIPHER_AES_CCM */
"wlan_ckip", /* IEEE80211_CIPHER_CKIP */
};
/*
* Default "null" key management routines.
*/
/* ARGSUSED */
static int
{
*keyix = 0; /* use key index 0 for ucast key */
return (1);
}
/* ARGSUSED */
static int
{
return (1);
}
/* ARGSUSED */
static int
{
return (1);
}
/* ARGSUSED */
static void
{
/* noop */
}
/*
* Reset key state to an unused state. The crypto
* key allocation mechanism insures other state (e.g.
* key data) is properly setup before a key is used.
*/
void
{
k->wk_cipher = &ieee80211_cipher_none;
}
/*
* Establish a relationship between the specified key and cipher
* and, if necessary, allocate a hardware index from the driver.
* Note that when a fixed key index is required it must be specified
* and we blindly assign it w/o consulting the driver.
*
* This must be the first call applied to a key; all the other key
* routines assume wk_cipher is setup.
*
* Locking must be handled by the caller using:
* ieee80211_key_update_begin(ic);
* ieee80211_key_update_end(ic);
*/
int
struct ieee80211_key *key)
{
void *keyctx;
/*
* Validate cipher and set reference to cipher routines.
*/
if (cipher >= IEEE80211_CIPHER_MAX) {
"invalid cipher %u\n", cipher);
return (0);
}
/* already load all the ciphers, cip can't be NULL */
"unable to load cipher %u, module %s\n",
return (0);
}
/*
* If the hardware does not support the cipher then
* fallback to a host-based implementation.
*/
"no h/w support for cipher %s, falling back to s/w\n",
}
/*
* Hardware TKIP with software MIC is an important
* combination; we handle it by flagging each key,
* the cipher modules honor it.
*/
if (cipher == IEEE80211_CIPHER_TKIP &&
"no h/w support for TKIP MIC, falling back to s/w\n");
}
/*
* Bind cipher to key instance. Note we do this
* after checking the device capabilities so the
* cipher module can optimize space usage based on
* whether or not it needs to do the cipher work.
*/
/*
* Fillin the flags so cipher modules can see s/w
* crypto requirements and potentially allocate
* pointers.
*/
return (0);
}
}
/*
* Commit to requested usage so driver can see the flags.
*/
/*
* Ask the driver for a key index if we don't have one.
* Note that entries in the global key table always have
* an index; this means it's safe to call this routine
* for these entries just to setup the reference to the
* cipher template. Note also that when using software
* crypto we also call the driver to give us a key index.
*/
/*
* Driver has no room; fallback to doing crypto
* in the host. We change the flags and start the
* procedure over. If we get back here then there's
* no hope and we bail. Note that this can leave
* the key in a inconsistent state if the caller
* continues to use it.
*/
"crypto_setkey: "
"no h/w resources for cipher %s, "
if (cipher == IEEE80211_CIPHER_TKIP)
goto again;
}
return (0);
}
}
return (1);
}
/*
* Remove the key (no locking, for internal use).
*/
static int
{
if (keyix != IEEE80211_KEYIX_NONE) {
/*
* Remove hardware entry.
*/
"ieee80211_crypto_delkey_locked: ",
"driverdeletes key %u failed\n", keyix);
}
}
/* NB: cannot depend on key index to decide this */
return (1);
}
/*
* Remove the specified key.
*/
int
{
int status;
return (status);
}
/*
* Clear the global key table.
*/
static void
{
int i;
for (i = 0; i < IEEE80211_WEP_NKID; i++)
}
/*
* Set the contents of the specified key.
*
* Locking must be handled by the caller using:
* ieee80211_key_update_begin(ic);
* ieee80211_key_update_end(ic);
*/
int
{
"%s keyix %u flags 0x%x mac %s len %u\n",
/*
* Give cipher a chance to validate key contents.
* should happen before modifying state.
*/
"cipher %s rejected key index %u len %u flags 0x%x\n",
return (0);
}
"no key index; should not happen!\n");
return (0);
}
}
/*
* Return the transmit key to use in sending a frame.
*/
struct ieee80211_key *
{
return (NULL);
}
{
WIFI_SEC_WEP, /* IEEE80211_CIPHER_WEP */
WIFI_SEC_WPA, /* IEEE80211_CIPHER_TKIP */
WIFI_SEC_WPA, /* IEEE80211_CIPHER_AES_CCM */
WIFI_SEC_NONE, /* IEEE80211_CIPHER_NONE */
};
return (WIFI_SEC_NONE);
return (WIFI_SEC_NONE);
}
/*
* Add privacy headers appropriate for the specified key.
*/
struct ieee80211_key *
{
struct ieee80211_key *k;
"ieee80211_crypto_encap: %s",
" No default xmit key for frame\n");
return (NULL);
}
}
/*
* Validate and strip privacy headers (and trailer) for a
*/
struct ieee80211_key *
{
struct ieee80211_key *k;
/* NB: this minimum size data frame could be bigger */
" WEP data frame too short, len %u\n",
return (NULL);
}
/*
* Locate the key. If unicast and there is no unicast
* key then we fall back to the key id in the header.
* This assumes unicast keys are only configured when
* the key id in the header is meaningless (typically 0).
*/
/* check to avoid panic when wep is on but key is not set */
if (k->wk_cipher == &ieee80211_cipher_none ||
return (NULL);
}
/*
* Setup crypto support.
*/
void
{
int i;
/* NB: we assume everything is pre-zero'd */
for (i = 0; i < IEEE80211_WEP_NKID; i++) {
}
/*
* Initialize the driver key support routines to noop entries.
* This is useful especially for the cipher test modules.
*/
}
/*
* Teardown crypto support.
*/
void
{
}
/*
* Register a crypto cipher module.
*/
void
const struct ieee80211_cipher *cip)
{
ieee80211_err("ieee80211_crypto_register: "
"cipher %s has an invalid cipher index %u\n",
return;
}
ieee80211_err("ieee80211_crypto_register: "
"cipher %s registered with a different template\n",
return;
}
}
/*
* Unregister a crypto cipher module.
*/
void
const struct ieee80211_cipher *cip)
{
ieee80211_err("ieee80211_crypto_unregister: "
"cipher %s has an invalid cipher index %u\n",
return;
}
ieee80211_err("ieee80211_crypto_unregister: "
"cipher %s registered with a different template\n",
return;
}
/* NB: don't complain about not being registered */
}