Holger Hans Peter Freyther | 58db60c | 2013-11-13 20:45:40 +0100 | [diff] [blame] | 1 | /* |
| 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 Freyther | df6b4f5 | 2013-11-24 17:05:48 +0100 | [diff] [blame] | 20 | #include "bts.h" |
| 21 | #include "gprs_debug.h" |
Holger Hans Peter Freyther | 58db60c | 2013-11-13 20:45:40 +0100 | [diff] [blame] | 22 | |
| 23 | extern "C" { |
| 24 | #include <osmocom/core/utils.h> |
| 25 | } |
| 26 | |
| 27 | |
| 28 | uint8_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 Freyther | 321f3c3 | 2013-11-23 16:06:54 +0100 | [diff] [blame] | 36 | |
| 37 | void 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 Freyther | 1577779 | 2013-11-24 00:18:47 +0100 | [diff] [blame] | 42 | |
| 43 | int 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 Freyther | 8b16ae3 | 2013-11-24 00:38:54 +0100 | [diff] [blame] | 55 | |
| 56 | int 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 Freyther | df6b4f5 | 2013-11-24 17:05:48 +0100 | [diff] [blame] | 73 | |
Holger Hans Peter Freyther | 9c5539d | 2013-11-24 17:34:17 +0100 | [diff] [blame^] | 74 | int gprs_rlc_v_b::count_unacked(const uint16_t v_a, const uint16_t v_s, |
| 75 | const uint16_t mod_sns, const uint16_t mod_sns_half) |
| 76 | { |
| 77 | uint16_t unacked = 0; |
| 78 | uint16_t bsn; |
| 79 | |
| 80 | for (bsn = v_a; bsn != v_s; bsn = (bsn + 1) & mod_sns) { |
| 81 | uint16_t index = bsn & mod_sns_half; |
| 82 | if (!is_acked(index)) |
| 83 | unacked += 1; |
| 84 | } |
| 85 | |
| 86 | return unacked; |
| 87 | } |
| 88 | |
Holger Hans Peter Freyther | df6b4f5 | 2013-11-24 17:05:48 +0100 | [diff] [blame] | 89 | void gprs_rlc_v_b::update(BTS *bts, char *show_rbb, uint8_t ssn, |
| 90 | const uint16_t v_a, |
| 91 | const uint16_t mod_sns, const uint16_t mod_sns_half, |
| 92 | uint16_t *lost, uint16_t *received) |
| 93 | { |
| 94 | uint16_t bsn; |
| 95 | int i; |
| 96 | |
| 97 | /* SSN - 1 is in range V(A)..V(S)-1 */ |
| 98 | for (i = 63, bsn = (ssn - 1) & mod_sns; |
| 99 | i >= 0 && bsn != ((v_a - 1) & mod_sns); |
| 100 | i--, bsn = (bsn - 1) & mod_sns) { |
| 101 | |
| 102 | if (show_rbb[i] == '1') { |
| 103 | LOGP(DRLCMACDL, LOGL_DEBUG, "- got ack for BSN=%d\n", bsn); |
| 104 | if (!is_acked(bsn & mod_sns_half)) |
| 105 | *received += 1; |
| 106 | mark_acked(bsn & mod_sns_half); |
| 107 | } else { |
| 108 | LOGP(DRLCMACDL, LOGL_DEBUG, "- got NACK for BSN=%d\n", bsn); |
| 109 | mark_nacked(bsn & mod_sns_half); |
| 110 | bts->rlc_nacked(); |
| 111 | *lost += 1; |
| 112 | } |
| 113 | } |
| 114 | } |
Holger Hans Peter Freyther | e358ff8 | 2013-11-24 17:13:10 +0100 | [diff] [blame] | 115 | |
| 116 | int gprs_rlc_v_b::move_window(const uint16_t v_a, const uint16_t v_s, |
| 117 | const uint16_t mod_sns, const uint16_t mod_sns_half) |
| 118 | { |
| 119 | int i; |
| 120 | uint16_t bsn; |
| 121 | int moved = 0; |
| 122 | |
| 123 | for (i = 0, bsn = v_a; bsn != v_s; i++, bsn = (bsn + 1) & mod_sns) { |
| 124 | uint16_t index = (bsn & mod_sns_half); |
| 125 | if (is_acked(index)) { |
| 126 | mark_invalid(index); |
| 127 | moved += 1; |
| 128 | } else |
| 129 | break; |
| 130 | } |
| 131 | |
| 132 | return moved; |
| 133 | } |
Holger Hans Peter Freyther | bc15570 | 2013-11-24 17:20:35 +0100 | [diff] [blame] | 134 | |
| 135 | void gprs_rlc_v_b::state(char *show_v_b, const uint16_t v_a, const uint16_t v_s, |
| 136 | const uint16_t mod_sns, const uint16_t mod_sns_half) |
| 137 | { |
| 138 | int i; |
| 139 | uint16_t bsn; |
| 140 | |
| 141 | for (i = 0, bsn = v_a; bsn != v_s; i++, bsn = (bsn + 1) & mod_sns) { |
| 142 | uint16_t index = (bsn & mod_sns_half); |
| 143 | show_v_b[i] = m_v_b[index]; |
| 144 | if (show_v_b[i] == 0) |
| 145 | show_v_b[i] = ' '; |
| 146 | } |
| 147 | show_v_b[i] = '\0'; |
| 148 | } |