blob: a76703d56bc4f497626b1b4942725c5cb1deb1b5 [file] [log] [blame]
Holger Hans Peter Freyther58db60c2013-11-13 20:45:40 +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#include "tbf.h"
Holger Hans Peter Freytherdf6b4f52013-11-24 17:05:48 +010020#include "bts.h"
21#include "gprs_debug.h"
Holger Hans Peter Freyther58db60c2013-11-13 20:45:40 +010022
23extern "C" {
24#include <osmocom/core/utils.h>
25}
26
27
28uint8_t *gprs_rlc_data::prepare(size_t block_data_len)
29{
30 /* todo.. only set it once if it turns out to be a bottleneck */
31 memset(block, 0x0, ARRAY_SIZE(block));
32 memset(block, 0x2b, block_data_len);
33
34 return block;
35}
Holger Hans Peter Freyther321f3c32013-11-23 16:06:54 +010036
37void gprs_rlc_v_b::reset()
38{
39 for (size_t i = 0; i < ARRAY_SIZE(m_v_b); ++i)
40 mark_invalid(i);
41}
Holger Hans Peter Freyther15777792013-11-24 00:18:47 +010042
43int gprs_rlc_v_b::resend_needed(const uint16_t v_a, const uint16_t v_s,
44 const uint16_t mod_sns,
45 const uint16_t mod_sns_half)
46{
47 for (uint8_t bsn = v_a; bsn != v_s; bsn = (bsn + 1) & mod_sns) {
48 uint16_t index = bsn & mod_sns_half;
49 if (is_nacked(index) || is_resend(index))
50 return bsn;
51 }
52
53 return -1;
54}
Holger Hans Peter Freyther8b16ae32013-11-24 00:38:54 +010055
56int gprs_rlc_v_b::mark_for_resend(const uint16_t v_a, const uint16_t v_s,
57 const uint16_t mod_sns,
58 const uint16_t mod_sns_half)
59{
60 int resend = 0;
61
62 for (uint8_t bsn = v_a; bsn != v_s; bsn = (bsn + 1) & mod_sns) {
63 uint16_t index = (bsn & mod_sns_half);
64 if (is_unacked(index)) {
65 /* mark to be re-send */
66 mark_resend(index);
67 resend += 1;
68 }
69 }
70
71 return resend;
72}
Holger Hans Peter Freytherdf6b4f52013-11-24 17:05:48 +010073
74void gprs_rlc_v_b::update(BTS *bts, char *show_rbb, uint8_t ssn,
75 const uint16_t v_a,
76 const uint16_t mod_sns, const uint16_t mod_sns_half,
77 uint16_t *lost, uint16_t *received)
78{
79 uint16_t bsn;
80 int i;
81
82 /* SSN - 1 is in range V(A)..V(S)-1 */
83 for (i = 63, bsn = (ssn - 1) & mod_sns;
84 i >= 0 && bsn != ((v_a - 1) & mod_sns);
85 i--, bsn = (bsn - 1) & mod_sns) {
86
87 if (show_rbb[i] == '1') {
88 LOGP(DRLCMACDL, LOGL_DEBUG, "- got ack for BSN=%d\n", bsn);
89 if (!is_acked(bsn & mod_sns_half))
90 *received += 1;
91 mark_acked(bsn & mod_sns_half);
92 } else {
93 LOGP(DRLCMACDL, LOGL_DEBUG, "- got NACK for BSN=%d\n", bsn);
94 mark_nacked(bsn & mod_sns_half);
95 bts->rlc_nacked();
96 *lost += 1;
97 }
98 }
99}
Holger Hans Peter Freythere358ff82013-11-24 17:13:10 +0100100
101int gprs_rlc_v_b::move_window(const uint16_t v_a, const uint16_t v_s,
102 const uint16_t mod_sns, const uint16_t mod_sns_half)
103{
104 int i;
105 uint16_t bsn;
106 int moved = 0;
107
108 for (i = 0, bsn = v_a; bsn != v_s; i++, bsn = (bsn + 1) & mod_sns) {
109 uint16_t index = (bsn & mod_sns_half);
110 if (is_acked(index)) {
111 mark_invalid(index);
112 moved += 1;
113 } else
114 break;
115 }
116
117 return moved;
118}
Holger Hans Peter Freytherbc155702013-11-24 17:20:35 +0100119
120void gprs_rlc_v_b::state(char *show_v_b, const uint16_t v_a, const uint16_t v_s,
121 const uint16_t mod_sns, const uint16_t mod_sns_half)
122{
123 int i;
124 uint16_t bsn;
125
126 for (i = 0, bsn = v_a; bsn != v_s; i++, bsn = (bsn + 1) & mod_sns) {
127 uint16_t index = (bsn & mod_sns_half);
128 show_v_b[i] = m_v_b[index];
129 if (show_v_b[i] == 0)
130 show_v_b[i] = ' ';
131 }
132 show_v_b[i] = '\0';
133}