ieee80211_crypto_wep.c (2cc12ade) ieee80211_crypto_wep.c (d16441fd)
1/*-
2 * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 68 unchanged lines hidden (view full) ---

77static int wep_encrypt(struct ieee80211_key *, struct mbuf *, int hdrlen);
78static int wep_decrypt(struct ieee80211_key *, struct mbuf *, int hdrlen);
79
80struct wep_ctx {
81 struct ieee80211com *wc_ic; /* for diagnostics */
82 u_int32_t wc_iv; /* initial vector for crypto */
83};
84
1/*-
2 * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 68 unchanged lines hidden (view full) ---

77static int wep_encrypt(struct ieee80211_key *, struct mbuf *, int hdrlen);
78static int wep_decrypt(struct ieee80211_key *, struct mbuf *, int hdrlen);
79
80struct wep_ctx {
81 struct ieee80211com *wc_ic; /* for diagnostics */
82 u_int32_t wc_iv; /* initial vector for crypto */
83};
84
85/* number of references from net80211 layer */
86static int nrefs = 0;
87
85static void *
86wep_attach(struct ieee80211com *ic, struct ieee80211_key *k)
87{
88 struct wep_ctx *ctx;
89
90 MALLOC(ctx, struct wep_ctx *, sizeof(struct wep_ctx),
91 M_DEVBUF, M_NOWAIT | M_ZERO);
92 if (ctx == NULL) {
93 ic->ic_stats.is_crypto_nomem++;
94 return NULL;
95 }
96
97 ctx->wc_ic = ic;
98 get_random_bytes(&ctx->wc_iv, sizeof(ctx->wc_iv));
88static void *
89wep_attach(struct ieee80211com *ic, struct ieee80211_key *k)
90{
91 struct wep_ctx *ctx;
92
93 MALLOC(ctx, struct wep_ctx *, sizeof(struct wep_ctx),
94 M_DEVBUF, M_NOWAIT | M_ZERO);
95 if (ctx == NULL) {
96 ic->ic_stats.is_crypto_nomem++;
97 return NULL;
98 }
99
100 ctx->wc_ic = ic;
101 get_random_bytes(&ctx->wc_iv, sizeof(ctx->wc_iv));
102 nrefs++; /* NB: we assume caller locking */
99 return ctx;
100}
101
102static void
103wep_detach(struct ieee80211_key *k)
104{
105 struct wep_ctx *ctx = k->wk_private;
106
107 FREE(ctx, M_DEVBUF);
103 return ctx;
104}
105
106static void
107wep_detach(struct ieee80211_key *k)
108{
109 struct wep_ctx *ctx = k->wk_private;
110
111 FREE(ctx, M_DEVBUF);
112 KASSERT(nrefs > 0, ("imbalanced attach/detach"));
113 nrefs--; /* NB: we assume caller locking */
108}
109
110static int
111wep_setkey(struct ieee80211_key *k)
112{
113 return k->wk_keylen >= 40/NBBY;
114}
115

--- 360 unchanged lines hidden (view full) ---

476static int
477wep_modevent(module_t mod, int type, void *unused)
478{
479 switch (type) {
480 case MOD_LOAD:
481 ieee80211_crypto_register(&wep);
482 return 0;
483 case MOD_UNLOAD:
114}
115
116static int
117wep_setkey(struct ieee80211_key *k)
118{
119 return k->wk_keylen >= 40/NBBY;
120}
121

--- 360 unchanged lines hidden (view full) ---

482static int
483wep_modevent(module_t mod, int type, void *unused)
484{
485 switch (type) {
486 case MOD_LOAD:
487 ieee80211_crypto_register(&wep);
488 return 0;
489 case MOD_UNLOAD:
484 ieee80211_crypto_unregister(&wep);
490 case MOD_QUIESCE:
491 if (nrefs) {
492 printf("wlan_wep: still in use (%u dynamic refs)\n",
493 nrefs);
494 return EBUSY;
495 }
496 if (type == MOD_UNLOAD)
497 ieee80211_crypto_unregister(&wep);
485 return 0;
486 }
487 return EINVAL;
488}
489
490static moduledata_t wep_mod = {
491 "wlan_wep",
492 wep_modevent,
493 0
494};
495DECLARE_MODULE(wlan_wep, wep_mod, SI_SUB_DRIVERS, SI_ORDER_FIRST);
496MODULE_VERSION(wlan_wep, 1);
497MODULE_DEPEND(wlan_wep, wlan, 1, 1, 1);
498 return 0;
499 }
500 return EINVAL;
501}
502
503static moduledata_t wep_mod = {
504 "wlan_wep",
505 wep_modevent,
506 0
507};
508DECLARE_MODULE(wlan_wep, wep_mod, SI_SUB_DRIVERS, SI_ORDER_FIRST);
509MODULE_VERSION(wlan_wep, 1);
510MODULE_DEPEND(wlan_wep, wlan, 1, 1, 1);