Android WiFi Direct P2P Connection always fails - android

I try to connect 2 Android devices via WiFi Direct so that I could use Miracast sometime but always get the same error.
Im working 3 days on that now but can't figure out, why this isnt working.
My logcat error:
I/wpa_supplicant( 4244): p2p0: P2P-FIND-STOPPED
D/myOnda ( 4533): onReceive action:android.net.wifi.p2p.DISCOVERY_STATE_CHANGE
D/myOnda ( 4533): Discovery state changed: 1 ->1:stop, 2:start
I/ethernet( 3755): event: NEWLINK(16), flags=0X1002
I/ethernet( 3755): flags: BC MC
I/ethernet( 3755): poll state :(null):17:
I/wpa_supplicant( 4244): p2p0: Failed to start AP functionality
V/EthernetStateTracker( 3755): report new state DISCONNECTED on dev (null) current=null
Ok it says "Failed to start AP functionality" but I just don't know how and where to solve that.
I try that connection 1 time with a Samsung Note Pro and 1 time with a Nexus 4 and it's always the same.
Another curious part is that the mac is always different from the original (found that here too).

Related

Why isn't the WIFI_P2P_CONNECTION_CHANGED_ACTION being detected by the broadcast receiver?

So this the first time I work with wifi-direct, I am trying to connect my android phone to a raspberry pi zero w over wifi-direct.
using this sample app on my android phone: https://github.com/ahmontero/wifi-direct-demo
I am able to get to the Connected state at the pi in the wpa_cli interface
and on the phone under the device name i see "connected" behind the progressDialog box that says "Connecting to 1e:67:58:4c:78:92" which should be dismissed after connecting but it isn't since WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION isn't being triggered after connecting.
my wpa_supplicant.conf:
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=LB
ap_scan=1
device_name=raspberry
device_type=1-0050F204-1
driver_param=use_p2p_group_interface=1
p2p_go_intent=7
p2p_go_ht40=1
p2p_listen_reg_class=81
p2p_listen_channel=1
p2p_oper_reg_class=81
p2p_oper_channel=1
and have done the following:
on the Pi:
$sudo wpa_supplicant -B -dd -iwlan0 -Dnl80211 -c /etc/wpa_supplicant/wpa_supplicant.conf
$sudo wpa_cli p2p-dev-wlan0
p2p_group_add
OK
<3>P2P-GROUP-STARTED p2p-wlan0-0 GO ssid="DIRECT-VC" freq=2412 passphrase="JrLfUAJf" go_dev_addr=5a:d3:65:e8:fc:e7
wps_pbc
OK
<3>P2P-DEVICE-FOUND 1e:67:58:4c:78:92 p2p_dev_addr=1e:67:58:4c:78:92 pri_dev_type=10-0050F204-5 name='HUAWEI' config_methods=0x188 dev_capab=0x25 group_capab=0x0 wfd_dev_info=0x00101c440032 new=1
<3>P2P-PROV-DISC-PBC-REQ 1e:67:58:4c:78:92 p2p_dev_addr=1e:67:58:4c:78:92 pri_dev_type=10-0050F204-5 name='HUAWEI' config_methods=0x188 dev_capab=0x25 group_capab=0x0
On the Phone:
I run the wifi direct sample app from google
and i can see the device with its info and when i click on connect i get stuck at connecting progressDialog and cant get passed that point to connected mode eventhough i see "connected" under device name.
the app seems to work fine between two phones but with a pi
this line in WiFiDirectBroadcastReceiver.java doesn't get executed when a connection has been made with the pi
} else if (WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION.equals(action))
however, when connection is lost after a timeout for example it gets triggered!
my question is what am i doing wrong here, why isn't the WIFI_P2P_CONNECTION_CHANGED_ACTION being detected by the broadcast receiver?
Note: phone is running Android 7.1
compileSdkVersion 26
targetSdkVersion 26
edit:
As Ben has pointed out in his answer below that I need to have a DHCP server running on the GO device (PI in my case), so I went ahead and installed and configured DHCP service on the pi by following the first section at this link https://www.raspberrypi.org/documentation/configuration/wireless/access-point.md
but, I can no longer run sudo wpa_supplicant -B -dd -iwlan0 -Dnl80211 -c /etc/wpa_supplicant/wpa_supplicant.conf command successfully as it might be clashing with the dhcp conf? any idea how i can enable p2p while running DHCP?
Well,
So as a part of GDPR (EU) implementation and similar things.
From android 8 & onwards there will be a restriction on the way by which android devices receive broadcast on any event (ofcourse to hide few device specific infos/specs.)
Please have a look at this:
https://developer.android.com/guide/components/broadcasts
Cheers.
Your Raspberry Pi is in the GO role and needs to act as a DHCP server. An Android device in the Client role will not broadcast WIFI_P2P_CONNECTION_CHANGED_ACTION until it has received an IP address from the GO via DHCP.
See my answer here for further details.

Samsung S5 and Note 4 July security update appears to have broken BLE

I'm looking for help finding a workaround for an issue that appears to be a problem with a recent security update for the Samsung S5 and Note 4 devices causing BLE device to not connect. The update was distributed by Verizon in early August and the Security Update date is: July 1, 2017 with a build number ending in DQF2. We are unable to connect to our BLE devices from the phones that have this specific update.
The BLE connection is made after scanning and finding the device. The scan works fine and devices are found normally but the connection goes nowhere. It's done like this:
BluetoothDevice device = mBtAdapter.getRemoteDevice(address);
device.connectGatt(context, true, btGattCallback);
However, I do not get any update from the callback is never notified of a connection with autoConnect = true, and with autoConnect = false, the callback only gets a connection update saying it disconnected (never gets to a connected state).
Before this update the connection was very reliable but fails 100% of the time since that update. Even a hard reset of the phone and BLE device and it still won't connect as well.
I've experimented with different things like making the connection on the main thread, ensuring that BLE scanning has stopped before connecting (we do this already but I added some extra delay as well in case of a race condition). I've added delays in different parts and experimented with both autoConnect on and off and no luck so far.
This definitely seems to be an issue with Samsung and I can see that the FitBit forums are lit up with users having this issue and while our product doesn't have as large of a base as FitBit it is effecting many people.
The only thing interesting I could find from logcat included:
08-12 14:11:17.848 4412-4602/? D/bt_upio: upio_set : pio 0 action 2, polarity 1
08-12 14:11:17.848 4412-4602/? D/bt_upio: BT_WAKE is asserted already
08-12 14:11:17.848 4412-4597/? D/BtGatt.GattService: [GSIM LOG]: increaseScanCount 4 Battery : com.myapp.internal.debug : 7
08-12 14:11:17.858 4412-4556/? D/bt_btif_gattc: btif_gattc_update_properties BLE device name=Axon-X81001976 len=14 dev_type=2
08-12 14:11:17.858 4412-4556/? E/bt_btif: property type:241, len:0 is invalid
08-12 14:11:17.858 4412-4556/? E/bt_btif_dm: ### ASSERT : system/bt/main/../btif/src/btif_dm.c line 4655 failed to save remote device manufacturer (1) ###
Other related threads:
VZW S5 thread
VZW Note 5 thread
Samsung Developer thread
Square contactless reader thread
Has anyone identified a way to make valid BLE connections on these devices?

Android Baidu push doesn't work with WiFi but works with cellular data

I have an Android app implemented which uses the Baidu push service. Baidu SDK version is 50 (jar lib is pushservice-5.0.0.66.jar).
Currently I see strange behavior: I get successful response in onBind (so I receive Baidu token). But if I use Wifi data, the app won't create a socket for Baidu.
With Baidu's debug mode enabled, I see this error:
com....:bdservice_v1 E/BDPushSDK-PushConnection: Create socket err, errno: 2socketfd: -1
com....:bdservice_v1 I/BDPushSDK-PushConnection: disconnectedByPeer, mStoped == false
com....:bdservice_v1 I/BDPushSDK-PushConnection: destroy
com....:bdservice_v1 I/BDPushSDK-PushConnection: Schedule retry-- retry times: 2 time delay: 30000*
It is hard to find any info about all these errors (this is all seems to be in Chinese). But seems that the Error 2 says smth like: "No such file or directory". Also I was getting before: Error 110 "Connection timed out". So this is not really helpful.
But the thing is that everything works when using cellular data.
It doesn't look like any local settings for my network, as many users report the same issue for WiFi.
com....:bdservice_v1 D/BDPushSDK-PushConnection: create Socket ok
com....:bdservice_v1 D/BDPushSDK-PushSDK: heartbeat set : 180 secs

Android UsbManager.openDevice(Device device) throw an Exception "device does not exist or be restricted"

I use a thread to send data to my usb-device (not data-storage) and get the return-data from device.
It worked fine in the first 5 minute. Data in, data out. (I almost start to sing in the sixth minute.)
Then suddenly it lost the connection.
There are the logcat message:
java.lang.IllegalArgumentException: device /dev/bus/usb/001/002 does not exist or is restricted
at android.os.Parcel.readException(Parcel.java:1331)
at android.os.Parcel.readException(Parcel.java:1281)
at android.hardware.usb.IUsbManager$Stub$Proxy.openDevice(IUsbManager.java:340)
at android.hardware.usb.UsbManager.openDevice(UsbManager.java:255)
So, I check the code of UsbManager, trying to find out what is the IUsbManager...
Cool. An interface... and there is zero information about what it is. That is why I am here.
Has anyone with any clue???
The app should be listening to the UsbManager.ACTION_USB_DEVICE_ATTACHED and UsbManager.ACTION_USB_DEVICE_DETACHED Intents. It should attempt to open the device received from the attached intent.
The error usually happens when the app tries to re-open the connection to a UsbDevice. When the UsbDevice reconnects it is assigned a new hardware address (Old: /dev/bus/usb/001/002, New: /dev/bus/usb/001/003).

Cleaning up failed UUID channel lookup

when opening a bluetooth rfcomm socket via the UUID method ( the other method ( using reflection ) in here http://code.google.com/p/android/issues/detail?id=5427 ) - I sometimes get the following error ( after successfull connections ) and the socket is not opened:
E/BluetoothService(21847): Received ACTION_UPDATE_SERVICE_CACHE00:0B:CE:01:2E:00
D/BluetoothService(21847): updateDeviceServiceChannelCache(00:0B:CE:01:2E:00)
D/BluetoothService(21847): Cleaning up failed UUID channel lookup: 00:0B:CE:01:2E:00 00001101-0000-1000-8000-00805f9b34fb
had no luck with google on this one - has anyone here a clue whats going on and how to prevent that?
Update:
for people running into the same problem - possible solutions:
advice the users to reboot the device if we run into that state (
very bad UX )
use the reflection method ( dirty but works most of the time )
I am still open for new Ideas ;-)
I stick to #2 at the moment - but waiting for a better solution.
It seems that the message is the consequence, not the reason. If a serial port emulation service is not found on device the connection will obviously fail.
Update
After reviewing code everything seems ok. So my questions are: Do the random errors occur with same device o with different devices? If the occur with different devices, the devices might have not registered the SerialPort service. Is device previously paired? In case of the error ocurring randomly with same device? Are you using the connection class concurrently? You have not protected the methods against concurrent access. You have not protected either against succesive connects. If you try to read/close a stream after a second connect it will fail (the socket object has changed).
It seems ok. The random error occurs with same device? If this is the case, are you using concurrent use of that class? In first case

Categories

Resources