2012-09-28 19:09:29 +04:00
|
|
|
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
|
|
|
|
/* vim: set ts=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
|
|
|
|
|
|
|
|
int
|
2012-11-03 05:36:34 +04:00
|
|
|
AppendHeaderName(uint8_t* aRetBuf, const char* aName, int aLength)
|
2012-09-28 19:09:29 +04:00
|
|
|
{
|
2012-11-03 05:36:34 +04:00
|
|
|
int headerLength = aLength + 3;
|
2012-09-28 19:09:29 +04:00
|
|
|
|
2012-11-03 05:36:34 +04:00
|
|
|
aRetBuf[0] = ObexHeaderId::Name;
|
|
|
|
aRetBuf[1] = (headerLength & 0xFF00) >> 8;
|
|
|
|
aRetBuf[2] = headerLength & 0x00FF;
|
2012-09-28 19:09:29 +04:00
|
|
|
|
2012-11-03 05:36:34 +04:00
|
|
|
memcpy(&aRetBuf[3], aName, aLength);
|
2012-09-28 19:09:29 +04:00
|
|
|
|
|
|
|
return headerLength;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2012-11-03 05:36:34 +04:00
|
|
|
AppendHeaderBody(uint8_t* aRetBuf, uint8_t* aData, int aLength)
|
2012-09-28 19:09:29 +04:00
|
|
|
{
|
2012-11-03 05:36:34 +04:00
|
|
|
int headerLength = aLength + 3;
|
2012-09-28 19:09:29 +04:00
|
|
|
|
2012-11-03 05:36:34 +04:00
|
|
|
aRetBuf[0] = ObexHeaderId::Body;
|
|
|
|
aRetBuf[1] = (headerLength & 0xFF00) >> 8;
|
|
|
|
aRetBuf[2] = headerLength & 0x00FF;
|
2012-09-28 19:09:29 +04:00
|
|
|
|
2012-11-03 05:36:34 +04:00
|
|
|
memcpy(&aRetBuf[3], aData, aLength);
|
2012-09-28 19:09:29 +04:00
|
|
|
|
|
|
|
return headerLength;
|
|
|
|
}
|
|
|
|
|
2012-12-11 09:55:37 +04:00
|
|
|
int
|
|
|
|
AppendHeaderEndOfBody(uint8_t* aRetBuf)
|
|
|
|
{
|
|
|
|
aRetBuf[0] = ObexHeaderId::EndOfBody;
|
|
|
|
aRetBuf[1] = 0x00;
|
|
|
|
aRetBuf[2] = 0x03;
|
|
|
|
|
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
|
2012-09-28 19:09:29 +04:00
|
|
|
int
|
2012-11-03 05:36:34 +04:00
|
|
|
AppendHeaderLength(uint8_t* aRetBuf, int aObjectLength)
|
2012-09-28 19:09:29 +04:00
|
|
|
{
|
2012-11-03 05:36:34 +04:00
|
|
|
aRetBuf[0] = ObexHeaderId::Length;
|
|
|
|
aRetBuf[1] = (aObjectLength & 0xFF000000) >> 24;
|
|
|
|
aRetBuf[2] = (aObjectLength & 0x00FF0000) >> 16;
|
|
|
|
aRetBuf[3] = (aObjectLength & 0x0000FF00) >> 8;
|
|
|
|
aRetBuf[4] = aObjectLength & 0x000000FF;
|
2012-09-28 19:09:29 +04:00
|
|
|
|
|
|
|
return 5;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2012-11-03 05:36:34 +04:00
|
|
|
AppendHeaderConnectionId(uint8_t* aRetBuf, int aConnectionId)
|
2012-09-28 19:09:29 +04:00
|
|
|
{
|
2012-11-03 05:36:34 +04:00
|
|
|
aRetBuf[0] = ObexHeaderId::ConnectionId;
|
|
|
|
aRetBuf[1] = (aConnectionId & 0xFF000000) >> 24;
|
|
|
|
aRetBuf[2] = (aConnectionId & 0x00FF0000) >> 16;
|
|
|
|
aRetBuf[3] = (aConnectionId & 0x0000FF00) >> 8;
|
|
|
|
aRetBuf[4] = aConnectionId & 0x000000FF;
|
2012-09-28 19:09:29 +04:00
|
|
|
|
|
|
|
return 5;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-11-03 05:36:34 +04:00
|
|
|
SetObexPacketInfo(uint8_t* aRetBuf, uint8_t aOpcode, int aPacketLength)
|
2012-09-28 19:09:29 +04:00
|
|
|
{
|
2012-11-03 05:36:34 +04:00
|
|
|
aRetBuf[0] = aOpcode;
|
|
|
|
aRetBuf[1] = (aPacketLength & 0xFF00) >> 8;
|
|
|
|
aRetBuf[2] = aPacketLength & 0x00FF;
|
2012-09-28 19:09:29 +04:00
|
|
|
}
|
|
|
|
|
2012-11-08 05:46:31 +04:00
|
|
|
void
|
|
|
|
ParseHeaders(const uint8_t* aHeaderStart,
|
|
|
|
int aTotalLength,
|
|
|
|
ObexHeaderSet* aRetHandlerSet)
|
2012-09-28 19:09:29 +04:00
|
|
|
{
|
2012-11-08 05:46:31 +04:00
|
|
|
const uint8_t* ptr = aHeaderStart;
|
2012-10-31 07:15:12 +04:00
|
|
|
|
|
|
|
while (ptr - aHeaderStart < aTotalLength) {
|
2012-11-08 05:46:31 +04:00
|
|
|
ObexHeaderId headerId = (ObexHeaderId)*ptr++;
|
2012-09-28 19:09:29 +04:00
|
|
|
|
2012-10-17 10:48:52 +04:00
|
|
|
int contentLength = 0;
|
2012-09-28 19:09:29 +04:00
|
|
|
uint8_t highByte, lowByte;
|
|
|
|
|
|
|
|
// Defined in 2.1 OBEX Headers, IrOBEX 1.2
|
|
|
|
switch (headerId >> 6)
|
|
|
|
{
|
|
|
|
case 0x00:
|
2012-10-31 07:15:12 +04:00
|
|
|
// NULL terminated Unicode text, length prefixed with 2-byte
|
|
|
|
// unsigned integer.
|
2012-09-28 19:09:29 +04:00
|
|
|
case 0x01:
|
|
|
|
// byte sequence, length prefixed with 2 byte unsigned integer.
|
|
|
|
highByte = *ptr++;
|
|
|
|
lowByte = *ptr++;
|
2012-10-17 10:48:52 +04:00
|
|
|
contentLength = (((int)highByte << 8) | lowByte) - 3;
|
2012-09-28 19:09:29 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x02:
|
|
|
|
// 1 byte quantity
|
2012-10-17 10:48:52 +04:00
|
|
|
contentLength = 1;
|
2012-09-28 19:09:29 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x03:
|
|
|
|
// 4 byte quantity
|
2012-10-17 10:48:52 +04:00
|
|
|
contentLength = 4;
|
2012-09-28 19:09:29 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-12-21 15:03:42 +04:00
|
|
|
aRetHandlerSet->AddHeader(new ObexHeader(headerId, contentLength, ptr));
|
2012-09-28 19:09:29 +04:00
|
|
|
|
2012-10-17 10:48:52 +04:00
|
|
|
ptr += contentLength;
|
2012-09-28 19:09:29 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
END_BLUETOOTH_NAMESPACE
|