/*
* (C) 2009,2010 by Holger Hans Peter Freyther <zecke@selfish.org>
* (C) 2009,2010 by On-Waves
* 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, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*/
#include <osmocom/core/byteswap.h>
#include <osmocom/gsm/gsm0808.h>
#include <osmocom/gsm/gsm0808_utils.h>
#include <osmocom/gsm/protocol/gsm_08_08.h>
#include <osmocom/gsm/gsm48.h>
/*! \addtogroup gsm0808
* @{
* \file gsm0808.c
* Helper functions regarding the TS 08.08 / 48.008 A interface, primarily
* message generation/encoding.
*/
/*! Create "Complete L3 Info" for AoIP, legacy implementation.
* Instead use gsm0808_create_layer3_aoip2(), which is capable of three-digit MNC with leading zeros.
* \param[in] msg_l3 msgb containing Layer 3 Message
* \param[in] nc Mobile Network Code
* \param[in] cc Mobile Country Code
* \param[in] lac Location Area Code
* \param[in] _ci Cell Identity
* \param[in] scl Speech Codec List
* \returns callee-allocated msgb with Complete L3 Info message */
struct msgb *gsm0808_create_layer3_aoip(const struct msgb *msg_l3, uint16_t nc,
uint16_t cc, int lac, uint16_t _ci,
const struct gsm0808_speech_codec_list
*scl)
{
struct osmo_cell_global_id cgi = {
.lai = {
.plmn = {
.mcc = cc,
.mnc = nc,
},
.lac = lac,
},
.cell_identity = _ci,
};
return gsm0808_create_layer3_2(msg_l3, &cgi, scl);
}
/*! Create "Complete L3 Info" for AoIP.
* \param[in] msg_l3 msgb containing Layer 3 Message -- not modified by this call.
* \param[in] cell MCC, MNC, LAC, CI to identify the cell.
* \param[in] scl Speech Codec List, optional.
* \returns newly allocated msgb with Complete L3 Info message */
struct msgb *gsm0808_create_layer3_2(const struct msgb *msg_l3, const struct osmo_cell_global_id *cell,
const struct gsm0808_speech_codec_list *scl)
{
struct msgb* msg;
struct {
uint8_t ident;
struct gsm48_loc_area_id lai;
uint16_t ci;
} __attribute__ ((packed)) lai_ci;
msg = msgb_alloc_headroom(BSSMAP_MSG_SIZE, BSSMAP_MSG_HEADROOM,
"bssmap cmpl l3");
if (!msg)
return NULL;
/* create layer 3 header */
msgb_v_put(msg, BSS_MAP_MSG_COMPLETE_LAYER_3);
/* create the cell header */
lai_ci.ident = CELL_IDENT_WHOLE_GLOBAL;
gsm48_generate_lai2(&lai_ci.lai, &cell->lai);
lai_ci.ci = osmo_htons(cell->cell_identity);
msgb_tlv_put(msg, GSM0808_IE_CELL_IDENTIFIER, sizeof(lai_ci),
(uint8_t *) &lai_ci);
/* copy the layer3 data */
msgb_tlv_put(msg, GSM0808_IE_LAYER_3_INFORMATION,
msgb_l3len(msg_l3),
|