Friday, 21 April 2017

Wifi Data TX path

Wifi TX for AP mode :

Linux stack passes ethernet packet.

1. xmit( netdev, skb) --- This is call back api of the wifi driver .
   - Linux stack calls this callback api to send packet through wifi driver
   - Extract the driver specific pointer from netdev.

2. Check that is skb has clones and remove any clones to it
    skb = skb_unshare(skb);

3. Check available header length, driver needs to add its header needed for host to target packet tradnfer
    skb_headroom()  --- return the available headroom
    skb = skb_realloc_headroom(skb, head_length_needed)
 

4. Check is the frame multicast packet
        - struct eth_head *eth = (struct eth_head *)skb->data;
          eth->destination[0] = 0x01 --- > it is nulticast packet

5. It it is not multicast packet, find the STA node that is associated with dest mac address.
  -     AP maintains node table of all the connected STA devices.
  -     If STA node is not found, then dest mac address is unknown mac and packet is discarded, Who fress the SKB here ??

STA devices connect and disconnect at random interval of time, access to node table needs to be protected. In tx path, node table is accessed only for read the table. rw_lock can be used to protect it here.

Read_Write lock: It allows multiple readers at the same but only one writer. Example, if reader has taken the lock, another reader can also take the lock, second reader will not get blocked till first reader unlocks it. Both can access the critical section the same time.
 read_lock(rw_lock)  ;

If writer tries to take the lock and if there are no readers at the same time, it will get the lock. In case there are any readers holding the lock, writer has to wait till all reader unlock the lock.
Wait operation is similer to spin_lock().

write_lock(rw_lock);
   
6. Classify the packet
 - Different types of packet are sent over ehternet,
   - IPv4
   - IPv6
   - EAPOL
   - ARP

   From  the ethernet header extract the type.
   For IPV4 packet types need to extract the "Type of Service" DSCP value from IP headet of  the packet.
  - struct ipheader *iph = (uint8 *)skb->data + sizeof(ether_header);
     iph->tos  - is the tid of the packet.
 Each tid falls into to any one of the below ACs
 Access Catogaries - Back Ground ----- lowest priority
                                 Best Effort
                                  Video
                                  Voice --- highetst priority

  Each SKB has some space left for control buffer(cb portion) of 48 bytes. This space can be used by each layer to set status of the packet and to set flags that describe the packet.

Tid of the packet is set in cb portion of the skb



7. DHCP packet - Check UDP source port as 63 or 64