Files
roytam1 35abf9a4e9 import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1207649: Prepare |BluetoothAddress| for general use throughout Bluetooth code, r=brsun (12c9761458)
- Bug 1207649: Convert Bluetooth Core backend to |BluetoothAddress|, r=brsun (0ca8bca611)
- Bug 1207649: Convert Bluetooth GATT backend to |BluetoothAddress|, r=joliu (baf3aabc35)
- Bug 1202386: Output clear Bluetooth IPC errors, r=shuang (805c1b886d)
- Bug 1204497: Interpret AVRCP remote features as bitmask, r=shuang (858bfc85f0)
- Bug 1207649: Remove obsolete string/address conversion from Bluetooth backend, r=brsun (18fc742a39)
- Bug 1209469: Expose |BluetoothAclState| in Bluetooth backend interface, r=brsun (452a5d8c4c)
- Bug 1209469: Expose |BluetoothPinCode| in Bluetooth backend interface, r=brsun (98d5c8489b)
- Bug 1186331: Check for \0 when parsing Bluetooth device names, r=btian (a4559805f7)
- Bug 1209469: Expose |BluetoothRemoteName| in Bluetooth backend interface, r=brsun (427212ca62)
- Bug 1209469: Expose |BluetoothServiceName| in Bluetooth backend interface, r=brsun (088cb2544e)
- Bug 1211948: Add interface class for Setup module to Bluetooth backend interface, r=brsun (4e1163d509)
- Bug 1203821 - [01] Add utility functions to convert big/little endianness and revise BluetoothPbapManager accordingly, r=shuang (34bcf3a373)
- Bug 1212729 - Handle illegal PBAP virtual folders path properly. r=btian (eaf1f9092b)
- Bug 1212725 - Convert relative paths of PBAP PullvCardListing to absolute path. r=btian (d2862cd8ac)
- Bug 1203821 - [02] Notify gaia of PBAP request with one integrated function, f=jaliu, r=shuang (c2e875b0f7)
- Bug 1215525: Update |BluetoothUuid| structure with c'tors and helper methods, r=brsun (44697b02d6)
- Bug 1221326 - use Endian.h more widely in bluetooth code; r=btian (94217af081)
- Bug 1166675 - Implement GetMessagesListing function, r=btian (e743afc62e)
- Bug 1166679 - Implement GetMessage function, r=btian (bf6c108a69)
- Bug 1186836 - Implement SetMessageStatus function, r=btian (2e163d29fd)
- Bug 1195710 - [MAP]Implement PushMessage function, r=btian (0efcf6dd0e)
- Bug 1166647 - Implement MAP bMessage class, r=btian (90ed64f17e)
- Bug 1184017 - [MAP] Dispatch events to MAP event handlers, r=btian, sr=mrbkap (32289cee15)
- Bug 1168298 - Support OBEX authentication procedure, r=shuang, r=mrbkap (24c07354f6)
- fix misspatch (f173366d27)
- Bug 1208492 - Handle MAP replies from Gaia and pass the results to BluetoothMapSmsManager, r=btian (1230cd8558)
- Bug 1216195 - use mozilla/Endian.h facilities in bluetooth code; r=btian (be77bb24a0)
- Bug 1207649: Convert Bluetooth A2DP backend to |BluetoothAddress|, r=shuang (30b71ac118)
- Bug 1202060: Store Bluetooth profile controller while (dis-)connecting AVRCP, r=shuang (0247a6db65)
- Bug 1204497: Complete AVRCP connect/disconnect from separate runnables, r=shuang (800a85b6dc)
- Bug 1207649: Convert Bluetooth Socket backend to |BluetoothAddress|, r=brsun (05c10fe2e0)
- Bug 1189315 - Add daemon interface for HFP WBS callback. r=tzimmermann (d60a8014d4)
- Bug 1207649: Convert Bluetooth Handsfree backend to |BluetoothAddress|, r=brsun (770e2a5ec2)
- Bug 1215525: Replace strings with Bluetooth addresses and UUIDs in Bluetooth mid-layer, r=brsun (e9409a5f08)
- Bug 1211769 - [MAP] Pack MAP replies to OBEX response packets, r=btain, sr=mrbkap (cbd72a044d)
- Bug 1226063 - take advantage of UniquePtr in BluetoothMapSmsManager::SendMasObexData; r=btian (80ea6465e8)
- Bug 1217339 - Fix illegal format of folder-listing object, r=btian (47739df63a)
- Bug 1221547 - part 1 - enable UnixSocketRawData to take ownership of a passed-in-buffer; r=tzimmerman (6971f7d47d)
- Bug 1207011 - Send Bluetooth OBEX End-of-Body header individually to improve the compatibility with other devices. r=btian (91164179a7)
- Bug 1221547 - part 2 - copy less data for file transfers over bluetooth; r=btian (5f87b8e38e)
- Bug 1203821 - [03] Restore missing bug 1212729 change, r=shuang (d0f384e58f)
- Bug 1218295 - Convert the relative path of PullvCardEntry to absolute path if PBAP request isn't using X-BT-UID. r=btian (6d88b2aa02)
- Bug 1221898 - Fix PBAP memory leakage, r=brsun (47735ba5b8)
- Bug 1224109 - [PBAP] Return early if OBEX authentication password is empty, r=shuang (dd2eab446b)
2023-01-14 11:31:20 +08:00

197 lines
4.8 KiB
C++

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "ObexBase.h"
BEGIN_BLUETOOTH_NAMESPACE
//
// Internal functions
//
/**
* Append byte array and length to header
*/
int
AppendHeader(uint8_t aHeaderId, uint8_t* aRetBuf, int aBufferSize,
const uint8_t* aData, int aLength)
{
int headerLength = aLength + 3;
int writtenLength = (headerLength < aBufferSize) ? headerLength : aBufferSize;
aRetBuf[0] = aHeaderId;
BigEndian::writeUint16(&aRetBuf[1], headerLength);
memcpy(&aRetBuf[3], aData, writtenLength - 3);
return writtenLength;
}
/**
* Append 4-byte integer to header
*/
int
AppendHeader(uint8_t aHeaderId, uint8_t* aRetBuf, int aValue)
{
aRetBuf[0] = aHeaderId;
BigEndian::writeInt32(&aRetBuf[1], aValue);
return 5;
}
//
// Exposed functions
//
int
AppendHeaderName(uint8_t* aRetBuf, int aBufferSize, const uint8_t* aName,
int aLength)
{
return AppendHeader(ObexHeaderId::Name, aRetBuf, aBufferSize,
aName, aLength);
}
int
AppendHeaderBody(uint8_t* aRetBuf, int aBufferSize, const uint8_t* aBody,
int aLength)
{
return AppendHeader(ObexHeaderId::Body, aRetBuf, aBufferSize,
aBody, aLength);
}
int
AppendHeaderTarget(uint8_t* aRetBuf, int aBufferSize, const uint8_t* aTarget,
int aLength)
{
return AppendHeader(ObexHeaderId::Target, aRetBuf, aBufferSize,
aTarget, aLength);
}
int
AppendHeaderWho(uint8_t* aRetBuf, int aBufferSize, const uint8_t* aWho,
int aLength)
{
return AppendHeader(ObexHeaderId::Who, aRetBuf, aBufferSize,
aWho, aLength);
}
int
AppendAuthResponse(uint8_t* aRetBuf, int aBufferSize, const uint8_t* aDigest,
int aLength)
{
return AppendHeader(ObexHeaderId::AuthResponse, aRetBuf, aBufferSize,
aDigest, aLength);
}
int
AppendHeaderAppParameters(uint8_t* aRetBuf, int aBufferSize,
const uint8_t* aAppParameters, int aLength)
{
return AppendHeader(ObexHeaderId::AppParameters, aRetBuf, aBufferSize,
aAppParameters, aLength);
}
int
AppendAppParameter(uint8_t* aRetBuf, int aBufferSize, const uint8_t aTagId,
const uint8_t* aValue, int aLength)
{
// An application parameter is a [tag]-[length]-[value] triplet. The [tag] and
// [length] fields are 1-byte length each.
if (aBufferSize < aLength + 2) {
// aBufferSize should be larger than size of AppParameter + header.
BT_WARNING("Return buffer size is too small for the AppParameter");
return 0;
}
aRetBuf[0] = aTagId;
aRetBuf[1] = aLength;
memcpy(&aRetBuf[2], aValue, aLength);
return aLength + 2;
}
int
AppendHeaderLength(uint8_t* aRetBuf, int aObjectLength)
{
return AppendHeader(ObexHeaderId::Length, aRetBuf, aObjectLength);
}
int
AppendHeaderConnectionId(uint8_t* aRetBuf, int aConnectionId)
{
return AppendHeader(ObexHeaderId::ConnectionId, aRetBuf, aConnectionId);
}
int
AppendHeaderEndOfBody(uint8_t* aRetBuf)
{
aRetBuf[0] = ObexHeaderId::EndOfBody;
aRetBuf[1] = 0x00;
aRetBuf[2] = 0x03;
return 3;
}
void
SetObexPacketInfo(uint8_t* aRetBuf, uint8_t aOpcode, int aPacketLength)
{
aRetBuf[0] = aOpcode;
BigEndian::writeUint16(&aRetBuf[1], aPacketLength);
}
bool
ParseHeaders(const uint8_t* aHeaderStart,
int aTotalLength,
ObexHeaderSet* aRetHandlerSet)
{
const uint8_t* ptr = aHeaderStart;
while (ptr - aHeaderStart < aTotalLength) {
ObexHeaderId headerId = (ObexHeaderId)*ptr++;
uint16_t contentLength = 0;
// Defined in 2.1 OBEX Headers, IrOBEX 1.2
switch (headerId >> 6)
{
case 0x00:
// Null-terminated Unicode text, length prefixed with 2-byte
// unsigned integer.
case 0x01:
// byte sequence, length prefixed with 2 byte unsigned integer.
contentLength = BigEndian::readUint16(ptr) - 3;
ptr += 2;
break;
case 0x02:
// 1 byte quantity
contentLength = 1;
break;
case 0x03:
// 4 byte quantity
contentLength = 4;
break;
}
// Length check to prevent from memory pollution.
if (ptr + contentLength > aHeaderStart + aTotalLength) {
// Severe error occurred. We can't even believe the received data, so
// clear all headers.
MOZ_ASSERT(false);
aRetHandlerSet->ClearHeaders();
return false;
}
aRetHandlerSet->AddHeader(new ObexHeader(headerId, contentLength, ptr));
ptr += contentLength;
}
return true;
}
END_BLUETOOTH_NAMESPACE