/src/coding/gsm0503_mapping.c

https://gitlab.com/nrw_noa/libosmocore · C · 305 lines · 233 code · 38 blank · 34 comment · 58 complexity · 017c0381436a7e54e8831788a3d043cf MD5 · raw file

  1. /*
  2. * (C) 2013 by Andreas Eversberg <jolly@eversberg.eu>
  3. * (C) 2016 by Tom Tsou <tom.tsou@ettus.com>
  4. *
  5. * All Rights Reserved
  6. *
  7. * SPDX-License-Identifier: GPL-2.0+
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License along
  20. * with this program; if not, write to the Free Software Foundation, Inc.,
  21. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  22. */
  23. #include <stdint.h>
  24. #include <string.h>
  25. #include <osmocom/core/bits.h>
  26. #include <osmocom/coding/gsm0503_mapping.h>
  27. /*! \addtogroup mapping
  28. * @{
  29. *
  30. * GSM TS 05.03 burst mapping
  31. *
  32. * This module contains burst mapping routines as specified in 3GPP TS
  33. * 05.03 / 45.003.
  34. *
  35. * \file gsm0503_mapping.c */
  36. void gsm0503_xcch_burst_unmap(sbit_t *iB, const sbit_t *eB,
  37. sbit_t *hl, sbit_t *hn)
  38. {
  39. memcpy(iB, eB, 57);
  40. memcpy(iB + 57, eB + 59, 57);
  41. if (hl)
  42. *hl = eB[57];
  43. if (hn)
  44. *hn = eB[58];
  45. }
  46. void gsm0503_xcch_burst_map(const ubit_t *iB, ubit_t *eB, const ubit_t *hl,
  47. const ubit_t *hn)
  48. {
  49. memcpy(eB, iB, 57);
  50. memcpy(eB + 59, iB + 57, 57);
  51. if (hl)
  52. eB[57] = *hl;
  53. if (hn)
  54. eB[58] = *hn;
  55. }
  56. void gsm0503_tch_burst_unmap(sbit_t *iB, const sbit_t *eB, sbit_t *h, int odd)
  57. {
  58. int i;
  59. /* brainfuck: only copy even or odd bits */
  60. if (iB) {
  61. for (i = odd; i < 57; i += 2)
  62. iB[i] = eB[i];
  63. for (i = 58 - odd; i < 114; i += 2)
  64. iB[i] = eB[i + 2];
  65. }
  66. if (h) {
  67. if (!odd)
  68. *h = eB[58];
  69. else
  70. *h = eB[57];
  71. }
  72. }
  73. void gsm0503_tch_burst_map(const ubit_t *iB, ubit_t *eB, const ubit_t *h, int odd)
  74. {
  75. int i;
  76. /* brainfuck: only copy even or odd bits */
  77. if (eB) {
  78. for (i = odd; i < 57; i += 2)
  79. eB[i] = iB[i];
  80. for (i = 58 - odd; i < 114; i += 2)
  81. eB[i + 2] = iB[i];
  82. }
  83. if (h) {
  84. if (!odd)
  85. eB[58] = *h;
  86. else
  87. eB[57] = *h;
  88. }
  89. }
  90. void gsm0503_mcs5_dl_burst_map(const ubit_t *di, ubit_t *eB,
  91. const ubit_t *hi, const ubit_t *up, int B)
  92. {
  93. int j;
  94. int q[8] = { 0, 0, 0, 0, 0, 0, 0, 0, };
  95. for (j = 0; j < 156; j++)
  96. eB[j] = di[312 * B + j];
  97. for (j = 156; j < 168; j++)
  98. eB[j] = hi[25 * B + j - 156];
  99. for (j = 168; j < 174; j++)
  100. eB[j] = up[9 * B + j - 168];
  101. for (j = 174; j < 176; j++)
  102. eB[j] = q[2 * B + j - 174];
  103. for (j = 176; j < 179; j++)
  104. eB[j] = up[9 * B + j - 170];
  105. for (j = 179; j < 192; j++)
  106. eB[j] = hi[25 * B + j - 167];
  107. for (j = 192; j < 348; j++)
  108. eB[j] = di[312 * B + j - 36];
  109. }
  110. void gsm0503_mcs5_dl_burst_unmap(sbit_t *di, const sbit_t *eB,
  111. sbit_t *hi, sbit_t *up, int B)
  112. {
  113. int j;
  114. for (j = 0; j < 156; j++)
  115. di[312 * B + j] = eB[j];
  116. for (j = 156; j < 168; j++)
  117. hi[25 * B + j - 156] = eB[j];
  118. for (j = 168; j < 174; j++)
  119. up[9 * B + j - 168] = eB[j];
  120. for (j = 176; j < 179; j++)
  121. up[9 * B + j - 170] = eB[j];
  122. for (j = 179; j < 192; j++)
  123. hi[25 * B + j - 167] = eB[j];
  124. for (j = 192; j < 348; j++)
  125. di[312 * B + j - 36] = eB[j];
  126. }
  127. void gsm0503_mcs5_ul_burst_map(const ubit_t *di, ubit_t *eB,
  128. const ubit_t *hi, int B)
  129. {
  130. int j;
  131. for (j = 0; j < 156; j++)
  132. eB[j] = di[312 * B + j];
  133. for (j = 156; j < 174; j++)
  134. eB[j] = hi[34 * B + j - 156];
  135. for (j = 174; j < 176; j++)
  136. eB[j] = 0;
  137. for (j = 176; j < 192; j++)
  138. eB[j] = hi[34 * B + j - 158];
  139. for (j = 192; j < 348; j++)
  140. eB[j] = di[312 * B + j - 36];
  141. }
  142. void gsm0503_mcs5_ul_burst_unmap(sbit_t *di, const sbit_t *eB,
  143. sbit_t *hi, int B)
  144. {
  145. int j;
  146. for (j = 0; j < 156; j++)
  147. di[312 * B + j] = eB[j];
  148. for (j = 156; j < 174; j++)
  149. hi[34 * B + j - 156] = eB[j];
  150. for (j = 176; j < 192; j++)
  151. hi[34 * B + j - 158] = eB[j];
  152. for (j = 192; j < 348; j++)
  153. di[312 * B + j - 36] = eB[j];
  154. }
  155. void gsm0503_mcs7_dl_burst_map(const ubit_t *di, ubit_t *eB,
  156. const ubit_t *hi, const ubit_t *up, int B)
  157. {
  158. int j;
  159. int q[8] = { 1, 1, 1, 0, 0, 1, 1, 1, };
  160. for (j = 0; j < 153; j++)
  161. eB[j] = di[306 * B + j];
  162. for (j = 153; j < 168; j++)
  163. eB[j] = hi[31 * B + j - 153];
  164. for (j = 168; j < 174; j++)
  165. eB[j] = up[9 * B + j - 168];
  166. for (j = 174; j < 176; j++)
  167. eB[j] = q[2 * B + j - 174];
  168. for (j = 176; j < 179; j++)
  169. eB[j] = up[9 * B + j - 170];
  170. for (j = 179; j < 195; j++)
  171. eB[j] = hi[31 * B + j - 164];
  172. for (j = 195; j < 348; j++)
  173. eB[j] = di[306 * B + j - 42];
  174. }
  175. void gsm0503_mcs7_dl_burst_unmap(sbit_t *di, const sbit_t *eB,
  176. sbit_t *hi, sbit_t *up, int B)
  177. {
  178. int j;
  179. for (j = 0; j < 153; j++)
  180. di[306 * B + j] = eB[j];
  181. for (j = 153; j < 168; j++)
  182. hi[31 * B + j - 153] = eB[j];
  183. for (j = 168; j < 174; j++)
  184. up[9 * B + j - 168] = eB[j];
  185. for (j = 176; j < 179; j++)
  186. up[9 * B + j - 170] = eB[j];
  187. for (j = 179; j < 195; j++)
  188. hi[31 * B + j - 164] = eB[j];
  189. for (j = 195; j < 348; j++)
  190. di[306 * B + j - 42] = eB[j];
  191. }
  192. void gsm0503_mcs7_ul_burst_map(const ubit_t *di, ubit_t *eB,
  193. const ubit_t *hi, int B)
  194. {
  195. int j;
  196. int q[8] = { 1, 1, 1, 0, 0, 1, 1, 1, };
  197. for (j = 0; j < 153; j++)
  198. eB[j] = di[306 * B + j];
  199. for (j = 153; j < 174; j++)
  200. eB[j] = hi[40 * B + j - 153];
  201. for (j = 174; j < 176; j++)
  202. eB[j] = q[2 * B + j - 174];
  203. for (j = 176; j < 195; j++)
  204. eB[j] = hi[40 * B + j - 155];
  205. for (j = 195; j < 348; j++)
  206. eB[j] = di[306 * B + j - 42];
  207. }
  208. void gsm0503_mcs7_ul_burst_unmap(sbit_t *di, const sbit_t *eB,
  209. sbit_t *hi, int B)
  210. {
  211. int j;
  212. for (j = 0; j < 153; j++)
  213. di[306 * B + j] = eB[j];
  214. for (j = 153; j < 174; j++)
  215. hi[40 * B + j - 153] = eB[j];
  216. for (j = 176; j < 195; j++)
  217. hi[40 * B + j - 155] = eB[j];
  218. for (j = 195; j < 348; j++)
  219. di[306 * B + j - 42] = eB[j];
  220. }
  221. void gsm0503_mcs5_burst_swap(sbit_t *eB)
  222. {
  223. sbit_t t[14];
  224. t[0] = eB[155];
  225. t[1] = eB[158];
  226. t[2] = eB[161];
  227. t[3] = eB[164];
  228. t[4] = eB[167];
  229. t[5] = eB[170];
  230. t[6] = eB[173];
  231. t[7] = eB[195];
  232. t[8] = eB[196];
  233. t[9] = eB[198];
  234. t[10] = eB[199];
  235. t[11] = eB[201];
  236. t[12] = eB[202];
  237. t[13] = eB[204];
  238. eB[155] = eB[142];
  239. eB[158] = eB[144];
  240. eB[161] = eB[145];
  241. eB[164] = eB[147];
  242. eB[167] = eB[148];
  243. eB[170] = eB[150];
  244. eB[173] = eB[151];
  245. eB[195] = eB[176];
  246. eB[196] = eB[179];
  247. eB[198] = eB[182];
  248. eB[199] = eB[185];
  249. eB[201] = eB[188];
  250. eB[202] = eB[191];
  251. eB[204] = eB[194];
  252. eB[142] = t[0];
  253. eB[144] = t[1];
  254. eB[145] = t[2];
  255. eB[147] = t[3];
  256. eB[148] = t[4];
  257. eB[150] = t[5];
  258. eB[151] = t[6];
  259. eB[176] = t[7];
  260. eB[179] = t[8];
  261. eB[182] = t[9];
  262. eB[185] = t[10];
  263. eB[188] = t[11];
  264. eB[191] = t[12];
  265. eB[194] = t[13];
  266. }
  267. /*! @} */