fix byte order and packet accounting

This commit is contained in:
Gilles Boccon-Gibod
2023-10-10 21:17:20 -07:00
parent 246b11925c
commit 5e5c9c2580
3 changed files with 32 additions and 16 deletions

View File

@@ -156,7 +156,7 @@ class HciAidlHal extends android.hardware.bluetooth.IBluetoothHciCallbacks.Stub
private static final String TAG = "HciAidlHal";
private final android.hardware.bluetooth.IBluetoothHci mHciService;
private final HciHalCallback mHciCallbacks;
private int mInitializationStatus = android.hardware.bluetooth.Status.SUCCESS; //-1;
private int mInitializationStatus = android.hardware.bluetooth.Status.SUCCESS;
public static HciAidlHal create(HciHalCallback hciCallbacks) {
IBinder binder = ServiceManager.getService("android.hardware.bluetooth.IBluetoothHci/default");
@@ -233,7 +233,7 @@ class HciAidlHal extends android.hardware.bluetooth.IBluetoothHciCallbacks.Stub
// IBluetoothHciCallbacks methods.
@Override
public /* synchronized */ void initializationComplete(int status) throws RemoteException {
public synchronized void initializationComplete(int status) throws RemoteException {
mInitializationStatus = status;
notifyAll();
}

View File

@@ -4,22 +4,10 @@ import static java.lang.Integer.min;
import java.io.ByteArrayOutputStream;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
class HciParser {
enum State {
NEED_TYPE,
NEED_LENGTH,
NEED_BODY
}
interface Sink {
void onPacket(HciPacket.Type type, byte[] packet);
}
static class InvalidFormatException extends RuntimeException {
}
Sink sink;
State state;
int bytesNeeded;
@@ -51,7 +39,9 @@ class HciParser {
bytesNeeded = packetType.lengthOffset + packetType.lengthSize;
state = State.NEED_LENGTH;
} else if (state == State.NEED_LENGTH) {
ByteBuffer lengthBuffer = ByteBuffer.wrap(packet.toByteArray());
ByteBuffer lengthBuffer =
ByteBuffer.wrap(packet.toByteArray())
.order(ByteOrder.LITTLE_ENDIAN);
bytesNeeded = packetType.lengthSize == 1 ?
lengthBuffer.get(packetType.lengthOffset) & 0xFF :
lengthBuffer.getShort(packetType.lengthOffset) & 0xFFFF;
@@ -79,4 +69,15 @@ class HciParser {
packet.reset();
packetType = null;
}
enum State {
NEED_TYPE, NEED_LENGTH, NEED_BODY
}
interface Sink {
void onPacket(HciPacket.Type type, byte[] packet);
}
static class InvalidFormatException extends RuntimeException {
}
}

View File

@@ -24,6 +24,21 @@ public class HciProxy {
@Override
public void onPacket(HciPacket.Type type, byte[] packet) {
mServer.sendPacket(type, packet);
switch (type) {
case EVENT:
mEventPacketsSent += 1;
break;
case ACL_DATA:
mAclPacketsSent += 1;
break;
case SCO_DATA:
mScoPacketsSent += 1;
break;
}
updateHciPacketCount();
}
});
if (hciHal == null) {