/*
* (C) 2016 by sysmocom - s.f.m.c. GmbH, Author: Philipp Maier
* All Rights Reserved
*
* SPDX-License-Identifier: GPL-2.0+
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "config.h"
#include <osmocom/core/utils.h>
#include <osmocom/core/msgb.h>
#include <osmocom/core/byteswap.h>
#include <string.h>
#include <errno.h>
#include <osmocom/gsm/protocol/gsm_08_08.h>
#include <osmocom/gsm/gsm48.h>
#include <osmocom/gsm/gsm0808.h>
#include <osmocom/gsm/gsm0808_utils.h>
#define IP_V4_ADDR_LEN 4
#define IP_V6_ADDR_LEN 16
#define IP_PORT_LEN 2
#define CHANNEL_TYPE_ELEMENT_MAXLEN 11
#define CHANNEL_TYPE_ELEMENT_MINLEN 3
#define ENCRYPT_INFO_ELEMENT_MINLEN 1
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#include <netinet/in.h>
/*! \addtogroup gsm0808
* @{
* \file gsm0808_utils.c
*/
/*! Encode TS 08.08 AoIP Cause IE
* \param[out] msg Message Buffer to which to append IE
* \param[in] cause Cause code to be used in IE
* \returns number of bytes added to \a msg */
uint8_t gsm0808_enc_cause(struct msgb *msg, uint16_t cause)
{
/* See also 3GPP TS 48.008 3.2.2.5 Cause */
uint8_t *old_tail;
bool extended;
old_tail = msg->tail;
extended = gsm0808_cause_ext(cause >> 8);
msgb_put_u8(msg, GSM0808_IE_CAUSE);
if (extended) {
msgb_put_u8(msg, 2);
msgb_put_u16(msg, cause);
} else {
msgb_put_u8(msg, 1);
msgb_put_u8(msg, (uint8_t) (cause & 0xFF));
}
return (uint8_t) (msg->tail - old_tail);
}
/*! Encode TS 08.08 AoIP transport address IE
* \param[out] msg Message Buffer to which to append IE
* \param[in] ss Socket Address to be used in IE
* \returns number of bytes added to \a msg */
uint8_t gsm0808_enc_aoip_trasp_addr(struct msgb *msg,
const struct sockaddr_storage *ss)
{
/* See also 3GPP TS 48.008 3.2.2.102 AoIP Transport Layer Address */
struct sockaddr_in *sin;
struct sockaddr_in6 *sin6;
uint16_t port = 0;
uint8_t
|