17
WiFi Direct in Android Mobile and Ubiquitous Compu9ng MEIC/MERC 2015/16 Nuno Santos

WiFi$Directin$Android$ - INESC-IDwiki/courses/cmu1516/lab04/slides.pdf · WiFi$Directin$Android$ $ Mobile$and$Ubiquitous$Compu9ng$ MEIC/MERC$2015/16$ $ Nuno$Santos$

  • Upload
    others

  • View
    5

  • Download
    0

Embed Size (px)

Citation preview

Page 1: WiFi$Directin$Android$ - INESC-IDwiki/courses/cmu1516/lab04/slides.pdf · WiFi$Directin$Android$ $ Mobile$and$Ubiquitous$Compu9ng$ MEIC/MERC$2015/16$ $ Nuno$Santos$

WiFi  Direct  in  Android  

 Mobile  and  Ubiquitous  Compu9ng  

MEIC/MERC  2015/16    

Nuno  Santos  

Page 2: WiFi$Directin$Android$ - INESC-IDwiki/courses/cmu1516/lab04/slides.pdf · WiFi$Directin$Android$ $ Mobile$and$Ubiquitous$Compu9ng$ MEIC/MERC$2015/16$ $ Nuno$Santos$

WiFi  Direct:  What  Is  It?  

•  Wi-­‐Fi  Direct  allows  devices  to  connect  directly  to  each  other  using  methods  similar  to  tradi9onal  Wi-­‐Fi,  except  without  a  pre-­‐established  access  point  –  Instead,  they  nego9ate  to  establish  one  peer  device  to  act  as  a  soOware  access  point  for  all  the  other  devices  in  the  group  

Mobile  and  Ubiquitous  Compu9ng  2015/16   2  

Acts  as  SoOware  Access  Point  

Client  1  

Client  2  

Client  3  

Page 3: WiFi$Directin$Android$ - INESC-IDwiki/courses/cmu1516/lab04/slides.pdf · WiFi$Directin$Android$ $ Mobile$and$Ubiquitous$Compu9ng$ MEIC/MERC$2015/16$ $ Nuno$Santos$

Devices  Form  P2P  Groups  

•  WiFi  Direct  device  roles  – WiFi  AP  and  client  

•  Devices  form  P2P  Groups  –  Group  Owner  (GO)  is  the  AP    –  Clients  connect  to  the  GO  –  The  GO  assigns  IPs  to  clients  

Mobile  and  Ubiquitous  Compu9ng  2015/16   3  

GO  of  Group  

Clients  of  Group  

P2P  Group  

Page 4: WiFi$Directin$Android$ - INESC-IDwiki/courses/cmu1516/lab04/slides.pdf · WiFi$Directin$Android$ $ Mobile$and$Ubiquitous$Compu9ng$ MEIC/MERC$2015/16$ $ Nuno$Santos$

WiFi  Direct  Supports  Many  Topologies  

Mobile  and  Ubiquitous  Compu9ng  2015/16   4  

Page 5: WiFi$Directin$Android$ - INESC-IDwiki/courses/cmu1516/lab04/slides.pdf · WiFi$Directin$Android$ $ Mobile$and$Ubiquitous$Compu9ng$ MEIC/MERC$2015/16$ $ Nuno$Santos$

P2P  Groups  Must  Be  Managed  by  App  Developers  

1.  Group  forma9on  –  Discovery,  GO  nego9a9on,  Address  config  

2.  Data  transfer  3.  Group  tear  down  

Mobile  and  Ubiquitous  Compu9ng  2015/16   5  

Group  Forma,on  

Page 6: WiFi$Directin$Android$ - INESC-IDwiki/courses/cmu1516/lab04/slides.pdf · WiFi$Directin$Android$ $ Mobile$and$Ubiquitous$Compu9ng$ MEIC/MERC$2015/16$ $ Nuno$Santos$

THE  TERMITE  TESTBED  

Mobile  and  Ubiquitous  Compu9ng  2015/16   6  

Page 7: WiFi$Directin$Android$ - INESC-IDwiki/courses/cmu1516/lab04/slides.pdf · WiFi$Directin$Android$ $ Mobile$and$Ubiquitous$Compu9ng$ MEIC/MERC$2015/16$ $ Nuno$Santos$

Termite:  WiFi  Direct  Simulator  •  Wdirect  testable  only  w/  real  devices  

–  Emulator  does  not  emulate  WiFi  Direct  

•  Use  Termite  to  emulate  WDirect  nets  

•  Termite  consists  of:  –  Sandalone  console  –  Library  packaged  with  apps  

•  Tertmite  workings  –  Console  takes  net  topology  script  –  Fires  net  events  to  emulator  instances  –  Library  emulates  WDirect  events  –  App  captures  and  handles  WDSim  events  

 Mobile  and  Ubiquitous  Compu9ng  2015/16   7  

Termite Console

Emulator Instances w/ Termite Lib

Page 8: WiFi$Directin$Android$ - INESC-IDwiki/courses/cmu1516/lab04/slides.pdf · WiFi$Directin$Android$ $ Mobile$and$Ubiquitous$Compu9ng$ MEIC/MERC$2015/16$ $ Nuno$Santos$

App

Termite  SoOware  Architecture  

Mobile  and  Ubiquitous  Compu9ng  2015/16   8  

Android on Hardware

WiFi Direct API

Software Stack WiFi Direct

App

Android on Emulator

Software Stack WDSim

WDSim API

WDSim Console

Attention: Termite API not fully compatible with WDirect

Page 9: WiFi$Directin$Android$ - INESC-IDwiki/courses/cmu1516/lab04/slides.pdf · WiFi$Directin$Android$ $ Mobile$and$Ubiquitous$Compu9ng$ MEIC/MERC$2015/16$ $ Nuno$Santos$

WIFI  DIRECT  ON  ANDROID  

Mobile  and  Ubiquitous  Compu9ng  2015/16   9  

Page 10: WiFi$Directin$Android$ - INESC-IDwiki/courses/cmu1516/lab04/slides.pdf · WiFi$Directin$Android$ $ Mobile$and$Ubiquitous$Compu9ng$ MEIC/MERC$2015/16$ $ Nuno$Santos$

Finding  Nearby  Peers  

•  There  are  two  methods  of  finding  nearby  peers:  

–  Peer  discovery  finds  all  nearby  peers  with  WiFi  Direct  •  hap://developer.android.com/training/connect-­‐devices-­‐wirelessly/wifi-­‐direct.html    

–  Service  discovery  finds  all  nearby  peers  with  WiFi  Direct  that  are  running  the  same  app  •  hap://developer.android.com/training/connect-­‐devices-­‐wirelessly/nsd-­‐wifi-­‐direct.html    

Mobile  and  Ubiquitous  Compu9ng  2015/16   10  

Page 11: WiFi$Directin$Android$ - INESC-IDwiki/courses/cmu1516/lab04/slides.pdf · WiFi$Directin$Android$ $ Mobile$and$Ubiquitous$Compu9ng$ MEIC/MERC$2015/16$ $ Nuno$Santos$

Quirks  If  You  Use  Service  Discovery  •  In  order  to  find  each  other,  both  devices  must  call  

WiFiP2pManager.discoverServices,  not  just  one.  This  method  puts  the  devices  in  the  FIND  phase,  in  which  they  both  adver9se  and  listen  for  nearby  services.  If  you  do  not  call  WiFiP2pManager.discoverServices,  your  device  will  not  adver9se  itself,  and  other  devices  will  not  be  able  to  find  it.  Issue  report  on  the  Android  issue  tracker.  –  haps://code.google.com/p/android/issues/detail?id=37425    

•  The  Android  specifica9on  claims  that  service  discovery  con9nues  un9l  the  phone  finds  a  device,  but  it  was  not  very  reliable  in  our  tests.  Some9mes  devices  failed  to  find  each  other,  but  later  found  each  other  if  we  called  WiFiP2pManager.discoverServices  a  second  9me.  

Mobile  and  Ubiquitous  Compu9ng  2015/16   11  

Page 12: WiFi$Directin$Android$ - INESC-IDwiki/courses/cmu1516/lab04/slides.pdf · WiFi$Directin$Android$ $ Mobile$and$Ubiquitous$Compu9ng$ MEIC/MERC$2015/16$ $ Nuno$Santos$

Connect  to  Peers  

•  Follow  the  developer  guide:  –  hap://developer.android.com/guide/topics/connec9vity/wifip2p.html  

•  Quirks:  –  If  you  already  have  a  pending  connec9on  with  a  peer,  you  cannot  aaempt  to  connect  to  a  second  peer.  If  you  wish  to  automa9cally  connect  to  all  the  peers  you  discover,  you  must  add  the  devices  to  a  queue,  and  connect  to  them  one  at  a  9me.  We  recommend  sor9ng  peers  into  three  queues:  •  available  •  connec9ng  (max  size:  1)  •  connected  

Mobile  and  Ubiquitous  Compu9ng  2015/16   12  

Page 13: WiFi$Directin$Android$ - INESC-IDwiki/courses/cmu1516/lab04/slides.pdf · WiFi$Directin$Android$ $ Mobile$and$Ubiquitous$Compu9ng$ MEIC/MERC$2015/16$ $ Nuno$Santos$

Make  Peers  Talk  1/4  

•  Every  phone  has  a  MAC  address  and  an  IP  address.  By  the  nature  of  the  WiFi  Direct  connec9on,  the  group  owner  is  aware  of  all  the  clients  MAC  addresses,  but  the  clients  are  not  aware  of  each  other  

•  In  order  to  get  clients  to  talk  to  each  other,  they  must  be  aware  of  each  other.  To  solve  this  problem,  we  needed  to  make  the  group  owner  distribute  a  list  of  the  clients  MAC  and  IP  addresses  to  all  clients  

Mobile  and  Ubiquitous  Compu9ng  2015/16   13  

Page 14: WiFi$Directin$Android$ - INESC-IDwiki/courses/cmu1516/lab04/slides.pdf · WiFi$Directin$Android$ $ Mobile$and$Ubiquitous$Compu9ng$ MEIC/MERC$2015/16$ $ Nuno$Santos$

Make  Peers  Talk  2/4  

•  Unfortunately,  the  Wi-­‐Fi  Direct  API  does  not  give  the  group  owner  direct  access  to  the  IP  addresses  of  the  clients.  The  group  owner  only  has  access  to  its  clients’  MAC  addresses.  To  get  access  the  clients’  IP  addresses,  ini9ate  a  socket  connec9on  from  the  client  to  the  group  owner.  

Mobile  and  Ubiquitous  Compu9ng  2015/16   14  

Page 15: WiFi$Directin$Android$ - INESC-IDwiki/courses/cmu1516/lab04/slides.pdf · WiFi$Directin$Android$ $ Mobile$and$Ubiquitous$Compu9ng$ MEIC/MERC$2015/16$ $ Nuno$Santos$

Make  Peers  Talk  3/4  

•  Once  that  socket  connec9on  is  established,  the  client  can  send  a  string  containing  its  MAC  address  to  the  group  owner,  so  the  group  owner  would  be  able  to  add  the  IP  of  the  socket  connec9on  to  the  known  MAC  of  the  client,  thereby  crea9ng  a  MAC,  IP  pair  

Mobile  and  Ubiquitous  Compu9ng  2015/16   15  

Page 16: WiFi$Directin$Android$ - INESC-IDwiki/courses/cmu1516/lab04/slides.pdf · WiFi$Directin$Android$ $ Mobile$and$Ubiquitous$Compu9ng$ MEIC/MERC$2015/16$ $ Nuno$Santos$

Make  Peers  Talk  4/4  

•  The  group  owner  can  store  all  IP,  MAC  address  pairs  in  a  hashmap,  and  distribute  this  hash  map  via  socket  connec9on  back  to  all  the  clients  

Mobile  and  Ubiquitous  Compu9ng  2015/16   16  

Page 17: WiFi$Directin$Android$ - INESC-IDwiki/courses/cmu1516/lab04/slides.pdf · WiFi$Directin$Android$ $ Mobile$and$Ubiquitous$Compu9ng$ MEIC/MERC$2015/16$ $ Nuno$Santos$

Relevant  Pointers  •  android.net.wifi.p2p  

hap://developer.android.com/reference/android/net/wifi/p2p/package-­‐summary.html  

•  Connec9ng  with  Wi-­‐Fi  Directhap://developer.android.com/training/connect-­‐devices-­‐wirelessly/wifi-­‐direct.html  

 

Mobile  and  Ubiquitous  Compu9ng  2015/16   17