Tuesday, July 19, 2016

Network Time Protocol (NTP)


What does NTP client asks NTP server when it bumps into it ? Hey buddy, What's the time? 

NTP protocol is used by computers and embedded devices to synchronize time to a common clock reference across the internet. Many embedded devices like a WLAN Access Point(AP) ,IPTV Set Top Box (STB), smart TV etc do not have hardware clock inside them. These devices heavily rely on NTP Server to get the correct time.
NTP based time is used for many critical processes inside these devices. For example a smart TV needs a correct time stamp for various things like:
  • Logging : If we have to debug some issue, which user is facing, we need a correct time stamp  to relate user specified problem with exact date and time inside the logs.
  • Device Lease : When your device gets connected to an ethernet interface or to WiFi interface , it will have DHCP lease allocated , If your device does not have correct date and time, your DHCP lease could lie in past and DHCP client on your device can start to behave insanely and it can get abrupt disconnections.  
The piece of software which runs on embedded devices to synchronize the time over the internet is called NTP client. NTP client talks to NTP server to get the correct date and time. NTP client uses UDP protocol for its operation and it operates over UDP port 123 at transport layer. Following sequence of packets exchange happens between NTP server and NTP client to update the time:
  • NTP client sends the packet to NTP server containing its own time stamp
  • NTP server responds  this request with a packet containing 2 time stamps:
    • The original client timestamp.
    • the time at which server received the request from NTP client.
    • the time at which server is sending the response to NTP client.
  • Client estimates the delta between its timestamp and server timestamp.
  • Client can talk to multiple NTP servers.
  • But it will sync up with only one NTP server based on the offset and jitter.

On most of the embedded devices the default time zone is UTC. NTP server and NTP client exchange messages  in UTC format. If after NTP synchronization , We want our device to display the correct date and time , then it should apply the correct timezone on UTC time.

Sunday, July 3, 2016

How a WLAN station connects to an Access Point ?



WLAN connection is a 3 step process:

  • Scanning
  • Authentication
  • Association
Scanning : - Station does a scan to find an appropriate AP to which a WLAN station(STA) wants to connect to. For detailed understanding, Please read my another article on WLAN Scanning.

Authentication:-
Authentication is a process by which WLAN STA proves its identity to an AP. Authentication could be :

  • An open system authentication : In an open system authentication ,WLAN STA does not need any password/secret passphrase to connect to an AP. WLAN STA just says "authenticate me" and  an AP says "Yes, you are authenticated",  And AP and STA can start data exchange after this.
  • Pre-shared key authentication : In shared key authentication there is a pre-shared,    key which both parties(AP and STA) know about. When STA wants to authenticate with an AP, 
    • it sends an authentication request frame to an AP.
    • Ap sends the "Challenge Text" to STA.
    • STA encrypts this "Challenge Text" with shared key it has, and sends back to an AP.
    • AP decrypts this "Challenge Text" and matches it with the original  "Challenge Text" it had. If both texts match AP sends the OK confirmation to a STA. And after this association process starts.
Association:
  1. 802.11 association  process finalizes the security and bit rate options and establishes the data link between station and an access point.
  2. 802.11 association process enables the access point to allocate resources to WLAN STA.
  3. WLAN STA starts the association process by sending an association request frame to an AP.
    1. This association frame contains information about the station like supported data rates and SSID it wants to associate with.
    2. In response to association request, AP sends back an association response, which may contain approval or disapproval.
    3. If an AP approves the association request, it will send back the Association ID (AID) and supported data rates.
    4. After association STA becomes the member of a BSS.
    5. STA can send data to an AP.
    6. AID  identifies each station.



Saturday, June 18, 2016

Dynamic Frequency Selection (DFS)

Dynamic Frequency Selection is a technique of detecting the RADAR signals which must be protected against interference from 5GHz radios and upon detection switching to 5G operating frequency which does not interferes with the RADAR.

So using DFS, WLAN 802.11ac 5G devices are able to use 5G channels which are also used by RADAR systems. Thirteen out of twenty two 20Mhz 5G channels are DFS channels. WLAN devices operating in DFS channels require the capability of RADAR detection and avoidance capability. IEEE 802.11h addresses this requirement by adding DFS and Transmit Power Control(TPC) to all DFS channels. Here is list of 5G channels which require DFS :

Channel
- 52
- 56
- 60
- 64
- 100
- 104
- 108
- 112
- 116
- 120
- 124
- 128
- 132
- 136
- 140

When a 5G radio is operating in DFS channel it continuously monitors that 5G channel for RADAR signals.And if RADAR is detected it:

  • Stops the transmission on that channel.
  • Flushes power save client queues.
  • Disassociates the clients.
  • Broadcasts the 802.11h channel change announcement.
  • Randomly selects another channel : 
    1. If the selected channel is non DFS channel, it starts the beaconing and accepts client associations on that channel.
    2. If the selected channel is DFS channel, then it waits for 60 sec to see if RADAR is detected and if RADAR is not detected, It starts the beaconing and accepts the client associations on this channel. If a RADAR is detected, It searches for another 5G channel.





Monday, June 13, 2016

WLAN Scanning





Ever wondered how does your mobile phone or laptop scan for WiFi networks around?

All Wireless radios scan for wlan transmitters continuously. 802.11 b/g/n radios scan in 2.4G frequency band and 802.11 a/ac radios scan in 5G frequency band. WLAN stations listen for beacons,probe responses  and finds out what Access Points (APs) are available in range to connect.

WLAN scanning is of two types:
  •  Passive Scanning
  •  Active scanning
Passive Scanning
All APs select one RF channel for their operation(Like for 2.4G band it could be channel number between 1 to 11  and for 5G band it could be channel 36,40,44,48,52,56,60,64,100, 104,108,112,116,120,124,128,132,136,140,144,149,153,153,157,161 or channel 165) and  send out beacon every 100ms (or more based on beacon interval configured).While doing a passive scan 2.4G WLAN station listens to  beacons  in  channels  allowed for 2.4G band and 5G station will  listen to channels allowed for 5G  frequency band and jolts down the results in the form of SSIDs of the different APs in proximity.

Passive scans are always enabled and can never be disabled because it's a bare minimum requirement for a client to connect to wireless AP.

Passive scan is a time consuming process because a WLAN station has to go to each channel and listen for approximately 200ms to listen to beacons. Once it is done scanning each channel, it will have list of APs in range.


Active Scanning
Active scans can be enabled and disabled based on requirement of the device in radio profile. During active scan,  WLAN station sends a broadcast probe request and listen to the probe responses from other WLAN devices.Active scans are more thorough than passive scans. Probe response received in response to active scan contains SSID and BSSID of an AP.

Active scan is little faster then passive scan and hence the preferred method for operating systems to connect to an AP.In active scan station goes to each channel and sends out either a broadcast probe request(asking any body out there?) or a directed probe request (asking some specific AP say : Hey, Neelam, are you out there ?)  and wait for <= 100ms for probe response and move to next channel.