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. |
| 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> |
| 24 | #include <gsm_rlcmac.h> |
Jacob Erlbeck | 5058bd6 | 2016-01-13 10:51:25 +0100 | [diff] [blame] | 25 | #include <gprs_coding_scheme.h> |
Holger Hans Peter Freyther | 63f29d6 | 2013-10-19 19:04:03 +0200 | [diff] [blame] | 26 | |
| 27 | struct gprs_rlcmac_bts; |
| 28 | struct gprs_rlcmac_tbf; |
| 29 | struct bitvec; |
Jacob Erlbeck | 14bb094 | 2016-01-12 11:58:13 +0100 | [diff] [blame] | 30 | struct gprs_llc; |
| 31 | struct gprs_rlc_data_block_info; |
Holger Hans Peter Freyther | 63f29d6 | 2013-10-19 19:04:03 +0200 | [diff] [blame] | 32 | |
| 33 | /** |
| 34 | * I help with encoding data into CSN1 messages. |
| 35 | * TODO: Nobody can remember a function signature like this. One should |
| 36 | * fill out a struct with the request parameters and then hand the struct |
| 37 | * to the code. |
| 38 | */ |
| 39 | class Encoding { |
| 40 | public: |
| 41 | static int write_immediate_assignment( |
| 42 | struct gprs_rlcmac_bts *bts, |
| 43 | bitvec * dest, uint8_t downlink, uint8_t ra, |
| 44 | uint32_t ref_fn, uint8_t ta, uint16_t arfcn, uint8_t ts, uint8_t tsc, |
| 45 | uint8_t tfi, uint8_t usf, uint32_t tlli, uint8_t polling, |
| 46 | uint32_t fn, uint8_t single_block, uint8_t alpha, uint8_t gamma, |
| 47 | int8_t ta_idx); |
| 48 | |
| 49 | static void write_packet_uplink_assignment( |
| 50 | struct gprs_rlcmac_bts *bts, |
| 51 | bitvec * dest, uint8_t old_tfi, |
Jacob Erlbeck | f2694b7 | 2016-01-26 21:46:26 +0100 | [diff] [blame^] | 52 | uint8_t old_downlink, uint32_t tlli, uint8_t use_tlli, |
| 53 | struct gprs_rlcmac_ul_tbf *tbf, uint8_t poll, uint8_t rrbp, |
| 54 | uint8_t alpha, uint8_t gamma, int8_t ta_idx, |
| 55 | int8_t use_egprs); |
Holger Hans Peter Freyther | 63f29d6 | 2013-10-19 19:04:03 +0200 | [diff] [blame] | 56 | |
Jacob Erlbeck | 166c9fc | 2016-01-07 16:04:29 +0100 | [diff] [blame] | 57 | static void write_packet_downlink_assignment(RlcMacDownlink_t * block, |
| 58 | uint8_t old_tfi, uint8_t old_downlink, |
Jacob Erlbeck | f2694b7 | 2016-01-26 21:46:26 +0100 | [diff] [blame^] | 59 | struct gprs_rlcmac_tbf *tbf, uint8_t poll, uint8_t rrbp, |
| 60 | uint8_t alpha, uint8_t gamma, |
| 61 | int8_t ta_idx, uint8_t ta_ts, bool use_egprs); |
Holger Hans Peter Freyther | 63f29d6 | 2013-10-19 19:04:03 +0200 | [diff] [blame] | 62 | |
Daniel Willmann | 5241c1a | 2013-12-11 14:35:29 +0100 | [diff] [blame] | 63 | static void encode_rbb(const char *show_rbb, uint8_t *rbb); |
| 64 | |
Jacob Erlbeck | 37005a1 | 2015-12-22 14:58:34 +0100 | [diff] [blame] | 65 | static void write_packet_uplink_ack( |
| 66 | struct gprs_rlcmac_bts *bts, bitvec * dest, |
Jacob Erlbeck | f2694b7 | 2016-01-26 21:46:26 +0100 | [diff] [blame^] | 67 | struct gprs_rlcmac_ul_tbf *tbf, bool is_final, |
| 68 | uint8_t rrbp); |
Holger Hans Peter Freyther | 63f29d6 | 2013-10-19 19:04:03 +0200 | [diff] [blame] | 69 | |
| 70 | static int write_paging_request(bitvec * dest, uint8_t *ptmsi, uint16_t ptmsi_len); |
| 71 | |
| 72 | static unsigned write_repeated_page_info(bitvec * dest, unsigned& wp, uint8_t len, |
| 73 | uint8_t *identity, uint8_t chan_needed); |
| 74 | |
| 75 | static unsigned write_packet_paging_request(bitvec * dest); |
Jacob Erlbeck | f0e4039 | 2016-01-08 10:07:53 +0100 | [diff] [blame] | 76 | |
| 77 | static int rlc_write_dl_data_header( |
| 78 | const struct gprs_rlc_data_info *rlc, |
| 79 | uint8_t *data); |
| 80 | static unsigned int rlc_copy_from_aligned_buffer( |
| 81 | const struct gprs_rlc_data_info *rlc, |
| 82 | unsigned int data_block_idx, |
| 83 | uint8_t *dst, const uint8_t *buffer); |
Jacob Erlbeck | 14bb094 | 2016-01-12 11:58:13 +0100 | [diff] [blame] | 84 | |
| 85 | enum AppendResult { |
| 86 | AR_NEED_MORE_BLOCKS, |
| 87 | AR_COMPLETED_SPACE_LEFT, |
| 88 | AR_COMPLETED_BLOCK_FILLED, |
| 89 | }; |
| 90 | |
| 91 | static AppendResult rlc_data_to_dl_append( |
Jacob Erlbeck | 5058bd6 | 2016-01-13 10:51:25 +0100 | [diff] [blame] | 92 | struct gprs_rlc_data_block_info *rdbi, GprsCodingScheme cs, |
Jacob Erlbeck | 14bb094 | 2016-01-12 11:58:13 +0100 | [diff] [blame] | 93 | gprs_llc *llc, int *offset, int *num_chunks, |
| 94 | uint8_t *data, |
| 95 | bool is_final); |
Holger Hans Peter Freyther | 63f29d6 | 2013-10-19 19:04:03 +0200 | [diff] [blame] | 96 | }; |