Holger Hans Peter Freyther | 6ca0a90 | 2013-10-19 18:50:22 +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 | |
Holger Hans Peter Freyther | 63f29d6 | 2013-10-19 19:04:03 +0200 | [diff] [blame] | 22 | #include <encoding.h> |
Holger Hans Peter Freyther | 6ca0a90 | 2013-10-19 18:50:22 +0200 | [diff] [blame] | 23 | #include <gprs_rlcmac.h> |
Holger Hans Peter Freyther | 34bd8bd | 2013-10-19 21:10:38 +0200 | [diff] [blame] | 24 | #include <bts.h> |
Holger Hans Peter Freyther | 6ca0a90 | 2013-10-19 18:50:22 +0200 | [diff] [blame] | 25 | #include <tbf.h> |
| 26 | #include <gprs_debug.h> |
sivasankari | 8adfcd0 | 2017-01-16 15:41:21 +0530 | [diff] [blame] | 27 | #include <egprs_rlc_compression.h> |
Holger Hans Peter Freyther | 6ca0a90 | 2013-10-19 18:50:22 +0200 | [diff] [blame] | 28 | |
Tom Tsou | df69809 | 2016-07-11 17:05:19 -0700 | [diff] [blame] | 29 | extern "C" { |
| 30 | #include <osmocom/gprs/protocol/gsm_04_60.h> |
| 31 | } |
| 32 | |
Max | d572054 | 2016-07-14 15:41:17 +0200 | [diff] [blame] | 33 | #include <osmocom/gsm/protocol/gsm_04_08.h> |
| 34 | |
| 35 | #include <stdbool.h> |
Jacob Erlbeck | f0e4039 | 2016-01-08 10:07:53 +0100 | [diff] [blame] | 36 | #include <errno.h> |
| 37 | #include <string.h> |
| 38 | |
Max | ae48381 | 2016-07-28 12:03:08 +0200 | [diff] [blame] | 39 | /* { 0 | 1 < TIMING_ADVANCE_INDEX : bit (4) > } */ |
| 40 | static inline bool write_tai(bitvec *dest, unsigned& wp, int8_t tai) |
| 41 | { |
| 42 | if (tai < 0) { /* No TIMING_ADVANCE_INDEX: */ |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 43 | bitvec_write_field(dest, &wp, 0, 1); |
Max | ae48381 | 2016-07-28 12:03:08 +0200 | [diff] [blame] | 44 | return false; |
| 45 | } |
| 46 | /* TIMING_ADVANCE_INDEX: */ |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 47 | bitvec_write_field(dest, &wp, 1, 1); |
| 48 | bitvec_write_field(dest, &wp, tai, 4); |
Max | ae48381 | 2016-07-28 12:03:08 +0200 | [diff] [blame] | 49 | return true; |
| 50 | } |
| 51 | |
| 52 | /* { 0 | 1 < TIMING_ADVANCE_VALUE : bit (6) > } */ |
| 53 | static inline void write_ta(bitvec *dest, unsigned& wp, int8_t ta) |
| 54 | { |
| 55 | if (ta < 0) /* No TIMING_ADVANCE_VALUE: */ |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 56 | bitvec_write_field(dest, &wp, 0, 1); |
Max | ae48381 | 2016-07-28 12:03:08 +0200 | [diff] [blame] | 57 | else { /* TIMING_ADVANCE_VALUE: */ |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 58 | bitvec_write_field(dest, &wp, 1, 1); |
| 59 | bitvec_write_field(dest, &wp, ta, 6); |
Max | ae48381 | 2016-07-28 12:03:08 +0200 | [diff] [blame] | 60 | } |
| 61 | } |
| 62 | |
| 63 | /* 3GPP TS 44.060 ยง 12.12: |
| 64 | { 0 | 1 < TIMING_ADVANCE_VALUE : bit (6) > } |
| 65 | { 0 | 1 < TIMING_ADVANCE_INDEX : bit (4) > |
| 66 | < TIMING_ADVANCE_TIMESLOT_NUMBER : bit (3) > } |
| 67 | */ |
| 68 | static inline void write_ta_ie(bitvec *dest, unsigned& wp, |
| 69 | int8_t ta, int8_t tai, uint8_t ts) |
| 70 | { |
| 71 | write_ta(dest, wp, ta); |
| 72 | if (write_tai(dest, wp, tai)) /* TIMING_ADVANCE_TIMESLOT_NUMBER: */ |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 73 | bitvec_write_field(dest, &wp, ts, 3); |
Max | ae48381 | 2016-07-28 12:03:08 +0200 | [diff] [blame] | 74 | } |
| 75 | |
Jacob Erlbeck | 2647a33 | 2016-02-01 16:13:38 +0100 | [diff] [blame] | 76 | static int write_ia_rest_downlink( |
| 77 | gprs_rlcmac_dl_tbf *tbf, |
Jacob Erlbeck | 18831c3 | 2016-02-01 15:23:35 +0100 | [diff] [blame] | 78 | bitvec * dest, unsigned& wp, |
Max | d572054 | 2016-07-14 15:41:17 +0200 | [diff] [blame] | 79 | uint8_t polling, bool ta_valid, uint32_t fn, |
Jacob Erlbeck | 2647a33 | 2016-02-01 16:13:38 +0100 | [diff] [blame] | 80 | uint8_t alpha, uint8_t gamma, int8_t ta_idx) |
Jacob Erlbeck | 18831c3 | 2016-02-01 15:23:35 +0100 | [diff] [blame] | 81 | { |
Jacob Erlbeck | 2647a33 | 2016-02-01 16:13:38 +0100 | [diff] [blame] | 82 | if (!tbf) { |
| 83 | LOGP(DRLCMACDL, LOGL_ERROR, |
| 84 | "Cannot encode DL IMMEDIATE ASSIGNMENT without TBF\n"); |
| 85 | return -EINVAL; |
| 86 | } |
Jacob Erlbeck | 18831c3 | 2016-02-01 15:23:35 +0100 | [diff] [blame] | 87 | // GSM 04.08 10.5.2.16 IA Rest Octets |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 88 | bitvec_write_field(dest, &wp, 3, 2); // "HH" |
| 89 | bitvec_write_field(dest, &wp, 1, 2); // "01" Packet Downlink Assignment |
| 90 | bitvec_write_field(dest, &wp,tbf->tlli(),32); // TLLI |
| 91 | bitvec_write_field(dest, &wp,0x1,1); // switch TFI : on |
| 92 | bitvec_write_field(dest, &wp,tbf->tfi(),5); // TFI |
| 93 | bitvec_write_field(dest, &wp,0x0,1); // RLC acknowledged mode |
Jacob Erlbeck | 18831c3 | 2016-02-01 15:23:35 +0100 | [diff] [blame] | 94 | if (alpha) { |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 95 | bitvec_write_field(dest, &wp,0x1,1); // ALPHA = present |
| 96 | bitvec_write_field(dest, &wp,alpha,4); // ALPHA |
Jacob Erlbeck | 18831c3 | 2016-02-01 15:23:35 +0100 | [diff] [blame] | 97 | } else { |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 98 | bitvec_write_field(dest, &wp,0x0,1); // ALPHA = not present |
Jacob Erlbeck | 18831c3 | 2016-02-01 15:23:35 +0100 | [diff] [blame] | 99 | } |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 100 | bitvec_write_field(dest, &wp,gamma,5); // GAMMA power control parameter |
| 101 | bitvec_write_field(dest, &wp,polling,1); // Polling Bit |
| 102 | bitvec_write_field(dest, &wp, ta_valid, 1); // N. B: NOT related to TAI! |
Max | ae48381 | 2016-07-28 12:03:08 +0200 | [diff] [blame] | 103 | write_tai(dest, wp, ta_idx); |
Jacob Erlbeck | 18831c3 | 2016-02-01 15:23:35 +0100 | [diff] [blame] | 104 | if (polling) { |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 105 | bitvec_write_field(dest, &wp,0x1,1); // TBF Starting TIME present |
| 106 | bitvec_write_field(dest, &wp,(fn / (26 * 51)) % 32,5); // T1' |
| 107 | bitvec_write_field(dest, &wp,fn % 51,6); // T3 |
| 108 | bitvec_write_field(dest, &wp,fn % 26,5); // T2 |
Jacob Erlbeck | 18831c3 | 2016-02-01 15:23:35 +0100 | [diff] [blame] | 109 | } else { |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 110 | bitvec_write_field(dest, &wp,0x0,1); // TBF Starting TIME present |
Jacob Erlbeck | 18831c3 | 2016-02-01 15:23:35 +0100 | [diff] [blame] | 111 | } |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 112 | bitvec_write_field(dest, &wp,0x0,1); // P0 not present |
| 113 | // bitvec_write_field(dest, &wp,0x1,1); // P0 not present |
| 114 | // bitvec_write_field(dest, &wp,,0xb,4); |
Jacob Erlbeck | be80c36 | 2016-02-01 16:39:52 +0100 | [diff] [blame] | 115 | if (tbf->is_egprs_enabled()) { |
| 116 | /* see GMS 44.018, 10.5.2.16 */ |
| 117 | unsigned int ws_enc = (tbf->m_window.ws() - 64) / 32; |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 118 | bitvec_write_field(dest, &wp, 1, 1); // "H" |
| 119 | bitvec_write_field(dest, &wp, ws_enc, 5); // EGPRS Window Size |
| 120 | bitvec_write_field(dest, &wp, 0x0, 2); // LINK_QUALITY_MEASUREMENT_MODE |
| 121 | bitvec_write_field(dest, &wp, 0, 1); // BEP_PERIOD2 not present |
Jacob Erlbeck | be80c36 | 2016-02-01 16:39:52 +0100 | [diff] [blame] | 122 | } |
Jacob Erlbeck | 2647a33 | 2016-02-01 16:13:38 +0100 | [diff] [blame] | 123 | |
| 124 | return 0; |
Jacob Erlbeck | 18831c3 | 2016-02-01 15:23:35 +0100 | [diff] [blame] | 125 | } |
| 126 | |
Jacob Erlbeck | 2647a33 | 2016-02-01 16:13:38 +0100 | [diff] [blame] | 127 | static int write_ia_rest_uplink( |
| 128 | gprs_rlcmac_ul_tbf *tbf, |
| 129 | bitvec * dest, unsigned& wp, |
| 130 | uint8_t usf, uint32_t fn, |
Jacob Erlbeck | 18831c3 | 2016-02-01 15:23:35 +0100 | [diff] [blame] | 131 | uint8_t alpha, uint8_t gamma, int8_t ta_idx) |
| 132 | { |
Jacob Erlbeck | be80c36 | 2016-02-01 16:39:52 +0100 | [diff] [blame] | 133 | OSMO_ASSERT(!tbf || !tbf->is_egprs_enabled()); |
| 134 | |
Jacob Erlbeck | 18831c3 | 2016-02-01 15:23:35 +0100 | [diff] [blame] | 135 | // GMS 04.08 10.5.2.37b 10.5.2.16 |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 136 | bitvec_write_field(dest, &wp, 3, 2); // "HH" |
| 137 | bitvec_write_field(dest, &wp, 0, 2); // "0" Packet Uplink Assignment |
Jacob Erlbeck | 2647a33 | 2016-02-01 16:13:38 +0100 | [diff] [blame] | 138 | if (tbf == NULL) { |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 139 | bitvec_write_field(dest, &wp, 0, 1); // Block Allocation : Single Block Allocation |
Jacob Erlbeck | 18831c3 | 2016-02-01 15:23:35 +0100 | [diff] [blame] | 140 | if (alpha) { |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 141 | bitvec_write_field(dest, &wp,0x1,1); // ALPHA = present |
| 142 | bitvec_write_field(dest, &wp,alpha,4); // ALPHA = present |
Jacob Erlbeck | 18831c3 | 2016-02-01 15:23:35 +0100 | [diff] [blame] | 143 | } else |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 144 | bitvec_write_field(dest, &wp,0x0,1); // ALPHA = not present |
| 145 | bitvec_write_field(dest, &wp,gamma,5); // GAMMA power control parameter |
Max | ae48381 | 2016-07-28 12:03:08 +0200 | [diff] [blame] | 146 | write_tai(dest, wp, ta_idx); |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 147 | bitvec_write_field(dest, &wp, 1, 1); // TBF_STARTING_TIME_FLAG |
| 148 | bitvec_write_field(dest, &wp,(fn / (26 * 51)) % 32,5); // T1' |
| 149 | bitvec_write_field(dest, &wp,fn % 51,6); // T3 |
| 150 | bitvec_write_field(dest, &wp,fn % 26,5); // T2 |
Jacob Erlbeck | 18831c3 | 2016-02-01 15:23:35 +0100 | [diff] [blame] | 151 | } else { |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 152 | bitvec_write_field(dest, &wp, 1, 1); // Block Allocation : Not Single Block Allocation |
| 153 | bitvec_write_field(dest, &wp, tbf->tfi(), 5); // TFI_ASSIGNMENT Temporary Flow Identity |
| 154 | bitvec_write_field(dest, &wp, 0, 1); // POLLING |
| 155 | bitvec_write_field(dest, &wp, 0, 1); // ALLOCATION_TYPE: dynamic |
| 156 | bitvec_write_field(dest, &wp, usf, 3); // USF |
| 157 | bitvec_write_field(dest, &wp, 0, 1); // USF_GRANULARITY |
| 158 | bitvec_write_field(dest, &wp, 0, 1); // "0" power control: Not Present |
| 159 | bitvec_write_field(dest, &wp, tbf->current_cs().to_num()-1, 2); // CHANNEL_CODING_COMMAND |
| 160 | bitvec_write_field(dest, &wp, 1, 1); // TLLI_BLOCK_CHANNEL_CODING |
Jacob Erlbeck | 18831c3 | 2016-02-01 15:23:35 +0100 | [diff] [blame] | 161 | if (alpha) { |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 162 | bitvec_write_field(dest, &wp,0x1,1); // ALPHA = present |
| 163 | bitvec_write_field(dest, &wp,alpha,4); // ALPHA |
Jacob Erlbeck | 18831c3 | 2016-02-01 15:23:35 +0100 | [diff] [blame] | 164 | } else |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 165 | bitvec_write_field(dest, &wp,0x0,1); // ALPHA = not present |
| 166 | bitvec_write_field(dest, &wp,gamma,5); // GAMMA power control parameter |
Jacob Erlbeck | 18831c3 | 2016-02-01 15:23:35 +0100 | [diff] [blame] | 167 | /* note: there is no choise for TAI and no starting time */ |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 168 | bitvec_write_field(dest, &wp, 0, 1); // switch TIMING_ADVANCE_INDEX = off |
| 169 | bitvec_write_field(dest, &wp, 0, 1); // TBF_STARTING_TIME_FLAG |
Jacob Erlbeck | 18831c3 | 2016-02-01 15:23:35 +0100 | [diff] [blame] | 170 | } |
Jacob Erlbeck | 2647a33 | 2016-02-01 16:13:38 +0100 | [diff] [blame] | 171 | return 0; |
Jacob Erlbeck | 18831c3 | 2016-02-01 15:23:35 +0100 | [diff] [blame] | 172 | } |
| 173 | |
Jacob Erlbeck | be80c36 | 2016-02-01 16:39:52 +0100 | [diff] [blame] | 174 | static int write_ia_rest_egprs_uplink( |
| 175 | gprs_rlcmac_ul_tbf *tbf, |
| 176 | bitvec * dest, unsigned& wp, |
| 177 | uint8_t usf, uint32_t fn, |
bhargava | 465f5bb | 2016-09-02 16:50:43 +0530 | [diff] [blame] | 178 | uint8_t alpha, uint8_t gamma, int8_t ta_idx, |
| 179 | enum ph_burst_type burst_type, uint16_t ra) |
Jacob Erlbeck | be80c36 | 2016-02-01 16:39:52 +0100 | [diff] [blame] | 180 | { |
bhargava | 465f5bb | 2016-09-02 16:50:43 +0530 | [diff] [blame] | 181 | unsigned int ws_enc = 0; |
| 182 | uint8_t extended_ra = 0; |
| 183 | |
| 184 | extended_ra = (ra & 0x1F); |
| 185 | |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 186 | bitvec_write_field(dest, &wp, 1, 2); /* LH */ |
| 187 | bitvec_write_field(dest, &wp, 0, 2); /* 0 EGPRS Uplink Assignment */ |
| 188 | bitvec_write_field(dest, &wp, extended_ra, 5); /* Extended RA */ |
| 189 | bitvec_write_field(dest, &wp, 0, 1); /* Access technology Request */ |
bhargava | 465f5bb | 2016-09-02 16:50:43 +0530 | [diff] [blame] | 190 | |
| 191 | if (tbf == NULL) { |
| 192 | |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 193 | bitvec_write_field(dest, &wp, 0, 1); /* multiblock allocation */ |
bhargava | 465f5bb | 2016-09-02 16:50:43 +0530 | [diff] [blame] | 194 | |
| 195 | if (alpha) { |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 196 | bitvec_write_field(dest, &wp, 0x1, 1); /* ALPHA =yes */ |
| 197 | bitvec_write_field(dest, &wp, alpha, 4); /* ALPHA */ |
bhargava | 465f5bb | 2016-09-02 16:50:43 +0530 | [diff] [blame] | 198 | } else { |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 199 | bitvec_write_field(dest, &wp, 0x0, 1); /* ALPHA = no */ |
bhargava | 465f5bb | 2016-09-02 16:50:43 +0530 | [diff] [blame] | 200 | } |
| 201 | |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 202 | bitvec_write_field(dest, &wp, gamma, 5); /* GAMMA power contrl */ |
| 203 | bitvec_write_field(dest, &wp, (fn / (26 * 51)) % 32, 5);/* T1' */ |
| 204 | bitvec_write_field(dest, &wp, fn % 51, 6); /* T3 */ |
| 205 | bitvec_write_field(dest, &wp, fn % 26, 5); /* T2 */ |
| 206 | bitvec_write_field(dest, &wp, 0, 2); /* Radio block allocation */ |
bhargava | 465f5bb | 2016-09-02 16:50:43 +0530 | [diff] [blame] | 207 | |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 208 | bitvec_write_field(dest, &wp, 0, 1); |
bhargava | 465f5bb | 2016-09-02 16:50:43 +0530 | [diff] [blame] | 209 | |
| 210 | } else { |
| 211 | |
| 212 | ws_enc = (tbf->m_window.ws() - 64) / 32; |
| 213 | |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 214 | bitvec_write_field(dest, &wp, 1, 1); /* single block alloc */ |
| 215 | bitvec_write_field(dest, &wp, tbf->tfi(), 5);/* TFI assignment */ |
| 216 | bitvec_write_field(dest, &wp, 0, 1); /* polling bit */ |
| 217 | bitvec_write_field(dest, &wp, 0, 1); /* constant */ |
| 218 | bitvec_write_field(dest, &wp, usf, 3); /* USF bit */ |
| 219 | bitvec_write_field(dest, &wp, 0, 1); /* USF granularity */ |
| 220 | bitvec_write_field(dest, &wp, 0, 1); /* P0 */ |
bhargava | 465f5bb | 2016-09-02 16:50:43 +0530 | [diff] [blame] | 221 | /* MCS */ |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 222 | bitvec_write_field(dest, &wp, tbf->current_cs().to_num()-1, 4); |
bhargava | 465f5bb | 2016-09-02 16:50:43 +0530 | [diff] [blame] | 223 | /* tlli channel block */ |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 224 | bitvec_write_field(dest, &wp, tbf->tlli(), 1); |
| 225 | bitvec_write_field(dest, &wp, 0, 1); /* BEP period present */ |
| 226 | bitvec_write_field(dest, &wp, 0, 1); /* resegmentation */ |
| 227 | bitvec_write_field(dest, &wp, ws_enc, 5);/* egprs window_size */ |
bhargava | 465f5bb | 2016-09-02 16:50:43 +0530 | [diff] [blame] | 228 | |
| 229 | if (alpha) { |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 230 | bitvec_write_field(dest, &wp, 0x1, 1); /* ALPHA =yes */ |
| 231 | bitvec_write_field(dest, &wp, alpha, 4); /* ALPHA */ |
bhargava | 465f5bb | 2016-09-02 16:50:43 +0530 | [diff] [blame] | 232 | } else { |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 233 | bitvec_write_field(dest, &wp, 0x0, 1); /* ALPHA = no */ |
bhargava | 465f5bb | 2016-09-02 16:50:43 +0530 | [diff] [blame] | 234 | } |
| 235 | |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 236 | bitvec_write_field(dest, &wp, gamma, 5); /* GAMMA power contrl */ |
| 237 | bitvec_write_field(dest, &wp, 0, 1); /* TIMING_ADVANCE_INDEX */ |
| 238 | bitvec_write_field(dest, &wp, 0, 1); /* TBF_STARTING_TIME_FLAG */ |
| 239 | bitvec_write_field(dest, &wp, 0, 1); /* NULL */ |
bhargava | 465f5bb | 2016-09-02 16:50:43 +0530 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | return 0; |
Jacob Erlbeck | be80c36 | 2016-02-01 16:39:52 +0100 | [diff] [blame] | 243 | } |
| 244 | |
Jacob Erlbeck | 18831c3 | 2016-02-01 15:23:35 +0100 | [diff] [blame] | 245 | /* |
aravind sirsikar | c0c3afd | 2016-11-09 16:27:00 +0530 | [diff] [blame] | 246 | * Immediate assignment reject, sent on the CCCH/AGCH |
| 247 | * see GSM 44.018, 9.1.20 + 10.5.2.30 |
| 248 | */ |
| 249 | int Encoding::write_immediate_assignment_reject( |
| 250 | bitvec *dest, uint16_t ra, |
| 251 | uint32_t ref_fn, |
| 252 | enum ph_burst_type burst_type) |
| 253 | { |
| 254 | unsigned wp = 0; |
| 255 | int plen; |
| 256 | int i; |
| 257 | |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 258 | bitvec_write_field(dest, &wp, 0x0, 4); // Skip Indicator |
| 259 | bitvec_write_field(dest, &wp, 0x6, 4); // Protocol Discriminator |
| 260 | bitvec_write_field(dest, &wp, 0x3A, 8); // Immediate Assign Message Type |
aravind sirsikar | c0c3afd | 2016-11-09 16:27:00 +0530 | [diff] [blame] | 261 | |
| 262 | // feature indicator |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 263 | bitvec_write_field(dest, &wp, 0x0, 1); // spare |
| 264 | bitvec_write_field(dest, &wp, 0x0, 1); // spare |
| 265 | bitvec_write_field(dest, &wp, 0x0, 1); // no cs |
| 266 | bitvec_write_field(dest, &wp, 0x1, 1); // implicit detach for PS |
aravind sirsikar | c0c3afd | 2016-11-09 16:27:00 +0530 | [diff] [blame] | 267 | |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 268 | bitvec_write_field(dest, &wp, 0x0, 4); // Page Mode |
aravind sirsikar | c0c3afd | 2016-11-09 16:27:00 +0530 | [diff] [blame] | 269 | /* |
| 270 | * 9.1.20.2 of 44.018 version 11.7.0 Release 11 |
| 271 | * Filling of the message |
| 272 | * If necessary the request reference information element and the |
| 273 | * wait indication information element should be duplicated to |
| 274 | * fill the message. |
| 275 | * TODO: group rejection for multiple MS |
| 276 | */ |
| 277 | for (i = 0; i < 4; i++) { |
| 278 | //10.5.2.30 Request Reference |
| 279 | if (((burst_type == GSM_L1_BURST_TYPE_ACCESS_1) || |
| 280 | (burst_type == GSM_L1_BURST_TYPE_ACCESS_2))) { |
| 281 | //9.1.20.2a of 44.018 version 11.7.0 Release 11 |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 282 | bitvec_write_field(dest, &wp, 0x7f, 8); /* RACH value */ |
aravind sirsikar | c0c3afd | 2016-11-09 16:27:00 +0530 | [diff] [blame] | 283 | } else { |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 284 | bitvec_write_field(dest, &wp, ra, 8); /* RACH value */ |
aravind sirsikar | c0c3afd | 2016-11-09 16:27:00 +0530 | [diff] [blame] | 285 | } |
| 286 | |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 287 | bitvec_write_field(dest, &wp, |
aravind sirsikar | c0c3afd | 2016-11-09 16:27:00 +0530 | [diff] [blame] | 288 | (ref_fn / (26 * 51)) % 32, 5); // T1' |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 289 | bitvec_write_field(dest, &wp, ref_fn % 51, 6); // T3 |
| 290 | bitvec_write_field(dest, &wp, ref_fn % 26, 5); // T2 |
aravind sirsikar | c0c3afd | 2016-11-09 16:27:00 +0530 | [diff] [blame] | 291 | |
| 292 | /* TODO: Make it configurable */ |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 293 | bitvec_write_field(dest, &wp, 20, 8); //Wait Indication 1 |
aravind sirsikar | c0c3afd | 2016-11-09 16:27:00 +0530 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | plen = wp / 8; |
| 297 | |
| 298 | if ((wp % 8)) { |
| 299 | LOGP(DRLCMACUL, LOGL_ERROR, "Length of IMM.ASS.Rej without" |
| 300 | "rest octets is not multiple of 8 bits, PLEASE FIX!\n"); |
| 301 | return -1; |
| 302 | } |
| 303 | |
| 304 | // Extended RA |
| 305 | else if (((burst_type == GSM_L1_BURST_TYPE_ACCESS_1) || |
| 306 | (burst_type == GSM_L1_BURST_TYPE_ACCESS_2))) { |
| 307 | //9.1.20.2a of 44.018 version 11.7.0 Release 11 |
| 308 | uint8_t extended_ra = 0; |
| 309 | |
| 310 | extended_ra = (ra & 0x1F); |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 311 | bitvec_write_field(dest, &wp, 0x1, 1); |
| 312 | bitvec_write_field(dest, &wp, extended_ra, 5); /* Extended RA */ |
aravind sirsikar | c0c3afd | 2016-11-09 16:27:00 +0530 | [diff] [blame] | 313 | } else { |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 314 | bitvec_write_field(dest, &wp, 0x0, 1); |
aravind sirsikar | c0c3afd | 2016-11-09 16:27:00 +0530 | [diff] [blame] | 315 | } |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 316 | bitvec_write_field(dest, &wp, 0x0, 1); |
| 317 | bitvec_write_field(dest, &wp, 0x0, 1); |
| 318 | bitvec_write_field(dest, &wp, 0x0, 1); |
aravind sirsikar | c0c3afd | 2016-11-09 16:27:00 +0530 | [diff] [blame] | 319 | |
| 320 | return plen; |
| 321 | } |
| 322 | |
Max | 0a8fae8 | 2017-03-08 18:53:30 +0100 | [diff] [blame] | 323 | static inline void log_alert_exit(const char * error) |
| 324 | { |
| 325 | LOGP(DRLCMACUL, LOGL_ERROR, error); |
| 326 | pcu_tx_txt_ind(PCU_OML_ALERT, error); |
| 327 | exit(1); |
| 328 | } |
| 329 | |
aravind sirsikar | c0c3afd | 2016-11-09 16:27:00 +0530 | [diff] [blame] | 330 | /* |
Jacob Erlbeck | 18831c3 | 2016-02-01 15:23:35 +0100 | [diff] [blame] | 331 | * Immediate assignment, sent on the CCCH/AGCH |
| 332 | * see GSM 04.08, 9.1.18 and GSM 44.018, 9.1.18 + 10.5.2.16 |
| 333 | */ |
Holger Hans Peter Freyther | 63f29d6 | 2013-10-19 19:04:03 +0200 | [diff] [blame] | 334 | int Encoding::write_immediate_assignment( |
Jacob Erlbeck | 2647a33 | 2016-02-01 16:13:38 +0100 | [diff] [blame] | 335 | struct gprs_rlcmac_tbf *tbf, |
bhargava | 465f5bb | 2016-09-02 16:50:43 +0530 | [diff] [blame] | 336 | bitvec * dest, uint8_t downlink, uint16_t ra, |
Holger Hans Peter Freyther | 6ca0a90 | 2013-10-19 18:50:22 +0200 | [diff] [blame] | 337 | uint32_t ref_fn, uint8_t ta, uint16_t arfcn, uint8_t ts, uint8_t tsc, |
Jacob Erlbeck | 2647a33 | 2016-02-01 16:13:38 +0100 | [diff] [blame] | 338 | uint8_t usf, uint8_t polling, uint32_t fn, uint8_t alpha, |
bhargava | 465f5bb | 2016-09-02 16:50:43 +0530 | [diff] [blame] | 339 | uint8_t gamma, int8_t ta_idx, enum ph_burst_type burst_type, uint8_t sb) |
Holger Hans Peter Freyther | 6ca0a90 | 2013-10-19 18:50:22 +0200 | [diff] [blame] | 340 | { |
| 341 | unsigned wp = 0; |
Jacob Erlbeck | 2647a33 | 2016-02-01 16:13:38 +0100 | [diff] [blame] | 342 | int plen; |
| 343 | int rc; |
Holger Hans Peter Freyther | 6ca0a90 | 2013-10-19 18:50:22 +0200 | [diff] [blame] | 344 | |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 345 | bitvec_write_field(dest, &wp,0x0,4); // Skip Indicator |
| 346 | bitvec_write_field(dest, &wp,0x6,4); // Protocol Discriminator |
| 347 | bitvec_write_field(dest, &wp,0x3F,8); // Immediate Assignment Message Type |
Holger Hans Peter Freyther | 6ca0a90 | 2013-10-19 18:50:22 +0200 | [diff] [blame] | 348 | |
| 349 | // 10.5.2.25b Dedicated mode or TBF |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 350 | bitvec_write_field(dest, &wp,0x0,1); // spare |
| 351 | bitvec_write_field(dest, &wp,0x0,1); // TMA : Two-message assignment: No meaning |
| 352 | bitvec_write_field(dest, &wp,downlink,1); // Downlink : Downlink assignment to mobile in packet idle mode |
| 353 | bitvec_write_field(dest, &wp,0x1,1); // T/D : TBF or dedicated mode: this message assigns a Temporary Block Flow (TBF). |
Holger Hans Peter Freyther | 6ca0a90 | 2013-10-19 18:50:22 +0200 | [diff] [blame] | 354 | |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 355 | bitvec_write_field(dest, &wp,0x0,4); // Page Mode |
Holger Hans Peter Freyther | 6ca0a90 | 2013-10-19 18:50:22 +0200 | [diff] [blame] | 356 | |
| 357 | // GSM 04.08 10.5.2.25a Packet Channel Description |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 358 | bitvec_write_field(dest, &wp,0x1,5); // Channel type |
| 359 | bitvec_write_field(dest, &wp,ts,3); // TN |
| 360 | bitvec_write_field(dest, &wp,tsc,3); // TSC |
| 361 | bitvec_write_field(dest, &wp,0x0,3); // non-hopping RF channel configuraion |
| 362 | bitvec_write_field(dest, &wp,arfcn,10); // ARFCN |
Holger Hans Peter Freyther | 6ca0a90 | 2013-10-19 18:50:22 +0200 | [diff] [blame] | 363 | |
| 364 | //10.5.2.30 Request Reference |
bhargava | 465f5bb | 2016-09-02 16:50:43 +0530 | [diff] [blame] | 365 | if (((burst_type == GSM_L1_BURST_TYPE_ACCESS_1) || |
| 366 | (burst_type == GSM_L1_BURST_TYPE_ACCESS_2))) { |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 367 | bitvec_write_field(dest, &wp, 0x7f, 8); /* RACH value */ |
bhargava | 465f5bb | 2016-09-02 16:50:43 +0530 | [diff] [blame] | 368 | } else { |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 369 | bitvec_write_field(dest, &wp, ra, 8); /* RACH value */ |
bhargava | 465f5bb | 2016-09-02 16:50:43 +0530 | [diff] [blame] | 370 | } |
| 371 | |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 372 | bitvec_write_field(dest, &wp,(ref_fn / (26 * 51)) % 32,5); // T1' |
| 373 | bitvec_write_field(dest, &wp,ref_fn % 51,6); // T3 |
| 374 | bitvec_write_field(dest, &wp,ref_fn % 26,5); // T2 |
Holger Hans Peter Freyther | 6ca0a90 | 2013-10-19 18:50:22 +0200 | [diff] [blame] | 375 | |
| 376 | // 10.5.2.40 Timing Advance |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 377 | bitvec_write_field(dest, &wp,0x0,2); // spare |
| 378 | bitvec_write_field(dest, &wp,ta,6); // Timing Advance value |
Holger Hans Peter Freyther | 6ca0a90 | 2013-10-19 18:50:22 +0200 | [diff] [blame] | 379 | |
| 380 | // No mobile allocation in non-hopping systems. |
| 381 | // A zero-length LV. Just write L=0. |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 382 | bitvec_write_field(dest, &wp,0,8); |
Holger Hans Peter Freyther | 6ca0a90 | 2013-10-19 18:50:22 +0200 | [diff] [blame] | 383 | |
Max | 0a8fae8 | 2017-03-08 18:53:30 +0100 | [diff] [blame] | 384 | if ((wp % 8)) |
| 385 | log_alert_exit("Length of IMM.ASS without rest octets is not " |
| 386 | "multiple of 8 bits, PLEASE FIX!\n"); |
| 387 | |
Holger Hans Peter Freyther | 6ca0a90 | 2013-10-19 18:50:22 +0200 | [diff] [blame] | 388 | plen = wp / 8; |
| 389 | |
| 390 | if (downlink) |
Jacob Erlbeck | 2647a33 | 2016-02-01 16:13:38 +0100 | [diff] [blame] | 391 | rc = write_ia_rest_downlink(as_dl_tbf(tbf), dest, wp, |
Max | d572054 | 2016-07-14 15:41:17 +0200 | [diff] [blame] | 392 | polling, gsm48_ta_is_valid(ta), fn, |
Jacob Erlbeck | 18831c3 | 2016-02-01 15:23:35 +0100 | [diff] [blame] | 393 | alpha, gamma, ta_idx); |
bhargava | 465f5bb | 2016-09-02 16:50:43 +0530 | [diff] [blame] | 394 | else if (((burst_type == GSM_L1_BURST_TYPE_ACCESS_1) || |
| 395 | (burst_type == GSM_L1_BURST_TYPE_ACCESS_2))) |
Jacob Erlbeck | be80c36 | 2016-02-01 16:39:52 +0100 | [diff] [blame] | 396 | rc = write_ia_rest_egprs_uplink(as_ul_tbf(tbf), dest, wp, |
| 397 | usf, fn, |
bhargava | 465f5bb | 2016-09-02 16:50:43 +0530 | [diff] [blame] | 398 | alpha, gamma, ta_idx, burst_type, ra); |
Holger Hans Peter Freyther | 6ca0a90 | 2013-10-19 18:50:22 +0200 | [diff] [blame] | 399 | else |
Jacob Erlbeck | 2647a33 | 2016-02-01 16:13:38 +0100 | [diff] [blame] | 400 | rc = write_ia_rest_uplink(as_ul_tbf(tbf), dest, wp, |
| 401 | usf, fn, |
Jacob Erlbeck | 18831c3 | 2016-02-01 15:23:35 +0100 | [diff] [blame] | 402 | alpha, gamma, ta_idx); |
Holger Hans Peter Freyther | 6ca0a90 | 2013-10-19 18:50:22 +0200 | [diff] [blame] | 403 | |
Jacob Erlbeck | 2647a33 | 2016-02-01 16:13:38 +0100 | [diff] [blame] | 404 | if (rc < 0) { |
| 405 | LOGP(DRLCMAC, LOGL_ERROR, |
| 406 | "Failed to create IMMEDIATE ASSIGMENT (%s) for %s\n", |
| 407 | downlink ? "downlink" : "uplink", |
| 408 | tbf ? tbf->name() : "single block allocation"); |
| 409 | return rc; |
| 410 | } |
| 411 | |
Holger Hans Peter Freyther | 6ca0a90 | 2013-10-19 18:50:22 +0200 | [diff] [blame] | 412 | return plen; |
| 413 | } |
| 414 | |
| 415 | /* generate uplink assignment */ |
Holger Hans Peter Freyther | 63f29d6 | 2013-10-19 19:04:03 +0200 | [diff] [blame] | 416 | void Encoding::write_packet_uplink_assignment( |
Holger Hans Peter Freyther | 6ca0a90 | 2013-10-19 18:50:22 +0200 | [diff] [blame] | 417 | struct gprs_rlcmac_bts *bts, |
| 418 | bitvec * dest, uint8_t old_tfi, |
| 419 | uint8_t old_downlink, uint32_t tlli, uint8_t use_tlli, |
Jacob Erlbeck | f2694b7 | 2016-01-26 21:46:26 +0100 | [diff] [blame] | 420 | struct gprs_rlcmac_ul_tbf *tbf, uint8_t poll, uint8_t rrbp, uint8_t alpha, |
Jacob Erlbeck | 76d767c | 2015-09-28 18:54:32 +0200 | [diff] [blame] | 421 | uint8_t gamma, int8_t ta_idx, int8_t use_egprs) |
Holger Hans Peter Freyther | 6ca0a90 | 2013-10-19 18:50:22 +0200 | [diff] [blame] | 422 | { |
| 423 | // TODO We should use our implementation of encode RLC/MAC Control messages. |
| 424 | unsigned wp = 0; |
| 425 | uint8_t ts; |
Max | ae48381 | 2016-07-28 12:03:08 +0200 | [diff] [blame] | 426 | /* timeslot assigned for the Continuous Timing Advance procedure */ |
| 427 | uint8_t ta_ts = 0; /* FIXME: supply it as parameter from caller */ |
Holger Hans Peter Freyther | 6ca0a90 | 2013-10-19 18:50:22 +0200 | [diff] [blame] | 428 | |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 429 | bitvec_write_field(dest, &wp,0x1,2); // Payload Type |
| 430 | bitvec_write_field(dest, &wp,0x0,2); // Uplink block with TDMA framenumber (N+13) |
| 431 | bitvec_write_field(dest, &wp,poll,1); // Suppl/Polling Bit |
| 432 | bitvec_write_field(dest, &wp,0x0,3); // Uplink state flag |
| 433 | bitvec_write_field(dest, &wp,0xa,6); // MESSAGE TYPE |
Holger Hans Peter Freyther | 6ca0a90 | 2013-10-19 18:50:22 +0200 | [diff] [blame] | 434 | |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 435 | bitvec_write_field(dest, &wp,0x0,2); // Page Mode |
Holger Hans Peter Freyther | 6ca0a90 | 2013-10-19 18:50:22 +0200 | [diff] [blame] | 436 | |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 437 | bitvec_write_field(dest, &wp,0x0,1); // switch PERSIST_LEVEL: off |
Holger Hans Peter Freyther | 6ca0a90 | 2013-10-19 18:50:22 +0200 | [diff] [blame] | 438 | if (use_tlli) { |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 439 | bitvec_write_field(dest, &wp,0x2,2); // switch TLLI : on |
| 440 | bitvec_write_field(dest, &wp,tlli,32); // TLLI |
Holger Hans Peter Freyther | 6ca0a90 | 2013-10-19 18:50:22 +0200 | [diff] [blame] | 441 | } else { |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 442 | bitvec_write_field(dest, &wp,0x0,1); // switch TFI : on |
| 443 | bitvec_write_field(dest, &wp,old_downlink,1); // 0=UPLINK TFI, 1=DL TFI |
| 444 | bitvec_write_field(dest, &wp,old_tfi,5); // TFI |
Holger Hans Peter Freyther | 6ca0a90 | 2013-10-19 18:50:22 +0200 | [diff] [blame] | 445 | } |
| 446 | |
Jacob Erlbeck | 76d767c | 2015-09-28 18:54:32 +0200 | [diff] [blame] | 447 | if (!use_egprs) { |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 448 | bitvec_write_field(dest, &wp,0x0,1); // Message escape |
| 449 | bitvec_write_field(dest, &wp,tbf->current_cs().to_num()-1, 2); // CHANNEL_CODING_COMMAND |
| 450 | bitvec_write_field(dest, &wp,0x1,1); // TLLI_BLOCK_CHANNEL_CODING |
Max | ae48381 | 2016-07-28 12:03:08 +0200 | [diff] [blame] | 451 | write_ta_ie(dest, wp,tbf->ta(), ta_idx, ta_ts); |
Jacob Erlbeck | 76d767c | 2015-09-28 18:54:32 +0200 | [diff] [blame] | 452 | } else { /* EPGRS */ |
Jacob Erlbeck | 36df774 | 2016-01-19 15:53:30 +0100 | [diff] [blame] | 453 | unsigned int ws_enc = (tbf->m_window.ws() - 64) / 32; |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 454 | bitvec_write_field(dest, &wp,0x1,1); // Message escape |
| 455 | bitvec_write_field(dest, &wp,0x0,2); // EGPRS message contents |
| 456 | bitvec_write_field(dest, &wp,0x0,1); // No CONTENTION_RESOLUTION_TLLI |
| 457 | bitvec_write_field(dest, &wp,0x0,1); // No COMPACT reduced MA |
| 458 | bitvec_write_field(dest, &wp,tbf->current_cs().to_num()-1, 4); // EGPRS Modulation and Coding IE |
Aravind Sirsikar | 505a86d | 2016-07-26 18:26:21 +0530 | [diff] [blame] | 459 | /* 0: no RESEGMENT, 1: Segmentation*/ |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 460 | bitvec_write_field(dest, &wp, 0x1, 1); |
| 461 | bitvec_write_field(dest, &wp,ws_enc,5); // EGPRS Window Size |
| 462 | bitvec_write_field(dest, &wp,0x0,1); // No Access Technologies Request |
| 463 | bitvec_write_field(dest, &wp,0x0,1); // No ARAC RETRANSMISSION REQUEST |
| 464 | bitvec_write_field(dest, &wp,0x1,1); // TLLI_BLOCK_CHANNEL_CODING |
| 465 | bitvec_write_field(dest, &wp,0x0,1); // No BEP_PERIOD2 |
Max | ae48381 | 2016-07-28 12:03:08 +0200 | [diff] [blame] | 466 | write_ta_ie(dest, wp,tbf->ta(), ta_idx, ta_ts); |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 467 | bitvec_write_field(dest, &wp,0x0,1); // No Packet Extended Timing Advance |
Holger Hans Peter Freyther | 6ca0a90 | 2013-10-19 18:50:22 +0200 | [diff] [blame] | 468 | } |
| 469 | |
| 470 | #if 1 |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 471 | bitvec_write_field(dest, &wp,0x1,1); // Frequency Parameters information elements = present |
| 472 | bitvec_write_field(dest, &wp,tbf->tsc(),3); // Training Sequence Code (TSC) |
| 473 | bitvec_write_field(dest, &wp,0x0,2); // ARFCN = present |
| 474 | bitvec_write_field(dest, &wp,tbf->trx->arfcn,10); // ARFCN |
Holger Hans Peter Freyther | 6ca0a90 | 2013-10-19 18:50:22 +0200 | [diff] [blame] | 475 | #else |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 476 | bitvec_write_field(dest, &wp,0x0,1); // Frequency Parameters = off |
Holger Hans Peter Freyther | 6ca0a90 | 2013-10-19 18:50:22 +0200 | [diff] [blame] | 477 | #endif |
| 478 | |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 479 | bitvec_write_field(dest, &wp,0x1,2); // Dynamic Allocation |
Jacob Erlbeck | edfd7e3 | 2015-11-17 16:30:58 +0100 | [diff] [blame] | 480 | |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 481 | bitvec_write_field(dest, &wp,0x0,1); // Extended Dynamic Allocation = off |
| 482 | bitvec_write_field(dest, &wp,0x0,1); // P0 = off |
Jacob Erlbeck | edfd7e3 | 2015-11-17 16:30:58 +0100 | [diff] [blame] | 483 | |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 484 | bitvec_write_field(dest, &wp,0x0,1); // USF_GRANULARITY |
| 485 | bitvec_write_field(dest, &wp,0x1,1); // switch TFI : on |
| 486 | bitvec_write_field(dest, &wp,tbf->tfi(),5);// TFI |
Holger Hans Peter Freyther | 6ca0a90 | 2013-10-19 18:50:22 +0200 | [diff] [blame] | 487 | |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 488 | bitvec_write_field(dest, &wp,0x0,1); // |
| 489 | bitvec_write_field(dest, &wp,0x0,1); // TBF Starting Time = off |
Holger Hans Peter Freyther | 6ca0a90 | 2013-10-19 18:50:22 +0200 | [diff] [blame] | 490 | if (alpha || gamma) { |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 491 | bitvec_write_field(dest, &wp,0x1,1); // Timeslot Allocation with Power Control |
| 492 | bitvec_write_field(dest, &wp,alpha,4); // ALPHA |
Holger Hans Peter Freyther | 6ca0a90 | 2013-10-19 18:50:22 +0200 | [diff] [blame] | 493 | } else |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 494 | bitvec_write_field(dest, &wp,0x0,1); // Timeslot Allocation |
Jacob Erlbeck | edfd7e3 | 2015-11-17 16:30:58 +0100 | [diff] [blame] | 495 | |
Holger Hans Peter Freyther | 6ca0a90 | 2013-10-19 18:50:22 +0200 | [diff] [blame] | 496 | for (ts = 0; ts < 8; ts++) { |
| 497 | if (tbf->pdch[ts]) { |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 498 | bitvec_write_field(dest, &wp,0x1,1); // USF_TN(i): on |
| 499 | bitvec_write_field(dest, &wp,tbf->m_usf[ts],3); // USF_TN(i) |
Holger Hans Peter Freyther | 6ca0a90 | 2013-10-19 18:50:22 +0200 | [diff] [blame] | 500 | if (alpha || gamma) |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 501 | bitvec_write_field(dest, &wp,gamma,5); // GAMMA power control parameter |
Holger Hans Peter Freyther | 6ca0a90 | 2013-10-19 18:50:22 +0200 | [diff] [blame] | 502 | } else |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 503 | bitvec_write_field(dest, &wp,0x0,1); // USF_TN(i): off |
Holger Hans Peter Freyther | 6ca0a90 | 2013-10-19 18:50:22 +0200 | [diff] [blame] | 504 | } |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 505 | // bitvec_write_field(dest, &wp,0x0,1); // Measurement Mapping struct not present |
Holger Hans Peter Freyther | 6ca0a90 | 2013-10-19 18:50:22 +0200 | [diff] [blame] | 506 | } |
| 507 | |
| 508 | |
| 509 | /* generate downlink assignment */ |
Jacob Erlbeck | 166c9fc | 2016-01-07 16:04:29 +0100 | [diff] [blame] | 510 | void Encoding::write_packet_downlink_assignment(RlcMacDownlink_t * block, |
Jacob Erlbeck | 6b356a5 | 2016-01-29 16:39:21 +0100 | [diff] [blame] | 511 | bool old_tfi_is_valid, uint8_t old_tfi, uint8_t old_downlink, |
| 512 | struct gprs_rlcmac_tbf *tbf, uint8_t poll, uint8_t rrbp, |
| 513 | uint8_t alpha, uint8_t gamma, int8_t ta_idx, |
Jacob Erlbeck | f2694b7 | 2016-01-26 21:46:26 +0100 | [diff] [blame] | 514 | uint8_t ta_ts, bool use_egprs) |
Holger Hans Peter Freyther | 6ca0a90 | 2013-10-19 18:50:22 +0200 | [diff] [blame] | 515 | { |
| 516 | // Packet downlink assignment TS 44.060 11.2.7 |
| 517 | |
Jacob Erlbeck | 166c9fc | 2016-01-07 16:04:29 +0100 | [diff] [blame] | 518 | PDA_AdditionsR99_t *pda_r99; |
| 519 | |
Holger Hans Peter Freyther | 6ca0a90 | 2013-10-19 18:50:22 +0200 | [diff] [blame] | 520 | uint8_t tn; |
Jacob Erlbeck | 36df774 | 2016-01-19 15:53:30 +0100 | [diff] [blame] | 521 | unsigned int ws_enc; |
Holger Hans Peter Freyther | 6ca0a90 | 2013-10-19 18:50:22 +0200 | [diff] [blame] | 522 | |
| 523 | block->PAYLOAD_TYPE = 0x1; // RLC/MAC control block that does not include the optional octets of the RLC/MAC control header |
Jacob Erlbeck | f2694b7 | 2016-01-26 21:46:26 +0100 | [diff] [blame] | 524 | block->RRBP = rrbp; // 0: N+13 |
Holger Hans Peter Freyther | 6ca0a90 | 2013-10-19 18:50:22 +0200 | [diff] [blame] | 525 | block->SP = poll; // RRBP field is valid |
| 526 | block->USF = 0x0; // Uplink state flag |
| 527 | |
| 528 | block->u.Packet_Downlink_Assignment.MESSAGE_TYPE = 0x2; // Packet Downlink Assignment |
| 529 | block->u.Packet_Downlink_Assignment.PAGE_MODE = 0x0; // Normal Paging |
| 530 | |
| 531 | block->u.Packet_Downlink_Assignment.Exist_PERSISTENCE_LEVEL = 0x0; // PERSISTENCE_LEVEL: off |
| 532 | |
Jacob Erlbeck | 6b356a5 | 2016-01-29 16:39:21 +0100 | [diff] [blame] | 533 | if (old_tfi_is_valid) { |
| 534 | block->u.Packet_Downlink_Assignment.ID.UnionType = 0x0; // TFI = on |
| 535 | block->u.Packet_Downlink_Assignment.ID.u.Global_TFI.UnionType = old_downlink; // 0=UPLINK TFI, 1=DL TFI |
| 536 | block->u.Packet_Downlink_Assignment.ID.u.Global_TFI.u.UPLINK_TFI = old_tfi; // TFI |
| 537 | } else { |
| 538 | block->u.Packet_Downlink_Assignment.ID.UnionType = 0x1; // TLLI |
| 539 | block->u.Packet_Downlink_Assignment.ID.u.TLLI = tbf->tlli(); |
| 540 | } |
Holger Hans Peter Freyther | 6ca0a90 | 2013-10-19 18:50:22 +0200 | [diff] [blame] | 541 | |
| 542 | block->u.Packet_Downlink_Assignment.MAC_MODE = 0x0; // Dynamic Allocation |
| 543 | block->u.Packet_Downlink_Assignment.RLC_MODE = 0x0; // RLC acknowledged mode |
Daniel Willmann | 73191a4 | 2014-05-30 17:58:00 +0200 | [diff] [blame] | 544 | block->u.Packet_Downlink_Assignment.CONTROL_ACK = tbf->was_releasing; // NW establishes no new DL TBF for the MS with running timer T3192 |
Holger Hans Peter Freyther | 6ca0a90 | 2013-10-19 18:50:22 +0200 | [diff] [blame] | 545 | block->u.Packet_Downlink_Assignment.TIMESLOT_ALLOCATION = 0; // timeslot(s) |
| 546 | for (tn = 0; tn < 8; tn++) { |
| 547 | if (tbf->pdch[tn]) |
| 548 | block->u.Packet_Downlink_Assignment.TIMESLOT_ALLOCATION |= 0x80 >> tn; // timeslot(s) |
| 549 | } |
| 550 | |
| 551 | block->u.Packet_Downlink_Assignment.Packet_Timing_Advance.Exist_TIMING_ADVANCE_VALUE = 0x1; // TIMING_ADVANCE_VALUE = on |
Jacob Erlbeck | 9200ce6 | 2015-05-22 17:48:04 +0200 | [diff] [blame] | 552 | block->u.Packet_Downlink_Assignment.Packet_Timing_Advance.TIMING_ADVANCE_VALUE = tbf->ta(); // TIMING_ADVANCE_VALUE |
Holger Hans Peter Freyther | 6ca0a90 | 2013-10-19 18:50:22 +0200 | [diff] [blame] | 553 | if (ta_idx < 0) { |
| 554 | block->u.Packet_Downlink_Assignment.Packet_Timing_Advance.Exist_IndexAndtimeSlot = 0x0; // TIMING_ADVANCE_INDEX = off |
| 555 | } else { |
| 556 | block->u.Packet_Downlink_Assignment.Packet_Timing_Advance.Exist_IndexAndtimeSlot = 0x1; // TIMING_ADVANCE_INDEX = on |
| 557 | block->u.Packet_Downlink_Assignment.Packet_Timing_Advance.TIMING_ADVANCE_INDEX = ta_idx; // TIMING_ADVANCE_INDEX |
| 558 | block->u.Packet_Downlink_Assignment.Packet_Timing_Advance.TIMING_ADVANCE_TIMESLOT_NUMBER = ta_ts; // TIMING_ADVANCE_TS |
| 559 | } |
| 560 | |
| 561 | block->u.Packet_Downlink_Assignment.Exist_P0_and_BTS_PWR_CTRL_MODE = 0x0; // POWER CONTROL = off |
| 562 | |
| 563 | block->u.Packet_Downlink_Assignment.Exist_Frequency_Parameters = 0x1; // Frequency Parameters = on |
Holger Hans Peter Freyther | 8f399de | 2013-12-25 20:22:35 +0100 | [diff] [blame] | 564 | block->u.Packet_Downlink_Assignment.Frequency_Parameters.TSC = tbf->tsc(); // Training Sequence Code (TSC) |
Holger Hans Peter Freyther | 6ca0a90 | 2013-10-19 18:50:22 +0200 | [diff] [blame] | 565 | block->u.Packet_Downlink_Assignment.Frequency_Parameters.UnionType = 0x0; // ARFCN = on |
Holger Hans Peter Freyther | fc498c9 | 2013-10-27 13:38:54 +0100 | [diff] [blame] | 566 | block->u.Packet_Downlink_Assignment.Frequency_Parameters.u.ARFCN = tbf->trx->arfcn; // ARFCN |
Holger Hans Peter Freyther | 6ca0a90 | 2013-10-19 18:50:22 +0200 | [diff] [blame] | 567 | |
| 568 | block->u.Packet_Downlink_Assignment.Exist_DOWNLINK_TFI_ASSIGNMENT = 0x1; // DOWNLINK TFI ASSIGNMENT = on |
Holger Hans Peter Freyther | 34f6e5e | 2013-10-27 20:31:47 +0100 | [diff] [blame] | 569 | block->u.Packet_Downlink_Assignment.DOWNLINK_TFI_ASSIGNMENT = tbf->tfi(); // TFI |
Holger Hans Peter Freyther | 6ca0a90 | 2013-10-19 18:50:22 +0200 | [diff] [blame] | 570 | |
| 571 | block->u.Packet_Downlink_Assignment.Exist_Power_Control_Parameters = 0x1; // Power Control Parameters = on |
| 572 | block->u.Packet_Downlink_Assignment.Power_Control_Parameters.ALPHA = alpha; // ALPHA |
| 573 | |
| 574 | for (tn = 0; tn < 8; tn++) |
| 575 | { |
| 576 | if (tbf->pdch[tn]) |
| 577 | { |
| 578 | block->u.Packet_Downlink_Assignment.Power_Control_Parameters.Slot[tn].Exist = 0x1; // Slot[i] = on |
| 579 | block->u.Packet_Downlink_Assignment.Power_Control_Parameters.Slot[tn].GAMMA_TN = gamma; // GAMMA_TN |
| 580 | } |
| 581 | else |
| 582 | { |
| 583 | block->u.Packet_Downlink_Assignment.Power_Control_Parameters.Slot[tn].Exist = 0x0; // Slot[i] = off |
| 584 | } |
| 585 | } |
| 586 | |
| 587 | block->u.Packet_Downlink_Assignment.Exist_TBF_Starting_Time = 0x0; // TBF Starting TIME = off |
| 588 | block->u.Packet_Downlink_Assignment.Exist_Measurement_Mapping = 0x0; // Measurement_Mapping = off |
Jacob Erlbeck | 166c9fc | 2016-01-07 16:04:29 +0100 | [diff] [blame] | 589 | if (!use_egprs) { |
| 590 | block->u.Packet_Downlink_Assignment.Exist_AdditionsR99 = 0x0; // AdditionsR99 = off |
| 591 | return; |
| 592 | } |
Jacob Erlbeck | 36df774 | 2016-01-19 15:53:30 +0100 | [diff] [blame] | 593 | |
| 594 | ws_enc = (tbf->window()->ws() - 64) / 32; |
| 595 | |
Jacob Erlbeck | 166c9fc | 2016-01-07 16:04:29 +0100 | [diff] [blame] | 596 | block->u.Packet_Downlink_Assignment.Exist_AdditionsR99 = 0x1; // AdditionsR99 = on |
| 597 | pda_r99 = &block->u.Packet_Downlink_Assignment.AdditionsR99; |
| 598 | pda_r99->Exist_EGPRS_Params = 1; |
Jacob Erlbeck | 36df774 | 2016-01-19 15:53:30 +0100 | [diff] [blame] | 599 | pda_r99->EGPRS_WindowSize = ws_enc; /* see TS 44.060, table 12.5.2.1 */ |
Jacob Erlbeck | 166c9fc | 2016-01-07 16:04:29 +0100 | [diff] [blame] | 600 | pda_r99->LINK_QUALITY_MEASUREMENT_MODE = 0x0; /* no meas, see TS 44.060, table 11.2.7.2 */ |
| 601 | pda_r99->Exist_BEP_PERIOD2 = 0; /* No extra EGPRS BEP PERIOD */ |
| 602 | pda_r99->Exist_Packet_Extended_Timing_Advance = 0; |
| 603 | pda_r99->Exist_COMPACT_ReducedMA = 0; |
Holger Hans Peter Freyther | 6ca0a90 | 2013-10-19 18:50:22 +0200 | [diff] [blame] | 604 | } |
| 605 | |
| 606 | /* generate paging request */ |
Holger Hans Peter Freyther | 63f29d6 | 2013-10-19 19:04:03 +0200 | [diff] [blame] | 607 | int Encoding::write_paging_request(bitvec * dest, uint8_t *ptmsi, uint16_t ptmsi_len) |
Holger Hans Peter Freyther | 6ca0a90 | 2013-10-19 18:50:22 +0200 | [diff] [blame] | 608 | { |
| 609 | unsigned wp = 0; |
| 610 | int plen; |
| 611 | |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 612 | bitvec_write_field(dest, &wp,0x0,4); // Skip Indicator |
| 613 | bitvec_write_field(dest, &wp,0x6,4); // Protocol Discriminator |
| 614 | bitvec_write_field(dest, &wp,0x21,8); // Paging Request Message Type |
Holger Hans Peter Freyther | 6ca0a90 | 2013-10-19 18:50:22 +0200 | [diff] [blame] | 615 | |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 616 | bitvec_write_field(dest, &wp,0x0,4); // Page Mode |
| 617 | bitvec_write_field(dest, &wp,0x0,4); // Channel Needed |
Holger Hans Peter Freyther | 6ca0a90 | 2013-10-19 18:50:22 +0200 | [diff] [blame] | 618 | |
| 619 | // Mobile Identity |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 620 | bitvec_write_field(dest, &wp,ptmsi_len+1,8); // Mobile Identity length |
| 621 | bitvec_write_field(dest, &wp,0xf,4); // unused |
| 622 | bitvec_write_field(dest, &wp,0x4,4); // PTMSI type |
Holger Hans Peter Freyther | 6ca0a90 | 2013-10-19 18:50:22 +0200 | [diff] [blame] | 623 | for (int i = 0; i < ptmsi_len; i++) |
| 624 | { |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 625 | bitvec_write_field(dest, &wp,ptmsi[i],8); // PTMSI |
Holger Hans Peter Freyther | 6ca0a90 | 2013-10-19 18:50:22 +0200 | [diff] [blame] | 626 | } |
Max | 0a8fae8 | 2017-03-08 18:53:30 +0100 | [diff] [blame] | 627 | |
| 628 | if ((wp % 8)) |
| 629 | log_alert_exit("Length of PAG.REQ without rest octets is not " |
| 630 | "multiple of 8 bits, PLEASE FIX!\n"); |
| 631 | |
Holger Hans Peter Freyther | 6ca0a90 | 2013-10-19 18:50:22 +0200 | [diff] [blame] | 632 | plen = wp / 8; |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 633 | bitvec_write_field(dest, &wp,0x0,1); // "L" NLN(PCH) = off |
| 634 | bitvec_write_field(dest, &wp,0x0,1); // "L" Priority1 = off |
| 635 | bitvec_write_field(dest, &wp,0x1,1); // "L" Priority2 = off |
| 636 | bitvec_write_field(dest, &wp,0x0,1); // "L" Group Call information = off |
| 637 | bitvec_write_field(dest, &wp,0x0,1); // "H" Packet Page Indication 1 = packet paging procedure |
| 638 | bitvec_write_field(dest, &wp,0x1,1); // "H" Packet Page Indication 2 = packet paging procedure |
Holger Hans Peter Freyther | 6ca0a90 | 2013-10-19 18:50:22 +0200 | [diff] [blame] | 639 | |
| 640 | return plen; |
| 641 | } |
| 642 | |
Daniel Willmann | 5241c1a | 2013-12-11 14:35:29 +0100 | [diff] [blame] | 643 | /** |
| 644 | * The index of the array show_rbb is the bit position inside the rbb |
| 645 | * (show_rbb[63] relates to BSN ssn-1) |
| 646 | */ |
| 647 | void Encoding::encode_rbb(const char *show_rbb, uint8_t *rbb) |
| 648 | { |
| 649 | uint8_t rbb_byte = 0; |
| 650 | |
| 651 | // RECEIVE_BLOCK_BITMAP |
| 652 | for (int i = 0; i < 64; i++) { |
| 653 | /* Set bit at the appropriate position (see 3GPP TS 04.60 9.1.8.1) */ |
| 654 | if (show_rbb[i] == 'R') |
| 655 | rbb_byte |= 1<< (7-(i%8)); |
| 656 | |
| 657 | if((i%8) == 7) { |
| 658 | rbb[i/8] = rbb_byte; |
| 659 | rbb_byte = 0; |
| 660 | } |
| 661 | } |
| 662 | } |
| 663 | |
Jacob Erlbeck | 37005a1 | 2015-12-22 14:58:34 +0100 | [diff] [blame] | 664 | static void write_packet_ack_nack_desc_gprs( |
| 665 | struct gprs_rlcmac_bts *bts, bitvec * dest, unsigned& wp, |
| 666 | gprs_rlc_ul_window *window, bool is_final) |
| 667 | { |
| 668 | char rbb[65]; |
| 669 | |
| 670 | window->update_rbb(rbb); |
| 671 | |
| 672 | rbb[64] = 0; |
| 673 | LOGP(DRLCMACUL, LOGL_DEBUG, "- V(N): \"%s\" R=Received " |
| 674 | "I=Invalid\n", rbb); |
| 675 | |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 676 | bitvec_write_field(dest, &wp, is_final, 1); // FINAL_ACK_INDICATION |
| 677 | bitvec_write_field(dest, &wp, window->ssn(), 7); // STARTING_SEQUENCE_NUMBER |
Jacob Erlbeck | 37005a1 | 2015-12-22 14:58:34 +0100 | [diff] [blame] | 678 | |
| 679 | for (int i = 0; i < 64; i++) { |
| 680 | /* Set bit at the appropriate position (see 3GPP TS 04.60 9.1.8.1) */ |
| 681 | bool is_ack = (rbb[i] == 'R'); |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 682 | bitvec_write_field(dest, &wp, is_ack, 1); |
Jacob Erlbeck | 37005a1 | 2015-12-22 14:58:34 +0100 | [diff] [blame] | 683 | } |
| 684 | } |
| 685 | |
| 686 | static void write_packet_uplink_ack_gprs( |
| 687 | struct gprs_rlcmac_bts *bts, bitvec * dest, unsigned& wp, |
| 688 | struct gprs_rlcmac_ul_tbf *tbf, bool is_final) |
| 689 | { |
| 690 | |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 691 | bitvec_write_field(dest, &wp, tbf->current_cs().to_num() - 1, 2); // CHANNEL_CODING_COMMAND |
Jacob Erlbeck | 37005a1 | 2015-12-22 14:58:34 +0100 | [diff] [blame] | 692 | write_packet_ack_nack_desc_gprs(bts, dest, wp, &tbf->m_window, is_final); |
| 693 | |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 694 | bitvec_write_field(dest, &wp, 1, 1); // 1: have CONTENTION_RESOLUTION_TLLI |
| 695 | bitvec_write_field(dest, &wp, tbf->tlli(), 32); // CONTENTION_RESOLUTION_TLLI |
Jacob Erlbeck | 37005a1 | 2015-12-22 14:58:34 +0100 | [diff] [blame] | 696 | |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 697 | bitvec_write_field(dest, &wp, 0, 1); // 0: don't have Packet Timing Advance |
| 698 | bitvec_write_field(dest, &wp, 0, 1); // 0: don't have Power Control Parameters |
| 699 | bitvec_write_field(dest, &wp, 0, 1); // 0: don't have Extension Bits |
| 700 | bitvec_write_field(dest, &wp, 0, 1); // fixed 0 |
| 701 | bitvec_write_field(dest, &wp, 1, 1); // 1: have Additions R99 |
| 702 | bitvec_write_field(dest, &wp, 0, 1); // 0: don't have Packet Extended Timing Advance |
| 703 | bitvec_write_field(dest, &wp, 1, 1); // TBF_EST (enabled) |
| 704 | bitvec_write_field(dest, &wp, 0, 1); // 0: don't have REL 5 |
Jacob Erlbeck | 37005a1 | 2015-12-22 14:58:34 +0100 | [diff] [blame] | 705 | }; |
| 706 | |
| 707 | static void write_packet_ack_nack_desc_egprs( |
| 708 | struct gprs_rlcmac_bts *bts, bitvec * dest, unsigned& wp, |
sivasankari | 8adfcd0 | 2017-01-16 15:41:21 +0530 | [diff] [blame] | 709 | gprs_rlc_ul_window *window, bool is_final, unsigned& rest_bits) |
Jacob Erlbeck | 37005a1 | 2015-12-22 14:58:34 +0100 | [diff] [blame] | 710 | { |
sivasankari | 8adfcd0 | 2017-01-16 15:41:21 +0530 | [diff] [blame] | 711 | unsigned int urbb_len = 0; |
| 712 | uint8_t crbb_len = 0; |
| 713 | uint8_t len; |
Jacob Erlbeck | 37005a1 | 2015-12-22 14:58:34 +0100 | [diff] [blame] | 714 | bool bow = true; |
| 715 | bool eow = true; |
| 716 | int ssn = window->mod_sns(window->v_q() + 1); |
sivasankari | 8adfcd0 | 2017-01-16 15:41:21 +0530 | [diff] [blame] | 717 | unsigned int num_blocks = window->mod_sns(window->v_r() - window->v_q()); |
Jacob Erlbeck | 37005a1 | 2015-12-22 14:58:34 +0100 | [diff] [blame] | 718 | int esn_crbb = window->mod_sns(ssn - 1); |
sivasankari | 8adfcd0 | 2017-01-16 15:41:21 +0530 | [diff] [blame] | 719 | static uint8_t rbb[RLC_EGPRS_MAX_WS] = {'\0'}; |
| 720 | uint8_t iter = 0; |
Pravin Kumarvel | 06bdb35 | 2016-10-24 12:21:21 +0530 | [diff] [blame] | 721 | int is_compressed = 0; |
sivasankari | 8adfcd0 | 2017-01-16 15:41:21 +0530 | [diff] [blame] | 722 | bool try_compression = false; |
| 723 | uint8_t ucmp_bmplen; |
| 724 | uint8_t crbb_bitmap[23] = {'\0'}; |
| 725 | bitvec ucmp_vec; |
| 726 | bitvec crbb_vec; |
| 727 | uint8_t uclen_crbb = 0; |
Pravin Kumarvel | 06bdb35 | 2016-10-24 12:21:21 +0530 | [diff] [blame] | 728 | bool len_coded = true; |
sivasankari | 8adfcd0 | 2017-01-16 15:41:21 +0530 | [diff] [blame] | 729 | uint8_t crbb_start_clr_code; |
Pravin Kumarvel | 06bdb35 | 2016-10-24 12:21:21 +0530 | [diff] [blame] | 730 | uint8_t i; |
sivasankari | 8adfcd0 | 2017-01-16 15:41:21 +0530 | [diff] [blame] | 731 | #if 0 |
| 732 | /* static size of 16 bits*/ |
| 733 | ..0. .... = ACKNACK: (Union) |
| 734 | Desc |
| 735 | |
| 736 | ...0 .... = FINAL_ACK_INDICATION: False |
| 737 | |
| 738 | .... 1... = BEGINNING_OF_WINDOW: 1 |
| 739 | |
| 740 | .... .1.. = END_OF_WINDOW: 1 |
| 741 | |
| 742 | .... ..10 0101 0001 1... .... = STARTING_SEQUENCE_NUMBER: 1187 |
| 743 | |
| 744 | .0.. .... = CRBB Exist: 0 |
| 745 | #endif |
| 746 | rest_bits -= 16; |
Jacob Erlbeck | 37005a1 | 2015-12-22 14:58:34 +0100 | [diff] [blame] | 747 | |
| 748 | if (num_blocks > 0) |
| 749 | /* V(Q) is NACK and omitted -> SSN = V(Q) + 1 */ |
| 750 | num_blocks -= 1; |
| 751 | |
| 752 | if (num_blocks > window->ws()) |
| 753 | num_blocks = window->ws(); |
sivasankari | 8adfcd0 | 2017-01-16 15:41:21 +0530 | [diff] [blame] | 754 | /* Try Compression as number of blocks does not fit */ |
| 755 | if (num_blocks > rest_bits) { |
| 756 | try_compression = true; |
| 757 | } |
| 758 | if (try_compression == true) { |
| 759 | ucmp_bmplen = window->update_egprs_rbb(rbb); |
| 760 | ucmp_vec.data = rbb; |
| 761 | ucmp_vec.cur_bit = ucmp_bmplen; |
| 762 | ucmp_vec.data_len = 127; |
| 763 | crbb_vec.data = crbb_bitmap; |
| 764 | crbb_vec.cur_bit = 0; |
| 765 | crbb_vec.data_len = 127; |
| 766 | LOGP(DRLCMACUL, LOGL_DEBUG, |
| 767 | "rest_bits=%d uncompressed len %d and uncompressed bitmap = %s\n", |
| 768 | rest_bits, ucmp_bmplen, |
| 769 | osmo_hexdump(ucmp_vec.data, (ucmp_bmplen+7)/8)); |
Jacob Erlbeck | 37005a1 | 2015-12-22 14:58:34 +0100 | [diff] [blame] | 770 | |
sivasankari | 8adfcd0 | 2017-01-16 15:41:21 +0530 | [diff] [blame] | 771 | is_compressed = egprs_compress::compress_rbb(&ucmp_vec, /* Uncompressed bitmap*/ |
| 772 | &crbb_vec, /*Compressed bitmap vector */ |
| 773 | &uclen_crbb, |
| 774 | (rest_bits - 16));/* CRBBlength:7 colourcode:1 dissector length:8*/ |
| 775 | LOGP(DRLCMACUL, LOGL_DEBUG, |
| 776 | "the ucmp len=%d uclen_crbb=%d num_blocks=%d crbb length %d, " |
| 777 | "and the CRBB bitmap = %s\n", |
| 778 | ucmp_bmplen, uclen_crbb, num_blocks, crbb_vec.cur_bit, |
| 779 | osmo_hexdump(crbb_bitmap, (crbb_vec.cur_bit+7)/8)); |
| 780 | crbb_len = crbb_vec.cur_bit; |
| 781 | } |
| 782 | |
| 783 | if (is_compressed == 0) { |
| 784 | /* length field takes 8 bits*/ |
| 785 | if (num_blocks > rest_bits - 8) { |
Pravin Kumarvel | 06bdb35 | 2016-10-24 12:21:21 +0530 | [diff] [blame] | 786 | eow = false; |
sivasankari | 8adfcd0 | 2017-01-16 15:41:21 +0530 | [diff] [blame] | 787 | urbb_len = rest_bits; |
Pravin Kumarvel | 06bdb35 | 2016-10-24 12:21:21 +0530 | [diff] [blame] | 788 | len_coded = false; |
sivasankari | 8adfcd0 | 2017-01-16 15:41:21 +0530 | [diff] [blame] | 789 | } else if (num_blocks == rest_bits) { |
| 790 | urbb_len = rest_bits; |
Pravin Kumarvel | 06bdb35 | 2016-10-24 12:21:21 +0530 | [diff] [blame] | 791 | len_coded = false; |
Pravin Kumarvel | 06bdb35 | 2016-10-24 12:21:21 +0530 | [diff] [blame] | 792 | } else |
| 793 | urbb_len = num_blocks; |
sivasankari | 8adfcd0 | 2017-01-16 15:41:21 +0530 | [diff] [blame] | 794 | |
Jacob Erlbeck | 37005a1 | 2015-12-22 14:58:34 +0100 | [diff] [blame] | 795 | len = urbb_len + 15; |
Pravin Kumarvel | 06bdb35 | 2016-10-24 12:21:21 +0530 | [diff] [blame] | 796 | } else { |
sivasankari | 8adfcd0 | 2017-01-16 15:41:21 +0530 | [diff] [blame] | 797 | if (num_blocks > uclen_crbb) { |
| 798 | eow = false; |
| 799 | urbb_len = num_blocks - uclen_crbb; |
| 800 | } |
| 801 | /* Union bit takes 1 bit */ |
| 802 | /* Other fields in descr of compresed bitmap takes 23 bits |
| 803 | * -8 = CRBB_STARTING_COLOR_CODE + CRBB_LENGTH */ |
| 804 | if (urbb_len > (rest_bits - crbb_len - 8)) { |
| 805 | eow = false; |
| 806 | len_coded = false; |
| 807 | urbb_len = rest_bits - crbb_len - 8; |
| 808 | /* -16 = ACKNACK Dissector length + CRBB_STARTING_COLOR_CODE + CRBB_LENGTH */ |
| 809 | } else if (urbb_len > (rest_bits - crbb_len - 16)) { |
| 810 | eow = false; |
| 811 | len_coded = false; |
| 812 | urbb_len = rest_bits - crbb_len - 16; |
| 813 | } |
| 814 | len = urbb_len + crbb_len + 23; |
Pravin Kumarvel | 06bdb35 | 2016-10-24 12:21:21 +0530 | [diff] [blame] | 815 | } |
Jacob Erlbeck | 37005a1 | 2015-12-22 14:58:34 +0100 | [diff] [blame] | 816 | |
| 817 | /* EGPRS Ack/Nack Description IE */ |
Pravin Kumarvel | 06bdb35 | 2016-10-24 12:21:21 +0530 | [diff] [blame] | 818 | if (len_coded == false) { |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 819 | bitvec_write_field(dest, &wp, 0, 1); // 0: don't have length |
Jacob Erlbeck | 37005a1 | 2015-12-22 14:58:34 +0100 | [diff] [blame] | 820 | } else { |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 821 | bitvec_write_field(dest, &wp, 1, 1); // 1: have length |
| 822 | bitvec_write_field(dest, &wp, len, 8); // length |
Jacob Erlbeck | 37005a1 | 2015-12-22 14:58:34 +0100 | [diff] [blame] | 823 | } |
| 824 | |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 825 | bitvec_write_field(dest, &wp, is_final, 1); // FINAL_ACK_INDICATION |
| 826 | bitvec_write_field(dest, &wp, bow, 1); // BEGINNING_OF_WINDOW |
| 827 | bitvec_write_field(dest, &wp, eow, 1); // END_OF_WINDOW |
| 828 | bitvec_write_field(dest, &wp, ssn, 11); // STARTING_SEQUENCE_NUMBER |
Pravin Kumarvel | 06bdb35 | 2016-10-24 12:21:21 +0530 | [diff] [blame] | 829 | if (is_compressed) { |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 830 | bitvec_write_field(dest, &wp, 1, 1); // CRBB_Exist |
| 831 | bitvec_write_field(dest, &wp, crbb_len, 7); // CRBB_LENGTH |
sivasankari | 8adfcd0 | 2017-01-16 15:41:21 +0530 | [diff] [blame] | 832 | crbb_start_clr_code = (0x80 & ucmp_vec.data[0])>>7; |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 833 | bitvec_write_field(dest, &wp, crbb_start_clr_code, 1); // CRBB_clr_code |
sivasankari | 8adfcd0 | 2017-01-16 15:41:21 +0530 | [diff] [blame] | 834 | LOGP(DRLCMACUL, LOGL_DEBUG, |
| 835 | "EGPRS CRBB, crbb_len = %d, crbb_start_clr_code = %d\n", |
| 836 | crbb_len, crbb_start_clr_code); |
| 837 | while (crbb_len != 0) { |
| 838 | if (crbb_len > 8) { |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 839 | bitvec_write_field(dest, &wp, crbb_bitmap[iter], 8); |
sivasankari | 8adfcd0 | 2017-01-16 15:41:21 +0530 | [diff] [blame] | 840 | crbb_len = crbb_len - 8; |
| 841 | iter++; |
| 842 | } else { |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 843 | bitvec_write_field(dest, &wp, crbb_bitmap[iter], crbb_len); |
sivasankari | 8adfcd0 | 2017-01-16 15:41:21 +0530 | [diff] [blame] | 844 | crbb_len = 0; |
| 845 | } |
| 846 | } |
| 847 | esn_crbb = window->mod_sns(esn_crbb + uclen_crbb); |
| 848 | } else { |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 849 | bitvec_write_field(dest, &wp, 0, 1); // CRBB_Exist |
sivasankari | 8adfcd0 | 2017-01-16 15:41:21 +0530 | [diff] [blame] | 850 | } |
Jacob Erlbeck | 37005a1 | 2015-12-22 14:58:34 +0100 | [diff] [blame] | 851 | LOGP(DRLCMACUL, LOGL_DEBUG, |
Pravin Kumarvel | 06bdb35 | 2016-10-24 12:21:21 +0530 | [diff] [blame] | 852 | "EGPRS URBB, urbb len = %d, SSN = %d, ESN_CRBB = %d, " |
| 853 | "len present = %s,desc len = %d, " |
Jacob Erlbeck | 37005a1 | 2015-12-22 14:58:34 +0100 | [diff] [blame] | 854 | "SNS = %d, WS = %d, V(Q) = %d, V(R) = %d%s%s\n", |
sivasankari | 8adfcd0 | 2017-01-16 15:41:21 +0530 | [diff] [blame] | 855 | urbb_len, ssn, esn_crbb, len_coded ? "yes" : "No" , len, |
Jacob Erlbeck | 37005a1 | 2015-12-22 14:58:34 +0100 | [diff] [blame] | 856 | window->sns(), window->ws(), window->v_q(), window->v_r(), |
| 857 | bow ? ", BOW" : "", eow ? ", EOW" : ""); |
Pravin Kumarvel | 06bdb35 | 2016-10-24 12:21:21 +0530 | [diff] [blame] | 858 | |
| 859 | for (i = urbb_len; i > 0; i--) { |
Jacob Erlbeck | 37005a1 | 2015-12-22 14:58:34 +0100 | [diff] [blame] | 860 | /* Set bit at the appropriate position (see 3GPP TS 04.60 12.3.1) */ |
| 861 | bool is_ack = window->m_v_n.is_received(esn_crbb + i); |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 862 | bitvec_write_field(dest, &wp, is_ack, 1); |
Jacob Erlbeck | 37005a1 | 2015-12-22 14:58:34 +0100 | [diff] [blame] | 863 | } |
| 864 | } |
| 865 | |
| 866 | static void write_packet_uplink_ack_egprs( |
| 867 | struct gprs_rlcmac_bts *bts, bitvec * dest, unsigned& wp, |
| 868 | struct gprs_rlcmac_ul_tbf *tbf, bool is_final) |
| 869 | { |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 870 | bitvec_write_field(dest, &wp, 0, 2); // fixed 00 |
Aravind Sirsikar | 99ab0a8 | 2016-06-15 17:46:41 +0530 | [diff] [blame] | 871 | /* CHANNEL_CODING_COMMAND */ |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 872 | bitvec_write_field(dest, &wp, |
Aravind Sirsikar | 99ab0a8 | 2016-06-15 17:46:41 +0530 | [diff] [blame] | 873 | tbf->current_cs().to_num() - 1, 4); |
Aravind Sirsikar | 505a86d | 2016-07-26 18:26:21 +0530 | [diff] [blame] | 874 | /* 0: no RESEGMENT, 1: Segmentation*/ |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 875 | bitvec_write_field(dest, &wp, 1, 1); |
| 876 | bitvec_write_field(dest, &wp, 1, 1); // PRE_EMPTIVE_TRANSMISSION, TODO: This resembles GPRS, change it? |
| 877 | bitvec_write_field(dest, &wp, 0, 1); // 0: no PRR_RETRANSMISSION_REQUEST, TODO: clarify |
| 878 | bitvec_write_field(dest, &wp, 0, 1); // 0: no ARAC_RETRANSMISSION_REQUEST, TODO: clarify |
| 879 | bitvec_write_field(dest, &wp, 1, 1); // 1: have CONTENTION_RESOLUTION_TLLI |
| 880 | bitvec_write_field(dest, &wp, tbf->tlli(), 32); // CONTENTION_RESOLUTION_TLLI |
| 881 | bitvec_write_field(dest, &wp, 1, 1); // TBF_EST (enabled) |
| 882 | bitvec_write_field(dest, &wp, 0, 1); // 0: don't have Packet Timing Advance |
| 883 | bitvec_write_field(dest, &wp, 0, 1); // 0: don't have Packet Extended Timing Advance |
| 884 | bitvec_write_field(dest, &wp, 0, 1); // 0: don't have Power Control Parameters |
| 885 | bitvec_write_field(dest, &wp, 0, 1); // 0: don't have Extension Bits |
Jacob Erlbeck | 37005a1 | 2015-12-22 14:58:34 +0100 | [diff] [blame] | 886 | |
sivasankari | 8adfcd0 | 2017-01-16 15:41:21 +0530 | [diff] [blame] | 887 | /* -2 for last bit 0 mandatory and REL5 not supported */ |
| 888 | unsigned bits_ack_nack = dest->data_len * 8 - wp - 2; |
| 889 | write_packet_ack_nack_desc_egprs(bts, dest, wp, &tbf->m_window, is_final, bits_ack_nack); |
Jacob Erlbeck | 37005a1 | 2015-12-22 14:58:34 +0100 | [diff] [blame] | 890 | |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 891 | bitvec_write_field(dest, &wp, 0, 1); // fixed 0 |
| 892 | bitvec_write_field(dest, &wp, 0, 1); // 0: don't have REL 5 |
Jacob Erlbeck | 37005a1 | 2015-12-22 14:58:34 +0100 | [diff] [blame] | 893 | }; |
| 894 | |
| 895 | void Encoding::write_packet_uplink_ack( |
| 896 | struct gprs_rlcmac_bts *bts, bitvec * dest, |
Jacob Erlbeck | f2694b7 | 2016-01-26 21:46:26 +0100 | [diff] [blame] | 897 | struct gprs_rlcmac_ul_tbf *tbf, bool is_final, |
| 898 | uint8_t rrbp) |
Jacob Erlbeck | 37005a1 | 2015-12-22 14:58:34 +0100 | [diff] [blame] | 899 | { |
| 900 | unsigned wp = 0; |
| 901 | |
| 902 | LOGP(DRLCMACUL, LOGL_DEBUG, "Encoding Ack/Nack for %s " |
| 903 | "(final=%d)\n", tbf_name(tbf), is_final); |
| 904 | |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 905 | bitvec_write_field(dest, &wp, 0x1, 2); // Payload Type |
| 906 | bitvec_write_field(dest, &wp, rrbp, 2); // Uplink block with TDMA framenumber |
| 907 | bitvec_write_field(dest, &wp, is_final, 1); // Suppl/Polling Bit |
| 908 | bitvec_write_field(dest, &wp, 0x0, 3); // Uplink state flag |
| 909 | bitvec_write_field(dest, &wp, 0x9, 6); // MESSAGE TYPE Uplink Ack/Nack |
| 910 | bitvec_write_field(dest, &wp, 0x0, 2); // Page Mode |
Jacob Erlbeck | 37005a1 | 2015-12-22 14:58:34 +0100 | [diff] [blame] | 911 | |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 912 | bitvec_write_field(dest, &wp, 0x0, 2); // fixed 00 |
| 913 | bitvec_write_field(dest, &wp, tbf->tfi(), 5); // Uplink TFI |
Jacob Erlbeck | 37005a1 | 2015-12-22 14:58:34 +0100 | [diff] [blame] | 914 | |
| 915 | if (tbf->is_egprs_enabled()) { |
| 916 | /* PU_AckNack_EGPRS = on */ |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 917 | bitvec_write_field(dest, &wp, 1, 1); // 1: EGPRS |
Jacob Erlbeck | 37005a1 | 2015-12-22 14:58:34 +0100 | [diff] [blame] | 918 | write_packet_uplink_ack_egprs(bts, dest, wp, tbf, is_final); |
| 919 | } else { |
| 920 | /* PU_AckNack_GPRS = on */ |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 921 | bitvec_write_field(dest, &wp, 0, 1); // 0: GPRS |
Jacob Erlbeck | 37005a1 | 2015-12-22 14:58:34 +0100 | [diff] [blame] | 922 | write_packet_uplink_ack_gprs(bts, dest, wp, tbf, is_final); |
| 923 | } |
| 924 | |
| 925 | LOGP(DRLCMACUL, LOGL_DEBUG, |
| 926 | "Uplink Ack/Nack bit count %d, max %d, message = %s\n", |
| 927 | wp, dest->data_len * 8, |
| 928 | osmo_hexdump(dest->data, dest->data_len)); |
| 929 | } |
| 930 | |
Holger Hans Peter Freyther | 63f29d6 | 2013-10-19 19:04:03 +0200 | [diff] [blame] | 931 | unsigned Encoding::write_packet_paging_request(bitvec * dest) |
Holger Hans Peter Freyther | 6ca0a90 | 2013-10-19 18:50:22 +0200 | [diff] [blame] | 932 | { |
| 933 | unsigned wp = 0; |
| 934 | |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 935 | bitvec_write_field(dest, &wp,0x1,2); // Payload Type |
| 936 | bitvec_write_field(dest, &wp,0x0,3); // No polling |
| 937 | bitvec_write_field(dest, &wp,0x0,3); // Uplink state flag |
| 938 | bitvec_write_field(dest, &wp,0x22,6); // MESSAGE TYPE |
Holger Hans Peter Freyther | 6ca0a90 | 2013-10-19 18:50:22 +0200 | [diff] [blame] | 939 | |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 940 | bitvec_write_field(dest, &wp,0x0,2); // Page Mode |
Holger Hans Peter Freyther | 6ca0a90 | 2013-10-19 18:50:22 +0200 | [diff] [blame] | 941 | |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 942 | bitvec_write_field(dest, &wp,0x0,1); // No PERSISTENCE_LEVEL |
| 943 | bitvec_write_field(dest, &wp,0x0,1); // No NLN |
Holger Hans Peter Freyther | 6ca0a90 | 2013-10-19 18:50:22 +0200 | [diff] [blame] | 944 | |
| 945 | return wp; |
| 946 | } |
| 947 | |
Holger Hans Peter Freyther | 63f29d6 | 2013-10-19 19:04:03 +0200 | [diff] [blame] | 948 | unsigned Encoding::write_repeated_page_info(bitvec * dest, unsigned& wp, uint8_t len, |
Holger Hans Peter Freyther | 6ca0a90 | 2013-10-19 18:50:22 +0200 | [diff] [blame] | 949 | uint8_t *identity, uint8_t chan_needed) |
| 950 | { |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 951 | bitvec_write_field(dest, &wp,0x1,1); // Repeated Page info exists |
Holger Hans Peter Freyther | 6ca0a90 | 2013-10-19 18:50:22 +0200 | [diff] [blame] | 952 | |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 953 | bitvec_write_field(dest, &wp,0x1,1); // RR connection paging |
Holger Hans Peter Freyther | 6ca0a90 | 2013-10-19 18:50:22 +0200 | [diff] [blame] | 954 | |
| 955 | if ((identity[0] & 0x07) == 4) { |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 956 | bitvec_write_field(dest, &wp,0x0,1); // TMSI |
Holger Hans Peter Freyther | 6ca0a90 | 2013-10-19 18:50:22 +0200 | [diff] [blame] | 957 | identity++; |
| 958 | len--; |
| 959 | } else { |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 960 | bitvec_write_field(dest, &wp,0x0,1); // MI |
| 961 | bitvec_write_field(dest, &wp,len,4); // MI len |
Holger Hans Peter Freyther | 6ca0a90 | 2013-10-19 18:50:22 +0200 | [diff] [blame] | 962 | } |
| 963 | while (len) { |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 964 | bitvec_write_field(dest, &wp,*identity++,8); // MI data |
Holger Hans Peter Freyther | 6ca0a90 | 2013-10-19 18:50:22 +0200 | [diff] [blame] | 965 | len--; |
| 966 | } |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 967 | bitvec_write_field(dest, &wp,chan_needed,2); // CHANNEL_NEEDED |
| 968 | bitvec_write_field(dest, &wp,0x0,1); // No eMLPP_PRIORITY |
Holger Hans Peter Freyther | 6ca0a90 | 2013-10-19 18:50:22 +0200 | [diff] [blame] | 969 | |
| 970 | return wp; |
| 971 | } |
| 972 | |
Jacob Erlbeck | f0e4039 | 2016-01-08 10:07:53 +0100 | [diff] [blame] | 973 | int Encoding::rlc_write_dl_data_header(const struct gprs_rlc_data_info *rlc, |
| 974 | uint8_t *data) |
| 975 | { |
Jacob Erlbeck | 9e85939 | 2016-02-02 11:48:37 +0100 | [diff] [blame] | 976 | struct gprs_rlc_dl_header_egprs_1 *egprs1; |
| 977 | struct gprs_rlc_dl_header_egprs_2 *egprs2; |
Jacob Erlbeck | f0e4039 | 2016-01-08 10:07:53 +0100 | [diff] [blame] | 978 | struct gprs_rlc_dl_header_egprs_3 *egprs3; |
| 979 | struct rlc_dl_header *gprs; |
| 980 | unsigned int e_fbi_header; |
| 981 | GprsCodingScheme cs = rlc->cs; |
Jacob Erlbeck | 9e85939 | 2016-02-02 11:48:37 +0100 | [diff] [blame] | 982 | unsigned int offs; |
| 983 | unsigned int bsn_delta; |
Jacob Erlbeck | f0e4039 | 2016-01-08 10:07:53 +0100 | [diff] [blame] | 984 | |
| 985 | switch(cs.headerTypeData()) { |
| 986 | case GprsCodingScheme::HEADER_GPRS_DATA: |
| 987 | gprs = static_cast<struct rlc_dl_header *> |
| 988 | ((void *)data); |
| 989 | |
| 990 | gprs->usf = rlc->usf; |
| 991 | gprs->s_p = rlc->es_p != 0 ? 1 : 0; |
| 992 | gprs->rrbp = rlc->rrbp; |
| 993 | gprs->pt = 0; |
| 994 | gprs->tfi = rlc->tfi; |
| 995 | gprs->pr = rlc->pr; |
| 996 | |
| 997 | gprs->fbi = rlc->block_info[0].cv == 0; |
| 998 | gprs->e = rlc->block_info[0].e; |
| 999 | gprs->bsn = rlc->block_info[0].bsn; |
| 1000 | break; |
| 1001 | |
Jacob Erlbeck | 9e85939 | 2016-02-02 11:48:37 +0100 | [diff] [blame] | 1002 | case GprsCodingScheme::HEADER_EGPRS_DATA_TYPE_1: |
| 1003 | egprs1 = static_cast<struct gprs_rlc_dl_header_egprs_1 *> |
| 1004 | ((void *)data); |
| 1005 | |
| 1006 | egprs1->usf = rlc->usf; |
| 1007 | egprs1->es_p = rlc->es_p; |
| 1008 | egprs1->rrbp = rlc->rrbp; |
Tom Tsou | df69809 | 2016-07-11 17:05:19 -0700 | [diff] [blame] | 1009 | egprs1->tfi_hi = rlc->tfi >> 0; /* 1 bit LSB */ |
| 1010 | egprs1->tfi_lo = rlc->tfi >> 1; /* 4 bits */ |
Jacob Erlbeck | 9e85939 | 2016-02-02 11:48:37 +0100 | [diff] [blame] | 1011 | egprs1->pr = rlc->pr; |
| 1012 | egprs1->cps = rlc->cps; |
| 1013 | |
Tom Tsou | df69809 | 2016-07-11 17:05:19 -0700 | [diff] [blame] | 1014 | egprs1->bsn1_hi = rlc->block_info[0].bsn >> 0; /* 2 bits LSB */ |
| 1015 | egprs1->bsn1_mid = rlc->block_info[0].bsn >> 2; /* 8 bits */ |
| 1016 | egprs1->bsn1_lo = rlc->block_info[0].bsn >> 10; /* 1 bit */ |
Jacob Erlbeck | 9e85939 | 2016-02-02 11:48:37 +0100 | [diff] [blame] | 1017 | |
| 1018 | bsn_delta = (rlc->block_info[1].bsn - rlc->block_info[0].bsn) & |
| 1019 | (RLC_EGPRS_SNS - 1); |
| 1020 | |
Tom Tsou | df69809 | 2016-07-11 17:05:19 -0700 | [diff] [blame] | 1021 | egprs1->bsn2_hi = bsn_delta >> 0; /* 7 bits LSB */ |
| 1022 | egprs1->bsn2_lo = bsn_delta >> 7; /* 3 bits */ |
Jacob Erlbeck | 9e85939 | 2016-02-02 11:48:37 +0100 | [diff] [blame] | 1023 | |
| 1024 | /* first FBI/E header */ |
| 1025 | e_fbi_header = rlc->block_info[0].e ? 0x01 : 0; |
| 1026 | e_fbi_header |= rlc->block_info[0].cv == 0 ? 0x02 : 0; /* FBI */ |
Jacob Erlbeck | 0f5c695 | 2016-02-03 18:35:27 +0100 | [diff] [blame] | 1027 | offs = rlc->data_offs_bits[0] / 8; |
| 1028 | OSMO_ASSERT(rlc->data_offs_bits[0] % 8 == 2); |
Jacob Erlbeck | 9e85939 | 2016-02-02 11:48:37 +0100 | [diff] [blame] | 1029 | e_fbi_header <<= 0; |
Jacob Erlbeck | 0f5c695 | 2016-02-03 18:35:27 +0100 | [diff] [blame] | 1030 | data[offs] = (data[offs] & 0b11111100) | e_fbi_header; |
Jacob Erlbeck | 9e85939 | 2016-02-02 11:48:37 +0100 | [diff] [blame] | 1031 | |
| 1032 | /* second FBI/E header */ |
| 1033 | e_fbi_header = rlc->block_info[1].e ? 0x01 : 0; |
| 1034 | e_fbi_header |= rlc->block_info[1].cv == 0 ? 0x02 : 0; /* FBI */ |
| 1035 | offs = rlc->data_offs_bits[1] / 8; |
| 1036 | OSMO_ASSERT(rlc->data_offs_bits[1] % 8 == 4); |
| 1037 | e_fbi_header <<= 2; |
| 1038 | data[offs] = (data[offs] & 0b11110011) | e_fbi_header; |
| 1039 | break; |
| 1040 | |
| 1041 | case GprsCodingScheme::HEADER_EGPRS_DATA_TYPE_2: |
| 1042 | egprs2 = static_cast<struct gprs_rlc_dl_header_egprs_2 *> |
| 1043 | ((void *)data); |
| 1044 | |
| 1045 | egprs2->usf = rlc->usf; |
| 1046 | egprs2->es_p = rlc->es_p; |
| 1047 | egprs2->rrbp = rlc->rrbp; |
Tom Tsou | df69809 | 2016-07-11 17:05:19 -0700 | [diff] [blame] | 1048 | egprs2->tfi_hi = rlc->tfi >> 0; /* 1 bit LSB */ |
| 1049 | egprs2->tfi_lo = rlc->tfi >> 1; /* 4 bits */ |
Jacob Erlbeck | 9e85939 | 2016-02-02 11:48:37 +0100 | [diff] [blame] | 1050 | egprs2->pr = rlc->pr; |
| 1051 | egprs2->cps = rlc->cps; |
| 1052 | |
Tom Tsou | df69809 | 2016-07-11 17:05:19 -0700 | [diff] [blame] | 1053 | egprs2->bsn1_hi = rlc->block_info[0].bsn >> 0; /* 2 bits LSB */ |
| 1054 | egprs2->bsn1_mid = rlc->block_info[0].bsn >> 2; /* 8 bits */ |
| 1055 | egprs2->bsn1_lo = rlc->block_info[0].bsn >> 10; /* 1 bit */ |
Jacob Erlbeck | 9e85939 | 2016-02-02 11:48:37 +0100 | [diff] [blame] | 1056 | |
| 1057 | e_fbi_header = rlc->block_info[0].e ? 0x01 : 0; |
| 1058 | e_fbi_header |= rlc->block_info[0].cv == 0 ? 0x02 : 0; /* FBI */ |
Jacob Erlbeck | 0f5c695 | 2016-02-03 18:35:27 +0100 | [diff] [blame] | 1059 | offs = rlc->data_offs_bits[0] / 8; |
| 1060 | OSMO_ASSERT(rlc->data_offs_bits[0] % 8 == 6); |
Jacob Erlbeck | 9e85939 | 2016-02-02 11:48:37 +0100 | [diff] [blame] | 1061 | e_fbi_header <<= 4; |
Jacob Erlbeck | 0f5c695 | 2016-02-03 18:35:27 +0100 | [diff] [blame] | 1062 | data[offs] = (data[offs] & 0b11001111) | e_fbi_header; |
Jacob Erlbeck | 9e85939 | 2016-02-02 11:48:37 +0100 | [diff] [blame] | 1063 | break; |
| 1064 | |
Jacob Erlbeck | f0e4039 | 2016-01-08 10:07:53 +0100 | [diff] [blame] | 1065 | case GprsCodingScheme::HEADER_EGPRS_DATA_TYPE_3: |
| 1066 | egprs3 = static_cast<struct gprs_rlc_dl_header_egprs_3 *> |
| 1067 | ((void *)data); |
| 1068 | |
| 1069 | egprs3->usf = rlc->usf; |
| 1070 | egprs3->es_p = rlc->es_p; |
| 1071 | egprs3->rrbp = rlc->rrbp; |
Tom Tsou | df69809 | 2016-07-11 17:05:19 -0700 | [diff] [blame] | 1072 | egprs3->tfi_hi = rlc->tfi >> 0; /* 1 bit LSB */ |
| 1073 | egprs3->tfi_lo = rlc->tfi >> 1; /* 4 bits */ |
Jacob Erlbeck | f0e4039 | 2016-01-08 10:07:53 +0100 | [diff] [blame] | 1074 | egprs3->pr = rlc->pr; |
| 1075 | egprs3->cps = rlc->cps; |
| 1076 | |
Tom Tsou | df69809 | 2016-07-11 17:05:19 -0700 | [diff] [blame] | 1077 | egprs3->bsn1_hi = rlc->block_info[0].bsn >> 0; /* 2 bits LSB */ |
| 1078 | egprs3->bsn1_mid = rlc->block_info[0].bsn >> 2; /* 8 bits */ |
| 1079 | egprs3->bsn1_lo = rlc->block_info[0].bsn >> 10; /* 1 bit */ |
Jacob Erlbeck | f0e4039 | 2016-01-08 10:07:53 +0100 | [diff] [blame] | 1080 | |
| 1081 | egprs3->spb = rlc->block_info[0].spb; |
| 1082 | |
| 1083 | e_fbi_header = rlc->block_info[0].e ? 0x01 : 0; |
| 1084 | e_fbi_header |= rlc->block_info[0].cv == 0 ? 0x02 : 0; /* FBI */ |
Jacob Erlbeck | 0f5c695 | 2016-02-03 18:35:27 +0100 | [diff] [blame] | 1085 | offs = rlc->data_offs_bits[0] / 8; |
| 1086 | OSMO_ASSERT(rlc->data_offs_bits[0] % 8 == 1); |
Jacob Erlbeck | f0e4039 | 2016-01-08 10:07:53 +0100 | [diff] [blame] | 1087 | e_fbi_header <<= 7; |
Jacob Erlbeck | 0f5c695 | 2016-02-03 18:35:27 +0100 | [diff] [blame] | 1088 | data[offs-1] = (data[offs-1] & 0b01111111) | (e_fbi_header >> 0); |
| 1089 | data[offs] = (data[offs] & 0b11111110) | (e_fbi_header >> 8); |
Jacob Erlbeck | f0e4039 | 2016-01-08 10:07:53 +0100 | [diff] [blame] | 1090 | break; |
| 1091 | |
Jacob Erlbeck | f0e4039 | 2016-01-08 10:07:53 +0100 | [diff] [blame] | 1092 | default: |
| 1093 | LOGP(DRLCMACDL, LOGL_ERROR, |
| 1094 | "Encoding of uplink %s data blocks not yet supported.\n", |
| 1095 | cs.name()); |
| 1096 | return -ENOTSUP; |
| 1097 | }; |
| 1098 | |
| 1099 | return 0; |
| 1100 | } |
| 1101 | |
| 1102 | /** |
| 1103 | * \brief Copy LSB bitstream RLC data block from byte aligned buffer. |
| 1104 | * |
| 1105 | * Note that the bitstream is encoded in LSB first order, so the two octets |
| 1106 | * 654321xx xxxxxx87 contain the octet 87654321 starting at bit position 3 |
| 1107 | * (LSB has bit position 1). This is a different order than the one used by |
| 1108 | * CSN.1. |
| 1109 | * |
| 1110 | * \param data_block_idx The block index, 0..1 for header type 1, 0 otherwise |
| 1111 | * \param src A pointer to the start of the RLC block (incl. the header) |
| 1112 | * \param buffer A data area of a least the size of the RLC block |
| 1113 | * \returns the number of bytes copied |
| 1114 | */ |
| 1115 | unsigned int Encoding::rlc_copy_from_aligned_buffer( |
| 1116 | const struct gprs_rlc_data_info *rlc, |
| 1117 | unsigned int data_block_idx, |
| 1118 | uint8_t *dst, const uint8_t *buffer) |
| 1119 | { |
| 1120 | unsigned int hdr_bytes; |
| 1121 | unsigned int extra_bits; |
| 1122 | unsigned int i; |
| 1123 | |
| 1124 | uint8_t c, last_c; |
| 1125 | const uint8_t *src; |
| 1126 | const struct gprs_rlc_data_block_info *rdbi; |
| 1127 | |
| 1128 | OSMO_ASSERT(data_block_idx < rlc->num_data_blocks); |
| 1129 | rdbi = &rlc->block_info[data_block_idx]; |
| 1130 | |
| 1131 | hdr_bytes = rlc->data_offs_bits[data_block_idx] / 8; |
| 1132 | extra_bits = (rlc->data_offs_bits[data_block_idx] % 8); |
| 1133 | |
| 1134 | if (extra_bits == 0) { |
| 1135 | /* It is aligned already */ |
| 1136 | memmove(dst + hdr_bytes, buffer, rdbi->data_len); |
| 1137 | return rdbi->data_len; |
| 1138 | } |
| 1139 | |
| 1140 | src = buffer; |
| 1141 | dst = dst + hdr_bytes; |
| 1142 | last_c = *dst << (8 - extra_bits); |
| 1143 | |
| 1144 | for (i = 0; i < rdbi->data_len; i++) { |
| 1145 | c = src[i]; |
| 1146 | *(dst++) = (last_c >> (8 - extra_bits)) | (c << extra_bits); |
| 1147 | last_c = c; |
| 1148 | } |
| 1149 | |
| 1150 | /* overwrite the lower extra_bits */ |
| 1151 | *dst = (*dst & (0xff << extra_bits)) | (last_c >> (8 - extra_bits)); |
| 1152 | |
| 1153 | return rdbi->data_len; |
| 1154 | } |
Jacob Erlbeck | 14bb094 | 2016-01-12 11:58:13 +0100 | [diff] [blame] | 1155 | |
Alexander Couzens | cb846ec | 2016-05-30 19:10:48 +0200 | [diff] [blame] | 1156 | /*! |
| 1157 | * \brief (GPRS) put llc pdu into an rlc/mac block. fragment the llc pdu if needed |
| 1158 | * \param rdbi rlc/mac block info |
| 1159 | * \param llc llc pdu |
| 1160 | * \param offset given offset within the rlc/mac block |
| 1161 | * \param num_chunks count the chunks (llc pdu data) within rlc/mac |
| 1162 | * \param data_block buffer holds rlc/mac data |
| 1163 | * \param is_final if this is the last rlc/mac within a TBF |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 1164 | * \param count_payload if not NULL save the written size of payload in bytes into it |
Alexander Couzens | cb846ec | 2016-05-30 19:10:48 +0200 | [diff] [blame] | 1165 | * \return the state of the rlc/mac like if there is more space for another chunk |
| 1166 | */ |
Jacob Erlbeck | 5058bd6 | 2016-01-13 10:51:25 +0100 | [diff] [blame] | 1167 | static Encoding::AppendResult rlc_data_to_dl_append_gprs( |
Jacob Erlbeck | 14bb094 | 2016-01-12 11:58:13 +0100 | [diff] [blame] | 1168 | struct gprs_rlc_data_block_info *rdbi, |
| 1169 | gprs_llc *llc, int *offset, int *num_chunks, |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 1170 | uint8_t *data_block, bool is_final, int *count_payload) |
Jacob Erlbeck | 14bb094 | 2016-01-12 11:58:13 +0100 | [diff] [blame] | 1171 | { |
| 1172 | int chunk; |
| 1173 | int space; |
| 1174 | struct rlc_li_field *li; |
| 1175 | uint8_t *delimiter, *data, *e_pointer; |
| 1176 | |
| 1177 | data = data_block + *offset; |
| 1178 | delimiter = data_block + *num_chunks; |
| 1179 | e_pointer = (*num_chunks ? delimiter - 1 : NULL); |
| 1180 | |
| 1181 | chunk = llc->chunk_size(); |
| 1182 | space = rdbi->data_len - *offset; |
| 1183 | |
| 1184 | /* if chunk will exceed block limit */ |
| 1185 | if (chunk > space) { |
| 1186 | LOGP(DRLCMACDL, LOGL_DEBUG, "-- Chunk with length %d " |
| 1187 | "larger than space (%d) left in block: copy " |
| 1188 | "only remaining space, and we are done\n", |
| 1189 | chunk, space); |
| 1190 | /* block is filled, so there is no extension */ |
| 1191 | if (e_pointer) |
| 1192 | *e_pointer |= 0x01; |
| 1193 | /* fill only space */ |
| 1194 | llc->consume(data, space); |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 1195 | if (count_payload) |
| 1196 | *count_payload = space; |
Jacob Erlbeck | 14bb094 | 2016-01-12 11:58:13 +0100 | [diff] [blame] | 1197 | /* return data block as message */ |
| 1198 | *offset = rdbi->data_len; |
| 1199 | (*num_chunks)++; |
Jacob Erlbeck | 5058bd6 | 2016-01-13 10:51:25 +0100 | [diff] [blame] | 1200 | return Encoding::AR_NEED_MORE_BLOCKS; |
Jacob Erlbeck | 14bb094 | 2016-01-12 11:58:13 +0100 | [diff] [blame] | 1201 | } |
| 1202 | /* if FINAL chunk would fit precisely in space left */ |
| 1203 | if (chunk == space && is_final) |
| 1204 | { |
| 1205 | LOGP(DRLCMACDL, LOGL_DEBUG, "-- Chunk with length %d " |
| 1206 | "would exactly fit into space (%d): because " |
| 1207 | "this is a final block, we don't add length " |
| 1208 | "header, and we are done\n", chunk, space); |
| 1209 | /* block is filled, so there is no extension */ |
| 1210 | if (e_pointer) |
| 1211 | *e_pointer |= 0x01; |
| 1212 | /* fill space */ |
| 1213 | llc->consume(data, space); |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 1214 | if (count_payload) |
| 1215 | *count_payload = space; |
Jacob Erlbeck | 14bb094 | 2016-01-12 11:58:13 +0100 | [diff] [blame] | 1216 | *offset = rdbi->data_len; |
| 1217 | (*num_chunks)++; |
| 1218 | rdbi->cv = 0; |
Jacob Erlbeck | 5058bd6 | 2016-01-13 10:51:25 +0100 | [diff] [blame] | 1219 | return Encoding::AR_COMPLETED_BLOCK_FILLED; |
Jacob Erlbeck | 14bb094 | 2016-01-12 11:58:13 +0100 | [diff] [blame] | 1220 | } |
| 1221 | /* if chunk would fit exactly in space left */ |
| 1222 | if (chunk == space) { |
| 1223 | LOGP(DRLCMACDL, LOGL_DEBUG, "-- Chunk with length %d " |
| 1224 | "would exactly fit into space (%d): add length " |
| 1225 | "header with LI=0, to make frame extend to " |
| 1226 | "next block, and we are done\n", chunk, space); |
| 1227 | /* make space for delimiter */ |
| 1228 | if (delimiter != data) |
| 1229 | memmove(delimiter + 1, delimiter, |
| 1230 | data - delimiter); |
| 1231 | data++; |
| 1232 | (*offset)++; |
| 1233 | space--; |
| 1234 | /* add LI with 0 length */ |
| 1235 | li = (struct rlc_li_field *)delimiter; |
| 1236 | li->e = 1; /* not more extension */ |
| 1237 | li->m = 0; /* shall be set to 0, in case of li = 0 */ |
| 1238 | li->li = 0; /* chunk fills the complete space */ |
| 1239 | rdbi->e = 0; /* 0: extensions present */ |
| 1240 | // no need to set e_pointer nor increase delimiter |
| 1241 | /* fill only space, which is 1 octet less than chunk */ |
| 1242 | llc->consume(data, space); |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 1243 | if (count_payload) |
| 1244 | *count_payload = space; |
Jacob Erlbeck | 14bb094 | 2016-01-12 11:58:13 +0100 | [diff] [blame] | 1245 | /* return data block as message */ |
| 1246 | *offset = rdbi->data_len; |
| 1247 | (*num_chunks)++; |
Jacob Erlbeck | 5058bd6 | 2016-01-13 10:51:25 +0100 | [diff] [blame] | 1248 | return Encoding::AR_NEED_MORE_BLOCKS; |
Jacob Erlbeck | 14bb094 | 2016-01-12 11:58:13 +0100 | [diff] [blame] | 1249 | } |
| 1250 | |
| 1251 | LOGP(DRLCMACDL, LOGL_DEBUG, "-- Chunk with length %d is less " |
| 1252 | "than remaining space (%d): add length header to " |
| 1253 | "to delimit LLC frame\n", chunk, space); |
| 1254 | /* the LLC frame chunk ends in this block */ |
| 1255 | /* make space for delimiter */ |
| 1256 | if (delimiter != data) |
| 1257 | memmove(delimiter + 1, delimiter, data - delimiter); |
| 1258 | data++; |
| 1259 | (*offset)++; |
| 1260 | space--; |
| 1261 | /* add LI to delimit frame */ |
| 1262 | li = (struct rlc_li_field *)delimiter; |
| 1263 | li->e = 0; /* Extension bit, maybe set later */ |
| 1264 | li->m = 0; /* will be set later, if there is more LLC data */ |
| 1265 | li->li = chunk; /* length of chunk */ |
| 1266 | rdbi->e = 0; /* 0: extensions present */ |
| 1267 | (*num_chunks)++; |
| 1268 | /* copy (rest of) LLC frame to space and reset later */ |
| 1269 | llc->consume(data, chunk); |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 1270 | if (count_payload) |
| 1271 | *count_payload = chunk; |
Jacob Erlbeck | 14bb094 | 2016-01-12 11:58:13 +0100 | [diff] [blame] | 1272 | data += chunk; |
| 1273 | space -= chunk; |
| 1274 | (*offset) += chunk; |
| 1275 | /* if we have more data and we have space left */ |
| 1276 | if (space > 0 && !is_final) { |
| 1277 | li->m = 1; /* we indicate more frames to follow */ |
Jacob Erlbeck | 5058bd6 | 2016-01-13 10:51:25 +0100 | [diff] [blame] | 1278 | return Encoding::AR_COMPLETED_SPACE_LEFT; |
Jacob Erlbeck | 14bb094 | 2016-01-12 11:58:13 +0100 | [diff] [blame] | 1279 | } |
| 1280 | /* if we don't have more LLC frames */ |
| 1281 | if (is_final) { |
| 1282 | LOGP(DRLCMACDL, LOGL_DEBUG, "-- Final block, so we " |
| 1283 | "done.\n"); |
| 1284 | li->e = 1; /* we cannot extend */ |
| 1285 | rdbi->cv = 0; |
Jacob Erlbeck | 5058bd6 | 2016-01-13 10:51:25 +0100 | [diff] [blame] | 1286 | return Encoding::AR_COMPLETED_BLOCK_FILLED; |
Jacob Erlbeck | 14bb094 | 2016-01-12 11:58:13 +0100 | [diff] [blame] | 1287 | } |
| 1288 | /* we have no space left */ |
| 1289 | LOGP(DRLCMACDL, LOGL_DEBUG, "-- No space left, so we are " |
| 1290 | "done.\n"); |
| 1291 | li->e = 1; /* we cannot extend */ |
Jacob Erlbeck | 5058bd6 | 2016-01-13 10:51:25 +0100 | [diff] [blame] | 1292 | return Encoding::AR_COMPLETED_BLOCK_FILLED; |
| 1293 | } |
| 1294 | |
Alexander Couzens | cb846ec | 2016-05-30 19:10:48 +0200 | [diff] [blame] | 1295 | /*! |
| 1296 | * \brief (EGPRS) put llc pdu into an rlc/mac block. fragment the llc pdu if needed |
| 1297 | * \param rdbi rlc/mac block info |
| 1298 | * \param llc llc pdu |
| 1299 | * \param offset given offset within the rlc/mac block |
| 1300 | * \param num_chunks count the chunks (llc pdu data) within rlc/mac |
| 1301 | * \param data_block buffer holds rlc/mac data |
| 1302 | * \param is_final if this is the last rlc/mac within a TBF |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 1303 | * \param count_payload if not NULL save the written size of payload in bytes into it |
Alexander Couzens | cb846ec | 2016-05-30 19:10:48 +0200 | [diff] [blame] | 1304 | * \return the state of the rlc/mac like if there is more space for another chunk |
| 1305 | */ |
Jacob Erlbeck | a88d065 | 2016-01-13 11:28:10 +0100 | [diff] [blame] | 1306 | static Encoding::AppendResult rlc_data_to_dl_append_egprs( |
| 1307 | struct gprs_rlc_data_block_info *rdbi, |
| 1308 | gprs_llc *llc, int *offset, int *num_chunks, |
| 1309 | uint8_t *data_block, |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 1310 | bool is_final, int *count_payload) |
Jacob Erlbeck | a88d065 | 2016-01-13 11:28:10 +0100 | [diff] [blame] | 1311 | { |
| 1312 | int chunk; |
| 1313 | int space; |
| 1314 | struct rlc_li_field_egprs *li; |
| 1315 | struct rlc_li_field_egprs *prev_li; |
| 1316 | uint8_t *delimiter, *data; |
| 1317 | |
| 1318 | data = data_block + *offset; |
| 1319 | delimiter = data_block + *num_chunks; |
| 1320 | prev_li = (struct rlc_li_field_egprs *) |
| 1321 | (*num_chunks ? delimiter - 1 : NULL); |
| 1322 | |
| 1323 | chunk = llc->chunk_size(); |
| 1324 | space = rdbi->data_len - *offset; |
| 1325 | |
| 1326 | /* if chunk will exceed block limit */ |
| 1327 | if (chunk > space) { |
| 1328 | LOGP(DRLCMACDL, LOGL_DEBUG, "-- Chunk with length %d " |
| 1329 | "larger than space (%d) left in block: copy " |
| 1330 | "only remaining space, and we are done\n", |
| 1331 | chunk, space); |
| 1332 | /* fill only space */ |
| 1333 | llc->consume(data, space); |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 1334 | if (count_payload) |
| 1335 | *count_payload = space; |
Jacob Erlbeck | a88d065 | 2016-01-13 11:28:10 +0100 | [diff] [blame] | 1336 | /* return data block as message */ |
| 1337 | *offset = rdbi->data_len; |
| 1338 | (*num_chunks)++; |
| 1339 | return Encoding::AR_NEED_MORE_BLOCKS; |
| 1340 | } |
| 1341 | /* if FINAL chunk would fit precisely in space left */ |
| 1342 | if (chunk == space && is_final) |
| 1343 | { |
| 1344 | LOGP(DRLCMACDL, LOGL_DEBUG, "-- Chunk with length %d " |
| 1345 | "would exactly fit into space (%d): because " |
| 1346 | "this is a final block, we don't add length " |
| 1347 | "header, and we are done\n", chunk, space); |
| 1348 | /* fill space */ |
| 1349 | llc->consume(data, space); |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 1350 | if (count_payload) |
| 1351 | *count_payload = space; |
Jacob Erlbeck | a88d065 | 2016-01-13 11:28:10 +0100 | [diff] [blame] | 1352 | *offset = rdbi->data_len; |
| 1353 | (*num_chunks)++; |
| 1354 | rdbi->cv = 0; |
| 1355 | return Encoding::AR_COMPLETED_BLOCK_FILLED; |
| 1356 | } |
| 1357 | /* if chunk would fit exactly in space left */ |
| 1358 | if (chunk == space) { |
| 1359 | LOGP(DRLCMACDL, LOGL_DEBUG, "-- Chunk with length %d " |
| 1360 | "would exactly fit into space (%d): just copy " |
| 1361 | "it, and we are done. The next block will have " |
| 1362 | "to start with an empty chunk\n", |
| 1363 | chunk, space); |
| 1364 | /* fill space */ |
| 1365 | llc->consume(data, space); |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 1366 | if (count_payload) |
| 1367 | *count_payload = space; |
Jacob Erlbeck | a88d065 | 2016-01-13 11:28:10 +0100 | [diff] [blame] | 1368 | *offset = rdbi->data_len; |
| 1369 | (*num_chunks)++; |
| 1370 | return Encoding::AR_NEED_MORE_BLOCKS; |
| 1371 | } |
| 1372 | |
| 1373 | LOGP(DRLCMACDL, LOGL_DEBUG, "-- Chunk with length %d is less " |
| 1374 | "than remaining space (%d): add length header to " |
| 1375 | "to delimit LLC frame\n", chunk, space); |
| 1376 | /* the LLC frame chunk ends in this block */ |
| 1377 | /* make space for delimiter */ |
| 1378 | |
| 1379 | if (delimiter != data) |
| 1380 | memmove(delimiter + 1, delimiter, data - delimiter); |
| 1381 | |
| 1382 | data += 1; |
| 1383 | (*offset) += 1; |
| 1384 | space -= 1; |
| 1385 | /* add LI to delimit frame */ |
| 1386 | li = (struct rlc_li_field_egprs *)delimiter; |
| 1387 | li->e = 1; /* Extension bit, maybe set later */ |
| 1388 | li->li = chunk; /* length of chunk */ |
| 1389 | /* tell previous extension header about the new one */ |
| 1390 | if (prev_li) |
| 1391 | prev_li->e = 0; |
| 1392 | rdbi->e = 0; /* 0: extensions present */ |
| 1393 | delimiter++; |
| 1394 | prev_li = li; |
| 1395 | (*num_chunks)++; |
| 1396 | /* copy (rest of) LLC frame to space and reset later */ |
| 1397 | llc->consume(data, chunk); |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 1398 | if (count_payload) |
| 1399 | *count_payload = chunk; |
Jacob Erlbeck | a88d065 | 2016-01-13 11:28:10 +0100 | [diff] [blame] | 1400 | data += chunk; |
| 1401 | space -= chunk; |
| 1402 | (*offset) += chunk; |
| 1403 | /* if we have more data and we have space left */ |
| 1404 | if (space > 0) { |
| 1405 | if (!is_final) |
| 1406 | return Encoding::AR_COMPLETED_SPACE_LEFT; |
| 1407 | |
| 1408 | /* we don't have more LLC frames */ |
| 1409 | /* We will have to add another chunk with filling octets */ |
| 1410 | LOGP(DRLCMACDL, LOGL_DEBUG, |
| 1411 | "-- There is remaining space (%d): add filling byte chunk\n", |
| 1412 | space); |
| 1413 | |
| 1414 | if (delimiter != data) |
| 1415 | memmove(delimiter + 1, delimiter, data - delimiter); |
| 1416 | |
| 1417 | data += 1; |
| 1418 | (*offset) += 1; |
| 1419 | space -= 1; |
| 1420 | |
| 1421 | /* set filling bytes extension */ |
| 1422 | li = (struct rlc_li_field_egprs *)delimiter; |
| 1423 | li->e = 1; |
| 1424 | li->li = 127; |
| 1425 | |
| 1426 | /* tell previous extension header about the new one */ |
| 1427 | if (prev_li) |
| 1428 | prev_li->e = 0; |
| 1429 | |
| 1430 | delimiter++; |
| 1431 | (*num_chunks)++; |
| 1432 | |
| 1433 | rdbi->cv = 0; |
| 1434 | |
| 1435 | LOGP(DRLCMACDL, LOGL_DEBUG, "-- Final block, so we " |
| 1436 | "are done.\n"); |
| 1437 | |
| 1438 | *offset = rdbi->data_len; |
| 1439 | return Encoding::AR_COMPLETED_BLOCK_FILLED; |
| 1440 | } |
| 1441 | |
| 1442 | if (is_final) { |
| 1443 | /* we don't have more LLC frames */ |
| 1444 | LOGP(DRLCMACDL, LOGL_DEBUG, "-- Final block, so we " |
| 1445 | "are done.\n"); |
| 1446 | rdbi->cv = 0; |
| 1447 | return Encoding::AR_COMPLETED_BLOCK_FILLED; |
| 1448 | } |
| 1449 | |
| 1450 | /* we have no space left */ |
| 1451 | LOGP(DRLCMACDL, LOGL_DEBUG, "-- No space left, so we are " |
| 1452 | "done.\n"); |
| 1453 | return Encoding::AR_COMPLETED_BLOCK_FILLED; |
| 1454 | } |
| 1455 | |
Alexander Couzens | cb846ec | 2016-05-30 19:10:48 +0200 | [diff] [blame] | 1456 | /*! |
| 1457 | * \brief Encoding::rlc_data_to_dl_append |
| 1458 | * \param rdbi rlc/mac block info |
| 1459 | * \param cs the coding scheme to use |
| 1460 | * \param llc llc pdu |
| 1461 | * \param offset given offset within the rlc/mac block |
| 1462 | * \param num_chunks count the chunks (llc pdu data) within rlc/mac |
| 1463 | * \param data_block buffer holds rlc/mac data |
| 1464 | * \param is_final if this is the last rlc/mac within a TBF |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 1465 | * \param count_payload if not NULL save the written size of payload in bytes into it |
Alexander Couzens | cb846ec | 2016-05-30 19:10:48 +0200 | [diff] [blame] | 1466 | * \return the state of the rlc/mac like if there is more space for another chunk |
| 1467 | */ |
Jacob Erlbeck | 5058bd6 | 2016-01-13 10:51:25 +0100 | [diff] [blame] | 1468 | Encoding::AppendResult Encoding::rlc_data_to_dl_append( |
| 1469 | struct gprs_rlc_data_block_info *rdbi, GprsCodingScheme cs, |
| 1470 | gprs_llc *llc, int *offset, int *num_chunks, |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 1471 | uint8_t *data_block, bool is_final, int *count_payload) |
Jacob Erlbeck | 5058bd6 | 2016-01-13 10:51:25 +0100 | [diff] [blame] | 1472 | { |
| 1473 | if (cs.isGprs()) |
| 1474 | return rlc_data_to_dl_append_gprs(rdbi, |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 1475 | llc, offset, num_chunks, data_block, is_final, |
| 1476 | count_payload); |
Jacob Erlbeck | 5058bd6 | 2016-01-13 10:51:25 +0100 | [diff] [blame] | 1477 | |
Jacob Erlbeck | a88d065 | 2016-01-13 11:28:10 +0100 | [diff] [blame] | 1478 | if (cs.isEgprs()) |
| 1479 | return rlc_data_to_dl_append_egprs(rdbi, |
Alexander Couzens | 6f0dc96 | 2016-05-30 19:30:21 +0200 | [diff] [blame] | 1480 | llc, offset, num_chunks, data_block, is_final, |
| 1481 | count_payload); |
Jacob Erlbeck | a88d065 | 2016-01-13 11:28:10 +0100 | [diff] [blame] | 1482 | |
Jacob Erlbeck | 5058bd6 | 2016-01-13 10:51:25 +0100 | [diff] [blame] | 1483 | LOGP(DRLCMACDL, LOGL_ERROR, "%s data block encoding not implemented\n", |
| 1484 | cs.name()); |
| 1485 | |
| 1486 | return AR_NEED_MORE_BLOCKS; |
Jacob Erlbeck | 14bb094 | 2016-01-12 11:58:13 +0100 | [diff] [blame] | 1487 | } |
aravind sirsikar | ed3413e | 2016-11-11 17:15:10 +0530 | [diff] [blame] | 1488 | |
| 1489 | /* |
| 1490 | * Refer 44.060 version 7.27.0 Release 7 |
| 1491 | * section 7.1.3.2.1 On receipt of a PACKET RESOURCE REQUEST message |
| 1492 | * 8.1.2.5 Establishment of uplink TBF |
| 1493 | */ |
| 1494 | void Encoding::write_packet_access_reject( |
| 1495 | bitvec * dest, uint32_t tlli) |
| 1496 | { |
| 1497 | unsigned wp = 0; |
| 1498 | |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 1499 | bitvec_write_field(dest, &wp, 0x1, 2); // Payload Type |
| 1500 | bitvec_write_field(dest, &wp, 0x0, 2); // Uplink block with TDMA FN |
| 1501 | bitvec_write_field(dest, &wp, 0, 1); // No Polling Bit |
| 1502 | bitvec_write_field(dest, &wp, 0x0, 3); // Uplink state flag |
| 1503 | bitvec_write_field(dest, &wp, |
aravind sirsikar | ed3413e | 2016-11-11 17:15:10 +0530 | [diff] [blame] | 1504 | MT_PACKET_ACCESS_REJECT, 6); // MESSAGE TYPE |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 1505 | bitvec_write_field(dest, &wp, 0, 2); // fixed 00 |
| 1506 | bitvec_write_field(dest, &wp, 0x0, 1); // TLLI / G-RNTI : bit (32) |
| 1507 | bitvec_write_field(dest, &wp, tlli, 32); // CONTENTION_RESOLUTION_TLLI |
| 1508 | bitvec_write_field(dest, &wp, 1, 1); // WAIT_INDICATION size in seconds |
aravind sirsikar | ed3413e | 2016-11-11 17:15:10 +0530 | [diff] [blame] | 1509 | /* TODO: make it configurable */ |
Alexander Couzens | ccde5c9 | 2017-02-04 03:10:08 +0100 | [diff] [blame] | 1510 | bitvec_write_field(dest, &wp, 5, 8); // WAIT_INDICATION value |
| 1511 | bitvec_write_field(dest, &wp, 0, 1); // WAIT_INDICATION size in seconds |
aravind sirsikar | ed3413e | 2016-11-11 17:15:10 +0530 | [diff] [blame] | 1512 | } |