aboutsummaryrefslogtreecommitdiffstats
path: root/src/poll_controller.cpp
blob: 0bf616ef38e1c750e3f6e5c28dbee3890cb1f1ab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/* poll_controller.h
 *
 * Copyright (C) 2012 Andreas Eversberg <jolly@eversberg.eu>
 * Copyright (C) 2013 by Holger Hans Peter Freyther
 *
 * All Rights Reserved
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#include <poll_controller.h>
#include <bts.h>
#include <tbf.h>

PollController::PollController(BTS& bts)
	: m_bts(bts)
{}

void PollController::expireTimedout(int frame_number)
{
	struct gprs_rlcmac_bts *bts = m_bts.bts_data();
	struct gprs_rlcmac_dl_tbf *dl_tbf;
	struct gprs_rlcmac_ul_tbf *ul_tbf;
	struct gprs_rlcmac_sba *sba, *sba2;
	struct llist_pods *lpods;
	uint32_t elapsed;

	/* check for poll timeout
	 * The UL frame numbers lag 3 behind the DL frames and the data
	 * indication is only sent after all 4 frames of the block have been
	 * received. Sometimes there is an idle frame between the end of one
	 * and start of another frame (every 3 blocks).  So the timeout should
	 * definitely be there if we're more than 8 frames past poll_fn. Let's
	 * stay on the safe side and say 13 or more. */
	llist_pods_for_each_entry(ul_tbf, &bts->ul_tbfs, list, lpods) {
		if (ul_tbf->poll_state == GPRS_RLCMAC_POLL_SCHED) {
			elapsed = (frame_number + 2715648 - ul_tbf->poll_fn)
								% 2715648;
			if (elapsed >= 13 && elapsed < 2715400)
				ul_tbf->poll_timeout();
		}
	}
	llist_pods_for_each_entry(dl_tbf, &bts->dl_tbfs, list, lpods) {
		if (dl_tbf->poll_state == GPRS_RLCMAC_POLL_SCHED) {
			elapsed = (frame_number + 2715648 - dl_tbf->poll_fn)
								% 2715648;
			if (elapsed >= 13 && elapsed < 2715400)
				dl_tbf->poll_timeout();
		}
	}
	llist_for_each_entry_safe(sba, sba2, &m_bts.sba()->m_sbas, list) {
		elapsed = (frame_number + 2715648 - sba->fn) % 2715648;
		if (elapsed >= 13 && elapsed < 2715400) {
			/* sba will be freed here */
			m_bts.sba()->timeout(sba);
		}
	}

}