blob: a6dfced684196a07c9fe0a8631bc947ce30dde82 [file] [log] [blame]
Holger Hans Peter Freyther17c31ce2013-08-24 18:31:27 +02001/*
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
Holger Hans Peter Freyther099535a2013-10-16 17:42:31 +020021#include "gprs_rlcmac.h"
22
Holger Hans Peter Freyther17c31ce2013-08-24 18:31:27 +020023#include <stdint.h>
24
Holger Hans Peter Freyther099535a2013-10-16 17:42:31 +020025struct gprs_rlcmac_tbf {
26 struct llist_head list;
27 enum gprs_rlcmac_tbf_state state;
28 uint32_t state_flags;
29 enum gprs_rlcmac_tbf_direction direction;
30 uint8_t tfi;
31 uint32_t tlli;
32 uint8_t tlli_valid;
33 uint8_t trx;
34 uint16_t arfcn;
35 uint8_t tsc;
36 uint8_t first_ts; /* first TS used by TBF */
37 uint8_t first_common_ts; /* first TS that the phone can send and
38 reveive simultaniously */
39 uint8_t control_ts; /* timeslot control messages and polling */
40 uint8_t ms_class;
41 struct gprs_rlcmac_pdch *pdch[8]; /* list of PDCHs allocated to TBF */
42 uint16_t ta;
43 uint8_t llc_frame[LLC_MAX_LEN]; /* current DL or UL frame */
44 uint16_t llc_index; /* current write/read position of frame */
45 uint16_t llc_length; /* len of current DL LLC_frame, 0 == no frame */
46 struct llist_head llc_queue; /* queued LLC DL data */
47
48 enum gprs_rlcmac_tbf_dl_ass_state dl_ass_state;
49 enum gprs_rlcmac_tbf_ul_ass_state ul_ass_state;
50 enum gprs_rlcmac_tbf_ul_ack_state ul_ack_state;
51
52 enum gprs_rlcmac_tbf_poll_state poll_state;
53 uint32_t poll_fn; /* frame number to poll */
54
55 uint16_t ws; /* window size */
56 uint16_t sns; /* sequence number space */
57
58 /* Please note that all variables here will be reset when changing
59 * from WAIT RELEASE back to FLOW state (re-use of TBF).
60 * All states that need reset must be in this struct, so this is why
61 * variables are in both (dl and ul) structs and not outside union.
62 */
63 union {
64 struct {
65 uint16_t bsn; /* block sequence number */
66 uint16_t v_s; /* send state */
67 uint16_t v_a; /* ack state */
68 char v_b[RLC_MAX_SNS/2]; /* acknowledge state array */
69 int32_t tx_counter; /* count all transmitted blocks */
70 char imsi[16]; /* store IMSI for PCH retransmission */
71 uint8_t wait_confirm; /* wait for CCCH IMM.ASS cnf */
72 } dl;
73 struct {
74 uint16_t bsn; /* block sequence number */
75 uint16_t v_r; /* receive state */
76 uint16_t v_q; /* receive window state */
77 char v_n[RLC_MAX_SNS/2]; /* receive state array */
78 int32_t rx_counter; /* count all received blocks */
79 uint8_t n3103; /* N3103 counter */
80 uint8_t usf[8]; /* list USFs per PDCH (timeslot) */
81 uint8_t contention_resolution_done; /* set after done */
82 uint8_t final_ack_sent; /* set if we sent final ack */
83 } ul;
84 } dir;
85 uint8_t rlc_block[RLC_MAX_SNS/2][RLC_MAX_LEN]; /* block history */
86 uint8_t rlc_block_len[RLC_MAX_SNS/2]; /* block len of history */
87
88 uint8_t n3105; /* N3105 counter */
89
90 struct osmo_timer_list timer;
91 unsigned int T; /* Txxxx number */
92 unsigned int num_T_exp; /* number of consecutive T expirations */
93
94 struct osmo_gsm_timer_list gsm_timer;
95 unsigned int fT; /* fTxxxx number */
96 unsigned int num_fT_exp; /* number of consecutive fT expirations */
97
98 struct {
99 char imsi[16];
100
101 struct timeval dl_bw_tv; /* timestamp for dl bw calculation */
102 uint32_t dl_bw_octets; /* number of octets since bw_tv */
103
104 struct timeval rssi_tv; /* timestamp for rssi calculation */
105 int32_t rssi_sum; /* sum of rssi values */
106 int rssi_num; /* number of rssi values added since rssi_tv */
107
108 struct timeval dl_loss_tv; /* timestamp for loss calculation */
109 uint16_t dl_loss_lost; /* sum of lost packets */
110 uint16_t dl_loss_received; /* sum of received packets */
111
112 } meas;
113
114 uint8_t cs; /* current coding scheme */
115
116#ifdef DEBUG_DIAGRAM
117 int diag; /* number where TBF is presented in diagram */
118 int diag_new; /* used to format output of new TBF */
119#endif
120};
121
Holger Hans Peter Freyther17c31ce2013-08-24 18:31:27 +0200122
Holger Hans Peter Freyther86921282013-08-24 21:26:42 +0200123/* dispatch Unitdata.DL messages */
Holger Hans Peter Freyther17c31ce2013-08-24 18:31:27 +0200124int tbf_handle(struct gprs_rlcmac_bts *bts,
125 const uint32_t tlli, const char *imsi, const uint8_t ms_class,
126 const uint16_t delay_csec, const uint8_t *data, const uint16_t len);
Holger Hans Peter Freyther86921282013-08-24 21:26:42 +0200127
128struct gprs_rlcmac_tbf *tbf_alloc_ul(struct gprs_rlcmac_bts *bts,
129 int8_t use_trx, uint8_t ms_class,
130 uint32_t tlli, uint8_t ta, struct gprs_rlcmac_tbf *dl_tbf);