blob: b22b1c208641b7fa931cefcb104a970249976206 [file] [log] [blame]
Holger Hans Peter Freytherbe570812013-11-07 08:01:49 +01001/*
2 * Copyright (C) 2013 by Holger Hans Peter Freyther
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (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, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18
19#pragma once
20
21#include <stdint.h>
Holger Hans Peter Freytheracb54272013-11-07 08:15:58 +010022#include <string.h>
Holger Hans Peter Freytherbe570812013-11-07 08:01:49 +010023
24#define LLC_MAX_LEN 1543
25
26/**
27 * I represent the LLC data to a MS
28 */
29struct gprs_llc {
Holger Hans Peter Freytherfce431c2013-11-13 15:17:12 +010030 static void calc_pdu_lifetime(BTS *bts, const uint16_t pdu_delay_csec, struct timeval *tv);
31
Holger Hans Peter Freytherbe570812013-11-07 08:01:49 +010032 void init();
33 void reset();
34 void reset_frame_space();
35
36 void enqueue(struct msgb *llc_msg);
37 struct msgb *dequeue();
38
Holger Hans Peter Freytherbe570812013-11-07 08:01:49 +010039 void put_frame(const uint8_t *data, size_t len);
Holger Hans Peter Freythere2310262013-11-13 16:56:15 +010040 void append_frame(const uint8_t *data, size_t len);
41
42 void consume(size_t len);
Holger Hans Peter Freytheracb54272013-11-07 08:15:58 +010043 void consume(uint8_t *data, size_t len);
Holger Hans Peter Freytherbe570812013-11-07 08:01:49 +010044 void clear(BTS *bts);
45
Holger Hans Peter Freytheracb54272013-11-07 08:15:58 +010046 uint16_t chunk_size() const;
Holger Hans Peter Freythere2310262013-11-13 16:56:15 +010047 uint16_t remaining_space() const;
48 uint16_t frame_length() const;
49
50 bool fits_in_current_frame(uint8_t size) const;
Holger Hans Peter Freytheracb54272013-11-07 08:15:58 +010051
Holger Hans Peter Freytherbe570812013-11-07 08:01:49 +010052 uint8_t frame[LLC_MAX_LEN]; /* current DL or UL frame */
53 uint16_t index; /* current write/read position of frame */
Holger Hans Peter Freythere2310262013-11-13 16:56:15 +010054 uint16_t m_length; /* len of current DL LLC_frame, 0 == no frame */
Holger Hans Peter Freytherbe570812013-11-07 08:01:49 +010055 struct llist_head queue; /* queued LLC DL data */
56};
57
Holger Hans Peter Freytheracb54272013-11-07 08:15:58 +010058inline uint16_t gprs_llc::chunk_size() const
59{
Holger Hans Peter Freythere2310262013-11-13 16:56:15 +010060 return m_length - index;
61}
62
63inline uint16_t gprs_llc::remaining_space() const
64{
65 return LLC_MAX_LEN - index;
66}
67
68inline uint16_t gprs_llc::frame_length() const
69{
70 return m_length;
71}
72
73inline void gprs_llc::consume(size_t len)
74{
75 index += len;
Holger Hans Peter Freytheracb54272013-11-07 08:15:58 +010076}
77
78inline void gprs_llc::consume(uint8_t *data, size_t len)
79{
80 /* copy and increment index */
81 memcpy(data, frame + index, len);
82 index += len;
83}
Holger Hans Peter Freythere2310262013-11-13 16:56:15 +010084
85inline bool gprs_llc::fits_in_current_frame(uint8_t chunk_size) const
86{
87 return index + chunk_size <= LLC_MAX_LEN;
88}