blob: da63a61b58dd1bb6d9c7578576f1fa4643998476 [file] [log] [blame]
Holger Hans Peter Freyther63f29d62013-10-19 19:04:03 +02001/* encoding.cpp
2 *
3 * Copyright (C) 2012 Ivan Klyuchnikov
4 * Copyright (C) 2012 Andreas Eversberg <jolly@eversberg.eu>
5 * Copyright (C) 2013 by Holger Hans Peter Freyther
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 */
21#pragma once
22
23#include <stdint.h>
Pau Espin Pedrol2ae83372020-05-18 11:35:35 +020024
bhargava465f5bb2016-09-02 16:50:43 +053025extern "C" {
26#include <osmocom/gsm/l1sap.h>
Pau Espin Pedrol2ae83372020-05-18 11:35:35 +020027#include "coding_scheme.h"
Pau Espin Pedrolb2653fe2020-03-26 15:14:01 +010028#include "gsm_rlcmac.h"
bhargava465f5bb2016-09-02 16:50:43 +053029}
Holger Hans Peter Freyther63f29d62013-10-19 19:04:03 +020030
Holger Hans Peter Freyther63f29d62013-10-19 19:04:03 +020031struct gprs_rlcmac_tbf;
32struct bitvec;
Jacob Erlbeck14bb0942016-01-12 11:58:13 +010033struct gprs_llc;
34struct gprs_rlc_data_block_info;
Holger Hans Peter Freyther63f29d62013-10-19 19:04:03 +020035
36/**
37 * I help with encoding data into CSN1 messages.
38 * TODO: Nobody can remember a function signature like this. One should
39 * fill out a struct with the request parameters and then hand the struct
40 * to the code.
41 */
42class Encoding {
43public:
44 static int write_immediate_assignment(
Vadim Yanitskiy11567762020-07-18 23:34:17 +070045 const struct gprs_rlcmac_pdch *pdch,
Jacob Erlbeck2647a332016-02-01 16:13:38 +010046 struct gprs_rlcmac_tbf *tbf,
Maxfc8afc22019-02-18 18:52:38 +010047 bitvec * dest, bool downlink, uint16_t ra,
Vadim Yanitskiy11567762020-07-18 23:34:17 +070048 uint32_t ref_fn, uint8_t ta,
49 uint8_t usf, bool polling,
Jacob Erlbeck2647a332016-02-01 16:13:38 +010050 uint32_t fn, uint8_t alpha, uint8_t gamma,
bhargava465f5bb2016-09-02 16:50:43 +053051 int8_t ta_idx,
Maxfc8afc22019-02-18 18:52:38 +010052 enum ph_burst_type burst_type);
Holger Hans Peter Freyther63f29d62013-10-19 19:04:03 +020053
aravind sirsikarc0c3afd2016-11-09 16:27:00 +053054 static int write_immediate_assignment_reject(
55 bitvec *dest, uint16_t ra,
56 uint32_t ref_fn,
57 enum ph_burst_type burst_type
58 );
59
Holger Hans Peter Freyther63f29d62013-10-19 19:04:03 +020060 static void write_packet_uplink_assignment(
Vadim Yanitskiydb56a352020-08-22 02:05:28 +070061 RlcMacDownlink_t * block, uint8_t old_tfi,
Jacob Erlbeckf2694b72016-01-26 21:46:26 +010062 uint8_t old_downlink, uint32_t tlli, uint8_t use_tlli,
Vadim Yanitskiyc0ddaa92020-08-20 16:49:34 +070063 const struct gprs_rlcmac_ul_tbf *tbf, uint8_t poll, uint8_t rrbp,
Jacob Erlbeckf2694b72016-01-26 21:46:26 +010064 uint8_t alpha, uint8_t gamma, int8_t ta_idx,
Vadim Yanitskiya76cdac2020-08-22 00:12:30 +070065 bool use_egprs);
Holger Hans Peter Freyther63f29d62013-10-19 19:04:03 +020066
Jacob Erlbeck166c9fc2016-01-07 16:04:29 +010067 static void write_packet_downlink_assignment(RlcMacDownlink_t * block,
Jacob Erlbeck6b356a52016-01-29 16:39:21 +010068 bool old_tfi_is_valid, uint8_t old_tfi, uint8_t old_downlink,
Vadim Yanitskiyc0ddaa92020-08-20 16:49:34 +070069 const struct gprs_rlcmac_dl_tbf *tbf, uint8_t poll, uint8_t rrbp,
Jacob Erlbeckf2694b72016-01-26 21:46:26 +010070 uint8_t alpha, uint8_t gamma,
71 int8_t ta_idx, uint8_t ta_ts, bool use_egprs);
Holger Hans Peter Freyther63f29d62013-10-19 19:04:03 +020072
Daniel Willmann5241c1a2013-12-11 14:35:29 +010073 static void encode_rbb(const char *show_rbb, uint8_t *rbb);
74
aravind sirsikared3413e2016-11-11 17:15:10 +053075 static void write_packet_access_reject(
76 bitvec * dest, uint32_t tlli);
77
Jacob Erlbeck37005a12015-12-22 14:58:34 +010078 static void write_packet_uplink_ack(
Alexander Couzens3a499f32019-06-16 15:25:30 +020079 bitvec * dest, struct gprs_rlcmac_ul_tbf *tbf, bool is_final,
Jacob Erlbeckf2694b72016-01-26 21:46:26 +010080 uint8_t rrbp);
Holger Hans Peter Freyther63f29d62013-10-19 19:04:03 +020081
Neels Hofmeyr59fc0bd2020-08-21 16:21:23 +020082 static int write_paging_request(bitvec * dest, const struct osmo_mobile_identity *mi);
Holger Hans Peter Freyther63f29d62013-10-19 19:04:03 +020083
84 static unsigned write_repeated_page_info(bitvec * dest, unsigned& wp, uint8_t len,
85 uint8_t *identity, uint8_t chan_needed);
86
87 static unsigned write_packet_paging_request(bitvec * dest);
Jacob Erlbeckf0e40392016-01-08 10:07:53 +010088
89 static int rlc_write_dl_data_header(
90 const struct gprs_rlc_data_info *rlc,
91 uint8_t *data);
92 static unsigned int rlc_copy_from_aligned_buffer(
93 const struct gprs_rlc_data_info *rlc,
94 unsigned int data_block_idx,
95 uint8_t *dst, const uint8_t *buffer);
Jacob Erlbeck14bb0942016-01-12 11:58:13 +010096
97 enum AppendResult {
98 AR_NEED_MORE_BLOCKS,
99 AR_COMPLETED_SPACE_LEFT,
100 AR_COMPLETED_BLOCK_FILLED,
101 };
102
103 static AppendResult rlc_data_to_dl_append(
Pau Espin Pedrol2ae83372020-05-18 11:35:35 +0200104 struct gprs_rlc_data_block_info *rdbi, enum CodingScheme cs,
Jacob Erlbeck14bb0942016-01-12 11:58:13 +0100105 gprs_llc *llc, int *offset, int *num_chunks,
Alexander Couzens6f0dc962016-05-30 19:30:21 +0200106 uint8_t *data, bool is_final, int *count_payload);
Pau Espin Pedrol7d0f9a02020-11-27 14:51:27 +0100107 static void rlc_data_to_dl_append_egprs_li_padding(
108 const struct gprs_rlc_data_block_info *rdbi,
109 int *offset, int *num_chunks, uint8_t *data_block);
Holger Hans Peter Freyther63f29d62013-10-19 19:04:03 +0200110};