Alexandre Lision | 51140e1 | 2013-12-02 10:54:09 -0500 | [diff] [blame] | 1 | /* |
Alexandre Lision | ddd731e | 2014-01-31 11:50:08 -0500 | [diff] [blame] | 2 | Copyright (C) 2006-2007 Werner Dittmann |
Alexandre Lision | 51140e1 | 2013-12-02 10:54:09 -0500 | [diff] [blame] | 3 | |
| 4 | This program is free software: you can redistribute it and/or modify |
Alexandre Lision | ddd731e | 2014-01-31 11:50:08 -0500 | [diff] [blame] | 5 | it under the terms of the GNU General Public License as published by |
Alexandre Lision | 51140e1 | 2013-12-02 10:54:09 -0500 | [diff] [blame] | 6 | 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 | |
| 24 | ZrtpPacketSASrelay::ZrtpPacketSASrelay() { |
| 25 | DEBUGOUT((fprintf(stdout, "Creating SASrelay packet without data, no sl data\n"))); |
| 26 | initialize(); |
| 27 | setSignatureLength(0); |
| 28 | } |
| 29 | |
| 30 | ZrtpPacketSASrelay::ZrtpPacketSASrelay(uint32_t sl) { |
| 31 | DEBUGOUT((fprintf(stdout, "Creating SASrelay packet without data\n"))); |
| 32 | initialize(); |
| 33 | setSignatureLength(sl); |
| 34 | } |
| 35 | |
| 36 | void 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 | |
| 47 | void 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 | |
| 57 | uint32_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 | |
| 65 | ZrtpPacketSASrelay::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 | |
| 73 | ZrtpPacketSASrelay::~ZrtpPacketSASrelay() { |
| 74 | DEBUGOUT((fprintf(stdout, "Deleting SASrelay packet: alloc: %x\n", allocated))); |
| 75 | } |