Changes between Version 7 and Version 8 of 802.11/wlan_exp/app_notes/tutorial_token_mac/CPU_LOW


Ignore:
Timestamp:
Jul 9, 2015, 5:02:36 PM (9 years ago)
Author:
chunter
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • 802.11/wlan_exp/app_notes/tutorial_token_mac/CPU_LOW

    v7 v8  
    202202                pkt_buf_pending_tx = msg->arg0;
    203203        }                       
    204         break;
     204break;
    205205}}}
    206206
     
    285285
    286286We will use {{{TX_PKT_BUF_TOKEN}}} as a hardcoded packet buffer index that is dedicated to transmitting our new token frames. {{{mac_frame_custom_token}}} is a struct that is our new custom token frame. It's format is inspired by 802.11 frames in order to allow nearby commercial Wi-Fi devices to decode and ignore these frames. We'll set the {{{frame_control_1}}} field to an invalid value to make ensure this.
     287
     288----
     289
     290Next, 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
     298int 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
     313int 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
     329Here 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.
    287330
    288331----