[6319] | 1 | /** @file wlan_mac_packet_types.c |
---|
| 2 | * @brief Packet Constructors |
---|
| 3 | * |
---|
| 4 | * This contains code for constructing a variety of different types of MPDUs. |
---|
| 5 | * |
---|
| 6 | * @copyright Copyright 2013-2019, Mango Communications. All rights reserved. |
---|
| 7 | * Distributed under the Mango Communications Reference Design License |
---|
| 8 | * See LICENSE.txt included in the design archive or |
---|
| 9 | * at http://mangocomm.com/802.11/license |
---|
| 10 | * |
---|
| 11 | * This file is part of the Mango 802.11 Reference Design (https://mangocomm.com/802.11) |
---|
| 12 | */ |
---|
| 13 | |
---|
| 14 | #include "wlan_mac_high_sw_config.h" |
---|
| 15 | |
---|
| 16 | // Xilinx SDK includes |
---|
| 17 | #include "stdio.h" |
---|
| 18 | #include "stdlib.h" |
---|
| 19 | #include "string.h" |
---|
| 20 | #include "xil_types.h" |
---|
| 21 | |
---|
| 22 | // WLAN includes |
---|
| 23 | #include "wlan_mac_high.h" |
---|
| 24 | #include "wlan_mac_802_11_defs.h" |
---|
| 25 | #include "wlan_mac_mgmt_tags.h" |
---|
| 26 | #include "wlan_mac_network_info.h" |
---|
| 27 | #include "wlan_mac_packet_types.h" |
---|
| 28 | #include "wlan_mac_common.h" |
---|
| 29 | |
---|
| 30 | |
---|
| 31 | int wlan_create_beacon_probe_resp_frame(u8* pkt, |
---|
| 32 | u8* addr1, |
---|
| 33 | u8* addr2, |
---|
| 34 | u8* addr3, |
---|
| 35 | u8 frame_control_1, |
---|
| 36 | network_info_t* network_info) { |
---|
| 37 | |
---|
| 38 | ht_capabilities* ht_capabilities_element; |
---|
| 39 | ht_information* ht_information_element; |
---|
| 40 | wmm_parameter_t* wmm_parameter; |
---|
| 41 | |
---|
| 42 | //void* pkt_buf,mac_header_80211_common* common, u16 beacon_interval, u16 capabilities, u8 ssid_len, u8* ssid, u8 chan |
---|
| 43 | |
---|
| 44 | u32 packetLen_bytes; |
---|
| 45 | mgmt_tag_template_t* mgmt_tag_template; |
---|
| 46 | |
---|
| 47 | u8 real_ssid_len = WLAN_MIN(strlen(network_info->bss_config.ssid), SSID_LEN_MAX); |
---|
| 48 | |
---|
| 49 | mac_header_80211* mac_header; |
---|
| 50 | mac_header = (mac_header_80211*)(pkt); |
---|
| 51 | |
---|
| 52 | mac_header->frame_control_1 = frame_control_1; |
---|
| 53 | mac_header->frame_control_2 = 0; |
---|
| 54 | |
---|
| 55 | //This field may be overwritten by CPU_LOW |
---|
| 56 | mac_header->duration_id = 0; |
---|
| 57 | |
---|
| 58 | mac_header->sequence_control = 0; //Will be filled in at dequeue |
---|
| 59 | |
---|
| 60 | memcpy(mac_header->address_1, addr1, MAC_ADDR_LEN); |
---|
| 61 | memcpy(mac_header->address_2, addr2, MAC_ADDR_LEN); |
---|
| 62 | memcpy(mac_header->address_3, addr3, MAC_ADDR_LEN); |
---|
| 63 | |
---|
| 64 | beacon_probe_frame* beacon_probe_mgmt_header; |
---|
| 65 | beacon_probe_mgmt_header = (beacon_probe_frame*)(pkt + sizeof(mac_header_80211)); |
---|
| 66 | |
---|
| 67 | //This field may be overwritten by CPU_LOW |
---|
| 68 | beacon_probe_mgmt_header->timestamp = 0; |
---|
| 69 | |
---|
| 70 | beacon_probe_mgmt_header->beacon_interval = network_info->bss_config.beacon_interval; |
---|
| 71 | beacon_probe_mgmt_header->capabilities = ((network_info->capabilities & BSS_CAPABILITIES_BEACON_MASK) | CAPABILITIES_SHORT_TIMESLOT); |
---|
| 72 | |
---|
| 73 | mgmt_tag_template = (mgmt_tag_template_t*)( pkt + sizeof(mac_header_80211) + sizeof(beacon_probe_frame)); |
---|
| 74 | |
---|
| 75 | |
---|
| 76 | mgmt_tag_template->header.tag_element_id = MGMT_TAG_SSID; |
---|
| 77 | mgmt_tag_template->header.tag_length = real_ssid_len; |
---|
| 78 | memcpy((void *)(mgmt_tag_template->data),network_info->bss_config.ssid,real_ssid_len); |
---|
| 79 | mgmt_tag_template = (void*)mgmt_tag_template + ( mgmt_tag_template->header.tag_length + sizeof(mgmt_tag_header) ); //Advance tag template forward |
---|
| 80 | |
---|
| 81 | //Top bit is whether or not the rate is mandatory (basic). Bottom 7 bits is in units of "number of 500kbps" |
---|
| 82 | mgmt_tag_template->header.tag_element_id = MGMT_TAG_SUPPORTED_RATES; |
---|
| 83 | mgmt_tag_template->header.tag_length = 8; |
---|
| 84 | mgmt_tag_template->data[0] = RATE_BASIC | (0x0C); //6Mbps (BPSK, 1/2) |
---|
| 85 | mgmt_tag_template->data[1] = (0x12); //9Mbps (BPSK, 3/4) |
---|
| 86 | mgmt_tag_template->data[2] = RATE_BASIC | (0x18); //12Mbps (QPSK, 1/2) |
---|
| 87 | mgmt_tag_template->data[3] = (0x24); //18Mbps (QPSK, 3/4) |
---|
| 88 | mgmt_tag_template->data[4] = RATE_BASIC | (0x30); //24Mbps (16-QAM, 1/2) |
---|
| 89 | mgmt_tag_template->data[5] = (0x48); //36Mbps (16-QAM, 3/4) |
---|
| 90 | mgmt_tag_template->data[6] = (0x60); //48Mbps (64-QAM, 2/3) |
---|
| 91 | mgmt_tag_template->data[7] = (0x6C); //54Mbps (64-QAM, 3/4) |
---|
| 92 | mgmt_tag_template = (void*)mgmt_tag_template + ( mgmt_tag_template->header.tag_length + sizeof(mgmt_tag_header) ); //Advance tag template forward |
---|
| 93 | |
---|
| 94 | if (network_info->bss_config.ht_capable) { |
---|
| 95 | //Insert HT Capabilities and HT Information tags |
---|
| 96 | mgmt_tag_template->header.tag_element_id = MGMT_TAG_HT_CAPABILITIES; |
---|
| 97 | mgmt_tag_template->header.tag_length = 26; |
---|
| 98 | |
---|
| 99 | ht_capabilities_element = (ht_capabilities*)mgmt_tag_template->data; |
---|
| 100 | ht_capabilities_element->ht_capabilities_info = 0x000c; |
---|
| 101 | ht_capabilities_element->a_mpdu_parameters = 0x00; |
---|
| 102 | ht_capabilities_element->rx_supported_mcs[0] = 0x000000ff; |
---|
| 103 | ht_capabilities_element->rx_supported_mcs[1] = 0x00000000; |
---|
| 104 | ht_capabilities_element->rx_supported_mcs[2] = 0x00000000; |
---|
| 105 | ht_capabilities_element->rx_supported_mcs[3] = 0x00000000; |
---|
| 106 | ht_capabilities_element->ht_extended_capabilities = 0x0000; |
---|
| 107 | ht_capabilities_element->tx_beamforming = 0x0000; |
---|
| 108 | ht_capabilities_element->ant_sel = 0x00; |
---|
| 109 | |
---|
| 110 | mgmt_tag_template = (void*)mgmt_tag_template + ( mgmt_tag_template->header.tag_length + sizeof(mgmt_tag_header) ); //Advance tag template forward |
---|
| 111 | |
---|
| 112 | mgmt_tag_template->header.tag_element_id = MGMT_TAG_HT_OPERATION; |
---|
| 113 | mgmt_tag_template->header.tag_length = 22; |
---|
| 114 | |
---|
| 115 | ht_information_element = (ht_information*)mgmt_tag_template->data; |
---|
| 116 | ht_information_element->channel = wlan_mac_high_bss_channel_spec_to_radio_chan(network_info->bss_config.chan_spec); |
---|
| 117 | ht_information_element->ht_info_subset_1 = 0x00; //only HT20 currently supported |
---|
| 118 | ht_information_element->ht_info_subset_2 = 0x0004; //One or more STAs are not greenfield compatible |
---|
| 119 | ht_information_element->ht_info_subset_3 = 0x0000; |
---|
| 120 | ht_information_element->rx_supported_mcs[0] = 0x00000000; |
---|
| 121 | ht_information_element->rx_supported_mcs[1] = 0x00000000; |
---|
| 122 | ht_information_element->rx_supported_mcs[2] = 0x00000000; |
---|
| 123 | ht_information_element->rx_supported_mcs[3] = 0x00000000; |
---|
| 124 | |
---|
| 125 | mgmt_tag_template = (void*)mgmt_tag_template + ( mgmt_tag_template->header.tag_length + sizeof(mgmt_tag_header) ); //Advance tag template forward |
---|
| 126 | } |
---|
| 127 | |
---|
| 128 | mgmt_tag_template->header.tag_element_id = MGMT_TAG_ERP; |
---|
| 129 | mgmt_tag_template->header.tag_length = 1; |
---|
| 130 | mgmt_tag_template->data[0] = 0; //Non ERP Present - not set, don't use protection, no barker preamble mode |
---|
| 131 | mgmt_tag_template = (void*)mgmt_tag_template + ( mgmt_tag_template->header.tag_length + sizeof(mgmt_tag_header) ); //Advance tag template forward |
---|
| 132 | |
---|
| 133 | if (network_info->bss_config.ht_capable) { |
---|
| 134 | //Insert WMM tag |
---|
| 135 | mgmt_tag_template->header.tag_element_id = MGMT_TAG_VENDOR_SPECIFIC; |
---|
| 136 | mgmt_tag_template->header.tag_length = 24; |
---|
| 137 | |
---|
| 138 | wmm_parameter = (wmm_parameter_t*)mgmt_tag_template->data; |
---|
| 139 | wmm_parameter->oui[0] = 0x00; |
---|
| 140 | wmm_parameter->oui[1] = 0x50; |
---|
| 141 | wmm_parameter->oui[2] = 0xf2; |
---|
| 142 | wmm_parameter->vendor_specific_oui_type = 2; |
---|
| 143 | wmm_parameter->wme_subtype = 1; |
---|
| 144 | wmm_parameter->wme_version = 1; |
---|
| 145 | wmm_parameter->wme_qos_info = 0x08; |
---|
| 146 | wmm_parameter->reserved = 0; |
---|
| 147 | wmm_parameter->aci0 = Xil_Htonl(0x03a40000); |
---|
| 148 | wmm_parameter->aci1 = Xil_Htonl(0x27a40000); |
---|
| 149 | wmm_parameter->aci2 = Xil_Htonl(0x42430000); |
---|
| 150 | wmm_parameter->aci3 = Xil_Htonl(0x62320000); |
---|
| 151 | |
---|
| 152 | mgmt_tag_template = (void*)mgmt_tag_template + ( mgmt_tag_template->header.tag_length + sizeof(mgmt_tag_header) ); //Advance tag template forward |
---|
| 153 | } |
---|
| 154 | |
---|
| 155 | packetLen_bytes = ((u8*)mgmt_tag_template - pkt) + WLAN_PHY_FCS_NBYTES; |
---|
| 156 | |
---|
| 157 | return packetLen_bytes; |
---|
| 158 | |
---|
| 159 | } |
---|
| 160 | |
---|
| 161 | |
---|
| 162 | |
---|
| 163 | int wlan_create_probe_req_frame(u8* pkt, |
---|
| 164 | u8* addr1, |
---|
| 165 | u8* addr2, |
---|
| 166 | u8* addr3, |
---|
| 167 | char* ssid){ |
---|
| 168 | u32 packetLen_bytes; |
---|
| 169 | u8* txBufferPtr_u8; |
---|
| 170 | u8 real_ssid_len = WLAN_MIN(strlen(ssid), SSID_LEN_MAX); |
---|
| 171 | |
---|
| 172 | mac_header_80211* probe_req_80211_header; |
---|
| 173 | |
---|
| 174 | if( pkt == NULL ) return WLAN_FAILURE; |
---|
| 175 | |
---|
| 176 | probe_req_80211_header = (mac_header_80211*)(pkt); |
---|
| 177 | |
---|
| 178 | probe_req_80211_header->frame_control_1 = MAC_FRAME_CTRL1_SUBTYPE_PROBE_REQ; |
---|
| 179 | probe_req_80211_header->frame_control_2 = 0; |
---|
| 180 | |
---|
| 181 | //This field may be overwritten by CPU_LOW |
---|
| 182 | probe_req_80211_header->duration_id = 0; |
---|
| 183 | |
---|
| 184 | memcpy(probe_req_80211_header->address_1, addr1, MAC_ADDR_LEN); |
---|
| 185 | memcpy(probe_req_80211_header->address_2, addr2, MAC_ADDR_LEN); |
---|
| 186 | memcpy(probe_req_80211_header->address_3, addr3, MAC_ADDR_LEN); |
---|
| 187 | |
---|
| 188 | probe_req_80211_header->sequence_control = 0; //Will be filled in at dequeue |
---|
| 189 | |
---|
| 190 | txBufferPtr_u8 = (u8*)((u8*)(pkt) + sizeof(mac_header_80211)); |
---|
| 191 | txBufferPtr_u8[0] = 0; //Tag 0: SSID parameter set |
---|
| 192 | txBufferPtr_u8[1] = real_ssid_len; |
---|
| 193 | memcpy((void *)(&(txBufferPtr_u8[2])),(void *)(&ssid[0]),real_ssid_len); |
---|
| 194 | |
---|
| 195 | txBufferPtr_u8+=(real_ssid_len+2); //Move up to next tag |
---|
| 196 | |
---|
| 197 | //http://my.safaribooksonline.com/book/networking/wireless/0596100523/4dot-802dot11-framing-in-detail/wireless802dot112-chp-4-sect-3 |
---|
| 198 | //Top bit is whether or not the rate is mandatory (basic). Bottom 7 bits is in units of "number of 500kbps" |
---|
| 199 | txBufferPtr_u8[0] = 1; //Tag 1: Supported Rates |
---|
| 200 | txBufferPtr_u8[1] = 8; //tag length... doesn't include the tag itself and the tag length |
---|
| 201 | txBufferPtr_u8[2] = (0x0C); //6Mbps (BPSK, 1/2) |
---|
| 202 | txBufferPtr_u8[3] = (0x12); //9Mbps (BPSK, 3/4) |
---|
| 203 | txBufferPtr_u8[4] = (0x18); //12Mbps (QPSK, 1/2) |
---|
| 204 | txBufferPtr_u8[5] = (0x24); //18Mbps (QPSK, 3/4) |
---|
| 205 | txBufferPtr_u8[6] = (0x30); //24Mbps (16-QAM, 1/2) |
---|
| 206 | txBufferPtr_u8[7] = (0x48); //36Mbps (16-QAM, 3/4) |
---|
| 207 | txBufferPtr_u8[8] = (0x60); //48Mbps (64-QAM, 2/3) |
---|
| 208 | txBufferPtr_u8[9] = (0x6C); //54Mbps (64-QAM, 3/4) |
---|
| 209 | txBufferPtr_u8+=(8+2); //Move up to next tag |
---|
| 210 | |
---|
| 211 | packetLen_bytes = (txBufferPtr_u8 - pkt) + WLAN_PHY_FCS_NBYTES; |
---|
| 212 | |
---|
| 213 | return packetLen_bytes; |
---|
| 214 | } |
---|
| 215 | |
---|
| 216 | int wlan_create_auth_frame(u8* pkt, |
---|
| 217 | u8* addr1, |
---|
| 218 | u8* addr2, |
---|
| 219 | u8* addr3, |
---|
| 220 | u16 auth_algorithm, |
---|
| 221 | u16 auth_seq, |
---|
| 222 | u16 status_code){ |
---|
| 223 | u32 packetLen_bytes; |
---|
| 224 | mac_header_80211* auth_80211_header; |
---|
| 225 | |
---|
| 226 | if(pkt == NULL) return WLAN_FAILURE; |
---|
| 227 | |
---|
| 228 | auth_80211_header = (mac_header_80211*)(pkt); |
---|
| 229 | |
---|
| 230 | auth_80211_header->frame_control_1 = MAC_FRAME_CTRL1_SUBTYPE_AUTH; |
---|
| 231 | auth_80211_header->frame_control_2 = 0; |
---|
| 232 | |
---|
| 233 | //duration can be filled in by CPU_LOW |
---|
| 234 | auth_80211_header->duration_id = 0; |
---|
| 235 | memcpy(auth_80211_header->address_1, addr1, MAC_ADDR_LEN); |
---|
| 236 | memcpy(auth_80211_header->address_2, addr2, MAC_ADDR_LEN); |
---|
| 237 | memcpy(auth_80211_header->address_3, addr3, MAC_ADDR_LEN); |
---|
| 238 | |
---|
| 239 | auth_80211_header->sequence_control = 0; //Will be filled in at dequeue |
---|
| 240 | |
---|
| 241 | authentication_frame* auth_mgmt_header; |
---|
| 242 | auth_mgmt_header = (authentication_frame*)(pkt + sizeof(mac_header_80211)); |
---|
| 243 | auth_mgmt_header->auth_algorithm = auth_algorithm; |
---|
| 244 | auth_mgmt_header->auth_sequence = auth_seq; |
---|
| 245 | auth_mgmt_header->status_code = status_code; |
---|
| 246 | |
---|
| 247 | packetLen_bytes = sizeof(mac_header_80211) + sizeof(authentication_frame) + WLAN_PHY_FCS_NBYTES; |
---|
| 248 | |
---|
| 249 | return packetLen_bytes; |
---|
| 250 | } |
---|
| 251 | |
---|
| 252 | |
---|
| 253 | |
---|
| 254 | int wlan_create_deauth_disassoc_frame(u8* pkt, |
---|
| 255 | u8* addr1, |
---|
| 256 | u8* addr2, |
---|
| 257 | u8* addr3, |
---|
| 258 | u8 frame_control_1, |
---|
| 259 | u16 reason_code){ |
---|
| 260 | u32 packetLen_bytes; |
---|
| 261 | mac_header_80211* deauth_80211_header; |
---|
| 262 | |
---|
| 263 | if( pkt == NULL ) return WLAN_FAILURE; |
---|
| 264 | |
---|
| 265 | deauth_80211_header = (mac_header_80211*)(pkt); |
---|
| 266 | |
---|
| 267 | deauth_80211_header->frame_control_1 = frame_control_1; |
---|
| 268 | deauth_80211_header->frame_control_2 = 0; |
---|
| 269 | |
---|
| 270 | //duration can be filled in by CPU_LOW |
---|
| 271 | deauth_80211_header->duration_id = 0; |
---|
| 272 | memcpy(deauth_80211_header->address_1, addr1, MAC_ADDR_LEN); |
---|
| 273 | memcpy(deauth_80211_header->address_2, addr2, MAC_ADDR_LEN); |
---|
| 274 | memcpy(deauth_80211_header->address_3, addr3, MAC_ADDR_LEN); |
---|
| 275 | |
---|
| 276 | deauth_80211_header->sequence_control = 0; //Will be filled in at dequeue |
---|
| 277 | |
---|
| 278 | deauthentication_frame* deauth_mgmt_header; |
---|
| 279 | deauth_mgmt_header = (deauthentication_frame*)(pkt + sizeof(mac_header_80211)); |
---|
| 280 | deauth_mgmt_header->reason_code = reason_code; |
---|
| 281 | |
---|
| 282 | packetLen_bytes = sizeof(mac_header_80211) + sizeof(deauthentication_frame) + WLAN_PHY_FCS_NBYTES; |
---|
| 283 | |
---|
| 284 | return packetLen_bytes; |
---|
| 285 | } |
---|
| 286 | |
---|
| 287 | |
---|
| 288 | |
---|
| 289 | int wlan_create_reassoc_assoc_req_frame(u8* pkt, |
---|
| 290 | u8* addr1, |
---|
| 291 | u8* addr2, |
---|
| 292 | u8* addr3, |
---|
| 293 | u8 frame_control_1, |
---|
| 294 | network_info_t* network_info){ |
---|
| 295 | u32 packetLen_bytes; |
---|
| 296 | |
---|
| 297 | ht_capabilities* ht_capabilities_element; |
---|
| 298 | ht_information* ht_information_element; |
---|
| 299 | |
---|
| 300 | u8 real_ssid_len = WLAN_MIN(strlen(network_info->bss_config.ssid), SSID_LEN_MAX); |
---|
| 301 | mgmt_tag_template_t* mgmt_tag_template; |
---|
| 302 | |
---|
| 303 | if( pkt == NULL ) return WLAN_FAILURE; |
---|
| 304 | |
---|
| 305 | mac_header_80211* assoc_80211_header; |
---|
| 306 | assoc_80211_header = (mac_header_80211*)(pkt); |
---|
| 307 | |
---|
| 308 | assoc_80211_header->frame_control_1 = frame_control_1; |
---|
| 309 | assoc_80211_header->frame_control_2 = 0; |
---|
| 310 | //duration can be filled in by CPU_LOW |
---|
| 311 | assoc_80211_header->duration_id = 0; |
---|
| 312 | |
---|
| 313 | memcpy(assoc_80211_header->address_1, addr1, MAC_ADDR_LEN); |
---|
| 314 | memcpy(assoc_80211_header->address_2, addr2, MAC_ADDR_LEN); |
---|
| 315 | memcpy(assoc_80211_header->address_3, addr3, MAC_ADDR_LEN); |
---|
| 316 | |
---|
| 317 | assoc_80211_header->sequence_control = 0; //Will be filled in at dequeue |
---|
| 318 | |
---|
| 319 | association_request_frame* association_req_mgmt_header; |
---|
| 320 | association_req_mgmt_header = (association_request_frame*)(pkt + sizeof(mac_header_80211)); |
---|
| 321 | association_req_mgmt_header->capabilities = (CAPABILITIES_ESS | CAPABILITIES_SHORT_TIMESLOT | CAPABILITIES_SHORT_PREAMBLE); |
---|
| 322 | |
---|
| 323 | //This value is defined in 802.11-2012 in 8.4.1.6 and tells the AP how many beacon intervals |
---|
| 324 | //this station intends to doze before waking. In our implementation we hardcode this to 1 |
---|
| 325 | //to represent that we will be awake at every beacon target time. |
---|
| 326 | association_req_mgmt_header->listen_interval = 0x0001; |
---|
| 327 | |
---|
| 328 | mgmt_tag_template = (mgmt_tag_template_t *)( pkt + sizeof(mac_header_80211) + sizeof(association_request_frame) ); |
---|
| 329 | |
---|
| 330 | |
---|
| 331 | mgmt_tag_template->header.tag_element_id = MGMT_TAG_SSID; |
---|
| 332 | mgmt_tag_template->header.tag_length = real_ssid_len; |
---|
| 333 | memcpy((void *)(mgmt_tag_template->data),network_info->bss_config.ssid,real_ssid_len); |
---|
| 334 | mgmt_tag_template = (void*)mgmt_tag_template + ( mgmt_tag_template->header.tag_length + sizeof(mgmt_tag_header) ); //Advance tag template forward |
---|
| 335 | |
---|
| 336 | //Top bit is whether or not the rate is mandatory (basic). Bottom 7 bits is in units of "number of 500kbps" |
---|
| 337 | //Note: these parameters are spoofed. The 802.11 Reference Design does not support the 802.11b rates (with the exception |
---|
| 338 | //of Rx of DSSS 1Mbps). However, most commercial APs will decline a STA from joining if they don't advertise support |
---|
| 339 | //for the nominal set of 802.11b basic rates. |
---|
| 340 | mgmt_tag_template->header.tag_element_id = MGMT_TAG_SUPPORTED_RATES; |
---|
| 341 | mgmt_tag_template->header.tag_length = 8; |
---|
| 342 | mgmt_tag_template->data[0] = RATE_BASIC | (0x02); //1Mbps |
---|
| 343 | mgmt_tag_template->data[1] = RATE_BASIC | (0x04); //2Mbps |
---|
| 344 | mgmt_tag_template->data[2] = RATE_BASIC | (0x0B); //5.5Mbps |
---|
| 345 | mgmt_tag_template->data[3] = RATE_BASIC | (0x16); //11Mbps |
---|
| 346 | mgmt_tag_template->data[4] = (0x24); //18Mbps |
---|
| 347 | mgmt_tag_template->data[5] = (0x30); //24Mbps |
---|
| 348 | mgmt_tag_template->data[6] = (0x48); //36Mbps |
---|
| 349 | mgmt_tag_template->data[7] = (0x6C); //54Mbps |
---|
| 350 | mgmt_tag_template = (void*)mgmt_tag_template + ( mgmt_tag_template->header.tag_length + sizeof(mgmt_tag_header) ); //Advance tag template forward |
---|
| 351 | |
---|
| 352 | mgmt_tag_template->header.tag_element_id = MGMT_TAG_EXTENDED_SUPPORTED_RATES; |
---|
| 353 | mgmt_tag_template->header.tag_length = 4; |
---|
| 354 | mgmt_tag_template->data[0] = (0x0c); //6Mbps |
---|
| 355 | mgmt_tag_template->data[1] = (0x12); //9Mbps |
---|
| 356 | mgmt_tag_template->data[2] = (0x18); //12Mbps |
---|
| 357 | mgmt_tag_template->data[3] = (0x60); //48Mbps |
---|
| 358 | mgmt_tag_template = (void*)mgmt_tag_template + ( mgmt_tag_template->header.tag_length + sizeof(mgmt_tag_header) ); //Advance tag template forward |
---|
| 359 | |
---|
| 360 | if (network_info->bss_config.ht_capable) { |
---|
| 361 | //Note: This is the only place in the code where a STA decides whether or not to advertise that it is |
---|
| 362 | // capable of HT rates. If it is joining a non-HT capable AP, it will omit these tags and pretend that |
---|
| 363 | // it is only capable of transmitting and receiving the non-HT rates. |
---|
| 364 | |
---|
| 365 | //Insert HT Capabilities and HT Information tags |
---|
| 366 | mgmt_tag_template->header.tag_element_id = MGMT_TAG_HT_CAPABILITIES; |
---|
| 367 | mgmt_tag_template->header.tag_length = 26; |
---|
| 368 | |
---|
| 369 | ht_capabilities_element = (ht_capabilities*)mgmt_tag_template->data; |
---|
| 370 | ht_capabilities_element->ht_capabilities_info = 0x000c; |
---|
| 371 | ht_capabilities_element->a_mpdu_parameters = 0x00; |
---|
| 372 | ht_capabilities_element->rx_supported_mcs[0] = 0x000000ff; |
---|
| 373 | ht_capabilities_element->rx_supported_mcs[1] = 0x00000000; |
---|
| 374 | ht_capabilities_element->rx_supported_mcs[2] = 0x00000000; |
---|
| 375 | ht_capabilities_element->rx_supported_mcs[3] = 0x00000000; |
---|
| 376 | ht_capabilities_element->ht_extended_capabilities = 0x0000; |
---|
| 377 | ht_capabilities_element->tx_beamforming = 0x0000; |
---|
| 378 | ht_capabilities_element->ant_sel = 0x00; |
---|
| 379 | |
---|
| 380 | mgmt_tag_template = (void*)mgmt_tag_template + ( mgmt_tag_template->header.tag_length + sizeof(mgmt_tag_header) ); //Advance tag template forward |
---|
| 381 | |
---|
| 382 | mgmt_tag_template->header.tag_element_id = MGMT_TAG_HT_OPERATION; |
---|
| 383 | mgmt_tag_template->header.tag_length = 22; |
---|
| 384 | |
---|
| 385 | ht_information_element = (ht_information*)mgmt_tag_template->data; |
---|
| 386 | ht_information_element->channel = wlan_mac_high_bss_channel_spec_to_radio_chan(network_info->bss_config.chan_spec); |
---|
| 387 | ht_information_element->ht_info_subset_1 = 0x00; |
---|
| 388 | ht_information_element->ht_info_subset_2 = 0x0004; //One or more STAs are not greenfield compatible |
---|
| 389 | ht_information_element->ht_info_subset_3 = 0x0000; |
---|
| 390 | ht_information_element->rx_supported_mcs[0] = 0x00000000; |
---|
| 391 | ht_information_element->rx_supported_mcs[1] = 0x00000000; |
---|
| 392 | ht_information_element->rx_supported_mcs[2] = 0x00000000; |
---|
| 393 | ht_information_element->rx_supported_mcs[3] = 0x00000000; |
---|
| 394 | |
---|
| 395 | mgmt_tag_template = (void*)mgmt_tag_template + ( mgmt_tag_template->header.tag_length + sizeof(mgmt_tag_header) ); //Advance tag template forward |
---|
| 396 | } |
---|
| 397 | packetLen_bytes = ((u8*)mgmt_tag_template - pkt) + WLAN_PHY_FCS_NBYTES; |
---|
| 398 | |
---|
| 399 | return packetLen_bytes; |
---|
| 400 | } |
---|
| 401 | |
---|
| 402 | int wlan_create_association_response_frame(u8* pkt, |
---|
| 403 | u8* addr1, |
---|
| 404 | u8* addr2, |
---|
| 405 | u8* addr3, |
---|
| 406 | u16 status, |
---|
| 407 | u16 AID, |
---|
| 408 | network_info_t* network_info) { |
---|
| 409 | u32 packetLen_bytes; |
---|
| 410 | |
---|
| 411 | ht_capabilities* ht_capabilities_element; |
---|
| 412 | ht_information* ht_information_element; |
---|
| 413 | wmm_parameter_t* wmm_parameter; |
---|
| 414 | |
---|
| 415 | mgmt_tag_template_t* mgmt_tag_template; |
---|
| 416 | |
---|
| 417 | mac_header_80211* assoc_80211_header; |
---|
| 418 | |
---|
| 419 | if(pkt == NULL) return WLAN_FAILURE; |
---|
| 420 | |
---|
| 421 | assoc_80211_header = (mac_header_80211*)(pkt); |
---|
| 422 | |
---|
| 423 | assoc_80211_header->frame_control_1 = MAC_FRAME_CTRL1_SUBTYPE_ASSOC_RESP; |
---|
| 424 | assoc_80211_header->frame_control_2 = 0; |
---|
| 425 | //duration can be filled in by CPU_LOW |
---|
| 426 | assoc_80211_header->duration_id = 0; |
---|
| 427 | |
---|
| 428 | memcpy(assoc_80211_header->address_1, addr1, MAC_ADDR_LEN); |
---|
| 429 | memcpy(assoc_80211_header->address_2, addr2, MAC_ADDR_LEN); |
---|
| 430 | memcpy(assoc_80211_header->address_3, addr3, MAC_ADDR_LEN); |
---|
| 431 | |
---|
| 432 | assoc_80211_header->sequence_control = 0; //Will be filled in at dequeue |
---|
| 433 | |
---|
| 434 | association_response_frame* association_resp_mgmt_header; |
---|
| 435 | association_resp_mgmt_header = (association_response_frame*)(pkt + sizeof(mac_header_80211)); |
---|
| 436 | association_resp_mgmt_header->capabilities = (CAPABILITIES_ESS | CAPABILITIES_SHORT_TIMESLOT); |
---|
| 437 | |
---|
| 438 | association_resp_mgmt_header->status_code = status; |
---|
| 439 | association_resp_mgmt_header->association_id = 0xC000 | AID; |
---|
| 440 | |
---|
| 441 | mgmt_tag_template = (mgmt_tag_template_t *)( pkt + sizeof(mac_header_80211) + sizeof(association_response_frame) ); |
---|
| 442 | |
---|
| 443 | mgmt_tag_template->header.tag_element_id = MGMT_TAG_SUPPORTED_RATES; |
---|
| 444 | mgmt_tag_template->header.tag_length = 8; |
---|
| 445 | mgmt_tag_template->data[0] = RATE_BASIC | (0x0C); //6Mbps (BPSK, 1/2) |
---|
| 446 | mgmt_tag_template->data[1] = (0x12); //9Mbps (BPSK, 3/4) |
---|
| 447 | mgmt_tag_template->data[2] = RATE_BASIC | (0x18); //12Mbps (QPSK, 1/2) |
---|
| 448 | mgmt_tag_template->data[3] = (0x24); //18Mbps (QPSK, 3/4) |
---|
| 449 | mgmt_tag_template->data[4] = RATE_BASIC | (0x30); //24Mbps (16-QAM, 1/2) |
---|
| 450 | mgmt_tag_template->data[5] = (0x48); //36Mbps (16-QAM, 3/4) |
---|
| 451 | mgmt_tag_template->data[6] = (0x60); //48Mbps (64-QAM, 2/3) |
---|
| 452 | mgmt_tag_template->data[7] = (0x6C); //54Mbps (64-QAM, 3/4) |
---|
| 453 | mgmt_tag_template = (void*)mgmt_tag_template + ( mgmt_tag_template->header.tag_length + sizeof(mgmt_tag_header) ); //Advance tag template forward |
---|
| 454 | |
---|
| 455 | if (network_info->bss_config.ht_capable) { |
---|
| 456 | //Insert HT Capabilities and HT Information tags |
---|
| 457 | mgmt_tag_template->header.tag_element_id = MGMT_TAG_HT_CAPABILITIES; |
---|
| 458 | mgmt_tag_template->header.tag_length = 26; |
---|
| 459 | |
---|
| 460 | ht_capabilities_element = (ht_capabilities*)mgmt_tag_template->data; |
---|
| 461 | ht_capabilities_element->ht_capabilities_info = 0x000c; |
---|
| 462 | ht_capabilities_element->a_mpdu_parameters = 0x00; |
---|
| 463 | ht_capabilities_element->rx_supported_mcs[0] = 0x000000ff; |
---|
| 464 | ht_capabilities_element->rx_supported_mcs[1] = 0x00000000; |
---|
| 465 | ht_capabilities_element->rx_supported_mcs[2] = 0x00000000; |
---|
| 466 | ht_capabilities_element->rx_supported_mcs[3] = 0x00000000; |
---|
| 467 | ht_capabilities_element->ht_extended_capabilities = 0x0000; |
---|
| 468 | ht_capabilities_element->tx_beamforming = 0x0000; |
---|
| 469 | ht_capabilities_element->ant_sel = 0x00; |
---|
| 470 | |
---|
| 471 | mgmt_tag_template = (void*)mgmt_tag_template + ( mgmt_tag_template->header.tag_length + sizeof(mgmt_tag_header) ); //Advance tag template forward |
---|
| 472 | |
---|
| 473 | mgmt_tag_template->header.tag_element_id = MGMT_TAG_HT_OPERATION; |
---|
| 474 | mgmt_tag_template->header.tag_length = 22; |
---|
| 475 | |
---|
| 476 | ht_information_element = (ht_information*)mgmt_tag_template->data; |
---|
| 477 | ht_information_element->channel = wlan_mac_high_bss_channel_spec_to_radio_chan(network_info->bss_config.chan_spec); |
---|
| 478 | ht_information_element->ht_info_subset_1 = 0x00; |
---|
| 479 | ht_information_element->ht_info_subset_2 = 0x0004; //One or more STAs are not greenfield compatible |
---|
| 480 | ht_information_element->ht_info_subset_3 = 0x0000; |
---|
| 481 | ht_information_element->rx_supported_mcs[0] = 0x00000000; |
---|
| 482 | ht_information_element->rx_supported_mcs[1] = 0x00000000; |
---|
| 483 | ht_information_element->rx_supported_mcs[2] = 0x00000000; |
---|
| 484 | ht_information_element->rx_supported_mcs[3] = 0x00000000; |
---|
| 485 | |
---|
| 486 | mgmt_tag_template = (void*)mgmt_tag_template + ( mgmt_tag_template->header.tag_length + sizeof(mgmt_tag_header) ); //Advance tag template forward |
---|
| 487 | |
---|
| 488 | //Insert WMM tag |
---|
| 489 | mgmt_tag_template->header.tag_element_id = MGMT_TAG_VENDOR_SPECIFIC; |
---|
| 490 | mgmt_tag_template->header.tag_length = 24; |
---|
| 491 | |
---|
| 492 | wmm_parameter = (wmm_parameter_t*)mgmt_tag_template->data; |
---|
| 493 | wmm_parameter->oui[0] = 0x00; |
---|
| 494 | wmm_parameter->oui[1] = 0x50; |
---|
| 495 | wmm_parameter->oui[2] = 0xf2; |
---|
| 496 | wmm_parameter->vendor_specific_oui_type = 2; |
---|
| 497 | wmm_parameter->wme_subtype = 1; |
---|
| 498 | wmm_parameter->wme_version = 1; |
---|
| 499 | wmm_parameter->wme_qos_info = 0x08; |
---|
| 500 | wmm_parameter->reserved = 0; |
---|
| 501 | wmm_parameter->aci0 = Xil_Htonl(0x03a40000); |
---|
| 502 | wmm_parameter->aci1 = Xil_Htonl(0x27a40000); |
---|
| 503 | wmm_parameter->aci2 = Xil_Htonl(0x42430000); |
---|
| 504 | wmm_parameter->aci3 = Xil_Htonl(0x62320000); |
---|
| 505 | |
---|
| 506 | mgmt_tag_template = (void*)mgmt_tag_template + ( mgmt_tag_template->header.tag_length + sizeof(mgmt_tag_header) ); //Advance tag template forward |
---|
| 507 | } |
---|
| 508 | |
---|
| 509 | packetLen_bytes = ((u8*)mgmt_tag_template - pkt) + WLAN_PHY_FCS_NBYTES; |
---|
| 510 | |
---|
| 511 | return packetLen_bytes; |
---|
| 512 | } |
---|
| 513 | |
---|
| 514 | |
---|
| 515 | |
---|
| 516 | int wlan_create_data_frame_header(u8* pkt, |
---|
| 517 | u8* addr1, |
---|
| 518 | u8* addr2, |
---|
| 519 | u8* addr3, |
---|
| 520 | u8 frame_control_2) { |
---|
| 521 | |
---|
| 522 | if(pkt == NULL) return WLAN_FAILURE; |
---|
| 523 | |
---|
| 524 | mac_header_80211* data_80211_header; |
---|
| 525 | data_80211_header = (mac_header_80211*)(pkt); |
---|
| 526 | |
---|
| 527 | data_80211_header->frame_control_1 = MAC_FRAME_CTRL1_SUBTYPE_DATA; |
---|
| 528 | data_80211_header->frame_control_2 = frame_control_2; |
---|
| 529 | |
---|
| 530 | data_80211_header->duration_id = 0; |
---|
| 531 | |
---|
| 532 | memcpy(data_80211_header->address_1, addr1, MAC_ADDR_LEN); |
---|
| 533 | memcpy(data_80211_header->address_2, addr2, MAC_ADDR_LEN); |
---|
| 534 | memcpy(data_80211_header->address_3, addr3, MAC_ADDR_LEN); |
---|
| 535 | |
---|
| 536 | data_80211_header->sequence_control = 0; //Will be filled in at dequeue |
---|
| 537 | |
---|
| 538 | return (sizeof(mac_header_80211) + WLAN_PHY_FCS_NBYTES) ; |
---|
| 539 | } |
---|
| 540 | |
---|