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" |
| 20 | |
| 21 | extern "C" { |
| 22 | #include <osmocom/core/utils.h> |
| 23 | } |
| 24 | |
| 25 | |
| 26 | uint8_t *gprs_rlc_data::prepare(size_t block_data_len) |
| 27 | { |
| 28 | /* todo.. only set it once if it turns out to be a bottleneck */ |
| 29 | memset(block, 0x0, ARRAY_SIZE(block)); |
| 30 | memset(block, 0x2b, block_data_len); |
| 31 | |
| 32 | return block; |
| 33 | } |
Holger Hans Peter Freyther | 321f3c3 | 2013-11-23 16:06:54 +0100 | [diff] [blame] | 34 | |
| 35 | void gprs_rlc_v_b::reset() |
| 36 | { |
| 37 | for (size_t i = 0; i < ARRAY_SIZE(m_v_b); ++i) |
| 38 | mark_invalid(i); |
| 39 | } |
Holger Hans Peter Freyther | 1577779 | 2013-11-24 00:18:47 +0100 | [diff] [blame] | 40 | |
| 41 | int gprs_rlc_v_b::resend_needed(const uint16_t v_a, const uint16_t v_s, |
| 42 | const uint16_t mod_sns, |
| 43 | const uint16_t mod_sns_half) |
| 44 | { |
| 45 | for (uint8_t bsn = v_a; bsn != v_s; bsn = (bsn + 1) & mod_sns) { |
| 46 | uint16_t index = bsn & mod_sns_half; |
| 47 | if (is_nacked(index) || is_resend(index)) |
| 48 | return bsn; |
| 49 | } |
| 50 | |
| 51 | return -1; |
| 52 | } |
Holger Hans Peter Freyther | 8b16ae3 | 2013-11-24 00:38:54 +0100 | [diff] [blame^] | 53 | |
| 54 | int gprs_rlc_v_b::mark_for_resend(const uint16_t v_a, const uint16_t v_s, |
| 55 | const uint16_t mod_sns, |
| 56 | const uint16_t mod_sns_half) |
| 57 | { |
| 58 | int resend = 0; |
| 59 | |
| 60 | for (uint8_t bsn = v_a; bsn != v_s; bsn = (bsn + 1) & mod_sns) { |
| 61 | uint16_t index = (bsn & mod_sns_half); |
| 62 | if (is_unacked(index)) { |
| 63 | /* mark to be re-send */ |
| 64 | mark_resend(index); |
| 65 | resend += 1; |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | return resend; |
| 70 | } |