Holger Hans Peter Freyther | 63f29d6 | 2013-10-19 19:04:03 +0200 | [diff] [blame] | 1 | /* 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 Freyther | 63f29d6 | 2013-10-19 19:04:03 +0200 | [diff] [blame] | 16 | */ |
| 17 | #pragma once |
| 18 | |
| 19 | #include <stdint.h> |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 20 | |
Pau Espin Pedrol | c0a250d | 2021-01-21 18:46:13 +0100 | [diff] [blame] | 21 | #ifdef __cplusplus |
bhargava | 465f5bb | 2016-09-02 16:50:43 +0530 | [diff] [blame] | 22 | extern "C" { |
Pau Espin Pedrol | c0a250d | 2021-01-21 18:46:13 +0100 | [diff] [blame] | 23 | #endif |
bhargava | 465f5bb | 2016-09-02 16:50:43 +0530 | [diff] [blame] | 24 | #include <osmocom/gsm/l1sap.h> |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 25 | #include "coding_scheme.h" |
Pau Espin Pedrol | b2653fe | 2020-03-26 15:14:01 +0100 | [diff] [blame] | 26 | #include "gsm_rlcmac.h" |
Pau Espin Pedrol | c0a250d | 2021-01-21 18:46:13 +0100 | [diff] [blame] | 27 | #ifdef __cplusplus |
bhargava | 465f5bb | 2016-09-02 16:50:43 +0530 | [diff] [blame] | 28 | } |
Pau Espin Pedrol | c0a250d | 2021-01-21 18:46:13 +0100 | [diff] [blame] | 29 | #endif |
Holger Hans Peter Freyther | 63f29d6 | 2013-10-19 19:04:03 +0200 | [diff] [blame] | 30 | |
Holger Hans Peter Freyther | 63f29d6 | 2013-10-19 19:04:03 +0200 | [diff] [blame] | 31 | struct gprs_rlcmac_tbf; |
| 32 | struct bitvec; |
Jacob Erlbeck | 14bb094 | 2016-01-12 11:58:13 +0100 | [diff] [blame] | 33 | struct gprs_llc; |
| 34 | struct gprs_rlc_data_block_info; |
Holger Hans Peter Freyther | 63f29d6 | 2013-10-19 19:04:03 +0200 | [diff] [blame] | 35 | |
Pau Espin Pedrol | c0a250d | 2021-01-21 18:46:13 +0100 | [diff] [blame] | 36 | #ifdef __cplusplus |
Holger Hans Peter Freyther | 63f29d6 | 2013-10-19 19:04:03 +0200 | [diff] [blame] | 37 | /** |
| 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 | */ |
| 43 | class Encoding { |
| 44 | public: |
| 45 | static int write_immediate_assignment( |
Vadim Yanitskiy | 1156776 | 2020-07-18 23:34:17 +0700 | [diff] [blame] | 46 | const struct gprs_rlcmac_pdch *pdch, |
Jacob Erlbeck | 2647a33 | 2016-02-01 16:13:38 +0100 | [diff] [blame] | 47 | struct gprs_rlcmac_tbf *tbf, |
Max | fc8afc2 | 2019-02-18 18:52:38 +0100 | [diff] [blame] | 48 | bitvec * dest, bool downlink, uint16_t ra, |
Vadim Yanitskiy | 1156776 | 2020-07-18 23:34:17 +0700 | [diff] [blame] | 49 | uint32_t ref_fn, uint8_t ta, |
| 50 | uint8_t usf, bool polling, |
Jacob Erlbeck | 2647a33 | 2016-02-01 16:13:38 +0100 | [diff] [blame] | 51 | uint32_t fn, uint8_t alpha, uint8_t gamma, |
bhargava | 465f5bb | 2016-09-02 16:50:43 +0530 | [diff] [blame] | 52 | int8_t ta_idx, |
Max | fc8afc2 | 2019-02-18 18:52:38 +0100 | [diff] [blame] | 53 | enum ph_burst_type burst_type); |
Holger Hans Peter Freyther | 63f29d6 | 2013-10-19 19:04:03 +0200 | [diff] [blame] | 54 | |
aravind sirsikar | c0c3afd | 2016-11-09 16:27:00 +0530 | [diff] [blame] | 55 | static int write_immediate_assignment_reject( |
| 56 | bitvec *dest, uint16_t ra, |
| 57 | uint32_t ref_fn, |
Pau Espin Pedrol | 25ebf3c | 2021-04-26 13:36:16 +0200 | [diff] [blame] | 58 | enum ph_burst_type burst_type, |
| 59 | uint8_t t3142 |
aravind sirsikar | c0c3afd | 2016-11-09 16:27:00 +0530 | [diff] [blame] | 60 | ); |
| 61 | |
Pau Espin Pedrol | afe189e | 2021-07-28 21:48:26 +0200 | [diff] [blame] | 62 | static void encode_rbb(const char *show_rbb, bitvec *rbb); |
Daniel Willmann | 5241c1a | 2013-12-11 14:35:29 +0100 | [diff] [blame] | 63 | |
Neels Hofmeyr | 59fc0bd | 2020-08-21 16:21:23 +0200 | [diff] [blame] | 64 | static int write_paging_request(bitvec * dest, const struct osmo_mobile_identity *mi); |
Holger Hans Peter Freyther | 63f29d6 | 2013-10-19 19:04:03 +0200 | [diff] [blame] | 65 | |
| 66 | static unsigned write_repeated_page_info(bitvec * dest, unsigned& wp, uint8_t len, |
| 67 | uint8_t *identity, uint8_t chan_needed); |
| 68 | |
| 69 | static unsigned write_packet_paging_request(bitvec * dest); |
Jacob Erlbeck | f0e4039 | 2016-01-08 10:07:53 +0100 | [diff] [blame] | 70 | |
| 71 | static int rlc_write_dl_data_header( |
| 72 | const struct gprs_rlc_data_info *rlc, |
| 73 | uint8_t *data); |
| 74 | static unsigned int rlc_copy_from_aligned_buffer( |
| 75 | const struct gprs_rlc_data_info *rlc, |
| 76 | unsigned int data_block_idx, |
| 77 | uint8_t *dst, const uint8_t *buffer); |
Jacob Erlbeck | 14bb094 | 2016-01-12 11:58:13 +0100 | [diff] [blame] | 78 | |
| 79 | enum AppendResult { |
| 80 | AR_NEED_MORE_BLOCKS, |
| 81 | AR_COMPLETED_SPACE_LEFT, |
| 82 | AR_COMPLETED_BLOCK_FILLED, |
| 83 | }; |
| 84 | |
| 85 | static AppendResult rlc_data_to_dl_append( |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 86 | struct gprs_rlc_data_block_info *rdbi, enum CodingScheme cs, |
Jacob Erlbeck | 14bb094 | 2016-01-12 11:58:13 +0100 | [diff] [blame] | 87 | gprs_llc *llc, int *offset, int *num_chunks, |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 88 | uint8_t *data, bool is_final, int *count_payload); |
Pau Espin Pedrol | 7d0f9a0 | 2020-11-27 14:51:27 +0100 | [diff] [blame] | 89 | static void rlc_data_to_dl_append_egprs_li_padding( |
| 90 | const struct gprs_rlc_data_block_info *rdbi, |
| 91 | int *offset, int *num_chunks, uint8_t *data_block); |
Holger Hans Peter Freyther | 63f29d6 | 2013-10-19 19:04:03 +0200 | [diff] [blame] | 92 | }; |
Pau Espin Pedrol | c0a250d | 2021-01-21 18:46:13 +0100 | [diff] [blame] | 93 | |
| 94 | #endif /* ifdef __cplusplus */ |
| 95 | |
| 96 | #ifdef __cplusplus |
| 97 | extern "C" { |
| 98 | #endif |
| 99 | |
Pau Espin Pedrol | 6ad11a6 | 2021-07-27 12:27:08 +0200 | [diff] [blame] | 100 | void write_packet_access_reject(struct bitvec *dest, uint32_t tlli, unsigned long t3172_ms); |
| 101 | void write_packet_uplink_assignment(RlcMacDownlink_t *block, uint8_t old_tfi, |
| 102 | uint8_t old_downlink, uint32_t tlli, uint8_t use_tlli, |
| 103 | const struct gprs_rlcmac_ul_tbf *tbf, uint8_t poll, |
| 104 | uint8_t rrbp, uint8_t alpha, uint8_t gamma, int8_t ta_idx, |
| 105 | bool use_egprs); |
| 106 | |
Pau Espin Pedrol | 49a2f40 | 2021-07-27 17:33:07 +0200 | [diff] [blame] | 107 | void write_packet_downlink_assignment(RlcMacDownlink_t * block, bool old_tfi_is_valid, |
| 108 | uint8_t old_tfi, uint8_t old_downlink, |
| 109 | const struct gprs_rlcmac_dl_tbf *tbf, uint8_t poll, |
| 110 | uint8_t rrbp, uint8_t alpha, uint8_t gamma, |
| 111 | int8_t ta_idx, uint8_t ta_ts, bool use_egprs, |
| 112 | uint8_t control_ack); |
| 113 | |
Pau Espin Pedrol | ea8dbdd | 2021-07-29 18:39:16 +0200 | [diff] [blame] | 114 | void write_packet_uplink_ack(struct bitvec *dest, struct gprs_rlcmac_ul_tbf *tbf, |
| 115 | bool is_final, uint8_t rrbp); |
| 116 | |
Pau Espin Pedrol | c0a250d | 2021-01-21 18:46:13 +0100 | [diff] [blame] | 117 | void write_packet_neighbour_cell_data(RlcMacDownlink_t *block, |
| 118 | bool tfi_is_dl, uint8_t tfi, uint8_t container_id, |
| 119 | uint8_t container_idx, PNCDContainer_t *container); |
| 120 | |
Pau Espin Pedrol | 952cb3d | 2021-02-01 14:52:48 +0100 | [diff] [blame] | 121 | void write_packet_cell_change_continue(RlcMacDownlink_t *block, uint8_t poll, uint8_t rrbp, |
| 122 | bool tfi_is_dl, uint8_t tfi, bool exist_id, |
| 123 | uint16_t arfcn, uint8_t bsic, uint8_t container_id); |
Pau Espin Pedrol | c0a250d | 2021-01-21 18:46:13 +0100 | [diff] [blame] | 124 | |
| 125 | #ifdef __cplusplus |
| 126 | } |
| 127 | #endif |