| 287 | |
| 288 | ---- |
| 289 | |
| 290 | Next, we will add two small functions to NoMAC that will act as packet constructors. They will create {{{mac_frame_custom_token}}} packets and fill the relevant values into the elements of that struct. |
| 291 | |
| 292 | {{{ |
| 293 | #!c |
| 294 | |
| 295 | #define MAC_FRAME_CTRL1_SUBTYPE_TOKEN_OFFER (MAC_FRAME_CTRL1_TYPE_CTRL | 0x10) |
| 296 | #define MAC_FRAME_CTRL1_SUBTYPE_TOKEN_RESPONSE (MAC_FRAME_CTRL1_TYPE_CTRL | 0x20) |
| 297 | |
| 298 | int wlan_create_token_offer_frame(void* pkt_buf_addr, u8* address_ra, u8* address_ta, u16 duration, u32 res_duration) { |
| 299 | mac_frame_custom_token* token; |
| 300 | token = (mac_frame_custom_token*)(pkt_buf_addr); |
| 301 | |
| 302 | token->frame_control_1 = MAC_FRAME_CTRL1_SUBTYPE_TOKEN_OFFER; |
| 303 | token->frame_control_2 = 0; |
| 304 | token->duration_id = duration; |
| 305 | memcpy(token->address_ra, address_ra, 6); |
| 306 | memcpy(token->address_ta, address_ta, 6); |
| 307 | token->res_duration_usec = res_duration; |
| 308 | |
| 309 | //Include FCS in packet size (MAC accounts for FCS, even though the PHY calculates it) |
| 310 | return (sizeof(mac_frame_custom_token)+WLAN_PHY_FCS_NBYTES); |
| 311 | } |
| 312 | |
| 313 | int wlan_create_token_response_frame(void* pkt_buf_addr, u8* address_ra, u8* address_ta, u16 duration, u32 res_duration) { |
| 314 | mac_frame_custom_token* token; |
| 315 | token = (mac_frame_custom_token*)(pkt_buf_addr); |
| 316 | |
| 317 | token->frame_control_1 = MAC_FRAME_CTRL1_SUBTYPE_TOKEN_RESPONSE; |
| 318 | token->frame_control_2 = 0; |
| 319 | token->duration_id = duration; |
| 320 | memcpy(token->address_ra, address_ra, 6); |
| 321 | memcpy(token->address_ta, address_ta, 6); |
| 322 | token->res_duration_usec = res_duration; |
| 323 | |
| 324 | //Include FCS in packet size (MAC accounts for FCS, even though the PHY calculates it) |
| 325 | return (sizeof(mac_frame_custom_token)+WLAN_PHY_FCS_NBYTES); |
| 326 | } |
| 327 | }}} |
| 328 | |
| 329 | Here we introduce the terminology of a "token offer" and a "token response." An offer is what an AP makes to a STA when it informs the STA it now can have the token and have access to the wireless medium. A response is what the STA responds to the offer with. This acts as a positive confirmation that the STA understands it has the token. Note that in both of these cases, the same {{{mac_frame_custom_token}}} struct is used. The distinction between these two types of frames is in the value of {{{frame_control_1}}}. The values of {{{MAC_FRAME_CTRL1_SUBTYPE_TOKEN_OFFER}}} and {{{MAC_FRAME_CTRL1_SUBTYPE_TOKEN_RESPONSE}}} are somewhat arbitrary. The definitions above are particularly useful because they are invalid in the 802.11 standard, so commercial Wi-Fi devices will likely just ignore them rather than falsely interpret them as some sort of standard 802.11 packet. |