No description, website, or topics provided.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

CSMA/CN: Carrier Sense Multiple Access / Collision Notification

CS546 Individual Class Term Project (Spring 2016, KAIST)

1. Requirements

Device name Requirements
Android Device Android version 5.0 or 5.1 (Lollipop) (Android 6.0 or higher would not work properly due to its changed permission system)
Bluetooth Low Energy (4.0) Capability
802.11n Wi-Fi Capability
Custom Wi-Fi AP Raspberry Pi + Ubuntu for Raspberry Pi
Bluetooth Low Energy (4.0) Capability
802.11n Wi-Fi Capability

2. Sample Testing Environment

I tested CSMA/CN in the following environments to implement the project and measure the performance.

  • Android device: Motorola Nexus 6 with Android 5.1, Samsung Galaxy A7 2016 with Android 5.1.1
  • Customized Wi-Fi AP: Raspberry Pi model B with Wi-Fi USB adapter and BLE USB adapter
  • Wi-Fi USB adapter: NEXT-202N mini (RTL8188CUS 802.11n WLAN adapter)
  • BLE USB adapter: NEXT-204BT (Cambridge Silicon Radio Ltd Bluetooth Dongle)


I strongly recommend you to use the same setup to test it.

3. Building an APK and installing it in Android

  • Run Android Studio and import the Android Studio project source code.
  • After finishing automatic build process, run the app at the connected device.

4. Installing Ubuntu packages in Raspberry Pi

  • You need to install several packages in your Raspberry Pi Ubuntu.

    sudo apt-get update
    sudo apt-get install build-essential
    sudo apt-get install hostapd isc-dhcp-server
    sudo apt-get install Bluetooth bluez libbluetooth-dev libudev-dev curl -sLS | sudo bash
    sudo apt-get install node
  • Then, Edit /etc/dhcp/dhcpd.conf as follows.

    • Modify option domain name "" to ""
    • Modify option domain name servers, to,
    • Uncomment authoritative.
    • Add the following lines to the bottom:
      subnet netmask {
          option broadcast-address;
          option routers;
  • Edit /etc/default/isc-dhcp-server as follows.

    • Modify INTERFACES="" to INTERFACE="wlan0".
  • Edit /etc/network/interfaces as follows.

    • Add the following lines to the bottom:
      iface wlan0 inet static
  • Assign the static IP address to wlan0 with sudo ifconfig wlan0
    It runs as a Wi-Fi AP with a router IP address that assigns IP addresses with the range ~ to clients.

  • Create /etc/hostapd/hostapd.conf file with the following contents:

    ssid=RPiAP <the SSID that you want>
    channel=11 <the Wi-Fi channel that you want. 1~11> wpa=3
    wpa_passpharse=password <the password that you want> wpa_key_mgmt=WPA-PSK
  • Modify /etc/default/hostapd as follows:

    • Find the line #DAEMON_CONFIG="" and edit it to DAEMON_CONFIG="/etc/hostapd/hostapd.conf".
  • Run the following command to make a tunnel between Wi-Fi and ethernet.

    sudo sh –c “echo 1 > /proc/sys/net/ipv4/ip_forward”

    This operation will be lost when you reboot the machine.

  • Run the following commands to create network translation between eth0 and wlan0.

    sudo iptables –t nat –A POSTROUTING –o eth0 –j MASQUERADE
    sudo iptables –A FORWARD –i eth0 –o wlan0 –m state --state RELATED,ESTABLISHED –j ACCEPT
    sudo iptables –A FORWARD –i wlan0 –o eth0 –j ACCEPT
  • Download the following file to update hostapd. This statement is necessary due to a bug of hostapd driver.

    sudo mv /usr/sbin/hostapd /usr/sbin/hostapd.ORIG
    sudo mv hostapd /usr/sbin
    sudo chmod 755 /usr/sbin/hostapd
  • Run the services as follows.

    sudo service hostapd restart
    sudo service isc-dhcp-server restart

    You should see RPiAP SSID in your smartphone after this moment.

  • Run the node.js server as follows.

    sudo node <server_files_location>/udp.js false false


    Parameter explanation:
    - the first one represents the existence of hidden terminal problem.
    - the second one represents the use of CSMA/CN. - false false or false true: The transmission without hidden terminal problem. Using CSMA/CN will have no meaningful effect. - true false: The transmission with hidden terminal problem and without CSMA/CN. The performance will drastically reduced. - true true: The tramission with hidden terminal problem and also with CSMA/CN.

    Root permission is required for node.js to use BLE driver.
    The server uses UDP port number 5000 by default. Please check any other app is already using the port or not.

5. Measuring Performance.

  • First, connect to the RPiAP Wi-Fi AP.


  • In andorid application, you first select a file to send.


  • Click send button to measure the transmission performance.
    You can see the current simulation setup and the transmission status.


6. Sample Result