blob: d132e2885b13da6864929449643d7e7895aff599 [file] [log] [blame]
Alexandre Lision51140e12013-12-02 10:54:09 -05001/*
Alexandre Lisione24852d2014-02-04 13:13:02 -05002 Copyright (C) 2006-2007 Werner Dittmann
Alexandre Lision51140e12013-12-02 10:54:09 -05003
4 This program is free software: you can redistribute it and/or modify
Alexandre Lisione24852d2014-02-04 13:13:02 -05005 it under the terms of the GNU General Public License as published by
Alexandre Lision51140e12013-12-02 10:54:09 -05006 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18/*
19 * Authors: Werner Dittmann <Werner.Dittmann@t-online.de>
20 */
21
22#include <libzrtpcpp/ZrtpPacketSASrelay.h>
23
24ZrtpPacketSASrelay::ZrtpPacketSASrelay() {
25 DEBUGOUT((fprintf(stdout, "Creating SASrelay packet without data, no sl data\n")));
26 initialize();
27 setSignatureLength(0);
28}
29
30ZrtpPacketSASrelay::ZrtpPacketSASrelay(uint32_t sl) {
31 DEBUGOUT((fprintf(stdout, "Creating SASrelay packet without data\n")));
32 initialize();
33 setSignatureLength(sl);
34}
35
36void ZrtpPacketSASrelay::initialize() {
37 void* allocated = &data;
38 memset(allocated, 0, sizeof(data));
39
40 zrtpHeader = (zrtpPacketHeader_t *)&((SASrelayPacket_t *)allocated)->hdr; // the standard header
41 sasRelayHeader = (SASrelay_t *)&((SASrelayPacket_t *)allocated)->sasrelay;
42
43 setZrtpId();
44 setMessageType((uint8_t*)SasRelayMsg);
45}
46
47void ZrtpPacketSASrelay::setSignatureLength(uint32_t sl) {
48 sl &= 0x1ff; // make sure it is max 9 bits
49 int32_t length = sizeof(ConfirmPacket_t) + (sl * ZRTP_WORD_SIZE);
50 sasRelayHeader->sigLength = sl; // sigLength is a uint byte
51 if (sl & 0x100) { // check the 9th bit
52 sasRelayHeader->filler[1] = 1; // and set it if necessary
53 }
54 setLength(length / 4);
55}
56
57uint32_t ZrtpPacketSASrelay::getSignatureLength() {
58 uint32_t sl = sasRelayHeader->sigLength;
59 if (sasRelayHeader->filler[1] == 1) { // do we have a 9th bit
60 sl |= 0x100;
61 }
62 return sl;
63}
64
65ZrtpPacketSASrelay::ZrtpPacketSASrelay(uint8_t* data) {
66 DEBUGOUT((fprintf(stdout, "Creating SASrelay packet from data\n")));
67
68 allocated = NULL;
69 zrtpHeader = (zrtpPacketHeader_t *)&((SASrelayPacket_t *)data)->hdr; // the standard header
70 sasRelayHeader = (SASrelay_t *)&((SASrelayPacket_t *)data)->sasrelay;
71}
72
73ZrtpPacketSASrelay::~ZrtpPacketSASrelay() {
74 DEBUGOUT((fprintf(stdout, "Deleting SASrelay packet: alloc: %x\n", allocated)));
75}