Forum: WiFi Direct Pairing
- Hits: 7028
I wanted to create a post with some information and tips about the Wi-Fi Direct Pairing process used by the FTC apps to establish a point-to-point wireless connection.
The FTC apps need to be "paired" together before you can control your robot via the driver station. They use a technology called Wi-Fi Direct to establish this unique and persistent connect. The Robot Controller (RC) acts as the "Group Owner" (sort of like a wireless access point) and the Driver Station (DS) acts as a client connected to the Wi-Fi Direct network established by the group owner. Wi-Fi Direct gives you Bluetooth-like connectivity using the Wi-Fi (802.11) technology.
When you want to pair your DS to a RC, you should use the Pair with Robot Controller menu item of the FTC Driver Station App (accessed in the Settings menu from the main screen). When you launch the Pair with Robot Controller activity the DS does a quick Wi-Fi Direct scan to see what Wi-Fi Direct enabled devices are available. It actually will send probe requests on a few known channels (1, 6, and 11) and then listen for probe responses from other Wi-Fi Direct enabled devices. It uses this probe response information to generate a list of available devices that you can select from the Pair with Robot Controller activity.
When you make your selection and exit back to the main activity of the FTC Driver Station app, the DS will attempt to establish a Wi-Fi Direct connection with the RC. If it is a new connection, a dialog box will appear on the RC's screen and the user has to manually accept the connection request in order to establish the Wi-Fi Direct connection between the two devices. Once the connection is made, it will be persistent. This means that the next time you turn on your FTC Driver STation app, the app will attempt to pair with the RC that it had previously established a connection. If that RC is up and its FTC Robot Controller app running, the two devices will establish the Wi-Fi Direct connection automatically (the user does not have to accept the connection request a second time).
Here's an important tip - at some of the Pilot Test events last winter I noticed that some teams had been pairing their devices through the Wi-Fi Direct activity of the Android operating system. In general, I don't think you want to do this. Generally, you want to use the Pair With Robot Controller activity to pair your DS to an RC. You can use the Android's Wi-Fi Direct activity to do tasks like rename your device or if you want to forget previously remembered Wi-Fi Direct groups. HOwever, in general you should use the Pair with Robot Controller to pair your DS to an RC.
Potential problems with Wi-Fi Direct Discovery Process
The Wi-Fi Direct connections that are established by the FTC apps are fairly robust. They can tolerate a fair amount of activity and noise/interference on their operating channel and still work reliably. However, somewhat paradoxically, the Wi-Fi Direct Discovery Process can be sensitive to background noise and traffic on the Wi-Fi spectrum.
If you are at an event and you notice that your Android devices have difficulties pairing (either they were pre-paired and can't establish a connection or you are trying to pair the DS to the RC but you don't see the RC listed in the available devices list) then it could be that the traffic and noise in the vicinity is hindering the Wi-Fi Direct discovery process. Here are some steps you can do to help successfully pair your devices:
1. You can physically remove the two devices from the general crowd and attempt to pair the devices in isolation. Once the devices have been paired, they can stay connected in spite of background noise and interference . By removing the devices from the main group of devices the DS should be able to receive the probe responses from the target RC and be able to see and pair to the device properly.
2. If you have a large group of teams that are all trying to pair their devices simultaneously, it might be easier to pair the devices in smaller groups. Have one small group (group "A" for example) turn on their devices first and pair, then after group "A" is done, have the next small group do this and so on until all groups are turned on.
Again, once the devices are paired they should operate properly and be able to tolerate a fair amount of noise. However, the WiFi Direct discovery process can be sensitive to noise so pairing in isolation or pairing in batches might be options at very crowded venues.
Malformed Probe Response Packets
There is a bug in Android Kit Kat (and possibly in early versions of Lollipop - we think we've seen it during our testing with a Lollipop device or two) where an Android device that is doing a Wi-Fi Direct scan (to search for available devices in the area) will crash and reboot itself whenever it encounters a "malformed" packet. The bug was reported by a company called Core Security (http://www.coresecurity.com/advisori...denial-service) in early 2015. Google fixed the bug, but did not include a patch for Kit Kat. The ZTE Speed phone currently runs Kit Kat and is vulnerable to this issue.
Philbot (thanks Phil!!!) was the first person in our community to encounter and report this bug (http://ftcforum.usfirst.org/showthre...hlight=newline) with the ZTE devices and we've seen this happen elsewhere. What Phil reported is that if a newline character is embedded in the Wi-Fi Direct name of a device, it can cause other Kit Kat Android devices to reboot whenever the device tries to do a Wi-Fi Direct scan. This is an Android issue, and will occur if you do a Wi-Fi Direct scan from the Android Wi-Fi Direct activity. It will also occur when the FTC Driver STation app tries to do a scan to see what Wi-Fi Direct devices are nearby.
This is a very scary situation if you are unaware of the cause. What can happen is that all of the Android devices start mysteriously rebooting whenever you launch the FTC apps. What is happening is that the FTC Driver STation app will try to scan the network and see what available devices are nearby. It will encounter the malformed packet that has the newline character in its name and reboot because of the bug.
We have seen this happen a few times - the virtual keyboard on the ZTE Speeds are very small and users inadvertently hit the RETURN key when they are typing in the device name for their phone.
The way to address the problem is as follows,
1. See if you can identify the device that has the newline character in its name. Note that the name might look like it has an underscore ("_") character in it which might actually be a newline character. If you find the offending device, rename it to remove the newline character.
2. Pair your devices in isolation. Take your DS and RC phones to a place away from the crowd, pair them and then come back. ONce the devices have been paired they will not do a WiFi Direct scan (unless you power cycle the DS or swipe close the DS then relaunch it).
3. Pair your devices in batches. Turn all devices off first, then pair them in small groups one group at a time.
Again, once the devices are connected they should not need to do a WiFi direct scan and will not be vulnerable to this issue (unless you power cycle the DS or swipe close the DS app and then relaunch it).
Mischief Makers Take Note!
It is possible to artificially create malformed packets and inject them into the spectrum to target individual phones or all phones with this vulnerability. It is also possible to detect such the presence of such attacks. If you are thinking about creating malformed packets and injecting them to disrupt an event, or using some other DoS mechanism to disrupt an event you should reconsider. This is very un-GP behavior and you run the risk of getting caught. Any type of malicious attack is regarded as a very serious offense and it can result in instant disqualification from an event and possible additional consequences!
If you look in the WiFi Direct activity (go to Settings on your Android device, launch the Wi-Fi activity, then usually there is a WiFi Direct sub menu) you see "Remembered Groups" in the activity. These remembered groups get created whenever you connect to another Wi-Fi Direct device. The FTC apps should be able to operate, even if it there are a large number of remembered groups in the list. However, sometimes you might want to clean up and remove unused/unneeded remembered groups.
You simply long click/touch on a remembered group to bring up a dialog box ("Forget this group?"). Select OK to forget the group. Once you have cleaned up, you might need to shut down and then restart your Wi-Fi adapter (I usually just reboot the device).
Trouble Pairing... Are devices connected to other WiFi networks?
In our testing, we have occasionally seen the case where a DS has problems connecting to its RC or where it seems like it is connected (for instance the FTC Robot Controller app will look like it's connected to a driver station) but the DS is unable to connect properly to the RC. When we've seen this, we have noticed that sometimes the FTC Robot Controller is also connected to another Wi-fi network (for example to a Wireless access point to do wireless ADB for debugging).
We recommend that for competitions, teams make sure that both Android devices (DS and RC) are not connected to any other Wi-Fi or Wi-Fi direct network, with the exception of the Wi-Fi Direct connection between the two devices. If you notice that there are some connection issues with your devices and if either or both of the devices are connected to other Wi-Fi networks, try disconnecting and forgetting the other networks and rebooting the devices to see if the connection problems get resolved.
Don't Install FTC Driver Station Software on the same device as FTC Robot Controller Software
One common problem that I have seen is when someone installs both the FTC Robot Controller app and the FTC Driver STation app on the same device. This is not recommended. The FTC Robot Controller wants to be a group owner, while the FTC Driver Station wants to be a client. If both apps are installed and were run at some point on the same device, it could cause conflicts with the Wi-Fi direct settings.
I hope this info helps!
Please let me know if you have questions and be sure to help your fellow member of the FIRST community if they encounter any WiFi Direct issues.