Holger Hans Peter Freyther | be57081 | 2013-11-07 08:01:49 +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 | #pragma once |
| 20 | |
| 21 | #include <stdint.h> |
Holger Hans Peter Freyther | acb5427 | 2013-11-07 08:15:58 +0100 | [diff] [blame] | 22 | #include <string.h> |
Holger Hans Peter Freyther | be57081 | 2013-11-07 08:01:49 +0100 | [diff] [blame] | 23 | |
| 24 | #define LLC_MAX_LEN 1543 |
| 25 | |
| 26 | /** |
| 27 | * I represent the LLC data to a MS |
| 28 | */ |
| 29 | struct gprs_llc { |
Holger Hans Peter Freyther | fce431c | 2013-11-13 15:17:12 +0100 | [diff] [blame^] | 30 | static void calc_pdu_lifetime(BTS *bts, const uint16_t pdu_delay_csec, struct timeval *tv); |
| 31 | |
Holger Hans Peter Freyther | be57081 | 2013-11-07 08:01:49 +0100 | [diff] [blame] | 32 | 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 Freyther | be57081 | 2013-11-07 08:01:49 +0100 | [diff] [blame] | 39 | void put_frame(const uint8_t *data, size_t len); |
Holger Hans Peter Freyther | acb5427 | 2013-11-07 08:15:58 +0100 | [diff] [blame] | 40 | void consume(uint8_t *data, size_t len); |
Holger Hans Peter Freyther | be57081 | 2013-11-07 08:01:49 +0100 | [diff] [blame] | 41 | void clear(BTS *bts); |
| 42 | |
Holger Hans Peter Freyther | acb5427 | 2013-11-07 08:15:58 +0100 | [diff] [blame] | 43 | uint16_t chunk_size() const; |
| 44 | |
Holger Hans Peter Freyther | be57081 | 2013-11-07 08:01:49 +0100 | [diff] [blame] | 45 | uint8_t frame[LLC_MAX_LEN]; /* current DL or UL frame */ |
| 46 | uint16_t index; /* current write/read position of frame */ |
| 47 | uint16_t length; /* len of current DL LLC_frame, 0 == no frame */ |
| 48 | struct llist_head queue; /* queued LLC DL data */ |
| 49 | }; |
| 50 | |
Holger Hans Peter Freyther | acb5427 | 2013-11-07 08:15:58 +0100 | [diff] [blame] | 51 | inline uint16_t gprs_llc::chunk_size() const |
| 52 | { |
| 53 | return length - index; |
| 54 | } |
| 55 | |
| 56 | inline void gprs_llc::consume(uint8_t *data, size_t len) |
| 57 | { |
| 58 | /* copy and increment index */ |
| 59 | memcpy(data, frame + index, len); |
| 60 | index += len; |
| 61 | } |