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> |
bhargava | 465f5bb | 2016-09-02 16:50:43 +0530 | [diff] [blame] | 26 | extern "C" { |
| 27 | #include <osmocom/gsm/l1sap.h> |
| 28 | } |
Holger Hans Peter Freyther | 63f29d6 | 2013-10-19 19:04:03 +0200 | [diff] [blame] | 29 | |
| 30 | struct gprs_rlcmac_bts; |
| 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 | |
| 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 | */ |
| 42 | class Encoding { |
| 43 | public: |
| 44 | static int write_immediate_assignment( |
Jacob Erlbeck | 2647a33 | 2016-02-01 16:13:38 +0100 | [diff] [blame] | 45 | struct gprs_rlcmac_tbf *tbf, |
bhargava | 465f5bb | 2016-09-02 16:50:43 +0530 | [diff] [blame] | 46 | bitvec * dest, uint8_t downlink, uint16_t ra, |
Jacob Erlbeck | 2647a33 | 2016-02-01 16:13:38 +0100 | [diff] [blame] | 47 | uint32_t ref_fn, uint8_t ta, uint16_t arfcn, uint8_t ts, |
| 48 | uint8_t tsc, uint8_t usf, uint8_t polling, |
| 49 | uint32_t fn, uint8_t alpha, uint8_t gamma, |
bhargava | 465f5bb | 2016-09-02 16:50:43 +0530 | [diff] [blame] | 50 | int8_t ta_idx, |
| 51 | enum ph_burst_type burst_type = |
| 52 | GSM_L1_BURST_TYPE_ACCESS_0, |
| 53 | uint8_t sb = 1); |
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, |
| 58 | enum ph_burst_type burst_type |
| 59 | ); |
| 60 | |
Holger Hans Peter Freyther | 63f29d6 | 2013-10-19 19:04:03 +0200 | [diff] [blame] | 61 | static void write_packet_uplink_assignment( |
| 62 | struct gprs_rlcmac_bts *bts, |
| 63 | bitvec * dest, uint8_t old_tfi, |
Jacob Erlbeck | f2694b7 | 2016-01-26 21:46:26 +0100 | [diff] [blame] | 64 | uint8_t old_downlink, uint32_t tlli, uint8_t use_tlli, |
| 65 | struct gprs_rlcmac_ul_tbf *tbf, uint8_t poll, uint8_t rrbp, |
| 66 | uint8_t alpha, uint8_t gamma, int8_t ta_idx, |
| 67 | int8_t use_egprs); |
Holger Hans Peter Freyther | 63f29d6 | 2013-10-19 19:04:03 +0200 | [diff] [blame] | 68 | |
Jacob Erlbeck | 166c9fc | 2016-01-07 16:04:29 +0100 | [diff] [blame] | 69 | static void write_packet_downlink_assignment(RlcMacDownlink_t * block, |
Jacob Erlbeck | 6b356a5 | 2016-01-29 16:39:21 +0100 | [diff] [blame] | 70 | bool old_tfi_is_valid, uint8_t old_tfi, uint8_t old_downlink, |
Jacob Erlbeck | f2694b7 | 2016-01-26 21:46:26 +0100 | [diff] [blame] | 71 | struct gprs_rlcmac_tbf *tbf, uint8_t poll, uint8_t rrbp, |
| 72 | uint8_t alpha, uint8_t gamma, |
| 73 | 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] | 74 | |
Daniel Willmann | 5241c1a | 2013-12-11 14:35:29 +0100 | [diff] [blame] | 75 | static void encode_rbb(const char *show_rbb, uint8_t *rbb); |
| 76 | |
aravind sirsikar | ed3413e | 2016-11-11 17:15:10 +0530 | [diff] [blame^] | 77 | static void write_packet_access_reject( |
| 78 | bitvec * dest, uint32_t tlli); |
| 79 | |
Jacob Erlbeck | 37005a1 | 2015-12-22 14:58:34 +0100 | [diff] [blame] | 80 | static void write_packet_uplink_ack( |
| 81 | struct gprs_rlcmac_bts *bts, bitvec * dest, |
Jacob Erlbeck | f2694b7 | 2016-01-26 21:46:26 +0100 | [diff] [blame] | 82 | struct gprs_rlcmac_ul_tbf *tbf, bool is_final, |
| 83 | uint8_t rrbp); |
Holger Hans Peter Freyther | 63f29d6 | 2013-10-19 19:04:03 +0200 | [diff] [blame] | 84 | |
| 85 | static int write_paging_request(bitvec * dest, uint8_t *ptmsi, uint16_t ptmsi_len); |
| 86 | |
| 87 | static unsigned write_repeated_page_info(bitvec * dest, unsigned& wp, uint8_t len, |
| 88 | uint8_t *identity, uint8_t chan_needed); |
| 89 | |
| 90 | static unsigned write_packet_paging_request(bitvec * dest); |
Jacob Erlbeck | f0e4039 | 2016-01-08 10:07:53 +0100 | [diff] [blame] | 91 | |
| 92 | static int rlc_write_dl_data_header( |
| 93 | const struct gprs_rlc_data_info *rlc, |
| 94 | uint8_t *data); |
| 95 | static unsigned int rlc_copy_from_aligned_buffer( |
| 96 | const struct gprs_rlc_data_info *rlc, |
| 97 | unsigned int data_block_idx, |
| 98 | uint8_t *dst, const uint8_t *buffer); |
Jacob Erlbeck | 14bb094 | 2016-01-12 11:58:13 +0100 | [diff] [blame] | 99 | |
| 100 | enum AppendResult { |
| 101 | AR_NEED_MORE_BLOCKS, |
| 102 | AR_COMPLETED_SPACE_LEFT, |
| 103 | AR_COMPLETED_BLOCK_FILLED, |
| 104 | }; |
| 105 | |
| 106 | static AppendResult rlc_data_to_dl_append( |
Jacob Erlbeck | 5058bd6 | 2016-01-13 10:51:25 +0100 | [diff] [blame] | 107 | struct gprs_rlc_data_block_info *rdbi, GprsCodingScheme cs, |
Jacob Erlbeck | 14bb094 | 2016-01-12 11:58:13 +0100 | [diff] [blame] | 108 | gprs_llc *llc, int *offset, int *num_chunks, |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 109 | uint8_t *data, bool is_final, int *count_payload); |
Holger Hans Peter Freyther | 63f29d6 | 2013-10-19 19:04:03 +0200 | [diff] [blame] | 110 | }; |