Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * Copyright 2002-2004, Instant802 Networks, Inc.
0004  * Copyright 2005, Devicescape Software, Inc.
0005  * Copyright (C) 2019, 2022 Intel Corporation
0006  */
0007 
0008 #ifndef IEEE80211_KEY_H
0009 #define IEEE80211_KEY_H
0010 
0011 #include <linux/types.h>
0012 #include <linux/list.h>
0013 #include <linux/crypto.h>
0014 #include <linux/rcupdate.h>
0015 #include <crypto/arc4.h>
0016 #include <net/mac80211.h>
0017 
0018 #define NUM_DEFAULT_KEYS 4
0019 #define NUM_DEFAULT_MGMT_KEYS 2
0020 #define NUM_DEFAULT_BEACON_KEYS 2
0021 #define INVALID_PTK_KEYIDX 2 /* Keyidx always pointing to a NULL key for PTK */
0022 
0023 struct ieee80211_local;
0024 struct ieee80211_sub_if_data;
0025 struct sta_info;
0026 
0027 /**
0028  * enum ieee80211_internal_key_flags - internal key flags
0029  *
0030  * @KEY_FLAG_UPLOADED_TO_HARDWARE: Indicates that this key is present
0031  *  in the hardware for TX crypto hardware acceleration.
0032  * @KEY_FLAG_TAINTED: Key is tainted and packets should be dropped.
0033  */
0034 enum ieee80211_internal_key_flags {
0035     KEY_FLAG_UPLOADED_TO_HARDWARE   = BIT(0),
0036     KEY_FLAG_TAINTED        = BIT(1),
0037 };
0038 
0039 enum ieee80211_internal_tkip_state {
0040     TKIP_STATE_NOT_INIT,
0041     TKIP_STATE_PHASE1_DONE,
0042     TKIP_STATE_PHASE1_HW_UPLOADED,
0043 };
0044 
0045 struct tkip_ctx {
0046     u16 p1k[5]; /* p1k cache */
0047     u32 p1k_iv32;   /* iv32 for which p1k computed */
0048     enum ieee80211_internal_tkip_state state;
0049 };
0050 
0051 struct tkip_ctx_rx {
0052     struct tkip_ctx ctx;
0053     u32 iv32;   /* current iv32 */
0054     u16 iv16;   /* current iv16 */
0055 };
0056 
0057 struct ieee80211_key {
0058     struct ieee80211_local *local;
0059     struct ieee80211_sub_if_data *sdata;
0060     struct sta_info *sta;
0061 
0062     /* for sdata list */
0063     struct list_head list;
0064 
0065     /* protected by key mutex */
0066     unsigned int flags;
0067 
0068     union {
0069         struct {
0070             /* protects tx context */
0071             spinlock_t txlock;
0072 
0073             /* last used TSC */
0074             struct tkip_ctx tx;
0075 
0076             /* last received RSC */
0077             struct tkip_ctx_rx rx[IEEE80211_NUM_TIDS];
0078 
0079             /* number of mic failures */
0080             u32 mic_failures;
0081         } tkip;
0082         struct {
0083             /*
0084              * Last received packet number. The first
0085              * IEEE80211_NUM_TIDS counters are used with Data
0086              * frames and the last counter is used with Robust
0087              * Management frames.
0088              */
0089             u8 rx_pn[IEEE80211_NUM_TIDS + 1][IEEE80211_CCMP_PN_LEN];
0090             struct crypto_aead *tfm;
0091             u32 replays; /* dot11RSNAStatsCCMPReplays */
0092         } ccmp;
0093         struct {
0094             u8 rx_pn[IEEE80211_CMAC_PN_LEN];
0095             struct crypto_shash *tfm;
0096             u32 replays; /* dot11RSNAStatsCMACReplays */
0097             u32 icverrors; /* dot11RSNAStatsCMACICVErrors */
0098         } aes_cmac;
0099         struct {
0100             u8 rx_pn[IEEE80211_GMAC_PN_LEN];
0101             struct crypto_aead *tfm;
0102             u32 replays; /* dot11RSNAStatsCMACReplays */
0103             u32 icverrors; /* dot11RSNAStatsCMACICVErrors */
0104         } aes_gmac;
0105         struct {
0106             /* Last received packet number. The first
0107              * IEEE80211_NUM_TIDS counters are used with Data
0108              * frames and the last counter is used with Robust
0109              * Management frames.
0110              */
0111             u8 rx_pn[IEEE80211_NUM_TIDS + 1][IEEE80211_GCMP_PN_LEN];
0112             struct crypto_aead *tfm;
0113             u32 replays; /* dot11RSNAStatsGCMPReplays */
0114         } gcmp;
0115         struct {
0116             /* generic cipher scheme */
0117             u8 rx_pn[IEEE80211_NUM_TIDS + 1][IEEE80211_MAX_PN_LEN];
0118         } gen;
0119     } u;
0120 
0121 #ifdef CONFIG_MAC80211_DEBUGFS
0122     struct {
0123         struct dentry *stalink;
0124         struct dentry *dir;
0125         int cnt;
0126     } debugfs;
0127 #endif
0128 
0129     unsigned int color;
0130 
0131     /*
0132      * key config, must be last because it contains key
0133      * material as variable length member
0134      */
0135     struct ieee80211_key_conf conf;
0136 };
0137 
0138 struct ieee80211_key *
0139 ieee80211_key_alloc(u32 cipher, int idx, size_t key_len,
0140             const u8 *key_data,
0141             size_t seq_len, const u8 *seq);
0142 /*
0143  * Insert a key into data structures (sdata, sta if necessary)
0144  * to make it used, free old key. On failure, also free the new key.
0145  */
0146 int ieee80211_key_link(struct ieee80211_key *key,
0147                struct ieee80211_sub_if_data *sdata,
0148                struct sta_info *sta);
0149 int ieee80211_set_tx_key(struct ieee80211_key *key);
0150 void ieee80211_key_free(struct ieee80211_key *key, bool delay_tailroom);
0151 void ieee80211_key_free_unused(struct ieee80211_key *key);
0152 void ieee80211_set_default_key(struct ieee80211_sub_if_data *sdata, int idx,
0153                    bool uni, bool multi);
0154 void ieee80211_set_default_mgmt_key(struct ieee80211_sub_if_data *sdata,
0155                     int idx);
0156 void ieee80211_set_default_beacon_key(struct ieee80211_sub_if_data *sdata,
0157                       int idx);
0158 void ieee80211_free_keys(struct ieee80211_sub_if_data *sdata,
0159              bool force_synchronize);
0160 void ieee80211_free_sta_keys(struct ieee80211_local *local,
0161                  struct sta_info *sta);
0162 void ieee80211_reenable_keys(struct ieee80211_sub_if_data *sdata);
0163 
0164 #define key_mtx_dereference(local, ref) \
0165     rcu_dereference_protected(ref, lockdep_is_held(&((local)->key_mtx)))
0166 #define rcu_dereference_check_key_mtx(local, ref) \
0167     rcu_dereference_check(ref, lockdep_is_held(&((local)->key_mtx)))
0168 
0169 void ieee80211_delayed_tailroom_dec(struct work_struct *wk);
0170 
0171 #endif /* IEEE80211_KEY_H */