2013-11-07 07:01:49 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2013 by Holger Hans Peter Freyther
|
|
|
|
*
|
|
|
|
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2015-06-15 09:19:13 +00:00
|
|
|
extern "C" {
|
|
|
|
#include <osmocom/core/linuxlist.h>
|
|
|
|
}
|
|
|
|
|
2013-11-07 07:01:49 +00:00
|
|
|
#include <stdint.h>
|
2013-11-07 07:15:58 +00:00
|
|
|
#include <string.h>
|
2020-03-11 13:04:52 +00:00
|
|
|
#include <time.h>
|
2013-11-07 07:01:49 +00:00
|
|
|
|
|
|
|
#define LLC_MAX_LEN 1543
|
|
|
|
|
2015-06-02 09:28:07 +00:00
|
|
|
struct BTS;
|
|
|
|
|
2013-11-07 07:01:49 +00:00
|
|
|
/**
|
|
|
|
* I represent the LLC data to a MS
|
|
|
|
*/
|
|
|
|
struct gprs_llc {
|
2015-03-20 11:02:42 +00:00
|
|
|
static bool is_user_data_frame(uint8_t *data, size_t len);
|
2013-11-13 14:17:12 +00:00
|
|
|
|
2013-11-07 07:01:49 +00:00
|
|
|
void init();
|
|
|
|
void reset();
|
|
|
|
void reset_frame_space();
|
|
|
|
|
|
|
|
void put_frame(const uint8_t *data, size_t len);
|
2015-03-20 12:57:27 +00:00
|
|
|
void put_dummy_frame(size_t req_len);
|
2013-11-13 15:56:15 +00:00
|
|
|
void append_frame(const uint8_t *data, size_t len);
|
|
|
|
|
|
|
|
void consume(size_t len);
|
2013-11-07 07:15:58 +00:00
|
|
|
void consume(uint8_t *data, size_t len);
|
2013-11-07 07:01:49 +00:00
|
|
|
|
2013-11-07 07:15:58 +00:00
|
|
|
uint16_t chunk_size() const;
|
2013-11-13 15:56:15 +00:00
|
|
|
uint16_t remaining_space() const;
|
|
|
|
uint16_t frame_length() const;
|
|
|
|
|
|
|
|
bool fits_in_current_frame(uint8_t size) const;
|
2013-11-07 07:15:58 +00:00
|
|
|
|
2013-11-07 07:01:49 +00:00
|
|
|
uint8_t frame[LLC_MAX_LEN]; /* current DL or UL frame */
|
2013-11-13 16:14:42 +00:00
|
|
|
uint16_t m_index; /* current write/read position of frame */
|
2013-11-13 15:56:15 +00:00
|
|
|
uint16_t m_length; /* len of current DL LLC_frame, 0 == no frame */
|
2015-05-29 08:37:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* I store the LLC frames that come from the SGSN.
|
|
|
|
*/
|
|
|
|
struct gprs_llc_queue {
|
2015-06-15 12:32:33 +00:00
|
|
|
struct MetaInfo {
|
2020-03-11 13:04:52 +00:00
|
|
|
struct timespec recv_time;
|
|
|
|
struct timespec expire_time;
|
2015-06-15 12:32:33 +00:00
|
|
|
};
|
|
|
|
|
2015-06-16 08:18:42 +00:00
|
|
|
static void calc_pdu_lifetime(BTS *bts, const uint16_t pdu_delay_csec,
|
2020-03-11 13:04:52 +00:00
|
|
|
struct timespec *tv);
|
|
|
|
static bool is_frame_expired(const struct timespec *now,
|
|
|
|
const struct timespec *tv);
|
2015-05-29 08:37:09 +00:00
|
|
|
static bool is_user_data_frame(uint8_t *data, size_t len);
|
|
|
|
|
|
|
|
void init();
|
|
|
|
|
2020-03-11 13:04:52 +00:00
|
|
|
void enqueue(struct msgb *llc_msg, const struct timespec *expire_time);
|
2015-06-15 12:32:33 +00:00
|
|
|
struct msgb *dequeue(const MetaInfo **info = 0);
|
2015-05-29 08:37:09 +00:00
|
|
|
void clear(BTS *bts);
|
2015-08-21 16:07:47 +00:00
|
|
|
void move_and_merge(gprs_llc_queue *o);
|
2015-05-29 08:37:09 +00:00
|
|
|
size_t size() const;
|
2015-06-15 09:05:44 +00:00
|
|
|
size_t octets() const;
|
2013-12-04 16:10:54 +00:00
|
|
|
|
2015-05-29 08:37:09 +00:00
|
|
|
private:
|
2013-12-04 17:11:47 +00:00
|
|
|
uint32_t m_avg_queue_delay; /* Average delay of data going through the queue */
|
2013-12-04 16:10:54 +00:00
|
|
|
size_t m_queue_size;
|
2015-06-15 09:05:44 +00:00
|
|
|
size_t m_queue_octets;
|
2015-05-29 08:37:09 +00:00
|
|
|
struct llist_head m_queue; /* queued LLC DL data */
|
|
|
|
|
2013-11-07 07:01:49 +00:00
|
|
|
};
|
|
|
|
|
2015-05-29 08:37:09 +00:00
|
|
|
|
2013-11-07 07:15:58 +00:00
|
|
|
inline uint16_t gprs_llc::chunk_size() const
|
|
|
|
{
|
2013-11-13 16:14:42 +00:00
|
|
|
return m_length - m_index;
|
2013-11-13 15:56:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline uint16_t gprs_llc::remaining_space() const
|
|
|
|
{
|
2013-11-21 20:30:23 +00:00
|
|
|
return LLC_MAX_LEN - m_length;
|
2013-11-13 15:56:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline uint16_t gprs_llc::frame_length() const
|
|
|
|
{
|
|
|
|
return m_length;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void gprs_llc::consume(size_t len)
|
|
|
|
{
|
2013-11-13 16:14:42 +00:00
|
|
|
m_index += len;
|
2013-11-07 07:15:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void gprs_llc::consume(uint8_t *data, size_t len)
|
|
|
|
{
|
|
|
|
/* copy and increment index */
|
2013-11-13 16:14:42 +00:00
|
|
|
memcpy(data, frame + m_index, len);
|
|
|
|
consume(len);
|
2013-11-07 07:15:58 +00:00
|
|
|
}
|
2013-11-13 15:56:15 +00:00
|
|
|
|
|
|
|
inline bool gprs_llc::fits_in_current_frame(uint8_t chunk_size) const
|
|
|
|
{
|
2013-11-21 20:30:23 +00:00
|
|
|
return m_length + chunk_size <= LLC_MAX_LEN;
|
2013-11-13 15:56:15 +00:00
|
|
|
}
|
2015-05-29 08:37:09 +00:00
|
|
|
|
|
|
|
inline size_t gprs_llc_queue::size() const
|
|
|
|
{
|
2016-06-07 12:31:29 +00:00
|
|
|
return m_queue_size;
|
2015-05-29 08:37:09 +00:00
|
|
|
}
|
2015-06-15 09:05:44 +00:00
|
|
|
|
|
|
|
inline size_t gprs_llc_queue::octets() const
|
|
|
|
{
|
2016-06-07 12:31:29 +00:00
|
|
|
return m_queue_octets;
|
2015-06-15 09:05:44 +00:00
|
|
|
}
|