android application of instantaneous messaging service on ... · android application of...

26
Android Application of instantaneous messaging service on link networks Rafaelle Botter / Jean-Marc Celesti Yohann Hako Moukam / Mathilde Igier June 2015 1 Introduction Wi-Fi Direct is a recent technology introduced by WiFi-Alliance in 2010. By connecting two devices in peer to peer mode and more besides, without requiring any Access Point or the Internet, it allows a group of devices to communicate, exchange files, stream data and others functionalities which are yet to come. In this paper we are going to explain the basics protocols of a connection between two peers, before enlarging to a group of multiple devices. In a first theoretical part we will describe the succession of protocols for setting up a connection. Because of the establishement of a connection is not exactly the same depending on the case we are, we will talk about several Wi-Fi Direct scripts, from a group formation to a device joining an existing group, including those which theoretically won’t work. As we made an Android application which uses this theory, we will detail some methods, the code to help you to understand our explanation about Wi-Fi Direct is on Appendix. But first of all, let us describe you how a such technology can help everyone in the daily life. 2 Edge of Wi-Fi Direct Firslty, depends of your use, it can be profitable to choose Wi-Fi Direct over Wi-Fi. Clearly, Wi-Fi Direct allows you to share file with someone in a close area without using Internet. It can be very useful in that way we all have plenty examples of area without any connection possible to Internet : subway, moun- tains...and even if we do, it is easier to set up a Direct connection. No need to enter credentials, as secure as a Wi-Fi connection with equivalent bit rates. As we introduce it, WiFi-Direct looks as similar to Bluetooth. Confusion can be made, in some ways it may be the same (above all the peer-to-peer connection), but it’s not. Let’s take a look at the sheet in figure 1, which illustrates the particularity between those two technologies. 1

Upload: others

Post on 26-Jun-2020

9 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Android Application of instantaneous messaging service on ... · Android Application of instantaneous messaging service on link networks Rafaelle Botter / Jean-Marc Celesti Yohann

Android Application of instantaneous messaging

service on link networks

Rafaelle Botter / Jean-Marc CelestiYohann Hako Moukam / Mathilde Igier

June 2015

1 Introduction

Wi-Fi Direct is a recent technology introduced by WiFi-Alliance in 2010. Byconnecting two devices in peer to peer mode and more besides, without requiringany Access Point or the Internet, it allows a group of devices to communicate,exchange files, stream data and others functionalities which are yet to come.

In this paper we are going to explain the basics protocols of a connectionbetween two peers, before enlarging to a group of multiple devices. In a firsttheoretical part we will describe the succession of protocols for setting up aconnection. Because of the establishement of a connection is not exactly thesame depending on the case we are, we will talk about several Wi-Fi Directscripts, from a group formation to a device joining an existing group, includingthose which theoretically won’t work. As we made an Android applicationwhich uses this theory, we will detail some methods, the code to help you tounderstand our explanation about Wi-Fi Direct is on Appendix. But first of all,let us describe you how a such technology can help everyone in the daily life.

2 Edge of Wi-Fi Direct

Firslty, depends of your use, it can be profitable to choose Wi-Fi Direct overWi-Fi. Clearly, Wi-Fi Direct allows you to share file with someone in a closearea without using Internet. It can be very useful in that way we all have plentyexamples of area without any connection possible to Internet : subway, moun-tains...and even if we do, it is easier to set up a Direct connection. No need toenter credentials, as secure as a Wi-Fi connection with equivalent bit rates.

As we introduce it, WiFi-Direct looks as similar to Bluetooth. Confusioncan be made, in some ways it may be the same (above all the peer-to-peerconnection), but it’s not. Let’s take a look at the sheet in figure 1, whichillustrates the particularity between those two technologies.

1

Page 2: Android Application of instantaneous messaging service on ... · Android Application of instantaneous messaging service on link networks Rafaelle Botter / Jean-Marc Celesti Yohann

Figure 1: Wi-Fi Direct and Bluetooth’s specifications

As we can see, Wi-Fi Direct seems to be usefull to transmit a lots of datain a high bandwidth and Bluetooth is simply the contrary (low consumptionfor light data). Let’s see how a connection takes place and in what extent aWiFi-Direct Network can replace a classic one.

3 Theory of a P2P Connection

The main idea of Wi-Fi Direct is to form a group without the need of an AccessPoint. It has become possible with the implementation of SoftAPs (softwareenable access point), softwares which allow a device to have the capabilities ofan AP, even if it has not been made to be a router.Method changes, but the topology stills the same. Thus, the softAP has tradi-tional AP functionalities, such as providing an IP Address via DHCP Protocolor routing packets through the network.

In Wi-Fi Direct P2P groups, this role is performed by a device called theGroup Owner (GO). As an AP, the P2P GO announce itself with though beaconscontaining additional P2P Information Element (P2P IE). This P2P IE areincluded in all management frame. If P2P GO leave the network wind up.Others devices are P2P Clients. A device (computer, tablet, smartphone...)can be both P2P GO or P2P Client in alternate the two roles by time-sharingthe Wi-Fi interface. There are 3 ways to provide a Wi-Fi network : Standard,Autonomous and Persistent mode. In each way, we can globally observe twophases:- Determination of P2P GO: the GO is determined in function of its desire tobecome GO and also its capabilities.- Provisioning of P2P GO group which consist in exchanging credentials.

Those modes differ by the ways devices discover each other, therefore howthe the GO is determined, and by which protocols.

3.1 Standard Mode

The standard mode is the case where two devices meet for the first time, andnone of them is already in a group. The meeting phase is named ”Discovery”,

2

Page 3: Android Application of instantaneous messaging service on ... · Android Application of instantaneous messaging service on link networks Rafaelle Botter / Jean-Marc Celesti Yohann

where as the determination of P2P GO is called the GO Negotiation. The partbelow describes those processes.

3.1.1 Discovery - Scan

As it sounds, the aim is to connect our device to a network which already existedthrough an active or passive scan. Typically, a GO device of a network alreadysend beacons on the network with all informations to connect it, thus we cando a passive scan in listening the network to receive this beacons. An activescan is to send Probe request, a GO device which receive this frames send Proberesponse with the same information than in a beacon and then we are enable toconnect us to its network. If, as in figure 2, none a such network existing yet,the device begin Find phase to create a P2P network with another device.

Figure 2: Scan

3.1.2 Discovery - Find

By sending request packets (Probe Requests) through several frequency chan-nels (SEARCH), and alternating with a listening period on a single channel toreceive sent packets, devices finally achieve to meet. Indeed, Probe Requestswhich are received are responded by Probe Response. Then happen a servicediscovery exchange.

3

Page 4: Android Application of instantaneous messaging service on ... · Android Application of instantaneous messaging service on link networks Rafaelle Botter / Jean-Marc Celesti Yohann

The GAS protocol (Generic Advertisement Service) is used by a device in servicediscovery in order to exchange P2P queries to discover the available service ofother devices. After this analysis, the device accept or not to join the network.GAS supports higher-layer protocols that employ a query/response mechanism,indeed it send ANQP (Access Network Query Protocol) elements between clientand AP. The ANQP communicates metadata useful in a mobile device’s networkselection process including the AP operator’s domain name, the IP addresses(Internet Protocol addresses) available at the AP, and information about po-tential roaming partners accessible through the AP. Public Action frames areused to transport this information.

Figure 3: Find

3.1.3 GO Negociation - Formation

When the two devices with Wi-Fi Direct establish the connection they createa local network as an AP network in which one of them become P2P GroupOwner (GO) and implements AP-like functionality in the P2P Group. Theother becomes the client and in the following, we are going to refer to them asP2P Clients. The negotiation for the initial network role is explained in figure1. The two devices draw a number (even if it can be forced, we will see howlater), basically named as p2p go intent, which goes from 0 to 15. Higher thenumber is, higher is the probability for you to become GO (thus, when it’s 7

4

Page 5: Android Application of instantaneous messaging service on ... · Android Application of instantaneous messaging service on link networks Rafaelle Botter / Jean-Marc Celesti Yohann

you have 50 %). The device with the higher number becomes P2P GO and theother become the P2P Client. In case of equality, we use the breaker bit, thedevice which have the breaker bit equal to 1 become the GO. The negotiationcan fail if the two device draw a number equal higher of 15.Then, once they agreed on who will be the GO (by the negotiation phase wetalked about), they set up a group on a specific channel (1,6 or 11). Note thatthe channel is also defined by the GO.

Figure 4: P2P GO vs P2P Client

The second part of the Group Formation is to assure a secure communicationbetween device. It is set up with the WPS (Wi-Fi protected setup). WPSallows establishing a secure connection by introducing a PIN in the P2P Client,or pushing a button in the two P2P Devices. The P2P GO implements aRegistrar : generate keys for Clients with Extensible Authentication Protocolrequest/respond message. The device Registrar have the authority to issue andrevoke credentials to a network. The P2P Clients implements the Enrollee : itreconnect the Client to the network with new authentication credentials. Thedevice Enrollee seek to join a wireless network. The session will run on thewireless medium as a series of EAP request/response messages, ending withthe GO disassociating from the Enrollee Station and waiting for the EnrolleeStation to reconnect with its new configuration (handed to it by the GO justbefore).The session consists of sending 8 messages and, in case of succeed connection amessage indicate that the protocol is completed. The exact stream of messagesmay change when configuring different kinds of devices (AP or STA), or whenusing different physical media (wired or wireless).

5

Page 6: Android Application of instantaneous messaging service on ... · Android Application of instantaneous messaging service on link networks Rafaelle Botter / Jean-Marc Celesti Yohann

Figure 5: Formation

Once the group is formed, GO saves some informations about it ( P2P Clientmac address, SSID, and pass-phrase) in a configuration file, in order to not createa group next time again.

3.2 Autonomous Mode

Autonomous mode is typically the case where a device creates, alone a P2PGroup, and logically becomes the GO. Then, he starts to send beacons on achannel (management frames which contains informations about Network, SSIDFirst), and other devices can discover the group with a traditional scan. Becausethere is no GO Negociation, the discovery phase is simplified.

3.3 Persistent Mode

In this process, the GO declare the group as persistent. Information about theNetwork is saved in a configuration file, with a list of P2P client’s mac addresses.Thus, when a device who have already established a standard connection be-fore recognize the group, he can immediately reinstantiate the group, withoutentering a pin code or a push button method.

4 Joining a Group

There are two ways to join the group. By Wi-Fi Direct, as another P2P client,or by connecting to it as a classic AP if the device does not supports P2P

6

Page 7: Android Application of instantaneous messaging service on ... · Android Application of instantaneous messaging service on link networks Rafaelle Botter / Jean-Marc Celesti Yohann

client mode. In this case, it’s a different kind of client, named Legacy Client.Legacy devices exchange with the P2P GO as an AP, can also communicatewith the rest of local machines (as well as P2P clients as legacy ones) eventhey not formally belong to the P2P Group and do not support the enhancedfunctionalities defined in Wi-Fi Direct.You have to take care of a particular point, the GO or a P2P Client already inthe group can invite an outside device. If the P2P Client is asking to incorporatean outside device, the invite is transparently forwarded to the GO who receivesand choose to accept or not. If the GO is not on the range of the outside devicethe connection fail.An outside device can also ask the GO for joining the group but if the outsidedevice ask a P2P Client for joining the group, the connection of the outsidedevice will fail. On Samsung, a message ”device is already connect to anotherperipheral” is post, but on HP the invitation is sent and the P2P Client havethe message ”invited” but the connection never happened. It depends on theAndroid overlay.

Figure 6: Android 7d0c is already in a group where Android 4798 is the GO

5 Wi-Fi-Direct: The Wi-Fi to link peers

As we already said, the Wi-FI P2P is used to connect peers and what we willexplain in the following lines it’s how it’s works and to use P2P APIs availableon Android.

7

Page 8: Android Application of instantaneous messaging service on ... · Android Application of instantaneous messaging service on link networks Rafaelle Botter / Jean-Marc Celesti Yohann

Figure 7: Different classes for the Wi-Fi P2P

We will explain the five first classes here, and later the WifiP2pManager

• WifiP2PConfig

This class only represents the configuration of the Wi-Fi network, as theP2P GO intent or the WPS. ( see the 3.2.2 section ).

• WifiP2pDevice

This class represents the device , we can know if the device is the GOor also get device MAC address. With this P2pDevice class we can havethe device where we are working on or one of other devices all around, eventhose we are not connected on. In the following, we will see the methodsimplemented to discover nearby devices. Wifip2pDeviceList represents alist of P2pDevices, and we have a method to convert this list in collection.

• WifiP2pGroup

This class only represents a p2pgroup of devices: Related peers , we canget a lot of information as the group owner, the passphrase of the Networkon which they are or the client list.

• WifiP2pInfo

Indicates some information : if group has been well created formed orwho is the group owner and his address.

The figure 8 represents the architecture of our application. The differentparts are going to be explain in following.

8

Page 9: Android Application of instantaneous messaging service on ... · Android Application of instantaneous messaging service on link networks Rafaelle Botter / Jean-Marc Celesti Yohann

Figure 8: Architecture

5.1 Activity

The Activity is what it’s shown. An activity can be oncreate, onresume or on-pause. When the activity is working it is on stage: oncreate(). To build theinterface, a .xml file is needed and the Activity is related to this file thanksto the command: ”setContentView(R.layout.filename)” method. Of course wealso use the classical methods of Activity to put button, TextView...At the beginning the Wi-Fi has to be okay therefore an intent (we named it”filtre”) is created and actions about connections are added to it. After theintent tests those actions.

Figure 9: filtre’s adding action

The channel develops the Wi-Fi Direct methods and has to be initialized.The broadcast receiver enables to connect peers in Wi-Fi Direct and receives

9

Page 10: Android Application of instantaneous messaging service on ... · Android Application of instantaneous messaging service on link networks Rafaelle Botter / Jean-Marc Celesti Yohann

all the information about connection. It runs in background. The braodcastreceiver is choosed with ”registerReceiver(mReceiver, filtre);”, mReceiver is ourbroadcast receiver.Our Activity calls a WifiP2pManager who does everything. Our Activity it’s achat where connected devices can communicate thanks to a socket. The Socketreceiver runs in background.

6 WifiP2pManager class

The Wi-Fi Direct manager is the one who allows a lot of things in Wi-Fi directapplications. It controls everything.

6.1 Discovering and Connection to the peers

As you can see, the 5 first lines are here to allow the connection and use ofdiscovering peers. People can choose to connect peers by the application ormanually. When people try to connect peers by the application, the classWifip2pConnection extends of Broadcast receiver class is called.As it is said before the broadcast receiver will get all the information about theconnection. When we enter in the class Wifip2pconection we have to look aboutthe action of Wi-Fi ( see Figure 7) and according the state we can do someactions ( I invit you to look on android site, the diffents available).One thatinterests us is: ”WifiP2pManager.WIFI P2P PEERS CHANGED ACTION”

DiscoversPeers(Channel, WifiP2pManager.ActionListener) finds peers avail-able around, it is a scan. If the Action Listener interface works, it calls thebroadcast receiver. When peers change action, the list of peers available can berequest by requestpeers(Channel, WifiP2pManager.PeerListListener). It is notalways easy to understand how works listeners interface with Android for exam-ple with requestpeers(Channel,WifiP2pManager.PeerListListener). This sheetcode helps you to have access to peers:

requestpeers(channel, new WifiP2pManager.PeerListListener() {

public void onPeersAvailable(WifiP2pDeviceList peers){

Iterator it=peers.getDeviceList().iterator();

WifiP2pDevice device=it.next();

} });

The DeviceList ”peers” has been filled-in by the listener. The only way to ac-cess to available peers is on the methods onPeersAvalaible(WifiP2pDeviceListpeers) which has to be define in parameters of requestpeers(...) as it is shownbefore. It’s why the connection is done inside this method.

10

Page 11: Android Application of instantaneous messaging service on ... · Android Application of instantaneous messaging service on link networks Rafaelle Botter / Jean-Marc Celesti Yohann

public void onPeersAvailable(WifiP2pDeviceList peers) {

Iterator it = peers.getDeviceList().iterator();

WifiP2pConfig config = new WifiP2pConfig();

while (it.hasNext()) {

WifiP2pDevice device = (WifiP2pDevice) it.next();

if (!device.isGroupOwner()) {

Log.v("NOUS", "Je suis Maı̂tre");

} else {

Log.v("NOUS", "Je suis Esclave");

}

config.deviceAddress = device.deviceAddress;

mManager.connect(mChannel, config, new WifiP2pManager.ActionListener() {

onSuccess() { //do what you want if connection is a success}

onFailure() {//do what you want if connection is a failure }

});01

}

}

Figure 10: Discovering Peers

We can see on the Figure 8 the ”.equals(action)”, it’s only the current state

11

Page 12: Android Application of instantaneous messaging service on ... · Android Application of instantaneous messaging service on link networks Rafaelle Botter / Jean-Marc Celesti Yohann

of the device and we compare it to the discovering of peers (developer.androidfor more information on states). This device is requesting a peer, catch the listof peer and try to connect to them: As you can see, the line called:

mManager.connect(mChannel, config, new WifiP2pManager.ActionListener()

This line allows to devices to be connected, and mChannel it’s only the channelwhere the devices try to be connected.

6.2 Sockets

The secure connection is now established, let’s see the creation of the socketbetween the devices and the transmission of packet via UDP Sockets. Thereare 2 threads: SocketListener which enables to receive an UDP packet and aSocketSender that sends packets through the network.The advantages of Thread are they can be executed in the same time and it isdone in background. It means that people use the activity normally meanwhile.To create both class, they implement a runnable because they are threads. Theystart by getting the context and by getting permission for the socket to receivepacket from a multicast adress.

After the UDP socket has to be created with DatagramSocket() for the senderand MulticastSocket(port) for the receiver. (port 8888 has been choosen). ADatagramSocket uses DatagramPacket() which is composed of a buffer and thebuffer lenght to stock data, only that for the receiver, and for the sender, he hasto put the broadcast adress and the port where the receiver listens to moreover.

The receiver has an infinity loop because it has to check everytime if he hasa new message. To update the chat another thread, which is called at the be-ginning it is achieved by the runOnUiThread method which is a runnable to.

12

Page 13: Android Application of instantaneous messaging service on ... · Android Application of instantaneous messaging service on link networks Rafaelle Botter / Jean-Marc Celesti Yohann

Figure 11: Socket Listener

The MulticastLock is here to allow the multicast messaging.For the sender, it starts by writting the message. To send message in broad-

cast we have to use broadcast address. To find that one, get the address of thenetwork:”WifiManager.getConnectionInfo().getNetwork()” (for us it was 192.68.49/24)and use the broadcast address, for us: 192.68.49.255.It works because everytime the network chooses the same address.

13

Page 14: Android Application of instantaneous messaging service on ... · Android Application of instantaneous messaging service on link networks Rafaelle Botter / Jean-Marc Celesti Yohann

Figure 12: Socket Sender

6.3 Permissions

Figure 13: Socket Sender

The first 5 permissions it’s to allow to access to newtwork connection, as thewifi activation or the discovering peers. The last one it’s just to allow the useof a multicast adress.

14

Page 15: Android Application of instantaneous messaging service on ... · Android Application of instantaneous messaging service on link networks Rafaelle Botter / Jean-Marc Celesti Yohann

7 Wireshark Experiments

Although the main objective was to develop an Android chat app, It can bevery interesting to see what’s happen at a deeper OSI level, especially at datalink, network and transport layer.

To perform frames capturing, either you use Wireshark or tcpdump. Theydo the same thing, except the second is a command line tool. We decided touse wireshark because you don’t have to stop the capture in order to view theframes.

7.1 Need to Root

Important thing to say, for obvious reasons, by default, Android OS does notallow the user to view or edit some configuration files. Problem is, they containsome information that can be very useful to see how things work, such as Grouppassphrase or p2p clients.

That’s why, for those experiments we decided to root some tablets. Rootingis a software operation which let you access to all the functionalities of yourdevice, as a superuser (root). It’s not without risk, so be careful about whatyou are doing. There are plenty of tutorials over the Internet, we decided to useKingoRoot.

Note that we could have done without it, but it would have required muchmore material (to monitor traffic on each possible frequency channel), and moretime to implement it for recovering parameters.

7.2 Interfaces

A wireless mobile chip has two net interfaces : wlan0, used for classic Wi-Fi, and p2p0, exclusively used for Wi-Fi Direct. When a Direct connection isinitialized, a new interface can be created (instead of using p2p0), dependingon the wireless driver software implementation. Sometimes, this interface willbe called as p2p0, or p2p-wlan-0 or even p2p-p2p-0.only one has a not null IPAddress when connected.

Because a new p2p interface is added, we thought using the old p2p0 inter-face to connect the device to another P2P Group in direct mode, in order toperform multi hooping, which is, according to the theory, possible. Unfortu-nately, we didn’t manage to do it. If a device attempts to connect the GO, itautomatically joins the group. But if it attempts to connect a client, it facesthe Busy device problem (Figure 4).

Those interfaces has different MAC Addresses. Usually, they differ just byone Byte, that can be confusing when capturing traffic. The netcfg command

15

Page 16: Android Application of instantaneous messaging service on ... · Android Application of instantaneous messaging service on link networks Rafaelle Botter / Jean-Marc Celesti Yohann

gives informations about interfaces and their IPs Address of the network theyare on.

shell@redwood:/ netcfg

p2p0 UP 0.0.0.0/0 0x00001003 9a:3b:16:2e:9b:38

gre0 DOWN 0.0.0.0/0 0x00000080 00:00:00:00:00:00

sit0 DOWN 0.0.0.0/0 0x00000080 00:00:00:00:00:00

lo UP 127.0.0.1/8 0x00000049 00:00:00:00:00:00

tunl0 DOWN 0.0.0.0/0 0x00000080 00:00:00:00:00:00

wlan0 UP 0.0.0.0/0 0x00001003 98:3b:16:2e:9b:38

ip6tnl0 DOWN 0.0.0.0/0 0x00000080 00:00:00:00:00:00

p2p-p2p0-0 UP 192.168.49.180/24 0x00001043 9a:3b:16:2e:1b:38

How do they run with the same chip ? They use time sharing. Time sharingis a way to share the same resource by allocating some time to each interface.To control those interfaces, there is a linux portage software, wpa supplicant.

7.3 Wpa supplicant

Wpa supplicant is a linux open-source software which implements IEE802.11authentication mechanisms. In other words, it is a supplicant which controlsthe roaming and association of the wireless driver. Because Android is built ona linux Kernel (Debian), It can be possible to run it on mobile. By default, it’salready included. Type the command wpa_supplicant -v in root mode usingadb shell to ensure that.

Wpa supplicant is run as soon as Wi-Fi is enabled and uses two configurationfiles, wpa_supplicant.conf and p2p_supplicant.conf.the first one is for Wi-Fi configuration, keeps informations about registered networks (ssid, wpa-pskpassphrase) whereas the second is dedicated to Wi-Fi Direct. That’s the onewe’re interested in.

7.3.1 P2P supplicant.conf

This configuration file is a central element of our project. Loaded by the OSwhen someone tries to access to Wi-Fi Direct menu. It is written as below :

root@redwood:/ # cat data/misc/wifi/p2p_supplicant.conf

ctrl_interface=/data/misc/wifi/sockets

disable_scan_offload=1

driver_param=use_p2p_group_interface=1

update_config=1

16

Page 17: Android Application of instantaneous messaging service on ... · Android Application of instantaneous messaging service on link networks Rafaelle Botter / Jean-Marc Celesti Yohann

device_name=Android_43e6

device_type=10-0050F204-5

config_methods=virtual_push_button physical_display keypad

p2p_ssid_postfix=-Android_43e6

p2p_go_intent=15

p2p_listen_reg_class=81

p2p_listen_channel=1

p2p_oper_reg_class=81

p2p_oper_channel=1

persistent_reconnect=1

As you can see, you can edit directly the name of your device, as if youwere in the menu and choose the option ”Rename”, in WLAN Direct. If wetake a look at the second paragraph, we can see several parameters (for moreexplanations, go back to part 1) :

p2p go intent :As it said before (GO-Negotiation - Group Formation), the p2p go intent pa-rameter is the number beetween 0 and 15 to determine your desire to be a GO.By setting this number to the highest value, it is possible to force a device tobecome GO.

p2p listen channel :The p2p listen channel parameter is use to choose the channel where the devicewill perform the passive discovery. By setting this number to a specific value(1,6 or 11), you can predict where the negotiation will take place.

p2p oper channel :The p2p oper channel is the channel which the device will operate on if it is theGO. It can be very useful for monitoring.

7.4 Monitor Mode

When a laptop is connected to an AP, its wireless device is in managed mode.There are four different modes : managed, ad-hoc (for a point to point connec-tion), master (device is acting like an AP) and monitor mode, the one we use.Monitor mode allows the wireless device to capture all the WLAN traffic, with-out being connected to any AP. Monotoring can be excluisively on one singlechannel, and if not,software (tcpdump or Wireshark) will alternate beetweenseveral frequencies. You have to make sure that your device handles monitormode. The command iwlist can be used to check it.

chris@chris-HP-Pavilion-15-Notebook-PC:~\$ iw list

Supported interface modes:

* IBSS

17

Page 18: Android Application of instantaneous messaging service on ... · Android Application of instantaneous messaging service on link networks Rafaelle Botter / Jean-Marc Celesti Yohann

* managed

* AP

* AP/VLAN

* monitor

* mesh point

* P2P-client

* P2P-GO

Note : Some devices may handle monitor mode, but the driver only allowsto capture only broadcast packets.

7.5 Probe Requests

Capture Probe Request frame is, without a doubt, one of the easiest part.Clearly, you don’t have to be on a specific channel since Probe Request are senton several channels. To see those frames, just enable the WiFi-Direct Mode.Here is a screenshot,on Wireshark of a Probe Request frame, followed by a proberesponse. Take a look at the SSID, it’s only DIRECT-. There is no ssid postfixfor now.

Figure 14: A Probe Request frame

18

Page 19: Android Application of instantaneous messaging service on ... · Android Application of instantaneous messaging service on link networks Rafaelle Botter / Jean-Marc Celesti Yohann

Figure 15: And the Probe Response

Now devices have discovered, they can start a GO Negotiation.

7.6 The GO Negotiation

The Negotiation process occurs on channel 1,6 or 11, depending on devices’ lis-tening (p2p listen channel mentioned above) channel.

In order to capture those frames, we forced a device to become GO and tolisten and operate on channel 1. We had to know exactly on what channel willbe the Go Negotiation because the process is too short to capture if we alternatechannels.

To set your wireless adapter in monitor mode, on a single channel, type thosecommands :

sudo ifconfig wlanX down

sudo iwconfig wlanX mode monitor

sudo ifconfig wlanX up

sudo iwconfig wlanX channel Y

where X is the number of your adapter interface and Y the channel to use.You can check if it works with iwconfig command. For example, to monitoron channel 6 :

19

Page 20: Android Application of instantaneous messaging service on ... · Android Application of instantaneous messaging service on link networks Rafaelle Botter / Jean-Marc Celesti Yohann

chris@chris-HP-Pavilion-15-Notebook-PC:~ iwconfig

wlan1 IEEE 802.11bgn Mode:Monitor Frequency:2.437 GHz Tx-Power=20 dBm

Retry long limit:7 RTS thr:off Fragment thr:off

Power Management:off

Then, we can go on Wireshark and start capturing traffic. The Figure belowshows a GO Negotiation process. Use wlan.addr==yourMACaddress in the filtercase.

Figure 16: Go Negotiation Process in Wireshark

Once the group is formed, GO saves main information in its p2p supplicant.conf’sfile as below :

root@redwood:/ # cat data/misc/wifi/p2p_supplicant.conf

ctrl_interface=/data/misc/wifi/sockets

device_name=Android_43e6

device_type=10-0050F204-5

p2p_ssid_postfix=-Android_43e6

persistent_reconnect=1

network={

ssid="DIRECT-zo-Android_43e6"

bssid=9a:3b:16:2f:07:d1

psk="c5mMRRBl"

proto=RSN

key_mgmt=WPA-PSK

20

Page 21: Android Application of instantaneous messaging service on ... · Android Application of instantaneous messaging service on link networks Rafaelle Botter / Jean-Marc Celesti Yohann

pairwise=CCMP

auth_alg=OPEN

mode=3

disabled=2

p2p_client_list=12:30:47:49:1f:8d

}

The psk field is the passphrase of the group, the one you type if someonewould want to connect to the group as if it was an AP. The BSSID use thep2p0 interface, and there is the list of p2p clients. If a device join the groupby classic Wi-Fi (legacy client), its MAC address won’t be on the list.

7.7 2nd Connection

Now there is an existing group. The GO does not send Probe Request anymore,but beacons to announce its own group.

Figure 17: A softAP sending Beacons

When a device attempts to connect to an existent group, or a group it hasalready been, mechanisms authentication are not the same since there is no GONegotiation anymore. Authentication is provided by EAP protocol, and followsa 4-way handshake, where key are exchanged and passphrase is derived intoPSK key.

21

Page 22: Android Application of instantaneous messaging service on ... · Android Application of instantaneous messaging service on link networks Rafaelle Botter / Jean-Marc Celesti Yohann

Figure 18: 4-Way Handshake

8 Routing

8.1 Need to connect the group

Usually, for security issues, WLAN captured traffic is encrypted. It is encap-sulated into LLC layer or in a 802.11 encapsulation, means it’s not possible tosee the protocols. Wireshark allows the user to decrypt the frames if he has thekey, and that’s we had tried to do, before thinking about something much moresimple.

In the following, we are connected to P2P Group as legacy client. In thiscase it’s possible to see broadcast/multicast traffic, but the traffic beetween twopeers stills encrypted (But you can see it). There is no need to be in monitormode anymore, It is just as you wanted to sniff your own network.

8.2 Providing IP with DHCP

Soft AP has to perform a routing role, including give an IP address to localmachines. This funtionnality is achieved by a DHCP server. When a deviceattempts to join a group, it has no IP Address (0.0.0.0), so it will communicateon port 67 a DHCP DISCOVER. Soft AP answers by a DHCP OFFER, andthen, after the DHCP Server has assigned an IP Adress and communicatedsubnet mask, Client can talk to the others device on the Network.

Figure 19: DHCP Discover

22

Page 23: Android Application of instantaneous messaging service on ... · Android Application of instantaneous messaging service on link networks Rafaelle Botter / Jean-Marc Celesti Yohann

8.3 Capture Conversations

As the computer is connected to the p2p group as a legacy client, it is able tocapture broadcast traffic. Every device in a P2P group has an 192.168.49.x/24IP Address, and can communicate with other members in the group, as well asp2p clients as legacy ones. You can check it, using ifconfig on a computerand netcfgon an Emulator Konsole (or Adb shell)

chris@chris-HP-Pavilion-15-Notebook-PC:~ ifconfig

wlan1 Link encap:Ethernet HWaddr e8:de:27:08:f4:8e

inet adr:192.168.49.148 Bcast:192.168.49.255 Masque:255.255.255.0

adr inet6: fe80::eade:27ff:fe08:f48e/64 Scope:Lien

shell@redwood:/ netcfg

p2p0 UP 0.0.0.0/0 0x00001003 9a:3b:16:2e:9b:38

gre0 DOWN 0.0.0.0/0 0x00000080 00:00:00:00:00:00

sit0 DOWN 0.0.0.0/0 0x00000080 00:00:00:00:00:00

lo UP 127.0.0.1/8 0x00000049 00:00:00:00:00:00

tunl0 DOWN 0.0.0.0/0 0x00000080 00:00:00:00:00:00

wlan0 UP 0.0.0.0/0 0x00001003 98:3b:16:2e:9b:38

ip6tnl0 DOWN 0.0.0.0/0 0x00000080 00:00:00:00:00:00

p2p-p2p0-6 UP 192.168.49.181/24 0x00001043 9a:3b:16:2e:1b:38

When you send messages, you can capture them on Wireshark. Those arethe the UDP packets adressed to the Broadcast.

Figure 20: UDP packets of Conversation

23

Page 24: Android Application of instantaneous messaging service on ... · Android Application of instantaneous messaging service on link networks Rafaelle Botter / Jean-Marc Celesti Yohann

Figure 21: ChatOn

9 Progress

At this time, it is quite clear to create a network and to control it. A moredelicate point is to root packet to a network to another. The time-sharing orfrequency-sharing to allow a Group Owner to a network to be Client of anotheris not yet implemented on Android, programmer have to implement it them-selves. We found an easier way to do this transfer of packet: P2P Client andP2P Group Owner use the p2p0 interface to communicate and Legacy Clientuse wlan0.

Typically : we have two networks: Network 1 and Network 2 whith two GroupOwner : GO 1 and GO 2. For connect the two network together, GO 1 ask GO2 as GO 2 is an AP (it enter the pass-phrase). Then, GO 1 stay GO in Network1 and become Legacy Client in Network 2.Packet can be send to an interface to the other by the application (creation ofa second socket and transmission of the message to a socket to the other). Thisexplanation still theorical, we let the user make his own experiences on thatsubject.

24

Page 25: Android Application of instantaneous messaging service on ... · Android Application of instantaneous messaging service on link networks Rafaelle Botter / Jean-Marc Celesti Yohann

To experiment the routing, we implemented methods where the device whichis between the both networks catch the messages from network on send them tonetwork 2. Because this is a chat, when this device send the messages, it receivesthem too. This thing causes a infinity loop. To prevent this, A list of messagescould be implanted, and a check of messages in double, but it causes a lot oftroubles and difficulties to develop. When we implemented this methods, everytime we received an enormous number of the same message and the applicationcrashed

10 Conclusion

This paper bring together several part of our project. The aim was to makea clear paper to link practical to theory. This technology are going to becomeore and more use as people need connections. The aim was to create a networkto communicate without internet but only with the wifi p2p. This technologyis not really known, it is pretty similar to bluetooth but the bit rate is betterthan bluetooth. Our apllication ChatOn can send message inside a group withUDP socket in broadcast. Nonetheless communicate message between differentsgroups is harder, because differents groupOwners have to be connected togetherin Wifi, the wifip2p can’t do that with Android methods. Connecting differentsGroupOwners in Wifi is difficult because a passphrase is required. To transferdata and to chat without internet to people who are until 200 meters, wifip2pis a good solution.

11 Sources

For connection protocols:http://www.it.uc3m.es/pablo/papers/pdf/2012campscommagwifidirect.pdfhttp : //hsc.com/Portals/0//Uploads/Articles/WFDT echnologyWhitepaperv1.7635035318321315728.pdfhttp : //web.archive.org/web/20141218011646/http : //p2feed.com/

For Bluetooth and Wi-Fi Direct specifications:http://www.pcworld.com/article/208778/WiF iDirectvsBluetooth40ABattleforSupremacy.html?page =2https : //gtms1313.wordpress.com/2013/04/01/bluetooth4−0−vs−wi−fi−direct/

Whireshark:http://apps.evozi.com/apk-downloader/?id=com.magicandroidapps.iperfhttp://www.cs.technion.ac.il/ sakogan/DSL/2011/projects/iperf/user.html

Other students code source about Wi-Fi Direct multihop:http://anrg.usc.edu/ee5792012/Group02/Design.html

25

Page 26: Android Application of instantaneous messaging service on ... · Android Application of instantaneous messaging service on link networks Rafaelle Botter / Jean-Marc Celesti Yohann

Android developer tutorial:http://developer.android.com/guide/topics/connectivity/wifip2p.htmlhttp://developer.android.com/reference/android/net/wifi/p2p/package-summary.html

Other tutorials:http://www.tahlildadeh.com/EbooksTemp/android/Android%204%20New%20Features%20for%20Application%20Development.pdfpage =147

26