blob: b95bbb083ee8f24d1309fb19d8121d083656da59 [file] [log] [blame]
John W. Linville7e272fc2008-09-24 18:13:14 -04001/*
2 * lib80211.h -- common bits for IEEE802.11 wireless drivers
3 *
4 * Copyright (c) 2008, John W. Linville <linville@tuxdriver.com>
5 *
John W. Linville274bfb82008-10-29 11:35:05 -04006 * Some bits copied from old ieee80211 component, w/ original copyright
7 * notices below:
8 *
9 * Original code based on Host AP (software wireless LAN access point) driver
10 * for Intersil Prism2/2.5/3.
11 *
12 * Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen
13 * <j@w1.fi>
14 * Copyright (c) 2002-2003, Jouni Malinen <j@w1.fi>
15 *
16 * Adaption to a generic IEEE 802.11 stack by James Ketrenos
17 * <jketreno@linux.intel.com>
18 *
19 * Copyright (c) 2004, Intel Corporation
20 *
John W. Linville7e272fc2008-09-24 18:13:14 -040021 */
22
23#ifndef LIB80211_H
24#define LIB80211_H
25
John W. Linville274bfb82008-10-29 11:35:05 -040026#include <linux/types.h>
27#include <linux/list.h>
28#include <linux/module.h>
Arun Sharma600634972011-07-26 16:09:06 -070029#include <linux/atomic.h>
John W. Linville274bfb82008-10-29 11:35:05 -040030#include <linux/if.h>
31#include <linux/skbuff.h>
John W. Linville72118012008-09-30 21:43:03 -040032#include <linux/ieee80211.h>
Rami Rosena1eb5fe2008-11-19 09:37:43 +020033#include <linux/timer.h>
John W. Linville9387b7c2008-09-30 20:59:05 -040034/* print_ssid() is intended to be used in debug (and possibly error)
John W. Linville7e272fc2008-09-24 18:13:14 -040035 * messages. It should never be used for passing ssid to user space. */
John W. Linville9387b7c2008-09-30 20:59:05 -040036const char *print_ssid(char *buf, const char *ssid, u8 ssid_len);
John W. Linville72118012008-09-30 21:43:03 -040037#define DECLARE_SSID_BUF(var) char var[IEEE80211_MAX_SSID_LEN * 4 + 1] __maybe_unused
John W. Linville7e272fc2008-09-24 18:13:14 -040038
John W. Linville274bfb82008-10-29 11:35:05 -040039#define NUM_WEP_KEYS 4
40
41enum {
42 IEEE80211_CRYPTO_TKIP_COUNTERMEASURES = (1 << 0),
43};
44
45struct lib80211_crypto_ops {
46 const char *name;
47 struct list_head list;
48
49 /* init new crypto context (e.g., allocate private data space,
50 * select IV, etc.); returns NULL on failure or pointer to allocated
51 * private data on success */
52 void *(*init) (int keyidx);
53
54 /* deinitialize crypto context and free allocated private data */
55 void (*deinit) (void *priv);
56
John W. Linville274bfb82008-10-29 11:35:05 -040057 /* encrypt/decrypt return < 0 on error or >= 0 on success. The return
58 * value from decrypt_mpdu is passed as the keyidx value for
59 * decrypt_msdu. skb must have enough head and tail room for the
60 * encryption; if not, error will be returned; these functions are
61 * called for all MPDUs (i.e., fragments).
62 */
63 int (*encrypt_mpdu) (struct sk_buff * skb, int hdr_len, void *priv);
64 int (*decrypt_mpdu) (struct sk_buff * skb, int hdr_len, void *priv);
65
66 /* These functions are called for full MSDUs, i.e. full frames.
67 * These can be NULL if full MSDU operations are not needed. */
68 int (*encrypt_msdu) (struct sk_buff * skb, int hdr_len, void *priv);
69 int (*decrypt_msdu) (struct sk_buff * skb, int keyidx, int hdr_len,
70 void *priv);
71
72 int (*set_key) (void *key, int len, u8 * seq, void *priv);
73 int (*get_key) (void *key, int len, u8 * seq, void *priv);
74
75 /* procfs handler for printing out key information and possible
76 * statistics */
77 char *(*print_stats) (char *p, void *priv);
78
79 /* Crypto specific flag get/set for configuration settings */
80 unsigned long (*get_flags) (void *priv);
81 unsigned long (*set_flags) (unsigned long flags, void *priv);
82
83 /* maximum number of bytes added by encryption; encrypt buf is
84 * allocated with extra_prefix_len bytes, copy of in_buf, and
85 * extra_postfix_len; encrypt need not use all this space, but
86 * the result must start at the beginning of the buffer and correct
87 * length must be returned */
88 int extra_mpdu_prefix_len, extra_mpdu_postfix_len;
89 int extra_msdu_prefix_len, extra_msdu_postfix_len;
90
91 struct module *owner;
92};
93
94struct lib80211_crypt_data {
95 struct list_head list; /* delayed deletion list */
96 struct lib80211_crypto_ops *ops;
97 void *priv;
98 atomic_t refcnt;
99};
100
101struct lib80211_crypt_info {
102 char *name;
103 /* Most clients will already have a lock,
104 so just point to that. */
105 spinlock_t *lock;
106
107 struct lib80211_crypt_data *crypt[NUM_WEP_KEYS];
108 int tx_keyidx; /* default TX key index (crypt[tx_keyidx]) */
109 struct list_head crypt_deinit_list;
110 struct timer_list crypt_deinit_timer;
111 int crypt_quiesced;
112};
113
John W. Linville2ba4b322008-11-11 16:00:06 -0500114int lib80211_crypt_info_init(struct lib80211_crypt_info *info, char *name,
115 spinlock_t *lock);
116void lib80211_crypt_info_free(struct lib80211_crypt_info *info);
John W. Linville274bfb82008-10-29 11:35:05 -0400117int lib80211_register_crypto_ops(struct lib80211_crypto_ops *ops);
118int lib80211_unregister_crypto_ops(struct lib80211_crypto_ops *ops);
119struct lib80211_crypto_ops *lib80211_get_crypto_ops(const char *name);
120void lib80211_crypt_deinit_entries(struct lib80211_crypt_info *, int);
121void lib80211_crypt_deinit_handler(unsigned long);
122void lib80211_crypt_delayed_deinit(struct lib80211_crypt_info *info,
123 struct lib80211_crypt_data **crypt);
124void lib80211_crypt_quiescing(struct lib80211_crypt_info *info);
125
John W. Linville7e272fc2008-09-24 18:13:14 -0400126#endif /* LIB80211_H */