blob: 998e69aaf82d4c12c49ff836c457420d5cb1129f [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
Pau Espin Pedrolc0a250d2021-01-21 18:46:13 +010025#ifdef __cplusplus
bhargava465f5bb2016-09-02 16:50:43 +053026extern "C" {
Pau Espin Pedrolc0a250d2021-01-21 18:46:13 +010027#endif
bhargava465f5bb2016-09-02 16:50:43 +053028#include <osmocom/gsm/l1sap.h>
Pau Espin Pedrol2ae83372020-05-18 11:35:35 +020029#include "coding_scheme.h"
Pau Espin Pedrolb2653fe2020-03-26 15:14:01 +010030#include "gsm_rlcmac.h"
Pau Espin Pedrolc0a250d2021-01-21 18:46:13 +010031#ifdef __cplusplus
bhargava465f5bb2016-09-02 16:50:43 +053032}
Pau Espin Pedrolc0a250d2021-01-21 18:46:13 +010033#endif
Holger Hans Peter Freyther63f29d62013-10-19 19:04:03 +020034
Holger Hans Peter Freyther63f29d62013-10-19 19:04:03 +020035struct gprs_rlcmac_tbf;
36struct bitvec;
Jacob Erlbeck14bb0942016-01-12 11:58:13 +010037struct gprs_llc;
38struct gprs_rlc_data_block_info;
Holger Hans Peter Freyther63f29d62013-10-19 19:04:03 +020039
Pau Espin Pedrolc0a250d2021-01-21 18:46:13 +010040#ifdef __cplusplus
Holger Hans Peter Freyther63f29d62013-10-19 19:04:03 +020041/**
42 * I help with encoding data into CSN1 messages.
43 * TODO: Nobody can remember a function signature like this. One should
44 * fill out a struct with the request parameters and then hand the struct
45 * to the code.
46 */
47class Encoding {
48public:
49 static int write_immediate_assignment(
Vadim Yanitskiy11567762020-07-18 23:34:17 +070050 const struct gprs_rlcmac_pdch *pdch,
Jacob Erlbeck2647a332016-02-01 16:13:38 +010051 struct gprs_rlcmac_tbf *tbf,
Maxfc8afc22019-02-18 18:52:38 +010052 bitvec * dest, bool downlink, uint16_t ra,
Vadim Yanitskiy11567762020-07-18 23:34:17 +070053 uint32_t ref_fn, uint8_t ta,
54 uint8_t usf, bool polling,
Jacob Erlbeck2647a332016-02-01 16:13:38 +010055 uint32_t fn, uint8_t alpha, uint8_t gamma,
bhargava465f5bb2016-09-02 16:50:43 +053056 int8_t ta_idx,
Maxfc8afc22019-02-18 18:52:38 +010057 enum ph_burst_type burst_type);
Holger Hans Peter Freyther63f29d62013-10-19 19:04:03 +020058
aravind sirsikarc0c3afd2016-11-09 16:27:00 +053059 static int write_immediate_assignment_reject(
60 bitvec *dest, uint16_t ra,
61 uint32_t ref_fn,
Pau Espin Pedrol25ebf3c2021-04-26 13:36:16 +020062 enum ph_burst_type burst_type,
63 uint8_t t3142
aravind sirsikarc0c3afd2016-11-09 16:27:00 +053064 );
65
Pau Espin Pedrolafe189e2021-07-28 21:48:26 +020066 static void encode_rbb(const char *show_rbb, bitvec *rbb);
Daniel Willmann5241c1a2013-12-11 14:35:29 +010067
Neels Hofmeyr59fc0bd2020-08-21 16:21:23 +020068 static int write_paging_request(bitvec * dest, const struct osmo_mobile_identity *mi);
Holger Hans Peter Freyther63f29d62013-10-19 19:04:03 +020069
70 static unsigned write_repeated_page_info(bitvec * dest, unsigned& wp, uint8_t len,
71 uint8_t *identity, uint8_t chan_needed);
72
73 static unsigned write_packet_paging_request(bitvec * dest);
Jacob Erlbeckf0e40392016-01-08 10:07:53 +010074
75 static int rlc_write_dl_data_header(
76 const struct gprs_rlc_data_info *rlc,
77 uint8_t *data);
78 static unsigned int rlc_copy_from_aligned_buffer(
79 const struct gprs_rlc_data_info *rlc,
80 unsigned int data_block_idx,
81 uint8_t *dst, const uint8_t *buffer);
Jacob Erlbeck14bb0942016-01-12 11:58:13 +010082
83 enum AppendResult {
84 AR_NEED_MORE_BLOCKS,
85 AR_COMPLETED_SPACE_LEFT,
86 AR_COMPLETED_BLOCK_FILLED,
87 };
88
89 static AppendResult rlc_data_to_dl_append(
Pau Espin Pedrol2ae83372020-05-18 11:35:35 +020090 struct gprs_rlc_data_block_info *rdbi, enum CodingScheme cs,
Jacob Erlbeck14bb0942016-01-12 11:58:13 +010091 gprs_llc *llc, int *offset, int *num_chunks,
Alexander Couzens6f0dc962016-05-30 19:30:21 +020092 uint8_t *data, bool is_final, int *count_payload);
Pau Espin Pedrol7d0f9a02020-11-27 14:51:27 +010093 static void rlc_data_to_dl_append_egprs_li_padding(
94 const struct gprs_rlc_data_block_info *rdbi,
95 int *offset, int *num_chunks, uint8_t *data_block);
Holger Hans Peter Freyther63f29d62013-10-19 19:04:03 +020096};
Pau Espin Pedrolc0a250d2021-01-21 18:46:13 +010097
98#endif /* ifdef __cplusplus */
99
100#ifdef __cplusplus
101extern "C" {
102#endif
103
Pau Espin Pedrol6ad11a62021-07-27 12:27:08 +0200104void write_packet_access_reject(struct bitvec *dest, uint32_t tlli, unsigned long t3172_ms);
105void write_packet_uplink_assignment(RlcMacDownlink_t *block, uint8_t old_tfi,
106 uint8_t old_downlink, uint32_t tlli, uint8_t use_tlli,
107 const struct gprs_rlcmac_ul_tbf *tbf, uint8_t poll,
108 uint8_t rrbp, uint8_t alpha, uint8_t gamma, int8_t ta_idx,
109 bool use_egprs);
110
Pau Espin Pedrol49a2f402021-07-27 17:33:07 +0200111void write_packet_downlink_assignment(RlcMacDownlink_t * block, bool old_tfi_is_valid,
112 uint8_t old_tfi, uint8_t old_downlink,
113 const struct gprs_rlcmac_dl_tbf *tbf, uint8_t poll,
114 uint8_t rrbp, uint8_t alpha, uint8_t gamma,
115 int8_t ta_idx, uint8_t ta_ts, bool use_egprs,
116 uint8_t control_ack);
117
Pau Espin Pedrolea8dbdd2021-07-29 18:39:16 +0200118void write_packet_uplink_ack(struct bitvec *dest, struct gprs_rlcmac_ul_tbf *tbf,
119 bool is_final, uint8_t rrbp);
120
Pau Espin Pedrolc0a250d2021-01-21 18:46:13 +0100121void write_packet_neighbour_cell_data(RlcMacDownlink_t *block,
122 bool tfi_is_dl, uint8_t tfi, uint8_t container_id,
123 uint8_t container_idx, PNCDContainer_t *container);
124
Pau Espin Pedrol952cb3d2021-02-01 14:52:48 +0100125void write_packet_cell_change_continue(RlcMacDownlink_t *block, uint8_t poll, uint8_t rrbp,
126 bool tfi_is_dl, uint8_t tfi, bool exist_id,
127 uint16_t arfcn, uint8_t bsic, uint8_t container_id);
Pau Espin Pedrolc0a250d2021-01-21 18:46:13 +0100128
129#ifdef __cplusplus
130}
131#endif