main content

802.11 mac frame generation -凯发k8网页登录

this example shows how to generate ieee® 802.11™ mac frames.

introduction

this example shows how to generate wlan mac frames, specified in section 9 of [1] and [2], and export these frames to a packet capture (pcap) file for analysis with third-party packet analysis tools.

the general mac frame format consists of a header, frame-body, and frame check sequence (fcs). the header holds information about the frame. the frame-body carries data that needs to be transmitted. the transmitter calculates the fcs over the header and frame-body. the receiver uses the fcs to confirm that the header and frame-body are properly formed. this diagram shows the structure of a general mac frame.

for more information, see the topic.

you can use the function to generate mac frames. this function accepts a mac frame configuration object as an input. this object configures the fields in the mac header. set the frametype property to the desired subtype description in table 9-1 of [1] to set the appropriate type and subtype fields in the mac header. the function supports the generation of these mpdus.

  • management frames: beacon

  • data frames: data, null, qos data, qos null

  • control frames: rts, cts, ack, block ack

in addition to these mpdus, also supports generation of a-mpdus containing mpdus of type qos data.

control frame generation

to generate an rts frame, create a mac frame configuration object with the frametype set to 'rts'.

rtscfg = wlanmacframeconfig('frametype', 'rts');
disp(rtscfg);
  wlanmacframeconfig with properties:
          frametype: 'rts'
    powermanagement: 0
           moredata: 0
           duration: 0
           address1: 'ffffffffffff'
           address2: '00123456789b'
   read-only properties:
            decoded: 0

configure the frame header fields.

% duration
rtscfg.duration = 500;
% receiver address
rtscfg.address1 = 'fcf8b0102001';
% transmitter address
rtscfg.address2 = 'fcf8b0102002';

generate an rts frame using the configuration.

% generate octets for an rts frame
rtsframe = wlanmacframe(rtscfg);

by default, the output of is a sequence of hexadecimal octets. if you want to generate the mac frame as a sequence of bits, set the outputformat parameter to bits.

% generate bits for an rts frame
rtsframebits = wlanmacframe(rtscfg, 'outputformat', 'bits');

data frame generation

to generate a qos data frame, create a mac frame configuration object with the frametype set to 'qos data'.

qosdatacfg = wlanmacframeconfig('frametype', 'qos data');
disp(qosdatacfg);
  wlanmacframeconfig with properties:
          frametype: 'qos data'
        frameformat: 'non-ht'
               tods: 0
             fromds: 1
     retransmission: 0
    powermanagement: 0
           moredata: 0
           duration: 0
           address1: 'ffffffffffff'
           address2: '00123456789b'
           address3: '00123456789b'
     sequencenumber: 0
                tid: 0
          ackpolicy: 'no ack'
    msduaggregation: 0
               eosp: 0
        ismeshframe: 0
   read-only properties:
            decoded: 0

configure the frame header fields.

% from ds flag
qosdatacfg.fromds = 1;
% to ds flag
qosdatacfg.tods = 0;
% acknowledgment policy
qosdatacfg.ackpolicy = 'normal ack';
% receiver address
qosdatacfg.address1 = 'fcf8b0102001';
% transmitter address
qosdatacfg.address2 = 'fcf8b0102002';

the qos data frame is used to transmit a payload from higher-layer. a 20-byte payload containing a repeating sequence of hexadecimal value '11' is used in this example.

payload = repmat('11', 1, 20);

generate a qos data frame using payload and configuration.

% generate octets for a qos data frame
qosdataframe = wlanmacframe(payload, qosdatacfg);

by default, the output of is a sequence of hexadecimal octets. if you want to generate the mac frame as a sequence of bits, set the outputformat parameter to bits.

% generate bits for a qos data frame
qosdataframebits = wlanmacframe(payload, qosdatacfg, 'outputformat', 'bits');

the output mac frame is an mpdu with a single msdu. for more information about a-msdu and a-mpdu generation, see 802.11ac waveform generation with mac frames.

management frame generation

to generate a beacon frame, create a mac frame configuration object with the frametype set to 'beacon'.

beaconcfg = wlanmacframeconfig('frametype', 'beacon');
disp(beaconcfg);
  wlanmacframeconfig with properties:
           frametype: 'beacon'
                tods: 0
              fromds: 1
      retransmission: 0
     powermanagement: 0
            moredata: 0
            duration: 0
            address1: 'ffffffffffff'
            address2: '00123456789b'
            address3: '00123456789b'
      sequencenumber: 0
    managementconfig: [1x1 wlanmacmanagementconfig]
   read-only properties:
             decoded: 0

beacon frame-body consists of information fields and information elements as explained in section 9.3.3.2 of [1]. you can configure these information fields and elements using .

% create a management frame-body configuration object
framebodycfg = wlanmacmanagementconfig;
disp(framebodycfg);
  wlanmacmanagementconfig with properties:
                   frametype: 'beacon'
                   timestamp: 0
              beaconinterval: 100
               esscapability: 1
              ibsscapability: 0
                     privacy: 0
               shortpreamble: 0
          spectrummanagement: 0
                  qossupport: 1
           shortslottimeused: 0
                 apsdsupport: 0
            radiomeasurement: 0
      delayedblockacksupport: 0
    immediateblockacksupport: 0
                        ssid: 'default ssid'
                  basicrates: {'6 mbps'  '12 mbps'  '24 mbps'}
             additionalrates: {}
   read-only properties:
         informationelements: {511x2 cell}

configure the information fields and elements in the frame-body configuration. you can add information elements using addie(elementid, information) method as shown below. section 9.4 in [1] lists the information fields and information elements.

% beacon interval
framebodycfg.beaconinterval = 100;
% timestamp
framebodycfg.timestamp = 123456;
% ssid
framebodycfg.ssid = 'test_beacon';
% add ds parameter ie (element id - 3) with channel number 11 (0x0b)
framebodycfg = framebodycfg.addie(3, '0b');

assign the updated frame-body configuration object to the managementconfig property in the mac frame configuration.

% update management frame-body configuration
beaconcfg.managementconfig = framebodycfg;

generate the beacon frame with the updated frame configuration.

% generate octets for a beacon frame
beaconframe = wlanmacframe(beaconcfg);

by default, the output of is a sequence of hexadecimal octets. if you want to generate the mac frame as a sequence of bits, set the outputformat parameter to bits.

% generate bits for a beacon frame
beaconframebits = wlanmacframe(beaconcfg, 'outputformat', 'bits');

export wlan mac frames to pcap or pcapng file

the packet capture (pcap) or packet capture next generation (pcapng) file (.pcap or .pcapng, respectively) is a widely used packet capture file format to perform packet analysis.

to capture the packet characteristics, export the generated mac frames to a pcap or pcapng file by using the object. you can visualize and analyze the pcap or pcapng file by using a third-party packet analyzer tool such as wireshark.

specify the name and extension of the pcap file. to export the mac frames to a pcapng file, set the file extension to 'pcapng'.

filename = 'macframes';
fileextension = 'pcap';

if a file with the filename name already exists in the current directory, delete the existing file.

if isfile(strcat(filename, '.', fileextension))
    delete(strcat(filename, '.', fileextension));
end

set the packet arrival time in posix® microseconds.

timestamp = 124800;

create a wlan pcap file writer object with the specified file name and extension by using the object.

pcap = wlanpcapwriter('filename', filename, 'fileextension', fileextension);

specify the mac frames to be exported to the pcap file.

frames = {rtsframe, qosdataframe, beaconframe};

write the mac frames to the pcap file.

for idx = 1:numel(frames)
    write(pcap, frames{idx}, timestamp);
end

delete the pcap file writer object.

delete(pcap);

visualization of the generated mac frames

you can open the pcap files containing the generated mac frames in a packet analyzer. the frames decoded by wireshark match the standard compliant mac frames generated using the wlan toolbox. this figure shows the analysis of the captured mac frames in wireshark.

  • rts frame

  • qos data frame

  • beacon frame

conclusion and further exploration

this example shows how to generate mac frames for the ieee 802.11 standard. you can use a packet analyzer to view the generated mac frames. to transmit the generated mac frames over the air, see 802.11 ofdm beacon frame generation and 802.11ac waveform generation with mac frames.

references

[1] ieee std 802.11™-2020 (revision of ieee std 802.11-2016). “part 11: wireless lan medium access control (mac) and physical layer (phy) specifications.” ieee standard for information technology — telecommunications and information exchange between systems — local and metropolitan area networks — specific requirements.

[2] ieee® std 802.11ax™-2021 (amendment to ieee std 802.11-2020). “part 11: wireless lan medium access control (mac) and physical layer (phy) specifications. amendment 1: enhancements for high efficiency wlan.” ieee standard for information technology — telecommunications and information exchange between systems. local and metropolitan area networks — specific requirements.

[3] wireshark · go deep. . accessed 30 june 2020

[4] group, the tcpdump. tcpdump/libpcap public repository. . accessed 30 june 2020

related topics

网站地图