Change WiFi-Direct IP range? Force IPv6 in Android

2019-05-08 23:52发布

问题:

I have two Android KitKat phones, both are running WiFi-Direct groups as Group Owners, let's call them GO1 and GO2

I managed to connect GO1 as a legacy client to GO2 without breaking any of the (previously set) wifi-direct groups.

The problem is that, as you might know, the GO IP address is hardcoded in Android source, and is set to 192.168.49.1

Therefore, both of my devices, GO1 and GO2 have the same IP address (**)... each on his local network.

My app is both client and server at the same time. But both networks are using the same IP range (192.168.49.XXX), which, apparently, I cannot change.

As a result I cannot create a TCP connection between them if they are both hosting a WiFi-Direct Group, since any device will connect to itself when trying to connect to 192.168.49.1

So the questions are:

  • Is there a way to change the IP range used in Wifi-Direct?
  • Is there a way to use IPv6 instead of IPv4 in Wifi-Direct?
  • Can any of this be done without rooting the phone?
  • Any other suggestion?

** : Actually, because GO1 is connecting as a legacy client to GO2, then GO1 is known as 192.168.49.227 (for example) to GO2 and GO2 is known as 192.168.49.1 to GO1. But because GO1 is ALSO a GO, it also known as 192.168.49.1 to his clients (and itself).

回答1:

There is no way to change the IP range because as you have correctly pointed out, it is hardcoded in the Android Wi-Fi Direct system service. Personally, I am not aware of IPv6 being enabled on the Wi-Fi P2P interface, and even if it was, it would likely be a hardcoded IPv6 address.

If GO1 and GO2, must be connected to each other whilst both in GO mode, then perhaps look at using Bluetooth or some other transport to allow them to communicate. If communication between GO1 and GO2 can be delayed, then cache whatever information is to be exchanged, and send it between these two devices when one can be the client of the other, e.g. when GO1 can stop being a GO and can be a client of GO2.



回答2:

A way to get around this without rooting the phone is to send your packets via multicast UDP*. These packets will make it from GO1 to GO2.

There are some side effects to this:

  • To use this for networking you must perform encapsulation and routing at the OSI Application level (not efficient).

  • You will also need to route based on MAC addresses since every device has the same 192.168.49.1 address.

  • "It is important to note that the multicast socket encapsulates a one-to-many unicast communication and, as a result of this, cannot fully utilize the total available WiFi and WiFi Direct bandwidth" *

Something else worth noting:

  • As you scale up the number of GOs, you will run into a problem of all nodes operating on the same wifi channel. This isn't a problem with a few devices, but with hundreds of devices, it will be a huge problem.

*This method was mentioned in Colin Funai, Cristiano Tapparello, and Wendi Heinzelman paper titled "Supporting Multi-hop Device-to-Device Networks Through WiFi Direct Multi-group Networking" found here: https://arxiv.org/pdf/1601.00028.pdf