diff options
Diffstat (limited to 'src/encoding.cpp')
-rw-r--r-- | src/encoding.cpp | 92 |
1 files changed, 45 insertions, 47 deletions
diff --git a/src/encoding.cpp b/src/encoding.cpp index 30b0ee1d..56956665 100644 --- a/src/encoding.cpp +++ b/src/encoding.cpp @@ -13,10 +13,6 @@ * 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 General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include <encoding.h> @@ -29,7 +25,7 @@ #include <egprs_rlc_compression.h> extern "C" { -#include <osmocom/gprs/protocol/gsm_04_60.h> +#include <osmocom/gsm/protocol/gsm_44_060.h> #include <osmocom/gsm/protocol/gsm_04_08.h> #include <osmocom/gsm/gsm48.h> } @@ -67,22 +63,22 @@ static int write_alpha_gamma(bitvec *dest, uint8_t alpha, uint8_t gamma) } /* TBF_STARTING_TIME -- same as 3GPP TS 44.018 §10.5.2.38 Starting Time without tag: */ -static int write_tbf_start_time(bitvec *dest, uint32_t fn) +static int write_tbf_start_time(bitvec *dest, uint16_t rfn) { int rc; /* Set values according to 3GPP TS 44.018 Table 10.5.2.38.1 */ /* T1' */ - rc = bitvec_set_u64(dest, (fn / (26 * 51)) % 32, 5, false); + rc = bitvec_set_u64(dest, (rfn / (26 * 51)) % 32, 5, false); CHECK(rc); /* T3 */ - rc = bitvec_set_u64(dest, fn % 51, 6, false); + rc = bitvec_set_u64(dest, rfn % 51, 6, false); CHECK(rc); /* T2 */ - rc = bitvec_set_u64(dest, fn % 26, 5, false); + rc = bitvec_set_u64(dest, rfn % 26, 5, false); CHECK(rc); return rc; @@ -184,7 +180,7 @@ static inline void write_ta_ie(bitvec *dest, unsigned& wp, } static int write_ia_rest_downlink(const gprs_rlcmac_dl_tbf *tbf, bitvec * dest, bool polling, bool ta_valid, - uint32_t fn, uint8_t alpha, uint8_t gamma, int8_t ta_idx) + uint16_t rfn, uint8_t alpha, uint8_t gamma, int8_t ta_idx) { int rc = 0; @@ -217,7 +213,7 @@ static int write_ia_rest_downlink(const gprs_rlcmac_dl_tbf *tbf, bitvec * dest, if (polling) { SET_1(dest); - rc = write_tbf_start_time(dest, fn); + rc = write_tbf_start_time(dest, rfn); CHECK(rc); } else SET_0(dest); @@ -239,7 +235,7 @@ static int write_ia_rest_downlink(const gprs_rlcmac_dl_tbf *tbf, bitvec * dest, } /* 3GPP TS 44.018 Table 10.5.2.16.1 < Packet Uplink Assignment > -- Single Block Allocation */ -static int write_ia_rest_uplink_sba(bitvec *dest, uint32_t fn, uint8_t alpha, uint8_t gamma) +static int write_ia_rest_uplink_sba(bitvec *dest, uint32_t rfn, uint8_t alpha, uint8_t gamma) { int rc = 0; @@ -252,7 +248,7 @@ static int write_ia_rest_uplink_sba(bitvec *dest, uint32_t fn, uint8_t alpha, ui SET_0(dest); SET_1(dest); - rc = write_tbf_start_time(dest, fn); + rc = write_tbf_start_time(dest, rfn); CHECK(rc); /* No P0 nor PR_MODE */ @@ -296,7 +292,7 @@ static int write_ia_rest_uplink_mba(const gprs_rlcmac_ul_tbf *tbf, bitvec *dest, return rc; } -static int write_ia_rest_egprs_uplink_mba(bitvec * dest, uint32_t fn, uint8_t alpha, uint8_t gamma) +static int write_ia_rest_egprs_uplink_mba(bitvec * dest, uint32_t rfn, uint8_t alpha, uint8_t gamma) { int rc = 0; @@ -305,7 +301,7 @@ static int write_ia_rest_egprs_uplink_mba(bitvec * dest, uint32_t fn, uint8_t al rc = write_alpha_gamma(dest, alpha, gamma); CHECK(rc); - rc = write_tbf_start_time(dest, fn); + rc = write_tbf_start_time(dest, rfn); CHECK(rc); SET_0(dest); /* NUMBER OF RADIO BLOCKS ALLOCATED: */ @@ -362,7 +358,7 @@ static int write_ia_rest_egprs_uplink_sba(const gprs_rlcmac_ul_tbf *tbf, bitvec * see GSM 44.018, 9.1.20 + 10.5.2.30 */ int Encoding::write_immediate_assignment_reject(bitvec *dest, uint16_t ra, - uint32_t ref_fn, enum ph_burst_type burst_type, uint8_t t3142) + uint16_t ref_rfn, enum ph_burst_type burst_type, uint8_t t3142) { unsigned wp = 0; int plen; @@ -398,9 +394,9 @@ int Encoding::write_immediate_assignment_reject(bitvec *dest, uint16_t ra, } bitvec_write_field(dest, &wp, - (ref_fn / (26 * 51)) % 32, 5); // T1' - bitvec_write_field(dest, &wp, ref_fn % 51, 6); // T3 - bitvec_write_field(dest, &wp, ref_fn % 26, 5); // T2 + (ref_rfn / (26 * 51)) % 32, 5); // T1' + bitvec_write_field(dest, &wp, ref_rfn % 51, 6); // T3 + bitvec_write_field(dest, &wp, ref_rfn % 26, 5); // T2 /* 10.5.2.43 Wait Indication */ bitvec_write_field(dest, &wp, t3142, 8); @@ -439,27 +435,27 @@ int Encoding::write_immediate_assignment_reject(bitvec *dest, uint16_t ra, */ int Encoding::write_immediate_assignment( const struct gprs_rlcmac_pdch *pdch, - struct gprs_rlcmac_tbf *tbf, + const struct gprs_rlcmac_tbf *tbf, bitvec * dest, bool downlink, uint16_t ra, - uint32_t ref_fn, uint8_t ta, - uint8_t usf, bool polling, uint32_t fn, uint8_t alpha, + uint16_t ref_rfn, uint8_t ta, + uint8_t usf, bool polling, uint16_t rfn, uint8_t alpha, uint8_t gamma, int8_t ta_idx, enum ph_burst_type burst_type) { unsigned wp = 0; int plen; int rc; - bitvec_write_field(dest, &wp,0x0,4); // Skip Indicator - bitvec_write_field(dest, &wp,0x6,4); // Protocol Discriminator - bitvec_write_field(dest, &wp,0x3F,8); // Immediate Assignment Message Type + bitvec_write_field(dest, &wp, 0x0, 4); // Skip Indicator + bitvec_write_field(dest, &wp, 0x6, 4); // Protocol Discriminator + bitvec_write_field(dest, &wp, GSM48_MT_RR_IMM_ASS, 8); // Immediate Assignment Message Type // 10.5.2.25b Dedicated mode or TBF - bitvec_write_field(dest, &wp,0x0,1); // spare - bitvec_write_field(dest, &wp,0x0,1); // TMA : Two-message assignment: No meaning - bitvec_write_field(dest, &wp,downlink,1); // Downlink : Downlink assignment to mobile in packet idle mode - bitvec_write_field(dest, &wp,0x1,1); // T/D : TBF or dedicated mode: this message assigns a Temporary Block Flow (TBF). + bitvec_write_field(dest, &wp, 0x0, 1); // spare + bitvec_write_field(dest, &wp, 0x0, 1); // TMA : Two-message assignment: No meaning + bitvec_write_field(dest, &wp, downlink, 1); // Downlink : Downlink assignment to mobile in packet idle mode + bitvec_write_field(dest, &wp, 0x1, 1); // T/D : TBF or dedicated mode: this message assigns a Temporary Block Flow (TBF). - bitvec_write_field(dest, &wp,0x0,4); // Page Mode + bitvec_write_field(dest, &wp, 0x0, 4); // Page Mode // GSM 04.08 10.5.2.25a Packet Channel Description bitvec_write_field(dest, &wp, 0x01, 5); // Channel type @@ -484,13 +480,13 @@ int Encoding::write_immediate_assignment( bitvec_write_field(dest, &wp, ra, 8); /* RACH value */ } - bitvec_write_field(dest, &wp,(ref_fn / (26 * 51)) % 32,5); // T1' - bitvec_write_field(dest, &wp,ref_fn % 51,6); // T3 - bitvec_write_field(dest, &wp,ref_fn % 26,5); // T2 + bitvec_write_field(dest, &wp, (ref_rfn / (26 * 51)) % 32, 5); // T1' + bitvec_write_field(dest, &wp, ref_rfn % 51, 6); // T3 + bitvec_write_field(dest, &wp, ref_rfn % 26, 5); // T2 // 10.5.2.40 Timing Advance - bitvec_write_field(dest, &wp,0x0,2); // spare - bitvec_write_field(dest, &wp,ta,6); // Timing Advance value + bitvec_write_field(dest, &wp, 0x0, 2); // spare + bitvec_write_field(dest, &wp, ta, 6); // Timing Advance value /* 10.5.2.21 Mobile Allocation */ if (pdch->fh.enabled) { @@ -510,9 +506,9 @@ int Encoding::write_immediate_assignment( /* 3GPP TS 44.018 §10.5.2.16 IA Rest Octets */ dest->cur_bit = wp; if (downlink) { - OSMO_ASSERT(as_dl_tbf(tbf) != NULL); + OSMO_ASSERT(tbf_as_dl_tbf_const(tbf) != NULL); - rc = write_ia_rest_downlink(as_dl_tbf(tbf), dest, polling, gsm48_ta_is_valid(ta), fn, alpha, gamma, + rc = write_ia_rest_downlink(tbf_as_dl_tbf_const(tbf), dest, polling, gsm48_ta_is_valid(ta), rfn, alpha, gamma, ta_idx); } else if (((burst_type == GSM_L1_BURST_TYPE_ACCESS_1) || (burst_type == GSM_L1_BURST_TYPE_ACCESS_2))) { SET_L(dest); SET_H(dest); // "LH" @@ -522,20 +518,20 @@ int Encoding::write_immediate_assignment( SET_0(dest); // No < Access Technologies Request struct > - if (as_ul_tbf(tbf) != NULL) - rc = write_ia_rest_egprs_uplink_sba(as_ul_tbf(tbf), dest, usf, alpha, gamma, ta_idx); + if (tbf_as_ul_tbf_const(tbf) != NULL) + rc = write_ia_rest_egprs_uplink_sba(tbf_as_ul_tbf_const(tbf), dest, usf, alpha, gamma, ta_idx); else - rc = write_ia_rest_egprs_uplink_mba(dest, fn, alpha, gamma); + rc = write_ia_rest_egprs_uplink_mba(dest, rfn, alpha, gamma); } else { OSMO_ASSERT(!tbf || !tbf->is_egprs_enabled()); SET_H(dest); SET_H(dest); // "HH" SET_0(dest); SET_0(dest); // "00" < Packet Uplink Assignment > - if (as_ul_tbf(tbf) != NULL) - rc = write_ia_rest_uplink_mba(as_ul_tbf(tbf), dest, usf, alpha, gamma, ta_idx); + if (tbf_as_ul_tbf_const(tbf) != NULL) + rc = write_ia_rest_uplink_mba(tbf_as_ul_tbf_const(tbf), dest, usf, alpha, gamma, ta_idx); else - rc = write_ia_rest_uplink_sba(dest, fn, alpha, gamma); + rc = write_ia_rest_uplink_sba(dest, rfn, alpha, gamma); } if (rc < 0) { @@ -557,7 +553,7 @@ static void gen_freq_params(Frequency_Parameters_t *freq_params, Direct_encoding_1_t fh_params; /* Check one PDCH, if it's hopping then all other should too */ - pdch = tbf->pdch[tbf->first_ts]; + pdch = tbf_get_first_ts_const(tbf); OSMO_ASSERT(pdch != NULL); /* Training Sequence Code */ @@ -566,7 +562,7 @@ static void gen_freq_params(Frequency_Parameters_t *freq_params, /* If frequency hopping is not in use, encode a single ARFCN */ if (!pdch->fh.enabled) { freq_params->UnionType = 0x00; - freq_params->u.ARFCN = tbf->trx->arfcn; + freq_params->u.ARFCN = pdch->trx->arfcn; return; } @@ -577,6 +573,8 @@ static void gen_freq_params(Frequency_Parameters_t *freq_params, fh_params.MAIO = pdch->fh.maio; fh_params.GPRS_Mobile_Allocation.HSN = pdch->fh.hsn; fh_params.GPRS_Mobile_Allocation.ElementsOf_RFL_NUMBER = 0; + memset(&fh_params.GPRS_Mobile_Allocation.RFL_NUMBER[0], 0x00, + sizeof(fh_params.GPRS_Mobile_Allocation.RFL_NUMBER)); /* Mobile Allocation bitmap */ fh_params.GPRS_Mobile_Allocation.UnionType = 0; /* MA bitmap */ @@ -607,7 +605,7 @@ void write_packet_uplink_assignment(RlcMacDownlink_t *block, uint8_t old_tfi, /* See 3GPP TS 44.060, section 11.2.29 */ pua = &block->u.Packet_Uplink_Assignment; - pua->MESSAGE_TYPE = 0x0a; // Packet Uplink Assignment + pua->MESSAGE_TYPE = MT_PACKET_UPLINK_ASSIGNMENT; // Packet Uplink Assignment pua->PAGE_MODE = 0x00; // Normal Paging /* TLLI or Global (UL/DL) TFI */ @@ -803,7 +801,7 @@ void write_packet_downlink_assignment(RlcMacDownlink_t * block, } /* Generate paging request. See 44.018, sections 10 and 9.1.22 */ -int Encoding::write_paging_request(bitvec * dest, const struct osmo_mobile_identity *mi) +int write_paging_request(struct bitvec *dest, const struct osmo_mobile_identity *mi) { uint8_t mi_buf[GSM48_MID_MAX_SIZE]; int mi_len; |