| Luis Carlos Cobo | 2e3c873 | 2008-02-23 15:17:09 +0100 | [diff] [blame] | 1 | /* | 
 | 2 |  * Copyright (c) 2008 open80211s Ltd. | 
 | 3 |  * Authors:    Luis Carlos Cobo <luisca@cozybit.com> | 
 | 4 |  * 	       Javier Cardona <javier@cozybit.com> | 
 | 5 |  * | 
 | 6 |  * This program is free software; you can redistribute it and/or modify | 
 | 7 |  * it under the terms of the GNU General Public License version 2 as | 
 | 8 |  * published by the Free Software Foundation. | 
 | 9 |  */ | 
 | 10 |  | 
| Luis Carlos Cobo | 51cedda | 2008-04-23 12:15:29 -0700 | [diff] [blame] | 11 | #include <asm/unaligned.h> | 
| Luis Carlos Cobo | 2e3c873 | 2008-02-23 15:17:09 +0100 | [diff] [blame] | 12 | #include "ieee80211_i.h" | 
 | 13 | #include "mesh.h" | 
 | 14 |  | 
| Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 15 | #define IEEE80211_MESH_PEER_INACTIVITY_LIMIT (1800 * HZ) | 
 | 16 | #define IEEE80211_MESH_HOUSEKEEPING_INTERVAL (60 * HZ) | 
 | 17 |  | 
| John W. Linville | 2473670 | 2008-04-08 14:15:46 -0400 | [diff] [blame] | 18 | #define PP_OFFSET 	1		/* Path Selection Protocol */ | 
 | 19 | #define PM_OFFSET	5		/* Path Selection Metric   */ | 
 | 20 | #define CC_OFFSET	9		/* Congestion Control Mode */ | 
 | 21 | #define CAPAB_OFFSET 17 | 
| Luis Carlos Cobo | 2e3c873 | 2008-02-23 15:17:09 +0100 | [diff] [blame] | 22 | #define ACCEPT_PLINKS 0x80 | 
 | 23 |  | 
 | 24 | int mesh_allocated; | 
 | 25 | static struct kmem_cache *rm_cache; | 
 | 26 |  | 
 | 27 | void ieee80211s_init(void) | 
 | 28 | { | 
 | 29 | 	mesh_pathtbl_init(); | 
 | 30 | 	mesh_allocated = 1; | 
 | 31 | 	rm_cache = kmem_cache_create("mesh_rmc", sizeof(struct rmc_entry), | 
 | 32 | 				     0, 0, NULL); | 
 | 33 | } | 
 | 34 |  | 
 | 35 | void ieee80211s_stop(void) | 
 | 36 | { | 
 | 37 | 	mesh_pathtbl_unregister(); | 
 | 38 | 	kmem_cache_destroy(rm_cache); | 
 | 39 | } | 
 | 40 |  | 
| Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 41 | static void ieee80211_mesh_housekeeping_timer(unsigned long data) | 
 | 42 | { | 
 | 43 | 	struct ieee80211_sub_if_data *sdata = (void *) data; | 
 | 44 | 	struct ieee80211_local *local = sdata->local; | 
 | 45 | 	struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; | 
 | 46 |  | 
 | 47 | 	ifmsh->housekeeping = true; | 
 | 48 | 	queue_work(local->hw.workqueue, &ifmsh->work); | 
 | 49 | } | 
 | 50 |  | 
| Luis Carlos Cobo | 2e3c873 | 2008-02-23 15:17:09 +0100 | [diff] [blame] | 51 | /** | 
 | 52 |  * mesh_matches_local - check if the config of a mesh point matches ours | 
 | 53 |  * | 
 | 54 |  * @ie: information elements of a management frame from the mesh peer | 
| Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 55 |  * @sdata: local mesh subif | 
| Luis Carlos Cobo | 2e3c873 | 2008-02-23 15:17:09 +0100 | [diff] [blame] | 56 |  * | 
 | 57 |  * This function checks if the mesh configuration of a mesh point matches the | 
 | 58 |  * local mesh configuration, i.e. if both nodes belong to the same mesh network. | 
 | 59 |  */ | 
| Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 60 | bool mesh_matches_local(struct ieee802_11_elems *ie, struct ieee80211_sub_if_data *sdata) | 
| Luis Carlos Cobo | 2e3c873 | 2008-02-23 15:17:09 +0100 | [diff] [blame] | 61 | { | 
| Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 62 | 	struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; | 
| Luis Carlos Cobo | 2e3c873 | 2008-02-23 15:17:09 +0100 | [diff] [blame] | 63 |  | 
| Luis Carlos Cobo | 2e3c873 | 2008-02-23 15:17:09 +0100 | [diff] [blame] | 64 | 	/* | 
 | 65 | 	 * As support for each feature is added, check for matching | 
 | 66 | 	 * - On mesh config capabilities | 
 | 67 | 	 *   - Power Save Support En | 
 | 68 | 	 *   - Sync support enabled | 
 | 69 | 	 *   - Sync support active | 
 | 70 | 	 *   - Sync support required from peer | 
 | 71 | 	 *   - MDA enabled | 
 | 72 | 	 * - Power management control on fc | 
 | 73 | 	 */ | 
| Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 74 | 	if (ifmsh->mesh_id_len == ie->mesh_id_len && | 
 | 75 | 		memcmp(ifmsh->mesh_id, ie->mesh_id, ie->mesh_id_len) == 0 && | 
 | 76 | 		memcmp(ifmsh->mesh_pp_id, ie->mesh_config + PP_OFFSET, 4) == 0 && | 
 | 77 | 		memcmp(ifmsh->mesh_pm_id, ie->mesh_config + PM_OFFSET, 4) == 0 && | 
 | 78 | 		memcmp(ifmsh->mesh_cc_id, ie->mesh_config + CC_OFFSET, 4) == 0) | 
| Luis Carlos Cobo | 2e3c873 | 2008-02-23 15:17:09 +0100 | [diff] [blame] | 79 | 		return true; | 
 | 80 |  | 
 | 81 | 	return false; | 
 | 82 | } | 
 | 83 |  | 
 | 84 | /** | 
 | 85 |  * mesh_peer_accepts_plinks - check if an mp is willing to establish peer links | 
 | 86 |  * | 
 | 87 |  * @ie: information elements of a management frame from the mesh peer | 
| Luis Carlos Cobo | 2e3c873 | 2008-02-23 15:17:09 +0100 | [diff] [blame] | 88 |  */ | 
| Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 89 | bool mesh_peer_accepts_plinks(struct ieee802_11_elems *ie) | 
| Luis Carlos Cobo | 2e3c873 | 2008-02-23 15:17:09 +0100 | [diff] [blame] | 90 | { | 
 | 91 | 	return (*(ie->mesh_config + CAPAB_OFFSET) & ACCEPT_PLINKS) != 0; | 
 | 92 | } | 
 | 93 |  | 
 | 94 | /** | 
 | 95 |  * mesh_accept_plinks_update: update accepting_plink in local mesh beacons | 
 | 96 |  * | 
| Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 97 |  * @sdata: mesh interface in which mesh beacons are going to be updated | 
| Luis Carlos Cobo | 2e3c873 | 2008-02-23 15:17:09 +0100 | [diff] [blame] | 98 |  */ | 
| Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 99 | void mesh_accept_plinks_update(struct ieee80211_sub_if_data *sdata) | 
| Luis Carlos Cobo | 2e3c873 | 2008-02-23 15:17:09 +0100 | [diff] [blame] | 100 | { | 
| Luis Carlos Cobo | 2e3c873 | 2008-02-23 15:17:09 +0100 | [diff] [blame] | 101 | 	bool free_plinks; | 
 | 102 |  | 
 | 103 | 	/* In case mesh_plink_free_count > 0 and mesh_plinktbl_capacity == 0, | 
 | 104 | 	 * the mesh interface might be able to establish plinks with peers that | 
| Luis Carlos Cobo | b4e08ea | 2008-02-29 15:46:08 -0800 | [diff] [blame] | 105 | 	 * are already on the table but are not on PLINK_ESTAB state. However, | 
 | 106 | 	 * in general the mesh interface is not accepting peer link requests | 
 | 107 | 	 * from new peers, and that must be reflected in the beacon | 
| Luis Carlos Cobo | 2e3c873 | 2008-02-23 15:17:09 +0100 | [diff] [blame] | 108 | 	 */ | 
 | 109 | 	free_plinks = mesh_plink_availables(sdata); | 
 | 110 |  | 
| Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 111 | 	if (free_plinks != sdata->u.mesh.accepting_plinks) | 
 | 112 | 		ieee80211_mesh_housekeeping_timer((unsigned long) sdata); | 
| Luis Carlos Cobo | 2e3c873 | 2008-02-23 15:17:09 +0100 | [diff] [blame] | 113 | } | 
 | 114 |  | 
| Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 115 | void mesh_ids_set_default(struct ieee80211_if_mesh *sta) | 
| Luis Carlos Cobo | 2e3c873 | 2008-02-23 15:17:09 +0100 | [diff] [blame] | 116 | { | 
 | 117 | 	u8 def_id[4] = {0x00, 0x0F, 0xAC, 0xff}; | 
 | 118 |  | 
 | 119 | 	memcpy(sta->mesh_pp_id, def_id, 4); | 
 | 120 | 	memcpy(sta->mesh_pm_id, def_id, 4); | 
 | 121 | 	memcpy(sta->mesh_cc_id, def_id, 4); | 
 | 122 | } | 
 | 123 |  | 
| Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 124 | int mesh_rmc_init(struct ieee80211_sub_if_data *sdata) | 
| Luis Carlos Cobo | 2e3c873 | 2008-02-23 15:17:09 +0100 | [diff] [blame] | 125 | { | 
| Luis Carlos Cobo | 2e3c873 | 2008-02-23 15:17:09 +0100 | [diff] [blame] | 126 | 	int i; | 
 | 127 |  | 
| Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 128 | 	sdata->u.mesh.rmc = kmalloc(sizeof(struct mesh_rmc), GFP_KERNEL); | 
 | 129 | 	if (!sdata->u.mesh.rmc) | 
| Luis Carlos Cobo | 2e3c873 | 2008-02-23 15:17:09 +0100 | [diff] [blame] | 130 | 		return -ENOMEM; | 
| Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 131 | 	sdata->u.mesh.rmc->idx_mask = RMC_BUCKETS - 1; | 
| Luis Carlos Cobo | 2e3c873 | 2008-02-23 15:17:09 +0100 | [diff] [blame] | 132 | 	for (i = 0; i < RMC_BUCKETS; i++) | 
| Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 133 | 		INIT_LIST_HEAD(&sdata->u.mesh.rmc->bucket[i].list); | 
| Luis Carlos Cobo | 2e3c873 | 2008-02-23 15:17:09 +0100 | [diff] [blame] | 134 | 	return 0; | 
 | 135 | } | 
 | 136 |  | 
| Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 137 | void mesh_rmc_free(struct ieee80211_sub_if_data *sdata) | 
| Luis Carlos Cobo | 2e3c873 | 2008-02-23 15:17:09 +0100 | [diff] [blame] | 138 | { | 
| Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 139 | 	struct mesh_rmc *rmc = sdata->u.mesh.rmc; | 
| Luis Carlos Cobo | 2e3c873 | 2008-02-23 15:17:09 +0100 | [diff] [blame] | 140 | 	struct rmc_entry *p, *n; | 
 | 141 | 	int i; | 
 | 142 |  | 
| Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 143 | 	if (!sdata->u.mesh.rmc) | 
| Luis Carlos Cobo | 2e3c873 | 2008-02-23 15:17:09 +0100 | [diff] [blame] | 144 | 		return; | 
 | 145 |  | 
 | 146 | 	for (i = 0; i < RMC_BUCKETS; i++) | 
 | 147 | 		list_for_each_entry_safe(p, n, &rmc->bucket[i].list, list) { | 
 | 148 | 			list_del(&p->list); | 
 | 149 | 			kmem_cache_free(rm_cache, p); | 
 | 150 | 		} | 
 | 151 |  | 
 | 152 | 	kfree(rmc); | 
| Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 153 | 	sdata->u.mesh.rmc = NULL; | 
| Luis Carlos Cobo | 2e3c873 | 2008-02-23 15:17:09 +0100 | [diff] [blame] | 154 | } | 
 | 155 |  | 
 | 156 | /** | 
 | 157 |  * mesh_rmc_check - Check frame in recent multicast cache and add if absent. | 
 | 158 |  * | 
 | 159 |  * @sa:		source address | 
 | 160 |  * @mesh_hdr:	mesh_header | 
 | 161 |  * | 
 | 162 |  * Returns: 0 if the frame is not in the cache, nonzero otherwise. | 
 | 163 |  * | 
 | 164 |  * Checks using the source address and the mesh sequence number if we have | 
 | 165 |  * received this frame lately. If the frame is not in the cache, it is added to | 
 | 166 |  * it. | 
 | 167 |  */ | 
 | 168 | int mesh_rmc_check(u8 *sa, struct ieee80211s_hdr *mesh_hdr, | 
| Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 169 | 		   struct ieee80211_sub_if_data *sdata) | 
| Luis Carlos Cobo | 2e3c873 | 2008-02-23 15:17:09 +0100 | [diff] [blame] | 170 | { | 
| Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 171 | 	struct mesh_rmc *rmc = sdata->u.mesh.rmc; | 
| Luis Carlos Cobo | 2e3c873 | 2008-02-23 15:17:09 +0100 | [diff] [blame] | 172 | 	u32 seqnum = 0; | 
 | 173 | 	int entries = 0; | 
 | 174 | 	u8 idx; | 
 | 175 | 	struct rmc_entry *p, *n; | 
 | 176 |  | 
 | 177 | 	/* Don't care about endianness since only match matters */ | 
| Luis Carlos Cobo | 51cedda | 2008-04-23 12:15:29 -0700 | [diff] [blame] | 178 | 	memcpy(&seqnum, &mesh_hdr->seqnum, sizeof(mesh_hdr->seqnum)); | 
 | 179 | 	idx = le32_to_cpu(mesh_hdr->seqnum) & rmc->idx_mask; | 
| Luis Carlos Cobo | 2e3c873 | 2008-02-23 15:17:09 +0100 | [diff] [blame] | 180 | 	list_for_each_entry_safe(p, n, &rmc->bucket[idx].list, list) { | 
 | 181 | 		++entries; | 
 | 182 | 		if (time_after(jiffies, p->exp_time) || | 
 | 183 | 				(entries == RMC_QUEUE_MAX_LEN)) { | 
 | 184 | 			list_del(&p->list); | 
 | 185 | 			kmem_cache_free(rm_cache, p); | 
 | 186 | 			--entries; | 
 | 187 | 		} else if ((seqnum == p->seqnum) | 
 | 188 | 				&& (memcmp(sa, p->sa, ETH_ALEN) == 0)) | 
 | 189 | 			return -1; | 
 | 190 | 	} | 
 | 191 |  | 
 | 192 | 	p = kmem_cache_alloc(rm_cache, GFP_ATOMIC); | 
 | 193 | 	if (!p) { | 
 | 194 | 		printk(KERN_DEBUG "o11s: could not allocate RMC entry\n"); | 
 | 195 | 		return 0; | 
 | 196 | 	} | 
 | 197 | 	p->seqnum = seqnum; | 
 | 198 | 	p->exp_time = jiffies + RMC_TIMEOUT; | 
 | 199 | 	memcpy(p->sa, sa, ETH_ALEN); | 
 | 200 | 	list_add(&p->list, &rmc->bucket[idx].list); | 
 | 201 | 	return 0; | 
 | 202 | } | 
 | 203 |  | 
| Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 204 | void mesh_mgmt_ies_add(struct sk_buff *skb, struct ieee80211_sub_if_data *sdata) | 
| Luis Carlos Cobo | 2e3c873 | 2008-02-23 15:17:09 +0100 | [diff] [blame] | 205 | { | 
| Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 206 | 	struct ieee80211_local *local = sdata->local; | 
| Luis Carlos Cobo | 2e3c873 | 2008-02-23 15:17:09 +0100 | [diff] [blame] | 207 | 	struct ieee80211_supported_band *sband; | 
 | 208 | 	u8 *pos; | 
 | 209 | 	int len, i, rate; | 
 | 210 |  | 
 | 211 | 	sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; | 
 | 212 | 	len = sband->n_bitrates; | 
 | 213 | 	if (len > 8) | 
 | 214 | 		len = 8; | 
 | 215 | 	pos = skb_put(skb, len + 2); | 
 | 216 | 	*pos++ = WLAN_EID_SUPP_RATES; | 
 | 217 | 	*pos++ = len; | 
 | 218 | 	for (i = 0; i < len; i++) { | 
 | 219 | 		rate = sband->bitrates[i].bitrate; | 
 | 220 | 		*pos++ = (u8) (rate / 5); | 
 | 221 | 	} | 
 | 222 |  | 
 | 223 | 	if (sband->n_bitrates > len) { | 
 | 224 | 		pos = skb_put(skb, sband->n_bitrates - len + 2); | 
 | 225 | 		*pos++ = WLAN_EID_EXT_SUPP_RATES; | 
 | 226 | 		*pos++ = sband->n_bitrates - len; | 
 | 227 | 		for (i = len; i < sband->n_bitrates; i++) { | 
 | 228 | 			rate = sband->bitrates[i].bitrate; | 
 | 229 | 			*pos++ = (u8) (rate / 5); | 
 | 230 | 		} | 
 | 231 | 	} | 
 | 232 |  | 
| Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 233 | 	pos = skb_put(skb, 2 + sdata->u.mesh.mesh_id_len); | 
| Luis Carlos Cobo | 2e3c873 | 2008-02-23 15:17:09 +0100 | [diff] [blame] | 234 | 	*pos++ = WLAN_EID_MESH_ID; | 
| Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 235 | 	*pos++ = sdata->u.mesh.mesh_id_len; | 
 | 236 | 	if (sdata->u.mesh.mesh_id_len) | 
 | 237 | 		memcpy(pos, sdata->u.mesh.mesh_id, sdata->u.mesh.mesh_id_len); | 
| Luis Carlos Cobo | 2e3c873 | 2008-02-23 15:17:09 +0100 | [diff] [blame] | 238 |  | 
 | 239 | 	pos = skb_put(skb, 21); | 
 | 240 | 	*pos++ = WLAN_EID_MESH_CONFIG; | 
| Johannes Berg | 1239cd5 | 2008-10-28 11:12:57 +0100 | [diff] [blame] | 241 | 	*pos++ = IEEE80211_MESH_CONFIG_LEN; | 
| Luis Carlos Cobo | 2e3c873 | 2008-02-23 15:17:09 +0100 | [diff] [blame] | 242 | 	/* Version */ | 
 | 243 | 	*pos++ = 1; | 
 | 244 |  | 
 | 245 | 	/* Active path selection protocol ID */ | 
| Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 246 | 	memcpy(pos, sdata->u.mesh.mesh_pp_id, 4); | 
| Luis Carlos Cobo | 2e3c873 | 2008-02-23 15:17:09 +0100 | [diff] [blame] | 247 | 	pos += 4; | 
 | 248 |  | 
 | 249 | 	/* Active path selection metric ID   */ | 
| Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 250 | 	memcpy(pos, sdata->u.mesh.mesh_pm_id, 4); | 
| Luis Carlos Cobo | 2e3c873 | 2008-02-23 15:17:09 +0100 | [diff] [blame] | 251 | 	pos += 4; | 
 | 252 |  | 
 | 253 | 	/* Congestion control mode identifier */ | 
| Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 254 | 	memcpy(pos, sdata->u.mesh.mesh_cc_id, 4); | 
| Luis Carlos Cobo | 2e3c873 | 2008-02-23 15:17:09 +0100 | [diff] [blame] | 255 | 	pos += 4; | 
 | 256 |  | 
 | 257 | 	/* Channel precedence: | 
 | 258 | 	 * Not running simple channel unification protocol | 
 | 259 | 	 */ | 
 | 260 | 	memset(pos, 0x00, 4); | 
 | 261 | 	pos += 4; | 
 | 262 |  | 
 | 263 | 	/* Mesh capability */ | 
| Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 264 | 	sdata->u.mesh.accepting_plinks = mesh_plink_availables(sdata); | 
 | 265 | 	*pos++ = sdata->u.mesh.accepting_plinks ? ACCEPT_PLINKS : 0x00; | 
| Luis Carlos Cobo | 2e3c873 | 2008-02-23 15:17:09 +0100 | [diff] [blame] | 266 | 	*pos++ = 0x00; | 
 | 267 |  | 
 | 268 | 	return; | 
 | 269 | } | 
 | 270 |  | 
| Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 271 | u32 mesh_table_hash(u8 *addr, struct ieee80211_sub_if_data *sdata, struct mesh_table *tbl) | 
| Luis Carlos Cobo | 2e3c873 | 2008-02-23 15:17:09 +0100 | [diff] [blame] | 272 | { | 
 | 273 | 	/* Use last four bytes of hw addr and interface index as hash index */ | 
| Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 274 | 	return jhash_2words(*(u32 *)(addr+2), sdata->dev->ifindex, tbl->hash_rnd) | 
| Luis Carlos Cobo | 2e3c873 | 2008-02-23 15:17:09 +0100 | [diff] [blame] | 275 | 		& tbl->hash_mask; | 
 | 276 | } | 
 | 277 |  | 
| Luis Carlos Cobo | 2e3c873 | 2008-02-23 15:17:09 +0100 | [diff] [blame] | 278 | struct mesh_table *mesh_table_alloc(int size_order) | 
 | 279 | { | 
 | 280 | 	int i; | 
 | 281 | 	struct mesh_table *newtbl; | 
 | 282 |  | 
 | 283 | 	newtbl = kmalloc(sizeof(struct mesh_table), GFP_KERNEL); | 
 | 284 | 	if (!newtbl) | 
 | 285 | 		return NULL; | 
 | 286 |  | 
 | 287 | 	newtbl->hash_buckets = kzalloc(sizeof(struct hlist_head) * | 
 | 288 | 			(1 << size_order), GFP_KERNEL); | 
 | 289 |  | 
 | 290 | 	if (!newtbl->hash_buckets) { | 
 | 291 | 		kfree(newtbl); | 
 | 292 | 		return NULL; | 
 | 293 | 	} | 
 | 294 |  | 
 | 295 | 	newtbl->hashwlock = kmalloc(sizeof(spinlock_t) * | 
 | 296 | 			(1 << size_order), GFP_KERNEL); | 
 | 297 | 	if (!newtbl->hashwlock) { | 
 | 298 | 		kfree(newtbl->hash_buckets); | 
 | 299 | 		kfree(newtbl); | 
 | 300 | 		return NULL; | 
 | 301 | 	} | 
 | 302 |  | 
 | 303 | 	newtbl->size_order = size_order; | 
 | 304 | 	newtbl->hash_mask = (1 << size_order) - 1; | 
 | 305 | 	atomic_set(&newtbl->entries,  0); | 
 | 306 | 	get_random_bytes(&newtbl->hash_rnd, | 
 | 307 | 			sizeof(newtbl->hash_rnd)); | 
 | 308 | 	for (i = 0; i <= newtbl->hash_mask; i++) | 
 | 309 | 		spin_lock_init(&newtbl->hashwlock[i]); | 
 | 310 |  | 
 | 311 | 	return newtbl; | 
 | 312 | } | 
 | 313 |  | 
| Pavel Emelyanov | bd9b448 | 2008-05-07 19:57:11 +0400 | [diff] [blame] | 314 | static void __mesh_table_free(struct mesh_table *tbl) | 
 | 315 | { | 
 | 316 | 	kfree(tbl->hash_buckets); | 
 | 317 | 	kfree(tbl->hashwlock); | 
 | 318 | 	kfree(tbl); | 
 | 319 | } | 
 | 320 |  | 
| Luis Carlos Cobo | 2e3c873 | 2008-02-23 15:17:09 +0100 | [diff] [blame] | 321 | void mesh_table_free(struct mesh_table *tbl, bool free_leafs) | 
 | 322 | { | 
 | 323 | 	struct hlist_head *mesh_hash; | 
 | 324 | 	struct hlist_node *p, *q; | 
 | 325 | 	int i; | 
 | 326 |  | 
 | 327 | 	mesh_hash = tbl->hash_buckets; | 
 | 328 | 	for (i = 0; i <= tbl->hash_mask; i++) { | 
 | 329 | 		spin_lock(&tbl->hashwlock[i]); | 
 | 330 | 		hlist_for_each_safe(p, q, &mesh_hash[i]) { | 
 | 331 | 			tbl->free_node(p, free_leafs); | 
 | 332 | 			atomic_dec(&tbl->entries); | 
 | 333 | 		} | 
 | 334 | 		spin_unlock(&tbl->hashwlock[i]); | 
 | 335 | 	} | 
| Pavel Emelyanov | bd9b448 | 2008-05-07 19:57:11 +0400 | [diff] [blame] | 336 | 	__mesh_table_free(tbl); | 
| Luis Carlos Cobo | 2e3c873 | 2008-02-23 15:17:09 +0100 | [diff] [blame] | 337 | } | 
 | 338 |  | 
 | 339 | static void ieee80211_mesh_path_timer(unsigned long data) | 
 | 340 | { | 
 | 341 | 	struct ieee80211_sub_if_data *sdata = | 
 | 342 | 		(struct ieee80211_sub_if_data *) data; | 
| Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 343 | 	struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; | 
| Johannes Berg | 133b822 | 2008-09-16 14:18:59 +0200 | [diff] [blame] | 344 | 	struct ieee80211_local *local = sdata->local; | 
| Luis Carlos Cobo | 2e3c873 | 2008-02-23 15:17:09 +0100 | [diff] [blame] | 345 |  | 
| Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 346 | 	queue_work(local->hw.workqueue, &ifmsh->work); | 
| Luis Carlos Cobo | 2e3c873 | 2008-02-23 15:17:09 +0100 | [diff] [blame] | 347 | } | 
 | 348 |  | 
 | 349 | struct mesh_table *mesh_table_grow(struct mesh_table *tbl) | 
 | 350 | { | 
 | 351 | 	struct mesh_table *newtbl; | 
 | 352 | 	struct hlist_head *oldhash; | 
| Pavel Emelyanov | 4caf86c | 2008-05-07 19:47:01 +0400 | [diff] [blame] | 353 | 	struct hlist_node *p, *q; | 
| Luis Carlos Cobo | 2e3c873 | 2008-02-23 15:17:09 +0100 | [diff] [blame] | 354 | 	int i; | 
 | 355 |  | 
 | 356 | 	if (atomic_read(&tbl->entries) | 
| Pavel Emelyanov | a3538b1 | 2008-05-07 19:55:59 +0400 | [diff] [blame] | 357 | 			< tbl->mean_chain_len * (tbl->hash_mask + 1)) | 
| Luis Carlos Cobo | 2e3c873 | 2008-02-23 15:17:09 +0100 | [diff] [blame] | 358 | 		goto endgrow; | 
| Luis Carlos Cobo | 2e3c873 | 2008-02-23 15:17:09 +0100 | [diff] [blame] | 359 |  | 
 | 360 | 	newtbl = mesh_table_alloc(tbl->size_order + 1); | 
| Pavel Emelyanov | a3538b1 | 2008-05-07 19:55:59 +0400 | [diff] [blame] | 361 | 	if (!newtbl) | 
| Luis Carlos Cobo | 2e3c873 | 2008-02-23 15:17:09 +0100 | [diff] [blame] | 362 | 		goto endgrow; | 
| Luis Carlos Cobo | 2e3c873 | 2008-02-23 15:17:09 +0100 | [diff] [blame] | 363 |  | 
 | 364 | 	newtbl->free_node = tbl->free_node; | 
 | 365 | 	newtbl->mean_chain_len = tbl->mean_chain_len; | 
 | 366 | 	newtbl->copy_node = tbl->copy_node; | 
 | 367 | 	atomic_set(&newtbl->entries, atomic_read(&tbl->entries)); | 
 | 368 |  | 
 | 369 | 	oldhash = tbl->hash_buckets; | 
 | 370 | 	for (i = 0; i <= tbl->hash_mask; i++) | 
 | 371 | 		hlist_for_each(p, &oldhash[i]) | 
| Pavel Emelyanov | 4caf86c | 2008-05-07 19:47:01 +0400 | [diff] [blame] | 372 | 			if (tbl->copy_node(p, newtbl) < 0) | 
 | 373 | 				goto errcopy; | 
| Luis Carlos Cobo | 2e3c873 | 2008-02-23 15:17:09 +0100 | [diff] [blame] | 374 |  | 
| Pavel Emelyanov | a3538b1 | 2008-05-07 19:55:59 +0400 | [diff] [blame] | 375 | 	return newtbl; | 
| Pavel Emelyanov | 4caf86c | 2008-05-07 19:47:01 +0400 | [diff] [blame] | 376 |  | 
 | 377 | errcopy: | 
 | 378 | 	for (i = 0; i <= newtbl->hash_mask; i++) { | 
 | 379 | 		hlist_for_each_safe(p, q, &newtbl->hash_buckets[i]) | 
 | 380 | 			tbl->free_node(p, 0); | 
 | 381 | 	} | 
| Julia Lawall | 667d8af | 2008-08-23 18:27:38 +0200 | [diff] [blame] | 382 | 	__mesh_table_free(newtbl); | 
| Pavel Emelyanov | a3538b1 | 2008-05-07 19:55:59 +0400 | [diff] [blame] | 383 | endgrow: | 
| Pavel Emelyanov | 4caf86c | 2008-05-07 19:47:01 +0400 | [diff] [blame] | 384 | 	return NULL; | 
| Luis Carlos Cobo | 2e3c873 | 2008-02-23 15:17:09 +0100 | [diff] [blame] | 385 | } | 
| Johannes Berg | 902acc7 | 2008-02-23 15:17:19 +0100 | [diff] [blame] | 386 |  | 
 | 387 | /** | 
 | 388 |  * ieee80211_new_mesh_header - create a new mesh header | 
 | 389 |  * @meshhdr:    uninitialized mesh header | 
 | 390 |  * @sdata:	mesh interface to be used | 
 | 391 |  * | 
 | 392 |  * Return the header length. | 
 | 393 |  */ | 
 | 394 | int ieee80211_new_mesh_header(struct ieee80211s_hdr *meshhdr, | 
 | 395 | 		struct ieee80211_sub_if_data *sdata) | 
 | 396 | { | 
 | 397 | 	meshhdr->flags = 0; | 
| Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 398 | 	meshhdr->ttl = sdata->u.mesh.mshcfg.dot11MeshTTL; | 
 | 399 | 	put_unaligned(cpu_to_le32(sdata->u.mesh.mesh_seqnum), &meshhdr->seqnum); | 
 | 400 | 	sdata->u.mesh.mesh_seqnum++; | 
| Johannes Berg | 902acc7 | 2008-02-23 15:17:19 +0100 | [diff] [blame] | 401 |  | 
| Luis Carlos Cobo | ef26925 | 2008-05-05 12:02:35 -0700 | [diff] [blame] | 402 | 	return 6; | 
| Johannes Berg | 902acc7 | 2008-02-23 15:17:19 +0100 | [diff] [blame] | 403 | } | 
 | 404 |  | 
| Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 405 | static void ieee80211_mesh_housekeeping(struct ieee80211_sub_if_data *sdata, | 
 | 406 | 			   struct ieee80211_if_mesh *ifmsh) | 
 | 407 | { | 
 | 408 | 	bool free_plinks; | 
 | 409 |  | 
 | 410 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG | 
 | 411 | 	printk(KERN_DEBUG "%s: running mesh housekeeping\n", | 
 | 412 | 	       sdata->dev->name); | 
 | 413 | #endif | 
 | 414 |  | 
 | 415 | 	ieee80211_sta_expire(sdata, IEEE80211_MESH_PEER_INACTIVITY_LIMIT); | 
 | 416 | 	mesh_path_expire(sdata); | 
 | 417 |  | 
 | 418 | 	free_plinks = mesh_plink_availables(sdata); | 
 | 419 | 	if (free_plinks != sdata->u.mesh.accepting_plinks) | 
| Johannes Berg | 2d0ddec | 2009-04-23 16:13:26 +0200 | [diff] [blame] | 420 | 		ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON); | 
| Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 421 |  | 
 | 422 | 	ifmsh->housekeeping = false; | 
 | 423 | 	mod_timer(&ifmsh->housekeeping_timer, | 
 | 424 | 		  round_jiffies(jiffies + IEEE80211_MESH_HOUSEKEEPING_INTERVAL)); | 
 | 425 | } | 
 | 426 |  | 
 | 427 |  | 
 | 428 | void ieee80211_start_mesh(struct ieee80211_sub_if_data *sdata) | 
 | 429 | { | 
 | 430 | 	struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; | 
 | 431 | 	struct ieee80211_local *local = sdata->local; | 
 | 432 |  | 
 | 433 | 	ifmsh->housekeeping = true; | 
 | 434 | 	queue_work(local->hw.workqueue, &ifmsh->work); | 
| Johannes Berg | 2d0ddec | 2009-04-23 16:13:26 +0200 | [diff] [blame] | 435 | 	ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON | | 
 | 436 | 						BSS_CHANGED_BEACON_ENABLED); | 
| Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 437 | } | 
 | 438 |  | 
 | 439 | void ieee80211_stop_mesh(struct ieee80211_sub_if_data *sdata) | 
 | 440 | { | 
 | 441 | 	del_timer_sync(&sdata->u.mesh.housekeeping_timer); | 
 | 442 | 	/* | 
| Johannes Berg | b741343 | 2008-09-11 00:01:50 +0200 | [diff] [blame] | 443 | 	 * If the timer fired while we waited for it, it will have | 
 | 444 | 	 * requeued the work. Now the work will be running again | 
 | 445 | 	 * but will not rearm the timer again because it checks | 
 | 446 | 	 * whether the interface is running, which, at this point, | 
 | 447 | 	 * it no longer is. | 
 | 448 | 	 */ | 
 | 449 | 	cancel_work_sync(&sdata->u.mesh.work); | 
 | 450 |  | 
 | 451 | 	/* | 
| Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 452 | 	 * When we get here, the interface is marked down. | 
 | 453 | 	 * Call synchronize_rcu() to wait for the RX path | 
 | 454 | 	 * should it be using the interface and enqueuing | 
 | 455 | 	 * frames at this very time on another CPU. | 
 | 456 | 	 */ | 
 | 457 | 	synchronize_rcu(); | 
 | 458 | 	skb_queue_purge(&sdata->u.mesh.skb_queue); | 
 | 459 | } | 
 | 460 |  | 
 | 461 | static void ieee80211_mesh_rx_bcn_presp(struct ieee80211_sub_if_data *sdata, | 
 | 462 | 					u16 stype, | 
 | 463 | 					struct ieee80211_mgmt *mgmt, | 
 | 464 | 					size_t len, | 
 | 465 | 					struct ieee80211_rx_status *rx_status) | 
 | 466 | { | 
| Johannes Berg | c6a1fa1 | 2008-10-07 12:04:32 +0200 | [diff] [blame] | 467 | 	struct ieee80211_local *local = sdata->local; | 
| Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 468 | 	struct ieee802_11_elems elems; | 
 | 469 | 	struct ieee80211_channel *channel; | 
| Johannes Berg | 881d948 | 2009-01-21 15:13:48 +0100 | [diff] [blame] | 470 | 	u32 supp_rates = 0; | 
| Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 471 | 	size_t baselen; | 
 | 472 | 	int freq; | 
 | 473 | 	enum ieee80211_band band = rx_status->band; | 
 | 474 |  | 
 | 475 | 	/* ignore ProbeResp to foreign address */ | 
 | 476 | 	if (stype == IEEE80211_STYPE_PROBE_RESP && | 
 | 477 | 	    compare_ether_addr(mgmt->da, sdata->dev->dev_addr)) | 
 | 478 | 		return; | 
 | 479 |  | 
 | 480 | 	baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt; | 
 | 481 | 	if (baselen > len) | 
 | 482 | 		return; | 
 | 483 |  | 
 | 484 | 	ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen, | 
 | 485 | 			       &elems); | 
 | 486 |  | 
 | 487 | 	if (elems.ds_params && elems.ds_params_len == 1) | 
 | 488 | 		freq = ieee80211_channel_to_frequency(elems.ds_params[0]); | 
 | 489 | 	else | 
 | 490 | 		freq = rx_status->freq; | 
 | 491 |  | 
 | 492 | 	channel = ieee80211_get_channel(local->hw.wiphy, freq); | 
 | 493 |  | 
 | 494 | 	if (!channel || channel->flags & IEEE80211_CHAN_DISABLED) | 
 | 495 | 		return; | 
 | 496 |  | 
 | 497 | 	if (elems.mesh_id && elems.mesh_config && | 
 | 498 | 	    mesh_matches_local(&elems, sdata)) { | 
 | 499 | 		supp_rates = ieee80211_sta_get_rates(local, &elems, band); | 
 | 500 |  | 
 | 501 | 		mesh_neighbour_update(mgmt->sa, supp_rates, sdata, | 
 | 502 | 				      mesh_peer_accepts_plinks(&elems)); | 
 | 503 | 	} | 
 | 504 | } | 
 | 505 |  | 
 | 506 | static void ieee80211_mesh_rx_mgmt_action(struct ieee80211_sub_if_data *sdata, | 
 | 507 | 					  struct ieee80211_mgmt *mgmt, | 
 | 508 | 					  size_t len, | 
 | 509 | 					  struct ieee80211_rx_status *rx_status) | 
 | 510 | { | 
 | 511 | 	switch (mgmt->u.action.category) { | 
 | 512 | 	case PLINK_CATEGORY: | 
 | 513 | 		mesh_rx_plink_frame(sdata, mgmt, len, rx_status); | 
 | 514 | 		break; | 
 | 515 | 	case MESH_PATH_SEL_CATEGORY: | 
 | 516 | 		mesh_rx_path_sel_frame(sdata, mgmt, len); | 
 | 517 | 		break; | 
 | 518 | 	} | 
 | 519 | } | 
 | 520 |  | 
 | 521 | static void ieee80211_mesh_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata, | 
 | 522 | 					  struct sk_buff *skb) | 
 | 523 | { | 
 | 524 | 	struct ieee80211_rx_status *rx_status; | 
 | 525 | 	struct ieee80211_if_mesh *ifmsh; | 
 | 526 | 	struct ieee80211_mgmt *mgmt; | 
 | 527 | 	u16 stype; | 
 | 528 |  | 
 | 529 | 	ifmsh = &sdata->u.mesh; | 
 | 530 |  | 
 | 531 | 	rx_status = (struct ieee80211_rx_status *) skb->cb; | 
 | 532 | 	mgmt = (struct ieee80211_mgmt *) skb->data; | 
 | 533 | 	stype = le16_to_cpu(mgmt->frame_control) & IEEE80211_FCTL_STYPE; | 
 | 534 |  | 
 | 535 | 	switch (stype) { | 
 | 536 | 	case IEEE80211_STYPE_PROBE_RESP: | 
 | 537 | 	case IEEE80211_STYPE_BEACON: | 
 | 538 | 		ieee80211_mesh_rx_bcn_presp(sdata, stype, mgmt, skb->len, | 
 | 539 | 					    rx_status); | 
 | 540 | 		break; | 
 | 541 | 	case IEEE80211_STYPE_ACTION: | 
 | 542 | 		ieee80211_mesh_rx_mgmt_action(sdata, mgmt, skb->len, rx_status); | 
 | 543 | 		break; | 
 | 544 | 	} | 
 | 545 |  | 
 | 546 | 	kfree_skb(skb); | 
 | 547 | } | 
 | 548 |  | 
 | 549 | static void ieee80211_mesh_work(struct work_struct *work) | 
 | 550 | { | 
 | 551 | 	struct ieee80211_sub_if_data *sdata = | 
 | 552 | 		container_of(work, struct ieee80211_sub_if_data, u.mesh.work); | 
 | 553 | 	struct ieee80211_local *local = sdata->local; | 
 | 554 | 	struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; | 
 | 555 | 	struct sk_buff *skb; | 
 | 556 |  | 
 | 557 | 	if (!netif_running(sdata->dev)) | 
 | 558 | 		return; | 
 | 559 |  | 
| Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 560 | 	if (local->sw_scanning || local->hw_scanning) | 
| Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 561 | 		return; | 
 | 562 |  | 
 | 563 | 	while ((skb = skb_dequeue(&ifmsh->skb_queue))) | 
 | 564 | 		ieee80211_mesh_rx_queued_mgmt(sdata, skb); | 
 | 565 |  | 
 | 566 | 	if (ifmsh->preq_queue_len && | 
 | 567 | 	    time_after(jiffies, | 
 | 568 | 		       ifmsh->last_preq + msecs_to_jiffies(ifmsh->mshcfg.dot11MeshHWMPpreqMinInterval))) | 
 | 569 | 		mesh_path_start_discovery(sdata); | 
 | 570 |  | 
 | 571 | 	if (ifmsh->housekeeping) | 
 | 572 | 		ieee80211_mesh_housekeeping(sdata, ifmsh); | 
 | 573 | } | 
 | 574 |  | 
 | 575 | void ieee80211_mesh_notify_scan_completed(struct ieee80211_local *local) | 
 | 576 | { | 
 | 577 | 	struct ieee80211_sub_if_data *sdata; | 
 | 578 |  | 
 | 579 | 	rcu_read_lock(); | 
 | 580 | 	list_for_each_entry_rcu(sdata, &local->interfaces, list) | 
 | 581 | 		if (ieee80211_vif_is_mesh(&sdata->vif)) | 
 | 582 | 			queue_work(local->hw.workqueue, &sdata->u.mesh.work); | 
 | 583 | 	rcu_read_unlock(); | 
 | 584 | } | 
 | 585 |  | 
| Johannes Berg | 902acc7 | 2008-02-23 15:17:19 +0100 | [diff] [blame] | 586 | void ieee80211_mesh_init_sdata(struct ieee80211_sub_if_data *sdata) | 
 | 587 | { | 
| Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 588 | 	struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; | 
| Johannes Berg | 902acc7 | 2008-02-23 15:17:19 +0100 | [diff] [blame] | 589 |  | 
| Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 590 | 	INIT_WORK(&ifmsh->work, ieee80211_mesh_work); | 
 | 591 | 	setup_timer(&ifmsh->housekeeping_timer, | 
 | 592 | 		    ieee80211_mesh_housekeeping_timer, | 
 | 593 | 		    (unsigned long) sdata); | 
 | 594 | 	skb_queue_head_init(&sdata->u.mesh.skb_queue); | 
 | 595 |  | 
 | 596 | 	ifmsh->mshcfg.dot11MeshRetryTimeout = MESH_RET_T; | 
 | 597 | 	ifmsh->mshcfg.dot11MeshConfirmTimeout = MESH_CONF_T; | 
 | 598 | 	ifmsh->mshcfg.dot11MeshHoldingTimeout = MESH_HOLD_T; | 
 | 599 | 	ifmsh->mshcfg.dot11MeshMaxRetries = MESH_MAX_RETR; | 
 | 600 | 	ifmsh->mshcfg.dot11MeshTTL = MESH_TTL; | 
 | 601 | 	ifmsh->mshcfg.auto_open_plinks = true; | 
 | 602 | 	ifmsh->mshcfg.dot11MeshMaxPeerLinks = | 
| Johannes Berg | 902acc7 | 2008-02-23 15:17:19 +0100 | [diff] [blame] | 603 | 		MESH_MAX_ESTAB_PLINKS; | 
| Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 604 | 	ifmsh->mshcfg.dot11MeshHWMPactivePathTimeout = | 
| Johannes Berg | 902acc7 | 2008-02-23 15:17:19 +0100 | [diff] [blame] | 605 | 		MESH_PATH_TIMEOUT; | 
| Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 606 | 	ifmsh->mshcfg.dot11MeshHWMPpreqMinInterval = | 
| Johannes Berg | 902acc7 | 2008-02-23 15:17:19 +0100 | [diff] [blame] | 607 | 		MESH_PREQ_MIN_INT; | 
| Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 608 | 	ifmsh->mshcfg.dot11MeshHWMPnetDiameterTraversalTime = | 
| Johannes Berg | 902acc7 | 2008-02-23 15:17:19 +0100 | [diff] [blame] | 609 | 		MESH_DIAM_TRAVERSAL_TIME; | 
| Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 610 | 	ifmsh->mshcfg.dot11MeshHWMPmaxPREQretries = | 
| Johannes Berg | 902acc7 | 2008-02-23 15:17:19 +0100 | [diff] [blame] | 611 | 		MESH_MAX_PREQ_RETRIES; | 
| Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 612 | 	ifmsh->mshcfg.path_refresh_time = | 
| Johannes Berg | 902acc7 | 2008-02-23 15:17:19 +0100 | [diff] [blame] | 613 | 		MESH_PATH_REFRESH_TIME; | 
| Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 614 | 	ifmsh->mshcfg.min_discovery_timeout = | 
| Johannes Berg | 902acc7 | 2008-02-23 15:17:19 +0100 | [diff] [blame] | 615 | 		MESH_MIN_DISCOVERY_TIMEOUT; | 
| Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 616 | 	ifmsh->accepting_plinks = true; | 
 | 617 | 	ifmsh->preq_id = 0; | 
 | 618 | 	ifmsh->dsn = 0; | 
 | 619 | 	atomic_set(&ifmsh->mpaths, 0); | 
| Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 620 | 	mesh_rmc_init(sdata); | 
| Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 621 | 	ifmsh->last_preq = jiffies; | 
| Johannes Berg | 902acc7 | 2008-02-23 15:17:19 +0100 | [diff] [blame] | 622 | 	/* Allocate all mesh structures when creating the first mesh interface. */ | 
 | 623 | 	if (!mesh_allocated) | 
 | 624 | 		ieee80211s_init(); | 
| Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 625 | 	mesh_ids_set_default(ifmsh); | 
 | 626 | 	setup_timer(&ifmsh->mesh_path_timer, | 
| Johannes Berg | 902acc7 | 2008-02-23 15:17:19 +0100 | [diff] [blame] | 627 | 		    ieee80211_mesh_path_timer, | 
 | 628 | 		    (unsigned long) sdata); | 
| Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 629 | 	INIT_LIST_HEAD(&ifmsh->preq_queue.list); | 
 | 630 | 	spin_lock_init(&ifmsh->mesh_preq_queue_lock); | 
 | 631 | } | 
 | 632 |  | 
 | 633 | ieee80211_rx_result | 
 | 634 | ieee80211_mesh_rx_mgmt(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb, | 
 | 635 | 		       struct ieee80211_rx_status *rx_status) | 
 | 636 | { | 
 | 637 | 	struct ieee80211_local *local = sdata->local; | 
 | 638 | 	struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; | 
 | 639 | 	struct ieee80211_mgmt *mgmt; | 
 | 640 | 	u16 fc; | 
 | 641 |  | 
 | 642 | 	if (skb->len < 24) | 
 | 643 | 		return RX_DROP_MONITOR; | 
 | 644 |  | 
 | 645 | 	mgmt = (struct ieee80211_mgmt *) skb->data; | 
 | 646 | 	fc = le16_to_cpu(mgmt->frame_control); | 
 | 647 |  | 
 | 648 | 	switch (fc & IEEE80211_FCTL_STYPE) { | 
 | 649 | 	case IEEE80211_STYPE_PROBE_RESP: | 
 | 650 | 	case IEEE80211_STYPE_BEACON: | 
 | 651 | 	case IEEE80211_STYPE_ACTION: | 
 | 652 | 		memcpy(skb->cb, rx_status, sizeof(*rx_status)); | 
 | 653 | 		skb_queue_tail(&ifmsh->skb_queue, skb); | 
 | 654 | 		queue_work(local->hw.workqueue, &ifmsh->work); | 
 | 655 | 		return RX_QUEUED; | 
 | 656 | 	} | 
 | 657 |  | 
 | 658 | 	return RX_CONTINUE; | 
| Johannes Berg | 902acc7 | 2008-02-23 15:17:19 +0100 | [diff] [blame] | 659 | } |