зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1221326 - use Endian.h more widely in bluetooth code; r=btian
This commit is contained in:
Родитель
7397339686
Коммит
555ffcc8b5
|
@ -502,8 +502,7 @@ BluetoothMapSmsManager::ReplyToConnect()
|
|||
|
||||
req[3] = 0x10; // version=1.0
|
||||
req[4] = 0x00; // flag=0x00
|
||||
req[5] = BluetoothMapSmsManager::MAX_PACKET_LENGTH >> 8;
|
||||
req[6] = (uint8_t)BluetoothMapSmsManager::MAX_PACKET_LENGTH;
|
||||
BigEndian::writeUint16(&req[5], BluetoothMapSmsManager::MAX_PACKET_LENGTH);
|
||||
|
||||
// Section 6.4 "Establishing an OBEX Session", MapSms 1.2
|
||||
// Headers: [Who:16][Connection ID]
|
||||
|
|
|
@ -866,8 +866,7 @@ BluetoothOppManager::ComposePacket(uint8_t aOpCode, UnixSocketBuffer* aMessage)
|
|||
// [opcode:1][length:2][Headers:var]
|
||||
frameHeaderLength = 3;
|
||||
|
||||
mPacketLength = ((static_cast<int>(data[1]) << 8) | data[2]) -
|
||||
frameHeaderLength;
|
||||
mPacketLength = BigEndian::readUint16(&data[1]) - frameHeaderLength;
|
||||
|
||||
/**
|
||||
* A PUT request from remote devices may be divided into multiple parts.
|
||||
|
@ -1119,7 +1118,7 @@ BluetoothOppManager::ClientDataHandler(UnixSocketBuffer* aMessage)
|
|||
// Keep remote information
|
||||
mRemoteObexVersion = data[3];
|
||||
mRemoteConnectionFlags = data[4];
|
||||
mRemoteMaxPacketLength = ((static_cast<int>(data[5]) << 8) | data[6]);
|
||||
mRemoteMaxPacketLength = BigEndian::readUint16(&data[5]);
|
||||
|
||||
// The length of file name exceeds maximum length.
|
||||
int fileNameByteLen = (mFileName.Length() + 1) * 2;
|
||||
|
|
|
@ -242,7 +242,7 @@ BluetoothPbapManager::ReceiveSocketData(BluetoothSocket* aSocket,
|
|||
}
|
||||
|
||||
// Save the max packet length from remote information
|
||||
mRemoteMaxPacketLength = ((static_cast<int>(data[5]) << 8) | data[6]);
|
||||
mRemoteMaxPacketLength = BigEndian::readUint16(&data[5]);
|
||||
|
||||
if (mRemoteMaxPacketLength < kObexLeastMaxSize) {
|
||||
BT_LOGR("Remote maximum packet length %d is smaller than %d bytes",
|
||||
|
|
|
@ -842,8 +842,7 @@ BluetoothOppManager::ComposePacket(uint8_t aOpCode, UnixSocketBuffer* aMessage)
|
|||
// [opcode:1][length:2][Headers:var]
|
||||
frameHeaderLength = 3;
|
||||
|
||||
mPacketLength = ((static_cast<int>(data[1]) << 8) | data[2]) -
|
||||
frameHeaderLength;
|
||||
mPacketLength = BigEndian::readUint16(&data[1]) - frameHeaderLength;
|
||||
/**
|
||||
* A PUT request from remote devices may be divided into multiple parts.
|
||||
* In other words, one request may need to be received multiple times,
|
||||
|
@ -1094,7 +1093,7 @@ BluetoothOppManager::ClientDataHandler(UnixSocketBuffer* aMessage)
|
|||
// Keep remote information
|
||||
mRemoteObexVersion = data[3];
|
||||
mRemoteConnectionFlags = data[4];
|
||||
mRemoteMaxPacketLength = (static_cast<int>(data[5]) << 8) | data[6];
|
||||
mRemoteMaxPacketLength = BigEndian::readUint16(&data[5]);
|
||||
|
||||
// The length of file name exceeds maximum length.
|
||||
int fileNameByteLen = (mFileName.Length() + 1) * 2;
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
|
||||
#include <algorithm>
|
||||
#include "mozilla/Compiler.h"
|
||||
#include "mozilla/Endian.h"
|
||||
#include "mozilla/Observer.h"
|
||||
#include "nsAutoPtr.h"
|
||||
#include "nsPrintfCString.h"
|
||||
|
@ -496,14 +497,12 @@ struct BluetoothAddress {
|
|||
|
||||
uint16_t GetNAP() const
|
||||
{
|
||||
return (static_cast<uint16_t>(mAddr[4])) |
|
||||
(static_cast<uint16_t>(mAddr[5]) << 8);
|
||||
return LittleEndian::readUint16(&mAddr[4]);
|
||||
}
|
||||
|
||||
void SetNAP(uint16_t aNAP)
|
||||
{
|
||||
mAddr[4] = aNAP;
|
||||
mAddr[5] = aNAP >> 8;
|
||||
LittleEndian::writeUint16(&mAddr[4], aNAP);
|
||||
}
|
||||
|
||||
};
|
||||
|
@ -635,10 +634,7 @@ struct BluetoothUuid {
|
|||
|
||||
void SetUuid32(uint32_t aUuid32)
|
||||
{
|
||||
mUuid[0] = static_cast<uint8_t>(0xff & (aUuid32 >> 24));
|
||||
mUuid[1] = static_cast<uint8_t>(0xff & (aUuid32 >> 16));
|
||||
mUuid[2] = static_cast<uint8_t>(0xff & (aUuid32 >> 8));
|
||||
mUuid[3] = static_cast<uint8_t>(0xff & (aUuid32));
|
||||
BigEndian::writeUint32(&mUuid[0], aUuid32);
|
||||
mUuid[4] = 0x00;
|
||||
mUuid[5] = 0x00;
|
||||
mUuid[6] = 0x10;
|
||||
|
@ -655,10 +651,7 @@ struct BluetoothUuid {
|
|||
|
||||
uint32_t GetUuid32() const
|
||||
{
|
||||
return (static_cast<uint32_t>(mUuid[0]) << 24) |
|
||||
(static_cast<uint32_t>(mUuid[1]) << 16) |
|
||||
(static_cast<uint32_t>(mUuid[2]) << 8) |
|
||||
(static_cast<uint32_t>(mUuid[3]));
|
||||
return BigEndian::readUint32(&mUuid[0]);
|
||||
}
|
||||
|
||||
void SetUuid16(uint16_t aUuid16)
|
||||
|
@ -668,8 +661,7 @@ struct BluetoothUuid {
|
|||
|
||||
uint16_t GetUuid16() const
|
||||
{
|
||||
return (static_cast<uint16_t>(mUuid[2]) << 8) |
|
||||
(static_cast<uint16_t>(mUuid[3]));
|
||||
return BigEndian::readUint16(&mUuid[2]);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -23,8 +23,7 @@ AppendHeader(uint8_t aHeaderId, uint8_t* aRetBuf, int aBufferSize,
|
|||
int writtenLength = (headerLength < aBufferSize) ? headerLength : aBufferSize;
|
||||
|
||||
aRetBuf[0] = aHeaderId;
|
||||
aRetBuf[1] = (headerLength & 0xFF00) >> 8;
|
||||
aRetBuf[2] = headerLength & 0x00FF;
|
||||
BigEndian::writeUint16(&aRetBuf[1], headerLength);
|
||||
memcpy(&aRetBuf[3], aData, writtenLength - 3);
|
||||
|
||||
return writtenLength;
|
||||
|
@ -37,10 +36,7 @@ int
|
|||
AppendHeader(uint8_t aHeaderId, uint8_t* aRetBuf, int aValue)
|
||||
{
|
||||
aRetBuf[0] = aHeaderId;
|
||||
aRetBuf[1] = (aValue & 0xFF000000) >> 24;
|
||||
aRetBuf[2] = (aValue & 0x00FF0000) >> 16;
|
||||
aRetBuf[3] = (aValue & 0x0000FF00) >> 8;
|
||||
aRetBuf[4] = aValue & 0x000000FF;
|
||||
BigEndian::writeInt32(&aRetBuf[1], aValue);
|
||||
|
||||
return 5;
|
||||
}
|
||||
|
@ -135,8 +131,7 @@ void
|
|||
SetObexPacketInfo(uint8_t* aRetBuf, uint8_t aOpcode, int aPacketLength)
|
||||
{
|
||||
aRetBuf[0] = aOpcode;
|
||||
aRetBuf[1] = (aPacketLength & 0xFF00) >> 8;
|
||||
aRetBuf[2] = aPacketLength & 0x00FF;
|
||||
BigEndian::writeUint16(&aRetBuf[1], aPacketLength);
|
||||
}
|
||||
|
||||
bool
|
||||
|
@ -150,7 +145,6 @@ ParseHeaders(const uint8_t* aHeaderStart,
|
|||
ObexHeaderId headerId = (ObexHeaderId)*ptr++;
|
||||
|
||||
uint16_t contentLength = 0;
|
||||
uint8_t highByte, lowByte;
|
||||
|
||||
// Defined in 2.1 OBEX Headers, IrOBEX 1.2
|
||||
switch (headerId >> 6)
|
||||
|
@ -160,9 +154,8 @@ ParseHeaders(const uint8_t* aHeaderStart,
|
|||
// unsigned integer.
|
||||
case 0x01:
|
||||
// byte sequence, length prefixed with 2 byte unsigned integer.
|
||||
highByte = *ptr++;
|
||||
lowByte = *ptr++;
|
||||
contentLength = (((uint16_t)highByte << 8) | lowByte) - 3;
|
||||
contentLength = BigEndian::readUint16(ptr) - 3;
|
||||
ptr += 2;
|
||||
break;
|
||||
|
||||
case 0x02:
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#define mozilla_dom_bluetooth_ObexBase_h
|
||||
|
||||
#include "BluetoothCommon.h"
|
||||
#include "mozilla/Endian.h"
|
||||
#include "nsAutoPtr.h"
|
||||
#include "nsTArray.h"
|
||||
|
||||
|
@ -178,7 +179,7 @@ public:
|
|||
uint8_t* ptr = mHeaders[i]->mData.get();
|
||||
|
||||
for (int j = 0; j < nameLength; ++j) {
|
||||
char16_t c = ((((uint32_t)ptr[j * 2]) << 8) | ptr[j * 2 + 1]);
|
||||
char16_t c = BigEndian::readUint16(&ptr[j * 2]);
|
||||
aRetName += c;
|
||||
}
|
||||
|
||||
|
@ -211,10 +212,7 @@ public:
|
|||
for (int i = 0; i < length; ++i) {
|
||||
if (mHeaders[i]->mId == ObexHeaderId::Length) {
|
||||
uint8_t* ptr = mHeaders[i]->mData.get();
|
||||
*aRetLength = ((uint32_t)ptr[0] << 24) |
|
||||
((uint32_t)ptr[1] << 16) |
|
||||
((uint32_t)ptr[2] << 8) |
|
||||
((uint32_t)ptr[3]);
|
||||
*aRetLength = BigEndian::readUint32(&ptr[0]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче