Holger Hans Peter Freyther | 17c31ce | 2013-08-24 18:31:27 +0200 | [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 | |
Daniel Willmann | afa72f5 | 2014-01-15 17:06:19 +0100 | [diff] [blame] | 21 | #ifdef __cplusplus |
| 22 | |
Holger Hans Peter Freyther | 099535a | 2013-10-16 17:42:31 +0200 | [diff] [blame] | 23 | #include "gprs_rlcmac.h" |
Holger Hans Peter Freyther | be57081 | 2013-11-07 08:01:49 +0100 | [diff] [blame] | 24 | #include "llc.h" |
Holger Hans Peter Freyther | 6b5660c | 2013-11-23 16:10:48 +0100 | [diff] [blame] | 25 | #include "rlc.h" |
Daniel Willmann | eb10024 | 2014-08-08 11:43:53 +0200 | [diff] [blame] | 26 | #include <gprs_debug.h> |
Holger Hans Peter Freyther | 099535a | 2013-10-16 17:42:31 +0200 | [diff] [blame] | 27 | |
Holger Hans Peter Freyther | 17c31ce | 2013-08-24 18:31:27 +0200 | [diff] [blame] | 28 | #include <stdint.h> |
| 29 | |
Holger Hans Peter Freyther | 1702f10 | 2013-10-20 08:44:02 +0200 | [diff] [blame] | 30 | struct bssgp_bvc_ctx; |
Holger Hans Peter Freyther | 77e0597 | 2013-11-06 19:16:43 +0100 | [diff] [blame] | 31 | struct rlc_ul_header; |
Holger Hans Peter Freyther | 096f6f9 | 2013-11-07 07:21:06 +0100 | [diff] [blame] | 32 | struct msgb; |
Holger Hans Peter Freyther | 1702f10 | 2013-10-20 08:44:02 +0200 | [diff] [blame] | 33 | |
Holger Hans Peter Freyther | 9e21d84 | 2013-10-16 17:48:12 +0200 | [diff] [blame] | 34 | /* |
| 35 | * TBF instance |
| 36 | */ |
| 37 | |
Holger Hans Peter Freyther | 9e21d84 | 2013-10-16 17:48:12 +0200 | [diff] [blame] | 38 | #define Tassign_agch 0,200000 /* waiting after IMM.ASS confirm */ |
| 39 | #define Tassign_pacch 2,0 /* timeout for pacch assigment */ |
| 40 | |
| 41 | enum gprs_rlcmac_tbf_state { |
| 42 | GPRS_RLCMAC_NULL = 0, /* new created TBF */ |
| 43 | GPRS_RLCMAC_ASSIGN, /* wait for downlink assignment */ |
| 44 | GPRS_RLCMAC_FLOW, /* RLC/MAC flow, resource needed */ |
| 45 | GPRS_RLCMAC_FINISHED, /* flow finished, wait for release */ |
| 46 | GPRS_RLCMAC_WAIT_RELEASE,/* wait for release or restart of DL TBF */ |
| 47 | GPRS_RLCMAC_RELEASING, /* releasing, wait to free TBI/USF */ |
| 48 | }; |
| 49 | |
| 50 | enum gprs_rlcmac_tbf_poll_state { |
| 51 | GPRS_RLCMAC_POLL_NONE = 0, |
| 52 | GPRS_RLCMAC_POLL_SCHED, /* a polling was scheduled */ |
| 53 | }; |
| 54 | |
| 55 | enum gprs_rlcmac_tbf_dl_ass_state { |
| 56 | GPRS_RLCMAC_DL_ASS_NONE = 0, |
| 57 | GPRS_RLCMAC_DL_ASS_SEND_ASS, /* send downlink assignment on next RTS */ |
| 58 | GPRS_RLCMAC_DL_ASS_WAIT_ACK, /* wait for PACKET CONTROL ACK */ |
| 59 | }; |
| 60 | |
| 61 | enum gprs_rlcmac_tbf_ul_ass_state { |
| 62 | GPRS_RLCMAC_UL_ASS_NONE = 0, |
| 63 | GPRS_RLCMAC_UL_ASS_SEND_ASS, /* send uplink assignment on next RTS */ |
| 64 | GPRS_RLCMAC_UL_ASS_WAIT_ACK, /* wait for PACKET CONTROL ACK */ |
| 65 | }; |
| 66 | |
| 67 | enum gprs_rlcmac_tbf_ul_ack_state { |
| 68 | GPRS_RLCMAC_UL_ACK_NONE = 0, |
| 69 | GPRS_RLCMAC_UL_ACK_SEND_ACK, /* send acknowledge on next RTS */ |
| 70 | GPRS_RLCMAC_UL_ACK_WAIT_ACK, /* wait for PACKET CONTROL ACK */ |
| 71 | }; |
| 72 | |
| 73 | enum gprs_rlcmac_tbf_direction { |
| 74 | GPRS_RLCMAC_DL_TBF, |
| 75 | GPRS_RLCMAC_UL_TBF |
| 76 | }; |
| 77 | |
| 78 | #define GPRS_RLCMAC_FLAG_CCCH 0 /* assignment on CCCH */ |
| 79 | #define GPRS_RLCMAC_FLAG_PACCH 1 /* assignment on PACCH */ |
| 80 | #define GPRS_RLCMAC_FLAG_UL_DATA 2 /* uplink data received */ |
| 81 | #define GPRS_RLCMAC_FLAG_DL_ACK 3 /* downlink acknowledge received */ |
| 82 | #define GPRS_RLCMAC_FLAG_TO_UL_ACK 4 |
| 83 | #define GPRS_RLCMAC_FLAG_TO_DL_ACK 5 |
| 84 | #define GPRS_RLCMAC_FLAG_TO_UL_ASS 6 |
| 85 | #define GPRS_RLCMAC_FLAG_TO_DL_ASS 7 |
| 86 | #define GPRS_RLCMAC_FLAG_TO_MASK 0xf0 /* timeout bits */ |
| 87 | |
Daniel Willmann | 1b3864f | 2014-07-30 13:25:19 +0200 | [diff] [blame] | 88 | struct llist_pods { |
| 89 | struct llist_head list; |
| 90 | void *back; |
| 91 | }; |
| 92 | |
| 93 | #define llist_pods_entry(ptr, type) \ |
| 94 | ((type *)(container_of(ptr, struct llist_pods, list)->back)) |
| 95 | |
| 96 | /** |
| 97 | * llist_pods_for_each_entry - like llist_for_each_entry, but uses |
| 98 | * struct llist_pods ->back to access the entry. |
| 99 | * This is necessary for non-PODS classes because container_of is |
| 100 | * not guaranteed to work anymore. */ |
| 101 | #define llist_pods_for_each_entry(pos, head, member, lpods) \ |
| 102 | for (lpods = llist_entry((head)->next, typeof(struct llist_pods), list), \ |
| 103 | pos = ((typeof(pos))lpods->back), \ |
| 104 | prefetch(pos->member.list.next); \ |
| 105 | &lpods->list != (head); \ |
| 106 | lpods = llist_entry(lpods->list.next, typeof(struct llist_pods), list), \ |
| 107 | pos = ((typeof(pos))lpods->back),\ |
| 108 | prefetch(pos->member.list.next)) |
| 109 | |
Holger Hans Peter Freyther | 099535a | 2013-10-16 17:42:31 +0200 | [diff] [blame] | 110 | struct gprs_rlcmac_tbf { |
Holger Hans Peter Freyther | 964ddb6 | 2013-10-16 17:53:23 +0200 | [diff] [blame] | 111 | |
| 112 | static void free_all(struct gprs_rlcmac_trx *trx); |
Holger Hans Peter Freyther | 4f6a4e5d | 2013-10-16 17:58:46 +0200 | [diff] [blame] | 113 | static void free_all(struct gprs_rlcmac_pdch *pdch); |
Holger Hans Peter Freyther | 964ddb6 | 2013-10-16 17:53:23 +0200 | [diff] [blame] | 114 | |
Holger Hans Peter Freyther | 1c344e2 | 2013-10-16 18:33:18 +0200 | [diff] [blame] | 115 | bool state_is(enum gprs_rlcmac_tbf_state rhs) const; |
| 116 | bool state_is_not(enum gprs_rlcmac_tbf_state rhs) const; |
| 117 | void set_state(enum gprs_rlcmac_tbf_state new_state); |
Daniel Willmann | 08e57c8 | 2014-08-15 18:11:57 +0200 | [diff] [blame] | 118 | const char *state_name() const; |
Holger Hans Peter Freyther | 1c344e2 | 2013-10-16 18:33:18 +0200 | [diff] [blame] | 119 | |
Jacob Erlbeck | adcdf15 | 2015-03-03 14:45:55 +0100 | [diff] [blame] | 120 | const char *name() const; |
| 121 | |
Holger Hans Peter Freyther | 2db7e7e | 2013-10-26 20:45:35 +0200 | [diff] [blame] | 122 | struct msgb *create_dl_ass(uint32_t fn); |
Holger Hans Peter Freyther | ae03f22 | 2013-10-26 21:20:51 +0200 | [diff] [blame] | 123 | struct msgb *create_ul_ass(uint32_t fn); |
Holger Hans Peter Freyther | 2db7e7e | 2013-10-26 20:45:35 +0200 | [diff] [blame] | 124 | |
Holger Hans Peter Freyther | 8f399de | 2013-12-25 20:22:35 +0100 | [diff] [blame] | 125 | uint8_t tsc() const; |
Holger Hans Peter Freyther | a1da251 | 2013-11-07 07:32:51 +0100 | [diff] [blame] | 126 | |
Holger Hans Peter Freyther | 7380bab | 2013-10-16 18:09:19 +0200 | [diff] [blame] | 127 | int rlcmac_diag(); |
Holger Hans Peter Freyther | 964ddb6 | 2013-10-16 17:53:23 +0200 | [diff] [blame] | 128 | |
Holger Hans Peter Freyther | aa9c326 | 2013-10-26 17:49:36 +0200 | [diff] [blame] | 129 | int update(); |
Holger Hans Peter Freyther | af8094d | 2013-10-26 17:56:15 +0200 | [diff] [blame] | 130 | void handle_timeout(); |
Holger Hans Peter Freyther | 86300bb | 2013-10-26 18:01:35 +0200 | [diff] [blame] | 131 | void stop_timer(); |
| 132 | void stop_t3191(); |
Holger Hans Peter Freyther | aa9c326 | 2013-10-26 17:49:36 +0200 | [diff] [blame] | 133 | |
Holger Hans Peter Freyther | d9262b3 | 2013-10-26 20:12:59 +0200 | [diff] [blame] | 134 | void poll_timeout(); |
| 135 | |
Holger Hans Peter Freyther | 474685e | 2013-10-27 17:01:14 +0100 | [diff] [blame] | 136 | /** tlli handling */ |
| 137 | void update_tlli(uint32_t tlli); |
| 138 | uint32_t tlli() const; |
| 139 | bool is_tlli_valid() const; |
| 140 | void tlli_mark_valid(); |
| 141 | |
Holger Hans Peter Freyther | 34f6e5e | 2013-10-27 20:31:47 +0100 | [diff] [blame] | 142 | uint8_t tfi() const; |
| 143 | |
Holger Hans Peter Freyther | 5464c9b | 2013-10-27 20:57:35 +0100 | [diff] [blame] | 144 | const char *imsi() const; |
| 145 | void assign_imsi(const char *imsi); |
| 146 | |
Daniel Willmann | e481815 | 2014-08-15 16:52:09 +0200 | [diff] [blame] | 147 | void set_new_tbf(gprs_rlcmac_tbf *tbf); |
| 148 | gprs_rlcmac_tbf *new_tbf() const; |
| 149 | |
Holger Hans Peter Freyther | a004799 | 2014-01-16 10:07:20 +0100 | [diff] [blame] | 150 | time_t created_ts() const; |
Daniel Willmann | 80367aa | 2014-01-15 17:40:28 +0100 | [diff] [blame] | 151 | |
Holger Hans Peter Freyther | 7a5f3c2 | 2013-11-26 13:08:12 +0100 | [diff] [blame] | 152 | /* attempt to make things a bit more fair */ |
| 153 | void rotate_in_list(); |
| 154 | |
Daniel Willmann | 1b3864f | 2014-07-30 13:25:19 +0200 | [diff] [blame] | 155 | struct llist_pods list; |
Holger Hans Peter Freyther | 099535a | 2013-10-16 17:42:31 +0200 | [diff] [blame] | 156 | uint32_t state_flags; |
| 157 | enum gprs_rlcmac_tbf_direction direction; |
Holger Hans Peter Freyther | 743bafa | 2013-09-29 07:50:50 +0200 | [diff] [blame] | 158 | struct gprs_rlcmac_trx *trx; |
Holger Hans Peter Freyther | 099535a | 2013-10-16 17:42:31 +0200 | [diff] [blame] | 159 | uint8_t first_ts; /* first TS used by TBF */ |
| 160 | uint8_t first_common_ts; /* first TS that the phone can send and |
| 161 | reveive simultaniously */ |
| 162 | uint8_t control_ts; /* timeslot control messages and polling */ |
| 163 | uint8_t ms_class; |
| 164 | struct gprs_rlcmac_pdch *pdch[8]; /* list of PDCHs allocated to TBF */ |
| 165 | uint16_t ta; |
Holger Hans Peter Freyther | 28e5378 | 2013-11-06 20:23:56 +0100 | [diff] [blame] | 166 | |
| 167 | gprs_llc m_llc; |
Holger Hans Peter Freyther | 099535a | 2013-10-16 17:42:31 +0200 | [diff] [blame] | 168 | |
| 169 | enum gprs_rlcmac_tbf_dl_ass_state dl_ass_state; |
| 170 | enum gprs_rlcmac_tbf_ul_ass_state ul_ass_state; |
| 171 | enum gprs_rlcmac_tbf_ul_ack_state ul_ack_state; |
| 172 | |
Daniel Willmann | e481815 | 2014-08-15 16:52:09 +0200 | [diff] [blame] | 173 | gprs_rlcmac_tbf *m_new_tbf; |
Jacob Erlbeck | 08fe76a | 2015-02-23 15:10:20 +0100 | [diff] [blame] | 174 | gprs_rlcmac_tbf *m_old_tbf; /* reverse pointer for m_new_tbf */ |
Daniel Willmann | e481815 | 2014-08-15 16:52:09 +0200 | [diff] [blame] | 175 | |
Holger Hans Peter Freyther | 099535a | 2013-10-16 17:42:31 +0200 | [diff] [blame] | 176 | enum gprs_rlcmac_tbf_poll_state poll_state; |
| 177 | uint32_t poll_fn; /* frame number to poll */ |
| 178 | |
Holger Hans Peter Freyther | 9241fd0 | 2013-11-13 19:51:55 +0100 | [diff] [blame] | 179 | gprs_rlc m_rlc; |
Holger Hans Peter Freyther | 099535a | 2013-10-16 17:42:31 +0200 | [diff] [blame] | 180 | |
| 181 | uint8_t n3105; /* N3105 counter */ |
| 182 | |
| 183 | struct osmo_timer_list timer; |
| 184 | unsigned int T; /* Txxxx number */ |
| 185 | unsigned int num_T_exp; /* number of consecutive T expirations */ |
| 186 | |
| 187 | struct osmo_gsm_timer_list gsm_timer; |
| 188 | unsigned int fT; /* fTxxxx number */ |
| 189 | unsigned int num_fT_exp; /* number of consecutive fT expirations */ |
| 190 | |
| 191 | struct { |
Holger Hans Peter Freyther | 099535a | 2013-10-16 17:42:31 +0200 | [diff] [blame] | 192 | struct timeval rssi_tv; /* timestamp for rssi calculation */ |
| 193 | int32_t rssi_sum; /* sum of rssi values */ |
| 194 | int rssi_num; /* number of rssi values added since rssi_tv */ |
Holger Hans Peter Freyther | 099535a | 2013-10-16 17:42:31 +0200 | [diff] [blame] | 195 | } meas; |
| 196 | |
| 197 | uint8_t cs; /* current coding scheme */ |
| 198 | |
Holger Hans Peter Freyther | 1c344e2 | 2013-10-16 18:33:18 +0200 | [diff] [blame] | 199 | /* these should become protected but only after gprs_rlcmac_data.c |
| 200 | * stops to iterate over all tbf in its current form */ |
| 201 | enum gprs_rlcmac_tbf_state state; |
Holger Hans Peter Freyther | 9f0c1d2 | 2013-10-19 21:24:34 +0200 | [diff] [blame] | 202 | |
Daniel Willmann | 73191a4 | 2014-05-30 17:58:00 +0200 | [diff] [blame] | 203 | /* Remember if the tbf was in wait_release state when we want to |
| 204 | * schedule a new dl assignment */ |
| 205 | uint8_t was_releasing; |
| 206 | |
Daniel Willmann | cf1fae7 | 2014-05-30 17:58:01 +0200 | [diff] [blame] | 207 | /* Can/should we upgrade this tbf to use multiple slots? */ |
| 208 | uint8_t upgrade_to_multislot; |
| 209 | |
Holger Hans Peter Freyther | 9f0c1d2 | 2013-10-19 21:24:34 +0200 | [diff] [blame] | 210 | /* store the BTS this TBF belongs to */ |
| 211 | BTS *bts; |
Holger Hans Peter Freyther | d9262b3 | 2013-10-26 20:12:59 +0200 | [diff] [blame] | 212 | |
Holger Hans Peter Freyther | 474685e | 2013-10-27 17:01:14 +0100 | [diff] [blame] | 213 | /* |
| 214 | * private fields. We can't make it private as it is breaking the |
| 215 | * llist macros. |
| 216 | */ |
| 217 | uint32_t m_tlli; |
| 218 | uint8_t m_tlli_valid; |
Holger Hans Peter Freyther | 34f6e5e | 2013-10-27 20:31:47 +0100 | [diff] [blame] | 219 | uint8_t m_tfi; |
Holger Hans Peter Freyther | a004799 | 2014-01-16 10:07:20 +0100 | [diff] [blame] | 220 | time_t m_created_ts; |
Holger Hans Peter Freyther | 474685e | 2013-10-27 17:01:14 +0100 | [diff] [blame] | 221 | |
Holger Hans Peter Freyther | 5464c9b | 2013-10-27 20:57:35 +0100 | [diff] [blame] | 222 | /* store IMSI for look-up and PCH retransmission */ |
| 223 | char m_imsi[16]; |
| 224 | |
Holger Hans Peter Freyther | d9262b3 | 2013-10-26 20:12:59 +0200 | [diff] [blame] | 225 | protected: |
| 226 | gprs_rlcmac_bts *bts_data() const; |
Holger Hans Peter Freyther | 474685e | 2013-10-27 17:01:14 +0100 | [diff] [blame] | 227 | |
Holger Hans Peter Freyther | 4c06d91 | 2013-11-25 23:05:26 +0100 | [diff] [blame] | 228 | int extract_tlli(const uint8_t *data, const size_t len); |
| 229 | |
Daniel Willmann | eb10024 | 2014-08-08 11:43:53 +0200 | [diff] [blame] | 230 | static const char *tbf_state_name[6]; |
Jacob Erlbeck | adcdf15 | 2015-03-03 14:45:55 +0100 | [diff] [blame] | 231 | |
| 232 | private: |
| 233 | mutable char m_name_buf[60]; |
Holger Hans Peter Freyther | 099535a | 2013-10-16 17:42:31 +0200 | [diff] [blame] | 234 | }; |
| 235 | |
Holger Hans Peter Freyther | 17c31ce | 2013-08-24 18:31:27 +0200 | [diff] [blame] | 236 | |
Daniel Willmann | 0d12a2f | 2014-07-10 17:44:07 +0200 | [diff] [blame] | 237 | struct gprs_rlcmac_ul_tbf *tbf_alloc_ul(struct gprs_rlcmac_bts *bts, |
Holger Hans Peter Freyther | 8692128 | 2013-08-24 21:26:42 +0200 | [diff] [blame] | 238 | int8_t use_trx, uint8_t ms_class, |
| 239 | uint32_t tlli, uint8_t ta, struct gprs_rlcmac_tbf *dl_tbf); |
Holger Hans Peter Freyther | 9e21d84 | 2013-10-16 17:48:12 +0200 | [diff] [blame] | 240 | |
Daniel Willmann | 48aa0b0 | 2014-07-16 18:54:10 +0200 | [diff] [blame] | 241 | struct gprs_rlcmac_ul_tbf *tbf_alloc_ul_tbf(struct gprs_rlcmac_bts *bts, |
Holger Hans Peter Freyther | 9e21d84 | 2013-10-16 17:48:12 +0200 | [diff] [blame] | 242 | struct gprs_rlcmac_tbf *old_tbf, |
Daniel Willmann | 48aa0b0 | 2014-07-16 18:54:10 +0200 | [diff] [blame] | 243 | uint8_t tfi, uint8_t trx, |
| 244 | uint8_t ms_class, uint8_t single_slot); |
| 245 | |
| 246 | struct gprs_rlcmac_dl_tbf *tbf_alloc_dl_tbf(struct gprs_rlcmac_bts *bts, |
| 247 | struct gprs_rlcmac_tbf *old_tbf, |
| 248 | uint8_t tfi, uint8_t trx, |
Holger Hans Peter Freyther | 9e21d84 | 2013-10-16 17:48:12 +0200 | [diff] [blame] | 249 | uint8_t ms_class, uint8_t single_slot); |
| 250 | |
Holger Hans Peter Freyther | 9e21d84 | 2013-10-16 17:48:12 +0200 | [diff] [blame] | 251 | void tbf_free(struct gprs_rlcmac_tbf *tbf); |
| 252 | |
Holger Hans Peter Freyther | 9e21d84 | 2013-10-16 17:48:12 +0200 | [diff] [blame] | 253 | int tbf_assign_control_ts(struct gprs_rlcmac_tbf *tbf); |
| 254 | |
Holger Hans Peter Freyther | 9e21d84 | 2013-10-16 17:48:12 +0200 | [diff] [blame] | 255 | void tbf_timer_start(struct gprs_rlcmac_tbf *tbf, unsigned int T, |
| 256 | unsigned int seconds, unsigned int microseconds); |
| 257 | |
Holger Hans Peter Freyther | 1c344e2 | 2013-10-16 18:33:18 +0200 | [diff] [blame] | 258 | inline bool gprs_rlcmac_tbf::state_is(enum gprs_rlcmac_tbf_state rhs) const |
| 259 | { |
| 260 | return state == rhs; |
| 261 | } |
| 262 | |
| 263 | inline bool gprs_rlcmac_tbf::state_is_not(enum gprs_rlcmac_tbf_state rhs) const |
| 264 | { |
| 265 | return state != rhs; |
| 266 | } |
| 267 | |
Daniel Willmann | eb10024 | 2014-08-08 11:43:53 +0200 | [diff] [blame] | 268 | const char *tbf_name(gprs_rlcmac_tbf *tbf); |
| 269 | |
Daniel Willmann | 08e57c8 | 2014-08-15 18:11:57 +0200 | [diff] [blame] | 270 | inline const char *gprs_rlcmac_tbf::state_name() const |
| 271 | { |
| 272 | return tbf_state_name[state]; |
| 273 | } |
| 274 | |
Holger Hans Peter Freyther | 1c344e2 | 2013-10-16 18:33:18 +0200 | [diff] [blame] | 275 | inline void gprs_rlcmac_tbf::set_state(enum gprs_rlcmac_tbf_state new_state) |
| 276 | { |
Daniel Willmann | eb10024 | 2014-08-08 11:43:53 +0200 | [diff] [blame] | 277 | LOGP(DRLCMAC, LOGL_DEBUG, "%s changes state from %s to %s\n", |
| 278 | tbf_name(this), |
| 279 | tbf_state_name[state], tbf_state_name[new_state]); |
Holger Hans Peter Freyther | 1c344e2 | 2013-10-16 18:33:18 +0200 | [diff] [blame] | 280 | state = new_state; |
| 281 | } |
Holger Hans Peter Freyther | bd449f5 | 2013-10-27 16:39:36 +0100 | [diff] [blame] | 282 | |
Holger Hans Peter Freyther | 474685e | 2013-10-27 17:01:14 +0100 | [diff] [blame] | 283 | inline uint32_t gprs_rlcmac_tbf::tlli() const |
| 284 | { |
| 285 | return m_tlli; |
| 286 | } |
| 287 | |
| 288 | inline bool gprs_rlcmac_tbf::is_tlli_valid() const |
| 289 | { |
| 290 | return m_tlli_valid; |
| 291 | } |
| 292 | |
Holger Hans Peter Freyther | 34f6e5e | 2013-10-27 20:31:47 +0100 | [diff] [blame] | 293 | inline uint8_t gprs_rlcmac_tbf::tfi() const |
| 294 | { |
| 295 | return m_tfi; |
| 296 | } |
| 297 | |
Holger Hans Peter Freyther | 5464c9b | 2013-10-27 20:57:35 +0100 | [diff] [blame] | 298 | inline const char *gprs_rlcmac_tbf::imsi() const |
| 299 | { |
| 300 | return m_imsi; |
| 301 | } |
| 302 | |
Daniel Willmann | e481815 | 2014-08-15 16:52:09 +0200 | [diff] [blame] | 303 | inline gprs_rlcmac_tbf *gprs_rlcmac_tbf::new_tbf() const |
| 304 | { |
| 305 | return m_new_tbf; |
| 306 | } |
| 307 | |
Holger Hans Peter Freyther | a004799 | 2014-01-16 10:07:20 +0100 | [diff] [blame] | 308 | inline time_t gprs_rlcmac_tbf::created_ts() const |
Daniel Willmann | 80367aa | 2014-01-15 17:40:28 +0100 | [diff] [blame] | 309 | { |
Holger Hans Peter Freyther | a004799 | 2014-01-16 10:07:20 +0100 | [diff] [blame] | 310 | return m_created_ts; |
Daniel Willmann | 80367aa | 2014-01-15 17:40:28 +0100 | [diff] [blame] | 311 | } |
| 312 | |
Daniel Willmann | 078bb71 | 2014-07-10 17:44:06 +0200 | [diff] [blame] | 313 | struct gprs_rlcmac_dl_tbf : public gprs_rlcmac_tbf { |
Daniel Willmann | 3016888 | 2014-08-07 12:48:29 +0200 | [diff] [blame] | 314 | /* dispatch Unitdata.DL messages */ |
| 315 | static int handle(struct gprs_rlcmac_bts *bts, |
| 316 | const uint32_t tlli, const char *imsi, const uint8_t ms_class, |
| 317 | const uint16_t delay_csec, const uint8_t *data, const uint16_t len); |
| 318 | |
Daniel Willmann | 538ac5b | 2014-07-30 19:12:27 +0200 | [diff] [blame] | 319 | int append_data(const uint8_t ms_class, |
| 320 | const uint16_t pdu_delay_csec, |
| 321 | const uint8_t *data, const uint16_t len); |
| 322 | |
Daniel Willmann | 6c813fc | 2014-07-30 19:12:27 +0200 | [diff] [blame] | 323 | int rcvd_dl_ack(uint8_t final, uint8_t ssn, uint8_t *rbb); |
Daniel Willmann | b8f2601 | 2014-07-30 19:12:28 +0200 | [diff] [blame] | 324 | struct msgb *create_dl_acked_block(uint32_t fn, uint8_t ts); |
Jacob Erlbeck | 7c44415 | 2015-03-12 12:08:54 +0100 | [diff] [blame] | 325 | void request_dl_ack(); |
Daniel Willmann | b8f2601 | 2014-07-30 19:12:28 +0200 | [diff] [blame] | 326 | |
Daniel Willmann | cf706b0 | 2014-08-07 17:35:22 +0200 | [diff] [blame] | 327 | /* TODO: add the gettimeofday as parameter */ |
| 328 | struct msgb *llc_dequeue(bssgp_bvc_ctx *bctx); |
| 329 | |
Daniel Willmann | 6a8a1dc | 2014-08-07 15:14:08 +0200 | [diff] [blame] | 330 | /* Please note that all variables here will be reset when changing |
| 331 | * from WAIT RELEASE back to FLOW state (re-use of TBF). |
| 332 | * All states that need reset must be in this struct, so this is why |
| 333 | * variables are in both (dl and ul) structs and not outside union. |
| 334 | */ |
Daniel Willmann | 7e994e3 | 2014-08-07 15:49:21 +0200 | [diff] [blame] | 335 | gprs_rlc_dl_window m_window; |
| 336 | int32_t m_tx_counter; /* count all transmitted blocks */ |
| 337 | uint8_t m_wait_confirm; /* wait for CCCH IMM.ASS cnf */ |
Jacob Erlbeck | 7c44415 | 2015-03-12 12:08:54 +0100 | [diff] [blame] | 338 | bool m_dl_ack_requested; |
Daniel Willmann | 6a8a1dc | 2014-08-07 15:14:08 +0200 | [diff] [blame] | 339 | |
Daniel Willmann | 418a423 | 2014-08-08 11:21:04 +0200 | [diff] [blame] | 340 | struct { |
| 341 | struct timeval dl_bw_tv; /* timestamp for dl bw calculation */ |
| 342 | uint32_t dl_bw_octets; /* number of octets since bw_tv */ |
| 343 | |
| 344 | struct timeval dl_loss_tv; /* timestamp for loss calculation */ |
| 345 | uint16_t dl_loss_lost; /* sum of lost packets */ |
| 346 | uint16_t dl_loss_received; /* sum of received packets */ |
| 347 | } m_bw; |
| 348 | |
Daniel Willmann | b8f2601 | 2014-07-30 19:12:28 +0200 | [diff] [blame] | 349 | protected: |
| 350 | struct msgb *create_new_bsn(const uint32_t fn, const uint8_t ts); |
| 351 | struct msgb *create_dl_acked_block(const uint32_t fn, const uint8_t ts, |
Jacob Erlbeck | 7c44415 | 2015-03-12 12:08:54 +0100 | [diff] [blame] | 352 | const int index); |
Daniel Willmann | 3016888 | 2014-08-07 12:48:29 +0200 | [diff] [blame] | 353 | int update_window(const uint8_t ssn, const uint8_t *rbb); |
| 354 | int maybe_start_new_window(); |
| 355 | bool dl_window_stalled() const; |
| 356 | void reuse_tbf(const uint8_t *data, const uint16_t len); |
Daniel Willmann | 078bb71 | 2014-07-10 17:44:06 +0200 | [diff] [blame] | 357 | }; |
| 358 | |
| 359 | struct gprs_rlcmac_ul_tbf : public gprs_rlcmac_tbf { |
Daniel Willmann | 350f64d | 2014-08-07 14:54:11 +0200 | [diff] [blame] | 360 | struct msgb *create_ul_ack(uint32_t fn); |
| 361 | |
| 362 | /* blocks were acked */ |
| 363 | int rcv_data_block_acknowledged(const uint8_t *data, size_t len, int8_t rssi); |
| 364 | |
Daniel Willmann | e2732e2 | 2014-08-07 17:32:01 +0200 | [diff] [blame] | 365 | /* TODO: extract LLC class? */ |
| 366 | int assemble_forward_llc(const gprs_rlc_data *data); |
| 367 | int snd_ul_ud(); |
| 368 | |
Daniel Willmann | 6a8a1dc | 2014-08-07 15:14:08 +0200 | [diff] [blame] | 369 | /* Please note that all variables here will be reset when changing |
| 370 | * from WAIT RELEASE back to FLOW state (re-use of TBF). |
| 371 | * All states that need reset must be in this struct, so this is why |
| 372 | * variables are in both (dl and ul) structs and not outside union. |
| 373 | */ |
Daniel Willmann | 7e994e3 | 2014-08-07 15:49:21 +0200 | [diff] [blame] | 374 | gprs_rlc_ul_window m_window; |
| 375 | int32_t m_rx_counter; /* count all received blocks */ |
| 376 | uint8_t m_n3103; /* N3103 counter */ |
| 377 | uint8_t m_usf[8]; /* list USFs per PDCH (timeslot) */ |
| 378 | uint8_t m_contention_resolution_done; /* set after done */ |
| 379 | uint8_t m_final_ack_sent; /* set if we sent final ack */ |
Daniel Willmann | 6a8a1dc | 2014-08-07 15:14:08 +0200 | [diff] [blame] | 380 | |
Daniel Willmann | 350f64d | 2014-08-07 14:54:11 +0200 | [diff] [blame] | 381 | protected: |
| 382 | void maybe_schedule_uplink_acknack(const rlc_ul_header *rh); |
Daniel Willmann | 078bb71 | 2014-07-10 17:44:06 +0200 | [diff] [blame] | 383 | }; |
| 384 | |
Daniel Willmann | afa72f5 | 2014-01-15 17:06:19 +0100 | [diff] [blame] | 385 | #endif |
Holger Hans Peter Freyther | 321f3c3 | 2013-11-23 16:06:54 +0100 | [diff] [blame] | 386 | |
Daniel Willmann | afa72f5 | 2014-01-15 17:06:19 +0100 | [diff] [blame] | 387 | #ifdef __cplusplus |
| 388 | extern "C" { |
| 389 | #endif |
| 390 | #include <osmocom/vty/command.h> |
| 391 | #include <osmocom/vty/vty.h> |
| 392 | |
| 393 | |
| 394 | void tbf_print_vty_info(struct vty *vty, llist_head *tbf); |
| 395 | #ifdef __cplusplus |
| 396 | } |
| 397 | #endif |