18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * lib80211.h -- common bits for IEEE802.11 wireless drivers
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (c) 2008, John W. Linville <linville@tuxdriver.com>
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * Some bits copied from old ieee80211 component, w/ original copyright
88c2ecf20Sopenharmony_ci * notices below:
98c2ecf20Sopenharmony_ci *
108c2ecf20Sopenharmony_ci * Original code based on Host AP (software wireless LAN access point) driver
118c2ecf20Sopenharmony_ci * for Intersil Prism2/2.5/3.
128c2ecf20Sopenharmony_ci *
138c2ecf20Sopenharmony_ci * Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen
148c2ecf20Sopenharmony_ci * <j@w1.fi>
158c2ecf20Sopenharmony_ci * Copyright (c) 2002-2003, Jouni Malinen <j@w1.fi>
168c2ecf20Sopenharmony_ci *
178c2ecf20Sopenharmony_ci * Adaption to a generic IEEE 802.11 stack by James Ketrenos
188c2ecf20Sopenharmony_ci * <jketreno@linux.intel.com>
198c2ecf20Sopenharmony_ci *
208c2ecf20Sopenharmony_ci * Copyright (c) 2004, Intel Corporation
218c2ecf20Sopenharmony_ci *
228c2ecf20Sopenharmony_ci */
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci#ifndef LIB80211_H
258c2ecf20Sopenharmony_ci#define LIB80211_H
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci#include <linux/types.h>
288c2ecf20Sopenharmony_ci#include <linux/list.h>
298c2ecf20Sopenharmony_ci#include <linux/atomic.h>
308c2ecf20Sopenharmony_ci#include <linux/if.h>
318c2ecf20Sopenharmony_ci#include <linux/skbuff.h>
328c2ecf20Sopenharmony_ci#include <linux/ieee80211.h>
338c2ecf20Sopenharmony_ci#include <linux/timer.h>
348c2ecf20Sopenharmony_ci#include <linux/seq_file.h>
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci#define NUM_WEP_KEYS	4
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_cienum {
398c2ecf20Sopenharmony_ci	IEEE80211_CRYPTO_TKIP_COUNTERMEASURES = (1 << 0),
408c2ecf20Sopenharmony_ci};
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_cistruct module;
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_cistruct lib80211_crypto_ops {
458c2ecf20Sopenharmony_ci	const char *name;
468c2ecf20Sopenharmony_ci	struct list_head list;
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci	/* init new crypto context (e.g., allocate private data space,
498c2ecf20Sopenharmony_ci	 * select IV, etc.); returns NULL on failure or pointer to allocated
508c2ecf20Sopenharmony_ci	 * private data on success */
518c2ecf20Sopenharmony_ci	void *(*init) (int keyidx);
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_ci	/* deinitialize crypto context and free allocated private data */
548c2ecf20Sopenharmony_ci	void (*deinit) (void *priv);
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ci	/* encrypt/decrypt return < 0 on error or >= 0 on success. The return
578c2ecf20Sopenharmony_ci	 * value from decrypt_mpdu is passed as the keyidx value for
588c2ecf20Sopenharmony_ci	 * decrypt_msdu. skb must have enough head and tail room for the
598c2ecf20Sopenharmony_ci	 * encryption; if not, error will be returned; these functions are
608c2ecf20Sopenharmony_ci	 * called for all MPDUs (i.e., fragments).
618c2ecf20Sopenharmony_ci	 */
628c2ecf20Sopenharmony_ci	int (*encrypt_mpdu) (struct sk_buff * skb, int hdr_len, void *priv);
638c2ecf20Sopenharmony_ci	int (*decrypt_mpdu) (struct sk_buff * skb, int hdr_len, void *priv);
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ci	/* These functions are called for full MSDUs, i.e. full frames.
668c2ecf20Sopenharmony_ci	 * These can be NULL if full MSDU operations are not needed. */
678c2ecf20Sopenharmony_ci	int (*encrypt_msdu) (struct sk_buff * skb, int hdr_len, void *priv);
688c2ecf20Sopenharmony_ci	int (*decrypt_msdu) (struct sk_buff * skb, int keyidx, int hdr_len,
698c2ecf20Sopenharmony_ci			     void *priv);
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_ci	int (*set_key) (void *key, int len, u8 * seq, void *priv);
728c2ecf20Sopenharmony_ci	int (*get_key) (void *key, int len, u8 * seq, void *priv);
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci	/* procfs handler for printing out key information and possible
758c2ecf20Sopenharmony_ci	 * statistics */
768c2ecf20Sopenharmony_ci	void (*print_stats) (struct seq_file *m, void *priv);
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_ci	/* Crypto specific flag get/set for configuration settings */
798c2ecf20Sopenharmony_ci	unsigned long (*get_flags) (void *priv);
808c2ecf20Sopenharmony_ci	unsigned long (*set_flags) (unsigned long flags, void *priv);
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_ci	/* maximum number of bytes added by encryption; encrypt buf is
838c2ecf20Sopenharmony_ci	 * allocated with extra_prefix_len bytes, copy of in_buf, and
848c2ecf20Sopenharmony_ci	 * extra_postfix_len; encrypt need not use all this space, but
858c2ecf20Sopenharmony_ci	 * the result must start at the beginning of the buffer and correct
868c2ecf20Sopenharmony_ci	 * length must be returned */
878c2ecf20Sopenharmony_ci	int extra_mpdu_prefix_len, extra_mpdu_postfix_len;
888c2ecf20Sopenharmony_ci	int extra_msdu_prefix_len, extra_msdu_postfix_len;
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_ci	struct module *owner;
918c2ecf20Sopenharmony_ci};
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_cistruct lib80211_crypt_data {
948c2ecf20Sopenharmony_ci	struct list_head list;	/* delayed deletion list */
958c2ecf20Sopenharmony_ci	struct lib80211_crypto_ops *ops;
968c2ecf20Sopenharmony_ci	void *priv;
978c2ecf20Sopenharmony_ci	atomic_t refcnt;
988c2ecf20Sopenharmony_ci};
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_cistruct lib80211_crypt_info {
1018c2ecf20Sopenharmony_ci	char *name;
1028c2ecf20Sopenharmony_ci	/* Most clients will already have a lock,
1038c2ecf20Sopenharmony_ci	   so just point to that. */
1048c2ecf20Sopenharmony_ci	spinlock_t *lock;
1058c2ecf20Sopenharmony_ci
1068c2ecf20Sopenharmony_ci	struct lib80211_crypt_data *crypt[NUM_WEP_KEYS];
1078c2ecf20Sopenharmony_ci	int tx_keyidx;		/* default TX key index (crypt[tx_keyidx]) */
1088c2ecf20Sopenharmony_ci	struct list_head crypt_deinit_list;
1098c2ecf20Sopenharmony_ci	struct timer_list crypt_deinit_timer;
1108c2ecf20Sopenharmony_ci	int crypt_quiesced;
1118c2ecf20Sopenharmony_ci};
1128c2ecf20Sopenharmony_ci
1138c2ecf20Sopenharmony_ciint lib80211_crypt_info_init(struct lib80211_crypt_info *info, char *name,
1148c2ecf20Sopenharmony_ci                                spinlock_t *lock);
1158c2ecf20Sopenharmony_civoid lib80211_crypt_info_free(struct lib80211_crypt_info *info);
1168c2ecf20Sopenharmony_ciint lib80211_register_crypto_ops(struct lib80211_crypto_ops *ops);
1178c2ecf20Sopenharmony_ciint lib80211_unregister_crypto_ops(struct lib80211_crypto_ops *ops);
1188c2ecf20Sopenharmony_cistruct lib80211_crypto_ops *lib80211_get_crypto_ops(const char *name);
1198c2ecf20Sopenharmony_civoid lib80211_crypt_delayed_deinit(struct lib80211_crypt_info *info,
1208c2ecf20Sopenharmony_ci				    struct lib80211_crypt_data **crypt);
1218c2ecf20Sopenharmony_ci
1228c2ecf20Sopenharmony_ci#endif /* LIB80211_H */
123