blob: ae4d57ffc539130316a8de222c19e852c6001c3b [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.
Holger Hans Peter Freyther63f29d62013-10-19 19:04:03 +020016 */
17#pragma once
18
19#include <stdint.h>
Pau Espin Pedrol2ae83372020-05-18 11:35:35 +020020
Pau Espin Pedrolc0a250d2021-01-21 18:46:13 +010021#ifdef __cplusplus
bhargava465f5bb2016-09-02 16:50:43 +053022extern "C" {
Pau Espin Pedrolc0a250d2021-01-21 18:46:13 +010023#endif
bhargava465f5bb2016-09-02 16:50:43 +053024#include <osmocom/gsm/l1sap.h>
Pau Espin Pedrol2ae83372020-05-18 11:35:35 +020025#include "coding_scheme.h"
Pau Espin Pedrolb2653fe2020-03-26 15:14:01 +010026#include "gsm_rlcmac.h"
Pau Espin Pedrolc0a250d2021-01-21 18:46:13 +010027#ifdef __cplusplus
bhargava465f5bb2016-09-02 16:50:43 +053028}
Pau Espin Pedrolc0a250d2021-01-21 18:46:13 +010029#endif
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
Pau Espin Pedrolc0a250d2021-01-21 18:46:13 +010036#ifdef __cplusplus
Holger Hans Peter Freyther63f29d62013-10-19 19:04:03 +020037/**
38 * I help with encoding data into CSN1 messages.
39 * TODO: Nobody can remember a function signature like this. One should
40 * fill out a struct with the request parameters and then hand the struct
41 * to the code.
42 */
43class Encoding {
44public:
45 static int write_immediate_assignment(
Vadim Yanitskiy11567762020-07-18 23:34:17 +070046 const struct gprs_rlcmac_pdch *pdch,
Pau Espin Pedrolcefddbc2022-12-12 19:45:04 +010047 const struct gprs_rlcmac_tbf *tbf,
Maxfc8afc22019-02-18 18:52:38 +010048 bitvec * dest, bool downlink, uint16_t ra,
Vadim Yanitskiy11567762020-07-18 23:34:17 +070049 uint32_t ref_fn, uint8_t ta,
50 uint8_t usf, bool polling,
Jacob Erlbeck2647a332016-02-01 16:13:38 +010051 uint32_t fn, uint8_t alpha, uint8_t gamma,
bhargava465f5bb2016-09-02 16:50:43 +053052 int8_t ta_idx,
Maxfc8afc22019-02-18 18:52:38 +010053 enum ph_burst_type burst_type);
Holger Hans Peter Freyther63f29d62013-10-19 19:04:03 +020054
aravind sirsikarc0c3afd2016-11-09 16:27:00 +053055 static int write_immediate_assignment_reject(
56 bitvec *dest, uint16_t ra,
57 uint32_t ref_fn,
Pau Espin Pedrol25ebf3c2021-04-26 13:36:16 +020058 enum ph_burst_type burst_type,
59 uint8_t t3142
aravind sirsikarc0c3afd2016-11-09 16:27:00 +053060 );
61
Pau Espin Pedrolafe189e2021-07-28 21:48:26 +020062 static void encode_rbb(const char *show_rbb, bitvec *rbb);
Daniel Willmann5241c1a2013-12-11 14:35:29 +010063
Holger Hans Peter Freyther63f29d62013-10-19 19:04:03 +020064 static unsigned write_repeated_page_info(bitvec * dest, unsigned& wp, uint8_t len,
65 uint8_t *identity, uint8_t chan_needed);
66
67 static unsigned write_packet_paging_request(bitvec * dest);
Jacob Erlbeckf0e40392016-01-08 10:07:53 +010068
69 static int rlc_write_dl_data_header(
70 const struct gprs_rlc_data_info *rlc,
71 uint8_t *data);
72 static unsigned int rlc_copy_from_aligned_buffer(
73 const struct gprs_rlc_data_info *rlc,
74 unsigned int data_block_idx,
75 uint8_t *dst, const uint8_t *buffer);
Jacob Erlbeck14bb0942016-01-12 11:58:13 +010076
77 enum AppendResult {
78 AR_NEED_MORE_BLOCKS,
79 AR_COMPLETED_SPACE_LEFT,
80 AR_COMPLETED_BLOCK_FILLED,
81 };
82
83 static AppendResult rlc_data_to_dl_append(
Pau Espin Pedrol2ae83372020-05-18 11:35:35 +020084 struct gprs_rlc_data_block_info *rdbi, enum CodingScheme cs,
Jacob Erlbeck14bb0942016-01-12 11:58:13 +010085 gprs_llc *llc, int *offset, int *num_chunks,
Alexander Couzens6f0dc962016-05-30 19:30:21 +020086 uint8_t *data, bool is_final, int *count_payload);
Pau Espin Pedrol7d0f9a02020-11-27 14:51:27 +010087 static void rlc_data_to_dl_append_egprs_li_padding(
88 const struct gprs_rlc_data_block_info *rdbi,
89 int *offset, int *num_chunks, uint8_t *data_block);
Holger Hans Peter Freyther63f29d62013-10-19 19:04:03 +020090};
Pau Espin Pedrolc0a250d2021-01-21 18:46:13 +010091
92#endif /* ifdef __cplusplus */
93
94#ifdef __cplusplus
95extern "C" {
96#endif
97
Pau Espin Pedrol6ad11a62021-07-27 12:27:08 +020098void write_packet_access_reject(struct bitvec *dest, uint32_t tlli, unsigned long t3172_ms);
Maxcb947e02023-04-12 08:27:54 +030099
100int write_paging_request(struct bitvec *dest, const struct osmo_mobile_identity *mi);
101
Pau Espin Pedrol6ad11a62021-07-27 12:27:08 +0200102void write_packet_uplink_assignment(RlcMacDownlink_t *block, uint8_t old_tfi,
103 uint8_t old_downlink, uint32_t tlli, uint8_t use_tlli,
104 const struct gprs_rlcmac_ul_tbf *tbf, uint8_t poll,
105 uint8_t rrbp, uint8_t alpha, uint8_t gamma, int8_t ta_idx,
106 bool use_egprs);
107
Pau Espin Pedrol49a2f402021-07-27 17:33:07 +0200108void write_packet_downlink_assignment(RlcMacDownlink_t * block, bool old_tfi_is_valid,
109 uint8_t old_tfi, uint8_t old_downlink,
110 const struct gprs_rlcmac_dl_tbf *tbf, uint8_t poll,
111 uint8_t rrbp, uint8_t alpha, uint8_t gamma,
112 int8_t ta_idx, uint8_t ta_ts, bool use_egprs,
113 uint8_t control_ack);
114
Pau Espin Pedrolea8dbdd2021-07-29 18:39:16 +0200115void write_packet_uplink_ack(struct bitvec *dest, struct gprs_rlcmac_ul_tbf *tbf,
116 bool is_final, uint8_t rrbp);
117
Pau Espin Pedrolc0a250d2021-01-21 18:46:13 +0100118void write_packet_neighbour_cell_data(RlcMacDownlink_t *block,
119 bool tfi_is_dl, uint8_t tfi, uint8_t container_id,
120 uint8_t container_idx, PNCDContainer_t *container);
121
Pau Espin Pedrol952cb3d2021-02-01 14:52:48 +0100122void write_packet_cell_change_continue(RlcMacDownlink_t *block, uint8_t poll, uint8_t rrbp,
123 bool tfi_is_dl, uint8_t tfi, bool exist_id,
124 uint16_t arfcn, uint8_t bsic, uint8_t container_id);
Pau Espin Pedrolc0a250d2021-01-21 18:46:13 +0100125
126#ifdef __cplusplus
127}
128#endif