wpa_supplicant(hidl): Ensure P2P iface object is removed
The helper function used to determine if the removed interface is P2P or
not does not work in |unregisterInterface| method. This is because
supplicant core resets the internal pointers before notifying the HIDL
control interface.
Error Log being fixed:
01-30 12:57:17.081 4914 4914 D wpa_supplicant: Deregistering interface
from hidl control: p2p0
01-30 12:57:17.081 4914 4914 E wpa_supplicant: Failed to unregister
STA interface with HIDL control: p2p0
Bug: 72497243
Test: Able to close & start P2P settings multiple times & ensure P2P
still works (This triggers multiple P2P iface creation/deletion)
Change-Id: Ie52b4f8bc65e1a8abd40f577f717daea2f653853
diff --git a/wpa_supplicant/hidl/1.1/hidl_manager.cpp b/wpa_supplicant/hidl/1.1/hidl_manager.cpp
index 977f579..5d09a22 100644
--- a/wpa_supplicant/hidl/1.1/hidl_manager.cpp
+++ b/wpa_supplicant/hidl/1.1/hidl_manager.cpp
@@ -459,34 +459,31 @@
if (!wpa_s)
return 1;
- if (isP2pIface(wpa_s)) {
- if (removeHidlObjectFromMap(
- wpa_s->ifname, p2p_iface_object_map_)) {
- wpa_printf(
- MSG_ERROR,
- "Failed to unregister P2P interface with HIDL "
- "control: %s",
- wpa_s->ifname);
- return 1;
+ // Check if this interface is present in P2P map first, else check in
+ // STA map.
+ // Note: We can't use isP2pIface() here because interface
+ // pointers (wpa_s->global->p2p_init_wpa_s == wpa_s) used by the helper
+ // function is cleared by the core before notifying the HIDL interface.
+ bool success =
+ !removeHidlObjectFromMap(wpa_s->ifname, p2p_iface_object_map_);
+ if (success) { // assumed to be P2P
+ success = !removeAllIfaceCallbackHidlObjectsFromMap(
+ wpa_s->ifname, p2p_iface_callbacks_map_);
+ } else { // assumed to be STA
+ success = !removeHidlObjectFromMap(
+ wpa_s->ifname, sta_iface_object_map_);
+ if (success) {
+ success = !removeAllIfaceCallbackHidlObjectsFromMap(
+ wpa_s->ifname, sta_iface_callbacks_map_);
}
- if (removeAllIfaceCallbackHidlObjectsFromMap(
- wpa_s->ifname, p2p_iface_callbacks_map_)) {
- return 1;
- }
- } else {
- if (removeHidlObjectFromMap(
- wpa_s->ifname, sta_iface_object_map_)) {
- wpa_printf(
- MSG_ERROR,
- "Failed to unregister STA interface with HIDL "
- "control: %s",
- wpa_s->ifname);
- return 1;
- }
- if (removeAllIfaceCallbackHidlObjectsFromMap(
- wpa_s->ifname, sta_iface_callbacks_map_)) {
- return 1;
- }
+ }
+ if (!success) {
+ wpa_printf(
+ MSG_ERROR,
+ "Failed to unregister interface with HIDL "
+ "control: %s",
+ wpa_s->ifname);
+ return 1;
}
// Invoke the |onInterfaceRemoved| method on all registered callbacks.