aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn W. Linville <linville@tuxdriver.com>2008-11-11 16:00:06 -0500
committerJohn W. Linville <linville@tuxdriver.com>2008-11-21 11:08:17 -0500
commit2ba4b32ecf748d5f45f298fc9677fa46d1dd9aff (patch)
treeebdf68be060014d9f5c799cf1cb54462bc896140
parent274bfb8dc5ffa16cb073801bebe76ab7f4e2e73d (diff)
lib80211: consolidate crypt init routines
Signed-off-by: John W. Linville <linville@tuxdriver.com>
-rw-r--r--drivers/net/wireless/hostap/hostap_hw.c61
-rw-r--r--drivers/net/wireless/hostap/hostap_ioctl.c43
-rw-r--r--include/net/lib80211.h3
-rw-r--r--net/ieee80211/ieee80211_module.c26
-rw-r--r--net/wireless/lib80211.c38
5 files changed, 54 insertions, 117 deletions
diff --git a/drivers/net/wireless/hostap/hostap_hw.c b/drivers/net/wireless/hostap/hostap_hw.c
index 066299fc9259..0f27059bbe85 100644
--- a/drivers/net/wireless/hostap/hostap_hw.c
+++ b/drivers/net/wireless/hostap/hostap_hw.c
@@ -2788,46 +2788,6 @@ static void prism2_check_sta_fw_version(local_info_t *local)
2788} 2788}
2789 2789
2790 2790
2791static void prism2_crypt_deinit_entries(local_info_t *local, int force)
2792{
2793 struct list_head *ptr, *n;
2794 struct lib80211_crypt_data *entry;
2795
2796 for (ptr = local->crypt_info.crypt_deinit_list.next, n = ptr->next;
2797 ptr != &local->crypt_info.crypt_deinit_list;
2798 ptr = n, n = ptr->next) {
2799 entry = list_entry(ptr, struct lib80211_crypt_data, list);
2800
2801 if (atomic_read(&entry->refcnt) != 0 && !force)
2802 continue;
2803
2804 list_del(ptr);
2805
2806 if (entry->ops)
2807 entry->ops->deinit(entry->priv);
2808 kfree(entry);
2809 }
2810}
2811
2812
2813static void prism2_crypt_deinit_handler(unsigned long data)
2814{
2815 local_info_t *local = (local_info_t *) data;
2816 unsigned long flags;
2817
2818 spin_lock_irqsave(&local->lock, flags);
2819 prism2_crypt_deinit_entries(local, 0);
2820 if (!list_empty(&local->crypt_info.crypt_deinit_list)) {
2821 printk(KERN_DEBUG "%s: entries remaining in delayed crypt "
2822 "deletion list\n", local->dev->name);
2823 local->crypt_info.crypt_deinit_timer.expires = jiffies + HZ;
2824 add_timer(&local->crypt_info.crypt_deinit_timer);
2825 }
2826 spin_unlock_irqrestore(&local->lock, flags);
2827
2828}
2829
2830
2831static void hostap_passive_scan(unsigned long data) 2791static void hostap_passive_scan(unsigned long data)
2832{ 2792{
2833 local_info_t *local = (local_info_t *) data; 2793 local_info_t *local = (local_info_t *) data;
@@ -3252,12 +3212,7 @@ while (0)
3252 INIT_LIST_HEAD(&local->cmd_queue); 3212 INIT_LIST_HEAD(&local->cmd_queue);
3253 init_waitqueue_head(&local->hostscan_wq); 3213 init_waitqueue_head(&local->hostscan_wq);
3254 3214
3255 local->crypt_info.name = dev->name; 3215 lib80211_crypt_info_init(&local->crypt_info, dev->name, &local->lock);
3256 local->crypt_info.lock = &local->lock;
3257 INIT_LIST_HEAD(&local->crypt_info.crypt_deinit_list);
3258 init_timer(&local->crypt_info.crypt_deinit_timer);
3259 local->crypt_info.crypt_deinit_timer.data = (unsigned long) local;
3260 local->crypt_info.crypt_deinit_timer.function = prism2_crypt_deinit_handler;
3261 3216
3262 init_timer(&local->passive_scan_timer); 3217 init_timer(&local->passive_scan_timer);
3263 local->passive_scan_timer.data = (unsigned long) local; 3218 local->passive_scan_timer.data = (unsigned long) local;
@@ -3358,9 +3313,7 @@ static void prism2_free_local_data(struct net_device *dev)
3358 3313
3359 flush_scheduled_work(); 3314 flush_scheduled_work();
3360 3315
3361 if (timer_pending(&local->crypt_info.crypt_deinit_timer)) 3316 lib80211_crypt_info_free(&local->crypt_info);
3362 del_timer(&local->crypt_info.crypt_deinit_timer);
3363 prism2_crypt_deinit_entries(local, 1);
3364 3317
3365 if (timer_pending(&local->passive_scan_timer)) 3318 if (timer_pending(&local->passive_scan_timer))
3366 del_timer(&local->passive_scan_timer); 3319 del_timer(&local->passive_scan_timer);
@@ -3377,16 +3330,6 @@ static void prism2_free_local_data(struct net_device *dev)
3377 if (local->dev_enabled) 3330 if (local->dev_enabled)
3378 prism2_callback(local, PRISM2_CALLBACK_DISABLE); 3331 prism2_callback(local, PRISM2_CALLBACK_DISABLE);
3379 3332
3380 for (i = 0; i < WEP_KEYS; i++) {
3381 struct lib80211_crypt_data *crypt = local->crypt_info.crypt[i];
3382 if (crypt) {
3383 if (crypt->ops)
3384 crypt->ops->deinit(crypt->priv);
3385 kfree(crypt);
3386 local->crypt_info.crypt[i] = NULL;
3387 }
3388 }
3389
3390 if (local->ap != NULL) 3333 if (local->ap != NULL)
3391 hostap_free_data(local->ap); 3334 hostap_free_data(local->ap);
3392 3335
diff --git a/drivers/net/wireless/hostap/hostap_ioctl.c b/drivers/net/wireless/hostap/hostap_ioctl.c
index 29aebb679099..c40fdf4c79de 100644
--- a/drivers/net/wireless/hostap/hostap_ioctl.c
+++ b/drivers/net/wireless/hostap/hostap_ioctl.c
@@ -116,32 +116,6 @@ static int prism2_get_name(struct net_device *dev,
116} 116}
117 117
118 118
119static void prism2_crypt_delayed_deinit(local_info_t *local,
120 struct lib80211_crypt_data **crypt)
121{
122 struct lib80211_crypt_data *tmp;
123 unsigned long flags;
124
125 tmp = *crypt;
126 *crypt = NULL;
127
128 if (tmp == NULL)
129 return;
130
131 /* must not run ops->deinit() while there may be pending encrypt or
132 * decrypt operations. Use a list of delayed deinits to avoid needing
133 * locking. */
134
135 spin_lock_irqsave(&local->lock, flags);
136 list_add(&tmp->list, &local->crypt_info.crypt_deinit_list);
137 if (!timer_pending(&local->crypt_info.crypt_deinit_timer)) {
138 local->crypt_info.crypt_deinit_timer.expires = jiffies + HZ;
139 add_timer(&local->crypt_info.crypt_deinit_timer);
140 }
141 spin_unlock_irqrestore(&local->lock, flags);
142}
143
144
145static int prism2_ioctl_siwencode(struct net_device *dev, 119static int prism2_ioctl_siwencode(struct net_device *dev,
146 struct iw_request_info *info, 120 struct iw_request_info *info,
147 struct iw_point *erq, char *keybuf) 121 struct iw_point *erq, char *keybuf)
@@ -166,14 +140,14 @@ static int prism2_ioctl_siwencode(struct net_device *dev,
166 140
167 if (erq->flags & IW_ENCODE_DISABLED) { 141 if (erq->flags & IW_ENCODE_DISABLED) {
168 if (*crypt) 142 if (*crypt)
169 prism2_crypt_delayed_deinit(local, crypt); 143 lib80211_crypt_delayed_deinit(&local->crypt_info, crypt);
170 goto done; 144 goto done;
171 } 145 }
172 146
173 if (*crypt != NULL && (*crypt)->ops != NULL && 147 if (*crypt != NULL && (*crypt)->ops != NULL &&
174 strcmp((*crypt)->ops->name, "WEP") != 0) { 148 strcmp((*crypt)->ops->name, "WEP") != 0) {
175 /* changing to use WEP; deinit previously used algorithm */ 149 /* changing to use WEP; deinit previously used algorithm */
176 prism2_crypt_delayed_deinit(local, crypt); 150 lib80211_crypt_delayed_deinit(&local->crypt_info, crypt);
177 } 151 }
178 152
179 if (*crypt == NULL) { 153 if (*crypt == NULL) {
@@ -189,7 +163,7 @@ static int prism2_ioctl_siwencode(struct net_device *dev,
189 request_module("lib80211_crypt_wep"); 163 request_module("lib80211_crypt_wep");
190 new_crypt->ops = lib80211_get_crypto_ops("WEP"); 164 new_crypt->ops = lib80211_get_crypto_ops("WEP");
191 } 165 }
192 if (new_crypt->ops) 166 if (new_crypt->ops && try_module_get(new_crypt->ops->owner))
193 new_crypt->priv = new_crypt->ops->init(i); 167 new_crypt->priv = new_crypt->ops->init(i);
194 if (!new_crypt->ops || !new_crypt->priv) { 168 if (!new_crypt->ops || !new_crypt->priv) {
195 kfree(new_crypt); 169 kfree(new_crypt);
@@ -3269,7 +3243,7 @@ static int prism2_ioctl_siwencodeext(struct net_device *dev,
3269 if ((erq->flags & IW_ENCODE_DISABLED) || 3243 if ((erq->flags & IW_ENCODE_DISABLED) ||
3270 ext->alg == IW_ENCODE_ALG_NONE) { 3244 ext->alg == IW_ENCODE_ALG_NONE) {
3271 if (*crypt) 3245 if (*crypt)
3272 prism2_crypt_delayed_deinit(local, crypt); 3246 lib80211_crypt_delayed_deinit(&local->crypt_info, crypt);
3273 goto done; 3247 goto done;
3274 } 3248 }
3275 3249
@@ -3317,7 +3291,7 @@ static int prism2_ioctl_siwencodeext(struct net_device *dev,
3317 if (*crypt == NULL || (*crypt)->ops != ops) { 3291 if (*crypt == NULL || (*crypt)->ops != ops) {
3318 struct lib80211_crypt_data *new_crypt; 3292 struct lib80211_crypt_data *new_crypt;
3319 3293
3320 prism2_crypt_delayed_deinit(local, crypt); 3294 lib80211_crypt_delayed_deinit(&local->crypt_info, crypt);
3321 3295
3322 new_crypt = kzalloc(sizeof(struct lib80211_crypt_data), 3296 new_crypt = kzalloc(sizeof(struct lib80211_crypt_data),
3323 GFP_KERNEL); 3297 GFP_KERNEL);
@@ -3326,7 +3300,8 @@ static int prism2_ioctl_siwencodeext(struct net_device *dev,
3326 goto done; 3300 goto done;
3327 } 3301 }
3328 new_crypt->ops = ops; 3302 new_crypt->ops = ops;
3329 new_crypt->priv = new_crypt->ops->init(i); 3303 if (new_crypt->ops && try_module_get(new_crypt->ops->owner))
3304 new_crypt->priv = new_crypt->ops->init(i);
3330 if (new_crypt->priv == NULL) { 3305 if (new_crypt->priv == NULL) {
3331 kfree(new_crypt); 3306 kfree(new_crypt);
3332 ret = -EINVAL; 3307 ret = -EINVAL;
@@ -3503,7 +3478,7 @@ static int prism2_ioctl_set_encryption(local_info_t *local,
3503 3478
3504 if (strcmp(param->u.crypt.alg, "none") == 0) { 3479 if (strcmp(param->u.crypt.alg, "none") == 0) {
3505 if (crypt) 3480 if (crypt)
3506 prism2_crypt_delayed_deinit(local, crypt); 3481 lib80211_crypt_delayed_deinit(&local->crypt_info, crypt);
3507 goto done; 3482 goto done;
3508 } 3483 }
3509 3484
@@ -3533,7 +3508,7 @@ static int prism2_ioctl_set_encryption(local_info_t *local,
3533 if (*crypt == NULL || (*crypt)->ops != ops) { 3508 if (*crypt == NULL || (*crypt)->ops != ops) {
3534 struct lib80211_crypt_data *new_crypt; 3509 struct lib80211_crypt_data *new_crypt;
3535 3510
3536 prism2_crypt_delayed_deinit(local, crypt); 3511 lib80211_crypt_delayed_deinit(&local->crypt_info, crypt);
3537 3512
3538 new_crypt = kzalloc(sizeof(struct lib80211_crypt_data), 3513 new_crypt = kzalloc(sizeof(struct lib80211_crypt_data),
3539 GFP_KERNEL); 3514 GFP_KERNEL);
diff --git a/include/net/lib80211.h b/include/net/lib80211.h
index dd1079f98da4..a269b23d1125 100644
--- a/include/net/lib80211.h
+++ b/include/net/lib80211.h
@@ -114,6 +114,9 @@ struct lib80211_crypt_info {
114 int crypt_quiesced; 114 int crypt_quiesced;
115}; 115};
116 116
117int lib80211_crypt_info_init(struct lib80211_crypt_info *info, char *name,
118 spinlock_t *lock);
119void lib80211_crypt_info_free(struct lib80211_crypt_info *info);
117int lib80211_register_crypto_ops(struct lib80211_crypto_ops *ops); 120int lib80211_register_crypto_ops(struct lib80211_crypto_ops *ops);
118int lib80211_unregister_crypto_ops(struct lib80211_crypto_ops *ops); 121int lib80211_unregister_crypto_ops(struct lib80211_crypto_ops *ops);
119struct lib80211_crypto_ops *lib80211_get_crypto_ops(const char *name); 122struct lib80211_crypto_ops *lib80211_get_crypto_ops(const char *name);
diff --git a/net/ieee80211/ieee80211_module.c b/net/ieee80211/ieee80211_module.c
index cf21f0bd8569..a2f5616d5b09 100644
--- a/net/ieee80211/ieee80211_module.c
+++ b/net/ieee80211/ieee80211_module.c
@@ -182,13 +182,7 @@ struct net_device *alloc_ieee80211(int sizeof_priv)
182 182
183 spin_lock_init(&ieee->lock); 183 spin_lock_init(&ieee->lock);
184 184
185 ieee->crypt_info.name = dev->name; 185 lib80211_crypt_info_init(&ieee->crypt_info, dev->name, &ieee->lock);
186 ieee->crypt_info.lock = &ieee->lock;
187 INIT_LIST_HEAD(&ieee->crypt_info.crypt_deinit_list);
188 setup_timer(&ieee->crypt_info.crypt_deinit_timer,
189 lib80211_crypt_deinit_handler,
190 (unsigned long)&ieee->crypt_info);
191 ieee->crypt_info.crypt_quiesced = 0;
192 186
193 ieee->wpa_enabled = 0; 187 ieee->wpa_enabled = 0;
194 ieee->drop_unencrypted = 0; 188 ieee->drop_unencrypted = 0;
@@ -206,23 +200,7 @@ void free_ieee80211(struct net_device *dev)
206{ 200{
207 struct ieee80211_device *ieee = netdev_priv(dev); 201 struct ieee80211_device *ieee = netdev_priv(dev);
208 202
209 int i; 203 lib80211_crypt_info_free(&ieee->crypt_info);
210
211 lib80211_crypt_quiescing(&ieee->crypt_info);
212 del_timer_sync(&ieee->crypt_info.crypt_deinit_timer);
213 lib80211_crypt_deinit_entries(&ieee->crypt_info, 1);
214
215 for (i = 0; i < WEP_KEYS; i++) {
216 struct lib80211_crypt_data *crypt = ieee->crypt_info.crypt[i];
217 if (crypt) {
218 if (crypt->ops) {
219 crypt->ops->deinit(crypt->priv);
220 module_put(crypt->ops->owner);
221 }
222 kfree(crypt);
223 ieee->crypt_info.crypt[i] = NULL;
224 }
225 }
226 204
227 ieee80211_networks_free(ieee); 205 ieee80211_networks_free(ieee);
228 free_netdev(dev); 206 free_netdev(dev);
diff --git a/net/wireless/lib80211.c b/net/wireless/lib80211.c
index d681721f4acb..97d411f74507 100644
--- a/net/wireless/lib80211.c
+++ b/net/wireless/lib80211.c
@@ -71,6 +71,44 @@ const char *print_ssid(char *buf, const char *ssid, u8 ssid_len)
71} 71}
72EXPORT_SYMBOL(print_ssid); 72EXPORT_SYMBOL(print_ssid);
73 73
74int lib80211_crypt_info_init(struct lib80211_crypt_info *info, char *name,
75 spinlock_t *lock)
76{
77 memset(info, 0, sizeof(*info));
78
79 info->name = name;
80 info->lock = lock;
81
82 INIT_LIST_HEAD(&info->crypt_deinit_list);
83 setup_timer(&info->crypt_deinit_timer, lib80211_crypt_deinit_handler,
84 (unsigned long)info);
85
86 return 0;
87}
88EXPORT_SYMBOL(lib80211_crypt_info_init);
89
90void lib80211_crypt_info_free(struct lib80211_crypt_info *info)
91{
92 int i;
93
94 lib80211_crypt_quiescing(info);
95 del_timer_sync(&info->crypt_deinit_timer);
96 lib80211_crypt_deinit_entries(info, 1);
97
98 for (i = 0; i < NUM_WEP_KEYS; i++) {
99 struct lib80211_crypt_data *crypt = info->crypt[i];
100 if (crypt) {
101 if (crypt->ops) {
102 crypt->ops->deinit(crypt->priv);
103 module_put(crypt->ops->owner);
104 }
105 kfree(crypt);
106 info->crypt[i] = NULL;
107 }
108 }
109}
110EXPORT_SYMBOL(lib80211_crypt_info_free);
111
74void lib80211_crypt_deinit_entries(struct lib80211_crypt_info *info, int force) 112void lib80211_crypt_deinit_entries(struct lib80211_crypt_info *info, int force)
75{ 113{
76 struct lib80211_crypt_data *entry, *next; 114 struct lib80211_crypt_data *entry, *next;