This project implements Precision Time Protocol (PTP) for Wi-Fi. Likely to be used in time-sensitive WLAN, UAV, etc., Original PTP is designed for LAN but it is possible to port it to Wi-Fi. The simplest way is to timestamp PTP packets in the NIC driver but is subject to several software uncertainties. This project makes use of the hardware TSF counter to emulate the hardware PTP clock like Ethernet NICs. A standard PTP clock interface is implemented in ath9k. Its performance is at 1 μs level. More details can be found in the ATC'21 paper.
The above figure illustrates how Wi-PTP works.
The ath9k directory contains the modified ath9k driver based on Linux Kernel 4.19.37. The ptp directory contains the adjusted linuxptp.
-
Patch
drivers/net/wireless/athin the Kernel source tree with this repo'sath9k.diff. We recommendpatchto do this.cd <kernel_source>/drivers/net/wireless/ath patch -sf -p1 < <repo_path>/wifi-ptp/ath9k.diff
-
Build ath9k driver.
cd <kernel source> make M=drivers/net/wireless/ath
-
Replace the ath9k driver.
WLAN_DEV=wlan0 ifdown ${WLAN_DEV} rmmod ath9k rmmod ath9k_common rmmod ath9k_hw rmmod ath cd <kernel source>/drivers/net/wireless/ath insmod ./ath.ko insmod ./ath9k/ath9k_hw.ko insmod ./ath9k/ath9k_common.ko insmod ./ath9k/ath9k.ko sleep 1 ifup ${WLAN_DEV}
Note: please replace the
wlan0above with the actual ath9k interface. -
Check for the PTP device.
ls /sys/class/net/${WLAN_DEV}/device/ptpThe above command should output a
ptp<X>.
The ptp version in this repo is modified to disable PTP capability checking and implement the PHC function in a relatively simple but improper way. The modified version is based on the commit dd30b3a. We also provide a file linuxptp.patch, which is the diff information between the commit dd30b3a and our modified linuxptp.
cd <repo path>/ptp
makeAfter building the linuxptp, the ar9300+ wireless cards can be used to perform PTP as ethernet cards.
Master: ./ptp4l -i wlan0 -p /dev/ptp<X> -m
Slave: ./ptp4l -i wlan0 -p /dev/ptp<X> -m -s
@inproceedings {273763,
author = {Paizhuo Chen and Zhice Yang},
title = {Understanding Precision Time Protocol in Today{\textquoteright}s Wi-Fi Networks: A Measurement Study},
booktitle = {2021 {USENIX} Annual Technical Conference ({USENIX} {ATC} 21)},
year = {2021},
isbn = {978-1-939133-23-6},
pages = {597--610},
url = {https://www.usenix.org/conference/atc21/presentation/chen},
publisher = {{USENIX} Association},
month = jul,
}
If you have any questions, please don't hesitate to contact [email protected] or [email protected].