-
Notifications
You must be signed in to change notification settings - Fork 325
/
RLC.cpp
84 lines (72 loc) · 2.53 KB
/
RLC.cpp
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
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
* Copyright 2011, 2014 Range Networks, Inc.
*
* This software is distributed under multiple licenses;
* see the COPYING file in the main directory for licensing
* information for this specific distribution.
*
* This use of this software may be subject to additional restrictions.
* See the LEGAL file in the main directory for details.
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.
*/
#define LOG_GROUP LogGroup::GPRS // Can set Log.Level.GPRS for debugging
#include "GPRSRLC.h"
#include "GSMCommon.h"
namespace GPRS {
int deltaBSN(int bsn1,int bsn2)
{
static const int halfModulus = RLCBSN_t::BSNPeriodicity/2;
int delta = bsn1 - bsn2;
if (delta>=halfModulus) delta -= RLCBSN_t::BSNPeriodicity;
else if (delta<-halfModulus) delta += RLCBSN_t::BSNPeriodicity;
return delta;
}
// Based on GSM::FNDelta
// We assume the values are within a half periodicity of each other.
int RLCBSN_t::BSNdelta(RLCBSN_t v2)
{
RLCBSN_t v1 = *this;
//int delta = v1.mValue - v2.mValue;
//if (delta>=halfModulus) delta -= BSNPeriodicity;
//else if (delta<-halfModulus) delta += BSNPeriodicity;
//return RLCBSN_t(delta);
return RLCBSN_t(deltaBSN(v1.mValue,v2.mValue));
}
// Return 1 if v1 > v2; return -1 if v1 < v2, using modulo BSNPeriodicity.
int RLCBSN_t::BSNcompare(RLCBSN_t v2)
{
int delta = BSNdelta(v2);
if (delta>0) return 1;
if (delta<0) return -1;
return 0;
}
// (pat) Return the block radio number for a frame number.
RLCBSN_t FrameNumber2BSN(int fn)
{
// The RLC blocks use a 52-multiframe, but each 13-multiframe is identical:
// the first 12 frames are 3 RLC blocks, and the last frame is for timing or idle.
int mfn = (fn / 13); // how many 13-multiframes
int rem = (fn - (mfn*13)); // how many blocks within the last multiframe.
RLCBSN_t result = mfn * 3 + ((rem==12) ? 2 : (rem/4));
result.normalize();
return result;
}
// Return the Block Sequence Number for a frame number.
// There are 12 radio blocks per 52 frames,
int BSN2FrameNumber(RLCBSN_t absn) // absolute block sequence number.
{
// One extra frame is inserted after every 3 radio blocks,
// so 3 radio blocks take 13 frames.
int bsn = absn; // Convert to int so we do math on int, not RLCBSN_t
int result = ((int)bsn / 3) * 13 + ((int)bsn % 3) * 4;
assert(result >= 0 && (unsigned) result <= GSM::gHyperframe);
return result;
}
std::ostream& operator<<(std::ostream& os, const RLCDir::type &dir)
{
os << RLCDir::name(dir);
return os;
}
};