tmatsugaki
Posts: 3
Joined: Tue Feb 18, 2020 11:50 pm

Bluetooth sometimes stops on AndroidThings (Raspberry pi model 3b)

Mon Feb 24, 2020 1:12 pm

I'm developing an application using BLE on AndroidThings on Raspberry pi model 3b.
Regrettably, sometimes alert popup with the message
Bluetooth has stopped
shows up on the Raspberry pi's console.
I've been casually using Bluetooth version both 3.x and 4.x on iPhones, Android phones and a general audio system for a long time, but I've never met instable states when using the above machines except for it (AndroidThings on Raspberry pi model 3b).
Is it a Raspberry pi model 3b specific problem?
Could you show me how to fix?

[Android Things]
Version: 8.1.0
API Level: 27
Build: OIM1.180327.097
Security patch level: Aug 1, 2019

Best,
Last edited by tmatsugaki on Fri Feb 28, 2020 1:00 am, edited 2 times in total.

Konsta
Posts: 177
Joined: Thu Aug 16, 2018 3:55 pm
Location: Finland
Contact: Website Twitter

Re: Bluetooth sometimes stops on AndroidThings (Raspberry pi model 3b+)

Tue Feb 25, 2020 7:06 am

That's certainly news if Android Things even boots on Pi 3 B+. Last I've checked it only supports Pi 3 B.

Pi 3 B and B+ have different wifi/bt hardware so that would explain why bluetooth is not working if you've really managed to boot it somehow.
KonstaKANG.com

tmatsugaki
Posts: 3
Joined: Tue Feb 18, 2020 11:50 pm

Re: Bluetooth sometimes stops on AndroidThings (Raspberry pi model 3b)

Fri Feb 28, 2020 12:58 am

Thank you for your reply!
I made a mistake on a model.
I used model 3b, not a model 3b+.
So I edited posts above.
I'm sorry!

[Bluetooth adapter states] seem to be right.
I/BluetoothAdapterState: Bluetooth adapter state changed: 10-> 14 STATE_OFF -> STATE_BLE_TURNING_ON
I/BluetoothAdapterState: Bluetooth adapter state changed: 14-> 15 STATE_BLE_TURNING_ON -> STATE_BLE_ON
I/BluetoothAdapterState: Bluetooth adapter state changed: 15-> 11 STATE_BLE_ON -> STATE_TURNING_ON
I/BluetoothAdapterState: Bluetooth adapter state changed: 11-> 12 STATE_TURNING_ON -> STATE_ON

As you know Android Things have some problems related to the Power Management.
So I've explored the result of the logcat.
There seemed to be the log outputs related to the Power Management regardless of using the Monitor with

Code: Select all

<uses-permission android:name="android.permission.WAKE_LOCK" />
.

2020-02-28 00:05:07.104 5973-6024/com.android.bluetooth I/bt_stack: [INFO:gatt_api.cc(1004)] GATT_Register
2020-02-28 00:05:07.104 5973-6024/com.android.bluetooth I/bt_stack: [INFO:gatt_api.cc(1027)] allocated gatt_if=5
2020-02-28 00:05:26.834 470-470/? E/wpa_supplicant: wpa_driver_nl80211_driver_cmd: failed to issue private command: BTCOEXMODE 1
2020-02-28 00:05:26.837 470-470/? E/wpa_supplicant: wpa_driver_nl80211_driver_cmd: failed to issue private command: SETSUSPENDMODE 0
2020-02-28 00:05:26.837 470-470/? I/wpa_supplicant: wlan0: CTRL-EVENT-DRIVER-STATE HANGED
2020-02-28 00:05:26.838 296-374/system_process E/SupplicantStaIfaceHal: ISupplicantStaIface.setSuspendModeEnabled failed: FAILURE_UNKNOWN,
2020-02-28 00:05:26.971 470-470/? E/wpa_supplicant: wpa_driver_nl80211_driver_cmd: failed to issue private command: BTCOEXMODE 2
2020-02-28 00:05:26.971 296-374/system_process E/SupplicantStaIfaceHal: ISupplicantStaIface.setBtCoexistenceMode failed: FAILURE_UNKNOWN,

https://android.googlesource.com/platfo ... _nl80211.c

Code: Select all

int wpa_driver_nl80211_driver_cmd(void *priv, char *cmd, char *buf,
				  size_t buf_len )
{
	struct i802_bss *bss = priv;
	struct wpa_driver_nl80211_data *drv = bss->drv;
	struct ifreq ifr;
	android_wifi_priv_cmd priv_cmd;
	int ret = 0;
	if (bss->ifindex <= 0 && bss->wdev_id > 0) {
		/* DRIVER CMD received on the DEDICATED P2P Interface which doesn't
		 * have an NETDEVICE associated with it. So we have to re-route the
		 * command to the parent NETDEVICE
		 */
		struct wpa_supplicant *wpa_s = (struct wpa_supplicant *)(drv->ctx);
		wpa_printf(MSG_DEBUG, "Re-routing DRIVER cmd to parent iface");
		if (wpa_s && wpa_s->parent) {
			/* Update the nl80211 pointers corresponding to parent iface */
			bss = wpa_s->parent->drv_priv;
			drv = bss->drv;
			wpa_printf(MSG_DEBUG, "Re-routing command to iface: %s"
					      " cmd (%s)", bss->ifname, cmd);
		}
	}
	if (os_strcasecmp(cmd, "STOP") == 0) {
		linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0);
		wpa_msg(drv->ctx, MSG_INFO, WPA_EVENT_DRIVER_STATE "STOPPED");
	} else if (os_strcasecmp(cmd, "START") == 0) {
		linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1);
		wpa_msg(drv->ctx, MSG_INFO, WPA_EVENT_DRIVER_STATE "STARTED");
	} else if (os_strcasecmp(cmd, "MACADDR") == 0) {
		u8 macaddr[ETH_ALEN] = {};
		ret = linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname, macaddr);
		if (!ret)
			ret = os_snprintf(buf, buf_len,
					  "Macaddr = " MACSTR "\n", MAC2STR(macaddr));
	} else { /* Use private command */
		os_memcpy(buf, cmd, strlen(cmd) + 1);
		memset(&ifr, 0, sizeof(ifr));
		memset(&priv_cmd, 0, sizeof(priv_cmd));
		os_strlcpy(ifr.ifr_name, bss->ifname, IFNAMSIZ);
#ifdef BCMDHD_64_BIT_IPC
		priv_cmd.bufaddr = (u64)(uintptr_t)buf;
#else
		priv_cmd.bufaddr = buf;
#endif
		priv_cmd.used_len = buf_len;
		priv_cmd.total_len = buf_len;
		ifr.ifr_data = &priv_cmd;
		if ((ret = ioctl(drv->global->ioctl_sock, SIOCDEVPRIVATE + 1, &ifr)) < 0) {
			wpa_printf(MSG_ERROR, "%s: failed to issue private command: %s", __func__, cmd);
			wpa_driver_send_hang_msg(drv);
		} else {
			drv_errors = 0;
			ret = 0;
			if ((os_strcasecmp(cmd, "LINKSPEED") == 0) ||
			    (os_strcasecmp(cmd, "RSSI") == 0) ||
			    (os_strcasecmp(cmd, "GETBAND") == 0) ||
			    (os_strncasecmp(cmd, "WLS_BATCHING", 12) == 0))
				ret = strlen(buf);
			wpa_driver_notify_country_change(drv->ctx, cmd);
			wpa_printf(MSG_DEBUG, "%s %s len = %d, %zu", __func__, buf, ret, strlen(buf));
		}
	}
	return ret;
}
https://android.googlesource.com/platfo ... ative.java

Code: Select all

    /**
      * Sets the bluetooth coexistence mode.
      *
      * @param mode One of {@link #BLUETOOTH_COEXISTENCE_MODE_DISABLED},
      *            {@link #BLUETOOTH_COEXISTENCE_MODE_ENABLED}, or
      *            {@link #BLUETOOTH_COEXISTENCE_MODE_SENSE}.
      * @return Whether the mode was successfully set.
      */
    public boolean setBluetoothCoexistenceMode(int mode) {
        return doBooleanCommand("DRIVER BTCOEXMODE " + mode);
    }
    /**
     * Enable or disable Bluetooth coexistence scan mode. When this mode is on,
     * some of the low-level scan parameters used by the driver are changed to
     * reduce interference with A2DP streaming.
     *
     * @param isSet whether to enable or disable this mode
     * @return {@code true} if the command succeeded, {@code false} otherwise.
     */
    public boolean setBluetoothCoexistenceScanMode(boolean setCoexScanMode) {
        if (setCoexScanMode) {
            return doBooleanCommand("DRIVER BTCOEXSCAN-START");
        } else {
            return doBooleanCommand("DRIVER BTCOEXSCAN-STOP");
        }
    }

Return to “Android”