17e272fcfSJohn W. Linville /* 27e272fcfSJohn W. Linville * lib80211.h -- common bits for IEEE802.11 wireless drivers 37e272fcfSJohn W. Linville * 47e272fcfSJohn W. Linville * Copyright (c) 2008, John W. Linville <linville@tuxdriver.com> 57e272fcfSJohn W. Linville * 6274bfb8dSJohn W. Linville * Some bits copied from old ieee80211 component, w/ original copyright 7274bfb8dSJohn W. Linville * notices below: 8274bfb8dSJohn W. Linville * 9274bfb8dSJohn W. Linville * Original code based on Host AP (software wireless LAN access point) driver 10274bfb8dSJohn W. Linville * for Intersil Prism2/2.5/3. 11274bfb8dSJohn W. Linville * 12274bfb8dSJohn W. Linville * Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen 13274bfb8dSJohn W. Linville * <j@w1.fi> 14274bfb8dSJohn W. Linville * Copyright (c) 2002-2003, Jouni Malinen <j@w1.fi> 15274bfb8dSJohn W. Linville * 16274bfb8dSJohn W. Linville * Adaption to a generic IEEE 802.11 stack by James Ketrenos 17274bfb8dSJohn W. Linville * <jketreno@linux.intel.com> 18274bfb8dSJohn W. Linville * 19274bfb8dSJohn W. Linville * Copyright (c) 2004, Intel Corporation 20274bfb8dSJohn W. Linville * 217e272fcfSJohn W. Linville */ 227e272fcfSJohn W. Linville 237e272fcfSJohn W. Linville #ifndef LIB80211_H 247e272fcfSJohn W. Linville #define LIB80211_H 257e272fcfSJohn W. Linville 26274bfb8dSJohn W. Linville #include <linux/types.h> 27274bfb8dSJohn W. Linville #include <linux/list.h> 28274bfb8dSJohn W. Linville #include <linux/module.h> 29*60063497SArun Sharma #include <linux/atomic.h> 30274bfb8dSJohn W. Linville #include <linux/if.h> 31274bfb8dSJohn W. Linville #include <linux/skbuff.h> 3272118015SJohn W. Linville #include <linux/ieee80211.h> 33a1eb5fe3SRami Rosen #include <linux/timer.h> 349387b7caSJohn W. Linville /* print_ssid() is intended to be used in debug (and possibly error) 357e272fcfSJohn W. Linville * messages. It should never be used for passing ssid to user space. */ 369387b7caSJohn W. Linville const char *print_ssid(char *buf, const char *ssid, u8 ssid_len); 3772118015SJohn W. Linville #define DECLARE_SSID_BUF(var) char var[IEEE80211_MAX_SSID_LEN * 4 + 1] __maybe_unused 387e272fcfSJohn W. Linville 39274bfb8dSJohn W. Linville #define NUM_WEP_KEYS 4 40274bfb8dSJohn W. Linville 41274bfb8dSJohn W. Linville enum { 42274bfb8dSJohn W. Linville IEEE80211_CRYPTO_TKIP_COUNTERMEASURES = (1 << 0), 43274bfb8dSJohn W. Linville }; 44274bfb8dSJohn W. Linville 45274bfb8dSJohn W. Linville struct lib80211_crypto_ops { 46274bfb8dSJohn W. Linville const char *name; 47274bfb8dSJohn W. Linville struct list_head list; 48274bfb8dSJohn W. Linville 49274bfb8dSJohn W. Linville /* init new crypto context (e.g., allocate private data space, 50274bfb8dSJohn W. Linville * select IV, etc.); returns NULL on failure or pointer to allocated 51274bfb8dSJohn W. Linville * private data on success */ 52274bfb8dSJohn W. Linville void *(*init) (int keyidx); 53274bfb8dSJohn W. Linville 54274bfb8dSJohn W. Linville /* deinitialize crypto context and free allocated private data */ 55274bfb8dSJohn W. Linville void (*deinit) (void *priv); 56274bfb8dSJohn W. Linville 57274bfb8dSJohn W. Linville /* encrypt/decrypt return < 0 on error or >= 0 on success. The return 58274bfb8dSJohn W. Linville * value from decrypt_mpdu is passed as the keyidx value for 59274bfb8dSJohn W. Linville * decrypt_msdu. skb must have enough head and tail room for the 60274bfb8dSJohn W. Linville * encryption; if not, error will be returned; these functions are 61274bfb8dSJohn W. Linville * called for all MPDUs (i.e., fragments). 62274bfb8dSJohn W. Linville */ 63274bfb8dSJohn W. Linville int (*encrypt_mpdu) (struct sk_buff * skb, int hdr_len, void *priv); 64274bfb8dSJohn W. Linville int (*decrypt_mpdu) (struct sk_buff * skb, int hdr_len, void *priv); 65274bfb8dSJohn W. Linville 66274bfb8dSJohn W. Linville /* These functions are called for full MSDUs, i.e. full frames. 67274bfb8dSJohn W. Linville * These can be NULL if full MSDU operations are not needed. */ 68274bfb8dSJohn W. Linville int (*encrypt_msdu) (struct sk_buff * skb, int hdr_len, void *priv); 69274bfb8dSJohn W. Linville int (*decrypt_msdu) (struct sk_buff * skb, int keyidx, int hdr_len, 70274bfb8dSJohn W. Linville void *priv); 71274bfb8dSJohn W. Linville 72274bfb8dSJohn W. Linville int (*set_key) (void *key, int len, u8 * seq, void *priv); 73274bfb8dSJohn W. Linville int (*get_key) (void *key, int len, u8 * seq, void *priv); 74274bfb8dSJohn W. Linville 75274bfb8dSJohn W. Linville /* procfs handler for printing out key information and possible 76274bfb8dSJohn W. Linville * statistics */ 77274bfb8dSJohn W. Linville char *(*print_stats) (char *p, void *priv); 78274bfb8dSJohn W. Linville 79274bfb8dSJohn W. Linville /* Crypto specific flag get/set for configuration settings */ 80274bfb8dSJohn W. Linville unsigned long (*get_flags) (void *priv); 81274bfb8dSJohn W. Linville unsigned long (*set_flags) (unsigned long flags, void *priv); 82274bfb8dSJohn W. Linville 83274bfb8dSJohn W. Linville /* maximum number of bytes added by encryption; encrypt buf is 84274bfb8dSJohn W. Linville * allocated with extra_prefix_len bytes, copy of in_buf, and 85274bfb8dSJohn W. Linville * extra_postfix_len; encrypt need not use all this space, but 86274bfb8dSJohn W. Linville * the result must start at the beginning of the buffer and correct 87274bfb8dSJohn W. Linville * length must be returned */ 88274bfb8dSJohn W. Linville int extra_mpdu_prefix_len, extra_mpdu_postfix_len; 89274bfb8dSJohn W. Linville int extra_msdu_prefix_len, extra_msdu_postfix_len; 90274bfb8dSJohn W. Linville 91274bfb8dSJohn W. Linville struct module *owner; 92274bfb8dSJohn W. Linville }; 93274bfb8dSJohn W. Linville 94274bfb8dSJohn W. Linville struct lib80211_crypt_data { 95274bfb8dSJohn W. Linville struct list_head list; /* delayed deletion list */ 96274bfb8dSJohn W. Linville struct lib80211_crypto_ops *ops; 97274bfb8dSJohn W. Linville void *priv; 98274bfb8dSJohn W. Linville atomic_t refcnt; 99274bfb8dSJohn W. Linville }; 100274bfb8dSJohn W. Linville 101274bfb8dSJohn W. Linville struct lib80211_crypt_info { 102274bfb8dSJohn W. Linville char *name; 103274bfb8dSJohn W. Linville /* Most clients will already have a lock, 104274bfb8dSJohn W. Linville so just point to that. */ 105274bfb8dSJohn W. Linville spinlock_t *lock; 106274bfb8dSJohn W. Linville 107274bfb8dSJohn W. Linville struct lib80211_crypt_data *crypt[NUM_WEP_KEYS]; 108274bfb8dSJohn W. Linville int tx_keyidx; /* default TX key index (crypt[tx_keyidx]) */ 109274bfb8dSJohn W. Linville struct list_head crypt_deinit_list; 110274bfb8dSJohn W. Linville struct timer_list crypt_deinit_timer; 111274bfb8dSJohn W. Linville int crypt_quiesced; 112274bfb8dSJohn W. Linville }; 113274bfb8dSJohn W. Linville 1142ba4b32eSJohn W. Linville int lib80211_crypt_info_init(struct lib80211_crypt_info *info, char *name, 1152ba4b32eSJohn W. Linville spinlock_t *lock); 1162ba4b32eSJohn W. Linville void lib80211_crypt_info_free(struct lib80211_crypt_info *info); 117274bfb8dSJohn W. Linville int lib80211_register_crypto_ops(struct lib80211_crypto_ops *ops); 118274bfb8dSJohn W. Linville int lib80211_unregister_crypto_ops(struct lib80211_crypto_ops *ops); 119274bfb8dSJohn W. Linville struct lib80211_crypto_ops *lib80211_get_crypto_ops(const char *name); 120274bfb8dSJohn W. Linville void lib80211_crypt_deinit_entries(struct lib80211_crypt_info *, int); 121274bfb8dSJohn W. Linville void lib80211_crypt_deinit_handler(unsigned long); 122274bfb8dSJohn W. Linville void lib80211_crypt_delayed_deinit(struct lib80211_crypt_info *info, 123274bfb8dSJohn W. Linville struct lib80211_crypt_data **crypt); 124274bfb8dSJohn W. Linville void lib80211_crypt_quiescing(struct lib80211_crypt_info *info); 125274bfb8dSJohn W. Linville 1267e272fcfSJohn W. Linville #endif /* LIB80211_H */ 127