Holger Hans Peter Freyther | 096f6f9 | 2013-11-07 07:21:06 +0100 | [diff] [blame^] | 1 | /* Copied from tbf.cpp |
| 2 | * |
| 3 | * Copyright (C) 2012 Ivan Klyuchnikov |
| 4 | * Copyright (C) 2012 Andreas Eversberg <jolly@eversberg.eu> |
| 5 | * Copyright (C) 2013 by Holger Hans Peter Freyther |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License |
| 9 | * as published by the Free Software Foundation; either version 2 |
| 10 | * of the License, or (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 20 | */ |
| 21 | |
| 22 | #include <tbf.h> |
| 23 | #include <bts.h> |
| 24 | |
| 25 | #include <string.h> |
| 26 | |
| 27 | extern "C" { |
| 28 | #include <osmocom/core/msgb.h> |
| 29 | } |
| 30 | |
| 31 | /* reset LLC frame */ |
| 32 | void gprs_llc::reset() |
| 33 | { |
| 34 | index = 0; |
| 35 | length = 0; |
| 36 | } |
| 37 | |
| 38 | void gprs_llc::reset_frame_space() |
| 39 | { |
| 40 | index = 0; |
| 41 | } |
| 42 | |
| 43 | void gprs_llc::enqueue(struct msgb *llc_msg) |
| 44 | { |
| 45 | msgb_enqueue(&queue, llc_msg); |
| 46 | } |
| 47 | |
| 48 | void gprs_llc::put_frame(const uint8_t *data, size_t len) |
| 49 | { |
| 50 | memcpy(frame, data, len); |
| 51 | length = len; |
| 52 | } |
| 53 | |
| 54 | void gprs_llc::clear(BTS *bts) |
| 55 | { |
| 56 | struct msgb *msg; |
| 57 | |
| 58 | while ((msg = msgb_dequeue(&queue))) { |
| 59 | bts->dropped_frame(); |
| 60 | msgb_free(msg); |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | void gprs_llc::init() |
| 65 | { |
| 66 | INIT_LLIST_HEAD(&queue); |
| 67 | } |
| 68 | |
| 69 | struct msgb *gprs_llc::dequeue() |
| 70 | { |
| 71 | return msgb_dequeue(&queue); |
| 72 | } |
| 73 | |
| 74 | void gprs_llc::update_frame(struct msgb *msg) |
| 75 | { |
| 76 | /* TODO: bounds check */ |
| 77 | memcpy(frame, msg->data, msg->len); |
| 78 | length = msg->len; |
| 79 | } |